1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2021 Intel Corporation. */
4 #include <linux/etherdevice.h>
5 #include <linux/of_net.h>
8 #include <generated/utsrelease.h>
9 #include <linux/crash_dump.h>
13 #include "i40e_diag.h"
15 #include <net/udp_tunnel.h>
16 #include <net/xdp_sock_drv.h>
17 /* All i40e tracepoints are defined by the include below, which
18 * must be included exactly once across the whole kernel with
19 * CREATE_TRACE_POINTS defined
21 #define CREATE_TRACE_POINTS
22 #include "i40e_trace.h"
24 const char i40e_driver_name
[] = "i40e";
25 static const char i40e_driver_string
[] =
26 "Intel(R) Ethernet Connection XL710 Network Driver";
28 static const char i40e_copyright
[] = "Copyright (c) 2013 - 2019 Intel Corporation.";
30 /* a bit of forward declarations */
31 static void i40e_vsi_reinit_locked(struct i40e_vsi
*vsi
);
32 static void i40e_handle_reset_warning(struct i40e_pf
*pf
, bool lock_acquired
);
33 static int i40e_add_vsi(struct i40e_vsi
*vsi
);
34 static int i40e_add_veb(struct i40e_veb
*veb
, struct i40e_vsi
*vsi
);
35 static int i40e_setup_pf_switch(struct i40e_pf
*pf
, bool reinit
, bool lock_acquired
);
36 static int i40e_setup_misc_vector(struct i40e_pf
*pf
);
37 static void i40e_determine_queue_usage(struct i40e_pf
*pf
);
38 static int i40e_setup_pf_filter_control(struct i40e_pf
*pf
);
39 static void i40e_prep_for_reset(struct i40e_pf
*pf
);
40 static void i40e_reset_and_rebuild(struct i40e_pf
*pf
, bool reinit
,
42 static int i40e_reset(struct i40e_pf
*pf
);
43 static void i40e_rebuild(struct i40e_pf
*pf
, bool reinit
, bool lock_acquired
);
44 static int i40e_setup_misc_vector_for_recovery_mode(struct i40e_pf
*pf
);
45 static int i40e_restore_interrupt_scheme(struct i40e_pf
*pf
);
46 static bool i40e_check_recovery_mode(struct i40e_pf
*pf
);
47 static int i40e_init_recovery_mode(struct i40e_pf
*pf
, struct i40e_hw
*hw
);
48 static void i40e_fdir_sb_setup(struct i40e_pf
*pf
);
49 static int i40e_veb_get_bw_info(struct i40e_veb
*veb
);
50 static int i40e_get_capabilities(struct i40e_pf
*pf
,
51 enum i40e_admin_queue_opc list_type
);
52 static bool i40e_is_total_port_shutdown_enabled(struct i40e_pf
*pf
);
54 /* i40e_pci_tbl - PCI Device ID Table
56 * Last entry must be all 0s
58 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
59 * Class, Class Mask, private data (not used) }
61 static const struct pci_device_id i40e_pci_tbl
[] = {
62 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_SFP_XL710
), 0},
63 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QEMU
), 0},
64 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_B
), 0},
65 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_C
), 0},
66 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_A
), 0},
67 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_B
), 0},
68 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_C
), 0},
69 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T
), 0},
70 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T4
), 0},
71 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T_BC
), 0},
72 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_SFP
), 0},
73 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_B
), 0},
74 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_X722
), 0},
75 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_X722
), 0},
76 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_SFP_X722
), 0},
77 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_1G_BASE_T_X722
), 0},
78 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T_X722
), 0},
79 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_SFP_I_X722
), 0},
80 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_20G_KR2
), 0},
81 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_20G_KR2_A
), 0},
82 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_X710_N3000
), 0},
83 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_XXV710_N3000
), 0},
84 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_25G_B
), 0},
85 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_25G_SFP28
), 0},
86 /* required last entry */
89 MODULE_DEVICE_TABLE(pci
, i40e_pci_tbl
);
91 #define I40E_MAX_VF_COUNT 128
92 static int debug
= -1;
93 module_param(debug
, uint
, 0);
94 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXX)");
96 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
97 MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
98 MODULE_LICENSE("GPL v2");
100 static struct workqueue_struct
*i40e_wq
;
102 static void netdev_hw_addr_refcnt(struct i40e_mac_filter
*f
,
103 struct net_device
*netdev
, int delta
)
105 struct netdev_hw_addr
*ha
;
110 netdev_for_each_mc_addr(ha
, netdev
) {
111 if (ether_addr_equal(ha
->addr
, f
->macaddr
)) {
112 ha
->refcount
+= delta
;
113 if (ha
->refcount
<= 0)
121 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
122 * @hw: pointer to the HW structure
123 * @mem: ptr to mem struct to fill out
124 * @size: size of memory requested
125 * @alignment: what to align the allocation to
127 int i40e_allocate_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
,
128 u64 size
, u32 alignment
)
130 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
132 mem
->size
= ALIGN(size
, alignment
);
133 mem
->va
= dma_alloc_coherent(&pf
->pdev
->dev
, mem
->size
, &mem
->pa
,
142 * i40e_free_dma_mem_d - OS specific memory free for shared code
143 * @hw: pointer to the HW structure
144 * @mem: ptr to mem struct to free
146 int i40e_free_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
)
148 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
150 dma_free_coherent(&pf
->pdev
->dev
, mem
->size
, mem
->va
, mem
->pa
);
159 * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
160 * @hw: pointer to the HW structure
161 * @mem: ptr to mem struct to fill out
162 * @size: size of memory requested
164 int i40e_allocate_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
,
168 mem
->va
= kzalloc(size
, GFP_KERNEL
);
177 * i40e_free_virt_mem_d - OS specific memory free for shared code
178 * @hw: pointer to the HW structure
179 * @mem: ptr to mem struct to free
181 int i40e_free_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
)
183 /* it's ok to kfree a NULL pointer */
192 * i40e_get_lump - find a lump of free generic resource
193 * @pf: board private structure
194 * @pile: the pile of resource to search
195 * @needed: the number of items needed
196 * @id: an owner id to stick on the items assigned
198 * Returns the base item index of the lump, or negative for error
200 static int i40e_get_lump(struct i40e_pf
*pf
, struct i40e_lump_tracking
*pile
,
206 if (!pile
|| needed
== 0 || id
>= I40E_PILE_VALID_BIT
) {
207 dev_info(&pf
->pdev
->dev
,
208 "param err: pile=%s needed=%d id=0x%04x\n",
209 pile
? "<valid>" : "<null>", needed
, id
);
213 /* Allocate last queue in the pile for FDIR VSI queue
214 * so it doesn't fragment the qp_pile
216 if (pile
== pf
->qp_pile
&& pf
->vsi
[id
]->type
== I40E_VSI_FDIR
) {
217 if (pile
->list
[pile
->num_entries
- 1] & I40E_PILE_VALID_BIT
) {
218 dev_err(&pf
->pdev
->dev
,
219 "Cannot allocate queue %d for I40E_VSI_FDIR\n",
220 pile
->num_entries
- 1);
223 pile
->list
[pile
->num_entries
- 1] = id
| I40E_PILE_VALID_BIT
;
224 return pile
->num_entries
- 1;
228 while (i
< pile
->num_entries
) {
229 /* skip already allocated entries */
230 if (pile
->list
[i
] & I40E_PILE_VALID_BIT
) {
235 /* do we have enough in this lump? */
236 for (j
= 0; (j
< needed
) && ((i
+j
) < pile
->num_entries
); j
++) {
237 if (pile
->list
[i
+j
] & I40E_PILE_VALID_BIT
)
242 /* there was enough, so assign it to the requestor */
243 for (j
= 0; j
< needed
; j
++)
244 pile
->list
[i
+j
] = id
| I40E_PILE_VALID_BIT
;
249 /* not enough, so skip over it and continue looking */
257 * i40e_put_lump - return a lump of generic resource
258 * @pile: the pile of resource to search
259 * @index: the base item index
260 * @id: the owner id of the items assigned
262 * Returns the count of items in the lump
264 static int i40e_put_lump(struct i40e_lump_tracking
*pile
, u16 index
, u16 id
)
266 int valid_id
= (id
| I40E_PILE_VALID_BIT
);
270 if (!pile
|| index
>= pile
->num_entries
)
274 i
< pile
->num_entries
&& pile
->list
[i
] == valid_id
;
285 * i40e_find_vsi_from_id - searches for the vsi with the given id
286 * @pf: the pf structure to search for the vsi
287 * @id: id of the vsi it is searching for
289 struct i40e_vsi
*i40e_find_vsi_from_id(struct i40e_pf
*pf
, u16 id
)
293 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
294 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->id
== id
))
301 * i40e_service_event_schedule - Schedule the service task to wake up
302 * @pf: board private structure
304 * If not already scheduled, this puts the task into the work queue
306 void i40e_service_event_schedule(struct i40e_pf
*pf
)
308 if ((!test_bit(__I40E_DOWN
, pf
->state
) &&
309 !test_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
)) ||
310 test_bit(__I40E_RECOVERY_MODE
, pf
->state
))
311 queue_work(i40e_wq
, &pf
->service_task
);
315 * i40e_tx_timeout - Respond to a Tx Hang
316 * @netdev: network interface device structure
317 * @txqueue: queue number timing out
319 * If any port has noticed a Tx timeout, it is likely that the whole
320 * device is munged, not just the one netdev port, so go for the full
323 static void i40e_tx_timeout(struct net_device
*netdev
, unsigned int txqueue
)
325 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
326 struct i40e_vsi
*vsi
= np
->vsi
;
327 struct i40e_pf
*pf
= vsi
->back
;
328 struct i40e_ring
*tx_ring
= NULL
;
332 pf
->tx_timeout_count
++;
334 /* with txqueue index, find the tx_ring struct */
335 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
336 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
) {
338 vsi
->tx_rings
[i
]->queue_index
) {
339 tx_ring
= vsi
->tx_rings
[i
];
345 if (time_after(jiffies
, (pf
->tx_timeout_last_recovery
+ HZ
*20)))
346 pf
->tx_timeout_recovery_level
= 1; /* reset after some time */
347 else if (time_before(jiffies
,
348 (pf
->tx_timeout_last_recovery
+ netdev
->watchdog_timeo
)))
349 return; /* don't do any new action before the next timeout */
351 /* don't kick off another recovery if one is already pending */
352 if (test_and_set_bit(__I40E_TIMEOUT_RECOVERY_PENDING
, pf
->state
))
356 head
= i40e_get_head(tx_ring
);
357 /* Read interrupt register */
358 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
360 I40E_PFINT_DYN_CTLN(tx_ring
->q_vector
->v_idx
+
361 tx_ring
->vsi
->base_vector
- 1));
363 val
= rd32(&pf
->hw
, I40E_PFINT_DYN_CTL0
);
365 netdev_info(netdev
, "tx_timeout: VSI_seid: %d, Q %d, NTC: 0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x, INT: 0x%x\n",
366 vsi
->seid
, txqueue
, tx_ring
->next_to_clean
,
367 head
, tx_ring
->next_to_use
,
368 readl(tx_ring
->tail
), val
);
371 pf
->tx_timeout_last_recovery
= jiffies
;
372 netdev_info(netdev
, "tx_timeout recovery level %d, txqueue %d\n",
373 pf
->tx_timeout_recovery_level
, txqueue
);
375 switch (pf
->tx_timeout_recovery_level
) {
377 set_bit(__I40E_PF_RESET_REQUESTED
, pf
->state
);
380 set_bit(__I40E_CORE_RESET_REQUESTED
, pf
->state
);
383 set_bit(__I40E_GLOBAL_RESET_REQUESTED
, pf
->state
);
386 netdev_err(netdev
, "tx_timeout recovery unsuccessful\n");
390 i40e_service_event_schedule(pf
);
391 pf
->tx_timeout_recovery_level
++;
395 * i40e_get_vsi_stats_struct - Get System Network Statistics
396 * @vsi: the VSI we care about
398 * Returns the address of the device statistics structure.
399 * The statistics are actually updated from the service task.
401 struct rtnl_link_stats64
*i40e_get_vsi_stats_struct(struct i40e_vsi
*vsi
)
403 return &vsi
->net_stats
;
407 * i40e_get_netdev_stats_struct_tx - populate stats from a Tx ring
408 * @ring: Tx ring to get statistics from
409 * @stats: statistics entry to be updated
411 static void i40e_get_netdev_stats_struct_tx(struct i40e_ring
*ring
,
412 struct rtnl_link_stats64
*stats
)
418 start
= u64_stats_fetch_begin_irq(&ring
->syncp
);
419 packets
= ring
->stats
.packets
;
420 bytes
= ring
->stats
.bytes
;
421 } while (u64_stats_fetch_retry_irq(&ring
->syncp
, start
));
423 stats
->tx_packets
+= packets
;
424 stats
->tx_bytes
+= bytes
;
428 * i40e_get_netdev_stats_struct - Get statistics for netdev interface
429 * @netdev: network interface device structure
430 * @stats: data structure to store statistics
432 * Returns the address of the device statistics structure.
433 * The statistics are actually updated from the service task.
435 static void i40e_get_netdev_stats_struct(struct net_device
*netdev
,
436 struct rtnl_link_stats64
*stats
)
438 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
439 struct i40e_vsi
*vsi
= np
->vsi
;
440 struct rtnl_link_stats64
*vsi_stats
= i40e_get_vsi_stats_struct(vsi
);
441 struct i40e_ring
*ring
;
444 if (test_bit(__I40E_VSI_DOWN
, vsi
->state
))
451 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
455 ring
= READ_ONCE(vsi
->tx_rings
[i
]);
458 i40e_get_netdev_stats_struct_tx(ring
, stats
);
460 if (i40e_enabled_xdp_vsi(vsi
)) {
461 ring
= READ_ONCE(vsi
->xdp_rings
[i
]);
464 i40e_get_netdev_stats_struct_tx(ring
, stats
);
467 ring
= READ_ONCE(vsi
->rx_rings
[i
]);
471 start
= u64_stats_fetch_begin_irq(&ring
->syncp
);
472 packets
= ring
->stats
.packets
;
473 bytes
= ring
->stats
.bytes
;
474 } while (u64_stats_fetch_retry_irq(&ring
->syncp
, start
));
476 stats
->rx_packets
+= packets
;
477 stats
->rx_bytes
+= bytes
;
482 /* following stats updated by i40e_watchdog_subtask() */
483 stats
->multicast
= vsi_stats
->multicast
;
484 stats
->tx_errors
= vsi_stats
->tx_errors
;
485 stats
->tx_dropped
= vsi_stats
->tx_dropped
;
486 stats
->rx_errors
= vsi_stats
->rx_errors
;
487 stats
->rx_dropped
= vsi_stats
->rx_dropped
;
488 stats
->rx_crc_errors
= vsi_stats
->rx_crc_errors
;
489 stats
->rx_length_errors
= vsi_stats
->rx_length_errors
;
493 * i40e_vsi_reset_stats - Resets all stats of the given vsi
494 * @vsi: the VSI to have its stats reset
496 void i40e_vsi_reset_stats(struct i40e_vsi
*vsi
)
498 struct rtnl_link_stats64
*ns
;
504 ns
= i40e_get_vsi_stats_struct(vsi
);
505 memset(ns
, 0, sizeof(*ns
));
506 memset(&vsi
->net_stats_offsets
, 0, sizeof(vsi
->net_stats_offsets
));
507 memset(&vsi
->eth_stats
, 0, sizeof(vsi
->eth_stats
));
508 memset(&vsi
->eth_stats_offsets
, 0, sizeof(vsi
->eth_stats_offsets
));
509 if (vsi
->rx_rings
&& vsi
->rx_rings
[0]) {
510 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
511 memset(&vsi
->rx_rings
[i
]->stats
, 0,
512 sizeof(vsi
->rx_rings
[i
]->stats
));
513 memset(&vsi
->rx_rings
[i
]->rx_stats
, 0,
514 sizeof(vsi
->rx_rings
[i
]->rx_stats
));
515 memset(&vsi
->tx_rings
[i
]->stats
, 0,
516 sizeof(vsi
->tx_rings
[i
]->stats
));
517 memset(&vsi
->tx_rings
[i
]->tx_stats
, 0,
518 sizeof(vsi
->tx_rings
[i
]->tx_stats
));
521 vsi
->stat_offsets_loaded
= false;
525 * i40e_pf_reset_stats - Reset all of the stats for the given PF
526 * @pf: the PF to be reset
528 void i40e_pf_reset_stats(struct i40e_pf
*pf
)
532 memset(&pf
->stats
, 0, sizeof(pf
->stats
));
533 memset(&pf
->stats_offsets
, 0, sizeof(pf
->stats_offsets
));
534 pf
->stat_offsets_loaded
= false;
536 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
538 memset(&pf
->veb
[i
]->stats
, 0,
539 sizeof(pf
->veb
[i
]->stats
));
540 memset(&pf
->veb
[i
]->stats_offsets
, 0,
541 sizeof(pf
->veb
[i
]->stats_offsets
));
542 memset(&pf
->veb
[i
]->tc_stats
, 0,
543 sizeof(pf
->veb
[i
]->tc_stats
));
544 memset(&pf
->veb
[i
]->tc_stats_offsets
, 0,
545 sizeof(pf
->veb
[i
]->tc_stats_offsets
));
546 pf
->veb
[i
]->stat_offsets_loaded
= false;
549 pf
->hw_csum_rx_error
= 0;
553 * i40e_stat_update48 - read and update a 48 bit stat from the chip
554 * @hw: ptr to the hardware info
555 * @hireg: the high 32 bit reg to read
556 * @loreg: the low 32 bit reg to read
557 * @offset_loaded: has the initial offset been loaded yet
558 * @offset: ptr to current offset value
559 * @stat: ptr to the stat
561 * Since the device stats are not reset at PFReset, they likely will not
562 * be zeroed when the driver starts. We'll save the first values read
563 * and use them as offsets to be subtracted from the raw values in order
564 * to report stats that count from zero. In the process, we also manage
565 * the potential roll-over.
567 static void i40e_stat_update48(struct i40e_hw
*hw
, u32 hireg
, u32 loreg
,
568 bool offset_loaded
, u64
*offset
, u64
*stat
)
572 if (hw
->device_id
== I40E_DEV_ID_QEMU
) {
573 new_data
= rd32(hw
, loreg
);
574 new_data
|= ((u64
)(rd32(hw
, hireg
) & 0xFFFF)) << 32;
576 new_data
= rd64(hw
, loreg
);
580 if (likely(new_data
>= *offset
))
581 *stat
= new_data
- *offset
;
583 *stat
= (new_data
+ BIT_ULL(48)) - *offset
;
584 *stat
&= 0xFFFFFFFFFFFFULL
;
588 * i40e_stat_update32 - read and update a 32 bit stat from the chip
589 * @hw: ptr to the hardware info
590 * @reg: the hw reg to read
591 * @offset_loaded: has the initial offset been loaded yet
592 * @offset: ptr to current offset value
593 * @stat: ptr to the stat
595 static void i40e_stat_update32(struct i40e_hw
*hw
, u32 reg
,
596 bool offset_loaded
, u64
*offset
, u64
*stat
)
600 new_data
= rd32(hw
, reg
);
603 if (likely(new_data
>= *offset
))
604 *stat
= (u32
)(new_data
- *offset
);
606 *stat
= (u32
)((new_data
+ BIT_ULL(32)) - *offset
);
610 * i40e_stat_update_and_clear32 - read and clear hw reg, update a 32 bit stat
611 * @hw: ptr to the hardware info
612 * @reg: the hw reg to read and clear
613 * @stat: ptr to the stat
615 static void i40e_stat_update_and_clear32(struct i40e_hw
*hw
, u32 reg
, u64
*stat
)
617 u32 new_data
= rd32(hw
, reg
);
619 wr32(hw
, reg
, 1); /* must write a nonzero value to clear register */
624 * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
625 * @vsi: the VSI to be updated
627 void i40e_update_eth_stats(struct i40e_vsi
*vsi
)
629 int stat_idx
= le16_to_cpu(vsi
->info
.stat_counter_idx
);
630 struct i40e_pf
*pf
= vsi
->back
;
631 struct i40e_hw
*hw
= &pf
->hw
;
632 struct i40e_eth_stats
*oes
;
633 struct i40e_eth_stats
*es
; /* device's eth stats */
635 es
= &vsi
->eth_stats
;
636 oes
= &vsi
->eth_stats_offsets
;
638 /* Gather up the stats that the hw collects */
639 i40e_stat_update32(hw
, I40E_GLV_TEPC(stat_idx
),
640 vsi
->stat_offsets_loaded
,
641 &oes
->tx_errors
, &es
->tx_errors
);
642 i40e_stat_update32(hw
, I40E_GLV_RDPC(stat_idx
),
643 vsi
->stat_offsets_loaded
,
644 &oes
->rx_discards
, &es
->rx_discards
);
645 i40e_stat_update32(hw
, I40E_GLV_RUPP(stat_idx
),
646 vsi
->stat_offsets_loaded
,
647 &oes
->rx_unknown_protocol
, &es
->rx_unknown_protocol
);
649 i40e_stat_update48(hw
, I40E_GLV_GORCH(stat_idx
),
650 I40E_GLV_GORCL(stat_idx
),
651 vsi
->stat_offsets_loaded
,
652 &oes
->rx_bytes
, &es
->rx_bytes
);
653 i40e_stat_update48(hw
, I40E_GLV_UPRCH(stat_idx
),
654 I40E_GLV_UPRCL(stat_idx
),
655 vsi
->stat_offsets_loaded
,
656 &oes
->rx_unicast
, &es
->rx_unicast
);
657 i40e_stat_update48(hw
, I40E_GLV_MPRCH(stat_idx
),
658 I40E_GLV_MPRCL(stat_idx
),
659 vsi
->stat_offsets_loaded
,
660 &oes
->rx_multicast
, &es
->rx_multicast
);
661 i40e_stat_update48(hw
, I40E_GLV_BPRCH(stat_idx
),
662 I40E_GLV_BPRCL(stat_idx
),
663 vsi
->stat_offsets_loaded
,
664 &oes
->rx_broadcast
, &es
->rx_broadcast
);
666 i40e_stat_update48(hw
, I40E_GLV_GOTCH(stat_idx
),
667 I40E_GLV_GOTCL(stat_idx
),
668 vsi
->stat_offsets_loaded
,
669 &oes
->tx_bytes
, &es
->tx_bytes
);
670 i40e_stat_update48(hw
, I40E_GLV_UPTCH(stat_idx
),
671 I40E_GLV_UPTCL(stat_idx
),
672 vsi
->stat_offsets_loaded
,
673 &oes
->tx_unicast
, &es
->tx_unicast
);
674 i40e_stat_update48(hw
, I40E_GLV_MPTCH(stat_idx
),
675 I40E_GLV_MPTCL(stat_idx
),
676 vsi
->stat_offsets_loaded
,
677 &oes
->tx_multicast
, &es
->tx_multicast
);
678 i40e_stat_update48(hw
, I40E_GLV_BPTCH(stat_idx
),
679 I40E_GLV_BPTCL(stat_idx
),
680 vsi
->stat_offsets_loaded
,
681 &oes
->tx_broadcast
, &es
->tx_broadcast
);
682 vsi
->stat_offsets_loaded
= true;
686 * i40e_update_veb_stats - Update Switch component statistics
687 * @veb: the VEB being updated
689 void i40e_update_veb_stats(struct i40e_veb
*veb
)
691 struct i40e_pf
*pf
= veb
->pf
;
692 struct i40e_hw
*hw
= &pf
->hw
;
693 struct i40e_eth_stats
*oes
;
694 struct i40e_eth_stats
*es
; /* device's eth stats */
695 struct i40e_veb_tc_stats
*veb_oes
;
696 struct i40e_veb_tc_stats
*veb_es
;
699 idx
= veb
->stats_idx
;
701 oes
= &veb
->stats_offsets
;
702 veb_es
= &veb
->tc_stats
;
703 veb_oes
= &veb
->tc_stats_offsets
;
705 /* Gather up the stats that the hw collects */
706 i40e_stat_update32(hw
, I40E_GLSW_TDPC(idx
),
707 veb
->stat_offsets_loaded
,
708 &oes
->tx_discards
, &es
->tx_discards
);
709 if (hw
->revision_id
> 0)
710 i40e_stat_update32(hw
, I40E_GLSW_RUPP(idx
),
711 veb
->stat_offsets_loaded
,
712 &oes
->rx_unknown_protocol
,
713 &es
->rx_unknown_protocol
);
714 i40e_stat_update48(hw
, I40E_GLSW_GORCH(idx
), I40E_GLSW_GORCL(idx
),
715 veb
->stat_offsets_loaded
,
716 &oes
->rx_bytes
, &es
->rx_bytes
);
717 i40e_stat_update48(hw
, I40E_GLSW_UPRCH(idx
), I40E_GLSW_UPRCL(idx
),
718 veb
->stat_offsets_loaded
,
719 &oes
->rx_unicast
, &es
->rx_unicast
);
720 i40e_stat_update48(hw
, I40E_GLSW_MPRCH(idx
), I40E_GLSW_MPRCL(idx
),
721 veb
->stat_offsets_loaded
,
722 &oes
->rx_multicast
, &es
->rx_multicast
);
723 i40e_stat_update48(hw
, I40E_GLSW_BPRCH(idx
), I40E_GLSW_BPRCL(idx
),
724 veb
->stat_offsets_loaded
,
725 &oes
->rx_broadcast
, &es
->rx_broadcast
);
727 i40e_stat_update48(hw
, I40E_GLSW_GOTCH(idx
), I40E_GLSW_GOTCL(idx
),
728 veb
->stat_offsets_loaded
,
729 &oes
->tx_bytes
, &es
->tx_bytes
);
730 i40e_stat_update48(hw
, I40E_GLSW_UPTCH(idx
), I40E_GLSW_UPTCL(idx
),
731 veb
->stat_offsets_loaded
,
732 &oes
->tx_unicast
, &es
->tx_unicast
);
733 i40e_stat_update48(hw
, I40E_GLSW_MPTCH(idx
), I40E_GLSW_MPTCL(idx
),
734 veb
->stat_offsets_loaded
,
735 &oes
->tx_multicast
, &es
->tx_multicast
);
736 i40e_stat_update48(hw
, I40E_GLSW_BPTCH(idx
), I40E_GLSW_BPTCL(idx
),
737 veb
->stat_offsets_loaded
,
738 &oes
->tx_broadcast
, &es
->tx_broadcast
);
739 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
740 i40e_stat_update48(hw
, I40E_GLVEBTC_RPCH(i
, idx
),
741 I40E_GLVEBTC_RPCL(i
, idx
),
742 veb
->stat_offsets_loaded
,
743 &veb_oes
->tc_rx_packets
[i
],
744 &veb_es
->tc_rx_packets
[i
]);
745 i40e_stat_update48(hw
, I40E_GLVEBTC_RBCH(i
, idx
),
746 I40E_GLVEBTC_RBCL(i
, idx
),
747 veb
->stat_offsets_loaded
,
748 &veb_oes
->tc_rx_bytes
[i
],
749 &veb_es
->tc_rx_bytes
[i
]);
750 i40e_stat_update48(hw
, I40E_GLVEBTC_TPCH(i
, idx
),
751 I40E_GLVEBTC_TPCL(i
, idx
),
752 veb
->stat_offsets_loaded
,
753 &veb_oes
->tc_tx_packets
[i
],
754 &veb_es
->tc_tx_packets
[i
]);
755 i40e_stat_update48(hw
, I40E_GLVEBTC_TBCH(i
, idx
),
756 I40E_GLVEBTC_TBCL(i
, idx
),
757 veb
->stat_offsets_loaded
,
758 &veb_oes
->tc_tx_bytes
[i
],
759 &veb_es
->tc_tx_bytes
[i
]);
761 veb
->stat_offsets_loaded
= true;
765 * i40e_update_vsi_stats - Update the vsi statistics counters.
766 * @vsi: the VSI to be updated
768 * There are a few instances where we store the same stat in a
769 * couple of different structs. This is partly because we have
770 * the netdev stats that need to be filled out, which is slightly
771 * different from the "eth_stats" defined by the chip and used in
772 * VF communications. We sort it out here.
774 static void i40e_update_vsi_stats(struct i40e_vsi
*vsi
)
776 struct i40e_pf
*pf
= vsi
->back
;
777 struct rtnl_link_stats64
*ons
;
778 struct rtnl_link_stats64
*ns
; /* netdev stats */
779 struct i40e_eth_stats
*oes
;
780 struct i40e_eth_stats
*es
; /* device's eth stats */
781 u64 tx_restart
, tx_busy
;
792 if (test_bit(__I40E_VSI_DOWN
, vsi
->state
) ||
793 test_bit(__I40E_CONFIG_BUSY
, pf
->state
))
796 ns
= i40e_get_vsi_stats_struct(vsi
);
797 ons
= &vsi
->net_stats_offsets
;
798 es
= &vsi
->eth_stats
;
799 oes
= &vsi
->eth_stats_offsets
;
801 /* Gather up the netdev and vsi stats that the driver collects
802 * on the fly during packet processing
806 tx_restart
= tx_busy
= tx_linearize
= tx_force_wb
= 0;
810 for (q
= 0; q
< vsi
->num_queue_pairs
; q
++) {
812 p
= READ_ONCE(vsi
->tx_rings
[q
]);
817 start
= u64_stats_fetch_begin_irq(&p
->syncp
);
818 packets
= p
->stats
.packets
;
819 bytes
= p
->stats
.bytes
;
820 } while (u64_stats_fetch_retry_irq(&p
->syncp
, start
));
823 tx_restart
+= p
->tx_stats
.restart_queue
;
824 tx_busy
+= p
->tx_stats
.tx_busy
;
825 tx_linearize
+= p
->tx_stats
.tx_linearize
;
826 tx_force_wb
+= p
->tx_stats
.tx_force_wb
;
829 p
= READ_ONCE(vsi
->rx_rings
[q
]);
834 start
= u64_stats_fetch_begin_irq(&p
->syncp
);
835 packets
= p
->stats
.packets
;
836 bytes
= p
->stats
.bytes
;
837 } while (u64_stats_fetch_retry_irq(&p
->syncp
, start
));
840 rx_buf
+= p
->rx_stats
.alloc_buff_failed
;
841 rx_page
+= p
->rx_stats
.alloc_page_failed
;
843 if (i40e_enabled_xdp_vsi(vsi
)) {
844 /* locate XDP ring */
845 p
= READ_ONCE(vsi
->xdp_rings
[q
]);
850 start
= u64_stats_fetch_begin_irq(&p
->syncp
);
851 packets
= p
->stats
.packets
;
852 bytes
= p
->stats
.bytes
;
853 } while (u64_stats_fetch_retry_irq(&p
->syncp
, start
));
856 tx_restart
+= p
->tx_stats
.restart_queue
;
857 tx_busy
+= p
->tx_stats
.tx_busy
;
858 tx_linearize
+= p
->tx_stats
.tx_linearize
;
859 tx_force_wb
+= p
->tx_stats
.tx_force_wb
;
863 vsi
->tx_restart
= tx_restart
;
864 vsi
->tx_busy
= tx_busy
;
865 vsi
->tx_linearize
= tx_linearize
;
866 vsi
->tx_force_wb
= tx_force_wb
;
867 vsi
->rx_page_failed
= rx_page
;
868 vsi
->rx_buf_failed
= rx_buf
;
870 ns
->rx_packets
= rx_p
;
872 ns
->tx_packets
= tx_p
;
875 /* update netdev stats from eth stats */
876 i40e_update_eth_stats(vsi
);
877 ons
->tx_errors
= oes
->tx_errors
;
878 ns
->tx_errors
= es
->tx_errors
;
879 ons
->multicast
= oes
->rx_multicast
;
880 ns
->multicast
= es
->rx_multicast
;
881 ons
->rx_dropped
= oes
->rx_discards
;
882 ns
->rx_dropped
= es
->rx_discards
;
883 ons
->tx_dropped
= oes
->tx_discards
;
884 ns
->tx_dropped
= es
->tx_discards
;
886 /* pull in a couple PF stats if this is the main vsi */
887 if (vsi
== pf
->vsi
[pf
->lan_vsi
]) {
888 ns
->rx_crc_errors
= pf
->stats
.crc_errors
;
889 ns
->rx_errors
= pf
->stats
.crc_errors
+ pf
->stats
.illegal_bytes
;
890 ns
->rx_length_errors
= pf
->stats
.rx_length_errors
;
895 * i40e_update_pf_stats - Update the PF statistics counters.
896 * @pf: the PF to be updated
898 static void i40e_update_pf_stats(struct i40e_pf
*pf
)
900 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
901 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
902 struct i40e_hw
*hw
= &pf
->hw
;
906 i40e_stat_update48(hw
, I40E_GLPRT_GORCH(hw
->port
),
907 I40E_GLPRT_GORCL(hw
->port
),
908 pf
->stat_offsets_loaded
,
909 &osd
->eth
.rx_bytes
, &nsd
->eth
.rx_bytes
);
910 i40e_stat_update48(hw
, I40E_GLPRT_GOTCH(hw
->port
),
911 I40E_GLPRT_GOTCL(hw
->port
),
912 pf
->stat_offsets_loaded
,
913 &osd
->eth
.tx_bytes
, &nsd
->eth
.tx_bytes
);
914 i40e_stat_update32(hw
, I40E_GLPRT_RDPC(hw
->port
),
915 pf
->stat_offsets_loaded
,
916 &osd
->eth
.rx_discards
,
917 &nsd
->eth
.rx_discards
);
918 i40e_stat_update48(hw
, I40E_GLPRT_UPRCH(hw
->port
),
919 I40E_GLPRT_UPRCL(hw
->port
),
920 pf
->stat_offsets_loaded
,
921 &osd
->eth
.rx_unicast
,
922 &nsd
->eth
.rx_unicast
);
923 i40e_stat_update48(hw
, I40E_GLPRT_MPRCH(hw
->port
),
924 I40E_GLPRT_MPRCL(hw
->port
),
925 pf
->stat_offsets_loaded
,
926 &osd
->eth
.rx_multicast
,
927 &nsd
->eth
.rx_multicast
);
928 i40e_stat_update48(hw
, I40E_GLPRT_BPRCH(hw
->port
),
929 I40E_GLPRT_BPRCL(hw
->port
),
930 pf
->stat_offsets_loaded
,
931 &osd
->eth
.rx_broadcast
,
932 &nsd
->eth
.rx_broadcast
);
933 i40e_stat_update48(hw
, I40E_GLPRT_UPTCH(hw
->port
),
934 I40E_GLPRT_UPTCL(hw
->port
),
935 pf
->stat_offsets_loaded
,
936 &osd
->eth
.tx_unicast
,
937 &nsd
->eth
.tx_unicast
);
938 i40e_stat_update48(hw
, I40E_GLPRT_MPTCH(hw
->port
),
939 I40E_GLPRT_MPTCL(hw
->port
),
940 pf
->stat_offsets_loaded
,
941 &osd
->eth
.tx_multicast
,
942 &nsd
->eth
.tx_multicast
);
943 i40e_stat_update48(hw
, I40E_GLPRT_BPTCH(hw
->port
),
944 I40E_GLPRT_BPTCL(hw
->port
),
945 pf
->stat_offsets_loaded
,
946 &osd
->eth
.tx_broadcast
,
947 &nsd
->eth
.tx_broadcast
);
949 i40e_stat_update32(hw
, I40E_GLPRT_TDOLD(hw
->port
),
950 pf
->stat_offsets_loaded
,
951 &osd
->tx_dropped_link_down
,
952 &nsd
->tx_dropped_link_down
);
954 i40e_stat_update32(hw
, I40E_GLPRT_CRCERRS(hw
->port
),
955 pf
->stat_offsets_loaded
,
956 &osd
->crc_errors
, &nsd
->crc_errors
);
958 i40e_stat_update32(hw
, I40E_GLPRT_ILLERRC(hw
->port
),
959 pf
->stat_offsets_loaded
,
960 &osd
->illegal_bytes
, &nsd
->illegal_bytes
);
962 i40e_stat_update32(hw
, I40E_GLPRT_MLFC(hw
->port
),
963 pf
->stat_offsets_loaded
,
964 &osd
->mac_local_faults
,
965 &nsd
->mac_local_faults
);
966 i40e_stat_update32(hw
, I40E_GLPRT_MRFC(hw
->port
),
967 pf
->stat_offsets_loaded
,
968 &osd
->mac_remote_faults
,
969 &nsd
->mac_remote_faults
);
971 i40e_stat_update32(hw
, I40E_GLPRT_RLEC(hw
->port
),
972 pf
->stat_offsets_loaded
,
973 &osd
->rx_length_errors
,
974 &nsd
->rx_length_errors
);
976 i40e_stat_update32(hw
, I40E_GLPRT_LXONRXC(hw
->port
),
977 pf
->stat_offsets_loaded
,
978 &osd
->link_xon_rx
, &nsd
->link_xon_rx
);
979 i40e_stat_update32(hw
, I40E_GLPRT_LXONTXC(hw
->port
),
980 pf
->stat_offsets_loaded
,
981 &osd
->link_xon_tx
, &nsd
->link_xon_tx
);
982 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFRXC(hw
->port
),
983 pf
->stat_offsets_loaded
,
984 &osd
->link_xoff_rx
, &nsd
->link_xoff_rx
);
985 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFTXC(hw
->port
),
986 pf
->stat_offsets_loaded
,
987 &osd
->link_xoff_tx
, &nsd
->link_xoff_tx
);
989 for (i
= 0; i
< 8; i
++) {
990 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFRXC(hw
->port
, i
),
991 pf
->stat_offsets_loaded
,
992 &osd
->priority_xoff_rx
[i
],
993 &nsd
->priority_xoff_rx
[i
]);
994 i40e_stat_update32(hw
, I40E_GLPRT_PXONRXC(hw
->port
, i
),
995 pf
->stat_offsets_loaded
,
996 &osd
->priority_xon_rx
[i
],
997 &nsd
->priority_xon_rx
[i
]);
998 i40e_stat_update32(hw
, I40E_GLPRT_PXONTXC(hw
->port
, i
),
999 pf
->stat_offsets_loaded
,
1000 &osd
->priority_xon_tx
[i
],
1001 &nsd
->priority_xon_tx
[i
]);
1002 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFTXC(hw
->port
, i
),
1003 pf
->stat_offsets_loaded
,
1004 &osd
->priority_xoff_tx
[i
],
1005 &nsd
->priority_xoff_tx
[i
]);
1006 i40e_stat_update32(hw
,
1007 I40E_GLPRT_RXON2OFFCNT(hw
->port
, i
),
1008 pf
->stat_offsets_loaded
,
1009 &osd
->priority_xon_2_xoff
[i
],
1010 &nsd
->priority_xon_2_xoff
[i
]);
1013 i40e_stat_update48(hw
, I40E_GLPRT_PRC64H(hw
->port
),
1014 I40E_GLPRT_PRC64L(hw
->port
),
1015 pf
->stat_offsets_loaded
,
1016 &osd
->rx_size_64
, &nsd
->rx_size_64
);
1017 i40e_stat_update48(hw
, I40E_GLPRT_PRC127H(hw
->port
),
1018 I40E_GLPRT_PRC127L(hw
->port
),
1019 pf
->stat_offsets_loaded
,
1020 &osd
->rx_size_127
, &nsd
->rx_size_127
);
1021 i40e_stat_update48(hw
, I40E_GLPRT_PRC255H(hw
->port
),
1022 I40E_GLPRT_PRC255L(hw
->port
),
1023 pf
->stat_offsets_loaded
,
1024 &osd
->rx_size_255
, &nsd
->rx_size_255
);
1025 i40e_stat_update48(hw
, I40E_GLPRT_PRC511H(hw
->port
),
1026 I40E_GLPRT_PRC511L(hw
->port
),
1027 pf
->stat_offsets_loaded
,
1028 &osd
->rx_size_511
, &nsd
->rx_size_511
);
1029 i40e_stat_update48(hw
, I40E_GLPRT_PRC1023H(hw
->port
),
1030 I40E_GLPRT_PRC1023L(hw
->port
),
1031 pf
->stat_offsets_loaded
,
1032 &osd
->rx_size_1023
, &nsd
->rx_size_1023
);
1033 i40e_stat_update48(hw
, I40E_GLPRT_PRC1522H(hw
->port
),
1034 I40E_GLPRT_PRC1522L(hw
->port
),
1035 pf
->stat_offsets_loaded
,
1036 &osd
->rx_size_1522
, &nsd
->rx_size_1522
);
1037 i40e_stat_update48(hw
, I40E_GLPRT_PRC9522H(hw
->port
),
1038 I40E_GLPRT_PRC9522L(hw
->port
),
1039 pf
->stat_offsets_loaded
,
1040 &osd
->rx_size_big
, &nsd
->rx_size_big
);
1042 i40e_stat_update48(hw
, I40E_GLPRT_PTC64H(hw
->port
),
1043 I40E_GLPRT_PTC64L(hw
->port
),
1044 pf
->stat_offsets_loaded
,
1045 &osd
->tx_size_64
, &nsd
->tx_size_64
);
1046 i40e_stat_update48(hw
, I40E_GLPRT_PTC127H(hw
->port
),
1047 I40E_GLPRT_PTC127L(hw
->port
),
1048 pf
->stat_offsets_loaded
,
1049 &osd
->tx_size_127
, &nsd
->tx_size_127
);
1050 i40e_stat_update48(hw
, I40E_GLPRT_PTC255H(hw
->port
),
1051 I40E_GLPRT_PTC255L(hw
->port
),
1052 pf
->stat_offsets_loaded
,
1053 &osd
->tx_size_255
, &nsd
->tx_size_255
);
1054 i40e_stat_update48(hw
, I40E_GLPRT_PTC511H(hw
->port
),
1055 I40E_GLPRT_PTC511L(hw
->port
),
1056 pf
->stat_offsets_loaded
,
1057 &osd
->tx_size_511
, &nsd
->tx_size_511
);
1058 i40e_stat_update48(hw
, I40E_GLPRT_PTC1023H(hw
->port
),
1059 I40E_GLPRT_PTC1023L(hw
->port
),
1060 pf
->stat_offsets_loaded
,
1061 &osd
->tx_size_1023
, &nsd
->tx_size_1023
);
1062 i40e_stat_update48(hw
, I40E_GLPRT_PTC1522H(hw
->port
),
1063 I40E_GLPRT_PTC1522L(hw
->port
),
1064 pf
->stat_offsets_loaded
,
1065 &osd
->tx_size_1522
, &nsd
->tx_size_1522
);
1066 i40e_stat_update48(hw
, I40E_GLPRT_PTC9522H(hw
->port
),
1067 I40E_GLPRT_PTC9522L(hw
->port
),
1068 pf
->stat_offsets_loaded
,
1069 &osd
->tx_size_big
, &nsd
->tx_size_big
);
1071 i40e_stat_update32(hw
, I40E_GLPRT_RUC(hw
->port
),
1072 pf
->stat_offsets_loaded
,
1073 &osd
->rx_undersize
, &nsd
->rx_undersize
);
1074 i40e_stat_update32(hw
, I40E_GLPRT_RFC(hw
->port
),
1075 pf
->stat_offsets_loaded
,
1076 &osd
->rx_fragments
, &nsd
->rx_fragments
);
1077 i40e_stat_update32(hw
, I40E_GLPRT_ROC(hw
->port
),
1078 pf
->stat_offsets_loaded
,
1079 &osd
->rx_oversize
, &nsd
->rx_oversize
);
1080 i40e_stat_update32(hw
, I40E_GLPRT_RJC(hw
->port
),
1081 pf
->stat_offsets_loaded
,
1082 &osd
->rx_jabber
, &nsd
->rx_jabber
);
1085 i40e_stat_update_and_clear32(hw
,
1086 I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(hw
->pf_id
)),
1087 &nsd
->fd_atr_match
);
1088 i40e_stat_update_and_clear32(hw
,
1089 I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(hw
->pf_id
)),
1091 i40e_stat_update_and_clear32(hw
,
1092 I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(hw
->pf_id
)),
1093 &nsd
->fd_atr_tunnel_match
);
1095 val
= rd32(hw
, I40E_PRTPM_EEE_STAT
);
1096 nsd
->tx_lpi_status
=
1097 (val
& I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK
) >>
1098 I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT
;
1099 nsd
->rx_lpi_status
=
1100 (val
& I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK
) >>
1101 I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT
;
1102 i40e_stat_update32(hw
, I40E_PRTPM_TLPIC
,
1103 pf
->stat_offsets_loaded
,
1104 &osd
->tx_lpi_count
, &nsd
->tx_lpi_count
);
1105 i40e_stat_update32(hw
, I40E_PRTPM_RLPIC
,
1106 pf
->stat_offsets_loaded
,
1107 &osd
->rx_lpi_count
, &nsd
->rx_lpi_count
);
1109 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
&&
1110 !test_bit(__I40E_FD_SB_AUTO_DISABLED
, pf
->state
))
1111 nsd
->fd_sb_status
= true;
1113 nsd
->fd_sb_status
= false;
1115 if (pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
&&
1116 !test_bit(__I40E_FD_ATR_AUTO_DISABLED
, pf
->state
))
1117 nsd
->fd_atr_status
= true;
1119 nsd
->fd_atr_status
= false;
1121 pf
->stat_offsets_loaded
= true;
1125 * i40e_update_stats - Update the various statistics counters.
1126 * @vsi: the VSI to be updated
1128 * Update the various stats for this VSI and its related entities.
1130 void i40e_update_stats(struct i40e_vsi
*vsi
)
1132 struct i40e_pf
*pf
= vsi
->back
;
1134 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
1135 i40e_update_pf_stats(pf
);
1137 i40e_update_vsi_stats(vsi
);
1141 * i40e_count_filters - counts VSI mac filters
1142 * @vsi: the VSI to be searched
1144 * Returns count of mac filters
1146 int i40e_count_filters(struct i40e_vsi
*vsi
)
1148 struct i40e_mac_filter
*f
;
1149 struct hlist_node
*h
;
1153 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
)
1160 * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
1161 * @vsi: the VSI to be searched
1162 * @macaddr: the MAC address
1165 * Returns ptr to the filter object or NULL
1167 static struct i40e_mac_filter
*i40e_find_filter(struct i40e_vsi
*vsi
,
1168 const u8
*macaddr
, s16 vlan
)
1170 struct i40e_mac_filter
*f
;
1173 if (!vsi
|| !macaddr
)
1176 key
= i40e_addr_to_hkey(macaddr
);
1177 hash_for_each_possible(vsi
->mac_filter_hash
, f
, hlist
, key
) {
1178 if ((ether_addr_equal(macaddr
, f
->macaddr
)) &&
1186 * i40e_find_mac - Find a mac addr in the macvlan filters list
1187 * @vsi: the VSI to be searched
1188 * @macaddr: the MAC address we are searching for
1190 * Returns the first filter with the provided MAC address or NULL if
1191 * MAC address was not found
1193 struct i40e_mac_filter
*i40e_find_mac(struct i40e_vsi
*vsi
, const u8
*macaddr
)
1195 struct i40e_mac_filter
*f
;
1198 if (!vsi
|| !macaddr
)
1201 key
= i40e_addr_to_hkey(macaddr
);
1202 hash_for_each_possible(vsi
->mac_filter_hash
, f
, hlist
, key
) {
1203 if ((ether_addr_equal(macaddr
, f
->macaddr
)))
1210 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1211 * @vsi: the VSI to be searched
1213 * Returns true if VSI is in vlan mode or false otherwise
1215 bool i40e_is_vsi_in_vlan(struct i40e_vsi
*vsi
)
1217 /* If we have a PVID, always operate in VLAN mode */
1221 /* We need to operate in VLAN mode whenever we have any filters with
1222 * a VLAN other than I40E_VLAN_ALL. We could check the table each
1223 * time, incurring search cost repeatedly. However, we can notice two
1226 * 1) the only place where we can gain a VLAN filter is in
1229 * 2) the only place where filters are actually removed is in
1230 * i40e_sync_filters_subtask.
1232 * Thus, we can simply use a boolean value, has_vlan_filters which we
1233 * will set to true when we add a VLAN filter in i40e_add_filter. Then
1234 * we have to perform the full search after deleting filters in
1235 * i40e_sync_filters_subtask, but we already have to search
1236 * filters here and can perform the check at the same time. This
1237 * results in avoiding embedding a loop for VLAN mode inside another
1238 * loop over all the filters, and should maintain correctness as noted
1241 return vsi
->has_vlan_filter
;
1245 * i40e_correct_mac_vlan_filters - Correct non-VLAN filters if necessary
1246 * @vsi: the VSI to configure
1247 * @tmp_add_list: list of filters ready to be added
1248 * @tmp_del_list: list of filters ready to be deleted
1249 * @vlan_filters: the number of active VLAN filters
1251 * Update VLAN=0 and VLAN=-1 (I40E_VLAN_ANY) filters properly so that they
1252 * behave as expected. If we have any active VLAN filters remaining or about
1253 * to be added then we need to update non-VLAN filters to be marked as VLAN=0
1254 * so that they only match against untagged traffic. If we no longer have any
1255 * active VLAN filters, we need to make all non-VLAN filters marked as VLAN=-1
1256 * so that they match against both tagged and untagged traffic. In this way,
1257 * we ensure that we correctly receive the desired traffic. This ensures that
1258 * when we have an active VLAN we will receive only untagged traffic and
1259 * traffic matching active VLANs. If we have no active VLANs then we will
1260 * operate in non-VLAN mode and receive all traffic, tagged or untagged.
1262 * Finally, in a similar fashion, this function also corrects filters when
1263 * there is an active PVID assigned to this VSI.
1265 * In case of memory allocation failure return -ENOMEM. Otherwise, return 0.
1267 * This function is only expected to be called from within
1268 * i40e_sync_vsi_filters.
1270 * NOTE: This function expects to be called while under the
1271 * mac_filter_hash_lock
1273 static int i40e_correct_mac_vlan_filters(struct i40e_vsi
*vsi
,
1274 struct hlist_head
*tmp_add_list
,
1275 struct hlist_head
*tmp_del_list
,
1278 s16 pvid
= le16_to_cpu(vsi
->info
.pvid
);
1279 struct i40e_mac_filter
*f
, *add_head
;
1280 struct i40e_new_mac_filter
*new;
1281 struct hlist_node
*h
;
1284 /* To determine if a particular filter needs to be replaced we
1285 * have the three following conditions:
1287 * a) if we have a PVID assigned, then all filters which are
1288 * not marked as VLAN=PVID must be replaced with filters that
1290 * b) otherwise, if we have any active VLANS, all filters
1291 * which are marked as VLAN=-1 must be replaced with
1292 * filters marked as VLAN=0
1293 * c) finally, if we do not have any active VLANS, all filters
1294 * which are marked as VLAN=0 must be replaced with filters
1298 /* Update the filters about to be added in place */
1299 hlist_for_each_entry(new, tmp_add_list
, hlist
) {
1300 if (pvid
&& new->f
->vlan
!= pvid
)
1301 new->f
->vlan
= pvid
;
1302 else if (vlan_filters
&& new->f
->vlan
== I40E_VLAN_ANY
)
1304 else if (!vlan_filters
&& new->f
->vlan
== 0)
1305 new->f
->vlan
= I40E_VLAN_ANY
;
1308 /* Update the remaining active filters */
1309 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
1310 /* Combine the checks for whether a filter needs to be changed
1311 * and then determine the new VLAN inside the if block, in
1312 * order to avoid duplicating code for adding the new filter
1313 * then deleting the old filter.
1315 if ((pvid
&& f
->vlan
!= pvid
) ||
1316 (vlan_filters
&& f
->vlan
== I40E_VLAN_ANY
) ||
1317 (!vlan_filters
&& f
->vlan
== 0)) {
1318 /* Determine the new vlan we will be adding */
1321 else if (vlan_filters
)
1324 new_vlan
= I40E_VLAN_ANY
;
1326 /* Create the new filter */
1327 add_head
= i40e_add_filter(vsi
, f
->macaddr
, new_vlan
);
1331 /* Create a temporary i40e_new_mac_filter */
1332 new = kzalloc(sizeof(*new), GFP_ATOMIC
);
1337 new->state
= add_head
->state
;
1339 /* Add the new filter to the tmp list */
1340 hlist_add_head(&new->hlist
, tmp_add_list
);
1342 /* Put the original filter into the delete list */
1343 f
->state
= I40E_FILTER_REMOVE
;
1344 hash_del(&f
->hlist
);
1345 hlist_add_head(&f
->hlist
, tmp_del_list
);
1349 vsi
->has_vlan_filter
= !!vlan_filters
;
1355 * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
1356 * @vsi: the PF Main VSI - inappropriate for any other VSI
1357 * @macaddr: the MAC address
1359 * Remove whatever filter the firmware set up so the driver can manage
1360 * its own filtering intelligently.
1362 static void i40e_rm_default_mac_filter(struct i40e_vsi
*vsi
, u8
*macaddr
)
1364 struct i40e_aqc_remove_macvlan_element_data element
;
1365 struct i40e_pf
*pf
= vsi
->back
;
1367 /* Only appropriate for the PF main VSI */
1368 if (vsi
->type
!= I40E_VSI_MAIN
)
1371 memset(&element
, 0, sizeof(element
));
1372 ether_addr_copy(element
.mac_addr
, macaddr
);
1373 element
.vlan_tag
= 0;
1374 /* Ignore error returns, some firmware does it this way... */
1375 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
1376 i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1378 memset(&element
, 0, sizeof(element
));
1379 ether_addr_copy(element
.mac_addr
, macaddr
);
1380 element
.vlan_tag
= 0;
1381 /* ...and some firmware does it this way. */
1382 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
|
1383 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
1384 i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1388 * i40e_add_filter - Add a mac/vlan filter to the VSI
1389 * @vsi: the VSI to be searched
1390 * @macaddr: the MAC address
1393 * Returns ptr to the filter object or NULL when no memory available.
1395 * NOTE: This function is expected to be called with mac_filter_hash_lock
1398 struct i40e_mac_filter
*i40e_add_filter(struct i40e_vsi
*vsi
,
1399 const u8
*macaddr
, s16 vlan
)
1401 struct i40e_mac_filter
*f
;
1404 if (!vsi
|| !macaddr
)
1407 f
= i40e_find_filter(vsi
, macaddr
, vlan
);
1409 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
1413 /* Update the boolean indicating if we need to function in
1417 vsi
->has_vlan_filter
= true;
1419 ether_addr_copy(f
->macaddr
, macaddr
);
1421 f
->state
= I40E_FILTER_NEW
;
1422 INIT_HLIST_NODE(&f
->hlist
);
1424 key
= i40e_addr_to_hkey(macaddr
);
1425 hash_add(vsi
->mac_filter_hash
, &f
->hlist
, key
);
1427 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1428 set_bit(__I40E_MACVLAN_SYNC_PENDING
, vsi
->back
->state
);
1431 /* If we're asked to add a filter that has been marked for removal, it
1432 * is safe to simply restore it to active state. __i40e_del_filter
1433 * will have simply deleted any filters which were previously marked
1434 * NEW or FAILED, so if it is currently marked REMOVE it must have
1435 * previously been ACTIVE. Since we haven't yet run the sync filters
1436 * task, just restore this filter to the ACTIVE state so that the
1437 * sync task leaves it in place
1439 if (f
->state
== I40E_FILTER_REMOVE
)
1440 f
->state
= I40E_FILTER_ACTIVE
;
1446 * __i40e_del_filter - Remove a specific filter from the VSI
1447 * @vsi: VSI to remove from
1448 * @f: the filter to remove from the list
1450 * This function should be called instead of i40e_del_filter only if you know
1451 * the exact filter you will remove already, such as via i40e_find_filter or
1454 * NOTE: This function is expected to be called with mac_filter_hash_lock
1456 * ANOTHER NOTE: This function MUST be called from within the context of
1457 * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
1458 * instead of list_for_each_entry().
1460 void __i40e_del_filter(struct i40e_vsi
*vsi
, struct i40e_mac_filter
*f
)
1465 /* If the filter was never added to firmware then we can just delete it
1466 * directly and we don't want to set the status to remove or else an
1467 * admin queue command will unnecessarily fire.
1469 if ((f
->state
== I40E_FILTER_FAILED
) ||
1470 (f
->state
== I40E_FILTER_NEW
)) {
1471 hash_del(&f
->hlist
);
1474 f
->state
= I40E_FILTER_REMOVE
;
1477 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1478 set_bit(__I40E_MACVLAN_SYNC_PENDING
, vsi
->back
->state
);
1482 * i40e_del_filter - Remove a MAC/VLAN filter from the VSI
1483 * @vsi: the VSI to be searched
1484 * @macaddr: the MAC address
1487 * NOTE: This function is expected to be called with mac_filter_hash_lock
1489 * ANOTHER NOTE: This function MUST be called from within the context of
1490 * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
1491 * instead of list_for_each_entry().
1493 void i40e_del_filter(struct i40e_vsi
*vsi
, const u8
*macaddr
, s16 vlan
)
1495 struct i40e_mac_filter
*f
;
1497 if (!vsi
|| !macaddr
)
1500 f
= i40e_find_filter(vsi
, macaddr
, vlan
);
1501 __i40e_del_filter(vsi
, f
);
1505 * i40e_add_mac_filter - Add a MAC filter for all active VLANs
1506 * @vsi: the VSI to be searched
1507 * @macaddr: the mac address to be filtered
1509 * If we're not in VLAN mode, just add the filter to I40E_VLAN_ANY. Otherwise,
1510 * go through all the macvlan filters and add a macvlan filter for each
1511 * unique vlan that already exists. If a PVID has been assigned, instead only
1512 * add the macaddr to that VLAN.
1514 * Returns last filter added on success, else NULL
1516 struct i40e_mac_filter
*i40e_add_mac_filter(struct i40e_vsi
*vsi
,
1519 struct i40e_mac_filter
*f
, *add
= NULL
;
1520 struct hlist_node
*h
;
1524 return i40e_add_filter(vsi
, macaddr
,
1525 le16_to_cpu(vsi
->info
.pvid
));
1527 if (!i40e_is_vsi_in_vlan(vsi
))
1528 return i40e_add_filter(vsi
, macaddr
, I40E_VLAN_ANY
);
1530 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
1531 if (f
->state
== I40E_FILTER_REMOVE
)
1533 add
= i40e_add_filter(vsi
, macaddr
, f
->vlan
);
1542 * i40e_del_mac_filter - Remove a MAC filter from all VLANs
1543 * @vsi: the VSI to be searched
1544 * @macaddr: the mac address to be removed
1546 * Removes a given MAC address from a VSI regardless of what VLAN it has been
1549 * Returns 0 for success, or error
1551 int i40e_del_mac_filter(struct i40e_vsi
*vsi
, const u8
*macaddr
)
1553 struct i40e_mac_filter
*f
;
1554 struct hlist_node
*h
;
1558 lockdep_assert_held(&vsi
->mac_filter_hash_lock
);
1559 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
1560 if (ether_addr_equal(macaddr
, f
->macaddr
)) {
1561 __i40e_del_filter(vsi
, f
);
1573 * i40e_set_mac - NDO callback to set mac address
1574 * @netdev: network interface device structure
1575 * @p: pointer to an address structure
1577 * Returns 0 on success, negative on failure
1579 static int i40e_set_mac(struct net_device
*netdev
, void *p
)
1581 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1582 struct i40e_vsi
*vsi
= np
->vsi
;
1583 struct i40e_pf
*pf
= vsi
->back
;
1584 struct i40e_hw
*hw
= &pf
->hw
;
1585 struct sockaddr
*addr
= p
;
1587 if (!is_valid_ether_addr(addr
->sa_data
))
1588 return -EADDRNOTAVAIL
;
1590 if (ether_addr_equal(netdev
->dev_addr
, addr
->sa_data
)) {
1591 netdev_info(netdev
, "already using mac address %pM\n",
1596 if (test_bit(__I40E_DOWN
, pf
->state
) ||
1597 test_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
))
1598 return -EADDRNOTAVAIL
;
1600 if (ether_addr_equal(hw
->mac
.addr
, addr
->sa_data
))
1601 netdev_info(netdev
, "returning to hw mac address %pM\n",
1604 netdev_info(netdev
, "set new mac address %pM\n", addr
->sa_data
);
1606 /* Copy the address first, so that we avoid a possible race with
1608 * - Remove old address from MAC filter
1609 * - Copy new address
1610 * - Add new address to MAC filter
1612 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
1613 i40e_del_mac_filter(vsi
, netdev
->dev_addr
);
1614 ether_addr_copy(netdev
->dev_addr
, addr
->sa_data
);
1615 i40e_add_mac_filter(vsi
, netdev
->dev_addr
);
1616 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
1618 if (vsi
->type
== I40E_VSI_MAIN
) {
1621 ret
= i40e_aq_mac_address_write(hw
, I40E_AQC_WRITE_TYPE_LAA_WOL
,
1622 addr
->sa_data
, NULL
);
1624 netdev_info(netdev
, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n",
1625 i40e_stat_str(hw
, ret
),
1626 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
1629 /* schedule our worker thread which will take care of
1630 * applying the new filter changes
1632 i40e_service_event_schedule(pf
);
1637 * i40e_config_rss_aq - Prepare for RSS using AQ commands
1638 * @vsi: vsi structure
1639 * @seed: RSS hash seed
1640 * @lut: pointer to lookup table of lut_size
1641 * @lut_size: size of the lookup table
1643 static int i40e_config_rss_aq(struct i40e_vsi
*vsi
, const u8
*seed
,
1644 u8
*lut
, u16 lut_size
)
1646 struct i40e_pf
*pf
= vsi
->back
;
1647 struct i40e_hw
*hw
= &pf
->hw
;
1651 struct i40e_aqc_get_set_rss_key_data
*seed_dw
=
1652 (struct i40e_aqc_get_set_rss_key_data
*)seed
;
1653 ret
= i40e_aq_set_rss_key(hw
, vsi
->id
, seed_dw
);
1655 dev_info(&pf
->pdev
->dev
,
1656 "Cannot set RSS key, err %s aq_err %s\n",
1657 i40e_stat_str(hw
, ret
),
1658 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
1663 bool pf_lut
= vsi
->type
== I40E_VSI_MAIN
;
1665 ret
= i40e_aq_set_rss_lut(hw
, vsi
->id
, pf_lut
, lut
, lut_size
);
1667 dev_info(&pf
->pdev
->dev
,
1668 "Cannot set RSS lut, err %s aq_err %s\n",
1669 i40e_stat_str(hw
, ret
),
1670 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
1678 * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
1679 * @vsi: VSI structure
1681 static int i40e_vsi_config_rss(struct i40e_vsi
*vsi
)
1683 struct i40e_pf
*pf
= vsi
->back
;
1684 u8 seed
[I40E_HKEY_ARRAY_SIZE
];
1688 if (!(pf
->hw_features
& I40E_HW_RSS_AQ_CAPABLE
))
1691 vsi
->rss_size
= min_t(int, pf
->alloc_rss_size
,
1692 vsi
->num_queue_pairs
);
1695 lut
= kzalloc(vsi
->rss_table_size
, GFP_KERNEL
);
1699 /* Use the user configured hash keys and lookup table if there is one,
1700 * otherwise use default
1702 if (vsi
->rss_lut_user
)
1703 memcpy(lut
, vsi
->rss_lut_user
, vsi
->rss_table_size
);
1705 i40e_fill_rss_lut(pf
, lut
, vsi
->rss_table_size
, vsi
->rss_size
);
1706 if (vsi
->rss_hkey_user
)
1707 memcpy(seed
, vsi
->rss_hkey_user
, I40E_HKEY_ARRAY_SIZE
);
1709 netdev_rss_key_fill((void *)seed
, I40E_HKEY_ARRAY_SIZE
);
1710 ret
= i40e_config_rss_aq(vsi
, seed
, lut
, vsi
->rss_table_size
);
1716 * i40e_vsi_setup_queue_map_mqprio - Prepares mqprio based tc_config
1717 * @vsi: the VSI being configured,
1718 * @ctxt: VSI context structure
1719 * @enabled_tc: number of traffic classes to enable
1721 * Prepares VSI tc_config to have queue configurations based on MQPRIO options.
1723 static int i40e_vsi_setup_queue_map_mqprio(struct i40e_vsi
*vsi
,
1724 struct i40e_vsi_context
*ctxt
,
1727 u16 qcount
= 0, max_qcount
, qmap
, sections
= 0;
1728 int i
, override_q
, pow
, num_qps
, ret
;
1729 u8 netdev_tc
= 0, offset
= 0;
1731 if (vsi
->type
!= I40E_VSI_MAIN
)
1733 sections
= I40E_AQ_VSI_PROP_QUEUE_MAP_VALID
;
1734 sections
|= I40E_AQ_VSI_PROP_SCHED_VALID
;
1735 vsi
->tc_config
.numtc
= vsi
->mqprio_qopt
.qopt
.num_tc
;
1736 vsi
->tc_config
.enabled_tc
= enabled_tc
? enabled_tc
: 1;
1737 num_qps
= vsi
->mqprio_qopt
.qopt
.count
[0];
1739 /* find the next higher power-of-2 of num queue pairs */
1740 pow
= ilog2(num_qps
);
1741 if (!is_power_of_2(num_qps
))
1743 qmap
= (offset
<< I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT
) |
1744 (pow
<< I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT
);
1746 /* Setup queue offset/count for all TCs for given VSI */
1747 max_qcount
= vsi
->mqprio_qopt
.qopt
.count
[0];
1748 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1749 /* See if the given TC is enabled for the given VSI */
1750 if (vsi
->tc_config
.enabled_tc
& BIT(i
)) {
1751 offset
= vsi
->mqprio_qopt
.qopt
.offset
[i
];
1752 qcount
= vsi
->mqprio_qopt
.qopt
.count
[i
];
1753 if (qcount
> max_qcount
)
1754 max_qcount
= qcount
;
1755 vsi
->tc_config
.tc_info
[i
].qoffset
= offset
;
1756 vsi
->tc_config
.tc_info
[i
].qcount
= qcount
;
1757 vsi
->tc_config
.tc_info
[i
].netdev_tc
= netdev_tc
++;
1759 /* TC is not enabled so set the offset to
1760 * default queue and allocate one queue
1763 vsi
->tc_config
.tc_info
[i
].qoffset
= 0;
1764 vsi
->tc_config
.tc_info
[i
].qcount
= 1;
1765 vsi
->tc_config
.tc_info
[i
].netdev_tc
= 0;
1769 /* Set actual Tx/Rx queue pairs */
1770 vsi
->num_queue_pairs
= offset
+ qcount
;
1772 /* Setup queue TC[0].qmap for given VSI context */
1773 ctxt
->info
.tc_mapping
[0] = cpu_to_le16(qmap
);
1774 ctxt
->info
.mapping_flags
|= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG
);
1775 ctxt
->info
.queue_mapping
[0] = cpu_to_le16(vsi
->base_queue
);
1776 ctxt
->info
.valid_sections
|= cpu_to_le16(sections
);
1778 /* Reconfigure RSS for main VSI with max queue count */
1779 vsi
->rss_size
= max_qcount
;
1780 ret
= i40e_vsi_config_rss(vsi
);
1782 dev_info(&vsi
->back
->pdev
->dev
,
1783 "Failed to reconfig rss for num_queues (%u)\n",
1787 vsi
->reconfig_rss
= true;
1788 dev_dbg(&vsi
->back
->pdev
->dev
,
1789 "Reconfigured rss with num_queues (%u)\n", max_qcount
);
1791 /* Find queue count available for channel VSIs and starting offset
1794 override_q
= vsi
->mqprio_qopt
.qopt
.count
[0];
1795 if (override_q
&& override_q
< vsi
->num_queue_pairs
) {
1796 vsi
->cnt_q_avail
= vsi
->num_queue_pairs
- override_q
;
1797 vsi
->next_base_queue
= override_q
;
1803 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1804 * @vsi: the VSI being setup
1805 * @ctxt: VSI context structure
1806 * @enabled_tc: Enabled TCs bitmap
1807 * @is_add: True if called before Add VSI
1809 * Setup VSI queue mapping for enabled traffic classes.
1811 static void i40e_vsi_setup_queue_map(struct i40e_vsi
*vsi
,
1812 struct i40e_vsi_context
*ctxt
,
1816 struct i40e_pf
*pf
= vsi
->back
;
1826 sections
= I40E_AQ_VSI_PROP_QUEUE_MAP_VALID
;
1828 /* zero out queue mapping, it will get updated on the end of the function */
1829 memset(ctxt
->info
.queue_mapping
, 0, sizeof(ctxt
->info
.queue_mapping
));
1831 if (vsi
->type
== I40E_VSI_MAIN
) {
1832 /* This code helps add more queue to the VSI if we have
1833 * more cores than RSS can support, the higher cores will
1834 * be served by ATR or other filters. Furthermore, the
1835 * non-zero req_queue_pairs says that user requested a new
1836 * queue count via ethtool's set_channels, so use this
1837 * value for queues distribution across traffic classes
1839 if (vsi
->req_queue_pairs
> 0)
1840 vsi
->num_queue_pairs
= vsi
->req_queue_pairs
;
1841 else if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
1842 vsi
->num_queue_pairs
= pf
->num_lan_msix
;
1845 /* Number of queues per enabled TC */
1846 if (vsi
->type
== I40E_VSI_MAIN
||
1847 (vsi
->type
== I40E_VSI_SRIOV
&& vsi
->num_queue_pairs
!= 0))
1848 num_tc_qps
= vsi
->num_queue_pairs
;
1850 num_tc_qps
= vsi
->alloc_queue_pairs
;
1852 if (enabled_tc
&& (vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
1853 /* Find numtc from enabled TC bitmap */
1854 for (i
= 0, numtc
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1855 if (enabled_tc
& BIT(i
)) /* TC is enabled */
1859 dev_warn(&pf
->pdev
->dev
, "DCB is enabled but no TC enabled, forcing TC0\n");
1862 num_tc_qps
= num_tc_qps
/ numtc
;
1863 num_tc_qps
= min_t(int, num_tc_qps
,
1864 i40e_pf_get_max_q_per_tc(pf
));
1867 vsi
->tc_config
.numtc
= numtc
;
1868 vsi
->tc_config
.enabled_tc
= enabled_tc
? enabled_tc
: 1;
1870 /* Do not allow use more TC queue pairs than MSI-X vectors exist */
1871 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
1872 num_tc_qps
= min_t(int, num_tc_qps
, pf
->num_lan_msix
);
1874 /* Setup queue offset/count for all TCs for given VSI */
1875 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1876 /* See if the given TC is enabled for the given VSI */
1877 if (vsi
->tc_config
.enabled_tc
& BIT(i
)) {
1881 switch (vsi
->type
) {
1883 if (!(pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
|
1884 I40E_FLAG_FD_ATR_ENABLED
)) ||
1885 vsi
->tc_config
.enabled_tc
!= 1) {
1886 qcount
= min_t(int, pf
->alloc_rss_size
,
1892 case I40E_VSI_SRIOV
:
1893 case I40E_VSI_VMDQ2
:
1895 qcount
= num_tc_qps
;
1899 vsi
->tc_config
.tc_info
[i
].qoffset
= offset
;
1900 vsi
->tc_config
.tc_info
[i
].qcount
= qcount
;
1902 /* find the next higher power-of-2 of num queue pairs */
1905 while (num_qps
&& (BIT_ULL(pow
) < qcount
)) {
1910 vsi
->tc_config
.tc_info
[i
].netdev_tc
= netdev_tc
++;
1912 (offset
<< I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT
) |
1913 (pow
<< I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT
);
1917 /* TC is not enabled so set the offset to
1918 * default queue and allocate one queue
1921 vsi
->tc_config
.tc_info
[i
].qoffset
= 0;
1922 vsi
->tc_config
.tc_info
[i
].qcount
= 1;
1923 vsi
->tc_config
.tc_info
[i
].netdev_tc
= 0;
1927 ctxt
->info
.tc_mapping
[i
] = cpu_to_le16(qmap
);
1929 /* Do not change previously set num_queue_pairs for PFs and VFs*/
1930 if ((vsi
->type
== I40E_VSI_MAIN
&& numtc
!= 1) ||
1931 (vsi
->type
== I40E_VSI_SRIOV
&& vsi
->num_queue_pairs
== 0) ||
1932 (vsi
->type
!= I40E_VSI_MAIN
&& vsi
->type
!= I40E_VSI_SRIOV
))
1933 vsi
->num_queue_pairs
= offset
;
1935 /* Scheduler section valid can only be set for ADD VSI */
1937 sections
|= I40E_AQ_VSI_PROP_SCHED_VALID
;
1939 ctxt
->info
.up_enable_bits
= enabled_tc
;
1941 if (vsi
->type
== I40E_VSI_SRIOV
) {
1942 ctxt
->info
.mapping_flags
|=
1943 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG
);
1944 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
1945 ctxt
->info
.queue_mapping
[i
] =
1946 cpu_to_le16(vsi
->base_queue
+ i
);
1948 ctxt
->info
.mapping_flags
|=
1949 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG
);
1950 ctxt
->info
.queue_mapping
[0] = cpu_to_le16(vsi
->base_queue
);
1952 ctxt
->info
.valid_sections
|= cpu_to_le16(sections
);
1956 * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address
1957 * @netdev: the netdevice
1958 * @addr: address to add
1960 * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
1961 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
1963 static int i40e_addr_sync(struct net_device
*netdev
, const u8
*addr
)
1965 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1966 struct i40e_vsi
*vsi
= np
->vsi
;
1968 if (i40e_add_mac_filter(vsi
, addr
))
1975 * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
1976 * @netdev: the netdevice
1977 * @addr: address to add
1979 * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
1980 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
1982 static int i40e_addr_unsync(struct net_device
*netdev
, const u8
*addr
)
1984 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1985 struct i40e_vsi
*vsi
= np
->vsi
;
1987 /* Under some circumstances, we might receive a request to delete
1988 * our own device address from our uc list. Because we store the
1989 * device address in the VSI's MAC/VLAN filter list, we need to ignore
1990 * such requests and not delete our device address from this list.
1992 if (ether_addr_equal(addr
, netdev
->dev_addr
))
1995 i40e_del_mac_filter(vsi
, addr
);
2001 * i40e_set_rx_mode - NDO callback to set the netdev filters
2002 * @netdev: network interface device structure
2004 static void i40e_set_rx_mode(struct net_device
*netdev
)
2006 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2007 struct i40e_vsi
*vsi
= np
->vsi
;
2009 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2011 __dev_uc_sync(netdev
, i40e_addr_sync
, i40e_addr_unsync
);
2012 __dev_mc_sync(netdev
, i40e_addr_sync
, i40e_addr_unsync
);
2014 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2016 /* check for other flag changes */
2017 if (vsi
->current_netdev_flags
!= vsi
->netdev
->flags
) {
2018 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
2019 set_bit(__I40E_MACVLAN_SYNC_PENDING
, vsi
->back
->state
);
2024 * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
2025 * @vsi: Pointer to VSI struct
2026 * @from: Pointer to list which contains MAC filter entries - changes to
2027 * those entries needs to be undone.
2029 * MAC filter entries from this list were slated for deletion.
2031 static void i40e_undo_del_filter_entries(struct i40e_vsi
*vsi
,
2032 struct hlist_head
*from
)
2034 struct i40e_mac_filter
*f
;
2035 struct hlist_node
*h
;
2037 hlist_for_each_entry_safe(f
, h
, from
, hlist
) {
2038 u64 key
= i40e_addr_to_hkey(f
->macaddr
);
2040 /* Move the element back into MAC filter list*/
2041 hlist_del(&f
->hlist
);
2042 hash_add(vsi
->mac_filter_hash
, &f
->hlist
, key
);
2047 * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries
2048 * @vsi: Pointer to vsi struct
2049 * @from: Pointer to list which contains MAC filter entries - changes to
2050 * those entries needs to be undone.
2052 * MAC filter entries from this list were slated for addition.
2054 static void i40e_undo_add_filter_entries(struct i40e_vsi
*vsi
,
2055 struct hlist_head
*from
)
2057 struct i40e_new_mac_filter
*new;
2058 struct hlist_node
*h
;
2060 hlist_for_each_entry_safe(new, h
, from
, hlist
) {
2061 /* We can simply free the wrapper structure */
2062 hlist_del(&new->hlist
);
2063 netdev_hw_addr_refcnt(new->f
, vsi
->netdev
, -1);
2069 * i40e_next_filter - Get the next non-broadcast filter from a list
2070 * @next: pointer to filter in list
2072 * Returns the next non-broadcast filter in the list. Required so that we
2073 * ignore broadcast filters within the list, since these are not handled via
2074 * the normal firmware update path.
2077 struct i40e_new_mac_filter
*i40e_next_filter(struct i40e_new_mac_filter
*next
)
2079 hlist_for_each_entry_continue(next
, hlist
) {
2080 if (!is_broadcast_ether_addr(next
->f
->macaddr
))
2088 * i40e_update_filter_state - Update filter state based on return data
2090 * @count: Number of filters added
2091 * @add_list: return data from fw
2092 * @add_head: pointer to first filter in current batch
2094 * MAC filter entries from list were slated to be added to device. Returns
2095 * number of successful filters. Note that 0 does NOT mean success!
2098 i40e_update_filter_state(int count
,
2099 struct i40e_aqc_add_macvlan_element_data
*add_list
,
2100 struct i40e_new_mac_filter
*add_head
)
2105 for (i
= 0; i
< count
; i
++) {
2106 /* Always check status of each filter. We don't need to check
2107 * the firmware return status because we pre-set the filter
2108 * status to I40E_AQC_MM_ERR_NO_RES when sending the filter
2109 * request to the adminq. Thus, if it no longer matches then
2110 * we know the filter is active.
2112 if (add_list
[i
].match_method
== I40E_AQC_MM_ERR_NO_RES
) {
2113 add_head
->state
= I40E_FILTER_FAILED
;
2115 add_head
->state
= I40E_FILTER_ACTIVE
;
2119 add_head
= i40e_next_filter(add_head
);
2128 * i40e_aqc_del_filters - Request firmware to delete a set of filters
2129 * @vsi: ptr to the VSI
2130 * @vsi_name: name to display in messages
2131 * @list: the list of filters to send to firmware
2132 * @num_del: the number of filters to delete
2133 * @retval: Set to -EIO on failure to delete
2135 * Send a request to firmware via AdminQ to delete a set of filters. Uses
2136 * *retval instead of a return value so that success does not force ret_val to
2137 * be set to 0. This ensures that a sequence of calls to this function
2138 * preserve the previous value of *retval on successful delete.
2141 void i40e_aqc_del_filters(struct i40e_vsi
*vsi
, const char *vsi_name
,
2142 struct i40e_aqc_remove_macvlan_element_data
*list
,
2143 int num_del
, int *retval
)
2145 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2149 aq_ret
= i40e_aq_remove_macvlan(hw
, vsi
->seid
, list
, num_del
, NULL
);
2150 aq_err
= hw
->aq
.asq_last_status
;
2152 /* Explicitly ignore and do not report when firmware returns ENOENT */
2153 if (aq_ret
&& !(aq_err
== I40E_AQ_RC_ENOENT
)) {
2155 dev_info(&vsi
->back
->pdev
->dev
,
2156 "ignoring delete macvlan error on %s, err %s, aq_err %s\n",
2157 vsi_name
, i40e_stat_str(hw
, aq_ret
),
2158 i40e_aq_str(hw
, aq_err
));
2163 * i40e_aqc_add_filters - Request firmware to add a set of filters
2164 * @vsi: ptr to the VSI
2165 * @vsi_name: name to display in messages
2166 * @list: the list of filters to send to firmware
2167 * @add_head: Position in the add hlist
2168 * @num_add: the number of filters to add
2170 * Send a request to firmware via AdminQ to add a chunk of filters. Will set
2171 * __I40E_VSI_OVERFLOW_PROMISC bit in vsi->state if the firmware has run out of
2172 * space for more filters.
2175 void i40e_aqc_add_filters(struct i40e_vsi
*vsi
, const char *vsi_name
,
2176 struct i40e_aqc_add_macvlan_element_data
*list
,
2177 struct i40e_new_mac_filter
*add_head
,
2180 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2183 i40e_aq_add_macvlan(hw
, vsi
->seid
, list
, num_add
, NULL
);
2184 aq_err
= hw
->aq
.asq_last_status
;
2185 fcnt
= i40e_update_filter_state(num_add
, list
, add_head
);
2187 if (fcnt
!= num_add
) {
2188 if (vsi
->type
== I40E_VSI_MAIN
) {
2189 set_bit(__I40E_VSI_OVERFLOW_PROMISC
, vsi
->state
);
2190 dev_warn(&vsi
->back
->pdev
->dev
,
2191 "Error %s adding RX filters on %s, promiscuous mode forced on\n",
2192 i40e_aq_str(hw
, aq_err
), vsi_name
);
2193 } else if (vsi
->type
== I40E_VSI_SRIOV
||
2194 vsi
->type
== I40E_VSI_VMDQ1
||
2195 vsi
->type
== I40E_VSI_VMDQ2
) {
2196 dev_warn(&vsi
->back
->pdev
->dev
,
2197 "Error %s adding RX filters on %s, please set promiscuous on manually for %s\n",
2198 i40e_aq_str(hw
, aq_err
), vsi_name
, vsi_name
);
2200 dev_warn(&vsi
->back
->pdev
->dev
,
2201 "Error %s adding RX filters on %s, incorrect VSI type: %i.\n",
2202 i40e_aq_str(hw
, aq_err
), vsi_name
, vsi
->type
);
2208 * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags
2209 * @vsi: pointer to the VSI
2210 * @vsi_name: the VSI name
2213 * This function sets or clears the promiscuous broadcast flags for VLAN
2214 * filters in order to properly receive broadcast frames. Assumes that only
2215 * broadcast filters are passed.
2217 * Returns status indicating success or failure;
2220 i40e_aqc_broadcast_filter(struct i40e_vsi
*vsi
, const char *vsi_name
,
2221 struct i40e_mac_filter
*f
)
2223 bool enable
= f
->state
== I40E_FILTER_NEW
;
2224 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2227 if (f
->vlan
== I40E_VLAN_ANY
) {
2228 aq_ret
= i40e_aq_set_vsi_broadcast(hw
,
2233 aq_ret
= i40e_aq_set_vsi_bc_promisc_on_vlan(hw
,
2241 set_bit(__I40E_VSI_OVERFLOW_PROMISC
, vsi
->state
);
2242 dev_warn(&vsi
->back
->pdev
->dev
,
2243 "Error %s, forcing overflow promiscuous on %s\n",
2244 i40e_aq_str(hw
, hw
->aq
.asq_last_status
),
2252 * i40e_set_promiscuous - set promiscuous mode
2253 * @pf: board private structure
2254 * @promisc: promisc on or off
2256 * There are different ways of setting promiscuous mode on a PF depending on
2257 * what state/environment we're in. This identifies and sets it appropriately.
2258 * Returns 0 on success.
2260 static int i40e_set_promiscuous(struct i40e_pf
*pf
, bool promisc
)
2262 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
2263 struct i40e_hw
*hw
= &pf
->hw
;
2266 if (vsi
->type
== I40E_VSI_MAIN
&&
2267 pf
->lan_veb
!= I40E_NO_VEB
&&
2268 !(pf
->flags
& I40E_FLAG_MFP_ENABLED
)) {
2269 /* set defport ON for Main VSI instead of true promisc
2270 * this way we will get all unicast/multicast and VLAN
2271 * promisc behavior but will not get VF or VMDq traffic
2272 * replicated on the Main VSI.
2275 aq_ret
= i40e_aq_set_default_vsi(hw
,
2279 aq_ret
= i40e_aq_clear_default_vsi(hw
,
2283 dev_info(&pf
->pdev
->dev
,
2284 "Set default VSI failed, err %s, aq_err %s\n",
2285 i40e_stat_str(hw
, aq_ret
),
2286 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
2289 aq_ret
= i40e_aq_set_vsi_unicast_promiscuous(
2295 dev_info(&pf
->pdev
->dev
,
2296 "set unicast promisc failed, err %s, aq_err %s\n",
2297 i40e_stat_str(hw
, aq_ret
),
2298 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
2300 aq_ret
= i40e_aq_set_vsi_multicast_promiscuous(
2305 dev_info(&pf
->pdev
->dev
,
2306 "set multicast promisc failed, err %s, aq_err %s\n",
2307 i40e_stat_str(hw
, aq_ret
),
2308 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
2313 pf
->cur_promisc
= promisc
;
2319 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
2320 * @vsi: ptr to the VSI
2322 * Push any outstanding VSI filter changes through the AdminQ.
2324 * Returns 0 or error value
2326 int i40e_sync_vsi_filters(struct i40e_vsi
*vsi
)
2328 struct hlist_head tmp_add_list
, tmp_del_list
;
2329 struct i40e_mac_filter
*f
;
2330 struct i40e_new_mac_filter
*new, *add_head
= NULL
;
2331 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2332 bool old_overflow
, new_overflow
;
2333 unsigned int failed_filters
= 0;
2334 unsigned int vlan_filters
= 0;
2335 char vsi_name
[16] = "PF";
2336 int filter_list_len
= 0;
2337 i40e_status aq_ret
= 0;
2338 u32 changed_flags
= 0;
2339 struct hlist_node
*h
;
2348 /* empty array typed pointers, kcalloc later */
2349 struct i40e_aqc_add_macvlan_element_data
*add_list
;
2350 struct i40e_aqc_remove_macvlan_element_data
*del_list
;
2352 while (test_and_set_bit(__I40E_VSI_SYNCING_FILTERS
, vsi
->state
))
2353 usleep_range(1000, 2000);
2356 old_overflow
= test_bit(__I40E_VSI_OVERFLOW_PROMISC
, vsi
->state
);
2359 changed_flags
= vsi
->current_netdev_flags
^ vsi
->netdev
->flags
;
2360 vsi
->current_netdev_flags
= vsi
->netdev
->flags
;
2363 INIT_HLIST_HEAD(&tmp_add_list
);
2364 INIT_HLIST_HEAD(&tmp_del_list
);
2366 if (vsi
->type
== I40E_VSI_SRIOV
)
2367 snprintf(vsi_name
, sizeof(vsi_name
) - 1, "VF %d", vsi
->vf_id
);
2368 else if (vsi
->type
!= I40E_VSI_MAIN
)
2369 snprintf(vsi_name
, sizeof(vsi_name
) - 1, "vsi %d", vsi
->seid
);
2371 if (vsi
->flags
& I40E_VSI_FLAG_FILTER_CHANGED
) {
2372 vsi
->flags
&= ~I40E_VSI_FLAG_FILTER_CHANGED
;
2374 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2375 /* Create a list of filters to delete. */
2376 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
2377 if (f
->state
== I40E_FILTER_REMOVE
) {
2378 /* Move the element into temporary del_list */
2379 hash_del(&f
->hlist
);
2380 hlist_add_head(&f
->hlist
, &tmp_del_list
);
2382 /* Avoid counting removed filters */
2385 if (f
->state
== I40E_FILTER_NEW
) {
2386 /* Create a temporary i40e_new_mac_filter */
2387 new = kzalloc(sizeof(*new), GFP_ATOMIC
);
2389 goto err_no_memory_locked
;
2391 /* Store pointer to the real filter */
2393 new->state
= f
->state
;
2395 /* Add it to the hash list */
2396 hlist_add_head(&new->hlist
, &tmp_add_list
);
2399 /* Count the number of active (current and new) VLAN
2400 * filters we have now. Does not count filters which
2401 * are marked for deletion.
2407 retval
= i40e_correct_mac_vlan_filters(vsi
,
2412 hlist_for_each_entry(new, &tmp_add_list
, hlist
)
2413 netdev_hw_addr_refcnt(new->f
, vsi
->netdev
, 1);
2416 goto err_no_memory_locked
;
2418 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2421 /* Now process 'del_list' outside the lock */
2422 if (!hlist_empty(&tmp_del_list
)) {
2423 filter_list_len
= hw
->aq
.asq_buf_size
/
2424 sizeof(struct i40e_aqc_remove_macvlan_element_data
);
2425 list_size
= filter_list_len
*
2426 sizeof(struct i40e_aqc_remove_macvlan_element_data
);
2427 del_list
= kzalloc(list_size
, GFP_ATOMIC
);
2431 hlist_for_each_entry_safe(f
, h
, &tmp_del_list
, hlist
) {
2434 /* handle broadcast filters by updating the broadcast
2435 * promiscuous flag and release filter list.
2437 if (is_broadcast_ether_addr(f
->macaddr
)) {
2438 i40e_aqc_broadcast_filter(vsi
, vsi_name
, f
);
2440 hlist_del(&f
->hlist
);
2445 /* add to delete list */
2446 ether_addr_copy(del_list
[num_del
].mac_addr
, f
->macaddr
);
2447 if (f
->vlan
== I40E_VLAN_ANY
) {
2448 del_list
[num_del
].vlan_tag
= 0;
2449 cmd_flags
|= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
2451 del_list
[num_del
].vlan_tag
=
2452 cpu_to_le16((u16
)(f
->vlan
));
2455 cmd_flags
|= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
2456 del_list
[num_del
].flags
= cmd_flags
;
2459 /* flush a full buffer */
2460 if (num_del
== filter_list_len
) {
2461 i40e_aqc_del_filters(vsi
, vsi_name
, del_list
,
2463 memset(del_list
, 0, list_size
);
2466 /* Release memory for MAC filter entries which were
2467 * synced up with HW.
2469 hlist_del(&f
->hlist
);
2474 i40e_aqc_del_filters(vsi
, vsi_name
, del_list
,
2482 if (!hlist_empty(&tmp_add_list
)) {
2483 /* Do all the adds now. */
2484 filter_list_len
= hw
->aq
.asq_buf_size
/
2485 sizeof(struct i40e_aqc_add_macvlan_element_data
);
2486 list_size
= filter_list_len
*
2487 sizeof(struct i40e_aqc_add_macvlan_element_data
);
2488 add_list
= kzalloc(list_size
, GFP_ATOMIC
);
2493 hlist_for_each_entry_safe(new, h
, &tmp_add_list
, hlist
) {
2494 /* handle broadcast filters by updating the broadcast
2495 * promiscuous flag instead of adding a MAC filter.
2497 if (is_broadcast_ether_addr(new->f
->macaddr
)) {
2498 if (i40e_aqc_broadcast_filter(vsi
, vsi_name
,
2500 new->state
= I40E_FILTER_FAILED
;
2502 new->state
= I40E_FILTER_ACTIVE
;
2506 /* add to add array */
2510 ether_addr_copy(add_list
[num_add
].mac_addr
,
2512 if (new->f
->vlan
== I40E_VLAN_ANY
) {
2513 add_list
[num_add
].vlan_tag
= 0;
2514 cmd_flags
|= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN
;
2516 add_list
[num_add
].vlan_tag
=
2517 cpu_to_le16((u16
)(new->f
->vlan
));
2519 add_list
[num_add
].queue_number
= 0;
2520 /* set invalid match method for later detection */
2521 add_list
[num_add
].match_method
= I40E_AQC_MM_ERR_NO_RES
;
2522 cmd_flags
|= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
;
2523 add_list
[num_add
].flags
= cpu_to_le16(cmd_flags
);
2526 /* flush a full buffer */
2527 if (num_add
== filter_list_len
) {
2528 i40e_aqc_add_filters(vsi
, vsi_name
, add_list
,
2530 memset(add_list
, 0, list_size
);
2535 i40e_aqc_add_filters(vsi
, vsi_name
, add_list
, add_head
,
2538 /* Now move all of the filters from the temp add list back to
2541 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2542 hlist_for_each_entry_safe(new, h
, &tmp_add_list
, hlist
) {
2543 /* Only update the state if we're still NEW */
2544 if (new->f
->state
== I40E_FILTER_NEW
)
2545 new->f
->state
= new->state
;
2546 hlist_del(&new->hlist
);
2547 netdev_hw_addr_refcnt(new->f
, vsi
->netdev
, -1);
2550 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2555 /* Determine the number of active and failed filters. */
2556 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2557 vsi
->active_filters
= 0;
2558 hash_for_each(vsi
->mac_filter_hash
, bkt
, f
, hlist
) {
2559 if (f
->state
== I40E_FILTER_ACTIVE
)
2560 vsi
->active_filters
++;
2561 else if (f
->state
== I40E_FILTER_FAILED
)
2564 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2566 /* Check if we are able to exit overflow promiscuous mode. We can
2567 * safely exit if we didn't just enter, we no longer have any failed
2568 * filters, and we have reduced filters below the threshold value.
2570 if (old_overflow
&& !failed_filters
&&
2571 vsi
->active_filters
< vsi
->promisc_threshold
) {
2572 dev_info(&pf
->pdev
->dev
,
2573 "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
2575 clear_bit(__I40E_VSI_OVERFLOW_PROMISC
, vsi
->state
);
2576 vsi
->promisc_threshold
= 0;
2579 /* if the VF is not trusted do not do promisc */
2580 if ((vsi
->type
== I40E_VSI_SRIOV
) && !pf
->vf
[vsi
->vf_id
].trusted
) {
2581 clear_bit(__I40E_VSI_OVERFLOW_PROMISC
, vsi
->state
);
2585 new_overflow
= test_bit(__I40E_VSI_OVERFLOW_PROMISC
, vsi
->state
);
2587 /* If we are entering overflow promiscuous, we need to calculate a new
2588 * threshold for when we are safe to exit
2590 if (!old_overflow
&& new_overflow
)
2591 vsi
->promisc_threshold
= (vsi
->active_filters
* 3) / 4;
2593 /* check for changes in promiscuous modes */
2594 if (changed_flags
& IFF_ALLMULTI
) {
2595 bool cur_multipromisc
;
2597 cur_multipromisc
= !!(vsi
->current_netdev_flags
& IFF_ALLMULTI
);
2598 aq_ret
= i40e_aq_set_vsi_multicast_promiscuous(&vsi
->back
->hw
,
2603 retval
= i40e_aq_rc_to_posix(aq_ret
,
2604 hw
->aq
.asq_last_status
);
2605 dev_info(&pf
->pdev
->dev
,
2606 "set multi promisc failed on %s, err %s aq_err %s\n",
2608 i40e_stat_str(hw
, aq_ret
),
2609 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
2611 dev_info(&pf
->pdev
->dev
, "%s allmulti mode.\n",
2612 cur_multipromisc
? "entering" : "leaving");
2616 if ((changed_flags
& IFF_PROMISC
) || old_overflow
!= new_overflow
) {
2619 cur_promisc
= (!!(vsi
->current_netdev_flags
& IFF_PROMISC
) ||
2621 aq_ret
= i40e_set_promiscuous(pf
, cur_promisc
);
2623 retval
= i40e_aq_rc_to_posix(aq_ret
,
2624 hw
->aq
.asq_last_status
);
2625 dev_info(&pf
->pdev
->dev
,
2626 "Setting promiscuous %s failed on %s, err %s aq_err %s\n",
2627 cur_promisc
? "on" : "off",
2629 i40e_stat_str(hw
, aq_ret
),
2630 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
2634 /* if something went wrong then set the changed flag so we try again */
2636 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
2638 clear_bit(__I40E_VSI_SYNCING_FILTERS
, vsi
->state
);
2642 /* Restore elements on the temporary add and delete lists */
2643 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2644 err_no_memory_locked
:
2645 i40e_undo_del_filter_entries(vsi
, &tmp_del_list
);
2646 i40e_undo_add_filter_entries(vsi
, &tmp_add_list
);
2647 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2649 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
2650 clear_bit(__I40E_VSI_SYNCING_FILTERS
, vsi
->state
);
2655 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
2656 * @pf: board private structure
2658 static void i40e_sync_filters_subtask(struct i40e_pf
*pf
)
2664 if (!test_and_clear_bit(__I40E_MACVLAN_SYNC_PENDING
, pf
->state
))
2666 if (test_bit(__I40E_VF_DISABLE
, pf
->state
)) {
2667 set_bit(__I40E_MACVLAN_SYNC_PENDING
, pf
->state
);
2671 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
2673 (pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_FILTER_CHANGED
) &&
2674 !test_bit(__I40E_VSI_RELEASING
, pf
->vsi
[v
]->state
)) {
2675 int ret
= i40e_sync_vsi_filters(pf
->vsi
[v
]);
2678 /* come back and try again later */
2679 set_bit(__I40E_MACVLAN_SYNC_PENDING
,
2688 * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP
2691 static int i40e_max_xdp_frame_size(struct i40e_vsi
*vsi
)
2693 if (PAGE_SIZE
>= 8192 || (vsi
->back
->flags
& I40E_FLAG_LEGACY_RX
))
2694 return I40E_RXBUFFER_2048
;
2696 return I40E_RXBUFFER_3072
;
2700 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
2701 * @netdev: network interface device structure
2702 * @new_mtu: new value for maximum frame size
2704 * Returns 0 on success, negative on failure
2706 static int i40e_change_mtu(struct net_device
*netdev
, int new_mtu
)
2708 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2709 struct i40e_vsi
*vsi
= np
->vsi
;
2710 struct i40e_pf
*pf
= vsi
->back
;
2712 if (i40e_enabled_xdp_vsi(vsi
)) {
2713 int frame_size
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
2715 if (frame_size
> i40e_max_xdp_frame_size(vsi
))
2719 netdev_dbg(netdev
, "changing MTU from %d to %d\n",
2720 netdev
->mtu
, new_mtu
);
2721 netdev
->mtu
= new_mtu
;
2722 if (netif_running(netdev
))
2723 i40e_vsi_reinit_locked(vsi
);
2724 set_bit(__I40E_CLIENT_SERVICE_REQUESTED
, pf
->state
);
2725 set_bit(__I40E_CLIENT_L2_CHANGE
, pf
->state
);
2730 * i40e_ioctl - Access the hwtstamp interface
2731 * @netdev: network interface device structure
2732 * @ifr: interface request data
2733 * @cmd: ioctl command
2735 int i40e_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
2737 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2738 struct i40e_pf
*pf
= np
->vsi
->back
;
2742 return i40e_ptp_get_ts_config(pf
, ifr
);
2744 return i40e_ptp_set_ts_config(pf
, ifr
);
2751 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
2752 * @vsi: the vsi being adjusted
2754 void i40e_vlan_stripping_enable(struct i40e_vsi
*vsi
)
2756 struct i40e_vsi_context ctxt
;
2759 /* Don't modify stripping options if a port VLAN is active */
2763 if ((vsi
->info
.valid_sections
&
2764 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
2765 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_MODE_MASK
) == 0))
2766 return; /* already enabled */
2768 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2769 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
2770 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH
;
2772 ctxt
.seid
= vsi
->seid
;
2773 ctxt
.info
= vsi
->info
;
2774 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2776 dev_info(&vsi
->back
->pdev
->dev
,
2777 "update vlan stripping failed, err %s aq_err %s\n",
2778 i40e_stat_str(&vsi
->back
->hw
, ret
),
2779 i40e_aq_str(&vsi
->back
->hw
,
2780 vsi
->back
->hw
.aq
.asq_last_status
));
2785 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2786 * @vsi: the vsi being adjusted
2788 void i40e_vlan_stripping_disable(struct i40e_vsi
*vsi
)
2790 struct i40e_vsi_context ctxt
;
2793 /* Don't modify stripping options if a port VLAN is active */
2797 if ((vsi
->info
.valid_sections
&
2798 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
2799 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_EMOD_MASK
) ==
2800 I40E_AQ_VSI_PVLAN_EMOD_MASK
))
2801 return; /* already disabled */
2803 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2804 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
2805 I40E_AQ_VSI_PVLAN_EMOD_NOTHING
;
2807 ctxt
.seid
= vsi
->seid
;
2808 ctxt
.info
= vsi
->info
;
2809 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2811 dev_info(&vsi
->back
->pdev
->dev
,
2812 "update vlan stripping failed, err %s aq_err %s\n",
2813 i40e_stat_str(&vsi
->back
->hw
, ret
),
2814 i40e_aq_str(&vsi
->back
->hw
,
2815 vsi
->back
->hw
.aq
.asq_last_status
));
2820 * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address
2821 * @vsi: the vsi being configured
2822 * @vid: vlan id to be added (0 = untagged only , -1 = any)
2824 * This is a helper function for adding a new MAC/VLAN filter with the
2825 * specified VLAN for each existing MAC address already in the hash table.
2826 * This function does *not* perform any accounting to update filters based on
2829 * NOTE: this function expects to be called while under the
2830 * mac_filter_hash_lock
2832 int i40e_add_vlan_all_mac(struct i40e_vsi
*vsi
, s16 vid
)
2834 struct i40e_mac_filter
*f
, *add_f
;
2835 struct hlist_node
*h
;
2838 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
2839 if (f
->state
== I40E_FILTER_REMOVE
)
2841 add_f
= i40e_add_filter(vsi
, f
->macaddr
, vid
);
2843 dev_info(&vsi
->back
->pdev
->dev
,
2844 "Could not add vlan filter %d for %pM\n",
2854 * i40e_vsi_add_vlan - Add VSI membership for given VLAN
2855 * @vsi: the VSI being configured
2856 * @vid: VLAN id to be added
2858 int i40e_vsi_add_vlan(struct i40e_vsi
*vsi
, u16 vid
)
2865 /* The network stack will attempt to add VID=0, with the intention to
2866 * receive priority tagged packets with a VLAN of 0. Our HW receives
2867 * these packets by default when configured to receive untagged
2868 * packets, so we don't need to add a filter for this case.
2869 * Additionally, HW interprets adding a VID=0 filter as meaning to
2870 * receive *only* tagged traffic and stops receiving untagged traffic.
2871 * Thus, we do not want to actually add a filter for VID=0
2876 /* Locked once because all functions invoked below iterates list*/
2877 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2878 err
= i40e_add_vlan_all_mac(vsi
, vid
);
2879 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2883 /* schedule our worker thread which will take care of
2884 * applying the new filter changes
2886 i40e_service_event_schedule(vsi
->back
);
2891 * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN
2892 * @vsi: the vsi being configured
2893 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
2895 * This function should be used to remove all VLAN filters which match the
2896 * given VID. It does not schedule the service event and does not take the
2897 * mac_filter_hash_lock so it may be combined with other operations under
2898 * a single invocation of the mac_filter_hash_lock.
2900 * NOTE: this function expects to be called while under the
2901 * mac_filter_hash_lock
2903 void i40e_rm_vlan_all_mac(struct i40e_vsi
*vsi
, s16 vid
)
2905 struct i40e_mac_filter
*f
;
2906 struct hlist_node
*h
;
2909 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
2911 __i40e_del_filter(vsi
, f
);
2916 * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN
2917 * @vsi: the VSI being configured
2918 * @vid: VLAN id to be removed
2920 void i40e_vsi_kill_vlan(struct i40e_vsi
*vsi
, u16 vid
)
2922 if (!vid
|| vsi
->info
.pvid
)
2925 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2926 i40e_rm_vlan_all_mac(vsi
, vid
);
2927 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2929 /* schedule our worker thread which will take care of
2930 * applying the new filter changes
2932 i40e_service_event_schedule(vsi
->back
);
2936 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2937 * @netdev: network interface to be adjusted
2938 * @proto: unused protocol value
2939 * @vid: vlan id to be added
2941 * net_device_ops implementation for adding vlan ids
2943 static int i40e_vlan_rx_add_vid(struct net_device
*netdev
,
2944 __always_unused __be16 proto
, u16 vid
)
2946 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2947 struct i40e_vsi
*vsi
= np
->vsi
;
2950 if (vid
>= VLAN_N_VID
)
2953 ret
= i40e_vsi_add_vlan(vsi
, vid
);
2955 set_bit(vid
, vsi
->active_vlans
);
2961 * i40e_vlan_rx_add_vid_up - Add a vlan id filter to HW offload in UP path
2962 * @netdev: network interface to be adjusted
2963 * @proto: unused protocol value
2964 * @vid: vlan id to be added
2966 static void i40e_vlan_rx_add_vid_up(struct net_device
*netdev
,
2967 __always_unused __be16 proto
, u16 vid
)
2969 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2970 struct i40e_vsi
*vsi
= np
->vsi
;
2972 if (vid
>= VLAN_N_VID
)
2974 set_bit(vid
, vsi
->active_vlans
);
2978 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2979 * @netdev: network interface to be adjusted
2980 * @proto: unused protocol value
2981 * @vid: vlan id to be removed
2983 * net_device_ops implementation for removing vlan ids
2985 static int i40e_vlan_rx_kill_vid(struct net_device
*netdev
,
2986 __always_unused __be16 proto
, u16 vid
)
2988 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2989 struct i40e_vsi
*vsi
= np
->vsi
;
2991 /* return code is ignored as there is nothing a user
2992 * can do about failure to remove and a log message was
2993 * already printed from the other function
2995 i40e_vsi_kill_vlan(vsi
, vid
);
2997 clear_bit(vid
, vsi
->active_vlans
);
3003 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
3004 * @vsi: the vsi being brought back up
3006 static void i40e_restore_vlan(struct i40e_vsi
*vsi
)
3013 if (vsi
->netdev
->features
& NETIF_F_HW_VLAN_CTAG_RX
)
3014 i40e_vlan_stripping_enable(vsi
);
3016 i40e_vlan_stripping_disable(vsi
);
3018 for_each_set_bit(vid
, vsi
->active_vlans
, VLAN_N_VID
)
3019 i40e_vlan_rx_add_vid_up(vsi
->netdev
, htons(ETH_P_8021Q
),
3024 * i40e_vsi_add_pvid - Add pvid for the VSI
3025 * @vsi: the vsi being adjusted
3026 * @vid: the vlan id to set as a PVID
3028 int i40e_vsi_add_pvid(struct i40e_vsi
*vsi
, u16 vid
)
3030 struct i40e_vsi_context ctxt
;
3033 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
3034 vsi
->info
.pvid
= cpu_to_le16(vid
);
3035 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_TAGGED
|
3036 I40E_AQ_VSI_PVLAN_INSERT_PVID
|
3037 I40E_AQ_VSI_PVLAN_EMOD_STR
;
3039 ctxt
.seid
= vsi
->seid
;
3040 ctxt
.info
= vsi
->info
;
3041 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
3043 dev_info(&vsi
->back
->pdev
->dev
,
3044 "add pvid failed, err %s aq_err %s\n",
3045 i40e_stat_str(&vsi
->back
->hw
, ret
),
3046 i40e_aq_str(&vsi
->back
->hw
,
3047 vsi
->back
->hw
.aq
.asq_last_status
));
3055 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
3056 * @vsi: the vsi being adjusted
3058 * Just use the vlan_rx_register() service to put it back to normal
3060 void i40e_vsi_remove_pvid(struct i40e_vsi
*vsi
)
3064 i40e_vlan_stripping_disable(vsi
);
3068 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
3069 * @vsi: ptr to the VSI
3071 * If this function returns with an error, then it's possible one or
3072 * more of the rings is populated (while the rest are not). It is the
3073 * callers duty to clean those orphaned rings.
3075 * Return 0 on success, negative on failure
3077 static int i40e_vsi_setup_tx_resources(struct i40e_vsi
*vsi
)
3081 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
3082 err
= i40e_setup_tx_descriptors(vsi
->tx_rings
[i
]);
3084 if (!i40e_enabled_xdp_vsi(vsi
))
3087 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
3088 err
= i40e_setup_tx_descriptors(vsi
->xdp_rings
[i
]);
3094 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
3095 * @vsi: ptr to the VSI
3097 * Free VSI's transmit software resources
3099 static void i40e_vsi_free_tx_resources(struct i40e_vsi
*vsi
)
3103 if (vsi
->tx_rings
) {
3104 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
3105 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
)
3106 i40e_free_tx_resources(vsi
->tx_rings
[i
]);
3109 if (vsi
->xdp_rings
) {
3110 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
3111 if (vsi
->xdp_rings
[i
] && vsi
->xdp_rings
[i
]->desc
)
3112 i40e_free_tx_resources(vsi
->xdp_rings
[i
]);
3117 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
3118 * @vsi: ptr to the VSI
3120 * If this function returns with an error, then it's possible one or
3121 * more of the rings is populated (while the rest are not). It is the
3122 * callers duty to clean those orphaned rings.
3124 * Return 0 on success, negative on failure
3126 static int i40e_vsi_setup_rx_resources(struct i40e_vsi
*vsi
)
3130 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
3131 err
= i40e_setup_rx_descriptors(vsi
->rx_rings
[i
]);
3136 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
3137 * @vsi: ptr to the VSI
3139 * Free all receive software resources
3141 static void i40e_vsi_free_rx_resources(struct i40e_vsi
*vsi
)
3148 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
3149 if (vsi
->rx_rings
[i
] && vsi
->rx_rings
[i
]->desc
)
3150 i40e_free_rx_resources(vsi
->rx_rings
[i
]);
3154 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
3155 * @ring: The Tx ring to configure
3157 * This enables/disables XPS for a given Tx descriptor ring
3158 * based on the TCs enabled for the VSI that ring belongs to.
3160 static void i40e_config_xps_tx_ring(struct i40e_ring
*ring
)
3164 if (!ring
->q_vector
|| !ring
->netdev
|| ring
->ch
)
3167 /* We only initialize XPS once, so as not to overwrite user settings */
3168 if (test_and_set_bit(__I40E_TX_XPS_INIT_DONE
, ring
->state
))
3171 cpu
= cpumask_local_spread(ring
->q_vector
->v_idx
, -1);
3172 netif_set_xps_queue(ring
->netdev
, get_cpu_mask(cpu
),
3177 * i40e_xsk_pool - Retrieve the AF_XDP buffer pool if XDP and ZC is enabled
3178 * @ring: The Tx or Rx ring
3180 * Returns the AF_XDP buffer pool or NULL.
3182 static struct xsk_buff_pool
*i40e_xsk_pool(struct i40e_ring
*ring
)
3184 bool xdp_on
= i40e_enabled_xdp_vsi(ring
->vsi
);
3185 int qid
= ring
->queue_index
;
3187 if (ring_is_xdp(ring
))
3188 qid
-= ring
->vsi
->alloc_queue_pairs
;
3190 if (!xdp_on
|| !test_bit(qid
, ring
->vsi
->af_xdp_zc_qps
))
3193 return xsk_get_pool_from_qid(ring
->vsi
->netdev
, qid
);
3197 * i40e_configure_tx_ring - Configure a transmit ring context and rest
3198 * @ring: The Tx ring to configure
3200 * Configure the Tx descriptor ring in the HMC context.
3202 static int i40e_configure_tx_ring(struct i40e_ring
*ring
)
3204 struct i40e_vsi
*vsi
= ring
->vsi
;
3205 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
3206 struct i40e_hw
*hw
= &vsi
->back
->hw
;
3207 struct i40e_hmc_obj_txq tx_ctx
;
3208 i40e_status err
= 0;
3211 if (ring_is_xdp(ring
))
3212 ring
->xsk_pool
= i40e_xsk_pool(ring
);
3214 /* some ATR related tx ring init */
3215 if (vsi
->back
->flags
& I40E_FLAG_FD_ATR_ENABLED
) {
3216 ring
->atr_sample_rate
= vsi
->back
->atr_sample_rate
;
3217 ring
->atr_count
= 0;
3219 ring
->atr_sample_rate
= 0;
3223 i40e_config_xps_tx_ring(ring
);
3225 /* clear the context structure first */
3226 memset(&tx_ctx
, 0, sizeof(tx_ctx
));
3228 tx_ctx
.new_context
= 1;
3229 tx_ctx
.base
= (ring
->dma
/ 128);
3230 tx_ctx
.qlen
= ring
->count
;
3231 tx_ctx
.fd_ena
= !!(vsi
->back
->flags
& (I40E_FLAG_FD_SB_ENABLED
|
3232 I40E_FLAG_FD_ATR_ENABLED
));
3233 tx_ctx
.timesync_ena
= !!(vsi
->back
->flags
& I40E_FLAG_PTP
);
3234 /* FDIR VSI tx ring can still use RS bit and writebacks */
3235 if (vsi
->type
!= I40E_VSI_FDIR
)
3236 tx_ctx
.head_wb_ena
= 1;
3237 tx_ctx
.head_wb_addr
= ring
->dma
+
3238 (ring
->count
* sizeof(struct i40e_tx_desc
));
3240 /* As part of VSI creation/update, FW allocates certain
3241 * Tx arbitration queue sets for each TC enabled for
3242 * the VSI. The FW returns the handles to these queue
3243 * sets as part of the response buffer to Add VSI,
3244 * Update VSI, etc. AQ commands. It is expected that
3245 * these queue set handles be associated with the Tx
3246 * queues by the driver as part of the TX queue context
3247 * initialization. This has to be done regardless of
3248 * DCB as by default everything is mapped to TC0.
3253 le16_to_cpu(ring
->ch
->info
.qs_handle
[ring
->dcb_tc
]);
3256 tx_ctx
.rdylist
= le16_to_cpu(vsi
->info
.qs_handle
[ring
->dcb_tc
]);
3258 tx_ctx
.rdylist_act
= 0;
3260 /* clear the context in the HMC */
3261 err
= i40e_clear_lan_tx_queue_context(hw
, pf_q
);
3263 dev_info(&vsi
->back
->pdev
->dev
,
3264 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
3265 ring
->queue_index
, pf_q
, err
);
3269 /* set the context in the HMC */
3270 err
= i40e_set_lan_tx_queue_context(hw
, pf_q
, &tx_ctx
);
3272 dev_info(&vsi
->back
->pdev
->dev
,
3273 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
3274 ring
->queue_index
, pf_q
, err
);
3278 /* Now associate this queue with this PCI function */
3280 if (ring
->ch
->type
== I40E_VSI_VMDQ2
)
3281 qtx_ctl
= I40E_QTX_CTL_VM_QUEUE
;
3285 qtx_ctl
|= (ring
->ch
->vsi_number
<<
3286 I40E_QTX_CTL_VFVM_INDX_SHIFT
) &
3287 I40E_QTX_CTL_VFVM_INDX_MASK
;
3289 if (vsi
->type
== I40E_VSI_VMDQ2
) {
3290 qtx_ctl
= I40E_QTX_CTL_VM_QUEUE
;
3291 qtx_ctl
|= ((vsi
->id
) << I40E_QTX_CTL_VFVM_INDX_SHIFT
) &
3292 I40E_QTX_CTL_VFVM_INDX_MASK
;
3294 qtx_ctl
= I40E_QTX_CTL_PF_QUEUE
;
3298 qtx_ctl
|= ((hw
->pf_id
<< I40E_QTX_CTL_PF_INDX_SHIFT
) &
3299 I40E_QTX_CTL_PF_INDX_MASK
);
3300 wr32(hw
, I40E_QTX_CTL(pf_q
), qtx_ctl
);
3303 /* cache tail off for easier writes later */
3304 ring
->tail
= hw
->hw_addr
+ I40E_QTX_TAIL(pf_q
);
3310 * i40e_rx_offset - Return expected offset into page to access data
3311 * @rx_ring: Ring we are requesting offset of
3313 * Returns the offset value for ring into the data buffer.
3315 static unsigned int i40e_rx_offset(struct i40e_ring
*rx_ring
)
3317 return ring_uses_build_skb(rx_ring
) ? I40E_SKB_PAD
: 0;
3321 * i40e_configure_rx_ring - Configure a receive ring context
3322 * @ring: The Rx ring to configure
3324 * Configure the Rx descriptor ring in the HMC context.
3326 static int i40e_configure_rx_ring(struct i40e_ring
*ring
)
3328 struct i40e_vsi
*vsi
= ring
->vsi
;
3329 u32 chain_len
= vsi
->back
->hw
.func_caps
.rx_buf_chain_len
;
3330 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
3331 struct i40e_hw
*hw
= &vsi
->back
->hw
;
3332 struct i40e_hmc_obj_rxq rx_ctx
;
3333 i40e_status err
= 0;
3337 bitmap_zero(ring
->state
, __I40E_RING_STATE_NBITS
);
3339 /* clear the context structure first */
3340 memset(&rx_ctx
, 0, sizeof(rx_ctx
));
3342 if (ring
->vsi
->type
== I40E_VSI_MAIN
)
3343 xdp_rxq_info_unreg_mem_model(&ring
->xdp_rxq
);
3346 ring
->xsk_pool
= i40e_xsk_pool(ring
);
3347 if (ring
->xsk_pool
) {
3348 ret
= i40e_alloc_rx_bi_zc(ring
);
3352 xsk_pool_get_rx_frame_size(ring
->xsk_pool
);
3353 /* For AF_XDP ZC, we disallow packets to span on
3354 * multiple buffers, thus letting us skip that
3355 * handling in the fast-path.
3358 ret
= xdp_rxq_info_reg_mem_model(&ring
->xdp_rxq
,
3359 MEM_TYPE_XSK_BUFF_POOL
,
3363 dev_info(&vsi
->back
->pdev
->dev
,
3364 "Registered XDP mem model MEM_TYPE_XSK_BUFF_POOL on Rx ring %d\n",
3368 ret
= i40e_alloc_rx_bi(ring
);
3371 ring
->rx_buf_len
= vsi
->rx_buf_len
;
3372 if (ring
->vsi
->type
== I40E_VSI_MAIN
) {
3373 ret
= xdp_rxq_info_reg_mem_model(&ring
->xdp_rxq
,
3374 MEM_TYPE_PAGE_SHARED
,
3381 rx_ctx
.dbuff
= DIV_ROUND_UP(ring
->rx_buf_len
,
3382 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT
));
3384 rx_ctx
.base
= (ring
->dma
/ 128);
3385 rx_ctx
.qlen
= ring
->count
;
3387 /* use 16 byte descriptors */
3390 /* descriptor type is always zero
3393 rx_ctx
.hsplit_0
= 0;
3395 rx_ctx
.rxmax
= min_t(u16
, vsi
->max_frame
, chain_len
* ring
->rx_buf_len
);
3396 if (hw
->revision_id
== 0)
3397 rx_ctx
.lrxqthresh
= 0;
3399 rx_ctx
.lrxqthresh
= 1;
3400 rx_ctx
.crcstrip
= 1;
3402 /* this controls whether VLAN is stripped from inner headers */
3404 /* set the prefena field to 1 because the manual says to */
3407 /* clear the context in the HMC */
3408 err
= i40e_clear_lan_rx_queue_context(hw
, pf_q
);
3410 dev_info(&vsi
->back
->pdev
->dev
,
3411 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
3412 ring
->queue_index
, pf_q
, err
);
3416 /* set the context in the HMC */
3417 err
= i40e_set_lan_rx_queue_context(hw
, pf_q
, &rx_ctx
);
3419 dev_info(&vsi
->back
->pdev
->dev
,
3420 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
3421 ring
->queue_index
, pf_q
, err
);
3425 /* configure Rx buffer alignment */
3426 if (!vsi
->netdev
|| (vsi
->back
->flags
& I40E_FLAG_LEGACY_RX
))
3427 clear_ring_build_skb_enabled(ring
);
3429 set_ring_build_skb_enabled(ring
);
3431 ring
->rx_offset
= i40e_rx_offset(ring
);
3433 /* cache tail for quicker writes, and clear the reg before use */
3434 ring
->tail
= hw
->hw_addr
+ I40E_QRX_TAIL(pf_q
);
3435 writel(0, ring
->tail
);
3437 if (ring
->xsk_pool
) {
3438 xsk_pool_set_rxq_info(ring
->xsk_pool
, &ring
->xdp_rxq
);
3439 ok
= i40e_alloc_rx_buffers_zc(ring
, I40E_DESC_UNUSED(ring
));
3441 ok
= !i40e_alloc_rx_buffers(ring
, I40E_DESC_UNUSED(ring
));
3444 /* Log this in case the user has forgotten to give the kernel
3445 * any buffers, even later in the application.
3447 dev_info(&vsi
->back
->pdev
->dev
,
3448 "Failed to allocate some buffers on %sRx ring %d (pf_q %d)\n",
3449 ring
->xsk_pool
? "AF_XDP ZC enabled " : "",
3450 ring
->queue_index
, pf_q
);
3457 * i40e_vsi_configure_tx - Configure the VSI for Tx
3458 * @vsi: VSI structure describing this set of rings and resources
3460 * Configure the Tx VSI for operation.
3462 static int i40e_vsi_configure_tx(struct i40e_vsi
*vsi
)
3467 for (i
= 0; (i
< vsi
->num_queue_pairs
) && !err
; i
++)
3468 err
= i40e_configure_tx_ring(vsi
->tx_rings
[i
]);
3470 if (err
|| !i40e_enabled_xdp_vsi(vsi
))
3473 for (i
= 0; (i
< vsi
->num_queue_pairs
) && !err
; i
++)
3474 err
= i40e_configure_tx_ring(vsi
->xdp_rings
[i
]);
3480 * i40e_vsi_configure_rx - Configure the VSI for Rx
3481 * @vsi: the VSI being configured
3483 * Configure the Rx VSI for operation.
3485 static int i40e_vsi_configure_rx(struct i40e_vsi
*vsi
)
3490 if (!vsi
->netdev
|| (vsi
->back
->flags
& I40E_FLAG_LEGACY_RX
)) {
3491 vsi
->max_frame
= I40E_MAX_RXBUFFER
;
3492 vsi
->rx_buf_len
= I40E_RXBUFFER_2048
;
3493 #if (PAGE_SIZE < 8192)
3494 } else if (!I40E_2K_TOO_SMALL_WITH_PADDING
&&
3495 (vsi
->netdev
->mtu
<= ETH_DATA_LEN
)) {
3496 vsi
->max_frame
= I40E_RXBUFFER_1536
- NET_IP_ALIGN
;
3497 vsi
->rx_buf_len
= I40E_RXBUFFER_1536
- NET_IP_ALIGN
;
3500 vsi
->max_frame
= I40E_MAX_RXBUFFER
;
3501 vsi
->rx_buf_len
= (PAGE_SIZE
< 8192) ? I40E_RXBUFFER_3072
:
3505 /* set up individual rings */
3506 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
3507 err
= i40e_configure_rx_ring(vsi
->rx_rings
[i
]);
3513 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
3514 * @vsi: ptr to the VSI
3516 static void i40e_vsi_config_dcb_rings(struct i40e_vsi
*vsi
)
3518 struct i40e_ring
*tx_ring
, *rx_ring
;
3519 u16 qoffset
, qcount
;
3522 if (!(vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
3523 /* Reset the TC information */
3524 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
3525 rx_ring
= vsi
->rx_rings
[i
];
3526 tx_ring
= vsi
->tx_rings
[i
];
3527 rx_ring
->dcb_tc
= 0;
3528 tx_ring
->dcb_tc
= 0;
3533 for (n
= 0; n
< I40E_MAX_TRAFFIC_CLASS
; n
++) {
3534 if (!(vsi
->tc_config
.enabled_tc
& BIT_ULL(n
)))
3537 qoffset
= vsi
->tc_config
.tc_info
[n
].qoffset
;
3538 qcount
= vsi
->tc_config
.tc_info
[n
].qcount
;
3539 for (i
= qoffset
; i
< (qoffset
+ qcount
); i
++) {
3540 rx_ring
= vsi
->rx_rings
[i
];
3541 tx_ring
= vsi
->tx_rings
[i
];
3542 rx_ring
->dcb_tc
= n
;
3543 tx_ring
->dcb_tc
= n
;
3549 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
3550 * @vsi: ptr to the VSI
3552 static void i40e_set_vsi_rx_mode(struct i40e_vsi
*vsi
)
3555 i40e_set_rx_mode(vsi
->netdev
);
3559 * i40e_reset_fdir_filter_cnt - Reset flow director filter counters
3560 * @pf: Pointer to the targeted PF
3562 * Set all flow director counters to 0.
3564 static void i40e_reset_fdir_filter_cnt(struct i40e_pf
*pf
)
3566 pf
->fd_tcp4_filter_cnt
= 0;
3567 pf
->fd_udp4_filter_cnt
= 0;
3568 pf
->fd_sctp4_filter_cnt
= 0;
3569 pf
->fd_ip4_filter_cnt
= 0;
3570 pf
->fd_tcp6_filter_cnt
= 0;
3571 pf
->fd_udp6_filter_cnt
= 0;
3572 pf
->fd_sctp6_filter_cnt
= 0;
3573 pf
->fd_ip6_filter_cnt
= 0;
3577 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
3578 * @vsi: Pointer to the targeted VSI
3580 * This function replays the hlist on the hw where all the SB Flow Director
3581 * filters were saved.
3583 static void i40e_fdir_filter_restore(struct i40e_vsi
*vsi
)
3585 struct i40e_fdir_filter
*filter
;
3586 struct i40e_pf
*pf
= vsi
->back
;
3587 struct hlist_node
*node
;
3589 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
3592 /* Reset FDir counters as we're replaying all existing filters */
3593 i40e_reset_fdir_filter_cnt(pf
);
3595 hlist_for_each_entry_safe(filter
, node
,
3596 &pf
->fdir_filter_list
, fdir_node
) {
3597 i40e_add_del_fdir(vsi
, filter
, true);
3602 * i40e_vsi_configure - Set up the VSI for action
3603 * @vsi: the VSI being configured
3605 static int i40e_vsi_configure(struct i40e_vsi
*vsi
)
3609 i40e_set_vsi_rx_mode(vsi
);
3610 i40e_restore_vlan(vsi
);
3611 i40e_vsi_config_dcb_rings(vsi
);
3612 err
= i40e_vsi_configure_tx(vsi
);
3614 err
= i40e_vsi_configure_rx(vsi
);
3620 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
3621 * @vsi: the VSI being configured
3623 static void i40e_vsi_configure_msix(struct i40e_vsi
*vsi
)
3625 bool has_xdp
= i40e_enabled_xdp_vsi(vsi
);
3626 struct i40e_pf
*pf
= vsi
->back
;
3627 struct i40e_hw
*hw
= &pf
->hw
;
3632 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
3633 * and PFINT_LNKLSTn registers, e.g.:
3634 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
3636 qp
= vsi
->base_queue
;
3637 vector
= vsi
->base_vector
;
3638 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vector
++) {
3639 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[i
];
3641 q_vector
->rx
.next_update
= jiffies
+ 1;
3642 q_vector
->rx
.target_itr
=
3643 ITR_TO_REG(vsi
->rx_rings
[i
]->itr_setting
);
3644 wr32(hw
, I40E_PFINT_ITRN(I40E_RX_ITR
, vector
- 1),
3645 q_vector
->rx
.target_itr
>> 1);
3646 q_vector
->rx
.current_itr
= q_vector
->rx
.target_itr
;
3648 q_vector
->tx
.next_update
= jiffies
+ 1;
3649 q_vector
->tx
.target_itr
=
3650 ITR_TO_REG(vsi
->tx_rings
[i
]->itr_setting
);
3651 wr32(hw
, I40E_PFINT_ITRN(I40E_TX_ITR
, vector
- 1),
3652 q_vector
->tx
.target_itr
>> 1);
3653 q_vector
->tx
.current_itr
= q_vector
->tx
.target_itr
;
3655 wr32(hw
, I40E_PFINT_RATEN(vector
- 1),
3656 i40e_intrl_usec_to_reg(vsi
->int_rate_limit
));
3658 /* Linked list for the queuepairs assigned to this vector */
3659 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), qp
);
3660 for (q
= 0; q
< q_vector
->num_ringpairs
; q
++) {
3661 u32 nextqp
= has_xdp
? qp
+ vsi
->alloc_queue_pairs
: qp
;
3664 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3665 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
3666 (vector
<< I40E_QINT_RQCTL_MSIX_INDX_SHIFT
) |
3667 (nextqp
<< I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT
) |
3668 (I40E_QUEUE_TYPE_TX
<<
3669 I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT
);
3671 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
3674 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3675 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
3676 (vector
<< I40E_QINT_TQCTL_MSIX_INDX_SHIFT
) |
3677 (qp
<< I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
) |
3678 (I40E_QUEUE_TYPE_TX
<<
3679 I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
3681 wr32(hw
, I40E_QINT_TQCTL(nextqp
), val
);
3684 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3685 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
3686 (vector
<< I40E_QINT_TQCTL_MSIX_INDX_SHIFT
) |
3687 ((qp
+ 1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
) |
3688 (I40E_QUEUE_TYPE_RX
<<
3689 I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
3691 /* Terminate the linked list */
3692 if (q
== (q_vector
->num_ringpairs
- 1))
3693 val
|= (I40E_QUEUE_END_OF_LIST
<<
3694 I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
3696 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
3705 * i40e_enable_misc_int_causes - enable the non-queue interrupts
3706 * @pf: pointer to private device data structure
3708 static void i40e_enable_misc_int_causes(struct i40e_pf
*pf
)
3710 struct i40e_hw
*hw
= &pf
->hw
;
3713 /* clear things first */
3714 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0); /* disable all */
3715 rd32(hw
, I40E_PFINT_ICR0
); /* read to clear */
3717 val
= I40E_PFINT_ICR0_ENA_ECC_ERR_MASK
|
3718 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
|
3719 I40E_PFINT_ICR0_ENA_GRST_MASK
|
3720 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK
|
3721 I40E_PFINT_ICR0_ENA_GPIO_MASK
|
3722 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK
|
3723 I40E_PFINT_ICR0_ENA_VFLR_MASK
|
3724 I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
3726 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
)
3727 val
|= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
;
3729 if (pf
->flags
& I40E_FLAG_PTP
)
3730 val
|= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
3732 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
3734 /* SW_ITR_IDX = 0, but don't change INTENA */
3735 wr32(hw
, I40E_PFINT_DYN_CTL0
, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK
|
3736 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK
);
3738 /* OTHER_ITR_IDX = 0 */
3739 wr32(hw
, I40E_PFINT_STAT_CTL0
, 0);
3743 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
3744 * @vsi: the VSI being configured
3746 static void i40e_configure_msi_and_legacy(struct i40e_vsi
*vsi
)
3748 u32 nextqp
= i40e_enabled_xdp_vsi(vsi
) ? vsi
->alloc_queue_pairs
: 0;
3749 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[0];
3750 struct i40e_pf
*pf
= vsi
->back
;
3751 struct i40e_hw
*hw
= &pf
->hw
;
3754 /* set the ITR configuration */
3755 q_vector
->rx
.next_update
= jiffies
+ 1;
3756 q_vector
->rx
.target_itr
= ITR_TO_REG(vsi
->rx_rings
[0]->itr_setting
);
3757 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), q_vector
->rx
.target_itr
>> 1);
3758 q_vector
->rx
.current_itr
= q_vector
->rx
.target_itr
;
3759 q_vector
->tx
.next_update
= jiffies
+ 1;
3760 q_vector
->tx
.target_itr
= ITR_TO_REG(vsi
->tx_rings
[0]->itr_setting
);
3761 wr32(hw
, I40E_PFINT_ITR0(I40E_TX_ITR
), q_vector
->tx
.target_itr
>> 1);
3762 q_vector
->tx
.current_itr
= q_vector
->tx
.target_itr
;
3764 i40e_enable_misc_int_causes(pf
);
3766 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
3767 wr32(hw
, I40E_PFINT_LNKLST0
, 0);
3769 /* Associate the queue pair to the vector and enable the queue int */
3770 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3771 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
3772 (nextqp
<< I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT
)|
3773 (I40E_QUEUE_TYPE_TX
<< I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
3775 wr32(hw
, I40E_QINT_RQCTL(0), val
);
3777 if (i40e_enabled_xdp_vsi(vsi
)) {
3778 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3779 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
)|
3781 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
3783 wr32(hw
, I40E_QINT_TQCTL(nextqp
), val
);
3786 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3787 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
3788 (I40E_QUEUE_END_OF_LIST
<< I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
3790 wr32(hw
, I40E_QINT_TQCTL(0), val
);
3795 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
3796 * @pf: board private structure
3798 void i40e_irq_dynamic_disable_icr0(struct i40e_pf
*pf
)
3800 struct i40e_hw
*hw
= &pf
->hw
;
3802 wr32(hw
, I40E_PFINT_DYN_CTL0
,
3803 I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
);
3808 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
3809 * @pf: board private structure
3811 void i40e_irq_dynamic_enable_icr0(struct i40e_pf
*pf
)
3813 struct i40e_hw
*hw
= &pf
->hw
;
3816 val
= I40E_PFINT_DYN_CTL0_INTENA_MASK
|
3817 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK
|
3818 (I40E_ITR_NONE
<< I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT
);
3820 wr32(hw
, I40E_PFINT_DYN_CTL0
, val
);
3825 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
3826 * @irq: interrupt number
3827 * @data: pointer to a q_vector
3829 static irqreturn_t
i40e_msix_clean_rings(int irq
, void *data
)
3831 struct i40e_q_vector
*q_vector
= data
;
3833 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
3836 napi_schedule_irqoff(&q_vector
->napi
);
3842 * i40e_irq_affinity_notify - Callback for affinity changes
3843 * @notify: context as to what irq was changed
3844 * @mask: the new affinity mask
3846 * This is a callback function used by the irq_set_affinity_notifier function
3847 * so that we may register to receive changes to the irq affinity masks.
3849 static void i40e_irq_affinity_notify(struct irq_affinity_notify
*notify
,
3850 const cpumask_t
*mask
)
3852 struct i40e_q_vector
*q_vector
=
3853 container_of(notify
, struct i40e_q_vector
, affinity_notify
);
3855 cpumask_copy(&q_vector
->affinity_mask
, mask
);
3859 * i40e_irq_affinity_release - Callback for affinity notifier release
3860 * @ref: internal core kernel usage
3862 * This is a callback function used by the irq_set_affinity_notifier function
3863 * to inform the current notification subscriber that they will no longer
3864 * receive notifications.
3866 static void i40e_irq_affinity_release(struct kref
*ref
) {}
3869 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3870 * @vsi: the VSI being configured
3871 * @basename: name for the vector
3873 * Allocates MSI-X vectors and requests interrupts from the kernel.
3875 static int i40e_vsi_request_irq_msix(struct i40e_vsi
*vsi
, char *basename
)
3877 int q_vectors
= vsi
->num_q_vectors
;
3878 struct i40e_pf
*pf
= vsi
->back
;
3879 int base
= vsi
->base_vector
;
3886 for (vector
= 0; vector
< q_vectors
; vector
++) {
3887 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[vector
];
3889 irq_num
= pf
->msix_entries
[base
+ vector
].vector
;
3891 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
3892 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3893 "%s-%s-%d", basename
, "TxRx", rx_int_idx
++);
3895 } else if (q_vector
->rx
.ring
) {
3896 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3897 "%s-%s-%d", basename
, "rx", rx_int_idx
++);
3898 } else if (q_vector
->tx
.ring
) {
3899 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3900 "%s-%s-%d", basename
, "tx", tx_int_idx
++);
3902 /* skip this unused q_vector */
3905 err
= request_irq(irq_num
,
3911 dev_info(&pf
->pdev
->dev
,
3912 "MSIX request_irq failed, error: %d\n", err
);
3913 goto free_queue_irqs
;
3916 /* register for affinity change notifications */
3917 q_vector
->affinity_notify
.notify
= i40e_irq_affinity_notify
;
3918 q_vector
->affinity_notify
.release
= i40e_irq_affinity_release
;
3919 irq_set_affinity_notifier(irq_num
, &q_vector
->affinity_notify
);
3920 /* Spread affinity hints out across online CPUs.
3922 * get_cpu_mask returns a static constant mask with
3923 * a permanent lifetime so it's ok to pass to
3924 * irq_set_affinity_hint without making a copy.
3926 cpu
= cpumask_local_spread(q_vector
->v_idx
, -1);
3927 irq_set_affinity_hint(irq_num
, get_cpu_mask(cpu
));
3930 vsi
->irqs_ready
= true;
3936 irq_num
= pf
->msix_entries
[base
+ vector
].vector
;
3937 irq_set_affinity_notifier(irq_num
, NULL
);
3938 irq_set_affinity_hint(irq_num
, NULL
);
3939 free_irq(irq_num
, &vsi
->q_vectors
[vector
]);
3945 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3946 * @vsi: the VSI being un-configured
3948 static void i40e_vsi_disable_irq(struct i40e_vsi
*vsi
)
3950 struct i40e_pf
*pf
= vsi
->back
;
3951 struct i40e_hw
*hw
= &pf
->hw
;
3952 int base
= vsi
->base_vector
;
3955 /* disable interrupt causation from each queue */
3956 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
3959 val
= rd32(hw
, I40E_QINT_TQCTL(vsi
->tx_rings
[i
]->reg_idx
));
3960 val
&= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK
;
3961 wr32(hw
, I40E_QINT_TQCTL(vsi
->tx_rings
[i
]->reg_idx
), val
);
3963 val
= rd32(hw
, I40E_QINT_RQCTL(vsi
->rx_rings
[i
]->reg_idx
));
3964 val
&= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK
;
3965 wr32(hw
, I40E_QINT_RQCTL(vsi
->rx_rings
[i
]->reg_idx
), val
);
3967 if (!i40e_enabled_xdp_vsi(vsi
))
3969 wr32(hw
, I40E_QINT_TQCTL(vsi
->xdp_rings
[i
]->reg_idx
), 0);
3972 /* disable each interrupt */
3973 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3974 for (i
= vsi
->base_vector
;
3975 i
< (vsi
->num_q_vectors
+ vsi
->base_vector
); i
++)
3976 wr32(hw
, I40E_PFINT_DYN_CTLN(i
- 1), 0);
3979 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3980 synchronize_irq(pf
->msix_entries
[i
+ base
].vector
);
3982 /* Legacy and MSI mode - this stops all interrupt handling */
3983 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0);
3984 wr32(hw
, I40E_PFINT_DYN_CTL0
, 0);
3986 synchronize_irq(pf
->pdev
->irq
);
3991 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3992 * @vsi: the VSI being configured
3994 static int i40e_vsi_enable_irq(struct i40e_vsi
*vsi
)
3996 struct i40e_pf
*pf
= vsi
->back
;
3999 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
4000 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
4001 i40e_irq_dynamic_enable(vsi
, i
);
4003 i40e_irq_dynamic_enable_icr0(pf
);
4006 i40e_flush(&pf
->hw
);
4011 * i40e_free_misc_vector - Free the vector that handles non-queue events
4012 * @pf: board private structure
4014 static void i40e_free_misc_vector(struct i40e_pf
*pf
)
4017 wr32(&pf
->hw
, I40E_PFINT_ICR0_ENA
, 0);
4018 i40e_flush(&pf
->hw
);
4020 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
&& pf
->msix_entries
) {
4021 synchronize_irq(pf
->msix_entries
[0].vector
);
4022 free_irq(pf
->msix_entries
[0].vector
, pf
);
4023 clear_bit(__I40E_MISC_IRQ_REQUESTED
, pf
->state
);
4028 * i40e_intr - MSI/Legacy and non-queue interrupt handler
4029 * @irq: interrupt number
4030 * @data: pointer to a q_vector
4032 * This is the handler used for all MSI/Legacy interrupts, and deals
4033 * with both queue and non-queue interrupts. This is also used in
4034 * MSIX mode to handle the non-queue interrupts.
4036 static irqreturn_t
i40e_intr(int irq
, void *data
)
4038 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
4039 struct i40e_hw
*hw
= &pf
->hw
;
4040 irqreturn_t ret
= IRQ_NONE
;
4041 u32 icr0
, icr0_remaining
;
4044 icr0
= rd32(hw
, I40E_PFINT_ICR0
);
4045 ena_mask
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
4047 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
4048 if ((icr0
& I40E_PFINT_ICR0_INTEVENT_MASK
) == 0)
4051 /* if interrupt but no bits showing, must be SWINT */
4052 if (((icr0
& ~I40E_PFINT_ICR0_INTEVENT_MASK
) == 0) ||
4053 (icr0
& I40E_PFINT_ICR0_SWINT_MASK
))
4056 if ((pf
->flags
& I40E_FLAG_IWARP_ENABLED
) &&
4057 (icr0
& I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
)) {
4058 ena_mask
&= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
;
4059 dev_dbg(&pf
->pdev
->dev
, "cleared PE_CRITERR\n");
4060 set_bit(__I40E_CORE_RESET_REQUESTED
, pf
->state
);
4063 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
4064 if (icr0
& I40E_PFINT_ICR0_QUEUE_0_MASK
) {
4065 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
4066 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[0];
4068 /* We do not have a way to disarm Queue causes while leaving
4069 * interrupt enabled for all other causes, ideally
4070 * interrupt should be disabled while we are in NAPI but
4071 * this is not a performance path and napi_schedule()
4072 * can deal with rescheduling.
4074 if (!test_bit(__I40E_DOWN
, pf
->state
))
4075 napi_schedule_irqoff(&q_vector
->napi
);
4078 if (icr0
& I40E_PFINT_ICR0_ADMINQ_MASK
) {
4079 ena_mask
&= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
4080 set_bit(__I40E_ADMINQ_EVENT_PENDING
, pf
->state
);
4081 i40e_debug(&pf
->hw
, I40E_DEBUG_NVM
, "AdminQ event\n");
4084 if (icr0
& I40E_PFINT_ICR0_MAL_DETECT_MASK
) {
4085 ena_mask
&= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
4086 set_bit(__I40E_MDD_EVENT_PENDING
, pf
->state
);
4089 if (icr0
& I40E_PFINT_ICR0_VFLR_MASK
) {
4090 /* disable any further VFLR event notifications */
4091 if (test_bit(__I40E_VF_RESETS_DISABLED
, pf
->state
)) {
4092 u32 reg
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
4094 reg
&= ~I40E_PFINT_ICR0_VFLR_MASK
;
4095 wr32(hw
, I40E_PFINT_ICR0_ENA
, reg
);
4097 ena_mask
&= ~I40E_PFINT_ICR0_ENA_VFLR_MASK
;
4098 set_bit(__I40E_VFLR_EVENT_PENDING
, pf
->state
);
4102 if (icr0
& I40E_PFINT_ICR0_GRST_MASK
) {
4103 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
))
4104 set_bit(__I40E_RESET_INTR_RECEIVED
, pf
->state
);
4105 ena_mask
&= ~I40E_PFINT_ICR0_ENA_GRST_MASK
;
4106 val
= rd32(hw
, I40E_GLGEN_RSTAT
);
4107 val
= (val
& I40E_GLGEN_RSTAT_RESET_TYPE_MASK
)
4108 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT
;
4109 if (val
== I40E_RESET_CORER
) {
4111 } else if (val
== I40E_RESET_GLOBR
) {
4113 } else if (val
== I40E_RESET_EMPR
) {
4115 set_bit(__I40E_EMP_RESET_INTR_RECEIVED
, pf
->state
);
4119 if (icr0
& I40E_PFINT_ICR0_HMC_ERR_MASK
) {
4120 icr0
&= ~I40E_PFINT_ICR0_HMC_ERR_MASK
;
4121 dev_info(&pf
->pdev
->dev
, "HMC error interrupt\n");
4122 dev_info(&pf
->pdev
->dev
, "HMC error info 0x%x, HMC error data 0x%x\n",
4123 rd32(hw
, I40E_PFHMC_ERRORINFO
),
4124 rd32(hw
, I40E_PFHMC_ERRORDATA
));
4127 if (icr0
& I40E_PFINT_ICR0_TIMESYNC_MASK
) {
4128 u32 prttsyn_stat
= rd32(hw
, I40E_PRTTSYN_STAT_0
);
4130 if (prttsyn_stat
& I40E_PRTTSYN_STAT_0_EVENT0_MASK
)
4131 schedule_work(&pf
->ptp_extts0_work
);
4133 if (prttsyn_stat
& I40E_PRTTSYN_STAT_0_TXTIME_MASK
)
4134 i40e_ptp_tx_hwtstamp(pf
);
4136 icr0
&= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
4139 /* If a critical error is pending we have no choice but to reset the
4141 * Report and mask out any remaining unexpected interrupts.
4143 icr0_remaining
= icr0
& ena_mask
;
4144 if (icr0_remaining
) {
4145 dev_info(&pf
->pdev
->dev
, "unhandled interrupt icr0=0x%08x\n",
4147 if ((icr0_remaining
& I40E_PFINT_ICR0_PE_CRITERR_MASK
) ||
4148 (icr0_remaining
& I40E_PFINT_ICR0_PCI_EXCEPTION_MASK
) ||
4149 (icr0_remaining
& I40E_PFINT_ICR0_ECC_ERR_MASK
)) {
4150 dev_info(&pf
->pdev
->dev
, "device will be reset\n");
4151 set_bit(__I40E_PF_RESET_REQUESTED
, pf
->state
);
4152 i40e_service_event_schedule(pf
);
4154 ena_mask
&= ~icr0_remaining
;
4159 /* re-enable interrupt causes */
4160 wr32(hw
, I40E_PFINT_ICR0_ENA
, ena_mask
);
4161 if (!test_bit(__I40E_DOWN
, pf
->state
) ||
4162 test_bit(__I40E_RECOVERY_MODE
, pf
->state
)) {
4163 i40e_service_event_schedule(pf
);
4164 i40e_irq_dynamic_enable_icr0(pf
);
4171 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
4172 * @tx_ring: tx ring to clean
4173 * @budget: how many cleans we're allowed
4175 * Returns true if there's any budget left (e.g. the clean is finished)
4177 static bool i40e_clean_fdir_tx_irq(struct i40e_ring
*tx_ring
, int budget
)
4179 struct i40e_vsi
*vsi
= tx_ring
->vsi
;
4180 u16 i
= tx_ring
->next_to_clean
;
4181 struct i40e_tx_buffer
*tx_buf
;
4182 struct i40e_tx_desc
*tx_desc
;
4184 tx_buf
= &tx_ring
->tx_bi
[i
];
4185 tx_desc
= I40E_TX_DESC(tx_ring
, i
);
4186 i
-= tx_ring
->count
;
4189 struct i40e_tx_desc
*eop_desc
= tx_buf
->next_to_watch
;
4191 /* if next_to_watch is not set then there is no work pending */
4195 /* prevent any other reads prior to eop_desc */
4198 /* if the descriptor isn't done, no work yet to do */
4199 if (!(eop_desc
->cmd_type_offset_bsz
&
4200 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE
)))
4203 /* clear next_to_watch to prevent false hangs */
4204 tx_buf
->next_to_watch
= NULL
;
4206 tx_desc
->buffer_addr
= 0;
4207 tx_desc
->cmd_type_offset_bsz
= 0;
4208 /* move past filter desc */
4213 i
-= tx_ring
->count
;
4214 tx_buf
= tx_ring
->tx_bi
;
4215 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
4217 /* unmap skb header data */
4218 dma_unmap_single(tx_ring
->dev
,
4219 dma_unmap_addr(tx_buf
, dma
),
4220 dma_unmap_len(tx_buf
, len
),
4222 if (tx_buf
->tx_flags
& I40E_TX_FLAGS_FD_SB
)
4223 kfree(tx_buf
->raw_buf
);
4225 tx_buf
->raw_buf
= NULL
;
4226 tx_buf
->tx_flags
= 0;
4227 tx_buf
->next_to_watch
= NULL
;
4228 dma_unmap_len_set(tx_buf
, len
, 0);
4229 tx_desc
->buffer_addr
= 0;
4230 tx_desc
->cmd_type_offset_bsz
= 0;
4232 /* move us past the eop_desc for start of next FD desc */
4237 i
-= tx_ring
->count
;
4238 tx_buf
= tx_ring
->tx_bi
;
4239 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
4242 /* update budget accounting */
4244 } while (likely(budget
));
4246 i
+= tx_ring
->count
;
4247 tx_ring
->next_to_clean
= i
;
4249 if (vsi
->back
->flags
& I40E_FLAG_MSIX_ENABLED
)
4250 i40e_irq_dynamic_enable(vsi
, tx_ring
->q_vector
->v_idx
);
4256 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
4257 * @irq: interrupt number
4258 * @data: pointer to a q_vector
4260 static irqreturn_t
i40e_fdir_clean_ring(int irq
, void *data
)
4262 struct i40e_q_vector
*q_vector
= data
;
4263 struct i40e_vsi
*vsi
;
4265 if (!q_vector
->tx
.ring
)
4268 vsi
= q_vector
->tx
.ring
->vsi
;
4269 i40e_clean_fdir_tx_irq(q_vector
->tx
.ring
, vsi
->work_limit
);
4275 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
4276 * @vsi: the VSI being configured
4277 * @v_idx: vector index
4278 * @qp_idx: queue pair index
4280 static void i40e_map_vector_to_qp(struct i40e_vsi
*vsi
, int v_idx
, int qp_idx
)
4282 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
4283 struct i40e_ring
*tx_ring
= vsi
->tx_rings
[qp_idx
];
4284 struct i40e_ring
*rx_ring
= vsi
->rx_rings
[qp_idx
];
4286 tx_ring
->q_vector
= q_vector
;
4287 tx_ring
->next
= q_vector
->tx
.ring
;
4288 q_vector
->tx
.ring
= tx_ring
;
4289 q_vector
->tx
.count
++;
4291 /* Place XDP Tx ring in the same q_vector ring list as regular Tx */
4292 if (i40e_enabled_xdp_vsi(vsi
)) {
4293 struct i40e_ring
*xdp_ring
= vsi
->xdp_rings
[qp_idx
];
4295 xdp_ring
->q_vector
= q_vector
;
4296 xdp_ring
->next
= q_vector
->tx
.ring
;
4297 q_vector
->tx
.ring
= xdp_ring
;
4298 q_vector
->tx
.count
++;
4301 rx_ring
->q_vector
= q_vector
;
4302 rx_ring
->next
= q_vector
->rx
.ring
;
4303 q_vector
->rx
.ring
= rx_ring
;
4304 q_vector
->rx
.count
++;
4308 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
4309 * @vsi: the VSI being configured
4311 * This function maps descriptor rings to the queue-specific vectors
4312 * we were allotted through the MSI-X enabling code. Ideally, we'd have
4313 * one vector per queue pair, but on a constrained vector budget, we
4314 * group the queue pairs as "efficiently" as possible.
4316 static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi
*vsi
)
4318 int qp_remaining
= vsi
->num_queue_pairs
;
4319 int q_vectors
= vsi
->num_q_vectors
;
4324 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
4325 * group them so there are multiple queues per vector.
4326 * It is also important to go through all the vectors available to be
4327 * sure that if we don't use all the vectors, that the remaining vectors
4328 * are cleared. This is especially important when decreasing the
4329 * number of queues in use.
4331 for (; v_start
< q_vectors
; v_start
++) {
4332 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_start
];
4334 num_ringpairs
= DIV_ROUND_UP(qp_remaining
, q_vectors
- v_start
);
4336 q_vector
->num_ringpairs
= num_ringpairs
;
4337 q_vector
->reg_idx
= q_vector
->v_idx
+ vsi
->base_vector
- 1;
4339 q_vector
->rx
.count
= 0;
4340 q_vector
->tx
.count
= 0;
4341 q_vector
->rx
.ring
= NULL
;
4342 q_vector
->tx
.ring
= NULL
;
4344 while (num_ringpairs
--) {
4345 i40e_map_vector_to_qp(vsi
, v_start
, qp_idx
);
4353 * i40e_vsi_request_irq - Request IRQ from the OS
4354 * @vsi: the VSI being configured
4355 * @basename: name for the vector
4357 static int i40e_vsi_request_irq(struct i40e_vsi
*vsi
, char *basename
)
4359 struct i40e_pf
*pf
= vsi
->back
;
4362 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
4363 err
= i40e_vsi_request_irq_msix(vsi
, basename
);
4364 else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
)
4365 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, 0,
4368 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, IRQF_SHARED
,
4372 dev_info(&pf
->pdev
->dev
, "request_irq failed, Error %d\n", err
);
4377 #ifdef CONFIG_NET_POLL_CONTROLLER
4379 * i40e_netpoll - A Polling 'interrupt' handler
4380 * @netdev: network interface device structure
4382 * This is used by netconsole to send skbs without having to re-enable
4383 * interrupts. It's not called while the normal interrupt routine is executing.
4385 static void i40e_netpoll(struct net_device
*netdev
)
4387 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
4388 struct i40e_vsi
*vsi
= np
->vsi
;
4389 struct i40e_pf
*pf
= vsi
->back
;
4392 /* if interface is down do nothing */
4393 if (test_bit(__I40E_VSI_DOWN
, vsi
->state
))
4396 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
4397 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
4398 i40e_msix_clean_rings(0, vsi
->q_vectors
[i
]);
4400 i40e_intr(pf
->pdev
->irq
, netdev
);
4405 #define I40E_QTX_ENA_WAIT_COUNT 50
4408 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
4409 * @pf: the PF being configured
4410 * @pf_q: the PF queue
4411 * @enable: enable or disable state of the queue
4413 * This routine will wait for the given Tx queue of the PF to reach the
4414 * enabled or disabled state.
4415 * Returns -ETIMEDOUT in case of failing to reach the requested state after
4416 * multiple retries; else will return 0 in case of success.
4418 static int i40e_pf_txq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
4423 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
4424 tx_reg
= rd32(&pf
->hw
, I40E_QTX_ENA(pf_q
));
4425 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
4428 usleep_range(10, 20);
4430 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
4437 * i40e_control_tx_q - Start or stop a particular Tx queue
4438 * @pf: the PF structure
4439 * @pf_q: the PF queue to configure
4440 * @enable: start or stop the queue
4442 * This function enables or disables a single queue. Note that any delay
4443 * required after the operation is expected to be handled by the caller of
4446 static void i40e_control_tx_q(struct i40e_pf
*pf
, int pf_q
, bool enable
)
4448 struct i40e_hw
*hw
= &pf
->hw
;
4452 /* warn the TX unit of coming changes */
4453 i40e_pre_tx_queue_cfg(&pf
->hw
, pf_q
, enable
);
4455 usleep_range(10, 20);
4457 for (i
= 0; i
< I40E_QTX_ENA_WAIT_COUNT
; i
++) {
4458 tx_reg
= rd32(hw
, I40E_QTX_ENA(pf_q
));
4459 if (((tx_reg
>> I40E_QTX_ENA_QENA_REQ_SHIFT
) & 1) ==
4460 ((tx_reg
>> I40E_QTX_ENA_QENA_STAT_SHIFT
) & 1))
4462 usleep_range(1000, 2000);
4465 /* Skip if the queue is already in the requested state */
4466 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
4469 /* turn on/off the queue */
4471 wr32(hw
, I40E_QTX_HEAD(pf_q
), 0);
4472 tx_reg
|= I40E_QTX_ENA_QENA_REQ_MASK
;
4474 tx_reg
&= ~I40E_QTX_ENA_QENA_REQ_MASK
;
4477 wr32(hw
, I40E_QTX_ENA(pf_q
), tx_reg
);
4481 * i40e_control_wait_tx_q - Start/stop Tx queue and wait for completion
4483 * @pf: the PF structure
4484 * @pf_q: the PF queue to configure
4485 * @is_xdp: true if the queue is used for XDP
4486 * @enable: start or stop the queue
4488 int i40e_control_wait_tx_q(int seid
, struct i40e_pf
*pf
, int pf_q
,
4489 bool is_xdp
, bool enable
)
4493 i40e_control_tx_q(pf
, pf_q
, enable
);
4495 /* wait for the change to finish */
4496 ret
= i40e_pf_txq_wait(pf
, pf_q
, enable
);
4498 dev_info(&pf
->pdev
->dev
,
4499 "VSI seid %d %sTx ring %d %sable timeout\n",
4500 seid
, (is_xdp
? "XDP " : ""), pf_q
,
4501 (enable
? "en" : "dis"));
4508 * i40e_vsi_enable_tx - Start a VSI's rings
4509 * @vsi: the VSI being configured
4511 static int i40e_vsi_enable_tx(struct i40e_vsi
*vsi
)
4513 struct i40e_pf
*pf
= vsi
->back
;
4514 int i
, pf_q
, ret
= 0;
4516 pf_q
= vsi
->base_queue
;
4517 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
4518 ret
= i40e_control_wait_tx_q(vsi
->seid
, pf
,
4520 false /*is xdp*/, true);
4524 if (!i40e_enabled_xdp_vsi(vsi
))
4527 ret
= i40e_control_wait_tx_q(vsi
->seid
, pf
,
4528 pf_q
+ vsi
->alloc_queue_pairs
,
4529 true /*is xdp*/, true);
4537 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
4538 * @pf: the PF being configured
4539 * @pf_q: the PF queue
4540 * @enable: enable or disable state of the queue
4542 * This routine will wait for the given Rx queue of the PF to reach the
4543 * enabled or disabled state.
4544 * Returns -ETIMEDOUT in case of failing to reach the requested state after
4545 * multiple retries; else will return 0 in case of success.
4547 static int i40e_pf_rxq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
4552 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
4553 rx_reg
= rd32(&pf
->hw
, I40E_QRX_ENA(pf_q
));
4554 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
4557 usleep_range(10, 20);
4559 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
4566 * i40e_control_rx_q - Start or stop a particular Rx queue
4567 * @pf: the PF structure
4568 * @pf_q: the PF queue to configure
4569 * @enable: start or stop the queue
4571 * This function enables or disables a single queue. Note that
4572 * any delay required after the operation is expected to be
4573 * handled by the caller of this function.
4575 static void i40e_control_rx_q(struct i40e_pf
*pf
, int pf_q
, bool enable
)
4577 struct i40e_hw
*hw
= &pf
->hw
;
4581 for (i
= 0; i
< I40E_QTX_ENA_WAIT_COUNT
; i
++) {
4582 rx_reg
= rd32(hw
, I40E_QRX_ENA(pf_q
));
4583 if (((rx_reg
>> I40E_QRX_ENA_QENA_REQ_SHIFT
) & 1) ==
4584 ((rx_reg
>> I40E_QRX_ENA_QENA_STAT_SHIFT
) & 1))
4586 usleep_range(1000, 2000);
4589 /* Skip if the queue is already in the requested state */
4590 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
4593 /* turn on/off the queue */
4595 rx_reg
|= I40E_QRX_ENA_QENA_REQ_MASK
;
4597 rx_reg
&= ~I40E_QRX_ENA_QENA_REQ_MASK
;
4599 wr32(hw
, I40E_QRX_ENA(pf_q
), rx_reg
);
4603 * i40e_control_wait_rx_q
4604 * @pf: the PF structure
4605 * @pf_q: queue being configured
4606 * @enable: start or stop the rings
4608 * This function enables or disables a single queue along with waiting
4609 * for the change to finish. The caller of this function should handle
4610 * the delays needed in the case of disabling queues.
4612 int i40e_control_wait_rx_q(struct i40e_pf
*pf
, int pf_q
, bool enable
)
4616 i40e_control_rx_q(pf
, pf_q
, enable
);
4618 /* wait for the change to finish */
4619 ret
= i40e_pf_rxq_wait(pf
, pf_q
, enable
);
4627 * i40e_vsi_enable_rx - Start a VSI's rings
4628 * @vsi: the VSI being configured
4630 static int i40e_vsi_enable_rx(struct i40e_vsi
*vsi
)
4632 struct i40e_pf
*pf
= vsi
->back
;
4633 int i
, pf_q
, ret
= 0;
4635 pf_q
= vsi
->base_queue
;
4636 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
4637 ret
= i40e_control_wait_rx_q(pf
, pf_q
, true);
4639 dev_info(&pf
->pdev
->dev
,
4640 "VSI seid %d Rx ring %d enable timeout\n",
4650 * i40e_vsi_start_rings - Start a VSI's rings
4651 * @vsi: the VSI being configured
4653 int i40e_vsi_start_rings(struct i40e_vsi
*vsi
)
4657 /* do rx first for enable and last for disable */
4658 ret
= i40e_vsi_enable_rx(vsi
);
4661 ret
= i40e_vsi_enable_tx(vsi
);
4666 #define I40E_DISABLE_TX_GAP_MSEC 50
4669 * i40e_vsi_stop_rings - Stop a VSI's rings
4670 * @vsi: the VSI being configured
4672 void i40e_vsi_stop_rings(struct i40e_vsi
*vsi
)
4674 struct i40e_pf
*pf
= vsi
->back
;
4675 int pf_q
, err
, q_end
;
4677 /* When port TX is suspended, don't wait */
4678 if (test_bit(__I40E_PORT_SUSPENDED
, vsi
->back
->state
))
4679 return i40e_vsi_stop_rings_no_wait(vsi
);
4681 q_end
= vsi
->base_queue
+ vsi
->num_queue_pairs
;
4682 for (pf_q
= vsi
->base_queue
; pf_q
< q_end
; pf_q
++)
4683 i40e_pre_tx_queue_cfg(&pf
->hw
, (u32
)pf_q
, false);
4685 for (pf_q
= vsi
->base_queue
; pf_q
< q_end
; pf_q
++) {
4686 err
= i40e_control_wait_rx_q(pf
, pf_q
, false);
4688 dev_info(&pf
->pdev
->dev
,
4689 "VSI seid %d Rx ring %d disable timeout\n",
4693 msleep(I40E_DISABLE_TX_GAP_MSEC
);
4694 pf_q
= vsi
->base_queue
;
4695 for (pf_q
= vsi
->base_queue
; pf_q
< q_end
; pf_q
++)
4696 wr32(&pf
->hw
, I40E_QTX_ENA(pf_q
), 0);
4698 i40e_vsi_wait_queues_disabled(vsi
);
4702 * i40e_vsi_stop_rings_no_wait - Stop a VSI's rings and do not delay
4703 * @vsi: the VSI being shutdown
4705 * This function stops all the rings for a VSI but does not delay to verify
4706 * that rings have been disabled. It is expected that the caller is shutting
4707 * down multiple VSIs at once and will delay together for all the VSIs after
4708 * initiating the shutdown. This is particularly useful for shutting down lots
4709 * of VFs together. Otherwise, a large delay can be incurred while configuring
4710 * each VSI in serial.
4712 void i40e_vsi_stop_rings_no_wait(struct i40e_vsi
*vsi
)
4714 struct i40e_pf
*pf
= vsi
->back
;
4717 pf_q
= vsi
->base_queue
;
4718 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
4719 i40e_control_tx_q(pf
, pf_q
, false);
4720 i40e_control_rx_q(pf
, pf_q
, false);
4725 * i40e_vsi_free_irq - Free the irq association with the OS
4726 * @vsi: the VSI being configured
4728 static void i40e_vsi_free_irq(struct i40e_vsi
*vsi
)
4730 struct i40e_pf
*pf
= vsi
->back
;
4731 struct i40e_hw
*hw
= &pf
->hw
;
4732 int base
= vsi
->base_vector
;
4736 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
4737 if (!vsi
->q_vectors
)
4740 if (!vsi
->irqs_ready
)
4743 vsi
->irqs_ready
= false;
4744 for (i
= 0; i
< vsi
->num_q_vectors
; i
++) {
4749 irq_num
= pf
->msix_entries
[vector
].vector
;
4751 /* free only the irqs that were actually requested */
4752 if (!vsi
->q_vectors
[i
] ||
4753 !vsi
->q_vectors
[i
]->num_ringpairs
)
4756 /* clear the affinity notifier in the IRQ descriptor */
4757 irq_set_affinity_notifier(irq_num
, NULL
);
4758 /* remove our suggested affinity mask for this IRQ */
4759 irq_set_affinity_hint(irq_num
, NULL
);
4760 synchronize_irq(irq_num
);
4761 free_irq(irq_num
, vsi
->q_vectors
[i
]);
4763 /* Tear down the interrupt queue link list
4765 * We know that they come in pairs and always
4766 * the Rx first, then the Tx. To clear the
4767 * link list, stick the EOL value into the
4768 * next_q field of the registers.
4770 val
= rd32(hw
, I40E_PFINT_LNKLSTN(vector
- 1));
4771 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
4772 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
4773 val
|= I40E_QUEUE_END_OF_LIST
4774 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
4775 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), val
);
4777 while (qp
!= I40E_QUEUE_END_OF_LIST
) {
4780 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
4782 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
4783 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
4784 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
4785 I40E_QINT_RQCTL_INTEVENT_MASK
);
4787 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
4788 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
4790 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
4792 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
4794 next
= (val
& I40E_QINT_TQCTL_NEXTQ_INDX_MASK
)
4795 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
;
4797 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
4798 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
4799 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
4800 I40E_QINT_TQCTL_INTEVENT_MASK
);
4802 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
4803 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
4805 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
4810 free_irq(pf
->pdev
->irq
, pf
);
4812 val
= rd32(hw
, I40E_PFINT_LNKLST0
);
4813 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
4814 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
4815 val
|= I40E_QUEUE_END_OF_LIST
4816 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT
;
4817 wr32(hw
, I40E_PFINT_LNKLST0
, val
);
4819 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
4820 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
4821 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
4822 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
4823 I40E_QINT_RQCTL_INTEVENT_MASK
);
4825 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
4826 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
4828 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
4830 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
4832 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
4833 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
4834 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
4835 I40E_QINT_TQCTL_INTEVENT_MASK
);
4837 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
4838 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
4840 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
4845 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
4846 * @vsi: the VSI being configured
4847 * @v_idx: Index of vector to be freed
4849 * This function frees the memory allocated to the q_vector. In addition if
4850 * NAPI is enabled it will delete any references to the NAPI struct prior
4851 * to freeing the q_vector.
4853 static void i40e_free_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
4855 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
4856 struct i40e_ring
*ring
;
4861 /* disassociate q_vector from rings */
4862 i40e_for_each_ring(ring
, q_vector
->tx
)
4863 ring
->q_vector
= NULL
;
4865 i40e_for_each_ring(ring
, q_vector
->rx
)
4866 ring
->q_vector
= NULL
;
4868 /* only VSI w/ an associated netdev is set up w/ NAPI */
4870 netif_napi_del(&q_vector
->napi
);
4872 vsi
->q_vectors
[v_idx
] = NULL
;
4874 kfree_rcu(q_vector
, rcu
);
4878 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
4879 * @vsi: the VSI being un-configured
4881 * This frees the memory allocated to the q_vectors and
4882 * deletes references to the NAPI struct.
4884 static void i40e_vsi_free_q_vectors(struct i40e_vsi
*vsi
)
4888 for (v_idx
= 0; v_idx
< vsi
->num_q_vectors
; v_idx
++)
4889 i40e_free_q_vector(vsi
, v_idx
);
4893 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
4894 * @pf: board private structure
4896 static void i40e_reset_interrupt_capability(struct i40e_pf
*pf
)
4898 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
4899 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
4900 pci_disable_msix(pf
->pdev
);
4901 kfree(pf
->msix_entries
);
4902 pf
->msix_entries
= NULL
;
4903 kfree(pf
->irq_pile
);
4904 pf
->irq_pile
= NULL
;
4905 } else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
) {
4906 pci_disable_msi(pf
->pdev
);
4908 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
);
4912 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
4913 * @pf: board private structure
4915 * We go through and clear interrupt specific resources and reset the structure
4916 * to pre-load conditions
4918 static void i40e_clear_interrupt_scheme(struct i40e_pf
*pf
)
4922 if (test_bit(__I40E_MISC_IRQ_REQUESTED
, pf
->state
))
4923 i40e_free_misc_vector(pf
);
4925 i40e_put_lump(pf
->irq_pile
, pf
->iwarp_base_vector
,
4926 I40E_IWARP_IRQ_PILE_ID
);
4928 i40e_put_lump(pf
->irq_pile
, 0, I40E_PILE_VALID_BIT
-1);
4929 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
4931 i40e_vsi_free_q_vectors(pf
->vsi
[i
]);
4932 i40e_reset_interrupt_capability(pf
);
4936 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
4937 * @vsi: the VSI being configured
4939 static void i40e_napi_enable_all(struct i40e_vsi
*vsi
)
4946 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++) {
4947 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[q_idx
];
4949 if (q_vector
->rx
.ring
|| q_vector
->tx
.ring
)
4950 napi_enable(&q_vector
->napi
);
4955 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4956 * @vsi: the VSI being configured
4958 static void i40e_napi_disable_all(struct i40e_vsi
*vsi
)
4965 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++) {
4966 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[q_idx
];
4968 if (q_vector
->rx
.ring
|| q_vector
->tx
.ring
)
4969 napi_disable(&q_vector
->napi
);
4974 * i40e_vsi_close - Shut down a VSI
4975 * @vsi: the vsi to be quelled
4977 static void i40e_vsi_close(struct i40e_vsi
*vsi
)
4979 struct i40e_pf
*pf
= vsi
->back
;
4980 if (!test_and_set_bit(__I40E_VSI_DOWN
, vsi
->state
))
4982 i40e_vsi_free_irq(vsi
);
4983 i40e_vsi_free_tx_resources(vsi
);
4984 i40e_vsi_free_rx_resources(vsi
);
4985 vsi
->current_netdev_flags
= 0;
4986 set_bit(__I40E_CLIENT_SERVICE_REQUESTED
, pf
->state
);
4987 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
))
4988 set_bit(__I40E_CLIENT_RESET
, pf
->state
);
4992 * i40e_quiesce_vsi - Pause a given VSI
4993 * @vsi: the VSI being paused
4995 static void i40e_quiesce_vsi(struct i40e_vsi
*vsi
)
4997 if (test_bit(__I40E_VSI_DOWN
, vsi
->state
))
5000 set_bit(__I40E_VSI_NEEDS_RESTART
, vsi
->state
);
5001 if (vsi
->netdev
&& netif_running(vsi
->netdev
))
5002 vsi
->netdev
->netdev_ops
->ndo_stop(vsi
->netdev
);
5004 i40e_vsi_close(vsi
);
5008 * i40e_unquiesce_vsi - Resume a given VSI
5009 * @vsi: the VSI being resumed
5011 static void i40e_unquiesce_vsi(struct i40e_vsi
*vsi
)
5013 if (!test_and_clear_bit(__I40E_VSI_NEEDS_RESTART
, vsi
->state
))
5016 if (vsi
->netdev
&& netif_running(vsi
->netdev
))
5017 vsi
->netdev
->netdev_ops
->ndo_open(vsi
->netdev
);
5019 i40e_vsi_open(vsi
); /* this clears the DOWN bit */
5023 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
5026 static void i40e_pf_quiesce_all_vsi(struct i40e_pf
*pf
)
5030 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5032 i40e_quiesce_vsi(pf
->vsi
[v
]);
5037 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
5040 static void i40e_pf_unquiesce_all_vsi(struct i40e_pf
*pf
)
5044 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5046 i40e_unquiesce_vsi(pf
->vsi
[v
]);
5051 * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
5052 * @vsi: the VSI being configured
5054 * Wait until all queues on a given VSI have been disabled.
5056 int i40e_vsi_wait_queues_disabled(struct i40e_vsi
*vsi
)
5058 struct i40e_pf
*pf
= vsi
->back
;
5061 pf_q
= vsi
->base_queue
;
5062 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
5063 /* Check and wait for the Tx queue */
5064 ret
= i40e_pf_txq_wait(pf
, pf_q
, false);
5066 dev_info(&pf
->pdev
->dev
,
5067 "VSI seid %d Tx ring %d disable timeout\n",
5072 if (!i40e_enabled_xdp_vsi(vsi
))
5075 /* Check and wait for the XDP Tx queue */
5076 ret
= i40e_pf_txq_wait(pf
, pf_q
+ vsi
->alloc_queue_pairs
,
5079 dev_info(&pf
->pdev
->dev
,
5080 "VSI seid %d XDP Tx ring %d disable timeout\n",
5085 /* Check and wait for the Rx queue */
5086 ret
= i40e_pf_rxq_wait(pf
, pf_q
, false);
5088 dev_info(&pf
->pdev
->dev
,
5089 "VSI seid %d Rx ring %d disable timeout\n",
5098 #ifdef CONFIG_I40E_DCB
5100 * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
5103 * This function waits for the queues to be in disabled state for all the
5104 * VSIs that are managed by this PF.
5106 static int i40e_pf_wait_queues_disabled(struct i40e_pf
*pf
)
5110 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
; v
++) {
5112 ret
= i40e_vsi_wait_queues_disabled(pf
->vsi
[v
]);
5124 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
5125 * @pf: pointer to PF
5127 * Get TC map for ISCSI PF type that will include iSCSI TC
5130 static u8
i40e_get_iscsi_tc_map(struct i40e_pf
*pf
)
5132 struct i40e_dcb_app_priority_table app
;
5133 struct i40e_hw
*hw
= &pf
->hw
;
5134 u8 enabled_tc
= 1; /* TC0 is always enabled */
5136 /* Get the iSCSI APP TLV */
5137 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
5139 for (i
= 0; i
< dcbcfg
->numapps
; i
++) {
5140 app
= dcbcfg
->app
[i
];
5141 if (app
.selector
== I40E_APP_SEL_TCPIP
&&
5142 app
.protocolid
== I40E_APP_PROTOID_ISCSI
) {
5143 tc
= dcbcfg
->etscfg
.prioritytable
[app
.priority
];
5144 enabled_tc
|= BIT(tc
);
5153 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
5154 * @dcbcfg: the corresponding DCBx configuration structure
5156 * Return the number of TCs from given DCBx configuration
5158 static u8
i40e_dcb_get_num_tc(struct i40e_dcbx_config
*dcbcfg
)
5160 int i
, tc_unused
= 0;
5164 /* Scan the ETS Config Priority Table to find
5165 * traffic class enabled for a given priority
5166 * and create a bitmask of enabled TCs
5168 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++)
5169 num_tc
|= BIT(dcbcfg
->etscfg
.prioritytable
[i
]);
5171 /* Now scan the bitmask to check for
5172 * contiguous TCs starting with TC0
5174 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
5175 if (num_tc
& BIT(i
)) {
5179 pr_err("Non-contiguous TC - Disabling DCB\n");
5187 /* There is always at least TC0 */
5195 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
5196 * @dcbcfg: the corresponding DCBx configuration structure
5198 * Query the current DCB configuration and return the number of
5199 * traffic classes enabled from the given DCBX config
5201 static u8
i40e_dcb_get_enabled_tc(struct i40e_dcbx_config
*dcbcfg
)
5203 u8 num_tc
= i40e_dcb_get_num_tc(dcbcfg
);
5207 for (i
= 0; i
< num_tc
; i
++)
5208 enabled_tc
|= BIT(i
);
5214 * i40e_mqprio_get_enabled_tc - Get enabled traffic classes
5215 * @pf: PF being queried
5217 * Query the current MQPRIO configuration and return the number of
5218 * traffic classes enabled.
5220 static u8
i40e_mqprio_get_enabled_tc(struct i40e_pf
*pf
)
5222 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
5223 u8 num_tc
= vsi
->mqprio_qopt
.qopt
.num_tc
;
5224 u8 enabled_tc
= 1, i
;
5226 for (i
= 1; i
< num_tc
; i
++)
5227 enabled_tc
|= BIT(i
);
5232 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
5233 * @pf: PF being queried
5235 * Return number of traffic classes enabled for the given PF
5237 static u8
i40e_pf_get_num_tc(struct i40e_pf
*pf
)
5239 struct i40e_hw
*hw
= &pf
->hw
;
5240 u8 i
, enabled_tc
= 1;
5242 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
5244 if (pf
->flags
& I40E_FLAG_TC_MQPRIO
)
5245 return pf
->vsi
[pf
->lan_vsi
]->mqprio_qopt
.qopt
.num_tc
;
5247 /* If neither MQPRIO nor DCB is enabled, then always use single TC */
5248 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
5251 /* SFP mode will be enabled for all TCs on port */
5252 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
5253 return i40e_dcb_get_num_tc(dcbcfg
);
5255 /* MFP mode return count of enabled TCs for this PF */
5256 if (pf
->hw
.func_caps
.iscsi
)
5257 enabled_tc
= i40e_get_iscsi_tc_map(pf
);
5259 return 1; /* Only TC0 */
5261 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
5262 if (enabled_tc
& BIT(i
))
5269 * i40e_pf_get_tc_map - Get bitmap for enabled traffic classes
5270 * @pf: PF being queried
5272 * Return a bitmap for enabled traffic classes for this PF.
5274 static u8
i40e_pf_get_tc_map(struct i40e_pf
*pf
)
5276 if (pf
->flags
& I40E_FLAG_TC_MQPRIO
)
5277 return i40e_mqprio_get_enabled_tc(pf
);
5279 /* If neither MQPRIO nor DCB is enabled for this PF then just return
5282 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
5283 return I40E_DEFAULT_TRAFFIC_CLASS
;
5285 /* SFP mode we want PF to be enabled for all TCs */
5286 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
5287 return i40e_dcb_get_enabled_tc(&pf
->hw
.local_dcbx_config
);
5289 /* MFP enabled and iSCSI PF type */
5290 if (pf
->hw
.func_caps
.iscsi
)
5291 return i40e_get_iscsi_tc_map(pf
);
5293 return I40E_DEFAULT_TRAFFIC_CLASS
;
5297 * i40e_vsi_get_bw_info - Query VSI BW Information
5298 * @vsi: the VSI being queried
5300 * Returns 0 on success, negative value on failure
5302 static int i40e_vsi_get_bw_info(struct i40e_vsi
*vsi
)
5304 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config
= {0};
5305 struct i40e_aqc_query_vsi_bw_config_resp bw_config
= {0};
5306 struct i40e_pf
*pf
= vsi
->back
;
5307 struct i40e_hw
*hw
= &pf
->hw
;
5312 /* Get the VSI level BW configuration */
5313 ret
= i40e_aq_query_vsi_bw_config(hw
, vsi
->seid
, &bw_config
, NULL
);
5315 dev_info(&pf
->pdev
->dev
,
5316 "couldn't get PF vsi bw config, err %s aq_err %s\n",
5317 i40e_stat_str(&pf
->hw
, ret
),
5318 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
5322 /* Get the VSI level BW configuration per TC */
5323 ret
= i40e_aq_query_vsi_ets_sla_config(hw
, vsi
->seid
, &bw_ets_config
,
5326 dev_info(&pf
->pdev
->dev
,
5327 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
5328 i40e_stat_str(&pf
->hw
, ret
),
5329 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
5333 if (bw_config
.tc_valid_bits
!= bw_ets_config
.tc_valid_bits
) {
5334 dev_info(&pf
->pdev
->dev
,
5335 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
5336 bw_config
.tc_valid_bits
,
5337 bw_ets_config
.tc_valid_bits
);
5338 /* Still continuing */
5341 vsi
->bw_limit
= le16_to_cpu(bw_config
.port_bw_limit
);
5342 vsi
->bw_max_quanta
= bw_config
.max_bw
;
5343 tc_bw_max
= le16_to_cpu(bw_ets_config
.tc_bw_max
[0]) |
5344 (le16_to_cpu(bw_ets_config
.tc_bw_max
[1]) << 16);
5345 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
5346 vsi
->bw_ets_share_credits
[i
] = bw_ets_config
.share_credits
[i
];
5347 vsi
->bw_ets_limit_credits
[i
] =
5348 le16_to_cpu(bw_ets_config
.credits
[i
]);
5349 /* 3 bits out of 4 for each TC */
5350 vsi
->bw_ets_max_quanta
[i
] = (u8
)((tc_bw_max
>> (i
*4)) & 0x7);
5357 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
5358 * @vsi: the VSI being configured
5359 * @enabled_tc: TC bitmap
5360 * @bw_share: BW shared credits per TC
5362 * Returns 0 on success, negative value on failure
5364 static int i40e_vsi_configure_bw_alloc(struct i40e_vsi
*vsi
, u8 enabled_tc
,
5367 struct i40e_aqc_configure_vsi_tc_bw_data bw_data
;
5368 struct i40e_pf
*pf
= vsi
->back
;
5372 /* There is no need to reset BW when mqprio mode is on. */
5373 if (pf
->flags
& I40E_FLAG_TC_MQPRIO
)
5375 if (!vsi
->mqprio_qopt
.qopt
.hw
&& !(pf
->flags
& I40E_FLAG_DCB_ENABLED
)) {
5376 ret
= i40e_set_bw_limit(vsi
, vsi
->seid
, 0);
5378 dev_info(&pf
->pdev
->dev
,
5379 "Failed to reset tx rate for vsi->seid %u\n",
5383 memset(&bw_data
, 0, sizeof(bw_data
));
5384 bw_data
.tc_valid_bits
= enabled_tc
;
5385 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
5386 bw_data
.tc_bw_credits
[i
] = bw_share
[i
];
5388 ret
= i40e_aq_config_vsi_tc_bw(&pf
->hw
, vsi
->seid
, &bw_data
, NULL
);
5390 dev_info(&pf
->pdev
->dev
,
5391 "AQ command Config VSI BW allocation per TC failed = %d\n",
5392 pf
->hw
.aq
.asq_last_status
);
5396 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
5397 vsi
->info
.qs_handle
[i
] = bw_data
.qs_handles
[i
];
5403 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
5404 * @vsi: the VSI being configured
5405 * @enabled_tc: TC map to be enabled
5408 static void i40e_vsi_config_netdev_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
5410 struct net_device
*netdev
= vsi
->netdev
;
5411 struct i40e_pf
*pf
= vsi
->back
;
5412 struct i40e_hw
*hw
= &pf
->hw
;
5415 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
5421 netdev_reset_tc(netdev
);
5425 /* Set up actual enabled TCs on the VSI */
5426 if (netdev_set_num_tc(netdev
, vsi
->tc_config
.numtc
))
5429 /* set per TC queues for the VSI */
5430 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
5431 /* Only set TC queues for enabled tcs
5433 * e.g. For a VSI that has TC0 and TC3 enabled the
5434 * enabled_tc bitmap would be 0x00001001; the driver
5435 * will set the numtc for netdev as 2 that will be
5436 * referenced by the netdev layer as TC 0 and 1.
5438 if (vsi
->tc_config
.enabled_tc
& BIT(i
))
5439 netdev_set_tc_queue(netdev
,
5440 vsi
->tc_config
.tc_info
[i
].netdev_tc
,
5441 vsi
->tc_config
.tc_info
[i
].qcount
,
5442 vsi
->tc_config
.tc_info
[i
].qoffset
);
5445 if (pf
->flags
& I40E_FLAG_TC_MQPRIO
)
5448 /* Assign UP2TC map for the VSI */
5449 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
5450 /* Get the actual TC# for the UP */
5451 u8 ets_tc
= dcbcfg
->etscfg
.prioritytable
[i
];
5452 /* Get the mapped netdev TC# for the UP */
5453 netdev_tc
= vsi
->tc_config
.tc_info
[ets_tc
].netdev_tc
;
5454 netdev_set_prio_tc_map(netdev
, i
, netdev_tc
);
5459 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
5460 * @vsi: the VSI being configured
5461 * @ctxt: the ctxt buffer returned from AQ VSI update param command
5463 static void i40e_vsi_update_queue_map(struct i40e_vsi
*vsi
,
5464 struct i40e_vsi_context
*ctxt
)
5466 /* copy just the sections touched not the entire info
5467 * since not all sections are valid as returned by
5470 vsi
->info
.mapping_flags
= ctxt
->info
.mapping_flags
;
5471 memcpy(&vsi
->info
.queue_mapping
,
5472 &ctxt
->info
.queue_mapping
, sizeof(vsi
->info
.queue_mapping
));
5473 memcpy(&vsi
->info
.tc_mapping
, ctxt
->info
.tc_mapping
,
5474 sizeof(vsi
->info
.tc_mapping
));
5478 * i40e_update_adq_vsi_queues - update queue mapping for ADq VSI
5479 * @vsi: the VSI being reconfigured
5480 * @vsi_offset: offset from main VF VSI
5482 int i40e_update_adq_vsi_queues(struct i40e_vsi
*vsi
, int vsi_offset
)
5484 struct i40e_vsi_context ctxt
= {};
5490 return I40E_ERR_PARAM
;
5494 ctxt
.seid
= vsi
->seid
;
5495 ctxt
.pf_num
= hw
->pf_id
;
5496 ctxt
.vf_num
= vsi
->vf_id
+ hw
->func_caps
.vf_base_id
+ vsi_offset
;
5497 ctxt
.uplink_seid
= vsi
->uplink_seid
;
5498 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
5499 ctxt
.flags
= I40E_AQ_VSI_TYPE_VF
;
5500 ctxt
.info
= vsi
->info
;
5502 i40e_vsi_setup_queue_map(vsi
, &ctxt
, vsi
->tc_config
.enabled_tc
,
5504 if (vsi
->reconfig_rss
) {
5505 vsi
->rss_size
= min_t(int, pf
->alloc_rss_size
,
5506 vsi
->num_queue_pairs
);
5507 ret
= i40e_vsi_config_rss(vsi
);
5509 dev_info(&pf
->pdev
->dev
, "Failed to reconfig rss for num_queues\n");
5512 vsi
->reconfig_rss
= false;
5515 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
5517 dev_info(&pf
->pdev
->dev
, "Update vsi config failed, err %s aq_err %s\n",
5518 i40e_stat_str(hw
, ret
),
5519 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
5522 /* update the local VSI info with updated queue map */
5523 i40e_vsi_update_queue_map(vsi
, &ctxt
);
5524 vsi
->info
.valid_sections
= 0;
5530 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
5531 * @vsi: VSI to be configured
5532 * @enabled_tc: TC bitmap
5534 * This configures a particular VSI for TCs that are mapped to the
5535 * given TC bitmap. It uses default bandwidth share for TCs across
5536 * VSIs to configure TC for a particular VSI.
5539 * It is expected that the VSI queues have been quisced before calling
5542 static int i40e_vsi_config_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
5544 u8 bw_share
[I40E_MAX_TRAFFIC_CLASS
] = {0};
5545 struct i40e_pf
*pf
= vsi
->back
;
5546 struct i40e_hw
*hw
= &pf
->hw
;
5547 struct i40e_vsi_context ctxt
;
5551 /* Check if enabled_tc is same as existing or new TCs */
5552 if (vsi
->tc_config
.enabled_tc
== enabled_tc
&&
5553 vsi
->mqprio_qopt
.mode
!= TC_MQPRIO_MODE_CHANNEL
)
5556 /* Enable ETS TCs with equal BW Share for now across all VSIs */
5557 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
5558 if (enabled_tc
& BIT(i
))
5562 ret
= i40e_vsi_configure_bw_alloc(vsi
, enabled_tc
, bw_share
);
5564 struct i40e_aqc_query_vsi_bw_config_resp bw_config
= {0};
5566 dev_info(&pf
->pdev
->dev
,
5567 "Failed configuring TC map %d for VSI %d\n",
5568 enabled_tc
, vsi
->seid
);
5569 ret
= i40e_aq_query_vsi_bw_config(hw
, vsi
->seid
,
5572 dev_info(&pf
->pdev
->dev
,
5573 "Failed querying vsi bw info, err %s aq_err %s\n",
5574 i40e_stat_str(hw
, ret
),
5575 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
5578 if ((bw_config
.tc_valid_bits
& enabled_tc
) != enabled_tc
) {
5579 u8 valid_tc
= bw_config
.tc_valid_bits
& enabled_tc
;
5582 valid_tc
= bw_config
.tc_valid_bits
;
5583 /* Always enable TC0, no matter what */
5585 dev_info(&pf
->pdev
->dev
,
5586 "Requested tc 0x%x, but FW reports 0x%x as valid. Attempting to use 0x%x.\n",
5587 enabled_tc
, bw_config
.tc_valid_bits
, valid_tc
);
5588 enabled_tc
= valid_tc
;
5591 ret
= i40e_vsi_configure_bw_alloc(vsi
, enabled_tc
, bw_share
);
5593 dev_err(&pf
->pdev
->dev
,
5594 "Unable to configure TC map %d for VSI %d\n",
5595 enabled_tc
, vsi
->seid
);
5600 /* Update Queue Pairs Mapping for currently enabled UPs */
5601 ctxt
.seid
= vsi
->seid
;
5602 ctxt
.pf_num
= vsi
->back
->hw
.pf_id
;
5604 ctxt
.uplink_seid
= vsi
->uplink_seid
;
5605 ctxt
.info
= vsi
->info
;
5606 if (vsi
->back
->flags
& I40E_FLAG_TC_MQPRIO
) {
5607 ret
= i40e_vsi_setup_queue_map_mqprio(vsi
, &ctxt
, enabled_tc
);
5611 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
5614 /* On destroying the qdisc, reset vsi->rss_size, as number of enabled
5617 if (!vsi
->mqprio_qopt
.qopt
.hw
&& vsi
->reconfig_rss
) {
5618 vsi
->rss_size
= min_t(int, vsi
->back
->alloc_rss_size
,
5619 vsi
->num_queue_pairs
);
5620 ret
= i40e_vsi_config_rss(vsi
);
5622 dev_info(&vsi
->back
->pdev
->dev
,
5623 "Failed to reconfig rss for num_queues\n");
5626 vsi
->reconfig_rss
= false;
5628 if (vsi
->back
->flags
& I40E_FLAG_IWARP_ENABLED
) {
5629 ctxt
.info
.valid_sections
|=
5630 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID
);
5631 ctxt
.info
.queueing_opt_flags
|= I40E_AQ_VSI_QUE_OPT_TCP_ENA
;
5634 /* Update the VSI after updating the VSI queue-mapping
5637 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
5639 dev_info(&pf
->pdev
->dev
,
5640 "Update vsi tc config failed, err %s aq_err %s\n",
5641 i40e_stat_str(hw
, ret
),
5642 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
5645 /* update the local VSI info with updated queue map */
5646 i40e_vsi_update_queue_map(vsi
, &ctxt
);
5647 vsi
->info
.valid_sections
= 0;
5649 /* Update current VSI BW information */
5650 ret
= i40e_vsi_get_bw_info(vsi
);
5652 dev_info(&pf
->pdev
->dev
,
5653 "Failed updating vsi bw info, err %s aq_err %s\n",
5654 i40e_stat_str(hw
, ret
),
5655 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
5659 /* Update the netdev TC setup */
5660 i40e_vsi_config_netdev_tc(vsi
, enabled_tc
);
5666 * i40e_get_link_speed - Returns link speed for the interface
5667 * @vsi: VSI to be configured
5670 static int i40e_get_link_speed(struct i40e_vsi
*vsi
)
5672 struct i40e_pf
*pf
= vsi
->back
;
5674 switch (pf
->hw
.phy
.link_info
.link_speed
) {
5675 case I40E_LINK_SPEED_40GB
:
5677 case I40E_LINK_SPEED_25GB
:
5679 case I40E_LINK_SPEED_20GB
:
5681 case I40E_LINK_SPEED_10GB
:
5683 case I40E_LINK_SPEED_1GB
:
5691 * i40e_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate
5692 * @vsi: VSI to be configured
5693 * @seid: seid of the channel/VSI
5694 * @max_tx_rate: max TX rate to be configured as BW limit
5696 * Helper function to set BW limit for a given VSI
5698 int i40e_set_bw_limit(struct i40e_vsi
*vsi
, u16 seid
, u64 max_tx_rate
)
5700 struct i40e_pf
*pf
= vsi
->back
;
5705 speed
= i40e_get_link_speed(vsi
);
5706 if (max_tx_rate
> speed
) {
5707 dev_err(&pf
->pdev
->dev
,
5708 "Invalid max tx rate %llu specified for VSI seid %d.",
5712 if (max_tx_rate
&& max_tx_rate
< 50) {
5713 dev_warn(&pf
->pdev
->dev
,
5714 "Setting max tx rate to minimum usable value of 50Mbps.\n");
5718 /* Tx rate credits are in values of 50Mbps, 0 is disabled */
5719 credits
= max_tx_rate
;
5720 do_div(credits
, I40E_BW_CREDIT_DIVISOR
);
5721 ret
= i40e_aq_config_vsi_bw_limit(&pf
->hw
, seid
, credits
,
5722 I40E_MAX_BW_INACTIVE_ACCUM
, NULL
);
5724 dev_err(&pf
->pdev
->dev
,
5725 "Failed set tx rate (%llu Mbps) for vsi->seid %u, err %s aq_err %s\n",
5726 max_tx_rate
, seid
, i40e_stat_str(&pf
->hw
, ret
),
5727 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
5732 * i40e_remove_queue_channels - Remove queue channels for the TCs
5733 * @vsi: VSI to be configured
5735 * Remove queue channels for the TCs
5737 static void i40e_remove_queue_channels(struct i40e_vsi
*vsi
)
5739 enum i40e_admin_queue_err last_aq_status
;
5740 struct i40e_cloud_filter
*cfilter
;
5741 struct i40e_channel
*ch
, *ch_tmp
;
5742 struct i40e_pf
*pf
= vsi
->back
;
5743 struct hlist_node
*node
;
5746 /* Reset rss size that was stored when reconfiguring rss for
5747 * channel VSIs with non-power-of-2 queue count.
5749 vsi
->current_rss_size
= 0;
5751 /* perform cleanup for channels if they exist */
5752 if (list_empty(&vsi
->ch_list
))
5755 list_for_each_entry_safe(ch
, ch_tmp
, &vsi
->ch_list
, list
) {
5756 struct i40e_vsi
*p_vsi
;
5758 list_del(&ch
->list
);
5759 p_vsi
= ch
->parent_vsi
;
5760 if (!p_vsi
|| !ch
->initialized
) {
5764 /* Reset queue contexts */
5765 for (i
= 0; i
< ch
->num_queue_pairs
; i
++) {
5766 struct i40e_ring
*tx_ring
, *rx_ring
;
5769 pf_q
= ch
->base_queue
+ i
;
5770 tx_ring
= vsi
->tx_rings
[pf_q
];
5773 rx_ring
= vsi
->rx_rings
[pf_q
];
5777 /* Reset BW configured for this VSI via mqprio */
5778 ret
= i40e_set_bw_limit(vsi
, ch
->seid
, 0);
5780 dev_info(&vsi
->back
->pdev
->dev
,
5781 "Failed to reset tx rate for ch->seid %u\n",
5784 /* delete cloud filters associated with this channel */
5785 hlist_for_each_entry_safe(cfilter
, node
,
5786 &pf
->cloud_filter_list
, cloud_node
) {
5787 if (cfilter
->seid
!= ch
->seid
)
5790 hash_del(&cfilter
->cloud_node
);
5791 if (cfilter
->dst_port
)
5792 ret
= i40e_add_del_cloud_filter_big_buf(vsi
,
5796 ret
= i40e_add_del_cloud_filter(vsi
, cfilter
,
5798 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
5800 dev_info(&pf
->pdev
->dev
,
5801 "Failed to delete cloud filter, err %s aq_err %s\n",
5802 i40e_stat_str(&pf
->hw
, ret
),
5803 i40e_aq_str(&pf
->hw
, last_aq_status
));
5807 /* delete VSI from FW */
5808 ret
= i40e_aq_delete_element(&vsi
->back
->hw
, ch
->seid
,
5811 dev_err(&vsi
->back
->pdev
->dev
,
5812 "unable to remove channel (%d) for parent VSI(%d)\n",
5813 ch
->seid
, p_vsi
->seid
);
5816 INIT_LIST_HEAD(&vsi
->ch_list
);
5820 * i40e_get_max_queues_for_channel
5821 * @vsi: ptr to VSI to which channels are associated with
5823 * Helper function which returns max value among the queue counts set on the
5824 * channels/TCs created.
5826 static int i40e_get_max_queues_for_channel(struct i40e_vsi
*vsi
)
5828 struct i40e_channel
*ch
, *ch_tmp
;
5831 list_for_each_entry_safe(ch
, ch_tmp
, &vsi
->ch_list
, list
) {
5832 if (!ch
->initialized
)
5834 if (ch
->num_queue_pairs
> max
)
5835 max
= ch
->num_queue_pairs
;
5842 * i40e_validate_num_queues - validate num_queues w.r.t channel
5843 * @pf: ptr to PF device
5844 * @num_queues: number of queues
5845 * @vsi: the parent VSI
5846 * @reconfig_rss: indicates should the RSS be reconfigured or not
5848 * This function validates number of queues in the context of new channel
5849 * which is being established and determines if RSS should be reconfigured
5850 * or not for parent VSI.
5852 static int i40e_validate_num_queues(struct i40e_pf
*pf
, int num_queues
,
5853 struct i40e_vsi
*vsi
, bool *reconfig_rss
)
5860 *reconfig_rss
= false;
5861 if (vsi
->current_rss_size
) {
5862 if (num_queues
> vsi
->current_rss_size
) {
5863 dev_dbg(&pf
->pdev
->dev
,
5864 "Error: num_queues (%d) > vsi's current_size(%d)\n",
5865 num_queues
, vsi
->current_rss_size
);
5867 } else if ((num_queues
< vsi
->current_rss_size
) &&
5868 (!is_power_of_2(num_queues
))) {
5869 dev_dbg(&pf
->pdev
->dev
,
5870 "Error: num_queues (%d) < vsi's current_size(%d), but not power of 2\n",
5871 num_queues
, vsi
->current_rss_size
);
5876 if (!is_power_of_2(num_queues
)) {
5877 /* Find the max num_queues configured for channel if channel
5879 * if channel exist, then enforce 'num_queues' to be more than
5880 * max ever queues configured for channel.
5882 max_ch_queues
= i40e_get_max_queues_for_channel(vsi
);
5883 if (num_queues
< max_ch_queues
) {
5884 dev_dbg(&pf
->pdev
->dev
,
5885 "Error: num_queues (%d) < max queues configured for channel(%d)\n",
5886 num_queues
, max_ch_queues
);
5889 *reconfig_rss
= true;
5896 * i40e_vsi_reconfig_rss - reconfig RSS based on specified rss_size
5897 * @vsi: the VSI being setup
5898 * @rss_size: size of RSS, accordingly LUT gets reprogrammed
5900 * This function reconfigures RSS by reprogramming LUTs using 'rss_size'
5902 static int i40e_vsi_reconfig_rss(struct i40e_vsi
*vsi
, u16 rss_size
)
5904 struct i40e_pf
*pf
= vsi
->back
;
5905 u8 seed
[I40E_HKEY_ARRAY_SIZE
];
5906 struct i40e_hw
*hw
= &pf
->hw
;
5914 if (rss_size
> vsi
->rss_size
)
5917 local_rss_size
= min_t(int, vsi
->rss_size
, rss_size
);
5918 lut
= kzalloc(vsi
->rss_table_size
, GFP_KERNEL
);
5922 /* Ignoring user configured lut if there is one */
5923 i40e_fill_rss_lut(pf
, lut
, vsi
->rss_table_size
, local_rss_size
);
5925 /* Use user configured hash key if there is one, otherwise
5928 if (vsi
->rss_hkey_user
)
5929 memcpy(seed
, vsi
->rss_hkey_user
, I40E_HKEY_ARRAY_SIZE
);
5931 netdev_rss_key_fill((void *)seed
, I40E_HKEY_ARRAY_SIZE
);
5933 ret
= i40e_config_rss(vsi
, seed
, lut
, vsi
->rss_table_size
);
5935 dev_info(&pf
->pdev
->dev
,
5936 "Cannot set RSS lut, err %s aq_err %s\n",
5937 i40e_stat_str(hw
, ret
),
5938 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
5944 /* Do the update w.r.t. storing rss_size */
5945 if (!vsi
->orig_rss_size
)
5946 vsi
->orig_rss_size
= vsi
->rss_size
;
5947 vsi
->current_rss_size
= local_rss_size
;
5953 * i40e_channel_setup_queue_map - Setup a channel queue map
5954 * @pf: ptr to PF device
5955 * @ctxt: VSI context structure
5956 * @ch: ptr to channel structure
5958 * Setup queue map for a specific channel
5960 static void i40e_channel_setup_queue_map(struct i40e_pf
*pf
,
5961 struct i40e_vsi_context
*ctxt
,
5962 struct i40e_channel
*ch
)
5964 u16 qcount
, qmap
, sections
= 0;
5968 sections
= I40E_AQ_VSI_PROP_QUEUE_MAP_VALID
;
5969 sections
|= I40E_AQ_VSI_PROP_SCHED_VALID
;
5971 qcount
= min_t(int, ch
->num_queue_pairs
, pf
->num_lan_msix
);
5972 ch
->num_queue_pairs
= qcount
;
5974 /* find the next higher power-of-2 of num queue pairs */
5975 pow
= ilog2(qcount
);
5976 if (!is_power_of_2(qcount
))
5979 qmap
= (offset
<< I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT
) |
5980 (pow
<< I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT
);
5982 /* Setup queue TC[0].qmap for given VSI context */
5983 ctxt
->info
.tc_mapping
[0] = cpu_to_le16(qmap
);
5985 ctxt
->info
.up_enable_bits
= 0x1; /* TC0 enabled */
5986 ctxt
->info
.mapping_flags
|= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG
);
5987 ctxt
->info
.queue_mapping
[0] = cpu_to_le16(ch
->base_queue
);
5988 ctxt
->info
.valid_sections
|= cpu_to_le16(sections
);
5992 * i40e_add_channel - add a channel by adding VSI
5993 * @pf: ptr to PF device
5994 * @uplink_seid: underlying HW switching element (VEB) ID
5995 * @ch: ptr to channel structure
5997 * Add a channel (VSI) using add_vsi and queue_map
5999 static int i40e_add_channel(struct i40e_pf
*pf
, u16 uplink_seid
,
6000 struct i40e_channel
*ch
)
6002 struct i40e_hw
*hw
= &pf
->hw
;
6003 struct i40e_vsi_context ctxt
;
6004 u8 enabled_tc
= 0x1; /* TC0 enabled */
6007 if (ch
->type
!= I40E_VSI_VMDQ2
) {
6008 dev_info(&pf
->pdev
->dev
,
6009 "add new vsi failed, ch->type %d\n", ch
->type
);
6013 memset(&ctxt
, 0, sizeof(ctxt
));
6014 ctxt
.pf_num
= hw
->pf_id
;
6016 ctxt
.uplink_seid
= uplink_seid
;
6017 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
6018 if (ch
->type
== I40E_VSI_VMDQ2
)
6019 ctxt
.flags
= I40E_AQ_VSI_TYPE_VMDQ2
;
6021 if (pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
) {
6022 ctxt
.info
.valid_sections
|=
6023 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
6024 ctxt
.info
.switch_id
=
6025 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
6028 /* Set queue map for a given VSI context */
6029 i40e_channel_setup_queue_map(pf
, &ctxt
, ch
);
6031 /* Now time to create VSI */
6032 ret
= i40e_aq_add_vsi(hw
, &ctxt
, NULL
);
6034 dev_info(&pf
->pdev
->dev
,
6035 "add new vsi failed, err %s aq_err %s\n",
6036 i40e_stat_str(&pf
->hw
, ret
),
6037 i40e_aq_str(&pf
->hw
,
6038 pf
->hw
.aq
.asq_last_status
));
6042 /* Success, update channel, set enabled_tc only if the channel
6045 ch
->enabled_tc
= !i40e_is_channel_macvlan(ch
) && enabled_tc
;
6046 ch
->seid
= ctxt
.seid
;
6047 ch
->vsi_number
= ctxt
.vsi_number
;
6048 ch
->stat_counter_idx
= le16_to_cpu(ctxt
.info
.stat_counter_idx
);
6050 /* copy just the sections touched not the entire info
6051 * since not all sections are valid as returned by
6054 ch
->info
.mapping_flags
= ctxt
.info
.mapping_flags
;
6055 memcpy(&ch
->info
.queue_mapping
,
6056 &ctxt
.info
.queue_mapping
, sizeof(ctxt
.info
.queue_mapping
));
6057 memcpy(&ch
->info
.tc_mapping
, ctxt
.info
.tc_mapping
,
6058 sizeof(ctxt
.info
.tc_mapping
));
6063 static int i40e_channel_config_bw(struct i40e_vsi
*vsi
, struct i40e_channel
*ch
,
6066 struct i40e_aqc_configure_vsi_tc_bw_data bw_data
;
6070 memset(&bw_data
, 0, sizeof(bw_data
));
6071 bw_data
.tc_valid_bits
= ch
->enabled_tc
;
6072 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
6073 bw_data
.tc_bw_credits
[i
] = bw_share
[i
];
6075 ret
= i40e_aq_config_vsi_tc_bw(&vsi
->back
->hw
, ch
->seid
,
6078 dev_info(&vsi
->back
->pdev
->dev
,
6079 "Config VSI BW allocation per TC failed, aq_err: %d for new_vsi->seid %u\n",
6080 vsi
->back
->hw
.aq
.asq_last_status
, ch
->seid
);
6084 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
6085 ch
->info
.qs_handle
[i
] = bw_data
.qs_handles
[i
];
6091 * i40e_channel_config_tx_ring - config TX ring associated with new channel
6092 * @pf: ptr to PF device
6093 * @vsi: the VSI being setup
6094 * @ch: ptr to channel structure
6096 * Configure TX rings associated with channel (VSI) since queues are being
6099 static int i40e_channel_config_tx_ring(struct i40e_pf
*pf
,
6100 struct i40e_vsi
*vsi
,
6101 struct i40e_channel
*ch
)
6105 u8 bw_share
[I40E_MAX_TRAFFIC_CLASS
] = {0};
6107 /* Enable ETS TCs with equal BW Share for now across all VSIs */
6108 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
6109 if (ch
->enabled_tc
& BIT(i
))
6113 /* configure BW for new VSI */
6114 ret
= i40e_channel_config_bw(vsi
, ch
, bw_share
);
6116 dev_info(&vsi
->back
->pdev
->dev
,
6117 "Failed configuring TC map %d for channel (seid %u)\n",
6118 ch
->enabled_tc
, ch
->seid
);
6122 for (i
= 0; i
< ch
->num_queue_pairs
; i
++) {
6123 struct i40e_ring
*tx_ring
, *rx_ring
;
6126 pf_q
= ch
->base_queue
+ i
;
6128 /* Get to TX ring ptr of main VSI, for re-setup TX queue
6131 tx_ring
= vsi
->tx_rings
[pf_q
];
6134 /* Get the RX ring ptr */
6135 rx_ring
= vsi
->rx_rings
[pf_q
];
6143 * i40e_setup_hw_channel - setup new channel
6144 * @pf: ptr to PF device
6145 * @vsi: the VSI being setup
6146 * @ch: ptr to channel structure
6147 * @uplink_seid: underlying HW switching element (VEB) ID
6148 * @type: type of channel to be created (VMDq2/VF)
6150 * Setup new channel (VSI) based on specified type (VMDq2/VF)
6151 * and configures TX rings accordingly
6153 static inline int i40e_setup_hw_channel(struct i40e_pf
*pf
,
6154 struct i40e_vsi
*vsi
,
6155 struct i40e_channel
*ch
,
6156 u16 uplink_seid
, u8 type
)
6160 ch
->initialized
= false;
6161 ch
->base_queue
= vsi
->next_base_queue
;
6164 /* Proceed with creation of channel (VMDq2) VSI */
6165 ret
= i40e_add_channel(pf
, uplink_seid
, ch
);
6167 dev_info(&pf
->pdev
->dev
,
6168 "failed to add_channel using uplink_seid %u\n",
6173 /* Mark the successful creation of channel */
6174 ch
->initialized
= true;
6176 /* Reconfigure TX queues using QTX_CTL register */
6177 ret
= i40e_channel_config_tx_ring(pf
, vsi
, ch
);
6179 dev_info(&pf
->pdev
->dev
,
6180 "failed to configure TX rings for channel %u\n",
6185 /* update 'next_base_queue' */
6186 vsi
->next_base_queue
= vsi
->next_base_queue
+ ch
->num_queue_pairs
;
6187 dev_dbg(&pf
->pdev
->dev
,
6188 "Added channel: vsi_seid %u, vsi_number %u, stat_counter_idx %u, num_queue_pairs %u, pf->next_base_queue %d\n",
6189 ch
->seid
, ch
->vsi_number
, ch
->stat_counter_idx
,
6190 ch
->num_queue_pairs
,
6191 vsi
->next_base_queue
);
6196 * i40e_setup_channel - setup new channel using uplink element
6197 * @pf: ptr to PF device
6198 * @vsi: pointer to the VSI to set up the channel within
6199 * @ch: ptr to channel structure
6201 * Setup new channel (VSI) based on specified type (VMDq2/VF)
6202 * and uplink switching element (uplink_seid)
6204 static bool i40e_setup_channel(struct i40e_pf
*pf
, struct i40e_vsi
*vsi
,
6205 struct i40e_channel
*ch
)
6211 if (vsi
->type
== I40E_VSI_MAIN
) {
6212 vsi_type
= I40E_VSI_VMDQ2
;
6214 dev_err(&pf
->pdev
->dev
, "unsupported parent vsi type(%d)\n",
6219 /* underlying switching element */
6220 seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
6222 /* create channel (VSI), configure TX rings */
6223 ret
= i40e_setup_hw_channel(pf
, vsi
, ch
, seid
, vsi_type
);
6225 dev_err(&pf
->pdev
->dev
, "failed to setup hw_channel\n");
6229 return ch
->initialized
? true : false;
6233 * i40e_validate_and_set_switch_mode - sets up switch mode correctly
6234 * @vsi: ptr to VSI which has PF backing
6236 * Sets up switch mode correctly if it needs to be changed and perform
6237 * what are allowed modes.
6239 static int i40e_validate_and_set_switch_mode(struct i40e_vsi
*vsi
)
6242 struct i40e_pf
*pf
= vsi
->back
;
6243 struct i40e_hw
*hw
= &pf
->hw
;
6246 ret
= i40e_get_capabilities(pf
, i40e_aqc_opc_list_dev_capabilities
);
6250 if (hw
->dev_caps
.switch_mode
) {
6251 /* if switch mode is set, support mode2 (non-tunneled for
6252 * cloud filter) for now
6254 u32 switch_mode
= hw
->dev_caps
.switch_mode
&
6255 I40E_SWITCH_MODE_MASK
;
6256 if (switch_mode
>= I40E_CLOUD_FILTER_MODE1
) {
6257 if (switch_mode
== I40E_CLOUD_FILTER_MODE2
)
6259 dev_err(&pf
->pdev
->dev
,
6260 "Invalid switch_mode (%d), only non-tunneled mode for cloud filter is supported\n",
6261 hw
->dev_caps
.switch_mode
);
6266 /* Set Bit 7 to be valid */
6267 mode
= I40E_AQ_SET_SWITCH_BIT7_VALID
;
6269 /* Set L4type for TCP support */
6270 mode
|= I40E_AQ_SET_SWITCH_L4_TYPE_TCP
;
6272 /* Set cloud filter mode */
6273 mode
|= I40E_AQ_SET_SWITCH_MODE_NON_TUNNEL
;
6275 /* Prep mode field for set_switch_config */
6276 ret
= i40e_aq_set_switch_config(hw
, pf
->last_sw_conf_flags
,
6277 pf
->last_sw_conf_valid_flags
,
6279 if (ret
&& hw
->aq
.asq_last_status
!= I40E_AQ_RC_ESRCH
)
6280 dev_err(&pf
->pdev
->dev
,
6281 "couldn't set switch config bits, err %s aq_err %s\n",
6282 i40e_stat_str(hw
, ret
),
6284 hw
->aq
.asq_last_status
));
6290 * i40e_create_queue_channel - function to create channel
6291 * @vsi: VSI to be configured
6292 * @ch: ptr to channel (it contains channel specific params)
6294 * This function creates channel (VSI) using num_queues specified by user,
6295 * reconfigs RSS if needed.
6297 int i40e_create_queue_channel(struct i40e_vsi
*vsi
,
6298 struct i40e_channel
*ch
)
6300 struct i40e_pf
*pf
= vsi
->back
;
6307 if (!ch
->num_queue_pairs
) {
6308 dev_err(&pf
->pdev
->dev
, "Invalid num_queues requested: %d\n",
6309 ch
->num_queue_pairs
);
6313 /* validate user requested num_queues for channel */
6314 err
= i40e_validate_num_queues(pf
, ch
->num_queue_pairs
, vsi
,
6317 dev_info(&pf
->pdev
->dev
, "Failed to validate num_queues (%d)\n",
6318 ch
->num_queue_pairs
);
6322 /* By default we are in VEPA mode, if this is the first VF/VMDq
6323 * VSI to be added switch to VEB mode.
6326 if (!(pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)) {
6327 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
6329 if (vsi
->type
== I40E_VSI_MAIN
) {
6330 if (pf
->flags
& I40E_FLAG_TC_MQPRIO
)
6331 i40e_do_reset(pf
, I40E_PF_RESET_FLAG
, true);
6333 i40e_do_reset_safe(pf
, I40E_PF_RESET_FLAG
);
6335 /* now onwards for main VSI, number of queues will be value
6336 * of TC0's queue count
6340 /* By this time, vsi->cnt_q_avail shall be set to non-zero and
6341 * it should be more than num_queues
6343 if (!vsi
->cnt_q_avail
|| vsi
->cnt_q_avail
< ch
->num_queue_pairs
) {
6344 dev_dbg(&pf
->pdev
->dev
,
6345 "Error: cnt_q_avail (%u) less than num_queues %d\n",
6346 vsi
->cnt_q_avail
, ch
->num_queue_pairs
);
6350 /* reconfig_rss only if vsi type is MAIN_VSI */
6351 if (reconfig_rss
&& (vsi
->type
== I40E_VSI_MAIN
)) {
6352 err
= i40e_vsi_reconfig_rss(vsi
, ch
->num_queue_pairs
);
6354 dev_info(&pf
->pdev
->dev
,
6355 "Error: unable to reconfig rss for num_queues (%u)\n",
6356 ch
->num_queue_pairs
);
6361 if (!i40e_setup_channel(pf
, vsi
, ch
)) {
6362 dev_info(&pf
->pdev
->dev
, "Failed to setup channel\n");
6366 dev_info(&pf
->pdev
->dev
,
6367 "Setup channel (id:%u) utilizing num_queues %d\n",
6368 ch
->seid
, ch
->num_queue_pairs
);
6370 /* configure VSI for BW limit */
6371 if (ch
->max_tx_rate
) {
6372 u64 credits
= ch
->max_tx_rate
;
6374 if (i40e_set_bw_limit(vsi
, ch
->seid
, ch
->max_tx_rate
))
6377 do_div(credits
, I40E_BW_CREDIT_DIVISOR
);
6378 dev_dbg(&pf
->pdev
->dev
,
6379 "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
6385 /* in case of VF, this will be main SRIOV VSI */
6386 ch
->parent_vsi
= vsi
;
6388 /* and update main_vsi's count for queue_available to use */
6389 vsi
->cnt_q_avail
-= ch
->num_queue_pairs
;
6395 * i40e_configure_queue_channels - Add queue channel for the given TCs
6396 * @vsi: VSI to be configured
6398 * Configures queue channel mapping to the given TCs
6400 static int i40e_configure_queue_channels(struct i40e_vsi
*vsi
)
6402 struct i40e_channel
*ch
;
6406 /* Create app vsi with the TCs. Main VSI with TC0 is already set up */
6407 vsi
->tc_seid_map
[0] = vsi
->seid
;
6408 for (i
= 1; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
6409 if (vsi
->tc_config
.enabled_tc
& BIT(i
)) {
6410 ch
= kzalloc(sizeof(*ch
), GFP_KERNEL
);
6416 INIT_LIST_HEAD(&ch
->list
);
6417 ch
->num_queue_pairs
=
6418 vsi
->tc_config
.tc_info
[i
].qcount
;
6420 vsi
->tc_config
.tc_info
[i
].qoffset
;
6422 /* Bandwidth limit through tc interface is in bytes/s,
6425 max_rate
= vsi
->mqprio_qopt
.max_rate
[i
];
6426 do_div(max_rate
, I40E_BW_MBPS_DIVISOR
);
6427 ch
->max_tx_rate
= max_rate
;
6429 list_add_tail(&ch
->list
, &vsi
->ch_list
);
6431 ret
= i40e_create_queue_channel(vsi
, ch
);
6433 dev_err(&vsi
->back
->pdev
->dev
,
6434 "Failed creating queue channel with TC%d: queues %d\n",
6435 i
, ch
->num_queue_pairs
);
6438 vsi
->tc_seid_map
[i
] = ch
->seid
;
6444 i40e_remove_queue_channels(vsi
);
6449 * i40e_veb_config_tc - Configure TCs for given VEB
6451 * @enabled_tc: TC bitmap
6453 * Configures given TC bitmap for VEB (switching) element
6455 int i40e_veb_config_tc(struct i40e_veb
*veb
, u8 enabled_tc
)
6457 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data
= {0};
6458 struct i40e_pf
*pf
= veb
->pf
;
6462 /* No TCs or already enabled TCs just return */
6463 if (!enabled_tc
|| veb
->enabled_tc
== enabled_tc
)
6466 bw_data
.tc_valid_bits
= enabled_tc
;
6467 /* bw_data.absolute_credits is not set (relative) */
6469 /* Enable ETS TCs with equal BW Share for now */
6470 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
6471 if (enabled_tc
& BIT(i
))
6472 bw_data
.tc_bw_share_credits
[i
] = 1;
6475 ret
= i40e_aq_config_switch_comp_bw_config(&pf
->hw
, veb
->seid
,
6478 dev_info(&pf
->pdev
->dev
,
6479 "VEB bw config failed, err %s aq_err %s\n",
6480 i40e_stat_str(&pf
->hw
, ret
),
6481 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6485 /* Update the BW information */
6486 ret
= i40e_veb_get_bw_info(veb
);
6488 dev_info(&pf
->pdev
->dev
,
6489 "Failed getting veb bw config, err %s aq_err %s\n",
6490 i40e_stat_str(&pf
->hw
, ret
),
6491 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6498 #ifdef CONFIG_I40E_DCB
6500 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
6503 * Reconfigure VEB/VSIs on a given PF; it is assumed that
6504 * the caller would've quiesce all the VSIs before calling
6507 static void i40e_dcb_reconfigure(struct i40e_pf
*pf
)
6513 /* Enable the TCs available on PF to all VEBs */
6514 tc_map
= i40e_pf_get_tc_map(pf
);
6515 if (tc_map
== I40E_DEFAULT_TRAFFIC_CLASS
)
6518 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
6521 ret
= i40e_veb_config_tc(pf
->veb
[v
], tc_map
);
6523 dev_info(&pf
->pdev
->dev
,
6524 "Failed configuring TC for VEB seid=%d\n",
6526 /* Will try to configure as many components */
6530 /* Update each VSI */
6531 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
6535 /* - Enable all TCs for the LAN VSI
6536 * - For all others keep them at TC0 for now
6538 if (v
== pf
->lan_vsi
)
6539 tc_map
= i40e_pf_get_tc_map(pf
);
6541 tc_map
= I40E_DEFAULT_TRAFFIC_CLASS
;
6543 ret
= i40e_vsi_config_tc(pf
->vsi
[v
], tc_map
);
6545 dev_info(&pf
->pdev
->dev
,
6546 "Failed configuring TC for VSI seid=%d\n",
6548 /* Will try to configure as many components */
6550 /* Re-configure VSI vectors based on updated TC map */
6551 i40e_vsi_map_rings_to_vectors(pf
->vsi
[v
]);
6552 if (pf
->vsi
[v
]->netdev
)
6553 i40e_dcbnl_set_all(pf
->vsi
[v
]);
6559 * i40e_resume_port_tx - Resume port Tx
6562 * Resume a port's Tx and issue a PF reset in case of failure to
6565 static int i40e_resume_port_tx(struct i40e_pf
*pf
)
6567 struct i40e_hw
*hw
= &pf
->hw
;
6570 ret
= i40e_aq_resume_port_tx(hw
, NULL
);
6572 dev_info(&pf
->pdev
->dev
,
6573 "Resume Port Tx failed, err %s aq_err %s\n",
6574 i40e_stat_str(&pf
->hw
, ret
),
6575 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6576 /* Schedule PF reset to recover */
6577 set_bit(__I40E_PF_RESET_REQUESTED
, pf
->state
);
6578 i40e_service_event_schedule(pf
);
6585 * i40e_suspend_port_tx - Suspend port Tx
6588 * Suspend a port's Tx and issue a PF reset in case of failure.
6590 static int i40e_suspend_port_tx(struct i40e_pf
*pf
)
6592 struct i40e_hw
*hw
= &pf
->hw
;
6595 ret
= i40e_aq_suspend_port_tx(hw
, pf
->mac_seid
, NULL
);
6597 dev_info(&pf
->pdev
->dev
,
6598 "Suspend Port Tx failed, err %s aq_err %s\n",
6599 i40e_stat_str(&pf
->hw
, ret
),
6600 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6601 /* Schedule PF reset to recover */
6602 set_bit(__I40E_PF_RESET_REQUESTED
, pf
->state
);
6603 i40e_service_event_schedule(pf
);
6610 * i40e_hw_set_dcb_config - Program new DCBX settings into HW
6611 * @pf: PF being configured
6612 * @new_cfg: New DCBX configuration
6614 * Program DCB settings into HW and reconfigure VEB/VSIs on
6615 * given PF. Uses "Set LLDP MIB" AQC to program the hardware.
6617 static int i40e_hw_set_dcb_config(struct i40e_pf
*pf
,
6618 struct i40e_dcbx_config
*new_cfg
)
6620 struct i40e_dcbx_config
*old_cfg
= &pf
->hw
.local_dcbx_config
;
6623 /* Check if need reconfiguration */
6624 if (!memcmp(&new_cfg
, &old_cfg
, sizeof(new_cfg
))) {
6625 dev_dbg(&pf
->pdev
->dev
, "No Change in DCB Config required.\n");
6629 /* Config change disable all VSIs */
6630 i40e_pf_quiesce_all_vsi(pf
);
6632 /* Copy the new config to the current config */
6633 *old_cfg
= *new_cfg
;
6634 old_cfg
->etsrec
= old_cfg
->etscfg
;
6635 ret
= i40e_set_dcb_config(&pf
->hw
);
6637 dev_info(&pf
->pdev
->dev
,
6638 "Set DCB Config failed, err %s aq_err %s\n",
6639 i40e_stat_str(&pf
->hw
, ret
),
6640 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6644 /* Changes in configuration update VEB/VSI */
6645 i40e_dcb_reconfigure(pf
);
6647 /* In case of reset do not try to resume anything */
6648 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
)) {
6649 /* Re-start the VSIs if disabled */
6650 ret
= i40e_resume_port_tx(pf
);
6651 /* In case of error no point in resuming VSIs */
6654 i40e_pf_unquiesce_all_vsi(pf
);
6661 * i40e_hw_dcb_config - Program new DCBX settings into HW
6662 * @pf: PF being configured
6663 * @new_cfg: New DCBX configuration
6665 * Program DCB settings into HW and reconfigure VEB/VSIs on
6668 int i40e_hw_dcb_config(struct i40e_pf
*pf
, struct i40e_dcbx_config
*new_cfg
)
6670 struct i40e_aqc_configure_switching_comp_ets_data ets_data
;
6671 u8 prio_type
[I40E_MAX_TRAFFIC_CLASS
] = {0};
6672 u32 mfs_tc
[I40E_MAX_TRAFFIC_CLASS
];
6673 struct i40e_dcbx_config
*old_cfg
;
6674 u8 mode
[I40E_MAX_TRAFFIC_CLASS
];
6675 struct i40e_rx_pb_config pb_cfg
;
6676 struct i40e_hw
*hw
= &pf
->hw
;
6677 u8 num_ports
= hw
->num_ports
;
6685 dev_dbg(&pf
->pdev
->dev
, "Configuring DCB registers directly\n");
6686 /* Un-pack information to Program ETS HW via shared API
6689 * ETS/NON-ETS arbiter mode
6690 * max exponent (credit refills)
6691 * Total number of ports
6692 * PFC priority bit-map
6695 * Arbiter mode between UPs sharing same TC
6696 * TSA table (ETS or non-ETS)
6697 * EEE enabled or not
6701 new_numtc
= i40e_dcb_get_num_tc(new_cfg
);
6703 memset(&ets_data
, 0, sizeof(ets_data
));
6704 for (i
= 0; i
< new_numtc
; i
++) {
6706 switch (new_cfg
->etscfg
.tsatable
[i
]) {
6707 case I40E_IEEE_TSA_ETS
:
6708 prio_type
[i
] = I40E_DCB_PRIO_TYPE_ETS
;
6709 ets_data
.tc_bw_share_credits
[i
] =
6710 new_cfg
->etscfg
.tcbwtable
[i
];
6712 case I40E_IEEE_TSA_STRICT
:
6713 prio_type
[i
] = I40E_DCB_PRIO_TYPE_STRICT
;
6715 ets_data
.tc_bw_share_credits
[i
] =
6716 I40E_DCB_STRICT_PRIO_CREDITS
;
6719 /* Invalid TSA type */
6720 need_reconfig
= false;
6725 old_cfg
= &hw
->local_dcbx_config
;
6726 /* Check if need reconfiguration */
6727 need_reconfig
= i40e_dcb_need_reconfig(pf
, old_cfg
, new_cfg
);
6729 /* If needed, enable/disable frame tagging, disable all VSIs
6730 * and suspend port tx
6732 if (need_reconfig
) {
6733 /* Enable DCB tagging only when more than one TC */
6735 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
6737 pf
->flags
&= ~I40E_FLAG_DCB_ENABLED
;
6739 set_bit(__I40E_PORT_SUSPENDED
, pf
->state
);
6740 /* Reconfiguration needed quiesce all VSIs */
6741 i40e_pf_quiesce_all_vsi(pf
);
6742 ret
= i40e_suspend_port_tx(pf
);
6747 /* Configure Port ETS Tx Scheduler */
6748 ets_data
.tc_valid_bits
= tc_map
;
6749 ets_data
.tc_strict_priority_flags
= lltc_map
;
6750 ret
= i40e_aq_config_switch_comp_ets
6751 (hw
, pf
->mac_seid
, &ets_data
,
6752 i40e_aqc_opc_modify_switching_comp_ets
, NULL
);
6754 dev_info(&pf
->pdev
->dev
,
6755 "Modify Port ETS failed, err %s aq_err %s\n",
6756 i40e_stat_str(&pf
->hw
, ret
),
6757 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6761 /* Configure Rx ETS HW */
6762 memset(&mode
, I40E_DCB_ARB_MODE_ROUND_ROBIN
, sizeof(mode
));
6763 i40e_dcb_hw_set_num_tc(hw
, new_numtc
);
6764 i40e_dcb_hw_rx_fifo_config(hw
, I40E_DCB_ARB_MODE_ROUND_ROBIN
,
6765 I40E_DCB_ARB_MODE_STRICT_PRIORITY
,
6766 I40E_DCB_DEFAULT_MAX_EXPONENT
,
6768 i40e_dcb_hw_rx_cmd_monitor_config(hw
, new_numtc
, num_ports
);
6769 i40e_dcb_hw_rx_ets_bw_config(hw
, new_cfg
->etscfg
.tcbwtable
, mode
,
6771 i40e_dcb_hw_pfc_config(hw
, new_cfg
->pfc
.pfcenable
,
6772 new_cfg
->etscfg
.prioritytable
);
6773 i40e_dcb_hw_rx_up2tc_config(hw
, new_cfg
->etscfg
.prioritytable
);
6775 /* Configure Rx Packet Buffers in HW */
6776 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
6777 mfs_tc
[i
] = pf
->vsi
[pf
->lan_vsi
]->netdev
->mtu
;
6778 mfs_tc
[i
] += I40E_PACKET_HDR_PAD
;
6781 i40e_dcb_hw_calculate_pool_sizes(hw
, num_ports
,
6782 false, new_cfg
->pfc
.pfcenable
,
6784 i40e_dcb_hw_rx_pb_config(hw
, &pf
->pb_cfg
, &pb_cfg
);
6786 /* Update the local Rx Packet buffer config */
6787 pf
->pb_cfg
= pb_cfg
;
6789 /* Inform the FW about changes to DCB configuration */
6790 ret
= i40e_aq_dcb_updated(&pf
->hw
, NULL
);
6792 dev_info(&pf
->pdev
->dev
,
6793 "DCB Updated failed, err %s aq_err %s\n",
6794 i40e_stat_str(&pf
->hw
, ret
),
6795 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6799 /* Update the port DCBx configuration */
6800 *old_cfg
= *new_cfg
;
6802 /* Changes in configuration update VEB/VSI */
6803 i40e_dcb_reconfigure(pf
);
6805 /* Re-start the VSIs if disabled */
6806 if (need_reconfig
) {
6807 ret
= i40e_resume_port_tx(pf
);
6809 clear_bit(__I40E_PORT_SUSPENDED
, pf
->state
);
6810 /* In case of error no point in resuming VSIs */
6814 /* Wait for the PF's queues to be disabled */
6815 ret
= i40e_pf_wait_queues_disabled(pf
);
6817 /* Schedule PF reset to recover */
6818 set_bit(__I40E_PF_RESET_REQUESTED
, pf
->state
);
6819 i40e_service_event_schedule(pf
);
6822 i40e_pf_unquiesce_all_vsi(pf
);
6823 set_bit(__I40E_CLIENT_SERVICE_REQUESTED
, pf
->state
);
6824 set_bit(__I40E_CLIENT_L2_CHANGE
, pf
->state
);
6826 /* registers are set, lets apply */
6827 if (pf
->hw_features
& I40E_HW_USE_SET_LLDP_MIB
)
6828 ret
= i40e_hw_set_dcb_config(pf
, new_cfg
);
6836 * i40e_dcb_sw_default_config - Set default DCB configuration when DCB in SW
6837 * @pf: PF being queried
6839 * Set default DCB configuration in case DCB is to be done in SW.
6841 int i40e_dcb_sw_default_config(struct i40e_pf
*pf
)
6843 struct i40e_dcbx_config
*dcb_cfg
= &pf
->hw
.local_dcbx_config
;
6844 struct i40e_aqc_configure_switching_comp_ets_data ets_data
;
6845 struct i40e_hw
*hw
= &pf
->hw
;
6848 if (pf
->hw_features
& I40E_HW_USE_SET_LLDP_MIB
) {
6849 /* Update the local cached instance with TC0 ETS */
6850 memset(&pf
->tmp_cfg
, 0, sizeof(struct i40e_dcbx_config
));
6851 pf
->tmp_cfg
.etscfg
.willing
= I40E_IEEE_DEFAULT_ETS_WILLING
;
6852 pf
->tmp_cfg
.etscfg
.maxtcs
= 0;
6853 pf
->tmp_cfg
.etscfg
.tcbwtable
[0] = I40E_IEEE_DEFAULT_ETS_TCBW
;
6854 pf
->tmp_cfg
.etscfg
.tsatable
[0] = I40E_IEEE_TSA_ETS
;
6855 pf
->tmp_cfg
.pfc
.willing
= I40E_IEEE_DEFAULT_PFC_WILLING
;
6856 pf
->tmp_cfg
.pfc
.pfccap
= I40E_MAX_TRAFFIC_CLASS
;
6857 /* FW needs one App to configure HW */
6858 pf
->tmp_cfg
.numapps
= I40E_IEEE_DEFAULT_NUM_APPS
;
6859 pf
->tmp_cfg
.app
[0].selector
= I40E_APP_SEL_ETHTYPE
;
6860 pf
->tmp_cfg
.app
[0].priority
= I40E_IEEE_DEFAULT_APP_PRIO
;
6861 pf
->tmp_cfg
.app
[0].protocolid
= I40E_APP_PROTOID_FCOE
;
6863 return i40e_hw_set_dcb_config(pf
, &pf
->tmp_cfg
);
6866 memset(&ets_data
, 0, sizeof(ets_data
));
6867 ets_data
.tc_valid_bits
= I40E_DEFAULT_TRAFFIC_CLASS
; /* TC0 only */
6868 ets_data
.tc_strict_priority_flags
= 0; /* ETS */
6869 ets_data
.tc_bw_share_credits
[0] = I40E_IEEE_DEFAULT_ETS_TCBW
; /* 100% to TC0 */
6871 /* Enable ETS on the Physical port */
6872 err
= i40e_aq_config_switch_comp_ets
6873 (hw
, pf
->mac_seid
, &ets_data
,
6874 i40e_aqc_opc_enable_switching_comp_ets
, NULL
);
6876 dev_info(&pf
->pdev
->dev
,
6877 "Enable Port ETS failed, err %s aq_err %s\n",
6878 i40e_stat_str(&pf
->hw
, err
),
6879 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6884 /* Update the local cached instance with TC0 ETS */
6885 dcb_cfg
->etscfg
.willing
= I40E_IEEE_DEFAULT_ETS_WILLING
;
6886 dcb_cfg
->etscfg
.cbs
= 0;
6887 dcb_cfg
->etscfg
.maxtcs
= I40E_MAX_TRAFFIC_CLASS
;
6888 dcb_cfg
->etscfg
.tcbwtable
[0] = I40E_IEEE_DEFAULT_ETS_TCBW
;
6895 * i40e_init_pf_dcb - Initialize DCB configuration
6896 * @pf: PF being configured
6898 * Query the current DCB configuration and cache it
6899 * in the hardware structure
6901 static int i40e_init_pf_dcb(struct i40e_pf
*pf
)
6903 struct i40e_hw
*hw
= &pf
->hw
;
6906 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable
6907 * Also do not enable DCBx if FW LLDP agent is disabled
6909 if (pf
->hw_features
& I40E_HW_NO_DCB_SUPPORT
) {
6910 dev_info(&pf
->pdev
->dev
, "DCB is not supported.\n");
6911 err
= I40E_NOT_SUPPORTED
;
6914 if (pf
->flags
& I40E_FLAG_DISABLE_FW_LLDP
) {
6915 dev_info(&pf
->pdev
->dev
, "FW LLDP is disabled, attempting SW DCB\n");
6916 err
= i40e_dcb_sw_default_config(pf
);
6918 dev_info(&pf
->pdev
->dev
, "Could not initialize SW DCB\n");
6921 dev_info(&pf
->pdev
->dev
, "SW DCB initialization succeeded.\n");
6922 pf
->dcbx_cap
= DCB_CAP_DCBX_HOST
|
6923 DCB_CAP_DCBX_VER_IEEE
;
6924 /* at init capable but disabled */
6925 pf
->flags
|= I40E_FLAG_DCB_CAPABLE
;
6926 pf
->flags
&= ~I40E_FLAG_DCB_ENABLED
;
6929 err
= i40e_init_dcb(hw
, true);
6931 /* Device/Function is not DCBX capable */
6932 if ((!hw
->func_caps
.dcb
) ||
6933 (hw
->dcbx_status
== I40E_DCBX_STATUS_DISABLED
)) {
6934 dev_info(&pf
->pdev
->dev
,
6935 "DCBX offload is not supported or is disabled for this PF.\n");
6937 /* When status is not DISABLED then DCBX in FW */
6938 pf
->dcbx_cap
= DCB_CAP_DCBX_LLD_MANAGED
|
6939 DCB_CAP_DCBX_VER_IEEE
;
6941 pf
->flags
|= I40E_FLAG_DCB_CAPABLE
;
6942 /* Enable DCB tagging only when more than one TC
6943 * or explicitly disable if only one TC
6945 if (i40e_dcb_get_num_tc(&hw
->local_dcbx_config
) > 1)
6946 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
6948 pf
->flags
&= ~I40E_FLAG_DCB_ENABLED
;
6949 dev_dbg(&pf
->pdev
->dev
,
6950 "DCBX offload is supported for this PF.\n");
6952 } else if (pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_EPERM
) {
6953 dev_info(&pf
->pdev
->dev
, "FW LLDP disabled for this PF.\n");
6954 pf
->flags
|= I40E_FLAG_DISABLE_FW_LLDP
;
6956 dev_info(&pf
->pdev
->dev
,
6957 "Query for DCB configuration failed, err %s aq_err %s\n",
6958 i40e_stat_str(&pf
->hw
, err
),
6959 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6965 #endif /* CONFIG_I40E_DCB */
6968 * i40e_print_link_message - print link up or down
6969 * @vsi: the VSI for which link needs a message
6970 * @isup: true of link is up, false otherwise
6972 void i40e_print_link_message(struct i40e_vsi
*vsi
, bool isup
)
6974 enum i40e_aq_link_speed new_speed
;
6975 struct i40e_pf
*pf
= vsi
->back
;
6976 char *speed
= "Unknown";
6977 char *fc
= "Unknown";
6983 new_speed
= pf
->hw
.phy
.link_info
.link_speed
;
6985 new_speed
= I40E_LINK_SPEED_UNKNOWN
;
6987 if ((vsi
->current_isup
== isup
) && (vsi
->current_speed
== new_speed
))
6989 vsi
->current_isup
= isup
;
6990 vsi
->current_speed
= new_speed
;
6992 netdev_info(vsi
->netdev
, "NIC Link is Down\n");
6996 /* Warn user if link speed on NPAR enabled partition is not at
6999 if (pf
->hw
.func_caps
.npar_enable
&&
7000 (pf
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_1GB
||
7001 pf
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_100MB
))
7002 netdev_warn(vsi
->netdev
,
7003 "The partition detected link speed that is less than 10Gbps\n");
7005 switch (pf
->hw
.phy
.link_info
.link_speed
) {
7006 case I40E_LINK_SPEED_40GB
:
7009 case I40E_LINK_SPEED_20GB
:
7012 case I40E_LINK_SPEED_25GB
:
7015 case I40E_LINK_SPEED_10GB
:
7018 case I40E_LINK_SPEED_5GB
:
7021 case I40E_LINK_SPEED_2_5GB
:
7024 case I40E_LINK_SPEED_1GB
:
7027 case I40E_LINK_SPEED_100MB
:
7034 switch (pf
->hw
.fc
.current_mode
) {
7038 case I40E_FC_TX_PAUSE
:
7041 case I40E_FC_RX_PAUSE
:
7049 if (pf
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_25GB
) {
7054 if (pf
->hw
.phy
.link_info
.an_info
& I40E_AQ_AN_COMPLETED
)
7057 if (pf
->hw
.phy
.link_info
.fec_info
&
7058 I40E_AQ_CONFIG_FEC_KR_ENA
)
7059 fec
= "CL74 FC-FEC/BASE-R";
7060 else if (pf
->hw
.phy
.link_info
.fec_info
&
7061 I40E_AQ_CONFIG_FEC_RS_ENA
)
7062 fec
= "CL108 RS-FEC";
7064 /* 'CL108 RS-FEC' should be displayed when RS is requested, or
7065 * both RS and FC are requested
7067 if (vsi
->back
->hw
.phy
.link_info
.req_fec_info
&
7068 (I40E_AQ_REQUEST_FEC_KR
| I40E_AQ_REQUEST_FEC_RS
)) {
7069 if (vsi
->back
->hw
.phy
.link_info
.req_fec_info
&
7070 I40E_AQ_REQUEST_FEC_RS
)
7071 req_fec
= "CL108 RS-FEC";
7073 req_fec
= "CL74 FC-FEC/BASE-R";
7075 netdev_info(vsi
->netdev
,
7076 "NIC Link is Up, %sbps Full Duplex, Requested FEC: %s, Negotiated FEC: %s, Autoneg: %s, Flow Control: %s\n",
7077 speed
, req_fec
, fec
, an
, fc
);
7078 } else if (pf
->hw
.device_id
== I40E_DEV_ID_KX_X722
) {
7083 if (pf
->hw
.phy
.link_info
.an_info
& I40E_AQ_AN_COMPLETED
)
7086 if (pf
->hw
.phy
.link_info
.fec_info
&
7087 I40E_AQ_CONFIG_FEC_KR_ENA
)
7088 fec
= "CL74 FC-FEC/BASE-R";
7090 if (pf
->hw
.phy
.link_info
.req_fec_info
&
7091 I40E_AQ_REQUEST_FEC_KR
)
7092 req_fec
= "CL74 FC-FEC/BASE-R";
7094 netdev_info(vsi
->netdev
,
7095 "NIC Link is Up, %sbps Full Duplex, Requested FEC: %s, Negotiated FEC: %s, Autoneg: %s, Flow Control: %s\n",
7096 speed
, req_fec
, fec
, an
, fc
);
7098 netdev_info(vsi
->netdev
,
7099 "NIC Link is Up, %sbps Full Duplex, Flow Control: %s\n",
7106 * i40e_up_complete - Finish the last steps of bringing up a connection
7107 * @vsi: the VSI being configured
7109 static int i40e_up_complete(struct i40e_vsi
*vsi
)
7111 struct i40e_pf
*pf
= vsi
->back
;
7114 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
7115 i40e_vsi_configure_msix(vsi
);
7117 i40e_configure_msi_and_legacy(vsi
);
7120 err
= i40e_vsi_start_rings(vsi
);
7124 clear_bit(__I40E_VSI_DOWN
, vsi
->state
);
7125 i40e_napi_enable_all(vsi
);
7126 i40e_vsi_enable_irq(vsi
);
7128 if ((pf
->hw
.phy
.link_info
.link_info
& I40E_AQ_LINK_UP
) &&
7130 i40e_print_link_message(vsi
, true);
7131 netif_tx_start_all_queues(vsi
->netdev
);
7132 netif_carrier_on(vsi
->netdev
);
7135 /* replay FDIR SB filters */
7136 if (vsi
->type
== I40E_VSI_FDIR
) {
7137 /* reset fd counters */
7140 i40e_fdir_filter_restore(vsi
);
7143 /* On the next run of the service_task, notify any clients of the new
7146 set_bit(__I40E_CLIENT_SERVICE_REQUESTED
, pf
->state
);
7147 i40e_service_event_schedule(pf
);
7153 * i40e_vsi_reinit_locked - Reset the VSI
7154 * @vsi: the VSI being configured
7156 * Rebuild the ring structs after some configuration
7157 * has changed, e.g. MTU size.
7159 static void i40e_vsi_reinit_locked(struct i40e_vsi
*vsi
)
7161 struct i40e_pf
*pf
= vsi
->back
;
7163 while (test_and_set_bit(__I40E_CONFIG_BUSY
, pf
->state
))
7164 usleep_range(1000, 2000);
7168 clear_bit(__I40E_CONFIG_BUSY
, pf
->state
);
7172 * i40e_force_link_state - Force the link status
7173 * @pf: board private structure
7174 * @is_up: whether the link state should be forced up or down
7176 static i40e_status
i40e_force_link_state(struct i40e_pf
*pf
, bool is_up
)
7178 struct i40e_aq_get_phy_abilities_resp abilities
;
7179 struct i40e_aq_set_phy_config config
= {0};
7180 bool non_zero_phy_type
= is_up
;
7181 struct i40e_hw
*hw
= &pf
->hw
;
7186 /* Card might've been put in an unstable state by other drivers
7187 * and applications, which causes incorrect speed values being
7188 * set on startup. In order to clear speed registers, we call
7189 * get_phy_capabilities twice, once to get initial state of
7190 * available speeds, and once to get current PHY config.
7192 err
= i40e_aq_get_phy_capabilities(hw
, false, true, &abilities
,
7195 dev_err(&pf
->pdev
->dev
,
7196 "failed to get phy cap., ret = %s last_status = %s\n",
7197 i40e_stat_str(hw
, err
),
7198 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
7201 speed
= abilities
.link_speed
;
7203 /* Get the current phy config */
7204 err
= i40e_aq_get_phy_capabilities(hw
, false, false, &abilities
,
7207 dev_err(&pf
->pdev
->dev
,
7208 "failed to get phy cap., ret = %s last_status = %s\n",
7209 i40e_stat_str(hw
, err
),
7210 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
7214 /* If link needs to go up, but was not forced to go down,
7215 * and its speed values are OK, no need for a flap
7216 * if non_zero_phy_type was set, still need to force up
7218 if (pf
->flags
& I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENABLED
)
7219 non_zero_phy_type
= true;
7220 else if (is_up
&& abilities
.phy_type
!= 0 && abilities
.link_speed
!= 0)
7221 return I40E_SUCCESS
;
7223 /* To force link we need to set bits for all supported PHY types,
7224 * but there are now more than 32, so we need to split the bitmap
7225 * across two fields.
7227 mask
= I40E_PHY_TYPES_BITMASK
;
7229 non_zero_phy_type
? cpu_to_le32((u32
)(mask
& 0xffffffff)) : 0;
7230 config
.phy_type_ext
=
7231 non_zero_phy_type
? (u8
)((mask
>> 32) & 0xff) : 0;
7232 /* Copy the old settings, except of phy_type */
7233 config
.abilities
= abilities
.abilities
;
7234 if (pf
->flags
& I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENABLED
) {
7236 config
.abilities
|= I40E_AQ_PHY_ENABLE_LINK
;
7238 config
.abilities
&= ~(I40E_AQ_PHY_ENABLE_LINK
);
7240 if (abilities
.link_speed
!= 0)
7241 config
.link_speed
= abilities
.link_speed
;
7243 config
.link_speed
= speed
;
7244 config
.eee_capability
= abilities
.eee_capability
;
7245 config
.eeer
= abilities
.eeer_val
;
7246 config
.low_power_ctrl
= abilities
.d3_lpan
;
7247 config
.fec_config
= abilities
.fec_cfg_curr_mod_ext_info
&
7248 I40E_AQ_PHY_FEC_CONFIG_MASK
;
7249 err
= i40e_aq_set_phy_config(hw
, &config
, NULL
);
7252 dev_err(&pf
->pdev
->dev
,
7253 "set phy config ret = %s last_status = %s\n",
7254 i40e_stat_str(&pf
->hw
, err
),
7255 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
7259 /* Update the link info */
7260 err
= i40e_update_link_info(hw
);
7262 /* Wait a little bit (on 40G cards it sometimes takes a really
7263 * long time for link to come back from the atomic reset)
7267 i40e_update_link_info(hw
);
7270 i40e_aq_set_link_restart_an(hw
, is_up
, NULL
);
7272 return I40E_SUCCESS
;
7276 * i40e_up - Bring the connection back up after being down
7277 * @vsi: the VSI being configured
7279 int i40e_up(struct i40e_vsi
*vsi
)
7283 if (vsi
->type
== I40E_VSI_MAIN
&&
7284 (vsi
->back
->flags
& I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED
||
7285 vsi
->back
->flags
& I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENABLED
))
7286 i40e_force_link_state(vsi
->back
, true);
7288 err
= i40e_vsi_configure(vsi
);
7290 err
= i40e_up_complete(vsi
);
7296 * i40e_down - Shutdown the connection processing
7297 * @vsi: the VSI being stopped
7299 void i40e_down(struct i40e_vsi
*vsi
)
7303 /* It is assumed that the caller of this function
7304 * sets the vsi->state __I40E_VSI_DOWN bit.
7307 netif_carrier_off(vsi
->netdev
);
7308 netif_tx_disable(vsi
->netdev
);
7310 i40e_vsi_disable_irq(vsi
);
7311 i40e_vsi_stop_rings(vsi
);
7312 if (vsi
->type
== I40E_VSI_MAIN
&&
7313 (vsi
->back
->flags
& I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED
||
7314 vsi
->back
->flags
& I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENABLED
))
7315 i40e_force_link_state(vsi
->back
, false);
7316 i40e_napi_disable_all(vsi
);
7318 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
7319 i40e_clean_tx_ring(vsi
->tx_rings
[i
]);
7320 if (i40e_enabled_xdp_vsi(vsi
)) {
7321 /* Make sure that in-progress ndo_xdp_xmit and
7322 * ndo_xsk_wakeup calls are completed.
7325 i40e_clean_tx_ring(vsi
->xdp_rings
[i
]);
7327 i40e_clean_rx_ring(vsi
->rx_rings
[i
]);
7333 * i40e_validate_mqprio_qopt- validate queue mapping info
7334 * @vsi: the VSI being configured
7335 * @mqprio_qopt: queue parametrs
7337 static int i40e_validate_mqprio_qopt(struct i40e_vsi
*vsi
,
7338 struct tc_mqprio_qopt_offload
*mqprio_qopt
)
7340 u64 sum_max_rate
= 0;
7344 if (mqprio_qopt
->qopt
.offset
[0] != 0 ||
7345 mqprio_qopt
->qopt
.num_tc
< 1 ||
7346 mqprio_qopt
->qopt
.num_tc
> I40E_MAX_TRAFFIC_CLASS
)
7348 for (i
= 0; ; i
++) {
7349 if (!mqprio_qopt
->qopt
.count
[i
])
7351 if (mqprio_qopt
->min_rate
[i
]) {
7352 dev_err(&vsi
->back
->pdev
->dev
,
7353 "Invalid min tx rate (greater than 0) specified\n");
7356 max_rate
= mqprio_qopt
->max_rate
[i
];
7357 do_div(max_rate
, I40E_BW_MBPS_DIVISOR
);
7358 sum_max_rate
+= max_rate
;
7360 if (i
>= mqprio_qopt
->qopt
.num_tc
- 1)
7362 if (mqprio_qopt
->qopt
.offset
[i
+ 1] !=
7363 (mqprio_qopt
->qopt
.offset
[i
] + mqprio_qopt
->qopt
.count
[i
]))
7366 if (vsi
->num_queue_pairs
<
7367 (mqprio_qopt
->qopt
.offset
[i
] + mqprio_qopt
->qopt
.count
[i
])) {
7368 dev_err(&vsi
->back
->pdev
->dev
,
7369 "Failed to create traffic channel, insufficient number of queues.\n");
7372 if (sum_max_rate
> i40e_get_link_speed(vsi
)) {
7373 dev_err(&vsi
->back
->pdev
->dev
,
7374 "Invalid max tx rate specified\n");
7381 * i40e_vsi_set_default_tc_config - set default values for tc configuration
7382 * @vsi: the VSI being configured
7384 static void i40e_vsi_set_default_tc_config(struct i40e_vsi
*vsi
)
7389 /* Only TC0 is enabled */
7390 vsi
->tc_config
.numtc
= 1;
7391 vsi
->tc_config
.enabled_tc
= 1;
7392 qcount
= min_t(int, vsi
->alloc_queue_pairs
,
7393 i40e_pf_get_max_q_per_tc(vsi
->back
));
7394 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
7395 /* For the TC that is not enabled set the offset to default
7396 * queue and allocate one queue for the given TC.
7398 vsi
->tc_config
.tc_info
[i
].qoffset
= 0;
7400 vsi
->tc_config
.tc_info
[i
].qcount
= qcount
;
7402 vsi
->tc_config
.tc_info
[i
].qcount
= 1;
7403 vsi
->tc_config
.tc_info
[i
].netdev_tc
= 0;
7408 * i40e_del_macvlan_filter
7409 * @hw: pointer to the HW structure
7410 * @seid: seid of the channel VSI
7411 * @macaddr: the mac address to apply as a filter
7412 * @aq_err: store the admin Q error
7414 * This function deletes a mac filter on the channel VSI which serves as the
7415 * macvlan. Returns 0 on success.
7417 static i40e_status
i40e_del_macvlan_filter(struct i40e_hw
*hw
, u16 seid
,
7418 const u8
*macaddr
, int *aq_err
)
7420 struct i40e_aqc_remove_macvlan_element_data element
;
7423 memset(&element
, 0, sizeof(element
));
7424 ether_addr_copy(element
.mac_addr
, macaddr
);
7425 element
.vlan_tag
= 0;
7426 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
7427 status
= i40e_aq_remove_macvlan(hw
, seid
, &element
, 1, NULL
);
7428 *aq_err
= hw
->aq
.asq_last_status
;
7434 * i40e_add_macvlan_filter
7435 * @hw: pointer to the HW structure
7436 * @seid: seid of the channel VSI
7437 * @macaddr: the mac address to apply as a filter
7438 * @aq_err: store the admin Q error
7440 * This function adds a mac filter on the channel VSI which serves as the
7441 * macvlan. Returns 0 on success.
7443 static i40e_status
i40e_add_macvlan_filter(struct i40e_hw
*hw
, u16 seid
,
7444 const u8
*macaddr
, int *aq_err
)
7446 struct i40e_aqc_add_macvlan_element_data element
;
7450 ether_addr_copy(element
.mac_addr
, macaddr
);
7451 element
.vlan_tag
= 0;
7452 element
.queue_number
= 0;
7453 element
.match_method
= I40E_AQC_MM_ERR_NO_RES
;
7454 cmd_flags
|= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
;
7455 element
.flags
= cpu_to_le16(cmd_flags
);
7456 status
= i40e_aq_add_macvlan(hw
, seid
, &element
, 1, NULL
);
7457 *aq_err
= hw
->aq
.asq_last_status
;
7463 * i40e_reset_ch_rings - Reset the queue contexts in a channel
7464 * @vsi: the VSI we want to access
7465 * @ch: the channel we want to access
7467 static void i40e_reset_ch_rings(struct i40e_vsi
*vsi
, struct i40e_channel
*ch
)
7469 struct i40e_ring
*tx_ring
, *rx_ring
;
7473 for (i
= 0; i
< ch
->num_queue_pairs
; i
++) {
7474 pf_q
= ch
->base_queue
+ i
;
7475 tx_ring
= vsi
->tx_rings
[pf_q
];
7477 rx_ring
= vsi
->rx_rings
[pf_q
];
7483 * i40e_free_macvlan_channels
7484 * @vsi: the VSI we want to access
7486 * This function frees the Qs of the channel VSI from
7487 * the stack and also deletes the channel VSIs which
7488 * serve as macvlans.
7490 static void i40e_free_macvlan_channels(struct i40e_vsi
*vsi
)
7492 struct i40e_channel
*ch
, *ch_tmp
;
7495 if (list_empty(&vsi
->macvlan_list
))
7498 list_for_each_entry_safe(ch
, ch_tmp
, &vsi
->macvlan_list
, list
) {
7499 struct i40e_vsi
*parent_vsi
;
7501 if (i40e_is_channel_macvlan(ch
)) {
7502 i40e_reset_ch_rings(vsi
, ch
);
7503 clear_bit(ch
->fwd
->bit_no
, vsi
->fwd_bitmask
);
7504 netdev_unbind_sb_channel(vsi
->netdev
, ch
->fwd
->netdev
);
7505 netdev_set_sb_channel(ch
->fwd
->netdev
, 0);
7510 list_del(&ch
->list
);
7511 parent_vsi
= ch
->parent_vsi
;
7512 if (!parent_vsi
|| !ch
->initialized
) {
7517 /* remove the VSI */
7518 ret
= i40e_aq_delete_element(&vsi
->back
->hw
, ch
->seid
,
7521 dev_err(&vsi
->back
->pdev
->dev
,
7522 "unable to remove channel (%d) for parent VSI(%d)\n",
7523 ch
->seid
, parent_vsi
->seid
);
7526 vsi
->macvlan_cnt
= 0;
7530 * i40e_fwd_ring_up - bring the macvlan device up
7531 * @vsi: the VSI we want to access
7532 * @vdev: macvlan netdevice
7533 * @fwd: the private fwd structure
7535 static int i40e_fwd_ring_up(struct i40e_vsi
*vsi
, struct net_device
*vdev
,
7536 struct i40e_fwd_adapter
*fwd
)
7538 int ret
= 0, num_tc
= 1, i
, aq_err
;
7539 struct i40e_channel
*ch
, *ch_tmp
;
7540 struct i40e_pf
*pf
= vsi
->back
;
7541 struct i40e_hw
*hw
= &pf
->hw
;
7543 if (list_empty(&vsi
->macvlan_list
))
7546 /* Go through the list and find an available channel */
7547 list_for_each_entry_safe(ch
, ch_tmp
, &vsi
->macvlan_list
, list
) {
7548 if (!i40e_is_channel_macvlan(ch
)) {
7550 /* record configuration for macvlan interface in vdev */
7551 for (i
= 0; i
< num_tc
; i
++)
7552 netdev_bind_sb_channel_queue(vsi
->netdev
, vdev
,
7554 ch
->num_queue_pairs
,
7556 for (i
= 0; i
< ch
->num_queue_pairs
; i
++) {
7557 struct i40e_ring
*tx_ring
, *rx_ring
;
7560 pf_q
= ch
->base_queue
+ i
;
7562 /* Get to TX ring ptr */
7563 tx_ring
= vsi
->tx_rings
[pf_q
];
7566 /* Get the RX ring ptr */
7567 rx_ring
= vsi
->rx_rings
[pf_q
];
7574 /* Guarantee all rings are updated before we update the
7575 * MAC address filter.
7579 /* Add a mac filter */
7580 ret
= i40e_add_macvlan_filter(hw
, ch
->seid
, vdev
->dev_addr
, &aq_err
);
7582 /* if we cannot add the MAC rule then disable the offload */
7583 macvlan_release_l2fw_offload(vdev
);
7584 for (i
= 0; i
< ch
->num_queue_pairs
; i
++) {
7585 struct i40e_ring
*rx_ring
;
7588 pf_q
= ch
->base_queue
+ i
;
7589 rx_ring
= vsi
->rx_rings
[pf_q
];
7590 rx_ring
->netdev
= NULL
;
7592 dev_info(&pf
->pdev
->dev
,
7593 "Error adding mac filter on macvlan err %s, aq_err %s\n",
7594 i40e_stat_str(hw
, ret
),
7595 i40e_aq_str(hw
, aq_err
));
7596 netdev_err(vdev
, "L2fwd offload disabled to L2 filter error\n");
7603 * i40e_setup_macvlans - create the channels which will be macvlans
7604 * @vsi: the VSI we want to access
7605 * @macvlan_cnt: no. of macvlans to be setup
7606 * @qcnt: no. of Qs per macvlan
7607 * @vdev: macvlan netdevice
7609 static int i40e_setup_macvlans(struct i40e_vsi
*vsi
, u16 macvlan_cnt
, u16 qcnt
,
7610 struct net_device
*vdev
)
7612 struct i40e_pf
*pf
= vsi
->back
;
7613 struct i40e_hw
*hw
= &pf
->hw
;
7614 struct i40e_vsi_context ctxt
;
7615 u16 sections
, qmap
, num_qps
;
7616 struct i40e_channel
*ch
;
7617 int i
, pow
, ret
= 0;
7620 if (vsi
->type
!= I40E_VSI_MAIN
|| !macvlan_cnt
)
7623 num_qps
= vsi
->num_queue_pairs
- (macvlan_cnt
* qcnt
);
7625 /* find the next higher power-of-2 of num queue pairs */
7626 pow
= fls(roundup_pow_of_two(num_qps
) - 1);
7628 qmap
= (offset
<< I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT
) |
7629 (pow
<< I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT
);
7631 /* Setup context bits for the main VSI */
7632 sections
= I40E_AQ_VSI_PROP_QUEUE_MAP_VALID
;
7633 sections
|= I40E_AQ_VSI_PROP_SCHED_VALID
;
7634 memset(&ctxt
, 0, sizeof(ctxt
));
7635 ctxt
.seid
= vsi
->seid
;
7636 ctxt
.pf_num
= vsi
->back
->hw
.pf_id
;
7638 ctxt
.uplink_seid
= vsi
->uplink_seid
;
7639 ctxt
.info
= vsi
->info
;
7640 ctxt
.info
.tc_mapping
[0] = cpu_to_le16(qmap
);
7641 ctxt
.info
.mapping_flags
|= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG
);
7642 ctxt
.info
.queue_mapping
[0] = cpu_to_le16(vsi
->base_queue
);
7643 ctxt
.info
.valid_sections
|= cpu_to_le16(sections
);
7645 /* Reconfigure RSS for main VSI with new max queue count */
7646 vsi
->rss_size
= max_t(u16
, num_qps
, qcnt
);
7647 ret
= i40e_vsi_config_rss(vsi
);
7649 dev_info(&pf
->pdev
->dev
,
7650 "Failed to reconfig RSS for num_queues (%u)\n",
7654 vsi
->reconfig_rss
= true;
7655 dev_dbg(&vsi
->back
->pdev
->dev
,
7656 "Reconfigured RSS with num_queues (%u)\n", vsi
->rss_size
);
7657 vsi
->next_base_queue
= num_qps
;
7658 vsi
->cnt_q_avail
= vsi
->num_queue_pairs
- num_qps
;
7660 /* Update the VSI after updating the VSI queue-mapping
7663 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
7665 dev_info(&pf
->pdev
->dev
,
7666 "Update vsi tc config failed, err %s aq_err %s\n",
7667 i40e_stat_str(hw
, ret
),
7668 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
7671 /* update the local VSI info with updated queue map */
7672 i40e_vsi_update_queue_map(vsi
, &ctxt
);
7673 vsi
->info
.valid_sections
= 0;
7675 /* Create channels for macvlans */
7676 INIT_LIST_HEAD(&vsi
->macvlan_list
);
7677 for (i
= 0; i
< macvlan_cnt
; i
++) {
7678 ch
= kzalloc(sizeof(*ch
), GFP_KERNEL
);
7683 INIT_LIST_HEAD(&ch
->list
);
7684 ch
->num_queue_pairs
= qcnt
;
7685 if (!i40e_setup_channel(pf
, vsi
, ch
)) {
7690 ch
->parent_vsi
= vsi
;
7691 vsi
->cnt_q_avail
-= ch
->num_queue_pairs
;
7693 list_add_tail(&ch
->list
, &vsi
->macvlan_list
);
7699 dev_info(&pf
->pdev
->dev
, "Failed to setup macvlans\n");
7700 i40e_free_macvlan_channels(vsi
);
7706 * i40e_fwd_add - configure macvlans
7707 * @netdev: net device to configure
7708 * @vdev: macvlan netdevice
7710 static void *i40e_fwd_add(struct net_device
*netdev
, struct net_device
*vdev
)
7712 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7713 u16 q_per_macvlan
= 0, macvlan_cnt
= 0, vectors
;
7714 struct i40e_vsi
*vsi
= np
->vsi
;
7715 struct i40e_pf
*pf
= vsi
->back
;
7716 struct i40e_fwd_adapter
*fwd
;
7717 int avail_macvlan
, ret
;
7719 if ((pf
->flags
& I40E_FLAG_DCB_ENABLED
)) {
7720 netdev_info(netdev
, "Macvlans are not supported when DCB is enabled\n");
7721 return ERR_PTR(-EINVAL
);
7723 if ((pf
->flags
& I40E_FLAG_TC_MQPRIO
)) {
7724 netdev_info(netdev
, "Macvlans are not supported when HW TC offload is on\n");
7725 return ERR_PTR(-EINVAL
);
7727 if (pf
->num_lan_msix
< I40E_MIN_MACVLAN_VECTORS
) {
7728 netdev_info(netdev
, "Not enough vectors available to support macvlans\n");
7729 return ERR_PTR(-EINVAL
);
7732 /* The macvlan device has to be a single Q device so that the
7733 * tc_to_txq field can be reused to pick the tx queue.
7735 if (netif_is_multiqueue(vdev
))
7736 return ERR_PTR(-ERANGE
);
7738 if (!vsi
->macvlan_cnt
) {
7739 /* reserve bit 0 for the pf device */
7740 set_bit(0, vsi
->fwd_bitmask
);
7742 /* Try to reserve as many queues as possible for macvlans. First
7743 * reserve 3/4th of max vectors, then half, then quarter and
7744 * calculate Qs per macvlan as you go
7746 vectors
= pf
->num_lan_msix
;
7747 if (vectors
<= I40E_MAX_MACVLANS
&& vectors
> 64) {
7748 /* allocate 4 Qs per macvlan and 32 Qs to the PF*/
7750 macvlan_cnt
= (vectors
- 32) / 4;
7751 } else if (vectors
<= 64 && vectors
> 32) {
7752 /* allocate 2 Qs per macvlan and 16 Qs to the PF*/
7754 macvlan_cnt
= (vectors
- 16) / 2;
7755 } else if (vectors
<= 32 && vectors
> 16) {
7756 /* allocate 1 Q per macvlan and 16 Qs to the PF*/
7758 macvlan_cnt
= vectors
- 16;
7759 } else if (vectors
<= 16 && vectors
> 8) {
7760 /* allocate 1 Q per macvlan and 8 Qs to the PF */
7762 macvlan_cnt
= vectors
- 8;
7764 /* allocate 1 Q per macvlan and 1 Q to the PF */
7766 macvlan_cnt
= vectors
- 1;
7769 if (macvlan_cnt
== 0)
7770 return ERR_PTR(-EBUSY
);
7772 /* Quiesce VSI queues */
7773 i40e_quiesce_vsi(vsi
);
7775 /* sets up the macvlans but does not "enable" them */
7776 ret
= i40e_setup_macvlans(vsi
, macvlan_cnt
, q_per_macvlan
,
7779 return ERR_PTR(ret
);
7782 i40e_unquiesce_vsi(vsi
);
7784 avail_macvlan
= find_first_zero_bit(vsi
->fwd_bitmask
,
7786 if (avail_macvlan
>= I40E_MAX_MACVLANS
)
7787 return ERR_PTR(-EBUSY
);
7789 /* create the fwd struct */
7790 fwd
= kzalloc(sizeof(*fwd
), GFP_KERNEL
);
7792 return ERR_PTR(-ENOMEM
);
7794 set_bit(avail_macvlan
, vsi
->fwd_bitmask
);
7795 fwd
->bit_no
= avail_macvlan
;
7796 netdev_set_sb_channel(vdev
, avail_macvlan
);
7799 if (!netif_running(netdev
))
7802 /* Set fwd ring up */
7803 ret
= i40e_fwd_ring_up(vsi
, vdev
, fwd
);
7805 /* unbind the queues and drop the subordinate channel config */
7806 netdev_unbind_sb_channel(netdev
, vdev
);
7807 netdev_set_sb_channel(vdev
, 0);
7810 return ERR_PTR(-EINVAL
);
7817 * i40e_del_all_macvlans - Delete all the mac filters on the channels
7818 * @vsi: the VSI we want to access
7820 static void i40e_del_all_macvlans(struct i40e_vsi
*vsi
)
7822 struct i40e_channel
*ch
, *ch_tmp
;
7823 struct i40e_pf
*pf
= vsi
->back
;
7824 struct i40e_hw
*hw
= &pf
->hw
;
7825 int aq_err
, ret
= 0;
7827 if (list_empty(&vsi
->macvlan_list
))
7830 list_for_each_entry_safe(ch
, ch_tmp
, &vsi
->macvlan_list
, list
) {
7831 if (i40e_is_channel_macvlan(ch
)) {
7832 ret
= i40e_del_macvlan_filter(hw
, ch
->seid
,
7833 i40e_channel_mac(ch
),
7836 /* Reset queue contexts */
7837 i40e_reset_ch_rings(vsi
, ch
);
7838 clear_bit(ch
->fwd
->bit_no
, vsi
->fwd_bitmask
);
7839 netdev_unbind_sb_channel(vsi
->netdev
,
7841 netdev_set_sb_channel(ch
->fwd
->netdev
, 0);
7850 * i40e_fwd_del - delete macvlan interfaces
7851 * @netdev: net device to configure
7852 * @vdev: macvlan netdevice
7854 static void i40e_fwd_del(struct net_device
*netdev
, void *vdev
)
7856 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7857 struct i40e_fwd_adapter
*fwd
= vdev
;
7858 struct i40e_channel
*ch
, *ch_tmp
;
7859 struct i40e_vsi
*vsi
= np
->vsi
;
7860 struct i40e_pf
*pf
= vsi
->back
;
7861 struct i40e_hw
*hw
= &pf
->hw
;
7862 int aq_err
, ret
= 0;
7864 /* Find the channel associated with the macvlan and del mac filter */
7865 list_for_each_entry_safe(ch
, ch_tmp
, &vsi
->macvlan_list
, list
) {
7866 if (i40e_is_channel_macvlan(ch
) &&
7867 ether_addr_equal(i40e_channel_mac(ch
),
7868 fwd
->netdev
->dev_addr
)) {
7869 ret
= i40e_del_macvlan_filter(hw
, ch
->seid
,
7870 i40e_channel_mac(ch
),
7873 /* Reset queue contexts */
7874 i40e_reset_ch_rings(vsi
, ch
);
7875 clear_bit(ch
->fwd
->bit_no
, vsi
->fwd_bitmask
);
7876 netdev_unbind_sb_channel(netdev
, fwd
->netdev
);
7877 netdev_set_sb_channel(fwd
->netdev
, 0);
7881 dev_info(&pf
->pdev
->dev
,
7882 "Error deleting mac filter on macvlan err %s, aq_err %s\n",
7883 i40e_stat_str(hw
, ret
),
7884 i40e_aq_str(hw
, aq_err
));
7892 * i40e_setup_tc - configure multiple traffic classes
7893 * @netdev: net device to configure
7894 * @type_data: tc offload data
7896 static int i40e_setup_tc(struct net_device
*netdev
, void *type_data
)
7898 struct tc_mqprio_qopt_offload
*mqprio_qopt
= type_data
;
7899 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7900 struct i40e_vsi
*vsi
= np
->vsi
;
7901 struct i40e_pf
*pf
= vsi
->back
;
7902 u8 enabled_tc
= 0, num_tc
, hw
;
7903 bool need_reset
= false;
7904 int old_queue_pairs
;
7909 old_queue_pairs
= vsi
->num_queue_pairs
;
7910 num_tc
= mqprio_qopt
->qopt
.num_tc
;
7911 hw
= mqprio_qopt
->qopt
.hw
;
7912 mode
= mqprio_qopt
->mode
;
7914 pf
->flags
&= ~I40E_FLAG_TC_MQPRIO
;
7915 memcpy(&vsi
->mqprio_qopt
, mqprio_qopt
, sizeof(*mqprio_qopt
));
7919 /* Check if MFP enabled */
7920 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
7922 "Configuring TC not supported in MFP mode\n");
7926 case TC_MQPRIO_MODE_DCB
:
7927 pf
->flags
&= ~I40E_FLAG_TC_MQPRIO
;
7929 /* Check if DCB enabled to continue */
7930 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
)) {
7932 "DCB is not enabled for adapter\n");
7936 /* Check whether tc count is within enabled limit */
7937 if (num_tc
> i40e_pf_get_num_tc(pf
)) {
7939 "TC count greater than enabled on link for adapter\n");
7943 case TC_MQPRIO_MODE_CHANNEL
:
7944 if (pf
->flags
& I40E_FLAG_DCB_ENABLED
) {
7946 "Full offload of TC Mqprio options is not supported when DCB is enabled\n");
7949 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
7951 ret
= i40e_validate_mqprio_qopt(vsi
, mqprio_qopt
);
7954 memcpy(&vsi
->mqprio_qopt
, mqprio_qopt
,
7955 sizeof(*mqprio_qopt
));
7956 pf
->flags
|= I40E_FLAG_TC_MQPRIO
;
7957 pf
->flags
&= ~I40E_FLAG_DCB_ENABLED
;
7964 /* Generate TC map for number of tc requested */
7965 for (i
= 0; i
< num_tc
; i
++)
7966 enabled_tc
|= BIT(i
);
7968 /* Requesting same TC configuration as already enabled */
7969 if (enabled_tc
== vsi
->tc_config
.enabled_tc
&&
7970 mode
!= TC_MQPRIO_MODE_CHANNEL
)
7973 /* Quiesce VSI queues */
7974 i40e_quiesce_vsi(vsi
);
7976 if (!hw
&& !(pf
->flags
& I40E_FLAG_TC_MQPRIO
))
7977 i40e_remove_queue_channels(vsi
);
7979 /* Configure VSI for enabled TCs */
7980 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
7982 netdev_info(netdev
, "Failed configuring TC for VSI seid=%d\n",
7986 } else if (enabled_tc
&&
7987 (!is_power_of_2(vsi
->tc_config
.tc_info
[0].qcount
))) {
7989 "Failed to create channel. Override queues (%u) not power of 2\n",
7990 vsi
->tc_config
.tc_info
[0].qcount
);
7996 dev_info(&vsi
->back
->pdev
->dev
,
7997 "Setup channel (id:%u) utilizing num_queues %d\n",
7998 vsi
->seid
, vsi
->tc_config
.tc_info
[0].qcount
);
8000 if (pf
->flags
& I40E_FLAG_TC_MQPRIO
) {
8001 if (vsi
->mqprio_qopt
.max_rate
[0]) {
8002 u64 max_tx_rate
= vsi
->mqprio_qopt
.max_rate
[0];
8004 do_div(max_tx_rate
, I40E_BW_MBPS_DIVISOR
);
8005 ret
= i40e_set_bw_limit(vsi
, vsi
->seid
, max_tx_rate
);
8007 u64 credits
= max_tx_rate
;
8009 do_div(credits
, I40E_BW_CREDIT_DIVISOR
);
8010 dev_dbg(&vsi
->back
->pdev
->dev
,
8011 "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
8020 ret
= i40e_configure_queue_channels(vsi
);
8022 vsi
->num_queue_pairs
= old_queue_pairs
;
8024 "Failed configuring queue channels\n");
8031 /* Reset the configuration data to defaults, only TC0 is enabled */
8033 i40e_vsi_set_default_tc_config(vsi
);
8038 i40e_unquiesce_vsi(vsi
);
8043 * i40e_set_cld_element - sets cloud filter element data
8044 * @filter: cloud filter rule
8045 * @cld: ptr to cloud filter element data
8047 * This is helper function to copy data into cloud filter element
8050 i40e_set_cld_element(struct i40e_cloud_filter
*filter
,
8051 struct i40e_aqc_cloud_filters_element_data
*cld
)
8056 memset(cld
, 0, sizeof(*cld
));
8057 ether_addr_copy(cld
->outer_mac
, filter
->dst_mac
);
8058 ether_addr_copy(cld
->inner_mac
, filter
->src_mac
);
8060 if (filter
->n_proto
!= ETH_P_IP
&& filter
->n_proto
!= ETH_P_IPV6
)
8063 if (filter
->n_proto
== ETH_P_IPV6
) {
8064 #define IPV6_MAX_INDEX (ARRAY_SIZE(filter->dst_ipv6) - 1)
8065 for (i
= 0; i
< ARRAY_SIZE(filter
->dst_ipv6
); i
++) {
8066 ipa
= be32_to_cpu(filter
->dst_ipv6
[IPV6_MAX_INDEX
- i
]);
8068 *(__le32
*)&cld
->ipaddr
.raw_v6
.data
[i
* 2] = cpu_to_le32(ipa
);
8071 ipa
= be32_to_cpu(filter
->dst_ipv4
);
8073 memcpy(&cld
->ipaddr
.v4
.data
, &ipa
, sizeof(ipa
));
8076 cld
->inner_vlan
= cpu_to_le16(ntohs(filter
->vlan_id
));
8078 /* tenant_id is not supported by FW now, once the support is enabled
8079 * fill the cld->tenant_id with cpu_to_le32(filter->tenant_id)
8081 if (filter
->tenant_id
)
8086 * i40e_add_del_cloud_filter - Add/del cloud filter
8087 * @vsi: pointer to VSI
8088 * @filter: cloud filter rule
8089 * @add: if true, add, if false, delete
8091 * Add or delete a cloud filter for a specific flow spec.
8092 * Returns 0 if the filter were successfully added.
8094 int i40e_add_del_cloud_filter(struct i40e_vsi
*vsi
,
8095 struct i40e_cloud_filter
*filter
, bool add
)
8097 struct i40e_aqc_cloud_filters_element_data cld_filter
;
8098 struct i40e_pf
*pf
= vsi
->back
;
8100 static const u16 flag_table
[128] = {
8101 [I40E_CLOUD_FILTER_FLAGS_OMAC
] =
8102 I40E_AQC_ADD_CLOUD_FILTER_OMAC
,
8103 [I40E_CLOUD_FILTER_FLAGS_IMAC
] =
8104 I40E_AQC_ADD_CLOUD_FILTER_IMAC
,
8105 [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN
] =
8106 I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN
,
8107 [I40E_CLOUD_FILTER_FLAGS_IMAC_TEN_ID
] =
8108 I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID
,
8109 [I40E_CLOUD_FILTER_FLAGS_OMAC_TEN_ID_IMAC
] =
8110 I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC
,
8111 [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN_TEN_ID
] =
8112 I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID
,
8113 [I40E_CLOUD_FILTER_FLAGS_IIP
] =
8114 I40E_AQC_ADD_CLOUD_FILTER_IIP
,
8117 if (filter
->flags
>= ARRAY_SIZE(flag_table
))
8118 return I40E_ERR_CONFIG
;
8120 memset(&cld_filter
, 0, sizeof(cld_filter
));
8122 /* copy element needed to add cloud filter from filter */
8123 i40e_set_cld_element(filter
, &cld_filter
);
8125 if (filter
->tunnel_type
!= I40E_CLOUD_TNL_TYPE_NONE
)
8126 cld_filter
.flags
= cpu_to_le16(filter
->tunnel_type
<<
8127 I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT
);
8129 if (filter
->n_proto
== ETH_P_IPV6
)
8130 cld_filter
.flags
|= cpu_to_le16(flag_table
[filter
->flags
] |
8131 I40E_AQC_ADD_CLOUD_FLAGS_IPV6
);
8133 cld_filter
.flags
|= cpu_to_le16(flag_table
[filter
->flags
] |
8134 I40E_AQC_ADD_CLOUD_FLAGS_IPV4
);
8137 ret
= i40e_aq_add_cloud_filters(&pf
->hw
, filter
->seid
,
8140 ret
= i40e_aq_rem_cloud_filters(&pf
->hw
, filter
->seid
,
8143 dev_dbg(&pf
->pdev
->dev
,
8144 "Failed to %s cloud filter using l4 port %u, err %d aq_err %d\n",
8145 add
? "add" : "delete", filter
->dst_port
, ret
,
8146 pf
->hw
.aq
.asq_last_status
);
8148 dev_info(&pf
->pdev
->dev
,
8149 "%s cloud filter for VSI: %d\n",
8150 add
? "Added" : "Deleted", filter
->seid
);
8155 * i40e_add_del_cloud_filter_big_buf - Add/del cloud filter using big_buf
8156 * @vsi: pointer to VSI
8157 * @filter: cloud filter rule
8158 * @add: if true, add, if false, delete
8160 * Add or delete a cloud filter for a specific flow spec using big buffer.
8161 * Returns 0 if the filter were successfully added.
8163 int i40e_add_del_cloud_filter_big_buf(struct i40e_vsi
*vsi
,
8164 struct i40e_cloud_filter
*filter
,
8167 struct i40e_aqc_cloud_filters_element_bb cld_filter
;
8168 struct i40e_pf
*pf
= vsi
->back
;
8171 /* Both (src/dst) valid mac_addr are not supported */
8172 if ((is_valid_ether_addr(filter
->dst_mac
) &&
8173 is_valid_ether_addr(filter
->src_mac
)) ||
8174 (is_multicast_ether_addr(filter
->dst_mac
) &&
8175 is_multicast_ether_addr(filter
->src_mac
)))
8178 /* Big buffer cloud filter needs 'L4 port' to be non-zero. Also, UDP
8179 * ports are not supported via big buffer now.
8181 if (!filter
->dst_port
|| filter
->ip_proto
== IPPROTO_UDP
)
8184 /* adding filter using src_port/src_ip is not supported at this stage */
8185 if (filter
->src_port
||
8186 (filter
->src_ipv4
&& filter
->n_proto
!= ETH_P_IPV6
) ||
8187 !ipv6_addr_any(&filter
->ip
.v6
.src_ip6
))
8190 memset(&cld_filter
, 0, sizeof(cld_filter
));
8192 /* copy element needed to add cloud filter from filter */
8193 i40e_set_cld_element(filter
, &cld_filter
.element
);
8195 if (is_valid_ether_addr(filter
->dst_mac
) ||
8196 is_valid_ether_addr(filter
->src_mac
) ||
8197 is_multicast_ether_addr(filter
->dst_mac
) ||
8198 is_multicast_ether_addr(filter
->src_mac
)) {
8199 /* MAC + IP : unsupported mode */
8200 if (filter
->dst_ipv4
)
8203 /* since we validated that L4 port must be valid before
8204 * we get here, start with respective "flags" value
8205 * and update if vlan is present or not
8207 cld_filter
.element
.flags
=
8208 cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_PORT
);
8210 if (filter
->vlan_id
) {
8211 cld_filter
.element
.flags
=
8212 cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_VLAN_PORT
);
8215 } else if ((filter
->dst_ipv4
&& filter
->n_proto
!= ETH_P_IPV6
) ||
8216 !ipv6_addr_any(&filter
->ip
.v6
.dst_ip6
)) {
8217 cld_filter
.element
.flags
=
8218 cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_IP_PORT
);
8219 if (filter
->n_proto
== ETH_P_IPV6
)
8220 cld_filter
.element
.flags
|=
8221 cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV6
);
8223 cld_filter
.element
.flags
|=
8224 cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV4
);
8226 dev_err(&pf
->pdev
->dev
,
8227 "either mac or ip has to be valid for cloud filter\n");
8231 /* Now copy L4 port in Byte 6..7 in general fields */
8232 cld_filter
.general_fields
[I40E_AQC_ADD_CLOUD_FV_FLU_0X16_WORD0
] =
8233 be16_to_cpu(filter
->dst_port
);
8236 /* Validate current device switch mode, change if necessary */
8237 ret
= i40e_validate_and_set_switch_mode(vsi
);
8239 dev_err(&pf
->pdev
->dev
,
8240 "failed to set switch mode, ret %d\n",
8245 ret
= i40e_aq_add_cloud_filters_bb(&pf
->hw
, filter
->seid
,
8248 ret
= i40e_aq_rem_cloud_filters_bb(&pf
->hw
, filter
->seid
,
8253 dev_dbg(&pf
->pdev
->dev
,
8254 "Failed to %s cloud filter(big buffer) err %d aq_err %d\n",
8255 add
? "add" : "delete", ret
, pf
->hw
.aq
.asq_last_status
);
8257 dev_info(&pf
->pdev
->dev
,
8258 "%s cloud filter for VSI: %d, L4 port: %d\n",
8259 add
? "add" : "delete", filter
->seid
,
8260 ntohs(filter
->dst_port
));
8265 * i40e_parse_cls_flower - Parse tc flower filters provided by kernel
8266 * @vsi: Pointer to VSI
8267 * @f: Pointer to struct flow_cls_offload
8268 * @filter: Pointer to cloud filter structure
8271 static int i40e_parse_cls_flower(struct i40e_vsi
*vsi
,
8272 struct flow_cls_offload
*f
,
8273 struct i40e_cloud_filter
*filter
)
8275 struct flow_rule
*rule
= flow_cls_offload_flow_rule(f
);
8276 struct flow_dissector
*dissector
= rule
->match
.dissector
;
8277 u16 n_proto_mask
= 0, n_proto_key
= 0, addr_type
= 0;
8278 struct i40e_pf
*pf
= vsi
->back
;
8281 if (dissector
->used_keys
&
8282 ~(BIT(FLOW_DISSECTOR_KEY_CONTROL
) |
8283 BIT(FLOW_DISSECTOR_KEY_BASIC
) |
8284 BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS
) |
8285 BIT(FLOW_DISSECTOR_KEY_VLAN
) |
8286 BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS
) |
8287 BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS
) |
8288 BIT(FLOW_DISSECTOR_KEY_PORTS
) |
8289 BIT(FLOW_DISSECTOR_KEY_ENC_KEYID
))) {
8290 dev_err(&pf
->pdev
->dev
, "Unsupported key used: 0x%x\n",
8291 dissector
->used_keys
);
8295 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_ENC_KEYID
)) {
8296 struct flow_match_enc_keyid match
;
8298 flow_rule_match_enc_keyid(rule
, &match
);
8299 if (match
.mask
->keyid
!= 0)
8300 field_flags
|= I40E_CLOUD_FIELD_TEN_ID
;
8302 filter
->tenant_id
= be32_to_cpu(match
.key
->keyid
);
8305 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_BASIC
)) {
8306 struct flow_match_basic match
;
8308 flow_rule_match_basic(rule
, &match
);
8309 n_proto_key
= ntohs(match
.key
->n_proto
);
8310 n_proto_mask
= ntohs(match
.mask
->n_proto
);
8312 if (n_proto_key
== ETH_P_ALL
) {
8316 filter
->n_proto
= n_proto_key
& n_proto_mask
;
8317 filter
->ip_proto
= match
.key
->ip_proto
;
8320 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_ETH_ADDRS
)) {
8321 struct flow_match_eth_addrs match
;
8323 flow_rule_match_eth_addrs(rule
, &match
);
8325 /* use is_broadcast and is_zero to check for all 0xf or 0 */
8326 if (!is_zero_ether_addr(match
.mask
->dst
)) {
8327 if (is_broadcast_ether_addr(match
.mask
->dst
)) {
8328 field_flags
|= I40E_CLOUD_FIELD_OMAC
;
8330 dev_err(&pf
->pdev
->dev
, "Bad ether dest mask %pM\n",
8332 return I40E_ERR_CONFIG
;
8336 if (!is_zero_ether_addr(match
.mask
->src
)) {
8337 if (is_broadcast_ether_addr(match
.mask
->src
)) {
8338 field_flags
|= I40E_CLOUD_FIELD_IMAC
;
8340 dev_err(&pf
->pdev
->dev
, "Bad ether src mask %pM\n",
8342 return I40E_ERR_CONFIG
;
8345 ether_addr_copy(filter
->dst_mac
, match
.key
->dst
);
8346 ether_addr_copy(filter
->src_mac
, match
.key
->src
);
8349 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_VLAN
)) {
8350 struct flow_match_vlan match
;
8352 flow_rule_match_vlan(rule
, &match
);
8353 if (match
.mask
->vlan_id
) {
8354 if (match
.mask
->vlan_id
== VLAN_VID_MASK
) {
8355 field_flags
|= I40E_CLOUD_FIELD_IVLAN
;
8358 dev_err(&pf
->pdev
->dev
, "Bad vlan mask 0x%04x\n",
8359 match
.mask
->vlan_id
);
8360 return I40E_ERR_CONFIG
;
8364 filter
->vlan_id
= cpu_to_be16(match
.key
->vlan_id
);
8367 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_CONTROL
)) {
8368 struct flow_match_control match
;
8370 flow_rule_match_control(rule
, &match
);
8371 addr_type
= match
.key
->addr_type
;
8374 if (addr_type
== FLOW_DISSECTOR_KEY_IPV4_ADDRS
) {
8375 struct flow_match_ipv4_addrs match
;
8377 flow_rule_match_ipv4_addrs(rule
, &match
);
8378 if (match
.mask
->dst
) {
8379 if (match
.mask
->dst
== cpu_to_be32(0xffffffff)) {
8380 field_flags
|= I40E_CLOUD_FIELD_IIP
;
8382 dev_err(&pf
->pdev
->dev
, "Bad ip dst mask %pI4b\n",
8384 return I40E_ERR_CONFIG
;
8388 if (match
.mask
->src
) {
8389 if (match
.mask
->src
== cpu_to_be32(0xffffffff)) {
8390 field_flags
|= I40E_CLOUD_FIELD_IIP
;
8392 dev_err(&pf
->pdev
->dev
, "Bad ip src mask %pI4b\n",
8394 return I40E_ERR_CONFIG
;
8398 if (field_flags
& I40E_CLOUD_FIELD_TEN_ID
) {
8399 dev_err(&pf
->pdev
->dev
, "Tenant id not allowed for ip filter\n");
8400 return I40E_ERR_CONFIG
;
8402 filter
->dst_ipv4
= match
.key
->dst
;
8403 filter
->src_ipv4
= match
.key
->src
;
8406 if (addr_type
== FLOW_DISSECTOR_KEY_IPV6_ADDRS
) {
8407 struct flow_match_ipv6_addrs match
;
8409 flow_rule_match_ipv6_addrs(rule
, &match
);
8411 /* src and dest IPV6 address should not be LOOPBACK
8412 * (0:0:0:0:0:0:0:1), which can be represented as ::1
8414 if (ipv6_addr_loopback(&match
.key
->dst
) ||
8415 ipv6_addr_loopback(&match
.key
->src
)) {
8416 dev_err(&pf
->pdev
->dev
,
8417 "Bad ipv6, addr is LOOPBACK\n");
8418 return I40E_ERR_CONFIG
;
8420 if (!ipv6_addr_any(&match
.mask
->dst
) ||
8421 !ipv6_addr_any(&match
.mask
->src
))
8422 field_flags
|= I40E_CLOUD_FIELD_IIP
;
8424 memcpy(&filter
->src_ipv6
, &match
.key
->src
.s6_addr32
,
8425 sizeof(filter
->src_ipv6
));
8426 memcpy(&filter
->dst_ipv6
, &match
.key
->dst
.s6_addr32
,
8427 sizeof(filter
->dst_ipv6
));
8430 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_PORTS
)) {
8431 struct flow_match_ports match
;
8433 flow_rule_match_ports(rule
, &match
);
8434 if (match
.mask
->src
) {
8435 if (match
.mask
->src
== cpu_to_be16(0xffff)) {
8436 field_flags
|= I40E_CLOUD_FIELD_IIP
;
8438 dev_err(&pf
->pdev
->dev
, "Bad src port mask 0x%04x\n",
8439 be16_to_cpu(match
.mask
->src
));
8440 return I40E_ERR_CONFIG
;
8444 if (match
.mask
->dst
) {
8445 if (match
.mask
->dst
== cpu_to_be16(0xffff)) {
8446 field_flags
|= I40E_CLOUD_FIELD_IIP
;
8448 dev_err(&pf
->pdev
->dev
, "Bad dst port mask 0x%04x\n",
8449 be16_to_cpu(match
.mask
->dst
));
8450 return I40E_ERR_CONFIG
;
8454 filter
->dst_port
= match
.key
->dst
;
8455 filter
->src_port
= match
.key
->src
;
8457 switch (filter
->ip_proto
) {
8462 dev_err(&pf
->pdev
->dev
,
8463 "Only UDP and TCP transport are supported\n");
8467 filter
->flags
= field_flags
;
8472 * i40e_handle_tclass: Forward to a traffic class on the device
8473 * @vsi: Pointer to VSI
8474 * @tc: traffic class index on the device
8475 * @filter: Pointer to cloud filter structure
8478 static int i40e_handle_tclass(struct i40e_vsi
*vsi
, u32 tc
,
8479 struct i40e_cloud_filter
*filter
)
8481 struct i40e_channel
*ch
, *ch_tmp
;
8483 /* direct to a traffic class on the same device */
8485 filter
->seid
= vsi
->seid
;
8487 } else if (vsi
->tc_config
.enabled_tc
& BIT(tc
)) {
8488 if (!filter
->dst_port
) {
8489 dev_err(&vsi
->back
->pdev
->dev
,
8490 "Specify destination port to direct to traffic class that is not default\n");
8493 if (list_empty(&vsi
->ch_list
))
8495 list_for_each_entry_safe(ch
, ch_tmp
, &vsi
->ch_list
,
8497 if (ch
->seid
== vsi
->tc_seid_map
[tc
])
8498 filter
->seid
= ch
->seid
;
8502 dev_err(&vsi
->back
->pdev
->dev
, "TC is not enabled\n");
8507 * i40e_configure_clsflower - Configure tc flower filters
8508 * @vsi: Pointer to VSI
8509 * @cls_flower: Pointer to struct flow_cls_offload
8512 static int i40e_configure_clsflower(struct i40e_vsi
*vsi
,
8513 struct flow_cls_offload
*cls_flower
)
8515 int tc
= tc_classid_to_hwtc(vsi
->netdev
, cls_flower
->classid
);
8516 struct i40e_cloud_filter
*filter
= NULL
;
8517 struct i40e_pf
*pf
= vsi
->back
;
8521 dev_err(&vsi
->back
->pdev
->dev
, "Invalid traffic class\n");
8525 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
) ||
8526 test_bit(__I40E_RESET_INTR_RECEIVED
, pf
->state
))
8529 if (pf
->fdir_pf_active_filters
||
8530 (!hlist_empty(&pf
->fdir_filter_list
))) {
8531 dev_err(&vsi
->back
->pdev
->dev
,
8532 "Flow Director Sideband filters exists, turn ntuple off to configure cloud filters\n");
8536 if (vsi
->back
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
8537 dev_err(&vsi
->back
->pdev
->dev
,
8538 "Disable Flow Director Sideband, configuring Cloud filters via tc-flower\n");
8539 vsi
->back
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
8540 vsi
->back
->flags
|= I40E_FLAG_FD_SB_TO_CLOUD_FILTER
;
8543 filter
= kzalloc(sizeof(*filter
), GFP_KERNEL
);
8547 filter
->cookie
= cls_flower
->cookie
;
8549 err
= i40e_parse_cls_flower(vsi
, cls_flower
, filter
);
8553 err
= i40e_handle_tclass(vsi
, tc
, filter
);
8557 /* Add cloud filter */
8558 if (filter
->dst_port
)
8559 err
= i40e_add_del_cloud_filter_big_buf(vsi
, filter
, true);
8561 err
= i40e_add_del_cloud_filter(vsi
, filter
, true);
8564 dev_err(&pf
->pdev
->dev
, "Failed to add cloud filter, err %d\n",
8569 /* add filter to the ordered list */
8570 INIT_HLIST_NODE(&filter
->cloud_node
);
8572 hlist_add_head(&filter
->cloud_node
, &pf
->cloud_filter_list
);
8574 pf
->num_cloud_filters
++;
8583 * i40e_find_cloud_filter - Find the could filter in the list
8584 * @vsi: Pointer to VSI
8585 * @cookie: filter specific cookie
8588 static struct i40e_cloud_filter
*i40e_find_cloud_filter(struct i40e_vsi
*vsi
,
8589 unsigned long *cookie
)
8591 struct i40e_cloud_filter
*filter
= NULL
;
8592 struct hlist_node
*node2
;
8594 hlist_for_each_entry_safe(filter
, node2
,
8595 &vsi
->back
->cloud_filter_list
, cloud_node
)
8596 if (!memcmp(cookie
, &filter
->cookie
, sizeof(filter
->cookie
)))
8602 * i40e_delete_clsflower - Remove tc flower filters
8603 * @vsi: Pointer to VSI
8604 * @cls_flower: Pointer to struct flow_cls_offload
8607 static int i40e_delete_clsflower(struct i40e_vsi
*vsi
,
8608 struct flow_cls_offload
*cls_flower
)
8610 struct i40e_cloud_filter
*filter
= NULL
;
8611 struct i40e_pf
*pf
= vsi
->back
;
8614 filter
= i40e_find_cloud_filter(vsi
, &cls_flower
->cookie
);
8619 hash_del(&filter
->cloud_node
);
8621 if (filter
->dst_port
)
8622 err
= i40e_add_del_cloud_filter_big_buf(vsi
, filter
, false);
8624 err
= i40e_add_del_cloud_filter(vsi
, filter
, false);
8628 dev_err(&pf
->pdev
->dev
,
8629 "Failed to delete cloud filter, err %s\n",
8630 i40e_stat_str(&pf
->hw
, err
));
8631 return i40e_aq_rc_to_posix(err
, pf
->hw
.aq
.asq_last_status
);
8634 pf
->num_cloud_filters
--;
8635 if (!pf
->num_cloud_filters
)
8636 if ((pf
->flags
& I40E_FLAG_FD_SB_TO_CLOUD_FILTER
) &&
8637 !(pf
->flags
& I40E_FLAG_FD_SB_INACTIVE
)) {
8638 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
8639 pf
->flags
&= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER
;
8640 pf
->flags
&= ~I40E_FLAG_FD_SB_INACTIVE
;
8646 * i40e_setup_tc_cls_flower - flower classifier offloads
8647 * @np: net device to configure
8648 * @cls_flower: offload data
8650 static int i40e_setup_tc_cls_flower(struct i40e_netdev_priv
*np
,
8651 struct flow_cls_offload
*cls_flower
)
8653 struct i40e_vsi
*vsi
= np
->vsi
;
8655 switch (cls_flower
->command
) {
8656 case FLOW_CLS_REPLACE
:
8657 return i40e_configure_clsflower(vsi
, cls_flower
);
8658 case FLOW_CLS_DESTROY
:
8659 return i40e_delete_clsflower(vsi
, cls_flower
);
8660 case FLOW_CLS_STATS
:
8667 static int i40e_setup_tc_block_cb(enum tc_setup_type type
, void *type_data
,
8670 struct i40e_netdev_priv
*np
= cb_priv
;
8672 if (!tc_cls_can_offload_and_chain0(np
->vsi
->netdev
, type_data
))
8676 case TC_SETUP_CLSFLOWER
:
8677 return i40e_setup_tc_cls_flower(np
, type_data
);
8684 static LIST_HEAD(i40e_block_cb_list
);
8686 static int __i40e_setup_tc(struct net_device
*netdev
, enum tc_setup_type type
,
8689 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8692 case TC_SETUP_QDISC_MQPRIO
:
8693 return i40e_setup_tc(netdev
, type_data
);
8694 case TC_SETUP_BLOCK
:
8695 return flow_block_cb_setup_simple(type_data
,
8696 &i40e_block_cb_list
,
8697 i40e_setup_tc_block_cb
,
8705 * i40e_open - Called when a network interface is made active
8706 * @netdev: network interface device structure
8708 * The open entry point is called when a network interface is made
8709 * active by the system (IFF_UP). At this point all resources needed
8710 * for transmit and receive operations are allocated, the interrupt
8711 * handler is registered with the OS, the netdev watchdog subtask is
8712 * enabled, and the stack is notified that the interface is ready.
8714 * Returns 0 on success, negative value on failure
8716 int i40e_open(struct net_device
*netdev
)
8718 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8719 struct i40e_vsi
*vsi
= np
->vsi
;
8720 struct i40e_pf
*pf
= vsi
->back
;
8723 /* disallow open during test or if eeprom is broken */
8724 if (test_bit(__I40E_TESTING
, pf
->state
) ||
8725 test_bit(__I40E_BAD_EEPROM
, pf
->state
))
8728 netif_carrier_off(netdev
);
8730 if (i40e_force_link_state(pf
, true))
8733 err
= i40e_vsi_open(vsi
);
8737 /* configure global TSO hardware offload settings */
8738 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_F
, be32_to_cpu(TCP_FLAG_PSH
|
8739 TCP_FLAG_FIN
) >> 16);
8740 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_M
, be32_to_cpu(TCP_FLAG_PSH
|
8742 TCP_FLAG_CWR
) >> 16);
8743 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_L
, be32_to_cpu(TCP_FLAG_CWR
) >> 16);
8744 udp_tunnel_get_rx_info(netdev
);
8750 * i40e_netif_set_realnum_tx_rx_queues - Update number of tx/rx queues
8751 * @vsi: vsi structure
8753 * This updates netdev's number of tx/rx queues
8755 * Returns status of setting tx/rx queues
8757 static int i40e_netif_set_realnum_tx_rx_queues(struct i40e_vsi
*vsi
)
8761 ret
= netif_set_real_num_rx_queues(vsi
->netdev
,
8762 vsi
->num_queue_pairs
);
8766 return netif_set_real_num_tx_queues(vsi
->netdev
,
8767 vsi
->num_queue_pairs
);
8772 * @vsi: the VSI to open
8774 * Finish initialization of the VSI.
8776 * Returns 0 on success, negative value on failure
8778 * Note: expects to be called while under rtnl_lock()
8780 int i40e_vsi_open(struct i40e_vsi
*vsi
)
8782 struct i40e_pf
*pf
= vsi
->back
;
8783 char int_name
[I40E_INT_NAME_STR_LEN
];
8786 /* allocate descriptors */
8787 err
= i40e_vsi_setup_tx_resources(vsi
);
8790 err
= i40e_vsi_setup_rx_resources(vsi
);
8794 err
= i40e_vsi_configure(vsi
);
8799 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s",
8800 dev_driver_string(&pf
->pdev
->dev
), vsi
->netdev
->name
);
8801 err
= i40e_vsi_request_irq(vsi
, int_name
);
8805 /* Notify the stack of the actual queue counts. */
8806 err
= i40e_netif_set_realnum_tx_rx_queues(vsi
);
8808 goto err_set_queues
;
8810 } else if (vsi
->type
== I40E_VSI_FDIR
) {
8811 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s:fdir",
8812 dev_driver_string(&pf
->pdev
->dev
),
8813 dev_name(&pf
->pdev
->dev
));
8814 err
= i40e_vsi_request_irq(vsi
, int_name
);
8823 err
= i40e_up_complete(vsi
);
8825 goto err_up_complete
;
8832 i40e_vsi_free_irq(vsi
);
8834 i40e_vsi_free_rx_resources(vsi
);
8836 i40e_vsi_free_tx_resources(vsi
);
8837 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
8838 i40e_do_reset(pf
, I40E_PF_RESET_FLAG
, true);
8844 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
8845 * @pf: Pointer to PF
8847 * This function destroys the hlist where all the Flow Director
8848 * filters were saved.
8850 static void i40e_fdir_filter_exit(struct i40e_pf
*pf
)
8852 struct i40e_fdir_filter
*filter
;
8853 struct i40e_flex_pit
*pit_entry
, *tmp
;
8854 struct hlist_node
*node2
;
8856 hlist_for_each_entry_safe(filter
, node2
,
8857 &pf
->fdir_filter_list
, fdir_node
) {
8858 hlist_del(&filter
->fdir_node
);
8862 list_for_each_entry_safe(pit_entry
, tmp
, &pf
->l3_flex_pit_list
, list
) {
8863 list_del(&pit_entry
->list
);
8866 INIT_LIST_HEAD(&pf
->l3_flex_pit_list
);
8868 list_for_each_entry_safe(pit_entry
, tmp
, &pf
->l4_flex_pit_list
, list
) {
8869 list_del(&pit_entry
->list
);
8872 INIT_LIST_HEAD(&pf
->l4_flex_pit_list
);
8874 pf
->fdir_pf_active_filters
= 0;
8875 i40e_reset_fdir_filter_cnt(pf
);
8877 /* Reprogram the default input set for TCP/IPv4 */
8878 i40e_write_fd_input_set(pf
, I40E_FILTER_PCTYPE_NONF_IPV4_TCP
,
8879 I40E_L3_SRC_MASK
| I40E_L3_DST_MASK
|
8880 I40E_L4_SRC_MASK
| I40E_L4_DST_MASK
);
8882 /* Reprogram the default input set for TCP/IPv6 */
8883 i40e_write_fd_input_set(pf
, I40E_FILTER_PCTYPE_NONF_IPV6_TCP
,
8884 I40E_L3_V6_SRC_MASK
| I40E_L3_V6_DST_MASK
|
8885 I40E_L4_SRC_MASK
| I40E_L4_DST_MASK
);
8887 /* Reprogram the default input set for UDP/IPv4 */
8888 i40e_write_fd_input_set(pf
, I40E_FILTER_PCTYPE_NONF_IPV4_UDP
,
8889 I40E_L3_SRC_MASK
| I40E_L3_DST_MASK
|
8890 I40E_L4_SRC_MASK
| I40E_L4_DST_MASK
);
8892 /* Reprogram the default input set for UDP/IPv6 */
8893 i40e_write_fd_input_set(pf
, I40E_FILTER_PCTYPE_NONF_IPV6_UDP
,
8894 I40E_L3_V6_SRC_MASK
| I40E_L3_V6_DST_MASK
|
8895 I40E_L4_SRC_MASK
| I40E_L4_DST_MASK
);
8897 /* Reprogram the default input set for SCTP/IPv4 */
8898 i40e_write_fd_input_set(pf
, I40E_FILTER_PCTYPE_NONF_IPV4_SCTP
,
8899 I40E_L3_SRC_MASK
| I40E_L3_DST_MASK
|
8900 I40E_L4_SRC_MASK
| I40E_L4_DST_MASK
);
8902 /* Reprogram the default input set for SCTP/IPv6 */
8903 i40e_write_fd_input_set(pf
, I40E_FILTER_PCTYPE_NONF_IPV6_SCTP
,
8904 I40E_L3_V6_SRC_MASK
| I40E_L3_V6_DST_MASK
|
8905 I40E_L4_SRC_MASK
| I40E_L4_DST_MASK
);
8907 /* Reprogram the default input set for Other/IPv4 */
8908 i40e_write_fd_input_set(pf
, I40E_FILTER_PCTYPE_NONF_IPV4_OTHER
,
8909 I40E_L3_SRC_MASK
| I40E_L3_DST_MASK
);
8911 i40e_write_fd_input_set(pf
, I40E_FILTER_PCTYPE_FRAG_IPV4
,
8912 I40E_L3_SRC_MASK
| I40E_L3_DST_MASK
);
8914 /* Reprogram the default input set for Other/IPv6 */
8915 i40e_write_fd_input_set(pf
, I40E_FILTER_PCTYPE_NONF_IPV6_OTHER
,
8916 I40E_L3_SRC_MASK
| I40E_L3_DST_MASK
);
8918 i40e_write_fd_input_set(pf
, I40E_FILTER_PCTYPE_FRAG_IPV6
,
8919 I40E_L3_SRC_MASK
| I40E_L3_DST_MASK
);
8923 * i40e_cloud_filter_exit - Cleans up the cloud filters
8924 * @pf: Pointer to PF
8926 * This function destroys the hlist where all the cloud filters
8929 static void i40e_cloud_filter_exit(struct i40e_pf
*pf
)
8931 struct i40e_cloud_filter
*cfilter
;
8932 struct hlist_node
*node
;
8934 hlist_for_each_entry_safe(cfilter
, node
,
8935 &pf
->cloud_filter_list
, cloud_node
) {
8936 hlist_del(&cfilter
->cloud_node
);
8939 pf
->num_cloud_filters
= 0;
8941 if ((pf
->flags
& I40E_FLAG_FD_SB_TO_CLOUD_FILTER
) &&
8942 !(pf
->flags
& I40E_FLAG_FD_SB_INACTIVE
)) {
8943 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
8944 pf
->flags
&= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER
;
8945 pf
->flags
&= ~I40E_FLAG_FD_SB_INACTIVE
;
8950 * i40e_close - Disables a network interface
8951 * @netdev: network interface device structure
8953 * The close entry point is called when an interface is de-activated
8954 * by the OS. The hardware is still under the driver's control, but
8955 * this netdev interface is disabled.
8957 * Returns 0, this is not allowed to fail
8959 int i40e_close(struct net_device
*netdev
)
8961 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8962 struct i40e_vsi
*vsi
= np
->vsi
;
8964 i40e_vsi_close(vsi
);
8970 * i40e_do_reset - Start a PF or Core Reset sequence
8971 * @pf: board private structure
8972 * @reset_flags: which reset is requested
8973 * @lock_acquired: indicates whether or not the lock has been acquired
8974 * before this function was called.
8976 * The essential difference in resets is that the PF Reset
8977 * doesn't clear the packet buffers, doesn't reset the PE
8978 * firmware, and doesn't bother the other PFs on the chip.
8980 void i40e_do_reset(struct i40e_pf
*pf
, u32 reset_flags
, bool lock_acquired
)
8984 /* do the biggest reset indicated */
8985 if (reset_flags
& BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED
)) {
8987 /* Request a Global Reset
8989 * This will start the chip's countdown to the actual full
8990 * chip reset event, and a warning interrupt to be sent
8991 * to all PFs, including the requestor. Our handler
8992 * for the warning interrupt will deal with the shutdown
8993 * and recovery of the switch setup.
8995 dev_dbg(&pf
->pdev
->dev
, "GlobalR requested\n");
8996 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
8997 val
|= I40E_GLGEN_RTRIG_GLOBR_MASK
;
8998 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
9000 } else if (reset_flags
& BIT_ULL(__I40E_CORE_RESET_REQUESTED
)) {
9002 /* Request a Core Reset
9004 * Same as Global Reset, except does *not* include the MAC/PHY
9006 dev_dbg(&pf
->pdev
->dev
, "CoreR requested\n");
9007 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
9008 val
|= I40E_GLGEN_RTRIG_CORER_MASK
;
9009 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
9010 i40e_flush(&pf
->hw
);
9012 } else if (reset_flags
& I40E_PF_RESET_FLAG
) {
9014 /* Request a PF Reset
9016 * Resets only the PF-specific registers
9018 * This goes directly to the tear-down and rebuild of
9019 * the switch, since we need to do all the recovery as
9020 * for the Core Reset.
9022 dev_dbg(&pf
->pdev
->dev
, "PFR requested\n");
9023 i40e_handle_reset_warning(pf
, lock_acquired
);
9025 } else if (reset_flags
& I40E_PF_RESET_AND_REBUILD_FLAG
) {
9026 /* Request a PF Reset
9028 * Resets PF and reinitializes PFs VSI.
9030 i40e_prep_for_reset(pf
);
9031 i40e_reset_and_rebuild(pf
, true, lock_acquired
);
9032 dev_info(&pf
->pdev
->dev
,
9033 pf
->flags
& I40E_FLAG_DISABLE_FW_LLDP
?
9034 "FW LLDP is disabled\n" :
9035 "FW LLDP is enabled\n");
9037 } else if (reset_flags
& BIT_ULL(__I40E_REINIT_REQUESTED
)) {
9040 /* Find the VSI(s) that requested a re-init */
9041 dev_info(&pf
->pdev
->dev
,
9042 "VSI reinit requested\n");
9043 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
9044 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
9047 test_and_clear_bit(__I40E_VSI_REINIT_REQUESTED
,
9049 i40e_vsi_reinit_locked(pf
->vsi
[v
]);
9051 } else if (reset_flags
& BIT_ULL(__I40E_DOWN_REQUESTED
)) {
9054 /* Find the VSI(s) that needs to be brought down */
9055 dev_info(&pf
->pdev
->dev
, "VSI down requested\n");
9056 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
9057 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
9060 test_and_clear_bit(__I40E_VSI_DOWN_REQUESTED
,
9062 set_bit(__I40E_VSI_DOWN
, vsi
->state
);
9067 dev_info(&pf
->pdev
->dev
,
9068 "bad reset request 0x%08x\n", reset_flags
);
9072 #ifdef CONFIG_I40E_DCB
9074 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
9075 * @pf: board private structure
9076 * @old_cfg: current DCB config
9077 * @new_cfg: new DCB config
9079 bool i40e_dcb_need_reconfig(struct i40e_pf
*pf
,
9080 struct i40e_dcbx_config
*old_cfg
,
9081 struct i40e_dcbx_config
*new_cfg
)
9083 bool need_reconfig
= false;
9085 /* Check if ETS configuration has changed */
9086 if (memcmp(&new_cfg
->etscfg
,
9088 sizeof(new_cfg
->etscfg
))) {
9089 /* If Priority Table has changed reconfig is needed */
9090 if (memcmp(&new_cfg
->etscfg
.prioritytable
,
9091 &old_cfg
->etscfg
.prioritytable
,
9092 sizeof(new_cfg
->etscfg
.prioritytable
))) {
9093 need_reconfig
= true;
9094 dev_dbg(&pf
->pdev
->dev
, "ETS UP2TC changed.\n");
9097 if (memcmp(&new_cfg
->etscfg
.tcbwtable
,
9098 &old_cfg
->etscfg
.tcbwtable
,
9099 sizeof(new_cfg
->etscfg
.tcbwtable
)))
9100 dev_dbg(&pf
->pdev
->dev
, "ETS TC BW Table changed.\n");
9102 if (memcmp(&new_cfg
->etscfg
.tsatable
,
9103 &old_cfg
->etscfg
.tsatable
,
9104 sizeof(new_cfg
->etscfg
.tsatable
)))
9105 dev_dbg(&pf
->pdev
->dev
, "ETS TSA Table changed.\n");
9108 /* Check if PFC configuration has changed */
9109 if (memcmp(&new_cfg
->pfc
,
9111 sizeof(new_cfg
->pfc
))) {
9112 need_reconfig
= true;
9113 dev_dbg(&pf
->pdev
->dev
, "PFC config change detected.\n");
9116 /* Check if APP Table has changed */
9117 if (memcmp(&new_cfg
->app
,
9119 sizeof(new_cfg
->app
))) {
9120 need_reconfig
= true;
9121 dev_dbg(&pf
->pdev
->dev
, "APP Table change detected.\n");
9124 dev_dbg(&pf
->pdev
->dev
, "dcb need_reconfig=%d\n", need_reconfig
);
9125 return need_reconfig
;
9129 * i40e_handle_lldp_event - Handle LLDP Change MIB event
9130 * @pf: board private structure
9131 * @e: event info posted on ARQ
9133 static int i40e_handle_lldp_event(struct i40e_pf
*pf
,
9134 struct i40e_arq_event_info
*e
)
9136 struct i40e_aqc_lldp_get_mib
*mib
=
9137 (struct i40e_aqc_lldp_get_mib
*)&e
->desc
.params
.raw
;
9138 struct i40e_hw
*hw
= &pf
->hw
;
9139 struct i40e_dcbx_config tmp_dcbx_cfg
;
9140 bool need_reconfig
= false;
9144 /* X710-T*L 2.5G and 5G speeds don't support DCB */
9145 if (I40E_IS_X710TL_DEVICE(hw
->device_id
) &&
9146 (hw
->phy
.link_info
.link_speed
&
9147 ~(I40E_LINK_SPEED_2_5GB
| I40E_LINK_SPEED_5GB
)) &&
9148 !(pf
->flags
& I40E_FLAG_DCB_CAPABLE
))
9149 /* let firmware decide if the DCB should be disabled */
9150 pf
->flags
|= I40E_FLAG_DCB_CAPABLE
;
9152 /* Not DCB capable or capability disabled */
9153 if (!(pf
->flags
& I40E_FLAG_DCB_CAPABLE
))
9156 /* Ignore if event is not for Nearest Bridge */
9157 type
= ((mib
->type
>> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT
)
9158 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK
);
9159 dev_dbg(&pf
->pdev
->dev
, "LLDP event mib bridge type 0x%x\n", type
);
9160 if (type
!= I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
)
9163 /* Check MIB Type and return if event for Remote MIB update */
9164 type
= mib
->type
& I40E_AQ_LLDP_MIB_TYPE_MASK
;
9165 dev_dbg(&pf
->pdev
->dev
,
9166 "LLDP event mib type %s\n", type
? "remote" : "local");
9167 if (type
== I40E_AQ_LLDP_MIB_REMOTE
) {
9168 /* Update the remote cached instance and return */
9169 ret
= i40e_aq_get_dcb_config(hw
, I40E_AQ_LLDP_MIB_REMOTE
,
9170 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
,
9171 &hw
->remote_dcbx_config
);
9175 /* Store the old configuration */
9176 tmp_dcbx_cfg
= hw
->local_dcbx_config
;
9178 /* Reset the old DCBx configuration data */
9179 memset(&hw
->local_dcbx_config
, 0, sizeof(hw
->local_dcbx_config
));
9180 /* Get updated DCBX data from firmware */
9181 ret
= i40e_get_dcb_config(&pf
->hw
);
9183 /* X710-T*L 2.5G and 5G speeds don't support DCB */
9184 if (I40E_IS_X710TL_DEVICE(hw
->device_id
) &&
9185 (hw
->phy
.link_info
.link_speed
&
9186 (I40E_LINK_SPEED_2_5GB
| I40E_LINK_SPEED_5GB
))) {
9187 dev_warn(&pf
->pdev
->dev
,
9188 "DCB is not supported for X710-T*L 2.5/5G speeds\n");
9189 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
9191 dev_info(&pf
->pdev
->dev
,
9192 "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
9193 i40e_stat_str(&pf
->hw
, ret
),
9194 i40e_aq_str(&pf
->hw
,
9195 pf
->hw
.aq
.asq_last_status
));
9200 /* No change detected in DCBX configs */
9201 if (!memcmp(&tmp_dcbx_cfg
, &hw
->local_dcbx_config
,
9202 sizeof(tmp_dcbx_cfg
))) {
9203 dev_dbg(&pf
->pdev
->dev
, "No change detected in DCBX configuration.\n");
9207 need_reconfig
= i40e_dcb_need_reconfig(pf
, &tmp_dcbx_cfg
,
9208 &hw
->local_dcbx_config
);
9210 i40e_dcbnl_flush_apps(pf
, &tmp_dcbx_cfg
, &hw
->local_dcbx_config
);
9215 /* Enable DCB tagging only when more than one TC */
9216 if (i40e_dcb_get_num_tc(&hw
->local_dcbx_config
) > 1)
9217 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
9219 pf
->flags
&= ~I40E_FLAG_DCB_ENABLED
;
9221 set_bit(__I40E_PORT_SUSPENDED
, pf
->state
);
9222 /* Reconfiguration needed quiesce all VSIs */
9223 i40e_pf_quiesce_all_vsi(pf
);
9225 /* Changes in configuration update VEB/VSI */
9226 i40e_dcb_reconfigure(pf
);
9228 ret
= i40e_resume_port_tx(pf
);
9230 clear_bit(__I40E_PORT_SUSPENDED
, pf
->state
);
9231 /* In case of error no point in resuming VSIs */
9235 /* Wait for the PF's queues to be disabled */
9236 ret
= i40e_pf_wait_queues_disabled(pf
);
9238 /* Schedule PF reset to recover */
9239 set_bit(__I40E_PF_RESET_REQUESTED
, pf
->state
);
9240 i40e_service_event_schedule(pf
);
9242 i40e_pf_unquiesce_all_vsi(pf
);
9243 set_bit(__I40E_CLIENT_SERVICE_REQUESTED
, pf
->state
);
9244 set_bit(__I40E_CLIENT_L2_CHANGE
, pf
->state
);
9250 #endif /* CONFIG_I40E_DCB */
9253 * i40e_do_reset_safe - Protected reset path for userland calls.
9254 * @pf: board private structure
9255 * @reset_flags: which reset is requested
9258 void i40e_do_reset_safe(struct i40e_pf
*pf
, u32 reset_flags
)
9261 i40e_do_reset(pf
, reset_flags
, true);
9266 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
9267 * @pf: board private structure
9268 * @e: event info posted on ARQ
9270 * Handler for LAN Queue Overflow Event generated by the firmware for PF
9273 static void i40e_handle_lan_overflow_event(struct i40e_pf
*pf
,
9274 struct i40e_arq_event_info
*e
)
9276 struct i40e_aqc_lan_overflow
*data
=
9277 (struct i40e_aqc_lan_overflow
*)&e
->desc
.params
.raw
;
9278 u32 queue
= le32_to_cpu(data
->prtdcb_rupto
);
9279 u32 qtx_ctl
= le32_to_cpu(data
->otx_ctl
);
9280 struct i40e_hw
*hw
= &pf
->hw
;
9284 dev_dbg(&pf
->pdev
->dev
, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
9287 /* Queue belongs to VF, find the VF and issue VF reset */
9288 if (((qtx_ctl
& I40E_QTX_CTL_PFVF_Q_MASK
)
9289 >> I40E_QTX_CTL_PFVF_Q_SHIFT
) == I40E_QTX_CTL_VF_QUEUE
) {
9290 vf_id
= (u16
)((qtx_ctl
& I40E_QTX_CTL_VFVM_INDX_MASK
)
9291 >> I40E_QTX_CTL_VFVM_INDX_SHIFT
);
9292 vf_id
-= hw
->func_caps
.vf_base_id
;
9293 vf
= &pf
->vf
[vf_id
];
9294 i40e_vc_notify_vf_reset(vf
);
9295 /* Allow VF to process pending reset notification */
9297 i40e_reset_vf(vf
, false);
9302 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
9303 * @pf: board private structure
9305 u32
i40e_get_cur_guaranteed_fd_count(struct i40e_pf
*pf
)
9309 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
9310 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
);
9315 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
9316 * @pf: board private structure
9318 u32
i40e_get_current_fd_count(struct i40e_pf
*pf
)
9322 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
9323 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
) +
9324 ((val
& I40E_PFQF_FDSTAT_BEST_CNT_MASK
) >>
9325 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT
);
9330 * i40e_get_global_fd_count - Get total FD filters programmed on device
9331 * @pf: board private structure
9333 u32
i40e_get_global_fd_count(struct i40e_pf
*pf
)
9337 val
= rd32(&pf
->hw
, I40E_GLQF_FDCNT_0
);
9338 fcnt_prog
= (val
& I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK
) +
9339 ((val
& I40E_GLQF_FDCNT_0_BESTCNT_MASK
) >>
9340 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT
);
9345 * i40e_reenable_fdir_sb - Restore FDir SB capability
9346 * @pf: board private structure
9348 static void i40e_reenable_fdir_sb(struct i40e_pf
*pf
)
9350 if (test_and_clear_bit(__I40E_FD_SB_AUTO_DISABLED
, pf
->state
))
9351 if ((pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) &&
9352 (I40E_DEBUG_FD
& pf
->hw
.debug_mask
))
9353 dev_info(&pf
->pdev
->dev
, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
9357 * i40e_reenable_fdir_atr - Restore FDir ATR capability
9358 * @pf: board private structure
9360 static void i40e_reenable_fdir_atr(struct i40e_pf
*pf
)
9362 if (test_and_clear_bit(__I40E_FD_ATR_AUTO_DISABLED
, pf
->state
)) {
9363 /* ATR uses the same filtering logic as SB rules. It only
9364 * functions properly if the input set mask is at the default
9365 * settings. It is safe to restore the default input set
9366 * because there are no active TCPv4 filter rules.
9368 i40e_write_fd_input_set(pf
, I40E_FILTER_PCTYPE_NONF_IPV4_TCP
,
9369 I40E_L3_SRC_MASK
| I40E_L3_DST_MASK
|
9370 I40E_L4_SRC_MASK
| I40E_L4_DST_MASK
);
9372 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
9373 (I40E_DEBUG_FD
& pf
->hw
.debug_mask
))
9374 dev_info(&pf
->pdev
->dev
, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n");
9379 * i40e_delete_invalid_filter - Delete an invalid FDIR filter
9380 * @pf: board private structure
9381 * @filter: FDir filter to remove
9383 static void i40e_delete_invalid_filter(struct i40e_pf
*pf
,
9384 struct i40e_fdir_filter
*filter
)
9386 /* Update counters */
9387 pf
->fdir_pf_active_filters
--;
9390 switch (filter
->flow_type
) {
9392 pf
->fd_tcp4_filter_cnt
--;
9395 pf
->fd_udp4_filter_cnt
--;
9398 pf
->fd_sctp4_filter_cnt
--;
9401 pf
->fd_tcp6_filter_cnt
--;
9404 pf
->fd_udp6_filter_cnt
--;
9407 pf
->fd_udp6_filter_cnt
--;
9410 switch (filter
->ipl4_proto
) {
9412 pf
->fd_tcp4_filter_cnt
--;
9415 pf
->fd_udp4_filter_cnt
--;
9418 pf
->fd_sctp4_filter_cnt
--;
9421 pf
->fd_ip4_filter_cnt
--;
9425 case IPV6_USER_FLOW
:
9426 switch (filter
->ipl4_proto
) {
9428 pf
->fd_tcp6_filter_cnt
--;
9431 pf
->fd_udp6_filter_cnt
--;
9434 pf
->fd_sctp6_filter_cnt
--;
9437 pf
->fd_ip6_filter_cnt
--;
9443 /* Remove the filter from the list and free memory */
9444 hlist_del(&filter
->fdir_node
);
9449 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
9450 * @pf: board private structure
9452 void i40e_fdir_check_and_reenable(struct i40e_pf
*pf
)
9454 struct i40e_fdir_filter
*filter
;
9455 u32 fcnt_prog
, fcnt_avail
;
9456 struct hlist_node
*node
;
9458 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, pf
->state
))
9461 /* Check if we have enough room to re-enable FDir SB capability. */
9462 fcnt_prog
= i40e_get_global_fd_count(pf
);
9463 fcnt_avail
= pf
->fdir_pf_filter_count
;
9464 if ((fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM
)) ||
9465 (pf
->fd_add_err
== 0) ||
9466 (i40e_get_current_atr_cnt(pf
) < pf
->fd_atr_cnt
))
9467 i40e_reenable_fdir_sb(pf
);
9469 /* We should wait for even more space before re-enabling ATR.
9470 * Additionally, we cannot enable ATR as long as we still have TCP SB
9473 if ((fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR
)) &&
9474 pf
->fd_tcp4_filter_cnt
== 0 && pf
->fd_tcp6_filter_cnt
== 0)
9475 i40e_reenable_fdir_atr(pf
);
9477 /* if hw had a problem adding a filter, delete it */
9478 if (pf
->fd_inv
> 0) {
9479 hlist_for_each_entry_safe(filter
, node
,
9480 &pf
->fdir_filter_list
, fdir_node
)
9481 if (filter
->fd_id
== pf
->fd_inv
)
9482 i40e_delete_invalid_filter(pf
, filter
);
9486 #define I40E_MIN_FD_FLUSH_INTERVAL 10
9487 #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
9489 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
9490 * @pf: board private structure
9492 static void i40e_fdir_flush_and_replay(struct i40e_pf
*pf
)
9494 unsigned long min_flush_time
;
9495 int flush_wait_retry
= 50;
9496 bool disable_atr
= false;
9500 if (!time_after(jiffies
, pf
->fd_flush_timestamp
+
9501 (I40E_MIN_FD_FLUSH_INTERVAL
* HZ
)))
9504 /* If the flush is happening too quick and we have mostly SB rules we
9505 * should not re-enable ATR for some time.
9507 min_flush_time
= pf
->fd_flush_timestamp
+
9508 (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE
* HZ
);
9509 fd_room
= pf
->fdir_pf_filter_count
- pf
->fdir_pf_active_filters
;
9511 if (!(time_after(jiffies
, min_flush_time
)) &&
9512 (fd_room
< I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR
)) {
9513 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
9514 dev_info(&pf
->pdev
->dev
, "ATR disabled, not enough FD filter space.\n");
9518 pf
->fd_flush_timestamp
= jiffies
;
9519 set_bit(__I40E_FD_ATR_AUTO_DISABLED
, pf
->state
);
9520 /* flush all filters */
9521 wr32(&pf
->hw
, I40E_PFQF_CTL_1
,
9522 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
);
9523 i40e_flush(&pf
->hw
);
9527 /* Check FD flush status every 5-6msec */
9528 usleep_range(5000, 6000);
9529 reg
= rd32(&pf
->hw
, I40E_PFQF_CTL_1
);
9530 if (!(reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
))
9532 } while (flush_wait_retry
--);
9533 if (reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
) {
9534 dev_warn(&pf
->pdev
->dev
, "FD table did not flush, needs more time\n");
9536 /* replay sideband filters */
9537 i40e_fdir_filter_restore(pf
->vsi
[pf
->lan_vsi
]);
9538 if (!disable_atr
&& !pf
->fd_tcp4_filter_cnt
)
9539 clear_bit(__I40E_FD_ATR_AUTO_DISABLED
, pf
->state
);
9540 clear_bit(__I40E_FD_FLUSH_REQUESTED
, pf
->state
);
9541 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
9542 dev_info(&pf
->pdev
->dev
, "FD Filter table flushed and FD-SB replayed.\n");
9547 * i40e_get_current_atr_cnt - Get the count of total FD ATR filters programmed
9548 * @pf: board private structure
9550 u32
i40e_get_current_atr_cnt(struct i40e_pf
*pf
)
9552 return i40e_get_current_fd_count(pf
) - pf
->fdir_pf_active_filters
;
9556 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
9557 * @pf: board private structure
9559 static void i40e_fdir_reinit_subtask(struct i40e_pf
*pf
)
9562 /* if interface is down do nothing */
9563 if (test_bit(__I40E_DOWN
, pf
->state
))
9566 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, pf
->state
))
9567 i40e_fdir_flush_and_replay(pf
);
9569 i40e_fdir_check_and_reenable(pf
);
9574 * i40e_vsi_link_event - notify VSI of a link event
9575 * @vsi: vsi to be notified
9576 * @link_up: link up or down
9578 static void i40e_vsi_link_event(struct i40e_vsi
*vsi
, bool link_up
)
9580 if (!vsi
|| test_bit(__I40E_VSI_DOWN
, vsi
->state
))
9583 switch (vsi
->type
) {
9585 if (!vsi
->netdev
|| !vsi
->netdev_registered
)
9589 netif_carrier_on(vsi
->netdev
);
9590 netif_tx_wake_all_queues(vsi
->netdev
);
9592 netif_carrier_off(vsi
->netdev
);
9593 netif_tx_stop_all_queues(vsi
->netdev
);
9597 case I40E_VSI_SRIOV
:
9598 case I40E_VSI_VMDQ2
:
9600 case I40E_VSI_IWARP
:
9601 case I40E_VSI_MIRROR
:
9603 /* there is no notification for other VSIs */
9609 * i40e_veb_link_event - notify elements on the veb of a link event
9610 * @veb: veb to be notified
9611 * @link_up: link up or down
9613 static void i40e_veb_link_event(struct i40e_veb
*veb
, bool link_up
)
9618 if (!veb
|| !veb
->pf
)
9622 /* depth first... */
9623 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
9624 if (pf
->veb
[i
] && (pf
->veb
[i
]->uplink_seid
== veb
->seid
))
9625 i40e_veb_link_event(pf
->veb
[i
], link_up
);
9627 /* ... now the local VSIs */
9628 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
9629 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->uplink_seid
== veb
->seid
))
9630 i40e_vsi_link_event(pf
->vsi
[i
], link_up
);
9634 * i40e_link_event - Update netif_carrier status
9635 * @pf: board private structure
9637 static void i40e_link_event(struct i40e_pf
*pf
)
9639 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
9640 u8 new_link_speed
, old_link_speed
;
9642 bool new_link
, old_link
;
9643 #ifdef CONFIG_I40E_DCB
9645 #endif /* CONFIG_I40E_DCB */
9647 /* set this to force the get_link_status call to refresh state */
9648 pf
->hw
.phy
.get_link_info
= true;
9649 old_link
= (pf
->hw
.phy
.link_info_old
.link_info
& I40E_AQ_LINK_UP
);
9650 status
= i40e_get_link_status(&pf
->hw
, &new_link
);
9652 /* On success, disable temp link polling */
9653 if (status
== I40E_SUCCESS
) {
9654 clear_bit(__I40E_TEMP_LINK_POLLING
, pf
->state
);
9656 /* Enable link polling temporarily until i40e_get_link_status
9657 * returns I40E_SUCCESS
9659 set_bit(__I40E_TEMP_LINK_POLLING
, pf
->state
);
9660 dev_dbg(&pf
->pdev
->dev
, "couldn't get link state, status: %d\n",
9665 old_link_speed
= pf
->hw
.phy
.link_info_old
.link_speed
;
9666 new_link_speed
= pf
->hw
.phy
.link_info
.link_speed
;
9668 if (new_link
== old_link
&&
9669 new_link_speed
== old_link_speed
&&
9670 (test_bit(__I40E_VSI_DOWN
, vsi
->state
) ||
9671 new_link
== netif_carrier_ok(vsi
->netdev
)))
9674 i40e_print_link_message(vsi
, new_link
);
9676 /* Notify the base of the switch tree connected to
9677 * the link. Floating VEBs are not notified.
9679 if (pf
->lan_veb
< I40E_MAX_VEB
&& pf
->veb
[pf
->lan_veb
])
9680 i40e_veb_link_event(pf
->veb
[pf
->lan_veb
], new_link
);
9682 i40e_vsi_link_event(vsi
, new_link
);
9685 i40e_vc_notify_link_state(pf
);
9687 if (pf
->flags
& I40E_FLAG_PTP
)
9688 i40e_ptp_set_increment(pf
);
9689 #ifdef CONFIG_I40E_DCB
9690 if (new_link
== old_link
)
9692 /* Not SW DCB so firmware will take care of default settings */
9693 if (pf
->dcbx_cap
& DCB_CAP_DCBX_LLD_MANAGED
)
9696 /* We cover here only link down, as after link up in case of SW DCB
9697 * SW LLDP agent will take care of setting it up
9700 dev_dbg(&pf
->pdev
->dev
, "Reconfig DCB to single TC as result of Link Down\n");
9701 memset(&pf
->tmp_cfg
, 0, sizeof(pf
->tmp_cfg
));
9702 err
= i40e_dcb_sw_default_config(pf
);
9704 pf
->flags
&= ~(I40E_FLAG_DCB_CAPABLE
|
9705 I40E_FLAG_DCB_ENABLED
);
9707 pf
->dcbx_cap
= DCB_CAP_DCBX_HOST
|
9708 DCB_CAP_DCBX_VER_IEEE
;
9709 pf
->flags
|= I40E_FLAG_DCB_CAPABLE
;
9710 pf
->flags
&= ~I40E_FLAG_DCB_ENABLED
;
9713 #endif /* CONFIG_I40E_DCB */
9717 * i40e_watchdog_subtask - periodic checks not using event driven response
9718 * @pf: board private structure
9720 static void i40e_watchdog_subtask(struct i40e_pf
*pf
)
9724 /* if interface is down do nothing */
9725 if (test_bit(__I40E_DOWN
, pf
->state
) ||
9726 test_bit(__I40E_CONFIG_BUSY
, pf
->state
))
9729 /* make sure we don't do these things too often */
9730 if (time_before(jiffies
, (pf
->service_timer_previous
+
9731 pf
->service_timer_period
)))
9733 pf
->service_timer_previous
= jiffies
;
9735 if ((pf
->flags
& I40E_FLAG_LINK_POLLING_ENABLED
) ||
9736 test_bit(__I40E_TEMP_LINK_POLLING
, pf
->state
))
9737 i40e_link_event(pf
);
9739 /* Update the stats for active netdevs so the network stack
9740 * can look at updated numbers whenever it cares to
9742 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
9743 if (pf
->vsi
[i
] && pf
->vsi
[i
]->netdev
)
9744 i40e_update_stats(pf
->vsi
[i
]);
9746 if (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
) {
9747 /* Update the stats for the active switching components */
9748 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
9750 i40e_update_veb_stats(pf
->veb
[i
]);
9753 i40e_ptp_rx_hang(pf
);
9754 i40e_ptp_tx_hang(pf
);
9758 * i40e_reset_subtask - Set up for resetting the device and driver
9759 * @pf: board private structure
9761 static void i40e_reset_subtask(struct i40e_pf
*pf
)
9763 u32 reset_flags
= 0;
9765 if (test_bit(__I40E_REINIT_REQUESTED
, pf
->state
)) {
9766 reset_flags
|= BIT(__I40E_REINIT_REQUESTED
);
9767 clear_bit(__I40E_REINIT_REQUESTED
, pf
->state
);
9769 if (test_bit(__I40E_PF_RESET_REQUESTED
, pf
->state
)) {
9770 reset_flags
|= BIT(__I40E_PF_RESET_REQUESTED
);
9771 clear_bit(__I40E_PF_RESET_REQUESTED
, pf
->state
);
9773 if (test_bit(__I40E_CORE_RESET_REQUESTED
, pf
->state
)) {
9774 reset_flags
|= BIT(__I40E_CORE_RESET_REQUESTED
);
9775 clear_bit(__I40E_CORE_RESET_REQUESTED
, pf
->state
);
9777 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED
, pf
->state
)) {
9778 reset_flags
|= BIT(__I40E_GLOBAL_RESET_REQUESTED
);
9779 clear_bit(__I40E_GLOBAL_RESET_REQUESTED
, pf
->state
);
9781 if (test_bit(__I40E_DOWN_REQUESTED
, pf
->state
)) {
9782 reset_flags
|= BIT(__I40E_DOWN_REQUESTED
);
9783 clear_bit(__I40E_DOWN_REQUESTED
, pf
->state
);
9786 /* If there's a recovery already waiting, it takes
9787 * precedence before starting a new reset sequence.
9789 if (test_bit(__I40E_RESET_INTR_RECEIVED
, pf
->state
)) {
9790 i40e_prep_for_reset(pf
);
9792 i40e_rebuild(pf
, false, false);
9795 /* If we're already down or resetting, just bail */
9797 !test_bit(__I40E_DOWN
, pf
->state
) &&
9798 !test_bit(__I40E_CONFIG_BUSY
, pf
->state
)) {
9799 i40e_do_reset(pf
, reset_flags
, false);
9804 * i40e_handle_link_event - Handle link event
9805 * @pf: board private structure
9806 * @e: event info posted on ARQ
9808 static void i40e_handle_link_event(struct i40e_pf
*pf
,
9809 struct i40e_arq_event_info
*e
)
9811 struct i40e_aqc_get_link_status
*status
=
9812 (struct i40e_aqc_get_link_status
*)&e
->desc
.params
.raw
;
9814 /* Do a new status request to re-enable LSE reporting
9815 * and load new status information into the hw struct
9816 * This completely ignores any state information
9817 * in the ARQ event info, instead choosing to always
9818 * issue the AQ update link status command.
9820 i40e_link_event(pf
);
9822 /* Check if module meets thermal requirements */
9823 if (status
->phy_type
== I40E_PHY_TYPE_NOT_SUPPORTED_HIGH_TEMP
) {
9824 dev_err(&pf
->pdev
->dev
,
9825 "Rx/Tx is disabled on this device because the module does not meet thermal requirements.\n");
9826 dev_err(&pf
->pdev
->dev
,
9827 "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
9829 /* check for unqualified module, if link is down, suppress
9830 * the message if link was forced to be down.
9832 if ((status
->link_info
& I40E_AQ_MEDIA_AVAILABLE
) &&
9833 (!(status
->an_info
& I40E_AQ_QUALIFIED_MODULE
)) &&
9834 (!(status
->link_info
& I40E_AQ_LINK_UP
)) &&
9835 (!(pf
->flags
& I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED
))) {
9836 dev_err(&pf
->pdev
->dev
,
9837 "Rx/Tx is disabled on this device because an unsupported SFP module type was detected.\n");
9838 dev_err(&pf
->pdev
->dev
,
9839 "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
9845 * i40e_clean_adminq_subtask - Clean the AdminQ rings
9846 * @pf: board private structure
9848 static void i40e_clean_adminq_subtask(struct i40e_pf
*pf
)
9850 struct i40e_arq_event_info event
;
9851 struct i40e_hw
*hw
= &pf
->hw
;
9858 /* Do not run clean AQ when PF reset fails */
9859 if (test_bit(__I40E_RESET_FAILED
, pf
->state
))
9862 /* check for error indications */
9863 val
= rd32(&pf
->hw
, pf
->hw
.aq
.arq
.len
);
9865 if (val
& I40E_PF_ARQLEN_ARQVFE_MASK
) {
9866 if (hw
->debug_mask
& I40E_DEBUG_AQ
)
9867 dev_info(&pf
->pdev
->dev
, "ARQ VF Error detected\n");
9868 val
&= ~I40E_PF_ARQLEN_ARQVFE_MASK
;
9870 if (val
& I40E_PF_ARQLEN_ARQOVFL_MASK
) {
9871 if (hw
->debug_mask
& I40E_DEBUG_AQ
)
9872 dev_info(&pf
->pdev
->dev
, "ARQ Overflow Error detected\n");
9873 val
&= ~I40E_PF_ARQLEN_ARQOVFL_MASK
;
9874 pf
->arq_overflows
++;
9876 if (val
& I40E_PF_ARQLEN_ARQCRIT_MASK
) {
9877 if (hw
->debug_mask
& I40E_DEBUG_AQ
)
9878 dev_info(&pf
->pdev
->dev
, "ARQ Critical Error detected\n");
9879 val
&= ~I40E_PF_ARQLEN_ARQCRIT_MASK
;
9882 wr32(&pf
->hw
, pf
->hw
.aq
.arq
.len
, val
);
9884 val
= rd32(&pf
->hw
, pf
->hw
.aq
.asq
.len
);
9886 if (val
& I40E_PF_ATQLEN_ATQVFE_MASK
) {
9887 if (pf
->hw
.debug_mask
& I40E_DEBUG_AQ
)
9888 dev_info(&pf
->pdev
->dev
, "ASQ VF Error detected\n");
9889 val
&= ~I40E_PF_ATQLEN_ATQVFE_MASK
;
9891 if (val
& I40E_PF_ATQLEN_ATQOVFL_MASK
) {
9892 if (pf
->hw
.debug_mask
& I40E_DEBUG_AQ
)
9893 dev_info(&pf
->pdev
->dev
, "ASQ Overflow Error detected\n");
9894 val
&= ~I40E_PF_ATQLEN_ATQOVFL_MASK
;
9896 if (val
& I40E_PF_ATQLEN_ATQCRIT_MASK
) {
9897 if (pf
->hw
.debug_mask
& I40E_DEBUG_AQ
)
9898 dev_info(&pf
->pdev
->dev
, "ASQ Critical Error detected\n");
9899 val
&= ~I40E_PF_ATQLEN_ATQCRIT_MASK
;
9902 wr32(&pf
->hw
, pf
->hw
.aq
.asq
.len
, val
);
9904 event
.buf_len
= I40E_MAX_AQ_BUF_SIZE
;
9905 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
9910 ret
= i40e_clean_arq_element(hw
, &event
, &pending
);
9911 if (ret
== I40E_ERR_ADMIN_QUEUE_NO_WORK
)
9914 dev_info(&pf
->pdev
->dev
, "ARQ event error %d\n", ret
);
9918 opcode
= le16_to_cpu(event
.desc
.opcode
);
9921 case i40e_aqc_opc_get_link_status
:
9923 i40e_handle_link_event(pf
, &event
);
9926 case i40e_aqc_opc_send_msg_to_pf
:
9927 ret
= i40e_vc_process_vf_msg(pf
,
9928 le16_to_cpu(event
.desc
.retval
),
9929 le32_to_cpu(event
.desc
.cookie_high
),
9930 le32_to_cpu(event
.desc
.cookie_low
),
9934 case i40e_aqc_opc_lldp_update_mib
:
9935 dev_dbg(&pf
->pdev
->dev
, "ARQ: Update LLDP MIB event received\n");
9936 #ifdef CONFIG_I40E_DCB
9938 i40e_handle_lldp_event(pf
, &event
);
9940 #endif /* CONFIG_I40E_DCB */
9942 case i40e_aqc_opc_event_lan_overflow
:
9943 dev_dbg(&pf
->pdev
->dev
, "ARQ LAN queue overflow event received\n");
9944 i40e_handle_lan_overflow_event(pf
, &event
);
9946 case i40e_aqc_opc_send_msg_to_peer
:
9947 dev_info(&pf
->pdev
->dev
, "ARQ: Msg from other pf\n");
9949 case i40e_aqc_opc_nvm_erase
:
9950 case i40e_aqc_opc_nvm_update
:
9951 case i40e_aqc_opc_oem_post_update
:
9952 i40e_debug(&pf
->hw
, I40E_DEBUG_NVM
,
9953 "ARQ NVM operation 0x%04x completed\n",
9957 dev_info(&pf
->pdev
->dev
,
9958 "ARQ: Unknown event 0x%04x ignored\n",
9962 } while (i
++ < pf
->adminq_work_limit
);
9964 if (i
< pf
->adminq_work_limit
)
9965 clear_bit(__I40E_ADMINQ_EVENT_PENDING
, pf
->state
);
9967 /* re-enable Admin queue interrupt cause */
9968 val
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
9969 val
|= I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
9970 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
9973 kfree(event
.msg_buf
);
9977 * i40e_verify_eeprom - make sure eeprom is good to use
9978 * @pf: board private structure
9980 static void i40e_verify_eeprom(struct i40e_pf
*pf
)
9984 err
= i40e_diag_eeprom_test(&pf
->hw
);
9986 /* retry in case of garbage read */
9987 err
= i40e_diag_eeprom_test(&pf
->hw
);
9989 dev_info(&pf
->pdev
->dev
, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
9991 set_bit(__I40E_BAD_EEPROM
, pf
->state
);
9995 if (!err
&& test_bit(__I40E_BAD_EEPROM
, pf
->state
)) {
9996 dev_info(&pf
->pdev
->dev
, "eeprom check passed, Tx/Rx traffic enabled\n");
9997 clear_bit(__I40E_BAD_EEPROM
, pf
->state
);
10002 * i40e_enable_pf_switch_lb
10003 * @pf: pointer to the PF structure
10005 * enable switch loop back or die - no point in a return value
10007 static void i40e_enable_pf_switch_lb(struct i40e_pf
*pf
)
10009 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
10010 struct i40e_vsi_context ctxt
;
10013 ctxt
.seid
= pf
->main_vsi_seid
;
10014 ctxt
.pf_num
= pf
->hw
.pf_id
;
10016 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
10018 dev_info(&pf
->pdev
->dev
,
10019 "couldn't get PF vsi config, err %s aq_err %s\n",
10020 i40e_stat_str(&pf
->hw
, ret
),
10021 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10024 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
10025 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
10026 ctxt
.info
.switch_id
|= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
10028 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
10030 dev_info(&pf
->pdev
->dev
,
10031 "update vsi switch failed, err %s aq_err %s\n",
10032 i40e_stat_str(&pf
->hw
, ret
),
10033 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10038 * i40e_disable_pf_switch_lb
10039 * @pf: pointer to the PF structure
10041 * disable switch loop back or die - no point in a return value
10043 static void i40e_disable_pf_switch_lb(struct i40e_pf
*pf
)
10045 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
10046 struct i40e_vsi_context ctxt
;
10049 ctxt
.seid
= pf
->main_vsi_seid
;
10050 ctxt
.pf_num
= pf
->hw
.pf_id
;
10052 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
10054 dev_info(&pf
->pdev
->dev
,
10055 "couldn't get PF vsi config, err %s aq_err %s\n",
10056 i40e_stat_str(&pf
->hw
, ret
),
10057 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10060 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
10061 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
10062 ctxt
.info
.switch_id
&= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
10064 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
10066 dev_info(&pf
->pdev
->dev
,
10067 "update vsi switch failed, err %s aq_err %s\n",
10068 i40e_stat_str(&pf
->hw
, ret
),
10069 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10074 * i40e_config_bridge_mode - Configure the HW bridge mode
10075 * @veb: pointer to the bridge instance
10077 * Configure the loop back mode for the LAN VSI that is downlink to the
10078 * specified HW bridge instance. It is expected this function is called
10079 * when a new HW bridge is instantiated.
10081 static void i40e_config_bridge_mode(struct i40e_veb
*veb
)
10083 struct i40e_pf
*pf
= veb
->pf
;
10085 if (pf
->hw
.debug_mask
& I40E_DEBUG_LAN
)
10086 dev_info(&pf
->pdev
->dev
, "enabling bridge mode: %s\n",
10087 veb
->bridge_mode
== BRIDGE_MODE_VEPA
? "VEPA" : "VEB");
10088 if (veb
->bridge_mode
& BRIDGE_MODE_VEPA
)
10089 i40e_disable_pf_switch_lb(pf
);
10091 i40e_enable_pf_switch_lb(pf
);
10095 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
10096 * @veb: pointer to the VEB instance
10098 * This is a recursive function that first builds the attached VSIs then
10099 * recurses in to build the next layer of VEB. We track the connections
10100 * through our own index numbers because the seid's from the HW could
10101 * change across the reset.
10103 static int i40e_reconstitute_veb(struct i40e_veb
*veb
)
10105 struct i40e_vsi
*ctl_vsi
= NULL
;
10106 struct i40e_pf
*pf
= veb
->pf
;
10110 /* build VSI that owns this VEB, temporarily attached to base VEB */
10111 for (v
= 0; v
< pf
->num_alloc_vsi
&& !ctl_vsi
; v
++) {
10113 pf
->vsi
[v
]->veb_idx
== veb
->idx
&&
10114 pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
10115 ctl_vsi
= pf
->vsi
[v
];
10120 dev_info(&pf
->pdev
->dev
,
10121 "missing owner VSI for veb_idx %d\n", veb
->idx
);
10123 goto end_reconstitute
;
10125 if (ctl_vsi
!= pf
->vsi
[pf
->lan_vsi
])
10126 ctl_vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
10127 ret
= i40e_add_vsi(ctl_vsi
);
10129 dev_info(&pf
->pdev
->dev
,
10130 "rebuild of veb_idx %d owner VSI failed: %d\n",
10132 goto end_reconstitute
;
10134 i40e_vsi_reset_stats(ctl_vsi
);
10136 /* create the VEB in the switch and move the VSI onto the VEB */
10137 ret
= i40e_add_veb(veb
, ctl_vsi
);
10139 goto end_reconstitute
;
10141 if (pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)
10142 veb
->bridge_mode
= BRIDGE_MODE_VEB
;
10144 veb
->bridge_mode
= BRIDGE_MODE_VEPA
;
10145 i40e_config_bridge_mode(veb
);
10147 /* create the remaining VSIs attached to this VEB */
10148 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
10149 if (!pf
->vsi
[v
] || pf
->vsi
[v
] == ctl_vsi
)
10152 if (pf
->vsi
[v
]->veb_idx
== veb
->idx
) {
10153 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
10155 vsi
->uplink_seid
= veb
->seid
;
10156 ret
= i40e_add_vsi(vsi
);
10158 dev_info(&pf
->pdev
->dev
,
10159 "rebuild of vsi_idx %d failed: %d\n",
10161 goto end_reconstitute
;
10163 i40e_vsi_reset_stats(vsi
);
10167 /* create any VEBs attached to this VEB - RECURSION */
10168 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
10169 if (pf
->veb
[veb_idx
] && pf
->veb
[veb_idx
]->veb_idx
== veb
->idx
) {
10170 pf
->veb
[veb_idx
]->uplink_seid
= veb
->seid
;
10171 ret
= i40e_reconstitute_veb(pf
->veb
[veb_idx
]);
10182 * i40e_get_capabilities - get info about the HW
10183 * @pf: the PF struct
10184 * @list_type: AQ capability to be queried
10186 static int i40e_get_capabilities(struct i40e_pf
*pf
,
10187 enum i40e_admin_queue_opc list_type
)
10189 struct i40e_aqc_list_capabilities_element_resp
*cap_buf
;
10194 buf_len
= 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp
);
10196 cap_buf
= kzalloc(buf_len
, GFP_KERNEL
);
10200 /* this loads the data into the hw struct for us */
10201 err
= i40e_aq_discover_capabilities(&pf
->hw
, cap_buf
, buf_len
,
10202 &data_size
, list_type
,
10204 /* data loaded, buffer no longer needed */
10207 if (pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_ENOMEM
) {
10208 /* retry with a larger buffer */
10209 buf_len
= data_size
;
10210 } else if (pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_OK
|| err
) {
10211 dev_info(&pf
->pdev
->dev
,
10212 "capability discovery failed, err %s aq_err %s\n",
10213 i40e_stat_str(&pf
->hw
, err
),
10214 i40e_aq_str(&pf
->hw
,
10215 pf
->hw
.aq
.asq_last_status
));
10220 if (pf
->hw
.debug_mask
& I40E_DEBUG_USER
) {
10221 if (list_type
== i40e_aqc_opc_list_func_capabilities
) {
10222 dev_info(&pf
->pdev
->dev
,
10223 "pf=%d, num_vfs=%d, msix_pf=%d, msix_vf=%d, fd_g=%d, fd_b=%d, pf_max_q=%d num_vsi=%d\n",
10224 pf
->hw
.pf_id
, pf
->hw
.func_caps
.num_vfs
,
10225 pf
->hw
.func_caps
.num_msix_vectors
,
10226 pf
->hw
.func_caps
.num_msix_vectors_vf
,
10227 pf
->hw
.func_caps
.fd_filters_guaranteed
,
10228 pf
->hw
.func_caps
.fd_filters_best_effort
,
10229 pf
->hw
.func_caps
.num_tx_qp
,
10230 pf
->hw
.func_caps
.num_vsis
);
10231 } else if (list_type
== i40e_aqc_opc_list_dev_capabilities
) {
10232 dev_info(&pf
->pdev
->dev
,
10233 "switch_mode=0x%04x, function_valid=0x%08x\n",
10234 pf
->hw
.dev_caps
.switch_mode
,
10235 pf
->hw
.dev_caps
.valid_functions
);
10236 dev_info(&pf
->pdev
->dev
,
10237 "SR-IOV=%d, num_vfs for all function=%u\n",
10238 pf
->hw
.dev_caps
.sr_iov_1_1
,
10239 pf
->hw
.dev_caps
.num_vfs
);
10240 dev_info(&pf
->pdev
->dev
,
10241 "num_vsis=%u, num_rx:%u, num_tx=%u\n",
10242 pf
->hw
.dev_caps
.num_vsis
,
10243 pf
->hw
.dev_caps
.num_rx_qp
,
10244 pf
->hw
.dev_caps
.num_tx_qp
);
10247 if (list_type
== i40e_aqc_opc_list_func_capabilities
) {
10248 #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
10249 + pf->hw.func_caps.num_vfs)
10250 if (pf
->hw
.revision_id
== 0 &&
10251 pf
->hw
.func_caps
.num_vsis
< DEF_NUM_VSI
) {
10252 dev_info(&pf
->pdev
->dev
,
10253 "got num_vsis %d, setting num_vsis to %d\n",
10254 pf
->hw
.func_caps
.num_vsis
, DEF_NUM_VSI
);
10255 pf
->hw
.func_caps
.num_vsis
= DEF_NUM_VSI
;
10261 static int i40e_vsi_clear(struct i40e_vsi
*vsi
);
10264 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
10265 * @pf: board private structure
10267 static void i40e_fdir_sb_setup(struct i40e_pf
*pf
)
10269 struct i40e_vsi
*vsi
;
10271 /* quick workaround for an NVM issue that leaves a critical register
10274 if (!rd32(&pf
->hw
, I40E_GLQF_HKEY(0))) {
10275 static const u32 hkey
[] = {
10276 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
10277 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
10278 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
10282 for (i
= 0; i
<= I40E_GLQF_HKEY_MAX_INDEX
; i
++)
10283 wr32(&pf
->hw
, I40E_GLQF_HKEY(i
), hkey
[i
]);
10286 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
10289 /* find existing VSI and see if it needs configuring */
10290 vsi
= i40e_find_vsi_by_type(pf
, I40E_VSI_FDIR
);
10292 /* create a new VSI if none exists */
10294 vsi
= i40e_vsi_setup(pf
, I40E_VSI_FDIR
,
10295 pf
->vsi
[pf
->lan_vsi
]->seid
, 0);
10297 dev_info(&pf
->pdev
->dev
, "Couldn't create FDir VSI\n");
10298 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
10299 pf
->flags
|= I40E_FLAG_FD_SB_INACTIVE
;
10304 i40e_vsi_setup_irqhandler(vsi
, i40e_fdir_clean_ring
);
10308 * i40e_fdir_teardown - release the Flow Director resources
10309 * @pf: board private structure
10311 static void i40e_fdir_teardown(struct i40e_pf
*pf
)
10313 struct i40e_vsi
*vsi
;
10315 i40e_fdir_filter_exit(pf
);
10316 vsi
= i40e_find_vsi_by_type(pf
, I40E_VSI_FDIR
);
10318 i40e_vsi_release(vsi
);
10322 * i40e_rebuild_cloud_filters - Rebuilds cloud filters for VSIs
10323 * @vsi: PF main vsi
10324 * @seid: seid of main or channel VSIs
10326 * Rebuilds cloud filters associated with main VSI and channel VSIs if they
10327 * existed before reset
10329 static int i40e_rebuild_cloud_filters(struct i40e_vsi
*vsi
, u16 seid
)
10331 struct i40e_cloud_filter
*cfilter
;
10332 struct i40e_pf
*pf
= vsi
->back
;
10333 struct hlist_node
*node
;
10336 /* Add cloud filters back if they exist */
10337 hlist_for_each_entry_safe(cfilter
, node
, &pf
->cloud_filter_list
,
10339 if (cfilter
->seid
!= seid
)
10342 if (cfilter
->dst_port
)
10343 ret
= i40e_add_del_cloud_filter_big_buf(vsi
, cfilter
,
10346 ret
= i40e_add_del_cloud_filter(vsi
, cfilter
, true);
10349 dev_dbg(&pf
->pdev
->dev
,
10350 "Failed to rebuild cloud filter, err %s aq_err %s\n",
10351 i40e_stat_str(&pf
->hw
, ret
),
10352 i40e_aq_str(&pf
->hw
,
10353 pf
->hw
.aq
.asq_last_status
));
10361 * i40e_rebuild_channels - Rebuilds channel VSIs if they existed before reset
10362 * @vsi: PF main vsi
10364 * Rebuilds channel VSIs if they existed before reset
10366 static int i40e_rebuild_channels(struct i40e_vsi
*vsi
)
10368 struct i40e_channel
*ch
, *ch_tmp
;
10371 if (list_empty(&vsi
->ch_list
))
10374 list_for_each_entry_safe(ch
, ch_tmp
, &vsi
->ch_list
, list
) {
10375 if (!ch
->initialized
)
10377 /* Proceed with creation of channel (VMDq2) VSI */
10378 ret
= i40e_add_channel(vsi
->back
, vsi
->uplink_seid
, ch
);
10380 dev_info(&vsi
->back
->pdev
->dev
,
10381 "failed to rebuild channels using uplink_seid %u\n",
10385 /* Reconfigure TX queues using QTX_CTL register */
10386 ret
= i40e_channel_config_tx_ring(vsi
->back
, vsi
, ch
);
10388 dev_info(&vsi
->back
->pdev
->dev
,
10389 "failed to configure TX rings for channel %u\n",
10393 /* update 'next_base_queue' */
10394 vsi
->next_base_queue
= vsi
->next_base_queue
+
10395 ch
->num_queue_pairs
;
10396 if (ch
->max_tx_rate
) {
10397 u64 credits
= ch
->max_tx_rate
;
10399 if (i40e_set_bw_limit(vsi
, ch
->seid
,
10403 do_div(credits
, I40E_BW_CREDIT_DIVISOR
);
10404 dev_dbg(&vsi
->back
->pdev
->dev
,
10405 "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
10410 ret
= i40e_rebuild_cloud_filters(vsi
, ch
->seid
);
10412 dev_dbg(&vsi
->back
->pdev
->dev
,
10413 "Failed to rebuild cloud filters for channel VSI %u\n",
10422 * i40e_prep_for_reset - prep for the core to reset
10423 * @pf: board private structure
10425 * Close up the VFs and other things in prep for PF Reset.
10427 static void i40e_prep_for_reset(struct i40e_pf
*pf
)
10429 struct i40e_hw
*hw
= &pf
->hw
;
10430 i40e_status ret
= 0;
10433 clear_bit(__I40E_RESET_INTR_RECEIVED
, pf
->state
);
10434 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
))
10436 if (i40e_check_asq_alive(&pf
->hw
))
10437 i40e_vc_notify_reset(pf
);
10439 dev_dbg(&pf
->pdev
->dev
, "Tearing down internal switch for reset\n");
10441 /* quiesce the VSIs and their queues that are not already DOWN */
10442 i40e_pf_quiesce_all_vsi(pf
);
10444 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
10446 pf
->vsi
[v
]->seid
= 0;
10449 i40e_shutdown_adminq(&pf
->hw
);
10451 /* call shutdown HMC */
10452 if (hw
->hmc
.hmc_obj
) {
10453 ret
= i40e_shutdown_lan_hmc(hw
);
10455 dev_warn(&pf
->pdev
->dev
,
10456 "shutdown_lan_hmc failed: %d\n", ret
);
10459 /* Save the current PTP time so that we can restore the time after the
10462 i40e_ptp_save_hw_time(pf
);
10466 * i40e_send_version - update firmware with driver version
10469 static void i40e_send_version(struct i40e_pf
*pf
)
10471 struct i40e_driver_version dv
;
10473 dv
.major_version
= 0xff;
10474 dv
.minor_version
= 0xff;
10475 dv
.build_version
= 0xff;
10476 dv
.subbuild_version
= 0;
10477 strlcpy(dv
.driver_string
, UTS_RELEASE
, sizeof(dv
.driver_string
));
10478 i40e_aq_send_driver_version(&pf
->hw
, &dv
, NULL
);
10482 * i40e_get_oem_version - get OEM specific version information
10483 * @hw: pointer to the hardware structure
10485 static void i40e_get_oem_version(struct i40e_hw
*hw
)
10487 u16 block_offset
= 0xffff;
10488 u16 block_length
= 0;
10489 u16 capabilities
= 0;
10493 #define I40E_SR_NVM_OEM_VERSION_PTR 0x1B
10494 #define I40E_NVM_OEM_LENGTH_OFFSET 0x00
10495 #define I40E_NVM_OEM_CAPABILITIES_OFFSET 0x01
10496 #define I40E_NVM_OEM_GEN_OFFSET 0x02
10497 #define I40E_NVM_OEM_RELEASE_OFFSET 0x03
10498 #define I40E_NVM_OEM_CAPABILITIES_MASK 0x000F
10499 #define I40E_NVM_OEM_LENGTH 3
10501 /* Check if pointer to OEM version block is valid. */
10502 i40e_read_nvm_word(hw
, I40E_SR_NVM_OEM_VERSION_PTR
, &block_offset
);
10503 if (block_offset
== 0xffff)
10506 /* Check if OEM version block has correct length. */
10507 i40e_read_nvm_word(hw
, block_offset
+ I40E_NVM_OEM_LENGTH_OFFSET
,
10509 if (block_length
< I40E_NVM_OEM_LENGTH
)
10512 /* Check if OEM version format is as expected. */
10513 i40e_read_nvm_word(hw
, block_offset
+ I40E_NVM_OEM_CAPABILITIES_OFFSET
,
10515 if ((capabilities
& I40E_NVM_OEM_CAPABILITIES_MASK
) != 0)
10518 i40e_read_nvm_word(hw
, block_offset
+ I40E_NVM_OEM_GEN_OFFSET
,
10520 i40e_read_nvm_word(hw
, block_offset
+ I40E_NVM_OEM_RELEASE_OFFSET
,
10522 hw
->nvm
.oem_ver
= (gen_snap
<< I40E_OEM_SNAP_SHIFT
) | release
;
10523 hw
->nvm
.eetrack
= I40E_OEM_EETRACK_ID
;
10527 * i40e_reset - wait for core reset to finish reset, reset pf if corer not seen
10528 * @pf: board private structure
10530 static int i40e_reset(struct i40e_pf
*pf
)
10532 struct i40e_hw
*hw
= &pf
->hw
;
10535 ret
= i40e_pf_reset(hw
);
10537 dev_info(&pf
->pdev
->dev
, "PF reset failed, %d\n", ret
);
10538 set_bit(__I40E_RESET_FAILED
, pf
->state
);
10539 clear_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
);
10547 * i40e_rebuild - rebuild using a saved config
10548 * @pf: board private structure
10549 * @reinit: if the Main VSI needs to re-initialized.
10550 * @lock_acquired: indicates whether or not the lock has been acquired
10551 * before this function was called.
10553 static void i40e_rebuild(struct i40e_pf
*pf
, bool reinit
, bool lock_acquired
)
10555 int old_recovery_mode_bit
= test_bit(__I40E_RECOVERY_MODE
, pf
->state
);
10556 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
10557 struct i40e_hw
*hw
= &pf
->hw
;
10562 if (test_bit(__I40E_EMP_RESET_INTR_RECEIVED
, pf
->state
) &&
10563 i40e_check_recovery_mode(pf
)) {
10564 i40e_set_ethtool_ops(pf
->vsi
[pf
->lan_vsi
]->netdev
);
10567 if (test_bit(__I40E_DOWN
, pf
->state
) &&
10568 !test_bit(__I40E_RECOVERY_MODE
, pf
->state
) &&
10569 !old_recovery_mode_bit
)
10570 goto clear_recovery
;
10571 dev_dbg(&pf
->pdev
->dev
, "Rebuilding internal switch\n");
10573 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
10574 ret
= i40e_init_adminq(&pf
->hw
);
10576 dev_info(&pf
->pdev
->dev
, "Rebuild AdminQ failed, err %s aq_err %s\n",
10577 i40e_stat_str(&pf
->hw
, ret
),
10578 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10579 goto clear_recovery
;
10581 i40e_get_oem_version(&pf
->hw
);
10583 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED
, pf
->state
)) {
10584 /* The following delay is necessary for firmware update. */
10588 /* re-verify the eeprom if we just had an EMP reset */
10589 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED
, pf
->state
))
10590 i40e_verify_eeprom(pf
);
10592 /* if we are going out of or into recovery mode we have to act
10593 * accordingly with regard to resources initialization
10594 * and deinitialization
10596 if (test_bit(__I40E_RECOVERY_MODE
, pf
->state
) ||
10597 old_recovery_mode_bit
) {
10598 if (i40e_get_capabilities(pf
,
10599 i40e_aqc_opc_list_func_capabilities
))
10602 if (test_bit(__I40E_RECOVERY_MODE
, pf
->state
)) {
10603 /* we're staying in recovery mode so we'll reinitialize
10606 if (i40e_setup_misc_vector_for_recovery_mode(pf
))
10609 if (!lock_acquired
)
10611 /* we're going out of recovery mode so we'll free
10612 * the IRQ allocated specifically for recovery mode
10613 * and restore the interrupt scheme
10615 free_irq(pf
->pdev
->irq
, pf
);
10616 i40e_clear_interrupt_scheme(pf
);
10617 if (i40e_restore_interrupt_scheme(pf
))
10621 /* tell the firmware that we're starting */
10622 i40e_send_version(pf
);
10624 /* bail out in case recovery mode was detected, as there is
10625 * no need for further configuration.
10630 i40e_clear_pxe_mode(hw
);
10631 ret
= i40e_get_capabilities(pf
, i40e_aqc_opc_list_func_capabilities
);
10633 goto end_core_reset
;
10635 ret
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
10636 hw
->func_caps
.num_rx_qp
, 0, 0);
10638 dev_info(&pf
->pdev
->dev
, "init_lan_hmc failed: %d\n", ret
);
10639 goto end_core_reset
;
10641 ret
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
10643 dev_info(&pf
->pdev
->dev
, "configure_lan_hmc failed: %d\n", ret
);
10644 goto end_core_reset
;
10647 #ifdef CONFIG_I40E_DCB
10648 /* Enable FW to write a default DCB config on link-up
10649 * unless I40E_FLAG_TC_MQPRIO was enabled or DCB
10650 * is not supported with new link speed
10652 if (pf
->flags
& I40E_FLAG_TC_MQPRIO
) {
10653 i40e_aq_set_dcb_parameters(hw
, false, NULL
);
10655 if (I40E_IS_X710TL_DEVICE(hw
->device_id
) &&
10656 (hw
->phy
.link_info
.link_speed
&
10657 (I40E_LINK_SPEED_2_5GB
| I40E_LINK_SPEED_5GB
))) {
10658 i40e_aq_set_dcb_parameters(hw
, false, NULL
);
10659 dev_warn(&pf
->pdev
->dev
,
10660 "DCB is not supported for X710-T*L 2.5/5G speeds\n");
10661 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
10663 i40e_aq_set_dcb_parameters(hw
, true, NULL
);
10664 ret
= i40e_init_pf_dcb(pf
);
10666 dev_info(&pf
->pdev
->dev
, "DCB init failed %d, disabled\n",
10668 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
10669 /* Continue without DCB enabled */
10674 #endif /* CONFIG_I40E_DCB */
10675 if (!lock_acquired
)
10677 ret
= i40e_setup_pf_switch(pf
, reinit
, true);
10681 /* The driver only wants link up/down and module qualification
10682 * reports from firmware. Note the negative logic.
10684 ret
= i40e_aq_set_phy_int_mask(&pf
->hw
,
10685 ~(I40E_AQ_EVENT_LINK_UPDOWN
|
10686 I40E_AQ_EVENT_MEDIA_NA
|
10687 I40E_AQ_EVENT_MODULE_QUAL_FAIL
), NULL
);
10689 dev_info(&pf
->pdev
->dev
, "set phy mask fail, err %s aq_err %s\n",
10690 i40e_stat_str(&pf
->hw
, ret
),
10691 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10693 /* Rebuild the VSIs and VEBs that existed before reset.
10694 * They are still in our local switch element arrays, so only
10695 * need to rebuild the switch model in the HW.
10697 * If there were VEBs but the reconstitution failed, we'll try
10698 * to recover minimal use by getting the basic PF VSI working.
10700 if (vsi
->uplink_seid
!= pf
->mac_seid
) {
10701 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild switch\n");
10702 /* find the one VEB connected to the MAC, and find orphans */
10703 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
10707 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
||
10708 pf
->veb
[v
]->uplink_seid
== 0) {
10709 ret
= i40e_reconstitute_veb(pf
->veb
[v
]);
10714 /* If Main VEB failed, we're in deep doodoo,
10715 * so give up rebuilding the switch and set up
10716 * for minimal rebuild of PF VSI.
10717 * If orphan failed, we'll report the error
10718 * but try to keep going.
10720 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
) {
10721 dev_info(&pf
->pdev
->dev
,
10722 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
10724 vsi
->uplink_seid
= pf
->mac_seid
;
10726 } else if (pf
->veb
[v
]->uplink_seid
== 0) {
10727 dev_info(&pf
->pdev
->dev
,
10728 "rebuild of orphan VEB failed: %d\n",
10735 if (vsi
->uplink_seid
== pf
->mac_seid
) {
10736 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild PF VSI\n");
10737 /* no VEB, so rebuild only the Main VSI */
10738 ret
= i40e_add_vsi(vsi
);
10740 dev_info(&pf
->pdev
->dev
,
10741 "rebuild of Main VSI failed: %d\n", ret
);
10746 if (vsi
->mqprio_qopt
.max_rate
[0]) {
10747 u64 max_tx_rate
= vsi
->mqprio_qopt
.max_rate
[0];
10750 do_div(max_tx_rate
, I40E_BW_MBPS_DIVISOR
);
10751 ret
= i40e_set_bw_limit(vsi
, vsi
->seid
, max_tx_rate
);
10755 credits
= max_tx_rate
;
10756 do_div(credits
, I40E_BW_CREDIT_DIVISOR
);
10757 dev_dbg(&vsi
->back
->pdev
->dev
,
10758 "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
10764 ret
= i40e_rebuild_cloud_filters(vsi
, vsi
->seid
);
10768 /* PF Main VSI is rebuild by now, go ahead and rebuild channel VSIs
10769 * for this main VSI if they exist
10771 ret
= i40e_rebuild_channels(vsi
);
10775 /* Reconfigure hardware for allowing smaller MSS in the case
10776 * of TSO, so that we avoid the MDD being fired and causing
10777 * a reset in the case of small MSS+TSO.
10779 #define I40E_REG_MSS 0x000E64DC
10780 #define I40E_REG_MSS_MIN_MASK 0x3FF0000
10781 #define I40E_64BYTE_MSS 0x400000
10782 val
= rd32(hw
, I40E_REG_MSS
);
10783 if ((val
& I40E_REG_MSS_MIN_MASK
) > I40E_64BYTE_MSS
) {
10784 val
&= ~I40E_REG_MSS_MIN_MASK
;
10785 val
|= I40E_64BYTE_MSS
;
10786 wr32(hw
, I40E_REG_MSS
, val
);
10789 if (pf
->hw_features
& I40E_HW_RESTART_AUTONEG
) {
10791 ret
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
10793 dev_info(&pf
->pdev
->dev
, "link restart failed, err %s aq_err %s\n",
10794 i40e_stat_str(&pf
->hw
, ret
),
10795 i40e_aq_str(&pf
->hw
,
10796 pf
->hw
.aq
.asq_last_status
));
10798 /* reinit the misc interrupt */
10799 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
10800 ret
= i40e_setup_misc_vector(pf
);
10802 /* Add a filter to drop all Flow control frames from any VSI from being
10803 * transmitted. By doing so we stop a malicious VF from sending out
10804 * PAUSE or PFC frames and potentially controlling traffic for other
10806 * The FW can still send Flow control frames if enabled.
10808 i40e_add_filter_to_drop_tx_flow_control_frames(&pf
->hw
,
10809 pf
->main_vsi_seid
);
10811 /* restart the VSIs that were rebuilt and running before the reset */
10812 i40e_pf_unquiesce_all_vsi(pf
);
10814 /* Release the RTNL lock before we start resetting VFs */
10815 if (!lock_acquired
)
10818 /* Restore promiscuous settings */
10819 ret
= i40e_set_promiscuous(pf
, pf
->cur_promisc
);
10821 dev_warn(&pf
->pdev
->dev
,
10822 "Failed to restore promiscuous setting: %s, err %s aq_err %s\n",
10823 pf
->cur_promisc
? "on" : "off",
10824 i40e_stat_str(&pf
->hw
, ret
),
10825 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10827 i40e_reset_all_vfs(pf
, true);
10829 /* tell the firmware that we're starting */
10830 i40e_send_version(pf
);
10832 /* We've already released the lock, so don't do it again */
10833 goto end_core_reset
;
10836 if (!lock_acquired
)
10839 clear_bit(__I40E_RESET_FAILED
, pf
->state
);
10841 clear_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
);
10842 clear_bit(__I40E_TIMEOUT_RECOVERY_PENDING
, pf
->state
);
10846 * i40e_reset_and_rebuild - reset and rebuild using a saved config
10847 * @pf: board private structure
10848 * @reinit: if the Main VSI needs to re-initialized.
10849 * @lock_acquired: indicates whether or not the lock has been acquired
10850 * before this function was called.
10852 static void i40e_reset_and_rebuild(struct i40e_pf
*pf
, bool reinit
,
10853 bool lock_acquired
)
10856 /* Now we wait for GRST to settle out.
10857 * We don't have to delete the VEBs or VSIs from the hw switch
10858 * because the reset will make them disappear.
10860 ret
= i40e_reset(pf
);
10862 i40e_rebuild(pf
, reinit
, lock_acquired
);
10866 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
10867 * @pf: board private structure
10869 * Close up the VFs and other things in prep for a Core Reset,
10870 * then get ready to rebuild the world.
10871 * @lock_acquired: indicates whether or not the lock has been acquired
10872 * before this function was called.
10874 static void i40e_handle_reset_warning(struct i40e_pf
*pf
, bool lock_acquired
)
10876 i40e_prep_for_reset(pf
);
10877 i40e_reset_and_rebuild(pf
, false, lock_acquired
);
10881 * i40e_handle_mdd_event
10882 * @pf: pointer to the PF structure
10884 * Called from the MDD irq handler to identify possibly malicious vfs
10886 static void i40e_handle_mdd_event(struct i40e_pf
*pf
)
10888 struct i40e_hw
*hw
= &pf
->hw
;
10889 bool mdd_detected
= false;
10890 struct i40e_vf
*vf
;
10894 if (!test_bit(__I40E_MDD_EVENT_PENDING
, pf
->state
))
10897 /* find what triggered the MDD event */
10898 reg
= rd32(hw
, I40E_GL_MDET_TX
);
10899 if (reg
& I40E_GL_MDET_TX_VALID_MASK
) {
10900 u8 pf_num
= (reg
& I40E_GL_MDET_TX_PF_NUM_MASK
) >>
10901 I40E_GL_MDET_TX_PF_NUM_SHIFT
;
10902 u16 vf_num
= (reg
& I40E_GL_MDET_TX_VF_NUM_MASK
) >>
10903 I40E_GL_MDET_TX_VF_NUM_SHIFT
;
10904 u8 event
= (reg
& I40E_GL_MDET_TX_EVENT_MASK
) >>
10905 I40E_GL_MDET_TX_EVENT_SHIFT
;
10906 u16 queue
= ((reg
& I40E_GL_MDET_TX_QUEUE_MASK
) >>
10907 I40E_GL_MDET_TX_QUEUE_SHIFT
) -
10908 pf
->hw
.func_caps
.base_queue
;
10909 if (netif_msg_tx_err(pf
))
10910 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
10911 event
, queue
, pf_num
, vf_num
);
10912 wr32(hw
, I40E_GL_MDET_TX
, 0xffffffff);
10913 mdd_detected
= true;
10915 reg
= rd32(hw
, I40E_GL_MDET_RX
);
10916 if (reg
& I40E_GL_MDET_RX_VALID_MASK
) {
10917 u8 func
= (reg
& I40E_GL_MDET_RX_FUNCTION_MASK
) >>
10918 I40E_GL_MDET_RX_FUNCTION_SHIFT
;
10919 u8 event
= (reg
& I40E_GL_MDET_RX_EVENT_MASK
) >>
10920 I40E_GL_MDET_RX_EVENT_SHIFT
;
10921 u16 queue
= ((reg
& I40E_GL_MDET_RX_QUEUE_MASK
) >>
10922 I40E_GL_MDET_RX_QUEUE_SHIFT
) -
10923 pf
->hw
.func_caps
.base_queue
;
10924 if (netif_msg_rx_err(pf
))
10925 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
10926 event
, queue
, func
);
10927 wr32(hw
, I40E_GL_MDET_RX
, 0xffffffff);
10928 mdd_detected
= true;
10931 if (mdd_detected
) {
10932 reg
= rd32(hw
, I40E_PF_MDET_TX
);
10933 if (reg
& I40E_PF_MDET_TX_VALID_MASK
) {
10934 wr32(hw
, I40E_PF_MDET_TX
, 0xFFFF);
10935 dev_dbg(&pf
->pdev
->dev
, "TX driver issue detected on PF\n");
10937 reg
= rd32(hw
, I40E_PF_MDET_RX
);
10938 if (reg
& I40E_PF_MDET_RX_VALID_MASK
) {
10939 wr32(hw
, I40E_PF_MDET_RX
, 0xFFFF);
10940 dev_dbg(&pf
->pdev
->dev
, "RX driver issue detected on PF\n");
10944 /* see if one of the VFs needs its hand slapped */
10945 for (i
= 0; i
< pf
->num_alloc_vfs
&& mdd_detected
; i
++) {
10947 reg
= rd32(hw
, I40E_VP_MDET_TX(i
));
10948 if (reg
& I40E_VP_MDET_TX_VALID_MASK
) {
10949 wr32(hw
, I40E_VP_MDET_TX(i
), 0xFFFF);
10950 vf
->num_mdd_events
++;
10951 dev_info(&pf
->pdev
->dev
, "TX driver issue detected on VF %d\n",
10953 dev_info(&pf
->pdev
->dev
,
10954 "Use PF Control I/F to re-enable the VF\n");
10955 set_bit(I40E_VF_STATE_DISABLED
, &vf
->vf_states
);
10958 reg
= rd32(hw
, I40E_VP_MDET_RX(i
));
10959 if (reg
& I40E_VP_MDET_RX_VALID_MASK
) {
10960 wr32(hw
, I40E_VP_MDET_RX(i
), 0xFFFF);
10961 vf
->num_mdd_events
++;
10962 dev_info(&pf
->pdev
->dev
, "RX driver issue detected on VF %d\n",
10964 dev_info(&pf
->pdev
->dev
,
10965 "Use PF Control I/F to re-enable the VF\n");
10966 set_bit(I40E_VF_STATE_DISABLED
, &vf
->vf_states
);
10970 /* re-enable mdd interrupt cause */
10971 clear_bit(__I40E_MDD_EVENT_PENDING
, pf
->state
);
10972 reg
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
10973 reg
|= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
10974 wr32(hw
, I40E_PFINT_ICR0_ENA
, reg
);
10979 * i40e_service_task - Run the driver's async subtasks
10980 * @work: pointer to work_struct containing our data
10982 static void i40e_service_task(struct work_struct
*work
)
10984 struct i40e_pf
*pf
= container_of(work
,
10987 unsigned long start_time
= jiffies
;
10989 /* don't bother with service tasks if a reset is in progress */
10990 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
) ||
10991 test_bit(__I40E_SUSPENDED
, pf
->state
))
10994 if (test_and_set_bit(__I40E_SERVICE_SCHED
, pf
->state
))
10997 if (!test_bit(__I40E_RECOVERY_MODE
, pf
->state
)) {
10998 i40e_detect_recover_hung(pf
->vsi
[pf
->lan_vsi
]);
10999 i40e_sync_filters_subtask(pf
);
11000 i40e_reset_subtask(pf
);
11001 i40e_handle_mdd_event(pf
);
11002 i40e_vc_process_vflr_event(pf
);
11003 i40e_watchdog_subtask(pf
);
11004 i40e_fdir_reinit_subtask(pf
);
11005 if (test_and_clear_bit(__I40E_CLIENT_RESET
, pf
->state
)) {
11006 /* Client subtask will reopen next time through. */
11007 i40e_notify_client_of_netdev_close(pf
->vsi
[pf
->lan_vsi
],
11010 i40e_client_subtask(pf
);
11011 if (test_and_clear_bit(__I40E_CLIENT_L2_CHANGE
,
11013 i40e_notify_client_of_l2_param_changes(
11014 pf
->vsi
[pf
->lan_vsi
]);
11016 i40e_sync_filters_subtask(pf
);
11018 i40e_reset_subtask(pf
);
11021 i40e_clean_adminq_subtask(pf
);
11023 /* flush memory to make sure state is correct before next watchdog */
11024 smp_mb__before_atomic();
11025 clear_bit(__I40E_SERVICE_SCHED
, pf
->state
);
11027 /* If the tasks have taken longer than one timer cycle or there
11028 * is more work to be done, reschedule the service task now
11029 * rather than wait for the timer to tick again.
11031 if (time_after(jiffies
, (start_time
+ pf
->service_timer_period
)) ||
11032 test_bit(__I40E_ADMINQ_EVENT_PENDING
, pf
->state
) ||
11033 test_bit(__I40E_MDD_EVENT_PENDING
, pf
->state
) ||
11034 test_bit(__I40E_VFLR_EVENT_PENDING
, pf
->state
))
11035 i40e_service_event_schedule(pf
);
11039 * i40e_service_timer - timer callback
11040 * @t: timer list pointer
11042 static void i40e_service_timer(struct timer_list
*t
)
11044 struct i40e_pf
*pf
= from_timer(pf
, t
, service_timer
);
11046 mod_timer(&pf
->service_timer
,
11047 round_jiffies(jiffies
+ pf
->service_timer_period
));
11048 i40e_service_event_schedule(pf
);
11052 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
11053 * @vsi: the VSI being configured
11055 static int i40e_set_num_rings_in_vsi(struct i40e_vsi
*vsi
)
11057 struct i40e_pf
*pf
= vsi
->back
;
11059 switch (vsi
->type
) {
11060 case I40E_VSI_MAIN
:
11061 vsi
->alloc_queue_pairs
= pf
->num_lan_qps
;
11062 if (!vsi
->num_tx_desc
)
11063 vsi
->num_tx_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
11064 I40E_REQ_DESCRIPTOR_MULTIPLE
);
11065 if (!vsi
->num_rx_desc
)
11066 vsi
->num_rx_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
11067 I40E_REQ_DESCRIPTOR_MULTIPLE
);
11068 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
11069 vsi
->num_q_vectors
= pf
->num_lan_msix
;
11071 vsi
->num_q_vectors
= 1;
11075 case I40E_VSI_FDIR
:
11076 vsi
->alloc_queue_pairs
= 1;
11077 vsi
->num_tx_desc
= ALIGN(I40E_FDIR_RING_COUNT
,
11078 I40E_REQ_DESCRIPTOR_MULTIPLE
);
11079 vsi
->num_rx_desc
= ALIGN(I40E_FDIR_RING_COUNT
,
11080 I40E_REQ_DESCRIPTOR_MULTIPLE
);
11081 vsi
->num_q_vectors
= pf
->num_fdsb_msix
;
11084 case I40E_VSI_VMDQ2
:
11085 vsi
->alloc_queue_pairs
= pf
->num_vmdq_qps
;
11086 if (!vsi
->num_tx_desc
)
11087 vsi
->num_tx_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
11088 I40E_REQ_DESCRIPTOR_MULTIPLE
);
11089 if (!vsi
->num_rx_desc
)
11090 vsi
->num_rx_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
11091 I40E_REQ_DESCRIPTOR_MULTIPLE
);
11092 vsi
->num_q_vectors
= pf
->num_vmdq_msix
;
11095 case I40E_VSI_SRIOV
:
11096 vsi
->alloc_queue_pairs
= pf
->num_vf_qps
;
11097 if (!vsi
->num_tx_desc
)
11098 vsi
->num_tx_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
11099 I40E_REQ_DESCRIPTOR_MULTIPLE
);
11100 if (!vsi
->num_rx_desc
)
11101 vsi
->num_rx_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
11102 I40E_REQ_DESCRIPTOR_MULTIPLE
);
11110 if (is_kdump_kernel()) {
11111 vsi
->num_tx_desc
= I40E_MIN_NUM_DESCRIPTORS
;
11112 vsi
->num_rx_desc
= I40E_MIN_NUM_DESCRIPTORS
;
11119 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
11120 * @vsi: VSI pointer
11121 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
11123 * On error: returns error code (negative)
11124 * On success: returns 0
11126 static int i40e_vsi_alloc_arrays(struct i40e_vsi
*vsi
, bool alloc_qvectors
)
11128 struct i40e_ring
**next_rings
;
11132 /* allocate memory for both Tx, XDP Tx and Rx ring pointers */
11133 size
= sizeof(struct i40e_ring
*) * vsi
->alloc_queue_pairs
*
11134 (i40e_enabled_xdp_vsi(vsi
) ? 3 : 2);
11135 vsi
->tx_rings
= kzalloc(size
, GFP_KERNEL
);
11136 if (!vsi
->tx_rings
)
11138 next_rings
= vsi
->tx_rings
+ vsi
->alloc_queue_pairs
;
11139 if (i40e_enabled_xdp_vsi(vsi
)) {
11140 vsi
->xdp_rings
= next_rings
;
11141 next_rings
+= vsi
->alloc_queue_pairs
;
11143 vsi
->rx_rings
= next_rings
;
11145 if (alloc_qvectors
) {
11146 /* allocate memory for q_vector pointers */
11147 size
= sizeof(struct i40e_q_vector
*) * vsi
->num_q_vectors
;
11148 vsi
->q_vectors
= kzalloc(size
, GFP_KERNEL
);
11149 if (!vsi
->q_vectors
) {
11157 kfree(vsi
->tx_rings
);
11162 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
11163 * @pf: board private structure
11164 * @type: type of VSI
11166 * On error: returns error code (negative)
11167 * On success: returns vsi index in PF (positive)
11169 static int i40e_vsi_mem_alloc(struct i40e_pf
*pf
, enum i40e_vsi_type type
)
11172 struct i40e_vsi
*vsi
;
11176 /* Need to protect the allocation of the VSIs at the PF level */
11177 mutex_lock(&pf
->switch_mutex
);
11179 /* VSI list may be fragmented if VSI creation/destruction has
11180 * been happening. We can afford to do a quick scan to look
11181 * for any free VSIs in the list.
11183 * find next empty vsi slot, looping back around if necessary
11186 while (i
< pf
->num_alloc_vsi
&& pf
->vsi
[i
])
11188 if (i
>= pf
->num_alloc_vsi
) {
11190 while (i
< pf
->next_vsi
&& pf
->vsi
[i
])
11194 if (i
< pf
->num_alloc_vsi
&& !pf
->vsi
[i
]) {
11195 vsi_idx
= i
; /* Found one! */
11198 goto unlock_pf
; /* out of VSI slots! */
11200 pf
->next_vsi
= ++i
;
11202 vsi
= kzalloc(sizeof(*vsi
), GFP_KERNEL
);
11209 set_bit(__I40E_VSI_DOWN
, vsi
->state
);
11211 vsi
->idx
= vsi_idx
;
11212 vsi
->int_rate_limit
= 0;
11213 vsi
->rss_table_size
= (vsi
->type
== I40E_VSI_MAIN
) ?
11214 pf
->rss_table_size
: 64;
11215 vsi
->netdev_registered
= false;
11216 vsi
->work_limit
= I40E_DEFAULT_IRQ_WORK
;
11217 hash_init(vsi
->mac_filter_hash
);
11218 vsi
->irqs_ready
= false;
11220 if (type
== I40E_VSI_MAIN
) {
11221 vsi
->af_xdp_zc_qps
= bitmap_zalloc(pf
->num_lan_qps
, GFP_KERNEL
);
11222 if (!vsi
->af_xdp_zc_qps
)
11226 ret
= i40e_set_num_rings_in_vsi(vsi
);
11230 ret
= i40e_vsi_alloc_arrays(vsi
, true);
11234 /* Setup default MSIX irq handler for VSI */
11235 i40e_vsi_setup_irqhandler(vsi
, i40e_msix_clean_rings
);
11237 /* Initialize VSI lock */
11238 spin_lock_init(&vsi
->mac_filter_hash_lock
);
11239 pf
->vsi
[vsi_idx
] = vsi
;
11244 bitmap_free(vsi
->af_xdp_zc_qps
);
11245 pf
->next_vsi
= i
- 1;
11248 mutex_unlock(&pf
->switch_mutex
);
11253 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
11254 * @vsi: VSI pointer
11255 * @free_qvectors: a bool to specify if q_vectors need to be freed.
11257 * On error: returns error code (negative)
11258 * On success: returns 0
11260 static void i40e_vsi_free_arrays(struct i40e_vsi
*vsi
, bool free_qvectors
)
11262 /* free the ring and vector containers */
11263 if (free_qvectors
) {
11264 kfree(vsi
->q_vectors
);
11265 vsi
->q_vectors
= NULL
;
11267 kfree(vsi
->tx_rings
);
11268 vsi
->tx_rings
= NULL
;
11269 vsi
->rx_rings
= NULL
;
11270 vsi
->xdp_rings
= NULL
;
11274 * i40e_clear_rss_config_user - clear the user configured RSS hash keys
11276 * @vsi: Pointer to VSI structure
11278 static void i40e_clear_rss_config_user(struct i40e_vsi
*vsi
)
11283 kfree(vsi
->rss_hkey_user
);
11284 vsi
->rss_hkey_user
= NULL
;
11286 kfree(vsi
->rss_lut_user
);
11287 vsi
->rss_lut_user
= NULL
;
11291 * i40e_vsi_clear - Deallocate the VSI provided
11292 * @vsi: the VSI being un-configured
11294 static int i40e_vsi_clear(struct i40e_vsi
*vsi
)
11296 struct i40e_pf
*pf
;
11305 mutex_lock(&pf
->switch_mutex
);
11306 if (!pf
->vsi
[vsi
->idx
]) {
11307 dev_err(&pf
->pdev
->dev
, "pf->vsi[%d] is NULL, just free vsi[%d](type %d)\n",
11308 vsi
->idx
, vsi
->idx
, vsi
->type
);
11312 if (pf
->vsi
[vsi
->idx
] != vsi
) {
11313 dev_err(&pf
->pdev
->dev
,
11314 "pf->vsi[%d](type %d) != vsi[%d](type %d): no free!\n",
11315 pf
->vsi
[vsi
->idx
]->idx
,
11316 pf
->vsi
[vsi
->idx
]->type
,
11317 vsi
->idx
, vsi
->type
);
11321 /* updates the PF for this cleared vsi */
11322 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
11323 i40e_put_lump(pf
->irq_pile
, vsi
->base_vector
, vsi
->idx
);
11325 bitmap_free(vsi
->af_xdp_zc_qps
);
11326 i40e_vsi_free_arrays(vsi
, true);
11327 i40e_clear_rss_config_user(vsi
);
11329 pf
->vsi
[vsi
->idx
] = NULL
;
11330 if (vsi
->idx
< pf
->next_vsi
)
11331 pf
->next_vsi
= vsi
->idx
;
11334 mutex_unlock(&pf
->switch_mutex
);
11342 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
11343 * @vsi: the VSI being cleaned
11345 static void i40e_vsi_clear_rings(struct i40e_vsi
*vsi
)
11349 if (vsi
->tx_rings
&& vsi
->tx_rings
[0]) {
11350 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
11351 kfree_rcu(vsi
->tx_rings
[i
], rcu
);
11352 WRITE_ONCE(vsi
->tx_rings
[i
], NULL
);
11353 WRITE_ONCE(vsi
->rx_rings
[i
], NULL
);
11354 if (vsi
->xdp_rings
)
11355 WRITE_ONCE(vsi
->xdp_rings
[i
], NULL
);
11361 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
11362 * @vsi: the VSI being configured
11364 static int i40e_alloc_rings(struct i40e_vsi
*vsi
)
11366 int i
, qpv
= i40e_enabled_xdp_vsi(vsi
) ? 3 : 2;
11367 struct i40e_pf
*pf
= vsi
->back
;
11368 struct i40e_ring
*ring
;
11370 /* Set basic values in the rings to be used later during open() */
11371 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
11372 /* allocate space for both Tx and Rx in one shot */
11373 ring
= kcalloc(qpv
, sizeof(struct i40e_ring
), GFP_KERNEL
);
11377 ring
->queue_index
= i
;
11378 ring
->reg_idx
= vsi
->base_queue
+ i
;
11379 ring
->ring_active
= false;
11381 ring
->netdev
= vsi
->netdev
;
11382 ring
->dev
= &pf
->pdev
->dev
;
11383 ring
->count
= vsi
->num_tx_desc
;
11386 if (vsi
->back
->hw_features
& I40E_HW_WB_ON_ITR_CAPABLE
)
11387 ring
->flags
= I40E_TXR_FLAGS_WB_ON_ITR
;
11388 ring
->itr_setting
= pf
->tx_itr_default
;
11389 WRITE_ONCE(vsi
->tx_rings
[i
], ring
++);
11391 if (!i40e_enabled_xdp_vsi(vsi
))
11394 ring
->queue_index
= vsi
->alloc_queue_pairs
+ i
;
11395 ring
->reg_idx
= vsi
->base_queue
+ ring
->queue_index
;
11396 ring
->ring_active
= false;
11398 ring
->netdev
= NULL
;
11399 ring
->dev
= &pf
->pdev
->dev
;
11400 ring
->count
= vsi
->num_tx_desc
;
11403 if (vsi
->back
->hw_features
& I40E_HW_WB_ON_ITR_CAPABLE
)
11404 ring
->flags
= I40E_TXR_FLAGS_WB_ON_ITR
;
11405 set_ring_xdp(ring
);
11406 ring
->itr_setting
= pf
->tx_itr_default
;
11407 WRITE_ONCE(vsi
->xdp_rings
[i
], ring
++);
11410 ring
->queue_index
= i
;
11411 ring
->reg_idx
= vsi
->base_queue
+ i
;
11412 ring
->ring_active
= false;
11414 ring
->netdev
= vsi
->netdev
;
11415 ring
->dev
= &pf
->pdev
->dev
;
11416 ring
->count
= vsi
->num_rx_desc
;
11419 ring
->itr_setting
= pf
->rx_itr_default
;
11420 WRITE_ONCE(vsi
->rx_rings
[i
], ring
);
11426 i40e_vsi_clear_rings(vsi
);
11431 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
11432 * @pf: board private structure
11433 * @vectors: the number of MSI-X vectors to request
11435 * Returns the number of vectors reserved, or error
11437 static int i40e_reserve_msix_vectors(struct i40e_pf
*pf
, int vectors
)
11439 vectors
= pci_enable_msix_range(pf
->pdev
, pf
->msix_entries
,
11440 I40E_MIN_MSIX
, vectors
);
11442 dev_info(&pf
->pdev
->dev
,
11443 "MSI-X vector reservation failed: %d\n", vectors
);
11451 * i40e_init_msix - Setup the MSIX capability
11452 * @pf: board private structure
11454 * Work with the OS to set up the MSIX vectors needed.
11456 * Returns the number of vectors reserved or negative on failure
11458 static int i40e_init_msix(struct i40e_pf
*pf
)
11460 struct i40e_hw
*hw
= &pf
->hw
;
11461 int cpus
, extra_vectors
;
11465 int iwarp_requested
= 0;
11467 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
11470 /* The number of vectors we'll request will be comprised of:
11471 * - Add 1 for "other" cause for Admin Queue events, etc.
11472 * - The number of LAN queue pairs
11473 * - Queues being used for RSS.
11474 * We don't need as many as max_rss_size vectors.
11475 * use rss_size instead in the calculation since that
11476 * is governed by number of cpus in the system.
11477 * - assumes symmetric Tx/Rx pairing
11478 * - The number of VMDq pairs
11479 * - The CPU count within the NUMA node if iWARP is enabled
11480 * Once we count this up, try the request.
11482 * If we can't get what we want, we'll simplify to nearly nothing
11483 * and try again. If that still fails, we punt.
11485 vectors_left
= hw
->func_caps
.num_msix_vectors
;
11488 /* reserve one vector for miscellaneous handler */
11489 if (vectors_left
) {
11494 /* reserve some vectors for the main PF traffic queues. Initially we
11495 * only reserve at most 50% of the available vectors, in the case that
11496 * the number of online CPUs is large. This ensures that we can enable
11497 * extra features as well. Once we've enabled the other features, we
11498 * will use any remaining vectors to reach as close as we can to the
11499 * number of online CPUs.
11501 cpus
= num_online_cpus();
11502 pf
->num_lan_msix
= min_t(int, cpus
, vectors_left
/ 2);
11503 vectors_left
-= pf
->num_lan_msix
;
11505 /* reserve one vector for sideband flow director */
11506 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
11507 if (vectors_left
) {
11508 pf
->num_fdsb_msix
= 1;
11512 pf
->num_fdsb_msix
= 0;
11516 /* can we reserve enough for iWARP? */
11517 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
) {
11518 iwarp_requested
= pf
->num_iwarp_msix
;
11521 pf
->num_iwarp_msix
= 0;
11522 else if (vectors_left
< pf
->num_iwarp_msix
)
11523 pf
->num_iwarp_msix
= 1;
11524 v_budget
+= pf
->num_iwarp_msix
;
11525 vectors_left
-= pf
->num_iwarp_msix
;
11528 /* any vectors left over go for VMDq support */
11529 if (pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) {
11530 if (!vectors_left
) {
11531 pf
->num_vmdq_msix
= 0;
11532 pf
->num_vmdq_qps
= 0;
11534 int vmdq_vecs_wanted
=
11535 pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
;
11537 min_t(int, vectors_left
, vmdq_vecs_wanted
);
11539 /* if we're short on vectors for what's desired, we limit
11540 * the queues per vmdq. If this is still more than are
11541 * available, the user will need to change the number of
11542 * queues/vectors used by the PF later with the ethtool
11545 if (vectors_left
< vmdq_vecs_wanted
) {
11546 pf
->num_vmdq_qps
= 1;
11547 vmdq_vecs_wanted
= pf
->num_vmdq_vsis
;
11548 vmdq_vecs
= min_t(int,
11552 pf
->num_vmdq_msix
= pf
->num_vmdq_qps
;
11554 v_budget
+= vmdq_vecs
;
11555 vectors_left
-= vmdq_vecs
;
11559 /* On systems with a large number of SMP cores, we previously limited
11560 * the number of vectors for num_lan_msix to be at most 50% of the
11561 * available vectors, to allow for other features. Now, we add back
11562 * the remaining vectors. However, we ensure that the total
11563 * num_lan_msix will not exceed num_online_cpus(). To do this, we
11564 * calculate the number of vectors we can add without going over the
11565 * cap of CPUs. For systems with a small number of CPUs this will be
11568 extra_vectors
= min_t(int, cpus
- pf
->num_lan_msix
, vectors_left
);
11569 pf
->num_lan_msix
+= extra_vectors
;
11570 vectors_left
-= extra_vectors
;
11572 WARN(vectors_left
< 0,
11573 "Calculation of remaining vectors underflowed. This is an accounting bug when determining total MSI-X vectors.\n");
11575 v_budget
+= pf
->num_lan_msix
;
11576 pf
->msix_entries
= kcalloc(v_budget
, sizeof(struct msix_entry
),
11578 if (!pf
->msix_entries
)
11581 for (i
= 0; i
< v_budget
; i
++)
11582 pf
->msix_entries
[i
].entry
= i
;
11583 v_actual
= i40e_reserve_msix_vectors(pf
, v_budget
);
11585 if (v_actual
< I40E_MIN_MSIX
) {
11586 pf
->flags
&= ~I40E_FLAG_MSIX_ENABLED
;
11587 kfree(pf
->msix_entries
);
11588 pf
->msix_entries
= NULL
;
11589 pci_disable_msix(pf
->pdev
);
11592 } else if (v_actual
== I40E_MIN_MSIX
) {
11593 /* Adjust for minimal MSIX use */
11594 pf
->num_vmdq_vsis
= 0;
11595 pf
->num_vmdq_qps
= 0;
11596 pf
->num_lan_qps
= 1;
11597 pf
->num_lan_msix
= 1;
11599 } else if (v_actual
!= v_budget
) {
11600 /* If we have limited resources, we will start with no vectors
11601 * for the special features and then allocate vectors to some
11602 * of these features based on the policy and at the end disable
11603 * the features that did not get any vectors.
11607 dev_info(&pf
->pdev
->dev
,
11608 "MSI-X vector limit reached with %d, wanted %d, attempting to redistribute vectors\n",
11609 v_actual
, v_budget
);
11610 /* reserve the misc vector */
11611 vec
= v_actual
- 1;
11613 /* Scale vector usage down */
11614 pf
->num_vmdq_msix
= 1; /* force VMDqs to only one vector */
11615 pf
->num_vmdq_vsis
= 1;
11616 pf
->num_vmdq_qps
= 1;
11618 /* partition out the remaining vectors */
11621 pf
->num_lan_msix
= 1;
11624 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
) {
11625 pf
->num_lan_msix
= 1;
11626 pf
->num_iwarp_msix
= 1;
11628 pf
->num_lan_msix
= 2;
11632 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
) {
11633 pf
->num_iwarp_msix
= min_t(int, (vec
/ 3),
11635 pf
->num_vmdq_vsis
= min_t(int, (vec
/ 3),
11636 I40E_DEFAULT_NUM_VMDQ_VSI
);
11638 pf
->num_vmdq_vsis
= min_t(int, (vec
/ 2),
11639 I40E_DEFAULT_NUM_VMDQ_VSI
);
11641 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
11642 pf
->num_fdsb_msix
= 1;
11645 pf
->num_lan_msix
= min_t(int,
11646 (vec
- (pf
->num_iwarp_msix
+ pf
->num_vmdq_vsis
)),
11648 pf
->num_lan_qps
= pf
->num_lan_msix
;
11653 if ((pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) &&
11654 (pf
->num_fdsb_msix
== 0)) {
11655 dev_info(&pf
->pdev
->dev
, "Sideband Flowdir disabled, not enough MSI-X vectors\n");
11656 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
11657 pf
->flags
|= I40E_FLAG_FD_SB_INACTIVE
;
11659 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
11660 (pf
->num_vmdq_msix
== 0)) {
11661 dev_info(&pf
->pdev
->dev
, "VMDq disabled, not enough MSI-X vectors\n");
11662 pf
->flags
&= ~I40E_FLAG_VMDQ_ENABLED
;
11665 if ((pf
->flags
& I40E_FLAG_IWARP_ENABLED
) &&
11666 (pf
->num_iwarp_msix
== 0)) {
11667 dev_info(&pf
->pdev
->dev
, "IWARP disabled, not enough MSI-X vectors\n");
11668 pf
->flags
&= ~I40E_FLAG_IWARP_ENABLED
;
11670 i40e_debug(&pf
->hw
, I40E_DEBUG_INIT
,
11671 "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n",
11673 pf
->num_vmdq_msix
* pf
->num_vmdq_vsis
,
11675 pf
->num_iwarp_msix
);
11681 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
11682 * @vsi: the VSI being configured
11683 * @v_idx: index of the vector in the vsi struct
11685 * We allocate one q_vector. If allocation fails we return -ENOMEM.
11687 static int i40e_vsi_alloc_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
11689 struct i40e_q_vector
*q_vector
;
11691 /* allocate q_vector */
11692 q_vector
= kzalloc(sizeof(struct i40e_q_vector
), GFP_KERNEL
);
11696 q_vector
->vsi
= vsi
;
11697 q_vector
->v_idx
= v_idx
;
11698 cpumask_copy(&q_vector
->affinity_mask
, cpu_possible_mask
);
11701 netif_napi_add(vsi
->netdev
, &q_vector
->napi
,
11702 i40e_napi_poll
, NAPI_POLL_WEIGHT
);
11704 /* tie q_vector and vsi together */
11705 vsi
->q_vectors
[v_idx
] = q_vector
;
11711 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
11712 * @vsi: the VSI being configured
11714 * We allocate one q_vector per queue interrupt. If allocation fails we
11717 static int i40e_vsi_alloc_q_vectors(struct i40e_vsi
*vsi
)
11719 struct i40e_pf
*pf
= vsi
->back
;
11720 int err
, v_idx
, num_q_vectors
;
11722 /* if not MSIX, give the one vector only to the LAN VSI */
11723 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
11724 num_q_vectors
= vsi
->num_q_vectors
;
11725 else if (vsi
== pf
->vsi
[pf
->lan_vsi
])
11730 for (v_idx
= 0; v_idx
< num_q_vectors
; v_idx
++) {
11731 err
= i40e_vsi_alloc_q_vector(vsi
, v_idx
);
11740 i40e_free_q_vector(vsi
, v_idx
);
11746 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
11747 * @pf: board private structure to initialize
11749 static int i40e_init_interrupt_scheme(struct i40e_pf
*pf
)
11754 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
11755 vectors
= i40e_init_msix(pf
);
11757 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
|
11758 I40E_FLAG_IWARP_ENABLED
|
11759 I40E_FLAG_RSS_ENABLED
|
11760 I40E_FLAG_DCB_CAPABLE
|
11761 I40E_FLAG_DCB_ENABLED
|
11762 I40E_FLAG_SRIOV_ENABLED
|
11763 I40E_FLAG_FD_SB_ENABLED
|
11764 I40E_FLAG_FD_ATR_ENABLED
|
11765 I40E_FLAG_VMDQ_ENABLED
);
11766 pf
->flags
|= I40E_FLAG_FD_SB_INACTIVE
;
11768 /* rework the queue expectations without MSIX */
11769 i40e_determine_queue_usage(pf
);
11773 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
11774 (pf
->flags
& I40E_FLAG_MSI_ENABLED
)) {
11775 dev_info(&pf
->pdev
->dev
, "MSI-X not available, trying MSI\n");
11776 vectors
= pci_enable_msi(pf
->pdev
);
11778 dev_info(&pf
->pdev
->dev
, "MSI init failed - %d\n",
11780 pf
->flags
&= ~I40E_FLAG_MSI_ENABLED
;
11782 vectors
= 1; /* one MSI or Legacy vector */
11785 if (!(pf
->flags
& (I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
)))
11786 dev_info(&pf
->pdev
->dev
, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
11788 /* set up vector assignment tracking */
11789 size
= sizeof(struct i40e_lump_tracking
) + (sizeof(u16
) * vectors
);
11790 pf
->irq_pile
= kzalloc(size
, GFP_KERNEL
);
11794 pf
->irq_pile
->num_entries
= vectors
;
11796 /* track first vector for misc interrupts, ignore return */
11797 (void)i40e_get_lump(pf
, pf
->irq_pile
, 1, I40E_PILE_VALID_BIT
- 1);
11803 * i40e_restore_interrupt_scheme - Restore the interrupt scheme
11804 * @pf: private board data structure
11806 * Restore the interrupt scheme that was cleared when we suspended the
11807 * device. This should be called during resume to re-allocate the q_vectors
11808 * and reacquire IRQs.
11810 static int i40e_restore_interrupt_scheme(struct i40e_pf
*pf
)
11814 /* We cleared the MSI and MSI-X flags when disabling the old interrupt
11815 * scheme. We need to re-enabled them here in order to attempt to
11816 * re-acquire the MSI or MSI-X vectors
11818 pf
->flags
|= (I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
);
11820 err
= i40e_init_interrupt_scheme(pf
);
11824 /* Now that we've re-acquired IRQs, we need to remap the vectors and
11825 * rings together again.
11827 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
11829 err
= i40e_vsi_alloc_q_vectors(pf
->vsi
[i
]);
11832 i40e_vsi_map_rings_to_vectors(pf
->vsi
[i
]);
11836 err
= i40e_setup_misc_vector(pf
);
11840 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
)
11841 i40e_client_update_msix_info(pf
);
11848 i40e_vsi_free_q_vectors(pf
->vsi
[i
]);
11855 * i40e_setup_misc_vector_for_recovery_mode - Setup the misc vector to handle
11856 * non queue events in recovery mode
11857 * @pf: board private structure
11859 * This sets up the handler for MSIX 0 or MSI/legacy, which is used to manage
11860 * the non-queue interrupts, e.g. AdminQ and errors in recovery mode.
11861 * This is handled differently than in recovery mode since no Tx/Rx resources
11862 * are being allocated.
11864 static int i40e_setup_misc_vector_for_recovery_mode(struct i40e_pf
*pf
)
11868 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
11869 err
= i40e_setup_misc_vector(pf
);
11872 dev_info(&pf
->pdev
->dev
,
11873 "MSI-X misc vector request failed, error %d\n",
11878 u32 flags
= pf
->flags
& I40E_FLAG_MSI_ENABLED
? 0 : IRQF_SHARED
;
11880 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, flags
,
11884 dev_info(&pf
->pdev
->dev
,
11885 "MSI/legacy misc vector request failed, error %d\n",
11889 i40e_enable_misc_int_causes(pf
);
11890 i40e_irq_dynamic_enable_icr0(pf
);
11897 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
11898 * @pf: board private structure
11900 * This sets up the handler for MSIX 0, which is used to manage the
11901 * non-queue interrupts, e.g. AdminQ and errors. This is not used
11902 * when in MSI or Legacy interrupt mode.
11904 static int i40e_setup_misc_vector(struct i40e_pf
*pf
)
11906 struct i40e_hw
*hw
= &pf
->hw
;
11909 /* Only request the IRQ once, the first time through. */
11910 if (!test_and_set_bit(__I40E_MISC_IRQ_REQUESTED
, pf
->state
)) {
11911 err
= request_irq(pf
->msix_entries
[0].vector
,
11912 i40e_intr
, 0, pf
->int_name
, pf
);
11914 clear_bit(__I40E_MISC_IRQ_REQUESTED
, pf
->state
);
11915 dev_info(&pf
->pdev
->dev
,
11916 "request_irq for %s failed: %d\n",
11917 pf
->int_name
, err
);
11922 i40e_enable_misc_int_causes(pf
);
11924 /* associate no queues to the misc vector */
11925 wr32(hw
, I40E_PFINT_LNKLST0
, I40E_QUEUE_END_OF_LIST
);
11926 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), I40E_ITR_8K
>> 1);
11930 i40e_irq_dynamic_enable_icr0(pf
);
11936 * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
11937 * @vsi: Pointer to vsi structure
11938 * @seed: Buffter to store the hash keys
11939 * @lut: Buffer to store the lookup table entries
11940 * @lut_size: Size of buffer to store the lookup table entries
11942 * Return 0 on success, negative on failure
11944 static int i40e_get_rss_aq(struct i40e_vsi
*vsi
, const u8
*seed
,
11945 u8
*lut
, u16 lut_size
)
11947 struct i40e_pf
*pf
= vsi
->back
;
11948 struct i40e_hw
*hw
= &pf
->hw
;
11952 ret
= i40e_aq_get_rss_key(hw
, vsi
->id
,
11953 (struct i40e_aqc_get_set_rss_key_data
*)seed
);
11955 dev_info(&pf
->pdev
->dev
,
11956 "Cannot get RSS key, err %s aq_err %s\n",
11957 i40e_stat_str(&pf
->hw
, ret
),
11958 i40e_aq_str(&pf
->hw
,
11959 pf
->hw
.aq
.asq_last_status
));
11965 bool pf_lut
= vsi
->type
== I40E_VSI_MAIN
;
11967 ret
= i40e_aq_get_rss_lut(hw
, vsi
->id
, pf_lut
, lut
, lut_size
);
11969 dev_info(&pf
->pdev
->dev
,
11970 "Cannot get RSS lut, err %s aq_err %s\n",
11971 i40e_stat_str(&pf
->hw
, ret
),
11972 i40e_aq_str(&pf
->hw
,
11973 pf
->hw
.aq
.asq_last_status
));
11982 * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
11983 * @vsi: Pointer to vsi structure
11984 * @seed: RSS hash seed
11985 * @lut: Lookup table
11986 * @lut_size: Lookup table size
11988 * Returns 0 on success, negative on failure
11990 static int i40e_config_rss_reg(struct i40e_vsi
*vsi
, const u8
*seed
,
11991 const u8
*lut
, u16 lut_size
)
11993 struct i40e_pf
*pf
= vsi
->back
;
11994 struct i40e_hw
*hw
= &pf
->hw
;
11995 u16 vf_id
= vsi
->vf_id
;
11998 /* Fill out hash function seed */
12000 u32
*seed_dw
= (u32
*)seed
;
12002 if (vsi
->type
== I40E_VSI_MAIN
) {
12003 for (i
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++)
12004 wr32(hw
, I40E_PFQF_HKEY(i
), seed_dw
[i
]);
12005 } else if (vsi
->type
== I40E_VSI_SRIOV
) {
12006 for (i
= 0; i
<= I40E_VFQF_HKEY1_MAX_INDEX
; i
++)
12007 wr32(hw
, I40E_VFQF_HKEY1(i
, vf_id
), seed_dw
[i
]);
12009 dev_err(&pf
->pdev
->dev
, "Cannot set RSS seed - invalid VSI type\n");
12014 u32
*lut_dw
= (u32
*)lut
;
12016 if (vsi
->type
== I40E_VSI_MAIN
) {
12017 if (lut_size
!= I40E_HLUT_ARRAY_SIZE
)
12019 for (i
= 0; i
<= I40E_PFQF_HLUT_MAX_INDEX
; i
++)
12020 wr32(hw
, I40E_PFQF_HLUT(i
), lut_dw
[i
]);
12021 } else if (vsi
->type
== I40E_VSI_SRIOV
) {
12022 if (lut_size
!= I40E_VF_HLUT_ARRAY_SIZE
)
12024 for (i
= 0; i
<= I40E_VFQF_HLUT_MAX_INDEX
; i
++)
12025 wr32(hw
, I40E_VFQF_HLUT1(i
, vf_id
), lut_dw
[i
]);
12027 dev_err(&pf
->pdev
->dev
, "Cannot set RSS LUT - invalid VSI type\n");
12036 * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
12037 * @vsi: Pointer to VSI structure
12038 * @seed: Buffer to store the keys
12039 * @lut: Buffer to store the lookup table entries
12040 * @lut_size: Size of buffer to store the lookup table entries
12042 * Returns 0 on success, negative on failure
12044 static int i40e_get_rss_reg(struct i40e_vsi
*vsi
, u8
*seed
,
12045 u8
*lut
, u16 lut_size
)
12047 struct i40e_pf
*pf
= vsi
->back
;
12048 struct i40e_hw
*hw
= &pf
->hw
;
12052 u32
*seed_dw
= (u32
*)seed
;
12054 for (i
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++)
12055 seed_dw
[i
] = i40e_read_rx_ctl(hw
, I40E_PFQF_HKEY(i
));
12058 u32
*lut_dw
= (u32
*)lut
;
12060 if (lut_size
!= I40E_HLUT_ARRAY_SIZE
)
12062 for (i
= 0; i
<= I40E_PFQF_HLUT_MAX_INDEX
; i
++)
12063 lut_dw
[i
] = rd32(hw
, I40E_PFQF_HLUT(i
));
12070 * i40e_config_rss - Configure RSS keys and lut
12071 * @vsi: Pointer to VSI structure
12072 * @seed: RSS hash seed
12073 * @lut: Lookup table
12074 * @lut_size: Lookup table size
12076 * Returns 0 on success, negative on failure
12078 int i40e_config_rss(struct i40e_vsi
*vsi
, u8
*seed
, u8
*lut
, u16 lut_size
)
12080 struct i40e_pf
*pf
= vsi
->back
;
12082 if (pf
->hw_features
& I40E_HW_RSS_AQ_CAPABLE
)
12083 return i40e_config_rss_aq(vsi
, seed
, lut
, lut_size
);
12085 return i40e_config_rss_reg(vsi
, seed
, lut
, lut_size
);
12089 * i40e_get_rss - Get RSS keys and lut
12090 * @vsi: Pointer to VSI structure
12091 * @seed: Buffer to store the keys
12092 * @lut: Buffer to store the lookup table entries
12093 * @lut_size: Size of buffer to store the lookup table entries
12095 * Returns 0 on success, negative on failure
12097 int i40e_get_rss(struct i40e_vsi
*vsi
, u8
*seed
, u8
*lut
, u16 lut_size
)
12099 struct i40e_pf
*pf
= vsi
->back
;
12101 if (pf
->hw_features
& I40E_HW_RSS_AQ_CAPABLE
)
12102 return i40e_get_rss_aq(vsi
, seed
, lut
, lut_size
);
12104 return i40e_get_rss_reg(vsi
, seed
, lut
, lut_size
);
12108 * i40e_fill_rss_lut - Fill the RSS lookup table with default values
12109 * @pf: Pointer to board private structure
12110 * @lut: Lookup table
12111 * @rss_table_size: Lookup table size
12112 * @rss_size: Range of queue number for hashing
12114 void i40e_fill_rss_lut(struct i40e_pf
*pf
, u8
*lut
,
12115 u16 rss_table_size
, u16 rss_size
)
12119 for (i
= 0; i
< rss_table_size
; i
++)
12120 lut
[i
] = i
% rss_size
;
12124 * i40e_pf_config_rss - Prepare for RSS if used
12125 * @pf: board private structure
12127 static int i40e_pf_config_rss(struct i40e_pf
*pf
)
12129 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
12130 u8 seed
[I40E_HKEY_ARRAY_SIZE
];
12132 struct i40e_hw
*hw
= &pf
->hw
;
12137 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
12138 hena
= (u64
)i40e_read_rx_ctl(hw
, I40E_PFQF_HENA(0)) |
12139 ((u64
)i40e_read_rx_ctl(hw
, I40E_PFQF_HENA(1)) << 32);
12140 hena
|= i40e_pf_get_default_rss_hena(pf
);
12142 i40e_write_rx_ctl(hw
, I40E_PFQF_HENA(0), (u32
)hena
);
12143 i40e_write_rx_ctl(hw
, I40E_PFQF_HENA(1), (u32
)(hena
>> 32));
12145 /* Determine the RSS table size based on the hardware capabilities */
12146 reg_val
= i40e_read_rx_ctl(hw
, I40E_PFQF_CTL_0
);
12147 reg_val
= (pf
->rss_table_size
== 512) ?
12148 (reg_val
| I40E_PFQF_CTL_0_HASHLUTSIZE_512
) :
12149 (reg_val
& ~I40E_PFQF_CTL_0_HASHLUTSIZE_512
);
12150 i40e_write_rx_ctl(hw
, I40E_PFQF_CTL_0
, reg_val
);
12152 /* Determine the RSS size of the VSI */
12153 if (!vsi
->rss_size
) {
12155 /* If the firmware does something weird during VSI init, we
12156 * could end up with zero TCs. Check for that to avoid
12157 * divide-by-zero. It probably won't pass traffic, but it also
12160 qcount
= vsi
->num_queue_pairs
/
12161 (vsi
->tc_config
.numtc
? vsi
->tc_config
.numtc
: 1);
12162 vsi
->rss_size
= min_t(int, pf
->alloc_rss_size
, qcount
);
12164 if (!vsi
->rss_size
)
12167 lut
= kzalloc(vsi
->rss_table_size
, GFP_KERNEL
);
12171 /* Use user configured lut if there is one, otherwise use default */
12172 if (vsi
->rss_lut_user
)
12173 memcpy(lut
, vsi
->rss_lut_user
, vsi
->rss_table_size
);
12175 i40e_fill_rss_lut(pf
, lut
, vsi
->rss_table_size
, vsi
->rss_size
);
12177 /* Use user configured hash key if there is one, otherwise
12180 if (vsi
->rss_hkey_user
)
12181 memcpy(seed
, vsi
->rss_hkey_user
, I40E_HKEY_ARRAY_SIZE
);
12183 netdev_rss_key_fill((void *)seed
, I40E_HKEY_ARRAY_SIZE
);
12184 ret
= i40e_config_rss(vsi
, seed
, lut
, vsi
->rss_table_size
);
12191 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
12192 * @pf: board private structure
12193 * @queue_count: the requested queue count for rss.
12195 * returns 0 if rss is not enabled, if enabled returns the final rss queue
12196 * count which may be different from the requested queue count.
12197 * Note: expects to be called while under rtnl_lock()
12199 int i40e_reconfig_rss_queues(struct i40e_pf
*pf
, int queue_count
)
12201 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
12204 if (!(pf
->flags
& I40E_FLAG_RSS_ENABLED
))
12207 queue_count
= min_t(int, queue_count
, num_online_cpus());
12208 new_rss_size
= min_t(int, queue_count
, pf
->rss_size_max
);
12210 if (queue_count
!= vsi
->num_queue_pairs
) {
12213 vsi
->req_queue_pairs
= queue_count
;
12214 i40e_prep_for_reset(pf
);
12216 pf
->alloc_rss_size
= new_rss_size
;
12218 i40e_reset_and_rebuild(pf
, true, true);
12220 /* Discard the user configured hash keys and lut, if less
12221 * queues are enabled.
12223 if (queue_count
< vsi
->rss_size
) {
12224 i40e_clear_rss_config_user(vsi
);
12225 dev_dbg(&pf
->pdev
->dev
,
12226 "discard user configured hash keys and lut\n");
12229 /* Reset vsi->rss_size, as number of enabled queues changed */
12230 qcount
= vsi
->num_queue_pairs
/ vsi
->tc_config
.numtc
;
12231 vsi
->rss_size
= min_t(int, pf
->alloc_rss_size
, qcount
);
12233 i40e_pf_config_rss(pf
);
12235 dev_info(&pf
->pdev
->dev
, "User requested queue count/HW max RSS count: %d/%d\n",
12236 vsi
->req_queue_pairs
, pf
->rss_size_max
);
12237 return pf
->alloc_rss_size
;
12241 * i40e_get_partition_bw_setting - Retrieve BW settings for this PF partition
12242 * @pf: board private structure
12244 i40e_status
i40e_get_partition_bw_setting(struct i40e_pf
*pf
)
12246 i40e_status status
;
12247 bool min_valid
, max_valid
;
12248 u32 max_bw
, min_bw
;
12250 status
= i40e_read_bw_from_alt_ram(&pf
->hw
, &max_bw
, &min_bw
,
12251 &min_valid
, &max_valid
);
12255 pf
->min_bw
= min_bw
;
12257 pf
->max_bw
= max_bw
;
12264 * i40e_set_partition_bw_setting - Set BW settings for this PF partition
12265 * @pf: board private structure
12267 i40e_status
i40e_set_partition_bw_setting(struct i40e_pf
*pf
)
12269 struct i40e_aqc_configure_partition_bw_data bw_data
;
12270 i40e_status status
;
12272 memset(&bw_data
, 0, sizeof(bw_data
));
12274 /* Set the valid bit for this PF */
12275 bw_data
.pf_valid_bits
= cpu_to_le16(BIT(pf
->hw
.pf_id
));
12276 bw_data
.max_bw
[pf
->hw
.pf_id
] = pf
->max_bw
& I40E_ALT_BW_VALUE_MASK
;
12277 bw_data
.min_bw
[pf
->hw
.pf_id
] = pf
->min_bw
& I40E_ALT_BW_VALUE_MASK
;
12279 /* Set the new bandwidths */
12280 status
= i40e_aq_configure_partition_bw(&pf
->hw
, &bw_data
, NULL
);
12286 * i40e_commit_partition_bw_setting - Commit BW settings for this PF partition
12287 * @pf: board private structure
12289 i40e_status
i40e_commit_partition_bw_setting(struct i40e_pf
*pf
)
12291 /* Commit temporary BW setting to permanent NVM image */
12292 enum i40e_admin_queue_err last_aq_status
;
12296 if (pf
->hw
.partition_id
!= 1) {
12297 dev_info(&pf
->pdev
->dev
,
12298 "Commit BW only works on partition 1! This is partition %d",
12299 pf
->hw
.partition_id
);
12300 ret
= I40E_NOT_SUPPORTED
;
12301 goto bw_commit_out
;
12304 /* Acquire NVM for read access */
12305 ret
= i40e_acquire_nvm(&pf
->hw
, I40E_RESOURCE_READ
);
12306 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
12308 dev_info(&pf
->pdev
->dev
,
12309 "Cannot acquire NVM for read access, err %s aq_err %s\n",
12310 i40e_stat_str(&pf
->hw
, ret
),
12311 i40e_aq_str(&pf
->hw
, last_aq_status
));
12312 goto bw_commit_out
;
12315 /* Read word 0x10 of NVM - SW compatibility word 1 */
12316 ret
= i40e_aq_read_nvm(&pf
->hw
,
12317 I40E_SR_NVM_CONTROL_WORD
,
12318 0x10, sizeof(nvm_word
), &nvm_word
,
12320 /* Save off last admin queue command status before releasing
12323 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
12324 i40e_release_nvm(&pf
->hw
);
12326 dev_info(&pf
->pdev
->dev
, "NVM read error, err %s aq_err %s\n",
12327 i40e_stat_str(&pf
->hw
, ret
),
12328 i40e_aq_str(&pf
->hw
, last_aq_status
));
12329 goto bw_commit_out
;
12332 /* Wait a bit for NVM release to complete */
12335 /* Acquire NVM for write access */
12336 ret
= i40e_acquire_nvm(&pf
->hw
, I40E_RESOURCE_WRITE
);
12337 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
12339 dev_info(&pf
->pdev
->dev
,
12340 "Cannot acquire NVM for write access, err %s aq_err %s\n",
12341 i40e_stat_str(&pf
->hw
, ret
),
12342 i40e_aq_str(&pf
->hw
, last_aq_status
));
12343 goto bw_commit_out
;
12345 /* Write it back out unchanged to initiate update NVM,
12346 * which will force a write of the shadow (alt) RAM to
12347 * the NVM - thus storing the bandwidth values permanently.
12349 ret
= i40e_aq_update_nvm(&pf
->hw
,
12350 I40E_SR_NVM_CONTROL_WORD
,
12351 0x10, sizeof(nvm_word
),
12352 &nvm_word
, true, 0, NULL
);
12353 /* Save off last admin queue command status before releasing
12356 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
12357 i40e_release_nvm(&pf
->hw
);
12359 dev_info(&pf
->pdev
->dev
,
12360 "BW settings NOT SAVED, err %s aq_err %s\n",
12361 i40e_stat_str(&pf
->hw
, ret
),
12362 i40e_aq_str(&pf
->hw
, last_aq_status
));
12369 * i40e_is_total_port_shutdown_enabled - read NVM and return value
12370 * if total port shutdown feature is enabled for this PF
12371 * @pf: board private structure
12373 static bool i40e_is_total_port_shutdown_enabled(struct i40e_pf
*pf
)
12375 #define I40E_TOTAL_PORT_SHUTDOWN_ENABLED BIT(4)
12376 #define I40E_FEATURES_ENABLE_PTR 0x2A
12377 #define I40E_CURRENT_SETTING_PTR 0x2B
12378 #define I40E_LINK_BEHAVIOR_WORD_OFFSET 0x2D
12379 #define I40E_LINK_BEHAVIOR_WORD_LENGTH 0x1
12380 #define I40E_LINK_BEHAVIOR_OS_FORCED_ENABLED BIT(0)
12381 #define I40E_LINK_BEHAVIOR_PORT_BIT_LENGTH 4
12382 i40e_status read_status
= I40E_SUCCESS
;
12383 u16 sr_emp_sr_settings_ptr
= 0;
12384 u16 features_enable
= 0;
12385 u16 link_behavior
= 0;
12388 read_status
= i40e_read_nvm_word(&pf
->hw
,
12389 I40E_SR_EMP_SR_SETTINGS_PTR
,
12390 &sr_emp_sr_settings_ptr
);
12393 read_status
= i40e_read_nvm_word(&pf
->hw
,
12394 sr_emp_sr_settings_ptr
+
12395 I40E_FEATURES_ENABLE_PTR
,
12399 if (I40E_TOTAL_PORT_SHUTDOWN_ENABLED
& features_enable
) {
12400 read_status
= i40e_read_nvm_module_data(&pf
->hw
,
12401 I40E_SR_EMP_SR_SETTINGS_PTR
,
12402 I40E_CURRENT_SETTING_PTR
,
12403 I40E_LINK_BEHAVIOR_WORD_OFFSET
,
12404 I40E_LINK_BEHAVIOR_WORD_LENGTH
,
12408 link_behavior
>>= (pf
->hw
.port
* I40E_LINK_BEHAVIOR_PORT_BIT_LENGTH
);
12409 ret
= I40E_LINK_BEHAVIOR_OS_FORCED_ENABLED
& link_behavior
;
12414 dev_warn(&pf
->pdev
->dev
,
12415 "total-port-shutdown feature is off due to read nvm error: %s\n",
12416 i40e_stat_str(&pf
->hw
, read_status
));
12421 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
12422 * @pf: board private structure to initialize
12424 * i40e_sw_init initializes the Adapter private data structure.
12425 * Fields are initialized based on PCI device information and
12426 * OS network device settings (MTU size).
12428 static int i40e_sw_init(struct i40e_pf
*pf
)
12434 /* Set default capability flags */
12435 pf
->flags
= I40E_FLAG_RX_CSUM_ENABLED
|
12436 I40E_FLAG_MSI_ENABLED
|
12437 I40E_FLAG_MSIX_ENABLED
;
12439 /* Set default ITR */
12440 pf
->rx_itr_default
= I40E_ITR_RX_DEF
;
12441 pf
->tx_itr_default
= I40E_ITR_TX_DEF
;
12443 /* Depending on PF configurations, it is possible that the RSS
12444 * maximum might end up larger than the available queues
12446 pf
->rss_size_max
= BIT(pf
->hw
.func_caps
.rss_table_entry_width
);
12447 pf
->alloc_rss_size
= 1;
12448 pf
->rss_table_size
= pf
->hw
.func_caps
.rss_table_size
;
12449 pf
->rss_size_max
= min_t(int, pf
->rss_size_max
,
12450 pf
->hw
.func_caps
.num_tx_qp
);
12452 /* find the next higher power-of-2 of num cpus */
12453 pow
= roundup_pow_of_two(num_online_cpus());
12454 pf
->rss_size_max
= min_t(int, pf
->rss_size_max
, pow
);
12456 if (pf
->hw
.func_caps
.rss
) {
12457 pf
->flags
|= I40E_FLAG_RSS_ENABLED
;
12458 pf
->alloc_rss_size
= min_t(int, pf
->rss_size_max
,
12459 num_online_cpus());
12462 /* MFP mode enabled */
12463 if (pf
->hw
.func_caps
.npar_enable
|| pf
->hw
.func_caps
.flex10_enable
) {
12464 pf
->flags
|= I40E_FLAG_MFP_ENABLED
;
12465 dev_info(&pf
->pdev
->dev
, "MFP mode Enabled\n");
12466 if (i40e_get_partition_bw_setting(pf
)) {
12467 dev_warn(&pf
->pdev
->dev
,
12468 "Could not get partition bw settings\n");
12470 dev_info(&pf
->pdev
->dev
,
12471 "Partition BW Min = %8.8x, Max = %8.8x\n",
12472 pf
->min_bw
, pf
->max_bw
);
12474 /* nudge the Tx scheduler */
12475 i40e_set_partition_bw_setting(pf
);
12479 if ((pf
->hw
.func_caps
.fd_filters_guaranteed
> 0) ||
12480 (pf
->hw
.func_caps
.fd_filters_best_effort
> 0)) {
12481 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
12482 pf
->atr_sample_rate
= I40E_DEFAULT_ATR_SAMPLE_RATE
;
12483 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
&&
12484 pf
->hw
.num_partitions
> 1)
12485 dev_info(&pf
->pdev
->dev
,
12486 "Flow Director Sideband mode Disabled in MFP mode\n");
12488 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
12489 pf
->fdir_pf_filter_count
=
12490 pf
->hw
.func_caps
.fd_filters_guaranteed
;
12491 pf
->hw
.fdir_shared_filter_count
=
12492 pf
->hw
.func_caps
.fd_filters_best_effort
;
12495 if (pf
->hw
.mac
.type
== I40E_MAC_X722
) {
12496 pf
->hw_features
|= (I40E_HW_RSS_AQ_CAPABLE
|
12497 I40E_HW_128_QP_RSS_CAPABLE
|
12498 I40E_HW_ATR_EVICT_CAPABLE
|
12499 I40E_HW_WB_ON_ITR_CAPABLE
|
12500 I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE
|
12501 I40E_HW_NO_PCI_LINK_CHECK
|
12502 I40E_HW_USE_SET_LLDP_MIB
|
12503 I40E_HW_GENEVE_OFFLOAD_CAPABLE
|
12504 I40E_HW_PTP_L4_CAPABLE
|
12505 I40E_HW_WOL_MC_MAGIC_PKT_WAKE
|
12506 I40E_HW_OUTER_UDP_CSUM_CAPABLE
);
12508 #define I40E_FDEVICT_PCTYPE_DEFAULT 0xc03
12509 if (rd32(&pf
->hw
, I40E_GLQF_FDEVICTENA(1)) !=
12510 I40E_FDEVICT_PCTYPE_DEFAULT
) {
12511 dev_warn(&pf
->pdev
->dev
,
12512 "FD EVICT PCTYPES are not right, disable FD HW EVICT\n");
12513 pf
->hw_features
&= ~I40E_HW_ATR_EVICT_CAPABLE
;
12515 } else if ((pf
->hw
.aq
.api_maj_ver
> 1) ||
12516 ((pf
->hw
.aq
.api_maj_ver
== 1) &&
12517 (pf
->hw
.aq
.api_min_ver
> 4))) {
12518 /* Supported in FW API version higher than 1.4 */
12519 pf
->hw_features
|= I40E_HW_GENEVE_OFFLOAD_CAPABLE
;
12522 /* Enable HW ATR eviction if possible */
12523 if (pf
->hw_features
& I40E_HW_ATR_EVICT_CAPABLE
)
12524 pf
->flags
|= I40E_FLAG_HW_ATR_EVICT_ENABLED
;
12526 if ((pf
->hw
.mac
.type
== I40E_MAC_XL710
) &&
12527 (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
12528 (pf
->hw
.aq
.fw_maj_ver
< 4))) {
12529 pf
->hw_features
|= I40E_HW_RESTART_AUTONEG
;
12530 /* No DCB support for FW < v4.33 */
12531 pf
->hw_features
|= I40E_HW_NO_DCB_SUPPORT
;
12534 /* Disable FW LLDP if FW < v4.3 */
12535 if ((pf
->hw
.mac
.type
== I40E_MAC_XL710
) &&
12536 (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 3)) ||
12537 (pf
->hw
.aq
.fw_maj_ver
< 4)))
12538 pf
->hw_features
|= I40E_HW_STOP_FW_LLDP
;
12540 /* Use the FW Set LLDP MIB API if FW > v4.40 */
12541 if ((pf
->hw
.mac
.type
== I40E_MAC_XL710
) &&
12542 (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
>= 40)) ||
12543 (pf
->hw
.aq
.fw_maj_ver
>= 5)))
12544 pf
->hw_features
|= I40E_HW_USE_SET_LLDP_MIB
;
12546 /* Enable PTP L4 if FW > v6.0 */
12547 if (pf
->hw
.mac
.type
== I40E_MAC_XL710
&&
12548 pf
->hw
.aq
.fw_maj_ver
>= 6)
12549 pf
->hw_features
|= I40E_HW_PTP_L4_CAPABLE
;
12551 if (pf
->hw
.func_caps
.vmdq
&& num_online_cpus() != 1) {
12552 pf
->num_vmdq_vsis
= I40E_DEFAULT_NUM_VMDQ_VSI
;
12553 pf
->flags
|= I40E_FLAG_VMDQ_ENABLED
;
12554 pf
->num_vmdq_qps
= i40e_default_queues_per_vmdq(pf
);
12557 if (pf
->hw
.func_caps
.iwarp
&& num_online_cpus() != 1) {
12558 pf
->flags
|= I40E_FLAG_IWARP_ENABLED
;
12559 /* IWARP needs one extra vector for CQP just like MISC.*/
12560 pf
->num_iwarp_msix
= (int)num_online_cpus() + 1;
12562 /* Stopping FW LLDP engine is supported on XL710 and X722
12563 * starting from FW versions determined in i40e_init_adminq.
12564 * Stopping the FW LLDP engine is not supported on XL710
12565 * if NPAR is functioning so unset this hw flag in this case.
12567 if (pf
->hw
.mac
.type
== I40E_MAC_XL710
&&
12568 pf
->hw
.func_caps
.npar_enable
&&
12569 (pf
->hw
.flags
& I40E_HW_FLAG_FW_LLDP_STOPPABLE
))
12570 pf
->hw
.flags
&= ~I40E_HW_FLAG_FW_LLDP_STOPPABLE
;
12572 #ifdef CONFIG_PCI_IOV
12573 if (pf
->hw
.func_caps
.num_vfs
&& pf
->hw
.partition_id
== 1) {
12574 pf
->num_vf_qps
= I40E_DEFAULT_QUEUES_PER_VF
;
12575 pf
->flags
|= I40E_FLAG_SRIOV_ENABLED
;
12576 pf
->num_req_vfs
= min_t(int,
12577 pf
->hw
.func_caps
.num_vfs
,
12578 I40E_MAX_VF_COUNT
);
12580 #endif /* CONFIG_PCI_IOV */
12581 pf
->eeprom_version
= 0xDEAD;
12582 pf
->lan_veb
= I40E_NO_VEB
;
12583 pf
->lan_vsi
= I40E_NO_VSI
;
12585 /* By default FW has this off for performance reasons */
12586 pf
->flags
&= ~I40E_FLAG_VEB_STATS_ENABLED
;
12588 /* set up queue assignment tracking */
12589 size
= sizeof(struct i40e_lump_tracking
)
12590 + (sizeof(u16
) * pf
->hw
.func_caps
.num_tx_qp
);
12591 pf
->qp_pile
= kzalloc(size
, GFP_KERNEL
);
12592 if (!pf
->qp_pile
) {
12596 pf
->qp_pile
->num_entries
= pf
->hw
.func_caps
.num_tx_qp
;
12598 pf
->tx_timeout_recovery_level
= 1;
12600 if (pf
->hw
.mac
.type
!= I40E_MAC_X722
&&
12601 i40e_is_total_port_shutdown_enabled(pf
)) {
12602 /* Link down on close must be on when total port shutdown
12603 * is enabled for a given port
12605 pf
->flags
|= (I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENABLED
|
12606 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED
);
12607 dev_info(&pf
->pdev
->dev
,
12608 "total-port-shutdown was enabled, link-down-on-close is forced on\n");
12610 mutex_init(&pf
->switch_mutex
);
12617 * i40e_set_ntuple - set the ntuple feature flag and take action
12618 * @pf: board private structure to initialize
12619 * @features: the feature set that the stack is suggesting
12621 * returns a bool to indicate if reset needs to happen
12623 bool i40e_set_ntuple(struct i40e_pf
*pf
, netdev_features_t features
)
12625 bool need_reset
= false;
12627 /* Check if Flow Director n-tuple support was enabled or disabled. If
12628 * the state changed, we need to reset.
12630 if (features
& NETIF_F_NTUPLE
) {
12631 /* Enable filters and mark for reset */
12632 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
12634 /* enable FD_SB only if there is MSI-X vector and no cloud
12637 if (pf
->num_fdsb_msix
> 0 && !pf
->num_cloud_filters
) {
12638 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
12639 pf
->flags
&= ~I40E_FLAG_FD_SB_INACTIVE
;
12642 /* turn off filters, mark for reset and clear SW filter list */
12643 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
12645 i40e_fdir_filter_exit(pf
);
12647 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
12648 clear_bit(__I40E_FD_SB_AUTO_DISABLED
, pf
->state
);
12649 pf
->flags
|= I40E_FLAG_FD_SB_INACTIVE
;
12651 /* reset fd counters */
12652 pf
->fd_add_err
= 0;
12653 pf
->fd_atr_cnt
= 0;
12654 /* if ATR was auto disabled it can be re-enabled. */
12655 if (test_and_clear_bit(__I40E_FD_ATR_AUTO_DISABLED
, pf
->state
))
12656 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
12657 (I40E_DEBUG_FD
& pf
->hw
.debug_mask
))
12658 dev_info(&pf
->pdev
->dev
, "ATR re-enabled.\n");
12664 * i40e_clear_rss_lut - clear the rx hash lookup table
12665 * @vsi: the VSI being configured
12667 static void i40e_clear_rss_lut(struct i40e_vsi
*vsi
)
12669 struct i40e_pf
*pf
= vsi
->back
;
12670 struct i40e_hw
*hw
= &pf
->hw
;
12671 u16 vf_id
= vsi
->vf_id
;
12674 if (vsi
->type
== I40E_VSI_MAIN
) {
12675 for (i
= 0; i
<= I40E_PFQF_HLUT_MAX_INDEX
; i
++)
12676 wr32(hw
, I40E_PFQF_HLUT(i
), 0);
12677 } else if (vsi
->type
== I40E_VSI_SRIOV
) {
12678 for (i
= 0; i
<= I40E_VFQF_HLUT_MAX_INDEX
; i
++)
12679 i40e_write_rx_ctl(hw
, I40E_VFQF_HLUT1(i
, vf_id
), 0);
12681 dev_err(&pf
->pdev
->dev
, "Cannot set RSS LUT - invalid VSI type\n");
12686 * i40e_set_features - set the netdev feature flags
12687 * @netdev: ptr to the netdev being adjusted
12688 * @features: the feature set that the stack is suggesting
12689 * Note: expects to be called while under rtnl_lock()
12691 static int i40e_set_features(struct net_device
*netdev
,
12692 netdev_features_t features
)
12694 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
12695 struct i40e_vsi
*vsi
= np
->vsi
;
12696 struct i40e_pf
*pf
= vsi
->back
;
12699 if (features
& NETIF_F_RXHASH
&& !(netdev
->features
& NETIF_F_RXHASH
))
12700 i40e_pf_config_rss(pf
);
12701 else if (!(features
& NETIF_F_RXHASH
) &&
12702 netdev
->features
& NETIF_F_RXHASH
)
12703 i40e_clear_rss_lut(vsi
);
12705 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
12706 i40e_vlan_stripping_enable(vsi
);
12708 i40e_vlan_stripping_disable(vsi
);
12710 if (!(features
& NETIF_F_HW_TC
) && pf
->num_cloud_filters
) {
12711 dev_err(&pf
->pdev
->dev
,
12712 "Offloaded tc filters active, can't turn hw_tc_offload off");
12716 if (!(features
& NETIF_F_HW_L2FW_DOFFLOAD
) && vsi
->macvlan_cnt
)
12717 i40e_del_all_macvlans(vsi
);
12719 need_reset
= i40e_set_ntuple(pf
, features
);
12722 i40e_do_reset(pf
, I40E_PF_RESET_FLAG
, true);
12727 static int i40e_udp_tunnel_set_port(struct net_device
*netdev
,
12728 unsigned int table
, unsigned int idx
,
12729 struct udp_tunnel_info
*ti
)
12731 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
12732 struct i40e_hw
*hw
= &np
->vsi
->back
->hw
;
12733 u8 type
, filter_index
;
12736 type
= ti
->type
== UDP_TUNNEL_TYPE_VXLAN
? I40E_AQC_TUNNEL_TYPE_VXLAN
:
12737 I40E_AQC_TUNNEL_TYPE_NGE
;
12739 ret
= i40e_aq_add_udp_tunnel(hw
, ntohs(ti
->port
), type
, &filter_index
,
12742 netdev_info(netdev
, "add UDP port failed, err %s aq_err %s\n",
12743 i40e_stat_str(hw
, ret
),
12744 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
12748 udp_tunnel_nic_set_port_priv(netdev
, table
, idx
, filter_index
);
12752 static int i40e_udp_tunnel_unset_port(struct net_device
*netdev
,
12753 unsigned int table
, unsigned int idx
,
12754 struct udp_tunnel_info
*ti
)
12756 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
12757 struct i40e_hw
*hw
= &np
->vsi
->back
->hw
;
12760 ret
= i40e_aq_del_udp_tunnel(hw
, ti
->hw_priv
, NULL
);
12762 netdev_info(netdev
, "delete UDP port failed, err %s aq_err %s\n",
12763 i40e_stat_str(hw
, ret
),
12764 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
12771 static int i40e_get_phys_port_id(struct net_device
*netdev
,
12772 struct netdev_phys_item_id
*ppid
)
12774 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
12775 struct i40e_pf
*pf
= np
->vsi
->back
;
12776 struct i40e_hw
*hw
= &pf
->hw
;
12778 if (!(pf
->hw_features
& I40E_HW_PORT_ID_VALID
))
12779 return -EOPNOTSUPP
;
12781 ppid
->id_len
= min_t(int, sizeof(hw
->mac
.port_addr
), sizeof(ppid
->id
));
12782 memcpy(ppid
->id
, hw
->mac
.port_addr
, ppid
->id_len
);
12788 * i40e_ndo_fdb_add - add an entry to the hardware database
12789 * @ndm: the input from the stack
12790 * @tb: pointer to array of nladdr (unused)
12791 * @dev: the net device pointer
12792 * @addr: the MAC address entry being added
12794 * @flags: instructions from stack about fdb operation
12795 * @extack: netlink extended ack, unused currently
12797 static int i40e_ndo_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
12798 struct net_device
*dev
,
12799 const unsigned char *addr
, u16 vid
,
12801 struct netlink_ext_ack
*extack
)
12803 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
12804 struct i40e_pf
*pf
= np
->vsi
->back
;
12807 if (!(pf
->flags
& I40E_FLAG_SRIOV_ENABLED
))
12808 return -EOPNOTSUPP
;
12811 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev
->name
);
12815 /* Hardware does not support aging addresses so if a
12816 * ndm_state is given only allow permanent addresses
12818 if (ndm
->ndm_state
&& !(ndm
->ndm_state
& NUD_PERMANENT
)) {
12819 netdev_info(dev
, "FDB only supports static addresses\n");
12823 if (is_unicast_ether_addr(addr
) || is_link_local_ether_addr(addr
))
12824 err
= dev_uc_add_excl(dev
, addr
);
12825 else if (is_multicast_ether_addr(addr
))
12826 err
= dev_mc_add_excl(dev
, addr
);
12830 /* Only return duplicate errors if NLM_F_EXCL is set */
12831 if (err
== -EEXIST
&& !(flags
& NLM_F_EXCL
))
12838 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
12839 * @dev: the netdev being configured
12840 * @nlh: RTNL message
12841 * @flags: bridge flags
12842 * @extack: netlink extended ack
12844 * Inserts a new hardware bridge if not already created and
12845 * enables the bridging mode requested (VEB or VEPA). If the
12846 * hardware bridge has already been inserted and the request
12847 * is to change the mode then that requires a PF reset to
12848 * allow rebuild of the components with required hardware
12849 * bridge mode enabled.
12851 * Note: expects to be called while under rtnl_lock()
12853 static int i40e_ndo_bridge_setlink(struct net_device
*dev
,
12854 struct nlmsghdr
*nlh
,
12856 struct netlink_ext_ack
*extack
)
12858 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
12859 struct i40e_vsi
*vsi
= np
->vsi
;
12860 struct i40e_pf
*pf
= vsi
->back
;
12861 struct i40e_veb
*veb
= NULL
;
12862 struct nlattr
*attr
, *br_spec
;
12865 /* Only for PF VSI for now */
12866 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
)
12867 return -EOPNOTSUPP
;
12869 /* Find the HW bridge for PF VSI */
12870 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
12871 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
12875 br_spec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
12877 nla_for_each_nested(attr
, br_spec
, rem
) {
12880 if (nla_type(attr
) != IFLA_BRIDGE_MODE
)
12883 mode
= nla_get_u16(attr
);
12884 if ((mode
!= BRIDGE_MODE_VEPA
) &&
12885 (mode
!= BRIDGE_MODE_VEB
))
12888 /* Insert a new HW bridge */
12890 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
12891 vsi
->tc_config
.enabled_tc
);
12893 veb
->bridge_mode
= mode
;
12894 i40e_config_bridge_mode(veb
);
12896 /* No Bridge HW offload available */
12900 } else if (mode
!= veb
->bridge_mode
) {
12901 /* Existing HW bridge but different mode needs reset */
12902 veb
->bridge_mode
= mode
;
12903 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
12904 if (mode
== BRIDGE_MODE_VEB
)
12905 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
12907 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
12908 i40e_do_reset(pf
, I40E_PF_RESET_FLAG
, true);
12917 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
12920 * @seq: RTNL message seq #
12921 * @dev: the netdev being configured
12922 * @filter_mask: unused
12923 * @nlflags: netlink flags passed in
12925 * Return the mode in which the hardware bridge is operating in
12928 static int i40e_ndo_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
12929 struct net_device
*dev
,
12930 u32 __always_unused filter_mask
,
12933 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
12934 struct i40e_vsi
*vsi
= np
->vsi
;
12935 struct i40e_pf
*pf
= vsi
->back
;
12936 struct i40e_veb
*veb
= NULL
;
12939 /* Only for PF VSI for now */
12940 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
)
12941 return -EOPNOTSUPP
;
12943 /* Find the HW bridge for the PF VSI */
12944 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
12945 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
12952 return ndo_dflt_bridge_getlink(skb
, pid
, seq
, dev
, veb
->bridge_mode
,
12953 0, 0, nlflags
, filter_mask
, NULL
);
12957 * i40e_features_check - Validate encapsulated packet conforms to limits
12959 * @dev: This physical port's netdev
12960 * @features: Offload features that the stack believes apply
12962 static netdev_features_t
i40e_features_check(struct sk_buff
*skb
,
12963 struct net_device
*dev
,
12964 netdev_features_t features
)
12968 /* No point in doing any of this if neither checksum nor GSO are
12969 * being requested for this frame. We can rule out both by just
12970 * checking for CHECKSUM_PARTIAL
12972 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
12975 /* We cannot support GSO if the MSS is going to be less than
12976 * 64 bytes. If it is then we need to drop support for GSO.
12978 if (skb_is_gso(skb
) && (skb_shinfo(skb
)->gso_size
< 64))
12979 features
&= ~NETIF_F_GSO_MASK
;
12981 /* MACLEN can support at most 63 words */
12982 len
= skb_network_header(skb
) - skb
->data
;
12983 if (len
& ~(63 * 2))
12986 /* IPLEN and EIPLEN can support at most 127 dwords */
12987 len
= skb_transport_header(skb
) - skb_network_header(skb
);
12988 if (len
& ~(127 * 4))
12991 if (skb
->encapsulation
) {
12992 /* L4TUNLEN can support 127 words */
12993 len
= skb_inner_network_header(skb
) - skb_transport_header(skb
);
12994 if (len
& ~(127 * 2))
12997 /* IPLEN can support at most 127 dwords */
12998 len
= skb_inner_transport_header(skb
) -
12999 skb_inner_network_header(skb
);
13000 if (len
& ~(127 * 4))
13004 /* No need to validate L4LEN as TCP is the only protocol with a
13005 * a flexible value and we support all possible values supported
13006 * by TCP, which is at most 15 dwords
13011 return features
& ~(NETIF_F_CSUM_MASK
| NETIF_F_GSO_MASK
);
13015 * i40e_xdp_setup - add/remove an XDP program
13016 * @vsi: VSI to changed
13017 * @prog: XDP program
13018 * @extack: netlink extended ack
13020 static int i40e_xdp_setup(struct i40e_vsi
*vsi
, struct bpf_prog
*prog
,
13021 struct netlink_ext_ack
*extack
)
13023 int frame_size
= vsi
->netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
13024 struct i40e_pf
*pf
= vsi
->back
;
13025 struct bpf_prog
*old_prog
;
13029 /* Don't allow frames that span over multiple buffers */
13030 if (frame_size
> vsi
->rx_buf_len
) {
13031 NL_SET_ERR_MSG_MOD(extack
, "MTU too large to enable XDP");
13035 /* When turning XDP on->off/off->on we reset and rebuild the rings. */
13036 need_reset
= (i40e_enabled_xdp_vsi(vsi
) != !!prog
);
13039 i40e_prep_for_reset(pf
);
13041 old_prog
= xchg(&vsi
->xdp_prog
, prog
);
13045 /* Wait until ndo_xsk_wakeup completes. */
13047 i40e_reset_and_rebuild(pf
, true, true);
13050 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
13051 WRITE_ONCE(vsi
->rx_rings
[i
]->xdp_prog
, vsi
->xdp_prog
);
13054 bpf_prog_put(old_prog
);
13056 /* Kick start the NAPI context if there is an AF_XDP socket open
13057 * on that queue id. This so that receiving will start.
13059 if (need_reset
&& prog
)
13060 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
13061 if (vsi
->xdp_rings
[i
]->xsk_pool
)
13062 (void)i40e_xsk_wakeup(vsi
->netdev
, i
,
13069 * i40e_enter_busy_conf - Enters busy config state
13072 * Returns 0 on success, <0 for failure.
13074 static int i40e_enter_busy_conf(struct i40e_vsi
*vsi
)
13076 struct i40e_pf
*pf
= vsi
->back
;
13079 while (test_and_set_bit(__I40E_CONFIG_BUSY
, pf
->state
)) {
13083 usleep_range(1000, 2000);
13090 * i40e_exit_busy_conf - Exits busy config state
13093 static void i40e_exit_busy_conf(struct i40e_vsi
*vsi
)
13095 struct i40e_pf
*pf
= vsi
->back
;
13097 clear_bit(__I40E_CONFIG_BUSY
, pf
->state
);
13101 * i40e_queue_pair_reset_stats - Resets all statistics for a queue pair
13103 * @queue_pair: queue pair
13105 static void i40e_queue_pair_reset_stats(struct i40e_vsi
*vsi
, int queue_pair
)
13107 memset(&vsi
->rx_rings
[queue_pair
]->rx_stats
, 0,
13108 sizeof(vsi
->rx_rings
[queue_pair
]->rx_stats
));
13109 memset(&vsi
->tx_rings
[queue_pair
]->stats
, 0,
13110 sizeof(vsi
->tx_rings
[queue_pair
]->stats
));
13111 if (i40e_enabled_xdp_vsi(vsi
)) {
13112 memset(&vsi
->xdp_rings
[queue_pair
]->stats
, 0,
13113 sizeof(vsi
->xdp_rings
[queue_pair
]->stats
));
13118 * i40e_queue_pair_clean_rings - Cleans all the rings of a queue pair
13120 * @queue_pair: queue pair
13122 static void i40e_queue_pair_clean_rings(struct i40e_vsi
*vsi
, int queue_pair
)
13124 i40e_clean_tx_ring(vsi
->tx_rings
[queue_pair
]);
13125 if (i40e_enabled_xdp_vsi(vsi
)) {
13126 /* Make sure that in-progress ndo_xdp_xmit calls are
13130 i40e_clean_tx_ring(vsi
->xdp_rings
[queue_pair
]);
13132 i40e_clean_rx_ring(vsi
->rx_rings
[queue_pair
]);
13136 * i40e_queue_pair_toggle_napi - Enables/disables NAPI for a queue pair
13138 * @queue_pair: queue pair
13139 * @enable: true for enable, false for disable
13141 static void i40e_queue_pair_toggle_napi(struct i40e_vsi
*vsi
, int queue_pair
,
13144 struct i40e_ring
*rxr
= vsi
->rx_rings
[queue_pair
];
13145 struct i40e_q_vector
*q_vector
= rxr
->q_vector
;
13150 /* All rings in a qp belong to the same qvector. */
13151 if (q_vector
->rx
.ring
|| q_vector
->tx
.ring
) {
13153 napi_enable(&q_vector
->napi
);
13155 napi_disable(&q_vector
->napi
);
13160 * i40e_queue_pair_toggle_rings - Enables/disables all rings for a queue pair
13162 * @queue_pair: queue pair
13163 * @enable: true for enable, false for disable
13165 * Returns 0 on success, <0 on failure.
13167 static int i40e_queue_pair_toggle_rings(struct i40e_vsi
*vsi
, int queue_pair
,
13170 struct i40e_pf
*pf
= vsi
->back
;
13173 pf_q
= vsi
->base_queue
+ queue_pair
;
13174 ret
= i40e_control_wait_tx_q(vsi
->seid
, pf
, pf_q
,
13175 false /*is xdp*/, enable
);
13177 dev_info(&pf
->pdev
->dev
,
13178 "VSI seid %d Tx ring %d %sable timeout\n",
13179 vsi
->seid
, pf_q
, (enable
? "en" : "dis"));
13183 i40e_control_rx_q(pf
, pf_q
, enable
);
13184 ret
= i40e_pf_rxq_wait(pf
, pf_q
, enable
);
13186 dev_info(&pf
->pdev
->dev
,
13187 "VSI seid %d Rx ring %d %sable timeout\n",
13188 vsi
->seid
, pf_q
, (enable
? "en" : "dis"));
13192 /* Due to HW errata, on Rx disable only, the register can
13193 * indicate done before it really is. Needs 50ms to be sure
13198 if (!i40e_enabled_xdp_vsi(vsi
))
13201 ret
= i40e_control_wait_tx_q(vsi
->seid
, pf
,
13202 pf_q
+ vsi
->alloc_queue_pairs
,
13203 true /*is xdp*/, enable
);
13205 dev_info(&pf
->pdev
->dev
,
13206 "VSI seid %d XDP Tx ring %d %sable timeout\n",
13207 vsi
->seid
, pf_q
, (enable
? "en" : "dis"));
13214 * i40e_queue_pair_enable_irq - Enables interrupts for a queue pair
13216 * @queue_pair: queue_pair
13218 static void i40e_queue_pair_enable_irq(struct i40e_vsi
*vsi
, int queue_pair
)
13220 struct i40e_ring
*rxr
= vsi
->rx_rings
[queue_pair
];
13221 struct i40e_pf
*pf
= vsi
->back
;
13222 struct i40e_hw
*hw
= &pf
->hw
;
13224 /* All rings in a qp belong to the same qvector. */
13225 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
13226 i40e_irq_dynamic_enable(vsi
, rxr
->q_vector
->v_idx
);
13228 i40e_irq_dynamic_enable_icr0(pf
);
13234 * i40e_queue_pair_disable_irq - Disables interrupts for a queue pair
13236 * @queue_pair: queue_pair
13238 static void i40e_queue_pair_disable_irq(struct i40e_vsi
*vsi
, int queue_pair
)
13240 struct i40e_ring
*rxr
= vsi
->rx_rings
[queue_pair
];
13241 struct i40e_pf
*pf
= vsi
->back
;
13242 struct i40e_hw
*hw
= &pf
->hw
;
13244 /* For simplicity, instead of removing the qp interrupt causes
13245 * from the interrupt linked list, we simply disable the interrupt, and
13246 * leave the list intact.
13248 * All rings in a qp belong to the same qvector.
13250 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
13251 u32 intpf
= vsi
->base_vector
+ rxr
->q_vector
->v_idx
;
13253 wr32(hw
, I40E_PFINT_DYN_CTLN(intpf
- 1), 0);
13255 synchronize_irq(pf
->msix_entries
[intpf
].vector
);
13257 /* Legacy and MSI mode - this stops all interrupt handling */
13258 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0);
13259 wr32(hw
, I40E_PFINT_DYN_CTL0
, 0);
13261 synchronize_irq(pf
->pdev
->irq
);
13266 * i40e_queue_pair_disable - Disables a queue pair
13268 * @queue_pair: queue pair
13270 * Returns 0 on success, <0 on failure.
13272 int i40e_queue_pair_disable(struct i40e_vsi
*vsi
, int queue_pair
)
13276 err
= i40e_enter_busy_conf(vsi
);
13280 i40e_queue_pair_disable_irq(vsi
, queue_pair
);
13281 err
= i40e_queue_pair_toggle_rings(vsi
, queue_pair
, false /* off */);
13282 i40e_queue_pair_toggle_napi(vsi
, queue_pair
, false /* off */);
13283 i40e_queue_pair_clean_rings(vsi
, queue_pair
);
13284 i40e_queue_pair_reset_stats(vsi
, queue_pair
);
13290 * i40e_queue_pair_enable - Enables a queue pair
13292 * @queue_pair: queue pair
13294 * Returns 0 on success, <0 on failure.
13296 int i40e_queue_pair_enable(struct i40e_vsi
*vsi
, int queue_pair
)
13300 err
= i40e_configure_tx_ring(vsi
->tx_rings
[queue_pair
]);
13304 if (i40e_enabled_xdp_vsi(vsi
)) {
13305 err
= i40e_configure_tx_ring(vsi
->xdp_rings
[queue_pair
]);
13310 err
= i40e_configure_rx_ring(vsi
->rx_rings
[queue_pair
]);
13314 err
= i40e_queue_pair_toggle_rings(vsi
, queue_pair
, true /* on */);
13315 i40e_queue_pair_toggle_napi(vsi
, queue_pair
, true /* on */);
13316 i40e_queue_pair_enable_irq(vsi
, queue_pair
);
13318 i40e_exit_busy_conf(vsi
);
13324 * i40e_xdp - implements ndo_bpf for i40e
13326 * @xdp: XDP command
13328 static int i40e_xdp(struct net_device
*dev
,
13329 struct netdev_bpf
*xdp
)
13331 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
13332 struct i40e_vsi
*vsi
= np
->vsi
;
13334 if (vsi
->type
!= I40E_VSI_MAIN
)
13337 switch (xdp
->command
) {
13338 case XDP_SETUP_PROG
:
13339 return i40e_xdp_setup(vsi
, xdp
->prog
, xdp
->extack
);
13340 case XDP_SETUP_XSK_POOL
:
13341 return i40e_xsk_pool_setup(vsi
, xdp
->xsk
.pool
,
13342 xdp
->xsk
.queue_id
);
13348 static const struct net_device_ops i40e_netdev_ops
= {
13349 .ndo_open
= i40e_open
,
13350 .ndo_stop
= i40e_close
,
13351 .ndo_start_xmit
= i40e_lan_xmit_frame
,
13352 .ndo_get_stats64
= i40e_get_netdev_stats_struct
,
13353 .ndo_set_rx_mode
= i40e_set_rx_mode
,
13354 .ndo_validate_addr
= eth_validate_addr
,
13355 .ndo_set_mac_address
= i40e_set_mac
,
13356 .ndo_change_mtu
= i40e_change_mtu
,
13357 .ndo_eth_ioctl
= i40e_ioctl
,
13358 .ndo_tx_timeout
= i40e_tx_timeout
,
13359 .ndo_vlan_rx_add_vid
= i40e_vlan_rx_add_vid
,
13360 .ndo_vlan_rx_kill_vid
= i40e_vlan_rx_kill_vid
,
13361 #ifdef CONFIG_NET_POLL_CONTROLLER
13362 .ndo_poll_controller
= i40e_netpoll
,
13364 .ndo_setup_tc
= __i40e_setup_tc
,
13365 .ndo_select_queue
= i40e_lan_select_queue
,
13366 .ndo_set_features
= i40e_set_features
,
13367 .ndo_set_vf_mac
= i40e_ndo_set_vf_mac
,
13368 .ndo_set_vf_vlan
= i40e_ndo_set_vf_port_vlan
,
13369 .ndo_get_vf_stats
= i40e_get_vf_stats
,
13370 .ndo_set_vf_rate
= i40e_ndo_set_vf_bw
,
13371 .ndo_get_vf_config
= i40e_ndo_get_vf_config
,
13372 .ndo_set_vf_link_state
= i40e_ndo_set_vf_link_state
,
13373 .ndo_set_vf_spoofchk
= i40e_ndo_set_vf_spoofchk
,
13374 .ndo_set_vf_trust
= i40e_ndo_set_vf_trust
,
13375 .ndo_get_phys_port_id
= i40e_get_phys_port_id
,
13376 .ndo_fdb_add
= i40e_ndo_fdb_add
,
13377 .ndo_features_check
= i40e_features_check
,
13378 .ndo_bridge_getlink
= i40e_ndo_bridge_getlink
,
13379 .ndo_bridge_setlink
= i40e_ndo_bridge_setlink
,
13380 .ndo_bpf
= i40e_xdp
,
13381 .ndo_xdp_xmit
= i40e_xdp_xmit
,
13382 .ndo_xsk_wakeup
= i40e_xsk_wakeup
,
13383 .ndo_dfwd_add_station
= i40e_fwd_add
,
13384 .ndo_dfwd_del_station
= i40e_fwd_del
,
13388 * i40e_config_netdev - Setup the netdev flags
13389 * @vsi: the VSI being configured
13391 * Returns 0 on success, negative value on failure
13393 static int i40e_config_netdev(struct i40e_vsi
*vsi
)
13395 struct i40e_pf
*pf
= vsi
->back
;
13396 struct i40e_hw
*hw
= &pf
->hw
;
13397 struct i40e_netdev_priv
*np
;
13398 struct net_device
*netdev
;
13399 u8 broadcast
[ETH_ALEN
];
13400 u8 mac_addr
[ETH_ALEN
];
13402 netdev_features_t hw_enc_features
;
13403 netdev_features_t hw_features
;
13405 etherdev_size
= sizeof(struct i40e_netdev_priv
);
13406 netdev
= alloc_etherdev_mq(etherdev_size
, vsi
->alloc_queue_pairs
);
13410 vsi
->netdev
= netdev
;
13411 np
= netdev_priv(netdev
);
13414 hw_enc_features
= NETIF_F_SG
|
13416 NETIF_F_IPV6_CSUM
|
13418 NETIF_F_SOFT_FEATURES
|
13423 NETIF_F_GSO_GRE_CSUM
|
13424 NETIF_F_GSO_PARTIAL
|
13425 NETIF_F_GSO_IPXIP4
|
13426 NETIF_F_GSO_IPXIP6
|
13427 NETIF_F_GSO_UDP_TUNNEL
|
13428 NETIF_F_GSO_UDP_TUNNEL_CSUM
|
13429 NETIF_F_GSO_UDP_L4
|
13435 if (!(pf
->hw_features
& I40E_HW_OUTER_UDP_CSUM_CAPABLE
))
13436 netdev
->gso_partial_features
|= NETIF_F_GSO_UDP_TUNNEL_CSUM
;
13438 netdev
->udp_tunnel_nic_info
= &pf
->udp_tunnel_nic
;
13440 netdev
->gso_partial_features
|= NETIF_F_GSO_GRE_CSUM
;
13442 netdev
->hw_enc_features
|= hw_enc_features
;
13444 /* record features VLANs can make use of */
13445 netdev
->vlan_features
|= hw_enc_features
| NETIF_F_TSO_MANGLEID
;
13447 /* enable macvlan offloads */
13448 netdev
->hw_features
|= NETIF_F_HW_L2FW_DOFFLOAD
;
13450 hw_features
= hw_enc_features
|
13451 NETIF_F_HW_VLAN_CTAG_TX
|
13452 NETIF_F_HW_VLAN_CTAG_RX
;
13454 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
13455 hw_features
|= NETIF_F_NTUPLE
| NETIF_F_HW_TC
;
13457 netdev
->hw_features
|= hw_features
;
13459 netdev
->features
|= hw_features
| NETIF_F_HW_VLAN_CTAG_FILTER
;
13460 netdev
->hw_enc_features
|= NETIF_F_TSO_MANGLEID
;
13462 if (vsi
->type
== I40E_VSI_MAIN
) {
13463 SET_NETDEV_DEV(netdev
, &pf
->pdev
->dev
);
13464 ether_addr_copy(mac_addr
, hw
->mac
.perm_addr
);
13465 /* The following steps are necessary for two reasons. First,
13466 * some older NVM configurations load a default MAC-VLAN
13467 * filter that will accept any tagged packet, and we want to
13468 * replace this with a normal filter. Additionally, it is
13469 * possible our MAC address was provided by the platform using
13470 * Open Firmware or similar.
13472 * Thus, we need to remove the default filter and install one
13473 * specific to the MAC address.
13475 i40e_rm_default_mac_filter(vsi
, mac_addr
);
13476 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
13477 i40e_add_mac_filter(vsi
, mac_addr
);
13478 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
13480 /* Relate the VSI_VMDQ name to the VSI_MAIN name. Note that we
13481 * are still limited by IFNAMSIZ, but we're adding 'v%d\0' to
13482 * the end, which is 4 bytes long, so force truncation of the
13483 * original name by IFNAMSIZ - 4
13485 snprintf(netdev
->name
, IFNAMSIZ
, "%.*sv%%d",
13487 pf
->vsi
[pf
->lan_vsi
]->netdev
->name
);
13488 eth_random_addr(mac_addr
);
13490 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
13491 i40e_add_mac_filter(vsi
, mac_addr
);
13492 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
13495 /* Add the broadcast filter so that we initially will receive
13496 * broadcast packets. Note that when a new VLAN is first added the
13497 * driver will convert all filters marked I40E_VLAN_ANY into VLAN
13498 * specific filters as part of transitioning into "vlan" operation.
13499 * When more VLANs are added, the driver will copy each existing MAC
13500 * filter and add it for the new VLAN.
13502 * Broadcast filters are handled specially by
13503 * i40e_sync_filters_subtask, as the driver must to set the broadcast
13504 * promiscuous bit instead of adding this directly as a MAC/VLAN
13505 * filter. The subtask will update the correct broadcast promiscuous
13506 * bits as VLANs become active or inactive.
13508 eth_broadcast_addr(broadcast
);
13509 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
13510 i40e_add_mac_filter(vsi
, broadcast
);
13511 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
13513 ether_addr_copy(netdev
->dev_addr
, mac_addr
);
13514 ether_addr_copy(netdev
->perm_addr
, mac_addr
);
13516 /* i40iw_net_event() reads 16 bytes from neigh->primary_key */
13517 netdev
->neigh_priv_len
= sizeof(u32
) * 4;
13519 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
13520 netdev
->priv_flags
|= IFF_SUPP_NOFCS
;
13521 /* Setup netdev TC information */
13522 i40e_vsi_config_netdev_tc(vsi
, vsi
->tc_config
.enabled_tc
);
13524 netdev
->netdev_ops
= &i40e_netdev_ops
;
13525 netdev
->watchdog_timeo
= 5 * HZ
;
13526 i40e_set_ethtool_ops(netdev
);
13528 /* MTU range: 68 - 9706 */
13529 netdev
->min_mtu
= ETH_MIN_MTU
;
13530 netdev
->max_mtu
= I40E_MAX_RXBUFFER
- I40E_PACKET_HDR_PAD
;
13536 * i40e_vsi_delete - Delete a VSI from the switch
13537 * @vsi: the VSI being removed
13539 * Returns 0 on success, negative value on failure
13541 static void i40e_vsi_delete(struct i40e_vsi
*vsi
)
13543 /* remove default VSI is not allowed */
13544 if (vsi
== vsi
->back
->vsi
[vsi
->back
->lan_vsi
])
13547 i40e_aq_delete_element(&vsi
->back
->hw
, vsi
->seid
, NULL
);
13551 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
13552 * @vsi: the VSI being queried
13554 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
13556 int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi
*vsi
)
13558 struct i40e_veb
*veb
;
13559 struct i40e_pf
*pf
= vsi
->back
;
13561 /* Uplink is not a bridge so default to VEB */
13562 if (vsi
->veb_idx
>= I40E_MAX_VEB
)
13565 veb
= pf
->veb
[vsi
->veb_idx
];
13567 dev_info(&pf
->pdev
->dev
,
13568 "There is no veb associated with the bridge\n");
13572 /* Uplink is a bridge in VEPA mode */
13573 if (veb
->bridge_mode
& BRIDGE_MODE_VEPA
) {
13576 /* Uplink is a bridge in VEB mode */
13580 /* VEPA is now default bridge, so return 0 */
13585 * i40e_add_vsi - Add a VSI to the switch
13586 * @vsi: the VSI being configured
13588 * This initializes a VSI context depending on the VSI type to be added and
13589 * passes it down to the add_vsi aq command.
13591 static int i40e_add_vsi(struct i40e_vsi
*vsi
)
13594 struct i40e_pf
*pf
= vsi
->back
;
13595 struct i40e_hw
*hw
= &pf
->hw
;
13596 struct i40e_vsi_context ctxt
;
13597 struct i40e_mac_filter
*f
;
13598 struct hlist_node
*h
;
13601 u8 enabled_tc
= 0x1; /* TC0 enabled */
13604 memset(&ctxt
, 0, sizeof(ctxt
));
13605 switch (vsi
->type
) {
13606 case I40E_VSI_MAIN
:
13607 /* The PF's main VSI is already setup as part of the
13608 * device initialization, so we'll not bother with
13609 * the add_vsi call, but we will retrieve the current
13612 ctxt
.seid
= pf
->main_vsi_seid
;
13613 ctxt
.pf_num
= pf
->hw
.pf_id
;
13615 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
13616 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
13618 dev_info(&pf
->pdev
->dev
,
13619 "couldn't get PF vsi config, err %s aq_err %s\n",
13620 i40e_stat_str(&pf
->hw
, ret
),
13621 i40e_aq_str(&pf
->hw
,
13622 pf
->hw
.aq
.asq_last_status
));
13625 vsi
->info
= ctxt
.info
;
13626 vsi
->info
.valid_sections
= 0;
13628 vsi
->seid
= ctxt
.seid
;
13629 vsi
->id
= ctxt
.vsi_number
;
13631 enabled_tc
= i40e_pf_get_tc_map(pf
);
13633 /* Source pruning is enabled by default, so the flag is
13634 * negative logic - if it's set, we need to fiddle with
13635 * the VSI to disable source pruning.
13637 if (pf
->flags
& I40E_FLAG_SOURCE_PRUNING_DISABLED
) {
13638 memset(&ctxt
, 0, sizeof(ctxt
));
13639 ctxt
.seid
= pf
->main_vsi_seid
;
13640 ctxt
.pf_num
= pf
->hw
.pf_id
;
13642 ctxt
.info
.valid_sections
|=
13643 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
13644 ctxt
.info
.switch_id
=
13645 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB
);
13646 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
13648 dev_info(&pf
->pdev
->dev
,
13649 "update vsi failed, err %s aq_err %s\n",
13650 i40e_stat_str(&pf
->hw
, ret
),
13651 i40e_aq_str(&pf
->hw
,
13652 pf
->hw
.aq
.asq_last_status
));
13658 /* MFP mode setup queue map and update VSI */
13659 if ((pf
->flags
& I40E_FLAG_MFP_ENABLED
) &&
13660 !(pf
->hw
.func_caps
.iscsi
)) { /* NIC type PF */
13661 memset(&ctxt
, 0, sizeof(ctxt
));
13662 ctxt
.seid
= pf
->main_vsi_seid
;
13663 ctxt
.pf_num
= pf
->hw
.pf_id
;
13665 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
13666 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
13668 dev_info(&pf
->pdev
->dev
,
13669 "update vsi failed, err %s aq_err %s\n",
13670 i40e_stat_str(&pf
->hw
, ret
),
13671 i40e_aq_str(&pf
->hw
,
13672 pf
->hw
.aq
.asq_last_status
));
13676 /* update the local VSI info queue map */
13677 i40e_vsi_update_queue_map(vsi
, &ctxt
);
13678 vsi
->info
.valid_sections
= 0;
13680 /* Default/Main VSI is only enabled for TC0
13681 * reconfigure it to enable all TCs that are
13682 * available on the port in SFP mode.
13683 * For MFP case the iSCSI PF would use this
13684 * flow to enable LAN+iSCSI TC.
13686 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
13688 /* Single TC condition is not fatal,
13689 * message and continue
13691 dev_info(&pf
->pdev
->dev
,
13692 "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
13694 i40e_stat_str(&pf
->hw
, ret
),
13695 i40e_aq_str(&pf
->hw
,
13696 pf
->hw
.aq
.asq_last_status
));
13701 case I40E_VSI_FDIR
:
13702 ctxt
.pf_num
= hw
->pf_id
;
13704 ctxt
.uplink_seid
= vsi
->uplink_seid
;
13705 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
13706 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
13707 if ((pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
) &&
13708 (i40e_is_vsi_uplink_mode_veb(vsi
))) {
13709 ctxt
.info
.valid_sections
|=
13710 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
13711 ctxt
.info
.switch_id
=
13712 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
13714 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
13717 case I40E_VSI_VMDQ2
:
13718 ctxt
.pf_num
= hw
->pf_id
;
13720 ctxt
.uplink_seid
= vsi
->uplink_seid
;
13721 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
13722 ctxt
.flags
= I40E_AQ_VSI_TYPE_VMDQ2
;
13724 /* This VSI is connected to VEB so the switch_id
13725 * should be set to zero by default.
13727 if (i40e_is_vsi_uplink_mode_veb(vsi
)) {
13728 ctxt
.info
.valid_sections
|=
13729 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
13730 ctxt
.info
.switch_id
=
13731 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
13734 /* Setup the VSI tx/rx queue map for TC0 only for now */
13735 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
13738 case I40E_VSI_SRIOV
:
13739 ctxt
.pf_num
= hw
->pf_id
;
13740 ctxt
.vf_num
= vsi
->vf_id
+ hw
->func_caps
.vf_base_id
;
13741 ctxt
.uplink_seid
= vsi
->uplink_seid
;
13742 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
13743 ctxt
.flags
= I40E_AQ_VSI_TYPE_VF
;
13745 /* This VSI is connected to VEB so the switch_id
13746 * should be set to zero by default.
13748 if (i40e_is_vsi_uplink_mode_veb(vsi
)) {
13749 ctxt
.info
.valid_sections
|=
13750 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
13751 ctxt
.info
.switch_id
=
13752 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
13755 if (vsi
->back
->flags
& I40E_FLAG_IWARP_ENABLED
) {
13756 ctxt
.info
.valid_sections
|=
13757 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID
);
13758 ctxt
.info
.queueing_opt_flags
|=
13759 (I40E_AQ_VSI_QUE_OPT_TCP_ENA
|
13760 I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI
);
13763 ctxt
.info
.valid_sections
|= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
13764 ctxt
.info
.port_vlan_flags
|= I40E_AQ_VSI_PVLAN_MODE_ALL
;
13765 if (pf
->vf
[vsi
->vf_id
].spoofchk
) {
13766 ctxt
.info
.valid_sections
|=
13767 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID
);
13768 ctxt
.info
.sec_flags
|=
13769 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK
|
13770 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK
);
13772 /* Setup the VSI tx/rx queue map for TC0 only for now */
13773 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
13776 case I40E_VSI_IWARP
:
13777 /* send down message to iWARP */
13784 if (vsi
->type
!= I40E_VSI_MAIN
) {
13785 ret
= i40e_aq_add_vsi(hw
, &ctxt
, NULL
);
13787 dev_info(&vsi
->back
->pdev
->dev
,
13788 "add vsi failed, err %s aq_err %s\n",
13789 i40e_stat_str(&pf
->hw
, ret
),
13790 i40e_aq_str(&pf
->hw
,
13791 pf
->hw
.aq
.asq_last_status
));
13795 vsi
->info
= ctxt
.info
;
13796 vsi
->info
.valid_sections
= 0;
13797 vsi
->seid
= ctxt
.seid
;
13798 vsi
->id
= ctxt
.vsi_number
;
13801 vsi
->active_filters
= 0;
13802 clear_bit(__I40E_VSI_OVERFLOW_PROMISC
, vsi
->state
);
13803 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
13804 /* If macvlan filters already exist, force them to get loaded */
13805 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
13806 f
->state
= I40E_FILTER_NEW
;
13809 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
13812 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
13813 set_bit(__I40E_MACVLAN_SYNC_PENDING
, pf
->state
);
13816 /* Update VSI BW information */
13817 ret
= i40e_vsi_get_bw_info(vsi
);
13819 dev_info(&pf
->pdev
->dev
,
13820 "couldn't get vsi bw info, err %s aq_err %s\n",
13821 i40e_stat_str(&pf
->hw
, ret
),
13822 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
13823 /* VSI is already added so not tearing that up */
13832 * i40e_vsi_release - Delete a VSI and free its resources
13833 * @vsi: the VSI being removed
13835 * Returns 0 on success or < 0 on error
13837 int i40e_vsi_release(struct i40e_vsi
*vsi
)
13839 struct i40e_mac_filter
*f
;
13840 struct hlist_node
*h
;
13841 struct i40e_veb
*veb
= NULL
;
13842 struct i40e_pf
*pf
;
13848 /* release of a VEB-owner or last VSI is not allowed */
13849 if (vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
13850 dev_info(&pf
->pdev
->dev
, "VSI %d has existing VEB %d\n",
13851 vsi
->seid
, vsi
->uplink_seid
);
13854 if (vsi
== pf
->vsi
[pf
->lan_vsi
] &&
13855 !test_bit(__I40E_DOWN
, pf
->state
)) {
13856 dev_info(&pf
->pdev
->dev
, "Can't remove PF VSI\n");
13859 set_bit(__I40E_VSI_RELEASING
, vsi
->state
);
13860 uplink_seid
= vsi
->uplink_seid
;
13861 if (vsi
->type
!= I40E_VSI_SRIOV
) {
13862 if (vsi
->netdev_registered
) {
13863 vsi
->netdev_registered
= false;
13865 /* results in a call to i40e_close() */
13866 unregister_netdev(vsi
->netdev
);
13869 i40e_vsi_close(vsi
);
13871 i40e_vsi_disable_irq(vsi
);
13874 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
13876 /* clear the sync flag on all filters */
13878 __dev_uc_unsync(vsi
->netdev
, NULL
);
13879 __dev_mc_unsync(vsi
->netdev
, NULL
);
13882 /* make sure any remaining filters are marked for deletion */
13883 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
)
13884 __i40e_del_filter(vsi
, f
);
13886 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
13888 i40e_sync_vsi_filters(vsi
);
13890 i40e_vsi_delete(vsi
);
13891 i40e_vsi_free_q_vectors(vsi
);
13893 free_netdev(vsi
->netdev
);
13894 vsi
->netdev
= NULL
;
13896 i40e_vsi_clear_rings(vsi
);
13897 i40e_vsi_clear(vsi
);
13899 /* If this was the last thing on the VEB, except for the
13900 * controlling VSI, remove the VEB, which puts the controlling
13901 * VSI onto the next level down in the switch.
13903 * Well, okay, there's one more exception here: don't remove
13904 * the orphan VEBs yet. We'll wait for an explicit remove request
13905 * from up the network stack.
13907 for (n
= 0, i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
13909 pf
->vsi
[i
]->uplink_seid
== uplink_seid
&&
13910 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
13911 n
++; /* count the VSIs */
13914 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
13917 if (pf
->veb
[i
]->uplink_seid
== uplink_seid
)
13918 n
++; /* count the VEBs */
13919 if (pf
->veb
[i
]->seid
== uplink_seid
)
13922 if (n
== 0 && veb
&& veb
->uplink_seid
!= 0)
13923 i40e_veb_release(veb
);
13929 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
13930 * @vsi: ptr to the VSI
13932 * This should only be called after i40e_vsi_mem_alloc() which allocates the
13933 * corresponding SW VSI structure and initializes num_queue_pairs for the
13934 * newly allocated VSI.
13936 * Returns 0 on success or negative on failure
13938 static int i40e_vsi_setup_vectors(struct i40e_vsi
*vsi
)
13941 struct i40e_pf
*pf
= vsi
->back
;
13943 if (vsi
->q_vectors
[0]) {
13944 dev_info(&pf
->pdev
->dev
, "VSI %d has existing q_vectors\n",
13949 if (vsi
->base_vector
) {
13950 dev_info(&pf
->pdev
->dev
, "VSI %d has non-zero base vector %d\n",
13951 vsi
->seid
, vsi
->base_vector
);
13955 ret
= i40e_vsi_alloc_q_vectors(vsi
);
13957 dev_info(&pf
->pdev
->dev
,
13958 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
13959 vsi
->num_q_vectors
, vsi
->seid
, ret
);
13960 vsi
->num_q_vectors
= 0;
13961 goto vector_setup_out
;
13964 /* In Legacy mode, we do not have to get any other vector since we
13965 * piggyback on the misc/ICR0 for queue interrupts.
13967 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
13969 if (vsi
->num_q_vectors
)
13970 vsi
->base_vector
= i40e_get_lump(pf
, pf
->irq_pile
,
13971 vsi
->num_q_vectors
, vsi
->idx
);
13972 if (vsi
->base_vector
< 0) {
13973 dev_info(&pf
->pdev
->dev
,
13974 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
13975 vsi
->num_q_vectors
, vsi
->seid
, vsi
->base_vector
);
13976 i40e_vsi_free_q_vectors(vsi
);
13978 goto vector_setup_out
;
13986 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
13987 * @vsi: pointer to the vsi.
13989 * This re-allocates a vsi's queue resources.
13991 * Returns pointer to the successfully allocated and configured VSI sw struct
13992 * on success, otherwise returns NULL on failure.
13994 static struct i40e_vsi
*i40e_vsi_reinit_setup(struct i40e_vsi
*vsi
)
13996 u16 alloc_queue_pairs
;
13997 struct i40e_pf
*pf
;
14006 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
14007 i40e_vsi_clear_rings(vsi
);
14009 i40e_vsi_free_arrays(vsi
, false);
14010 i40e_set_num_rings_in_vsi(vsi
);
14011 ret
= i40e_vsi_alloc_arrays(vsi
, false);
14015 alloc_queue_pairs
= vsi
->alloc_queue_pairs
*
14016 (i40e_enabled_xdp_vsi(vsi
) ? 2 : 1);
14018 ret
= i40e_get_lump(pf
, pf
->qp_pile
, alloc_queue_pairs
, vsi
->idx
);
14020 dev_info(&pf
->pdev
->dev
,
14021 "failed to get tracking for %d queues for VSI %d err %d\n",
14022 alloc_queue_pairs
, vsi
->seid
, ret
);
14025 vsi
->base_queue
= ret
;
14027 /* Update the FW view of the VSI. Force a reset of TC and queue
14028 * layout configurations.
14030 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
14031 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
14032 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
14033 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
14034 if (vsi
->type
== I40E_VSI_MAIN
)
14035 i40e_rm_default_mac_filter(vsi
, pf
->hw
.mac
.perm_addr
);
14037 /* assign it some queues */
14038 ret
= i40e_alloc_rings(vsi
);
14042 /* map all of the rings to the q_vectors */
14043 i40e_vsi_map_rings_to_vectors(vsi
);
14047 i40e_vsi_free_q_vectors(vsi
);
14048 if (vsi
->netdev_registered
) {
14049 vsi
->netdev_registered
= false;
14050 unregister_netdev(vsi
->netdev
);
14051 free_netdev(vsi
->netdev
);
14052 vsi
->netdev
= NULL
;
14054 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
14056 i40e_vsi_clear(vsi
);
14061 * i40e_vsi_setup - Set up a VSI by a given type
14062 * @pf: board private structure
14064 * @uplink_seid: the switch element to link to
14065 * @param1: usage depends upon VSI type. For VF types, indicates VF id
14067 * This allocates the sw VSI structure and its queue resources, then add a VSI
14068 * to the identified VEB.
14070 * Returns pointer to the successfully allocated and configure VSI sw struct on
14071 * success, otherwise returns NULL on failure.
14073 struct i40e_vsi
*i40e_vsi_setup(struct i40e_pf
*pf
, u8 type
,
14074 u16 uplink_seid
, u32 param1
)
14076 struct i40e_vsi
*vsi
= NULL
;
14077 struct i40e_veb
*veb
= NULL
;
14078 u16 alloc_queue_pairs
;
14082 /* The requested uplink_seid must be either
14083 * - the PF's port seid
14084 * no VEB is needed because this is the PF
14085 * or this is a Flow Director special case VSI
14086 * - seid of an existing VEB
14087 * - seid of a VSI that owns an existing VEB
14088 * - seid of a VSI that doesn't own a VEB
14089 * a new VEB is created and the VSI becomes the owner
14090 * - seid of the PF VSI, which is what creates the first VEB
14091 * this is a special case of the previous
14093 * Find which uplink_seid we were given and create a new VEB if needed
14095 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
14096 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== uplink_seid
) {
14102 if (!veb
&& uplink_seid
!= pf
->mac_seid
) {
14104 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
14105 if (pf
->vsi
[i
] && pf
->vsi
[i
]->seid
== uplink_seid
) {
14111 dev_info(&pf
->pdev
->dev
, "no such uplink_seid %d\n",
14116 if (vsi
->uplink_seid
== pf
->mac_seid
)
14117 veb
= i40e_veb_setup(pf
, 0, pf
->mac_seid
, vsi
->seid
,
14118 vsi
->tc_config
.enabled_tc
);
14119 else if ((vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0)
14120 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
14121 vsi
->tc_config
.enabled_tc
);
14123 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
) {
14124 dev_info(&vsi
->back
->pdev
->dev
,
14125 "New VSI creation error, uplink seid of LAN VSI expected.\n");
14128 /* We come up by default in VEPA mode if SRIOV is not
14129 * already enabled, in which case we can't force VEPA
14132 if (!(pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)) {
14133 veb
->bridge_mode
= BRIDGE_MODE_VEPA
;
14134 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
14136 i40e_config_bridge_mode(veb
);
14138 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
14139 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
14143 dev_info(&pf
->pdev
->dev
, "couldn't add VEB\n");
14147 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
14148 uplink_seid
= veb
->seid
;
14151 /* get vsi sw struct */
14152 v_idx
= i40e_vsi_mem_alloc(pf
, type
);
14155 vsi
= pf
->vsi
[v_idx
];
14159 vsi
->veb_idx
= (veb
? veb
->idx
: I40E_NO_VEB
);
14161 if (type
== I40E_VSI_MAIN
)
14162 pf
->lan_vsi
= v_idx
;
14163 else if (type
== I40E_VSI_SRIOV
)
14164 vsi
->vf_id
= param1
;
14165 /* assign it some queues */
14166 alloc_queue_pairs
= vsi
->alloc_queue_pairs
*
14167 (i40e_enabled_xdp_vsi(vsi
) ? 2 : 1);
14169 ret
= i40e_get_lump(pf
, pf
->qp_pile
, alloc_queue_pairs
, vsi
->idx
);
14171 dev_info(&pf
->pdev
->dev
,
14172 "failed to get tracking for %d queues for VSI %d err=%d\n",
14173 alloc_queue_pairs
, vsi
->seid
, ret
);
14176 vsi
->base_queue
= ret
;
14178 /* get a VSI from the hardware */
14179 vsi
->uplink_seid
= uplink_seid
;
14180 ret
= i40e_add_vsi(vsi
);
14184 switch (vsi
->type
) {
14185 /* setup the netdev if needed */
14186 case I40E_VSI_MAIN
:
14187 case I40E_VSI_VMDQ2
:
14188 ret
= i40e_config_netdev(vsi
);
14191 ret
= i40e_netif_set_realnum_tx_rx_queues(vsi
);
14194 ret
= register_netdev(vsi
->netdev
);
14197 vsi
->netdev_registered
= true;
14198 netif_carrier_off(vsi
->netdev
);
14199 #ifdef CONFIG_I40E_DCB
14200 /* Setup DCB netlink interface */
14201 i40e_dcbnl_setup(vsi
);
14202 #endif /* CONFIG_I40E_DCB */
14204 case I40E_VSI_FDIR
:
14205 /* set up vectors and rings if needed */
14206 ret
= i40e_vsi_setup_vectors(vsi
);
14210 ret
= i40e_alloc_rings(vsi
);
14214 /* map all of the rings to the q_vectors */
14215 i40e_vsi_map_rings_to_vectors(vsi
);
14217 i40e_vsi_reset_stats(vsi
);
14220 /* no netdev or rings for the other VSI types */
14224 if ((pf
->hw_features
& I40E_HW_RSS_AQ_CAPABLE
) &&
14225 (vsi
->type
== I40E_VSI_VMDQ2
)) {
14226 ret
= i40e_vsi_config_rss(vsi
);
14231 i40e_vsi_free_q_vectors(vsi
);
14233 if (vsi
->netdev_registered
) {
14234 vsi
->netdev_registered
= false;
14235 unregister_netdev(vsi
->netdev
);
14236 free_netdev(vsi
->netdev
);
14237 vsi
->netdev
= NULL
;
14240 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
14242 i40e_vsi_clear(vsi
);
14248 * i40e_veb_get_bw_info - Query VEB BW information
14249 * @veb: the veb to query
14251 * Query the Tx scheduler BW configuration data for given VEB
14253 static int i40e_veb_get_bw_info(struct i40e_veb
*veb
)
14255 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data
;
14256 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data
;
14257 struct i40e_pf
*pf
= veb
->pf
;
14258 struct i40e_hw
*hw
= &pf
->hw
;
14263 ret
= i40e_aq_query_switch_comp_bw_config(hw
, veb
->seid
,
14266 dev_info(&pf
->pdev
->dev
,
14267 "query veb bw config failed, err %s aq_err %s\n",
14268 i40e_stat_str(&pf
->hw
, ret
),
14269 i40e_aq_str(&pf
->hw
, hw
->aq
.asq_last_status
));
14273 ret
= i40e_aq_query_switch_comp_ets_config(hw
, veb
->seid
,
14276 dev_info(&pf
->pdev
->dev
,
14277 "query veb bw ets config failed, err %s aq_err %s\n",
14278 i40e_stat_str(&pf
->hw
, ret
),
14279 i40e_aq_str(&pf
->hw
, hw
->aq
.asq_last_status
));
14283 veb
->bw_limit
= le16_to_cpu(ets_data
.port_bw_limit
);
14284 veb
->bw_max_quanta
= ets_data
.tc_bw_max
;
14285 veb
->is_abs_credits
= bw_data
.absolute_credits_enable
;
14286 veb
->enabled_tc
= ets_data
.tc_valid_bits
;
14287 tc_bw_max
= le16_to_cpu(bw_data
.tc_bw_max
[0]) |
14288 (le16_to_cpu(bw_data
.tc_bw_max
[1]) << 16);
14289 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
14290 veb
->bw_tc_share_credits
[i
] = bw_data
.tc_bw_share_credits
[i
];
14291 veb
->bw_tc_limit_credits
[i
] =
14292 le16_to_cpu(bw_data
.tc_bw_limits
[i
]);
14293 veb
->bw_tc_max_quanta
[i
] = ((tc_bw_max
>> (i
*4)) & 0x7);
14301 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
14302 * @pf: board private structure
14304 * On error: returns error code (negative)
14305 * On success: returns vsi index in PF (positive)
14307 static int i40e_veb_mem_alloc(struct i40e_pf
*pf
)
14310 struct i40e_veb
*veb
;
14313 /* Need to protect the allocation of switch elements at the PF level */
14314 mutex_lock(&pf
->switch_mutex
);
14316 /* VEB list may be fragmented if VEB creation/destruction has
14317 * been happening. We can afford to do a quick scan to look
14318 * for any free slots in the list.
14320 * find next empty veb slot, looping back around if necessary
14323 while ((i
< I40E_MAX_VEB
) && (pf
->veb
[i
] != NULL
))
14325 if (i
>= I40E_MAX_VEB
) {
14327 goto err_alloc_veb
; /* out of VEB slots! */
14330 veb
= kzalloc(sizeof(*veb
), GFP_KERNEL
);
14333 goto err_alloc_veb
;
14337 veb
->enabled_tc
= 1;
14342 mutex_unlock(&pf
->switch_mutex
);
14347 * i40e_switch_branch_release - Delete a branch of the switch tree
14348 * @branch: where to start deleting
14350 * This uses recursion to find the tips of the branch to be
14351 * removed, deleting until we get back to and can delete this VEB.
14353 static void i40e_switch_branch_release(struct i40e_veb
*branch
)
14355 struct i40e_pf
*pf
= branch
->pf
;
14356 u16 branch_seid
= branch
->seid
;
14357 u16 veb_idx
= branch
->idx
;
14360 /* release any VEBs on this VEB - RECURSION */
14361 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
14364 if (pf
->veb
[i
]->uplink_seid
== branch
->seid
)
14365 i40e_switch_branch_release(pf
->veb
[i
]);
14368 /* Release the VSIs on this VEB, but not the owner VSI.
14370 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
14371 * the VEB itself, so don't use (*branch) after this loop.
14373 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
14376 if (pf
->vsi
[i
]->uplink_seid
== branch_seid
&&
14377 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
14378 i40e_vsi_release(pf
->vsi
[i
]);
14382 /* There's one corner case where the VEB might not have been
14383 * removed, so double check it here and remove it if needed.
14384 * This case happens if the veb was created from the debugfs
14385 * commands and no VSIs were added to it.
14387 if (pf
->veb
[veb_idx
])
14388 i40e_veb_release(pf
->veb
[veb_idx
]);
14392 * i40e_veb_clear - remove veb struct
14393 * @veb: the veb to remove
14395 static void i40e_veb_clear(struct i40e_veb
*veb
)
14401 struct i40e_pf
*pf
= veb
->pf
;
14403 mutex_lock(&pf
->switch_mutex
);
14404 if (pf
->veb
[veb
->idx
] == veb
)
14405 pf
->veb
[veb
->idx
] = NULL
;
14406 mutex_unlock(&pf
->switch_mutex
);
14413 * i40e_veb_release - Delete a VEB and free its resources
14414 * @veb: the VEB being removed
14416 void i40e_veb_release(struct i40e_veb
*veb
)
14418 struct i40e_vsi
*vsi
= NULL
;
14419 struct i40e_pf
*pf
;
14424 /* find the remaining VSI and check for extras */
14425 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
14426 if (pf
->vsi
[i
] && pf
->vsi
[i
]->uplink_seid
== veb
->seid
) {
14432 dev_info(&pf
->pdev
->dev
,
14433 "can't remove VEB %d with %d VSIs left\n",
14438 /* move the remaining VSI to uplink veb */
14439 vsi
->flags
&= ~I40E_VSI_FLAG_VEB_OWNER
;
14440 if (veb
->uplink_seid
) {
14441 vsi
->uplink_seid
= veb
->uplink_seid
;
14442 if (veb
->uplink_seid
== pf
->mac_seid
)
14443 vsi
->veb_idx
= I40E_NO_VEB
;
14445 vsi
->veb_idx
= veb
->veb_idx
;
14448 vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
14449 vsi
->veb_idx
= pf
->vsi
[pf
->lan_vsi
]->veb_idx
;
14452 i40e_aq_delete_element(&pf
->hw
, veb
->seid
, NULL
);
14453 i40e_veb_clear(veb
);
14457 * i40e_add_veb - create the VEB in the switch
14458 * @veb: the VEB to be instantiated
14459 * @vsi: the controlling VSI
14461 static int i40e_add_veb(struct i40e_veb
*veb
, struct i40e_vsi
*vsi
)
14463 struct i40e_pf
*pf
= veb
->pf
;
14464 bool enable_stats
= !!(pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
);
14467 ret
= i40e_aq_add_veb(&pf
->hw
, veb
->uplink_seid
, vsi
->seid
,
14468 veb
->enabled_tc
, false,
14469 &veb
->seid
, enable_stats
, NULL
);
14471 /* get a VEB from the hardware */
14473 dev_info(&pf
->pdev
->dev
,
14474 "couldn't add VEB, err %s aq_err %s\n",
14475 i40e_stat_str(&pf
->hw
, ret
),
14476 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
14480 /* get statistics counter */
14481 ret
= i40e_aq_get_veb_parameters(&pf
->hw
, veb
->seid
, NULL
, NULL
,
14482 &veb
->stats_idx
, NULL
, NULL
, NULL
);
14484 dev_info(&pf
->pdev
->dev
,
14485 "couldn't get VEB statistics idx, err %s aq_err %s\n",
14486 i40e_stat_str(&pf
->hw
, ret
),
14487 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
14490 ret
= i40e_veb_get_bw_info(veb
);
14492 dev_info(&pf
->pdev
->dev
,
14493 "couldn't get VEB bw info, err %s aq_err %s\n",
14494 i40e_stat_str(&pf
->hw
, ret
),
14495 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
14496 i40e_aq_delete_element(&pf
->hw
, veb
->seid
, NULL
);
14500 vsi
->uplink_seid
= veb
->seid
;
14501 vsi
->veb_idx
= veb
->idx
;
14502 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
14508 * i40e_veb_setup - Set up a VEB
14509 * @pf: board private structure
14510 * @flags: VEB setup flags
14511 * @uplink_seid: the switch element to link to
14512 * @vsi_seid: the initial VSI seid
14513 * @enabled_tc: Enabled TC bit-map
14515 * This allocates the sw VEB structure and links it into the switch
14516 * It is possible and legal for this to be a duplicate of an already
14517 * existing VEB. It is also possible for both uplink and vsi seids
14518 * to be zero, in order to create a floating VEB.
14520 * Returns pointer to the successfully allocated VEB sw struct on
14521 * success, otherwise returns NULL on failure.
14523 struct i40e_veb
*i40e_veb_setup(struct i40e_pf
*pf
, u16 flags
,
14524 u16 uplink_seid
, u16 vsi_seid
,
14527 struct i40e_veb
*veb
, *uplink_veb
= NULL
;
14528 int vsi_idx
, veb_idx
;
14531 /* if one seid is 0, the other must be 0 to create a floating relay */
14532 if ((uplink_seid
== 0 || vsi_seid
== 0) &&
14533 (uplink_seid
+ vsi_seid
!= 0)) {
14534 dev_info(&pf
->pdev
->dev
,
14535 "one, not both seid's are 0: uplink=%d vsi=%d\n",
14536 uplink_seid
, vsi_seid
);
14540 /* make sure there is such a vsi and uplink */
14541 for (vsi_idx
= 0; vsi_idx
< pf
->num_alloc_vsi
; vsi_idx
++)
14542 if (pf
->vsi
[vsi_idx
] && pf
->vsi
[vsi_idx
]->seid
== vsi_seid
)
14544 if (vsi_idx
== pf
->num_alloc_vsi
&& vsi_seid
!= 0) {
14545 dev_info(&pf
->pdev
->dev
, "vsi seid %d not found\n",
14550 if (uplink_seid
&& uplink_seid
!= pf
->mac_seid
) {
14551 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
14552 if (pf
->veb
[veb_idx
] &&
14553 pf
->veb
[veb_idx
]->seid
== uplink_seid
) {
14554 uplink_veb
= pf
->veb
[veb_idx
];
14559 dev_info(&pf
->pdev
->dev
,
14560 "uplink seid %d not found\n", uplink_seid
);
14565 /* get veb sw struct */
14566 veb_idx
= i40e_veb_mem_alloc(pf
);
14569 veb
= pf
->veb
[veb_idx
];
14570 veb
->flags
= flags
;
14571 veb
->uplink_seid
= uplink_seid
;
14572 veb
->veb_idx
= (uplink_veb
? uplink_veb
->idx
: I40E_NO_VEB
);
14573 veb
->enabled_tc
= (enabled_tc
? enabled_tc
: 0x1);
14575 /* create the VEB in the switch */
14576 ret
= i40e_add_veb(veb
, pf
->vsi
[vsi_idx
]);
14579 if (vsi_idx
== pf
->lan_vsi
)
14580 pf
->lan_veb
= veb
->idx
;
14585 i40e_veb_clear(veb
);
14591 * i40e_setup_pf_switch_element - set PF vars based on switch type
14592 * @pf: board private structure
14593 * @ele: element we are building info from
14594 * @num_reported: total number of elements
14595 * @printconfig: should we print the contents
14597 * helper function to assist in extracting a few useful SEID values.
14599 static void i40e_setup_pf_switch_element(struct i40e_pf
*pf
,
14600 struct i40e_aqc_switch_config_element_resp
*ele
,
14601 u16 num_reported
, bool printconfig
)
14603 u16 downlink_seid
= le16_to_cpu(ele
->downlink_seid
);
14604 u16 uplink_seid
= le16_to_cpu(ele
->uplink_seid
);
14605 u8 element_type
= ele
->element_type
;
14606 u16 seid
= le16_to_cpu(ele
->seid
);
14609 dev_info(&pf
->pdev
->dev
,
14610 "type=%d seid=%d uplink=%d downlink=%d\n",
14611 element_type
, seid
, uplink_seid
, downlink_seid
);
14613 switch (element_type
) {
14614 case I40E_SWITCH_ELEMENT_TYPE_MAC
:
14615 pf
->mac_seid
= seid
;
14617 case I40E_SWITCH_ELEMENT_TYPE_VEB
:
14619 if (uplink_seid
!= pf
->mac_seid
)
14621 if (pf
->lan_veb
>= I40E_MAX_VEB
) {
14624 /* find existing or else empty VEB */
14625 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
14626 if (pf
->veb
[v
] && (pf
->veb
[v
]->seid
== seid
)) {
14631 if (pf
->lan_veb
>= I40E_MAX_VEB
) {
14632 v
= i40e_veb_mem_alloc(pf
);
14638 if (pf
->lan_veb
>= I40E_MAX_VEB
)
14641 pf
->veb
[pf
->lan_veb
]->seid
= seid
;
14642 pf
->veb
[pf
->lan_veb
]->uplink_seid
= pf
->mac_seid
;
14643 pf
->veb
[pf
->lan_veb
]->pf
= pf
;
14644 pf
->veb
[pf
->lan_veb
]->veb_idx
= I40E_NO_VEB
;
14646 case I40E_SWITCH_ELEMENT_TYPE_VSI
:
14647 if (num_reported
!= 1)
14649 /* This is immediately after a reset so we can assume this is
14652 pf
->mac_seid
= uplink_seid
;
14653 pf
->pf_seid
= downlink_seid
;
14654 pf
->main_vsi_seid
= seid
;
14656 dev_info(&pf
->pdev
->dev
,
14657 "pf_seid=%d main_vsi_seid=%d\n",
14658 pf
->pf_seid
, pf
->main_vsi_seid
);
14660 case I40E_SWITCH_ELEMENT_TYPE_PF
:
14661 case I40E_SWITCH_ELEMENT_TYPE_VF
:
14662 case I40E_SWITCH_ELEMENT_TYPE_EMP
:
14663 case I40E_SWITCH_ELEMENT_TYPE_BMC
:
14664 case I40E_SWITCH_ELEMENT_TYPE_PE
:
14665 case I40E_SWITCH_ELEMENT_TYPE_PA
:
14666 /* ignore these for now */
14669 dev_info(&pf
->pdev
->dev
, "unknown element type=%d seid=%d\n",
14670 element_type
, seid
);
14676 * i40e_fetch_switch_configuration - Get switch config from firmware
14677 * @pf: board private structure
14678 * @printconfig: should we print the contents
14680 * Get the current switch configuration from the device and
14681 * extract a few useful SEID values.
14683 int i40e_fetch_switch_configuration(struct i40e_pf
*pf
, bool printconfig
)
14685 struct i40e_aqc_get_switch_config_resp
*sw_config
;
14691 aq_buf
= kzalloc(I40E_AQ_LARGE_BUF
, GFP_KERNEL
);
14695 sw_config
= (struct i40e_aqc_get_switch_config_resp
*)aq_buf
;
14697 u16 num_reported
, num_total
;
14699 ret
= i40e_aq_get_switch_config(&pf
->hw
, sw_config
,
14703 dev_info(&pf
->pdev
->dev
,
14704 "get switch config failed err %s aq_err %s\n",
14705 i40e_stat_str(&pf
->hw
, ret
),
14706 i40e_aq_str(&pf
->hw
,
14707 pf
->hw
.aq
.asq_last_status
));
14712 num_reported
= le16_to_cpu(sw_config
->header
.num_reported
);
14713 num_total
= le16_to_cpu(sw_config
->header
.num_total
);
14716 dev_info(&pf
->pdev
->dev
,
14717 "header: %d reported %d total\n",
14718 num_reported
, num_total
);
14720 for (i
= 0; i
< num_reported
; i
++) {
14721 struct i40e_aqc_switch_config_element_resp
*ele
=
14722 &sw_config
->element
[i
];
14724 i40e_setup_pf_switch_element(pf
, ele
, num_reported
,
14727 } while (next_seid
!= 0);
14734 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
14735 * @pf: board private structure
14736 * @reinit: if the Main VSI needs to re-initialized.
14737 * @lock_acquired: indicates whether or not the lock has been acquired
14739 * Returns 0 on success, negative value on failure
14741 static int i40e_setup_pf_switch(struct i40e_pf
*pf
, bool reinit
, bool lock_acquired
)
14746 /* find out what's out there already */
14747 ret
= i40e_fetch_switch_configuration(pf
, false);
14749 dev_info(&pf
->pdev
->dev
,
14750 "couldn't fetch switch config, err %s aq_err %s\n",
14751 i40e_stat_str(&pf
->hw
, ret
),
14752 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
14755 i40e_pf_reset_stats(pf
);
14757 /* set the switch config bit for the whole device to
14758 * support limited promisc or true promisc
14759 * when user requests promisc. The default is limited
14763 if ((pf
->hw
.pf_id
== 0) &&
14764 !(pf
->flags
& I40E_FLAG_TRUE_PROMISC_SUPPORT
)) {
14765 flags
= I40E_AQ_SET_SWITCH_CFG_PROMISC
;
14766 pf
->last_sw_conf_flags
= flags
;
14769 if (pf
->hw
.pf_id
== 0) {
14772 valid_flags
= I40E_AQ_SET_SWITCH_CFG_PROMISC
;
14773 ret
= i40e_aq_set_switch_config(&pf
->hw
, flags
, valid_flags
, 0,
14775 if (ret
&& pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_ESRCH
) {
14776 dev_info(&pf
->pdev
->dev
,
14777 "couldn't set switch config bits, err %s aq_err %s\n",
14778 i40e_stat_str(&pf
->hw
, ret
),
14779 i40e_aq_str(&pf
->hw
,
14780 pf
->hw
.aq
.asq_last_status
));
14781 /* not a fatal problem, just keep going */
14783 pf
->last_sw_conf_valid_flags
= valid_flags
;
14786 /* first time setup */
14787 if (pf
->lan_vsi
== I40E_NO_VSI
|| reinit
) {
14788 struct i40e_vsi
*vsi
= NULL
;
14791 /* Set up the PF VSI associated with the PF's main VSI
14792 * that is already in the HW switch
14794 if (pf
->lan_veb
< I40E_MAX_VEB
&& pf
->veb
[pf
->lan_veb
])
14795 uplink_seid
= pf
->veb
[pf
->lan_veb
]->seid
;
14797 uplink_seid
= pf
->mac_seid
;
14798 if (pf
->lan_vsi
== I40E_NO_VSI
)
14799 vsi
= i40e_vsi_setup(pf
, I40E_VSI_MAIN
, uplink_seid
, 0);
14801 vsi
= i40e_vsi_reinit_setup(pf
->vsi
[pf
->lan_vsi
]);
14803 dev_info(&pf
->pdev
->dev
, "setup of MAIN VSI failed\n");
14804 i40e_cloud_filter_exit(pf
);
14805 i40e_fdir_teardown(pf
);
14809 /* force a reset of TC and queue layout configurations */
14810 u8 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
14812 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
14813 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
14814 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
14816 i40e_vlan_stripping_disable(pf
->vsi
[pf
->lan_vsi
]);
14818 i40e_fdir_sb_setup(pf
);
14820 /* Setup static PF queue filter control settings */
14821 ret
= i40e_setup_pf_filter_control(pf
);
14823 dev_info(&pf
->pdev
->dev
, "setup_pf_filter_control failed: %d\n",
14825 /* Failure here should not stop continuing other steps */
14828 /* enable RSS in the HW, even for only one queue, as the stack can use
14831 if ((pf
->flags
& I40E_FLAG_RSS_ENABLED
))
14832 i40e_pf_config_rss(pf
);
14834 /* fill in link information and enable LSE reporting */
14835 i40e_link_event(pf
);
14837 /* Initialize user-specific link properties */
14838 pf
->fc_autoneg_status
= ((pf
->hw
.phy
.link_info
.an_info
&
14839 I40E_AQ_AN_COMPLETED
) ? true : false);
14843 if (!lock_acquired
)
14846 /* repopulate tunnel port filters */
14847 udp_tunnel_nic_reset_ntf(pf
->vsi
[pf
->lan_vsi
]->netdev
);
14849 if (!lock_acquired
)
14856 * i40e_determine_queue_usage - Work out queue distribution
14857 * @pf: board private structure
14859 static void i40e_determine_queue_usage(struct i40e_pf
*pf
)
14864 pf
->num_lan_qps
= 0;
14866 /* Find the max queues to be put into basic use. We'll always be
14867 * using TC0, whether or not DCB is running, and TC0 will get the
14870 queues_left
= pf
->hw
.func_caps
.num_tx_qp
;
14872 if ((queues_left
== 1) ||
14873 !(pf
->flags
& I40E_FLAG_MSIX_ENABLED
)) {
14874 /* one qp for PF, no queues for anything else */
14876 pf
->alloc_rss_size
= pf
->num_lan_qps
= 1;
14878 /* make sure all the fancies are disabled */
14879 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
14880 I40E_FLAG_IWARP_ENABLED
|
14881 I40E_FLAG_FD_SB_ENABLED
|
14882 I40E_FLAG_FD_ATR_ENABLED
|
14883 I40E_FLAG_DCB_CAPABLE
|
14884 I40E_FLAG_DCB_ENABLED
|
14885 I40E_FLAG_SRIOV_ENABLED
|
14886 I40E_FLAG_VMDQ_ENABLED
);
14887 pf
->flags
|= I40E_FLAG_FD_SB_INACTIVE
;
14888 } else if (!(pf
->flags
& (I40E_FLAG_RSS_ENABLED
|
14889 I40E_FLAG_FD_SB_ENABLED
|
14890 I40E_FLAG_FD_ATR_ENABLED
|
14891 I40E_FLAG_DCB_CAPABLE
))) {
14892 /* one qp for PF */
14893 pf
->alloc_rss_size
= pf
->num_lan_qps
= 1;
14894 queues_left
-= pf
->num_lan_qps
;
14896 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
14897 I40E_FLAG_IWARP_ENABLED
|
14898 I40E_FLAG_FD_SB_ENABLED
|
14899 I40E_FLAG_FD_ATR_ENABLED
|
14900 I40E_FLAG_DCB_ENABLED
|
14901 I40E_FLAG_VMDQ_ENABLED
);
14902 pf
->flags
|= I40E_FLAG_FD_SB_INACTIVE
;
14904 /* Not enough queues for all TCs */
14905 if ((pf
->flags
& I40E_FLAG_DCB_CAPABLE
) &&
14906 (queues_left
< I40E_MAX_TRAFFIC_CLASS
)) {
14907 pf
->flags
&= ~(I40E_FLAG_DCB_CAPABLE
|
14908 I40E_FLAG_DCB_ENABLED
);
14909 dev_info(&pf
->pdev
->dev
, "not enough queues for DCB. DCB is disabled.\n");
14912 /* limit lan qps to the smaller of qps, cpus or msix */
14913 q_max
= max_t(int, pf
->rss_size_max
, num_online_cpus());
14914 q_max
= min_t(int, q_max
, pf
->hw
.func_caps
.num_tx_qp
);
14915 q_max
= min_t(int, q_max
, pf
->hw
.func_caps
.num_msix_vectors
);
14916 pf
->num_lan_qps
= q_max
;
14918 queues_left
-= pf
->num_lan_qps
;
14921 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
14922 if (queues_left
> 1) {
14923 queues_left
-= 1; /* save 1 queue for FD */
14925 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
14926 pf
->flags
|= I40E_FLAG_FD_SB_INACTIVE
;
14927 dev_info(&pf
->pdev
->dev
, "not enough queues for Flow Director. Flow Director feature is disabled\n");
14931 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
14932 pf
->num_vf_qps
&& pf
->num_req_vfs
&& queues_left
) {
14933 pf
->num_req_vfs
= min_t(int, pf
->num_req_vfs
,
14934 (queues_left
/ pf
->num_vf_qps
));
14935 queues_left
-= (pf
->num_req_vfs
* pf
->num_vf_qps
);
14938 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
14939 pf
->num_vmdq_vsis
&& pf
->num_vmdq_qps
&& queues_left
) {
14940 pf
->num_vmdq_vsis
= min_t(int, pf
->num_vmdq_vsis
,
14941 (queues_left
/ pf
->num_vmdq_qps
));
14942 queues_left
-= (pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
);
14945 pf
->queues_left
= queues_left
;
14946 dev_dbg(&pf
->pdev
->dev
,
14947 "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
14948 pf
->hw
.func_caps
.num_tx_qp
,
14949 !!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
),
14950 pf
->num_lan_qps
, pf
->alloc_rss_size
, pf
->num_req_vfs
,
14951 pf
->num_vf_qps
, pf
->num_vmdq_vsis
, pf
->num_vmdq_qps
,
14956 * i40e_setup_pf_filter_control - Setup PF static filter control
14957 * @pf: PF to be setup
14959 * i40e_setup_pf_filter_control sets up a PF's initial filter control
14960 * settings. If PE/FCoE are enabled then it will also set the per PF
14961 * based filter sizes required for them. It also enables Flow director,
14962 * ethertype and macvlan type filter settings for the pf.
14964 * Returns 0 on success, negative on failure
14966 static int i40e_setup_pf_filter_control(struct i40e_pf
*pf
)
14968 struct i40e_filter_control_settings
*settings
= &pf
->filter_settings
;
14970 settings
->hash_lut_size
= I40E_HASH_LUT_SIZE_128
;
14972 /* Flow Director is enabled */
14973 if (pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
))
14974 settings
->enable_fdir
= true;
14976 /* Ethtype and MACVLAN filters enabled for PF */
14977 settings
->enable_ethtype
= true;
14978 settings
->enable_macvlan
= true;
14980 if (i40e_set_filter_control(&pf
->hw
, settings
))
14986 #define INFO_STRING_LEN 255
14987 #define REMAIN(__x) (INFO_STRING_LEN - (__x))
14988 static void i40e_print_features(struct i40e_pf
*pf
)
14990 struct i40e_hw
*hw
= &pf
->hw
;
14994 buf
= kmalloc(INFO_STRING_LEN
, GFP_KERNEL
);
14998 i
= snprintf(buf
, INFO_STRING_LEN
, "Features: PF-id[%d]", hw
->pf_id
);
14999 #ifdef CONFIG_PCI_IOV
15000 i
+= scnprintf(&buf
[i
], REMAIN(i
), " VFs: %d", pf
->num_req_vfs
);
15002 i
+= scnprintf(&buf
[i
], REMAIN(i
), " VSIs: %d QP: %d",
15003 pf
->hw
.func_caps
.num_vsis
,
15004 pf
->vsi
[pf
->lan_vsi
]->num_queue_pairs
);
15005 if (pf
->flags
& I40E_FLAG_RSS_ENABLED
)
15006 i
+= scnprintf(&buf
[i
], REMAIN(i
), " RSS");
15007 if (pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
)
15008 i
+= scnprintf(&buf
[i
], REMAIN(i
), " FD_ATR");
15009 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
15010 i
+= scnprintf(&buf
[i
], REMAIN(i
), " FD_SB");
15011 i
+= scnprintf(&buf
[i
], REMAIN(i
), " NTUPLE");
15013 if (pf
->flags
& I40E_FLAG_DCB_CAPABLE
)
15014 i
+= scnprintf(&buf
[i
], REMAIN(i
), " DCB");
15015 i
+= scnprintf(&buf
[i
], REMAIN(i
), " VxLAN");
15016 i
+= scnprintf(&buf
[i
], REMAIN(i
), " Geneve");
15017 if (pf
->flags
& I40E_FLAG_PTP
)
15018 i
+= scnprintf(&buf
[i
], REMAIN(i
), " PTP");
15019 if (pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)
15020 i
+= scnprintf(&buf
[i
], REMAIN(i
), " VEB");
15022 i
+= scnprintf(&buf
[i
], REMAIN(i
), " VEPA");
15024 dev_info(&pf
->pdev
->dev
, "%s\n", buf
);
15026 WARN_ON(i
> INFO_STRING_LEN
);
15030 * i40e_get_platform_mac_addr - get platform-specific MAC address
15031 * @pdev: PCI device information struct
15032 * @pf: board private structure
15034 * Look up the MAC address for the device. First we'll try
15035 * eth_platform_get_mac_address, which will check Open Firmware, or arch
15036 * specific fallback. Otherwise, we'll default to the stored value in
15039 static void i40e_get_platform_mac_addr(struct pci_dev
*pdev
, struct i40e_pf
*pf
)
15041 if (eth_platform_get_mac_address(&pdev
->dev
, pf
->hw
.mac
.addr
))
15042 i40e_get_mac_addr(&pf
->hw
, pf
->hw
.mac
.addr
);
15046 * i40e_set_fec_in_flags - helper function for setting FEC options in flags
15047 * @fec_cfg: FEC option to set in flags
15048 * @flags: ptr to flags in which we set FEC option
15050 void i40e_set_fec_in_flags(u8 fec_cfg
, u32
*flags
)
15052 if (fec_cfg
& I40E_AQ_SET_FEC_AUTO
)
15053 *flags
|= I40E_FLAG_RS_FEC
| I40E_FLAG_BASE_R_FEC
;
15054 if ((fec_cfg
& I40E_AQ_SET_FEC_REQUEST_RS
) ||
15055 (fec_cfg
& I40E_AQ_SET_FEC_ABILITY_RS
)) {
15056 *flags
|= I40E_FLAG_RS_FEC
;
15057 *flags
&= ~I40E_FLAG_BASE_R_FEC
;
15059 if ((fec_cfg
& I40E_AQ_SET_FEC_REQUEST_KR
) ||
15060 (fec_cfg
& I40E_AQ_SET_FEC_ABILITY_KR
)) {
15061 *flags
|= I40E_FLAG_BASE_R_FEC
;
15062 *flags
&= ~I40E_FLAG_RS_FEC
;
15065 *flags
&= ~(I40E_FLAG_RS_FEC
| I40E_FLAG_BASE_R_FEC
);
15069 * i40e_check_recovery_mode - check if we are running transition firmware
15070 * @pf: board private structure
15072 * Check registers indicating the firmware runs in recovery mode. Sets the
15073 * appropriate driver state.
15075 * Returns true if the recovery mode was detected, false otherwise
15077 static bool i40e_check_recovery_mode(struct i40e_pf
*pf
)
15079 u32 val
= rd32(&pf
->hw
, I40E_GL_FWSTS
);
15081 if (val
& I40E_GL_FWSTS_FWS1B_MASK
) {
15082 dev_crit(&pf
->pdev
->dev
, "Firmware recovery mode detected. Limiting functionality.\n");
15083 dev_crit(&pf
->pdev
->dev
, "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for details on firmware recovery mode.\n");
15084 set_bit(__I40E_RECOVERY_MODE
, pf
->state
);
15088 if (test_bit(__I40E_RECOVERY_MODE
, pf
->state
))
15089 dev_info(&pf
->pdev
->dev
, "Please do Power-On Reset to initialize adapter in normal mode with full functionality.\n");
15095 * i40e_pf_loop_reset - perform reset in a loop.
15096 * @pf: board private structure
15098 * This function is useful when a NIC is about to enter recovery mode.
15099 * When a NIC's internal data structures are corrupted the NIC's
15100 * firmware is going to enter recovery mode.
15101 * Right after a POR it takes about 7 minutes for firmware to enter
15102 * recovery mode. Until that time a NIC is in some kind of intermediate
15103 * state. After that time period the NIC almost surely enters
15104 * recovery mode. The only way for a driver to detect intermediate
15105 * state is to issue a series of pf-resets and check a return value.
15106 * If a PF reset returns success then the firmware could be in recovery
15107 * mode so the caller of this code needs to check for recovery mode
15108 * if this function returns success. There is a little chance that
15109 * firmware will hang in intermediate state forever.
15110 * Since waiting 7 minutes is quite a lot of time this function waits
15111 * 10 seconds and then gives up by returning an error.
15113 * Return 0 on success, negative on failure.
15115 static i40e_status
i40e_pf_loop_reset(struct i40e_pf
*pf
)
15117 /* wait max 10 seconds for PF reset to succeed */
15118 const unsigned long time_end
= jiffies
+ 10 * HZ
;
15120 struct i40e_hw
*hw
= &pf
->hw
;
15123 ret
= i40e_pf_reset(hw
);
15124 while (ret
!= I40E_SUCCESS
&& time_before(jiffies
, time_end
)) {
15125 usleep_range(10000, 20000);
15126 ret
= i40e_pf_reset(hw
);
15129 if (ret
== I40E_SUCCESS
)
15132 dev_info(&pf
->pdev
->dev
, "PF reset failed: %d\n", ret
);
15138 * i40e_check_fw_empr - check if FW issued unexpected EMP Reset
15139 * @pf: board private structure
15141 * Check FW registers to determine if FW issued unexpected EMP Reset.
15142 * Every time when unexpected EMP Reset occurs the FW increments
15143 * a counter of unexpected EMP Resets. When the counter reaches 10
15144 * the FW should enter the Recovery mode
15146 * Returns true if FW issued unexpected EMP Reset
15148 static bool i40e_check_fw_empr(struct i40e_pf
*pf
)
15150 const u32 fw_sts
= rd32(&pf
->hw
, I40E_GL_FWSTS
) &
15151 I40E_GL_FWSTS_FWS1B_MASK
;
15152 return (fw_sts
> I40E_GL_FWSTS_FWS1B_EMPR_0
) &&
15153 (fw_sts
<= I40E_GL_FWSTS_FWS1B_EMPR_10
);
15157 * i40e_handle_resets - handle EMP resets and PF resets
15158 * @pf: board private structure
15160 * Handle both EMP resets and PF resets and conclude whether there are
15161 * any issues regarding these resets. If there are any issues then
15162 * generate log entry.
15164 * Return 0 if NIC is healthy or negative value when there are issues
15167 static i40e_status
i40e_handle_resets(struct i40e_pf
*pf
)
15169 const i40e_status pfr
= i40e_pf_loop_reset(pf
);
15170 const bool is_empr
= i40e_check_fw_empr(pf
);
15172 if (is_empr
|| pfr
!= I40E_SUCCESS
)
15173 dev_crit(&pf
->pdev
->dev
, "Entering recovery mode due to repeated FW resets. This may take several minutes. Refer to the Intel(R) Ethernet Adapters and Devices User Guide.\n");
15175 return is_empr
? I40E_ERR_RESET_FAILED
: pfr
;
15179 * i40e_init_recovery_mode - initialize subsystems needed in recovery mode
15180 * @pf: board private structure
15181 * @hw: ptr to the hardware info
15183 * This function does a minimal setup of all subsystems needed for running
15186 * Returns 0 on success, negative on failure
15188 static int i40e_init_recovery_mode(struct i40e_pf
*pf
, struct i40e_hw
*hw
)
15190 struct i40e_vsi
*vsi
;
15194 pci_save_state(pf
->pdev
);
15196 /* set up periodic task facility */
15197 timer_setup(&pf
->service_timer
, i40e_service_timer
, 0);
15198 pf
->service_timer_period
= HZ
;
15200 INIT_WORK(&pf
->service_task
, i40e_service_task
);
15201 clear_bit(__I40E_SERVICE_SCHED
, pf
->state
);
15203 err
= i40e_init_interrupt_scheme(pf
);
15205 goto err_switch_setup
;
15207 /* The number of VSIs reported by the FW is the minimum guaranteed
15208 * to us; HW supports far more and we share the remaining pool with
15209 * the other PFs. We allocate space for more than the guarantee with
15210 * the understanding that we might not get them all later.
15212 if (pf
->hw
.func_caps
.num_vsis
< I40E_MIN_VSI_ALLOC
)
15213 pf
->num_alloc_vsi
= I40E_MIN_VSI_ALLOC
;
15215 pf
->num_alloc_vsi
= pf
->hw
.func_caps
.num_vsis
;
15217 /* Set up the vsi struct and our local tracking of the MAIN PF vsi. */
15218 pf
->vsi
= kcalloc(pf
->num_alloc_vsi
, sizeof(struct i40e_vsi
*),
15222 goto err_switch_setup
;
15225 /* We allocate one VSI which is needed as absolute minimum
15226 * in order to register the netdev
15228 v_idx
= i40e_vsi_mem_alloc(pf
, I40E_VSI_MAIN
);
15231 goto err_switch_setup
;
15233 pf
->lan_vsi
= v_idx
;
15234 vsi
= pf
->vsi
[v_idx
];
15237 goto err_switch_setup
;
15239 vsi
->alloc_queue_pairs
= 1;
15240 err
= i40e_config_netdev(vsi
);
15242 goto err_switch_setup
;
15243 err
= register_netdev(vsi
->netdev
);
15245 goto err_switch_setup
;
15246 vsi
->netdev_registered
= true;
15247 i40e_dbg_pf_init(pf
);
15249 err
= i40e_setup_misc_vector_for_recovery_mode(pf
);
15251 goto err_switch_setup
;
15253 /* tell the firmware that we're starting */
15254 i40e_send_version(pf
);
15256 /* since everything's happy, start the service_task timer */
15257 mod_timer(&pf
->service_timer
,
15258 round_jiffies(jiffies
+ pf
->service_timer_period
));
15263 i40e_reset_interrupt_capability(pf
);
15264 del_timer_sync(&pf
->service_timer
);
15265 i40e_shutdown_adminq(hw
);
15266 iounmap(hw
->hw_addr
);
15267 pci_disable_pcie_error_reporting(pf
->pdev
);
15268 pci_release_mem_regions(pf
->pdev
);
15269 pci_disable_device(pf
->pdev
);
15276 * i40e_set_subsystem_device_id - set subsystem device id
15277 * @hw: pointer to the hardware info
15279 * Set PCI subsystem device id either from a pci_dev structure or
15280 * a specific FW register.
15282 static inline void i40e_set_subsystem_device_id(struct i40e_hw
*hw
)
15284 struct pci_dev
*pdev
= ((struct i40e_pf
*)hw
->back
)->pdev
;
15286 hw
->subsystem_device_id
= pdev
->subsystem_device
?
15287 pdev
->subsystem_device
:
15288 (ushort
)(rd32(hw
, I40E_PFPCI_SUBSYSID
) & USHRT_MAX
);
15292 * i40e_probe - Device initialization routine
15293 * @pdev: PCI device information struct
15294 * @ent: entry in i40e_pci_tbl
15296 * i40e_probe initializes a PF identified by a pci_dev structure.
15297 * The OS initialization, configuring of the PF private structure,
15298 * and a hardware reset occur.
15300 * Returns 0 on success, negative on failure
15302 static int i40e_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
15304 struct i40e_aq_get_phy_abilities_resp abilities
;
15305 #ifdef CONFIG_I40E_DCB
15306 enum i40e_get_fw_lldp_status_resp lldp_status
;
15307 i40e_status status
;
15308 #endif /* CONFIG_I40E_DCB */
15309 struct i40e_pf
*pf
;
15310 struct i40e_hw
*hw
;
15311 static u16 pfs_found
;
15318 err
= pci_enable_device_mem(pdev
);
15322 /* set up for high or low dma */
15323 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
15325 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
15327 dev_err(&pdev
->dev
,
15328 "DMA configuration failed: 0x%x\n", err
);
15333 /* set up pci connections */
15334 err
= pci_request_mem_regions(pdev
, i40e_driver_name
);
15336 dev_info(&pdev
->dev
,
15337 "pci_request_selected_regions failed %d\n", err
);
15341 pci_enable_pcie_error_reporting(pdev
);
15342 pci_set_master(pdev
);
15344 /* Now that we have a PCI connection, we need to do the
15345 * low level device setup. This is primarily setting up
15346 * the Admin Queue structures and then querying for the
15347 * device's current profile information.
15349 pf
= kzalloc(sizeof(*pf
), GFP_KERNEL
);
15356 set_bit(__I40E_DOWN
, pf
->state
);
15361 pf
->ioremap_len
= min_t(int, pci_resource_len(pdev
, 0),
15362 I40E_MAX_CSR_SPACE
);
15363 /* We believe that the highest register to read is
15364 * I40E_GLGEN_STAT_CLEAR, so we check if the BAR size
15365 * is not less than that before mapping to prevent a
15368 if (pf
->ioremap_len
< I40E_GLGEN_STAT_CLEAR
) {
15369 dev_err(&pdev
->dev
, "Cannot map registers, bar size 0x%X too small, aborting\n",
15374 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0), pf
->ioremap_len
);
15375 if (!hw
->hw_addr
) {
15377 dev_info(&pdev
->dev
, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
15378 (unsigned int)pci_resource_start(pdev
, 0),
15379 pf
->ioremap_len
, err
);
15382 hw
->vendor_id
= pdev
->vendor
;
15383 hw
->device_id
= pdev
->device
;
15384 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
15385 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
15386 i40e_set_subsystem_device_id(hw
);
15387 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
15388 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
15389 hw
->bus
.bus_id
= pdev
->bus
->number
;
15390 pf
->instance
= pfs_found
;
15392 /* Select something other than the 802.1ad ethertype for the
15393 * switch to use internally and drop on ingress.
15395 hw
->switch_tag
= 0xffff;
15396 hw
->first_tag
= ETH_P_8021AD
;
15397 hw
->second_tag
= ETH_P_8021Q
;
15399 INIT_LIST_HEAD(&pf
->l3_flex_pit_list
);
15400 INIT_LIST_HEAD(&pf
->l4_flex_pit_list
);
15401 INIT_LIST_HEAD(&pf
->ddp_old_prof
);
15403 /* set up the locks for the AQ, do this only once in probe
15404 * and destroy them only once in remove
15406 mutex_init(&hw
->aq
.asq_mutex
);
15407 mutex_init(&hw
->aq
.arq_mutex
);
15409 pf
->msg_enable
= netif_msg_init(debug
,
15414 pf
->hw
.debug_mask
= debug
;
15416 /* do a special CORER for clearing PXE mode once at init */
15417 if (hw
->revision_id
== 0 &&
15418 (rd32(hw
, I40E_GLLAN_RCTL_0
) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK
)) {
15419 wr32(hw
, I40E_GLGEN_RTRIG
, I40E_GLGEN_RTRIG_CORER_MASK
);
15424 i40e_clear_pxe_mode(hw
);
15427 /* Reset here to make sure all is clean and to define PF 'n' */
15430 err
= i40e_set_mac_type(hw
);
15432 dev_warn(&pdev
->dev
, "unidentified MAC or BLANK NVM: %d\n",
15437 err
= i40e_handle_resets(pf
);
15441 i40e_check_recovery_mode(pf
);
15443 if (is_kdump_kernel()) {
15444 hw
->aq
.num_arq_entries
= I40E_MIN_ARQ_LEN
;
15445 hw
->aq
.num_asq_entries
= I40E_MIN_ASQ_LEN
;
15447 hw
->aq
.num_arq_entries
= I40E_AQ_LEN
;
15448 hw
->aq
.num_asq_entries
= I40E_AQ_LEN
;
15450 hw
->aq
.arq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
15451 hw
->aq
.asq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
15452 pf
->adminq_work_limit
= I40E_AQ_WORK_LIMIT
;
15454 snprintf(pf
->int_name
, sizeof(pf
->int_name
) - 1,
15456 dev_driver_string(&pf
->pdev
->dev
), dev_name(&pdev
->dev
));
15458 err
= i40e_init_shared_code(hw
);
15460 dev_warn(&pdev
->dev
, "unidentified MAC or BLANK NVM: %d\n",
15465 /* set up a default setting for link flow control */
15466 pf
->hw
.fc
.requested_mode
= I40E_FC_NONE
;
15468 err
= i40e_init_adminq(hw
);
15470 if (err
== I40E_ERR_FIRMWARE_API_VERSION
)
15471 dev_info(&pdev
->dev
,
15472 "The driver for the device stopped because the NVM image v%u.%u is newer than expected v%u.%u. You must install the most recent version of the network driver.\n",
15473 hw
->aq
.api_maj_ver
,
15474 hw
->aq
.api_min_ver
,
15475 I40E_FW_API_VERSION_MAJOR
,
15476 I40E_FW_MINOR_VERSION(hw
));
15478 dev_info(&pdev
->dev
,
15479 "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
15483 i40e_get_oem_version(hw
);
15485 /* provide nvm, fw, api versions, vendor:device id, subsys vendor:device id */
15486 dev_info(&pdev
->dev
, "fw %d.%d.%05d api %d.%d nvm %s [%04x:%04x] [%04x:%04x]\n",
15487 hw
->aq
.fw_maj_ver
, hw
->aq
.fw_min_ver
, hw
->aq
.fw_build
,
15488 hw
->aq
.api_maj_ver
, hw
->aq
.api_min_ver
,
15489 i40e_nvm_version_str(hw
), hw
->vendor_id
, hw
->device_id
,
15490 hw
->subsystem_vendor_id
, hw
->subsystem_device_id
);
15492 if (hw
->aq
.api_maj_ver
== I40E_FW_API_VERSION_MAJOR
&&
15493 hw
->aq
.api_min_ver
> I40E_FW_MINOR_VERSION(hw
))
15494 dev_dbg(&pdev
->dev
,
15495 "The driver for the device detected a newer version of the NVM image v%u.%u than v%u.%u.\n",
15496 hw
->aq
.api_maj_ver
,
15497 hw
->aq
.api_min_ver
,
15498 I40E_FW_API_VERSION_MAJOR
,
15499 I40E_FW_MINOR_VERSION(hw
));
15500 else if (hw
->aq
.api_maj_ver
== 1 && hw
->aq
.api_min_ver
< 4)
15501 dev_info(&pdev
->dev
,
15502 "The driver for the device detected an older version of the NVM image v%u.%u than expected v%u.%u. Please update the NVM image.\n",
15503 hw
->aq
.api_maj_ver
,
15504 hw
->aq
.api_min_ver
,
15505 I40E_FW_API_VERSION_MAJOR
,
15506 I40E_FW_MINOR_VERSION(hw
));
15508 i40e_verify_eeprom(pf
);
15510 /* Rev 0 hardware was never productized */
15511 if (hw
->revision_id
< 1)
15512 dev_warn(&pdev
->dev
, "This device is a pre-production adapter/LOM. Please be aware there may be issues with your hardware. If you are experiencing problems please contact your Intel or hardware representative who provided you with this hardware.\n");
15514 i40e_clear_pxe_mode(hw
);
15516 err
= i40e_get_capabilities(pf
, i40e_aqc_opc_list_func_capabilities
);
15518 goto err_adminq_setup
;
15520 err
= i40e_sw_init(pf
);
15522 dev_info(&pdev
->dev
, "sw_init failed: %d\n", err
);
15526 if (test_bit(__I40E_RECOVERY_MODE
, pf
->state
))
15527 return i40e_init_recovery_mode(pf
, hw
);
15529 err
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
15530 hw
->func_caps
.num_rx_qp
, 0, 0);
15532 dev_info(&pdev
->dev
, "init_lan_hmc failed: %d\n", err
);
15533 goto err_init_lan_hmc
;
15536 err
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
15538 dev_info(&pdev
->dev
, "configure_lan_hmc failed: %d\n", err
);
15540 goto err_configure_lan_hmc
;
15543 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
15544 * Ignore error return codes because if it was already disabled via
15545 * hardware settings this will fail
15547 if (pf
->hw_features
& I40E_HW_STOP_FW_LLDP
) {
15548 dev_info(&pdev
->dev
, "Stopping firmware LLDP agent.\n");
15549 i40e_aq_stop_lldp(hw
, true, false, NULL
);
15552 /* allow a platform config to override the HW addr */
15553 i40e_get_platform_mac_addr(pdev
, pf
);
15555 if (!is_valid_ether_addr(hw
->mac
.addr
)) {
15556 dev_info(&pdev
->dev
, "invalid MAC address %pM\n", hw
->mac
.addr
);
15560 dev_info(&pdev
->dev
, "MAC address: %pM\n", hw
->mac
.addr
);
15561 ether_addr_copy(hw
->mac
.perm_addr
, hw
->mac
.addr
);
15562 i40e_get_port_mac_addr(hw
, hw
->mac
.port_addr
);
15563 if (is_valid_ether_addr(hw
->mac
.port_addr
))
15564 pf
->hw_features
|= I40E_HW_PORT_ID_VALID
;
15566 i40e_ptp_alloc_pins(pf
);
15567 pci_set_drvdata(pdev
, pf
);
15568 pci_save_state(pdev
);
15570 #ifdef CONFIG_I40E_DCB
15571 status
= i40e_get_fw_lldp_status(&pf
->hw
, &lldp_status
);
15573 lldp_status
== I40E_GET_FW_LLDP_STATUS_ENABLED
) ?
15574 (pf
->flags
&= ~I40E_FLAG_DISABLE_FW_LLDP
) :
15575 (pf
->flags
|= I40E_FLAG_DISABLE_FW_LLDP
);
15576 dev_info(&pdev
->dev
,
15577 (pf
->flags
& I40E_FLAG_DISABLE_FW_LLDP
) ?
15578 "FW LLDP is disabled\n" :
15579 "FW LLDP is enabled\n");
15581 /* Enable FW to write default DCB config on link-up */
15582 i40e_aq_set_dcb_parameters(hw
, true, NULL
);
15584 err
= i40e_init_pf_dcb(pf
);
15586 dev_info(&pdev
->dev
, "DCB init failed %d, disabled\n", err
);
15587 pf
->flags
&= ~(I40E_FLAG_DCB_CAPABLE
| I40E_FLAG_DCB_ENABLED
);
15588 /* Continue without DCB enabled */
15590 #endif /* CONFIG_I40E_DCB */
15592 /* set up periodic task facility */
15593 timer_setup(&pf
->service_timer
, i40e_service_timer
, 0);
15594 pf
->service_timer_period
= HZ
;
15596 INIT_WORK(&pf
->service_task
, i40e_service_task
);
15597 clear_bit(__I40E_SERVICE_SCHED
, pf
->state
);
15599 /* NVM bit on means WoL disabled for the port */
15600 i40e_read_nvm_word(hw
, I40E_SR_NVM_WAKE_ON_LAN
, &wol_nvm_bits
);
15601 if (BIT (hw
->port
) & wol_nvm_bits
|| hw
->partition_id
!= 1)
15602 pf
->wol_en
= false;
15605 device_set_wakeup_enable(&pf
->pdev
->dev
, pf
->wol_en
);
15607 /* set up the main switch operations */
15608 i40e_determine_queue_usage(pf
);
15609 err
= i40e_init_interrupt_scheme(pf
);
15611 goto err_switch_setup
;
15613 /* Reduce Tx and Rx pairs for kdump
15614 * When MSI-X is enabled, it's not allowed to use more TC queue
15615 * pairs than MSI-X vectors (pf->num_lan_msix) exist. Thus
15616 * vsi->num_queue_pairs will be equal to pf->num_lan_msix, i.e., 1.
15618 if (is_kdump_kernel())
15619 pf
->num_lan_msix
= 1;
15621 pf
->udp_tunnel_nic
.set_port
= i40e_udp_tunnel_set_port
;
15622 pf
->udp_tunnel_nic
.unset_port
= i40e_udp_tunnel_unset_port
;
15623 pf
->udp_tunnel_nic
.flags
= UDP_TUNNEL_NIC_INFO_MAY_SLEEP
;
15624 pf
->udp_tunnel_nic
.shared
= &pf
->udp_tunnel_shared
;
15625 pf
->udp_tunnel_nic
.tables
[0].n_entries
= I40E_MAX_PF_UDP_OFFLOAD_PORTS
;
15626 pf
->udp_tunnel_nic
.tables
[0].tunnel_types
= UDP_TUNNEL_TYPE_VXLAN
|
15627 UDP_TUNNEL_TYPE_GENEVE
;
15629 /* The number of VSIs reported by the FW is the minimum guaranteed
15630 * to us; HW supports far more and we share the remaining pool with
15631 * the other PFs. We allocate space for more than the guarantee with
15632 * the understanding that we might not get them all later.
15634 if (pf
->hw
.func_caps
.num_vsis
< I40E_MIN_VSI_ALLOC
)
15635 pf
->num_alloc_vsi
= I40E_MIN_VSI_ALLOC
;
15637 pf
->num_alloc_vsi
= pf
->hw
.func_caps
.num_vsis
;
15638 if (pf
->num_alloc_vsi
> UDP_TUNNEL_NIC_MAX_SHARING_DEVICES
) {
15639 dev_warn(&pf
->pdev
->dev
,
15640 "limiting the VSI count due to UDP tunnel limitation %d > %d\n",
15641 pf
->num_alloc_vsi
, UDP_TUNNEL_NIC_MAX_SHARING_DEVICES
);
15642 pf
->num_alloc_vsi
= UDP_TUNNEL_NIC_MAX_SHARING_DEVICES
;
15645 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
15646 pf
->vsi
= kcalloc(pf
->num_alloc_vsi
, sizeof(struct i40e_vsi
*),
15650 goto err_switch_setup
;
15653 #ifdef CONFIG_PCI_IOV
15654 /* prep for VF support */
15655 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
15656 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
15657 !test_bit(__I40E_BAD_EEPROM
, pf
->state
)) {
15658 if (pci_num_vf(pdev
))
15659 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
15662 err
= i40e_setup_pf_switch(pf
, false, false);
15664 dev_info(&pdev
->dev
, "setup_pf_switch failed: %d\n", err
);
15667 INIT_LIST_HEAD(&pf
->vsi
[pf
->lan_vsi
]->ch_list
);
15669 /* if FDIR VSI was set up, start it now */
15670 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
15671 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
15672 i40e_vsi_open(pf
->vsi
[i
]);
15677 /* The driver only wants link up/down and module qualification
15678 * reports from firmware. Note the negative logic.
15680 err
= i40e_aq_set_phy_int_mask(&pf
->hw
,
15681 ~(I40E_AQ_EVENT_LINK_UPDOWN
|
15682 I40E_AQ_EVENT_MEDIA_NA
|
15683 I40E_AQ_EVENT_MODULE_QUAL_FAIL
), NULL
);
15685 dev_info(&pf
->pdev
->dev
, "set phy mask fail, err %s aq_err %s\n",
15686 i40e_stat_str(&pf
->hw
, err
),
15687 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
15689 /* Reconfigure hardware for allowing smaller MSS in the case
15690 * of TSO, so that we avoid the MDD being fired and causing
15691 * a reset in the case of small MSS+TSO.
15693 val
= rd32(hw
, I40E_REG_MSS
);
15694 if ((val
& I40E_REG_MSS_MIN_MASK
) > I40E_64BYTE_MSS
) {
15695 val
&= ~I40E_REG_MSS_MIN_MASK
;
15696 val
|= I40E_64BYTE_MSS
;
15697 wr32(hw
, I40E_REG_MSS
, val
);
15700 if (pf
->hw_features
& I40E_HW_RESTART_AUTONEG
) {
15702 err
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
15704 dev_info(&pf
->pdev
->dev
, "link restart failed, err %s aq_err %s\n",
15705 i40e_stat_str(&pf
->hw
, err
),
15706 i40e_aq_str(&pf
->hw
,
15707 pf
->hw
.aq
.asq_last_status
));
15709 /* The main driver is (mostly) up and happy. We need to set this state
15710 * before setting up the misc vector or we get a race and the vector
15711 * ends up disabled forever.
15713 clear_bit(__I40E_DOWN
, pf
->state
);
15715 /* In case of MSIX we are going to setup the misc vector right here
15716 * to handle admin queue events etc. In case of legacy and MSI
15717 * the misc functionality and queue processing is combined in
15718 * the same vector and that gets setup at open.
15720 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
15721 err
= i40e_setup_misc_vector(pf
);
15723 dev_info(&pdev
->dev
,
15724 "setup of misc vector failed: %d\n", err
);
15725 i40e_cloud_filter_exit(pf
);
15726 i40e_fdir_teardown(pf
);
15731 #ifdef CONFIG_PCI_IOV
15732 /* prep for VF support */
15733 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
15734 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
15735 !test_bit(__I40E_BAD_EEPROM
, pf
->state
)) {
15736 /* disable link interrupts for VFs */
15737 val
= rd32(hw
, I40E_PFGEN_PORTMDIO_NUM
);
15738 val
&= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK
;
15739 wr32(hw
, I40E_PFGEN_PORTMDIO_NUM
, val
);
15742 if (pci_num_vf(pdev
)) {
15743 dev_info(&pdev
->dev
,
15744 "Active VFs found, allocating resources.\n");
15745 err
= i40e_alloc_vfs(pf
, pci_num_vf(pdev
));
15747 dev_info(&pdev
->dev
,
15748 "Error %d allocating resources for existing VFs\n",
15752 #endif /* CONFIG_PCI_IOV */
15754 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
) {
15755 pf
->iwarp_base_vector
= i40e_get_lump(pf
, pf
->irq_pile
,
15756 pf
->num_iwarp_msix
,
15757 I40E_IWARP_IRQ_PILE_ID
);
15758 if (pf
->iwarp_base_vector
< 0) {
15759 dev_info(&pdev
->dev
,
15760 "failed to get tracking for %d vectors for IWARP err=%d\n",
15761 pf
->num_iwarp_msix
, pf
->iwarp_base_vector
);
15762 pf
->flags
&= ~I40E_FLAG_IWARP_ENABLED
;
15766 i40e_dbg_pf_init(pf
);
15768 /* tell the firmware that we're starting */
15769 i40e_send_version(pf
);
15771 /* since everything's happy, start the service_task timer */
15772 mod_timer(&pf
->service_timer
,
15773 round_jiffies(jiffies
+ pf
->service_timer_period
));
15775 /* add this PF to client device list and launch a client service task */
15776 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
) {
15777 err
= i40e_lan_add_device(pf
);
15779 dev_info(&pdev
->dev
, "Failed to add PF to client API service list: %d\n",
15783 #define PCI_SPEED_SIZE 8
15784 #define PCI_WIDTH_SIZE 8
15785 /* Devices on the IOSF bus do not have this information
15786 * and will report PCI Gen 1 x 1 by default so don't bother
15789 if (!(pf
->hw_features
& I40E_HW_NO_PCI_LINK_CHECK
)) {
15790 char speed
[PCI_SPEED_SIZE
] = "Unknown";
15791 char width
[PCI_WIDTH_SIZE
] = "Unknown";
15793 /* Get the negotiated link width and speed from PCI config
15796 pcie_capability_read_word(pf
->pdev
, PCI_EXP_LNKSTA
,
15799 i40e_set_pci_config_data(hw
, link_status
);
15801 switch (hw
->bus
.speed
) {
15802 case i40e_bus_speed_8000
:
15803 strlcpy(speed
, "8.0", PCI_SPEED_SIZE
); break;
15804 case i40e_bus_speed_5000
:
15805 strlcpy(speed
, "5.0", PCI_SPEED_SIZE
); break;
15806 case i40e_bus_speed_2500
:
15807 strlcpy(speed
, "2.5", PCI_SPEED_SIZE
); break;
15811 switch (hw
->bus
.width
) {
15812 case i40e_bus_width_pcie_x8
:
15813 strlcpy(width
, "8", PCI_WIDTH_SIZE
); break;
15814 case i40e_bus_width_pcie_x4
:
15815 strlcpy(width
, "4", PCI_WIDTH_SIZE
); break;
15816 case i40e_bus_width_pcie_x2
:
15817 strlcpy(width
, "2", PCI_WIDTH_SIZE
); break;
15818 case i40e_bus_width_pcie_x1
:
15819 strlcpy(width
, "1", PCI_WIDTH_SIZE
); break;
15824 dev_info(&pdev
->dev
, "PCI-Express: Speed %sGT/s Width x%s\n",
15827 if (hw
->bus
.width
< i40e_bus_width_pcie_x8
||
15828 hw
->bus
.speed
< i40e_bus_speed_8000
) {
15829 dev_warn(&pdev
->dev
, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
15830 dev_warn(&pdev
->dev
, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
15834 /* get the requested speeds from the fw */
15835 err
= i40e_aq_get_phy_capabilities(hw
, false, false, &abilities
, NULL
);
15837 dev_dbg(&pf
->pdev
->dev
, "get requested speeds ret = %s last_status = %s\n",
15838 i40e_stat_str(&pf
->hw
, err
),
15839 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
15840 pf
->hw
.phy
.link_info
.requested_speeds
= abilities
.link_speed
;
15842 /* set the FEC config due to the board capabilities */
15843 i40e_set_fec_in_flags(abilities
.fec_cfg_curr_mod_ext_info
, &pf
->flags
);
15845 /* get the supported phy types from the fw */
15846 err
= i40e_aq_get_phy_capabilities(hw
, false, true, &abilities
, NULL
);
15848 dev_dbg(&pf
->pdev
->dev
, "get supported phy types ret = %s last_status = %s\n",
15849 i40e_stat_str(&pf
->hw
, err
),
15850 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
15852 /* make sure the MFS hasn't been set lower than the default */
15853 #define MAX_FRAME_SIZE_DEFAULT 0x2600
15854 val
= (rd32(&pf
->hw
, I40E_PRTGL_SAH
) &
15855 I40E_PRTGL_SAH_MFS_MASK
) >> I40E_PRTGL_SAH_MFS_SHIFT
;
15856 if (val
< MAX_FRAME_SIZE_DEFAULT
)
15857 dev_warn(&pdev
->dev
, "MFS for port %x has been set below the default: %x\n",
15860 /* Add a filter to drop all Flow control frames from any VSI from being
15861 * transmitted. By doing so we stop a malicious VF from sending out
15862 * PAUSE or PFC frames and potentially controlling traffic for other
15864 * The FW can still send Flow control frames if enabled.
15866 i40e_add_filter_to_drop_tx_flow_control_frames(&pf
->hw
,
15867 pf
->main_vsi_seid
);
15869 if ((pf
->hw
.device_id
== I40E_DEV_ID_10G_BASE_T
) ||
15870 (pf
->hw
.device_id
== I40E_DEV_ID_10G_BASE_T4
))
15871 pf
->hw_features
|= I40E_HW_PHY_CONTROLS_LEDS
;
15872 if (pf
->hw
.device_id
== I40E_DEV_ID_SFP_I_X722
)
15873 pf
->hw_features
|= I40E_HW_HAVE_CRT_RETIMER
;
15874 /* print a string summarizing features */
15875 i40e_print_features(pf
);
15879 /* Unwind what we've done if something failed in the setup */
15881 set_bit(__I40E_DOWN
, pf
->state
);
15882 i40e_clear_interrupt_scheme(pf
);
15885 i40e_reset_interrupt_capability(pf
);
15886 del_timer_sync(&pf
->service_timer
);
15888 err_configure_lan_hmc
:
15889 (void)i40e_shutdown_lan_hmc(hw
);
15891 kfree(pf
->qp_pile
);
15895 iounmap(hw
->hw_addr
);
15899 pci_disable_pcie_error_reporting(pdev
);
15900 pci_release_mem_regions(pdev
);
15903 pci_disable_device(pdev
);
15908 * i40e_remove - Device removal routine
15909 * @pdev: PCI device information struct
15911 * i40e_remove is called by the PCI subsystem to alert the driver
15912 * that is should release a PCI device. This could be caused by a
15913 * Hot-Plug event, or because the driver is going to be removed from
15916 static void i40e_remove(struct pci_dev
*pdev
)
15918 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
15919 struct i40e_hw
*hw
= &pf
->hw
;
15920 i40e_status ret_code
;
15923 i40e_dbg_pf_exit(pf
);
15927 /* Disable RSS in hw */
15928 i40e_write_rx_ctl(hw
, I40E_PFQF_HENA(0), 0);
15929 i40e_write_rx_ctl(hw
, I40E_PFQF_HENA(1), 0);
15931 while (test_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
))
15932 usleep_range(1000, 2000);
15934 if (pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) {
15935 set_bit(__I40E_VF_RESETS_DISABLED
, pf
->state
);
15937 pf
->flags
&= ~I40E_FLAG_SRIOV_ENABLED
;
15939 /* no more scheduling of any task */
15940 set_bit(__I40E_SUSPENDED
, pf
->state
);
15941 set_bit(__I40E_DOWN
, pf
->state
);
15942 if (pf
->service_timer
.function
)
15943 del_timer_sync(&pf
->service_timer
);
15944 if (pf
->service_task
.func
)
15945 cancel_work_sync(&pf
->service_task
);
15947 if (test_bit(__I40E_RECOVERY_MODE
, pf
->state
)) {
15948 struct i40e_vsi
*vsi
= pf
->vsi
[0];
15950 /* We know that we have allocated only one vsi for this PF,
15951 * it was just for registering netdevice, so the interface
15952 * could be visible in the 'ifconfig' output
15954 unregister_netdev(vsi
->netdev
);
15955 free_netdev(vsi
->netdev
);
15960 /* Client close must be called explicitly here because the timer
15961 * has been stopped.
15963 i40e_notify_client_of_netdev_close(pf
->vsi
[pf
->lan_vsi
], false);
15965 i40e_fdir_teardown(pf
);
15967 /* If there is a switch structure or any orphans, remove them.
15968 * This will leave only the PF's VSI remaining.
15970 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
15974 if (pf
->veb
[i
]->uplink_seid
== pf
->mac_seid
||
15975 pf
->veb
[i
]->uplink_seid
== 0)
15976 i40e_switch_branch_release(pf
->veb
[i
]);
15979 /* Now we can shutdown the PF's VSI, just before we kill
15982 if (pf
->vsi
[pf
->lan_vsi
])
15983 i40e_vsi_release(pf
->vsi
[pf
->lan_vsi
]);
15985 i40e_cloud_filter_exit(pf
);
15987 /* remove attached clients */
15988 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
) {
15989 ret_code
= i40e_lan_del_device(pf
);
15991 dev_warn(&pdev
->dev
, "Failed to delete client device: %d\n",
15995 /* shutdown and destroy the HMC */
15996 if (hw
->hmc
.hmc_obj
) {
15997 ret_code
= i40e_shutdown_lan_hmc(hw
);
15999 dev_warn(&pdev
->dev
,
16000 "Failed to destroy the HMC resources: %d\n",
16005 /* Free MSI/legacy interrupt 0 when in recovery mode. */
16006 if (test_bit(__I40E_RECOVERY_MODE
, pf
->state
) &&
16007 !(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
16008 free_irq(pf
->pdev
->irq
, pf
);
16010 /* shutdown the adminq */
16011 i40e_shutdown_adminq(hw
);
16013 /* destroy the locks only once, here */
16014 mutex_destroy(&hw
->aq
.arq_mutex
);
16015 mutex_destroy(&hw
->aq
.asq_mutex
);
16017 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
16019 i40e_clear_interrupt_scheme(pf
);
16020 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
16022 if (!test_bit(__I40E_RECOVERY_MODE
, pf
->state
))
16023 i40e_vsi_clear_rings(pf
->vsi
[i
]);
16024 i40e_vsi_clear(pf
->vsi
[i
]);
16030 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
16035 kfree(pf
->qp_pile
);
16038 iounmap(hw
->hw_addr
);
16040 pci_release_mem_regions(pdev
);
16042 pci_disable_pcie_error_reporting(pdev
);
16043 pci_disable_device(pdev
);
16047 * i40e_pci_error_detected - warning that something funky happened in PCI land
16048 * @pdev: PCI device information struct
16049 * @error: the type of PCI error
16051 * Called to warn that something happened and the error handling steps
16052 * are in progress. Allows the driver to quiesce things, be ready for
16055 static pci_ers_result_t
i40e_pci_error_detected(struct pci_dev
*pdev
,
16056 pci_channel_state_t error
)
16058 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
16060 dev_info(&pdev
->dev
, "%s: error %d\n", __func__
, error
);
16063 dev_info(&pdev
->dev
,
16064 "Cannot recover - error happened during device probe\n");
16065 return PCI_ERS_RESULT_DISCONNECT
;
16068 /* shutdown all operations */
16069 if (!test_bit(__I40E_SUSPENDED
, pf
->state
))
16070 i40e_prep_for_reset(pf
);
16072 /* Request a slot reset */
16073 return PCI_ERS_RESULT_NEED_RESET
;
16077 * i40e_pci_error_slot_reset - a PCI slot reset just happened
16078 * @pdev: PCI device information struct
16080 * Called to find if the driver can work with the device now that
16081 * the pci slot has been reset. If a basic connection seems good
16082 * (registers are readable and have sane content) then return a
16083 * happy little PCI_ERS_RESULT_xxx.
16085 static pci_ers_result_t
i40e_pci_error_slot_reset(struct pci_dev
*pdev
)
16087 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
16088 pci_ers_result_t result
;
16091 dev_dbg(&pdev
->dev
, "%s\n", __func__
);
16092 if (pci_enable_device_mem(pdev
)) {
16093 dev_info(&pdev
->dev
,
16094 "Cannot re-enable PCI device after reset.\n");
16095 result
= PCI_ERS_RESULT_DISCONNECT
;
16097 pci_set_master(pdev
);
16098 pci_restore_state(pdev
);
16099 pci_save_state(pdev
);
16100 pci_wake_from_d3(pdev
, false);
16102 reg
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
16104 result
= PCI_ERS_RESULT_RECOVERED
;
16106 result
= PCI_ERS_RESULT_DISCONNECT
;
16113 * i40e_pci_error_reset_prepare - prepare device driver for pci reset
16114 * @pdev: PCI device information struct
16116 static void i40e_pci_error_reset_prepare(struct pci_dev
*pdev
)
16118 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
16120 i40e_prep_for_reset(pf
);
16124 * i40e_pci_error_reset_done - pci reset done, device driver reset can begin
16125 * @pdev: PCI device information struct
16127 static void i40e_pci_error_reset_done(struct pci_dev
*pdev
)
16129 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
16131 i40e_reset_and_rebuild(pf
, false, false);
16135 * i40e_pci_error_resume - restart operations after PCI error recovery
16136 * @pdev: PCI device information struct
16138 * Called to allow the driver to bring things back up after PCI error
16139 * and/or reset recovery has finished.
16141 static void i40e_pci_error_resume(struct pci_dev
*pdev
)
16143 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
16145 dev_dbg(&pdev
->dev
, "%s\n", __func__
);
16146 if (test_bit(__I40E_SUSPENDED
, pf
->state
))
16149 i40e_handle_reset_warning(pf
, false);
16153 * i40e_enable_mc_magic_wake - enable multicast magic packet wake up
16154 * using the mac_address_write admin q function
16155 * @pf: pointer to i40e_pf struct
16157 static void i40e_enable_mc_magic_wake(struct i40e_pf
*pf
)
16159 struct i40e_hw
*hw
= &pf
->hw
;
16164 /* Get current MAC address in case it's an LAA */
16165 if (pf
->vsi
[pf
->lan_vsi
] && pf
->vsi
[pf
->lan_vsi
]->netdev
) {
16166 ether_addr_copy(mac_addr
,
16167 pf
->vsi
[pf
->lan_vsi
]->netdev
->dev_addr
);
16169 dev_err(&pf
->pdev
->dev
,
16170 "Failed to retrieve MAC address; using default\n");
16171 ether_addr_copy(mac_addr
, hw
->mac
.addr
);
16174 /* The FW expects the mac address write cmd to first be called with
16175 * one of these flags before calling it again with the multicast
16178 flags
= I40E_AQC_WRITE_TYPE_LAA_WOL
;
16180 if (hw
->func_caps
.flex10_enable
&& hw
->partition_id
!= 1)
16181 flags
= I40E_AQC_WRITE_TYPE_LAA_ONLY
;
16183 ret
= i40e_aq_mac_address_write(hw
, flags
, mac_addr
, NULL
);
16185 dev_err(&pf
->pdev
->dev
,
16186 "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up");
16190 flags
= I40E_AQC_MC_MAG_EN
16191 | I40E_AQC_WOL_PRESERVE_ON_PFR
16192 | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG
;
16193 ret
= i40e_aq_mac_address_write(hw
, flags
, mac_addr
, NULL
);
16195 dev_err(&pf
->pdev
->dev
,
16196 "Failed to enable Multicast Magic Packet wake up\n");
16200 * i40e_shutdown - PCI callback for shutting down
16201 * @pdev: PCI device information struct
16203 static void i40e_shutdown(struct pci_dev
*pdev
)
16205 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
16206 struct i40e_hw
*hw
= &pf
->hw
;
16208 set_bit(__I40E_SUSPENDED
, pf
->state
);
16209 set_bit(__I40E_DOWN
, pf
->state
);
16211 del_timer_sync(&pf
->service_timer
);
16212 cancel_work_sync(&pf
->service_task
);
16213 i40e_cloud_filter_exit(pf
);
16214 i40e_fdir_teardown(pf
);
16216 /* Client close must be called explicitly here because the timer
16217 * has been stopped.
16219 i40e_notify_client_of_netdev_close(pf
->vsi
[pf
->lan_vsi
], false);
16221 if (pf
->wol_en
&& (pf
->hw_features
& I40E_HW_WOL_MC_MAGIC_PKT_WAKE
))
16222 i40e_enable_mc_magic_wake(pf
);
16224 i40e_prep_for_reset(pf
);
16226 wr32(hw
, I40E_PFPM_APM
,
16227 (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
16228 wr32(hw
, I40E_PFPM_WUFC
,
16229 (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
16231 /* Free MSI/legacy interrupt 0 when in recovery mode. */
16232 if (test_bit(__I40E_RECOVERY_MODE
, pf
->state
) &&
16233 !(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
16234 free_irq(pf
->pdev
->irq
, pf
);
16236 /* Since we're going to destroy queues during the
16237 * i40e_clear_interrupt_scheme() we should hold the RTNL lock for this
16241 i40e_clear_interrupt_scheme(pf
);
16244 if (system_state
== SYSTEM_POWER_OFF
) {
16245 pci_wake_from_d3(pdev
, pf
->wol_en
);
16246 pci_set_power_state(pdev
, PCI_D3hot
);
16251 * i40e_suspend - PM callback for moving to D3
16252 * @dev: generic device information structure
16254 static int __maybe_unused
i40e_suspend(struct device
*dev
)
16256 struct i40e_pf
*pf
= dev_get_drvdata(dev
);
16257 struct i40e_hw
*hw
= &pf
->hw
;
16259 /* If we're already suspended, then there is nothing to do */
16260 if (test_and_set_bit(__I40E_SUSPENDED
, pf
->state
))
16263 set_bit(__I40E_DOWN
, pf
->state
);
16265 /* Ensure service task will not be running */
16266 del_timer_sync(&pf
->service_timer
);
16267 cancel_work_sync(&pf
->service_task
);
16269 /* Client close must be called explicitly here because the timer
16270 * has been stopped.
16272 i40e_notify_client_of_netdev_close(pf
->vsi
[pf
->lan_vsi
], false);
16274 if (pf
->wol_en
&& (pf
->hw_features
& I40E_HW_WOL_MC_MAGIC_PKT_WAKE
))
16275 i40e_enable_mc_magic_wake(pf
);
16277 /* Since we're going to destroy queues during the
16278 * i40e_clear_interrupt_scheme() we should hold the RTNL lock for this
16283 i40e_prep_for_reset(pf
);
16285 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
16286 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
16288 /* Clear the interrupt scheme and release our IRQs so that the system
16289 * can safely hibernate even when there are a large number of CPUs.
16290 * Otherwise hibernation might fail when mapping all the vectors back
16293 i40e_clear_interrupt_scheme(pf
);
16301 * i40e_resume - PM callback for waking up from D3
16302 * @dev: generic device information structure
16304 static int __maybe_unused
i40e_resume(struct device
*dev
)
16306 struct i40e_pf
*pf
= dev_get_drvdata(dev
);
16309 /* If we're not suspended, then there is nothing to do */
16310 if (!test_bit(__I40E_SUSPENDED
, pf
->state
))
16313 /* We need to hold the RTNL lock prior to restoring interrupt schemes,
16314 * since we're going to be restoring queues
16318 /* We cleared the interrupt scheme when we suspended, so we need to
16319 * restore it now to resume device functionality.
16321 err
= i40e_restore_interrupt_scheme(pf
);
16323 dev_err(dev
, "Cannot restore interrupt scheme: %d\n",
16327 clear_bit(__I40E_DOWN
, pf
->state
);
16328 i40e_reset_and_rebuild(pf
, false, true);
16332 /* Clear suspended state last after everything is recovered */
16333 clear_bit(__I40E_SUSPENDED
, pf
->state
);
16335 /* Restart the service task */
16336 mod_timer(&pf
->service_timer
,
16337 round_jiffies(jiffies
+ pf
->service_timer_period
));
16342 static const struct pci_error_handlers i40e_err_handler
= {
16343 .error_detected
= i40e_pci_error_detected
,
16344 .slot_reset
= i40e_pci_error_slot_reset
,
16345 .reset_prepare
= i40e_pci_error_reset_prepare
,
16346 .reset_done
= i40e_pci_error_reset_done
,
16347 .resume
= i40e_pci_error_resume
,
16350 static SIMPLE_DEV_PM_OPS(i40e_pm_ops
, i40e_suspend
, i40e_resume
);
16352 static struct pci_driver i40e_driver
= {
16353 .name
= i40e_driver_name
,
16354 .id_table
= i40e_pci_tbl
,
16355 .probe
= i40e_probe
,
16356 .remove
= i40e_remove
,
16358 .pm
= &i40e_pm_ops
,
16360 .shutdown
= i40e_shutdown
,
16361 .err_handler
= &i40e_err_handler
,
16362 .sriov_configure
= i40e_pci_sriov_configure
,
16366 * i40e_init_module - Driver registration routine
16368 * i40e_init_module is the first routine called when the driver is
16369 * loaded. All it does is register with the PCI subsystem.
16371 static int __init
i40e_init_module(void)
16373 pr_info("%s: %s\n", i40e_driver_name
, i40e_driver_string
);
16374 pr_info("%s: %s\n", i40e_driver_name
, i40e_copyright
);
16376 /* There is no need to throttle the number of active tasks because
16377 * each device limits its own task using a state bit for scheduling
16378 * the service task, and the device tasks do not interfere with each
16379 * other, so we don't set a max task limit. We must set WQ_MEM_RECLAIM
16380 * since we need to be able to guarantee forward progress even under
16383 i40e_wq
= alloc_workqueue("%s", WQ_MEM_RECLAIM
, 0, i40e_driver_name
);
16385 pr_err("%s: Failed to create workqueue\n", i40e_driver_name
);
16390 return pci_register_driver(&i40e_driver
);
16392 module_init(i40e_init_module
);
16395 * i40e_exit_module - Driver exit cleanup routine
16397 * i40e_exit_module is called just before the driver is removed
16400 static void __exit
i40e_exit_module(void)
16402 pci_unregister_driver(&i40e_driver
);
16403 destroy_workqueue(i40e_wq
);
16404 ida_destroy(&i40e_client_ida
);
16407 module_exit(i40e_exit_module
);