blob: 94eff4a269e69acc5da159a0d05467821f095ff5 [file] [log] [blame]
Greg Rose5eae00c2013-12-21 06:12:45 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
Sravanthi Tangeda5b8eb172015-02-06 08:52:21 +00004 * Copyright(c) 2013 - 2015 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);
31static int i40evf_close(struct net_device *netdev);
32
33char i40evf_driver_name[] = "i40evf";
34static const char i40evf_driver_string[] =
Mitch Williams0af56f42014-06-04 20:42:10 +000035 "Intel(R) XL710/X710 Virtual Function Network Driver";
Greg Rose5eae00c2013-12-21 06:12:45 +000036
Catherine Sullivanec7a06f2015-02-27 09:18:37 +000037#define DRV_VERSION "1.2.25"
Greg Rose5eae00c2013-12-21 06:12:45 +000038const char i40evf_driver_version[] = DRV_VERSION;
39static const char i40evf_copyright[] =
Mitch Williams673f2eb2014-02-20 19:29:13 -080040 "Copyright (c) 2013 - 2014 Intel Corporation.";
Greg Rose5eae00c2013-12-21 06:12:45 +000041
42/* i40evf_pci_tbl - PCI Device ID Table
43 *
44 * Wildcard entries (PCI_ANY_ID) should come last
45 * Last entry must be all 0s
46 *
47 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
48 * Class, Class Mask, private data (not used) }
49 */
Benoit Taine9baa3c32014-08-08 15:56:03 +020050static const struct pci_device_id i40evf_pci_tbl[] = {
Shannon Nelsonab600852014-01-17 15:36:39 -080051 {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF), 0},
Greg Rose5eae00c2013-12-21 06:12:45 +000052 /* required last entry */
53 {0, }
54};
55
56MODULE_DEVICE_TABLE(pci, i40evf_pci_tbl);
57
58MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
59MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver");
60MODULE_LICENSE("GPL");
61MODULE_VERSION(DRV_VERSION);
62
63/**
64 * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code
65 * @hw: pointer to the HW structure
66 * @mem: ptr to mem struct to fill out
67 * @size: size of memory requested
68 * @alignment: what to align the allocation to
69 **/
70i40e_status i40evf_allocate_dma_mem_d(struct i40e_hw *hw,
71 struct i40e_dma_mem *mem,
72 u64 size, u32 alignment)
73{
74 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
75
76 if (!mem)
77 return I40E_ERR_PARAM;
78
79 mem->size = ALIGN(size, alignment);
80 mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size,
81 (dma_addr_t *)&mem->pa, GFP_KERNEL);
82 if (mem->va)
83 return 0;
84 else
85 return I40E_ERR_NO_MEMORY;
86}
87
88/**
89 * i40evf_free_dma_mem_d - OS specific memory free for shared code
90 * @hw: pointer to the HW structure
91 * @mem: ptr to mem struct to free
92 **/
93i40e_status i40evf_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
94{
95 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
96
97 if (!mem || !mem->va)
98 return I40E_ERR_PARAM;
99 dma_free_coherent(&adapter->pdev->dev, mem->size,
100 mem->va, (dma_addr_t)mem->pa);
101 return 0;
102}
103
104/**
105 * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code
106 * @hw: pointer to the HW structure
107 * @mem: ptr to mem struct to fill out
108 * @size: size of memory requested
109 **/
110i40e_status i40evf_allocate_virt_mem_d(struct i40e_hw *hw,
111 struct i40e_virt_mem *mem, u32 size)
112{
113 if (!mem)
114 return I40E_ERR_PARAM;
115
116 mem->size = size;
117 mem->va = kzalloc(size, GFP_KERNEL);
118
119 if (mem->va)
120 return 0;
121 else
122 return I40E_ERR_NO_MEMORY;
123}
124
125/**
126 * i40evf_free_virt_mem_d - OS specific memory free for shared code
127 * @hw: pointer to the HW structure
128 * @mem: ptr to mem struct to free
129 **/
130i40e_status i40evf_free_virt_mem_d(struct i40e_hw *hw,
131 struct i40e_virt_mem *mem)
132{
133 if (!mem)
134 return I40E_ERR_PARAM;
135
136 /* it's ok to kfree a NULL pointer */
137 kfree(mem->va);
138
139 return 0;
140}
141
142/**
143 * i40evf_debug_d - OS dependent version of debug printing
144 * @hw: pointer to the HW structure
145 * @mask: debug level mask
146 * @fmt_str: printf-type format description
147 **/
148void i40evf_debug_d(void *hw, u32 mask, char *fmt_str, ...)
149{
150 char buf[512];
151 va_list argptr;
152
153 if (!(mask & ((struct i40e_hw *)hw)->debug_mask))
154 return;
155
156 va_start(argptr, fmt_str);
157 vsnprintf(buf, sizeof(buf), fmt_str, argptr);
158 va_end(argptr);
159
160 /* the debug string is already formatted with a newline */
161 pr_info("%s", buf);
162}
163
164/**
165 * i40evf_tx_timeout - Respond to a Tx Hang
166 * @netdev: network interface device structure
167 **/
168static void i40evf_tx_timeout(struct net_device *netdev)
169{
170 struct i40evf_adapter *adapter = netdev_priv(netdev);
171
172 adapter->tx_timeout_count++;
Mitch Williams67c818a2015-06-19 08:56:30 -0700173 if (!(adapter->flags & (I40EVF_FLAG_RESET_PENDING |
174 I40EVF_FLAG_RESET_NEEDED))) {
Mitch Williams3526d802014-03-06 08:59:56 +0000175 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
Mitch Williams625777e2014-02-20 19:29:05 -0800176 schedule_work(&adapter->reset_task);
177 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000178}
179
180/**
181 * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC
182 * @adapter: board private structure
183 **/
184static void i40evf_misc_irq_disable(struct i40evf_adapter *adapter)
185{
186 struct i40e_hw *hw = &adapter->hw;
Mitch Williams75a64432014-11-11 20:02:42 +0000187
Greg Rose5eae00c2013-12-21 06:12:45 +0000188 wr32(hw, I40E_VFINT_DYN_CTL01, 0);
189
190 /* read flush */
191 rd32(hw, I40E_VFGEN_RSTAT);
192
193 synchronize_irq(adapter->msix_entries[0].vector);
194}
195
196/**
197 * i40evf_misc_irq_enable - Enable default interrupt generation settings
198 * @adapter: board private structure
199 **/
200static void i40evf_misc_irq_enable(struct i40evf_adapter *adapter)
201{
202 struct i40e_hw *hw = &adapter->hw;
Mitch Williams75a64432014-11-11 20:02:42 +0000203
Greg Rose5eae00c2013-12-21 06:12:45 +0000204 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);
Greg Rose5eae00c2013-12-21 06:12:45 +0000230}
231
232/**
233 * i40evf_irq_enable_queues - Enable interrupt for specified queues
234 * @adapter: board private structure
235 * @mask: bitmap of queues to enable
236 **/
237void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask)
238{
239 struct i40e_hw *hw = &adapter->hw;
240 int i;
241
242 for (i = 1; i < adapter->num_msix_vectors; i++) {
243 if (mask & (1 << (i - 1))) {
244 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1),
245 I40E_VFINT_DYN_CTLN1_INTENA_MASK |
Jesse Brandeburg97bf75f2015-02-27 09:18:32 +0000246 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
Greg Rose5eae00c2013-12-21 06:12:45 +0000247 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 **/
Mitch Williams75a64432014-11-11 20:02:42 +0000257static void i40evf_fire_sw_int(struct i40evf_adapter *adapter, u32 mask)
Greg Rose5eae00c2013-12-21 06:12:45 +0000258{
259 struct i40e_hw *hw = &adapter->hw;
260 int i;
261 uint32_t dyn_ctl;
262
Mitch Williams164ec1b2014-06-04 08:45:19 +0000263 if (mask & 1) {
264 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTL01);
265 dyn_ctl |= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK |
Jesse Brandeburg97bf75f2015-02-27 09:18:32 +0000266 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
Mitch Williams164ec1b2014-06-04 08:45:19 +0000267 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK;
268 wr32(hw, I40E_VFINT_DYN_CTL01, dyn_ctl);
269 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000270 for (i = 1; i < adapter->num_msix_vectors; i++) {
271 if (mask & (1 << i)) {
272 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTLN1(i - 1));
273 dyn_ctl |= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK |
Jesse Brandeburg97bf75f2015-02-27 09:18:32 +0000274 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
Greg Rose5eae00c2013-12-21 06:12:45 +0000275 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK;
276 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), dyn_ctl);
277 }
278 }
279}
280
281/**
282 * i40evf_irq_enable - Enable default interrupt generation settings
283 * @adapter: board private structure
284 **/
285void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush)
286{
287 struct i40e_hw *hw = &adapter->hw;
288
Mitch Williams164ec1b2014-06-04 08:45:19 +0000289 i40evf_misc_irq_enable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +0000290 i40evf_irq_enable_queues(adapter, ~0);
291
292 if (flush)
293 rd32(hw, I40E_VFGEN_RSTAT);
294}
295
296/**
297 * i40evf_msix_aq - Interrupt handler for vector 0
298 * @irq: interrupt number
299 * @data: pointer to netdev
300 **/
301static irqreturn_t i40evf_msix_aq(int irq, void *data)
302{
303 struct net_device *netdev = data;
304 struct i40evf_adapter *adapter = netdev_priv(netdev);
305 struct i40e_hw *hw = &adapter->hw;
306 u32 val;
307 u32 ena_mask;
308
309 /* handle non-queue interrupts */
310 val = rd32(hw, I40E_VFINT_ICR01);
311 ena_mask = rd32(hw, I40E_VFINT_ICR0_ENA1);
312
313
314 val = rd32(hw, I40E_VFINT_DYN_CTL01);
315 val = val | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK;
316 wr32(hw, I40E_VFINT_DYN_CTL01, val);
317
Greg Rose5eae00c2013-12-21 06:12:45 +0000318 /* schedule work on the private workqueue */
319 schedule_work(&adapter->adminq_task);
320
321 return IRQ_HANDLED;
322}
323
324/**
325 * i40evf_msix_clean_rings - MSIX mode Interrupt Handler
326 * @irq: interrupt number
327 * @data: pointer to a q_vector
328 **/
329static irqreturn_t i40evf_msix_clean_rings(int irq, void *data)
330{
331 struct i40e_q_vector *q_vector = data;
332
333 if (!q_vector->tx.ring && !q_vector->rx.ring)
334 return IRQ_HANDLED;
335
336 napi_schedule(&q_vector->napi);
337
338 return IRQ_HANDLED;
339}
340
341/**
342 * i40evf_map_vector_to_rxq - associate irqs with rx queues
343 * @adapter: board private structure
344 * @v_idx: interrupt number
345 * @r_idx: queue number
346 **/
347static void
348i40evf_map_vector_to_rxq(struct i40evf_adapter *adapter, int v_idx, int r_idx)
349{
350 struct i40e_q_vector *q_vector = adapter->q_vector[v_idx];
351 struct i40e_ring *rx_ring = adapter->rx_rings[r_idx];
352
353 rx_ring->q_vector = q_vector;
354 rx_ring->next = q_vector->rx.ring;
355 rx_ring->vsi = &adapter->vsi;
356 q_vector->rx.ring = rx_ring;
357 q_vector->rx.count++;
358 q_vector->rx.latency_range = I40E_LOW_LATENCY;
359}
360
361/**
362 * i40evf_map_vector_to_txq - associate irqs with tx queues
363 * @adapter: board private structure
364 * @v_idx: interrupt number
365 * @t_idx: queue number
366 **/
367static void
368i40evf_map_vector_to_txq(struct i40evf_adapter *adapter, int v_idx, int t_idx)
369{
370 struct i40e_q_vector *q_vector = adapter->q_vector[v_idx];
371 struct i40e_ring *tx_ring = adapter->tx_rings[t_idx];
372
373 tx_ring->q_vector = q_vector;
374 tx_ring->next = q_vector->tx.ring;
375 tx_ring->vsi = &adapter->vsi;
376 q_vector->tx.ring = tx_ring;
377 q_vector->tx.count++;
378 q_vector->tx.latency_range = I40E_LOW_LATENCY;
379 q_vector->num_ringpairs++;
380 q_vector->ring_mask |= (1 << t_idx);
381}
382
383/**
384 * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors
385 * @adapter: board private structure to initialize
386 *
387 * This function maps descriptor rings to the queue-specific vectors
388 * we were allotted through the MSI-X enabling code. Ideally, we'd have
389 * one vector per ring/queue, but on a constrained vector budget, we
390 * group the rings as "efficiently" as possible. You would add new
391 * mapping configurations in here.
392 **/
393static int i40evf_map_rings_to_vectors(struct i40evf_adapter *adapter)
394{
395 int q_vectors;
396 int v_start = 0;
397 int rxr_idx = 0, txr_idx = 0;
Mitch Williamscc052922014-10-25 03:24:34 +0000398 int rxr_remaining = adapter->num_active_queues;
399 int txr_remaining = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +0000400 int i, j;
401 int rqpv, tqpv;
402 int err = 0;
403
404 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
405
406 /* The ideal configuration...
407 * We have enough vectors to map one per queue.
408 */
Mitch Williams973371d2015-04-27 14:57:09 -0400409 if (q_vectors >= (rxr_remaining * 2)) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000410 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
411 i40evf_map_vector_to_rxq(adapter, v_start, rxr_idx);
412
413 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
414 i40evf_map_vector_to_txq(adapter, v_start, txr_idx);
415 goto out;
416 }
417
418 /* If we don't have enough vectors for a 1-to-1
419 * mapping, we'll have to group them so there are
420 * multiple queues per vector.
421 * Re-adjusting *qpv takes care of the remainder.
422 */
423 for (i = v_start; i < q_vectors; i++) {
424 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
425 for (j = 0; j < rqpv; j++) {
426 i40evf_map_vector_to_rxq(adapter, i, rxr_idx);
427 rxr_idx++;
428 rxr_remaining--;
429 }
430 }
431 for (i = v_start; i < q_vectors; i++) {
432 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
433 for (j = 0; j < tqpv; j++) {
434 i40evf_map_vector_to_txq(adapter, i, txr_idx);
435 txr_idx++;
436 txr_remaining--;
437 }
438 }
439
440out:
441 adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
442
443 return err;
444}
445
446/**
447 * i40evf_request_traffic_irqs - Initialize MSI-X interrupts
448 * @adapter: board private structure
449 *
450 * Allocates MSI-X vectors for tx and rx handling, and requests
451 * interrupts from the kernel.
452 **/
453static int
454i40evf_request_traffic_irqs(struct i40evf_adapter *adapter, char *basename)
455{
456 int vector, err, q_vectors;
457 int rx_int_idx = 0, tx_int_idx = 0;
458
459 i40evf_irq_disable(adapter);
460 /* Decrement for Other and TCP Timer vectors */
461 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
462
463 for (vector = 0; vector < q_vectors; vector++) {
464 struct i40e_q_vector *q_vector = adapter->q_vector[vector];
465
466 if (q_vector->tx.ring && q_vector->rx.ring) {
467 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
468 "i40evf-%s-%s-%d", basename,
469 "TxRx", rx_int_idx++);
470 tx_int_idx++;
471 } else if (q_vector->rx.ring) {
472 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
473 "i40evf-%s-%s-%d", basename,
474 "rx", rx_int_idx++);
475 } else if (q_vector->tx.ring) {
476 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
477 "i40evf-%s-%s-%d", basename,
478 "tx", tx_int_idx++);
479 } else {
480 /* skip this unused q_vector */
481 continue;
482 }
483 err = request_irq(
484 adapter->msix_entries[vector + NONQ_VECS].vector,
485 i40evf_msix_clean_rings,
486 0,
487 q_vector->name,
488 q_vector);
489 if (err) {
490 dev_info(&adapter->pdev->dev,
491 "%s: request_irq failed, error: %d\n",
492 __func__, err);
493 goto free_queue_irqs;
494 }
495 /* assign the mask for this irq */
496 irq_set_affinity_hint(
497 adapter->msix_entries[vector + NONQ_VECS].vector,
498 q_vector->affinity_mask);
499 }
500
501 return 0;
502
503free_queue_irqs:
504 while (vector) {
505 vector--;
506 irq_set_affinity_hint(
507 adapter->msix_entries[vector + NONQ_VECS].vector,
508 NULL);
509 free_irq(adapter->msix_entries[vector + NONQ_VECS].vector,
510 adapter->q_vector[vector]);
511 }
512 return err;
513}
514
515/**
516 * i40evf_request_misc_irq - Initialize MSI-X interrupts
517 * @adapter: board private structure
518 *
519 * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
520 * vector is only for the admin queue, and stays active even when the netdev
521 * is closed.
522 **/
523static int i40evf_request_misc_irq(struct i40evf_adapter *adapter)
524{
525 struct net_device *netdev = adapter->netdev;
526 int err;
527
Jesse Brandeburgb39c1e22014-08-01 13:27:08 -0700528 snprintf(adapter->misc_vector_name,
Carolyn Wyborny9a21a002015-02-06 08:52:20 +0000529 sizeof(adapter->misc_vector_name) - 1, "i40evf-%s:mbx",
530 dev_name(&adapter->pdev->dev));
Greg Rose5eae00c2013-12-21 06:12:45 +0000531 err = request_irq(adapter->msix_entries[0].vector,
Mitch Williamse1dfee82014-02-13 03:48:51 -0800532 &i40evf_msix_aq, 0,
533 adapter->misc_vector_name, netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +0000534 if (err) {
535 dev_err(&adapter->pdev->dev,
Catherine Sullivan77fa28b2014-02-20 19:29:17 -0800536 "request_irq for %s failed: %d\n",
537 adapter->misc_vector_name, err);
Greg Rose5eae00c2013-12-21 06:12:45 +0000538 free_irq(adapter->msix_entries[0].vector, netdev);
539 }
540 return err;
541}
542
543/**
544 * i40evf_free_traffic_irqs - Free MSI-X interrupts
545 * @adapter: board private structure
546 *
547 * Frees all MSI-X vectors other than 0.
548 **/
549static void i40evf_free_traffic_irqs(struct i40evf_adapter *adapter)
550{
551 int i;
552 int q_vectors;
Mitch Williams75a64432014-11-11 20:02:42 +0000553
Greg Rose5eae00c2013-12-21 06:12:45 +0000554 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
555
556 for (i = 0; i < q_vectors; i++) {
557 irq_set_affinity_hint(adapter->msix_entries[i+1].vector,
558 NULL);
559 free_irq(adapter->msix_entries[i+1].vector,
560 adapter->q_vector[i]);
561 }
562}
563
564/**
565 * i40evf_free_misc_irq - Free MSI-X miscellaneous vector
566 * @adapter: board private structure
567 *
568 * Frees MSI-X vector 0.
569 **/
570static void i40evf_free_misc_irq(struct i40evf_adapter *adapter)
571{
572 struct net_device *netdev = adapter->netdev;
573
574 free_irq(adapter->msix_entries[0].vector, netdev);
575}
576
577/**
578 * i40evf_configure_tx - Configure Transmit Unit after Reset
579 * @adapter: board private structure
580 *
581 * Configure the Tx unit of the MAC after a reset.
582 **/
583static void i40evf_configure_tx(struct i40evf_adapter *adapter)
584{
585 struct i40e_hw *hw = &adapter->hw;
586 int i;
Mitch Williams75a64432014-11-11 20:02:42 +0000587
Mitch Williamscc052922014-10-25 03:24:34 +0000588 for (i = 0; i < adapter->num_active_queues; i++)
Greg Rose5eae00c2013-12-21 06:12:45 +0000589 adapter->tx_rings[i]->tail = hw->hw_addr + I40E_QTX_TAIL1(i);
590}
591
592/**
593 * i40evf_configure_rx - Configure Receive Unit after Reset
594 * @adapter: board private structure
595 *
596 * Configure the Rx unit of the MAC after a reset.
597 **/
598static void i40evf_configure_rx(struct i40evf_adapter *adapter)
599{
600 struct i40e_hw *hw = &adapter->hw;
601 struct net_device *netdev = adapter->netdev;
602 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
603 int i;
604 int rx_buf_len;
605
606
607 adapter->flags &= ~I40EVF_FLAG_RX_PS_CAPABLE;
608 adapter->flags |= I40EVF_FLAG_RX_1BUF_CAPABLE;
609
610 /* Decide whether to use packet split mode or not */
611 if (netdev->mtu > ETH_DATA_LEN) {
612 if (adapter->flags & I40EVF_FLAG_RX_PS_CAPABLE)
613 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
614 else
615 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
616 } else {
617 if (adapter->flags & I40EVF_FLAG_RX_1BUF_CAPABLE)
618 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
619 else
620 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
621 }
622
623 /* Set the RX buffer length according to the mode */
624 if (adapter->flags & I40EVF_FLAG_RX_PS_ENABLED) {
625 rx_buf_len = I40E_RX_HDR_SIZE;
626 } else {
627 if (netdev->mtu <= ETH_DATA_LEN)
628 rx_buf_len = I40EVF_RXBUFFER_2048;
629 else
630 rx_buf_len = ALIGN(max_frame, 1024);
631 }
632
Mitch Williamscc052922014-10-25 03:24:34 +0000633 for (i = 0; i < adapter->num_active_queues; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000634 adapter->rx_rings[i]->tail = hw->hw_addr + I40E_QRX_TAIL1(i);
635 adapter->rx_rings[i]->rx_buf_len = rx_buf_len;
636 }
637}
638
639/**
640 * i40evf_find_vlan - Search filter list for specific vlan filter
641 * @adapter: board private structure
642 * @vlan: vlan tag
643 *
644 * Returns ptr to the filter object or NULL
645 **/
646static struct
647i40evf_vlan_filter *i40evf_find_vlan(struct i40evf_adapter *adapter, u16 vlan)
648{
649 struct i40evf_vlan_filter *f;
650
651 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
652 if (vlan == f->vlan)
653 return f;
654 }
655 return NULL;
656}
657
658/**
659 * i40evf_add_vlan - Add a vlan filter to the list
660 * @adapter: board private structure
661 * @vlan: VLAN tag
662 *
663 * Returns ptr to the filter object or NULL when no memory available.
664 **/
665static struct
666i40evf_vlan_filter *i40evf_add_vlan(struct i40evf_adapter *adapter, u16 vlan)
667{
Mitch Williams13acb542015-03-31 00:45:05 -0700668 struct i40evf_vlan_filter *f = NULL;
669 int count = 50;
670
671 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
672 &adapter->crit_section)) {
673 udelay(1);
674 if (--count == 0)
675 goto out;
676 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000677
678 f = i40evf_find_vlan(adapter, vlan);
Mitch Williams348d4992014-11-11 20:02:52 +0000679 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000680 f = kzalloc(sizeof(*f), GFP_ATOMIC);
Mitch Williams348d4992014-11-11 20:02:52 +0000681 if (!f)
Mitch Williams13acb542015-03-31 00:45:05 -0700682 goto clearout;
Mitch Williams249c8b82014-05-10 04:49:04 +0000683
Greg Rose5eae00c2013-12-21 06:12:45 +0000684 f->vlan = vlan;
685
686 INIT_LIST_HEAD(&f->list);
687 list_add(&f->list, &adapter->vlan_filter_list);
688 f->add = true;
689 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
690 }
691
Mitch Williams13acb542015-03-31 00:45:05 -0700692clearout:
693 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
694out:
Greg Rose5eae00c2013-12-21 06:12:45 +0000695 return f;
696}
697
698/**
699 * i40evf_del_vlan - Remove a vlan filter from the list
700 * @adapter: board private structure
701 * @vlan: VLAN tag
702 **/
703static void i40evf_del_vlan(struct i40evf_adapter *adapter, u16 vlan)
704{
705 struct i40evf_vlan_filter *f;
Mitch Williams13acb542015-03-31 00:45:05 -0700706 int count = 50;
707
708 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
709 &adapter->crit_section)) {
710 udelay(1);
711 if (--count == 0)
712 return;
713 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000714
715 f = i40evf_find_vlan(adapter, vlan);
716 if (f) {
717 f->remove = true;
718 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
719 }
Mitch Williams13acb542015-03-31 00:45:05 -0700720 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Greg Rose5eae00c2013-12-21 06:12:45 +0000721}
722
723/**
724 * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device
725 * @netdev: network device struct
726 * @vid: VLAN tag
727 **/
728static int i40evf_vlan_rx_add_vid(struct net_device *netdev,
Mitch Williams75a64432014-11-11 20:02:42 +0000729 __always_unused __be16 proto, u16 vid)
Greg Rose5eae00c2013-12-21 06:12:45 +0000730{
731 struct i40evf_adapter *adapter = netdev_priv(netdev);
732
733 if (i40evf_add_vlan(adapter, vid) == NULL)
734 return -ENOMEM;
735 return 0;
736}
737
738/**
739 * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device
740 * @netdev: network device struct
741 * @vid: VLAN tag
742 **/
743static int i40evf_vlan_rx_kill_vid(struct net_device *netdev,
Mitch Williams75a64432014-11-11 20:02:42 +0000744 __always_unused __be16 proto, u16 vid)
Greg Rose5eae00c2013-12-21 06:12:45 +0000745{
746 struct i40evf_adapter *adapter = netdev_priv(netdev);
747
748 i40evf_del_vlan(adapter, vid);
749 return 0;
750}
751
752/**
753 * i40evf_find_filter - Search filter list for specific mac filter
754 * @adapter: board private structure
755 * @macaddr: the MAC address
756 *
757 * Returns ptr to the filter object or NULL
758 **/
759static struct
760i40evf_mac_filter *i40evf_find_filter(struct i40evf_adapter *adapter,
761 u8 *macaddr)
762{
763 struct i40evf_mac_filter *f;
764
765 if (!macaddr)
766 return NULL;
767
768 list_for_each_entry(f, &adapter->mac_filter_list, list) {
769 if (ether_addr_equal(macaddr, f->macaddr))
770 return f;
771 }
772 return NULL;
773}
774
775/**
776 * i40e_add_filter - Add a mac filter to the filter list
777 * @adapter: board private structure
778 * @macaddr: the MAC address
779 *
780 * Returns ptr to the filter object or NULL when no memory available.
781 **/
782static struct
783i40evf_mac_filter *i40evf_add_filter(struct i40evf_adapter *adapter,
784 u8 *macaddr)
785{
786 struct i40evf_mac_filter *f;
Mitch Williams54e16f62015-01-29 07:17:20 +0000787 int count = 50;
Greg Rose5eae00c2013-12-21 06:12:45 +0000788
789 if (!macaddr)
790 return NULL;
791
792 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
Mitch Williams54e16f62015-01-29 07:17:20 +0000793 &adapter->crit_section)) {
Mitch Williamsb65476c2014-07-09 07:46:14 +0000794 udelay(1);
Mitch Williams54e16f62015-01-29 07:17:20 +0000795 if (--count == 0)
796 return NULL;
797 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000798
799 f = i40evf_find_filter(adapter, macaddr);
Mitch Williams348d4992014-11-11 20:02:52 +0000800 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000801 f = kzalloc(sizeof(*f), GFP_ATOMIC);
Mitch Williams348d4992014-11-11 20:02:52 +0000802 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000803 clear_bit(__I40EVF_IN_CRITICAL_TASK,
804 &adapter->crit_section);
805 return NULL;
806 }
807
Greg Rose9a173902014-05-22 06:32:02 +0000808 ether_addr_copy(f->macaddr, macaddr);
Greg Rose5eae00c2013-12-21 06:12:45 +0000809
810 list_add(&f->list, &adapter->mac_filter_list);
811 f->add = true;
812 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
813 }
814
815 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
816 return f;
817}
818
819/**
820 * i40evf_set_mac - NDO callback to set port mac address
821 * @netdev: network interface device structure
822 * @p: pointer to an address structure
823 *
824 * Returns 0 on success, negative on failure
825 **/
826static int i40evf_set_mac(struct net_device *netdev, void *p)
827{
828 struct i40evf_adapter *adapter = netdev_priv(netdev);
829 struct i40e_hw *hw = &adapter->hw;
830 struct i40evf_mac_filter *f;
831 struct sockaddr *addr = p;
832
833 if (!is_valid_ether_addr(addr->sa_data))
834 return -EADDRNOTAVAIL;
835
836 if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
837 return 0;
838
839 f = i40evf_add_filter(adapter, addr->sa_data);
840 if (f) {
Greg Rose9a173902014-05-22 06:32:02 +0000841 ether_addr_copy(hw->mac.addr, addr->sa_data);
842 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +0000843 }
844
845 return (f == NULL) ? -ENOMEM : 0;
846}
847
848/**
849 * i40evf_set_rx_mode - NDO callback to set the netdev filters
850 * @netdev: network interface device structure
851 **/
852static void i40evf_set_rx_mode(struct net_device *netdev)
853{
854 struct i40evf_adapter *adapter = netdev_priv(netdev);
855 struct i40evf_mac_filter *f, *ftmp;
856 struct netdev_hw_addr *uca;
857 struct netdev_hw_addr *mca;
Mitch Williams54e16f62015-01-29 07:17:20 +0000858 int count = 50;
Greg Rose5eae00c2013-12-21 06:12:45 +0000859
860 /* add addr if not already in the filter list */
861 netdev_for_each_uc_addr(uca, netdev) {
862 i40evf_add_filter(adapter, uca->addr);
863 }
864 netdev_for_each_mc_addr(mca, netdev) {
865 i40evf_add_filter(adapter, mca->addr);
866 }
867
868 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
Mitch Williams54e16f62015-01-29 07:17:20 +0000869 &adapter->crit_section)) {
Mitch Williamsb65476c2014-07-09 07:46:14 +0000870 udelay(1);
Mitch Williams54e16f62015-01-29 07:17:20 +0000871 if (--count == 0) {
872 dev_err(&adapter->pdev->dev,
873 "Failed to get lock in %s\n", __func__);
874 return;
875 }
876 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000877 /* remove filter if not in netdev list */
878 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
879 bool found = false;
880
Tobias Klauserdc5f2de2014-05-20 08:23:06 +0000881 if (is_multicast_ether_addr(f->macaddr)) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000882 netdev_for_each_mc_addr(mca, netdev) {
883 if (ether_addr_equal(mca->addr, f->macaddr)) {
884 found = true;
885 break;
886 }
887 }
888 } else {
889 netdev_for_each_uc_addr(uca, netdev) {
890 if (ether_addr_equal(uca->addr, f->macaddr)) {
891 found = true;
892 break;
893 }
894 }
895 }
896 if (found) {
897 f->remove = true;
898 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
899 }
900 }
901 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
902}
903
904/**
905 * i40evf_napi_enable_all - enable NAPI on all queue vectors
906 * @adapter: board private structure
907 **/
908static void i40evf_napi_enable_all(struct i40evf_adapter *adapter)
909{
910 int q_idx;
911 struct i40e_q_vector *q_vector;
912 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
913
914 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
915 struct napi_struct *napi;
Mitch Williams75a64432014-11-11 20:02:42 +0000916
Greg Rose5eae00c2013-12-21 06:12:45 +0000917 q_vector = adapter->q_vector[q_idx];
918 napi = &q_vector->napi;
919 napi_enable(napi);
920 }
921}
922
923/**
924 * i40evf_napi_disable_all - disable NAPI on all queue vectors
925 * @adapter: board private structure
926 **/
927static void i40evf_napi_disable_all(struct i40evf_adapter *adapter)
928{
929 int q_idx;
930 struct i40e_q_vector *q_vector;
931 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
932
933 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
934 q_vector = adapter->q_vector[q_idx];
935 napi_disable(&q_vector->napi);
936 }
937}
938
939/**
940 * i40evf_configure - set up transmit and receive data structures
941 * @adapter: board private structure
942 **/
943static void i40evf_configure(struct i40evf_adapter *adapter)
944{
945 struct net_device *netdev = adapter->netdev;
946 int i;
947
948 i40evf_set_rx_mode(netdev);
949
950 i40evf_configure_tx(adapter);
951 i40evf_configure_rx(adapter);
952 adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
953
Mitch Williamscc052922014-10-25 03:24:34 +0000954 for (i = 0; i < adapter->num_active_queues; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000955 struct i40e_ring *ring = adapter->rx_rings[i];
Mitch Williams75a64432014-11-11 20:02:42 +0000956
Mitch Williamsa132af22015-01-24 09:58:35 +0000957 i40evf_alloc_rx_buffers_1buf(ring, ring->count);
Greg Rose5eae00c2013-12-21 06:12:45 +0000958 ring->next_to_use = ring->count - 1;
959 writel(ring->next_to_use, ring->tail);
960 }
961}
962
963/**
964 * i40evf_up_complete - Finish the last steps of bringing up a connection
965 * @adapter: board private structure
966 **/
967static int i40evf_up_complete(struct i40evf_adapter *adapter)
968{
969 adapter->state = __I40EVF_RUNNING;
970 clear_bit(__I40E_DOWN, &adapter->vsi.state);
971
972 i40evf_napi_enable_all(adapter);
973
974 adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
975 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
976 return 0;
977}
978
979/**
Greg Rose5eae00c2013-12-21 06:12:45 +0000980 * i40e_down - Shutdown the connection processing
981 * @adapter: board private structure
982 **/
983void i40evf_down(struct i40evf_adapter *adapter)
984{
985 struct net_device *netdev = adapter->netdev;
986 struct i40evf_mac_filter *f;
987
Mitch Williamsddf0b3a2014-05-22 06:31:46 +0000988 if (adapter->state == __I40EVF_DOWN)
989 return;
990
Mitch A Williams53d0b3a2014-12-09 08:53:04 +0000991 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
992 &adapter->crit_section))
993 usleep_range(500, 1000);
994
Mitch Williams63e18c22015-03-27 00:12:10 -0700995 netif_carrier_off(netdev);
996 netif_tx_disable(netdev);
Mitch Williams748c4342015-01-29 07:17:18 +0000997 i40evf_napi_disable_all(adapter);
Mitch Williams63e18c22015-03-27 00:12:10 -0700998 i40evf_irq_disable(adapter);
Mitch A Williams53d0b3a2014-12-09 08:53:04 +0000999
Mitch Williamsef8693e2014-02-13 03:48:53 -08001000 /* remove all MAC filters */
Greg Rose5eae00c2013-12-21 06:12:45 +00001001 list_for_each_entry(f, &adapter->mac_filter_list, list) {
1002 f->remove = true;
1003 }
Mitch Williamsed1f5b52014-02-20 19:29:06 -08001004 /* remove all VLAN filters */
1005 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
1006 f->remove = true;
1007 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001008 if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) &&
1009 adapter->state != __I40EVF_RESETTING) {
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001010 /* cancel any current operation */
1011 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001012 /* Schedule operations to close down the HW. Don't wait
1013 * here for this to complete. The watchdog is still running
1014 * and it will take care of this.
1015 */
1016 adapter->aq_required = I40EVF_FLAG_AQ_DEL_MAC_FILTER;
Mitch Williamsed1f5b52014-02-20 19:29:06 -08001017 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001018 adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001019 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001020
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001021 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Greg Rose5eae00c2013-12-21 06:12:45 +00001022}
1023
1024/**
1025 * i40evf_acquire_msix_vectors - Setup the MSIX capability
1026 * @adapter: board private structure
1027 * @vectors: number of vectors to request
1028 *
1029 * Work with the OS to set up the MSIX vectors needed.
1030 *
1031 * Returns 0 on success, negative on failure
1032 **/
1033static int
1034i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors)
1035{
1036 int err, vector_threshold;
1037
1038 /* We'll want at least 3 (vector_threshold):
1039 * 0) Other (Admin Queue and link, mostly)
1040 * 1) TxQ[0] Cleanup
1041 * 2) RxQ[0] Cleanup
1042 */
1043 vector_threshold = MIN_MSIX_COUNT;
1044
1045 /* The more we get, the more we will assign to Tx/Rx Cleanup
1046 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1047 * Right now, we simply care about how many we'll get; we'll
1048 * set them up later while requesting irq's.
1049 */
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001050 err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
1051 vector_threshold, vectors);
1052 if (err < 0) {
Mitch Williams80e72892014-05-10 04:49:06 +00001053 dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001054 kfree(adapter->msix_entries);
1055 adapter->msix_entries = NULL;
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001056 return err;
Greg Rose5eae00c2013-12-21 06:12:45 +00001057 }
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001058
1059 /* Adjust for only the vectors we'll use, which is minimum
1060 * of max_msix_q_vectors + NONQ_VECS, or the number of
1061 * vectors we were allocated.
1062 */
1063 adapter->num_msix_vectors = err;
1064 return 0;
Greg Rose5eae00c2013-12-21 06:12:45 +00001065}
1066
1067/**
1068 * i40evf_free_queues - Free memory for all rings
1069 * @adapter: board private structure to initialize
1070 *
1071 * Free all of the memory associated with queue pairs.
1072 **/
1073static void i40evf_free_queues(struct i40evf_adapter *adapter)
1074{
1075 int i;
1076
1077 if (!adapter->vsi_res)
1078 return;
Mitch Williamscc052922014-10-25 03:24:34 +00001079 for (i = 0; i < adapter->num_active_queues; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001080 if (adapter->tx_rings[i])
1081 kfree_rcu(adapter->tx_rings[i], rcu);
1082 adapter->tx_rings[i] = NULL;
1083 adapter->rx_rings[i] = NULL;
1084 }
1085}
1086
1087/**
1088 * i40evf_alloc_queues - Allocate memory for all rings
1089 * @adapter: board private structure to initialize
1090 *
1091 * We allocate one ring per queue at run-time since we don't know the
1092 * number of queues at compile-time. The polling_netdev array is
1093 * intended for Multiqueue, but should work fine with a single queue.
1094 **/
1095static int i40evf_alloc_queues(struct i40evf_adapter *adapter)
1096{
1097 int i;
1098
Mitch Williamscc052922014-10-25 03:24:34 +00001099 for (i = 0; i < adapter->num_active_queues; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001100 struct i40e_ring *tx_ring;
1101 struct i40e_ring *rx_ring;
1102
Mitch Williams75a64432014-11-11 20:02:42 +00001103 tx_ring = kzalloc(sizeof(*tx_ring) * 2, GFP_KERNEL);
Greg Rose5eae00c2013-12-21 06:12:45 +00001104 if (!tx_ring)
1105 goto err_out;
1106
1107 tx_ring->queue_index = i;
1108 tx_ring->netdev = adapter->netdev;
1109 tx_ring->dev = &adapter->pdev->dev;
Mitch Williamsd732a182014-04-24 06:41:37 +00001110 tx_ring->count = adapter->tx_desc_count;
Greg Rose5eae00c2013-12-21 06:12:45 +00001111 adapter->tx_rings[i] = tx_ring;
1112
1113 rx_ring = &tx_ring[1];
1114 rx_ring->queue_index = i;
1115 rx_ring->netdev = adapter->netdev;
1116 rx_ring->dev = &adapter->pdev->dev;
Mitch Williamsd732a182014-04-24 06:41:37 +00001117 rx_ring->count = adapter->rx_desc_count;
Greg Rose5eae00c2013-12-21 06:12:45 +00001118 adapter->rx_rings[i] = rx_ring;
1119 }
1120
1121 return 0;
1122
1123err_out:
1124 i40evf_free_queues(adapter);
1125 return -ENOMEM;
1126}
1127
1128/**
1129 * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
1130 * @adapter: board private structure to initialize
1131 *
1132 * Attempt to configure the interrupts using the best available
1133 * capabilities of the hardware and the kernel.
1134 **/
1135static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter)
1136{
1137 int vector, v_budget;
1138 int pairs = 0;
1139 int err = 0;
1140
1141 if (!adapter->vsi_res) {
1142 err = -EIO;
1143 goto out;
1144 }
Mitch Williamscc052922014-10-25 03:24:34 +00001145 pairs = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +00001146
1147 /* It's easy to be greedy for MSI-X vectors, but it really
1148 * doesn't do us much good if we have a lot more vectors
1149 * than CPU's. So let's be conservative and only ask for
1150 * (roughly) twice the number of vectors as there are CPU's.
1151 */
Mitch Williams30a500e2014-02-11 08:27:52 +00001152 v_budget = min_t(int, pairs, (int)(num_online_cpus() * 2)) + NONQ_VECS;
1153 v_budget = min_t(int, v_budget, (int)adapter->vf_res->max_vectors);
Greg Rose5eae00c2013-12-21 06:12:45 +00001154
Greg Rose5eae00c2013-12-21 06:12:45 +00001155 adapter->msix_entries = kcalloc(v_budget,
1156 sizeof(struct msix_entry), GFP_KERNEL);
1157 if (!adapter->msix_entries) {
1158 err = -ENOMEM;
1159 goto out;
1160 }
1161
1162 for (vector = 0; vector < v_budget; vector++)
1163 adapter->msix_entries[vector].entry = vector;
1164
1165 i40evf_acquire_msix_vectors(adapter, v_budget);
1166
1167out:
1168 adapter->netdev->real_num_tx_queues = pairs;
1169 return err;
1170}
1171
1172/**
1173 * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
1174 * @adapter: board private structure to initialize
1175 *
1176 * We allocate one q_vector per queue interrupt. If allocation fails we
1177 * return -ENOMEM.
1178 **/
1179static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter)
1180{
1181 int q_idx, num_q_vectors;
1182 struct i40e_q_vector *q_vector;
1183
1184 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
1185
1186 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Mitch Williams75a64432014-11-11 20:02:42 +00001187 q_vector = kzalloc(sizeof(*q_vector), GFP_KERNEL);
Greg Rose5eae00c2013-12-21 06:12:45 +00001188 if (!q_vector)
1189 goto err_out;
1190 q_vector->adapter = adapter;
1191 q_vector->vsi = &adapter->vsi;
1192 q_vector->v_idx = q_idx;
1193 netif_napi_add(adapter->netdev, &q_vector->napi,
Mitch Williams75a64432014-11-11 20:02:42 +00001194 i40evf_napi_poll, NAPI_POLL_WEIGHT);
Greg Rose5eae00c2013-12-21 06:12:45 +00001195 adapter->q_vector[q_idx] = q_vector;
1196 }
1197
1198 return 0;
1199
1200err_out:
1201 while (q_idx) {
1202 q_idx--;
1203 q_vector = adapter->q_vector[q_idx];
1204 netif_napi_del(&q_vector->napi);
1205 kfree(q_vector);
1206 adapter->q_vector[q_idx] = NULL;
1207 }
1208 return -ENOMEM;
1209}
1210
1211/**
1212 * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
1213 * @adapter: board private structure to initialize
1214 *
1215 * This function frees the memory allocated to the q_vectors. In addition if
1216 * NAPI is enabled it will delete any references to the NAPI struct prior
1217 * to freeing the q_vector.
1218 **/
1219static void i40evf_free_q_vectors(struct i40evf_adapter *adapter)
1220{
1221 int q_idx, num_q_vectors;
1222 int napi_vectors;
1223
1224 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
Mitch Williamscc052922014-10-25 03:24:34 +00001225 napi_vectors = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +00001226
1227 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
1228 struct i40e_q_vector *q_vector = adapter->q_vector[q_idx];
1229
1230 adapter->q_vector[q_idx] = NULL;
1231 if (q_idx < napi_vectors)
1232 netif_napi_del(&q_vector->napi);
1233 kfree(q_vector);
1234 }
1235}
1236
1237/**
1238 * i40evf_reset_interrupt_capability - Reset MSIX setup
1239 * @adapter: board private structure
1240 *
1241 **/
1242void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter)
1243{
1244 pci_disable_msix(adapter->pdev);
1245 kfree(adapter->msix_entries);
1246 adapter->msix_entries = NULL;
Greg Rose5eae00c2013-12-21 06:12:45 +00001247}
1248
1249/**
1250 * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
1251 * @adapter: board private structure to initialize
1252 *
1253 **/
1254int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter)
1255{
1256 int err;
1257
1258 err = i40evf_set_interrupt_capability(adapter);
1259 if (err) {
1260 dev_err(&adapter->pdev->dev,
1261 "Unable to setup interrupt capabilities\n");
1262 goto err_set_interrupt;
1263 }
1264
1265 err = i40evf_alloc_q_vectors(adapter);
1266 if (err) {
1267 dev_err(&adapter->pdev->dev,
1268 "Unable to allocate memory for queue vectors\n");
1269 goto err_alloc_q_vectors;
1270 }
1271
1272 err = i40evf_alloc_queues(adapter);
1273 if (err) {
1274 dev_err(&adapter->pdev->dev,
1275 "Unable to allocate memory for queues\n");
1276 goto err_alloc_queues;
1277 }
1278
1279 dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u",
Mitch Williams75a64432014-11-11 20:02:42 +00001280 (adapter->num_active_queues > 1) ? "Enabled" : "Disabled",
1281 adapter->num_active_queues);
Greg Rose5eae00c2013-12-21 06:12:45 +00001282
1283 return 0;
1284err_alloc_queues:
1285 i40evf_free_q_vectors(adapter);
1286err_alloc_q_vectors:
1287 i40evf_reset_interrupt_capability(adapter);
1288err_set_interrupt:
1289 return err;
1290}
1291
1292/**
1293 * i40evf_watchdog_timer - Periodic call-back timer
1294 * @data: pointer to adapter disguised as unsigned long
1295 **/
1296static void i40evf_watchdog_timer(unsigned long data)
1297{
1298 struct i40evf_adapter *adapter = (struct i40evf_adapter *)data;
Mitch Williams75a64432014-11-11 20:02:42 +00001299
Greg Rose5eae00c2013-12-21 06:12:45 +00001300 schedule_work(&adapter->watchdog_task);
1301 /* timer will be rescheduled in watchdog task */
1302}
1303
1304/**
1305 * i40evf_watchdog_task - Periodic call-back task
1306 * @work: pointer to work_struct
1307 **/
1308static void i40evf_watchdog_task(struct work_struct *work)
1309{
1310 struct i40evf_adapter *adapter = container_of(work,
Mitch Williams75a64432014-11-11 20:02:42 +00001311 struct i40evf_adapter,
1312 watchdog_task);
Greg Rose5eae00c2013-12-21 06:12:45 +00001313 struct i40e_hw *hw = &adapter->hw;
Ashish Shahfd358862014-08-01 13:27:11 -07001314 uint32_t rstat_val;
Greg Rose5eae00c2013-12-21 06:12:45 +00001315
Greg Rose5eae00c2013-12-21 06:12:45 +00001316 if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section))
Mitch Williamsef8693e2014-02-13 03:48:53 -08001317 goto restart_watchdog;
1318
1319 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
Ashish Shahfd358862014-08-01 13:27:11 -07001320 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1321 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1322 if ((rstat_val == I40E_VFR_VFACTIVE) ||
1323 (rstat_val == I40E_VFR_COMPLETED)) {
Mitch Williamsef8693e2014-02-13 03:48:53 -08001324 /* A chance for redemption! */
1325 dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n");
1326 adapter->state = __I40EVF_STARTUP;
1327 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
1328 schedule_delayed_work(&adapter->init_task, 10);
1329 clear_bit(__I40EVF_IN_CRITICAL_TASK,
1330 &adapter->crit_section);
1331 /* Don't reschedule the watchdog, since we've restarted
1332 * the init task. When init_task contacts the PF and
1333 * gets everything set up again, it'll restart the
1334 * watchdog for us. Down, boy. Sit. Stay. Woof.
1335 */
1336 return;
1337 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001338 adapter->aq_required = 0;
1339 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1340 goto watchdog_done;
1341 }
1342
1343 if ((adapter->state < __I40EVF_DOWN) ||
1344 (adapter->flags & I40EVF_FLAG_RESET_PENDING))
Greg Rose5eae00c2013-12-21 06:12:45 +00001345 goto watchdog_done;
1346
Mitch Williamsef8693e2014-02-13 03:48:53 -08001347 /* check for reset */
Ashish Shahfd358862014-08-01 13:27:11 -07001348 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
Mitch Williams75a64432014-11-11 20:02:42 +00001349 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001350 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) &&
Ashish Shahfd358862014-08-01 13:27:11 -07001351 (rstat_val != I40E_VFR_VFACTIVE) &&
1352 (rstat_val != I40E_VFR_COMPLETED)) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001353 adapter->state = __I40EVF_RESETTING;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001354 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
Mitch Williams249c8b82014-05-10 04:49:04 +00001355 dev_err(&adapter->pdev->dev, "Hardware reset detected\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001356 schedule_work(&adapter->reset_task);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001357 adapter->aq_required = 0;
1358 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001359 goto watchdog_done;
1360 }
1361
1362 /* Process admin queue tasks. After init, everything gets done
1363 * here so we don't race on the admin queue.
1364 */
Mitch Williamsed636962015-04-07 19:45:32 -04001365 if (adapter->current_op) {
Mitch A Williams0758e7cb2014-12-09 08:53:08 +00001366 if (!i40evf_asq_done(hw)) {
1367 dev_dbg(&adapter->pdev->dev, "Admin queue timeout\n");
1368 i40evf_send_api_ver(adapter);
1369 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001370 goto watchdog_done;
Mitch A Williams0758e7cb2014-12-09 08:53:08 +00001371 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001372
Mitch Williamse284fc82015-03-27 00:12:09 -07001373 if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) {
1374 i40evf_disable_queues(adapter);
1375 goto watchdog_done;
1376 }
1377
Greg Rose5eae00c2013-12-21 06:12:45 +00001378 if (adapter->aq_required & I40EVF_FLAG_AQ_MAP_VECTORS) {
1379 i40evf_map_queues(adapter);
1380 goto watchdog_done;
1381 }
1382
1383 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_MAC_FILTER) {
1384 i40evf_add_ether_addrs(adapter);
1385 goto watchdog_done;
1386 }
1387
1388 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_VLAN_FILTER) {
1389 i40evf_add_vlans(adapter);
1390 goto watchdog_done;
1391 }
1392
1393 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_MAC_FILTER) {
1394 i40evf_del_ether_addrs(adapter);
1395 goto watchdog_done;
1396 }
1397
1398 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_VLAN_FILTER) {
1399 i40evf_del_vlans(adapter);
1400 goto watchdog_done;
1401 }
1402
Greg Rose5eae00c2013-12-21 06:12:45 +00001403 if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_QUEUES) {
1404 i40evf_configure_queues(adapter);
1405 goto watchdog_done;
1406 }
1407
1408 if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_QUEUES) {
1409 i40evf_enable_queues(adapter);
1410 goto watchdog_done;
1411 }
1412
1413 if (adapter->state == __I40EVF_RUNNING)
1414 i40evf_request_stats(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001415watchdog_done:
Mitch A Williams4870e172014-12-09 08:53:06 +00001416 if (adapter->state == __I40EVF_RUNNING) {
1417 i40evf_irq_enable_queues(adapter, ~0);
1418 i40evf_fire_sw_int(adapter, 0xFF);
1419 } else {
1420 i40evf_fire_sw_int(adapter, 0x1);
1421 }
1422
Mitch Williamsef8693e2014-02-13 03:48:53 -08001423 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1424restart_watchdog:
Ashish Shahd3e2edb2014-08-01 13:27:12 -07001425 if (adapter->state == __I40EVF_REMOVE)
1426 return;
Greg Rose5eae00c2013-12-21 06:12:45 +00001427 if (adapter->aq_required)
1428 mod_timer(&adapter->watchdog_timer,
1429 jiffies + msecs_to_jiffies(20));
1430 else
1431 mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2));
Greg Rose5eae00c2013-12-21 06:12:45 +00001432 schedule_work(&adapter->adminq_task);
1433}
1434
Mitch A Williams5b7af022014-03-28 06:49:02 +00001435/**
Anjali Singhai Jain9a9c8ae2015-03-31 00:45:06 -07001436 * i40evf_configure_rss - Prepare for RSS
Greg Rose5eae00c2013-12-21 06:12:45 +00001437 * @adapter: board private structure
1438 **/
1439static void i40evf_configure_rss(struct i40evf_adapter *adapter)
1440{
Eric Dumazet22f258a2014-11-16 06:23:13 -08001441 u32 rss_key[I40E_VFQF_HKEY_MAX_INDEX + 1];
Greg Rose5eae00c2013-12-21 06:12:45 +00001442 struct i40e_hw *hw = &adapter->hw;
Anjali Singhai Jain9a9c8ae2015-03-31 00:45:06 -07001443 u32 cqueue = 0;
Greg Rose5eae00c2013-12-21 06:12:45 +00001444 u32 lut = 0;
1445 int i, j;
1446 u64 hena;
1447
Mitch Williamscc052922014-10-25 03:24:34 +00001448 /* Hash type is configured by the PF - we just supply the key */
Eric Dumazet22f258a2014-11-16 06:23:13 -08001449 netdev_rss_key_fill(rss_key, sizeof(rss_key));
Anjali Singhai Jain9a9c8ae2015-03-31 00:45:06 -07001450
1451 /* Fill out hash function seed */
Greg Rose5eae00c2013-12-21 06:12:45 +00001452 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
Eric Dumazet22f258a2014-11-16 06:23:13 -08001453 wr32(hw, I40E_VFQF_HKEY(i), rss_key[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00001454
1455 /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
1456 hena = I40E_DEFAULT_RSS_HENA;
1457 wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
1458 wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
1459
1460 /* Populate the LUT with max no. of queues in round robin fashion */
Mitch Williams96d47702014-02-11 08:27:50 +00001461 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) {
Anjali Singhai Jain9a9c8ae2015-03-31 00:45:06 -07001462 lut = 0;
1463 for (j = 0; j < 4; j++) {
Mitch Williams40746eb2015-06-22 17:26:38 -07001464 if (cqueue == adapter->num_active_queues)
Anjali Singhai Jain9a9c8ae2015-03-31 00:45:06 -07001465 cqueue = 0;
1466 lut |= ((cqueue) << (8 * j));
1467 cqueue++;
1468 }
Mitch Williams96d47702014-02-11 08:27:50 +00001469 wr32(hw, I40E_VFQF_HLUT(i), lut);
Greg Rose5eae00c2013-12-21 06:12:45 +00001470 }
1471 i40e_flush(hw);
1472}
1473
Mitch Williams67c818a2015-06-19 08:56:30 -07001474#define I40EVF_RESET_WAIT_MS 10
1475#define I40EVF_RESET_WAIT_COUNT 500
Greg Rose5eae00c2013-12-21 06:12:45 +00001476/**
1477 * i40evf_reset_task - Call-back task to handle hardware reset
1478 * @work: pointer to work_struct
1479 *
1480 * During reset we need to shut down and reinitialize the admin queue
1481 * before we can use it to communicate with the PF again. We also clear
1482 * and reinit the rings because that context is lost as well.
1483 **/
1484static void i40evf_reset_task(struct work_struct *work)
1485{
Mitch Williamsef8693e2014-02-13 03:48:53 -08001486 struct i40evf_adapter *adapter = container_of(work,
1487 struct i40evf_adapter,
1488 reset_task);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001489 struct net_device *netdev = adapter->netdev;
Greg Rose5eae00c2013-12-21 06:12:45 +00001490 struct i40e_hw *hw = &adapter->hw;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001491 struct i40evf_mac_filter *f;
Greg Rose5eae00c2013-12-21 06:12:45 +00001492 uint32_t rstat_val;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001493 int i = 0, err;
Greg Rose5eae00c2013-12-21 06:12:45 +00001494
1495 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
1496 &adapter->crit_section))
Neerav Parikhf98a2002014-09-13 07:40:44 +00001497 usleep_range(500, 1000);
Mitch Williams3526d802014-03-06 08:59:56 +00001498
Mitch Williams67c818a2015-06-19 08:56:30 -07001499 i40evf_misc_irq_disable(adapter);
Mitch Williams3526d802014-03-06 08:59:56 +00001500 if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) {
Mitch Williams67c818a2015-06-19 08:56:30 -07001501 adapter->flags &= ~I40EVF_FLAG_RESET_NEEDED;
1502 /* Restart the AQ here. If we have been reset but didn't
1503 * detect it, or if the PF had to reinit, our AQ will be hosed.
1504 */
1505 i40evf_shutdown_adminq(hw);
1506 i40evf_init_adminq(hw);
Mitch Williams3526d802014-03-06 08:59:56 +00001507 i40evf_request_reset(adapter);
1508 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001509 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
Mitch Williams3526d802014-03-06 08:59:56 +00001510
Mitch Williamsef8693e2014-02-13 03:48:53 -08001511 /* poll until we see the reset actually happen */
1512 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001513 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1514 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
Ashish Shahfd358862014-08-01 13:27:11 -07001515 if ((rstat_val != I40E_VFR_VFACTIVE) &&
1516 (rstat_val != I40E_VFR_COMPLETED))
Greg Rose5eae00c2013-12-21 06:12:45 +00001517 break;
Mitch Williams67c818a2015-06-19 08:56:30 -07001518 usleep_range(500, 1000);
Greg Rose5eae00c2013-12-21 06:12:45 +00001519 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001520 if (i == I40EVF_RESET_WAIT_COUNT) {
Mitch Williams67c818a2015-06-19 08:56:30 -07001521 dev_info(&adapter->pdev->dev, "Never saw reset\n");
Mitch Williamsef8693e2014-02-13 03:48:53 -08001522 goto continue_reset; /* act like the reset happened */
1523 }
1524
1525 /* wait until the reset is complete and the PF is responding to us */
1526 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
1527 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1528 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
Mitch Williams67c818a2015-06-19 08:56:30 -07001529 if (rstat_val == I40E_VFR_VFACTIVE)
Mitch Williamsef8693e2014-02-13 03:48:53 -08001530 break;
Mitch Williamsc88e38c2014-11-11 20:03:13 +00001531 msleep(I40EVF_RESET_WAIT_MS);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001532 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001533 /* extra wait to make sure minimum wait is met */
1534 msleep(I40EVF_RESET_WAIT_MS);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001535 if (i == I40EVF_RESET_WAIT_COUNT) {
Mitch Williams6ba36a22014-08-01 13:27:14 -07001536 struct i40evf_mac_filter *f, *ftmp;
1537 struct i40evf_vlan_filter *fv, *fvtmp;
1538
Greg Rose5eae00c2013-12-21 06:12:45 +00001539 /* reset never finished */
Mitch Williams80e72892014-05-10 04:49:06 +00001540 dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n",
Mitch Williamsef8693e2014-02-13 03:48:53 -08001541 rstat_val);
1542 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
1543
Mitch Williams169f4072014-04-01 07:11:50 +00001544 if (netif_running(adapter->netdev)) {
1545 set_bit(__I40E_DOWN, &adapter->vsi.state);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001546 netif_carrier_off(netdev);
Mitch Williams67c818a2015-06-19 08:56:30 -07001547 netif_tx_disable(netdev);
1548 i40evf_napi_disable_all(adapter);
1549 i40evf_irq_disable(adapter);
Mitch Williams169f4072014-04-01 07:11:50 +00001550 i40evf_free_traffic_irqs(adapter);
1551 i40evf_free_all_tx_resources(adapter);
1552 i40evf_free_all_rx_resources(adapter);
1553 }
Mitch Williams6ba36a22014-08-01 13:27:14 -07001554
1555 /* Delete all of the filters, both MAC and VLAN. */
1556 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list,
1557 list) {
1558 list_del(&f->list);
1559 kfree(f);
1560 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001561
Mitch Williams6ba36a22014-08-01 13:27:14 -07001562 list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list,
1563 list) {
1564 list_del(&fv->list);
1565 kfree(fv);
1566 }
1567
Mitch Williamsef8693e2014-02-13 03:48:53 -08001568 i40evf_free_misc_irq(adapter);
1569 i40evf_reset_interrupt_capability(adapter);
1570 i40evf_free_queues(adapter);
Mitch Williamsd31944d2014-08-01 13:27:13 -07001571 i40evf_free_q_vectors(adapter);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001572 kfree(adapter->vf_res);
1573 i40evf_shutdown_adminq(hw);
1574 adapter->netdev->flags &= ~IFF_UP;
1575 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Mitch Williams67c818a2015-06-19 08:56:30 -07001576 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1577 dev_info(&adapter->pdev->dev, "Reset task did not complete, VF disabled\n");
Mitch Williamsef8693e2014-02-13 03:48:53 -08001578 return; /* Do not attempt to reinit. It's dead, Jim. */
Greg Rose5eae00c2013-12-21 06:12:45 +00001579 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001580
1581continue_reset:
Mitch Williams67c818a2015-06-19 08:56:30 -07001582 if (netif_running(adapter->netdev)) {
1583 netif_carrier_off(netdev);
1584 netif_tx_stop_all_queues(netdev);
1585 i40evf_napi_disable_all(adapter);
1586 }
Mitch Williamsac833bb2015-01-29 07:17:19 +00001587 i40evf_irq_disable(adapter);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001588
Greg Rose5eae00c2013-12-21 06:12:45 +00001589 adapter->state = __I40EVF_RESETTING;
Mitch Williams67c818a2015-06-19 08:56:30 -07001590 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1591
1592 /* free the Tx/Rx rings and descriptors, might be better to just
1593 * re-use them sometime in the future
1594 */
1595 i40evf_free_all_rx_resources(adapter);
1596 i40evf_free_all_tx_resources(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001597
1598 /* kill and reinit the admin queue */
1599 if (i40evf_shutdown_adminq(hw))
Mitch Williamsac833bb2015-01-29 07:17:19 +00001600 dev_warn(&adapter->pdev->dev, "Failed to shut down adminq\n");
1601 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001602 err = i40evf_init_adminq(hw);
1603 if (err)
Mitch Williamsac833bb2015-01-29 07:17:19 +00001604 dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n",
1605 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00001606
Greg Rose5eae00c2013-12-21 06:12:45 +00001607 i40evf_map_queues(adapter);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001608
1609 /* re-add all MAC filters */
1610 list_for_each_entry(f, &adapter->mac_filter_list, list) {
1611 f->add = true;
1612 }
1613 /* re-add all VLAN filters */
1614 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
1615 f->add = true;
1616 }
1617 adapter->aq_required = I40EVF_FLAG_AQ_ADD_MAC_FILTER;
1618 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
Greg Rose5eae00c2013-12-21 06:12:45 +00001619 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Mitch Williams67c818a2015-06-19 08:56:30 -07001620 i40evf_misc_irq_enable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001621
1622 mod_timer(&adapter->watchdog_timer, jiffies + 2);
1623
1624 if (netif_running(adapter->netdev)) {
1625 /* allocate transmit descriptors */
1626 err = i40evf_setup_all_tx_resources(adapter);
1627 if (err)
1628 goto reset_err;
1629
1630 /* allocate receive descriptors */
1631 err = i40evf_setup_all_rx_resources(adapter);
1632 if (err)
1633 goto reset_err;
1634
1635 i40evf_configure(adapter);
1636
1637 err = i40evf_up_complete(adapter);
1638 if (err)
1639 goto reset_err;
1640
1641 i40evf_irq_enable(adapter, true);
Mitch Williams67c818a2015-06-19 08:56:30 -07001642 } else {
1643 adapter->state = __I40EVF_DOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001644 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001645
Greg Rose5eae00c2013-12-21 06:12:45 +00001646 return;
1647reset_err:
Mitch Williams80e72892014-05-10 04:49:06 +00001648 dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001649 i40evf_close(adapter->netdev);
1650}
1651
1652/**
1653 * i40evf_adminq_task - worker thread to clean the admin queue
1654 * @work: pointer to work_struct containing our data
1655 **/
1656static void i40evf_adminq_task(struct work_struct *work)
1657{
1658 struct i40evf_adapter *adapter =
1659 container_of(work, struct i40evf_adapter, adminq_task);
1660 struct i40e_hw *hw = &adapter->hw;
1661 struct i40e_arq_event_info event;
1662 struct i40e_virtchnl_msg *v_msg;
1663 i40e_status ret;
Mitch Williams912257e2014-05-22 06:32:07 +00001664 u32 val, oldval;
Greg Rose5eae00c2013-12-21 06:12:45 +00001665 u16 pending;
1666
Mitch Williamsef8693e2014-02-13 03:48:53 -08001667 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
Mitch A Williams72354482014-12-09 08:53:07 +00001668 goto out;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001669
Mitch Williams1001dc32014-11-11 20:02:19 +00001670 event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
1671 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +00001672 if (!event.msg_buf)
Mitch A Williams72354482014-12-09 08:53:07 +00001673 goto out;
Mitch Williams249c8b82014-05-10 04:49:04 +00001674
Greg Rose5eae00c2013-12-21 06:12:45 +00001675 v_msg = (struct i40e_virtchnl_msg *)&event.desc;
1676 do {
1677 ret = i40evf_clean_arq_element(hw, &event, &pending);
Mitch Williams8b011eb2015-01-09 11:18:17 +00001678 if (ret || !v_msg->v_opcode)
Greg Rose5eae00c2013-12-21 06:12:45 +00001679 break; /* No event to process or error cleaning ARQ */
1680
1681 i40evf_virtchnl_completion(adapter, v_msg->v_opcode,
1682 v_msg->v_retval, event.msg_buf,
Mitch Williams1001dc32014-11-11 20:02:19 +00001683 event.msg_len);
Mitch Williams75a64432014-11-11 20:02:42 +00001684 if (pending != 0)
Greg Rose5eae00c2013-12-21 06:12:45 +00001685 memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE);
Greg Rose5eae00c2013-12-21 06:12:45 +00001686 } while (pending);
1687
Mitch Williams67c818a2015-06-19 08:56:30 -07001688 if ((adapter->flags &
1689 (I40EVF_FLAG_RESET_PENDING | I40EVF_FLAG_RESET_NEEDED)) ||
1690 adapter->state == __I40EVF_RESETTING)
1691 goto freedom;
1692
Mitch Williams912257e2014-05-22 06:32:07 +00001693 /* check for error indications */
1694 val = rd32(hw, hw->aq.arq.len);
1695 oldval = val;
1696 if (val & I40E_VF_ARQLEN_ARQVFE_MASK) {
1697 dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n");
1698 val &= ~I40E_VF_ARQLEN_ARQVFE_MASK;
1699 }
1700 if (val & I40E_VF_ARQLEN_ARQOVFL_MASK) {
1701 dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n");
1702 val &= ~I40E_VF_ARQLEN_ARQOVFL_MASK;
1703 }
1704 if (val & I40E_VF_ARQLEN_ARQCRIT_MASK) {
1705 dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n");
1706 val &= ~I40E_VF_ARQLEN_ARQCRIT_MASK;
1707 }
1708 if (oldval != val)
1709 wr32(hw, hw->aq.arq.len, val);
1710
1711 val = rd32(hw, hw->aq.asq.len);
1712 oldval = val;
1713 if (val & I40E_VF_ATQLEN_ATQVFE_MASK) {
1714 dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n");
1715 val &= ~I40E_VF_ATQLEN_ATQVFE_MASK;
1716 }
1717 if (val & I40E_VF_ATQLEN_ATQOVFL_MASK) {
1718 dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n");
1719 val &= ~I40E_VF_ATQLEN_ATQOVFL_MASK;
1720 }
1721 if (val & I40E_VF_ATQLEN_ATQCRIT_MASK) {
1722 dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n");
1723 val &= ~I40E_VF_ATQLEN_ATQCRIT_MASK;
1724 }
1725 if (oldval != val)
1726 wr32(hw, hw->aq.asq.len, val);
1727
Mitch Williams67c818a2015-06-19 08:56:30 -07001728freedom:
Mitch A Williams72354482014-12-09 08:53:07 +00001729 kfree(event.msg_buf);
1730out:
Greg Rose5eae00c2013-12-21 06:12:45 +00001731 /* re-enable Admin queue interrupt cause */
1732 i40evf_misc_irq_enable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001733}
1734
1735/**
1736 * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
1737 * @adapter: board private structure
1738 *
1739 * Free all transmit software resources
1740 **/
Mitch Williamse284fc82015-03-27 00:12:09 -07001741void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter)
Greg Rose5eae00c2013-12-21 06:12:45 +00001742{
1743 int i;
1744
Mitch Williamscc052922014-10-25 03:24:34 +00001745 for (i = 0; i < adapter->num_active_queues; i++)
Greg Rose5eae00c2013-12-21 06:12:45 +00001746 if (adapter->tx_rings[i]->desc)
1747 i40evf_free_tx_resources(adapter->tx_rings[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00001748}
1749
1750/**
1751 * i40evf_setup_all_tx_resources - allocate all queues Tx resources
1752 * @adapter: board private structure
1753 *
1754 * If this function returns with an error, then it's possible one or
1755 * more of the rings is populated (while the rest are not). It is the
1756 * callers duty to clean those orphaned rings.
1757 *
1758 * Return 0 on success, negative on failure
1759 **/
1760static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter)
1761{
1762 int i, err = 0;
1763
Mitch Williamscc052922014-10-25 03:24:34 +00001764 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williamsd732a182014-04-24 06:41:37 +00001765 adapter->tx_rings[i]->count = adapter->tx_desc_count;
Greg Rose5eae00c2013-12-21 06:12:45 +00001766 err = i40evf_setup_tx_descriptors(adapter->tx_rings[i]);
1767 if (!err)
1768 continue;
1769 dev_err(&adapter->pdev->dev,
1770 "%s: Allocation for Tx Queue %u failed\n",
1771 __func__, i);
1772 break;
1773 }
1774
1775 return err;
1776}
1777
1778/**
1779 * i40evf_setup_all_rx_resources - allocate all queues Rx resources
1780 * @adapter: board private structure
1781 *
1782 * If this function returns with an error, then it's possible one or
1783 * more of the rings is populated (while the rest are not). It is the
1784 * callers duty to clean those orphaned rings.
1785 *
1786 * Return 0 on success, negative on failure
1787 **/
1788static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter)
1789{
1790 int i, err = 0;
1791
Mitch Williamscc052922014-10-25 03:24:34 +00001792 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williamsd732a182014-04-24 06:41:37 +00001793 adapter->rx_rings[i]->count = adapter->rx_desc_count;
Greg Rose5eae00c2013-12-21 06:12:45 +00001794 err = i40evf_setup_rx_descriptors(adapter->rx_rings[i]);
1795 if (!err)
1796 continue;
1797 dev_err(&adapter->pdev->dev,
1798 "%s: Allocation for Rx Queue %u failed\n",
1799 __func__, i);
1800 break;
1801 }
1802 return err;
1803}
1804
1805/**
1806 * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
1807 * @adapter: board private structure
1808 *
1809 * Free all receive software resources
1810 **/
Mitch Williamse284fc82015-03-27 00:12:09 -07001811void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter)
Greg Rose5eae00c2013-12-21 06:12:45 +00001812{
1813 int i;
1814
Mitch Williamscc052922014-10-25 03:24:34 +00001815 for (i = 0; i < adapter->num_active_queues; i++)
Greg Rose5eae00c2013-12-21 06:12:45 +00001816 if (adapter->rx_rings[i]->desc)
1817 i40evf_free_rx_resources(adapter->rx_rings[i]);
1818}
1819
1820/**
1821 * i40evf_open - Called when a network interface is made active
1822 * @netdev: network interface device structure
1823 *
1824 * Returns 0 on success, negative value on failure
1825 *
1826 * The open entry point is called when a network interface is made
1827 * active by the system (IFF_UP). At this point all resources needed
1828 * for transmit and receive operations are allocated, the interrupt
1829 * handler is registered with the OS, the watchdog timer is started,
1830 * and the stack is notified that the interface is ready.
1831 **/
1832static int i40evf_open(struct net_device *netdev)
1833{
1834 struct i40evf_adapter *adapter = netdev_priv(netdev);
1835 int err;
1836
Mitch Williamsef8693e2014-02-13 03:48:53 -08001837 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
1838 dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
1839 return -EIO;
1840 }
Mitch Williamse284fc82015-03-27 00:12:09 -07001841 if (adapter->state != __I40EVF_DOWN || adapter->aq_required)
Greg Rose5eae00c2013-12-21 06:12:45 +00001842 return -EBUSY;
1843
1844 /* allocate transmit descriptors */
1845 err = i40evf_setup_all_tx_resources(adapter);
1846 if (err)
1847 goto err_setup_tx;
1848
1849 /* allocate receive descriptors */
1850 err = i40evf_setup_all_rx_resources(adapter);
1851 if (err)
1852 goto err_setup_rx;
1853
1854 /* clear any pending interrupts, may auto mask */
1855 err = i40evf_request_traffic_irqs(adapter, netdev->name);
1856 if (err)
1857 goto err_req_irq;
1858
1859 i40evf_configure(adapter);
1860
1861 err = i40evf_up_complete(adapter);
1862 if (err)
1863 goto err_req_irq;
1864
1865 i40evf_irq_enable(adapter, true);
1866
1867 return 0;
1868
1869err_req_irq:
1870 i40evf_down(adapter);
1871 i40evf_free_traffic_irqs(adapter);
1872err_setup_rx:
1873 i40evf_free_all_rx_resources(adapter);
1874err_setup_tx:
1875 i40evf_free_all_tx_resources(adapter);
1876
1877 return err;
1878}
1879
1880/**
1881 * i40evf_close - Disables a network interface
1882 * @netdev: network interface device structure
1883 *
1884 * Returns 0, this is not allowed to fail
1885 *
1886 * The close entry point is called when an interface is de-activated
1887 * by the OS. The hardware is still under the drivers control, but
1888 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
1889 * are freed, along with all transmit and receive resources.
1890 **/
1891static int i40evf_close(struct net_device *netdev)
1892{
1893 struct i40evf_adapter *adapter = netdev_priv(netdev);
1894
Mitch Williamsef8693e2014-02-13 03:48:53 -08001895 if (adapter->state <= __I40EVF_DOWN)
1896 return 0;
1897
Mitch Williamsef8693e2014-02-13 03:48:53 -08001898
Greg Rose5eae00c2013-12-21 06:12:45 +00001899 set_bit(__I40E_DOWN, &adapter->vsi.state);
1900
1901 i40evf_down(adapter);
Mitch Williamsddf0b3a2014-05-22 06:31:46 +00001902 adapter->state = __I40EVF_DOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001903 i40evf_free_traffic_irqs(adapter);
1904
Greg Rose5eae00c2013-12-21 06:12:45 +00001905 return 0;
1906}
1907
1908/**
1909 * i40evf_get_stats - Get System Network Statistics
1910 * @netdev: network interface device structure
1911 *
1912 * Returns the address of the device statistics structure.
1913 * The statistics are actually updated from the timer callback.
1914 **/
1915static struct net_device_stats *i40evf_get_stats(struct net_device *netdev)
1916{
1917 struct i40evf_adapter *adapter = netdev_priv(netdev);
1918
1919 /* only return the current stats */
1920 return &adapter->net_stats;
1921}
1922
1923/**
Greg Rose5eae00c2013-12-21 06:12:45 +00001924 * i40evf_change_mtu - Change the Maximum Transfer Unit
1925 * @netdev: network interface device structure
1926 * @new_mtu: new value for maximum frame size
1927 *
1928 * Returns 0 on success, negative on failure
1929 **/
1930static int i40evf_change_mtu(struct net_device *netdev, int new_mtu)
1931{
1932 struct i40evf_adapter *adapter = netdev_priv(netdev);
1933 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
1934
1935 if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
1936 return -EINVAL;
1937
Greg Rose5eae00c2013-12-21 06:12:45 +00001938 netdev->mtu = new_mtu;
Mitch Williams67c818a2015-06-19 08:56:30 -07001939 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
1940 schedule_work(&adapter->reset_task);
1941
Greg Rose5eae00c2013-12-21 06:12:45 +00001942 return 0;
1943}
1944
1945static const struct net_device_ops i40evf_netdev_ops = {
1946 .ndo_open = i40evf_open,
1947 .ndo_stop = i40evf_close,
1948 .ndo_start_xmit = i40evf_xmit_frame,
1949 .ndo_get_stats = i40evf_get_stats,
1950 .ndo_set_rx_mode = i40evf_set_rx_mode,
1951 .ndo_validate_addr = eth_validate_addr,
1952 .ndo_set_mac_address = i40evf_set_mac,
1953 .ndo_change_mtu = i40evf_change_mtu,
1954 .ndo_tx_timeout = i40evf_tx_timeout,
1955 .ndo_vlan_rx_add_vid = i40evf_vlan_rx_add_vid,
1956 .ndo_vlan_rx_kill_vid = i40evf_vlan_rx_kill_vid,
1957};
1958
1959/**
1960 * i40evf_check_reset_complete - check that VF reset is complete
1961 * @hw: pointer to hw struct
1962 *
1963 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
1964 **/
1965static int i40evf_check_reset_complete(struct i40e_hw *hw)
1966{
1967 u32 rstat;
1968 int i;
1969
1970 for (i = 0; i < 100; i++) {
Ashish Shahfd358862014-08-01 13:27:11 -07001971 rstat = rd32(hw, I40E_VFGEN_RSTAT) &
1972 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1973 if ((rstat == I40E_VFR_VFACTIVE) ||
1974 (rstat == I40E_VFR_COMPLETED))
Greg Rose5eae00c2013-12-21 06:12:45 +00001975 return 0;
Neerav Parikhf98a2002014-09-13 07:40:44 +00001976 usleep_range(10, 20);
Greg Rose5eae00c2013-12-21 06:12:45 +00001977 }
1978 return -EBUSY;
1979}
1980
1981/**
1982 * i40evf_init_task - worker thread to perform delayed initialization
1983 * @work: pointer to work_struct containing our data
1984 *
1985 * This task completes the work that was begun in probe. Due to the nature
1986 * of VF-PF communications, we may need to wait tens of milliseconds to get
Joe Perchesdbedd442015-03-06 20:49:12 -08001987 * responses back from the PF. Rather than busy-wait in probe and bog down the
Greg Rose5eae00c2013-12-21 06:12:45 +00001988 * whole system, we'll do it in a task so we can sleep.
1989 * This task only runs during driver init. Once we've established
1990 * communications with the PF driver and set up our netdev, the watchdog
1991 * takes over.
1992 **/
1993static void i40evf_init_task(struct work_struct *work)
1994{
1995 struct i40evf_adapter *adapter = container_of(work,
1996 struct i40evf_adapter,
1997 init_task.work);
1998 struct net_device *netdev = adapter->netdev;
1999 struct i40evf_mac_filter *f;
2000 struct i40e_hw *hw = &adapter->hw;
2001 struct pci_dev *pdev = adapter->pdev;
2002 int i, err, bufsz;
2003
2004 switch (adapter->state) {
2005 case __I40EVF_STARTUP:
2006 /* driver loaded, probe complete */
Mitch Williamsef8693e2014-02-13 03:48:53 -08002007 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
2008 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
Greg Rose5eae00c2013-12-21 06:12:45 +00002009 err = i40e_set_mac_type(hw);
2010 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002011 dev_err(&pdev->dev, "Failed to set MAC type (%d)\n",
2012 err);
Mitch Williams2619ef42015-04-07 19:45:30 -04002013 goto err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002014 }
2015 err = i40evf_check_reset_complete(hw);
2016 if (err) {
Mitch Williams0d9c7ea2014-04-23 04:50:00 +00002017 dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n",
Mitch Williams75a64432014-11-11 20:02:42 +00002018 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002019 goto err;
2020 }
2021 hw->aq.num_arq_entries = I40EVF_AQ_LEN;
2022 hw->aq.num_asq_entries = I40EVF_AQ_LEN;
2023 hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2024 hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2025
2026 err = i40evf_init_adminq(hw);
2027 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002028 dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n",
2029 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002030 goto err;
2031 }
2032 err = i40evf_send_api_ver(adapter);
2033 if (err) {
Mitch Williams10bdd672014-03-06 08:59:53 +00002034 dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002035 i40evf_shutdown_adminq(hw);
2036 goto err;
2037 }
2038 adapter->state = __I40EVF_INIT_VERSION_CHECK;
2039 goto restart;
Greg Rose5eae00c2013-12-21 06:12:45 +00002040 case __I40EVF_INIT_VERSION_CHECK:
Mitch Williams10bdd672014-03-06 08:59:53 +00002041 if (!i40evf_asq_done(hw)) {
Mitch Williams80e72892014-05-10 04:49:06 +00002042 dev_err(&pdev->dev, "Admin queue command never completed\n");
Mitch Williams906a6932014-11-13 03:06:12 +00002043 i40evf_shutdown_adminq(hw);
2044 adapter->state = __I40EVF_STARTUP;
Greg Rose5eae00c2013-12-21 06:12:45 +00002045 goto err;
Mitch Williams10bdd672014-03-06 08:59:53 +00002046 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002047
2048 /* aq msg sent, awaiting reply */
2049 err = i40evf_verify_api_ver(adapter);
2050 if (err) {
Mitch A Williamsd4f82fd2014-12-09 08:53:03 +00002051 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
Mitch Williams56f99202014-06-04 04:22:41 +00002052 err = i40evf_send_api_ver(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002053 goto err;
2054 }
2055 err = i40evf_send_vf_config_msg(adapter);
2056 if (err) {
Mitch Williams3f2ab172014-06-04 04:22:40 +00002057 dev_err(&pdev->dev, "Unable to send config request (%d)\n",
Greg Rose5eae00c2013-12-21 06:12:45 +00002058 err);
2059 goto err;
2060 }
2061 adapter->state = __I40EVF_INIT_GET_RESOURCES;
2062 goto restart;
Greg Rose5eae00c2013-12-21 06:12:45 +00002063 case __I40EVF_INIT_GET_RESOURCES:
2064 /* aq msg sent, awaiting reply */
2065 if (!adapter->vf_res) {
2066 bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
2067 (I40E_MAX_VF_VSI *
2068 sizeof(struct i40e_virtchnl_vsi_resource));
2069 adapter->vf_res = kzalloc(bufsz, GFP_KERNEL);
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002070 if (!adapter->vf_res)
Greg Rose5eae00c2013-12-21 06:12:45 +00002071 goto err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002072 }
2073 err = i40evf_get_vf_config(adapter);
Mitch Williams906a6932014-11-13 03:06:12 +00002074 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) {
Mitch Williams906a6932014-11-13 03:06:12 +00002075 err = i40evf_send_vf_config_msg(adapter);
2076 goto err;
2077 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002078 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002079 dev_err(&pdev->dev, "Unable to get VF config (%d)\n",
2080 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002081 goto err_alloc;
2082 }
2083 adapter->state = __I40EVF_INIT_SW;
2084 break;
2085 default:
2086 goto err_alloc;
2087 }
2088 /* got VF config message back from PF, now we can parse it */
2089 for (i = 0; i < adapter->vf_res->num_vsis; i++) {
2090 if (adapter->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
2091 adapter->vsi_res = &adapter->vf_res->vsi_res[i];
2092 }
2093 if (!adapter->vsi_res) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002094 dev_err(&pdev->dev, "No LAN VSI found\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00002095 goto err_alloc;
2096 }
2097
2098 adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED;
2099
Greg Rose5eae00c2013-12-21 06:12:45 +00002100 netdev->netdev_ops = &i40evf_netdev_ops;
2101 i40evf_set_ethtool_ops(netdev);
2102 netdev->watchdog_timeo = 5 * HZ;
Mitch Williamsdbbd8112014-02-20 19:29:08 -08002103 netdev->features |= NETIF_F_HIGHDMA |
2104 NETIF_F_SG |
Greg Rose5eae00c2013-12-21 06:12:45 +00002105 NETIF_F_IP_CSUM |
2106 NETIF_F_SCTP_CSUM |
2107 NETIF_F_IPV6_CSUM |
2108 NETIF_F_TSO |
2109 NETIF_F_TSO6 |
Greg Rose3415e8c2014-01-30 12:40:27 +00002110 NETIF_F_RXCSUM |
Greg Rose5eae00c2013-12-21 06:12:45 +00002111 NETIF_F_GRO;
2112
2113 if (adapter->vf_res->vf_offload_flags
2114 & I40E_VIRTCHNL_VF_OFFLOAD_VLAN) {
2115 netdev->vlan_features = netdev->features;
2116 netdev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2117 NETIF_F_HW_VLAN_CTAG_RX |
2118 NETIF_F_HW_VLAN_CTAG_FILTER;
2119 }
2120
Greg Rose3415e8c2014-01-30 12:40:27 +00002121 /* copy netdev features into list of user selectable features */
2122 netdev->hw_features |= netdev->features;
2123 netdev->hw_features &= ~NETIF_F_RXCSUM;
2124
Greg Rose5eae00c2013-12-21 06:12:45 +00002125 if (!is_valid_ether_addr(adapter->hw.mac.addr)) {
Mitch Williamsb34f90e2014-05-10 04:49:07 +00002126 dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n",
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002127 adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002128 random_ether_addr(adapter->hw.mac.addr);
2129 }
Greg Rose9a173902014-05-22 06:32:02 +00002130 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
2131 ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002132
Greg Rose5eae00c2013-12-21 06:12:45 +00002133 f = kzalloc(sizeof(*f), GFP_ATOMIC);
Mitch Williams348d4992014-11-11 20:02:52 +00002134 if (!f)
Greg Rose5eae00c2013-12-21 06:12:45 +00002135 goto err_sw_init;
2136
Greg Rose9a173902014-05-22 06:32:02 +00002137 ether_addr_copy(f->macaddr, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002138 f->add = true;
2139 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
2140
2141 list_add(&f->list, &adapter->mac_filter_list);
2142
2143 init_timer(&adapter->watchdog_timer);
2144 adapter->watchdog_timer.function = &i40evf_watchdog_timer;
2145 adapter->watchdog_timer.data = (unsigned long)adapter;
2146 mod_timer(&adapter->watchdog_timer, jiffies + 1);
2147
Mitch Williamscc052922014-10-25 03:24:34 +00002148 adapter->num_active_queues = min_t(int,
2149 adapter->vsi_res->num_queue_pairs,
2150 (int)(num_online_cpus()));
Mitch Williamsd732a182014-04-24 06:41:37 +00002151 adapter->tx_desc_count = I40EVF_DEFAULT_TXD;
2152 adapter->rx_desc_count = I40EVF_DEFAULT_RXD;
Greg Rose5eae00c2013-12-21 06:12:45 +00002153 err = i40evf_init_interrupt_scheme(adapter);
2154 if (err)
2155 goto err_sw_init;
2156 i40evf_map_rings_to_vectors(adapter);
2157 i40evf_configure_rss(adapter);
2158 err = i40evf_request_misc_irq(adapter);
2159 if (err)
2160 goto err_sw_init;
2161
2162 netif_carrier_off(netdev);
2163
Greg Rose5eae00c2013-12-21 06:12:45 +00002164 adapter->vsi.id = adapter->vsi_res->vsi_id;
2165 adapter->vsi.seid = adapter->vsi_res->vsi_id; /* dummy */
2166 adapter->vsi.back = adapter;
2167 adapter->vsi.base_vector = 1;
2168 adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK;
Mitch Williamsca99eb92014-04-04 04:43:07 +00002169 adapter->vsi.rx_itr_setting = (I40E_ITR_DYNAMIC |
2170 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
2171 adapter->vsi.tx_itr_setting = (I40E_ITR_DYNAMIC |
2172 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
Greg Rose5eae00c2013-12-21 06:12:45 +00002173 adapter->vsi.netdev = adapter->netdev;
2174
Mitch Williamsef8693e2014-02-13 03:48:53 -08002175 if (!adapter->netdev_registered) {
2176 err = register_netdev(netdev);
2177 if (err)
2178 goto err_register;
2179 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002180
2181 adapter->netdev_registered = true;
2182
2183 netif_tx_stop_all_queues(netdev);
2184
Mitch Williamsb34f90e2014-05-10 04:49:07 +00002185 dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002186 if (netdev->features & NETIF_F_GRO)
2187 dev_info(&pdev->dev, "GRO is enabled\n");
2188
2189 dev_info(&pdev->dev, "%s\n", i40evf_driver_string);
2190 adapter->state = __I40EVF_DOWN;
2191 set_bit(__I40E_DOWN, &adapter->vsi.state);
2192 i40evf_misc_irq_enable(adapter);
2193 return;
2194restart:
2195 schedule_delayed_work(&adapter->init_task,
2196 msecs_to_jiffies(50));
2197 return;
2198
2199err_register:
2200 i40evf_free_misc_irq(adapter);
2201err_sw_init:
2202 i40evf_reset_interrupt_capability(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002203err_alloc:
2204 kfree(adapter->vf_res);
2205 adapter->vf_res = NULL;
2206err:
2207 /* Things went into the weeds, so try again later */
2208 if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) {
Mitch Williams80e72892014-05-10 04:49:06 +00002209 dev_err(&pdev->dev, "Failed to communicate with PF; giving up\n");
Mitch Williamsef8693e2014-02-13 03:48:53 -08002210 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
Greg Rose5eae00c2013-12-21 06:12:45 +00002211 return; /* do not reschedule */
2212 }
2213 schedule_delayed_work(&adapter->init_task, HZ * 3);
Greg Rose5eae00c2013-12-21 06:12:45 +00002214}
2215
2216/**
2217 * i40evf_shutdown - Shutdown the device in preparation for a reboot
2218 * @pdev: pci device structure
2219 **/
2220static void i40evf_shutdown(struct pci_dev *pdev)
2221{
2222 struct net_device *netdev = pci_get_drvdata(pdev);
Mitch Williams00293fd2015-01-09 11:18:18 +00002223 struct i40evf_adapter *adapter = netdev_priv(netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +00002224
2225 netif_device_detach(netdev);
2226
2227 if (netif_running(netdev))
2228 i40evf_close(netdev);
2229
Mitch Williams00293fd2015-01-09 11:18:18 +00002230 /* Prevent the watchdog from running. */
2231 adapter->state = __I40EVF_REMOVE;
2232 adapter->aq_required = 0;
Mitch Williams00293fd2015-01-09 11:18:18 +00002233
Greg Rose5eae00c2013-12-21 06:12:45 +00002234#ifdef CONFIG_PM
2235 pci_save_state(pdev);
2236
2237#endif
2238 pci_disable_device(pdev);
2239}
2240
2241/**
2242 * i40evf_probe - Device Initialization Routine
2243 * @pdev: PCI device information struct
2244 * @ent: entry in i40evf_pci_tbl
2245 *
2246 * Returns 0 on success, negative on failure
2247 *
2248 * i40evf_probe initializes an adapter identified by a pci_dev structure.
2249 * The OS initialization, configuring of the adapter private structure,
2250 * and a hardware reset occur.
2251 **/
2252static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2253{
2254 struct net_device *netdev;
2255 struct i40evf_adapter *adapter = NULL;
2256 struct i40e_hw *hw = NULL;
Mitch Williamsdbbd8112014-02-20 19:29:08 -08002257 int err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002258
2259 err = pci_enable_device(pdev);
2260 if (err)
2261 return err;
2262
Mitch Williams64942942014-02-11 08:26:33 +00002263 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Mitch Williams64942942014-02-11 08:26:33 +00002264 if (err) {
Jean Sacrene3e3bfd2014-03-25 04:30:27 +00002265 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2266 if (err) {
2267 dev_err(&pdev->dev,
2268 "DMA configuration failed: 0x%x\n", err);
2269 goto err_dma;
2270 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002271 }
2272
2273 err = pci_request_regions(pdev, i40evf_driver_name);
2274 if (err) {
2275 dev_err(&pdev->dev,
2276 "pci_request_regions failed 0x%x\n", err);
2277 goto err_pci_reg;
2278 }
2279
2280 pci_enable_pcie_error_reporting(pdev);
2281
2282 pci_set_master(pdev);
2283
2284 netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter),
2285 MAX_TX_QUEUES);
2286 if (!netdev) {
2287 err = -ENOMEM;
2288 goto err_alloc_etherdev;
2289 }
2290
2291 SET_NETDEV_DEV(netdev, &pdev->dev);
2292
2293 pci_set_drvdata(pdev, netdev);
2294 adapter = netdev_priv(netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +00002295
2296 adapter->netdev = netdev;
2297 adapter->pdev = pdev;
2298
2299 hw = &adapter->hw;
2300 hw->back = adapter;
2301
2302 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
2303 adapter->state = __I40EVF_STARTUP;
2304
2305 /* Call save state here because it relies on the adapter struct. */
2306 pci_save_state(pdev);
2307
2308 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2309 pci_resource_len(pdev, 0));
2310 if (!hw->hw_addr) {
2311 err = -EIO;
2312 goto err_ioremap;
2313 }
2314 hw->vendor_id = pdev->vendor;
2315 hw->device_id = pdev->device;
2316 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2317 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2318 hw->subsystem_device_id = pdev->subsystem_device;
2319 hw->bus.device = PCI_SLOT(pdev->devfn);
2320 hw->bus.func = PCI_FUNC(pdev->devfn);
2321
Serey Kong8bb1a542014-08-01 13:27:15 -07002322 INIT_LIST_HEAD(&adapter->mac_filter_list);
2323 INIT_LIST_HEAD(&adapter->vlan_filter_list);
2324
Greg Rose5eae00c2013-12-21 06:12:45 +00002325 INIT_WORK(&adapter->reset_task, i40evf_reset_task);
2326 INIT_WORK(&adapter->adminq_task, i40evf_adminq_task);
2327 INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task);
2328 INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task);
2329 schedule_delayed_work(&adapter->init_task, 10);
2330
2331 return 0;
2332
2333err_ioremap:
2334 free_netdev(netdev);
2335err_alloc_etherdev:
2336 pci_release_regions(pdev);
2337err_pci_reg:
2338err_dma:
2339 pci_disable_device(pdev);
2340 return err;
2341}
2342
2343#ifdef CONFIG_PM
2344/**
2345 * i40evf_suspend - Power management suspend routine
2346 * @pdev: PCI device information struct
2347 * @state: unused
2348 *
2349 * Called when the system (VM) is entering sleep/suspend.
2350 **/
2351static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state)
2352{
2353 struct net_device *netdev = pci_get_drvdata(pdev);
2354 struct i40evf_adapter *adapter = netdev_priv(netdev);
2355 int retval = 0;
2356
2357 netif_device_detach(netdev);
2358
2359 if (netif_running(netdev)) {
2360 rtnl_lock();
2361 i40evf_down(adapter);
2362 rtnl_unlock();
2363 }
2364 i40evf_free_misc_irq(adapter);
2365 i40evf_reset_interrupt_capability(adapter);
2366
2367 retval = pci_save_state(pdev);
2368 if (retval)
2369 return retval;
2370
2371 pci_disable_device(pdev);
2372
2373 return 0;
2374}
2375
2376/**
Joe Perchesdbedd442015-03-06 20:49:12 -08002377 * i40evf_resume - Power management resume routine
Greg Rose5eae00c2013-12-21 06:12:45 +00002378 * @pdev: PCI device information struct
2379 *
2380 * Called when the system (VM) is resumed from sleep/suspend.
2381 **/
2382static int i40evf_resume(struct pci_dev *pdev)
2383{
2384 struct i40evf_adapter *adapter = pci_get_drvdata(pdev);
2385 struct net_device *netdev = adapter->netdev;
2386 u32 err;
2387
2388 pci_set_power_state(pdev, PCI_D0);
2389 pci_restore_state(pdev);
2390 /* pci_restore_state clears dev->state_saved so call
2391 * pci_save_state to restore it.
2392 */
2393 pci_save_state(pdev);
2394
2395 err = pci_enable_device_mem(pdev);
2396 if (err) {
2397 dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n");
2398 return err;
2399 }
2400 pci_set_master(pdev);
2401
2402 rtnl_lock();
2403 err = i40evf_set_interrupt_capability(adapter);
2404 if (err) {
2405 dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n");
2406 return err;
2407 }
2408 err = i40evf_request_misc_irq(adapter);
2409 rtnl_unlock();
2410 if (err) {
2411 dev_err(&pdev->dev, "Cannot get interrupt vector.\n");
2412 return err;
2413 }
2414
2415 schedule_work(&adapter->reset_task);
2416
2417 netif_device_attach(netdev);
2418
2419 return err;
2420}
2421
2422#endif /* CONFIG_PM */
2423/**
2424 * i40evf_remove - Device Removal Routine
2425 * @pdev: PCI device information struct
2426 *
2427 * i40evf_remove is called by the PCI subsystem to alert the driver
2428 * that it should release a PCI device. The could be caused by a
2429 * Hot-Plug event, or because the driver is going to be removed from
2430 * memory.
2431 **/
2432static void i40evf_remove(struct pci_dev *pdev)
2433{
2434 struct net_device *netdev = pci_get_drvdata(pdev);
2435 struct i40evf_adapter *adapter = netdev_priv(netdev);
Mitch Williams6ba36a22014-08-01 13:27:14 -07002436 struct i40evf_mac_filter *f, *ftmp;
Greg Rose5eae00c2013-12-21 06:12:45 +00002437 struct i40e_hw *hw = &adapter->hw;
2438
2439 cancel_delayed_work_sync(&adapter->init_task);
Mitch Williamsef8693e2014-02-13 03:48:53 -08002440 cancel_work_sync(&adapter->reset_task);
Greg Rose5eae00c2013-12-21 06:12:45 +00002441
2442 if (adapter->netdev_registered) {
2443 unregister_netdev(netdev);
2444 adapter->netdev_registered = false;
2445 }
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00002446
Mitch Williamsf4a71882015-01-09 11:18:16 +00002447 /* Shut down all the garbage mashers on the detention level */
Greg Rose5eae00c2013-12-21 06:12:45 +00002448 adapter->state = __I40EVF_REMOVE;
Mitch Williamsf4a71882015-01-09 11:18:16 +00002449 adapter->aq_required = 0;
Mitch Williamsf4a71882015-01-09 11:18:16 +00002450 i40evf_request_reset(adapter);
2451 msleep(20);
2452 /* If the FW isn't responding, kick it once, but only once. */
2453 if (!i40evf_asq_done(hw)) {
2454 i40evf_request_reset(adapter);
2455 msleep(20);
2456 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002457
Mitch Williamsdbb01c82014-02-20 19:29:07 -08002458 if (adapter->msix_entries) {
Greg Rose5eae00c2013-12-21 06:12:45 +00002459 i40evf_misc_irq_disable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002460 i40evf_free_misc_irq(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002461 i40evf_reset_interrupt_capability(adapter);
Mitch Williamsd31944d2014-08-01 13:27:13 -07002462 i40evf_free_q_vectors(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002463 }
2464
Mitch Williamse5d17c32014-06-04 04:22:38 +00002465 if (adapter->watchdog_timer.function)
2466 del_timer_sync(&adapter->watchdog_timer);
2467
Mitch Williamsdbb01c82014-02-20 19:29:07 -08002468 flush_scheduled_work();
2469
Greg Rose5eae00c2013-12-21 06:12:45 +00002470 if (hw->aq.asq.count)
2471 i40evf_shutdown_adminq(hw);
2472
2473 iounmap(hw->hw_addr);
2474 pci_release_regions(pdev);
2475
Mitch Williamse284fc82015-03-27 00:12:09 -07002476 i40evf_free_all_tx_resources(adapter);
2477 i40evf_free_all_rx_resources(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002478 i40evf_free_queues(adapter);
2479 kfree(adapter->vf_res);
Mitch Williams6ba36a22014-08-01 13:27:14 -07002480 /* If we got removed before an up/down sequence, we've got a filter
2481 * hanging out there that we need to get rid of.
2482 */
2483 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
2484 list_del(&f->list);
2485 kfree(f);
2486 }
Mitch A Williams37dfdf32014-12-09 08:53:05 +00002487 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
2488 list_del(&f->list);
2489 kfree(f);
2490 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002491
2492 free_netdev(netdev);
2493
2494 pci_disable_pcie_error_reporting(pdev);
2495
2496 pci_disable_device(pdev);
2497}
2498
2499static struct pci_driver i40evf_driver = {
2500 .name = i40evf_driver_name,
2501 .id_table = i40evf_pci_tbl,
2502 .probe = i40evf_probe,
2503 .remove = i40evf_remove,
2504#ifdef CONFIG_PM
2505 .suspend = i40evf_suspend,
2506 .resume = i40evf_resume,
2507#endif
2508 .shutdown = i40evf_shutdown,
2509};
2510
2511/**
2512 * i40e_init_module - Driver Registration Routine
2513 *
2514 * i40e_init_module is the first routine called when the driver is
2515 * loaded. All it does is register with the PCI subsystem.
2516 **/
2517static int __init i40evf_init_module(void)
2518{
2519 int ret;
Mitch Williams75a64432014-11-11 20:02:42 +00002520
Greg Rose5eae00c2013-12-21 06:12:45 +00002521 pr_info("i40evf: %s - version %s\n", i40evf_driver_string,
Mitch Williams75a64432014-11-11 20:02:42 +00002522 i40evf_driver_version);
Greg Rose5eae00c2013-12-21 06:12:45 +00002523
2524 pr_info("%s\n", i40evf_copyright);
2525
2526 ret = pci_register_driver(&i40evf_driver);
2527 return ret;
2528}
2529
2530module_init(i40evf_init_module);
2531
2532/**
2533 * i40e_exit_module - Driver Exit Cleanup Routine
2534 *
2535 * i40e_exit_module is called just before the driver is removed
2536 * from memory.
2537 **/
2538static void __exit i40evf_exit_module(void)
2539{
2540 pci_unregister_driver(&i40evf_driver);
2541}
2542
2543module_exit(i40evf_exit_module);
2544
2545/* i40evf_main.c */