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