aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/layerscape/patches-5.4/701-net-0317-staging-fsl_ppfe-eth-separate-mdio-init-from-mac-ini.patch
blob: fbf13c8ffc4f5c278ea102796130819438c65aa5 (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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
From 8848f975ce42674b8bc8dedb5c7b326a42088e99 Mon Sep 17 00:00:00 2001
From: Calvin Johnson <calvin.johnson@nxp.com>
Date: Mon, 10 Dec 2018 10:22:33 +0530
Subject: [PATCH] staging: fsl_ppfe/eth: separate mdio init from mac init

- separate mdio initialization from mac initialization
- Define pfe_mdio_priv_s structure to hold mii_bus structure and other
  related data.
- Modify functions to work with the separted mdio init model.

Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
---
 drivers/staging/fsl_ppfe/pfe_eth.c              | 232 ++++++++++--------------
 drivers/staging/fsl_ppfe/pfe_eth.h              |  17 +-
 drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c |  50 ++---
 drivers/staging/fsl_ppfe/pfe_mod.h              |   1 +
 4 files changed, 126 insertions(+), 174 deletions(-)

--- a/drivers/staging/fsl_ppfe/pfe_eth.c
+++ b/drivers/staging/fsl_ppfe/pfe_eth.c
@@ -790,10 +790,9 @@ const struct ethtool_ops pfe_ethtool_ops
  */
 int pfe_eth_mdio_reset(struct mii_bus *bus)
 {
-	struct pfe_eth_priv_s *priv = (struct pfe_eth_priv_s *)bus->priv;
+	struct pfe_mdio_priv_s *priv = (struct pfe_mdio_priv_s *)bus->priv;
 	u32 phy_speed;
 
-	netif_info(priv, hw, priv->ndev, "%s\n", __func__);
 
 	mutex_lock(&bus->mdio_lock);
 
@@ -806,25 +805,25 @@ int pfe_eth_mdio_reset(struct mii_bus *b
 	phy_speed = (DIV_ROUND_UP((pfe->ctrl.sys_clk * 1000), 4000000)
 		     << EMAC_MII_SPEED_SHIFT);
 	phy_speed |= EMAC_HOLDTIME(0x5);
-	__raw_writel(phy_speed, priv->PHY_baseaddr + EMAC_MII_CTRL_REG);
+	__raw_writel(phy_speed, priv->mdio_base + EMAC_MII_CTRL_REG);
 
 	mutex_unlock(&bus->mdio_lock);
 
 	return 0;
 }
 
-/* pfe_eth_gemac_phy_timeout
+/* pfe_eth_mdio_timeout
  *
  */
-static int pfe_eth_gemac_phy_timeout(struct pfe_eth_priv_s *priv, int timeout)
+static int pfe_eth_mdio_timeout(struct pfe_mdio_priv_s *priv, int timeout)
 {
-	while (!(__raw_readl(priv->PHY_baseaddr + EMAC_IEVENT_REG) &
+	while (!(__raw_readl(priv->mdio_base + EMAC_IEVENT_REG) &
 			EMAC_IEVENT_MII)) {
 		if (timeout-- <= 0)
 			return -1;
 		usleep_range(10, 20);
 	}
-	__raw_writel(EMAC_IEVENT_MII, priv->PHY_baseaddr + EMAC_IEVENT_REG);
+	__raw_writel(EMAC_IEVENT_MII, priv->mdio_base + EMAC_IEVENT_REG);
 	return 0;
 }
 
@@ -856,16 +855,15 @@ static int pfe_eth_mdio_mux(u8 muxval)
 static int pfe_eth_mdio_write_addr(struct mii_bus *bus, int mii_id,
 				   int dev_addr, int regnum)
 {
-	struct pfe_eth_priv_s *priv = (struct pfe_eth_priv_s *)bus->priv;
+	struct pfe_mdio_priv_s *priv = (struct pfe_mdio_priv_s *)bus->priv;
 
 	__raw_writel(EMAC_MII_DATA_PA(mii_id) |
 		     EMAC_MII_DATA_RA(dev_addr) |
 		     EMAC_MII_DATA_TA | EMAC_MII_DATA(regnum),
-		     priv->PHY_baseaddr + EMAC_MII_DATA_REG);
+		     priv->mdio_base + EMAC_MII_DATA_REG);
 
-	if (pfe_eth_gemac_phy_timeout(priv, EMAC_MDIO_TIMEOUT)) {
-		netdev_err(priv->ndev, "%s: phy MDIO address write timeout\n",
-			   __func__);
+	if (pfe_eth_mdio_timeout(priv, EMAC_MDIO_TIMEOUT)) {
+		dev_err(&bus->dev, "phy MDIO address write timeout\n");
 		return -1;
 	}
 
@@ -875,7 +873,7 @@ static int pfe_eth_mdio_write_addr(struc
 static int pfe_eth_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
 			      u16 value)
 {
-	struct pfe_eth_priv_s *priv = (struct pfe_eth_priv_s *)bus->priv;
+	struct pfe_mdio_priv_s *priv = (struct pfe_mdio_priv_s *)bus->priv;
 
 	/*To access external PHYs on QDS board mux needs to be configured*/
 	if ((mii_id) && (pfe->mdio_muxval[mii_id]))
@@ -888,30 +886,26 @@ static int pfe_eth_mdio_write(struct mii
 			     EMAC_MII_DATA_PA(mii_id) |
 			     EMAC_MII_DATA_RA((regnum >> 16) & 0x1f) |
 			     EMAC_MII_DATA_TA | EMAC_MII_DATA(value),
-			     priv->PHY_baseaddr + EMAC_MII_DATA_REG);
+			     priv->mdio_base + EMAC_MII_DATA_REG);
 	} else {
 		/* start a write op */
 		__raw_writel(EMAC_MII_DATA_ST | EMAC_MII_DATA_OP_WR |
 			     EMAC_MII_DATA_PA(mii_id) |
 			     EMAC_MII_DATA_RA(regnum) |
 			     EMAC_MII_DATA_TA | EMAC_MII_DATA(value),
-			     priv->PHY_baseaddr + EMAC_MII_DATA_REG);
+			     priv->mdio_base + EMAC_MII_DATA_REG);
 	}
 
-	if (pfe_eth_gemac_phy_timeout(priv, EMAC_MDIO_TIMEOUT)) {
-		netdev_err(priv->ndev, "%s: phy MDIO write timeout\n",
-			   __func__);
+	if (pfe_eth_mdio_timeout(priv, EMAC_MDIO_TIMEOUT)) {
+		dev_err(&bus->dev, "%s: phy MDIO write timeout\n", __func__);
 		return -1;
 	}
-	netif_info(priv, hw, priv->ndev, "%s: phy %x reg %x val %x\n", __func__,
-		   mii_id, regnum, value);
-
 	return 0;
 }
 
 static int pfe_eth_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
 {
-	struct pfe_eth_priv_s *priv = (struct pfe_eth_priv_s *)bus->priv;
+	struct pfe_mdio_priv_s *priv = (struct pfe_mdio_priv_s *)bus->priv;
 	u16 value = 0;
 
 	/*To access external PHYs on QDS board mux needs to be configured*/
@@ -925,65 +919,67 @@ static int pfe_eth_mdio_read(struct mii_
 			     EMAC_MII_DATA_PA(mii_id) |
 			     EMAC_MII_DATA_RA((regnum >> 16) & 0x1f) |
 			     EMAC_MII_DATA_TA,
-			     priv->PHY_baseaddr + EMAC_MII_DATA_REG);
+			     priv->mdio_base + EMAC_MII_DATA_REG);
 	} else {
 		/* start a read op */
 		__raw_writel(EMAC_MII_DATA_ST | EMAC_MII_DATA_OP_RD |
 			     EMAC_MII_DATA_PA(mii_id) |
 			     EMAC_MII_DATA_RA(regnum) |
-			     EMAC_MII_DATA_TA, priv->PHY_baseaddr +
+			     EMAC_MII_DATA_TA, priv->mdio_base +
 			     EMAC_MII_DATA_REG);
 	}
 
-	if (pfe_eth_gemac_phy_timeout(priv, EMAC_MDIO_TIMEOUT)) {
-		netdev_err(priv->ndev, "%s: phy MDIO read timeout\n", __func__);
+	if (pfe_eth_mdio_timeout(priv, EMAC_MDIO_TIMEOUT)) {
+		dev_err(&bus->dev, "%s: phy MDIO read timeout\n", __func__);
 		return -1;
 	}
 
-	value = EMAC_MII_DATA(__raw_readl(priv->PHY_baseaddr +
+	value = EMAC_MII_DATA(__raw_readl(priv->mdio_base +
 						EMAC_MII_DATA_REG));
-	netif_info(priv, hw, priv->ndev, "%s: phy %x reg %x val %x\n", __func__,
-		   mii_id, regnum, value);
 	return value;
 }
 
-static int pfe_eth_mdio_init(struct pfe_eth_priv_s *priv,
-			     struct ls1012a_mdio_platform_data *minfo)
+static int pfe_eth_mdio_init(struct pfe *pfe,
+			     struct ls1012a_pfe_platform_data *pfe_info,
+			     int ii)
 {
+	struct pfe_mdio_priv_s *priv = NULL;
+	struct ls1012a_mdio_platform_data *mdio_info;
 	struct mii_bus *bus;
 	struct device_node *mdio_node;
-	int rc = 0, ii;
-	struct phy_device *phydev;
+	int rc = 0;
 
-	netif_info(priv, drv, priv->ndev, "%s\n", __func__);
-	pr_info("%s\n", __func__);
+	mdio_info = (struct ls1012a_mdio_platform_data *)
+					pfe_info->ls1012a_mdio_pdata;
+	mdio_info->id = ii;
 
-	bus = mdiobus_alloc();
+	bus = mdiobus_alloc_size(sizeof(struct pfe_mdio_priv_s));
 	if (!bus) {
-		netdev_err(priv->ndev, "mdiobus_alloc() failed\n");
+		pr_err("mdiobus_alloc() failed\n");
 		rc = -ENOMEM;
-		goto err0;
+		goto err_mdioalloc;
 	}
 
 	bus->name = "ls1012a MDIO Bus";
-	snprintf(bus->id, MII_BUS_ID_SIZE, "ls1012a-%x", priv->id);
+	snprintf(bus->id, MII_BUS_ID_SIZE, "ls1012a-%x", mdio_info->id);
 
-	bus->priv = priv;
 	bus->read = &pfe_eth_mdio_read;
 	bus->write = &pfe_eth_mdio_write;
 	bus->reset = &pfe_eth_mdio_reset;
-	bus->parent = priv->pfe->dev;
-	bus->phy_mask = minfo->phy_mask;
-	bus->irq[0] = minfo->irq[0];
+	bus->parent = pfe->dev;
+	bus->phy_mask = mdio_info->phy_mask;
+	bus->irq[0] = mdio_info->irq[0];
+	priv = bus->priv;
+	priv->mdio_base = cbus_emac_base[ii];
 
-	priv->mdc_div = minfo->mdc_div;
+	priv->mdc_div = mdio_info->mdc_div;
 	if (!priv->mdc_div)
 		priv->mdc_div = 64;
-	netif_info(priv, drv, priv->ndev, "%s: mdc_div: %d, phy_mask: %x\n",
-		   __func__, priv->mdc_div, bus->phy_mask);
+		dev_info(bus->parent, "%s: mdc_div: %d, phy_mask: %x\n",
+			 __func__, priv->mdc_div, bus->phy_mask);
 
-	mdio_node = of_get_child_by_name(priv->pfe->dev->of_node, "mdio");
-	if (mdio_node) {
+	mdio_node = of_get_child_by_name(pfe->dev->of_node, "mdio");
+	if ((mdio_info->id == 0) && mdio_node) {
 		rc = of_mdiobus_register(bus, mdio_node);
 		of_node_put(mdio_node);
 	} else {
@@ -991,56 +987,34 @@ static int pfe_eth_mdio_init(struct pfe_
 	}
 
 	if (rc) {
-		netdev_err(priv->ndev, "mdiobus_register(%s) failed\n",
-			   bus->name);
-		goto err1;
+		dev_err(bus->parent, "mdiobus_register(%s) failed\n",
+			bus->name);
+		goto err_mdioregister;
 	}
 
 	priv->mii_bus = bus;
-
-	/* For clause 45 we need to call get_phy_device() with it's
-	 * 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,
-					priv->einfo->phy_id + ii, true);
-			if (!phydev || IS_ERR(phydev)) {
-				rc = -EIO;
-				netdev_err(priv->ndev, "fail to get device\n");
-				goto err1;
-			}
-			rc = phy_device_register(phydev);
-			if (rc) {
-				phy_device_free(phydev);
-				netdev_err(priv->ndev,
-					"phy_device_register() failed\n");
-				goto err1;
-			}
-		}
-	}
+	pfe->mdio.mdio_priv[ii] = priv;
 
 	pfe_eth_mdio_reset(bus);
 
 	return 0;
 
-err1:
+err_mdioregister:
 	mdiobus_free(bus);
-err0:
+err_mdioalloc:
 	return rc;
 }
 
 /* pfe_eth_mdio_exit
  */
-static void pfe_eth_mdio_exit(struct mii_bus *bus)
+static void pfe_eth_mdio_exit(struct pfe *pfe,
+			      int ii)
 {
+	struct pfe_mdio_priv_s *mdio_priv = pfe->mdio.mdio_priv[ii];
+	struct mii_bus *bus = mdio_priv->mii_bus;
+
 	if (!bus)
 		return;
-
-	netif_info((struct pfe_eth_priv_s *)bus->priv, drv, ((struct
-			pfe_eth_priv_s *)(bus->priv))->ndev, "%s\n", __func__);
-
 	mdiobus_unregister(bus);
 	mdiobus_free(bus);
 }
@@ -1221,15 +1195,16 @@ static int pfe_eth_start(struct pfe_eth_
  */
 static void ls1012a_configure_serdes(struct net_device *ndev)
 {
-	struct pfe_eth_priv_s *priv = pfe->eth.eth_priv[0];
+	struct pfe_eth_priv_s *eth_priv = netdev_priv(ndev);
+	struct pfe_mdio_priv_s *mdio_priv = pfe->mdio.mdio_priv[eth_priv->id];
 	int sgmii_2500 = 0;
-	struct mii_bus *bus = priv->mii_bus;
+	struct mii_bus *bus = mdio_priv->mii_bus;
 	u16 value = 0;
 
-	if (priv->einfo->mii_config == PHY_INTERFACE_MODE_2500SGMII)
+	if (eth_priv->einfo->mii_config == PHY_INTERFACE_MODE_2500SGMII)
 		sgmii_2500 = 1;
 
-	netif_info(priv, drv, ndev, "%s\n", __func__);
+	netif_info(eth_priv, drv, ndev, "%s\n", __func__);
 	/* PCS configuration done with corresponding GEMAC */
 
 	pfe_eth_mdio_read(bus, 0, MDIO_SGMII_CR);
@@ -2333,26 +2308,15 @@ static const struct net_device_ops pfe_n
 
 /* pfe_eth_init_one
  */
-static int pfe_eth_init_one(struct pfe *pfe, int id)
+static int pfe_eth_init_one(struct pfe *pfe,
+			    struct ls1012a_pfe_platform_data *pfe_info,
+			    int id)
 {
 	struct net_device *ndev = NULL;
 	struct pfe_eth_priv_s *priv = NULL;
 	struct ls1012a_eth_platform_data *einfo;
-	struct ls1012a_mdio_platform_data *minfo;
-	struct ls1012a_pfe_platform_data *pfe_info;
 	int err;
 
-	/* Extract pltform data */
-	pfe_info = (struct ls1012a_pfe_platform_data *)
-					pfe->dev->platform_data;
-	if (!pfe_info) {
-		pr_err(
-			"%s: pfe missing additional platform data\n"
-			, __func__);
-		err = -ENODEV;
-		goto err0;
-	}
-
 	einfo = (struct ls1012a_eth_platform_data *)
 				pfe_info->ls1012a_eth_pdata;
 
@@ -2365,18 +2329,6 @@ static int pfe_eth_init_one(struct pfe *
 		goto err0;
 	}
 
-	minfo = (struct ls1012a_mdio_platform_data *)
-				pfe_info->ls1012a_mdio_pdata;
-
-	/* einfo never be NULL, but no harm in having this check */
-	if (!minfo) {
-		pr_err(
-			"%s: pfe missing additional mdios platform data\n",
-			 __func__);
-		err = -ENODEV;
-		goto err0;
-	}
-
 	if (us)
 		emac_txq_cnt = EMAC_TXQ_CNT;
 	/* Create an ethernet device instance */
@@ -2402,7 +2354,6 @@ static int pfe_eth_init_one(struct pfe *
 	/* Set the info in the priv to the current info */
 	priv->einfo = &einfo[id];
 	priv->EMAC_baseaddr = cbus_emac_base[id];
-	priv->PHY_baseaddr = cbus_emac_base[0];
 	priv->GPI_baseaddr = cbus_gpi_base[id];
 
 	spin_lock_init(&priv->lock);
@@ -2412,13 +2363,6 @@ static int pfe_eth_init_one(struct pfe *
 	/* Copy the station address into the dev structure, */
 	memcpy(ndev->dev_addr, einfo[id].mac_addr, ETH_ALEN);
 
-	/* Initialize mdio */
-	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)
 		goto phy_init;
 
@@ -2463,7 +2407,7 @@ static int pfe_eth_init_one(struct pfe *
 	err = register_netdev(ndev);
 	if (err) {
 		netdev_err(ndev, "register_netdev() failed\n");
-		goto err2;
+		goto err1;
 	}
 
 	if ((!(pfe_use_old_dts_phy) && !(priv->phy_node)) ||
@@ -2480,7 +2424,7 @@ phy_init:
 	if (err) {
 		netdev_err(ndev, "%s: pfe_phy_init() failed\n",
 			   __func__);
-		goto err3;
+		goto err2;
 	}
 
 	if (us) {
@@ -2494,21 +2438,19 @@ phy_init:
 skip_phy_init:
 	/* Create all the sysfs files */
 	if (pfe_eth_sysfs_init(ndev))
-		goto err4;
+		goto err3;
 
 	netif_info(priv, probe, ndev, "%s: created interface, baseaddr: %p\n",
 		   __func__, priv->EMAC_baseaddr);
 
 	return 0;
 
-err4:
-	pfe_phy_exit(priv->ndev);
 err3:
+	pfe_phy_exit(priv->ndev);
+err2:
 	if (us)
-		goto err2;
+		goto err1;
 	unregister_netdev(ndev);
-err2:
-	pfe_eth_mdio_exit(priv->mii_bus);
 err1:
 	free_netdev(priv->ndev);
 err0:
@@ -2521,6 +2463,7 @@ int pfe_eth_init(struct pfe *pfe)
 {
 	int ii = 0;
 	int err;
+	struct ls1012a_pfe_platform_data *pfe_info;
 
 	pr_info("%s\n", __func__);
 
@@ -2530,24 +2473,43 @@ int pfe_eth_init(struct pfe *pfe)
 	cbus_gpi_base[0] = EGPI1_BASE_ADDR;
 	cbus_gpi_base[1] = EGPI2_BASE_ADDR;
 
+	pfe_info = (struct ls1012a_pfe_platform_data *)
+					pfe->dev->platform_data;
+	if (!pfe_info) {
+		pr_err("%s: pfe missing additional platform data\n", __func__);
+		err = -ENODEV;
+		goto err_pdata;
+	}
+
+	for (ii = 0; ii < NUM_GEMAC_SUPPORT; ii++) {
+		err = pfe_eth_mdio_init(pfe, pfe_info, ii);
+		if (err) {
+			pr_err("%s: pfe_eth_mdio_init() failed\n", __func__);
+			goto err_mdio_init;
+		}
+	}
+
 	if (fsl_guts_get_svr() == LS1012A_REV_1_0)
 		pfe_errata_a010897 = true;
 	else
 		pfe_errata_a010897 = false;
 
 	for (ii = 0; ii < NUM_GEMAC_SUPPORT; ii++) {
-		err = pfe_eth_init_one(pfe, ii);
+		err = pfe_eth_init_one(pfe, pfe_info, ii);
 		if (err)
-			goto err0;
+			goto err_eth_init;
 	}
 
 	return 0;
 
-err0:
-	while (ii--)
+err_eth_init:
+	while (ii--) {
 		pfe_eth_exit_one(pfe->eth.eth_priv[ii]);
+		pfe_eth_mdio_exit(pfe, ii);
+	}
 
-	/* Register three network devices in the kernel */
+err_mdio_init:
+err_pdata:
 	return err;
 }
 
@@ -2573,9 +2535,6 @@ skip_phy_exit:
 	if (!us)
 		unregister_netdev(priv->ndev);
 
-	if (priv->mii_bus)
-		pfe_eth_mdio_exit(priv->mii_bus);
-
 	free_netdev(priv->ndev);
 }
 
@@ -2589,4 +2548,7 @@ void pfe_eth_exit(struct pfe *pfe)
 
 	for (ii = NUM_GEMAC_SUPPORT - 1; ii >= 0; ii--)
 		pfe_eth_exit_one(pfe->eth.eth_priv[ii]);
+
+	for (ii = NUM_GEMAC_SUPPORT - 1; ii >= 0; ii--)
+		pfe_eth_mdio_exit(pfe, ii);
 }
--- a/drivers/staging/fsl_ppfe/pfe_eth.h
+++ b/drivers/staging/fsl_ppfe/pfe_eth.h
@@ -48,7 +48,7 @@ struct ls1012a_eth_platform_data {
 };
 
 struct ls1012a_mdio_platform_data {
-	int enabled;
+	int id;
 	int irq[32];
 	u32 phy_mask;
 	int mdc_div;
@@ -120,8 +120,6 @@ struct  pfe_eth_priv_s {
 	unsigned int		event_status;
 	int			irq;
 	void			*EMAC_baseaddr;
-	/* This points to the EMAC base from where we access PHY */
-	void			*PHY_baseaddr;
 	void			*GPI_baseaddr;
 	/* PHY stuff */
 	struct phy_device	*phydev;
@@ -129,9 +127,6 @@ struct  pfe_eth_priv_s {
 	int			oldduplex;
 	int			oldlink;
 	struct device_node	*phy_node;
-	/* mdio info */
-	int			mdc_div;
-	struct mii_bus		*mii_bus;
 	struct clk		*gemtx_clk;
 	int			wol;
 	int			pause_flag;
@@ -161,6 +156,16 @@ struct pfe_eth {
 	struct pfe_eth_priv_s *eth_priv[3];
 };
 
+struct pfe_mdio_priv_s {
+	void __iomem *mdio_base;
+	int			mdc_div;
+	struct mii_bus		*mii_bus;
+};
+
+struct pfe_mdio {
+	struct pfe_mdio_priv_s *mdio_priv[3];
+};
+
 int pfe_eth_init(struct pfe *pfe);
 void pfe_eth_exit(struct pfe *pfe);
 int pfe_eth_suspend(struct net_device *dev);
--- a/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
+++ b/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
@@ -21,31 +21,18 @@
 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
-					if_cnt,
-					struct ls1012a_pfe_platform_data
-					*pdata)
+static int pfe_get_gemac_if_properties(struct device_node *gem,
+				       int port,
+				       struct ls1012a_pfe_platform_data	*pdata)
 {
-	struct device_node *gem = NULL, *phy = NULL, *phy_node = NULL;
+	struct device_node *phy_node = NULL;
 	int size;
-	int ii = 0, phy_id = 0;
+	int phy_id = 0;
 	const u32 *addr;
 	const void *mac_addr;
 
-	for (ii = 0; ii < if_cnt; ii++) {
-		gem = of_get_next_child(parent, gem);
-		if (!gem)
-			goto err;
-		addr = of_get_property(gem, "reg", &size);
-		if (addr && (be32_to_cpup(addr) == port))
-			break;
-	}
-
-	if (ii >= if_cnt) {
-		pr_err("%s:%d Failed to find interface = %d\n",
-		       __func__, __LINE__, if_cnt);
-		goto err;
-	}
+	addr = of_get_property(gem, "reg", &size);
+	port = be32_to_cpup(addr);
 
 	pdata->ls1012a_eth_pdata[port].gem_id = port;
 
@@ -88,14 +75,6 @@ static int pfe_get_gemac_if_properties(s
 		if (pdata->ls1012a_eth_pdata[port].phy_flags & GEMAC_NO_PHY)
 			goto done;
 
-		phy = of_get_next_child(gem, NULL);
-		addr = of_get_property(phy, "reg", &size);
-		if (!addr)
-			pr_err("%s:%d Invalid phy enable flag....\n",
-			       __func__, __LINE__);
-		else
-			pdata->ls1012a_mdio_pdata[port].enabled =
-							be32_to_cpup(addr);
 	} else {
 		pr_info("%s: No PHY or fixed-link\n", __func__);
 		return 0;
@@ -140,7 +119,7 @@ static int pfe_platform_probe(struct pla
 	struct resource res;
 	int ii, rc, interface_count = 0, size = 0;
 	const u32 *prop;
-	struct device_node  *np;
+	struct device_node *np, *gem = NULL;
 	struct clk *pfe_clk;
 
 	np = pdev->dev.of_node;
@@ -224,8 +203,13 @@ static int pfe_platform_probe(struct pla
 	pfe_platform_data.ls1012a_mdio_pdata[0].phy_mask = 0xffffffff;
 
 	for (ii = 0; ii < interface_count; ii++) {
-		pfe_get_gemac_if_properties(np, ii, interface_count,
-					    &pfe_platform_data);
+		gem = of_get_next_child(np, gem);
+		if (gem)
+			pfe_get_gemac_if_properties(gem, ii,
+						    &pfe_platform_data);
+		else
+			pr_err("Unable to find interface %d\n", ii);
+
 	}
 
 	pfe->dev = &pdev->dev;
@@ -347,8 +331,8 @@ static int pfe_platform_resume(struct de
 	for (i = 0; i < (NUM_GEMAC_SUPPORT); i++) {
 		netdev = pfe->eth.eth_priv[i]->ndev;
 
-		if (pfe->eth.eth_priv[i]->mii_bus)
-			pfe_eth_mdio_reset(pfe->eth.eth_priv[i]->mii_bus);
+		if (pfe->mdio.mdio_priv[i]->mii_bus)
+			pfe_eth_mdio_reset(pfe->mdio.mdio_priv[i]->mii_bus);
 
 		if (netif_running(netdev))
 			pfe_eth_resume(netdev);
--- a/drivers/staging/fsl_ppfe/pfe_mod.h
+++ b/drivers/staging/fsl_ppfe/pfe_mod.h
@@ -52,6 +52,7 @@ struct pfe {
 	struct pfe_ctrl ctrl;
 	struct pfe_hif hif;
 	struct pfe_eth eth;
+	struct pfe_mdio mdio;
 	struct hif_client_s *hif_client[HIF_CLIENTS_MAX];
 #if defined(CFG_DIAGS)
 	struct pfe_diags diags;