aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/fec.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/fec.c')
-rw-r--r--drivers/net/fec.c125
1 files changed, 57 insertions, 68 deletions
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index d7a3ea88edd..32a4f17d35f 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -67,6 +67,10 @@
67#define FEC_MAX_PORTS 1 67#define FEC_MAX_PORTS 1
68#endif 68#endif
69 69
70#if defined(CONFIG_FADS) || defined(CONFIG_RPXCLASSIC) || defined(CONFIG_M5272)
71#define HAVE_mii_link_interrupt
72#endif
73
70/* 74/*
71 * Define the fixed address of the FEC hardware. 75 * Define the fixed address of the FEC hardware.
72 */ 76 */
@@ -205,7 +209,10 @@ struct fec_enet_private {
205 cbd_t *cur_rx, *cur_tx; /* The next free ring entry */ 209 cbd_t *cur_rx, *cur_tx; /* The next free ring entry */
206 cbd_t *dirty_tx; /* The ring entries to be free()ed. */ 210 cbd_t *dirty_tx; /* The ring entries to be free()ed. */
207 uint tx_full; 211 uint tx_full;
208 spinlock_t lock; 212 /* hold while accessing the HW like ringbuffer for tx/rx but not MAC */
213 spinlock_t hw_lock;
214 /* hold while accessing the mii_list_t() elements */
215 spinlock_t mii_lock;
209 216
210 uint phy_id; 217 uint phy_id;
211 uint phy_id_done; 218 uint phy_id_done;
@@ -309,6 +316,7 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
309 volatile fec_t *fecp; 316 volatile fec_t *fecp;
310 volatile cbd_t *bdp; 317 volatile cbd_t *bdp;
311 unsigned short status; 318 unsigned short status;
319 unsigned long flags;
312 320
313 fep = netdev_priv(dev); 321 fep = netdev_priv(dev);
314 fecp = (volatile fec_t*)dev->base_addr; 322 fecp = (volatile fec_t*)dev->base_addr;
@@ -318,6 +326,7 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
318 return 1; 326 return 1;
319 } 327 }
320 328
329 spin_lock_irqsave(&fep->hw_lock, flags);
321 /* Fill in a Tx ring entry */ 330 /* Fill in a Tx ring entry */
322 bdp = fep->cur_tx; 331 bdp = fep->cur_tx;
323 332
@@ -328,6 +337,7 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
328 * This should not happen, since dev->tbusy should be set. 337 * This should not happen, since dev->tbusy should be set.
329 */ 338 */
330 printk("%s: tx queue full!.\n", dev->name); 339 printk("%s: tx queue full!.\n", dev->name);
340 spin_unlock_irqrestore(&fep->hw_lock, flags);
331 return 1; 341 return 1;
332 } 342 }
333#endif 343#endif
@@ -366,8 +376,6 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
366 flush_dcache_range((unsigned long)skb->data, 376 flush_dcache_range((unsigned long)skb->data,
367 (unsigned long)skb->data + skb->len); 377 (unsigned long)skb->data + skb->len);
368 378
369 spin_lock_irq(&fep->lock);
370
371 /* Send it on its way. Tell FEC it's ready, interrupt when done, 379 /* Send it on its way. Tell FEC it's ready, interrupt when done,
372 * it's the last BD of the frame, and to put the CRC on the end. 380 * it's the last BD of the frame, and to put the CRC on the end.
373 */ 381 */
@@ -396,7 +404,7 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
396 404
397 fep->cur_tx = (cbd_t *)bdp; 405 fep->cur_tx = (cbd_t *)bdp;
398 406
399 spin_unlock_irq(&fep->lock); 407 spin_unlock_irqrestore(&fep->hw_lock, flags);
400 408
401 return 0; 409 return 0;
402} 410}
@@ -454,19 +462,20 @@ fec_enet_interrupt(int irq, void * dev_id)
454 struct net_device *dev = dev_id; 462 struct net_device *dev = dev_id;
455 volatile fec_t *fecp; 463 volatile fec_t *fecp;
456 uint int_events; 464 uint int_events;
457 int handled = 0; 465 irqreturn_t ret = IRQ_NONE;
458 466
459 fecp = (volatile fec_t*)dev->base_addr; 467 fecp = (volatile fec_t*)dev->base_addr;
460 468
461 /* Get the interrupt events that caused us to be here. 469 /* Get the interrupt events that caused us to be here.
462 */ 470 */
463 while ((int_events = fecp->fec_ievent) != 0) { 471 do {
472 int_events = fecp->fec_ievent;
464 fecp->fec_ievent = int_events; 473 fecp->fec_ievent = int_events;
465 474
466 /* Handle receive event in its own function. 475 /* Handle receive event in its own function.
467 */ 476 */
468 if (int_events & FEC_ENET_RXF) { 477 if (int_events & FEC_ENET_RXF) {
469 handled = 1; 478 ret = IRQ_HANDLED;
470 fec_enet_rx(dev); 479 fec_enet_rx(dev);
471 } 480 }
472 481
@@ -475,17 +484,18 @@ fec_enet_interrupt(int irq, void * dev_id)
475 them as part of the transmit process. 484 them as part of the transmit process.
476 */ 485 */
477 if (int_events & FEC_ENET_TXF) { 486 if (int_events & FEC_ENET_TXF) {
478 handled = 1; 487 ret = IRQ_HANDLED;
479 fec_enet_tx(dev); 488 fec_enet_tx(dev);
480 } 489 }
481 490
482 if (int_events & FEC_ENET_MII) { 491 if (int_events & FEC_ENET_MII) {
483 handled = 1; 492 ret = IRQ_HANDLED;
484 fec_enet_mii(dev); 493 fec_enet_mii(dev);
485 } 494 }
486 495
487 } 496 } while (int_events);
488 return IRQ_RETVAL(handled); 497
498 return ret;
489} 499}
490 500
491 501
@@ -498,7 +508,7 @@ fec_enet_tx(struct net_device *dev)
498 struct sk_buff *skb; 508 struct sk_buff *skb;
499 509
500 fep = netdev_priv(dev); 510 fep = netdev_priv(dev);
501 spin_lock(&fep->lock); 511 spin_lock_irq(&fep->hw_lock);
502 bdp = fep->dirty_tx; 512 bdp = fep->dirty_tx;
503 513
504 while (((status = bdp->cbd_sc) & BD_ENET_TX_READY) == 0) { 514 while (((status = bdp->cbd_sc) & BD_ENET_TX_READY) == 0) {
@@ -557,7 +567,7 @@ fec_enet_tx(struct net_device *dev)
557 } 567 }
558 } 568 }
559 fep->dirty_tx = (cbd_t *)bdp; 569 fep->dirty_tx = (cbd_t *)bdp;
560 spin_unlock(&fep->lock); 570 spin_unlock_irq(&fep->hw_lock);
561} 571}
562 572
563 573
@@ -584,6 +594,8 @@ fec_enet_rx(struct net_device *dev)
584 fep = netdev_priv(dev); 594 fep = netdev_priv(dev);
585 fecp = (volatile fec_t*)dev->base_addr; 595 fecp = (volatile fec_t*)dev->base_addr;
586 596
597 spin_lock_irq(&fep->hw_lock);
598
587 /* First, grab all of the stats for the incoming packet. 599 /* First, grab all of the stats for the incoming packet.
588 * These get messed up if we get called due to a busy condition. 600 * These get messed up if we get called due to a busy condition.
589 */ 601 */
@@ -689,6 +701,8 @@ while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) {
689 */ 701 */
690 fecp->fec_r_des_active = 0; 702 fecp->fec_r_des_active = 0;
691#endif 703#endif
704
705 spin_unlock_irq(&fep->hw_lock);
692} 706}
693 707
694 708
@@ -702,11 +716,11 @@ fec_enet_mii(struct net_device *dev)
702 uint mii_reg; 716 uint mii_reg;
703 717
704 fep = netdev_priv(dev); 718 fep = netdev_priv(dev);
719 spin_lock_irq(&fep->mii_lock);
720
705 ep = fep->hwp; 721 ep = fep->hwp;
706 mii_reg = ep->fec_mii_data; 722 mii_reg = ep->fec_mii_data;
707 723
708 spin_lock(&fep->lock);
709
710 if ((mip = mii_head) == NULL) { 724 if ((mip = mii_head) == NULL) {
711 printk("MII and no head!\n"); 725 printk("MII and no head!\n");
712 goto unlock; 726 goto unlock;
@@ -723,7 +737,7 @@ fec_enet_mii(struct net_device *dev)
723 ep->fec_mii_data = mip->mii_regval; 737 ep->fec_mii_data = mip->mii_regval;
724 738
725unlock: 739unlock:
726 spin_unlock(&fep->lock); 740 spin_unlock_irq(&fep->mii_lock);
727} 741}
728 742
729static int 743static int
@@ -737,12 +751,11 @@ mii_queue(struct net_device *dev, int regval, void (*func)(uint, struct net_devi
737 /* Add PHY address to register command. 751 /* Add PHY address to register command.
738 */ 752 */
739 fep = netdev_priv(dev); 753 fep = netdev_priv(dev);
740 regval |= fep->phy_addr << 23; 754 spin_lock_irqsave(&fep->mii_lock, flags);
741 755
756 regval |= fep->phy_addr << 23;
742 retval = 0; 757 retval = 0;
743 758
744 spin_lock_irqsave(&fep->lock,flags);
745
746 if ((mip = mii_free) != NULL) { 759 if ((mip = mii_free) != NULL) {
747 mii_free = mip->mii_next; 760 mii_free = mip->mii_next;
748 mip->mii_regval = regval; 761 mip->mii_regval = regval;
@@ -759,9 +772,8 @@ mii_queue(struct net_device *dev, int regval, void (*func)(uint, struct net_devi
759 retval = 1; 772 retval = 1;
760 } 773 }
761 774
762 spin_unlock_irqrestore(&fep->lock,flags); 775 spin_unlock_irqrestore(&fep->mii_lock, flags);
763 776 return retval;
764 return(retval);
765} 777}
766 778
767static void mii_do_cmd(struct net_device *dev, const phy_cmd_t *c) 779static void mii_do_cmd(struct net_device *dev, const phy_cmd_t *c)
@@ -1222,7 +1234,7 @@ static phy_info_t const * const phy_info[] = {
1222}; 1234};
1223 1235
1224/* ------------------------------------------------------------------------- */ 1236/* ------------------------------------------------------------------------- */
1225#if !defined(CONFIG_M532x) 1237#ifdef HAVE_mii_link_interrupt
1226#ifdef CONFIG_RPXCLASSIC 1238#ifdef CONFIG_RPXCLASSIC
1227static void 1239static void
1228mii_link_interrupt(void *dev_id); 1240mii_link_interrupt(void *dev_id);
@@ -1362,18 +1374,8 @@ static void __inline__ fec_request_intrs(struct net_device *dev)
1362 unsigned short irq; 1374 unsigned short irq;
1363 } *idp, id[] = { 1375 } *idp, id[] = {
1364 { "fec(TXF)", 23 }, 1376 { "fec(TXF)", 23 },
1365 { "fec(TXB)", 24 },
1366 { "fec(TXFIFO)", 25 },
1367 { "fec(TXCR)", 26 },
1368 { "fec(RXF)", 27 }, 1377 { "fec(RXF)", 27 },
1369 { "fec(RXB)", 28 },
1370 { "fec(MII)", 29 }, 1378 { "fec(MII)", 29 },
1371 { "fec(LC)", 30 },
1372 { "fec(HBERR)", 31 },
1373 { "fec(GRA)", 32 },
1374 { "fec(EBERR)", 33 },
1375 { "fec(BABT)", 34 },
1376 { "fec(BABR)", 35 },
1377 { NULL }, 1379 { NULL },
1378 }; 1380 };
1379 1381
@@ -1533,18 +1535,8 @@ static void __inline__ fec_request_intrs(struct net_device *dev)
1533 unsigned short irq; 1535 unsigned short irq;
1534 } *idp, id[] = { 1536 } *idp, id[] = {
1535 { "fec(TXF)", 23 }, 1537 { "fec(TXF)", 23 },
1536 { "fec(TXB)", 24 },
1537 { "fec(TXFIFO)", 25 },
1538 { "fec(TXCR)", 26 },
1539 { "fec(RXF)", 27 }, 1538 { "fec(RXF)", 27 },
1540 { "fec(RXB)", 28 },
1541 { "fec(MII)", 29 }, 1539 { "fec(MII)", 29 },
1542 { "fec(LC)", 30 },
1543 { "fec(HBERR)", 31 },
1544 { "fec(GRA)", 32 },
1545 { "fec(EBERR)", 33 },
1546 { "fec(BABT)", 34 },
1547 { "fec(BABR)", 35 },
1548 { NULL }, 1540 { NULL },
1549 }; 1541 };
1550 1542
@@ -1660,18 +1652,8 @@ static void __inline__ fec_request_intrs(struct net_device *dev)
1660 unsigned short irq; 1652 unsigned short irq;
1661 } *idp, id[] = { 1653 } *idp, id[] = {
1662 { "fec(TXF)", 36 }, 1654 { "fec(TXF)", 36 },
1663 { "fec(TXB)", 37 },
1664 { "fec(TXFIFO)", 38 },
1665 { "fec(TXCR)", 39 },
1666 { "fec(RXF)", 40 }, 1655 { "fec(RXF)", 40 },
1667 { "fec(RXB)", 41 },
1668 { "fec(MII)", 42 }, 1656 { "fec(MII)", 42 },
1669 { "fec(LC)", 43 },
1670 { "fec(HBERR)", 44 },
1671 { "fec(GRA)", 45 },
1672 { "fec(EBERR)", 46 },
1673 { "fec(BABT)", 47 },
1674 { "fec(BABR)", 48 },
1675 { NULL }, 1657 { NULL },
1676 }; 1658 };
1677 1659
@@ -2126,6 +2108,7 @@ mii_discover_phy(uint mii_reg, struct net_device *dev)
2126 2108
2127/* This interrupt occurs when the PHY detects a link change. 2109/* This interrupt occurs when the PHY detects a link change.
2128*/ 2110*/
2111#ifdef HAVE_mii_link_interrupt
2129#ifdef CONFIG_RPXCLASSIC 2112#ifdef CONFIG_RPXCLASSIC
2130static void 2113static void
2131mii_link_interrupt(void *dev_id) 2114mii_link_interrupt(void *dev_id)
@@ -2148,6 +2131,7 @@ mii_link_interrupt(int irq, void * dev_id)
2148 2131
2149 return IRQ_HANDLED; 2132 return IRQ_HANDLED;
2150} 2133}
2134#endif
2151 2135
2152static int 2136static int
2153fec_enet_open(struct net_device *dev) 2137fec_enet_open(struct net_device *dev)
@@ -2243,13 +2227,13 @@ static void set_multicast_list(struct net_device *dev)
2243 /* Catch all multicast addresses, so set the 2227 /* Catch all multicast addresses, so set the
2244 * filter to all 1's. 2228 * filter to all 1's.
2245 */ 2229 */
2246 ep->fec_hash_table_high = 0xffffffff; 2230 ep->fec_grp_hash_table_high = 0xffffffff;
2247 ep->fec_hash_table_low = 0xffffffff; 2231 ep->fec_grp_hash_table_low = 0xffffffff;
2248 } else { 2232 } else {
2249 /* Clear filter and add the addresses in hash register. 2233 /* Clear filter and add the addresses in hash register.
2250 */ 2234 */
2251 ep->fec_hash_table_high = 0; 2235 ep->fec_grp_hash_table_high = 0;
2252 ep->fec_hash_table_low = 0; 2236 ep->fec_grp_hash_table_low = 0;
2253 2237
2254 dmi = dev->mc_list; 2238 dmi = dev->mc_list;
2255 2239
@@ -2280,9 +2264,9 @@ static void set_multicast_list(struct net_device *dev)
2280 hash = (crc >> (32 - HASH_BITS)) & 0x3f; 2264 hash = (crc >> (32 - HASH_BITS)) & 0x3f;
2281 2265
2282 if (hash > 31) 2266 if (hash > 31)
2283 ep->fec_hash_table_high |= 1 << (hash - 32); 2267 ep->fec_grp_hash_table_high |= 1 << (hash - 32);
2284 else 2268 else
2285 ep->fec_hash_table_low |= 1 << hash; 2269 ep->fec_grp_hash_table_low |= 1 << hash;
2286 } 2270 }
2287 } 2271 }
2288 } 2272 }
@@ -2332,6 +2316,9 @@ int __init fec_enet_init(struct net_device *dev)
2332 return -ENOMEM; 2316 return -ENOMEM;
2333 } 2317 }
2334 2318
2319 spin_lock_init(&fep->hw_lock);
2320 spin_lock_init(&fep->mii_lock);
2321
2335 /* Create an Ethernet device instance. 2322 /* Create an Ethernet device instance.
2336 */ 2323 */
2337 fecp = (volatile fec_t *) fec_hw[index]; 2324 fecp = (volatile fec_t *) fec_hw[index];
@@ -2430,11 +2417,15 @@ int __init fec_enet_init(struct net_device *dev)
2430 */ 2417 */
2431 fec_request_intrs(dev); 2418 fec_request_intrs(dev);
2432 2419
2433 fecp->fec_hash_table_high = 0; 2420 fecp->fec_grp_hash_table_high = 0;
2434 fecp->fec_hash_table_low = 0; 2421 fecp->fec_grp_hash_table_low = 0;
2435 fecp->fec_r_buff_size = PKT_MAXBLR_SIZE; 2422 fecp->fec_r_buff_size = PKT_MAXBLR_SIZE;
2436 fecp->fec_ecntrl = 2; 2423 fecp->fec_ecntrl = 2;
2437 fecp->fec_r_des_active = 0; 2424 fecp->fec_r_des_active = 0;
2425#ifndef CONFIG_M5272
2426 fecp->fec_hash_table_high = 0;
2427 fecp->fec_hash_table_low = 0;
2428#endif
2438 2429
2439 dev->base_addr = (unsigned long)fecp; 2430 dev->base_addr = (unsigned long)fecp;
2440 2431
@@ -2455,8 +2446,7 @@ int __init fec_enet_init(struct net_device *dev)
2455 2446
2456 /* Clear and enable interrupts */ 2447 /* Clear and enable interrupts */
2457 fecp->fec_ievent = 0xffc00000; 2448 fecp->fec_ievent = 0xffc00000;
2458 fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_TXB | 2449 fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_MII);
2459 FEC_ENET_RXF | FEC_ENET_RXB | FEC_ENET_MII);
2460 2450
2461 /* Queue up command to detect the PHY and initialize the 2451 /* Queue up command to detect the PHY and initialize the
2462 * remainder of the interface. 2452 * remainder of the interface.
@@ -2500,8 +2490,8 @@ fec_restart(struct net_device *dev, int duplex)
2500 2490
2501 /* Reset all multicast. 2491 /* Reset all multicast.
2502 */ 2492 */
2503 fecp->fec_hash_table_high = 0; 2493 fecp->fec_grp_hash_table_high = 0;
2504 fecp->fec_hash_table_low = 0; 2494 fecp->fec_grp_hash_table_low = 0;
2505 2495
2506 /* Set maximum receive buffer size. 2496 /* Set maximum receive buffer size.
2507 */ 2497 */
@@ -2583,8 +2573,7 @@ fec_restart(struct net_device *dev, int duplex)
2583 2573
2584 /* Enable interrupts we wish to service. 2574 /* Enable interrupts we wish to service.
2585 */ 2575 */
2586 fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_TXB | 2576 fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_MII);
2587 FEC_ENET_RXF | FEC_ENET_RXB | FEC_ENET_MII);
2588} 2577}
2589 2578
2590static void 2579static void
@@ -2624,7 +2613,7 @@ fec_stop(struct net_device *dev)
2624static int __init fec_enet_module_init(void) 2613static int __init fec_enet_module_init(void)
2625{ 2614{
2626 struct net_device *dev; 2615 struct net_device *dev;
2627 int i, j, err; 2616 int i, err;
2628 DECLARE_MAC_BUF(mac); 2617 DECLARE_MAC_BUF(mac);
2629 2618
2630 printk("FEC ENET Version 0.2\n"); 2619 printk("FEC ENET Version 0.2\n");