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