]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/net/ethernet/intel/i40evf/i40evf_main.c
i40e/i40evf: Bump version to 1.3.6 for i40e and 1.3.2 for i40evf
[karo-tx-linux.git] / drivers / net / ethernet / intel / i40evf / i40evf_main.c
1 /*******************************************************************************
2  *
3  * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
4  * Copyright(c) 2013 - 2015 Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  * The full GNU General Public License is included in this distribution in
19  * the file called "COPYING".
20  *
21  * Contact Information:
22  * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24  *
25  ******************************************************************************/
26
27 #include "i40evf.h"
28 #include "i40e_prototype.h"
29 static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter);
30 static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter);
31 static int i40evf_close(struct net_device *netdev);
32
33 char i40evf_driver_name[] = "i40evf";
34 static const char i40evf_driver_string[] =
35         "Intel(R) XL710/X710 Virtual Function Network Driver";
36
37 #define DRV_VERSION "1.3.2"
38 const char i40evf_driver_version[] = DRV_VERSION;
39 static const char i40evf_copyright[] =
40         "Copyright (c) 2013 - 2014 Intel Corporation.";
41
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  */
50 static const struct pci_device_id i40evf_pci_tbl[] = {
51         {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF), 0},
52         /* required last entry */
53         {0, }
54 };
55
56 MODULE_DEVICE_TABLE(pci, i40evf_pci_tbl);
57
58 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
59 MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver");
60 MODULE_LICENSE("GPL");
61 MODULE_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  **/
70 i40e_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  **/
93 i40e_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  **/
110 i40e_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  **/
130 i40e_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  **/
148 void 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  **/
168 static void i40evf_tx_timeout(struct net_device *netdev)
169 {
170         struct i40evf_adapter *adapter = netdev_priv(netdev);
171
172         adapter->tx_timeout_count++;
173         if (!(adapter->flags & (I40EVF_FLAG_RESET_PENDING |
174                                 I40EVF_FLAG_RESET_NEEDED))) {
175                 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
176                 schedule_work(&adapter->reset_task);
177         }
178 }
179
180 /**
181  * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC
182  * @adapter: board private structure
183  **/
184 static void i40evf_misc_irq_disable(struct i40evf_adapter *adapter)
185 {
186         struct i40e_hw *hw = &adapter->hw;
187
188         wr32(hw, I40E_VFINT_DYN_CTL01, 0);
189
190         /* read flush */
191         rd32(hw, I40E_VFGEN_RSTAT);
192
193         synchronize_irq(adapter->msix_entries[0].vector);
194 }
195
196 /**
197  * i40evf_misc_irq_enable - Enable default interrupt generation settings
198  * @adapter: board private structure
199  **/
200 static void i40evf_misc_irq_enable(struct i40evf_adapter *adapter)
201 {
202         struct i40e_hw *hw = &adapter->hw;
203
204         wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK |
205                                        I40E_VFINT_DYN_CTL01_ITR_INDX_MASK);
206         wr32(hw, I40E_VFINT_ICR0_ENA1, I40E_VFINT_ICR0_ENA_ADMINQ_MASK);
207
208         /* read flush */
209         rd32(hw, I40E_VFGEN_RSTAT);
210 }
211
212 /**
213  * i40evf_irq_disable - Mask off interrupt generation on the NIC
214  * @adapter: board private structure
215  **/
216 static void i40evf_irq_disable(struct i40evf_adapter *adapter)
217 {
218         int i;
219         struct i40e_hw *hw = &adapter->hw;
220
221         if (!adapter->msix_entries)
222                 return;
223
224         for (i = 1; i < adapter->num_msix_vectors; i++) {
225                 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), 0);
226                 synchronize_irq(adapter->msix_entries[i].vector);
227         }
228         /* read flush */
229         rd32(hw, I40E_VFGEN_RSTAT);
230 }
231
232 /**
233  * i40evf_irq_enable_queues - Enable interrupt for specified queues
234  * @adapter: board private structure
235  * @mask: bitmap of queues to enable
236  **/
237 void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask)
238 {
239         struct i40e_hw *hw = &adapter->hw;
240         int i;
241
242         for (i = 1; i < adapter->num_msix_vectors; i++) {
243                 if (mask & (1 << (i - 1))) {
244                         wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1),
245                              I40E_VFINT_DYN_CTLN1_INTENA_MASK |
246                              I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
247                              I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
248                 }
249         }
250 }
251
252 /**
253  * i40evf_fire_sw_int - Generate SW interrupt for specified vectors
254  * @adapter: board private structure
255  * @mask: bitmap of vectors to trigger
256  **/
257 static void i40evf_fire_sw_int(struct i40evf_adapter *adapter, u32 mask)
258 {
259         struct i40e_hw *hw = &adapter->hw;
260         int i;
261         uint32_t dyn_ctl;
262
263         if (mask & 1) {
264                 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTL01);
265                 dyn_ctl |= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK |
266                            I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
267                            I40E_VFINT_DYN_CTLN_CLEARPBA_MASK;
268                 wr32(hw, I40E_VFINT_DYN_CTL01, dyn_ctl);
269         }
270         for (i = 1; i < adapter->num_msix_vectors; i++) {
271                 if (mask & (1 << i)) {
272                         dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTLN1(i - 1));
273                         dyn_ctl |= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK |
274                                    I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
275                                    I40E_VFINT_DYN_CTLN_CLEARPBA_MASK;
276                         wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), dyn_ctl);
277                 }
278         }
279 }
280
281 /**
282  * i40evf_irq_enable - Enable default interrupt generation settings
283  * @adapter: board private structure
284  **/
285 void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush)
286 {
287         struct i40e_hw *hw = &adapter->hw;
288
289         i40evf_misc_irq_enable(adapter);
290         i40evf_irq_enable_queues(adapter, ~0);
291
292         if (flush)
293                 rd32(hw, I40E_VFGEN_RSTAT);
294 }
295
296 /**
297  * i40evf_msix_aq - Interrupt handler for vector 0
298  * @irq: interrupt number
299  * @data: pointer to netdev
300  **/
301 static irqreturn_t i40evf_msix_aq(int irq, void *data)
302 {
303         struct net_device *netdev = data;
304         struct i40evf_adapter *adapter = netdev_priv(netdev);
305         struct i40e_hw *hw = &adapter->hw;
306         u32 val;
307         u32 ena_mask;
308
309         /* handle non-queue interrupts */
310         val = rd32(hw, I40E_VFINT_ICR01);
311         ena_mask = rd32(hw, I40E_VFINT_ICR0_ENA1);
312
313
314         val = rd32(hw, I40E_VFINT_DYN_CTL01);
315         val = val | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK;
316         wr32(hw, I40E_VFINT_DYN_CTL01, val);
317
318         /* schedule work on the private workqueue */
319         schedule_work(&adapter->adminq_task);
320
321         return IRQ_HANDLED;
322 }
323
324 /**
325  * i40evf_msix_clean_rings - MSIX mode Interrupt Handler
326  * @irq: interrupt number
327  * @data: pointer to a q_vector
328  **/
329 static irqreturn_t i40evf_msix_clean_rings(int irq, void *data)
330 {
331         struct i40e_q_vector *q_vector = data;
332
333         if (!q_vector->tx.ring && !q_vector->rx.ring)
334                 return IRQ_HANDLED;
335
336         napi_schedule(&q_vector->napi);
337
338         return IRQ_HANDLED;
339 }
340
341 /**
342  * i40evf_map_vector_to_rxq - associate irqs with rx queues
343  * @adapter: board private structure
344  * @v_idx: interrupt number
345  * @r_idx: queue number
346  **/
347 static void
348 i40evf_map_vector_to_rxq(struct i40evf_adapter *adapter, int v_idx, int r_idx)
349 {
350         struct i40e_q_vector *q_vector = adapter->q_vector[v_idx];
351         struct i40e_ring *rx_ring = adapter->rx_rings[r_idx];
352
353         rx_ring->q_vector = q_vector;
354         rx_ring->next = q_vector->rx.ring;
355         rx_ring->vsi = &adapter->vsi;
356         q_vector->rx.ring = rx_ring;
357         q_vector->rx.count++;
358         q_vector->rx.latency_range = I40E_LOW_LATENCY;
359 }
360
361 /**
362  * i40evf_map_vector_to_txq - associate irqs with tx queues
363  * @adapter: board private structure
364  * @v_idx: interrupt number
365  * @t_idx: queue number
366  **/
367 static void
368 i40evf_map_vector_to_txq(struct i40evf_adapter *adapter, int v_idx, int t_idx)
369 {
370         struct i40e_q_vector *q_vector = adapter->q_vector[v_idx];
371         struct i40e_ring *tx_ring = adapter->tx_rings[t_idx];
372
373         tx_ring->q_vector = q_vector;
374         tx_ring->next = q_vector->tx.ring;
375         tx_ring->vsi = &adapter->vsi;
376         q_vector->tx.ring = tx_ring;
377         q_vector->tx.count++;
378         q_vector->tx.latency_range = I40E_LOW_LATENCY;
379         q_vector->num_ringpairs++;
380         q_vector->ring_mask |= (1 << t_idx);
381 }
382
383 /**
384  * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors
385  * @adapter: board private structure to initialize
386  *
387  * This function maps descriptor rings to the queue-specific vectors
388  * we were allotted through the MSI-X enabling code.  Ideally, we'd have
389  * one vector per ring/queue, but on a constrained vector budget, we
390  * group the rings as "efficiently" as possible.  You would add new
391  * mapping configurations in here.
392  **/
393 static int i40evf_map_rings_to_vectors(struct i40evf_adapter *adapter)
394 {
395         int q_vectors;
396         int v_start = 0;
397         int rxr_idx = 0, txr_idx = 0;
398         int rxr_remaining = adapter->num_active_queues;
399         int txr_remaining = adapter->num_active_queues;
400         int i, j;
401         int rqpv, tqpv;
402         int err = 0;
403
404         q_vectors = adapter->num_msix_vectors - NONQ_VECS;
405
406         /* The ideal configuration...
407          * We have enough vectors to map one per queue.
408          */
409         if (q_vectors >= (rxr_remaining * 2)) {
410                 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
411                         i40evf_map_vector_to_rxq(adapter, v_start, rxr_idx);
412
413                 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
414                         i40evf_map_vector_to_txq(adapter, v_start, txr_idx);
415                 goto out;
416         }
417
418         /* If we don't have enough vectors for a 1-to-1
419          * mapping, we'll have to group them so there are
420          * multiple queues per vector.
421          * Re-adjusting *qpv takes care of the remainder.
422          */
423         for (i = v_start; i < q_vectors; i++) {
424                 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
425                 for (j = 0; j < rqpv; j++) {
426                         i40evf_map_vector_to_rxq(adapter, i, rxr_idx);
427                         rxr_idx++;
428                         rxr_remaining--;
429                 }
430         }
431         for (i = v_start; i < q_vectors; i++) {
432                 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
433                 for (j = 0; j < tqpv; j++) {
434                         i40evf_map_vector_to_txq(adapter, i, txr_idx);
435                         txr_idx++;
436                         txr_remaining--;
437                 }
438         }
439
440 out:
441         adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
442
443         return err;
444 }
445
446 /**
447  * i40evf_request_traffic_irqs - Initialize MSI-X interrupts
448  * @adapter: board private structure
449  *
450  * Allocates MSI-X vectors for tx and rx handling, and requests
451  * interrupts from the kernel.
452  **/
453 static int
454 i40evf_request_traffic_irqs(struct i40evf_adapter *adapter, char *basename)
455 {
456         int vector, err, q_vectors;
457         int rx_int_idx = 0, tx_int_idx = 0;
458
459         i40evf_irq_disable(adapter);
460         /* Decrement for Other and TCP Timer vectors */
461         q_vectors = adapter->num_msix_vectors - NONQ_VECS;
462
463         for (vector = 0; vector < q_vectors; vector++) {
464                 struct i40e_q_vector *q_vector = adapter->q_vector[vector];
465
466                 if (q_vector->tx.ring && q_vector->rx.ring) {
467                         snprintf(q_vector->name, sizeof(q_vector->name) - 1,
468                                  "i40evf-%s-%s-%d", basename,
469                                  "TxRx", rx_int_idx++);
470                         tx_int_idx++;
471                 } else if (q_vector->rx.ring) {
472                         snprintf(q_vector->name, sizeof(q_vector->name) - 1,
473                                  "i40evf-%s-%s-%d", basename,
474                                  "rx", rx_int_idx++);
475                 } else if (q_vector->tx.ring) {
476                         snprintf(q_vector->name, sizeof(q_vector->name) - 1,
477                                  "i40evf-%s-%s-%d", basename,
478                                  "tx", tx_int_idx++);
479                 } else {
480                         /* skip this unused q_vector */
481                         continue;
482                 }
483                 err = request_irq(
484                         adapter->msix_entries[vector + NONQ_VECS].vector,
485                         i40evf_msix_clean_rings,
486                         0,
487                         q_vector->name,
488                         q_vector);
489                 if (err) {
490                         dev_info(&adapter->pdev->dev,
491                                  "%s: request_irq failed, error: %d\n",
492                                 __func__, err);
493                         goto free_queue_irqs;
494                 }
495                 /* assign the mask for this irq */
496                 irq_set_affinity_hint(
497                         adapter->msix_entries[vector + NONQ_VECS].vector,
498                         q_vector->affinity_mask);
499         }
500
501         return 0;
502
503 free_queue_irqs:
504         while (vector) {
505                 vector--;
506                 irq_set_affinity_hint(
507                         adapter->msix_entries[vector + NONQ_VECS].vector,
508                         NULL);
509                 free_irq(adapter->msix_entries[vector + NONQ_VECS].vector,
510                          adapter->q_vector[vector]);
511         }
512         return err;
513 }
514
515 /**
516  * i40evf_request_misc_irq - Initialize MSI-X interrupts
517  * @adapter: board private structure
518  *
519  * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
520  * vector is only for the admin queue, and stays active even when the netdev
521  * is closed.
522  **/
523 static int i40evf_request_misc_irq(struct i40evf_adapter *adapter)
524 {
525         struct net_device *netdev = adapter->netdev;
526         int err;
527
528         snprintf(adapter->misc_vector_name,
529                  sizeof(adapter->misc_vector_name) - 1, "i40evf-%s:mbx",
530                  dev_name(&adapter->pdev->dev));
531         err = request_irq(adapter->msix_entries[0].vector,
532                           &i40evf_msix_aq, 0,
533                           adapter->misc_vector_name, netdev);
534         if (err) {
535                 dev_err(&adapter->pdev->dev,
536                         "request_irq for %s failed: %d\n",
537                         adapter->misc_vector_name, err);
538                 free_irq(adapter->msix_entries[0].vector, netdev);
539         }
540         return err;
541 }
542
543 /**
544  * i40evf_free_traffic_irqs - Free MSI-X interrupts
545  * @adapter: board private structure
546  *
547  * Frees all MSI-X vectors other than 0.
548  **/
549 static void i40evf_free_traffic_irqs(struct i40evf_adapter *adapter)
550 {
551         int i;
552         int q_vectors;
553
554         q_vectors = adapter->num_msix_vectors - NONQ_VECS;
555
556         for (i = 0; i < q_vectors; i++) {
557                 irq_set_affinity_hint(adapter->msix_entries[i+1].vector,
558                                       NULL);
559                 free_irq(adapter->msix_entries[i+1].vector,
560                          adapter->q_vector[i]);
561         }
562 }
563
564 /**
565  * i40evf_free_misc_irq - Free MSI-X miscellaneous vector
566  * @adapter: board private structure
567  *
568  * Frees MSI-X vector 0.
569  **/
570 static void i40evf_free_misc_irq(struct i40evf_adapter *adapter)
571 {
572         struct net_device *netdev = adapter->netdev;
573
574         free_irq(adapter->msix_entries[0].vector, netdev);
575 }
576
577 /**
578  * i40evf_configure_tx - Configure Transmit Unit after Reset
579  * @adapter: board private structure
580  *
581  * Configure the Tx unit of the MAC after a reset.
582  **/
583 static void i40evf_configure_tx(struct i40evf_adapter *adapter)
584 {
585         struct i40e_hw *hw = &adapter->hw;
586         int i;
587
588         for (i = 0; i < adapter->num_active_queues; i++)
589                 adapter->tx_rings[i]->tail = hw->hw_addr + I40E_QTX_TAIL1(i);
590 }
591
592 /**
593  * i40evf_configure_rx - Configure Receive Unit after Reset
594  * @adapter: board private structure
595  *
596  * Configure the Rx unit of the MAC after a reset.
597  **/
598 static void i40evf_configure_rx(struct i40evf_adapter *adapter)
599 {
600         struct i40e_hw *hw = &adapter->hw;
601         struct net_device *netdev = adapter->netdev;
602         int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
603         int i;
604         int rx_buf_len;
605
606
607         adapter->flags &= ~I40EVF_FLAG_RX_PS_CAPABLE;
608         adapter->flags |= I40EVF_FLAG_RX_1BUF_CAPABLE;
609
610         /* Decide whether to use packet split mode or not */
611         if (netdev->mtu > ETH_DATA_LEN) {
612                 if (adapter->flags & I40EVF_FLAG_RX_PS_CAPABLE)
613                         adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
614                 else
615                         adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
616         } else {
617                 if (adapter->flags & I40EVF_FLAG_RX_1BUF_CAPABLE)
618                         adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
619                 else
620                         adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
621         }
622
623         /* Set the RX buffer length according to the mode */
624         if (adapter->flags & I40EVF_FLAG_RX_PS_ENABLED) {
625                 rx_buf_len = I40E_RX_HDR_SIZE;
626         } else {
627                 if (netdev->mtu <= ETH_DATA_LEN)
628                         rx_buf_len = I40EVF_RXBUFFER_2048;
629                 else
630                         rx_buf_len = ALIGN(max_frame, 1024);
631         }
632
633         for (i = 0; i < adapter->num_active_queues; i++) {
634                 adapter->rx_rings[i]->tail = hw->hw_addr + I40E_QRX_TAIL1(i);
635                 adapter->rx_rings[i]->rx_buf_len = rx_buf_len;
636         }
637 }
638
639 /**
640  * i40evf_find_vlan - Search filter list for specific vlan filter
641  * @adapter: board private structure
642  * @vlan: vlan tag
643  *
644  * Returns ptr to the filter object or NULL
645  **/
646 static struct
647 i40evf_vlan_filter *i40evf_find_vlan(struct i40evf_adapter *adapter, u16 vlan)
648 {
649         struct i40evf_vlan_filter *f;
650
651         list_for_each_entry(f, &adapter->vlan_filter_list, list) {
652                 if (vlan == f->vlan)
653                         return f;
654         }
655         return NULL;
656 }
657
658 /**
659  * i40evf_add_vlan - Add a vlan filter to the list
660  * @adapter: board private structure
661  * @vlan: VLAN tag
662  *
663  * Returns ptr to the filter object or NULL when no memory available.
664  **/
665 static struct
666 i40evf_vlan_filter *i40evf_add_vlan(struct i40evf_adapter *adapter, u16 vlan)
667 {
668         struct i40evf_vlan_filter *f = NULL;
669         int count = 50;
670
671         while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
672                                 &adapter->crit_section)) {
673                 udelay(1);
674                 if (--count == 0)
675                         goto out;
676         }
677
678         f = i40evf_find_vlan(adapter, vlan);
679         if (!f) {
680                 f = kzalloc(sizeof(*f), GFP_ATOMIC);
681                 if (!f)
682                         goto clearout;
683
684                 f->vlan = vlan;
685
686                 INIT_LIST_HEAD(&f->list);
687                 list_add(&f->list, &adapter->vlan_filter_list);
688                 f->add = true;
689                 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
690         }
691
692 clearout:
693         clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
694 out:
695         return f;
696 }
697
698 /**
699  * i40evf_del_vlan - Remove a vlan filter from the list
700  * @adapter: board private structure
701  * @vlan: VLAN tag
702  **/
703 static void i40evf_del_vlan(struct i40evf_adapter *adapter, u16 vlan)
704 {
705         struct i40evf_vlan_filter *f;
706         int count = 50;
707
708         while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
709                                 &adapter->crit_section)) {
710                 udelay(1);
711                 if (--count == 0)
712                         return;
713         }
714
715         f = i40evf_find_vlan(adapter, vlan);
716         if (f) {
717                 f->remove = true;
718                 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
719         }
720         clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
721 }
722
723 /**
724  * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device
725  * @netdev: network device struct
726  * @vid: VLAN tag
727  **/
728 static int i40evf_vlan_rx_add_vid(struct net_device *netdev,
729                                   __always_unused __be16 proto, u16 vid)
730 {
731         struct i40evf_adapter *adapter = netdev_priv(netdev);
732
733         if (i40evf_add_vlan(adapter, vid) == NULL)
734                 return -ENOMEM;
735         return 0;
736 }
737
738 /**
739  * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device
740  * @netdev: network device struct
741  * @vid: VLAN tag
742  **/
743 static int i40evf_vlan_rx_kill_vid(struct net_device *netdev,
744                                    __always_unused __be16 proto, u16 vid)
745 {
746         struct i40evf_adapter *adapter = netdev_priv(netdev);
747
748         i40evf_del_vlan(adapter, vid);
749         return 0;
750 }
751
752 /**
753  * i40evf_find_filter - Search filter list for specific mac filter
754  * @adapter: board private structure
755  * @macaddr: the MAC address
756  *
757  * Returns ptr to the filter object or NULL
758  **/
759 static struct
760 i40evf_mac_filter *i40evf_find_filter(struct i40evf_adapter *adapter,
761                                       u8 *macaddr)
762 {
763         struct i40evf_mac_filter *f;
764
765         if (!macaddr)
766                 return NULL;
767
768         list_for_each_entry(f, &adapter->mac_filter_list, list) {
769                 if (ether_addr_equal(macaddr, f->macaddr))
770                         return f;
771         }
772         return NULL;
773 }
774
775 /**
776  * i40e_add_filter - Add a mac filter to the filter list
777  * @adapter: board private structure
778  * @macaddr: the MAC address
779  *
780  * Returns ptr to the filter object or NULL when no memory available.
781  **/
782 static struct
783 i40evf_mac_filter *i40evf_add_filter(struct i40evf_adapter *adapter,
784                                      u8 *macaddr)
785 {
786         struct i40evf_mac_filter *f;
787         int count = 50;
788
789         if (!macaddr)
790                 return NULL;
791
792         while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
793                                 &adapter->crit_section)) {
794                 udelay(1);
795                 if (--count == 0)
796                         return NULL;
797         }
798
799         f = i40evf_find_filter(adapter, macaddr);
800         if (!f) {
801                 f = kzalloc(sizeof(*f), GFP_ATOMIC);
802                 if (!f) {
803                         clear_bit(__I40EVF_IN_CRITICAL_TASK,
804                                   &adapter->crit_section);
805                         return NULL;
806                 }
807
808                 ether_addr_copy(f->macaddr, macaddr);
809
810                 list_add(&f->list, &adapter->mac_filter_list);
811                 f->add = true;
812                 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
813         }
814
815         clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
816         return f;
817 }
818
819 /**
820  * i40evf_set_mac - NDO callback to set port mac address
821  * @netdev: network interface device structure
822  * @p: pointer to an address structure
823  *
824  * Returns 0 on success, negative on failure
825  **/
826 static int i40evf_set_mac(struct net_device *netdev, void *p)
827 {
828         struct i40evf_adapter *adapter = netdev_priv(netdev);
829         struct i40e_hw *hw = &adapter->hw;
830         struct i40evf_mac_filter *f;
831         struct sockaddr *addr = p;
832
833         if (!is_valid_ether_addr(addr->sa_data))
834                 return -EADDRNOTAVAIL;
835
836         if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
837                 return 0;
838
839         f = i40evf_add_filter(adapter, addr->sa_data);
840         if (f) {
841                 ether_addr_copy(hw->mac.addr, addr->sa_data);
842                 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
843         }
844
845         return (f == NULL) ? -ENOMEM : 0;
846 }
847
848 /**
849  * i40evf_set_rx_mode - NDO callback to set the netdev filters
850  * @netdev: network interface device structure
851  **/
852 static void i40evf_set_rx_mode(struct net_device *netdev)
853 {
854         struct i40evf_adapter *adapter = netdev_priv(netdev);
855         struct i40evf_mac_filter *f, *ftmp;
856         struct netdev_hw_addr *uca;
857         struct netdev_hw_addr *mca;
858         int count = 50;
859
860         /* add addr if not already in the filter list */
861         netdev_for_each_uc_addr(uca, netdev) {
862                 i40evf_add_filter(adapter, uca->addr);
863         }
864         netdev_for_each_mc_addr(mca, netdev) {
865                 i40evf_add_filter(adapter, mca->addr);
866         }
867
868         while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
869                                 &adapter->crit_section)) {
870                 udelay(1);
871                 if (--count == 0) {
872                         dev_err(&adapter->pdev->dev,
873                                 "Failed to get lock in %s\n", __func__);
874                         return;
875                 }
876         }
877         /* remove filter if not in netdev list */
878         list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
879                 bool found = false;
880
881                 if (is_multicast_ether_addr(f->macaddr)) {
882                         netdev_for_each_mc_addr(mca, netdev) {
883                                 if (ether_addr_equal(mca->addr, f->macaddr)) {
884                                         found = true;
885                                         break;
886                                 }
887                         }
888                 } else {
889                         netdev_for_each_uc_addr(uca, netdev) {
890                                 if (ether_addr_equal(uca->addr, f->macaddr)) {
891                                         found = true;
892                                         break;
893                                 }
894                         }
895                         if (ether_addr_equal(f->macaddr, adapter->hw.mac.addr))
896                                 found = true;
897                 }
898                 if (!found) {
899                         f->remove = true;
900                         adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
901                 }
902         }
903         clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
904 }
905
906 /**
907  * i40evf_napi_enable_all - enable NAPI on all queue vectors
908  * @adapter: board private structure
909  **/
910 static void i40evf_napi_enable_all(struct i40evf_adapter *adapter)
911 {
912         int q_idx;
913         struct i40e_q_vector *q_vector;
914         int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
915
916         for (q_idx = 0; q_idx < q_vectors; q_idx++) {
917                 struct napi_struct *napi;
918
919                 q_vector = adapter->q_vector[q_idx];
920                 napi = &q_vector->napi;
921                 napi_enable(napi);
922         }
923 }
924
925 /**
926  * i40evf_napi_disable_all - disable NAPI on all queue vectors
927  * @adapter: board private structure
928  **/
929 static void i40evf_napi_disable_all(struct i40evf_adapter *adapter)
930 {
931         int q_idx;
932         struct i40e_q_vector *q_vector;
933         int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
934
935         for (q_idx = 0; q_idx < q_vectors; q_idx++) {
936                 q_vector = adapter->q_vector[q_idx];
937                 napi_disable(&q_vector->napi);
938         }
939 }
940
941 /**
942  * i40evf_configure - set up transmit and receive data structures
943  * @adapter: board private structure
944  **/
945 static void i40evf_configure(struct i40evf_adapter *adapter)
946 {
947         struct net_device *netdev = adapter->netdev;
948         int i;
949
950         i40evf_set_rx_mode(netdev);
951
952         i40evf_configure_tx(adapter);
953         i40evf_configure_rx(adapter);
954         adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
955
956         for (i = 0; i < adapter->num_active_queues; i++) {
957                 struct i40e_ring *ring = adapter->rx_rings[i];
958
959                 i40evf_alloc_rx_buffers_1buf(ring, ring->count);
960                 ring->next_to_use = ring->count - 1;
961                 writel(ring->next_to_use, ring->tail);
962         }
963 }
964
965 /**
966  * i40evf_up_complete - Finish the last steps of bringing up a connection
967  * @adapter: board private structure
968  **/
969 static int i40evf_up_complete(struct i40evf_adapter *adapter)
970 {
971         adapter->state = __I40EVF_RUNNING;
972         clear_bit(__I40E_DOWN, &adapter->vsi.state);
973
974         i40evf_napi_enable_all(adapter);
975
976         adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
977         mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
978         return 0;
979 }
980
981 /**
982  * i40e_down - Shutdown the connection processing
983  * @adapter: board private structure
984  **/
985 void i40evf_down(struct i40evf_adapter *adapter)
986 {
987         struct net_device *netdev = adapter->netdev;
988         struct i40evf_mac_filter *f;
989
990         if (adapter->state == __I40EVF_DOWN)
991                 return;
992
993         while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
994                                 &adapter->crit_section))
995                 usleep_range(500, 1000);
996
997         netif_carrier_off(netdev);
998         netif_tx_disable(netdev);
999         i40evf_napi_disable_all(adapter);
1000         i40evf_irq_disable(adapter);
1001
1002         /* remove all MAC filters */
1003         list_for_each_entry(f, &adapter->mac_filter_list, list) {
1004                 f->remove = true;
1005         }
1006         /* remove all VLAN filters */
1007         list_for_each_entry(f, &adapter->vlan_filter_list, list) {
1008                 f->remove = true;
1009         }
1010         if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) &&
1011             adapter->state != __I40EVF_RESETTING) {
1012                 /* cancel any current operation */
1013                 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1014                 /* Schedule operations to close down the HW. Don't wait
1015                  * here for this to complete. The watchdog is still running
1016                  * and it will take care of this.
1017                  */
1018                 adapter->aq_required = I40EVF_FLAG_AQ_DEL_MAC_FILTER;
1019                 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
1020                 adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
1021         }
1022
1023         clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1024 }
1025
1026 /**
1027  * i40evf_acquire_msix_vectors - Setup the MSIX capability
1028  * @adapter: board private structure
1029  * @vectors: number of vectors to request
1030  *
1031  * Work with the OS to set up the MSIX vectors needed.
1032  *
1033  * Returns 0 on success, negative on failure
1034  **/
1035 static int
1036 i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors)
1037 {
1038         int err, vector_threshold;
1039
1040         /* We'll want at least 3 (vector_threshold):
1041          * 0) Other (Admin Queue and link, mostly)
1042          * 1) TxQ[0] Cleanup
1043          * 2) RxQ[0] Cleanup
1044          */
1045         vector_threshold = MIN_MSIX_COUNT;
1046
1047         /* The more we get, the more we will assign to Tx/Rx Cleanup
1048          * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1049          * Right now, we simply care about how many we'll get; we'll
1050          * set them up later while requesting irq's.
1051          */
1052         err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
1053                                     vector_threshold, vectors);
1054         if (err < 0) {
1055                 dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n");
1056                 kfree(adapter->msix_entries);
1057                 adapter->msix_entries = NULL;
1058                 return err;
1059         }
1060
1061         /* Adjust for only the vectors we'll use, which is minimum
1062          * of max_msix_q_vectors + NONQ_VECS, or the number of
1063          * vectors we were allocated.
1064          */
1065         adapter->num_msix_vectors = err;
1066         return 0;
1067 }
1068
1069 /**
1070  * i40evf_free_queues - Free memory for all rings
1071  * @adapter: board private structure to initialize
1072  *
1073  * Free all of the memory associated with queue pairs.
1074  **/
1075 static void i40evf_free_queues(struct i40evf_adapter *adapter)
1076 {
1077         int i;
1078
1079         if (!adapter->vsi_res)
1080                 return;
1081         for (i = 0; i < adapter->num_active_queues; i++) {
1082                 if (adapter->tx_rings[i])
1083                         kfree_rcu(adapter->tx_rings[i], rcu);
1084                 adapter->tx_rings[i] = NULL;
1085                 adapter->rx_rings[i] = NULL;
1086         }
1087 }
1088
1089 /**
1090  * i40evf_alloc_queues - Allocate memory for all rings
1091  * @adapter: board private structure to initialize
1092  *
1093  * We allocate one ring per queue at run-time since we don't know the
1094  * number of queues at compile-time.  The polling_netdev array is
1095  * intended for Multiqueue, but should work fine with a single queue.
1096  **/
1097 static int i40evf_alloc_queues(struct i40evf_adapter *adapter)
1098 {
1099         int i;
1100
1101         for (i = 0; i < adapter->num_active_queues; i++) {
1102                 struct i40e_ring *tx_ring;
1103                 struct i40e_ring *rx_ring;
1104
1105                 tx_ring = kzalloc(sizeof(*tx_ring) * 2, GFP_KERNEL);
1106                 if (!tx_ring)
1107                         goto err_out;
1108
1109                 tx_ring->queue_index = i;
1110                 tx_ring->netdev = adapter->netdev;
1111                 tx_ring->dev = &adapter->pdev->dev;
1112                 tx_ring->count = adapter->tx_desc_count;
1113                 adapter->tx_rings[i] = tx_ring;
1114
1115                 rx_ring = &tx_ring[1];
1116                 rx_ring->queue_index = i;
1117                 rx_ring->netdev = adapter->netdev;
1118                 rx_ring->dev = &adapter->pdev->dev;
1119                 rx_ring->count = adapter->rx_desc_count;
1120                 adapter->rx_rings[i] = rx_ring;
1121         }
1122
1123         return 0;
1124
1125 err_out:
1126         i40evf_free_queues(adapter);
1127         return -ENOMEM;
1128 }
1129
1130 /**
1131  * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
1132  * @adapter: board private structure to initialize
1133  *
1134  * Attempt to configure the interrupts using the best available
1135  * capabilities of the hardware and the kernel.
1136  **/
1137 static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter)
1138 {
1139         int vector, v_budget;
1140         int pairs = 0;
1141         int err = 0;
1142
1143         if (!adapter->vsi_res) {
1144                 err = -EIO;
1145                 goto out;
1146         }
1147         pairs = adapter->num_active_queues;
1148
1149         /* It's easy to be greedy for MSI-X vectors, but it really
1150          * doesn't do us much good if we have a lot more vectors
1151          * than CPU's.  So let's be conservative and only ask for
1152          * (roughly) twice the number of vectors as there are CPU's.
1153          */
1154         v_budget = min_t(int, pairs, (int)(num_online_cpus() * 2)) + NONQ_VECS;
1155         v_budget = min_t(int, v_budget, (int)adapter->vf_res->max_vectors);
1156
1157         adapter->msix_entries = kcalloc(v_budget,
1158                                         sizeof(struct msix_entry), GFP_KERNEL);
1159         if (!adapter->msix_entries) {
1160                 err = -ENOMEM;
1161                 goto out;
1162         }
1163
1164         for (vector = 0; vector < v_budget; vector++)
1165                 adapter->msix_entries[vector].entry = vector;
1166
1167         i40evf_acquire_msix_vectors(adapter, v_budget);
1168
1169 out:
1170         adapter->netdev->real_num_tx_queues = pairs;
1171         return err;
1172 }
1173
1174 /**
1175  * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
1176  * @adapter: board private structure to initialize
1177  *
1178  * We allocate one q_vector per queue interrupt.  If allocation fails we
1179  * return -ENOMEM.
1180  **/
1181 static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter)
1182 {
1183         int q_idx, num_q_vectors;
1184         struct i40e_q_vector *q_vector;
1185
1186         num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
1187
1188         for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
1189                 q_vector = kzalloc(sizeof(*q_vector), GFP_KERNEL);
1190                 if (!q_vector)
1191                         goto err_out;
1192                 q_vector->adapter = adapter;
1193                 q_vector->vsi = &adapter->vsi;
1194                 q_vector->v_idx = q_idx;
1195                 netif_napi_add(adapter->netdev, &q_vector->napi,
1196                                i40evf_napi_poll, NAPI_POLL_WEIGHT);
1197                 adapter->q_vector[q_idx] = q_vector;
1198         }
1199
1200         return 0;
1201
1202 err_out:
1203         while (q_idx) {
1204                 q_idx--;
1205                 q_vector = adapter->q_vector[q_idx];
1206                 netif_napi_del(&q_vector->napi);
1207                 kfree(q_vector);
1208                 adapter->q_vector[q_idx] = NULL;
1209         }
1210         return -ENOMEM;
1211 }
1212
1213 /**
1214  * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
1215  * @adapter: board private structure to initialize
1216  *
1217  * This function frees the memory allocated to the q_vectors.  In addition if
1218  * NAPI is enabled it will delete any references to the NAPI struct prior
1219  * to freeing the q_vector.
1220  **/
1221 static void i40evf_free_q_vectors(struct i40evf_adapter *adapter)
1222 {
1223         int q_idx, num_q_vectors;
1224         int napi_vectors;
1225
1226         num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
1227         napi_vectors = adapter->num_active_queues;
1228
1229         for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
1230                 struct i40e_q_vector *q_vector = adapter->q_vector[q_idx];
1231
1232                 adapter->q_vector[q_idx] = NULL;
1233                 if (q_idx < napi_vectors)
1234                         netif_napi_del(&q_vector->napi);
1235                 kfree(q_vector);
1236         }
1237 }
1238
1239 /**
1240  * i40evf_reset_interrupt_capability - Reset MSIX setup
1241  * @adapter: board private structure
1242  *
1243  **/
1244 void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter)
1245 {
1246         pci_disable_msix(adapter->pdev);
1247         kfree(adapter->msix_entries);
1248         adapter->msix_entries = NULL;
1249 }
1250
1251 /**
1252  * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
1253  * @adapter: board private structure to initialize
1254  *
1255  **/
1256 int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter)
1257 {
1258         int err;
1259
1260         err = i40evf_set_interrupt_capability(adapter);
1261         if (err) {
1262                 dev_err(&adapter->pdev->dev,
1263                         "Unable to setup interrupt capabilities\n");
1264                 goto err_set_interrupt;
1265         }
1266
1267         err = i40evf_alloc_q_vectors(adapter);
1268         if (err) {
1269                 dev_err(&adapter->pdev->dev,
1270                         "Unable to allocate memory for queue vectors\n");
1271                 goto err_alloc_q_vectors;
1272         }
1273
1274         err = i40evf_alloc_queues(adapter);
1275         if (err) {
1276                 dev_err(&adapter->pdev->dev,
1277                         "Unable to allocate memory for queues\n");
1278                 goto err_alloc_queues;
1279         }
1280
1281         dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u",
1282                  (adapter->num_active_queues > 1) ? "Enabled" : "Disabled",
1283                  adapter->num_active_queues);
1284
1285         return 0;
1286 err_alloc_queues:
1287         i40evf_free_q_vectors(adapter);
1288 err_alloc_q_vectors:
1289         i40evf_reset_interrupt_capability(adapter);
1290 err_set_interrupt:
1291         return err;
1292 }
1293
1294 /**
1295  * i40evf_watchdog_timer - Periodic call-back timer
1296  * @data: pointer to adapter disguised as unsigned long
1297  **/
1298 static void i40evf_watchdog_timer(unsigned long data)
1299 {
1300         struct i40evf_adapter *adapter = (struct i40evf_adapter *)data;
1301
1302         schedule_work(&adapter->watchdog_task);
1303         /* timer will be rescheduled in watchdog task */
1304 }
1305
1306 /**
1307  * i40evf_watchdog_task - Periodic call-back task
1308  * @work: pointer to work_struct
1309  **/
1310 static void i40evf_watchdog_task(struct work_struct *work)
1311 {
1312         struct i40evf_adapter *adapter = container_of(work,
1313                                                       struct i40evf_adapter,
1314                                                       watchdog_task);
1315         struct i40e_hw *hw = &adapter->hw;
1316         uint32_t rstat_val;
1317
1318         if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section))
1319                 goto restart_watchdog;
1320
1321         if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
1322                 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1323                             I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1324                 if ((rstat_val == I40E_VFR_VFACTIVE) ||
1325                     (rstat_val == I40E_VFR_COMPLETED)) {
1326                         /* A chance for redemption! */
1327                         dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n");
1328                         adapter->state = __I40EVF_STARTUP;
1329                         adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
1330                         schedule_delayed_work(&adapter->init_task, 10);
1331                         clear_bit(__I40EVF_IN_CRITICAL_TASK,
1332                                   &adapter->crit_section);
1333                         /* Don't reschedule the watchdog, since we've restarted
1334                          * the init task. When init_task contacts the PF and
1335                          * gets everything set up again, it'll restart the
1336                          * watchdog for us. Down, boy. Sit. Stay. Woof.
1337                          */
1338                         return;
1339                 }
1340                 adapter->aq_required = 0;
1341                 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1342                 goto watchdog_done;
1343         }
1344
1345         if ((adapter->state < __I40EVF_DOWN) ||
1346             (adapter->flags & I40EVF_FLAG_RESET_PENDING))
1347                 goto watchdog_done;
1348
1349         /* check for reset */
1350         rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1351                     I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1352         if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) &&
1353             (rstat_val != I40E_VFR_VFACTIVE) &&
1354             (rstat_val != I40E_VFR_COMPLETED)) {
1355                 adapter->state = __I40EVF_RESETTING;
1356                 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
1357                 dev_err(&adapter->pdev->dev, "Hardware reset detected\n");
1358                 schedule_work(&adapter->reset_task);
1359                 adapter->aq_required = 0;
1360                 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1361                 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          */
1367         if (adapter->current_op) {
1368                 if (!i40evf_asq_done(hw)) {
1369                         dev_dbg(&adapter->pdev->dev, "Admin queue timeout\n");
1370                         i40evf_send_api_ver(adapter);
1371                 }
1372                 goto watchdog_done;
1373         }
1374
1375         if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) {
1376                 i40evf_disable_queues(adapter);
1377                 goto watchdog_done;
1378         }
1379
1380         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
1405         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);
1417 watchdog_done:
1418         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
1425         clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1426 restart_watchdog:
1427         if (adapter->state == __I40EVF_REMOVE)
1428                 return;
1429         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));
1434         schedule_work(&adapter->adminq_task);
1435 }
1436
1437 /**
1438  * i40evf_configure_rss - Prepare for RSS
1439  * @adapter: board private structure
1440  **/
1441 static void i40evf_configure_rss(struct i40evf_adapter *adapter)
1442 {
1443         u32 rss_key[I40E_VFQF_HKEY_MAX_INDEX + 1];
1444         struct i40e_hw *hw = &adapter->hw;
1445         u32 cqueue = 0;
1446         u32 lut = 0;
1447         int i, j;
1448         u64 hena;
1449
1450         /* Hash type is configured by the PF - we just supply the key */
1451         netdev_rss_key_fill(rss_key, sizeof(rss_key));
1452
1453         /* Fill out hash function seed */
1454         for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
1455                 wr32(hw, I40E_VFQF_HKEY(i), rss_key[i]);
1456
1457         /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
1458         hena = I40E_DEFAULT_RSS_HENA;
1459         wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
1460         wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
1461
1462         /* Populate the LUT with max no. of queues in round robin fashion */
1463         for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) {
1464                 lut = 0;
1465                 for (j = 0; j < 4; j++) {
1466                         if (cqueue == adapter->num_active_queues)
1467                                 cqueue = 0;
1468                         lut |= ((cqueue) << (8 * j));
1469                         cqueue++;
1470                 }
1471                 wr32(hw, I40E_VFQF_HLUT(i), lut);
1472         }
1473         i40e_flush(hw);
1474 }
1475
1476 #define I40EVF_RESET_WAIT_MS 10
1477 #define I40EVF_RESET_WAIT_COUNT 500
1478 /**
1479  * i40evf_reset_task - Call-back task to handle hardware reset
1480  * @work: pointer to work_struct
1481  *
1482  * During reset we need to shut down and reinitialize the admin queue
1483  * before we can use it to communicate with the PF again. We also clear
1484  * and reinit the rings because that context is lost as well.
1485  **/
1486 static void i40evf_reset_task(struct work_struct *work)
1487 {
1488         struct i40evf_adapter *adapter = container_of(work,
1489                                                       struct i40evf_adapter,
1490                                                       reset_task);
1491         struct net_device *netdev = adapter->netdev;
1492         struct i40e_hw *hw = &adapter->hw;
1493         struct i40evf_mac_filter *f;
1494         uint32_t rstat_val;
1495         int i = 0, err;
1496
1497         while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
1498                                 &adapter->crit_section))
1499                 usleep_range(500, 1000);
1500
1501         i40evf_misc_irq_disable(adapter);
1502         if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) {
1503                 adapter->flags &= ~I40EVF_FLAG_RESET_NEEDED;
1504                 /* Restart the AQ here. If we have been reset but didn't
1505                  * detect it, or if the PF had to reinit, our AQ will be hosed.
1506                  */
1507                 i40evf_shutdown_adminq(hw);
1508                 i40evf_init_adminq(hw);
1509                 i40evf_request_reset(adapter);
1510         }
1511         adapter->flags |= I40EVF_FLAG_RESET_PENDING;
1512
1513         /* poll until we see the reset actually happen */
1514         for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
1515                 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1516                             I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1517                 if ((rstat_val != I40E_VFR_VFACTIVE) &&
1518                     (rstat_val != I40E_VFR_COMPLETED))
1519                         break;
1520                 usleep_range(500, 1000);
1521         }
1522         if (i == I40EVF_RESET_WAIT_COUNT) {
1523                 dev_info(&adapter->pdev->dev, "Never saw reset\n");
1524                 goto continue_reset; /* act like the reset happened */
1525         }
1526
1527         /* wait until the reset is complete and the PF is responding to us */
1528         for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
1529                 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1530                             I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1531                 if (rstat_val == I40E_VFR_VFACTIVE)
1532                         break;
1533                 msleep(I40EVF_RESET_WAIT_MS);
1534         }
1535         /* extra wait to make sure minimum wait is met */
1536         msleep(I40EVF_RESET_WAIT_MS);
1537         if (i == I40EVF_RESET_WAIT_COUNT) {
1538                 struct i40evf_mac_filter *f, *ftmp;
1539                 struct i40evf_vlan_filter *fv, *fvtmp;
1540
1541                 /* reset never finished */
1542                 dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n",
1543                         rstat_val);
1544                 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
1545
1546                 if (netif_running(adapter->netdev)) {
1547                         set_bit(__I40E_DOWN, &adapter->vsi.state);
1548                         netif_carrier_off(netdev);
1549                         netif_tx_disable(netdev);
1550                         i40evf_napi_disable_all(adapter);
1551                         i40evf_irq_disable(adapter);
1552                         i40evf_free_traffic_irqs(adapter);
1553                         i40evf_free_all_tx_resources(adapter);
1554                         i40evf_free_all_rx_resources(adapter);
1555                 }
1556
1557                 /* Delete all of the filters, both MAC and VLAN. */
1558                 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list,
1559                                          list) {
1560                         list_del(&f->list);
1561                         kfree(f);
1562                 }
1563
1564                 list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list,
1565                                          list) {
1566                         list_del(&fv->list);
1567                         kfree(fv);
1568                 }
1569
1570                 i40evf_free_misc_irq(adapter);
1571                 i40evf_reset_interrupt_capability(adapter);
1572                 i40evf_free_queues(adapter);
1573                 i40evf_free_q_vectors(adapter);
1574                 kfree(adapter->vf_res);
1575                 i40evf_shutdown_adminq(hw);
1576                 adapter->netdev->flags &= ~IFF_UP;
1577                 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1578                 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1579                 dev_info(&adapter->pdev->dev, "Reset task did not complete, VF disabled\n");
1580                 return; /* Do not attempt to reinit. It's dead, Jim. */
1581         }
1582
1583 continue_reset:
1584         if (netif_running(adapter->netdev)) {
1585                 netif_carrier_off(netdev);
1586                 netif_tx_stop_all_queues(netdev);
1587                 i40evf_napi_disable_all(adapter);
1588         }
1589         i40evf_irq_disable(adapter);
1590
1591         adapter->state = __I40EVF_RESETTING;
1592         adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1593
1594         /* free the Tx/Rx rings and descriptors, might be better to just
1595          * re-use them sometime in the future
1596          */
1597         i40evf_free_all_rx_resources(adapter);
1598         i40evf_free_all_tx_resources(adapter);
1599
1600         /* kill and reinit the admin queue */
1601         if (i40evf_shutdown_adminq(hw))
1602                 dev_warn(&adapter->pdev->dev, "Failed to shut down adminq\n");
1603         adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1604         err = i40evf_init_adminq(hw);
1605         if (err)
1606                 dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n",
1607                          err);
1608
1609         i40evf_map_queues(adapter);
1610
1611         /* re-add all MAC filters */
1612         list_for_each_entry(f, &adapter->mac_filter_list, list) {
1613                 f->add = true;
1614         }
1615         /* re-add all VLAN filters */
1616         list_for_each_entry(f, &adapter->vlan_filter_list, list) {
1617                 f->add = true;
1618         }
1619         adapter->aq_required = I40EVF_FLAG_AQ_ADD_MAC_FILTER;
1620         adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
1621         clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1622         i40evf_misc_irq_enable(adapter);
1623
1624         mod_timer(&adapter->watchdog_timer, jiffies + 2);
1625
1626         if (netif_running(adapter->netdev)) {
1627                 /* allocate transmit descriptors */
1628                 err = i40evf_setup_all_tx_resources(adapter);
1629                 if (err)
1630                         goto reset_err;
1631
1632                 /* allocate receive descriptors */
1633                 err = i40evf_setup_all_rx_resources(adapter);
1634                 if (err)
1635                         goto reset_err;
1636
1637                 i40evf_configure(adapter);
1638
1639                 err = i40evf_up_complete(adapter);
1640                 if (err)
1641                         goto reset_err;
1642
1643                 i40evf_irq_enable(adapter, true);
1644         } else {
1645                 adapter->state = __I40EVF_DOWN;
1646         }
1647
1648         return;
1649 reset_err:
1650         dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
1651         i40evf_close(adapter->netdev);
1652 }
1653
1654 /**
1655  * i40evf_adminq_task - worker thread to clean the admin queue
1656  * @work: pointer to work_struct containing our data
1657  **/
1658 static void i40evf_adminq_task(struct work_struct *work)
1659 {
1660         struct i40evf_adapter *adapter =
1661                 container_of(work, struct i40evf_adapter, adminq_task);
1662         struct i40e_hw *hw = &adapter->hw;
1663         struct i40e_arq_event_info event;
1664         struct i40e_virtchnl_msg *v_msg;
1665         i40e_status ret;
1666         u32 val, oldval;
1667         u16 pending;
1668
1669         if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
1670                 goto out;
1671
1672         event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
1673         event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
1674         if (!event.msg_buf)
1675                 goto out;
1676
1677         v_msg = (struct i40e_virtchnl_msg *)&event.desc;
1678         do {
1679                 ret = i40evf_clean_arq_element(hw, &event, &pending);
1680                 if (ret || !v_msg->v_opcode)
1681                         break; /* No event to process or error cleaning ARQ */
1682
1683                 i40evf_virtchnl_completion(adapter, v_msg->v_opcode,
1684                                            v_msg->v_retval, event.msg_buf,
1685                                            event.msg_len);
1686                 if (pending != 0)
1687                         memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE);
1688         } while (pending);
1689
1690         if ((adapter->flags &
1691              (I40EVF_FLAG_RESET_PENDING | I40EVF_FLAG_RESET_NEEDED)) ||
1692             adapter->state == __I40EVF_RESETTING)
1693                 goto freedom;
1694
1695         /* check for error indications */
1696         val = rd32(hw, hw->aq.arq.len);
1697         oldval = val;
1698         if (val & I40E_VF_ARQLEN_ARQVFE_MASK) {
1699                 dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n");
1700                 val &= ~I40E_VF_ARQLEN_ARQVFE_MASK;
1701         }
1702         if (val & I40E_VF_ARQLEN_ARQOVFL_MASK) {
1703                 dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n");
1704                 val &= ~I40E_VF_ARQLEN_ARQOVFL_MASK;
1705         }
1706         if (val & I40E_VF_ARQLEN_ARQCRIT_MASK) {
1707                 dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n");
1708                 val &= ~I40E_VF_ARQLEN_ARQCRIT_MASK;
1709         }
1710         if (oldval != val)
1711                 wr32(hw, hw->aq.arq.len, val);
1712
1713         val = rd32(hw, hw->aq.asq.len);
1714         oldval = val;
1715         if (val & I40E_VF_ATQLEN_ATQVFE_MASK) {
1716                 dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n");
1717                 val &= ~I40E_VF_ATQLEN_ATQVFE_MASK;
1718         }
1719         if (val & I40E_VF_ATQLEN_ATQOVFL_MASK) {
1720                 dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n");
1721                 val &= ~I40E_VF_ATQLEN_ATQOVFL_MASK;
1722         }
1723         if (val & I40E_VF_ATQLEN_ATQCRIT_MASK) {
1724                 dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n");
1725                 val &= ~I40E_VF_ATQLEN_ATQCRIT_MASK;
1726         }
1727         if (oldval != val)
1728                 wr32(hw, hw->aq.asq.len, val);
1729
1730 freedom:
1731         kfree(event.msg_buf);
1732 out:
1733         /* re-enable Admin queue interrupt cause */
1734         i40evf_misc_irq_enable(adapter);
1735 }
1736
1737 /**
1738  * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
1739  * @adapter: board private structure
1740  *
1741  * Free all transmit software resources
1742  **/
1743 void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter)
1744 {
1745         int i;
1746
1747         for (i = 0; i < adapter->num_active_queues; i++)
1748                 if (adapter->tx_rings[i]->desc)
1749                         i40evf_free_tx_resources(adapter->tx_rings[i]);
1750 }
1751
1752 /**
1753  * i40evf_setup_all_tx_resources - allocate all queues Tx resources
1754  * @adapter: board private structure
1755  *
1756  * If this function returns with an error, then it's possible one or
1757  * more of the rings is populated (while the rest are not).  It is the
1758  * callers duty to clean those orphaned rings.
1759  *
1760  * Return 0 on success, negative on failure
1761  **/
1762 static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter)
1763 {
1764         int i, err = 0;
1765
1766         for (i = 0; i < adapter->num_active_queues; i++) {
1767                 adapter->tx_rings[i]->count = adapter->tx_desc_count;
1768                 err = i40evf_setup_tx_descriptors(adapter->tx_rings[i]);
1769                 if (!err)
1770                         continue;
1771                 dev_err(&adapter->pdev->dev,
1772                         "%s: Allocation for Tx Queue %u failed\n",
1773                         __func__, i);
1774                 break;
1775         }
1776
1777         return err;
1778 }
1779
1780 /**
1781  * i40evf_setup_all_rx_resources - allocate all queues Rx resources
1782  * @adapter: board private structure
1783  *
1784  * If this function returns with an error, then it's possible one or
1785  * more of the rings is populated (while the rest are not).  It is the
1786  * callers duty to clean those orphaned rings.
1787  *
1788  * Return 0 on success, negative on failure
1789  **/
1790 static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter)
1791 {
1792         int i, err = 0;
1793
1794         for (i = 0; i < adapter->num_active_queues; i++) {
1795                 adapter->rx_rings[i]->count = adapter->rx_desc_count;
1796                 err = i40evf_setup_rx_descriptors(adapter->rx_rings[i]);
1797                 if (!err)
1798                         continue;
1799                 dev_err(&adapter->pdev->dev,
1800                         "%s: Allocation for Rx Queue %u failed\n",
1801                         __func__, i);
1802                 break;
1803         }
1804         return err;
1805 }
1806
1807 /**
1808  * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
1809  * @adapter: board private structure
1810  *
1811  * Free all receive software resources
1812  **/
1813 void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter)
1814 {
1815         int i;
1816
1817         for (i = 0; i < adapter->num_active_queues; i++)
1818                 if (adapter->rx_rings[i]->desc)
1819                         i40evf_free_rx_resources(adapter->rx_rings[i]);
1820 }
1821
1822 /**
1823  * i40evf_open - Called when a network interface is made active
1824  * @netdev: network interface device structure
1825  *
1826  * Returns 0 on success, negative value on failure
1827  *
1828  * The open entry point is called when a network interface is made
1829  * active by the system (IFF_UP).  At this point all resources needed
1830  * for transmit and receive operations are allocated, the interrupt
1831  * handler is registered with the OS, the watchdog timer is started,
1832  * and the stack is notified that the interface is ready.
1833  **/
1834 static int i40evf_open(struct net_device *netdev)
1835 {
1836         struct i40evf_adapter *adapter = netdev_priv(netdev);
1837         int err;
1838
1839         if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
1840                 dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
1841                 return -EIO;
1842         }
1843         if (adapter->state != __I40EVF_DOWN || adapter->aq_required)
1844                 return -EBUSY;
1845
1846         /* allocate transmit descriptors */
1847         err = i40evf_setup_all_tx_resources(adapter);
1848         if (err)
1849                 goto err_setup_tx;
1850
1851         /* allocate receive descriptors */
1852         err = i40evf_setup_all_rx_resources(adapter);
1853         if (err)
1854                 goto err_setup_rx;
1855
1856         /* clear any pending interrupts, may auto mask */
1857         err = i40evf_request_traffic_irqs(adapter, netdev->name);
1858         if (err)
1859                 goto err_req_irq;
1860
1861         i40evf_add_filter(adapter, adapter->hw.mac.addr);
1862         i40evf_configure(adapter);
1863
1864         err = i40evf_up_complete(adapter);
1865         if (err)
1866                 goto err_req_irq;
1867
1868         i40evf_irq_enable(adapter, true);
1869
1870         return 0;
1871
1872 err_req_irq:
1873         i40evf_down(adapter);
1874         i40evf_free_traffic_irqs(adapter);
1875 err_setup_rx:
1876         i40evf_free_all_rx_resources(adapter);
1877 err_setup_tx:
1878         i40evf_free_all_tx_resources(adapter);
1879
1880         return err;
1881 }
1882
1883 /**
1884  * i40evf_close - Disables a network interface
1885  * @netdev: network interface device structure
1886  *
1887  * Returns 0, this is not allowed to fail
1888  *
1889  * The close entry point is called when an interface is de-activated
1890  * by the OS.  The hardware is still under the drivers control, but
1891  * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
1892  * are freed, along with all transmit and receive resources.
1893  **/
1894 static int i40evf_close(struct net_device *netdev)
1895 {
1896         struct i40evf_adapter *adapter = netdev_priv(netdev);
1897
1898         if (adapter->state <= __I40EVF_DOWN)
1899                 return 0;
1900
1901
1902         set_bit(__I40E_DOWN, &adapter->vsi.state);
1903
1904         i40evf_down(adapter);
1905         adapter->state = __I40EVF_DOWN;
1906         i40evf_free_traffic_irqs(adapter);
1907
1908         return 0;
1909 }
1910
1911 /**
1912  * i40evf_get_stats - Get System Network Statistics
1913  * @netdev: network interface device structure
1914  *
1915  * Returns the address of the device statistics structure.
1916  * The statistics are actually updated from the timer callback.
1917  **/
1918 static struct net_device_stats *i40evf_get_stats(struct net_device *netdev)
1919 {
1920         struct i40evf_adapter *adapter = netdev_priv(netdev);
1921
1922         /* only return the current stats */
1923         return &adapter->net_stats;
1924 }
1925
1926 /**
1927  * i40evf_change_mtu - Change the Maximum Transfer Unit
1928  * @netdev: network interface device structure
1929  * @new_mtu: new value for maximum frame size
1930  *
1931  * Returns 0 on success, negative on failure
1932  **/
1933 static int i40evf_change_mtu(struct net_device *netdev, int new_mtu)
1934 {
1935         struct i40evf_adapter *adapter = netdev_priv(netdev);
1936         int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
1937
1938         if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
1939                 return -EINVAL;
1940
1941         netdev->mtu = new_mtu;
1942         adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
1943         schedule_work(&adapter->reset_task);
1944
1945         return 0;
1946 }
1947
1948 static const struct net_device_ops i40evf_netdev_ops = {
1949         .ndo_open               = i40evf_open,
1950         .ndo_stop               = i40evf_close,
1951         .ndo_start_xmit         = i40evf_xmit_frame,
1952         .ndo_get_stats          = i40evf_get_stats,
1953         .ndo_set_rx_mode        = i40evf_set_rx_mode,
1954         .ndo_validate_addr      = eth_validate_addr,
1955         .ndo_set_mac_address    = i40evf_set_mac,
1956         .ndo_change_mtu         = i40evf_change_mtu,
1957         .ndo_tx_timeout         = i40evf_tx_timeout,
1958         .ndo_vlan_rx_add_vid    = i40evf_vlan_rx_add_vid,
1959         .ndo_vlan_rx_kill_vid   = i40evf_vlan_rx_kill_vid,
1960 };
1961
1962 /**
1963  * i40evf_check_reset_complete - check that VF reset is complete
1964  * @hw: pointer to hw struct
1965  *
1966  * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
1967  **/
1968 static int i40evf_check_reset_complete(struct i40e_hw *hw)
1969 {
1970         u32 rstat;
1971         int i;
1972
1973         for (i = 0; i < 100; i++) {
1974                 rstat = rd32(hw, I40E_VFGEN_RSTAT) &
1975                             I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1976                 if ((rstat == I40E_VFR_VFACTIVE) ||
1977                     (rstat == I40E_VFR_COMPLETED))
1978                         return 0;
1979                 usleep_range(10, 20);
1980         }
1981         return -EBUSY;
1982 }
1983
1984 /**
1985  * i40evf_init_task - worker thread to perform delayed initialization
1986  * @work: pointer to work_struct containing our data
1987  *
1988  * This task completes the work that was begun in probe. Due to the nature
1989  * of VF-PF communications, we may need to wait tens of milliseconds to get
1990  * responses back from the PF. Rather than busy-wait in probe and bog down the
1991  * whole system, we'll do it in a task so we can sleep.
1992  * This task only runs during driver init. Once we've established
1993  * communications with the PF driver and set up our netdev, the watchdog
1994  * takes over.
1995  **/
1996 static void i40evf_init_task(struct work_struct *work)
1997 {
1998         struct i40evf_adapter *adapter = container_of(work,
1999                                                       struct i40evf_adapter,
2000                                                       init_task.work);
2001         struct net_device *netdev = adapter->netdev;
2002         struct i40e_hw *hw = &adapter->hw;
2003         struct pci_dev *pdev = adapter->pdev;
2004         int i, err, bufsz;
2005
2006         switch (adapter->state) {
2007         case __I40EVF_STARTUP:
2008                 /* driver loaded, probe complete */
2009                 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
2010                 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
2011                 err = i40e_set_mac_type(hw);
2012                 if (err) {
2013                         dev_err(&pdev->dev, "Failed to set MAC type (%d)\n",
2014                                 err);
2015                         goto err;
2016                 }
2017                 err = i40evf_check_reset_complete(hw);
2018                 if (err) {
2019                         dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n",
2020                                  err);
2021                         goto err;
2022                 }
2023                 hw->aq.num_arq_entries = I40EVF_AQ_LEN;
2024                 hw->aq.num_asq_entries = I40EVF_AQ_LEN;
2025                 hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2026                 hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2027
2028                 err = i40evf_init_adminq(hw);
2029                 if (err) {
2030                         dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n",
2031                                 err);
2032                         goto err;
2033                 }
2034                 err = i40evf_send_api_ver(adapter);
2035                 if (err) {
2036                         dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err);
2037                         i40evf_shutdown_adminq(hw);
2038                         goto err;
2039                 }
2040                 adapter->state = __I40EVF_INIT_VERSION_CHECK;
2041                 goto restart;
2042         case __I40EVF_INIT_VERSION_CHECK:
2043                 if (!i40evf_asq_done(hw)) {
2044                         dev_err(&pdev->dev, "Admin queue command never completed\n");
2045                         i40evf_shutdown_adminq(hw);
2046                         adapter->state = __I40EVF_STARTUP;
2047                         goto err;
2048                 }
2049
2050                 /* aq msg sent, awaiting reply */
2051                 err = i40evf_verify_api_ver(adapter);
2052                 if (err) {
2053                         if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
2054                                 err = i40evf_send_api_ver(adapter);
2055                         goto err;
2056                 }
2057                 err = i40evf_send_vf_config_msg(adapter);
2058                 if (err) {
2059                         dev_err(&pdev->dev, "Unable to send config request (%d)\n",
2060                                 err);
2061                         goto err;
2062                 }
2063                 adapter->state = __I40EVF_INIT_GET_RESOURCES;
2064                 goto restart;
2065         case __I40EVF_INIT_GET_RESOURCES:
2066                 /* aq msg sent, awaiting reply */
2067                 if (!adapter->vf_res) {
2068                         bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
2069                                 (I40E_MAX_VF_VSI *
2070                                  sizeof(struct i40e_virtchnl_vsi_resource));
2071                         adapter->vf_res = kzalloc(bufsz, GFP_KERNEL);
2072                         if (!adapter->vf_res)
2073                                 goto err;
2074                 }
2075                 err = i40evf_get_vf_config(adapter);
2076                 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) {
2077                         err = i40evf_send_vf_config_msg(adapter);
2078                         goto err;
2079                 }
2080                 if (err) {
2081                         dev_err(&pdev->dev, "Unable to get VF config (%d)\n",
2082                                 err);
2083                         goto err_alloc;
2084                 }
2085                 adapter->state = __I40EVF_INIT_SW;
2086                 break;
2087         default:
2088                 goto err_alloc;
2089         }
2090         /* got VF config message back from PF, now we can parse it */
2091         for (i = 0; i < adapter->vf_res->num_vsis; i++) {
2092                 if (adapter->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
2093                         adapter->vsi_res = &adapter->vf_res->vsi_res[i];
2094         }
2095         if (!adapter->vsi_res) {
2096                 dev_err(&pdev->dev, "No LAN VSI found\n");
2097                 goto err_alloc;
2098         }
2099
2100         adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED;
2101
2102         netdev->netdev_ops = &i40evf_netdev_ops;
2103         i40evf_set_ethtool_ops(netdev);
2104         netdev->watchdog_timeo = 5 * HZ;
2105         netdev->features |= NETIF_F_HIGHDMA |
2106                             NETIF_F_SG |
2107                             NETIF_F_IP_CSUM |
2108                             NETIF_F_SCTP_CSUM |
2109                             NETIF_F_IPV6_CSUM |
2110                             NETIF_F_TSO |
2111                             NETIF_F_TSO6 |
2112                             NETIF_F_RXCSUM |
2113                             NETIF_F_GRO;
2114
2115         if (adapter->vf_res->vf_offload_flags
2116             & I40E_VIRTCHNL_VF_OFFLOAD_VLAN) {
2117                 netdev->vlan_features = netdev->features;
2118                 netdev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2119                                     NETIF_F_HW_VLAN_CTAG_RX |
2120                                     NETIF_F_HW_VLAN_CTAG_FILTER;
2121         }
2122
2123         /* copy netdev features into list of user selectable features */
2124         netdev->hw_features |= netdev->features;
2125         netdev->hw_features &= ~NETIF_F_RXCSUM;
2126
2127         if (!is_valid_ether_addr(adapter->hw.mac.addr)) {
2128                 dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n",
2129                          adapter->hw.mac.addr);
2130                 random_ether_addr(adapter->hw.mac.addr);
2131         }
2132         ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
2133         ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr);
2134
2135         init_timer(&adapter->watchdog_timer);
2136         adapter->watchdog_timer.function = &i40evf_watchdog_timer;
2137         adapter->watchdog_timer.data = (unsigned long)adapter;
2138         mod_timer(&adapter->watchdog_timer, jiffies + 1);
2139
2140         adapter->num_active_queues = min_t(int,
2141                                            adapter->vsi_res->num_queue_pairs,
2142                                            (int)(num_online_cpus()));
2143         adapter->tx_desc_count = I40EVF_DEFAULT_TXD;
2144         adapter->rx_desc_count = I40EVF_DEFAULT_RXD;
2145         err = i40evf_init_interrupt_scheme(adapter);
2146         if (err)
2147                 goto err_sw_init;
2148         i40evf_map_rings_to_vectors(adapter);
2149         i40evf_configure_rss(adapter);
2150         err = i40evf_request_misc_irq(adapter);
2151         if (err)
2152                 goto err_sw_init;
2153
2154         netif_carrier_off(netdev);
2155
2156         adapter->vsi.id = adapter->vsi_res->vsi_id;
2157         adapter->vsi.seid = adapter->vsi_res->vsi_id; /* dummy */
2158         adapter->vsi.back = adapter;
2159         adapter->vsi.base_vector = 1;
2160         adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK;
2161         adapter->vsi.rx_itr_setting = (I40E_ITR_DYNAMIC |
2162                                        ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
2163         adapter->vsi.tx_itr_setting = (I40E_ITR_DYNAMIC |
2164                                        ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
2165         adapter->vsi.netdev = adapter->netdev;
2166
2167         if (!adapter->netdev_registered) {
2168                 err = register_netdev(netdev);
2169                 if (err)
2170                         goto err_register;
2171         }
2172
2173         adapter->netdev_registered = true;
2174
2175         netif_tx_stop_all_queues(netdev);
2176
2177         dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr);
2178         if (netdev->features & NETIF_F_GRO)
2179                 dev_info(&pdev->dev, "GRO is enabled\n");
2180
2181         dev_info(&pdev->dev, "%s\n", i40evf_driver_string);
2182         adapter->state = __I40EVF_DOWN;
2183         set_bit(__I40E_DOWN, &adapter->vsi.state);
2184         i40evf_misc_irq_enable(adapter);
2185         return;
2186 restart:
2187         schedule_delayed_work(&adapter->init_task,
2188                               msecs_to_jiffies(50));
2189         return;
2190
2191 err_register:
2192         i40evf_free_misc_irq(adapter);
2193 err_sw_init:
2194         i40evf_reset_interrupt_capability(adapter);
2195 err_alloc:
2196         kfree(adapter->vf_res);
2197         adapter->vf_res = NULL;
2198 err:
2199         /* Things went into the weeds, so try again later */
2200         if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) {
2201                 dev_err(&pdev->dev, "Failed to communicate with PF; giving up\n");
2202                 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
2203                 return; /* do not reschedule */
2204         }
2205         schedule_delayed_work(&adapter->init_task, HZ * 3);
2206 }
2207
2208 /**
2209  * i40evf_shutdown - Shutdown the device in preparation for a reboot
2210  * @pdev: pci device structure
2211  **/
2212 static void i40evf_shutdown(struct pci_dev *pdev)
2213 {
2214         struct net_device *netdev = pci_get_drvdata(pdev);
2215         struct i40evf_adapter *adapter = netdev_priv(netdev);
2216
2217         netif_device_detach(netdev);
2218
2219         if (netif_running(netdev))
2220                 i40evf_close(netdev);
2221
2222         /* Prevent the watchdog from running. */
2223         adapter->state = __I40EVF_REMOVE;
2224         adapter->aq_required = 0;
2225
2226 #ifdef CONFIG_PM
2227         pci_save_state(pdev);
2228
2229 #endif
2230         pci_disable_device(pdev);
2231 }
2232
2233 /**
2234  * i40evf_probe - Device Initialization Routine
2235  * @pdev: PCI device information struct
2236  * @ent: entry in i40evf_pci_tbl
2237  *
2238  * Returns 0 on success, negative on failure
2239  *
2240  * i40evf_probe initializes an adapter identified by a pci_dev structure.
2241  * The OS initialization, configuring of the adapter private structure,
2242  * and a hardware reset occur.
2243  **/
2244 static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2245 {
2246         struct net_device *netdev;
2247         struct i40evf_adapter *adapter = NULL;
2248         struct i40e_hw *hw = NULL;
2249         int err;
2250
2251         err = pci_enable_device(pdev);
2252         if (err)
2253                 return err;
2254
2255         err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
2256         if (err) {
2257                 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2258                 if (err) {
2259                         dev_err(&pdev->dev,
2260                                 "DMA configuration failed: 0x%x\n", err);
2261                         goto err_dma;
2262                 }
2263         }
2264
2265         err = pci_request_regions(pdev, i40evf_driver_name);
2266         if (err) {
2267                 dev_err(&pdev->dev,
2268                         "pci_request_regions failed 0x%x\n", err);
2269                 goto err_pci_reg;
2270         }
2271
2272         pci_enable_pcie_error_reporting(pdev);
2273
2274         pci_set_master(pdev);
2275
2276         netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter),
2277                                    MAX_TX_QUEUES);
2278         if (!netdev) {
2279                 err = -ENOMEM;
2280                 goto err_alloc_etherdev;
2281         }
2282
2283         SET_NETDEV_DEV(netdev, &pdev->dev);
2284
2285         pci_set_drvdata(pdev, netdev);
2286         adapter = netdev_priv(netdev);
2287
2288         adapter->netdev = netdev;
2289         adapter->pdev = pdev;
2290
2291         hw = &adapter->hw;
2292         hw->back = adapter;
2293
2294         adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
2295         adapter->state = __I40EVF_STARTUP;
2296
2297         /* Call save state here because it relies on the adapter struct. */
2298         pci_save_state(pdev);
2299
2300         hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2301                               pci_resource_len(pdev, 0));
2302         if (!hw->hw_addr) {
2303                 err = -EIO;
2304                 goto err_ioremap;
2305         }
2306         hw->vendor_id = pdev->vendor;
2307         hw->device_id = pdev->device;
2308         pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2309         hw->subsystem_vendor_id = pdev->subsystem_vendor;
2310         hw->subsystem_device_id = pdev->subsystem_device;
2311         hw->bus.device = PCI_SLOT(pdev->devfn);
2312         hw->bus.func = PCI_FUNC(pdev->devfn);
2313
2314         INIT_LIST_HEAD(&adapter->mac_filter_list);
2315         INIT_LIST_HEAD(&adapter->vlan_filter_list);
2316
2317         INIT_WORK(&adapter->reset_task, i40evf_reset_task);
2318         INIT_WORK(&adapter->adminq_task, i40evf_adminq_task);
2319         INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task);
2320         INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task);
2321         schedule_delayed_work(&adapter->init_task, 10);
2322
2323         return 0;
2324
2325 err_ioremap:
2326         free_netdev(netdev);
2327 err_alloc_etherdev:
2328         pci_release_regions(pdev);
2329 err_pci_reg:
2330 err_dma:
2331         pci_disable_device(pdev);
2332         return err;
2333 }
2334
2335 #ifdef CONFIG_PM
2336 /**
2337  * i40evf_suspend - Power management suspend routine
2338  * @pdev: PCI device information struct
2339  * @state: unused
2340  *
2341  * Called when the system (VM) is entering sleep/suspend.
2342  **/
2343 static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state)
2344 {
2345         struct net_device *netdev = pci_get_drvdata(pdev);
2346         struct i40evf_adapter *adapter = netdev_priv(netdev);
2347         int retval = 0;
2348
2349         netif_device_detach(netdev);
2350
2351         if (netif_running(netdev)) {
2352                 rtnl_lock();
2353                 i40evf_down(adapter);
2354                 rtnl_unlock();
2355         }
2356         i40evf_free_misc_irq(adapter);
2357         i40evf_reset_interrupt_capability(adapter);
2358
2359         retval = pci_save_state(pdev);
2360         if (retval)
2361                 return retval;
2362
2363         pci_disable_device(pdev);
2364
2365         return 0;
2366 }
2367
2368 /**
2369  * i40evf_resume - Power management resume routine
2370  * @pdev: PCI device information struct
2371  *
2372  * Called when the system (VM) is resumed from sleep/suspend.
2373  **/
2374 static int i40evf_resume(struct pci_dev *pdev)
2375 {
2376         struct i40evf_adapter *adapter = pci_get_drvdata(pdev);
2377         struct net_device *netdev = adapter->netdev;
2378         u32 err;
2379
2380         pci_set_power_state(pdev, PCI_D0);
2381         pci_restore_state(pdev);
2382         /* pci_restore_state clears dev->state_saved so call
2383          * pci_save_state to restore it.
2384          */
2385         pci_save_state(pdev);
2386
2387         err = pci_enable_device_mem(pdev);
2388         if (err) {
2389                 dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n");
2390                 return err;
2391         }
2392         pci_set_master(pdev);
2393
2394         rtnl_lock();
2395         err = i40evf_set_interrupt_capability(adapter);
2396         if (err) {
2397                 dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n");
2398                 return err;
2399         }
2400         err = i40evf_request_misc_irq(adapter);
2401         rtnl_unlock();
2402         if (err) {
2403                 dev_err(&pdev->dev, "Cannot get interrupt vector.\n");
2404                 return err;
2405         }
2406
2407         schedule_work(&adapter->reset_task);
2408
2409         netif_device_attach(netdev);
2410
2411         return err;
2412 }
2413
2414 #endif /* CONFIG_PM */
2415 /**
2416  * i40evf_remove - Device Removal Routine
2417  * @pdev: PCI device information struct
2418  *
2419  * i40evf_remove is called by the PCI subsystem to alert the driver
2420  * that it should release a PCI device.  The could be caused by a
2421  * Hot-Plug event, or because the driver is going to be removed from
2422  * memory.
2423  **/
2424 static void i40evf_remove(struct pci_dev *pdev)
2425 {
2426         struct net_device *netdev = pci_get_drvdata(pdev);
2427         struct i40evf_adapter *adapter = netdev_priv(netdev);
2428         struct i40evf_mac_filter *f, *ftmp;
2429         struct i40e_hw *hw = &adapter->hw;
2430
2431         cancel_delayed_work_sync(&adapter->init_task);
2432         cancel_work_sync(&adapter->reset_task);
2433
2434         if (adapter->netdev_registered) {
2435                 unregister_netdev(netdev);
2436                 adapter->netdev_registered = false;
2437         }
2438
2439         /* Shut down all the garbage mashers on the detention level */
2440         adapter->state = __I40EVF_REMOVE;
2441         adapter->aq_required = 0;
2442         i40evf_request_reset(adapter);
2443         msleep(20);
2444         /* If the FW isn't responding, kick it once, but only once. */
2445         if (!i40evf_asq_done(hw)) {
2446                 i40evf_request_reset(adapter);
2447                 msleep(20);
2448         }
2449
2450         if (adapter->msix_entries) {
2451                 i40evf_misc_irq_disable(adapter);
2452                 i40evf_free_misc_irq(adapter);
2453                 i40evf_reset_interrupt_capability(adapter);
2454                 i40evf_free_q_vectors(adapter);
2455         }
2456
2457         if (adapter->watchdog_timer.function)
2458                 del_timer_sync(&adapter->watchdog_timer);
2459
2460         flush_scheduled_work();
2461
2462         if (hw->aq.asq.count)
2463                 i40evf_shutdown_adminq(hw);
2464
2465         iounmap(hw->hw_addr);
2466         pci_release_regions(pdev);
2467
2468         i40evf_free_all_tx_resources(adapter);
2469         i40evf_free_all_rx_resources(adapter);
2470         i40evf_free_queues(adapter);
2471         kfree(adapter->vf_res);
2472         /* If we got removed before an up/down sequence, we've got a filter
2473          * hanging out there that we need to get rid of.
2474          */
2475         list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
2476                 list_del(&f->list);
2477                 kfree(f);
2478         }
2479         list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
2480                 list_del(&f->list);
2481                 kfree(f);
2482         }
2483
2484         free_netdev(netdev);
2485
2486         pci_disable_pcie_error_reporting(pdev);
2487
2488         pci_disable_device(pdev);
2489 }
2490
2491 static struct pci_driver i40evf_driver = {
2492         .name     = i40evf_driver_name,
2493         .id_table = i40evf_pci_tbl,
2494         .probe    = i40evf_probe,
2495         .remove   = i40evf_remove,
2496 #ifdef CONFIG_PM
2497         .suspend  = i40evf_suspend,
2498         .resume   = i40evf_resume,
2499 #endif
2500         .shutdown = i40evf_shutdown,
2501 };
2502
2503 /**
2504  * i40e_init_module - Driver Registration Routine
2505  *
2506  * i40e_init_module is the first routine called when the driver is
2507  * loaded. All it does is register with the PCI subsystem.
2508  **/
2509 static int __init i40evf_init_module(void)
2510 {
2511         int ret;
2512
2513         pr_info("i40evf: %s - version %s\n", i40evf_driver_string,
2514                 i40evf_driver_version);
2515
2516         pr_info("%s\n", i40evf_copyright);
2517
2518         ret = pci_register_driver(&i40evf_driver);
2519         return ret;
2520 }
2521
2522 module_init(i40evf_init_module);
2523
2524 /**
2525  * i40e_exit_module - Driver Exit Cleanup Routine
2526  *
2527  * i40e_exit_module is called just before the driver is removed
2528  * from memory.
2529  **/
2530 static void __exit i40evf_exit_module(void)
2531 {
2532         pci_unregister_driver(&i40evf_driver);
2533 }
2534
2535 module_exit(i40evf_exit_module);
2536
2537 /* i40evf_main.c */