i40e/i40evf: Fix for UDP/TCP RSS for X722
[deliverable/linux.git] / drivers / net / ethernet / intel / i40evf / i40evf_main.c
CommitLineData
5eae00c5
GR
1/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
5b8eb176 4 * Copyright(c) 2013 - 2015 Intel Corporation.
5eae00c5
GR
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
b831607d
JB
15 * 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 *
5eae00c5
GR
18 * 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[] =
0af56f44 35 "Intel(R) XL710/X710 Virtual Function Network Driver";
5eae00c5 36
69ebe955
MW
37#define DRV_KERN "-k"
38
39#define DRV_VERSION_MAJOR 1
40#define DRV_VERSION_MINOR 4
c9c9f1ba 41#define DRV_VERSION_BUILD 4
69ebe955
MW
42#define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
43 __stringify(DRV_VERSION_MINOR) "." \
44 __stringify(DRV_VERSION_BUILD) \
45 DRV_KERN
5eae00c5
GR
46const char i40evf_driver_version[] = DRV_VERSION;
47static const char i40evf_copyright[] =
bf41846e 48 "Copyright (c) 2013 - 2015 Intel Corporation.";
5eae00c5
GR
49
50/* i40evf_pci_tbl - PCI Device ID Table
51 *
52 * Wildcard entries (PCI_ANY_ID) should come last
53 * Last entry must be all 0s
54 *
55 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
56 * Class, Class Mask, private data (not used) }
57 */
9baa3c34 58static const struct pci_device_id i40evf_pci_tbl[] = {
ab60085e 59 {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF), 0},
87e6c1d7 60 {PCI_VDEVICE(INTEL, I40E_DEV_ID_X722_VF), 0},
5eae00c5
GR
61 /* required last entry */
62 {0, }
63};
64
65MODULE_DEVICE_TABLE(pci, i40evf_pci_tbl);
66
67MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
68MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver");
69MODULE_LICENSE("GPL");
70MODULE_VERSION(DRV_VERSION);
71
72/**
73 * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code
74 * @hw: pointer to the HW structure
75 * @mem: ptr to mem struct to fill out
76 * @size: size of memory requested
77 * @alignment: what to align the allocation to
78 **/
79i40e_status i40evf_allocate_dma_mem_d(struct i40e_hw *hw,
80 struct i40e_dma_mem *mem,
81 u64 size, u32 alignment)
82{
83 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
84
85 if (!mem)
86 return I40E_ERR_PARAM;
87
88 mem->size = ALIGN(size, alignment);
89 mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size,
90 (dma_addr_t *)&mem->pa, GFP_KERNEL);
91 if (mem->va)
92 return 0;
93 else
94 return I40E_ERR_NO_MEMORY;
95}
96
97/**
98 * i40evf_free_dma_mem_d - OS specific memory free for shared code
99 * @hw: pointer to the HW structure
100 * @mem: ptr to mem struct to free
101 **/
102i40e_status i40evf_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
103{
104 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
105
106 if (!mem || !mem->va)
107 return I40E_ERR_PARAM;
108 dma_free_coherent(&adapter->pdev->dev, mem->size,
109 mem->va, (dma_addr_t)mem->pa);
110 return 0;
111}
112
113/**
114 * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code
115 * @hw: pointer to the HW structure
116 * @mem: ptr to mem struct to fill out
117 * @size: size of memory requested
118 **/
119i40e_status i40evf_allocate_virt_mem_d(struct i40e_hw *hw,
120 struct i40e_virt_mem *mem, u32 size)
121{
122 if (!mem)
123 return I40E_ERR_PARAM;
124
125 mem->size = size;
126 mem->va = kzalloc(size, GFP_KERNEL);
127
128 if (mem->va)
129 return 0;
130 else
131 return I40E_ERR_NO_MEMORY;
132}
133
134/**
135 * i40evf_free_virt_mem_d - OS specific memory free for shared code
136 * @hw: pointer to the HW structure
137 * @mem: ptr to mem struct to free
138 **/
139i40e_status i40evf_free_virt_mem_d(struct i40e_hw *hw,
140 struct i40e_virt_mem *mem)
141{
142 if (!mem)
143 return I40E_ERR_PARAM;
144
145 /* it's ok to kfree a NULL pointer */
146 kfree(mem->va);
147
148 return 0;
149}
150
151/**
152 * i40evf_debug_d - OS dependent version of debug printing
153 * @hw: pointer to the HW structure
154 * @mask: debug level mask
155 * @fmt_str: printf-type format description
156 **/
157void i40evf_debug_d(void *hw, u32 mask, char *fmt_str, ...)
158{
159 char buf[512];
160 va_list argptr;
161
162 if (!(mask & ((struct i40e_hw *)hw)->debug_mask))
163 return;
164
165 va_start(argptr, fmt_str);
166 vsnprintf(buf, sizeof(buf), fmt_str, argptr);
167 va_end(argptr);
168
169 /* the debug string is already formatted with a newline */
170 pr_info("%s", buf);
171}
172
173/**
174 * i40evf_tx_timeout - Respond to a Tx Hang
175 * @netdev: network interface device structure
176 **/
177static void i40evf_tx_timeout(struct net_device *netdev)
178{
179 struct i40evf_adapter *adapter = netdev_priv(netdev);
180
181 adapter->tx_timeout_count++;
67c818a1
MW
182 if (!(adapter->flags & (I40EVF_FLAG_RESET_PENDING |
183 I40EVF_FLAG_RESET_NEEDED))) {
3526d800 184 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
625777e3
MW
185 schedule_work(&adapter->reset_task);
186 }
5eae00c5
GR
187}
188
189/**
190 * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC
191 * @adapter: board private structure
192 **/
193static void i40evf_misc_irq_disable(struct i40evf_adapter *adapter)
194{
195 struct i40e_hw *hw = &adapter->hw;
75a64435 196
5eae00c5
GR
197 wr32(hw, I40E_VFINT_DYN_CTL01, 0);
198
199 /* read flush */
200 rd32(hw, I40E_VFGEN_RSTAT);
201
202 synchronize_irq(adapter->msix_entries[0].vector);
203}
204
205/**
206 * i40evf_misc_irq_enable - Enable default interrupt generation settings
207 * @adapter: board private structure
208 **/
209static void i40evf_misc_irq_enable(struct i40evf_adapter *adapter)
210{
211 struct i40e_hw *hw = &adapter->hw;
75a64435 212
5eae00c5
GR
213 wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK |
214 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK);
b1f3366b 215 wr32(hw, I40E_VFINT_ICR0_ENA1, I40E_VFINT_ICR0_ENA1_ADMINQ_MASK);
5eae00c5
GR
216
217 /* read flush */
218 rd32(hw, I40E_VFGEN_RSTAT);
219}
220
221/**
222 * i40evf_irq_disable - Mask off interrupt generation on the NIC
223 * @adapter: board private structure
224 **/
225static void i40evf_irq_disable(struct i40evf_adapter *adapter)
226{
227 int i;
228 struct i40e_hw *hw = &adapter->hw;
229
dbb01c8a
MW
230 if (!adapter->msix_entries)
231 return;
232
5eae00c5
GR
233 for (i = 1; i < adapter->num_msix_vectors; i++) {
234 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), 0);
235 synchronize_irq(adapter->msix_entries[i].vector);
236 }
237 /* read flush */
238 rd32(hw, I40E_VFGEN_RSTAT);
5eae00c5
GR
239}
240
241/**
242 * i40evf_irq_enable_queues - Enable interrupt for specified queues
243 * @adapter: board private structure
244 * @mask: bitmap of queues to enable
245 **/
246void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask)
247{
248 struct i40e_hw *hw = &adapter->hw;
249 int i;
250
251 for (i = 1; i < adapter->num_msix_vectors; i++) {
41a1d04b 252 if (mask & BIT(i - 1)) {
5eae00c5
GR
253 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1),
254 I40E_VFINT_DYN_CTLN1_INTENA_MASK |
97bf75f1 255 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
b1f3366b 256 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK);
5eae00c5
GR
257 }
258 }
259}
260
261/**
262 * i40evf_fire_sw_int - Generate SW interrupt for specified vectors
263 * @adapter: board private structure
264 * @mask: bitmap of vectors to trigger
265 **/
75a64435 266static void i40evf_fire_sw_int(struct i40evf_adapter *adapter, u32 mask)
5eae00c5
GR
267{
268 struct i40e_hw *hw = &adapter->hw;
269 int i;
d82acb35 270 u32 dyn_ctl;
5eae00c5 271
164ec1bf
MW
272 if (mask & 1) {
273 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTL01);
b1f3366b 274 dyn_ctl |= I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK |
97bf75f1 275 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
b1f3366b 276 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK;
164ec1bf
MW
277 wr32(hw, I40E_VFINT_DYN_CTL01, dyn_ctl);
278 }
5eae00c5 279 for (i = 1; i < adapter->num_msix_vectors; i++) {
41a1d04b 280 if (mask & BIT(i)) {
5eae00c5 281 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTLN1(i - 1));
b1f3366b 282 dyn_ctl |= I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK |
97bf75f1 283 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
b1f3366b 284 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK;
5eae00c5
GR
285 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), dyn_ctl);
286 }
287 }
288}
289
290/**
291 * i40evf_irq_enable - Enable default interrupt generation settings
292 * @adapter: board private structure
69c1d70a 293 * @flush: boolean value whether to run rd32()
5eae00c5
GR
294 **/
295void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush)
296{
297 struct i40e_hw *hw = &adapter->hw;
298
164ec1bf 299 i40evf_misc_irq_enable(adapter);
5eae00c5
GR
300 i40evf_irq_enable_queues(adapter, ~0);
301
302 if (flush)
303 rd32(hw, I40E_VFGEN_RSTAT);
304}
305
306/**
307 * i40evf_msix_aq - Interrupt handler for vector 0
308 * @irq: interrupt number
309 * @data: pointer to netdev
310 **/
311static irqreturn_t i40evf_msix_aq(int irq, void *data)
312{
313 struct net_device *netdev = data;
314 struct i40evf_adapter *adapter = netdev_priv(netdev);
315 struct i40e_hw *hw = &adapter->hw;
316 u32 val;
5eae00c5 317
cfbe4dba
JB
318 /* handle non-queue interrupts, these reads clear the registers */
319 val = rd32(hw, I40E_VFINT_ICR01);
320 val = rd32(hw, I40E_VFINT_ICR0_ENA1);
5eae00c5 321
ed17f7e5
JS
322 val = rd32(hw, I40E_VFINT_DYN_CTL01) |
323 I40E_VFINT_DYN_CTL01_CLEARPBA_MASK;
5eae00c5
GR
324 wr32(hw, I40E_VFINT_DYN_CTL01, val);
325
5eae00c5
GR
326 /* schedule work on the private workqueue */
327 schedule_work(&adapter->adminq_task);
328
329 return IRQ_HANDLED;
330}
331
332/**
333 * i40evf_msix_clean_rings - MSIX mode Interrupt Handler
334 * @irq: interrupt number
335 * @data: pointer to a q_vector
336 **/
337static irqreturn_t i40evf_msix_clean_rings(int irq, void *data)
338{
339 struct i40e_q_vector *q_vector = data;
340
341 if (!q_vector->tx.ring && !q_vector->rx.ring)
342 return IRQ_HANDLED;
343
5d3465a1 344 napi_schedule_irqoff(&q_vector->napi);
5eae00c5
GR
345
346 return IRQ_HANDLED;
347}
348
349/**
350 * i40evf_map_vector_to_rxq - associate irqs with rx queues
351 * @adapter: board private structure
352 * @v_idx: interrupt number
353 * @r_idx: queue number
354 **/
355static void
356i40evf_map_vector_to_rxq(struct i40evf_adapter *adapter, int v_idx, int r_idx)
357{
7d96ba1a 358 struct i40e_q_vector *q_vector = &adapter->q_vectors[v_idx];
0dd438d8 359 struct i40e_ring *rx_ring = &adapter->rx_rings[r_idx];
5eae00c5
GR
360
361 rx_ring->q_vector = q_vector;
362 rx_ring->next = q_vector->rx.ring;
363 rx_ring->vsi = &adapter->vsi;
364 q_vector->rx.ring = rx_ring;
365 q_vector->rx.count++;
366 q_vector->rx.latency_range = I40E_LOW_LATENCY;
ee2319cf 367 q_vector->itr_countdown = ITR_COUNTDOWN_START;
5eae00c5
GR
368}
369
370/**
371 * i40evf_map_vector_to_txq - associate irqs with tx queues
372 * @adapter: board private structure
373 * @v_idx: interrupt number
374 * @t_idx: queue number
375 **/
376static void
377i40evf_map_vector_to_txq(struct i40evf_adapter *adapter, int v_idx, int t_idx)
378{
7d96ba1a 379 struct i40e_q_vector *q_vector = &adapter->q_vectors[v_idx];
0dd438d8 380 struct i40e_ring *tx_ring = &adapter->tx_rings[t_idx];
5eae00c5
GR
381
382 tx_ring->q_vector = q_vector;
383 tx_ring->next = q_vector->tx.ring;
384 tx_ring->vsi = &adapter->vsi;
385 q_vector->tx.ring = tx_ring;
386 q_vector->tx.count++;
387 q_vector->tx.latency_range = I40E_LOW_LATENCY;
ee2319cf 388 q_vector->itr_countdown = ITR_COUNTDOWN_START;
5eae00c5 389 q_vector->num_ringpairs++;
41a1d04b 390 q_vector->ring_mask |= BIT(t_idx);
5eae00c5
GR
391}
392
393/**
394 * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors
395 * @adapter: board private structure to initialize
396 *
397 * This function maps descriptor rings to the queue-specific vectors
398 * we were allotted through the MSI-X enabling code. Ideally, we'd have
399 * one vector per ring/queue, but on a constrained vector budget, we
400 * group the rings as "efficiently" as possible. You would add new
401 * mapping configurations in here.
402 **/
403static int i40evf_map_rings_to_vectors(struct i40evf_adapter *adapter)
404{
405 int q_vectors;
406 int v_start = 0;
407 int rxr_idx = 0, txr_idx = 0;
cc052927
MW
408 int rxr_remaining = adapter->num_active_queues;
409 int txr_remaining = adapter->num_active_queues;
5eae00c5
GR
410 int i, j;
411 int rqpv, tqpv;
412 int err = 0;
413
414 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
415
416 /* The ideal configuration...
417 * We have enough vectors to map one per queue.
418 */
973371da 419 if (q_vectors >= (rxr_remaining * 2)) {
5eae00c5
GR
420 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
421 i40evf_map_vector_to_rxq(adapter, v_start, rxr_idx);
422
423 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
424 i40evf_map_vector_to_txq(adapter, v_start, txr_idx);
425 goto out;
426 }
427
428 /* If we don't have enough vectors for a 1-to-1
429 * mapping, we'll have to group them so there are
430 * multiple queues per vector.
431 * Re-adjusting *qpv takes care of the remainder.
432 */
433 for (i = v_start; i < q_vectors; i++) {
434 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
435 for (j = 0; j < rqpv; j++) {
436 i40evf_map_vector_to_rxq(adapter, i, rxr_idx);
437 rxr_idx++;
438 rxr_remaining--;
439 }
440 }
441 for (i = v_start; i < q_vectors; i++) {
442 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
443 for (j = 0; j < tqpv; j++) {
444 i40evf_map_vector_to_txq(adapter, i, txr_idx);
445 txr_idx++;
446 txr_remaining--;
447 }
448 }
449
450out:
451 adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
452
453 return err;
454}
455
7709b4c1
AD
456#ifdef CONFIG_NET_POLL_CONTROLLER
457/**
458 * i40evf_netpoll - A Polling 'interrupt' handler
459 * @netdev: network interface device structure
460 *
461 * This is used by netconsole to send skbs without having to re-enable
462 * interrupts. It's not called while the normal interrupt routine is executing.
463 **/
464static void i40evf_netpoll(struct net_device *netdev)
465{
466 struct i40evf_adapter *adapter = netdev_priv(netdev);
467 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
468 int i;
469
470 /* if interface is down do nothing */
471 if (test_bit(__I40E_DOWN, &adapter->vsi.state))
472 return;
473
474 for (i = 0; i < q_vectors; i++)
7d96ba1a 475 i40evf_msix_clean_rings(0, &adapter->q_vectors[i]);
7709b4c1
AD
476}
477
478#endif
5eae00c5
GR
479/**
480 * i40evf_request_traffic_irqs - Initialize MSI-X interrupts
481 * @adapter: board private structure
482 *
483 * Allocates MSI-X vectors for tx and rx handling, and requests
484 * interrupts from the kernel.
485 **/
486static int
487i40evf_request_traffic_irqs(struct i40evf_adapter *adapter, char *basename)
488{
489 int vector, err, q_vectors;
490 int rx_int_idx = 0, tx_int_idx = 0;
491
492 i40evf_irq_disable(adapter);
493 /* Decrement for Other and TCP Timer vectors */
494 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
495
496 for (vector = 0; vector < q_vectors; vector++) {
7d96ba1a 497 struct i40e_q_vector *q_vector = &adapter->q_vectors[vector];
5eae00c5
GR
498
499 if (q_vector->tx.ring && q_vector->rx.ring) {
500 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
501 "i40evf-%s-%s-%d", basename,
502 "TxRx", rx_int_idx++);
503 tx_int_idx++;
504 } else if (q_vector->rx.ring) {
505 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
506 "i40evf-%s-%s-%d", basename,
507 "rx", rx_int_idx++);
508 } else if (q_vector->tx.ring) {
509 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
510 "i40evf-%s-%s-%d", basename,
511 "tx", tx_int_idx++);
512 } else {
513 /* skip this unused q_vector */
514 continue;
515 }
516 err = request_irq(
517 adapter->msix_entries[vector + NONQ_VECS].vector,
518 i40evf_msix_clean_rings,
519 0,
520 q_vector->name,
521 q_vector);
522 if (err) {
523 dev_info(&adapter->pdev->dev,
fb43201f 524 "Request_irq failed, error: %d\n", err);
5eae00c5
GR
525 goto free_queue_irqs;
526 }
527 /* assign the mask for this irq */
528 irq_set_affinity_hint(
529 adapter->msix_entries[vector + NONQ_VECS].vector,
530 q_vector->affinity_mask);
531 }
532
533 return 0;
534
535free_queue_irqs:
536 while (vector) {
537 vector--;
538 irq_set_affinity_hint(
539 adapter->msix_entries[vector + NONQ_VECS].vector,
540 NULL);
541 free_irq(adapter->msix_entries[vector + NONQ_VECS].vector,
7d96ba1a 542 &adapter->q_vectors[vector]);
5eae00c5
GR
543 }
544 return err;
545}
546
547/**
548 * i40evf_request_misc_irq - Initialize MSI-X interrupts
549 * @adapter: board private structure
550 *
551 * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
552 * vector is only for the admin queue, and stays active even when the netdev
553 * is closed.
554 **/
555static int i40evf_request_misc_irq(struct i40evf_adapter *adapter)
556{
557 struct net_device *netdev = adapter->netdev;
558 int err;
559
b39c1e2c 560 snprintf(adapter->misc_vector_name,
9a21a007
CW
561 sizeof(adapter->misc_vector_name) - 1, "i40evf-%s:mbx",
562 dev_name(&adapter->pdev->dev));
5eae00c5 563 err = request_irq(adapter->msix_entries[0].vector,
e1dfee8e
MW
564 &i40evf_msix_aq, 0,
565 adapter->misc_vector_name, netdev);
5eae00c5
GR
566 if (err) {
567 dev_err(&adapter->pdev->dev,
77fa28be
CS
568 "request_irq for %s failed: %d\n",
569 adapter->misc_vector_name, err);
5eae00c5
GR
570 free_irq(adapter->msix_entries[0].vector, netdev);
571 }
572 return err;
573}
574
575/**
576 * i40evf_free_traffic_irqs - Free MSI-X interrupts
577 * @adapter: board private structure
578 *
579 * Frees all MSI-X vectors other than 0.
580 **/
581static void i40evf_free_traffic_irqs(struct i40evf_adapter *adapter)
582{
583 int i;
584 int q_vectors;
75a64435 585
5eae00c5
GR
586 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
587
588 for (i = 0; i < q_vectors; i++) {
589 irq_set_affinity_hint(adapter->msix_entries[i+1].vector,
590 NULL);
591 free_irq(adapter->msix_entries[i+1].vector,
7d96ba1a 592 &adapter->q_vectors[i]);
5eae00c5
GR
593 }
594}
595
596/**
597 * i40evf_free_misc_irq - Free MSI-X miscellaneous vector
598 * @adapter: board private structure
599 *
600 * Frees MSI-X vector 0.
601 **/
602static void i40evf_free_misc_irq(struct i40evf_adapter *adapter)
603{
604 struct net_device *netdev = adapter->netdev;
605
606 free_irq(adapter->msix_entries[0].vector, netdev);
607}
608
609/**
610 * i40evf_configure_tx - Configure Transmit Unit after Reset
611 * @adapter: board private structure
612 *
613 * Configure the Tx unit of the MAC after a reset.
614 **/
615static void i40evf_configure_tx(struct i40evf_adapter *adapter)
616{
617 struct i40e_hw *hw = &adapter->hw;
618 int i;
75a64435 619
cc052927 620 for (i = 0; i < adapter->num_active_queues; i++)
0dd438d8 621 adapter->tx_rings[i].tail = hw->hw_addr + I40E_QTX_TAIL1(i);
5eae00c5
GR
622}
623
624/**
625 * i40evf_configure_rx - Configure Receive Unit after Reset
626 * @adapter: board private structure
627 *
628 * Configure the Rx unit of the MAC after a reset.
629 **/
630static void i40evf_configure_rx(struct i40evf_adapter *adapter)
631{
632 struct i40e_hw *hw = &adapter->hw;
633 struct net_device *netdev = adapter->netdev;
634 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
635 int i;
636 int rx_buf_len;
637
638
639 adapter->flags &= ~I40EVF_FLAG_RX_PS_CAPABLE;
640 adapter->flags |= I40EVF_FLAG_RX_1BUF_CAPABLE;
641
642 /* Decide whether to use packet split mode or not */
643 if (netdev->mtu > ETH_DATA_LEN) {
644 if (adapter->flags & I40EVF_FLAG_RX_PS_CAPABLE)
645 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
646 else
647 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
648 } else {
649 if (adapter->flags & I40EVF_FLAG_RX_1BUF_CAPABLE)
650 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
651 else
652 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
653 }
654
655 /* Set the RX buffer length according to the mode */
656 if (adapter->flags & I40EVF_FLAG_RX_PS_ENABLED) {
657 rx_buf_len = I40E_RX_HDR_SIZE;
658 } else {
659 if (netdev->mtu <= ETH_DATA_LEN)
660 rx_buf_len = I40EVF_RXBUFFER_2048;
661 else
662 rx_buf_len = ALIGN(max_frame, 1024);
663 }
664
cc052927 665 for (i = 0; i < adapter->num_active_queues; i++) {
0dd438d8
MW
666 adapter->rx_rings[i].tail = hw->hw_addr + I40E_QRX_TAIL1(i);
667 adapter->rx_rings[i].rx_buf_len = rx_buf_len;
5eae00c5
GR
668 }
669}
670
671/**
672 * i40evf_find_vlan - Search filter list for specific vlan filter
673 * @adapter: board private structure
674 * @vlan: vlan tag
675 *
676 * Returns ptr to the filter object or NULL
677 **/
678static struct
679i40evf_vlan_filter *i40evf_find_vlan(struct i40evf_adapter *adapter, u16 vlan)
680{
681 struct i40evf_vlan_filter *f;
682
683 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
684 if (vlan == f->vlan)
685 return f;
686 }
687 return NULL;
688}
689
690/**
691 * i40evf_add_vlan - Add a vlan filter to the list
692 * @adapter: board private structure
693 * @vlan: VLAN tag
694 *
695 * Returns ptr to the filter object or NULL when no memory available.
696 **/
697static struct
698i40evf_vlan_filter *i40evf_add_vlan(struct i40evf_adapter *adapter, u16 vlan)
699{
13acb546
MW
700 struct i40evf_vlan_filter *f = NULL;
701 int count = 50;
702
703 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
704 &adapter->crit_section)) {
705 udelay(1);
706 if (--count == 0)
707 goto out;
708 }
5eae00c5
GR
709
710 f = i40evf_find_vlan(adapter, vlan);
348d4994 711 if (!f) {
5eae00c5 712 f = kzalloc(sizeof(*f), GFP_ATOMIC);
348d4994 713 if (!f)
13acb546 714 goto clearout;
249c8b8d 715
5eae00c5
GR
716 f->vlan = vlan;
717
718 INIT_LIST_HEAD(&f->list);
719 list_add(&f->list, &adapter->vlan_filter_list);
720 f->add = true;
721 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
722 }
723
13acb546
MW
724clearout:
725 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
726out:
5eae00c5
GR
727 return f;
728}
729
730/**
731 * i40evf_del_vlan - Remove a vlan filter from the list
732 * @adapter: board private structure
733 * @vlan: VLAN tag
734 **/
735static void i40evf_del_vlan(struct i40evf_adapter *adapter, u16 vlan)
736{
737 struct i40evf_vlan_filter *f;
13acb546
MW
738 int count = 50;
739
740 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
741 &adapter->crit_section)) {
742 udelay(1);
743 if (--count == 0)
744 return;
745 }
5eae00c5
GR
746
747 f = i40evf_find_vlan(adapter, vlan);
748 if (f) {
749 f->remove = true;
750 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
751 }
13acb546 752 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
5eae00c5
GR
753}
754
755/**
756 * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device
757 * @netdev: network device struct
758 * @vid: VLAN tag
759 **/
760static int i40evf_vlan_rx_add_vid(struct net_device *netdev,
75a64435 761 __always_unused __be16 proto, u16 vid)
5eae00c5
GR
762{
763 struct i40evf_adapter *adapter = netdev_priv(netdev);
764
8ed995ff
MW
765 if (!VLAN_ALLOWED(adapter))
766 return -EIO;
5eae00c5
GR
767 if (i40evf_add_vlan(adapter, vid) == NULL)
768 return -ENOMEM;
769 return 0;
770}
771
772/**
773 * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device
774 * @netdev: network device struct
775 * @vid: VLAN tag
776 **/
777static int i40evf_vlan_rx_kill_vid(struct net_device *netdev,
75a64435 778 __always_unused __be16 proto, u16 vid)
5eae00c5
GR
779{
780 struct i40evf_adapter *adapter = netdev_priv(netdev);
781
8ed995ff
MW
782 if (VLAN_ALLOWED(adapter)) {
783 i40evf_del_vlan(adapter, vid);
784 return 0;
785 }
786 return -EIO;
5eae00c5
GR
787}
788
789/**
790 * i40evf_find_filter - Search filter list for specific mac filter
791 * @adapter: board private structure
792 * @macaddr: the MAC address
793 *
794 * Returns ptr to the filter object or NULL
795 **/
796static struct
797i40evf_mac_filter *i40evf_find_filter(struct i40evf_adapter *adapter,
798 u8 *macaddr)
799{
800 struct i40evf_mac_filter *f;
801
802 if (!macaddr)
803 return NULL;
804
805 list_for_each_entry(f, &adapter->mac_filter_list, list) {
806 if (ether_addr_equal(macaddr, f->macaddr))
807 return f;
808 }
809 return NULL;
810}
811
812/**
813 * i40e_add_filter - Add a mac filter to the filter list
814 * @adapter: board private structure
815 * @macaddr: the MAC address
816 *
817 * Returns ptr to the filter object or NULL when no memory available.
818 **/
819static struct
820i40evf_mac_filter *i40evf_add_filter(struct i40evf_adapter *adapter,
821 u8 *macaddr)
822{
823 struct i40evf_mac_filter *f;
54e16f64 824 int count = 50;
5eae00c5
GR
825
826 if (!macaddr)
827 return NULL;
828
829 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
54e16f64 830 &adapter->crit_section)) {
b65476cd 831 udelay(1);
54e16f64
MW
832 if (--count == 0)
833 return NULL;
834 }
5eae00c5
GR
835
836 f = i40evf_find_filter(adapter, macaddr);
348d4994 837 if (!f) {
5eae00c5 838 f = kzalloc(sizeof(*f), GFP_ATOMIC);
348d4994 839 if (!f) {
5eae00c5
GR
840 clear_bit(__I40EVF_IN_CRITICAL_TASK,
841 &adapter->crit_section);
842 return NULL;
843 }
844
9a173901 845 ether_addr_copy(f->macaddr, macaddr);
5eae00c5
GR
846
847 list_add(&f->list, &adapter->mac_filter_list);
848 f->add = true;
849 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
850 }
851
852 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
853 return f;
854}
855
856/**
857 * i40evf_set_mac - NDO callback to set port mac address
858 * @netdev: network interface device structure
859 * @p: pointer to an address structure
860 *
861 * Returns 0 on success, negative on failure
862 **/
863static int i40evf_set_mac(struct net_device *netdev, void *p)
864{
865 struct i40evf_adapter *adapter = netdev_priv(netdev);
866 struct i40e_hw *hw = &adapter->hw;
867 struct i40evf_mac_filter *f;
868 struct sockaddr *addr = p;
869
870 if (!is_valid_ether_addr(addr->sa_data))
871 return -EADDRNOTAVAIL;
872
873 if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
874 return 0;
875
14e52ee2
MW
876 if (adapter->flags & I40EVF_FLAG_ADDR_SET_BY_PF)
877 return -EPERM;
878
879 f = i40evf_find_filter(adapter, hw->mac.addr);
880 if (f) {
881 f->remove = true;
882 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
883 }
884
5eae00c5
GR
885 f = i40evf_add_filter(adapter, addr->sa_data);
886 if (f) {
9a173901
GR
887 ether_addr_copy(hw->mac.addr, addr->sa_data);
888 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
5eae00c5
GR
889 }
890
891 return (f == NULL) ? -ENOMEM : 0;
892}
893
894/**
895 * i40evf_set_rx_mode - NDO callback to set the netdev filters
896 * @netdev: network interface device structure
897 **/
898static void i40evf_set_rx_mode(struct net_device *netdev)
899{
900 struct i40evf_adapter *adapter = netdev_priv(netdev);
901 struct i40evf_mac_filter *f, *ftmp;
902 struct netdev_hw_addr *uca;
903 struct netdev_hw_addr *mca;
2f41f335 904 struct netdev_hw_addr *ha;
54e16f64 905 int count = 50;
5eae00c5
GR
906
907 /* add addr if not already in the filter list */
908 netdev_for_each_uc_addr(uca, netdev) {
909 i40evf_add_filter(adapter, uca->addr);
910 }
911 netdev_for_each_mc_addr(mca, netdev) {
912 i40evf_add_filter(adapter, mca->addr);
913 }
914
915 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
54e16f64 916 &adapter->crit_section)) {
b65476cd 917 udelay(1);
54e16f64
MW
918 if (--count == 0) {
919 dev_err(&adapter->pdev->dev,
920 "Failed to get lock in %s\n", __func__);
921 return;
922 }
923 }
5eae00c5
GR
924 /* remove filter if not in netdev list */
925 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
2f41f335
SN
926 netdev_for_each_mc_addr(mca, netdev)
927 if (ether_addr_equal(mca->addr, f->macaddr))
928 goto bottom_of_search_loop;
929
930 netdev_for_each_uc_addr(uca, netdev)
931 if (ether_addr_equal(uca->addr, f->macaddr))
932 goto bottom_of_search_loop;
933
934 for_each_dev_addr(netdev, ha)
935 if (ether_addr_equal(ha->addr, f->macaddr))
936 goto bottom_of_search_loop;
937
938 if (ether_addr_equal(f->macaddr, adapter->hw.mac.addr))
939 goto bottom_of_search_loop;
940
941 /* f->macaddr wasn't found in uc, mc, or ha list so delete it */
942 f->remove = true;
943 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
944
945bottom_of_search_loop:
946 continue;
5eae00c5
GR
947 }
948 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
949}
950
951/**
952 * i40evf_napi_enable_all - enable NAPI on all queue vectors
953 * @adapter: board private structure
954 **/
955static void i40evf_napi_enable_all(struct i40evf_adapter *adapter)
956{
957 int q_idx;
958 struct i40e_q_vector *q_vector;
959 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
960
961 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
962 struct napi_struct *napi;
75a64435 963
7d96ba1a 964 q_vector = &adapter->q_vectors[q_idx];
5eae00c5
GR
965 napi = &q_vector->napi;
966 napi_enable(napi);
967 }
968}
969
970/**
971 * i40evf_napi_disable_all - disable NAPI on all queue vectors
972 * @adapter: board private structure
973 **/
974static void i40evf_napi_disable_all(struct i40evf_adapter *adapter)
975{
976 int q_idx;
977 struct i40e_q_vector *q_vector;
978 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
979
980 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
7d96ba1a 981 q_vector = &adapter->q_vectors[q_idx];
5eae00c5
GR
982 napi_disable(&q_vector->napi);
983 }
984}
985
986/**
987 * i40evf_configure - set up transmit and receive data structures
988 * @adapter: board private structure
989 **/
990static void i40evf_configure(struct i40evf_adapter *adapter)
991{
992 struct net_device *netdev = adapter->netdev;
993 int i;
994
995 i40evf_set_rx_mode(netdev);
996
997 i40evf_configure_tx(adapter);
998 i40evf_configure_rx(adapter);
999 adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
1000
cc052927 1001 for (i = 0; i < adapter->num_active_queues; i++) {
0dd438d8 1002 struct i40e_ring *ring = &adapter->rx_rings[i];
75a64435 1003
a132af24 1004 i40evf_alloc_rx_buffers_1buf(ring, ring->count);
5eae00c5
GR
1005 ring->next_to_use = ring->count - 1;
1006 writel(ring->next_to_use, ring->tail);
1007 }
1008}
1009
1010/**
1011 * i40evf_up_complete - Finish the last steps of bringing up a connection
1012 * @adapter: board private structure
1013 **/
1014static int i40evf_up_complete(struct i40evf_adapter *adapter)
1015{
1016 adapter->state = __I40EVF_RUNNING;
1017 clear_bit(__I40E_DOWN, &adapter->vsi.state);
1018
1019 i40evf_napi_enable_all(adapter);
1020
1021 adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
1022 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
1023 return 0;
1024}
1025
5eae00c5
GR
1026/**
1027 * i40e_down - Shutdown the connection processing
1028 * @adapter: board private structure
1029 **/
1030void i40evf_down(struct i40evf_adapter *adapter)
1031{
1032 struct net_device *netdev = adapter->netdev;
1033 struct i40evf_mac_filter *f;
1034
209dc4da 1035 if (adapter->state <= __I40EVF_DOWN_PENDING)
ddf0b3a6
MW
1036 return;
1037
53d0b3ae
MW
1038 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
1039 &adapter->crit_section))
1040 usleep_range(500, 1000);
1041
63e18c25
MW
1042 netif_carrier_off(netdev);
1043 netif_tx_disable(netdev);
748c434b 1044 i40evf_napi_disable_all(adapter);
63e18c25 1045 i40evf_irq_disable(adapter);
53d0b3ae 1046
ef8693eb 1047 /* remove all MAC filters */
5eae00c5
GR
1048 list_for_each_entry(f, &adapter->mac_filter_list, list) {
1049 f->remove = true;
1050 }
ed1f5b58
MW
1051 /* remove all VLAN filters */
1052 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
1053 f->remove = true;
1054 }
ef8693eb
MW
1055 if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) &&
1056 adapter->state != __I40EVF_RESETTING) {
53d0b3ae
MW
1057 /* cancel any current operation */
1058 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
53d0b3ae
MW
1059 /* Schedule operations to close down the HW. Don't wait
1060 * here for this to complete. The watchdog is still running
1061 * and it will take care of this.
1062 */
1063 adapter->aq_required = I40EVF_FLAG_AQ_DEL_MAC_FILTER;
ed1f5b58 1064 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
ef8693eb 1065 adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
ef8693eb 1066 }
5eae00c5 1067
53d0b3ae 1068 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
5eae00c5
GR
1069}
1070
1071/**
1072 * i40evf_acquire_msix_vectors - Setup the MSIX capability
1073 * @adapter: board private structure
1074 * @vectors: number of vectors to request
1075 *
1076 * Work with the OS to set up the MSIX vectors needed.
1077 *
1078 * Returns 0 on success, negative on failure
1079 **/
1080static int
1081i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors)
1082{
1083 int err, vector_threshold;
1084
1085 /* We'll want at least 3 (vector_threshold):
1086 * 0) Other (Admin Queue and link, mostly)
1087 * 1) TxQ[0] Cleanup
1088 * 2) RxQ[0] Cleanup
1089 */
1090 vector_threshold = MIN_MSIX_COUNT;
1091
1092 /* The more we get, the more we will assign to Tx/Rx Cleanup
1093 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1094 * Right now, we simply care about how many we'll get; we'll
1095 * set them up later while requesting irq's.
1096 */
fc2f2f5d
AG
1097 err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
1098 vector_threshold, vectors);
1099 if (err < 0) {
80e72893 1100 dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n");
5eae00c5
GR
1101 kfree(adapter->msix_entries);
1102 adapter->msix_entries = NULL;
fc2f2f5d 1103 return err;
5eae00c5 1104 }
fc2f2f5d
AG
1105
1106 /* Adjust for only the vectors we'll use, which is minimum
1107 * of max_msix_q_vectors + NONQ_VECS, or the number of
1108 * vectors we were allocated.
1109 */
1110 adapter->num_msix_vectors = err;
1111 return 0;
5eae00c5
GR
1112}
1113
1114/**
1115 * i40evf_free_queues - Free memory for all rings
1116 * @adapter: board private structure to initialize
1117 *
1118 * Free all of the memory associated with queue pairs.
1119 **/
1120static void i40evf_free_queues(struct i40evf_adapter *adapter)
1121{
5eae00c5
GR
1122 if (!adapter->vsi_res)
1123 return;
0dd438d8 1124 kfree(adapter->tx_rings);
10311540 1125 adapter->tx_rings = NULL;
0dd438d8 1126 kfree(adapter->rx_rings);
10311540 1127 adapter->rx_rings = NULL;
5eae00c5
GR
1128}
1129
1130/**
1131 * i40evf_alloc_queues - Allocate memory for all rings
1132 * @adapter: board private structure to initialize
1133 *
1134 * We allocate one ring per queue at run-time since we don't know the
1135 * number of queues at compile-time. The polling_netdev array is
1136 * intended for Multiqueue, but should work fine with a single queue.
1137 **/
1138static int i40evf_alloc_queues(struct i40evf_adapter *adapter)
1139{
1140 int i;
1141
0dd438d8
MW
1142 adapter->tx_rings = kcalloc(adapter->num_active_queues,
1143 sizeof(struct i40e_ring), GFP_KERNEL);
1144 if (!adapter->tx_rings)
1145 goto err_out;
1146 adapter->rx_rings = kcalloc(adapter->num_active_queues,
1147 sizeof(struct i40e_ring), GFP_KERNEL);
1148 if (!adapter->rx_rings)
1149 goto err_out;
1150
cc052927 1151 for (i = 0; i < adapter->num_active_queues; i++) {
5eae00c5
GR
1152 struct i40e_ring *tx_ring;
1153 struct i40e_ring *rx_ring;
1154
0dd438d8 1155 tx_ring = &adapter->tx_rings[i];
5eae00c5
GR
1156
1157 tx_ring->queue_index = i;
1158 tx_ring->netdev = adapter->netdev;
1159 tx_ring->dev = &adapter->pdev->dev;
d732a184 1160 tx_ring->count = adapter->tx_desc_count;
1f012279
ASJ
1161 if (adapter->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
1162 tx_ring->flags |= I40E_TXR_FLAGS_WB_ON_ITR;
5eae00c5 1163
0dd438d8 1164 rx_ring = &adapter->rx_rings[i];
5eae00c5
GR
1165 rx_ring->queue_index = i;
1166 rx_ring->netdev = adapter->netdev;
1167 rx_ring->dev = &adapter->pdev->dev;
d732a184 1168 rx_ring->count = adapter->rx_desc_count;
5eae00c5
GR
1169 }
1170
1171 return 0;
1172
1173err_out:
1174 i40evf_free_queues(adapter);
1175 return -ENOMEM;
1176}
1177
1178/**
1179 * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
1180 * @adapter: board private structure to initialize
1181 *
1182 * Attempt to configure the interrupts using the best available
1183 * capabilities of the hardware and the kernel.
1184 **/
1185static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter)
1186{
1187 int vector, v_budget;
1188 int pairs = 0;
1189 int err = 0;
1190
1191 if (!adapter->vsi_res) {
1192 err = -EIO;
1193 goto out;
1194 }
cc052927 1195 pairs = adapter->num_active_queues;
5eae00c5
GR
1196
1197 /* It's easy to be greedy for MSI-X vectors, but it really
1198 * doesn't do us much good if we have a lot more vectors
1199 * than CPU's. So let's be conservative and only ask for
1200 * (roughly) twice the number of vectors as there are CPU's.
1201 */
30a500e2
MW
1202 v_budget = min_t(int, pairs, (int)(num_online_cpus() * 2)) + NONQ_VECS;
1203 v_budget = min_t(int, v_budget, (int)adapter->vf_res->max_vectors);
5eae00c5 1204
5eae00c5
GR
1205 adapter->msix_entries = kcalloc(v_budget,
1206 sizeof(struct msix_entry), GFP_KERNEL);
1207 if (!adapter->msix_entries) {
1208 err = -ENOMEM;
1209 goto out;
1210 }
1211
1212 for (vector = 0; vector < v_budget; vector++)
1213 adapter->msix_entries[vector].entry = vector;
1214
313ed2d5 1215 err = i40evf_acquire_msix_vectors(adapter, v_budget);
5eae00c5
GR
1216
1217out:
e6c4cf6f
MW
1218 netif_set_real_num_rx_queues(adapter->netdev, pairs);
1219 netif_set_real_num_tx_queues(adapter->netdev, pairs);
5eae00c5
GR
1220 return err;
1221}
1222
e25d00b8 1223/**
2c86ac3c 1224 * i40e_config_rss_aq - Prepare for RSS using AQ commands
e25d00b8
ASJ
1225 * @vsi: vsi structure
1226 * @seed: RSS hash seed
2c86ac3c
HZ
1227 * @lut: Lookup table
1228 * @lut_size: Lookup table size
1229 *
1230 * Return 0 on success, negative on failure
e25d00b8 1231 **/
2c86ac3c
HZ
1232static int i40evf_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
1233 u8 *lut, u16 lut_size)
e25d00b8 1234{
e25d00b8
ASJ
1235 struct i40evf_adapter *adapter = vsi->back;
1236 struct i40e_hw *hw = &adapter->hw;
2c86ac3c 1237 int ret = 0;
e25d00b8
ASJ
1238
1239 if (!vsi->id)
2c86ac3c 1240 return -EINVAL;
e25d00b8
ASJ
1241
1242 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
1243 /* bail because we already have a command pending */
e3d132d1 1244 dev_err(&adapter->pdev->dev, "Cannot configure RSS, command %d pending\n",
e25d00b8 1245 adapter->current_op);
2c86ac3c 1246 return -EBUSY;
e25d00b8
ASJ
1247 }
1248
2c86ac3c
HZ
1249 if (seed) {
1250 struct i40e_aqc_get_set_rss_key_data *rss_key =
1251 (struct i40e_aqc_get_set_rss_key_data *)seed;
1252 ret = i40evf_aq_set_rss_key(hw, vsi->id, rss_key);
1253 if (ret) {
1254 dev_err(&adapter->pdev->dev, "Cannot set RSS key, err %s aq_err %s\n",
1255 i40evf_stat_str(hw, ret),
1256 i40evf_aq_str(hw, hw->aq.asq_last_status));
1257 return ret;
1258 }
1259 }
e25d00b8 1260
2c86ac3c
HZ
1261 if (lut) {
1262 ret = i40evf_aq_set_rss_lut(hw, vsi->id, false, lut, lut_size);
1263 if (ret) {
1264 dev_err(&adapter->pdev->dev,
1265 "Cannot set RSS lut, err %s aq_err %s\n",
1266 i40evf_stat_str(hw, ret),
1267 i40evf_aq_str(hw, hw->aq.asq_last_status));
1268 return ret;
1269 }
e25d00b8
ASJ
1270 }
1271
2c86ac3c 1272 return ret;
e25d00b8
ASJ
1273}
1274
1275/**
2c86ac3c
HZ
1276 * i40evf_config_rss_reg - Configure RSS keys and lut by writing registers
1277 * @vsi: Pointer to vsi structure
e25d00b8 1278 * @seed: RSS hash seed
2c86ac3c
HZ
1279 * @lut: Lookup table
1280 * @lut_size: Lookup table size
1281 *
1282 * Returns 0 on success, negative on failure
e25d00b8 1283 **/
2c86ac3c
HZ
1284static int i40evf_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
1285 const u8 *lut, u16 lut_size)
e25d00b8 1286{
2c86ac3c 1287 struct i40evf_adapter *adapter = vsi->back;
e25d00b8 1288 struct i40e_hw *hw = &adapter->hw;
2c86ac3c 1289 u16 i;
e25d00b8 1290
2c86ac3c
HZ
1291 if (seed) {
1292 u32 *seed_dw = (u32 *)seed;
1293
1294 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
1295 wr32(hw, I40E_VFQF_HKEY(i), seed_dw[i]);
1296 }
1297
1298 if (lut) {
1299 u32 *lut_dw = (u32 *)lut;
1300
1301 if (lut_size != I40EVF_HLUT_ARRAY_SIZE)
1302 return -EINVAL;
1303
1304 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
1305 wr32(hw, I40E_VFQF_HLUT(i), lut_dw[i]);
e25d00b8
ASJ
1306 }
1307 i40e_flush(hw);
2c86ac3c
HZ
1308
1309 return 0;
1310}
1311
90b02b43
HZ
1312/**
1313 * * i40evf_get_rss_aq - Get RSS keys and lut by using AQ commands
1314 * @vsi: Pointer to vsi structure
1315 * @seed: RSS hash seed
1316 * @lut: Lookup table
1317 * @lut_size: Lookup table size
1318 *
1319 * Return 0 on success, negative on failure
1320 **/
1321static int i40evf_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
1322 u8 *lut, u16 lut_size)
1323{
1324 struct i40evf_adapter *adapter = vsi->back;
1325 struct i40e_hw *hw = &adapter->hw;
1326 int ret = 0;
1327
1328 if (seed) {
1329 ret = i40evf_aq_get_rss_key(hw, vsi->id,
1330 (struct i40e_aqc_get_set_rss_key_data *)seed);
1331 if (ret) {
1332 dev_err(&adapter->pdev->dev,
1333 "Cannot get RSS key, err %s aq_err %s\n",
1334 i40evf_stat_str(hw, ret),
1335 i40evf_aq_str(hw, hw->aq.asq_last_status));
1336 return ret;
1337 }
1338 }
1339
1340 if (lut) {
1341 ret = i40evf_aq_get_rss_lut(hw, vsi->id, seed, lut, lut_size);
1342 if (ret) {
1343 dev_err(&adapter->pdev->dev,
1344 "Cannot get RSS lut, err %s aq_err %s\n",
1345 i40evf_stat_str(hw, ret),
1346 i40evf_aq_str(hw, hw->aq.asq_last_status));
1347 return ret;
1348 }
1349 }
1350
1351 return ret;
1352}
1353
1354/**
1355 * * i40evf_get_rss_reg - Get RSS keys and lut by reading registers
1356 * @vsi: Pointer to vsi structure
1357 * @seed: RSS hash seed
1358 * @lut: Lookup table
1359 * @lut_size: Lookup table size
1360 *
1361 * Returns 0 on success, negative on failure
1362 **/
1363static int i40evf_get_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
1364 const u8 *lut, u16 lut_size)
1365{
1366 struct i40evf_adapter *adapter = vsi->back;
1367 struct i40e_hw *hw = &adapter->hw;
1368 u16 i;
1369
1370 if (seed) {
1371 u32 *seed_dw = (u32 *)seed;
1372
1373 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
1374 seed_dw[i] = rd32(hw, I40E_VFQF_HKEY(i));
1375 }
1376
1377 if (lut) {
1378 u32 *lut_dw = (u32 *)lut;
1379
1380 if (lut_size != I40EVF_HLUT_ARRAY_SIZE)
1381 return -EINVAL;
1382
1383 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
1384 lut_dw[i] = rd32(hw, I40E_VFQF_HLUT(i));
1385 }
1386
1387 return 0;
1388}
1389
2c86ac3c
HZ
1390/**
1391 * i40evf_config_rss - Configure RSS keys and lut
1392 * @vsi: Pointer to vsi structure
1393 * @seed: RSS hash seed
1394 * @lut: Lookup table
1395 * @lut_size: Lookup table size
1396 *
1397 * Returns 0 on success, negative on failure
1398 **/
1399int i40evf_config_rss(struct i40e_vsi *vsi, const u8 *seed,
1400 u8 *lut, u16 lut_size)
1401{
1402 struct i40evf_adapter *adapter = vsi->back;
1403
1404 if (RSS_AQ(adapter))
1405 return i40evf_config_rss_aq(vsi, seed, lut, lut_size);
1406 else
1407 return i40evf_config_rss_reg(vsi, seed, lut, lut_size);
1408}
1409
90b02b43
HZ
1410/**
1411 * i40evf_get_rss - Get RSS keys and lut
1412 * @vsi: Pointer to vsi structure
1413 * @seed: RSS hash seed
1414 * @lut: Lookup table
1415 * @lut_size: Lookup table size
1416 *
1417 * Returns 0 on success, negative on failure
1418 **/
1419int i40evf_get_rss(struct i40e_vsi *vsi, const u8 *seed, u8 *lut, u16 lut_size)
1420{
1421 struct i40evf_adapter *adapter = vsi->back;
1422
1423 if (RSS_AQ(adapter))
1424 return i40evf_get_rss_aq(vsi, seed, lut, lut_size);
1425 else
1426 return i40evf_get_rss_reg(vsi, seed, lut, lut_size);
1427}
1428
2c86ac3c
HZ
1429/**
1430 * i40evf_fill_rss_lut - Fill the lut with default values
1431 * @lut: Lookup table to be filled with
1432 * @rss_table_size: Lookup table size
1433 * @rss_size: Range of queue number for hashing
1434 **/
1435static void i40evf_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
1436{
1437 u16 i;
1438
1439 for (i = 0; i < rss_table_size; i++)
1440 lut[i] = i % rss_size;
e25d00b8
ASJ
1441}
1442
1443/**
96a81986 1444 * i40evf_init_rss - Prepare for RSS
e25d00b8 1445 * @adapter: board private structure
2c86ac3c
HZ
1446 *
1447 * Return 0 on success, negative on failure
e25d00b8 1448 **/
2c86ac3c 1449static int i40evf_init_rss(struct i40evf_adapter *adapter)
e25d00b8 1450{
2c86ac3c 1451 struct i40e_vsi *vsi = &adapter->vsi;
e25d00b8
ASJ
1452 struct i40e_hw *hw = &adapter->hw;
1453 u8 seed[I40EVF_HKEY_ARRAY_SIZE];
1454 u64 hena;
2c86ac3c
HZ
1455 u8 *lut;
1456 int ret;
e25d00b8
ASJ
1457
1458 /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
3d0da5b7
ASJ
1459 if (adapter->vf_res->vf_offload_flags &
1460 I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
1461 hena = I40E_DEFAULT_RSS_HENA_EXPANDED;
1462 else
1463 hena = I40E_DEFAULT_RSS_HENA;
e25d00b8
ASJ
1464 wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
1465 wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
1466
2c86ac3c
HZ
1467 lut = kzalloc(I40EVF_HLUT_ARRAY_SIZE, GFP_KERNEL);
1468 if (!lut)
1469 return -ENOMEM;
66f9af85
HZ
1470
1471 /* Use user configured lut if there is one, otherwise use default */
1472 if (vsi->rss_lut_user)
1473 memcpy(lut, vsi->rss_lut_user, I40EVF_HLUT_ARRAY_SIZE);
1474 else
1475 i40evf_fill_rss_lut(lut, I40EVF_HLUT_ARRAY_SIZE,
1476 adapter->num_active_queues);
1477
1478 /* Use user configured hash key if there is one, otherwise
1479 * user default.
1480 */
1481 if (vsi->rss_hkey_user)
1482 memcpy(seed, vsi->rss_hkey_user, I40EVF_HKEY_ARRAY_SIZE);
1483 else
1484 netdev_rss_key_fill((void *)seed, I40EVF_HKEY_ARRAY_SIZE);
2c86ac3c
HZ
1485 ret = i40evf_config_rss(vsi, seed, lut, I40EVF_HLUT_ARRAY_SIZE);
1486 kfree(lut);
1487
1488 return ret;
e25d00b8
ASJ
1489}
1490
5eae00c5
GR
1491/**
1492 * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
1493 * @adapter: board private structure to initialize
1494 *
1495 * We allocate one q_vector per queue interrupt. If allocation fails we
1496 * return -ENOMEM.
1497 **/
1498static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter)
1499{
7d96ba1a 1500 int q_idx = 0, num_q_vectors;
5eae00c5
GR
1501 struct i40e_q_vector *q_vector;
1502
1503 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
0dd438d8 1504 adapter->q_vectors = kcalloc(num_q_vectors, sizeof(*q_vector),
7d96ba1a
MW
1505 GFP_KERNEL);
1506 if (!adapter->q_vectors)
1507 goto err_out;
5eae00c5
GR
1508
1509 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
7d96ba1a 1510 q_vector = &adapter->q_vectors[q_idx];
5eae00c5
GR
1511 q_vector->adapter = adapter;
1512 q_vector->vsi = &adapter->vsi;
1513 q_vector->v_idx = q_idx;
1514 netif_napi_add(adapter->netdev, &q_vector->napi,
75a64435 1515 i40evf_napi_poll, NAPI_POLL_WEIGHT);
5eae00c5
GR
1516 }
1517
1518 return 0;
1519
1520err_out:
1521 while (q_idx) {
1522 q_idx--;
7d96ba1a 1523 q_vector = &adapter->q_vectors[q_idx];
5eae00c5 1524 netif_napi_del(&q_vector->napi);
5eae00c5 1525 }
7d96ba1a 1526 kfree(adapter->q_vectors);
5eae00c5
GR
1527 return -ENOMEM;
1528}
1529
1530/**
1531 * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
1532 * @adapter: board private structure to initialize
1533 *
1534 * This function frees the memory allocated to the q_vectors. In addition if
1535 * NAPI is enabled it will delete any references to the NAPI struct prior
1536 * to freeing the q_vector.
1537 **/
1538static void i40evf_free_q_vectors(struct i40evf_adapter *adapter)
1539{
1540 int q_idx, num_q_vectors;
1541 int napi_vectors;
1542
1543 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
cc052927 1544 napi_vectors = adapter->num_active_queues;
5eae00c5
GR
1545
1546 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
7d96ba1a 1547 struct i40e_q_vector *q_vector = &adapter->q_vectors[q_idx];
5eae00c5
GR
1548 if (q_idx < napi_vectors)
1549 netif_napi_del(&q_vector->napi);
5eae00c5 1550 }
7d96ba1a 1551 kfree(adapter->q_vectors);
5eae00c5
GR
1552}
1553
1554/**
1555 * i40evf_reset_interrupt_capability - Reset MSIX setup
1556 * @adapter: board private structure
1557 *
1558 **/
1559void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter)
1560{
1561 pci_disable_msix(adapter->pdev);
1562 kfree(adapter->msix_entries);
1563 adapter->msix_entries = NULL;
5eae00c5
GR
1564}
1565
1566/**
1567 * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
1568 * @adapter: board private structure to initialize
1569 *
1570 **/
1571int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter)
1572{
1573 int err;
1574
1575 err = i40evf_set_interrupt_capability(adapter);
1576 if (err) {
1577 dev_err(&adapter->pdev->dev,
1578 "Unable to setup interrupt capabilities\n");
1579 goto err_set_interrupt;
1580 }
1581
1582 err = i40evf_alloc_q_vectors(adapter);
1583 if (err) {
1584 dev_err(&adapter->pdev->dev,
1585 "Unable to allocate memory for queue vectors\n");
1586 goto err_alloc_q_vectors;
1587 }
1588
1589 err = i40evf_alloc_queues(adapter);
1590 if (err) {
1591 dev_err(&adapter->pdev->dev,
1592 "Unable to allocate memory for queues\n");
1593 goto err_alloc_queues;
1594 }
1595
1596 dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u",
75a64435
MW
1597 (adapter->num_active_queues > 1) ? "Enabled" : "Disabled",
1598 adapter->num_active_queues);
5eae00c5
GR
1599
1600 return 0;
1601err_alloc_queues:
1602 i40evf_free_q_vectors(adapter);
1603err_alloc_q_vectors:
1604 i40evf_reset_interrupt_capability(adapter);
1605err_set_interrupt:
1606 return err;
1607}
1608
66f9af85
HZ
1609/**
1610 * i40evf_clear_rss_config_user - Clear user configurations of RSS
1611 * @vsi: Pointer to VSI structure
1612 **/
1613static void i40evf_clear_rss_config_user(struct i40e_vsi *vsi)
1614{
1615 if (!vsi)
1616 return;
1617
1618 kfree(vsi->rss_hkey_user);
1619 vsi->rss_hkey_user = NULL;
1620
1621 kfree(vsi->rss_lut_user);
1622 vsi->rss_lut_user = NULL;
1623}
1624
5eae00c5
GR
1625/**
1626 * i40evf_watchdog_timer - Periodic call-back timer
1627 * @data: pointer to adapter disguised as unsigned long
1628 **/
1629static void i40evf_watchdog_timer(unsigned long data)
1630{
1631 struct i40evf_adapter *adapter = (struct i40evf_adapter *)data;
75a64435 1632
5eae00c5
GR
1633 schedule_work(&adapter->watchdog_task);
1634 /* timer will be rescheduled in watchdog task */
1635}
1636
1637/**
1638 * i40evf_watchdog_task - Periodic call-back task
1639 * @work: pointer to work_struct
1640 **/
1641static void i40evf_watchdog_task(struct work_struct *work)
1642{
1643 struct i40evf_adapter *adapter = container_of(work,
75a64435
MW
1644 struct i40evf_adapter,
1645 watchdog_task);
5eae00c5 1646 struct i40e_hw *hw = &adapter->hw;
ee5c1e92 1647 u32 reg_val;
5eae00c5 1648
ef8693eb
MW
1649 if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section))
1650 goto restart_watchdog;
1651
1652 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
ee5c1e92
MW
1653 reg_val = rd32(hw, I40E_VFGEN_RSTAT) &
1654 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1655 if ((reg_val == I40E_VFR_VFACTIVE) ||
1656 (reg_val == I40E_VFR_COMPLETED)) {
ef8693eb
MW
1657 /* A chance for redemption! */
1658 dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n");
1659 adapter->state = __I40EVF_STARTUP;
1660 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
1661 schedule_delayed_work(&adapter->init_task, 10);
1662 clear_bit(__I40EVF_IN_CRITICAL_TASK,
1663 &adapter->crit_section);
1664 /* Don't reschedule the watchdog, since we've restarted
1665 * the init task. When init_task contacts the PF and
1666 * gets everything set up again, it'll restart the
1667 * watchdog for us. Down, boy. Sit. Stay. Woof.
1668 */
1669 return;
1670 }
ef8693eb
MW
1671 adapter->aq_required = 0;
1672 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
5eae00c5 1673 goto watchdog_done;
ef8693eb 1674 }
5eae00c5 1675
ef8693eb
MW
1676 if ((adapter->state < __I40EVF_DOWN) ||
1677 (adapter->flags & I40EVF_FLAG_RESET_PENDING))
5eae00c5
GR
1678 goto watchdog_done;
1679
ef8693eb 1680 /* check for reset */
ee5c1e92
MW
1681 reg_val = rd32(hw, I40E_VF_ARQLEN1) & I40E_VF_ARQLEN1_ARQENABLE_MASK;
1682 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) && !reg_val) {
5eae00c5 1683 adapter->state = __I40EVF_RESETTING;
ef8693eb 1684 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
249c8b8d 1685 dev_err(&adapter->pdev->dev, "Hardware reset detected\n");
5eae00c5 1686 schedule_work(&adapter->reset_task);
ef8693eb
MW
1687 adapter->aq_required = 0;
1688 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
5eae00c5
GR
1689 goto watchdog_done;
1690 }
1691
1692 /* Process admin queue tasks. After init, everything gets done
1693 * here so we don't race on the admin queue.
1694 */
ed636960 1695 if (adapter->current_op) {
0758e7cb
MW
1696 if (!i40evf_asq_done(hw)) {
1697 dev_dbg(&adapter->pdev->dev, "Admin queue timeout\n");
1698 i40evf_send_api_ver(adapter);
1699 }
5eae00c5 1700 goto watchdog_done;
0758e7cb 1701 }
e6d038de
MW
1702 if (adapter->aq_required & I40EVF_FLAG_AQ_GET_CONFIG) {
1703 i40evf_send_vf_config_msg(adapter);
1704 goto watchdog_done;
1705 }
5eae00c5 1706
e284fc88
MW
1707 if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) {
1708 i40evf_disable_queues(adapter);
1709 goto watchdog_done;
1710 }
1711
5eae00c5
GR
1712 if (adapter->aq_required & I40EVF_FLAG_AQ_MAP_VECTORS) {
1713 i40evf_map_queues(adapter);
1714 goto watchdog_done;
1715 }
1716
1717 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_MAC_FILTER) {
1718 i40evf_add_ether_addrs(adapter);
1719 goto watchdog_done;
1720 }
1721
1722 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_VLAN_FILTER) {
1723 i40evf_add_vlans(adapter);
1724 goto watchdog_done;
1725 }
1726
1727 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_MAC_FILTER) {
1728 i40evf_del_ether_addrs(adapter);
1729 goto watchdog_done;
1730 }
1731
1732 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_VLAN_FILTER) {
1733 i40evf_del_vlans(adapter);
1734 goto watchdog_done;
1735 }
1736
5eae00c5
GR
1737 if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_QUEUES) {
1738 i40evf_configure_queues(adapter);
1739 goto watchdog_done;
1740 }
1741
1742 if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_QUEUES) {
1743 i40evf_enable_queues(adapter);
1744 goto watchdog_done;
1745 }
1746
e25d00b8
ASJ
1747 if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_RSS) {
1748 /* This message goes straight to the firmware, not the
1749 * PF, so we don't have to set current_op as we will
1750 * not get a response through the ARQ.
1751 */
96a81986 1752 i40evf_init_rss(adapter);
e25d00b8
ASJ
1753 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_RSS;
1754 goto watchdog_done;
1755 }
1756
5eae00c5
GR
1757 if (adapter->state == __I40EVF_RUNNING)
1758 i40evf_request_stats(adapter);
5eae00c5 1759watchdog_done:
4870e176
MW
1760 if (adapter->state == __I40EVF_RUNNING) {
1761 i40evf_irq_enable_queues(adapter, ~0);
1762 i40evf_fire_sw_int(adapter, 0xFF);
1763 } else {
1764 i40evf_fire_sw_int(adapter, 0x1);
1765 }
1766
ef8693eb
MW
1767 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1768restart_watchdog:
d3e2edb7
AS
1769 if (adapter->state == __I40EVF_REMOVE)
1770 return;
5eae00c5
GR
1771 if (adapter->aq_required)
1772 mod_timer(&adapter->watchdog_timer,
1773 jiffies + msecs_to_jiffies(20));
1774 else
1775 mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2));
5eae00c5
GR
1776 schedule_work(&adapter->adminq_task);
1777}
1778
67c818a1
MW
1779#define I40EVF_RESET_WAIT_MS 10
1780#define I40EVF_RESET_WAIT_COUNT 500
5eae00c5
GR
1781/**
1782 * i40evf_reset_task - Call-back task to handle hardware reset
1783 * @work: pointer to work_struct
1784 *
1785 * During reset we need to shut down and reinitialize the admin queue
1786 * before we can use it to communicate with the PF again. We also clear
1787 * and reinit the rings because that context is lost as well.
1788 **/
1789static void i40evf_reset_task(struct work_struct *work)
1790{
ef8693eb
MW
1791 struct i40evf_adapter *adapter = container_of(work,
1792 struct i40evf_adapter,
1793 reset_task);
ac833bbf 1794 struct net_device *netdev = adapter->netdev;
5eae00c5 1795 struct i40e_hw *hw = &adapter->hw;
40d01366 1796 struct i40evf_vlan_filter *vlf;
ac833bbf 1797 struct i40evf_mac_filter *f;
ee5c1e92 1798 u32 reg_val;
ac833bbf 1799 int i = 0, err;
5eae00c5
GR
1800
1801 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
1802 &adapter->crit_section))
f98a2006 1803 usleep_range(500, 1000);
3526d800 1804
67c818a1 1805 i40evf_misc_irq_disable(adapter);
3526d800 1806 if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) {
67c818a1
MW
1807 adapter->flags &= ~I40EVF_FLAG_RESET_NEEDED;
1808 /* Restart the AQ here. If we have been reset but didn't
1809 * detect it, or if the PF had to reinit, our AQ will be hosed.
1810 */
1811 i40evf_shutdown_adminq(hw);
1812 i40evf_init_adminq(hw);
3526d800
MW
1813 i40evf_request_reset(adapter);
1814 }
67c818a1 1815 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
3526d800 1816
ef8693eb
MW
1817 /* poll until we see the reset actually happen */
1818 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
ee5c1e92
MW
1819 reg_val = rd32(hw, I40E_VF_ARQLEN1) &
1820 I40E_VF_ARQLEN1_ARQENABLE_MASK;
1821 if (!reg_val)
ef8693eb 1822 break;
ee5c1e92 1823 usleep_range(5000, 10000);
ef8693eb
MW
1824 }
1825 if (i == I40EVF_RESET_WAIT_COUNT) {
67c818a1 1826 dev_info(&adapter->pdev->dev, "Never saw reset\n");
ef8693eb
MW
1827 goto continue_reset; /* act like the reset happened */
1828 }
5eae00c5 1829
ef8693eb
MW
1830 /* wait until the reset is complete and the PF is responding to us */
1831 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
ee5c1e92
MW
1832 reg_val = rd32(hw, I40E_VFGEN_RSTAT) &
1833 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1834 if (reg_val == I40E_VFR_VFACTIVE)
5eae00c5 1835 break;
c88e38cc 1836 msleep(I40EVF_RESET_WAIT_MS);
5eae00c5 1837 }
67c818a1
MW
1838 /* extra wait to make sure minimum wait is met */
1839 msleep(I40EVF_RESET_WAIT_MS);
ef8693eb 1840 if (i == I40EVF_RESET_WAIT_COUNT) {
874d1a10 1841 struct i40evf_mac_filter *ftmp;
6ba36a24
MW
1842 struct i40evf_vlan_filter *fv, *fvtmp;
1843
5eae00c5 1844 /* reset never finished */
80e72893 1845 dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n",
ee5c1e92 1846 reg_val);
ef8693eb
MW
1847 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
1848
169f4076
MW
1849 if (netif_running(adapter->netdev)) {
1850 set_bit(__I40E_DOWN, &adapter->vsi.state);
ac833bbf 1851 netif_carrier_off(netdev);
67c818a1
MW
1852 netif_tx_disable(netdev);
1853 i40evf_napi_disable_all(adapter);
1854 i40evf_irq_disable(adapter);
169f4076
MW
1855 i40evf_free_traffic_irqs(adapter);
1856 i40evf_free_all_tx_resources(adapter);
1857 i40evf_free_all_rx_resources(adapter);
1858 }
6ba36a24
MW
1859
1860 /* Delete all of the filters, both MAC and VLAN. */
1861 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list,
1862 list) {
1863 list_del(&f->list);
1864 kfree(f);
1865 }
67c818a1 1866
6ba36a24
MW
1867 list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list,
1868 list) {
1869 list_del(&fv->list);
1870 kfree(fv);
1871 }
1872
ef8693eb
MW
1873 i40evf_free_misc_irq(adapter);
1874 i40evf_reset_interrupt_capability(adapter);
1875 i40evf_free_queues(adapter);
d31944d6 1876 i40evf_free_q_vectors(adapter);
ef8693eb
MW
1877 kfree(adapter->vf_res);
1878 i40evf_shutdown_adminq(hw);
1879 adapter->netdev->flags &= ~IFF_UP;
1880 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
67c818a1
MW
1881 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1882 dev_info(&adapter->pdev->dev, "Reset task did not complete, VF disabled\n");
ef8693eb 1883 return; /* Do not attempt to reinit. It's dead, Jim. */
5eae00c5 1884 }
ef8693eb
MW
1885
1886continue_reset:
3c8e0b98 1887 if (netif_running(adapter->netdev)) {
3c8e0b98 1888 netif_carrier_off(netdev);
67c818a1
MW
1889 netif_tx_stop_all_queues(netdev);
1890 i40evf_napi_disable_all(adapter);
3c8e0b98 1891 }
67c818a1 1892 i40evf_irq_disable(adapter);
ac833bbf 1893
5eae00c5 1894 adapter->state = __I40EVF_RESETTING;
67c818a1
MW
1895 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1896
1897 /* free the Tx/Rx rings and descriptors, might be better to just
1898 * re-use them sometime in the future
1899 */
1900 i40evf_free_all_rx_resources(adapter);
1901 i40evf_free_all_tx_resources(adapter);
5eae00c5
GR
1902
1903 /* kill and reinit the admin queue */
1904 if (i40evf_shutdown_adminq(hw))
ac833bbf
MW
1905 dev_warn(&adapter->pdev->dev, "Failed to shut down adminq\n");
1906 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
5eae00c5
GR
1907 err = i40evf_init_adminq(hw);
1908 if (err)
ac833bbf
MW
1909 dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n",
1910 err);
5eae00c5 1911
e6d038de
MW
1912 adapter->aq_required = I40EVF_FLAG_AQ_GET_CONFIG;
1913 adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
ac833bbf
MW
1914
1915 /* re-add all MAC filters */
1916 list_for_each_entry(f, &adapter->mac_filter_list, list) {
1917 f->add = true;
1918 }
1919 /* re-add all VLAN filters */
40d01366
MW
1920 list_for_each_entry(vlf, &adapter->vlan_filter_list, list) {
1921 vlf->add = true;
ac833bbf 1922 }
e6d038de 1923 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
ac833bbf 1924 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
5eae00c5 1925 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
67c818a1 1926 i40evf_misc_irq_enable(adapter);
5eae00c5
GR
1927
1928 mod_timer(&adapter->watchdog_timer, jiffies + 2);
1929
1930 if (netif_running(adapter->netdev)) {
1931 /* allocate transmit descriptors */
1932 err = i40evf_setup_all_tx_resources(adapter);
1933 if (err)
1934 goto reset_err;
1935
1936 /* allocate receive descriptors */
1937 err = i40evf_setup_all_rx_resources(adapter);
1938 if (err)
1939 goto reset_err;
1940
1941 i40evf_configure(adapter);
1942
1943 err = i40evf_up_complete(adapter);
1944 if (err)
1945 goto reset_err;
1946
1947 i40evf_irq_enable(adapter, true);
67c818a1
MW
1948 } else {
1949 adapter->state = __I40EVF_DOWN;
5eae00c5 1950 }
67c818a1 1951
5eae00c5
GR
1952 return;
1953reset_err:
80e72893 1954 dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
5eae00c5
GR
1955 i40evf_close(adapter->netdev);
1956}
1957
1958/**
1959 * i40evf_adminq_task - worker thread to clean the admin queue
1960 * @work: pointer to work_struct containing our data
1961 **/
1962static void i40evf_adminq_task(struct work_struct *work)
1963{
1964 struct i40evf_adapter *adapter =
1965 container_of(work, struct i40evf_adapter, adminq_task);
1966 struct i40e_hw *hw = &adapter->hw;
1967 struct i40e_arq_event_info event;
1968 struct i40e_virtchnl_msg *v_msg;
1969 i40e_status ret;
912257e5 1970 u32 val, oldval;
5eae00c5
GR
1971 u16 pending;
1972
ef8693eb 1973 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
7235448c 1974 goto out;
ef8693eb 1975
1001dc37
MW
1976 event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
1977 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
249c8b8d 1978 if (!event.msg_buf)
7235448c 1979 goto out;
249c8b8d 1980
5eae00c5
GR
1981 v_msg = (struct i40e_virtchnl_msg *)&event.desc;
1982 do {
1983 ret = i40evf_clean_arq_element(hw, &event, &pending);
8b011ebb 1984 if (ret || !v_msg->v_opcode)
5eae00c5
GR
1985 break; /* No event to process or error cleaning ARQ */
1986
1987 i40evf_virtchnl_completion(adapter, v_msg->v_opcode,
1988 v_msg->v_retval, event.msg_buf,
1001dc37 1989 event.msg_len);
75a64435 1990 if (pending != 0)
5eae00c5 1991 memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE);
5eae00c5
GR
1992 } while (pending);
1993
67c818a1
MW
1994 if ((adapter->flags &
1995 (I40EVF_FLAG_RESET_PENDING | I40EVF_FLAG_RESET_NEEDED)) ||
1996 adapter->state == __I40EVF_RESETTING)
1997 goto freedom;
1998
912257e5
MW
1999 /* check for error indications */
2000 val = rd32(hw, hw->aq.arq.len);
2001 oldval = val;
b1f3366b 2002 if (val & I40E_VF_ARQLEN1_ARQVFE_MASK) {
912257e5 2003 dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n");
b1f3366b 2004 val &= ~I40E_VF_ARQLEN1_ARQVFE_MASK;
912257e5 2005 }
b1f3366b 2006 if (val & I40E_VF_ARQLEN1_ARQOVFL_MASK) {
912257e5 2007 dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n");
b1f3366b 2008 val &= ~I40E_VF_ARQLEN1_ARQOVFL_MASK;
912257e5 2009 }
b1f3366b 2010 if (val & I40E_VF_ARQLEN1_ARQCRIT_MASK) {
912257e5 2011 dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n");
b1f3366b 2012 val &= ~I40E_VF_ARQLEN1_ARQCRIT_MASK;
912257e5
MW
2013 }
2014 if (oldval != val)
2015 wr32(hw, hw->aq.arq.len, val);
2016
2017 val = rd32(hw, hw->aq.asq.len);
2018 oldval = val;
b1f3366b 2019 if (val & I40E_VF_ATQLEN1_ATQVFE_MASK) {
912257e5 2020 dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n");
b1f3366b 2021 val &= ~I40E_VF_ATQLEN1_ATQVFE_MASK;
912257e5 2022 }
b1f3366b 2023 if (val & I40E_VF_ATQLEN1_ATQOVFL_MASK) {
912257e5 2024 dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n");
b1f3366b 2025 val &= ~I40E_VF_ATQLEN1_ATQOVFL_MASK;
912257e5 2026 }
b1f3366b 2027 if (val & I40E_VF_ATQLEN1_ATQCRIT_MASK) {
912257e5 2028 dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n");
b1f3366b 2029 val &= ~I40E_VF_ATQLEN1_ATQCRIT_MASK;
912257e5
MW
2030 }
2031 if (oldval != val)
2032 wr32(hw, hw->aq.asq.len, val);
2033
67c818a1 2034freedom:
7235448c
MW
2035 kfree(event.msg_buf);
2036out:
5eae00c5
GR
2037 /* re-enable Admin queue interrupt cause */
2038 i40evf_misc_irq_enable(adapter);
5eae00c5
GR
2039}
2040
2041/**
2042 * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
2043 * @adapter: board private structure
2044 *
2045 * Free all transmit software resources
2046 **/
e284fc88 2047void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter)
5eae00c5
GR
2048{
2049 int i;
2050
fdb47ae8
MW
2051 if (!adapter->tx_rings)
2052 return;
2053
cc052927 2054 for (i = 0; i < adapter->num_active_queues; i++)
0dd438d8
MW
2055 if (adapter->tx_rings[i].desc)
2056 i40evf_free_tx_resources(&adapter->tx_rings[i]);
5eae00c5
GR
2057}
2058
2059/**
2060 * i40evf_setup_all_tx_resources - allocate all queues Tx resources
2061 * @adapter: board private structure
2062 *
2063 * If this function returns with an error, then it's possible one or
2064 * more of the rings is populated (while the rest are not). It is the
2065 * callers duty to clean those orphaned rings.
2066 *
2067 * Return 0 on success, negative on failure
2068 **/
2069static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter)
2070{
2071 int i, err = 0;
2072
cc052927 2073 for (i = 0; i < adapter->num_active_queues; i++) {
0dd438d8
MW
2074 adapter->tx_rings[i].count = adapter->tx_desc_count;
2075 err = i40evf_setup_tx_descriptors(&adapter->tx_rings[i]);
5eae00c5
GR
2076 if (!err)
2077 continue;
2078 dev_err(&adapter->pdev->dev,
fb43201f 2079 "Allocation for Tx Queue %u failed\n", i);
5eae00c5
GR
2080 break;
2081 }
2082
2083 return err;
2084}
2085
2086/**
2087 * i40evf_setup_all_rx_resources - allocate all queues Rx resources
2088 * @adapter: board private structure
2089 *
2090 * If this function returns with an error, then it's possible one or
2091 * more of the rings is populated (while the rest are not). It is the
2092 * callers duty to clean those orphaned rings.
2093 *
2094 * Return 0 on success, negative on failure
2095 **/
2096static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter)
2097{
2098 int i, err = 0;
2099
cc052927 2100 for (i = 0; i < adapter->num_active_queues; i++) {
0dd438d8
MW
2101 adapter->rx_rings[i].count = adapter->rx_desc_count;
2102 err = i40evf_setup_rx_descriptors(&adapter->rx_rings[i]);
5eae00c5
GR
2103 if (!err)
2104 continue;
2105 dev_err(&adapter->pdev->dev,
fb43201f 2106 "Allocation for Rx Queue %u failed\n", i);
5eae00c5
GR
2107 break;
2108 }
2109 return err;
2110}
2111
2112/**
2113 * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
2114 * @adapter: board private structure
2115 *
2116 * Free all receive software resources
2117 **/
e284fc88 2118void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter)
5eae00c5
GR
2119{
2120 int i;
2121
fdb47ae8
MW
2122 if (!adapter->rx_rings)
2123 return;
2124
cc052927 2125 for (i = 0; i < adapter->num_active_queues; i++)
0dd438d8
MW
2126 if (adapter->rx_rings[i].desc)
2127 i40evf_free_rx_resources(&adapter->rx_rings[i]);
5eae00c5
GR
2128}
2129
2130/**
2131 * i40evf_open - Called when a network interface is made active
2132 * @netdev: network interface device structure
2133 *
2134 * Returns 0 on success, negative value on failure
2135 *
2136 * The open entry point is called when a network interface is made
2137 * active by the system (IFF_UP). At this point all resources needed
2138 * for transmit and receive operations are allocated, the interrupt
2139 * handler is registered with the OS, the watchdog timer is started,
2140 * and the stack is notified that the interface is ready.
2141 **/
2142static int i40evf_open(struct net_device *netdev)
2143{
2144 struct i40evf_adapter *adapter = netdev_priv(netdev);
2145 int err;
2146
ef8693eb
MW
2147 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
2148 dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
2149 return -EIO;
2150 }
209dc4da
MW
2151
2152 if (adapter->state != __I40EVF_DOWN)
5eae00c5
GR
2153 return -EBUSY;
2154
2155 /* allocate transmit descriptors */
2156 err = i40evf_setup_all_tx_resources(adapter);
2157 if (err)
2158 goto err_setup_tx;
2159
2160 /* allocate receive descriptors */
2161 err = i40evf_setup_all_rx_resources(adapter);
2162 if (err)
2163 goto err_setup_rx;
2164
2165 /* clear any pending interrupts, may auto mask */
2166 err = i40evf_request_traffic_irqs(adapter, netdev->name);
2167 if (err)
2168 goto err_req_irq;
2169
44151cd3 2170 i40evf_add_filter(adapter, adapter->hw.mac.addr);
5eae00c5
GR
2171 i40evf_configure(adapter);
2172
2173 err = i40evf_up_complete(adapter);
2174 if (err)
2175 goto err_req_irq;
2176
2177 i40evf_irq_enable(adapter, true);
2178
2179 return 0;
2180
2181err_req_irq:
2182 i40evf_down(adapter);
2183 i40evf_free_traffic_irqs(adapter);
2184err_setup_rx:
2185 i40evf_free_all_rx_resources(adapter);
2186err_setup_tx:
2187 i40evf_free_all_tx_resources(adapter);
2188
2189 return err;
2190}
2191
2192/**
2193 * i40evf_close - Disables a network interface
2194 * @netdev: network interface device structure
2195 *
2196 * Returns 0, this is not allowed to fail
2197 *
2198 * The close entry point is called when an interface is de-activated
2199 * by the OS. The hardware is still under the drivers control, but
2200 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
2201 * are freed, along with all transmit and receive resources.
2202 **/
2203static int i40evf_close(struct net_device *netdev)
2204{
2205 struct i40evf_adapter *adapter = netdev_priv(netdev);
2206
209dc4da 2207 if (adapter->state <= __I40EVF_DOWN_PENDING)
ef8693eb
MW
2208 return 0;
2209
ef8693eb 2210
5eae00c5
GR
2211 set_bit(__I40E_DOWN, &adapter->vsi.state);
2212
2213 i40evf_down(adapter);
209dc4da 2214 adapter->state = __I40EVF_DOWN_PENDING;
5eae00c5
GR
2215 i40evf_free_traffic_irqs(adapter);
2216
5eae00c5
GR
2217 return 0;
2218}
2219
2220/**
2221 * i40evf_get_stats - Get System Network Statistics
2222 * @netdev: network interface device structure
2223 *
2224 * Returns the address of the device statistics structure.
2225 * The statistics are actually updated from the timer callback.
2226 **/
2227static struct net_device_stats *i40evf_get_stats(struct net_device *netdev)
2228{
2229 struct i40evf_adapter *adapter = netdev_priv(netdev);
2230
2231 /* only return the current stats */
2232 return &adapter->net_stats;
2233}
2234
5eae00c5
GR
2235/**
2236 * i40evf_change_mtu - Change the Maximum Transfer Unit
2237 * @netdev: network interface device structure
2238 * @new_mtu: new value for maximum frame size
2239 *
2240 * Returns 0 on success, negative on failure
2241 **/
2242static int i40evf_change_mtu(struct net_device *netdev, int new_mtu)
2243{
2244 struct i40evf_adapter *adapter = netdev_priv(netdev);
2245 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
2246
2247 if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
2248 return -EINVAL;
2249
5eae00c5 2250 netdev->mtu = new_mtu;
67c818a1
MW
2251 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
2252 schedule_work(&adapter->reset_task);
2253
5eae00c5
GR
2254 return 0;
2255}
2256
2257static const struct net_device_ops i40evf_netdev_ops = {
2258 .ndo_open = i40evf_open,
2259 .ndo_stop = i40evf_close,
2260 .ndo_start_xmit = i40evf_xmit_frame,
2261 .ndo_get_stats = i40evf_get_stats,
2262 .ndo_set_rx_mode = i40evf_set_rx_mode,
2263 .ndo_validate_addr = eth_validate_addr,
2264 .ndo_set_mac_address = i40evf_set_mac,
2265 .ndo_change_mtu = i40evf_change_mtu,
2266 .ndo_tx_timeout = i40evf_tx_timeout,
2267 .ndo_vlan_rx_add_vid = i40evf_vlan_rx_add_vid,
2268 .ndo_vlan_rx_kill_vid = i40evf_vlan_rx_kill_vid,
7709b4c1
AD
2269#ifdef CONFIG_NET_POLL_CONTROLLER
2270 .ndo_poll_controller = i40evf_netpoll,
2271#endif
5eae00c5
GR
2272};
2273
2274/**
2275 * i40evf_check_reset_complete - check that VF reset is complete
2276 * @hw: pointer to hw struct
2277 *
2278 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
2279 **/
2280static int i40evf_check_reset_complete(struct i40e_hw *hw)
2281{
2282 u32 rstat;
2283 int i;
2284
2285 for (i = 0; i < 100; i++) {
fd35886a
AS
2286 rstat = rd32(hw, I40E_VFGEN_RSTAT) &
2287 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
2288 if ((rstat == I40E_VFR_VFACTIVE) ||
2289 (rstat == I40E_VFR_COMPLETED))
5eae00c5 2290 return 0;
f98a2006 2291 usleep_range(10, 20);
5eae00c5
GR
2292 }
2293 return -EBUSY;
2294}
2295
e6d038de
MW
2296/**
2297 * i40evf_process_config - Process the config information we got from the PF
2298 * @adapter: board private structure
2299 *
2300 * Verify that we have a valid config struct, and set up our netdev features
2301 * and our VSI struct.
2302 **/
2303int i40evf_process_config(struct i40evf_adapter *adapter)
2304{
2305 struct net_device *netdev = adapter->netdev;
2306 int i;
2307
2308 /* got VF config message back from PF, now we can parse it */
2309 for (i = 0; i < adapter->vf_res->num_vsis; i++) {
2310 if (adapter->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
2311 adapter->vsi_res = &adapter->vf_res->vsi_res[i];
2312 }
2313 if (!adapter->vsi_res) {
2314 dev_err(&adapter->pdev->dev, "No LAN VSI found\n");
2315 return -ENODEV;
2316 }
2317
2318 if (adapter->vf_res->vf_offload_flags
2319 & I40E_VIRTCHNL_VF_OFFLOAD_VLAN) {
cc7e406c
MW
2320 netdev->vlan_features = netdev->features &
2321 ~(NETIF_F_HW_VLAN_CTAG_TX |
2322 NETIF_F_HW_VLAN_CTAG_RX |
2323 NETIF_F_HW_VLAN_CTAG_FILTER);
e6d038de
MW
2324 netdev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2325 NETIF_F_HW_VLAN_CTAG_RX |
2326 NETIF_F_HW_VLAN_CTAG_FILTER;
2327 }
2328 netdev->features |= NETIF_F_HIGHDMA |
2329 NETIF_F_SG |
2330 NETIF_F_IP_CSUM |
53692b1d 2331 NETIF_F_SCTP_CRC |
e6d038de
MW
2332 NETIF_F_IPV6_CSUM |
2333 NETIF_F_TSO |
2334 NETIF_F_TSO6 |
2335 NETIF_F_RXCSUM |
2336 NETIF_F_GRO;
2337
2338 /* copy netdev features into list of user selectable features */
2339 netdev->hw_features |= netdev->features;
2340 netdev->hw_features &= ~NETIF_F_RXCSUM;
2341
2342 adapter->vsi.id = adapter->vsi_res->vsi_id;
2343
2344 adapter->vsi.back = adapter;
2345 adapter->vsi.base_vector = 1;
2346 adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK;
2347 adapter->vsi.rx_itr_setting = (I40E_ITR_DYNAMIC |
2348 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
2349 adapter->vsi.tx_itr_setting = (I40E_ITR_DYNAMIC |
2350 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
2351 adapter->vsi.netdev = adapter->netdev;
f578f5f4 2352 adapter->vsi.qs_handle = adapter->vsi_res->qset_handle;
e6d038de
MW
2353 return 0;
2354}
2355
5eae00c5
GR
2356/**
2357 * i40evf_init_task - worker thread to perform delayed initialization
2358 * @work: pointer to work_struct containing our data
2359 *
2360 * This task completes the work that was begun in probe. Due to the nature
2361 * of VF-PF communications, we may need to wait tens of milliseconds to get
dbedd44e 2362 * responses back from the PF. Rather than busy-wait in probe and bog down the
5eae00c5
GR
2363 * whole system, we'll do it in a task so we can sleep.
2364 * This task only runs during driver init. Once we've established
2365 * communications with the PF driver and set up our netdev, the watchdog
2366 * takes over.
2367 **/
2368static void i40evf_init_task(struct work_struct *work)
2369{
2370 struct i40evf_adapter *adapter = container_of(work,
2371 struct i40evf_adapter,
2372 init_task.work);
2373 struct net_device *netdev = adapter->netdev;
5eae00c5
GR
2374 struct i40e_hw *hw = &adapter->hw;
2375 struct pci_dev *pdev = adapter->pdev;
e6d038de 2376 int err, bufsz;
5eae00c5
GR
2377
2378 switch (adapter->state) {
2379 case __I40EVF_STARTUP:
2380 /* driver loaded, probe complete */
ef8693eb
MW
2381 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
2382 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
5eae00c5
GR
2383 err = i40e_set_mac_type(hw);
2384 if (err) {
c2a137cb
MW
2385 dev_err(&pdev->dev, "Failed to set MAC type (%d)\n",
2386 err);
2619ef47 2387 goto err;
5eae00c5
GR
2388 }
2389 err = i40evf_check_reset_complete(hw);
2390 if (err) {
0d9c7ea8 2391 dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n",
75a64435 2392 err);
5eae00c5
GR
2393 goto err;
2394 }
2395 hw->aq.num_arq_entries = I40EVF_AQ_LEN;
2396 hw->aq.num_asq_entries = I40EVF_AQ_LEN;
2397 hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2398 hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2399
2400 err = i40evf_init_adminq(hw);
2401 if (err) {
c2a137cb
MW
2402 dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n",
2403 err);
5eae00c5
GR
2404 goto err;
2405 }
2406 err = i40evf_send_api_ver(adapter);
2407 if (err) {
10bdd67b 2408 dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err);
5eae00c5
GR
2409 i40evf_shutdown_adminq(hw);
2410 goto err;
2411 }
2412 adapter->state = __I40EVF_INIT_VERSION_CHECK;
2413 goto restart;
5eae00c5 2414 case __I40EVF_INIT_VERSION_CHECK:
10bdd67b 2415 if (!i40evf_asq_done(hw)) {
80e72893 2416 dev_err(&pdev->dev, "Admin queue command never completed\n");
906a6937
MW
2417 i40evf_shutdown_adminq(hw);
2418 adapter->state = __I40EVF_STARTUP;
5eae00c5 2419 goto err;
10bdd67b 2420 }
5eae00c5
GR
2421
2422 /* aq msg sent, awaiting reply */
2423 err = i40evf_verify_api_ver(adapter);
2424 if (err) {
d4f82fd3 2425 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
56f9920a 2426 err = i40evf_send_api_ver(adapter);
ee1693e5
MW
2427 else
2428 dev_err(&pdev->dev, "Unsupported PF API version %d.%d, expected %d.%d\n",
2429 adapter->pf_version.major,
2430 adapter->pf_version.minor,
2431 I40E_VIRTCHNL_VERSION_MAJOR,
2432 I40E_VIRTCHNL_VERSION_MINOR);
5eae00c5
GR
2433 goto err;
2434 }
2435 err = i40evf_send_vf_config_msg(adapter);
2436 if (err) {
3f2ab172 2437 dev_err(&pdev->dev, "Unable to send config request (%d)\n",
5eae00c5
GR
2438 err);
2439 goto err;
2440 }
2441 adapter->state = __I40EVF_INIT_GET_RESOURCES;
2442 goto restart;
5eae00c5
GR
2443 case __I40EVF_INIT_GET_RESOURCES:
2444 /* aq msg sent, awaiting reply */
2445 if (!adapter->vf_res) {
2446 bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
2447 (I40E_MAX_VF_VSI *
2448 sizeof(struct i40e_virtchnl_vsi_resource));
2449 adapter->vf_res = kzalloc(bufsz, GFP_KERNEL);
c2a137cb 2450 if (!adapter->vf_res)
5eae00c5 2451 goto err;
5eae00c5
GR
2452 }
2453 err = i40evf_get_vf_config(adapter);
906a6937 2454 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) {
906a6937
MW
2455 err = i40evf_send_vf_config_msg(adapter);
2456 goto err;
e743072f
MW
2457 } else if (err == I40E_ERR_PARAM) {
2458 /* We only get ERR_PARAM if the device is in a very bad
2459 * state or if we've been disabled for previous bad
2460 * behavior. Either way, we're done now.
2461 */
2462 i40evf_shutdown_adminq(hw);
2463 dev_err(&pdev->dev, "Unable to get VF config due to PF error condition, not retrying\n");
2464 return;
906a6937 2465 }
5eae00c5 2466 if (err) {
c2a137cb
MW
2467 dev_err(&pdev->dev, "Unable to get VF config (%d)\n",
2468 err);
5eae00c5
GR
2469 goto err_alloc;
2470 }
2471 adapter->state = __I40EVF_INIT_SW;
2472 break;
2473 default:
2474 goto err_alloc;
2475 }
e6d038de 2476 if (i40evf_process_config(adapter))
5eae00c5 2477 goto err_alloc;
e6d038de 2478 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
5eae00c5
GR
2479
2480 adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED;
2481
5eae00c5
GR
2482 netdev->netdev_ops = &i40evf_netdev_ops;
2483 i40evf_set_ethtool_ops(netdev);
2484 netdev->watchdog_timeo = 5 * HZ;
3415e8ce 2485
5eae00c5 2486 if (!is_valid_ether_addr(adapter->hw.mac.addr)) {
b34f90e7 2487 dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n",
c2a137cb 2488 adapter->hw.mac.addr);
14e52ee2
MW
2489 eth_hw_addr_random(netdev);
2490 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2491 } else {
2492 adapter->flags |= I40EVF_FLAG_ADDR_SET_BY_PF;
2493 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
2494 ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr);
5eae00c5 2495 }
5eae00c5 2496
5eae00c5
GR
2497 init_timer(&adapter->watchdog_timer);
2498 adapter->watchdog_timer.function = &i40evf_watchdog_timer;
2499 adapter->watchdog_timer.data = (unsigned long)adapter;
2500 mod_timer(&adapter->watchdog_timer, jiffies + 1);
2501
cc052927
MW
2502 adapter->num_active_queues = min_t(int,
2503 adapter->vsi_res->num_queue_pairs,
2504 (int)(num_online_cpus()));
d732a184
MW
2505 adapter->tx_desc_count = I40EVF_DEFAULT_TXD;
2506 adapter->rx_desc_count = I40EVF_DEFAULT_RXD;
5eae00c5
GR
2507 err = i40evf_init_interrupt_scheme(adapter);
2508 if (err)
2509 goto err_sw_init;
2510 i40evf_map_rings_to_vectors(adapter);
1f012279
ASJ
2511 if (adapter->vf_res->vf_offload_flags &
2512 I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
2513 adapter->flags |= I40EVF_FLAG_WB_ON_ITR_CAPABLE;
5eae00c5
GR
2514 err = i40evf_request_misc_irq(adapter);
2515 if (err)
2516 goto err_sw_init;
2517
2518 netif_carrier_off(netdev);
2519
ef8693eb
MW
2520 if (!adapter->netdev_registered) {
2521 err = register_netdev(netdev);
2522 if (err)
2523 goto err_register;
2524 }
5eae00c5
GR
2525
2526 adapter->netdev_registered = true;
2527
2528 netif_tx_stop_all_queues(netdev);
2529
b34f90e7 2530 dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr);
5eae00c5
GR
2531 if (netdev->features & NETIF_F_GRO)
2532 dev_info(&pdev->dev, "GRO is enabled\n");
2533
5eae00c5
GR
2534 adapter->state = __I40EVF_DOWN;
2535 set_bit(__I40E_DOWN, &adapter->vsi.state);
2536 i40evf_misc_irq_enable(adapter);
e25d00b8
ASJ
2537
2538 if (RSS_AQ(adapter)) {
2539 adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_RSS;
2540 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
2541 } else {
96a81986 2542 i40evf_init_rss(adapter);
e25d00b8 2543 }
5eae00c5
GR
2544 return;
2545restart:
3f7e5c33 2546 schedule_delayed_work(&adapter->init_task, msecs_to_jiffies(30));
5eae00c5
GR
2547 return;
2548
2549err_register:
2550 i40evf_free_misc_irq(adapter);
2551err_sw_init:
2552 i40evf_reset_interrupt_capability(adapter);
5eae00c5
GR
2553err_alloc:
2554 kfree(adapter->vf_res);
2555 adapter->vf_res = NULL;
2556err:
2557 /* Things went into the weeds, so try again later */
2558 if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) {
b9029e94 2559 dev_err(&pdev->dev, "Failed to communicate with PF; waiting before retry\n");
ef8693eb 2560 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
b9029e94
MW
2561 i40evf_shutdown_adminq(hw);
2562 adapter->state = __I40EVF_STARTUP;
2563 schedule_delayed_work(&adapter->init_task, HZ * 5);
2564 return;
5eae00c5 2565 }
3f7e5c33 2566 schedule_delayed_work(&adapter->init_task, HZ);
5eae00c5
GR
2567}
2568
2569/**
2570 * i40evf_shutdown - Shutdown the device in preparation for a reboot
2571 * @pdev: pci device structure
2572 **/
2573static void i40evf_shutdown(struct pci_dev *pdev)
2574{
2575 struct net_device *netdev = pci_get_drvdata(pdev);
00293fdc 2576 struct i40evf_adapter *adapter = netdev_priv(netdev);
5eae00c5
GR
2577
2578 netif_device_detach(netdev);
2579
2580 if (netif_running(netdev))
2581 i40evf_close(netdev);
2582
00293fdc
MW
2583 /* Prevent the watchdog from running. */
2584 adapter->state = __I40EVF_REMOVE;
2585 adapter->aq_required = 0;
00293fdc 2586
5eae00c5
GR
2587#ifdef CONFIG_PM
2588 pci_save_state(pdev);
2589
2590#endif
2591 pci_disable_device(pdev);
2592}
2593
2594/**
2595 * i40evf_probe - Device Initialization Routine
2596 * @pdev: PCI device information struct
2597 * @ent: entry in i40evf_pci_tbl
2598 *
2599 * Returns 0 on success, negative on failure
2600 *
2601 * i40evf_probe initializes an adapter identified by a pci_dev structure.
2602 * The OS initialization, configuring of the adapter private structure,
2603 * and a hardware reset occur.
2604 **/
2605static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2606{
2607 struct net_device *netdev;
2608 struct i40evf_adapter *adapter = NULL;
2609 struct i40e_hw *hw = NULL;
dbbd8111 2610 int err;
5eae00c5
GR
2611
2612 err = pci_enable_device(pdev);
2613 if (err)
2614 return err;
2615
6494294f 2616 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
6494294f 2617 if (err) {
e3e3bfdd
JS
2618 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2619 if (err) {
2620 dev_err(&pdev->dev,
2621 "DMA configuration failed: 0x%x\n", err);
2622 goto err_dma;
2623 }
5eae00c5
GR
2624 }
2625
2626 err = pci_request_regions(pdev, i40evf_driver_name);
2627 if (err) {
2628 dev_err(&pdev->dev,
2629 "pci_request_regions failed 0x%x\n", err);
2630 goto err_pci_reg;
2631 }
2632
2633 pci_enable_pcie_error_reporting(pdev);
2634
2635 pci_set_master(pdev);
2636
1255b7a1 2637 netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter), MAX_QUEUES);
5eae00c5
GR
2638 if (!netdev) {
2639 err = -ENOMEM;
2640 goto err_alloc_etherdev;
2641 }
2642
2643 SET_NETDEV_DEV(netdev, &pdev->dev);
2644
2645 pci_set_drvdata(pdev, netdev);
2646 adapter = netdev_priv(netdev);
5eae00c5
GR
2647
2648 adapter->netdev = netdev;
2649 adapter->pdev = pdev;
2650
2651 hw = &adapter->hw;
2652 hw->back = adapter;
2653
41a1d04b 2654 adapter->msg_enable = BIT(DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
5eae00c5
GR
2655 adapter->state = __I40EVF_STARTUP;
2656
2657 /* Call save state here because it relies on the adapter struct. */
2658 pci_save_state(pdev);
2659
2660 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2661 pci_resource_len(pdev, 0));
2662 if (!hw->hw_addr) {
2663 err = -EIO;
2664 goto err_ioremap;
2665 }
2666 hw->vendor_id = pdev->vendor;
2667 hw->device_id = pdev->device;
2668 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2669 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2670 hw->subsystem_device_id = pdev->subsystem_device;
2671 hw->bus.device = PCI_SLOT(pdev->devfn);
2672 hw->bus.func = PCI_FUNC(pdev->devfn);
2673
8ddb3326
JB
2674 /* set up the locks for the AQ, do this only once in probe
2675 * and destroy them only once in remove
2676 */
2677 mutex_init(&hw->aq.asq_mutex);
2678 mutex_init(&hw->aq.arq_mutex);
2679
8bb1a540
SK
2680 INIT_LIST_HEAD(&adapter->mac_filter_list);
2681 INIT_LIST_HEAD(&adapter->vlan_filter_list);
2682
5eae00c5
GR
2683 INIT_WORK(&adapter->reset_task, i40evf_reset_task);
2684 INIT_WORK(&adapter->adminq_task, i40evf_adminq_task);
2685 INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task);
2686 INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task);
9b32b0b5
MW
2687 schedule_delayed_work(&adapter->init_task,
2688 msecs_to_jiffies(5 * (pdev->devfn & 0x07)));
5eae00c5
GR
2689
2690 return 0;
2691
2692err_ioremap:
2693 free_netdev(netdev);
2694err_alloc_etherdev:
2695 pci_release_regions(pdev);
2696err_pci_reg:
2697err_dma:
2698 pci_disable_device(pdev);
2699 return err;
2700}
2701
2702#ifdef CONFIG_PM
2703/**
2704 * i40evf_suspend - Power management suspend routine
2705 * @pdev: PCI device information struct
2706 * @state: unused
2707 *
2708 * Called when the system (VM) is entering sleep/suspend.
2709 **/
2710static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state)
2711{
2712 struct net_device *netdev = pci_get_drvdata(pdev);
2713 struct i40evf_adapter *adapter = netdev_priv(netdev);
2714 int retval = 0;
2715
2716 netif_device_detach(netdev);
2717
2718 if (netif_running(netdev)) {
2719 rtnl_lock();
2720 i40evf_down(adapter);
2721 rtnl_unlock();
2722 }
2723 i40evf_free_misc_irq(adapter);
2724 i40evf_reset_interrupt_capability(adapter);
2725
2726 retval = pci_save_state(pdev);
2727 if (retval)
2728 return retval;
2729
2730 pci_disable_device(pdev);
2731
2732 return 0;
2733}
2734
2735/**
dbedd44e 2736 * i40evf_resume - Power management resume routine
5eae00c5
GR
2737 * @pdev: PCI device information struct
2738 *
2739 * Called when the system (VM) is resumed from sleep/suspend.
2740 **/
2741static int i40evf_resume(struct pci_dev *pdev)
2742{
2743 struct i40evf_adapter *adapter = pci_get_drvdata(pdev);
2744 struct net_device *netdev = adapter->netdev;
2745 u32 err;
2746
2747 pci_set_power_state(pdev, PCI_D0);
2748 pci_restore_state(pdev);
2749 /* pci_restore_state clears dev->state_saved so call
2750 * pci_save_state to restore it.
2751 */
2752 pci_save_state(pdev);
2753
2754 err = pci_enable_device_mem(pdev);
2755 if (err) {
2756 dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n");
2757 return err;
2758 }
2759 pci_set_master(pdev);
2760
2761 rtnl_lock();
2762 err = i40evf_set_interrupt_capability(adapter);
2763 if (err) {
f2a1c368 2764 rtnl_unlock();
5eae00c5
GR
2765 dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n");
2766 return err;
2767 }
2768 err = i40evf_request_misc_irq(adapter);
2769 rtnl_unlock();
2770 if (err) {
2771 dev_err(&pdev->dev, "Cannot get interrupt vector.\n");
2772 return err;
2773 }
2774
2775 schedule_work(&adapter->reset_task);
2776
2777 netif_device_attach(netdev);
2778
2779 return err;
2780}
2781
2782#endif /* CONFIG_PM */
2783/**
2784 * i40evf_remove - Device Removal Routine
2785 * @pdev: PCI device information struct
2786 *
2787 * i40evf_remove is called by the PCI subsystem to alert the driver
2788 * that it should release a PCI device. The could be caused by a
2789 * Hot-Plug event, or because the driver is going to be removed from
2790 * memory.
2791 **/
2792static void i40evf_remove(struct pci_dev *pdev)
2793{
2794 struct net_device *netdev = pci_get_drvdata(pdev);
2795 struct i40evf_adapter *adapter = netdev_priv(netdev);
6ba36a24 2796 struct i40evf_mac_filter *f, *ftmp;
5eae00c5
GR
2797 struct i40e_hw *hw = &adapter->hw;
2798
2799 cancel_delayed_work_sync(&adapter->init_task);
ef8693eb 2800 cancel_work_sync(&adapter->reset_task);
5eae00c5
GR
2801
2802 if (adapter->netdev_registered) {
2803 unregister_netdev(netdev);
2804 adapter->netdev_registered = false;
2805 }
53d0b3ae 2806
f4a71881 2807 /* Shut down all the garbage mashers on the detention level */
5eae00c5 2808 adapter->state = __I40EVF_REMOVE;
f4a71881 2809 adapter->aq_required = 0;
f4a71881
MW
2810 i40evf_request_reset(adapter);
2811 msleep(20);
2812 /* If the FW isn't responding, kick it once, but only once. */
2813 if (!i40evf_asq_done(hw)) {
2814 i40evf_request_reset(adapter);
2815 msleep(20);
2816 }
5eae00c5 2817
dbb01c8a 2818 if (adapter->msix_entries) {
5eae00c5 2819 i40evf_misc_irq_disable(adapter);
5eae00c5 2820 i40evf_free_misc_irq(adapter);
5eae00c5 2821 i40evf_reset_interrupt_capability(adapter);
d31944d6 2822 i40evf_free_q_vectors(adapter);
5eae00c5
GR
2823 }
2824
e5d17c3e
MW
2825 if (adapter->watchdog_timer.function)
2826 del_timer_sync(&adapter->watchdog_timer);
2827
dbb01c8a
MW
2828 flush_scheduled_work();
2829
66f9af85
HZ
2830 /* Clear user configurations for RSS */
2831 i40evf_clear_rss_config_user(&adapter->vsi);
2832
5eae00c5
GR
2833 if (hw->aq.asq.count)
2834 i40evf_shutdown_adminq(hw);
2835
8ddb3326
JB
2836 /* destroy the locks only once, here */
2837 mutex_destroy(&hw->aq.arq_mutex);
2838 mutex_destroy(&hw->aq.asq_mutex);
2839
5eae00c5
GR
2840 iounmap(hw->hw_addr);
2841 pci_release_regions(pdev);
2842
e284fc88
MW
2843 i40evf_free_all_tx_resources(adapter);
2844 i40evf_free_all_rx_resources(adapter);
5eae00c5
GR
2845 i40evf_free_queues(adapter);
2846 kfree(adapter->vf_res);
6ba36a24
MW
2847 /* If we got removed before an up/down sequence, we've got a filter
2848 * hanging out there that we need to get rid of.
2849 */
2850 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
2851 list_del(&f->list);
2852 kfree(f);
2853 }
37dfdf37
MW
2854 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
2855 list_del(&f->list);
2856 kfree(f);
2857 }
5eae00c5
GR
2858
2859 free_netdev(netdev);
2860
2861 pci_disable_pcie_error_reporting(pdev);
2862
2863 pci_disable_device(pdev);
2864}
2865
2866static struct pci_driver i40evf_driver = {
2867 .name = i40evf_driver_name,
2868 .id_table = i40evf_pci_tbl,
2869 .probe = i40evf_probe,
2870 .remove = i40evf_remove,
2871#ifdef CONFIG_PM
2872 .suspend = i40evf_suspend,
2873 .resume = i40evf_resume,
2874#endif
2875 .shutdown = i40evf_shutdown,
2876};
2877
2878/**
2879 * i40e_init_module - Driver Registration Routine
2880 *
2881 * i40e_init_module is the first routine called when the driver is
2882 * loaded. All it does is register with the PCI subsystem.
2883 **/
2884static int __init i40evf_init_module(void)
2885{
2886 int ret;
75a64435 2887
5eae00c5 2888 pr_info("i40evf: %s - version %s\n", i40evf_driver_string,
75a64435 2889 i40evf_driver_version);
5eae00c5
GR
2890
2891 pr_info("%s\n", i40evf_copyright);
2892
2893 ret = pci_register_driver(&i40evf_driver);
2894 return ret;
2895}
2896
2897module_init(i40evf_init_module);
2898
2899/**
2900 * i40e_exit_module - Driver Exit Cleanup Routine
2901 *
2902 * i40e_exit_module is called just before the driver is removed
2903 * from memory.
2904 **/
2905static void __exit i40evf_exit_module(void)
2906{
2907 pci_unregister_driver(&i40evf_driver);
2908}
2909
2910module_exit(i40evf_exit_module);
2911
2912/* i40evf_main.c */
This page took 0.348075 seconds and 5 git commands to generate.