i40e: Extend ethtool RSS hooks 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 */
1459 hena = I40E_DEFAULT_RSS_HENA;
1460 wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
1461 wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
1462
2c86ac3c
HZ
1463 lut = kzalloc(I40EVF_HLUT_ARRAY_SIZE, GFP_KERNEL);
1464 if (!lut)
1465 return -ENOMEM;
66f9af85
HZ
1466
1467 /* Use user configured lut if there is one, otherwise use default */
1468 if (vsi->rss_lut_user)
1469 memcpy(lut, vsi->rss_lut_user, I40EVF_HLUT_ARRAY_SIZE);
1470 else
1471 i40evf_fill_rss_lut(lut, I40EVF_HLUT_ARRAY_SIZE,
1472 adapter->num_active_queues);
1473
1474 /* Use user configured hash key if there is one, otherwise
1475 * user default.
1476 */
1477 if (vsi->rss_hkey_user)
1478 memcpy(seed, vsi->rss_hkey_user, I40EVF_HKEY_ARRAY_SIZE);
1479 else
1480 netdev_rss_key_fill((void *)seed, I40EVF_HKEY_ARRAY_SIZE);
2c86ac3c
HZ
1481 ret = i40evf_config_rss(vsi, seed, lut, I40EVF_HLUT_ARRAY_SIZE);
1482 kfree(lut);
1483
1484 return ret;
e25d00b8
ASJ
1485}
1486
5eae00c5
GR
1487/**
1488 * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
1489 * @adapter: board private structure to initialize
1490 *
1491 * We allocate one q_vector per queue interrupt. If allocation fails we
1492 * return -ENOMEM.
1493 **/
1494static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter)
1495{
7d96ba1a 1496 int q_idx = 0, num_q_vectors;
5eae00c5
GR
1497 struct i40e_q_vector *q_vector;
1498
1499 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
0dd438d8 1500 adapter->q_vectors = kcalloc(num_q_vectors, sizeof(*q_vector),
7d96ba1a
MW
1501 GFP_KERNEL);
1502 if (!adapter->q_vectors)
1503 goto err_out;
5eae00c5
GR
1504
1505 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
7d96ba1a 1506 q_vector = &adapter->q_vectors[q_idx];
5eae00c5
GR
1507 q_vector->adapter = adapter;
1508 q_vector->vsi = &adapter->vsi;
1509 q_vector->v_idx = q_idx;
1510 netif_napi_add(adapter->netdev, &q_vector->napi,
75a64435 1511 i40evf_napi_poll, NAPI_POLL_WEIGHT);
5eae00c5
GR
1512 }
1513
1514 return 0;
1515
1516err_out:
1517 while (q_idx) {
1518 q_idx--;
7d96ba1a 1519 q_vector = &adapter->q_vectors[q_idx];
5eae00c5 1520 netif_napi_del(&q_vector->napi);
5eae00c5 1521 }
7d96ba1a 1522 kfree(adapter->q_vectors);
5eae00c5
GR
1523 return -ENOMEM;
1524}
1525
1526/**
1527 * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
1528 * @adapter: board private structure to initialize
1529 *
1530 * This function frees the memory allocated to the q_vectors. In addition if
1531 * NAPI is enabled it will delete any references to the NAPI struct prior
1532 * to freeing the q_vector.
1533 **/
1534static void i40evf_free_q_vectors(struct i40evf_adapter *adapter)
1535{
1536 int q_idx, num_q_vectors;
1537 int napi_vectors;
1538
1539 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
cc052927 1540 napi_vectors = adapter->num_active_queues;
5eae00c5
GR
1541
1542 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
7d96ba1a 1543 struct i40e_q_vector *q_vector = &adapter->q_vectors[q_idx];
5eae00c5
GR
1544 if (q_idx < napi_vectors)
1545 netif_napi_del(&q_vector->napi);
5eae00c5 1546 }
7d96ba1a 1547 kfree(adapter->q_vectors);
5eae00c5
GR
1548}
1549
1550/**
1551 * i40evf_reset_interrupt_capability - Reset MSIX setup
1552 * @adapter: board private structure
1553 *
1554 **/
1555void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter)
1556{
1557 pci_disable_msix(adapter->pdev);
1558 kfree(adapter->msix_entries);
1559 adapter->msix_entries = NULL;
5eae00c5
GR
1560}
1561
1562/**
1563 * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
1564 * @adapter: board private structure to initialize
1565 *
1566 **/
1567int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter)
1568{
1569 int err;
1570
1571 err = i40evf_set_interrupt_capability(adapter);
1572 if (err) {
1573 dev_err(&adapter->pdev->dev,
1574 "Unable to setup interrupt capabilities\n");
1575 goto err_set_interrupt;
1576 }
1577
1578 err = i40evf_alloc_q_vectors(adapter);
1579 if (err) {
1580 dev_err(&adapter->pdev->dev,
1581 "Unable to allocate memory for queue vectors\n");
1582 goto err_alloc_q_vectors;
1583 }
1584
1585 err = i40evf_alloc_queues(adapter);
1586 if (err) {
1587 dev_err(&adapter->pdev->dev,
1588 "Unable to allocate memory for queues\n");
1589 goto err_alloc_queues;
1590 }
1591
1592 dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u",
75a64435
MW
1593 (adapter->num_active_queues > 1) ? "Enabled" : "Disabled",
1594 adapter->num_active_queues);
5eae00c5
GR
1595
1596 return 0;
1597err_alloc_queues:
1598 i40evf_free_q_vectors(adapter);
1599err_alloc_q_vectors:
1600 i40evf_reset_interrupt_capability(adapter);
1601err_set_interrupt:
1602 return err;
1603}
1604
66f9af85
HZ
1605/**
1606 * i40evf_clear_rss_config_user - Clear user configurations of RSS
1607 * @vsi: Pointer to VSI structure
1608 **/
1609static void i40evf_clear_rss_config_user(struct i40e_vsi *vsi)
1610{
1611 if (!vsi)
1612 return;
1613
1614 kfree(vsi->rss_hkey_user);
1615 vsi->rss_hkey_user = NULL;
1616
1617 kfree(vsi->rss_lut_user);
1618 vsi->rss_lut_user = NULL;
1619}
1620
5eae00c5
GR
1621/**
1622 * i40evf_watchdog_timer - Periodic call-back timer
1623 * @data: pointer to adapter disguised as unsigned long
1624 **/
1625static void i40evf_watchdog_timer(unsigned long data)
1626{
1627 struct i40evf_adapter *adapter = (struct i40evf_adapter *)data;
75a64435 1628
5eae00c5
GR
1629 schedule_work(&adapter->watchdog_task);
1630 /* timer will be rescheduled in watchdog task */
1631}
1632
1633/**
1634 * i40evf_watchdog_task - Periodic call-back task
1635 * @work: pointer to work_struct
1636 **/
1637static void i40evf_watchdog_task(struct work_struct *work)
1638{
1639 struct i40evf_adapter *adapter = container_of(work,
75a64435
MW
1640 struct i40evf_adapter,
1641 watchdog_task);
5eae00c5 1642 struct i40e_hw *hw = &adapter->hw;
ee5c1e92 1643 u32 reg_val;
5eae00c5 1644
ef8693eb
MW
1645 if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section))
1646 goto restart_watchdog;
1647
1648 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
ee5c1e92
MW
1649 reg_val = rd32(hw, I40E_VFGEN_RSTAT) &
1650 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1651 if ((reg_val == I40E_VFR_VFACTIVE) ||
1652 (reg_val == I40E_VFR_COMPLETED)) {
ef8693eb
MW
1653 /* A chance for redemption! */
1654 dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n");
1655 adapter->state = __I40EVF_STARTUP;
1656 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
1657 schedule_delayed_work(&adapter->init_task, 10);
1658 clear_bit(__I40EVF_IN_CRITICAL_TASK,
1659 &adapter->crit_section);
1660 /* Don't reschedule the watchdog, since we've restarted
1661 * the init task. When init_task contacts the PF and
1662 * gets everything set up again, it'll restart the
1663 * watchdog for us. Down, boy. Sit. Stay. Woof.
1664 */
1665 return;
1666 }
ef8693eb
MW
1667 adapter->aq_required = 0;
1668 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
5eae00c5 1669 goto watchdog_done;
ef8693eb 1670 }
5eae00c5 1671
ef8693eb
MW
1672 if ((adapter->state < __I40EVF_DOWN) ||
1673 (adapter->flags & I40EVF_FLAG_RESET_PENDING))
5eae00c5
GR
1674 goto watchdog_done;
1675
ef8693eb 1676 /* check for reset */
ee5c1e92
MW
1677 reg_val = rd32(hw, I40E_VF_ARQLEN1) & I40E_VF_ARQLEN1_ARQENABLE_MASK;
1678 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) && !reg_val) {
5eae00c5 1679 adapter->state = __I40EVF_RESETTING;
ef8693eb 1680 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
249c8b8d 1681 dev_err(&adapter->pdev->dev, "Hardware reset detected\n");
5eae00c5 1682 schedule_work(&adapter->reset_task);
ef8693eb
MW
1683 adapter->aq_required = 0;
1684 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
5eae00c5
GR
1685 goto watchdog_done;
1686 }
1687
1688 /* Process admin queue tasks. After init, everything gets done
1689 * here so we don't race on the admin queue.
1690 */
ed636960 1691 if (adapter->current_op) {
0758e7cb
MW
1692 if (!i40evf_asq_done(hw)) {
1693 dev_dbg(&adapter->pdev->dev, "Admin queue timeout\n");
1694 i40evf_send_api_ver(adapter);
1695 }
5eae00c5 1696 goto watchdog_done;
0758e7cb 1697 }
e6d038de
MW
1698 if (adapter->aq_required & I40EVF_FLAG_AQ_GET_CONFIG) {
1699 i40evf_send_vf_config_msg(adapter);
1700 goto watchdog_done;
1701 }
5eae00c5 1702
e284fc88
MW
1703 if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) {
1704 i40evf_disable_queues(adapter);
1705 goto watchdog_done;
1706 }
1707
5eae00c5
GR
1708 if (adapter->aq_required & I40EVF_FLAG_AQ_MAP_VECTORS) {
1709 i40evf_map_queues(adapter);
1710 goto watchdog_done;
1711 }
1712
1713 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_MAC_FILTER) {
1714 i40evf_add_ether_addrs(adapter);
1715 goto watchdog_done;
1716 }
1717
1718 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_VLAN_FILTER) {
1719 i40evf_add_vlans(adapter);
1720 goto watchdog_done;
1721 }
1722
1723 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_MAC_FILTER) {
1724 i40evf_del_ether_addrs(adapter);
1725 goto watchdog_done;
1726 }
1727
1728 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_VLAN_FILTER) {
1729 i40evf_del_vlans(adapter);
1730 goto watchdog_done;
1731 }
1732
5eae00c5
GR
1733 if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_QUEUES) {
1734 i40evf_configure_queues(adapter);
1735 goto watchdog_done;
1736 }
1737
1738 if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_QUEUES) {
1739 i40evf_enable_queues(adapter);
1740 goto watchdog_done;
1741 }
1742
e25d00b8
ASJ
1743 if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_RSS) {
1744 /* This message goes straight to the firmware, not the
1745 * PF, so we don't have to set current_op as we will
1746 * not get a response through the ARQ.
1747 */
96a81986 1748 i40evf_init_rss(adapter);
e25d00b8
ASJ
1749 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_RSS;
1750 goto watchdog_done;
1751 }
1752
5eae00c5
GR
1753 if (adapter->state == __I40EVF_RUNNING)
1754 i40evf_request_stats(adapter);
5eae00c5 1755watchdog_done:
4870e176
MW
1756 if (adapter->state == __I40EVF_RUNNING) {
1757 i40evf_irq_enable_queues(adapter, ~0);
1758 i40evf_fire_sw_int(adapter, 0xFF);
1759 } else {
1760 i40evf_fire_sw_int(adapter, 0x1);
1761 }
1762
ef8693eb
MW
1763 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1764restart_watchdog:
d3e2edb7
AS
1765 if (adapter->state == __I40EVF_REMOVE)
1766 return;
5eae00c5
GR
1767 if (adapter->aq_required)
1768 mod_timer(&adapter->watchdog_timer,
1769 jiffies + msecs_to_jiffies(20));
1770 else
1771 mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2));
5eae00c5
GR
1772 schedule_work(&adapter->adminq_task);
1773}
1774
67c818a1
MW
1775#define I40EVF_RESET_WAIT_MS 10
1776#define I40EVF_RESET_WAIT_COUNT 500
5eae00c5
GR
1777/**
1778 * i40evf_reset_task - Call-back task to handle hardware reset
1779 * @work: pointer to work_struct
1780 *
1781 * During reset we need to shut down and reinitialize the admin queue
1782 * before we can use it to communicate with the PF again. We also clear
1783 * and reinit the rings because that context is lost as well.
1784 **/
1785static void i40evf_reset_task(struct work_struct *work)
1786{
ef8693eb
MW
1787 struct i40evf_adapter *adapter = container_of(work,
1788 struct i40evf_adapter,
1789 reset_task);
ac833bbf 1790 struct net_device *netdev = adapter->netdev;
5eae00c5 1791 struct i40e_hw *hw = &adapter->hw;
40d01366 1792 struct i40evf_vlan_filter *vlf;
ac833bbf 1793 struct i40evf_mac_filter *f;
ee5c1e92 1794 u32 reg_val;
ac833bbf 1795 int i = 0, err;
5eae00c5
GR
1796
1797 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
1798 &adapter->crit_section))
f98a2006 1799 usleep_range(500, 1000);
3526d800 1800
67c818a1 1801 i40evf_misc_irq_disable(adapter);
3526d800 1802 if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) {
67c818a1
MW
1803 adapter->flags &= ~I40EVF_FLAG_RESET_NEEDED;
1804 /* Restart the AQ here. If we have been reset but didn't
1805 * detect it, or if the PF had to reinit, our AQ will be hosed.
1806 */
1807 i40evf_shutdown_adminq(hw);
1808 i40evf_init_adminq(hw);
3526d800
MW
1809 i40evf_request_reset(adapter);
1810 }
67c818a1 1811 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
3526d800 1812
ef8693eb
MW
1813 /* poll until we see the reset actually happen */
1814 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
ee5c1e92
MW
1815 reg_val = rd32(hw, I40E_VF_ARQLEN1) &
1816 I40E_VF_ARQLEN1_ARQENABLE_MASK;
1817 if (!reg_val)
ef8693eb 1818 break;
ee5c1e92 1819 usleep_range(5000, 10000);
ef8693eb
MW
1820 }
1821 if (i == I40EVF_RESET_WAIT_COUNT) {
67c818a1 1822 dev_info(&adapter->pdev->dev, "Never saw reset\n");
ef8693eb
MW
1823 goto continue_reset; /* act like the reset happened */
1824 }
5eae00c5 1825
ef8693eb
MW
1826 /* wait until the reset is complete and the PF is responding to us */
1827 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
ee5c1e92
MW
1828 reg_val = rd32(hw, I40E_VFGEN_RSTAT) &
1829 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1830 if (reg_val == I40E_VFR_VFACTIVE)
5eae00c5 1831 break;
c88e38cc 1832 msleep(I40EVF_RESET_WAIT_MS);
5eae00c5 1833 }
67c818a1
MW
1834 /* extra wait to make sure minimum wait is met */
1835 msleep(I40EVF_RESET_WAIT_MS);
ef8693eb 1836 if (i == I40EVF_RESET_WAIT_COUNT) {
874d1a10 1837 struct i40evf_mac_filter *ftmp;
6ba36a24
MW
1838 struct i40evf_vlan_filter *fv, *fvtmp;
1839
5eae00c5 1840 /* reset never finished */
80e72893 1841 dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n",
ee5c1e92 1842 reg_val);
ef8693eb
MW
1843 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
1844
169f4076
MW
1845 if (netif_running(adapter->netdev)) {
1846 set_bit(__I40E_DOWN, &adapter->vsi.state);
ac833bbf 1847 netif_carrier_off(netdev);
67c818a1
MW
1848 netif_tx_disable(netdev);
1849 i40evf_napi_disable_all(adapter);
1850 i40evf_irq_disable(adapter);
169f4076
MW
1851 i40evf_free_traffic_irqs(adapter);
1852 i40evf_free_all_tx_resources(adapter);
1853 i40evf_free_all_rx_resources(adapter);
1854 }
6ba36a24
MW
1855
1856 /* Delete all of the filters, both MAC and VLAN. */
1857 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list,
1858 list) {
1859 list_del(&f->list);
1860 kfree(f);
1861 }
67c818a1 1862
6ba36a24
MW
1863 list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list,
1864 list) {
1865 list_del(&fv->list);
1866 kfree(fv);
1867 }
1868
ef8693eb
MW
1869 i40evf_free_misc_irq(adapter);
1870 i40evf_reset_interrupt_capability(adapter);
1871 i40evf_free_queues(adapter);
d31944d6 1872 i40evf_free_q_vectors(adapter);
ef8693eb
MW
1873 kfree(adapter->vf_res);
1874 i40evf_shutdown_adminq(hw);
1875 adapter->netdev->flags &= ~IFF_UP;
1876 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
67c818a1
MW
1877 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1878 dev_info(&adapter->pdev->dev, "Reset task did not complete, VF disabled\n");
ef8693eb 1879 return; /* Do not attempt to reinit. It's dead, Jim. */
5eae00c5 1880 }
ef8693eb
MW
1881
1882continue_reset:
3c8e0b98 1883 if (netif_running(adapter->netdev)) {
3c8e0b98 1884 netif_carrier_off(netdev);
67c818a1
MW
1885 netif_tx_stop_all_queues(netdev);
1886 i40evf_napi_disable_all(adapter);
3c8e0b98 1887 }
67c818a1 1888 i40evf_irq_disable(adapter);
ac833bbf 1889
5eae00c5 1890 adapter->state = __I40EVF_RESETTING;
67c818a1
MW
1891 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1892
1893 /* free the Tx/Rx rings and descriptors, might be better to just
1894 * re-use them sometime in the future
1895 */
1896 i40evf_free_all_rx_resources(adapter);
1897 i40evf_free_all_tx_resources(adapter);
5eae00c5
GR
1898
1899 /* kill and reinit the admin queue */
1900 if (i40evf_shutdown_adminq(hw))
ac833bbf
MW
1901 dev_warn(&adapter->pdev->dev, "Failed to shut down adminq\n");
1902 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
5eae00c5
GR
1903 err = i40evf_init_adminq(hw);
1904 if (err)
ac833bbf
MW
1905 dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n",
1906 err);
5eae00c5 1907
e6d038de
MW
1908 adapter->aq_required = I40EVF_FLAG_AQ_GET_CONFIG;
1909 adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
ac833bbf
MW
1910
1911 /* re-add all MAC filters */
1912 list_for_each_entry(f, &adapter->mac_filter_list, list) {
1913 f->add = true;
1914 }
1915 /* re-add all VLAN filters */
40d01366
MW
1916 list_for_each_entry(vlf, &adapter->vlan_filter_list, list) {
1917 vlf->add = true;
ac833bbf 1918 }
e6d038de 1919 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
ac833bbf 1920 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
5eae00c5 1921 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
67c818a1 1922 i40evf_misc_irq_enable(adapter);
5eae00c5
GR
1923
1924 mod_timer(&adapter->watchdog_timer, jiffies + 2);
1925
1926 if (netif_running(adapter->netdev)) {
1927 /* allocate transmit descriptors */
1928 err = i40evf_setup_all_tx_resources(adapter);
1929 if (err)
1930 goto reset_err;
1931
1932 /* allocate receive descriptors */
1933 err = i40evf_setup_all_rx_resources(adapter);
1934 if (err)
1935 goto reset_err;
1936
1937 i40evf_configure(adapter);
1938
1939 err = i40evf_up_complete(adapter);
1940 if (err)
1941 goto reset_err;
1942
1943 i40evf_irq_enable(adapter, true);
67c818a1
MW
1944 } else {
1945 adapter->state = __I40EVF_DOWN;
5eae00c5 1946 }
67c818a1 1947
5eae00c5
GR
1948 return;
1949reset_err:
80e72893 1950 dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
5eae00c5
GR
1951 i40evf_close(adapter->netdev);
1952}
1953
1954/**
1955 * i40evf_adminq_task - worker thread to clean the admin queue
1956 * @work: pointer to work_struct containing our data
1957 **/
1958static void i40evf_adminq_task(struct work_struct *work)
1959{
1960 struct i40evf_adapter *adapter =
1961 container_of(work, struct i40evf_adapter, adminq_task);
1962 struct i40e_hw *hw = &adapter->hw;
1963 struct i40e_arq_event_info event;
1964 struct i40e_virtchnl_msg *v_msg;
1965 i40e_status ret;
912257e5 1966 u32 val, oldval;
5eae00c5
GR
1967 u16 pending;
1968
ef8693eb 1969 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
7235448c 1970 goto out;
ef8693eb 1971
1001dc37
MW
1972 event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
1973 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
249c8b8d 1974 if (!event.msg_buf)
7235448c 1975 goto out;
249c8b8d 1976
5eae00c5
GR
1977 v_msg = (struct i40e_virtchnl_msg *)&event.desc;
1978 do {
1979 ret = i40evf_clean_arq_element(hw, &event, &pending);
8b011ebb 1980 if (ret || !v_msg->v_opcode)
5eae00c5
GR
1981 break; /* No event to process or error cleaning ARQ */
1982
1983 i40evf_virtchnl_completion(adapter, v_msg->v_opcode,
1984 v_msg->v_retval, event.msg_buf,
1001dc37 1985 event.msg_len);
75a64435 1986 if (pending != 0)
5eae00c5 1987 memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE);
5eae00c5
GR
1988 } while (pending);
1989
67c818a1
MW
1990 if ((adapter->flags &
1991 (I40EVF_FLAG_RESET_PENDING | I40EVF_FLAG_RESET_NEEDED)) ||
1992 adapter->state == __I40EVF_RESETTING)
1993 goto freedom;
1994
912257e5
MW
1995 /* check for error indications */
1996 val = rd32(hw, hw->aq.arq.len);
1997 oldval = val;
b1f3366b 1998 if (val & I40E_VF_ARQLEN1_ARQVFE_MASK) {
912257e5 1999 dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n");
b1f3366b 2000 val &= ~I40E_VF_ARQLEN1_ARQVFE_MASK;
912257e5 2001 }
b1f3366b 2002 if (val & I40E_VF_ARQLEN1_ARQOVFL_MASK) {
912257e5 2003 dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n");
b1f3366b 2004 val &= ~I40E_VF_ARQLEN1_ARQOVFL_MASK;
912257e5 2005 }
b1f3366b 2006 if (val & I40E_VF_ARQLEN1_ARQCRIT_MASK) {
912257e5 2007 dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n");
b1f3366b 2008 val &= ~I40E_VF_ARQLEN1_ARQCRIT_MASK;
912257e5
MW
2009 }
2010 if (oldval != val)
2011 wr32(hw, hw->aq.arq.len, val);
2012
2013 val = rd32(hw, hw->aq.asq.len);
2014 oldval = val;
b1f3366b 2015 if (val & I40E_VF_ATQLEN1_ATQVFE_MASK) {
912257e5 2016 dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n");
b1f3366b 2017 val &= ~I40E_VF_ATQLEN1_ATQVFE_MASK;
912257e5 2018 }
b1f3366b 2019 if (val & I40E_VF_ATQLEN1_ATQOVFL_MASK) {
912257e5 2020 dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n");
b1f3366b 2021 val &= ~I40E_VF_ATQLEN1_ATQOVFL_MASK;
912257e5 2022 }
b1f3366b 2023 if (val & I40E_VF_ATQLEN1_ATQCRIT_MASK) {
912257e5 2024 dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n");
b1f3366b 2025 val &= ~I40E_VF_ATQLEN1_ATQCRIT_MASK;
912257e5
MW
2026 }
2027 if (oldval != val)
2028 wr32(hw, hw->aq.asq.len, val);
2029
67c818a1 2030freedom:
7235448c
MW
2031 kfree(event.msg_buf);
2032out:
5eae00c5
GR
2033 /* re-enable Admin queue interrupt cause */
2034 i40evf_misc_irq_enable(adapter);
5eae00c5
GR
2035}
2036
2037/**
2038 * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
2039 * @adapter: board private structure
2040 *
2041 * Free all transmit software resources
2042 **/
e284fc88 2043void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter)
5eae00c5
GR
2044{
2045 int i;
2046
fdb47ae8
MW
2047 if (!adapter->tx_rings)
2048 return;
2049
cc052927 2050 for (i = 0; i < adapter->num_active_queues; i++)
0dd438d8
MW
2051 if (adapter->tx_rings[i].desc)
2052 i40evf_free_tx_resources(&adapter->tx_rings[i]);
5eae00c5
GR
2053}
2054
2055/**
2056 * i40evf_setup_all_tx_resources - allocate all queues Tx resources
2057 * @adapter: board private structure
2058 *
2059 * If this function returns with an error, then it's possible one or
2060 * more of the rings is populated (while the rest are not). It is the
2061 * callers duty to clean those orphaned rings.
2062 *
2063 * Return 0 on success, negative on failure
2064 **/
2065static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter)
2066{
2067 int i, err = 0;
2068
cc052927 2069 for (i = 0; i < adapter->num_active_queues; i++) {
0dd438d8
MW
2070 adapter->tx_rings[i].count = adapter->tx_desc_count;
2071 err = i40evf_setup_tx_descriptors(&adapter->tx_rings[i]);
5eae00c5
GR
2072 if (!err)
2073 continue;
2074 dev_err(&adapter->pdev->dev,
fb43201f 2075 "Allocation for Tx Queue %u failed\n", i);
5eae00c5
GR
2076 break;
2077 }
2078
2079 return err;
2080}
2081
2082/**
2083 * i40evf_setup_all_rx_resources - allocate all queues Rx resources
2084 * @adapter: board private structure
2085 *
2086 * If this function returns with an error, then it's possible one or
2087 * more of the rings is populated (while the rest are not). It is the
2088 * callers duty to clean those orphaned rings.
2089 *
2090 * Return 0 on success, negative on failure
2091 **/
2092static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter)
2093{
2094 int i, err = 0;
2095
cc052927 2096 for (i = 0; i < adapter->num_active_queues; i++) {
0dd438d8
MW
2097 adapter->rx_rings[i].count = adapter->rx_desc_count;
2098 err = i40evf_setup_rx_descriptors(&adapter->rx_rings[i]);
5eae00c5
GR
2099 if (!err)
2100 continue;
2101 dev_err(&adapter->pdev->dev,
fb43201f 2102 "Allocation for Rx Queue %u failed\n", i);
5eae00c5
GR
2103 break;
2104 }
2105 return err;
2106}
2107
2108/**
2109 * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
2110 * @adapter: board private structure
2111 *
2112 * Free all receive software resources
2113 **/
e284fc88 2114void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter)
5eae00c5
GR
2115{
2116 int i;
2117
fdb47ae8
MW
2118 if (!adapter->rx_rings)
2119 return;
2120
cc052927 2121 for (i = 0; i < adapter->num_active_queues; i++)
0dd438d8
MW
2122 if (adapter->rx_rings[i].desc)
2123 i40evf_free_rx_resources(&adapter->rx_rings[i]);
5eae00c5
GR
2124}
2125
2126/**
2127 * i40evf_open - Called when a network interface is made active
2128 * @netdev: network interface device structure
2129 *
2130 * Returns 0 on success, negative value on failure
2131 *
2132 * The open entry point is called when a network interface is made
2133 * active by the system (IFF_UP). At this point all resources needed
2134 * for transmit and receive operations are allocated, the interrupt
2135 * handler is registered with the OS, the watchdog timer is started,
2136 * and the stack is notified that the interface is ready.
2137 **/
2138static int i40evf_open(struct net_device *netdev)
2139{
2140 struct i40evf_adapter *adapter = netdev_priv(netdev);
2141 int err;
2142
ef8693eb
MW
2143 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
2144 dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
2145 return -EIO;
2146 }
209dc4da
MW
2147
2148 if (adapter->state != __I40EVF_DOWN)
5eae00c5
GR
2149 return -EBUSY;
2150
2151 /* allocate transmit descriptors */
2152 err = i40evf_setup_all_tx_resources(adapter);
2153 if (err)
2154 goto err_setup_tx;
2155
2156 /* allocate receive descriptors */
2157 err = i40evf_setup_all_rx_resources(adapter);
2158 if (err)
2159 goto err_setup_rx;
2160
2161 /* clear any pending interrupts, may auto mask */
2162 err = i40evf_request_traffic_irqs(adapter, netdev->name);
2163 if (err)
2164 goto err_req_irq;
2165
44151cd3 2166 i40evf_add_filter(adapter, adapter->hw.mac.addr);
5eae00c5
GR
2167 i40evf_configure(adapter);
2168
2169 err = i40evf_up_complete(adapter);
2170 if (err)
2171 goto err_req_irq;
2172
2173 i40evf_irq_enable(adapter, true);
2174
2175 return 0;
2176
2177err_req_irq:
2178 i40evf_down(adapter);
2179 i40evf_free_traffic_irqs(adapter);
2180err_setup_rx:
2181 i40evf_free_all_rx_resources(adapter);
2182err_setup_tx:
2183 i40evf_free_all_tx_resources(adapter);
2184
2185 return err;
2186}
2187
2188/**
2189 * i40evf_close - Disables a network interface
2190 * @netdev: network interface device structure
2191 *
2192 * Returns 0, this is not allowed to fail
2193 *
2194 * The close entry point is called when an interface is de-activated
2195 * by the OS. The hardware is still under the drivers control, but
2196 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
2197 * are freed, along with all transmit and receive resources.
2198 **/
2199static int i40evf_close(struct net_device *netdev)
2200{
2201 struct i40evf_adapter *adapter = netdev_priv(netdev);
2202
209dc4da 2203 if (adapter->state <= __I40EVF_DOWN_PENDING)
ef8693eb
MW
2204 return 0;
2205
ef8693eb 2206
5eae00c5
GR
2207 set_bit(__I40E_DOWN, &adapter->vsi.state);
2208
2209 i40evf_down(adapter);
209dc4da 2210 adapter->state = __I40EVF_DOWN_PENDING;
5eae00c5
GR
2211 i40evf_free_traffic_irqs(adapter);
2212
5eae00c5
GR
2213 return 0;
2214}
2215
2216/**
2217 * i40evf_get_stats - Get System Network Statistics
2218 * @netdev: network interface device structure
2219 *
2220 * Returns the address of the device statistics structure.
2221 * The statistics are actually updated from the timer callback.
2222 **/
2223static struct net_device_stats *i40evf_get_stats(struct net_device *netdev)
2224{
2225 struct i40evf_adapter *adapter = netdev_priv(netdev);
2226
2227 /* only return the current stats */
2228 return &adapter->net_stats;
2229}
2230
5eae00c5
GR
2231/**
2232 * i40evf_change_mtu - Change the Maximum Transfer Unit
2233 * @netdev: network interface device structure
2234 * @new_mtu: new value for maximum frame size
2235 *
2236 * Returns 0 on success, negative on failure
2237 **/
2238static int i40evf_change_mtu(struct net_device *netdev, int new_mtu)
2239{
2240 struct i40evf_adapter *adapter = netdev_priv(netdev);
2241 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
2242
2243 if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
2244 return -EINVAL;
2245
5eae00c5 2246 netdev->mtu = new_mtu;
67c818a1
MW
2247 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
2248 schedule_work(&adapter->reset_task);
2249
5eae00c5
GR
2250 return 0;
2251}
2252
2253static const struct net_device_ops i40evf_netdev_ops = {
2254 .ndo_open = i40evf_open,
2255 .ndo_stop = i40evf_close,
2256 .ndo_start_xmit = i40evf_xmit_frame,
2257 .ndo_get_stats = i40evf_get_stats,
2258 .ndo_set_rx_mode = i40evf_set_rx_mode,
2259 .ndo_validate_addr = eth_validate_addr,
2260 .ndo_set_mac_address = i40evf_set_mac,
2261 .ndo_change_mtu = i40evf_change_mtu,
2262 .ndo_tx_timeout = i40evf_tx_timeout,
2263 .ndo_vlan_rx_add_vid = i40evf_vlan_rx_add_vid,
2264 .ndo_vlan_rx_kill_vid = i40evf_vlan_rx_kill_vid,
7709b4c1
AD
2265#ifdef CONFIG_NET_POLL_CONTROLLER
2266 .ndo_poll_controller = i40evf_netpoll,
2267#endif
5eae00c5
GR
2268};
2269
2270/**
2271 * i40evf_check_reset_complete - check that VF reset is complete
2272 * @hw: pointer to hw struct
2273 *
2274 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
2275 **/
2276static int i40evf_check_reset_complete(struct i40e_hw *hw)
2277{
2278 u32 rstat;
2279 int i;
2280
2281 for (i = 0; i < 100; i++) {
fd35886a
AS
2282 rstat = rd32(hw, I40E_VFGEN_RSTAT) &
2283 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
2284 if ((rstat == I40E_VFR_VFACTIVE) ||
2285 (rstat == I40E_VFR_COMPLETED))
5eae00c5 2286 return 0;
f98a2006 2287 usleep_range(10, 20);
5eae00c5
GR
2288 }
2289 return -EBUSY;
2290}
2291
e6d038de
MW
2292/**
2293 * i40evf_process_config - Process the config information we got from the PF
2294 * @adapter: board private structure
2295 *
2296 * Verify that we have a valid config struct, and set up our netdev features
2297 * and our VSI struct.
2298 **/
2299int i40evf_process_config(struct i40evf_adapter *adapter)
2300{
2301 struct net_device *netdev = adapter->netdev;
2302 int i;
2303
2304 /* got VF config message back from PF, now we can parse it */
2305 for (i = 0; i < adapter->vf_res->num_vsis; i++) {
2306 if (adapter->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
2307 adapter->vsi_res = &adapter->vf_res->vsi_res[i];
2308 }
2309 if (!adapter->vsi_res) {
2310 dev_err(&adapter->pdev->dev, "No LAN VSI found\n");
2311 return -ENODEV;
2312 }
2313
2314 if (adapter->vf_res->vf_offload_flags
2315 & I40E_VIRTCHNL_VF_OFFLOAD_VLAN) {
cc7e406c
MW
2316 netdev->vlan_features = netdev->features &
2317 ~(NETIF_F_HW_VLAN_CTAG_TX |
2318 NETIF_F_HW_VLAN_CTAG_RX |
2319 NETIF_F_HW_VLAN_CTAG_FILTER);
e6d038de
MW
2320 netdev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2321 NETIF_F_HW_VLAN_CTAG_RX |
2322 NETIF_F_HW_VLAN_CTAG_FILTER;
2323 }
2324 netdev->features |= NETIF_F_HIGHDMA |
2325 NETIF_F_SG |
2326 NETIF_F_IP_CSUM |
53692b1d 2327 NETIF_F_SCTP_CRC |
e6d038de
MW
2328 NETIF_F_IPV6_CSUM |
2329 NETIF_F_TSO |
2330 NETIF_F_TSO6 |
2331 NETIF_F_RXCSUM |
2332 NETIF_F_GRO;
2333
2334 /* copy netdev features into list of user selectable features */
2335 netdev->hw_features |= netdev->features;
2336 netdev->hw_features &= ~NETIF_F_RXCSUM;
2337
2338 adapter->vsi.id = adapter->vsi_res->vsi_id;
2339
2340 adapter->vsi.back = adapter;
2341 adapter->vsi.base_vector = 1;
2342 adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK;
2343 adapter->vsi.rx_itr_setting = (I40E_ITR_DYNAMIC |
2344 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
2345 adapter->vsi.tx_itr_setting = (I40E_ITR_DYNAMIC |
2346 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
2347 adapter->vsi.netdev = adapter->netdev;
f578f5f4 2348 adapter->vsi.qs_handle = adapter->vsi_res->qset_handle;
e6d038de
MW
2349 return 0;
2350}
2351
5eae00c5
GR
2352/**
2353 * i40evf_init_task - worker thread to perform delayed initialization
2354 * @work: pointer to work_struct containing our data
2355 *
2356 * This task completes the work that was begun in probe. Due to the nature
2357 * of VF-PF communications, we may need to wait tens of milliseconds to get
dbedd44e 2358 * responses back from the PF. Rather than busy-wait in probe and bog down the
5eae00c5
GR
2359 * whole system, we'll do it in a task so we can sleep.
2360 * This task only runs during driver init. Once we've established
2361 * communications with the PF driver and set up our netdev, the watchdog
2362 * takes over.
2363 **/
2364static void i40evf_init_task(struct work_struct *work)
2365{
2366 struct i40evf_adapter *adapter = container_of(work,
2367 struct i40evf_adapter,
2368 init_task.work);
2369 struct net_device *netdev = adapter->netdev;
5eae00c5
GR
2370 struct i40e_hw *hw = &adapter->hw;
2371 struct pci_dev *pdev = adapter->pdev;
e6d038de 2372 int err, bufsz;
5eae00c5
GR
2373
2374 switch (adapter->state) {
2375 case __I40EVF_STARTUP:
2376 /* driver loaded, probe complete */
ef8693eb
MW
2377 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
2378 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
5eae00c5
GR
2379 err = i40e_set_mac_type(hw);
2380 if (err) {
c2a137cb
MW
2381 dev_err(&pdev->dev, "Failed to set MAC type (%d)\n",
2382 err);
2619ef47 2383 goto err;
5eae00c5
GR
2384 }
2385 err = i40evf_check_reset_complete(hw);
2386 if (err) {
0d9c7ea8 2387 dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n",
75a64435 2388 err);
5eae00c5
GR
2389 goto err;
2390 }
2391 hw->aq.num_arq_entries = I40EVF_AQ_LEN;
2392 hw->aq.num_asq_entries = I40EVF_AQ_LEN;
2393 hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2394 hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2395
2396 err = i40evf_init_adminq(hw);
2397 if (err) {
c2a137cb
MW
2398 dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n",
2399 err);
5eae00c5
GR
2400 goto err;
2401 }
2402 err = i40evf_send_api_ver(adapter);
2403 if (err) {
10bdd67b 2404 dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err);
5eae00c5
GR
2405 i40evf_shutdown_adminq(hw);
2406 goto err;
2407 }
2408 adapter->state = __I40EVF_INIT_VERSION_CHECK;
2409 goto restart;
5eae00c5 2410 case __I40EVF_INIT_VERSION_CHECK:
10bdd67b 2411 if (!i40evf_asq_done(hw)) {
80e72893 2412 dev_err(&pdev->dev, "Admin queue command never completed\n");
906a6937
MW
2413 i40evf_shutdown_adminq(hw);
2414 adapter->state = __I40EVF_STARTUP;
5eae00c5 2415 goto err;
10bdd67b 2416 }
5eae00c5
GR
2417
2418 /* aq msg sent, awaiting reply */
2419 err = i40evf_verify_api_ver(adapter);
2420 if (err) {
d4f82fd3 2421 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
56f9920a 2422 err = i40evf_send_api_ver(adapter);
ee1693e5
MW
2423 else
2424 dev_err(&pdev->dev, "Unsupported PF API version %d.%d, expected %d.%d\n",
2425 adapter->pf_version.major,
2426 adapter->pf_version.minor,
2427 I40E_VIRTCHNL_VERSION_MAJOR,
2428 I40E_VIRTCHNL_VERSION_MINOR);
5eae00c5
GR
2429 goto err;
2430 }
2431 err = i40evf_send_vf_config_msg(adapter);
2432 if (err) {
3f2ab172 2433 dev_err(&pdev->dev, "Unable to send config request (%d)\n",
5eae00c5
GR
2434 err);
2435 goto err;
2436 }
2437 adapter->state = __I40EVF_INIT_GET_RESOURCES;
2438 goto restart;
5eae00c5
GR
2439 case __I40EVF_INIT_GET_RESOURCES:
2440 /* aq msg sent, awaiting reply */
2441 if (!adapter->vf_res) {
2442 bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
2443 (I40E_MAX_VF_VSI *
2444 sizeof(struct i40e_virtchnl_vsi_resource));
2445 adapter->vf_res = kzalloc(bufsz, GFP_KERNEL);
c2a137cb 2446 if (!adapter->vf_res)
5eae00c5 2447 goto err;
5eae00c5
GR
2448 }
2449 err = i40evf_get_vf_config(adapter);
906a6937 2450 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) {
906a6937
MW
2451 err = i40evf_send_vf_config_msg(adapter);
2452 goto err;
e743072f
MW
2453 } else if (err == I40E_ERR_PARAM) {
2454 /* We only get ERR_PARAM if the device is in a very bad
2455 * state or if we've been disabled for previous bad
2456 * behavior. Either way, we're done now.
2457 */
2458 i40evf_shutdown_adminq(hw);
2459 dev_err(&pdev->dev, "Unable to get VF config due to PF error condition, not retrying\n");
2460 return;
906a6937 2461 }
5eae00c5 2462 if (err) {
c2a137cb
MW
2463 dev_err(&pdev->dev, "Unable to get VF config (%d)\n",
2464 err);
5eae00c5
GR
2465 goto err_alloc;
2466 }
2467 adapter->state = __I40EVF_INIT_SW;
2468 break;
2469 default:
2470 goto err_alloc;
2471 }
e6d038de 2472 if (i40evf_process_config(adapter))
5eae00c5 2473 goto err_alloc;
e6d038de 2474 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
5eae00c5
GR
2475
2476 adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED;
2477
5eae00c5
GR
2478 netdev->netdev_ops = &i40evf_netdev_ops;
2479 i40evf_set_ethtool_ops(netdev);
2480 netdev->watchdog_timeo = 5 * HZ;
3415e8ce 2481
5eae00c5 2482 if (!is_valid_ether_addr(adapter->hw.mac.addr)) {
b34f90e7 2483 dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n",
c2a137cb 2484 adapter->hw.mac.addr);
14e52ee2
MW
2485 eth_hw_addr_random(netdev);
2486 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2487 } else {
2488 adapter->flags |= I40EVF_FLAG_ADDR_SET_BY_PF;
2489 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
2490 ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr);
5eae00c5 2491 }
5eae00c5 2492
5eae00c5
GR
2493 init_timer(&adapter->watchdog_timer);
2494 adapter->watchdog_timer.function = &i40evf_watchdog_timer;
2495 adapter->watchdog_timer.data = (unsigned long)adapter;
2496 mod_timer(&adapter->watchdog_timer, jiffies + 1);
2497
cc052927
MW
2498 adapter->num_active_queues = min_t(int,
2499 adapter->vsi_res->num_queue_pairs,
2500 (int)(num_online_cpus()));
d732a184
MW
2501 adapter->tx_desc_count = I40EVF_DEFAULT_TXD;
2502 adapter->rx_desc_count = I40EVF_DEFAULT_RXD;
5eae00c5
GR
2503 err = i40evf_init_interrupt_scheme(adapter);
2504 if (err)
2505 goto err_sw_init;
2506 i40evf_map_rings_to_vectors(adapter);
1f012279
ASJ
2507 if (adapter->vf_res->vf_offload_flags &
2508 I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
2509 adapter->flags |= I40EVF_FLAG_WB_ON_ITR_CAPABLE;
e25d00b8 2510 if (!RSS_AQ(adapter))
96a81986 2511 i40evf_init_rss(adapter);
5eae00c5
GR
2512 err = i40evf_request_misc_irq(adapter);
2513 if (err)
2514 goto err_sw_init;
2515
2516 netif_carrier_off(netdev);
2517
ef8693eb
MW
2518 if (!adapter->netdev_registered) {
2519 err = register_netdev(netdev);
2520 if (err)
2521 goto err_register;
2522 }
5eae00c5
GR
2523
2524 adapter->netdev_registered = true;
2525
2526 netif_tx_stop_all_queues(netdev);
2527
b34f90e7 2528 dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr);
5eae00c5
GR
2529 if (netdev->features & NETIF_F_GRO)
2530 dev_info(&pdev->dev, "GRO is enabled\n");
2531
5eae00c5
GR
2532 adapter->state = __I40EVF_DOWN;
2533 set_bit(__I40E_DOWN, &adapter->vsi.state);
2534 i40evf_misc_irq_enable(adapter);
e25d00b8
ASJ
2535
2536 if (RSS_AQ(adapter)) {
2537 adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_RSS;
2538 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
2539 } else {
96a81986 2540 i40evf_init_rss(adapter);
e25d00b8 2541 }
5eae00c5
GR
2542 return;
2543restart:
3f7e5c33 2544 schedule_delayed_work(&adapter->init_task, msecs_to_jiffies(30));
5eae00c5
GR
2545 return;
2546
2547err_register:
2548 i40evf_free_misc_irq(adapter);
2549err_sw_init:
2550 i40evf_reset_interrupt_capability(adapter);
5eae00c5
GR
2551err_alloc:
2552 kfree(adapter->vf_res);
2553 adapter->vf_res = NULL;
2554err:
2555 /* Things went into the weeds, so try again later */
2556 if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) {
b9029e94 2557 dev_err(&pdev->dev, "Failed to communicate with PF; waiting before retry\n");
ef8693eb 2558 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
b9029e94
MW
2559 i40evf_shutdown_adminq(hw);
2560 adapter->state = __I40EVF_STARTUP;
2561 schedule_delayed_work(&adapter->init_task, HZ * 5);
2562 return;
5eae00c5 2563 }
3f7e5c33 2564 schedule_delayed_work(&adapter->init_task, HZ);
5eae00c5
GR
2565}
2566
2567/**
2568 * i40evf_shutdown - Shutdown the device in preparation for a reboot
2569 * @pdev: pci device structure
2570 **/
2571static void i40evf_shutdown(struct pci_dev *pdev)
2572{
2573 struct net_device *netdev = pci_get_drvdata(pdev);
00293fdc 2574 struct i40evf_adapter *adapter = netdev_priv(netdev);
5eae00c5
GR
2575
2576 netif_device_detach(netdev);
2577
2578 if (netif_running(netdev))
2579 i40evf_close(netdev);
2580
00293fdc
MW
2581 /* Prevent the watchdog from running. */
2582 adapter->state = __I40EVF_REMOVE;
2583 adapter->aq_required = 0;
00293fdc 2584
5eae00c5
GR
2585#ifdef CONFIG_PM
2586 pci_save_state(pdev);
2587
2588#endif
2589 pci_disable_device(pdev);
2590}
2591
2592/**
2593 * i40evf_probe - Device Initialization Routine
2594 * @pdev: PCI device information struct
2595 * @ent: entry in i40evf_pci_tbl
2596 *
2597 * Returns 0 on success, negative on failure
2598 *
2599 * i40evf_probe initializes an adapter identified by a pci_dev structure.
2600 * The OS initialization, configuring of the adapter private structure,
2601 * and a hardware reset occur.
2602 **/
2603static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2604{
2605 struct net_device *netdev;
2606 struct i40evf_adapter *adapter = NULL;
2607 struct i40e_hw *hw = NULL;
dbbd8111 2608 int err;
5eae00c5
GR
2609
2610 err = pci_enable_device(pdev);
2611 if (err)
2612 return err;
2613
6494294f 2614 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
6494294f 2615 if (err) {
e3e3bfdd
JS
2616 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2617 if (err) {
2618 dev_err(&pdev->dev,
2619 "DMA configuration failed: 0x%x\n", err);
2620 goto err_dma;
2621 }
5eae00c5
GR
2622 }
2623
2624 err = pci_request_regions(pdev, i40evf_driver_name);
2625 if (err) {
2626 dev_err(&pdev->dev,
2627 "pci_request_regions failed 0x%x\n", err);
2628 goto err_pci_reg;
2629 }
2630
2631 pci_enable_pcie_error_reporting(pdev);
2632
2633 pci_set_master(pdev);
2634
1255b7a1 2635 netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter), MAX_QUEUES);
5eae00c5
GR
2636 if (!netdev) {
2637 err = -ENOMEM;
2638 goto err_alloc_etherdev;
2639 }
2640
2641 SET_NETDEV_DEV(netdev, &pdev->dev);
2642
2643 pci_set_drvdata(pdev, netdev);
2644 adapter = netdev_priv(netdev);
5eae00c5
GR
2645
2646 adapter->netdev = netdev;
2647 adapter->pdev = pdev;
2648
2649 hw = &adapter->hw;
2650 hw->back = adapter;
2651
41a1d04b 2652 adapter->msg_enable = BIT(DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
5eae00c5
GR
2653 adapter->state = __I40EVF_STARTUP;
2654
2655 /* Call save state here because it relies on the adapter struct. */
2656 pci_save_state(pdev);
2657
2658 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2659 pci_resource_len(pdev, 0));
2660 if (!hw->hw_addr) {
2661 err = -EIO;
2662 goto err_ioremap;
2663 }
2664 hw->vendor_id = pdev->vendor;
2665 hw->device_id = pdev->device;
2666 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2667 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2668 hw->subsystem_device_id = pdev->subsystem_device;
2669 hw->bus.device = PCI_SLOT(pdev->devfn);
2670 hw->bus.func = PCI_FUNC(pdev->devfn);
2671
8ddb3326
JB
2672 /* set up the locks for the AQ, do this only once in probe
2673 * and destroy them only once in remove
2674 */
2675 mutex_init(&hw->aq.asq_mutex);
2676 mutex_init(&hw->aq.arq_mutex);
2677
8bb1a540
SK
2678 INIT_LIST_HEAD(&adapter->mac_filter_list);
2679 INIT_LIST_HEAD(&adapter->vlan_filter_list);
2680
5eae00c5
GR
2681 INIT_WORK(&adapter->reset_task, i40evf_reset_task);
2682 INIT_WORK(&adapter->adminq_task, i40evf_adminq_task);
2683 INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task);
2684 INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task);
9b32b0b5
MW
2685 schedule_delayed_work(&adapter->init_task,
2686 msecs_to_jiffies(5 * (pdev->devfn & 0x07)));
5eae00c5
GR
2687
2688 return 0;
2689
2690err_ioremap:
2691 free_netdev(netdev);
2692err_alloc_etherdev:
2693 pci_release_regions(pdev);
2694err_pci_reg:
2695err_dma:
2696 pci_disable_device(pdev);
2697 return err;
2698}
2699
2700#ifdef CONFIG_PM
2701/**
2702 * i40evf_suspend - Power management suspend routine
2703 * @pdev: PCI device information struct
2704 * @state: unused
2705 *
2706 * Called when the system (VM) is entering sleep/suspend.
2707 **/
2708static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state)
2709{
2710 struct net_device *netdev = pci_get_drvdata(pdev);
2711 struct i40evf_adapter *adapter = netdev_priv(netdev);
2712 int retval = 0;
2713
2714 netif_device_detach(netdev);
2715
2716 if (netif_running(netdev)) {
2717 rtnl_lock();
2718 i40evf_down(adapter);
2719 rtnl_unlock();
2720 }
2721 i40evf_free_misc_irq(adapter);
2722 i40evf_reset_interrupt_capability(adapter);
2723
2724 retval = pci_save_state(pdev);
2725 if (retval)
2726 return retval;
2727
2728 pci_disable_device(pdev);
2729
2730 return 0;
2731}
2732
2733/**
dbedd44e 2734 * i40evf_resume - Power management resume routine
5eae00c5
GR
2735 * @pdev: PCI device information struct
2736 *
2737 * Called when the system (VM) is resumed from sleep/suspend.
2738 **/
2739static int i40evf_resume(struct pci_dev *pdev)
2740{
2741 struct i40evf_adapter *adapter = pci_get_drvdata(pdev);
2742 struct net_device *netdev = adapter->netdev;
2743 u32 err;
2744
2745 pci_set_power_state(pdev, PCI_D0);
2746 pci_restore_state(pdev);
2747 /* pci_restore_state clears dev->state_saved so call
2748 * pci_save_state to restore it.
2749 */
2750 pci_save_state(pdev);
2751
2752 err = pci_enable_device_mem(pdev);
2753 if (err) {
2754 dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n");
2755 return err;
2756 }
2757 pci_set_master(pdev);
2758
2759 rtnl_lock();
2760 err = i40evf_set_interrupt_capability(adapter);
2761 if (err) {
f2a1c368 2762 rtnl_unlock();
5eae00c5
GR
2763 dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n");
2764 return err;
2765 }
2766 err = i40evf_request_misc_irq(adapter);
2767 rtnl_unlock();
2768 if (err) {
2769 dev_err(&pdev->dev, "Cannot get interrupt vector.\n");
2770 return err;
2771 }
2772
2773 schedule_work(&adapter->reset_task);
2774
2775 netif_device_attach(netdev);
2776
2777 return err;
2778}
2779
2780#endif /* CONFIG_PM */
2781/**
2782 * i40evf_remove - Device Removal Routine
2783 * @pdev: PCI device information struct
2784 *
2785 * i40evf_remove is called by the PCI subsystem to alert the driver
2786 * that it should release a PCI device. The could be caused by a
2787 * Hot-Plug event, or because the driver is going to be removed from
2788 * memory.
2789 **/
2790static void i40evf_remove(struct pci_dev *pdev)
2791{
2792 struct net_device *netdev = pci_get_drvdata(pdev);
2793 struct i40evf_adapter *adapter = netdev_priv(netdev);
6ba36a24 2794 struct i40evf_mac_filter *f, *ftmp;
5eae00c5
GR
2795 struct i40e_hw *hw = &adapter->hw;
2796
2797 cancel_delayed_work_sync(&adapter->init_task);
ef8693eb 2798 cancel_work_sync(&adapter->reset_task);
5eae00c5
GR
2799
2800 if (adapter->netdev_registered) {
2801 unregister_netdev(netdev);
2802 adapter->netdev_registered = false;
2803 }
53d0b3ae 2804
f4a71881 2805 /* Shut down all the garbage mashers on the detention level */
5eae00c5 2806 adapter->state = __I40EVF_REMOVE;
f4a71881 2807 adapter->aq_required = 0;
f4a71881
MW
2808 i40evf_request_reset(adapter);
2809 msleep(20);
2810 /* If the FW isn't responding, kick it once, but only once. */
2811 if (!i40evf_asq_done(hw)) {
2812 i40evf_request_reset(adapter);
2813 msleep(20);
2814 }
5eae00c5 2815
dbb01c8a 2816 if (adapter->msix_entries) {
5eae00c5 2817 i40evf_misc_irq_disable(adapter);
5eae00c5 2818 i40evf_free_misc_irq(adapter);
5eae00c5 2819 i40evf_reset_interrupt_capability(adapter);
d31944d6 2820 i40evf_free_q_vectors(adapter);
5eae00c5
GR
2821 }
2822
e5d17c3e
MW
2823 if (adapter->watchdog_timer.function)
2824 del_timer_sync(&adapter->watchdog_timer);
2825
dbb01c8a
MW
2826 flush_scheduled_work();
2827
66f9af85
HZ
2828 /* Clear user configurations for RSS */
2829 i40evf_clear_rss_config_user(&adapter->vsi);
2830
5eae00c5
GR
2831 if (hw->aq.asq.count)
2832 i40evf_shutdown_adminq(hw);
2833
8ddb3326
JB
2834 /* destroy the locks only once, here */
2835 mutex_destroy(&hw->aq.arq_mutex);
2836 mutex_destroy(&hw->aq.asq_mutex);
2837
5eae00c5
GR
2838 iounmap(hw->hw_addr);
2839 pci_release_regions(pdev);
2840
e284fc88
MW
2841 i40evf_free_all_tx_resources(adapter);
2842 i40evf_free_all_rx_resources(adapter);
5eae00c5
GR
2843 i40evf_free_queues(adapter);
2844 kfree(adapter->vf_res);
6ba36a24
MW
2845 /* If we got removed before an up/down sequence, we've got a filter
2846 * hanging out there that we need to get rid of.
2847 */
2848 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
2849 list_del(&f->list);
2850 kfree(f);
2851 }
37dfdf37
MW
2852 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
2853 list_del(&f->list);
2854 kfree(f);
2855 }
5eae00c5
GR
2856
2857 free_netdev(netdev);
2858
2859 pci_disable_pcie_error_reporting(pdev);
2860
2861 pci_disable_device(pdev);
2862}
2863
2864static struct pci_driver i40evf_driver = {
2865 .name = i40evf_driver_name,
2866 .id_table = i40evf_pci_tbl,
2867 .probe = i40evf_probe,
2868 .remove = i40evf_remove,
2869#ifdef CONFIG_PM
2870 .suspend = i40evf_suspend,
2871 .resume = i40evf_resume,
2872#endif
2873 .shutdown = i40evf_shutdown,
2874};
2875
2876/**
2877 * i40e_init_module - Driver Registration Routine
2878 *
2879 * i40e_init_module is the first routine called when the driver is
2880 * loaded. All it does is register with the PCI subsystem.
2881 **/
2882static int __init i40evf_init_module(void)
2883{
2884 int ret;
75a64435 2885
5eae00c5 2886 pr_info("i40evf: %s - version %s\n", i40evf_driver_string,
75a64435 2887 i40evf_driver_version);
5eae00c5
GR
2888
2889 pr_info("%s\n", i40evf_copyright);
2890
2891 ret = pci_register_driver(&i40evf_driver);
2892 return ret;
2893}
2894
2895module_init(i40evf_init_module);
2896
2897/**
2898 * i40e_exit_module - Driver Exit Cleanup Routine
2899 *
2900 * i40e_exit_module is called just before the driver is removed
2901 * from memory.
2902 **/
2903static void __exit i40evf_exit_module(void)
2904{
2905 pci_unregister_driver(&i40evf_driver);
2906}
2907
2908module_exit(i40evf_exit_module);
2909
2910/* i40evf_main.c */
This page took 0.355038 seconds and 5 git commands to generate.