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