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>
12 #include "i40e_diag.h"
14 #include <net/udp_tunnel.h>
15 #include <net/xdp_sock_drv.h>
16 /* All i40e tracepoints are defined by the include below, which
17 * must be included exactly once across the whole kernel with
18 * CREATE_TRACE_POINTS defined
20 #define CREATE_TRACE_POINTS
21 #include "i40e_trace.h"
23 const char i40e_driver_name[] = "i40e";
24 static const char i40e_driver_string[] =
25 "Intel(R) Ethernet Connection XL710 Network Driver";
27 static const char i40e_copyright[] = "Copyright (c) 2013 - 2019 Intel Corporation.";
29 /* a bit of forward declarations */
30 static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
31 static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired);
32 static int i40e_add_vsi(struct i40e_vsi *vsi);
33 static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
34 static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
35 static int i40e_setup_misc_vector(struct i40e_pf *pf);
36 static void i40e_determine_queue_usage(struct i40e_pf *pf);
37 static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
38 static void i40e_prep_for_reset(struct i40e_pf *pf);
39 static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit,
41 static int i40e_reset(struct i40e_pf *pf);
42 static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired);
43 static int i40e_setup_misc_vector_for_recovery_mode(struct i40e_pf *pf);
44 static int i40e_restore_interrupt_scheme(struct i40e_pf *pf);
45 static bool i40e_check_recovery_mode(struct i40e_pf *pf);
46 static int i40e_init_recovery_mode(struct i40e_pf *pf, struct i40e_hw *hw);
47 static void i40e_fdir_sb_setup(struct i40e_pf *pf);
48 static int i40e_veb_get_bw_info(struct i40e_veb *veb);
49 static int i40e_get_capabilities(struct i40e_pf *pf,
50 enum i40e_admin_queue_opc list_type);
51 static bool i40e_is_total_port_shutdown_enabled(struct i40e_pf *pf);
53 /* i40e_pci_tbl - PCI Device ID Table
55 * Last entry must be all 0s
57 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
58 * Class, Class Mask, private data (not used) }
60 static const struct pci_device_id i40e_pci_tbl[] = {
61 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
62 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
63 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
64 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
65 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
66 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
67 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
68 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0},
69 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0},
70 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_BC), 0},
71 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_SFP), 0},
72 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_B), 0},
73 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0},
74 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0},
75 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0},
76 {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0},
77 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0},
78 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0},
79 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
80 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0},
81 {PCI_VDEVICE(INTEL, I40E_DEV_ID_X710_N3000), 0},
82 {PCI_VDEVICE(INTEL, I40E_DEV_ID_XXV710_N3000), 0},
83 {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_B), 0},
84 {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_SFP28), 0},
85 /* required last entry */
88 MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
90 #define I40E_MAX_VF_COUNT 128
91 static int debug = -1;
92 module_param(debug, uint, 0);
93 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXX)");
95 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
96 MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
97 MODULE_LICENSE("GPL v2");
99 static struct workqueue_struct *i40e_wq;
102 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
103 * @hw: pointer to the HW structure
104 * @mem: ptr to mem struct to fill out
105 * @size: size of memory requested
106 * @alignment: what to align the allocation to
108 int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
109 u64 size, u32 alignment)
111 struct i40e_pf *pf = (struct i40e_pf *)hw->back;
113 mem->size = ALIGN(size, alignment);
114 mem->va = dma_alloc_coherent(&pf->pdev->dev, mem->size, &mem->pa,
123 * i40e_free_dma_mem_d - OS specific memory free for shared code
124 * @hw: pointer to the HW structure
125 * @mem: ptr to mem struct to free
127 int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
129 struct i40e_pf *pf = (struct i40e_pf *)hw->back;
131 dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
140 * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
141 * @hw: pointer to the HW structure
142 * @mem: ptr to mem struct to fill out
143 * @size: size of memory requested
145 int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
149 mem->va = kzalloc(size, GFP_KERNEL);
158 * i40e_free_virt_mem_d - OS specific memory free for shared code
159 * @hw: pointer to the HW structure
160 * @mem: ptr to mem struct to free
162 int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
164 /* it's ok to kfree a NULL pointer */
173 * i40e_get_lump - find a lump of free generic resource
174 * @pf: board private structure
175 * @pile: the pile of resource to search
176 * @needed: the number of items needed
177 * @id: an owner id to stick on the items assigned
179 * Returns the base item index of the lump, or negative for error
181 * The search_hint trick and lack of advanced fit-finding only work
182 * because we're highly likely to have all the same size lump requests.
183 * Linear search time and any fragmentation should be minimal.
185 static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
191 if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
192 dev_info(&pf->pdev->dev,
193 "param err: pile=%s needed=%d id=0x%04x\n",
194 pile ? "<valid>" : "<null>", needed, id);
198 /* start the linear search with an imperfect hint */
199 i = pile->search_hint;
200 while (i < pile->num_entries) {
201 /* skip already allocated entries */
202 if (pile->list[i] & I40E_PILE_VALID_BIT) {
207 /* do we have enough in this lump? */
208 for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
209 if (pile->list[i+j] & I40E_PILE_VALID_BIT)
214 /* there was enough, so assign it to the requestor */
215 for (j = 0; j < needed; j++)
216 pile->list[i+j] = id | I40E_PILE_VALID_BIT;
218 pile->search_hint = i + j;
222 /* not enough, so skip over it and continue looking */
230 * i40e_put_lump - return a lump of generic resource
231 * @pile: the pile of resource to search
232 * @index: the base item index
233 * @id: the owner id of the items assigned
235 * Returns the count of items in the lump
237 static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
239 int valid_id = (id | I40E_PILE_VALID_BIT);
243 if (!pile || index >= pile->num_entries)
247 i < pile->num_entries && pile->list[i] == valid_id;
253 if (count && index < pile->search_hint)
254 pile->search_hint = index;
260 * i40e_find_vsi_from_id - searches for the vsi with the given id
261 * @pf: the pf structure to search for the vsi
262 * @id: id of the vsi it is searching for
264 struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id)
268 for (i = 0; i < pf->num_alloc_vsi; i++)
269 if (pf->vsi[i] && (pf->vsi[i]->id == id))
276 * i40e_service_event_schedule - Schedule the service task to wake up
277 * @pf: board private structure
279 * If not already scheduled, this puts the task into the work queue
281 void i40e_service_event_schedule(struct i40e_pf *pf)
283 if ((!test_bit(__I40E_DOWN, pf->state) &&
284 !test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) ||
285 test_bit(__I40E_RECOVERY_MODE, pf->state))
286 queue_work(i40e_wq, &pf->service_task);
290 * i40e_tx_timeout - Respond to a Tx Hang
291 * @netdev: network interface device structure
292 * @txqueue: queue number timing out
294 * If any port has noticed a Tx timeout, it is likely that the whole
295 * device is munged, not just the one netdev port, so go for the full
298 static void i40e_tx_timeout(struct net_device *netdev, unsigned int txqueue)
300 struct i40e_netdev_priv *np = netdev_priv(netdev);
301 struct i40e_vsi *vsi = np->vsi;
302 struct i40e_pf *pf = vsi->back;
303 struct i40e_ring *tx_ring = NULL;
307 pf->tx_timeout_count++;
309 /* with txqueue index, find the tx_ring struct */
310 for (i = 0; i < vsi->num_queue_pairs; i++) {
311 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
313 vsi->tx_rings[i]->queue_index) {
314 tx_ring = vsi->tx_rings[i];
320 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
321 pf->tx_timeout_recovery_level = 1; /* reset after some time */
322 else if (time_before(jiffies,
323 (pf->tx_timeout_last_recovery + netdev->watchdog_timeo)))
324 return; /* don't do any new action before the next timeout */
326 /* don't kick off another recovery if one is already pending */
327 if (test_and_set_bit(__I40E_TIMEOUT_RECOVERY_PENDING, pf->state))
331 head = i40e_get_head(tx_ring);
332 /* Read interrupt register */
333 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
335 I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
336 tx_ring->vsi->base_vector - 1));
338 val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
340 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",
341 vsi->seid, txqueue, tx_ring->next_to_clean,
342 head, tx_ring->next_to_use,
343 readl(tx_ring->tail), val);
346 pf->tx_timeout_last_recovery = jiffies;
347 netdev_info(netdev, "tx_timeout recovery level %d, txqueue %d\n",
348 pf->tx_timeout_recovery_level, txqueue);
350 switch (pf->tx_timeout_recovery_level) {
352 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
355 set_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
358 set_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state);
361 netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
365 i40e_service_event_schedule(pf);
366 pf->tx_timeout_recovery_level++;
370 * i40e_get_vsi_stats_struct - Get System Network Statistics
371 * @vsi: the VSI we care about
373 * Returns the address of the device statistics structure.
374 * The statistics are actually updated from the service task.
376 struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
378 return &vsi->net_stats;
382 * i40e_get_netdev_stats_struct_tx - populate stats from a Tx ring
383 * @ring: Tx ring to get statistics from
384 * @stats: statistics entry to be updated
386 static void i40e_get_netdev_stats_struct_tx(struct i40e_ring *ring,
387 struct rtnl_link_stats64 *stats)
393 start = u64_stats_fetch_begin_irq(&ring->syncp);
394 packets = ring->stats.packets;
395 bytes = ring->stats.bytes;
396 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
398 stats->tx_packets += packets;
399 stats->tx_bytes += bytes;
403 * i40e_get_netdev_stats_struct - Get statistics for netdev interface
404 * @netdev: network interface device structure
405 * @stats: data structure to store statistics
407 * Returns the address of the device statistics structure.
408 * The statistics are actually updated from the service task.
410 static void i40e_get_netdev_stats_struct(struct net_device *netdev,
411 struct rtnl_link_stats64 *stats)
413 struct i40e_netdev_priv *np = netdev_priv(netdev);
414 struct i40e_vsi *vsi = np->vsi;
415 struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
416 struct i40e_ring *ring;
419 if (test_bit(__I40E_VSI_DOWN, vsi->state))
426 for (i = 0; i < vsi->num_queue_pairs; i++) {
430 ring = READ_ONCE(vsi->tx_rings[i]);
433 i40e_get_netdev_stats_struct_tx(ring, stats);
435 if (i40e_enabled_xdp_vsi(vsi)) {
436 ring = READ_ONCE(vsi->xdp_rings[i]);
439 i40e_get_netdev_stats_struct_tx(ring, stats);
442 ring = READ_ONCE(vsi->rx_rings[i]);
446 start = u64_stats_fetch_begin_irq(&ring->syncp);
447 packets = ring->stats.packets;
448 bytes = ring->stats.bytes;
449 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
451 stats->rx_packets += packets;
452 stats->rx_bytes += bytes;
457 /* following stats updated by i40e_watchdog_subtask() */
458 stats->multicast = vsi_stats->multicast;
459 stats->tx_errors = vsi_stats->tx_errors;
460 stats->tx_dropped = vsi_stats->tx_dropped;
461 stats->rx_errors = vsi_stats->rx_errors;
462 stats->rx_dropped = vsi_stats->rx_dropped;
463 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
464 stats->rx_length_errors = vsi_stats->rx_length_errors;
468 * i40e_vsi_reset_stats - Resets all stats of the given vsi
469 * @vsi: the VSI to have its stats reset
471 void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
473 struct rtnl_link_stats64 *ns;
479 ns = i40e_get_vsi_stats_struct(vsi);
480 memset(ns, 0, sizeof(*ns));
481 memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
482 memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
483 memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
484 if (vsi->rx_rings && vsi->rx_rings[0]) {
485 for (i = 0; i < vsi->num_queue_pairs; i++) {
486 memset(&vsi->rx_rings[i]->stats, 0,
487 sizeof(vsi->rx_rings[i]->stats));
488 memset(&vsi->rx_rings[i]->rx_stats, 0,
489 sizeof(vsi->rx_rings[i]->rx_stats));
490 memset(&vsi->tx_rings[i]->stats, 0,
491 sizeof(vsi->tx_rings[i]->stats));
492 memset(&vsi->tx_rings[i]->tx_stats, 0,
493 sizeof(vsi->tx_rings[i]->tx_stats));
496 vsi->stat_offsets_loaded = false;
500 * i40e_pf_reset_stats - Reset all of the stats for the given PF
501 * @pf: the PF to be reset
503 void i40e_pf_reset_stats(struct i40e_pf *pf)
507 memset(&pf->stats, 0, sizeof(pf->stats));
508 memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
509 pf->stat_offsets_loaded = false;
511 for (i = 0; i < I40E_MAX_VEB; i++) {
513 memset(&pf->veb[i]->stats, 0,
514 sizeof(pf->veb[i]->stats));
515 memset(&pf->veb[i]->stats_offsets, 0,
516 sizeof(pf->veb[i]->stats_offsets));
517 memset(&pf->veb[i]->tc_stats, 0,
518 sizeof(pf->veb[i]->tc_stats));
519 memset(&pf->veb[i]->tc_stats_offsets, 0,
520 sizeof(pf->veb[i]->tc_stats_offsets));
521 pf->veb[i]->stat_offsets_loaded = false;
524 pf->hw_csum_rx_error = 0;
528 * i40e_stat_update48 - read and update a 48 bit stat from the chip
529 * @hw: ptr to the hardware info
530 * @hireg: the high 32 bit reg to read
531 * @loreg: the low 32 bit reg to read
532 * @offset_loaded: has the initial offset been loaded yet
533 * @offset: ptr to current offset value
534 * @stat: ptr to the stat
536 * Since the device stats are not reset at PFReset, they likely will not
537 * be zeroed when the driver starts. We'll save the first values read
538 * and use them as offsets to be subtracted from the raw values in order
539 * to report stats that count from zero. In the process, we also manage
540 * the potential roll-over.
542 static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
543 bool offset_loaded, u64 *offset, u64 *stat)
547 if (hw->device_id == I40E_DEV_ID_QEMU) {
548 new_data = rd32(hw, loreg);
549 new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
551 new_data = rd64(hw, loreg);
555 if (likely(new_data >= *offset))
556 *stat = new_data - *offset;
558 *stat = (new_data + BIT_ULL(48)) - *offset;
559 *stat &= 0xFFFFFFFFFFFFULL;
563 * i40e_stat_update32 - read and update a 32 bit stat from the chip
564 * @hw: ptr to the hardware info
565 * @reg: the hw reg to read
566 * @offset_loaded: has the initial offset been loaded yet
567 * @offset: ptr to current offset value
568 * @stat: ptr to the stat
570 static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
571 bool offset_loaded, u64 *offset, u64 *stat)
575 new_data = rd32(hw, reg);
578 if (likely(new_data >= *offset))
579 *stat = (u32)(new_data - *offset);
581 *stat = (u32)((new_data + BIT_ULL(32)) - *offset);
585 * i40e_stat_update_and_clear32 - read and clear hw reg, update a 32 bit stat
586 * @hw: ptr to the hardware info
587 * @reg: the hw reg to read and clear
588 * @stat: ptr to the stat
590 static void i40e_stat_update_and_clear32(struct i40e_hw *hw, u32 reg, u64 *stat)
592 u32 new_data = rd32(hw, reg);
594 wr32(hw, reg, 1); /* must write a nonzero value to clear register */
599 * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
600 * @vsi: the VSI to be updated
602 void i40e_update_eth_stats(struct i40e_vsi *vsi)
604 int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
605 struct i40e_pf *pf = vsi->back;
606 struct i40e_hw *hw = &pf->hw;
607 struct i40e_eth_stats *oes;
608 struct i40e_eth_stats *es; /* device's eth stats */
610 es = &vsi->eth_stats;
611 oes = &vsi->eth_stats_offsets;
613 /* Gather up the stats that the hw collects */
614 i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
615 vsi->stat_offsets_loaded,
616 &oes->tx_errors, &es->tx_errors);
617 i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
618 vsi->stat_offsets_loaded,
619 &oes->rx_discards, &es->rx_discards);
620 i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
621 vsi->stat_offsets_loaded,
622 &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
624 i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
625 I40E_GLV_GORCL(stat_idx),
626 vsi->stat_offsets_loaded,
627 &oes->rx_bytes, &es->rx_bytes);
628 i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
629 I40E_GLV_UPRCL(stat_idx),
630 vsi->stat_offsets_loaded,
631 &oes->rx_unicast, &es->rx_unicast);
632 i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
633 I40E_GLV_MPRCL(stat_idx),
634 vsi->stat_offsets_loaded,
635 &oes->rx_multicast, &es->rx_multicast);
636 i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
637 I40E_GLV_BPRCL(stat_idx),
638 vsi->stat_offsets_loaded,
639 &oes->rx_broadcast, &es->rx_broadcast);
641 i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
642 I40E_GLV_GOTCL(stat_idx),
643 vsi->stat_offsets_loaded,
644 &oes->tx_bytes, &es->tx_bytes);
645 i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
646 I40E_GLV_UPTCL(stat_idx),
647 vsi->stat_offsets_loaded,
648 &oes->tx_unicast, &es->tx_unicast);
649 i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
650 I40E_GLV_MPTCL(stat_idx),
651 vsi->stat_offsets_loaded,
652 &oes->tx_multicast, &es->tx_multicast);
653 i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
654 I40E_GLV_BPTCL(stat_idx),
655 vsi->stat_offsets_loaded,
656 &oes->tx_broadcast, &es->tx_broadcast);
657 vsi->stat_offsets_loaded = true;
661 * i40e_update_veb_stats - Update Switch component statistics
662 * @veb: the VEB being updated
664 void i40e_update_veb_stats(struct i40e_veb *veb)
666 struct i40e_pf *pf = veb->pf;
667 struct i40e_hw *hw = &pf->hw;
668 struct i40e_eth_stats *oes;
669 struct i40e_eth_stats *es; /* device's eth stats */
670 struct i40e_veb_tc_stats *veb_oes;
671 struct i40e_veb_tc_stats *veb_es;
674 idx = veb->stats_idx;
676 oes = &veb->stats_offsets;
677 veb_es = &veb->tc_stats;
678 veb_oes = &veb->tc_stats_offsets;
680 /* Gather up the stats that the hw collects */
681 i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
682 veb->stat_offsets_loaded,
683 &oes->tx_discards, &es->tx_discards);
684 if (hw->revision_id > 0)
685 i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
686 veb->stat_offsets_loaded,
687 &oes->rx_unknown_protocol,
688 &es->rx_unknown_protocol);
689 i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
690 veb->stat_offsets_loaded,
691 &oes->rx_bytes, &es->rx_bytes);
692 i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
693 veb->stat_offsets_loaded,
694 &oes->rx_unicast, &es->rx_unicast);
695 i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
696 veb->stat_offsets_loaded,
697 &oes->rx_multicast, &es->rx_multicast);
698 i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
699 veb->stat_offsets_loaded,
700 &oes->rx_broadcast, &es->rx_broadcast);
702 i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
703 veb->stat_offsets_loaded,
704 &oes->tx_bytes, &es->tx_bytes);
705 i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
706 veb->stat_offsets_loaded,
707 &oes->tx_unicast, &es->tx_unicast);
708 i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
709 veb->stat_offsets_loaded,
710 &oes->tx_multicast, &es->tx_multicast);
711 i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
712 veb->stat_offsets_loaded,
713 &oes->tx_broadcast, &es->tx_broadcast);
714 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
715 i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx),
716 I40E_GLVEBTC_RPCL(i, idx),
717 veb->stat_offsets_loaded,
718 &veb_oes->tc_rx_packets[i],
719 &veb_es->tc_rx_packets[i]);
720 i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx),
721 I40E_GLVEBTC_RBCL(i, idx),
722 veb->stat_offsets_loaded,
723 &veb_oes->tc_rx_bytes[i],
724 &veb_es->tc_rx_bytes[i]);
725 i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx),
726 I40E_GLVEBTC_TPCL(i, idx),
727 veb->stat_offsets_loaded,
728 &veb_oes->tc_tx_packets[i],
729 &veb_es->tc_tx_packets[i]);
730 i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx),
731 I40E_GLVEBTC_TBCL(i, idx),
732 veb->stat_offsets_loaded,
733 &veb_oes->tc_tx_bytes[i],
734 &veb_es->tc_tx_bytes[i]);
736 veb->stat_offsets_loaded = true;
740 * i40e_update_vsi_stats - Update the vsi statistics counters.
741 * @vsi: the VSI to be updated
743 * There are a few instances where we store the same stat in a
744 * couple of different structs. This is partly because we have
745 * the netdev stats that need to be filled out, which is slightly
746 * different from the "eth_stats" defined by the chip and used in
747 * VF communications. We sort it out here.
749 static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
751 struct i40e_pf *pf = vsi->back;
752 struct rtnl_link_stats64 *ons;
753 struct rtnl_link_stats64 *ns; /* netdev stats */
754 struct i40e_eth_stats *oes;
755 struct i40e_eth_stats *es; /* device's eth stats */
756 u32 tx_restart, tx_busy;
767 if (test_bit(__I40E_VSI_DOWN, vsi->state) ||
768 test_bit(__I40E_CONFIG_BUSY, pf->state))
771 ns = i40e_get_vsi_stats_struct(vsi);
772 ons = &vsi->net_stats_offsets;
773 es = &vsi->eth_stats;
774 oes = &vsi->eth_stats_offsets;
776 /* Gather up the netdev and vsi stats that the driver collects
777 * on the fly during packet processing
781 tx_restart = tx_busy = tx_linearize = tx_force_wb = 0;
785 for (q = 0; q < vsi->num_queue_pairs; q++) {
787 p = READ_ONCE(vsi->tx_rings[q]);
792 start = u64_stats_fetch_begin_irq(&p->syncp);
793 packets = p->stats.packets;
794 bytes = p->stats.bytes;
795 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
798 tx_restart += p->tx_stats.restart_queue;
799 tx_busy += p->tx_stats.tx_busy;
800 tx_linearize += p->tx_stats.tx_linearize;
801 tx_force_wb += p->tx_stats.tx_force_wb;
804 p = READ_ONCE(vsi->rx_rings[q]);
809 start = u64_stats_fetch_begin_irq(&p->syncp);
810 packets = p->stats.packets;
811 bytes = p->stats.bytes;
812 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
815 rx_buf += p->rx_stats.alloc_buff_failed;
816 rx_page += p->rx_stats.alloc_page_failed;
818 if (i40e_enabled_xdp_vsi(vsi)) {
819 /* locate XDP ring */
820 p = READ_ONCE(vsi->xdp_rings[q]);
825 start = u64_stats_fetch_begin_irq(&p->syncp);
826 packets = p->stats.packets;
827 bytes = p->stats.bytes;
828 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
831 tx_restart += p->tx_stats.restart_queue;
832 tx_busy += p->tx_stats.tx_busy;
833 tx_linearize += p->tx_stats.tx_linearize;
834 tx_force_wb += p->tx_stats.tx_force_wb;
838 vsi->tx_restart = tx_restart;
839 vsi->tx_busy = tx_busy;
840 vsi->tx_linearize = tx_linearize;
841 vsi->tx_force_wb = tx_force_wb;
842 vsi->rx_page_failed = rx_page;
843 vsi->rx_buf_failed = rx_buf;
845 ns->rx_packets = rx_p;
847 ns->tx_packets = tx_p;
850 /* update netdev stats from eth stats */
851 i40e_update_eth_stats(vsi);
852 ons->tx_errors = oes->tx_errors;
853 ns->tx_errors = es->tx_errors;
854 ons->multicast = oes->rx_multicast;
855 ns->multicast = es->rx_multicast;
856 ons->rx_dropped = oes->rx_discards;
857 ns->rx_dropped = es->rx_discards;
858 ons->tx_dropped = oes->tx_discards;
859 ns->tx_dropped = es->tx_discards;
861 /* pull in a couple PF stats if this is the main vsi */
862 if (vsi == pf->vsi[pf->lan_vsi]) {
863 ns->rx_crc_errors = pf->stats.crc_errors;
864 ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
865 ns->rx_length_errors = pf->stats.rx_length_errors;
870 * i40e_update_pf_stats - Update the PF statistics counters.
871 * @pf: the PF to be updated
873 static void i40e_update_pf_stats(struct i40e_pf *pf)
875 struct i40e_hw_port_stats *osd = &pf->stats_offsets;
876 struct i40e_hw_port_stats *nsd = &pf->stats;
877 struct i40e_hw *hw = &pf->hw;
881 i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
882 I40E_GLPRT_GORCL(hw->port),
883 pf->stat_offsets_loaded,
884 &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
885 i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
886 I40E_GLPRT_GOTCL(hw->port),
887 pf->stat_offsets_loaded,
888 &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
889 i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
890 pf->stat_offsets_loaded,
891 &osd->eth.rx_discards,
892 &nsd->eth.rx_discards);
893 i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
894 I40E_GLPRT_UPRCL(hw->port),
895 pf->stat_offsets_loaded,
896 &osd->eth.rx_unicast,
897 &nsd->eth.rx_unicast);
898 i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
899 I40E_GLPRT_MPRCL(hw->port),
900 pf->stat_offsets_loaded,
901 &osd->eth.rx_multicast,
902 &nsd->eth.rx_multicast);
903 i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
904 I40E_GLPRT_BPRCL(hw->port),
905 pf->stat_offsets_loaded,
906 &osd->eth.rx_broadcast,
907 &nsd->eth.rx_broadcast);
908 i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
909 I40E_GLPRT_UPTCL(hw->port),
910 pf->stat_offsets_loaded,
911 &osd->eth.tx_unicast,
912 &nsd->eth.tx_unicast);
913 i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
914 I40E_GLPRT_MPTCL(hw->port),
915 pf->stat_offsets_loaded,
916 &osd->eth.tx_multicast,
917 &nsd->eth.tx_multicast);
918 i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
919 I40E_GLPRT_BPTCL(hw->port),
920 pf->stat_offsets_loaded,
921 &osd->eth.tx_broadcast,
922 &nsd->eth.tx_broadcast);
924 i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
925 pf->stat_offsets_loaded,
926 &osd->tx_dropped_link_down,
927 &nsd->tx_dropped_link_down);
929 i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
930 pf->stat_offsets_loaded,
931 &osd->crc_errors, &nsd->crc_errors);
933 i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
934 pf->stat_offsets_loaded,
935 &osd->illegal_bytes, &nsd->illegal_bytes);
937 i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
938 pf->stat_offsets_loaded,
939 &osd->mac_local_faults,
940 &nsd->mac_local_faults);
941 i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
942 pf->stat_offsets_loaded,
943 &osd->mac_remote_faults,
944 &nsd->mac_remote_faults);
946 i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
947 pf->stat_offsets_loaded,
948 &osd->rx_length_errors,
949 &nsd->rx_length_errors);
951 i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
952 pf->stat_offsets_loaded,
953 &osd->link_xon_rx, &nsd->link_xon_rx);
954 i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
955 pf->stat_offsets_loaded,
956 &osd->link_xon_tx, &nsd->link_xon_tx);
957 i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
958 pf->stat_offsets_loaded,
959 &osd->link_xoff_rx, &nsd->link_xoff_rx);
960 i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
961 pf->stat_offsets_loaded,
962 &osd->link_xoff_tx, &nsd->link_xoff_tx);
964 for (i = 0; i < 8; i++) {
965 i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
966 pf->stat_offsets_loaded,
967 &osd->priority_xoff_rx[i],
968 &nsd->priority_xoff_rx[i]);
969 i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
970 pf->stat_offsets_loaded,
971 &osd->priority_xon_rx[i],
972 &nsd->priority_xon_rx[i]);
973 i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
974 pf->stat_offsets_loaded,
975 &osd->priority_xon_tx[i],
976 &nsd->priority_xon_tx[i]);
977 i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
978 pf->stat_offsets_loaded,
979 &osd->priority_xoff_tx[i],
980 &nsd->priority_xoff_tx[i]);
981 i40e_stat_update32(hw,
982 I40E_GLPRT_RXON2OFFCNT(hw->port, i),
983 pf->stat_offsets_loaded,
984 &osd->priority_xon_2_xoff[i],
985 &nsd->priority_xon_2_xoff[i]);
988 i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
989 I40E_GLPRT_PRC64L(hw->port),
990 pf->stat_offsets_loaded,
991 &osd->rx_size_64, &nsd->rx_size_64);
992 i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
993 I40E_GLPRT_PRC127L(hw->port),
994 pf->stat_offsets_loaded,
995 &osd->rx_size_127, &nsd->rx_size_127);
996 i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
997 I40E_GLPRT_PRC255L(hw->port),
998 pf->stat_offsets_loaded,
999 &osd->rx_size_255, &nsd->rx_size_255);
1000 i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
1001 I40E_GLPRT_PRC511L(hw->port),
1002 pf->stat_offsets_loaded,
1003 &osd->rx_size_511, &nsd->rx_size_511);
1004 i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
1005 I40E_GLPRT_PRC1023L(hw->port),
1006 pf->stat_offsets_loaded,
1007 &osd->rx_size_1023, &nsd->rx_size_1023);
1008 i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
1009 I40E_GLPRT_PRC1522L(hw->port),
1010 pf->stat_offsets_loaded,
1011 &osd->rx_size_1522, &nsd->rx_size_1522);
1012 i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
1013 I40E_GLPRT_PRC9522L(hw->port),
1014 pf->stat_offsets_loaded,
1015 &osd->rx_size_big, &nsd->rx_size_big);
1017 i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
1018 I40E_GLPRT_PTC64L(hw->port),
1019 pf->stat_offsets_loaded,
1020 &osd->tx_size_64, &nsd->tx_size_64);
1021 i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
1022 I40E_GLPRT_PTC127L(hw->port),
1023 pf->stat_offsets_loaded,
1024 &osd->tx_size_127, &nsd->tx_size_127);
1025 i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
1026 I40E_GLPRT_PTC255L(hw->port),
1027 pf->stat_offsets_loaded,
1028 &osd->tx_size_255, &nsd->tx_size_255);
1029 i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
1030 I40E_GLPRT_PTC511L(hw->port),
1031 pf->stat_offsets_loaded,
1032 &osd->tx_size_511, &nsd->tx_size_511);
1033 i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
1034 I40E_GLPRT_PTC1023L(hw->port),
1035 pf->stat_offsets_loaded,
1036 &osd->tx_size_1023, &nsd->tx_size_1023);
1037 i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
1038 I40E_GLPRT_PTC1522L(hw->port),
1039 pf->stat_offsets_loaded,
1040 &osd->tx_size_1522, &nsd->tx_size_1522);
1041 i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
1042 I40E_GLPRT_PTC9522L(hw->port),
1043 pf->stat_offsets_loaded,
1044 &osd->tx_size_big, &nsd->tx_size_big);
1046 i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
1047 pf->stat_offsets_loaded,
1048 &osd->rx_undersize, &nsd->rx_undersize);
1049 i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
1050 pf->stat_offsets_loaded,
1051 &osd->rx_fragments, &nsd->rx_fragments);
1052 i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
1053 pf->stat_offsets_loaded,
1054 &osd->rx_oversize, &nsd->rx_oversize);
1055 i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
1056 pf->stat_offsets_loaded,
1057 &osd->rx_jabber, &nsd->rx_jabber);
1060 i40e_stat_update_and_clear32(hw,
1061 I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(hw->pf_id)),
1062 &nsd->fd_atr_match);
1063 i40e_stat_update_and_clear32(hw,
1064 I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(hw->pf_id)),
1066 i40e_stat_update_and_clear32(hw,
1067 I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(hw->pf_id)),
1068 &nsd->fd_atr_tunnel_match);
1070 val = rd32(hw, I40E_PRTPM_EEE_STAT);
1071 nsd->tx_lpi_status =
1072 (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
1073 I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
1074 nsd->rx_lpi_status =
1075 (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
1076 I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
1077 i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
1078 pf->stat_offsets_loaded,
1079 &osd->tx_lpi_count, &nsd->tx_lpi_count);
1080 i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
1081 pf->stat_offsets_loaded,
1082 &osd->rx_lpi_count, &nsd->rx_lpi_count);
1084 if (pf->flags & I40E_FLAG_FD_SB_ENABLED &&
1085 !test_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state))
1086 nsd->fd_sb_status = true;
1088 nsd->fd_sb_status = false;
1090 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED &&
1091 !test_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state))
1092 nsd->fd_atr_status = true;
1094 nsd->fd_atr_status = false;
1096 pf->stat_offsets_loaded = true;
1100 * i40e_update_stats - Update the various statistics counters.
1101 * @vsi: the VSI to be updated
1103 * Update the various stats for this VSI and its related entities.
1105 void i40e_update_stats(struct i40e_vsi *vsi)
1107 struct i40e_pf *pf = vsi->back;
1109 if (vsi == pf->vsi[pf->lan_vsi])
1110 i40e_update_pf_stats(pf);
1112 i40e_update_vsi_stats(vsi);
1116 * i40e_count_filters - counts VSI mac filters
1117 * @vsi: the VSI to be searched
1119 * Returns count of mac filters
1121 int i40e_count_filters(struct i40e_vsi *vsi)
1123 struct i40e_mac_filter *f;
1124 struct hlist_node *h;
1128 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
1135 * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
1136 * @vsi: the VSI to be searched
1137 * @macaddr: the MAC address
1140 * Returns ptr to the filter object or NULL
1142 static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
1143 const u8 *macaddr, s16 vlan)
1145 struct i40e_mac_filter *f;
1148 if (!vsi || !macaddr)
1151 key = i40e_addr_to_hkey(macaddr);
1152 hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
1153 if ((ether_addr_equal(macaddr, f->macaddr)) &&
1161 * i40e_find_mac - Find a mac addr in the macvlan filters list
1162 * @vsi: the VSI to be searched
1163 * @macaddr: the MAC address we are searching for
1165 * Returns the first filter with the provided MAC address or NULL if
1166 * MAC address was not found
1168 struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr)
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)))
1185 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1186 * @vsi: the VSI to be searched
1188 * Returns true if VSI is in vlan mode or false otherwise
1190 bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
1192 /* If we have a PVID, always operate in VLAN mode */
1196 /* We need to operate in VLAN mode whenever we have any filters with
1197 * a VLAN other than I40E_VLAN_ALL. We could check the table each
1198 * time, incurring search cost repeatedly. However, we can notice two
1201 * 1) the only place where we can gain a VLAN filter is in
1204 * 2) the only place where filters are actually removed is in
1205 * i40e_sync_filters_subtask.
1207 * Thus, we can simply use a boolean value, has_vlan_filters which we
1208 * will set to true when we add a VLAN filter in i40e_add_filter. Then
1209 * we have to perform the full search after deleting filters in
1210 * i40e_sync_filters_subtask, but we already have to search
1211 * filters here and can perform the check at the same time. This
1212 * results in avoiding embedding a loop for VLAN mode inside another
1213 * loop over all the filters, and should maintain correctness as noted
1216 return vsi->has_vlan_filter;
1220 * i40e_correct_mac_vlan_filters - Correct non-VLAN filters if necessary
1221 * @vsi: the VSI to configure
1222 * @tmp_add_list: list of filters ready to be added
1223 * @tmp_del_list: list of filters ready to be deleted
1224 * @vlan_filters: the number of active VLAN filters
1226 * Update VLAN=0 and VLAN=-1 (I40E_VLAN_ANY) filters properly so that they
1227 * behave as expected. If we have any active VLAN filters remaining or about
1228 * to be added then we need to update non-VLAN filters to be marked as VLAN=0
1229 * so that they only match against untagged traffic. If we no longer have any
1230 * active VLAN filters, we need to make all non-VLAN filters marked as VLAN=-1
1231 * so that they match against both tagged and untagged traffic. In this way,
1232 * we ensure that we correctly receive the desired traffic. This ensures that
1233 * when we have an active VLAN we will receive only untagged traffic and
1234 * traffic matching active VLANs. If we have no active VLANs then we will
1235 * operate in non-VLAN mode and receive all traffic, tagged or untagged.
1237 * Finally, in a similar fashion, this function also corrects filters when
1238 * there is an active PVID assigned to this VSI.
1240 * In case of memory allocation failure return -ENOMEM. Otherwise, return 0.
1242 * This function is only expected to be called from within
1243 * i40e_sync_vsi_filters.
1245 * NOTE: This function expects to be called while under the
1246 * mac_filter_hash_lock
1248 static int i40e_correct_mac_vlan_filters(struct i40e_vsi *vsi,
1249 struct hlist_head *tmp_add_list,
1250 struct hlist_head *tmp_del_list,
1253 s16 pvid = le16_to_cpu(vsi->info.pvid);
1254 struct i40e_mac_filter *f, *add_head;
1255 struct i40e_new_mac_filter *new;
1256 struct hlist_node *h;
1259 /* To determine if a particular filter needs to be replaced we
1260 * have the three following conditions:
1262 * a) if we have a PVID assigned, then all filters which are
1263 * not marked as VLAN=PVID must be replaced with filters that
1265 * b) otherwise, if we have any active VLANS, all filters
1266 * which are marked as VLAN=-1 must be replaced with
1267 * filters marked as VLAN=0
1268 * c) finally, if we do not have any active VLANS, all filters
1269 * which are marked as VLAN=0 must be replaced with filters
1273 /* Update the filters about to be added in place */
1274 hlist_for_each_entry(new, tmp_add_list, hlist) {
1275 if (pvid && new->f->vlan != pvid)
1276 new->f->vlan = pvid;
1277 else if (vlan_filters && new->f->vlan == I40E_VLAN_ANY)
1279 else if (!vlan_filters && new->f->vlan == 0)
1280 new->f->vlan = I40E_VLAN_ANY;
1283 /* Update the remaining active filters */
1284 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
1285 /* Combine the checks for whether a filter needs to be changed
1286 * and then determine the new VLAN inside the if block, in
1287 * order to avoid duplicating code for adding the new filter
1288 * then deleting the old filter.
1290 if ((pvid && f->vlan != pvid) ||
1291 (vlan_filters && f->vlan == I40E_VLAN_ANY) ||
1292 (!vlan_filters && f->vlan == 0)) {
1293 /* Determine the new vlan we will be adding */
1296 else if (vlan_filters)
1299 new_vlan = I40E_VLAN_ANY;
1301 /* Create the new filter */
1302 add_head = i40e_add_filter(vsi, f->macaddr, new_vlan);
1306 /* Create a temporary i40e_new_mac_filter */
1307 new = kzalloc(sizeof(*new), GFP_ATOMIC);
1312 new->state = add_head->state;
1314 /* Add the new filter to the tmp list */
1315 hlist_add_head(&new->hlist, tmp_add_list);
1317 /* Put the original filter into the delete list */
1318 f->state = I40E_FILTER_REMOVE;
1319 hash_del(&f->hlist);
1320 hlist_add_head(&f->hlist, tmp_del_list);
1324 vsi->has_vlan_filter = !!vlan_filters;
1330 * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
1331 * @vsi: the PF Main VSI - inappropriate for any other VSI
1332 * @macaddr: the MAC address
1334 * Remove whatever filter the firmware set up so the driver can manage
1335 * its own filtering intelligently.
1337 static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
1339 struct i40e_aqc_remove_macvlan_element_data element;
1340 struct i40e_pf *pf = vsi->back;
1342 /* Only appropriate for the PF main VSI */
1343 if (vsi->type != I40E_VSI_MAIN)
1346 memset(&element, 0, sizeof(element));
1347 ether_addr_copy(element.mac_addr, macaddr);
1348 element.vlan_tag = 0;
1349 /* Ignore error returns, some firmware does it this way... */
1350 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
1351 i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1353 memset(&element, 0, sizeof(element));
1354 ether_addr_copy(element.mac_addr, macaddr);
1355 element.vlan_tag = 0;
1356 /* ...and some firmware does it this way. */
1357 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
1358 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
1359 i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1363 * i40e_add_filter - Add a mac/vlan filter to the VSI
1364 * @vsi: the VSI to be searched
1365 * @macaddr: the MAC address
1368 * Returns ptr to the filter object or NULL when no memory available.
1370 * NOTE: This function is expected to be called with mac_filter_hash_lock
1373 struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
1374 const u8 *macaddr, s16 vlan)
1376 struct i40e_mac_filter *f;
1379 if (!vsi || !macaddr)
1382 f = i40e_find_filter(vsi, macaddr, vlan);
1384 f = kzalloc(sizeof(*f), GFP_ATOMIC);
1388 /* Update the boolean indicating if we need to function in
1392 vsi->has_vlan_filter = true;
1394 ether_addr_copy(f->macaddr, macaddr);
1396 f->state = I40E_FILTER_NEW;
1397 INIT_HLIST_NODE(&f->hlist);
1399 key = i40e_addr_to_hkey(macaddr);
1400 hash_add(vsi->mac_filter_hash, &f->hlist, key);
1402 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1403 set_bit(__I40E_MACVLAN_SYNC_PENDING, vsi->back->state);
1406 /* If we're asked to add a filter that has been marked for removal, it
1407 * is safe to simply restore it to active state. __i40e_del_filter
1408 * will have simply deleted any filters which were previously marked
1409 * NEW or FAILED, so if it is currently marked REMOVE it must have
1410 * previously been ACTIVE. Since we haven't yet run the sync filters
1411 * task, just restore this filter to the ACTIVE state so that the
1412 * sync task leaves it in place
1414 if (f->state == I40E_FILTER_REMOVE)
1415 f->state = I40E_FILTER_ACTIVE;
1421 * __i40e_del_filter - Remove a specific filter from the VSI
1422 * @vsi: VSI to remove from
1423 * @f: the filter to remove from the list
1425 * This function should be called instead of i40e_del_filter only if you know
1426 * the exact filter you will remove already, such as via i40e_find_filter or
1429 * NOTE: This function is expected to be called with mac_filter_hash_lock
1431 * ANOTHER NOTE: This function MUST be called from within the context of
1432 * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
1433 * instead of list_for_each_entry().
1435 void __i40e_del_filter(struct i40e_vsi *vsi, struct i40e_mac_filter *f)
1440 /* If the filter was never added to firmware then we can just delete it
1441 * directly and we don't want to set the status to remove or else an
1442 * admin queue command will unnecessarily fire.
1444 if ((f->state == I40E_FILTER_FAILED) ||
1445 (f->state == I40E_FILTER_NEW)) {
1446 hash_del(&f->hlist);
1449 f->state = I40E_FILTER_REMOVE;
1452 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1453 set_bit(__I40E_MACVLAN_SYNC_PENDING, vsi->back->state);
1457 * i40e_del_filter - Remove a MAC/VLAN filter from the VSI
1458 * @vsi: the VSI to be searched
1459 * @macaddr: the MAC address
1462 * NOTE: This function is expected to be called with mac_filter_hash_lock
1464 * ANOTHER NOTE: This function MUST be called from within the context of
1465 * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
1466 * instead of list_for_each_entry().
1468 void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan)
1470 struct i40e_mac_filter *f;
1472 if (!vsi || !macaddr)
1475 f = i40e_find_filter(vsi, macaddr, vlan);
1476 __i40e_del_filter(vsi, f);
1480 * i40e_add_mac_filter - Add a MAC filter for all active VLANs
1481 * @vsi: the VSI to be searched
1482 * @macaddr: the mac address to be filtered
1484 * If we're not in VLAN mode, just add the filter to I40E_VLAN_ANY. Otherwise,
1485 * go through all the macvlan filters and add a macvlan filter for each
1486 * unique vlan that already exists. If a PVID has been assigned, instead only
1487 * add the macaddr to that VLAN.
1489 * Returns last filter added on success, else NULL
1491 struct i40e_mac_filter *i40e_add_mac_filter(struct i40e_vsi *vsi,
1494 struct i40e_mac_filter *f, *add = NULL;
1495 struct hlist_node *h;
1499 return i40e_add_filter(vsi, macaddr,
1500 le16_to_cpu(vsi->info.pvid));
1502 if (!i40e_is_vsi_in_vlan(vsi))
1503 return i40e_add_filter(vsi, macaddr, I40E_VLAN_ANY);
1505 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
1506 if (f->state == I40E_FILTER_REMOVE)
1508 add = i40e_add_filter(vsi, macaddr, f->vlan);
1517 * i40e_del_mac_filter - Remove a MAC filter from all VLANs
1518 * @vsi: the VSI to be searched
1519 * @macaddr: the mac address to be removed
1521 * Removes a given MAC address from a VSI regardless of what VLAN it has been
1524 * Returns 0 for success, or error
1526 int i40e_del_mac_filter(struct i40e_vsi *vsi, const u8 *macaddr)
1528 struct i40e_mac_filter *f;
1529 struct hlist_node *h;
1533 lockdep_assert_held(&vsi->mac_filter_hash_lock);
1534 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
1535 if (ether_addr_equal(macaddr, f->macaddr)) {
1536 __i40e_del_filter(vsi, f);
1548 * i40e_set_mac - NDO callback to set mac address
1549 * @netdev: network interface device structure
1550 * @p: pointer to an address structure
1552 * Returns 0 on success, negative on failure
1554 static int i40e_set_mac(struct net_device *netdev, void *p)
1556 struct i40e_netdev_priv *np = netdev_priv(netdev);
1557 struct i40e_vsi *vsi = np->vsi;
1558 struct i40e_pf *pf = vsi->back;
1559 struct i40e_hw *hw = &pf->hw;
1560 struct sockaddr *addr = p;
1562 if (!is_valid_ether_addr(addr->sa_data))
1563 return -EADDRNOTAVAIL;
1565 if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
1566 netdev_info(netdev, "already using mac address %pM\n",
1571 if (test_bit(__I40E_DOWN, pf->state) ||
1572 test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
1573 return -EADDRNOTAVAIL;
1575 if (ether_addr_equal(hw->mac.addr, addr->sa_data))
1576 netdev_info(netdev, "returning to hw mac address %pM\n",
1579 netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
1581 /* Copy the address first, so that we avoid a possible race with
1583 * - Remove old address from MAC filter
1584 * - Copy new address
1585 * - Add new address to MAC filter
1587 spin_lock_bh(&vsi->mac_filter_hash_lock);
1588 i40e_del_mac_filter(vsi, netdev->dev_addr);
1589 ether_addr_copy(netdev->dev_addr, addr->sa_data);
1590 i40e_add_mac_filter(vsi, netdev->dev_addr);
1591 spin_unlock_bh(&vsi->mac_filter_hash_lock);
1593 if (vsi->type == I40E_VSI_MAIN) {
1596 ret = i40e_aq_mac_address_write(hw, I40E_AQC_WRITE_TYPE_LAA_WOL,
1597 addr->sa_data, NULL);
1599 netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n",
1600 i40e_stat_str(hw, ret),
1601 i40e_aq_str(hw, hw->aq.asq_last_status));
1604 /* schedule our worker thread which will take care of
1605 * applying the new filter changes
1607 i40e_service_event_schedule(pf);
1612 * i40e_config_rss_aq - Prepare for RSS using AQ commands
1613 * @vsi: vsi structure
1614 * @seed: RSS hash seed
1615 * @lut: pointer to lookup table of lut_size
1616 * @lut_size: size of the lookup table
1618 static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
1619 u8 *lut, u16 lut_size)
1621 struct i40e_pf *pf = vsi->back;
1622 struct i40e_hw *hw = &pf->hw;
1626 struct i40e_aqc_get_set_rss_key_data *seed_dw =
1627 (struct i40e_aqc_get_set_rss_key_data *)seed;
1628 ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw);
1630 dev_info(&pf->pdev->dev,
1631 "Cannot set RSS key, err %s aq_err %s\n",
1632 i40e_stat_str(hw, ret),
1633 i40e_aq_str(hw, hw->aq.asq_last_status));
1638 bool pf_lut = vsi->type == I40E_VSI_MAIN;
1640 ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
1642 dev_info(&pf->pdev->dev,
1643 "Cannot set RSS lut, err %s aq_err %s\n",
1644 i40e_stat_str(hw, ret),
1645 i40e_aq_str(hw, hw->aq.asq_last_status));
1653 * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
1654 * @vsi: VSI structure
1656 static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
1658 struct i40e_pf *pf = vsi->back;
1659 u8 seed[I40E_HKEY_ARRAY_SIZE];
1663 if (!(pf->hw_features & I40E_HW_RSS_AQ_CAPABLE))
1666 vsi->rss_size = min_t(int, pf->alloc_rss_size,
1667 vsi->num_queue_pairs);
1670 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
1674 /* Use the user configured hash keys and lookup table if there is one,
1675 * otherwise use default
1677 if (vsi->rss_lut_user)
1678 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
1680 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
1681 if (vsi->rss_hkey_user)
1682 memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
1684 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
1685 ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
1691 * i40e_vsi_setup_queue_map_mqprio - Prepares mqprio based tc_config
1692 * @vsi: the VSI being configured,
1693 * @ctxt: VSI context structure
1694 * @enabled_tc: number of traffic classes to enable
1696 * Prepares VSI tc_config to have queue configurations based on MQPRIO options.
1698 static int i40e_vsi_setup_queue_map_mqprio(struct i40e_vsi *vsi,
1699 struct i40e_vsi_context *ctxt,
1702 u16 qcount = 0, max_qcount, qmap, sections = 0;
1703 int i, override_q, pow, num_qps, ret;
1704 u8 netdev_tc = 0, offset = 0;
1706 if (vsi->type != I40E_VSI_MAIN)
1708 sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
1709 sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
1710 vsi->tc_config.numtc = vsi->mqprio_qopt.qopt.num_tc;
1711 vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
1712 num_qps = vsi->mqprio_qopt.qopt.count[0];
1714 /* find the next higher power-of-2 of num queue pairs */
1715 pow = ilog2(num_qps);
1716 if (!is_power_of_2(num_qps))
1718 qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
1719 (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
1721 /* Setup queue offset/count for all TCs for given VSI */
1722 max_qcount = vsi->mqprio_qopt.qopt.count[0];
1723 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1724 /* See if the given TC is enabled for the given VSI */
1725 if (vsi->tc_config.enabled_tc & BIT(i)) {
1726 offset = vsi->mqprio_qopt.qopt.offset[i];
1727 qcount = vsi->mqprio_qopt.qopt.count[i];
1728 if (qcount > max_qcount)
1729 max_qcount = qcount;
1730 vsi->tc_config.tc_info[i].qoffset = offset;
1731 vsi->tc_config.tc_info[i].qcount = qcount;
1732 vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
1734 /* TC is not enabled so set the offset to
1735 * default queue and allocate one queue
1738 vsi->tc_config.tc_info[i].qoffset = 0;
1739 vsi->tc_config.tc_info[i].qcount = 1;
1740 vsi->tc_config.tc_info[i].netdev_tc = 0;
1744 /* Set actual Tx/Rx queue pairs */
1745 vsi->num_queue_pairs = offset + qcount;
1747 /* Setup queue TC[0].qmap for given VSI context */
1748 ctxt->info.tc_mapping[0] = cpu_to_le16(qmap);
1749 ctxt->info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
1750 ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
1751 ctxt->info.valid_sections |= cpu_to_le16(sections);
1753 /* Reconfigure RSS for main VSI with max queue count */
1754 vsi->rss_size = max_qcount;
1755 ret = i40e_vsi_config_rss(vsi);
1757 dev_info(&vsi->back->pdev->dev,
1758 "Failed to reconfig rss for num_queues (%u)\n",
1762 vsi->reconfig_rss = true;
1763 dev_dbg(&vsi->back->pdev->dev,
1764 "Reconfigured rss with num_queues (%u)\n", max_qcount);
1766 /* Find queue count available for channel VSIs and starting offset
1769 override_q = vsi->mqprio_qopt.qopt.count[0];
1770 if (override_q && override_q < vsi->num_queue_pairs) {
1771 vsi->cnt_q_avail = vsi->num_queue_pairs - override_q;
1772 vsi->next_base_queue = override_q;
1778 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1779 * @vsi: the VSI being setup
1780 * @ctxt: VSI context structure
1781 * @enabled_tc: Enabled TCs bitmap
1782 * @is_add: True if called before Add VSI
1784 * Setup VSI queue mapping for enabled traffic classes.
1786 static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
1787 struct i40e_vsi_context *ctxt,
1791 struct i40e_pf *pf = vsi->back;
1801 sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
1804 /* Number of queues per enabled TC */
1805 num_tc_qps = vsi->alloc_queue_pairs;
1806 if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
1807 /* Find numtc from enabled TC bitmap */
1808 for (i = 0, numtc = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1809 if (enabled_tc & BIT(i)) /* TC is enabled */
1813 dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
1816 num_tc_qps = num_tc_qps / numtc;
1817 num_tc_qps = min_t(int, num_tc_qps,
1818 i40e_pf_get_max_q_per_tc(pf));
1821 vsi->tc_config.numtc = numtc;
1822 vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
1824 /* Do not allow use more TC queue pairs than MSI-X vectors exist */
1825 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
1826 num_tc_qps = min_t(int, num_tc_qps, pf->num_lan_msix);
1828 /* Setup queue offset/count for all TCs for given VSI */
1829 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1830 /* See if the given TC is enabled for the given VSI */
1831 if (vsi->tc_config.enabled_tc & BIT(i)) {
1835 switch (vsi->type) {
1837 if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED |
1838 I40E_FLAG_FD_ATR_ENABLED)) ||
1839 vsi->tc_config.enabled_tc != 1) {
1840 qcount = min_t(int, pf->alloc_rss_size,
1846 case I40E_VSI_SRIOV:
1847 case I40E_VSI_VMDQ2:
1849 qcount = num_tc_qps;
1853 vsi->tc_config.tc_info[i].qoffset = offset;
1854 vsi->tc_config.tc_info[i].qcount = qcount;
1856 /* find the next higher power-of-2 of num queue pairs */
1859 while (num_qps && (BIT_ULL(pow) < qcount)) {
1864 vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
1866 (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
1867 (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
1871 /* TC is not enabled so set the offset to
1872 * default queue and allocate one queue
1875 vsi->tc_config.tc_info[i].qoffset = 0;
1876 vsi->tc_config.tc_info[i].qcount = 1;
1877 vsi->tc_config.tc_info[i].netdev_tc = 0;
1881 ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
1884 /* Set actual Tx/Rx queue pairs */
1885 vsi->num_queue_pairs = offset;
1886 if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
1887 if (vsi->req_queue_pairs > 0)
1888 vsi->num_queue_pairs = vsi->req_queue_pairs;
1889 else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
1890 vsi->num_queue_pairs = pf->num_lan_msix;
1893 /* Scheduler section valid can only be set for ADD VSI */
1895 sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
1897 ctxt->info.up_enable_bits = enabled_tc;
1899 if (vsi->type == I40E_VSI_SRIOV) {
1900 ctxt->info.mapping_flags |=
1901 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
1902 for (i = 0; i < vsi->num_queue_pairs; i++)
1903 ctxt->info.queue_mapping[i] =
1904 cpu_to_le16(vsi->base_queue + i);
1906 ctxt->info.mapping_flags |=
1907 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
1908 ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
1910 ctxt->info.valid_sections |= cpu_to_le16(sections);
1914 * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address
1915 * @netdev: the netdevice
1916 * @addr: address to add
1918 * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
1919 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
1921 static int i40e_addr_sync(struct net_device *netdev, const u8 *addr)
1923 struct i40e_netdev_priv *np = netdev_priv(netdev);
1924 struct i40e_vsi *vsi = np->vsi;
1926 if (i40e_add_mac_filter(vsi, addr))
1933 * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
1934 * @netdev: the netdevice
1935 * @addr: address to add
1937 * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
1938 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
1940 static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr)
1942 struct i40e_netdev_priv *np = netdev_priv(netdev);
1943 struct i40e_vsi *vsi = np->vsi;
1945 /* Under some circumstances, we might receive a request to delete
1946 * our own device address from our uc list. Because we store the
1947 * device address in the VSI's MAC/VLAN filter list, we need to ignore
1948 * such requests and not delete our device address from this list.
1950 if (ether_addr_equal(addr, netdev->dev_addr))
1953 i40e_del_mac_filter(vsi, addr);
1959 * i40e_set_rx_mode - NDO callback to set the netdev filters
1960 * @netdev: network interface device structure
1962 static void i40e_set_rx_mode(struct net_device *netdev)
1964 struct i40e_netdev_priv *np = netdev_priv(netdev);
1965 struct i40e_vsi *vsi = np->vsi;
1967 spin_lock_bh(&vsi->mac_filter_hash_lock);
1969 __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
1970 __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
1972 spin_unlock_bh(&vsi->mac_filter_hash_lock);
1974 /* check for other flag changes */
1975 if (vsi->current_netdev_flags != vsi->netdev->flags) {
1976 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1977 set_bit(__I40E_MACVLAN_SYNC_PENDING, vsi->back->state);
1982 * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
1983 * @vsi: Pointer to VSI struct
1984 * @from: Pointer to list which contains MAC filter entries - changes to
1985 * those entries needs to be undone.
1987 * MAC filter entries from this list were slated for deletion.
1989 static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi,
1990 struct hlist_head *from)
1992 struct i40e_mac_filter *f;
1993 struct hlist_node *h;
1995 hlist_for_each_entry_safe(f, h, from, hlist) {
1996 u64 key = i40e_addr_to_hkey(f->macaddr);
1998 /* Move the element back into MAC filter list*/
1999 hlist_del(&f->hlist);
2000 hash_add(vsi->mac_filter_hash, &f->hlist, key);
2005 * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries
2006 * @vsi: Pointer to vsi struct
2007 * @from: Pointer to list which contains MAC filter entries - changes to
2008 * those entries needs to be undone.
2010 * MAC filter entries from this list were slated for addition.
2012 static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi,
2013 struct hlist_head *from)
2015 struct i40e_new_mac_filter *new;
2016 struct hlist_node *h;
2018 hlist_for_each_entry_safe(new, h, from, hlist) {
2019 /* We can simply free the wrapper structure */
2020 hlist_del(&new->hlist);
2026 * i40e_next_entry - Get the next non-broadcast filter from a list
2027 * @next: pointer to filter in list
2029 * Returns the next non-broadcast filter in the list. Required so that we
2030 * ignore broadcast filters within the list, since these are not handled via
2031 * the normal firmware update path.
2034 struct i40e_new_mac_filter *i40e_next_filter(struct i40e_new_mac_filter *next)
2036 hlist_for_each_entry_continue(next, hlist) {
2037 if (!is_broadcast_ether_addr(next->f->macaddr))
2045 * i40e_update_filter_state - Update filter state based on return data
2047 * @count: Number of filters added
2048 * @add_list: return data from fw
2049 * @add_head: pointer to first filter in current batch
2051 * MAC filter entries from list were slated to be added to device. Returns
2052 * number of successful filters. Note that 0 does NOT mean success!
2055 i40e_update_filter_state(int count,
2056 struct i40e_aqc_add_macvlan_element_data *add_list,
2057 struct i40e_new_mac_filter *add_head)
2062 for (i = 0; i < count; i++) {
2063 /* Always check status of each filter. We don't need to check
2064 * the firmware return status because we pre-set the filter
2065 * status to I40E_AQC_MM_ERR_NO_RES when sending the filter
2066 * request to the adminq. Thus, if it no longer matches then
2067 * we know the filter is active.
2069 if (add_list[i].match_method == I40E_AQC_MM_ERR_NO_RES) {
2070 add_head->state = I40E_FILTER_FAILED;
2072 add_head->state = I40E_FILTER_ACTIVE;
2076 add_head = i40e_next_filter(add_head);
2085 * i40e_aqc_del_filters - Request firmware to delete a set of filters
2086 * @vsi: ptr to the VSI
2087 * @vsi_name: name to display in messages
2088 * @list: the list of filters to send to firmware
2089 * @num_del: the number of filters to delete
2090 * @retval: Set to -EIO on failure to delete
2092 * Send a request to firmware via AdminQ to delete a set of filters. Uses
2093 * *retval instead of a return value so that success does not force ret_val to
2094 * be set to 0. This ensures that a sequence of calls to this function
2095 * preserve the previous value of *retval on successful delete.
2098 void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name,
2099 struct i40e_aqc_remove_macvlan_element_data *list,
2100 int num_del, int *retval)
2102 struct i40e_hw *hw = &vsi->back->hw;
2106 aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL);
2107 aq_err = hw->aq.asq_last_status;
2109 /* Explicitly ignore and do not report when firmware returns ENOENT */
2110 if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) {
2112 dev_info(&vsi->back->pdev->dev,
2113 "ignoring delete macvlan error on %s, err %s, aq_err %s\n",
2114 vsi_name, i40e_stat_str(hw, aq_ret),
2115 i40e_aq_str(hw, aq_err));
2120 * i40e_aqc_add_filters - Request firmware to add a set of filters
2121 * @vsi: ptr to the VSI
2122 * @vsi_name: name to display in messages
2123 * @list: the list of filters to send to firmware
2124 * @add_head: Position in the add hlist
2125 * @num_add: the number of filters to add
2127 * Send a request to firmware via AdminQ to add a chunk of filters. Will set
2128 * __I40E_VSI_OVERFLOW_PROMISC bit in vsi->state if the firmware has run out of
2129 * space for more filters.
2132 void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name,
2133 struct i40e_aqc_add_macvlan_element_data *list,
2134 struct i40e_new_mac_filter *add_head,
2137 struct i40e_hw *hw = &vsi->back->hw;
2140 i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL);
2141 aq_err = hw->aq.asq_last_status;
2142 fcnt = i40e_update_filter_state(num_add, list, add_head);
2144 if (fcnt != num_add) {
2145 if (vsi->type == I40E_VSI_MAIN) {
2146 set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
2147 dev_warn(&vsi->back->pdev->dev,
2148 "Error %s adding RX filters on %s, promiscuous mode forced on\n",
2149 i40e_aq_str(hw, aq_err), vsi_name);
2150 } else if (vsi->type == I40E_VSI_SRIOV ||
2151 vsi->type == I40E_VSI_VMDQ1 ||
2152 vsi->type == I40E_VSI_VMDQ2) {
2153 dev_warn(&vsi->back->pdev->dev,
2154 "Error %s adding RX filters on %s, please set promiscuous on manually for %s\n",
2155 i40e_aq_str(hw, aq_err), vsi_name, vsi_name);
2157 dev_warn(&vsi->back->pdev->dev,
2158 "Error %s adding RX filters on %s, incorrect VSI type: %i.\n",
2159 i40e_aq_str(hw, aq_err), vsi_name, vsi->type);
2165 * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags
2166 * @vsi: pointer to the VSI
2167 * @vsi_name: the VSI name
2170 * This function sets or clears the promiscuous broadcast flags for VLAN
2171 * filters in order to properly receive broadcast frames. Assumes that only
2172 * broadcast filters are passed.
2174 * Returns status indicating success or failure;
2177 i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name,
2178 struct i40e_mac_filter *f)
2180 bool enable = f->state == I40E_FILTER_NEW;
2181 struct i40e_hw *hw = &vsi->back->hw;
2184 if (f->vlan == I40E_VLAN_ANY) {
2185 aq_ret = i40e_aq_set_vsi_broadcast(hw,
2190 aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw,
2198 set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
2199 dev_warn(&vsi->back->pdev->dev,
2200 "Error %s, forcing overflow promiscuous on %s\n",
2201 i40e_aq_str(hw, hw->aq.asq_last_status),
2209 * i40e_set_promiscuous - set promiscuous mode
2210 * @pf: board private structure
2211 * @promisc: promisc on or off
2213 * There are different ways of setting promiscuous mode on a PF depending on
2214 * what state/environment we're in. This identifies and sets it appropriately.
2215 * Returns 0 on success.
2217 static int i40e_set_promiscuous(struct i40e_pf *pf, bool promisc)
2219 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
2220 struct i40e_hw *hw = &pf->hw;
2223 if (vsi->type == I40E_VSI_MAIN &&
2224 pf->lan_veb != I40E_NO_VEB &&
2225 !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
2226 /* set defport ON for Main VSI instead of true promisc
2227 * this way we will get all unicast/multicast and VLAN
2228 * promisc behavior but will not get VF or VMDq traffic
2229 * replicated on the Main VSI.
2232 aq_ret = i40e_aq_set_default_vsi(hw,
2236 aq_ret = i40e_aq_clear_default_vsi(hw,
2240 dev_info(&pf->pdev->dev,
2241 "Set default VSI failed, err %s, aq_err %s\n",
2242 i40e_stat_str(hw, aq_ret),
2243 i40e_aq_str(hw, hw->aq.asq_last_status));
2246 aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
2252 dev_info(&pf->pdev->dev,
2253 "set unicast promisc failed, err %s, aq_err %s\n",
2254 i40e_stat_str(hw, aq_ret),
2255 i40e_aq_str(hw, hw->aq.asq_last_status));
2257 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
2262 dev_info(&pf->pdev->dev,
2263 "set multicast promisc failed, err %s, aq_err %s\n",
2264 i40e_stat_str(hw, aq_ret),
2265 i40e_aq_str(hw, hw->aq.asq_last_status));
2270 pf->cur_promisc = promisc;
2276 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
2277 * @vsi: ptr to the VSI
2279 * Push any outstanding VSI filter changes through the AdminQ.
2281 * Returns 0 or error value
2283 int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
2285 struct hlist_head tmp_add_list, tmp_del_list;
2286 struct i40e_mac_filter *f;
2287 struct i40e_new_mac_filter *new, *add_head = NULL;
2288 struct i40e_hw *hw = &vsi->back->hw;
2289 bool old_overflow, new_overflow;
2290 unsigned int failed_filters = 0;
2291 unsigned int vlan_filters = 0;
2292 char vsi_name[16] = "PF";
2293 int filter_list_len = 0;
2294 i40e_status aq_ret = 0;
2295 u32 changed_flags = 0;
2296 struct hlist_node *h;
2305 /* empty array typed pointers, kcalloc later */
2306 struct i40e_aqc_add_macvlan_element_data *add_list;
2307 struct i40e_aqc_remove_macvlan_element_data *del_list;
2309 while (test_and_set_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state))
2310 usleep_range(1000, 2000);
2313 old_overflow = test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
2316 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
2317 vsi->current_netdev_flags = vsi->netdev->flags;
2320 INIT_HLIST_HEAD(&tmp_add_list);
2321 INIT_HLIST_HEAD(&tmp_del_list);
2323 if (vsi->type == I40E_VSI_SRIOV)
2324 snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id);
2325 else if (vsi->type != I40E_VSI_MAIN)
2326 snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid);
2328 if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
2329 vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
2331 spin_lock_bh(&vsi->mac_filter_hash_lock);
2332 /* Create a list of filters to delete. */
2333 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
2334 if (f->state == I40E_FILTER_REMOVE) {
2335 /* Move the element into temporary del_list */
2336 hash_del(&f->hlist);
2337 hlist_add_head(&f->hlist, &tmp_del_list);
2339 /* Avoid counting removed filters */
2342 if (f->state == I40E_FILTER_NEW) {
2343 /* Create a temporary i40e_new_mac_filter */
2344 new = kzalloc(sizeof(*new), GFP_ATOMIC);
2346 goto err_no_memory_locked;
2348 /* Store pointer to the real filter */
2350 new->state = f->state;
2352 /* Add it to the hash list */
2353 hlist_add_head(&new->hlist, &tmp_add_list);
2356 /* Count the number of active (current and new) VLAN
2357 * filters we have now. Does not count filters which
2358 * are marked for deletion.
2364 retval = i40e_correct_mac_vlan_filters(vsi,
2369 goto err_no_memory_locked;
2371 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2374 /* Now process 'del_list' outside the lock */
2375 if (!hlist_empty(&tmp_del_list)) {
2376 filter_list_len = hw->aq.asq_buf_size /
2377 sizeof(struct i40e_aqc_remove_macvlan_element_data);
2378 list_size = filter_list_len *
2379 sizeof(struct i40e_aqc_remove_macvlan_element_data);
2380 del_list = kzalloc(list_size, GFP_ATOMIC);
2384 hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) {
2387 /* handle broadcast filters by updating the broadcast
2388 * promiscuous flag and release filter list.
2390 if (is_broadcast_ether_addr(f->macaddr)) {
2391 i40e_aqc_broadcast_filter(vsi, vsi_name, f);
2393 hlist_del(&f->hlist);
2398 /* add to delete list */
2399 ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
2400 if (f->vlan == I40E_VLAN_ANY) {
2401 del_list[num_del].vlan_tag = 0;
2402 cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
2404 del_list[num_del].vlan_tag =
2405 cpu_to_le16((u16)(f->vlan));
2408 cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
2409 del_list[num_del].flags = cmd_flags;
2412 /* flush a full buffer */
2413 if (num_del == filter_list_len) {
2414 i40e_aqc_del_filters(vsi, vsi_name, del_list,
2416 memset(del_list, 0, list_size);
2419 /* Release memory for MAC filter entries which were
2420 * synced up with HW.
2422 hlist_del(&f->hlist);
2427 i40e_aqc_del_filters(vsi, vsi_name, del_list,
2435 if (!hlist_empty(&tmp_add_list)) {
2436 /* Do all the adds now. */
2437 filter_list_len = hw->aq.asq_buf_size /
2438 sizeof(struct i40e_aqc_add_macvlan_element_data);
2439 list_size = filter_list_len *
2440 sizeof(struct i40e_aqc_add_macvlan_element_data);
2441 add_list = kzalloc(list_size, GFP_ATOMIC);
2446 hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
2447 /* handle broadcast filters by updating the broadcast
2448 * promiscuous flag instead of adding a MAC filter.
2450 if (is_broadcast_ether_addr(new->f->macaddr)) {
2451 if (i40e_aqc_broadcast_filter(vsi, vsi_name,
2453 new->state = I40E_FILTER_FAILED;
2455 new->state = I40E_FILTER_ACTIVE;
2459 /* add to add array */
2463 ether_addr_copy(add_list[num_add].mac_addr,
2465 if (new->f->vlan == I40E_VLAN_ANY) {
2466 add_list[num_add].vlan_tag = 0;
2467 cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
2469 add_list[num_add].vlan_tag =
2470 cpu_to_le16((u16)(new->f->vlan));
2472 add_list[num_add].queue_number = 0;
2473 /* set invalid match method for later detection */
2474 add_list[num_add].match_method = I40E_AQC_MM_ERR_NO_RES;
2475 cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
2476 add_list[num_add].flags = cpu_to_le16(cmd_flags);
2479 /* flush a full buffer */
2480 if (num_add == filter_list_len) {
2481 i40e_aqc_add_filters(vsi, vsi_name, add_list,
2483 memset(add_list, 0, list_size);
2488 i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head,
2491 /* Now move all of the filters from the temp add list back to
2494 spin_lock_bh(&vsi->mac_filter_hash_lock);
2495 hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
2496 /* Only update the state if we're still NEW */
2497 if (new->f->state == I40E_FILTER_NEW)
2498 new->f->state = new->state;
2499 hlist_del(&new->hlist);
2502 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2507 /* Determine the number of active and failed filters. */
2508 spin_lock_bh(&vsi->mac_filter_hash_lock);
2509 vsi->active_filters = 0;
2510 hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
2511 if (f->state == I40E_FILTER_ACTIVE)
2512 vsi->active_filters++;
2513 else if (f->state == I40E_FILTER_FAILED)
2516 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2518 /* Check if we are able to exit overflow promiscuous mode. We can
2519 * safely exit if we didn't just enter, we no longer have any failed
2520 * filters, and we have reduced filters below the threshold value.
2522 if (old_overflow && !failed_filters &&
2523 vsi->active_filters < vsi->promisc_threshold) {
2524 dev_info(&pf->pdev->dev,
2525 "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
2527 clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
2528 vsi->promisc_threshold = 0;
2531 /* if the VF is not trusted do not do promisc */
2532 if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) {
2533 clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
2537 new_overflow = test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
2539 /* If we are entering overflow promiscuous, we need to calculate a new
2540 * threshold for when we are safe to exit
2542 if (!old_overflow && new_overflow)
2543 vsi->promisc_threshold = (vsi->active_filters * 3) / 4;
2545 /* check for changes in promiscuous modes */
2546 if (changed_flags & IFF_ALLMULTI) {
2547 bool cur_multipromisc;
2549 cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
2550 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
2555 retval = i40e_aq_rc_to_posix(aq_ret,
2556 hw->aq.asq_last_status);
2557 dev_info(&pf->pdev->dev,
2558 "set multi promisc failed on %s, err %s aq_err %s\n",
2560 i40e_stat_str(hw, aq_ret),
2561 i40e_aq_str(hw, hw->aq.asq_last_status));
2563 dev_info(&pf->pdev->dev, "%s is %s allmulti mode.\n",
2565 cur_multipromisc ? "entering" : "leaving");
2569 if ((changed_flags & IFF_PROMISC) || old_overflow != new_overflow) {
2572 cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
2574 aq_ret = i40e_set_promiscuous(pf, cur_promisc);
2576 retval = i40e_aq_rc_to_posix(aq_ret,
2577 hw->aq.asq_last_status);
2578 dev_info(&pf->pdev->dev,
2579 "Setting promiscuous %s failed on %s, err %s aq_err %s\n",
2580 cur_promisc ? "on" : "off",
2582 i40e_stat_str(hw, aq_ret),
2583 i40e_aq_str(hw, hw->aq.asq_last_status));
2587 /* if something went wrong then set the changed flag so we try again */
2589 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
2591 clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
2595 /* Restore elements on the temporary add and delete lists */
2596 spin_lock_bh(&vsi->mac_filter_hash_lock);
2597 err_no_memory_locked:
2598 i40e_undo_del_filter_entries(vsi, &tmp_del_list);
2599 i40e_undo_add_filter_entries(vsi, &tmp_add_list);
2600 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2602 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
2603 clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
2608 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
2609 * @pf: board private structure
2611 static void i40e_sync_filters_subtask(struct i40e_pf *pf)
2617 if (!test_and_clear_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state))
2619 if (test_bit(__I40E_VF_DISABLE, pf->state)) {
2620 set_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state);
2624 for (v = 0; v < pf->num_alloc_vsi; v++) {
2626 (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
2627 int ret = i40e_sync_vsi_filters(pf->vsi[v]);
2630 /* come back and try again later */
2631 set_bit(__I40E_MACVLAN_SYNC_PENDING,
2640 * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP
2643 static int i40e_max_xdp_frame_size(struct i40e_vsi *vsi)
2645 if (PAGE_SIZE >= 8192 || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
2646 return I40E_RXBUFFER_2048;
2648 return I40E_RXBUFFER_3072;
2652 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
2653 * @netdev: network interface device structure
2654 * @new_mtu: new value for maximum frame size
2656 * Returns 0 on success, negative on failure
2658 static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
2660 struct i40e_netdev_priv *np = netdev_priv(netdev);
2661 struct i40e_vsi *vsi = np->vsi;
2662 struct i40e_pf *pf = vsi->back;
2664 if (i40e_enabled_xdp_vsi(vsi)) {
2665 int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
2667 if (frame_size > i40e_max_xdp_frame_size(vsi))
2671 netdev_dbg(netdev, "changing MTU from %d to %d\n",
2672 netdev->mtu, new_mtu);
2673 netdev->mtu = new_mtu;
2674 if (netif_running(netdev))
2675 i40e_vsi_reinit_locked(vsi);
2676 set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
2677 set_bit(__I40E_CLIENT_L2_CHANGE, pf->state);
2682 * i40e_ioctl - Access the hwtstamp interface
2683 * @netdev: network interface device structure
2684 * @ifr: interface request data
2685 * @cmd: ioctl command
2687 int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2689 struct i40e_netdev_priv *np = netdev_priv(netdev);
2690 struct i40e_pf *pf = np->vsi->back;
2694 return i40e_ptp_get_ts_config(pf, ifr);
2696 return i40e_ptp_set_ts_config(pf, ifr);
2703 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
2704 * @vsi: the vsi being adjusted
2706 void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
2708 struct i40e_vsi_context ctxt;
2711 /* Don't modify stripping options if a port VLAN is active */
2715 if ((vsi->info.valid_sections &
2716 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2717 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
2718 return; /* already enabled */
2720 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2721 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2722 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
2724 ctxt.seid = vsi->seid;
2725 ctxt.info = vsi->info;
2726 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2728 dev_info(&vsi->back->pdev->dev,
2729 "update vlan stripping failed, err %s aq_err %s\n",
2730 i40e_stat_str(&vsi->back->hw, ret),
2731 i40e_aq_str(&vsi->back->hw,
2732 vsi->back->hw.aq.asq_last_status));
2737 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2738 * @vsi: the vsi being adjusted
2740 void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
2742 struct i40e_vsi_context ctxt;
2745 /* Don't modify stripping options if a port VLAN is active */
2749 if ((vsi->info.valid_sections &
2750 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2751 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
2752 I40E_AQ_VSI_PVLAN_EMOD_MASK))
2753 return; /* already disabled */
2755 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2756 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2757 I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
2759 ctxt.seid = vsi->seid;
2760 ctxt.info = vsi->info;
2761 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2763 dev_info(&vsi->back->pdev->dev,
2764 "update vlan stripping failed, err %s aq_err %s\n",
2765 i40e_stat_str(&vsi->back->hw, ret),
2766 i40e_aq_str(&vsi->back->hw,
2767 vsi->back->hw.aq.asq_last_status));
2772 * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address
2773 * @vsi: the vsi being configured
2774 * @vid: vlan id to be added (0 = untagged only , -1 = any)
2776 * This is a helper function for adding a new MAC/VLAN filter with the
2777 * specified VLAN for each existing MAC address already in the hash table.
2778 * This function does *not* perform any accounting to update filters based on
2781 * NOTE: this function expects to be called while under the
2782 * mac_filter_hash_lock
2784 int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
2786 struct i40e_mac_filter *f, *add_f;
2787 struct hlist_node *h;
2790 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
2791 if (f->state == I40E_FILTER_REMOVE)
2793 add_f = i40e_add_filter(vsi, f->macaddr, vid);
2795 dev_info(&vsi->back->pdev->dev,
2796 "Could not add vlan filter %d for %pM\n",
2806 * i40e_vsi_add_vlan - Add VSI membership for given VLAN
2807 * @vsi: the VSI being configured
2808 * @vid: VLAN id to be added
2810 int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid)
2817 /* The network stack will attempt to add VID=0, with the intention to
2818 * receive priority tagged packets with a VLAN of 0. Our HW receives
2819 * these packets by default when configured to receive untagged
2820 * packets, so we don't need to add a filter for this case.
2821 * Additionally, HW interprets adding a VID=0 filter as meaning to
2822 * receive *only* tagged traffic and stops receiving untagged traffic.
2823 * Thus, we do not want to actually add a filter for VID=0
2828 /* Locked once because all functions invoked below iterates list*/
2829 spin_lock_bh(&vsi->mac_filter_hash_lock);
2830 err = i40e_add_vlan_all_mac(vsi, vid);
2831 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2835 /* schedule our worker thread which will take care of
2836 * applying the new filter changes
2838 i40e_service_event_schedule(vsi->back);
2843 * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN
2844 * @vsi: the vsi being configured
2845 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
2847 * This function should be used to remove all VLAN filters which match the
2848 * given VID. It does not schedule the service event and does not take the
2849 * mac_filter_hash_lock so it may be combined with other operations under
2850 * a single invocation of the mac_filter_hash_lock.
2852 * NOTE: this function expects to be called while under the
2853 * mac_filter_hash_lock
2855 void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
2857 struct i40e_mac_filter *f;
2858 struct hlist_node *h;
2861 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
2863 __i40e_del_filter(vsi, f);
2868 * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN
2869 * @vsi: the VSI being configured
2870 * @vid: VLAN id to be removed
2872 void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid)
2874 if (!vid || vsi->info.pvid)
2877 spin_lock_bh(&vsi->mac_filter_hash_lock);
2878 i40e_rm_vlan_all_mac(vsi, vid);
2879 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2881 /* schedule our worker thread which will take care of
2882 * applying the new filter changes
2884 i40e_service_event_schedule(vsi->back);
2888 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2889 * @netdev: network interface to be adjusted
2890 * @proto: unused protocol value
2891 * @vid: vlan id to be added
2893 * net_device_ops implementation for adding vlan ids
2895 static int i40e_vlan_rx_add_vid(struct net_device *netdev,
2896 __always_unused __be16 proto, u16 vid)
2898 struct i40e_netdev_priv *np = netdev_priv(netdev);
2899 struct i40e_vsi *vsi = np->vsi;
2902 if (vid >= VLAN_N_VID)
2905 ret = i40e_vsi_add_vlan(vsi, vid);
2907 set_bit(vid, vsi->active_vlans);
2913 * i40e_vlan_rx_add_vid_up - Add a vlan id filter to HW offload in UP path
2914 * @netdev: network interface to be adjusted
2915 * @proto: unused protocol value
2916 * @vid: vlan id to be added
2918 static void i40e_vlan_rx_add_vid_up(struct net_device *netdev,
2919 __always_unused __be16 proto, u16 vid)
2921 struct i40e_netdev_priv *np = netdev_priv(netdev);
2922 struct i40e_vsi *vsi = np->vsi;
2924 if (vid >= VLAN_N_VID)
2926 set_bit(vid, vsi->active_vlans);
2930 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2931 * @netdev: network interface to be adjusted
2932 * @proto: unused protocol value
2933 * @vid: vlan id to be removed
2935 * net_device_ops implementation for removing vlan ids
2937 static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2938 __always_unused __be16 proto, u16 vid)
2940 struct i40e_netdev_priv *np = netdev_priv(netdev);
2941 struct i40e_vsi *vsi = np->vsi;
2943 /* return code is ignored as there is nothing a user
2944 * can do about failure to remove and a log message was
2945 * already printed from the other function
2947 i40e_vsi_kill_vlan(vsi, vid);
2949 clear_bit(vid, vsi->active_vlans);
2955 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2956 * @vsi: the vsi being brought back up
2958 static void i40e_restore_vlan(struct i40e_vsi *vsi)
2965 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
2966 i40e_vlan_stripping_enable(vsi);
2968 i40e_vlan_stripping_disable(vsi);
2970 for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
2971 i40e_vlan_rx_add_vid_up(vsi->netdev, htons(ETH_P_8021Q),
2976 * i40e_vsi_add_pvid - Add pvid for the VSI
2977 * @vsi: the vsi being adjusted
2978 * @vid: the vlan id to set as a PVID
2980 int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
2982 struct i40e_vsi_context ctxt;
2985 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2986 vsi->info.pvid = cpu_to_le16(vid);
2987 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
2988 I40E_AQ_VSI_PVLAN_INSERT_PVID |
2989 I40E_AQ_VSI_PVLAN_EMOD_STR;
2991 ctxt.seid = vsi->seid;
2992 ctxt.info = vsi->info;
2993 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2995 dev_info(&vsi->back->pdev->dev,
2996 "add pvid failed, err %s aq_err %s\n",
2997 i40e_stat_str(&vsi->back->hw, ret),
2998 i40e_aq_str(&vsi->back->hw,
2999 vsi->back->hw.aq.asq_last_status));
3007 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
3008 * @vsi: the vsi being adjusted
3010 * Just use the vlan_rx_register() service to put it back to normal
3012 void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
3016 i40e_vlan_stripping_disable(vsi);
3020 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
3021 * @vsi: ptr to the VSI
3023 * If this function returns with an error, then it's possible one or
3024 * more of the rings is populated (while the rest are not). It is the
3025 * callers duty to clean those orphaned rings.
3027 * Return 0 on success, negative on failure
3029 static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
3033 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
3034 err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
3036 if (!i40e_enabled_xdp_vsi(vsi))
3039 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
3040 err = i40e_setup_tx_descriptors(vsi->xdp_rings[i]);
3046 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
3047 * @vsi: ptr to the VSI
3049 * Free VSI's transmit software resources
3051 static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
3055 if (vsi->tx_rings) {
3056 for (i = 0; i < vsi->num_queue_pairs; i++)
3057 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
3058 i40e_free_tx_resources(vsi->tx_rings[i]);
3061 if (vsi->xdp_rings) {
3062 for (i = 0; i < vsi->num_queue_pairs; i++)
3063 if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc)
3064 i40e_free_tx_resources(vsi->xdp_rings[i]);
3069 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
3070 * @vsi: ptr to the VSI
3072 * If this function returns with an error, then it's possible one or
3073 * more of the rings is populated (while the rest are not). It is the
3074 * callers duty to clean those orphaned rings.
3076 * Return 0 on success, negative on failure
3078 static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
3082 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
3083 err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
3088 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
3089 * @vsi: ptr to the VSI
3091 * Free all receive software resources
3093 static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
3100 for (i = 0; i < vsi->num_queue_pairs; i++)
3101 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
3102 i40e_free_rx_resources(vsi->rx_rings[i]);
3106 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
3107 * @ring: The Tx ring to configure
3109 * This enables/disables XPS for a given Tx descriptor ring
3110 * based on the TCs enabled for the VSI that ring belongs to.
3112 static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
3116 if (!ring->q_vector || !ring->netdev || ring->ch)
3119 /* We only initialize XPS once, so as not to overwrite user settings */
3120 if (test_and_set_bit(__I40E_TX_XPS_INIT_DONE, ring->state))
3123 cpu = cpumask_local_spread(ring->q_vector->v_idx, -1);
3124 netif_set_xps_queue(ring->netdev, get_cpu_mask(cpu),
3129 * i40e_xsk_pool - Retrieve the AF_XDP buffer pool if XDP and ZC is enabled
3130 * @ring: The Tx or Rx ring
3132 * Returns the AF_XDP buffer pool or NULL.
3134 static struct xsk_buff_pool *i40e_xsk_pool(struct i40e_ring *ring)
3136 bool xdp_on = i40e_enabled_xdp_vsi(ring->vsi);
3137 int qid = ring->queue_index;
3139 if (ring_is_xdp(ring))
3140 qid -= ring->vsi->alloc_queue_pairs;
3142 if (!xdp_on || !test_bit(qid, ring->vsi->af_xdp_zc_qps))
3145 return xsk_get_pool_from_qid(ring->vsi->netdev, qid);
3149 * i40e_configure_tx_ring - Configure a transmit ring context and rest
3150 * @ring: The Tx ring to configure
3152 * Configure the Tx descriptor ring in the HMC context.
3154 static int i40e_configure_tx_ring(struct i40e_ring *ring)
3156 struct i40e_vsi *vsi = ring->vsi;
3157 u16 pf_q = vsi->base_queue + ring->queue_index;
3158 struct i40e_hw *hw = &vsi->back->hw;
3159 struct i40e_hmc_obj_txq tx_ctx;
3160 i40e_status err = 0;
3163 if (ring_is_xdp(ring))
3164 ring->xsk_pool = i40e_xsk_pool(ring);
3166 /* some ATR related tx ring init */
3167 if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
3168 ring->atr_sample_rate = vsi->back->atr_sample_rate;
3169 ring->atr_count = 0;
3171 ring->atr_sample_rate = 0;
3175 i40e_config_xps_tx_ring(ring);
3177 /* clear the context structure first */
3178 memset(&tx_ctx, 0, sizeof(tx_ctx));
3180 tx_ctx.new_context = 1;
3181 tx_ctx.base = (ring->dma / 128);
3182 tx_ctx.qlen = ring->count;
3183 tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
3184 I40E_FLAG_FD_ATR_ENABLED));
3185 tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
3186 /* FDIR VSI tx ring can still use RS bit and writebacks */
3187 if (vsi->type != I40E_VSI_FDIR)
3188 tx_ctx.head_wb_ena = 1;
3189 tx_ctx.head_wb_addr = ring->dma +
3190 (ring->count * sizeof(struct i40e_tx_desc));
3192 /* As part of VSI creation/update, FW allocates certain
3193 * Tx arbitration queue sets for each TC enabled for
3194 * the VSI. The FW returns the handles to these queue
3195 * sets as part of the response buffer to Add VSI,
3196 * Update VSI, etc. AQ commands. It is expected that
3197 * these queue set handles be associated with the Tx
3198 * queues by the driver as part of the TX queue context
3199 * initialization. This has to be done regardless of
3200 * DCB as by default everything is mapped to TC0.
3205 le16_to_cpu(ring->ch->info.qs_handle[ring->dcb_tc]);
3208 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
3210 tx_ctx.rdylist_act = 0;
3212 /* clear the context in the HMC */
3213 err = i40e_clear_lan_tx_queue_context(hw, pf_q);
3215 dev_info(&vsi->back->pdev->dev,
3216 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
3217 ring->queue_index, pf_q, err);
3221 /* set the context in the HMC */
3222 err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
3224 dev_info(&vsi->back->pdev->dev,
3225 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
3226 ring->queue_index, pf_q, err);
3230 /* Now associate this queue with this PCI function */
3232 if (ring->ch->type == I40E_VSI_VMDQ2)
3233 qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
3237 qtx_ctl |= (ring->ch->vsi_number <<
3238 I40E_QTX_CTL_VFVM_INDX_SHIFT) &
3239 I40E_QTX_CTL_VFVM_INDX_MASK;
3241 if (vsi->type == I40E_VSI_VMDQ2) {
3242 qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
3243 qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
3244 I40E_QTX_CTL_VFVM_INDX_MASK;
3246 qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
3250 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
3251 I40E_QTX_CTL_PF_INDX_MASK);
3252 wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
3255 /* cache tail off for easier writes later */
3256 ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
3262 * i40e_rx_offset - Return expected offset into page to access data
3263 * @rx_ring: Ring we are requesting offset of
3265 * Returns the offset value for ring into the data buffer.
3267 static unsigned int i40e_rx_offset(struct i40e_ring *rx_ring)
3269 return ring_uses_build_skb(rx_ring) ? I40E_SKB_PAD : 0;
3273 * i40e_configure_rx_ring - Configure a receive ring context
3274 * @ring: The Rx ring to configure
3276 * Configure the Rx descriptor ring in the HMC context.
3278 static int i40e_configure_rx_ring(struct i40e_ring *ring)
3280 struct i40e_vsi *vsi = ring->vsi;
3281 u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
3282 u16 pf_q = vsi->base_queue + ring->queue_index;
3283 struct i40e_hw *hw = &vsi->back->hw;
3284 struct i40e_hmc_obj_rxq rx_ctx;
3285 i40e_status err = 0;
3289 bitmap_zero(ring->state, __I40E_RING_STATE_NBITS);
3291 /* clear the context structure first */
3292 memset(&rx_ctx, 0, sizeof(rx_ctx));
3294 if (ring->vsi->type == I40E_VSI_MAIN)
3295 xdp_rxq_info_unreg_mem_model(&ring->xdp_rxq);
3298 ring->xsk_pool = i40e_xsk_pool(ring);
3299 if (ring->xsk_pool) {
3300 ret = i40e_alloc_rx_bi_zc(ring);
3304 xsk_pool_get_rx_frame_size(ring->xsk_pool);
3305 /* For AF_XDP ZC, we disallow packets to span on
3306 * multiple buffers, thus letting us skip that
3307 * handling in the fast-path.
3310 ret = xdp_rxq_info_reg_mem_model(&ring->xdp_rxq,
3311 MEM_TYPE_XSK_BUFF_POOL,
3315 dev_info(&vsi->back->pdev->dev,
3316 "Registered XDP mem model MEM_TYPE_XSK_BUFF_POOL on Rx ring %d\n",
3320 ret = i40e_alloc_rx_bi(ring);
3323 ring->rx_buf_len = vsi->rx_buf_len;
3324 if (ring->vsi->type == I40E_VSI_MAIN) {
3325 ret = xdp_rxq_info_reg_mem_model(&ring->xdp_rxq,
3326 MEM_TYPE_PAGE_SHARED,
3333 rx_ctx.dbuff = DIV_ROUND_UP(ring->rx_buf_len,
3334 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
3336 rx_ctx.base = (ring->dma / 128);
3337 rx_ctx.qlen = ring->count;
3339 /* use 16 byte descriptors */
3342 /* descriptor type is always zero
3345 rx_ctx.hsplit_0 = 0;
3347 rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len);
3348 if (hw->revision_id == 0)
3349 rx_ctx.lrxqthresh = 0;
3351 rx_ctx.lrxqthresh = 1;
3352 rx_ctx.crcstrip = 1;
3354 /* this controls whether VLAN is stripped from inner headers */
3356 /* set the prefena field to 1 because the manual says to */
3359 /* clear the context in the HMC */
3360 err = i40e_clear_lan_rx_queue_context(hw, pf_q);
3362 dev_info(&vsi->back->pdev->dev,
3363 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
3364 ring->queue_index, pf_q, err);
3368 /* set the context in the HMC */
3369 err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
3371 dev_info(&vsi->back->pdev->dev,
3372 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
3373 ring->queue_index, pf_q, err);
3377 /* configure Rx buffer alignment */
3378 if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
3379 clear_ring_build_skb_enabled(ring);
3381 set_ring_build_skb_enabled(ring);
3383 ring->rx_offset = i40e_rx_offset(ring);
3385 /* cache tail for quicker writes, and clear the reg before use */
3386 ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
3387 writel(0, ring->tail);
3389 if (ring->xsk_pool) {
3390 xsk_pool_set_rxq_info(ring->xsk_pool, &ring->xdp_rxq);
3391 ok = i40e_alloc_rx_buffers_zc(ring, I40E_DESC_UNUSED(ring));
3393 ok = !i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
3396 /* Log this in case the user has forgotten to give the kernel
3397 * any buffers, even later in the application.
3399 dev_info(&vsi->back->pdev->dev,
3400 "Failed to allocate some buffers on %sRx ring %d (pf_q %d)\n",
3401 ring->xsk_pool ? "AF_XDP ZC enabled " : "",
3402 ring->queue_index, pf_q);
3409 * i40e_vsi_configure_tx - Configure the VSI for Tx
3410 * @vsi: VSI structure describing this set of rings and resources
3412 * Configure the Tx VSI for operation.
3414 static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
3419 for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
3420 err = i40e_configure_tx_ring(vsi->tx_rings[i]);
3422 if (err || !i40e_enabled_xdp_vsi(vsi))
3425 for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
3426 err = i40e_configure_tx_ring(vsi->xdp_rings[i]);
3432 * i40e_vsi_configure_rx - Configure the VSI for Rx
3433 * @vsi: the VSI being configured
3435 * Configure the Rx VSI for operation.
3437 static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
3442 if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) {
3443 vsi->max_frame = I40E_MAX_RXBUFFER;
3444 vsi->rx_buf_len = I40E_RXBUFFER_2048;
3445 #if (PAGE_SIZE < 8192)
3446 } else if (!I40E_2K_TOO_SMALL_WITH_PADDING &&
3447 (vsi->netdev->mtu <= ETH_DATA_LEN)) {
3448 vsi->max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
3449 vsi->rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
3452 vsi->max_frame = I40E_MAX_RXBUFFER;
3453 vsi->rx_buf_len = (PAGE_SIZE < 8192) ? I40E_RXBUFFER_3072 :
3457 /* set up individual rings */
3458 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
3459 err = i40e_configure_rx_ring(vsi->rx_rings[i]);
3465 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
3466 * @vsi: ptr to the VSI
3468 static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
3470 struct i40e_ring *tx_ring, *rx_ring;
3471 u16 qoffset, qcount;
3474 if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
3475 /* Reset the TC information */
3476 for (i = 0; i < vsi->num_queue_pairs; i++) {
3477 rx_ring = vsi->rx_rings[i];
3478 tx_ring = vsi->tx_rings[i];
3479 rx_ring->dcb_tc = 0;
3480 tx_ring->dcb_tc = 0;
3485 for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
3486 if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
3489 qoffset = vsi->tc_config.tc_info[n].qoffset;
3490 qcount = vsi->tc_config.tc_info[n].qcount;
3491 for (i = qoffset; i < (qoffset + qcount); i++) {
3492 rx_ring = vsi->rx_rings[i];
3493 tx_ring = vsi->tx_rings[i];
3494 rx_ring->dcb_tc = n;
3495 tx_ring->dcb_tc = n;
3501 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
3502 * @vsi: ptr to the VSI
3504 static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
3507 i40e_set_rx_mode(vsi->netdev);
3511 * i40e_reset_fdir_filter_cnt - Reset flow director filter counters
3512 * @pf: Pointer to the targeted PF
3514 * Set all flow director counters to 0.
3516 static void i40e_reset_fdir_filter_cnt(struct i40e_pf *pf)
3518 pf->fd_tcp4_filter_cnt = 0;
3519 pf->fd_udp4_filter_cnt = 0;
3520 pf->fd_sctp4_filter_cnt = 0;
3521 pf->fd_ip4_filter_cnt = 0;
3522 pf->fd_tcp6_filter_cnt = 0;
3523 pf->fd_udp6_filter_cnt = 0;
3524 pf->fd_sctp6_filter_cnt = 0;
3525 pf->fd_ip6_filter_cnt = 0;
3529 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
3530 * @vsi: Pointer to the targeted VSI
3532 * This function replays the hlist on the hw where all the SB Flow Director
3533 * filters were saved.
3535 static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
3537 struct i40e_fdir_filter *filter;
3538 struct i40e_pf *pf = vsi->back;
3539 struct hlist_node *node;
3541 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3544 /* Reset FDir counters as we're replaying all existing filters */
3545 i40e_reset_fdir_filter_cnt(pf);
3547 hlist_for_each_entry_safe(filter, node,
3548 &pf->fdir_filter_list, fdir_node) {
3549 i40e_add_del_fdir(vsi, filter, true);
3554 * i40e_vsi_configure - Set up the VSI for action
3555 * @vsi: the VSI being configured
3557 static int i40e_vsi_configure(struct i40e_vsi *vsi)
3561 i40e_set_vsi_rx_mode(vsi);
3562 i40e_restore_vlan(vsi);
3563 i40e_vsi_config_dcb_rings(vsi);
3564 err = i40e_vsi_configure_tx(vsi);
3566 err = i40e_vsi_configure_rx(vsi);
3572 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
3573 * @vsi: the VSI being configured
3575 static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
3577 bool has_xdp = i40e_enabled_xdp_vsi(vsi);
3578 struct i40e_pf *pf = vsi->back;
3579 struct i40e_hw *hw = &pf->hw;
3584 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
3585 * and PFINT_LNKLSTn registers, e.g.:
3586 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
3588 qp = vsi->base_queue;
3589 vector = vsi->base_vector;
3590 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
3591 struct i40e_q_vector *q_vector = vsi->q_vectors[i];
3593 q_vector->rx.next_update = jiffies + 1;
3594 q_vector->rx.target_itr =
3595 ITR_TO_REG(vsi->rx_rings[i]->itr_setting);
3596 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
3597 q_vector->rx.target_itr >> 1);
3598 q_vector->rx.current_itr = q_vector->rx.target_itr;
3600 q_vector->tx.next_update = jiffies + 1;
3601 q_vector->tx.target_itr =
3602 ITR_TO_REG(vsi->tx_rings[i]->itr_setting);
3603 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
3604 q_vector->tx.target_itr >> 1);
3605 q_vector->tx.current_itr = q_vector->tx.target_itr;
3607 wr32(hw, I40E_PFINT_RATEN(vector - 1),
3608 i40e_intrl_usec_to_reg(vsi->int_rate_limit));
3610 /* Linked list for the queuepairs assigned to this vector */
3611 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
3612 for (q = 0; q < q_vector->num_ringpairs; q++) {
3613 u32 nextqp = has_xdp ? qp + vsi->alloc_queue_pairs : qp;
3616 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3617 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3618 (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
3619 (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
3620 (I40E_QUEUE_TYPE_TX <<
3621 I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
3623 wr32(hw, I40E_QINT_RQCTL(qp), val);
3626 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3627 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3628 (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
3629 (qp << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
3630 (I40E_QUEUE_TYPE_TX <<
3631 I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3633 wr32(hw, I40E_QINT_TQCTL(nextqp), val);
3636 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3637 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3638 (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
3639 ((qp + 1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
3640 (I40E_QUEUE_TYPE_RX <<
3641 I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3643 /* Terminate the linked list */
3644 if (q == (q_vector->num_ringpairs - 1))
3645 val |= (I40E_QUEUE_END_OF_LIST <<
3646 I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3648 wr32(hw, I40E_QINT_TQCTL(qp), val);
3657 * i40e_enable_misc_int_causes - enable the non-queue interrupts
3658 * @pf: pointer to private device data structure
3660 static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
3662 struct i40e_hw *hw = &pf->hw;
3665 /* clear things first */
3666 wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
3667 rd32(hw, I40E_PFINT_ICR0); /* read to clear */
3669 val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
3670 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
3671 I40E_PFINT_ICR0_ENA_GRST_MASK |
3672 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
3673 I40E_PFINT_ICR0_ENA_GPIO_MASK |
3674 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
3675 I40E_PFINT_ICR0_ENA_VFLR_MASK |
3676 I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
3678 if (pf->flags & I40E_FLAG_IWARP_ENABLED)
3679 val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3681 if (pf->flags & I40E_FLAG_PTP)
3682 val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
3684 wr32(hw, I40E_PFINT_ICR0_ENA, val);
3686 /* SW_ITR_IDX = 0, but don't change INTENA */
3687 wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
3688 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
3690 /* OTHER_ITR_IDX = 0 */
3691 wr32(hw, I40E_PFINT_STAT_CTL0, 0);
3695 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
3696 * @vsi: the VSI being configured
3698 static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
3700 u32 nextqp = i40e_enabled_xdp_vsi(vsi) ? vsi->alloc_queue_pairs : 0;
3701 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
3702 struct i40e_pf *pf = vsi->back;
3703 struct i40e_hw *hw = &pf->hw;
3706 /* set the ITR configuration */
3707 q_vector->rx.next_update = jiffies + 1;
3708 q_vector->rx.target_itr = ITR_TO_REG(vsi->rx_rings[0]->itr_setting);
3709 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.target_itr >> 1);
3710 q_vector->rx.current_itr = q_vector->rx.target_itr;
3711 q_vector->tx.next_update = jiffies + 1;
3712 q_vector->tx.target_itr = ITR_TO_REG(vsi->tx_rings[0]->itr_setting);
3713 wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.target_itr >> 1);
3714 q_vector->tx.current_itr = q_vector->tx.target_itr;
3716 i40e_enable_misc_int_causes(pf);
3718 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
3719 wr32(hw, I40E_PFINT_LNKLST0, 0);
3721 /* Associate the queue pair to the vector and enable the queue int */
3722 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3723 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3724 (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
3725 (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3727 wr32(hw, I40E_QINT_RQCTL(0), val);
3729 if (i40e_enabled_xdp_vsi(vsi)) {
3730 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3731 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT)|
3733 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3735 wr32(hw, I40E_QINT_TQCTL(nextqp), val);
3738 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3739 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3740 (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3742 wr32(hw, I40E_QINT_TQCTL(0), val);
3747 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
3748 * @pf: board private structure
3750 void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
3752 struct i40e_hw *hw = &pf->hw;
3754 wr32(hw, I40E_PFINT_DYN_CTL0,
3755 I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
3760 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
3761 * @pf: board private structure
3763 void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf)
3765 struct i40e_hw *hw = &pf->hw;
3768 val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
3769 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
3770 (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
3772 wr32(hw, I40E_PFINT_DYN_CTL0, val);
3777 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
3778 * @irq: interrupt number
3779 * @data: pointer to a q_vector
3781 static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
3783 struct i40e_q_vector *q_vector = data;
3785 if (!q_vector->tx.ring && !q_vector->rx.ring)
3788 napi_schedule_irqoff(&q_vector->napi);
3794 * i40e_irq_affinity_notify - Callback for affinity changes
3795 * @notify: context as to what irq was changed
3796 * @mask: the new affinity mask
3798 * This is a callback function used by the irq_set_affinity_notifier function
3799 * so that we may register to receive changes to the irq affinity masks.
3801 static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify,
3802 const cpumask_t *mask)
3804 struct i40e_q_vector *q_vector =
3805 container_of(notify, struct i40e_q_vector, affinity_notify);
3807 cpumask_copy(&q_vector->affinity_mask, mask);
3811 * i40e_irq_affinity_release - Callback for affinity notifier release
3812 * @ref: internal core kernel usage
3814 * This is a callback function used by the irq_set_affinity_notifier function
3815 * to inform the current notification subscriber that they will no longer
3816 * receive notifications.
3818 static void i40e_irq_affinity_release(struct kref *ref) {}
3821 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3822 * @vsi: the VSI being configured
3823 * @basename: name for the vector
3825 * Allocates MSI-X vectors and requests interrupts from the kernel.
3827 static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
3829 int q_vectors = vsi->num_q_vectors;
3830 struct i40e_pf *pf = vsi->back;
3831 int base = vsi->base_vector;
3838 for (vector = 0; vector < q_vectors; vector++) {
3839 struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
3841 irq_num = pf->msix_entries[base + vector].vector;
3843 if (q_vector->tx.ring && q_vector->rx.ring) {
3844 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3845 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
3847 } else if (q_vector->rx.ring) {
3848 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3849 "%s-%s-%d", basename, "rx", rx_int_idx++);
3850 } else if (q_vector->tx.ring) {
3851 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3852 "%s-%s-%d", basename, "tx", tx_int_idx++);
3854 /* skip this unused q_vector */
3857 err = request_irq(irq_num,
3863 dev_info(&pf->pdev->dev,
3864 "MSIX request_irq failed, error: %d\n", err);
3865 goto free_queue_irqs;
3868 /* register for affinity change notifications */
3869 q_vector->affinity_notify.notify = i40e_irq_affinity_notify;
3870 q_vector->affinity_notify.release = i40e_irq_affinity_release;
3871 irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
3872 /* Spread affinity hints out across online CPUs.
3874 * get_cpu_mask returns a static constant mask with
3875 * a permanent lifetime so it's ok to pass to
3876 * irq_set_affinity_hint without making a copy.
3878 cpu = cpumask_local_spread(q_vector->v_idx, -1);
3879 irq_set_affinity_hint(irq_num, get_cpu_mask(cpu));
3882 vsi->irqs_ready = true;
3888 irq_num = pf->msix_entries[base + vector].vector;
3889 irq_set_affinity_notifier(irq_num, NULL);
3890 irq_set_affinity_hint(irq_num, NULL);
3891 free_irq(irq_num, &vsi->q_vectors[vector]);
3897 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3898 * @vsi: the VSI being un-configured
3900 static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
3902 struct i40e_pf *pf = vsi->back;
3903 struct i40e_hw *hw = &pf->hw;
3904 int base = vsi->base_vector;
3907 /* disable interrupt causation from each queue */
3908 for (i = 0; i < vsi->num_queue_pairs; i++) {
3911 val = rd32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx));
3912 val &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
3913 wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), val);
3915 val = rd32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx));
3916 val &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
3917 wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), val);
3919 if (!i40e_enabled_xdp_vsi(vsi))
3921 wr32(hw, I40E_QINT_TQCTL(vsi->xdp_rings[i]->reg_idx), 0);
3924 /* disable each interrupt */
3925 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3926 for (i = vsi->base_vector;
3927 i < (vsi->num_q_vectors + vsi->base_vector); i++)
3928 wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
3931 for (i = 0; i < vsi->num_q_vectors; i++)
3932 synchronize_irq(pf->msix_entries[i + base].vector);
3934 /* Legacy and MSI mode - this stops all interrupt handling */
3935 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
3936 wr32(hw, I40E_PFINT_DYN_CTL0, 0);
3938 synchronize_irq(pf->pdev->irq);
3943 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3944 * @vsi: the VSI being configured
3946 static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
3948 struct i40e_pf *pf = vsi->back;
3951 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3952 for (i = 0; i < vsi->num_q_vectors; i++)
3953 i40e_irq_dynamic_enable(vsi, i);
3955 i40e_irq_dynamic_enable_icr0(pf);
3958 i40e_flush(&pf->hw);
3963 * i40e_free_misc_vector - Free the vector that handles non-queue events
3964 * @pf: board private structure
3966 static void i40e_free_misc_vector(struct i40e_pf *pf)
3969 wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
3970 i40e_flush(&pf->hw);
3972 if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
3973 synchronize_irq(pf->msix_entries[0].vector);
3974 free_irq(pf->msix_entries[0].vector, pf);
3975 clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state);
3980 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3981 * @irq: interrupt number
3982 * @data: pointer to a q_vector
3984 * This is the handler used for all MSI/Legacy interrupts, and deals
3985 * with both queue and non-queue interrupts. This is also used in
3986 * MSIX mode to handle the non-queue interrupts.
3988 static irqreturn_t i40e_intr(int irq, void *data)
3990 struct i40e_pf *pf = (struct i40e_pf *)data;
3991 struct i40e_hw *hw = &pf->hw;
3992 irqreturn_t ret = IRQ_NONE;
3993 u32 icr0, icr0_remaining;
3996 icr0 = rd32(hw, I40E_PFINT_ICR0);
3997 ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
3999 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
4000 if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
4003 /* if interrupt but no bits showing, must be SWINT */
4004 if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
4005 (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
4008 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
4009 (icr0 & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
4010 ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
4011 dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n");
4012 set_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
4015 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
4016 if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
4017 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
4018 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
4020 /* We do not have a way to disarm Queue causes while leaving
4021 * interrupt enabled for all other causes, ideally
4022 * interrupt should be disabled while we are in NAPI but
4023 * this is not a performance path and napi_schedule()
4024 * can deal with rescheduling.
4026 if (!test_bit(__I40E_DOWN, pf->state))
4027 napi_schedule_irqoff(&q_vector->napi);
4030 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
4031 ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
4032 set_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
4033 i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
4036 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
4037 ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
4038 set_bit(__I40E_MDD_EVENT_PENDING, pf->state);
4041 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
4042 /* disable any further VFLR event notifications */
4043 if (test_bit(__I40E_VF_RESETS_DISABLED, pf->state)) {
4044 u32 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
4046 reg &= ~I40E_PFINT_ICR0_VFLR_MASK;
4047 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
4049 ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
4050 set_bit(__I40E_VFLR_EVENT_PENDING, pf->state);
4054 if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
4055 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
4056 set_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
4057 ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
4058 val = rd32(hw, I40E_GLGEN_RSTAT);
4059 val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
4060 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
4061 if (val == I40E_RESET_CORER) {
4063 } else if (val == I40E_RESET_GLOBR) {
4065 } else if (val == I40E_RESET_EMPR) {
4067 set_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state);
4071 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
4072 icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
4073 dev_info(&pf->pdev->dev, "HMC error interrupt\n");
4074 dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
4075 rd32(hw, I40E_PFHMC_ERRORINFO),
4076 rd32(hw, I40E_PFHMC_ERRORDATA));
4079 if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
4080 u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
4082 if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
4083 icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
4084 i40e_ptp_tx_hwtstamp(pf);
4088 /* If a critical error is pending we have no choice but to reset the
4090 * Report and mask out any remaining unexpected interrupts.
4092 icr0_remaining = icr0 & ena_mask;
4093 if (icr0_remaining) {
4094 dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
4096 if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
4097 (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
4098 (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
4099 dev_info(&pf->pdev->dev, "device will be reset\n");
4100 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
4101 i40e_service_event_schedule(pf);
4103 ena_mask &= ~icr0_remaining;
4108 /* re-enable interrupt causes */
4109 wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
4110 if (!test_bit(__I40E_DOWN, pf->state) ||
4111 test_bit(__I40E_RECOVERY_MODE, pf->state)) {
4112 i40e_service_event_schedule(pf);
4113 i40e_irq_dynamic_enable_icr0(pf);
4120 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
4121 * @tx_ring: tx ring to clean
4122 * @budget: how many cleans we're allowed
4124 * Returns true if there's any budget left (e.g. the clean is finished)
4126 static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
4128 struct i40e_vsi *vsi = tx_ring->vsi;
4129 u16 i = tx_ring->next_to_clean;
4130 struct i40e_tx_buffer *tx_buf;
4131 struct i40e_tx_desc *tx_desc;
4133 tx_buf = &tx_ring->tx_bi[i];
4134 tx_desc = I40E_TX_DESC(tx_ring, i);
4135 i -= tx_ring->count;
4138 struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
4140 /* if next_to_watch is not set then there is no work pending */
4144 /* prevent any other reads prior to eop_desc */
4147 /* if the descriptor isn't done, no work yet to do */
4148 if (!(eop_desc->cmd_type_offset_bsz &
4149 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
4152 /* clear next_to_watch to prevent false hangs */
4153 tx_buf->next_to_watch = NULL;
4155 tx_desc->buffer_addr = 0;
4156 tx_desc->cmd_type_offset_bsz = 0;
4157 /* move past filter desc */
4162 i -= tx_ring->count;
4163 tx_buf = tx_ring->tx_bi;
4164 tx_desc = I40E_TX_DESC(tx_ring, 0);
4166 /* unmap skb header data */
4167 dma_unmap_single(tx_ring->dev,
4168 dma_unmap_addr(tx_buf, dma),
4169 dma_unmap_len(tx_buf, len),
4171 if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
4172 kfree(tx_buf->raw_buf);
4174 tx_buf->raw_buf = NULL;
4175 tx_buf->tx_flags = 0;
4176 tx_buf->next_to_watch = NULL;
4177 dma_unmap_len_set(tx_buf, len, 0);
4178 tx_desc->buffer_addr = 0;
4179 tx_desc->cmd_type_offset_bsz = 0;
4181 /* move us past the eop_desc for start of next FD desc */
4186 i -= tx_ring->count;
4187 tx_buf = tx_ring->tx_bi;
4188 tx_desc = I40E_TX_DESC(tx_ring, 0);
4191 /* update budget accounting */
4193 } while (likely(budget));
4195 i += tx_ring->count;
4196 tx_ring->next_to_clean = i;
4198 if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
4199 i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
4205 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
4206 * @irq: interrupt number
4207 * @data: pointer to a q_vector
4209 static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
4211 struct i40e_q_vector *q_vector = data;
4212 struct i40e_vsi *vsi;
4214 if (!q_vector->tx.ring)
4217 vsi = q_vector->tx.ring->vsi;
4218 i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
4224 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
4225 * @vsi: the VSI being configured
4226 * @v_idx: vector index
4227 * @qp_idx: queue pair index
4229 static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
4231 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
4232 struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
4233 struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
4235 tx_ring->q_vector = q_vector;
4236 tx_ring->next = q_vector->tx.ring;
4237 q_vector->tx.ring = tx_ring;
4238 q_vector->tx.count++;
4240 /* Place XDP Tx ring in the same q_vector ring list as regular Tx */
4241 if (i40e_enabled_xdp_vsi(vsi)) {
4242 struct i40e_ring *xdp_ring = vsi->xdp_rings[qp_idx];
4244 xdp_ring->q_vector = q_vector;
4245 xdp_ring->next = q_vector->tx.ring;
4246 q_vector->tx.ring = xdp_ring;
4247 q_vector->tx.count++;
4250 rx_ring->q_vector = q_vector;
4251 rx_ring->next = q_vector->rx.ring;
4252 q_vector->rx.ring = rx_ring;
4253 q_vector->rx.count++;
4257 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
4258 * @vsi: the VSI being configured
4260 * This function maps descriptor rings to the queue-specific vectors
4261 * we were allotted through the MSI-X enabling code. Ideally, we'd have
4262 * one vector per queue pair, but on a constrained vector budget, we
4263 * group the queue pairs as "efficiently" as possible.
4265 static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
4267 int qp_remaining = vsi->num_queue_pairs;
4268 int q_vectors = vsi->num_q_vectors;
4273 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
4274 * group them so there are multiple queues per vector.
4275 * It is also important to go through all the vectors available to be
4276 * sure that if we don't use all the vectors, that the remaining vectors
4277 * are cleared. This is especially important when decreasing the
4278 * number of queues in use.
4280 for (; v_start < q_vectors; v_start++) {
4281 struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
4283 num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
4285 q_vector->num_ringpairs = num_ringpairs;
4286 q_vector->reg_idx = q_vector->v_idx + vsi->base_vector - 1;
4288 q_vector->rx.count = 0;
4289 q_vector->tx.count = 0;
4290 q_vector->rx.ring = NULL;
4291 q_vector->tx.ring = NULL;
4293 while (num_ringpairs--) {
4294 i40e_map_vector_to_qp(vsi, v_start, qp_idx);
4302 * i40e_vsi_request_irq - Request IRQ from the OS
4303 * @vsi: the VSI being configured
4304 * @basename: name for the vector
4306 static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
4308 struct i40e_pf *pf = vsi->back;
4311 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
4312 err = i40e_vsi_request_irq_msix(vsi, basename);
4313 else if (pf->flags & I40E_FLAG_MSI_ENABLED)
4314 err = request_irq(pf->pdev->irq, i40e_intr, 0,
4317 err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
4321 dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
4326 #ifdef CONFIG_NET_POLL_CONTROLLER
4328 * i40e_netpoll - A Polling 'interrupt' handler
4329 * @netdev: network interface device structure
4331 * This is used by netconsole to send skbs without having to re-enable
4332 * interrupts. It's not called while the normal interrupt routine is executing.
4334 static void i40e_netpoll(struct net_device *netdev)
4336 struct i40e_netdev_priv *np = netdev_priv(netdev);
4337 struct i40e_vsi *vsi = np->vsi;
4338 struct i40e_pf *pf = vsi->back;
4341 /* if interface is down do nothing */
4342 if (test_bit(__I40E_VSI_DOWN, vsi->state))
4345 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4346 for (i = 0; i < vsi->num_q_vectors; i++)
4347 i40e_msix_clean_rings(0, vsi->q_vectors[i]);
4349 i40e_intr(pf->pdev->irq, netdev);
4354 #define I40E_QTX_ENA_WAIT_COUNT 50
4357 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
4358 * @pf: the PF being configured
4359 * @pf_q: the PF queue
4360 * @enable: enable or disable state of the queue
4362 * This routine will wait for the given Tx queue of the PF to reach the
4363 * enabled or disabled state.
4364 * Returns -ETIMEDOUT in case of failing to reach the requested state after
4365 * multiple retries; else will return 0 in case of success.
4367 static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
4372 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
4373 tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
4374 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
4377 usleep_range(10, 20);
4379 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
4386 * i40e_control_tx_q - Start or stop a particular Tx queue
4387 * @pf: the PF structure
4388 * @pf_q: the PF queue to configure
4389 * @enable: start or stop the queue
4391 * This function enables or disables a single queue. Note that any delay
4392 * required after the operation is expected to be handled by the caller of
4395 static void i40e_control_tx_q(struct i40e_pf *pf, int pf_q, bool enable)
4397 struct i40e_hw *hw = &pf->hw;
4401 /* warn the TX unit of coming changes */
4402 i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
4404 usleep_range(10, 20);
4406 for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
4407 tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
4408 if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
4409 ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
4411 usleep_range(1000, 2000);
4414 /* Skip if the queue is already in the requested state */
4415 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
4418 /* turn on/off the queue */
4420 wr32(hw, I40E_QTX_HEAD(pf_q), 0);
4421 tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
4423 tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
4426 wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
4430 * i40e_control_wait_tx_q - Start/stop Tx queue and wait for completion
4432 * @pf: the PF structure
4433 * @pf_q: the PF queue to configure
4434 * @is_xdp: true if the queue is used for XDP
4435 * @enable: start or stop the queue
4437 int i40e_control_wait_tx_q(int seid, struct i40e_pf *pf, int pf_q,
4438 bool is_xdp, bool enable)
4442 i40e_control_tx_q(pf, pf_q, enable);
4444 /* wait for the change to finish */
4445 ret = i40e_pf_txq_wait(pf, pf_q, enable);
4447 dev_info(&pf->pdev->dev,
4448 "VSI seid %d %sTx ring %d %sable timeout\n",
4449 seid, (is_xdp ? "XDP " : ""), pf_q,
4450 (enable ? "en" : "dis"));
4457 * i40e_vsi_control_tx - Start or stop a VSI's rings
4458 * @vsi: the VSI being configured
4459 * @enable: start or stop the rings
4461 static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
4463 struct i40e_pf *pf = vsi->back;
4464 int i, pf_q, ret = 0;
4466 pf_q = vsi->base_queue;
4467 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
4468 ret = i40e_control_wait_tx_q(vsi->seid, pf,
4470 false /*is xdp*/, enable);
4474 if (!i40e_enabled_xdp_vsi(vsi))
4477 ret = i40e_control_wait_tx_q(vsi->seid, pf,
4478 pf_q + vsi->alloc_queue_pairs,
4479 true /*is xdp*/, enable);
4487 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
4488 * @pf: the PF being configured
4489 * @pf_q: the PF queue
4490 * @enable: enable or disable state of the queue
4492 * This routine will wait for the given Rx queue of the PF to reach the
4493 * enabled or disabled state.
4494 * Returns -ETIMEDOUT in case of failing to reach the requested state after
4495 * multiple retries; else will return 0 in case of success.
4497 static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
4502 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
4503 rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
4504 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
4507 usleep_range(10, 20);
4509 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
4516 * i40e_control_rx_q - Start or stop a particular Rx queue
4517 * @pf: the PF structure
4518 * @pf_q: the PF queue to configure
4519 * @enable: start or stop the queue
4521 * This function enables or disables a single queue. Note that
4522 * any delay required after the operation is expected to be
4523 * handled by the caller of this function.
4525 static void i40e_control_rx_q(struct i40e_pf *pf, int pf_q, bool enable)
4527 struct i40e_hw *hw = &pf->hw;
4531 for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
4532 rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
4533 if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
4534 ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
4536 usleep_range(1000, 2000);
4539 /* Skip if the queue is already in the requested state */
4540 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
4543 /* turn on/off the queue */
4545 rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
4547 rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
4549 wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
4553 * i40e_control_wait_rx_q
4554 * @pf: the PF structure
4555 * @pf_q: queue being configured
4556 * @enable: start or stop the rings
4558 * This function enables or disables a single queue along with waiting
4559 * for the change to finish. The caller of this function should handle
4560 * the delays needed in the case of disabling queues.
4562 int i40e_control_wait_rx_q(struct i40e_pf *pf, int pf_q, bool enable)
4566 i40e_control_rx_q(pf, pf_q, enable);
4568 /* wait for the change to finish */
4569 ret = i40e_pf_rxq_wait(pf, pf_q, enable);
4577 * i40e_vsi_control_rx - Start or stop a VSI's rings
4578 * @vsi: the VSI being configured
4579 * @enable: start or stop the rings
4581 static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
4583 struct i40e_pf *pf = vsi->back;
4584 int i, pf_q, ret = 0;
4586 pf_q = vsi->base_queue;
4587 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
4588 ret = i40e_control_wait_rx_q(pf, pf_q, enable);
4590 dev_info(&pf->pdev->dev,
4591 "VSI seid %d Rx ring %d %sable timeout\n",
4592 vsi->seid, pf_q, (enable ? "en" : "dis"));
4597 /* Due to HW errata, on Rx disable only, the register can indicate done
4598 * before it really is. Needs 50ms to be sure
4607 * i40e_vsi_start_rings - Start a VSI's rings
4608 * @vsi: the VSI being configured
4610 int i40e_vsi_start_rings(struct i40e_vsi *vsi)
4614 /* do rx first for enable and last for disable */
4615 ret = i40e_vsi_control_rx(vsi, true);
4618 ret = i40e_vsi_control_tx(vsi, true);
4624 * i40e_vsi_stop_rings - Stop a VSI's rings
4625 * @vsi: the VSI being configured
4627 void i40e_vsi_stop_rings(struct i40e_vsi *vsi)
4629 /* When port TX is suspended, don't wait */
4630 if (test_bit(__I40E_PORT_SUSPENDED, vsi->back->state))
4631 return i40e_vsi_stop_rings_no_wait(vsi);
4633 /* do rx first for enable and last for disable
4634 * Ignore return value, we need to shutdown whatever we can
4636 i40e_vsi_control_tx(vsi, false);
4637 i40e_vsi_control_rx(vsi, false);
4641 * i40e_vsi_stop_rings_no_wait - Stop a VSI's rings and do not delay
4642 * @vsi: the VSI being shutdown
4644 * This function stops all the rings for a VSI but does not delay to verify
4645 * that rings have been disabled. It is expected that the caller is shutting
4646 * down multiple VSIs at once and will delay together for all the VSIs after
4647 * initiating the shutdown. This is particularly useful for shutting down lots
4648 * of VFs together. Otherwise, a large delay can be incurred while configuring
4649 * each VSI in serial.
4651 void i40e_vsi_stop_rings_no_wait(struct i40e_vsi *vsi)
4653 struct i40e_pf *pf = vsi->back;
4656 pf_q = vsi->base_queue;
4657 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
4658 i40e_control_tx_q(pf, pf_q, false);
4659 i40e_control_rx_q(pf, pf_q, false);
4664 * i40e_vsi_free_irq - Free the irq association with the OS
4665 * @vsi: the VSI being configured
4667 static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
4669 struct i40e_pf *pf = vsi->back;
4670 struct i40e_hw *hw = &pf->hw;
4671 int base = vsi->base_vector;
4675 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4676 if (!vsi->q_vectors)
4679 if (!vsi->irqs_ready)
4682 vsi->irqs_ready = false;
4683 for (i = 0; i < vsi->num_q_vectors; i++) {
4688 irq_num = pf->msix_entries[vector].vector;
4690 /* free only the irqs that were actually requested */
4691 if (!vsi->q_vectors[i] ||
4692 !vsi->q_vectors[i]->num_ringpairs)
4695 /* clear the affinity notifier in the IRQ descriptor */
4696 irq_set_affinity_notifier(irq_num, NULL);
4697 /* remove our suggested affinity mask for this IRQ */
4698 irq_set_affinity_hint(irq_num, NULL);
4699 synchronize_irq(irq_num);
4700 free_irq(irq_num, vsi->q_vectors[i]);
4702 /* Tear down the interrupt queue link list
4704 * We know that they come in pairs and always
4705 * the Rx first, then the Tx. To clear the
4706 * link list, stick the EOL value into the
4707 * next_q field of the registers.
4709 val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
4710 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
4711 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4712 val |= I40E_QUEUE_END_OF_LIST
4713 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4714 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
4716 while (qp != I40E_QUEUE_END_OF_LIST) {
4719 val = rd32(hw, I40E_QINT_RQCTL(qp));
4721 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4722 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4723 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4724 I40E_QINT_RQCTL_INTEVENT_MASK);
4726 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4727 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4729 wr32(hw, I40E_QINT_RQCTL(qp), val);
4731 val = rd32(hw, I40E_QINT_TQCTL(qp));
4733 next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
4734 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
4736 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4737 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4738 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4739 I40E_QINT_TQCTL_INTEVENT_MASK);
4741 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4742 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4744 wr32(hw, I40E_QINT_TQCTL(qp), val);
4749 free_irq(pf->pdev->irq, pf);
4751 val = rd32(hw, I40E_PFINT_LNKLST0);
4752 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
4753 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4754 val |= I40E_QUEUE_END_OF_LIST
4755 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
4756 wr32(hw, I40E_PFINT_LNKLST0, val);
4758 val = rd32(hw, I40E_QINT_RQCTL(qp));
4759 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4760 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4761 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4762 I40E_QINT_RQCTL_INTEVENT_MASK);
4764 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4765 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4767 wr32(hw, I40E_QINT_RQCTL(qp), val);
4769 val = rd32(hw, I40E_QINT_TQCTL(qp));
4771 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4772 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4773 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4774 I40E_QINT_TQCTL_INTEVENT_MASK);
4776 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4777 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4779 wr32(hw, I40E_QINT_TQCTL(qp), val);
4784 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
4785 * @vsi: the VSI being configured
4786 * @v_idx: Index of vector to be freed
4788 * This function frees the memory allocated to the q_vector. In addition if
4789 * NAPI is enabled it will delete any references to the NAPI struct prior
4790 * to freeing the q_vector.
4792 static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
4794 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
4795 struct i40e_ring *ring;
4800 /* disassociate q_vector from rings */
4801 i40e_for_each_ring(ring, q_vector->tx)
4802 ring->q_vector = NULL;
4804 i40e_for_each_ring(ring, q_vector->rx)
4805 ring->q_vector = NULL;
4807 /* only VSI w/ an associated netdev is set up w/ NAPI */
4809 netif_napi_del(&q_vector->napi);
4811 vsi->q_vectors[v_idx] = NULL;
4813 kfree_rcu(q_vector, rcu);
4817 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
4818 * @vsi: the VSI being un-configured
4820 * This frees the memory allocated to the q_vectors and
4821 * deletes references to the NAPI struct.
4823 static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
4827 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
4828 i40e_free_q_vector(vsi, v_idx);
4832 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
4833 * @pf: board private structure
4835 static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
4837 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
4838 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4839 pci_disable_msix(pf->pdev);
4840 kfree(pf->msix_entries);
4841 pf->msix_entries = NULL;
4842 kfree(pf->irq_pile);
4843 pf->irq_pile = NULL;
4844 } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
4845 pci_disable_msi(pf->pdev);
4847 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
4851 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
4852 * @pf: board private structure
4854 * We go through and clear interrupt specific resources and reset the structure
4855 * to pre-load conditions
4857 static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
4861 i40e_free_misc_vector(pf);
4863 i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
4864 I40E_IWARP_IRQ_PILE_ID);
4866 i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
4867 for (i = 0; i < pf->num_alloc_vsi; i++)
4869 i40e_vsi_free_q_vectors(pf->vsi[i]);
4870 i40e_reset_interrupt_capability(pf);
4874 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
4875 * @vsi: the VSI being configured
4877 static void i40e_napi_enable_all(struct i40e_vsi *vsi)
4884 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
4885 struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
4887 if (q_vector->rx.ring || q_vector->tx.ring)
4888 napi_enable(&q_vector->napi);
4893 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4894 * @vsi: the VSI being configured
4896 static void i40e_napi_disable_all(struct i40e_vsi *vsi)
4903 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
4904 struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
4906 if (q_vector->rx.ring || q_vector->tx.ring)
4907 napi_disable(&q_vector->napi);
4912 * i40e_vsi_close - Shut down a VSI
4913 * @vsi: the vsi to be quelled
4915 static void i40e_vsi_close(struct i40e_vsi *vsi)
4917 struct i40e_pf *pf = vsi->back;
4918 if (!test_and_set_bit(__I40E_VSI_DOWN, vsi->state))
4920 i40e_vsi_free_irq(vsi);
4921 i40e_vsi_free_tx_resources(vsi);
4922 i40e_vsi_free_rx_resources(vsi);
4923 vsi->current_netdev_flags = 0;
4924 set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
4925 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
4926 set_bit(__I40E_CLIENT_RESET, pf->state);
4930 * i40e_quiesce_vsi - Pause a given VSI
4931 * @vsi: the VSI being paused
4933 static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
4935 if (test_bit(__I40E_VSI_DOWN, vsi->state))
4938 set_bit(__I40E_VSI_NEEDS_RESTART, vsi->state);
4939 if (vsi->netdev && netif_running(vsi->netdev))
4940 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
4942 i40e_vsi_close(vsi);
4946 * i40e_unquiesce_vsi - Resume a given VSI
4947 * @vsi: the VSI being resumed
4949 static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
4951 if (!test_and_clear_bit(__I40E_VSI_NEEDS_RESTART, vsi->state))
4954 if (vsi->netdev && netif_running(vsi->netdev))
4955 vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
4957 i40e_vsi_open(vsi); /* this clears the DOWN bit */
4961 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
4964 static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
4968 for (v = 0; v < pf->num_alloc_vsi; v++) {
4970 i40e_quiesce_vsi(pf->vsi[v]);
4975 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
4978 static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
4982 for (v = 0; v < pf->num_alloc_vsi; v++) {
4984 i40e_unquiesce_vsi(pf->vsi[v]);
4989 * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
4990 * @vsi: the VSI being configured
4992 * Wait until all queues on a given VSI have been disabled.
4994 int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
4996 struct i40e_pf *pf = vsi->back;
4999 pf_q = vsi->base_queue;
5000 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
5001 /* Check and wait for the Tx queue */
5002 ret = i40e_pf_txq_wait(pf, pf_q, false);
5004 dev_info(&pf->pdev->dev,
5005 "VSI seid %d Tx ring %d disable timeout\n",
5010 if (!i40e_enabled_xdp_vsi(vsi))
5013 /* Check and wait for the XDP Tx queue */
5014 ret = i40e_pf_txq_wait(pf, pf_q + vsi->alloc_queue_pairs,
5017 dev_info(&pf->pdev->dev,
5018 "VSI seid %d XDP Tx ring %d disable timeout\n",
5023 /* Check and wait for the Rx queue */
5024 ret = i40e_pf_rxq_wait(pf, pf_q, false);
5026 dev_info(&pf->pdev->dev,
5027 "VSI seid %d Rx ring %d disable timeout\n",
5036 #ifdef CONFIG_I40E_DCB
5038 * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
5041 * This function waits for the queues to be in disabled state for all the
5042 * VSIs that are managed by this PF.
5044 static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
5048 for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
5050 ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
5062 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
5063 * @pf: pointer to PF
5065 * Get TC map for ISCSI PF type that will include iSCSI TC
5068 static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
5070 struct i40e_dcb_app_priority_table app;
5071 struct i40e_hw *hw = &pf->hw;
5072 u8 enabled_tc = 1; /* TC0 is always enabled */
5074 /* Get the iSCSI APP TLV */
5075 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
5077 for (i = 0; i < dcbcfg->numapps; i++) {
5078 app = dcbcfg->app[i];
5079 if (app.selector == I40E_APP_SEL_TCPIP &&
5080 app.protocolid == I40E_APP_PROTOID_ISCSI) {
5081 tc = dcbcfg->etscfg.prioritytable[app.priority];
5082 enabled_tc |= BIT(tc);
5091 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
5092 * @dcbcfg: the corresponding DCBx configuration structure
5094 * Return the number of TCs from given DCBx configuration
5096 static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
5098 int i, tc_unused = 0;
5102 /* Scan the ETS Config Priority Table to find
5103 * traffic class enabled for a given priority
5104 * and create a bitmask of enabled TCs
5106 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
5107 num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]);
5109 /* Now scan the bitmask to check for
5110 * contiguous TCs starting with TC0
5112 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5113 if (num_tc & BIT(i)) {
5117 pr_err("Non-contiguous TC - Disabling DCB\n");
5125 /* There is always at least TC0 */
5133 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
5134 * @dcbcfg: the corresponding DCBx configuration structure
5136 * Query the current DCB configuration and return the number of
5137 * traffic classes enabled from the given DCBX config
5139 static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
5141 u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
5145 for (i = 0; i < num_tc; i++)
5146 enabled_tc |= BIT(i);
5152 * i40e_mqprio_get_enabled_tc - Get enabled traffic classes
5153 * @pf: PF being queried
5155 * Query the current MQPRIO configuration and return the number of
5156 * traffic classes enabled.
5158 static u8 i40e_mqprio_get_enabled_tc(struct i40e_pf *pf)
5160 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
5161 u8 num_tc = vsi->mqprio_qopt.qopt.num_tc;
5162 u8 enabled_tc = 1, i;
5164 for (i = 1; i < num_tc; i++)
5165 enabled_tc |= BIT(i);
5170 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
5171 * @pf: PF being queried
5173 * Return number of traffic classes enabled for the given PF
5175 static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
5177 struct i40e_hw *hw = &pf->hw;
5178 u8 i, enabled_tc = 1;
5180 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
5182 if (pf->flags & I40E_FLAG_TC_MQPRIO)
5183 return pf->vsi[pf->lan_vsi]->mqprio_qopt.qopt.num_tc;
5185 /* If neither MQPRIO nor DCB is enabled, then always use single TC */
5186 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
5189 /* SFP mode will be enabled for all TCs on port */
5190 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
5191 return i40e_dcb_get_num_tc(dcbcfg);
5193 /* MFP mode return count of enabled TCs for this PF */
5194 if (pf->hw.func_caps.iscsi)
5195 enabled_tc = i40e_get_iscsi_tc_map(pf);
5197 return 1; /* Only TC0 */
5199 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5200 if (enabled_tc & BIT(i))
5207 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
5208 * @pf: PF being queried
5210 * Return a bitmap for enabled traffic classes for this PF.
5212 static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
5214 if (pf->flags & I40E_FLAG_TC_MQPRIO)
5215 return i40e_mqprio_get_enabled_tc(pf);
5217 /* If neither MQPRIO nor DCB is enabled for this PF then just return
5220 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
5221 return I40E_DEFAULT_TRAFFIC_CLASS;
5223 /* SFP mode we want PF to be enabled for all TCs */
5224 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
5225 return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
5227 /* MFP enabled and iSCSI PF type */
5228 if (pf->hw.func_caps.iscsi)
5229 return i40e_get_iscsi_tc_map(pf);
5231 return I40E_DEFAULT_TRAFFIC_CLASS;
5235 * i40e_vsi_get_bw_info - Query VSI BW Information
5236 * @vsi: the VSI being queried
5238 * Returns 0 on success, negative value on failure
5240 static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
5242 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
5243 struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
5244 struct i40e_pf *pf = vsi->back;
5245 struct i40e_hw *hw = &pf->hw;
5250 /* Get the VSI level BW configuration */
5251 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
5253 dev_info(&pf->pdev->dev,
5254 "couldn't get PF vsi bw config, err %s aq_err %s\n",
5255 i40e_stat_str(&pf->hw, ret),
5256 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
5260 /* Get the VSI level BW configuration per TC */
5261 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
5264 dev_info(&pf->pdev->dev,
5265 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
5266 i40e_stat_str(&pf->hw, ret),
5267 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
5271 if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
5272 dev_info(&pf->pdev->dev,
5273 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
5274 bw_config.tc_valid_bits,
5275 bw_ets_config.tc_valid_bits);
5276 /* Still continuing */
5279 vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
5280 vsi->bw_max_quanta = bw_config.max_bw;
5281 tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
5282 (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
5283 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5284 vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
5285 vsi->bw_ets_limit_credits[i] =
5286 le16_to_cpu(bw_ets_config.credits[i]);
5287 /* 3 bits out of 4 for each TC */
5288 vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
5295 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
5296 * @vsi: the VSI being configured
5297 * @enabled_tc: TC bitmap
5298 * @bw_share: BW shared credits per TC
5300 * Returns 0 on success, negative value on failure
5302 static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
5305 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
5306 struct i40e_pf *pf = vsi->back;
5310 /* There is no need to reset BW when mqprio mode is on. */
5311 if (pf->flags & I40E_FLAG_TC_MQPRIO)
5313 if (!vsi->mqprio_qopt.qopt.hw && !(pf->flags & I40E_FLAG_DCB_ENABLED)) {
5314 ret = i40e_set_bw_limit(vsi, vsi->seid, 0);
5316 dev_info(&pf->pdev->dev,
5317 "Failed to reset tx rate for vsi->seid %u\n",
5321 memset(&bw_data, 0, sizeof(bw_data));
5322 bw_data.tc_valid_bits = enabled_tc;
5323 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5324 bw_data.tc_bw_credits[i] = bw_share[i];
5326 ret = i40e_aq_config_vsi_tc_bw(&pf->hw, vsi->seid, &bw_data, NULL);
5328 dev_info(&pf->pdev->dev,
5329 "AQ command Config VSI BW allocation per TC failed = %d\n",
5330 pf->hw.aq.asq_last_status);
5334 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5335 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
5341 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
5342 * @vsi: the VSI being configured
5343 * @enabled_tc: TC map to be enabled
5346 static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
5348 struct net_device *netdev = vsi->netdev;
5349 struct i40e_pf *pf = vsi->back;
5350 struct i40e_hw *hw = &pf->hw;
5353 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
5359 netdev_reset_tc(netdev);
5363 /* Set up actual enabled TCs on the VSI */
5364 if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
5367 /* set per TC queues for the VSI */
5368 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5369 /* Only set TC queues for enabled tcs
5371 * e.g. For a VSI that has TC0 and TC3 enabled the
5372 * enabled_tc bitmap would be 0x00001001; the driver
5373 * will set the numtc for netdev as 2 that will be
5374 * referenced by the netdev layer as TC 0 and 1.
5376 if (vsi->tc_config.enabled_tc & BIT(i))
5377 netdev_set_tc_queue(netdev,
5378 vsi->tc_config.tc_info[i].netdev_tc,
5379 vsi->tc_config.tc_info[i].qcount,
5380 vsi->tc_config.tc_info[i].qoffset);
5383 if (pf->flags & I40E_FLAG_TC_MQPRIO)
5386 /* Assign UP2TC map for the VSI */
5387 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
5388 /* Get the actual TC# for the UP */
5389 u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
5390 /* Get the mapped netdev TC# for the UP */
5391 netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
5392 netdev_set_prio_tc_map(netdev, i, netdev_tc);
5397 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
5398 * @vsi: the VSI being configured
5399 * @ctxt: the ctxt buffer returned from AQ VSI update param command
5401 static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
5402 struct i40e_vsi_context *ctxt)
5404 /* copy just the sections touched not the entire info
5405 * since not all sections are valid as returned by
5408 vsi->info.mapping_flags = ctxt->info.mapping_flags;
5409 memcpy(&vsi->info.queue_mapping,
5410 &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
5411 memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
5412 sizeof(vsi->info.tc_mapping));
5416 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
5417 * @vsi: VSI to be configured
5418 * @enabled_tc: TC bitmap
5420 * This configures a particular VSI for TCs that are mapped to the
5421 * given TC bitmap. It uses default bandwidth share for TCs across
5422 * VSIs to configure TC for a particular VSI.
5425 * It is expected that the VSI queues have been quisced before calling
5428 static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
5430 u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
5431 struct i40e_pf *pf = vsi->back;
5432 struct i40e_hw *hw = &pf->hw;
5433 struct i40e_vsi_context ctxt;
5437 /* Check if enabled_tc is same as existing or new TCs */
5438 if (vsi->tc_config.enabled_tc == enabled_tc &&
5439 vsi->mqprio_qopt.mode != TC_MQPRIO_MODE_CHANNEL)
5442 /* Enable ETS TCs with equal BW Share for now across all VSIs */
5443 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5444 if (enabled_tc & BIT(i))
5448 ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
5450 struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
5452 dev_info(&pf->pdev->dev,
5453 "Failed configuring TC map %d for VSI %d\n",
5454 enabled_tc, vsi->seid);
5455 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid,
5458 dev_info(&pf->pdev->dev,
5459 "Failed querying vsi bw info, err %s aq_err %s\n",
5460 i40e_stat_str(hw, ret),
5461 i40e_aq_str(hw, hw->aq.asq_last_status));
5464 if ((bw_config.tc_valid_bits & enabled_tc) != enabled_tc) {
5465 u8 valid_tc = bw_config.tc_valid_bits & enabled_tc;
5468 valid_tc = bw_config.tc_valid_bits;
5469 /* Always enable TC0, no matter what */
5471 dev_info(&pf->pdev->dev,
5472 "Requested tc 0x%x, but FW reports 0x%x as valid. Attempting to use 0x%x.\n",
5473 enabled_tc, bw_config.tc_valid_bits, valid_tc);
5474 enabled_tc = valid_tc;
5477 ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
5479 dev_err(&pf->pdev->dev,
5480 "Unable to configure TC map %d for VSI %d\n",
5481 enabled_tc, vsi->seid);
5486 /* Update Queue Pairs Mapping for currently enabled UPs */
5487 ctxt.seid = vsi->seid;
5488 ctxt.pf_num = vsi->back->hw.pf_id;
5490 ctxt.uplink_seid = vsi->uplink_seid;
5491 ctxt.info = vsi->info;
5492 if (vsi->back->flags & I40E_FLAG_TC_MQPRIO) {
5493 ret = i40e_vsi_setup_queue_map_mqprio(vsi, &ctxt, enabled_tc);
5497 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
5500 /* On destroying the qdisc, reset vsi->rss_size, as number of enabled
5503 if (!vsi->mqprio_qopt.qopt.hw && vsi->reconfig_rss) {
5504 vsi->rss_size = min_t(int, vsi->back->alloc_rss_size,
5505 vsi->num_queue_pairs);
5506 ret = i40e_vsi_config_rss(vsi);
5508 dev_info(&vsi->back->pdev->dev,
5509 "Failed to reconfig rss for num_queues\n");
5512 vsi->reconfig_rss = false;
5514 if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
5515 ctxt.info.valid_sections |=
5516 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
5517 ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
5520 /* Update the VSI after updating the VSI queue-mapping
5523 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5525 dev_info(&pf->pdev->dev,
5526 "Update vsi tc config failed, err %s aq_err %s\n",
5527 i40e_stat_str(hw, ret),
5528 i40e_aq_str(hw, hw->aq.asq_last_status));
5531 /* update the local VSI info with updated queue map */
5532 i40e_vsi_update_queue_map(vsi, &ctxt);
5533 vsi->info.valid_sections = 0;
5535 /* Update current VSI BW information */
5536 ret = i40e_vsi_get_bw_info(vsi);
5538 dev_info(&pf->pdev->dev,
5539 "Failed updating vsi bw info, err %s aq_err %s\n",
5540 i40e_stat_str(hw, ret),
5541 i40e_aq_str(hw, hw->aq.asq_last_status));
5545 /* Update the netdev TC setup */
5546 i40e_vsi_config_netdev_tc(vsi, enabled_tc);
5552 * i40e_get_link_speed - Returns link speed for the interface
5553 * @vsi: VSI to be configured
5556 static int i40e_get_link_speed(struct i40e_vsi *vsi)
5558 struct i40e_pf *pf = vsi->back;
5560 switch (pf->hw.phy.link_info.link_speed) {
5561 case I40E_LINK_SPEED_40GB:
5563 case I40E_LINK_SPEED_25GB:
5565 case I40E_LINK_SPEED_20GB:
5567 case I40E_LINK_SPEED_10GB:
5569 case I40E_LINK_SPEED_1GB:
5577 * i40e_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate
5578 * @vsi: VSI to be configured
5579 * @seid: seid of the channel/VSI
5580 * @max_tx_rate: max TX rate to be configured as BW limit
5582 * Helper function to set BW limit for a given VSI
5584 int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate)
5586 struct i40e_pf *pf = vsi->back;
5591 speed = i40e_get_link_speed(vsi);
5592 if (max_tx_rate > speed) {
5593 dev_err(&pf->pdev->dev,
5594 "Invalid max tx rate %llu specified for VSI seid %d.",
5598 if (max_tx_rate && max_tx_rate < 50) {
5599 dev_warn(&pf->pdev->dev,
5600 "Setting max tx rate to minimum usable value of 50Mbps.\n");
5604 /* Tx rate credits are in values of 50Mbps, 0 is disabled */
5605 credits = max_tx_rate;
5606 do_div(credits, I40E_BW_CREDIT_DIVISOR);
5607 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, seid, credits,
5608 I40E_MAX_BW_INACTIVE_ACCUM, NULL);
5610 dev_err(&pf->pdev->dev,
5611 "Failed set tx rate (%llu Mbps) for vsi->seid %u, err %s aq_err %s\n",
5612 max_tx_rate, seid, i40e_stat_str(&pf->hw, ret),
5613 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
5618 * i40e_remove_queue_channels - Remove queue channels for the TCs
5619 * @vsi: VSI to be configured
5621 * Remove queue channels for the TCs
5623 static void i40e_remove_queue_channels(struct i40e_vsi *vsi)
5625 enum i40e_admin_queue_err last_aq_status;
5626 struct i40e_cloud_filter *cfilter;
5627 struct i40e_channel *ch, *ch_tmp;
5628 struct i40e_pf *pf = vsi->back;
5629 struct hlist_node *node;
5632 /* Reset rss size that was stored when reconfiguring rss for
5633 * channel VSIs with non-power-of-2 queue count.
5635 vsi->current_rss_size = 0;
5637 /* perform cleanup for channels if they exist */
5638 if (list_empty(&vsi->ch_list))
5641 list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
5642 struct i40e_vsi *p_vsi;
5644 list_del(&ch->list);
5645 p_vsi = ch->parent_vsi;
5646 if (!p_vsi || !ch->initialized) {
5650 /* Reset queue contexts */
5651 for (i = 0; i < ch->num_queue_pairs; i++) {
5652 struct i40e_ring *tx_ring, *rx_ring;
5655 pf_q = ch->base_queue + i;
5656 tx_ring = vsi->tx_rings[pf_q];
5659 rx_ring = vsi->rx_rings[pf_q];
5663 /* Reset BW configured for this VSI via mqprio */
5664 ret = i40e_set_bw_limit(vsi, ch->seid, 0);
5666 dev_info(&vsi->back->pdev->dev,
5667 "Failed to reset tx rate for ch->seid %u\n",
5670 /* delete cloud filters associated with this channel */
5671 hlist_for_each_entry_safe(cfilter, node,
5672 &pf->cloud_filter_list, cloud_node) {
5673 if (cfilter->seid != ch->seid)
5676 hash_del(&cfilter->cloud_node);
5677 if (cfilter->dst_port)
5678 ret = i40e_add_del_cloud_filter_big_buf(vsi,
5682 ret = i40e_add_del_cloud_filter(vsi, cfilter,
5684 last_aq_status = pf->hw.aq.asq_last_status;
5686 dev_info(&pf->pdev->dev,
5687 "Failed to delete cloud filter, err %s aq_err %s\n",
5688 i40e_stat_str(&pf->hw, ret),
5689 i40e_aq_str(&pf->hw, last_aq_status));
5693 /* delete VSI from FW */
5694 ret = i40e_aq_delete_element(&vsi->back->hw, ch->seid,
5697 dev_err(&vsi->back->pdev->dev,
5698 "unable to remove channel (%d) for parent VSI(%d)\n",
5699 ch->seid, p_vsi->seid);
5702 INIT_LIST_HEAD(&vsi->ch_list);
5706 * i40e_is_any_channel - channel exist or not
5707 * @vsi: ptr to VSI to which channels are associated with
5709 * Returns true or false if channel(s) exist for associated VSI or not
5711 static bool i40e_is_any_channel(struct i40e_vsi *vsi)
5713 struct i40e_channel *ch, *ch_tmp;
5715 list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
5716 if (ch->initialized)
5724 * i40e_get_max_queues_for_channel
5725 * @vsi: ptr to VSI to which channels are associated with
5727 * Helper function which returns max value among the queue counts set on the
5728 * channels/TCs created.
5730 static int i40e_get_max_queues_for_channel(struct i40e_vsi *vsi)
5732 struct i40e_channel *ch, *ch_tmp;
5735 list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
5736 if (!ch->initialized)
5738 if (ch->num_queue_pairs > max)
5739 max = ch->num_queue_pairs;
5746 * i40e_validate_num_queues - validate num_queues w.r.t channel
5747 * @pf: ptr to PF device
5748 * @num_queues: number of queues
5749 * @vsi: the parent VSI
5750 * @reconfig_rss: indicates should the RSS be reconfigured or not
5752 * This function validates number of queues in the context of new channel
5753 * which is being established and determines if RSS should be reconfigured
5754 * or not for parent VSI.
5756 static int i40e_validate_num_queues(struct i40e_pf *pf, int num_queues,
5757 struct i40e_vsi *vsi, bool *reconfig_rss)
5764 *reconfig_rss = false;
5765 if (vsi->current_rss_size) {
5766 if (num_queues > vsi->current_rss_size) {
5767 dev_dbg(&pf->pdev->dev,
5768 "Error: num_queues (%d) > vsi's current_size(%d)\n",
5769 num_queues, vsi->current_rss_size);
5771 } else if ((num_queues < vsi->current_rss_size) &&
5772 (!is_power_of_2(num_queues))) {
5773 dev_dbg(&pf->pdev->dev,
5774 "Error: num_queues (%d) < vsi's current_size(%d), but not power of 2\n",
5775 num_queues, vsi->current_rss_size);
5780 if (!is_power_of_2(num_queues)) {
5781 /* Find the max num_queues configured for channel if channel
5783 * if channel exist, then enforce 'num_queues' to be more than
5784 * max ever queues configured for channel.
5786 max_ch_queues = i40e_get_max_queues_for_channel(vsi);
5787 if (num_queues < max_ch_queues) {
5788 dev_dbg(&pf->pdev->dev,
5789 "Error: num_queues (%d) < max queues configured for channel(%d)\n",
5790 num_queues, max_ch_queues);
5793 *reconfig_rss = true;
5800 * i40e_vsi_reconfig_rss - reconfig RSS based on specified rss_size
5801 * @vsi: the VSI being setup
5802 * @rss_size: size of RSS, accordingly LUT gets reprogrammed
5804 * This function reconfigures RSS by reprogramming LUTs using 'rss_size'
5806 static int i40e_vsi_reconfig_rss(struct i40e_vsi *vsi, u16 rss_size)
5808 struct i40e_pf *pf = vsi->back;
5809 u8 seed[I40E_HKEY_ARRAY_SIZE];
5810 struct i40e_hw *hw = &pf->hw;
5818 if (rss_size > vsi->rss_size)
5821 local_rss_size = min_t(int, vsi->rss_size, rss_size);
5822 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
5826 /* Ignoring user configured lut if there is one */
5827 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, local_rss_size);
5829 /* Use user configured hash key if there is one, otherwise
5832 if (vsi->rss_hkey_user)
5833 memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
5835 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
5837 ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
5839 dev_info(&pf->pdev->dev,
5840 "Cannot set RSS lut, err %s aq_err %s\n",
5841 i40e_stat_str(hw, ret),
5842 i40e_aq_str(hw, hw->aq.asq_last_status));
5848 /* Do the update w.r.t. storing rss_size */
5849 if (!vsi->orig_rss_size)
5850 vsi->orig_rss_size = vsi->rss_size;
5851 vsi->current_rss_size = local_rss_size;
5857 * i40e_channel_setup_queue_map - Setup a channel queue map
5858 * @pf: ptr to PF device
5859 * @ctxt: VSI context structure
5860 * @ch: ptr to channel structure
5862 * Setup queue map for a specific channel
5864 static void i40e_channel_setup_queue_map(struct i40e_pf *pf,
5865 struct i40e_vsi_context *ctxt,
5866 struct i40e_channel *ch)
5868 u16 qcount, qmap, sections = 0;
5872 sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
5873 sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
5875 qcount = min_t(int, ch->num_queue_pairs, pf->num_lan_msix);
5876 ch->num_queue_pairs = qcount;
5878 /* find the next higher power-of-2 of num queue pairs */
5879 pow = ilog2(qcount);
5880 if (!is_power_of_2(qcount))
5883 qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
5884 (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
5886 /* Setup queue TC[0].qmap for given VSI context */
5887 ctxt->info.tc_mapping[0] = cpu_to_le16(qmap);
5889 ctxt->info.up_enable_bits = 0x1; /* TC0 enabled */
5890 ctxt->info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
5891 ctxt->info.queue_mapping[0] = cpu_to_le16(ch->base_queue);
5892 ctxt->info.valid_sections |= cpu_to_le16(sections);
5896 * i40e_add_channel - add a channel by adding VSI
5897 * @pf: ptr to PF device
5898 * @uplink_seid: underlying HW switching element (VEB) ID
5899 * @ch: ptr to channel structure
5901 * Add a channel (VSI) using add_vsi and queue_map
5903 static int i40e_add_channel(struct i40e_pf *pf, u16 uplink_seid,
5904 struct i40e_channel *ch)
5906 struct i40e_hw *hw = &pf->hw;
5907 struct i40e_vsi_context ctxt;
5908 u8 enabled_tc = 0x1; /* TC0 enabled */
5911 if (ch->type != I40E_VSI_VMDQ2) {
5912 dev_info(&pf->pdev->dev,
5913 "add new vsi failed, ch->type %d\n", ch->type);
5917 memset(&ctxt, 0, sizeof(ctxt));
5918 ctxt.pf_num = hw->pf_id;
5920 ctxt.uplink_seid = uplink_seid;
5921 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
5922 if (ch->type == I40E_VSI_VMDQ2)
5923 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
5925 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) {
5926 ctxt.info.valid_sections |=
5927 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5928 ctxt.info.switch_id =
5929 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5932 /* Set queue map for a given VSI context */
5933 i40e_channel_setup_queue_map(pf, &ctxt, ch);
5935 /* Now time to create VSI */
5936 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
5938 dev_info(&pf->pdev->dev,
5939 "add new vsi failed, err %s aq_err %s\n",
5940 i40e_stat_str(&pf->hw, ret),
5941 i40e_aq_str(&pf->hw,
5942 pf->hw.aq.asq_last_status));
5946 /* Success, update channel, set enabled_tc only if the channel
5949 ch->enabled_tc = !i40e_is_channel_macvlan(ch) && enabled_tc;
5950 ch->seid = ctxt.seid;
5951 ch->vsi_number = ctxt.vsi_number;
5952 ch->stat_counter_idx = le16_to_cpu(ctxt.info.stat_counter_idx);
5954 /* copy just the sections touched not the entire info
5955 * since not all sections are valid as returned by
5958 ch->info.mapping_flags = ctxt.info.mapping_flags;
5959 memcpy(&ch->info.queue_mapping,
5960 &ctxt.info.queue_mapping, sizeof(ctxt.info.queue_mapping));
5961 memcpy(&ch->info.tc_mapping, ctxt.info.tc_mapping,
5962 sizeof(ctxt.info.tc_mapping));
5967 static int i40e_channel_config_bw(struct i40e_vsi *vsi, struct i40e_channel *ch,
5970 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
5974 memset(&bw_data, 0, sizeof(bw_data));
5975 bw_data.tc_valid_bits = ch->enabled_tc;
5976 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5977 bw_data.tc_bw_credits[i] = bw_share[i];
5979 ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, ch->seid,
5982 dev_info(&vsi->back->pdev->dev,
5983 "Config VSI BW allocation per TC failed, aq_err: %d for new_vsi->seid %u\n",
5984 vsi->back->hw.aq.asq_last_status, ch->seid);
5988 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5989 ch->info.qs_handle[i] = bw_data.qs_handles[i];
5995 * i40e_channel_config_tx_ring - config TX ring associated with new channel
5996 * @pf: ptr to PF device
5997 * @vsi: the VSI being setup
5998 * @ch: ptr to channel structure
6000 * Configure TX rings associated with channel (VSI) since queues are being
6003 static int i40e_channel_config_tx_ring(struct i40e_pf *pf,
6004 struct i40e_vsi *vsi,
6005 struct i40e_channel *ch)
6009 u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
6011 /* Enable ETS TCs with equal BW Share for now across all VSIs */
6012 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
6013 if (ch->enabled_tc & BIT(i))
6017 /* configure BW for new VSI */
6018 ret = i40e_channel_config_bw(vsi, ch, bw_share);
6020 dev_info(&vsi->back->pdev->dev,
6021 "Failed configuring TC map %d for channel (seid %u)\n",
6022 ch->enabled_tc, ch->seid);
6026 for (i = 0; i < ch->num_queue_pairs; i++) {
6027 struct i40e_ring *tx_ring, *rx_ring;
6030 pf_q = ch->base_queue + i;
6032 /* Get to TX ring ptr of main VSI, for re-setup TX queue
6035 tx_ring = vsi->tx_rings[pf_q];
6038 /* Get the RX ring ptr */
6039 rx_ring = vsi->rx_rings[pf_q];
6047 * i40e_setup_hw_channel - setup new channel
6048 * @pf: ptr to PF device
6049 * @vsi: the VSI being setup
6050 * @ch: ptr to channel structure
6051 * @uplink_seid: underlying HW switching element (VEB) ID
6052 * @type: type of channel to be created (VMDq2/VF)
6054 * Setup new channel (VSI) based on specified type (VMDq2/VF)
6055 * and configures TX rings accordingly
6057 static inline int i40e_setup_hw_channel(struct i40e_pf *pf,
6058 struct i40e_vsi *vsi,
6059 struct i40e_channel *ch,
6060 u16 uplink_seid, u8 type)
6064 ch->initialized = false;
6065 ch->base_queue = vsi->next_base_queue;
6068 /* Proceed with creation of channel (VMDq2) VSI */
6069 ret = i40e_add_channel(pf, uplink_seid, ch);
6071 dev_info(&pf->pdev->dev,
6072 "failed to add_channel using uplink_seid %u\n",
6077 /* Mark the successful creation of channel */
6078 ch->initialized = true;
6080 /* Reconfigure TX queues using QTX_CTL register */
6081 ret = i40e_channel_config_tx_ring(pf, vsi, ch);
6083 dev_info(&pf->pdev->dev,
6084 "failed to configure TX rings for channel %u\n",
6089 /* update 'next_base_queue' */
6090 vsi->next_base_queue = vsi->next_base_queue + ch->num_queue_pairs;
6091 dev_dbg(&pf->pdev->dev,
6092 "Added channel: vsi_seid %u, vsi_number %u, stat_counter_idx %u, num_queue_pairs %u, pf->next_base_queue %d\n",
6093 ch->seid, ch->vsi_number, ch->stat_counter_idx,
6094 ch->num_queue_pairs,
6095 vsi->next_base_queue);
6100 * i40e_setup_channel - setup new channel using uplink element
6101 * @pf: ptr to PF device
6102 * @vsi: pointer to the VSI to set up the channel within
6103 * @ch: ptr to channel structure
6105 * Setup new channel (VSI) based on specified type (VMDq2/VF)
6106 * and uplink switching element (uplink_seid)
6108 static bool i40e_setup_channel(struct i40e_pf *pf, struct i40e_vsi *vsi,
6109 struct i40e_channel *ch)
6115 if (vsi->type == I40E_VSI_MAIN) {
6116 vsi_type = I40E_VSI_VMDQ2;
6118 dev_err(&pf->pdev->dev, "unsupported parent vsi type(%d)\n",
6123 /* underlying switching element */
6124 seid = pf->vsi[pf->lan_vsi]->uplink_seid;
6126 /* create channel (VSI), configure TX rings */
6127 ret = i40e_setup_hw_channel(pf, vsi, ch, seid, vsi_type);
6129 dev_err(&pf->pdev->dev, "failed to setup hw_channel\n");
6133 return ch->initialized ? true : false;
6137 * i40e_validate_and_set_switch_mode - sets up switch mode correctly
6138 * @vsi: ptr to VSI which has PF backing
6140 * Sets up switch mode correctly if it needs to be changed and perform
6141 * what are allowed modes.
6143 static int i40e_validate_and_set_switch_mode(struct i40e_vsi *vsi)
6146 struct i40e_pf *pf = vsi->back;
6147 struct i40e_hw *hw = &pf->hw;
6150 ret = i40e_get_capabilities(pf, i40e_aqc_opc_list_dev_capabilities);
6154 if (hw->dev_caps.switch_mode) {
6155 /* if switch mode is set, support mode2 (non-tunneled for
6156 * cloud filter) for now
6158 u32 switch_mode = hw->dev_caps.switch_mode &
6159 I40E_SWITCH_MODE_MASK;
6160 if (switch_mode >= I40E_CLOUD_FILTER_MODE1) {
6161 if (switch_mode == I40E_CLOUD_FILTER_MODE2)
6163 dev_err(&pf->pdev->dev,
6164 "Invalid switch_mode (%d), only non-tunneled mode for cloud filter is supported\n",
6165 hw->dev_caps.switch_mode);
6170 /* Set Bit 7 to be valid */
6171 mode = I40E_AQ_SET_SWITCH_BIT7_VALID;
6173 /* Set L4type for TCP support */
6174 mode |= I40E_AQ_SET_SWITCH_L4_TYPE_TCP;
6176 /* Set cloud filter mode */
6177 mode |= I40E_AQ_SET_SWITCH_MODE_NON_TUNNEL;
6179 /* Prep mode field for set_switch_config */
6180 ret = i40e_aq_set_switch_config(hw, pf->last_sw_conf_flags,
6181 pf->last_sw_conf_valid_flags,
6183 if (ret && hw->aq.asq_last_status != I40E_AQ_RC_ESRCH)
6184 dev_err(&pf->pdev->dev,
6185 "couldn't set switch config bits, err %s aq_err %s\n",
6186 i40e_stat_str(hw, ret),
6188 hw->aq.asq_last_status));
6194 * i40e_create_queue_channel - function to create channel
6195 * @vsi: VSI to be configured
6196 * @ch: ptr to channel (it contains channel specific params)
6198 * This function creates channel (VSI) using num_queues specified by user,
6199 * reconfigs RSS if needed.
6201 int i40e_create_queue_channel(struct i40e_vsi *vsi,
6202 struct i40e_channel *ch)
6204 struct i40e_pf *pf = vsi->back;
6211 if (!ch->num_queue_pairs) {
6212 dev_err(&pf->pdev->dev, "Invalid num_queues requested: %d\n",
6213 ch->num_queue_pairs);
6217 /* validate user requested num_queues for channel */
6218 err = i40e_validate_num_queues(pf, ch->num_queue_pairs, vsi,
6221 dev_info(&pf->pdev->dev, "Failed to validate num_queues (%d)\n",
6222 ch->num_queue_pairs);
6226 /* By default we are in VEPA mode, if this is the first VF/VMDq
6227 * VSI to be added switch to VEB mode.
6229 if ((!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) ||
6230 (!i40e_is_any_channel(vsi))) {
6231 if (!is_power_of_2(vsi->tc_config.tc_info[0].qcount)) {
6232 dev_dbg(&pf->pdev->dev,
6233 "Failed to create channel. Override queues (%u) not power of 2\n",
6234 vsi->tc_config.tc_info[0].qcount);
6238 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
6239 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
6241 if (vsi->type == I40E_VSI_MAIN) {
6242 if (pf->flags & I40E_FLAG_TC_MQPRIO)
6243 i40e_do_reset(pf, I40E_PF_RESET_FLAG,
6246 i40e_do_reset_safe(pf,
6247 I40E_PF_RESET_FLAG);
6250 /* now onwards for main VSI, number of queues will be value
6251 * of TC0's queue count
6255 /* By this time, vsi->cnt_q_avail shall be set to non-zero and
6256 * it should be more than num_queues
6258 if (!vsi->cnt_q_avail || vsi->cnt_q_avail < ch->num_queue_pairs) {
6259 dev_dbg(&pf->pdev->dev,
6260 "Error: cnt_q_avail (%u) less than num_queues %d\n",
6261 vsi->cnt_q_avail, ch->num_queue_pairs);
6265 /* reconfig_rss only if vsi type is MAIN_VSI */
6266 if (reconfig_rss && (vsi->type == I40E_VSI_MAIN)) {
6267 err = i40e_vsi_reconfig_rss(vsi, ch->num_queue_pairs);
6269 dev_info(&pf->pdev->dev,
6270 "Error: unable to reconfig rss for num_queues (%u)\n",
6271 ch->num_queue_pairs);
6276 if (!i40e_setup_channel(pf, vsi, ch)) {
6277 dev_info(&pf->pdev->dev, "Failed to setup channel\n");
6281 dev_info(&pf->pdev->dev,
6282 "Setup channel (id:%u) utilizing num_queues %d\n",
6283 ch->seid, ch->num_queue_pairs);
6285 /* configure VSI for BW limit */
6286 if (ch->max_tx_rate) {
6287 u64 credits = ch->max_tx_rate;
6289 if (i40e_set_bw_limit(vsi, ch->seid, ch->max_tx_rate))
6292 do_div(credits, I40E_BW_CREDIT_DIVISOR);
6293 dev_dbg(&pf->pdev->dev,
6294 "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
6300 /* in case of VF, this will be main SRIOV VSI */
6301 ch->parent_vsi = vsi;
6303 /* and update main_vsi's count for queue_available to use */
6304 vsi->cnt_q_avail -= ch->num_queue_pairs;
6310 * i40e_configure_queue_channels - Add queue channel for the given TCs
6311 * @vsi: VSI to be configured
6313 * Configures queue channel mapping to the given TCs
6315 static int i40e_configure_queue_channels(struct i40e_vsi *vsi)
6317 struct i40e_channel *ch;
6321 /* Create app vsi with the TCs. Main VSI with TC0 is already set up */
6322 vsi->tc_seid_map[0] = vsi->seid;
6323 for (i = 1; i < I40E_MAX_TRAFFIC_CLASS; i++) {
6324 if (vsi->tc_config.enabled_tc & BIT(i)) {
6325 ch = kzalloc(sizeof(*ch), GFP_KERNEL);
6331 INIT_LIST_HEAD(&ch->list);
6332 ch->num_queue_pairs =
6333 vsi->tc_config.tc_info[i].qcount;
6335 vsi->tc_config.tc_info[i].qoffset;
6337 /* Bandwidth limit through tc interface is in bytes/s,
6340 max_rate = vsi->mqprio_qopt.max_rate[i];
6341 do_div(max_rate, I40E_BW_MBPS_DIVISOR);
6342 ch->max_tx_rate = max_rate;
6344 list_add_tail(&ch->list, &vsi->ch_list);
6346 ret = i40e_create_queue_channel(vsi, ch);
6348 dev_err(&vsi->back->pdev->dev,
6349 "Failed creating queue channel with TC%d: queues %d\n",
6350 i, ch->num_queue_pairs);
6353 vsi->tc_seid_map[i] = ch->seid;
6359 i40e_remove_queue_channels(vsi);
6364 * i40e_veb_config_tc - Configure TCs for given VEB
6366 * @enabled_tc: TC bitmap
6368 * Configures given TC bitmap for VEB (switching) element
6370 int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
6372 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
6373 struct i40e_pf *pf = veb->pf;
6377 /* No TCs or already enabled TCs just return */
6378 if (!enabled_tc || veb->enabled_tc == enabled_tc)
6381 bw_data.tc_valid_bits = enabled_tc;
6382 /* bw_data.absolute_credits is not set (relative) */
6384 /* Enable ETS TCs with equal BW Share for now */
6385 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
6386 if (enabled_tc & BIT(i))
6387 bw_data.tc_bw_share_credits[i] = 1;
6390 ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
6393 dev_info(&pf->pdev->dev,
6394 "VEB bw config failed, err %s aq_err %s\n",
6395 i40e_stat_str(&pf->hw, ret),
6396 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6400 /* Update the BW information */
6401 ret = i40e_veb_get_bw_info(veb);
6403 dev_info(&pf->pdev->dev,
6404 "Failed getting veb bw config, err %s aq_err %s\n",
6405 i40e_stat_str(&pf->hw, ret),
6406 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6413 #ifdef CONFIG_I40E_DCB
6415 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
6418 * Reconfigure VEB/VSIs on a given PF; it is assumed that
6419 * the caller would've quiesce all the VSIs before calling
6422 static void i40e_dcb_reconfigure(struct i40e_pf *pf)
6428 /* Enable the TCs available on PF to all VEBs */
6429 tc_map = i40e_pf_get_tc_map(pf);
6430 if (tc_map == I40E_DEFAULT_TRAFFIC_CLASS)
6433 for (v = 0; v < I40E_MAX_VEB; v++) {
6436 ret = i40e_veb_config_tc(pf->veb[v], tc_map);
6438 dev_info(&pf->pdev->dev,
6439 "Failed configuring TC for VEB seid=%d\n",
6441 /* Will try to configure as many components */
6445 /* Update each VSI */
6446 for (v = 0; v < pf->num_alloc_vsi; v++) {
6450 /* - Enable all TCs for the LAN VSI
6451 * - For all others keep them at TC0 for now
6453 if (v == pf->lan_vsi)
6454 tc_map = i40e_pf_get_tc_map(pf);
6456 tc_map = I40E_DEFAULT_TRAFFIC_CLASS;
6458 ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
6460 dev_info(&pf->pdev->dev,
6461 "Failed configuring TC for VSI seid=%d\n",
6463 /* Will try to configure as many components */
6465 /* Re-configure VSI vectors based on updated TC map */
6466 i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
6467 if (pf->vsi[v]->netdev)
6468 i40e_dcbnl_set_all(pf->vsi[v]);
6474 * i40e_resume_port_tx - Resume port Tx
6477 * Resume a port's Tx and issue a PF reset in case of failure to
6480 static int i40e_resume_port_tx(struct i40e_pf *pf)
6482 struct i40e_hw *hw = &pf->hw;
6485 ret = i40e_aq_resume_port_tx(hw, NULL);
6487 dev_info(&pf->pdev->dev,
6488 "Resume Port Tx failed, err %s aq_err %s\n",
6489 i40e_stat_str(&pf->hw, ret),
6490 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6491 /* Schedule PF reset to recover */
6492 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
6493 i40e_service_event_schedule(pf);
6500 * i40e_suspend_port_tx - Suspend port Tx
6503 * Suspend a port's Tx and issue a PF reset in case of failure.
6505 static int i40e_suspend_port_tx(struct i40e_pf *pf)
6507 struct i40e_hw *hw = &pf->hw;
6510 ret = i40e_aq_suspend_port_tx(hw, pf->mac_seid, NULL);
6512 dev_info(&pf->pdev->dev,
6513 "Suspend Port Tx failed, err %s aq_err %s\n",
6514 i40e_stat_str(&pf->hw, ret),
6515 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6516 /* Schedule PF reset to recover */
6517 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
6518 i40e_service_event_schedule(pf);
6525 * i40e_hw_set_dcb_config - Program new DCBX settings into HW
6526 * @pf: PF being configured
6527 * @new_cfg: New DCBX configuration
6529 * Program DCB settings into HW and reconfigure VEB/VSIs on
6530 * given PF. Uses "Set LLDP MIB" AQC to program the hardware.
6532 static int i40e_hw_set_dcb_config(struct i40e_pf *pf,
6533 struct i40e_dcbx_config *new_cfg)
6535 struct i40e_dcbx_config *old_cfg = &pf->hw.local_dcbx_config;
6538 /* Check if need reconfiguration */
6539 if (!memcmp(&new_cfg, &old_cfg, sizeof(new_cfg))) {
6540 dev_dbg(&pf->pdev->dev, "No Change in DCB Config required.\n");
6544 /* Config change disable all VSIs */
6545 i40e_pf_quiesce_all_vsi(pf);
6547 /* Copy the new config to the current config */
6548 *old_cfg = *new_cfg;
6549 old_cfg->etsrec = old_cfg->etscfg;
6550 ret = i40e_set_dcb_config(&pf->hw);
6552 dev_info(&pf->pdev->dev,
6553 "Set DCB Config failed, err %s aq_err %s\n",
6554 i40e_stat_str(&pf->hw, ret),
6555 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6559 /* Changes in configuration update VEB/VSI */
6560 i40e_dcb_reconfigure(pf);
6562 /* In case of reset do not try to resume anything */
6563 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) {
6564 /* Re-start the VSIs if disabled */
6565 ret = i40e_resume_port_tx(pf);
6566 /* In case of error no point in resuming VSIs */
6569 i40e_pf_unquiesce_all_vsi(pf);
6576 * i40e_hw_dcb_config - Program new DCBX settings into HW
6577 * @pf: PF being configured
6578 * @new_cfg: New DCBX configuration
6580 * Program DCB settings into HW and reconfigure VEB/VSIs on
6583 int i40e_hw_dcb_config(struct i40e_pf *pf, struct i40e_dcbx_config *new_cfg)
6585 struct i40e_aqc_configure_switching_comp_ets_data ets_data;
6586 u8 prio_type[I40E_MAX_TRAFFIC_CLASS] = {0};
6587 u32 mfs_tc[I40E_MAX_TRAFFIC_CLASS];
6588 struct i40e_dcbx_config *old_cfg;
6589 u8 mode[I40E_MAX_TRAFFIC_CLASS];
6590 struct i40e_rx_pb_config pb_cfg;
6591 struct i40e_hw *hw = &pf->hw;
6592 u8 num_ports = hw->num_ports;
6600 dev_dbg(&pf->pdev->dev, "Configuring DCB registers directly\n");
6601 /* Un-pack information to Program ETS HW via shared API
6604 * ETS/NON-ETS arbiter mode
6605 * max exponent (credit refills)
6606 * Total number of ports
6607 * PFC priority bit-map
6610 * Arbiter mode between UPs sharing same TC
6611 * TSA table (ETS or non-ETS)
6612 * EEE enabled or not
6616 new_numtc = i40e_dcb_get_num_tc(new_cfg);
6618 memset(&ets_data, 0, sizeof(ets_data));
6619 for (i = 0; i < new_numtc; i++) {
6621 switch (new_cfg->etscfg.tsatable[i]) {
6622 case I40E_IEEE_TSA_ETS:
6623 prio_type[i] = I40E_DCB_PRIO_TYPE_ETS;
6624 ets_data.tc_bw_share_credits[i] =
6625 new_cfg->etscfg.tcbwtable[i];
6627 case I40E_IEEE_TSA_STRICT:
6628 prio_type[i] = I40E_DCB_PRIO_TYPE_STRICT;
6630 ets_data.tc_bw_share_credits[i] =
6631 I40E_DCB_STRICT_PRIO_CREDITS;
6634 /* Invalid TSA type */
6635 need_reconfig = false;
6640 old_cfg = &hw->local_dcbx_config;
6641 /* Check if need reconfiguration */
6642 need_reconfig = i40e_dcb_need_reconfig(pf, old_cfg, new_cfg);
6644 /* If needed, enable/disable frame tagging, disable all VSIs
6645 * and suspend port tx
6647 if (need_reconfig) {
6648 /* Enable DCB tagging only when more than one TC */
6650 pf->flags |= I40E_FLAG_DCB_ENABLED;
6652 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
6654 set_bit(__I40E_PORT_SUSPENDED, pf->state);
6655 /* Reconfiguration needed quiesce all VSIs */
6656 i40e_pf_quiesce_all_vsi(pf);
6657 ret = i40e_suspend_port_tx(pf);
6662 /* Configure Port ETS Tx Scheduler */
6663 ets_data.tc_valid_bits = tc_map;
6664 ets_data.tc_strict_priority_flags = lltc_map;
6665 ret = i40e_aq_config_switch_comp_ets
6666 (hw, pf->mac_seid, &ets_data,
6667 i40e_aqc_opc_modify_switching_comp_ets, NULL);
6669 dev_info(&pf->pdev->dev,
6670 "Modify Port ETS failed, err %s aq_err %s\n",
6671 i40e_stat_str(&pf->hw, ret),
6672 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6676 /* Configure Rx ETS HW */
6677 memset(&mode, I40E_DCB_ARB_MODE_ROUND_ROBIN, sizeof(mode));
6678 i40e_dcb_hw_set_num_tc(hw, new_numtc);
6679 i40e_dcb_hw_rx_fifo_config(hw, I40E_DCB_ARB_MODE_ROUND_ROBIN,
6680 I40E_DCB_ARB_MODE_STRICT_PRIORITY,
6681 I40E_DCB_DEFAULT_MAX_EXPONENT,
6683 i40e_dcb_hw_rx_cmd_monitor_config(hw, new_numtc, num_ports);
6684 i40e_dcb_hw_rx_ets_bw_config(hw, new_cfg->etscfg.tcbwtable, mode,
6686 i40e_dcb_hw_pfc_config(hw, new_cfg->pfc.pfcenable,
6687 new_cfg->etscfg.prioritytable);
6688 i40e_dcb_hw_rx_up2tc_config(hw, new_cfg->etscfg.prioritytable);
6690 /* Configure Rx Packet Buffers in HW */
6691 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
6692 mfs_tc[i] = pf->vsi[pf->lan_vsi]->netdev->mtu;
6693 mfs_tc[i] += I40E_PACKET_HDR_PAD;
6696 i40e_dcb_hw_calculate_pool_sizes(hw, num_ports,
6697 false, new_cfg->pfc.pfcenable,
6699 i40e_dcb_hw_rx_pb_config(hw, &pf->pb_cfg, &pb_cfg);
6701 /* Update the local Rx Packet buffer config */
6702 pf->pb_cfg = pb_cfg;
6704 /* Inform the FW about changes to DCB configuration */
6705 ret = i40e_aq_dcb_updated(&pf->hw, NULL);
6707 dev_info(&pf->pdev->dev,
6708 "DCB Updated failed, err %s aq_err %s\n",
6709 i40e_stat_str(&pf->hw, ret),
6710 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6714 /* Update the port DCBx configuration */
6715 *old_cfg = *new_cfg;
6717 /* Changes in configuration update VEB/VSI */
6718 i40e_dcb_reconfigure(pf);
6720 /* Re-start the VSIs if disabled */
6721 if (need_reconfig) {
6722 ret = i40e_resume_port_tx(pf);
6724 clear_bit(__I40E_PORT_SUSPENDED, pf->state);
6725 /* In case of error no point in resuming VSIs */
6729 /* Wait for the PF's queues to be disabled */
6730 ret = i40e_pf_wait_queues_disabled(pf);
6732 /* Schedule PF reset to recover */
6733 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
6734 i40e_service_event_schedule(pf);
6737 i40e_pf_unquiesce_all_vsi(pf);
6738 set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
6739 set_bit(__I40E_CLIENT_L2_CHANGE, pf->state);
6741 /* registers are set, lets apply */
6742 if (pf->hw_features & I40E_HW_USE_SET_LLDP_MIB)
6743 ret = i40e_hw_set_dcb_config(pf, new_cfg);
6751 * i40e_dcb_sw_default_config - Set default DCB configuration when DCB in SW
6752 * @pf: PF being queried
6754 * Set default DCB configuration in case DCB is to be done in SW.
6756 int i40e_dcb_sw_default_config(struct i40e_pf *pf)
6758 struct i40e_dcbx_config *dcb_cfg = &pf->hw.local_dcbx_config;
6759 struct i40e_aqc_configure_switching_comp_ets_data ets_data;
6760 struct i40e_hw *hw = &pf->hw;
6763 if (pf->hw_features & I40E_HW_USE_SET_LLDP_MIB) {
6764 /* Update the local cached instance with TC0 ETS */
6765 memset(&pf->tmp_cfg, 0, sizeof(struct i40e_dcbx_config));
6766 pf->tmp_cfg.etscfg.willing = I40E_IEEE_DEFAULT_ETS_WILLING;
6767 pf->tmp_cfg.etscfg.maxtcs = 0;
6768 pf->tmp_cfg.etscfg.tcbwtable[0] = I40E_IEEE_DEFAULT_ETS_TCBW;
6769 pf->tmp_cfg.etscfg.tsatable[0] = I40E_IEEE_TSA_ETS;
6770 pf->tmp_cfg.pfc.willing = I40E_IEEE_DEFAULT_PFC_WILLING;
6771 pf->tmp_cfg.pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
6772 /* FW needs one App to configure HW */
6773 pf->tmp_cfg.numapps = I40E_IEEE_DEFAULT_NUM_APPS;
6774 pf->tmp_cfg.app[0].selector = I40E_APP_SEL_ETHTYPE;
6775 pf->tmp_cfg.app[0].priority = I40E_IEEE_DEFAULT_APP_PRIO;
6776 pf->tmp_cfg.app[0].protocolid = I40E_APP_PROTOID_FCOE;
6778 return i40e_hw_set_dcb_config(pf, &pf->tmp_cfg);
6781 memset(&ets_data, 0, sizeof(ets_data));
6782 ets_data.tc_valid_bits = I40E_DEFAULT_TRAFFIC_CLASS; /* TC0 only */
6783 ets_data.tc_strict_priority_flags = 0; /* ETS */
6784 ets_data.tc_bw_share_credits[0] = I40E_IEEE_DEFAULT_ETS_TCBW; /* 100% to TC0 */
6786 /* Enable ETS on the Physical port */
6787 err = i40e_aq_config_switch_comp_ets
6788 (hw, pf->mac_seid, &ets_data,
6789 i40e_aqc_opc_enable_switching_comp_ets, NULL);
6791 dev_info(&pf->pdev->dev,
6792 "Enable Port ETS failed, err %s aq_err %s\n",
6793 i40e_stat_str(&pf->hw, err),
6794 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6799 /* Update the local cached instance with TC0 ETS */
6800 dcb_cfg->etscfg.willing = I40E_IEEE_DEFAULT_ETS_WILLING;
6801 dcb_cfg->etscfg.cbs = 0;
6802 dcb_cfg->etscfg.maxtcs = I40E_MAX_TRAFFIC_CLASS;
6803 dcb_cfg->etscfg.tcbwtable[0] = I40E_IEEE_DEFAULT_ETS_TCBW;
6810 * i40e_init_pf_dcb - Initialize DCB configuration
6811 * @pf: PF being configured
6813 * Query the current DCB configuration and cache it
6814 * in the hardware structure
6816 static int i40e_init_pf_dcb(struct i40e_pf *pf)
6818 struct i40e_hw *hw = &pf->hw;
6821 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable
6822 * Also do not enable DCBx if FW LLDP agent is disabled
6824 if (pf->hw_features & I40E_HW_NO_DCB_SUPPORT) {
6825 dev_info(&pf->pdev->dev, "DCB is not supported.\n");
6826 err = I40E_NOT_SUPPORTED;
6829 if (pf->flags & I40E_FLAG_DISABLE_FW_LLDP) {
6830 dev_info(&pf->pdev->dev, "FW LLDP is disabled, attempting SW DCB\n");
6831 err = i40e_dcb_sw_default_config(pf);
6833 dev_info(&pf->pdev->dev, "Could not initialize SW DCB\n");
6836 dev_info(&pf->pdev->dev, "SW DCB initialization succeeded.\n");
6837 pf->dcbx_cap = DCB_CAP_DCBX_HOST |
6838 DCB_CAP_DCBX_VER_IEEE;
6839 /* at init capable but disabled */
6840 pf->flags |= I40E_FLAG_DCB_CAPABLE;
6841 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
6844 err = i40e_init_dcb(hw, true);
6846 /* Device/Function is not DCBX capable */
6847 if ((!hw->func_caps.dcb) ||
6848 (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
6849 dev_info(&pf->pdev->dev,
6850 "DCBX offload is not supported or is disabled for this PF.\n");
6852 /* When status is not DISABLED then DCBX in FW */
6853 pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
6854 DCB_CAP_DCBX_VER_IEEE;
6856 pf->flags |= I40E_FLAG_DCB_CAPABLE;
6857 /* Enable DCB tagging only when more than one TC
6858 * or explicitly disable if only one TC
6860 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
6861 pf->flags |= I40E_FLAG_DCB_ENABLED;
6863 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
6864 dev_dbg(&pf->pdev->dev,
6865 "DCBX offload is supported for this PF.\n");
6867 } else if (pf->hw.aq.asq_last_status == I40E_AQ_RC_EPERM) {
6868 dev_info(&pf->pdev->dev, "FW LLDP disabled for this PF.\n");
6869 pf->flags |= I40E_FLAG_DISABLE_FW_LLDP;
6871 dev_info(&pf->pdev->dev,
6872 "Query for DCB configuration failed, err %s aq_err %s\n",
6873 i40e_stat_str(&pf->hw, err),
6874 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6880 #endif /* CONFIG_I40E_DCB */
6883 * i40e_set_lldp_forwarding - set forwarding of lldp frames
6884 * @pf: PF being configured
6885 * @enable: if forwarding to OS shall be enabled
6887 * Toggle forwarding of lldp frames behavior,
6888 * When passing DCB control from firmware to software
6889 * lldp frames must be forwarded to the software based
6892 void i40e_set_lldp_forwarding(struct i40e_pf *pf, bool enable)
6894 if (pf->lan_vsi == I40E_NO_VSI)
6897 if (!pf->vsi[pf->lan_vsi])
6900 /* No need to check the outcome, commands may fail
6901 * if desired value is already set
6903 i40e_aq_add_rem_control_packet_filter(&pf->hw, NULL, ETH_P_LLDP,
6904 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX |
6905 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC,
6906 pf->vsi[pf->lan_vsi]->seid, 0,
6907 enable, NULL, NULL);
6909 i40e_aq_add_rem_control_packet_filter(&pf->hw, NULL, ETH_P_LLDP,
6910 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_RX |
6911 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC,
6912 pf->vsi[pf->lan_vsi]->seid, 0,
6913 enable, NULL, NULL);
6917 * i40e_print_link_message - print link up or down
6918 * @vsi: the VSI for which link needs a message
6919 * @isup: true of link is up, false otherwise
6921 void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
6923 enum i40e_aq_link_speed new_speed;
6924 struct i40e_pf *pf = vsi->back;
6925 char *speed = "Unknown";
6926 char *fc = "Unknown";
6932 new_speed = pf->hw.phy.link_info.link_speed;
6934 new_speed = I40E_LINK_SPEED_UNKNOWN;
6936 if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed))
6938 vsi->current_isup = isup;
6939 vsi->current_speed = new_speed;
6941 netdev_info(vsi->netdev, "NIC Link is Down\n");
6945 /* Warn user if link speed on NPAR enabled partition is not at
6948 if (pf->hw.func_caps.npar_enable &&
6949 (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
6950 pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
6951 netdev_warn(vsi->netdev,
6952 "The partition detected link speed that is less than 10Gbps\n");
6954 switch (pf->hw.phy.link_info.link_speed) {
6955 case I40E_LINK_SPEED_40GB:
6958 case I40E_LINK_SPEED_20GB:
6961 case I40E_LINK_SPEED_25GB:
6964 case I40E_LINK_SPEED_10GB:
6967 case I40E_LINK_SPEED_5GB:
6970 case I40E_LINK_SPEED_2_5GB:
6973 case I40E_LINK_SPEED_1GB:
6976 case I40E_LINK_SPEED_100MB:
6983 switch (pf->hw.fc.current_mode) {
6987 case I40E_FC_TX_PAUSE:
6990 case I40E_FC_RX_PAUSE:
6998 if (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_25GB) {
7003 if (pf->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED)
7006 if (pf->hw.phy.link_info.fec_info &
7007 I40E_AQ_CONFIG_FEC_KR_ENA)
7008 fec = "CL74 FC-FEC/BASE-R";
7009 else if (pf->hw.phy.link_info.fec_info &
7010 I40E_AQ_CONFIG_FEC_RS_ENA)
7011 fec = "CL108 RS-FEC";
7013 /* 'CL108 RS-FEC' should be displayed when RS is requested, or
7014 * both RS and FC are requested
7016 if (vsi->back->hw.phy.link_info.req_fec_info &
7017 (I40E_AQ_REQUEST_FEC_KR | I40E_AQ_REQUEST_FEC_RS)) {
7018 if (vsi->back->hw.phy.link_info.req_fec_info &
7019 I40E_AQ_REQUEST_FEC_RS)
7020 req_fec = "CL108 RS-FEC";
7022 req_fec = "CL74 FC-FEC/BASE-R";
7024 netdev_info(vsi->netdev,
7025 "NIC Link is Up, %sbps Full Duplex, Requested FEC: %s, Negotiated FEC: %s, Autoneg: %s, Flow Control: %s\n",
7026 speed, req_fec, fec, an, fc);
7027 } else if (pf->hw.device_id == I40E_DEV_ID_KX_X722) {
7032 if (pf->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED)
7035 if (pf->hw.phy.link_info.fec_info &
7036 I40E_AQ_CONFIG_FEC_KR_ENA)
7037 fec = "CL74 FC-FEC/BASE-R";
7039 if (pf->hw.phy.link_info.req_fec_info &
7040 I40E_AQ_REQUEST_FEC_KR)
7041 req_fec = "CL74 FC-FEC/BASE-R";
7043 netdev_info(vsi->netdev,
7044 "NIC Link is Up, %sbps Full Duplex, Requested FEC: %s, Negotiated FEC: %s, Autoneg: %s, Flow Control: %s\n",
7045 speed, req_fec, fec, an, fc);
7047 netdev_info(vsi->netdev,
7048 "NIC Link is Up, %sbps Full Duplex, Flow Control: %s\n",
7055 * i40e_up_complete - Finish the last steps of bringing up a connection
7056 * @vsi: the VSI being configured
7058 static int i40e_up_complete(struct i40e_vsi *vsi)
7060 struct i40e_pf *pf = vsi->back;
7063 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7064 i40e_vsi_configure_msix(vsi);
7066 i40e_configure_msi_and_legacy(vsi);
7069 err = i40e_vsi_start_rings(vsi);
7073 clear_bit(__I40E_VSI_DOWN, vsi->state);
7074 i40e_napi_enable_all(vsi);
7075 i40e_vsi_enable_irq(vsi);
7077 if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
7079 i40e_print_link_message(vsi, true);
7080 netif_tx_start_all_queues(vsi->netdev);
7081 netif_carrier_on(vsi->netdev);
7084 /* replay FDIR SB filters */
7085 if (vsi->type == I40E_VSI_FDIR) {
7086 /* reset fd counters */
7089 i40e_fdir_filter_restore(vsi);
7092 /* On the next run of the service_task, notify any clients of the new
7095 set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
7096 i40e_service_event_schedule(pf);
7102 * i40e_vsi_reinit_locked - Reset the VSI
7103 * @vsi: the VSI being configured
7105 * Rebuild the ring structs after some configuration
7106 * has changed, e.g. MTU size.
7108 static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
7110 struct i40e_pf *pf = vsi->back;
7112 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state))
7113 usleep_range(1000, 2000);
7117 clear_bit(__I40E_CONFIG_BUSY, pf->state);
7121 * i40e_force_link_state - Force the link status
7122 * @pf: board private structure
7123 * @is_up: whether the link state should be forced up or down
7125 static i40e_status i40e_force_link_state(struct i40e_pf *pf, bool is_up)
7127 struct i40e_aq_get_phy_abilities_resp abilities;
7128 struct i40e_aq_set_phy_config config = {0};
7129 bool non_zero_phy_type = is_up;
7130 struct i40e_hw *hw = &pf->hw;
7135 /* Card might've been put in an unstable state by other drivers
7136 * and applications, which causes incorrect speed values being
7137 * set on startup. In order to clear speed registers, we call
7138 * get_phy_capabilities twice, once to get initial state of
7139 * available speeds, and once to get current PHY config.
7141 err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities,
7144 dev_err(&pf->pdev->dev,
7145 "failed to get phy cap., ret = %s last_status = %s\n",
7146 i40e_stat_str(hw, err),
7147 i40e_aq_str(hw, hw->aq.asq_last_status));
7150 speed = abilities.link_speed;
7152 /* Get the current phy config */
7153 err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
7156 dev_err(&pf->pdev->dev,
7157 "failed to get phy cap., ret = %s last_status = %s\n",
7158 i40e_stat_str(hw, err),
7159 i40e_aq_str(hw, hw->aq.asq_last_status));
7163 /* If link needs to go up, but was not forced to go down,
7164 * and its speed values are OK, no need for a flap
7165 * if non_zero_phy_type was set, still need to force up
7167 if (pf->flags & I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENABLED)
7168 non_zero_phy_type = true;
7169 else if (is_up && abilities.phy_type != 0 && abilities.link_speed != 0)
7170 return I40E_SUCCESS;
7172 /* To force link we need to set bits for all supported PHY types,
7173 * but there are now more than 32, so we need to split the bitmap
7174 * across two fields.
7176 mask = I40E_PHY_TYPES_BITMASK;
7178 non_zero_phy_type ? cpu_to_le32((u32)(mask & 0xffffffff)) : 0;
7179 config.phy_type_ext =
7180 non_zero_phy_type ? (u8)((mask >> 32) & 0xff) : 0;
7181 /* Copy the old settings, except of phy_type */
7182 config.abilities = abilities.abilities;
7183 if (pf->flags & I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENABLED) {
7185 config.abilities |= I40E_AQ_PHY_ENABLE_LINK;
7187 config.abilities &= ~(I40E_AQ_PHY_ENABLE_LINK);
7189 if (abilities.link_speed != 0)
7190 config.link_speed = abilities.link_speed;
7192 config.link_speed = speed;
7193 config.eee_capability = abilities.eee_capability;
7194 config.eeer = abilities.eeer_val;
7195 config.low_power_ctrl = abilities.d3_lpan;
7196 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
7197 I40E_AQ_PHY_FEC_CONFIG_MASK;
7198 err = i40e_aq_set_phy_config(hw, &config, NULL);
7201 dev_err(&pf->pdev->dev,
7202 "set phy config ret = %s last_status = %s\n",
7203 i40e_stat_str(&pf->hw, err),
7204 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
7208 /* Update the link info */
7209 err = i40e_update_link_info(hw);
7211 /* Wait a little bit (on 40G cards it sometimes takes a really
7212 * long time for link to come back from the atomic reset)
7216 i40e_update_link_info(hw);
7219 i40e_aq_set_link_restart_an(hw, is_up, NULL);
7221 return I40E_SUCCESS;
7225 * i40e_up - Bring the connection back up after being down
7226 * @vsi: the VSI being configured
7228 int i40e_up(struct i40e_vsi *vsi)
7232 if (vsi->type == I40E_VSI_MAIN &&
7233 (vsi->back->flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED ||
7234 vsi->back->flags & I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENABLED))
7235 i40e_force_link_state(vsi->back, true);
7237 err = i40e_vsi_configure(vsi);
7239 err = i40e_up_complete(vsi);
7245 * i40e_down - Shutdown the connection processing
7246 * @vsi: the VSI being stopped
7248 void i40e_down(struct i40e_vsi *vsi)
7252 /* It is assumed that the caller of this function
7253 * sets the vsi->state __I40E_VSI_DOWN bit.
7256 netif_carrier_off(vsi->netdev);
7257 netif_tx_disable(vsi->netdev);
7259 i40e_vsi_disable_irq(vsi);
7260 i40e_vsi_stop_rings(vsi);
7261 if (vsi->type == I40E_VSI_MAIN &&
7262 (vsi->back->flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED ||
7263 vsi->back->flags & I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENABLED))
7264 i40e_force_link_state(vsi->back, false);
7265 i40e_napi_disable_all(vsi);
7267 for (i = 0; i < vsi->num_queue_pairs; i++) {
7268 i40e_clean_tx_ring(vsi->tx_rings[i]);
7269 if (i40e_enabled_xdp_vsi(vsi)) {
7270 /* Make sure that in-progress ndo_xdp_xmit and
7271 * ndo_xsk_wakeup calls are completed.
7274 i40e_clean_tx_ring(vsi->xdp_rings[i]);
7276 i40e_clean_rx_ring(vsi->rx_rings[i]);
7282 * i40e_validate_mqprio_qopt- validate queue mapping info
7283 * @vsi: the VSI being configured
7284 * @mqprio_qopt: queue parametrs
7286 static int i40e_validate_mqprio_qopt(struct i40e_vsi *vsi,
7287 struct tc_mqprio_qopt_offload *mqprio_qopt)
7289 u64 sum_max_rate = 0;
7293 if (mqprio_qopt->qopt.offset[0] != 0 ||
7294 mqprio_qopt->qopt.num_tc < 1 ||
7295 mqprio_qopt->qopt.num_tc > I40E_MAX_TRAFFIC_CLASS)
7297 for (i = 0; ; i++) {
7298 if (!mqprio_qopt->qopt.count[i])
7300 if (mqprio_qopt->min_rate[i]) {
7301 dev_err(&vsi->back->pdev->dev,
7302 "Invalid min tx rate (greater than 0) specified\n");
7305 max_rate = mqprio_qopt->max_rate[i];
7306 do_div(max_rate, I40E_BW_MBPS_DIVISOR);
7307 sum_max_rate += max_rate;
7309 if (i >= mqprio_qopt->qopt.num_tc - 1)
7311 if (mqprio_qopt->qopt.offset[i + 1] !=
7312 (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i]))
7315 if (vsi->num_queue_pairs <
7316 (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i])) {
7319 if (sum_max_rate > i40e_get_link_speed(vsi)) {
7320 dev_err(&vsi->back->pdev->dev,
7321 "Invalid max tx rate specified\n");
7328 * i40e_vsi_set_default_tc_config - set default values for tc configuration
7329 * @vsi: the VSI being configured
7331 static void i40e_vsi_set_default_tc_config(struct i40e_vsi *vsi)
7336 /* Only TC0 is enabled */
7337 vsi->tc_config.numtc = 1;
7338 vsi->tc_config.enabled_tc = 1;
7339 qcount = min_t(int, vsi->alloc_queue_pairs,
7340 i40e_pf_get_max_q_per_tc(vsi->back));
7341 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
7342 /* For the TC that is not enabled set the offset to to default
7343 * queue and allocate one queue for the given TC.
7345 vsi->tc_config.tc_info[i].qoffset = 0;
7347 vsi->tc_config.tc_info[i].qcount = qcount;
7349 vsi->tc_config.tc_info[i].qcount = 1;
7350 vsi->tc_config.tc_info[i].netdev_tc = 0;
7355 * i40e_del_macvlan_filter
7356 * @hw: pointer to the HW structure
7357 * @seid: seid of the channel VSI
7358 * @macaddr: the mac address to apply as a filter
7359 * @aq_err: store the admin Q error
7361 * This function deletes a mac filter on the channel VSI which serves as the
7362 * macvlan. Returns 0 on success.
7364 static i40e_status i40e_del_macvlan_filter(struct i40e_hw *hw, u16 seid,
7365 const u8 *macaddr, int *aq_err)
7367 struct i40e_aqc_remove_macvlan_element_data element;
7370 memset(&element, 0, sizeof(element));
7371 ether_addr_copy(element.mac_addr, macaddr);
7372 element.vlan_tag = 0;
7373 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
7374 status = i40e_aq_remove_macvlan(hw, seid, &element, 1, NULL);
7375 *aq_err = hw->aq.asq_last_status;
7381 * i40e_add_macvlan_filter
7382 * @hw: pointer to the HW structure
7383 * @seid: seid of the channel VSI
7384 * @macaddr: the mac address to apply as a filter
7385 * @aq_err: store the admin Q error
7387 * This function adds a mac filter on the channel VSI which serves as the
7388 * macvlan. Returns 0 on success.
7390 static i40e_status i40e_add_macvlan_filter(struct i40e_hw *hw, u16 seid,
7391 const u8 *macaddr, int *aq_err)
7393 struct i40e_aqc_add_macvlan_element_data element;
7397 ether_addr_copy(element.mac_addr, macaddr);
7398 element.vlan_tag = 0;
7399 element.queue_number = 0;
7400 element.match_method = I40E_AQC_MM_ERR_NO_RES;
7401 cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
7402 element.flags = cpu_to_le16(cmd_flags);
7403 status = i40e_aq_add_macvlan(hw, seid, &element, 1, NULL);
7404 *aq_err = hw->aq.asq_last_status;
7410 * i40e_reset_ch_rings - Reset the queue contexts in a channel
7411 * @vsi: the VSI we want to access
7412 * @ch: the channel we want to access
7414 static void i40e_reset_ch_rings(struct i40e_vsi *vsi, struct i40e_channel *ch)
7416 struct i40e_ring *tx_ring, *rx_ring;
7420 for (i = 0; i < ch->num_queue_pairs; i++) {
7421 pf_q = ch->base_queue + i;
7422 tx_ring = vsi->tx_rings[pf_q];
7424 rx_ring = vsi->rx_rings[pf_q];
7430 * i40e_free_macvlan_channels
7431 * @vsi: the VSI we want to access
7433 * This function frees the Qs of the channel VSI from
7434 * the stack and also deletes the channel VSIs which
7435 * serve as macvlans.
7437 static void i40e_free_macvlan_channels(struct i40e_vsi *vsi)
7439 struct i40e_channel *ch, *ch_tmp;
7442 if (list_empty(&vsi->macvlan_list))
7445 list_for_each_entry_safe(ch, ch_tmp, &vsi->macvlan_list, list) {
7446 struct i40e_vsi *parent_vsi;
7448 if (i40e_is_channel_macvlan(ch)) {
7449 i40e_reset_ch_rings(vsi, ch);
7450 clear_bit(ch->fwd->bit_no, vsi->fwd_bitmask);
7451 netdev_unbind_sb_channel(vsi->netdev, ch->fwd->netdev);
7452 netdev_set_sb_channel(ch->fwd->netdev, 0);
7457 list_del(&ch->list);
7458 parent_vsi = ch->parent_vsi;
7459 if (!parent_vsi || !ch->initialized) {
7464 /* remove the VSI */
7465 ret = i40e_aq_delete_element(&vsi->back->hw, ch->seid,
7468 dev_err(&vsi->back->pdev->dev,
7469 "unable to remove channel (%d) for parent VSI(%d)\n",
7470 ch->seid, parent_vsi->seid);
7473 vsi->macvlan_cnt = 0;
7477 * i40e_fwd_ring_up - bring the macvlan device up
7478 * @vsi: the VSI we want to access
7479 * @vdev: macvlan netdevice
7480 * @fwd: the private fwd structure
7482 static int i40e_fwd_ring_up(struct i40e_vsi *vsi, struct net_device *vdev,
7483 struct i40e_fwd_adapter *fwd)
7485 int ret = 0, num_tc = 1, i, aq_err;
7486 struct i40e_channel *ch, *ch_tmp;
7487 struct i40e_pf *pf = vsi->back;
7488 struct i40e_hw *hw = &pf->hw;
7490 if (list_empty(&vsi->macvlan_list))
7493 /* Go through the list and find an available channel */
7494 list_for_each_entry_safe(ch, ch_tmp, &vsi->macvlan_list, list) {
7495 if (!i40e_is_channel_macvlan(ch)) {
7497 /* record configuration for macvlan interface in vdev */
7498 for (i = 0; i < num_tc; i++)
7499 netdev_bind_sb_channel_queue(vsi->netdev, vdev,
7501 ch->num_queue_pairs,
7503 for (i = 0; i < ch->num_queue_pairs; i++) {
7504 struct i40e_ring *tx_ring, *rx_ring;
7507 pf_q = ch->base_queue + i;
7509 /* Get to TX ring ptr */
7510 tx_ring = vsi->tx_rings[pf_q];
7513 /* Get the RX ring ptr */
7514 rx_ring = vsi->rx_rings[pf_q];
7521 /* Guarantee all rings are updated before we update the
7522 * MAC address filter.
7526 /* Add a mac filter */
7527 ret = i40e_add_macvlan_filter(hw, ch->seid, vdev->dev_addr, &aq_err);
7529 /* if we cannot add the MAC rule then disable the offload */
7530 macvlan_release_l2fw_offload(vdev);
7531 for (i = 0; i < ch->num_queue_pairs; i++) {
7532 struct i40e_ring *rx_ring;
7535 pf_q = ch->base_queue + i;
7536 rx_ring = vsi->rx_rings[pf_q];
7537 rx_ring->netdev = NULL;
7539 dev_info(&pf->pdev->dev,
7540 "Error adding mac filter on macvlan err %s, aq_err %s\n",
7541 i40e_stat_str(hw, ret),
7542 i40e_aq_str(hw, aq_err));
7543 netdev_err(vdev, "L2fwd offload disabled to L2 filter error\n");
7550 * i40e_setup_macvlans - create the channels which will be macvlans
7551 * @vsi: the VSI we want to access
7552 * @macvlan_cnt: no. of macvlans to be setup
7553 * @qcnt: no. of Qs per macvlan
7554 * @vdev: macvlan netdevice
7556 static int i40e_setup_macvlans(struct i40e_vsi *vsi, u16 macvlan_cnt, u16 qcnt,
7557 struct net_device *vdev)
7559 struct i40e_pf *pf = vsi->back;
7560 struct i40e_hw *hw = &pf->hw;
7561 struct i40e_vsi_context ctxt;
7562 u16 sections, qmap, num_qps;
7563 struct i40e_channel *ch;
7564 int i, pow, ret = 0;
7567 if (vsi->type != I40E_VSI_MAIN || !macvlan_cnt)
7570 num_qps = vsi->num_queue_pairs - (macvlan_cnt * qcnt);
7572 /* find the next higher power-of-2 of num queue pairs */
7573 pow = fls(roundup_pow_of_two(num_qps) - 1);
7575 qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
7576 (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
7578 /* Setup context bits for the main VSI */
7579 sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
7580 sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
7581 memset(&ctxt, 0, sizeof(ctxt));
7582 ctxt.seid = vsi->seid;
7583 ctxt.pf_num = vsi->back->hw.pf_id;
7585 ctxt.uplink_seid = vsi->uplink_seid;
7586 ctxt.info = vsi->info;
7587 ctxt.info.tc_mapping[0] = cpu_to_le16(qmap);
7588 ctxt.info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
7589 ctxt.info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
7590 ctxt.info.valid_sections |= cpu_to_le16(sections);
7592 /* Reconfigure RSS for main VSI with new max queue count */
7593 vsi->rss_size = max_t(u16, num_qps, qcnt);
7594 ret = i40e_vsi_config_rss(vsi);
7596 dev_info(&pf->pdev->dev,
7597 "Failed to reconfig RSS for num_queues (%u)\n",
7601 vsi->reconfig_rss = true;
7602 dev_dbg(&vsi->back->pdev->dev,
7603 "Reconfigured RSS with num_queues (%u)\n", vsi->rss_size);
7604 vsi->next_base_queue = num_qps;
7605 vsi->cnt_q_avail = vsi->num_queue_pairs - num_qps;
7607 /* Update the VSI after updating the VSI queue-mapping
7610 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
7612 dev_info(&pf->pdev->dev,
7613 "Update vsi tc config failed, err %s aq_err %s\n",
7614 i40e_stat_str(hw, ret),
7615 i40e_aq_str(hw, hw->aq.asq_last_status));
7618 /* update the local VSI info with updated queue map */
7619 i40e_vsi_update_queue_map(vsi, &ctxt);
7620 vsi->info.valid_sections = 0;
7622 /* Create channels for macvlans */
7623 INIT_LIST_HEAD(&vsi->macvlan_list);
7624 for (i = 0; i < macvlan_cnt; i++) {
7625 ch = kzalloc(sizeof(*ch), GFP_KERNEL);
7630 INIT_LIST_HEAD(&ch->list);
7631 ch->num_queue_pairs = qcnt;
7632 if (!i40e_setup_channel(pf, vsi, ch)) {
7637 ch->parent_vsi = vsi;
7638 vsi->cnt_q_avail -= ch->num_queue_pairs;
7640 list_add_tail(&ch->list, &vsi->macvlan_list);
7646 dev_info(&pf->pdev->dev, "Failed to setup macvlans\n");
7647 i40e_free_macvlan_channels(vsi);
7653 * i40e_fwd_add - configure macvlans
7654 * @netdev: net device to configure
7655 * @vdev: macvlan netdevice
7657 static void *i40e_fwd_add(struct net_device *netdev, struct net_device *vdev)
7659 struct i40e_netdev_priv *np = netdev_priv(netdev);
7660 u16 q_per_macvlan = 0, macvlan_cnt = 0, vectors;
7661 struct i40e_vsi *vsi = np->vsi;
7662 struct i40e_pf *pf = vsi->back;
7663 struct i40e_fwd_adapter *fwd;
7664 int avail_macvlan, ret;
7666 if ((pf->flags & I40E_FLAG_DCB_ENABLED)) {
7667 netdev_info(netdev, "Macvlans are not supported when DCB is enabled\n");
7668 return ERR_PTR(-EINVAL);
7670 if ((pf->flags & I40E_FLAG_TC_MQPRIO)) {
7671 netdev_info(netdev, "Macvlans are not supported when HW TC offload is on\n");
7672 return ERR_PTR(-EINVAL);
7674 if (pf->num_lan_msix < I40E_MIN_MACVLAN_VECTORS) {
7675 netdev_info(netdev, "Not enough vectors available to support macvlans\n");
7676 return ERR_PTR(-EINVAL);
7679 /* The macvlan device has to be a single Q device so that the
7680 * tc_to_txq field can be reused to pick the tx queue.
7682 if (netif_is_multiqueue(vdev))
7683 return ERR_PTR(-ERANGE);
7685 if (!vsi->macvlan_cnt) {
7686 /* reserve bit 0 for the pf device */
7687 set_bit(0, vsi->fwd_bitmask);
7689 /* Try to reserve as many queues as possible for macvlans. First
7690 * reserve 3/4th of max vectors, then half, then quarter and
7691 * calculate Qs per macvlan as you go
7693 vectors = pf->num_lan_msix;
7694 if (vectors <= I40E_MAX_MACVLANS && vectors > 64) {
7695 /* allocate 4 Qs per macvlan and 32 Qs to the PF*/
7697 macvlan_cnt = (vectors - 32) / 4;
7698 } else if (vectors <= 64 && vectors > 32) {
7699 /* allocate 2 Qs per macvlan and 16 Qs to the PF*/
7701 macvlan_cnt = (vectors - 16) / 2;
7702 } else if (vectors <= 32 && vectors > 16) {
7703 /* allocate 1 Q per macvlan and 16 Qs to the PF*/
7705 macvlan_cnt = vectors - 16;
7706 } else if (vectors <= 16 && vectors > 8) {
7707 /* allocate 1 Q per macvlan and 8 Qs to the PF */
7709 macvlan_cnt = vectors - 8;
7711 /* allocate 1 Q per macvlan and 1 Q to the PF */
7713 macvlan_cnt = vectors - 1;
7716 if (macvlan_cnt == 0)
7717 return ERR_PTR(-EBUSY);
7719 /* Quiesce VSI queues */
7720 i40e_quiesce_vsi(vsi);
7722 /* sets up the macvlans but does not "enable" them */
7723 ret = i40e_setup_macvlans(vsi, macvlan_cnt, q_per_macvlan,
7726 return ERR_PTR(ret);
7729 i40e_unquiesce_vsi(vsi);
7731 avail_macvlan = find_first_zero_bit(vsi->fwd_bitmask,
7733 if (avail_macvlan >= I40E_MAX_MACVLANS)
7734 return ERR_PTR(-EBUSY);
7736 /* create the fwd struct */
7737 fwd = kzalloc(sizeof(*fwd), GFP_KERNEL);
7739 return ERR_PTR(-ENOMEM);
7741 set_bit(avail_macvlan, vsi->fwd_bitmask);
7742 fwd->bit_no = avail_macvlan;
7743 netdev_set_sb_channel(vdev, avail_macvlan);
7746 if (!netif_running(netdev))
7749 /* Set fwd ring up */
7750 ret = i40e_fwd_ring_up(vsi, vdev, fwd);
7752 /* unbind the queues and drop the subordinate channel config */
7753 netdev_unbind_sb_channel(netdev, vdev);
7754 netdev_set_sb_channel(vdev, 0);
7757 return ERR_PTR(-EINVAL);
7764 * i40e_del_all_macvlans - Delete all the mac filters on the channels
7765 * @vsi: the VSI we want to access
7767 static void i40e_del_all_macvlans(struct i40e_vsi *vsi)
7769 struct i40e_channel *ch, *ch_tmp;
7770 struct i40e_pf *pf = vsi->back;
7771 struct i40e_hw *hw = &pf->hw;
7772 int aq_err, ret = 0;
7774 if (list_empty(&vsi->macvlan_list))
7777 list_for_each_entry_safe(ch, ch_tmp, &vsi->macvlan_list, list) {
7778 if (i40e_is_channel_macvlan(ch)) {
7779 ret = i40e_del_macvlan_filter(hw, ch->seid,
7780 i40e_channel_mac(ch),
7783 /* Reset queue contexts */
7784 i40e_reset_ch_rings(vsi, ch);
7785 clear_bit(ch->fwd->bit_no, vsi->fwd_bitmask);
7786 netdev_unbind_sb_channel(vsi->netdev,
7788 netdev_set_sb_channel(ch->fwd->netdev, 0);
7797 * i40e_fwd_del - delete macvlan interfaces
7798 * @netdev: net device to configure
7799 * @vdev: macvlan netdevice
7801 static void i40e_fwd_del(struct net_device *netdev, void *vdev)
7803 struct i40e_netdev_priv *np = netdev_priv(netdev);
7804 struct i40e_fwd_adapter *fwd = vdev;
7805 struct i40e_channel *ch, *ch_tmp;
7806 struct i40e_vsi *vsi = np->vsi;
7807 struct i40e_pf *pf = vsi->back;
7808 struct i40e_hw *hw = &pf->hw;
7809 int aq_err, ret = 0;
7811 /* Find the channel associated with the macvlan and del mac filter */
7812 list_for_each_entry_safe(ch, ch_tmp, &vsi->macvlan_list, list) {
7813 if (i40e_is_channel_macvlan(ch) &&
7814 ether_addr_equal(i40e_channel_mac(ch),
7815 fwd->netdev->dev_addr)) {
7816 ret = i40e_del_macvlan_filter(hw, ch->seid,
7817 i40e_channel_mac(ch),
7820 /* Reset queue contexts */
7821 i40e_reset_ch_rings(vsi, ch);
7822 clear_bit(ch->fwd->bit_no, vsi->fwd_bitmask);
7823 netdev_unbind_sb_channel(netdev, fwd->netdev);
7824 netdev_set_sb_channel(fwd->netdev, 0);
7828 dev_info(&pf->pdev->dev,
7829 "Error deleting mac filter on macvlan err %s, aq_err %s\n",
7830 i40e_stat_str(hw, ret),
7831 i40e_aq_str(hw, aq_err));
7839 * i40e_setup_tc - configure multiple traffic classes
7840 * @netdev: net device to configure
7841 * @type_data: tc offload data
7843 static int i40e_setup_tc(struct net_device *netdev, void *type_data)
7845 struct tc_mqprio_qopt_offload *mqprio_qopt = type_data;
7846 struct i40e_netdev_priv *np = netdev_priv(netdev);
7847 struct i40e_vsi *vsi = np->vsi;
7848 struct i40e_pf *pf = vsi->back;
7849 u8 enabled_tc = 0, num_tc, hw;
7850 bool need_reset = false;
7851 int old_queue_pairs;
7856 old_queue_pairs = vsi->num_queue_pairs;
7857 num_tc = mqprio_qopt->qopt.num_tc;
7858 hw = mqprio_qopt->qopt.hw;
7859 mode = mqprio_qopt->mode;
7861 pf->flags &= ~I40E_FLAG_TC_MQPRIO;
7862 memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt));
7866 /* Check if MFP enabled */
7867 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
7869 "Configuring TC not supported in MFP mode\n");
7873 case TC_MQPRIO_MODE_DCB:
7874 pf->flags &= ~I40E_FLAG_TC_MQPRIO;
7876 /* Check if DCB enabled to continue */
7877 if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
7879 "DCB is not enabled for adapter\n");
7883 /* Check whether tc count is within enabled limit */
7884 if (num_tc > i40e_pf_get_num_tc(pf)) {
7886 "TC count greater than enabled on link for adapter\n");
7890 case TC_MQPRIO_MODE_CHANNEL:
7891 if (pf->flags & I40E_FLAG_DCB_ENABLED) {
7893 "Full offload of TC Mqprio options is not supported when DCB is enabled\n");
7896 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
7898 ret = i40e_validate_mqprio_qopt(vsi, mqprio_qopt);
7901 memcpy(&vsi->mqprio_qopt, mqprio_qopt,
7902 sizeof(*mqprio_qopt));
7903 pf->flags |= I40E_FLAG_TC_MQPRIO;
7904 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
7911 /* Generate TC map for number of tc requested */
7912 for (i = 0; i < num_tc; i++)
7913 enabled_tc |= BIT(i);
7915 /* Requesting same TC configuration as already enabled */
7916 if (enabled_tc == vsi->tc_config.enabled_tc &&
7917 mode != TC_MQPRIO_MODE_CHANNEL)
7920 /* Quiesce VSI queues */
7921 i40e_quiesce_vsi(vsi);
7923 if (!hw && !(pf->flags & I40E_FLAG_TC_MQPRIO))
7924 i40e_remove_queue_channels(vsi);
7926 /* Configure VSI for enabled TCs */
7927 ret = i40e_vsi_config_tc(vsi, enabled_tc);
7929 netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
7934 dev_info(&vsi->back->pdev->dev,
7935 "Setup channel (id:%u) utilizing num_queues %d\n",
7936 vsi->seid, vsi->tc_config.tc_info[0].qcount);
7939 if (pf->flags & I40E_FLAG_TC_MQPRIO) {
7940 if (vsi->mqprio_qopt.max_rate[0]) {
7941 u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
7943 do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
7944 ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
7946 u64 credits = max_tx_rate;
7948 do_div(credits, I40E_BW_CREDIT_DIVISOR);
7949 dev_dbg(&vsi->back->pdev->dev,
7950 "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
7959 ret = i40e_configure_queue_channels(vsi);
7961 vsi->num_queue_pairs = old_queue_pairs;
7963 "Failed configuring queue channels\n");
7970 /* Reset the configuration data to defaults, only TC0 is enabled */
7972 i40e_vsi_set_default_tc_config(vsi);
7977 i40e_unquiesce_vsi(vsi);
7982 * i40e_set_cld_element - sets cloud filter element data
7983 * @filter: cloud filter rule
7984 * @cld: ptr to cloud filter element data
7986 * This is helper function to copy data into cloud filter element
7989 i40e_set_cld_element(struct i40e_cloud_filter *filter,
7990 struct i40e_aqc_cloud_filters_element_data *cld)
7995 memset(cld, 0, sizeof(*cld));
7996 ether_addr_copy(cld->outer_mac, filter->dst_mac);
7997 ether_addr_copy(cld->inner_mac, filter->src_mac);
7999 if (filter->n_proto != ETH_P_IP && filter->n_proto != ETH_P_IPV6)
8002 if (filter->n_proto == ETH_P_IPV6) {
8003 #define IPV6_MAX_INDEX (ARRAY_SIZE(filter->dst_ipv6) - 1)
8004 for (i = 0; i < ARRAY_SIZE(filter->dst_ipv6); i++) {
8005 ipa = be32_to_cpu(filter->dst_ipv6[IPV6_MAX_INDEX - i]);
8007 *(__le32 *)&cld->ipaddr.raw_v6.data[i * 2] = cpu_to_le32(ipa);
8010 ipa = be32_to_cpu(filter->dst_ipv4);
8012 memcpy(&cld->ipaddr.v4.data, &ipa, sizeof(ipa));
8015 cld->inner_vlan = cpu_to_le16(ntohs(filter->vlan_id));
8017 /* tenant_id is not supported by FW now, once the support is enabled
8018 * fill the cld->tenant_id with cpu_to_le32(filter->tenant_id)
8020 if (filter->tenant_id)
8025 * i40e_add_del_cloud_filter - Add/del cloud filter
8026 * @vsi: pointer to VSI
8027 * @filter: cloud filter rule
8028 * @add: if true, add, if false, delete
8030 * Add or delete a cloud filter for a specific flow spec.
8031 * Returns 0 if the filter were successfully added.
8033 int i40e_add_del_cloud_filter(struct i40e_vsi *vsi,
8034 struct i40e_cloud_filter *filter, bool add)
8036 struct i40e_aqc_cloud_filters_element_data cld_filter;
8037 struct i40e_pf *pf = vsi->back;
8039 static const u16 flag_table[128] = {
8040 [I40E_CLOUD_FILTER_FLAGS_OMAC] =
8041 I40E_AQC_ADD_CLOUD_FILTER_OMAC,
8042 [I40E_CLOUD_FILTER_FLAGS_IMAC] =
8043 I40E_AQC_ADD_CLOUD_FILTER_IMAC,
8044 [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN] =
8045 I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN,
8046 [I40E_CLOUD_FILTER_FLAGS_IMAC_TEN_ID] =
8047 I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID,
8048 [I40E_CLOUD_FILTER_FLAGS_OMAC_TEN_ID_IMAC] =
8049 I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC,
8050 [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN_TEN_ID] =
8051 I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID,
8052 [I40E_CLOUD_FILTER_FLAGS_IIP] =
8053 I40E_AQC_ADD_CLOUD_FILTER_IIP,
8056 if (filter->flags >= ARRAY_SIZE(flag_table))
8057 return I40E_ERR_CONFIG;
8059 memset(&cld_filter, 0, sizeof(cld_filter));
8061 /* copy element needed to add cloud filter from filter */
8062 i40e_set_cld_element(filter, &cld_filter);
8064 if (filter->tunnel_type != I40E_CLOUD_TNL_TYPE_NONE)
8065 cld_filter.flags = cpu_to_le16(filter->tunnel_type <<
8066 I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT);
8068 if (filter->n_proto == ETH_P_IPV6)
8069 cld_filter.flags |= cpu_to_le16(flag_table[filter->flags] |
8070 I40E_AQC_ADD_CLOUD_FLAGS_IPV6);
8072 cld_filter.flags |= cpu_to_le16(flag_table[filter->flags] |
8073 I40E_AQC_ADD_CLOUD_FLAGS_IPV4);
8076 ret = i40e_aq_add_cloud_filters(&pf->hw, filter->seid,
8079 ret = i40e_aq_rem_cloud_filters(&pf->hw, filter->seid,
8082 dev_dbg(&pf->pdev->dev,
8083 "Failed to %s cloud filter using l4 port %u, err %d aq_err %d\n",
8084 add ? "add" : "delete", filter->dst_port, ret,
8085 pf->hw.aq.asq_last_status);
8087 dev_info(&pf->pdev->dev,
8088 "%s cloud filter for VSI: %d\n",
8089 add ? "Added" : "Deleted", filter->seid);
8094 * i40e_add_del_cloud_filter_big_buf - Add/del cloud filter using big_buf
8095 * @vsi: pointer to VSI
8096 * @filter: cloud filter rule
8097 * @add: if true, add, if false, delete
8099 * Add or delete a cloud filter for a specific flow spec using big buffer.
8100 * Returns 0 if the filter were successfully added.
8102 int i40e_add_del_cloud_filter_big_buf(struct i40e_vsi *vsi,
8103 struct i40e_cloud_filter *filter,
8106 struct i40e_aqc_cloud_filters_element_bb cld_filter;
8107 struct i40e_pf *pf = vsi->back;
8110 /* Both (src/dst) valid mac_addr are not supported */
8111 if ((is_valid_ether_addr(filter->dst_mac) &&
8112 is_valid_ether_addr(filter->src_mac)) ||
8113 (is_multicast_ether_addr(filter->dst_mac) &&
8114 is_multicast_ether_addr(filter->src_mac)))
8117 /* Big buffer cloud filter needs 'L4 port' to be non-zero. Also, UDP
8118 * ports are not supported via big buffer now.
8120 if (!filter->dst_port || filter->ip_proto == IPPROTO_UDP)
8123 /* adding filter using src_port/src_ip is not supported at this stage */
8124 if (filter->src_port ||
8125 (filter->src_ipv4 && filter->n_proto != ETH_P_IPV6) ||
8126 !ipv6_addr_any(&filter->ip.v6.src_ip6))
8129 memset(&cld_filter, 0, sizeof(cld_filter));
8131 /* copy element needed to add cloud filter from filter */
8132 i40e_set_cld_element(filter, &cld_filter.element);
8134 if (is_valid_ether_addr(filter->dst_mac) ||
8135 is_valid_ether_addr(filter->src_mac) ||
8136 is_multicast_ether_addr(filter->dst_mac) ||
8137 is_multicast_ether_addr(filter->src_mac)) {
8138 /* MAC + IP : unsupported mode */
8139 if (filter->dst_ipv4)
8142 /* since we validated that L4 port must be valid before
8143 * we get here, start with respective "flags" value
8144 * and update if vlan is present or not
8146 cld_filter.element.flags =
8147 cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_PORT);
8149 if (filter->vlan_id) {
8150 cld_filter.element.flags =
8151 cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_VLAN_PORT);
8154 } else if ((filter->dst_ipv4 && filter->n_proto != ETH_P_IPV6) ||
8155 !ipv6_addr_any(&filter->ip.v6.dst_ip6)) {
8156 cld_filter.element.flags =
8157 cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_IP_PORT);
8158 if (filter->n_proto == ETH_P_IPV6)
8159 cld_filter.element.flags |=
8160 cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV6);
8162 cld_filter.element.flags |=
8163 cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV4);
8165 dev_err(&pf->pdev->dev,
8166 "either mac or ip has to be valid for cloud filter\n");
8170 /* Now copy L4 port in Byte 6..7 in general fields */
8171 cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X16_WORD0] =
8172 be16_to_cpu(filter->dst_port);
8175 /* Validate current device switch mode, change if necessary */
8176 ret = i40e_validate_and_set_switch_mode(vsi);
8178 dev_err(&pf->pdev->dev,
8179 "failed to set switch mode, ret %d\n",
8184 ret = i40e_aq_add_cloud_filters_bb(&pf->hw, filter->seid,
8187 ret = i40e_aq_rem_cloud_filters_bb(&pf->hw, filter->seid,
8192 dev_dbg(&pf->pdev->dev,
8193 "Failed to %s cloud filter(big buffer) err %d aq_err %d\n",
8194 add ? "add" : "delete", ret, pf->hw.aq.asq_last_status);
8196 dev_info(&pf->pdev->dev,
8197 "%s cloud filter for VSI: %d, L4 port: %d\n",
8198 add ? "add" : "delete", filter->seid,
8199 ntohs(filter->dst_port));
8204 * i40e_parse_cls_flower - Parse tc flower filters provided by kernel
8205 * @vsi: Pointer to VSI
8206 * @f: Pointer to struct flow_cls_offload
8207 * @filter: Pointer to cloud filter structure
8210 static int i40e_parse_cls_flower(struct i40e_vsi *vsi,
8211 struct flow_cls_offload *f,
8212 struct i40e_cloud_filter *filter)
8214 struct flow_rule *rule = flow_cls_offload_flow_rule(f);
8215 struct flow_dissector *dissector = rule->match.dissector;
8216 u16 n_proto_mask = 0, n_proto_key = 0, addr_type = 0;
8217 struct i40e_pf *pf = vsi->back;
8220 if (dissector->used_keys &
8221 ~(BIT(FLOW_DISSECTOR_KEY_CONTROL) |
8222 BIT(FLOW_DISSECTOR_KEY_BASIC) |
8223 BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) |
8224 BIT(FLOW_DISSECTOR_KEY_VLAN) |
8225 BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
8226 BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
8227 BIT(FLOW_DISSECTOR_KEY_PORTS) |
8228 BIT(FLOW_DISSECTOR_KEY_ENC_KEYID))) {
8229 dev_err(&pf->pdev->dev, "Unsupported key used: 0x%x\n",
8230 dissector->used_keys);
8234 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_KEYID)) {
8235 struct flow_match_enc_keyid match;
8237 flow_rule_match_enc_keyid(rule, &match);
8238 if (match.mask->keyid != 0)
8239 field_flags |= I40E_CLOUD_FIELD_TEN_ID;
8241 filter->tenant_id = be32_to_cpu(match.key->keyid);
8244 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) {
8245 struct flow_match_basic match;
8247 flow_rule_match_basic(rule, &match);
8248 n_proto_key = ntohs(match.key->n_proto);
8249 n_proto_mask = ntohs(match.mask->n_proto);
8251 if (n_proto_key == ETH_P_ALL) {
8255 filter->n_proto = n_proto_key & n_proto_mask;
8256 filter->ip_proto = match.key->ip_proto;
8259 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
8260 struct flow_match_eth_addrs match;
8262 flow_rule_match_eth_addrs(rule, &match);
8264 /* use is_broadcast and is_zero to check for all 0xf or 0 */
8265 if (!is_zero_ether_addr(match.mask->dst)) {
8266 if (is_broadcast_ether_addr(match.mask->dst)) {
8267 field_flags |= I40E_CLOUD_FIELD_OMAC;
8269 dev_err(&pf->pdev->dev, "Bad ether dest mask %pM\n",
8271 return I40E_ERR_CONFIG;
8275 if (!is_zero_ether_addr(match.mask->src)) {
8276 if (is_broadcast_ether_addr(match.mask->src)) {
8277 field_flags |= I40E_CLOUD_FIELD_IMAC;
8279 dev_err(&pf->pdev->dev, "Bad ether src mask %pM\n",
8281 return I40E_ERR_CONFIG;
8284 ether_addr_copy(filter->dst_mac, match.key->dst);
8285 ether_addr_copy(filter->src_mac, match.key->src);
8288 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_VLAN)) {
8289 struct flow_match_vlan match;
8291 flow_rule_match_vlan(rule, &match);
8292 if (match.mask->vlan_id) {
8293 if (match.mask->vlan_id == VLAN_VID_MASK) {
8294 field_flags |= I40E_CLOUD_FIELD_IVLAN;
8297 dev_err(&pf->pdev->dev, "Bad vlan mask 0x%04x\n",
8298 match.mask->vlan_id);
8299 return I40E_ERR_CONFIG;
8303 filter->vlan_id = cpu_to_be16(match.key->vlan_id);
8306 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL)) {
8307 struct flow_match_control match;
8309 flow_rule_match_control(rule, &match);
8310 addr_type = match.key->addr_type;
8313 if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
8314 struct flow_match_ipv4_addrs match;
8316 flow_rule_match_ipv4_addrs(rule, &match);
8317 if (match.mask->dst) {
8318 if (match.mask->dst == cpu_to_be32(0xffffffff)) {
8319 field_flags |= I40E_CLOUD_FIELD_IIP;
8321 dev_err(&pf->pdev->dev, "Bad ip dst mask %pI4b\n",
8323 return I40E_ERR_CONFIG;
8327 if (match.mask->src) {
8328 if (match.mask->src == cpu_to_be32(0xffffffff)) {
8329 field_flags |= I40E_CLOUD_FIELD_IIP;
8331 dev_err(&pf->pdev->dev, "Bad ip src mask %pI4b\n",
8333 return I40E_ERR_CONFIG;
8337 if (field_flags & I40E_CLOUD_FIELD_TEN_ID) {
8338 dev_err(&pf->pdev->dev, "Tenant id not allowed for ip filter\n");
8339 return I40E_ERR_CONFIG;
8341 filter->dst_ipv4 = match.key->dst;
8342 filter->src_ipv4 = match.key->src;
8345 if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) {
8346 struct flow_match_ipv6_addrs match;
8348 flow_rule_match_ipv6_addrs(rule, &match);
8350 /* src and dest IPV6 address should not be LOOPBACK
8351 * (0:0:0:0:0:0:0:1), which can be represented as ::1
8353 if (ipv6_addr_loopback(&match.key->dst) ||
8354 ipv6_addr_loopback(&match.key->src)) {
8355 dev_err(&pf->pdev->dev,
8356 "Bad ipv6, addr is LOOPBACK\n");
8357 return I40E_ERR_CONFIG;
8359 if (!ipv6_addr_any(&match.mask->dst) ||
8360 !ipv6_addr_any(&match.mask->src))
8361 field_flags |= I40E_CLOUD_FIELD_IIP;
8363 memcpy(&filter->src_ipv6, &match.key->src.s6_addr32,
8364 sizeof(filter->src_ipv6));
8365 memcpy(&filter->dst_ipv6, &match.key->dst.s6_addr32,
8366 sizeof(filter->dst_ipv6));
8369 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_PORTS)) {
8370 struct flow_match_ports match;
8372 flow_rule_match_ports(rule, &match);
8373 if (match.mask->src) {
8374 if (match.mask->src == cpu_to_be16(0xffff)) {
8375 field_flags |= I40E_CLOUD_FIELD_IIP;
8377 dev_err(&pf->pdev->dev, "Bad src port mask 0x%04x\n",
8378 be16_to_cpu(match.mask->src));
8379 return I40E_ERR_CONFIG;
8383 if (match.mask->dst) {
8384 if (match.mask->dst == cpu_to_be16(0xffff)) {
8385 field_flags |= I40E_CLOUD_FIELD_IIP;
8387 dev_err(&pf->pdev->dev, "Bad dst port mask 0x%04x\n",
8388 be16_to_cpu(match.mask->dst));
8389 return I40E_ERR_CONFIG;
8393 filter->dst_port = match.key->dst;
8394 filter->src_port = match.key->src;
8396 switch (filter->ip_proto) {
8401 dev_err(&pf->pdev->dev,
8402 "Only UDP and TCP transport are supported\n");
8406 filter->flags = field_flags;
8411 * i40e_handle_tclass: Forward to a traffic class on the device
8412 * @vsi: Pointer to VSI
8413 * @tc: traffic class index on the device
8414 * @filter: Pointer to cloud filter structure
8417 static int i40e_handle_tclass(struct i40e_vsi *vsi, u32 tc,
8418 struct i40e_cloud_filter *filter)
8420 struct i40e_channel *ch, *ch_tmp;
8422 /* direct to a traffic class on the same device */
8424 filter->seid = vsi->seid;
8426 } else if (vsi->tc_config.enabled_tc & BIT(tc)) {
8427 if (!filter->dst_port) {
8428 dev_err(&vsi->back->pdev->dev,
8429 "Specify destination port to direct to traffic class that is not default\n");
8432 if (list_empty(&vsi->ch_list))
8434 list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list,
8436 if (ch->seid == vsi->tc_seid_map[tc])
8437 filter->seid = ch->seid;
8441 dev_err(&vsi->back->pdev->dev, "TC is not enabled\n");
8446 * i40e_configure_clsflower - Configure tc flower filters
8447 * @vsi: Pointer to VSI
8448 * @cls_flower: Pointer to struct flow_cls_offload
8451 static int i40e_configure_clsflower(struct i40e_vsi *vsi,
8452 struct flow_cls_offload *cls_flower)
8454 int tc = tc_classid_to_hwtc(vsi->netdev, cls_flower->classid);
8455 struct i40e_cloud_filter *filter = NULL;
8456 struct i40e_pf *pf = vsi->back;
8460 dev_err(&vsi->back->pdev->dev, "Invalid traffic class\n");
8464 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
8465 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
8468 if (pf->fdir_pf_active_filters ||
8469 (!hlist_empty(&pf->fdir_filter_list))) {
8470 dev_err(&vsi->back->pdev->dev,
8471 "Flow Director Sideband filters exists, turn ntuple off to configure cloud filters\n");
8475 if (vsi->back->flags & I40E_FLAG_FD_SB_ENABLED) {
8476 dev_err(&vsi->back->pdev->dev,
8477 "Disable Flow Director Sideband, configuring Cloud filters via tc-flower\n");
8478 vsi->back->flags &= ~I40E_FLAG_FD_SB_ENABLED;
8479 vsi->back->flags |= I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
8482 filter = kzalloc(sizeof(*filter), GFP_KERNEL);
8486 filter->cookie = cls_flower->cookie;
8488 err = i40e_parse_cls_flower(vsi, cls_flower, filter);
8492 err = i40e_handle_tclass(vsi, tc, filter);
8496 /* Add cloud filter */
8497 if (filter->dst_port)
8498 err = i40e_add_del_cloud_filter_big_buf(vsi, filter, true);
8500 err = i40e_add_del_cloud_filter(vsi, filter, true);
8503 dev_err(&pf->pdev->dev,
8504 "Failed to add cloud filter, err %s\n",
8505 i40e_stat_str(&pf->hw, err));
8509 /* add filter to the ordered list */
8510 INIT_HLIST_NODE(&filter->cloud_node);
8512 hlist_add_head(&filter->cloud_node, &pf->cloud_filter_list);
8514 pf->num_cloud_filters++;
8523 * i40e_find_cloud_filter - Find the could filter in the list
8524 * @vsi: Pointer to VSI
8525 * @cookie: filter specific cookie
8528 static struct i40e_cloud_filter *i40e_find_cloud_filter(struct i40e_vsi *vsi,
8529 unsigned long *cookie)
8531 struct i40e_cloud_filter *filter = NULL;
8532 struct hlist_node *node2;
8534 hlist_for_each_entry_safe(filter, node2,
8535 &vsi->back->cloud_filter_list, cloud_node)
8536 if (!memcmp(cookie, &filter->cookie, sizeof(filter->cookie)))
8542 * i40e_delete_clsflower - Remove tc flower filters
8543 * @vsi: Pointer to VSI
8544 * @cls_flower: Pointer to struct flow_cls_offload
8547 static int i40e_delete_clsflower(struct i40e_vsi *vsi,
8548 struct flow_cls_offload *cls_flower)
8550 struct i40e_cloud_filter *filter = NULL;
8551 struct i40e_pf *pf = vsi->back;
8554 filter = i40e_find_cloud_filter(vsi, &cls_flower->cookie);
8559 hash_del(&filter->cloud_node);
8561 if (filter->dst_port)
8562 err = i40e_add_del_cloud_filter_big_buf(vsi, filter, false);
8564 err = i40e_add_del_cloud_filter(vsi, filter, false);
8568 dev_err(&pf->pdev->dev,
8569 "Failed to delete cloud filter, err %s\n",
8570 i40e_stat_str(&pf->hw, err));
8571 return i40e_aq_rc_to_posix(err, pf->hw.aq.asq_last_status);
8574 pf->num_cloud_filters--;
8575 if (!pf->num_cloud_filters)
8576 if ((pf->flags & I40E_FLAG_FD_SB_TO_CLOUD_FILTER) &&
8577 !(pf->flags & I40E_FLAG_FD_SB_INACTIVE)) {
8578 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
8579 pf->flags &= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
8580 pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
8586 * i40e_setup_tc_cls_flower - flower classifier offloads
8587 * @np: net device to configure
8588 * @cls_flower: offload data
8590 static int i40e_setup_tc_cls_flower(struct i40e_netdev_priv *np,
8591 struct flow_cls_offload *cls_flower)
8593 struct i40e_vsi *vsi = np->vsi;
8595 switch (cls_flower->command) {
8596 case FLOW_CLS_REPLACE:
8597 return i40e_configure_clsflower(vsi, cls_flower);
8598 case FLOW_CLS_DESTROY:
8599 return i40e_delete_clsflower(vsi, cls_flower);
8600 case FLOW_CLS_STATS:
8607 static int i40e_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
8610 struct i40e_netdev_priv *np = cb_priv;
8612 if (!tc_cls_can_offload_and_chain0(np->vsi->netdev, type_data))
8616 case TC_SETUP_CLSFLOWER:
8617 return i40e_setup_tc_cls_flower(np, type_data);
8624 static LIST_HEAD(i40e_block_cb_list);
8626 static int __i40e_setup_tc(struct net_device *netdev, enum tc_setup_type type,
8629 struct i40e_netdev_priv *np = netdev_priv(netdev);
8632 case TC_SETUP_QDISC_MQPRIO:
8633 return i40e_setup_tc(netdev, type_data);
8634 case TC_SETUP_BLOCK:
8635 return flow_block_cb_setup_simple(type_data,
8636 &i40e_block_cb_list,
8637 i40e_setup_tc_block_cb,
8645 * i40e_open - Called when a network interface is made active
8646 * @netdev: network interface device structure
8648 * The open entry point is called when a network interface is made
8649 * active by the system (IFF_UP). At this point all resources needed
8650 * for transmit and receive operations are allocated, the interrupt
8651 * handler is registered with the OS, the netdev watchdog subtask is
8652 * enabled, and the stack is notified that the interface is ready.
8654 * Returns 0 on success, negative value on failure
8656 int i40e_open(struct net_device *netdev)
8658 struct i40e_netdev_priv *np = netdev_priv(netdev);
8659 struct i40e_vsi *vsi = np->vsi;
8660 struct i40e_pf *pf = vsi->back;
8663 /* disallow open during test or if eeprom is broken */
8664 if (test_bit(__I40E_TESTING, pf->state) ||
8665 test_bit(__I40E_BAD_EEPROM, pf->state))
8668 netif_carrier_off(netdev);
8670 if (i40e_force_link_state(pf, true))
8673 err = i40e_vsi_open(vsi);
8677 /* configure global TSO hardware offload settings */
8678 wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
8679 TCP_FLAG_FIN) >> 16);
8680 wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
8682 TCP_FLAG_CWR) >> 16);
8683 wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
8684 udp_tunnel_get_rx_info(netdev);
8691 * @vsi: the VSI to open
8693 * Finish initialization of the VSI.
8695 * Returns 0 on success, negative value on failure
8697 * Note: expects to be called while under rtnl_lock()
8699 int i40e_vsi_open(struct i40e_vsi *vsi)
8701 struct i40e_pf *pf = vsi->back;
8702 char int_name[I40E_INT_NAME_STR_LEN];
8705 /* allocate descriptors */
8706 err = i40e_vsi_setup_tx_resources(vsi);
8709 err = i40e_vsi_setup_rx_resources(vsi);
8713 err = i40e_vsi_configure(vsi);
8718 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
8719 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
8720 err = i40e_vsi_request_irq(vsi, int_name);
8724 /* Notify the stack of the actual queue counts. */
8725 err = netif_set_real_num_tx_queues(vsi->netdev,
8726 vsi->num_queue_pairs);
8728 goto err_set_queues;
8730 err = netif_set_real_num_rx_queues(vsi->netdev,
8731 vsi->num_queue_pairs);
8733 goto err_set_queues;
8735 } else if (vsi->type == I40E_VSI_FDIR) {
8736 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
8737 dev_driver_string(&pf->pdev->dev),
8738 dev_name(&pf->pdev->dev));
8739 err = i40e_vsi_request_irq(vsi, int_name);
8746 err = i40e_up_complete(vsi);
8748 goto err_up_complete;
8755 i40e_vsi_free_irq(vsi);
8757 i40e_vsi_free_rx_resources(vsi);
8759 i40e_vsi_free_tx_resources(vsi);
8760 if (vsi == pf->vsi[pf->lan_vsi])
8761 i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
8767 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
8768 * @pf: Pointer to PF
8770 * This function destroys the hlist where all the Flow Director
8771 * filters were saved.
8773 static void i40e_fdir_filter_exit(struct i40e_pf *pf)
8775 struct i40e_fdir_filter *filter;
8776 struct i40e_flex_pit *pit_entry, *tmp;
8777 struct hlist_node *node2;
8779 hlist_for_each_entry_safe(filter, node2,
8780 &pf->fdir_filter_list, fdir_node) {
8781 hlist_del(&filter->fdir_node);
8785 list_for_each_entry_safe(pit_entry, tmp, &pf->l3_flex_pit_list, list) {
8786 list_del(&pit_entry->list);
8789 INIT_LIST_HEAD(&pf->l3_flex_pit_list);
8791 list_for_each_entry_safe(pit_entry, tmp, &pf->l4_flex_pit_list, list) {
8792 list_del(&pit_entry->list);
8795 INIT_LIST_HEAD(&pf->l4_flex_pit_list);
8797 pf->fdir_pf_active_filters = 0;
8798 i40e_reset_fdir_filter_cnt(pf);
8800 /* Reprogram the default input set for TCP/IPv4 */
8801 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
8802 I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
8803 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
8805 /* Reprogram the default input set for TCP/IPv6 */
8806 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV6_TCP,
8807 I40E_L3_V6_SRC_MASK | I40E_L3_V6_DST_MASK |
8808 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
8810 /* Reprogram the default input set for UDP/IPv4 */
8811 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_UDP,
8812 I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
8813 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
8815 /* Reprogram the default input set for UDP/IPv6 */
8816 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV6_UDP,
8817 I40E_L3_V6_SRC_MASK | I40E_L3_V6_DST_MASK |
8818 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
8820 /* Reprogram the default input set for SCTP/IPv4 */
8821 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_SCTP,
8822 I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
8823 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
8825 /* Reprogram the default input set for SCTP/IPv6 */
8826 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV6_SCTP,
8827 I40E_L3_V6_SRC_MASK | I40E_L3_V6_DST_MASK |
8828 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
8830 /* Reprogram the default input set for Other/IPv4 */
8831 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_OTHER,
8832 I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
8834 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_FRAG_IPV4,
8835 I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
8837 /* Reprogram the default input set for Other/IPv6 */
8838 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV6_OTHER,
8839 I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
8841 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_FRAG_IPV6,
8842 I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
8846 * i40e_cloud_filter_exit - Cleans up the cloud filters
8847 * @pf: Pointer to PF
8849 * This function destroys the hlist where all the cloud filters
8852 static void i40e_cloud_filter_exit(struct i40e_pf *pf)
8854 struct i40e_cloud_filter *cfilter;
8855 struct hlist_node *node;
8857 hlist_for_each_entry_safe(cfilter, node,
8858 &pf->cloud_filter_list, cloud_node) {
8859 hlist_del(&cfilter->cloud_node);
8862 pf->num_cloud_filters = 0;
8864 if ((pf->flags & I40E_FLAG_FD_SB_TO_CLOUD_FILTER) &&
8865 !(pf->flags & I40E_FLAG_FD_SB_INACTIVE)) {
8866 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
8867 pf->flags &= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
8868 pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
8873 * i40e_close - Disables a network interface
8874 * @netdev: network interface device structure
8876 * The close entry point is called when an interface is de-activated
8877 * by the OS. The hardware is still under the driver's control, but
8878 * this netdev interface is disabled.
8880 * Returns 0, this is not allowed to fail
8882 int i40e_close(struct net_device *netdev)
8884 struct i40e_netdev_priv *np = netdev_priv(netdev);
8885 struct i40e_vsi *vsi = np->vsi;
8887 i40e_vsi_close(vsi);
8893 * i40e_do_reset - Start a PF or Core Reset sequence
8894 * @pf: board private structure
8895 * @reset_flags: which reset is requested
8896 * @lock_acquired: indicates whether or not the lock has been acquired
8897 * before this function was called.
8899 * The essential difference in resets is that the PF Reset
8900 * doesn't clear the packet buffers, doesn't reset the PE
8901 * firmware, and doesn't bother the other PFs on the chip.
8903 void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags, bool lock_acquired)
8907 /* do the biggest reset indicated */
8908 if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
8910 /* Request a Global Reset
8912 * This will start the chip's countdown to the actual full
8913 * chip reset event, and a warning interrupt to be sent
8914 * to all PFs, including the requestor. Our handler
8915 * for the warning interrupt will deal with the shutdown
8916 * and recovery of the switch setup.
8918 dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
8919 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
8920 val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
8921 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
8923 } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
8925 /* Request a Core Reset
8927 * Same as Global Reset, except does *not* include the MAC/PHY
8929 dev_dbg(&pf->pdev->dev, "CoreR requested\n");
8930 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
8931 val |= I40E_GLGEN_RTRIG_CORER_MASK;
8932 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
8933 i40e_flush(&pf->hw);
8935 } else if (reset_flags & I40E_PF_RESET_FLAG) {
8937 /* Request a PF Reset
8939 * Resets only the PF-specific registers
8941 * This goes directly to the tear-down and rebuild of
8942 * the switch, since we need to do all the recovery as
8943 * for the Core Reset.
8945 dev_dbg(&pf->pdev->dev, "PFR requested\n");
8946 i40e_handle_reset_warning(pf, lock_acquired);
8948 } else if (reset_flags & I40E_PF_RESET_AND_REBUILD_FLAG) {
8949 /* Request a PF Reset
8951 * Resets PF and reinitializes PFs VSI.
8953 i40e_prep_for_reset(pf);
8954 i40e_reset_and_rebuild(pf, true, lock_acquired);
8955 dev_info(&pf->pdev->dev,
8956 pf->flags & I40E_FLAG_DISABLE_FW_LLDP ?
8957 "FW LLDP is disabled\n" :
8958 "FW LLDP is enabled\n");
8960 } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
8963 /* Find the VSI(s) that requested a re-init */
8964 dev_info(&pf->pdev->dev,
8965 "VSI reinit requested\n");
8966 for (v = 0; v < pf->num_alloc_vsi; v++) {
8967 struct i40e_vsi *vsi = pf->vsi[v];
8970 test_and_clear_bit(__I40E_VSI_REINIT_REQUESTED,
8972 i40e_vsi_reinit_locked(pf->vsi[v]);
8974 } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
8977 /* Find the VSI(s) that needs to be brought down */
8978 dev_info(&pf->pdev->dev, "VSI down requested\n");
8979 for (v = 0; v < pf->num_alloc_vsi; v++) {
8980 struct i40e_vsi *vsi = pf->vsi[v];
8983 test_and_clear_bit(__I40E_VSI_DOWN_REQUESTED,
8985 set_bit(__I40E_VSI_DOWN, vsi->state);
8990 dev_info(&pf->pdev->dev,
8991 "bad reset request 0x%08x\n", reset_flags);
8995 #ifdef CONFIG_I40E_DCB
8997 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
8998 * @pf: board private structure
8999 * @old_cfg: current DCB config
9000 * @new_cfg: new DCB config
9002 bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
9003 struct i40e_dcbx_config *old_cfg,
9004 struct i40e_dcbx_config *new_cfg)
9006 bool need_reconfig = false;
9008 /* Check if ETS configuration has changed */
9009 if (memcmp(&new_cfg->etscfg,
9011 sizeof(new_cfg->etscfg))) {
9012 /* If Priority Table has changed reconfig is needed */
9013 if (memcmp(&new_cfg->etscfg.prioritytable,
9014 &old_cfg->etscfg.prioritytable,
9015 sizeof(new_cfg->etscfg.prioritytable))) {
9016 need_reconfig = true;
9017 dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
9020 if (memcmp(&new_cfg->etscfg.tcbwtable,
9021 &old_cfg->etscfg.tcbwtable,
9022 sizeof(new_cfg->etscfg.tcbwtable)))
9023 dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
9025 if (memcmp(&new_cfg->etscfg.tsatable,
9026 &old_cfg->etscfg.tsatable,
9027 sizeof(new_cfg->etscfg.tsatable)))
9028 dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
9031 /* Check if PFC configuration has changed */
9032 if (memcmp(&new_cfg->pfc,
9034 sizeof(new_cfg->pfc))) {
9035 need_reconfig = true;
9036 dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
9039 /* Check if APP Table has changed */
9040 if (memcmp(&new_cfg->app,
9042 sizeof(new_cfg->app))) {
9043 need_reconfig = true;
9044 dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
9047 dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
9048 return need_reconfig;
9052 * i40e_handle_lldp_event - Handle LLDP Change MIB event
9053 * @pf: board private structure
9054 * @e: event info posted on ARQ
9056 static int i40e_handle_lldp_event(struct i40e_pf *pf,
9057 struct i40e_arq_event_info *e)
9059 struct i40e_aqc_lldp_get_mib *mib =
9060 (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
9061 struct i40e_hw *hw = &pf->hw;
9062 struct i40e_dcbx_config tmp_dcbx_cfg;
9063 bool need_reconfig = false;
9067 /* X710-T*L 2.5G and 5G speeds don't support DCB */
9068 if (I40E_IS_X710TL_DEVICE(hw->device_id) &&
9069 (hw->phy.link_info.link_speed &
9070 ~(I40E_LINK_SPEED_2_5GB | I40E_LINK_SPEED_5GB)) &&
9071 !(pf->flags & I40E_FLAG_DCB_CAPABLE))
9072 /* let firmware decide if the DCB should be disabled */
9073 pf->flags |= I40E_FLAG_DCB_CAPABLE;
9075 /* Not DCB capable or capability disabled */
9076 if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
9079 /* Ignore if event is not for Nearest Bridge */
9080 type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
9081 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
9082 dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
9083 if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
9086 /* Check MIB Type and return if event for Remote MIB update */
9087 type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
9088 dev_dbg(&pf->pdev->dev,
9089 "LLDP event mib type %s\n", type ? "remote" : "local");
9090 if (type == I40E_AQ_LLDP_MIB_REMOTE) {
9091 /* Update the remote cached instance and return */
9092 ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
9093 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
9094 &hw->remote_dcbx_config);
9098 /* Store the old configuration */
9099 tmp_dcbx_cfg = hw->local_dcbx_config;
9101 /* Reset the old DCBx configuration data */
9102 memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
9103 /* Get updated DCBX data from firmware */
9104 ret = i40e_get_dcb_config(&pf->hw);
9106 /* X710-T*L 2.5G and 5G speeds don't support DCB */
9107 if (I40E_IS_X710TL_DEVICE(hw->device_id) &&
9108 (hw->phy.link_info.link_speed &
9109 (I40E_LINK_SPEED_2_5GB | I40E_LINK_SPEED_5GB))) {
9110 dev_warn(&pf->pdev->dev,
9111 "DCB is not supported for X710-T*L 2.5/5G speeds\n");
9112 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
9114 dev_info(&pf->pdev->dev,
9115 "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
9116 i40e_stat_str(&pf->hw, ret),
9117 i40e_aq_str(&pf->hw,
9118 pf->hw.aq.asq_last_status));
9123 /* No change detected in DCBX configs */
9124 if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
9125 sizeof(tmp_dcbx_cfg))) {
9126 dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
9130 need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
9131 &hw->local_dcbx_config);
9133 i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
9138 /* Enable DCB tagging only when more than one TC */
9139 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
9140 pf->flags |= I40E_FLAG_DCB_ENABLED;
9142 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
9144 set_bit(__I40E_PORT_SUSPENDED, pf->state);
9145 /* Reconfiguration needed quiesce all VSIs */
9146 i40e_pf_quiesce_all_vsi(pf);
9148 /* Changes in configuration update VEB/VSI */
9149 i40e_dcb_reconfigure(pf);
9151 ret = i40e_resume_port_tx(pf);
9153 clear_bit(__I40E_PORT_SUSPENDED, pf->state);
9154 /* In case of error no point in resuming VSIs */
9158 /* Wait for the PF's queues to be disabled */
9159 ret = i40e_pf_wait_queues_disabled(pf);
9161 /* Schedule PF reset to recover */
9162 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
9163 i40e_service_event_schedule(pf);
9165 i40e_pf_unquiesce_all_vsi(pf);
9166 set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
9167 set_bit(__I40E_CLIENT_L2_CHANGE, pf->state);
9173 #endif /* CONFIG_I40E_DCB */
9176 * i40e_do_reset_safe - Protected reset path for userland calls.
9177 * @pf: board private structure
9178 * @reset_flags: which reset is requested
9181 void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
9184 i40e_do_reset(pf, reset_flags, true);
9189 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
9190 * @pf: board private structure
9191 * @e: event info posted on ARQ
9193 * Handler for LAN Queue Overflow Event generated by the firmware for PF
9196 static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
9197 struct i40e_arq_event_info *e)
9199 struct i40e_aqc_lan_overflow *data =
9200 (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
9201 u32 queue = le32_to_cpu(data->prtdcb_rupto);
9202 u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
9203 struct i40e_hw *hw = &pf->hw;
9207 dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
9210 /* Queue belongs to VF, find the VF and issue VF reset */
9211 if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
9212 >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
9213 vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
9214 >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
9215 vf_id -= hw->func_caps.vf_base_id;
9216 vf = &pf->vf[vf_id];
9217 i40e_vc_notify_vf_reset(vf);
9218 /* Allow VF to process pending reset notification */
9220 i40e_reset_vf(vf, false);
9225 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
9226 * @pf: board private structure
9228 u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
9232 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
9233 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
9238 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
9239 * @pf: board private structure
9241 u32 i40e_get_current_fd_count(struct i40e_pf *pf)
9245 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
9246 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
9247 ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
9248 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
9253 * i40e_get_global_fd_count - Get total FD filters programmed on device
9254 * @pf: board private structure
9256 u32 i40e_get_global_fd_count(struct i40e_pf *pf)
9260 val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
9261 fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
9262 ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
9263 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
9268 * i40e_reenable_fdir_sb - Restore FDir SB capability
9269 * @pf: board private structure
9271 static void i40e_reenable_fdir_sb(struct i40e_pf *pf)
9273 if (test_and_clear_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state))
9274 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
9275 (I40E_DEBUG_FD & pf->hw.debug_mask))
9276 dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
9280 * i40e_reenable_fdir_atr - Restore FDir ATR capability
9281 * @pf: board private structure
9283 static void i40e_reenable_fdir_atr(struct i40e_pf *pf)
9285 if (test_and_clear_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state)) {
9286 /* ATR uses the same filtering logic as SB rules. It only
9287 * functions properly if the input set mask is at the default
9288 * settings. It is safe to restore the default input set
9289 * because there are no active TCPv4 filter rules.
9291 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
9292 I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
9293 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
9295 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
9296 (I40E_DEBUG_FD & pf->hw.debug_mask))
9297 dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n");
9302 * i40e_delete_invalid_filter - Delete an invalid FDIR filter
9303 * @pf: board private structure
9304 * @filter: FDir filter to remove
9306 static void i40e_delete_invalid_filter(struct i40e_pf *pf,
9307 struct i40e_fdir_filter *filter)
9309 /* Update counters */
9310 pf->fdir_pf_active_filters--;
9313 switch (filter->flow_type) {
9315 pf->fd_tcp4_filter_cnt--;
9318 pf->fd_udp4_filter_cnt--;
9321 pf->fd_sctp4_filter_cnt--;
9324 pf->fd_tcp6_filter_cnt--;
9327 pf->fd_udp6_filter_cnt--;
9330 pf->fd_udp6_filter_cnt--;
9333 switch (filter->ipl4_proto) {
9335 pf->fd_tcp4_filter_cnt--;
9338 pf->fd_udp4_filter_cnt--;
9341 pf->fd_sctp4_filter_cnt--;
9344 pf->fd_ip4_filter_cnt--;
9348 case IPV6_USER_FLOW:
9349 switch (filter->ipl4_proto) {
9351 pf->fd_tcp6_filter_cnt--;
9354 pf->fd_udp6_filter_cnt--;
9357 pf->fd_sctp6_filter_cnt--;
9360 pf->fd_ip6_filter_cnt--;
9366 /* Remove the filter from the list and free memory */
9367 hlist_del(&filter->fdir_node);
9372 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
9373 * @pf: board private structure
9375 void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
9377 struct i40e_fdir_filter *filter;
9378 u32 fcnt_prog, fcnt_avail;
9379 struct hlist_node *node;
9381 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
9384 /* Check if we have enough room to re-enable FDir SB capability. */
9385 fcnt_prog = i40e_get_global_fd_count(pf);
9386 fcnt_avail = pf->fdir_pf_filter_count;
9387 if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
9388 (pf->fd_add_err == 0) ||
9389 (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt))
9390 i40e_reenable_fdir_sb(pf);
9392 /* We should wait for even more space before re-enabling ATR.
9393 * Additionally, we cannot enable ATR as long as we still have TCP SB
9396 if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) &&
9397 pf->fd_tcp4_filter_cnt == 0 && pf->fd_tcp6_filter_cnt == 0)
9398 i40e_reenable_fdir_atr(pf);
9400 /* if hw had a problem adding a filter, delete it */
9401 if (pf->fd_inv > 0) {
9402 hlist_for_each_entry_safe(filter, node,
9403 &pf->fdir_filter_list, fdir_node)
9404 if (filter->fd_id == pf->fd_inv)
9405 i40e_delete_invalid_filter(pf, filter);
9409 #define I40E_MIN_FD_FLUSH_INTERVAL 10
9410 #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
9412 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
9413 * @pf: board private structure
9415 static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
9417 unsigned long min_flush_time;
9418 int flush_wait_retry = 50;
9419 bool disable_atr = false;
9423 if (!time_after(jiffies, pf->fd_flush_timestamp +
9424 (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
9427 /* If the flush is happening too quick and we have mostly SB rules we
9428 * should not re-enable ATR for some time.
9430 min_flush_time = pf->fd_flush_timestamp +
9431 (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
9432 fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
9434 if (!(time_after(jiffies, min_flush_time)) &&
9435 (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
9436 if (I40E_DEBUG_FD & pf->hw.debug_mask)
9437 dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
9441 pf->fd_flush_timestamp = jiffies;
9442 set_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
9443 /* flush all filters */
9444 wr32(&pf->hw, I40E_PFQF_CTL_1,
9445 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
9446 i40e_flush(&pf->hw);
9450 /* Check FD flush status every 5-6msec */
9451 usleep_range(5000, 6000);
9452 reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
9453 if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
9455 } while (flush_wait_retry--);
9456 if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
9457 dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
9459 /* replay sideband filters */
9460 i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
9461 if (!disable_atr && !pf->fd_tcp4_filter_cnt)
9462 clear_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
9463 clear_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
9464 if (I40E_DEBUG_FD & pf->hw.debug_mask)
9465 dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
9470 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
9471 * @pf: board private structure
9473 u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
9475 return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
9479 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
9480 * @pf: board private structure
9482 static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
9485 /* if interface is down do nothing */
9486 if (test_bit(__I40E_DOWN, pf->state))
9489 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
9490 i40e_fdir_flush_and_replay(pf);
9492 i40e_fdir_check_and_reenable(pf);
9497 * i40e_vsi_link_event - notify VSI of a link event
9498 * @vsi: vsi to be notified
9499 * @link_up: link up or down
9501 static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
9503 if (!vsi || test_bit(__I40E_VSI_DOWN, vsi->state))
9506 switch (vsi->type) {
9508 if (!vsi->netdev || !vsi->netdev_registered)
9512 netif_carrier_on(vsi->netdev);
9513 netif_tx_wake_all_queues(vsi->netdev);
9515 netif_carrier_off(vsi->netdev);
9516 netif_tx_stop_all_queues(vsi->netdev);
9520 case I40E_VSI_SRIOV:
9521 case I40E_VSI_VMDQ2:
9523 case I40E_VSI_IWARP:
9524 case I40E_VSI_MIRROR:
9526 /* there is no notification for other VSIs */
9532 * i40e_veb_link_event - notify elements on the veb of a link event
9533 * @veb: veb to be notified
9534 * @link_up: link up or down
9536 static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
9541 if (!veb || !veb->pf)
9545 /* depth first... */
9546 for (i = 0; i < I40E_MAX_VEB; i++)
9547 if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
9548 i40e_veb_link_event(pf->veb[i], link_up);
9550 /* ... now the local VSIs */
9551 for (i = 0; i < pf->num_alloc_vsi; i++)
9552 if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
9553 i40e_vsi_link_event(pf->vsi[i], link_up);
9557 * i40e_link_event - Update netif_carrier status
9558 * @pf: board private structure
9560 static void i40e_link_event(struct i40e_pf *pf)
9562 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
9563 u8 new_link_speed, old_link_speed;
9565 bool new_link, old_link;
9566 #ifdef CONFIG_I40E_DCB
9568 #endif /* CONFIG_I40E_DCB */
9570 /* set this to force the get_link_status call to refresh state */
9571 pf->hw.phy.get_link_info = true;
9572 old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
9573 status = i40e_get_link_status(&pf->hw, &new_link);
9575 /* On success, disable temp link polling */
9576 if (status == I40E_SUCCESS) {
9577 clear_bit(__I40E_TEMP_LINK_POLLING, pf->state);
9579 /* Enable link polling temporarily until i40e_get_link_status
9580 * returns I40E_SUCCESS
9582 set_bit(__I40E_TEMP_LINK_POLLING, pf->state);
9583 dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
9588 old_link_speed = pf->hw.phy.link_info_old.link_speed;
9589 new_link_speed = pf->hw.phy.link_info.link_speed;
9591 if (new_link == old_link &&
9592 new_link_speed == old_link_speed &&
9593 (test_bit(__I40E_VSI_DOWN, vsi->state) ||
9594 new_link == netif_carrier_ok(vsi->netdev)))
9597 i40e_print_link_message(vsi, new_link);
9599 /* Notify the base of the switch tree connected to
9600 * the link. Floating VEBs are not notified.
9602 if (pf->lan_veb < I40E_MAX_VEB && pf->veb[pf->lan_veb])
9603 i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
9605 i40e_vsi_link_event(vsi, new_link);
9608 i40e_vc_notify_link_state(pf);
9610 if (pf->flags & I40E_FLAG_PTP)
9611 i40e_ptp_set_increment(pf);
9612 #ifdef CONFIG_I40E_DCB
9613 if (new_link == old_link)
9615 /* Not SW DCB so firmware will take care of default settings */
9616 if (pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED)
9619 /* We cover here only link down, as after link up in case of SW DCB
9620 * SW LLDP agent will take care of setting it up
9623 dev_dbg(&pf->pdev->dev, "Reconfig DCB to single TC as result of Link Down\n");
9624 memset(&pf->tmp_cfg, 0, sizeof(pf->tmp_cfg));
9625 err = i40e_dcb_sw_default_config(pf);
9627 pf->flags &= ~(I40E_FLAG_DCB_CAPABLE |
9628 I40E_FLAG_DCB_ENABLED);
9630 pf->dcbx_cap = DCB_CAP_DCBX_HOST |
9631 DCB_CAP_DCBX_VER_IEEE;
9632 pf->flags |= I40E_FLAG_DCB_CAPABLE;
9633 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
9636 #endif /* CONFIG_I40E_DCB */
9640 * i40e_watchdog_subtask - periodic checks not using event driven response
9641 * @pf: board private structure
9643 static void i40e_watchdog_subtask(struct i40e_pf *pf)
9647 /* if interface is down do nothing */
9648 if (test_bit(__I40E_DOWN, pf->state) ||
9649 test_bit(__I40E_CONFIG_BUSY, pf->state))
9652 /* make sure we don't do these things too often */
9653 if (time_before(jiffies, (pf->service_timer_previous +
9654 pf->service_timer_period)))
9656 pf->service_timer_previous = jiffies;
9658 if ((pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) ||
9659 test_bit(__I40E_TEMP_LINK_POLLING, pf->state))
9660 i40e_link_event(pf);
9662 /* Update the stats for active netdevs so the network stack
9663 * can look at updated numbers whenever it cares to
9665 for (i = 0; i < pf->num_alloc_vsi; i++)
9666 if (pf->vsi[i] && pf->vsi[i]->netdev)
9667 i40e_update_stats(pf->vsi[i]);
9669 if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
9670 /* Update the stats for the active switching components */
9671 for (i = 0; i < I40E_MAX_VEB; i++)
9673 i40e_update_veb_stats(pf->veb[i]);
9676 i40e_ptp_rx_hang(pf);
9677 i40e_ptp_tx_hang(pf);
9681 * i40e_reset_subtask - Set up for resetting the device and driver
9682 * @pf: board private structure
9684 static void i40e_reset_subtask(struct i40e_pf *pf)
9686 u32 reset_flags = 0;
9688 if (test_bit(__I40E_REINIT_REQUESTED, pf->state)) {
9689 reset_flags |= BIT(__I40E_REINIT_REQUESTED);
9690 clear_bit(__I40E_REINIT_REQUESTED, pf->state);
9692 if (test_bit(__I40E_PF_RESET_REQUESTED, pf->state)) {
9693 reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
9694 clear_bit(__I40E_PF_RESET_REQUESTED, pf->state);
9696 if (test_bit(__I40E_CORE_RESET_REQUESTED, pf->state)) {
9697 reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
9698 clear_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
9700 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state)) {
9701 reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
9702 clear_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state);
9704 if (test_bit(__I40E_DOWN_REQUESTED, pf->state)) {
9705 reset_flags |= BIT(__I40E_DOWN_REQUESTED);
9706 clear_bit(__I40E_DOWN_REQUESTED, pf->state);
9709 /* If there's a recovery already waiting, it takes
9710 * precedence before starting a new reset sequence.
9712 if (test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) {
9713 i40e_prep_for_reset(pf);
9715 i40e_rebuild(pf, false, false);
9718 /* If we're already down or resetting, just bail */
9720 !test_bit(__I40E_DOWN, pf->state) &&
9721 !test_bit(__I40E_CONFIG_BUSY, pf->state)) {
9722 i40e_do_reset(pf, reset_flags, false);
9727 * i40e_handle_link_event - Handle link event
9728 * @pf: board private structure
9729 * @e: event info posted on ARQ
9731 static void i40e_handle_link_event(struct i40e_pf *pf,
9732 struct i40e_arq_event_info *e)
9734 struct i40e_aqc_get_link_status *status =
9735 (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
9737 /* Do a new status request to re-enable LSE reporting
9738 * and load new status information into the hw struct
9739 * This completely ignores any state information
9740 * in the ARQ event info, instead choosing to always
9741 * issue the AQ update link status command.
9743 i40e_link_event(pf);
9745 /* Check if module meets thermal requirements */
9746 if (status->phy_type == I40E_PHY_TYPE_NOT_SUPPORTED_HIGH_TEMP) {
9747 dev_err(&pf->pdev->dev,
9748 "Rx/Tx is disabled on this device because the module does not meet thermal requirements.\n");
9749 dev_err(&pf->pdev->dev,
9750 "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
9752 /* check for unqualified module, if link is down, suppress
9753 * the message if link was forced to be down.
9755 if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
9756 (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
9757 (!(status->link_info & I40E_AQ_LINK_UP)) &&
9758 (!(pf->flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED))) {
9759 dev_err(&pf->pdev->dev,
9760 "Rx/Tx is disabled on this device because an unsupported SFP module type was detected.\n");
9761 dev_err(&pf->pdev->dev,
9762 "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
9768 * i40e_clean_adminq_subtask - Clean the AdminQ rings
9769 * @pf: board private structure
9771 static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
9773 struct i40e_arq_event_info event;
9774 struct i40e_hw *hw = &pf->hw;
9781 /* Do not run clean AQ when PF reset fails */
9782 if (test_bit(__I40E_RESET_FAILED, pf->state))
9785 /* check for error indications */
9786 val = rd32(&pf->hw, pf->hw.aq.arq.len);
9788 if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
9789 if (hw->debug_mask & I40E_DEBUG_AQ)
9790 dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
9791 val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
9793 if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
9794 if (hw->debug_mask & I40E_DEBUG_AQ)
9795 dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
9796 val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
9797 pf->arq_overflows++;
9799 if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
9800 if (hw->debug_mask & I40E_DEBUG_AQ)
9801 dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
9802 val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
9805 wr32(&pf->hw, pf->hw.aq.arq.len, val);
9807 val = rd32(&pf->hw, pf->hw.aq.asq.len);
9809 if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
9810 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
9811 dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
9812 val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
9814 if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
9815 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
9816 dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
9817 val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
9819 if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
9820 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
9821 dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
9822 val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
9825 wr32(&pf->hw, pf->hw.aq.asq.len, val);
9827 event.buf_len = I40E_MAX_AQ_BUF_SIZE;
9828 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
9833 ret = i40e_clean_arq_element(hw, &event, &pending);
9834 if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
9837 dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
9841 opcode = le16_to_cpu(event.desc.opcode);
9844 case i40e_aqc_opc_get_link_status:
9846 i40e_handle_link_event(pf, &event);
9849 case i40e_aqc_opc_send_msg_to_pf:
9850 ret = i40e_vc_process_vf_msg(pf,
9851 le16_to_cpu(event.desc.retval),
9852 le32_to_cpu(event.desc.cookie_high),
9853 le32_to_cpu(event.desc.cookie_low),
9857 case i40e_aqc_opc_lldp_update_mib:
9858 dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
9859 #ifdef CONFIG_I40E_DCB
9861 i40e_handle_lldp_event(pf, &event);
9863 #endif /* CONFIG_I40E_DCB */
9865 case i40e_aqc_opc_event_lan_overflow:
9866 dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
9867 i40e_handle_lan_overflow_event(pf, &event);
9869 case i40e_aqc_opc_send_msg_to_peer:
9870 dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
9872 case i40e_aqc_opc_nvm_erase:
9873 case i40e_aqc_opc_nvm_update:
9874 case i40e_aqc_opc_oem_post_update:
9875 i40e_debug(&pf->hw, I40E_DEBUG_NVM,
9876 "ARQ NVM operation 0x%04x completed\n",
9880 dev_info(&pf->pdev->dev,
9881 "ARQ: Unknown event 0x%04x ignored\n",
9885 } while (i++ < pf->adminq_work_limit);
9887 if (i < pf->adminq_work_limit)
9888 clear_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
9890 /* re-enable Admin queue interrupt cause */
9891 val = rd32(hw, I40E_PFINT_ICR0_ENA);
9892 val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
9893 wr32(hw, I40E_PFINT_ICR0_ENA, val);
9896 kfree(event.msg_buf);
9900 * i40e_verify_eeprom - make sure eeprom is good to use
9901 * @pf: board private structure
9903 static void i40e_verify_eeprom(struct i40e_pf *pf)
9907 err = i40e_diag_eeprom_test(&pf->hw);
9909 /* retry in case of garbage read */
9910 err = i40e_diag_eeprom_test(&pf->hw);
9912 dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
9914 set_bit(__I40E_BAD_EEPROM, pf->state);
9918 if (!err && test_bit(__I40E_BAD_EEPROM, pf->state)) {
9919 dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
9920 clear_bit(__I40E_BAD_EEPROM, pf->state);
9925 * i40e_enable_pf_switch_lb
9926 * @pf: pointer to the PF structure
9928 * enable switch loop back or die - no point in a return value
9930 static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
9932 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
9933 struct i40e_vsi_context ctxt;
9936 ctxt.seid = pf->main_vsi_seid;
9937 ctxt.pf_num = pf->hw.pf_id;
9939 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
9941 dev_info(&pf->pdev->dev,
9942 "couldn't get PF vsi config, err %s aq_err %s\n",
9943 i40e_stat_str(&pf->hw, ret),
9944 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
9947 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
9948 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9949 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9951 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
9953 dev_info(&pf->pdev->dev,
9954 "update vsi switch failed, err %s aq_err %s\n",
9955 i40e_stat_str(&pf->hw, ret),
9956 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
9961 * i40e_disable_pf_switch_lb
9962 * @pf: pointer to the PF structure
9964 * disable switch loop back or die - no point in a return value
9966 static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
9968 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
9969 struct i40e_vsi_context ctxt;
9972 ctxt.seid = pf->main_vsi_seid;
9973 ctxt.pf_num = pf->hw.pf_id;
9975 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
9977 dev_info(&pf->pdev->dev,
9978 "couldn't get PF vsi config, err %s aq_err %s\n",
9979 i40e_stat_str(&pf->hw, ret),
9980 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
9983 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
9984 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9985 ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9987 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
9989 dev_info(&pf->pdev->dev,
9990 "update vsi switch failed, err %s aq_err %s\n",
9991 i40e_stat_str(&pf->hw, ret),
9992 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
9997 * i40e_config_bridge_mode - Configure the HW bridge mode
9998 * @veb: pointer to the bridge instance
10000 * Configure the loop back mode for the LAN VSI that is downlink to the
10001 * specified HW bridge instance. It is expected this function is called
10002 * when a new HW bridge is instantiated.
10004 static void i40e_config_bridge_mode(struct i40e_veb *veb)
10006 struct i40e_pf *pf = veb->pf;
10008 if (pf->hw.debug_mask & I40E_DEBUG_LAN)
10009 dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
10010 veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
10011 if (veb->bridge_mode & BRIDGE_MODE_VEPA)
10012 i40e_disable_pf_switch_lb(pf);
10014 i40e_enable_pf_switch_lb(pf);
10018 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
10019 * @veb: pointer to the VEB instance
10021 * This is a recursive function that first builds the attached VSIs then
10022 * recurses in to build the next layer of VEB. We track the connections
10023 * through our own index numbers because the seid's from the HW could
10024 * change across the reset.
10026 static int i40e_reconstitute_veb(struct i40e_veb *veb)
10028 struct i40e_vsi *ctl_vsi = NULL;
10029 struct i40e_pf *pf = veb->pf;
10033 /* build VSI that owns this VEB, temporarily attached to base VEB */
10034 for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
10036 pf->vsi[v]->veb_idx == veb->idx &&
10037 pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
10038 ctl_vsi = pf->vsi[v];
10043 dev_info(&pf->pdev->dev,
10044 "missing owner VSI for veb_idx %d\n", veb->idx);
10046 goto end_reconstitute;
10048 if (ctl_vsi != pf->vsi[pf->lan_vsi])
10049 ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
10050 ret = i40e_add_vsi(ctl_vsi);
10052 dev_info(&pf->pdev->dev,
10053 "rebuild of veb_idx %d owner VSI failed: %d\n",
10055 goto end_reconstitute;
10057 i40e_vsi_reset_stats(ctl_vsi);
10059 /* create the VEB in the switch and move the VSI onto the VEB */
10060 ret = i40e_add_veb(veb, ctl_vsi);
10062 goto end_reconstitute;
10064 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
10065 veb->bridge_mode = BRIDGE_MODE_VEB;
10067 veb->bridge_mode = BRIDGE_MODE_VEPA;
10068 i40e_config_bridge_mode(veb);
10070 /* create the remaining VSIs attached to this VEB */
10071 for (v = 0; v < pf->num_alloc_vsi; v++) {
10072 if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
10075 if (pf->vsi[v]->veb_idx == veb->idx) {
10076 struct i40e_vsi *vsi = pf->vsi[v];
10078 vsi->uplink_seid = veb->seid;
10079 ret = i40e_add_vsi(vsi);
10081 dev_info(&pf->pdev->dev,
10082 "rebuild of vsi_idx %d failed: %d\n",
10084 goto end_reconstitute;
10086 i40e_vsi_reset_stats(vsi);
10090 /* create any VEBs attached to this VEB - RECURSION */
10091 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
10092 if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
10093 pf->veb[veb_idx]->uplink_seid = veb->seid;
10094 ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
10105 * i40e_get_capabilities - get info about the HW
10106 * @pf: the PF struct
10107 * @list_type: AQ capability to be queried
10109 static int i40e_get_capabilities(struct i40e_pf *pf,
10110 enum i40e_admin_queue_opc list_type)
10112 struct i40e_aqc_list_capabilities_element_resp *cap_buf;
10117 buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
10119 cap_buf = kzalloc(buf_len, GFP_KERNEL);
10123 /* this loads the data into the hw struct for us */
10124 err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
10125 &data_size, list_type,
10127 /* data loaded, buffer no longer needed */
10130 if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
10131 /* retry with a larger buffer */
10132 buf_len = data_size;
10133 } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
10134 dev_info(&pf->pdev->dev,
10135 "capability discovery failed, err %s aq_err %s\n",
10136 i40e_stat_str(&pf->hw, err),
10137 i40e_aq_str(&pf->hw,
10138 pf->hw.aq.asq_last_status));
10143 if (pf->hw.debug_mask & I40E_DEBUG_USER) {
10144 if (list_type == i40e_aqc_opc_list_func_capabilities) {
10145 dev_info(&pf->pdev->dev,
10146 "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",
10147 pf->hw.pf_id, pf->hw.func_caps.num_vfs,
10148 pf->hw.func_caps.num_msix_vectors,
10149 pf->hw.func_caps.num_msix_vectors_vf,
10150 pf->hw.func_caps.fd_filters_guaranteed,
10151 pf->hw.func_caps.fd_filters_best_effort,
10152 pf->hw.func_caps.num_tx_qp,
10153 pf->hw.func_caps.num_vsis);
10154 } else if (list_type == i40e_aqc_opc_list_dev_capabilities) {
10155 dev_info(&pf->pdev->dev,
10156 "switch_mode=0x%04x, function_valid=0x%08x\n",
10157 pf->hw.dev_caps.switch_mode,
10158 pf->hw.dev_caps.valid_functions);
10159 dev_info(&pf->pdev->dev,
10160 "SR-IOV=%d, num_vfs for all function=%u\n",
10161 pf->hw.dev_caps.sr_iov_1_1,
10162 pf->hw.dev_caps.num_vfs);
10163 dev_info(&pf->pdev->dev,
10164 "num_vsis=%u, num_rx:%u, num_tx=%u\n",
10165 pf->hw.dev_caps.num_vsis,
10166 pf->hw.dev_caps.num_rx_qp,
10167 pf->hw.dev_caps.num_tx_qp);
10170 if (list_type == i40e_aqc_opc_list_func_capabilities) {
10171 #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
10172 + pf->hw.func_caps.num_vfs)
10173 if (pf->hw.revision_id == 0 &&
10174 pf->hw.func_caps.num_vsis < DEF_NUM_VSI) {
10175 dev_info(&pf->pdev->dev,
10176 "got num_vsis %d, setting num_vsis to %d\n",
10177 pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
10178 pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
10184 static int i40e_vsi_clear(struct i40e_vsi *vsi);
10187 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
10188 * @pf: board private structure
10190 static void i40e_fdir_sb_setup(struct i40e_pf *pf)
10192 struct i40e_vsi *vsi;
10194 /* quick workaround for an NVM issue that leaves a critical register
10197 if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
10198 static const u32 hkey[] = {
10199 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
10200 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
10201 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
10205 for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
10206 wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
10209 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
10212 /* find existing VSI and see if it needs configuring */
10213 vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
10215 /* create a new VSI if none exists */
10217 vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
10218 pf->vsi[pf->lan_vsi]->seid, 0);
10220 dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
10221 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
10222 pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
10227 i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
10231 * i40e_fdir_teardown - release the Flow Director resources
10232 * @pf: board private structure
10234 static void i40e_fdir_teardown(struct i40e_pf *pf)
10236 struct i40e_vsi *vsi;
10238 i40e_fdir_filter_exit(pf);
10239 vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
10241 i40e_vsi_release(vsi);
10245 * i40e_rebuild_cloud_filters - Rebuilds cloud filters for VSIs
10246 * @vsi: PF main vsi
10247 * @seid: seid of main or channel VSIs
10249 * Rebuilds cloud filters associated with main VSI and channel VSIs if they
10250 * existed before reset
10252 static int i40e_rebuild_cloud_filters(struct i40e_vsi *vsi, u16 seid)
10254 struct i40e_cloud_filter *cfilter;
10255 struct i40e_pf *pf = vsi->back;
10256 struct hlist_node *node;
10259 /* Add cloud filters back if they exist */
10260 hlist_for_each_entry_safe(cfilter, node, &pf->cloud_filter_list,
10262 if (cfilter->seid != seid)
10265 if (cfilter->dst_port)
10266 ret = i40e_add_del_cloud_filter_big_buf(vsi, cfilter,
10269 ret = i40e_add_del_cloud_filter(vsi, cfilter, true);
10272 dev_dbg(&pf->pdev->dev,
10273 "Failed to rebuild cloud filter, err %s aq_err %s\n",
10274 i40e_stat_str(&pf->hw, ret),
10275 i40e_aq_str(&pf->hw,
10276 pf->hw.aq.asq_last_status));
10284 * i40e_rebuild_channels - Rebuilds channel VSIs if they existed before reset
10285 * @vsi: PF main vsi
10287 * Rebuilds channel VSIs if they existed before reset
10289 static int i40e_rebuild_channels(struct i40e_vsi *vsi)
10291 struct i40e_channel *ch, *ch_tmp;
10294 if (list_empty(&vsi->ch_list))
10297 list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
10298 if (!ch->initialized)
10300 /* Proceed with creation of channel (VMDq2) VSI */
10301 ret = i40e_add_channel(vsi->back, vsi->uplink_seid, ch);
10303 dev_info(&vsi->back->pdev->dev,
10304 "failed to rebuild channels using uplink_seid %u\n",
10308 /* Reconfigure TX queues using QTX_CTL register */
10309 ret = i40e_channel_config_tx_ring(vsi->back, vsi, ch);
10311 dev_info(&vsi->back->pdev->dev,
10312 "failed to configure TX rings for channel %u\n",
10316 /* update 'next_base_queue' */
10317 vsi->next_base_queue = vsi->next_base_queue +
10318 ch->num_queue_pairs;
10319 if (ch->max_tx_rate) {
10320 u64 credits = ch->max_tx_rate;
10322 if (i40e_set_bw_limit(vsi, ch->seid,
10326 do_div(credits, I40E_BW_CREDIT_DIVISOR);
10327 dev_dbg(&vsi->back->pdev->dev,
10328 "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
10333 ret = i40e_rebuild_cloud_filters(vsi, ch->seid);
10335 dev_dbg(&vsi->back->pdev->dev,
10336 "Failed to rebuild cloud filters for channel VSI %u\n",
10345 * i40e_prep_for_reset - prep for the core to reset
10346 * @pf: board private structure
10348 * Close up the VFs and other things in prep for PF Reset.
10350 static void i40e_prep_for_reset(struct i40e_pf *pf)
10352 struct i40e_hw *hw = &pf->hw;
10353 i40e_status ret = 0;
10356 clear_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
10357 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
10359 if (i40e_check_asq_alive(&pf->hw))
10360 i40e_vc_notify_reset(pf);
10362 dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
10364 /* quiesce the VSIs and their queues that are not already DOWN */
10365 i40e_pf_quiesce_all_vsi(pf);
10367 for (v = 0; v < pf->num_alloc_vsi; v++) {
10369 pf->vsi[v]->seid = 0;
10372 i40e_shutdown_adminq(&pf->hw);
10374 /* call shutdown HMC */
10375 if (hw->hmc.hmc_obj) {
10376 ret = i40e_shutdown_lan_hmc(hw);
10378 dev_warn(&pf->pdev->dev,
10379 "shutdown_lan_hmc failed: %d\n", ret);
10382 /* Save the current PTP time so that we can restore the time after the
10385 i40e_ptp_save_hw_time(pf);
10389 * i40e_send_version - update firmware with driver version
10392 static void i40e_send_version(struct i40e_pf *pf)
10394 struct i40e_driver_version dv;
10396 dv.major_version = 0xff;
10397 dv.minor_version = 0xff;
10398 dv.build_version = 0xff;
10399 dv.subbuild_version = 0;
10400 strlcpy(dv.driver_string, UTS_RELEASE, sizeof(dv.driver_string));
10401 i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
10405 * i40e_get_oem_version - get OEM specific version information
10406 * @hw: pointer to the hardware structure
10408 static void i40e_get_oem_version(struct i40e_hw *hw)
10410 u16 block_offset = 0xffff;
10411 u16 block_length = 0;
10412 u16 capabilities = 0;
10416 #define I40E_SR_NVM_OEM_VERSION_PTR 0x1B
10417 #define I40E_NVM_OEM_LENGTH_OFFSET 0x00
10418 #define I40E_NVM_OEM_CAPABILITIES_OFFSET 0x01
10419 #define I40E_NVM_OEM_GEN_OFFSET 0x02
10420 #define I40E_NVM_OEM_RELEASE_OFFSET 0x03
10421 #define I40E_NVM_OEM_CAPABILITIES_MASK 0x000F
10422 #define I40E_NVM_OEM_LENGTH 3
10424 /* Check if pointer to OEM version block is valid. */
10425 i40e_read_nvm_word(hw, I40E_SR_NVM_OEM_VERSION_PTR, &block_offset);
10426 if (block_offset == 0xffff)
10429 /* Check if OEM version block has correct length. */
10430 i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_LENGTH_OFFSET,
10432 if (block_length < I40E_NVM_OEM_LENGTH)
10435 /* Check if OEM version format is as expected. */
10436 i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_CAPABILITIES_OFFSET,
10438 if ((capabilities & I40E_NVM_OEM_CAPABILITIES_MASK) != 0)
10441 i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_GEN_OFFSET,
10443 i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_RELEASE_OFFSET,
10445 hw->nvm.oem_ver = (gen_snap << I40E_OEM_SNAP_SHIFT) | release;
10446 hw->nvm.eetrack = I40E_OEM_EETRACK_ID;
10450 * i40e_reset - wait for core reset to finish reset, reset pf if corer not seen
10451 * @pf: board private structure
10453 static int i40e_reset(struct i40e_pf *pf)
10455 struct i40e_hw *hw = &pf->hw;
10458 ret = i40e_pf_reset(hw);
10460 dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
10461 set_bit(__I40E_RESET_FAILED, pf->state);
10462 clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
10470 * i40e_rebuild - rebuild using a saved config
10471 * @pf: board private structure
10472 * @reinit: if the Main VSI needs to re-initialized.
10473 * @lock_acquired: indicates whether or not the lock has been acquired
10474 * before this function was called.
10476 static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired)
10478 int old_recovery_mode_bit = test_bit(__I40E_RECOVERY_MODE, pf->state);
10479 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
10480 struct i40e_hw *hw = &pf->hw;
10485 if (test_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state) &&
10486 i40e_check_recovery_mode(pf)) {
10487 i40e_set_ethtool_ops(pf->vsi[pf->lan_vsi]->netdev);
10490 if (test_bit(__I40E_DOWN, pf->state) &&
10491 !test_bit(__I40E_RECOVERY_MODE, pf->state) &&
10492 !old_recovery_mode_bit)
10493 goto clear_recovery;
10494 dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
10496 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
10497 ret = i40e_init_adminq(&pf->hw);
10499 dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
10500 i40e_stat_str(&pf->hw, ret),
10501 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
10502 goto clear_recovery;
10504 i40e_get_oem_version(&pf->hw);
10506 if (test_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state) &&
10507 ((hw->aq.fw_maj_ver == 4 && hw->aq.fw_min_ver <= 33) ||
10508 hw->aq.fw_maj_ver < 4) && hw->mac.type == I40E_MAC_XL710) {
10509 /* The following delay is necessary for 4.33 firmware and older
10510 * to recover after EMP reset. 200 ms should suffice but we
10511 * put here 300 ms to be sure that FW is ready to operate
10517 /* re-verify the eeprom if we just had an EMP reset */
10518 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state))
10519 i40e_verify_eeprom(pf);
10521 /* if we are going out of or into recovery mode we have to act
10522 * accordingly with regard to resources initialization
10523 * and deinitialization
10525 if (test_bit(__I40E_RECOVERY_MODE, pf->state) ||
10526 old_recovery_mode_bit) {
10527 if (i40e_get_capabilities(pf,
10528 i40e_aqc_opc_list_func_capabilities))
10531 if (test_bit(__I40E_RECOVERY_MODE, pf->state)) {
10532 /* we're staying in recovery mode so we'll reinitialize
10535 if (i40e_setup_misc_vector_for_recovery_mode(pf))
10538 if (!lock_acquired)
10540 /* we're going out of recovery mode so we'll free
10541 * the IRQ allocated specifically for recovery mode
10542 * and restore the interrupt scheme
10544 free_irq(pf->pdev->irq, pf);
10545 i40e_clear_interrupt_scheme(pf);
10546 if (i40e_restore_interrupt_scheme(pf))
10550 /* tell the firmware that we're starting */
10551 i40e_send_version(pf);
10553 /* bail out in case recovery mode was detected, as there is
10554 * no need for further configuration.
10559 i40e_clear_pxe_mode(hw);
10560 ret = i40e_get_capabilities(pf, i40e_aqc_opc_list_func_capabilities);
10562 goto end_core_reset;
10564 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
10565 hw->func_caps.num_rx_qp, 0, 0);
10567 dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
10568 goto end_core_reset;
10570 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
10572 dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
10573 goto end_core_reset;
10576 if (!lock_acquired)
10578 ret = i40e_setup_pf_switch(pf, reinit);
10582 #ifdef CONFIG_I40E_DCB
10583 /* Enable FW to write a default DCB config on link-up
10584 * unless I40E_FLAG_TC_MQPRIO was enabled or DCB
10585 * is not supported with new link speed
10587 if (pf->flags & I40E_FLAG_TC_MQPRIO) {
10588 i40e_aq_set_dcb_parameters(hw, false, NULL);
10590 if (I40E_IS_X710TL_DEVICE(hw->device_id) &&
10591 (hw->phy.link_info.link_speed &
10592 (I40E_LINK_SPEED_2_5GB | I40E_LINK_SPEED_5GB))) {
10593 i40e_aq_set_dcb_parameters(hw, false, NULL);
10594 dev_warn(&pf->pdev->dev,
10595 "DCB is not supported for X710-T*L 2.5/5G speeds\n");
10596 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
10598 i40e_aq_set_dcb_parameters(hw, true, NULL);
10599 ret = i40e_init_pf_dcb(pf);
10601 dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n",
10603 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
10604 /* Continue without DCB enabled */
10609 #endif /* CONFIG_I40E_DCB */
10611 /* The driver only wants link up/down and module qualification
10612 * reports from firmware. Note the negative logic.
10614 ret = i40e_aq_set_phy_int_mask(&pf->hw,
10615 ~(I40E_AQ_EVENT_LINK_UPDOWN |
10616 I40E_AQ_EVENT_MEDIA_NA |
10617 I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
10619 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
10620 i40e_stat_str(&pf->hw, ret),
10621 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
10623 /* Rebuild the VSIs and VEBs that existed before reset.
10624 * They are still in our local switch element arrays, so only
10625 * need to rebuild the switch model in the HW.
10627 * If there were VEBs but the reconstitution failed, we'll try
10628 * try to recover minimal use by getting the basic PF VSI working.
10630 if (vsi->uplink_seid != pf->mac_seid) {
10631 dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
10632 /* find the one VEB connected to the MAC, and find orphans */
10633 for (v = 0; v < I40E_MAX_VEB; v++) {
10637 if (pf->veb[v]->uplink_seid == pf->mac_seid ||
10638 pf->veb[v]->uplink_seid == 0) {
10639 ret = i40e_reconstitute_veb(pf->veb[v]);
10644 /* If Main VEB failed, we're in deep doodoo,
10645 * so give up rebuilding the switch and set up
10646 * for minimal rebuild of PF VSI.
10647 * If orphan failed, we'll report the error
10648 * but try to keep going.
10650 if (pf->veb[v]->uplink_seid == pf->mac_seid) {
10651 dev_info(&pf->pdev->dev,
10652 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
10654 vsi->uplink_seid = pf->mac_seid;
10656 } else if (pf->veb[v]->uplink_seid == 0) {
10657 dev_info(&pf->pdev->dev,
10658 "rebuild of orphan VEB failed: %d\n",
10665 if (vsi->uplink_seid == pf->mac_seid) {
10666 dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
10667 /* no VEB, so rebuild only the Main VSI */
10668 ret = i40e_add_vsi(vsi);
10670 dev_info(&pf->pdev->dev,
10671 "rebuild of Main VSI failed: %d\n", ret);
10676 if (vsi->mqprio_qopt.max_rate[0]) {
10677 u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
10680 do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
10681 ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
10685 credits = max_tx_rate;
10686 do_div(credits, I40E_BW_CREDIT_DIVISOR);
10687 dev_dbg(&vsi->back->pdev->dev,
10688 "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
10694 ret = i40e_rebuild_cloud_filters(vsi, vsi->seid);
10698 /* PF Main VSI is rebuild by now, go ahead and rebuild channel VSIs
10699 * for this main VSI if they exist
10701 ret = i40e_rebuild_channels(vsi);
10705 /* Reconfigure hardware for allowing smaller MSS in the case
10706 * of TSO, so that we avoid the MDD being fired and causing
10707 * a reset in the case of small MSS+TSO.
10709 #define I40E_REG_MSS 0x000E64DC
10710 #define I40E_REG_MSS_MIN_MASK 0x3FF0000
10711 #define I40E_64BYTE_MSS 0x400000
10712 val = rd32(hw, I40E_REG_MSS);
10713 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
10714 val &= ~I40E_REG_MSS_MIN_MASK;
10715 val |= I40E_64BYTE_MSS;
10716 wr32(hw, I40E_REG_MSS, val);
10719 if (pf->hw_features & I40E_HW_RESTART_AUTONEG) {
10721 ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
10723 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
10724 i40e_stat_str(&pf->hw, ret),
10725 i40e_aq_str(&pf->hw,
10726 pf->hw.aq.asq_last_status));
10728 /* reinit the misc interrupt */
10729 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
10730 ret = i40e_setup_misc_vector(pf);
10732 /* Add a filter to drop all Flow control frames from any VSI from being
10733 * transmitted. By doing so we stop a malicious VF from sending out
10734 * PAUSE or PFC frames and potentially controlling traffic for other
10736 * The FW can still send Flow control frames if enabled.
10738 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
10739 pf->main_vsi_seid);
10740 #ifdef CONFIG_I40E_DCB
10741 if (pf->flags & I40E_FLAG_DISABLE_FW_LLDP)
10742 i40e_set_lldp_forwarding(pf, true);
10743 #endif /* CONFIG_I40E_DCB */
10745 /* restart the VSIs that were rebuilt and running before the reset */
10746 i40e_pf_unquiesce_all_vsi(pf);
10748 /* Release the RTNL lock before we start resetting VFs */
10749 if (!lock_acquired)
10752 /* Restore promiscuous settings */
10753 ret = i40e_set_promiscuous(pf, pf->cur_promisc);
10755 dev_warn(&pf->pdev->dev,
10756 "Failed to restore promiscuous setting: %s, err %s aq_err %s\n",
10757 pf->cur_promisc ? "on" : "off",
10758 i40e_stat_str(&pf->hw, ret),
10759 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
10761 i40e_reset_all_vfs(pf, true);
10763 /* tell the firmware that we're starting */
10764 i40e_send_version(pf);
10766 /* We've already released the lock, so don't do it again */
10767 goto end_core_reset;
10770 if (!lock_acquired)
10773 clear_bit(__I40E_RESET_FAILED, pf->state);
10775 clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
10776 clear_bit(__I40E_TIMEOUT_RECOVERY_PENDING, pf->state);
10780 * i40e_reset_and_rebuild - reset and rebuild using a saved config
10781 * @pf: board private structure
10782 * @reinit: if the Main VSI needs to re-initialized.
10783 * @lock_acquired: indicates whether or not the lock has been acquired
10784 * before this function was called.
10786 static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit,
10787 bool lock_acquired)
10790 /* Now we wait for GRST to settle out.
10791 * We don't have to delete the VEBs or VSIs from the hw switch
10792 * because the reset will make them disappear.
10794 ret = i40e_reset(pf);
10796 i40e_rebuild(pf, reinit, lock_acquired);
10800 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
10801 * @pf: board private structure
10803 * Close up the VFs and other things in prep for a Core Reset,
10804 * then get ready to rebuild the world.
10805 * @lock_acquired: indicates whether or not the lock has been acquired
10806 * before this function was called.
10808 static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired)
10810 i40e_prep_for_reset(pf);
10811 i40e_reset_and_rebuild(pf, false, lock_acquired);
10815 * i40e_handle_mdd_event
10816 * @pf: pointer to the PF structure
10818 * Called from the MDD irq handler to identify possibly malicious vfs
10820 static void i40e_handle_mdd_event(struct i40e_pf *pf)
10822 struct i40e_hw *hw = &pf->hw;
10823 bool mdd_detected = false;
10824 struct i40e_vf *vf;
10828 if (!test_bit(__I40E_MDD_EVENT_PENDING, pf->state))
10831 /* find what triggered the MDD event */
10832 reg = rd32(hw, I40E_GL_MDET_TX);
10833 if (reg & I40E_GL_MDET_TX_VALID_MASK) {
10834 u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
10835 I40E_GL_MDET_TX_PF_NUM_SHIFT;
10836 u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
10837 I40E_GL_MDET_TX_VF_NUM_SHIFT;
10838 u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
10839 I40E_GL_MDET_TX_EVENT_SHIFT;
10840 u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
10841 I40E_GL_MDET_TX_QUEUE_SHIFT) -
10842 pf->hw.func_caps.base_queue;
10843 if (netif_msg_tx_err(pf))
10844 dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
10845 event, queue, pf_num, vf_num);
10846 wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
10847 mdd_detected = true;
10849 reg = rd32(hw, I40E_GL_MDET_RX);
10850 if (reg & I40E_GL_MDET_RX_VALID_MASK) {
10851 u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
10852 I40E_GL_MDET_RX_FUNCTION_SHIFT;
10853 u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
10854 I40E_GL_MDET_RX_EVENT_SHIFT;
10855 u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
10856 I40E_GL_MDET_RX_QUEUE_SHIFT) -
10857 pf->hw.func_caps.base_queue;
10858 if (netif_msg_rx_err(pf))
10859 dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
10860 event, queue, func);
10861 wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
10862 mdd_detected = true;
10865 if (mdd_detected) {
10866 reg = rd32(hw, I40E_PF_MDET_TX);
10867 if (reg & I40E_PF_MDET_TX_VALID_MASK) {
10868 wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
10869 dev_dbg(&pf->pdev->dev, "TX driver issue detected on PF\n");
10871 reg = rd32(hw, I40E_PF_MDET_RX);
10872 if (reg & I40E_PF_MDET_RX_VALID_MASK) {
10873 wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
10874 dev_dbg(&pf->pdev->dev, "RX driver issue detected on PF\n");
10878 /* see if one of the VFs needs its hand slapped */
10879 for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
10881 reg = rd32(hw, I40E_VP_MDET_TX(i));
10882 if (reg & I40E_VP_MDET_TX_VALID_MASK) {
10883 wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
10884 vf->num_mdd_events++;
10885 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
10887 dev_info(&pf->pdev->dev,
10888 "Use PF Control I/F to re-enable the VF\n");
10889 set_bit(I40E_VF_STATE_DISABLED, &vf->vf_states);
10892 reg = rd32(hw, I40E_VP_MDET_RX(i));
10893 if (reg & I40E_VP_MDET_RX_VALID_MASK) {
10894 wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
10895 vf->num_mdd_events++;
10896 dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
10898 dev_info(&pf->pdev->dev,
10899 "Use PF Control I/F to re-enable the VF\n");
10900 set_bit(I40E_VF_STATE_DISABLED, &vf->vf_states);
10904 /* re-enable mdd interrupt cause */
10905 clear_bit(__I40E_MDD_EVENT_PENDING, pf->state);
10906 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
10907 reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
10908 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
10913 * i40e_service_task - Run the driver's async subtasks
10914 * @work: pointer to work_struct containing our data
10916 static void i40e_service_task(struct work_struct *work)
10918 struct i40e_pf *pf = container_of(work,
10921 unsigned long start_time = jiffies;
10923 /* don't bother with service tasks if a reset is in progress */
10924 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
10925 test_bit(__I40E_SUSPENDED, pf->state))
10928 if (test_and_set_bit(__I40E_SERVICE_SCHED, pf->state))
10931 if (!test_bit(__I40E_RECOVERY_MODE, pf->state)) {
10932 i40e_detect_recover_hung(pf->vsi[pf->lan_vsi]);
10933 i40e_sync_filters_subtask(pf);
10934 i40e_reset_subtask(pf);
10935 i40e_handle_mdd_event(pf);
10936 i40e_vc_process_vflr_event(pf);
10937 i40e_watchdog_subtask(pf);
10938 i40e_fdir_reinit_subtask(pf);
10939 if (test_and_clear_bit(__I40E_CLIENT_RESET, pf->state)) {
10940 /* Client subtask will reopen next time through. */
10941 i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi],
10944 i40e_client_subtask(pf);
10945 if (test_and_clear_bit(__I40E_CLIENT_L2_CHANGE,
10947 i40e_notify_client_of_l2_param_changes(
10948 pf->vsi[pf->lan_vsi]);
10950 i40e_sync_filters_subtask(pf);
10952 i40e_reset_subtask(pf);
10955 i40e_clean_adminq_subtask(pf);
10957 /* flush memory to make sure state is correct before next watchdog */
10958 smp_mb__before_atomic();
10959 clear_bit(__I40E_SERVICE_SCHED, pf->state);
10961 /* If the tasks have taken longer than one timer cycle or there
10962 * is more work to be done, reschedule the service task now
10963 * rather than wait for the timer to tick again.
10965 if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
10966 test_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state) ||
10967 test_bit(__I40E_MDD_EVENT_PENDING, pf->state) ||
10968 test_bit(__I40E_VFLR_EVENT_PENDING, pf->state))
10969 i40e_service_event_schedule(pf);
10973 * i40e_service_timer - timer callback
10974 * @t: timer list pointer
10976 static void i40e_service_timer(struct timer_list *t)
10978 struct i40e_pf *pf = from_timer(pf, t, service_timer);
10980 mod_timer(&pf->service_timer,
10981 round_jiffies(jiffies + pf->service_timer_period));
10982 i40e_service_event_schedule(pf);
10986 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
10987 * @vsi: the VSI being configured
10989 static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
10991 struct i40e_pf *pf = vsi->back;
10993 switch (vsi->type) {
10994 case I40E_VSI_MAIN:
10995 vsi->alloc_queue_pairs = pf->num_lan_qps;
10996 if (!vsi->num_tx_desc)
10997 vsi->num_tx_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
10998 I40E_REQ_DESCRIPTOR_MULTIPLE);
10999 if (!vsi->num_rx_desc)
11000 vsi->num_rx_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
11001 I40E_REQ_DESCRIPTOR_MULTIPLE);
11002 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
11003 vsi->num_q_vectors = pf->num_lan_msix;
11005 vsi->num_q_vectors = 1;
11009 case I40E_VSI_FDIR:
11010 vsi->alloc_queue_pairs = 1;
11011 vsi->num_tx_desc = ALIGN(I40E_FDIR_RING_COUNT,
11012 I40E_REQ_DESCRIPTOR_MULTIPLE);
11013 vsi->num_rx_desc = ALIGN(I40E_FDIR_RING_COUNT,
11014 I40E_REQ_DESCRIPTOR_MULTIPLE);
11015 vsi->num_q_vectors = pf->num_fdsb_msix;
11018 case I40E_VSI_VMDQ2:
11019 vsi->alloc_queue_pairs = pf->num_vmdq_qps;
11020 if (!vsi->num_tx_desc)
11021 vsi->num_tx_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
11022 I40E_REQ_DESCRIPTOR_MULTIPLE);
11023 if (!vsi->num_rx_desc)
11024 vsi->num_rx_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
11025 I40E_REQ_DESCRIPTOR_MULTIPLE);
11026 vsi->num_q_vectors = pf->num_vmdq_msix;
11029 case I40E_VSI_SRIOV:
11030 vsi->alloc_queue_pairs = pf->num_vf_qps;
11031 if (!vsi->num_tx_desc)
11032 vsi->num_tx_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
11033 I40E_REQ_DESCRIPTOR_MULTIPLE);
11034 if (!vsi->num_rx_desc)
11035 vsi->num_rx_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
11036 I40E_REQ_DESCRIPTOR_MULTIPLE);
11048 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
11049 * @vsi: VSI pointer
11050 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
11052 * On error: returns error code (negative)
11053 * On success: returns 0
11055 static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
11057 struct i40e_ring **next_rings;
11061 /* allocate memory for both Tx, XDP Tx and Rx ring pointers */
11062 size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs *
11063 (i40e_enabled_xdp_vsi(vsi) ? 3 : 2);
11064 vsi->tx_rings = kzalloc(size, GFP_KERNEL);
11065 if (!vsi->tx_rings)
11067 next_rings = vsi->tx_rings + vsi->alloc_queue_pairs;
11068 if (i40e_enabled_xdp_vsi(vsi)) {
11069 vsi->xdp_rings = next_rings;
11070 next_rings += vsi->alloc_queue_pairs;
11072 vsi->rx_rings = next_rings;
11074 if (alloc_qvectors) {
11075 /* allocate memory for q_vector pointers */
11076 size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
11077 vsi->q_vectors = kzalloc(size, GFP_KERNEL);
11078 if (!vsi->q_vectors) {
11086 kfree(vsi->tx_rings);
11091 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
11092 * @pf: board private structure
11093 * @type: type of VSI
11095 * On error: returns error code (negative)
11096 * On success: returns vsi index in PF (positive)
11098 static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
11101 struct i40e_vsi *vsi;
11105 /* Need to protect the allocation of the VSIs at the PF level */
11106 mutex_lock(&pf->switch_mutex);
11108 /* VSI list may be fragmented if VSI creation/destruction has
11109 * been happening. We can afford to do a quick scan to look
11110 * for any free VSIs in the list.
11112 * find next empty vsi slot, looping back around if necessary
11115 while (i < pf->num_alloc_vsi && pf->vsi[i])
11117 if (i >= pf->num_alloc_vsi) {
11119 while (i < pf->next_vsi && pf->vsi[i])
11123 if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
11124 vsi_idx = i; /* Found one! */
11127 goto unlock_pf; /* out of VSI slots! */
11129 pf->next_vsi = ++i;
11131 vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
11138 set_bit(__I40E_VSI_DOWN, vsi->state);
11140 vsi->idx = vsi_idx;
11141 vsi->int_rate_limit = 0;
11142 vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
11143 pf->rss_table_size : 64;
11144 vsi->netdev_registered = false;
11145 vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
11146 hash_init(vsi->mac_filter_hash);
11147 vsi->irqs_ready = false;
11149 if (type == I40E_VSI_MAIN) {
11150 vsi->af_xdp_zc_qps = bitmap_zalloc(pf->num_lan_qps, GFP_KERNEL);
11151 if (!vsi->af_xdp_zc_qps)
11155 ret = i40e_set_num_rings_in_vsi(vsi);
11159 ret = i40e_vsi_alloc_arrays(vsi, true);
11163 /* Setup default MSIX irq handler for VSI */
11164 i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
11166 /* Initialize VSI lock */
11167 spin_lock_init(&vsi->mac_filter_hash_lock);
11168 pf->vsi[vsi_idx] = vsi;
11173 bitmap_free(vsi->af_xdp_zc_qps);
11174 pf->next_vsi = i - 1;
11177 mutex_unlock(&pf->switch_mutex);
11182 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
11183 * @vsi: VSI pointer
11184 * @free_qvectors: a bool to specify if q_vectors need to be freed.
11186 * On error: returns error code (negative)
11187 * On success: returns 0
11189 static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
11191 /* free the ring and vector containers */
11192 if (free_qvectors) {
11193 kfree(vsi->q_vectors);
11194 vsi->q_vectors = NULL;
11196 kfree(vsi->tx_rings);
11197 vsi->tx_rings = NULL;
11198 vsi->rx_rings = NULL;
11199 vsi->xdp_rings = NULL;
11203 * i40e_clear_rss_config_user - clear the user configured RSS hash keys
11205 * @vsi: Pointer to VSI structure
11207 static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
11212 kfree(vsi->rss_hkey_user);
11213 vsi->rss_hkey_user = NULL;
11215 kfree(vsi->rss_lut_user);
11216 vsi->rss_lut_user = NULL;
11220 * i40e_vsi_clear - Deallocate the VSI provided
11221 * @vsi: the VSI being un-configured
11223 static int i40e_vsi_clear(struct i40e_vsi *vsi)
11225 struct i40e_pf *pf;
11234 mutex_lock(&pf->switch_mutex);
11235 if (!pf->vsi[vsi->idx]) {
11236 dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](type %d)\n",
11237 vsi->idx, vsi->idx, vsi->type);
11241 if (pf->vsi[vsi->idx] != vsi) {
11242 dev_err(&pf->pdev->dev,
11243 "pf->vsi[%d](type %d) != vsi[%d](type %d): no free!\n",
11244 pf->vsi[vsi->idx]->idx,
11245 pf->vsi[vsi->idx]->type,
11246 vsi->idx, vsi->type);
11250 /* updates the PF for this cleared vsi */
11251 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
11252 i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
11254 bitmap_free(vsi->af_xdp_zc_qps);
11255 i40e_vsi_free_arrays(vsi, true);
11256 i40e_clear_rss_config_user(vsi);
11258 pf->vsi[vsi->idx] = NULL;
11259 if (vsi->idx < pf->next_vsi)
11260 pf->next_vsi = vsi->idx;
11263 mutex_unlock(&pf->switch_mutex);
11271 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
11272 * @vsi: the VSI being cleaned
11274 static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
11278 if (vsi->tx_rings && vsi->tx_rings[0]) {
11279 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
11280 kfree_rcu(vsi->tx_rings[i], rcu);
11281 WRITE_ONCE(vsi->tx_rings[i], NULL);
11282 WRITE_ONCE(vsi->rx_rings[i], NULL);
11283 if (vsi->xdp_rings)
11284 WRITE_ONCE(vsi->xdp_rings[i], NULL);
11290 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
11291 * @vsi: the VSI being configured
11293 static int i40e_alloc_rings(struct i40e_vsi *vsi)
11295 int i, qpv = i40e_enabled_xdp_vsi(vsi) ? 3 : 2;
11296 struct i40e_pf *pf = vsi->back;
11297 struct i40e_ring *ring;
11299 /* Set basic values in the rings to be used later during open() */
11300 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
11301 /* allocate space for both Tx and Rx in one shot */
11302 ring = kcalloc(qpv, sizeof(struct i40e_ring), GFP_KERNEL);
11306 ring->queue_index = i;
11307 ring->reg_idx = vsi->base_queue + i;
11308 ring->ring_active = false;
11310 ring->netdev = vsi->netdev;
11311 ring->dev = &pf->pdev->dev;
11312 ring->count = vsi->num_tx_desc;
11315 if (vsi->back->hw_features & I40E_HW_WB_ON_ITR_CAPABLE)
11316 ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
11317 ring->itr_setting = pf->tx_itr_default;
11318 WRITE_ONCE(vsi->tx_rings[i], ring++);
11320 if (!i40e_enabled_xdp_vsi(vsi))
11323 ring->queue_index = vsi->alloc_queue_pairs + i;
11324 ring->reg_idx = vsi->base_queue + ring->queue_index;
11325 ring->ring_active = false;
11327 ring->netdev = NULL;
11328 ring->dev = &pf->pdev->dev;
11329 ring->count = vsi->num_tx_desc;
11332 if (vsi->back->hw_features & I40E_HW_WB_ON_ITR_CAPABLE)
11333 ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
11334 set_ring_xdp(ring);
11335 ring->itr_setting = pf->tx_itr_default;
11336 WRITE_ONCE(vsi->xdp_rings[i], ring++);
11339 ring->queue_index = i;
11340 ring->reg_idx = vsi->base_queue + i;
11341 ring->ring_active = false;
11343 ring->netdev = vsi->netdev;
11344 ring->dev = &pf->pdev->dev;
11345 ring->count = vsi->num_rx_desc;
11348 ring->itr_setting = pf->rx_itr_default;
11349 WRITE_ONCE(vsi->rx_rings[i], ring);
11355 i40e_vsi_clear_rings(vsi);
11360 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
11361 * @pf: board private structure
11362 * @vectors: the number of MSI-X vectors to request
11364 * Returns the number of vectors reserved, or error
11366 static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
11368 vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
11369 I40E_MIN_MSIX, vectors);
11371 dev_info(&pf->pdev->dev,
11372 "MSI-X vector reservation failed: %d\n", vectors);
11380 * i40e_init_msix - Setup the MSIX capability
11381 * @pf: board private structure
11383 * Work with the OS to set up the MSIX vectors needed.
11385 * Returns the number of vectors reserved or negative on failure
11387 static int i40e_init_msix(struct i40e_pf *pf)
11389 struct i40e_hw *hw = &pf->hw;
11390 int cpus, extra_vectors;
11394 int iwarp_requested = 0;
11396 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
11399 /* The number of vectors we'll request will be comprised of:
11400 * - Add 1 for "other" cause for Admin Queue events, etc.
11401 * - The number of LAN queue pairs
11402 * - Queues being used for RSS.
11403 * We don't need as many as max_rss_size vectors.
11404 * use rss_size instead in the calculation since that
11405 * is governed by number of cpus in the system.
11406 * - assumes symmetric Tx/Rx pairing
11407 * - The number of VMDq pairs
11408 * - The CPU count within the NUMA node if iWARP is enabled
11409 * Once we count this up, try the request.
11411 * If we can't get what we want, we'll simplify to nearly nothing
11412 * and try again. If that still fails, we punt.
11414 vectors_left = hw->func_caps.num_msix_vectors;
11417 /* reserve one vector for miscellaneous handler */
11418 if (vectors_left) {
11423 /* reserve some vectors for the main PF traffic queues. Initially we
11424 * only reserve at most 50% of the available vectors, in the case that
11425 * the number of online CPUs is large. This ensures that we can enable
11426 * extra features as well. Once we've enabled the other features, we
11427 * will use any remaining vectors to reach as close as we can to the
11428 * number of online CPUs.
11430 cpus = num_online_cpus();
11431 pf->num_lan_msix = min_t(int, cpus, vectors_left / 2);
11432 vectors_left -= pf->num_lan_msix;
11434 /* reserve one vector for sideband flow director */
11435 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
11436 if (vectors_left) {
11437 pf->num_fdsb_msix = 1;
11441 pf->num_fdsb_msix = 0;
11445 /* can we reserve enough for iWARP? */
11446 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
11447 iwarp_requested = pf->num_iwarp_msix;
11450 pf->num_iwarp_msix = 0;
11451 else if (vectors_left < pf->num_iwarp_msix)
11452 pf->num_iwarp_msix = 1;
11453 v_budget += pf->num_iwarp_msix;
11454 vectors_left -= pf->num_iwarp_msix;
11457 /* any vectors left over go for VMDq support */
11458 if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
11459 if (!vectors_left) {
11460 pf->num_vmdq_msix = 0;
11461 pf->num_vmdq_qps = 0;
11463 int vmdq_vecs_wanted =
11464 pf->num_vmdq_vsis * pf->num_vmdq_qps;
11466 min_t(int, vectors_left, vmdq_vecs_wanted);
11468 /* if we're short on vectors for what's desired, we limit
11469 * the queues per vmdq. If this is still more than are
11470 * available, the user will need to change the number of
11471 * queues/vectors used by the PF later with the ethtool
11474 if (vectors_left < vmdq_vecs_wanted) {
11475 pf->num_vmdq_qps = 1;
11476 vmdq_vecs_wanted = pf->num_vmdq_vsis;
11477 vmdq_vecs = min_t(int,
11481 pf->num_vmdq_msix = pf->num_vmdq_qps;
11483 v_budget += vmdq_vecs;
11484 vectors_left -= vmdq_vecs;
11488 /* On systems with a large number of SMP cores, we previously limited
11489 * the number of vectors for num_lan_msix to be at most 50% of the
11490 * available vectors, to allow for other features. Now, we add back
11491 * the remaining vectors. However, we ensure that the total
11492 * num_lan_msix will not exceed num_online_cpus(). To do this, we
11493 * calculate the number of vectors we can add without going over the
11494 * cap of CPUs. For systems with a small number of CPUs this will be
11497 extra_vectors = min_t(int, cpus - pf->num_lan_msix, vectors_left);
11498 pf->num_lan_msix += extra_vectors;
11499 vectors_left -= extra_vectors;
11501 WARN(vectors_left < 0,
11502 "Calculation of remaining vectors underflowed. This is an accounting bug when determining total MSI-X vectors.\n");
11504 v_budget += pf->num_lan_msix;
11505 pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
11507 if (!pf->msix_entries)
11510 for (i = 0; i < v_budget; i++)
11511 pf->msix_entries[i].entry = i;
11512 v_actual = i40e_reserve_msix_vectors(pf, v_budget);
11514 if (v_actual < I40E_MIN_MSIX) {
11515 pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
11516 kfree(pf->msix_entries);
11517 pf->msix_entries = NULL;
11518 pci_disable_msix(pf->pdev);
11521 } else if (v_actual == I40E_MIN_MSIX) {
11522 /* Adjust for minimal MSIX use */
11523 pf->num_vmdq_vsis = 0;
11524 pf->num_vmdq_qps = 0;
11525 pf->num_lan_qps = 1;
11526 pf->num_lan_msix = 1;
11528 } else if (v_actual != v_budget) {
11529 /* If we have limited resources, we will start with no vectors
11530 * for the special features and then allocate vectors to some
11531 * of these features based on the policy and at the end disable
11532 * the features that did not get any vectors.
11536 dev_info(&pf->pdev->dev,
11537 "MSI-X vector limit reached with %d, wanted %d, attempting to redistribute vectors\n",
11538 v_actual, v_budget);
11539 /* reserve the misc vector */
11540 vec = v_actual - 1;
11542 /* Scale vector usage down */
11543 pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
11544 pf->num_vmdq_vsis = 1;
11545 pf->num_vmdq_qps = 1;
11547 /* partition out the remaining vectors */
11550 pf->num_lan_msix = 1;
11553 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
11554 pf->num_lan_msix = 1;
11555 pf->num_iwarp_msix = 1;
11557 pf->num_lan_msix = 2;
11561 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
11562 pf->num_iwarp_msix = min_t(int, (vec / 3),
11564 pf->num_vmdq_vsis = min_t(int, (vec / 3),
11565 I40E_DEFAULT_NUM_VMDQ_VSI);
11567 pf->num_vmdq_vsis = min_t(int, (vec / 2),
11568 I40E_DEFAULT_NUM_VMDQ_VSI);
11570 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
11571 pf->num_fdsb_msix = 1;
11574 pf->num_lan_msix = min_t(int,
11575 (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)),
11577 pf->num_lan_qps = pf->num_lan_msix;
11582 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
11583 (pf->num_fdsb_msix == 0)) {
11584 dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n");
11585 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
11586 pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
11588 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
11589 (pf->num_vmdq_msix == 0)) {
11590 dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
11591 pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
11594 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
11595 (pf->num_iwarp_msix == 0)) {
11596 dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n");
11597 pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
11599 i40e_debug(&pf->hw, I40E_DEBUG_INIT,
11600 "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n",
11602 pf->num_vmdq_msix * pf->num_vmdq_vsis,
11604 pf->num_iwarp_msix);
11610 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
11611 * @vsi: the VSI being configured
11612 * @v_idx: index of the vector in the vsi struct
11614 * We allocate one q_vector. If allocation fails we return -ENOMEM.
11616 static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx)
11618 struct i40e_q_vector *q_vector;
11620 /* allocate q_vector */
11621 q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
11625 q_vector->vsi = vsi;
11626 q_vector->v_idx = v_idx;
11627 cpumask_copy(&q_vector->affinity_mask, cpu_possible_mask);
11630 netif_napi_add(vsi->netdev, &q_vector->napi,
11631 i40e_napi_poll, NAPI_POLL_WEIGHT);
11633 /* tie q_vector and vsi together */
11634 vsi->q_vectors[v_idx] = q_vector;
11640 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
11641 * @vsi: the VSI being configured
11643 * We allocate one q_vector per queue interrupt. If allocation fails we
11646 static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
11648 struct i40e_pf *pf = vsi->back;
11649 int err, v_idx, num_q_vectors;
11651 /* if not MSIX, give the one vector only to the LAN VSI */
11652 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
11653 num_q_vectors = vsi->num_q_vectors;
11654 else if (vsi == pf->vsi[pf->lan_vsi])
11659 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
11660 err = i40e_vsi_alloc_q_vector(vsi, v_idx);
11669 i40e_free_q_vector(vsi, v_idx);
11675 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
11676 * @pf: board private structure to initialize
11678 static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
11683 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
11684 vectors = i40e_init_msix(pf);
11686 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
11687 I40E_FLAG_IWARP_ENABLED |
11688 I40E_FLAG_RSS_ENABLED |
11689 I40E_FLAG_DCB_CAPABLE |
11690 I40E_FLAG_DCB_ENABLED |
11691 I40E_FLAG_SRIOV_ENABLED |
11692 I40E_FLAG_FD_SB_ENABLED |
11693 I40E_FLAG_FD_ATR_ENABLED |
11694 I40E_FLAG_VMDQ_ENABLED);
11695 pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
11697 /* rework the queue expectations without MSIX */
11698 i40e_determine_queue_usage(pf);
11702 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
11703 (pf->flags & I40E_FLAG_MSI_ENABLED)) {
11704 dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
11705 vectors = pci_enable_msi(pf->pdev);
11707 dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
11709 pf->flags &= ~I40E_FLAG_MSI_ENABLED;
11711 vectors = 1; /* one MSI or Legacy vector */
11714 if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
11715 dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
11717 /* set up vector assignment tracking */
11718 size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
11719 pf->irq_pile = kzalloc(size, GFP_KERNEL);
11723 pf->irq_pile->num_entries = vectors;
11724 pf->irq_pile->search_hint = 0;
11726 /* track first vector for misc interrupts, ignore return */
11727 (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
11733 * i40e_restore_interrupt_scheme - Restore the interrupt scheme
11734 * @pf: private board data structure
11736 * Restore the interrupt scheme that was cleared when we suspended the
11737 * device. This should be called during resume to re-allocate the q_vectors
11738 * and reacquire IRQs.
11740 static int i40e_restore_interrupt_scheme(struct i40e_pf *pf)
11744 /* We cleared the MSI and MSI-X flags when disabling the old interrupt
11745 * scheme. We need to re-enabled them here in order to attempt to
11746 * re-acquire the MSI or MSI-X vectors
11748 pf->flags |= (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
11750 err = i40e_init_interrupt_scheme(pf);
11754 /* Now that we've re-acquired IRQs, we need to remap the vectors and
11755 * rings together again.
11757 for (i = 0; i < pf->num_alloc_vsi; i++) {
11759 err = i40e_vsi_alloc_q_vectors(pf->vsi[i]);
11762 i40e_vsi_map_rings_to_vectors(pf->vsi[i]);
11766 err = i40e_setup_misc_vector(pf);
11770 if (pf->flags & I40E_FLAG_IWARP_ENABLED)
11771 i40e_client_update_msix_info(pf);
11778 i40e_vsi_free_q_vectors(pf->vsi[i]);
11785 * i40e_setup_misc_vector_for_recovery_mode - Setup the misc vector to handle
11786 * non queue events in recovery mode
11787 * @pf: board private structure
11789 * This sets up the handler for MSIX 0 or MSI/legacy, which is used to manage
11790 * the non-queue interrupts, e.g. AdminQ and errors in recovery mode.
11791 * This is handled differently than in recovery mode since no Tx/Rx resources
11792 * are being allocated.
11794 static int i40e_setup_misc_vector_for_recovery_mode(struct i40e_pf *pf)
11798 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
11799 err = i40e_setup_misc_vector(pf);
11802 dev_info(&pf->pdev->dev,
11803 "MSI-X misc vector request failed, error %d\n",
11808 u32 flags = pf->flags & I40E_FLAG_MSI_ENABLED ? 0 : IRQF_SHARED;
11810 err = request_irq(pf->pdev->irq, i40e_intr, flags,
11814 dev_info(&pf->pdev->dev,
11815 "MSI/legacy misc vector request failed, error %d\n",
11819 i40e_enable_misc_int_causes(pf);
11820 i40e_irq_dynamic_enable_icr0(pf);
11827 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
11828 * @pf: board private structure
11830 * This sets up the handler for MSIX 0, which is used to manage the
11831 * non-queue interrupts, e.g. AdminQ and errors. This is not used
11832 * when in MSI or Legacy interrupt mode.
11834 static int i40e_setup_misc_vector(struct i40e_pf *pf)
11836 struct i40e_hw *hw = &pf->hw;
11839 /* Only request the IRQ once, the first time through. */
11840 if (!test_and_set_bit(__I40E_MISC_IRQ_REQUESTED, pf->state)) {
11841 err = request_irq(pf->msix_entries[0].vector,
11842 i40e_intr, 0, pf->int_name, pf);
11844 clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state);
11845 dev_info(&pf->pdev->dev,
11846 "request_irq for %s failed: %d\n",
11847 pf->int_name, err);
11852 i40e_enable_misc_int_causes(pf);
11854 /* associate no queues to the misc vector */
11855 wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
11856 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K >> 1);
11860 i40e_irq_dynamic_enable_icr0(pf);
11866 * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
11867 * @vsi: Pointer to vsi structure
11868 * @seed: Buffter to store the hash keys
11869 * @lut: Buffer to store the lookup table entries
11870 * @lut_size: Size of buffer to store the lookup table entries
11872 * Return 0 on success, negative on failure
11874 static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
11875 u8 *lut, u16 lut_size)
11877 struct i40e_pf *pf = vsi->back;
11878 struct i40e_hw *hw = &pf->hw;
11882 ret = i40e_aq_get_rss_key(hw, vsi->id,
11883 (struct i40e_aqc_get_set_rss_key_data *)seed);
11885 dev_info(&pf->pdev->dev,
11886 "Cannot get RSS key, err %s aq_err %s\n",
11887 i40e_stat_str(&pf->hw, ret),
11888 i40e_aq_str(&pf->hw,
11889 pf->hw.aq.asq_last_status));
11895 bool pf_lut = vsi->type == I40E_VSI_MAIN;
11897 ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
11899 dev_info(&pf->pdev->dev,
11900 "Cannot get RSS lut, err %s aq_err %s\n",
11901 i40e_stat_str(&pf->hw, ret),
11902 i40e_aq_str(&pf->hw,
11903 pf->hw.aq.asq_last_status));
11912 * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
11913 * @vsi: Pointer to vsi structure
11914 * @seed: RSS hash seed
11915 * @lut: Lookup table
11916 * @lut_size: Lookup table size
11918 * Returns 0 on success, negative on failure
11920 static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
11921 const u8 *lut, u16 lut_size)
11923 struct i40e_pf *pf = vsi->back;
11924 struct i40e_hw *hw = &pf->hw;
11925 u16 vf_id = vsi->vf_id;
11928 /* Fill out hash function seed */
11930 u32 *seed_dw = (u32 *)seed;
11932 if (vsi->type == I40E_VSI_MAIN) {
11933 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
11934 wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]);
11935 } else if (vsi->type == I40E_VSI_SRIOV) {
11936 for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++)
11937 wr32(hw, I40E_VFQF_HKEY1(i, vf_id), seed_dw[i]);
11939 dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n");
11944 u32 *lut_dw = (u32 *)lut;
11946 if (vsi->type == I40E_VSI_MAIN) {
11947 if (lut_size != I40E_HLUT_ARRAY_SIZE)
11949 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
11950 wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
11951 } else if (vsi->type == I40E_VSI_SRIOV) {
11952 if (lut_size != I40E_VF_HLUT_ARRAY_SIZE)
11954 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
11955 wr32(hw, I40E_VFQF_HLUT1(i, vf_id), lut_dw[i]);
11957 dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
11966 * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
11967 * @vsi: Pointer to VSI structure
11968 * @seed: Buffer to store the keys
11969 * @lut: Buffer to store the lookup table entries
11970 * @lut_size: Size of buffer to store the lookup table entries
11972 * Returns 0 on success, negative on failure
11974 static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
11975 u8 *lut, u16 lut_size)
11977 struct i40e_pf *pf = vsi->back;
11978 struct i40e_hw *hw = &pf->hw;
11982 u32 *seed_dw = (u32 *)seed;
11984 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
11985 seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
11988 u32 *lut_dw = (u32 *)lut;
11990 if (lut_size != I40E_HLUT_ARRAY_SIZE)
11992 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
11993 lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
12000 * i40e_config_rss - Configure RSS keys and lut
12001 * @vsi: Pointer to VSI structure
12002 * @seed: RSS hash seed
12003 * @lut: Lookup table
12004 * @lut_size: Lookup table size
12006 * Returns 0 on success, negative on failure
12008 int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
12010 struct i40e_pf *pf = vsi->back;
12012 if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)
12013 return i40e_config_rss_aq(vsi, seed, lut, lut_size);
12015 return i40e_config_rss_reg(vsi, seed, lut, lut_size);
12019 * i40e_get_rss - Get RSS keys and lut
12020 * @vsi: Pointer to VSI structure
12021 * @seed: Buffer to store the keys
12022 * @lut: Buffer to store the lookup table entries
12023 * @lut_size: Size of buffer to store the lookup table entries
12025 * Returns 0 on success, negative on failure
12027 int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
12029 struct i40e_pf *pf = vsi->back;
12031 if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)
12032 return i40e_get_rss_aq(vsi, seed, lut, lut_size);
12034 return i40e_get_rss_reg(vsi, seed, lut, lut_size);
12038 * i40e_fill_rss_lut - Fill the RSS lookup table with default values
12039 * @pf: Pointer to board private structure
12040 * @lut: Lookup table
12041 * @rss_table_size: Lookup table size
12042 * @rss_size: Range of queue number for hashing
12044 void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
12045 u16 rss_table_size, u16 rss_size)
12049 for (i = 0; i < rss_table_size; i++)
12050 lut[i] = i % rss_size;
12054 * i40e_pf_config_rss - Prepare for RSS if used
12055 * @pf: board private structure
12057 static int i40e_pf_config_rss(struct i40e_pf *pf)
12059 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
12060 u8 seed[I40E_HKEY_ARRAY_SIZE];
12062 struct i40e_hw *hw = &pf->hw;
12067 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
12068 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
12069 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
12070 hena |= i40e_pf_get_default_rss_hena(pf);
12072 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
12073 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
12075 /* Determine the RSS table size based on the hardware capabilities */
12076 reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
12077 reg_val = (pf->rss_table_size == 512) ?
12078 (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
12079 (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
12080 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val);
12082 /* Determine the RSS size of the VSI */
12083 if (!vsi->rss_size) {
12085 /* If the firmware does something weird during VSI init, we
12086 * could end up with zero TCs. Check for that to avoid
12087 * divide-by-zero. It probably won't pass traffic, but it also
12090 qcount = vsi->num_queue_pairs /
12091 (vsi->tc_config.numtc ? vsi->tc_config.numtc : 1);
12092 vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
12094 if (!vsi->rss_size)
12097 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
12101 /* Use user configured lut if there is one, otherwise use default */
12102 if (vsi->rss_lut_user)
12103 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
12105 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
12107 /* Use user configured hash key if there is one, otherwise
12110 if (vsi->rss_hkey_user)
12111 memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
12113 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
12114 ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
12121 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
12122 * @pf: board private structure
12123 * @queue_count: the requested queue count for rss.
12125 * returns 0 if rss is not enabled, if enabled returns the final rss queue
12126 * count which may be different from the requested queue count.
12127 * Note: expects to be called while under rtnl_lock()
12129 int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
12131 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
12134 if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
12137 queue_count = min_t(int, queue_count, num_online_cpus());
12138 new_rss_size = min_t(int, queue_count, pf->rss_size_max);
12140 if (queue_count != vsi->num_queue_pairs) {
12143 vsi->req_queue_pairs = queue_count;
12144 i40e_prep_for_reset(pf);
12146 pf->alloc_rss_size = new_rss_size;
12148 i40e_reset_and_rebuild(pf, true, true);
12150 /* Discard the user configured hash keys and lut, if less
12151 * queues are enabled.
12153 if (queue_count < vsi->rss_size) {
12154 i40e_clear_rss_config_user(vsi);
12155 dev_dbg(&pf->pdev->dev,
12156 "discard user configured hash keys and lut\n");
12159 /* Reset vsi->rss_size, as number of enabled queues changed */
12160 qcount = vsi->num_queue_pairs / vsi->tc_config.numtc;
12161 vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
12163 i40e_pf_config_rss(pf);
12165 dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n",
12166 vsi->req_queue_pairs, pf->rss_size_max);
12167 return pf->alloc_rss_size;
12171 * i40e_get_partition_bw_setting - Retrieve BW settings for this PF partition
12172 * @pf: board private structure
12174 i40e_status i40e_get_partition_bw_setting(struct i40e_pf *pf)
12176 i40e_status status;
12177 bool min_valid, max_valid;
12178 u32 max_bw, min_bw;
12180 status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
12181 &min_valid, &max_valid);
12185 pf->min_bw = min_bw;
12187 pf->max_bw = max_bw;
12194 * i40e_set_partition_bw_setting - Set BW settings for this PF partition
12195 * @pf: board private structure
12197 i40e_status i40e_set_partition_bw_setting(struct i40e_pf *pf)
12199 struct i40e_aqc_configure_partition_bw_data bw_data;
12200 i40e_status status;
12202 memset(&bw_data, 0, sizeof(bw_data));
12204 /* Set the valid bit for this PF */
12205 bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
12206 bw_data.max_bw[pf->hw.pf_id] = pf->max_bw & I40E_ALT_BW_VALUE_MASK;
12207 bw_data.min_bw[pf->hw.pf_id] = pf->min_bw & I40E_ALT_BW_VALUE_MASK;
12209 /* Set the new bandwidths */
12210 status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
12216 * i40e_commit_partition_bw_setting - Commit BW settings for this PF partition
12217 * @pf: board private structure
12219 i40e_status i40e_commit_partition_bw_setting(struct i40e_pf *pf)
12221 /* Commit temporary BW setting to permanent NVM image */
12222 enum i40e_admin_queue_err last_aq_status;
12226 if (pf->hw.partition_id != 1) {
12227 dev_info(&pf->pdev->dev,
12228 "Commit BW only works on partition 1! This is partition %d",
12229 pf->hw.partition_id);
12230 ret = I40E_NOT_SUPPORTED;
12231 goto bw_commit_out;
12234 /* Acquire NVM for read access */
12235 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
12236 last_aq_status = pf->hw.aq.asq_last_status;
12238 dev_info(&pf->pdev->dev,
12239 "Cannot acquire NVM for read access, err %s aq_err %s\n",
12240 i40e_stat_str(&pf->hw, ret),
12241 i40e_aq_str(&pf->hw, last_aq_status));
12242 goto bw_commit_out;
12245 /* Read word 0x10 of NVM - SW compatibility word 1 */
12246 ret = i40e_aq_read_nvm(&pf->hw,
12247 I40E_SR_NVM_CONTROL_WORD,
12248 0x10, sizeof(nvm_word), &nvm_word,
12250 /* Save off last admin queue command status before releasing
12253 last_aq_status = pf->hw.aq.asq_last_status;
12254 i40e_release_nvm(&pf->hw);
12256 dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
12257 i40e_stat_str(&pf->hw, ret),
12258 i40e_aq_str(&pf->hw, last_aq_status));
12259 goto bw_commit_out;
12262 /* Wait a bit for NVM release to complete */
12265 /* Acquire NVM for write access */
12266 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
12267 last_aq_status = pf->hw.aq.asq_last_status;
12269 dev_info(&pf->pdev->dev,
12270 "Cannot acquire NVM for write access, err %s aq_err %s\n",
12271 i40e_stat_str(&pf->hw, ret),
12272 i40e_aq_str(&pf->hw, last_aq_status));
12273 goto bw_commit_out;
12275 /* Write it back out unchanged to initiate update NVM,
12276 * which will force a write of the shadow (alt) RAM to
12277 * the NVM - thus storing the bandwidth values permanently.
12279 ret = i40e_aq_update_nvm(&pf->hw,
12280 I40E_SR_NVM_CONTROL_WORD,
12281 0x10, sizeof(nvm_word),
12282 &nvm_word, true, 0, NULL);
12283 /* Save off last admin queue command status before releasing
12286 last_aq_status = pf->hw.aq.asq_last_status;
12287 i40e_release_nvm(&pf->hw);
12289 dev_info(&pf->pdev->dev,
12290 "BW settings NOT SAVED, err %s aq_err %s\n",
12291 i40e_stat_str(&pf->hw, ret),
12292 i40e_aq_str(&pf->hw, last_aq_status));
12299 * i40e_is_total_port_shutdown_enabled - read NVM and return value
12300 * if total port shutdown feature is enabled for this PF
12301 * @pf: board private structure
12303 static bool i40e_is_total_port_shutdown_enabled(struct i40e_pf *pf)
12305 #define I40E_TOTAL_PORT_SHUTDOWN_ENABLED BIT(4)
12306 #define I40E_FEATURES_ENABLE_PTR 0x2A
12307 #define I40E_CURRENT_SETTING_PTR 0x2B
12308 #define I40E_LINK_BEHAVIOR_WORD_OFFSET 0x2D
12309 #define I40E_LINK_BEHAVIOR_WORD_LENGTH 0x1
12310 #define I40E_LINK_BEHAVIOR_OS_FORCED_ENABLED BIT(0)
12311 #define I40E_LINK_BEHAVIOR_PORT_BIT_LENGTH 4
12312 i40e_status read_status = I40E_SUCCESS;
12313 u16 sr_emp_sr_settings_ptr = 0;
12314 u16 features_enable = 0;
12315 u16 link_behavior = 0;
12318 read_status = i40e_read_nvm_word(&pf->hw,
12319 I40E_SR_EMP_SR_SETTINGS_PTR,
12320 &sr_emp_sr_settings_ptr);
12323 read_status = i40e_read_nvm_word(&pf->hw,
12324 sr_emp_sr_settings_ptr +
12325 I40E_FEATURES_ENABLE_PTR,
12329 if (I40E_TOTAL_PORT_SHUTDOWN_ENABLED & features_enable) {
12330 read_status = i40e_read_nvm_module_data(&pf->hw,
12331 I40E_SR_EMP_SR_SETTINGS_PTR,
12332 I40E_CURRENT_SETTING_PTR,
12333 I40E_LINK_BEHAVIOR_WORD_OFFSET,
12334 I40E_LINK_BEHAVIOR_WORD_LENGTH,
12338 link_behavior >>= (pf->hw.port * I40E_LINK_BEHAVIOR_PORT_BIT_LENGTH);
12339 ret = I40E_LINK_BEHAVIOR_OS_FORCED_ENABLED & link_behavior;
12344 dev_warn(&pf->pdev->dev,
12345 "total-port-shutdown feature is off due to read nvm error: %s\n",
12346 i40e_stat_str(&pf->hw, read_status));
12351 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
12352 * @pf: board private structure to initialize
12354 * i40e_sw_init initializes the Adapter private data structure.
12355 * Fields are initialized based on PCI device information and
12356 * OS network device settings (MTU size).
12358 static int i40e_sw_init(struct i40e_pf *pf)
12363 /* Set default capability flags */
12364 pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
12365 I40E_FLAG_MSI_ENABLED |
12366 I40E_FLAG_MSIX_ENABLED;
12368 /* Set default ITR */
12369 pf->rx_itr_default = I40E_ITR_RX_DEF;
12370 pf->tx_itr_default = I40E_ITR_TX_DEF;
12372 /* Depending on PF configurations, it is possible that the RSS
12373 * maximum might end up larger than the available queues
12375 pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
12376 pf->alloc_rss_size = 1;
12377 pf->rss_table_size = pf->hw.func_caps.rss_table_size;
12378 pf->rss_size_max = min_t(int, pf->rss_size_max,
12379 pf->hw.func_caps.num_tx_qp);
12380 if (pf->hw.func_caps.rss) {
12381 pf->flags |= I40E_FLAG_RSS_ENABLED;
12382 pf->alloc_rss_size = min_t(int, pf->rss_size_max,
12383 num_online_cpus());
12386 /* MFP mode enabled */
12387 if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
12388 pf->flags |= I40E_FLAG_MFP_ENABLED;
12389 dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
12390 if (i40e_get_partition_bw_setting(pf)) {
12391 dev_warn(&pf->pdev->dev,
12392 "Could not get partition bw settings\n");
12394 dev_info(&pf->pdev->dev,
12395 "Partition BW Min = %8.8x, Max = %8.8x\n",
12396 pf->min_bw, pf->max_bw);
12398 /* nudge the Tx scheduler */
12399 i40e_set_partition_bw_setting(pf);
12403 if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
12404 (pf->hw.func_caps.fd_filters_best_effort > 0)) {
12405 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
12406 pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
12407 if (pf->flags & I40E_FLAG_MFP_ENABLED &&
12408 pf->hw.num_partitions > 1)
12409 dev_info(&pf->pdev->dev,
12410 "Flow Director Sideband mode Disabled in MFP mode\n");
12412 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
12413 pf->fdir_pf_filter_count =
12414 pf->hw.func_caps.fd_filters_guaranteed;
12415 pf->hw.fdir_shared_filter_count =
12416 pf->hw.func_caps.fd_filters_best_effort;
12419 if (pf->hw.mac.type == I40E_MAC_X722) {
12420 pf->hw_features |= (I40E_HW_RSS_AQ_CAPABLE |
12421 I40E_HW_128_QP_RSS_CAPABLE |
12422 I40E_HW_ATR_EVICT_CAPABLE |
12423 I40E_HW_WB_ON_ITR_CAPABLE |
12424 I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE |
12425 I40E_HW_NO_PCI_LINK_CHECK |
12426 I40E_HW_USE_SET_LLDP_MIB |
12427 I40E_HW_GENEVE_OFFLOAD_CAPABLE |
12428 I40E_HW_PTP_L4_CAPABLE |
12429 I40E_HW_WOL_MC_MAGIC_PKT_WAKE |
12430 I40E_HW_OUTER_UDP_CSUM_CAPABLE);
12432 #define I40E_FDEVICT_PCTYPE_DEFAULT 0xc03
12433 if (rd32(&pf->hw, I40E_GLQF_FDEVICTENA(1)) !=
12434 I40E_FDEVICT_PCTYPE_DEFAULT) {
12435 dev_warn(&pf->pdev->dev,
12436 "FD EVICT PCTYPES are not right, disable FD HW EVICT\n");
12437 pf->hw_features &= ~I40E_HW_ATR_EVICT_CAPABLE;
12439 } else if ((pf->hw.aq.api_maj_ver > 1) ||
12440 ((pf->hw.aq.api_maj_ver == 1) &&
12441 (pf->hw.aq.api_min_ver > 4))) {
12442 /* Supported in FW API version higher than 1.4 */
12443 pf->hw_features |= I40E_HW_GENEVE_OFFLOAD_CAPABLE;
12446 /* Enable HW ATR eviction if possible */
12447 if (pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE)
12448 pf->flags |= I40E_FLAG_HW_ATR_EVICT_ENABLED;
12450 if ((pf->hw.mac.type == I40E_MAC_XL710) &&
12451 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
12452 (pf->hw.aq.fw_maj_ver < 4))) {
12453 pf->hw_features |= I40E_HW_RESTART_AUTONEG;
12454 /* No DCB support for FW < v4.33 */
12455 pf->hw_features |= I40E_HW_NO_DCB_SUPPORT;
12458 /* Disable FW LLDP if FW < v4.3 */
12459 if ((pf->hw.mac.type == I40E_MAC_XL710) &&
12460 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
12461 (pf->hw.aq.fw_maj_ver < 4)))
12462 pf->hw_features |= I40E_HW_STOP_FW_LLDP;
12464 /* Use the FW Set LLDP MIB API if FW > v4.40 */
12465 if ((pf->hw.mac.type == I40E_MAC_XL710) &&
12466 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) ||
12467 (pf->hw.aq.fw_maj_ver >= 5)))
12468 pf->hw_features |= I40E_HW_USE_SET_LLDP_MIB;
12470 /* Enable PTP L4 if FW > v6.0 */
12471 if (pf->hw.mac.type == I40E_MAC_XL710 &&
12472 pf->hw.aq.fw_maj_ver >= 6)
12473 pf->hw_features |= I40E_HW_PTP_L4_CAPABLE;
12475 if (pf->hw.func_caps.vmdq && num_online_cpus() != 1) {
12476 pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
12477 pf->flags |= I40E_FLAG_VMDQ_ENABLED;
12478 pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
12481 if (pf->hw.func_caps.iwarp && num_online_cpus() != 1) {
12482 pf->flags |= I40E_FLAG_IWARP_ENABLED;
12483 /* IWARP needs one extra vector for CQP just like MISC.*/
12484 pf->num_iwarp_msix = (int)num_online_cpus() + 1;
12486 /* Stopping FW LLDP engine is supported on XL710 and X722
12487 * starting from FW versions determined in i40e_init_adminq.
12488 * Stopping the FW LLDP engine is not supported on XL710
12489 * if NPAR is functioning so unset this hw flag in this case.
12491 if (pf->hw.mac.type == I40E_MAC_XL710 &&
12492 pf->hw.func_caps.npar_enable &&
12493 (pf->hw.flags & I40E_HW_FLAG_FW_LLDP_STOPPABLE))
12494 pf->hw.flags &= ~I40E_HW_FLAG_FW_LLDP_STOPPABLE;
12496 #ifdef CONFIG_PCI_IOV
12497 if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
12498 pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
12499 pf->flags |= I40E_FLAG_SRIOV_ENABLED;
12500 pf->num_req_vfs = min_t(int,
12501 pf->hw.func_caps.num_vfs,
12502 I40E_MAX_VF_COUNT);
12504 #endif /* CONFIG_PCI_IOV */
12505 pf->eeprom_version = 0xDEAD;
12506 pf->lan_veb = I40E_NO_VEB;
12507 pf->lan_vsi = I40E_NO_VSI;
12509 /* By default FW has this off for performance reasons */
12510 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
12512 /* set up queue assignment tracking */
12513 size = sizeof(struct i40e_lump_tracking)
12514 + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
12515 pf->qp_pile = kzalloc(size, GFP_KERNEL);
12516 if (!pf->qp_pile) {
12520 pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
12521 pf->qp_pile->search_hint = 0;
12523 pf->tx_timeout_recovery_level = 1;
12525 if (pf->hw.mac.type != I40E_MAC_X722 &&
12526 i40e_is_total_port_shutdown_enabled(pf)) {
12527 /* Link down on close must be on when total port shutdown
12528 * is enabled for a given port
12530 pf->flags |= (I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENABLED |
12531 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED);
12532 dev_info(&pf->pdev->dev,
12533 "total-port-shutdown was enabled, link-down-on-close is forced on\n");
12535 mutex_init(&pf->switch_mutex);
12542 * i40e_set_ntuple - set the ntuple feature flag and take action
12543 * @pf: board private structure to initialize
12544 * @features: the feature set that the stack is suggesting
12546 * returns a bool to indicate if reset needs to happen
12548 bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
12550 bool need_reset = false;
12552 /* Check if Flow Director n-tuple support was enabled or disabled. If
12553 * the state changed, we need to reset.
12555 if (features & NETIF_F_NTUPLE) {
12556 /* Enable filters and mark for reset */
12557 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
12559 /* enable FD_SB only if there is MSI-X vector and no cloud
12562 if (pf->num_fdsb_msix > 0 && !pf->num_cloud_filters) {
12563 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
12564 pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
12567 /* turn off filters, mark for reset and clear SW filter list */
12568 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
12570 i40e_fdir_filter_exit(pf);
12572 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
12573 clear_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state);
12574 pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
12576 /* reset fd counters */
12577 pf->fd_add_err = 0;
12578 pf->fd_atr_cnt = 0;
12579 /* if ATR was auto disabled it can be re-enabled. */
12580 if (test_and_clear_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state))
12581 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
12582 (I40E_DEBUG_FD & pf->hw.debug_mask))
12583 dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
12589 * i40e_clear_rss_lut - clear the rx hash lookup table
12590 * @vsi: the VSI being configured
12592 static void i40e_clear_rss_lut(struct i40e_vsi *vsi)
12594 struct i40e_pf *pf = vsi->back;
12595 struct i40e_hw *hw = &pf->hw;
12596 u16 vf_id = vsi->vf_id;
12599 if (vsi->type == I40E_VSI_MAIN) {
12600 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
12601 wr32(hw, I40E_PFQF_HLUT(i), 0);
12602 } else if (vsi->type == I40E_VSI_SRIOV) {
12603 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
12604 i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0);
12606 dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
12611 * i40e_set_features - set the netdev feature flags
12612 * @netdev: ptr to the netdev being adjusted
12613 * @features: the feature set that the stack is suggesting
12614 * Note: expects to be called while under rtnl_lock()
12616 static int i40e_set_features(struct net_device *netdev,
12617 netdev_features_t features)
12619 struct i40e_netdev_priv *np = netdev_priv(netdev);
12620 struct i40e_vsi *vsi = np->vsi;
12621 struct i40e_pf *pf = vsi->back;
12624 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
12625 i40e_pf_config_rss(pf);
12626 else if (!(features & NETIF_F_RXHASH) &&
12627 netdev->features & NETIF_F_RXHASH)
12628 i40e_clear_rss_lut(vsi);
12630 if (features & NETIF_F_HW_VLAN_CTAG_RX)
12631 i40e_vlan_stripping_enable(vsi);
12633 i40e_vlan_stripping_disable(vsi);
12635 if (!(features & NETIF_F_HW_TC) && pf->num_cloud_filters) {
12636 dev_err(&pf->pdev->dev,
12637 "Offloaded tc filters active, can't turn hw_tc_offload off");
12641 if (!(features & NETIF_F_HW_L2FW_DOFFLOAD) && vsi->macvlan_cnt)
12642 i40e_del_all_macvlans(vsi);
12644 need_reset = i40e_set_ntuple(pf, features);
12647 i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
12652 static int i40e_udp_tunnel_set_port(struct net_device *netdev,
12653 unsigned int table, unsigned int idx,
12654 struct udp_tunnel_info *ti)
12656 struct i40e_netdev_priv *np = netdev_priv(netdev);
12657 struct i40e_hw *hw = &np->vsi->back->hw;
12658 u8 type, filter_index;
12661 type = ti->type == UDP_TUNNEL_TYPE_VXLAN ? I40E_AQC_TUNNEL_TYPE_VXLAN :
12662 I40E_AQC_TUNNEL_TYPE_NGE;
12664 ret = i40e_aq_add_udp_tunnel(hw, ntohs(ti->port), type, &filter_index,
12667 netdev_info(netdev, "add UDP port failed, err %s aq_err %s\n",
12668 i40e_stat_str(hw, ret),
12669 i40e_aq_str(hw, hw->aq.asq_last_status));
12673 udp_tunnel_nic_set_port_priv(netdev, table, idx, filter_index);
12677 static int i40e_udp_tunnel_unset_port(struct net_device *netdev,
12678 unsigned int table, unsigned int idx,
12679 struct udp_tunnel_info *ti)
12681 struct i40e_netdev_priv *np = netdev_priv(netdev);
12682 struct i40e_hw *hw = &np->vsi->back->hw;
12685 ret = i40e_aq_del_udp_tunnel(hw, ti->hw_priv, NULL);
12687 netdev_info(netdev, "delete UDP port failed, err %s aq_err %s\n",
12688 i40e_stat_str(hw, ret),
12689 i40e_aq_str(hw, hw->aq.asq_last_status));
12696 static int i40e_get_phys_port_id(struct net_device *netdev,
12697 struct netdev_phys_item_id *ppid)
12699 struct i40e_netdev_priv *np = netdev_priv(netdev);
12700 struct i40e_pf *pf = np->vsi->back;
12701 struct i40e_hw *hw = &pf->hw;
12703 if (!(pf->hw_features & I40E_HW_PORT_ID_VALID))
12704 return -EOPNOTSUPP;
12706 ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
12707 memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
12713 * i40e_ndo_fdb_add - add an entry to the hardware database
12714 * @ndm: the input from the stack
12715 * @tb: pointer to array of nladdr (unused)
12716 * @dev: the net device pointer
12717 * @addr: the MAC address entry being added
12719 * @flags: instructions from stack about fdb operation
12720 * @extack: netlink extended ack, unused currently
12722 static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
12723 struct net_device *dev,
12724 const unsigned char *addr, u16 vid,
12726 struct netlink_ext_ack *extack)
12728 struct i40e_netdev_priv *np = netdev_priv(dev);
12729 struct i40e_pf *pf = np->vsi->back;
12732 if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
12733 return -EOPNOTSUPP;
12736 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
12740 /* Hardware does not support aging addresses so if a
12741 * ndm_state is given only allow permanent addresses
12743 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
12744 netdev_info(dev, "FDB only supports static addresses\n");
12748 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
12749 err = dev_uc_add_excl(dev, addr);
12750 else if (is_multicast_ether_addr(addr))
12751 err = dev_mc_add_excl(dev, addr);
12755 /* Only return duplicate errors if NLM_F_EXCL is set */
12756 if (err == -EEXIST && !(flags & NLM_F_EXCL))
12763 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
12764 * @dev: the netdev being configured
12765 * @nlh: RTNL message
12766 * @flags: bridge flags
12767 * @extack: netlink extended ack
12769 * Inserts a new hardware bridge if not already created and
12770 * enables the bridging mode requested (VEB or VEPA). If the
12771 * hardware bridge has already been inserted and the request
12772 * is to change the mode then that requires a PF reset to
12773 * allow rebuild of the components with required hardware
12774 * bridge mode enabled.
12776 * Note: expects to be called while under rtnl_lock()
12778 static int i40e_ndo_bridge_setlink(struct net_device *dev,
12779 struct nlmsghdr *nlh,
12781 struct netlink_ext_ack *extack)
12783 struct i40e_netdev_priv *np = netdev_priv(dev);
12784 struct i40e_vsi *vsi = np->vsi;
12785 struct i40e_pf *pf = vsi->back;
12786 struct i40e_veb *veb = NULL;
12787 struct nlattr *attr, *br_spec;
12790 /* Only for PF VSI for now */
12791 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
12792 return -EOPNOTSUPP;
12794 /* Find the HW bridge for PF VSI */
12795 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
12796 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
12800 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
12802 nla_for_each_nested(attr, br_spec, rem) {
12805 if (nla_type(attr) != IFLA_BRIDGE_MODE)
12808 mode = nla_get_u16(attr);
12809 if ((mode != BRIDGE_MODE_VEPA) &&
12810 (mode != BRIDGE_MODE_VEB))
12813 /* Insert a new HW bridge */
12815 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
12816 vsi->tc_config.enabled_tc);
12818 veb->bridge_mode = mode;
12819 i40e_config_bridge_mode(veb);
12821 /* No Bridge HW offload available */
12825 } else if (mode != veb->bridge_mode) {
12826 /* Existing HW bridge but different mode needs reset */
12827 veb->bridge_mode = mode;
12828 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
12829 if (mode == BRIDGE_MODE_VEB)
12830 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
12832 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
12833 i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
12842 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
12845 * @seq: RTNL message seq #
12846 * @dev: the netdev being configured
12847 * @filter_mask: unused
12848 * @nlflags: netlink flags passed in
12850 * Return the mode in which the hardware bridge is operating in
12853 static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
12854 struct net_device *dev,
12855 u32 __always_unused filter_mask,
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;
12864 /* Only for PF VSI for now */
12865 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
12866 return -EOPNOTSUPP;
12868 /* Find the HW bridge for the PF VSI */
12869 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
12870 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
12877 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
12878 0, 0, nlflags, filter_mask, NULL);
12882 * i40e_features_check - Validate encapsulated packet conforms to limits
12884 * @dev: This physical port's netdev
12885 * @features: Offload features that the stack believes apply
12887 static netdev_features_t i40e_features_check(struct sk_buff *skb,
12888 struct net_device *dev,
12889 netdev_features_t features)
12893 /* No point in doing any of this if neither checksum nor GSO are
12894 * being requested for this frame. We can rule out both by just
12895 * checking for CHECKSUM_PARTIAL
12897 if (skb->ip_summed != CHECKSUM_PARTIAL)
12900 /* We cannot support GSO if the MSS is going to be less than
12901 * 64 bytes. If it is then we need to drop support for GSO.
12903 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
12904 features &= ~NETIF_F_GSO_MASK;
12906 /* MACLEN can support at most 63 words */
12907 len = skb_network_header(skb) - skb->data;
12908 if (len & ~(63 * 2))
12911 /* IPLEN and EIPLEN can support at most 127 dwords */
12912 len = skb_transport_header(skb) - skb_network_header(skb);
12913 if (len & ~(127 * 4))
12916 if (skb->encapsulation) {
12917 /* L4TUNLEN can support 127 words */
12918 len = skb_inner_network_header(skb) - skb_transport_header(skb);
12919 if (len & ~(127 * 2))
12922 /* IPLEN can support at most 127 dwords */
12923 len = skb_inner_transport_header(skb) -
12924 skb_inner_network_header(skb);
12925 if (len & ~(127 * 4))
12929 /* No need to validate L4LEN as TCP is the only protocol with a
12930 * a flexible value and we support all possible values supported
12931 * by TCP, which is at most 15 dwords
12936 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
12940 * i40e_xdp_setup - add/remove an XDP program
12941 * @vsi: VSI to changed
12942 * @prog: XDP program
12943 * @extack: netlink extended ack
12945 static int i40e_xdp_setup(struct i40e_vsi *vsi, struct bpf_prog *prog,
12946 struct netlink_ext_ack *extack)
12948 int frame_size = vsi->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
12949 struct i40e_pf *pf = vsi->back;
12950 struct bpf_prog *old_prog;
12954 /* Don't allow frames that span over multiple buffers */
12955 if (frame_size > vsi->rx_buf_len) {
12956 NL_SET_ERR_MSG_MOD(extack, "MTU too large to enable XDP");
12960 /* When turning XDP on->off/off->on we reset and rebuild the rings. */
12961 need_reset = (i40e_enabled_xdp_vsi(vsi) != !!prog);
12964 i40e_prep_for_reset(pf);
12966 old_prog = xchg(&vsi->xdp_prog, prog);
12970 /* Wait until ndo_xsk_wakeup completes. */
12972 i40e_reset_and_rebuild(pf, true, true);
12975 for (i = 0; i < vsi->num_queue_pairs; i++)
12976 WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
12979 bpf_prog_put(old_prog);
12981 /* Kick start the NAPI context if there is an AF_XDP socket open
12982 * on that queue id. This so that receiving will start.
12984 if (need_reset && prog)
12985 for (i = 0; i < vsi->num_queue_pairs; i++)
12986 if (vsi->xdp_rings[i]->xsk_pool)
12987 (void)i40e_xsk_wakeup(vsi->netdev, i,
12994 * i40e_enter_busy_conf - Enters busy config state
12997 * Returns 0 on success, <0 for failure.
12999 static int i40e_enter_busy_conf(struct i40e_vsi *vsi)
13001 struct i40e_pf *pf = vsi->back;
13004 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
13008 usleep_range(1000, 2000);
13015 * i40e_exit_busy_conf - Exits busy config state
13018 static void i40e_exit_busy_conf(struct i40e_vsi *vsi)
13020 struct i40e_pf *pf = vsi->back;
13022 clear_bit(__I40E_CONFIG_BUSY, pf->state);
13026 * i40e_queue_pair_reset_stats - Resets all statistics for a queue pair
13028 * @queue_pair: queue pair
13030 static void i40e_queue_pair_reset_stats(struct i40e_vsi *vsi, int queue_pair)
13032 memset(&vsi->rx_rings[queue_pair]->rx_stats, 0,
13033 sizeof(vsi->rx_rings[queue_pair]->rx_stats));
13034 memset(&vsi->tx_rings[queue_pair]->stats, 0,
13035 sizeof(vsi->tx_rings[queue_pair]->stats));
13036 if (i40e_enabled_xdp_vsi(vsi)) {
13037 memset(&vsi->xdp_rings[queue_pair]->stats, 0,
13038 sizeof(vsi->xdp_rings[queue_pair]->stats));
13043 * i40e_queue_pair_clean_rings - Cleans all the rings of a queue pair
13045 * @queue_pair: queue pair
13047 static void i40e_queue_pair_clean_rings(struct i40e_vsi *vsi, int queue_pair)
13049 i40e_clean_tx_ring(vsi->tx_rings[queue_pair]);
13050 if (i40e_enabled_xdp_vsi(vsi)) {
13051 /* Make sure that in-progress ndo_xdp_xmit calls are
13055 i40e_clean_tx_ring(vsi->xdp_rings[queue_pair]);
13057 i40e_clean_rx_ring(vsi->rx_rings[queue_pair]);
13061 * i40e_queue_pair_toggle_napi - Enables/disables NAPI for a queue pair
13063 * @queue_pair: queue pair
13064 * @enable: true for enable, false for disable
13066 static void i40e_queue_pair_toggle_napi(struct i40e_vsi *vsi, int queue_pair,
13069 struct i40e_ring *rxr = vsi->rx_rings[queue_pair];
13070 struct i40e_q_vector *q_vector = rxr->q_vector;
13075 /* All rings in a qp belong to the same qvector. */
13076 if (q_vector->rx.ring || q_vector->tx.ring) {
13078 napi_enable(&q_vector->napi);
13080 napi_disable(&q_vector->napi);
13085 * i40e_queue_pair_toggle_rings - Enables/disables all rings for a queue pair
13087 * @queue_pair: queue pair
13088 * @enable: true for enable, false for disable
13090 * Returns 0 on success, <0 on failure.
13092 static int i40e_queue_pair_toggle_rings(struct i40e_vsi *vsi, int queue_pair,
13095 struct i40e_pf *pf = vsi->back;
13098 pf_q = vsi->base_queue + queue_pair;
13099 ret = i40e_control_wait_tx_q(vsi->seid, pf, pf_q,
13100 false /*is xdp*/, enable);
13102 dev_info(&pf->pdev->dev,
13103 "VSI seid %d Tx ring %d %sable timeout\n",
13104 vsi->seid, pf_q, (enable ? "en" : "dis"));
13108 i40e_control_rx_q(pf, pf_q, enable);
13109 ret = i40e_pf_rxq_wait(pf, pf_q, enable);
13111 dev_info(&pf->pdev->dev,
13112 "VSI seid %d Rx ring %d %sable timeout\n",
13113 vsi->seid, pf_q, (enable ? "en" : "dis"));
13117 /* Due to HW errata, on Rx disable only, the register can
13118 * indicate done before it really is. Needs 50ms to be sure
13123 if (!i40e_enabled_xdp_vsi(vsi))
13126 ret = i40e_control_wait_tx_q(vsi->seid, pf,
13127 pf_q + vsi->alloc_queue_pairs,
13128 true /*is xdp*/, enable);
13130 dev_info(&pf->pdev->dev,
13131 "VSI seid %d XDP Tx ring %d %sable timeout\n",
13132 vsi->seid, pf_q, (enable ? "en" : "dis"));
13139 * i40e_queue_pair_enable_irq - Enables interrupts for a queue pair
13141 * @queue_pair: queue_pair
13143 static void i40e_queue_pair_enable_irq(struct i40e_vsi *vsi, int queue_pair)
13145 struct i40e_ring *rxr = vsi->rx_rings[queue_pair];
13146 struct i40e_pf *pf = vsi->back;
13147 struct i40e_hw *hw = &pf->hw;
13149 /* All rings in a qp belong to the same qvector. */
13150 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
13151 i40e_irq_dynamic_enable(vsi, rxr->q_vector->v_idx);
13153 i40e_irq_dynamic_enable_icr0(pf);
13159 * i40e_queue_pair_disable_irq - Disables interrupts for a queue pair
13161 * @queue_pair: queue_pair
13163 static void i40e_queue_pair_disable_irq(struct i40e_vsi *vsi, int queue_pair)
13165 struct i40e_ring *rxr = vsi->rx_rings[queue_pair];
13166 struct i40e_pf *pf = vsi->back;
13167 struct i40e_hw *hw = &pf->hw;
13169 /* For simplicity, instead of removing the qp interrupt causes
13170 * from the interrupt linked list, we simply disable the interrupt, and
13171 * leave the list intact.
13173 * All rings in a qp belong to the same qvector.
13175 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
13176 u32 intpf = vsi->base_vector + rxr->q_vector->v_idx;
13178 wr32(hw, I40E_PFINT_DYN_CTLN(intpf - 1), 0);
13180 synchronize_irq(pf->msix_entries[intpf].vector);
13182 /* Legacy and MSI mode - this stops all interrupt handling */
13183 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
13184 wr32(hw, I40E_PFINT_DYN_CTL0, 0);
13186 synchronize_irq(pf->pdev->irq);
13191 * i40e_queue_pair_disable - Disables a queue pair
13193 * @queue_pair: queue pair
13195 * Returns 0 on success, <0 on failure.
13197 int i40e_queue_pair_disable(struct i40e_vsi *vsi, int queue_pair)
13201 err = i40e_enter_busy_conf(vsi);
13205 i40e_queue_pair_disable_irq(vsi, queue_pair);
13206 err = i40e_queue_pair_toggle_rings(vsi, queue_pair, false /* off */);
13207 i40e_queue_pair_toggle_napi(vsi, queue_pair, false /* off */);
13208 i40e_queue_pair_clean_rings(vsi, queue_pair);
13209 i40e_queue_pair_reset_stats(vsi, queue_pair);
13215 * i40e_queue_pair_enable - Enables a queue pair
13217 * @queue_pair: queue pair
13219 * Returns 0 on success, <0 on failure.
13221 int i40e_queue_pair_enable(struct i40e_vsi *vsi, int queue_pair)
13225 err = i40e_configure_tx_ring(vsi->tx_rings[queue_pair]);
13229 if (i40e_enabled_xdp_vsi(vsi)) {
13230 err = i40e_configure_tx_ring(vsi->xdp_rings[queue_pair]);
13235 err = i40e_configure_rx_ring(vsi->rx_rings[queue_pair]);
13239 err = i40e_queue_pair_toggle_rings(vsi, queue_pair, true /* on */);
13240 i40e_queue_pair_toggle_napi(vsi, queue_pair, true /* on */);
13241 i40e_queue_pair_enable_irq(vsi, queue_pair);
13243 i40e_exit_busy_conf(vsi);
13249 * i40e_xdp - implements ndo_bpf for i40e
13251 * @xdp: XDP command
13253 static int i40e_xdp(struct net_device *dev,
13254 struct netdev_bpf *xdp)
13256 struct i40e_netdev_priv *np = netdev_priv(dev);
13257 struct i40e_vsi *vsi = np->vsi;
13259 if (vsi->type != I40E_VSI_MAIN)
13262 switch (xdp->command) {
13263 case XDP_SETUP_PROG:
13264 return i40e_xdp_setup(vsi, xdp->prog, xdp->extack);
13265 case XDP_SETUP_XSK_POOL:
13266 return i40e_xsk_pool_setup(vsi, xdp->xsk.pool,
13267 xdp->xsk.queue_id);
13273 static const struct net_device_ops i40e_netdev_ops = {
13274 .ndo_open = i40e_open,
13275 .ndo_stop = i40e_close,
13276 .ndo_start_xmit = i40e_lan_xmit_frame,
13277 .ndo_get_stats64 = i40e_get_netdev_stats_struct,
13278 .ndo_set_rx_mode = i40e_set_rx_mode,
13279 .ndo_validate_addr = eth_validate_addr,
13280 .ndo_set_mac_address = i40e_set_mac,
13281 .ndo_change_mtu = i40e_change_mtu,
13282 .ndo_do_ioctl = i40e_ioctl,
13283 .ndo_tx_timeout = i40e_tx_timeout,
13284 .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
13285 .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
13286 #ifdef CONFIG_NET_POLL_CONTROLLER
13287 .ndo_poll_controller = i40e_netpoll,
13289 .ndo_setup_tc = __i40e_setup_tc,
13290 .ndo_set_features = i40e_set_features,
13291 .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
13292 .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
13293 .ndo_get_vf_stats = i40e_get_vf_stats,
13294 .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
13295 .ndo_get_vf_config = i40e_ndo_get_vf_config,
13296 .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
13297 .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
13298 .ndo_set_vf_trust = i40e_ndo_set_vf_trust,
13299 .ndo_get_phys_port_id = i40e_get_phys_port_id,
13300 .ndo_fdb_add = i40e_ndo_fdb_add,
13301 .ndo_features_check = i40e_features_check,
13302 .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
13303 .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
13304 .ndo_bpf = i40e_xdp,
13305 .ndo_xdp_xmit = i40e_xdp_xmit,
13306 .ndo_xsk_wakeup = i40e_xsk_wakeup,
13307 .ndo_dfwd_add_station = i40e_fwd_add,
13308 .ndo_dfwd_del_station = i40e_fwd_del,
13312 * i40e_config_netdev - Setup the netdev flags
13313 * @vsi: the VSI being configured
13315 * Returns 0 on success, negative value on failure
13317 static int i40e_config_netdev(struct i40e_vsi *vsi)
13319 struct i40e_pf *pf = vsi->back;
13320 struct i40e_hw *hw = &pf->hw;
13321 struct i40e_netdev_priv *np;
13322 struct net_device *netdev;
13323 u8 broadcast[ETH_ALEN];
13324 u8 mac_addr[ETH_ALEN];
13326 netdev_features_t hw_enc_features;
13327 netdev_features_t hw_features;
13329 etherdev_size = sizeof(struct i40e_netdev_priv);
13330 netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
13334 vsi->netdev = netdev;
13335 np = netdev_priv(netdev);
13338 hw_enc_features = NETIF_F_SG |
13340 NETIF_F_IPV6_CSUM |
13342 NETIF_F_SOFT_FEATURES |
13347 NETIF_F_GSO_GRE_CSUM |
13348 NETIF_F_GSO_PARTIAL |
13349 NETIF_F_GSO_IPXIP4 |
13350 NETIF_F_GSO_IPXIP6 |
13351 NETIF_F_GSO_UDP_TUNNEL |
13352 NETIF_F_GSO_UDP_TUNNEL_CSUM |
13353 NETIF_F_GSO_UDP_L4 |
13359 if (!(pf->hw_features & I40E_HW_OUTER_UDP_CSUM_CAPABLE))
13360 netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
13362 netdev->udp_tunnel_nic_info = &pf->udp_tunnel_nic;
13364 netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
13366 netdev->hw_enc_features |= hw_enc_features;
13368 /* record features VLANs can make use of */
13369 netdev->vlan_features |= hw_enc_features | NETIF_F_TSO_MANGLEID;
13371 /* enable macvlan offloads */
13372 netdev->hw_features |= NETIF_F_HW_L2FW_DOFFLOAD;
13374 hw_features = hw_enc_features |
13375 NETIF_F_HW_VLAN_CTAG_TX |
13376 NETIF_F_HW_VLAN_CTAG_RX;
13378 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
13379 hw_features |= NETIF_F_NTUPLE | NETIF_F_HW_TC;
13381 netdev->hw_features |= hw_features;
13383 netdev->features |= hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
13384 netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
13386 if (vsi->type == I40E_VSI_MAIN) {
13387 SET_NETDEV_DEV(netdev, &pf->pdev->dev);
13388 ether_addr_copy(mac_addr, hw->mac.perm_addr);
13389 /* The following steps are necessary for two reasons. First,
13390 * some older NVM configurations load a default MAC-VLAN
13391 * filter that will accept any tagged packet, and we want to
13392 * replace this with a normal filter. Additionally, it is
13393 * possible our MAC address was provided by the platform using
13394 * Open Firmware or similar.
13396 * Thus, we need to remove the default filter and install one
13397 * specific to the MAC address.
13399 i40e_rm_default_mac_filter(vsi, mac_addr);
13400 spin_lock_bh(&vsi->mac_filter_hash_lock);
13401 i40e_add_mac_filter(vsi, mac_addr);
13402 spin_unlock_bh(&vsi->mac_filter_hash_lock);
13404 /* Relate the VSI_VMDQ name to the VSI_MAIN name. Note that we
13405 * are still limited by IFNAMSIZ, but we're adding 'v%d\0' to
13406 * the end, which is 4 bytes long, so force truncation of the
13407 * original name by IFNAMSIZ - 4
13409 snprintf(netdev->name, IFNAMSIZ, "%.*sv%%d",
13411 pf->vsi[pf->lan_vsi]->netdev->name);
13412 eth_random_addr(mac_addr);
13414 spin_lock_bh(&vsi->mac_filter_hash_lock);
13415 i40e_add_mac_filter(vsi, mac_addr);
13416 spin_unlock_bh(&vsi->mac_filter_hash_lock);
13419 /* Add the broadcast filter so that we initially will receive
13420 * broadcast packets. Note that when a new VLAN is first added the
13421 * driver will convert all filters marked I40E_VLAN_ANY into VLAN
13422 * specific filters as part of transitioning into "vlan" operation.
13423 * When more VLANs are added, the driver will copy each existing MAC
13424 * filter and add it for the new VLAN.
13426 * Broadcast filters are handled specially by
13427 * i40e_sync_filters_subtask, as the driver must to set the broadcast
13428 * promiscuous bit instead of adding this directly as a MAC/VLAN
13429 * filter. The subtask will update the correct broadcast promiscuous
13430 * bits as VLANs become active or inactive.
13432 eth_broadcast_addr(broadcast);
13433 spin_lock_bh(&vsi->mac_filter_hash_lock);
13434 i40e_add_mac_filter(vsi, broadcast);
13435 spin_unlock_bh(&vsi->mac_filter_hash_lock);
13437 ether_addr_copy(netdev->dev_addr, mac_addr);
13438 ether_addr_copy(netdev->perm_addr, mac_addr);
13440 /* i40iw_net_event() reads 16 bytes from neigh->primary_key */
13441 netdev->neigh_priv_len = sizeof(u32) * 4;
13443 netdev->priv_flags |= IFF_UNICAST_FLT;
13444 netdev->priv_flags |= IFF_SUPP_NOFCS;
13445 /* Setup netdev TC information */
13446 i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
13448 netdev->netdev_ops = &i40e_netdev_ops;
13449 netdev->watchdog_timeo = 5 * HZ;
13450 i40e_set_ethtool_ops(netdev);
13452 /* MTU range: 68 - 9706 */
13453 netdev->min_mtu = ETH_MIN_MTU;
13454 netdev->max_mtu = I40E_MAX_RXBUFFER - I40E_PACKET_HDR_PAD;
13460 * i40e_vsi_delete - Delete a VSI from the switch
13461 * @vsi: the VSI being removed
13463 * Returns 0 on success, negative value on failure
13465 static void i40e_vsi_delete(struct i40e_vsi *vsi)
13467 /* remove default VSI is not allowed */
13468 if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
13471 i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
13475 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
13476 * @vsi: the VSI being queried
13478 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
13480 int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
13482 struct i40e_veb *veb;
13483 struct i40e_pf *pf = vsi->back;
13485 /* Uplink is not a bridge so default to VEB */
13486 if (vsi->veb_idx >= I40E_MAX_VEB)
13489 veb = pf->veb[vsi->veb_idx];
13491 dev_info(&pf->pdev->dev,
13492 "There is no veb associated with the bridge\n");
13496 /* Uplink is a bridge in VEPA mode */
13497 if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
13500 /* Uplink is a bridge in VEB mode */
13504 /* VEPA is now default bridge, so return 0 */
13509 * i40e_add_vsi - Add a VSI to the switch
13510 * @vsi: the VSI being configured
13512 * This initializes a VSI context depending on the VSI type to be added and
13513 * passes it down to the add_vsi aq command.
13515 static int i40e_add_vsi(struct i40e_vsi *vsi)
13518 struct i40e_pf *pf = vsi->back;
13519 struct i40e_hw *hw = &pf->hw;
13520 struct i40e_vsi_context ctxt;
13521 struct i40e_mac_filter *f;
13522 struct hlist_node *h;
13525 u8 enabled_tc = 0x1; /* TC0 enabled */
13528 memset(&ctxt, 0, sizeof(ctxt));
13529 switch (vsi->type) {
13530 case I40E_VSI_MAIN:
13531 /* The PF's main VSI is already setup as part of the
13532 * device initialization, so we'll not bother with
13533 * the add_vsi call, but we will retrieve the current
13536 ctxt.seid = pf->main_vsi_seid;
13537 ctxt.pf_num = pf->hw.pf_id;
13539 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
13540 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
13542 dev_info(&pf->pdev->dev,
13543 "couldn't get PF vsi config, err %s aq_err %s\n",
13544 i40e_stat_str(&pf->hw, ret),
13545 i40e_aq_str(&pf->hw,
13546 pf->hw.aq.asq_last_status));
13549 vsi->info = ctxt.info;
13550 vsi->info.valid_sections = 0;
13552 vsi->seid = ctxt.seid;
13553 vsi->id = ctxt.vsi_number;
13555 enabled_tc = i40e_pf_get_tc_map(pf);
13557 /* Source pruning is enabled by default, so the flag is
13558 * negative logic - if it's set, we need to fiddle with
13559 * the VSI to disable source pruning.
13561 if (pf->flags & I40E_FLAG_SOURCE_PRUNING_DISABLED) {
13562 memset(&ctxt, 0, sizeof(ctxt));
13563 ctxt.seid = pf->main_vsi_seid;
13564 ctxt.pf_num = pf->hw.pf_id;
13566 ctxt.info.valid_sections |=
13567 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
13568 ctxt.info.switch_id =
13569 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
13570 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
13572 dev_info(&pf->pdev->dev,
13573 "update vsi failed, err %s aq_err %s\n",
13574 i40e_stat_str(&pf->hw, ret),
13575 i40e_aq_str(&pf->hw,
13576 pf->hw.aq.asq_last_status));
13582 /* MFP mode setup queue map and update VSI */
13583 if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
13584 !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
13585 memset(&ctxt, 0, sizeof(ctxt));
13586 ctxt.seid = pf->main_vsi_seid;
13587 ctxt.pf_num = pf->hw.pf_id;
13589 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
13590 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
13592 dev_info(&pf->pdev->dev,
13593 "update vsi failed, err %s aq_err %s\n",
13594 i40e_stat_str(&pf->hw, ret),
13595 i40e_aq_str(&pf->hw,
13596 pf->hw.aq.asq_last_status));
13600 /* update the local VSI info queue map */
13601 i40e_vsi_update_queue_map(vsi, &ctxt);
13602 vsi->info.valid_sections = 0;
13604 /* Default/Main VSI is only enabled for TC0
13605 * reconfigure it to enable all TCs that are
13606 * available on the port in SFP mode.
13607 * For MFP case the iSCSI PF would use this
13608 * flow to enable LAN+iSCSI TC.
13610 ret = i40e_vsi_config_tc(vsi, enabled_tc);
13612 /* Single TC condition is not fatal,
13613 * message and continue
13615 dev_info(&pf->pdev->dev,
13616 "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
13618 i40e_stat_str(&pf->hw, ret),
13619 i40e_aq_str(&pf->hw,
13620 pf->hw.aq.asq_last_status));
13625 case I40E_VSI_FDIR:
13626 ctxt.pf_num = hw->pf_id;
13628 ctxt.uplink_seid = vsi->uplink_seid;
13629 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
13630 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
13631 if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
13632 (i40e_is_vsi_uplink_mode_veb(vsi))) {
13633 ctxt.info.valid_sections |=
13634 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
13635 ctxt.info.switch_id =
13636 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
13638 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
13641 case I40E_VSI_VMDQ2:
13642 ctxt.pf_num = hw->pf_id;
13644 ctxt.uplink_seid = vsi->uplink_seid;
13645 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
13646 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
13648 /* This VSI is connected to VEB so the switch_id
13649 * should be set to zero by default.
13651 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
13652 ctxt.info.valid_sections |=
13653 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
13654 ctxt.info.switch_id =
13655 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
13658 /* Setup the VSI tx/rx queue map for TC0 only for now */
13659 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
13662 case I40E_VSI_SRIOV:
13663 ctxt.pf_num = hw->pf_id;
13664 ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
13665 ctxt.uplink_seid = vsi->uplink_seid;
13666 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
13667 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
13669 /* This VSI is connected to VEB so the switch_id
13670 * should be set to zero by default.
13672 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
13673 ctxt.info.valid_sections |=
13674 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
13675 ctxt.info.switch_id =
13676 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
13679 if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
13680 ctxt.info.valid_sections |=
13681 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
13682 ctxt.info.queueing_opt_flags |=
13683 (I40E_AQ_VSI_QUE_OPT_TCP_ENA |
13684 I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI);
13687 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
13688 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
13689 if (pf->vf[vsi->vf_id].spoofchk) {
13690 ctxt.info.valid_sections |=
13691 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
13692 ctxt.info.sec_flags |=
13693 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
13694 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
13696 /* Setup the VSI tx/rx queue map for TC0 only for now */
13697 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
13700 case I40E_VSI_IWARP:
13701 /* send down message to iWARP */
13708 if (vsi->type != I40E_VSI_MAIN) {
13709 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
13711 dev_info(&vsi->back->pdev->dev,
13712 "add vsi failed, err %s aq_err %s\n",
13713 i40e_stat_str(&pf->hw, ret),
13714 i40e_aq_str(&pf->hw,
13715 pf->hw.aq.asq_last_status));
13719 vsi->info = ctxt.info;
13720 vsi->info.valid_sections = 0;
13721 vsi->seid = ctxt.seid;
13722 vsi->id = ctxt.vsi_number;
13725 vsi->active_filters = 0;
13726 clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
13727 spin_lock_bh(&vsi->mac_filter_hash_lock);
13728 /* If macvlan filters already exist, force them to get loaded */
13729 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
13730 f->state = I40E_FILTER_NEW;
13733 spin_unlock_bh(&vsi->mac_filter_hash_lock);
13736 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
13737 set_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state);
13740 /* Update VSI BW information */
13741 ret = i40e_vsi_get_bw_info(vsi);
13743 dev_info(&pf->pdev->dev,
13744 "couldn't get vsi bw info, err %s aq_err %s\n",
13745 i40e_stat_str(&pf->hw, ret),
13746 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
13747 /* VSI is already added so not tearing that up */
13756 * i40e_vsi_release - Delete a VSI and free its resources
13757 * @vsi: the VSI being removed
13759 * Returns 0 on success or < 0 on error
13761 int i40e_vsi_release(struct i40e_vsi *vsi)
13763 struct i40e_mac_filter *f;
13764 struct hlist_node *h;
13765 struct i40e_veb *veb = NULL;
13766 struct i40e_pf *pf;
13772 /* release of a VEB-owner or last VSI is not allowed */
13773 if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
13774 dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
13775 vsi->seid, vsi->uplink_seid);
13778 if (vsi == pf->vsi[pf->lan_vsi] &&
13779 !test_bit(__I40E_DOWN, pf->state)) {
13780 dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
13784 uplink_seid = vsi->uplink_seid;
13785 if (vsi->type != I40E_VSI_SRIOV) {
13786 if (vsi->netdev_registered) {
13787 vsi->netdev_registered = false;
13789 /* results in a call to i40e_close() */
13790 unregister_netdev(vsi->netdev);
13793 i40e_vsi_close(vsi);
13795 i40e_vsi_disable_irq(vsi);
13798 spin_lock_bh(&vsi->mac_filter_hash_lock);
13800 /* clear the sync flag on all filters */
13802 __dev_uc_unsync(vsi->netdev, NULL);
13803 __dev_mc_unsync(vsi->netdev, NULL);
13806 /* make sure any remaining filters are marked for deletion */
13807 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
13808 __i40e_del_filter(vsi, f);
13810 spin_unlock_bh(&vsi->mac_filter_hash_lock);
13812 i40e_sync_vsi_filters(vsi);
13814 i40e_vsi_delete(vsi);
13815 i40e_vsi_free_q_vectors(vsi);
13817 free_netdev(vsi->netdev);
13818 vsi->netdev = NULL;
13820 i40e_vsi_clear_rings(vsi);
13821 i40e_vsi_clear(vsi);
13823 /* If this was the last thing on the VEB, except for the
13824 * controlling VSI, remove the VEB, which puts the controlling
13825 * VSI onto the next level down in the switch.
13827 * Well, okay, there's one more exception here: don't remove
13828 * the orphan VEBs yet. We'll wait for an explicit remove request
13829 * from up the network stack.
13831 for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
13833 pf->vsi[i]->uplink_seid == uplink_seid &&
13834 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
13835 n++; /* count the VSIs */
13838 for (i = 0; i < I40E_MAX_VEB; i++) {
13841 if (pf->veb[i]->uplink_seid == uplink_seid)
13842 n++; /* count the VEBs */
13843 if (pf->veb[i]->seid == uplink_seid)
13846 if (n == 0 && veb && veb->uplink_seid != 0)
13847 i40e_veb_release(veb);
13853 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
13854 * @vsi: ptr to the VSI
13856 * This should only be called after i40e_vsi_mem_alloc() which allocates the
13857 * corresponding SW VSI structure and initializes num_queue_pairs for the
13858 * newly allocated VSI.
13860 * Returns 0 on success or negative on failure
13862 static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
13865 struct i40e_pf *pf = vsi->back;
13867 if (vsi->q_vectors[0]) {
13868 dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
13873 if (vsi->base_vector) {
13874 dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
13875 vsi->seid, vsi->base_vector);
13879 ret = i40e_vsi_alloc_q_vectors(vsi);
13881 dev_info(&pf->pdev->dev,
13882 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
13883 vsi->num_q_vectors, vsi->seid, ret);
13884 vsi->num_q_vectors = 0;
13885 goto vector_setup_out;
13888 /* In Legacy mode, we do not have to get any other vector since we
13889 * piggyback on the misc/ICR0 for queue interrupts.
13891 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
13893 if (vsi->num_q_vectors)
13894 vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
13895 vsi->num_q_vectors, vsi->idx);
13896 if (vsi->base_vector < 0) {
13897 dev_info(&pf->pdev->dev,
13898 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
13899 vsi->num_q_vectors, vsi->seid, vsi->base_vector);
13900 i40e_vsi_free_q_vectors(vsi);
13902 goto vector_setup_out;
13910 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
13911 * @vsi: pointer to the vsi.
13913 * This re-allocates a vsi's queue resources.
13915 * Returns pointer to the successfully allocated and configured VSI sw struct
13916 * on success, otherwise returns NULL on failure.
13918 static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
13920 u16 alloc_queue_pairs;
13921 struct i40e_pf *pf;
13930 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
13931 i40e_vsi_clear_rings(vsi);
13933 i40e_vsi_free_arrays(vsi, false);
13934 i40e_set_num_rings_in_vsi(vsi);
13935 ret = i40e_vsi_alloc_arrays(vsi, false);
13939 alloc_queue_pairs = vsi->alloc_queue_pairs *
13940 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
13942 ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
13944 dev_info(&pf->pdev->dev,
13945 "failed to get tracking for %d queues for VSI %d err %d\n",
13946 alloc_queue_pairs, vsi->seid, ret);
13949 vsi->base_queue = ret;
13951 /* Update the FW view of the VSI. Force a reset of TC and queue
13952 * layout configurations.
13954 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
13955 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
13956 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
13957 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
13958 if (vsi->type == I40E_VSI_MAIN)
13959 i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr);
13961 /* assign it some queues */
13962 ret = i40e_alloc_rings(vsi);
13966 /* map all of the rings to the q_vectors */
13967 i40e_vsi_map_rings_to_vectors(vsi);
13971 i40e_vsi_free_q_vectors(vsi);
13972 if (vsi->netdev_registered) {
13973 vsi->netdev_registered = false;
13974 unregister_netdev(vsi->netdev);
13975 free_netdev(vsi->netdev);
13976 vsi->netdev = NULL;
13978 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
13980 i40e_vsi_clear(vsi);
13985 * i40e_vsi_setup - Set up a VSI by a given type
13986 * @pf: board private structure
13988 * @uplink_seid: the switch element to link to
13989 * @param1: usage depends upon VSI type. For VF types, indicates VF id
13991 * This allocates the sw VSI structure and its queue resources, then add a VSI
13992 * to the identified VEB.
13994 * Returns pointer to the successfully allocated and configure VSI sw struct on
13995 * success, otherwise returns NULL on failure.
13997 struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
13998 u16 uplink_seid, u32 param1)
14000 struct i40e_vsi *vsi = NULL;
14001 struct i40e_veb *veb = NULL;
14002 u16 alloc_queue_pairs;
14006 /* The requested uplink_seid must be either
14007 * - the PF's port seid
14008 * no VEB is needed because this is the PF
14009 * or this is a Flow Director special case VSI
14010 * - seid of an existing VEB
14011 * - seid of a VSI that owns an existing VEB
14012 * - seid of a VSI that doesn't own a VEB
14013 * a new VEB is created and the VSI becomes the owner
14014 * - seid of the PF VSI, which is what creates the first VEB
14015 * this is a special case of the previous
14017 * Find which uplink_seid we were given and create a new VEB if needed
14019 for (i = 0; i < I40E_MAX_VEB; i++) {
14020 if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
14026 if (!veb && uplink_seid != pf->mac_seid) {
14028 for (i = 0; i < pf->num_alloc_vsi; i++) {
14029 if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
14035 dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
14040 if (vsi->uplink_seid == pf->mac_seid)
14041 veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
14042 vsi->tc_config.enabled_tc);
14043 else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
14044 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
14045 vsi->tc_config.enabled_tc);
14047 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
14048 dev_info(&vsi->back->pdev->dev,
14049 "New VSI creation error, uplink seid of LAN VSI expected.\n");
14052 /* We come up by default in VEPA mode if SRIOV is not
14053 * already enabled, in which case we can't force VEPA
14056 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
14057 veb->bridge_mode = BRIDGE_MODE_VEPA;
14058 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
14060 i40e_config_bridge_mode(veb);
14062 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
14063 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
14067 dev_info(&pf->pdev->dev, "couldn't add VEB\n");
14071 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
14072 uplink_seid = veb->seid;
14075 /* get vsi sw struct */
14076 v_idx = i40e_vsi_mem_alloc(pf, type);
14079 vsi = pf->vsi[v_idx];
14083 vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
14085 if (type == I40E_VSI_MAIN)
14086 pf->lan_vsi = v_idx;
14087 else if (type == I40E_VSI_SRIOV)
14088 vsi->vf_id = param1;
14089 /* assign it some queues */
14090 alloc_queue_pairs = vsi->alloc_queue_pairs *
14091 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
14093 ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
14095 dev_info(&pf->pdev->dev,
14096 "failed to get tracking for %d queues for VSI %d err=%d\n",
14097 alloc_queue_pairs, vsi->seid, ret);
14100 vsi->base_queue = ret;
14102 /* get a VSI from the hardware */
14103 vsi->uplink_seid = uplink_seid;
14104 ret = i40e_add_vsi(vsi);
14108 switch (vsi->type) {
14109 /* setup the netdev if needed */
14110 case I40E_VSI_MAIN:
14111 case I40E_VSI_VMDQ2:
14112 ret = i40e_config_netdev(vsi);
14115 ret = register_netdev(vsi->netdev);
14118 vsi->netdev_registered = true;
14119 netif_carrier_off(vsi->netdev);
14120 #ifdef CONFIG_I40E_DCB
14121 /* Setup DCB netlink interface */
14122 i40e_dcbnl_setup(vsi);
14123 #endif /* CONFIG_I40E_DCB */
14125 case I40E_VSI_FDIR:
14126 /* set up vectors and rings if needed */
14127 ret = i40e_vsi_setup_vectors(vsi);
14131 ret = i40e_alloc_rings(vsi);
14135 /* map all of the rings to the q_vectors */
14136 i40e_vsi_map_rings_to_vectors(vsi);
14138 i40e_vsi_reset_stats(vsi);
14141 /* no netdev or rings for the other VSI types */
14145 if ((pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) &&
14146 (vsi->type == I40E_VSI_VMDQ2)) {
14147 ret = i40e_vsi_config_rss(vsi);
14152 i40e_vsi_free_q_vectors(vsi);
14154 if (vsi->netdev_registered) {
14155 vsi->netdev_registered = false;
14156 unregister_netdev(vsi->netdev);
14157 free_netdev(vsi->netdev);
14158 vsi->netdev = NULL;
14161 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
14163 i40e_vsi_clear(vsi);
14169 * i40e_veb_get_bw_info - Query VEB BW information
14170 * @veb: the veb to query
14172 * Query the Tx scheduler BW configuration data for given VEB
14174 static int i40e_veb_get_bw_info(struct i40e_veb *veb)
14176 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
14177 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
14178 struct i40e_pf *pf = veb->pf;
14179 struct i40e_hw *hw = &pf->hw;
14184 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
14187 dev_info(&pf->pdev->dev,
14188 "query veb bw config failed, err %s aq_err %s\n",
14189 i40e_stat_str(&pf->hw, ret),
14190 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
14194 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
14197 dev_info(&pf->pdev->dev,
14198 "query veb bw ets config failed, err %s aq_err %s\n",
14199 i40e_stat_str(&pf->hw, ret),
14200 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
14204 veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
14205 veb->bw_max_quanta = ets_data.tc_bw_max;
14206 veb->is_abs_credits = bw_data.absolute_credits_enable;
14207 veb->enabled_tc = ets_data.tc_valid_bits;
14208 tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
14209 (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
14210 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
14211 veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
14212 veb->bw_tc_limit_credits[i] =
14213 le16_to_cpu(bw_data.tc_bw_limits[i]);
14214 veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
14222 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
14223 * @pf: board private structure
14225 * On error: returns error code (negative)
14226 * On success: returns vsi index in PF (positive)
14228 static int i40e_veb_mem_alloc(struct i40e_pf *pf)
14231 struct i40e_veb *veb;
14234 /* Need to protect the allocation of switch elements at the PF level */
14235 mutex_lock(&pf->switch_mutex);
14237 /* VEB list may be fragmented if VEB creation/destruction has
14238 * been happening. We can afford to do a quick scan to look
14239 * for any free slots in the list.
14241 * find next empty veb slot, looping back around if necessary
14244 while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
14246 if (i >= I40E_MAX_VEB) {
14248 goto err_alloc_veb; /* out of VEB slots! */
14251 veb = kzalloc(sizeof(*veb), GFP_KERNEL);
14254 goto err_alloc_veb;
14258 veb->enabled_tc = 1;
14263 mutex_unlock(&pf->switch_mutex);
14268 * i40e_switch_branch_release - Delete a branch of the switch tree
14269 * @branch: where to start deleting
14271 * This uses recursion to find the tips of the branch to be
14272 * removed, deleting until we get back to and can delete this VEB.
14274 static void i40e_switch_branch_release(struct i40e_veb *branch)
14276 struct i40e_pf *pf = branch->pf;
14277 u16 branch_seid = branch->seid;
14278 u16 veb_idx = branch->idx;
14281 /* release any VEBs on this VEB - RECURSION */
14282 for (i = 0; i < I40E_MAX_VEB; i++) {
14285 if (pf->veb[i]->uplink_seid == branch->seid)
14286 i40e_switch_branch_release(pf->veb[i]);
14289 /* Release the VSIs on this VEB, but not the owner VSI.
14291 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
14292 * the VEB itself, so don't use (*branch) after this loop.
14294 for (i = 0; i < pf->num_alloc_vsi; i++) {
14297 if (pf->vsi[i]->uplink_seid == branch_seid &&
14298 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
14299 i40e_vsi_release(pf->vsi[i]);
14303 /* There's one corner case where the VEB might not have been
14304 * removed, so double check it here and remove it if needed.
14305 * This case happens if the veb was created from the debugfs
14306 * commands and no VSIs were added to it.
14308 if (pf->veb[veb_idx])
14309 i40e_veb_release(pf->veb[veb_idx]);
14313 * i40e_veb_clear - remove veb struct
14314 * @veb: the veb to remove
14316 static void i40e_veb_clear(struct i40e_veb *veb)
14322 struct i40e_pf *pf = veb->pf;
14324 mutex_lock(&pf->switch_mutex);
14325 if (pf->veb[veb->idx] == veb)
14326 pf->veb[veb->idx] = NULL;
14327 mutex_unlock(&pf->switch_mutex);
14334 * i40e_veb_release - Delete a VEB and free its resources
14335 * @veb: the VEB being removed
14337 void i40e_veb_release(struct i40e_veb *veb)
14339 struct i40e_vsi *vsi = NULL;
14340 struct i40e_pf *pf;
14345 /* find the remaining VSI and check for extras */
14346 for (i = 0; i < pf->num_alloc_vsi; i++) {
14347 if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
14353 dev_info(&pf->pdev->dev,
14354 "can't remove VEB %d with %d VSIs left\n",
14359 /* move the remaining VSI to uplink veb */
14360 vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
14361 if (veb->uplink_seid) {
14362 vsi->uplink_seid = veb->uplink_seid;
14363 if (veb->uplink_seid == pf->mac_seid)
14364 vsi->veb_idx = I40E_NO_VEB;
14366 vsi->veb_idx = veb->veb_idx;
14369 vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
14370 vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
14373 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
14374 i40e_veb_clear(veb);
14378 * i40e_add_veb - create the VEB in the switch
14379 * @veb: the VEB to be instantiated
14380 * @vsi: the controlling VSI
14382 static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
14384 struct i40e_pf *pf = veb->pf;
14385 bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
14388 ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
14389 veb->enabled_tc, false,
14390 &veb->seid, enable_stats, NULL);
14392 /* get a VEB from the hardware */
14394 dev_info(&pf->pdev->dev,
14395 "couldn't add VEB, err %s aq_err %s\n",
14396 i40e_stat_str(&pf->hw, ret),
14397 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
14401 /* get statistics counter */
14402 ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
14403 &veb->stats_idx, NULL, NULL, NULL);
14405 dev_info(&pf->pdev->dev,
14406 "couldn't get VEB statistics idx, err %s aq_err %s\n",
14407 i40e_stat_str(&pf->hw, ret),
14408 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
14411 ret = i40e_veb_get_bw_info(veb);
14413 dev_info(&pf->pdev->dev,
14414 "couldn't get VEB bw info, err %s aq_err %s\n",
14415 i40e_stat_str(&pf->hw, ret),
14416 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
14417 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
14421 vsi->uplink_seid = veb->seid;
14422 vsi->veb_idx = veb->idx;
14423 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
14429 * i40e_veb_setup - Set up a VEB
14430 * @pf: board private structure
14431 * @flags: VEB setup flags
14432 * @uplink_seid: the switch element to link to
14433 * @vsi_seid: the initial VSI seid
14434 * @enabled_tc: Enabled TC bit-map
14436 * This allocates the sw VEB structure and links it into the switch
14437 * It is possible and legal for this to be a duplicate of an already
14438 * existing VEB. It is also possible for both uplink and vsi seids
14439 * to be zero, in order to create a floating VEB.
14441 * Returns pointer to the successfully allocated VEB sw struct on
14442 * success, otherwise returns NULL on failure.
14444 struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
14445 u16 uplink_seid, u16 vsi_seid,
14448 struct i40e_veb *veb, *uplink_veb = NULL;
14449 int vsi_idx, veb_idx;
14452 /* if one seid is 0, the other must be 0 to create a floating relay */
14453 if ((uplink_seid == 0 || vsi_seid == 0) &&
14454 (uplink_seid + vsi_seid != 0)) {
14455 dev_info(&pf->pdev->dev,
14456 "one, not both seid's are 0: uplink=%d vsi=%d\n",
14457 uplink_seid, vsi_seid);
14461 /* make sure there is such a vsi and uplink */
14462 for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
14463 if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
14465 if (vsi_idx == pf->num_alloc_vsi && vsi_seid != 0) {
14466 dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
14471 if (uplink_seid && uplink_seid != pf->mac_seid) {
14472 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
14473 if (pf->veb[veb_idx] &&
14474 pf->veb[veb_idx]->seid == uplink_seid) {
14475 uplink_veb = pf->veb[veb_idx];
14480 dev_info(&pf->pdev->dev,
14481 "uplink seid %d not found\n", uplink_seid);
14486 /* get veb sw struct */
14487 veb_idx = i40e_veb_mem_alloc(pf);
14490 veb = pf->veb[veb_idx];
14491 veb->flags = flags;
14492 veb->uplink_seid = uplink_seid;
14493 veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
14494 veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
14496 /* create the VEB in the switch */
14497 ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
14500 if (vsi_idx == pf->lan_vsi)
14501 pf->lan_veb = veb->idx;
14506 i40e_veb_clear(veb);
14512 * i40e_setup_pf_switch_element - set PF vars based on switch type
14513 * @pf: board private structure
14514 * @ele: element we are building info from
14515 * @num_reported: total number of elements
14516 * @printconfig: should we print the contents
14518 * helper function to assist in extracting a few useful SEID values.
14520 static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
14521 struct i40e_aqc_switch_config_element_resp *ele,
14522 u16 num_reported, bool printconfig)
14524 u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
14525 u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
14526 u8 element_type = ele->element_type;
14527 u16 seid = le16_to_cpu(ele->seid);
14530 dev_info(&pf->pdev->dev,
14531 "type=%d seid=%d uplink=%d downlink=%d\n",
14532 element_type, seid, uplink_seid, downlink_seid);
14534 switch (element_type) {
14535 case I40E_SWITCH_ELEMENT_TYPE_MAC:
14536 pf->mac_seid = seid;
14538 case I40E_SWITCH_ELEMENT_TYPE_VEB:
14540 if (uplink_seid != pf->mac_seid)
14542 if (pf->lan_veb >= I40E_MAX_VEB) {
14545 /* find existing or else empty VEB */
14546 for (v = 0; v < I40E_MAX_VEB; v++) {
14547 if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
14552 if (pf->lan_veb >= I40E_MAX_VEB) {
14553 v = i40e_veb_mem_alloc(pf);
14559 if (pf->lan_veb >= I40E_MAX_VEB)
14562 pf->veb[pf->lan_veb]->seid = seid;
14563 pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
14564 pf->veb[pf->lan_veb]->pf = pf;
14565 pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
14567 case I40E_SWITCH_ELEMENT_TYPE_VSI:
14568 if (num_reported != 1)
14570 /* This is immediately after a reset so we can assume this is
14573 pf->mac_seid = uplink_seid;
14574 pf->pf_seid = downlink_seid;
14575 pf->main_vsi_seid = seid;
14577 dev_info(&pf->pdev->dev,
14578 "pf_seid=%d main_vsi_seid=%d\n",
14579 pf->pf_seid, pf->main_vsi_seid);
14581 case I40E_SWITCH_ELEMENT_TYPE_PF:
14582 case I40E_SWITCH_ELEMENT_TYPE_VF:
14583 case I40E_SWITCH_ELEMENT_TYPE_EMP:
14584 case I40E_SWITCH_ELEMENT_TYPE_BMC:
14585 case I40E_SWITCH_ELEMENT_TYPE_PE:
14586 case I40E_SWITCH_ELEMENT_TYPE_PA:
14587 /* ignore these for now */
14590 dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
14591 element_type, seid);
14597 * i40e_fetch_switch_configuration - Get switch config from firmware
14598 * @pf: board private structure
14599 * @printconfig: should we print the contents
14601 * Get the current switch configuration from the device and
14602 * extract a few useful SEID values.
14604 int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
14606 struct i40e_aqc_get_switch_config_resp *sw_config;
14612 aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
14616 sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
14618 u16 num_reported, num_total;
14620 ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
14624 dev_info(&pf->pdev->dev,
14625 "get switch config failed err %s aq_err %s\n",
14626 i40e_stat_str(&pf->hw, ret),
14627 i40e_aq_str(&pf->hw,
14628 pf->hw.aq.asq_last_status));
14633 num_reported = le16_to_cpu(sw_config->header.num_reported);
14634 num_total = le16_to_cpu(sw_config->header.num_total);
14637 dev_info(&pf->pdev->dev,
14638 "header: %d reported %d total\n",
14639 num_reported, num_total);
14641 for (i = 0; i < num_reported; i++) {
14642 struct i40e_aqc_switch_config_element_resp *ele =
14643 &sw_config->element[i];
14645 i40e_setup_pf_switch_element(pf, ele, num_reported,
14648 } while (next_seid != 0);
14655 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
14656 * @pf: board private structure
14657 * @reinit: if the Main VSI needs to re-initialized.
14659 * Returns 0 on success, negative value on failure
14661 static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
14666 /* find out what's out there already */
14667 ret = i40e_fetch_switch_configuration(pf, false);
14669 dev_info(&pf->pdev->dev,
14670 "couldn't fetch switch config, err %s aq_err %s\n",
14671 i40e_stat_str(&pf->hw, ret),
14672 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
14675 i40e_pf_reset_stats(pf);
14677 /* set the switch config bit for the whole device to
14678 * support limited promisc or true promisc
14679 * when user requests promisc. The default is limited
14683 if ((pf->hw.pf_id == 0) &&
14684 !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
14685 flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
14686 pf->last_sw_conf_flags = flags;
14689 if (pf->hw.pf_id == 0) {
14692 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
14693 ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, 0,
14695 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
14696 dev_info(&pf->pdev->dev,
14697 "couldn't set switch config bits, err %s aq_err %s\n",
14698 i40e_stat_str(&pf->hw, ret),
14699 i40e_aq_str(&pf->hw,
14700 pf->hw.aq.asq_last_status));
14701 /* not a fatal problem, just keep going */
14703 pf->last_sw_conf_valid_flags = valid_flags;
14706 /* first time setup */
14707 if (pf->lan_vsi == I40E_NO_VSI || reinit) {
14708 struct i40e_vsi *vsi = NULL;
14711 /* Set up the PF VSI associated with the PF's main VSI
14712 * that is already in the HW switch
14714 if (pf->lan_veb < I40E_MAX_VEB && pf->veb[pf->lan_veb])
14715 uplink_seid = pf->veb[pf->lan_veb]->seid;
14717 uplink_seid = pf->mac_seid;
14718 if (pf->lan_vsi == I40E_NO_VSI)
14719 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
14721 vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
14723 dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
14724 i40e_cloud_filter_exit(pf);
14725 i40e_fdir_teardown(pf);
14729 /* force a reset of TC and queue layout configurations */
14730 u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
14732 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
14733 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
14734 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
14736 i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
14738 i40e_fdir_sb_setup(pf);
14740 /* Setup static PF queue filter control settings */
14741 ret = i40e_setup_pf_filter_control(pf);
14743 dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
14745 /* Failure here should not stop continuing other steps */
14748 /* enable RSS in the HW, even for only one queue, as the stack can use
14751 if ((pf->flags & I40E_FLAG_RSS_ENABLED))
14752 i40e_pf_config_rss(pf);
14754 /* fill in link information and enable LSE reporting */
14755 i40e_link_event(pf);
14757 /* Initialize user-specific link properties */
14758 pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
14759 I40E_AQ_AN_COMPLETED) ? true : false);
14763 /* repopulate tunnel port filters */
14764 udp_tunnel_nic_reset_ntf(pf->vsi[pf->lan_vsi]->netdev);
14770 * i40e_determine_queue_usage - Work out queue distribution
14771 * @pf: board private structure
14773 static void i40e_determine_queue_usage(struct i40e_pf *pf)
14778 pf->num_lan_qps = 0;
14780 /* Find the max queues to be put into basic use. We'll always be
14781 * using TC0, whether or not DCB is running, and TC0 will get the
14784 queues_left = pf->hw.func_caps.num_tx_qp;
14786 if ((queues_left == 1) ||
14787 !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
14788 /* one qp for PF, no queues for anything else */
14790 pf->alloc_rss_size = pf->num_lan_qps = 1;
14792 /* make sure all the fancies are disabled */
14793 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
14794 I40E_FLAG_IWARP_ENABLED |
14795 I40E_FLAG_FD_SB_ENABLED |
14796 I40E_FLAG_FD_ATR_ENABLED |
14797 I40E_FLAG_DCB_CAPABLE |
14798 I40E_FLAG_DCB_ENABLED |
14799 I40E_FLAG_SRIOV_ENABLED |
14800 I40E_FLAG_VMDQ_ENABLED);
14801 pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
14802 } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
14803 I40E_FLAG_FD_SB_ENABLED |
14804 I40E_FLAG_FD_ATR_ENABLED |
14805 I40E_FLAG_DCB_CAPABLE))) {
14806 /* one qp for PF */
14807 pf->alloc_rss_size = pf->num_lan_qps = 1;
14808 queues_left -= pf->num_lan_qps;
14810 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
14811 I40E_FLAG_IWARP_ENABLED |
14812 I40E_FLAG_FD_SB_ENABLED |
14813 I40E_FLAG_FD_ATR_ENABLED |
14814 I40E_FLAG_DCB_ENABLED |
14815 I40E_FLAG_VMDQ_ENABLED);
14816 pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
14818 /* Not enough queues for all TCs */
14819 if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
14820 (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
14821 pf->flags &= ~(I40E_FLAG_DCB_CAPABLE |
14822 I40E_FLAG_DCB_ENABLED);
14823 dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
14826 /* limit lan qps to the smaller of qps, cpus or msix */
14827 q_max = max_t(int, pf->rss_size_max, num_online_cpus());
14828 q_max = min_t(int, q_max, pf->hw.func_caps.num_tx_qp);
14829 q_max = min_t(int, q_max, pf->hw.func_caps.num_msix_vectors);
14830 pf->num_lan_qps = q_max;
14832 queues_left -= pf->num_lan_qps;
14835 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
14836 if (queues_left > 1) {
14837 queues_left -= 1; /* save 1 queue for FD */
14839 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
14840 pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
14841 dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
14845 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
14846 pf->num_vf_qps && pf->num_req_vfs && queues_left) {
14847 pf->num_req_vfs = min_t(int, pf->num_req_vfs,
14848 (queues_left / pf->num_vf_qps));
14849 queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
14852 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
14853 pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
14854 pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
14855 (queues_left / pf->num_vmdq_qps));
14856 queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
14859 pf->queues_left = queues_left;
14860 dev_dbg(&pf->pdev->dev,
14861 "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
14862 pf->hw.func_caps.num_tx_qp,
14863 !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
14864 pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
14865 pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
14870 * i40e_setup_pf_filter_control - Setup PF static filter control
14871 * @pf: PF to be setup
14873 * i40e_setup_pf_filter_control sets up a PF's initial filter control
14874 * settings. If PE/FCoE are enabled then it will also set the per PF
14875 * based filter sizes required for them. It also enables Flow director,
14876 * ethertype and macvlan type filter settings for the pf.
14878 * Returns 0 on success, negative on failure
14880 static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
14882 struct i40e_filter_control_settings *settings = &pf->filter_settings;
14884 settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
14886 /* Flow Director is enabled */
14887 if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
14888 settings->enable_fdir = true;
14890 /* Ethtype and MACVLAN filters enabled for PF */
14891 settings->enable_ethtype = true;
14892 settings->enable_macvlan = true;
14894 if (i40e_set_filter_control(&pf->hw, settings))
14900 #define INFO_STRING_LEN 255
14901 #define REMAIN(__x) (INFO_STRING_LEN - (__x))
14902 static void i40e_print_features(struct i40e_pf *pf)
14904 struct i40e_hw *hw = &pf->hw;
14908 buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
14912 i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
14913 #ifdef CONFIG_PCI_IOV
14914 i += scnprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
14916 i += scnprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d",
14917 pf->hw.func_caps.num_vsis,
14918 pf->vsi[pf->lan_vsi]->num_queue_pairs);
14919 if (pf->flags & I40E_FLAG_RSS_ENABLED)
14920 i += scnprintf(&buf[i], REMAIN(i), " RSS");
14921 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
14922 i += scnprintf(&buf[i], REMAIN(i), " FD_ATR");
14923 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
14924 i += scnprintf(&buf[i], REMAIN(i), " FD_SB");
14925 i += scnprintf(&buf[i], REMAIN(i), " NTUPLE");
14927 if (pf->flags & I40E_FLAG_DCB_CAPABLE)
14928 i += scnprintf(&buf[i], REMAIN(i), " DCB");
14929 i += scnprintf(&buf[i], REMAIN(i), " VxLAN");
14930 i += scnprintf(&buf[i], REMAIN(i), " Geneve");
14931 if (pf->flags & I40E_FLAG_PTP)
14932 i += scnprintf(&buf[i], REMAIN(i), " PTP");
14933 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
14934 i += scnprintf(&buf[i], REMAIN(i), " VEB");
14936 i += scnprintf(&buf[i], REMAIN(i), " VEPA");
14938 dev_info(&pf->pdev->dev, "%s\n", buf);
14940 WARN_ON(i > INFO_STRING_LEN);
14944 * i40e_get_platform_mac_addr - get platform-specific MAC address
14945 * @pdev: PCI device information struct
14946 * @pf: board private structure
14948 * Look up the MAC address for the device. First we'll try
14949 * eth_platform_get_mac_address, which will check Open Firmware, or arch
14950 * specific fallback. Otherwise, we'll default to the stored value in
14953 static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
14955 if (eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
14956 i40e_get_mac_addr(&pf->hw, pf->hw.mac.addr);
14960 * i40e_set_fec_in_flags - helper function for setting FEC options in flags
14961 * @fec_cfg: FEC option to set in flags
14962 * @flags: ptr to flags in which we set FEC option
14964 void i40e_set_fec_in_flags(u8 fec_cfg, u32 *flags)
14966 if (fec_cfg & I40E_AQ_SET_FEC_AUTO)
14967 *flags |= I40E_FLAG_RS_FEC | I40E_FLAG_BASE_R_FEC;
14968 if ((fec_cfg & I40E_AQ_SET_FEC_REQUEST_RS) ||
14969 (fec_cfg & I40E_AQ_SET_FEC_ABILITY_RS)) {
14970 *flags |= I40E_FLAG_RS_FEC;
14971 *flags &= ~I40E_FLAG_BASE_R_FEC;
14973 if ((fec_cfg & I40E_AQ_SET_FEC_REQUEST_KR) ||
14974 (fec_cfg & I40E_AQ_SET_FEC_ABILITY_KR)) {
14975 *flags |= I40E_FLAG_BASE_R_FEC;
14976 *flags &= ~I40E_FLAG_RS_FEC;
14979 *flags &= ~(I40E_FLAG_RS_FEC | I40E_FLAG_BASE_R_FEC);
14983 * i40e_check_recovery_mode - check if we are running transition firmware
14984 * @pf: board private structure
14986 * Check registers indicating the firmware runs in recovery mode. Sets the
14987 * appropriate driver state.
14989 * Returns true if the recovery mode was detected, false otherwise
14991 static bool i40e_check_recovery_mode(struct i40e_pf *pf)
14993 u32 val = rd32(&pf->hw, I40E_GL_FWSTS);
14995 if (val & I40E_GL_FWSTS_FWS1B_MASK) {
14996 dev_crit(&pf->pdev->dev, "Firmware recovery mode detected. Limiting functionality.\n");
14997 dev_crit(&pf->pdev->dev, "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for details on firmware recovery mode.\n");
14998 set_bit(__I40E_RECOVERY_MODE, pf->state);
15002 if (test_bit(__I40E_RECOVERY_MODE, pf->state))
15003 dev_info(&pf->pdev->dev, "Please do Power-On Reset to initialize adapter in normal mode with full functionality.\n");
15009 * i40e_pf_loop_reset - perform reset in a loop.
15010 * @pf: board private structure
15012 * This function is useful when a NIC is about to enter recovery mode.
15013 * When a NIC's internal data structures are corrupted the NIC's
15014 * firmware is going to enter recovery mode.
15015 * Right after a POR it takes about 7 minutes for firmware to enter
15016 * recovery mode. Until that time a NIC is in some kind of intermediate
15017 * state. After that time period the NIC almost surely enters
15018 * recovery mode. The only way for a driver to detect intermediate
15019 * state is to issue a series of pf-resets and check a return value.
15020 * If a PF reset returns success then the firmware could be in recovery
15021 * mode so the caller of this code needs to check for recovery mode
15022 * if this function returns success. There is a little chance that
15023 * firmware will hang in intermediate state forever.
15024 * Since waiting 7 minutes is quite a lot of time this function waits
15025 * 10 seconds and then gives up by returning an error.
15027 * Return 0 on success, negative on failure.
15029 static i40e_status i40e_pf_loop_reset(struct i40e_pf *pf)
15031 /* wait max 10 seconds for PF reset to succeed */
15032 const unsigned long time_end = jiffies + 10 * HZ;
15034 struct i40e_hw *hw = &pf->hw;
15037 ret = i40e_pf_reset(hw);
15038 while (ret != I40E_SUCCESS && time_before(jiffies, time_end)) {
15039 usleep_range(10000, 20000);
15040 ret = i40e_pf_reset(hw);
15043 if (ret == I40E_SUCCESS)
15046 dev_info(&pf->pdev->dev, "PF reset failed: %d\n", ret);
15052 * i40e_check_fw_empr - check if FW issued unexpected EMP Reset
15053 * @pf: board private structure
15055 * Check FW registers to determine if FW issued unexpected EMP Reset.
15056 * Every time when unexpected EMP Reset occurs the FW increments
15057 * a counter of unexpected EMP Resets. When the counter reaches 10
15058 * the FW should enter the Recovery mode
15060 * Returns true if FW issued unexpected EMP Reset
15062 static bool i40e_check_fw_empr(struct i40e_pf *pf)
15064 const u32 fw_sts = rd32(&pf->hw, I40E_GL_FWSTS) &
15065 I40E_GL_FWSTS_FWS1B_MASK;
15066 return (fw_sts > I40E_GL_FWSTS_FWS1B_EMPR_0) &&
15067 (fw_sts <= I40E_GL_FWSTS_FWS1B_EMPR_10);
15071 * i40e_handle_resets - handle EMP resets and PF resets
15072 * @pf: board private structure
15074 * Handle both EMP resets and PF resets and conclude whether there are
15075 * any issues regarding these resets. If there are any issues then
15076 * generate log entry.
15078 * Return 0 if NIC is healthy or negative value when there are issues
15081 static i40e_status i40e_handle_resets(struct i40e_pf *pf)
15083 const i40e_status pfr = i40e_pf_loop_reset(pf);
15084 const bool is_empr = i40e_check_fw_empr(pf);
15086 if (is_empr || pfr != I40E_SUCCESS)
15087 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");
15089 return is_empr ? I40E_ERR_RESET_FAILED : pfr;
15093 * i40e_init_recovery_mode - initialize subsystems needed in recovery mode
15094 * @pf: board private structure
15095 * @hw: ptr to the hardware info
15097 * This function does a minimal setup of all subsystems needed for running
15100 * Returns 0 on success, negative on failure
15102 static int i40e_init_recovery_mode(struct i40e_pf *pf, struct i40e_hw *hw)
15104 struct i40e_vsi *vsi;
15108 pci_save_state(pf->pdev);
15110 /* set up periodic task facility */
15111 timer_setup(&pf->service_timer, i40e_service_timer, 0);
15112 pf->service_timer_period = HZ;
15114 INIT_WORK(&pf->service_task, i40e_service_task);
15115 clear_bit(__I40E_SERVICE_SCHED, pf->state);
15117 err = i40e_init_interrupt_scheme(pf);
15119 goto err_switch_setup;
15121 /* The number of VSIs reported by the FW is the minimum guaranteed
15122 * to us; HW supports far more and we share the remaining pool with
15123 * the other PFs. We allocate space for more than the guarantee with
15124 * the understanding that we might not get them all later.
15126 if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
15127 pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
15129 pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
15131 /* Set up the vsi struct and our local tracking of the MAIN PF vsi. */
15132 pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
15136 goto err_switch_setup;
15139 /* We allocate one VSI which is needed as absolute minimum
15140 * in order to register the netdev
15142 v_idx = i40e_vsi_mem_alloc(pf, I40E_VSI_MAIN);
15144 goto err_switch_setup;
15145 pf->lan_vsi = v_idx;
15146 vsi = pf->vsi[v_idx];
15148 goto err_switch_setup;
15149 vsi->alloc_queue_pairs = 1;
15150 err = i40e_config_netdev(vsi);
15152 goto err_switch_setup;
15153 err = register_netdev(vsi->netdev);
15155 goto err_switch_setup;
15156 vsi->netdev_registered = true;
15157 i40e_dbg_pf_init(pf);
15159 err = i40e_setup_misc_vector_for_recovery_mode(pf);
15161 goto err_switch_setup;
15163 /* tell the firmware that we're starting */
15164 i40e_send_version(pf);
15166 /* since everything's happy, start the service_task timer */
15167 mod_timer(&pf->service_timer,
15168 round_jiffies(jiffies + pf->service_timer_period));
15173 i40e_reset_interrupt_capability(pf);
15174 del_timer_sync(&pf->service_timer);
15175 i40e_shutdown_adminq(hw);
15176 iounmap(hw->hw_addr);
15177 pci_disable_pcie_error_reporting(pf->pdev);
15178 pci_release_mem_regions(pf->pdev);
15179 pci_disable_device(pf->pdev);
15186 * i40e_probe - Device initialization routine
15187 * @pdev: PCI device information struct
15188 * @ent: entry in i40e_pci_tbl
15190 * i40e_probe initializes a PF identified by a pci_dev structure.
15191 * The OS initialization, configuring of the PF private structure,
15192 * and a hardware reset occur.
15194 * Returns 0 on success, negative on failure
15196 static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
15198 struct i40e_aq_get_phy_abilities_resp abilities;
15199 #ifdef CONFIG_I40E_DCB
15200 enum i40e_get_fw_lldp_status_resp lldp_status;
15201 i40e_status status;
15202 #endif /* CONFIG_I40E_DCB */
15203 struct i40e_pf *pf;
15204 struct i40e_hw *hw;
15205 static u16 pfs_found;
15212 err = pci_enable_device_mem(pdev);
15216 /* set up for high or low dma */
15217 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
15219 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
15221 dev_err(&pdev->dev,
15222 "DMA configuration failed: 0x%x\n", err);
15227 /* set up pci connections */
15228 err = pci_request_mem_regions(pdev, i40e_driver_name);
15230 dev_info(&pdev->dev,
15231 "pci_request_selected_regions failed %d\n", err);
15235 pci_enable_pcie_error_reporting(pdev);
15236 pci_set_master(pdev);
15238 /* Now that we have a PCI connection, we need to do the
15239 * low level device setup. This is primarily setting up
15240 * the Admin Queue structures and then querying for the
15241 * device's current profile information.
15243 pf = kzalloc(sizeof(*pf), GFP_KERNEL);
15250 set_bit(__I40E_DOWN, pf->state);
15255 pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
15256 I40E_MAX_CSR_SPACE);
15257 /* We believe that the highest register to read is
15258 * I40E_GLGEN_STAT_CLEAR, so we check if the BAR size
15259 * is not less than that before mapping to prevent a
15262 if (pf->ioremap_len < I40E_GLGEN_STAT_CLEAR) {
15263 dev_err(&pdev->dev, "Cannot map registers, bar size 0x%X too small, aborting\n",
15268 hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
15269 if (!hw->hw_addr) {
15271 dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
15272 (unsigned int)pci_resource_start(pdev, 0),
15273 pf->ioremap_len, err);
15276 hw->vendor_id = pdev->vendor;
15277 hw->device_id = pdev->device;
15278 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
15279 hw->subsystem_vendor_id = pdev->subsystem_vendor;
15280 hw->subsystem_device_id = pdev->subsystem_device;
15281 hw->bus.device = PCI_SLOT(pdev->devfn);
15282 hw->bus.func = PCI_FUNC(pdev->devfn);
15283 hw->bus.bus_id = pdev->bus->number;
15284 pf->instance = pfs_found;
15286 /* Select something other than the 802.1ad ethertype for the
15287 * switch to use internally and drop on ingress.
15289 hw->switch_tag = 0xffff;
15290 hw->first_tag = ETH_P_8021AD;
15291 hw->second_tag = ETH_P_8021Q;
15293 INIT_LIST_HEAD(&pf->l3_flex_pit_list);
15294 INIT_LIST_HEAD(&pf->l4_flex_pit_list);
15295 INIT_LIST_HEAD(&pf->ddp_old_prof);
15297 /* set up the locks for the AQ, do this only once in probe
15298 * and destroy them only once in remove
15300 mutex_init(&hw->aq.asq_mutex);
15301 mutex_init(&hw->aq.arq_mutex);
15303 pf->msg_enable = netif_msg_init(debug,
15308 pf->hw.debug_mask = debug;
15310 /* do a special CORER for clearing PXE mode once at init */
15311 if (hw->revision_id == 0 &&
15312 (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
15313 wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
15318 i40e_clear_pxe_mode(hw);
15321 /* Reset here to make sure all is clean and to define PF 'n' */
15324 err = i40e_set_mac_type(hw);
15326 dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
15331 err = i40e_handle_resets(pf);
15335 i40e_check_recovery_mode(pf);
15337 hw->aq.num_arq_entries = I40E_AQ_LEN;
15338 hw->aq.num_asq_entries = I40E_AQ_LEN;
15339 hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
15340 hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
15341 pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
15343 snprintf(pf->int_name, sizeof(pf->int_name) - 1,
15345 dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
15347 err = i40e_init_shared_code(hw);
15349 dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
15354 /* set up a default setting for link flow control */
15355 pf->hw.fc.requested_mode = I40E_FC_NONE;
15357 err = i40e_init_adminq(hw);
15359 if (err == I40E_ERR_FIRMWARE_API_VERSION)
15360 dev_info(&pdev->dev,
15361 "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",
15362 hw->aq.api_maj_ver,
15363 hw->aq.api_min_ver,
15364 I40E_FW_API_VERSION_MAJOR,
15365 I40E_FW_MINOR_VERSION(hw));
15367 dev_info(&pdev->dev,
15368 "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
15372 i40e_get_oem_version(hw);
15374 /* provide nvm, fw, api versions, vendor:device id, subsys vendor:device id */
15375 dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s [%04x:%04x] [%04x:%04x]\n",
15376 hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
15377 hw->aq.api_maj_ver, hw->aq.api_min_ver,
15378 i40e_nvm_version_str(hw), hw->vendor_id, hw->device_id,
15379 hw->subsystem_vendor_id, hw->subsystem_device_id);
15381 if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
15382 hw->aq.api_min_ver > I40E_FW_MINOR_VERSION(hw))
15383 dev_info(&pdev->dev,
15384 "The driver for the device detected a newer version of the NVM image v%u.%u than expected v%u.%u. Please install the most recent version of the network driver.\n",
15385 hw->aq.api_maj_ver,
15386 hw->aq.api_min_ver,
15387 I40E_FW_API_VERSION_MAJOR,
15388 I40E_FW_MINOR_VERSION(hw));
15389 else if (hw->aq.api_maj_ver == 1 && hw->aq.api_min_ver < 4)
15390 dev_info(&pdev->dev,
15391 "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",
15392 hw->aq.api_maj_ver,
15393 hw->aq.api_min_ver,
15394 I40E_FW_API_VERSION_MAJOR,
15395 I40E_FW_MINOR_VERSION(hw));
15397 i40e_verify_eeprom(pf);
15399 /* Rev 0 hardware was never productized */
15400 if (hw->revision_id < 1)
15401 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");
15403 i40e_clear_pxe_mode(hw);
15405 err = i40e_get_capabilities(pf, i40e_aqc_opc_list_func_capabilities);
15407 goto err_adminq_setup;
15409 err = i40e_sw_init(pf);
15411 dev_info(&pdev->dev, "sw_init failed: %d\n", err);
15415 if (test_bit(__I40E_RECOVERY_MODE, pf->state))
15416 return i40e_init_recovery_mode(pf, hw);
15418 err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
15419 hw->func_caps.num_rx_qp, 0, 0);
15421 dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
15422 goto err_init_lan_hmc;
15425 err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
15427 dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
15429 goto err_configure_lan_hmc;
15432 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
15433 * Ignore error return codes because if it was already disabled via
15434 * hardware settings this will fail
15436 if (pf->hw_features & I40E_HW_STOP_FW_LLDP) {
15437 dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
15438 i40e_aq_stop_lldp(hw, true, false, NULL);
15441 /* allow a platform config to override the HW addr */
15442 i40e_get_platform_mac_addr(pdev, pf);
15444 if (!is_valid_ether_addr(hw->mac.addr)) {
15445 dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
15449 dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
15450 ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
15451 i40e_get_port_mac_addr(hw, hw->mac.port_addr);
15452 if (is_valid_ether_addr(hw->mac.port_addr))
15453 pf->hw_features |= I40E_HW_PORT_ID_VALID;
15455 pci_set_drvdata(pdev, pf);
15456 pci_save_state(pdev);
15458 #ifdef CONFIG_I40E_DCB
15459 status = i40e_get_fw_lldp_status(&pf->hw, &lldp_status);
15461 lldp_status == I40E_GET_FW_LLDP_STATUS_ENABLED) ?
15462 (pf->flags &= ~I40E_FLAG_DISABLE_FW_LLDP) :
15463 (pf->flags |= I40E_FLAG_DISABLE_FW_LLDP);
15464 dev_info(&pdev->dev,
15465 (pf->flags & I40E_FLAG_DISABLE_FW_LLDP) ?
15466 "FW LLDP is disabled\n" :
15467 "FW LLDP is enabled\n");
15469 /* Enable FW to write default DCB config on link-up */
15470 i40e_aq_set_dcb_parameters(hw, true, NULL);
15472 err = i40e_init_pf_dcb(pf);
15474 dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
15475 pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED);
15476 /* Continue without DCB enabled */
15478 #endif /* CONFIG_I40E_DCB */
15480 /* set up periodic task facility */
15481 timer_setup(&pf->service_timer, i40e_service_timer, 0);
15482 pf->service_timer_period = HZ;
15484 INIT_WORK(&pf->service_task, i40e_service_task);
15485 clear_bit(__I40E_SERVICE_SCHED, pf->state);
15487 /* NVM bit on means WoL disabled for the port */
15488 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
15489 if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
15490 pf->wol_en = false;
15493 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
15495 /* set up the main switch operations */
15496 i40e_determine_queue_usage(pf);
15497 err = i40e_init_interrupt_scheme(pf);
15499 goto err_switch_setup;
15501 pf->udp_tunnel_nic.set_port = i40e_udp_tunnel_set_port;
15502 pf->udp_tunnel_nic.unset_port = i40e_udp_tunnel_unset_port;
15503 pf->udp_tunnel_nic.flags = UDP_TUNNEL_NIC_INFO_MAY_SLEEP;
15504 pf->udp_tunnel_nic.shared = &pf->udp_tunnel_shared;
15505 pf->udp_tunnel_nic.tables[0].n_entries = I40E_MAX_PF_UDP_OFFLOAD_PORTS;
15506 pf->udp_tunnel_nic.tables[0].tunnel_types = UDP_TUNNEL_TYPE_VXLAN |
15507 UDP_TUNNEL_TYPE_GENEVE;
15509 /* The number of VSIs reported by the FW is the minimum guaranteed
15510 * to us; HW supports far more and we share the remaining pool with
15511 * the other PFs. We allocate space for more than the guarantee with
15512 * the understanding that we might not get them all later.
15514 if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
15515 pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
15517 pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
15518 if (pf->num_alloc_vsi > UDP_TUNNEL_NIC_MAX_SHARING_DEVICES) {
15519 dev_warn(&pf->pdev->dev,
15520 "limiting the VSI count due to UDP tunnel limitation %d > %d\n",
15521 pf->num_alloc_vsi, UDP_TUNNEL_NIC_MAX_SHARING_DEVICES);
15522 pf->num_alloc_vsi = UDP_TUNNEL_NIC_MAX_SHARING_DEVICES;
15525 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
15526 pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
15530 goto err_switch_setup;
15533 #ifdef CONFIG_PCI_IOV
15534 /* prep for VF support */
15535 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
15536 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
15537 !test_bit(__I40E_BAD_EEPROM, pf->state)) {
15538 if (pci_num_vf(pdev))
15539 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
15542 err = i40e_setup_pf_switch(pf, false);
15544 dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
15547 INIT_LIST_HEAD(&pf->vsi[pf->lan_vsi]->ch_list);
15549 /* if FDIR VSI was set up, start it now */
15550 for (i = 0; i < pf->num_alloc_vsi; i++) {
15551 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
15552 i40e_vsi_open(pf->vsi[i]);
15557 /* The driver only wants link up/down and module qualification
15558 * reports from firmware. Note the negative logic.
15560 err = i40e_aq_set_phy_int_mask(&pf->hw,
15561 ~(I40E_AQ_EVENT_LINK_UPDOWN |
15562 I40E_AQ_EVENT_MEDIA_NA |
15563 I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
15565 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
15566 i40e_stat_str(&pf->hw, err),
15567 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
15569 /* Reconfigure hardware for allowing smaller MSS in the case
15570 * of TSO, so that we avoid the MDD being fired and causing
15571 * a reset in the case of small MSS+TSO.
15573 val = rd32(hw, I40E_REG_MSS);
15574 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
15575 val &= ~I40E_REG_MSS_MIN_MASK;
15576 val |= I40E_64BYTE_MSS;
15577 wr32(hw, I40E_REG_MSS, val);
15580 if (pf->hw_features & I40E_HW_RESTART_AUTONEG) {
15582 err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
15584 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
15585 i40e_stat_str(&pf->hw, err),
15586 i40e_aq_str(&pf->hw,
15587 pf->hw.aq.asq_last_status));
15589 /* The main driver is (mostly) up and happy. We need to set this state
15590 * before setting up the misc vector or we get a race and the vector
15591 * ends up disabled forever.
15593 clear_bit(__I40E_DOWN, pf->state);
15595 /* In case of MSIX we are going to setup the misc vector right here
15596 * to handle admin queue events etc. In case of legacy and MSI
15597 * the misc functionality and queue processing is combined in
15598 * the same vector and that gets setup at open.
15600 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
15601 err = i40e_setup_misc_vector(pf);
15603 dev_info(&pdev->dev,
15604 "setup of misc vector failed: %d\n", err);
15605 i40e_cloud_filter_exit(pf);
15606 i40e_fdir_teardown(pf);
15611 #ifdef CONFIG_PCI_IOV
15612 /* prep for VF support */
15613 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
15614 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
15615 !test_bit(__I40E_BAD_EEPROM, pf->state)) {
15616 /* disable link interrupts for VFs */
15617 val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
15618 val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
15619 wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
15622 if (pci_num_vf(pdev)) {
15623 dev_info(&pdev->dev,
15624 "Active VFs found, allocating resources.\n");
15625 err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
15627 dev_info(&pdev->dev,
15628 "Error %d allocating resources for existing VFs\n",
15632 #endif /* CONFIG_PCI_IOV */
15634 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
15635 pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
15636 pf->num_iwarp_msix,
15637 I40E_IWARP_IRQ_PILE_ID);
15638 if (pf->iwarp_base_vector < 0) {
15639 dev_info(&pdev->dev,
15640 "failed to get tracking for %d vectors for IWARP err=%d\n",
15641 pf->num_iwarp_msix, pf->iwarp_base_vector);
15642 pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
15646 i40e_dbg_pf_init(pf);
15648 /* tell the firmware that we're starting */
15649 i40e_send_version(pf);
15651 /* since everything's happy, start the service_task timer */
15652 mod_timer(&pf->service_timer,
15653 round_jiffies(jiffies + pf->service_timer_period));
15655 /* add this PF to client device list and launch a client service task */
15656 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
15657 err = i40e_lan_add_device(pf);
15659 dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
15663 #define PCI_SPEED_SIZE 8
15664 #define PCI_WIDTH_SIZE 8
15665 /* Devices on the IOSF bus do not have this information
15666 * and will report PCI Gen 1 x 1 by default so don't bother
15669 if (!(pf->hw_features & I40E_HW_NO_PCI_LINK_CHECK)) {
15670 char speed[PCI_SPEED_SIZE] = "Unknown";
15671 char width[PCI_WIDTH_SIZE] = "Unknown";
15673 /* Get the negotiated link width and speed from PCI config
15676 pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
15679 i40e_set_pci_config_data(hw, link_status);
15681 switch (hw->bus.speed) {
15682 case i40e_bus_speed_8000:
15683 strlcpy(speed, "8.0", PCI_SPEED_SIZE); break;
15684 case i40e_bus_speed_5000:
15685 strlcpy(speed, "5.0", PCI_SPEED_SIZE); break;
15686 case i40e_bus_speed_2500:
15687 strlcpy(speed, "2.5", PCI_SPEED_SIZE); break;
15691 switch (hw->bus.width) {
15692 case i40e_bus_width_pcie_x8:
15693 strlcpy(width, "8", PCI_WIDTH_SIZE); break;
15694 case i40e_bus_width_pcie_x4:
15695 strlcpy(width, "4", PCI_WIDTH_SIZE); break;
15696 case i40e_bus_width_pcie_x2:
15697 strlcpy(width, "2", PCI_WIDTH_SIZE); break;
15698 case i40e_bus_width_pcie_x1:
15699 strlcpy(width, "1", PCI_WIDTH_SIZE); break;
15704 dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
15707 if (hw->bus.width < i40e_bus_width_pcie_x8 ||
15708 hw->bus.speed < i40e_bus_speed_8000) {
15709 dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
15710 dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
15714 /* get the requested speeds from the fw */
15715 err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
15717 dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
15718 i40e_stat_str(&pf->hw, err),
15719 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
15720 pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
15722 /* set the FEC config due to the board capabilities */
15723 i40e_set_fec_in_flags(abilities.fec_cfg_curr_mod_ext_info, &pf->flags);
15725 /* get the supported phy types from the fw */
15726 err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
15728 dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
15729 i40e_stat_str(&pf->hw, err),
15730 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
15732 /* make sure the MFS hasn't been set lower than the default */
15733 #define MAX_FRAME_SIZE_DEFAULT 0x2600
15734 val = (rd32(&pf->hw, I40E_PRTGL_SAH) &
15735 I40E_PRTGL_SAH_MFS_MASK) >> I40E_PRTGL_SAH_MFS_SHIFT;
15736 if (val < MAX_FRAME_SIZE_DEFAULT)
15737 dev_warn(&pdev->dev, "MFS for port %x has been set below the default: %x\n",
15740 /* Add a filter to drop all Flow control frames from any VSI from being
15741 * transmitted. By doing so we stop a malicious VF from sending out
15742 * PAUSE or PFC frames and potentially controlling traffic for other
15744 * The FW can still send Flow control frames if enabled.
15746 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
15747 pf->main_vsi_seid);
15748 #ifdef CONFIG_I40E_DCB
15749 if (pf->flags & I40E_FLAG_DISABLE_FW_LLDP)
15750 i40e_set_lldp_forwarding(pf, true);
15751 #endif /* CONFIG_I40E_DCB */
15753 if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) ||
15754 (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4))
15755 pf->hw_features |= I40E_HW_PHY_CONTROLS_LEDS;
15756 if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722)
15757 pf->hw_features |= I40E_HW_HAVE_CRT_RETIMER;
15758 /* print a string summarizing features */
15759 i40e_print_features(pf);
15763 /* Unwind what we've done if something failed in the setup */
15765 set_bit(__I40E_DOWN, pf->state);
15766 i40e_clear_interrupt_scheme(pf);
15769 i40e_reset_interrupt_capability(pf);
15770 del_timer_sync(&pf->service_timer);
15772 err_configure_lan_hmc:
15773 (void)i40e_shutdown_lan_hmc(hw);
15775 kfree(pf->qp_pile);
15779 iounmap(hw->hw_addr);
15783 pci_disable_pcie_error_reporting(pdev);
15784 pci_release_mem_regions(pdev);
15787 pci_disable_device(pdev);
15792 * i40e_remove - Device removal routine
15793 * @pdev: PCI device information struct
15795 * i40e_remove is called by the PCI subsystem to alert the driver
15796 * that is should release a PCI device. This could be caused by a
15797 * Hot-Plug event, or because the driver is going to be removed from
15800 static void i40e_remove(struct pci_dev *pdev)
15802 struct i40e_pf *pf = pci_get_drvdata(pdev);
15803 struct i40e_hw *hw = &pf->hw;
15804 i40e_status ret_code;
15807 i40e_dbg_pf_exit(pf);
15811 /* Disable RSS in hw */
15812 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
15813 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
15815 while (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
15816 usleep_range(1000, 2000);
15818 if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
15819 set_bit(__I40E_VF_RESETS_DISABLED, pf->state);
15821 pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
15823 /* no more scheduling of any task */
15824 set_bit(__I40E_SUSPENDED, pf->state);
15825 set_bit(__I40E_DOWN, pf->state);
15826 if (pf->service_timer.function)
15827 del_timer_sync(&pf->service_timer);
15828 if (pf->service_task.func)
15829 cancel_work_sync(&pf->service_task);
15831 if (test_bit(__I40E_RECOVERY_MODE, pf->state)) {
15832 struct i40e_vsi *vsi = pf->vsi[0];
15834 /* We know that we have allocated only one vsi for this PF,
15835 * it was just for registering netdevice, so the interface
15836 * could be visible in the 'ifconfig' output
15838 unregister_netdev(vsi->netdev);
15839 free_netdev(vsi->netdev);
15844 /* Client close must be called explicitly here because the timer
15845 * has been stopped.
15847 i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
15849 i40e_fdir_teardown(pf);
15851 /* If there is a switch structure or any orphans, remove them.
15852 * This will leave only the PF's VSI remaining.
15854 for (i = 0; i < I40E_MAX_VEB; i++) {
15858 if (pf->veb[i]->uplink_seid == pf->mac_seid ||
15859 pf->veb[i]->uplink_seid == 0)
15860 i40e_switch_branch_release(pf->veb[i]);
15863 /* Now we can shutdown the PF's VSI, just before we kill
15866 if (pf->vsi[pf->lan_vsi])
15867 i40e_vsi_release(pf->vsi[pf->lan_vsi]);
15869 i40e_cloud_filter_exit(pf);
15871 /* remove attached clients */
15872 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
15873 ret_code = i40e_lan_del_device(pf);
15875 dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
15879 /* shutdown and destroy the HMC */
15880 if (hw->hmc.hmc_obj) {
15881 ret_code = i40e_shutdown_lan_hmc(hw);
15883 dev_warn(&pdev->dev,
15884 "Failed to destroy the HMC resources: %d\n",
15889 /* Free MSI/legacy interrupt 0 when in recovery mode. */
15890 if (test_bit(__I40E_RECOVERY_MODE, pf->state) &&
15891 !(pf->flags & I40E_FLAG_MSIX_ENABLED))
15892 free_irq(pf->pdev->irq, pf);
15894 /* shutdown the adminq */
15895 i40e_shutdown_adminq(hw);
15897 /* destroy the locks only once, here */
15898 mutex_destroy(&hw->aq.arq_mutex);
15899 mutex_destroy(&hw->aq.asq_mutex);
15901 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
15903 i40e_clear_interrupt_scheme(pf);
15904 for (i = 0; i < pf->num_alloc_vsi; i++) {
15906 if (!test_bit(__I40E_RECOVERY_MODE, pf->state))
15907 i40e_vsi_clear_rings(pf->vsi[i]);
15908 i40e_vsi_clear(pf->vsi[i]);
15914 for (i = 0; i < I40E_MAX_VEB; i++) {
15919 kfree(pf->qp_pile);
15922 iounmap(hw->hw_addr);
15924 pci_release_mem_regions(pdev);
15926 pci_disable_pcie_error_reporting(pdev);
15927 pci_disable_device(pdev);
15931 * i40e_pci_error_detected - warning that something funky happened in PCI land
15932 * @pdev: PCI device information struct
15933 * @error: the type of PCI error
15935 * Called to warn that something happened and the error handling steps
15936 * are in progress. Allows the driver to quiesce things, be ready for
15939 static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
15940 pci_channel_state_t error)
15942 struct i40e_pf *pf = pci_get_drvdata(pdev);
15944 dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
15947 dev_info(&pdev->dev,
15948 "Cannot recover - error happened during device probe\n");
15949 return PCI_ERS_RESULT_DISCONNECT;
15952 /* shutdown all operations */
15953 if (!test_bit(__I40E_SUSPENDED, pf->state))
15954 i40e_prep_for_reset(pf);
15956 /* Request a slot reset */
15957 return PCI_ERS_RESULT_NEED_RESET;
15961 * i40e_pci_error_slot_reset - a PCI slot reset just happened
15962 * @pdev: PCI device information struct
15964 * Called to find if the driver can work with the device now that
15965 * the pci slot has been reset. If a basic connection seems good
15966 * (registers are readable and have sane content) then return a
15967 * happy little PCI_ERS_RESULT_xxx.
15969 static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
15971 struct i40e_pf *pf = pci_get_drvdata(pdev);
15972 pci_ers_result_t result;
15975 dev_dbg(&pdev->dev, "%s\n", __func__);
15976 if (pci_enable_device_mem(pdev)) {
15977 dev_info(&pdev->dev,
15978 "Cannot re-enable PCI device after reset.\n");
15979 result = PCI_ERS_RESULT_DISCONNECT;
15981 pci_set_master(pdev);
15982 pci_restore_state(pdev);
15983 pci_save_state(pdev);
15984 pci_wake_from_d3(pdev, false);
15986 reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
15988 result = PCI_ERS_RESULT_RECOVERED;
15990 result = PCI_ERS_RESULT_DISCONNECT;
15997 * i40e_pci_error_reset_prepare - prepare device driver for pci reset
15998 * @pdev: PCI device information struct
16000 static void i40e_pci_error_reset_prepare(struct pci_dev *pdev)
16002 struct i40e_pf *pf = pci_get_drvdata(pdev);
16004 i40e_prep_for_reset(pf);
16008 * i40e_pci_error_reset_done - pci reset done, device driver reset can begin
16009 * @pdev: PCI device information struct
16011 static void i40e_pci_error_reset_done(struct pci_dev *pdev)
16013 struct i40e_pf *pf = pci_get_drvdata(pdev);
16015 i40e_reset_and_rebuild(pf, false, false);
16019 * i40e_pci_error_resume - restart operations after PCI error recovery
16020 * @pdev: PCI device information struct
16022 * Called to allow the driver to bring things back up after PCI error
16023 * and/or reset recovery has finished.
16025 static void i40e_pci_error_resume(struct pci_dev *pdev)
16027 struct i40e_pf *pf = pci_get_drvdata(pdev);
16029 dev_dbg(&pdev->dev, "%s\n", __func__);
16030 if (test_bit(__I40E_SUSPENDED, pf->state))
16033 i40e_handle_reset_warning(pf, false);
16037 * i40e_enable_mc_magic_wake - enable multicast magic packet wake up
16038 * using the mac_address_write admin q function
16039 * @pf: pointer to i40e_pf struct
16041 static void i40e_enable_mc_magic_wake(struct i40e_pf *pf)
16043 struct i40e_hw *hw = &pf->hw;
16048 /* Get current MAC address in case it's an LAA */
16049 if (pf->vsi[pf->lan_vsi] && pf->vsi[pf->lan_vsi]->netdev) {
16050 ether_addr_copy(mac_addr,
16051 pf->vsi[pf->lan_vsi]->netdev->dev_addr);
16053 dev_err(&pf->pdev->dev,
16054 "Failed to retrieve MAC address; using default\n");
16055 ether_addr_copy(mac_addr, hw->mac.addr);
16058 /* The FW expects the mac address write cmd to first be called with
16059 * one of these flags before calling it again with the multicast
16062 flags = I40E_AQC_WRITE_TYPE_LAA_WOL;
16064 if (hw->func_caps.flex10_enable && hw->partition_id != 1)
16065 flags = I40E_AQC_WRITE_TYPE_LAA_ONLY;
16067 ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
16069 dev_err(&pf->pdev->dev,
16070 "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up");
16074 flags = I40E_AQC_MC_MAG_EN
16075 | I40E_AQC_WOL_PRESERVE_ON_PFR
16076 | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG;
16077 ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
16079 dev_err(&pf->pdev->dev,
16080 "Failed to enable Multicast Magic Packet wake up\n");
16084 * i40e_shutdown - PCI callback for shutting down
16085 * @pdev: PCI device information struct
16087 static void i40e_shutdown(struct pci_dev *pdev)
16089 struct i40e_pf *pf = pci_get_drvdata(pdev);
16090 struct i40e_hw *hw = &pf->hw;
16092 set_bit(__I40E_SUSPENDED, pf->state);
16093 set_bit(__I40E_DOWN, pf->state);
16095 del_timer_sync(&pf->service_timer);
16096 cancel_work_sync(&pf->service_task);
16097 i40e_cloud_filter_exit(pf);
16098 i40e_fdir_teardown(pf);
16100 /* Client close must be called explicitly here because the timer
16101 * has been stopped.
16103 i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
16105 if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE))
16106 i40e_enable_mc_magic_wake(pf);
16108 i40e_prep_for_reset(pf);
16110 wr32(hw, I40E_PFPM_APM,
16111 (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
16112 wr32(hw, I40E_PFPM_WUFC,
16113 (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
16115 /* Free MSI/legacy interrupt 0 when in recovery mode. */
16116 if (test_bit(__I40E_RECOVERY_MODE, pf->state) &&
16117 !(pf->flags & I40E_FLAG_MSIX_ENABLED))
16118 free_irq(pf->pdev->irq, pf);
16120 /* Since we're going to destroy queues during the
16121 * i40e_clear_interrupt_scheme() we should hold the RTNL lock for this
16125 i40e_clear_interrupt_scheme(pf);
16128 if (system_state == SYSTEM_POWER_OFF) {
16129 pci_wake_from_d3(pdev, pf->wol_en);
16130 pci_set_power_state(pdev, PCI_D3hot);
16135 * i40e_suspend - PM callback for moving to D3
16136 * @dev: generic device information structure
16138 static int __maybe_unused i40e_suspend(struct device *dev)
16140 struct i40e_pf *pf = dev_get_drvdata(dev);
16141 struct i40e_hw *hw = &pf->hw;
16143 /* If we're already suspended, then there is nothing to do */
16144 if (test_and_set_bit(__I40E_SUSPENDED, pf->state))
16147 set_bit(__I40E_DOWN, pf->state);
16149 /* Ensure service task will not be running */
16150 del_timer_sync(&pf->service_timer);
16151 cancel_work_sync(&pf->service_task);
16153 /* Client close must be called explicitly here because the timer
16154 * has been stopped.
16156 i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
16158 if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE))
16159 i40e_enable_mc_magic_wake(pf);
16161 /* Since we're going to destroy queues during the
16162 * i40e_clear_interrupt_scheme() we should hold the RTNL lock for this
16167 i40e_prep_for_reset(pf);
16169 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
16170 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
16172 /* Clear the interrupt scheme and release our IRQs so that the system
16173 * can safely hibernate even when there are a large number of CPUs.
16174 * Otherwise hibernation might fail when mapping all the vectors back
16177 i40e_clear_interrupt_scheme(pf);
16185 * i40e_resume - PM callback for waking up from D3
16186 * @dev: generic device information structure
16188 static int __maybe_unused i40e_resume(struct device *dev)
16190 struct i40e_pf *pf = dev_get_drvdata(dev);
16193 /* If we're not suspended, then there is nothing to do */
16194 if (!test_bit(__I40E_SUSPENDED, pf->state))
16197 /* We need to hold the RTNL lock prior to restoring interrupt schemes,
16198 * since we're going to be restoring queues
16202 /* We cleared the interrupt scheme when we suspended, so we need to
16203 * restore it now to resume device functionality.
16205 err = i40e_restore_interrupt_scheme(pf);
16207 dev_err(dev, "Cannot restore interrupt scheme: %d\n",
16211 clear_bit(__I40E_DOWN, pf->state);
16212 i40e_reset_and_rebuild(pf, false, true);
16216 /* Clear suspended state last after everything is recovered */
16217 clear_bit(__I40E_SUSPENDED, pf->state);
16219 /* Restart the service task */
16220 mod_timer(&pf->service_timer,
16221 round_jiffies(jiffies + pf->service_timer_period));
16226 static const struct pci_error_handlers i40e_err_handler = {
16227 .error_detected = i40e_pci_error_detected,
16228 .slot_reset = i40e_pci_error_slot_reset,
16229 .reset_prepare = i40e_pci_error_reset_prepare,
16230 .reset_done = i40e_pci_error_reset_done,
16231 .resume = i40e_pci_error_resume,
16234 static SIMPLE_DEV_PM_OPS(i40e_pm_ops, i40e_suspend, i40e_resume);
16236 static struct pci_driver i40e_driver = {
16237 .name = i40e_driver_name,
16238 .id_table = i40e_pci_tbl,
16239 .probe = i40e_probe,
16240 .remove = i40e_remove,
16242 .pm = &i40e_pm_ops,
16244 .shutdown = i40e_shutdown,
16245 .err_handler = &i40e_err_handler,
16246 .sriov_configure = i40e_pci_sriov_configure,
16250 * i40e_init_module - Driver registration routine
16252 * i40e_init_module is the first routine called when the driver is
16253 * loaded. All it does is register with the PCI subsystem.
16255 static int __init i40e_init_module(void)
16257 pr_info("%s: %s\n", i40e_driver_name, i40e_driver_string);
16258 pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
16260 /* There is no need to throttle the number of active tasks because
16261 * each device limits its own task using a state bit for scheduling
16262 * the service task, and the device tasks do not interfere with each
16263 * other, so we don't set a max task limit. We must set WQ_MEM_RECLAIM
16264 * since we need to be able to guarantee forward progress even under
16267 i40e_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, i40e_driver_name);
16269 pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
16274 return pci_register_driver(&i40e_driver);
16276 module_init(i40e_init_module);
16279 * i40e_exit_module - Driver exit cleanup routine
16281 * i40e_exit_module is called just before the driver is removed
16284 static void __exit i40e_exit_module(void)
16286 pci_unregister_driver(&i40e_driver);
16287 destroy_workqueue(i40e_wq);
16290 module_exit(i40e_exit_module);