diff options
author | Jeff Garzik <jgarzik@pobox.com> | 2005-10-28 12:31:34 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@pobox.com> | 2005-10-28 12:31:34 -0400 |
commit | 96b88fb850cc419171f926ad04650ec509e9f543 (patch) | |
tree | 5bf9537bde467534608b3acdbfa5f7726ede8c3f /drivers/net/gianfar.c | |
parent | e78a57de94480226f7fc90d0b4837bfc6c99a9e0 (diff) | |
parent | 5fadd053d9bb4345ec6f405d24db4e7eb49cf81e (diff) |
Merge branch 'master'
Diffstat (limited to 'drivers/net/gianfar.c')
-rw-r--r-- | drivers/net/gianfar.c | 412 |
1 files changed, 86 insertions, 326 deletions
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c index 6518334b9280..ae5a2ed3b264 100644 --- a/drivers/net/gianfar.c +++ b/drivers/net/gianfar.c | |||
@@ -29,12 +29,7 @@ | |||
29 | * define the configuration needed by the board are defined in a | 29 | * define the configuration needed by the board are defined in a |
30 | * board structure in arch/ppc/platforms (though I do not | 30 | * board structure in arch/ppc/platforms (though I do not |
31 | * discount the possibility that other architectures could one | 31 | * discount the possibility that other architectures could one |
32 | * day be supported. One assumption the driver currently makes | 32 | * day be supported. |
33 | * is that the PHY is configured in such a way to advertise all | ||
34 | * capabilities. This is a sensible default, and on certain | ||
35 | * PHYs, changing this default encounters substantial errata | ||
36 | * issues. Future versions may remove this requirement, but for | ||
37 | * now, it is best for the firmware to ensure this is the case. | ||
38 | * | 33 | * |
39 | * The Gianfar Ethernet Controller uses a ring of buffer | 34 | * The Gianfar Ethernet Controller uses a ring of buffer |
40 | * descriptors. The beginning is indicated by a register | 35 | * descriptors. The beginning is indicated by a register |
@@ -47,7 +42,7 @@ | |||
47 | * corresponding bit in the IMASK register is also set (if | 42 | * corresponding bit in the IMASK register is also set (if |
48 | * interrupt coalescing is active, then the interrupt may not | 43 | * interrupt coalescing is active, then the interrupt may not |
49 | * happen immediately, but will wait until either a set number | 44 | * happen immediately, but will wait until either a set number |
50 | * of frames or amount of time have passed.). In NAPI, the | 45 | * of frames or amount of time have passed). In NAPI, the |
51 | * interrupt handler will signal there is work to be done, and | 46 | * interrupt handler will signal there is work to be done, and |
52 | * exit. Without NAPI, the packet(s) will be handled | 47 | * exit. Without NAPI, the packet(s) will be handled |
53 | * immediately. Both methods will start at the last known empty | 48 | * immediately. Both methods will start at the last known empty |
@@ -75,6 +70,7 @@ | |||
75 | #include <linux/sched.h> | 70 | #include <linux/sched.h> |
76 | #include <linux/string.h> | 71 | #include <linux/string.h> |
77 | #include <linux/errno.h> | 72 | #include <linux/errno.h> |
73 | #include <linux/unistd.h> | ||
78 | #include <linux/slab.h> | 74 | #include <linux/slab.h> |
79 | #include <linux/interrupt.h> | 75 | #include <linux/interrupt.h> |
80 | #include <linux/init.h> | 76 | #include <linux/init.h> |
@@ -97,9 +93,11 @@ | |||
97 | #include <linux/version.h> | 93 | #include <linux/version.h> |
98 | #include <linux/dma-mapping.h> | 94 | #include <linux/dma-mapping.h> |
99 | #include <linux/crc32.h> | 95 | #include <linux/crc32.h> |
96 | #include <linux/mii.h> | ||
97 | #include <linux/phy.h> | ||
100 | 98 | ||
101 | #include "gianfar.h" | 99 | #include "gianfar.h" |
102 | #include "gianfar_phy.h" | 100 | #include "gianfar_mii.h" |
103 | 101 | ||
104 | #define TX_TIMEOUT (1*HZ) | 102 | #define TX_TIMEOUT (1*HZ) |
105 | #define SKB_ALLOC_TIMEOUT 1000000 | 103 | #define SKB_ALLOC_TIMEOUT 1000000 |
@@ -113,9 +111,8 @@ | |||
113 | #endif | 111 | #endif |
114 | 112 | ||
115 | const char gfar_driver_name[] = "Gianfar Ethernet"; | 113 | const char gfar_driver_name[] = "Gianfar Ethernet"; |
116 | const char gfar_driver_version[] = "1.1"; | 114 | const char gfar_driver_version[] = "1.2"; |
117 | 115 | ||
118 | int startup_gfar(struct net_device *dev); | ||
119 | static int gfar_enet_open(struct net_device *dev); | 116 | static int gfar_enet_open(struct net_device *dev); |
120 | static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev); | 117 | static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev); |
121 | static void gfar_timeout(struct net_device *dev); | 118 | static void gfar_timeout(struct net_device *dev); |
@@ -126,17 +123,13 @@ static int gfar_set_mac_address(struct net_device *dev); | |||
126 | static int gfar_change_mtu(struct net_device *dev, int new_mtu); | 123 | static int gfar_change_mtu(struct net_device *dev, int new_mtu); |
127 | static irqreturn_t gfar_error(int irq, void *dev_id, struct pt_regs *regs); | 124 | static irqreturn_t gfar_error(int irq, void *dev_id, struct pt_regs *regs); |
128 | static irqreturn_t gfar_transmit(int irq, void *dev_id, struct pt_regs *regs); | 125 | static irqreturn_t gfar_transmit(int irq, void *dev_id, struct pt_regs *regs); |
129 | static irqreturn_t gfar_receive(int irq, void *dev_id, struct pt_regs *regs); | ||
130 | static irqreturn_t gfar_interrupt(int irq, void *dev_id, struct pt_regs *regs); | 126 | static irqreturn_t gfar_interrupt(int irq, void *dev_id, struct pt_regs *regs); |
131 | static irqreturn_t phy_interrupt(int irq, void *dev_id, struct pt_regs *regs); | ||
132 | static void gfar_phy_change(void *data); | ||
133 | static void gfar_phy_timer(unsigned long data); | ||
134 | static void adjust_link(struct net_device *dev); | 127 | static void adjust_link(struct net_device *dev); |
135 | static void init_registers(struct net_device *dev); | 128 | static void init_registers(struct net_device *dev); |
136 | static int init_phy(struct net_device *dev); | 129 | static int init_phy(struct net_device *dev); |
137 | static int gfar_probe(struct device *device); | 130 | static int gfar_probe(struct device *device); |
138 | static int gfar_remove(struct device *device); | 131 | static int gfar_remove(struct device *device); |
139 | void free_skb_resources(struct gfar_private *priv); | 132 | static void free_skb_resources(struct gfar_private *priv); |
140 | static void gfar_set_multi(struct net_device *dev); | 133 | static void gfar_set_multi(struct net_device *dev); |
141 | static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr); | 134 | static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr); |
142 | #ifdef CONFIG_GFAR_NAPI | 135 | #ifdef CONFIG_GFAR_NAPI |
@@ -144,7 +137,6 @@ static int gfar_poll(struct net_device *dev, int *budget); | |||
144 | #endif | 137 | #endif |
145 | int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit); | 138 | int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit); |
146 | static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb, int length); | 139 | static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb, int length); |
147 | static void gfar_phy_startup_timer(unsigned long data); | ||
148 | static void gfar_vlan_rx_register(struct net_device *netdev, | 140 | static void gfar_vlan_rx_register(struct net_device *netdev, |
149 | struct vlan_group *grp); | 141 | struct vlan_group *grp); |
150 | static void gfar_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid); | 142 | static void gfar_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid); |
@@ -162,6 +154,9 @@ int gfar_uses_fcb(struct gfar_private *priv) | |||
162 | else | 154 | else |
163 | return 0; | 155 | return 0; |
164 | } | 156 | } |
157 | |||
158 | /* Set up the ethernet device structure, private data, | ||
159 | * and anything else we need before we start */ | ||
165 | static int gfar_probe(struct device *device) | 160 | static int gfar_probe(struct device *device) |
166 | { | 161 | { |
167 | u32 tempval; | 162 | u32 tempval; |
@@ -175,7 +170,7 @@ static int gfar_probe(struct device *device) | |||
175 | 170 | ||
176 | einfo = (struct gianfar_platform_data *) pdev->dev.platform_data; | 171 | einfo = (struct gianfar_platform_data *) pdev->dev.platform_data; |
177 | 172 | ||
178 | if (einfo == NULL) { | 173 | if (NULL == einfo) { |
179 | printk(KERN_ERR "gfar %d: Missing additional data!\n", | 174 | printk(KERN_ERR "gfar %d: Missing additional data!\n", |
180 | pdev->id); | 175 | pdev->id); |
181 | 176 | ||
@@ -185,7 +180,7 @@ static int gfar_probe(struct device *device) | |||
185 | /* Create an ethernet device instance */ | 180 | /* Create an ethernet device instance */ |
186 | dev = alloc_etherdev(sizeof (*priv)); | 181 | dev = alloc_etherdev(sizeof (*priv)); |
187 | 182 | ||
188 | if (dev == NULL) | 183 | if (NULL == dev) |
189 | return -ENOMEM; | 184 | return -ENOMEM; |
190 | 185 | ||
191 | priv = netdev_priv(dev); | 186 | priv = netdev_priv(dev); |
@@ -207,20 +202,11 @@ static int gfar_probe(struct device *device) | |||
207 | priv->regs = (struct gfar *) | 202 | priv->regs = (struct gfar *) |
208 | ioremap(r->start, sizeof (struct gfar)); | 203 | ioremap(r->start, sizeof (struct gfar)); |
209 | 204 | ||
210 | if (priv->regs == NULL) { | 205 | if (NULL == priv->regs) { |
211 | err = -ENOMEM; | 206 | err = -ENOMEM; |
212 | goto regs_fail; | 207 | goto regs_fail; |
213 | } | 208 | } |
214 | 209 | ||
215 | /* Set the PHY base address */ | ||
216 | priv->phyregs = (struct gfar *) | ||
217 | ioremap(einfo->phy_reg_addr, sizeof (struct gfar)); | ||
218 | |||
219 | if (priv->phyregs == NULL) { | ||
220 | err = -ENOMEM; | ||
221 | goto phy_regs_fail; | ||
222 | } | ||
223 | |||
224 | spin_lock_init(&priv->lock); | 210 | spin_lock_init(&priv->lock); |
225 | 211 | ||
226 | dev_set_drvdata(device, dev); | 212 | dev_set_drvdata(device, dev); |
@@ -386,12 +372,10 @@ static int gfar_probe(struct device *device) | |||
386 | return 0; | 372 | return 0; |
387 | 373 | ||
388 | register_fail: | 374 | register_fail: |
389 | iounmap((void *) priv->phyregs); | ||
390 | phy_regs_fail: | ||
391 | iounmap((void *) priv->regs); | 375 | iounmap((void *) priv->regs); |
392 | regs_fail: | 376 | regs_fail: |
393 | free_netdev(dev); | 377 | free_netdev(dev); |
394 | return -ENOMEM; | 378 | return err; |
395 | } | 379 | } |
396 | 380 | ||
397 | static int gfar_remove(struct device *device) | 381 | static int gfar_remove(struct device *device) |
@@ -402,108 +386,41 @@ static int gfar_remove(struct device *device) | |||
402 | dev_set_drvdata(device, NULL); | 386 | dev_set_drvdata(device, NULL); |
403 | 387 | ||
404 | iounmap((void *) priv->regs); | 388 | iounmap((void *) priv->regs); |
405 | iounmap((void *) priv->phyregs); | ||
406 | free_netdev(dev); | 389 | free_netdev(dev); |
407 | 390 | ||
408 | return 0; | 391 | return 0; |
409 | } | 392 | } |
410 | 393 | ||
411 | 394 | ||
412 | /* Configure the PHY for dev. | 395 | /* Initializes driver's PHY state, and attaches to the PHY. |
413 | * returns 0 if success. -1 if failure | 396 | * Returns 0 on success. |
414 | */ | 397 | */ |
415 | static int init_phy(struct net_device *dev) | 398 | static int init_phy(struct net_device *dev) |
416 | { | 399 | { |
417 | struct gfar_private *priv = netdev_priv(dev); | 400 | struct gfar_private *priv = netdev_priv(dev); |
418 | struct phy_info *curphy; | 401 | uint gigabit_support = |
419 | unsigned int timeout = PHY_INIT_TIMEOUT; | 402 | priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT ? |
420 | struct gfar *phyregs = priv->phyregs; | 403 | SUPPORTED_1000baseT_Full : 0; |
421 | struct gfar_mii_info *mii_info; | 404 | struct phy_device *phydev; |
422 | int err; | ||
423 | 405 | ||
424 | priv->oldlink = 0; | 406 | priv->oldlink = 0; |
425 | priv->oldspeed = 0; | 407 | priv->oldspeed = 0; |
426 | priv->oldduplex = -1; | 408 | priv->oldduplex = -1; |
427 | 409 | ||
428 | mii_info = kmalloc(sizeof(struct gfar_mii_info), | 410 | phydev = phy_connect(dev, priv->einfo->bus_id, &adjust_link, 0); |
429 | GFP_KERNEL); | ||
430 | |||
431 | if(NULL == mii_info) { | ||
432 | if (netif_msg_ifup(priv)) | ||
433 | printk(KERN_ERR "%s: Could not allocate mii_info\n", | ||
434 | dev->name); | ||
435 | return -ENOMEM; | ||
436 | } | ||
437 | |||
438 | mii_info->speed = SPEED_1000; | ||
439 | mii_info->duplex = DUPLEX_FULL; | ||
440 | mii_info->pause = 0; | ||
441 | mii_info->link = 1; | ||
442 | |||
443 | mii_info->advertising = (ADVERTISED_10baseT_Half | | ||
444 | ADVERTISED_10baseT_Full | | ||
445 | ADVERTISED_100baseT_Half | | ||
446 | ADVERTISED_100baseT_Full | | ||
447 | ADVERTISED_1000baseT_Full); | ||
448 | mii_info->autoneg = 1; | ||
449 | 411 | ||
450 | spin_lock_init(&mii_info->mdio_lock); | 412 | if (IS_ERR(phydev)) { |
451 | 413 | printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name); | |
452 | mii_info->mii_id = priv->einfo->phyid; | 414 | return PTR_ERR(phydev); |
453 | |||
454 | mii_info->dev = dev; | ||
455 | |||
456 | mii_info->mdio_read = &read_phy_reg; | ||
457 | mii_info->mdio_write = &write_phy_reg; | ||
458 | |||
459 | priv->mii_info = mii_info; | ||
460 | |||
461 | /* Reset the management interface */ | ||
462 | gfar_write(&phyregs->miimcfg, MIIMCFG_RESET); | ||
463 | |||
464 | /* Setup the MII Mgmt clock speed */ | ||
465 | gfar_write(&phyregs->miimcfg, MIIMCFG_INIT_VALUE); | ||
466 | |||
467 | /* Wait until the bus is free */ | ||
468 | while ((gfar_read(&phyregs->miimind) & MIIMIND_BUSY) && | ||
469 | timeout--) | ||
470 | cpu_relax(); | ||
471 | |||
472 | if(timeout <= 0) { | ||
473 | printk(KERN_ERR "%s: The MII Bus is stuck!\n", | ||
474 | dev->name); | ||
475 | err = -1; | ||
476 | goto bus_fail; | ||
477 | } | ||
478 | |||
479 | /* get info for this PHY */ | ||
480 | curphy = get_phy_info(priv->mii_info); | ||
481 | |||
482 | if (curphy == NULL) { | ||
483 | if (netif_msg_ifup(priv)) | ||
484 | printk(KERN_ERR "%s: No PHY found\n", dev->name); | ||
485 | err = -1; | ||
486 | goto no_phy; | ||
487 | } | 415 | } |
488 | 416 | ||
489 | mii_info->phyinfo = curphy; | 417 | /* Remove any features not supported by the controller */ |
418 | phydev->supported &= (GFAR_SUPPORTED | gigabit_support); | ||
419 | phydev->advertising = phydev->supported; | ||
490 | 420 | ||
491 | /* Run the commands which initialize the PHY */ | 421 | priv->phydev = phydev; |
492 | if(curphy->init) { | ||
493 | err = curphy->init(priv->mii_info); | ||
494 | |||
495 | if (err) | ||
496 | goto phy_init_fail; | ||
497 | } | ||
498 | 422 | ||
499 | return 0; | 423 | return 0; |
500 | |||
501 | phy_init_fail: | ||
502 | no_phy: | ||
503 | bus_fail: | ||
504 | kfree(mii_info); | ||
505 | |||
506 | return err; | ||
507 | } | 424 | } |
508 | 425 | ||
509 | static void init_registers(struct net_device *dev) | 426 | static void init_registers(struct net_device *dev) |
@@ -603,24 +520,13 @@ void stop_gfar(struct net_device *dev) | |||
603 | struct gfar *regs = priv->regs; | 520 | struct gfar *regs = priv->regs; |
604 | unsigned long flags; | 521 | unsigned long flags; |
605 | 522 | ||
523 | phy_stop(priv->phydev); | ||
524 | |||
606 | /* Lock it down */ | 525 | /* Lock it down */ |
607 | spin_lock_irqsave(&priv->lock, flags); | 526 | spin_lock_irqsave(&priv->lock, flags); |
608 | 527 | ||
609 | /* Tell the kernel the link is down */ | ||
610 | priv->mii_info->link = 0; | ||
611 | adjust_link(dev); | ||
612 | |||
613 | gfar_halt(dev); | 528 | gfar_halt(dev); |
614 | 529 | ||
615 | if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) { | ||
616 | /* Clear any pending interrupts */ | ||
617 | mii_clear_phy_interrupt(priv->mii_info); | ||
618 | |||
619 | /* Disable PHY Interrupts */ | ||
620 | mii_configure_phy_interrupt(priv->mii_info, | ||
621 | MII_INTERRUPT_DISABLED); | ||
622 | } | ||
623 | |||
624 | spin_unlock_irqrestore(&priv->lock, flags); | 530 | spin_unlock_irqrestore(&priv->lock, flags); |
625 | 531 | ||
626 | /* Free the IRQs */ | 532 | /* Free the IRQs */ |
@@ -629,13 +535,7 @@ void stop_gfar(struct net_device *dev) | |||
629 | free_irq(priv->interruptTransmit, dev); | 535 | free_irq(priv->interruptTransmit, dev); |
630 | free_irq(priv->interruptReceive, dev); | 536 | free_irq(priv->interruptReceive, dev); |
631 | } else { | 537 | } else { |
632 | free_irq(priv->interruptTransmit, dev); | 538 | free_irq(priv->interruptTransmit, dev); |
633 | } | ||
634 | |||
635 | if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) { | ||
636 | free_irq(priv->einfo->interruptPHY, dev); | ||
637 | } else { | ||
638 | del_timer_sync(&priv->phy_info_timer); | ||
639 | } | 539 | } |
640 | 540 | ||
641 | free_skb_resources(priv); | 541 | free_skb_resources(priv); |
@@ -649,7 +549,7 @@ void stop_gfar(struct net_device *dev) | |||
649 | 549 | ||
650 | /* If there are any tx skbs or rx skbs still around, free them. | 550 | /* If there are any tx skbs or rx skbs still around, free them. |
651 | * Then free tx_skbuff and rx_skbuff */ | 551 | * Then free tx_skbuff and rx_skbuff */ |
652 | void free_skb_resources(struct gfar_private *priv) | 552 | static void free_skb_resources(struct gfar_private *priv) |
653 | { | 553 | { |
654 | struct rxbd8 *rxbdp; | 554 | struct rxbd8 *rxbdp; |
655 | struct txbd8 *txbdp; | 555 | struct txbd8 *txbdp; |
@@ -770,7 +670,7 @@ int startup_gfar(struct net_device *dev) | |||
770 | (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) * | 670 | (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) * |
771 | priv->tx_ring_size, GFP_KERNEL); | 671 | priv->tx_ring_size, GFP_KERNEL); |
772 | 672 | ||
773 | if (priv->tx_skbuff == NULL) { | 673 | if (NULL == priv->tx_skbuff) { |
774 | if (netif_msg_ifup(priv)) | 674 | if (netif_msg_ifup(priv)) |
775 | printk(KERN_ERR "%s: Could not allocate tx_skbuff\n", | 675 | printk(KERN_ERR "%s: Could not allocate tx_skbuff\n", |
776 | dev->name); | 676 | dev->name); |
@@ -785,7 +685,7 @@ int startup_gfar(struct net_device *dev) | |||
785 | (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) * | 685 | (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) * |
786 | priv->rx_ring_size, GFP_KERNEL); | 686 | priv->rx_ring_size, GFP_KERNEL); |
787 | 687 | ||
788 | if (priv->rx_skbuff == NULL) { | 688 | if (NULL == priv->rx_skbuff) { |
789 | if (netif_msg_ifup(priv)) | 689 | if (netif_msg_ifup(priv)) |
790 | printk(KERN_ERR "%s: Could not allocate rx_skbuff\n", | 690 | printk(KERN_ERR "%s: Could not allocate rx_skbuff\n", |
791 | dev->name); | 691 | dev->name); |
@@ -879,13 +779,7 @@ int startup_gfar(struct net_device *dev) | |||
879 | } | 779 | } |
880 | } | 780 | } |
881 | 781 | ||
882 | /* Set up the PHY change work queue */ | 782 | phy_start(priv->phydev); |
883 | INIT_WORK(&priv->tq, gfar_phy_change, dev); | ||
884 | |||
885 | init_timer(&priv->phy_info_timer); | ||
886 | priv->phy_info_timer.function = &gfar_phy_startup_timer; | ||
887 | priv->phy_info_timer.data = (unsigned long) priv->mii_info; | ||
888 | mod_timer(&priv->phy_info_timer, jiffies + HZ); | ||
889 | 783 | ||
890 | /* Configure the coalescing support */ | 784 | /* Configure the coalescing support */ |
891 | if (priv->txcoalescing) | 785 | if (priv->txcoalescing) |
@@ -933,11 +827,6 @@ tx_skb_fail: | |||
933 | priv->tx_bd_base, | 827 | priv->tx_bd_base, |
934 | gfar_read(®s->tbase0)); | 828 | gfar_read(®s->tbase0)); |
935 | 829 | ||
936 | if (priv->mii_info->phyinfo->close) | ||
937 | priv->mii_info->phyinfo->close(priv->mii_info); | ||
938 | |||
939 | kfree(priv->mii_info); | ||
940 | |||
941 | return err; | 830 | return err; |
942 | } | 831 | } |
943 | 832 | ||
@@ -1035,7 +924,7 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
1035 | txbdp->status &= TXBD_WRAP; | 924 | txbdp->status &= TXBD_WRAP; |
1036 | 925 | ||
1037 | /* Set up checksumming */ | 926 | /* Set up checksumming */ |
1038 | if ((dev->features & NETIF_F_IP_CSUM) | 927 | if ((dev->features & NETIF_F_IP_CSUM) |
1039 | && (CHECKSUM_HW == skb->ip_summed)) { | 928 | && (CHECKSUM_HW == skb->ip_summed)) { |
1040 | fcb = gfar_add_fcb(skb, txbdp); | 929 | fcb = gfar_add_fcb(skb, txbdp); |
1041 | gfar_tx_checksum(skb, fcb); | 930 | gfar_tx_checksum(skb, fcb); |
@@ -1103,11 +992,9 @@ static int gfar_close(struct net_device *dev) | |||
1103 | struct gfar_private *priv = netdev_priv(dev); | 992 | struct gfar_private *priv = netdev_priv(dev); |
1104 | stop_gfar(dev); | 993 | stop_gfar(dev); |
1105 | 994 | ||
1106 | /* Shutdown the PHY */ | 995 | /* Disconnect from the PHY */ |
1107 | if (priv->mii_info->phyinfo->close) | 996 | phy_disconnect(priv->phydev); |
1108 | priv->mii_info->phyinfo->close(priv->mii_info); | 997 | priv->phydev = NULL; |
1109 | |||
1110 | kfree(priv->mii_info); | ||
1111 | 998 | ||
1112 | netif_stop_queue(dev); | 999 | netif_stop_queue(dev); |
1113 | 1000 | ||
@@ -1343,7 +1230,7 @@ struct sk_buff * gfar_new_skb(struct net_device *dev, struct rxbd8 *bdp) | |||
1343 | while ((!skb) && timeout--) | 1230 | while ((!skb) && timeout--) |
1344 | skb = dev_alloc_skb(priv->rx_buffer_size + RXBUF_ALIGNMENT); | 1231 | skb = dev_alloc_skb(priv->rx_buffer_size + RXBUF_ALIGNMENT); |
1345 | 1232 | ||
1346 | if (skb == NULL) | 1233 | if (NULL == skb) |
1347 | return NULL; | 1234 | return NULL; |
1348 | 1235 | ||
1349 | /* We need the data buffer to be aligned properly. We will reserve | 1236 | /* We need the data buffer to be aligned properly. We will reserve |
@@ -1490,7 +1377,7 @@ static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb, | |||
1490 | struct gfar_private *priv = netdev_priv(dev); | 1377 | struct gfar_private *priv = netdev_priv(dev); |
1491 | struct rxfcb *fcb = NULL; | 1378 | struct rxfcb *fcb = NULL; |
1492 | 1379 | ||
1493 | if (skb == NULL) { | 1380 | if (NULL == skb) { |
1494 | if (netif_msg_rx_err(priv)) | 1381 | if (netif_msg_rx_err(priv)) |
1495 | printk(KERN_WARNING "%s: Missing skb!!.\n", dev->name); | 1382 | printk(KERN_WARNING "%s: Missing skb!!.\n", dev->name); |
1496 | priv->stats.rx_dropped++; | 1383 | priv->stats.rx_dropped++; |
@@ -1718,131 +1605,9 @@ static irqreturn_t gfar_interrupt(int irq, void *dev_id, struct pt_regs *regs) | |||
1718 | return IRQ_HANDLED; | 1605 | return IRQ_HANDLED; |
1719 | } | 1606 | } |
1720 | 1607 | ||
1721 | static irqreturn_t phy_interrupt(int irq, void *dev_id, struct pt_regs *regs) | ||
1722 | { | ||
1723 | struct net_device *dev = (struct net_device *) dev_id; | ||
1724 | struct gfar_private *priv = netdev_priv(dev); | ||
1725 | |||
1726 | /* Clear the interrupt */ | ||
1727 | mii_clear_phy_interrupt(priv->mii_info); | ||
1728 | |||
1729 | /* Disable PHY interrupts */ | ||
1730 | mii_configure_phy_interrupt(priv->mii_info, | ||
1731 | MII_INTERRUPT_DISABLED); | ||
1732 | |||
1733 | /* Schedule the phy change */ | ||
1734 | schedule_work(&priv->tq); | ||
1735 | |||
1736 | return IRQ_HANDLED; | ||
1737 | } | ||
1738 | |||
1739 | /* Scheduled by the phy_interrupt/timer to handle PHY changes */ | ||
1740 | static void gfar_phy_change(void *data) | ||
1741 | { | ||
1742 | struct net_device *dev = (struct net_device *) data; | ||
1743 | struct gfar_private *priv = netdev_priv(dev); | ||
1744 | int result = 0; | ||
1745 | |||
1746 | /* Delay to give the PHY a chance to change the | ||
1747 | * register state */ | ||
1748 | msleep(1); | ||
1749 | |||
1750 | /* Update the link, speed, duplex */ | ||
1751 | result = priv->mii_info->phyinfo->read_status(priv->mii_info); | ||
1752 | |||
1753 | /* Adjust the known status as long as the link | ||
1754 | * isn't still coming up */ | ||
1755 | if((0 == result) || (priv->mii_info->link == 0)) | ||
1756 | adjust_link(dev); | ||
1757 | |||
1758 | /* Reenable interrupts, if needed */ | ||
1759 | if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) | ||
1760 | mii_configure_phy_interrupt(priv->mii_info, | ||
1761 | MII_INTERRUPT_ENABLED); | ||
1762 | } | ||
1763 | |||
1764 | /* Called every so often on systems that don't interrupt | ||
1765 | * the core for PHY changes */ | ||
1766 | static void gfar_phy_timer(unsigned long data) | ||
1767 | { | ||
1768 | struct net_device *dev = (struct net_device *) data; | ||
1769 | struct gfar_private *priv = netdev_priv(dev); | ||
1770 | |||
1771 | schedule_work(&priv->tq); | ||
1772 | |||
1773 | mod_timer(&priv->phy_info_timer, jiffies + | ||
1774 | GFAR_PHY_CHANGE_TIME * HZ); | ||
1775 | } | ||
1776 | |||
1777 | /* Keep trying aneg for some time | ||
1778 | * If, after GFAR_AN_TIMEOUT seconds, it has not | ||
1779 | * finished, we switch to forced. | ||
1780 | * Either way, once the process has completed, we either | ||
1781 | * request the interrupt, or switch the timer over to | ||
1782 | * using gfar_phy_timer to check status */ | ||
1783 | static void gfar_phy_startup_timer(unsigned long data) | ||
1784 | { | ||
1785 | int result; | ||
1786 | static int secondary = GFAR_AN_TIMEOUT; | ||
1787 | struct gfar_mii_info *mii_info = (struct gfar_mii_info *)data; | ||
1788 | struct gfar_private *priv = netdev_priv(mii_info->dev); | ||
1789 | |||
1790 | /* Configure the Auto-negotiation */ | ||
1791 | result = mii_info->phyinfo->config_aneg(mii_info); | ||
1792 | |||
1793 | /* If autonegotiation failed to start, and | ||
1794 | * we haven't timed out, reset the timer, and return */ | ||
1795 | if (result && secondary--) { | ||
1796 | mod_timer(&priv->phy_info_timer, jiffies + HZ); | ||
1797 | return; | ||
1798 | } else if (result) { | ||
1799 | /* Couldn't start autonegotiation. | ||
1800 | * Try switching to forced */ | ||
1801 | mii_info->autoneg = 0; | ||
1802 | result = mii_info->phyinfo->config_aneg(mii_info); | ||
1803 | |||
1804 | /* Forcing failed! Give up */ | ||
1805 | if(result) { | ||
1806 | if (netif_msg_link(priv)) | ||
1807 | printk(KERN_ERR "%s: Forcing failed!\n", | ||
1808 | mii_info->dev->name); | ||
1809 | return; | ||
1810 | } | ||
1811 | } | ||
1812 | |||
1813 | /* Kill the timer so it can be restarted */ | ||
1814 | del_timer_sync(&priv->phy_info_timer); | ||
1815 | |||
1816 | /* Grab the PHY interrupt, if necessary/possible */ | ||
1817 | if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) { | ||
1818 | if (request_irq(priv->einfo->interruptPHY, | ||
1819 | phy_interrupt, | ||
1820 | SA_SHIRQ, | ||
1821 | "phy_interrupt", | ||
1822 | mii_info->dev) < 0) { | ||
1823 | if (netif_msg_intr(priv)) | ||
1824 | printk(KERN_ERR "%s: Can't get IRQ %d (PHY)\n", | ||
1825 | mii_info->dev->name, | ||
1826 | priv->einfo->interruptPHY); | ||
1827 | } else { | ||
1828 | mii_configure_phy_interrupt(priv->mii_info, | ||
1829 | MII_INTERRUPT_ENABLED); | ||
1830 | return; | ||
1831 | } | ||
1832 | } | ||
1833 | |||
1834 | /* Start the timer again, this time in order to | ||
1835 | * handle a change in status */ | ||
1836 | init_timer(&priv->phy_info_timer); | ||
1837 | priv->phy_info_timer.function = &gfar_phy_timer; | ||
1838 | priv->phy_info_timer.data = (unsigned long) mii_info->dev; | ||
1839 | mod_timer(&priv->phy_info_timer, jiffies + | ||
1840 | GFAR_PHY_CHANGE_TIME * HZ); | ||
1841 | } | ||
1842 | |||
1843 | /* Called every time the controller might need to be made | 1608 | /* Called every time the controller might need to be made |
1844 | * aware of new link state. The PHY code conveys this | 1609 | * aware of new link state. The PHY code conveys this |
1845 | * information through variables in the priv structure, and this | 1610 | * information through variables in the phydev structure, and this |
1846 | * function converts those variables into the appropriate | 1611 | * function converts those variables into the appropriate |
1847 | * register values, and can bring down the device if needed. | 1612 | * register values, and can bring down the device if needed. |
1848 | */ | 1613 | */ |
@@ -1850,84 +1615,68 @@ static void adjust_link(struct net_device *dev) | |||
1850 | { | 1615 | { |
1851 | struct gfar_private *priv = netdev_priv(dev); | 1616 | struct gfar_private *priv = netdev_priv(dev); |
1852 | struct gfar *regs = priv->regs; | 1617 | struct gfar *regs = priv->regs; |
1853 | u32 tempval; | 1618 | unsigned long flags; |
1854 | struct gfar_mii_info *mii_info = priv->mii_info; | 1619 | struct phy_device *phydev = priv->phydev; |
1620 | int new_state = 0; | ||
1621 | |||
1622 | spin_lock_irqsave(&priv->lock, flags); | ||
1623 | if (phydev->link) { | ||
1624 | u32 tempval = gfar_read(®s->maccfg2); | ||
1855 | 1625 | ||
1856 | if (mii_info->link) { | ||
1857 | /* Now we make sure that we can be in full duplex mode. | 1626 | /* Now we make sure that we can be in full duplex mode. |
1858 | * If not, we operate in half-duplex mode. */ | 1627 | * If not, we operate in half-duplex mode. */ |
1859 | if (mii_info->duplex != priv->oldduplex) { | 1628 | if (phydev->duplex != priv->oldduplex) { |
1860 | if (!(mii_info->duplex)) { | 1629 | new_state = 1; |
1861 | tempval = gfar_read(®s->maccfg2); | 1630 | if (!(phydev->duplex)) |
1862 | tempval &= ~(MACCFG2_FULL_DUPLEX); | 1631 | tempval &= ~(MACCFG2_FULL_DUPLEX); |
1863 | gfar_write(®s->maccfg2, tempval); | 1632 | else |
1864 | |||
1865 | if (netif_msg_link(priv)) | ||
1866 | printk(KERN_INFO "%s: Half Duplex\n", | ||
1867 | dev->name); | ||
1868 | } else { | ||
1869 | tempval = gfar_read(®s->maccfg2); | ||
1870 | tempval |= MACCFG2_FULL_DUPLEX; | 1633 | tempval |= MACCFG2_FULL_DUPLEX; |
1871 | gfar_write(®s->maccfg2, tempval); | ||
1872 | 1634 | ||
1873 | if (netif_msg_link(priv)) | 1635 | priv->oldduplex = phydev->duplex; |
1874 | printk(KERN_INFO "%s: Full Duplex\n", | ||
1875 | dev->name); | ||
1876 | } | ||
1877 | |||
1878 | priv->oldduplex = mii_info->duplex; | ||
1879 | } | 1636 | } |
1880 | 1637 | ||
1881 | if (mii_info->speed != priv->oldspeed) { | 1638 | if (phydev->speed != priv->oldspeed) { |
1882 | switch (mii_info->speed) { | 1639 | new_state = 1; |
1640 | switch (phydev->speed) { | ||
1883 | case 1000: | 1641 | case 1000: |
1884 | tempval = gfar_read(®s->maccfg2); | ||
1885 | tempval = | 1642 | tempval = |
1886 | ((tempval & ~(MACCFG2_IF)) | MACCFG2_GMII); | 1643 | ((tempval & ~(MACCFG2_IF)) | MACCFG2_GMII); |
1887 | gfar_write(®s->maccfg2, tempval); | ||
1888 | break; | 1644 | break; |
1889 | case 100: | 1645 | case 100: |
1890 | case 10: | 1646 | case 10: |
1891 | tempval = gfar_read(®s->maccfg2); | ||
1892 | tempval = | 1647 | tempval = |
1893 | ((tempval & ~(MACCFG2_IF)) | MACCFG2_MII); | 1648 | ((tempval & ~(MACCFG2_IF)) | MACCFG2_MII); |
1894 | gfar_write(®s->maccfg2, tempval); | ||
1895 | break; | 1649 | break; |
1896 | default: | 1650 | default: |
1897 | if (netif_msg_link(priv)) | 1651 | if (netif_msg_link(priv)) |
1898 | printk(KERN_WARNING | 1652 | printk(KERN_WARNING |
1899 | "%s: Ack! Speed (%d) is not 10/100/1000!\n", | 1653 | "%s: Ack! Speed (%d) is not 10/100/1000!\n", |
1900 | dev->name, mii_info->speed); | 1654 | dev->name, phydev->speed); |
1901 | break; | 1655 | break; |
1902 | } | 1656 | } |
1903 | 1657 | ||
1904 | if (netif_msg_link(priv)) | 1658 | priv->oldspeed = phydev->speed; |
1905 | printk(KERN_INFO "%s: Speed %dBT\n", dev->name, | ||
1906 | mii_info->speed); | ||
1907 | |||
1908 | priv->oldspeed = mii_info->speed; | ||
1909 | } | 1659 | } |
1910 | 1660 | ||
1661 | gfar_write(®s->maccfg2, tempval); | ||
1662 | |||
1911 | if (!priv->oldlink) { | 1663 | if (!priv->oldlink) { |
1912 | if (netif_msg_link(priv)) | 1664 | new_state = 1; |
1913 | printk(KERN_INFO "%s: Link is up\n", dev->name); | ||
1914 | priv->oldlink = 1; | 1665 | priv->oldlink = 1; |
1915 | netif_carrier_on(dev); | ||
1916 | netif_schedule(dev); | 1666 | netif_schedule(dev); |
1917 | } | 1667 | } |
1918 | } else { | 1668 | } else if (priv->oldlink) { |
1919 | if (priv->oldlink) { | 1669 | new_state = 1; |
1920 | if (netif_msg_link(priv)) | 1670 | priv->oldlink = 0; |
1921 | printk(KERN_INFO "%s: Link is down\n", | 1671 | priv->oldspeed = 0; |
1922 | dev->name); | 1672 | priv->oldduplex = -1; |
1923 | priv->oldlink = 0; | ||
1924 | priv->oldspeed = 0; | ||
1925 | priv->oldduplex = -1; | ||
1926 | netif_carrier_off(dev); | ||
1927 | } | ||
1928 | } | 1673 | } |
1929 | } | ||
1930 | 1674 | ||
1675 | if (new_state && netif_msg_link(priv)) | ||
1676 | phy_print_status(phydev); | ||
1677 | |||
1678 | spin_unlock_irqrestore(&priv->lock, flags); | ||
1679 | } | ||
1931 | 1680 | ||
1932 | /* Update the hash table based on the current list of multicast | 1681 | /* Update the hash table based on the current list of multicast |
1933 | * addresses we subscribe to. Also, change the promiscuity of | 1682 | * addresses we subscribe to. Also, change the promiscuity of |
@@ -2122,12 +1871,23 @@ static struct device_driver gfar_driver = { | |||
2122 | 1871 | ||
2123 | static int __init gfar_init(void) | 1872 | static int __init gfar_init(void) |
2124 | { | 1873 | { |
2125 | return driver_register(&gfar_driver); | 1874 | int err = gfar_mdio_init(); |
1875 | |||
1876 | if (err) | ||
1877 | return err; | ||
1878 | |||
1879 | err = driver_register(&gfar_driver); | ||
1880 | |||
1881 | if (err) | ||
1882 | gfar_mdio_exit(); | ||
1883 | |||
1884 | return err; | ||
2126 | } | 1885 | } |
2127 | 1886 | ||
2128 | static void __exit gfar_exit(void) | 1887 | static void __exit gfar_exit(void) |
2129 | { | 1888 | { |
2130 | driver_unregister(&gfar_driver); | 1889 | driver_unregister(&gfar_driver); |
1890 | gfar_mdio_exit(); | ||
2131 | } | 1891 | } |
2132 | 1892 | ||
2133 | module_init(gfar_init); | 1893 | module_init(gfar_init); |