1 From 98f64a89977a32df96cdb8aaf3884086b2309924 Mon Sep 17 00:00:00 2001
2 From: Alex Marginean <alexandru.marginean@nxp.com>
3 Date: Tue, 27 Aug 2019 15:14:11 +0300
4 Subject: [PATCH] enetc: Use DT protocol information to set up the ports
6 Use DT information rather than in-band information from bootloader to
7 set up MAC for XGMII. For RGMII use the DT indication in addition to
8 RGMII defaults in hardware.
9 However, this implies that PHY connection information needs to be
10 extracted before netdevice creation, when the ENETC Port MAC is
13 Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
14 Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
16 drivers/net/ethernet/freescale/enetc/enetc_pf.c | 55 ++++++++++++++-----------
17 drivers/net/ethernet/freescale/enetc/enetc_pf.h | 3 ++
18 2 files changed, 33 insertions(+), 25 deletions(-)
20 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
21 +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
22 @@ -507,7 +507,8 @@ static void enetc_port_si_configure(stru
23 enetc_port_wr(hw, ENETC_PSIVLANFMR, ENETC_PSIVLANFMR_VS);
26 -static void enetc_configure_port_mac(struct enetc_hw *hw)
27 +static void enetc_configure_port_mac(struct enetc_hw *hw,
28 + phy_interface_t phy_mode)
30 enetc_port_wr(hw, ENETC_PM0_MAXFRM,
31 ENETC_SET_MAXFRM(ENETC_RX_MAXFRM_SIZE));
32 @@ -523,9 +524,11 @@ static void enetc_configure_port_mac(str
33 ENETC_PM0_CMD_TXP | ENETC_PM0_PROMISC |
34 ENETC_PM0_TX_EN | ENETC_PM0_RX_EN);
35 /* set auto-speed for RGMII */
36 - if (enetc_port_rd(hw, ENETC_PM0_IF_MODE) & ENETC_PMO_IFM_RG)
37 + if (enetc_port_rd(hw, ENETC_PM0_IF_MODE) & ENETC_PMO_IFM_RG ||
38 + phy_mode == PHY_INTERFACE_MODE_RGMII)
39 enetc_port_wr(hw, ENETC_PM0_IF_MODE, ENETC_PM0_IFM_RGAUTO);
40 - if (enetc_global_rd(hw, ENETC_G_EPFBLPR(1)) == ENETC_G_EPFBLPR1_XGMII)
42 + if (phy_mode == PHY_INTERFACE_MODE_XGMII)
43 enetc_port_wr(hw, ENETC_PM0_IF_MODE, ENETC_PM0_IFM_XGMII);
46 @@ -549,7 +552,7 @@ static void enetc_configure_port(struct
48 enetc_configure_port_pmac(hw);
50 - enetc_configure_port_mac(hw);
51 + enetc_configure_port_mac(hw, pf->if_mode);
53 enetc_port_si_configure(pf->si);
55 @@ -749,28 +752,28 @@ static void enetc_pf_netdev_setup(struct
56 enetc_get_primary_mac_addr(&si->hw, ndev->dev_addr);
59 -static int enetc_of_get_phy(struct enetc_ndev_priv *priv)
60 +static int enetc_of_get_phy(struct enetc_pf *pf)
62 - struct enetc_pf *pf = enetc_si_priv(priv->si);
63 - struct device_node *np = priv->dev->of_node;
64 + struct device *dev = &pf->si->pdev->dev;
65 + struct device_node *np = dev->of_node;
66 struct device_node *mdio_np;
70 - priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
71 - if (!priv->phy_node) {
72 + pf->phy_node = of_parse_phandle(np, "phy-handle", 0);
73 + if (!pf->phy_node) {
74 if (!of_phy_is_fixed_link(np)) {
75 - dev_err(priv->dev, "PHY not specified\n");
76 + dev_err(dev, "PHY not specified\n");
80 err = of_phy_register_fixed_link(np);
82 - dev_err(priv->dev, "fixed link registration failed\n");
83 + dev_err(dev, "fixed link registration failed\n");
87 - priv->phy_node = of_node_get(np);
88 + pf->phy_node = of_node_get(np);
91 mdio_np = of_get_child_by_name(np, "mdio");
92 @@ -778,28 +781,28 @@ static int enetc_of_get_phy(struct enetc
94 err = enetc_mdio_probe(pf);
96 - of_node_put(priv->phy_node);
97 + of_node_put(pf->phy_node);
102 phy_mode = of_get_phy_mode(np);
104 - priv->if_mode = PHY_INTERFACE_MODE_NA; /* fixed link */
105 + pf->if_mode = PHY_INTERFACE_MODE_NA; /* fixed link */
107 - priv->if_mode = phy_mode;
108 + pf->if_mode = phy_mode;
113 -static void enetc_of_put_phy(struct enetc_ndev_priv *priv)
114 +static void enetc_of_put_phy(struct enetc_pf *pf)
116 - struct device_node *np = priv->dev->of_node;
117 + struct device_node *np = pf->si->pdev->dev.of_node;
119 if (np && of_phy_is_fixed_link(np))
120 of_phy_deregister_fixed_link(np);
121 - if (priv->phy_node)
122 - of_node_put(priv->phy_node);
124 + of_node_put(pf->phy_node);
127 static void enetc_configure_sgmii(struct mii_bus *imdio)
128 @@ -888,6 +891,10 @@ static int enetc_pf_probe(struct pci_dev
130 pf->total_vfs = pci_sriov_get_totalvfs(pdev);
132 + err = enetc_of_get_phy(pf);
134 + dev_warn(&pdev->dev, "Fallback to PHY-less operation\n");
136 enetc_configure_port(pf);
138 enetc_get_si_caps(si);
139 @@ -902,6 +909,8 @@ static int enetc_pf_probe(struct pci_dev
140 enetc_pf_netdev_setup(si, ndev, &enetc_ndev_ops);
142 priv = netdev_priv(ndev);
143 + priv->phy_node = pf->phy_node;
144 + priv->if_mode = pf->if_mode;
146 enetc_init_si_rings_params(priv);
148 @@ -917,10 +926,6 @@ static int enetc_pf_probe(struct pci_dev
152 - err = enetc_of_get_phy(priv);
154 - dev_warn(&pdev->dev, "Fallback to PHY-less operation\n");
156 err = enetc_configure_serdes(priv);
158 dev_warn(&pdev->dev, "Attempted serdes config but failed\n");
159 @@ -937,7 +942,6 @@ static int enetc_pf_probe(struct pci_dev
163 - enetc_of_put_phy(priv);
164 enetc_free_msix(priv);
166 enetc_free_si_resources(priv);
167 @@ -945,6 +949,7 @@ err_alloc_si_res:
171 + enetc_of_put_phy(pf);
173 enetc_pci_remove(pdev);
175 @@ -967,7 +972,7 @@ static void enetc_pf_remove(struct pci_d
176 unregister_netdev(si->ndev);
178 enetc_mdio_remove(pf);
179 - enetc_of_put_phy(priv);
180 + enetc_of_put_phy(pf);
182 enetc_free_msix(priv);
184 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.h
185 +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.h
186 @@ -45,6 +45,9 @@ struct enetc_pf {
188 struct mii_bus *mdio; /* saved for cleanup */
189 struct mii_bus *imdio;
191 + struct device_node *phy_node;
192 + phy_interface_t if_mode;
195 int enetc_msg_psi_init(struct enetc_pf *pf);