net: enetc: remove bootloader dependency
Subsystems (6)
v4 cover net: enetc: remove bootloader dependency
This is a resend [now a new v4] of the series because the conversion to the phylink interface will likely take longer:
https://lore.kernel.org/netdev/CA+h21hpBodyY8CtNH2ktRdc2FqPi=Fjp94=VVZvzSVbnvnfKVg@mail.gmail.com/
Also the discussion in the v3 resend doesn't look like it will be resolved soon :/
https://lore.kernel.org/netdev/[email protected]/
Unfortunately, we have boards in the wild with a bootloader which doesn't set the PCS up correctly. Thus I'd really see this patches picked up as an intermediate step until the phylink conversion is ready. Vladimir Oltean already offered to convert enetc to phylink when he converts the felix to phylink. After this series the PCS setup of the enetc looks almost the same as the current felix setup. Thus conversion should be easy.
These patches were picked from the following series:
https://lore.kernel.org/netdev/[email protected]/
They have never been resent. I've picked them up, addressed Andrews comments, fixed some more bugs and asked Claudiu if I can keep their SOB tags; he agreed. I've tested this on our board which happens to have a bootloader which doesn't do the enetc setup in all cases. Though, only SGMII mode was tested.
changes since v3:
- rebased to latest net-next where devm_mdiobus_free() was removed. replace it by mdiobus_free(). The internal MDIO bus is optional, if there is any error, we try to run with the bootloader default PCS settings, thus in the error case, we need to free the mdiobus.
changes since v2:
- removed SOBs from "net: enetc: Initialize SerDes for SGMII and USXGMII protocols" because almost everything has changed.
- get a phy_device for the internal PCS PHY so we can use the phy_ functions instead of raw mdiobus writes
- reuse macros already defined in fsl_mdio.h, move missing bits from felix to fsl_mdio.h, because they share the same PCS PHY building block
- added 2500BaseX mode (based on felix init routine)
- changed xgmii mode to usxgmii mode, because it is actually USXGMII and felix does the same.
- fixed devad, which is 0x1f (MMD_VEND2)
changes since v1:
- mdiobus id is '"imdio-%s", dev_name(dev)' because the plain dev_name() is used by the emdio.
- use mdiobus_write() instead of imdio->write(imdio, ..), since this is already a full featured mdiobus
- set phy_mask to ~0 to avoid scanning the bus
- use phy_interface_mode_is_rgmii(phy_mode) to also include the RGMII modes with pad delays.
- move enetc_imdio_init() to enetc_pf.c, there shouldn't be any other users, should it?
- renamed serdes to SerDes
- printing the error code of mdiobus_register() in the error path
- call mdiobus_unregister() on _remove()
- call devm_mdiobus_free() if mdiobus_register() fails, since an error is not fatal
Alex Marginean (1):
net: enetc: Use DT protocol information to set up the ports
Michael Walle (2):
net: dsa: felix: move USXGMII defines to common place
net: enetc: Initialize SerDes for SGMII and USXGMII protocols
drivers/net/dsa/ocelot/felix_vsc9959.c | 21 -- .../net/ethernet/freescale/enetc/enetc_hw.h | 3 + .../net/ethernet/freescale/enetc/enetc_pf.c | 190 +++++++++++++++--- .../net/ethernet/freescale/enetc/enetc_pf.h | 5 + include/linux/fsl/enetc_mdio.h | 19 ++ 5 files changed, 193 insertions(+), 45 deletions(-)
Signature · 1 line
2.20.1
PATCH v4 1/3 net: dsa: felix: move USXGMII defines to common place
The ENETC has the same PCS PHY and thus needs the same definitions. Move them into the common enetc_mdio.h header which has already the macros for the SGMII PCS.
--- drivers/net/dsa/ocelot/felix_vsc9959.c | 21 --------------------- include/linux/fsl/enetc_mdio.h | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 21 deletions(-)
drivers/net/dsa/ocelot/felix_vsc9959.c +0 -21
@@ -16,29 +16,8 @@#define VSC9959_VCAP_IS2_CNT 1024#define VSC9959_VCAP_IS2_ENTRY_WIDTH 376#define VSC9959_VCAP_PORT_CNT 6 - -/* TODO: should find a better place for these */ -#define USXGMII_BMCR_RESET BIT(15) -#define USXGMII_BMCR_AN_EN BIT(12) -#define USXGMII_BMCR_RST_AN BIT(9) -#define USXGMII_BMSR_LNKS (status) (((status) & GENMASK(2, 2)) >> 2) -#define USXGMII_BMSR_AN_CMPL (status) (((status) & GENMASK(5, 5)) >> 5) -#define USXGMII_ADVERTISE_LNKS (x) (((x) << 15) & BIT(15)) -#define USXGMII_ADVERTISE_FDX BIT(12) -#define USXGMII_ADVERTISE_SPEED (x) (((x) << 9) & GENMASK(11, 9)) -#define USXGMII_LPA_LNKS (lpa) ((lpa) >> 15) -#define USXGMII_LPA_DUPLEX (lpa) (((lpa) & GENMASK(12, 12)) >> 12) -#define USXGMII_LPA_SPEED (lpa) (((lpa) & GENMASK(11, 9)) >> 9) -#define VSC9959_TAS_GCL_ENTRY_MAX 63 -enum usxgmii_speed { -USXGMII_SPEED_10 =0 , -USXGMII_SPEED_100 =1 , -USXGMII_SPEED_1000 =2 , -USXGMII_SPEED_2500 =4 , -}; -static const u32 vsc9959_ana_regmap[] = {REG (ANA_ADVLEARN ,0x0089a0 ),REG (ANA_VLANMASK ,0x0089a4 ),
include/linux/fsl/enetc_mdio.h +19 -0
@@ -28,6 +28,25 @@ enum enetc_pcs_speed { ENETC_PCS_SPEED_2500 = 2, }; +#define USXGMII_BMCR_RESET BIT(15) +#define USXGMII_BMCR_AN_EN BIT(12) +#define USXGMII_BMCR_RST_AN BIT(9) +#define USXGMII_BMSR_LNKS (status) (((status) & GENMASK(2, 2)) >> 2) +#define USXGMII_BMSR_AN_CMPL (status) (((status) & GENMASK(5, 5)) >> 5) +#define USXGMII_ADVERTISE_LNKS (x) (((x) << 15) & BIT(15)) +#define USXGMII_ADVERTISE_FDX BIT(12) +#define USXGMII_ADVERTISE_SPEED (x) (((x) << 9) & GENMASK(11, 9)) +#define USXGMII_LPA_LNKS (lpa) ((lpa) >> 15) +#define USXGMII_LPA_DUPLEX (lpa) (((lpa) & GENMASK(12, 12)) >> 12) +#define USXGMII_LPA_SPEED (lpa) (((lpa) & GENMASK(11, 9)) >> 9) + +enum usxgmii_speed { +USXGMII_SPEED_10 =0 , +USXGMII_SPEED_100 =1 , +USXGMII_SPEED_1000 =2 , +USXGMII_SPEED_2500 =4 , +}; +struct enetc_hw ;struct enetc_mdio_priv {
Signature · 1 line
2.20.1
RE: [PATCH net-next v4 1/3] net: dsa: felix: move USXGMII defines to common place
Quoted 3 lines
-----Original Message-----
From: Michael Walle <[email protected]>
Sent: Tuesday, July 7, 2020 1:03 AM
[...]
Quoted 8 lines
Subject: [PATCH net-next v4 1/3] net: dsa: felix: move USXGMII defines to common place
The ENETC has the same PCS PHY and thus needs the same definitions. Move them into the common
enetc_mdio.hheader which has already the macros for the SGMII PCS.Signed-off-by Michael Walle <[email protected]>
Re: [PATCH net-next v4 1/3] net: dsa: felix: move USXGMII defines to common place
In reply to Michael WalleQuoted 49 lines · Michael Walle
The ENETC has the same PCS PHY and thus needs the same definitions. Move them into the common
enetc_mdio.hheader which has already the macros for the SGMII PCS.Signed-off-by Michael Walle <[email protected]>--- drivers/net/dsa/ocelot/felix_vsc9959.c | 21 --------------------- include/linux/fsl/enetc_mdio.h | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 21 deletions(-)drivers/net/dsa/ocelot/felix_vsc9959.c +0
-21@@ -16,29 +16,8 @@#define VSC9959_VCAP_IS2_CNT 1024#define VSC9959_VCAP_IS2_ENTRY_WIDTH 376#define VSC9959_VCAP_PORT_CNT 6 - -/* TODO: should find a better place for these */ -#define USXGMII_BMCR_RESET BIT(15) -#define USXGMII_BMCR_AN_EN BIT(12) -#define USXGMII_BMCR_RST_AN BIT(9) -#define USXGMII_BMSR_LNKS (status) (((status) & GENMASK(2, 2)) >> 2) -#define USXGMII_BMSR_AN_CMPL (status) (((status) & GENMASK(5, 5)) >> 5) -#define USXGMII_ADVERTISE_LNKS (x) (((x) << 15) & BIT(15)) -#define USXGMII_ADVERTISE_FDX BIT(12) -#define USXGMII_ADVERTISE_SPEED (x) (((x) << 9) & GENMASK(11, 9)) -#define USXGMII_LPA_LNKS (lpa) ((lpa) >> 15) -#define USXGMII_LPA_DUPLEX (lpa) (((lpa) & GENMASK(12, 12)) >> 12) -#define USXGMII_LPA_SPEED (lpa) (((lpa) & GENMASK(11, 9)) >> 9) -#define VSC9959_TAS_GCL_ENTRY_MAX 63 -enum usxgmii_speed { -USXGMII_SPEED_10 =0 , -USXGMII_SPEED_100 =1 , -USXGMII_SPEED_1000 =2 , -USXGMII_SPEED_2500 =4 , -}; -static const u32 vsc9959_ana_regmap[] = {REG (ANA_ADVLEARN ,0x0089a0 ),REG (ANA_VLANMASK ,0x0089a4 ),include/linux/fsl/enetc_mdio.h +0
-0
include/linux/fsl/enetc_mdio.h enum enetc_pcs_speed { · line 33
Quoted 6 lines
include/linux/fsl/enetc_mdio.h +3
-0@@ -28,6 +28,25 @@ enum enetc_pcs_speed { ENETC_PCS_SPEED_2500 = 2, }; +#define USXGMII_BMCR_RESET BIT(15) +#define USXGMII_BMCR_AN_EN BIT(12) +#define USXGMII_BMCR_RST_AN BIT(9)
Aren't these just redefinitions of the standard BMCR definitions?
include/linux/fsl/enetc_mdio.h enum enetc_pcs_speed { · line 35
Quoted 2 lines
include/linux/fsl/enetc_mdio.h +2
-0+#define USXGMII_BMSR_LNKS (status) (((status) & GENMASK(2, 2)) >> 2) +#define USXGMII_BMSR_AN_CMPL (status) (((status) & GENMASK(5, 5)) >> 5)
Aren't these just redefinitions of the standard BMSR definitions just differently?
Maybe convert the code to use the standard definitions found in include/uapi/linux/mii.h and include/uapi/linux/mdio.h?
Quoted 4 lines
include/linux/fsl/enetc_mdio.h +4
-0+#define USXGMII_ADVERTISE_LNKS (x) (((x) << 15) & BIT(15)) +#define USXGMII_ADVERTISE_FDX BIT(12) +#define USXGMII_ADVERTISE_SPEED (x) (((x) << 9) & GENMASK(11, 9)) +#define USXGMII_LPA_LNKS (lpa) ((lpa) >> 15)
include/linux/fsl/enetc_mdio.h enum enetc_pcs_speed { · line 49
Quoted 10 lines
include/linux/fsl/enetc_mdio.h +10
-0+#define USXGMII_LPA_DUPLEX (lpa) (((lpa) & GENMASK(12, 12)) >> 12) +#define USXGMII_LPA_SPEED (lpa) (((lpa) & GENMASK(11, 9)) >> 9) + +enum usxgmii_speed { +USXGMII_SPEED_10 =0 , +USXGMII_SPEED_100 =1 , +USXGMII_SPEED_1000 =2 , +USXGMII_SPEED_2500 =4 , +}; +
I've asked in other patch sets for the USXGMII definitions to be moved into some header that everyone can use - there is nothing enetc specific about the USXGMII word definitions. Please move them to a header file so that everyone can use them.
Thanks.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
PATCH v4 2/3 net: enetc: Initialize SerDes for SGMII and USXGMII protocols
In reply to Michael WalleENETC has ethernet MACs capable of SGMII, 2500BaseX and USXGMII. But in order to use these protocols some SerDes configurations need to be performed. The SerDes is configurable via an internal PCS PHY which is connected to an internal MDIO bus at address 0.
This patch basically removes the dependency on bootloader regarding SerDes initialization.
--- .../net/ethernet/freescale/enetc/enetc_hw.h | 3 + .../net/ethernet/freescale/enetc/enetc_pf.c | 137 ++++++++++++++++++ .../net/ethernet/freescale/enetc/enetc_pf.h | 2 + 3 files changed, 142 insertions(+)
drivers/net/ethernet/freescale/enetc/enetc_hw.h +3 -0
@@ -224,6 +224,9 @@ enum enetc_bdr_type {TX, RX};#define ENETC_PM0_MAXFRM 0x8014#define ENETC_SET_TX_MTU (val) ((val) << 16)#define ENETC_SET_MAXFRM (val) ((val) & 0xffff) + +#define ENETC_PM_IMDIO_BASE 0x8030 +#define ENETC_PM0_IF_MODE 0x8300#define ENETC_PMO_IFM_RG BIT(2)#define ENETC_PM0_IFM_RLP (BIT(5) | BIT(11))
drivers/net/ethernet/freescale/enetc/enetc_pf.c +137 -0
155 lines not on this page · raw message
drivers/net/ethernet/freescale/enetc/enetc_pf.h +2 -0
@@ -44,6 +44,8 @@ struct enetc_pf {DECLARE_BITMAP (active_vlans,VLAN_N_VID );struct mii_bus *mdio;/* saved for cleanup */ +struct mii_bus *imdio; +struct phy_device *pcs; };int enetc_msg_psi_init (struct enetc_pf *pf);
Signature · 1 line
2.20.1
RE: [PATCH net-next v4 2/3] net: enetc: Initialize SerDes for SGMII and USXGMII protocols
Quoted 3 lines
-----Original Message-----
From: Michael Walle <[email protected]>
Sent: Tuesday, July 7, 2020 1:03 AM
[...]
Quoted 8 lines
Subject: [PATCH net-next v4 2/3] net: enetc: Initialize SerDes for SGMII and USXGMII protocols
ENETC has ethernet MACs capable of SGMII, 2500BaseX and USXGMII. But in order to use these protocols some SerDes configurations need to be performed. The SerDes is configurable via an internal PCS PHY which is connected to an internal MDIO bus at address 0.
Quoted 4 lines
This patch basically removes the dependency on bootloader regarding SerDes initialization.
Signed-off-by Michael Walle <[email protected]>
PATCH v4 3/3 net: enetc: Use DT protocol information to set up the ports
In reply to Michael WalleFrom: Alex Marginean <[email protected]>
Use DT information rather than in-band information from bootloader to set up MAC for XGMII. For RGMII use the DT indication in addition to RGMII defaults in hardware.
However, this implies that PHY connection information needs to be extracted before netdevice creation, when the ENETC Port MAC is being configured.
--- .../net/ethernet/freescale/enetc/enetc_pf.c | 57 ++++++++++--------- .../net/ethernet/freescale/enetc/enetc_pf.h | 3 + 2 files changed, 34 insertions(+), 26 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_pf.c +31 -26
@@ -481,7 +481,8 @@ static void enetc_port_si_configure(struct enetc_si *si)enetc_port_wr (hw,ENETC_PSIVLANFMR ,ENETC_PSIVLANFMR_VS ); } -static void enetc_configure_port_mac (struct enetc_hw *hw) +static void enetc_configure_port_mac (struct enetc_hw *hw, +phy_interface_t phy_mode) {enetc_port_wr (hw,ENETC_PM0_MAXFRM ,ENETC_SET_MAXFRM (ENETC_RX_MAXFRM_SIZE ));
@@ -497,9 +498,11 @@ static void enetc_configure_port_mac(struct enetc_hw *hw)ENETC_PM0_CMD_TXP |ENETC_PM0_PROMISC | ENETC_PM0_TX_EN | ENETC_PM0_RX_EN);/* set auto-speed for RGMII */ -if (enetc_port_rd (hw,ENETC_PM0_IF_MODE ) &ENETC_PMO_IFM_RG ) +if (enetc_port_rd (hw,ENETC_PM0_IF_MODE ) &ENETC_PMO_IFM_RG || +phy_interface_mode_is_rgmii (phy_mode))enetc_port_wr (hw,ENETC_PM0_IF_MODE ,ENETC_PM0_IFM_RGAUTO ); -if (enetc_global_rd (hw,ENETC_G_EPFBLPR (1 )) ==ENETC_G_EPFBLPR1_XGMII ) + +if (phy_mode ==PHY_INTERFACE_MODE_USXGMII )enetc_port_wr (hw,ENETC_PM0_IF_MODE ,ENETC_PM0_IFM_XGMII ); }
@@ -523,7 +526,7 @@ static void enetc_configure_port(struct enetc_pf *pf)enetc_configure_port_pmac (hw); -enetc_configure_port_mac (hw); +enetc_configure_port_mac (hw, pf->if_mode);enetc_port_si_configure (pf->si);
@@ -775,27 +778,27 @@ static void enetc_mdio_remove(struct enetc_pf *pf)mdiobus_unregister (pf->mdio); } -static int enetc_of_get_phy (struct enetc_ndev_priv *priv) +static int enetc_of_get_phy (struct enetc_pf *pf) { -struct enetc_pf *pf =enetc_si_priv (priv->si); -struct device_node *np = priv->dev->of_node; +struct device *dev = &pf->si->pdev->dev; +struct device_node *np = dev->of_node;struct device_node *mdio_np;int err; - priv->phy_node =of_parse_phandle (np,"phy-handle" ,0 ); -if (!priv->phy_node) { + pf->phy_node =of_parse_phandle (np,"phy-handle" ,0 ); +if (!pf->phy_node) {if (!of_phy_is_fixed_link (np)) { -dev_err (priv->dev,"PHY not specified\n" ); +dev_err (dev,"PHY not specified\n" );return -ENODEV ; } err =of_phy_register_fixed_link (np);if (err <0 ) { -dev_err (priv->dev,"fixed link registration failed\n" ); +dev_err (dev,"fixed link registration failed\n" );return err; } - priv->phy_node =of_node_get (np); + pf->phy_node =of_node_get (np); } mdio_np =of_get_child_by_name (np,"mdio" );
@@ -803,15 +806,15 @@ static int enetc_of_get_phy(struct enetc_ndev_priv *priv)of_node_put (mdio_np); err =enetc_mdio_probe (pf);if (err) { -of_node_put (priv->phy_node); +of_node_put (pf->phy_node);return err; } } - err =of_get_phy_mode (np, &priv->if_mode); + err =of_get_phy_mode (np, &pf->if_mode);if (err) { -dev_err (priv->dev,"missing phy type\n" ); -of_node_put (priv->phy_node); +dev_err (dev,"missing phy type\n" ); +of_node_put (pf->phy_node);if (of_phy_is_fixed_link (np))of_phy_deregister_fixed_link (np);else
@@ -823,14 +826,14 @@ static int enetc_of_get_phy(struct enetc_ndev_priv *priv)return 0 ; } -static void enetc_of_put_phy (struct enetc_ndev_priv *priv) +static void enetc_of_put_phy (struct enetc_pf *pf) { -struct device_node *np = priv->dev->of_node; +struct device_node *np = pf->si->pdev->dev.of_node;if (np &&of_phy_is_fixed_link (np))of_phy_deregister_fixed_link (np); -if (priv->phy_node) -of_node_put (priv->phy_node); +if (pf->phy_node) +of_node_put (pf->phy_node); }static int enetc_imdio_init (struct enetc_pf *pf,bool is_c45)
@@ -996,6 +999,10 @@ static int enetc_pf_probe(struct pci_dev *pdev, pf->si = si; pf->total_vfs =pci_sriov_get_totalvfs (pdev); + err =enetc_of_get_phy (pf); +if (err) +dev_warn (&pdev->dev,"Fallback to PHY-less operation\n" ); +enetc_configure_port (pf);enetc_get_si_caps (si);
@@ -1010,6 +1017,8 @@ static int enetc_pf_probe(struct pci_dev *pdev,enetc_pf_netdev_setup (si, ndev, &enetc_ndev_ops); priv =netdev_priv (ndev); + priv->phy_node = pf->phy_node; + priv->if_mode = pf->if_mode;enetc_init_si_rings_params (priv);
@@ -1025,10 +1034,6 @@ static int enetc_pf_probe(struct pci_dev *pdev, goto err_alloc_msix; } - err =enetc_of_get_phy (priv); -if (err) -dev_warn (&pdev->dev,"Fallback to PHY-less operation\n" ); - err =enetc_configure_serdes (priv);if (err)dev_warn (&pdev->dev,"Attempted SerDes config but failed\n" );
@@ -1042,7 +1047,6 @@ static int enetc_pf_probe(struct pci_dev *pdev,return 0 ; err_reg_netdev: -enetc_of_put_phy (priv);enetc_free_msix (priv); err_alloc_msix:enetc_free_si_resources (priv);
@@ -1050,6 +1054,7 @@ static int enetc_pf_probe(struct pci_dev *pdev, si->ndev =NULL ;free_netdev (ndev); err_alloc_netdev: +enetc_of_put_phy (pf); err_map_pf_space:enetc_pci_remove (pdev);
@@ -1070,7 +1075,7 @@ static void enetc_pf_remove(struct pci_dev *pdev)enetc_imdio_remove (pf);enetc_mdio_remove (pf); -enetc_of_put_phy (priv); +enetc_of_put_phy (pf);enetc_free_msix (priv);
drivers/net/ethernet/freescale/enetc/enetc_pf.h +3 -0
@@ -46,6 +46,9 @@ struct enetc_pf {struct mii_bus *mdio;/* saved for cleanup */ struct mii_bus *imdio;struct phy_device *pcs; + +struct device_node *phy_node; +phy_interface_t if_mode; };int enetc_msg_psi_init (struct enetc_pf *pf);
Signature · 1 line
2.20.1