aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/freescale
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-06-12 17:27:40 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-06-12 17:27:40 -0400
commitf9da455b93f6ba076935b4ef4589f61e529ae046 (patch)
tree3c4e69ce1ba1d6bf65915b97a76ca2172105b278 /drivers/net/ethernet/freescale
parent0e04c641b199435f3779454055f6a7de258ecdfc (diff)
parente5eca6d41f53db48edd8cf88a3f59d2c30227f8e (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
Pull networking updates from David Miller: 1) Seccomp BPF filters can now be JIT'd, from Alexei Starovoitov. 2) Multiqueue support in xen-netback and xen-netfront, from Andrew J Benniston. 3) Allow tweaking of aggregation settings in cdc_ncm driver, from Bjørn Mork. 4) BPF now has a "random" opcode, from Chema Gonzalez. 5) Add more BPF documentation and improve test framework, from Daniel Borkmann. 6) Support TCP fastopen over ipv6, from Daniel Lee. 7) Add software TSO helper functions and use them to support software TSO in mvneta and mv643xx_eth drivers. From Ezequiel Garcia. 8) Support software TSO in fec driver too, from Nimrod Andy. 9) Add Broadcom SYSTEMPORT driver, from Florian Fainelli. 10) Handle broadcasts more gracefully over macvlan when there are large numbers of interfaces configured, from Herbert Xu. 11) Allow more control over fwmark used for non-socket based responses, from Lorenzo Colitti. 12) Do TCP congestion window limiting based upon measurements, from Neal Cardwell. 13) Support busy polling in SCTP, from Neal Horman. 14) Allow RSS key to be configured via ethtool, from Venkata Duvvuru. 15) Bridge promisc mode handling improvements from Vlad Yasevich. 16) Don't use inetpeer entries to implement ID generation any more, it performs poorly, from Eric Dumazet. * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next: (1522 commits) rtnetlink: fix userspace API breakage for iproute2 < v3.9.0 tcp: fixing TLP's FIN recovery net: fec: Add software TSO support net: fec: Add Scatter/gather support net: fec: Increase buffer descriptor entry number net: fec: Factorize feature setting net: fec: Enable IP header hardware checksum net: fec: Factorize the .xmit transmit function bridge: fix compile error when compiling without IPv6 support bridge: fix smatch warning / potential null pointer dereference via-rhine: fix full-duplex with autoneg disable bnx2x: Enlarge the dorq threshold for VFs bnx2x: Check for UNDI in uncommon branch bnx2x: Fix 1G-baseT link bnx2x: Fix link for KR with swapped polarity lane sctp: Fix sk_ack_backlog wrap-around problem net/core: Add VF link state control policy net/fsl: xgmac_mdio is dependent on OF_MDIO net/fsl: Make xgmac_mdio read error message useful net_sched: drr: warn when qdisc is not work conserving ...
Diffstat (limited to 'drivers/net/ethernet/freescale')
-rw-r--r--drivers/net/ethernet/freescale/Kconfig1
-rw-r--r--drivers/net/ethernet/freescale/fec.h13
-rw-r--r--drivers/net/ethernet/freescale/fec_main.c661
-rw-r--r--drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c17
-rw-r--r--drivers/net/ethernet/freescale/gianfar.c22
-rw-r--r--drivers/net/ethernet/freescale/ucc_geth.c14
-rw-r--r--drivers/net/ethernet/freescale/ucc_geth_ethtool.c2
-rw-r--r--drivers/net/ethernet/freescale/xgmac_mdio.c4
8 files changed, 550 insertions, 184 deletions
diff --git a/drivers/net/ethernet/freescale/Kconfig b/drivers/net/ethernet/freescale/Kconfig
index 6048dc8604ee..270308315d43 100644
--- a/drivers/net/ethernet/freescale/Kconfig
+++ b/drivers/net/ethernet/freescale/Kconfig
@@ -67,6 +67,7 @@ config FSL_XGMAC_MDIO
67 tristate "Freescale XGMAC MDIO" 67 tristate "Freescale XGMAC MDIO"
68 depends on FSL_SOC 68 depends on FSL_SOC
69 select PHYLIB 69 select PHYLIB
70 select OF_MDIO
70 ---help--- 71 ---help---
71 This driver supports the MDIO bus on the Fman 10G Ethernet MACs. 72 This driver supports the MDIO bus on the Fman 10G Ethernet MACs.
72 73
diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h
index 3b8d6d19ff05..671d080105a7 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -221,7 +221,7 @@ struct bufdesc_ex {
221#define BD_ENET_TX_RCMASK ((ushort)0x003c) 221#define BD_ENET_TX_RCMASK ((ushort)0x003c)
222#define BD_ENET_TX_UN ((ushort)0x0002) 222#define BD_ENET_TX_UN ((ushort)0x0002)
223#define BD_ENET_TX_CSL ((ushort)0x0001) 223#define BD_ENET_TX_CSL ((ushort)0x0001)
224#define BD_ENET_TX_STATS ((ushort)0x03ff) /* All status bits */ 224#define BD_ENET_TX_STATS ((ushort)0x0fff) /* All status bits */
225 225
226/*enhanced buffer descriptor control/status used by Ethernet transmit*/ 226/*enhanced buffer descriptor control/status used by Ethernet transmit*/
227#define BD_ENET_TX_INT 0x40000000 227#define BD_ENET_TX_INT 0x40000000
@@ -246,8 +246,8 @@ struct bufdesc_ex {
246#define RX_RING_SIZE (FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES) 246#define RX_RING_SIZE (FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES)
247#define FEC_ENET_TX_FRSIZE 2048 247#define FEC_ENET_TX_FRSIZE 2048
248#define FEC_ENET_TX_FRPPG (PAGE_SIZE / FEC_ENET_TX_FRSIZE) 248#define FEC_ENET_TX_FRPPG (PAGE_SIZE / FEC_ENET_TX_FRSIZE)
249#define TX_RING_SIZE 16 /* Must be power of two */ 249#define TX_RING_SIZE 512 /* Must be power of two */
250#define TX_RING_MOD_MASK 15 /* for this to work */ 250#define TX_RING_MOD_MASK 511 /* for this to work */
251 251
252#define BD_ENET_RX_INT 0x00800000 252#define BD_ENET_RX_INT 0x00800000
253#define BD_ENET_RX_PTP ((ushort)0x0400) 253#define BD_ENET_RX_PTP ((ushort)0x0400)
@@ -296,8 +296,15 @@ struct fec_enet_private {
296 /* The ring entries to be free()ed */ 296 /* The ring entries to be free()ed */
297 struct bufdesc *dirty_tx; 297 struct bufdesc *dirty_tx;
298 298
299 unsigned short bufdesc_size;
299 unsigned short tx_ring_size; 300 unsigned short tx_ring_size;
300 unsigned short rx_ring_size; 301 unsigned short rx_ring_size;
302 unsigned short tx_stop_threshold;
303 unsigned short tx_wake_threshold;
304
305 /* Software TSO */
306 char *tso_hdrs;
307 dma_addr_t tso_hdrs_dma;
301 308
302 struct platform_device *pdev; 309 struct platform_device *pdev;
303 310
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 8d69e439f0c5..38d9d276ab8b 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -36,6 +36,7 @@
36#include <linux/in.h> 36#include <linux/in.h>
37#include <linux/ip.h> 37#include <linux/ip.h>
38#include <net/ip.h> 38#include <net/ip.h>
39#include <net/tso.h>
39#include <linux/tcp.h> 40#include <linux/tcp.h>
40#include <linux/udp.h> 41#include <linux/udp.h>
41#include <linux/icmp.h> 42#include <linux/icmp.h>
@@ -54,6 +55,7 @@
54#include <linux/of_net.h> 55#include <linux/of_net.h>
55#include <linux/regulator/consumer.h> 56#include <linux/regulator/consumer.h>
56#include <linux/if_vlan.h> 57#include <linux/if_vlan.h>
58#include <linux/pinctrl/consumer.h>
57 59
58#include <asm/cacheflush.h> 60#include <asm/cacheflush.h>
59 61
@@ -172,10 +174,6 @@ MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
172#endif 174#endif
173#endif /* CONFIG_M5272 */ 175#endif /* CONFIG_M5272 */
174 176
175#if (((RX_RING_SIZE + TX_RING_SIZE) * 32) > PAGE_SIZE)
176#error "FEC: descriptor ring size constants too large"
177#endif
178
179/* Interrupt events/masks. */ 177/* Interrupt events/masks. */
180#define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */ 178#define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
181#define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */ 179#define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
@@ -231,6 +229,15 @@ MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
231#define FEC_PAUSE_FLAG_AUTONEG 0x1 229#define FEC_PAUSE_FLAG_AUTONEG 0x1
232#define FEC_PAUSE_FLAG_ENABLE 0x2 230#define FEC_PAUSE_FLAG_ENABLE 0x2
233 231
232#define TSO_HEADER_SIZE 128
233/* Max number of allowed TCP segments for software TSO */
234#define FEC_MAX_TSO_SEGS 100
235#define FEC_MAX_SKB_DESCS (FEC_MAX_TSO_SEGS * 2 + MAX_SKB_FRAGS)
236
237#define IS_TSO_HEADER(txq, addr) \
238 ((addr >= txq->tso_hdrs_dma) && \
239 (addr < txq->tso_hdrs_dma + txq->tx_ring_size * TSO_HEADER_SIZE))
240
234static int mii_cnt; 241static int mii_cnt;
235 242
236static inline 243static inline
@@ -286,6 +293,22 @@ struct bufdesc *fec_enet_get_prevdesc(struct bufdesc *bdp, struct fec_enet_priva
286 return (new_bd < base) ? (new_bd + ring_size) : new_bd; 293 return (new_bd < base) ? (new_bd + ring_size) : new_bd;
287} 294}
288 295
296static int fec_enet_get_bd_index(struct bufdesc *base, struct bufdesc *bdp,
297 struct fec_enet_private *fep)
298{
299 return ((const char *)bdp - (const char *)base) / fep->bufdesc_size;
300}
301
302static int fec_enet_get_free_txdesc_num(struct fec_enet_private *fep)
303{
304 int entries;
305
306 entries = ((const char *)fep->dirty_tx -
307 (const char *)fep->cur_tx) / fep->bufdesc_size - 1;
308
309 return entries > 0 ? entries : entries + fep->tx_ring_size;
310}
311
289static void *swap_buffer(void *bufaddr, int len) 312static void *swap_buffer(void *bufaddr, int len)
290{ 313{
291 int i; 314 int i;
@@ -307,33 +330,133 @@ fec_enet_clear_csum(struct sk_buff *skb, struct net_device *ndev)
307 if (unlikely(skb_cow_head(skb, 0))) 330 if (unlikely(skb_cow_head(skb, 0)))
308 return -1; 331 return -1;
309 332
333 ip_hdr(skb)->check = 0;
310 *(__sum16 *)(skb->head + skb->csum_start + skb->csum_offset) = 0; 334 *(__sum16 *)(skb->head + skb->csum_start + skb->csum_offset) = 0;
311 335
312 return 0; 336 return 0;
313} 337}
314 338
315static netdev_tx_t 339static void
316fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev) 340fec_enet_submit_work(struct bufdesc *bdp, struct fec_enet_private *fep)
341{
342 const struct platform_device_id *id_entry =
343 platform_get_device_id(fep->pdev);
344 struct bufdesc *bdp_pre;
345
346 bdp_pre = fec_enet_get_prevdesc(bdp, fep);
347 if ((id_entry->driver_data & FEC_QUIRK_ERR006358) &&
348 !(bdp_pre->cbd_sc & BD_ENET_TX_READY)) {
349 fep->delay_work.trig_tx = true;
350 schedule_delayed_work(&(fep->delay_work.delay_work),
351 msecs_to_jiffies(1));
352 }
353}
354
355static int
356fec_enet_txq_submit_frag_skb(struct sk_buff *skb, struct net_device *ndev)
317{ 357{
318 struct fec_enet_private *fep = netdev_priv(ndev); 358 struct fec_enet_private *fep = netdev_priv(ndev);
319 const struct platform_device_id *id_entry = 359 const struct platform_device_id *id_entry =
320 platform_get_device_id(fep->pdev); 360 platform_get_device_id(fep->pdev);
321 struct bufdesc *bdp, *bdp_pre; 361 struct bufdesc *bdp = fep->cur_tx;
322 void *bufaddr; 362 struct bufdesc_ex *ebdp;
323 unsigned short status; 363 int nr_frags = skb_shinfo(skb)->nr_frags;
364 int frag, frag_len;
365 unsigned short status;
366 unsigned int estatus = 0;
367 skb_frag_t *this_frag;
324 unsigned int index; 368 unsigned int index;
369 void *bufaddr;
370 int i;
325 371
326 /* Fill in a Tx ring entry */ 372 for (frag = 0; frag < nr_frags; frag++) {
373 this_frag = &skb_shinfo(skb)->frags[frag];
374 bdp = fec_enet_get_nextdesc(bdp, fep);
375 ebdp = (struct bufdesc_ex *)bdp;
376
377 status = bdp->cbd_sc;
378 status &= ~BD_ENET_TX_STATS;
379 status |= (BD_ENET_TX_TC | BD_ENET_TX_READY);
380 frag_len = skb_shinfo(skb)->frags[frag].size;
381
382 /* Handle the last BD specially */
383 if (frag == nr_frags - 1) {
384 status |= (BD_ENET_TX_INTR | BD_ENET_TX_LAST);
385 if (fep->bufdesc_ex) {
386 estatus |= BD_ENET_TX_INT;
387 if (unlikely(skb_shinfo(skb)->tx_flags &
388 SKBTX_HW_TSTAMP && fep->hwts_tx_en))
389 estatus |= BD_ENET_TX_TS;
390 }
391 }
392
393 if (fep->bufdesc_ex) {
394 if (skb->ip_summed == CHECKSUM_PARTIAL)
395 estatus |= BD_ENET_TX_PINS | BD_ENET_TX_IINS;
396 ebdp->cbd_bdu = 0;
397 ebdp->cbd_esc = estatus;
398 }
399
400 bufaddr = page_address(this_frag->page.p) + this_frag->page_offset;
401
402 index = fec_enet_get_bd_index(fep->tx_bd_base, bdp, fep);
403 if (((unsigned long) bufaddr) & FEC_ALIGNMENT ||
404 id_entry->driver_data & FEC_QUIRK_SWAP_FRAME) {
405 memcpy(fep->tx_bounce[index], bufaddr, frag_len);
406 bufaddr = fep->tx_bounce[index];
407
408 if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
409 swap_buffer(bufaddr, frag_len);
410 }
411
412 bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, bufaddr,
413 frag_len, DMA_TO_DEVICE);
414 if (dma_mapping_error(&fep->pdev->dev, bdp->cbd_bufaddr)) {
415 dev_kfree_skb_any(skb);
416 if (net_ratelimit())
417 netdev_err(ndev, "Tx DMA memory map failed\n");
418 goto dma_mapping_error;
419 }
420
421 bdp->cbd_datlen = frag_len;
422 bdp->cbd_sc = status;
423 }
424
425 fep->cur_tx = bdp;
426
427 return 0;
428
429dma_mapping_error:
327 bdp = fep->cur_tx; 430 bdp = fep->cur_tx;
431 for (i = 0; i < frag; i++) {
432 bdp = fec_enet_get_nextdesc(bdp, fep);
433 dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
434 bdp->cbd_datlen, DMA_TO_DEVICE);
435 }
436 return NETDEV_TX_OK;
437}
328 438
329 status = bdp->cbd_sc; 439static int fec_enet_txq_submit_skb(struct sk_buff *skb, struct net_device *ndev)
440{
441 struct fec_enet_private *fep = netdev_priv(ndev);
442 const struct platform_device_id *id_entry =
443 platform_get_device_id(fep->pdev);
444 int nr_frags = skb_shinfo(skb)->nr_frags;
445 struct bufdesc *bdp, *last_bdp;
446 void *bufaddr;
447 unsigned short status;
448 unsigned short buflen;
449 unsigned int estatus = 0;
450 unsigned int index;
451 int entries_free;
452 int ret;
330 453
331 if (status & BD_ENET_TX_READY) { 454 entries_free = fec_enet_get_free_txdesc_num(fep);
332 /* Ooops. All transmit buffers are full. Bail out. 455 if (entries_free < MAX_SKB_FRAGS + 1) {
333 * This should not happen, since ndev->tbusy should be set. 456 dev_kfree_skb_any(skb);
334 */ 457 if (net_ratelimit())
335 netdev_err(ndev, "tx queue full!\n"); 458 netdev_err(ndev, "NOT enough BD for SG!\n");
336 return NETDEV_TX_BUSY; 459 return NETDEV_TX_OK;
337 } 460 }
338 461
339 /* Protocol checksum off-load for TCP and UDP. */ 462 /* Protocol checksum off-load for TCP and UDP. */
@@ -342,102 +465,300 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
342 return NETDEV_TX_OK; 465 return NETDEV_TX_OK;
343 } 466 }
344 467
345 /* Clear all of the status flags */ 468 /* Fill in a Tx ring entry */
469 bdp = fep->cur_tx;
470 status = bdp->cbd_sc;
346 status &= ~BD_ENET_TX_STATS; 471 status &= ~BD_ENET_TX_STATS;
347 472
348 /* Set buffer length and buffer pointer */ 473 /* Set buffer length and buffer pointer */
349 bufaddr = skb->data; 474 bufaddr = skb->data;
350 bdp->cbd_datlen = skb->len; 475 buflen = skb_headlen(skb);
351
352 /*
353 * On some FEC implementations data must be aligned on
354 * 4-byte boundaries. Use bounce buffers to copy data
355 * and get it aligned. Ugh.
356 */
357 if (fep->bufdesc_ex)
358 index = (struct bufdesc_ex *)bdp -
359 (struct bufdesc_ex *)fep->tx_bd_base;
360 else
361 index = bdp - fep->tx_bd_base;
362 476
363 if (((unsigned long) bufaddr) & FEC_ALIGNMENT) { 477 index = fec_enet_get_bd_index(fep->tx_bd_base, bdp, fep);
364 memcpy(fep->tx_bounce[index], skb->data, skb->len); 478 if (((unsigned long) bufaddr) & FEC_ALIGNMENT ||
479 id_entry->driver_data & FEC_QUIRK_SWAP_FRAME) {
480 memcpy(fep->tx_bounce[index], skb->data, buflen);
365 bufaddr = fep->tx_bounce[index]; 481 bufaddr = fep->tx_bounce[index];
366 }
367 482
368 /* 483 if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
369 * Some design made an incorrect assumption on endian mode of 484 swap_buffer(bufaddr, buflen);
370 * the system that it's running on. As the result, driver has to 485 }
371 * swap every frame going to and coming from the controller.
372 */
373 if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
374 swap_buffer(bufaddr, skb->len);
375
376 /* Save skb pointer */
377 fep->tx_skbuff[index] = skb;
378 486
379 /* Push the data cache so the CPM does not get stale memory 487 /* Push the data cache so the CPM does not get stale memory
380 * data. 488 * data.
381 */ 489 */
382 bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, bufaddr, 490 bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, bufaddr,
383 skb->len, DMA_TO_DEVICE); 491 buflen, DMA_TO_DEVICE);
384 if (dma_mapping_error(&fep->pdev->dev, bdp->cbd_bufaddr)) { 492 if (dma_mapping_error(&fep->pdev->dev, bdp->cbd_bufaddr)) {
385 bdp->cbd_bufaddr = 0;
386 fep->tx_skbuff[index] = NULL;
387 dev_kfree_skb_any(skb); 493 dev_kfree_skb_any(skb);
388 if (net_ratelimit()) 494 if (net_ratelimit())
389 netdev_err(ndev, "Tx DMA memory map failed\n"); 495 netdev_err(ndev, "Tx DMA memory map failed\n");
390 return NETDEV_TX_OK; 496 return NETDEV_TX_OK;
391 } 497 }
392 498
499 if (nr_frags) {
500 ret = fec_enet_txq_submit_frag_skb(skb, ndev);
501 if (ret)
502 return ret;
503 } else {
504 status |= (BD_ENET_TX_INTR | BD_ENET_TX_LAST);
505 if (fep->bufdesc_ex) {
506 estatus = BD_ENET_TX_INT;
507 if (unlikely(skb_shinfo(skb)->tx_flags &
508 SKBTX_HW_TSTAMP && fep->hwts_tx_en))
509 estatus |= BD_ENET_TX_TS;
510 }
511 }
512
393 if (fep->bufdesc_ex) { 513 if (fep->bufdesc_ex) {
394 514
395 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp; 515 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
396 ebdp->cbd_bdu = 0; 516
397 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP && 517 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP &&
398 fep->hwts_tx_en)) { 518 fep->hwts_tx_en))
399 ebdp->cbd_esc = (BD_ENET_TX_TS | BD_ENET_TX_INT);
400 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; 519 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
401 } else {
402 ebdp->cbd_esc = BD_ENET_TX_INT;
403 520
404 /* Enable protocol checksum flags 521 if (skb->ip_summed == CHECKSUM_PARTIAL)
405 * We do not bother with the IP Checksum bits as they 522 estatus |= BD_ENET_TX_PINS | BD_ENET_TX_IINS;
406 * are done by the kernel 523
407 */ 524 ebdp->cbd_bdu = 0;
408 if (skb->ip_summed == CHECKSUM_PARTIAL) 525 ebdp->cbd_esc = estatus;
409 ebdp->cbd_esc |= BD_ENET_TX_PINS;
410 }
411 } 526 }
412 527
528 last_bdp = fep->cur_tx;
529 index = fec_enet_get_bd_index(fep->tx_bd_base, last_bdp, fep);
530 /* Save skb pointer */
531 fep->tx_skbuff[index] = skb;
532
533 bdp->cbd_datlen = buflen;
534
413 /* Send it on its way. Tell FEC it's ready, interrupt when done, 535 /* Send it on its way. Tell FEC it's ready, interrupt when done,
414 * it's the last BD of the frame, and to put the CRC on the end. 536 * it's the last BD of the frame, and to put the CRC on the end.
415 */ 537 */
416 status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR 538 status |= (BD_ENET_TX_READY | BD_ENET_TX_TC);
417 | BD_ENET_TX_LAST | BD_ENET_TX_TC);
418 bdp->cbd_sc = status; 539 bdp->cbd_sc = status;
419 540
420 bdp_pre = fec_enet_get_prevdesc(bdp, fep); 541 fec_enet_submit_work(bdp, fep);
421 if ((id_entry->driver_data & FEC_QUIRK_ERR006358) &&
422 !(bdp_pre->cbd_sc & BD_ENET_TX_READY)) {
423 fep->delay_work.trig_tx = true;
424 schedule_delayed_work(&(fep->delay_work.delay_work),
425 msecs_to_jiffies(1));
426 }
427 542
428 /* If this was the last BD in the ring, start at the beginning again. */ 543 /* If this was the last BD in the ring, start at the beginning again. */
429 bdp = fec_enet_get_nextdesc(bdp, fep); 544 bdp = fec_enet_get_nextdesc(last_bdp, fep);
430 545
431 skb_tx_timestamp(skb); 546 skb_tx_timestamp(skb);
432 547
433 fep->cur_tx = bdp; 548 fep->cur_tx = bdp;
434 549
435 if (fep->cur_tx == fep->dirty_tx) 550 /* Trigger transmission start */
436 netif_stop_queue(ndev); 551 writel(0, fep->hwp + FEC_X_DES_ACTIVE);
552
553 return 0;
554}
555
556static int
557fec_enet_txq_put_data_tso(struct sk_buff *skb, struct net_device *ndev,
558 struct bufdesc *bdp, int index, char *data,
559 int size, bool last_tcp, bool is_last)
560{
561 struct fec_enet_private *fep = netdev_priv(ndev);
562 const struct platform_device_id *id_entry =
563 platform_get_device_id(fep->pdev);
564 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
565 unsigned short status;
566 unsigned int estatus = 0;
567
568 status = bdp->cbd_sc;
569 status &= ~BD_ENET_TX_STATS;
570
571 status |= (BD_ENET_TX_TC | BD_ENET_TX_READY);
572 bdp->cbd_datlen = size;
573
574 if (((unsigned long) data) & FEC_ALIGNMENT ||
575 id_entry->driver_data & FEC_QUIRK_SWAP_FRAME) {
576 memcpy(fep->tx_bounce[index], data, size);
577 data = fep->tx_bounce[index];
578
579 if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
580 swap_buffer(data, size);
581 }
582
583 bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, data,
584 size, DMA_TO_DEVICE);
585 if (dma_mapping_error(&fep->pdev->dev, bdp->cbd_bufaddr)) {
586 dev_kfree_skb_any(skb);
587 if (net_ratelimit())
588 netdev_err(ndev, "Tx DMA memory map failed\n");
589 return NETDEV_TX_BUSY;
590 }
591
592 if (fep->bufdesc_ex) {
593 if (skb->ip_summed == CHECKSUM_PARTIAL)
594 estatus |= BD_ENET_TX_PINS | BD_ENET_TX_IINS;
595 ebdp->cbd_bdu = 0;
596 ebdp->cbd_esc = estatus;
597 }
598
599 /* Handle the last BD specially */
600 if (last_tcp)
601 status |= (BD_ENET_TX_LAST | BD_ENET_TX_TC);
602 if (is_last) {
603 status |= BD_ENET_TX_INTR;
604 if (fep->bufdesc_ex)
605 ebdp->cbd_esc |= BD_ENET_TX_INT;
606 }
607
608 bdp->cbd_sc = status;
609
610 return 0;
611}
612
613static int
614fec_enet_txq_put_hdr_tso(struct sk_buff *skb, struct net_device *ndev,
615 struct bufdesc *bdp, int index)
616{
617 struct fec_enet_private *fep = netdev_priv(ndev);
618 const struct platform_device_id *id_entry =
619 platform_get_device_id(fep->pdev);
620 int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
621 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
622 void *bufaddr;
623 unsigned long dmabuf;
624 unsigned short status;
625 unsigned int estatus = 0;
626
627 status = bdp->cbd_sc;
628 status &= ~BD_ENET_TX_STATS;
629 status |= (BD_ENET_TX_TC | BD_ENET_TX_READY);
630
631 bufaddr = fep->tso_hdrs + index * TSO_HEADER_SIZE;
632 dmabuf = fep->tso_hdrs_dma + index * TSO_HEADER_SIZE;
633 if (((unsigned long) bufaddr) & FEC_ALIGNMENT ||
634 id_entry->driver_data & FEC_QUIRK_SWAP_FRAME) {
635 memcpy(fep->tx_bounce[index], skb->data, hdr_len);
636 bufaddr = fep->tx_bounce[index];
637
638 if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
639 swap_buffer(bufaddr, hdr_len);
640
641 dmabuf = dma_map_single(&fep->pdev->dev, bufaddr,
642 hdr_len, DMA_TO_DEVICE);
643 if (dma_mapping_error(&fep->pdev->dev, dmabuf)) {
644 dev_kfree_skb_any(skb);
645 if (net_ratelimit())
646 netdev_err(ndev, "Tx DMA memory map failed\n");
647 return NETDEV_TX_BUSY;
648 }
649 }
650
651 bdp->cbd_bufaddr = dmabuf;
652 bdp->cbd_datlen = hdr_len;
653
654 if (fep->bufdesc_ex) {
655 if (skb->ip_summed == CHECKSUM_PARTIAL)
656 estatus |= BD_ENET_TX_PINS | BD_ENET_TX_IINS;
657 ebdp->cbd_bdu = 0;
658 ebdp->cbd_esc = estatus;
659 }
660
661 bdp->cbd_sc = status;
662
663 return 0;
664}
665
666static int fec_enet_txq_submit_tso(struct sk_buff *skb, struct net_device *ndev)
667{
668 struct fec_enet_private *fep = netdev_priv(ndev);
669 int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
670 int total_len, data_left;
671 struct bufdesc *bdp = fep->cur_tx;
672 struct tso_t tso;
673 unsigned int index = 0;
674 int ret;
675
676 if (tso_count_descs(skb) >= fec_enet_get_free_txdesc_num(fep)) {
677 dev_kfree_skb_any(skb);
678 if (net_ratelimit())
679 netdev_err(ndev, "NOT enough BD for TSO!\n");
680 return NETDEV_TX_OK;
681 }
682
683 /* Protocol checksum off-load for TCP and UDP. */
684 if (fec_enet_clear_csum(skb, ndev)) {
685 dev_kfree_skb_any(skb);
686 return NETDEV_TX_OK;
687 }
688
689 /* Initialize the TSO handler, and prepare the first payload */
690 tso_start(skb, &tso);
691
692 total_len = skb->len - hdr_len;
693 while (total_len > 0) {
694 char *hdr;
695
696 index = fec_enet_get_bd_index(fep->tx_bd_base, bdp, fep);
697 data_left = min_t(int, skb_shinfo(skb)->gso_size, total_len);
698 total_len -= data_left;
699
700 /* prepare packet headers: MAC + IP + TCP */
701 hdr = fep->tso_hdrs + index * TSO_HEADER_SIZE;
702 tso_build_hdr(skb, hdr, &tso, data_left, total_len == 0);
703 ret = fec_enet_txq_put_hdr_tso(skb, ndev, bdp, index);
704 if (ret)
705 goto err_release;
706
707 while (data_left > 0) {
708 int size;
709
710 size = min_t(int, tso.size, data_left);
711 bdp = fec_enet_get_nextdesc(bdp, fep);
712 index = fec_enet_get_bd_index(fep->tx_bd_base, bdp, fep);
713 ret = fec_enet_txq_put_data_tso(skb, ndev, bdp, index, tso.data,
714 size, size == data_left,
715 total_len == 0);
716 if (ret)
717 goto err_release;
718
719 data_left -= size;
720 tso_build_data(skb, &tso, size);
721 }
722
723 bdp = fec_enet_get_nextdesc(bdp, fep);
724 }
725
726 /* Save skb pointer */
727 fep->tx_skbuff[index] = skb;
728
729 fec_enet_submit_work(bdp, fep);
730
731 skb_tx_timestamp(skb);
732 fep->cur_tx = bdp;
437 733
438 /* Trigger transmission start */ 734 /* Trigger transmission start */
439 writel(0, fep->hwp + FEC_X_DES_ACTIVE); 735 writel(0, fep->hwp + FEC_X_DES_ACTIVE);
440 736
737 return 0;
738
739err_release:
740 /* TODO: Release all used data descriptors for TSO */
741 return ret;
742}
743
744static netdev_tx_t
745fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
746{
747 struct fec_enet_private *fep = netdev_priv(ndev);
748 int entries_free;
749 int ret;
750
751 if (skb_is_gso(skb))
752 ret = fec_enet_txq_submit_tso(skb, ndev);
753 else
754 ret = fec_enet_txq_submit_skb(skb, ndev);
755 if (ret)
756 return ret;
757
758 entries_free = fec_enet_get_free_txdesc_num(fep);
759 if (entries_free <= fep->tx_stop_threshold)
760 netif_stop_queue(ndev);
761
441 return NETDEV_TX_OK; 762 return NETDEV_TX_OK;
442} 763}
443 764
@@ -756,6 +1077,7 @@ fec_enet_tx(struct net_device *ndev)
756 unsigned short status; 1077 unsigned short status;
757 struct sk_buff *skb; 1078 struct sk_buff *skb;
758 int index = 0; 1079 int index = 0;
1080 int entries_free;
759 1081
760 fep = netdev_priv(ndev); 1082 fep = netdev_priv(ndev);
761 bdp = fep->dirty_tx; 1083 bdp = fep->dirty_tx;
@@ -769,16 +1091,17 @@ fec_enet_tx(struct net_device *ndev)
769 if (bdp == fep->cur_tx) 1091 if (bdp == fep->cur_tx)
770 break; 1092 break;
771 1093
772 if (fep->bufdesc_ex) 1094 index = fec_enet_get_bd_index(fep->tx_bd_base, bdp, fep);
773 index = (struct bufdesc_ex *)bdp -
774 (struct bufdesc_ex *)fep->tx_bd_base;
775 else
776 index = bdp - fep->tx_bd_base;
777 1095
778 skb = fep->tx_skbuff[index]; 1096 skb = fep->tx_skbuff[index];
779 dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr, skb->len, 1097 if (!IS_TSO_HEADER(fep, bdp->cbd_bufaddr))
780 DMA_TO_DEVICE); 1098 dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
1099 bdp->cbd_datlen, DMA_TO_DEVICE);
781 bdp->cbd_bufaddr = 0; 1100 bdp->cbd_bufaddr = 0;
1101 if (!skb) {
1102 bdp = fec_enet_get_nextdesc(bdp, fep);
1103 continue;
1104 }
782 1105
783 /* Check for errors. */ 1106 /* Check for errors. */
784 if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC | 1107 if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC |
@@ -797,7 +1120,7 @@ fec_enet_tx(struct net_device *ndev)
797 ndev->stats.tx_carrier_errors++; 1120 ndev->stats.tx_carrier_errors++;
798 } else { 1121 } else {
799 ndev->stats.tx_packets++; 1122 ndev->stats.tx_packets++;
800 ndev->stats.tx_bytes += bdp->cbd_datlen; 1123 ndev->stats.tx_bytes += skb->len;
801 } 1124 }
802 1125
803 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS) && 1126 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS) &&
@@ -834,15 +1157,15 @@ fec_enet_tx(struct net_device *ndev)
834 1157
835 /* Since we have freed up a buffer, the ring is no longer full 1158 /* Since we have freed up a buffer, the ring is no longer full
836 */ 1159 */
837 if (fep->dirty_tx != fep->cur_tx) { 1160 if (netif_queue_stopped(ndev)) {
838 if (netif_queue_stopped(ndev)) 1161 entries_free = fec_enet_get_free_txdesc_num(fep);
1162 if (entries_free >= fep->tx_wake_threshold)
839 netif_wake_queue(ndev); 1163 netif_wake_queue(ndev);
840 } 1164 }
841 } 1165 }
842 return; 1166 return;
843} 1167}
844 1168
845
846/* During a receive, the cur_rx points to the current incoming buffer. 1169/* During a receive, the cur_rx points to the current incoming buffer.
847 * When we update through the ring, if the next incoming buffer has 1170 * When we update through the ring, if the next incoming buffer has
848 * not been given to the system, we just set the empty indicator, 1171 * not been given to the system, we just set the empty indicator,
@@ -920,11 +1243,7 @@ fec_enet_rx(struct net_device *ndev, int budget)
920 pkt_len = bdp->cbd_datlen; 1243 pkt_len = bdp->cbd_datlen;
921 ndev->stats.rx_bytes += pkt_len; 1244 ndev->stats.rx_bytes += pkt_len;
922 1245
923 if (fep->bufdesc_ex) 1246 index = fec_enet_get_bd_index(fep->rx_bd_base, bdp, fep);
924 index = (struct bufdesc_ex *)bdp -
925 (struct bufdesc_ex *)fep->rx_bd_base;
926 else
927 index = bdp - fep->rx_bd_base;
928 data = fep->rx_skbuff[index]->data; 1247 data = fep->rx_skbuff[index]->data;
929 dma_sync_single_for_cpu(&fep->pdev->dev, bdp->cbd_bufaddr, 1248 dma_sync_single_for_cpu(&fep->pdev->dev, bdp->cbd_bufaddr,
930 FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE); 1249 FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
@@ -1255,6 +1574,49 @@ static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
1255 return 0; 1574 return 0;
1256} 1575}
1257 1576
1577static int fec_enet_clk_enable(struct net_device *ndev, bool enable)
1578{
1579 struct fec_enet_private *fep = netdev_priv(ndev);
1580 int ret;
1581
1582 if (enable) {
1583 ret = clk_prepare_enable(fep->clk_ahb);
1584 if (ret)
1585 return ret;
1586 ret = clk_prepare_enable(fep->clk_ipg);
1587 if (ret)
1588 goto failed_clk_ipg;
1589 if (fep->clk_enet_out) {
1590 ret = clk_prepare_enable(fep->clk_enet_out);
1591 if (ret)
1592 goto failed_clk_enet_out;
1593 }
1594 if (fep->clk_ptp) {
1595 ret = clk_prepare_enable(fep->clk_ptp);
1596 if (ret)
1597 goto failed_clk_ptp;
1598 }
1599 } else {
1600 clk_disable_unprepare(fep->clk_ahb);
1601 clk_disable_unprepare(fep->clk_ipg);
1602 if (fep->clk_enet_out)
1603 clk_disable_unprepare(fep->clk_enet_out);
1604 if (fep->clk_ptp)
1605 clk_disable_unprepare(fep->clk_ptp);
1606 }
1607
1608 return 0;
1609failed_clk_ptp:
1610 if (fep->clk_enet_out)
1611 clk_disable_unprepare(fep->clk_enet_out);
1612failed_clk_enet_out:
1613 clk_disable_unprepare(fep->clk_ipg);
1614failed_clk_ipg:
1615 clk_disable_unprepare(fep->clk_ahb);
1616
1617 return ret;
1618}
1619
1258static int fec_enet_mii_probe(struct net_device *ndev) 1620static int fec_enet_mii_probe(struct net_device *ndev)
1259{ 1621{
1260 struct fec_enet_private *fep = netdev_priv(ndev); 1622 struct fec_enet_private *fep = netdev_priv(ndev);
@@ -1364,7 +1726,7 @@ static int fec_enet_mii_init(struct platform_device *pdev)
1364 * Reference Manual has an error on this, and gets fixed on i.MX6Q 1726 * Reference Manual has an error on this, and gets fixed on i.MX6Q
1365 * document. 1727 * document.
1366 */ 1728 */
1367 fep->phy_speed = DIV_ROUND_UP(clk_get_rate(fep->clk_ahb), 5000000); 1729 fep->phy_speed = DIV_ROUND_UP(clk_get_rate(fep->clk_ipg), 5000000);
1368 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) 1730 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC)
1369 fep->phy_speed--; 1731 fep->phy_speed--;
1370 fep->phy_speed <<= 1; 1732 fep->phy_speed <<= 1;
@@ -1773,6 +2135,11 @@ fec_enet_open(struct net_device *ndev)
1773 struct fec_enet_private *fep = netdev_priv(ndev); 2135 struct fec_enet_private *fep = netdev_priv(ndev);
1774 int ret; 2136 int ret;
1775 2137
2138 pinctrl_pm_select_default_state(&fep->pdev->dev);
2139 ret = fec_enet_clk_enable(ndev, true);
2140 if (ret)
2141 return ret;
2142
1776 /* I should reset the ring buffers here, but I don't yet know 2143 /* I should reset the ring buffers here, but I don't yet know
1777 * a simple way to do that. 2144 * a simple way to do that.
1778 */ 2145 */
@@ -1811,6 +2178,8 @@ fec_enet_close(struct net_device *ndev)
1811 phy_disconnect(fep->phy_dev); 2178 phy_disconnect(fep->phy_dev);
1812 } 2179 }
1813 2180
2181 fec_enet_clk_enable(ndev, false);
2182 pinctrl_pm_select_sleep_state(&fep->pdev->dev);
1814 fec_enet_free_buffers(ndev); 2183 fec_enet_free_buffers(ndev);
1815 2184
1816 return 0; 2185 return 0;
@@ -1988,13 +2357,35 @@ static int fec_enet_init(struct net_device *ndev)
1988 const struct platform_device_id *id_entry = 2357 const struct platform_device_id *id_entry =
1989 platform_get_device_id(fep->pdev); 2358 platform_get_device_id(fep->pdev);
1990 struct bufdesc *cbd_base; 2359 struct bufdesc *cbd_base;
2360 int bd_size;
2361
2362 /* init the tx & rx ring size */
2363 fep->tx_ring_size = TX_RING_SIZE;
2364 fep->rx_ring_size = RX_RING_SIZE;
2365
2366 fep->tx_stop_threshold = FEC_MAX_SKB_DESCS;
2367 fep->tx_wake_threshold = (fep->tx_ring_size - fep->tx_stop_threshold) / 2;
2368
2369 if (fep->bufdesc_ex)
2370 fep->bufdesc_size = sizeof(struct bufdesc_ex);
2371 else
2372 fep->bufdesc_size = sizeof(struct bufdesc);
2373 bd_size = (fep->tx_ring_size + fep->rx_ring_size) *
2374 fep->bufdesc_size;
1991 2375
1992 /* Allocate memory for buffer descriptors. */ 2376 /* Allocate memory for buffer descriptors. */
1993 cbd_base = dma_alloc_coherent(NULL, PAGE_SIZE, &fep->bd_dma, 2377 cbd_base = dma_alloc_coherent(NULL, bd_size, &fep->bd_dma,
1994 GFP_KERNEL); 2378 GFP_KERNEL);
1995 if (!cbd_base) 2379 if (!cbd_base)
1996 return -ENOMEM; 2380 return -ENOMEM;
1997 2381
2382 fep->tso_hdrs = dma_alloc_coherent(NULL, fep->tx_ring_size * TSO_HEADER_SIZE,
2383 &fep->tso_hdrs_dma, GFP_KERNEL);
2384 if (!fep->tso_hdrs) {
2385 dma_free_coherent(NULL, bd_size, cbd_base, fep->bd_dma);
2386 return -ENOMEM;
2387 }
2388
1998 memset(cbd_base, 0, PAGE_SIZE); 2389 memset(cbd_base, 0, PAGE_SIZE);
1999 2390
2000 fep->netdev = ndev; 2391 fep->netdev = ndev;
@@ -2004,10 +2395,6 @@ static int fec_enet_init(struct net_device *ndev)
2004 /* make sure MAC we just acquired is programmed into the hw */ 2395 /* make sure MAC we just acquired is programmed into the hw */
2005 fec_set_mac_address(ndev, NULL); 2396 fec_set_mac_address(ndev, NULL);
2006 2397
2007 /* init the tx & rx ring size */
2008 fep->tx_ring_size = TX_RING_SIZE;
2009 fep->rx_ring_size = RX_RING_SIZE;
2010
2011 /* Set receive and transmit descriptor base. */ 2398 /* Set receive and transmit descriptor base. */
2012 fep->rx_bd_base = cbd_base; 2399 fep->rx_bd_base = cbd_base;
2013 if (fep->bufdesc_ex) 2400 if (fep->bufdesc_ex)
@@ -2024,21 +2411,21 @@ static int fec_enet_init(struct net_device *ndev)
2024 writel(FEC_RX_DISABLED_IMASK, fep->hwp + FEC_IMASK); 2411 writel(FEC_RX_DISABLED_IMASK, fep->hwp + FEC_IMASK);
2025 netif_napi_add(ndev, &fep->napi, fec_enet_rx_napi, NAPI_POLL_WEIGHT); 2412 netif_napi_add(ndev, &fep->napi, fec_enet_rx_napi, NAPI_POLL_WEIGHT);
2026 2413
2027 if (id_entry->driver_data & FEC_QUIRK_HAS_VLAN) { 2414 if (id_entry->driver_data & FEC_QUIRK_HAS_VLAN)
2028 /* enable hw VLAN support */ 2415 /* enable hw VLAN support */
2029 ndev->features |= NETIF_F_HW_VLAN_CTAG_RX; 2416 ndev->features |= NETIF_F_HW_VLAN_CTAG_RX;
2030 ndev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
2031 }
2032 2417
2033 if (id_entry->driver_data & FEC_QUIRK_HAS_CSUM) { 2418 if (id_entry->driver_data & FEC_QUIRK_HAS_CSUM) {
2419 ndev->gso_max_segs = FEC_MAX_TSO_SEGS;
2420
2034 /* enable hw accelerator */ 2421 /* enable hw accelerator */
2035 ndev->features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM 2422 ndev->features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM
2036 | NETIF_F_RXCSUM); 2423 | NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_TSO);
2037 ndev->hw_features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM
2038 | NETIF_F_RXCSUM);
2039 fep->csum_flags |= FLAG_RX_CSUM_ENABLED; 2424 fep->csum_flags |= FLAG_RX_CSUM_ENABLED;
2040 } 2425 }
2041 2426
2427 ndev->hw_features = ndev->features;
2428
2042 fec_restart(ndev, 0); 2429 fec_restart(ndev, 0);
2043 2430
2044 return 0; 2431 return 0;
@@ -2114,6 +2501,9 @@ fec_probe(struct platform_device *pdev)
2114 fep->pause_flag |= FEC_PAUSE_FLAG_AUTONEG; 2501 fep->pause_flag |= FEC_PAUSE_FLAG_AUTONEG;
2115#endif 2502#endif
2116 2503
2504 /* Select default pin state */
2505 pinctrl_pm_select_default_state(&pdev->dev);
2506
2117 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2507 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2118 fep->hwp = devm_ioremap_resource(&pdev->dev, r); 2508 fep->hwp = devm_ioremap_resource(&pdev->dev, r);
2119 if (IS_ERR(fep->hwp)) { 2509 if (IS_ERR(fep->hwp)) {
@@ -2164,26 +2554,10 @@ fec_probe(struct platform_device *pdev)
2164 fep->bufdesc_ex = 0; 2554 fep->bufdesc_ex = 0;
2165 } 2555 }
2166 2556
2167 ret = clk_prepare_enable(fep->clk_ahb); 2557 ret = fec_enet_clk_enable(ndev, true);
2168 if (ret) 2558 if (ret)
2169 goto failed_clk; 2559 goto failed_clk;
2170 2560
2171 ret = clk_prepare_enable(fep->clk_ipg);
2172 if (ret)
2173 goto failed_clk_ipg;
2174
2175 if (fep->clk_enet_out) {
2176 ret = clk_prepare_enable(fep->clk_enet_out);
2177 if (ret)
2178 goto failed_clk_enet_out;
2179 }
2180
2181 if (fep->clk_ptp) {
2182 ret = clk_prepare_enable(fep->clk_ptp);
2183 if (ret)
2184 goto failed_clk_ptp;
2185 }
2186
2187 fep->reg_phy = devm_regulator_get(&pdev->dev, "phy"); 2561 fep->reg_phy = devm_regulator_get(&pdev->dev, "phy");
2188 if (!IS_ERR(fep->reg_phy)) { 2562 if (!IS_ERR(fep->reg_phy)) {
2189 ret = regulator_enable(fep->reg_phy); 2563 ret = regulator_enable(fep->reg_phy);
@@ -2225,6 +2599,8 @@ fec_probe(struct platform_device *pdev)
2225 2599
2226 /* Carrier starts down, phylib will bring it up */ 2600 /* Carrier starts down, phylib will bring it up */
2227 netif_carrier_off(ndev); 2601 netif_carrier_off(ndev);
2602 fec_enet_clk_enable(ndev, false);
2603 pinctrl_pm_select_sleep_state(&pdev->dev);
2228 2604
2229 ret = register_netdev(ndev); 2605 ret = register_netdev(ndev);
2230 if (ret) 2606 if (ret)
@@ -2244,15 +2620,7 @@ failed_init:
2244 if (fep->reg_phy) 2620 if (fep->reg_phy)
2245 regulator_disable(fep->reg_phy); 2621 regulator_disable(fep->reg_phy);
2246failed_regulator: 2622failed_regulator:
2247 if (fep->clk_ptp) 2623 fec_enet_clk_enable(ndev, false);
2248 clk_disable_unprepare(fep->clk_ptp);
2249failed_clk_ptp:
2250 if (fep->clk_enet_out)
2251 clk_disable_unprepare(fep->clk_enet_out);
2252failed_clk_enet_out:
2253 clk_disable_unprepare(fep->clk_ipg);
2254failed_clk_ipg:
2255 clk_disable_unprepare(fep->clk_ahb);
2256failed_clk: 2624failed_clk:
2257failed_ioremap: 2625failed_ioremap:
2258 free_netdev(ndev); 2626 free_netdev(ndev);
@@ -2272,14 +2640,9 @@ fec_drv_remove(struct platform_device *pdev)
2272 del_timer_sync(&fep->time_keep); 2640 del_timer_sync(&fep->time_keep);
2273 if (fep->reg_phy) 2641 if (fep->reg_phy)
2274 regulator_disable(fep->reg_phy); 2642 regulator_disable(fep->reg_phy);
2275 if (fep->clk_ptp)
2276 clk_disable_unprepare(fep->clk_ptp);
2277 if (fep->ptp_clock) 2643 if (fep->ptp_clock)
2278 ptp_clock_unregister(fep->ptp_clock); 2644 ptp_clock_unregister(fep->ptp_clock);
2279 if (fep->clk_enet_out) 2645 fec_enet_clk_enable(ndev, false);
2280 clk_disable_unprepare(fep->clk_enet_out);
2281 clk_disable_unprepare(fep->clk_ipg);
2282 clk_disable_unprepare(fep->clk_ahb);
2283 free_netdev(ndev); 2646 free_netdev(ndev);
2284 2647
2285 return 0; 2648 return 0;
@@ -2296,12 +2659,8 @@ fec_suspend(struct device *dev)
2296 fec_stop(ndev); 2659 fec_stop(ndev);
2297 netif_device_detach(ndev); 2660 netif_device_detach(ndev);
2298 } 2661 }
2299 if (fep->clk_ptp) 2662 fec_enet_clk_enable(ndev, false);
2300 clk_disable_unprepare(fep->clk_ptp); 2663 pinctrl_pm_select_sleep_state(&fep->pdev->dev);
2301 if (fep->clk_enet_out)
2302 clk_disable_unprepare(fep->clk_enet_out);
2303 clk_disable_unprepare(fep->clk_ipg);
2304 clk_disable_unprepare(fep->clk_ahb);
2305 2664
2306 if (fep->reg_phy) 2665 if (fep->reg_phy)
2307 regulator_disable(fep->reg_phy); 2666 regulator_disable(fep->reg_phy);
@@ -2322,25 +2681,10 @@ fec_resume(struct device *dev)
2322 return ret; 2681 return ret;
2323 } 2682 }
2324 2683
2325 ret = clk_prepare_enable(fep->clk_ahb); 2684 pinctrl_pm_select_default_state(&fep->pdev->dev);
2685 ret = fec_enet_clk_enable(ndev, true);
2326 if (ret) 2686 if (ret)
2327 goto failed_clk_ahb; 2687 goto failed_clk;
2328
2329 ret = clk_prepare_enable(fep->clk_ipg);
2330 if (ret)
2331 goto failed_clk_ipg;
2332
2333 if (fep->clk_enet_out) {
2334 ret = clk_prepare_enable(fep->clk_enet_out);
2335 if (ret)
2336 goto failed_clk_enet_out;
2337 }
2338
2339 if (fep->clk_ptp) {
2340 ret = clk_prepare_enable(fep->clk_ptp);
2341 if (ret)
2342 goto failed_clk_ptp;
2343 }
2344 2688
2345 if (netif_running(ndev)) { 2689 if (netif_running(ndev)) {
2346 fec_restart(ndev, fep->full_duplex); 2690 fec_restart(ndev, fep->full_duplex);
@@ -2349,14 +2693,7 @@ fec_resume(struct device *dev)
2349 2693
2350 return 0; 2694 return 0;
2351 2695
2352failed_clk_ptp: 2696failed_clk:
2353 if (fep->clk_enet_out)
2354 clk_disable_unprepare(fep->clk_enet_out);
2355failed_clk_enet_out:
2356 clk_disable_unprepare(fep->clk_ipg);
2357failed_clk_ipg:
2358 clk_disable_unprepare(fep->clk_ahb);
2359failed_clk_ahb:
2360 if (fep->reg_phy) 2697 if (fep->reg_phy)
2361 regulator_disable(fep->reg_phy); 2698 regulator_disable(fep->reg_phy);
2362 return ret; 2699 return ret;
diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
index dc80db41d6b3..cfaf17b70f3f 100644
--- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
+++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
@@ -792,10 +792,6 @@ static int fs_init_phy(struct net_device *dev)
792 phydev = of_phy_connect(dev, fep->fpi->phy_node, &fs_adjust_link, 0, 792 phydev = of_phy_connect(dev, fep->fpi->phy_node, &fs_adjust_link, 0,
793 iface); 793 iface);
794 if (!phydev) { 794 if (!phydev) {
795 phydev = of_phy_connect_fixed_link(dev, &fs_adjust_link,
796 iface);
797 }
798 if (!phydev) {
799 dev_err(&dev->dev, "Could not attach to PHY\n"); 795 dev_err(&dev->dev, "Could not attach to PHY\n");
800 return -ENODEV; 796 return -ENODEV;
801 } 797 }
@@ -1029,9 +1025,16 @@ static int fs_enet_probe(struct platform_device *ofdev)
1029 fpi->use_napi = 1; 1025 fpi->use_napi = 1;
1030 fpi->napi_weight = 17; 1026 fpi->napi_weight = 17;
1031 fpi->phy_node = of_parse_phandle(ofdev->dev.of_node, "phy-handle", 0); 1027 fpi->phy_node = of_parse_phandle(ofdev->dev.of_node, "phy-handle", 0);
1032 if ((!fpi->phy_node) && (!of_get_property(ofdev->dev.of_node, "fixed-link", 1028 if (!fpi->phy_node && of_phy_is_fixed_link(ofdev->dev.of_node)) {
1033 NULL))) 1029 err = of_phy_register_fixed_link(ofdev->dev.of_node);
1034 goto out_free_fpi; 1030 if (err)
1031 goto out_free_fpi;
1032
1033 /* In the case of a fixed PHY, the DT node associated
1034 * to the PHY is the Ethernet MAC DT node.
1035 */
1036 fpi->phy_node = ofdev->dev.of_node;
1037 }
1035 1038
1036 if (of_device_is_compatible(ofdev->dev.of_node, "fsl,mpc5125-fec")) { 1039 if (of_device_is_compatible(ofdev->dev.of_node, "fsl,mpc5125-fec")) {
1037 phy_connection_type = of_get_property(ofdev->dev.of_node, 1040 phy_connection_type = of_get_property(ofdev->dev.of_node,
diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c
index ee6ddbd4f252..a6cf40e62f3a 100644
--- a/drivers/net/ethernet/freescale/gianfar.c
+++ b/drivers/net/ethernet/freescale/gianfar.c
@@ -889,6 +889,17 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)
889 889
890 priv->phy_node = of_parse_phandle(np, "phy-handle", 0); 890 priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
891 891
892 /* In the case of a fixed PHY, the DT node associated
893 * to the PHY is the Ethernet MAC DT node.
894 */
895 if (of_phy_is_fixed_link(np)) {
896 err = of_phy_register_fixed_link(np);
897 if (err)
898 goto err_grp_init;
899
900 priv->phy_node = np;
901 }
902
892 /* Find the TBI PHY. If it's not there, we don't support SGMII */ 903 /* Find the TBI PHY. If it's not there, we don't support SGMII */
893 priv->tbi_node = of_parse_phandle(np, "tbi-handle", 0); 904 priv->tbi_node = of_parse_phandle(np, "tbi-handle", 0);
894 905
@@ -1231,7 +1242,7 @@ static void gfar_hw_init(struct gfar_private *priv)
1231 gfar_write_isrg(priv); 1242 gfar_write_isrg(priv);
1232} 1243}
1233 1244
1234static void __init gfar_init_addr_hash_table(struct gfar_private *priv) 1245static void gfar_init_addr_hash_table(struct gfar_private *priv)
1235{ 1246{
1236 struct gfar __iomem *regs = priv->gfargrp[0].regs; 1247 struct gfar __iomem *regs = priv->gfargrp[0].regs;
1237 1248
@@ -1373,6 +1384,9 @@ static int gfar_probe(struct platform_device *ofdev)
1373 1384
1374 gfar_hw_init(priv); 1385 gfar_hw_init(priv);
1375 1386
1387 /* Carrier starts down, phylib will bring it up */
1388 netif_carrier_off(dev);
1389
1376 err = register_netdev(dev); 1390 err = register_netdev(dev);
1377 1391
1378 if (err) { 1392 if (err) {
@@ -1380,9 +1394,6 @@ static int gfar_probe(struct platform_device *ofdev)
1380 goto register_fail; 1394 goto register_fail;
1381 } 1395 }
1382 1396
1383 /* Carrier starts down, phylib will bring it up */
1384 netif_carrier_off(dev);
1385
1386 device_init_wakeup(&dev->dev, 1397 device_init_wakeup(&dev->dev,
1387 priv->device_flags & 1398 priv->device_flags &
1388 FSL_GIANFAR_DEV_HAS_MAGIC_PACKET); 1399 FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
@@ -1660,9 +1671,6 @@ static int init_phy(struct net_device *dev)
1660 1671
1661 priv->phydev = of_phy_connect(dev, priv->phy_node, &adjust_link, 0, 1672 priv->phydev = of_phy_connect(dev, priv->phy_node, &adjust_link, 0,
1662 interface); 1673 interface);
1663 if (!priv->phydev)
1664 priv->phydev = of_phy_connect_fixed_link(dev, &adjust_link,
1665 interface);
1666 if (!priv->phydev) { 1674 if (!priv->phydev) {
1667 dev_err(&dev->dev, "could not attach to PHY\n"); 1675 dev_err(&dev->dev, "could not attach to PHY\n");
1668 return -ENODEV; 1676 return -ENODEV;
diff --git a/drivers/net/ethernet/freescale/ucc_geth.c b/drivers/net/ethernet/freescale/ucc_geth.c
index c8299c31b21f..fab39e295441 100644
--- a/drivers/net/ethernet/freescale/ucc_geth.c
+++ b/drivers/net/ethernet/freescale/ucc_geth.c
@@ -1728,9 +1728,6 @@ static int init_phy(struct net_device *dev)
1728 1728
1729 phydev = of_phy_connect(dev, ug_info->phy_node, &adjust_link, 0, 1729 phydev = of_phy_connect(dev, ug_info->phy_node, &adjust_link, 0,
1730 priv->phy_interface); 1730 priv->phy_interface);
1731 if (!phydev)
1732 phydev = of_phy_connect_fixed_link(dev, &adjust_link,
1733 priv->phy_interface);
1734 if (!phydev) { 1731 if (!phydev) {
1735 dev_err(&dev->dev, "Could not attach to PHY\n"); 1732 dev_err(&dev->dev, "Could not attach to PHY\n");
1736 return -ENODEV; 1733 return -ENODEV;
@@ -3790,6 +3787,17 @@ static int ucc_geth_probe(struct platform_device* ofdev)
3790 ug_info->uf_info.irq = irq_of_parse_and_map(np, 0); 3787 ug_info->uf_info.irq = irq_of_parse_and_map(np, 0);
3791 3788
3792 ug_info->phy_node = of_parse_phandle(np, "phy-handle", 0); 3789 ug_info->phy_node = of_parse_phandle(np, "phy-handle", 0);
3790 if (!ug_info->phy_node) {
3791 /* In the case of a fixed PHY, the DT node associated
3792 * to the PHY is the Ethernet MAC DT node.
3793 */
3794 if (of_phy_is_fixed_link(np)) {
3795 err = of_phy_register_fixed_link(np);
3796 if (err)
3797 return err;
3798 }
3799 ug_info->phy_node = np;
3800 }
3793 3801
3794 /* Find the TBI PHY node. If it's not there, we don't support SGMII */ 3802 /* Find the TBI PHY node. If it's not there, we don't support SGMII */
3795 ug_info->tbi_node = of_parse_phandle(np, "tbi-handle", 0); 3803 ug_info->tbi_node = of_parse_phandle(np, "tbi-handle", 0);
diff --git a/drivers/net/ethernet/freescale/ucc_geth_ethtool.c b/drivers/net/ethernet/freescale/ucc_geth_ethtool.c
index 413329eff2ff..cc83350d56ba 100644
--- a/drivers/net/ethernet/freescale/ucc_geth_ethtool.c
+++ b/drivers/net/ethernet/freescale/ucc_geth_ethtool.c
@@ -417,5 +417,5 @@ static const struct ethtool_ops uec_ethtool_ops = {
417 417
418void uec_set_ethtool_ops(struct net_device *netdev) 418void uec_set_ethtool_ops(struct net_device *netdev)
419{ 419{
420 SET_ETHTOOL_OPS(netdev, &uec_ethtool_ops); 420 netdev->ethtool_ops = &uec_ethtool_ops;
421} 421}
diff --git a/drivers/net/ethernet/freescale/xgmac_mdio.c b/drivers/net/ethernet/freescale/xgmac_mdio.c
index d449fcb90199..0c9d55c862ae 100644
--- a/drivers/net/ethernet/freescale/xgmac_mdio.c
+++ b/drivers/net/ethernet/freescale/xgmac_mdio.c
@@ -162,7 +162,9 @@ static int xgmac_mdio_read(struct mii_bus *bus, int phy_id, int regnum)
162 162
163 /* Return all Fs if nothing was there */ 163 /* Return all Fs if nothing was there */
164 if (in_be32(&regs->mdio_stat) & MDIO_STAT_RD_ER) { 164 if (in_be32(&regs->mdio_stat) & MDIO_STAT_RD_ER) {
165 dev_err(&bus->dev, "MDIO read error\n"); 165 dev_err(&bus->dev,
166 "Error while reading PHY%d reg at %d.%d\n",
167 phy_id, dev_addr, regnum);
166 return 0xffff; 168 return 0xffff;
167 } 169 }
168 170