aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/igbvf/netdev.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/igbvf/netdev.c')
-rw-r--r--drivers/net/igbvf/netdev.c142
1 files changed, 80 insertions, 62 deletions
diff --git a/drivers/net/igbvf/netdev.c b/drivers/net/igbvf/netdev.c
index 91024a3cdad3..1b1edad1eb5e 100644
--- a/drivers/net/igbvf/netdev.c
+++ b/drivers/net/igbvf/netdev.c
@@ -35,6 +35,7 @@
35#include <linux/netdevice.h> 35#include <linux/netdevice.h>
36#include <linux/tcp.h> 36#include <linux/tcp.h>
37#include <linux/ipv6.h> 37#include <linux/ipv6.h>
38#include <linux/slab.h>
38#include <net/checksum.h> 39#include <net/checksum.h>
39#include <net/ip6_checksum.h> 40#include <net/ip6_checksum.h>
40#include <linux/mii.h> 41#include <linux/mii.h>
@@ -170,18 +171,12 @@ static void igbvf_alloc_rx_buffers(struct igbvf_ring *rx_ring,
170 } 171 }
171 172
172 if (!buffer_info->skb) { 173 if (!buffer_info->skb) {
173 skb = netdev_alloc_skb(netdev, bufsz + NET_IP_ALIGN); 174 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
174 if (!skb) { 175 if (!skb) {
175 adapter->alloc_rx_buff_failed++; 176 adapter->alloc_rx_buff_failed++;
176 goto no_buffers; 177 goto no_buffers;
177 } 178 }
178 179
179 /* Make buffer alignment 2 beyond a 16 byte boundary
180 * this will result in a 16 byte aligned IP header after
181 * the 14 byte MAC header is removed
182 */
183 skb_reserve(skb, NET_IP_ALIGN);
184
185 buffer_info->skb = skb; 180 buffer_info->skb = skb;
186 buffer_info->dma = pci_map_single(pdev, skb->data, 181 buffer_info->dma = pci_map_single(pdev, skb->data,
187 bufsz, 182 bufsz,
@@ -372,10 +367,20 @@ next_desc:
372static void igbvf_put_txbuf(struct igbvf_adapter *adapter, 367static void igbvf_put_txbuf(struct igbvf_adapter *adapter,
373 struct igbvf_buffer *buffer_info) 368 struct igbvf_buffer *buffer_info)
374{ 369{
375 buffer_info->dma = 0; 370 if (buffer_info->dma) {
371 if (buffer_info->mapped_as_page)
372 pci_unmap_page(adapter->pdev,
373 buffer_info->dma,
374 buffer_info->length,
375 PCI_DMA_TODEVICE);
376 else
377 pci_unmap_single(adapter->pdev,
378 buffer_info->dma,
379 buffer_info->length,
380 PCI_DMA_TODEVICE);
381 buffer_info->dma = 0;
382 }
376 if (buffer_info->skb) { 383 if (buffer_info->skb) {
377 skb_dma_unmap(&adapter->pdev->dev, buffer_info->skb,
378 DMA_TO_DEVICE);
379 dev_kfree_skb_any(buffer_info->skb); 384 dev_kfree_skb_any(buffer_info->skb);
380 buffer_info->skb = NULL; 385 buffer_info->skb = NULL;
381 } 386 }
@@ -823,8 +828,8 @@ static bool igbvf_clean_tx_irq(struct igbvf_ring *tx_ring)
823 adapter->detect_tx_hung = false; 828 adapter->detect_tx_hung = false;
824 if (tx_ring->buffer_info[i].time_stamp && 829 if (tx_ring->buffer_info[i].time_stamp &&
825 time_after(jiffies, tx_ring->buffer_info[i].time_stamp + 830 time_after(jiffies, tx_ring->buffer_info[i].time_stamp +
826 (adapter->tx_timeout_factor * HZ)) 831 (adapter->tx_timeout_factor * HZ)) &&
827 && !(er32(STATUS) & E1000_STATUS_TXOFF)) { 832 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
828 833
829 tx_desc = IGBVF_TX_DESC_ADV(*tx_ring, i); 834 tx_desc = IGBVF_TX_DESC_ADV(*tx_ring, i);
830 /* detected Tx unit hang */ 835 /* detected Tx unit hang */
@@ -1049,7 +1054,7 @@ static int igbvf_request_msix(struct igbvf_adapter *adapter)
1049 } 1054 }
1050 1055
1051 err = request_irq(adapter->msix_entries[vector].vector, 1056 err = request_irq(adapter->msix_entries[vector].vector,
1052 &igbvf_intr_msix_tx, 0, adapter->tx_ring->name, 1057 igbvf_intr_msix_tx, 0, adapter->tx_ring->name,
1053 netdev); 1058 netdev);
1054 if (err) 1059 if (err)
1055 goto out; 1060 goto out;
@@ -1059,7 +1064,7 @@ static int igbvf_request_msix(struct igbvf_adapter *adapter)
1059 vector++; 1064 vector++;
1060 1065
1061 err = request_irq(adapter->msix_entries[vector].vector, 1066 err = request_irq(adapter->msix_entries[vector].vector,
1062 &igbvf_intr_msix_rx, 0, adapter->rx_ring->name, 1067 igbvf_intr_msix_rx, 0, adapter->rx_ring->name,
1063 netdev); 1068 netdev);
1064 if (err) 1069 if (err)
1065 goto out; 1070 goto out;
@@ -1069,7 +1074,7 @@ static int igbvf_request_msix(struct igbvf_adapter *adapter)
1069 vector++; 1074 vector++;
1070 1075
1071 err = request_irq(adapter->msix_entries[vector].vector, 1076 err = request_irq(adapter->msix_entries[vector].vector,
1072 &igbvf_msix_other, 0, netdev->name, netdev); 1077 igbvf_msix_other, 0, netdev->name, netdev);
1073 if (err) 1078 if (err)
1074 goto out; 1079 goto out;
1075 1080
@@ -1300,8 +1305,6 @@ static void igbvf_configure_tx(struct igbvf_adapter *adapter)
1300 1305
1301 /* enable Report Status bit */ 1306 /* enable Report Status bit */
1302 adapter->txd_cmd |= E1000_ADVTXD_DCMD_RS; 1307 adapter->txd_cmd |= E1000_ADVTXD_DCMD_RS;
1303
1304 adapter->tx_queue_len = adapter->netdev->tx_queue_len;
1305} 1308}
1306 1309
1307/** 1310/**
@@ -1399,8 +1402,8 @@ static void igbvf_set_multi(struct net_device *netdev)
1399 u8 *mta_list = NULL; 1402 u8 *mta_list = NULL;
1400 int i; 1403 int i;
1401 1404
1402 if (netdev->mc_count) { 1405 if (!netdev_mc_empty(netdev)) {
1403 mta_list = kmalloc(netdev->mc_count * 6, GFP_ATOMIC); 1406 mta_list = kmalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
1404 if (!mta_list) { 1407 if (!mta_list) {
1405 dev_err(&adapter->pdev->dev, 1408 dev_err(&adapter->pdev->dev,
1406 "failed to allocate multicast filter list\n"); 1409 "failed to allocate multicast filter list\n");
@@ -1409,15 +1412,9 @@ static void igbvf_set_multi(struct net_device *netdev)
1409 } 1412 }
1410 1413
1411 /* prepare a packed array of only addresses. */ 1414 /* prepare a packed array of only addresses. */
1412 mc_ptr = netdev->mc_list; 1415 i = 0;
1413 1416 netdev_for_each_mc_addr(mc_ptr, netdev)
1414 for (i = 0; i < netdev->mc_count; i++) { 1417 memcpy(mta_list + (i++ * ETH_ALEN), mc_ptr->dmi_addr, ETH_ALEN);
1415 if (!mc_ptr)
1416 break;
1417 memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr,
1418 ETH_ALEN);
1419 mc_ptr = mc_ptr->next;
1420 }
1421 1418
1422 hw->mac.ops.update_mc_addr_list(hw, mta_list, i, 0, 0); 1419 hw->mac.ops.update_mc_addr_list(hw, mta_list, i, 0, 0);
1423 kfree(mta_list); 1420 kfree(mta_list);
@@ -1465,6 +1462,8 @@ static void igbvf_reset(struct igbvf_adapter *adapter)
1465 memcpy(netdev->perm_addr, adapter->hw.mac.addr, 1462 memcpy(netdev->perm_addr, adapter->hw.mac.addr,
1466 netdev->addr_len); 1463 netdev->addr_len);
1467 } 1464 }
1465
1466 adapter->last_reset = jiffies;
1468} 1467}
1469 1468
1470int igbvf_up(struct igbvf_adapter *adapter) 1469int igbvf_up(struct igbvf_adapter *adapter)
@@ -1524,7 +1523,6 @@ void igbvf_down(struct igbvf_adapter *adapter)
1524 1523
1525 del_timer_sync(&adapter->watchdog_timer); 1524 del_timer_sync(&adapter->watchdog_timer);
1526 1525
1527 netdev->tx_queue_len = adapter->tx_queue_len;
1528 netif_carrier_off(netdev); 1526 netif_carrier_off(netdev);
1529 1527
1530 /* record the stats before reset*/ 1528 /* record the stats before reset*/
@@ -1808,11 +1806,15 @@ static bool igbvf_has_link(struct igbvf_adapter *adapter)
1808 s32 ret_val = E1000_SUCCESS; 1806 s32 ret_val = E1000_SUCCESS;
1809 bool link_active; 1807 bool link_active;
1810 1808
1809 /* If interface is down, stay link down */
1810 if (test_bit(__IGBVF_DOWN, &adapter->state))
1811 return false;
1812
1811 ret_val = hw->mac.ops.check_for_link(hw); 1813 ret_val = hw->mac.ops.check_for_link(hw);
1812 link_active = !hw->mac.get_link_status; 1814 link_active = !hw->mac.get_link_status;
1813 1815
1814 /* if check for link returns error we will need to reset */ 1816 /* if check for link returns error we will need to reset */
1815 if (ret_val) 1817 if (ret_val && time_after(jiffies, adapter->last_reset + (10 * HZ)))
1816 schedule_work(&adapter->reset_task); 1818 schedule_work(&adapter->reset_task);
1817 1819
1818 return link_active; 1820 return link_active;
@@ -1853,21 +1855,15 @@ static void igbvf_watchdog_task(struct work_struct *work)
1853 &adapter->link_duplex); 1855 &adapter->link_duplex);
1854 igbvf_print_link_info(adapter); 1856 igbvf_print_link_info(adapter);
1855 1857
1856 /* 1858 /* adjust timeout factor according to speed/duplex */
1857 * tweak tx_queue_len according to speed/duplex
1858 * and adjust the timeout factor
1859 */
1860 netdev->tx_queue_len = adapter->tx_queue_len;
1861 adapter->tx_timeout_factor = 1; 1859 adapter->tx_timeout_factor = 1;
1862 switch (adapter->link_speed) { 1860 switch (adapter->link_speed) {
1863 case SPEED_10: 1861 case SPEED_10:
1864 txb2b = 0; 1862 txb2b = 0;
1865 netdev->tx_queue_len = 10;
1866 adapter->tx_timeout_factor = 16; 1863 adapter->tx_timeout_factor = 16;
1867 break; 1864 break;
1868 case SPEED_100: 1865 case SPEED_100:
1869 txb2b = 0; 1866 txb2b = 0;
1870 netdev->tx_queue_len = 100;
1871 /* maybe add some timeout factor ? */ 1867 /* maybe add some timeout factor ? */
1872 break; 1868 break;
1873 } 1869 }
@@ -1953,7 +1949,7 @@ static int igbvf_tso(struct igbvf_adapter *adapter,
1953 iph->daddr, 0, 1949 iph->daddr, 0,
1954 IPPROTO_TCP, 1950 IPPROTO_TCP,
1955 0); 1951 0);
1956 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) { 1952 } else if (skb_is_gso_v6(skb)) {
1957 ipv6_hdr(skb)->payload_len = 0; 1953 ipv6_hdr(skb)->payload_len = 0;
1958 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, 1954 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
1959 &ipv6_hdr(skb)->daddr, 1955 &ipv6_hdr(skb)->daddr,
@@ -2094,31 +2090,30 @@ static inline int igbvf_tx_map_adv(struct igbvf_adapter *adapter,
2094 unsigned int first) 2090 unsigned int first)
2095{ 2091{
2096 struct igbvf_buffer *buffer_info; 2092 struct igbvf_buffer *buffer_info;
2093 struct pci_dev *pdev = adapter->pdev;
2097 unsigned int len = skb_headlen(skb); 2094 unsigned int len = skb_headlen(skb);
2098 unsigned int count = 0, i; 2095 unsigned int count = 0, i;
2099 unsigned int f; 2096 unsigned int f;
2100 dma_addr_t *map;
2101 2097
2102 i = tx_ring->next_to_use; 2098 i = tx_ring->next_to_use;
2103 2099
2104 if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
2105 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
2106 return 0;
2107 }
2108
2109 map = skb_shinfo(skb)->dma_maps;
2110
2111 buffer_info = &tx_ring->buffer_info[i]; 2100 buffer_info = &tx_ring->buffer_info[i];
2112 BUG_ON(len >= IGBVF_MAX_DATA_PER_TXD); 2101 BUG_ON(len >= IGBVF_MAX_DATA_PER_TXD);
2113 buffer_info->length = len; 2102 buffer_info->length = len;
2114 /* set time_stamp *before* dma to help avoid a possible race */ 2103 /* set time_stamp *before* dma to help avoid a possible race */
2115 buffer_info->time_stamp = jiffies; 2104 buffer_info->time_stamp = jiffies;
2116 buffer_info->next_to_watch = i; 2105 buffer_info->next_to_watch = i;
2117 buffer_info->dma = skb_shinfo(skb)->dma_head; 2106 buffer_info->mapped_as_page = false;
2107 buffer_info->dma = pci_map_single(pdev, skb->data, len,
2108 PCI_DMA_TODEVICE);
2109 if (pci_dma_mapping_error(pdev, buffer_info->dma))
2110 goto dma_error;
2111
2118 2112
2119 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) { 2113 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) {
2120 struct skb_frag_struct *frag; 2114 struct skb_frag_struct *frag;
2121 2115
2116 count++;
2122 i++; 2117 i++;
2123 if (i == tx_ring->count) 2118 if (i == tx_ring->count)
2124 i = 0; 2119 i = 0;
@@ -2131,14 +2126,43 @@ static inline int igbvf_tx_map_adv(struct igbvf_adapter *adapter,
2131 buffer_info->length = len; 2126 buffer_info->length = len;
2132 buffer_info->time_stamp = jiffies; 2127 buffer_info->time_stamp = jiffies;
2133 buffer_info->next_to_watch = i; 2128 buffer_info->next_to_watch = i;
2134 buffer_info->dma = map[count]; 2129 buffer_info->mapped_as_page = true;
2135 count++; 2130 buffer_info->dma = pci_map_page(pdev,
2131 frag->page,
2132 frag->page_offset,
2133 len,
2134 PCI_DMA_TODEVICE);
2135 if (pci_dma_mapping_error(pdev, buffer_info->dma))
2136 goto dma_error;
2136 } 2137 }
2137 2138
2138 tx_ring->buffer_info[i].skb = skb; 2139 tx_ring->buffer_info[i].skb = skb;
2139 tx_ring->buffer_info[first].next_to_watch = i; 2140 tx_ring->buffer_info[first].next_to_watch = i;
2140 2141
2141 return count + 1; 2142 return ++count;
2143
2144dma_error:
2145 dev_err(&pdev->dev, "TX DMA map failed\n");
2146
2147 /* clear timestamp and dma mappings for failed buffer_info mapping */
2148 buffer_info->dma = 0;
2149 buffer_info->time_stamp = 0;
2150 buffer_info->length = 0;
2151 buffer_info->next_to_watch = 0;
2152 buffer_info->mapped_as_page = false;
2153 if (count)
2154 count--;
2155
2156 /* clear timestamp and dma mappings for remaining portion of packet */
2157 while (count--) {
2158 if (i==0)
2159 i += tx_ring->count;
2160 i--;
2161 buffer_info = &tx_ring->buffer_info[i];
2162 igbvf_put_txbuf(adapter, buffer_info);
2163 }
2164
2165 return 0;
2142} 2166}
2143 2167
2144static inline void igbvf_tx_queue_adv(struct igbvf_adapter *adapter, 2168static inline void igbvf_tx_queue_adv(struct igbvf_adapter *adapter,
@@ -2571,11 +2595,7 @@ static void igbvf_print_device_info(struct igbvf_adapter *adapter)
2571 struct pci_dev *pdev = adapter->pdev; 2595 struct pci_dev *pdev = adapter->pdev;
2572 2596
2573 dev_info(&pdev->dev, "Intel(R) 82576 Virtual Function\n"); 2597 dev_info(&pdev->dev, "Intel(R) 82576 Virtual Function\n");
2574 dev_info(&pdev->dev, "Address: %02x:%02x:%02x:%02x:%02x:%02x\n", 2598 dev_info(&pdev->dev, "Address: %pM\n", netdev->dev_addr);
2575 /* MAC address */
2576 netdev->dev_addr[0], netdev->dev_addr[1],
2577 netdev->dev_addr[2], netdev->dev_addr[3],
2578 netdev->dev_addr[4], netdev->dev_addr[5]);
2579 dev_info(&pdev->dev, "MAC: %d\n", hw->mac.type); 2599 dev_info(&pdev->dev, "MAC: %d\n", hw->mac.type);
2580} 2600}
2581 2601
@@ -2726,7 +2746,8 @@ static int __devinit igbvf_probe(struct pci_dev *pdev,
2726 err = hw->mac.ops.reset_hw(hw); 2746 err = hw->mac.ops.reset_hw(hw);
2727 if (err) { 2747 if (err) {
2728 dev_info(&pdev->dev, 2748 dev_info(&pdev->dev,
2729 "PF still in reset state, assigning new address\n"); 2749 "PF still in reset state, assigning new address."
2750 " Is the PF interface up?\n");
2730 random_ether_addr(hw->mac.addr); 2751 random_ether_addr(hw->mac.addr);
2731 } else { 2752 } else {
2732 err = hw->mac.ops.read_mac_addr(hw); 2753 err = hw->mac.ops.read_mac_addr(hw);
@@ -2740,11 +2761,8 @@ static int __devinit igbvf_probe(struct pci_dev *pdev,
2740 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len); 2761 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
2741 2762
2742 if (!is_valid_ether_addr(netdev->perm_addr)) { 2763 if (!is_valid_ether_addr(netdev->perm_addr)) {
2743 dev_err(&pdev->dev, "Invalid MAC Address: " 2764 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
2744 "%02x:%02x:%02x:%02x:%02x:%02x\n", 2765 netdev->dev_addr);
2745 netdev->dev_addr[0], netdev->dev_addr[1],
2746 netdev->dev_addr[2], netdev->dev_addr[3],
2747 netdev->dev_addr[4], netdev->dev_addr[5]);
2748 err = -EIO; 2766 err = -EIO;
2749 goto err_hw_init; 2767 goto err_hw_init;
2750 } 2768 }
@@ -2846,7 +2864,7 @@ static struct pci_error_handlers igbvf_err_handler = {
2846 .resume = igbvf_io_resume, 2864 .resume = igbvf_io_resume,
2847}; 2865};
2848 2866
2849static struct pci_device_id igbvf_pci_tbl[] = { 2867static DEFINE_PCI_DEVICE_TABLE(igbvf_pci_tbl) = {
2850 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_VF), board_vf }, 2868 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_VF), board_vf },
2851 { } /* terminate list */ 2869 { } /* terminate list */
2852}; 2870};