blob: 46aef2a45cbfa9a9efaa6518a6c982845ea14e30 [file] [log] [blame]
Greg Rose5eae00c2013-12-21 06:12:45 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
Sravanthi Tangeda5b8eb172015-02-06 08:52:21 +00004 * Copyright(c) 2013 - 2015 Intel Corporation.
Greg Rose5eae00c2013-12-21 06:12:45 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Jesse Brandeburgb8316072014-04-05 07:46:11 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
Greg Rose5eae00c2013-12-21 06:12:45 +000018 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27#include "i40evf.h"
28#include "i40e_prototype.h"
29static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter);
30static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter);
31static int i40evf_close(struct net_device *netdev);
32
33char i40evf_driver_name[] = "i40evf";
34static const char i40evf_driver_string[] =
Mitch Williams0af56f42014-06-04 20:42:10 +000035 "Intel(R) XL710/X710 Virtual Function Network Driver";
Greg Rose5eae00c2013-12-21 06:12:45 +000036
Catherine Sullivanec7a06f2015-02-27 09:18:37 +000037#define DRV_VERSION "1.2.25"
Greg Rose5eae00c2013-12-21 06:12:45 +000038const char i40evf_driver_version[] = DRV_VERSION;
39static const char i40evf_copyright[] =
Mitch Williams673f2eb2014-02-20 19:29:13 -080040 "Copyright (c) 2013 - 2014 Intel Corporation.";
Greg Rose5eae00c2013-12-21 06:12:45 +000041
42/* i40evf_pci_tbl - PCI Device ID Table
43 *
44 * Wildcard entries (PCI_ANY_ID) should come last
45 * Last entry must be all 0s
46 *
47 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
48 * Class, Class Mask, private data (not used) }
49 */
Benoit Taine9baa3c32014-08-08 15:56:03 +020050static const struct pci_device_id i40evf_pci_tbl[] = {
Shannon Nelsonab600852014-01-17 15:36:39 -080051 {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF), 0},
Greg Rose5eae00c2013-12-21 06:12:45 +000052 /* required last entry */
53 {0, }
54};
55
56MODULE_DEVICE_TABLE(pci, i40evf_pci_tbl);
57
58MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
59MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver");
60MODULE_LICENSE("GPL");
61MODULE_VERSION(DRV_VERSION);
62
63/**
64 * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code
65 * @hw: pointer to the HW structure
66 * @mem: ptr to mem struct to fill out
67 * @size: size of memory requested
68 * @alignment: what to align the allocation to
69 **/
70i40e_status i40evf_allocate_dma_mem_d(struct i40e_hw *hw,
71 struct i40e_dma_mem *mem,
72 u64 size, u32 alignment)
73{
74 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
75
76 if (!mem)
77 return I40E_ERR_PARAM;
78
79 mem->size = ALIGN(size, alignment);
80 mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size,
81 (dma_addr_t *)&mem->pa, GFP_KERNEL);
82 if (mem->va)
83 return 0;
84 else
85 return I40E_ERR_NO_MEMORY;
86}
87
88/**
89 * i40evf_free_dma_mem_d - OS specific memory free for shared code
90 * @hw: pointer to the HW structure
91 * @mem: ptr to mem struct to free
92 **/
93i40e_status i40evf_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
94{
95 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
96
97 if (!mem || !mem->va)
98 return I40E_ERR_PARAM;
99 dma_free_coherent(&adapter->pdev->dev, mem->size,
100 mem->va, (dma_addr_t)mem->pa);
101 return 0;
102}
103
104/**
105 * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code
106 * @hw: pointer to the HW structure
107 * @mem: ptr to mem struct to fill out
108 * @size: size of memory requested
109 **/
110i40e_status i40evf_allocate_virt_mem_d(struct i40e_hw *hw,
111 struct i40e_virt_mem *mem, u32 size)
112{
113 if (!mem)
114 return I40E_ERR_PARAM;
115
116 mem->size = size;
117 mem->va = kzalloc(size, GFP_KERNEL);
118
119 if (mem->va)
120 return 0;
121 else
122 return I40E_ERR_NO_MEMORY;
123}
124
125/**
126 * i40evf_free_virt_mem_d - OS specific memory free for shared code
127 * @hw: pointer to the HW structure
128 * @mem: ptr to mem struct to free
129 **/
130i40e_status i40evf_free_virt_mem_d(struct i40e_hw *hw,
131 struct i40e_virt_mem *mem)
132{
133 if (!mem)
134 return I40E_ERR_PARAM;
135
136 /* it's ok to kfree a NULL pointer */
137 kfree(mem->va);
138
139 return 0;
140}
141
142/**
143 * i40evf_debug_d - OS dependent version of debug printing
144 * @hw: pointer to the HW structure
145 * @mask: debug level mask
146 * @fmt_str: printf-type format description
147 **/
148void i40evf_debug_d(void *hw, u32 mask, char *fmt_str, ...)
149{
150 char buf[512];
151 va_list argptr;
152
153 if (!(mask & ((struct i40e_hw *)hw)->debug_mask))
154 return;
155
156 va_start(argptr, fmt_str);
157 vsnprintf(buf, sizeof(buf), fmt_str, argptr);
158 va_end(argptr);
159
160 /* the debug string is already formatted with a newline */
161 pr_info("%s", buf);
162}
163
164/**
165 * i40evf_tx_timeout - Respond to a Tx Hang
166 * @netdev: network interface device structure
167 **/
168static void i40evf_tx_timeout(struct net_device *netdev)
169{
170 struct i40evf_adapter *adapter = netdev_priv(netdev);
171
172 adapter->tx_timeout_count++;
Mitch Williams625777e2014-02-20 19:29:05 -0800173 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
Mitch Williams3526d802014-03-06 08:59:56 +0000174 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
Mitch Williams625777e2014-02-20 19:29:05 -0800175 schedule_work(&adapter->reset_task);
176 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000177}
178
179/**
180 * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC
181 * @adapter: board private structure
182 **/
183static void i40evf_misc_irq_disable(struct i40evf_adapter *adapter)
184{
185 struct i40e_hw *hw = &adapter->hw;
Mitch Williams75a64432014-11-11 20:02:42 +0000186
Greg Rose5eae00c2013-12-21 06:12:45 +0000187 wr32(hw, I40E_VFINT_DYN_CTL01, 0);
188
189 /* read flush */
190 rd32(hw, I40E_VFGEN_RSTAT);
191
192 synchronize_irq(adapter->msix_entries[0].vector);
193}
194
195/**
196 * i40evf_misc_irq_enable - Enable default interrupt generation settings
197 * @adapter: board private structure
198 **/
199static void i40evf_misc_irq_enable(struct i40evf_adapter *adapter)
200{
201 struct i40e_hw *hw = &adapter->hw;
Mitch Williams75a64432014-11-11 20:02:42 +0000202
Greg Rose5eae00c2013-12-21 06:12:45 +0000203 wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK |
204 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK);
205 wr32(hw, I40E_VFINT_ICR0_ENA1, I40E_VFINT_ICR0_ENA_ADMINQ_MASK);
206
207 /* read flush */
208 rd32(hw, I40E_VFGEN_RSTAT);
209}
210
211/**
212 * i40evf_irq_disable - Mask off interrupt generation on the NIC
213 * @adapter: board private structure
214 **/
215static void i40evf_irq_disable(struct i40evf_adapter *adapter)
216{
217 int i;
218 struct i40e_hw *hw = &adapter->hw;
219
Mitch Williamsdbb01c82014-02-20 19:29:07 -0800220 if (!adapter->msix_entries)
221 return;
222
Greg Rose5eae00c2013-12-21 06:12:45 +0000223 for (i = 1; i < adapter->num_msix_vectors; i++) {
224 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), 0);
225 synchronize_irq(adapter->msix_entries[i].vector);
226 }
227 /* read flush */
228 rd32(hw, I40E_VFGEN_RSTAT);
Greg Rose5eae00c2013-12-21 06:12:45 +0000229}
230
231/**
232 * i40evf_irq_enable_queues - Enable interrupt for specified queues
233 * @adapter: board private structure
234 * @mask: bitmap of queues to enable
235 **/
236void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask)
237{
238 struct i40e_hw *hw = &adapter->hw;
239 int i;
240
241 for (i = 1; i < adapter->num_msix_vectors; i++) {
242 if (mask & (1 << (i - 1))) {
243 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1),
244 I40E_VFINT_DYN_CTLN1_INTENA_MASK |
Jesse Brandeburg97bf75f2015-02-27 09:18:32 +0000245 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
Greg Rose5eae00c2013-12-21 06:12:45 +0000246 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
247 }
248 }
249}
250
251/**
252 * i40evf_fire_sw_int - Generate SW interrupt for specified vectors
253 * @adapter: board private structure
254 * @mask: bitmap of vectors to trigger
255 **/
Mitch Williams75a64432014-11-11 20:02:42 +0000256static void i40evf_fire_sw_int(struct i40evf_adapter *adapter, u32 mask)
Greg Rose5eae00c2013-12-21 06:12:45 +0000257{
258 struct i40e_hw *hw = &adapter->hw;
259 int i;
260 uint32_t dyn_ctl;
261
Mitch Williams164ec1b2014-06-04 08:45:19 +0000262 if (mask & 1) {
263 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTL01);
264 dyn_ctl |= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK |
Jesse Brandeburg97bf75f2015-02-27 09:18:32 +0000265 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
Mitch Williams164ec1b2014-06-04 08:45:19 +0000266 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK;
267 wr32(hw, I40E_VFINT_DYN_CTL01, dyn_ctl);
268 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000269 for (i = 1; i < adapter->num_msix_vectors; i++) {
270 if (mask & (1 << i)) {
271 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTLN1(i - 1));
272 dyn_ctl |= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK |
Jesse Brandeburg97bf75f2015-02-27 09:18:32 +0000273 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
Greg Rose5eae00c2013-12-21 06:12:45 +0000274 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK;
275 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), dyn_ctl);
276 }
277 }
278}
279
280/**
281 * i40evf_irq_enable - Enable default interrupt generation settings
282 * @adapter: board private structure
283 **/
284void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush)
285{
286 struct i40e_hw *hw = &adapter->hw;
287
Mitch Williams164ec1b2014-06-04 08:45:19 +0000288 i40evf_misc_irq_enable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +0000289 i40evf_irq_enable_queues(adapter, ~0);
290
291 if (flush)
292 rd32(hw, I40E_VFGEN_RSTAT);
293}
294
295/**
296 * i40evf_msix_aq - Interrupt handler for vector 0
297 * @irq: interrupt number
298 * @data: pointer to netdev
299 **/
300static irqreturn_t i40evf_msix_aq(int irq, void *data)
301{
302 struct net_device *netdev = data;
303 struct i40evf_adapter *adapter = netdev_priv(netdev);
304 struct i40e_hw *hw = &adapter->hw;
305 u32 val;
306 u32 ena_mask;
307
308 /* handle non-queue interrupts */
309 val = rd32(hw, I40E_VFINT_ICR01);
310 ena_mask = rd32(hw, I40E_VFINT_ICR0_ENA1);
311
312
313 val = rd32(hw, I40E_VFINT_DYN_CTL01);
314 val = val | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK;
315 wr32(hw, I40E_VFINT_DYN_CTL01, val);
316
Greg Rose5eae00c2013-12-21 06:12:45 +0000317 /* schedule work on the private workqueue */
318 schedule_work(&adapter->adminq_task);
319
320 return IRQ_HANDLED;
321}
322
323/**
324 * i40evf_msix_clean_rings - MSIX mode Interrupt Handler
325 * @irq: interrupt number
326 * @data: pointer to a q_vector
327 **/
328static irqreturn_t i40evf_msix_clean_rings(int irq, void *data)
329{
330 struct i40e_q_vector *q_vector = data;
331
332 if (!q_vector->tx.ring && !q_vector->rx.ring)
333 return IRQ_HANDLED;
334
335 napi_schedule(&q_vector->napi);
336
337 return IRQ_HANDLED;
338}
339
340/**
341 * i40evf_map_vector_to_rxq - associate irqs with rx queues
342 * @adapter: board private structure
343 * @v_idx: interrupt number
344 * @r_idx: queue number
345 **/
346static void
347i40evf_map_vector_to_rxq(struct i40evf_adapter *adapter, int v_idx, int r_idx)
348{
349 struct i40e_q_vector *q_vector = adapter->q_vector[v_idx];
350 struct i40e_ring *rx_ring = adapter->rx_rings[r_idx];
351
352 rx_ring->q_vector = q_vector;
353 rx_ring->next = q_vector->rx.ring;
354 rx_ring->vsi = &adapter->vsi;
355 q_vector->rx.ring = rx_ring;
356 q_vector->rx.count++;
357 q_vector->rx.latency_range = I40E_LOW_LATENCY;
358}
359
360/**
361 * i40evf_map_vector_to_txq - associate irqs with tx queues
362 * @adapter: board private structure
363 * @v_idx: interrupt number
364 * @t_idx: queue number
365 **/
366static void
367i40evf_map_vector_to_txq(struct i40evf_adapter *adapter, int v_idx, int t_idx)
368{
369 struct i40e_q_vector *q_vector = adapter->q_vector[v_idx];
370 struct i40e_ring *tx_ring = adapter->tx_rings[t_idx];
371
372 tx_ring->q_vector = q_vector;
373 tx_ring->next = q_vector->tx.ring;
374 tx_ring->vsi = &adapter->vsi;
375 q_vector->tx.ring = tx_ring;
376 q_vector->tx.count++;
377 q_vector->tx.latency_range = I40E_LOW_LATENCY;
378 q_vector->num_ringpairs++;
379 q_vector->ring_mask |= (1 << t_idx);
380}
381
382/**
383 * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors
384 * @adapter: board private structure to initialize
385 *
386 * This function maps descriptor rings to the queue-specific vectors
387 * we were allotted through the MSI-X enabling code. Ideally, we'd have
388 * one vector per ring/queue, but on a constrained vector budget, we
389 * group the rings as "efficiently" as possible. You would add new
390 * mapping configurations in here.
391 **/
392static int i40evf_map_rings_to_vectors(struct i40evf_adapter *adapter)
393{
394 int q_vectors;
395 int v_start = 0;
396 int rxr_idx = 0, txr_idx = 0;
Mitch Williamscc052922014-10-25 03:24:34 +0000397 int rxr_remaining = adapter->num_active_queues;
398 int txr_remaining = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +0000399 int i, j;
400 int rqpv, tqpv;
401 int err = 0;
402
403 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
404
405 /* The ideal configuration...
406 * We have enough vectors to map one per queue.
407 */
408 if (q_vectors == (rxr_remaining * 2)) {
409 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
410 i40evf_map_vector_to_rxq(adapter, v_start, rxr_idx);
411
412 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
413 i40evf_map_vector_to_txq(adapter, v_start, txr_idx);
414 goto out;
415 }
416
417 /* If we don't have enough vectors for a 1-to-1
418 * mapping, we'll have to group them so there are
419 * multiple queues per vector.
420 * Re-adjusting *qpv takes care of the remainder.
421 */
422 for (i = v_start; i < q_vectors; i++) {
423 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
424 for (j = 0; j < rqpv; j++) {
425 i40evf_map_vector_to_rxq(adapter, i, rxr_idx);
426 rxr_idx++;
427 rxr_remaining--;
428 }
429 }
430 for (i = v_start; i < q_vectors; i++) {
431 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
432 for (j = 0; j < tqpv; j++) {
433 i40evf_map_vector_to_txq(adapter, i, txr_idx);
434 txr_idx++;
435 txr_remaining--;
436 }
437 }
438
439out:
440 adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
441
442 return err;
443}
444
445/**
446 * i40evf_request_traffic_irqs - Initialize MSI-X interrupts
447 * @adapter: board private structure
448 *
449 * Allocates MSI-X vectors for tx and rx handling, and requests
450 * interrupts from the kernel.
451 **/
452static int
453i40evf_request_traffic_irqs(struct i40evf_adapter *adapter, char *basename)
454{
455 int vector, err, q_vectors;
456 int rx_int_idx = 0, tx_int_idx = 0;
457
458 i40evf_irq_disable(adapter);
459 /* Decrement for Other and TCP Timer vectors */
460 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
461
462 for (vector = 0; vector < q_vectors; vector++) {
463 struct i40e_q_vector *q_vector = adapter->q_vector[vector];
464
465 if (q_vector->tx.ring && q_vector->rx.ring) {
466 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
467 "i40evf-%s-%s-%d", basename,
468 "TxRx", rx_int_idx++);
469 tx_int_idx++;
470 } else if (q_vector->rx.ring) {
471 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
472 "i40evf-%s-%s-%d", basename,
473 "rx", rx_int_idx++);
474 } else if (q_vector->tx.ring) {
475 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
476 "i40evf-%s-%s-%d", basename,
477 "tx", tx_int_idx++);
478 } else {
479 /* skip this unused q_vector */
480 continue;
481 }
482 err = request_irq(
483 adapter->msix_entries[vector + NONQ_VECS].vector,
484 i40evf_msix_clean_rings,
485 0,
486 q_vector->name,
487 q_vector);
488 if (err) {
489 dev_info(&adapter->pdev->dev,
490 "%s: request_irq failed, error: %d\n",
491 __func__, err);
492 goto free_queue_irqs;
493 }
494 /* assign the mask for this irq */
495 irq_set_affinity_hint(
496 adapter->msix_entries[vector + NONQ_VECS].vector,
497 q_vector->affinity_mask);
498 }
499
500 return 0;
501
502free_queue_irqs:
503 while (vector) {
504 vector--;
505 irq_set_affinity_hint(
506 adapter->msix_entries[vector + NONQ_VECS].vector,
507 NULL);
508 free_irq(adapter->msix_entries[vector + NONQ_VECS].vector,
509 adapter->q_vector[vector]);
510 }
511 return err;
512}
513
514/**
515 * i40evf_request_misc_irq - Initialize MSI-X interrupts
516 * @adapter: board private structure
517 *
518 * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
519 * vector is only for the admin queue, and stays active even when the netdev
520 * is closed.
521 **/
522static int i40evf_request_misc_irq(struct i40evf_adapter *adapter)
523{
524 struct net_device *netdev = adapter->netdev;
525 int err;
526
Jesse Brandeburgb39c1e22014-08-01 13:27:08 -0700527 snprintf(adapter->misc_vector_name,
Carolyn Wyborny9a21a002015-02-06 08:52:20 +0000528 sizeof(adapter->misc_vector_name) - 1, "i40evf-%s:mbx",
529 dev_name(&adapter->pdev->dev));
Greg Rose5eae00c2013-12-21 06:12:45 +0000530 err = request_irq(adapter->msix_entries[0].vector,
Mitch Williamse1dfee82014-02-13 03:48:51 -0800531 &i40evf_msix_aq, 0,
532 adapter->misc_vector_name, netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +0000533 if (err) {
534 dev_err(&adapter->pdev->dev,
Catherine Sullivan77fa28b2014-02-20 19:29:17 -0800535 "request_irq for %s failed: %d\n",
536 adapter->misc_vector_name, err);
Greg Rose5eae00c2013-12-21 06:12:45 +0000537 free_irq(adapter->msix_entries[0].vector, netdev);
538 }
539 return err;
540}
541
542/**
543 * i40evf_free_traffic_irqs - Free MSI-X interrupts
544 * @adapter: board private structure
545 *
546 * Frees all MSI-X vectors other than 0.
547 **/
548static void i40evf_free_traffic_irqs(struct i40evf_adapter *adapter)
549{
550 int i;
551 int q_vectors;
Mitch Williams75a64432014-11-11 20:02:42 +0000552
Greg Rose5eae00c2013-12-21 06:12:45 +0000553 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
554
555 for (i = 0; i < q_vectors; i++) {
556 irq_set_affinity_hint(adapter->msix_entries[i+1].vector,
557 NULL);
558 free_irq(adapter->msix_entries[i+1].vector,
559 adapter->q_vector[i]);
560 }
561}
562
563/**
564 * i40evf_free_misc_irq - Free MSI-X miscellaneous vector
565 * @adapter: board private structure
566 *
567 * Frees MSI-X vector 0.
568 **/
569static void i40evf_free_misc_irq(struct i40evf_adapter *adapter)
570{
571 struct net_device *netdev = adapter->netdev;
572
573 free_irq(adapter->msix_entries[0].vector, netdev);
574}
575
576/**
577 * i40evf_configure_tx - Configure Transmit Unit after Reset
578 * @adapter: board private structure
579 *
580 * Configure the Tx unit of the MAC after a reset.
581 **/
582static void i40evf_configure_tx(struct i40evf_adapter *adapter)
583{
584 struct i40e_hw *hw = &adapter->hw;
585 int i;
Mitch Williams75a64432014-11-11 20:02:42 +0000586
Mitch Williamscc052922014-10-25 03:24:34 +0000587 for (i = 0; i < adapter->num_active_queues; i++)
Greg Rose5eae00c2013-12-21 06:12:45 +0000588 adapter->tx_rings[i]->tail = hw->hw_addr + I40E_QTX_TAIL1(i);
589}
590
591/**
592 * i40evf_configure_rx - Configure Receive Unit after Reset
593 * @adapter: board private structure
594 *
595 * Configure the Rx unit of the MAC after a reset.
596 **/
597static void i40evf_configure_rx(struct i40evf_adapter *adapter)
598{
599 struct i40e_hw *hw = &adapter->hw;
600 struct net_device *netdev = adapter->netdev;
601 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
602 int i;
603 int rx_buf_len;
604
605
606 adapter->flags &= ~I40EVF_FLAG_RX_PS_CAPABLE;
607 adapter->flags |= I40EVF_FLAG_RX_1BUF_CAPABLE;
608
609 /* Decide whether to use packet split mode or not */
610 if (netdev->mtu > ETH_DATA_LEN) {
611 if (adapter->flags & I40EVF_FLAG_RX_PS_CAPABLE)
612 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
613 else
614 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
615 } else {
616 if (adapter->flags & I40EVF_FLAG_RX_1BUF_CAPABLE)
617 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
618 else
619 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
620 }
621
622 /* Set the RX buffer length according to the mode */
623 if (adapter->flags & I40EVF_FLAG_RX_PS_ENABLED) {
624 rx_buf_len = I40E_RX_HDR_SIZE;
625 } else {
626 if (netdev->mtu <= ETH_DATA_LEN)
627 rx_buf_len = I40EVF_RXBUFFER_2048;
628 else
629 rx_buf_len = ALIGN(max_frame, 1024);
630 }
631
Mitch Williamscc052922014-10-25 03:24:34 +0000632 for (i = 0; i < adapter->num_active_queues; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000633 adapter->rx_rings[i]->tail = hw->hw_addr + I40E_QRX_TAIL1(i);
634 adapter->rx_rings[i]->rx_buf_len = rx_buf_len;
635 }
636}
637
638/**
639 * i40evf_find_vlan - Search filter list for specific vlan filter
640 * @adapter: board private structure
641 * @vlan: vlan tag
642 *
643 * Returns ptr to the filter object or NULL
644 **/
645static struct
646i40evf_vlan_filter *i40evf_find_vlan(struct i40evf_adapter *adapter, u16 vlan)
647{
648 struct i40evf_vlan_filter *f;
649
650 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
651 if (vlan == f->vlan)
652 return f;
653 }
654 return NULL;
655}
656
657/**
658 * i40evf_add_vlan - Add a vlan filter to the list
659 * @adapter: board private structure
660 * @vlan: VLAN tag
661 *
662 * Returns ptr to the filter object or NULL when no memory available.
663 **/
664static struct
665i40evf_vlan_filter *i40evf_add_vlan(struct i40evf_adapter *adapter, u16 vlan)
666{
Mitch Williams13acb542015-03-31 00:45:05 -0700667 struct i40evf_vlan_filter *f = NULL;
668 int count = 50;
669
670 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
671 &adapter->crit_section)) {
672 udelay(1);
673 if (--count == 0)
674 goto out;
675 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000676
677 f = i40evf_find_vlan(adapter, vlan);
Mitch Williams348d4992014-11-11 20:02:52 +0000678 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000679 f = kzalloc(sizeof(*f), GFP_ATOMIC);
Mitch Williams348d4992014-11-11 20:02:52 +0000680 if (!f)
Mitch Williams13acb542015-03-31 00:45:05 -0700681 goto clearout;
Mitch Williams249c8b82014-05-10 04:49:04 +0000682
Greg Rose5eae00c2013-12-21 06:12:45 +0000683 f->vlan = vlan;
684
685 INIT_LIST_HEAD(&f->list);
686 list_add(&f->list, &adapter->vlan_filter_list);
687 f->add = true;
688 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
689 }
690
Mitch Williams13acb542015-03-31 00:45:05 -0700691clearout:
692 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
693out:
Greg Rose5eae00c2013-12-21 06:12:45 +0000694 return f;
695}
696
697/**
698 * i40evf_del_vlan - Remove a vlan filter from the list
699 * @adapter: board private structure
700 * @vlan: VLAN tag
701 **/
702static void i40evf_del_vlan(struct i40evf_adapter *adapter, u16 vlan)
703{
704 struct i40evf_vlan_filter *f;
Mitch Williams13acb542015-03-31 00:45:05 -0700705 int count = 50;
706
707 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
708 &adapter->crit_section)) {
709 udelay(1);
710 if (--count == 0)
711 return;
712 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000713
714 f = i40evf_find_vlan(adapter, vlan);
715 if (f) {
716 f->remove = true;
717 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
718 }
Mitch Williams13acb542015-03-31 00:45:05 -0700719 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Greg Rose5eae00c2013-12-21 06:12:45 +0000720}
721
722/**
723 * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device
724 * @netdev: network device struct
725 * @vid: VLAN tag
726 **/
727static int i40evf_vlan_rx_add_vid(struct net_device *netdev,
Mitch Williams75a64432014-11-11 20:02:42 +0000728 __always_unused __be16 proto, u16 vid)
Greg Rose5eae00c2013-12-21 06:12:45 +0000729{
730 struct i40evf_adapter *adapter = netdev_priv(netdev);
731
732 if (i40evf_add_vlan(adapter, vid) == NULL)
733 return -ENOMEM;
734 return 0;
735}
736
737/**
738 * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device
739 * @netdev: network device struct
740 * @vid: VLAN tag
741 **/
742static int i40evf_vlan_rx_kill_vid(struct net_device *netdev,
Mitch Williams75a64432014-11-11 20:02:42 +0000743 __always_unused __be16 proto, u16 vid)
Greg Rose5eae00c2013-12-21 06:12:45 +0000744{
745 struct i40evf_adapter *adapter = netdev_priv(netdev);
746
747 i40evf_del_vlan(adapter, vid);
748 return 0;
749}
750
751/**
752 * i40evf_find_filter - Search filter list for specific mac filter
753 * @adapter: board private structure
754 * @macaddr: the MAC address
755 *
756 * Returns ptr to the filter object or NULL
757 **/
758static struct
759i40evf_mac_filter *i40evf_find_filter(struct i40evf_adapter *adapter,
760 u8 *macaddr)
761{
762 struct i40evf_mac_filter *f;
763
764 if (!macaddr)
765 return NULL;
766
767 list_for_each_entry(f, &adapter->mac_filter_list, list) {
768 if (ether_addr_equal(macaddr, f->macaddr))
769 return f;
770 }
771 return NULL;
772}
773
774/**
775 * i40e_add_filter - Add a mac filter to the filter list
776 * @adapter: board private structure
777 * @macaddr: the MAC address
778 *
779 * Returns ptr to the filter object or NULL when no memory available.
780 **/
781static struct
782i40evf_mac_filter *i40evf_add_filter(struct i40evf_adapter *adapter,
783 u8 *macaddr)
784{
785 struct i40evf_mac_filter *f;
Mitch Williams54e16f62015-01-29 07:17:20 +0000786 int count = 50;
Greg Rose5eae00c2013-12-21 06:12:45 +0000787
788 if (!macaddr)
789 return NULL;
790
791 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
Mitch Williams54e16f62015-01-29 07:17:20 +0000792 &adapter->crit_section)) {
Mitch Williamsb65476c2014-07-09 07:46:14 +0000793 udelay(1);
Mitch Williams54e16f62015-01-29 07:17:20 +0000794 if (--count == 0)
795 return NULL;
796 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000797
798 f = i40evf_find_filter(adapter, macaddr);
Mitch Williams348d4992014-11-11 20:02:52 +0000799 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000800 f = kzalloc(sizeof(*f), GFP_ATOMIC);
Mitch Williams348d4992014-11-11 20:02:52 +0000801 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000802 clear_bit(__I40EVF_IN_CRITICAL_TASK,
803 &adapter->crit_section);
804 return NULL;
805 }
806
Greg Rose9a173902014-05-22 06:32:02 +0000807 ether_addr_copy(f->macaddr, macaddr);
Greg Rose5eae00c2013-12-21 06:12:45 +0000808
809 list_add(&f->list, &adapter->mac_filter_list);
810 f->add = true;
811 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
812 }
813
814 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
815 return f;
816}
817
818/**
819 * i40evf_set_mac - NDO callback to set port mac address
820 * @netdev: network interface device structure
821 * @p: pointer to an address structure
822 *
823 * Returns 0 on success, negative on failure
824 **/
825static int i40evf_set_mac(struct net_device *netdev, void *p)
826{
827 struct i40evf_adapter *adapter = netdev_priv(netdev);
828 struct i40e_hw *hw = &adapter->hw;
829 struct i40evf_mac_filter *f;
830 struct sockaddr *addr = p;
831
832 if (!is_valid_ether_addr(addr->sa_data))
833 return -EADDRNOTAVAIL;
834
835 if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
836 return 0;
837
838 f = i40evf_add_filter(adapter, addr->sa_data);
839 if (f) {
Greg Rose9a173902014-05-22 06:32:02 +0000840 ether_addr_copy(hw->mac.addr, addr->sa_data);
841 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +0000842 }
843
844 return (f == NULL) ? -ENOMEM : 0;
845}
846
847/**
848 * i40evf_set_rx_mode - NDO callback to set the netdev filters
849 * @netdev: network interface device structure
850 **/
851static void i40evf_set_rx_mode(struct net_device *netdev)
852{
853 struct i40evf_adapter *adapter = netdev_priv(netdev);
854 struct i40evf_mac_filter *f, *ftmp;
855 struct netdev_hw_addr *uca;
856 struct netdev_hw_addr *mca;
Mitch Williams54e16f62015-01-29 07:17:20 +0000857 int count = 50;
Greg Rose5eae00c2013-12-21 06:12:45 +0000858
859 /* add addr if not already in the filter list */
860 netdev_for_each_uc_addr(uca, netdev) {
861 i40evf_add_filter(adapter, uca->addr);
862 }
863 netdev_for_each_mc_addr(mca, netdev) {
864 i40evf_add_filter(adapter, mca->addr);
865 }
866
867 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
Mitch Williams54e16f62015-01-29 07:17:20 +0000868 &adapter->crit_section)) {
Mitch Williamsb65476c2014-07-09 07:46:14 +0000869 udelay(1);
Mitch Williams54e16f62015-01-29 07:17:20 +0000870 if (--count == 0) {
871 dev_err(&adapter->pdev->dev,
872 "Failed to get lock in %s\n", __func__);
873 return;
874 }
875 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000876 /* remove filter if not in netdev list */
877 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
878 bool found = false;
879
Tobias Klauserdc5f2de2014-05-20 08:23:06 +0000880 if (is_multicast_ether_addr(f->macaddr)) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000881 netdev_for_each_mc_addr(mca, netdev) {
882 if (ether_addr_equal(mca->addr, f->macaddr)) {
883 found = true;
884 break;
885 }
886 }
887 } else {
888 netdev_for_each_uc_addr(uca, netdev) {
889 if (ether_addr_equal(uca->addr, f->macaddr)) {
890 found = true;
891 break;
892 }
893 }
894 }
895 if (found) {
896 f->remove = true;
897 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
898 }
899 }
900 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
901}
902
903/**
904 * i40evf_napi_enable_all - enable NAPI on all queue vectors
905 * @adapter: board private structure
906 **/
907static void i40evf_napi_enable_all(struct i40evf_adapter *adapter)
908{
909 int q_idx;
910 struct i40e_q_vector *q_vector;
911 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
912
913 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
914 struct napi_struct *napi;
Mitch Williams75a64432014-11-11 20:02:42 +0000915
Greg Rose5eae00c2013-12-21 06:12:45 +0000916 q_vector = adapter->q_vector[q_idx];
917 napi = &q_vector->napi;
918 napi_enable(napi);
919 }
920}
921
922/**
923 * i40evf_napi_disable_all - disable NAPI on all queue vectors
924 * @adapter: board private structure
925 **/
926static void i40evf_napi_disable_all(struct i40evf_adapter *adapter)
927{
928 int q_idx;
929 struct i40e_q_vector *q_vector;
930 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
931
932 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
933 q_vector = adapter->q_vector[q_idx];
934 napi_disable(&q_vector->napi);
935 }
936}
937
938/**
939 * i40evf_configure - set up transmit and receive data structures
940 * @adapter: board private structure
941 **/
942static void i40evf_configure(struct i40evf_adapter *adapter)
943{
944 struct net_device *netdev = adapter->netdev;
945 int i;
946
947 i40evf_set_rx_mode(netdev);
948
949 i40evf_configure_tx(adapter);
950 i40evf_configure_rx(adapter);
951 adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
952
Mitch Williamscc052922014-10-25 03:24:34 +0000953 for (i = 0; i < adapter->num_active_queues; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000954 struct i40e_ring *ring = adapter->rx_rings[i];
Mitch Williams75a64432014-11-11 20:02:42 +0000955
Mitch Williamsa132af22015-01-24 09:58:35 +0000956 i40evf_alloc_rx_buffers_1buf(ring, ring->count);
Greg Rose5eae00c2013-12-21 06:12:45 +0000957 ring->next_to_use = ring->count - 1;
958 writel(ring->next_to_use, ring->tail);
959 }
960}
961
962/**
963 * i40evf_up_complete - Finish the last steps of bringing up a connection
964 * @adapter: board private structure
965 **/
966static int i40evf_up_complete(struct i40evf_adapter *adapter)
967{
968 adapter->state = __I40EVF_RUNNING;
969 clear_bit(__I40E_DOWN, &adapter->vsi.state);
970
971 i40evf_napi_enable_all(adapter);
972
973 adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
974 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
975 return 0;
976}
977
978/**
Greg Rose5eae00c2013-12-21 06:12:45 +0000979 * i40e_down - Shutdown the connection processing
980 * @adapter: board private structure
981 **/
982void i40evf_down(struct i40evf_adapter *adapter)
983{
984 struct net_device *netdev = adapter->netdev;
985 struct i40evf_mac_filter *f;
986
Mitch Williamsddf0b3a2014-05-22 06:31:46 +0000987 if (adapter->state == __I40EVF_DOWN)
988 return;
989
Mitch A Williams53d0b3a2014-12-09 08:53:04 +0000990 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
991 &adapter->crit_section))
992 usleep_range(500, 1000);
993
Mitch Williams63e18c22015-03-27 00:12:10 -0700994 netif_carrier_off(netdev);
995 netif_tx_disable(netdev);
Mitch Williams748c4342015-01-29 07:17:18 +0000996 i40evf_napi_disable_all(adapter);
Mitch Williams63e18c22015-03-27 00:12:10 -0700997 i40evf_irq_disable(adapter);
Mitch A Williams53d0b3a2014-12-09 08:53:04 +0000998
Mitch Williamsef8693e2014-02-13 03:48:53 -0800999 /* remove all MAC filters */
Greg Rose5eae00c2013-12-21 06:12:45 +00001000 list_for_each_entry(f, &adapter->mac_filter_list, list) {
1001 f->remove = true;
1002 }
Mitch Williamsed1f5b52014-02-20 19:29:06 -08001003 /* remove all VLAN filters */
1004 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
1005 f->remove = true;
1006 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001007 if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) &&
1008 adapter->state != __I40EVF_RESETTING) {
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001009 /* cancel any current operation */
1010 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1011 adapter->aq_pending = 0;
1012 /* Schedule operations to close down the HW. Don't wait
1013 * here for this to complete. The watchdog is still running
1014 * and it will take care of this.
1015 */
1016 adapter->aq_required = I40EVF_FLAG_AQ_DEL_MAC_FILTER;
Mitch Williamsed1f5b52014-02-20 19:29:06 -08001017 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001018 adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001019 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001020
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001021 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Greg Rose5eae00c2013-12-21 06:12:45 +00001022}
1023
1024/**
1025 * i40evf_acquire_msix_vectors - Setup the MSIX capability
1026 * @adapter: board private structure
1027 * @vectors: number of vectors to request
1028 *
1029 * Work with the OS to set up the MSIX vectors needed.
1030 *
1031 * Returns 0 on success, negative on failure
1032 **/
1033static int
1034i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors)
1035{
1036 int err, vector_threshold;
1037
1038 /* We'll want at least 3 (vector_threshold):
1039 * 0) Other (Admin Queue and link, mostly)
1040 * 1) TxQ[0] Cleanup
1041 * 2) RxQ[0] Cleanup
1042 */
1043 vector_threshold = MIN_MSIX_COUNT;
1044
1045 /* The more we get, the more we will assign to Tx/Rx Cleanup
1046 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1047 * Right now, we simply care about how many we'll get; we'll
1048 * set them up later while requesting irq's.
1049 */
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001050 err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
1051 vector_threshold, vectors);
1052 if (err < 0) {
Mitch Williams80e72892014-05-10 04:49:06 +00001053 dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001054 kfree(adapter->msix_entries);
1055 adapter->msix_entries = NULL;
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001056 return err;
Greg Rose5eae00c2013-12-21 06:12:45 +00001057 }
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001058
1059 /* Adjust for only the vectors we'll use, which is minimum
1060 * of max_msix_q_vectors + NONQ_VECS, or the number of
1061 * vectors we were allocated.
1062 */
1063 adapter->num_msix_vectors = err;
1064 return 0;
Greg Rose5eae00c2013-12-21 06:12:45 +00001065}
1066
1067/**
1068 * i40evf_free_queues - Free memory for all rings
1069 * @adapter: board private structure to initialize
1070 *
1071 * Free all of the memory associated with queue pairs.
1072 **/
1073static void i40evf_free_queues(struct i40evf_adapter *adapter)
1074{
1075 int i;
1076
1077 if (!adapter->vsi_res)
1078 return;
Mitch Williamscc052922014-10-25 03:24:34 +00001079 for (i = 0; i < adapter->num_active_queues; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001080 if (adapter->tx_rings[i])
1081 kfree_rcu(adapter->tx_rings[i], rcu);
1082 adapter->tx_rings[i] = NULL;
1083 adapter->rx_rings[i] = NULL;
1084 }
1085}
1086
1087/**
1088 * i40evf_alloc_queues - Allocate memory for all rings
1089 * @adapter: board private structure to initialize
1090 *
1091 * We allocate one ring per queue at run-time since we don't know the
1092 * number of queues at compile-time. The polling_netdev array is
1093 * intended for Multiqueue, but should work fine with a single queue.
1094 **/
1095static int i40evf_alloc_queues(struct i40evf_adapter *adapter)
1096{
1097 int i;
1098
Mitch Williamscc052922014-10-25 03:24:34 +00001099 for (i = 0; i < adapter->num_active_queues; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001100 struct i40e_ring *tx_ring;
1101 struct i40e_ring *rx_ring;
1102
Mitch Williams75a64432014-11-11 20:02:42 +00001103 tx_ring = kzalloc(sizeof(*tx_ring) * 2, GFP_KERNEL);
Greg Rose5eae00c2013-12-21 06:12:45 +00001104 if (!tx_ring)
1105 goto err_out;
1106
1107 tx_ring->queue_index = i;
1108 tx_ring->netdev = adapter->netdev;
1109 tx_ring->dev = &adapter->pdev->dev;
Mitch Williamsd732a182014-04-24 06:41:37 +00001110 tx_ring->count = adapter->tx_desc_count;
Greg Rose5eae00c2013-12-21 06:12:45 +00001111 adapter->tx_rings[i] = tx_ring;
1112
1113 rx_ring = &tx_ring[1];
1114 rx_ring->queue_index = i;
1115 rx_ring->netdev = adapter->netdev;
1116 rx_ring->dev = &adapter->pdev->dev;
Mitch Williamsd732a182014-04-24 06:41:37 +00001117 rx_ring->count = adapter->rx_desc_count;
Greg Rose5eae00c2013-12-21 06:12:45 +00001118 adapter->rx_rings[i] = rx_ring;
1119 }
1120
1121 return 0;
1122
1123err_out:
1124 i40evf_free_queues(adapter);
1125 return -ENOMEM;
1126}
1127
1128/**
1129 * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
1130 * @adapter: board private structure to initialize
1131 *
1132 * Attempt to configure the interrupts using the best available
1133 * capabilities of the hardware and the kernel.
1134 **/
1135static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter)
1136{
1137 int vector, v_budget;
1138 int pairs = 0;
1139 int err = 0;
1140
1141 if (!adapter->vsi_res) {
1142 err = -EIO;
1143 goto out;
1144 }
Mitch Williamscc052922014-10-25 03:24:34 +00001145 pairs = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +00001146
1147 /* It's easy to be greedy for MSI-X vectors, but it really
1148 * doesn't do us much good if we have a lot more vectors
1149 * than CPU's. So let's be conservative and only ask for
1150 * (roughly) twice the number of vectors as there are CPU's.
1151 */
Mitch Williams30a500e2014-02-11 08:27:52 +00001152 v_budget = min_t(int, pairs, (int)(num_online_cpus() * 2)) + NONQ_VECS;
1153 v_budget = min_t(int, v_budget, (int)adapter->vf_res->max_vectors);
Greg Rose5eae00c2013-12-21 06:12:45 +00001154
Greg Rose5eae00c2013-12-21 06:12:45 +00001155 adapter->msix_entries = kcalloc(v_budget,
1156 sizeof(struct msix_entry), GFP_KERNEL);
1157 if (!adapter->msix_entries) {
1158 err = -ENOMEM;
1159 goto out;
1160 }
1161
1162 for (vector = 0; vector < v_budget; vector++)
1163 adapter->msix_entries[vector].entry = vector;
1164
1165 i40evf_acquire_msix_vectors(adapter, v_budget);
1166
1167out:
1168 adapter->netdev->real_num_tx_queues = pairs;
1169 return err;
1170}
1171
1172/**
1173 * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
1174 * @adapter: board private structure to initialize
1175 *
1176 * We allocate one q_vector per queue interrupt. If allocation fails we
1177 * return -ENOMEM.
1178 **/
1179static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter)
1180{
1181 int q_idx, num_q_vectors;
1182 struct i40e_q_vector *q_vector;
1183
1184 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
1185
1186 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Mitch Williams75a64432014-11-11 20:02:42 +00001187 q_vector = kzalloc(sizeof(*q_vector), GFP_KERNEL);
Greg Rose5eae00c2013-12-21 06:12:45 +00001188 if (!q_vector)
1189 goto err_out;
1190 q_vector->adapter = adapter;
1191 q_vector->vsi = &adapter->vsi;
1192 q_vector->v_idx = q_idx;
1193 netif_napi_add(adapter->netdev, &q_vector->napi,
Mitch Williams75a64432014-11-11 20:02:42 +00001194 i40evf_napi_poll, NAPI_POLL_WEIGHT);
Greg Rose5eae00c2013-12-21 06:12:45 +00001195 adapter->q_vector[q_idx] = q_vector;
1196 }
1197
1198 return 0;
1199
1200err_out:
1201 while (q_idx) {
1202 q_idx--;
1203 q_vector = adapter->q_vector[q_idx];
1204 netif_napi_del(&q_vector->napi);
1205 kfree(q_vector);
1206 adapter->q_vector[q_idx] = NULL;
1207 }
1208 return -ENOMEM;
1209}
1210
1211/**
1212 * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
1213 * @adapter: board private structure to initialize
1214 *
1215 * This function frees the memory allocated to the q_vectors. In addition if
1216 * NAPI is enabled it will delete any references to the NAPI struct prior
1217 * to freeing the q_vector.
1218 **/
1219static void i40evf_free_q_vectors(struct i40evf_adapter *adapter)
1220{
1221 int q_idx, num_q_vectors;
1222 int napi_vectors;
1223
1224 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
Mitch Williamscc052922014-10-25 03:24:34 +00001225 napi_vectors = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +00001226
1227 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
1228 struct i40e_q_vector *q_vector = adapter->q_vector[q_idx];
1229
1230 adapter->q_vector[q_idx] = NULL;
1231 if (q_idx < napi_vectors)
1232 netif_napi_del(&q_vector->napi);
1233 kfree(q_vector);
1234 }
1235}
1236
1237/**
1238 * i40evf_reset_interrupt_capability - Reset MSIX setup
1239 * @adapter: board private structure
1240 *
1241 **/
1242void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter)
1243{
1244 pci_disable_msix(adapter->pdev);
1245 kfree(adapter->msix_entries);
1246 adapter->msix_entries = NULL;
Greg Rose5eae00c2013-12-21 06:12:45 +00001247}
1248
1249/**
1250 * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
1251 * @adapter: board private structure to initialize
1252 *
1253 **/
1254int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter)
1255{
1256 int err;
1257
1258 err = i40evf_set_interrupt_capability(adapter);
1259 if (err) {
1260 dev_err(&adapter->pdev->dev,
1261 "Unable to setup interrupt capabilities\n");
1262 goto err_set_interrupt;
1263 }
1264
1265 err = i40evf_alloc_q_vectors(adapter);
1266 if (err) {
1267 dev_err(&adapter->pdev->dev,
1268 "Unable to allocate memory for queue vectors\n");
1269 goto err_alloc_q_vectors;
1270 }
1271
1272 err = i40evf_alloc_queues(adapter);
1273 if (err) {
1274 dev_err(&adapter->pdev->dev,
1275 "Unable to allocate memory for queues\n");
1276 goto err_alloc_queues;
1277 }
1278
1279 dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u",
Mitch Williams75a64432014-11-11 20:02:42 +00001280 (adapter->num_active_queues > 1) ? "Enabled" : "Disabled",
1281 adapter->num_active_queues);
Greg Rose5eae00c2013-12-21 06:12:45 +00001282
1283 return 0;
1284err_alloc_queues:
1285 i40evf_free_q_vectors(adapter);
1286err_alloc_q_vectors:
1287 i40evf_reset_interrupt_capability(adapter);
1288err_set_interrupt:
1289 return err;
1290}
1291
1292/**
1293 * i40evf_watchdog_timer - Periodic call-back timer
1294 * @data: pointer to adapter disguised as unsigned long
1295 **/
1296static void i40evf_watchdog_timer(unsigned long data)
1297{
1298 struct i40evf_adapter *adapter = (struct i40evf_adapter *)data;
Mitch Williams75a64432014-11-11 20:02:42 +00001299
Greg Rose5eae00c2013-12-21 06:12:45 +00001300 schedule_work(&adapter->watchdog_task);
1301 /* timer will be rescheduled in watchdog task */
1302}
1303
1304/**
1305 * i40evf_watchdog_task - Periodic call-back task
1306 * @work: pointer to work_struct
1307 **/
1308static void i40evf_watchdog_task(struct work_struct *work)
1309{
1310 struct i40evf_adapter *adapter = container_of(work,
Mitch Williams75a64432014-11-11 20:02:42 +00001311 struct i40evf_adapter,
1312 watchdog_task);
Greg Rose5eae00c2013-12-21 06:12:45 +00001313 struct i40e_hw *hw = &adapter->hw;
Ashish Shahfd358862014-08-01 13:27:11 -07001314 uint32_t rstat_val;
Greg Rose5eae00c2013-12-21 06:12:45 +00001315
Greg Rose5eae00c2013-12-21 06:12:45 +00001316 if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section))
Mitch Williamsef8693e2014-02-13 03:48:53 -08001317 goto restart_watchdog;
1318
1319 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
Ashish Shahfd358862014-08-01 13:27:11 -07001320 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1321 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1322 if ((rstat_val == I40E_VFR_VFACTIVE) ||
1323 (rstat_val == I40E_VFR_COMPLETED)) {
Mitch Williamsef8693e2014-02-13 03:48:53 -08001324 /* A chance for redemption! */
1325 dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n");
1326 adapter->state = __I40EVF_STARTUP;
1327 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
1328 schedule_delayed_work(&adapter->init_task, 10);
1329 clear_bit(__I40EVF_IN_CRITICAL_TASK,
1330 &adapter->crit_section);
1331 /* Don't reschedule the watchdog, since we've restarted
1332 * the init task. When init_task contacts the PF and
1333 * gets everything set up again, it'll restart the
1334 * watchdog for us. Down, boy. Sit. Stay. Woof.
1335 */
1336 return;
1337 }
1338 adapter->aq_pending = 0;
1339 adapter->aq_required = 0;
1340 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1341 goto watchdog_done;
1342 }
1343
1344 if ((adapter->state < __I40EVF_DOWN) ||
1345 (adapter->flags & I40EVF_FLAG_RESET_PENDING))
Greg Rose5eae00c2013-12-21 06:12:45 +00001346 goto watchdog_done;
1347
Mitch Williamsef8693e2014-02-13 03:48:53 -08001348 /* check for reset */
Ashish Shahfd358862014-08-01 13:27:11 -07001349 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
Mitch Williams75a64432014-11-11 20:02:42 +00001350 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001351 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) &&
Ashish Shahfd358862014-08-01 13:27:11 -07001352 (rstat_val != I40E_VFR_VFACTIVE) &&
1353 (rstat_val != I40E_VFR_COMPLETED)) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001354 adapter->state = __I40EVF_RESETTING;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001355 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
Mitch Williams249c8b82014-05-10 04:49:04 +00001356 dev_err(&adapter->pdev->dev, "Hardware reset detected\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001357 schedule_work(&adapter->reset_task);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001358 adapter->aq_pending = 0;
1359 adapter->aq_required = 0;
1360 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001361 goto watchdog_done;
1362 }
1363
1364 /* Process admin queue tasks. After init, everything gets done
1365 * here so we don't race on the admin queue.
1366 */
Mitch A Williams0758e7cb2014-12-09 08:53:08 +00001367 if (adapter->aq_pending) {
1368 if (!i40evf_asq_done(hw)) {
1369 dev_dbg(&adapter->pdev->dev, "Admin queue timeout\n");
1370 i40evf_send_api_ver(adapter);
1371 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001372 goto watchdog_done;
Mitch A Williams0758e7cb2014-12-09 08:53:08 +00001373 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001374
Mitch Williamse284fc82015-03-27 00:12:09 -07001375 if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) {
1376 i40evf_disable_queues(adapter);
1377 goto watchdog_done;
1378 }
1379
Greg Rose5eae00c2013-12-21 06:12:45 +00001380 if (adapter->aq_required & I40EVF_FLAG_AQ_MAP_VECTORS) {
1381 i40evf_map_queues(adapter);
1382 goto watchdog_done;
1383 }
1384
1385 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_MAC_FILTER) {
1386 i40evf_add_ether_addrs(adapter);
1387 goto watchdog_done;
1388 }
1389
1390 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_VLAN_FILTER) {
1391 i40evf_add_vlans(adapter);
1392 goto watchdog_done;
1393 }
1394
1395 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_MAC_FILTER) {
1396 i40evf_del_ether_addrs(adapter);
1397 goto watchdog_done;
1398 }
1399
1400 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_VLAN_FILTER) {
1401 i40evf_del_vlans(adapter);
1402 goto watchdog_done;
1403 }
1404
Greg Rose5eae00c2013-12-21 06:12:45 +00001405 if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_QUEUES) {
1406 i40evf_configure_queues(adapter);
1407 goto watchdog_done;
1408 }
1409
1410 if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_QUEUES) {
1411 i40evf_enable_queues(adapter);
1412 goto watchdog_done;
1413 }
1414
1415 if (adapter->state == __I40EVF_RUNNING)
1416 i40evf_request_stats(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001417watchdog_done:
Mitch A Williams4870e172014-12-09 08:53:06 +00001418 if (adapter->state == __I40EVF_RUNNING) {
1419 i40evf_irq_enable_queues(adapter, ~0);
1420 i40evf_fire_sw_int(adapter, 0xFF);
1421 } else {
1422 i40evf_fire_sw_int(adapter, 0x1);
1423 }
1424
Mitch Williamsef8693e2014-02-13 03:48:53 -08001425 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1426restart_watchdog:
Ashish Shahd3e2edb2014-08-01 13:27:12 -07001427 if (adapter->state == __I40EVF_REMOVE)
1428 return;
Greg Rose5eae00c2013-12-21 06:12:45 +00001429 if (adapter->aq_required)
1430 mod_timer(&adapter->watchdog_timer,
1431 jiffies + msecs_to_jiffies(20));
1432 else
1433 mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2));
Greg Rose5eae00c2013-12-21 06:12:45 +00001434 schedule_work(&adapter->adminq_task);
1435}
1436
Mitch A Williams5b7af022014-03-28 06:49:02 +00001437/**
Catherine Sullivan3dd55502014-05-20 08:01:36 +00001438 * next_queue - increment to next available tx queue
Mitch A Williams5b7af022014-03-28 06:49:02 +00001439 * @adapter: board private structure
1440 * @j: queue counter
1441 *
1442 * Helper function for RSS programming to increment through available
1443 * queus. Returns the next queue value.
1444 **/
Mitch Williams96d47702014-02-11 08:27:50 +00001445static int next_queue(struct i40evf_adapter *adapter, int j)
1446{
1447 j += 1;
1448
Mitch Williamscc052922014-10-25 03:24:34 +00001449 return j >= adapter->num_active_queues ? 0 : j;
Mitch Williams96d47702014-02-11 08:27:50 +00001450}
1451
Greg Rose5eae00c2013-12-21 06:12:45 +00001452/**
1453 * i40evf_configure_rss - Prepare for RSS if used
1454 * @adapter: board private structure
1455 **/
1456static void i40evf_configure_rss(struct i40evf_adapter *adapter)
1457{
Eric Dumazet22f258a2014-11-16 06:23:13 -08001458 u32 rss_key[I40E_VFQF_HKEY_MAX_INDEX + 1];
Greg Rose5eae00c2013-12-21 06:12:45 +00001459 struct i40e_hw *hw = &adapter->hw;
1460 u32 lut = 0;
1461 int i, j;
1462 u64 hena;
1463
Mitch Williamscc052922014-10-25 03:24:34 +00001464 /* No RSS for single queue. */
1465 if (adapter->num_active_queues == 1) {
1466 wr32(hw, I40E_VFQF_HENA(0), 0);
1467 wr32(hw, I40E_VFQF_HENA(1), 0);
1468 return;
1469 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001470
Mitch Williamscc052922014-10-25 03:24:34 +00001471 /* Hash type is configured by the PF - we just supply the key */
Eric Dumazet22f258a2014-11-16 06:23:13 -08001472 netdev_rss_key_fill(rss_key, sizeof(rss_key));
Greg Rose5eae00c2013-12-21 06:12:45 +00001473 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
Eric Dumazet22f258a2014-11-16 06:23:13 -08001474 wr32(hw, I40E_VFQF_HKEY(i), rss_key[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00001475
1476 /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
1477 hena = I40E_DEFAULT_RSS_HENA;
1478 wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
1479 wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
1480
1481 /* Populate the LUT with max no. of queues in round robin fashion */
Mitch Williamscc052922014-10-25 03:24:34 +00001482 j = adapter->num_active_queues;
Mitch Williams96d47702014-02-11 08:27:50 +00001483 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) {
Mitch A Williams5b7af022014-03-28 06:49:02 +00001484 j = next_queue(adapter, j);
1485 lut = j;
1486 j = next_queue(adapter, j);
1487 lut |= j << 8;
1488 j = next_queue(adapter, j);
1489 lut |= j << 16;
1490 j = next_queue(adapter, j);
1491 lut |= j << 24;
Mitch Williams96d47702014-02-11 08:27:50 +00001492 wr32(hw, I40E_VFQF_HLUT(i), lut);
Greg Rose5eae00c2013-12-21 06:12:45 +00001493 }
1494 i40e_flush(hw);
1495}
1496
Mitch Williamsef8693e2014-02-13 03:48:53 -08001497#define I40EVF_RESET_WAIT_MS 100
1498#define I40EVF_RESET_WAIT_COUNT 200
Greg Rose5eae00c2013-12-21 06:12:45 +00001499/**
1500 * i40evf_reset_task - Call-back task to handle hardware reset
1501 * @work: pointer to work_struct
1502 *
1503 * During reset we need to shut down and reinitialize the admin queue
1504 * before we can use it to communicate with the PF again. We also clear
1505 * and reinit the rings because that context is lost as well.
1506 **/
1507static void i40evf_reset_task(struct work_struct *work)
1508{
Mitch Williamsef8693e2014-02-13 03:48:53 -08001509 struct i40evf_adapter *adapter = container_of(work,
1510 struct i40evf_adapter,
1511 reset_task);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001512 struct net_device *netdev = adapter->netdev;
Greg Rose5eae00c2013-12-21 06:12:45 +00001513 struct i40e_hw *hw = &adapter->hw;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001514 struct i40evf_mac_filter *f;
Greg Rose5eae00c2013-12-21 06:12:45 +00001515 uint32_t rstat_val;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001516 int i = 0, err;
Greg Rose5eae00c2013-12-21 06:12:45 +00001517
1518 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
1519 &adapter->crit_section))
Neerav Parikhf98a2002014-09-13 07:40:44 +00001520 usleep_range(500, 1000);
Mitch Williams3526d802014-03-06 08:59:56 +00001521
1522 if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) {
1523 dev_info(&adapter->pdev->dev, "Requesting reset from PF\n");
1524 i40evf_request_reset(adapter);
1525 }
1526
Mitch Williamsef8693e2014-02-13 03:48:53 -08001527 /* poll until we see the reset actually happen */
1528 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001529 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1530 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
Ashish Shahfd358862014-08-01 13:27:11 -07001531 if ((rstat_val != I40E_VFR_VFACTIVE) &&
1532 (rstat_val != I40E_VFR_COMPLETED))
Greg Rose5eae00c2013-12-21 06:12:45 +00001533 break;
Mitch Williamsc88e38c2014-11-11 20:03:13 +00001534 msleep(I40EVF_RESET_WAIT_MS);
Greg Rose5eae00c2013-12-21 06:12:45 +00001535 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001536 if (i == I40EVF_RESET_WAIT_COUNT) {
Mitch Williamsef8693e2014-02-13 03:48:53 -08001537 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1538 goto continue_reset; /* act like the reset happened */
1539 }
1540
1541 /* wait until the reset is complete and the PF is responding to us */
1542 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
1543 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1544 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
Ashish Shahfd358862014-08-01 13:27:11 -07001545 if ((rstat_val == I40E_VFR_VFACTIVE) ||
1546 (rstat_val == I40E_VFR_COMPLETED))
Mitch Williamsef8693e2014-02-13 03:48:53 -08001547 break;
Mitch Williamsc88e38c2014-11-11 20:03:13 +00001548 msleep(I40EVF_RESET_WAIT_MS);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001549 }
1550 if (i == I40EVF_RESET_WAIT_COUNT) {
Mitch Williams6ba36a22014-08-01 13:27:14 -07001551 struct i40evf_mac_filter *f, *ftmp;
1552 struct i40evf_vlan_filter *fv, *fvtmp;
1553
Greg Rose5eae00c2013-12-21 06:12:45 +00001554 /* reset never finished */
Mitch Williams80e72892014-05-10 04:49:06 +00001555 dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n",
Mitch Williamsef8693e2014-02-13 03:48:53 -08001556 rstat_val);
1557 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
1558
Mitch Williams169f4072014-04-01 07:11:50 +00001559 if (netif_running(adapter->netdev)) {
1560 set_bit(__I40E_DOWN, &adapter->vsi.state);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001561 i40evf_irq_disable(adapter);
1562 i40evf_napi_disable_all(adapter);
1563 netif_tx_disable(netdev);
1564 netif_tx_stop_all_queues(netdev);
1565 netif_carrier_off(netdev);
Mitch Williams169f4072014-04-01 07:11:50 +00001566 i40evf_free_traffic_irqs(adapter);
1567 i40evf_free_all_tx_resources(adapter);
1568 i40evf_free_all_rx_resources(adapter);
1569 }
Mitch Williams6ba36a22014-08-01 13:27:14 -07001570
1571 /* Delete all of the filters, both MAC and VLAN. */
1572 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list,
1573 list) {
1574 list_del(&f->list);
1575 kfree(f);
1576 }
1577 list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list,
1578 list) {
1579 list_del(&fv->list);
1580 kfree(fv);
1581 }
1582
Mitch Williamsef8693e2014-02-13 03:48:53 -08001583 i40evf_free_misc_irq(adapter);
1584 i40evf_reset_interrupt_capability(adapter);
1585 i40evf_free_queues(adapter);
Mitch Williamsd31944d2014-08-01 13:27:13 -07001586 i40evf_free_q_vectors(adapter);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001587 kfree(adapter->vf_res);
1588 i40evf_shutdown_adminq(hw);
1589 adapter->netdev->flags &= ~IFF_UP;
1590 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1591 return; /* Do not attempt to reinit. It's dead, Jim. */
Greg Rose5eae00c2013-12-21 06:12:45 +00001592 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001593
1594continue_reset:
1595 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1596
Mitch Williamsac833bb2015-01-29 07:17:19 +00001597 i40evf_irq_disable(adapter);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001598
Mitch Williams3c8e0b92015-02-27 09:18:31 +00001599 if (netif_running(adapter->netdev)) {
1600 i40evf_napi_disable_all(adapter);
1601 netif_tx_disable(netdev);
1602 netif_tx_stop_all_queues(netdev);
1603 netif_carrier_off(netdev);
1604 }
Mitch Williamsac833bb2015-01-29 07:17:19 +00001605
Greg Rose5eae00c2013-12-21 06:12:45 +00001606 adapter->state = __I40EVF_RESETTING;
1607
1608 /* kill and reinit the admin queue */
1609 if (i40evf_shutdown_adminq(hw))
Mitch Williamsac833bb2015-01-29 07:17:19 +00001610 dev_warn(&adapter->pdev->dev, "Failed to shut down adminq\n");
1611 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001612 err = i40evf_init_adminq(hw);
1613 if (err)
Mitch Williamsac833bb2015-01-29 07:17:19 +00001614 dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n",
1615 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00001616
Greg Rose5eae00c2013-12-21 06:12:45 +00001617 i40evf_map_queues(adapter);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001618
1619 /* re-add all MAC filters */
1620 list_for_each_entry(f, &adapter->mac_filter_list, list) {
1621 f->add = true;
1622 }
1623 /* re-add all VLAN filters */
1624 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
1625 f->add = true;
1626 }
1627 adapter->aq_required = I40EVF_FLAG_AQ_ADD_MAC_FILTER;
1628 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
Greg Rose5eae00c2013-12-21 06:12:45 +00001629 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1630
1631 mod_timer(&adapter->watchdog_timer, jiffies + 2);
1632
1633 if (netif_running(adapter->netdev)) {
1634 /* allocate transmit descriptors */
1635 err = i40evf_setup_all_tx_resources(adapter);
1636 if (err)
1637 goto reset_err;
1638
1639 /* allocate receive descriptors */
1640 err = i40evf_setup_all_rx_resources(adapter);
1641 if (err)
1642 goto reset_err;
1643
1644 i40evf_configure(adapter);
1645
1646 err = i40evf_up_complete(adapter);
1647 if (err)
1648 goto reset_err;
1649
1650 i40evf_irq_enable(adapter, true);
1651 }
1652 return;
1653reset_err:
Mitch Williams80e72892014-05-10 04:49:06 +00001654 dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001655 i40evf_close(adapter->netdev);
1656}
1657
1658/**
1659 * i40evf_adminq_task - worker thread to clean the admin queue
1660 * @work: pointer to work_struct containing our data
1661 **/
1662static void i40evf_adminq_task(struct work_struct *work)
1663{
1664 struct i40evf_adapter *adapter =
1665 container_of(work, struct i40evf_adapter, adminq_task);
1666 struct i40e_hw *hw = &adapter->hw;
1667 struct i40e_arq_event_info event;
1668 struct i40e_virtchnl_msg *v_msg;
1669 i40e_status ret;
Mitch Williams912257e2014-05-22 06:32:07 +00001670 u32 val, oldval;
Greg Rose5eae00c2013-12-21 06:12:45 +00001671 u16 pending;
1672
Mitch Williamsef8693e2014-02-13 03:48:53 -08001673 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
Mitch A Williams72354482014-12-09 08:53:07 +00001674 goto out;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001675
Mitch Williams1001dc32014-11-11 20:02:19 +00001676 event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
1677 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +00001678 if (!event.msg_buf)
Mitch A Williams72354482014-12-09 08:53:07 +00001679 goto out;
Mitch Williams249c8b82014-05-10 04:49:04 +00001680
Greg Rose5eae00c2013-12-21 06:12:45 +00001681 v_msg = (struct i40e_virtchnl_msg *)&event.desc;
1682 do {
1683 ret = i40evf_clean_arq_element(hw, &event, &pending);
Mitch Williams8b011eb2015-01-09 11:18:17 +00001684 if (ret || !v_msg->v_opcode)
Greg Rose5eae00c2013-12-21 06:12:45 +00001685 break; /* No event to process or error cleaning ARQ */
1686
1687 i40evf_virtchnl_completion(adapter, v_msg->v_opcode,
1688 v_msg->v_retval, event.msg_buf,
Mitch Williams1001dc32014-11-11 20:02:19 +00001689 event.msg_len);
Mitch Williams75a64432014-11-11 20:02:42 +00001690 if (pending != 0)
Greg Rose5eae00c2013-12-21 06:12:45 +00001691 memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE);
Greg Rose5eae00c2013-12-21 06:12:45 +00001692 } while (pending);
1693
Mitch Williams912257e2014-05-22 06:32:07 +00001694 /* check for error indications */
1695 val = rd32(hw, hw->aq.arq.len);
1696 oldval = val;
1697 if (val & I40E_VF_ARQLEN_ARQVFE_MASK) {
1698 dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n");
1699 val &= ~I40E_VF_ARQLEN_ARQVFE_MASK;
1700 }
1701 if (val & I40E_VF_ARQLEN_ARQOVFL_MASK) {
1702 dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n");
1703 val &= ~I40E_VF_ARQLEN_ARQOVFL_MASK;
1704 }
1705 if (val & I40E_VF_ARQLEN_ARQCRIT_MASK) {
1706 dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n");
1707 val &= ~I40E_VF_ARQLEN_ARQCRIT_MASK;
1708 }
1709 if (oldval != val)
1710 wr32(hw, hw->aq.arq.len, val);
1711
1712 val = rd32(hw, hw->aq.asq.len);
1713 oldval = val;
1714 if (val & I40E_VF_ATQLEN_ATQVFE_MASK) {
1715 dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n");
1716 val &= ~I40E_VF_ATQLEN_ATQVFE_MASK;
1717 }
1718 if (val & I40E_VF_ATQLEN_ATQOVFL_MASK) {
1719 dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n");
1720 val &= ~I40E_VF_ATQLEN_ATQOVFL_MASK;
1721 }
1722 if (val & I40E_VF_ATQLEN_ATQCRIT_MASK) {
1723 dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n");
1724 val &= ~I40E_VF_ATQLEN_ATQCRIT_MASK;
1725 }
1726 if (oldval != val)
1727 wr32(hw, hw->aq.asq.len, val);
1728
Mitch A Williams72354482014-12-09 08:53:07 +00001729 kfree(event.msg_buf);
1730out:
Greg Rose5eae00c2013-12-21 06:12:45 +00001731 /* re-enable Admin queue interrupt cause */
1732 i40evf_misc_irq_enable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001733}
1734
1735/**
1736 * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
1737 * @adapter: board private structure
1738 *
1739 * Free all transmit software resources
1740 **/
Mitch Williamse284fc82015-03-27 00:12:09 -07001741void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter)
Greg Rose5eae00c2013-12-21 06:12:45 +00001742{
1743 int i;
1744
Mitch Williamscc052922014-10-25 03:24:34 +00001745 for (i = 0; i < adapter->num_active_queues; i++)
Greg Rose5eae00c2013-12-21 06:12:45 +00001746 if (adapter->tx_rings[i]->desc)
1747 i40evf_free_tx_resources(adapter->tx_rings[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00001748}
1749
1750/**
1751 * i40evf_setup_all_tx_resources - allocate all queues Tx resources
1752 * @adapter: board private structure
1753 *
1754 * If this function returns with an error, then it's possible one or
1755 * more of the rings is populated (while the rest are not). It is the
1756 * callers duty to clean those orphaned rings.
1757 *
1758 * Return 0 on success, negative on failure
1759 **/
1760static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter)
1761{
1762 int i, err = 0;
1763
Mitch Williamscc052922014-10-25 03:24:34 +00001764 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williamsd732a182014-04-24 06:41:37 +00001765 adapter->tx_rings[i]->count = adapter->tx_desc_count;
Greg Rose5eae00c2013-12-21 06:12:45 +00001766 err = i40evf_setup_tx_descriptors(adapter->tx_rings[i]);
1767 if (!err)
1768 continue;
1769 dev_err(&adapter->pdev->dev,
1770 "%s: Allocation for Tx Queue %u failed\n",
1771 __func__, i);
1772 break;
1773 }
1774
1775 return err;
1776}
1777
1778/**
1779 * i40evf_setup_all_rx_resources - allocate all queues Rx resources
1780 * @adapter: board private structure
1781 *
1782 * If this function returns with an error, then it's possible one or
1783 * more of the rings is populated (while the rest are not). It is the
1784 * callers duty to clean those orphaned rings.
1785 *
1786 * Return 0 on success, negative on failure
1787 **/
1788static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter)
1789{
1790 int i, err = 0;
1791
Mitch Williamscc052922014-10-25 03:24:34 +00001792 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williamsd732a182014-04-24 06:41:37 +00001793 adapter->rx_rings[i]->count = adapter->rx_desc_count;
Greg Rose5eae00c2013-12-21 06:12:45 +00001794 err = i40evf_setup_rx_descriptors(adapter->rx_rings[i]);
1795 if (!err)
1796 continue;
1797 dev_err(&adapter->pdev->dev,
1798 "%s: Allocation for Rx Queue %u failed\n",
1799 __func__, i);
1800 break;
1801 }
1802 return err;
1803}
1804
1805/**
1806 * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
1807 * @adapter: board private structure
1808 *
1809 * Free all receive software resources
1810 **/
Mitch Williamse284fc82015-03-27 00:12:09 -07001811void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter)
Greg Rose5eae00c2013-12-21 06:12:45 +00001812{
1813 int i;
1814
Mitch Williamscc052922014-10-25 03:24:34 +00001815 for (i = 0; i < adapter->num_active_queues; i++)
Greg Rose5eae00c2013-12-21 06:12:45 +00001816 if (adapter->rx_rings[i]->desc)
1817 i40evf_free_rx_resources(adapter->rx_rings[i]);
1818}
1819
1820/**
1821 * i40evf_open - Called when a network interface is made active
1822 * @netdev: network interface device structure
1823 *
1824 * Returns 0 on success, negative value on failure
1825 *
1826 * The open entry point is called when a network interface is made
1827 * active by the system (IFF_UP). At this point all resources needed
1828 * for transmit and receive operations are allocated, the interrupt
1829 * handler is registered with the OS, the watchdog timer is started,
1830 * and the stack is notified that the interface is ready.
1831 **/
1832static int i40evf_open(struct net_device *netdev)
1833{
1834 struct i40evf_adapter *adapter = netdev_priv(netdev);
1835 int err;
1836
Mitch Williamsef8693e2014-02-13 03:48:53 -08001837 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
1838 dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
1839 return -EIO;
1840 }
Mitch Williamse284fc82015-03-27 00:12:09 -07001841 if (adapter->state != __I40EVF_DOWN || adapter->aq_required)
Greg Rose5eae00c2013-12-21 06:12:45 +00001842 return -EBUSY;
1843
1844 /* allocate transmit descriptors */
1845 err = i40evf_setup_all_tx_resources(adapter);
1846 if (err)
1847 goto err_setup_tx;
1848
1849 /* allocate receive descriptors */
1850 err = i40evf_setup_all_rx_resources(adapter);
1851 if (err)
1852 goto err_setup_rx;
1853
1854 /* clear any pending interrupts, may auto mask */
1855 err = i40evf_request_traffic_irqs(adapter, netdev->name);
1856 if (err)
1857 goto err_req_irq;
1858
1859 i40evf_configure(adapter);
1860
1861 err = i40evf_up_complete(adapter);
1862 if (err)
1863 goto err_req_irq;
1864
1865 i40evf_irq_enable(adapter, true);
1866
1867 return 0;
1868
1869err_req_irq:
1870 i40evf_down(adapter);
1871 i40evf_free_traffic_irqs(adapter);
1872err_setup_rx:
1873 i40evf_free_all_rx_resources(adapter);
1874err_setup_tx:
1875 i40evf_free_all_tx_resources(adapter);
1876
1877 return err;
1878}
1879
1880/**
1881 * i40evf_close - Disables a network interface
1882 * @netdev: network interface device structure
1883 *
1884 * Returns 0, this is not allowed to fail
1885 *
1886 * The close entry point is called when an interface is de-activated
1887 * by the OS. The hardware is still under the drivers control, but
1888 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
1889 * are freed, along with all transmit and receive resources.
1890 **/
1891static int i40evf_close(struct net_device *netdev)
1892{
1893 struct i40evf_adapter *adapter = netdev_priv(netdev);
1894
Mitch Williamsef8693e2014-02-13 03:48:53 -08001895 if (adapter->state <= __I40EVF_DOWN)
1896 return 0;
1897
Mitch Williamsef8693e2014-02-13 03:48:53 -08001898
Greg Rose5eae00c2013-12-21 06:12:45 +00001899 set_bit(__I40E_DOWN, &adapter->vsi.state);
1900
1901 i40evf_down(adapter);
Mitch Williamsddf0b3a2014-05-22 06:31:46 +00001902 adapter->state = __I40EVF_DOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001903 i40evf_free_traffic_irqs(adapter);
1904
Greg Rose5eae00c2013-12-21 06:12:45 +00001905 return 0;
1906}
1907
1908/**
1909 * i40evf_get_stats - Get System Network Statistics
1910 * @netdev: network interface device structure
1911 *
1912 * Returns the address of the device statistics structure.
1913 * The statistics are actually updated from the timer callback.
1914 **/
1915static struct net_device_stats *i40evf_get_stats(struct net_device *netdev)
1916{
1917 struct i40evf_adapter *adapter = netdev_priv(netdev);
1918
1919 /* only return the current stats */
1920 return &adapter->net_stats;
1921}
1922
1923/**
1924 * i40evf_reinit_locked - Software reinit
1925 * @adapter: board private structure
1926 *
1927 * Reinititalizes the ring structures in response to a software configuration
1928 * change. Roughly the same as close followed by open, but skips releasing
1929 * and reallocating the interrupts.
1930 **/
1931void i40evf_reinit_locked(struct i40evf_adapter *adapter)
1932{
1933 struct net_device *netdev = adapter->netdev;
1934 int err;
1935
1936 WARN_ON(in_interrupt());
1937
Greg Rose5eae00c2013-12-21 06:12:45 +00001938 i40evf_down(adapter);
1939
1940 /* allocate transmit descriptors */
1941 err = i40evf_setup_all_tx_resources(adapter);
1942 if (err)
1943 goto err_reinit;
1944
1945 /* allocate receive descriptors */
1946 err = i40evf_setup_all_rx_resources(adapter);
1947 if (err)
1948 goto err_reinit;
1949
1950 i40evf_configure(adapter);
1951
1952 err = i40evf_up_complete(adapter);
1953 if (err)
1954 goto err_reinit;
1955
1956 i40evf_irq_enable(adapter, true);
1957 return;
1958
1959err_reinit:
Mitch Williams80e72892014-05-10 04:49:06 +00001960 dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001961 i40evf_close(netdev);
1962}
1963
1964/**
1965 * i40evf_change_mtu - Change the Maximum Transfer Unit
1966 * @netdev: network interface device structure
1967 * @new_mtu: new value for maximum frame size
1968 *
1969 * Returns 0 on success, negative on failure
1970 **/
1971static int i40evf_change_mtu(struct net_device *netdev, int new_mtu)
1972{
1973 struct i40evf_adapter *adapter = netdev_priv(netdev);
1974 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
1975
1976 if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
1977 return -EINVAL;
1978
1979 /* must set new MTU before calling down or up */
1980 netdev->mtu = new_mtu;
1981 i40evf_reinit_locked(adapter);
1982 return 0;
1983}
1984
1985static const struct net_device_ops i40evf_netdev_ops = {
1986 .ndo_open = i40evf_open,
1987 .ndo_stop = i40evf_close,
1988 .ndo_start_xmit = i40evf_xmit_frame,
1989 .ndo_get_stats = i40evf_get_stats,
1990 .ndo_set_rx_mode = i40evf_set_rx_mode,
1991 .ndo_validate_addr = eth_validate_addr,
1992 .ndo_set_mac_address = i40evf_set_mac,
1993 .ndo_change_mtu = i40evf_change_mtu,
1994 .ndo_tx_timeout = i40evf_tx_timeout,
1995 .ndo_vlan_rx_add_vid = i40evf_vlan_rx_add_vid,
1996 .ndo_vlan_rx_kill_vid = i40evf_vlan_rx_kill_vid,
1997};
1998
1999/**
2000 * i40evf_check_reset_complete - check that VF reset is complete
2001 * @hw: pointer to hw struct
2002 *
2003 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
2004 **/
2005static int i40evf_check_reset_complete(struct i40e_hw *hw)
2006{
2007 u32 rstat;
2008 int i;
2009
2010 for (i = 0; i < 100; i++) {
Ashish Shahfd358862014-08-01 13:27:11 -07002011 rstat = rd32(hw, I40E_VFGEN_RSTAT) &
2012 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
2013 if ((rstat == I40E_VFR_VFACTIVE) ||
2014 (rstat == I40E_VFR_COMPLETED))
Greg Rose5eae00c2013-12-21 06:12:45 +00002015 return 0;
Neerav Parikhf98a2002014-09-13 07:40:44 +00002016 usleep_range(10, 20);
Greg Rose5eae00c2013-12-21 06:12:45 +00002017 }
2018 return -EBUSY;
2019}
2020
2021/**
2022 * i40evf_init_task - worker thread to perform delayed initialization
2023 * @work: pointer to work_struct containing our data
2024 *
2025 * This task completes the work that was begun in probe. Due to the nature
2026 * of VF-PF communications, we may need to wait tens of milliseconds to get
Joe Perchesdbedd442015-03-06 20:49:12 -08002027 * responses back from the PF. Rather than busy-wait in probe and bog down the
Greg Rose5eae00c2013-12-21 06:12:45 +00002028 * whole system, we'll do it in a task so we can sleep.
2029 * This task only runs during driver init. Once we've established
2030 * communications with the PF driver and set up our netdev, the watchdog
2031 * takes over.
2032 **/
2033static void i40evf_init_task(struct work_struct *work)
2034{
2035 struct i40evf_adapter *adapter = container_of(work,
2036 struct i40evf_adapter,
2037 init_task.work);
2038 struct net_device *netdev = adapter->netdev;
2039 struct i40evf_mac_filter *f;
2040 struct i40e_hw *hw = &adapter->hw;
2041 struct pci_dev *pdev = adapter->pdev;
2042 int i, err, bufsz;
2043
2044 switch (adapter->state) {
2045 case __I40EVF_STARTUP:
2046 /* driver loaded, probe complete */
Mitch Williamsef8693e2014-02-13 03:48:53 -08002047 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
2048 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
Greg Rose5eae00c2013-12-21 06:12:45 +00002049 err = i40e_set_mac_type(hw);
2050 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002051 dev_err(&pdev->dev, "Failed to set MAC type (%d)\n",
2052 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002053 goto err;
2054 }
2055 err = i40evf_check_reset_complete(hw);
2056 if (err) {
Mitch Williams0d9c7ea2014-04-23 04:50:00 +00002057 dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n",
Mitch Williams75a64432014-11-11 20:02:42 +00002058 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002059 goto err;
2060 }
2061 hw->aq.num_arq_entries = I40EVF_AQ_LEN;
2062 hw->aq.num_asq_entries = I40EVF_AQ_LEN;
2063 hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2064 hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2065
2066 err = i40evf_init_adminq(hw);
2067 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002068 dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n",
2069 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002070 goto err;
2071 }
2072 err = i40evf_send_api_ver(adapter);
2073 if (err) {
Mitch Williams10bdd672014-03-06 08:59:53 +00002074 dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002075 i40evf_shutdown_adminq(hw);
2076 goto err;
2077 }
2078 adapter->state = __I40EVF_INIT_VERSION_CHECK;
2079 goto restart;
Greg Rose5eae00c2013-12-21 06:12:45 +00002080 case __I40EVF_INIT_VERSION_CHECK:
Mitch Williams10bdd672014-03-06 08:59:53 +00002081 if (!i40evf_asq_done(hw)) {
Mitch Williams80e72892014-05-10 04:49:06 +00002082 dev_err(&pdev->dev, "Admin queue command never completed\n");
Mitch Williams906a6932014-11-13 03:06:12 +00002083 i40evf_shutdown_adminq(hw);
2084 adapter->state = __I40EVF_STARTUP;
Greg Rose5eae00c2013-12-21 06:12:45 +00002085 goto err;
Mitch Williams10bdd672014-03-06 08:59:53 +00002086 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002087
2088 /* aq msg sent, awaiting reply */
2089 err = i40evf_verify_api_ver(adapter);
2090 if (err) {
Mitch A Williamsd4f82fd2014-12-09 08:53:03 +00002091 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
Mitch Williams56f99202014-06-04 04:22:41 +00002092 err = i40evf_send_api_ver(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002093 goto err;
2094 }
2095 err = i40evf_send_vf_config_msg(adapter);
2096 if (err) {
Mitch Williams3f2ab172014-06-04 04:22:40 +00002097 dev_err(&pdev->dev, "Unable to send config request (%d)\n",
Greg Rose5eae00c2013-12-21 06:12:45 +00002098 err);
2099 goto err;
2100 }
2101 adapter->state = __I40EVF_INIT_GET_RESOURCES;
2102 goto restart;
Greg Rose5eae00c2013-12-21 06:12:45 +00002103 case __I40EVF_INIT_GET_RESOURCES:
2104 /* aq msg sent, awaiting reply */
2105 if (!adapter->vf_res) {
2106 bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
2107 (I40E_MAX_VF_VSI *
2108 sizeof(struct i40e_virtchnl_vsi_resource));
2109 adapter->vf_res = kzalloc(bufsz, GFP_KERNEL);
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002110 if (!adapter->vf_res)
Greg Rose5eae00c2013-12-21 06:12:45 +00002111 goto err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002112 }
2113 err = i40evf_get_vf_config(adapter);
Mitch Williams906a6932014-11-13 03:06:12 +00002114 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) {
Mitch Williams906a6932014-11-13 03:06:12 +00002115 err = i40evf_send_vf_config_msg(adapter);
2116 goto err;
2117 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002118 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002119 dev_err(&pdev->dev, "Unable to get VF config (%d)\n",
2120 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002121 goto err_alloc;
2122 }
2123 adapter->state = __I40EVF_INIT_SW;
2124 break;
2125 default:
2126 goto err_alloc;
2127 }
2128 /* got VF config message back from PF, now we can parse it */
2129 for (i = 0; i < adapter->vf_res->num_vsis; i++) {
2130 if (adapter->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
2131 adapter->vsi_res = &adapter->vf_res->vsi_res[i];
2132 }
2133 if (!adapter->vsi_res) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002134 dev_err(&pdev->dev, "No LAN VSI found\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00002135 goto err_alloc;
2136 }
2137
2138 adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED;
2139
Greg Rose5eae00c2013-12-21 06:12:45 +00002140 netdev->netdev_ops = &i40evf_netdev_ops;
2141 i40evf_set_ethtool_ops(netdev);
2142 netdev->watchdog_timeo = 5 * HZ;
Mitch Williamsdbbd8112014-02-20 19:29:08 -08002143 netdev->features |= NETIF_F_HIGHDMA |
2144 NETIF_F_SG |
Greg Rose5eae00c2013-12-21 06:12:45 +00002145 NETIF_F_IP_CSUM |
2146 NETIF_F_SCTP_CSUM |
2147 NETIF_F_IPV6_CSUM |
2148 NETIF_F_TSO |
2149 NETIF_F_TSO6 |
Greg Rose3415e8c2014-01-30 12:40:27 +00002150 NETIF_F_RXCSUM |
Greg Rose5eae00c2013-12-21 06:12:45 +00002151 NETIF_F_GRO;
2152
2153 if (adapter->vf_res->vf_offload_flags
2154 & I40E_VIRTCHNL_VF_OFFLOAD_VLAN) {
2155 netdev->vlan_features = netdev->features;
2156 netdev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2157 NETIF_F_HW_VLAN_CTAG_RX |
2158 NETIF_F_HW_VLAN_CTAG_FILTER;
2159 }
2160
Greg Rose3415e8c2014-01-30 12:40:27 +00002161 /* copy netdev features into list of user selectable features */
2162 netdev->hw_features |= netdev->features;
2163 netdev->hw_features &= ~NETIF_F_RXCSUM;
2164
Greg Rose5eae00c2013-12-21 06:12:45 +00002165 if (!is_valid_ether_addr(adapter->hw.mac.addr)) {
Mitch Williamsb34f90e2014-05-10 04:49:07 +00002166 dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n",
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002167 adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002168 random_ether_addr(adapter->hw.mac.addr);
2169 }
Greg Rose9a173902014-05-22 06:32:02 +00002170 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
2171 ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002172
Greg Rose5eae00c2013-12-21 06:12:45 +00002173 f = kzalloc(sizeof(*f), GFP_ATOMIC);
Mitch Williams348d4992014-11-11 20:02:52 +00002174 if (!f)
Greg Rose5eae00c2013-12-21 06:12:45 +00002175 goto err_sw_init;
2176
Greg Rose9a173902014-05-22 06:32:02 +00002177 ether_addr_copy(f->macaddr, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002178 f->add = true;
2179 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
2180
2181 list_add(&f->list, &adapter->mac_filter_list);
2182
2183 init_timer(&adapter->watchdog_timer);
2184 adapter->watchdog_timer.function = &i40evf_watchdog_timer;
2185 adapter->watchdog_timer.data = (unsigned long)adapter;
2186 mod_timer(&adapter->watchdog_timer, jiffies + 1);
2187
Mitch Williamscc052922014-10-25 03:24:34 +00002188 adapter->num_active_queues = min_t(int,
2189 adapter->vsi_res->num_queue_pairs,
2190 (int)(num_online_cpus()));
Mitch Williamsd732a182014-04-24 06:41:37 +00002191 adapter->tx_desc_count = I40EVF_DEFAULT_TXD;
2192 adapter->rx_desc_count = I40EVF_DEFAULT_RXD;
Greg Rose5eae00c2013-12-21 06:12:45 +00002193 err = i40evf_init_interrupt_scheme(adapter);
2194 if (err)
2195 goto err_sw_init;
2196 i40evf_map_rings_to_vectors(adapter);
2197 i40evf_configure_rss(adapter);
2198 err = i40evf_request_misc_irq(adapter);
2199 if (err)
2200 goto err_sw_init;
2201
2202 netif_carrier_off(netdev);
2203
Greg Rose5eae00c2013-12-21 06:12:45 +00002204 adapter->vsi.id = adapter->vsi_res->vsi_id;
2205 adapter->vsi.seid = adapter->vsi_res->vsi_id; /* dummy */
2206 adapter->vsi.back = adapter;
2207 adapter->vsi.base_vector = 1;
2208 adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK;
Mitch Williamsca99eb92014-04-04 04:43:07 +00002209 adapter->vsi.rx_itr_setting = (I40E_ITR_DYNAMIC |
2210 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
2211 adapter->vsi.tx_itr_setting = (I40E_ITR_DYNAMIC |
2212 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
Greg Rose5eae00c2013-12-21 06:12:45 +00002213 adapter->vsi.netdev = adapter->netdev;
2214
Mitch Williamsef8693e2014-02-13 03:48:53 -08002215 if (!adapter->netdev_registered) {
2216 err = register_netdev(netdev);
2217 if (err)
2218 goto err_register;
2219 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002220
2221 adapter->netdev_registered = true;
2222
2223 netif_tx_stop_all_queues(netdev);
2224
Mitch Williamsb34f90e2014-05-10 04:49:07 +00002225 dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002226 if (netdev->features & NETIF_F_GRO)
2227 dev_info(&pdev->dev, "GRO is enabled\n");
2228
2229 dev_info(&pdev->dev, "%s\n", i40evf_driver_string);
2230 adapter->state = __I40EVF_DOWN;
2231 set_bit(__I40E_DOWN, &adapter->vsi.state);
2232 i40evf_misc_irq_enable(adapter);
2233 return;
2234restart:
2235 schedule_delayed_work(&adapter->init_task,
2236 msecs_to_jiffies(50));
2237 return;
2238
2239err_register:
2240 i40evf_free_misc_irq(adapter);
2241err_sw_init:
2242 i40evf_reset_interrupt_capability(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002243err_alloc:
2244 kfree(adapter->vf_res);
2245 adapter->vf_res = NULL;
2246err:
2247 /* Things went into the weeds, so try again later */
2248 if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) {
Mitch Williams80e72892014-05-10 04:49:06 +00002249 dev_err(&pdev->dev, "Failed to communicate with PF; giving up\n");
Mitch Williamsef8693e2014-02-13 03:48:53 -08002250 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
Greg Rose5eae00c2013-12-21 06:12:45 +00002251 return; /* do not reschedule */
2252 }
2253 schedule_delayed_work(&adapter->init_task, HZ * 3);
Greg Rose5eae00c2013-12-21 06:12:45 +00002254}
2255
2256/**
2257 * i40evf_shutdown - Shutdown the device in preparation for a reboot
2258 * @pdev: pci device structure
2259 **/
2260static void i40evf_shutdown(struct pci_dev *pdev)
2261{
2262 struct net_device *netdev = pci_get_drvdata(pdev);
Mitch Williams00293fd2015-01-09 11:18:18 +00002263 struct i40evf_adapter *adapter = netdev_priv(netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +00002264
2265 netif_device_detach(netdev);
2266
2267 if (netif_running(netdev))
2268 i40evf_close(netdev);
2269
Mitch Williams00293fd2015-01-09 11:18:18 +00002270 /* Prevent the watchdog from running. */
2271 adapter->state = __I40EVF_REMOVE;
2272 adapter->aq_required = 0;
2273 adapter->aq_pending = 0;
2274
Greg Rose5eae00c2013-12-21 06:12:45 +00002275#ifdef CONFIG_PM
2276 pci_save_state(pdev);
2277
2278#endif
2279 pci_disable_device(pdev);
2280}
2281
2282/**
2283 * i40evf_probe - Device Initialization Routine
2284 * @pdev: PCI device information struct
2285 * @ent: entry in i40evf_pci_tbl
2286 *
2287 * Returns 0 on success, negative on failure
2288 *
2289 * i40evf_probe initializes an adapter identified by a pci_dev structure.
2290 * The OS initialization, configuring of the adapter private structure,
2291 * and a hardware reset occur.
2292 **/
2293static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2294{
2295 struct net_device *netdev;
2296 struct i40evf_adapter *adapter = NULL;
2297 struct i40e_hw *hw = NULL;
Mitch Williamsdbbd8112014-02-20 19:29:08 -08002298 int err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002299
2300 err = pci_enable_device(pdev);
2301 if (err)
2302 return err;
2303
Mitch Williams64942942014-02-11 08:26:33 +00002304 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Mitch Williams64942942014-02-11 08:26:33 +00002305 if (err) {
Jean Sacrene3e3bfd2014-03-25 04:30:27 +00002306 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2307 if (err) {
2308 dev_err(&pdev->dev,
2309 "DMA configuration failed: 0x%x\n", err);
2310 goto err_dma;
2311 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002312 }
2313
2314 err = pci_request_regions(pdev, i40evf_driver_name);
2315 if (err) {
2316 dev_err(&pdev->dev,
2317 "pci_request_regions failed 0x%x\n", err);
2318 goto err_pci_reg;
2319 }
2320
2321 pci_enable_pcie_error_reporting(pdev);
2322
2323 pci_set_master(pdev);
2324
2325 netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter),
2326 MAX_TX_QUEUES);
2327 if (!netdev) {
2328 err = -ENOMEM;
2329 goto err_alloc_etherdev;
2330 }
2331
2332 SET_NETDEV_DEV(netdev, &pdev->dev);
2333
2334 pci_set_drvdata(pdev, netdev);
2335 adapter = netdev_priv(netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +00002336
2337 adapter->netdev = netdev;
2338 adapter->pdev = pdev;
2339
2340 hw = &adapter->hw;
2341 hw->back = adapter;
2342
2343 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
2344 adapter->state = __I40EVF_STARTUP;
2345
2346 /* Call save state here because it relies on the adapter struct. */
2347 pci_save_state(pdev);
2348
2349 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2350 pci_resource_len(pdev, 0));
2351 if (!hw->hw_addr) {
2352 err = -EIO;
2353 goto err_ioremap;
2354 }
2355 hw->vendor_id = pdev->vendor;
2356 hw->device_id = pdev->device;
2357 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2358 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2359 hw->subsystem_device_id = pdev->subsystem_device;
2360 hw->bus.device = PCI_SLOT(pdev->devfn);
2361 hw->bus.func = PCI_FUNC(pdev->devfn);
2362
Serey Kong8bb1a542014-08-01 13:27:15 -07002363 INIT_LIST_HEAD(&adapter->mac_filter_list);
2364 INIT_LIST_HEAD(&adapter->vlan_filter_list);
2365
Greg Rose5eae00c2013-12-21 06:12:45 +00002366 INIT_WORK(&adapter->reset_task, i40evf_reset_task);
2367 INIT_WORK(&adapter->adminq_task, i40evf_adminq_task);
2368 INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task);
2369 INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task);
2370 schedule_delayed_work(&adapter->init_task, 10);
2371
2372 return 0;
2373
2374err_ioremap:
2375 free_netdev(netdev);
2376err_alloc_etherdev:
2377 pci_release_regions(pdev);
2378err_pci_reg:
2379err_dma:
2380 pci_disable_device(pdev);
2381 return err;
2382}
2383
2384#ifdef CONFIG_PM
2385/**
2386 * i40evf_suspend - Power management suspend routine
2387 * @pdev: PCI device information struct
2388 * @state: unused
2389 *
2390 * Called when the system (VM) is entering sleep/suspend.
2391 **/
2392static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state)
2393{
2394 struct net_device *netdev = pci_get_drvdata(pdev);
2395 struct i40evf_adapter *adapter = netdev_priv(netdev);
2396 int retval = 0;
2397
2398 netif_device_detach(netdev);
2399
2400 if (netif_running(netdev)) {
2401 rtnl_lock();
2402 i40evf_down(adapter);
2403 rtnl_unlock();
2404 }
2405 i40evf_free_misc_irq(adapter);
2406 i40evf_reset_interrupt_capability(adapter);
2407
2408 retval = pci_save_state(pdev);
2409 if (retval)
2410 return retval;
2411
2412 pci_disable_device(pdev);
2413
2414 return 0;
2415}
2416
2417/**
Joe Perchesdbedd442015-03-06 20:49:12 -08002418 * i40evf_resume - Power management resume routine
Greg Rose5eae00c2013-12-21 06:12:45 +00002419 * @pdev: PCI device information struct
2420 *
2421 * Called when the system (VM) is resumed from sleep/suspend.
2422 **/
2423static int i40evf_resume(struct pci_dev *pdev)
2424{
2425 struct i40evf_adapter *adapter = pci_get_drvdata(pdev);
2426 struct net_device *netdev = adapter->netdev;
2427 u32 err;
2428
2429 pci_set_power_state(pdev, PCI_D0);
2430 pci_restore_state(pdev);
2431 /* pci_restore_state clears dev->state_saved so call
2432 * pci_save_state to restore it.
2433 */
2434 pci_save_state(pdev);
2435
2436 err = pci_enable_device_mem(pdev);
2437 if (err) {
2438 dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n");
2439 return err;
2440 }
2441 pci_set_master(pdev);
2442
2443 rtnl_lock();
2444 err = i40evf_set_interrupt_capability(adapter);
2445 if (err) {
2446 dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n");
2447 return err;
2448 }
2449 err = i40evf_request_misc_irq(adapter);
2450 rtnl_unlock();
2451 if (err) {
2452 dev_err(&pdev->dev, "Cannot get interrupt vector.\n");
2453 return err;
2454 }
2455
2456 schedule_work(&adapter->reset_task);
2457
2458 netif_device_attach(netdev);
2459
2460 return err;
2461}
2462
2463#endif /* CONFIG_PM */
2464/**
2465 * i40evf_remove - Device Removal Routine
2466 * @pdev: PCI device information struct
2467 *
2468 * i40evf_remove is called by the PCI subsystem to alert the driver
2469 * that it should release a PCI device. The could be caused by a
2470 * Hot-Plug event, or because the driver is going to be removed from
2471 * memory.
2472 **/
2473static void i40evf_remove(struct pci_dev *pdev)
2474{
2475 struct net_device *netdev = pci_get_drvdata(pdev);
2476 struct i40evf_adapter *adapter = netdev_priv(netdev);
Mitch Williams6ba36a22014-08-01 13:27:14 -07002477 struct i40evf_mac_filter *f, *ftmp;
Greg Rose5eae00c2013-12-21 06:12:45 +00002478 struct i40e_hw *hw = &adapter->hw;
2479
2480 cancel_delayed_work_sync(&adapter->init_task);
Mitch Williamsef8693e2014-02-13 03:48:53 -08002481 cancel_work_sync(&adapter->reset_task);
Greg Rose5eae00c2013-12-21 06:12:45 +00002482
2483 if (adapter->netdev_registered) {
2484 unregister_netdev(netdev);
2485 adapter->netdev_registered = false;
2486 }
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00002487
Mitch Williamsf4a71882015-01-09 11:18:16 +00002488 /* Shut down all the garbage mashers on the detention level */
Greg Rose5eae00c2013-12-21 06:12:45 +00002489 adapter->state = __I40EVF_REMOVE;
Mitch Williamsf4a71882015-01-09 11:18:16 +00002490 adapter->aq_required = 0;
2491 adapter->aq_pending = 0;
2492 i40evf_request_reset(adapter);
2493 msleep(20);
2494 /* If the FW isn't responding, kick it once, but only once. */
2495 if (!i40evf_asq_done(hw)) {
2496 i40evf_request_reset(adapter);
2497 msleep(20);
2498 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002499
Mitch Williamsdbb01c82014-02-20 19:29:07 -08002500 if (adapter->msix_entries) {
Greg Rose5eae00c2013-12-21 06:12:45 +00002501 i40evf_misc_irq_disable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002502 i40evf_free_misc_irq(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002503 i40evf_reset_interrupt_capability(adapter);
Mitch Williamsd31944d2014-08-01 13:27:13 -07002504 i40evf_free_q_vectors(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002505 }
2506
Mitch Williamse5d17c32014-06-04 04:22:38 +00002507 if (adapter->watchdog_timer.function)
2508 del_timer_sync(&adapter->watchdog_timer);
2509
Mitch Williamsdbb01c82014-02-20 19:29:07 -08002510 flush_scheduled_work();
2511
Greg Rose5eae00c2013-12-21 06:12:45 +00002512 if (hw->aq.asq.count)
2513 i40evf_shutdown_adminq(hw);
2514
2515 iounmap(hw->hw_addr);
2516 pci_release_regions(pdev);
2517
Mitch Williamse284fc82015-03-27 00:12:09 -07002518 i40evf_free_all_tx_resources(adapter);
2519 i40evf_free_all_rx_resources(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002520 i40evf_free_queues(adapter);
2521 kfree(adapter->vf_res);
Mitch Williams6ba36a22014-08-01 13:27:14 -07002522 /* If we got removed before an up/down sequence, we've got a filter
2523 * hanging out there that we need to get rid of.
2524 */
2525 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
2526 list_del(&f->list);
2527 kfree(f);
2528 }
Mitch A Williams37dfdf32014-12-09 08:53:05 +00002529 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
2530 list_del(&f->list);
2531 kfree(f);
2532 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002533
2534 free_netdev(netdev);
2535
2536 pci_disable_pcie_error_reporting(pdev);
2537
2538 pci_disable_device(pdev);
2539}
2540
2541static struct pci_driver i40evf_driver = {
2542 .name = i40evf_driver_name,
2543 .id_table = i40evf_pci_tbl,
2544 .probe = i40evf_probe,
2545 .remove = i40evf_remove,
2546#ifdef CONFIG_PM
2547 .suspend = i40evf_suspend,
2548 .resume = i40evf_resume,
2549#endif
2550 .shutdown = i40evf_shutdown,
2551};
2552
2553/**
2554 * i40e_init_module - Driver Registration Routine
2555 *
2556 * i40e_init_module is the first routine called when the driver is
2557 * loaded. All it does is register with the PCI subsystem.
2558 **/
2559static int __init i40evf_init_module(void)
2560{
2561 int ret;
Mitch Williams75a64432014-11-11 20:02:42 +00002562
Greg Rose5eae00c2013-12-21 06:12:45 +00002563 pr_info("i40evf: %s - version %s\n", i40evf_driver_string,
Mitch Williams75a64432014-11-11 20:02:42 +00002564 i40evf_driver_version);
Greg Rose5eae00c2013-12-21 06:12:45 +00002565
2566 pr_info("%s\n", i40evf_copyright);
2567
2568 ret = pci_register_driver(&i40evf_driver);
2569 return ret;
2570}
2571
2572module_init(i40evf_init_module);
2573
2574/**
2575 * i40e_exit_module - Driver Exit Cleanup Routine
2576 *
2577 * i40e_exit_module is called just before the driver is removed
2578 * from memory.
2579 **/
2580static void __exit i40evf_exit_module(void)
2581{
2582 pci_unregister_driver(&i40evf_driver);
2583}
2584
2585module_exit(i40evf_exit_module);
2586
2587/* i40evf_main.c */