| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1 | /******************************************************************************* | 
|  | 2 |  | 
|  | 3 | Intel(R) 82576 Virtual Function Linux driver | 
|  | 4 | Copyright(c) 2009 Intel Corporation. | 
|  | 5 |  | 
|  | 6 | This program is free software; you can redistribute it and/or modify it | 
|  | 7 | under the terms and conditions of the GNU General Public License, | 
|  | 8 | version 2, as published by the Free Software Foundation. | 
|  | 9 |  | 
|  | 10 | This program is distributed in the hope it will be useful, but WITHOUT | 
|  | 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 
|  | 12 | FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for | 
|  | 13 | more details. | 
|  | 14 |  | 
|  | 15 | You should have received a copy of the GNU General Public License along with | 
|  | 16 | this program; if not, write to the Free Software Foundation, Inc., | 
|  | 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | 
|  | 18 |  | 
|  | 19 | The full GNU General Public License is included in this distribution in | 
|  | 20 | the file called "COPYING". | 
|  | 21 |  | 
|  | 22 | Contact Information: | 
|  | 23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | 
|  | 24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | 
|  | 25 |  | 
|  | 26 | *******************************************************************************/ | 
|  | 27 |  | 
|  | 28 | #include <linux/module.h> | 
|  | 29 | #include <linux/types.h> | 
|  | 30 | #include <linux/init.h> | 
|  | 31 | #include <linux/pci.h> | 
|  | 32 | #include <linux/vmalloc.h> | 
|  | 33 | #include <linux/pagemap.h> | 
|  | 34 | #include <linux/delay.h> | 
|  | 35 | #include <linux/netdevice.h> | 
|  | 36 | #include <linux/tcp.h> | 
|  | 37 | #include <linux/ipv6.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 38 | #include <linux/slab.h> | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 39 | #include <net/checksum.h> | 
|  | 40 | #include <net/ip6_checksum.h> | 
|  | 41 | #include <linux/mii.h> | 
|  | 42 | #include <linux/ethtool.h> | 
|  | 43 | #include <linux/if_vlan.h> | 
|  | 44 | #include <linux/pm_qos_params.h> | 
|  | 45 |  | 
|  | 46 | #include "igbvf.h" | 
|  | 47 |  | 
|  | 48 | #define DRV_VERSION "1.0.0-k0" | 
|  | 49 | char igbvf_driver_name[] = "igbvf"; | 
|  | 50 | const char igbvf_driver_version[] = DRV_VERSION; | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 51 | struct pm_qos_request_list *igbvf_driver_pm_qos_req; | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 52 | static const char igbvf_driver_string[] = | 
|  | 53 | "Intel(R) Virtual Function Network Driver"; | 
|  | 54 | static const char igbvf_copyright[] = "Copyright (c) 2009 Intel Corporation."; | 
|  | 55 |  | 
|  | 56 | static int igbvf_poll(struct napi_struct *napi, int budget); | 
| Alexander Duyck | 2d16577 | 2009-04-09 22:49:20 +0000 | [diff] [blame] | 57 | static void igbvf_reset(struct igbvf_adapter *); | 
|  | 58 | static void igbvf_set_interrupt_capability(struct igbvf_adapter *); | 
|  | 59 | static void igbvf_reset_interrupt_capability(struct igbvf_adapter *); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 60 |  | 
|  | 61 | static struct igbvf_info igbvf_vf_info = { | 
|  | 62 | .mac                    = e1000_vfadapt, | 
| Alexander Duyck | 0364d6f | 2009-05-06 10:25:01 +0000 | [diff] [blame] | 63 | .flags                  = 0, | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 64 | .pba                    = 10, | 
|  | 65 | .init_ops               = e1000_init_function_pointers_vf, | 
|  | 66 | }; | 
|  | 67 |  | 
|  | 68 | static const struct igbvf_info *igbvf_info_tbl[] = { | 
|  | 69 | [board_vf]              = &igbvf_vf_info, | 
|  | 70 | }; | 
|  | 71 |  | 
|  | 72 | /** | 
|  | 73 | * igbvf_desc_unused - calculate if we have unused descriptors | 
|  | 74 | **/ | 
|  | 75 | static int igbvf_desc_unused(struct igbvf_ring *ring) | 
|  | 76 | { | 
|  | 77 | if (ring->next_to_clean > ring->next_to_use) | 
|  | 78 | return ring->next_to_clean - ring->next_to_use - 1; | 
|  | 79 |  | 
|  | 80 | return ring->count + ring->next_to_clean - ring->next_to_use - 1; | 
|  | 81 | } | 
|  | 82 |  | 
|  | 83 | /** | 
|  | 84 | * igbvf_receive_skb - helper function to handle Rx indications | 
|  | 85 | * @adapter: board private structure | 
|  | 86 | * @status: descriptor status field as written by hardware | 
|  | 87 | * @vlan: descriptor vlan field as written by hardware (no le/be conversion) | 
|  | 88 | * @skb: pointer to sk_buff to be indicated to stack | 
|  | 89 | **/ | 
|  | 90 | static void igbvf_receive_skb(struct igbvf_adapter *adapter, | 
|  | 91 | struct net_device *netdev, | 
|  | 92 | struct sk_buff *skb, | 
|  | 93 | u32 status, u16 vlan) | 
|  | 94 | { | 
|  | 95 | if (adapter->vlgrp && (status & E1000_RXD_STAT_VP)) | 
|  | 96 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, | 
|  | 97 | le16_to_cpu(vlan) & | 
|  | 98 | E1000_RXD_SPC_VLAN_MASK); | 
|  | 99 | else | 
|  | 100 | netif_receive_skb(skb); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 101 | } | 
|  | 102 |  | 
|  | 103 | static inline void igbvf_rx_checksum_adv(struct igbvf_adapter *adapter, | 
|  | 104 | u32 status_err, struct sk_buff *skb) | 
|  | 105 | { | 
|  | 106 | skb->ip_summed = CHECKSUM_NONE; | 
|  | 107 |  | 
|  | 108 | /* Ignore Checksum bit is set or checksum is disabled through ethtool */ | 
| Alexander Duyck | 0364d6f | 2009-05-06 10:25:01 +0000 | [diff] [blame] | 109 | if ((status_err & E1000_RXD_STAT_IXSM) || | 
|  | 110 | (adapter->flags & IGBVF_FLAG_RX_CSUM_DISABLED)) | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 111 | return; | 
| Alexander Duyck | 0364d6f | 2009-05-06 10:25:01 +0000 | [diff] [blame] | 112 |  | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 113 | /* TCP/UDP checksum error bit is set */ | 
|  | 114 | if (status_err & | 
|  | 115 | (E1000_RXDEXT_STATERR_TCPE | E1000_RXDEXT_STATERR_IPE)) { | 
|  | 116 | /* let the stack verify checksum errors */ | 
|  | 117 | adapter->hw_csum_err++; | 
|  | 118 | return; | 
|  | 119 | } | 
| Alexander Duyck | 0364d6f | 2009-05-06 10:25:01 +0000 | [diff] [blame] | 120 |  | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 121 | /* It must be a TCP or UDP packet with a valid checksum */ | 
|  | 122 | if (status_err & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)) | 
|  | 123 | skb->ip_summed = CHECKSUM_UNNECESSARY; | 
|  | 124 |  | 
|  | 125 | adapter->hw_csum_good++; | 
|  | 126 | } | 
|  | 127 |  | 
|  | 128 | /** | 
|  | 129 | * igbvf_alloc_rx_buffers - Replace used receive buffers; packet split | 
|  | 130 | * @rx_ring: address of ring structure to repopulate | 
|  | 131 | * @cleaned_count: number of buffers to repopulate | 
|  | 132 | **/ | 
|  | 133 | static void igbvf_alloc_rx_buffers(struct igbvf_ring *rx_ring, | 
|  | 134 | int cleaned_count) | 
|  | 135 | { | 
|  | 136 | struct igbvf_adapter *adapter = rx_ring->adapter; | 
|  | 137 | struct net_device *netdev = adapter->netdev; | 
|  | 138 | struct pci_dev *pdev = adapter->pdev; | 
|  | 139 | union e1000_adv_rx_desc *rx_desc; | 
|  | 140 | struct igbvf_buffer *buffer_info; | 
|  | 141 | struct sk_buff *skb; | 
|  | 142 | unsigned int i; | 
|  | 143 | int bufsz; | 
|  | 144 |  | 
|  | 145 | i = rx_ring->next_to_use; | 
|  | 146 | buffer_info = &rx_ring->buffer_info[i]; | 
|  | 147 |  | 
|  | 148 | if (adapter->rx_ps_hdr_size) | 
|  | 149 | bufsz = adapter->rx_ps_hdr_size; | 
|  | 150 | else | 
|  | 151 | bufsz = adapter->rx_buffer_len; | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 152 |  | 
|  | 153 | while (cleaned_count--) { | 
|  | 154 | rx_desc = IGBVF_RX_DESC_ADV(*rx_ring, i); | 
|  | 155 |  | 
|  | 156 | if (adapter->rx_ps_hdr_size && !buffer_info->page_dma) { | 
|  | 157 | if (!buffer_info->page) { | 
|  | 158 | buffer_info->page = alloc_page(GFP_ATOMIC); | 
|  | 159 | if (!buffer_info->page) { | 
|  | 160 | adapter->alloc_rx_buff_failed++; | 
|  | 161 | goto no_buffers; | 
|  | 162 | } | 
|  | 163 | buffer_info->page_offset = 0; | 
|  | 164 | } else { | 
|  | 165 | buffer_info->page_offset ^= PAGE_SIZE / 2; | 
|  | 166 | } | 
|  | 167 | buffer_info->page_dma = | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 168 | dma_map_page(&pdev->dev, buffer_info->page, | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 169 | buffer_info->page_offset, | 
|  | 170 | PAGE_SIZE / 2, | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 171 | DMA_FROM_DEVICE); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 172 | } | 
|  | 173 |  | 
|  | 174 | if (!buffer_info->skb) { | 
| Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 175 | skb = netdev_alloc_skb_ip_align(netdev, bufsz); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 176 | if (!skb) { | 
|  | 177 | adapter->alloc_rx_buff_failed++; | 
|  | 178 | goto no_buffers; | 
|  | 179 | } | 
|  | 180 |  | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 181 | buffer_info->skb = skb; | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 182 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 183 | bufsz, | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 184 | DMA_FROM_DEVICE); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 185 | } | 
|  | 186 | /* Refresh the desc even if buffer_addrs didn't change because | 
|  | 187 | * each write-back erases this info. */ | 
|  | 188 | if (adapter->rx_ps_hdr_size) { | 
|  | 189 | rx_desc->read.pkt_addr = | 
|  | 190 | cpu_to_le64(buffer_info->page_dma); | 
|  | 191 | rx_desc->read.hdr_addr = cpu_to_le64(buffer_info->dma); | 
|  | 192 | } else { | 
|  | 193 | rx_desc->read.pkt_addr = | 
|  | 194 | cpu_to_le64(buffer_info->dma); | 
|  | 195 | rx_desc->read.hdr_addr = 0; | 
|  | 196 | } | 
|  | 197 |  | 
|  | 198 | i++; | 
|  | 199 | if (i == rx_ring->count) | 
|  | 200 | i = 0; | 
|  | 201 | buffer_info = &rx_ring->buffer_info[i]; | 
|  | 202 | } | 
|  | 203 |  | 
|  | 204 | no_buffers: | 
|  | 205 | if (rx_ring->next_to_use != i) { | 
|  | 206 | rx_ring->next_to_use = i; | 
|  | 207 | if (i == 0) | 
|  | 208 | i = (rx_ring->count - 1); | 
|  | 209 | else | 
|  | 210 | i--; | 
|  | 211 |  | 
|  | 212 | /* Force memory writes to complete before letting h/w | 
|  | 213 | * know there are new descriptors to fetch.  (Only | 
|  | 214 | * applicable for weak-ordered memory model archs, | 
|  | 215 | * such as IA-64). */ | 
|  | 216 | wmb(); | 
|  | 217 | writel(i, adapter->hw.hw_addr + rx_ring->tail); | 
|  | 218 | } | 
|  | 219 | } | 
|  | 220 |  | 
|  | 221 | /** | 
|  | 222 | * igbvf_clean_rx_irq - Send received data up the network stack; legacy | 
|  | 223 | * @adapter: board private structure | 
|  | 224 | * | 
|  | 225 | * the return value indicates whether actual cleaning was done, there | 
|  | 226 | * is no guarantee that everything was cleaned | 
|  | 227 | **/ | 
|  | 228 | static bool igbvf_clean_rx_irq(struct igbvf_adapter *adapter, | 
|  | 229 | int *work_done, int work_to_do) | 
|  | 230 | { | 
|  | 231 | struct igbvf_ring *rx_ring = adapter->rx_ring; | 
|  | 232 | struct net_device *netdev = adapter->netdev; | 
|  | 233 | struct pci_dev *pdev = adapter->pdev; | 
|  | 234 | union e1000_adv_rx_desc *rx_desc, *next_rxd; | 
|  | 235 | struct igbvf_buffer *buffer_info, *next_buffer; | 
|  | 236 | struct sk_buff *skb; | 
|  | 237 | bool cleaned = false; | 
|  | 238 | int cleaned_count = 0; | 
|  | 239 | unsigned int total_bytes = 0, total_packets = 0; | 
|  | 240 | unsigned int i; | 
|  | 241 | u32 length, hlen, staterr; | 
|  | 242 |  | 
|  | 243 | i = rx_ring->next_to_clean; | 
|  | 244 | rx_desc = IGBVF_RX_DESC_ADV(*rx_ring, i); | 
|  | 245 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); | 
|  | 246 |  | 
|  | 247 | while (staterr & E1000_RXD_STAT_DD) { | 
|  | 248 | if (*work_done >= work_to_do) | 
|  | 249 | break; | 
|  | 250 | (*work_done)++; | 
|  | 251 |  | 
|  | 252 | buffer_info = &rx_ring->buffer_info[i]; | 
|  | 253 |  | 
|  | 254 | /* HW will not DMA in data larger than the given buffer, even | 
|  | 255 | * if it parses the (NFS, of course) header to be larger.  In | 
|  | 256 | * that case, it fills the header buffer and spills the rest | 
|  | 257 | * into the page. | 
|  | 258 | */ | 
|  | 259 | hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info) & | 
|  | 260 | E1000_RXDADV_HDRBUFLEN_MASK) >> E1000_RXDADV_HDRBUFLEN_SHIFT; | 
|  | 261 | if (hlen > adapter->rx_ps_hdr_size) | 
|  | 262 | hlen = adapter->rx_ps_hdr_size; | 
|  | 263 |  | 
|  | 264 | length = le16_to_cpu(rx_desc->wb.upper.length); | 
|  | 265 | cleaned = true; | 
|  | 266 | cleaned_count++; | 
|  | 267 |  | 
|  | 268 | skb = buffer_info->skb; | 
|  | 269 | prefetch(skb->data - NET_IP_ALIGN); | 
|  | 270 | buffer_info->skb = NULL; | 
|  | 271 | if (!adapter->rx_ps_hdr_size) { | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 272 | dma_unmap_single(&pdev->dev, buffer_info->dma, | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 273 | adapter->rx_buffer_len, | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 274 | DMA_FROM_DEVICE); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 275 | buffer_info->dma = 0; | 
|  | 276 | skb_put(skb, length); | 
|  | 277 | goto send_up; | 
|  | 278 | } | 
|  | 279 |  | 
|  | 280 | if (!skb_shinfo(skb)->nr_frags) { | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 281 | dma_unmap_single(&pdev->dev, buffer_info->dma, | 
| Alexander Duyck | 92d947b | 2009-07-23 18:11:01 +0000 | [diff] [blame] | 282 | adapter->rx_ps_hdr_size, | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 283 | DMA_FROM_DEVICE); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 284 | skb_put(skb, hlen); | 
|  | 285 | } | 
|  | 286 |  | 
|  | 287 | if (length) { | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 288 | dma_unmap_page(&pdev->dev, buffer_info->page_dma, | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 289 | PAGE_SIZE / 2, | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 290 | DMA_FROM_DEVICE); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 291 | buffer_info->page_dma = 0; | 
|  | 292 |  | 
| Koki Sanagi | ec857fd | 2010-04-27 01:01:39 +0000 | [diff] [blame] | 293 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 294 | buffer_info->page, | 
|  | 295 | buffer_info->page_offset, | 
|  | 296 | length); | 
|  | 297 |  | 
|  | 298 | if ((adapter->rx_buffer_len > (PAGE_SIZE / 2)) || | 
|  | 299 | (page_count(buffer_info->page) != 1)) | 
|  | 300 | buffer_info->page = NULL; | 
|  | 301 | else | 
|  | 302 | get_page(buffer_info->page); | 
|  | 303 |  | 
|  | 304 | skb->len += length; | 
|  | 305 | skb->data_len += length; | 
|  | 306 | skb->truesize += length; | 
|  | 307 | } | 
|  | 308 | send_up: | 
|  | 309 | i++; | 
|  | 310 | if (i == rx_ring->count) | 
|  | 311 | i = 0; | 
|  | 312 | next_rxd = IGBVF_RX_DESC_ADV(*rx_ring, i); | 
|  | 313 | prefetch(next_rxd); | 
|  | 314 | next_buffer = &rx_ring->buffer_info[i]; | 
|  | 315 |  | 
|  | 316 | if (!(staterr & E1000_RXD_STAT_EOP)) { | 
|  | 317 | buffer_info->skb = next_buffer->skb; | 
|  | 318 | buffer_info->dma = next_buffer->dma; | 
|  | 319 | next_buffer->skb = skb; | 
|  | 320 | next_buffer->dma = 0; | 
|  | 321 | goto next_desc; | 
|  | 322 | } | 
|  | 323 |  | 
|  | 324 | if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) { | 
|  | 325 | dev_kfree_skb_irq(skb); | 
|  | 326 | goto next_desc; | 
|  | 327 | } | 
|  | 328 |  | 
|  | 329 | total_bytes += skb->len; | 
|  | 330 | total_packets++; | 
|  | 331 |  | 
|  | 332 | igbvf_rx_checksum_adv(adapter, staterr, skb); | 
|  | 333 |  | 
|  | 334 | skb->protocol = eth_type_trans(skb, netdev); | 
|  | 335 |  | 
|  | 336 | igbvf_receive_skb(adapter, netdev, skb, staterr, | 
|  | 337 | rx_desc->wb.upper.vlan); | 
|  | 338 |  | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 339 | next_desc: | 
|  | 340 | rx_desc->wb.upper.status_error = 0; | 
|  | 341 |  | 
|  | 342 | /* return some buffers to hardware, one at a time is too slow */ | 
|  | 343 | if (cleaned_count >= IGBVF_RX_BUFFER_WRITE) { | 
|  | 344 | igbvf_alloc_rx_buffers(rx_ring, cleaned_count); | 
|  | 345 | cleaned_count = 0; | 
|  | 346 | } | 
|  | 347 |  | 
|  | 348 | /* use prefetched values */ | 
|  | 349 | rx_desc = next_rxd; | 
|  | 350 | buffer_info = next_buffer; | 
|  | 351 |  | 
|  | 352 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); | 
|  | 353 | } | 
|  | 354 |  | 
|  | 355 | rx_ring->next_to_clean = i; | 
|  | 356 | cleaned_count = igbvf_desc_unused(rx_ring); | 
|  | 357 |  | 
|  | 358 | if (cleaned_count) | 
|  | 359 | igbvf_alloc_rx_buffers(rx_ring, cleaned_count); | 
|  | 360 |  | 
|  | 361 | adapter->total_rx_packets += total_packets; | 
|  | 362 | adapter->total_rx_bytes += total_bytes; | 
|  | 363 | adapter->net_stats.rx_bytes += total_bytes; | 
|  | 364 | adapter->net_stats.rx_packets += total_packets; | 
|  | 365 | return cleaned; | 
|  | 366 | } | 
|  | 367 |  | 
|  | 368 | static void igbvf_put_txbuf(struct igbvf_adapter *adapter, | 
|  | 369 | struct igbvf_buffer *buffer_info) | 
|  | 370 | { | 
| Alexander Duyck | a7d5ca4 | 2009-12-02 16:47:37 +0000 | [diff] [blame] | 371 | if (buffer_info->dma) { | 
|  | 372 | if (buffer_info->mapped_as_page) | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 373 | dma_unmap_page(&adapter->pdev->dev, | 
| Alexander Duyck | a7d5ca4 | 2009-12-02 16:47:37 +0000 | [diff] [blame] | 374 | buffer_info->dma, | 
|  | 375 | buffer_info->length, | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 376 | DMA_TO_DEVICE); | 
| Alexander Duyck | a7d5ca4 | 2009-12-02 16:47:37 +0000 | [diff] [blame] | 377 | else | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 378 | dma_unmap_single(&adapter->pdev->dev, | 
| Alexander Duyck | a7d5ca4 | 2009-12-02 16:47:37 +0000 | [diff] [blame] | 379 | buffer_info->dma, | 
|  | 380 | buffer_info->length, | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 381 | DMA_TO_DEVICE); | 
| Alexander Duyck | a7d5ca4 | 2009-12-02 16:47:37 +0000 | [diff] [blame] | 382 | buffer_info->dma = 0; | 
|  | 383 | } | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 384 | if (buffer_info->skb) { | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 385 | dev_kfree_skb_any(buffer_info->skb); | 
|  | 386 | buffer_info->skb = NULL; | 
|  | 387 | } | 
|  | 388 | buffer_info->time_stamp = 0; | 
|  | 389 | } | 
|  | 390 |  | 
|  | 391 | static void igbvf_print_tx_hang(struct igbvf_adapter *adapter) | 
|  | 392 | { | 
|  | 393 | struct igbvf_ring *tx_ring = adapter->tx_ring; | 
|  | 394 | unsigned int i = tx_ring->next_to_clean; | 
|  | 395 | unsigned int eop = tx_ring->buffer_info[i].next_to_watch; | 
|  | 396 | union e1000_adv_tx_desc *eop_desc = IGBVF_TX_DESC_ADV(*tx_ring, eop); | 
|  | 397 |  | 
|  | 398 | /* detected Tx unit hang */ | 
|  | 399 | dev_err(&adapter->pdev->dev, | 
|  | 400 | "Detected Tx Unit Hang:\n" | 
|  | 401 | "  TDH                  <%x>\n" | 
|  | 402 | "  TDT                  <%x>\n" | 
|  | 403 | "  next_to_use          <%x>\n" | 
|  | 404 | "  next_to_clean        <%x>\n" | 
|  | 405 | "buffer_info[next_to_clean]:\n" | 
|  | 406 | "  time_stamp           <%lx>\n" | 
|  | 407 | "  next_to_watch        <%x>\n" | 
|  | 408 | "  jiffies              <%lx>\n" | 
|  | 409 | "  next_to_watch.status <%x>\n", | 
|  | 410 | readl(adapter->hw.hw_addr + tx_ring->head), | 
|  | 411 | readl(adapter->hw.hw_addr + tx_ring->tail), | 
|  | 412 | tx_ring->next_to_use, | 
|  | 413 | tx_ring->next_to_clean, | 
|  | 414 | tx_ring->buffer_info[eop].time_stamp, | 
|  | 415 | eop, | 
|  | 416 | jiffies, | 
|  | 417 | eop_desc->wb.status); | 
|  | 418 | } | 
|  | 419 |  | 
|  | 420 | /** | 
|  | 421 | * igbvf_setup_tx_resources - allocate Tx resources (Descriptors) | 
|  | 422 | * @adapter: board private structure | 
|  | 423 | * | 
|  | 424 | * Return 0 on success, negative on failure | 
|  | 425 | **/ | 
|  | 426 | int igbvf_setup_tx_resources(struct igbvf_adapter *adapter, | 
|  | 427 | struct igbvf_ring *tx_ring) | 
|  | 428 | { | 
|  | 429 | struct pci_dev *pdev = adapter->pdev; | 
|  | 430 | int size; | 
|  | 431 |  | 
|  | 432 | size = sizeof(struct igbvf_buffer) * tx_ring->count; | 
|  | 433 | tx_ring->buffer_info = vmalloc(size); | 
|  | 434 | if (!tx_ring->buffer_info) | 
|  | 435 | goto err; | 
|  | 436 | memset(tx_ring->buffer_info, 0, size); | 
|  | 437 |  | 
|  | 438 | /* round up to nearest 4K */ | 
|  | 439 | tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc); | 
|  | 440 | tx_ring->size = ALIGN(tx_ring->size, 4096); | 
|  | 441 |  | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 442 | tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size, | 
|  | 443 | &tx_ring->dma, GFP_KERNEL); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 444 |  | 
|  | 445 | if (!tx_ring->desc) | 
|  | 446 | goto err; | 
|  | 447 |  | 
|  | 448 | tx_ring->adapter = adapter; | 
|  | 449 | tx_ring->next_to_use = 0; | 
|  | 450 | tx_ring->next_to_clean = 0; | 
|  | 451 |  | 
|  | 452 | return 0; | 
|  | 453 | err: | 
|  | 454 | vfree(tx_ring->buffer_info); | 
|  | 455 | dev_err(&adapter->pdev->dev, | 
|  | 456 | "Unable to allocate memory for the transmit descriptor ring\n"); | 
|  | 457 | return -ENOMEM; | 
|  | 458 | } | 
|  | 459 |  | 
|  | 460 | /** | 
|  | 461 | * igbvf_setup_rx_resources - allocate Rx resources (Descriptors) | 
|  | 462 | * @adapter: board private structure | 
|  | 463 | * | 
|  | 464 | * Returns 0 on success, negative on failure | 
|  | 465 | **/ | 
|  | 466 | int igbvf_setup_rx_resources(struct igbvf_adapter *adapter, | 
|  | 467 | struct igbvf_ring *rx_ring) | 
|  | 468 | { | 
|  | 469 | struct pci_dev *pdev = adapter->pdev; | 
|  | 470 | int size, desc_len; | 
|  | 471 |  | 
|  | 472 | size = sizeof(struct igbvf_buffer) * rx_ring->count; | 
|  | 473 | rx_ring->buffer_info = vmalloc(size); | 
|  | 474 | if (!rx_ring->buffer_info) | 
|  | 475 | goto err; | 
|  | 476 | memset(rx_ring->buffer_info, 0, size); | 
|  | 477 |  | 
|  | 478 | desc_len = sizeof(union e1000_adv_rx_desc); | 
|  | 479 |  | 
|  | 480 | /* Round up to nearest 4K */ | 
|  | 481 | rx_ring->size = rx_ring->count * desc_len; | 
|  | 482 | rx_ring->size = ALIGN(rx_ring->size, 4096); | 
|  | 483 |  | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 484 | rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size, | 
|  | 485 | &rx_ring->dma, GFP_KERNEL); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 486 |  | 
|  | 487 | if (!rx_ring->desc) | 
|  | 488 | goto err; | 
|  | 489 |  | 
|  | 490 | rx_ring->next_to_clean = 0; | 
|  | 491 | rx_ring->next_to_use = 0; | 
|  | 492 |  | 
|  | 493 | rx_ring->adapter = adapter; | 
|  | 494 |  | 
|  | 495 | return 0; | 
|  | 496 |  | 
|  | 497 | err: | 
|  | 498 | vfree(rx_ring->buffer_info); | 
|  | 499 | rx_ring->buffer_info = NULL; | 
|  | 500 | dev_err(&adapter->pdev->dev, | 
|  | 501 | "Unable to allocate memory for the receive descriptor ring\n"); | 
|  | 502 | return -ENOMEM; | 
|  | 503 | } | 
|  | 504 |  | 
|  | 505 | /** | 
|  | 506 | * igbvf_clean_tx_ring - Free Tx Buffers | 
|  | 507 | * @tx_ring: ring to be cleaned | 
|  | 508 | **/ | 
|  | 509 | static void igbvf_clean_tx_ring(struct igbvf_ring *tx_ring) | 
|  | 510 | { | 
|  | 511 | struct igbvf_adapter *adapter = tx_ring->adapter; | 
|  | 512 | struct igbvf_buffer *buffer_info; | 
|  | 513 | unsigned long size; | 
|  | 514 | unsigned int i; | 
|  | 515 |  | 
|  | 516 | if (!tx_ring->buffer_info) | 
|  | 517 | return; | 
|  | 518 |  | 
|  | 519 | /* Free all the Tx ring sk_buffs */ | 
|  | 520 | for (i = 0; i < tx_ring->count; i++) { | 
|  | 521 | buffer_info = &tx_ring->buffer_info[i]; | 
|  | 522 | igbvf_put_txbuf(adapter, buffer_info); | 
|  | 523 | } | 
|  | 524 |  | 
|  | 525 | size = sizeof(struct igbvf_buffer) * tx_ring->count; | 
|  | 526 | memset(tx_ring->buffer_info, 0, size); | 
|  | 527 |  | 
|  | 528 | /* Zero out the descriptor ring */ | 
|  | 529 | memset(tx_ring->desc, 0, tx_ring->size); | 
|  | 530 |  | 
|  | 531 | tx_ring->next_to_use = 0; | 
|  | 532 | tx_ring->next_to_clean = 0; | 
|  | 533 |  | 
|  | 534 | writel(0, adapter->hw.hw_addr + tx_ring->head); | 
|  | 535 | writel(0, adapter->hw.hw_addr + tx_ring->tail); | 
|  | 536 | } | 
|  | 537 |  | 
|  | 538 | /** | 
|  | 539 | * igbvf_free_tx_resources - Free Tx Resources per Queue | 
|  | 540 | * @tx_ring: ring to free resources from | 
|  | 541 | * | 
|  | 542 | * Free all transmit software resources | 
|  | 543 | **/ | 
|  | 544 | void igbvf_free_tx_resources(struct igbvf_ring *tx_ring) | 
|  | 545 | { | 
|  | 546 | struct pci_dev *pdev = tx_ring->adapter->pdev; | 
|  | 547 |  | 
|  | 548 | igbvf_clean_tx_ring(tx_ring); | 
|  | 549 |  | 
|  | 550 | vfree(tx_ring->buffer_info); | 
|  | 551 | tx_ring->buffer_info = NULL; | 
|  | 552 |  | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 553 | dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, | 
|  | 554 | tx_ring->dma); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 555 |  | 
|  | 556 | tx_ring->desc = NULL; | 
|  | 557 | } | 
|  | 558 |  | 
|  | 559 | /** | 
|  | 560 | * igbvf_clean_rx_ring - Free Rx Buffers per Queue | 
|  | 561 | * @adapter: board private structure | 
|  | 562 | **/ | 
|  | 563 | static void igbvf_clean_rx_ring(struct igbvf_ring *rx_ring) | 
|  | 564 | { | 
|  | 565 | struct igbvf_adapter *adapter = rx_ring->adapter; | 
|  | 566 | struct igbvf_buffer *buffer_info; | 
|  | 567 | struct pci_dev *pdev = adapter->pdev; | 
|  | 568 | unsigned long size; | 
|  | 569 | unsigned int i; | 
|  | 570 |  | 
|  | 571 | if (!rx_ring->buffer_info) | 
|  | 572 | return; | 
|  | 573 |  | 
|  | 574 | /* Free all the Rx ring sk_buffs */ | 
|  | 575 | for (i = 0; i < rx_ring->count; i++) { | 
|  | 576 | buffer_info = &rx_ring->buffer_info[i]; | 
|  | 577 | if (buffer_info->dma) { | 
|  | 578 | if (adapter->rx_ps_hdr_size){ | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 579 | dma_unmap_single(&pdev->dev, buffer_info->dma, | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 580 | adapter->rx_ps_hdr_size, | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 581 | DMA_FROM_DEVICE); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 582 | } else { | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 583 | dma_unmap_single(&pdev->dev, buffer_info->dma, | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 584 | adapter->rx_buffer_len, | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 585 | DMA_FROM_DEVICE); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 586 | } | 
|  | 587 | buffer_info->dma = 0; | 
|  | 588 | } | 
|  | 589 |  | 
|  | 590 | if (buffer_info->skb) { | 
|  | 591 | dev_kfree_skb(buffer_info->skb); | 
|  | 592 | buffer_info->skb = NULL; | 
|  | 593 | } | 
|  | 594 |  | 
|  | 595 | if (buffer_info->page) { | 
|  | 596 | if (buffer_info->page_dma) | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 597 | dma_unmap_page(&pdev->dev, | 
|  | 598 | buffer_info->page_dma, | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 599 | PAGE_SIZE / 2, | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 600 | DMA_FROM_DEVICE); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 601 | put_page(buffer_info->page); | 
|  | 602 | buffer_info->page = NULL; | 
|  | 603 | buffer_info->page_dma = 0; | 
|  | 604 | buffer_info->page_offset = 0; | 
|  | 605 | } | 
|  | 606 | } | 
|  | 607 |  | 
|  | 608 | size = sizeof(struct igbvf_buffer) * rx_ring->count; | 
|  | 609 | memset(rx_ring->buffer_info, 0, size); | 
|  | 610 |  | 
|  | 611 | /* Zero out the descriptor ring */ | 
|  | 612 | memset(rx_ring->desc, 0, rx_ring->size); | 
|  | 613 |  | 
|  | 614 | rx_ring->next_to_clean = 0; | 
|  | 615 | rx_ring->next_to_use = 0; | 
|  | 616 |  | 
|  | 617 | writel(0, adapter->hw.hw_addr + rx_ring->head); | 
|  | 618 | writel(0, adapter->hw.hw_addr + rx_ring->tail); | 
|  | 619 | } | 
|  | 620 |  | 
|  | 621 | /** | 
|  | 622 | * igbvf_free_rx_resources - Free Rx Resources | 
|  | 623 | * @rx_ring: ring to clean the resources from | 
|  | 624 | * | 
|  | 625 | * Free all receive software resources | 
|  | 626 | **/ | 
|  | 627 |  | 
|  | 628 | void igbvf_free_rx_resources(struct igbvf_ring *rx_ring) | 
|  | 629 | { | 
|  | 630 | struct pci_dev *pdev = rx_ring->adapter->pdev; | 
|  | 631 |  | 
|  | 632 | igbvf_clean_rx_ring(rx_ring); | 
|  | 633 |  | 
|  | 634 | vfree(rx_ring->buffer_info); | 
|  | 635 | rx_ring->buffer_info = NULL; | 
|  | 636 |  | 
|  | 637 | dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, | 
|  | 638 | rx_ring->dma); | 
|  | 639 | rx_ring->desc = NULL; | 
|  | 640 | } | 
|  | 641 |  | 
|  | 642 | /** | 
|  | 643 | * igbvf_update_itr - update the dynamic ITR value based on statistics | 
|  | 644 | * @adapter: pointer to adapter | 
|  | 645 | * @itr_setting: current adapter->itr | 
|  | 646 | * @packets: the number of packets during this measurement interval | 
|  | 647 | * @bytes: the number of bytes during this measurement interval | 
|  | 648 | * | 
|  | 649 | *      Stores a new ITR value based on packets and byte | 
|  | 650 | *      counts during the last interrupt.  The advantage of per interrupt | 
|  | 651 | *      computation is faster updates and more accurate ITR for the current | 
|  | 652 | *      traffic pattern.  Constants in this function were computed | 
|  | 653 | *      based on theoretical maximum wire speed and thresholds were set based | 
|  | 654 | *      on testing data as well as attempting to minimize response time | 
|  | 655 | *      while increasing bulk throughput.  This functionality is controlled | 
|  | 656 | *      by the InterruptThrottleRate module parameter. | 
|  | 657 | **/ | 
|  | 658 | static unsigned int igbvf_update_itr(struct igbvf_adapter *adapter, | 
|  | 659 | u16 itr_setting, int packets, | 
|  | 660 | int bytes) | 
|  | 661 | { | 
|  | 662 | unsigned int retval = itr_setting; | 
|  | 663 |  | 
|  | 664 | if (packets == 0) | 
|  | 665 | goto update_itr_done; | 
|  | 666 |  | 
|  | 667 | switch (itr_setting) { | 
|  | 668 | case lowest_latency: | 
|  | 669 | /* handle TSO and jumbo frames */ | 
|  | 670 | if (bytes/packets > 8000) | 
|  | 671 | retval = bulk_latency; | 
|  | 672 | else if ((packets < 5) && (bytes > 512)) | 
|  | 673 | retval = low_latency; | 
|  | 674 | break; | 
|  | 675 | case low_latency:  /* 50 usec aka 20000 ints/s */ | 
|  | 676 | if (bytes > 10000) { | 
|  | 677 | /* this if handles the TSO accounting */ | 
|  | 678 | if (bytes/packets > 8000) | 
|  | 679 | retval = bulk_latency; | 
|  | 680 | else if ((packets < 10) || ((bytes/packets) > 1200)) | 
|  | 681 | retval = bulk_latency; | 
|  | 682 | else if ((packets > 35)) | 
|  | 683 | retval = lowest_latency; | 
|  | 684 | } else if (bytes/packets > 2000) { | 
|  | 685 | retval = bulk_latency; | 
|  | 686 | } else if (packets <= 2 && bytes < 512) { | 
|  | 687 | retval = lowest_latency; | 
|  | 688 | } | 
|  | 689 | break; | 
|  | 690 | case bulk_latency: /* 250 usec aka 4000 ints/s */ | 
|  | 691 | if (bytes > 25000) { | 
|  | 692 | if (packets > 35) | 
|  | 693 | retval = low_latency; | 
|  | 694 | } else if (bytes < 6000) { | 
|  | 695 | retval = low_latency; | 
|  | 696 | } | 
|  | 697 | break; | 
|  | 698 | } | 
|  | 699 |  | 
|  | 700 | update_itr_done: | 
|  | 701 | return retval; | 
|  | 702 | } | 
|  | 703 |  | 
|  | 704 | static void igbvf_set_itr(struct igbvf_adapter *adapter) | 
|  | 705 | { | 
|  | 706 | struct e1000_hw *hw = &adapter->hw; | 
|  | 707 | u16 current_itr; | 
|  | 708 | u32 new_itr = adapter->itr; | 
|  | 709 |  | 
|  | 710 | adapter->tx_itr = igbvf_update_itr(adapter, adapter->tx_itr, | 
|  | 711 | adapter->total_tx_packets, | 
|  | 712 | adapter->total_tx_bytes); | 
|  | 713 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ | 
|  | 714 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) | 
|  | 715 | adapter->tx_itr = low_latency; | 
|  | 716 |  | 
|  | 717 | adapter->rx_itr = igbvf_update_itr(adapter, adapter->rx_itr, | 
|  | 718 | adapter->total_rx_packets, | 
|  | 719 | adapter->total_rx_bytes); | 
|  | 720 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ | 
|  | 721 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) | 
|  | 722 | adapter->rx_itr = low_latency; | 
|  | 723 |  | 
|  | 724 | current_itr = max(adapter->rx_itr, adapter->tx_itr); | 
|  | 725 |  | 
|  | 726 | switch (current_itr) { | 
|  | 727 | /* counts and packets in update_itr are dependent on these numbers */ | 
|  | 728 | case lowest_latency: | 
|  | 729 | new_itr = 70000; | 
|  | 730 | break; | 
|  | 731 | case low_latency: | 
|  | 732 | new_itr = 20000; /* aka hwitr = ~200 */ | 
|  | 733 | break; | 
|  | 734 | case bulk_latency: | 
|  | 735 | new_itr = 4000; | 
|  | 736 | break; | 
|  | 737 | default: | 
|  | 738 | break; | 
|  | 739 | } | 
|  | 740 |  | 
|  | 741 | if (new_itr != adapter->itr) { | 
|  | 742 | /* | 
|  | 743 | * this attempts to bias the interrupt rate towards Bulk | 
|  | 744 | * by adding intermediate steps when interrupt rate is | 
|  | 745 | * increasing | 
|  | 746 | */ | 
|  | 747 | new_itr = new_itr > adapter->itr ? | 
|  | 748 | min(adapter->itr + (new_itr >> 2), new_itr) : | 
|  | 749 | new_itr; | 
|  | 750 | adapter->itr = new_itr; | 
|  | 751 | adapter->rx_ring->itr_val = 1952; | 
|  | 752 |  | 
|  | 753 | if (adapter->msix_entries) | 
|  | 754 | adapter->rx_ring->set_itr = 1; | 
|  | 755 | else | 
|  | 756 | ew32(ITR, 1952); | 
|  | 757 | } | 
|  | 758 | } | 
|  | 759 |  | 
|  | 760 | /** | 
|  | 761 | * igbvf_clean_tx_irq - Reclaim resources after transmit completes | 
|  | 762 | * @adapter: board private structure | 
|  | 763 | * returns true if ring is completely cleaned | 
|  | 764 | **/ | 
|  | 765 | static bool igbvf_clean_tx_irq(struct igbvf_ring *tx_ring) | 
|  | 766 | { | 
|  | 767 | struct igbvf_adapter *adapter = tx_ring->adapter; | 
|  | 768 | struct e1000_hw *hw = &adapter->hw; | 
|  | 769 | struct net_device *netdev = adapter->netdev; | 
|  | 770 | struct igbvf_buffer *buffer_info; | 
|  | 771 | struct sk_buff *skb; | 
|  | 772 | union e1000_adv_tx_desc *tx_desc, *eop_desc; | 
|  | 773 | unsigned int total_bytes = 0, total_packets = 0; | 
|  | 774 | unsigned int i, eop, count = 0; | 
|  | 775 | bool cleaned = false; | 
|  | 776 |  | 
|  | 777 | i = tx_ring->next_to_clean; | 
|  | 778 | eop = tx_ring->buffer_info[i].next_to_watch; | 
|  | 779 | eop_desc = IGBVF_TX_DESC_ADV(*tx_ring, eop); | 
|  | 780 |  | 
|  | 781 | while ((eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)) && | 
|  | 782 | (count < tx_ring->count)) { | 
|  | 783 | for (cleaned = false; !cleaned; count++) { | 
|  | 784 | tx_desc = IGBVF_TX_DESC_ADV(*tx_ring, i); | 
|  | 785 | buffer_info = &tx_ring->buffer_info[i]; | 
|  | 786 | cleaned = (i == eop); | 
|  | 787 | skb = buffer_info->skb; | 
|  | 788 |  | 
|  | 789 | if (skb) { | 
|  | 790 | unsigned int segs, bytecount; | 
|  | 791 |  | 
|  | 792 | /* gso_segs is currently only valid for tcp */ | 
|  | 793 | segs = skb_shinfo(skb)->gso_segs ?: 1; | 
|  | 794 | /* multiply data chunks by size of headers */ | 
|  | 795 | bytecount = ((segs - 1) * skb_headlen(skb)) + | 
|  | 796 | skb->len; | 
|  | 797 | total_packets += segs; | 
|  | 798 | total_bytes += bytecount; | 
|  | 799 | } | 
|  | 800 |  | 
|  | 801 | igbvf_put_txbuf(adapter, buffer_info); | 
|  | 802 | tx_desc->wb.status = 0; | 
|  | 803 |  | 
|  | 804 | i++; | 
|  | 805 | if (i == tx_ring->count) | 
|  | 806 | i = 0; | 
|  | 807 | } | 
|  | 808 | eop = tx_ring->buffer_info[i].next_to_watch; | 
|  | 809 | eop_desc = IGBVF_TX_DESC_ADV(*tx_ring, eop); | 
|  | 810 | } | 
|  | 811 |  | 
|  | 812 | tx_ring->next_to_clean = i; | 
|  | 813 |  | 
|  | 814 | if (unlikely(count && | 
|  | 815 | netif_carrier_ok(netdev) && | 
|  | 816 | igbvf_desc_unused(tx_ring) >= IGBVF_TX_QUEUE_WAKE)) { | 
|  | 817 | /* Make sure that anybody stopping the queue after this | 
|  | 818 | * sees the new next_to_clean. | 
|  | 819 | */ | 
|  | 820 | smp_mb(); | 
|  | 821 | if (netif_queue_stopped(netdev) && | 
|  | 822 | !(test_bit(__IGBVF_DOWN, &adapter->state))) { | 
|  | 823 | netif_wake_queue(netdev); | 
|  | 824 | ++adapter->restart_queue; | 
|  | 825 | } | 
|  | 826 | } | 
|  | 827 |  | 
|  | 828 | if (adapter->detect_tx_hung) { | 
|  | 829 | /* Detect a transmit hang in hardware, this serializes the | 
|  | 830 | * check with the clearing of time_stamp and movement of i */ | 
|  | 831 | adapter->detect_tx_hung = false; | 
|  | 832 | if (tx_ring->buffer_info[i].time_stamp && | 
|  | 833 | time_after(jiffies, tx_ring->buffer_info[i].time_stamp + | 
| Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 834 | (adapter->tx_timeout_factor * HZ)) && | 
|  | 835 | !(er32(STATUS) & E1000_STATUS_TXOFF)) { | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 836 |  | 
|  | 837 | tx_desc = IGBVF_TX_DESC_ADV(*tx_ring, i); | 
|  | 838 | /* detected Tx unit hang */ | 
|  | 839 | igbvf_print_tx_hang(adapter); | 
|  | 840 |  | 
|  | 841 | netif_stop_queue(netdev); | 
|  | 842 | } | 
|  | 843 | } | 
|  | 844 | adapter->net_stats.tx_bytes += total_bytes; | 
|  | 845 | adapter->net_stats.tx_packets += total_packets; | 
|  | 846 | return (count < tx_ring->count); | 
|  | 847 | } | 
|  | 848 |  | 
|  | 849 | static irqreturn_t igbvf_msix_other(int irq, void *data) | 
|  | 850 | { | 
|  | 851 | struct net_device *netdev = data; | 
|  | 852 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 853 | struct e1000_hw *hw = &adapter->hw; | 
|  | 854 |  | 
|  | 855 | adapter->int_counter1++; | 
|  | 856 |  | 
|  | 857 | netif_carrier_off(netdev); | 
|  | 858 | hw->mac.get_link_status = 1; | 
|  | 859 | if (!test_bit(__IGBVF_DOWN, &adapter->state)) | 
|  | 860 | mod_timer(&adapter->watchdog_timer, jiffies + 1); | 
|  | 861 |  | 
|  | 862 | ew32(EIMS, adapter->eims_other); | 
|  | 863 |  | 
|  | 864 | return IRQ_HANDLED; | 
|  | 865 | } | 
|  | 866 |  | 
|  | 867 | static irqreturn_t igbvf_intr_msix_tx(int irq, void *data) | 
|  | 868 | { | 
|  | 869 | struct net_device *netdev = data; | 
|  | 870 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 871 | struct e1000_hw *hw = &adapter->hw; | 
|  | 872 | struct igbvf_ring *tx_ring = adapter->tx_ring; | 
|  | 873 |  | 
|  | 874 |  | 
|  | 875 | adapter->total_tx_bytes = 0; | 
|  | 876 | adapter->total_tx_packets = 0; | 
|  | 877 |  | 
|  | 878 | /* auto mask will automatically reenable the interrupt when we write | 
|  | 879 | * EICS */ | 
|  | 880 | if (!igbvf_clean_tx_irq(tx_ring)) | 
|  | 881 | /* Ring was not completely cleaned, so fire another interrupt */ | 
|  | 882 | ew32(EICS, tx_ring->eims_value); | 
|  | 883 | else | 
|  | 884 | ew32(EIMS, tx_ring->eims_value); | 
|  | 885 |  | 
|  | 886 | return IRQ_HANDLED; | 
|  | 887 | } | 
|  | 888 |  | 
|  | 889 | static irqreturn_t igbvf_intr_msix_rx(int irq, void *data) | 
|  | 890 | { | 
|  | 891 | struct net_device *netdev = data; | 
|  | 892 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 893 |  | 
|  | 894 | adapter->int_counter0++; | 
|  | 895 |  | 
|  | 896 | /* Write the ITR value calculated at the end of the | 
|  | 897 | * previous interrupt. | 
|  | 898 | */ | 
|  | 899 | if (adapter->rx_ring->set_itr) { | 
|  | 900 | writel(adapter->rx_ring->itr_val, | 
|  | 901 | adapter->hw.hw_addr + adapter->rx_ring->itr_register); | 
|  | 902 | adapter->rx_ring->set_itr = 0; | 
|  | 903 | } | 
|  | 904 |  | 
|  | 905 | if (napi_schedule_prep(&adapter->rx_ring->napi)) { | 
|  | 906 | adapter->total_rx_bytes = 0; | 
|  | 907 | adapter->total_rx_packets = 0; | 
|  | 908 | __napi_schedule(&adapter->rx_ring->napi); | 
|  | 909 | } | 
|  | 910 |  | 
|  | 911 | return IRQ_HANDLED; | 
|  | 912 | } | 
|  | 913 |  | 
|  | 914 | #define IGBVF_NO_QUEUE -1 | 
|  | 915 |  | 
|  | 916 | static void igbvf_assign_vector(struct igbvf_adapter *adapter, int rx_queue, | 
|  | 917 | int tx_queue, int msix_vector) | 
|  | 918 | { | 
|  | 919 | struct e1000_hw *hw = &adapter->hw; | 
|  | 920 | u32 ivar, index; | 
|  | 921 |  | 
|  | 922 | /* 82576 uses a table-based method for assigning vectors. | 
|  | 923 | Each queue has a single entry in the table to which we write | 
|  | 924 | a vector number along with a "valid" bit.  Sadly, the layout | 
|  | 925 | of the table is somewhat counterintuitive. */ | 
|  | 926 | if (rx_queue > IGBVF_NO_QUEUE) { | 
|  | 927 | index = (rx_queue >> 1); | 
|  | 928 | ivar = array_er32(IVAR0, index); | 
|  | 929 | if (rx_queue & 0x1) { | 
|  | 930 | /* vector goes into third byte of register */ | 
|  | 931 | ivar = ivar & 0xFF00FFFF; | 
|  | 932 | ivar |= (msix_vector | E1000_IVAR_VALID) << 16; | 
|  | 933 | } else { | 
|  | 934 | /* vector goes into low byte of register */ | 
|  | 935 | ivar = ivar & 0xFFFFFF00; | 
|  | 936 | ivar |= msix_vector | E1000_IVAR_VALID; | 
|  | 937 | } | 
|  | 938 | adapter->rx_ring[rx_queue].eims_value = 1 << msix_vector; | 
|  | 939 | array_ew32(IVAR0, index, ivar); | 
|  | 940 | } | 
|  | 941 | if (tx_queue > IGBVF_NO_QUEUE) { | 
|  | 942 | index = (tx_queue >> 1); | 
|  | 943 | ivar = array_er32(IVAR0, index); | 
|  | 944 | if (tx_queue & 0x1) { | 
|  | 945 | /* vector goes into high byte of register */ | 
|  | 946 | ivar = ivar & 0x00FFFFFF; | 
|  | 947 | ivar |= (msix_vector | E1000_IVAR_VALID) << 24; | 
|  | 948 | } else { | 
|  | 949 | /* vector goes into second byte of register */ | 
|  | 950 | ivar = ivar & 0xFFFF00FF; | 
|  | 951 | ivar |= (msix_vector | E1000_IVAR_VALID) << 8; | 
|  | 952 | } | 
|  | 953 | adapter->tx_ring[tx_queue].eims_value = 1 << msix_vector; | 
|  | 954 | array_ew32(IVAR0, index, ivar); | 
|  | 955 | } | 
|  | 956 | } | 
|  | 957 |  | 
|  | 958 | /** | 
|  | 959 | * igbvf_configure_msix - Configure MSI-X hardware | 
|  | 960 | * | 
|  | 961 | * igbvf_configure_msix sets up the hardware to properly | 
|  | 962 | * generate MSI-X interrupts. | 
|  | 963 | **/ | 
|  | 964 | static void igbvf_configure_msix(struct igbvf_adapter *adapter) | 
|  | 965 | { | 
|  | 966 | u32 tmp; | 
|  | 967 | struct e1000_hw *hw = &adapter->hw; | 
|  | 968 | struct igbvf_ring *tx_ring = adapter->tx_ring; | 
|  | 969 | struct igbvf_ring *rx_ring = adapter->rx_ring; | 
|  | 970 | int vector = 0; | 
|  | 971 |  | 
|  | 972 | adapter->eims_enable_mask = 0; | 
|  | 973 |  | 
|  | 974 | igbvf_assign_vector(adapter, IGBVF_NO_QUEUE, 0, vector++); | 
|  | 975 | adapter->eims_enable_mask |= tx_ring->eims_value; | 
|  | 976 | if (tx_ring->itr_val) | 
|  | 977 | writel(tx_ring->itr_val, | 
|  | 978 | hw->hw_addr + tx_ring->itr_register); | 
|  | 979 | else | 
|  | 980 | writel(1952, hw->hw_addr + tx_ring->itr_register); | 
|  | 981 |  | 
|  | 982 | igbvf_assign_vector(adapter, 0, IGBVF_NO_QUEUE, vector++); | 
|  | 983 | adapter->eims_enable_mask |= rx_ring->eims_value; | 
|  | 984 | if (rx_ring->itr_val) | 
|  | 985 | writel(rx_ring->itr_val, | 
|  | 986 | hw->hw_addr + rx_ring->itr_register); | 
|  | 987 | else | 
|  | 988 | writel(1952, hw->hw_addr + rx_ring->itr_register); | 
|  | 989 |  | 
|  | 990 | /* set vector for other causes, i.e. link changes */ | 
|  | 991 |  | 
|  | 992 | tmp = (vector++ | E1000_IVAR_VALID); | 
|  | 993 |  | 
|  | 994 | ew32(IVAR_MISC, tmp); | 
|  | 995 |  | 
|  | 996 | adapter->eims_enable_mask = (1 << (vector)) - 1; | 
|  | 997 | adapter->eims_other = 1 << (vector - 1); | 
|  | 998 | e1e_flush(); | 
|  | 999 | } | 
|  | 1000 |  | 
| Alexander Duyck | 2d16577 | 2009-04-09 22:49:20 +0000 | [diff] [blame] | 1001 | static void igbvf_reset_interrupt_capability(struct igbvf_adapter *adapter) | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1002 | { | 
|  | 1003 | if (adapter->msix_entries) { | 
|  | 1004 | pci_disable_msix(adapter->pdev); | 
|  | 1005 | kfree(adapter->msix_entries); | 
|  | 1006 | adapter->msix_entries = NULL; | 
|  | 1007 | } | 
|  | 1008 | } | 
|  | 1009 |  | 
|  | 1010 | /** | 
|  | 1011 | * igbvf_set_interrupt_capability - set MSI or MSI-X if supported | 
|  | 1012 | * | 
|  | 1013 | * Attempt to configure interrupts using the best available | 
|  | 1014 | * capabilities of the hardware and kernel. | 
|  | 1015 | **/ | 
| Alexander Duyck | 2d16577 | 2009-04-09 22:49:20 +0000 | [diff] [blame] | 1016 | static void igbvf_set_interrupt_capability(struct igbvf_adapter *adapter) | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1017 | { | 
|  | 1018 | int err = -ENOMEM; | 
|  | 1019 | int i; | 
|  | 1020 |  | 
|  | 1021 | /* we allocate 3 vectors, 1 for tx, 1 for rx, one for pf messages */ | 
|  | 1022 | adapter->msix_entries = kcalloc(3, sizeof(struct msix_entry), | 
|  | 1023 | GFP_KERNEL); | 
|  | 1024 | if (adapter->msix_entries) { | 
|  | 1025 | for (i = 0; i < 3; i++) | 
|  | 1026 | adapter->msix_entries[i].entry = i; | 
|  | 1027 |  | 
|  | 1028 | err = pci_enable_msix(adapter->pdev, | 
|  | 1029 | adapter->msix_entries, 3); | 
|  | 1030 | } | 
|  | 1031 |  | 
|  | 1032 | if (err) { | 
|  | 1033 | /* MSI-X failed */ | 
|  | 1034 | dev_err(&adapter->pdev->dev, | 
|  | 1035 | "Failed to initialize MSI-X interrupts.\n"); | 
|  | 1036 | igbvf_reset_interrupt_capability(adapter); | 
|  | 1037 | } | 
|  | 1038 | } | 
|  | 1039 |  | 
|  | 1040 | /** | 
|  | 1041 | * igbvf_request_msix - Initialize MSI-X interrupts | 
|  | 1042 | * | 
|  | 1043 | * igbvf_request_msix allocates MSI-X vectors and requests interrupts from the | 
|  | 1044 | * kernel. | 
|  | 1045 | **/ | 
|  | 1046 | static int igbvf_request_msix(struct igbvf_adapter *adapter) | 
|  | 1047 | { | 
|  | 1048 | struct net_device *netdev = adapter->netdev; | 
|  | 1049 | int err = 0, vector = 0; | 
|  | 1050 |  | 
|  | 1051 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) { | 
|  | 1052 | sprintf(adapter->tx_ring->name, "%s-tx-0", netdev->name); | 
|  | 1053 | sprintf(adapter->rx_ring->name, "%s-rx-0", netdev->name); | 
|  | 1054 | } else { | 
|  | 1055 | memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ); | 
|  | 1056 | memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ); | 
|  | 1057 | } | 
|  | 1058 |  | 
|  | 1059 | err = request_irq(adapter->msix_entries[vector].vector, | 
| Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1060 | igbvf_intr_msix_tx, 0, adapter->tx_ring->name, | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1061 | netdev); | 
|  | 1062 | if (err) | 
|  | 1063 | goto out; | 
|  | 1064 |  | 
|  | 1065 | adapter->tx_ring->itr_register = E1000_EITR(vector); | 
|  | 1066 | adapter->tx_ring->itr_val = 1952; | 
|  | 1067 | vector++; | 
|  | 1068 |  | 
|  | 1069 | err = request_irq(adapter->msix_entries[vector].vector, | 
| Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1070 | igbvf_intr_msix_rx, 0, adapter->rx_ring->name, | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1071 | netdev); | 
|  | 1072 | if (err) | 
|  | 1073 | goto out; | 
|  | 1074 |  | 
|  | 1075 | adapter->rx_ring->itr_register = E1000_EITR(vector); | 
|  | 1076 | adapter->rx_ring->itr_val = 1952; | 
|  | 1077 | vector++; | 
|  | 1078 |  | 
|  | 1079 | err = request_irq(adapter->msix_entries[vector].vector, | 
| Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1080 | igbvf_msix_other, 0, netdev->name, netdev); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1081 | if (err) | 
|  | 1082 | goto out; | 
|  | 1083 |  | 
|  | 1084 | igbvf_configure_msix(adapter); | 
|  | 1085 | return 0; | 
|  | 1086 | out: | 
|  | 1087 | return err; | 
|  | 1088 | } | 
|  | 1089 |  | 
|  | 1090 | /** | 
|  | 1091 | * igbvf_alloc_queues - Allocate memory for all rings | 
|  | 1092 | * @adapter: board private structure to initialize | 
|  | 1093 | **/ | 
|  | 1094 | static int __devinit igbvf_alloc_queues(struct igbvf_adapter *adapter) | 
|  | 1095 | { | 
|  | 1096 | struct net_device *netdev = adapter->netdev; | 
|  | 1097 |  | 
|  | 1098 | adapter->tx_ring = kzalloc(sizeof(struct igbvf_ring), GFP_KERNEL); | 
|  | 1099 | if (!adapter->tx_ring) | 
|  | 1100 | return -ENOMEM; | 
|  | 1101 |  | 
|  | 1102 | adapter->rx_ring = kzalloc(sizeof(struct igbvf_ring), GFP_KERNEL); | 
|  | 1103 | if (!adapter->rx_ring) { | 
|  | 1104 | kfree(adapter->tx_ring); | 
|  | 1105 | return -ENOMEM; | 
|  | 1106 | } | 
|  | 1107 |  | 
|  | 1108 | netif_napi_add(netdev, &adapter->rx_ring->napi, igbvf_poll, 64); | 
|  | 1109 |  | 
|  | 1110 | return 0; | 
|  | 1111 | } | 
|  | 1112 |  | 
|  | 1113 | /** | 
|  | 1114 | * igbvf_request_irq - initialize interrupts | 
|  | 1115 | * | 
|  | 1116 | * Attempts to configure interrupts using the best available | 
|  | 1117 | * capabilities of the hardware and kernel. | 
|  | 1118 | **/ | 
|  | 1119 | static int igbvf_request_irq(struct igbvf_adapter *adapter) | 
|  | 1120 | { | 
|  | 1121 | int err = -1; | 
|  | 1122 |  | 
|  | 1123 | /* igbvf supports msi-x only */ | 
|  | 1124 | if (adapter->msix_entries) | 
|  | 1125 | err = igbvf_request_msix(adapter); | 
|  | 1126 |  | 
|  | 1127 | if (!err) | 
|  | 1128 | return err; | 
|  | 1129 |  | 
|  | 1130 | dev_err(&adapter->pdev->dev, | 
|  | 1131 | "Unable to allocate interrupt, Error: %d\n", err); | 
|  | 1132 |  | 
|  | 1133 | return err; | 
|  | 1134 | } | 
|  | 1135 |  | 
|  | 1136 | static void igbvf_free_irq(struct igbvf_adapter *adapter) | 
|  | 1137 | { | 
|  | 1138 | struct net_device *netdev = adapter->netdev; | 
|  | 1139 | int vector; | 
|  | 1140 |  | 
|  | 1141 | if (adapter->msix_entries) { | 
|  | 1142 | for (vector = 0; vector < 3; vector++) | 
|  | 1143 | free_irq(adapter->msix_entries[vector].vector, netdev); | 
|  | 1144 | } | 
|  | 1145 | } | 
|  | 1146 |  | 
|  | 1147 | /** | 
|  | 1148 | * igbvf_irq_disable - Mask off interrupt generation on the NIC | 
|  | 1149 | **/ | 
|  | 1150 | static void igbvf_irq_disable(struct igbvf_adapter *adapter) | 
|  | 1151 | { | 
|  | 1152 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1153 |  | 
|  | 1154 | ew32(EIMC, ~0); | 
|  | 1155 |  | 
|  | 1156 | if (adapter->msix_entries) | 
|  | 1157 | ew32(EIAC, 0); | 
|  | 1158 | } | 
|  | 1159 |  | 
|  | 1160 | /** | 
|  | 1161 | * igbvf_irq_enable - Enable default interrupt generation settings | 
|  | 1162 | **/ | 
|  | 1163 | static void igbvf_irq_enable(struct igbvf_adapter *adapter) | 
|  | 1164 | { | 
|  | 1165 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1166 |  | 
|  | 1167 | ew32(EIAC, adapter->eims_enable_mask); | 
|  | 1168 | ew32(EIAM, adapter->eims_enable_mask); | 
|  | 1169 | ew32(EIMS, adapter->eims_enable_mask); | 
|  | 1170 | } | 
|  | 1171 |  | 
|  | 1172 | /** | 
|  | 1173 | * igbvf_poll - NAPI Rx polling callback | 
|  | 1174 | * @napi: struct associated with this polling callback | 
|  | 1175 | * @budget: amount of packets driver is allowed to process this poll | 
|  | 1176 | **/ | 
|  | 1177 | static int igbvf_poll(struct napi_struct *napi, int budget) | 
|  | 1178 | { | 
|  | 1179 | struct igbvf_ring *rx_ring = container_of(napi, struct igbvf_ring, napi); | 
|  | 1180 | struct igbvf_adapter *adapter = rx_ring->adapter; | 
|  | 1181 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1182 | int work_done = 0; | 
|  | 1183 |  | 
|  | 1184 | igbvf_clean_rx_irq(adapter, &work_done, budget); | 
|  | 1185 |  | 
|  | 1186 | /* If not enough Rx work done, exit the polling mode */ | 
|  | 1187 | if (work_done < budget) { | 
|  | 1188 | napi_complete(napi); | 
|  | 1189 |  | 
|  | 1190 | if (adapter->itr_setting & 3) | 
|  | 1191 | igbvf_set_itr(adapter); | 
|  | 1192 |  | 
|  | 1193 | if (!test_bit(__IGBVF_DOWN, &adapter->state)) | 
|  | 1194 | ew32(EIMS, adapter->rx_ring->eims_value); | 
|  | 1195 | } | 
|  | 1196 |  | 
|  | 1197 | return work_done; | 
|  | 1198 | } | 
|  | 1199 |  | 
|  | 1200 | /** | 
|  | 1201 | * igbvf_set_rlpml - set receive large packet maximum length | 
|  | 1202 | * @adapter: board private structure | 
|  | 1203 | * | 
|  | 1204 | * Configure the maximum size of packets that will be received | 
|  | 1205 | */ | 
|  | 1206 | static void igbvf_set_rlpml(struct igbvf_adapter *adapter) | 
|  | 1207 | { | 
|  | 1208 | int max_frame_size = adapter->max_frame_size; | 
|  | 1209 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1210 |  | 
|  | 1211 | if (adapter->vlgrp) | 
|  | 1212 | max_frame_size += VLAN_TAG_SIZE; | 
|  | 1213 |  | 
|  | 1214 | e1000_rlpml_set_vf(hw, max_frame_size); | 
|  | 1215 | } | 
|  | 1216 |  | 
|  | 1217 | static void igbvf_vlan_rx_add_vid(struct net_device *netdev, u16 vid) | 
|  | 1218 | { | 
|  | 1219 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 1220 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1221 |  | 
|  | 1222 | if (hw->mac.ops.set_vfta(hw, vid, true)) | 
|  | 1223 | dev_err(&adapter->pdev->dev, "Failed to add vlan id %d\n", vid); | 
|  | 1224 | } | 
|  | 1225 |  | 
|  | 1226 | static void igbvf_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) | 
|  | 1227 | { | 
|  | 1228 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 1229 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1230 |  | 
|  | 1231 | igbvf_irq_disable(adapter); | 
|  | 1232 | vlan_group_set_device(adapter->vlgrp, vid, NULL); | 
|  | 1233 |  | 
|  | 1234 | if (!test_bit(__IGBVF_DOWN, &adapter->state)) | 
|  | 1235 | igbvf_irq_enable(adapter); | 
|  | 1236 |  | 
|  | 1237 | if (hw->mac.ops.set_vfta(hw, vid, false)) | 
|  | 1238 | dev_err(&adapter->pdev->dev, | 
|  | 1239 | "Failed to remove vlan id %d\n", vid); | 
|  | 1240 | } | 
|  | 1241 |  | 
|  | 1242 | static void igbvf_vlan_rx_register(struct net_device *netdev, | 
|  | 1243 | struct vlan_group *grp) | 
|  | 1244 | { | 
|  | 1245 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 1246 |  | 
|  | 1247 | adapter->vlgrp = grp; | 
|  | 1248 | } | 
|  | 1249 |  | 
|  | 1250 | static void igbvf_restore_vlan(struct igbvf_adapter *adapter) | 
|  | 1251 | { | 
|  | 1252 | u16 vid; | 
|  | 1253 |  | 
|  | 1254 | if (!adapter->vlgrp) | 
|  | 1255 | return; | 
|  | 1256 |  | 
|  | 1257 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { | 
|  | 1258 | if (!vlan_group_get_device(adapter->vlgrp, vid)) | 
|  | 1259 | continue; | 
|  | 1260 | igbvf_vlan_rx_add_vid(adapter->netdev, vid); | 
|  | 1261 | } | 
|  | 1262 |  | 
|  | 1263 | igbvf_set_rlpml(adapter); | 
|  | 1264 | } | 
|  | 1265 |  | 
|  | 1266 | /** | 
|  | 1267 | * igbvf_configure_tx - Configure Transmit Unit after Reset | 
|  | 1268 | * @adapter: board private structure | 
|  | 1269 | * | 
|  | 1270 | * Configure the Tx unit of the MAC after a reset. | 
|  | 1271 | **/ | 
|  | 1272 | static void igbvf_configure_tx(struct igbvf_adapter *adapter) | 
|  | 1273 | { | 
|  | 1274 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1275 | struct igbvf_ring *tx_ring = adapter->tx_ring; | 
|  | 1276 | u64 tdba; | 
|  | 1277 | u32 txdctl, dca_txctrl; | 
|  | 1278 |  | 
|  | 1279 | /* disable transmits */ | 
|  | 1280 | txdctl = er32(TXDCTL(0)); | 
|  | 1281 | ew32(TXDCTL(0), txdctl & ~E1000_TXDCTL_QUEUE_ENABLE); | 
|  | 1282 | msleep(10); | 
|  | 1283 |  | 
|  | 1284 | /* Setup the HW Tx Head and Tail descriptor pointers */ | 
|  | 1285 | ew32(TDLEN(0), tx_ring->count * sizeof(union e1000_adv_tx_desc)); | 
|  | 1286 | tdba = tx_ring->dma; | 
| Andrew Morton | 8e20ce9 | 2009-06-18 16:49:17 -0700 | [diff] [blame] | 1287 | ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32))); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1288 | ew32(TDBAH(0), (tdba >> 32)); | 
|  | 1289 | ew32(TDH(0), 0); | 
|  | 1290 | ew32(TDT(0), 0); | 
|  | 1291 | tx_ring->head = E1000_TDH(0); | 
|  | 1292 | tx_ring->tail = E1000_TDT(0); | 
|  | 1293 |  | 
|  | 1294 | /* Turn off Relaxed Ordering on head write-backs.  The writebacks | 
|  | 1295 | * MUST be delivered in order or it will completely screw up | 
|  | 1296 | * our bookeeping. | 
|  | 1297 | */ | 
|  | 1298 | dca_txctrl = er32(DCA_TXCTRL(0)); | 
|  | 1299 | dca_txctrl &= ~E1000_DCA_TXCTRL_TX_WB_RO_EN; | 
|  | 1300 | ew32(DCA_TXCTRL(0), dca_txctrl); | 
|  | 1301 |  | 
|  | 1302 | /* enable transmits */ | 
|  | 1303 | txdctl |= E1000_TXDCTL_QUEUE_ENABLE; | 
|  | 1304 | ew32(TXDCTL(0), txdctl); | 
|  | 1305 |  | 
|  | 1306 | /* Setup Transmit Descriptor Settings for eop descriptor */ | 
|  | 1307 | adapter->txd_cmd = E1000_ADVTXD_DCMD_EOP | E1000_ADVTXD_DCMD_IFCS; | 
|  | 1308 |  | 
|  | 1309 | /* enable Report Status bit */ | 
|  | 1310 | adapter->txd_cmd |= E1000_ADVTXD_DCMD_RS; | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1311 | } | 
|  | 1312 |  | 
|  | 1313 | /** | 
|  | 1314 | * igbvf_setup_srrctl - configure the receive control registers | 
|  | 1315 | * @adapter: Board private structure | 
|  | 1316 | **/ | 
|  | 1317 | static void igbvf_setup_srrctl(struct igbvf_adapter *adapter) | 
|  | 1318 | { | 
|  | 1319 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1320 | u32 srrctl = 0; | 
|  | 1321 |  | 
|  | 1322 | srrctl &= ~(E1000_SRRCTL_DESCTYPE_MASK | | 
|  | 1323 | E1000_SRRCTL_BSIZEHDR_MASK | | 
|  | 1324 | E1000_SRRCTL_BSIZEPKT_MASK); | 
|  | 1325 |  | 
|  | 1326 | /* Enable queue drop to avoid head of line blocking */ | 
|  | 1327 | srrctl |= E1000_SRRCTL_DROP_EN; | 
|  | 1328 |  | 
|  | 1329 | /* Setup buffer sizes */ | 
|  | 1330 | srrctl |= ALIGN(adapter->rx_buffer_len, 1024) >> | 
|  | 1331 | E1000_SRRCTL_BSIZEPKT_SHIFT; | 
|  | 1332 |  | 
|  | 1333 | if (adapter->rx_buffer_len < 2048) { | 
|  | 1334 | adapter->rx_ps_hdr_size = 0; | 
|  | 1335 | srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF; | 
|  | 1336 | } else { | 
|  | 1337 | adapter->rx_ps_hdr_size = 128; | 
|  | 1338 | srrctl |= adapter->rx_ps_hdr_size << | 
|  | 1339 | E1000_SRRCTL_BSIZEHDRSIZE_SHIFT; | 
|  | 1340 | srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; | 
|  | 1341 | } | 
|  | 1342 |  | 
|  | 1343 | ew32(SRRCTL(0), srrctl); | 
|  | 1344 | } | 
|  | 1345 |  | 
|  | 1346 | /** | 
|  | 1347 | * igbvf_configure_rx - Configure Receive Unit after Reset | 
|  | 1348 | * @adapter: board private structure | 
|  | 1349 | * | 
|  | 1350 | * Configure the Rx unit of the MAC after a reset. | 
|  | 1351 | **/ | 
|  | 1352 | static void igbvf_configure_rx(struct igbvf_adapter *adapter) | 
|  | 1353 | { | 
|  | 1354 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1355 | struct igbvf_ring *rx_ring = adapter->rx_ring; | 
|  | 1356 | u64 rdba; | 
|  | 1357 | u32 rdlen, rxdctl; | 
|  | 1358 |  | 
|  | 1359 | /* disable receives */ | 
|  | 1360 | rxdctl = er32(RXDCTL(0)); | 
|  | 1361 | ew32(RXDCTL(0), rxdctl & ~E1000_RXDCTL_QUEUE_ENABLE); | 
|  | 1362 | msleep(10); | 
|  | 1363 |  | 
|  | 1364 | rdlen = rx_ring->count * sizeof(union e1000_adv_rx_desc); | 
|  | 1365 |  | 
|  | 1366 | /* | 
|  | 1367 | * Setup the HW Rx Head and Tail Descriptor Pointers and | 
|  | 1368 | * the Base and Length of the Rx Descriptor Ring | 
|  | 1369 | */ | 
|  | 1370 | rdba = rx_ring->dma; | 
| Andrew Morton | 8e20ce9 | 2009-06-18 16:49:17 -0700 | [diff] [blame] | 1371 | ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32))); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1372 | ew32(RDBAH(0), (rdba >> 32)); | 
|  | 1373 | ew32(RDLEN(0), rx_ring->count * sizeof(union e1000_adv_rx_desc)); | 
|  | 1374 | rx_ring->head = E1000_RDH(0); | 
|  | 1375 | rx_ring->tail = E1000_RDT(0); | 
|  | 1376 | ew32(RDH(0), 0); | 
|  | 1377 | ew32(RDT(0), 0); | 
|  | 1378 |  | 
|  | 1379 | rxdctl |= E1000_RXDCTL_QUEUE_ENABLE; | 
|  | 1380 | rxdctl &= 0xFFF00000; | 
|  | 1381 | rxdctl |= IGBVF_RX_PTHRESH; | 
|  | 1382 | rxdctl |= IGBVF_RX_HTHRESH << 8; | 
|  | 1383 | rxdctl |= IGBVF_RX_WTHRESH << 16; | 
|  | 1384 |  | 
|  | 1385 | igbvf_set_rlpml(adapter); | 
|  | 1386 |  | 
|  | 1387 | /* enable receives */ | 
|  | 1388 | ew32(RXDCTL(0), rxdctl); | 
|  | 1389 | } | 
|  | 1390 |  | 
|  | 1391 | /** | 
|  | 1392 | * igbvf_set_multi - Multicast and Promiscuous mode set | 
|  | 1393 | * @netdev: network interface device structure | 
|  | 1394 | * | 
|  | 1395 | * The set_multi entry point is called whenever the multicast address | 
|  | 1396 | * list or the network interface flags are updated.  This routine is | 
|  | 1397 | * responsible for configuring the hardware for proper multicast, | 
|  | 1398 | * promiscuous mode, and all-multi behavior. | 
|  | 1399 | **/ | 
|  | 1400 | static void igbvf_set_multi(struct net_device *netdev) | 
|  | 1401 | { | 
|  | 1402 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 1403 | struct e1000_hw *hw = &adapter->hw; | 
| Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1404 | struct netdev_hw_addr *ha; | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1405 | u8  *mta_list = NULL; | 
|  | 1406 | int i; | 
|  | 1407 |  | 
| Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 1408 | if (!netdev_mc_empty(netdev)) { | 
|  | 1409 | mta_list = kmalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1410 | if (!mta_list) { | 
|  | 1411 | dev_err(&adapter->pdev->dev, | 
|  | 1412 | "failed to allocate multicast filter list\n"); | 
|  | 1413 | return; | 
|  | 1414 | } | 
|  | 1415 | } | 
|  | 1416 |  | 
|  | 1417 | /* prepare a packed array of only addresses. */ | 
| Jiri Pirko | 48e2f18 | 2010-02-22 09:22:26 +0000 | [diff] [blame] | 1418 | i = 0; | 
| Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1419 | netdev_for_each_mc_addr(ha, netdev) | 
|  | 1420 | memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1421 |  | 
|  | 1422 | hw->mac.ops.update_mc_addr_list(hw, mta_list, i, 0, 0); | 
|  | 1423 | kfree(mta_list); | 
|  | 1424 | } | 
|  | 1425 |  | 
|  | 1426 | /** | 
|  | 1427 | * igbvf_configure - configure the hardware for Rx and Tx | 
|  | 1428 | * @adapter: private board structure | 
|  | 1429 | **/ | 
|  | 1430 | static void igbvf_configure(struct igbvf_adapter *adapter) | 
|  | 1431 | { | 
|  | 1432 | igbvf_set_multi(adapter->netdev); | 
|  | 1433 |  | 
|  | 1434 | igbvf_restore_vlan(adapter); | 
|  | 1435 |  | 
|  | 1436 | igbvf_configure_tx(adapter); | 
|  | 1437 | igbvf_setup_srrctl(adapter); | 
|  | 1438 | igbvf_configure_rx(adapter); | 
|  | 1439 | igbvf_alloc_rx_buffers(adapter->rx_ring, | 
|  | 1440 | igbvf_desc_unused(adapter->rx_ring)); | 
|  | 1441 | } | 
|  | 1442 |  | 
|  | 1443 | /* igbvf_reset - bring the hardware into a known good state | 
|  | 1444 | * | 
|  | 1445 | * This function boots the hardware and enables some settings that | 
|  | 1446 | * require a configuration cycle of the hardware - those cannot be | 
|  | 1447 | * set/changed during runtime. After reset the device needs to be | 
|  | 1448 | * properly configured for Rx, Tx etc. | 
|  | 1449 | */ | 
| Alexander Duyck | 2d16577 | 2009-04-09 22:49:20 +0000 | [diff] [blame] | 1450 | static void igbvf_reset(struct igbvf_adapter *adapter) | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1451 | { | 
|  | 1452 | struct e1000_mac_info *mac = &adapter->hw.mac; | 
|  | 1453 | struct net_device *netdev = adapter->netdev; | 
|  | 1454 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1455 |  | 
|  | 1456 | /* Allow time for pending master requests to run */ | 
|  | 1457 | if (mac->ops.reset_hw(hw)) | 
|  | 1458 | dev_err(&adapter->pdev->dev, "PF still resetting\n"); | 
|  | 1459 |  | 
|  | 1460 | mac->ops.init_hw(hw); | 
|  | 1461 |  | 
|  | 1462 | if (is_valid_ether_addr(adapter->hw.mac.addr)) { | 
|  | 1463 | memcpy(netdev->dev_addr, adapter->hw.mac.addr, | 
|  | 1464 | netdev->addr_len); | 
|  | 1465 | memcpy(netdev->perm_addr, adapter->hw.mac.addr, | 
|  | 1466 | netdev->addr_len); | 
|  | 1467 | } | 
| Alexander Duyck | 7227909 | 2009-12-11 22:58:14 -0800 | [diff] [blame] | 1468 |  | 
|  | 1469 | adapter->last_reset = jiffies; | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1470 | } | 
|  | 1471 |  | 
|  | 1472 | int igbvf_up(struct igbvf_adapter *adapter) | 
|  | 1473 | { | 
|  | 1474 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1475 |  | 
|  | 1476 | /* hardware has been reset, we need to reload some things */ | 
|  | 1477 | igbvf_configure(adapter); | 
|  | 1478 |  | 
|  | 1479 | clear_bit(__IGBVF_DOWN, &adapter->state); | 
|  | 1480 |  | 
|  | 1481 | napi_enable(&adapter->rx_ring->napi); | 
|  | 1482 | if (adapter->msix_entries) | 
|  | 1483 | igbvf_configure_msix(adapter); | 
|  | 1484 |  | 
|  | 1485 | /* Clear any pending interrupts. */ | 
|  | 1486 | er32(EICR); | 
|  | 1487 | igbvf_irq_enable(adapter); | 
|  | 1488 |  | 
|  | 1489 | /* start the watchdog */ | 
|  | 1490 | hw->mac.get_link_status = 1; | 
|  | 1491 | mod_timer(&adapter->watchdog_timer, jiffies + 1); | 
|  | 1492 |  | 
|  | 1493 |  | 
|  | 1494 | return 0; | 
|  | 1495 | } | 
|  | 1496 |  | 
|  | 1497 | void igbvf_down(struct igbvf_adapter *adapter) | 
|  | 1498 | { | 
|  | 1499 | struct net_device *netdev = adapter->netdev; | 
|  | 1500 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1501 | u32 rxdctl, txdctl; | 
|  | 1502 |  | 
|  | 1503 | /* | 
|  | 1504 | * signal that we're down so the interrupt handler does not | 
|  | 1505 | * reschedule our watchdog timer | 
|  | 1506 | */ | 
|  | 1507 | set_bit(__IGBVF_DOWN, &adapter->state); | 
|  | 1508 |  | 
|  | 1509 | /* disable receives in the hardware */ | 
|  | 1510 | rxdctl = er32(RXDCTL(0)); | 
|  | 1511 | ew32(RXDCTL(0), rxdctl & ~E1000_RXDCTL_QUEUE_ENABLE); | 
|  | 1512 |  | 
|  | 1513 | netif_stop_queue(netdev); | 
|  | 1514 |  | 
|  | 1515 | /* disable transmits in the hardware */ | 
|  | 1516 | txdctl = er32(TXDCTL(0)); | 
|  | 1517 | ew32(TXDCTL(0), txdctl & ~E1000_TXDCTL_QUEUE_ENABLE); | 
|  | 1518 |  | 
|  | 1519 | /* flush both disables and wait for them to finish */ | 
|  | 1520 | e1e_flush(); | 
|  | 1521 | msleep(10); | 
|  | 1522 |  | 
|  | 1523 | napi_disable(&adapter->rx_ring->napi); | 
|  | 1524 |  | 
|  | 1525 | igbvf_irq_disable(adapter); | 
|  | 1526 |  | 
|  | 1527 | del_timer_sync(&adapter->watchdog_timer); | 
|  | 1528 |  | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1529 | netif_carrier_off(netdev); | 
|  | 1530 |  | 
|  | 1531 | /* record the stats before reset*/ | 
|  | 1532 | igbvf_update_stats(adapter); | 
|  | 1533 |  | 
|  | 1534 | adapter->link_speed = 0; | 
|  | 1535 | adapter->link_duplex = 0; | 
|  | 1536 |  | 
|  | 1537 | igbvf_reset(adapter); | 
|  | 1538 | igbvf_clean_tx_ring(adapter->tx_ring); | 
|  | 1539 | igbvf_clean_rx_ring(adapter->rx_ring); | 
|  | 1540 | } | 
|  | 1541 |  | 
|  | 1542 | void igbvf_reinit_locked(struct igbvf_adapter *adapter) | 
|  | 1543 | { | 
|  | 1544 | might_sleep(); | 
|  | 1545 | while (test_and_set_bit(__IGBVF_RESETTING, &adapter->state)) | 
|  | 1546 | msleep(1); | 
|  | 1547 | igbvf_down(adapter); | 
|  | 1548 | igbvf_up(adapter); | 
|  | 1549 | clear_bit(__IGBVF_RESETTING, &adapter->state); | 
|  | 1550 | } | 
|  | 1551 |  | 
|  | 1552 | /** | 
|  | 1553 | * igbvf_sw_init - Initialize general software structures (struct igbvf_adapter) | 
|  | 1554 | * @adapter: board private structure to initialize | 
|  | 1555 | * | 
|  | 1556 | * igbvf_sw_init initializes the Adapter private data structure. | 
|  | 1557 | * Fields are initialized based on PCI device information and | 
|  | 1558 | * OS network device settings (MTU size). | 
|  | 1559 | **/ | 
|  | 1560 | static int __devinit igbvf_sw_init(struct igbvf_adapter *adapter) | 
|  | 1561 | { | 
|  | 1562 | struct net_device *netdev = adapter->netdev; | 
|  | 1563 | s32 rc; | 
|  | 1564 |  | 
|  | 1565 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN; | 
|  | 1566 | adapter->rx_ps_hdr_size = 0; | 
|  | 1567 | adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; | 
|  | 1568 | adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; | 
|  | 1569 |  | 
|  | 1570 | adapter->tx_int_delay = 8; | 
|  | 1571 | adapter->tx_abs_int_delay = 32; | 
|  | 1572 | adapter->rx_int_delay = 0; | 
|  | 1573 | adapter->rx_abs_int_delay = 8; | 
|  | 1574 | adapter->itr_setting = 3; | 
|  | 1575 | adapter->itr = 20000; | 
|  | 1576 |  | 
|  | 1577 | /* Set various function pointers */ | 
|  | 1578 | adapter->ei->init_ops(&adapter->hw); | 
|  | 1579 |  | 
|  | 1580 | rc = adapter->hw.mac.ops.init_params(&adapter->hw); | 
|  | 1581 | if (rc) | 
|  | 1582 | return rc; | 
|  | 1583 |  | 
|  | 1584 | rc = adapter->hw.mbx.ops.init_params(&adapter->hw); | 
|  | 1585 | if (rc) | 
|  | 1586 | return rc; | 
|  | 1587 |  | 
|  | 1588 | igbvf_set_interrupt_capability(adapter); | 
|  | 1589 |  | 
|  | 1590 | if (igbvf_alloc_queues(adapter)) | 
|  | 1591 | return -ENOMEM; | 
|  | 1592 |  | 
|  | 1593 | spin_lock_init(&adapter->tx_queue_lock); | 
|  | 1594 |  | 
|  | 1595 | /* Explicitly disable IRQ since the NIC can be in any state. */ | 
|  | 1596 | igbvf_irq_disable(adapter); | 
|  | 1597 |  | 
|  | 1598 | spin_lock_init(&adapter->stats_lock); | 
|  | 1599 |  | 
|  | 1600 | set_bit(__IGBVF_DOWN, &adapter->state); | 
|  | 1601 | return 0; | 
|  | 1602 | } | 
|  | 1603 |  | 
|  | 1604 | static void igbvf_initialize_last_counter_stats(struct igbvf_adapter *adapter) | 
|  | 1605 | { | 
|  | 1606 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1607 |  | 
|  | 1608 | adapter->stats.last_gprc = er32(VFGPRC); | 
|  | 1609 | adapter->stats.last_gorc = er32(VFGORC); | 
|  | 1610 | adapter->stats.last_gptc = er32(VFGPTC); | 
|  | 1611 | adapter->stats.last_gotc = er32(VFGOTC); | 
|  | 1612 | adapter->stats.last_mprc = er32(VFMPRC); | 
|  | 1613 | adapter->stats.last_gotlbc = er32(VFGOTLBC); | 
|  | 1614 | adapter->stats.last_gptlbc = er32(VFGPTLBC); | 
|  | 1615 | adapter->stats.last_gorlbc = er32(VFGORLBC); | 
|  | 1616 | adapter->stats.last_gprlbc = er32(VFGPRLBC); | 
|  | 1617 |  | 
|  | 1618 | adapter->stats.base_gprc = er32(VFGPRC); | 
|  | 1619 | adapter->stats.base_gorc = er32(VFGORC); | 
|  | 1620 | adapter->stats.base_gptc = er32(VFGPTC); | 
|  | 1621 | adapter->stats.base_gotc = er32(VFGOTC); | 
|  | 1622 | adapter->stats.base_mprc = er32(VFMPRC); | 
|  | 1623 | adapter->stats.base_gotlbc = er32(VFGOTLBC); | 
|  | 1624 | adapter->stats.base_gptlbc = er32(VFGPTLBC); | 
|  | 1625 | adapter->stats.base_gorlbc = er32(VFGORLBC); | 
|  | 1626 | adapter->stats.base_gprlbc = er32(VFGPRLBC); | 
|  | 1627 | } | 
|  | 1628 |  | 
|  | 1629 | /** | 
|  | 1630 | * igbvf_open - Called when a network interface is made active | 
|  | 1631 | * @netdev: network interface device structure | 
|  | 1632 | * | 
|  | 1633 | * Returns 0 on success, negative value on failure | 
|  | 1634 | * | 
|  | 1635 | * The open entry point is called when a network interface is made | 
|  | 1636 | * active by the system (IFF_UP).  At this point all resources needed | 
|  | 1637 | * for transmit and receive operations are allocated, the interrupt | 
|  | 1638 | * handler is registered with the OS, the watchdog timer is started, | 
|  | 1639 | * and the stack is notified that the interface is ready. | 
|  | 1640 | **/ | 
|  | 1641 | static int igbvf_open(struct net_device *netdev) | 
|  | 1642 | { | 
|  | 1643 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 1644 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1645 | int err; | 
|  | 1646 |  | 
|  | 1647 | /* disallow open during test */ | 
|  | 1648 | if (test_bit(__IGBVF_TESTING, &adapter->state)) | 
|  | 1649 | return -EBUSY; | 
|  | 1650 |  | 
|  | 1651 | /* allocate transmit descriptors */ | 
|  | 1652 | err = igbvf_setup_tx_resources(adapter, adapter->tx_ring); | 
|  | 1653 | if (err) | 
|  | 1654 | goto err_setup_tx; | 
|  | 1655 |  | 
|  | 1656 | /* allocate receive descriptors */ | 
|  | 1657 | err = igbvf_setup_rx_resources(adapter, adapter->rx_ring); | 
|  | 1658 | if (err) | 
|  | 1659 | goto err_setup_rx; | 
|  | 1660 |  | 
|  | 1661 | /* | 
|  | 1662 | * before we allocate an interrupt, we must be ready to handle it. | 
|  | 1663 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt | 
|  | 1664 | * as soon as we call pci_request_irq, so we have to setup our | 
|  | 1665 | * clean_rx handler before we do so. | 
|  | 1666 | */ | 
|  | 1667 | igbvf_configure(adapter); | 
|  | 1668 |  | 
|  | 1669 | err = igbvf_request_irq(adapter); | 
|  | 1670 | if (err) | 
|  | 1671 | goto err_req_irq; | 
|  | 1672 |  | 
|  | 1673 | /* From here on the code is the same as igbvf_up() */ | 
|  | 1674 | clear_bit(__IGBVF_DOWN, &adapter->state); | 
|  | 1675 |  | 
|  | 1676 | napi_enable(&adapter->rx_ring->napi); | 
|  | 1677 |  | 
|  | 1678 | /* clear any pending interrupts */ | 
|  | 1679 | er32(EICR); | 
|  | 1680 |  | 
|  | 1681 | igbvf_irq_enable(adapter); | 
|  | 1682 |  | 
|  | 1683 | /* start the watchdog */ | 
|  | 1684 | hw->mac.get_link_status = 1; | 
|  | 1685 | mod_timer(&adapter->watchdog_timer, jiffies + 1); | 
|  | 1686 |  | 
|  | 1687 | return 0; | 
|  | 1688 |  | 
|  | 1689 | err_req_irq: | 
|  | 1690 | igbvf_free_rx_resources(adapter->rx_ring); | 
|  | 1691 | err_setup_rx: | 
|  | 1692 | igbvf_free_tx_resources(adapter->tx_ring); | 
|  | 1693 | err_setup_tx: | 
|  | 1694 | igbvf_reset(adapter); | 
|  | 1695 |  | 
|  | 1696 | return err; | 
|  | 1697 | } | 
|  | 1698 |  | 
|  | 1699 | /** | 
|  | 1700 | * igbvf_close - Disables a network interface | 
|  | 1701 | * @netdev: network interface device structure | 
|  | 1702 | * | 
|  | 1703 | * Returns 0, this is not allowed to fail | 
|  | 1704 | * | 
|  | 1705 | * The close entry point is called when an interface is de-activated | 
|  | 1706 | * by the OS.  The hardware is still under the drivers control, but | 
|  | 1707 | * needs to be disabled.  A global MAC reset is issued to stop the | 
|  | 1708 | * hardware, and all transmit and receive resources are freed. | 
|  | 1709 | **/ | 
|  | 1710 | static int igbvf_close(struct net_device *netdev) | 
|  | 1711 | { | 
|  | 1712 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 1713 |  | 
|  | 1714 | WARN_ON(test_bit(__IGBVF_RESETTING, &adapter->state)); | 
|  | 1715 | igbvf_down(adapter); | 
|  | 1716 |  | 
|  | 1717 | igbvf_free_irq(adapter); | 
|  | 1718 |  | 
|  | 1719 | igbvf_free_tx_resources(adapter->tx_ring); | 
|  | 1720 | igbvf_free_rx_resources(adapter->rx_ring); | 
|  | 1721 |  | 
|  | 1722 | return 0; | 
|  | 1723 | } | 
|  | 1724 | /** | 
|  | 1725 | * igbvf_set_mac - Change the Ethernet Address of the NIC | 
|  | 1726 | * @netdev: network interface device structure | 
|  | 1727 | * @p: pointer to an address structure | 
|  | 1728 | * | 
|  | 1729 | * Returns 0 on success, negative on failure | 
|  | 1730 | **/ | 
|  | 1731 | static int igbvf_set_mac(struct net_device *netdev, void *p) | 
|  | 1732 | { | 
|  | 1733 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 1734 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1735 | struct sockaddr *addr = p; | 
|  | 1736 |  | 
|  | 1737 | if (!is_valid_ether_addr(addr->sa_data)) | 
|  | 1738 | return -EADDRNOTAVAIL; | 
|  | 1739 |  | 
|  | 1740 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); | 
|  | 1741 |  | 
|  | 1742 | hw->mac.ops.rar_set(hw, hw->mac.addr, 0); | 
|  | 1743 |  | 
|  | 1744 | if (memcmp(addr->sa_data, hw->mac.addr, 6)) | 
|  | 1745 | return -EADDRNOTAVAIL; | 
|  | 1746 |  | 
|  | 1747 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); | 
|  | 1748 |  | 
|  | 1749 | return 0; | 
|  | 1750 | } | 
|  | 1751 |  | 
|  | 1752 | #define UPDATE_VF_COUNTER(reg, name)                                    \ | 
|  | 1753 | {                                                               \ | 
|  | 1754 | u32 current_counter = er32(reg);                        \ | 
|  | 1755 | if (current_counter < adapter->stats.last_##name)       \ | 
|  | 1756 | adapter->stats.name += 0x100000000LL;           \ | 
|  | 1757 | adapter->stats.last_##name = current_counter;           \ | 
|  | 1758 | adapter->stats.name &= 0xFFFFFFFF00000000LL;            \ | 
|  | 1759 | adapter->stats.name |= current_counter;                 \ | 
|  | 1760 | } | 
|  | 1761 |  | 
|  | 1762 | /** | 
|  | 1763 | * igbvf_update_stats - Update the board statistics counters | 
|  | 1764 | * @adapter: board private structure | 
|  | 1765 | **/ | 
|  | 1766 | void igbvf_update_stats(struct igbvf_adapter *adapter) | 
|  | 1767 | { | 
|  | 1768 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1769 | struct pci_dev *pdev = adapter->pdev; | 
|  | 1770 |  | 
|  | 1771 | /* | 
|  | 1772 | * Prevent stats update while adapter is being reset, link is down | 
|  | 1773 | * or if the pci connection is down. | 
|  | 1774 | */ | 
|  | 1775 | if (adapter->link_speed == 0) | 
|  | 1776 | return; | 
|  | 1777 |  | 
|  | 1778 | if (test_bit(__IGBVF_RESETTING, &adapter->state)) | 
|  | 1779 | return; | 
|  | 1780 |  | 
|  | 1781 | if (pci_channel_offline(pdev)) | 
|  | 1782 | return; | 
|  | 1783 |  | 
|  | 1784 | UPDATE_VF_COUNTER(VFGPRC, gprc); | 
|  | 1785 | UPDATE_VF_COUNTER(VFGORC, gorc); | 
|  | 1786 | UPDATE_VF_COUNTER(VFGPTC, gptc); | 
|  | 1787 | UPDATE_VF_COUNTER(VFGOTC, gotc); | 
|  | 1788 | UPDATE_VF_COUNTER(VFMPRC, mprc); | 
|  | 1789 | UPDATE_VF_COUNTER(VFGOTLBC, gotlbc); | 
|  | 1790 | UPDATE_VF_COUNTER(VFGPTLBC, gptlbc); | 
|  | 1791 | UPDATE_VF_COUNTER(VFGORLBC, gorlbc); | 
|  | 1792 | UPDATE_VF_COUNTER(VFGPRLBC, gprlbc); | 
|  | 1793 |  | 
|  | 1794 | /* Fill out the OS statistics structure */ | 
|  | 1795 | adapter->net_stats.multicast = adapter->stats.mprc; | 
|  | 1796 | } | 
|  | 1797 |  | 
|  | 1798 | static void igbvf_print_link_info(struct igbvf_adapter *adapter) | 
|  | 1799 | { | 
|  | 1800 | dev_info(&adapter->pdev->dev, "Link is Up %d Mbps %s\n", | 
|  | 1801 | adapter->link_speed, | 
|  | 1802 | ((adapter->link_duplex == FULL_DUPLEX) ? | 
|  | 1803 | "Full Duplex" : "Half Duplex")); | 
|  | 1804 | } | 
|  | 1805 |  | 
|  | 1806 | static bool igbvf_has_link(struct igbvf_adapter *adapter) | 
|  | 1807 | { | 
|  | 1808 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1809 | s32 ret_val = E1000_SUCCESS; | 
|  | 1810 | bool link_active; | 
|  | 1811 |  | 
| Alexander Duyck | 7227909 | 2009-12-11 22:58:14 -0800 | [diff] [blame] | 1812 | /* If interface is down, stay link down */ | 
|  | 1813 | if (test_bit(__IGBVF_DOWN, &adapter->state)) | 
|  | 1814 | return false; | 
|  | 1815 |  | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1816 | ret_val = hw->mac.ops.check_for_link(hw); | 
|  | 1817 | link_active = !hw->mac.get_link_status; | 
|  | 1818 |  | 
|  | 1819 | /* if check for link returns error we will need to reset */ | 
| Alexander Duyck | 7227909 | 2009-12-11 22:58:14 -0800 | [diff] [blame] | 1820 | if (ret_val && time_after(jiffies, adapter->last_reset + (10 * HZ))) | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1821 | schedule_work(&adapter->reset_task); | 
|  | 1822 |  | 
|  | 1823 | return link_active; | 
|  | 1824 | } | 
|  | 1825 |  | 
|  | 1826 | /** | 
|  | 1827 | * igbvf_watchdog - Timer Call-back | 
|  | 1828 | * @data: pointer to adapter cast into an unsigned long | 
|  | 1829 | **/ | 
|  | 1830 | static void igbvf_watchdog(unsigned long data) | 
|  | 1831 | { | 
|  | 1832 | struct igbvf_adapter *adapter = (struct igbvf_adapter *) data; | 
|  | 1833 |  | 
|  | 1834 | /* Do the rest outside of interrupt context */ | 
|  | 1835 | schedule_work(&adapter->watchdog_task); | 
|  | 1836 | } | 
|  | 1837 |  | 
|  | 1838 | static void igbvf_watchdog_task(struct work_struct *work) | 
|  | 1839 | { | 
|  | 1840 | struct igbvf_adapter *adapter = container_of(work, | 
|  | 1841 | struct igbvf_adapter, | 
|  | 1842 | watchdog_task); | 
|  | 1843 | struct net_device *netdev = adapter->netdev; | 
|  | 1844 | struct e1000_mac_info *mac = &adapter->hw.mac; | 
|  | 1845 | struct igbvf_ring *tx_ring = adapter->tx_ring; | 
|  | 1846 | struct e1000_hw *hw = &adapter->hw; | 
|  | 1847 | u32 link; | 
|  | 1848 | int tx_pending = 0; | 
|  | 1849 |  | 
|  | 1850 | link = igbvf_has_link(adapter); | 
|  | 1851 |  | 
|  | 1852 | if (link) { | 
|  | 1853 | if (!netif_carrier_ok(netdev)) { | 
|  | 1854 | bool txb2b = 1; | 
|  | 1855 |  | 
|  | 1856 | mac->ops.get_link_up_info(&adapter->hw, | 
|  | 1857 | &adapter->link_speed, | 
|  | 1858 | &adapter->link_duplex); | 
|  | 1859 | igbvf_print_link_info(adapter); | 
|  | 1860 |  | 
| Emil Tantilov | a08af74 | 2010-03-25 12:11:48 +0000 | [diff] [blame] | 1861 | /* adjust timeout factor according to speed/duplex */ | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1862 | adapter->tx_timeout_factor = 1; | 
|  | 1863 | switch (adapter->link_speed) { | 
|  | 1864 | case SPEED_10: | 
|  | 1865 | txb2b = 0; | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1866 | adapter->tx_timeout_factor = 16; | 
|  | 1867 | break; | 
|  | 1868 | case SPEED_100: | 
|  | 1869 | txb2b = 0; | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1870 | /* maybe add some timeout factor ? */ | 
|  | 1871 | break; | 
|  | 1872 | } | 
|  | 1873 |  | 
|  | 1874 | netif_carrier_on(netdev); | 
|  | 1875 | netif_wake_queue(netdev); | 
|  | 1876 | } | 
|  | 1877 | } else { | 
|  | 1878 | if (netif_carrier_ok(netdev)) { | 
|  | 1879 | adapter->link_speed = 0; | 
|  | 1880 | adapter->link_duplex = 0; | 
|  | 1881 | dev_info(&adapter->pdev->dev, "Link is Down\n"); | 
|  | 1882 | netif_carrier_off(netdev); | 
|  | 1883 | netif_stop_queue(netdev); | 
|  | 1884 | } | 
|  | 1885 | } | 
|  | 1886 |  | 
|  | 1887 | if (netif_carrier_ok(netdev)) { | 
|  | 1888 | igbvf_update_stats(adapter); | 
|  | 1889 | } else { | 
|  | 1890 | tx_pending = (igbvf_desc_unused(tx_ring) + 1 < | 
|  | 1891 | tx_ring->count); | 
|  | 1892 | if (tx_pending) { | 
|  | 1893 | /* | 
|  | 1894 | * We've lost link, so the controller stops DMA, | 
|  | 1895 | * but we've got queued Tx work that's never going | 
|  | 1896 | * to get done, so reset controller to flush Tx. | 
|  | 1897 | * (Do the reset outside of interrupt context). | 
|  | 1898 | */ | 
|  | 1899 | adapter->tx_timeout_count++; | 
|  | 1900 | schedule_work(&adapter->reset_task); | 
|  | 1901 | } | 
|  | 1902 | } | 
|  | 1903 |  | 
|  | 1904 | /* Cause software interrupt to ensure Rx ring is cleaned */ | 
|  | 1905 | ew32(EICS, adapter->rx_ring->eims_value); | 
|  | 1906 |  | 
|  | 1907 | /* Force detection of hung controller every watchdog period */ | 
|  | 1908 | adapter->detect_tx_hung = 1; | 
|  | 1909 |  | 
|  | 1910 | /* Reset the timer */ | 
|  | 1911 | if (!test_bit(__IGBVF_DOWN, &adapter->state)) | 
|  | 1912 | mod_timer(&adapter->watchdog_timer, | 
|  | 1913 | round_jiffies(jiffies + (2 * HZ))); | 
|  | 1914 | } | 
|  | 1915 |  | 
|  | 1916 | #define IGBVF_TX_FLAGS_CSUM             0x00000001 | 
|  | 1917 | #define IGBVF_TX_FLAGS_VLAN             0x00000002 | 
|  | 1918 | #define IGBVF_TX_FLAGS_TSO              0x00000004 | 
|  | 1919 | #define IGBVF_TX_FLAGS_IPV4             0x00000008 | 
|  | 1920 | #define IGBVF_TX_FLAGS_VLAN_MASK        0xffff0000 | 
|  | 1921 | #define IGBVF_TX_FLAGS_VLAN_SHIFT       16 | 
|  | 1922 |  | 
|  | 1923 | static int igbvf_tso(struct igbvf_adapter *adapter, | 
|  | 1924 | struct igbvf_ring *tx_ring, | 
|  | 1925 | struct sk_buff *skb, u32 tx_flags, u8 *hdr_len) | 
|  | 1926 | { | 
|  | 1927 | struct e1000_adv_tx_context_desc *context_desc; | 
|  | 1928 | unsigned int i; | 
|  | 1929 | int err; | 
|  | 1930 | struct igbvf_buffer *buffer_info; | 
|  | 1931 | u32 info = 0, tu_cmd = 0; | 
|  | 1932 | u32 mss_l4len_idx, l4len; | 
|  | 1933 | *hdr_len = 0; | 
|  | 1934 |  | 
|  | 1935 | if (skb_header_cloned(skb)) { | 
|  | 1936 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); | 
|  | 1937 | if (err) { | 
|  | 1938 | dev_err(&adapter->pdev->dev, | 
|  | 1939 | "igbvf_tso returning an error\n"); | 
|  | 1940 | return err; | 
|  | 1941 | } | 
|  | 1942 | } | 
|  | 1943 |  | 
|  | 1944 | l4len = tcp_hdrlen(skb); | 
|  | 1945 | *hdr_len += l4len; | 
|  | 1946 |  | 
|  | 1947 | if (skb->protocol == htons(ETH_P_IP)) { | 
|  | 1948 | struct iphdr *iph = ip_hdr(skb); | 
|  | 1949 | iph->tot_len = 0; | 
|  | 1950 | iph->check = 0; | 
|  | 1951 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, | 
|  | 1952 | iph->daddr, 0, | 
|  | 1953 | IPPROTO_TCP, | 
|  | 1954 | 0); | 
| Sridhar Samudrala | 8e1e8a4 | 2010-01-23 02:02:21 -0800 | [diff] [blame] | 1955 | } else if (skb_is_gso_v6(skb)) { | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1956 | ipv6_hdr(skb)->payload_len = 0; | 
|  | 1957 | tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, | 
|  | 1958 | &ipv6_hdr(skb)->daddr, | 
|  | 1959 | 0, IPPROTO_TCP, 0); | 
|  | 1960 | } | 
|  | 1961 |  | 
|  | 1962 | i = tx_ring->next_to_use; | 
|  | 1963 |  | 
|  | 1964 | buffer_info = &tx_ring->buffer_info[i]; | 
|  | 1965 | context_desc = IGBVF_TX_CTXTDESC_ADV(*tx_ring, i); | 
|  | 1966 | /* VLAN MACLEN IPLEN */ | 
|  | 1967 | if (tx_flags & IGBVF_TX_FLAGS_VLAN) | 
|  | 1968 | info |= (tx_flags & IGBVF_TX_FLAGS_VLAN_MASK); | 
|  | 1969 | info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT); | 
|  | 1970 | *hdr_len += skb_network_offset(skb); | 
|  | 1971 | info |= (skb_transport_header(skb) - skb_network_header(skb)); | 
|  | 1972 | *hdr_len += (skb_transport_header(skb) - skb_network_header(skb)); | 
|  | 1973 | context_desc->vlan_macip_lens = cpu_to_le32(info); | 
|  | 1974 |  | 
|  | 1975 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ | 
|  | 1976 | tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT); | 
|  | 1977 |  | 
|  | 1978 | if (skb->protocol == htons(ETH_P_IP)) | 
|  | 1979 | tu_cmd |= E1000_ADVTXD_TUCMD_IPV4; | 
|  | 1980 | tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP; | 
|  | 1981 |  | 
|  | 1982 | context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd); | 
|  | 1983 |  | 
|  | 1984 | /* MSS L4LEN IDX */ | 
|  | 1985 | mss_l4len_idx = (skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT); | 
|  | 1986 | mss_l4len_idx |= (l4len << E1000_ADVTXD_L4LEN_SHIFT); | 
|  | 1987 |  | 
|  | 1988 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); | 
|  | 1989 | context_desc->seqnum_seed = 0; | 
|  | 1990 |  | 
|  | 1991 | buffer_info->time_stamp = jiffies; | 
|  | 1992 | buffer_info->next_to_watch = i; | 
|  | 1993 | buffer_info->dma = 0; | 
|  | 1994 | i++; | 
|  | 1995 | if (i == tx_ring->count) | 
|  | 1996 | i = 0; | 
|  | 1997 |  | 
|  | 1998 | tx_ring->next_to_use = i; | 
|  | 1999 |  | 
|  | 2000 | return true; | 
|  | 2001 | } | 
|  | 2002 |  | 
|  | 2003 | static inline bool igbvf_tx_csum(struct igbvf_adapter *adapter, | 
|  | 2004 | struct igbvf_ring *tx_ring, | 
|  | 2005 | struct sk_buff *skb, u32 tx_flags) | 
|  | 2006 | { | 
|  | 2007 | struct e1000_adv_tx_context_desc *context_desc; | 
|  | 2008 | unsigned int i; | 
|  | 2009 | struct igbvf_buffer *buffer_info; | 
|  | 2010 | u32 info = 0, tu_cmd = 0; | 
|  | 2011 |  | 
|  | 2012 | if ((skb->ip_summed == CHECKSUM_PARTIAL) || | 
|  | 2013 | (tx_flags & IGBVF_TX_FLAGS_VLAN)) { | 
|  | 2014 | i = tx_ring->next_to_use; | 
|  | 2015 | buffer_info = &tx_ring->buffer_info[i]; | 
|  | 2016 | context_desc = IGBVF_TX_CTXTDESC_ADV(*tx_ring, i); | 
|  | 2017 |  | 
|  | 2018 | if (tx_flags & IGBVF_TX_FLAGS_VLAN) | 
|  | 2019 | info |= (tx_flags & IGBVF_TX_FLAGS_VLAN_MASK); | 
|  | 2020 |  | 
|  | 2021 | info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT); | 
|  | 2022 | if (skb->ip_summed == CHECKSUM_PARTIAL) | 
|  | 2023 | info |= (skb_transport_header(skb) - | 
|  | 2024 | skb_network_header(skb)); | 
|  | 2025 |  | 
|  | 2026 |  | 
|  | 2027 | context_desc->vlan_macip_lens = cpu_to_le32(info); | 
|  | 2028 |  | 
|  | 2029 | tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT); | 
|  | 2030 |  | 
|  | 2031 | if (skb->ip_summed == CHECKSUM_PARTIAL) { | 
|  | 2032 | switch (skb->protocol) { | 
|  | 2033 | case __constant_htons(ETH_P_IP): | 
|  | 2034 | tu_cmd |= E1000_ADVTXD_TUCMD_IPV4; | 
|  | 2035 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) | 
|  | 2036 | tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP; | 
|  | 2037 | break; | 
|  | 2038 | case __constant_htons(ETH_P_IPV6): | 
|  | 2039 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) | 
|  | 2040 | tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP; | 
|  | 2041 | break; | 
|  | 2042 | default: | 
|  | 2043 | break; | 
|  | 2044 | } | 
|  | 2045 | } | 
|  | 2046 |  | 
|  | 2047 | context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd); | 
|  | 2048 | context_desc->seqnum_seed = 0; | 
|  | 2049 | context_desc->mss_l4len_idx = 0; | 
|  | 2050 |  | 
|  | 2051 | buffer_info->time_stamp = jiffies; | 
|  | 2052 | buffer_info->next_to_watch = i; | 
|  | 2053 | buffer_info->dma = 0; | 
|  | 2054 | i++; | 
|  | 2055 | if (i == tx_ring->count) | 
|  | 2056 | i = 0; | 
|  | 2057 | tx_ring->next_to_use = i; | 
|  | 2058 |  | 
|  | 2059 | return true; | 
|  | 2060 | } | 
|  | 2061 |  | 
|  | 2062 | return false; | 
|  | 2063 | } | 
|  | 2064 |  | 
|  | 2065 | static int igbvf_maybe_stop_tx(struct net_device *netdev, int size) | 
|  | 2066 | { | 
|  | 2067 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 2068 |  | 
|  | 2069 | /* there is enough descriptors then we don't need to worry  */ | 
|  | 2070 | if (igbvf_desc_unused(adapter->tx_ring) >= size) | 
|  | 2071 | return 0; | 
|  | 2072 |  | 
|  | 2073 | netif_stop_queue(netdev); | 
|  | 2074 |  | 
|  | 2075 | smp_mb(); | 
|  | 2076 |  | 
|  | 2077 | /* We need to check again just in case room has been made available */ | 
|  | 2078 | if (igbvf_desc_unused(adapter->tx_ring) < size) | 
|  | 2079 | return -EBUSY; | 
|  | 2080 |  | 
|  | 2081 | netif_wake_queue(netdev); | 
|  | 2082 |  | 
|  | 2083 | ++adapter->restart_queue; | 
|  | 2084 | return 0; | 
|  | 2085 | } | 
|  | 2086 |  | 
|  | 2087 | #define IGBVF_MAX_TXD_PWR       16 | 
|  | 2088 | #define IGBVF_MAX_DATA_PER_TXD  (1 << IGBVF_MAX_TXD_PWR) | 
|  | 2089 |  | 
|  | 2090 | static inline int igbvf_tx_map_adv(struct igbvf_adapter *adapter, | 
|  | 2091 | struct igbvf_ring *tx_ring, | 
|  | 2092 | struct sk_buff *skb, | 
|  | 2093 | unsigned int first) | 
|  | 2094 | { | 
|  | 2095 | struct igbvf_buffer *buffer_info; | 
| Alexander Duyck | a7d5ca4 | 2009-12-02 16:47:37 +0000 | [diff] [blame] | 2096 | struct pci_dev *pdev = adapter->pdev; | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2097 | unsigned int len = skb_headlen(skb); | 
|  | 2098 | unsigned int count = 0, i; | 
|  | 2099 | unsigned int f; | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2100 |  | 
|  | 2101 | i = tx_ring->next_to_use; | 
|  | 2102 |  | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2103 | buffer_info = &tx_ring->buffer_info[i]; | 
|  | 2104 | BUG_ON(len >= IGBVF_MAX_DATA_PER_TXD); | 
|  | 2105 | buffer_info->length = len; | 
|  | 2106 | /* set time_stamp *before* dma to help avoid a possible race */ | 
|  | 2107 | buffer_info->time_stamp = jiffies; | 
|  | 2108 | buffer_info->next_to_watch = i; | 
| Alexander Duyck | ac26d7d | 2010-01-27 15:30:39 +0000 | [diff] [blame] | 2109 | buffer_info->mapped_as_page = false; | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 2110 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, len, | 
|  | 2111 | DMA_TO_DEVICE); | 
|  | 2112 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) | 
| Alexander Duyck | a7d5ca4 | 2009-12-02 16:47:37 +0000 | [diff] [blame] | 2113 | goto dma_error; | 
|  | 2114 |  | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2115 |  | 
|  | 2116 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) { | 
|  | 2117 | struct skb_frag_struct *frag; | 
|  | 2118 |  | 
| Alexander Duyck | 8581145 | 2010-01-23 01:35:00 -0800 | [diff] [blame] | 2119 | count++; | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2120 | i++; | 
|  | 2121 | if (i == tx_ring->count) | 
|  | 2122 | i = 0; | 
|  | 2123 |  | 
|  | 2124 | frag = &skb_shinfo(skb)->frags[f]; | 
|  | 2125 | len = frag->size; | 
|  | 2126 |  | 
|  | 2127 | buffer_info = &tx_ring->buffer_info[i]; | 
|  | 2128 | BUG_ON(len >= IGBVF_MAX_DATA_PER_TXD); | 
|  | 2129 | buffer_info->length = len; | 
|  | 2130 | buffer_info->time_stamp = jiffies; | 
|  | 2131 | buffer_info->next_to_watch = i; | 
| Alexander Duyck | a7d5ca4 | 2009-12-02 16:47:37 +0000 | [diff] [blame] | 2132 | buffer_info->mapped_as_page = true; | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 2133 | buffer_info->dma = dma_map_page(&pdev->dev, | 
| Alexander Duyck | a7d5ca4 | 2009-12-02 16:47:37 +0000 | [diff] [blame] | 2134 | frag->page, | 
|  | 2135 | frag->page_offset, | 
|  | 2136 | len, | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 2137 | DMA_TO_DEVICE); | 
|  | 2138 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) | 
| Alexander Duyck | a7d5ca4 | 2009-12-02 16:47:37 +0000 | [diff] [blame] | 2139 | goto dma_error; | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2140 | } | 
|  | 2141 |  | 
|  | 2142 | tx_ring->buffer_info[i].skb = skb; | 
|  | 2143 | tx_ring->buffer_info[first].next_to_watch = i; | 
|  | 2144 |  | 
| Alexander Duyck | a7d5ca4 | 2009-12-02 16:47:37 +0000 | [diff] [blame] | 2145 | return ++count; | 
|  | 2146 |  | 
|  | 2147 | dma_error: | 
|  | 2148 | dev_err(&pdev->dev, "TX DMA map failed\n"); | 
|  | 2149 |  | 
|  | 2150 | /* clear timestamp and dma mappings for failed buffer_info mapping */ | 
|  | 2151 | buffer_info->dma = 0; | 
|  | 2152 | buffer_info->time_stamp = 0; | 
|  | 2153 | buffer_info->length = 0; | 
|  | 2154 | buffer_info->next_to_watch = 0; | 
|  | 2155 | buffer_info->mapped_as_page = false; | 
| Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 2156 | if (count) | 
|  | 2157 | count--; | 
| Alexander Duyck | a7d5ca4 | 2009-12-02 16:47:37 +0000 | [diff] [blame] | 2158 |  | 
|  | 2159 | /* clear timestamp and dma mappings for remaining portion of packet */ | 
| Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 2160 | while (count--) { | 
|  | 2161 | if (i==0) | 
| Alexander Duyck | a7d5ca4 | 2009-12-02 16:47:37 +0000 | [diff] [blame] | 2162 | i += tx_ring->count; | 
| Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 2163 | i--; | 
| Alexander Duyck | a7d5ca4 | 2009-12-02 16:47:37 +0000 | [diff] [blame] | 2164 | buffer_info = &tx_ring->buffer_info[i]; | 
|  | 2165 | igbvf_put_txbuf(adapter, buffer_info); | 
|  | 2166 | } | 
|  | 2167 |  | 
|  | 2168 | return 0; | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2169 | } | 
|  | 2170 |  | 
|  | 2171 | static inline void igbvf_tx_queue_adv(struct igbvf_adapter *adapter, | 
|  | 2172 | struct igbvf_ring *tx_ring, | 
|  | 2173 | int tx_flags, int count, u32 paylen, | 
|  | 2174 | u8 hdr_len) | 
|  | 2175 | { | 
|  | 2176 | union e1000_adv_tx_desc *tx_desc = NULL; | 
|  | 2177 | struct igbvf_buffer *buffer_info; | 
|  | 2178 | u32 olinfo_status = 0, cmd_type_len; | 
|  | 2179 | unsigned int i; | 
|  | 2180 |  | 
|  | 2181 | cmd_type_len = (E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_IFCS | | 
|  | 2182 | E1000_ADVTXD_DCMD_DEXT); | 
|  | 2183 |  | 
|  | 2184 | if (tx_flags & IGBVF_TX_FLAGS_VLAN) | 
|  | 2185 | cmd_type_len |= E1000_ADVTXD_DCMD_VLE; | 
|  | 2186 |  | 
|  | 2187 | if (tx_flags & IGBVF_TX_FLAGS_TSO) { | 
|  | 2188 | cmd_type_len |= E1000_ADVTXD_DCMD_TSE; | 
|  | 2189 |  | 
|  | 2190 | /* insert tcp checksum */ | 
|  | 2191 | olinfo_status |= E1000_TXD_POPTS_TXSM << 8; | 
|  | 2192 |  | 
|  | 2193 | /* insert ip checksum */ | 
|  | 2194 | if (tx_flags & IGBVF_TX_FLAGS_IPV4) | 
|  | 2195 | olinfo_status |= E1000_TXD_POPTS_IXSM << 8; | 
|  | 2196 |  | 
|  | 2197 | } else if (tx_flags & IGBVF_TX_FLAGS_CSUM) { | 
|  | 2198 | olinfo_status |= E1000_TXD_POPTS_TXSM << 8; | 
|  | 2199 | } | 
|  | 2200 |  | 
|  | 2201 | olinfo_status |= ((paylen - hdr_len) << E1000_ADVTXD_PAYLEN_SHIFT); | 
|  | 2202 |  | 
|  | 2203 | i = tx_ring->next_to_use; | 
|  | 2204 | while (count--) { | 
|  | 2205 | buffer_info = &tx_ring->buffer_info[i]; | 
|  | 2206 | tx_desc = IGBVF_TX_DESC_ADV(*tx_ring, i); | 
|  | 2207 | tx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); | 
|  | 2208 | tx_desc->read.cmd_type_len = | 
|  | 2209 | cpu_to_le32(cmd_type_len | buffer_info->length); | 
|  | 2210 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); | 
|  | 2211 | i++; | 
|  | 2212 | if (i == tx_ring->count) | 
|  | 2213 | i = 0; | 
|  | 2214 | } | 
|  | 2215 |  | 
|  | 2216 | tx_desc->read.cmd_type_len |= cpu_to_le32(adapter->txd_cmd); | 
|  | 2217 | /* Force memory writes to complete before letting h/w | 
|  | 2218 | * know there are new descriptors to fetch.  (Only | 
|  | 2219 | * applicable for weak-ordered memory model archs, | 
|  | 2220 | * such as IA-64). */ | 
|  | 2221 | wmb(); | 
|  | 2222 |  | 
|  | 2223 | tx_ring->next_to_use = i; | 
|  | 2224 | writel(i, adapter->hw.hw_addr + tx_ring->tail); | 
|  | 2225 | /* we need this if more than one processor can write to our tail | 
|  | 2226 | * at a time, it syncronizes IO on IA64/Altix systems */ | 
|  | 2227 | mmiowb(); | 
|  | 2228 | } | 
|  | 2229 |  | 
| Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 2230 | static netdev_tx_t igbvf_xmit_frame_ring_adv(struct sk_buff *skb, | 
|  | 2231 | struct net_device *netdev, | 
|  | 2232 | struct igbvf_ring *tx_ring) | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2233 | { | 
|  | 2234 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 2235 | unsigned int first, tx_flags = 0; | 
|  | 2236 | u8 hdr_len = 0; | 
|  | 2237 | int count = 0; | 
|  | 2238 | int tso = 0; | 
|  | 2239 |  | 
|  | 2240 | if (test_bit(__IGBVF_DOWN, &adapter->state)) { | 
|  | 2241 | dev_kfree_skb_any(skb); | 
|  | 2242 | return NETDEV_TX_OK; | 
|  | 2243 | } | 
|  | 2244 |  | 
|  | 2245 | if (skb->len <= 0) { | 
|  | 2246 | dev_kfree_skb_any(skb); | 
|  | 2247 | return NETDEV_TX_OK; | 
|  | 2248 | } | 
|  | 2249 |  | 
|  | 2250 | /* | 
|  | 2251 | * need: count + 4 desc gap to keep tail from touching | 
|  | 2252 | *       + 2 desc gap to keep tail from touching head, | 
|  | 2253 | *       + 1 desc for skb->data, | 
|  | 2254 | *       + 1 desc for context descriptor, | 
|  | 2255 | * head, otherwise try next time | 
|  | 2256 | */ | 
|  | 2257 | if (igbvf_maybe_stop_tx(netdev, skb_shinfo(skb)->nr_frags + 4)) { | 
|  | 2258 | /* this is a hard error */ | 
|  | 2259 | return NETDEV_TX_BUSY; | 
|  | 2260 | } | 
|  | 2261 |  | 
|  | 2262 | if (adapter->vlgrp && vlan_tx_tag_present(skb)) { | 
|  | 2263 | tx_flags |= IGBVF_TX_FLAGS_VLAN; | 
|  | 2264 | tx_flags |= (vlan_tx_tag_get(skb) << IGBVF_TX_FLAGS_VLAN_SHIFT); | 
|  | 2265 | } | 
|  | 2266 |  | 
|  | 2267 | if (skb->protocol == htons(ETH_P_IP)) | 
|  | 2268 | tx_flags |= IGBVF_TX_FLAGS_IPV4; | 
|  | 2269 |  | 
|  | 2270 | first = tx_ring->next_to_use; | 
|  | 2271 |  | 
|  | 2272 | tso = skb_is_gso(skb) ? | 
|  | 2273 | igbvf_tso(adapter, tx_ring, skb, tx_flags, &hdr_len) : 0; | 
|  | 2274 | if (unlikely(tso < 0)) { | 
|  | 2275 | dev_kfree_skb_any(skb); | 
|  | 2276 | return NETDEV_TX_OK; | 
|  | 2277 | } | 
|  | 2278 |  | 
|  | 2279 | if (tso) | 
|  | 2280 | tx_flags |= IGBVF_TX_FLAGS_TSO; | 
|  | 2281 | else if (igbvf_tx_csum(adapter, tx_ring, skb, tx_flags) && | 
|  | 2282 | (skb->ip_summed == CHECKSUM_PARTIAL)) | 
|  | 2283 | tx_flags |= IGBVF_TX_FLAGS_CSUM; | 
|  | 2284 |  | 
|  | 2285 | /* | 
|  | 2286 | * count reflects descriptors mapped, if 0 then mapping error | 
|  | 2287 | * has occured and we need to rewind the descriptor queue | 
|  | 2288 | */ | 
|  | 2289 | count = igbvf_tx_map_adv(adapter, tx_ring, skb, first); | 
|  | 2290 |  | 
|  | 2291 | if (count) { | 
|  | 2292 | igbvf_tx_queue_adv(adapter, tx_ring, tx_flags, count, | 
|  | 2293 | skb->len, hdr_len); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2294 | /* Make sure there is space in the ring for the next send. */ | 
|  | 2295 | igbvf_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 4); | 
|  | 2296 | } else { | 
|  | 2297 | dev_kfree_skb_any(skb); | 
|  | 2298 | tx_ring->buffer_info[first].time_stamp = 0; | 
|  | 2299 | tx_ring->next_to_use = first; | 
|  | 2300 | } | 
|  | 2301 |  | 
|  | 2302 | return NETDEV_TX_OK; | 
|  | 2303 | } | 
|  | 2304 |  | 
| Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 2305 | static netdev_tx_t igbvf_xmit_frame(struct sk_buff *skb, | 
|  | 2306 | struct net_device *netdev) | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2307 | { | 
|  | 2308 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 2309 | struct igbvf_ring *tx_ring; | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2310 |  | 
|  | 2311 | if (test_bit(__IGBVF_DOWN, &adapter->state)) { | 
|  | 2312 | dev_kfree_skb_any(skb); | 
|  | 2313 | return NETDEV_TX_OK; | 
|  | 2314 | } | 
|  | 2315 |  | 
|  | 2316 | tx_ring = &adapter->tx_ring[0]; | 
|  | 2317 |  | 
| Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 2318 | return igbvf_xmit_frame_ring_adv(skb, netdev, tx_ring); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2319 | } | 
|  | 2320 |  | 
|  | 2321 | /** | 
|  | 2322 | * igbvf_tx_timeout - Respond to a Tx Hang | 
|  | 2323 | * @netdev: network interface device structure | 
|  | 2324 | **/ | 
|  | 2325 | static void igbvf_tx_timeout(struct net_device *netdev) | 
|  | 2326 | { | 
|  | 2327 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 2328 |  | 
|  | 2329 | /* Do the reset outside of interrupt context */ | 
|  | 2330 | adapter->tx_timeout_count++; | 
|  | 2331 | schedule_work(&adapter->reset_task); | 
|  | 2332 | } | 
|  | 2333 |  | 
|  | 2334 | static void igbvf_reset_task(struct work_struct *work) | 
|  | 2335 | { | 
|  | 2336 | struct igbvf_adapter *adapter; | 
|  | 2337 | adapter = container_of(work, struct igbvf_adapter, reset_task); | 
|  | 2338 |  | 
|  | 2339 | igbvf_reinit_locked(adapter); | 
|  | 2340 | } | 
|  | 2341 |  | 
|  | 2342 | /** | 
|  | 2343 | * igbvf_get_stats - Get System Network Statistics | 
|  | 2344 | * @netdev: network interface device structure | 
|  | 2345 | * | 
|  | 2346 | * Returns the address of the device statistics structure. | 
|  | 2347 | * The statistics are actually updated from the timer callback. | 
|  | 2348 | **/ | 
|  | 2349 | static struct net_device_stats *igbvf_get_stats(struct net_device *netdev) | 
|  | 2350 | { | 
|  | 2351 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 2352 |  | 
|  | 2353 | /* only return the current stats */ | 
|  | 2354 | return &adapter->net_stats; | 
|  | 2355 | } | 
|  | 2356 |  | 
|  | 2357 | /** | 
|  | 2358 | * igbvf_change_mtu - Change the Maximum Transfer Unit | 
|  | 2359 | * @netdev: network interface device structure | 
|  | 2360 | * @new_mtu: new value for maximum frame size | 
|  | 2361 | * | 
|  | 2362 | * Returns 0 on success, negative on failure | 
|  | 2363 | **/ | 
|  | 2364 | static int igbvf_change_mtu(struct net_device *netdev, int new_mtu) | 
|  | 2365 | { | 
|  | 2366 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 2367 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; | 
|  | 2368 |  | 
|  | 2369 | if ((new_mtu < 68) || (max_frame > MAX_JUMBO_FRAME_SIZE)) { | 
|  | 2370 | dev_err(&adapter->pdev->dev, "Invalid MTU setting\n"); | 
|  | 2371 | return -EINVAL; | 
|  | 2372 | } | 
|  | 2373 |  | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2374 | #define MAX_STD_JUMBO_FRAME_SIZE 9234 | 
|  | 2375 | if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) { | 
|  | 2376 | dev_err(&adapter->pdev->dev, "MTU > 9216 not supported.\n"); | 
|  | 2377 | return -EINVAL; | 
|  | 2378 | } | 
|  | 2379 |  | 
|  | 2380 | while (test_and_set_bit(__IGBVF_RESETTING, &adapter->state)) | 
|  | 2381 | msleep(1); | 
|  | 2382 | /* igbvf_down has a dependency on max_frame_size */ | 
|  | 2383 | adapter->max_frame_size = max_frame; | 
|  | 2384 | if (netif_running(netdev)) | 
|  | 2385 | igbvf_down(adapter); | 
|  | 2386 |  | 
|  | 2387 | /* | 
|  | 2388 | * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN | 
|  | 2389 | * means we reserve 2 more, this pushes us to allocate from the next | 
|  | 2390 | * larger slab size. | 
|  | 2391 | * i.e. RXBUFFER_2048 --> size-4096 slab | 
|  | 2392 | * However with the new *_jumbo_rx* routines, jumbo receives will use | 
|  | 2393 | * fragmented skbs | 
|  | 2394 | */ | 
|  | 2395 |  | 
|  | 2396 | if (max_frame <= 1024) | 
|  | 2397 | adapter->rx_buffer_len = 1024; | 
|  | 2398 | else if (max_frame <= 2048) | 
|  | 2399 | adapter->rx_buffer_len = 2048; | 
|  | 2400 | else | 
|  | 2401 | #if (PAGE_SIZE / 2) > 16384 | 
|  | 2402 | adapter->rx_buffer_len = 16384; | 
|  | 2403 | #else | 
|  | 2404 | adapter->rx_buffer_len = PAGE_SIZE / 2; | 
|  | 2405 | #endif | 
|  | 2406 |  | 
|  | 2407 |  | 
|  | 2408 | /* adjust allocation if LPE protects us, and we aren't using SBP */ | 
|  | 2409 | if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) || | 
|  | 2410 | (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN)) | 
|  | 2411 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + | 
|  | 2412 | ETH_FCS_LEN; | 
|  | 2413 |  | 
|  | 2414 | dev_info(&adapter->pdev->dev, "changing MTU from %d to %d\n", | 
|  | 2415 | netdev->mtu, new_mtu); | 
|  | 2416 | netdev->mtu = new_mtu; | 
|  | 2417 |  | 
|  | 2418 | if (netif_running(netdev)) | 
|  | 2419 | igbvf_up(adapter); | 
|  | 2420 | else | 
|  | 2421 | igbvf_reset(adapter); | 
|  | 2422 |  | 
|  | 2423 | clear_bit(__IGBVF_RESETTING, &adapter->state); | 
|  | 2424 |  | 
|  | 2425 | return 0; | 
|  | 2426 | } | 
|  | 2427 |  | 
|  | 2428 | static int igbvf_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) | 
|  | 2429 | { | 
|  | 2430 | switch (cmd) { | 
|  | 2431 | default: | 
|  | 2432 | return -EOPNOTSUPP; | 
|  | 2433 | } | 
|  | 2434 | } | 
|  | 2435 |  | 
|  | 2436 | static int igbvf_suspend(struct pci_dev *pdev, pm_message_t state) | 
|  | 2437 | { | 
|  | 2438 | struct net_device *netdev = pci_get_drvdata(pdev); | 
|  | 2439 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 2440 | #ifdef CONFIG_PM | 
|  | 2441 | int retval = 0; | 
|  | 2442 | #endif | 
|  | 2443 |  | 
|  | 2444 | netif_device_detach(netdev); | 
|  | 2445 |  | 
|  | 2446 | if (netif_running(netdev)) { | 
|  | 2447 | WARN_ON(test_bit(__IGBVF_RESETTING, &adapter->state)); | 
|  | 2448 | igbvf_down(adapter); | 
|  | 2449 | igbvf_free_irq(adapter); | 
|  | 2450 | } | 
|  | 2451 |  | 
|  | 2452 | #ifdef CONFIG_PM | 
|  | 2453 | retval = pci_save_state(pdev); | 
|  | 2454 | if (retval) | 
|  | 2455 | return retval; | 
|  | 2456 | #endif | 
|  | 2457 |  | 
|  | 2458 | pci_disable_device(pdev); | 
|  | 2459 |  | 
|  | 2460 | return 0; | 
|  | 2461 | } | 
|  | 2462 |  | 
|  | 2463 | #ifdef CONFIG_PM | 
|  | 2464 | static int igbvf_resume(struct pci_dev *pdev) | 
|  | 2465 | { | 
|  | 2466 | struct net_device *netdev = pci_get_drvdata(pdev); | 
|  | 2467 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 2468 | u32 err; | 
|  | 2469 |  | 
|  | 2470 | pci_restore_state(pdev); | 
|  | 2471 | err = pci_enable_device_mem(pdev); | 
|  | 2472 | if (err) { | 
|  | 2473 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n"); | 
|  | 2474 | return err; | 
|  | 2475 | } | 
|  | 2476 |  | 
|  | 2477 | pci_set_master(pdev); | 
|  | 2478 |  | 
|  | 2479 | if (netif_running(netdev)) { | 
|  | 2480 | err = igbvf_request_irq(adapter); | 
|  | 2481 | if (err) | 
|  | 2482 | return err; | 
|  | 2483 | } | 
|  | 2484 |  | 
|  | 2485 | igbvf_reset(adapter); | 
|  | 2486 |  | 
|  | 2487 | if (netif_running(netdev)) | 
|  | 2488 | igbvf_up(adapter); | 
|  | 2489 |  | 
|  | 2490 | netif_device_attach(netdev); | 
|  | 2491 |  | 
|  | 2492 | return 0; | 
|  | 2493 | } | 
|  | 2494 | #endif | 
|  | 2495 |  | 
|  | 2496 | static void igbvf_shutdown(struct pci_dev *pdev) | 
|  | 2497 | { | 
|  | 2498 | igbvf_suspend(pdev, PMSG_SUSPEND); | 
|  | 2499 | } | 
|  | 2500 |  | 
|  | 2501 | #ifdef CONFIG_NET_POLL_CONTROLLER | 
|  | 2502 | /* | 
|  | 2503 | * Polling 'interrupt' - used by things like netconsole to send skbs | 
|  | 2504 | * without having to re-enable interrupts. It's not called while | 
|  | 2505 | * the interrupt routine is executing. | 
|  | 2506 | */ | 
|  | 2507 | static void igbvf_netpoll(struct net_device *netdev) | 
|  | 2508 | { | 
|  | 2509 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 2510 |  | 
|  | 2511 | disable_irq(adapter->pdev->irq); | 
|  | 2512 |  | 
|  | 2513 | igbvf_clean_tx_irq(adapter->tx_ring); | 
|  | 2514 |  | 
|  | 2515 | enable_irq(adapter->pdev->irq); | 
|  | 2516 | } | 
|  | 2517 | #endif | 
|  | 2518 |  | 
|  | 2519 | /** | 
|  | 2520 | * igbvf_io_error_detected - called when PCI error is detected | 
|  | 2521 | * @pdev: Pointer to PCI device | 
|  | 2522 | * @state: The current pci connection state | 
|  | 2523 | * | 
|  | 2524 | * This function is called after a PCI bus error affecting | 
|  | 2525 | * this device has been detected. | 
|  | 2526 | */ | 
|  | 2527 | static pci_ers_result_t igbvf_io_error_detected(struct pci_dev *pdev, | 
|  | 2528 | pci_channel_state_t state) | 
|  | 2529 | { | 
|  | 2530 | struct net_device *netdev = pci_get_drvdata(pdev); | 
|  | 2531 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 2532 |  | 
|  | 2533 | netif_device_detach(netdev); | 
|  | 2534 |  | 
| Dean Nelson | c06c430 | 2009-07-31 09:13:33 +0000 | [diff] [blame] | 2535 | if (state == pci_channel_io_perm_failure) | 
|  | 2536 | return PCI_ERS_RESULT_DISCONNECT; | 
|  | 2537 |  | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2538 | if (netif_running(netdev)) | 
|  | 2539 | igbvf_down(adapter); | 
|  | 2540 | pci_disable_device(pdev); | 
|  | 2541 |  | 
|  | 2542 | /* Request a slot slot reset. */ | 
|  | 2543 | return PCI_ERS_RESULT_NEED_RESET; | 
|  | 2544 | } | 
|  | 2545 |  | 
|  | 2546 | /** | 
|  | 2547 | * igbvf_io_slot_reset - called after the pci bus has been reset. | 
|  | 2548 | * @pdev: Pointer to PCI device | 
|  | 2549 | * | 
|  | 2550 | * Restart the card from scratch, as if from a cold-boot. Implementation | 
|  | 2551 | * resembles the first-half of the igbvf_resume routine. | 
|  | 2552 | */ | 
|  | 2553 | static pci_ers_result_t igbvf_io_slot_reset(struct pci_dev *pdev) | 
|  | 2554 | { | 
|  | 2555 | struct net_device *netdev = pci_get_drvdata(pdev); | 
|  | 2556 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 2557 |  | 
|  | 2558 | if (pci_enable_device_mem(pdev)) { | 
|  | 2559 | dev_err(&pdev->dev, | 
|  | 2560 | "Cannot re-enable PCI device after reset.\n"); | 
|  | 2561 | return PCI_ERS_RESULT_DISCONNECT; | 
|  | 2562 | } | 
|  | 2563 | pci_set_master(pdev); | 
|  | 2564 |  | 
|  | 2565 | igbvf_reset(adapter); | 
|  | 2566 |  | 
|  | 2567 | return PCI_ERS_RESULT_RECOVERED; | 
|  | 2568 | } | 
|  | 2569 |  | 
|  | 2570 | /** | 
|  | 2571 | * igbvf_io_resume - called when traffic can start flowing again. | 
|  | 2572 | * @pdev: Pointer to PCI device | 
|  | 2573 | * | 
|  | 2574 | * This callback is called when the error recovery driver tells us that | 
|  | 2575 | * its OK to resume normal operation. Implementation resembles the | 
|  | 2576 | * second-half of the igbvf_resume routine. | 
|  | 2577 | */ | 
|  | 2578 | static void igbvf_io_resume(struct pci_dev *pdev) | 
|  | 2579 | { | 
|  | 2580 | struct net_device *netdev = pci_get_drvdata(pdev); | 
|  | 2581 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 2582 |  | 
|  | 2583 | if (netif_running(netdev)) { | 
|  | 2584 | if (igbvf_up(adapter)) { | 
|  | 2585 | dev_err(&pdev->dev, | 
|  | 2586 | "can't bring device back up after reset\n"); | 
|  | 2587 | return; | 
|  | 2588 | } | 
|  | 2589 | } | 
|  | 2590 |  | 
|  | 2591 | netif_device_attach(netdev); | 
|  | 2592 | } | 
|  | 2593 |  | 
|  | 2594 | static void igbvf_print_device_info(struct igbvf_adapter *adapter) | 
|  | 2595 | { | 
|  | 2596 | struct e1000_hw *hw = &adapter->hw; | 
|  | 2597 | struct net_device *netdev = adapter->netdev; | 
|  | 2598 | struct pci_dev *pdev = adapter->pdev; | 
|  | 2599 |  | 
|  | 2600 | dev_info(&pdev->dev, "Intel(R) 82576 Virtual Function\n"); | 
| H Hartley Sweeten | 753cdc3 | 2009-12-29 20:02:29 -0800 | [diff] [blame] | 2601 | dev_info(&pdev->dev, "Address: %pM\n", netdev->dev_addr); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2602 | dev_info(&pdev->dev, "MAC: %d\n", hw->mac.type); | 
|  | 2603 | } | 
|  | 2604 |  | 
|  | 2605 | static const struct net_device_ops igbvf_netdev_ops = { | 
|  | 2606 | .ndo_open                       = igbvf_open, | 
|  | 2607 | .ndo_stop                       = igbvf_close, | 
|  | 2608 | .ndo_start_xmit                 = igbvf_xmit_frame, | 
|  | 2609 | .ndo_get_stats                  = igbvf_get_stats, | 
|  | 2610 | .ndo_set_multicast_list         = igbvf_set_multi, | 
|  | 2611 | .ndo_set_mac_address            = igbvf_set_mac, | 
|  | 2612 | .ndo_change_mtu                 = igbvf_change_mtu, | 
|  | 2613 | .ndo_do_ioctl                   = igbvf_ioctl, | 
|  | 2614 | .ndo_tx_timeout                 = igbvf_tx_timeout, | 
|  | 2615 | .ndo_vlan_rx_register           = igbvf_vlan_rx_register, | 
|  | 2616 | .ndo_vlan_rx_add_vid            = igbvf_vlan_rx_add_vid, | 
|  | 2617 | .ndo_vlan_rx_kill_vid           = igbvf_vlan_rx_kill_vid, | 
|  | 2618 | #ifdef CONFIG_NET_POLL_CONTROLLER | 
|  | 2619 | .ndo_poll_controller            = igbvf_netpoll, | 
|  | 2620 | #endif | 
|  | 2621 | }; | 
|  | 2622 |  | 
|  | 2623 | /** | 
|  | 2624 | * igbvf_probe - Device Initialization Routine | 
|  | 2625 | * @pdev: PCI device information struct | 
|  | 2626 | * @ent: entry in igbvf_pci_tbl | 
|  | 2627 | * | 
|  | 2628 | * Returns 0 on success, negative on failure | 
|  | 2629 | * | 
|  | 2630 | * igbvf_probe initializes an adapter identified by a pci_dev structure. | 
|  | 2631 | * The OS initialization, configuring of the adapter private structure, | 
|  | 2632 | * and a hardware reset occur. | 
|  | 2633 | **/ | 
|  | 2634 | static int __devinit igbvf_probe(struct pci_dev *pdev, | 
|  | 2635 | const struct pci_device_id *ent) | 
|  | 2636 | { | 
|  | 2637 | struct net_device *netdev; | 
|  | 2638 | struct igbvf_adapter *adapter; | 
|  | 2639 | struct e1000_hw *hw; | 
|  | 2640 | const struct igbvf_info *ei = igbvf_info_tbl[ent->driver_data]; | 
|  | 2641 |  | 
|  | 2642 | static int cards_found; | 
|  | 2643 | int err, pci_using_dac; | 
|  | 2644 |  | 
|  | 2645 | err = pci_enable_device_mem(pdev); | 
|  | 2646 | if (err) | 
|  | 2647 | return err; | 
|  | 2648 |  | 
|  | 2649 | pci_using_dac = 0; | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 2650 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2651 | if (!err) { | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 2652 | err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2653 | if (!err) | 
|  | 2654 | pci_using_dac = 1; | 
|  | 2655 | } else { | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 2656 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2657 | if (err) { | 
| Nick Nunley | 123e9f1 | 2010-04-27 13:09:44 +0000 | [diff] [blame] | 2658 | err = dma_set_coherent_mask(&pdev->dev, | 
|  | 2659 | DMA_BIT_MASK(32)); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2660 | if (err) { | 
|  | 2661 | dev_err(&pdev->dev, "No usable DMA " | 
|  | 2662 | "configuration, aborting\n"); | 
|  | 2663 | goto err_dma; | 
|  | 2664 | } | 
|  | 2665 | } | 
|  | 2666 | } | 
|  | 2667 |  | 
|  | 2668 | err = pci_request_regions(pdev, igbvf_driver_name); | 
|  | 2669 | if (err) | 
|  | 2670 | goto err_pci_reg; | 
|  | 2671 |  | 
|  | 2672 | pci_set_master(pdev); | 
|  | 2673 |  | 
|  | 2674 | err = -ENOMEM; | 
|  | 2675 | netdev = alloc_etherdev(sizeof(struct igbvf_adapter)); | 
|  | 2676 | if (!netdev) | 
|  | 2677 | goto err_alloc_etherdev; | 
|  | 2678 |  | 
|  | 2679 | SET_NETDEV_DEV(netdev, &pdev->dev); | 
|  | 2680 |  | 
|  | 2681 | pci_set_drvdata(pdev, netdev); | 
|  | 2682 | adapter = netdev_priv(netdev); | 
|  | 2683 | hw = &adapter->hw; | 
|  | 2684 | adapter->netdev = netdev; | 
|  | 2685 | adapter->pdev = pdev; | 
|  | 2686 | adapter->ei = ei; | 
|  | 2687 | adapter->pba = ei->pba; | 
|  | 2688 | adapter->flags = ei->flags; | 
|  | 2689 | adapter->hw.back = adapter; | 
|  | 2690 | adapter->hw.mac.type = ei->mac; | 
|  | 2691 | adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1; | 
|  | 2692 |  | 
|  | 2693 | /* PCI config space info */ | 
|  | 2694 |  | 
|  | 2695 | hw->vendor_id = pdev->vendor; | 
|  | 2696 | hw->device_id = pdev->device; | 
|  | 2697 | hw->subsystem_vendor_id = pdev->subsystem_vendor; | 
|  | 2698 | hw->subsystem_device_id = pdev->subsystem_device; | 
|  | 2699 |  | 
|  | 2700 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); | 
|  | 2701 |  | 
|  | 2702 | err = -EIO; | 
|  | 2703 | adapter->hw.hw_addr = ioremap(pci_resource_start(pdev, 0), | 
|  | 2704 | pci_resource_len(pdev, 0)); | 
|  | 2705 |  | 
|  | 2706 | if (!adapter->hw.hw_addr) | 
|  | 2707 | goto err_ioremap; | 
|  | 2708 |  | 
|  | 2709 | if (ei->get_variants) { | 
|  | 2710 | err = ei->get_variants(adapter); | 
|  | 2711 | if (err) | 
|  | 2712 | goto err_ioremap; | 
|  | 2713 | } | 
|  | 2714 |  | 
|  | 2715 | /* setup adapter struct */ | 
|  | 2716 | err = igbvf_sw_init(adapter); | 
|  | 2717 | if (err) | 
|  | 2718 | goto err_sw_init; | 
|  | 2719 |  | 
|  | 2720 | /* construct the net_device struct */ | 
|  | 2721 | netdev->netdev_ops = &igbvf_netdev_ops; | 
|  | 2722 |  | 
|  | 2723 | igbvf_set_ethtool_ops(netdev); | 
|  | 2724 | netdev->watchdog_timeo = 5 * HZ; | 
|  | 2725 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); | 
|  | 2726 |  | 
|  | 2727 | adapter->bd_number = cards_found++; | 
|  | 2728 |  | 
|  | 2729 | netdev->features = NETIF_F_SG | | 
|  | 2730 | NETIF_F_IP_CSUM | | 
|  | 2731 | NETIF_F_HW_VLAN_TX | | 
|  | 2732 | NETIF_F_HW_VLAN_RX | | 
|  | 2733 | NETIF_F_HW_VLAN_FILTER; | 
|  | 2734 |  | 
|  | 2735 | netdev->features |= NETIF_F_IPV6_CSUM; | 
|  | 2736 | netdev->features |= NETIF_F_TSO; | 
|  | 2737 | netdev->features |= NETIF_F_TSO6; | 
|  | 2738 |  | 
|  | 2739 | if (pci_using_dac) | 
|  | 2740 | netdev->features |= NETIF_F_HIGHDMA; | 
|  | 2741 |  | 
|  | 2742 | netdev->vlan_features |= NETIF_F_TSO; | 
|  | 2743 | netdev->vlan_features |= NETIF_F_TSO6; | 
|  | 2744 | netdev->vlan_features |= NETIF_F_IP_CSUM; | 
|  | 2745 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; | 
|  | 2746 | netdev->vlan_features |= NETIF_F_SG; | 
|  | 2747 |  | 
|  | 2748 | /*reset the controller to put the device in a known good state */ | 
|  | 2749 | err = hw->mac.ops.reset_hw(hw); | 
|  | 2750 | if (err) { | 
|  | 2751 | dev_info(&pdev->dev, | 
| Williams, Mitch A | 1242b6f | 2009-12-23 13:22:43 +0000 | [diff] [blame] | 2752 | "PF still in reset state, assigning new address." | 
|  | 2753 | " Is the PF interface up?\n"); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2754 | random_ether_addr(hw->mac.addr); | 
|  | 2755 | } else { | 
|  | 2756 | err = hw->mac.ops.read_mac_addr(hw); | 
|  | 2757 | if (err) { | 
|  | 2758 | dev_err(&pdev->dev, "Error reading MAC address\n"); | 
|  | 2759 | goto err_hw_init; | 
|  | 2760 | } | 
|  | 2761 | } | 
|  | 2762 |  | 
|  | 2763 | memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); | 
|  | 2764 | memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len); | 
|  | 2765 |  | 
|  | 2766 | if (!is_valid_ether_addr(netdev->perm_addr)) { | 
| H Hartley Sweeten | 753cdc3 | 2009-12-29 20:02:29 -0800 | [diff] [blame] | 2767 | dev_err(&pdev->dev, "Invalid MAC Address: %pM\n", | 
|  | 2768 | netdev->dev_addr); | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2769 | err = -EIO; | 
|  | 2770 | goto err_hw_init; | 
|  | 2771 | } | 
|  | 2772 |  | 
|  | 2773 | setup_timer(&adapter->watchdog_timer, &igbvf_watchdog, | 
|  | 2774 | (unsigned long) adapter); | 
|  | 2775 |  | 
|  | 2776 | INIT_WORK(&adapter->reset_task, igbvf_reset_task); | 
|  | 2777 | INIT_WORK(&adapter->watchdog_task, igbvf_watchdog_task); | 
|  | 2778 |  | 
|  | 2779 | /* ring size defaults */ | 
|  | 2780 | adapter->rx_ring->count = 1024; | 
|  | 2781 | adapter->tx_ring->count = 1024; | 
|  | 2782 |  | 
|  | 2783 | /* reset the hardware with the new settings */ | 
|  | 2784 | igbvf_reset(adapter); | 
|  | 2785 |  | 
|  | 2786 | /* tell the stack to leave us alone until igbvf_open() is called */ | 
|  | 2787 | netif_carrier_off(netdev); | 
|  | 2788 | netif_stop_queue(netdev); | 
|  | 2789 |  | 
|  | 2790 | strcpy(netdev->name, "eth%d"); | 
|  | 2791 | err = register_netdev(netdev); | 
|  | 2792 | if (err) | 
|  | 2793 | goto err_hw_init; | 
|  | 2794 |  | 
|  | 2795 | igbvf_print_device_info(adapter); | 
|  | 2796 |  | 
|  | 2797 | igbvf_initialize_last_counter_stats(adapter); | 
|  | 2798 |  | 
|  | 2799 | return 0; | 
|  | 2800 |  | 
|  | 2801 | err_hw_init: | 
|  | 2802 | kfree(adapter->tx_ring); | 
|  | 2803 | kfree(adapter->rx_ring); | 
|  | 2804 | err_sw_init: | 
|  | 2805 | igbvf_reset_interrupt_capability(adapter); | 
|  | 2806 | iounmap(adapter->hw.hw_addr); | 
|  | 2807 | err_ioremap: | 
|  | 2808 | free_netdev(netdev); | 
|  | 2809 | err_alloc_etherdev: | 
|  | 2810 | pci_release_regions(pdev); | 
|  | 2811 | err_pci_reg: | 
|  | 2812 | err_dma: | 
|  | 2813 | pci_disable_device(pdev); | 
|  | 2814 | return err; | 
|  | 2815 | } | 
|  | 2816 |  | 
|  | 2817 | /** | 
|  | 2818 | * igbvf_remove - Device Removal Routine | 
|  | 2819 | * @pdev: PCI device information struct | 
|  | 2820 | * | 
|  | 2821 | * igbvf_remove is called by the PCI subsystem to alert the driver | 
|  | 2822 | * that it should release a PCI device.  The could be caused by a | 
|  | 2823 | * Hot-Plug event, or because the driver is going to be removed from | 
|  | 2824 | * memory. | 
|  | 2825 | **/ | 
|  | 2826 | static void __devexit igbvf_remove(struct pci_dev *pdev) | 
|  | 2827 | { | 
|  | 2828 | struct net_device *netdev = pci_get_drvdata(pdev); | 
|  | 2829 | struct igbvf_adapter *adapter = netdev_priv(netdev); | 
|  | 2830 | struct e1000_hw *hw = &adapter->hw; | 
|  | 2831 |  | 
|  | 2832 | /* | 
|  | 2833 | * flush_scheduled work may reschedule our watchdog task, so | 
|  | 2834 | * explicitly disable watchdog tasks from being rescheduled | 
|  | 2835 | */ | 
|  | 2836 | set_bit(__IGBVF_DOWN, &adapter->state); | 
|  | 2837 | del_timer_sync(&adapter->watchdog_timer); | 
|  | 2838 |  | 
|  | 2839 | flush_scheduled_work(); | 
|  | 2840 |  | 
|  | 2841 | unregister_netdev(netdev); | 
|  | 2842 |  | 
|  | 2843 | igbvf_reset_interrupt_capability(adapter); | 
|  | 2844 |  | 
|  | 2845 | /* | 
|  | 2846 | * it is important to delete the napi struct prior to freeing the | 
|  | 2847 | * rx ring so that you do not end up with null pointer refs | 
|  | 2848 | */ | 
|  | 2849 | netif_napi_del(&adapter->rx_ring->napi); | 
|  | 2850 | kfree(adapter->tx_ring); | 
|  | 2851 | kfree(adapter->rx_ring); | 
|  | 2852 |  | 
|  | 2853 | iounmap(hw->hw_addr); | 
|  | 2854 | if (hw->flash_address) | 
|  | 2855 | iounmap(hw->flash_address); | 
|  | 2856 | pci_release_regions(pdev); | 
|  | 2857 |  | 
|  | 2858 | free_netdev(netdev); | 
|  | 2859 |  | 
|  | 2860 | pci_disable_device(pdev); | 
|  | 2861 | } | 
|  | 2862 |  | 
|  | 2863 | /* PCI Error Recovery (ERS) */ | 
|  | 2864 | static struct pci_error_handlers igbvf_err_handler = { | 
|  | 2865 | .error_detected = igbvf_io_error_detected, | 
|  | 2866 | .slot_reset = igbvf_io_slot_reset, | 
|  | 2867 | .resume = igbvf_io_resume, | 
|  | 2868 | }; | 
|  | 2869 |  | 
| Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 2870 | static DEFINE_PCI_DEVICE_TABLE(igbvf_pci_tbl) = { | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2871 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_VF), board_vf }, | 
|  | 2872 | { } /* terminate list */ | 
|  | 2873 | }; | 
|  | 2874 | MODULE_DEVICE_TABLE(pci, igbvf_pci_tbl); | 
|  | 2875 |  | 
|  | 2876 | /* PCI Device API Driver */ | 
|  | 2877 | static struct pci_driver igbvf_driver = { | 
|  | 2878 | .name     = igbvf_driver_name, | 
|  | 2879 | .id_table = igbvf_pci_tbl, | 
|  | 2880 | .probe    = igbvf_probe, | 
|  | 2881 | .remove   = __devexit_p(igbvf_remove), | 
|  | 2882 | #ifdef CONFIG_PM | 
|  | 2883 | /* Power Management Hooks */ | 
|  | 2884 | .suspend  = igbvf_suspend, | 
|  | 2885 | .resume   = igbvf_resume, | 
|  | 2886 | #endif | 
|  | 2887 | .shutdown = igbvf_shutdown, | 
|  | 2888 | .err_handler = &igbvf_err_handler | 
|  | 2889 | }; | 
|  | 2890 |  | 
|  | 2891 | /** | 
|  | 2892 | * igbvf_init_module - Driver Registration Routine | 
|  | 2893 | * | 
|  | 2894 | * igbvf_init_module is the first routine called when the driver is | 
|  | 2895 | * loaded. All it does is register with the PCI subsystem. | 
|  | 2896 | **/ | 
|  | 2897 | static int __init igbvf_init_module(void) | 
|  | 2898 | { | 
|  | 2899 | int ret; | 
|  | 2900 | printk(KERN_INFO "%s - version %s\n", | 
|  | 2901 | igbvf_driver_string, igbvf_driver_version); | 
|  | 2902 | printk(KERN_INFO "%s\n", igbvf_copyright); | 
|  | 2903 |  | 
|  | 2904 | ret = pci_register_driver(&igbvf_driver); | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 2905 | igbvf_driver_pm_qos_req = pm_qos_add_request(PM_QOS_CPU_DMA_LATENCY, | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2906 | PM_QOS_DEFAULT_VALUE); | 
|  | 2907 |  | 
|  | 2908 | return ret; | 
|  | 2909 | } | 
|  | 2910 | module_init(igbvf_init_module); | 
|  | 2911 |  | 
|  | 2912 | /** | 
|  | 2913 | * igbvf_exit_module - Driver Exit Cleanup Routine | 
|  | 2914 | * | 
|  | 2915 | * igbvf_exit_module is called just before the driver is removed | 
|  | 2916 | * from memory. | 
|  | 2917 | **/ | 
|  | 2918 | static void __exit igbvf_exit_module(void) | 
|  | 2919 | { | 
|  | 2920 | pci_unregister_driver(&igbvf_driver); | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 2921 | pm_qos_remove_request(igbvf_driver_pm_qos_req); | 
|  | 2922 | igbvf_driver_pm_qos_req = NULL; | 
| Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 2923 | } | 
|  | 2924 | module_exit(igbvf_exit_module); | 
|  | 2925 |  | 
|  | 2926 |  | 
|  | 2927 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); | 
|  | 2928 | MODULE_DESCRIPTION("Intel(R) 82576 Virtual Function Network Driver"); | 
|  | 2929 | MODULE_LICENSE("GPL"); | 
|  | 2930 | MODULE_VERSION(DRV_VERSION); | 
|  | 2931 |  | 
|  | 2932 | /* netdev.c */ |