blob: 13989ef357502829a5e7b80948d08e1cba3c9899 [file] [log] [blame]
Greg Rose5eae00c2013-12-21 06:12:45 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
Mitch Williamse1dfee82014-02-13 03:48:51 -08004 * Copyright(c) 2013 - 2014 Intel Corporation.
Greg Rose5eae00c2013-12-21 06:12:45 +00005 *
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 *
Jesse Brandeburgb8316072014-04-05 07:46:11 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
Greg Rose5eae00c2013-12-21 06:12:45 +000018 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27#include "i40evf.h"
28#include "i40e_prototype.h"
29static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter);
30static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter);
Mitch Williams169f4072014-04-01 07:11:50 +000031static void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter);
32static void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +000033static int i40evf_close(struct net_device *netdev);
34
35char i40evf_driver_name[] = "i40evf";
36static const char i40evf_driver_string[] =
37 "Intel(R) XL710 X710 Virtual Function Network Driver";
38
Catherine Sullivanded7b9a2014-04-01 07:11:57 +000039#define DRV_VERSION "0.9.23"
Greg Rose5eae00c2013-12-21 06:12:45 +000040const char i40evf_driver_version[] = DRV_VERSION;
41static const char i40evf_copyright[] =
Mitch Williams673f2eb2014-02-20 19:29:13 -080042 "Copyright (c) 2013 - 2014 Intel Corporation.";
Greg Rose5eae00c2013-12-21 06:12:45 +000043
44/* i40evf_pci_tbl - PCI Device ID Table
45 *
46 * Wildcard entries (PCI_ANY_ID) should come last
47 * Last entry must be all 0s
48 *
49 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
50 * Class, Class Mask, private data (not used) }
51 */
52static DEFINE_PCI_DEVICE_TABLE(i40evf_pci_tbl) = {
Shannon Nelsonab600852014-01-17 15:36:39 -080053 {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF), 0},
Greg Rose5eae00c2013-12-21 06:12:45 +000054 /* required last entry */
55 {0, }
56};
57
58MODULE_DEVICE_TABLE(pci, i40evf_pci_tbl);
59
60MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
61MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver");
62MODULE_LICENSE("GPL");
63MODULE_VERSION(DRV_VERSION);
64
65/**
66 * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code
67 * @hw: pointer to the HW structure
68 * @mem: ptr to mem struct to fill out
69 * @size: size of memory requested
70 * @alignment: what to align the allocation to
71 **/
72i40e_status i40evf_allocate_dma_mem_d(struct i40e_hw *hw,
73 struct i40e_dma_mem *mem,
74 u64 size, u32 alignment)
75{
76 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
77
78 if (!mem)
79 return I40E_ERR_PARAM;
80
81 mem->size = ALIGN(size, alignment);
82 mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size,
83 (dma_addr_t *)&mem->pa, GFP_KERNEL);
84 if (mem->va)
85 return 0;
86 else
87 return I40E_ERR_NO_MEMORY;
88}
89
90/**
91 * i40evf_free_dma_mem_d - OS specific memory free for shared code
92 * @hw: pointer to the HW structure
93 * @mem: ptr to mem struct to free
94 **/
95i40e_status i40evf_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
96{
97 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
98
99 if (!mem || !mem->va)
100 return I40E_ERR_PARAM;
101 dma_free_coherent(&adapter->pdev->dev, mem->size,
102 mem->va, (dma_addr_t)mem->pa);
103 return 0;
104}
105
106/**
107 * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code
108 * @hw: pointer to the HW structure
109 * @mem: ptr to mem struct to fill out
110 * @size: size of memory requested
111 **/
112i40e_status i40evf_allocate_virt_mem_d(struct i40e_hw *hw,
113 struct i40e_virt_mem *mem, u32 size)
114{
115 if (!mem)
116 return I40E_ERR_PARAM;
117
118 mem->size = size;
119 mem->va = kzalloc(size, GFP_KERNEL);
120
121 if (mem->va)
122 return 0;
123 else
124 return I40E_ERR_NO_MEMORY;
125}
126
127/**
128 * i40evf_free_virt_mem_d - OS specific memory free for shared code
129 * @hw: pointer to the HW structure
130 * @mem: ptr to mem struct to free
131 **/
132i40e_status i40evf_free_virt_mem_d(struct i40e_hw *hw,
133 struct i40e_virt_mem *mem)
134{
135 if (!mem)
136 return I40E_ERR_PARAM;
137
138 /* it's ok to kfree a NULL pointer */
139 kfree(mem->va);
140
141 return 0;
142}
143
144/**
145 * i40evf_debug_d - OS dependent version of debug printing
146 * @hw: pointer to the HW structure
147 * @mask: debug level mask
148 * @fmt_str: printf-type format description
149 **/
150void i40evf_debug_d(void *hw, u32 mask, char *fmt_str, ...)
151{
152 char buf[512];
153 va_list argptr;
154
155 if (!(mask & ((struct i40e_hw *)hw)->debug_mask))
156 return;
157
158 va_start(argptr, fmt_str);
159 vsnprintf(buf, sizeof(buf), fmt_str, argptr);
160 va_end(argptr);
161
162 /* the debug string is already formatted with a newline */
163 pr_info("%s", buf);
164}
165
166/**
167 * i40evf_tx_timeout - Respond to a Tx Hang
168 * @netdev: network interface device structure
169 **/
170static void i40evf_tx_timeout(struct net_device *netdev)
171{
172 struct i40evf_adapter *adapter = netdev_priv(netdev);
173
174 adapter->tx_timeout_count++;
Mitch Williams625777e2014-02-20 19:29:05 -0800175 dev_info(&adapter->pdev->dev, "TX timeout detected.\n");
176 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
Mitch Williams3526d802014-03-06 08:59:56 +0000177 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
Mitch Williams625777e2014-02-20 19:29:05 -0800178 schedule_work(&adapter->reset_task);
179 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000180}
181
182/**
183 * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC
184 * @adapter: board private structure
185 **/
186static void i40evf_misc_irq_disable(struct i40evf_adapter *adapter)
187{
188 struct i40e_hw *hw = &adapter->hw;
189 wr32(hw, I40E_VFINT_DYN_CTL01, 0);
190
191 /* read flush */
192 rd32(hw, I40E_VFGEN_RSTAT);
193
194 synchronize_irq(adapter->msix_entries[0].vector);
195}
196
197/**
198 * i40evf_misc_irq_enable - Enable default interrupt generation settings
199 * @adapter: board private structure
200 **/
201static void i40evf_misc_irq_enable(struct i40evf_adapter *adapter)
202{
203 struct i40e_hw *hw = &adapter->hw;
204 wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK |
205 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK);
206 wr32(hw, I40E_VFINT_ICR0_ENA1, I40E_VFINT_ICR0_ENA_ADMINQ_MASK);
207
208 /* read flush */
209 rd32(hw, I40E_VFGEN_RSTAT);
210}
211
212/**
213 * i40evf_irq_disable - Mask off interrupt generation on the NIC
214 * @adapter: board private structure
215 **/
216static void i40evf_irq_disable(struct i40evf_adapter *adapter)
217{
218 int i;
219 struct i40e_hw *hw = &adapter->hw;
220
Mitch Williamsdbb01c82014-02-20 19:29:07 -0800221 if (!adapter->msix_entries)
222 return;
223
Greg Rose5eae00c2013-12-21 06:12:45 +0000224 for (i = 1; i < adapter->num_msix_vectors; i++) {
225 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), 0);
226 synchronize_irq(adapter->msix_entries[i].vector);
227 }
228 /* read flush */
229 rd32(hw, I40E_VFGEN_RSTAT);
230
231}
232
233/**
234 * i40evf_irq_enable_queues - Enable interrupt for specified queues
235 * @adapter: board private structure
236 * @mask: bitmap of queues to enable
237 **/
238void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask)
239{
240 struct i40e_hw *hw = &adapter->hw;
241 int i;
242
243 for (i = 1; i < adapter->num_msix_vectors; i++) {
244 if (mask & (1 << (i - 1))) {
245 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1),
246 I40E_VFINT_DYN_CTLN1_INTENA_MASK |
247 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
248 }
249 }
250}
251
252/**
253 * i40evf_fire_sw_int - Generate SW interrupt for specified vectors
254 * @adapter: board private structure
255 * @mask: bitmap of vectors to trigger
256 **/
257static void i40evf_fire_sw_int(struct i40evf_adapter *adapter,
258 u32 mask)
259{
260 struct i40e_hw *hw = &adapter->hw;
261 int i;
262 uint32_t dyn_ctl;
263
264 for (i = 1; i < adapter->num_msix_vectors; i++) {
265 if (mask & (1 << i)) {
266 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTLN1(i - 1));
267 dyn_ctl |= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK |
268 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK;
269 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), dyn_ctl);
270 }
271 }
272}
273
274/**
275 * i40evf_irq_enable - Enable default interrupt generation settings
276 * @adapter: board private structure
277 **/
278void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush)
279{
280 struct i40e_hw *hw = &adapter->hw;
281
282 i40evf_irq_enable_queues(adapter, ~0);
283
284 if (flush)
285 rd32(hw, I40E_VFGEN_RSTAT);
286}
287
288/**
289 * i40evf_msix_aq - Interrupt handler for vector 0
290 * @irq: interrupt number
291 * @data: pointer to netdev
292 **/
293static irqreturn_t i40evf_msix_aq(int irq, void *data)
294{
295 struct net_device *netdev = data;
296 struct i40evf_adapter *adapter = netdev_priv(netdev);
297 struct i40e_hw *hw = &adapter->hw;
298 u32 val;
299 u32 ena_mask;
300
301 /* handle non-queue interrupts */
302 val = rd32(hw, I40E_VFINT_ICR01);
303 ena_mask = rd32(hw, I40E_VFINT_ICR0_ENA1);
304
305
306 val = rd32(hw, I40E_VFINT_DYN_CTL01);
307 val = val | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK;
308 wr32(hw, I40E_VFINT_DYN_CTL01, val);
309
310 /* re-enable interrupt causes */
311 wr32(hw, I40E_VFINT_ICR0_ENA1, ena_mask);
312 wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK);
313
314 /* schedule work on the private workqueue */
315 schedule_work(&adapter->adminq_task);
316
317 return IRQ_HANDLED;
318}
319
320/**
321 * i40evf_msix_clean_rings - MSIX mode Interrupt Handler
322 * @irq: interrupt number
323 * @data: pointer to a q_vector
324 **/
325static irqreturn_t i40evf_msix_clean_rings(int irq, void *data)
326{
327 struct i40e_q_vector *q_vector = data;
328
329 if (!q_vector->tx.ring && !q_vector->rx.ring)
330 return IRQ_HANDLED;
331
332 napi_schedule(&q_vector->napi);
333
334 return IRQ_HANDLED;
335}
336
337/**
338 * i40evf_map_vector_to_rxq - associate irqs with rx queues
339 * @adapter: board private structure
340 * @v_idx: interrupt number
341 * @r_idx: queue number
342 **/
343static void
344i40evf_map_vector_to_rxq(struct i40evf_adapter *adapter, int v_idx, int r_idx)
345{
346 struct i40e_q_vector *q_vector = adapter->q_vector[v_idx];
347 struct i40e_ring *rx_ring = adapter->rx_rings[r_idx];
348
349 rx_ring->q_vector = q_vector;
350 rx_ring->next = q_vector->rx.ring;
351 rx_ring->vsi = &adapter->vsi;
352 q_vector->rx.ring = rx_ring;
353 q_vector->rx.count++;
354 q_vector->rx.latency_range = I40E_LOW_LATENCY;
355}
356
357/**
358 * i40evf_map_vector_to_txq - associate irqs with tx queues
359 * @adapter: board private structure
360 * @v_idx: interrupt number
361 * @t_idx: queue number
362 **/
363static void
364i40evf_map_vector_to_txq(struct i40evf_adapter *adapter, int v_idx, int t_idx)
365{
366 struct i40e_q_vector *q_vector = adapter->q_vector[v_idx];
367 struct i40e_ring *tx_ring = adapter->tx_rings[t_idx];
368
369 tx_ring->q_vector = q_vector;
370 tx_ring->next = q_vector->tx.ring;
371 tx_ring->vsi = &adapter->vsi;
372 q_vector->tx.ring = tx_ring;
373 q_vector->tx.count++;
374 q_vector->tx.latency_range = I40E_LOW_LATENCY;
375 q_vector->num_ringpairs++;
376 q_vector->ring_mask |= (1 << t_idx);
377}
378
379/**
380 * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors
381 * @adapter: board private structure to initialize
382 *
383 * This function maps descriptor rings to the queue-specific vectors
384 * we were allotted through the MSI-X enabling code. Ideally, we'd have
385 * one vector per ring/queue, but on a constrained vector budget, we
386 * group the rings as "efficiently" as possible. You would add new
387 * mapping configurations in here.
388 **/
389static int i40evf_map_rings_to_vectors(struct i40evf_adapter *adapter)
390{
391 int q_vectors;
392 int v_start = 0;
393 int rxr_idx = 0, txr_idx = 0;
394 int rxr_remaining = adapter->vsi_res->num_queue_pairs;
395 int txr_remaining = adapter->vsi_res->num_queue_pairs;
396 int i, j;
397 int rqpv, tqpv;
398 int err = 0;
399
400 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
401
402 /* The ideal configuration...
403 * We have enough vectors to map one per queue.
404 */
405 if (q_vectors == (rxr_remaining * 2)) {
406 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
407 i40evf_map_vector_to_rxq(adapter, v_start, rxr_idx);
408
409 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
410 i40evf_map_vector_to_txq(adapter, v_start, txr_idx);
411 goto out;
412 }
413
414 /* If we don't have enough vectors for a 1-to-1
415 * mapping, we'll have to group them so there are
416 * multiple queues per vector.
417 * Re-adjusting *qpv takes care of the remainder.
418 */
419 for (i = v_start; i < q_vectors; i++) {
420 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
421 for (j = 0; j < rqpv; j++) {
422 i40evf_map_vector_to_rxq(adapter, i, rxr_idx);
423 rxr_idx++;
424 rxr_remaining--;
425 }
426 }
427 for (i = v_start; i < q_vectors; i++) {
428 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
429 for (j = 0; j < tqpv; j++) {
430 i40evf_map_vector_to_txq(adapter, i, txr_idx);
431 txr_idx++;
432 txr_remaining--;
433 }
434 }
435
436out:
437 adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
438
439 return err;
440}
441
442/**
443 * i40evf_request_traffic_irqs - Initialize MSI-X interrupts
444 * @adapter: board private structure
445 *
446 * Allocates MSI-X vectors for tx and rx handling, and requests
447 * interrupts from the kernel.
448 **/
449static int
450i40evf_request_traffic_irqs(struct i40evf_adapter *adapter, char *basename)
451{
452 int vector, err, q_vectors;
453 int rx_int_idx = 0, tx_int_idx = 0;
454
455 i40evf_irq_disable(adapter);
456 /* Decrement for Other and TCP Timer vectors */
457 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
458
459 for (vector = 0; vector < q_vectors; vector++) {
460 struct i40e_q_vector *q_vector = adapter->q_vector[vector];
461
462 if (q_vector->tx.ring && q_vector->rx.ring) {
463 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
464 "i40evf-%s-%s-%d", basename,
465 "TxRx", rx_int_idx++);
466 tx_int_idx++;
467 } else if (q_vector->rx.ring) {
468 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
469 "i40evf-%s-%s-%d", basename,
470 "rx", rx_int_idx++);
471 } else if (q_vector->tx.ring) {
472 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
473 "i40evf-%s-%s-%d", basename,
474 "tx", tx_int_idx++);
475 } else {
476 /* skip this unused q_vector */
477 continue;
478 }
479 err = request_irq(
480 adapter->msix_entries[vector + NONQ_VECS].vector,
481 i40evf_msix_clean_rings,
482 0,
483 q_vector->name,
484 q_vector);
485 if (err) {
486 dev_info(&adapter->pdev->dev,
487 "%s: request_irq failed, error: %d\n",
488 __func__, err);
489 goto free_queue_irqs;
490 }
491 /* assign the mask for this irq */
492 irq_set_affinity_hint(
493 adapter->msix_entries[vector + NONQ_VECS].vector,
494 q_vector->affinity_mask);
495 }
496
497 return 0;
498
499free_queue_irqs:
500 while (vector) {
501 vector--;
502 irq_set_affinity_hint(
503 adapter->msix_entries[vector + NONQ_VECS].vector,
504 NULL);
505 free_irq(adapter->msix_entries[vector + NONQ_VECS].vector,
506 adapter->q_vector[vector]);
507 }
508 return err;
509}
510
511/**
512 * i40evf_request_misc_irq - Initialize MSI-X interrupts
513 * @adapter: board private structure
514 *
515 * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
516 * vector is only for the admin queue, and stays active even when the netdev
517 * is closed.
518 **/
519static int i40evf_request_misc_irq(struct i40evf_adapter *adapter)
520{
521 struct net_device *netdev = adapter->netdev;
522 int err;
523
Mitch Williamse1dfee82014-02-13 03:48:51 -0800524 sprintf(adapter->misc_vector_name, "i40evf:mbx");
Greg Rose5eae00c2013-12-21 06:12:45 +0000525 err = request_irq(adapter->msix_entries[0].vector,
Mitch Williamse1dfee82014-02-13 03:48:51 -0800526 &i40evf_msix_aq, 0,
527 adapter->misc_vector_name, netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +0000528 if (err) {
529 dev_err(&adapter->pdev->dev,
Catherine Sullivan77fa28b2014-02-20 19:29:17 -0800530 "request_irq for %s failed: %d\n",
531 adapter->misc_vector_name, err);
Greg Rose5eae00c2013-12-21 06:12:45 +0000532 free_irq(adapter->msix_entries[0].vector, netdev);
533 }
534 return err;
535}
536
537/**
538 * i40evf_free_traffic_irqs - Free MSI-X interrupts
539 * @adapter: board private structure
540 *
541 * Frees all MSI-X vectors other than 0.
542 **/
543static void i40evf_free_traffic_irqs(struct i40evf_adapter *adapter)
544{
545 int i;
546 int q_vectors;
547 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
548
549 for (i = 0; i < q_vectors; i++) {
550 irq_set_affinity_hint(adapter->msix_entries[i+1].vector,
551 NULL);
552 free_irq(adapter->msix_entries[i+1].vector,
553 adapter->q_vector[i]);
554 }
555}
556
557/**
558 * i40evf_free_misc_irq - Free MSI-X miscellaneous vector
559 * @adapter: board private structure
560 *
561 * Frees MSI-X vector 0.
562 **/
563static void i40evf_free_misc_irq(struct i40evf_adapter *adapter)
564{
565 struct net_device *netdev = adapter->netdev;
566
567 free_irq(adapter->msix_entries[0].vector, netdev);
568}
569
570/**
571 * i40evf_configure_tx - Configure Transmit Unit after Reset
572 * @adapter: board private structure
573 *
574 * Configure the Tx unit of the MAC after a reset.
575 **/
576static void i40evf_configure_tx(struct i40evf_adapter *adapter)
577{
578 struct i40e_hw *hw = &adapter->hw;
579 int i;
580 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++)
581 adapter->tx_rings[i]->tail = hw->hw_addr + I40E_QTX_TAIL1(i);
582}
583
584/**
585 * i40evf_configure_rx - Configure Receive Unit after Reset
586 * @adapter: board private structure
587 *
588 * Configure the Rx unit of the MAC after a reset.
589 **/
590static void i40evf_configure_rx(struct i40evf_adapter *adapter)
591{
592 struct i40e_hw *hw = &adapter->hw;
593 struct net_device *netdev = adapter->netdev;
594 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
595 int i;
596 int rx_buf_len;
597
598
599 adapter->flags &= ~I40EVF_FLAG_RX_PS_CAPABLE;
600 adapter->flags |= I40EVF_FLAG_RX_1BUF_CAPABLE;
601
602 /* Decide whether to use packet split mode or not */
603 if (netdev->mtu > ETH_DATA_LEN) {
604 if (adapter->flags & I40EVF_FLAG_RX_PS_CAPABLE)
605 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
606 else
607 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
608 } else {
609 if (adapter->flags & I40EVF_FLAG_RX_1BUF_CAPABLE)
610 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
611 else
612 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
613 }
614
615 /* Set the RX buffer length according to the mode */
616 if (adapter->flags & I40EVF_FLAG_RX_PS_ENABLED) {
617 rx_buf_len = I40E_RX_HDR_SIZE;
618 } else {
619 if (netdev->mtu <= ETH_DATA_LEN)
620 rx_buf_len = I40EVF_RXBUFFER_2048;
621 else
622 rx_buf_len = ALIGN(max_frame, 1024);
623 }
624
625 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
626 adapter->rx_rings[i]->tail = hw->hw_addr + I40E_QRX_TAIL1(i);
627 adapter->rx_rings[i]->rx_buf_len = rx_buf_len;
628 }
629}
630
631/**
632 * i40evf_find_vlan - Search filter list for specific vlan filter
633 * @adapter: board private structure
634 * @vlan: vlan tag
635 *
636 * Returns ptr to the filter object or NULL
637 **/
638static struct
639i40evf_vlan_filter *i40evf_find_vlan(struct i40evf_adapter *adapter, u16 vlan)
640{
641 struct i40evf_vlan_filter *f;
642
643 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
644 if (vlan == f->vlan)
645 return f;
646 }
647 return NULL;
648}
649
650/**
651 * i40evf_add_vlan - Add a vlan filter to the list
652 * @adapter: board private structure
653 * @vlan: VLAN tag
654 *
655 * Returns ptr to the filter object or NULL when no memory available.
656 **/
657static struct
658i40evf_vlan_filter *i40evf_add_vlan(struct i40evf_adapter *adapter, u16 vlan)
659{
660 struct i40evf_vlan_filter *f;
661
662 f = i40evf_find_vlan(adapter, vlan);
663 if (NULL == f) {
664 f = kzalloc(sizeof(*f), GFP_ATOMIC);
665 if (NULL == f) {
666 dev_info(&adapter->pdev->dev,
667 "%s: no memory for new VLAN filter\n",
668 __func__);
669 return NULL;
670 }
671 f->vlan = vlan;
672
673 INIT_LIST_HEAD(&f->list);
674 list_add(&f->list, &adapter->vlan_filter_list);
675 f->add = true;
676 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
677 }
678
679 return f;
680}
681
682/**
683 * i40evf_del_vlan - Remove a vlan filter from the list
684 * @adapter: board private structure
685 * @vlan: VLAN tag
686 **/
687static void i40evf_del_vlan(struct i40evf_adapter *adapter, u16 vlan)
688{
689 struct i40evf_vlan_filter *f;
690
691 f = i40evf_find_vlan(adapter, vlan);
692 if (f) {
693 f->remove = true;
694 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
695 }
696 return;
697}
698
699/**
700 * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device
701 * @netdev: network device struct
702 * @vid: VLAN tag
703 **/
704static int i40evf_vlan_rx_add_vid(struct net_device *netdev,
705 __always_unused __be16 proto, u16 vid)
706{
707 struct i40evf_adapter *adapter = netdev_priv(netdev);
708
709 if (i40evf_add_vlan(adapter, vid) == NULL)
710 return -ENOMEM;
711 return 0;
712}
713
714/**
715 * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device
716 * @netdev: network device struct
717 * @vid: VLAN tag
718 **/
719static int i40evf_vlan_rx_kill_vid(struct net_device *netdev,
720 __always_unused __be16 proto, u16 vid)
721{
722 struct i40evf_adapter *adapter = netdev_priv(netdev);
723
724 i40evf_del_vlan(adapter, vid);
725 return 0;
726}
727
728/**
729 * i40evf_find_filter - Search filter list for specific mac filter
730 * @adapter: board private structure
731 * @macaddr: the MAC address
732 *
733 * Returns ptr to the filter object or NULL
734 **/
735static struct
736i40evf_mac_filter *i40evf_find_filter(struct i40evf_adapter *adapter,
737 u8 *macaddr)
738{
739 struct i40evf_mac_filter *f;
740
741 if (!macaddr)
742 return NULL;
743
744 list_for_each_entry(f, &adapter->mac_filter_list, list) {
745 if (ether_addr_equal(macaddr, f->macaddr))
746 return f;
747 }
748 return NULL;
749}
750
751/**
752 * i40e_add_filter - Add a mac filter to the filter list
753 * @adapter: board private structure
754 * @macaddr: the MAC address
755 *
756 * Returns ptr to the filter object or NULL when no memory available.
757 **/
758static struct
759i40evf_mac_filter *i40evf_add_filter(struct i40evf_adapter *adapter,
760 u8 *macaddr)
761{
762 struct i40evf_mac_filter *f;
763
764 if (!macaddr)
765 return NULL;
766
767 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
768 &adapter->crit_section))
769 mdelay(1);
770
771 f = i40evf_find_filter(adapter, macaddr);
772 if (NULL == f) {
773 f = kzalloc(sizeof(*f), GFP_ATOMIC);
774 if (NULL == f) {
775 dev_info(&adapter->pdev->dev,
776 "%s: no memory for new filter\n", __func__);
777 clear_bit(__I40EVF_IN_CRITICAL_TASK,
778 &adapter->crit_section);
779 return NULL;
780 }
781
782 memcpy(f->macaddr, macaddr, ETH_ALEN);
783
784 list_add(&f->list, &adapter->mac_filter_list);
785 f->add = true;
786 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
787 }
788
789 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
790 return f;
791}
792
793/**
794 * i40evf_set_mac - NDO callback to set port mac address
795 * @netdev: network interface device structure
796 * @p: pointer to an address structure
797 *
798 * Returns 0 on success, negative on failure
799 **/
800static int i40evf_set_mac(struct net_device *netdev, void *p)
801{
802 struct i40evf_adapter *adapter = netdev_priv(netdev);
803 struct i40e_hw *hw = &adapter->hw;
804 struct i40evf_mac_filter *f;
805 struct sockaddr *addr = p;
806
807 if (!is_valid_ether_addr(addr->sa_data))
808 return -EADDRNOTAVAIL;
809
810 if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
811 return 0;
812
813 f = i40evf_add_filter(adapter, addr->sa_data);
814 if (f) {
815 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
816 memcpy(netdev->dev_addr, adapter->hw.mac.addr,
817 netdev->addr_len);
818 }
819
820 return (f == NULL) ? -ENOMEM : 0;
821}
822
823/**
824 * i40evf_set_rx_mode - NDO callback to set the netdev filters
825 * @netdev: network interface device structure
826 **/
827static void i40evf_set_rx_mode(struct net_device *netdev)
828{
829 struct i40evf_adapter *adapter = netdev_priv(netdev);
830 struct i40evf_mac_filter *f, *ftmp;
831 struct netdev_hw_addr *uca;
832 struct netdev_hw_addr *mca;
833
834 /* add addr if not already in the filter list */
835 netdev_for_each_uc_addr(uca, netdev) {
836 i40evf_add_filter(adapter, uca->addr);
837 }
838 netdev_for_each_mc_addr(mca, netdev) {
839 i40evf_add_filter(adapter, mca->addr);
840 }
841
842 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
843 &adapter->crit_section))
844 mdelay(1);
845 /* remove filter if not in netdev list */
846 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
847 bool found = false;
848
849 if (f->macaddr[0] & 0x01) {
850 netdev_for_each_mc_addr(mca, netdev) {
851 if (ether_addr_equal(mca->addr, f->macaddr)) {
852 found = true;
853 break;
854 }
855 }
856 } else {
857 netdev_for_each_uc_addr(uca, netdev) {
858 if (ether_addr_equal(uca->addr, f->macaddr)) {
859 found = true;
860 break;
861 }
862 }
863 }
864 if (found) {
865 f->remove = true;
866 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
867 }
868 }
869 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
870}
871
872/**
873 * i40evf_napi_enable_all - enable NAPI on all queue vectors
874 * @adapter: board private structure
875 **/
876static void i40evf_napi_enable_all(struct i40evf_adapter *adapter)
877{
878 int q_idx;
879 struct i40e_q_vector *q_vector;
880 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
881
882 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
883 struct napi_struct *napi;
884 q_vector = adapter->q_vector[q_idx];
885 napi = &q_vector->napi;
886 napi_enable(napi);
887 }
888}
889
890/**
891 * i40evf_napi_disable_all - disable NAPI on all queue vectors
892 * @adapter: board private structure
893 **/
894static void i40evf_napi_disable_all(struct i40evf_adapter *adapter)
895{
896 int q_idx;
897 struct i40e_q_vector *q_vector;
898 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
899
900 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
901 q_vector = adapter->q_vector[q_idx];
902 napi_disable(&q_vector->napi);
903 }
904}
905
906/**
907 * i40evf_configure - set up transmit and receive data structures
908 * @adapter: board private structure
909 **/
910static void i40evf_configure(struct i40evf_adapter *adapter)
911{
912 struct net_device *netdev = adapter->netdev;
913 int i;
914
915 i40evf_set_rx_mode(netdev);
916
917 i40evf_configure_tx(adapter);
918 i40evf_configure_rx(adapter);
919 adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
920
921 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
922 struct i40e_ring *ring = adapter->rx_rings[i];
923 i40evf_alloc_rx_buffers(ring, ring->count);
924 ring->next_to_use = ring->count - 1;
925 writel(ring->next_to_use, ring->tail);
926 }
927}
928
929/**
930 * i40evf_up_complete - Finish the last steps of bringing up a connection
931 * @adapter: board private structure
932 **/
933static int i40evf_up_complete(struct i40evf_adapter *adapter)
934{
935 adapter->state = __I40EVF_RUNNING;
936 clear_bit(__I40E_DOWN, &adapter->vsi.state);
937
938 i40evf_napi_enable_all(adapter);
939
940 adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
941 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
942 return 0;
943}
944
945/**
946 * i40evf_clean_all_rx_rings - Free Rx Buffers for all queues
947 * @adapter: board private structure
948 **/
949static void i40evf_clean_all_rx_rings(struct i40evf_adapter *adapter)
950{
951 int i;
952
953 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++)
954 i40evf_clean_rx_ring(adapter->rx_rings[i]);
955}
956
957/**
958 * i40evf_clean_all_tx_rings - Free Tx Buffers for all queues
959 * @adapter: board private structure
960 **/
961static void i40evf_clean_all_tx_rings(struct i40evf_adapter *adapter)
962{
963 int i;
964
965 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++)
966 i40evf_clean_tx_ring(adapter->tx_rings[i]);
967}
968
969/**
970 * i40e_down - Shutdown the connection processing
971 * @adapter: board private structure
972 **/
973void i40evf_down(struct i40evf_adapter *adapter)
974{
975 struct net_device *netdev = adapter->netdev;
976 struct i40evf_mac_filter *f;
977
Mitch Williamsef8693e2014-02-13 03:48:53 -0800978 /* remove all MAC filters */
Greg Rose5eae00c2013-12-21 06:12:45 +0000979 list_for_each_entry(f, &adapter->mac_filter_list, list) {
980 f->remove = true;
981 }
Mitch Williamsed1f5b52014-02-20 19:29:06 -0800982 /* remove all VLAN filters */
983 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
984 f->remove = true;
985 }
Mitch Williamsef8693e2014-02-13 03:48:53 -0800986 if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) &&
987 adapter->state != __I40EVF_RESETTING) {
988 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
Mitch Williamsed1f5b52014-02-20 19:29:06 -0800989 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
Mitch Williamsef8693e2014-02-13 03:48:53 -0800990 /* disable receives */
991 adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
992 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
993 msleep(20);
994 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000995 netif_tx_disable(netdev);
996
997 netif_tx_stop_all_queues(netdev);
998
999 i40evf_irq_disable(adapter);
1000
1001 i40evf_napi_disable_all(adapter);
1002
1003 netif_carrier_off(netdev);
1004
1005 i40evf_clean_all_tx_rings(adapter);
1006 i40evf_clean_all_rx_rings(adapter);
1007}
1008
1009/**
1010 * i40evf_acquire_msix_vectors - Setup the MSIX capability
1011 * @adapter: board private structure
1012 * @vectors: number of vectors to request
1013 *
1014 * Work with the OS to set up the MSIX vectors needed.
1015 *
1016 * Returns 0 on success, negative on failure
1017 **/
1018static int
1019i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors)
1020{
1021 int err, vector_threshold;
1022
1023 /* We'll want at least 3 (vector_threshold):
1024 * 0) Other (Admin Queue and link, mostly)
1025 * 1) TxQ[0] Cleanup
1026 * 2) RxQ[0] Cleanup
1027 */
1028 vector_threshold = MIN_MSIX_COUNT;
1029
1030 /* The more we get, the more we will assign to Tx/Rx Cleanup
1031 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1032 * Right now, we simply care about how many we'll get; we'll
1033 * set them up later while requesting irq's.
1034 */
1035 while (vectors >= vector_threshold) {
1036 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
1037 vectors);
1038 if (!err) /* Success in acquiring all requested vectors. */
1039 break;
1040 else if (err < 0)
1041 vectors = 0; /* Nasty failure, quit now */
1042 else /* err == number of vectors we should try again with */
1043 vectors = err;
1044 }
1045
1046 if (vectors < vector_threshold) {
1047 dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts.\n");
1048 kfree(adapter->msix_entries);
1049 adapter->msix_entries = NULL;
1050 err = -EIO;
1051 } else {
1052 /* Adjust for only the vectors we'll use, which is minimum
1053 * of max_msix_q_vectors + NONQ_VECS, or the number of
1054 * vectors we were allocated.
1055 */
1056 adapter->num_msix_vectors = vectors;
1057 }
1058 return err;
1059}
1060
1061/**
1062 * i40evf_free_queues - Free memory for all rings
1063 * @adapter: board private structure to initialize
1064 *
1065 * Free all of the memory associated with queue pairs.
1066 **/
1067static void i40evf_free_queues(struct i40evf_adapter *adapter)
1068{
1069 int i;
1070
1071 if (!adapter->vsi_res)
1072 return;
1073 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
1074 if (adapter->tx_rings[i])
1075 kfree_rcu(adapter->tx_rings[i], rcu);
1076 adapter->tx_rings[i] = NULL;
1077 adapter->rx_rings[i] = NULL;
1078 }
1079}
1080
1081/**
1082 * i40evf_alloc_queues - Allocate memory for all rings
1083 * @adapter: board private structure to initialize
1084 *
1085 * We allocate one ring per queue at run-time since we don't know the
1086 * number of queues at compile-time. The polling_netdev array is
1087 * intended for Multiqueue, but should work fine with a single queue.
1088 **/
1089static int i40evf_alloc_queues(struct i40evf_adapter *adapter)
1090{
1091 int i;
1092
1093 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
1094 struct i40e_ring *tx_ring;
1095 struct i40e_ring *rx_ring;
1096
1097 tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
1098 if (!tx_ring)
1099 goto err_out;
1100
1101 tx_ring->queue_index = i;
1102 tx_ring->netdev = adapter->netdev;
1103 tx_ring->dev = &adapter->pdev->dev;
1104 tx_ring->count = I40EVF_DEFAULT_TXD;
1105 adapter->tx_rings[i] = tx_ring;
1106
1107 rx_ring = &tx_ring[1];
1108 rx_ring->queue_index = i;
1109 rx_ring->netdev = adapter->netdev;
1110 rx_ring->dev = &adapter->pdev->dev;
1111 rx_ring->count = I40EVF_DEFAULT_RXD;
1112 adapter->rx_rings[i] = rx_ring;
1113 }
1114
1115 return 0;
1116
1117err_out:
1118 i40evf_free_queues(adapter);
1119 return -ENOMEM;
1120}
1121
1122/**
1123 * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
1124 * @adapter: board private structure to initialize
1125 *
1126 * Attempt to configure the interrupts using the best available
1127 * capabilities of the hardware and the kernel.
1128 **/
1129static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter)
1130{
1131 int vector, v_budget;
1132 int pairs = 0;
1133 int err = 0;
1134
1135 if (!adapter->vsi_res) {
1136 err = -EIO;
1137 goto out;
1138 }
1139 pairs = adapter->vsi_res->num_queue_pairs;
1140
1141 /* It's easy to be greedy for MSI-X vectors, but it really
1142 * doesn't do us much good if we have a lot more vectors
1143 * than CPU's. So let's be conservative and only ask for
1144 * (roughly) twice the number of vectors as there are CPU's.
1145 */
Mitch Williams30a500e2014-02-11 08:27:52 +00001146 v_budget = min_t(int, pairs, (int)(num_online_cpus() * 2)) + NONQ_VECS;
1147 v_budget = min_t(int, v_budget, (int)adapter->vf_res->max_vectors);
Greg Rose5eae00c2013-12-21 06:12:45 +00001148
1149 /* A failure in MSI-X entry allocation isn't fatal, but it does
1150 * mean we disable MSI-X capabilities of the adapter.
1151 */
1152 adapter->msix_entries = kcalloc(v_budget,
1153 sizeof(struct msix_entry), GFP_KERNEL);
1154 if (!adapter->msix_entries) {
1155 err = -ENOMEM;
1156 goto out;
1157 }
1158
1159 for (vector = 0; vector < v_budget; vector++)
1160 adapter->msix_entries[vector].entry = vector;
1161
1162 i40evf_acquire_msix_vectors(adapter, v_budget);
1163
1164out:
1165 adapter->netdev->real_num_tx_queues = pairs;
1166 return err;
1167}
1168
1169/**
1170 * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
1171 * @adapter: board private structure to initialize
1172 *
1173 * We allocate one q_vector per queue interrupt. If allocation fails we
1174 * return -ENOMEM.
1175 **/
1176static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter)
1177{
1178 int q_idx, num_q_vectors;
1179 struct i40e_q_vector *q_vector;
1180
1181 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
1182
1183 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
1184 q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
1185 if (!q_vector)
1186 goto err_out;
1187 q_vector->adapter = adapter;
1188 q_vector->vsi = &adapter->vsi;
1189 q_vector->v_idx = q_idx;
1190 netif_napi_add(adapter->netdev, &q_vector->napi,
1191 i40evf_napi_poll, 64);
1192 adapter->q_vector[q_idx] = q_vector;
1193 }
1194
1195 return 0;
1196
1197err_out:
1198 while (q_idx) {
1199 q_idx--;
1200 q_vector = adapter->q_vector[q_idx];
1201 netif_napi_del(&q_vector->napi);
1202 kfree(q_vector);
1203 adapter->q_vector[q_idx] = NULL;
1204 }
1205 return -ENOMEM;
1206}
1207
1208/**
1209 * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
1210 * @adapter: board private structure to initialize
1211 *
1212 * This function frees the memory allocated to the q_vectors. In addition if
1213 * NAPI is enabled it will delete any references to the NAPI struct prior
1214 * to freeing the q_vector.
1215 **/
1216static void i40evf_free_q_vectors(struct i40evf_adapter *adapter)
1217{
1218 int q_idx, num_q_vectors;
1219 int napi_vectors;
1220
1221 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
1222 napi_vectors = adapter->vsi_res->num_queue_pairs;
1223
1224 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
1225 struct i40e_q_vector *q_vector = adapter->q_vector[q_idx];
1226
1227 adapter->q_vector[q_idx] = NULL;
1228 if (q_idx < napi_vectors)
1229 netif_napi_del(&q_vector->napi);
1230 kfree(q_vector);
1231 }
1232}
1233
1234/**
1235 * i40evf_reset_interrupt_capability - Reset MSIX setup
1236 * @adapter: board private structure
1237 *
1238 **/
1239void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter)
1240{
1241 pci_disable_msix(adapter->pdev);
1242 kfree(adapter->msix_entries);
1243 adapter->msix_entries = NULL;
1244
1245 return;
1246}
1247
1248/**
1249 * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
1250 * @adapter: board private structure to initialize
1251 *
1252 **/
1253int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter)
1254{
1255 int err;
1256
1257 err = i40evf_set_interrupt_capability(adapter);
1258 if (err) {
1259 dev_err(&adapter->pdev->dev,
1260 "Unable to setup interrupt capabilities\n");
1261 goto err_set_interrupt;
1262 }
1263
1264 err = i40evf_alloc_q_vectors(adapter);
1265 if (err) {
1266 dev_err(&adapter->pdev->dev,
1267 "Unable to allocate memory for queue vectors\n");
1268 goto err_alloc_q_vectors;
1269 }
1270
1271 err = i40evf_alloc_queues(adapter);
1272 if (err) {
1273 dev_err(&adapter->pdev->dev,
1274 "Unable to allocate memory for queues\n");
1275 goto err_alloc_queues;
1276 }
1277
1278 dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u",
1279 (adapter->vsi_res->num_queue_pairs > 1) ? "Enabled" :
1280 "Disabled", adapter->vsi_res->num_queue_pairs);
1281
1282 return 0;
1283err_alloc_queues:
1284 i40evf_free_q_vectors(adapter);
1285err_alloc_q_vectors:
1286 i40evf_reset_interrupt_capability(adapter);
1287err_set_interrupt:
1288 return err;
1289}
1290
1291/**
1292 * i40evf_watchdog_timer - Periodic call-back timer
1293 * @data: pointer to adapter disguised as unsigned long
1294 **/
1295static void i40evf_watchdog_timer(unsigned long data)
1296{
1297 struct i40evf_adapter *adapter = (struct i40evf_adapter *)data;
1298 schedule_work(&adapter->watchdog_task);
1299 /* timer will be rescheduled in watchdog task */
1300}
1301
1302/**
1303 * i40evf_watchdog_task - Periodic call-back task
1304 * @work: pointer to work_struct
1305 **/
1306static void i40evf_watchdog_task(struct work_struct *work)
1307{
1308 struct i40evf_adapter *adapter = container_of(work,
1309 struct i40evf_adapter,
1310 watchdog_task);
1311 struct i40e_hw *hw = &adapter->hw;
1312
Greg Rose5eae00c2013-12-21 06:12:45 +00001313 if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section))
Mitch Williamsef8693e2014-02-13 03:48:53 -08001314 goto restart_watchdog;
1315
1316 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
Mitch Williamsef8693e2014-02-13 03:48:53 -08001317 if ((rd32(hw, I40E_VFGEN_RSTAT) & 0x3) == I40E_VFR_VFACTIVE) {
1318 /* A chance for redemption! */
1319 dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n");
1320 adapter->state = __I40EVF_STARTUP;
1321 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
1322 schedule_delayed_work(&adapter->init_task, 10);
1323 clear_bit(__I40EVF_IN_CRITICAL_TASK,
1324 &adapter->crit_section);
1325 /* Don't reschedule the watchdog, since we've restarted
1326 * the init task. When init_task contacts the PF and
1327 * gets everything set up again, it'll restart the
1328 * watchdog for us. Down, boy. Sit. Stay. Woof.
1329 */
1330 return;
1331 }
1332 adapter->aq_pending = 0;
1333 adapter->aq_required = 0;
1334 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1335 goto watchdog_done;
1336 }
1337
1338 if ((adapter->state < __I40EVF_DOWN) ||
1339 (adapter->flags & I40EVF_FLAG_RESET_PENDING))
Greg Rose5eae00c2013-12-21 06:12:45 +00001340 goto watchdog_done;
1341
Mitch Williamsef8693e2014-02-13 03:48:53 -08001342 /* check for reset */
1343 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) &&
Greg Rose5eae00c2013-12-21 06:12:45 +00001344 (rd32(hw, I40E_VFGEN_RSTAT) & 0x3) != I40E_VFR_VFACTIVE) {
1345 adapter->state = __I40EVF_RESETTING;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001346 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
1347 dev_err(&adapter->pdev->dev, "Hardware reset detected.\n");
1348 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001349 schedule_work(&adapter->reset_task);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001350 adapter->aq_pending = 0;
1351 adapter->aq_required = 0;
1352 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001353 goto watchdog_done;
1354 }
1355
1356 /* Process admin queue tasks. After init, everything gets done
1357 * here so we don't race on the admin queue.
1358 */
1359 if (adapter->aq_pending)
1360 goto watchdog_done;
1361
1362 if (adapter->aq_required & I40EVF_FLAG_AQ_MAP_VECTORS) {
1363 i40evf_map_queues(adapter);
1364 goto watchdog_done;
1365 }
1366
1367 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_MAC_FILTER) {
1368 i40evf_add_ether_addrs(adapter);
1369 goto watchdog_done;
1370 }
1371
1372 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_VLAN_FILTER) {
1373 i40evf_add_vlans(adapter);
1374 goto watchdog_done;
1375 }
1376
1377 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_MAC_FILTER) {
1378 i40evf_del_ether_addrs(adapter);
1379 goto watchdog_done;
1380 }
1381
1382 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_VLAN_FILTER) {
1383 i40evf_del_vlans(adapter);
1384 goto watchdog_done;
1385 }
1386
1387 if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) {
1388 i40evf_disable_queues(adapter);
1389 goto watchdog_done;
1390 }
1391
1392 if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_QUEUES) {
1393 i40evf_configure_queues(adapter);
1394 goto watchdog_done;
1395 }
1396
1397 if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_QUEUES) {
1398 i40evf_enable_queues(adapter);
1399 goto watchdog_done;
1400 }
1401
1402 if (adapter->state == __I40EVF_RUNNING)
1403 i40evf_request_stats(adapter);
1404
1405 i40evf_irq_enable(adapter, true);
1406 i40evf_fire_sw_int(adapter, 0xFF);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001407
Greg Rose5eae00c2013-12-21 06:12:45 +00001408watchdog_done:
Mitch Williamsef8693e2014-02-13 03:48:53 -08001409 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1410restart_watchdog:
Greg Rose5eae00c2013-12-21 06:12:45 +00001411 if (adapter->aq_required)
1412 mod_timer(&adapter->watchdog_timer,
1413 jiffies + msecs_to_jiffies(20));
1414 else
1415 mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2));
Greg Rose5eae00c2013-12-21 06:12:45 +00001416 schedule_work(&adapter->adminq_task);
1417}
1418
Mitch A Williams5b7af022014-03-28 06:49:02 +00001419/**
1420 * i40evf_configure_rss - increment to next available tx queue
1421 * @adapter: board private structure
1422 * @j: queue counter
1423 *
1424 * Helper function for RSS programming to increment through available
1425 * queus. Returns the next queue value.
1426 **/
Mitch Williams96d47702014-02-11 08:27:50 +00001427static int next_queue(struct i40evf_adapter *adapter, int j)
1428{
1429 j += 1;
1430
1431 return j >= adapter->vsi_res->num_queue_pairs ? 0 : j;
1432}
1433
Greg Rose5eae00c2013-12-21 06:12:45 +00001434/**
1435 * i40evf_configure_rss - Prepare for RSS if used
1436 * @adapter: board private structure
1437 **/
1438static void i40evf_configure_rss(struct i40evf_adapter *adapter)
1439{
1440 struct i40e_hw *hw = &adapter->hw;
1441 u32 lut = 0;
1442 int i, j;
1443 u64 hena;
1444
1445 /* Set of random keys generated using kernel random number generator */
1446 static const u32 seed[I40E_VFQF_HKEY_MAX_INDEX + 1] = {
1447 0x794221b4, 0xbca0c5ab, 0x6cd5ebd9, 0x1ada6127,
1448 0x983b3aa1, 0x1c4e71eb, 0x7f6328b2, 0xfcdc0da0,
1449 0xc135cafa, 0x7a6f7e2d, 0xe7102d28, 0x163cd12e,
1450 0x4954b126 };
1451
1452 /* Hash type is configured by the PF - we just supply the key */
1453
1454 /* Fill out hash function seed */
1455 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
1456 wr32(hw, I40E_VFQF_HKEY(i), seed[i]);
1457
1458 /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
1459 hena = I40E_DEFAULT_RSS_HENA;
1460 wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
1461 wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
1462
1463 /* Populate the LUT with max no. of queues in round robin fashion */
Mitch Williams96d47702014-02-11 08:27:50 +00001464 j = adapter->vsi_res->num_queue_pairs;
1465 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) {
Mitch A Williams5b7af022014-03-28 06:49:02 +00001466 j = next_queue(adapter, j);
1467 lut = j;
1468 j = next_queue(adapter, j);
1469 lut |= j << 8;
1470 j = next_queue(adapter, j);
1471 lut |= j << 16;
1472 j = next_queue(adapter, j);
1473 lut |= j << 24;
Mitch Williams96d47702014-02-11 08:27:50 +00001474 wr32(hw, I40E_VFQF_HLUT(i), lut);
Greg Rose5eae00c2013-12-21 06:12:45 +00001475 }
1476 i40e_flush(hw);
1477}
1478
Mitch Williamsef8693e2014-02-13 03:48:53 -08001479#define I40EVF_RESET_WAIT_MS 100
1480#define I40EVF_RESET_WAIT_COUNT 200
Greg Rose5eae00c2013-12-21 06:12:45 +00001481/**
1482 * i40evf_reset_task - Call-back task to handle hardware reset
1483 * @work: pointer to work_struct
1484 *
1485 * During reset we need to shut down and reinitialize the admin queue
1486 * before we can use it to communicate with the PF again. We also clear
1487 * and reinit the rings because that context is lost as well.
1488 **/
1489static void i40evf_reset_task(struct work_struct *work)
1490{
Mitch Williamsef8693e2014-02-13 03:48:53 -08001491 struct i40evf_adapter *adapter = container_of(work,
1492 struct i40evf_adapter,
1493 reset_task);
Greg Rose5eae00c2013-12-21 06:12:45 +00001494 struct i40e_hw *hw = &adapter->hw;
1495 int i = 0, err;
1496 uint32_t rstat_val;
1497
1498 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
1499 &adapter->crit_section))
1500 udelay(500);
Mitch Williams3526d802014-03-06 08:59:56 +00001501
1502 if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) {
1503 dev_info(&adapter->pdev->dev, "Requesting reset from PF\n");
1504 i40evf_request_reset(adapter);
1505 }
1506
Mitch Williamsef8693e2014-02-13 03:48:53 -08001507 /* poll until we see the reset actually happen */
1508 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001509 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1510 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001511 if (rstat_val != I40E_VFR_VFACTIVE) {
1512 dev_info(&adapter->pdev->dev, "Reset now occurring\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001513 break;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001514 } else {
1515 msleep(I40EVF_RESET_WAIT_MS);
1516 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001517 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001518 if (i == I40EVF_RESET_WAIT_COUNT) {
1519 dev_err(&adapter->pdev->dev, "Reset was not detected\n");
1520 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1521 goto continue_reset; /* act like the reset happened */
1522 }
1523
1524 /* wait until the reset is complete and the PF is responding to us */
1525 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
1526 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1527 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1528 if (rstat_val == I40E_VFR_VFACTIVE) {
1529 dev_info(&adapter->pdev->dev, "Reset is complete. Reinitializing.\n");
1530 break;
1531 } else {
1532 msleep(I40EVF_RESET_WAIT_MS);
1533 }
1534 }
1535 if (i == I40EVF_RESET_WAIT_COUNT) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001536 /* reset never finished */
Mitch Williamsef8693e2014-02-13 03:48:53 -08001537 dev_err(&adapter->pdev->dev, "Reset never finished (%x). PF driver is dead, and so am I.\n",
1538 rstat_val);
1539 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
1540
Mitch Williams169f4072014-04-01 07:11:50 +00001541 if (netif_running(adapter->netdev)) {
1542 set_bit(__I40E_DOWN, &adapter->vsi.state);
1543 i40evf_down(adapter);
1544 i40evf_free_traffic_irqs(adapter);
1545 i40evf_free_all_tx_resources(adapter);
1546 i40evf_free_all_rx_resources(adapter);
1547 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001548 i40evf_free_misc_irq(adapter);
1549 i40evf_reset_interrupt_capability(adapter);
1550 i40evf_free_queues(adapter);
1551 kfree(adapter->vf_res);
1552 i40evf_shutdown_adminq(hw);
1553 adapter->netdev->flags &= ~IFF_UP;
1554 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1555 return; /* Do not attempt to reinit. It's dead, Jim. */
Greg Rose5eae00c2013-12-21 06:12:45 +00001556 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001557
1558continue_reset:
1559 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1560
Greg Rose5eae00c2013-12-21 06:12:45 +00001561 i40evf_down(adapter);
1562 adapter->state = __I40EVF_RESETTING;
1563
1564 /* kill and reinit the admin queue */
1565 if (i40evf_shutdown_adminq(hw))
1566 dev_warn(&adapter->pdev->dev,
1567 "%s: Failed to destroy the Admin Queue resources\n",
1568 __func__);
1569 err = i40evf_init_adminq(hw);
1570 if (err)
1571 dev_info(&adapter->pdev->dev, "%s: init_adminq failed: %d\n",
1572 __func__, err);
1573
1574 adapter->aq_pending = 0;
1575 adapter->aq_required = 0;
1576 i40evf_map_queues(adapter);
1577 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1578
1579 mod_timer(&adapter->watchdog_timer, jiffies + 2);
1580
1581 if (netif_running(adapter->netdev)) {
1582 /* allocate transmit descriptors */
1583 err = i40evf_setup_all_tx_resources(adapter);
1584 if (err)
1585 goto reset_err;
1586
1587 /* allocate receive descriptors */
1588 err = i40evf_setup_all_rx_resources(adapter);
1589 if (err)
1590 goto reset_err;
1591
1592 i40evf_configure(adapter);
1593
1594 err = i40evf_up_complete(adapter);
1595 if (err)
1596 goto reset_err;
1597
1598 i40evf_irq_enable(adapter, true);
1599 }
1600 return;
1601reset_err:
1602 dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit.\n");
1603 i40evf_close(adapter->netdev);
1604}
1605
1606/**
1607 * i40evf_adminq_task - worker thread to clean the admin queue
1608 * @work: pointer to work_struct containing our data
1609 **/
1610static void i40evf_adminq_task(struct work_struct *work)
1611{
1612 struct i40evf_adapter *adapter =
1613 container_of(work, struct i40evf_adapter, adminq_task);
1614 struct i40e_hw *hw = &adapter->hw;
1615 struct i40e_arq_event_info event;
1616 struct i40e_virtchnl_msg *v_msg;
1617 i40e_status ret;
1618 u16 pending;
1619
Mitch Williamsef8693e2014-02-13 03:48:53 -08001620 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
1621 return;
1622
Greg Rose5eae00c2013-12-21 06:12:45 +00001623 event.msg_size = I40EVF_MAX_AQ_BUF_SIZE;
1624 event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
1625 if (!event.msg_buf) {
1626 dev_info(&adapter->pdev->dev, "%s: no memory for ARQ clean\n",
1627 __func__);
1628 return;
1629 }
1630 v_msg = (struct i40e_virtchnl_msg *)&event.desc;
1631 do {
1632 ret = i40evf_clean_arq_element(hw, &event, &pending);
1633 if (ret)
1634 break; /* No event to process or error cleaning ARQ */
1635
1636 i40evf_virtchnl_completion(adapter, v_msg->v_opcode,
1637 v_msg->v_retval, event.msg_buf,
1638 event.msg_size);
1639 if (pending != 0) {
1640 dev_info(&adapter->pdev->dev,
1641 "%s: ARQ: Pending events %d\n",
1642 __func__, pending);
1643 memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE);
1644 }
1645 } while (pending);
1646
1647 /* re-enable Admin queue interrupt cause */
1648 i40evf_misc_irq_enable(adapter);
1649
1650 kfree(event.msg_buf);
1651}
1652
1653/**
1654 * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
1655 * @adapter: board private structure
1656 *
1657 * Free all transmit software resources
1658 **/
1659static void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter)
1660{
1661 int i;
1662
1663 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++)
1664 if (adapter->tx_rings[i]->desc)
1665 i40evf_free_tx_resources(adapter->tx_rings[i]);
1666
1667}
1668
1669/**
1670 * i40evf_setup_all_tx_resources - allocate all queues Tx resources
1671 * @adapter: board private structure
1672 *
1673 * If this function returns with an error, then it's possible one or
1674 * more of the rings is populated (while the rest are not). It is the
1675 * callers duty to clean those orphaned rings.
1676 *
1677 * Return 0 on success, negative on failure
1678 **/
1679static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter)
1680{
1681 int i, err = 0;
1682
1683 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
1684 err = i40evf_setup_tx_descriptors(adapter->tx_rings[i]);
1685 if (!err)
1686 continue;
1687 dev_err(&adapter->pdev->dev,
1688 "%s: Allocation for Tx Queue %u failed\n",
1689 __func__, i);
1690 break;
1691 }
1692
1693 return err;
1694}
1695
1696/**
1697 * i40evf_setup_all_rx_resources - allocate all queues Rx resources
1698 * @adapter: board private structure
1699 *
1700 * If this function returns with an error, then it's possible one or
1701 * more of the rings is populated (while the rest are not). It is the
1702 * callers duty to clean those orphaned rings.
1703 *
1704 * Return 0 on success, negative on failure
1705 **/
1706static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter)
1707{
1708 int i, err = 0;
1709
1710 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
1711 err = i40evf_setup_rx_descriptors(adapter->rx_rings[i]);
1712 if (!err)
1713 continue;
1714 dev_err(&adapter->pdev->dev,
1715 "%s: Allocation for Rx Queue %u failed\n",
1716 __func__, i);
1717 break;
1718 }
1719 return err;
1720}
1721
1722/**
1723 * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
1724 * @adapter: board private structure
1725 *
1726 * Free all receive software resources
1727 **/
1728static void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter)
1729{
1730 int i;
1731
1732 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++)
1733 if (adapter->rx_rings[i]->desc)
1734 i40evf_free_rx_resources(adapter->rx_rings[i]);
1735}
1736
1737/**
1738 * i40evf_open - Called when a network interface is made active
1739 * @netdev: network interface device structure
1740 *
1741 * Returns 0 on success, negative value on failure
1742 *
1743 * The open entry point is called when a network interface is made
1744 * active by the system (IFF_UP). At this point all resources needed
1745 * for transmit and receive operations are allocated, the interrupt
1746 * handler is registered with the OS, the watchdog timer is started,
1747 * and the stack is notified that the interface is ready.
1748 **/
1749static int i40evf_open(struct net_device *netdev)
1750{
1751 struct i40evf_adapter *adapter = netdev_priv(netdev);
1752 int err;
1753
Mitch Williamsef8693e2014-02-13 03:48:53 -08001754 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
1755 dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
1756 return -EIO;
1757 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001758 if (adapter->state != __I40EVF_DOWN)
1759 return -EBUSY;
1760
1761 /* allocate transmit descriptors */
1762 err = i40evf_setup_all_tx_resources(adapter);
1763 if (err)
1764 goto err_setup_tx;
1765
1766 /* allocate receive descriptors */
1767 err = i40evf_setup_all_rx_resources(adapter);
1768 if (err)
1769 goto err_setup_rx;
1770
1771 /* clear any pending interrupts, may auto mask */
1772 err = i40evf_request_traffic_irqs(adapter, netdev->name);
1773 if (err)
1774 goto err_req_irq;
1775
1776 i40evf_configure(adapter);
1777
1778 err = i40evf_up_complete(adapter);
1779 if (err)
1780 goto err_req_irq;
1781
1782 i40evf_irq_enable(adapter, true);
1783
1784 return 0;
1785
1786err_req_irq:
1787 i40evf_down(adapter);
1788 i40evf_free_traffic_irqs(adapter);
1789err_setup_rx:
1790 i40evf_free_all_rx_resources(adapter);
1791err_setup_tx:
1792 i40evf_free_all_tx_resources(adapter);
1793
1794 return err;
1795}
1796
1797/**
1798 * i40evf_close - Disables a network interface
1799 * @netdev: network interface device structure
1800 *
1801 * Returns 0, this is not allowed to fail
1802 *
1803 * The close entry point is called when an interface is de-activated
1804 * by the OS. The hardware is still under the drivers control, but
1805 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
1806 * are freed, along with all transmit and receive resources.
1807 **/
1808static int i40evf_close(struct net_device *netdev)
1809{
1810 struct i40evf_adapter *adapter = netdev_priv(netdev);
1811
Mitch Williamsef8693e2014-02-13 03:48:53 -08001812 if (adapter->state <= __I40EVF_DOWN)
1813 return 0;
1814
Greg Rose5eae00c2013-12-21 06:12:45 +00001815 /* signal that we are down to the interrupt handler */
1816 adapter->state = __I40EVF_DOWN;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001817
Greg Rose5eae00c2013-12-21 06:12:45 +00001818 set_bit(__I40E_DOWN, &adapter->vsi.state);
1819
1820 i40evf_down(adapter);
1821 i40evf_free_traffic_irqs(adapter);
1822
1823 i40evf_free_all_tx_resources(adapter);
1824 i40evf_free_all_rx_resources(adapter);
1825
1826 return 0;
1827}
1828
1829/**
1830 * i40evf_get_stats - Get System Network Statistics
1831 * @netdev: network interface device structure
1832 *
1833 * Returns the address of the device statistics structure.
1834 * The statistics are actually updated from the timer callback.
1835 **/
1836static struct net_device_stats *i40evf_get_stats(struct net_device *netdev)
1837{
1838 struct i40evf_adapter *adapter = netdev_priv(netdev);
1839
1840 /* only return the current stats */
1841 return &adapter->net_stats;
1842}
1843
1844/**
1845 * i40evf_reinit_locked - Software reinit
1846 * @adapter: board private structure
1847 *
1848 * Reinititalizes the ring structures in response to a software configuration
1849 * change. Roughly the same as close followed by open, but skips releasing
1850 * and reallocating the interrupts.
1851 **/
1852void i40evf_reinit_locked(struct i40evf_adapter *adapter)
1853{
1854 struct net_device *netdev = adapter->netdev;
1855 int err;
1856
1857 WARN_ON(in_interrupt());
1858
1859 adapter->state = __I40EVF_RESETTING;
1860
1861 i40evf_down(adapter);
1862
1863 /* allocate transmit descriptors */
1864 err = i40evf_setup_all_tx_resources(adapter);
1865 if (err)
1866 goto err_reinit;
1867
1868 /* allocate receive descriptors */
1869 err = i40evf_setup_all_rx_resources(adapter);
1870 if (err)
1871 goto err_reinit;
1872
1873 i40evf_configure(adapter);
1874
1875 err = i40evf_up_complete(adapter);
1876 if (err)
1877 goto err_reinit;
1878
1879 i40evf_irq_enable(adapter, true);
1880 return;
1881
1882err_reinit:
1883 dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit.\n");
1884 i40evf_close(netdev);
1885}
1886
1887/**
1888 * i40evf_change_mtu - Change the Maximum Transfer Unit
1889 * @netdev: network interface device structure
1890 * @new_mtu: new value for maximum frame size
1891 *
1892 * Returns 0 on success, negative on failure
1893 **/
1894static int i40evf_change_mtu(struct net_device *netdev, int new_mtu)
1895{
1896 struct i40evf_adapter *adapter = netdev_priv(netdev);
1897 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
1898
1899 if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
1900 return -EINVAL;
1901
1902 /* must set new MTU before calling down or up */
1903 netdev->mtu = new_mtu;
1904 i40evf_reinit_locked(adapter);
1905 return 0;
1906}
1907
1908static const struct net_device_ops i40evf_netdev_ops = {
1909 .ndo_open = i40evf_open,
1910 .ndo_stop = i40evf_close,
1911 .ndo_start_xmit = i40evf_xmit_frame,
1912 .ndo_get_stats = i40evf_get_stats,
1913 .ndo_set_rx_mode = i40evf_set_rx_mode,
1914 .ndo_validate_addr = eth_validate_addr,
1915 .ndo_set_mac_address = i40evf_set_mac,
1916 .ndo_change_mtu = i40evf_change_mtu,
1917 .ndo_tx_timeout = i40evf_tx_timeout,
1918 .ndo_vlan_rx_add_vid = i40evf_vlan_rx_add_vid,
1919 .ndo_vlan_rx_kill_vid = i40evf_vlan_rx_kill_vid,
1920};
1921
1922/**
1923 * i40evf_check_reset_complete - check that VF reset is complete
1924 * @hw: pointer to hw struct
1925 *
1926 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
1927 **/
1928static int i40evf_check_reset_complete(struct i40e_hw *hw)
1929{
1930 u32 rstat;
1931 int i;
1932
1933 for (i = 0; i < 100; i++) {
1934 rstat = rd32(hw, I40E_VFGEN_RSTAT);
1935 if (rstat == I40E_VFR_VFACTIVE)
1936 return 0;
1937 udelay(10);
1938 }
1939 return -EBUSY;
1940}
1941
1942/**
1943 * i40evf_init_task - worker thread to perform delayed initialization
1944 * @work: pointer to work_struct containing our data
1945 *
1946 * This task completes the work that was begun in probe. Due to the nature
1947 * of VF-PF communications, we may need to wait tens of milliseconds to get
1948 * reponses back from the PF. Rather than busy-wait in probe and bog down the
1949 * whole system, we'll do it in a task so we can sleep.
1950 * This task only runs during driver init. Once we've established
1951 * communications with the PF driver and set up our netdev, the watchdog
1952 * takes over.
1953 **/
1954static void i40evf_init_task(struct work_struct *work)
1955{
1956 struct i40evf_adapter *adapter = container_of(work,
1957 struct i40evf_adapter,
1958 init_task.work);
1959 struct net_device *netdev = adapter->netdev;
1960 struct i40evf_mac_filter *f;
1961 struct i40e_hw *hw = &adapter->hw;
1962 struct pci_dev *pdev = adapter->pdev;
1963 int i, err, bufsz;
1964
1965 switch (adapter->state) {
1966 case __I40EVF_STARTUP:
1967 /* driver loaded, probe complete */
Mitch Williamsef8693e2014-02-13 03:48:53 -08001968 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
1969 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
Greg Rose5eae00c2013-12-21 06:12:45 +00001970 err = i40e_set_mac_type(hw);
1971 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08001972 dev_err(&pdev->dev, "Failed to set MAC type (%d)\n",
1973 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00001974 goto err;
1975 }
1976 err = i40evf_check_reset_complete(hw);
1977 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08001978 dev_err(&pdev->dev, "Device is still in reset (%d)\n",
1979 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00001980 goto err;
1981 }
1982 hw->aq.num_arq_entries = I40EVF_AQ_LEN;
1983 hw->aq.num_asq_entries = I40EVF_AQ_LEN;
1984 hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
1985 hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
1986
1987 err = i40evf_init_adminq(hw);
1988 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08001989 dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n",
1990 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00001991 goto err;
1992 }
1993 err = i40evf_send_api_ver(adapter);
1994 if (err) {
Mitch Williams10bdd672014-03-06 08:59:53 +00001995 dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err);
Greg Rose5eae00c2013-12-21 06:12:45 +00001996 i40evf_shutdown_adminq(hw);
1997 goto err;
1998 }
1999 adapter->state = __I40EVF_INIT_VERSION_CHECK;
2000 goto restart;
2001 break;
2002 case __I40EVF_INIT_VERSION_CHECK:
Mitch Williams10bdd672014-03-06 08:59:53 +00002003 if (!i40evf_asq_done(hw)) {
2004 dev_err(&pdev->dev, "Admin queue command never completed.\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00002005 goto err;
Mitch Williams10bdd672014-03-06 08:59:53 +00002006 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002007
2008 /* aq msg sent, awaiting reply */
2009 err = i40evf_verify_api_ver(adapter);
2010 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002011 dev_err(&pdev->dev, "Unable to verify API version (%d)\n",
Greg Rose5eae00c2013-12-21 06:12:45 +00002012 err);
2013 goto err;
2014 }
2015 err = i40evf_send_vf_config_msg(adapter);
2016 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002017 dev_err(&pdev->dev, "Unable send config request (%d)\n",
Greg Rose5eae00c2013-12-21 06:12:45 +00002018 err);
2019 goto err;
2020 }
2021 adapter->state = __I40EVF_INIT_GET_RESOURCES;
2022 goto restart;
2023 break;
2024 case __I40EVF_INIT_GET_RESOURCES:
2025 /* aq msg sent, awaiting reply */
2026 if (!adapter->vf_res) {
2027 bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
2028 (I40E_MAX_VF_VSI *
2029 sizeof(struct i40e_virtchnl_vsi_resource));
2030 adapter->vf_res = kzalloc(bufsz, GFP_KERNEL);
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002031 if (!adapter->vf_res)
Greg Rose5eae00c2013-12-21 06:12:45 +00002032 goto err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002033 }
2034 err = i40evf_get_vf_config(adapter);
2035 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
2036 goto restart;
2037 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002038 dev_err(&pdev->dev, "Unable to get VF config (%d)\n",
2039 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002040 goto err_alloc;
2041 }
2042 adapter->state = __I40EVF_INIT_SW;
2043 break;
2044 default:
2045 goto err_alloc;
2046 }
2047 /* got VF config message back from PF, now we can parse it */
2048 for (i = 0; i < adapter->vf_res->num_vsis; i++) {
2049 if (adapter->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
2050 adapter->vsi_res = &adapter->vf_res->vsi_res[i];
2051 }
2052 if (!adapter->vsi_res) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002053 dev_err(&pdev->dev, "No LAN VSI found\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00002054 goto err_alloc;
2055 }
2056
2057 adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED;
2058
Greg Rose5eae00c2013-12-21 06:12:45 +00002059 netdev->netdev_ops = &i40evf_netdev_ops;
2060 i40evf_set_ethtool_ops(netdev);
2061 netdev->watchdog_timeo = 5 * HZ;
Mitch Williamsdbbd8112014-02-20 19:29:08 -08002062 netdev->features |= NETIF_F_HIGHDMA |
2063 NETIF_F_SG |
Greg Rose5eae00c2013-12-21 06:12:45 +00002064 NETIF_F_IP_CSUM |
2065 NETIF_F_SCTP_CSUM |
2066 NETIF_F_IPV6_CSUM |
2067 NETIF_F_TSO |
2068 NETIF_F_TSO6 |
Greg Rose3415e8c2014-01-30 12:40:27 +00002069 NETIF_F_RXCSUM |
Greg Rose5eae00c2013-12-21 06:12:45 +00002070 NETIF_F_GRO;
2071
2072 if (adapter->vf_res->vf_offload_flags
2073 & I40E_VIRTCHNL_VF_OFFLOAD_VLAN) {
2074 netdev->vlan_features = netdev->features;
2075 netdev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2076 NETIF_F_HW_VLAN_CTAG_RX |
2077 NETIF_F_HW_VLAN_CTAG_FILTER;
2078 }
2079
Greg Rose3415e8c2014-01-30 12:40:27 +00002080 /* copy netdev features into list of user selectable features */
2081 netdev->hw_features |= netdev->features;
2082 netdev->hw_features &= ~NETIF_F_RXCSUM;
2083
Greg Rose5eae00c2013-12-21 06:12:45 +00002084 if (!is_valid_ether_addr(adapter->hw.mac.addr)) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002085 dev_info(&pdev->dev, "Invalid MAC address %pMAC, using random\n",
2086 adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002087 random_ether_addr(adapter->hw.mac.addr);
2088 }
2089 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
2090 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
2091
2092 INIT_LIST_HEAD(&adapter->mac_filter_list);
2093 INIT_LIST_HEAD(&adapter->vlan_filter_list);
2094 f = kzalloc(sizeof(*f), GFP_ATOMIC);
2095 if (NULL == f)
2096 goto err_sw_init;
2097
2098 memcpy(f->macaddr, adapter->hw.mac.addr, ETH_ALEN);
2099 f->add = true;
2100 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
2101
2102 list_add(&f->list, &adapter->mac_filter_list);
2103
2104 init_timer(&adapter->watchdog_timer);
2105 adapter->watchdog_timer.function = &i40evf_watchdog_timer;
2106 adapter->watchdog_timer.data = (unsigned long)adapter;
2107 mod_timer(&adapter->watchdog_timer, jiffies + 1);
2108
2109 err = i40evf_init_interrupt_scheme(adapter);
2110 if (err)
2111 goto err_sw_init;
2112 i40evf_map_rings_to_vectors(adapter);
2113 i40evf_configure_rss(adapter);
2114 err = i40evf_request_misc_irq(adapter);
2115 if (err)
2116 goto err_sw_init;
2117
2118 netif_carrier_off(netdev);
2119
Greg Rose5eae00c2013-12-21 06:12:45 +00002120 adapter->vsi.id = adapter->vsi_res->vsi_id;
2121 adapter->vsi.seid = adapter->vsi_res->vsi_id; /* dummy */
2122 adapter->vsi.back = adapter;
2123 adapter->vsi.base_vector = 1;
2124 adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK;
Mitch Williamsca99eb92014-04-04 04:43:07 +00002125 adapter->vsi.rx_itr_setting = (I40E_ITR_DYNAMIC |
2126 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
2127 adapter->vsi.tx_itr_setting = (I40E_ITR_DYNAMIC |
2128 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
Greg Rose5eae00c2013-12-21 06:12:45 +00002129 adapter->vsi.netdev = adapter->netdev;
2130
Mitch Williamsef8693e2014-02-13 03:48:53 -08002131 if (!adapter->netdev_registered) {
2132 err = register_netdev(netdev);
2133 if (err)
2134 goto err_register;
2135 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002136
2137 adapter->netdev_registered = true;
2138
2139 netif_tx_stop_all_queues(netdev);
2140
2141 dev_info(&pdev->dev, "MAC address: %pMAC\n", adapter->hw.mac.addr);
2142 if (netdev->features & NETIF_F_GRO)
2143 dev_info(&pdev->dev, "GRO is enabled\n");
2144
2145 dev_info(&pdev->dev, "%s\n", i40evf_driver_string);
2146 adapter->state = __I40EVF_DOWN;
2147 set_bit(__I40E_DOWN, &adapter->vsi.state);
2148 i40evf_misc_irq_enable(adapter);
2149 return;
2150restart:
2151 schedule_delayed_work(&adapter->init_task,
2152 msecs_to_jiffies(50));
2153 return;
2154
2155err_register:
2156 i40evf_free_misc_irq(adapter);
2157err_sw_init:
2158 i40evf_reset_interrupt_capability(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002159err_alloc:
2160 kfree(adapter->vf_res);
2161 adapter->vf_res = NULL;
2162err:
2163 /* Things went into the weeds, so try again later */
2164 if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) {
2165 dev_err(&pdev->dev, "Failed to communicate with PF; giving up.\n");
Mitch Williamsef8693e2014-02-13 03:48:53 -08002166 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
Greg Rose5eae00c2013-12-21 06:12:45 +00002167 return; /* do not reschedule */
2168 }
2169 schedule_delayed_work(&adapter->init_task, HZ * 3);
2170 return;
2171}
2172
2173/**
2174 * i40evf_shutdown - Shutdown the device in preparation for a reboot
2175 * @pdev: pci device structure
2176 **/
2177static void i40evf_shutdown(struct pci_dev *pdev)
2178{
2179 struct net_device *netdev = pci_get_drvdata(pdev);
2180
2181 netif_device_detach(netdev);
2182
2183 if (netif_running(netdev))
2184 i40evf_close(netdev);
2185
2186#ifdef CONFIG_PM
2187 pci_save_state(pdev);
2188
2189#endif
2190 pci_disable_device(pdev);
2191}
2192
2193/**
2194 * i40evf_probe - Device Initialization Routine
2195 * @pdev: PCI device information struct
2196 * @ent: entry in i40evf_pci_tbl
2197 *
2198 * Returns 0 on success, negative on failure
2199 *
2200 * i40evf_probe initializes an adapter identified by a pci_dev structure.
2201 * The OS initialization, configuring of the adapter private structure,
2202 * and a hardware reset occur.
2203 **/
2204static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2205{
2206 struct net_device *netdev;
2207 struct i40evf_adapter *adapter = NULL;
2208 struct i40e_hw *hw = NULL;
Mitch Williamsdbbd8112014-02-20 19:29:08 -08002209 int err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002210
2211 err = pci_enable_device(pdev);
2212 if (err)
2213 return err;
2214
Mitch Williams64942942014-02-11 08:26:33 +00002215 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Mitch Williams64942942014-02-11 08:26:33 +00002216 if (err) {
Jean Sacrene3e3bfd2014-03-25 04:30:27 +00002217 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2218 if (err) {
2219 dev_err(&pdev->dev,
2220 "DMA configuration failed: 0x%x\n", err);
2221 goto err_dma;
2222 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002223 }
2224
2225 err = pci_request_regions(pdev, i40evf_driver_name);
2226 if (err) {
2227 dev_err(&pdev->dev,
2228 "pci_request_regions failed 0x%x\n", err);
2229 goto err_pci_reg;
2230 }
2231
2232 pci_enable_pcie_error_reporting(pdev);
2233
2234 pci_set_master(pdev);
2235
2236 netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter),
2237 MAX_TX_QUEUES);
2238 if (!netdev) {
2239 err = -ENOMEM;
2240 goto err_alloc_etherdev;
2241 }
2242
2243 SET_NETDEV_DEV(netdev, &pdev->dev);
2244
2245 pci_set_drvdata(pdev, netdev);
2246 adapter = netdev_priv(netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +00002247
2248 adapter->netdev = netdev;
2249 adapter->pdev = pdev;
2250
2251 hw = &adapter->hw;
2252 hw->back = adapter;
2253
2254 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
2255 adapter->state = __I40EVF_STARTUP;
2256
2257 /* Call save state here because it relies on the adapter struct. */
2258 pci_save_state(pdev);
2259
2260 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2261 pci_resource_len(pdev, 0));
2262 if (!hw->hw_addr) {
2263 err = -EIO;
2264 goto err_ioremap;
2265 }
2266 hw->vendor_id = pdev->vendor;
2267 hw->device_id = pdev->device;
2268 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2269 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2270 hw->subsystem_device_id = pdev->subsystem_device;
2271 hw->bus.device = PCI_SLOT(pdev->devfn);
2272 hw->bus.func = PCI_FUNC(pdev->devfn);
2273
2274 INIT_WORK(&adapter->reset_task, i40evf_reset_task);
2275 INIT_WORK(&adapter->adminq_task, i40evf_adminq_task);
2276 INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task);
2277 INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task);
2278 schedule_delayed_work(&adapter->init_task, 10);
2279
2280 return 0;
2281
2282err_ioremap:
2283 free_netdev(netdev);
2284err_alloc_etherdev:
2285 pci_release_regions(pdev);
2286err_pci_reg:
2287err_dma:
2288 pci_disable_device(pdev);
2289 return err;
2290}
2291
2292#ifdef CONFIG_PM
2293/**
2294 * i40evf_suspend - Power management suspend routine
2295 * @pdev: PCI device information struct
2296 * @state: unused
2297 *
2298 * Called when the system (VM) is entering sleep/suspend.
2299 **/
2300static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state)
2301{
2302 struct net_device *netdev = pci_get_drvdata(pdev);
2303 struct i40evf_adapter *adapter = netdev_priv(netdev);
2304 int retval = 0;
2305
2306 netif_device_detach(netdev);
2307
2308 if (netif_running(netdev)) {
2309 rtnl_lock();
2310 i40evf_down(adapter);
2311 rtnl_unlock();
2312 }
2313 i40evf_free_misc_irq(adapter);
2314 i40evf_reset_interrupt_capability(adapter);
2315
2316 retval = pci_save_state(pdev);
2317 if (retval)
2318 return retval;
2319
2320 pci_disable_device(pdev);
2321
2322 return 0;
2323}
2324
2325/**
2326 * i40evf_resume - Power managment resume routine
2327 * @pdev: PCI device information struct
2328 *
2329 * Called when the system (VM) is resumed from sleep/suspend.
2330 **/
2331static int i40evf_resume(struct pci_dev *pdev)
2332{
2333 struct i40evf_adapter *adapter = pci_get_drvdata(pdev);
2334 struct net_device *netdev = adapter->netdev;
2335 u32 err;
2336
2337 pci_set_power_state(pdev, PCI_D0);
2338 pci_restore_state(pdev);
2339 /* pci_restore_state clears dev->state_saved so call
2340 * pci_save_state to restore it.
2341 */
2342 pci_save_state(pdev);
2343
2344 err = pci_enable_device_mem(pdev);
2345 if (err) {
2346 dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n");
2347 return err;
2348 }
2349 pci_set_master(pdev);
2350
2351 rtnl_lock();
2352 err = i40evf_set_interrupt_capability(adapter);
2353 if (err) {
2354 dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n");
2355 return err;
2356 }
2357 err = i40evf_request_misc_irq(adapter);
2358 rtnl_unlock();
2359 if (err) {
2360 dev_err(&pdev->dev, "Cannot get interrupt vector.\n");
2361 return err;
2362 }
2363
2364 schedule_work(&adapter->reset_task);
2365
2366 netif_device_attach(netdev);
2367
2368 return err;
2369}
2370
2371#endif /* CONFIG_PM */
2372/**
2373 * i40evf_remove - Device Removal Routine
2374 * @pdev: PCI device information struct
2375 *
2376 * i40evf_remove is called by the PCI subsystem to alert the driver
2377 * that it should release a PCI device. The could be caused by a
2378 * Hot-Plug event, or because the driver is going to be removed from
2379 * memory.
2380 **/
2381static void i40evf_remove(struct pci_dev *pdev)
2382{
2383 struct net_device *netdev = pci_get_drvdata(pdev);
2384 struct i40evf_adapter *adapter = netdev_priv(netdev);
2385 struct i40e_hw *hw = &adapter->hw;
2386
2387 cancel_delayed_work_sync(&adapter->init_task);
Mitch Williamsef8693e2014-02-13 03:48:53 -08002388 cancel_work_sync(&adapter->reset_task);
Greg Rose5eae00c2013-12-21 06:12:45 +00002389
2390 if (adapter->netdev_registered) {
2391 unregister_netdev(netdev);
2392 adapter->netdev_registered = false;
2393 }
2394 adapter->state = __I40EVF_REMOVE;
2395
Mitch Williamsdbb01c82014-02-20 19:29:07 -08002396 if (adapter->msix_entries) {
Greg Rose5eae00c2013-12-21 06:12:45 +00002397 i40evf_misc_irq_disable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002398 i40evf_free_misc_irq(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002399 i40evf_reset_interrupt_capability(adapter);
2400 }
2401
Mitch Williamsdbb01c82014-02-20 19:29:07 -08002402 del_timer_sync(&adapter->watchdog_timer);
2403 flush_scheduled_work();
2404
Greg Rose5eae00c2013-12-21 06:12:45 +00002405 if (hw->aq.asq.count)
2406 i40evf_shutdown_adminq(hw);
2407
2408 iounmap(hw->hw_addr);
2409 pci_release_regions(pdev);
2410
2411 i40evf_free_queues(adapter);
2412 kfree(adapter->vf_res);
2413
2414 free_netdev(netdev);
2415
2416 pci_disable_pcie_error_reporting(pdev);
2417
2418 pci_disable_device(pdev);
2419}
2420
2421static struct pci_driver i40evf_driver = {
2422 .name = i40evf_driver_name,
2423 .id_table = i40evf_pci_tbl,
2424 .probe = i40evf_probe,
2425 .remove = i40evf_remove,
2426#ifdef CONFIG_PM
2427 .suspend = i40evf_suspend,
2428 .resume = i40evf_resume,
2429#endif
2430 .shutdown = i40evf_shutdown,
2431};
2432
2433/**
2434 * i40e_init_module - Driver Registration Routine
2435 *
2436 * i40e_init_module is the first routine called when the driver is
2437 * loaded. All it does is register with the PCI subsystem.
2438 **/
2439static int __init i40evf_init_module(void)
2440{
2441 int ret;
2442 pr_info("i40evf: %s - version %s\n", i40evf_driver_string,
2443 i40evf_driver_version);
2444
2445 pr_info("%s\n", i40evf_copyright);
2446
2447 ret = pci_register_driver(&i40evf_driver);
2448 return ret;
2449}
2450
2451module_init(i40evf_init_module);
2452
2453/**
2454 * i40e_exit_module - Driver Exit Cleanup Routine
2455 *
2456 * i40e_exit_module is called just before the driver is removed
2457 * from memory.
2458 **/
2459static void __exit i40evf_exit_module(void)
2460{
2461 pci_unregister_driver(&i40evf_driver);
2462}
2463
2464module_exit(i40evf_exit_module);
2465
2466/* i40evf_main.c */