blob: 642944e622af8b133431472424a04f4d35d9f8d9 [file] [log] [blame]
Greg Rose5eae00c2013-12-21 06:12:45 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
Sravanthi Tangeda5b8eb172015-02-06 08:52:21 +00004 * Copyright(c) 2013 - 2015 Intel Corporation.
Greg Rose5eae00c2013-12-21 06:12:45 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Jesse Brandeburgb8316072014-04-05 07:46:11 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
Greg Rose5eae00c2013-12-21 06:12:45 +000018 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27#include "i40evf.h"
28#include "i40e_prototype.h"
29static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter);
30static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter);
31static int i40evf_close(struct net_device *netdev);
32
33char i40evf_driver_name[] = "i40evf";
34static const char i40evf_driver_string[] =
Mitch Williams0af56f42014-06-04 20:42:10 +000035 "Intel(R) XL710/X710 Virtual Function Network Driver";
Greg Rose5eae00c2013-12-21 06:12:45 +000036
Catherine Sullivan76945bf2015-04-27 14:57:22 -040037#define DRV_VERSION "1.3.2"
Greg Rose5eae00c2013-12-21 06:12:45 +000038const char i40evf_driver_version[] = DRV_VERSION;
39static const char i40evf_copyright[] =
Mitch Williams673f2eb2014-02-20 19:29:13 -080040 "Copyright (c) 2013 - 2014 Intel Corporation.";
Greg Rose5eae00c2013-12-21 06:12:45 +000041
42/* i40evf_pci_tbl - PCI Device ID Table
43 *
44 * Wildcard entries (PCI_ANY_ID) should come last
45 * Last entry must be all 0s
46 *
47 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
48 * Class, Class Mask, private data (not used) }
49 */
Benoit Taine9baa3c32014-08-08 15:56:03 +020050static const struct pci_device_id i40evf_pci_tbl[] = {
Shannon Nelsonab600852014-01-17 15:36:39 -080051 {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF), 0},
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040052 {PCI_VDEVICE(INTEL, I40E_DEV_ID_X722_VF), 0},
Greg Rose5eae00c2013-12-21 06:12:45 +000053 /* required last entry */
54 {0, }
55};
56
57MODULE_DEVICE_TABLE(pci, i40evf_pci_tbl);
58
59MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
60MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver");
61MODULE_LICENSE("GPL");
62MODULE_VERSION(DRV_VERSION);
63
64/**
65 * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code
66 * @hw: pointer to the HW structure
67 * @mem: ptr to mem struct to fill out
68 * @size: size of memory requested
69 * @alignment: what to align the allocation to
70 **/
71i40e_status i40evf_allocate_dma_mem_d(struct i40e_hw *hw,
72 struct i40e_dma_mem *mem,
73 u64 size, u32 alignment)
74{
75 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
76
77 if (!mem)
78 return I40E_ERR_PARAM;
79
80 mem->size = ALIGN(size, alignment);
81 mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size,
82 (dma_addr_t *)&mem->pa, GFP_KERNEL);
83 if (mem->va)
84 return 0;
85 else
86 return I40E_ERR_NO_MEMORY;
87}
88
89/**
90 * i40evf_free_dma_mem_d - OS specific memory free for shared code
91 * @hw: pointer to the HW structure
92 * @mem: ptr to mem struct to free
93 **/
94i40e_status i40evf_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
95{
96 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
97
98 if (!mem || !mem->va)
99 return I40E_ERR_PARAM;
100 dma_free_coherent(&adapter->pdev->dev, mem->size,
101 mem->va, (dma_addr_t)mem->pa);
102 return 0;
103}
104
105/**
106 * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code
107 * @hw: pointer to the HW structure
108 * @mem: ptr to mem struct to fill out
109 * @size: size of memory requested
110 **/
111i40e_status i40evf_allocate_virt_mem_d(struct i40e_hw *hw,
112 struct i40e_virt_mem *mem, u32 size)
113{
114 if (!mem)
115 return I40E_ERR_PARAM;
116
117 mem->size = size;
118 mem->va = kzalloc(size, GFP_KERNEL);
119
120 if (mem->va)
121 return 0;
122 else
123 return I40E_ERR_NO_MEMORY;
124}
125
126/**
127 * i40evf_free_virt_mem_d - OS specific memory free for shared code
128 * @hw: pointer to the HW structure
129 * @mem: ptr to mem struct to free
130 **/
131i40e_status i40evf_free_virt_mem_d(struct i40e_hw *hw,
132 struct i40e_virt_mem *mem)
133{
134 if (!mem)
135 return I40E_ERR_PARAM;
136
137 /* it's ok to kfree a NULL pointer */
138 kfree(mem->va);
139
140 return 0;
141}
142
143/**
144 * i40evf_debug_d - OS dependent version of debug printing
145 * @hw: pointer to the HW structure
146 * @mask: debug level mask
147 * @fmt_str: printf-type format description
148 **/
149void i40evf_debug_d(void *hw, u32 mask, char *fmt_str, ...)
150{
151 char buf[512];
152 va_list argptr;
153
154 if (!(mask & ((struct i40e_hw *)hw)->debug_mask))
155 return;
156
157 va_start(argptr, fmt_str);
158 vsnprintf(buf, sizeof(buf), fmt_str, argptr);
159 va_end(argptr);
160
161 /* the debug string is already formatted with a newline */
162 pr_info("%s", buf);
163}
164
165/**
166 * i40evf_tx_timeout - Respond to a Tx Hang
167 * @netdev: network interface device structure
168 **/
169static void i40evf_tx_timeout(struct net_device *netdev)
170{
171 struct i40evf_adapter *adapter = netdev_priv(netdev);
172
173 adapter->tx_timeout_count++;
Mitch Williams67c818a2015-06-19 08:56:30 -0700174 if (!(adapter->flags & (I40EVF_FLAG_RESET_PENDING |
175 I40EVF_FLAG_RESET_NEEDED))) {
Mitch Williams3526d802014-03-06 08:59:56 +0000176 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
Mitch Williams625777e2014-02-20 19:29:05 -0800177 schedule_work(&adapter->reset_task);
178 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000179}
180
181/**
182 * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC
183 * @adapter: board private structure
184 **/
185static void i40evf_misc_irq_disable(struct i40evf_adapter *adapter)
186{
187 struct i40e_hw *hw = &adapter->hw;
Mitch Williams75a64432014-11-11 20:02:42 +0000188
Greg Rose5eae00c2013-12-21 06:12:45 +0000189 wr32(hw, I40E_VFINT_DYN_CTL01, 0);
190
191 /* read flush */
192 rd32(hw, I40E_VFGEN_RSTAT);
193
194 synchronize_irq(adapter->msix_entries[0].vector);
195}
196
197/**
198 * i40evf_misc_irq_enable - Enable default interrupt generation settings
199 * @adapter: board private structure
200 **/
201static void i40evf_misc_irq_enable(struct i40evf_adapter *adapter)
202{
203 struct i40e_hw *hw = &adapter->hw;
Mitch Williams75a64432014-11-11 20:02:42 +0000204
Greg Rose5eae00c2013-12-21 06:12:45 +0000205 wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK |
206 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK);
207 wr32(hw, I40E_VFINT_ICR0_ENA1, I40E_VFINT_ICR0_ENA_ADMINQ_MASK);
208
209 /* read flush */
210 rd32(hw, I40E_VFGEN_RSTAT);
211}
212
213/**
214 * i40evf_irq_disable - Mask off interrupt generation on the NIC
215 * @adapter: board private structure
216 **/
217static void i40evf_irq_disable(struct i40evf_adapter *adapter)
218{
219 int i;
220 struct i40e_hw *hw = &adapter->hw;
221
Mitch Williamsdbb01c82014-02-20 19:29:07 -0800222 if (!adapter->msix_entries)
223 return;
224
Greg Rose5eae00c2013-12-21 06:12:45 +0000225 for (i = 1; i < adapter->num_msix_vectors; i++) {
226 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), 0);
227 synchronize_irq(adapter->msix_entries[i].vector);
228 }
229 /* read flush */
230 rd32(hw, I40E_VFGEN_RSTAT);
Greg Rose5eae00c2013-12-21 06:12:45 +0000231}
232
233/**
234 * i40evf_irq_enable_queues - Enable interrupt for specified queues
235 * @adapter: board private structure
236 * @mask: bitmap of queues to enable
237 **/
238void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask)
239{
240 struct i40e_hw *hw = &adapter->hw;
241 int i;
242
243 for (i = 1; i < adapter->num_msix_vectors; i++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400244 if (mask & BIT(i - 1)) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000245 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1),
246 I40E_VFINT_DYN_CTLN1_INTENA_MASK |
Jesse Brandeburg97bf75f2015-02-27 09:18:32 +0000247 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
Greg Rose5eae00c2013-12-21 06:12:45 +0000248 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
249 }
250 }
251}
252
253/**
254 * i40evf_fire_sw_int - Generate SW interrupt for specified vectors
255 * @adapter: board private structure
256 * @mask: bitmap of vectors to trigger
257 **/
Mitch Williams75a64432014-11-11 20:02:42 +0000258static void i40evf_fire_sw_int(struct i40evf_adapter *adapter, u32 mask)
Greg Rose5eae00c2013-12-21 06:12:45 +0000259{
260 struct i40e_hw *hw = &adapter->hw;
261 int i;
262 uint32_t dyn_ctl;
263
Mitch Williams164ec1b2014-06-04 08:45:19 +0000264 if (mask & 1) {
265 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTL01);
266 dyn_ctl |= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK |
Jesse Brandeburg97bf75f2015-02-27 09:18:32 +0000267 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
Mitch Williams164ec1b2014-06-04 08:45:19 +0000268 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK;
269 wr32(hw, I40E_VFINT_DYN_CTL01, dyn_ctl);
270 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000271 for (i = 1; i < adapter->num_msix_vectors; i++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400272 if (mask & BIT(i)) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000273 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTLN1(i - 1));
274 dyn_ctl |= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK |
Jesse Brandeburg97bf75f2015-02-27 09:18:32 +0000275 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
Greg Rose5eae00c2013-12-21 06:12:45 +0000276 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK;
277 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), dyn_ctl);
278 }
279 }
280}
281
282/**
283 * i40evf_irq_enable - Enable default interrupt generation settings
284 * @adapter: board private structure
285 **/
286void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush)
287{
288 struct i40e_hw *hw = &adapter->hw;
289
Mitch Williams164ec1b2014-06-04 08:45:19 +0000290 i40evf_misc_irq_enable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +0000291 i40evf_irq_enable_queues(adapter, ~0);
292
293 if (flush)
294 rd32(hw, I40E_VFGEN_RSTAT);
295}
296
297/**
298 * i40evf_msix_aq - Interrupt handler for vector 0
299 * @irq: interrupt number
300 * @data: pointer to netdev
301 **/
302static irqreturn_t i40evf_msix_aq(int irq, void *data)
303{
304 struct net_device *netdev = data;
305 struct i40evf_adapter *adapter = netdev_priv(netdev);
306 struct i40e_hw *hw = &adapter->hw;
307 u32 val;
308 u32 ena_mask;
309
310 /* handle non-queue interrupts */
311 val = rd32(hw, I40E_VFINT_ICR01);
312 ena_mask = rd32(hw, I40E_VFINT_ICR0_ENA1);
313
314
315 val = rd32(hw, I40E_VFINT_DYN_CTL01);
316 val = val | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK;
317 wr32(hw, I40E_VFINT_DYN_CTL01, val);
318
Greg Rose5eae00c2013-12-21 06:12:45 +0000319 /* schedule work on the private workqueue */
320 schedule_work(&adapter->adminq_task);
321
322 return IRQ_HANDLED;
323}
324
325/**
326 * i40evf_msix_clean_rings - MSIX mode Interrupt Handler
327 * @irq: interrupt number
328 * @data: pointer to a q_vector
329 **/
330static irqreturn_t i40evf_msix_clean_rings(int irq, void *data)
331{
332 struct i40e_q_vector *q_vector = data;
333
334 if (!q_vector->tx.ring && !q_vector->rx.ring)
335 return IRQ_HANDLED;
336
337 napi_schedule(&q_vector->napi);
338
339 return IRQ_HANDLED;
340}
341
342/**
343 * i40evf_map_vector_to_rxq - associate irqs with rx queues
344 * @adapter: board private structure
345 * @v_idx: interrupt number
346 * @r_idx: queue number
347 **/
348static void
349i40evf_map_vector_to_rxq(struct i40evf_adapter *adapter, int v_idx, int r_idx)
350{
351 struct i40e_q_vector *q_vector = adapter->q_vector[v_idx];
352 struct i40e_ring *rx_ring = adapter->rx_rings[r_idx];
353
354 rx_ring->q_vector = q_vector;
355 rx_ring->next = q_vector->rx.ring;
356 rx_ring->vsi = &adapter->vsi;
357 q_vector->rx.ring = rx_ring;
358 q_vector->rx.count++;
359 q_vector->rx.latency_range = I40E_LOW_LATENCY;
360}
361
362/**
363 * i40evf_map_vector_to_txq - associate irqs with tx queues
364 * @adapter: board private structure
365 * @v_idx: interrupt number
366 * @t_idx: queue number
367 **/
368static void
369i40evf_map_vector_to_txq(struct i40evf_adapter *adapter, int v_idx, int t_idx)
370{
371 struct i40e_q_vector *q_vector = adapter->q_vector[v_idx];
372 struct i40e_ring *tx_ring = adapter->tx_rings[t_idx];
373
374 tx_ring->q_vector = q_vector;
375 tx_ring->next = q_vector->tx.ring;
376 tx_ring->vsi = &adapter->vsi;
377 q_vector->tx.ring = tx_ring;
378 q_vector->tx.count++;
379 q_vector->tx.latency_range = I40E_LOW_LATENCY;
380 q_vector->num_ringpairs++;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400381 q_vector->ring_mask |= BIT(t_idx);
Greg Rose5eae00c2013-12-21 06:12:45 +0000382}
383
384/**
385 * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors
386 * @adapter: board private structure to initialize
387 *
388 * This function maps descriptor rings to the queue-specific vectors
389 * we were allotted through the MSI-X enabling code. Ideally, we'd have
390 * one vector per ring/queue, but on a constrained vector budget, we
391 * group the rings as "efficiently" as possible. You would add new
392 * mapping configurations in here.
393 **/
394static int i40evf_map_rings_to_vectors(struct i40evf_adapter *adapter)
395{
396 int q_vectors;
397 int v_start = 0;
398 int rxr_idx = 0, txr_idx = 0;
Mitch Williamscc052922014-10-25 03:24:34 +0000399 int rxr_remaining = adapter->num_active_queues;
400 int txr_remaining = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +0000401 int i, j;
402 int rqpv, tqpv;
403 int err = 0;
404
405 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
406
407 /* The ideal configuration...
408 * We have enough vectors to map one per queue.
409 */
Mitch Williams973371d2015-04-27 14:57:09 -0400410 if (q_vectors >= (rxr_remaining * 2)) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000411 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
412 i40evf_map_vector_to_rxq(adapter, v_start, rxr_idx);
413
414 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
415 i40evf_map_vector_to_txq(adapter, v_start, txr_idx);
416 goto out;
417 }
418
419 /* If we don't have enough vectors for a 1-to-1
420 * mapping, we'll have to group them so there are
421 * multiple queues per vector.
422 * Re-adjusting *qpv takes care of the remainder.
423 */
424 for (i = v_start; i < q_vectors; i++) {
425 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
426 for (j = 0; j < rqpv; j++) {
427 i40evf_map_vector_to_rxq(adapter, i, rxr_idx);
428 rxr_idx++;
429 rxr_remaining--;
430 }
431 }
432 for (i = v_start; i < q_vectors; i++) {
433 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
434 for (j = 0; j < tqpv; j++) {
435 i40evf_map_vector_to_txq(adapter, i, txr_idx);
436 txr_idx++;
437 txr_remaining--;
438 }
439 }
440
441out:
442 adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
443
444 return err;
445}
446
447/**
448 * i40evf_request_traffic_irqs - Initialize MSI-X interrupts
449 * @adapter: board private structure
450 *
451 * Allocates MSI-X vectors for tx and rx handling, and requests
452 * interrupts from the kernel.
453 **/
454static int
455i40evf_request_traffic_irqs(struct i40evf_adapter *adapter, char *basename)
456{
457 int vector, err, q_vectors;
458 int rx_int_idx = 0, tx_int_idx = 0;
459
460 i40evf_irq_disable(adapter);
461 /* Decrement for Other and TCP Timer vectors */
462 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
463
464 for (vector = 0; vector < q_vectors; vector++) {
465 struct i40e_q_vector *q_vector = adapter->q_vector[vector];
466
467 if (q_vector->tx.ring && q_vector->rx.ring) {
468 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
469 "i40evf-%s-%s-%d", basename,
470 "TxRx", rx_int_idx++);
471 tx_int_idx++;
472 } else if (q_vector->rx.ring) {
473 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
474 "i40evf-%s-%s-%d", basename,
475 "rx", rx_int_idx++);
476 } else if (q_vector->tx.ring) {
477 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
478 "i40evf-%s-%s-%d", basename,
479 "tx", tx_int_idx++);
480 } else {
481 /* skip this unused q_vector */
482 continue;
483 }
484 err = request_irq(
485 adapter->msix_entries[vector + NONQ_VECS].vector,
486 i40evf_msix_clean_rings,
487 0,
488 q_vector->name,
489 q_vector);
490 if (err) {
491 dev_info(&adapter->pdev->dev,
492 "%s: request_irq failed, error: %d\n",
493 __func__, err);
494 goto free_queue_irqs;
495 }
496 /* assign the mask for this irq */
497 irq_set_affinity_hint(
498 adapter->msix_entries[vector + NONQ_VECS].vector,
499 q_vector->affinity_mask);
500 }
501
502 return 0;
503
504free_queue_irqs:
505 while (vector) {
506 vector--;
507 irq_set_affinity_hint(
508 adapter->msix_entries[vector + NONQ_VECS].vector,
509 NULL);
510 free_irq(adapter->msix_entries[vector + NONQ_VECS].vector,
511 adapter->q_vector[vector]);
512 }
513 return err;
514}
515
516/**
517 * i40evf_request_misc_irq - Initialize MSI-X interrupts
518 * @adapter: board private structure
519 *
520 * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
521 * vector is only for the admin queue, and stays active even when the netdev
522 * is closed.
523 **/
524static int i40evf_request_misc_irq(struct i40evf_adapter *adapter)
525{
526 struct net_device *netdev = adapter->netdev;
527 int err;
528
Jesse Brandeburgb39c1e22014-08-01 13:27:08 -0700529 snprintf(adapter->misc_vector_name,
Carolyn Wyborny9a21a002015-02-06 08:52:20 +0000530 sizeof(adapter->misc_vector_name) - 1, "i40evf-%s:mbx",
531 dev_name(&adapter->pdev->dev));
Greg Rose5eae00c2013-12-21 06:12:45 +0000532 err = request_irq(adapter->msix_entries[0].vector,
Mitch Williamse1dfee82014-02-13 03:48:51 -0800533 &i40evf_msix_aq, 0,
534 adapter->misc_vector_name, netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +0000535 if (err) {
536 dev_err(&adapter->pdev->dev,
Catherine Sullivan77fa28b2014-02-20 19:29:17 -0800537 "request_irq for %s failed: %d\n",
538 adapter->misc_vector_name, err);
Greg Rose5eae00c2013-12-21 06:12:45 +0000539 free_irq(adapter->msix_entries[0].vector, netdev);
540 }
541 return err;
542}
543
544/**
545 * i40evf_free_traffic_irqs - Free MSI-X interrupts
546 * @adapter: board private structure
547 *
548 * Frees all MSI-X vectors other than 0.
549 **/
550static void i40evf_free_traffic_irqs(struct i40evf_adapter *adapter)
551{
552 int i;
553 int q_vectors;
Mitch Williams75a64432014-11-11 20:02:42 +0000554
Greg Rose5eae00c2013-12-21 06:12:45 +0000555 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
556
557 for (i = 0; i < q_vectors; i++) {
558 irq_set_affinity_hint(adapter->msix_entries[i+1].vector,
559 NULL);
560 free_irq(adapter->msix_entries[i+1].vector,
561 adapter->q_vector[i]);
562 }
563}
564
565/**
566 * i40evf_free_misc_irq - Free MSI-X miscellaneous vector
567 * @adapter: board private structure
568 *
569 * Frees MSI-X vector 0.
570 **/
571static void i40evf_free_misc_irq(struct i40evf_adapter *adapter)
572{
573 struct net_device *netdev = adapter->netdev;
574
575 free_irq(adapter->msix_entries[0].vector, netdev);
576}
577
578/**
579 * i40evf_configure_tx - Configure Transmit Unit after Reset
580 * @adapter: board private structure
581 *
582 * Configure the Tx unit of the MAC after a reset.
583 **/
584static void i40evf_configure_tx(struct i40evf_adapter *adapter)
585{
586 struct i40e_hw *hw = &adapter->hw;
587 int i;
Mitch Williams75a64432014-11-11 20:02:42 +0000588
Mitch Williamscc052922014-10-25 03:24:34 +0000589 for (i = 0; i < adapter->num_active_queues; i++)
Greg Rose5eae00c2013-12-21 06:12:45 +0000590 adapter->tx_rings[i]->tail = hw->hw_addr + I40E_QTX_TAIL1(i);
591}
592
593/**
594 * i40evf_configure_rx - Configure Receive Unit after Reset
595 * @adapter: board private structure
596 *
597 * Configure the Rx unit of the MAC after a reset.
598 **/
599static void i40evf_configure_rx(struct i40evf_adapter *adapter)
600{
601 struct i40e_hw *hw = &adapter->hw;
602 struct net_device *netdev = adapter->netdev;
603 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
604 int i;
605 int rx_buf_len;
606
607
608 adapter->flags &= ~I40EVF_FLAG_RX_PS_CAPABLE;
609 adapter->flags |= I40EVF_FLAG_RX_1BUF_CAPABLE;
610
611 /* Decide whether to use packet split mode or not */
612 if (netdev->mtu > ETH_DATA_LEN) {
613 if (adapter->flags & I40EVF_FLAG_RX_PS_CAPABLE)
614 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
615 else
616 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
617 } else {
618 if (adapter->flags & I40EVF_FLAG_RX_1BUF_CAPABLE)
619 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
620 else
621 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
622 }
623
624 /* Set the RX buffer length according to the mode */
625 if (adapter->flags & I40EVF_FLAG_RX_PS_ENABLED) {
626 rx_buf_len = I40E_RX_HDR_SIZE;
627 } else {
628 if (netdev->mtu <= ETH_DATA_LEN)
629 rx_buf_len = I40EVF_RXBUFFER_2048;
630 else
631 rx_buf_len = ALIGN(max_frame, 1024);
632 }
633
Mitch Williamscc052922014-10-25 03:24:34 +0000634 for (i = 0; i < adapter->num_active_queues; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000635 adapter->rx_rings[i]->tail = hw->hw_addr + I40E_QRX_TAIL1(i);
636 adapter->rx_rings[i]->rx_buf_len = rx_buf_len;
637 }
638}
639
640/**
641 * i40evf_find_vlan - Search filter list for specific vlan filter
642 * @adapter: board private structure
643 * @vlan: vlan tag
644 *
645 * Returns ptr to the filter object or NULL
646 **/
647static struct
648i40evf_vlan_filter *i40evf_find_vlan(struct i40evf_adapter *adapter, u16 vlan)
649{
650 struct i40evf_vlan_filter *f;
651
652 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
653 if (vlan == f->vlan)
654 return f;
655 }
656 return NULL;
657}
658
659/**
660 * i40evf_add_vlan - Add a vlan filter to the list
661 * @adapter: board private structure
662 * @vlan: VLAN tag
663 *
664 * Returns ptr to the filter object or NULL when no memory available.
665 **/
666static struct
667i40evf_vlan_filter *i40evf_add_vlan(struct i40evf_adapter *adapter, u16 vlan)
668{
Mitch Williams13acb542015-03-31 00:45:05 -0700669 struct i40evf_vlan_filter *f = NULL;
670 int count = 50;
671
672 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
673 &adapter->crit_section)) {
674 udelay(1);
675 if (--count == 0)
676 goto out;
677 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000678
679 f = i40evf_find_vlan(adapter, vlan);
Mitch Williams348d4992014-11-11 20:02:52 +0000680 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000681 f = kzalloc(sizeof(*f), GFP_ATOMIC);
Mitch Williams348d4992014-11-11 20:02:52 +0000682 if (!f)
Mitch Williams13acb542015-03-31 00:45:05 -0700683 goto clearout;
Mitch Williams249c8b82014-05-10 04:49:04 +0000684
Greg Rose5eae00c2013-12-21 06:12:45 +0000685 f->vlan = vlan;
686
687 INIT_LIST_HEAD(&f->list);
688 list_add(&f->list, &adapter->vlan_filter_list);
689 f->add = true;
690 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
691 }
692
Mitch Williams13acb542015-03-31 00:45:05 -0700693clearout:
694 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
695out:
Greg Rose5eae00c2013-12-21 06:12:45 +0000696 return f;
697}
698
699/**
700 * i40evf_del_vlan - Remove a vlan filter from the list
701 * @adapter: board private structure
702 * @vlan: VLAN tag
703 **/
704static void i40evf_del_vlan(struct i40evf_adapter *adapter, u16 vlan)
705{
706 struct i40evf_vlan_filter *f;
Mitch Williams13acb542015-03-31 00:45:05 -0700707 int count = 50;
708
709 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
710 &adapter->crit_section)) {
711 udelay(1);
712 if (--count == 0)
713 return;
714 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000715
716 f = i40evf_find_vlan(adapter, vlan);
717 if (f) {
718 f->remove = true;
719 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
720 }
Mitch Williams13acb542015-03-31 00:45:05 -0700721 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Greg Rose5eae00c2013-12-21 06:12:45 +0000722}
723
724/**
725 * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device
726 * @netdev: network device struct
727 * @vid: VLAN tag
728 **/
729static int i40evf_vlan_rx_add_vid(struct net_device *netdev,
Mitch Williams75a64432014-11-11 20:02:42 +0000730 __always_unused __be16 proto, u16 vid)
Greg Rose5eae00c2013-12-21 06:12:45 +0000731{
732 struct i40evf_adapter *adapter = netdev_priv(netdev);
733
734 if (i40evf_add_vlan(adapter, vid) == NULL)
735 return -ENOMEM;
736 return 0;
737}
738
739/**
740 * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device
741 * @netdev: network device struct
742 * @vid: VLAN tag
743 **/
744static int i40evf_vlan_rx_kill_vid(struct net_device *netdev,
Mitch Williams75a64432014-11-11 20:02:42 +0000745 __always_unused __be16 proto, u16 vid)
Greg Rose5eae00c2013-12-21 06:12:45 +0000746{
747 struct i40evf_adapter *adapter = netdev_priv(netdev);
748
749 i40evf_del_vlan(adapter, vid);
750 return 0;
751}
752
753/**
754 * i40evf_find_filter - Search filter list for specific mac filter
755 * @adapter: board private structure
756 * @macaddr: the MAC address
757 *
758 * Returns ptr to the filter object or NULL
759 **/
760static struct
761i40evf_mac_filter *i40evf_find_filter(struct i40evf_adapter *adapter,
762 u8 *macaddr)
763{
764 struct i40evf_mac_filter *f;
765
766 if (!macaddr)
767 return NULL;
768
769 list_for_each_entry(f, &adapter->mac_filter_list, list) {
770 if (ether_addr_equal(macaddr, f->macaddr))
771 return f;
772 }
773 return NULL;
774}
775
776/**
777 * i40e_add_filter - Add a mac filter to the filter list
778 * @adapter: board private structure
779 * @macaddr: the MAC address
780 *
781 * Returns ptr to the filter object or NULL when no memory available.
782 **/
783static struct
784i40evf_mac_filter *i40evf_add_filter(struct i40evf_adapter *adapter,
785 u8 *macaddr)
786{
787 struct i40evf_mac_filter *f;
Mitch Williams54e16f62015-01-29 07:17:20 +0000788 int count = 50;
Greg Rose5eae00c2013-12-21 06:12:45 +0000789
790 if (!macaddr)
791 return NULL;
792
793 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
Mitch Williams54e16f62015-01-29 07:17:20 +0000794 &adapter->crit_section)) {
Mitch Williamsb65476c2014-07-09 07:46:14 +0000795 udelay(1);
Mitch Williams54e16f62015-01-29 07:17:20 +0000796 if (--count == 0)
797 return NULL;
798 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000799
800 f = i40evf_find_filter(adapter, macaddr);
Mitch Williams348d4992014-11-11 20:02:52 +0000801 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000802 f = kzalloc(sizeof(*f), GFP_ATOMIC);
Mitch Williams348d4992014-11-11 20:02:52 +0000803 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000804 clear_bit(__I40EVF_IN_CRITICAL_TASK,
805 &adapter->crit_section);
806 return NULL;
807 }
808
Greg Rose9a173902014-05-22 06:32:02 +0000809 ether_addr_copy(f->macaddr, macaddr);
Greg Rose5eae00c2013-12-21 06:12:45 +0000810
811 list_add(&f->list, &adapter->mac_filter_list);
812 f->add = true;
813 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
814 }
815
816 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
817 return f;
818}
819
820/**
821 * i40evf_set_mac - NDO callback to set port mac address
822 * @netdev: network interface device structure
823 * @p: pointer to an address structure
824 *
825 * Returns 0 on success, negative on failure
826 **/
827static int i40evf_set_mac(struct net_device *netdev, void *p)
828{
829 struct i40evf_adapter *adapter = netdev_priv(netdev);
830 struct i40e_hw *hw = &adapter->hw;
831 struct i40evf_mac_filter *f;
832 struct sockaddr *addr = p;
833
834 if (!is_valid_ether_addr(addr->sa_data))
835 return -EADDRNOTAVAIL;
836
837 if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
838 return 0;
839
840 f = i40evf_add_filter(adapter, addr->sa_data);
841 if (f) {
Greg Rose9a173902014-05-22 06:32:02 +0000842 ether_addr_copy(hw->mac.addr, addr->sa_data);
843 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +0000844 }
845
846 return (f == NULL) ? -ENOMEM : 0;
847}
848
849/**
850 * i40evf_set_rx_mode - NDO callback to set the netdev filters
851 * @netdev: network interface device structure
852 **/
853static void i40evf_set_rx_mode(struct net_device *netdev)
854{
855 struct i40evf_adapter *adapter = netdev_priv(netdev);
856 struct i40evf_mac_filter *f, *ftmp;
857 struct netdev_hw_addr *uca;
858 struct netdev_hw_addr *mca;
Mitch Williams54e16f62015-01-29 07:17:20 +0000859 int count = 50;
Greg Rose5eae00c2013-12-21 06:12:45 +0000860
861 /* add addr if not already in the filter list */
862 netdev_for_each_uc_addr(uca, netdev) {
863 i40evf_add_filter(adapter, uca->addr);
864 }
865 netdev_for_each_mc_addr(mca, netdev) {
866 i40evf_add_filter(adapter, mca->addr);
867 }
868
869 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
Mitch Williams54e16f62015-01-29 07:17:20 +0000870 &adapter->crit_section)) {
Mitch Williamsb65476c2014-07-09 07:46:14 +0000871 udelay(1);
Mitch Williams54e16f62015-01-29 07:17:20 +0000872 if (--count == 0) {
873 dev_err(&adapter->pdev->dev,
874 "Failed to get lock in %s\n", __func__);
875 return;
876 }
877 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000878 /* remove filter if not in netdev list */
879 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
880 bool found = false;
881
Tobias Klauserdc5f2de2014-05-20 08:23:06 +0000882 if (is_multicast_ether_addr(f->macaddr)) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000883 netdev_for_each_mc_addr(mca, netdev) {
884 if (ether_addr_equal(mca->addr, f->macaddr)) {
885 found = true;
886 break;
887 }
888 }
889 } else {
890 netdev_for_each_uc_addr(uca, netdev) {
891 if (ether_addr_equal(uca->addr, f->macaddr)) {
892 found = true;
893 break;
894 }
895 }
Mitch Williams68ef1692015-04-27 14:57:16 -0400896 if (ether_addr_equal(f->macaddr, adapter->hw.mac.addr))
897 found = true;
Greg Rose5eae00c2013-12-21 06:12:45 +0000898 }
Mitch Williams68ef1692015-04-27 14:57:16 -0400899 if (!found) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000900 f->remove = true;
901 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
902 }
903 }
904 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
905}
906
907/**
908 * i40evf_napi_enable_all - enable NAPI on all queue vectors
909 * @adapter: board private structure
910 **/
911static void i40evf_napi_enable_all(struct i40evf_adapter *adapter)
912{
913 int q_idx;
914 struct i40e_q_vector *q_vector;
915 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
916
917 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
918 struct napi_struct *napi;
Mitch Williams75a64432014-11-11 20:02:42 +0000919
Greg Rose5eae00c2013-12-21 06:12:45 +0000920 q_vector = adapter->q_vector[q_idx];
921 napi = &q_vector->napi;
922 napi_enable(napi);
923 }
924}
925
926/**
927 * i40evf_napi_disable_all - disable NAPI on all queue vectors
928 * @adapter: board private structure
929 **/
930static void i40evf_napi_disable_all(struct i40evf_adapter *adapter)
931{
932 int q_idx;
933 struct i40e_q_vector *q_vector;
934 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
935
936 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
937 q_vector = adapter->q_vector[q_idx];
938 napi_disable(&q_vector->napi);
939 }
940}
941
942/**
943 * i40evf_configure - set up transmit and receive data structures
944 * @adapter: board private structure
945 **/
946static void i40evf_configure(struct i40evf_adapter *adapter)
947{
948 struct net_device *netdev = adapter->netdev;
949 int i;
950
951 i40evf_set_rx_mode(netdev);
952
953 i40evf_configure_tx(adapter);
954 i40evf_configure_rx(adapter);
955 adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
956
Mitch Williamscc052922014-10-25 03:24:34 +0000957 for (i = 0; i < adapter->num_active_queues; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000958 struct i40e_ring *ring = adapter->rx_rings[i];
Mitch Williams75a64432014-11-11 20:02:42 +0000959
Mitch Williamsa132af22015-01-24 09:58:35 +0000960 i40evf_alloc_rx_buffers_1buf(ring, ring->count);
Greg Rose5eae00c2013-12-21 06:12:45 +0000961 ring->next_to_use = ring->count - 1;
962 writel(ring->next_to_use, ring->tail);
963 }
964}
965
966/**
967 * i40evf_up_complete - Finish the last steps of bringing up a connection
968 * @adapter: board private structure
969 **/
970static int i40evf_up_complete(struct i40evf_adapter *adapter)
971{
972 adapter->state = __I40EVF_RUNNING;
973 clear_bit(__I40E_DOWN, &adapter->vsi.state);
974
975 i40evf_napi_enable_all(adapter);
976
977 adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
978 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
979 return 0;
980}
981
982/**
Greg Rose5eae00c2013-12-21 06:12:45 +0000983 * i40e_down - Shutdown the connection processing
984 * @adapter: board private structure
985 **/
986void i40evf_down(struct i40evf_adapter *adapter)
987{
988 struct net_device *netdev = adapter->netdev;
989 struct i40evf_mac_filter *f;
990
Mitch Williamsddf0b3a2014-05-22 06:31:46 +0000991 if (adapter->state == __I40EVF_DOWN)
992 return;
993
Mitch A Williams53d0b3a2014-12-09 08:53:04 +0000994 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
995 &adapter->crit_section))
996 usleep_range(500, 1000);
997
Mitch Williams63e18c22015-03-27 00:12:10 -0700998 netif_carrier_off(netdev);
999 netif_tx_disable(netdev);
Mitch Williams748c4342015-01-29 07:17:18 +00001000 i40evf_napi_disable_all(adapter);
Mitch Williams63e18c22015-03-27 00:12:10 -07001001 i40evf_irq_disable(adapter);
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001002
Mitch Williamsef8693e2014-02-13 03:48:53 -08001003 /* remove all MAC filters */
Greg Rose5eae00c2013-12-21 06:12:45 +00001004 list_for_each_entry(f, &adapter->mac_filter_list, list) {
1005 f->remove = true;
1006 }
Mitch Williamsed1f5b52014-02-20 19:29:06 -08001007 /* remove all VLAN filters */
1008 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
1009 f->remove = true;
1010 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001011 if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) &&
1012 adapter->state != __I40EVF_RESETTING) {
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001013 /* cancel any current operation */
1014 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001015 /* Schedule operations to close down the HW. Don't wait
1016 * here for this to complete. The watchdog is still running
1017 * and it will take care of this.
1018 */
1019 adapter->aq_required = I40EVF_FLAG_AQ_DEL_MAC_FILTER;
Mitch Williamsed1f5b52014-02-20 19:29:06 -08001020 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001021 adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001022 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001023
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001024 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Greg Rose5eae00c2013-12-21 06:12:45 +00001025}
1026
1027/**
1028 * i40evf_acquire_msix_vectors - Setup the MSIX capability
1029 * @adapter: board private structure
1030 * @vectors: number of vectors to request
1031 *
1032 * Work with the OS to set up the MSIX vectors needed.
1033 *
1034 * Returns 0 on success, negative on failure
1035 **/
1036static int
1037i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors)
1038{
1039 int err, vector_threshold;
1040
1041 /* We'll want at least 3 (vector_threshold):
1042 * 0) Other (Admin Queue and link, mostly)
1043 * 1) TxQ[0] Cleanup
1044 * 2) RxQ[0] Cleanup
1045 */
1046 vector_threshold = MIN_MSIX_COUNT;
1047
1048 /* The more we get, the more we will assign to Tx/Rx Cleanup
1049 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1050 * Right now, we simply care about how many we'll get; we'll
1051 * set them up later while requesting irq's.
1052 */
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001053 err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
1054 vector_threshold, vectors);
1055 if (err < 0) {
Mitch Williams80e72892014-05-10 04:49:06 +00001056 dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001057 kfree(adapter->msix_entries);
1058 adapter->msix_entries = NULL;
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001059 return err;
Greg Rose5eae00c2013-12-21 06:12:45 +00001060 }
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001061
1062 /* Adjust for only the vectors we'll use, which is minimum
1063 * of max_msix_q_vectors + NONQ_VECS, or the number of
1064 * vectors we were allocated.
1065 */
1066 adapter->num_msix_vectors = err;
1067 return 0;
Greg Rose5eae00c2013-12-21 06:12:45 +00001068}
1069
1070/**
1071 * i40evf_free_queues - Free memory for all rings
1072 * @adapter: board private structure to initialize
1073 *
1074 * Free all of the memory associated with queue pairs.
1075 **/
1076static void i40evf_free_queues(struct i40evf_adapter *adapter)
1077{
1078 int i;
1079
1080 if (!adapter->vsi_res)
1081 return;
Mitch Williamscc052922014-10-25 03:24:34 +00001082 for (i = 0; i < adapter->num_active_queues; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001083 if (adapter->tx_rings[i])
1084 kfree_rcu(adapter->tx_rings[i], rcu);
1085 adapter->tx_rings[i] = NULL;
1086 adapter->rx_rings[i] = NULL;
1087 }
1088}
1089
1090/**
1091 * i40evf_alloc_queues - Allocate memory for all rings
1092 * @adapter: board private structure to initialize
1093 *
1094 * We allocate one ring per queue at run-time since we don't know the
1095 * number of queues at compile-time. The polling_netdev array is
1096 * intended for Multiqueue, but should work fine with a single queue.
1097 **/
1098static int i40evf_alloc_queues(struct i40evf_adapter *adapter)
1099{
1100 int i;
1101
Mitch Williamscc052922014-10-25 03:24:34 +00001102 for (i = 0; i < adapter->num_active_queues; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001103 struct i40e_ring *tx_ring;
1104 struct i40e_ring *rx_ring;
1105
Mitch Williams75a64432014-11-11 20:02:42 +00001106 tx_ring = kzalloc(sizeof(*tx_ring) * 2, GFP_KERNEL);
Greg Rose5eae00c2013-12-21 06:12:45 +00001107 if (!tx_ring)
1108 goto err_out;
1109
1110 tx_ring->queue_index = i;
1111 tx_ring->netdev = adapter->netdev;
1112 tx_ring->dev = &adapter->pdev->dev;
Mitch Williamsd732a182014-04-24 06:41:37 +00001113 tx_ring->count = adapter->tx_desc_count;
Greg Rose5eae00c2013-12-21 06:12:45 +00001114 adapter->tx_rings[i] = tx_ring;
1115
1116 rx_ring = &tx_ring[1];
1117 rx_ring->queue_index = i;
1118 rx_ring->netdev = adapter->netdev;
1119 rx_ring->dev = &adapter->pdev->dev;
Mitch Williamsd732a182014-04-24 06:41:37 +00001120 rx_ring->count = adapter->rx_desc_count;
Greg Rose5eae00c2013-12-21 06:12:45 +00001121 adapter->rx_rings[i] = rx_ring;
1122 }
1123
1124 return 0;
1125
1126err_out:
1127 i40evf_free_queues(adapter);
1128 return -ENOMEM;
1129}
1130
1131/**
1132 * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
1133 * @adapter: board private structure to initialize
1134 *
1135 * Attempt to configure the interrupts using the best available
1136 * capabilities of the hardware and the kernel.
1137 **/
1138static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter)
1139{
1140 int vector, v_budget;
1141 int pairs = 0;
1142 int err = 0;
1143
1144 if (!adapter->vsi_res) {
1145 err = -EIO;
1146 goto out;
1147 }
Mitch Williamscc052922014-10-25 03:24:34 +00001148 pairs = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +00001149
1150 /* It's easy to be greedy for MSI-X vectors, but it really
1151 * doesn't do us much good if we have a lot more vectors
1152 * than CPU's. So let's be conservative and only ask for
1153 * (roughly) twice the number of vectors as there are CPU's.
1154 */
Mitch Williams30a500e2014-02-11 08:27:52 +00001155 v_budget = min_t(int, pairs, (int)(num_online_cpus() * 2)) + NONQ_VECS;
1156 v_budget = min_t(int, v_budget, (int)adapter->vf_res->max_vectors);
Greg Rose5eae00c2013-12-21 06:12:45 +00001157
Greg Rose5eae00c2013-12-21 06:12:45 +00001158 adapter->msix_entries = kcalloc(v_budget,
1159 sizeof(struct msix_entry), GFP_KERNEL);
1160 if (!adapter->msix_entries) {
1161 err = -ENOMEM;
1162 goto out;
1163 }
1164
1165 for (vector = 0; vector < v_budget; vector++)
1166 adapter->msix_entries[vector].entry = vector;
1167
1168 i40evf_acquire_msix_vectors(adapter, v_budget);
1169
1170out:
1171 adapter->netdev->real_num_tx_queues = pairs;
1172 return err;
1173}
1174
1175/**
1176 * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
1177 * @adapter: board private structure to initialize
1178 *
1179 * We allocate one q_vector per queue interrupt. If allocation fails we
1180 * return -ENOMEM.
1181 **/
1182static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter)
1183{
1184 int q_idx, num_q_vectors;
1185 struct i40e_q_vector *q_vector;
1186
1187 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
1188
1189 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Mitch Williams75a64432014-11-11 20:02:42 +00001190 q_vector = kzalloc(sizeof(*q_vector), GFP_KERNEL);
Greg Rose5eae00c2013-12-21 06:12:45 +00001191 if (!q_vector)
1192 goto err_out;
1193 q_vector->adapter = adapter;
1194 q_vector->vsi = &adapter->vsi;
1195 q_vector->v_idx = q_idx;
1196 netif_napi_add(adapter->netdev, &q_vector->napi,
Mitch Williams75a64432014-11-11 20:02:42 +00001197 i40evf_napi_poll, NAPI_POLL_WEIGHT);
Greg Rose5eae00c2013-12-21 06:12:45 +00001198 adapter->q_vector[q_idx] = q_vector;
1199 }
1200
1201 return 0;
1202
1203err_out:
1204 while (q_idx) {
1205 q_idx--;
1206 q_vector = adapter->q_vector[q_idx];
1207 netif_napi_del(&q_vector->napi);
1208 kfree(q_vector);
1209 adapter->q_vector[q_idx] = NULL;
1210 }
1211 return -ENOMEM;
1212}
1213
1214/**
1215 * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
1216 * @adapter: board private structure to initialize
1217 *
1218 * This function frees the memory allocated to the q_vectors. In addition if
1219 * NAPI is enabled it will delete any references to the NAPI struct prior
1220 * to freeing the q_vector.
1221 **/
1222static void i40evf_free_q_vectors(struct i40evf_adapter *adapter)
1223{
1224 int q_idx, num_q_vectors;
1225 int napi_vectors;
1226
1227 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
Mitch Williamscc052922014-10-25 03:24:34 +00001228 napi_vectors = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +00001229
1230 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
1231 struct i40e_q_vector *q_vector = adapter->q_vector[q_idx];
1232
1233 adapter->q_vector[q_idx] = NULL;
1234 if (q_idx < napi_vectors)
1235 netif_napi_del(&q_vector->napi);
1236 kfree(q_vector);
1237 }
1238}
1239
1240/**
1241 * i40evf_reset_interrupt_capability - Reset MSIX setup
1242 * @adapter: board private structure
1243 *
1244 **/
1245void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter)
1246{
1247 pci_disable_msix(adapter->pdev);
1248 kfree(adapter->msix_entries);
1249 adapter->msix_entries = NULL;
Greg Rose5eae00c2013-12-21 06:12:45 +00001250}
1251
1252/**
1253 * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
1254 * @adapter: board private structure to initialize
1255 *
1256 **/
1257int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter)
1258{
1259 int err;
1260
1261 err = i40evf_set_interrupt_capability(adapter);
1262 if (err) {
1263 dev_err(&adapter->pdev->dev,
1264 "Unable to setup interrupt capabilities\n");
1265 goto err_set_interrupt;
1266 }
1267
1268 err = i40evf_alloc_q_vectors(adapter);
1269 if (err) {
1270 dev_err(&adapter->pdev->dev,
1271 "Unable to allocate memory for queue vectors\n");
1272 goto err_alloc_q_vectors;
1273 }
1274
1275 err = i40evf_alloc_queues(adapter);
1276 if (err) {
1277 dev_err(&adapter->pdev->dev,
1278 "Unable to allocate memory for queues\n");
1279 goto err_alloc_queues;
1280 }
1281
1282 dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u",
Mitch Williams75a64432014-11-11 20:02:42 +00001283 (adapter->num_active_queues > 1) ? "Enabled" : "Disabled",
1284 adapter->num_active_queues);
Greg Rose5eae00c2013-12-21 06:12:45 +00001285
1286 return 0;
1287err_alloc_queues:
1288 i40evf_free_q_vectors(adapter);
1289err_alloc_q_vectors:
1290 i40evf_reset_interrupt_capability(adapter);
1291err_set_interrupt:
1292 return err;
1293}
1294
1295/**
1296 * i40evf_watchdog_timer - Periodic call-back timer
1297 * @data: pointer to adapter disguised as unsigned long
1298 **/
1299static void i40evf_watchdog_timer(unsigned long data)
1300{
1301 struct i40evf_adapter *adapter = (struct i40evf_adapter *)data;
Mitch Williams75a64432014-11-11 20:02:42 +00001302
Greg Rose5eae00c2013-12-21 06:12:45 +00001303 schedule_work(&adapter->watchdog_task);
1304 /* timer will be rescheduled in watchdog task */
1305}
1306
1307/**
1308 * i40evf_watchdog_task - Periodic call-back task
1309 * @work: pointer to work_struct
1310 **/
1311static void i40evf_watchdog_task(struct work_struct *work)
1312{
1313 struct i40evf_adapter *adapter = container_of(work,
Mitch Williams75a64432014-11-11 20:02:42 +00001314 struct i40evf_adapter,
1315 watchdog_task);
Greg Rose5eae00c2013-12-21 06:12:45 +00001316 struct i40e_hw *hw = &adapter->hw;
Ashish Shahfd358862014-08-01 13:27:11 -07001317 uint32_t rstat_val;
Greg Rose5eae00c2013-12-21 06:12:45 +00001318
Greg Rose5eae00c2013-12-21 06:12:45 +00001319 if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section))
Mitch Williamsef8693e2014-02-13 03:48:53 -08001320 goto restart_watchdog;
1321
1322 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
Ashish Shahfd358862014-08-01 13:27:11 -07001323 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1324 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1325 if ((rstat_val == I40E_VFR_VFACTIVE) ||
1326 (rstat_val == I40E_VFR_COMPLETED)) {
Mitch Williamsef8693e2014-02-13 03:48:53 -08001327 /* A chance for redemption! */
1328 dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n");
1329 adapter->state = __I40EVF_STARTUP;
1330 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
1331 schedule_delayed_work(&adapter->init_task, 10);
1332 clear_bit(__I40EVF_IN_CRITICAL_TASK,
1333 &adapter->crit_section);
1334 /* Don't reschedule the watchdog, since we've restarted
1335 * the init task. When init_task contacts the PF and
1336 * gets everything set up again, it'll restart the
1337 * watchdog for us. Down, boy. Sit. Stay. Woof.
1338 */
1339 return;
1340 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001341 adapter->aq_required = 0;
1342 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1343 goto watchdog_done;
1344 }
1345
1346 if ((adapter->state < __I40EVF_DOWN) ||
1347 (adapter->flags & I40EVF_FLAG_RESET_PENDING))
Greg Rose5eae00c2013-12-21 06:12:45 +00001348 goto watchdog_done;
1349
Mitch Williamsef8693e2014-02-13 03:48:53 -08001350 /* check for reset */
Ashish Shahfd358862014-08-01 13:27:11 -07001351 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
Mitch Williams75a64432014-11-11 20:02:42 +00001352 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001353 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) &&
Ashish Shahfd358862014-08-01 13:27:11 -07001354 (rstat_val != I40E_VFR_VFACTIVE) &&
1355 (rstat_val != I40E_VFR_COMPLETED)) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001356 adapter->state = __I40EVF_RESETTING;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001357 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
Mitch Williams249c8b82014-05-10 04:49:04 +00001358 dev_err(&adapter->pdev->dev, "Hardware reset detected\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001359 schedule_work(&adapter->reset_task);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001360 adapter->aq_required = 0;
1361 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001362 goto watchdog_done;
1363 }
1364
1365 /* Process admin queue tasks. After init, everything gets done
1366 * here so we don't race on the admin queue.
1367 */
Mitch Williamsed636962015-04-07 19:45:32 -04001368 if (adapter->current_op) {
Mitch A Williams0758e7cb2014-12-09 08:53:08 +00001369 if (!i40evf_asq_done(hw)) {
1370 dev_dbg(&adapter->pdev->dev, "Admin queue timeout\n");
1371 i40evf_send_api_ver(adapter);
1372 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001373 goto watchdog_done;
Mitch A Williams0758e7cb2014-12-09 08:53:08 +00001374 }
Mitch Williamse6d038d2015-06-04 16:23:58 -04001375 if (adapter->aq_required & I40EVF_FLAG_AQ_GET_CONFIG) {
1376 i40evf_send_vf_config_msg(adapter);
1377 goto watchdog_done;
1378 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001379
Mitch Williamse284fc82015-03-27 00:12:09 -07001380 if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) {
1381 i40evf_disable_queues(adapter);
1382 goto watchdog_done;
1383 }
1384
Greg Rose5eae00c2013-12-21 06:12:45 +00001385 if (adapter->aq_required & I40EVF_FLAG_AQ_MAP_VECTORS) {
1386 i40evf_map_queues(adapter);
1387 goto watchdog_done;
1388 }
1389
1390 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_MAC_FILTER) {
1391 i40evf_add_ether_addrs(adapter);
1392 goto watchdog_done;
1393 }
1394
1395 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_VLAN_FILTER) {
1396 i40evf_add_vlans(adapter);
1397 goto watchdog_done;
1398 }
1399
1400 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_MAC_FILTER) {
1401 i40evf_del_ether_addrs(adapter);
1402 goto watchdog_done;
1403 }
1404
1405 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_VLAN_FILTER) {
1406 i40evf_del_vlans(adapter);
1407 goto watchdog_done;
1408 }
1409
Greg Rose5eae00c2013-12-21 06:12:45 +00001410 if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_QUEUES) {
1411 i40evf_configure_queues(adapter);
1412 goto watchdog_done;
1413 }
1414
1415 if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_QUEUES) {
1416 i40evf_enable_queues(adapter);
1417 goto watchdog_done;
1418 }
1419
1420 if (adapter->state == __I40EVF_RUNNING)
1421 i40evf_request_stats(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001422watchdog_done:
Mitch A Williams4870e172014-12-09 08:53:06 +00001423 if (adapter->state == __I40EVF_RUNNING) {
1424 i40evf_irq_enable_queues(adapter, ~0);
1425 i40evf_fire_sw_int(adapter, 0xFF);
1426 } else {
1427 i40evf_fire_sw_int(adapter, 0x1);
1428 }
1429
Mitch Williamsef8693e2014-02-13 03:48:53 -08001430 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1431restart_watchdog:
Ashish Shahd3e2edb2014-08-01 13:27:12 -07001432 if (adapter->state == __I40EVF_REMOVE)
1433 return;
Greg Rose5eae00c2013-12-21 06:12:45 +00001434 if (adapter->aq_required)
1435 mod_timer(&adapter->watchdog_timer,
1436 jiffies + msecs_to_jiffies(20));
1437 else
1438 mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2));
Greg Rose5eae00c2013-12-21 06:12:45 +00001439 schedule_work(&adapter->adminq_task);
1440}
1441
Mitch A Williams5b7af022014-03-28 06:49:02 +00001442/**
Anjali Singhai Jain9a9c8ae2015-03-31 00:45:06 -07001443 * i40evf_configure_rss - Prepare for RSS
Greg Rose5eae00c2013-12-21 06:12:45 +00001444 * @adapter: board private structure
1445 **/
1446static void i40evf_configure_rss(struct i40evf_adapter *adapter)
1447{
Eric Dumazet22f258a2014-11-16 06:23:13 -08001448 u32 rss_key[I40E_VFQF_HKEY_MAX_INDEX + 1];
Greg Rose5eae00c2013-12-21 06:12:45 +00001449 struct i40e_hw *hw = &adapter->hw;
Anjali Singhai Jain9a9c8ae2015-03-31 00:45:06 -07001450 u32 cqueue = 0;
Greg Rose5eae00c2013-12-21 06:12:45 +00001451 u32 lut = 0;
1452 int i, j;
1453 u64 hena;
1454
Mitch Williamscc052922014-10-25 03:24:34 +00001455 /* Hash type is configured by the PF - we just supply the key */
Eric Dumazet22f258a2014-11-16 06:23:13 -08001456 netdev_rss_key_fill(rss_key, sizeof(rss_key));
Anjali Singhai Jain9a9c8ae2015-03-31 00:45:06 -07001457
1458 /* Fill out hash function seed */
Greg Rose5eae00c2013-12-21 06:12:45 +00001459 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
Eric Dumazet22f258a2014-11-16 06:23:13 -08001460 wr32(hw, I40E_VFQF_HKEY(i), rss_key[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00001461
1462 /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
1463 hena = I40E_DEFAULT_RSS_HENA;
1464 wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
1465 wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
1466
1467 /* Populate the LUT with max no. of queues in round robin fashion */
Mitch Williams96d47702014-02-11 08:27:50 +00001468 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) {
Anjali Singhai Jain9a9c8ae2015-03-31 00:45:06 -07001469 lut = 0;
1470 for (j = 0; j < 4; j++) {
Mitch Williams40746eb2015-06-22 17:26:38 -07001471 if (cqueue == adapter->num_active_queues)
Anjali Singhai Jain9a9c8ae2015-03-31 00:45:06 -07001472 cqueue = 0;
1473 lut |= ((cqueue) << (8 * j));
1474 cqueue++;
1475 }
Mitch Williams96d47702014-02-11 08:27:50 +00001476 wr32(hw, I40E_VFQF_HLUT(i), lut);
Greg Rose5eae00c2013-12-21 06:12:45 +00001477 }
1478 i40e_flush(hw);
1479}
1480
Mitch Williams67c818a2015-06-19 08:56:30 -07001481#define I40EVF_RESET_WAIT_MS 10
1482#define I40EVF_RESET_WAIT_COUNT 500
Greg Rose5eae00c2013-12-21 06:12:45 +00001483/**
1484 * i40evf_reset_task - Call-back task to handle hardware reset
1485 * @work: pointer to work_struct
1486 *
1487 * During reset we need to shut down and reinitialize the admin queue
1488 * before we can use it to communicate with the PF again. We also clear
1489 * and reinit the rings because that context is lost as well.
1490 **/
1491static void i40evf_reset_task(struct work_struct *work)
1492{
Mitch Williamsef8693e2014-02-13 03:48:53 -08001493 struct i40evf_adapter *adapter = container_of(work,
1494 struct i40evf_adapter,
1495 reset_task);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001496 struct net_device *netdev = adapter->netdev;
Greg Rose5eae00c2013-12-21 06:12:45 +00001497 struct i40e_hw *hw = &adapter->hw;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001498 struct i40evf_mac_filter *f;
Greg Rose5eae00c2013-12-21 06:12:45 +00001499 uint32_t rstat_val;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001500 int i = 0, err;
Greg Rose5eae00c2013-12-21 06:12:45 +00001501
1502 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
1503 &adapter->crit_section))
Neerav Parikhf98a2002014-09-13 07:40:44 +00001504 usleep_range(500, 1000);
Mitch Williams3526d802014-03-06 08:59:56 +00001505
Mitch Williams67c818a2015-06-19 08:56:30 -07001506 i40evf_misc_irq_disable(adapter);
Mitch Williams3526d802014-03-06 08:59:56 +00001507 if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) {
Mitch Williams67c818a2015-06-19 08:56:30 -07001508 adapter->flags &= ~I40EVF_FLAG_RESET_NEEDED;
1509 /* Restart the AQ here. If we have been reset but didn't
1510 * detect it, or if the PF had to reinit, our AQ will be hosed.
1511 */
1512 i40evf_shutdown_adminq(hw);
1513 i40evf_init_adminq(hw);
Mitch Williams3526d802014-03-06 08:59:56 +00001514 i40evf_request_reset(adapter);
1515 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001516 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
Mitch Williams3526d802014-03-06 08:59:56 +00001517
Mitch Williamsef8693e2014-02-13 03:48:53 -08001518 /* poll until we see the reset actually happen */
1519 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001520 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1521 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
Ashish Shahfd358862014-08-01 13:27:11 -07001522 if ((rstat_val != I40E_VFR_VFACTIVE) &&
1523 (rstat_val != I40E_VFR_COMPLETED))
Greg Rose5eae00c2013-12-21 06:12:45 +00001524 break;
Mitch Williams67c818a2015-06-19 08:56:30 -07001525 usleep_range(500, 1000);
Greg Rose5eae00c2013-12-21 06:12:45 +00001526 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001527 if (i == I40EVF_RESET_WAIT_COUNT) {
Mitch Williams67c818a2015-06-19 08:56:30 -07001528 dev_info(&adapter->pdev->dev, "Never saw reset\n");
Mitch Williamsef8693e2014-02-13 03:48:53 -08001529 goto continue_reset; /* act like the reset happened */
1530 }
1531
1532 /* wait until the reset is complete and the PF is responding to us */
1533 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
1534 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1535 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
Mitch Williams67c818a2015-06-19 08:56:30 -07001536 if (rstat_val == I40E_VFR_VFACTIVE)
Mitch Williamsef8693e2014-02-13 03:48:53 -08001537 break;
Mitch Williamsc88e38c2014-11-11 20:03:13 +00001538 msleep(I40EVF_RESET_WAIT_MS);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001539 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001540 /* extra wait to make sure minimum wait is met */
1541 msleep(I40EVF_RESET_WAIT_MS);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001542 if (i == I40EVF_RESET_WAIT_COUNT) {
Mitch Williams6ba36a22014-08-01 13:27:14 -07001543 struct i40evf_mac_filter *f, *ftmp;
1544 struct i40evf_vlan_filter *fv, *fvtmp;
1545
Greg Rose5eae00c2013-12-21 06:12:45 +00001546 /* reset never finished */
Mitch Williams80e72892014-05-10 04:49:06 +00001547 dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n",
Mitch Williamsef8693e2014-02-13 03:48:53 -08001548 rstat_val);
1549 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
1550
Mitch Williams169f4072014-04-01 07:11:50 +00001551 if (netif_running(adapter->netdev)) {
1552 set_bit(__I40E_DOWN, &adapter->vsi.state);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001553 netif_carrier_off(netdev);
Mitch Williams67c818a2015-06-19 08:56:30 -07001554 netif_tx_disable(netdev);
1555 i40evf_napi_disable_all(adapter);
1556 i40evf_irq_disable(adapter);
Mitch Williams169f4072014-04-01 07:11:50 +00001557 i40evf_free_traffic_irqs(adapter);
1558 i40evf_free_all_tx_resources(adapter);
1559 i40evf_free_all_rx_resources(adapter);
1560 }
Mitch Williams6ba36a22014-08-01 13:27:14 -07001561
1562 /* Delete all of the filters, both MAC and VLAN. */
1563 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list,
1564 list) {
1565 list_del(&f->list);
1566 kfree(f);
1567 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001568
Mitch Williams6ba36a22014-08-01 13:27:14 -07001569 list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list,
1570 list) {
1571 list_del(&fv->list);
1572 kfree(fv);
1573 }
1574
Mitch Williamsef8693e2014-02-13 03:48:53 -08001575 i40evf_free_misc_irq(adapter);
1576 i40evf_reset_interrupt_capability(adapter);
1577 i40evf_free_queues(adapter);
Mitch Williamsd31944d2014-08-01 13:27:13 -07001578 i40evf_free_q_vectors(adapter);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001579 kfree(adapter->vf_res);
1580 i40evf_shutdown_adminq(hw);
1581 adapter->netdev->flags &= ~IFF_UP;
1582 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Mitch Williams67c818a2015-06-19 08:56:30 -07001583 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1584 dev_info(&adapter->pdev->dev, "Reset task did not complete, VF disabled\n");
Mitch Williamsef8693e2014-02-13 03:48:53 -08001585 return; /* Do not attempt to reinit. It's dead, Jim. */
Greg Rose5eae00c2013-12-21 06:12:45 +00001586 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001587
1588continue_reset:
Mitch Williams67c818a2015-06-19 08:56:30 -07001589 if (netif_running(adapter->netdev)) {
1590 netif_carrier_off(netdev);
1591 netif_tx_stop_all_queues(netdev);
1592 i40evf_napi_disable_all(adapter);
1593 }
Mitch Williamsac833bb2015-01-29 07:17:19 +00001594 i40evf_irq_disable(adapter);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001595
Greg Rose5eae00c2013-12-21 06:12:45 +00001596 adapter->state = __I40EVF_RESETTING;
Mitch Williams67c818a2015-06-19 08:56:30 -07001597 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1598
1599 /* free the Tx/Rx rings and descriptors, might be better to just
1600 * re-use them sometime in the future
1601 */
1602 i40evf_free_all_rx_resources(adapter);
1603 i40evf_free_all_tx_resources(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001604
1605 /* kill and reinit the admin queue */
1606 if (i40evf_shutdown_adminq(hw))
Mitch Williamsac833bb2015-01-29 07:17:19 +00001607 dev_warn(&adapter->pdev->dev, "Failed to shut down adminq\n");
1608 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001609 err = i40evf_init_adminq(hw);
1610 if (err)
Mitch Williamsac833bb2015-01-29 07:17:19 +00001611 dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n",
1612 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00001613
Mitch Williamse6d038d2015-06-04 16:23:58 -04001614 adapter->aq_required = I40EVF_FLAG_AQ_GET_CONFIG;
1615 adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001616
1617 /* re-add all MAC filters */
1618 list_for_each_entry(f, &adapter->mac_filter_list, list) {
1619 f->add = true;
1620 }
1621 /* re-add all VLAN filters */
1622 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
1623 f->add = true;
1624 }
Mitch Williamse6d038d2015-06-04 16:23:58 -04001625 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001626 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
Greg Rose5eae00c2013-12-21 06:12:45 +00001627 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Mitch Williams67c818a2015-06-19 08:56:30 -07001628 i40evf_misc_irq_enable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001629
1630 mod_timer(&adapter->watchdog_timer, jiffies + 2);
1631
1632 if (netif_running(adapter->netdev)) {
1633 /* allocate transmit descriptors */
1634 err = i40evf_setup_all_tx_resources(adapter);
1635 if (err)
1636 goto reset_err;
1637
1638 /* allocate receive descriptors */
1639 err = i40evf_setup_all_rx_resources(adapter);
1640 if (err)
1641 goto reset_err;
1642
1643 i40evf_configure(adapter);
1644
1645 err = i40evf_up_complete(adapter);
1646 if (err)
1647 goto reset_err;
1648
1649 i40evf_irq_enable(adapter, true);
Mitch Williams67c818a2015-06-19 08:56:30 -07001650 } else {
1651 adapter->state = __I40EVF_DOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001652 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001653
Greg Rose5eae00c2013-12-21 06:12:45 +00001654 return;
1655reset_err:
Mitch Williams80e72892014-05-10 04:49:06 +00001656 dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001657 i40evf_close(adapter->netdev);
1658}
1659
1660/**
1661 * i40evf_adminq_task - worker thread to clean the admin queue
1662 * @work: pointer to work_struct containing our data
1663 **/
1664static void i40evf_adminq_task(struct work_struct *work)
1665{
1666 struct i40evf_adapter *adapter =
1667 container_of(work, struct i40evf_adapter, adminq_task);
1668 struct i40e_hw *hw = &adapter->hw;
1669 struct i40e_arq_event_info event;
1670 struct i40e_virtchnl_msg *v_msg;
1671 i40e_status ret;
Mitch Williams912257e2014-05-22 06:32:07 +00001672 u32 val, oldval;
Greg Rose5eae00c2013-12-21 06:12:45 +00001673 u16 pending;
1674
Mitch Williamsef8693e2014-02-13 03:48:53 -08001675 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
Mitch A Williams72354482014-12-09 08:53:07 +00001676 goto out;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001677
Mitch Williams1001dc32014-11-11 20:02:19 +00001678 event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
1679 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +00001680 if (!event.msg_buf)
Mitch A Williams72354482014-12-09 08:53:07 +00001681 goto out;
Mitch Williams249c8b82014-05-10 04:49:04 +00001682
Greg Rose5eae00c2013-12-21 06:12:45 +00001683 v_msg = (struct i40e_virtchnl_msg *)&event.desc;
1684 do {
1685 ret = i40evf_clean_arq_element(hw, &event, &pending);
Mitch Williams8b011eb2015-01-09 11:18:17 +00001686 if (ret || !v_msg->v_opcode)
Greg Rose5eae00c2013-12-21 06:12:45 +00001687 break; /* No event to process or error cleaning ARQ */
1688
1689 i40evf_virtchnl_completion(adapter, v_msg->v_opcode,
1690 v_msg->v_retval, event.msg_buf,
Mitch Williams1001dc32014-11-11 20:02:19 +00001691 event.msg_len);
Mitch Williams75a64432014-11-11 20:02:42 +00001692 if (pending != 0)
Greg Rose5eae00c2013-12-21 06:12:45 +00001693 memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE);
Greg Rose5eae00c2013-12-21 06:12:45 +00001694 } while (pending);
1695
Mitch Williams67c818a2015-06-19 08:56:30 -07001696 if ((adapter->flags &
1697 (I40EVF_FLAG_RESET_PENDING | I40EVF_FLAG_RESET_NEEDED)) ||
1698 adapter->state == __I40EVF_RESETTING)
1699 goto freedom;
1700
Mitch Williams912257e2014-05-22 06:32:07 +00001701 /* check for error indications */
1702 val = rd32(hw, hw->aq.arq.len);
1703 oldval = val;
1704 if (val & I40E_VF_ARQLEN_ARQVFE_MASK) {
1705 dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n");
1706 val &= ~I40E_VF_ARQLEN_ARQVFE_MASK;
1707 }
1708 if (val & I40E_VF_ARQLEN_ARQOVFL_MASK) {
1709 dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n");
1710 val &= ~I40E_VF_ARQLEN_ARQOVFL_MASK;
1711 }
1712 if (val & I40E_VF_ARQLEN_ARQCRIT_MASK) {
1713 dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n");
1714 val &= ~I40E_VF_ARQLEN_ARQCRIT_MASK;
1715 }
1716 if (oldval != val)
1717 wr32(hw, hw->aq.arq.len, val);
1718
1719 val = rd32(hw, hw->aq.asq.len);
1720 oldval = val;
1721 if (val & I40E_VF_ATQLEN_ATQVFE_MASK) {
1722 dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n");
1723 val &= ~I40E_VF_ATQLEN_ATQVFE_MASK;
1724 }
1725 if (val & I40E_VF_ATQLEN_ATQOVFL_MASK) {
1726 dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n");
1727 val &= ~I40E_VF_ATQLEN_ATQOVFL_MASK;
1728 }
1729 if (val & I40E_VF_ATQLEN_ATQCRIT_MASK) {
1730 dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n");
1731 val &= ~I40E_VF_ATQLEN_ATQCRIT_MASK;
1732 }
1733 if (oldval != val)
1734 wr32(hw, hw->aq.asq.len, val);
1735
Mitch Williams67c818a2015-06-19 08:56:30 -07001736freedom:
Mitch A Williams72354482014-12-09 08:53:07 +00001737 kfree(event.msg_buf);
1738out:
Greg Rose5eae00c2013-12-21 06:12:45 +00001739 /* re-enable Admin queue interrupt cause */
1740 i40evf_misc_irq_enable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001741}
1742
1743/**
1744 * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
1745 * @adapter: board private structure
1746 *
1747 * Free all transmit software resources
1748 **/
Mitch Williamse284fc82015-03-27 00:12:09 -07001749void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter)
Greg Rose5eae00c2013-12-21 06:12:45 +00001750{
1751 int i;
1752
Mitch Williamscc052922014-10-25 03:24:34 +00001753 for (i = 0; i < adapter->num_active_queues; i++)
Greg Rose5eae00c2013-12-21 06:12:45 +00001754 if (adapter->tx_rings[i]->desc)
1755 i40evf_free_tx_resources(adapter->tx_rings[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00001756}
1757
1758/**
1759 * i40evf_setup_all_tx_resources - allocate all queues Tx resources
1760 * @adapter: board private structure
1761 *
1762 * If this function returns with an error, then it's possible one or
1763 * more of the rings is populated (while the rest are not). It is the
1764 * callers duty to clean those orphaned rings.
1765 *
1766 * Return 0 on success, negative on failure
1767 **/
1768static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter)
1769{
1770 int i, err = 0;
1771
Mitch Williamscc052922014-10-25 03:24:34 +00001772 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williamsd732a182014-04-24 06:41:37 +00001773 adapter->tx_rings[i]->count = adapter->tx_desc_count;
Greg Rose5eae00c2013-12-21 06:12:45 +00001774 err = i40evf_setup_tx_descriptors(adapter->tx_rings[i]);
1775 if (!err)
1776 continue;
1777 dev_err(&adapter->pdev->dev,
1778 "%s: Allocation for Tx Queue %u failed\n",
1779 __func__, i);
1780 break;
1781 }
1782
1783 return err;
1784}
1785
1786/**
1787 * i40evf_setup_all_rx_resources - allocate all queues Rx resources
1788 * @adapter: board private structure
1789 *
1790 * If this function returns with an error, then it's possible one or
1791 * more of the rings is populated (while the rest are not). It is the
1792 * callers duty to clean those orphaned rings.
1793 *
1794 * Return 0 on success, negative on failure
1795 **/
1796static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter)
1797{
1798 int i, err = 0;
1799
Mitch Williamscc052922014-10-25 03:24:34 +00001800 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williamsd732a182014-04-24 06:41:37 +00001801 adapter->rx_rings[i]->count = adapter->rx_desc_count;
Greg Rose5eae00c2013-12-21 06:12:45 +00001802 err = i40evf_setup_rx_descriptors(adapter->rx_rings[i]);
1803 if (!err)
1804 continue;
1805 dev_err(&adapter->pdev->dev,
1806 "%s: Allocation for Rx Queue %u failed\n",
1807 __func__, i);
1808 break;
1809 }
1810 return err;
1811}
1812
1813/**
1814 * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
1815 * @adapter: board private structure
1816 *
1817 * Free all receive software resources
1818 **/
Mitch Williamse284fc82015-03-27 00:12:09 -07001819void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter)
Greg Rose5eae00c2013-12-21 06:12:45 +00001820{
1821 int i;
1822
Mitch Williamscc052922014-10-25 03:24:34 +00001823 for (i = 0; i < adapter->num_active_queues; i++)
Greg Rose5eae00c2013-12-21 06:12:45 +00001824 if (adapter->rx_rings[i]->desc)
1825 i40evf_free_rx_resources(adapter->rx_rings[i]);
1826}
1827
1828/**
1829 * i40evf_open - Called when a network interface is made active
1830 * @netdev: network interface device structure
1831 *
1832 * Returns 0 on success, negative value on failure
1833 *
1834 * The open entry point is called when a network interface is made
1835 * active by the system (IFF_UP). At this point all resources needed
1836 * for transmit and receive operations are allocated, the interrupt
1837 * handler is registered with the OS, the watchdog timer is started,
1838 * and the stack is notified that the interface is ready.
1839 **/
1840static int i40evf_open(struct net_device *netdev)
1841{
1842 struct i40evf_adapter *adapter = netdev_priv(netdev);
1843 int err;
1844
Mitch Williamsef8693e2014-02-13 03:48:53 -08001845 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
1846 dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
1847 return -EIO;
1848 }
Mitch Williamse284fc82015-03-27 00:12:09 -07001849 if (adapter->state != __I40EVF_DOWN || adapter->aq_required)
Greg Rose5eae00c2013-12-21 06:12:45 +00001850 return -EBUSY;
1851
1852 /* allocate transmit descriptors */
1853 err = i40evf_setup_all_tx_resources(adapter);
1854 if (err)
1855 goto err_setup_tx;
1856
1857 /* allocate receive descriptors */
1858 err = i40evf_setup_all_rx_resources(adapter);
1859 if (err)
1860 goto err_setup_rx;
1861
1862 /* clear any pending interrupts, may auto mask */
1863 err = i40evf_request_traffic_irqs(adapter, netdev->name);
1864 if (err)
1865 goto err_req_irq;
1866
Mitch Williams44151cd2015-04-27 14:57:17 -04001867 i40evf_add_filter(adapter, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00001868 i40evf_configure(adapter);
1869
1870 err = i40evf_up_complete(adapter);
1871 if (err)
1872 goto err_req_irq;
1873
1874 i40evf_irq_enable(adapter, true);
1875
1876 return 0;
1877
1878err_req_irq:
1879 i40evf_down(adapter);
1880 i40evf_free_traffic_irqs(adapter);
1881err_setup_rx:
1882 i40evf_free_all_rx_resources(adapter);
1883err_setup_tx:
1884 i40evf_free_all_tx_resources(adapter);
1885
1886 return err;
1887}
1888
1889/**
1890 * i40evf_close - Disables a network interface
1891 * @netdev: network interface device structure
1892 *
1893 * Returns 0, this is not allowed to fail
1894 *
1895 * The close entry point is called when an interface is de-activated
1896 * by the OS. The hardware is still under the drivers control, but
1897 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
1898 * are freed, along with all transmit and receive resources.
1899 **/
1900static int i40evf_close(struct net_device *netdev)
1901{
1902 struct i40evf_adapter *adapter = netdev_priv(netdev);
1903
Mitch Williamsef8693e2014-02-13 03:48:53 -08001904 if (adapter->state <= __I40EVF_DOWN)
1905 return 0;
1906
Mitch Williamsef8693e2014-02-13 03:48:53 -08001907
Greg Rose5eae00c2013-12-21 06:12:45 +00001908 set_bit(__I40E_DOWN, &adapter->vsi.state);
1909
1910 i40evf_down(adapter);
Mitch Williamsddf0b3a2014-05-22 06:31:46 +00001911 adapter->state = __I40EVF_DOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001912 i40evf_free_traffic_irqs(adapter);
1913
Greg Rose5eae00c2013-12-21 06:12:45 +00001914 return 0;
1915}
1916
1917/**
1918 * i40evf_get_stats - Get System Network Statistics
1919 * @netdev: network interface device structure
1920 *
1921 * Returns the address of the device statistics structure.
1922 * The statistics are actually updated from the timer callback.
1923 **/
1924static struct net_device_stats *i40evf_get_stats(struct net_device *netdev)
1925{
1926 struct i40evf_adapter *adapter = netdev_priv(netdev);
1927
1928 /* only return the current stats */
1929 return &adapter->net_stats;
1930}
1931
1932/**
Greg Rose5eae00c2013-12-21 06:12:45 +00001933 * i40evf_change_mtu - Change the Maximum Transfer Unit
1934 * @netdev: network interface device structure
1935 * @new_mtu: new value for maximum frame size
1936 *
1937 * Returns 0 on success, negative on failure
1938 **/
1939static int i40evf_change_mtu(struct net_device *netdev, int new_mtu)
1940{
1941 struct i40evf_adapter *adapter = netdev_priv(netdev);
1942 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
1943
1944 if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
1945 return -EINVAL;
1946
Greg Rose5eae00c2013-12-21 06:12:45 +00001947 netdev->mtu = new_mtu;
Mitch Williams67c818a2015-06-19 08:56:30 -07001948 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
1949 schedule_work(&adapter->reset_task);
1950
Greg Rose5eae00c2013-12-21 06:12:45 +00001951 return 0;
1952}
1953
1954static const struct net_device_ops i40evf_netdev_ops = {
1955 .ndo_open = i40evf_open,
1956 .ndo_stop = i40evf_close,
1957 .ndo_start_xmit = i40evf_xmit_frame,
1958 .ndo_get_stats = i40evf_get_stats,
1959 .ndo_set_rx_mode = i40evf_set_rx_mode,
1960 .ndo_validate_addr = eth_validate_addr,
1961 .ndo_set_mac_address = i40evf_set_mac,
1962 .ndo_change_mtu = i40evf_change_mtu,
1963 .ndo_tx_timeout = i40evf_tx_timeout,
1964 .ndo_vlan_rx_add_vid = i40evf_vlan_rx_add_vid,
1965 .ndo_vlan_rx_kill_vid = i40evf_vlan_rx_kill_vid,
1966};
1967
1968/**
1969 * i40evf_check_reset_complete - check that VF reset is complete
1970 * @hw: pointer to hw struct
1971 *
1972 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
1973 **/
1974static int i40evf_check_reset_complete(struct i40e_hw *hw)
1975{
1976 u32 rstat;
1977 int i;
1978
1979 for (i = 0; i < 100; i++) {
Ashish Shahfd358862014-08-01 13:27:11 -07001980 rstat = rd32(hw, I40E_VFGEN_RSTAT) &
1981 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1982 if ((rstat == I40E_VFR_VFACTIVE) ||
1983 (rstat == I40E_VFR_COMPLETED))
Greg Rose5eae00c2013-12-21 06:12:45 +00001984 return 0;
Neerav Parikhf98a2002014-09-13 07:40:44 +00001985 usleep_range(10, 20);
Greg Rose5eae00c2013-12-21 06:12:45 +00001986 }
1987 return -EBUSY;
1988}
1989
1990/**
Mitch Williamse6d038d2015-06-04 16:23:58 -04001991 * i40evf_process_config - Process the config information we got from the PF
1992 * @adapter: board private structure
1993 *
1994 * Verify that we have a valid config struct, and set up our netdev features
1995 * and our VSI struct.
1996 **/
1997int i40evf_process_config(struct i40evf_adapter *adapter)
1998{
1999 struct net_device *netdev = adapter->netdev;
2000 int i;
2001
2002 /* got VF config message back from PF, now we can parse it */
2003 for (i = 0; i < adapter->vf_res->num_vsis; i++) {
2004 if (adapter->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
2005 adapter->vsi_res = &adapter->vf_res->vsi_res[i];
2006 }
2007 if (!adapter->vsi_res) {
2008 dev_err(&adapter->pdev->dev, "No LAN VSI found\n");
2009 return -ENODEV;
2010 }
2011
2012 if (adapter->vf_res->vf_offload_flags
2013 & I40E_VIRTCHNL_VF_OFFLOAD_VLAN) {
2014 netdev->vlan_features = netdev->features;
2015 netdev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2016 NETIF_F_HW_VLAN_CTAG_RX |
2017 NETIF_F_HW_VLAN_CTAG_FILTER;
2018 }
2019 netdev->features |= NETIF_F_HIGHDMA |
2020 NETIF_F_SG |
2021 NETIF_F_IP_CSUM |
2022 NETIF_F_SCTP_CSUM |
2023 NETIF_F_IPV6_CSUM |
2024 NETIF_F_TSO |
2025 NETIF_F_TSO6 |
2026 NETIF_F_RXCSUM |
2027 NETIF_F_GRO;
2028
2029 /* copy netdev features into list of user selectable features */
2030 netdev->hw_features |= netdev->features;
2031 netdev->hw_features &= ~NETIF_F_RXCSUM;
2032
2033 adapter->vsi.id = adapter->vsi_res->vsi_id;
2034
2035 adapter->vsi.back = adapter;
2036 adapter->vsi.base_vector = 1;
2037 adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK;
2038 adapter->vsi.rx_itr_setting = (I40E_ITR_DYNAMIC |
2039 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
2040 adapter->vsi.tx_itr_setting = (I40E_ITR_DYNAMIC |
2041 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
2042 adapter->vsi.netdev = adapter->netdev;
2043 return 0;
2044}
2045
2046/**
Greg Rose5eae00c2013-12-21 06:12:45 +00002047 * i40evf_init_task - worker thread to perform delayed initialization
2048 * @work: pointer to work_struct containing our data
2049 *
2050 * This task completes the work that was begun in probe. Due to the nature
2051 * of VF-PF communications, we may need to wait tens of milliseconds to get
Joe Perchesdbedd442015-03-06 20:49:12 -08002052 * responses back from the PF. Rather than busy-wait in probe and bog down the
Greg Rose5eae00c2013-12-21 06:12:45 +00002053 * whole system, we'll do it in a task so we can sleep.
2054 * This task only runs during driver init. Once we've established
2055 * communications with the PF driver and set up our netdev, the watchdog
2056 * takes over.
2057 **/
2058static void i40evf_init_task(struct work_struct *work)
2059{
2060 struct i40evf_adapter *adapter = container_of(work,
2061 struct i40evf_adapter,
2062 init_task.work);
2063 struct net_device *netdev = adapter->netdev;
Greg Rose5eae00c2013-12-21 06:12:45 +00002064 struct i40e_hw *hw = &adapter->hw;
2065 struct pci_dev *pdev = adapter->pdev;
Mitch Williamse6d038d2015-06-04 16:23:58 -04002066 int err, bufsz;
Greg Rose5eae00c2013-12-21 06:12:45 +00002067
2068 switch (adapter->state) {
2069 case __I40EVF_STARTUP:
2070 /* driver loaded, probe complete */
Mitch Williamsef8693e2014-02-13 03:48:53 -08002071 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
2072 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
Greg Rose5eae00c2013-12-21 06:12:45 +00002073 err = i40e_set_mac_type(hw);
2074 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002075 dev_err(&pdev->dev, "Failed to set MAC type (%d)\n",
2076 err);
Mitch Williams2619ef42015-04-07 19:45:30 -04002077 goto err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002078 }
2079 err = i40evf_check_reset_complete(hw);
2080 if (err) {
Mitch Williams0d9c7ea2014-04-23 04:50:00 +00002081 dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n",
Mitch Williams75a64432014-11-11 20:02:42 +00002082 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002083 goto err;
2084 }
2085 hw->aq.num_arq_entries = I40EVF_AQ_LEN;
2086 hw->aq.num_asq_entries = I40EVF_AQ_LEN;
2087 hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2088 hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2089
2090 err = i40evf_init_adminq(hw);
2091 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002092 dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n",
2093 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002094 goto err;
2095 }
2096 err = i40evf_send_api_ver(adapter);
2097 if (err) {
Mitch Williams10bdd672014-03-06 08:59:53 +00002098 dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002099 i40evf_shutdown_adminq(hw);
2100 goto err;
2101 }
2102 adapter->state = __I40EVF_INIT_VERSION_CHECK;
2103 goto restart;
Greg Rose5eae00c2013-12-21 06:12:45 +00002104 case __I40EVF_INIT_VERSION_CHECK:
Mitch Williams10bdd672014-03-06 08:59:53 +00002105 if (!i40evf_asq_done(hw)) {
Mitch Williams80e72892014-05-10 04:49:06 +00002106 dev_err(&pdev->dev, "Admin queue command never completed\n");
Mitch Williams906a6932014-11-13 03:06:12 +00002107 i40evf_shutdown_adminq(hw);
2108 adapter->state = __I40EVF_STARTUP;
Greg Rose5eae00c2013-12-21 06:12:45 +00002109 goto err;
Mitch Williams10bdd672014-03-06 08:59:53 +00002110 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002111
2112 /* aq msg sent, awaiting reply */
2113 err = i40evf_verify_api_ver(adapter);
2114 if (err) {
Mitch A Williamsd4f82fd2014-12-09 08:53:03 +00002115 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
Mitch Williams56f99202014-06-04 04:22:41 +00002116 err = i40evf_send_api_ver(adapter);
Mitch Williamsee1693e2015-06-04 16:23:59 -04002117 else
2118 dev_err(&pdev->dev, "Unsupported PF API version %d.%d, expected %d.%d\n",
2119 adapter->pf_version.major,
2120 adapter->pf_version.minor,
2121 I40E_VIRTCHNL_VERSION_MAJOR,
2122 I40E_VIRTCHNL_VERSION_MINOR);
Greg Rose5eae00c2013-12-21 06:12:45 +00002123 goto err;
2124 }
2125 err = i40evf_send_vf_config_msg(adapter);
2126 if (err) {
Mitch Williams3f2ab172014-06-04 04:22:40 +00002127 dev_err(&pdev->dev, "Unable to send config request (%d)\n",
Greg Rose5eae00c2013-12-21 06:12:45 +00002128 err);
2129 goto err;
2130 }
2131 adapter->state = __I40EVF_INIT_GET_RESOURCES;
2132 goto restart;
Greg Rose5eae00c2013-12-21 06:12:45 +00002133 case __I40EVF_INIT_GET_RESOURCES:
2134 /* aq msg sent, awaiting reply */
2135 if (!adapter->vf_res) {
2136 bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
2137 (I40E_MAX_VF_VSI *
2138 sizeof(struct i40e_virtchnl_vsi_resource));
2139 adapter->vf_res = kzalloc(bufsz, GFP_KERNEL);
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002140 if (!adapter->vf_res)
Greg Rose5eae00c2013-12-21 06:12:45 +00002141 goto err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002142 }
2143 err = i40evf_get_vf_config(adapter);
Mitch Williams906a6932014-11-13 03:06:12 +00002144 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) {
Mitch Williams906a6932014-11-13 03:06:12 +00002145 err = i40evf_send_vf_config_msg(adapter);
2146 goto err;
2147 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002148 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002149 dev_err(&pdev->dev, "Unable to get VF config (%d)\n",
2150 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002151 goto err_alloc;
2152 }
2153 adapter->state = __I40EVF_INIT_SW;
2154 break;
2155 default:
2156 goto err_alloc;
2157 }
Mitch Williamse6d038d2015-06-04 16:23:58 -04002158 if (i40evf_process_config(adapter))
Greg Rose5eae00c2013-12-21 06:12:45 +00002159 goto err_alloc;
Mitch Williamse6d038d2015-06-04 16:23:58 -04002160 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00002161
2162 adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED;
2163
Greg Rose5eae00c2013-12-21 06:12:45 +00002164 netdev->netdev_ops = &i40evf_netdev_ops;
2165 i40evf_set_ethtool_ops(netdev);
2166 netdev->watchdog_timeo = 5 * HZ;
Greg Rose3415e8c2014-01-30 12:40:27 +00002167
Greg Rose5eae00c2013-12-21 06:12:45 +00002168 if (!is_valid_ether_addr(adapter->hw.mac.addr)) {
Mitch Williamsb34f90e2014-05-10 04:49:07 +00002169 dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n",
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002170 adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002171 random_ether_addr(adapter->hw.mac.addr);
2172 }
Greg Rose9a173902014-05-22 06:32:02 +00002173 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
2174 ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002175
Greg Rose5eae00c2013-12-21 06:12:45 +00002176 init_timer(&adapter->watchdog_timer);
2177 adapter->watchdog_timer.function = &i40evf_watchdog_timer;
2178 adapter->watchdog_timer.data = (unsigned long)adapter;
2179 mod_timer(&adapter->watchdog_timer, jiffies + 1);
2180
Mitch Williamscc052922014-10-25 03:24:34 +00002181 adapter->num_active_queues = min_t(int,
2182 adapter->vsi_res->num_queue_pairs,
2183 (int)(num_online_cpus()));
Mitch Williamsd732a182014-04-24 06:41:37 +00002184 adapter->tx_desc_count = I40EVF_DEFAULT_TXD;
2185 adapter->rx_desc_count = I40EVF_DEFAULT_RXD;
Greg Rose5eae00c2013-12-21 06:12:45 +00002186 err = i40evf_init_interrupt_scheme(adapter);
2187 if (err)
2188 goto err_sw_init;
2189 i40evf_map_rings_to_vectors(adapter);
2190 i40evf_configure_rss(adapter);
2191 err = i40evf_request_misc_irq(adapter);
2192 if (err)
2193 goto err_sw_init;
2194
2195 netif_carrier_off(netdev);
2196
Mitch Williamsef8693e2014-02-13 03:48:53 -08002197 if (!adapter->netdev_registered) {
2198 err = register_netdev(netdev);
2199 if (err)
2200 goto err_register;
2201 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002202
2203 adapter->netdev_registered = true;
2204
2205 netif_tx_stop_all_queues(netdev);
2206
Mitch Williamsb34f90e2014-05-10 04:49:07 +00002207 dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002208 if (netdev->features & NETIF_F_GRO)
2209 dev_info(&pdev->dev, "GRO is enabled\n");
2210
2211 dev_info(&pdev->dev, "%s\n", i40evf_driver_string);
2212 adapter->state = __I40EVF_DOWN;
2213 set_bit(__I40E_DOWN, &adapter->vsi.state);
2214 i40evf_misc_irq_enable(adapter);
2215 return;
2216restart:
2217 schedule_delayed_work(&adapter->init_task,
2218 msecs_to_jiffies(50));
2219 return;
2220
2221err_register:
2222 i40evf_free_misc_irq(adapter);
2223err_sw_init:
2224 i40evf_reset_interrupt_capability(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002225err_alloc:
2226 kfree(adapter->vf_res);
2227 adapter->vf_res = NULL;
2228err:
2229 /* Things went into the weeds, so try again later */
2230 if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) {
Mitch Williams80e72892014-05-10 04:49:06 +00002231 dev_err(&pdev->dev, "Failed to communicate with PF; giving up\n");
Mitch Williamsef8693e2014-02-13 03:48:53 -08002232 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
Greg Rose5eae00c2013-12-21 06:12:45 +00002233 return; /* do not reschedule */
2234 }
2235 schedule_delayed_work(&adapter->init_task, HZ * 3);
Greg Rose5eae00c2013-12-21 06:12:45 +00002236}
2237
2238/**
2239 * i40evf_shutdown - Shutdown the device in preparation for a reboot
2240 * @pdev: pci device structure
2241 **/
2242static void i40evf_shutdown(struct pci_dev *pdev)
2243{
2244 struct net_device *netdev = pci_get_drvdata(pdev);
Mitch Williams00293fd2015-01-09 11:18:18 +00002245 struct i40evf_adapter *adapter = netdev_priv(netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +00002246
2247 netif_device_detach(netdev);
2248
2249 if (netif_running(netdev))
2250 i40evf_close(netdev);
2251
Mitch Williams00293fd2015-01-09 11:18:18 +00002252 /* Prevent the watchdog from running. */
2253 adapter->state = __I40EVF_REMOVE;
2254 adapter->aq_required = 0;
Mitch Williams00293fd2015-01-09 11:18:18 +00002255
Greg Rose5eae00c2013-12-21 06:12:45 +00002256#ifdef CONFIG_PM
2257 pci_save_state(pdev);
2258
2259#endif
2260 pci_disable_device(pdev);
2261}
2262
2263/**
2264 * i40evf_probe - Device Initialization Routine
2265 * @pdev: PCI device information struct
2266 * @ent: entry in i40evf_pci_tbl
2267 *
2268 * Returns 0 on success, negative on failure
2269 *
2270 * i40evf_probe initializes an adapter identified by a pci_dev structure.
2271 * The OS initialization, configuring of the adapter private structure,
2272 * and a hardware reset occur.
2273 **/
2274static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2275{
2276 struct net_device *netdev;
2277 struct i40evf_adapter *adapter = NULL;
2278 struct i40e_hw *hw = NULL;
Mitch Williamsdbbd8112014-02-20 19:29:08 -08002279 int err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002280
2281 err = pci_enable_device(pdev);
2282 if (err)
2283 return err;
2284
Mitch Williams64942942014-02-11 08:26:33 +00002285 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Mitch Williams64942942014-02-11 08:26:33 +00002286 if (err) {
Jean Sacrene3e3bfd2014-03-25 04:30:27 +00002287 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2288 if (err) {
2289 dev_err(&pdev->dev,
2290 "DMA configuration failed: 0x%x\n", err);
2291 goto err_dma;
2292 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002293 }
2294
2295 err = pci_request_regions(pdev, i40evf_driver_name);
2296 if (err) {
2297 dev_err(&pdev->dev,
2298 "pci_request_regions failed 0x%x\n", err);
2299 goto err_pci_reg;
2300 }
2301
2302 pci_enable_pcie_error_reporting(pdev);
2303
2304 pci_set_master(pdev);
2305
2306 netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter),
2307 MAX_TX_QUEUES);
2308 if (!netdev) {
2309 err = -ENOMEM;
2310 goto err_alloc_etherdev;
2311 }
2312
2313 SET_NETDEV_DEV(netdev, &pdev->dev);
2314
2315 pci_set_drvdata(pdev, netdev);
2316 adapter = netdev_priv(netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +00002317
2318 adapter->netdev = netdev;
2319 adapter->pdev = pdev;
2320
2321 hw = &adapter->hw;
2322 hw->back = adapter;
2323
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002324 adapter->msg_enable = BIT(DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
Greg Rose5eae00c2013-12-21 06:12:45 +00002325 adapter->state = __I40EVF_STARTUP;
2326
2327 /* Call save state here because it relies on the adapter struct. */
2328 pci_save_state(pdev);
2329
2330 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2331 pci_resource_len(pdev, 0));
2332 if (!hw->hw_addr) {
2333 err = -EIO;
2334 goto err_ioremap;
2335 }
2336 hw->vendor_id = pdev->vendor;
2337 hw->device_id = pdev->device;
2338 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2339 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2340 hw->subsystem_device_id = pdev->subsystem_device;
2341 hw->bus.device = PCI_SLOT(pdev->devfn);
2342 hw->bus.func = PCI_FUNC(pdev->devfn);
2343
Serey Kong8bb1a542014-08-01 13:27:15 -07002344 INIT_LIST_HEAD(&adapter->mac_filter_list);
2345 INIT_LIST_HEAD(&adapter->vlan_filter_list);
2346
Greg Rose5eae00c2013-12-21 06:12:45 +00002347 INIT_WORK(&adapter->reset_task, i40evf_reset_task);
2348 INIT_WORK(&adapter->adminq_task, i40evf_adminq_task);
2349 INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task);
2350 INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task);
2351 schedule_delayed_work(&adapter->init_task, 10);
2352
2353 return 0;
2354
2355err_ioremap:
2356 free_netdev(netdev);
2357err_alloc_etherdev:
2358 pci_release_regions(pdev);
2359err_pci_reg:
2360err_dma:
2361 pci_disable_device(pdev);
2362 return err;
2363}
2364
2365#ifdef CONFIG_PM
2366/**
2367 * i40evf_suspend - Power management suspend routine
2368 * @pdev: PCI device information struct
2369 * @state: unused
2370 *
2371 * Called when the system (VM) is entering sleep/suspend.
2372 **/
2373static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state)
2374{
2375 struct net_device *netdev = pci_get_drvdata(pdev);
2376 struct i40evf_adapter *adapter = netdev_priv(netdev);
2377 int retval = 0;
2378
2379 netif_device_detach(netdev);
2380
2381 if (netif_running(netdev)) {
2382 rtnl_lock();
2383 i40evf_down(adapter);
2384 rtnl_unlock();
2385 }
2386 i40evf_free_misc_irq(adapter);
2387 i40evf_reset_interrupt_capability(adapter);
2388
2389 retval = pci_save_state(pdev);
2390 if (retval)
2391 return retval;
2392
2393 pci_disable_device(pdev);
2394
2395 return 0;
2396}
2397
2398/**
Joe Perchesdbedd442015-03-06 20:49:12 -08002399 * i40evf_resume - Power management resume routine
Greg Rose5eae00c2013-12-21 06:12:45 +00002400 * @pdev: PCI device information struct
2401 *
2402 * Called when the system (VM) is resumed from sleep/suspend.
2403 **/
2404static int i40evf_resume(struct pci_dev *pdev)
2405{
2406 struct i40evf_adapter *adapter = pci_get_drvdata(pdev);
2407 struct net_device *netdev = adapter->netdev;
2408 u32 err;
2409
2410 pci_set_power_state(pdev, PCI_D0);
2411 pci_restore_state(pdev);
2412 /* pci_restore_state clears dev->state_saved so call
2413 * pci_save_state to restore it.
2414 */
2415 pci_save_state(pdev);
2416
2417 err = pci_enable_device_mem(pdev);
2418 if (err) {
2419 dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n");
2420 return err;
2421 }
2422 pci_set_master(pdev);
2423
2424 rtnl_lock();
2425 err = i40evf_set_interrupt_capability(adapter);
2426 if (err) {
2427 dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n");
2428 return err;
2429 }
2430 err = i40evf_request_misc_irq(adapter);
2431 rtnl_unlock();
2432 if (err) {
2433 dev_err(&pdev->dev, "Cannot get interrupt vector.\n");
2434 return err;
2435 }
2436
2437 schedule_work(&adapter->reset_task);
2438
2439 netif_device_attach(netdev);
2440
2441 return err;
2442}
2443
2444#endif /* CONFIG_PM */
2445/**
2446 * i40evf_remove - Device Removal Routine
2447 * @pdev: PCI device information struct
2448 *
2449 * i40evf_remove is called by the PCI subsystem to alert the driver
2450 * that it should release a PCI device. The could be caused by a
2451 * Hot-Plug event, or because the driver is going to be removed from
2452 * memory.
2453 **/
2454static void i40evf_remove(struct pci_dev *pdev)
2455{
2456 struct net_device *netdev = pci_get_drvdata(pdev);
2457 struct i40evf_adapter *adapter = netdev_priv(netdev);
Mitch Williams6ba36a22014-08-01 13:27:14 -07002458 struct i40evf_mac_filter *f, *ftmp;
Greg Rose5eae00c2013-12-21 06:12:45 +00002459 struct i40e_hw *hw = &adapter->hw;
2460
2461 cancel_delayed_work_sync(&adapter->init_task);
Mitch Williamsef8693e2014-02-13 03:48:53 -08002462 cancel_work_sync(&adapter->reset_task);
Greg Rose5eae00c2013-12-21 06:12:45 +00002463
2464 if (adapter->netdev_registered) {
2465 unregister_netdev(netdev);
2466 adapter->netdev_registered = false;
2467 }
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00002468
Mitch Williamsf4a71882015-01-09 11:18:16 +00002469 /* Shut down all the garbage mashers on the detention level */
Greg Rose5eae00c2013-12-21 06:12:45 +00002470 adapter->state = __I40EVF_REMOVE;
Mitch Williamsf4a71882015-01-09 11:18:16 +00002471 adapter->aq_required = 0;
Mitch Williamsf4a71882015-01-09 11:18:16 +00002472 i40evf_request_reset(adapter);
2473 msleep(20);
2474 /* If the FW isn't responding, kick it once, but only once. */
2475 if (!i40evf_asq_done(hw)) {
2476 i40evf_request_reset(adapter);
2477 msleep(20);
2478 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002479
Mitch Williamsdbb01c82014-02-20 19:29:07 -08002480 if (adapter->msix_entries) {
Greg Rose5eae00c2013-12-21 06:12:45 +00002481 i40evf_misc_irq_disable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002482 i40evf_free_misc_irq(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002483 i40evf_reset_interrupt_capability(adapter);
Mitch Williamsd31944d2014-08-01 13:27:13 -07002484 i40evf_free_q_vectors(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002485 }
2486
Mitch Williamse5d17c32014-06-04 04:22:38 +00002487 if (adapter->watchdog_timer.function)
2488 del_timer_sync(&adapter->watchdog_timer);
2489
Mitch Williamsdbb01c82014-02-20 19:29:07 -08002490 flush_scheduled_work();
2491
Greg Rose5eae00c2013-12-21 06:12:45 +00002492 if (hw->aq.asq.count)
2493 i40evf_shutdown_adminq(hw);
2494
2495 iounmap(hw->hw_addr);
2496 pci_release_regions(pdev);
2497
Mitch Williamse284fc82015-03-27 00:12:09 -07002498 i40evf_free_all_tx_resources(adapter);
2499 i40evf_free_all_rx_resources(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002500 i40evf_free_queues(adapter);
2501 kfree(adapter->vf_res);
Mitch Williams6ba36a22014-08-01 13:27:14 -07002502 /* If we got removed before an up/down sequence, we've got a filter
2503 * hanging out there that we need to get rid of.
2504 */
2505 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
2506 list_del(&f->list);
2507 kfree(f);
2508 }
Mitch A Williams37dfdf32014-12-09 08:53:05 +00002509 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
2510 list_del(&f->list);
2511 kfree(f);
2512 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002513
2514 free_netdev(netdev);
2515
2516 pci_disable_pcie_error_reporting(pdev);
2517
2518 pci_disable_device(pdev);
2519}
2520
2521static struct pci_driver i40evf_driver = {
2522 .name = i40evf_driver_name,
2523 .id_table = i40evf_pci_tbl,
2524 .probe = i40evf_probe,
2525 .remove = i40evf_remove,
2526#ifdef CONFIG_PM
2527 .suspend = i40evf_suspend,
2528 .resume = i40evf_resume,
2529#endif
2530 .shutdown = i40evf_shutdown,
2531};
2532
2533/**
2534 * i40e_init_module - Driver Registration Routine
2535 *
2536 * i40e_init_module is the first routine called when the driver is
2537 * loaded. All it does is register with the PCI subsystem.
2538 **/
2539static int __init i40evf_init_module(void)
2540{
2541 int ret;
Mitch Williams75a64432014-11-11 20:02:42 +00002542
Greg Rose5eae00c2013-12-21 06:12:45 +00002543 pr_info("i40evf: %s - version %s\n", i40evf_driver_string,
Mitch Williams75a64432014-11-11 20:02:42 +00002544 i40evf_driver_version);
Greg Rose5eae00c2013-12-21 06:12:45 +00002545
2546 pr_info("%s\n", i40evf_copyright);
2547
2548 ret = pci_register_driver(&i40evf_driver);
2549 return ret;
2550}
2551
2552module_init(i40evf_init_module);
2553
2554/**
2555 * i40e_exit_module - Driver Exit Cleanup Routine
2556 *
2557 * i40e_exit_module is called just before the driver is removed
2558 * from memory.
2559 **/
2560static void __exit i40evf_exit_module(void)
2561{
2562 pci_unregister_driver(&i40evf_driver);
2563}
2564
2565module_exit(i40evf_exit_module);
2566
2567/* i40evf_main.c */