aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/pcnet32.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/pcnet32.c')
-rw-r--r--drivers/net/pcnet32.c545
1 files changed, 399 insertions, 146 deletions
diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
index d768f3d1ac28..d50bcb89dd28 100644
--- a/drivers/net/pcnet32.c
+++ b/drivers/net/pcnet32.c
@@ -58,18 +58,15 @@ static const char *const version =
58 * PCI device identifiers for "new style" Linux PCI Device Drivers 58 * PCI device identifiers for "new style" Linux PCI Device Drivers
59 */ 59 */
60static struct pci_device_id pcnet32_pci_tbl[] = { 60static struct pci_device_id pcnet32_pci_tbl[] = {
61 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE_HOME, 61 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE_HOME), },
62 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 62 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE), },
63 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE,
64 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
65 63
66 /* 64 /*
67 * Adapters that were sold with IBM's RS/6000 or pSeries hardware have 65 * Adapters that were sold with IBM's RS/6000 or pSeries hardware have
68 * the incorrect vendor id. 66 * the incorrect vendor id.
69 */ 67 */
70 { PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_AMD_LANCE, 68 { PCI_DEVICE(PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_AMD_LANCE),
71 PCI_ANY_ID, PCI_ANY_ID, 69 .class = (PCI_CLASS_NETWORK_ETHERNET << 8), .class_mask = 0xffff00, },
72 PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, 0},
73 70
74 { } /* terminate list */ 71 { } /* terminate list */
75}; 72};
@@ -188,6 +185,25 @@ static int homepna[MAX_UNITS];
188 185
189#define PCNET32_TOTAL_SIZE 0x20 186#define PCNET32_TOTAL_SIZE 0x20
190 187
188#define CSR0 0
189#define CSR0_INIT 0x1
190#define CSR0_START 0x2
191#define CSR0_STOP 0x4
192#define CSR0_TXPOLL 0x8
193#define CSR0_INTEN 0x40
194#define CSR0_IDON 0x0100
195#define CSR0_NORMAL (CSR0_START | CSR0_INTEN)
196#define PCNET32_INIT_LOW 1
197#define PCNET32_INIT_HIGH 2
198#define CSR3 3
199#define CSR4 4
200#define CSR5 5
201#define CSR5_SUSPEND 0x0001
202#define CSR15 15
203#define PCNET32_MC_FILTER 8
204
205#define PCNET32_79C970A 0x2621
206
191/* The PCNET32 Rx and Tx ring descriptors. */ 207/* The PCNET32 Rx and Tx ring descriptors. */
192struct pcnet32_rx_head { 208struct pcnet32_rx_head {
193 u32 base; 209 u32 base;
@@ -275,9 +291,9 @@ struct pcnet32_private {
275 291
276 /* each bit indicates an available PHY */ 292 /* each bit indicates an available PHY */
277 u32 phymask; 293 u32 phymask;
294 unsigned short chip_version; /* which variant this is */
278}; 295};
279 296
280static void pcnet32_probe_vlbus(void);
281static int pcnet32_probe_pci(struct pci_dev *, const struct pci_device_id *); 297static int pcnet32_probe_pci(struct pci_dev *, const struct pci_device_id *);
282static int pcnet32_probe1(unsigned long, int, struct pci_dev *); 298static int pcnet32_probe1(unsigned long, int, struct pci_dev *);
283static int pcnet32_open(struct net_device *); 299static int pcnet32_open(struct net_device *);
@@ -419,6 +435,238 @@ static struct pcnet32_access pcnet32_dwio = {
419 .reset = pcnet32_dwio_reset 435 .reset = pcnet32_dwio_reset
420}; 436};
421 437
438static void pcnet32_netif_stop(struct net_device *dev)
439{
440 dev->trans_start = jiffies;
441 netif_poll_disable(dev);
442 netif_tx_disable(dev);
443}
444
445static void pcnet32_netif_start(struct net_device *dev)
446{
447 netif_wake_queue(dev);
448 netif_poll_enable(dev);
449}
450
451/*
452 * Allocate space for the new sized tx ring.
453 * Free old resources
454 * Save new resources.
455 * Any failure keeps old resources.
456 * Must be called with lp->lock held.
457 */
458static void pcnet32_realloc_tx_ring(struct net_device *dev,
459 struct pcnet32_private *lp,
460 unsigned int size)
461{
462 dma_addr_t new_ring_dma_addr;
463 dma_addr_t *new_dma_addr_list;
464 struct pcnet32_tx_head *new_tx_ring;
465 struct sk_buff **new_skb_list;
466
467 pcnet32_purge_tx_ring(dev);
468
469 new_tx_ring = pci_alloc_consistent(lp->pci_dev,
470 sizeof(struct pcnet32_tx_head) *
471 (1 << size),
472 &new_ring_dma_addr);
473 if (new_tx_ring == NULL) {
474 if (netif_msg_drv(lp))
475 printk("\n" KERN_ERR
476 "%s: Consistent memory allocation failed.\n",
477 dev->name);
478 return;
479 }
480 memset(new_tx_ring, 0, sizeof(struct pcnet32_tx_head) * (1 << size));
481
482 new_dma_addr_list = kcalloc((1 << size), sizeof(dma_addr_t),
483 GFP_ATOMIC);
484 if (!new_dma_addr_list) {
485 if (netif_msg_drv(lp))
486 printk("\n" KERN_ERR
487 "%s: Memory allocation failed.\n", dev->name);
488 goto free_new_tx_ring;
489 }
490
491 new_skb_list = kcalloc((1 << size), sizeof(struct sk_buff *),
492 GFP_ATOMIC);
493 if (!new_skb_list) {
494 if (netif_msg_drv(lp))
495 printk("\n" KERN_ERR
496 "%s: Memory allocation failed.\n", dev->name);
497 goto free_new_lists;
498 }
499
500 kfree(lp->tx_skbuff);
501 kfree(lp->tx_dma_addr);
502 pci_free_consistent(lp->pci_dev,
503 sizeof(struct pcnet32_tx_head) *
504 lp->tx_ring_size, lp->tx_ring,
505 lp->tx_ring_dma_addr);
506
507 lp->tx_ring_size = (1 << size);
508 lp->tx_mod_mask = lp->tx_ring_size - 1;
509 lp->tx_len_bits = (size << 12);
510 lp->tx_ring = new_tx_ring;
511 lp->tx_ring_dma_addr = new_ring_dma_addr;
512 lp->tx_dma_addr = new_dma_addr_list;
513 lp->tx_skbuff = new_skb_list;
514 return;
515
516 free_new_lists:
517 kfree(new_dma_addr_list);
518 free_new_tx_ring:
519 pci_free_consistent(lp->pci_dev,
520 sizeof(struct pcnet32_tx_head) *
521 (1 << size),
522 new_tx_ring,
523 new_ring_dma_addr);
524 return;
525}
526
527/*
528 * Allocate space for the new sized rx ring.
529 * Re-use old receive buffers.
530 * alloc extra buffers
531 * free unneeded buffers
532 * free unneeded buffers
533 * Save new resources.
534 * Any failure keeps old resources.
535 * Must be called with lp->lock held.
536 */
537static void pcnet32_realloc_rx_ring(struct net_device *dev,
538 struct pcnet32_private *lp,
539 unsigned int size)
540{
541 dma_addr_t new_ring_dma_addr;
542 dma_addr_t *new_dma_addr_list;
543 struct pcnet32_rx_head *new_rx_ring;
544 struct sk_buff **new_skb_list;
545 int new, overlap;
546
547 new_rx_ring = pci_alloc_consistent(lp->pci_dev,
548 sizeof(struct pcnet32_rx_head) *
549 (1 << size),
550 &new_ring_dma_addr);
551 if (new_rx_ring == NULL) {
552 if (netif_msg_drv(lp))
553 printk("\n" KERN_ERR
554 "%s: Consistent memory allocation failed.\n",
555 dev->name);
556 return;
557 }
558 memset(new_rx_ring, 0, sizeof(struct pcnet32_rx_head) * (1 << size));
559
560 new_dma_addr_list = kcalloc((1 << size), sizeof(dma_addr_t),
561 GFP_ATOMIC);
562 if (!new_dma_addr_list) {
563 if (netif_msg_drv(lp))
564 printk("\n" KERN_ERR
565 "%s: Memory allocation failed.\n", dev->name);
566 goto free_new_rx_ring;
567 }
568
569 new_skb_list = kcalloc((1 << size), sizeof(struct sk_buff *),
570 GFP_ATOMIC);
571 if (!new_skb_list) {
572 if (netif_msg_drv(lp))
573 printk("\n" KERN_ERR
574 "%s: Memory allocation failed.\n", dev->name);
575 goto free_new_lists;
576 }
577
578 /* first copy the current receive buffers */
579 overlap = min(size, lp->rx_ring_size);
580 for (new = 0; new < overlap; new++) {
581 new_rx_ring[new] = lp->rx_ring[new];
582 new_dma_addr_list[new] = lp->rx_dma_addr[new];
583 new_skb_list[new] = lp->rx_skbuff[new];
584 }
585 /* now allocate any new buffers needed */
586 for (; new < size; new++ ) {
587 struct sk_buff *rx_skbuff;
588 new_skb_list[new] = dev_alloc_skb(PKT_BUF_SZ);
589 if (!(rx_skbuff = new_skb_list[new])) {
590 /* keep the original lists and buffers */
591 if (netif_msg_drv(lp))
592 printk(KERN_ERR
593 "%s: pcnet32_realloc_rx_ring dev_alloc_skb failed.\n",
594 dev->name);
595 goto free_all_new;
596 }
597 skb_reserve(rx_skbuff, 2);
598
599 new_dma_addr_list[new] =
600 pci_map_single(lp->pci_dev, rx_skbuff->data,
601 PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
602 new_rx_ring[new].base = (u32) le32_to_cpu(new_dma_addr_list[new]);
603 new_rx_ring[new].buf_length = le16_to_cpu(2 - PKT_BUF_SZ);
604 new_rx_ring[new].status = le16_to_cpu(0x8000);
605 }
606 /* and free any unneeded buffers */
607 for (; new < lp->rx_ring_size; new++) {
608 if (lp->rx_skbuff[new]) {
609 pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[new],
610 PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
611 dev_kfree_skb(lp->rx_skbuff[new]);
612 }
613 }
614
615 kfree(lp->rx_skbuff);
616 kfree(lp->rx_dma_addr);
617 pci_free_consistent(lp->pci_dev,
618 sizeof(struct pcnet32_rx_head) *
619 lp->rx_ring_size, lp->rx_ring,
620 lp->rx_ring_dma_addr);
621
622 lp->rx_ring_size = (1 << size);
623 lp->rx_mod_mask = lp->rx_ring_size - 1;
624 lp->rx_len_bits = (size << 4);
625 lp->rx_ring = new_rx_ring;
626 lp->rx_ring_dma_addr = new_ring_dma_addr;
627 lp->rx_dma_addr = new_dma_addr_list;
628 lp->rx_skbuff = new_skb_list;
629 return;
630
631 free_all_new:
632 for (; --new >= lp->rx_ring_size; ) {
633 if (new_skb_list[new]) {
634 pci_unmap_single(lp->pci_dev, new_dma_addr_list[new],
635 PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
636 dev_kfree_skb(new_skb_list[new]);
637 }
638 }
639 kfree(new_skb_list);
640 free_new_lists:
641 kfree(new_dma_addr_list);
642 free_new_rx_ring:
643 pci_free_consistent(lp->pci_dev,
644 sizeof(struct pcnet32_rx_head) *
645 (1 << size),
646 new_rx_ring,
647 new_ring_dma_addr);
648 return;
649}
650
651static void pcnet32_purge_rx_ring(struct net_device *dev)
652{
653 struct pcnet32_private *lp = dev->priv;
654 int i;
655
656 /* free all allocated skbuffs */
657 for (i = 0; i < lp->rx_ring_size; i++) {
658 lp->rx_ring[i].status = 0; /* CPU owns buffer */
659 wmb(); /* Make sure adapter sees owner change */
660 if (lp->rx_skbuff[i]) {
661 pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[i],
662 PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
663 dev_kfree_skb_any(lp->rx_skbuff[i]);
664 }
665 lp->rx_skbuff[i] = NULL;
666 lp->rx_dma_addr[i] = 0;
667 }
668}
669
422#ifdef CONFIG_NET_POLL_CONTROLLER 670#ifdef CONFIG_NET_POLL_CONTROLLER
423static void pcnet32_poll_controller(struct net_device *dev) 671static void pcnet32_poll_controller(struct net_device *dev)
424{ 672{
@@ -479,9 +727,11 @@ static u32 pcnet32_get_link(struct net_device *dev)
479 spin_lock_irqsave(&lp->lock, flags); 727 spin_lock_irqsave(&lp->lock, flags);
480 if (lp->mii) { 728 if (lp->mii) {
481 r = mii_link_ok(&lp->mii_if); 729 r = mii_link_ok(&lp->mii_if);
482 } else { 730 } else if (lp->chip_version >= PCNET32_79C970A) {
483 ulong ioaddr = dev->base_addr; /* card base I/O address */ 731 ulong ioaddr = dev->base_addr; /* card base I/O address */
484 r = (lp->a.read_bcr(ioaddr, 4) != 0xc0); 732 r = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
733 } else { /* can not detect link on really old chips */
734 r = 1;
485 } 735 }
486 spin_unlock_irqrestore(&lp->lock, flags); 736 spin_unlock_irqrestore(&lp->lock, flags);
487 737
@@ -519,10 +769,10 @@ static void pcnet32_get_ringparam(struct net_device *dev,
519{ 769{
520 struct pcnet32_private *lp = dev->priv; 770 struct pcnet32_private *lp = dev->priv;
521 771
522 ering->tx_max_pending = TX_MAX_RING_SIZE - 1; 772 ering->tx_max_pending = TX_MAX_RING_SIZE;
523 ering->tx_pending = lp->tx_ring_size - 1; 773 ering->tx_pending = lp->tx_ring_size;
524 ering->rx_max_pending = RX_MAX_RING_SIZE - 1; 774 ering->rx_max_pending = RX_MAX_RING_SIZE;
525 ering->rx_pending = lp->rx_ring_size - 1; 775 ering->rx_pending = lp->rx_ring_size;
526} 776}
527 777
528static int pcnet32_set_ringparam(struct net_device *dev, 778static int pcnet32_set_ringparam(struct net_device *dev,
@@ -530,56 +780,53 @@ static int pcnet32_set_ringparam(struct net_device *dev,
530{ 780{
531 struct pcnet32_private *lp = dev->priv; 781 struct pcnet32_private *lp = dev->priv;
532 unsigned long flags; 782 unsigned long flags;
783 unsigned int size;
784 ulong ioaddr = dev->base_addr;
533 int i; 785 int i;
534 786
535 if (ering->rx_mini_pending || ering->rx_jumbo_pending) 787 if (ering->rx_mini_pending || ering->rx_jumbo_pending)
536 return -EINVAL; 788 return -EINVAL;
537 789
538 if (netif_running(dev)) 790 if (netif_running(dev))
539 pcnet32_close(dev); 791 pcnet32_netif_stop(dev);
540 792
541 spin_lock_irqsave(&lp->lock, flags); 793 spin_lock_irqsave(&lp->lock, flags);
542 pcnet32_free_ring(dev); 794 lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
543 lp->tx_ring_size = 795
544 min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE); 796 size = min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE);
545 lp->rx_ring_size =
546 min(ering->rx_pending, (unsigned int)RX_MAX_RING_SIZE);
547 797
548 /* set the minimum ring size to 4, to allow the loopback test to work 798 /* set the minimum ring size to 4, to allow the loopback test to work
549 * unchanged. 799 * unchanged.
550 */ 800 */
551 for (i = 2; i <= PCNET32_LOG_MAX_TX_BUFFERS; i++) { 801 for (i = 2; i <= PCNET32_LOG_MAX_TX_BUFFERS; i++) {
552 if (lp->tx_ring_size <= (1 << i)) 802 if (size <= (1 << i))
553 break; 803 break;
554 } 804 }
555 lp->tx_ring_size = (1 << i); 805 if ((1 << i) != lp->tx_ring_size)
556 lp->tx_mod_mask = lp->tx_ring_size - 1; 806 pcnet32_realloc_tx_ring(dev, lp, i);
557 lp->tx_len_bits = (i << 12); 807
558 808 size = min(ering->rx_pending, (unsigned int)RX_MAX_RING_SIZE);
559 for (i = 2; i <= PCNET32_LOG_MAX_RX_BUFFERS; i++) { 809 for (i = 2; i <= PCNET32_LOG_MAX_RX_BUFFERS; i++) {
560 if (lp->rx_ring_size <= (1 << i)) 810 if (size <= (1 << i))
561 break; 811 break;
562 } 812 }
563 lp->rx_ring_size = (1 << i); 813 if ((1 << i) != lp->rx_ring_size)
564 lp->rx_mod_mask = lp->rx_ring_size - 1; 814 pcnet32_realloc_rx_ring(dev, lp, i);
565 lp->rx_len_bits = (i << 4); 815
816 dev->weight = lp->rx_ring_size / 2;
566 817
567 if (pcnet32_alloc_ring(dev, dev->name)) { 818 if (netif_running(dev)) {
568 pcnet32_free_ring(dev); 819 pcnet32_netif_start(dev);
569 spin_unlock_irqrestore(&lp->lock, flags); 820 pcnet32_restart(dev, CSR0_NORMAL);
570 return -ENOMEM;
571 } 821 }
572 822
573 spin_unlock_irqrestore(&lp->lock, flags); 823 spin_unlock_irqrestore(&lp->lock, flags);
574 824
575 if (pcnet32_debug & NETIF_MSG_DRV) 825 if (netif_msg_drv(lp))
576 printk(KERN_INFO PFX 826 printk(KERN_INFO
577 "%s: Ring Param Settings: RX: %d, TX: %d\n", dev->name, 827 "%s: Ring Param Settings: RX: %d, TX: %d\n", dev->name,
578 lp->rx_ring_size, lp->tx_ring_size); 828 lp->rx_ring_size, lp->tx_ring_size);
579 829
580 if (netif_running(dev))
581 pcnet32_open(dev);
582
583 return 0; 830 return 0;
584} 831}
585 832
@@ -633,29 +880,27 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
633 unsigned long flags; 880 unsigned long flags;
634 unsigned long ticks; 881 unsigned long ticks;
635 882
636 *data1 = 1; /* status of test, default to fail */
637 rc = 1; /* default to fail */ 883 rc = 1; /* default to fail */
638 884
639 if (netif_running(dev)) 885 if (netif_running(dev))
640 pcnet32_close(dev); 886 pcnet32_close(dev);
641 887
642 spin_lock_irqsave(&lp->lock, flags); 888 spin_lock_irqsave(&lp->lock, flags);
889 lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
890
891 numbuffs = min(numbuffs, (int)min(lp->rx_ring_size, lp->tx_ring_size));
643 892
644 /* Reset the PCNET32 */ 893 /* Reset the PCNET32 */
645 lp->a.reset(ioaddr); 894 lp->a.reset(ioaddr);
895 lp->a.write_csr(ioaddr, CSR4, 0x0915);
646 896
647 /* switch pcnet32 to 32bit mode */ 897 /* switch pcnet32 to 32bit mode */
648 lp->a.write_bcr(ioaddr, 20, 2); 898 lp->a.write_bcr(ioaddr, 20, 2);
649 899
650 lp->init_block.mode =
651 le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7);
652 lp->init_block.filter[0] = 0;
653 lp->init_block.filter[1] = 0;
654
655 /* purge & init rings but don't actually restart */ 900 /* purge & init rings but don't actually restart */
656 pcnet32_restart(dev, 0x0000); 901 pcnet32_restart(dev, 0x0000);
657 902
658 lp->a.write_csr(ioaddr, 0, 0x0004); /* Set STOP bit */ 903 lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
659 904
660 /* Initialize Transmit buffers. */ 905 /* Initialize Transmit buffers. */
661 size = data_len + 15; 906 size = data_len + 15;
@@ -697,14 +942,15 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
697 } 942 }
698 } 943 }
699 944
700 x = a->read_bcr(ioaddr, 32); /* set internal loopback in BSR32 */ 945 x = a->read_bcr(ioaddr, 32); /* set internal loopback in BCR32 */
701 x = x | 0x0002; 946 a->write_bcr(ioaddr, 32, x | 0x0002);
702 a->write_bcr(ioaddr, 32, x);
703 947
704 lp->a.write_csr(ioaddr, 15, 0x0044); /* set int loopback in CSR15 */ 948 /* set int loopback in CSR15 */
949 x = a->read_csr(ioaddr, CSR15) & 0xfffc;
950 lp->a.write_csr(ioaddr, CSR15, x | 0x0044);
705 951
706 teststatus = le16_to_cpu(0x8000); 952 teststatus = le16_to_cpu(0x8000);
707 lp->a.write_csr(ioaddr, 0, 0x0002); /* Set STRT bit */ 953 lp->a.write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
708 954
709 /* Check status of descriptors */ 955 /* Check status of descriptors */
710 for (x = 0; x < numbuffs; x++) { 956 for (x = 0; x < numbuffs; x++) {
@@ -712,7 +958,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
712 rmb(); 958 rmb();
713 while ((lp->rx_ring[x].status & teststatus) && (ticks < 200)) { 959 while ((lp->rx_ring[x].status & teststatus) && (ticks < 200)) {
714 spin_unlock_irqrestore(&lp->lock, flags); 960 spin_unlock_irqrestore(&lp->lock, flags);
715 mdelay(1); 961 msleep(1);
716 spin_lock_irqsave(&lp->lock, flags); 962 spin_lock_irqsave(&lp->lock, flags);
717 rmb(); 963 rmb();
718 ticks++; 964 ticks++;
@@ -725,7 +971,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
725 } 971 }
726 } 972 }
727 973
728 lp->a.write_csr(ioaddr, 0, 0x0004); /* Set STOP bit */ 974 lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
729 wmb(); 975 wmb();
730 if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) { 976 if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) {
731 printk(KERN_DEBUG "%s: RX loopback packets:\n", dev->name); 977 printk(KERN_DEBUG "%s: RX loopback packets:\n", dev->name);
@@ -758,25 +1004,24 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
758 } 1004 }
759 x++; 1005 x++;
760 } 1006 }
761 if (!rc) {
762 *data1 = 0;
763 }
764 1007
765 clean_up: 1008 clean_up:
1009 *data1 = rc;
766 pcnet32_purge_tx_ring(dev); 1010 pcnet32_purge_tx_ring(dev);
767 x = a->read_csr(ioaddr, 15) & 0xFFFF;
768 a->write_csr(ioaddr, 15, (x & ~0x0044)); /* reset bits 6 and 2 */
769 1011
770 x = a->read_bcr(ioaddr, 32); /* reset internal loopback */ 1012 x = a->read_csr(ioaddr, CSR15);
771 x = x & ~0x0002; 1013 a->write_csr(ioaddr, CSR15, (x & ~0x0044)); /* reset bits 6 and 2 */
772 a->write_bcr(ioaddr, 32, x);
773 1014
774 spin_unlock_irqrestore(&lp->lock, flags); 1015 x = a->read_bcr(ioaddr, 32); /* reset internal loopback */
1016 a->write_bcr(ioaddr, 32, (x & ~0x0002));
775 1017
776 if (netif_running(dev)) { 1018 if (netif_running(dev)) {
1019 spin_unlock_irqrestore(&lp->lock, flags);
777 pcnet32_open(dev); 1020 pcnet32_open(dev);
778 } else { 1021 } else {
1022 pcnet32_purge_rx_ring(dev);
779 lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */ 1023 lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
1024 spin_unlock_irqrestore(&lp->lock, flags);
780 } 1025 }
781 1026
782 return (rc); 1027 return (rc);
@@ -839,6 +1084,47 @@ static int pcnet32_phys_id(struct net_device *dev, u32 data)
839 return 0; 1084 return 0;
840} 1085}
841 1086
1087/*
1088 * lp->lock must be held.
1089 */
1090static int pcnet32_suspend(struct net_device *dev, unsigned long *flags,
1091 int can_sleep)
1092{
1093 int csr5;
1094 struct pcnet32_private *lp = dev->priv;
1095 struct pcnet32_access *a = &lp->a;
1096 ulong ioaddr = dev->base_addr;
1097 int ticks;
1098
1099 /* really old chips have to be stopped. */
1100 if (lp->chip_version < PCNET32_79C970A)
1101 return 0;
1102
1103 /* set SUSPEND (SPND) - CSR5 bit 0 */
1104 csr5 = a->read_csr(ioaddr, CSR5);
1105 a->write_csr(ioaddr, CSR5, csr5 | CSR5_SUSPEND);
1106
1107 /* poll waiting for bit to be set */
1108 ticks = 0;
1109 while (!(a->read_csr(ioaddr, CSR5) & CSR5_SUSPEND)) {
1110 spin_unlock_irqrestore(&lp->lock, *flags);
1111 if (can_sleep)
1112 msleep(1);
1113 else
1114 mdelay(1);
1115 spin_lock_irqsave(&lp->lock, *flags);
1116 ticks++;
1117 if (ticks > 200) {
1118 if (netif_msg_hw(lp))
1119 printk(KERN_DEBUG
1120 "%s: Error getting into suspend!\n",
1121 dev->name);
1122 return 0;
1123 }
1124 }
1125 return 1;
1126}
1127
842#define PCNET32_REGS_PER_PHY 32 1128#define PCNET32_REGS_PER_PHY 32
843#define PCNET32_MAX_PHYS 32 1129#define PCNET32_MAX_PHYS 32
844static int pcnet32_get_regs_len(struct net_device *dev) 1130static int pcnet32_get_regs_len(struct net_device *dev)
@@ -857,32 +1143,13 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
857 struct pcnet32_private *lp = dev->priv; 1143 struct pcnet32_private *lp = dev->priv;
858 struct pcnet32_access *a = &lp->a; 1144 struct pcnet32_access *a = &lp->a;
859 ulong ioaddr = dev->base_addr; 1145 ulong ioaddr = dev->base_addr;
860 int ticks;
861 unsigned long flags; 1146 unsigned long flags;
862 1147
863 spin_lock_irqsave(&lp->lock, flags); 1148 spin_lock_irqsave(&lp->lock, flags);
864 1149
865 csr0 = a->read_csr(ioaddr, 0); 1150 csr0 = a->read_csr(ioaddr, CSR0);
866 if (!(csr0 & 0x0004)) { /* If not stopped */ 1151 if (!(csr0 & CSR0_STOP)) /* If not stopped */
867 /* set SUSPEND (SPND) - CSR5 bit 0 */ 1152 pcnet32_suspend(dev, &flags, 1);
868 a->write_csr(ioaddr, 5, 0x0001);
869
870 /* poll waiting for bit to be set */
871 ticks = 0;
872 while (!(a->read_csr(ioaddr, 5) & 0x0001)) {
873 spin_unlock_irqrestore(&lp->lock, flags);
874 mdelay(1);
875 spin_lock_irqsave(&lp->lock, flags);
876 ticks++;
877 if (ticks > 200) {
878 if (netif_msg_hw(lp))
879 printk(KERN_DEBUG
880 "%s: Error getting into suspend!\n",
881 dev->name);
882 break;
883 }
884 }
885 }
886 1153
887 /* read address PROM */ 1154 /* read address PROM */
888 for (i = 0; i < 16; i += 2) 1155 for (i = 0; i < 16; i += 2)
@@ -919,9 +1186,12 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
919 } 1186 }
920 } 1187 }
921 1188
922 if (!(csr0 & 0x0004)) { /* If not stopped */ 1189 if (!(csr0 & CSR0_STOP)) { /* If not stopped */
1190 int csr5;
1191
923 /* clear SUSPEND (SPND) - CSR5 bit 0 */ 1192 /* clear SUSPEND (SPND) - CSR5 bit 0 */
924 a->write_csr(ioaddr, 5, 0x0000); 1193 csr5 = a->read_csr(ioaddr, CSR5);
1194 a->write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
925 } 1195 }
926 1196
927 spin_unlock_irqrestore(&lp->lock, flags); 1197 spin_unlock_irqrestore(&lp->lock, flags);
@@ -952,7 +1222,7 @@ static struct ethtool_ops pcnet32_ethtool_ops = {
952/* only probes for non-PCI devices, the rest are handled by 1222/* only probes for non-PCI devices, the rest are handled by
953 * pci_register_driver via pcnet32_probe_pci */ 1223 * pci_register_driver via pcnet32_probe_pci */
954 1224
955static void __devinit pcnet32_probe_vlbus(void) 1225static void __devinit pcnet32_probe_vlbus(unsigned int *pcnet32_portlist)
956{ 1226{
957 unsigned int *port, ioaddr; 1227 unsigned int *port, ioaddr;
958 1228
@@ -1268,6 +1538,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
1268 lp->mii_if.reg_num_mask = 0x1f; 1538 lp->mii_if.reg_num_mask = 0x1f;
1269 lp->dxsuflo = dxsuflo; 1539 lp->dxsuflo = dxsuflo;
1270 lp->mii = mii; 1540 lp->mii = mii;
1541 lp->chip_version = chip_version;
1271 lp->msg_enable = pcnet32_debug; 1542 lp->msg_enable = pcnet32_debug;
1272 if ((cards_found >= MAX_UNITS) 1543 if ((cards_found >= MAX_UNITS)
1273 || (options[cards_found] > sizeof(options_mapping))) 1544 || (options[cards_found] > sizeof(options_mapping)))
@@ -1436,7 +1707,7 @@ static int pcnet32_alloc_ring(struct net_device *dev, char *name)
1436 lp->tx_ring_size, 1707 lp->tx_ring_size,
1437 &lp->tx_ring_dma_addr); 1708 &lp->tx_ring_dma_addr);
1438 if (lp->tx_ring == NULL) { 1709 if (lp->tx_ring == NULL) {
1439 if (pcnet32_debug & NETIF_MSG_DRV) 1710 if (netif_msg_drv(lp))
1440 printk("\n" KERN_ERR PFX 1711 printk("\n" KERN_ERR PFX
1441 "%s: Consistent memory allocation failed.\n", 1712 "%s: Consistent memory allocation failed.\n",
1442 name); 1713 name);
@@ -1448,52 +1719,48 @@ static int pcnet32_alloc_ring(struct net_device *dev, char *name)
1448 lp->rx_ring_size, 1719 lp->rx_ring_size,
1449 &lp->rx_ring_dma_addr); 1720 &lp->rx_ring_dma_addr);
1450 if (lp->rx_ring == NULL) { 1721 if (lp->rx_ring == NULL) {
1451 if (pcnet32_debug & NETIF_MSG_DRV) 1722 if (netif_msg_drv(lp))
1452 printk("\n" KERN_ERR PFX 1723 printk("\n" KERN_ERR PFX
1453 "%s: Consistent memory allocation failed.\n", 1724 "%s: Consistent memory allocation failed.\n",
1454 name); 1725 name);
1455 return -ENOMEM; 1726 return -ENOMEM;
1456 } 1727 }
1457 1728
1458 lp->tx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->tx_ring_size, 1729 lp->tx_dma_addr = kcalloc(lp->tx_ring_size, sizeof(dma_addr_t),
1459 GFP_ATOMIC); 1730 GFP_ATOMIC);
1460 if (!lp->tx_dma_addr) { 1731 if (!lp->tx_dma_addr) {
1461 if (pcnet32_debug & NETIF_MSG_DRV) 1732 if (netif_msg_drv(lp))
1462 printk("\n" KERN_ERR PFX 1733 printk("\n" KERN_ERR PFX
1463 "%s: Memory allocation failed.\n", name); 1734 "%s: Memory allocation failed.\n", name);
1464 return -ENOMEM; 1735 return -ENOMEM;
1465 } 1736 }
1466 memset(lp->tx_dma_addr, 0, sizeof(dma_addr_t) * lp->tx_ring_size);
1467 1737
1468 lp->rx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->rx_ring_size, 1738 lp->rx_dma_addr = kcalloc(lp->rx_ring_size, sizeof(dma_addr_t),
1469 GFP_ATOMIC); 1739 GFP_ATOMIC);
1470 if (!lp->rx_dma_addr) { 1740 if (!lp->rx_dma_addr) {
1471 if (pcnet32_debug & NETIF_MSG_DRV) 1741 if (netif_msg_drv(lp))
1472 printk("\n" KERN_ERR PFX 1742 printk("\n" KERN_ERR PFX
1473 "%s: Memory allocation failed.\n", name); 1743 "%s: Memory allocation failed.\n", name);
1474 return -ENOMEM; 1744 return -ENOMEM;
1475 } 1745 }
1476 memset(lp->rx_dma_addr, 0, sizeof(dma_addr_t) * lp->rx_ring_size);
1477 1746
1478 lp->tx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->tx_ring_size, 1747 lp->tx_skbuff = kcalloc(lp->tx_ring_size, sizeof(struct sk_buff *),
1479 GFP_ATOMIC); 1748 GFP_ATOMIC);
1480 if (!lp->tx_skbuff) { 1749 if (!lp->tx_skbuff) {
1481 if (pcnet32_debug & NETIF_MSG_DRV) 1750 if (netif_msg_drv(lp))
1482 printk("\n" KERN_ERR PFX 1751 printk("\n" KERN_ERR PFX
1483 "%s: Memory allocation failed.\n", name); 1752 "%s: Memory allocation failed.\n", name);
1484 return -ENOMEM; 1753 return -ENOMEM;
1485 } 1754 }
1486 memset(lp->tx_skbuff, 0, sizeof(struct sk_buff *) * lp->tx_ring_size);
1487 1755
1488 lp->rx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->rx_ring_size, 1756 lp->rx_skbuff = kcalloc(lp->rx_ring_size, sizeof(struct sk_buff *),
1489 GFP_ATOMIC); 1757 GFP_ATOMIC);
1490 if (!lp->rx_skbuff) { 1758 if (!lp->rx_skbuff) {
1491 if (pcnet32_debug & NETIF_MSG_DRV) 1759 if (netif_msg_drv(lp))
1492 printk("\n" KERN_ERR PFX 1760 printk("\n" KERN_ERR PFX
1493 "%s: Memory allocation failed.\n", name); 1761 "%s: Memory allocation failed.\n", name);
1494 return -ENOMEM; 1762 return -ENOMEM;
1495 } 1763 }
1496 memset(lp->rx_skbuff, 0, sizeof(struct sk_buff *) * lp->rx_ring_size);
1497 1764
1498 return 0; 1765 return 0;
1499} 1766}
@@ -1582,10 +1849,7 @@ static int pcnet32_open(struct net_device *dev)
1582 val |= 2; 1849 val |= 2;
1583 } else if (lp->options & PCNET32_PORT_ASEL) { 1850 } else if (lp->options & PCNET32_PORT_ASEL) {
1584 /* workaround of xSeries250, turn on for 79C975 only */ 1851 /* workaround of xSeries250, turn on for 79C975 only */
1585 i = ((lp->a.read_csr(ioaddr, 88) | 1852 if (lp->chip_version == 0x2627)
1586 (lp->a.
1587 read_csr(ioaddr, 89) << 16)) >> 12) & 0xffff;
1588 if (i == 0x2627)
1589 val |= 3; 1853 val |= 3;
1590 } 1854 }
1591 lp->a.write_bcr(ioaddr, 9, val); 1855 lp->a.write_bcr(ioaddr, 9, val);
@@ -1729,9 +1993,11 @@ static int pcnet32_open(struct net_device *dev)
1729 1993
1730 netif_start_queue(dev); 1994 netif_start_queue(dev);
1731 1995
1732 /* Print the link status and start the watchdog */ 1996 if (lp->chip_version >= PCNET32_79C970A) {
1733 pcnet32_check_media(dev, 1); 1997 /* Print the link status and start the watchdog */
1734 mod_timer(&(lp->watchdog_timer), PCNET32_WATCHDOG_TIMEOUT); 1998 pcnet32_check_media(dev, 1);
1999 mod_timer(&(lp->watchdog_timer), PCNET32_WATCHDOG_TIMEOUT);
2000 }
1735 2001
1736 i = 0; 2002 i = 0;
1737 while (i++ < 100) 2003 while (i++ < 100)
@@ -1757,16 +2023,7 @@ static int pcnet32_open(struct net_device *dev)
1757 2023
1758 err_free_ring: 2024 err_free_ring:
1759 /* free any allocated skbuffs */ 2025 /* free any allocated skbuffs */
1760 for (i = 0; i < lp->rx_ring_size; i++) { 2026 pcnet32_purge_rx_ring(dev);
1761 lp->rx_ring[i].status = 0;
1762 if (lp->rx_skbuff[i]) {
1763 pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[i],
1764 PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
1765 dev_kfree_skb(lp->rx_skbuff[i]);
1766 }
1767 lp->rx_skbuff[i] = NULL;
1768 lp->rx_dma_addr[i] = 0;
1769 }
1770 2027
1771 /* 2028 /*
1772 * Switch back to 16bit mode to avoid problems with dumb 2029 * Switch back to 16bit mode to avoid problems with dumb
@@ -2348,7 +2605,6 @@ static int pcnet32_close(struct net_device *dev)
2348{ 2605{
2349 unsigned long ioaddr = dev->base_addr; 2606 unsigned long ioaddr = dev->base_addr;
2350 struct pcnet32_private *lp = dev->priv; 2607 struct pcnet32_private *lp = dev->priv;
2351 int i;
2352 unsigned long flags; 2608 unsigned long flags;
2353 2609
2354 del_timer_sync(&lp->watchdog_timer); 2610 del_timer_sync(&lp->watchdog_timer);
@@ -2379,31 +2635,8 @@ static int pcnet32_close(struct net_device *dev)
2379 2635
2380 spin_lock_irqsave(&lp->lock, flags); 2636 spin_lock_irqsave(&lp->lock, flags);
2381 2637
2382 /* free all allocated skbuffs */ 2638 pcnet32_purge_rx_ring(dev);
2383 for (i = 0; i < lp->rx_ring_size; i++) { 2639 pcnet32_purge_tx_ring(dev);
2384 lp->rx_ring[i].status = 0;
2385 wmb(); /* Make sure adapter sees owner change */
2386 if (lp->rx_skbuff[i]) {
2387 pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[i],
2388 PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
2389 dev_kfree_skb(lp->rx_skbuff[i]);
2390 }
2391 lp->rx_skbuff[i] = NULL;
2392 lp->rx_dma_addr[i] = 0;
2393 }
2394
2395 for (i = 0; i < lp->tx_ring_size; i++) {
2396 lp->tx_ring[i].status = 0; /* CPU owns buffer */
2397 wmb(); /* Make sure adapter sees owner change */
2398 if (lp->tx_skbuff[i]) {
2399 pci_unmap_single(lp->pci_dev, lp->tx_dma_addr[i],
2400 lp->tx_skbuff[i]->len,
2401 PCI_DMA_TODEVICE);
2402 dev_kfree_skb(lp->tx_skbuff[i]);
2403 }
2404 lp->tx_skbuff[i] = NULL;
2405 lp->tx_dma_addr[i] = 0;
2406 }
2407 2640
2408 spin_unlock_irqrestore(&lp->lock, flags); 2641 spin_unlock_irqrestore(&lp->lock, flags);
2409 2642
@@ -2433,6 +2666,7 @@ static void pcnet32_load_multicast(struct net_device *dev)
2433 volatile struct pcnet32_init_block *ib = &lp->init_block; 2666 volatile struct pcnet32_init_block *ib = &lp->init_block;
2434 volatile u16 *mcast_table = (u16 *) & ib->filter; 2667 volatile u16 *mcast_table = (u16 *) & ib->filter;
2435 struct dev_mc_list *dmi = dev->mc_list; 2668 struct dev_mc_list *dmi = dev->mc_list;
2669 unsigned long ioaddr = dev->base_addr;
2436 char *addrs; 2670 char *addrs;
2437 int i; 2671 int i;
2438 u32 crc; 2672 u32 crc;
@@ -2441,6 +2675,10 @@ static void pcnet32_load_multicast(struct net_device *dev)
2441 if (dev->flags & IFF_ALLMULTI) { 2675 if (dev->flags & IFF_ALLMULTI) {
2442 ib->filter[0] = 0xffffffff; 2676 ib->filter[0] = 0xffffffff;
2443 ib->filter[1] = 0xffffffff; 2677 ib->filter[1] = 0xffffffff;
2678 lp->a.write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
2679 lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
2680 lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
2681 lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
2444 return; 2682 return;
2445 } 2683 }
2446 /* clear the multicast filter */ 2684 /* clear the multicast filter */
@@ -2462,6 +2700,9 @@ static void pcnet32_load_multicast(struct net_device *dev)
2462 le16_to_cpu(le16_to_cpu(mcast_table[crc >> 4]) | 2700 le16_to_cpu(le16_to_cpu(mcast_table[crc >> 4]) |
2463 (1 << (crc & 0xf))); 2701 (1 << (crc & 0xf)));
2464 } 2702 }
2703 for (i = 0; i < 4; i++)
2704 lp->a.write_csr(ioaddr, PCNET32_MC_FILTER + i,
2705 le16_to_cpu(mcast_table[i]));
2465 return; 2706 return;
2466} 2707}
2467 2708
@@ -2472,8 +2713,11 @@ static void pcnet32_set_multicast_list(struct net_device *dev)
2472{ 2713{
2473 unsigned long ioaddr = dev->base_addr, flags; 2714 unsigned long ioaddr = dev->base_addr, flags;
2474 struct pcnet32_private *lp = dev->priv; 2715 struct pcnet32_private *lp = dev->priv;
2716 int csr15, suspended;
2475 2717
2476 spin_lock_irqsave(&lp->lock, flags); 2718 spin_lock_irqsave(&lp->lock, flags);
2719 suspended = pcnet32_suspend(dev, &flags, 0);
2720 csr15 = lp->a.read_csr(ioaddr, CSR15);
2477 if (dev->flags & IFF_PROMISC) { 2721 if (dev->flags & IFF_PROMISC) {
2478 /* Log any net taps. */ 2722 /* Log any net taps. */
2479 if (netif_msg_hw(lp)) 2723 if (netif_msg_hw(lp))
@@ -2482,15 +2726,24 @@ static void pcnet32_set_multicast_list(struct net_device *dev)
2482 lp->init_block.mode = 2726 lp->init_block.mode =
2483 le16_to_cpu(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) << 2727 le16_to_cpu(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) <<
2484 7); 2728 7);
2729 lp->a.write_csr(ioaddr, CSR15, csr15 | 0x8000);
2485 } else { 2730 } else {
2486 lp->init_block.mode = 2731 lp->init_block.mode =
2487 le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7); 2732 le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7);
2733 lp->a.write_csr(ioaddr, CSR15, csr15 & 0x7fff);
2488 pcnet32_load_multicast(dev); 2734 pcnet32_load_multicast(dev);
2489 } 2735 }
2490 2736
2491 lp->a.write_csr(ioaddr, 0, 0x0004); /* Temporarily stop the lance. */ 2737 if (suspended) {
2492 pcnet32_restart(dev, 0x0042); /* Resume normal operation */ 2738 int csr5;
2493 netif_wake_queue(dev); 2739 /* clear SUSPEND (SPND) - CSR5 bit 0 */
2740 csr5 = lp->a.read_csr(ioaddr, CSR5);
2741 lp->a.write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
2742 } else {
2743 lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
2744 pcnet32_restart(dev, CSR0_NORMAL);
2745 netif_wake_queue(dev);
2746 }
2494 2747
2495 spin_unlock_irqrestore(&lp->lock, flags); 2748 spin_unlock_irqrestore(&lp->lock, flags);
2496} 2749}
@@ -2730,7 +2983,7 @@ static int __init pcnet32_init_module(void)
2730 2983
2731 /* should we find any remaining VLbus devices ? */ 2984 /* should we find any remaining VLbus devices ? */
2732 if (pcnet32vlb) 2985 if (pcnet32vlb)
2733 pcnet32_probe_vlbus(); 2986 pcnet32_probe_vlbus(pcnet32_portlist);
2734 2987
2735 if (cards_found && (pcnet32_debug & NETIF_MSG_PROBE)) 2988 if (cards_found && (pcnet32_debug & NETIF_MSG_PROBE))
2736 printk(KERN_INFO PFX "%d cards_found.\n", cards_found); 2989 printk(KERN_INFO PFX "%d cards_found.\n", cards_found);