1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
4 * Copyright(c) 2013 - 2015 Intel Corporation.
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.
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
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/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
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
25 ******************************************************************************/
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
);
33 char i40evf_driver_name
[] = "i40evf";
34 static const char i40evf_driver_string
[] =
35 "Intel(R) XL710/X710 Virtual Function Network Driver";
39 #define DRV_VERSION_MAJOR 1
40 #define DRV_VERSION_MINOR 4
41 #define DRV_VERSION_BUILD 4
42 #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
43 __stringify(DRV_VERSION_MINOR) "." \
44 __stringify(DRV_VERSION_BUILD) \
46 const char i40evf_driver_version
[] = DRV_VERSION
;
47 static const char i40evf_copyright
[] =
48 "Copyright (c) 2013 - 2015 Intel Corporation.";
50 /* i40evf_pci_tbl - PCI Device ID Table
52 * Wildcard entries (PCI_ANY_ID) should come last
53 * Last entry must be all 0s
55 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
56 * Class, Class Mask, private data (not used) }
58 static const struct pci_device_id i40evf_pci_tbl
[] = {
59 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_VF
), 0},
60 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_X722_VF
), 0},
61 /* required last entry */
65 MODULE_DEVICE_TABLE(pci
, i40evf_pci_tbl
);
67 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
68 MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver");
69 MODULE_LICENSE("GPL");
70 MODULE_VERSION(DRV_VERSION
);
73 * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code
74 * @hw: pointer to the HW structure
75 * @mem: ptr to mem struct to fill out
76 * @size: size of memory requested
77 * @alignment: what to align the allocation to
79 i40e_status
i40evf_allocate_dma_mem_d(struct i40e_hw
*hw
,
80 struct i40e_dma_mem
*mem
,
81 u64 size
, u32 alignment
)
83 struct i40evf_adapter
*adapter
= (struct i40evf_adapter
*)hw
->back
;
86 return I40E_ERR_PARAM
;
88 mem
->size
= ALIGN(size
, alignment
);
89 mem
->va
= dma_alloc_coherent(&adapter
->pdev
->dev
, mem
->size
,
90 (dma_addr_t
*)&mem
->pa
, GFP_KERNEL
);
94 return I40E_ERR_NO_MEMORY
;
98 * i40evf_free_dma_mem_d - OS specific memory free for shared code
99 * @hw: pointer to the HW structure
100 * @mem: ptr to mem struct to free
102 i40e_status
i40evf_free_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
)
104 struct i40evf_adapter
*adapter
= (struct i40evf_adapter
*)hw
->back
;
106 if (!mem
|| !mem
->va
)
107 return I40E_ERR_PARAM
;
108 dma_free_coherent(&adapter
->pdev
->dev
, mem
->size
,
109 mem
->va
, (dma_addr_t
)mem
->pa
);
114 * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code
115 * @hw: pointer to the HW structure
116 * @mem: ptr to mem struct to fill out
117 * @size: size of memory requested
119 i40e_status
i40evf_allocate_virt_mem_d(struct i40e_hw
*hw
,
120 struct i40e_virt_mem
*mem
, u32 size
)
123 return I40E_ERR_PARAM
;
126 mem
->va
= kzalloc(size
, GFP_KERNEL
);
131 return I40E_ERR_NO_MEMORY
;
135 * i40evf_free_virt_mem_d - OS specific memory free for shared code
136 * @hw: pointer to the HW structure
137 * @mem: ptr to mem struct to free
139 i40e_status
i40evf_free_virt_mem_d(struct i40e_hw
*hw
,
140 struct i40e_virt_mem
*mem
)
143 return I40E_ERR_PARAM
;
145 /* it's ok to kfree a NULL pointer */
152 * i40evf_debug_d - OS dependent version of debug printing
153 * @hw: pointer to the HW structure
154 * @mask: debug level mask
155 * @fmt_str: printf-type format description
157 void i40evf_debug_d(void *hw
, u32 mask
, char *fmt_str
, ...)
162 if (!(mask
& ((struct i40e_hw
*)hw
)->debug_mask
))
165 va_start(argptr
, fmt_str
);
166 vsnprintf(buf
, sizeof(buf
), fmt_str
, argptr
);
169 /* the debug string is already formatted with a newline */
174 * i40evf_tx_timeout - Respond to a Tx Hang
175 * @netdev: network interface device structure
177 static void i40evf_tx_timeout(struct net_device
*netdev
)
179 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
181 adapter
->tx_timeout_count
++;
182 if (!(adapter
->flags
& (I40EVF_FLAG_RESET_PENDING
|
183 I40EVF_FLAG_RESET_NEEDED
))) {
184 adapter
->flags
|= I40EVF_FLAG_RESET_NEEDED
;
185 schedule_work(&adapter
->reset_task
);
190 * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC
191 * @adapter: board private structure
193 static void i40evf_misc_irq_disable(struct i40evf_adapter
*adapter
)
195 struct i40e_hw
*hw
= &adapter
->hw
;
197 wr32(hw
, I40E_VFINT_DYN_CTL01
, 0);
200 rd32(hw
, I40E_VFGEN_RSTAT
);
202 synchronize_irq(adapter
->msix_entries
[0].vector
);
206 * i40evf_misc_irq_enable - Enable default interrupt generation settings
207 * @adapter: board private structure
209 static void i40evf_misc_irq_enable(struct i40evf_adapter
*adapter
)
211 struct i40e_hw
*hw
= &adapter
->hw
;
213 wr32(hw
, I40E_VFINT_DYN_CTL01
, I40E_VFINT_DYN_CTL01_INTENA_MASK
|
214 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK
);
215 wr32(hw
, I40E_VFINT_ICR0_ENA1
, I40E_VFINT_ICR0_ENA1_ADMINQ_MASK
);
218 rd32(hw
, I40E_VFGEN_RSTAT
);
222 * i40evf_irq_disable - Mask off interrupt generation on the NIC
223 * @adapter: board private structure
225 static void i40evf_irq_disable(struct i40evf_adapter
*adapter
)
228 struct i40e_hw
*hw
= &adapter
->hw
;
230 if (!adapter
->msix_entries
)
233 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
234 wr32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1), 0);
235 synchronize_irq(adapter
->msix_entries
[i
].vector
);
238 rd32(hw
, I40E_VFGEN_RSTAT
);
242 * i40evf_irq_enable_queues - Enable interrupt for specified queues
243 * @adapter: board private structure
244 * @mask: bitmap of queues to enable
246 void i40evf_irq_enable_queues(struct i40evf_adapter
*adapter
, u32 mask
)
248 struct i40e_hw
*hw
= &adapter
->hw
;
251 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
252 if (mask
& BIT(i
- 1)) {
253 wr32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1),
254 I40E_VFINT_DYN_CTLN1_INTENA_MASK
|
255 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK
|
256 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK
);
262 * i40evf_fire_sw_int - Generate SW interrupt for specified vectors
263 * @adapter: board private structure
264 * @mask: bitmap of vectors to trigger
266 static void i40evf_fire_sw_int(struct i40evf_adapter
*adapter
, u32 mask
)
268 struct i40e_hw
*hw
= &adapter
->hw
;
273 dyn_ctl
= rd32(hw
, I40E_VFINT_DYN_CTL01
);
274 dyn_ctl
|= I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK
|
275 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK
|
276 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK
;
277 wr32(hw
, I40E_VFINT_DYN_CTL01
, dyn_ctl
);
279 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
281 dyn_ctl
= rd32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1));
282 dyn_ctl
|= I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK
|
283 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK
|
284 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK
;
285 wr32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1), dyn_ctl
);
291 * i40evf_irq_enable - Enable default interrupt generation settings
292 * @adapter: board private structure
293 * @flush: boolean value whether to run rd32()
295 void i40evf_irq_enable(struct i40evf_adapter
*adapter
, bool flush
)
297 struct i40e_hw
*hw
= &adapter
->hw
;
299 i40evf_misc_irq_enable(adapter
);
300 i40evf_irq_enable_queues(adapter
, ~0);
303 rd32(hw
, I40E_VFGEN_RSTAT
);
307 * i40evf_msix_aq - Interrupt handler for vector 0
308 * @irq: interrupt number
309 * @data: pointer to netdev
311 static irqreturn_t
i40evf_msix_aq(int irq
, void *data
)
313 struct net_device
*netdev
= data
;
314 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
315 struct i40e_hw
*hw
= &adapter
->hw
;
318 /* handle non-queue interrupts, these reads clear the registers */
319 val
= rd32(hw
, I40E_VFINT_ICR01
);
320 val
= rd32(hw
, I40E_VFINT_ICR0_ENA1
);
322 val
= rd32(hw
, I40E_VFINT_DYN_CTL01
) |
323 I40E_VFINT_DYN_CTL01_CLEARPBA_MASK
;
324 wr32(hw
, I40E_VFINT_DYN_CTL01
, val
);
326 /* schedule work on the private workqueue */
327 schedule_work(&adapter
->adminq_task
);
333 * i40evf_msix_clean_rings - MSIX mode Interrupt Handler
334 * @irq: interrupt number
335 * @data: pointer to a q_vector
337 static irqreturn_t
i40evf_msix_clean_rings(int irq
, void *data
)
339 struct i40e_q_vector
*q_vector
= data
;
341 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
344 napi_schedule_irqoff(&q_vector
->napi
);
350 * i40evf_map_vector_to_rxq - associate irqs with rx queues
351 * @adapter: board private structure
352 * @v_idx: interrupt number
353 * @r_idx: queue number
356 i40evf_map_vector_to_rxq(struct i40evf_adapter
*adapter
, int v_idx
, int r_idx
)
358 struct i40e_q_vector
*q_vector
= &adapter
->q_vectors
[v_idx
];
359 struct i40e_ring
*rx_ring
= &adapter
->rx_rings
[r_idx
];
361 rx_ring
->q_vector
= q_vector
;
362 rx_ring
->next
= q_vector
->rx
.ring
;
363 rx_ring
->vsi
= &adapter
->vsi
;
364 q_vector
->rx
.ring
= rx_ring
;
365 q_vector
->rx
.count
++;
366 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
367 q_vector
->itr_countdown
= ITR_COUNTDOWN_START
;
371 * i40evf_map_vector_to_txq - associate irqs with tx queues
372 * @adapter: board private structure
373 * @v_idx: interrupt number
374 * @t_idx: queue number
377 i40evf_map_vector_to_txq(struct i40evf_adapter
*adapter
, int v_idx
, int t_idx
)
379 struct i40e_q_vector
*q_vector
= &adapter
->q_vectors
[v_idx
];
380 struct i40e_ring
*tx_ring
= &adapter
->tx_rings
[t_idx
];
382 tx_ring
->q_vector
= q_vector
;
383 tx_ring
->next
= q_vector
->tx
.ring
;
384 tx_ring
->vsi
= &adapter
->vsi
;
385 q_vector
->tx
.ring
= tx_ring
;
386 q_vector
->tx
.count
++;
387 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
388 q_vector
->itr_countdown
= ITR_COUNTDOWN_START
;
389 q_vector
->num_ringpairs
++;
390 q_vector
->ring_mask
|= BIT(t_idx
);
394 * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors
395 * @adapter: board private structure to initialize
397 * This function maps descriptor rings to the queue-specific vectors
398 * we were allotted through the MSI-X enabling code. Ideally, we'd have
399 * one vector per ring/queue, but on a constrained vector budget, we
400 * group the rings as "efficiently" as possible. You would add new
401 * mapping configurations in here.
403 static int i40evf_map_rings_to_vectors(struct i40evf_adapter
*adapter
)
407 int rxr_idx
= 0, txr_idx
= 0;
408 int rxr_remaining
= adapter
->num_active_queues
;
409 int txr_remaining
= adapter
->num_active_queues
;
414 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
416 /* The ideal configuration...
417 * We have enough vectors to map one per queue.
419 if (q_vectors
>= (rxr_remaining
* 2)) {
420 for (; rxr_idx
< rxr_remaining
; v_start
++, rxr_idx
++)
421 i40evf_map_vector_to_rxq(adapter
, v_start
, rxr_idx
);
423 for (; txr_idx
< txr_remaining
; v_start
++, txr_idx
++)
424 i40evf_map_vector_to_txq(adapter
, v_start
, txr_idx
);
428 /* If we don't have enough vectors for a 1-to-1
429 * mapping, we'll have to group them so there are
430 * multiple queues per vector.
431 * Re-adjusting *qpv takes care of the remainder.
433 for (i
= v_start
; i
< q_vectors
; i
++) {
434 rqpv
= DIV_ROUND_UP(rxr_remaining
, q_vectors
- i
);
435 for (j
= 0; j
< rqpv
; j
++) {
436 i40evf_map_vector_to_rxq(adapter
, i
, rxr_idx
);
441 for (i
= v_start
; i
< q_vectors
; i
++) {
442 tqpv
= DIV_ROUND_UP(txr_remaining
, q_vectors
- i
);
443 for (j
= 0; j
< tqpv
; j
++) {
444 i40evf_map_vector_to_txq(adapter
, i
, txr_idx
);
451 adapter
->aq_required
|= I40EVF_FLAG_AQ_MAP_VECTORS
;
456 #ifdef CONFIG_NET_POLL_CONTROLLER
458 * i40evf_netpoll - A Polling 'interrupt' handler
459 * @netdev: network interface device structure
461 * This is used by netconsole to send skbs without having to re-enable
462 * interrupts. It's not called while the normal interrupt routine is executing.
464 static void i40evf_netpoll(struct net_device
*netdev
)
466 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
467 int q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
470 /* if interface is down do nothing */
471 if (test_bit(__I40E_DOWN
, &adapter
->vsi
.state
))
474 for (i
= 0; i
< q_vectors
; i
++)
475 i40evf_msix_clean_rings(0, &adapter
->q_vectors
[i
]);
480 * i40evf_request_traffic_irqs - Initialize MSI-X interrupts
481 * @adapter: board private structure
483 * Allocates MSI-X vectors for tx and rx handling, and requests
484 * interrupts from the kernel.
487 i40evf_request_traffic_irqs(struct i40evf_adapter
*adapter
, char *basename
)
489 int vector
, err
, q_vectors
;
490 int rx_int_idx
= 0, tx_int_idx
= 0;
492 i40evf_irq_disable(adapter
);
493 /* Decrement for Other and TCP Timer vectors */
494 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
496 for (vector
= 0; vector
< q_vectors
; vector
++) {
497 struct i40e_q_vector
*q_vector
= &adapter
->q_vectors
[vector
];
499 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
500 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
501 "i40evf-%s-%s-%d", basename
,
502 "TxRx", rx_int_idx
++);
504 } else if (q_vector
->rx
.ring
) {
505 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
506 "i40evf-%s-%s-%d", basename
,
508 } else if (q_vector
->tx
.ring
) {
509 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
510 "i40evf-%s-%s-%d", basename
,
513 /* skip this unused q_vector */
517 adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
518 i40evf_msix_clean_rings
,
523 dev_info(&adapter
->pdev
->dev
,
524 "Request_irq failed, error: %d\n", err
);
525 goto free_queue_irqs
;
527 /* assign the mask for this irq */
528 irq_set_affinity_hint(
529 adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
530 q_vector
->affinity_mask
);
538 irq_set_affinity_hint(
539 adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
541 free_irq(adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
542 &adapter
->q_vectors
[vector
]);
548 * i40evf_request_misc_irq - Initialize MSI-X interrupts
549 * @adapter: board private structure
551 * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
552 * vector is only for the admin queue, and stays active even when the netdev
555 static int i40evf_request_misc_irq(struct i40evf_adapter
*adapter
)
557 struct net_device
*netdev
= adapter
->netdev
;
560 snprintf(adapter
->misc_vector_name
,
561 sizeof(adapter
->misc_vector_name
) - 1, "i40evf-%s:mbx",
562 dev_name(&adapter
->pdev
->dev
));
563 err
= request_irq(adapter
->msix_entries
[0].vector
,
565 adapter
->misc_vector_name
, netdev
);
567 dev_err(&adapter
->pdev
->dev
,
568 "request_irq for %s failed: %d\n",
569 adapter
->misc_vector_name
, err
);
570 free_irq(adapter
->msix_entries
[0].vector
, netdev
);
576 * i40evf_free_traffic_irqs - Free MSI-X interrupts
577 * @adapter: board private structure
579 * Frees all MSI-X vectors other than 0.
581 static void i40evf_free_traffic_irqs(struct i40evf_adapter
*adapter
)
586 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
588 for (i
= 0; i
< q_vectors
; i
++) {
589 irq_set_affinity_hint(adapter
->msix_entries
[i
+1].vector
,
591 free_irq(adapter
->msix_entries
[i
+1].vector
,
592 &adapter
->q_vectors
[i
]);
597 * i40evf_free_misc_irq - Free MSI-X miscellaneous vector
598 * @adapter: board private structure
600 * Frees MSI-X vector 0.
602 static void i40evf_free_misc_irq(struct i40evf_adapter
*adapter
)
604 struct net_device
*netdev
= adapter
->netdev
;
606 free_irq(adapter
->msix_entries
[0].vector
, netdev
);
610 * i40evf_configure_tx - Configure Transmit Unit after Reset
611 * @adapter: board private structure
613 * Configure the Tx unit of the MAC after a reset.
615 static void i40evf_configure_tx(struct i40evf_adapter
*adapter
)
617 struct i40e_hw
*hw
= &adapter
->hw
;
620 for (i
= 0; i
< adapter
->num_active_queues
; i
++)
621 adapter
->tx_rings
[i
].tail
= hw
->hw_addr
+ I40E_QTX_TAIL1(i
);
625 * i40evf_configure_rx - Configure Receive Unit after Reset
626 * @adapter: board private structure
628 * Configure the Rx unit of the MAC after a reset.
630 static void i40evf_configure_rx(struct i40evf_adapter
*adapter
)
632 struct i40e_hw
*hw
= &adapter
->hw
;
633 struct net_device
*netdev
= adapter
->netdev
;
634 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
639 adapter
->flags
&= ~I40EVF_FLAG_RX_PS_CAPABLE
;
640 adapter
->flags
|= I40EVF_FLAG_RX_1BUF_CAPABLE
;
642 /* Decide whether to use packet split mode or not */
643 if (netdev
->mtu
> ETH_DATA_LEN
) {
644 if (adapter
->flags
& I40EVF_FLAG_RX_PS_CAPABLE
)
645 adapter
->flags
|= I40EVF_FLAG_RX_PS_ENABLED
;
647 adapter
->flags
&= ~I40EVF_FLAG_RX_PS_ENABLED
;
649 if (adapter
->flags
& I40EVF_FLAG_RX_1BUF_CAPABLE
)
650 adapter
->flags
&= ~I40EVF_FLAG_RX_PS_ENABLED
;
652 adapter
->flags
|= I40EVF_FLAG_RX_PS_ENABLED
;
655 /* Set the RX buffer length according to the mode */
656 if (adapter
->flags
& I40EVF_FLAG_RX_PS_ENABLED
) {
657 rx_buf_len
= I40E_RX_HDR_SIZE
;
659 if (netdev
->mtu
<= ETH_DATA_LEN
)
660 rx_buf_len
= I40EVF_RXBUFFER_2048
;
662 rx_buf_len
= ALIGN(max_frame
, 1024);
665 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
666 adapter
->rx_rings
[i
].tail
= hw
->hw_addr
+ I40E_QRX_TAIL1(i
);
667 adapter
->rx_rings
[i
].rx_buf_len
= rx_buf_len
;
672 * i40evf_find_vlan - Search filter list for specific vlan filter
673 * @adapter: board private structure
676 * Returns ptr to the filter object or NULL
679 i40evf_vlan_filter
*i40evf_find_vlan(struct i40evf_adapter
*adapter
, u16 vlan
)
681 struct i40evf_vlan_filter
*f
;
683 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
691 * i40evf_add_vlan - Add a vlan filter to the list
692 * @adapter: board private structure
695 * Returns ptr to the filter object or NULL when no memory available.
698 i40evf_vlan_filter
*i40evf_add_vlan(struct i40evf_adapter
*adapter
, u16 vlan
)
700 struct i40evf_vlan_filter
*f
= NULL
;
703 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
704 &adapter
->crit_section
)) {
710 f
= i40evf_find_vlan(adapter
, vlan
);
712 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
718 INIT_LIST_HEAD(&f
->list
);
719 list_add(&f
->list
, &adapter
->vlan_filter_list
);
721 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_VLAN_FILTER
;
725 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
731 * i40evf_del_vlan - Remove a vlan filter from the list
732 * @adapter: board private structure
735 static void i40evf_del_vlan(struct i40evf_adapter
*adapter
, u16 vlan
)
737 struct i40evf_vlan_filter
*f
;
740 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
741 &adapter
->crit_section
)) {
747 f
= i40evf_find_vlan(adapter
, vlan
);
750 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_VLAN_FILTER
;
752 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
756 * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device
757 * @netdev: network device struct
760 static int i40evf_vlan_rx_add_vid(struct net_device
*netdev
,
761 __always_unused __be16 proto
, u16 vid
)
763 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
765 if (!VLAN_ALLOWED(adapter
))
767 if (i40evf_add_vlan(adapter
, vid
) == NULL
)
773 * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device
774 * @netdev: network device struct
777 static int i40evf_vlan_rx_kill_vid(struct net_device
*netdev
,
778 __always_unused __be16 proto
, u16 vid
)
780 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
782 if (VLAN_ALLOWED(adapter
)) {
783 i40evf_del_vlan(adapter
, vid
);
790 * i40evf_find_filter - Search filter list for specific mac filter
791 * @adapter: board private structure
792 * @macaddr: the MAC address
794 * Returns ptr to the filter object or NULL
797 i40evf_mac_filter
*i40evf_find_filter(struct i40evf_adapter
*adapter
,
800 struct i40evf_mac_filter
*f
;
805 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
806 if (ether_addr_equal(macaddr
, f
->macaddr
))
813 * i40e_add_filter - Add a mac filter to the filter list
814 * @adapter: board private structure
815 * @macaddr: the MAC address
817 * Returns ptr to the filter object or NULL when no memory available.
820 i40evf_mac_filter
*i40evf_add_filter(struct i40evf_adapter
*adapter
,
823 struct i40evf_mac_filter
*f
;
829 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
830 &adapter
->crit_section
)) {
836 f
= i40evf_find_filter(adapter
, macaddr
);
838 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
840 clear_bit(__I40EVF_IN_CRITICAL_TASK
,
841 &adapter
->crit_section
);
845 ether_addr_copy(f
->macaddr
, macaddr
);
847 list_add(&f
->list
, &adapter
->mac_filter_list
);
849 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_MAC_FILTER
;
852 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
857 * i40evf_set_mac - NDO callback to set port mac address
858 * @netdev: network interface device structure
859 * @p: pointer to an address structure
861 * Returns 0 on success, negative on failure
863 static int i40evf_set_mac(struct net_device
*netdev
, void *p
)
865 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
866 struct i40e_hw
*hw
= &adapter
->hw
;
867 struct i40evf_mac_filter
*f
;
868 struct sockaddr
*addr
= p
;
870 if (!is_valid_ether_addr(addr
->sa_data
))
871 return -EADDRNOTAVAIL
;
873 if (ether_addr_equal(netdev
->dev_addr
, addr
->sa_data
))
876 if (adapter
->flags
& I40EVF_FLAG_ADDR_SET_BY_PF
)
879 f
= i40evf_find_filter(adapter
, hw
->mac
.addr
);
882 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
885 f
= i40evf_add_filter(adapter
, addr
->sa_data
);
887 ether_addr_copy(hw
->mac
.addr
, addr
->sa_data
);
888 ether_addr_copy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
);
891 return (f
== NULL
) ? -ENOMEM
: 0;
895 * i40evf_set_rx_mode - NDO callback to set the netdev filters
896 * @netdev: network interface device structure
898 static void i40evf_set_rx_mode(struct net_device
*netdev
)
900 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
901 struct i40evf_mac_filter
*f
, *ftmp
;
902 struct netdev_hw_addr
*uca
;
903 struct netdev_hw_addr
*mca
;
904 struct netdev_hw_addr
*ha
;
907 /* add addr if not already in the filter list */
908 netdev_for_each_uc_addr(uca
, netdev
) {
909 i40evf_add_filter(adapter
, uca
->addr
);
911 netdev_for_each_mc_addr(mca
, netdev
) {
912 i40evf_add_filter(adapter
, mca
->addr
);
915 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
916 &adapter
->crit_section
)) {
919 dev_err(&adapter
->pdev
->dev
,
920 "Failed to get lock in %s\n", __func__
);
924 /* remove filter if not in netdev list */
925 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
926 netdev_for_each_mc_addr(mca
, netdev
)
927 if (ether_addr_equal(mca
->addr
, f
->macaddr
))
928 goto bottom_of_search_loop
;
930 netdev_for_each_uc_addr(uca
, netdev
)
931 if (ether_addr_equal(uca
->addr
, f
->macaddr
))
932 goto bottom_of_search_loop
;
934 for_each_dev_addr(netdev
, ha
)
935 if (ether_addr_equal(ha
->addr
, f
->macaddr
))
936 goto bottom_of_search_loop
;
938 if (ether_addr_equal(f
->macaddr
, adapter
->hw
.mac
.addr
))
939 goto bottom_of_search_loop
;
941 /* f->macaddr wasn't found in uc, mc, or ha list so delete it */
943 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
945 bottom_of_search_loop
:
948 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
952 * i40evf_napi_enable_all - enable NAPI on all queue vectors
953 * @adapter: board private structure
955 static void i40evf_napi_enable_all(struct i40evf_adapter
*adapter
)
958 struct i40e_q_vector
*q_vector
;
959 int q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
961 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
962 struct napi_struct
*napi
;
964 q_vector
= &adapter
->q_vectors
[q_idx
];
965 napi
= &q_vector
->napi
;
971 * i40evf_napi_disable_all - disable NAPI on all queue vectors
972 * @adapter: board private structure
974 static void i40evf_napi_disable_all(struct i40evf_adapter
*adapter
)
977 struct i40e_q_vector
*q_vector
;
978 int q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
980 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
981 q_vector
= &adapter
->q_vectors
[q_idx
];
982 napi_disable(&q_vector
->napi
);
987 * i40evf_configure - set up transmit and receive data structures
988 * @adapter: board private structure
990 static void i40evf_configure(struct i40evf_adapter
*adapter
)
992 struct net_device
*netdev
= adapter
->netdev
;
995 i40evf_set_rx_mode(netdev
);
997 i40evf_configure_tx(adapter
);
998 i40evf_configure_rx(adapter
);
999 adapter
->aq_required
|= I40EVF_FLAG_AQ_CONFIGURE_QUEUES
;
1001 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
1002 struct i40e_ring
*ring
= &adapter
->rx_rings
[i
];
1004 i40evf_alloc_rx_buffers_1buf(ring
, ring
->count
);
1005 ring
->next_to_use
= ring
->count
- 1;
1006 writel(ring
->next_to_use
, ring
->tail
);
1011 * i40evf_up_complete - Finish the last steps of bringing up a connection
1012 * @adapter: board private structure
1014 static int i40evf_up_complete(struct i40evf_adapter
*adapter
)
1016 adapter
->state
= __I40EVF_RUNNING
;
1017 clear_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
1019 i40evf_napi_enable_all(adapter
);
1021 adapter
->aq_required
|= I40EVF_FLAG_AQ_ENABLE_QUEUES
;
1022 mod_timer_pending(&adapter
->watchdog_timer
, jiffies
+ 1);
1027 * i40e_down - Shutdown the connection processing
1028 * @adapter: board private structure
1030 void i40evf_down(struct i40evf_adapter
*adapter
)
1032 struct net_device
*netdev
= adapter
->netdev
;
1033 struct i40evf_mac_filter
*f
;
1035 if (adapter
->state
== __I40EVF_DOWN
)
1038 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
1039 &adapter
->crit_section
))
1040 usleep_range(500, 1000);
1042 netif_carrier_off(netdev
);
1043 netif_tx_disable(netdev
);
1044 i40evf_napi_disable_all(adapter
);
1045 i40evf_irq_disable(adapter
);
1047 /* remove all MAC filters */
1048 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
1051 /* remove all VLAN filters */
1052 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
1055 if (!(adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
) &&
1056 adapter
->state
!= __I40EVF_RESETTING
) {
1057 /* cancel any current operation */
1058 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
1059 /* Schedule operations to close down the HW. Don't wait
1060 * here for this to complete. The watchdog is still running
1061 * and it will take care of this.
1063 adapter
->aq_required
= I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
1064 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_VLAN_FILTER
;
1065 adapter
->aq_required
|= I40EVF_FLAG_AQ_DISABLE_QUEUES
;
1068 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1072 * i40evf_acquire_msix_vectors - Setup the MSIX capability
1073 * @adapter: board private structure
1074 * @vectors: number of vectors to request
1076 * Work with the OS to set up the MSIX vectors needed.
1078 * Returns 0 on success, negative on failure
1081 i40evf_acquire_msix_vectors(struct i40evf_adapter
*adapter
, int vectors
)
1083 int err
, vector_threshold
;
1085 /* We'll want at least 3 (vector_threshold):
1086 * 0) Other (Admin Queue and link, mostly)
1090 vector_threshold
= MIN_MSIX_COUNT
;
1092 /* The more we get, the more we will assign to Tx/Rx Cleanup
1093 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1094 * Right now, we simply care about how many we'll get; we'll
1095 * set them up later while requesting irq's.
1097 err
= pci_enable_msix_range(adapter
->pdev
, adapter
->msix_entries
,
1098 vector_threshold
, vectors
);
1100 dev_err(&adapter
->pdev
->dev
, "Unable to allocate MSI-X interrupts\n");
1101 kfree(adapter
->msix_entries
);
1102 adapter
->msix_entries
= NULL
;
1106 /* Adjust for only the vectors we'll use, which is minimum
1107 * of max_msix_q_vectors + NONQ_VECS, or the number of
1108 * vectors we were allocated.
1110 adapter
->num_msix_vectors
= err
;
1115 * i40evf_free_queues - Free memory for all rings
1116 * @adapter: board private structure to initialize
1118 * Free all of the memory associated with queue pairs.
1120 static void i40evf_free_queues(struct i40evf_adapter
*adapter
)
1122 if (!adapter
->vsi_res
)
1124 kfree(adapter
->tx_rings
);
1125 kfree(adapter
->rx_rings
);
1129 * i40evf_alloc_queues - Allocate memory for all rings
1130 * @adapter: board private structure to initialize
1132 * We allocate one ring per queue at run-time since we don't know the
1133 * number of queues at compile-time. The polling_netdev array is
1134 * intended for Multiqueue, but should work fine with a single queue.
1136 static int i40evf_alloc_queues(struct i40evf_adapter
*adapter
)
1140 adapter
->tx_rings
= kcalloc(adapter
->num_active_queues
,
1141 sizeof(struct i40e_ring
), GFP_KERNEL
);
1142 if (!adapter
->tx_rings
)
1144 adapter
->rx_rings
= kcalloc(adapter
->num_active_queues
,
1145 sizeof(struct i40e_ring
), GFP_KERNEL
);
1146 if (!adapter
->rx_rings
)
1149 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
1150 struct i40e_ring
*tx_ring
;
1151 struct i40e_ring
*rx_ring
;
1153 tx_ring
= &adapter
->tx_rings
[i
];
1155 tx_ring
->queue_index
= i
;
1156 tx_ring
->netdev
= adapter
->netdev
;
1157 tx_ring
->dev
= &adapter
->pdev
->dev
;
1158 tx_ring
->count
= adapter
->tx_desc_count
;
1159 if (adapter
->flags
& I40E_FLAG_WB_ON_ITR_CAPABLE
)
1160 tx_ring
->flags
|= I40E_TXR_FLAGS_WB_ON_ITR
;
1162 rx_ring
= &adapter
->rx_rings
[i
];
1163 rx_ring
->queue_index
= i
;
1164 rx_ring
->netdev
= adapter
->netdev
;
1165 rx_ring
->dev
= &adapter
->pdev
->dev
;
1166 rx_ring
->count
= adapter
->rx_desc_count
;
1172 i40evf_free_queues(adapter
);
1177 * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
1178 * @adapter: board private structure to initialize
1180 * Attempt to configure the interrupts using the best available
1181 * capabilities of the hardware and the kernel.
1183 static int i40evf_set_interrupt_capability(struct i40evf_adapter
*adapter
)
1185 int vector
, v_budget
;
1189 if (!adapter
->vsi_res
) {
1193 pairs
= adapter
->num_active_queues
;
1195 /* It's easy to be greedy for MSI-X vectors, but it really
1196 * doesn't do us much good if we have a lot more vectors
1197 * than CPU's. So let's be conservative and only ask for
1198 * (roughly) twice the number of vectors as there are CPU's.
1200 v_budget
= min_t(int, pairs
, (int)(num_online_cpus() * 2)) + NONQ_VECS
;
1201 v_budget
= min_t(int, v_budget
, (int)adapter
->vf_res
->max_vectors
);
1203 adapter
->msix_entries
= kcalloc(v_budget
,
1204 sizeof(struct msix_entry
), GFP_KERNEL
);
1205 if (!adapter
->msix_entries
) {
1210 for (vector
= 0; vector
< v_budget
; vector
++)
1211 adapter
->msix_entries
[vector
].entry
= vector
;
1213 err
= i40evf_acquire_msix_vectors(adapter
, v_budget
);
1216 netif_set_real_num_rx_queues(adapter
->netdev
, pairs
);
1217 netif_set_real_num_tx_queues(adapter
->netdev
, pairs
);
1222 * i40e_config_rss_aq - Prepare for RSS using AQ commands
1223 * @vsi: vsi structure
1224 * @seed: RSS hash seed
1225 * @lut: Lookup table
1226 * @lut_size: Lookup table size
1228 * Return 0 on success, negative on failure
1230 static int i40evf_config_rss_aq(struct i40e_vsi
*vsi
, const u8
*seed
,
1231 u8
*lut
, u16 lut_size
)
1233 struct i40evf_adapter
*adapter
= vsi
->back
;
1234 struct i40e_hw
*hw
= &adapter
->hw
;
1240 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
1241 /* bail because we already have a command pending */
1242 dev_err(&adapter
->pdev
->dev
, "Cannot confiure RSS, command %d pending\n",
1243 adapter
->current_op
);
1248 struct i40e_aqc_get_set_rss_key_data
*rss_key
=
1249 (struct i40e_aqc_get_set_rss_key_data
*)seed
;
1250 ret
= i40evf_aq_set_rss_key(hw
, vsi
->id
, rss_key
);
1252 dev_err(&adapter
->pdev
->dev
, "Cannot set RSS key, err %s aq_err %s\n",
1253 i40evf_stat_str(hw
, ret
),
1254 i40evf_aq_str(hw
, hw
->aq
.asq_last_status
));
1260 ret
= i40evf_aq_set_rss_lut(hw
, vsi
->id
, false, lut
, lut_size
);
1262 dev_err(&adapter
->pdev
->dev
,
1263 "Cannot set RSS lut, err %s aq_err %s\n",
1264 i40evf_stat_str(hw
, ret
),
1265 i40evf_aq_str(hw
, hw
->aq
.asq_last_status
));
1274 * i40evf_config_rss_reg - Configure RSS keys and lut by writing registers
1275 * @vsi: Pointer to vsi structure
1276 * @seed: RSS hash seed
1277 * @lut: Lookup table
1278 * @lut_size: Lookup table size
1280 * Returns 0 on success, negative on failure
1282 static int i40evf_config_rss_reg(struct i40e_vsi
*vsi
, const u8
*seed
,
1283 const u8
*lut
, u16 lut_size
)
1285 struct i40evf_adapter
*adapter
= vsi
->back
;
1286 struct i40e_hw
*hw
= &adapter
->hw
;
1290 u32
*seed_dw
= (u32
*)seed
;
1292 for (i
= 0; i
<= I40E_VFQF_HKEY_MAX_INDEX
; i
++)
1293 wr32(hw
, I40E_VFQF_HKEY(i
), seed_dw
[i
]);
1297 u32
*lut_dw
= (u32
*)lut
;
1299 if (lut_size
!= I40EVF_HLUT_ARRAY_SIZE
)
1302 for (i
= 0; i
<= I40E_VFQF_HLUT_MAX_INDEX
; i
++)
1303 wr32(hw
, I40E_VFQF_HLUT(i
), lut_dw
[i
]);
1311 * * i40evf_get_rss_aq - Get RSS keys and lut by using AQ commands
1312 * @vsi: Pointer to vsi structure
1313 * @seed: RSS hash seed
1314 * @lut: Lookup table
1315 * @lut_size: Lookup table size
1317 * Return 0 on success, negative on failure
1319 static int i40evf_get_rss_aq(struct i40e_vsi
*vsi
, const u8
*seed
,
1320 u8
*lut
, u16 lut_size
)
1322 struct i40evf_adapter
*adapter
= vsi
->back
;
1323 struct i40e_hw
*hw
= &adapter
->hw
;
1327 ret
= i40evf_aq_get_rss_key(hw
, vsi
->id
,
1328 (struct i40e_aqc_get_set_rss_key_data
*)seed
);
1330 dev_err(&adapter
->pdev
->dev
,
1331 "Cannot get RSS key, err %s aq_err %s\n",
1332 i40evf_stat_str(hw
, ret
),
1333 i40evf_aq_str(hw
, hw
->aq
.asq_last_status
));
1339 ret
= i40evf_aq_get_rss_lut(hw
, vsi
->id
, seed
, lut
, lut_size
);
1341 dev_err(&adapter
->pdev
->dev
,
1342 "Cannot get RSS lut, err %s aq_err %s\n",
1343 i40evf_stat_str(hw
, ret
),
1344 i40evf_aq_str(hw
, hw
->aq
.asq_last_status
));
1353 * * i40evf_get_rss_reg - Get RSS keys and lut by reading registers
1354 * @vsi: Pointer to vsi structure
1355 * @seed: RSS hash seed
1356 * @lut: Lookup table
1357 * @lut_size: Lookup table size
1359 * Returns 0 on success, negative on failure
1361 static int i40evf_get_rss_reg(struct i40e_vsi
*vsi
, const u8
*seed
,
1362 const u8
*lut
, u16 lut_size
)
1364 struct i40evf_adapter
*adapter
= vsi
->back
;
1365 struct i40e_hw
*hw
= &adapter
->hw
;
1369 u32
*seed_dw
= (u32
*)seed
;
1371 for (i
= 0; i
<= I40E_VFQF_HKEY_MAX_INDEX
; i
++)
1372 seed_dw
[i
] = rd32(hw
, I40E_VFQF_HKEY(i
));
1376 u32
*lut_dw
= (u32
*)lut
;
1378 if (lut_size
!= I40EVF_HLUT_ARRAY_SIZE
)
1381 for (i
= 0; i
<= I40E_VFQF_HLUT_MAX_INDEX
; i
++)
1382 lut_dw
[i
] = rd32(hw
, I40E_VFQF_HLUT(i
));
1389 * i40evf_config_rss - Configure RSS keys and lut
1390 * @vsi: Pointer to vsi structure
1391 * @seed: RSS hash seed
1392 * @lut: Lookup table
1393 * @lut_size: Lookup table size
1395 * Returns 0 on success, negative on failure
1397 int i40evf_config_rss(struct i40e_vsi
*vsi
, const u8
*seed
,
1398 u8
*lut
, u16 lut_size
)
1400 struct i40evf_adapter
*adapter
= vsi
->back
;
1402 if (RSS_AQ(adapter
))
1403 return i40evf_config_rss_aq(vsi
, seed
, lut
, lut_size
);
1405 return i40evf_config_rss_reg(vsi
, seed
, lut
, lut_size
);
1409 * i40evf_get_rss - Get RSS keys and lut
1410 * @vsi: Pointer to vsi structure
1411 * @seed: RSS hash seed
1412 * @lut: Lookup table
1413 * @lut_size: Lookup table size
1415 * Returns 0 on success, negative on failure
1417 int i40evf_get_rss(struct i40e_vsi
*vsi
, const u8
*seed
, u8
*lut
, u16 lut_size
)
1419 struct i40evf_adapter
*adapter
= vsi
->back
;
1421 if (RSS_AQ(adapter
))
1422 return i40evf_get_rss_aq(vsi
, seed
, lut
, lut_size
);
1424 return i40evf_get_rss_reg(vsi
, seed
, lut
, lut_size
);
1428 * i40evf_fill_rss_lut - Fill the lut with default values
1429 * @lut: Lookup table to be filled with
1430 * @rss_table_size: Lookup table size
1431 * @rss_size: Range of queue number for hashing
1433 static void i40evf_fill_rss_lut(u8
*lut
, u16 rss_table_size
, u16 rss_size
)
1437 for (i
= 0; i
< rss_table_size
; i
++)
1438 lut
[i
] = i
% rss_size
;
1442 * i40evf_init_rss - Prepare for RSS
1443 * @adapter: board private structure
1445 * Return 0 on success, negative on failure
1447 static int i40evf_init_rss(struct i40evf_adapter
*adapter
)
1449 struct i40e_vsi
*vsi
= &adapter
->vsi
;
1450 struct i40e_hw
*hw
= &adapter
->hw
;
1451 u8 seed
[I40EVF_HKEY_ARRAY_SIZE
];
1456 /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
1457 hena
= I40E_DEFAULT_RSS_HENA
;
1458 wr32(hw
, I40E_VFQF_HENA(0), (u32
)hena
);
1459 wr32(hw
, I40E_VFQF_HENA(1), (u32
)(hena
>> 32));
1461 lut
= kzalloc(I40EVF_HLUT_ARRAY_SIZE
, GFP_KERNEL
);
1465 /* Use user configured lut if there is one, otherwise use default */
1466 if (vsi
->rss_lut_user
)
1467 memcpy(lut
, vsi
->rss_lut_user
, I40EVF_HLUT_ARRAY_SIZE
);
1469 i40evf_fill_rss_lut(lut
, I40EVF_HLUT_ARRAY_SIZE
,
1470 adapter
->num_active_queues
);
1472 /* Use user configured hash key if there is one, otherwise
1475 if (vsi
->rss_hkey_user
)
1476 memcpy(seed
, vsi
->rss_hkey_user
, I40EVF_HKEY_ARRAY_SIZE
);
1478 netdev_rss_key_fill((void *)seed
, I40EVF_HKEY_ARRAY_SIZE
);
1479 ret
= i40evf_config_rss(vsi
, seed
, lut
, I40EVF_HLUT_ARRAY_SIZE
);
1486 * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
1487 * @adapter: board private structure to initialize
1489 * We allocate one q_vector per queue interrupt. If allocation fails we
1492 static int i40evf_alloc_q_vectors(struct i40evf_adapter
*adapter
)
1494 int q_idx
= 0, num_q_vectors
;
1495 struct i40e_q_vector
*q_vector
;
1497 num_q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
1498 adapter
->q_vectors
= kcalloc(num_q_vectors
, sizeof(*q_vector
),
1500 if (!adapter
->q_vectors
)
1503 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
1504 q_vector
= &adapter
->q_vectors
[q_idx
];
1505 q_vector
->adapter
= adapter
;
1506 q_vector
->vsi
= &adapter
->vsi
;
1507 q_vector
->v_idx
= q_idx
;
1508 netif_napi_add(adapter
->netdev
, &q_vector
->napi
,
1509 i40evf_napi_poll
, NAPI_POLL_WEIGHT
);
1517 q_vector
= &adapter
->q_vectors
[q_idx
];
1518 netif_napi_del(&q_vector
->napi
);
1520 kfree(adapter
->q_vectors
);
1525 * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
1526 * @adapter: board private structure to initialize
1528 * This function frees the memory allocated to the q_vectors. In addition if
1529 * NAPI is enabled it will delete any references to the NAPI struct prior
1530 * to freeing the q_vector.
1532 static void i40evf_free_q_vectors(struct i40evf_adapter
*adapter
)
1534 int q_idx
, num_q_vectors
;
1537 num_q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
1538 napi_vectors
= adapter
->num_active_queues
;
1540 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
1541 struct i40e_q_vector
*q_vector
= &adapter
->q_vectors
[q_idx
];
1542 if (q_idx
< napi_vectors
)
1543 netif_napi_del(&q_vector
->napi
);
1545 kfree(adapter
->q_vectors
);
1549 * i40evf_reset_interrupt_capability - Reset MSIX setup
1550 * @adapter: board private structure
1553 void i40evf_reset_interrupt_capability(struct i40evf_adapter
*adapter
)
1555 pci_disable_msix(adapter
->pdev
);
1556 kfree(adapter
->msix_entries
);
1557 adapter
->msix_entries
= NULL
;
1561 * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
1562 * @adapter: board private structure to initialize
1565 int i40evf_init_interrupt_scheme(struct i40evf_adapter
*adapter
)
1569 err
= i40evf_set_interrupt_capability(adapter
);
1571 dev_err(&adapter
->pdev
->dev
,
1572 "Unable to setup interrupt capabilities\n");
1573 goto err_set_interrupt
;
1576 err
= i40evf_alloc_q_vectors(adapter
);
1578 dev_err(&adapter
->pdev
->dev
,
1579 "Unable to allocate memory for queue vectors\n");
1580 goto err_alloc_q_vectors
;
1583 err
= i40evf_alloc_queues(adapter
);
1585 dev_err(&adapter
->pdev
->dev
,
1586 "Unable to allocate memory for queues\n");
1587 goto err_alloc_queues
;
1590 dev_info(&adapter
->pdev
->dev
, "Multiqueue %s: Queue pair count = %u",
1591 (adapter
->num_active_queues
> 1) ? "Enabled" : "Disabled",
1592 adapter
->num_active_queues
);
1596 i40evf_free_q_vectors(adapter
);
1597 err_alloc_q_vectors
:
1598 i40evf_reset_interrupt_capability(adapter
);
1604 * i40evf_clear_rss_config_user - Clear user configurations of RSS
1605 * @vsi: Pointer to VSI structure
1607 static void i40evf_clear_rss_config_user(struct i40e_vsi
*vsi
)
1612 kfree(vsi
->rss_hkey_user
);
1613 vsi
->rss_hkey_user
= NULL
;
1615 kfree(vsi
->rss_lut_user
);
1616 vsi
->rss_lut_user
= NULL
;
1620 * i40evf_watchdog_timer - Periodic call-back timer
1621 * @data: pointer to adapter disguised as unsigned long
1623 static void i40evf_watchdog_timer(unsigned long data
)
1625 struct i40evf_adapter
*adapter
= (struct i40evf_adapter
*)data
;
1627 schedule_work(&adapter
->watchdog_task
);
1628 /* timer will be rescheduled in watchdog task */
1632 * i40evf_watchdog_task - Periodic call-back task
1633 * @work: pointer to work_struct
1635 static void i40evf_watchdog_task(struct work_struct
*work
)
1637 struct i40evf_adapter
*adapter
= container_of(work
,
1638 struct i40evf_adapter
,
1640 struct i40e_hw
*hw
= &adapter
->hw
;
1643 if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
))
1644 goto restart_watchdog
;
1646 if (adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
) {
1647 reg_val
= rd32(hw
, I40E_VFGEN_RSTAT
) &
1648 I40E_VFGEN_RSTAT_VFR_STATE_MASK
;
1649 if ((reg_val
== I40E_VFR_VFACTIVE
) ||
1650 (reg_val
== I40E_VFR_COMPLETED
)) {
1651 /* A chance for redemption! */
1652 dev_err(&adapter
->pdev
->dev
, "Hardware came out of reset. Attempting reinit.\n");
1653 adapter
->state
= __I40EVF_STARTUP
;
1654 adapter
->flags
&= ~I40EVF_FLAG_PF_COMMS_FAILED
;
1655 schedule_delayed_work(&adapter
->init_task
, 10);
1656 clear_bit(__I40EVF_IN_CRITICAL_TASK
,
1657 &adapter
->crit_section
);
1658 /* Don't reschedule the watchdog, since we've restarted
1659 * the init task. When init_task contacts the PF and
1660 * gets everything set up again, it'll restart the
1661 * watchdog for us. Down, boy. Sit. Stay. Woof.
1665 adapter
->aq_required
= 0;
1666 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
1670 if ((adapter
->state
< __I40EVF_DOWN
) ||
1671 (adapter
->flags
& I40EVF_FLAG_RESET_PENDING
))
1674 /* check for reset */
1675 reg_val
= rd32(hw
, I40E_VF_ARQLEN1
) & I40E_VF_ARQLEN1_ARQENABLE_MASK
;
1676 if (!(adapter
->flags
& I40EVF_FLAG_RESET_PENDING
) && !reg_val
) {
1677 adapter
->state
= __I40EVF_RESETTING
;
1678 adapter
->flags
|= I40EVF_FLAG_RESET_PENDING
;
1679 dev_err(&adapter
->pdev
->dev
, "Hardware reset detected\n");
1680 schedule_work(&adapter
->reset_task
);
1681 adapter
->aq_required
= 0;
1682 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
1686 /* Process admin queue tasks. After init, everything gets done
1687 * here so we don't race on the admin queue.
1689 if (adapter
->current_op
) {
1690 if (!i40evf_asq_done(hw
)) {
1691 dev_dbg(&adapter
->pdev
->dev
, "Admin queue timeout\n");
1692 i40evf_send_api_ver(adapter
);
1696 if (adapter
->aq_required
& I40EVF_FLAG_AQ_GET_CONFIG
) {
1697 i40evf_send_vf_config_msg(adapter
);
1701 if (adapter
->aq_required
& I40EVF_FLAG_AQ_DISABLE_QUEUES
) {
1702 i40evf_disable_queues(adapter
);
1706 if (adapter
->aq_required
& I40EVF_FLAG_AQ_MAP_VECTORS
) {
1707 i40evf_map_queues(adapter
);
1711 if (adapter
->aq_required
& I40EVF_FLAG_AQ_ADD_MAC_FILTER
) {
1712 i40evf_add_ether_addrs(adapter
);
1716 if (adapter
->aq_required
& I40EVF_FLAG_AQ_ADD_VLAN_FILTER
) {
1717 i40evf_add_vlans(adapter
);
1721 if (adapter
->aq_required
& I40EVF_FLAG_AQ_DEL_MAC_FILTER
) {
1722 i40evf_del_ether_addrs(adapter
);
1726 if (adapter
->aq_required
& I40EVF_FLAG_AQ_DEL_VLAN_FILTER
) {
1727 i40evf_del_vlans(adapter
);
1731 if (adapter
->aq_required
& I40EVF_FLAG_AQ_CONFIGURE_QUEUES
) {
1732 i40evf_configure_queues(adapter
);
1736 if (adapter
->aq_required
& I40EVF_FLAG_AQ_ENABLE_QUEUES
) {
1737 i40evf_enable_queues(adapter
);
1741 if (adapter
->aq_required
& I40EVF_FLAG_AQ_CONFIGURE_RSS
) {
1742 /* This message goes straight to the firmware, not the
1743 * PF, so we don't have to set current_op as we will
1744 * not get a response through the ARQ.
1746 i40evf_init_rss(adapter
);
1747 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_CONFIGURE_RSS
;
1751 if (adapter
->state
== __I40EVF_RUNNING
)
1752 i40evf_request_stats(adapter
);
1754 if (adapter
->state
== __I40EVF_RUNNING
) {
1755 i40evf_irq_enable_queues(adapter
, ~0);
1756 i40evf_fire_sw_int(adapter
, 0xFF);
1758 i40evf_fire_sw_int(adapter
, 0x1);
1761 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1763 if (adapter
->state
== __I40EVF_REMOVE
)
1765 if (adapter
->aq_required
)
1766 mod_timer(&adapter
->watchdog_timer
,
1767 jiffies
+ msecs_to_jiffies(20));
1769 mod_timer(&adapter
->watchdog_timer
, jiffies
+ (HZ
* 2));
1770 schedule_work(&adapter
->adminq_task
);
1773 #define I40EVF_RESET_WAIT_MS 10
1774 #define I40EVF_RESET_WAIT_COUNT 500
1776 * i40evf_reset_task - Call-back task to handle hardware reset
1777 * @work: pointer to work_struct
1779 * During reset we need to shut down and reinitialize the admin queue
1780 * before we can use it to communicate with the PF again. We also clear
1781 * and reinit the rings because that context is lost as well.
1783 static void i40evf_reset_task(struct work_struct
*work
)
1785 struct i40evf_adapter
*adapter
= container_of(work
,
1786 struct i40evf_adapter
,
1788 struct net_device
*netdev
= adapter
->netdev
;
1789 struct i40e_hw
*hw
= &adapter
->hw
;
1790 struct i40evf_vlan_filter
*vlf
;
1791 struct i40evf_mac_filter
*f
;
1795 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
1796 &adapter
->crit_section
))
1797 usleep_range(500, 1000);
1799 i40evf_misc_irq_disable(adapter
);
1800 if (adapter
->flags
& I40EVF_FLAG_RESET_NEEDED
) {
1801 adapter
->flags
&= ~I40EVF_FLAG_RESET_NEEDED
;
1802 /* Restart the AQ here. If we have been reset but didn't
1803 * detect it, or if the PF had to reinit, our AQ will be hosed.
1805 i40evf_shutdown_adminq(hw
);
1806 i40evf_init_adminq(hw
);
1807 i40evf_request_reset(adapter
);
1809 adapter
->flags
|= I40EVF_FLAG_RESET_PENDING
;
1811 /* poll until we see the reset actually happen */
1812 for (i
= 0; i
< I40EVF_RESET_WAIT_COUNT
; i
++) {
1813 reg_val
= rd32(hw
, I40E_VF_ARQLEN1
) &
1814 I40E_VF_ARQLEN1_ARQENABLE_MASK
;
1817 usleep_range(5000, 10000);
1819 if (i
== I40EVF_RESET_WAIT_COUNT
) {
1820 dev_info(&adapter
->pdev
->dev
, "Never saw reset\n");
1821 goto continue_reset
; /* act like the reset happened */
1824 /* wait until the reset is complete and the PF is responding to us */
1825 for (i
= 0; i
< I40EVF_RESET_WAIT_COUNT
; i
++) {
1826 reg_val
= rd32(hw
, I40E_VFGEN_RSTAT
) &
1827 I40E_VFGEN_RSTAT_VFR_STATE_MASK
;
1828 if (reg_val
== I40E_VFR_VFACTIVE
)
1830 msleep(I40EVF_RESET_WAIT_MS
);
1832 /* extra wait to make sure minimum wait is met */
1833 msleep(I40EVF_RESET_WAIT_MS
);
1834 if (i
== I40EVF_RESET_WAIT_COUNT
) {
1835 struct i40evf_mac_filter
*ftmp
;
1836 struct i40evf_vlan_filter
*fv
, *fvtmp
;
1838 /* reset never finished */
1839 dev_err(&adapter
->pdev
->dev
, "Reset never finished (%x)\n",
1841 adapter
->flags
|= I40EVF_FLAG_PF_COMMS_FAILED
;
1843 if (netif_running(adapter
->netdev
)) {
1844 set_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
1845 netif_carrier_off(netdev
);
1846 netif_tx_disable(netdev
);
1847 i40evf_napi_disable_all(adapter
);
1848 i40evf_irq_disable(adapter
);
1849 i40evf_free_traffic_irqs(adapter
);
1850 i40evf_free_all_tx_resources(adapter
);
1851 i40evf_free_all_rx_resources(adapter
);
1854 /* Delete all of the filters, both MAC and VLAN. */
1855 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
,
1861 list_for_each_entry_safe(fv
, fvtmp
, &adapter
->vlan_filter_list
,
1863 list_del(&fv
->list
);
1867 i40evf_free_misc_irq(adapter
);
1868 i40evf_reset_interrupt_capability(adapter
);
1869 i40evf_free_queues(adapter
);
1870 i40evf_free_q_vectors(adapter
);
1871 kfree(adapter
->vf_res
);
1872 i40evf_shutdown_adminq(hw
);
1873 adapter
->netdev
->flags
&= ~IFF_UP
;
1874 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1875 adapter
->flags
&= ~I40EVF_FLAG_RESET_PENDING
;
1876 dev_info(&adapter
->pdev
->dev
, "Reset task did not complete, VF disabled\n");
1877 return; /* Do not attempt to reinit. It's dead, Jim. */
1881 if (netif_running(adapter
->netdev
)) {
1882 netif_carrier_off(netdev
);
1883 netif_tx_stop_all_queues(netdev
);
1884 i40evf_napi_disable_all(adapter
);
1886 i40evf_irq_disable(adapter
);
1888 adapter
->state
= __I40EVF_RESETTING
;
1889 adapter
->flags
&= ~I40EVF_FLAG_RESET_PENDING
;
1891 /* free the Tx/Rx rings and descriptors, might be better to just
1892 * re-use them sometime in the future
1894 i40evf_free_all_rx_resources(adapter
);
1895 i40evf_free_all_tx_resources(adapter
);
1897 /* kill and reinit the admin queue */
1898 if (i40evf_shutdown_adminq(hw
))
1899 dev_warn(&adapter
->pdev
->dev
, "Failed to shut down adminq\n");
1900 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
1901 err
= i40evf_init_adminq(hw
);
1903 dev_info(&adapter
->pdev
->dev
, "Failed to init adminq: %d\n",
1906 adapter
->aq_required
= I40EVF_FLAG_AQ_GET_CONFIG
;
1907 adapter
->aq_required
|= I40EVF_FLAG_AQ_MAP_VECTORS
;
1909 /* re-add all MAC filters */
1910 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
1913 /* re-add all VLAN filters */
1914 list_for_each_entry(vlf
, &adapter
->vlan_filter_list
, list
) {
1917 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_MAC_FILTER
;
1918 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_VLAN_FILTER
;
1919 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1920 i40evf_misc_irq_enable(adapter
);
1922 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 2);
1924 if (netif_running(adapter
->netdev
)) {
1925 /* allocate transmit descriptors */
1926 err
= i40evf_setup_all_tx_resources(adapter
);
1930 /* allocate receive descriptors */
1931 err
= i40evf_setup_all_rx_resources(adapter
);
1935 i40evf_configure(adapter
);
1937 err
= i40evf_up_complete(adapter
);
1941 i40evf_irq_enable(adapter
, true);
1943 adapter
->state
= __I40EVF_DOWN
;
1948 dev_err(&adapter
->pdev
->dev
, "failed to allocate resources during reinit\n");
1949 i40evf_close(adapter
->netdev
);
1953 * i40evf_adminq_task - worker thread to clean the admin queue
1954 * @work: pointer to work_struct containing our data
1956 static void i40evf_adminq_task(struct work_struct
*work
)
1958 struct i40evf_adapter
*adapter
=
1959 container_of(work
, struct i40evf_adapter
, adminq_task
);
1960 struct i40e_hw
*hw
= &adapter
->hw
;
1961 struct i40e_arq_event_info event
;
1962 struct i40e_virtchnl_msg
*v_msg
;
1967 if (adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
)
1970 event
.buf_len
= I40EVF_MAX_AQ_BUF_SIZE
;
1971 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
1975 v_msg
= (struct i40e_virtchnl_msg
*)&event
.desc
;
1977 ret
= i40evf_clean_arq_element(hw
, &event
, &pending
);
1978 if (ret
|| !v_msg
->v_opcode
)
1979 break; /* No event to process or error cleaning ARQ */
1981 i40evf_virtchnl_completion(adapter
, v_msg
->v_opcode
,
1982 v_msg
->v_retval
, event
.msg_buf
,
1985 memset(event
.msg_buf
, 0, I40EVF_MAX_AQ_BUF_SIZE
);
1988 if ((adapter
->flags
&
1989 (I40EVF_FLAG_RESET_PENDING
| I40EVF_FLAG_RESET_NEEDED
)) ||
1990 adapter
->state
== __I40EVF_RESETTING
)
1993 /* check for error indications */
1994 val
= rd32(hw
, hw
->aq
.arq
.len
);
1996 if (val
& I40E_VF_ARQLEN1_ARQVFE_MASK
) {
1997 dev_info(&adapter
->pdev
->dev
, "ARQ VF Error detected\n");
1998 val
&= ~I40E_VF_ARQLEN1_ARQVFE_MASK
;
2000 if (val
& I40E_VF_ARQLEN1_ARQOVFL_MASK
) {
2001 dev_info(&adapter
->pdev
->dev
, "ARQ Overflow Error detected\n");
2002 val
&= ~I40E_VF_ARQLEN1_ARQOVFL_MASK
;
2004 if (val
& I40E_VF_ARQLEN1_ARQCRIT_MASK
) {
2005 dev_info(&adapter
->pdev
->dev
, "ARQ Critical Error detected\n");
2006 val
&= ~I40E_VF_ARQLEN1_ARQCRIT_MASK
;
2009 wr32(hw
, hw
->aq
.arq
.len
, val
);
2011 val
= rd32(hw
, hw
->aq
.asq
.len
);
2013 if (val
& I40E_VF_ATQLEN1_ATQVFE_MASK
) {
2014 dev_info(&adapter
->pdev
->dev
, "ASQ VF Error detected\n");
2015 val
&= ~I40E_VF_ATQLEN1_ATQVFE_MASK
;
2017 if (val
& I40E_VF_ATQLEN1_ATQOVFL_MASK
) {
2018 dev_info(&adapter
->pdev
->dev
, "ASQ Overflow Error detected\n");
2019 val
&= ~I40E_VF_ATQLEN1_ATQOVFL_MASK
;
2021 if (val
& I40E_VF_ATQLEN1_ATQCRIT_MASK
) {
2022 dev_info(&adapter
->pdev
->dev
, "ASQ Critical Error detected\n");
2023 val
&= ~I40E_VF_ATQLEN1_ATQCRIT_MASK
;
2026 wr32(hw
, hw
->aq
.asq
.len
, val
);
2029 kfree(event
.msg_buf
);
2031 /* re-enable Admin queue interrupt cause */
2032 i40evf_misc_irq_enable(adapter
);
2036 * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
2037 * @adapter: board private structure
2039 * Free all transmit software resources
2041 void i40evf_free_all_tx_resources(struct i40evf_adapter
*adapter
)
2045 if (!adapter
->tx_rings
)
2048 for (i
= 0; i
< adapter
->num_active_queues
; i
++)
2049 if (adapter
->tx_rings
[i
].desc
)
2050 i40evf_free_tx_resources(&adapter
->tx_rings
[i
]);
2054 * i40evf_setup_all_tx_resources - allocate all queues Tx resources
2055 * @adapter: board private structure
2057 * If this function returns with an error, then it's possible one or
2058 * more of the rings is populated (while the rest are not). It is the
2059 * callers duty to clean those orphaned rings.
2061 * Return 0 on success, negative on failure
2063 static int i40evf_setup_all_tx_resources(struct i40evf_adapter
*adapter
)
2067 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
2068 adapter
->tx_rings
[i
].count
= adapter
->tx_desc_count
;
2069 err
= i40evf_setup_tx_descriptors(&adapter
->tx_rings
[i
]);
2072 dev_err(&adapter
->pdev
->dev
,
2073 "Allocation for Tx Queue %u failed\n", i
);
2081 * i40evf_setup_all_rx_resources - allocate all queues Rx resources
2082 * @adapter: board private structure
2084 * If this function returns with an error, then it's possible one or
2085 * more of the rings is populated (while the rest are not). It is the
2086 * callers duty to clean those orphaned rings.
2088 * Return 0 on success, negative on failure
2090 static int i40evf_setup_all_rx_resources(struct i40evf_adapter
*adapter
)
2094 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
2095 adapter
->rx_rings
[i
].count
= adapter
->rx_desc_count
;
2096 err
= i40evf_setup_rx_descriptors(&adapter
->rx_rings
[i
]);
2099 dev_err(&adapter
->pdev
->dev
,
2100 "Allocation for Rx Queue %u failed\n", i
);
2107 * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
2108 * @adapter: board private structure
2110 * Free all receive software resources
2112 void i40evf_free_all_rx_resources(struct i40evf_adapter
*adapter
)
2116 if (!adapter
->rx_rings
)
2119 for (i
= 0; i
< adapter
->num_active_queues
; i
++)
2120 if (adapter
->rx_rings
[i
].desc
)
2121 i40evf_free_rx_resources(&adapter
->rx_rings
[i
]);
2125 * i40evf_open - Called when a network interface is made active
2126 * @netdev: network interface device structure
2128 * Returns 0 on success, negative value on failure
2130 * The open entry point is called when a network interface is made
2131 * active by the system (IFF_UP). At this point all resources needed
2132 * for transmit and receive operations are allocated, the interrupt
2133 * handler is registered with the OS, the watchdog timer is started,
2134 * and the stack is notified that the interface is ready.
2136 static int i40evf_open(struct net_device
*netdev
)
2138 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2141 if (adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
) {
2142 dev_err(&adapter
->pdev
->dev
, "Unable to open device due to PF driver failure.\n");
2145 if (adapter
->state
!= __I40EVF_DOWN
|| adapter
->aq_required
)
2148 /* allocate transmit descriptors */
2149 err
= i40evf_setup_all_tx_resources(adapter
);
2153 /* allocate receive descriptors */
2154 err
= i40evf_setup_all_rx_resources(adapter
);
2158 /* clear any pending interrupts, may auto mask */
2159 err
= i40evf_request_traffic_irqs(adapter
, netdev
->name
);
2163 i40evf_add_filter(adapter
, adapter
->hw
.mac
.addr
);
2164 i40evf_configure(adapter
);
2166 err
= i40evf_up_complete(adapter
);
2170 i40evf_irq_enable(adapter
, true);
2175 i40evf_down(adapter
);
2176 i40evf_free_traffic_irqs(adapter
);
2178 i40evf_free_all_rx_resources(adapter
);
2180 i40evf_free_all_tx_resources(adapter
);
2186 * i40evf_close - Disables a network interface
2187 * @netdev: network interface device structure
2189 * Returns 0, this is not allowed to fail
2191 * The close entry point is called when an interface is de-activated
2192 * by the OS. The hardware is still under the drivers control, but
2193 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
2194 * are freed, along with all transmit and receive resources.
2196 static int i40evf_close(struct net_device
*netdev
)
2198 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2200 if (adapter
->state
<= __I40EVF_DOWN
)
2204 set_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
2206 i40evf_down(adapter
);
2207 adapter
->state
= __I40EVF_DOWN
;
2208 i40evf_free_traffic_irqs(adapter
);
2214 * i40evf_get_stats - Get System Network Statistics
2215 * @netdev: network interface device structure
2217 * Returns the address of the device statistics structure.
2218 * The statistics are actually updated from the timer callback.
2220 static struct net_device_stats
*i40evf_get_stats(struct net_device
*netdev
)
2222 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2224 /* only return the current stats */
2225 return &adapter
->net_stats
;
2229 * i40evf_change_mtu - Change the Maximum Transfer Unit
2230 * @netdev: network interface device structure
2231 * @new_mtu: new value for maximum frame size
2233 * Returns 0 on success, negative on failure
2235 static int i40evf_change_mtu(struct net_device
*netdev
, int new_mtu
)
2237 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2238 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
2240 if ((new_mtu
< 68) || (max_frame
> I40E_MAX_RXBUFFER
))
2243 netdev
->mtu
= new_mtu
;
2244 adapter
->flags
|= I40EVF_FLAG_RESET_NEEDED
;
2245 schedule_work(&adapter
->reset_task
);
2250 static const struct net_device_ops i40evf_netdev_ops
= {
2251 .ndo_open
= i40evf_open
,
2252 .ndo_stop
= i40evf_close
,
2253 .ndo_start_xmit
= i40evf_xmit_frame
,
2254 .ndo_get_stats
= i40evf_get_stats
,
2255 .ndo_set_rx_mode
= i40evf_set_rx_mode
,
2256 .ndo_validate_addr
= eth_validate_addr
,
2257 .ndo_set_mac_address
= i40evf_set_mac
,
2258 .ndo_change_mtu
= i40evf_change_mtu
,
2259 .ndo_tx_timeout
= i40evf_tx_timeout
,
2260 .ndo_vlan_rx_add_vid
= i40evf_vlan_rx_add_vid
,
2261 .ndo_vlan_rx_kill_vid
= i40evf_vlan_rx_kill_vid
,
2262 #ifdef CONFIG_NET_POLL_CONTROLLER
2263 .ndo_poll_controller
= i40evf_netpoll
,
2268 * i40evf_check_reset_complete - check that VF reset is complete
2269 * @hw: pointer to hw struct
2271 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
2273 static int i40evf_check_reset_complete(struct i40e_hw
*hw
)
2278 for (i
= 0; i
< 100; i
++) {
2279 rstat
= rd32(hw
, I40E_VFGEN_RSTAT
) &
2280 I40E_VFGEN_RSTAT_VFR_STATE_MASK
;
2281 if ((rstat
== I40E_VFR_VFACTIVE
) ||
2282 (rstat
== I40E_VFR_COMPLETED
))
2284 usleep_range(10, 20);
2290 * i40evf_process_config - Process the config information we got from the PF
2291 * @adapter: board private structure
2293 * Verify that we have a valid config struct, and set up our netdev features
2294 * and our VSI struct.
2296 int i40evf_process_config(struct i40evf_adapter
*adapter
)
2298 struct net_device
*netdev
= adapter
->netdev
;
2301 /* got VF config message back from PF, now we can parse it */
2302 for (i
= 0; i
< adapter
->vf_res
->num_vsis
; i
++) {
2303 if (adapter
->vf_res
->vsi_res
[i
].vsi_type
== I40E_VSI_SRIOV
)
2304 adapter
->vsi_res
= &adapter
->vf_res
->vsi_res
[i
];
2306 if (!adapter
->vsi_res
) {
2307 dev_err(&adapter
->pdev
->dev
, "No LAN VSI found\n");
2311 if (adapter
->vf_res
->vf_offload_flags
2312 & I40E_VIRTCHNL_VF_OFFLOAD_VLAN
) {
2313 netdev
->vlan_features
= netdev
->features
&
2314 ~(NETIF_F_HW_VLAN_CTAG_TX
|
2315 NETIF_F_HW_VLAN_CTAG_RX
|
2316 NETIF_F_HW_VLAN_CTAG_FILTER
);
2317 netdev
->features
|= NETIF_F_HW_VLAN_CTAG_TX
|
2318 NETIF_F_HW_VLAN_CTAG_RX
|
2319 NETIF_F_HW_VLAN_CTAG_FILTER
;
2321 netdev
->features
|= NETIF_F_HIGHDMA
|
2331 /* copy netdev features into list of user selectable features */
2332 netdev
->hw_features
|= netdev
->features
;
2333 netdev
->hw_features
&= ~NETIF_F_RXCSUM
;
2335 adapter
->vsi
.id
= adapter
->vsi_res
->vsi_id
;
2337 adapter
->vsi
.back
= adapter
;
2338 adapter
->vsi
.base_vector
= 1;
2339 adapter
->vsi
.work_limit
= I40E_DEFAULT_IRQ_WORK
;
2340 adapter
->vsi
.rx_itr_setting
= (I40E_ITR_DYNAMIC
|
2341 ITR_REG_TO_USEC(I40E_ITR_RX_DEF
));
2342 adapter
->vsi
.tx_itr_setting
= (I40E_ITR_DYNAMIC
|
2343 ITR_REG_TO_USEC(I40E_ITR_TX_DEF
));
2344 adapter
->vsi
.netdev
= adapter
->netdev
;
2345 adapter
->vsi
.qs_handle
= adapter
->vsi_res
->qset_handle
;
2350 * i40evf_init_task - worker thread to perform delayed initialization
2351 * @work: pointer to work_struct containing our data
2353 * This task completes the work that was begun in probe. Due to the nature
2354 * of VF-PF communications, we may need to wait tens of milliseconds to get
2355 * responses back from the PF. Rather than busy-wait in probe and bog down the
2356 * whole system, we'll do it in a task so we can sleep.
2357 * This task only runs during driver init. Once we've established
2358 * communications with the PF driver and set up our netdev, the watchdog
2361 static void i40evf_init_task(struct work_struct
*work
)
2363 struct i40evf_adapter
*adapter
= container_of(work
,
2364 struct i40evf_adapter
,
2366 struct net_device
*netdev
= adapter
->netdev
;
2367 struct i40e_hw
*hw
= &adapter
->hw
;
2368 struct pci_dev
*pdev
= adapter
->pdev
;
2371 switch (adapter
->state
) {
2372 case __I40EVF_STARTUP
:
2373 /* driver loaded, probe complete */
2374 adapter
->flags
&= ~I40EVF_FLAG_PF_COMMS_FAILED
;
2375 adapter
->flags
&= ~I40EVF_FLAG_RESET_PENDING
;
2376 err
= i40e_set_mac_type(hw
);
2378 dev_err(&pdev
->dev
, "Failed to set MAC type (%d)\n",
2382 err
= i40evf_check_reset_complete(hw
);
2384 dev_info(&pdev
->dev
, "Device is still in reset (%d), retrying\n",
2388 hw
->aq
.num_arq_entries
= I40EVF_AQ_LEN
;
2389 hw
->aq
.num_asq_entries
= I40EVF_AQ_LEN
;
2390 hw
->aq
.arq_buf_size
= I40EVF_MAX_AQ_BUF_SIZE
;
2391 hw
->aq
.asq_buf_size
= I40EVF_MAX_AQ_BUF_SIZE
;
2393 err
= i40evf_init_adminq(hw
);
2395 dev_err(&pdev
->dev
, "Failed to init Admin Queue (%d)\n",
2399 err
= i40evf_send_api_ver(adapter
);
2401 dev_err(&pdev
->dev
, "Unable to send to PF (%d)\n", err
);
2402 i40evf_shutdown_adminq(hw
);
2405 adapter
->state
= __I40EVF_INIT_VERSION_CHECK
;
2407 case __I40EVF_INIT_VERSION_CHECK
:
2408 if (!i40evf_asq_done(hw
)) {
2409 dev_err(&pdev
->dev
, "Admin queue command never completed\n");
2410 i40evf_shutdown_adminq(hw
);
2411 adapter
->state
= __I40EVF_STARTUP
;
2415 /* aq msg sent, awaiting reply */
2416 err
= i40evf_verify_api_ver(adapter
);
2418 if (err
== I40E_ERR_ADMIN_QUEUE_NO_WORK
)
2419 err
= i40evf_send_api_ver(adapter
);
2421 dev_err(&pdev
->dev
, "Unsupported PF API version %d.%d, expected %d.%d\n",
2422 adapter
->pf_version
.major
,
2423 adapter
->pf_version
.minor
,
2424 I40E_VIRTCHNL_VERSION_MAJOR
,
2425 I40E_VIRTCHNL_VERSION_MINOR
);
2428 err
= i40evf_send_vf_config_msg(adapter
);
2430 dev_err(&pdev
->dev
, "Unable to send config request (%d)\n",
2434 adapter
->state
= __I40EVF_INIT_GET_RESOURCES
;
2436 case __I40EVF_INIT_GET_RESOURCES
:
2437 /* aq msg sent, awaiting reply */
2438 if (!adapter
->vf_res
) {
2439 bufsz
= sizeof(struct i40e_virtchnl_vf_resource
) +
2441 sizeof(struct i40e_virtchnl_vsi_resource
));
2442 adapter
->vf_res
= kzalloc(bufsz
, GFP_KERNEL
);
2443 if (!adapter
->vf_res
)
2446 err
= i40evf_get_vf_config(adapter
);
2447 if (err
== I40E_ERR_ADMIN_QUEUE_NO_WORK
) {
2448 err
= i40evf_send_vf_config_msg(adapter
);
2450 } else if (err
== I40E_ERR_PARAM
) {
2451 /* We only get ERR_PARAM if the device is in a very bad
2452 * state or if we've been disabled for previous bad
2453 * behavior. Either way, we're done now.
2455 i40evf_shutdown_adminq(hw
);
2456 dev_err(&pdev
->dev
, "Unable to get VF config due to PF error condition, not retrying\n");
2460 dev_err(&pdev
->dev
, "Unable to get VF config (%d)\n",
2464 adapter
->state
= __I40EVF_INIT_SW
;
2469 if (i40evf_process_config(adapter
))
2471 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
2473 adapter
->flags
|= I40EVF_FLAG_RX_CSUM_ENABLED
;
2475 netdev
->netdev_ops
= &i40evf_netdev_ops
;
2476 i40evf_set_ethtool_ops(netdev
);
2477 netdev
->watchdog_timeo
= 5 * HZ
;
2479 if (!is_valid_ether_addr(adapter
->hw
.mac
.addr
)) {
2480 dev_info(&pdev
->dev
, "Invalid MAC address %pM, using random\n",
2481 adapter
->hw
.mac
.addr
);
2482 eth_hw_addr_random(netdev
);
2483 ether_addr_copy(adapter
->hw
.mac
.addr
, netdev
->dev_addr
);
2485 adapter
->flags
|= I40EVF_FLAG_ADDR_SET_BY_PF
;
2486 ether_addr_copy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
);
2487 ether_addr_copy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
);
2490 init_timer(&adapter
->watchdog_timer
);
2491 adapter
->watchdog_timer
.function
= &i40evf_watchdog_timer
;
2492 adapter
->watchdog_timer
.data
= (unsigned long)adapter
;
2493 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
2495 adapter
->num_active_queues
= min_t(int,
2496 adapter
->vsi_res
->num_queue_pairs
,
2497 (int)(num_online_cpus()));
2498 adapter
->tx_desc_count
= I40EVF_DEFAULT_TXD
;
2499 adapter
->rx_desc_count
= I40EVF_DEFAULT_RXD
;
2500 err
= i40evf_init_interrupt_scheme(adapter
);
2503 i40evf_map_rings_to_vectors(adapter
);
2504 if (adapter
->vf_res
->vf_offload_flags
&
2505 I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR
)
2506 adapter
->flags
|= I40EVF_FLAG_WB_ON_ITR_CAPABLE
;
2507 if (!RSS_AQ(adapter
))
2508 i40evf_init_rss(adapter
);
2509 err
= i40evf_request_misc_irq(adapter
);
2513 netif_carrier_off(netdev
);
2515 if (!adapter
->netdev_registered
) {
2516 err
= register_netdev(netdev
);
2521 adapter
->netdev_registered
= true;
2523 netif_tx_stop_all_queues(netdev
);
2525 dev_info(&pdev
->dev
, "MAC address: %pM\n", adapter
->hw
.mac
.addr
);
2526 if (netdev
->features
& NETIF_F_GRO
)
2527 dev_info(&pdev
->dev
, "GRO is enabled\n");
2529 adapter
->state
= __I40EVF_DOWN
;
2530 set_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
2531 i40evf_misc_irq_enable(adapter
);
2533 if (RSS_AQ(adapter
)) {
2534 adapter
->aq_required
|= I40EVF_FLAG_AQ_CONFIGURE_RSS
;
2535 mod_timer_pending(&adapter
->watchdog_timer
, jiffies
+ 1);
2537 i40evf_init_rss(adapter
);
2541 schedule_delayed_work(&adapter
->init_task
, msecs_to_jiffies(30));
2545 i40evf_free_misc_irq(adapter
);
2547 i40evf_reset_interrupt_capability(adapter
);
2549 kfree(adapter
->vf_res
);
2550 adapter
->vf_res
= NULL
;
2552 /* Things went into the weeds, so try again later */
2553 if (++adapter
->aq_wait_count
> I40EVF_AQ_MAX_ERR
) {
2554 dev_err(&pdev
->dev
, "Failed to communicate with PF; waiting before retry\n");
2555 adapter
->flags
|= I40EVF_FLAG_PF_COMMS_FAILED
;
2556 i40evf_shutdown_adminq(hw
);
2557 adapter
->state
= __I40EVF_STARTUP
;
2558 schedule_delayed_work(&adapter
->init_task
, HZ
* 5);
2561 schedule_delayed_work(&adapter
->init_task
, HZ
);
2565 * i40evf_shutdown - Shutdown the device in preparation for a reboot
2566 * @pdev: pci device structure
2568 static void i40evf_shutdown(struct pci_dev
*pdev
)
2570 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2571 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2573 netif_device_detach(netdev
);
2575 if (netif_running(netdev
))
2576 i40evf_close(netdev
);
2578 /* Prevent the watchdog from running. */
2579 adapter
->state
= __I40EVF_REMOVE
;
2580 adapter
->aq_required
= 0;
2583 pci_save_state(pdev
);
2586 pci_disable_device(pdev
);
2590 * i40evf_probe - Device Initialization Routine
2591 * @pdev: PCI device information struct
2592 * @ent: entry in i40evf_pci_tbl
2594 * Returns 0 on success, negative on failure
2596 * i40evf_probe initializes an adapter identified by a pci_dev structure.
2597 * The OS initialization, configuring of the adapter private structure,
2598 * and a hardware reset occur.
2600 static int i40evf_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2602 struct net_device
*netdev
;
2603 struct i40evf_adapter
*adapter
= NULL
;
2604 struct i40e_hw
*hw
= NULL
;
2607 err
= pci_enable_device(pdev
);
2611 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
2613 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
2616 "DMA configuration failed: 0x%x\n", err
);
2621 err
= pci_request_regions(pdev
, i40evf_driver_name
);
2624 "pci_request_regions failed 0x%x\n", err
);
2628 pci_enable_pcie_error_reporting(pdev
);
2630 pci_set_master(pdev
);
2632 netdev
= alloc_etherdev_mq(sizeof(struct i40evf_adapter
), MAX_QUEUES
);
2635 goto err_alloc_etherdev
;
2638 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
2640 pci_set_drvdata(pdev
, netdev
);
2641 adapter
= netdev_priv(netdev
);
2643 adapter
->netdev
= netdev
;
2644 adapter
->pdev
= pdev
;
2649 adapter
->msg_enable
= BIT(DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
2650 adapter
->state
= __I40EVF_STARTUP
;
2652 /* Call save state here because it relies on the adapter struct. */
2653 pci_save_state(pdev
);
2655 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
2656 pci_resource_len(pdev
, 0));
2661 hw
->vendor_id
= pdev
->vendor
;
2662 hw
->device_id
= pdev
->device
;
2663 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
2664 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
2665 hw
->subsystem_device_id
= pdev
->subsystem_device
;
2666 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
2667 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
2669 /* set up the locks for the AQ, do this only once in probe
2670 * and destroy them only once in remove
2672 mutex_init(&hw
->aq
.asq_mutex
);
2673 mutex_init(&hw
->aq
.arq_mutex
);
2675 INIT_LIST_HEAD(&adapter
->mac_filter_list
);
2676 INIT_LIST_HEAD(&adapter
->vlan_filter_list
);
2678 INIT_WORK(&adapter
->reset_task
, i40evf_reset_task
);
2679 INIT_WORK(&adapter
->adminq_task
, i40evf_adminq_task
);
2680 INIT_WORK(&adapter
->watchdog_task
, i40evf_watchdog_task
);
2681 INIT_DELAYED_WORK(&adapter
->init_task
, i40evf_init_task
);
2682 schedule_delayed_work(&adapter
->init_task
,
2683 msecs_to_jiffies(5 * (pdev
->devfn
& 0x07)));
2688 free_netdev(netdev
);
2690 pci_release_regions(pdev
);
2693 pci_disable_device(pdev
);
2699 * i40evf_suspend - Power management suspend routine
2700 * @pdev: PCI device information struct
2703 * Called when the system (VM) is entering sleep/suspend.
2705 static int i40evf_suspend(struct pci_dev
*pdev
, pm_message_t state
)
2707 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2708 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2711 netif_device_detach(netdev
);
2713 if (netif_running(netdev
)) {
2715 i40evf_down(adapter
);
2718 i40evf_free_misc_irq(adapter
);
2719 i40evf_reset_interrupt_capability(adapter
);
2721 retval
= pci_save_state(pdev
);
2725 pci_disable_device(pdev
);
2731 * i40evf_resume - Power management resume routine
2732 * @pdev: PCI device information struct
2734 * Called when the system (VM) is resumed from sleep/suspend.
2736 static int i40evf_resume(struct pci_dev
*pdev
)
2738 struct i40evf_adapter
*adapter
= pci_get_drvdata(pdev
);
2739 struct net_device
*netdev
= adapter
->netdev
;
2742 pci_set_power_state(pdev
, PCI_D0
);
2743 pci_restore_state(pdev
);
2744 /* pci_restore_state clears dev->state_saved so call
2745 * pci_save_state to restore it.
2747 pci_save_state(pdev
);
2749 err
= pci_enable_device_mem(pdev
);
2751 dev_err(&pdev
->dev
, "Cannot enable PCI device from suspend.\n");
2754 pci_set_master(pdev
);
2757 err
= i40evf_set_interrupt_capability(adapter
);
2760 dev_err(&pdev
->dev
, "Cannot enable MSI-X interrupts.\n");
2763 err
= i40evf_request_misc_irq(adapter
);
2766 dev_err(&pdev
->dev
, "Cannot get interrupt vector.\n");
2770 schedule_work(&adapter
->reset_task
);
2772 netif_device_attach(netdev
);
2777 #endif /* CONFIG_PM */
2779 * i40evf_remove - Device Removal Routine
2780 * @pdev: PCI device information struct
2782 * i40evf_remove is called by the PCI subsystem to alert the driver
2783 * that it should release a PCI device. The could be caused by a
2784 * Hot-Plug event, or because the driver is going to be removed from
2787 static void i40evf_remove(struct pci_dev
*pdev
)
2789 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2790 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2791 struct i40evf_mac_filter
*f
, *ftmp
;
2792 struct i40e_hw
*hw
= &adapter
->hw
;
2794 cancel_delayed_work_sync(&adapter
->init_task
);
2795 cancel_work_sync(&adapter
->reset_task
);
2797 if (adapter
->netdev_registered
) {
2798 unregister_netdev(netdev
);
2799 adapter
->netdev_registered
= false;
2802 /* Shut down all the garbage mashers on the detention level */
2803 adapter
->state
= __I40EVF_REMOVE
;
2804 adapter
->aq_required
= 0;
2805 i40evf_request_reset(adapter
);
2807 /* If the FW isn't responding, kick it once, but only once. */
2808 if (!i40evf_asq_done(hw
)) {
2809 i40evf_request_reset(adapter
);
2813 if (adapter
->msix_entries
) {
2814 i40evf_misc_irq_disable(adapter
);
2815 i40evf_free_misc_irq(adapter
);
2816 i40evf_reset_interrupt_capability(adapter
);
2817 i40evf_free_q_vectors(adapter
);
2820 if (adapter
->watchdog_timer
.function
)
2821 del_timer_sync(&adapter
->watchdog_timer
);
2823 flush_scheduled_work();
2825 /* Clear user configurations for RSS */
2826 i40evf_clear_rss_config_user(&adapter
->vsi
);
2828 if (hw
->aq
.asq
.count
)
2829 i40evf_shutdown_adminq(hw
);
2831 /* destroy the locks only once, here */
2832 mutex_destroy(&hw
->aq
.arq_mutex
);
2833 mutex_destroy(&hw
->aq
.asq_mutex
);
2835 iounmap(hw
->hw_addr
);
2836 pci_release_regions(pdev
);
2838 i40evf_free_all_tx_resources(adapter
);
2839 i40evf_free_all_rx_resources(adapter
);
2840 i40evf_free_queues(adapter
);
2841 kfree(adapter
->vf_res
);
2842 /* If we got removed before an up/down sequence, we've got a filter
2843 * hanging out there that we need to get rid of.
2845 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
2849 list_for_each_entry_safe(f
, ftmp
, &adapter
->vlan_filter_list
, list
) {
2854 free_netdev(netdev
);
2856 pci_disable_pcie_error_reporting(pdev
);
2858 pci_disable_device(pdev
);
2861 static struct pci_driver i40evf_driver
= {
2862 .name
= i40evf_driver_name
,
2863 .id_table
= i40evf_pci_tbl
,
2864 .probe
= i40evf_probe
,
2865 .remove
= i40evf_remove
,
2867 .suspend
= i40evf_suspend
,
2868 .resume
= i40evf_resume
,
2870 .shutdown
= i40evf_shutdown
,
2874 * i40e_init_module - Driver Registration Routine
2876 * i40e_init_module is the first routine called when the driver is
2877 * loaded. All it does is register with the PCI subsystem.
2879 static int __init
i40evf_init_module(void)
2883 pr_info("i40evf: %s - version %s\n", i40evf_driver_string
,
2884 i40evf_driver_version
);
2886 pr_info("%s\n", i40evf_copyright
);
2888 ret
= pci_register_driver(&i40evf_driver
);
2892 module_init(i40evf_init_module
);
2895 * i40e_exit_module - Driver Exit Cleanup Routine
2897 * i40e_exit_module is called just before the driver is removed
2900 static void __exit
i40evf_exit_module(void)
2902 pci_unregister_driver(&i40evf_driver
);
2905 module_exit(i40evf_exit_module
);