aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/layerscape/patches-5.4/701-net-0314-staging-fsl_ppfe-eth-support-single-interface-initia.patch
blob: 4c4cf6c0f3bce359e3ecd61b641be3f07e8072ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
From dff5fdd84a9ace2d9b8b56659c0855542829148a Mon Sep 17 00:00:00 2001
From: Calvin Johnson <calvin.johnson@nxp.com>
Date: Fri, 23 Nov 2018 23:58:28 +0530
Subject: [PATCH] staging: fsl_ppfe/eth: support single interface
 initialization

- arrange members of struct mii_bus in sequence matching phy.h
- if mdio node is defined, use of_mdiobus_register to register
  child nodes (phy devices) available on the mdio bus.
- remove of_phy_register_fixed_link from pfe_phy_init as it is being
  handled in pfe_get_gemac_if_properties
- remove mdio enabled check
- skip phy init, if no PHY or fixed-link

Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
---
 drivers/staging/fsl_ppfe/pfe_eth.c              | 110 +++++++++++++-----------
 drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c |   4 +
 2 files changed, 66 insertions(+), 48 deletions(-)

--- a/drivers/staging/fsl_ppfe/pfe_eth.c
+++ b/drivers/staging/fsl_ppfe/pfe_eth.c
@@ -47,6 +47,7 @@
 
 #define LS1012A_REV_1_0		0x87040010
 
+bool pfe_use_old_dts_phy;
 bool pfe_errata_a010897;
 
 static void *cbus_emac_base[3];
@@ -950,7 +951,8 @@ static int pfe_eth_mdio_init(struct pfe_
 			     struct ls1012a_mdio_platform_data *minfo)
 {
 	struct mii_bus *bus;
-	int rc, ii;
+	struct device_node *mdio_node;
+	int rc = 0, ii;
 	struct phy_device *phydev;
 
 	netif_info(priv, drv, priv->ndev, "%s\n", __func__);
@@ -964,25 +966,30 @@ static int pfe_eth_mdio_init(struct pfe_
 	}
 
 	bus->name = "ls1012a MDIO Bus";
+	snprintf(bus->id, MII_BUS_ID_SIZE, "ls1012a-%x", priv->id);
+
+	bus->priv = priv;
 	bus->read = &pfe_eth_mdio_read;
 	bus->write = &pfe_eth_mdio_write;
 	bus->reset = &pfe_eth_mdio_reset;
-	snprintf(bus->id, MII_BUS_ID_SIZE, "ls1012a-%x", priv->id);
-	bus->priv = priv;
-
+	bus->parent = priv->pfe->dev;
 	bus->phy_mask = minfo->phy_mask;
-	priv->mdc_div = minfo->mdc_div;
+	bus->irq[0] = minfo->irq[0];
 
+	priv->mdc_div = minfo->mdc_div;
 	if (!priv->mdc_div)
 		priv->mdc_div = 64;
-
-	bus->irq[0] = minfo->irq[0];
-
-	bus->parent = priv->pfe->dev;
-
 	netif_info(priv, drv, priv->ndev, "%s: mdc_div: %d, phy_mask: %x\n",
 		   __func__, priv->mdc_div, bus->phy_mask);
-	rc = mdiobus_register(bus);
+
+	mdio_node = of_get_child_by_name(priv->pfe->dev->of_node, "mdio");
+	if (mdio_node) {
+		rc = of_mdiobus_register(bus, mdio_node);
+		of_node_put(mdio_node);
+	} else {
+		rc = mdiobus_register(bus);
+	}
+
 	if (rc) {
 		netdev_err(priv->ndev, "mdiobus_register(%s) failed\n",
 			   bus->name);
@@ -995,7 +1002,6 @@ static int pfe_eth_mdio_init(struct pfe_
 	 * 3rd argument as true and then register the phy device
 	 * via phy_device_register()
 	 */
-
 	if (priv->einfo->mii_config == PHY_INTERFACE_MODE_2500SGMII) {
 		for (ii = 0; ii < NUM_GEMAC_SUPPORT; ii++) {
 			phydev = get_phy_device(priv->mii_bus,
@@ -1268,8 +1274,6 @@ static int pfe_phy_init(struct net_devic
 	char phy_id[MII_BUS_ID_SIZE + 3];
 	char bus_id[MII_BUS_ID_SIZE];
 	phy_interface_t interface;
-	struct device_node *phy_node;
-	int rc;
 
 	priv->oldlink = 0;
 	priv->oldspeed = 0;
@@ -1278,7 +1282,6 @@ static int pfe_phy_init(struct net_devic
 	snprintf(bus_id, MII_BUS_ID_SIZE, "ls1012a-%d", 0);
 	snprintf(phy_id, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
 		 priv->einfo->phy_id);
-
 	netif_info(priv, drv, ndev, "%s: %s\n", __func__, phy_id);
 	interface = priv->einfo->mii_config;
 	if ((interface == PHY_INTERFACE_MODE_SGMII) ||
@@ -1301,23 +1304,22 @@ static int pfe_phy_init(struct net_devic
 	priv->oldduplex = -1;
 	pr_info("%s interface %x\n", __func__, interface);
 
-	if (of_phy_is_fixed_link(priv->phy_node)) {
-		rc = of_phy_register_fixed_link(priv->phy_node);
-		if (rc)
-			return rc;
-		phy_node = of_node_get(priv->phy_node);
-		phydev = of_phy_connect(ndev, phy_node, pfe_eth_adjust_link, 0,
+	if (priv->phy_node) {
+		phydev = of_phy_connect(ndev, priv->phy_node,
+					pfe_eth_adjust_link, 0,
 					priv->einfo->mii_config);
-		of_node_put(phy_node);
+		if (!(phydev)) {
+			netdev_err(ndev, "Unable to connect to phy\n");
+			return -ENODEV;
+		}
 
 	} else {
 		phydev = phy_connect(ndev, phy_id,
 				     &pfe_eth_adjust_link, interface);
-	}
-
-	if (IS_ERR(phydev)) {
-		netdev_err(ndev, "phy_connect() failed\n");
-		return PTR_ERR(phydev);
+		if (IS_ERR(phydev)) {
+			netdev_err(ndev, "Unable to connect to phy\n");
+			return PTR_ERR(phydev);
+		}
 	}
 
 	priv->phydev = phydev;
@@ -2411,13 +2413,10 @@ static int pfe_eth_init_one(struct pfe *
 	memcpy(ndev->dev_addr, einfo[id].mac_addr, ETH_ALEN);
 
 	/* Initialize mdio */
-	if (minfo[id].enabled) {
-		err = pfe_eth_mdio_init(priv, &minfo[id]);
-		if (err) {
-			netdev_err(ndev, "%s: pfe_eth_mdio_init() failed\n",
-				   __func__);
-			goto err2;
-		}
+	err = pfe_eth_mdio_init(priv, &minfo[id]);
+	if (err) {
+		netdev_err(ndev, "%s: pfe_eth_mdio_init() failed\n", __func__);
+		goto err1;
 	}
 
 	if (us)
@@ -2462,22 +2461,26 @@ static int pfe_eth_init_one(struct pfe *
 		       HIF_RX_POLL_WEIGHT - 16);
 
 	err = register_netdev(ndev);
-
 	if (err) {
 		netdev_err(ndev, "register_netdev() failed\n");
-		goto err3;
+		goto err2;
+	}
+
+	if ((!(pfe_use_old_dts_phy) && !(priv->phy_node)) ||
+	    ((pfe_use_old_dts_phy) &&
+	      (priv->einfo->phy_flags & GEMAC_NO_PHY))) {
+		pr_info("%s: No PHY or fixed-link\n", __func__);
+		goto skip_phy_init;
 	}
 
 phy_init:
 	device_init_wakeup(&ndev->dev, WAKE_MAGIC);
 
-	if (!(priv->einfo->phy_flags & GEMAC_NO_PHY)) {
-		err = pfe_phy_init(ndev);
-		if (err) {
-			netdev_err(ndev, "%s: pfe_phy_init() failed\n",
-				   __func__);
-			goto err4;
-		}
+	err = pfe_phy_init(ndev);
+	if (err) {
+		netdev_err(ndev, "%s: pfe_phy_init() failed\n",
+			   __func__);
+		goto err3;
 	}
 
 	if (us) {
@@ -2488,6 +2491,7 @@ phy_init:
 
 	netif_carrier_on(ndev);
 
+skip_phy_init:
 	/* Create all the sysfs files */
 	if (pfe_eth_sysfs_init(ndev))
 		goto err4;
@@ -2496,13 +2500,16 @@ phy_init:
 		   __func__, priv->EMAC_baseaddr);
 
 	return 0;
+
 err4:
+	pfe_phy_exit(priv->ndev);
+err3:
 	if (us)
-		goto err3;
+		goto err2;
 	unregister_netdev(ndev);
-err3:
-	pfe_eth_mdio_exit(priv->mii_bus);
 err2:
+	pfe_eth_mdio_exit(priv->mii_bus);
+err1:
 	free_netdev(priv->ndev);
 err0:
 	return err;
@@ -2553,9 +2560,16 @@ static void pfe_eth_exit_one(struct pfe_
 	if (!us)
 		pfe_eth_sysfs_exit(priv->ndev);
 
-	if (!(priv->einfo->phy_flags & GEMAC_NO_PHY))
-		pfe_phy_exit(priv->ndev);
+	if ((!(pfe_use_old_dts_phy) && !(priv->phy_node)) ||
+	    ((pfe_use_old_dts_phy) &&
+	      (priv->einfo->phy_flags & GEMAC_NO_PHY))) {
+		pr_info("%s: No PHY or fixed-link\n", __func__);
+		goto skip_phy_exit;
+	}
+
+	pfe_phy_exit(priv->ndev);
 
+skip_phy_exit:
 	if (!us)
 		unregister_netdev(priv->ndev);
 
--- a/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
+++ b/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
@@ -18,6 +18,7 @@
 
 #include "pfe_mod.h"
 
+extern bool pfe_use_old_dts_phy;
 struct ls1012a_pfe_platform_data pfe_platform_data;
 
 static int pfe_get_gemac_if_properties(struct device_node *parent, int port, int
@@ -64,8 +65,10 @@ static int pfe_get_gemac_if_properties(s
 	phy_node = of_parse_phandle(gem, "phy-handle", 0);
 	pdata->ls1012a_eth_pdata[port].phy_node = phy_node;
 	if (phy_node) {
+		pfe_use_old_dts_phy = false;
 		goto process_phynode;
 	} else if (of_phy_is_fixed_link(gem)) {
+		pfe_use_old_dts_phy = false;
 		if (of_phy_register_fixed_link(gem) < 0) {
 			pr_err("broken fixed-link specification\n");
 			goto err;
@@ -73,6 +76,7 @@ static int pfe_get_gemac_if_properties(s
 		phy_node = of_node_get(gem);
 		pdata->ls1012a_eth_pdata[port].phy_node = phy_node;
 	} else if (of_get_property(gem, "fsl,pfe-phy-if-flags", &size)) {
+		pfe_use_old_dts_phy = true;
 		/* Use old dts properties for phy handling */
 		addr = of_get_property(gem, "fsl,pfe-phy-if-flags", &size);
 		pdata->ls1012a_eth_pdata[port].phy_flags = be32_to_cpup(addr);