1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
4 * Copyright(c) 2013 - 2014 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 void i40evf_free_all_tx_resources(struct i40evf_adapter
*adapter
);
32 static void i40evf_free_all_rx_resources(struct i40evf_adapter
*adapter
);
33 static int i40evf_close(struct net_device
*netdev
);
35 char i40evf_driver_name
[] = "i40evf";
36 static const char i40evf_driver_string
[] =
37 "Intel(R) XL710/X710 Virtual Function Network Driver";
39 #define DRV_VERSION "1.0.5"
40 const char i40evf_driver_version
[] = DRV_VERSION
;
41 static const char i40evf_copyright
[] =
42 "Copyright (c) 2013 - 2014 Intel Corporation.";
44 /* i40evf_pci_tbl - PCI Device ID Table
46 * Wildcard entries (PCI_ANY_ID) should come last
47 * Last entry must be all 0s
49 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
50 * Class, Class Mask, private data (not used) }
52 static const struct pci_device_id i40evf_pci_tbl
[] = {
53 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_VF
), 0},
54 /* required last entry */
58 MODULE_DEVICE_TABLE(pci
, i40evf_pci_tbl
);
60 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
61 MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver");
62 MODULE_LICENSE("GPL");
63 MODULE_VERSION(DRV_VERSION
);
66 * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code
67 * @hw: pointer to the HW structure
68 * @mem: ptr to mem struct to fill out
69 * @size: size of memory requested
70 * @alignment: what to align the allocation to
72 i40e_status
i40evf_allocate_dma_mem_d(struct i40e_hw
*hw
,
73 struct i40e_dma_mem
*mem
,
74 u64 size
, u32 alignment
)
76 struct i40evf_adapter
*adapter
= (struct i40evf_adapter
*)hw
->back
;
79 return I40E_ERR_PARAM
;
81 mem
->size
= ALIGN(size
, alignment
);
82 mem
->va
= dma_alloc_coherent(&adapter
->pdev
->dev
, mem
->size
,
83 (dma_addr_t
*)&mem
->pa
, GFP_KERNEL
);
87 return I40E_ERR_NO_MEMORY
;
91 * i40evf_free_dma_mem_d - OS specific memory free for shared code
92 * @hw: pointer to the HW structure
93 * @mem: ptr to mem struct to free
95 i40e_status
i40evf_free_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
)
97 struct i40evf_adapter
*adapter
= (struct i40evf_adapter
*)hw
->back
;
100 return I40E_ERR_PARAM
;
101 dma_free_coherent(&adapter
->pdev
->dev
, mem
->size
,
102 mem
->va
, (dma_addr_t
)mem
->pa
);
107 * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code
108 * @hw: pointer to the HW structure
109 * @mem: ptr to mem struct to fill out
110 * @size: size of memory requested
112 i40e_status
i40evf_allocate_virt_mem_d(struct i40e_hw
*hw
,
113 struct i40e_virt_mem
*mem
, u32 size
)
116 return I40E_ERR_PARAM
;
119 mem
->va
= kzalloc(size
, GFP_KERNEL
);
124 return I40E_ERR_NO_MEMORY
;
128 * i40evf_free_virt_mem_d - OS specific memory free for shared code
129 * @hw: pointer to the HW structure
130 * @mem: ptr to mem struct to free
132 i40e_status
i40evf_free_virt_mem_d(struct i40e_hw
*hw
,
133 struct i40e_virt_mem
*mem
)
136 return I40E_ERR_PARAM
;
138 /* it's ok to kfree a NULL pointer */
145 * i40evf_debug_d - OS dependent version of debug printing
146 * @hw: pointer to the HW structure
147 * @mask: debug level mask
148 * @fmt_str: printf-type format description
150 void i40evf_debug_d(void *hw
, u32 mask
, char *fmt_str
, ...)
155 if (!(mask
& ((struct i40e_hw
*)hw
)->debug_mask
))
158 va_start(argptr
, fmt_str
);
159 vsnprintf(buf
, sizeof(buf
), fmt_str
, argptr
);
162 /* the debug string is already formatted with a newline */
167 * i40evf_tx_timeout - Respond to a Tx Hang
168 * @netdev: network interface device structure
170 static void i40evf_tx_timeout(struct net_device
*netdev
)
172 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
174 adapter
->tx_timeout_count
++;
175 if (!(adapter
->flags
& I40EVF_FLAG_RESET_PENDING
)) {
176 adapter
->flags
|= I40EVF_FLAG_RESET_NEEDED
;
177 schedule_work(&adapter
->reset_task
);
182 * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC
183 * @adapter: board private structure
185 static void i40evf_misc_irq_disable(struct i40evf_adapter
*adapter
)
187 struct i40e_hw
*hw
= &adapter
->hw
;
188 wr32(hw
, I40E_VFINT_DYN_CTL01
, 0);
191 rd32(hw
, I40E_VFGEN_RSTAT
);
193 synchronize_irq(adapter
->msix_entries
[0].vector
);
197 * i40evf_misc_irq_enable - Enable default interrupt generation settings
198 * @adapter: board private structure
200 static void i40evf_misc_irq_enable(struct i40evf_adapter
*adapter
)
202 struct i40e_hw
*hw
= &adapter
->hw
;
203 wr32(hw
, I40E_VFINT_DYN_CTL01
, I40E_VFINT_DYN_CTL01_INTENA_MASK
|
204 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK
);
205 wr32(hw
, I40E_VFINT_ICR0_ENA1
, I40E_VFINT_ICR0_ENA_ADMINQ_MASK
);
208 rd32(hw
, I40E_VFGEN_RSTAT
);
212 * i40evf_irq_disable - Mask off interrupt generation on the NIC
213 * @adapter: board private structure
215 static void i40evf_irq_disable(struct i40evf_adapter
*adapter
)
218 struct i40e_hw
*hw
= &adapter
->hw
;
220 if (!adapter
->msix_entries
)
223 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
224 wr32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1), 0);
225 synchronize_irq(adapter
->msix_entries
[i
].vector
);
228 rd32(hw
, I40E_VFGEN_RSTAT
);
233 * i40evf_irq_enable_queues - Enable interrupt for specified queues
234 * @adapter: board private structure
235 * @mask: bitmap of queues to enable
237 void i40evf_irq_enable_queues(struct i40evf_adapter
*adapter
, u32 mask
)
239 struct i40e_hw
*hw
= &adapter
->hw
;
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_CTLN_CLEARPBA_MASK
);
252 * i40evf_fire_sw_int - Generate SW interrupt for specified vectors
253 * @adapter: board private structure
254 * @mask: bitmap of vectors to trigger
256 static void i40evf_fire_sw_int(struct i40evf_adapter
*adapter
,
259 struct i40e_hw
*hw
= &adapter
->hw
;
264 dyn_ctl
= rd32(hw
, I40E_VFINT_DYN_CTL01
);
265 dyn_ctl
|= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK
|
266 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK
;
267 wr32(hw
, I40E_VFINT_DYN_CTL01
, dyn_ctl
);
269 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
270 if (mask
& (1 << i
)) {
271 dyn_ctl
= rd32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1));
272 dyn_ctl
|= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK
|
273 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK
;
274 wr32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1), dyn_ctl
);
280 * i40evf_irq_enable - Enable default interrupt generation settings
281 * @adapter: board private structure
283 void i40evf_irq_enable(struct i40evf_adapter
*adapter
, bool flush
)
285 struct i40e_hw
*hw
= &adapter
->hw
;
287 i40evf_misc_irq_enable(adapter
);
288 i40evf_irq_enable_queues(adapter
, ~0);
291 rd32(hw
, I40E_VFGEN_RSTAT
);
295 * i40evf_msix_aq - Interrupt handler for vector 0
296 * @irq: interrupt number
297 * @data: pointer to netdev
299 static irqreturn_t
i40evf_msix_aq(int irq
, void *data
)
301 struct net_device
*netdev
= data
;
302 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
303 struct i40e_hw
*hw
= &adapter
->hw
;
307 /* handle non-queue interrupts */
308 val
= rd32(hw
, I40E_VFINT_ICR01
);
309 ena_mask
= rd32(hw
, I40E_VFINT_ICR0_ENA1
);
312 val
= rd32(hw
, I40E_VFINT_DYN_CTL01
);
313 val
= val
| I40E_PFINT_DYN_CTL0_CLEARPBA_MASK
;
314 wr32(hw
, I40E_VFINT_DYN_CTL01
, val
);
316 /* re-enable interrupt causes */
317 wr32(hw
, I40E_VFINT_ICR0_ENA1
, ena_mask
);
318 wr32(hw
, I40E_VFINT_DYN_CTL01
, I40E_VFINT_DYN_CTL01_INTENA_MASK
);
320 /* schedule work on the private workqueue */
321 schedule_work(&adapter
->adminq_task
);
327 * i40evf_msix_clean_rings - MSIX mode Interrupt Handler
328 * @irq: interrupt number
329 * @data: pointer to a q_vector
331 static irqreturn_t
i40evf_msix_clean_rings(int irq
, void *data
)
333 struct i40e_q_vector
*q_vector
= data
;
335 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
338 napi_schedule(&q_vector
->napi
);
344 * i40evf_map_vector_to_rxq - associate irqs with rx queues
345 * @adapter: board private structure
346 * @v_idx: interrupt number
347 * @r_idx: queue number
350 i40evf_map_vector_to_rxq(struct i40evf_adapter
*adapter
, int v_idx
, int r_idx
)
352 struct i40e_q_vector
*q_vector
= adapter
->q_vector
[v_idx
];
353 struct i40e_ring
*rx_ring
= adapter
->rx_rings
[r_idx
];
355 rx_ring
->q_vector
= q_vector
;
356 rx_ring
->next
= q_vector
->rx
.ring
;
357 rx_ring
->vsi
= &adapter
->vsi
;
358 q_vector
->rx
.ring
= rx_ring
;
359 q_vector
->rx
.count
++;
360 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
364 * i40evf_map_vector_to_txq - associate irqs with tx queues
365 * @adapter: board private structure
366 * @v_idx: interrupt number
367 * @t_idx: queue number
370 i40evf_map_vector_to_txq(struct i40evf_adapter
*adapter
, int v_idx
, int t_idx
)
372 struct i40e_q_vector
*q_vector
= adapter
->q_vector
[v_idx
];
373 struct i40e_ring
*tx_ring
= adapter
->tx_rings
[t_idx
];
375 tx_ring
->q_vector
= q_vector
;
376 tx_ring
->next
= q_vector
->tx
.ring
;
377 tx_ring
->vsi
= &adapter
->vsi
;
378 q_vector
->tx
.ring
= tx_ring
;
379 q_vector
->tx
.count
++;
380 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
381 q_vector
->num_ringpairs
++;
382 q_vector
->ring_mask
|= (1 << t_idx
);
386 * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors
387 * @adapter: board private structure to initialize
389 * This function maps descriptor rings to the queue-specific vectors
390 * we were allotted through the MSI-X enabling code. Ideally, we'd have
391 * one vector per ring/queue, but on a constrained vector budget, we
392 * group the rings as "efficiently" as possible. You would add new
393 * mapping configurations in here.
395 static int i40evf_map_rings_to_vectors(struct i40evf_adapter
*adapter
)
399 int rxr_idx
= 0, txr_idx
= 0;
400 int rxr_remaining
= adapter
->vsi_res
->num_queue_pairs
;
401 int txr_remaining
= adapter
->vsi_res
->num_queue_pairs
;
406 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
408 /* The ideal configuration...
409 * We have enough vectors to map one per queue.
411 if (q_vectors
== (rxr_remaining
* 2)) {
412 for (; rxr_idx
< rxr_remaining
; v_start
++, rxr_idx
++)
413 i40evf_map_vector_to_rxq(adapter
, v_start
, rxr_idx
);
415 for (; txr_idx
< txr_remaining
; v_start
++, txr_idx
++)
416 i40evf_map_vector_to_txq(adapter
, v_start
, txr_idx
);
420 /* If we don't have enough vectors for a 1-to-1
421 * mapping, we'll have to group them so there are
422 * multiple queues per vector.
423 * Re-adjusting *qpv takes care of the remainder.
425 for (i
= v_start
; i
< q_vectors
; i
++) {
426 rqpv
= DIV_ROUND_UP(rxr_remaining
, q_vectors
- i
);
427 for (j
= 0; j
< rqpv
; j
++) {
428 i40evf_map_vector_to_rxq(adapter
, i
, rxr_idx
);
433 for (i
= v_start
; i
< q_vectors
; i
++) {
434 tqpv
= DIV_ROUND_UP(txr_remaining
, q_vectors
- i
);
435 for (j
= 0; j
< tqpv
; j
++) {
436 i40evf_map_vector_to_txq(adapter
, i
, txr_idx
);
443 adapter
->aq_required
|= I40EVF_FLAG_AQ_MAP_VECTORS
;
449 * i40evf_request_traffic_irqs - Initialize MSI-X interrupts
450 * @adapter: board private structure
452 * Allocates MSI-X vectors for tx and rx handling, and requests
453 * interrupts from the kernel.
456 i40evf_request_traffic_irqs(struct i40evf_adapter
*adapter
, char *basename
)
458 int vector
, err
, q_vectors
;
459 int rx_int_idx
= 0, tx_int_idx
= 0;
461 i40evf_irq_disable(adapter
);
462 /* Decrement for Other and TCP Timer vectors */
463 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
465 for (vector
= 0; vector
< q_vectors
; vector
++) {
466 struct i40e_q_vector
*q_vector
= adapter
->q_vector
[vector
];
468 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
469 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
470 "i40evf-%s-%s-%d", basename
,
471 "TxRx", rx_int_idx
++);
473 } else if (q_vector
->rx
.ring
) {
474 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
475 "i40evf-%s-%s-%d", basename
,
477 } else if (q_vector
->tx
.ring
) {
478 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
479 "i40evf-%s-%s-%d", basename
,
482 /* skip this unused q_vector */
486 adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
487 i40evf_msix_clean_rings
,
492 dev_info(&adapter
->pdev
->dev
,
493 "%s: request_irq failed, error: %d\n",
495 goto free_queue_irqs
;
497 /* assign the mask for this irq */
498 irq_set_affinity_hint(
499 adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
500 q_vector
->affinity_mask
);
508 irq_set_affinity_hint(
509 adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
511 free_irq(adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
512 adapter
->q_vector
[vector
]);
518 * i40evf_request_misc_irq - Initialize MSI-X interrupts
519 * @adapter: board private structure
521 * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
522 * vector is only for the admin queue, and stays active even when the netdev
525 static int i40evf_request_misc_irq(struct i40evf_adapter
*adapter
)
527 struct net_device
*netdev
= adapter
->netdev
;
530 snprintf(adapter
->misc_vector_name
,
531 sizeof(adapter
->misc_vector_name
) - 1, "i40evf:mbx");
532 err
= request_irq(adapter
->msix_entries
[0].vector
,
534 adapter
->misc_vector_name
, netdev
);
536 dev_err(&adapter
->pdev
->dev
,
537 "request_irq for %s failed: %d\n",
538 adapter
->misc_vector_name
, err
);
539 free_irq(adapter
->msix_entries
[0].vector
, netdev
);
545 * i40evf_free_traffic_irqs - Free MSI-X interrupts
546 * @adapter: board private structure
548 * Frees all MSI-X vectors other than 0.
550 static void i40evf_free_traffic_irqs(struct i40evf_adapter
*adapter
)
554 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
556 for (i
= 0; i
< q_vectors
; i
++) {
557 irq_set_affinity_hint(adapter
->msix_entries
[i
+1].vector
,
559 free_irq(adapter
->msix_entries
[i
+1].vector
,
560 adapter
->q_vector
[i
]);
565 * i40evf_free_misc_irq - Free MSI-X miscellaneous vector
566 * @adapter: board private structure
568 * Frees MSI-X vector 0.
570 static void i40evf_free_misc_irq(struct i40evf_adapter
*adapter
)
572 struct net_device
*netdev
= adapter
->netdev
;
574 free_irq(adapter
->msix_entries
[0].vector
, netdev
);
578 * i40evf_configure_tx - Configure Transmit Unit after Reset
579 * @adapter: board private structure
581 * Configure the Tx unit of the MAC after a reset.
583 static void i40evf_configure_tx(struct i40evf_adapter
*adapter
)
585 struct i40e_hw
*hw
= &adapter
->hw
;
587 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++)
588 adapter
->tx_rings
[i
]->tail
= hw
->hw_addr
+ I40E_QTX_TAIL1(i
);
592 * i40evf_configure_rx - Configure Receive Unit after Reset
593 * @adapter: board private structure
595 * Configure the Rx unit of the MAC after a reset.
597 static void i40evf_configure_rx(struct i40evf_adapter
*adapter
)
599 struct i40e_hw
*hw
= &adapter
->hw
;
600 struct net_device
*netdev
= adapter
->netdev
;
601 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
606 adapter
->flags
&= ~I40EVF_FLAG_RX_PS_CAPABLE
;
607 adapter
->flags
|= I40EVF_FLAG_RX_1BUF_CAPABLE
;
609 /* Decide whether to use packet split mode or not */
610 if (netdev
->mtu
> ETH_DATA_LEN
) {
611 if (adapter
->flags
& I40EVF_FLAG_RX_PS_CAPABLE
)
612 adapter
->flags
|= I40EVF_FLAG_RX_PS_ENABLED
;
614 adapter
->flags
&= ~I40EVF_FLAG_RX_PS_ENABLED
;
616 if (adapter
->flags
& I40EVF_FLAG_RX_1BUF_CAPABLE
)
617 adapter
->flags
&= ~I40EVF_FLAG_RX_PS_ENABLED
;
619 adapter
->flags
|= I40EVF_FLAG_RX_PS_ENABLED
;
622 /* Set the RX buffer length according to the mode */
623 if (adapter
->flags
& I40EVF_FLAG_RX_PS_ENABLED
) {
624 rx_buf_len
= I40E_RX_HDR_SIZE
;
626 if (netdev
->mtu
<= ETH_DATA_LEN
)
627 rx_buf_len
= I40EVF_RXBUFFER_2048
;
629 rx_buf_len
= ALIGN(max_frame
, 1024);
632 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++) {
633 adapter
->rx_rings
[i
]->tail
= hw
->hw_addr
+ I40E_QRX_TAIL1(i
);
634 adapter
->rx_rings
[i
]->rx_buf_len
= rx_buf_len
;
639 * i40evf_find_vlan - Search filter list for specific vlan filter
640 * @adapter: board private structure
643 * Returns ptr to the filter object or NULL
646 i40evf_vlan_filter
*i40evf_find_vlan(struct i40evf_adapter
*adapter
, u16 vlan
)
648 struct i40evf_vlan_filter
*f
;
650 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
658 * i40evf_add_vlan - Add a vlan filter to the list
659 * @adapter: board private structure
662 * Returns ptr to the filter object or NULL when no memory available.
665 i40evf_vlan_filter
*i40evf_add_vlan(struct i40evf_adapter
*adapter
, u16 vlan
)
667 struct i40evf_vlan_filter
*f
;
669 f
= i40evf_find_vlan(adapter
, vlan
);
671 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
677 INIT_LIST_HEAD(&f
->list
);
678 list_add(&f
->list
, &adapter
->vlan_filter_list
);
680 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_VLAN_FILTER
;
687 * i40evf_del_vlan - Remove a vlan filter from the list
688 * @adapter: board private structure
691 static void i40evf_del_vlan(struct i40evf_adapter
*adapter
, u16 vlan
)
693 struct i40evf_vlan_filter
*f
;
695 f
= i40evf_find_vlan(adapter
, vlan
);
698 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_VLAN_FILTER
;
703 * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device
704 * @netdev: network device struct
707 static int i40evf_vlan_rx_add_vid(struct net_device
*netdev
,
708 __always_unused __be16 proto
, u16 vid
)
710 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
712 if (i40evf_add_vlan(adapter
, vid
) == NULL
)
718 * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device
719 * @netdev: network device struct
722 static int i40evf_vlan_rx_kill_vid(struct net_device
*netdev
,
723 __always_unused __be16 proto
, u16 vid
)
725 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
727 i40evf_del_vlan(adapter
, vid
);
732 * i40evf_find_filter - Search filter list for specific mac filter
733 * @adapter: board private structure
734 * @macaddr: the MAC address
736 * Returns ptr to the filter object or NULL
739 i40evf_mac_filter
*i40evf_find_filter(struct i40evf_adapter
*adapter
,
742 struct i40evf_mac_filter
*f
;
747 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
748 if (ether_addr_equal(macaddr
, f
->macaddr
))
755 * i40e_add_filter - Add a mac filter to the filter list
756 * @adapter: board private structure
757 * @macaddr: the MAC address
759 * Returns ptr to the filter object or NULL when no memory available.
762 i40evf_mac_filter
*i40evf_add_filter(struct i40evf_adapter
*adapter
,
765 struct i40evf_mac_filter
*f
;
770 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
771 &adapter
->crit_section
))
774 f
= i40evf_find_filter(adapter
, macaddr
);
776 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
778 clear_bit(__I40EVF_IN_CRITICAL_TASK
,
779 &adapter
->crit_section
);
783 ether_addr_copy(f
->macaddr
, macaddr
);
785 list_add(&f
->list
, &adapter
->mac_filter_list
);
787 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_MAC_FILTER
;
790 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
795 * i40evf_set_mac - NDO callback to set port mac address
796 * @netdev: network interface device structure
797 * @p: pointer to an address structure
799 * Returns 0 on success, negative on failure
801 static int i40evf_set_mac(struct net_device
*netdev
, void *p
)
803 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
804 struct i40e_hw
*hw
= &adapter
->hw
;
805 struct i40evf_mac_filter
*f
;
806 struct sockaddr
*addr
= p
;
808 if (!is_valid_ether_addr(addr
->sa_data
))
809 return -EADDRNOTAVAIL
;
811 if (ether_addr_equal(netdev
->dev_addr
, addr
->sa_data
))
814 f
= i40evf_add_filter(adapter
, addr
->sa_data
);
816 ether_addr_copy(hw
->mac
.addr
, addr
->sa_data
);
817 ether_addr_copy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
);
820 return (f
== NULL
) ? -ENOMEM
: 0;
824 * i40evf_set_rx_mode - NDO callback to set the netdev filters
825 * @netdev: network interface device structure
827 static void i40evf_set_rx_mode(struct net_device
*netdev
)
829 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
830 struct i40evf_mac_filter
*f
, *ftmp
;
831 struct netdev_hw_addr
*uca
;
832 struct netdev_hw_addr
*mca
;
834 /* add addr if not already in the filter list */
835 netdev_for_each_uc_addr(uca
, netdev
) {
836 i40evf_add_filter(adapter
, uca
->addr
);
838 netdev_for_each_mc_addr(mca
, netdev
) {
839 i40evf_add_filter(adapter
, mca
->addr
);
842 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
843 &adapter
->crit_section
))
845 /* remove filter if not in netdev list */
846 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
849 if (is_multicast_ether_addr(f
->macaddr
)) {
850 netdev_for_each_mc_addr(mca
, netdev
) {
851 if (ether_addr_equal(mca
->addr
, f
->macaddr
)) {
857 netdev_for_each_uc_addr(uca
, netdev
) {
858 if (ether_addr_equal(uca
->addr
, f
->macaddr
)) {
866 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
869 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
873 * i40evf_napi_enable_all - enable NAPI on all queue vectors
874 * @adapter: board private structure
876 static void i40evf_napi_enable_all(struct i40evf_adapter
*adapter
)
879 struct i40e_q_vector
*q_vector
;
880 int q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
882 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
883 struct napi_struct
*napi
;
884 q_vector
= adapter
->q_vector
[q_idx
];
885 napi
= &q_vector
->napi
;
891 * i40evf_napi_disable_all - disable NAPI on all queue vectors
892 * @adapter: board private structure
894 static void i40evf_napi_disable_all(struct i40evf_adapter
*adapter
)
897 struct i40e_q_vector
*q_vector
;
898 int q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
900 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
901 q_vector
= adapter
->q_vector
[q_idx
];
902 napi_disable(&q_vector
->napi
);
907 * i40evf_configure - set up transmit and receive data structures
908 * @adapter: board private structure
910 static void i40evf_configure(struct i40evf_adapter
*adapter
)
912 struct net_device
*netdev
= adapter
->netdev
;
915 i40evf_set_rx_mode(netdev
);
917 i40evf_configure_tx(adapter
);
918 i40evf_configure_rx(adapter
);
919 adapter
->aq_required
|= I40EVF_FLAG_AQ_CONFIGURE_QUEUES
;
921 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++) {
922 struct i40e_ring
*ring
= adapter
->rx_rings
[i
];
923 i40evf_alloc_rx_buffers(ring
, ring
->count
);
924 ring
->next_to_use
= ring
->count
- 1;
925 writel(ring
->next_to_use
, ring
->tail
);
930 * i40evf_up_complete - Finish the last steps of bringing up a connection
931 * @adapter: board private structure
933 static int i40evf_up_complete(struct i40evf_adapter
*adapter
)
935 adapter
->state
= __I40EVF_RUNNING
;
936 clear_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
938 i40evf_napi_enable_all(adapter
);
940 adapter
->aq_required
|= I40EVF_FLAG_AQ_ENABLE_QUEUES
;
941 mod_timer_pending(&adapter
->watchdog_timer
, jiffies
+ 1);
946 * i40evf_clean_all_rx_rings - Free Rx Buffers for all queues
947 * @adapter: board private structure
949 static void i40evf_clean_all_rx_rings(struct i40evf_adapter
*adapter
)
953 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++)
954 i40evf_clean_rx_ring(adapter
->rx_rings
[i
]);
958 * i40evf_clean_all_tx_rings - Free Tx Buffers for all queues
959 * @adapter: board private structure
961 static void i40evf_clean_all_tx_rings(struct i40evf_adapter
*adapter
)
965 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++)
966 i40evf_clean_tx_ring(adapter
->tx_rings
[i
]);
970 * i40e_down - Shutdown the connection processing
971 * @adapter: board private structure
973 void i40evf_down(struct i40evf_adapter
*adapter
)
975 struct net_device
*netdev
= adapter
->netdev
;
976 struct i40evf_mac_filter
*f
;
978 if (adapter
->state
== __I40EVF_DOWN
)
981 /* remove all MAC filters */
982 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
985 /* remove all VLAN filters */
986 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
989 if (!(adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
) &&
990 adapter
->state
!= __I40EVF_RESETTING
) {
991 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
992 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_VLAN_FILTER
;
993 /* disable receives */
994 adapter
->aq_required
|= I40EVF_FLAG_AQ_DISABLE_QUEUES
;
995 mod_timer_pending(&adapter
->watchdog_timer
, jiffies
+ 1);
998 netif_tx_disable(netdev
);
1000 netif_tx_stop_all_queues(netdev
);
1002 i40evf_irq_disable(adapter
);
1004 i40evf_napi_disable_all(adapter
);
1006 netif_carrier_off(netdev
);
1008 i40evf_clean_all_tx_rings(adapter
);
1009 i40evf_clean_all_rx_rings(adapter
);
1013 * i40evf_acquire_msix_vectors - Setup the MSIX capability
1014 * @adapter: board private structure
1015 * @vectors: number of vectors to request
1017 * Work with the OS to set up the MSIX vectors needed.
1019 * Returns 0 on success, negative on failure
1022 i40evf_acquire_msix_vectors(struct i40evf_adapter
*adapter
, int vectors
)
1024 int err
, vector_threshold
;
1026 /* We'll want at least 3 (vector_threshold):
1027 * 0) Other (Admin Queue and link, mostly)
1031 vector_threshold
= MIN_MSIX_COUNT
;
1033 /* The more we get, the more we will assign to Tx/Rx Cleanup
1034 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1035 * Right now, we simply care about how many we'll get; we'll
1036 * set them up later while requesting irq's.
1038 err
= pci_enable_msix_range(adapter
->pdev
, adapter
->msix_entries
,
1039 vector_threshold
, vectors
);
1041 dev_err(&adapter
->pdev
->dev
, "Unable to allocate MSI-X interrupts\n");
1042 kfree(adapter
->msix_entries
);
1043 adapter
->msix_entries
= NULL
;
1047 /* Adjust for only the vectors we'll use, which is minimum
1048 * of max_msix_q_vectors + NONQ_VECS, or the number of
1049 * vectors we were allocated.
1051 adapter
->num_msix_vectors
= err
;
1056 * i40evf_free_queues - Free memory for all rings
1057 * @adapter: board private structure to initialize
1059 * Free all of the memory associated with queue pairs.
1061 static void i40evf_free_queues(struct i40evf_adapter
*adapter
)
1065 if (!adapter
->vsi_res
)
1067 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++) {
1068 if (adapter
->tx_rings
[i
])
1069 kfree_rcu(adapter
->tx_rings
[i
], rcu
);
1070 adapter
->tx_rings
[i
] = NULL
;
1071 adapter
->rx_rings
[i
] = NULL
;
1076 * i40evf_alloc_queues - Allocate memory for all rings
1077 * @adapter: board private structure to initialize
1079 * We allocate one ring per queue at run-time since we don't know the
1080 * number of queues at compile-time. The polling_netdev array is
1081 * intended for Multiqueue, but should work fine with a single queue.
1083 static int i40evf_alloc_queues(struct i40evf_adapter
*adapter
)
1087 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++) {
1088 struct i40e_ring
*tx_ring
;
1089 struct i40e_ring
*rx_ring
;
1091 tx_ring
= kzalloc(sizeof(struct i40e_ring
) * 2, GFP_KERNEL
);
1095 tx_ring
->queue_index
= i
;
1096 tx_ring
->netdev
= adapter
->netdev
;
1097 tx_ring
->dev
= &adapter
->pdev
->dev
;
1098 tx_ring
->count
= adapter
->tx_desc_count
;
1099 adapter
->tx_rings
[i
] = tx_ring
;
1101 rx_ring
= &tx_ring
[1];
1102 rx_ring
->queue_index
= i
;
1103 rx_ring
->netdev
= adapter
->netdev
;
1104 rx_ring
->dev
= &adapter
->pdev
->dev
;
1105 rx_ring
->count
= adapter
->rx_desc_count
;
1106 adapter
->rx_rings
[i
] = rx_ring
;
1112 i40evf_free_queues(adapter
);
1117 * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
1118 * @adapter: board private structure to initialize
1120 * Attempt to configure the interrupts using the best available
1121 * capabilities of the hardware and the kernel.
1123 static int i40evf_set_interrupt_capability(struct i40evf_adapter
*adapter
)
1125 int vector
, v_budget
;
1129 if (!adapter
->vsi_res
) {
1133 pairs
= adapter
->vsi_res
->num_queue_pairs
;
1135 /* It's easy to be greedy for MSI-X vectors, but it really
1136 * doesn't do us much good if we have a lot more vectors
1137 * than CPU's. So let's be conservative and only ask for
1138 * (roughly) twice the number of vectors as there are CPU's.
1140 v_budget
= min_t(int, pairs
, (int)(num_online_cpus() * 2)) + NONQ_VECS
;
1141 v_budget
= min_t(int, v_budget
, (int)adapter
->vf_res
->max_vectors
);
1143 adapter
->msix_entries
= kcalloc(v_budget
,
1144 sizeof(struct msix_entry
), GFP_KERNEL
);
1145 if (!adapter
->msix_entries
) {
1150 for (vector
= 0; vector
< v_budget
; vector
++)
1151 adapter
->msix_entries
[vector
].entry
= vector
;
1153 i40evf_acquire_msix_vectors(adapter
, v_budget
);
1156 adapter
->netdev
->real_num_tx_queues
= pairs
;
1161 * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
1162 * @adapter: board private structure to initialize
1164 * We allocate one q_vector per queue interrupt. If allocation fails we
1167 static int i40evf_alloc_q_vectors(struct i40evf_adapter
*adapter
)
1169 int q_idx
, num_q_vectors
;
1170 struct i40e_q_vector
*q_vector
;
1172 num_q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
1174 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
1175 q_vector
= kzalloc(sizeof(struct i40e_q_vector
), GFP_KERNEL
);
1178 q_vector
->adapter
= adapter
;
1179 q_vector
->vsi
= &adapter
->vsi
;
1180 q_vector
->v_idx
= q_idx
;
1181 netif_napi_add(adapter
->netdev
, &q_vector
->napi
,
1182 i40evf_napi_poll
, NAPI_POLL_WEIGHT
);
1183 adapter
->q_vector
[q_idx
] = q_vector
;
1191 q_vector
= adapter
->q_vector
[q_idx
];
1192 netif_napi_del(&q_vector
->napi
);
1194 adapter
->q_vector
[q_idx
] = NULL
;
1200 * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
1201 * @adapter: board private structure to initialize
1203 * This function frees the memory allocated to the q_vectors. In addition if
1204 * NAPI is enabled it will delete any references to the NAPI struct prior
1205 * to freeing the q_vector.
1207 static void i40evf_free_q_vectors(struct i40evf_adapter
*adapter
)
1209 int q_idx
, num_q_vectors
;
1212 num_q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
1213 napi_vectors
= adapter
->vsi_res
->num_queue_pairs
;
1215 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
1216 struct i40e_q_vector
*q_vector
= adapter
->q_vector
[q_idx
];
1218 adapter
->q_vector
[q_idx
] = NULL
;
1219 if (q_idx
< napi_vectors
)
1220 netif_napi_del(&q_vector
->napi
);
1226 * i40evf_reset_interrupt_capability - Reset MSIX setup
1227 * @adapter: board private structure
1230 void i40evf_reset_interrupt_capability(struct i40evf_adapter
*adapter
)
1232 pci_disable_msix(adapter
->pdev
);
1233 kfree(adapter
->msix_entries
);
1234 adapter
->msix_entries
= NULL
;
1238 * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
1239 * @adapter: board private structure to initialize
1242 int i40evf_init_interrupt_scheme(struct i40evf_adapter
*adapter
)
1246 err
= i40evf_set_interrupt_capability(adapter
);
1248 dev_err(&adapter
->pdev
->dev
,
1249 "Unable to setup interrupt capabilities\n");
1250 goto err_set_interrupt
;
1253 err
= i40evf_alloc_q_vectors(adapter
);
1255 dev_err(&adapter
->pdev
->dev
,
1256 "Unable to allocate memory for queue vectors\n");
1257 goto err_alloc_q_vectors
;
1260 err
= i40evf_alloc_queues(adapter
);
1262 dev_err(&adapter
->pdev
->dev
,
1263 "Unable to allocate memory for queues\n");
1264 goto err_alloc_queues
;
1267 dev_info(&adapter
->pdev
->dev
, "Multiqueue %s: Queue pair count = %u",
1268 (adapter
->vsi_res
->num_queue_pairs
> 1) ? "Enabled" :
1269 "Disabled", adapter
->vsi_res
->num_queue_pairs
);
1273 i40evf_free_q_vectors(adapter
);
1274 err_alloc_q_vectors
:
1275 i40evf_reset_interrupt_capability(adapter
);
1281 * i40evf_watchdog_timer - Periodic call-back timer
1282 * @data: pointer to adapter disguised as unsigned long
1284 static void i40evf_watchdog_timer(unsigned long data
)
1286 struct i40evf_adapter
*adapter
= (struct i40evf_adapter
*)data
;
1287 schedule_work(&adapter
->watchdog_task
);
1288 /* timer will be rescheduled in watchdog task */
1292 * i40evf_watchdog_task - Periodic call-back task
1293 * @work: pointer to work_struct
1295 static void i40evf_watchdog_task(struct work_struct
*work
)
1297 struct i40evf_adapter
*adapter
= container_of(work
,
1298 struct i40evf_adapter
,
1300 struct i40e_hw
*hw
= &adapter
->hw
;
1303 if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
))
1304 goto restart_watchdog
;
1306 if (adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
) {
1307 rstat_val
= rd32(hw
, I40E_VFGEN_RSTAT
) &
1308 I40E_VFGEN_RSTAT_VFR_STATE_MASK
;
1309 if ((rstat_val
== I40E_VFR_VFACTIVE
) ||
1310 (rstat_val
== I40E_VFR_COMPLETED
)) {
1311 /* A chance for redemption! */
1312 dev_err(&adapter
->pdev
->dev
, "Hardware came out of reset. Attempting reinit.\n");
1313 adapter
->state
= __I40EVF_STARTUP
;
1314 adapter
->flags
&= ~I40EVF_FLAG_PF_COMMS_FAILED
;
1315 schedule_delayed_work(&adapter
->init_task
, 10);
1316 clear_bit(__I40EVF_IN_CRITICAL_TASK
,
1317 &adapter
->crit_section
);
1318 /* Don't reschedule the watchdog, since we've restarted
1319 * the init task. When init_task contacts the PF and
1320 * gets everything set up again, it'll restart the
1321 * watchdog for us. Down, boy. Sit. Stay. Woof.
1325 adapter
->aq_pending
= 0;
1326 adapter
->aq_required
= 0;
1327 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
1331 if ((adapter
->state
< __I40EVF_DOWN
) ||
1332 (adapter
->flags
& I40EVF_FLAG_RESET_PENDING
))
1335 /* check for reset */
1336 rstat_val
= rd32(hw
, I40E_VFGEN_RSTAT
) &
1337 I40E_VFGEN_RSTAT_VFR_STATE_MASK
;
1338 if (!(adapter
->flags
& I40EVF_FLAG_RESET_PENDING
) &&
1339 (rstat_val
!= I40E_VFR_VFACTIVE
) &&
1340 (rstat_val
!= I40E_VFR_COMPLETED
)) {
1341 adapter
->state
= __I40EVF_RESETTING
;
1342 adapter
->flags
|= I40EVF_FLAG_RESET_PENDING
;
1343 dev_err(&adapter
->pdev
->dev
, "Hardware reset detected\n");
1344 schedule_work(&adapter
->reset_task
);
1345 adapter
->aq_pending
= 0;
1346 adapter
->aq_required
= 0;
1347 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
1351 /* Process admin queue tasks. After init, everything gets done
1352 * here so we don't race on the admin queue.
1354 if (adapter
->aq_pending
)
1357 if (adapter
->aq_required
& I40EVF_FLAG_AQ_MAP_VECTORS
) {
1358 i40evf_map_queues(adapter
);
1362 if (adapter
->aq_required
& I40EVF_FLAG_AQ_ADD_MAC_FILTER
) {
1363 i40evf_add_ether_addrs(adapter
);
1367 if (adapter
->aq_required
& I40EVF_FLAG_AQ_ADD_VLAN_FILTER
) {
1368 i40evf_add_vlans(adapter
);
1372 if (adapter
->aq_required
& I40EVF_FLAG_AQ_DEL_MAC_FILTER
) {
1373 i40evf_del_ether_addrs(adapter
);
1377 if (adapter
->aq_required
& I40EVF_FLAG_AQ_DEL_VLAN_FILTER
) {
1378 i40evf_del_vlans(adapter
);
1382 if (adapter
->aq_required
& I40EVF_FLAG_AQ_DISABLE_QUEUES
) {
1383 i40evf_disable_queues(adapter
);
1387 if (adapter
->aq_required
& I40EVF_FLAG_AQ_CONFIGURE_QUEUES
) {
1388 i40evf_configure_queues(adapter
);
1392 if (adapter
->aq_required
& I40EVF_FLAG_AQ_ENABLE_QUEUES
) {
1393 i40evf_enable_queues(adapter
);
1397 if (adapter
->state
== __I40EVF_RUNNING
)
1398 i40evf_request_stats(adapter
);
1400 i40evf_irq_enable(adapter
, true);
1401 i40evf_fire_sw_int(adapter
, 0xFF);
1404 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1406 if (adapter
->state
== __I40EVF_REMOVE
)
1408 if (adapter
->aq_required
)
1409 mod_timer(&adapter
->watchdog_timer
,
1410 jiffies
+ msecs_to_jiffies(20));
1412 mod_timer(&adapter
->watchdog_timer
, jiffies
+ (HZ
* 2));
1413 schedule_work(&adapter
->adminq_task
);
1417 * next_queue - increment to next available tx queue
1418 * @adapter: board private structure
1421 * Helper function for RSS programming to increment through available
1422 * queus. Returns the next queue value.
1424 static int next_queue(struct i40evf_adapter
*adapter
, int j
)
1428 return j
>= adapter
->vsi_res
->num_queue_pairs
? 0 : j
;
1432 * i40evf_configure_rss - Prepare for RSS if used
1433 * @adapter: board private structure
1435 static void i40evf_configure_rss(struct i40evf_adapter
*adapter
)
1437 struct i40e_hw
*hw
= &adapter
->hw
;
1442 /* Set of random keys generated using kernel random number generator */
1443 static const u32 seed
[I40E_VFQF_HKEY_MAX_INDEX
+ 1] = {
1444 0x794221b4, 0xbca0c5ab, 0x6cd5ebd9, 0x1ada6127,
1445 0x983b3aa1, 0x1c4e71eb, 0x7f6328b2, 0xfcdc0da0,
1446 0xc135cafa, 0x7a6f7e2d, 0xe7102d28, 0x163cd12e,
1449 /* Hash type is configured by the PF - we just supply the key */
1451 /* Fill out hash function seed */
1452 for (i
= 0; i
<= I40E_VFQF_HKEY_MAX_INDEX
; i
++)
1453 wr32(hw
, I40E_VFQF_HKEY(i
), seed
[i
]);
1455 /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
1456 hena
= I40E_DEFAULT_RSS_HENA
;
1457 wr32(hw
, I40E_VFQF_HENA(0), (u32
)hena
);
1458 wr32(hw
, I40E_VFQF_HENA(1), (u32
)(hena
>> 32));
1460 /* Populate the LUT with max no. of queues in round robin fashion */
1461 j
= adapter
->vsi_res
->num_queue_pairs
;
1462 for (i
= 0; i
<= I40E_VFQF_HLUT_MAX_INDEX
; i
++) {
1463 j
= next_queue(adapter
, j
);
1465 j
= next_queue(adapter
, j
);
1467 j
= next_queue(adapter
, j
);
1469 j
= next_queue(adapter
, j
);
1471 wr32(hw
, I40E_VFQF_HLUT(i
), lut
);
1476 #define I40EVF_RESET_WAIT_MS 100
1477 #define I40EVF_RESET_WAIT_COUNT 200
1479 * i40evf_reset_task - Call-back task to handle hardware reset
1480 * @work: pointer to work_struct
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.
1486 static void i40evf_reset_task(struct work_struct
*work
)
1488 struct i40evf_adapter
*adapter
= container_of(work
,
1489 struct i40evf_adapter
,
1491 struct i40e_hw
*hw
= &adapter
->hw
;
1495 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
1496 &adapter
->crit_section
))
1499 if (adapter
->flags
& I40EVF_FLAG_RESET_NEEDED
) {
1500 dev_info(&adapter
->pdev
->dev
, "Requesting reset from PF\n");
1501 i40evf_request_reset(adapter
);
1504 /* poll until we see the reset actually happen */
1505 for (i
= 0; i
< I40EVF_RESET_WAIT_COUNT
; i
++) {
1506 rstat_val
= rd32(hw
, I40E_VFGEN_RSTAT
) &
1507 I40E_VFGEN_RSTAT_VFR_STATE_MASK
;
1508 if ((rstat_val
!= I40E_VFR_VFACTIVE
) &&
1509 (rstat_val
!= I40E_VFR_COMPLETED
))
1512 msleep(I40EVF_RESET_WAIT_MS
);
1514 if (i
== I40EVF_RESET_WAIT_COUNT
) {
1515 adapter
->flags
&= ~I40EVF_FLAG_RESET_PENDING
;
1516 goto continue_reset
; /* act like the reset happened */
1519 /* wait until the reset is complete and the PF is responding to us */
1520 for (i
= 0; i
< I40EVF_RESET_WAIT_COUNT
; i
++) {
1521 rstat_val
= rd32(hw
, I40E_VFGEN_RSTAT
) &
1522 I40E_VFGEN_RSTAT_VFR_STATE_MASK
;
1523 if ((rstat_val
== I40E_VFR_VFACTIVE
) ||
1524 (rstat_val
== I40E_VFR_COMPLETED
))
1527 msleep(I40EVF_RESET_WAIT_MS
);
1529 if (i
== I40EVF_RESET_WAIT_COUNT
) {
1530 struct i40evf_mac_filter
*f
, *ftmp
;
1531 struct i40evf_vlan_filter
*fv
, *fvtmp
;
1533 /* reset never finished */
1534 dev_err(&adapter
->pdev
->dev
, "Reset never finished (%x)\n",
1536 adapter
->flags
|= I40EVF_FLAG_PF_COMMS_FAILED
;
1538 if (netif_running(adapter
->netdev
)) {
1539 set_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
1540 i40evf_down(adapter
);
1541 i40evf_free_traffic_irqs(adapter
);
1542 i40evf_free_all_tx_resources(adapter
);
1543 i40evf_free_all_rx_resources(adapter
);
1546 /* Delete all of the filters, both MAC and VLAN. */
1547 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
,
1552 list_for_each_entry_safe(fv
, fvtmp
, &adapter
->vlan_filter_list
,
1554 list_del(&fv
->list
);
1558 i40evf_free_misc_irq(adapter
);
1559 i40evf_reset_interrupt_capability(adapter
);
1560 i40evf_free_queues(adapter
);
1561 i40evf_free_q_vectors(adapter
);
1562 kfree(adapter
->vf_res
);
1563 i40evf_shutdown_adminq(hw
);
1564 adapter
->netdev
->flags
&= ~IFF_UP
;
1565 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1566 return; /* Do not attempt to reinit. It's dead, Jim. */
1570 adapter
->flags
&= ~I40EVF_FLAG_RESET_PENDING
;
1572 i40evf_down(adapter
);
1573 adapter
->state
= __I40EVF_RESETTING
;
1575 /* kill and reinit the admin queue */
1576 if (i40evf_shutdown_adminq(hw
))
1577 dev_warn(&adapter
->pdev
->dev
,
1578 "%s: Failed to destroy the Admin Queue resources\n",
1580 err
= i40evf_init_adminq(hw
);
1582 dev_info(&adapter
->pdev
->dev
, "%s: init_adminq failed: %d\n",
1585 adapter
->aq_pending
= 0;
1586 adapter
->aq_required
= 0;
1587 i40evf_map_queues(adapter
);
1588 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1590 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 2);
1592 if (netif_running(adapter
->netdev
)) {
1593 /* allocate transmit descriptors */
1594 err
= i40evf_setup_all_tx_resources(adapter
);
1598 /* allocate receive descriptors */
1599 err
= i40evf_setup_all_rx_resources(adapter
);
1603 i40evf_configure(adapter
);
1605 err
= i40evf_up_complete(adapter
);
1609 i40evf_irq_enable(adapter
, true);
1613 dev_err(&adapter
->pdev
->dev
, "failed to allocate resources during reinit\n");
1614 i40evf_close(adapter
->netdev
);
1618 * i40evf_adminq_task - worker thread to clean the admin queue
1619 * @work: pointer to work_struct containing our data
1621 static void i40evf_adminq_task(struct work_struct
*work
)
1623 struct i40evf_adapter
*adapter
=
1624 container_of(work
, struct i40evf_adapter
, adminq_task
);
1625 struct i40e_hw
*hw
= &adapter
->hw
;
1626 struct i40e_arq_event_info event
;
1627 struct i40e_virtchnl_msg
*v_msg
;
1632 if (adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
)
1635 event
.msg_size
= I40EVF_MAX_AQ_BUF_SIZE
;
1636 event
.msg_buf
= kzalloc(event
.msg_size
, GFP_KERNEL
);
1640 v_msg
= (struct i40e_virtchnl_msg
*)&event
.desc
;
1642 ret
= i40evf_clean_arq_element(hw
, &event
, &pending
);
1644 break; /* No event to process or error cleaning ARQ */
1646 i40evf_virtchnl_completion(adapter
, v_msg
->v_opcode
,
1647 v_msg
->v_retval
, event
.msg_buf
,
1650 dev_info(&adapter
->pdev
->dev
,
1651 "%s: ARQ: Pending events %d\n",
1653 memset(event
.msg_buf
, 0, I40EVF_MAX_AQ_BUF_SIZE
);
1657 /* check for error indications */
1658 val
= rd32(hw
, hw
->aq
.arq
.len
);
1660 if (val
& I40E_VF_ARQLEN_ARQVFE_MASK
) {
1661 dev_info(&adapter
->pdev
->dev
, "ARQ VF Error detected\n");
1662 val
&= ~I40E_VF_ARQLEN_ARQVFE_MASK
;
1664 if (val
& I40E_VF_ARQLEN_ARQOVFL_MASK
) {
1665 dev_info(&adapter
->pdev
->dev
, "ARQ Overflow Error detected\n");
1666 val
&= ~I40E_VF_ARQLEN_ARQOVFL_MASK
;
1668 if (val
& I40E_VF_ARQLEN_ARQCRIT_MASK
) {
1669 dev_info(&adapter
->pdev
->dev
, "ARQ Critical Error detected\n");
1670 val
&= ~I40E_VF_ARQLEN_ARQCRIT_MASK
;
1673 wr32(hw
, hw
->aq
.arq
.len
, val
);
1675 val
= rd32(hw
, hw
->aq
.asq
.len
);
1677 if (val
& I40E_VF_ATQLEN_ATQVFE_MASK
) {
1678 dev_info(&adapter
->pdev
->dev
, "ASQ VF Error detected\n");
1679 val
&= ~I40E_VF_ATQLEN_ATQVFE_MASK
;
1681 if (val
& I40E_VF_ATQLEN_ATQOVFL_MASK
) {
1682 dev_info(&adapter
->pdev
->dev
, "ASQ Overflow Error detected\n");
1683 val
&= ~I40E_VF_ATQLEN_ATQOVFL_MASK
;
1685 if (val
& I40E_VF_ATQLEN_ATQCRIT_MASK
) {
1686 dev_info(&adapter
->pdev
->dev
, "ASQ Critical Error detected\n");
1687 val
&= ~I40E_VF_ATQLEN_ATQCRIT_MASK
;
1690 wr32(hw
, hw
->aq
.asq
.len
, val
);
1692 /* re-enable Admin queue interrupt cause */
1693 i40evf_misc_irq_enable(adapter
);
1695 kfree(event
.msg_buf
);
1699 * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
1700 * @adapter: board private structure
1702 * Free all transmit software resources
1704 static void i40evf_free_all_tx_resources(struct i40evf_adapter
*adapter
)
1708 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++)
1709 if (adapter
->tx_rings
[i
]->desc
)
1710 i40evf_free_tx_resources(adapter
->tx_rings
[i
]);
1715 * i40evf_setup_all_tx_resources - allocate all queues Tx resources
1716 * @adapter: board private structure
1718 * If this function returns with an error, then it's possible one or
1719 * more of the rings is populated (while the rest are not). It is the
1720 * callers duty to clean those orphaned rings.
1722 * Return 0 on success, negative on failure
1724 static int i40evf_setup_all_tx_resources(struct i40evf_adapter
*adapter
)
1728 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++) {
1729 adapter
->tx_rings
[i
]->count
= adapter
->tx_desc_count
;
1730 err
= i40evf_setup_tx_descriptors(adapter
->tx_rings
[i
]);
1733 dev_err(&adapter
->pdev
->dev
,
1734 "%s: Allocation for Tx Queue %u failed\n",
1743 * i40evf_setup_all_rx_resources - allocate all queues Rx resources
1744 * @adapter: board private structure
1746 * If this function returns with an error, then it's possible one or
1747 * more of the rings is populated (while the rest are not). It is the
1748 * callers duty to clean those orphaned rings.
1750 * Return 0 on success, negative on failure
1752 static int i40evf_setup_all_rx_resources(struct i40evf_adapter
*adapter
)
1756 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++) {
1757 adapter
->rx_rings
[i
]->count
= adapter
->rx_desc_count
;
1758 err
= i40evf_setup_rx_descriptors(adapter
->rx_rings
[i
]);
1761 dev_err(&adapter
->pdev
->dev
,
1762 "%s: Allocation for Rx Queue %u failed\n",
1770 * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
1771 * @adapter: board private structure
1773 * Free all receive software resources
1775 static void i40evf_free_all_rx_resources(struct i40evf_adapter
*adapter
)
1779 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++)
1780 if (adapter
->rx_rings
[i
]->desc
)
1781 i40evf_free_rx_resources(adapter
->rx_rings
[i
]);
1785 * i40evf_open - Called when a network interface is made active
1786 * @netdev: network interface device structure
1788 * Returns 0 on success, negative value on failure
1790 * The open entry point is called when a network interface is made
1791 * active by the system (IFF_UP). At this point all resources needed
1792 * for transmit and receive operations are allocated, the interrupt
1793 * handler is registered with the OS, the watchdog timer is started,
1794 * and the stack is notified that the interface is ready.
1796 static int i40evf_open(struct net_device
*netdev
)
1798 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
1801 if (adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
) {
1802 dev_err(&adapter
->pdev
->dev
, "Unable to open device due to PF driver failure.\n");
1805 if (adapter
->state
!= __I40EVF_DOWN
)
1808 /* allocate transmit descriptors */
1809 err
= i40evf_setup_all_tx_resources(adapter
);
1813 /* allocate receive descriptors */
1814 err
= i40evf_setup_all_rx_resources(adapter
);
1818 /* clear any pending interrupts, may auto mask */
1819 err
= i40evf_request_traffic_irqs(adapter
, netdev
->name
);
1823 i40evf_configure(adapter
);
1825 err
= i40evf_up_complete(adapter
);
1829 i40evf_irq_enable(adapter
, true);
1834 i40evf_down(adapter
);
1835 i40evf_free_traffic_irqs(adapter
);
1837 i40evf_free_all_rx_resources(adapter
);
1839 i40evf_free_all_tx_resources(adapter
);
1845 * i40evf_close - Disables a network interface
1846 * @netdev: network interface device structure
1848 * Returns 0, this is not allowed to fail
1850 * The close entry point is called when an interface is de-activated
1851 * by the OS. The hardware is still under the drivers control, but
1852 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
1853 * are freed, along with all transmit and receive resources.
1855 static int i40evf_close(struct net_device
*netdev
)
1857 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
1859 if (adapter
->state
<= __I40EVF_DOWN
)
1863 set_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
1865 i40evf_down(adapter
);
1866 adapter
->state
= __I40EVF_DOWN
;
1867 i40evf_free_traffic_irqs(adapter
);
1869 i40evf_free_all_tx_resources(adapter
);
1870 i40evf_free_all_rx_resources(adapter
);
1876 * i40evf_get_stats - Get System Network Statistics
1877 * @netdev: network interface device structure
1879 * Returns the address of the device statistics structure.
1880 * The statistics are actually updated from the timer callback.
1882 static struct net_device_stats
*i40evf_get_stats(struct net_device
*netdev
)
1884 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
1886 /* only return the current stats */
1887 return &adapter
->net_stats
;
1891 * i40evf_reinit_locked - Software reinit
1892 * @adapter: board private structure
1894 * Reinititalizes the ring structures in response to a software configuration
1895 * change. Roughly the same as close followed by open, but skips releasing
1896 * and reallocating the interrupts.
1898 void i40evf_reinit_locked(struct i40evf_adapter
*adapter
)
1900 struct net_device
*netdev
= adapter
->netdev
;
1903 WARN_ON(in_interrupt());
1905 i40evf_down(adapter
);
1907 /* allocate transmit descriptors */
1908 err
= i40evf_setup_all_tx_resources(adapter
);
1912 /* allocate receive descriptors */
1913 err
= i40evf_setup_all_rx_resources(adapter
);
1917 i40evf_configure(adapter
);
1919 err
= i40evf_up_complete(adapter
);
1923 i40evf_irq_enable(adapter
, true);
1927 dev_err(&adapter
->pdev
->dev
, "failed to allocate resources during reinit\n");
1928 i40evf_close(netdev
);
1932 * i40evf_change_mtu - Change the Maximum Transfer Unit
1933 * @netdev: network interface device structure
1934 * @new_mtu: new value for maximum frame size
1936 * Returns 0 on success, negative on failure
1938 static int i40evf_change_mtu(struct net_device
*netdev
, int new_mtu
)
1940 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
1941 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
1943 if ((new_mtu
< 68) || (max_frame
> I40E_MAX_RXBUFFER
))
1946 /* must set new MTU before calling down or up */
1947 netdev
->mtu
= new_mtu
;
1948 i40evf_reinit_locked(adapter
);
1952 static const struct net_device_ops i40evf_netdev_ops
= {
1953 .ndo_open
= i40evf_open
,
1954 .ndo_stop
= i40evf_close
,
1955 .ndo_start_xmit
= i40evf_xmit_frame
,
1956 .ndo_get_stats
= i40evf_get_stats
,
1957 .ndo_set_rx_mode
= i40evf_set_rx_mode
,
1958 .ndo_validate_addr
= eth_validate_addr
,
1959 .ndo_set_mac_address
= i40evf_set_mac
,
1960 .ndo_change_mtu
= i40evf_change_mtu
,
1961 .ndo_tx_timeout
= i40evf_tx_timeout
,
1962 .ndo_vlan_rx_add_vid
= i40evf_vlan_rx_add_vid
,
1963 .ndo_vlan_rx_kill_vid
= i40evf_vlan_rx_kill_vid
,
1967 * i40evf_check_reset_complete - check that VF reset is complete
1968 * @hw: pointer to hw struct
1970 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
1972 static int i40evf_check_reset_complete(struct i40e_hw
*hw
)
1977 for (i
= 0; i
< 100; i
++) {
1978 rstat
= rd32(hw
, I40E_VFGEN_RSTAT
) &
1979 I40E_VFGEN_RSTAT_VFR_STATE_MASK
;
1980 if ((rstat
== I40E_VFR_VFACTIVE
) ||
1981 (rstat
== I40E_VFR_COMPLETED
))
1989 * i40evf_init_task - worker thread to perform delayed initialization
1990 * @work: pointer to work_struct containing our data
1992 * This task completes the work that was begun in probe. Due to the nature
1993 * of VF-PF communications, we may need to wait tens of milliseconds to get
1994 * reponses back from the PF. Rather than busy-wait in probe and bog down the
1995 * whole system, we'll do it in a task so we can sleep.
1996 * This task only runs during driver init. Once we've established
1997 * communications with the PF driver and set up our netdev, the watchdog
2000 static void i40evf_init_task(struct work_struct
*work
)
2002 struct i40evf_adapter
*adapter
= container_of(work
,
2003 struct i40evf_adapter
,
2005 struct net_device
*netdev
= adapter
->netdev
;
2006 struct i40evf_mac_filter
*f
;
2007 struct i40e_hw
*hw
= &adapter
->hw
;
2008 struct pci_dev
*pdev
= adapter
->pdev
;
2011 switch (adapter
->state
) {
2012 case __I40EVF_STARTUP
:
2013 /* driver loaded, probe complete */
2014 adapter
->flags
&= ~I40EVF_FLAG_PF_COMMS_FAILED
;
2015 adapter
->flags
&= ~I40EVF_FLAG_RESET_PENDING
;
2016 err
= i40e_set_mac_type(hw
);
2018 dev_err(&pdev
->dev
, "Failed to set MAC type (%d)\n",
2022 err
= i40evf_check_reset_complete(hw
);
2024 dev_info(&pdev
->dev
, "Device is still in reset (%d), retrying\n",
2028 hw
->aq
.num_arq_entries
= I40EVF_AQ_LEN
;
2029 hw
->aq
.num_asq_entries
= I40EVF_AQ_LEN
;
2030 hw
->aq
.arq_buf_size
= I40EVF_MAX_AQ_BUF_SIZE
;
2031 hw
->aq
.asq_buf_size
= I40EVF_MAX_AQ_BUF_SIZE
;
2033 err
= i40evf_init_adminq(hw
);
2035 dev_err(&pdev
->dev
, "Failed to init Admin Queue (%d)\n",
2039 err
= i40evf_send_api_ver(adapter
);
2041 dev_err(&pdev
->dev
, "Unable to send to PF (%d)\n", err
);
2042 i40evf_shutdown_adminq(hw
);
2045 adapter
->state
= __I40EVF_INIT_VERSION_CHECK
;
2047 case __I40EVF_INIT_VERSION_CHECK
:
2048 if (!i40evf_asq_done(hw
)) {
2049 dev_err(&pdev
->dev
, "Admin queue command never completed\n");
2053 /* aq msg sent, awaiting reply */
2054 err
= i40evf_verify_api_ver(adapter
);
2056 dev_info(&pdev
->dev
, "Unable to verify API version (%d), retrying\n",
2058 if (err
== I40E_ERR_ADMIN_QUEUE_NO_WORK
) {
2059 dev_info(&pdev
->dev
, "Resending request\n");
2060 err
= i40evf_send_api_ver(adapter
);
2064 err
= i40evf_send_vf_config_msg(adapter
);
2066 dev_err(&pdev
->dev
, "Unable to send config request (%d)\n",
2070 adapter
->state
= __I40EVF_INIT_GET_RESOURCES
;
2072 case __I40EVF_INIT_GET_RESOURCES
:
2073 /* aq msg sent, awaiting reply */
2074 if (!adapter
->vf_res
) {
2075 bufsz
= sizeof(struct i40e_virtchnl_vf_resource
) +
2077 sizeof(struct i40e_virtchnl_vsi_resource
));
2078 adapter
->vf_res
= kzalloc(bufsz
, GFP_KERNEL
);
2079 if (!adapter
->vf_res
)
2082 err
= i40evf_get_vf_config(adapter
);
2083 if (err
== I40E_ERR_ADMIN_QUEUE_NO_WORK
)
2086 dev_err(&pdev
->dev
, "Unable to get VF config (%d)\n",
2090 adapter
->state
= __I40EVF_INIT_SW
;
2095 /* got VF config message back from PF, now we can parse it */
2096 for (i
= 0; i
< adapter
->vf_res
->num_vsis
; i
++) {
2097 if (adapter
->vf_res
->vsi_res
[i
].vsi_type
== I40E_VSI_SRIOV
)
2098 adapter
->vsi_res
= &adapter
->vf_res
->vsi_res
[i
];
2100 if (!adapter
->vsi_res
) {
2101 dev_err(&pdev
->dev
, "No LAN VSI found\n");
2105 adapter
->flags
|= I40EVF_FLAG_RX_CSUM_ENABLED
;
2107 netdev
->netdev_ops
= &i40evf_netdev_ops
;
2108 i40evf_set_ethtool_ops(netdev
);
2109 netdev
->watchdog_timeo
= 5 * HZ
;
2110 netdev
->features
|= NETIF_F_HIGHDMA
|
2120 if (adapter
->vf_res
->vf_offload_flags
2121 & I40E_VIRTCHNL_VF_OFFLOAD_VLAN
) {
2122 netdev
->vlan_features
= netdev
->features
;
2123 netdev
->features
|= NETIF_F_HW_VLAN_CTAG_TX
|
2124 NETIF_F_HW_VLAN_CTAG_RX
|
2125 NETIF_F_HW_VLAN_CTAG_FILTER
;
2128 /* copy netdev features into list of user selectable features */
2129 netdev
->hw_features
|= netdev
->features
;
2130 netdev
->hw_features
&= ~NETIF_F_RXCSUM
;
2132 if (!is_valid_ether_addr(adapter
->hw
.mac
.addr
)) {
2133 dev_info(&pdev
->dev
, "Invalid MAC address %pM, using random\n",
2134 adapter
->hw
.mac
.addr
);
2135 random_ether_addr(adapter
->hw
.mac
.addr
);
2137 ether_addr_copy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
);
2138 ether_addr_copy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
);
2140 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
2144 ether_addr_copy(f
->macaddr
, adapter
->hw
.mac
.addr
);
2146 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_MAC_FILTER
;
2148 list_add(&f
->list
, &adapter
->mac_filter_list
);
2150 init_timer(&adapter
->watchdog_timer
);
2151 adapter
->watchdog_timer
.function
= &i40evf_watchdog_timer
;
2152 adapter
->watchdog_timer
.data
= (unsigned long)adapter
;
2153 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
2155 adapter
->tx_desc_count
= I40EVF_DEFAULT_TXD
;
2156 adapter
->rx_desc_count
= I40EVF_DEFAULT_RXD
;
2157 err
= i40evf_init_interrupt_scheme(adapter
);
2160 i40evf_map_rings_to_vectors(adapter
);
2161 i40evf_configure_rss(adapter
);
2162 err
= i40evf_request_misc_irq(adapter
);
2166 netif_carrier_off(netdev
);
2168 adapter
->vsi
.id
= adapter
->vsi_res
->vsi_id
;
2169 adapter
->vsi
.seid
= adapter
->vsi_res
->vsi_id
; /* dummy */
2170 adapter
->vsi
.back
= adapter
;
2171 adapter
->vsi
.base_vector
= 1;
2172 adapter
->vsi
.work_limit
= I40E_DEFAULT_IRQ_WORK
;
2173 adapter
->vsi
.rx_itr_setting
= (I40E_ITR_DYNAMIC
|
2174 ITR_REG_TO_USEC(I40E_ITR_RX_DEF
));
2175 adapter
->vsi
.tx_itr_setting
= (I40E_ITR_DYNAMIC
|
2176 ITR_REG_TO_USEC(I40E_ITR_TX_DEF
));
2177 adapter
->vsi
.netdev
= adapter
->netdev
;
2179 if (!adapter
->netdev_registered
) {
2180 err
= register_netdev(netdev
);
2185 adapter
->netdev_registered
= true;
2187 netif_tx_stop_all_queues(netdev
);
2189 dev_info(&pdev
->dev
, "MAC address: %pM\n", adapter
->hw
.mac
.addr
);
2190 if (netdev
->features
& NETIF_F_GRO
)
2191 dev_info(&pdev
->dev
, "GRO is enabled\n");
2193 dev_info(&pdev
->dev
, "%s\n", i40evf_driver_string
);
2194 adapter
->state
= __I40EVF_DOWN
;
2195 set_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
2196 i40evf_misc_irq_enable(adapter
);
2199 schedule_delayed_work(&adapter
->init_task
,
2200 msecs_to_jiffies(50));
2204 i40evf_free_misc_irq(adapter
);
2206 i40evf_reset_interrupt_capability(adapter
);
2208 kfree(adapter
->vf_res
);
2209 adapter
->vf_res
= NULL
;
2211 /* Things went into the weeds, so try again later */
2212 if (++adapter
->aq_wait_count
> I40EVF_AQ_MAX_ERR
) {
2213 dev_err(&pdev
->dev
, "Failed to communicate with PF; giving up\n");
2214 adapter
->flags
|= I40EVF_FLAG_PF_COMMS_FAILED
;
2215 return; /* do not reschedule */
2217 schedule_delayed_work(&adapter
->init_task
, HZ
* 3);
2221 * i40evf_shutdown - Shutdown the device in preparation for a reboot
2222 * @pdev: pci device structure
2224 static void i40evf_shutdown(struct pci_dev
*pdev
)
2226 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2228 netif_device_detach(netdev
);
2230 if (netif_running(netdev
))
2231 i40evf_close(netdev
);
2234 pci_save_state(pdev
);
2237 pci_disable_device(pdev
);
2241 * i40evf_probe - Device Initialization Routine
2242 * @pdev: PCI device information struct
2243 * @ent: entry in i40evf_pci_tbl
2245 * Returns 0 on success, negative on failure
2247 * i40evf_probe initializes an adapter identified by a pci_dev structure.
2248 * The OS initialization, configuring of the adapter private structure,
2249 * and a hardware reset occur.
2251 static int i40evf_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2253 struct net_device
*netdev
;
2254 struct i40evf_adapter
*adapter
= NULL
;
2255 struct i40e_hw
*hw
= NULL
;
2258 err
= pci_enable_device(pdev
);
2262 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
2264 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
2267 "DMA configuration failed: 0x%x\n", err
);
2272 err
= pci_request_regions(pdev
, i40evf_driver_name
);
2275 "pci_request_regions failed 0x%x\n", err
);
2279 pci_enable_pcie_error_reporting(pdev
);
2281 pci_set_master(pdev
);
2283 netdev
= alloc_etherdev_mq(sizeof(struct i40evf_adapter
),
2287 goto err_alloc_etherdev
;
2290 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
2292 pci_set_drvdata(pdev
, netdev
);
2293 adapter
= netdev_priv(netdev
);
2295 adapter
->netdev
= netdev
;
2296 adapter
->pdev
= pdev
;
2301 adapter
->msg_enable
= (1 << DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
2302 adapter
->state
= __I40EVF_STARTUP
;
2304 /* Call save state here because it relies on the adapter struct. */
2305 pci_save_state(pdev
);
2307 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
2308 pci_resource_len(pdev
, 0));
2313 hw
->vendor_id
= pdev
->vendor
;
2314 hw
->device_id
= pdev
->device
;
2315 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
2316 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
2317 hw
->subsystem_device_id
= pdev
->subsystem_device
;
2318 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
2319 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
2321 INIT_LIST_HEAD(&adapter
->mac_filter_list
);
2322 INIT_LIST_HEAD(&adapter
->vlan_filter_list
);
2324 INIT_WORK(&adapter
->reset_task
, i40evf_reset_task
);
2325 INIT_WORK(&adapter
->adminq_task
, i40evf_adminq_task
);
2326 INIT_WORK(&adapter
->watchdog_task
, i40evf_watchdog_task
);
2327 INIT_DELAYED_WORK(&adapter
->init_task
, i40evf_init_task
);
2328 schedule_delayed_work(&adapter
->init_task
, 10);
2333 free_netdev(netdev
);
2335 pci_release_regions(pdev
);
2338 pci_disable_device(pdev
);
2344 * i40evf_suspend - Power management suspend routine
2345 * @pdev: PCI device information struct
2348 * Called when the system (VM) is entering sleep/suspend.
2350 static int i40evf_suspend(struct pci_dev
*pdev
, pm_message_t state
)
2352 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2353 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2356 netif_device_detach(netdev
);
2358 if (netif_running(netdev
)) {
2360 i40evf_down(adapter
);
2363 i40evf_free_misc_irq(adapter
);
2364 i40evf_reset_interrupt_capability(adapter
);
2366 retval
= pci_save_state(pdev
);
2370 pci_disable_device(pdev
);
2376 * i40evf_resume - Power managment resume routine
2377 * @pdev: PCI device information struct
2379 * Called when the system (VM) is resumed from sleep/suspend.
2381 static int i40evf_resume(struct pci_dev
*pdev
)
2383 struct i40evf_adapter
*adapter
= pci_get_drvdata(pdev
);
2384 struct net_device
*netdev
= adapter
->netdev
;
2387 pci_set_power_state(pdev
, PCI_D0
);
2388 pci_restore_state(pdev
);
2389 /* pci_restore_state clears dev->state_saved so call
2390 * pci_save_state to restore it.
2392 pci_save_state(pdev
);
2394 err
= pci_enable_device_mem(pdev
);
2396 dev_err(&pdev
->dev
, "Cannot enable PCI device from suspend.\n");
2399 pci_set_master(pdev
);
2402 err
= i40evf_set_interrupt_capability(adapter
);
2404 dev_err(&pdev
->dev
, "Cannot enable MSI-X interrupts.\n");
2407 err
= i40evf_request_misc_irq(adapter
);
2410 dev_err(&pdev
->dev
, "Cannot get interrupt vector.\n");
2414 schedule_work(&adapter
->reset_task
);
2416 netif_device_attach(netdev
);
2421 #endif /* CONFIG_PM */
2423 * i40evf_remove - Device Removal Routine
2424 * @pdev: PCI device information struct
2426 * i40evf_remove is called by the PCI subsystem to alert the driver
2427 * that it should release a PCI device. The could be caused by a
2428 * Hot-Plug event, or because the driver is going to be removed from
2431 static void i40evf_remove(struct pci_dev
*pdev
)
2433 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2434 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2435 struct i40evf_mac_filter
*f
, *ftmp
;
2436 struct i40e_hw
*hw
= &adapter
->hw
;
2438 cancel_delayed_work_sync(&adapter
->init_task
);
2439 cancel_work_sync(&adapter
->reset_task
);
2441 if (adapter
->netdev_registered
) {
2442 unregister_netdev(netdev
);
2443 adapter
->netdev_registered
= false;
2445 adapter
->state
= __I40EVF_REMOVE
;
2447 if (adapter
->msix_entries
) {
2448 i40evf_misc_irq_disable(adapter
);
2449 i40evf_free_misc_irq(adapter
);
2450 i40evf_reset_interrupt_capability(adapter
);
2451 i40evf_free_q_vectors(adapter
);
2454 if (adapter
->watchdog_timer
.function
)
2455 del_timer_sync(&adapter
->watchdog_timer
);
2457 flush_scheduled_work();
2459 if (hw
->aq
.asq
.count
)
2460 i40evf_shutdown_adminq(hw
);
2462 iounmap(hw
->hw_addr
);
2463 pci_release_regions(pdev
);
2465 i40evf_free_queues(adapter
);
2466 kfree(adapter
->vf_res
);
2467 /* If we got removed before an up/down sequence, we've got a filter
2468 * hanging out there that we need to get rid of.
2470 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
2475 free_netdev(netdev
);
2477 pci_disable_pcie_error_reporting(pdev
);
2479 pci_disable_device(pdev
);
2482 static struct pci_driver i40evf_driver
= {
2483 .name
= i40evf_driver_name
,
2484 .id_table
= i40evf_pci_tbl
,
2485 .probe
= i40evf_probe
,
2486 .remove
= i40evf_remove
,
2488 .suspend
= i40evf_suspend
,
2489 .resume
= i40evf_resume
,
2491 .shutdown
= i40evf_shutdown
,
2495 * i40e_init_module - Driver Registration Routine
2497 * i40e_init_module is the first routine called when the driver is
2498 * loaded. All it does is register with the PCI subsystem.
2500 static int __init
i40evf_init_module(void)
2503 pr_info("i40evf: %s - version %s\n", i40evf_driver_string
,
2504 i40evf_driver_version
);
2506 pr_info("%s\n", i40evf_copyright
);
2508 ret
= pci_register_driver(&i40evf_driver
);
2512 module_init(i40evf_init_module
);
2515 * i40e_exit_module - Driver Exit Cleanup Routine
2517 * i40e_exit_module is called just before the driver is removed
2520 static void __exit
i40evf_exit_module(void)
2522 pci_unregister_driver(&i40evf_driver
);
2525 module_exit(i40evf_exit_module
);