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 * The full GNU General Public License is included in this distribution in
16 * the file called "COPYING".
18 * Contact Information:
19 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
20 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
22 ******************************************************************************/
25 #include "i40e_prototype.h"
26 static int i40evf_setup_all_tx_resources(struct i40evf_adapter
*adapter
);
27 static int i40evf_setup_all_rx_resources(struct i40evf_adapter
*adapter
);
28 static int i40evf_close(struct net_device
*netdev
);
30 char i40evf_driver_name
[] = "i40evf";
31 static const char i40evf_driver_string
[] =
32 "Intel(R) XL710 X710 Virtual Function Network Driver";
34 #define DRV_VERSION "0.9.21"
35 const char i40evf_driver_version
[] = DRV_VERSION
;
36 static const char i40evf_copyright
[] =
37 "Copyright (c) 2013 - 2014 Intel Corporation.";
39 /* i40evf_pci_tbl - PCI Device ID Table
41 * Wildcard entries (PCI_ANY_ID) should come last
42 * Last entry must be all 0s
44 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
45 * Class, Class Mask, private data (not used) }
47 static DEFINE_PCI_DEVICE_TABLE(i40evf_pci_tbl
) = {
48 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_VF
), 0},
49 /* required last entry */
53 MODULE_DEVICE_TABLE(pci
, i40evf_pci_tbl
);
55 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
56 MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver");
57 MODULE_LICENSE("GPL");
58 MODULE_VERSION(DRV_VERSION
);
61 * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code
62 * @hw: pointer to the HW structure
63 * @mem: ptr to mem struct to fill out
64 * @size: size of memory requested
65 * @alignment: what to align the allocation to
67 i40e_status
i40evf_allocate_dma_mem_d(struct i40e_hw
*hw
,
68 struct i40e_dma_mem
*mem
,
69 u64 size
, u32 alignment
)
71 struct i40evf_adapter
*adapter
= (struct i40evf_adapter
*)hw
->back
;
74 return I40E_ERR_PARAM
;
76 mem
->size
= ALIGN(size
, alignment
);
77 mem
->va
= dma_alloc_coherent(&adapter
->pdev
->dev
, mem
->size
,
78 (dma_addr_t
*)&mem
->pa
, GFP_KERNEL
);
82 return I40E_ERR_NO_MEMORY
;
86 * i40evf_free_dma_mem_d - OS specific memory free for shared code
87 * @hw: pointer to the HW structure
88 * @mem: ptr to mem struct to free
90 i40e_status
i40evf_free_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
)
92 struct i40evf_adapter
*adapter
= (struct i40evf_adapter
*)hw
->back
;
95 return I40E_ERR_PARAM
;
96 dma_free_coherent(&adapter
->pdev
->dev
, mem
->size
,
97 mem
->va
, (dma_addr_t
)mem
->pa
);
102 * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code
103 * @hw: pointer to the HW structure
104 * @mem: ptr to mem struct to fill out
105 * @size: size of memory requested
107 i40e_status
i40evf_allocate_virt_mem_d(struct i40e_hw
*hw
,
108 struct i40e_virt_mem
*mem
, u32 size
)
111 return I40E_ERR_PARAM
;
114 mem
->va
= kzalloc(size
, GFP_KERNEL
);
119 return I40E_ERR_NO_MEMORY
;
123 * i40evf_free_virt_mem_d - OS specific memory free for shared code
124 * @hw: pointer to the HW structure
125 * @mem: ptr to mem struct to free
127 i40e_status
i40evf_free_virt_mem_d(struct i40e_hw
*hw
,
128 struct i40e_virt_mem
*mem
)
131 return I40E_ERR_PARAM
;
133 /* it's ok to kfree a NULL pointer */
140 * i40evf_debug_d - OS dependent version of debug printing
141 * @hw: pointer to the HW structure
142 * @mask: debug level mask
143 * @fmt_str: printf-type format description
145 void i40evf_debug_d(void *hw
, u32 mask
, char *fmt_str
, ...)
150 if (!(mask
& ((struct i40e_hw
*)hw
)->debug_mask
))
153 va_start(argptr
, fmt_str
);
154 vsnprintf(buf
, sizeof(buf
), fmt_str
, argptr
);
157 /* the debug string is already formatted with a newline */
162 * i40evf_tx_timeout - Respond to a Tx Hang
163 * @netdev: network interface device structure
165 static void i40evf_tx_timeout(struct net_device
*netdev
)
167 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
169 adapter
->tx_timeout_count
++;
170 dev_info(&adapter
->pdev
->dev
, "TX timeout detected.\n");
171 if (!(adapter
->flags
& I40EVF_FLAG_RESET_PENDING
)) {
172 adapter
->flags
|= I40EVF_FLAG_RESET_NEEDED
;
173 schedule_work(&adapter
->reset_task
);
178 * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC
179 * @adapter: board private structure
181 static void i40evf_misc_irq_disable(struct i40evf_adapter
*adapter
)
183 struct i40e_hw
*hw
= &adapter
->hw
;
184 wr32(hw
, I40E_VFINT_DYN_CTL01
, 0);
187 rd32(hw
, I40E_VFGEN_RSTAT
);
189 synchronize_irq(adapter
->msix_entries
[0].vector
);
193 * i40evf_misc_irq_enable - Enable default interrupt generation settings
194 * @adapter: board private structure
196 static void i40evf_misc_irq_enable(struct i40evf_adapter
*adapter
)
198 struct i40e_hw
*hw
= &adapter
->hw
;
199 wr32(hw
, I40E_VFINT_DYN_CTL01
, I40E_VFINT_DYN_CTL01_INTENA_MASK
|
200 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK
);
201 wr32(hw
, I40E_VFINT_ICR0_ENA1
, I40E_VFINT_ICR0_ENA_ADMINQ_MASK
);
204 rd32(hw
, I40E_VFGEN_RSTAT
);
208 * i40evf_irq_disable - Mask off interrupt generation on the NIC
209 * @adapter: board private structure
211 static void i40evf_irq_disable(struct i40evf_adapter
*adapter
)
214 struct i40e_hw
*hw
= &adapter
->hw
;
216 if (!adapter
->msix_entries
)
219 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
220 wr32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1), 0);
221 synchronize_irq(adapter
->msix_entries
[i
].vector
);
224 rd32(hw
, I40E_VFGEN_RSTAT
);
229 * i40evf_irq_enable_queues - Enable interrupt for specified queues
230 * @adapter: board private structure
231 * @mask: bitmap of queues to enable
233 void i40evf_irq_enable_queues(struct i40evf_adapter
*adapter
, u32 mask
)
235 struct i40e_hw
*hw
= &adapter
->hw
;
238 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
239 if (mask
& (1 << (i
- 1))) {
240 wr32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1),
241 I40E_VFINT_DYN_CTLN1_INTENA_MASK
|
242 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK
);
248 * i40evf_fire_sw_int - Generate SW interrupt for specified vectors
249 * @adapter: board private structure
250 * @mask: bitmap of vectors to trigger
252 static void i40evf_fire_sw_int(struct i40evf_adapter
*adapter
,
255 struct i40e_hw
*hw
= &adapter
->hw
;
259 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
260 if (mask
& (1 << i
)) {
261 dyn_ctl
= rd32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1));
262 dyn_ctl
|= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK
|
263 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK
;
264 wr32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1), dyn_ctl
);
270 * i40evf_irq_enable - Enable default interrupt generation settings
271 * @adapter: board private structure
273 void i40evf_irq_enable(struct i40evf_adapter
*adapter
, bool flush
)
275 struct i40e_hw
*hw
= &adapter
->hw
;
277 i40evf_irq_enable_queues(adapter
, ~0);
280 rd32(hw
, I40E_VFGEN_RSTAT
);
284 * i40evf_msix_aq - Interrupt handler for vector 0
285 * @irq: interrupt number
286 * @data: pointer to netdev
288 static irqreturn_t
i40evf_msix_aq(int irq
, void *data
)
290 struct net_device
*netdev
= data
;
291 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
292 struct i40e_hw
*hw
= &adapter
->hw
;
296 /* handle non-queue interrupts */
297 val
= rd32(hw
, I40E_VFINT_ICR01
);
298 ena_mask
= rd32(hw
, I40E_VFINT_ICR0_ENA1
);
301 val
= rd32(hw
, I40E_VFINT_DYN_CTL01
);
302 val
= val
| I40E_PFINT_DYN_CTL0_CLEARPBA_MASK
;
303 wr32(hw
, I40E_VFINT_DYN_CTL01
, val
);
305 /* re-enable interrupt causes */
306 wr32(hw
, I40E_VFINT_ICR0_ENA1
, ena_mask
);
307 wr32(hw
, I40E_VFINT_DYN_CTL01
, I40E_VFINT_DYN_CTL01_INTENA_MASK
);
309 /* schedule work on the private workqueue */
310 schedule_work(&adapter
->adminq_task
);
316 * i40evf_msix_clean_rings - MSIX mode Interrupt Handler
317 * @irq: interrupt number
318 * @data: pointer to a q_vector
320 static irqreturn_t
i40evf_msix_clean_rings(int irq
, void *data
)
322 struct i40e_q_vector
*q_vector
= data
;
324 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
327 napi_schedule(&q_vector
->napi
);
333 * i40evf_map_vector_to_rxq - associate irqs with rx queues
334 * @adapter: board private structure
335 * @v_idx: interrupt number
336 * @r_idx: queue number
339 i40evf_map_vector_to_rxq(struct i40evf_adapter
*adapter
, int v_idx
, int r_idx
)
341 struct i40e_q_vector
*q_vector
= adapter
->q_vector
[v_idx
];
342 struct i40e_ring
*rx_ring
= adapter
->rx_rings
[r_idx
];
344 rx_ring
->q_vector
= q_vector
;
345 rx_ring
->next
= q_vector
->rx
.ring
;
346 rx_ring
->vsi
= &adapter
->vsi
;
347 q_vector
->rx
.ring
= rx_ring
;
348 q_vector
->rx
.count
++;
349 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
353 * i40evf_map_vector_to_txq - associate irqs with tx queues
354 * @adapter: board private structure
355 * @v_idx: interrupt number
356 * @t_idx: queue number
359 i40evf_map_vector_to_txq(struct i40evf_adapter
*adapter
, int v_idx
, int t_idx
)
361 struct i40e_q_vector
*q_vector
= adapter
->q_vector
[v_idx
];
362 struct i40e_ring
*tx_ring
= adapter
->tx_rings
[t_idx
];
364 tx_ring
->q_vector
= q_vector
;
365 tx_ring
->next
= q_vector
->tx
.ring
;
366 tx_ring
->vsi
= &adapter
->vsi
;
367 q_vector
->tx
.ring
= tx_ring
;
368 q_vector
->tx
.count
++;
369 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
370 q_vector
->num_ringpairs
++;
371 q_vector
->ring_mask
|= (1 << t_idx
);
375 * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors
376 * @adapter: board private structure to initialize
378 * This function maps descriptor rings to the queue-specific vectors
379 * we were allotted through the MSI-X enabling code. Ideally, we'd have
380 * one vector per ring/queue, but on a constrained vector budget, we
381 * group the rings as "efficiently" as possible. You would add new
382 * mapping configurations in here.
384 static int i40evf_map_rings_to_vectors(struct i40evf_adapter
*adapter
)
388 int rxr_idx
= 0, txr_idx
= 0;
389 int rxr_remaining
= adapter
->vsi_res
->num_queue_pairs
;
390 int txr_remaining
= adapter
->vsi_res
->num_queue_pairs
;
395 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
397 /* The ideal configuration...
398 * We have enough vectors to map one per queue.
400 if (q_vectors
== (rxr_remaining
* 2)) {
401 for (; rxr_idx
< rxr_remaining
; v_start
++, rxr_idx
++)
402 i40evf_map_vector_to_rxq(adapter
, v_start
, rxr_idx
);
404 for (; txr_idx
< txr_remaining
; v_start
++, txr_idx
++)
405 i40evf_map_vector_to_txq(adapter
, v_start
, txr_idx
);
409 /* If we don't have enough vectors for a 1-to-1
410 * mapping, we'll have to group them so there are
411 * multiple queues per vector.
412 * Re-adjusting *qpv takes care of the remainder.
414 for (i
= v_start
; i
< q_vectors
; i
++) {
415 rqpv
= DIV_ROUND_UP(rxr_remaining
, q_vectors
- i
);
416 for (j
= 0; j
< rqpv
; j
++) {
417 i40evf_map_vector_to_rxq(adapter
, i
, rxr_idx
);
422 for (i
= v_start
; i
< q_vectors
; i
++) {
423 tqpv
= DIV_ROUND_UP(txr_remaining
, q_vectors
- i
);
424 for (j
= 0; j
< tqpv
; j
++) {
425 i40evf_map_vector_to_txq(adapter
, i
, txr_idx
);
432 adapter
->aq_required
|= I40EVF_FLAG_AQ_MAP_VECTORS
;
438 * i40evf_request_traffic_irqs - Initialize MSI-X interrupts
439 * @adapter: board private structure
441 * Allocates MSI-X vectors for tx and rx handling, and requests
442 * interrupts from the kernel.
445 i40evf_request_traffic_irqs(struct i40evf_adapter
*adapter
, char *basename
)
447 int vector
, err
, q_vectors
;
448 int rx_int_idx
= 0, tx_int_idx
= 0;
450 i40evf_irq_disable(adapter
);
451 /* Decrement for Other and TCP Timer vectors */
452 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
454 for (vector
= 0; vector
< q_vectors
; vector
++) {
455 struct i40e_q_vector
*q_vector
= adapter
->q_vector
[vector
];
457 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
458 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
459 "i40evf-%s-%s-%d", basename
,
460 "TxRx", rx_int_idx
++);
462 } else if (q_vector
->rx
.ring
) {
463 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
464 "i40evf-%s-%s-%d", basename
,
466 } else if (q_vector
->tx
.ring
) {
467 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
468 "i40evf-%s-%s-%d", basename
,
471 /* skip this unused q_vector */
475 adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
476 i40evf_msix_clean_rings
,
481 dev_info(&adapter
->pdev
->dev
,
482 "%s: request_irq failed, error: %d\n",
484 goto free_queue_irqs
;
486 /* assign the mask for this irq */
487 irq_set_affinity_hint(
488 adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
489 q_vector
->affinity_mask
);
497 irq_set_affinity_hint(
498 adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
500 free_irq(adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
501 adapter
->q_vector
[vector
]);
507 * i40evf_request_misc_irq - Initialize MSI-X interrupts
508 * @adapter: board private structure
510 * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
511 * vector is only for the admin queue, and stays active even when the netdev
514 static int i40evf_request_misc_irq(struct i40evf_adapter
*adapter
)
516 struct net_device
*netdev
= adapter
->netdev
;
519 sprintf(adapter
->misc_vector_name
, "i40evf:mbx");
520 err
= request_irq(adapter
->msix_entries
[0].vector
,
522 adapter
->misc_vector_name
, netdev
);
524 dev_err(&adapter
->pdev
->dev
,
525 "request_irq for %s failed: %d\n",
526 adapter
->misc_vector_name
, err
);
527 free_irq(adapter
->msix_entries
[0].vector
, netdev
);
533 * i40evf_free_traffic_irqs - Free MSI-X interrupts
534 * @adapter: board private structure
536 * Frees all MSI-X vectors other than 0.
538 static void i40evf_free_traffic_irqs(struct i40evf_adapter
*adapter
)
542 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
544 for (i
= 0; i
< q_vectors
; i
++) {
545 irq_set_affinity_hint(adapter
->msix_entries
[i
+1].vector
,
547 free_irq(adapter
->msix_entries
[i
+1].vector
,
548 adapter
->q_vector
[i
]);
553 * i40evf_free_misc_irq - Free MSI-X miscellaneous vector
554 * @adapter: board private structure
556 * Frees MSI-X vector 0.
558 static void i40evf_free_misc_irq(struct i40evf_adapter
*adapter
)
560 struct net_device
*netdev
= adapter
->netdev
;
562 free_irq(adapter
->msix_entries
[0].vector
, netdev
);
566 * i40evf_configure_tx - Configure Transmit Unit after Reset
567 * @adapter: board private structure
569 * Configure the Tx unit of the MAC after a reset.
571 static void i40evf_configure_tx(struct i40evf_adapter
*adapter
)
573 struct i40e_hw
*hw
= &adapter
->hw
;
575 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++)
576 adapter
->tx_rings
[i
]->tail
= hw
->hw_addr
+ I40E_QTX_TAIL1(i
);
580 * i40evf_configure_rx - Configure Receive Unit after Reset
581 * @adapter: board private structure
583 * Configure the Rx unit of the MAC after a reset.
585 static void i40evf_configure_rx(struct i40evf_adapter
*adapter
)
587 struct i40e_hw
*hw
= &adapter
->hw
;
588 struct net_device
*netdev
= adapter
->netdev
;
589 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
594 adapter
->flags
&= ~I40EVF_FLAG_RX_PS_CAPABLE
;
595 adapter
->flags
|= I40EVF_FLAG_RX_1BUF_CAPABLE
;
597 /* Decide whether to use packet split mode or not */
598 if (netdev
->mtu
> ETH_DATA_LEN
) {
599 if (adapter
->flags
& I40EVF_FLAG_RX_PS_CAPABLE
)
600 adapter
->flags
|= I40EVF_FLAG_RX_PS_ENABLED
;
602 adapter
->flags
&= ~I40EVF_FLAG_RX_PS_ENABLED
;
604 if (adapter
->flags
& I40EVF_FLAG_RX_1BUF_CAPABLE
)
605 adapter
->flags
&= ~I40EVF_FLAG_RX_PS_ENABLED
;
607 adapter
->flags
|= I40EVF_FLAG_RX_PS_ENABLED
;
610 /* Set the RX buffer length according to the mode */
611 if (adapter
->flags
& I40EVF_FLAG_RX_PS_ENABLED
) {
612 rx_buf_len
= I40E_RX_HDR_SIZE
;
614 if (netdev
->mtu
<= ETH_DATA_LEN
)
615 rx_buf_len
= I40EVF_RXBUFFER_2048
;
617 rx_buf_len
= ALIGN(max_frame
, 1024);
620 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++) {
621 adapter
->rx_rings
[i
]->tail
= hw
->hw_addr
+ I40E_QRX_TAIL1(i
);
622 adapter
->rx_rings
[i
]->rx_buf_len
= rx_buf_len
;
627 * i40evf_find_vlan - Search filter list for specific vlan filter
628 * @adapter: board private structure
631 * Returns ptr to the filter object or NULL
634 i40evf_vlan_filter
*i40evf_find_vlan(struct i40evf_adapter
*adapter
, u16 vlan
)
636 struct i40evf_vlan_filter
*f
;
638 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
646 * i40evf_add_vlan - Add a vlan filter to the list
647 * @adapter: board private structure
650 * Returns ptr to the filter object or NULL when no memory available.
653 i40evf_vlan_filter
*i40evf_add_vlan(struct i40evf_adapter
*adapter
, u16 vlan
)
655 struct i40evf_vlan_filter
*f
;
657 f
= i40evf_find_vlan(adapter
, vlan
);
659 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
661 dev_info(&adapter
->pdev
->dev
,
662 "%s: no memory for new VLAN filter\n",
668 INIT_LIST_HEAD(&f
->list
);
669 list_add(&f
->list
, &adapter
->vlan_filter_list
);
671 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_VLAN_FILTER
;
678 * i40evf_del_vlan - Remove a vlan filter from the list
679 * @adapter: board private structure
682 static void i40evf_del_vlan(struct i40evf_adapter
*adapter
, u16 vlan
)
684 struct i40evf_vlan_filter
*f
;
686 f
= i40evf_find_vlan(adapter
, vlan
);
689 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_VLAN_FILTER
;
695 * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device
696 * @netdev: network device struct
699 static int i40evf_vlan_rx_add_vid(struct net_device
*netdev
,
700 __always_unused __be16 proto
, u16 vid
)
702 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
704 if (i40evf_add_vlan(adapter
, vid
) == NULL
)
710 * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device
711 * @netdev: network device struct
714 static int i40evf_vlan_rx_kill_vid(struct net_device
*netdev
,
715 __always_unused __be16 proto
, u16 vid
)
717 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
719 i40evf_del_vlan(adapter
, vid
);
724 * i40evf_find_filter - Search filter list for specific mac filter
725 * @adapter: board private structure
726 * @macaddr: the MAC address
728 * Returns ptr to the filter object or NULL
731 i40evf_mac_filter
*i40evf_find_filter(struct i40evf_adapter
*adapter
,
734 struct i40evf_mac_filter
*f
;
739 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
740 if (ether_addr_equal(macaddr
, f
->macaddr
))
747 * i40e_add_filter - Add a mac filter to the filter list
748 * @adapter: board private structure
749 * @macaddr: the MAC address
751 * Returns ptr to the filter object or NULL when no memory available.
754 i40evf_mac_filter
*i40evf_add_filter(struct i40evf_adapter
*adapter
,
757 struct i40evf_mac_filter
*f
;
762 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
763 &adapter
->crit_section
))
766 f
= i40evf_find_filter(adapter
, macaddr
);
768 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
770 dev_info(&adapter
->pdev
->dev
,
771 "%s: no memory for new filter\n", __func__
);
772 clear_bit(__I40EVF_IN_CRITICAL_TASK
,
773 &adapter
->crit_section
);
777 memcpy(f
->macaddr
, macaddr
, ETH_ALEN
);
779 list_add(&f
->list
, &adapter
->mac_filter_list
);
781 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_MAC_FILTER
;
784 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
789 * i40evf_set_mac - NDO callback to set port mac address
790 * @netdev: network interface device structure
791 * @p: pointer to an address structure
793 * Returns 0 on success, negative on failure
795 static int i40evf_set_mac(struct net_device
*netdev
, void *p
)
797 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
798 struct i40e_hw
*hw
= &adapter
->hw
;
799 struct i40evf_mac_filter
*f
;
800 struct sockaddr
*addr
= p
;
802 if (!is_valid_ether_addr(addr
->sa_data
))
803 return -EADDRNOTAVAIL
;
805 if (ether_addr_equal(netdev
->dev_addr
, addr
->sa_data
))
808 f
= i40evf_add_filter(adapter
, addr
->sa_data
);
810 memcpy(hw
->mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
811 memcpy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
,
815 return (f
== NULL
) ? -ENOMEM
: 0;
819 * i40evf_set_rx_mode - NDO callback to set the netdev filters
820 * @netdev: network interface device structure
822 static void i40evf_set_rx_mode(struct net_device
*netdev
)
824 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
825 struct i40evf_mac_filter
*f
, *ftmp
;
826 struct netdev_hw_addr
*uca
;
827 struct netdev_hw_addr
*mca
;
829 /* add addr if not already in the filter list */
830 netdev_for_each_uc_addr(uca
, netdev
) {
831 i40evf_add_filter(adapter
, uca
->addr
);
833 netdev_for_each_mc_addr(mca
, netdev
) {
834 i40evf_add_filter(adapter
, mca
->addr
);
837 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
838 &adapter
->crit_section
))
840 /* remove filter if not in netdev list */
841 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
844 if (f
->macaddr
[0] & 0x01) {
845 netdev_for_each_mc_addr(mca
, netdev
) {
846 if (ether_addr_equal(mca
->addr
, f
->macaddr
)) {
852 netdev_for_each_uc_addr(uca
, netdev
) {
853 if (ether_addr_equal(uca
->addr
, f
->macaddr
)) {
861 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
864 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
868 * i40evf_napi_enable_all - enable NAPI on all queue vectors
869 * @adapter: board private structure
871 static void i40evf_napi_enable_all(struct i40evf_adapter
*adapter
)
874 struct i40e_q_vector
*q_vector
;
875 int q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
877 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
878 struct napi_struct
*napi
;
879 q_vector
= adapter
->q_vector
[q_idx
];
880 napi
= &q_vector
->napi
;
886 * i40evf_napi_disable_all - disable NAPI on all queue vectors
887 * @adapter: board private structure
889 static void i40evf_napi_disable_all(struct i40evf_adapter
*adapter
)
892 struct i40e_q_vector
*q_vector
;
893 int q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
895 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
896 q_vector
= adapter
->q_vector
[q_idx
];
897 napi_disable(&q_vector
->napi
);
902 * i40evf_configure - set up transmit and receive data structures
903 * @adapter: board private structure
905 static void i40evf_configure(struct i40evf_adapter
*adapter
)
907 struct net_device
*netdev
= adapter
->netdev
;
910 i40evf_set_rx_mode(netdev
);
912 i40evf_configure_tx(adapter
);
913 i40evf_configure_rx(adapter
);
914 adapter
->aq_required
|= I40EVF_FLAG_AQ_CONFIGURE_QUEUES
;
916 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++) {
917 struct i40e_ring
*ring
= adapter
->rx_rings
[i
];
918 i40evf_alloc_rx_buffers(ring
, ring
->count
);
919 ring
->next_to_use
= ring
->count
- 1;
920 writel(ring
->next_to_use
, ring
->tail
);
925 * i40evf_up_complete - Finish the last steps of bringing up a connection
926 * @adapter: board private structure
928 static int i40evf_up_complete(struct i40evf_adapter
*adapter
)
930 adapter
->state
= __I40EVF_RUNNING
;
931 clear_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
933 i40evf_napi_enable_all(adapter
);
935 adapter
->aq_required
|= I40EVF_FLAG_AQ_ENABLE_QUEUES
;
936 mod_timer_pending(&adapter
->watchdog_timer
, jiffies
+ 1);
941 * i40evf_clean_all_rx_rings - Free Rx Buffers for all queues
942 * @adapter: board private structure
944 static void i40evf_clean_all_rx_rings(struct i40evf_adapter
*adapter
)
948 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++)
949 i40evf_clean_rx_ring(adapter
->rx_rings
[i
]);
953 * i40evf_clean_all_tx_rings - Free Tx Buffers for all queues
954 * @adapter: board private structure
956 static void i40evf_clean_all_tx_rings(struct i40evf_adapter
*adapter
)
960 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++)
961 i40evf_clean_tx_ring(adapter
->tx_rings
[i
]);
965 * i40e_down - Shutdown the connection processing
966 * @adapter: board private structure
968 void i40evf_down(struct i40evf_adapter
*adapter
)
970 struct net_device
*netdev
= adapter
->netdev
;
971 struct i40evf_mac_filter
*f
;
973 /* remove all MAC filters */
974 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
977 /* remove all VLAN filters */
978 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
981 if (!(adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
) &&
982 adapter
->state
!= __I40EVF_RESETTING
) {
983 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
984 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_VLAN_FILTER
;
985 /* disable receives */
986 adapter
->aq_required
|= I40EVF_FLAG_AQ_DISABLE_QUEUES
;
987 mod_timer_pending(&adapter
->watchdog_timer
, jiffies
+ 1);
990 netif_tx_disable(netdev
);
992 netif_tx_stop_all_queues(netdev
);
994 i40evf_irq_disable(adapter
);
996 i40evf_napi_disable_all(adapter
);
998 netif_carrier_off(netdev
);
1000 i40evf_clean_all_tx_rings(adapter
);
1001 i40evf_clean_all_rx_rings(adapter
);
1005 * i40evf_acquire_msix_vectors - Setup the MSIX capability
1006 * @adapter: board private structure
1007 * @vectors: number of vectors to request
1009 * Work with the OS to set up the MSIX vectors needed.
1011 * Returns 0 on success, negative on failure
1014 i40evf_acquire_msix_vectors(struct i40evf_adapter
*adapter
, int vectors
)
1016 int err
, vector_threshold
;
1018 /* We'll want at least 3 (vector_threshold):
1019 * 0) Other (Admin Queue and link, mostly)
1023 vector_threshold
= MIN_MSIX_COUNT
;
1025 /* The more we get, the more we will assign to Tx/Rx Cleanup
1026 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1027 * Right now, we simply care about how many we'll get; we'll
1028 * set them up later while requesting irq's.
1030 while (vectors
>= vector_threshold
) {
1031 err
= pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
,
1033 if (!err
) /* Success in acquiring all requested vectors. */
1036 vectors
= 0; /* Nasty failure, quit now */
1037 else /* err == number of vectors we should try again with */
1041 if (vectors
< vector_threshold
) {
1042 dev_err(&adapter
->pdev
->dev
, "Unable to allocate MSI-X interrupts.\n");
1043 kfree(adapter
->msix_entries
);
1044 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
= vectors
;
1057 * i40evf_free_queues - Free memory for all rings
1058 * @adapter: board private structure to initialize
1060 * Free all of the memory associated with queue pairs.
1062 static void i40evf_free_queues(struct i40evf_adapter
*adapter
)
1066 if (!adapter
->vsi_res
)
1068 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++) {
1069 if (adapter
->tx_rings
[i
])
1070 kfree_rcu(adapter
->tx_rings
[i
], rcu
);
1071 adapter
->tx_rings
[i
] = NULL
;
1072 adapter
->rx_rings
[i
] = NULL
;
1077 * i40evf_alloc_queues - Allocate memory for all rings
1078 * @adapter: board private structure to initialize
1080 * We allocate one ring per queue at run-time since we don't know the
1081 * number of queues at compile-time. The polling_netdev array is
1082 * intended for Multiqueue, but should work fine with a single queue.
1084 static int i40evf_alloc_queues(struct i40evf_adapter
*adapter
)
1088 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++) {
1089 struct i40e_ring
*tx_ring
;
1090 struct i40e_ring
*rx_ring
;
1092 tx_ring
= kzalloc(sizeof(struct i40e_ring
) * 2, GFP_KERNEL
);
1096 tx_ring
->queue_index
= i
;
1097 tx_ring
->netdev
= adapter
->netdev
;
1098 tx_ring
->dev
= &adapter
->pdev
->dev
;
1099 tx_ring
->count
= I40EVF_DEFAULT_TXD
;
1100 adapter
->tx_rings
[i
] = tx_ring
;
1102 rx_ring
= &tx_ring
[1];
1103 rx_ring
->queue_index
= i
;
1104 rx_ring
->netdev
= adapter
->netdev
;
1105 rx_ring
->dev
= &adapter
->pdev
->dev
;
1106 rx_ring
->count
= I40EVF_DEFAULT_RXD
;
1107 adapter
->rx_rings
[i
] = rx_ring
;
1113 i40evf_free_queues(adapter
);
1118 * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
1119 * @adapter: board private structure to initialize
1121 * Attempt to configure the interrupts using the best available
1122 * capabilities of the hardware and the kernel.
1124 static int i40evf_set_interrupt_capability(struct i40evf_adapter
*adapter
)
1126 int vector
, v_budget
;
1130 if (!adapter
->vsi_res
) {
1134 pairs
= adapter
->vsi_res
->num_queue_pairs
;
1136 /* It's easy to be greedy for MSI-X vectors, but it really
1137 * doesn't do us much good if we have a lot more vectors
1138 * than CPU's. So let's be conservative and only ask for
1139 * (roughly) twice the number of vectors as there are CPU's.
1141 v_budget
= min_t(int, pairs
, (int)(num_online_cpus() * 2)) + NONQ_VECS
;
1142 v_budget
= min_t(int, v_budget
, (int)adapter
->vf_res
->max_vectors
);
1144 /* A failure in MSI-X entry allocation isn't fatal, but it does
1145 * mean we disable MSI-X capabilities of the adapter.
1147 adapter
->msix_entries
= kcalloc(v_budget
,
1148 sizeof(struct msix_entry
), GFP_KERNEL
);
1149 if (!adapter
->msix_entries
) {
1154 for (vector
= 0; vector
< v_budget
; vector
++)
1155 adapter
->msix_entries
[vector
].entry
= vector
;
1157 i40evf_acquire_msix_vectors(adapter
, v_budget
);
1160 adapter
->netdev
->real_num_tx_queues
= pairs
;
1165 * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
1166 * @adapter: board private structure to initialize
1168 * We allocate one q_vector per queue interrupt. If allocation fails we
1171 static int i40evf_alloc_q_vectors(struct i40evf_adapter
*adapter
)
1173 int q_idx
, num_q_vectors
;
1174 struct i40e_q_vector
*q_vector
;
1176 num_q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
1178 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
1179 q_vector
= kzalloc(sizeof(struct i40e_q_vector
), GFP_KERNEL
);
1182 q_vector
->adapter
= adapter
;
1183 q_vector
->vsi
= &adapter
->vsi
;
1184 q_vector
->v_idx
= q_idx
;
1185 netif_napi_add(adapter
->netdev
, &q_vector
->napi
,
1186 i40evf_napi_poll
, 64);
1187 adapter
->q_vector
[q_idx
] = q_vector
;
1195 q_vector
= adapter
->q_vector
[q_idx
];
1196 netif_napi_del(&q_vector
->napi
);
1198 adapter
->q_vector
[q_idx
] = NULL
;
1204 * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
1205 * @adapter: board private structure to initialize
1207 * This function frees the memory allocated to the q_vectors. In addition if
1208 * NAPI is enabled it will delete any references to the NAPI struct prior
1209 * to freeing the q_vector.
1211 static void i40evf_free_q_vectors(struct i40evf_adapter
*adapter
)
1213 int q_idx
, num_q_vectors
;
1216 num_q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
1217 napi_vectors
= adapter
->vsi_res
->num_queue_pairs
;
1219 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
1220 struct i40e_q_vector
*q_vector
= adapter
->q_vector
[q_idx
];
1222 adapter
->q_vector
[q_idx
] = NULL
;
1223 if (q_idx
< napi_vectors
)
1224 netif_napi_del(&q_vector
->napi
);
1230 * i40evf_reset_interrupt_capability - Reset MSIX setup
1231 * @adapter: board private structure
1234 void i40evf_reset_interrupt_capability(struct i40evf_adapter
*adapter
)
1236 pci_disable_msix(adapter
->pdev
);
1237 kfree(adapter
->msix_entries
);
1238 adapter
->msix_entries
= NULL
;
1244 * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
1245 * @adapter: board private structure to initialize
1248 int i40evf_init_interrupt_scheme(struct i40evf_adapter
*adapter
)
1252 err
= i40evf_set_interrupt_capability(adapter
);
1254 dev_err(&adapter
->pdev
->dev
,
1255 "Unable to setup interrupt capabilities\n");
1256 goto err_set_interrupt
;
1259 err
= i40evf_alloc_q_vectors(adapter
);
1261 dev_err(&adapter
->pdev
->dev
,
1262 "Unable to allocate memory for queue vectors\n");
1263 goto err_alloc_q_vectors
;
1266 err
= i40evf_alloc_queues(adapter
);
1268 dev_err(&adapter
->pdev
->dev
,
1269 "Unable to allocate memory for queues\n");
1270 goto err_alloc_queues
;
1273 dev_info(&adapter
->pdev
->dev
, "Multiqueue %s: Queue pair count = %u",
1274 (adapter
->vsi_res
->num_queue_pairs
> 1) ? "Enabled" :
1275 "Disabled", adapter
->vsi_res
->num_queue_pairs
);
1279 i40evf_free_q_vectors(adapter
);
1280 err_alloc_q_vectors
:
1281 i40evf_reset_interrupt_capability(adapter
);
1287 * i40evf_watchdog_timer - Periodic call-back timer
1288 * @data: pointer to adapter disguised as unsigned long
1290 static void i40evf_watchdog_timer(unsigned long data
)
1292 struct i40evf_adapter
*adapter
= (struct i40evf_adapter
*)data
;
1293 schedule_work(&adapter
->watchdog_task
);
1294 /* timer will be rescheduled in watchdog task */
1298 * i40evf_watchdog_task - Periodic call-back task
1299 * @work: pointer to work_struct
1301 static void i40evf_watchdog_task(struct work_struct
*work
)
1303 struct i40evf_adapter
*adapter
= container_of(work
,
1304 struct i40evf_adapter
,
1306 struct i40e_hw
*hw
= &adapter
->hw
;
1308 if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
))
1309 goto restart_watchdog
;
1311 if (adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
) {
1312 dev_info(&adapter
->pdev
->dev
, "Checking for redemption\n");
1313 if ((rd32(hw
, I40E_VFGEN_RSTAT
) & 0x3) == I40E_VFR_VFACTIVE
) {
1314 /* A chance for redemption! */
1315 dev_err(&adapter
->pdev
->dev
, "Hardware came out of reset. Attempting reinit.\n");
1316 adapter
->state
= __I40EVF_STARTUP
;
1317 adapter
->flags
&= ~I40EVF_FLAG_PF_COMMS_FAILED
;
1318 schedule_delayed_work(&adapter
->init_task
, 10);
1319 clear_bit(__I40EVF_IN_CRITICAL_TASK
,
1320 &adapter
->crit_section
);
1321 /* Don't reschedule the watchdog, since we've restarted
1322 * the init task. When init_task contacts the PF and
1323 * gets everything set up again, it'll restart the
1324 * watchdog for us. Down, boy. Sit. Stay. Woof.
1328 adapter
->aq_pending
= 0;
1329 adapter
->aq_required
= 0;
1330 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
1334 if ((adapter
->state
< __I40EVF_DOWN
) ||
1335 (adapter
->flags
& I40EVF_FLAG_RESET_PENDING
))
1338 /* check for reset */
1339 if (!(adapter
->flags
& I40EVF_FLAG_RESET_PENDING
) &&
1340 (rd32(hw
, I40E_VFGEN_RSTAT
) & 0x3) != I40E_VFR_VFACTIVE
) {
1341 adapter
->state
= __I40EVF_RESETTING
;
1342 adapter
->flags
|= I40EVF_FLAG_RESET_PENDING
;
1343 dev_err(&adapter
->pdev
->dev
, "Hardware reset detected.\n");
1344 dev_info(&adapter
->pdev
->dev
, "Scheduling reset task\n");
1345 schedule_work(&adapter
->reset_task
);
1346 adapter
->aq_pending
= 0;
1347 adapter
->aq_required
= 0;
1348 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
1352 /* Process admin queue tasks. After init, everything gets done
1353 * here so we don't race on the admin queue.
1355 if (adapter
->aq_pending
)
1358 if (adapter
->aq_required
& I40EVF_FLAG_AQ_MAP_VECTORS
) {
1359 i40evf_map_queues(adapter
);
1363 if (adapter
->aq_required
& I40EVF_FLAG_AQ_ADD_MAC_FILTER
) {
1364 i40evf_add_ether_addrs(adapter
);
1368 if (adapter
->aq_required
& I40EVF_FLAG_AQ_ADD_VLAN_FILTER
) {
1369 i40evf_add_vlans(adapter
);
1373 if (adapter
->aq_required
& I40EVF_FLAG_AQ_DEL_MAC_FILTER
) {
1374 i40evf_del_ether_addrs(adapter
);
1378 if (adapter
->aq_required
& I40EVF_FLAG_AQ_DEL_VLAN_FILTER
) {
1379 i40evf_del_vlans(adapter
);
1383 if (adapter
->aq_required
& I40EVF_FLAG_AQ_DISABLE_QUEUES
) {
1384 i40evf_disable_queues(adapter
);
1388 if (adapter
->aq_required
& I40EVF_FLAG_AQ_CONFIGURE_QUEUES
) {
1389 i40evf_configure_queues(adapter
);
1393 if (adapter
->aq_required
& I40EVF_FLAG_AQ_ENABLE_QUEUES
) {
1394 i40evf_enable_queues(adapter
);
1398 if (adapter
->state
== __I40EVF_RUNNING
)
1399 i40evf_request_stats(adapter
);
1401 i40evf_irq_enable(adapter
, true);
1402 i40evf_fire_sw_int(adapter
, 0xFF);
1405 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1407 if (adapter
->aq_required
)
1408 mod_timer(&adapter
->watchdog_timer
,
1409 jiffies
+ msecs_to_jiffies(20));
1411 mod_timer(&adapter
->watchdog_timer
, jiffies
+ (HZ
* 2));
1412 schedule_work(&adapter
->adminq_task
);
1416 * i40evf_configure_rss - increment to next available tx queue
1417 * @adapter: board private structure
1420 * Helper function for RSS programming to increment through available
1421 * queus. Returns the next queue value.
1423 static int next_queue(struct i40evf_adapter
*adapter
, int j
)
1427 return j
>= adapter
->vsi_res
->num_queue_pairs
? 0 : j
;
1431 * i40evf_configure_rss - Prepare for RSS if used
1432 * @adapter: board private structure
1434 static void i40evf_configure_rss(struct i40evf_adapter
*adapter
)
1436 struct i40e_hw
*hw
= &adapter
->hw
;
1441 /* Set of random keys generated using kernel random number generator */
1442 static const u32 seed
[I40E_VFQF_HKEY_MAX_INDEX
+ 1] = {
1443 0x794221b4, 0xbca0c5ab, 0x6cd5ebd9, 0x1ada6127,
1444 0x983b3aa1, 0x1c4e71eb, 0x7f6328b2, 0xfcdc0da0,
1445 0xc135cafa, 0x7a6f7e2d, 0xe7102d28, 0x163cd12e,
1448 /* Hash type is configured by the PF - we just supply the key */
1450 /* Fill out hash function seed */
1451 for (i
= 0; i
<= I40E_VFQF_HKEY_MAX_INDEX
; i
++)
1452 wr32(hw
, I40E_VFQF_HKEY(i
), seed
[i
]);
1454 /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
1455 hena
= I40E_DEFAULT_RSS_HENA
;
1456 wr32(hw
, I40E_VFQF_HENA(0), (u32
)hena
);
1457 wr32(hw
, I40E_VFQF_HENA(1), (u32
)(hena
>> 32));
1459 /* Populate the LUT with max no. of queues in round robin fashion */
1460 j
= adapter
->vsi_res
->num_queue_pairs
;
1461 for (i
= 0; i
<= I40E_VFQF_HLUT_MAX_INDEX
; i
++) {
1462 j
= next_queue(adapter
, j
);
1464 j
= next_queue(adapter
, j
);
1466 j
= next_queue(adapter
, j
);
1468 j
= next_queue(adapter
, j
);
1470 wr32(hw
, I40E_VFQF_HLUT(i
), lut
);
1475 #define I40EVF_RESET_WAIT_MS 100
1476 #define I40EVF_RESET_WAIT_COUNT 200
1478 * i40evf_reset_task - Call-back task to handle hardware reset
1479 * @work: pointer to work_struct
1481 * During reset we need to shut down and reinitialize the admin queue
1482 * before we can use it to communicate with the PF again. We also clear
1483 * and reinit the rings because that context is lost as well.
1485 static void i40evf_reset_task(struct work_struct
*work
)
1487 struct i40evf_adapter
*adapter
= container_of(work
,
1488 struct i40evf_adapter
,
1490 struct i40e_hw
*hw
= &adapter
->hw
;
1494 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
1495 &adapter
->crit_section
))
1498 if (adapter
->flags
& I40EVF_FLAG_RESET_NEEDED
) {
1499 dev_info(&adapter
->pdev
->dev
, "Requesting reset from PF\n");
1500 i40evf_request_reset(adapter
);
1503 /* poll until we see the reset actually happen */
1504 for (i
= 0; i
< I40EVF_RESET_WAIT_COUNT
; i
++) {
1505 rstat_val
= rd32(hw
, I40E_VFGEN_RSTAT
) &
1506 I40E_VFGEN_RSTAT_VFR_STATE_MASK
;
1507 if (rstat_val
!= I40E_VFR_VFACTIVE
) {
1508 dev_info(&adapter
->pdev
->dev
, "Reset now occurring\n");
1511 msleep(I40EVF_RESET_WAIT_MS
);
1514 if (i
== I40EVF_RESET_WAIT_COUNT
) {
1515 dev_err(&adapter
->pdev
->dev
, "Reset was not detected\n");
1516 adapter
->flags
&= ~I40EVF_FLAG_RESET_PENDING
;
1517 goto continue_reset
; /* act like the reset happened */
1520 /* wait until the reset is complete and the PF is responding to us */
1521 for (i
= 0; i
< I40EVF_RESET_WAIT_COUNT
; i
++) {
1522 rstat_val
= rd32(hw
, I40E_VFGEN_RSTAT
) &
1523 I40E_VFGEN_RSTAT_VFR_STATE_MASK
;
1524 if (rstat_val
== I40E_VFR_VFACTIVE
) {
1525 dev_info(&adapter
->pdev
->dev
, "Reset is complete. Reinitializing.\n");
1528 msleep(I40EVF_RESET_WAIT_MS
);
1531 if (i
== I40EVF_RESET_WAIT_COUNT
) {
1532 /* reset never finished */
1533 dev_err(&adapter
->pdev
->dev
, "Reset never finished (%x). PF driver is dead, and so am I.\n",
1535 adapter
->flags
|= I40EVF_FLAG_PF_COMMS_FAILED
;
1537 if (netif_running(adapter
->netdev
))
1538 i40evf_close(adapter
->netdev
);
1540 i40evf_free_misc_irq(adapter
);
1541 i40evf_reset_interrupt_capability(adapter
);
1542 i40evf_free_queues(adapter
);
1543 kfree(adapter
->vf_res
);
1544 i40evf_shutdown_adminq(hw
);
1545 adapter
->netdev
->flags
&= ~IFF_UP
;
1546 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1547 return; /* Do not attempt to reinit. It's dead, Jim. */
1551 adapter
->flags
&= ~I40EVF_FLAG_RESET_PENDING
;
1553 i40evf_down(adapter
);
1554 adapter
->state
= __I40EVF_RESETTING
;
1556 /* kill and reinit the admin queue */
1557 if (i40evf_shutdown_adminq(hw
))
1558 dev_warn(&adapter
->pdev
->dev
,
1559 "%s: Failed to destroy the Admin Queue resources\n",
1561 err
= i40evf_init_adminq(hw
);
1563 dev_info(&adapter
->pdev
->dev
, "%s: init_adminq failed: %d\n",
1566 adapter
->aq_pending
= 0;
1567 adapter
->aq_required
= 0;
1568 i40evf_map_queues(adapter
);
1569 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1571 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 2);
1573 if (netif_running(adapter
->netdev
)) {
1574 /* allocate transmit descriptors */
1575 err
= i40evf_setup_all_tx_resources(adapter
);
1579 /* allocate receive descriptors */
1580 err
= i40evf_setup_all_rx_resources(adapter
);
1584 i40evf_configure(adapter
);
1586 err
= i40evf_up_complete(adapter
);
1590 i40evf_irq_enable(adapter
, true);
1594 dev_err(&adapter
->pdev
->dev
, "failed to allocate resources during reinit.\n");
1595 i40evf_close(adapter
->netdev
);
1599 * i40evf_adminq_task - worker thread to clean the admin queue
1600 * @work: pointer to work_struct containing our data
1602 static void i40evf_adminq_task(struct work_struct
*work
)
1604 struct i40evf_adapter
*adapter
=
1605 container_of(work
, struct i40evf_adapter
, adminq_task
);
1606 struct i40e_hw
*hw
= &adapter
->hw
;
1607 struct i40e_arq_event_info event
;
1608 struct i40e_virtchnl_msg
*v_msg
;
1612 if (adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
)
1615 event
.msg_size
= I40EVF_MAX_AQ_BUF_SIZE
;
1616 event
.msg_buf
= kzalloc(event
.msg_size
, GFP_KERNEL
);
1617 if (!event
.msg_buf
) {
1618 dev_info(&adapter
->pdev
->dev
, "%s: no memory for ARQ clean\n",
1622 v_msg
= (struct i40e_virtchnl_msg
*)&event
.desc
;
1624 ret
= i40evf_clean_arq_element(hw
, &event
, &pending
);
1626 break; /* No event to process or error cleaning ARQ */
1628 i40evf_virtchnl_completion(adapter
, v_msg
->v_opcode
,
1629 v_msg
->v_retval
, event
.msg_buf
,
1632 dev_info(&adapter
->pdev
->dev
,
1633 "%s: ARQ: Pending events %d\n",
1635 memset(event
.msg_buf
, 0, I40EVF_MAX_AQ_BUF_SIZE
);
1639 /* re-enable Admin queue interrupt cause */
1640 i40evf_misc_irq_enable(adapter
);
1642 kfree(event
.msg_buf
);
1646 * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
1647 * @adapter: board private structure
1649 * Free all transmit software resources
1651 static void i40evf_free_all_tx_resources(struct i40evf_adapter
*adapter
)
1655 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++)
1656 if (adapter
->tx_rings
[i
]->desc
)
1657 i40evf_free_tx_resources(adapter
->tx_rings
[i
]);
1662 * i40evf_setup_all_tx_resources - allocate all queues Tx resources
1663 * @adapter: board private structure
1665 * If this function returns with an error, then it's possible one or
1666 * more of the rings is populated (while the rest are not). It is the
1667 * callers duty to clean those orphaned rings.
1669 * Return 0 on success, negative on failure
1671 static int i40evf_setup_all_tx_resources(struct i40evf_adapter
*adapter
)
1675 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++) {
1676 err
= i40evf_setup_tx_descriptors(adapter
->tx_rings
[i
]);
1679 dev_err(&adapter
->pdev
->dev
,
1680 "%s: Allocation for Tx Queue %u failed\n",
1689 * i40evf_setup_all_rx_resources - allocate all queues Rx resources
1690 * @adapter: board private structure
1692 * If this function returns with an error, then it's possible one or
1693 * more of the rings is populated (while the rest are not). It is the
1694 * callers duty to clean those orphaned rings.
1696 * Return 0 on success, negative on failure
1698 static int i40evf_setup_all_rx_resources(struct i40evf_adapter
*adapter
)
1702 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++) {
1703 err
= i40evf_setup_rx_descriptors(adapter
->rx_rings
[i
]);
1706 dev_err(&adapter
->pdev
->dev
,
1707 "%s: Allocation for Rx Queue %u failed\n",
1715 * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
1716 * @adapter: board private structure
1718 * Free all receive software resources
1720 static void i40evf_free_all_rx_resources(struct i40evf_adapter
*adapter
)
1724 for (i
= 0; i
< adapter
->vsi_res
->num_queue_pairs
; i
++)
1725 if (adapter
->rx_rings
[i
]->desc
)
1726 i40evf_free_rx_resources(adapter
->rx_rings
[i
]);
1730 * i40evf_open - Called when a network interface is made active
1731 * @netdev: network interface device structure
1733 * Returns 0 on success, negative value on failure
1735 * The open entry point is called when a network interface is made
1736 * active by the system (IFF_UP). At this point all resources needed
1737 * for transmit and receive operations are allocated, the interrupt
1738 * handler is registered with the OS, the watchdog timer is started,
1739 * and the stack is notified that the interface is ready.
1741 static int i40evf_open(struct net_device
*netdev
)
1743 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
1746 if (adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
) {
1747 dev_err(&adapter
->pdev
->dev
, "Unable to open device due to PF driver failure.\n");
1750 if (adapter
->state
!= __I40EVF_DOWN
)
1753 /* allocate transmit descriptors */
1754 err
= i40evf_setup_all_tx_resources(adapter
);
1758 /* allocate receive descriptors */
1759 err
= i40evf_setup_all_rx_resources(adapter
);
1763 /* clear any pending interrupts, may auto mask */
1764 err
= i40evf_request_traffic_irqs(adapter
, netdev
->name
);
1768 i40evf_configure(adapter
);
1770 err
= i40evf_up_complete(adapter
);
1774 i40evf_irq_enable(adapter
, true);
1779 i40evf_down(adapter
);
1780 i40evf_free_traffic_irqs(adapter
);
1782 i40evf_free_all_rx_resources(adapter
);
1784 i40evf_free_all_tx_resources(adapter
);
1790 * i40evf_close - Disables a network interface
1791 * @netdev: network interface device structure
1793 * Returns 0, this is not allowed to fail
1795 * The close entry point is called when an interface is de-activated
1796 * by the OS. The hardware is still under the drivers control, but
1797 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
1798 * are freed, along with all transmit and receive resources.
1800 static int i40evf_close(struct net_device
*netdev
)
1802 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
1804 if (adapter
->state
<= __I40EVF_DOWN
)
1807 /* signal that we are down to the interrupt handler */
1808 adapter
->state
= __I40EVF_DOWN
;
1810 set_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
1812 i40evf_down(adapter
);
1813 i40evf_free_traffic_irqs(adapter
);
1815 i40evf_free_all_tx_resources(adapter
);
1816 i40evf_free_all_rx_resources(adapter
);
1822 * i40evf_get_stats - Get System Network Statistics
1823 * @netdev: network interface device structure
1825 * Returns the address of the device statistics structure.
1826 * The statistics are actually updated from the timer callback.
1828 static struct net_device_stats
*i40evf_get_stats(struct net_device
*netdev
)
1830 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
1832 /* only return the current stats */
1833 return &adapter
->net_stats
;
1837 * i40evf_reinit_locked - Software reinit
1838 * @adapter: board private structure
1840 * Reinititalizes the ring structures in response to a software configuration
1841 * change. Roughly the same as close followed by open, but skips releasing
1842 * and reallocating the interrupts.
1844 void i40evf_reinit_locked(struct i40evf_adapter
*adapter
)
1846 struct net_device
*netdev
= adapter
->netdev
;
1849 WARN_ON(in_interrupt());
1851 adapter
->state
= __I40EVF_RESETTING
;
1853 i40evf_down(adapter
);
1855 /* allocate transmit descriptors */
1856 err
= i40evf_setup_all_tx_resources(adapter
);
1860 /* allocate receive descriptors */
1861 err
= i40evf_setup_all_rx_resources(adapter
);
1865 i40evf_configure(adapter
);
1867 err
= i40evf_up_complete(adapter
);
1871 i40evf_irq_enable(adapter
, true);
1875 dev_err(&adapter
->pdev
->dev
, "failed to allocate resources during reinit.\n");
1876 i40evf_close(netdev
);
1880 * i40evf_change_mtu - Change the Maximum Transfer Unit
1881 * @netdev: network interface device structure
1882 * @new_mtu: new value for maximum frame size
1884 * Returns 0 on success, negative on failure
1886 static int i40evf_change_mtu(struct net_device
*netdev
, int new_mtu
)
1888 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
1889 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
1891 if ((new_mtu
< 68) || (max_frame
> I40E_MAX_RXBUFFER
))
1894 /* must set new MTU before calling down or up */
1895 netdev
->mtu
= new_mtu
;
1896 i40evf_reinit_locked(adapter
);
1900 static const struct net_device_ops i40evf_netdev_ops
= {
1901 .ndo_open
= i40evf_open
,
1902 .ndo_stop
= i40evf_close
,
1903 .ndo_start_xmit
= i40evf_xmit_frame
,
1904 .ndo_get_stats
= i40evf_get_stats
,
1905 .ndo_set_rx_mode
= i40evf_set_rx_mode
,
1906 .ndo_validate_addr
= eth_validate_addr
,
1907 .ndo_set_mac_address
= i40evf_set_mac
,
1908 .ndo_change_mtu
= i40evf_change_mtu
,
1909 .ndo_tx_timeout
= i40evf_tx_timeout
,
1910 .ndo_vlan_rx_add_vid
= i40evf_vlan_rx_add_vid
,
1911 .ndo_vlan_rx_kill_vid
= i40evf_vlan_rx_kill_vid
,
1915 * i40evf_check_reset_complete - check that VF reset is complete
1916 * @hw: pointer to hw struct
1918 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
1920 static int i40evf_check_reset_complete(struct i40e_hw
*hw
)
1925 for (i
= 0; i
< 100; i
++) {
1926 rstat
= rd32(hw
, I40E_VFGEN_RSTAT
);
1927 if (rstat
== I40E_VFR_VFACTIVE
)
1935 * i40evf_init_task - worker thread to perform delayed initialization
1936 * @work: pointer to work_struct containing our data
1938 * This task completes the work that was begun in probe. Due to the nature
1939 * of VF-PF communications, we may need to wait tens of milliseconds to get
1940 * reponses back from the PF. Rather than busy-wait in probe and bog down the
1941 * whole system, we'll do it in a task so we can sleep.
1942 * This task only runs during driver init. Once we've established
1943 * communications with the PF driver and set up our netdev, the watchdog
1946 static void i40evf_init_task(struct work_struct
*work
)
1948 struct i40evf_adapter
*adapter
= container_of(work
,
1949 struct i40evf_adapter
,
1951 struct net_device
*netdev
= adapter
->netdev
;
1952 struct i40evf_mac_filter
*f
;
1953 struct i40e_hw
*hw
= &adapter
->hw
;
1954 struct pci_dev
*pdev
= adapter
->pdev
;
1957 switch (adapter
->state
) {
1958 case __I40EVF_STARTUP
:
1959 /* driver loaded, probe complete */
1960 adapter
->flags
&= ~I40EVF_FLAG_PF_COMMS_FAILED
;
1961 adapter
->flags
&= ~I40EVF_FLAG_RESET_PENDING
;
1962 err
= i40e_set_mac_type(hw
);
1964 dev_err(&pdev
->dev
, "Failed to set MAC type (%d)\n",
1968 err
= i40evf_check_reset_complete(hw
);
1970 dev_err(&pdev
->dev
, "Device is still in reset (%d)\n",
1974 hw
->aq
.num_arq_entries
= I40EVF_AQ_LEN
;
1975 hw
->aq
.num_asq_entries
= I40EVF_AQ_LEN
;
1976 hw
->aq
.arq_buf_size
= I40EVF_MAX_AQ_BUF_SIZE
;
1977 hw
->aq
.asq_buf_size
= I40EVF_MAX_AQ_BUF_SIZE
;
1979 err
= i40evf_init_adminq(hw
);
1981 dev_err(&pdev
->dev
, "Failed to init Admin Queue (%d)\n",
1985 err
= i40evf_send_api_ver(adapter
);
1987 dev_err(&pdev
->dev
, "Unable to send to PF (%d)\n", err
);
1988 i40evf_shutdown_adminq(hw
);
1991 adapter
->state
= __I40EVF_INIT_VERSION_CHECK
;
1994 case __I40EVF_INIT_VERSION_CHECK
:
1995 if (!i40evf_asq_done(hw
)) {
1996 dev_err(&pdev
->dev
, "Admin queue command never completed.\n");
2000 /* aq msg sent, awaiting reply */
2001 err
= i40evf_verify_api_ver(adapter
);
2003 dev_err(&pdev
->dev
, "Unable to verify API version (%d)\n",
2007 err
= i40evf_send_vf_config_msg(adapter
);
2009 dev_err(&pdev
->dev
, "Unable send config request (%d)\n",
2013 adapter
->state
= __I40EVF_INIT_GET_RESOURCES
;
2016 case __I40EVF_INIT_GET_RESOURCES
:
2017 /* aq msg sent, awaiting reply */
2018 if (!adapter
->vf_res
) {
2019 bufsz
= sizeof(struct i40e_virtchnl_vf_resource
) +
2021 sizeof(struct i40e_virtchnl_vsi_resource
));
2022 adapter
->vf_res
= kzalloc(bufsz
, GFP_KERNEL
);
2023 if (!adapter
->vf_res
)
2026 err
= i40evf_get_vf_config(adapter
);
2027 if (err
== I40E_ERR_ADMIN_QUEUE_NO_WORK
)
2030 dev_err(&pdev
->dev
, "Unable to get VF config (%d)\n",
2034 adapter
->state
= __I40EVF_INIT_SW
;
2039 /* got VF config message back from PF, now we can parse it */
2040 for (i
= 0; i
< adapter
->vf_res
->num_vsis
; i
++) {
2041 if (adapter
->vf_res
->vsi_res
[i
].vsi_type
== I40E_VSI_SRIOV
)
2042 adapter
->vsi_res
= &adapter
->vf_res
->vsi_res
[i
];
2044 if (!adapter
->vsi_res
) {
2045 dev_err(&pdev
->dev
, "No LAN VSI found\n");
2049 adapter
->flags
|= I40EVF_FLAG_RX_CSUM_ENABLED
;
2051 netdev
->netdev_ops
= &i40evf_netdev_ops
;
2052 i40evf_set_ethtool_ops(netdev
);
2053 netdev
->watchdog_timeo
= 5 * HZ
;
2054 netdev
->features
|= NETIF_F_HIGHDMA
|
2064 if (adapter
->vf_res
->vf_offload_flags
2065 & I40E_VIRTCHNL_VF_OFFLOAD_VLAN
) {
2066 netdev
->vlan_features
= netdev
->features
;
2067 netdev
->features
|= NETIF_F_HW_VLAN_CTAG_TX
|
2068 NETIF_F_HW_VLAN_CTAG_RX
|
2069 NETIF_F_HW_VLAN_CTAG_FILTER
;
2072 /* copy netdev features into list of user selectable features */
2073 netdev
->hw_features
|= netdev
->features
;
2074 netdev
->hw_features
&= ~NETIF_F_RXCSUM
;
2076 if (!is_valid_ether_addr(adapter
->hw
.mac
.addr
)) {
2077 dev_info(&pdev
->dev
, "Invalid MAC address %pMAC, using random\n",
2078 adapter
->hw
.mac
.addr
);
2079 random_ether_addr(adapter
->hw
.mac
.addr
);
2081 memcpy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
2082 memcpy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
2084 INIT_LIST_HEAD(&adapter
->mac_filter_list
);
2085 INIT_LIST_HEAD(&adapter
->vlan_filter_list
);
2086 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
2090 memcpy(f
->macaddr
, adapter
->hw
.mac
.addr
, ETH_ALEN
);
2092 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_MAC_FILTER
;
2094 list_add(&f
->list
, &adapter
->mac_filter_list
);
2096 init_timer(&adapter
->watchdog_timer
);
2097 adapter
->watchdog_timer
.function
= &i40evf_watchdog_timer
;
2098 adapter
->watchdog_timer
.data
= (unsigned long)adapter
;
2099 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
2101 err
= i40evf_init_interrupt_scheme(adapter
);
2104 i40evf_map_rings_to_vectors(adapter
);
2105 i40evf_configure_rss(adapter
);
2106 err
= i40evf_request_misc_irq(adapter
);
2110 netif_carrier_off(netdev
);
2112 adapter
->vsi
.id
= adapter
->vsi_res
->vsi_id
;
2113 adapter
->vsi
.seid
= adapter
->vsi_res
->vsi_id
; /* dummy */
2114 adapter
->vsi
.back
= adapter
;
2115 adapter
->vsi
.base_vector
= 1;
2116 adapter
->vsi
.work_limit
= I40E_DEFAULT_IRQ_WORK
;
2117 adapter
->vsi
.rx_itr_setting
= I40E_ITR_DYNAMIC
;
2118 adapter
->vsi
.tx_itr_setting
= I40E_ITR_DYNAMIC
;
2119 adapter
->vsi
.netdev
= adapter
->netdev
;
2121 if (!adapter
->netdev_registered
) {
2122 err
= register_netdev(netdev
);
2127 adapter
->netdev_registered
= true;
2129 netif_tx_stop_all_queues(netdev
);
2131 dev_info(&pdev
->dev
, "MAC address: %pMAC\n", adapter
->hw
.mac
.addr
);
2132 if (netdev
->features
& NETIF_F_GRO
)
2133 dev_info(&pdev
->dev
, "GRO is enabled\n");
2135 dev_info(&pdev
->dev
, "%s\n", i40evf_driver_string
);
2136 adapter
->state
= __I40EVF_DOWN
;
2137 set_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
2138 i40evf_misc_irq_enable(adapter
);
2141 schedule_delayed_work(&adapter
->init_task
,
2142 msecs_to_jiffies(50));
2146 i40evf_free_misc_irq(adapter
);
2148 i40evf_reset_interrupt_capability(adapter
);
2150 kfree(adapter
->vf_res
);
2151 adapter
->vf_res
= NULL
;
2153 /* Things went into the weeds, so try again later */
2154 if (++adapter
->aq_wait_count
> I40EVF_AQ_MAX_ERR
) {
2155 dev_err(&pdev
->dev
, "Failed to communicate with PF; giving up.\n");
2156 adapter
->flags
|= I40EVF_FLAG_PF_COMMS_FAILED
;
2157 return; /* do not reschedule */
2159 schedule_delayed_work(&adapter
->init_task
, HZ
* 3);
2164 * i40evf_shutdown - Shutdown the device in preparation for a reboot
2165 * @pdev: pci device structure
2167 static void i40evf_shutdown(struct pci_dev
*pdev
)
2169 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2171 netif_device_detach(netdev
);
2173 if (netif_running(netdev
))
2174 i40evf_close(netdev
);
2177 pci_save_state(pdev
);
2180 pci_disable_device(pdev
);
2184 * i40evf_probe - Device Initialization Routine
2185 * @pdev: PCI device information struct
2186 * @ent: entry in i40evf_pci_tbl
2188 * Returns 0 on success, negative on failure
2190 * i40evf_probe initializes an adapter identified by a pci_dev structure.
2191 * The OS initialization, configuring of the adapter private structure,
2192 * and a hardware reset occur.
2194 static int i40evf_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2196 struct net_device
*netdev
;
2197 struct i40evf_adapter
*adapter
= NULL
;
2198 struct i40e_hw
*hw
= NULL
;
2201 err
= pci_enable_device(pdev
);
2205 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
2207 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
2210 "DMA configuration failed: 0x%x\n", err
);
2215 err
= pci_request_regions(pdev
, i40evf_driver_name
);
2218 "pci_request_regions failed 0x%x\n", err
);
2222 pci_enable_pcie_error_reporting(pdev
);
2224 pci_set_master(pdev
);
2226 netdev
= alloc_etherdev_mq(sizeof(struct i40evf_adapter
),
2230 goto err_alloc_etherdev
;
2233 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
2235 pci_set_drvdata(pdev
, netdev
);
2236 adapter
= netdev_priv(netdev
);
2238 adapter
->netdev
= netdev
;
2239 adapter
->pdev
= pdev
;
2244 adapter
->msg_enable
= (1 << DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
2245 adapter
->state
= __I40EVF_STARTUP
;
2247 /* Call save state here because it relies on the adapter struct. */
2248 pci_save_state(pdev
);
2250 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
2251 pci_resource_len(pdev
, 0));
2256 hw
->vendor_id
= pdev
->vendor
;
2257 hw
->device_id
= pdev
->device
;
2258 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
2259 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
2260 hw
->subsystem_device_id
= pdev
->subsystem_device
;
2261 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
2262 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
2264 INIT_WORK(&adapter
->reset_task
, i40evf_reset_task
);
2265 INIT_WORK(&adapter
->adminq_task
, i40evf_adminq_task
);
2266 INIT_WORK(&adapter
->watchdog_task
, i40evf_watchdog_task
);
2267 INIT_DELAYED_WORK(&adapter
->init_task
, i40evf_init_task
);
2268 schedule_delayed_work(&adapter
->init_task
, 10);
2273 free_netdev(netdev
);
2275 pci_release_regions(pdev
);
2278 pci_disable_device(pdev
);
2284 * i40evf_suspend - Power management suspend routine
2285 * @pdev: PCI device information struct
2288 * Called when the system (VM) is entering sleep/suspend.
2290 static int i40evf_suspend(struct pci_dev
*pdev
, pm_message_t state
)
2292 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2293 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2296 netif_device_detach(netdev
);
2298 if (netif_running(netdev
)) {
2300 i40evf_down(adapter
);
2303 i40evf_free_misc_irq(adapter
);
2304 i40evf_reset_interrupt_capability(adapter
);
2306 retval
= pci_save_state(pdev
);
2310 pci_disable_device(pdev
);
2316 * i40evf_resume - Power managment resume routine
2317 * @pdev: PCI device information struct
2319 * Called when the system (VM) is resumed from sleep/suspend.
2321 static int i40evf_resume(struct pci_dev
*pdev
)
2323 struct i40evf_adapter
*adapter
= pci_get_drvdata(pdev
);
2324 struct net_device
*netdev
= adapter
->netdev
;
2327 pci_set_power_state(pdev
, PCI_D0
);
2328 pci_restore_state(pdev
);
2329 /* pci_restore_state clears dev->state_saved so call
2330 * pci_save_state to restore it.
2332 pci_save_state(pdev
);
2334 err
= pci_enable_device_mem(pdev
);
2336 dev_err(&pdev
->dev
, "Cannot enable PCI device from suspend.\n");
2339 pci_set_master(pdev
);
2342 err
= i40evf_set_interrupt_capability(adapter
);
2344 dev_err(&pdev
->dev
, "Cannot enable MSI-X interrupts.\n");
2347 err
= i40evf_request_misc_irq(adapter
);
2350 dev_err(&pdev
->dev
, "Cannot get interrupt vector.\n");
2354 schedule_work(&adapter
->reset_task
);
2356 netif_device_attach(netdev
);
2361 #endif /* CONFIG_PM */
2363 * i40evf_remove - Device Removal Routine
2364 * @pdev: PCI device information struct
2366 * i40evf_remove is called by the PCI subsystem to alert the driver
2367 * that it should release a PCI device. The could be caused by a
2368 * Hot-Plug event, or because the driver is going to be removed from
2371 static void i40evf_remove(struct pci_dev
*pdev
)
2373 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2374 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2375 struct i40e_hw
*hw
= &adapter
->hw
;
2377 cancel_delayed_work_sync(&adapter
->init_task
);
2378 cancel_work_sync(&adapter
->reset_task
);
2380 if (adapter
->netdev_registered
) {
2381 unregister_netdev(netdev
);
2382 adapter
->netdev_registered
= false;
2384 adapter
->state
= __I40EVF_REMOVE
;
2386 if (adapter
->msix_entries
) {
2387 i40evf_misc_irq_disable(adapter
);
2388 i40evf_free_misc_irq(adapter
);
2389 i40evf_reset_interrupt_capability(adapter
);
2392 del_timer_sync(&adapter
->watchdog_timer
);
2393 flush_scheduled_work();
2395 if (hw
->aq
.asq
.count
)
2396 i40evf_shutdown_adminq(hw
);
2398 iounmap(hw
->hw_addr
);
2399 pci_release_regions(pdev
);
2401 i40evf_free_queues(adapter
);
2402 kfree(adapter
->vf_res
);
2404 free_netdev(netdev
);
2406 pci_disable_pcie_error_reporting(pdev
);
2408 pci_disable_device(pdev
);
2411 static struct pci_driver i40evf_driver
= {
2412 .name
= i40evf_driver_name
,
2413 .id_table
= i40evf_pci_tbl
,
2414 .probe
= i40evf_probe
,
2415 .remove
= i40evf_remove
,
2417 .suspend
= i40evf_suspend
,
2418 .resume
= i40evf_resume
,
2420 .shutdown
= i40evf_shutdown
,
2424 * i40e_init_module - Driver Registration Routine
2426 * i40e_init_module is the first routine called when the driver is
2427 * loaded. All it does is register with the PCI subsystem.
2429 static int __init
i40evf_init_module(void)
2432 pr_info("i40evf: %s - version %s\n", i40evf_driver_string
,
2433 i40evf_driver_version
);
2435 pr_info("%s\n", i40evf_copyright
);
2437 ret
= pci_register_driver(&i40evf_driver
);
2441 module_init(i40evf_init_module
);
2444 * i40e_exit_module - Driver Exit Cleanup Routine
2446 * i40e_exit_module is called just before the driver is removed
2449 static void __exit
i40evf_exit_module(void)
2451 pci_unregister_driver(&i40evf_driver
);
2454 module_exit(i40evf_exit_module
);