aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/net/8139cp.c114
1 files changed, 51 insertions, 63 deletions
diff --git a/drivers/net/8139cp.c b/drivers/net/8139cp.c
index 4cdb6b2efb9a..488241c5bdd8 100644
--- a/drivers/net/8139cp.c
+++ b/drivers/net/8139cp.c
@@ -314,12 +314,6 @@ struct cp_desc {
314 u64 addr; 314 u64 addr;
315}; 315};
316 316
317struct ring_info {
318 struct sk_buff *skb;
319 dma_addr_t mapping;
320 u32 len;
321};
322
323struct cp_dma_stats { 317struct cp_dma_stats {
324 u64 tx_ok; 318 u64 tx_ok;
325 u64 rx_ok; 319 u64 rx_ok;
@@ -353,23 +347,23 @@ struct cp_private {
353 struct net_device_stats net_stats; 347 struct net_device_stats net_stats;
354 struct cp_extra_stats cp_stats; 348 struct cp_extra_stats cp_stats;
355 349
356 unsigned rx_tail ____cacheline_aligned; 350 unsigned rx_head ____cacheline_aligned;
351 unsigned rx_tail;
357 struct cp_desc *rx_ring; 352 struct cp_desc *rx_ring;
358 struct ring_info rx_skb[CP_RX_RING_SIZE]; 353 struct sk_buff *rx_skb[CP_RX_RING_SIZE];
359 unsigned rx_buf_sz;
360 354
361 unsigned tx_head ____cacheline_aligned; 355 unsigned tx_head ____cacheline_aligned;
362 unsigned tx_tail; 356 unsigned tx_tail;
363
364 struct cp_desc *tx_ring; 357 struct cp_desc *tx_ring;
365 struct ring_info tx_skb[CP_TX_RING_SIZE]; 358 struct sk_buff *tx_skb[CP_TX_RING_SIZE];
366 dma_addr_t ring_dma; 359
360 unsigned rx_buf_sz;
361 unsigned wol_enabled : 1; /* Is Wake-on-LAN enabled? */
367 362
368#if CP_VLAN_TAG_USED 363#if CP_VLAN_TAG_USED
369 struct vlan_group *vlgrp; 364 struct vlan_group *vlgrp;
370#endif 365#endif
371 366 dma_addr_t ring_dma;
372 unsigned int wol_enabled : 1; /* Is Wake-on-LAN enabled? */
373 367
374 struct mii_if_info mii_if; 368 struct mii_if_info mii_if;
375}; 369};
@@ -407,10 +401,8 @@ static int cp_set_eeprom(struct net_device *dev,
407 struct ethtool_eeprom *eeprom, u8 *data); 401 struct ethtool_eeprom *eeprom, u8 *data);
408 402
409static struct pci_device_id cp_pci_tbl[] = { 403static struct pci_device_id cp_pci_tbl[] = {
410 { PCI_VENDOR_ID_REALTEK, PCI_DEVICE_ID_REALTEK_8139, 404 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, PCI_DEVICE_ID_REALTEK_8139), },
411 PCI_ANY_ID, PCI_ANY_ID, 0, 0, }, 405 { PCI_DEVICE(PCI_VENDOR_ID_TTTECH, PCI_DEVICE_ID_TTTECH_MC322), },
412 { PCI_VENDOR_ID_TTTECH, PCI_DEVICE_ID_TTTECH_MC322,
413 PCI_ANY_ID, PCI_ANY_ID, 0, 0, },
414 { }, 406 { },
415}; 407};
416MODULE_DEVICE_TABLE(pci, cp_pci_tbl); 408MODULE_DEVICE_TABLE(pci, cp_pci_tbl);
@@ -542,7 +534,7 @@ rx_status_loop:
542 struct cp_desc *desc; 534 struct cp_desc *desc;
543 unsigned buflen; 535 unsigned buflen;
544 536
545 skb = cp->rx_skb[rx_tail].skb; 537 skb = cp->rx_skb[rx_tail];
546 BUG_ON(!skb); 538 BUG_ON(!skb);
547 539
548 desc = &cp->rx_ring[rx_tail]; 540 desc = &cp->rx_ring[rx_tail];
@@ -551,7 +543,7 @@ rx_status_loop:
551 break; 543 break;
552 544
553 len = (status & 0x1fff) - 4; 545 len = (status & 0x1fff) - 4;
554 mapping = cp->rx_skb[rx_tail].mapping; 546 mapping = le64_to_cpu(desc->addr);
555 547
556 if ((status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag)) { 548 if ((status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag)) {
557 /* we don't support incoming fragmented frames. 549 /* we don't support incoming fragmented frames.
@@ -572,7 +564,7 @@ rx_status_loop:
572 564
573 if (netif_msg_rx_status(cp)) 565 if (netif_msg_rx_status(cp))
574 printk(KERN_DEBUG "%s: rx slot %d status 0x%x len %d\n", 566 printk(KERN_DEBUG "%s: rx slot %d status 0x%x len %d\n",
575 cp->dev->name, rx_tail, status, len); 567 dev->name, rx_tail, status, len);
576 568
577 buflen = cp->rx_buf_sz + RX_OFFSET; 569 buflen = cp->rx_buf_sz + RX_OFFSET;
578 new_skb = dev_alloc_skb (buflen); 570 new_skb = dev_alloc_skb (buflen);
@@ -582,7 +574,7 @@ rx_status_loop:
582 } 574 }
583 575
584 skb_reserve(new_skb, RX_OFFSET); 576 skb_reserve(new_skb, RX_OFFSET);
585 new_skb->dev = cp->dev; 577 new_skb->dev = dev;
586 578
587 pci_unmap_single(cp->pdev, mapping, 579 pci_unmap_single(cp->pdev, mapping,
588 buflen, PCI_DMA_FROMDEVICE); 580 buflen, PCI_DMA_FROMDEVICE);
@@ -595,11 +587,9 @@ rx_status_loop:
595 587
596 skb_put(skb, len); 588 skb_put(skb, len);
597 589
598 mapping = 590 mapping = pci_map_single(cp->pdev, new_skb->data, buflen,
599 cp->rx_skb[rx_tail].mapping = 591 PCI_DMA_FROMDEVICE);
600 pci_map_single(cp->pdev, new_skb->data, 592 cp->rx_skb[rx_tail] = new_skb;
601 buflen, PCI_DMA_FROMDEVICE);
602 cp->rx_skb[rx_tail].skb = new_skb;
603 593
604 cp_rx_skb(cp, skb, desc); 594 cp_rx_skb(cp, skb, desc);
605 rx++; 595 rx++;
@@ -717,19 +707,21 @@ static void cp_tx (struct cp_private *cp)
717 unsigned tx_tail = cp->tx_tail; 707 unsigned tx_tail = cp->tx_tail;
718 708
719 while (tx_tail != tx_head) { 709 while (tx_tail != tx_head) {
710 struct cp_desc *txd = cp->tx_ring + tx_tail;
720 struct sk_buff *skb; 711 struct sk_buff *skb;
721 u32 status; 712 u32 status;
722 713
723 rmb(); 714 rmb();
724 status = le32_to_cpu(cp->tx_ring[tx_tail].opts1); 715 status = le32_to_cpu(txd->opts1);
725 if (status & DescOwn) 716 if (status & DescOwn)
726 break; 717 break;
727 718
728 skb = cp->tx_skb[tx_tail].skb; 719 skb = cp->tx_skb[tx_tail];
729 BUG_ON(!skb); 720 BUG_ON(!skb);
730 721
731 pci_unmap_single(cp->pdev, cp->tx_skb[tx_tail].mapping, 722 pci_unmap_single(cp->pdev, le64_to_cpu(txd->addr),
732 cp->tx_skb[tx_tail].len, PCI_DMA_TODEVICE); 723 le32_to_cpu(txd->opts1) & 0xffff,
724 PCI_DMA_TODEVICE);
733 725
734 if (status & LastFrag) { 726 if (status & LastFrag) {
735 if (status & (TxError | TxFIFOUnder)) { 727 if (status & (TxError | TxFIFOUnder)) {
@@ -756,7 +748,7 @@ static void cp_tx (struct cp_private *cp)
756 dev_kfree_skb_irq(skb); 748 dev_kfree_skb_irq(skb);
757 } 749 }
758 750
759 cp->tx_skb[tx_tail].skb = NULL; 751 cp->tx_skb[tx_tail] = NULL;
760 752
761 tx_tail = NEXT_TX(tx_tail); 753 tx_tail = NEXT_TX(tx_tail);
762 } 754 }
@@ -826,9 +818,7 @@ static int cp_start_xmit (struct sk_buff *skb, struct net_device *dev)
826 txd->opts1 = cpu_to_le32(flags); 818 txd->opts1 = cpu_to_le32(flags);
827 wmb(); 819 wmb();
828 820
829 cp->tx_skb[entry].skb = skb; 821 cp->tx_skb[entry] = skb;
830 cp->tx_skb[entry].mapping = mapping;
831 cp->tx_skb[entry].len = len;
832 entry = NEXT_TX(entry); 822 entry = NEXT_TX(entry);
833 } else { 823 } else {
834 struct cp_desc *txd; 824 struct cp_desc *txd;
@@ -844,9 +834,7 @@ static int cp_start_xmit (struct sk_buff *skb, struct net_device *dev)
844 first_len = skb_headlen(skb); 834 first_len = skb_headlen(skb);
845 first_mapping = pci_map_single(cp->pdev, skb->data, 835 first_mapping = pci_map_single(cp->pdev, skb->data,
846 first_len, PCI_DMA_TODEVICE); 836 first_len, PCI_DMA_TODEVICE);
847 cp->tx_skb[entry].skb = skb; 837 cp->tx_skb[entry] = skb;
848 cp->tx_skb[entry].mapping = first_mapping;
849 cp->tx_skb[entry].len = first_len;
850 entry = NEXT_TX(entry); 838 entry = NEXT_TX(entry);
851 839
852 for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) { 840 for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) {
@@ -887,9 +875,7 @@ static int cp_start_xmit (struct sk_buff *skb, struct net_device *dev)
887 txd->opts1 = cpu_to_le32(ctrl); 875 txd->opts1 = cpu_to_le32(ctrl);
888 wmb(); 876 wmb();
889 877
890 cp->tx_skb[entry].skb = skb; 878 cp->tx_skb[entry] = skb;
891 cp->tx_skb[entry].mapping = mapping;
892 cp->tx_skb[entry].len = len;
893 entry = NEXT_TX(entry); 879 entry = NEXT_TX(entry);
894 } 880 }
895 881
@@ -1089,6 +1075,7 @@ static int cp_refill_rx (struct cp_private *cp)
1089 1075
1090 for (i = 0; i < CP_RX_RING_SIZE; i++) { 1076 for (i = 0; i < CP_RX_RING_SIZE; i++) {
1091 struct sk_buff *skb; 1077 struct sk_buff *skb;
1078 dma_addr_t mapping;
1092 1079
1093 skb = dev_alloc_skb(cp->rx_buf_sz + RX_OFFSET); 1080 skb = dev_alloc_skb(cp->rx_buf_sz + RX_OFFSET);
1094 if (!skb) 1081 if (!skb)
@@ -1097,12 +1084,12 @@ static int cp_refill_rx (struct cp_private *cp)
1097 skb->dev = cp->dev; 1084 skb->dev = cp->dev;
1098 skb_reserve(skb, RX_OFFSET); 1085 skb_reserve(skb, RX_OFFSET);
1099 1086
1100 cp->rx_skb[i].mapping = pci_map_single(cp->pdev, 1087 mapping = pci_map_single(cp->pdev, skb->data, cp->rx_buf_sz,
1101 skb->data, cp->rx_buf_sz, PCI_DMA_FROMDEVICE); 1088 PCI_DMA_FROMDEVICE);
1102 cp->rx_skb[i].skb = skb; 1089 cp->rx_skb[i] = skb;
1103 1090
1104 cp->rx_ring[i].opts2 = 0; 1091 cp->rx_ring[i].opts2 = 0;
1105 cp->rx_ring[i].addr = cpu_to_le64(cp->rx_skb[i].mapping); 1092 cp->rx_ring[i].addr = cpu_to_le64(mapping);
1106 if (i == (CP_RX_RING_SIZE - 1)) 1093 if (i == (CP_RX_RING_SIZE - 1))
1107 cp->rx_ring[i].opts1 = 1094 cp->rx_ring[i].opts1 =
1108 cpu_to_le32(DescOwn | RingEnd | cp->rx_buf_sz); 1095 cpu_to_le32(DescOwn | RingEnd | cp->rx_buf_sz);
@@ -1150,23 +1137,27 @@ static int cp_alloc_rings (struct cp_private *cp)
1150 1137
1151static void cp_clean_rings (struct cp_private *cp) 1138static void cp_clean_rings (struct cp_private *cp)
1152{ 1139{
1140 struct cp_desc *desc;
1153 unsigned i; 1141 unsigned i;
1154 1142
1155 for (i = 0; i < CP_RX_RING_SIZE; i++) { 1143 for (i = 0; i < CP_RX_RING_SIZE; i++) {
1156 if (cp->rx_skb[i].skb) { 1144 if (cp->rx_skb[i]) {
1157 pci_unmap_single(cp->pdev, cp->rx_skb[i].mapping, 1145 desc = cp->rx_ring + i;
1146 pci_unmap_single(cp->pdev, le64_to_cpu(desc->addr),
1158 cp->rx_buf_sz, PCI_DMA_FROMDEVICE); 1147 cp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1159 dev_kfree_skb(cp->rx_skb[i].skb); 1148 dev_kfree_skb(cp->rx_skb[i]);
1160 } 1149 }
1161 } 1150 }
1162 1151
1163 for (i = 0; i < CP_TX_RING_SIZE; i++) { 1152 for (i = 0; i < CP_TX_RING_SIZE; i++) {
1164 if (cp->tx_skb[i].skb) { 1153 if (cp->tx_skb[i]) {
1165 struct sk_buff *skb = cp->tx_skb[i].skb; 1154 struct sk_buff *skb = cp->tx_skb[i];
1166 1155
1167 pci_unmap_single(cp->pdev, cp->tx_skb[i].mapping, 1156 desc = cp->tx_ring + i;
1168 cp->tx_skb[i].len, PCI_DMA_TODEVICE); 1157 pci_unmap_single(cp->pdev, le64_to_cpu(desc->addr),
1169 if (le32_to_cpu(cp->tx_ring[i].opts1) & LastFrag) 1158 le32_to_cpu(desc->opts1) & 0xffff,
1159 PCI_DMA_TODEVICE);
1160 if (le32_to_cpu(desc->opts1) & LastFrag)
1170 dev_kfree_skb(skb); 1161 dev_kfree_skb(skb);
1171 cp->net_stats.tx_dropped++; 1162 cp->net_stats.tx_dropped++;
1172 } 1163 }
@@ -1175,8 +1166,8 @@ static void cp_clean_rings (struct cp_private *cp)
1175 memset(cp->rx_ring, 0, sizeof(struct cp_desc) * CP_RX_RING_SIZE); 1166 memset(cp->rx_ring, 0, sizeof(struct cp_desc) * CP_RX_RING_SIZE);
1176 memset(cp->tx_ring, 0, sizeof(struct cp_desc) * CP_TX_RING_SIZE); 1167 memset(cp->tx_ring, 0, sizeof(struct cp_desc) * CP_TX_RING_SIZE);
1177 1168
1178 memset(&cp->rx_skb, 0, sizeof(struct ring_info) * CP_RX_RING_SIZE); 1169 memset(cp->rx_skb, 0, sizeof(struct sk_buff *) * CP_RX_RING_SIZE);
1179 memset(&cp->tx_skb, 0, sizeof(struct ring_info) * CP_TX_RING_SIZE); 1170 memset(cp->tx_skb, 0, sizeof(struct sk_buff *) * CP_TX_RING_SIZE);
1180} 1171}
1181 1172
1182static void cp_free_rings (struct cp_private *cp) 1173static void cp_free_rings (struct cp_private *cp)
@@ -2008,7 +1999,6 @@ static void cp_remove_one (struct pci_dev *pdev)
2008 struct net_device *dev = pci_get_drvdata(pdev); 1999 struct net_device *dev = pci_get_drvdata(pdev);
2009 struct cp_private *cp = netdev_priv(dev); 2000 struct cp_private *cp = netdev_priv(dev);
2010 2001
2011 BUG_ON(!dev);
2012 unregister_netdev(dev); 2002 unregister_netdev(dev);
2013 iounmap(cp->regs); 2003 iounmap(cp->regs);
2014 if (cp->wol_enabled) 2004 if (cp->wol_enabled)
@@ -2023,14 +2013,12 @@ static void cp_remove_one (struct pci_dev *pdev)
2023#ifdef CONFIG_PM 2013#ifdef CONFIG_PM
2024static int cp_suspend (struct pci_dev *pdev, pm_message_t state) 2014static int cp_suspend (struct pci_dev *pdev, pm_message_t state)
2025{ 2015{
2026 struct net_device *dev; 2016 struct net_device *dev = pci_get_drvdata(pdev);
2027 struct cp_private *cp; 2017 struct cp_private *cp = netdev_priv(dev);
2028 unsigned long flags; 2018 unsigned long flags;
2029 2019
2030 dev = pci_get_drvdata (pdev); 2020 if (!netif_running(dev))
2031 cp = netdev_priv(dev); 2021 return 0;
2032
2033 if (!dev || !netif_running (dev)) return 0;
2034 2022
2035 netif_device_detach (dev); 2023 netif_device_detach (dev);
2036 netif_stop_queue (dev); 2024 netif_stop_queue (dev);