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 allmulti mode.\n",
2564 cur_multipromisc ? "entering" : "leaving");
2568 if ((changed_flags & IFF_PROMISC) || old_overflow != new_overflow) {
2571 cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
2573 aq_ret = i40e_set_promiscuous(pf, cur_promisc);
2575 retval = i40e_aq_rc_to_posix(aq_ret,
2576 hw->aq.asq_last_status);
2577 dev_info(&pf->pdev->dev,
2578 "Setting promiscuous %s failed on %s, err %s aq_err %s\n",
2579 cur_promisc ? "on" : "off",
2581 i40e_stat_str(hw, aq_ret),
2582 i40e_aq_str(hw, hw->aq.asq_last_status));
2586 /* if something went wrong then set the changed flag so we try again */
2588 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
2590 clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
2594 /* Restore elements on the temporary add and delete lists */
2595 spin_lock_bh(&vsi->mac_filter_hash_lock);
2596 err_no_memory_locked:
2597 i40e_undo_del_filter_entries(vsi, &tmp_del_list);
2598 i40e_undo_add_filter_entries(vsi, &tmp_add_list);
2599 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2601 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
2602 clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
2607 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
2608 * @pf: board private structure
2610 static void i40e_sync_filters_subtask(struct i40e_pf *pf)
2616 if (!test_and_clear_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state))
2618 if (test_bit(__I40E_VF_DISABLE, pf->state)) {
2619 set_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state);
2623 for (v = 0; v < pf->num_alloc_vsi; v++) {
2625 (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
2626 int ret = i40e_sync_vsi_filters(pf->vsi[v]);
2629 /* come back and try again later */
2630 set_bit(__I40E_MACVLAN_SYNC_PENDING,
2639 * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP
2642 static int i40e_max_xdp_frame_size(struct i40e_vsi *vsi)
2644 if (PAGE_SIZE >= 8192 || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
2645 return I40E_RXBUFFER_2048;
2647 return I40E_RXBUFFER_3072;
2651 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
2652 * @netdev: network interface device structure
2653 * @new_mtu: new value for maximum frame size
2655 * Returns 0 on success, negative on failure
2657 static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
2659 struct i40e_netdev_priv *np = netdev_priv(netdev);
2660 struct i40e_vsi *vsi = np->vsi;
2661 struct i40e_pf *pf = vsi->back;
2663 if (i40e_enabled_xdp_vsi(vsi)) {
2664 int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
2666 if (frame_size > i40e_max_xdp_frame_size(vsi))
2670 netdev_dbg(netdev, "changing MTU from %d to %d\n",
2671 netdev->mtu, new_mtu);
2672 netdev->mtu = new_mtu;
2673 if (netif_running(netdev))
2674 i40e_vsi_reinit_locked(vsi);
2675 set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
2676 set_bit(__I40E_CLIENT_L2_CHANGE, pf->state);
2681 * i40e_ioctl - Access the hwtstamp interface
2682 * @netdev: network interface device structure
2683 * @ifr: interface request data
2684 * @cmd: ioctl command
2686 int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2688 struct i40e_netdev_priv *np = netdev_priv(netdev);
2689 struct i40e_pf *pf = np->vsi->back;
2693 return i40e_ptp_get_ts_config(pf, ifr);
2695 return i40e_ptp_set_ts_config(pf, ifr);
2702 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
2703 * @vsi: the vsi being adjusted
2705 void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
2707 struct i40e_vsi_context ctxt;
2710 /* Don't modify stripping options if a port VLAN is active */
2714 if ((vsi->info.valid_sections &
2715 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2716 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
2717 return; /* already enabled */
2719 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2720 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2721 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
2723 ctxt.seid = vsi->seid;
2724 ctxt.info = vsi->info;
2725 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2727 dev_info(&vsi->back->pdev->dev,
2728 "update vlan stripping failed, err %s aq_err %s\n",
2729 i40e_stat_str(&vsi->back->hw, ret),
2730 i40e_aq_str(&vsi->back->hw,
2731 vsi->back->hw.aq.asq_last_status));
2736 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2737 * @vsi: the vsi being adjusted
2739 void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
2741 struct i40e_vsi_context ctxt;
2744 /* Don't modify stripping options if a port VLAN is active */
2748 if ((vsi->info.valid_sections &
2749 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2750 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
2751 I40E_AQ_VSI_PVLAN_EMOD_MASK))
2752 return; /* already disabled */
2754 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2755 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2756 I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
2758 ctxt.seid = vsi->seid;
2759 ctxt.info = vsi->info;
2760 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2762 dev_info(&vsi->back->pdev->dev,
2763 "update vlan stripping failed, err %s aq_err %s\n",
2764 i40e_stat_str(&vsi->back->hw, ret),
2765 i40e_aq_str(&vsi->back->hw,
2766 vsi->back->hw.aq.asq_last_status));
2771 * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address
2772 * @vsi: the vsi being configured
2773 * @vid: vlan id to be added (0 = untagged only , -1 = any)
2775 * This is a helper function for adding a new MAC/VLAN filter with the
2776 * specified VLAN for each existing MAC address already in the hash table.
2777 * This function does *not* perform any accounting to update filters based on
2780 * NOTE: this function expects to be called while under the
2781 * mac_filter_hash_lock
2783 int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
2785 struct i40e_mac_filter *f, *add_f;
2786 struct hlist_node *h;
2789 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
2790 if (f->state == I40E_FILTER_REMOVE)
2792 add_f = i40e_add_filter(vsi, f->macaddr, vid);
2794 dev_info(&vsi->back->pdev->dev,
2795 "Could not add vlan filter %d for %pM\n",
2805 * i40e_vsi_add_vlan - Add VSI membership for given VLAN
2806 * @vsi: the VSI being configured
2807 * @vid: VLAN id to be added
2809 int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid)
2816 /* The network stack will attempt to add VID=0, with the intention to
2817 * receive priority tagged packets with a VLAN of 0. Our HW receives
2818 * these packets by default when configured to receive untagged
2819 * packets, so we don't need to add a filter for this case.
2820 * Additionally, HW interprets adding a VID=0 filter as meaning to
2821 * receive *only* tagged traffic and stops receiving untagged traffic.
2822 * Thus, we do not want to actually add a filter for VID=0
2827 /* Locked once because all functions invoked below iterates list*/
2828 spin_lock_bh(&vsi->mac_filter_hash_lock);
2829 err = i40e_add_vlan_all_mac(vsi, vid);
2830 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2834 /* schedule our worker thread which will take care of
2835 * applying the new filter changes
2837 i40e_service_event_schedule(vsi->back);
2842 * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN
2843 * @vsi: the vsi being configured
2844 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
2846 * This function should be used to remove all VLAN filters which match the
2847 * given VID. It does not schedule the service event and does not take the
2848 * mac_filter_hash_lock so it may be combined with other operations under
2849 * a single invocation of the mac_filter_hash_lock.
2851 * NOTE: this function expects to be called while under the
2852 * mac_filter_hash_lock
2854 void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
2856 struct i40e_mac_filter *f;
2857 struct hlist_node *h;
2860 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
2862 __i40e_del_filter(vsi, f);
2867 * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN
2868 * @vsi: the VSI being configured
2869 * @vid: VLAN id to be removed
2871 void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid)
2873 if (!vid || vsi->info.pvid)
2876 spin_lock_bh(&vsi->mac_filter_hash_lock);
2877 i40e_rm_vlan_all_mac(vsi, vid);
2878 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2880 /* schedule our worker thread which will take care of
2881 * applying the new filter changes
2883 i40e_service_event_schedule(vsi->back);
2887 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2888 * @netdev: network interface to be adjusted
2889 * @proto: unused protocol value
2890 * @vid: vlan id to be added
2892 * net_device_ops implementation for adding vlan ids
2894 static int i40e_vlan_rx_add_vid(struct net_device *netdev,
2895 __always_unused __be16 proto, u16 vid)
2897 struct i40e_netdev_priv *np = netdev_priv(netdev);
2898 struct i40e_vsi *vsi = np->vsi;
2901 if (vid >= VLAN_N_VID)
2904 ret = i40e_vsi_add_vlan(vsi, vid);
2906 set_bit(vid, vsi->active_vlans);
2912 * i40e_vlan_rx_add_vid_up - Add a vlan id filter to HW offload in UP path
2913 * @netdev: network interface to be adjusted
2914 * @proto: unused protocol value
2915 * @vid: vlan id to be added
2917 static void i40e_vlan_rx_add_vid_up(struct net_device *netdev,
2918 __always_unused __be16 proto, u16 vid)
2920 struct i40e_netdev_priv *np = netdev_priv(netdev);
2921 struct i40e_vsi *vsi = np->vsi;
2923 if (vid >= VLAN_N_VID)
2925 set_bit(vid, vsi->active_vlans);
2929 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2930 * @netdev: network interface to be adjusted
2931 * @proto: unused protocol value
2932 * @vid: vlan id to be removed
2934 * net_device_ops implementation for removing vlan ids
2936 static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2937 __always_unused __be16 proto, u16 vid)
2939 struct i40e_netdev_priv *np = netdev_priv(netdev);
2940 struct i40e_vsi *vsi = np->vsi;
2942 /* return code is ignored as there is nothing a user
2943 * can do about failure to remove and a log message was
2944 * already printed from the other function
2946 i40e_vsi_kill_vlan(vsi, vid);
2948 clear_bit(vid, vsi->active_vlans);
2954 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2955 * @vsi: the vsi being brought back up
2957 static void i40e_restore_vlan(struct i40e_vsi *vsi)
2964 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
2965 i40e_vlan_stripping_enable(vsi);
2967 i40e_vlan_stripping_disable(vsi);
2969 for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
2970 i40e_vlan_rx_add_vid_up(vsi->netdev, htons(ETH_P_8021Q),
2975 * i40e_vsi_add_pvid - Add pvid for the VSI
2976 * @vsi: the vsi being adjusted
2977 * @vid: the vlan id to set as a PVID
2979 int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
2981 struct i40e_vsi_context ctxt;
2984 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2985 vsi->info.pvid = cpu_to_le16(vid);
2986 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
2987 I40E_AQ_VSI_PVLAN_INSERT_PVID |
2988 I40E_AQ_VSI_PVLAN_EMOD_STR;
2990 ctxt.seid = vsi->seid;
2991 ctxt.info = vsi->info;
2992 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2994 dev_info(&vsi->back->pdev->dev,
2995 "add pvid failed, err %s aq_err %s\n",
2996 i40e_stat_str(&vsi->back->hw, ret),
2997 i40e_aq_str(&vsi->back->hw,
2998 vsi->back->hw.aq.asq_last_status));
3006 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
3007 * @vsi: the vsi being adjusted
3009 * Just use the vlan_rx_register() service to put it back to normal
3011 void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
3015 i40e_vlan_stripping_disable(vsi);
3019 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
3020 * @vsi: ptr to the VSI
3022 * If this function returns with an error, then it's possible one or
3023 * more of the rings is populated (while the rest are not). It is the
3024 * callers duty to clean those orphaned rings.
3026 * Return 0 on success, negative on failure
3028 static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
3032 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
3033 err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
3035 if (!i40e_enabled_xdp_vsi(vsi))
3038 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
3039 err = i40e_setup_tx_descriptors(vsi->xdp_rings[i]);
3045 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
3046 * @vsi: ptr to the VSI
3048 * Free VSI's transmit software resources
3050 static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
3054 if (vsi->tx_rings) {
3055 for (i = 0; i < vsi->num_queue_pairs; i++)
3056 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
3057 i40e_free_tx_resources(vsi->tx_rings[i]);
3060 if (vsi->xdp_rings) {
3061 for (i = 0; i < vsi->num_queue_pairs; i++)
3062 if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc)
3063 i40e_free_tx_resources(vsi->xdp_rings[i]);
3068 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
3069 * @vsi: ptr to the VSI
3071 * If this function returns with an error, then it's possible one or
3072 * more of the rings is populated (while the rest are not). It is the
3073 * callers duty to clean those orphaned rings.
3075 * Return 0 on success, negative on failure
3077 static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
3081 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
3082 err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
3087 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
3088 * @vsi: ptr to the VSI
3090 * Free all receive software resources
3092 static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
3099 for (i = 0; i < vsi->num_queue_pairs; i++)
3100 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
3101 i40e_free_rx_resources(vsi->rx_rings[i]);
3105 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
3106 * @ring: The Tx ring to configure
3108 * This enables/disables XPS for a given Tx descriptor ring
3109 * based on the TCs enabled for the VSI that ring belongs to.
3111 static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
3115 if (!ring->q_vector || !ring->netdev || ring->ch)
3118 /* We only initialize XPS once, so as not to overwrite user settings */
3119 if (test_and_set_bit(__I40E_TX_XPS_INIT_DONE, ring->state))
3122 cpu = cpumask_local_spread(ring->q_vector->v_idx, -1);
3123 netif_set_xps_queue(ring->netdev, get_cpu_mask(cpu),
3128 * i40e_xsk_pool - Retrieve the AF_XDP buffer pool if XDP and ZC is enabled
3129 * @ring: The Tx or Rx ring
3131 * Returns the AF_XDP buffer pool or NULL.
3133 static struct xsk_buff_pool *i40e_xsk_pool(struct i40e_ring *ring)
3135 bool xdp_on = i40e_enabled_xdp_vsi(ring->vsi);
3136 int qid = ring->queue_index;
3138 if (ring_is_xdp(ring))
3139 qid -= ring->vsi->alloc_queue_pairs;
3141 if (!xdp_on || !test_bit(qid, ring->vsi->af_xdp_zc_qps))
3144 return xsk_get_pool_from_qid(ring->vsi->netdev, qid);
3148 * i40e_configure_tx_ring - Configure a transmit ring context and rest
3149 * @ring: The Tx ring to configure
3151 * Configure the Tx descriptor ring in the HMC context.
3153 static int i40e_configure_tx_ring(struct i40e_ring *ring)
3155 struct i40e_vsi *vsi = ring->vsi;
3156 u16 pf_q = vsi->base_queue + ring->queue_index;
3157 struct i40e_hw *hw = &vsi->back->hw;
3158 struct i40e_hmc_obj_txq tx_ctx;
3159 i40e_status err = 0;
3162 if (ring_is_xdp(ring))
3163 ring->xsk_pool = i40e_xsk_pool(ring);
3165 /* some ATR related tx ring init */
3166 if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
3167 ring->atr_sample_rate = vsi->back->atr_sample_rate;
3168 ring->atr_count = 0;
3170 ring->atr_sample_rate = 0;
3174 i40e_config_xps_tx_ring(ring);
3176 /* clear the context structure first */
3177 memset(&tx_ctx, 0, sizeof(tx_ctx));
3179 tx_ctx.new_context = 1;
3180 tx_ctx.base = (ring->dma / 128);
3181 tx_ctx.qlen = ring->count;
3182 tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
3183 I40E_FLAG_FD_ATR_ENABLED));
3184 tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
3185 /* FDIR VSI tx ring can still use RS bit and writebacks */
3186 if (vsi->type != I40E_VSI_FDIR)
3187 tx_ctx.head_wb_ena = 1;
3188 tx_ctx.head_wb_addr = ring->dma +
3189 (ring->count * sizeof(struct i40e_tx_desc));
3191 /* As part of VSI creation/update, FW allocates certain
3192 * Tx arbitration queue sets for each TC enabled for
3193 * the VSI. The FW returns the handles to these queue
3194 * sets as part of the response buffer to Add VSI,
3195 * Update VSI, etc. AQ commands. It is expected that
3196 * these queue set handles be associated with the Tx
3197 * queues by the driver as part of the TX queue context
3198 * initialization. This has to be done regardless of
3199 * DCB as by default everything is mapped to TC0.
3204 le16_to_cpu(ring->ch->info.qs_handle[ring->dcb_tc]);
3207 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
3209 tx_ctx.rdylist_act = 0;
3211 /* clear the context in the HMC */
3212 err = i40e_clear_lan_tx_queue_context(hw, pf_q);
3214 dev_info(&vsi->back->pdev->dev,
3215 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
3216 ring->queue_index, pf_q, err);
3220 /* set the context in the HMC */
3221 err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
3223 dev_info(&vsi->back->pdev->dev,
3224 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
3225 ring->queue_index, pf_q, err);
3229 /* Now associate this queue with this PCI function */
3231 if (ring->ch->type == I40E_VSI_VMDQ2)
3232 qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
3236 qtx_ctl |= (ring->ch->vsi_number <<
3237 I40E_QTX_CTL_VFVM_INDX_SHIFT) &
3238 I40E_QTX_CTL_VFVM_INDX_MASK;
3240 if (vsi->type == I40E_VSI_VMDQ2) {
3241 qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
3242 qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
3243 I40E_QTX_CTL_VFVM_INDX_MASK;
3245 qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
3249 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
3250 I40E_QTX_CTL_PF_INDX_MASK);
3251 wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
3254 /* cache tail off for easier writes later */
3255 ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
3261 * i40e_rx_offset - Return expected offset into page to access data
3262 * @rx_ring: Ring we are requesting offset of
3264 * Returns the offset value for ring into the data buffer.
3266 static unsigned int i40e_rx_offset(struct i40e_ring *rx_ring)
3268 return ring_uses_build_skb(rx_ring) ? I40E_SKB_PAD : 0;
3272 * i40e_configure_rx_ring - Configure a receive ring context
3273 * @ring: The Rx ring to configure
3275 * Configure the Rx descriptor ring in the HMC context.
3277 static int i40e_configure_rx_ring(struct i40e_ring *ring)
3279 struct i40e_vsi *vsi = ring->vsi;
3280 u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
3281 u16 pf_q = vsi->base_queue + ring->queue_index;
3282 struct i40e_hw *hw = &vsi->back->hw;
3283 struct i40e_hmc_obj_rxq rx_ctx;
3284 i40e_status err = 0;
3288 bitmap_zero(ring->state, __I40E_RING_STATE_NBITS);
3290 /* clear the context structure first */
3291 memset(&rx_ctx, 0, sizeof(rx_ctx));
3293 if (ring->vsi->type == I40E_VSI_MAIN)
3294 xdp_rxq_info_unreg_mem_model(&ring->xdp_rxq);
3297 ring->xsk_pool = i40e_xsk_pool(ring);
3298 if (ring->xsk_pool) {
3299 ret = i40e_alloc_rx_bi_zc(ring);
3303 xsk_pool_get_rx_frame_size(ring->xsk_pool);
3304 /* For AF_XDP ZC, we disallow packets to span on
3305 * multiple buffers, thus letting us skip that
3306 * handling in the fast-path.
3309 ret = xdp_rxq_info_reg_mem_model(&ring->xdp_rxq,
3310 MEM_TYPE_XSK_BUFF_POOL,
3314 dev_info(&vsi->back->pdev->dev,
3315 "Registered XDP mem model MEM_TYPE_XSK_BUFF_POOL on Rx ring %d\n",
3319 ret = i40e_alloc_rx_bi(ring);
3322 ring->rx_buf_len = vsi->rx_buf_len;
3323 if (ring->vsi->type == I40E_VSI_MAIN) {
3324 ret = xdp_rxq_info_reg_mem_model(&ring->xdp_rxq,
3325 MEM_TYPE_PAGE_SHARED,
3332 rx_ctx.dbuff = DIV_ROUND_UP(ring->rx_buf_len,
3333 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
3335 rx_ctx.base = (ring->dma / 128);
3336 rx_ctx.qlen = ring->count;
3338 /* use 16 byte descriptors */
3341 /* descriptor type is always zero
3344 rx_ctx.hsplit_0 = 0;
3346 rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len);
3347 if (hw->revision_id == 0)
3348 rx_ctx.lrxqthresh = 0;
3350 rx_ctx.lrxqthresh = 1;
3351 rx_ctx.crcstrip = 1;
3353 /* this controls whether VLAN is stripped from inner headers */
3355 /* set the prefena field to 1 because the manual says to */
3358 /* clear the context in the HMC */
3359 err = i40e_clear_lan_rx_queue_context(hw, pf_q);
3361 dev_info(&vsi->back->pdev->dev,
3362 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
3363 ring->queue_index, pf_q, err);
3367 /* set the context in the HMC */
3368 err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
3370 dev_info(&vsi->back->pdev->dev,
3371 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
3372 ring->queue_index, pf_q, err);
3376 /* configure Rx buffer alignment */
3377 if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
3378 clear_ring_build_skb_enabled(ring);
3380 set_ring_build_skb_enabled(ring);
3382 ring->rx_offset = i40e_rx_offset(ring);
3384 /* cache tail for quicker writes, and clear the reg before use */
3385 ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
3386 writel(0, ring->tail);
3388 if (ring->xsk_pool) {
3389 xsk_pool_set_rxq_info(ring->xsk_pool, &ring->xdp_rxq);
3390 ok = i40e_alloc_rx_buffers_zc(ring, I40E_DESC_UNUSED(ring));
3392 ok = !i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
3395 /* Log this in case the user has forgotten to give the kernel
3396 * any buffers, even later in the application.
3398 dev_info(&vsi->back->pdev->dev,
3399 "Failed to allocate some buffers on %sRx ring %d (pf_q %d)\n",
3400 ring->xsk_pool ? "AF_XDP ZC enabled " : "",
3401 ring->queue_index, pf_q);
3408 * i40e_vsi_configure_tx - Configure the VSI for Tx
3409 * @vsi: VSI structure describing this set of rings and resources
3411 * Configure the Tx VSI for operation.
3413 static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
3418 for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
3419 err = i40e_configure_tx_ring(vsi->tx_rings[i]);
3421 if (err || !i40e_enabled_xdp_vsi(vsi))
3424 for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
3425 err = i40e_configure_tx_ring(vsi->xdp_rings[i]);
3431 * i40e_vsi_configure_rx - Configure the VSI for Rx
3432 * @vsi: the VSI being configured
3434 * Configure the Rx VSI for operation.
3436 static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
3441 if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) {
3442 vsi->max_frame = I40E_MAX_RXBUFFER;
3443 vsi->rx_buf_len = I40E_RXBUFFER_2048;
3444 #if (PAGE_SIZE < 8192)
3445 } else if (!I40E_2K_TOO_SMALL_WITH_PADDING &&
3446 (vsi->netdev->mtu <= ETH_DATA_LEN)) {
3447 vsi->max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
3448 vsi->rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
3451 vsi->max_frame = I40E_MAX_RXBUFFER;
3452 vsi->rx_buf_len = (PAGE_SIZE < 8192) ? I40E_RXBUFFER_3072 :
3456 /* set up individual rings */
3457 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
3458 err = i40e_configure_rx_ring(vsi->rx_rings[i]);
3464 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
3465 * @vsi: ptr to the VSI
3467 static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
3469 struct i40e_ring *tx_ring, *rx_ring;
3470 u16 qoffset, qcount;
3473 if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
3474 /* Reset the TC information */
3475 for (i = 0; i < vsi->num_queue_pairs; i++) {
3476 rx_ring = vsi->rx_rings[i];
3477 tx_ring = vsi->tx_rings[i];
3478 rx_ring->dcb_tc = 0;
3479 tx_ring->dcb_tc = 0;
3484 for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
3485 if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
3488 qoffset = vsi->tc_config.tc_info[n].qoffset;
3489 qcount = vsi->tc_config.tc_info[n].qcount;
3490 for (i = qoffset; i < (qoffset + qcount); i++) {
3491 rx_ring = vsi->rx_rings[i];
3492 tx_ring = vsi->tx_rings[i];
3493 rx_ring->dcb_tc = n;
3494 tx_ring->dcb_tc = n;
3500 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
3501 * @vsi: ptr to the VSI
3503 static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
3506 i40e_set_rx_mode(vsi->netdev);
3510 * i40e_reset_fdir_filter_cnt - Reset flow director filter counters
3511 * @pf: Pointer to the targeted PF
3513 * Set all flow director counters to 0.
3515 static void i40e_reset_fdir_filter_cnt(struct i40e_pf *pf)
3517 pf->fd_tcp4_filter_cnt = 0;
3518 pf->fd_udp4_filter_cnt = 0;
3519 pf->fd_sctp4_filter_cnt = 0;
3520 pf->fd_ip4_filter_cnt = 0;
3521 pf->fd_tcp6_filter_cnt = 0;
3522 pf->fd_udp6_filter_cnt = 0;
3523 pf->fd_sctp6_filter_cnt = 0;
3524 pf->fd_ip6_filter_cnt = 0;
3528 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
3529 * @vsi: Pointer to the targeted VSI
3531 * This function replays the hlist on the hw where all the SB Flow Director
3532 * filters were saved.
3534 static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
3536 struct i40e_fdir_filter *filter;
3537 struct i40e_pf *pf = vsi->back;
3538 struct hlist_node *node;
3540 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3543 /* Reset FDir counters as we're replaying all existing filters */
3544 i40e_reset_fdir_filter_cnt(pf);
3546 hlist_for_each_entry_safe(filter, node,
3547 &pf->fdir_filter_list, fdir_node) {
3548 i40e_add_del_fdir(vsi, filter, true);
3553 * i40e_vsi_configure - Set up the VSI for action
3554 * @vsi: the VSI being configured
3556 static int i40e_vsi_configure(struct i40e_vsi *vsi)
3560 i40e_set_vsi_rx_mode(vsi);
3561 i40e_restore_vlan(vsi);
3562 i40e_vsi_config_dcb_rings(vsi);
3563 err = i40e_vsi_configure_tx(vsi);
3565 err = i40e_vsi_configure_rx(vsi);
3571 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
3572 * @vsi: the VSI being configured
3574 static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
3576 bool has_xdp = i40e_enabled_xdp_vsi(vsi);
3577 struct i40e_pf *pf = vsi->back;
3578 struct i40e_hw *hw = &pf->hw;
3583 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
3584 * and PFINT_LNKLSTn registers, e.g.:
3585 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
3587 qp = vsi->base_queue;
3588 vector = vsi->base_vector;
3589 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
3590 struct i40e_q_vector *q_vector = vsi->q_vectors[i];
3592 q_vector->rx.next_update = jiffies + 1;
3593 q_vector->rx.target_itr =
3594 ITR_TO_REG(vsi->rx_rings[i]->itr_setting);
3595 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
3596 q_vector->rx.target_itr >> 1);
3597 q_vector->rx.current_itr = q_vector->rx.target_itr;
3599 q_vector->tx.next_update = jiffies + 1;
3600 q_vector->tx.target_itr =
3601 ITR_TO_REG(vsi->tx_rings[i]->itr_setting);
3602 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
3603 q_vector->tx.target_itr >> 1);
3604 q_vector->tx.current_itr = q_vector->tx.target_itr;
3606 wr32(hw, I40E_PFINT_RATEN(vector - 1),
3607 i40e_intrl_usec_to_reg(vsi->int_rate_limit));
3609 /* Linked list for the queuepairs assigned to this vector */
3610 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
3611 for (q = 0; q < q_vector->num_ringpairs; q++) {
3612 u32 nextqp = has_xdp ? qp + vsi->alloc_queue_pairs : qp;
3615 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3616 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3617 (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
3618 (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
3619 (I40E_QUEUE_TYPE_TX <<
3620 I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
3622 wr32(hw, I40E_QINT_RQCTL(qp), val);
3625 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3626 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3627 (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
3628 (qp << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
3629 (I40E_QUEUE_TYPE_TX <<
3630 I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3632 wr32(hw, I40E_QINT_TQCTL(nextqp), val);
3635 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3636 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3637 (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
3638 ((qp + 1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
3639 (I40E_QUEUE_TYPE_RX <<
3640 I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3642 /* Terminate the linked list */
3643 if (q == (q_vector->num_ringpairs - 1))
3644 val |= (I40E_QUEUE_END_OF_LIST <<
3645 I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3647 wr32(hw, I40E_QINT_TQCTL(qp), val);
3656 * i40e_enable_misc_int_causes - enable the non-queue interrupts
3657 * @pf: pointer to private device data structure
3659 static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
3661 struct i40e_hw *hw = &pf->hw;
3664 /* clear things first */
3665 wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
3666 rd32(hw, I40E_PFINT_ICR0); /* read to clear */
3668 val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
3669 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
3670 I40E_PFINT_ICR0_ENA_GRST_MASK |
3671 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
3672 I40E_PFINT_ICR0_ENA_GPIO_MASK |
3673 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
3674 I40E_PFINT_ICR0_ENA_VFLR_MASK |
3675 I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
3677 if (pf->flags & I40E_FLAG_IWARP_ENABLED)
3678 val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3680 if (pf->flags & I40E_FLAG_PTP)
3681 val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
3683 wr32(hw, I40E_PFINT_ICR0_ENA, val);
3685 /* SW_ITR_IDX = 0, but don't change INTENA */
3686 wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
3687 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
3689 /* OTHER_ITR_IDX = 0 */
3690 wr32(hw, I40E_PFINT_STAT_CTL0, 0);
3694 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
3695 * @vsi: the VSI being configured
3697 static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
3699 u32 nextqp = i40e_enabled_xdp_vsi(vsi) ? vsi->alloc_queue_pairs : 0;
3700 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
3701 struct i40e_pf *pf = vsi->back;
3702 struct i40e_hw *hw = &pf->hw;
3705 /* set the ITR configuration */
3706 q_vector->rx.next_update = jiffies + 1;
3707 q_vector->rx.target_itr = ITR_TO_REG(vsi->rx_rings[0]->itr_setting);
3708 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.target_itr >> 1);
3709 q_vector->rx.current_itr = q_vector->rx.target_itr;
3710 q_vector->tx.next_update = jiffies + 1;
3711 q_vector->tx.target_itr = ITR_TO_REG(vsi->tx_rings[0]->itr_setting);
3712 wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.target_itr >> 1);
3713 q_vector->tx.current_itr = q_vector->tx.target_itr;
3715 i40e_enable_misc_int_causes(pf);
3717 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
3718 wr32(hw, I40E_PFINT_LNKLST0, 0);
3720 /* Associate the queue pair to the vector and enable the queue int */
3721 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3722 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3723 (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
3724 (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3726 wr32(hw, I40E_QINT_RQCTL(0), val);
3728 if (i40e_enabled_xdp_vsi(vsi)) {
3729 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3730 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT)|
3732 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3734 wr32(hw, I40E_QINT_TQCTL(nextqp), val);
3737 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3738 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3739 (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3741 wr32(hw, I40E_QINT_TQCTL(0), val);
3746 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
3747 * @pf: board private structure
3749 void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
3751 struct i40e_hw *hw = &pf->hw;
3753 wr32(hw, I40E_PFINT_DYN_CTL0,
3754 I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
3759 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
3760 * @pf: board private structure
3762 void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf)
3764 struct i40e_hw *hw = &pf->hw;
3767 val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
3768 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
3769 (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
3771 wr32(hw, I40E_PFINT_DYN_CTL0, val);
3776 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
3777 * @irq: interrupt number
3778 * @data: pointer to a q_vector
3780 static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
3782 struct i40e_q_vector *q_vector = data;
3784 if (!q_vector->tx.ring && !q_vector->rx.ring)
3787 napi_schedule_irqoff(&q_vector->napi);
3793 * i40e_irq_affinity_notify - Callback for affinity changes
3794 * @notify: context as to what irq was changed
3795 * @mask: the new affinity mask
3797 * This is a callback function used by the irq_set_affinity_notifier function
3798 * so that we may register to receive changes to the irq affinity masks.
3800 static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify,
3801 const cpumask_t *mask)
3803 struct i40e_q_vector *q_vector =
3804 container_of(notify, struct i40e_q_vector, affinity_notify);
3806 cpumask_copy(&q_vector->affinity_mask, mask);
3810 * i40e_irq_affinity_release - Callback for affinity notifier release
3811 * @ref: internal core kernel usage
3813 * This is a callback function used by the irq_set_affinity_notifier function
3814 * to inform the current notification subscriber that they will no longer
3815 * receive notifications.
3817 static void i40e_irq_affinity_release(struct kref *ref) {}
3820 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3821 * @vsi: the VSI being configured
3822 * @basename: name for the vector
3824 * Allocates MSI-X vectors and requests interrupts from the kernel.
3826 static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
3828 int q_vectors = vsi->num_q_vectors;
3829 struct i40e_pf *pf = vsi->back;
3830 int base = vsi->base_vector;
3837 for (vector = 0; vector < q_vectors; vector++) {
3838 struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
3840 irq_num = pf->msix_entries[base + vector].vector;
3842 if (q_vector->tx.ring && q_vector->rx.ring) {
3843 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3844 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
3846 } else if (q_vector->rx.ring) {
3847 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3848 "%s-%s-%d", basename, "rx", rx_int_idx++);
3849 } else if (q_vector->tx.ring) {
3850 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3851 "%s-%s-%d", basename, "tx", tx_int_idx++);
3853 /* skip this unused q_vector */
3856 err = request_irq(irq_num,
3862 dev_info(&pf->pdev->dev,
3863 "MSIX request_irq failed, error: %d\n", err);
3864 goto free_queue_irqs;
3867 /* register for affinity change notifications */
3868 q_vector->affinity_notify.notify = i40e_irq_affinity_notify;
3869 q_vector->affinity_notify.release = i40e_irq_affinity_release;
3870 irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
3871 /* Spread affinity hints out across online CPUs.
3873 * get_cpu_mask returns a static constant mask with
3874 * a permanent lifetime so it's ok to pass to
3875 * irq_set_affinity_hint without making a copy.
3877 cpu = cpumask_local_spread(q_vector->v_idx, -1);
3878 irq_set_affinity_hint(irq_num, get_cpu_mask(cpu));
3881 vsi->irqs_ready = true;
3887 irq_num = pf->msix_entries[base + vector].vector;
3888 irq_set_affinity_notifier(irq_num, NULL);
3889 irq_set_affinity_hint(irq_num, NULL);
3890 free_irq(irq_num, &vsi->q_vectors[vector]);
3896 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3897 * @vsi: the VSI being un-configured
3899 static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
3901 struct i40e_pf *pf = vsi->back;
3902 struct i40e_hw *hw = &pf->hw;
3903 int base = vsi->base_vector;
3906 /* disable interrupt causation from each queue */
3907 for (i = 0; i < vsi->num_queue_pairs; i++) {
3910 val = rd32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx));
3911 val &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
3912 wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), val);
3914 val = rd32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx));
3915 val &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
3916 wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), val);
3918 if (!i40e_enabled_xdp_vsi(vsi))
3920 wr32(hw, I40E_QINT_TQCTL(vsi->xdp_rings[i]->reg_idx), 0);
3923 /* disable each interrupt */
3924 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3925 for (i = vsi->base_vector;
3926 i < (vsi->num_q_vectors + vsi->base_vector); i++)
3927 wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
3930 for (i = 0; i < vsi->num_q_vectors; i++)
3931 synchronize_irq(pf->msix_entries[i + base].vector);
3933 /* Legacy and MSI mode - this stops all interrupt handling */
3934 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
3935 wr32(hw, I40E_PFINT_DYN_CTL0, 0);
3937 synchronize_irq(pf->pdev->irq);
3942 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3943 * @vsi: the VSI being configured
3945 static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
3947 struct i40e_pf *pf = vsi->back;
3950 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3951 for (i = 0; i < vsi->num_q_vectors; i++)
3952 i40e_irq_dynamic_enable(vsi, i);
3954 i40e_irq_dynamic_enable_icr0(pf);
3957 i40e_flush(&pf->hw);
3962 * i40e_free_misc_vector - Free the vector that handles non-queue events
3963 * @pf: board private structure
3965 static void i40e_free_misc_vector(struct i40e_pf *pf)
3968 wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
3969 i40e_flush(&pf->hw);
3971 if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
3972 synchronize_irq(pf->msix_entries[0].vector);
3973 free_irq(pf->msix_entries[0].vector, pf);
3974 clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state);
3979 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3980 * @irq: interrupt number
3981 * @data: pointer to a q_vector
3983 * This is the handler used for all MSI/Legacy interrupts, and deals
3984 * with both queue and non-queue interrupts. This is also used in
3985 * MSIX mode to handle the non-queue interrupts.
3987 static irqreturn_t i40e_intr(int irq, void *data)
3989 struct i40e_pf *pf = (struct i40e_pf *)data;
3990 struct i40e_hw *hw = &pf->hw;
3991 irqreturn_t ret = IRQ_NONE;
3992 u32 icr0, icr0_remaining;
3995 icr0 = rd32(hw, I40E_PFINT_ICR0);
3996 ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
3998 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
3999 if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
4002 /* if interrupt but no bits showing, must be SWINT */
4003 if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
4004 (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
4007 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
4008 (icr0 & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
4009 ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
4010 dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n");
4011 set_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
4014 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
4015 if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
4016 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
4017 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
4019 /* We do not have a way to disarm Queue causes while leaving
4020 * interrupt enabled for all other causes, ideally
4021 * interrupt should be disabled while we are in NAPI but
4022 * this is not a performance path and napi_schedule()
4023 * can deal with rescheduling.
4025 if (!test_bit(__I40E_DOWN, pf->state))
4026 napi_schedule_irqoff(&q_vector->napi);
4029 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
4030 ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
4031 set_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
4032 i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
4035 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
4036 ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
4037 set_bit(__I40E_MDD_EVENT_PENDING, pf->state);
4040 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
4041 /* disable any further VFLR event notifications */
4042 if (test_bit(__I40E_VF_RESETS_DISABLED, pf->state)) {
4043 u32 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
4045 reg &= ~I40E_PFINT_ICR0_VFLR_MASK;
4046 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
4048 ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
4049 set_bit(__I40E_VFLR_EVENT_PENDING, pf->state);
4053 if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
4054 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
4055 set_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
4056 ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
4057 val = rd32(hw, I40E_GLGEN_RSTAT);
4058 val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
4059 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
4060 if (val == I40E_RESET_CORER) {
4062 } else if (val == I40E_RESET_GLOBR) {
4064 } else if (val == I40E_RESET_EMPR) {
4066 set_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state);
4070 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
4071 icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
4072 dev_info(&pf->pdev->dev, "HMC error interrupt\n");
4073 dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
4074 rd32(hw, I40E_PFHMC_ERRORINFO),
4075 rd32(hw, I40E_PFHMC_ERRORDATA));
4078 if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
4079 u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
4081 if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
4082 icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
4083 i40e_ptp_tx_hwtstamp(pf);
4087 /* If a critical error is pending we have no choice but to reset the
4089 * Report and mask out any remaining unexpected interrupts.
4091 icr0_remaining = icr0 & ena_mask;
4092 if (icr0_remaining) {
4093 dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
4095 if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
4096 (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
4097 (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
4098 dev_info(&pf->pdev->dev, "device will be reset\n");
4099 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
4100 i40e_service_event_schedule(pf);
4102 ena_mask &= ~icr0_remaining;
4107 /* re-enable interrupt causes */
4108 wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
4109 if (!test_bit(__I40E_DOWN, pf->state) ||
4110 test_bit(__I40E_RECOVERY_MODE, pf->state)) {
4111 i40e_service_event_schedule(pf);
4112 i40e_irq_dynamic_enable_icr0(pf);
4119 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
4120 * @tx_ring: tx ring to clean
4121 * @budget: how many cleans we're allowed
4123 * Returns true if there's any budget left (e.g. the clean is finished)
4125 static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
4127 struct i40e_vsi *vsi = tx_ring->vsi;
4128 u16 i = tx_ring->next_to_clean;
4129 struct i40e_tx_buffer *tx_buf;
4130 struct i40e_tx_desc *tx_desc;
4132 tx_buf = &tx_ring->tx_bi[i];
4133 tx_desc = I40E_TX_DESC(tx_ring, i);
4134 i -= tx_ring->count;
4137 struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
4139 /* if next_to_watch is not set then there is no work pending */
4143 /* prevent any other reads prior to eop_desc */
4146 /* if the descriptor isn't done, no work yet to do */
4147 if (!(eop_desc->cmd_type_offset_bsz &
4148 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
4151 /* clear next_to_watch to prevent false hangs */
4152 tx_buf->next_to_watch = NULL;
4154 tx_desc->buffer_addr = 0;
4155 tx_desc->cmd_type_offset_bsz = 0;
4156 /* move past filter desc */
4161 i -= tx_ring->count;
4162 tx_buf = tx_ring->tx_bi;
4163 tx_desc = I40E_TX_DESC(tx_ring, 0);
4165 /* unmap skb header data */
4166 dma_unmap_single(tx_ring->dev,
4167 dma_unmap_addr(tx_buf, dma),
4168 dma_unmap_len(tx_buf, len),
4170 if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
4171 kfree(tx_buf->raw_buf);
4173 tx_buf->raw_buf = NULL;
4174 tx_buf->tx_flags = 0;
4175 tx_buf->next_to_watch = NULL;
4176 dma_unmap_len_set(tx_buf, len, 0);
4177 tx_desc->buffer_addr = 0;
4178 tx_desc->cmd_type_offset_bsz = 0;
4180 /* move us past the eop_desc for start of next FD desc */
4185 i -= tx_ring->count;
4186 tx_buf = tx_ring->tx_bi;
4187 tx_desc = I40E_TX_DESC(tx_ring, 0);
4190 /* update budget accounting */
4192 } while (likely(budget));
4194 i += tx_ring->count;
4195 tx_ring->next_to_clean = i;
4197 if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
4198 i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
4204 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
4205 * @irq: interrupt number
4206 * @data: pointer to a q_vector
4208 static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
4210 struct i40e_q_vector *q_vector = data;
4211 struct i40e_vsi *vsi;
4213 if (!q_vector->tx.ring)
4216 vsi = q_vector->tx.ring->vsi;
4217 i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
4223 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
4224 * @vsi: the VSI being configured
4225 * @v_idx: vector index
4226 * @qp_idx: queue pair index
4228 static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
4230 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
4231 struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
4232 struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
4234 tx_ring->q_vector = q_vector;
4235 tx_ring->next = q_vector->tx.ring;
4236 q_vector->tx.ring = tx_ring;
4237 q_vector->tx.count++;
4239 /* Place XDP Tx ring in the same q_vector ring list as regular Tx */
4240 if (i40e_enabled_xdp_vsi(vsi)) {
4241 struct i40e_ring *xdp_ring = vsi->xdp_rings[qp_idx];
4243 xdp_ring->q_vector = q_vector;
4244 xdp_ring->next = q_vector->tx.ring;
4245 q_vector->tx.ring = xdp_ring;
4246 q_vector->tx.count++;
4249 rx_ring->q_vector = q_vector;
4250 rx_ring->next = q_vector->rx.ring;
4251 q_vector->rx.ring = rx_ring;
4252 q_vector->rx.count++;
4256 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
4257 * @vsi: the VSI being configured
4259 * This function maps descriptor rings to the queue-specific vectors
4260 * we were allotted through the MSI-X enabling code. Ideally, we'd have
4261 * one vector per queue pair, but on a constrained vector budget, we
4262 * group the queue pairs as "efficiently" as possible.
4264 static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
4266 int qp_remaining = vsi->num_queue_pairs;
4267 int q_vectors = vsi->num_q_vectors;
4272 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
4273 * group them so there are multiple queues per vector.
4274 * It is also important to go through all the vectors available to be
4275 * sure that if we don't use all the vectors, that the remaining vectors
4276 * are cleared. This is especially important when decreasing the
4277 * number of queues in use.
4279 for (; v_start < q_vectors; v_start++) {
4280 struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
4282 num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
4284 q_vector->num_ringpairs = num_ringpairs;
4285 q_vector->reg_idx = q_vector->v_idx + vsi->base_vector - 1;
4287 q_vector->rx.count = 0;
4288 q_vector->tx.count = 0;
4289 q_vector->rx.ring = NULL;
4290 q_vector->tx.ring = NULL;
4292 while (num_ringpairs--) {
4293 i40e_map_vector_to_qp(vsi, v_start, qp_idx);
4301 * i40e_vsi_request_irq - Request IRQ from the OS
4302 * @vsi: the VSI being configured
4303 * @basename: name for the vector
4305 static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
4307 struct i40e_pf *pf = vsi->back;
4310 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
4311 err = i40e_vsi_request_irq_msix(vsi, basename);
4312 else if (pf->flags & I40E_FLAG_MSI_ENABLED)
4313 err = request_irq(pf->pdev->irq, i40e_intr, 0,
4316 err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
4320 dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
4325 #ifdef CONFIG_NET_POLL_CONTROLLER
4327 * i40e_netpoll - A Polling 'interrupt' handler
4328 * @netdev: network interface device structure
4330 * This is used by netconsole to send skbs without having to re-enable
4331 * interrupts. It's not called while the normal interrupt routine is executing.
4333 static void i40e_netpoll(struct net_device *netdev)
4335 struct i40e_netdev_priv *np = netdev_priv(netdev);
4336 struct i40e_vsi *vsi = np->vsi;
4337 struct i40e_pf *pf = vsi->back;
4340 /* if interface is down do nothing */
4341 if (test_bit(__I40E_VSI_DOWN, vsi->state))
4344 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4345 for (i = 0; i < vsi->num_q_vectors; i++)
4346 i40e_msix_clean_rings(0, vsi->q_vectors[i]);
4348 i40e_intr(pf->pdev->irq, netdev);
4353 #define I40E_QTX_ENA_WAIT_COUNT 50
4356 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
4357 * @pf: the PF being configured
4358 * @pf_q: the PF queue
4359 * @enable: enable or disable state of the queue
4361 * This routine will wait for the given Tx queue of the PF to reach the
4362 * enabled or disabled state.
4363 * Returns -ETIMEDOUT in case of failing to reach the requested state after
4364 * multiple retries; else will return 0 in case of success.
4366 static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
4371 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
4372 tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
4373 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
4376 usleep_range(10, 20);
4378 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
4385 * i40e_control_tx_q - Start or stop a particular Tx queue
4386 * @pf: the PF structure
4387 * @pf_q: the PF queue to configure
4388 * @enable: start or stop the queue
4390 * This function enables or disables a single queue. Note that any delay
4391 * required after the operation is expected to be handled by the caller of
4394 static void i40e_control_tx_q(struct i40e_pf *pf, int pf_q, bool enable)
4396 struct i40e_hw *hw = &pf->hw;
4400 /* warn the TX unit of coming changes */
4401 i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
4403 usleep_range(10, 20);
4405 for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
4406 tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
4407 if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
4408 ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
4410 usleep_range(1000, 2000);
4413 /* Skip if the queue is already in the requested state */
4414 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
4417 /* turn on/off the queue */
4419 wr32(hw, I40E_QTX_HEAD(pf_q), 0);
4420 tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
4422 tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
4425 wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
4429 * i40e_control_wait_tx_q - Start/stop Tx queue and wait for completion
4431 * @pf: the PF structure
4432 * @pf_q: the PF queue to configure
4433 * @is_xdp: true if the queue is used for XDP
4434 * @enable: start or stop the queue
4436 int i40e_control_wait_tx_q(int seid, struct i40e_pf *pf, int pf_q,
4437 bool is_xdp, bool enable)
4441 i40e_control_tx_q(pf, pf_q, enable);
4443 /* wait for the change to finish */
4444 ret = i40e_pf_txq_wait(pf, pf_q, enable);
4446 dev_info(&pf->pdev->dev,
4447 "VSI seid %d %sTx ring %d %sable timeout\n",
4448 seid, (is_xdp ? "XDP " : ""), pf_q,
4449 (enable ? "en" : "dis"));
4456 * i40e_vsi_control_tx - Start or stop a VSI's rings
4457 * @vsi: the VSI being configured
4458 * @enable: start or stop the rings
4460 static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
4462 struct i40e_pf *pf = vsi->back;
4463 int i, pf_q, ret = 0;
4465 pf_q = vsi->base_queue;
4466 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
4467 ret = i40e_control_wait_tx_q(vsi->seid, pf,
4469 false /*is xdp*/, enable);
4473 if (!i40e_enabled_xdp_vsi(vsi))
4476 ret = i40e_control_wait_tx_q(vsi->seid, pf,
4477 pf_q + vsi->alloc_queue_pairs,
4478 true /*is xdp*/, enable);
4486 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
4487 * @pf: the PF being configured
4488 * @pf_q: the PF queue
4489 * @enable: enable or disable state of the queue
4491 * This routine will wait for the given Rx queue of the PF to reach the
4492 * enabled or disabled state.
4493 * Returns -ETIMEDOUT in case of failing to reach the requested state after
4494 * multiple retries; else will return 0 in case of success.
4496 static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
4501 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
4502 rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
4503 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
4506 usleep_range(10, 20);
4508 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
4515 * i40e_control_rx_q - Start or stop a particular Rx queue
4516 * @pf: the PF structure
4517 * @pf_q: the PF queue to configure
4518 * @enable: start or stop the queue
4520 * This function enables or disables a single queue. Note that
4521 * any delay required after the operation is expected to be
4522 * handled by the caller of this function.
4524 static void i40e_control_rx_q(struct i40e_pf *pf, int pf_q, bool enable)
4526 struct i40e_hw *hw = &pf->hw;
4530 for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
4531 rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
4532 if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
4533 ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
4535 usleep_range(1000, 2000);
4538 /* Skip if the queue is already in the requested state */
4539 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
4542 /* turn on/off the queue */
4544 rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
4546 rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
4548 wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
4552 * i40e_control_wait_rx_q
4553 * @pf: the PF structure
4554 * @pf_q: queue being configured
4555 * @enable: start or stop the rings
4557 * This function enables or disables a single queue along with waiting
4558 * for the change to finish. The caller of this function should handle
4559 * the delays needed in the case of disabling queues.
4561 int i40e_control_wait_rx_q(struct i40e_pf *pf, int pf_q, bool enable)
4565 i40e_control_rx_q(pf, pf_q, enable);
4567 /* wait for the change to finish */
4568 ret = i40e_pf_rxq_wait(pf, pf_q, enable);
4576 * i40e_vsi_control_rx - Start or stop a VSI's rings
4577 * @vsi: the VSI being configured
4578 * @enable: start or stop the rings
4580 static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
4582 struct i40e_pf *pf = vsi->back;
4583 int i, pf_q, ret = 0;
4585 pf_q = vsi->base_queue;
4586 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
4587 ret = i40e_control_wait_rx_q(pf, pf_q, enable);
4589 dev_info(&pf->pdev->dev,
4590 "VSI seid %d Rx ring %d %sable timeout\n",
4591 vsi->seid, pf_q, (enable ? "en" : "dis"));
4596 /* Due to HW errata, on Rx disable only, the register can indicate done
4597 * before it really is. Needs 50ms to be sure
4606 * i40e_vsi_start_rings - Start a VSI's rings
4607 * @vsi: the VSI being configured
4609 int i40e_vsi_start_rings(struct i40e_vsi *vsi)
4613 /* do rx first for enable and last for disable */
4614 ret = i40e_vsi_control_rx(vsi, true);
4617 ret = i40e_vsi_control_tx(vsi, true);
4623 * i40e_vsi_stop_rings - Stop a VSI's rings
4624 * @vsi: the VSI being configured
4626 void i40e_vsi_stop_rings(struct i40e_vsi *vsi)
4628 /* When port TX is suspended, don't wait */
4629 if (test_bit(__I40E_PORT_SUSPENDED, vsi->back->state))
4630 return i40e_vsi_stop_rings_no_wait(vsi);
4632 /* do rx first for enable and last for disable
4633 * Ignore return value, we need to shutdown whatever we can
4635 i40e_vsi_control_tx(vsi, false);
4636 i40e_vsi_control_rx(vsi, false);
4640 * i40e_vsi_stop_rings_no_wait - Stop a VSI's rings and do not delay
4641 * @vsi: the VSI being shutdown
4643 * This function stops all the rings for a VSI but does not delay to verify
4644 * that rings have been disabled. It is expected that the caller is shutting
4645 * down multiple VSIs at once and will delay together for all the VSIs after
4646 * initiating the shutdown. This is particularly useful for shutting down lots
4647 * of VFs together. Otherwise, a large delay can be incurred while configuring
4648 * each VSI in serial.
4650 void i40e_vsi_stop_rings_no_wait(struct i40e_vsi *vsi)
4652 struct i40e_pf *pf = vsi->back;
4655 pf_q = vsi->base_queue;
4656 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
4657 i40e_control_tx_q(pf, pf_q, false);
4658 i40e_control_rx_q(pf, pf_q, false);
4663 * i40e_vsi_free_irq - Free the irq association with the OS
4664 * @vsi: the VSI being configured
4666 static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
4668 struct i40e_pf *pf = vsi->back;
4669 struct i40e_hw *hw = &pf->hw;
4670 int base = vsi->base_vector;
4674 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4675 if (!vsi->q_vectors)
4678 if (!vsi->irqs_ready)
4681 vsi->irqs_ready = false;
4682 for (i = 0; i < vsi->num_q_vectors; i++) {
4687 irq_num = pf->msix_entries[vector].vector;
4689 /* free only the irqs that were actually requested */
4690 if (!vsi->q_vectors[i] ||
4691 !vsi->q_vectors[i]->num_ringpairs)
4694 /* clear the affinity notifier in the IRQ descriptor */
4695 irq_set_affinity_notifier(irq_num, NULL);
4696 /* remove our suggested affinity mask for this IRQ */
4697 irq_set_affinity_hint(irq_num, NULL);
4698 synchronize_irq(irq_num);
4699 free_irq(irq_num, vsi->q_vectors[i]);
4701 /* Tear down the interrupt queue link list
4703 * We know that they come in pairs and always
4704 * the Rx first, then the Tx. To clear the
4705 * link list, stick the EOL value into the
4706 * next_q field of the registers.
4708 val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
4709 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
4710 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4711 val |= I40E_QUEUE_END_OF_LIST
4712 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4713 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
4715 while (qp != I40E_QUEUE_END_OF_LIST) {
4718 val = rd32(hw, I40E_QINT_RQCTL(qp));
4720 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4721 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4722 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4723 I40E_QINT_RQCTL_INTEVENT_MASK);
4725 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4726 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4728 wr32(hw, I40E_QINT_RQCTL(qp), val);
4730 val = rd32(hw, I40E_QINT_TQCTL(qp));
4732 next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
4733 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
4735 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4736 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4737 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4738 I40E_QINT_TQCTL_INTEVENT_MASK);
4740 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4741 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4743 wr32(hw, I40E_QINT_TQCTL(qp), val);
4748 free_irq(pf->pdev->irq, pf);
4750 val = rd32(hw, I40E_PFINT_LNKLST0);
4751 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
4752 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4753 val |= I40E_QUEUE_END_OF_LIST
4754 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
4755 wr32(hw, I40E_PFINT_LNKLST0, val);
4757 val = rd32(hw, I40E_QINT_RQCTL(qp));
4758 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4759 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4760 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4761 I40E_QINT_RQCTL_INTEVENT_MASK);
4763 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4764 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4766 wr32(hw, I40E_QINT_RQCTL(qp), val);
4768 val = rd32(hw, I40E_QINT_TQCTL(qp));
4770 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4771 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4772 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4773 I40E_QINT_TQCTL_INTEVENT_MASK);
4775 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4776 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4778 wr32(hw, I40E_QINT_TQCTL(qp), val);
4783 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
4784 * @vsi: the VSI being configured
4785 * @v_idx: Index of vector to be freed
4787 * This function frees the memory allocated to the q_vector. In addition if
4788 * NAPI is enabled it will delete any references to the NAPI struct prior
4789 * to freeing the q_vector.
4791 static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
4793 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
4794 struct i40e_ring *ring;
4799 /* disassociate q_vector from rings */
4800 i40e_for_each_ring(ring, q_vector->tx)
4801 ring->q_vector = NULL;
4803 i40e_for_each_ring(ring, q_vector->rx)
4804 ring->q_vector = NULL;
4806 /* only VSI w/ an associated netdev is set up w/ NAPI */
4808 netif_napi_del(&q_vector->napi);
4810 vsi->q_vectors[v_idx] = NULL;
4812 kfree_rcu(q_vector, rcu);
4816 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
4817 * @vsi: the VSI being un-configured
4819 * This frees the memory allocated to the q_vectors and
4820 * deletes references to the NAPI struct.
4822 static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
4826 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
4827 i40e_free_q_vector(vsi, v_idx);
4831 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
4832 * @pf: board private structure
4834 static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
4836 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
4837 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4838 pci_disable_msix(pf->pdev);
4839 kfree(pf->msix_entries);
4840 pf->msix_entries = NULL;
4841 kfree(pf->irq_pile);
4842 pf->irq_pile = NULL;
4843 } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
4844 pci_disable_msi(pf->pdev);
4846 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
4850 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
4851 * @pf: board private structure
4853 * We go through and clear interrupt specific resources and reset the structure
4854 * to pre-load conditions
4856 static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
4860 i40e_free_misc_vector(pf);
4862 i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
4863 I40E_IWARP_IRQ_PILE_ID);
4865 i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
4866 for (i = 0; i < pf->num_alloc_vsi; i++)
4868 i40e_vsi_free_q_vectors(pf->vsi[i]);
4869 i40e_reset_interrupt_capability(pf);
4873 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
4874 * @vsi: the VSI being configured
4876 static void i40e_napi_enable_all(struct i40e_vsi *vsi)
4883 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
4884 struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
4886 if (q_vector->rx.ring || q_vector->tx.ring)
4887 napi_enable(&q_vector->napi);
4892 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4893 * @vsi: the VSI being configured
4895 static void i40e_napi_disable_all(struct i40e_vsi *vsi)
4902 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
4903 struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
4905 if (q_vector->rx.ring || q_vector->tx.ring)
4906 napi_disable(&q_vector->napi);
4911 * i40e_vsi_close - Shut down a VSI
4912 * @vsi: the vsi to be quelled
4914 static void i40e_vsi_close(struct i40e_vsi *vsi)
4916 struct i40e_pf *pf = vsi->back;
4917 if (!test_and_set_bit(__I40E_VSI_DOWN, vsi->state))
4919 i40e_vsi_free_irq(vsi);
4920 i40e_vsi_free_tx_resources(vsi);
4921 i40e_vsi_free_rx_resources(vsi);
4922 vsi->current_netdev_flags = 0;
4923 set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
4924 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
4925 set_bit(__I40E_CLIENT_RESET, pf->state);
4929 * i40e_quiesce_vsi - Pause a given VSI
4930 * @vsi: the VSI being paused
4932 static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
4934 if (test_bit(__I40E_VSI_DOWN, vsi->state))
4937 set_bit(__I40E_VSI_NEEDS_RESTART, vsi->state);
4938 if (vsi->netdev && netif_running(vsi->netdev))
4939 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
4941 i40e_vsi_close(vsi);
4945 * i40e_unquiesce_vsi - Resume a given VSI
4946 * @vsi: the VSI being resumed
4948 static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
4950 if (!test_and_clear_bit(__I40E_VSI_NEEDS_RESTART, vsi->state))
4953 if (vsi->netdev && netif_running(vsi->netdev))
4954 vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
4956 i40e_vsi_open(vsi); /* this clears the DOWN bit */
4960 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
4963 static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
4967 for (v = 0; v < pf->num_alloc_vsi; v++) {
4969 i40e_quiesce_vsi(pf->vsi[v]);
4974 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
4977 static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
4981 for (v = 0; v < pf->num_alloc_vsi; v++) {
4983 i40e_unquiesce_vsi(pf->vsi[v]);
4988 * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
4989 * @vsi: the VSI being configured
4991 * Wait until all queues on a given VSI have been disabled.
4993 int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
4995 struct i40e_pf *pf = vsi->back;
4998 pf_q = vsi->base_queue;
4999 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
5000 /* Check and wait for the Tx queue */
5001 ret = i40e_pf_txq_wait(pf, pf_q, false);
5003 dev_info(&pf->pdev->dev,
5004 "VSI seid %d Tx ring %d disable timeout\n",
5009 if (!i40e_enabled_xdp_vsi(vsi))
5012 /* Check and wait for the XDP Tx queue */
5013 ret = i40e_pf_txq_wait(pf, pf_q + vsi->alloc_queue_pairs,
5016 dev_info(&pf->pdev->dev,
5017 "VSI seid %d XDP Tx ring %d disable timeout\n",
5022 /* Check and wait for the Rx queue */
5023 ret = i40e_pf_rxq_wait(pf, pf_q, false);
5025 dev_info(&pf->pdev->dev,
5026 "VSI seid %d Rx ring %d disable timeout\n",
5035 #ifdef CONFIG_I40E_DCB
5037 * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
5040 * This function waits for the queues to be in disabled state for all the
5041 * VSIs that are managed by this PF.
5043 static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
5047 for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
5049 ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
5061 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
5062 * @pf: pointer to PF
5064 * Get TC map for ISCSI PF type that will include iSCSI TC
5067 static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
5069 struct i40e_dcb_app_priority_table app;
5070 struct i40e_hw *hw = &pf->hw;
5071 u8 enabled_tc = 1; /* TC0 is always enabled */
5073 /* Get the iSCSI APP TLV */
5074 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
5076 for (i = 0; i < dcbcfg->numapps; i++) {
5077 app = dcbcfg->app[i];
5078 if (app.selector == I40E_APP_SEL_TCPIP &&
5079 app.protocolid == I40E_APP_PROTOID_ISCSI) {
5080 tc = dcbcfg->etscfg.prioritytable[app.priority];
5081 enabled_tc |= BIT(tc);
5090 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
5091 * @dcbcfg: the corresponding DCBx configuration structure
5093 * Return the number of TCs from given DCBx configuration
5095 static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
5097 int i, tc_unused = 0;
5101 /* Scan the ETS Config Priority Table to find
5102 * traffic class enabled for a given priority
5103 * and create a bitmask of enabled TCs
5105 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
5106 num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]);
5108 /* Now scan the bitmask to check for
5109 * contiguous TCs starting with TC0
5111 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5112 if (num_tc & BIT(i)) {
5116 pr_err("Non-contiguous TC - Disabling DCB\n");
5124 /* There is always at least TC0 */
5132 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
5133 * @dcbcfg: the corresponding DCBx configuration structure
5135 * Query the current DCB configuration and return the number of
5136 * traffic classes enabled from the given DCBX config
5138 static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
5140 u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
5144 for (i = 0; i < num_tc; i++)
5145 enabled_tc |= BIT(i);
5151 * i40e_mqprio_get_enabled_tc - Get enabled traffic classes
5152 * @pf: PF being queried
5154 * Query the current MQPRIO configuration and return the number of
5155 * traffic classes enabled.
5157 static u8 i40e_mqprio_get_enabled_tc(struct i40e_pf *pf)
5159 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
5160 u8 num_tc = vsi->mqprio_qopt.qopt.num_tc;
5161 u8 enabled_tc = 1, i;
5163 for (i = 1; i < num_tc; i++)
5164 enabled_tc |= BIT(i);
5169 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
5170 * @pf: PF being queried
5172 * Return number of traffic classes enabled for the given PF
5174 static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
5176 struct i40e_hw *hw = &pf->hw;
5177 u8 i, enabled_tc = 1;
5179 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
5181 if (pf->flags & I40E_FLAG_TC_MQPRIO)
5182 return pf->vsi[pf->lan_vsi]->mqprio_qopt.qopt.num_tc;
5184 /* If neither MQPRIO nor DCB is enabled, then always use single TC */
5185 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
5188 /* SFP mode will be enabled for all TCs on port */
5189 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
5190 return i40e_dcb_get_num_tc(dcbcfg);
5192 /* MFP mode return count of enabled TCs for this PF */
5193 if (pf->hw.func_caps.iscsi)
5194 enabled_tc = i40e_get_iscsi_tc_map(pf);
5196 return 1; /* Only TC0 */
5198 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5199 if (enabled_tc & BIT(i))
5206 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
5207 * @pf: PF being queried
5209 * Return a bitmap for enabled traffic classes for this PF.
5211 static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
5213 if (pf->flags & I40E_FLAG_TC_MQPRIO)
5214 return i40e_mqprio_get_enabled_tc(pf);
5216 /* If neither MQPRIO nor DCB is enabled for this PF then just return
5219 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
5220 return I40E_DEFAULT_TRAFFIC_CLASS;
5222 /* SFP mode we want PF to be enabled for all TCs */
5223 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
5224 return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
5226 /* MFP enabled and iSCSI PF type */
5227 if (pf->hw.func_caps.iscsi)
5228 return i40e_get_iscsi_tc_map(pf);
5230 return I40E_DEFAULT_TRAFFIC_CLASS;
5234 * i40e_vsi_get_bw_info - Query VSI BW Information
5235 * @vsi: the VSI being queried
5237 * Returns 0 on success, negative value on failure
5239 static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
5241 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
5242 struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
5243 struct i40e_pf *pf = vsi->back;
5244 struct i40e_hw *hw = &pf->hw;
5249 /* Get the VSI level BW configuration */
5250 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
5252 dev_info(&pf->pdev->dev,
5253 "couldn't get PF vsi bw config, err %s aq_err %s\n",
5254 i40e_stat_str(&pf->hw, ret),
5255 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
5259 /* Get the VSI level BW configuration per TC */
5260 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
5263 dev_info(&pf->pdev->dev,
5264 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
5265 i40e_stat_str(&pf->hw, ret),
5266 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
5270 if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
5271 dev_info(&pf->pdev->dev,
5272 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
5273 bw_config.tc_valid_bits,
5274 bw_ets_config.tc_valid_bits);
5275 /* Still continuing */
5278 vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
5279 vsi->bw_max_quanta = bw_config.max_bw;
5280 tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
5281 (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
5282 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5283 vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
5284 vsi->bw_ets_limit_credits[i] =
5285 le16_to_cpu(bw_ets_config.credits[i]);
5286 /* 3 bits out of 4 for each TC */
5287 vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
5294 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
5295 * @vsi: the VSI being configured
5296 * @enabled_tc: TC bitmap
5297 * @bw_share: BW shared credits per TC
5299 * Returns 0 on success, negative value on failure
5301 static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
5304 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
5305 struct i40e_pf *pf = vsi->back;
5309 /* There is no need to reset BW when mqprio mode is on. */
5310 if (pf->flags & I40E_FLAG_TC_MQPRIO)
5312 if (!vsi->mqprio_qopt.qopt.hw && !(pf->flags & I40E_FLAG_DCB_ENABLED)) {
5313 ret = i40e_set_bw_limit(vsi, vsi->seid, 0);
5315 dev_info(&pf->pdev->dev,
5316 "Failed to reset tx rate for vsi->seid %u\n",
5320 memset(&bw_data, 0, sizeof(bw_data));
5321 bw_data.tc_valid_bits = enabled_tc;
5322 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5323 bw_data.tc_bw_credits[i] = bw_share[i];
5325 ret = i40e_aq_config_vsi_tc_bw(&pf->hw, vsi->seid, &bw_data, NULL);
5327 dev_info(&pf->pdev->dev,
5328 "AQ command Config VSI BW allocation per TC failed = %d\n",
5329 pf->hw.aq.asq_last_status);
5333 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5334 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
5340 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
5341 * @vsi: the VSI being configured
5342 * @enabled_tc: TC map to be enabled
5345 static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
5347 struct net_device *netdev = vsi->netdev;
5348 struct i40e_pf *pf = vsi->back;
5349 struct i40e_hw *hw = &pf->hw;
5352 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
5358 netdev_reset_tc(netdev);
5362 /* Set up actual enabled TCs on the VSI */
5363 if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
5366 /* set per TC queues for the VSI */
5367 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5368 /* Only set TC queues for enabled tcs
5370 * e.g. For a VSI that has TC0 and TC3 enabled the
5371 * enabled_tc bitmap would be 0x00001001; the driver
5372 * will set the numtc for netdev as 2 that will be
5373 * referenced by the netdev layer as TC 0 and 1.
5375 if (vsi->tc_config.enabled_tc & BIT(i))
5376 netdev_set_tc_queue(netdev,
5377 vsi->tc_config.tc_info[i].netdev_tc,
5378 vsi->tc_config.tc_info[i].qcount,
5379 vsi->tc_config.tc_info[i].qoffset);
5382 if (pf->flags & I40E_FLAG_TC_MQPRIO)
5385 /* Assign UP2TC map for the VSI */
5386 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
5387 /* Get the actual TC# for the UP */
5388 u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
5389 /* Get the mapped netdev TC# for the UP */
5390 netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
5391 netdev_set_prio_tc_map(netdev, i, netdev_tc);
5396 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
5397 * @vsi: the VSI being configured
5398 * @ctxt: the ctxt buffer returned from AQ VSI update param command
5400 static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
5401 struct i40e_vsi_context *ctxt)
5403 /* copy just the sections touched not the entire info
5404 * since not all sections are valid as returned by
5407 vsi->info.mapping_flags = ctxt->info.mapping_flags;
5408 memcpy(&vsi->info.queue_mapping,
5409 &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
5410 memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
5411 sizeof(vsi->info.tc_mapping));
5415 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
5416 * @vsi: VSI to be configured
5417 * @enabled_tc: TC bitmap
5419 * This configures a particular VSI for TCs that are mapped to the
5420 * given TC bitmap. It uses default bandwidth share for TCs across
5421 * VSIs to configure TC for a particular VSI.
5424 * It is expected that the VSI queues have been quisced before calling
5427 static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
5429 u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
5430 struct i40e_pf *pf = vsi->back;
5431 struct i40e_hw *hw = &pf->hw;
5432 struct i40e_vsi_context ctxt;
5436 /* Check if enabled_tc is same as existing or new TCs */
5437 if (vsi->tc_config.enabled_tc == enabled_tc &&
5438 vsi->mqprio_qopt.mode != TC_MQPRIO_MODE_CHANNEL)
5441 /* Enable ETS TCs with equal BW Share for now across all VSIs */
5442 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5443 if (enabled_tc & BIT(i))
5447 ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
5449 struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
5451 dev_info(&pf->pdev->dev,
5452 "Failed configuring TC map %d for VSI %d\n",
5453 enabled_tc, vsi->seid);
5454 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid,
5457 dev_info(&pf->pdev->dev,
5458 "Failed querying vsi bw info, err %s aq_err %s\n",
5459 i40e_stat_str(hw, ret),
5460 i40e_aq_str(hw, hw->aq.asq_last_status));
5463 if ((bw_config.tc_valid_bits & enabled_tc) != enabled_tc) {
5464 u8 valid_tc = bw_config.tc_valid_bits & enabled_tc;
5467 valid_tc = bw_config.tc_valid_bits;
5468 /* Always enable TC0, no matter what */
5470 dev_info(&pf->pdev->dev,
5471 "Requested tc 0x%x, but FW reports 0x%x as valid. Attempting to use 0x%x.\n",
5472 enabled_tc, bw_config.tc_valid_bits, valid_tc);
5473 enabled_tc = valid_tc;
5476 ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
5478 dev_err(&pf->pdev->dev,
5479 "Unable to configure TC map %d for VSI %d\n",
5480 enabled_tc, vsi->seid);
5485 /* Update Queue Pairs Mapping for currently enabled UPs */
5486 ctxt.seid = vsi->seid;
5487 ctxt.pf_num = vsi->back->hw.pf_id;
5489 ctxt.uplink_seid = vsi->uplink_seid;
5490 ctxt.info = vsi->info;
5491 if (vsi->back->flags & I40E_FLAG_TC_MQPRIO) {
5492 ret = i40e_vsi_setup_queue_map_mqprio(vsi, &ctxt, enabled_tc);
5496 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
5499 /* On destroying the qdisc, reset vsi->rss_size, as number of enabled
5502 if (!vsi->mqprio_qopt.qopt.hw && vsi->reconfig_rss) {
5503 vsi->rss_size = min_t(int, vsi->back->alloc_rss_size,
5504 vsi->num_queue_pairs);
5505 ret = i40e_vsi_config_rss(vsi);
5507 dev_info(&vsi->back->pdev->dev,
5508 "Failed to reconfig rss for num_queues\n");
5511 vsi->reconfig_rss = false;
5513 if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
5514 ctxt.info.valid_sections |=
5515 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
5516 ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
5519 /* Update the VSI after updating the VSI queue-mapping
5522 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5524 dev_info(&pf->pdev->dev,
5525 "Update vsi tc config failed, err %s aq_err %s\n",
5526 i40e_stat_str(hw, ret),
5527 i40e_aq_str(hw, hw->aq.asq_last_status));
5530 /* update the local VSI info with updated queue map */
5531 i40e_vsi_update_queue_map(vsi, &ctxt);
5532 vsi->info.valid_sections = 0;
5534 /* Update current VSI BW information */
5535 ret = i40e_vsi_get_bw_info(vsi);
5537 dev_info(&pf->pdev->dev,
5538 "Failed updating vsi bw info, err %s aq_err %s\n",
5539 i40e_stat_str(hw, ret),
5540 i40e_aq_str(hw, hw->aq.asq_last_status));
5544 /* Update the netdev TC setup */
5545 i40e_vsi_config_netdev_tc(vsi, enabled_tc);
5551 * i40e_get_link_speed - Returns link speed for the interface
5552 * @vsi: VSI to be configured
5555 static int i40e_get_link_speed(struct i40e_vsi *vsi)
5557 struct i40e_pf *pf = vsi->back;
5559 switch (pf->hw.phy.link_info.link_speed) {
5560 case I40E_LINK_SPEED_40GB:
5562 case I40E_LINK_SPEED_25GB:
5564 case I40E_LINK_SPEED_20GB:
5566 case I40E_LINK_SPEED_10GB:
5568 case I40E_LINK_SPEED_1GB:
5576 * i40e_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate
5577 * @vsi: VSI to be configured
5578 * @seid: seid of the channel/VSI
5579 * @max_tx_rate: max TX rate to be configured as BW limit
5581 * Helper function to set BW limit for a given VSI
5583 int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate)
5585 struct i40e_pf *pf = vsi->back;
5590 speed = i40e_get_link_speed(vsi);
5591 if (max_tx_rate > speed) {
5592 dev_err(&pf->pdev->dev,
5593 "Invalid max tx rate %llu specified for VSI seid %d.",
5597 if (max_tx_rate && max_tx_rate < 50) {
5598 dev_warn(&pf->pdev->dev,
5599 "Setting max tx rate to minimum usable value of 50Mbps.\n");
5603 /* Tx rate credits are in values of 50Mbps, 0 is disabled */
5604 credits = max_tx_rate;
5605 do_div(credits, I40E_BW_CREDIT_DIVISOR);
5606 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, seid, credits,
5607 I40E_MAX_BW_INACTIVE_ACCUM, NULL);
5609 dev_err(&pf->pdev->dev,
5610 "Failed set tx rate (%llu Mbps) for vsi->seid %u, err %s aq_err %s\n",
5611 max_tx_rate, seid, i40e_stat_str(&pf->hw, ret),
5612 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
5617 * i40e_remove_queue_channels - Remove queue channels for the TCs
5618 * @vsi: VSI to be configured
5620 * Remove queue channels for the TCs
5622 static void i40e_remove_queue_channels(struct i40e_vsi *vsi)
5624 enum i40e_admin_queue_err last_aq_status;
5625 struct i40e_cloud_filter *cfilter;
5626 struct i40e_channel *ch, *ch_tmp;
5627 struct i40e_pf *pf = vsi->back;
5628 struct hlist_node *node;
5631 /* Reset rss size that was stored when reconfiguring rss for
5632 * channel VSIs with non-power-of-2 queue count.
5634 vsi->current_rss_size = 0;
5636 /* perform cleanup for channels if they exist */
5637 if (list_empty(&vsi->ch_list))
5640 list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
5641 struct i40e_vsi *p_vsi;
5643 list_del(&ch->list);
5644 p_vsi = ch->parent_vsi;
5645 if (!p_vsi || !ch->initialized) {
5649 /* Reset queue contexts */
5650 for (i = 0; i < ch->num_queue_pairs; i++) {
5651 struct i40e_ring *tx_ring, *rx_ring;
5654 pf_q = ch->base_queue + i;
5655 tx_ring = vsi->tx_rings[pf_q];
5658 rx_ring = vsi->rx_rings[pf_q];
5662 /* Reset BW configured for this VSI via mqprio */
5663 ret = i40e_set_bw_limit(vsi, ch->seid, 0);
5665 dev_info(&vsi->back->pdev->dev,
5666 "Failed to reset tx rate for ch->seid %u\n",
5669 /* delete cloud filters associated with this channel */
5670 hlist_for_each_entry_safe(cfilter, node,
5671 &pf->cloud_filter_list, cloud_node) {
5672 if (cfilter->seid != ch->seid)
5675 hash_del(&cfilter->cloud_node);
5676 if (cfilter->dst_port)
5677 ret = i40e_add_del_cloud_filter_big_buf(vsi,
5681 ret = i40e_add_del_cloud_filter(vsi, cfilter,
5683 last_aq_status = pf->hw.aq.asq_last_status;
5685 dev_info(&pf->pdev->dev,
5686 "Failed to delete cloud filter, err %s aq_err %s\n",
5687 i40e_stat_str(&pf->hw, ret),
5688 i40e_aq_str(&pf->hw, last_aq_status));
5692 /* delete VSI from FW */
5693 ret = i40e_aq_delete_element(&vsi->back->hw, ch->seid,
5696 dev_err(&vsi->back->pdev->dev,
5697 "unable to remove channel (%d) for parent VSI(%d)\n",
5698 ch->seid, p_vsi->seid);
5701 INIT_LIST_HEAD(&vsi->ch_list);
5705 * i40e_is_any_channel - channel exist or not
5706 * @vsi: ptr to VSI to which channels are associated with
5708 * Returns true or false if channel(s) exist for associated VSI or not
5710 static bool i40e_is_any_channel(struct i40e_vsi *vsi)
5712 struct i40e_channel *ch, *ch_tmp;
5714 list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
5715 if (ch->initialized)
5723 * i40e_get_max_queues_for_channel
5724 * @vsi: ptr to VSI to which channels are associated with
5726 * Helper function which returns max value among the queue counts set on the
5727 * channels/TCs created.
5729 static int i40e_get_max_queues_for_channel(struct i40e_vsi *vsi)
5731 struct i40e_channel *ch, *ch_tmp;
5734 list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
5735 if (!ch->initialized)
5737 if (ch->num_queue_pairs > max)
5738 max = ch->num_queue_pairs;
5745 * i40e_validate_num_queues - validate num_queues w.r.t channel
5746 * @pf: ptr to PF device
5747 * @num_queues: number of queues
5748 * @vsi: the parent VSI
5749 * @reconfig_rss: indicates should the RSS be reconfigured or not
5751 * This function validates number of queues in the context of new channel
5752 * which is being established and determines if RSS should be reconfigured
5753 * or not for parent VSI.
5755 static int i40e_validate_num_queues(struct i40e_pf *pf, int num_queues,
5756 struct i40e_vsi *vsi, bool *reconfig_rss)
5763 *reconfig_rss = false;
5764 if (vsi->current_rss_size) {
5765 if (num_queues > vsi->current_rss_size) {
5766 dev_dbg(&pf->pdev->dev,
5767 "Error: num_queues (%d) > vsi's current_size(%d)\n",
5768 num_queues, vsi->current_rss_size);
5770 } else if ((num_queues < vsi->current_rss_size) &&
5771 (!is_power_of_2(num_queues))) {
5772 dev_dbg(&pf->pdev->dev,
5773 "Error: num_queues (%d) < vsi's current_size(%d), but not power of 2\n",
5774 num_queues, vsi->current_rss_size);
5779 if (!is_power_of_2(num_queues)) {
5780 /* Find the max num_queues configured for channel if channel
5782 * if channel exist, then enforce 'num_queues' to be more than
5783 * max ever queues configured for channel.
5785 max_ch_queues = i40e_get_max_queues_for_channel(vsi);
5786 if (num_queues < max_ch_queues) {
5787 dev_dbg(&pf->pdev->dev,
5788 "Error: num_queues (%d) < max queues configured for channel(%d)\n",
5789 num_queues, max_ch_queues);
5792 *reconfig_rss = true;
5799 * i40e_vsi_reconfig_rss - reconfig RSS based on specified rss_size
5800 * @vsi: the VSI being setup
5801 * @rss_size: size of RSS, accordingly LUT gets reprogrammed
5803 * This function reconfigures RSS by reprogramming LUTs using 'rss_size'
5805 static int i40e_vsi_reconfig_rss(struct i40e_vsi *vsi, u16 rss_size)
5807 struct i40e_pf *pf = vsi->back;
5808 u8 seed[I40E_HKEY_ARRAY_SIZE];
5809 struct i40e_hw *hw = &pf->hw;
5817 if (rss_size > vsi->rss_size)
5820 local_rss_size = min_t(int, vsi->rss_size, rss_size);
5821 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
5825 /* Ignoring user configured lut if there is one */
5826 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, local_rss_size);
5828 /* Use user configured hash key if there is one, otherwise
5831 if (vsi->rss_hkey_user)
5832 memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
5834 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
5836 ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
5838 dev_info(&pf->pdev->dev,
5839 "Cannot set RSS lut, err %s aq_err %s\n",
5840 i40e_stat_str(hw, ret),
5841 i40e_aq_str(hw, hw->aq.asq_last_status));
5847 /* Do the update w.r.t. storing rss_size */
5848 if (!vsi->orig_rss_size)
5849 vsi->orig_rss_size = vsi->rss_size;
5850 vsi->current_rss_size = local_rss_size;
5856 * i40e_channel_setup_queue_map - Setup a channel queue map
5857 * @pf: ptr to PF device
5858 * @ctxt: VSI context structure
5859 * @ch: ptr to channel structure
5861 * Setup queue map for a specific channel
5863 static void i40e_channel_setup_queue_map(struct i40e_pf *pf,
5864 struct i40e_vsi_context *ctxt,
5865 struct i40e_channel *ch)
5867 u16 qcount, qmap, sections = 0;
5871 sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
5872 sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
5874 qcount = min_t(int, ch->num_queue_pairs, pf->num_lan_msix);
5875 ch->num_queue_pairs = qcount;
5877 /* find the next higher power-of-2 of num queue pairs */
5878 pow = ilog2(qcount);
5879 if (!is_power_of_2(qcount))
5882 qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
5883 (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
5885 /* Setup queue TC[0].qmap for given VSI context */
5886 ctxt->info.tc_mapping[0] = cpu_to_le16(qmap);
5888 ctxt->info.up_enable_bits = 0x1; /* TC0 enabled */
5889 ctxt->info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
5890 ctxt->info.queue_mapping[0] = cpu_to_le16(ch->base_queue);
5891 ctxt->info.valid_sections |= cpu_to_le16(sections);
5895 * i40e_add_channel - add a channel by adding VSI
5896 * @pf: ptr to PF device
5897 * @uplink_seid: underlying HW switching element (VEB) ID
5898 * @ch: ptr to channel structure
5900 * Add a channel (VSI) using add_vsi and queue_map
5902 static int i40e_add_channel(struct i40e_pf *pf, u16 uplink_seid,
5903 struct i40e_channel *ch)
5905 struct i40e_hw *hw = &pf->hw;
5906 struct i40e_vsi_context ctxt;
5907 u8 enabled_tc = 0x1; /* TC0 enabled */
5910 if (ch->type != I40E_VSI_VMDQ2) {
5911 dev_info(&pf->pdev->dev,
5912 "add new vsi failed, ch->type %d\n", ch->type);
5916 memset(&ctxt, 0, sizeof(ctxt));
5917 ctxt.pf_num = hw->pf_id;
5919 ctxt.uplink_seid = uplink_seid;
5920 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
5921 if (ch->type == I40E_VSI_VMDQ2)
5922 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
5924 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) {
5925 ctxt.info.valid_sections |=
5926 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5927 ctxt.info.switch_id =
5928 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5931 /* Set queue map for a given VSI context */
5932 i40e_channel_setup_queue_map(pf, &ctxt, ch);
5934 /* Now time to create VSI */
5935 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
5937 dev_info(&pf->pdev->dev,
5938 "add new vsi failed, err %s aq_err %s\n",
5939 i40e_stat_str(&pf->hw, ret),
5940 i40e_aq_str(&pf->hw,
5941 pf->hw.aq.asq_last_status));
5945 /* Success, update channel, set enabled_tc only if the channel
5948 ch->enabled_tc = !i40e_is_channel_macvlan(ch) && enabled_tc;
5949 ch->seid = ctxt.seid;
5950 ch->vsi_number = ctxt.vsi_number;
5951 ch->stat_counter_idx = le16_to_cpu(ctxt.info.stat_counter_idx);
5953 /* copy just the sections touched not the entire info
5954 * since not all sections are valid as returned by
5957 ch->info.mapping_flags = ctxt.info.mapping_flags;
5958 memcpy(&ch->info.queue_mapping,
5959 &ctxt.info.queue_mapping, sizeof(ctxt.info.queue_mapping));
5960 memcpy(&ch->info.tc_mapping, ctxt.info.tc_mapping,
5961 sizeof(ctxt.info.tc_mapping));
5966 static int i40e_channel_config_bw(struct i40e_vsi *vsi, struct i40e_channel *ch,
5969 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
5973 memset(&bw_data, 0, sizeof(bw_data));
5974 bw_data.tc_valid_bits = ch->enabled_tc;
5975 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5976 bw_data.tc_bw_credits[i] = bw_share[i];
5978 ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, ch->seid,
5981 dev_info(&vsi->back->pdev->dev,
5982 "Config VSI BW allocation per TC failed, aq_err: %d for new_vsi->seid %u\n",
5983 vsi->back->hw.aq.asq_last_status, ch->seid);
5987 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5988 ch->info.qs_handle[i] = bw_data.qs_handles[i];
5994 * i40e_channel_config_tx_ring - config TX ring associated with new channel
5995 * @pf: ptr to PF device
5996 * @vsi: the VSI being setup
5997 * @ch: ptr to channel structure
5999 * Configure TX rings associated with channel (VSI) since queues are being
6002 static int i40e_channel_config_tx_ring(struct i40e_pf *pf,
6003 struct i40e_vsi *vsi,
6004 struct i40e_channel *ch)
6008 u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
6010 /* Enable ETS TCs with equal BW Share for now across all VSIs */
6011 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
6012 if (ch->enabled_tc & BIT(i))
6016 /* configure BW for new VSI */
6017 ret = i40e_channel_config_bw(vsi, ch, bw_share);
6019 dev_info(&vsi->back->pdev->dev,
6020 "Failed configuring TC map %d for channel (seid %u)\n",
6021 ch->enabled_tc, ch->seid);
6025 for (i = 0; i < ch->num_queue_pairs; i++) {
6026 struct i40e_ring *tx_ring, *rx_ring;
6029 pf_q = ch->base_queue + i;
6031 /* Get to TX ring ptr of main VSI, for re-setup TX queue
6034 tx_ring = vsi->tx_rings[pf_q];
6037 /* Get the RX ring ptr */
6038 rx_ring = vsi->rx_rings[pf_q];
6046 * i40e_setup_hw_channel - setup new channel
6047 * @pf: ptr to PF device
6048 * @vsi: the VSI being setup
6049 * @ch: ptr to channel structure
6050 * @uplink_seid: underlying HW switching element (VEB) ID
6051 * @type: type of channel to be created (VMDq2/VF)
6053 * Setup new channel (VSI) based on specified type (VMDq2/VF)
6054 * and configures TX rings accordingly
6056 static inline int i40e_setup_hw_channel(struct i40e_pf *pf,
6057 struct i40e_vsi *vsi,
6058 struct i40e_channel *ch,
6059 u16 uplink_seid, u8 type)
6063 ch->initialized = false;
6064 ch->base_queue = vsi->next_base_queue;
6067 /* Proceed with creation of channel (VMDq2) VSI */
6068 ret = i40e_add_channel(pf, uplink_seid, ch);
6070 dev_info(&pf->pdev->dev,
6071 "failed to add_channel using uplink_seid %u\n",
6076 /* Mark the successful creation of channel */
6077 ch->initialized = true;
6079 /* Reconfigure TX queues using QTX_CTL register */
6080 ret = i40e_channel_config_tx_ring(pf, vsi, ch);
6082 dev_info(&pf->pdev->dev,
6083 "failed to configure TX rings for channel %u\n",
6088 /* update 'next_base_queue' */
6089 vsi->next_base_queue = vsi->next_base_queue + ch->num_queue_pairs;
6090 dev_dbg(&pf->pdev->dev,
6091 "Added channel: vsi_seid %u, vsi_number %u, stat_counter_idx %u, num_queue_pairs %u, pf->next_base_queue %d\n",
6092 ch->seid, ch->vsi_number, ch->stat_counter_idx,
6093 ch->num_queue_pairs,
6094 vsi->next_base_queue);
6099 * i40e_setup_channel - setup new channel using uplink element
6100 * @pf: ptr to PF device
6101 * @vsi: pointer to the VSI to set up the channel within
6102 * @ch: ptr to channel structure
6104 * Setup new channel (VSI) based on specified type (VMDq2/VF)
6105 * and uplink switching element (uplink_seid)
6107 static bool i40e_setup_channel(struct i40e_pf *pf, struct i40e_vsi *vsi,
6108 struct i40e_channel *ch)
6114 if (vsi->type == I40E_VSI_MAIN) {
6115 vsi_type = I40E_VSI_VMDQ2;
6117 dev_err(&pf->pdev->dev, "unsupported parent vsi type(%d)\n",
6122 /* underlying switching element */
6123 seid = pf->vsi[pf->lan_vsi]->uplink_seid;
6125 /* create channel (VSI), configure TX rings */
6126 ret = i40e_setup_hw_channel(pf, vsi, ch, seid, vsi_type);
6128 dev_err(&pf->pdev->dev, "failed to setup hw_channel\n");
6132 return ch->initialized ? true : false;
6136 * i40e_validate_and_set_switch_mode - sets up switch mode correctly
6137 * @vsi: ptr to VSI which has PF backing
6139 * Sets up switch mode correctly if it needs to be changed and perform
6140 * what are allowed modes.
6142 static int i40e_validate_and_set_switch_mode(struct i40e_vsi *vsi)
6145 struct i40e_pf *pf = vsi->back;
6146 struct i40e_hw *hw = &pf->hw;
6149 ret = i40e_get_capabilities(pf, i40e_aqc_opc_list_dev_capabilities);
6153 if (hw->dev_caps.switch_mode) {
6154 /* if switch mode is set, support mode2 (non-tunneled for
6155 * cloud filter) for now
6157 u32 switch_mode = hw->dev_caps.switch_mode &
6158 I40E_SWITCH_MODE_MASK;
6159 if (switch_mode >= I40E_CLOUD_FILTER_MODE1) {
6160 if (switch_mode == I40E_CLOUD_FILTER_MODE2)
6162 dev_err(&pf->pdev->dev,
6163 "Invalid switch_mode (%d), only non-tunneled mode for cloud filter is supported\n",
6164 hw->dev_caps.switch_mode);
6169 /* Set Bit 7 to be valid */
6170 mode = I40E_AQ_SET_SWITCH_BIT7_VALID;
6172 /* Set L4type for TCP support */
6173 mode |= I40E_AQ_SET_SWITCH_L4_TYPE_TCP;
6175 /* Set cloud filter mode */
6176 mode |= I40E_AQ_SET_SWITCH_MODE_NON_TUNNEL;
6178 /* Prep mode field for set_switch_config */
6179 ret = i40e_aq_set_switch_config(hw, pf->last_sw_conf_flags,
6180 pf->last_sw_conf_valid_flags,
6182 if (ret && hw->aq.asq_last_status != I40E_AQ_RC_ESRCH)
6183 dev_err(&pf->pdev->dev,
6184 "couldn't set switch config bits, err %s aq_err %s\n",
6185 i40e_stat_str(hw, ret),
6187 hw->aq.asq_last_status));
6193 * i40e_create_queue_channel - function to create channel
6194 * @vsi: VSI to be configured
6195 * @ch: ptr to channel (it contains channel specific params)
6197 * This function creates channel (VSI) using num_queues specified by user,
6198 * reconfigs RSS if needed.
6200 int i40e_create_queue_channel(struct i40e_vsi *vsi,
6201 struct i40e_channel *ch)
6203 struct i40e_pf *pf = vsi->back;
6210 if (!ch->num_queue_pairs) {
6211 dev_err(&pf->pdev->dev, "Invalid num_queues requested: %d\n",
6212 ch->num_queue_pairs);
6216 /* validate user requested num_queues for channel */
6217 err = i40e_validate_num_queues(pf, ch->num_queue_pairs, vsi,
6220 dev_info(&pf->pdev->dev, "Failed to validate num_queues (%d)\n",
6221 ch->num_queue_pairs);
6225 /* By default we are in VEPA mode, if this is the first VF/VMDq
6226 * VSI to be added switch to VEB mode.
6228 if ((!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) ||
6229 (!i40e_is_any_channel(vsi))) {
6230 if (!is_power_of_2(vsi->tc_config.tc_info[0].qcount)) {
6231 dev_dbg(&pf->pdev->dev,
6232 "Failed to create channel. Override queues (%u) not power of 2\n",
6233 vsi->tc_config.tc_info[0].qcount);
6237 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
6238 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
6240 if (vsi->type == I40E_VSI_MAIN) {
6241 if (pf->flags & I40E_FLAG_TC_MQPRIO)
6242 i40e_do_reset(pf, I40E_PF_RESET_FLAG,
6245 i40e_do_reset_safe(pf,
6246 I40E_PF_RESET_FLAG);
6249 /* now onwards for main VSI, number of queues will be value
6250 * of TC0's queue count
6254 /* By this time, vsi->cnt_q_avail shall be set to non-zero and
6255 * it should be more than num_queues
6257 if (!vsi->cnt_q_avail || vsi->cnt_q_avail < ch->num_queue_pairs) {
6258 dev_dbg(&pf->pdev->dev,
6259 "Error: cnt_q_avail (%u) less than num_queues %d\n",
6260 vsi->cnt_q_avail, ch->num_queue_pairs);
6264 /* reconfig_rss only if vsi type is MAIN_VSI */
6265 if (reconfig_rss && (vsi->type == I40E_VSI_MAIN)) {
6266 err = i40e_vsi_reconfig_rss(vsi, ch->num_queue_pairs);
6268 dev_info(&pf->pdev->dev,
6269 "Error: unable to reconfig rss for num_queues (%u)\n",
6270 ch->num_queue_pairs);
6275 if (!i40e_setup_channel(pf, vsi, ch)) {
6276 dev_info(&pf->pdev->dev, "Failed to setup channel\n");
6280 dev_info(&pf->pdev->dev,
6281 "Setup channel (id:%u) utilizing num_queues %d\n",
6282 ch->seid, ch->num_queue_pairs);
6284 /* configure VSI for BW limit */
6285 if (ch->max_tx_rate) {
6286 u64 credits = ch->max_tx_rate;
6288 if (i40e_set_bw_limit(vsi, ch->seid, ch->max_tx_rate))
6291 do_div(credits, I40E_BW_CREDIT_DIVISOR);
6292 dev_dbg(&pf->pdev->dev,
6293 "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
6299 /* in case of VF, this will be main SRIOV VSI */
6300 ch->parent_vsi = vsi;
6302 /* and update main_vsi's count for queue_available to use */
6303 vsi->cnt_q_avail -= ch->num_queue_pairs;
6309 * i40e_configure_queue_channels - Add queue channel for the given TCs
6310 * @vsi: VSI to be configured
6312 * Configures queue channel mapping to the given TCs
6314 static int i40e_configure_queue_channels(struct i40e_vsi *vsi)
6316 struct i40e_channel *ch;
6320 /* Create app vsi with the TCs. Main VSI with TC0 is already set up */
6321 vsi->tc_seid_map[0] = vsi->seid;
6322 for (i = 1; i < I40E_MAX_TRAFFIC_CLASS; i++) {
6323 if (vsi->tc_config.enabled_tc & BIT(i)) {
6324 ch = kzalloc(sizeof(*ch), GFP_KERNEL);
6330 INIT_LIST_HEAD(&ch->list);
6331 ch->num_queue_pairs =
6332 vsi->tc_config.tc_info[i].qcount;
6334 vsi->tc_config.tc_info[i].qoffset;
6336 /* Bandwidth limit through tc interface is in bytes/s,
6339 max_rate = vsi->mqprio_qopt.max_rate[i];
6340 do_div(max_rate, I40E_BW_MBPS_DIVISOR);
6341 ch->max_tx_rate = max_rate;
6343 list_add_tail(&ch->list, &vsi->ch_list);
6345 ret = i40e_create_queue_channel(vsi, ch);
6347 dev_err(&vsi->back->pdev->dev,
6348 "Failed creating queue channel with TC%d: queues %d\n",
6349 i, ch->num_queue_pairs);
6352 vsi->tc_seid_map[i] = ch->seid;
6358 i40e_remove_queue_channels(vsi);
6363 * i40e_veb_config_tc - Configure TCs for given VEB
6365 * @enabled_tc: TC bitmap
6367 * Configures given TC bitmap for VEB (switching) element
6369 int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
6371 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
6372 struct i40e_pf *pf = veb->pf;
6376 /* No TCs or already enabled TCs just return */
6377 if (!enabled_tc || veb->enabled_tc == enabled_tc)
6380 bw_data.tc_valid_bits = enabled_tc;
6381 /* bw_data.absolute_credits is not set (relative) */
6383 /* Enable ETS TCs with equal BW Share for now */
6384 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
6385 if (enabled_tc & BIT(i))
6386 bw_data.tc_bw_share_credits[i] = 1;
6389 ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
6392 dev_info(&pf->pdev->dev,
6393 "VEB bw config failed, err %s aq_err %s\n",
6394 i40e_stat_str(&pf->hw, ret),
6395 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6399 /* Update the BW information */
6400 ret = i40e_veb_get_bw_info(veb);
6402 dev_info(&pf->pdev->dev,
6403 "Failed getting veb bw config, err %s aq_err %s\n",
6404 i40e_stat_str(&pf->hw, ret),
6405 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6412 #ifdef CONFIG_I40E_DCB
6414 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
6417 * Reconfigure VEB/VSIs on a given PF; it is assumed that
6418 * the caller would've quiesce all the VSIs before calling
6421 static void i40e_dcb_reconfigure(struct i40e_pf *pf)
6427 /* Enable the TCs available on PF to all VEBs */
6428 tc_map = i40e_pf_get_tc_map(pf);
6429 if (tc_map == I40E_DEFAULT_TRAFFIC_CLASS)
6432 for (v = 0; v < I40E_MAX_VEB; v++) {
6435 ret = i40e_veb_config_tc(pf->veb[v], tc_map);
6437 dev_info(&pf->pdev->dev,
6438 "Failed configuring TC for VEB seid=%d\n",
6440 /* Will try to configure as many components */
6444 /* Update each VSI */
6445 for (v = 0; v < pf->num_alloc_vsi; v++) {
6449 /* - Enable all TCs for the LAN VSI
6450 * - For all others keep them at TC0 for now
6452 if (v == pf->lan_vsi)
6453 tc_map = i40e_pf_get_tc_map(pf);
6455 tc_map = I40E_DEFAULT_TRAFFIC_CLASS;
6457 ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
6459 dev_info(&pf->pdev->dev,
6460 "Failed configuring TC for VSI seid=%d\n",
6462 /* Will try to configure as many components */
6464 /* Re-configure VSI vectors based on updated TC map */
6465 i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
6466 if (pf->vsi[v]->netdev)
6467 i40e_dcbnl_set_all(pf->vsi[v]);
6473 * i40e_resume_port_tx - Resume port Tx
6476 * Resume a port's Tx and issue a PF reset in case of failure to
6479 static int i40e_resume_port_tx(struct i40e_pf *pf)
6481 struct i40e_hw *hw = &pf->hw;
6484 ret = i40e_aq_resume_port_tx(hw, NULL);
6486 dev_info(&pf->pdev->dev,
6487 "Resume Port Tx failed, err %s aq_err %s\n",
6488 i40e_stat_str(&pf->hw, ret),
6489 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6490 /* Schedule PF reset to recover */
6491 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
6492 i40e_service_event_schedule(pf);
6499 * i40e_suspend_port_tx - Suspend port Tx
6502 * Suspend a port's Tx and issue a PF reset in case of failure.
6504 static int i40e_suspend_port_tx(struct i40e_pf *pf)
6506 struct i40e_hw *hw = &pf->hw;
6509 ret = i40e_aq_suspend_port_tx(hw, pf->mac_seid, NULL);
6511 dev_info(&pf->pdev->dev,
6512 "Suspend Port Tx failed, err %s aq_err %s\n",
6513 i40e_stat_str(&pf->hw, ret),
6514 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6515 /* Schedule PF reset to recover */
6516 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
6517 i40e_service_event_schedule(pf);
6524 * i40e_hw_set_dcb_config - Program new DCBX settings into HW
6525 * @pf: PF being configured
6526 * @new_cfg: New DCBX configuration
6528 * Program DCB settings into HW and reconfigure VEB/VSIs on
6529 * given PF. Uses "Set LLDP MIB" AQC to program the hardware.
6531 static int i40e_hw_set_dcb_config(struct i40e_pf *pf,
6532 struct i40e_dcbx_config *new_cfg)
6534 struct i40e_dcbx_config *old_cfg = &pf->hw.local_dcbx_config;
6537 /* Check if need reconfiguration */
6538 if (!memcmp(&new_cfg, &old_cfg, sizeof(new_cfg))) {
6539 dev_dbg(&pf->pdev->dev, "No Change in DCB Config required.\n");
6543 /* Config change disable all VSIs */
6544 i40e_pf_quiesce_all_vsi(pf);
6546 /* Copy the new config to the current config */
6547 *old_cfg = *new_cfg;
6548 old_cfg->etsrec = old_cfg->etscfg;
6549 ret = i40e_set_dcb_config(&pf->hw);
6551 dev_info(&pf->pdev->dev,
6552 "Set DCB Config failed, err %s aq_err %s\n",
6553 i40e_stat_str(&pf->hw, ret),
6554 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6558 /* Changes in configuration update VEB/VSI */
6559 i40e_dcb_reconfigure(pf);
6561 /* In case of reset do not try to resume anything */
6562 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) {
6563 /* Re-start the VSIs if disabled */
6564 ret = i40e_resume_port_tx(pf);
6565 /* In case of error no point in resuming VSIs */
6568 i40e_pf_unquiesce_all_vsi(pf);
6575 * i40e_hw_dcb_config - Program new DCBX settings into HW
6576 * @pf: PF being configured
6577 * @new_cfg: New DCBX configuration
6579 * Program DCB settings into HW and reconfigure VEB/VSIs on
6582 int i40e_hw_dcb_config(struct i40e_pf *pf, struct i40e_dcbx_config *new_cfg)
6584 struct i40e_aqc_configure_switching_comp_ets_data ets_data;
6585 u8 prio_type[I40E_MAX_TRAFFIC_CLASS] = {0};
6586 u32 mfs_tc[I40E_MAX_TRAFFIC_CLASS];
6587 struct i40e_dcbx_config *old_cfg;
6588 u8 mode[I40E_MAX_TRAFFIC_CLASS];
6589 struct i40e_rx_pb_config pb_cfg;
6590 struct i40e_hw *hw = &pf->hw;
6591 u8 num_ports = hw->num_ports;
6599 dev_dbg(&pf->pdev->dev, "Configuring DCB registers directly\n");
6600 /* Un-pack information to Program ETS HW via shared API
6603 * ETS/NON-ETS arbiter mode
6604 * max exponent (credit refills)
6605 * Total number of ports
6606 * PFC priority bit-map
6609 * Arbiter mode between UPs sharing same TC
6610 * TSA table (ETS or non-ETS)
6611 * EEE enabled or not
6615 new_numtc = i40e_dcb_get_num_tc(new_cfg);
6617 memset(&ets_data, 0, sizeof(ets_data));
6618 for (i = 0; i < new_numtc; i++) {
6620 switch (new_cfg->etscfg.tsatable[i]) {
6621 case I40E_IEEE_TSA_ETS:
6622 prio_type[i] = I40E_DCB_PRIO_TYPE_ETS;
6623 ets_data.tc_bw_share_credits[i] =
6624 new_cfg->etscfg.tcbwtable[i];
6626 case I40E_IEEE_TSA_STRICT:
6627 prio_type[i] = I40E_DCB_PRIO_TYPE_STRICT;
6629 ets_data.tc_bw_share_credits[i] =
6630 I40E_DCB_STRICT_PRIO_CREDITS;
6633 /* Invalid TSA type */
6634 need_reconfig = false;
6639 old_cfg = &hw->local_dcbx_config;
6640 /* Check if need reconfiguration */
6641 need_reconfig = i40e_dcb_need_reconfig(pf, old_cfg, new_cfg);
6643 /* If needed, enable/disable frame tagging, disable all VSIs
6644 * and suspend port tx
6646 if (need_reconfig) {
6647 /* Enable DCB tagging only when more than one TC */
6649 pf->flags |= I40E_FLAG_DCB_ENABLED;
6651 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
6653 set_bit(__I40E_PORT_SUSPENDED, pf->state);
6654 /* Reconfiguration needed quiesce all VSIs */
6655 i40e_pf_quiesce_all_vsi(pf);
6656 ret = i40e_suspend_port_tx(pf);
6661 /* Configure Port ETS Tx Scheduler */
6662 ets_data.tc_valid_bits = tc_map;
6663 ets_data.tc_strict_priority_flags = lltc_map;
6664 ret = i40e_aq_config_switch_comp_ets
6665 (hw, pf->mac_seid, &ets_data,
6666 i40e_aqc_opc_modify_switching_comp_ets, NULL);
6668 dev_info(&pf->pdev->dev,
6669 "Modify Port ETS failed, err %s aq_err %s\n",
6670 i40e_stat_str(&pf->hw, ret),
6671 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6675 /* Configure Rx ETS HW */
6676 memset(&mode, I40E_DCB_ARB_MODE_ROUND_ROBIN, sizeof(mode));
6677 i40e_dcb_hw_set_num_tc(hw, new_numtc);
6678 i40e_dcb_hw_rx_fifo_config(hw, I40E_DCB_ARB_MODE_ROUND_ROBIN,
6679 I40E_DCB_ARB_MODE_STRICT_PRIORITY,
6680 I40E_DCB_DEFAULT_MAX_EXPONENT,
6682 i40e_dcb_hw_rx_cmd_monitor_config(hw, new_numtc, num_ports);
6683 i40e_dcb_hw_rx_ets_bw_config(hw, new_cfg->etscfg.tcbwtable, mode,
6685 i40e_dcb_hw_pfc_config(hw, new_cfg->pfc.pfcenable,
6686 new_cfg->etscfg.prioritytable);
6687 i40e_dcb_hw_rx_up2tc_config(hw, new_cfg->etscfg.prioritytable);
6689 /* Configure Rx Packet Buffers in HW */
6690 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
6691 mfs_tc[i] = pf->vsi[pf->lan_vsi]->netdev->mtu;
6692 mfs_tc[i] += I40E_PACKET_HDR_PAD;
6695 i40e_dcb_hw_calculate_pool_sizes(hw, num_ports,
6696 false, new_cfg->pfc.pfcenable,
6698 i40e_dcb_hw_rx_pb_config(hw, &pf->pb_cfg, &pb_cfg);
6700 /* Update the local Rx Packet buffer config */
6701 pf->pb_cfg = pb_cfg;
6703 /* Inform the FW about changes to DCB configuration */
6704 ret = i40e_aq_dcb_updated(&pf->hw, NULL);
6706 dev_info(&pf->pdev->dev,
6707 "DCB Updated failed, err %s aq_err %s\n",
6708 i40e_stat_str(&pf->hw, ret),
6709 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6713 /* Update the port DCBx configuration */
6714 *old_cfg = *new_cfg;
6716 /* Changes in configuration update VEB/VSI */
6717 i40e_dcb_reconfigure(pf);
6719 /* Re-start the VSIs if disabled */
6720 if (need_reconfig) {
6721 ret = i40e_resume_port_tx(pf);
6723 clear_bit(__I40E_PORT_SUSPENDED, pf->state);
6724 /* In case of error no point in resuming VSIs */
6728 /* Wait for the PF's queues to be disabled */
6729 ret = i40e_pf_wait_queues_disabled(pf);
6731 /* Schedule PF reset to recover */
6732 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
6733 i40e_service_event_schedule(pf);
6736 i40e_pf_unquiesce_all_vsi(pf);
6737 set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
6738 set_bit(__I40E_CLIENT_L2_CHANGE, pf->state);
6740 /* registers are set, lets apply */
6741 if (pf->hw_features & I40E_HW_USE_SET_LLDP_MIB)
6742 ret = i40e_hw_set_dcb_config(pf, new_cfg);
6750 * i40e_dcb_sw_default_config - Set default DCB configuration when DCB in SW
6751 * @pf: PF being queried
6753 * Set default DCB configuration in case DCB is to be done in SW.
6755 int i40e_dcb_sw_default_config(struct i40e_pf *pf)
6757 struct i40e_dcbx_config *dcb_cfg = &pf->hw.local_dcbx_config;
6758 struct i40e_aqc_configure_switching_comp_ets_data ets_data;
6759 struct i40e_hw *hw = &pf->hw;
6762 if (pf->hw_features & I40E_HW_USE_SET_LLDP_MIB) {
6763 /* Update the local cached instance with TC0 ETS */
6764 memset(&pf->tmp_cfg, 0, sizeof(struct i40e_dcbx_config));
6765 pf->tmp_cfg.etscfg.willing = I40E_IEEE_DEFAULT_ETS_WILLING;
6766 pf->tmp_cfg.etscfg.maxtcs = 0;
6767 pf->tmp_cfg.etscfg.tcbwtable[0] = I40E_IEEE_DEFAULT_ETS_TCBW;
6768 pf->tmp_cfg.etscfg.tsatable[0] = I40E_IEEE_TSA_ETS;
6769 pf->tmp_cfg.pfc.willing = I40E_IEEE_DEFAULT_PFC_WILLING;
6770 pf->tmp_cfg.pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
6771 /* FW needs one App to configure HW */
6772 pf->tmp_cfg.numapps = I40E_IEEE_DEFAULT_NUM_APPS;
6773 pf->tmp_cfg.app[0].selector = I40E_APP_SEL_ETHTYPE;
6774 pf->tmp_cfg.app[0].priority = I40E_IEEE_DEFAULT_APP_PRIO;
6775 pf->tmp_cfg.app[0].protocolid = I40E_APP_PROTOID_FCOE;
6777 return i40e_hw_set_dcb_config(pf, &pf->tmp_cfg);
6780 memset(&ets_data, 0, sizeof(ets_data));
6781 ets_data.tc_valid_bits = I40E_DEFAULT_TRAFFIC_CLASS; /* TC0 only */
6782 ets_data.tc_strict_priority_flags = 0; /* ETS */
6783 ets_data.tc_bw_share_credits[0] = I40E_IEEE_DEFAULT_ETS_TCBW; /* 100% to TC0 */
6785 /* Enable ETS on the Physical port */
6786 err = i40e_aq_config_switch_comp_ets
6787 (hw, pf->mac_seid, &ets_data,
6788 i40e_aqc_opc_enable_switching_comp_ets, NULL);
6790 dev_info(&pf->pdev->dev,
6791 "Enable Port ETS failed, err %s aq_err %s\n",
6792 i40e_stat_str(&pf->hw, err),
6793 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6798 /* Update the local cached instance with TC0 ETS */
6799 dcb_cfg->etscfg.willing = I40E_IEEE_DEFAULT_ETS_WILLING;
6800 dcb_cfg->etscfg.cbs = 0;
6801 dcb_cfg->etscfg.maxtcs = I40E_MAX_TRAFFIC_CLASS;
6802 dcb_cfg->etscfg.tcbwtable[0] = I40E_IEEE_DEFAULT_ETS_TCBW;
6809 * i40e_init_pf_dcb - Initialize DCB configuration
6810 * @pf: PF being configured
6812 * Query the current DCB configuration and cache it
6813 * in the hardware structure
6815 static int i40e_init_pf_dcb(struct i40e_pf *pf)
6817 struct i40e_hw *hw = &pf->hw;
6820 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable
6821 * Also do not enable DCBx if FW LLDP agent is disabled
6823 if (pf->hw_features & I40E_HW_NO_DCB_SUPPORT) {
6824 dev_info(&pf->pdev->dev, "DCB is not supported.\n");
6825 err = I40E_NOT_SUPPORTED;
6828 if (pf->flags & I40E_FLAG_DISABLE_FW_LLDP) {
6829 dev_info(&pf->pdev->dev, "FW LLDP is disabled, attempting SW DCB\n");
6830 err = i40e_dcb_sw_default_config(pf);
6832 dev_info(&pf->pdev->dev, "Could not initialize SW DCB\n");
6835 dev_info(&pf->pdev->dev, "SW DCB initialization succeeded.\n");
6836 pf->dcbx_cap = DCB_CAP_DCBX_HOST |
6837 DCB_CAP_DCBX_VER_IEEE;
6838 /* at init capable but disabled */
6839 pf->flags |= I40E_FLAG_DCB_CAPABLE;
6840 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
6843 err = i40e_init_dcb(hw, true);
6845 /* Device/Function is not DCBX capable */
6846 if ((!hw->func_caps.dcb) ||
6847 (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
6848 dev_info(&pf->pdev->dev,
6849 "DCBX offload is not supported or is disabled for this PF.\n");
6851 /* When status is not DISABLED then DCBX in FW */
6852 pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
6853 DCB_CAP_DCBX_VER_IEEE;
6855 pf->flags |= I40E_FLAG_DCB_CAPABLE;
6856 /* Enable DCB tagging only when more than one TC
6857 * or explicitly disable if only one TC
6859 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
6860 pf->flags |= I40E_FLAG_DCB_ENABLED;
6862 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
6863 dev_dbg(&pf->pdev->dev,
6864 "DCBX offload is supported for this PF.\n");
6866 } else if (pf->hw.aq.asq_last_status == I40E_AQ_RC_EPERM) {
6867 dev_info(&pf->pdev->dev, "FW LLDP disabled for this PF.\n");
6868 pf->flags |= I40E_FLAG_DISABLE_FW_LLDP;
6870 dev_info(&pf->pdev->dev,
6871 "Query for DCB configuration failed, err %s aq_err %s\n",
6872 i40e_stat_str(&pf->hw, err),
6873 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6879 #endif /* CONFIG_I40E_DCB */
6882 * i40e_set_lldp_forwarding - set forwarding of lldp frames
6883 * @pf: PF being configured
6884 * @enable: if forwarding to OS shall be enabled
6886 * Toggle forwarding of lldp frames behavior,
6887 * When passing DCB control from firmware to software
6888 * lldp frames must be forwarded to the software based
6891 void i40e_set_lldp_forwarding(struct i40e_pf *pf, bool enable)
6893 if (pf->lan_vsi == I40E_NO_VSI)
6896 if (!pf->vsi[pf->lan_vsi])
6899 /* No need to check the outcome, commands may fail
6900 * if desired value is already set
6902 i40e_aq_add_rem_control_packet_filter(&pf->hw, NULL, ETH_P_LLDP,
6903 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX |
6904 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC,
6905 pf->vsi[pf->lan_vsi]->seid, 0,
6906 enable, NULL, NULL);
6908 i40e_aq_add_rem_control_packet_filter(&pf->hw, NULL, ETH_P_LLDP,
6909 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_RX |
6910 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC,
6911 pf->vsi[pf->lan_vsi]->seid, 0,
6912 enable, NULL, NULL);
6916 * i40e_print_link_message - print link up or down
6917 * @vsi: the VSI for which link needs a message
6918 * @isup: true of link is up, false otherwise
6920 void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
6922 enum i40e_aq_link_speed new_speed;
6923 struct i40e_pf *pf = vsi->back;
6924 char *speed = "Unknown";
6925 char *fc = "Unknown";
6931 new_speed = pf->hw.phy.link_info.link_speed;
6933 new_speed = I40E_LINK_SPEED_UNKNOWN;
6935 if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed))
6937 vsi->current_isup = isup;
6938 vsi->current_speed = new_speed;
6940 netdev_info(vsi->netdev, "NIC Link is Down\n");
6944 /* Warn user if link speed on NPAR enabled partition is not at
6947 if (pf->hw.func_caps.npar_enable &&
6948 (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
6949 pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
6950 netdev_warn(vsi->netdev,
6951 "The partition detected link speed that is less than 10Gbps\n");
6953 switch (pf->hw.phy.link_info.link_speed) {
6954 case I40E_LINK_SPEED_40GB:
6957 case I40E_LINK_SPEED_20GB:
6960 case I40E_LINK_SPEED_25GB:
6963 case I40E_LINK_SPEED_10GB:
6966 case I40E_LINK_SPEED_5GB:
6969 case I40E_LINK_SPEED_2_5GB:
6972 case I40E_LINK_SPEED_1GB:
6975 case I40E_LINK_SPEED_100MB:
6982 switch (pf->hw.fc.current_mode) {
6986 case I40E_FC_TX_PAUSE:
6989 case I40E_FC_RX_PAUSE:
6997 if (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_25GB) {
7002 if (pf->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED)
7005 if (pf->hw.phy.link_info.fec_info &
7006 I40E_AQ_CONFIG_FEC_KR_ENA)
7007 fec = "CL74 FC-FEC/BASE-R";
7008 else if (pf->hw.phy.link_info.fec_info &
7009 I40E_AQ_CONFIG_FEC_RS_ENA)
7010 fec = "CL108 RS-FEC";
7012 /* 'CL108 RS-FEC' should be displayed when RS is requested, or
7013 * both RS and FC are requested
7015 if (vsi->back->hw.phy.link_info.req_fec_info &
7016 (I40E_AQ_REQUEST_FEC_KR | I40E_AQ_REQUEST_FEC_RS)) {
7017 if (vsi->back->hw.phy.link_info.req_fec_info &
7018 I40E_AQ_REQUEST_FEC_RS)
7019 req_fec = "CL108 RS-FEC";
7021 req_fec = "CL74 FC-FEC/BASE-R";
7023 netdev_info(vsi->netdev,
7024 "NIC Link is Up, %sbps Full Duplex, Requested FEC: %s, Negotiated FEC: %s, Autoneg: %s, Flow Control: %s\n",
7025 speed, req_fec, fec, an, fc);
7026 } else if (pf->hw.device_id == I40E_DEV_ID_KX_X722) {
7031 if (pf->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED)
7034 if (pf->hw.phy.link_info.fec_info &
7035 I40E_AQ_CONFIG_FEC_KR_ENA)
7036 fec = "CL74 FC-FEC/BASE-R";
7038 if (pf->hw.phy.link_info.req_fec_info &
7039 I40E_AQ_REQUEST_FEC_KR)
7040 req_fec = "CL74 FC-FEC/BASE-R";
7042 netdev_info(vsi->netdev,
7043 "NIC Link is Up, %sbps Full Duplex, Requested FEC: %s, Negotiated FEC: %s, Autoneg: %s, Flow Control: %s\n",
7044 speed, req_fec, fec, an, fc);
7046 netdev_info(vsi->netdev,
7047 "NIC Link is Up, %sbps Full Duplex, Flow Control: %s\n",
7054 * i40e_up_complete - Finish the last steps of bringing up a connection
7055 * @vsi: the VSI being configured
7057 static int i40e_up_complete(struct i40e_vsi *vsi)
7059 struct i40e_pf *pf = vsi->back;
7062 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7063 i40e_vsi_configure_msix(vsi);
7065 i40e_configure_msi_and_legacy(vsi);
7068 err = i40e_vsi_start_rings(vsi);
7072 clear_bit(__I40E_VSI_DOWN, vsi->state);
7073 i40e_napi_enable_all(vsi);
7074 i40e_vsi_enable_irq(vsi);
7076 if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
7078 i40e_print_link_message(vsi, true);
7079 netif_tx_start_all_queues(vsi->netdev);
7080 netif_carrier_on(vsi->netdev);
7083 /* replay FDIR SB filters */
7084 if (vsi->type == I40E_VSI_FDIR) {
7085 /* reset fd counters */
7088 i40e_fdir_filter_restore(vsi);
7091 /* On the next run of the service_task, notify any clients of the new
7094 set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
7095 i40e_service_event_schedule(pf);
7101 * i40e_vsi_reinit_locked - Reset the VSI
7102 * @vsi: the VSI being configured
7104 * Rebuild the ring structs after some configuration
7105 * has changed, e.g. MTU size.
7107 static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
7109 struct i40e_pf *pf = vsi->back;
7111 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state))
7112 usleep_range(1000, 2000);
7116 clear_bit(__I40E_CONFIG_BUSY, pf->state);
7120 * i40e_force_link_state - Force the link status
7121 * @pf: board private structure
7122 * @is_up: whether the link state should be forced up or down
7124 static i40e_status i40e_force_link_state(struct i40e_pf *pf, bool is_up)
7126 struct i40e_aq_get_phy_abilities_resp abilities;
7127 struct i40e_aq_set_phy_config config = {0};
7128 bool non_zero_phy_type = is_up;
7129 struct i40e_hw *hw = &pf->hw;
7134 /* Card might've been put in an unstable state by other drivers
7135 * and applications, which causes incorrect speed values being
7136 * set on startup. In order to clear speed registers, we call
7137 * get_phy_capabilities twice, once to get initial state of
7138 * available speeds, and once to get current PHY config.
7140 err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities,
7143 dev_err(&pf->pdev->dev,
7144 "failed to get phy cap., ret = %s last_status = %s\n",
7145 i40e_stat_str(hw, err),
7146 i40e_aq_str(hw, hw->aq.asq_last_status));
7149 speed = abilities.link_speed;
7151 /* Get the current phy config */
7152 err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
7155 dev_err(&pf->pdev->dev,
7156 "failed to get phy cap., ret = %s last_status = %s\n",
7157 i40e_stat_str(hw, err),
7158 i40e_aq_str(hw, hw->aq.asq_last_status));
7162 /* If link needs to go up, but was not forced to go down,
7163 * and its speed values are OK, no need for a flap
7164 * if non_zero_phy_type was set, still need to force up
7166 if (pf->flags & I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENABLED)
7167 non_zero_phy_type = true;
7168 else if (is_up && abilities.phy_type != 0 && abilities.link_speed != 0)
7169 return I40E_SUCCESS;
7171 /* To force link we need to set bits for all supported PHY types,
7172 * but there are now more than 32, so we need to split the bitmap
7173 * across two fields.
7175 mask = I40E_PHY_TYPES_BITMASK;
7177 non_zero_phy_type ? cpu_to_le32((u32)(mask & 0xffffffff)) : 0;
7178 config.phy_type_ext =
7179 non_zero_phy_type ? (u8)((mask >> 32) & 0xff) : 0;
7180 /* Copy the old settings, except of phy_type */
7181 config.abilities = abilities.abilities;
7182 if (pf->flags & I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENABLED) {
7184 config.abilities |= I40E_AQ_PHY_ENABLE_LINK;
7186 config.abilities &= ~(I40E_AQ_PHY_ENABLE_LINK);
7188 if (abilities.link_speed != 0)
7189 config.link_speed = abilities.link_speed;
7191 config.link_speed = speed;
7192 config.eee_capability = abilities.eee_capability;
7193 config.eeer = abilities.eeer_val;
7194 config.low_power_ctrl = abilities.d3_lpan;
7195 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
7196 I40E_AQ_PHY_FEC_CONFIG_MASK;
7197 err = i40e_aq_set_phy_config(hw, &config, NULL);
7200 dev_err(&pf->pdev->dev,
7201 "set phy config ret = %s last_status = %s\n",
7202 i40e_stat_str(&pf->hw, err),
7203 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
7207 /* Update the link info */
7208 err = i40e_update_link_info(hw);
7210 /* Wait a little bit (on 40G cards it sometimes takes a really
7211 * long time for link to come back from the atomic reset)
7215 i40e_update_link_info(hw);
7218 i40e_aq_set_link_restart_an(hw, is_up, NULL);
7220 return I40E_SUCCESS;
7224 * i40e_up - Bring the connection back up after being down
7225 * @vsi: the VSI being configured
7227 int i40e_up(struct i40e_vsi *vsi)
7231 if (vsi->type == I40E_VSI_MAIN &&
7232 (vsi->back->flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED ||
7233 vsi->back->flags & I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENABLED))
7234 i40e_force_link_state(vsi->back, true);
7236 err = i40e_vsi_configure(vsi);
7238 err = i40e_up_complete(vsi);
7244 * i40e_down - Shutdown the connection processing
7245 * @vsi: the VSI being stopped
7247 void i40e_down(struct i40e_vsi *vsi)
7251 /* It is assumed that the caller of this function
7252 * sets the vsi->state __I40E_VSI_DOWN bit.
7255 netif_carrier_off(vsi->netdev);
7256 netif_tx_disable(vsi->netdev);
7258 i40e_vsi_disable_irq(vsi);
7259 i40e_vsi_stop_rings(vsi);
7260 if (vsi->type == I40E_VSI_MAIN &&
7261 (vsi->back->flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED ||
7262 vsi->back->flags & I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENABLED))
7263 i40e_force_link_state(vsi->back, false);
7264 i40e_napi_disable_all(vsi);
7266 for (i = 0; i < vsi->num_queue_pairs; i++) {
7267 i40e_clean_tx_ring(vsi->tx_rings[i]);
7268 if (i40e_enabled_xdp_vsi(vsi)) {
7269 /* Make sure that in-progress ndo_xdp_xmit and
7270 * ndo_xsk_wakeup calls are completed.
7273 i40e_clean_tx_ring(vsi->xdp_rings[i]);
7275 i40e_clean_rx_ring(vsi->rx_rings[i]);
7281 * i40e_validate_mqprio_qopt- validate queue mapping info
7282 * @vsi: the VSI being configured
7283 * @mqprio_qopt: queue parametrs
7285 static int i40e_validate_mqprio_qopt(struct i40e_vsi *vsi,
7286 struct tc_mqprio_qopt_offload *mqprio_qopt)
7288 u64 sum_max_rate = 0;
7292 if (mqprio_qopt->qopt.offset[0] != 0 ||
7293 mqprio_qopt->qopt.num_tc < 1 ||
7294 mqprio_qopt->qopt.num_tc > I40E_MAX_TRAFFIC_CLASS)
7296 for (i = 0; ; i++) {
7297 if (!mqprio_qopt->qopt.count[i])
7299 if (mqprio_qopt->min_rate[i]) {
7300 dev_err(&vsi->back->pdev->dev,
7301 "Invalid min tx rate (greater than 0) specified\n");
7304 max_rate = mqprio_qopt->max_rate[i];
7305 do_div(max_rate, I40E_BW_MBPS_DIVISOR);
7306 sum_max_rate += max_rate;
7308 if (i >= mqprio_qopt->qopt.num_tc - 1)
7310 if (mqprio_qopt->qopt.offset[i + 1] !=
7311 (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i]))
7314 if (vsi->num_queue_pairs <
7315 (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i])) {
7318 if (sum_max_rate > i40e_get_link_speed(vsi)) {
7319 dev_err(&vsi->back->pdev->dev,
7320 "Invalid max tx rate specified\n");
7327 * i40e_vsi_set_default_tc_config - set default values for tc configuration
7328 * @vsi: the VSI being configured
7330 static void i40e_vsi_set_default_tc_config(struct i40e_vsi *vsi)
7335 /* Only TC0 is enabled */
7336 vsi->tc_config.numtc = 1;
7337 vsi->tc_config.enabled_tc = 1;
7338 qcount = min_t(int, vsi->alloc_queue_pairs,
7339 i40e_pf_get_max_q_per_tc(vsi->back));
7340 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
7341 /* For the TC that is not enabled set the offset to to default
7342 * queue and allocate one queue for the given TC.
7344 vsi->tc_config.tc_info[i].qoffset = 0;
7346 vsi->tc_config.tc_info[i].qcount = qcount;
7348 vsi->tc_config.tc_info[i].qcount = 1;
7349 vsi->tc_config.tc_info[i].netdev_tc = 0;
7354 * i40e_del_macvlan_filter
7355 * @hw: pointer to the HW structure
7356 * @seid: seid of the channel VSI
7357 * @macaddr: the mac address to apply as a filter
7358 * @aq_err: store the admin Q error
7360 * This function deletes a mac filter on the channel VSI which serves as the
7361 * macvlan. Returns 0 on success.
7363 static i40e_status i40e_del_macvlan_filter(struct i40e_hw *hw, u16 seid,
7364 const u8 *macaddr, int *aq_err)
7366 struct i40e_aqc_remove_macvlan_element_data element;
7369 memset(&element, 0, sizeof(element));
7370 ether_addr_copy(element.mac_addr, macaddr);
7371 element.vlan_tag = 0;
7372 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
7373 status = i40e_aq_remove_macvlan(hw, seid, &element, 1, NULL);
7374 *aq_err = hw->aq.asq_last_status;
7380 * i40e_add_macvlan_filter
7381 * @hw: pointer to the HW structure
7382 * @seid: seid of the channel VSI
7383 * @macaddr: the mac address to apply as a filter
7384 * @aq_err: store the admin Q error
7386 * This function adds a mac filter on the channel VSI which serves as the
7387 * macvlan. Returns 0 on success.
7389 static i40e_status i40e_add_macvlan_filter(struct i40e_hw *hw, u16 seid,
7390 const u8 *macaddr, int *aq_err)
7392 struct i40e_aqc_add_macvlan_element_data element;
7396 ether_addr_copy(element.mac_addr, macaddr);
7397 element.vlan_tag = 0;
7398 element.queue_number = 0;
7399 element.match_method = I40E_AQC_MM_ERR_NO_RES;
7400 cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
7401 element.flags = cpu_to_le16(cmd_flags);
7402 status = i40e_aq_add_macvlan(hw, seid, &element, 1, NULL);
7403 *aq_err = hw->aq.asq_last_status;
7409 * i40e_reset_ch_rings - Reset the queue contexts in a channel
7410 * @vsi: the VSI we want to access
7411 * @ch: the channel we want to access
7413 static void i40e_reset_ch_rings(struct i40e_vsi *vsi, struct i40e_channel *ch)
7415 struct i40e_ring *tx_ring, *rx_ring;
7419 for (i = 0; i < ch->num_queue_pairs; i++) {
7420 pf_q = ch->base_queue + i;
7421 tx_ring = vsi->tx_rings[pf_q];
7423 rx_ring = vsi->rx_rings[pf_q];
7429 * i40e_free_macvlan_channels
7430 * @vsi: the VSI we want to access
7432 * This function frees the Qs of the channel VSI from
7433 * the stack and also deletes the channel VSIs which
7434 * serve as macvlans.
7436 static void i40e_free_macvlan_channels(struct i40e_vsi *vsi)
7438 struct i40e_channel *ch, *ch_tmp;
7441 if (list_empty(&vsi->macvlan_list))
7444 list_for_each_entry_safe(ch, ch_tmp, &vsi->macvlan_list, list) {
7445 struct i40e_vsi *parent_vsi;
7447 if (i40e_is_channel_macvlan(ch)) {
7448 i40e_reset_ch_rings(vsi, ch);
7449 clear_bit(ch->fwd->bit_no, vsi->fwd_bitmask);
7450 netdev_unbind_sb_channel(vsi->netdev, ch->fwd->netdev);
7451 netdev_set_sb_channel(ch->fwd->netdev, 0);
7456 list_del(&ch->list);
7457 parent_vsi = ch->parent_vsi;
7458 if (!parent_vsi || !ch->initialized) {
7463 /* remove the VSI */
7464 ret = i40e_aq_delete_element(&vsi->back->hw, ch->seid,
7467 dev_err(&vsi->back->pdev->dev,
7468 "unable to remove channel (%d) for parent VSI(%d)\n",
7469 ch->seid, parent_vsi->seid);
7472 vsi->macvlan_cnt = 0;
7476 * i40e_fwd_ring_up - bring the macvlan device up
7477 * @vsi: the VSI we want to access
7478 * @vdev: macvlan netdevice
7479 * @fwd: the private fwd structure
7481 static int i40e_fwd_ring_up(struct i40e_vsi *vsi, struct net_device *vdev,
7482 struct i40e_fwd_adapter *fwd)
7484 int ret = 0, num_tc = 1, i, aq_err;
7485 struct i40e_channel *ch, *ch_tmp;
7486 struct i40e_pf *pf = vsi->back;
7487 struct i40e_hw *hw = &pf->hw;
7489 if (list_empty(&vsi->macvlan_list))
7492 /* Go through the list and find an available channel */
7493 list_for_each_entry_safe(ch, ch_tmp, &vsi->macvlan_list, list) {
7494 if (!i40e_is_channel_macvlan(ch)) {
7496 /* record configuration for macvlan interface in vdev */
7497 for (i = 0; i < num_tc; i++)
7498 netdev_bind_sb_channel_queue(vsi->netdev, vdev,
7500 ch->num_queue_pairs,
7502 for (i = 0; i < ch->num_queue_pairs; i++) {
7503 struct i40e_ring *tx_ring, *rx_ring;
7506 pf_q = ch->base_queue + i;
7508 /* Get to TX ring ptr */
7509 tx_ring = vsi->tx_rings[pf_q];
7512 /* Get the RX ring ptr */
7513 rx_ring = vsi->rx_rings[pf_q];
7520 /* Guarantee all rings are updated before we update the
7521 * MAC address filter.
7525 /* Add a mac filter */
7526 ret = i40e_add_macvlan_filter(hw, ch->seid, vdev->dev_addr, &aq_err);
7528 /* if we cannot add the MAC rule then disable the offload */
7529 macvlan_release_l2fw_offload(vdev);
7530 for (i = 0; i < ch->num_queue_pairs; i++) {
7531 struct i40e_ring *rx_ring;
7534 pf_q = ch->base_queue + i;
7535 rx_ring = vsi->rx_rings[pf_q];
7536 rx_ring->netdev = NULL;
7538 dev_info(&pf->pdev->dev,
7539 "Error adding mac filter on macvlan err %s, aq_err %s\n",
7540 i40e_stat_str(hw, ret),
7541 i40e_aq_str(hw, aq_err));
7542 netdev_err(vdev, "L2fwd offload disabled to L2 filter error\n");
7549 * i40e_setup_macvlans - create the channels which will be macvlans
7550 * @vsi: the VSI we want to access
7551 * @macvlan_cnt: no. of macvlans to be setup
7552 * @qcnt: no. of Qs per macvlan
7553 * @vdev: macvlan netdevice
7555 static int i40e_setup_macvlans(struct i40e_vsi *vsi, u16 macvlan_cnt, u16 qcnt,
7556 struct net_device *vdev)
7558 struct i40e_pf *pf = vsi->back;
7559 struct i40e_hw *hw = &pf->hw;
7560 struct i40e_vsi_context ctxt;
7561 u16 sections, qmap, num_qps;
7562 struct i40e_channel *ch;
7563 int i, pow, ret = 0;
7566 if (vsi->type != I40E_VSI_MAIN || !macvlan_cnt)
7569 num_qps = vsi->num_queue_pairs - (macvlan_cnt * qcnt);
7571 /* find the next higher power-of-2 of num queue pairs */
7572 pow = fls(roundup_pow_of_two(num_qps) - 1);
7574 qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
7575 (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
7577 /* Setup context bits for the main VSI */
7578 sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
7579 sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
7580 memset(&ctxt, 0, sizeof(ctxt));
7581 ctxt.seid = vsi->seid;
7582 ctxt.pf_num = vsi->back->hw.pf_id;
7584 ctxt.uplink_seid = vsi->uplink_seid;
7585 ctxt.info = vsi->info;
7586 ctxt.info.tc_mapping[0] = cpu_to_le16(qmap);
7587 ctxt.info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
7588 ctxt.info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
7589 ctxt.info.valid_sections |= cpu_to_le16(sections);
7591 /* Reconfigure RSS for main VSI with new max queue count */
7592 vsi->rss_size = max_t(u16, num_qps, qcnt);
7593 ret = i40e_vsi_config_rss(vsi);
7595 dev_info(&pf->pdev->dev,
7596 "Failed to reconfig RSS for num_queues (%u)\n",
7600 vsi->reconfig_rss = true;
7601 dev_dbg(&vsi->back->pdev->dev,
7602 "Reconfigured RSS with num_queues (%u)\n", vsi->rss_size);
7603 vsi->next_base_queue = num_qps;
7604 vsi->cnt_q_avail = vsi->num_queue_pairs - num_qps;
7606 /* Update the VSI after updating the VSI queue-mapping
7609 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
7611 dev_info(&pf->pdev->dev,
7612 "Update vsi tc config failed, err %s aq_err %s\n",
7613 i40e_stat_str(hw, ret),
7614 i40e_aq_str(hw, hw->aq.asq_last_status));
7617 /* update the local VSI info with updated queue map */
7618 i40e_vsi_update_queue_map(vsi, &ctxt);
7619 vsi->info.valid_sections = 0;
7621 /* Create channels for macvlans */
7622 INIT_LIST_HEAD(&vsi->macvlan_list);
7623 for (i = 0; i < macvlan_cnt; i++) {
7624 ch = kzalloc(sizeof(*ch), GFP_KERNEL);
7629 INIT_LIST_HEAD(&ch->list);
7630 ch->num_queue_pairs = qcnt;
7631 if (!i40e_setup_channel(pf, vsi, ch)) {
7636 ch->parent_vsi = vsi;
7637 vsi->cnt_q_avail -= ch->num_queue_pairs;
7639 list_add_tail(&ch->list, &vsi->macvlan_list);
7645 dev_info(&pf->pdev->dev, "Failed to setup macvlans\n");
7646 i40e_free_macvlan_channels(vsi);
7652 * i40e_fwd_add - configure macvlans
7653 * @netdev: net device to configure
7654 * @vdev: macvlan netdevice
7656 static void *i40e_fwd_add(struct net_device *netdev, struct net_device *vdev)
7658 struct i40e_netdev_priv *np = netdev_priv(netdev);
7659 u16 q_per_macvlan = 0, macvlan_cnt = 0, vectors;
7660 struct i40e_vsi *vsi = np->vsi;
7661 struct i40e_pf *pf = vsi->back;
7662 struct i40e_fwd_adapter *fwd;
7663 int avail_macvlan, ret;
7665 if ((pf->flags & I40E_FLAG_DCB_ENABLED)) {
7666 netdev_info(netdev, "Macvlans are not supported when DCB is enabled\n");
7667 return ERR_PTR(-EINVAL);
7669 if ((pf->flags & I40E_FLAG_TC_MQPRIO)) {
7670 netdev_info(netdev, "Macvlans are not supported when HW TC offload is on\n");
7671 return ERR_PTR(-EINVAL);
7673 if (pf->num_lan_msix < I40E_MIN_MACVLAN_VECTORS) {
7674 netdev_info(netdev, "Not enough vectors available to support macvlans\n");
7675 return ERR_PTR(-EINVAL);
7678 /* The macvlan device has to be a single Q device so that the
7679 * tc_to_txq field can be reused to pick the tx queue.
7681 if (netif_is_multiqueue(vdev))
7682 return ERR_PTR(-ERANGE);
7684 if (!vsi->macvlan_cnt) {
7685 /* reserve bit 0 for the pf device */
7686 set_bit(0, vsi->fwd_bitmask);
7688 /* Try to reserve as many queues as possible for macvlans. First
7689 * reserve 3/4th of max vectors, then half, then quarter and
7690 * calculate Qs per macvlan as you go
7692 vectors = pf->num_lan_msix;
7693 if (vectors <= I40E_MAX_MACVLANS && vectors > 64) {
7694 /* allocate 4 Qs per macvlan and 32 Qs to the PF*/
7696 macvlan_cnt = (vectors - 32) / 4;
7697 } else if (vectors <= 64 && vectors > 32) {
7698 /* allocate 2 Qs per macvlan and 16 Qs to the PF*/
7700 macvlan_cnt = (vectors - 16) / 2;
7701 } else if (vectors <= 32 && vectors > 16) {
7702 /* allocate 1 Q per macvlan and 16 Qs to the PF*/
7704 macvlan_cnt = vectors - 16;
7705 } else if (vectors <= 16 && vectors > 8) {
7706 /* allocate 1 Q per macvlan and 8 Qs to the PF */
7708 macvlan_cnt = vectors - 8;
7710 /* allocate 1 Q per macvlan and 1 Q to the PF */
7712 macvlan_cnt = vectors - 1;
7715 if (macvlan_cnt == 0)
7716 return ERR_PTR(-EBUSY);
7718 /* Quiesce VSI queues */
7719 i40e_quiesce_vsi(vsi);
7721 /* sets up the macvlans but does not "enable" them */
7722 ret = i40e_setup_macvlans(vsi, macvlan_cnt, q_per_macvlan,
7725 return ERR_PTR(ret);
7728 i40e_unquiesce_vsi(vsi);
7730 avail_macvlan = find_first_zero_bit(vsi->fwd_bitmask,
7732 if (avail_macvlan >= I40E_MAX_MACVLANS)
7733 return ERR_PTR(-EBUSY);
7735 /* create the fwd struct */
7736 fwd = kzalloc(sizeof(*fwd), GFP_KERNEL);
7738 return ERR_PTR(-ENOMEM);
7740 set_bit(avail_macvlan, vsi->fwd_bitmask);
7741 fwd->bit_no = avail_macvlan;
7742 netdev_set_sb_channel(vdev, avail_macvlan);
7745 if (!netif_running(netdev))
7748 /* Set fwd ring up */
7749 ret = i40e_fwd_ring_up(vsi, vdev, fwd);
7751 /* unbind the queues and drop the subordinate channel config */
7752 netdev_unbind_sb_channel(netdev, vdev);
7753 netdev_set_sb_channel(vdev, 0);
7756 return ERR_PTR(-EINVAL);
7763 * i40e_del_all_macvlans - Delete all the mac filters on the channels
7764 * @vsi: the VSI we want to access
7766 static void i40e_del_all_macvlans(struct i40e_vsi *vsi)
7768 struct i40e_channel *ch, *ch_tmp;
7769 struct i40e_pf *pf = vsi->back;
7770 struct i40e_hw *hw = &pf->hw;
7771 int aq_err, ret = 0;
7773 if (list_empty(&vsi->macvlan_list))
7776 list_for_each_entry_safe(ch, ch_tmp, &vsi->macvlan_list, list) {
7777 if (i40e_is_channel_macvlan(ch)) {
7778 ret = i40e_del_macvlan_filter(hw, ch->seid,
7779 i40e_channel_mac(ch),
7782 /* Reset queue contexts */
7783 i40e_reset_ch_rings(vsi, ch);
7784 clear_bit(ch->fwd->bit_no, vsi->fwd_bitmask);
7785 netdev_unbind_sb_channel(vsi->netdev,
7787 netdev_set_sb_channel(ch->fwd->netdev, 0);
7796 * i40e_fwd_del - delete macvlan interfaces
7797 * @netdev: net device to configure
7798 * @vdev: macvlan netdevice
7800 static void i40e_fwd_del(struct net_device *netdev, void *vdev)
7802 struct i40e_netdev_priv *np = netdev_priv(netdev);
7803 struct i40e_fwd_adapter *fwd = vdev;
7804 struct i40e_channel *ch, *ch_tmp;
7805 struct i40e_vsi *vsi = np->vsi;
7806 struct i40e_pf *pf = vsi->back;
7807 struct i40e_hw *hw = &pf->hw;
7808 int aq_err, ret = 0;
7810 /* Find the channel associated with the macvlan and del mac filter */
7811 list_for_each_entry_safe(ch, ch_tmp, &vsi->macvlan_list, list) {
7812 if (i40e_is_channel_macvlan(ch) &&
7813 ether_addr_equal(i40e_channel_mac(ch),
7814 fwd->netdev->dev_addr)) {
7815 ret = i40e_del_macvlan_filter(hw, ch->seid,
7816 i40e_channel_mac(ch),
7819 /* Reset queue contexts */
7820 i40e_reset_ch_rings(vsi, ch);
7821 clear_bit(ch->fwd->bit_no, vsi->fwd_bitmask);
7822 netdev_unbind_sb_channel(netdev, fwd->netdev);
7823 netdev_set_sb_channel(fwd->netdev, 0);
7827 dev_info(&pf->pdev->dev,
7828 "Error deleting mac filter on macvlan err %s, aq_err %s\n",
7829 i40e_stat_str(hw, ret),
7830 i40e_aq_str(hw, aq_err));
7838 * i40e_setup_tc - configure multiple traffic classes
7839 * @netdev: net device to configure
7840 * @type_data: tc offload data
7842 static int i40e_setup_tc(struct net_device *netdev, void *type_data)
7844 struct tc_mqprio_qopt_offload *mqprio_qopt = type_data;
7845 struct i40e_netdev_priv *np = netdev_priv(netdev);
7846 struct i40e_vsi *vsi = np->vsi;
7847 struct i40e_pf *pf = vsi->back;
7848 u8 enabled_tc = 0, num_tc, hw;
7849 bool need_reset = false;
7850 int old_queue_pairs;
7855 old_queue_pairs = vsi->num_queue_pairs;
7856 num_tc = mqprio_qopt->qopt.num_tc;
7857 hw = mqprio_qopt->qopt.hw;
7858 mode = mqprio_qopt->mode;
7860 pf->flags &= ~I40E_FLAG_TC_MQPRIO;
7861 memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt));
7865 /* Check if MFP enabled */
7866 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
7868 "Configuring TC not supported in MFP mode\n");
7872 case TC_MQPRIO_MODE_DCB:
7873 pf->flags &= ~I40E_FLAG_TC_MQPRIO;
7875 /* Check if DCB enabled to continue */
7876 if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
7878 "DCB is not enabled for adapter\n");
7882 /* Check whether tc count is within enabled limit */
7883 if (num_tc > i40e_pf_get_num_tc(pf)) {
7885 "TC count greater than enabled on link for adapter\n");
7889 case TC_MQPRIO_MODE_CHANNEL:
7890 if (pf->flags & I40E_FLAG_DCB_ENABLED) {
7892 "Full offload of TC Mqprio options is not supported when DCB is enabled\n");
7895 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
7897 ret = i40e_validate_mqprio_qopt(vsi, mqprio_qopt);
7900 memcpy(&vsi->mqprio_qopt, mqprio_qopt,
7901 sizeof(*mqprio_qopt));
7902 pf->flags |= I40E_FLAG_TC_MQPRIO;
7903 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
7910 /* Generate TC map for number of tc requested */
7911 for (i = 0; i < num_tc; i++)
7912 enabled_tc |= BIT(i);
7914 /* Requesting same TC configuration as already enabled */
7915 if (enabled_tc == vsi->tc_config.enabled_tc &&
7916 mode != TC_MQPRIO_MODE_CHANNEL)
7919 /* Quiesce VSI queues */
7920 i40e_quiesce_vsi(vsi);
7922 if (!hw && !(pf->flags & I40E_FLAG_TC_MQPRIO))
7923 i40e_remove_queue_channels(vsi);
7925 /* Configure VSI for enabled TCs */
7926 ret = i40e_vsi_config_tc(vsi, enabled_tc);
7928 netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
7933 dev_info(&vsi->back->pdev->dev,
7934 "Setup channel (id:%u) utilizing num_queues %d\n",
7935 vsi->seid, vsi->tc_config.tc_info[0].qcount);
7938 if (pf->flags & I40E_FLAG_TC_MQPRIO) {
7939 if (vsi->mqprio_qopt.max_rate[0]) {
7940 u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
7942 do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
7943 ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
7945 u64 credits = max_tx_rate;
7947 do_div(credits, I40E_BW_CREDIT_DIVISOR);
7948 dev_dbg(&vsi->back->pdev->dev,
7949 "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
7958 ret = i40e_configure_queue_channels(vsi);
7960 vsi->num_queue_pairs = old_queue_pairs;
7962 "Failed configuring queue channels\n");
7969 /* Reset the configuration data to defaults, only TC0 is enabled */
7971 i40e_vsi_set_default_tc_config(vsi);
7976 i40e_unquiesce_vsi(vsi);
7981 * i40e_set_cld_element - sets cloud filter element data
7982 * @filter: cloud filter rule
7983 * @cld: ptr to cloud filter element data
7985 * This is helper function to copy data into cloud filter element
7988 i40e_set_cld_element(struct i40e_cloud_filter *filter,
7989 struct i40e_aqc_cloud_filters_element_data *cld)
7994 memset(cld, 0, sizeof(*cld));
7995 ether_addr_copy(cld->outer_mac, filter->dst_mac);
7996 ether_addr_copy(cld->inner_mac, filter->src_mac);
7998 if (filter->n_proto != ETH_P_IP && filter->n_proto != ETH_P_IPV6)
8001 if (filter->n_proto == ETH_P_IPV6) {
8002 #define IPV6_MAX_INDEX (ARRAY_SIZE(filter->dst_ipv6) - 1)
8003 for (i = 0; i < ARRAY_SIZE(filter->dst_ipv6); i++) {
8004 ipa = be32_to_cpu(filter->dst_ipv6[IPV6_MAX_INDEX - i]);
8006 *(__le32 *)&cld->ipaddr.raw_v6.data[i * 2] = cpu_to_le32(ipa);
8009 ipa = be32_to_cpu(filter->dst_ipv4);
8011 memcpy(&cld->ipaddr.v4.data, &ipa, sizeof(ipa));
8014 cld->inner_vlan = cpu_to_le16(ntohs(filter->vlan_id));
8016 /* tenant_id is not supported by FW now, once the support is enabled
8017 * fill the cld->tenant_id with cpu_to_le32(filter->tenant_id)
8019 if (filter->tenant_id)
8024 * i40e_add_del_cloud_filter - Add/del cloud filter
8025 * @vsi: pointer to VSI
8026 * @filter: cloud filter rule
8027 * @add: if true, add, if false, delete
8029 * Add or delete a cloud filter for a specific flow spec.
8030 * Returns 0 if the filter were successfully added.
8032 int i40e_add_del_cloud_filter(struct i40e_vsi *vsi,
8033 struct i40e_cloud_filter *filter, bool add)
8035 struct i40e_aqc_cloud_filters_element_data cld_filter;
8036 struct i40e_pf *pf = vsi->back;
8038 static const u16 flag_table[128] = {
8039 [I40E_CLOUD_FILTER_FLAGS_OMAC] =
8040 I40E_AQC_ADD_CLOUD_FILTER_OMAC,
8041 [I40E_CLOUD_FILTER_FLAGS_IMAC] =
8042 I40E_AQC_ADD_CLOUD_FILTER_IMAC,
8043 [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN] =
8044 I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN,
8045 [I40E_CLOUD_FILTER_FLAGS_IMAC_TEN_ID] =
8046 I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID,
8047 [I40E_CLOUD_FILTER_FLAGS_OMAC_TEN_ID_IMAC] =
8048 I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC,
8049 [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN_TEN_ID] =
8050 I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID,
8051 [I40E_CLOUD_FILTER_FLAGS_IIP] =
8052 I40E_AQC_ADD_CLOUD_FILTER_IIP,
8055 if (filter->flags >= ARRAY_SIZE(flag_table))
8056 return I40E_ERR_CONFIG;
8058 memset(&cld_filter, 0, sizeof(cld_filter));
8060 /* copy element needed to add cloud filter from filter */
8061 i40e_set_cld_element(filter, &cld_filter);
8063 if (filter->tunnel_type != I40E_CLOUD_TNL_TYPE_NONE)
8064 cld_filter.flags = cpu_to_le16(filter->tunnel_type <<
8065 I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT);
8067 if (filter->n_proto == ETH_P_IPV6)
8068 cld_filter.flags |= cpu_to_le16(flag_table[filter->flags] |
8069 I40E_AQC_ADD_CLOUD_FLAGS_IPV6);
8071 cld_filter.flags |= cpu_to_le16(flag_table[filter->flags] |
8072 I40E_AQC_ADD_CLOUD_FLAGS_IPV4);
8075 ret = i40e_aq_add_cloud_filters(&pf->hw, filter->seid,
8078 ret = i40e_aq_rem_cloud_filters(&pf->hw, filter->seid,
8081 dev_dbg(&pf->pdev->dev,
8082 "Failed to %s cloud filter using l4 port %u, err %d aq_err %d\n",
8083 add ? "add" : "delete", filter->dst_port, ret,
8084 pf->hw.aq.asq_last_status);
8086 dev_info(&pf->pdev->dev,
8087 "%s cloud filter for VSI: %d\n",
8088 add ? "Added" : "Deleted", filter->seid);
8093 * i40e_add_del_cloud_filter_big_buf - Add/del cloud filter using big_buf
8094 * @vsi: pointer to VSI
8095 * @filter: cloud filter rule
8096 * @add: if true, add, if false, delete
8098 * Add or delete a cloud filter for a specific flow spec using big buffer.
8099 * Returns 0 if the filter were successfully added.
8101 int i40e_add_del_cloud_filter_big_buf(struct i40e_vsi *vsi,
8102 struct i40e_cloud_filter *filter,
8105 struct i40e_aqc_cloud_filters_element_bb cld_filter;
8106 struct i40e_pf *pf = vsi->back;
8109 /* Both (src/dst) valid mac_addr are not supported */
8110 if ((is_valid_ether_addr(filter->dst_mac) &&
8111 is_valid_ether_addr(filter->src_mac)) ||
8112 (is_multicast_ether_addr(filter->dst_mac) &&
8113 is_multicast_ether_addr(filter->src_mac)))
8116 /* Big buffer cloud filter needs 'L4 port' to be non-zero. Also, UDP
8117 * ports are not supported via big buffer now.
8119 if (!filter->dst_port || filter->ip_proto == IPPROTO_UDP)
8122 /* adding filter using src_port/src_ip is not supported at this stage */
8123 if (filter->src_port ||
8124 (filter->src_ipv4 && filter->n_proto != ETH_P_IPV6) ||
8125 !ipv6_addr_any(&filter->ip.v6.src_ip6))
8128 memset(&cld_filter, 0, sizeof(cld_filter));
8130 /* copy element needed to add cloud filter from filter */
8131 i40e_set_cld_element(filter, &cld_filter.element);
8133 if (is_valid_ether_addr(filter->dst_mac) ||
8134 is_valid_ether_addr(filter->src_mac) ||
8135 is_multicast_ether_addr(filter->dst_mac) ||
8136 is_multicast_ether_addr(filter->src_mac)) {
8137 /* MAC + IP : unsupported mode */
8138 if (filter->dst_ipv4)
8141 /* since we validated that L4 port must be valid before
8142 * we get here, start with respective "flags" value
8143 * and update if vlan is present or not
8145 cld_filter.element.flags =
8146 cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_PORT);
8148 if (filter->vlan_id) {
8149 cld_filter.element.flags =
8150 cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_VLAN_PORT);
8153 } else if ((filter->dst_ipv4 && filter->n_proto != ETH_P_IPV6) ||
8154 !ipv6_addr_any(&filter->ip.v6.dst_ip6)) {
8155 cld_filter.element.flags =
8156 cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_IP_PORT);
8157 if (filter->n_proto == ETH_P_IPV6)
8158 cld_filter.element.flags |=
8159 cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV6);
8161 cld_filter.element.flags |=
8162 cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV4);
8164 dev_err(&pf->pdev->dev,
8165 "either mac or ip has to be valid for cloud filter\n");
8169 /* Now copy L4 port in Byte 6..7 in general fields */
8170 cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X16_WORD0] =
8171 be16_to_cpu(filter->dst_port);
8174 /* Validate current device switch mode, change if necessary */
8175 ret = i40e_validate_and_set_switch_mode(vsi);
8177 dev_err(&pf->pdev->dev,
8178 "failed to set switch mode, ret %d\n",
8183 ret = i40e_aq_add_cloud_filters_bb(&pf->hw, filter->seid,
8186 ret = i40e_aq_rem_cloud_filters_bb(&pf->hw, filter->seid,
8191 dev_dbg(&pf->pdev->dev,
8192 "Failed to %s cloud filter(big buffer) err %d aq_err %d\n",
8193 add ? "add" : "delete", ret, pf->hw.aq.asq_last_status);
8195 dev_info(&pf->pdev->dev,
8196 "%s cloud filter for VSI: %d, L4 port: %d\n",
8197 add ? "add" : "delete", filter->seid,
8198 ntohs(filter->dst_port));
8203 * i40e_parse_cls_flower - Parse tc flower filters provided by kernel
8204 * @vsi: Pointer to VSI
8205 * @f: Pointer to struct flow_cls_offload
8206 * @filter: Pointer to cloud filter structure
8209 static int i40e_parse_cls_flower(struct i40e_vsi *vsi,
8210 struct flow_cls_offload *f,
8211 struct i40e_cloud_filter *filter)
8213 struct flow_rule *rule = flow_cls_offload_flow_rule(f);
8214 struct flow_dissector *dissector = rule->match.dissector;
8215 u16 n_proto_mask = 0, n_proto_key = 0, addr_type = 0;
8216 struct i40e_pf *pf = vsi->back;
8219 if (dissector->used_keys &
8220 ~(BIT(FLOW_DISSECTOR_KEY_CONTROL) |
8221 BIT(FLOW_DISSECTOR_KEY_BASIC) |
8222 BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) |
8223 BIT(FLOW_DISSECTOR_KEY_VLAN) |
8224 BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
8225 BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
8226 BIT(FLOW_DISSECTOR_KEY_PORTS) |
8227 BIT(FLOW_DISSECTOR_KEY_ENC_KEYID))) {
8228 dev_err(&pf->pdev->dev, "Unsupported key used: 0x%x\n",
8229 dissector->used_keys);
8233 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_KEYID)) {
8234 struct flow_match_enc_keyid match;
8236 flow_rule_match_enc_keyid(rule, &match);
8237 if (match.mask->keyid != 0)
8238 field_flags |= I40E_CLOUD_FIELD_TEN_ID;
8240 filter->tenant_id = be32_to_cpu(match.key->keyid);
8243 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) {
8244 struct flow_match_basic match;
8246 flow_rule_match_basic(rule, &match);
8247 n_proto_key = ntohs(match.key->n_proto);
8248 n_proto_mask = ntohs(match.mask->n_proto);
8250 if (n_proto_key == ETH_P_ALL) {
8254 filter->n_proto = n_proto_key & n_proto_mask;
8255 filter->ip_proto = match.key->ip_proto;
8258 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
8259 struct flow_match_eth_addrs match;
8261 flow_rule_match_eth_addrs(rule, &match);
8263 /* use is_broadcast and is_zero to check for all 0xf or 0 */
8264 if (!is_zero_ether_addr(match.mask->dst)) {
8265 if (is_broadcast_ether_addr(match.mask->dst)) {
8266 field_flags |= I40E_CLOUD_FIELD_OMAC;
8268 dev_err(&pf->pdev->dev, "Bad ether dest mask %pM\n",
8270 return I40E_ERR_CONFIG;
8274 if (!is_zero_ether_addr(match.mask->src)) {
8275 if (is_broadcast_ether_addr(match.mask->src)) {
8276 field_flags |= I40E_CLOUD_FIELD_IMAC;
8278 dev_err(&pf->pdev->dev, "Bad ether src mask %pM\n",
8280 return I40E_ERR_CONFIG;
8283 ether_addr_copy(filter->dst_mac, match.key->dst);
8284 ether_addr_copy(filter->src_mac, match.key->src);
8287 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_VLAN)) {
8288 struct flow_match_vlan match;
8290 flow_rule_match_vlan(rule, &match);
8291 if (match.mask->vlan_id) {
8292 if (match.mask->vlan_id == VLAN_VID_MASK) {
8293 field_flags |= I40E_CLOUD_FIELD_IVLAN;
8296 dev_err(&pf->pdev->dev, "Bad vlan mask 0x%04x\n",
8297 match.mask->vlan_id);
8298 return I40E_ERR_CONFIG;
8302 filter->vlan_id = cpu_to_be16(match.key->vlan_id);
8305 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL)) {
8306 struct flow_match_control match;
8308 flow_rule_match_control(rule, &match);
8309 addr_type = match.key->addr_type;
8312 if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
8313 struct flow_match_ipv4_addrs match;
8315 flow_rule_match_ipv4_addrs(rule, &match);
8316 if (match.mask->dst) {
8317 if (match.mask->dst == cpu_to_be32(0xffffffff)) {
8318 field_flags |= I40E_CLOUD_FIELD_IIP;
8320 dev_err(&pf->pdev->dev, "Bad ip dst mask %pI4b\n",
8322 return I40E_ERR_CONFIG;
8326 if (match.mask->src) {
8327 if (match.mask->src == cpu_to_be32(0xffffffff)) {
8328 field_flags |= I40E_CLOUD_FIELD_IIP;
8330 dev_err(&pf->pdev->dev, "Bad ip src mask %pI4b\n",
8332 return I40E_ERR_CONFIG;
8336 if (field_flags & I40E_CLOUD_FIELD_TEN_ID) {
8337 dev_err(&pf->pdev->dev, "Tenant id not allowed for ip filter\n");
8338 return I40E_ERR_CONFIG;
8340 filter->dst_ipv4 = match.key->dst;
8341 filter->src_ipv4 = match.key->src;
8344 if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) {
8345 struct flow_match_ipv6_addrs match;
8347 flow_rule_match_ipv6_addrs(rule, &match);
8349 /* src and dest IPV6 address should not be LOOPBACK
8350 * (0:0:0:0:0:0:0:1), which can be represented as ::1
8352 if (ipv6_addr_loopback(&match.key->dst) ||
8353 ipv6_addr_loopback(&match.key->src)) {
8354 dev_err(&pf->pdev->dev,
8355 "Bad ipv6, addr is LOOPBACK\n");
8356 return I40E_ERR_CONFIG;
8358 if (!ipv6_addr_any(&match.mask->dst) ||
8359 !ipv6_addr_any(&match.mask->src))
8360 field_flags |= I40E_CLOUD_FIELD_IIP;
8362 memcpy(&filter->src_ipv6, &match.key->src.s6_addr32,
8363 sizeof(filter->src_ipv6));
8364 memcpy(&filter->dst_ipv6, &match.key->dst.s6_addr32,
8365 sizeof(filter->dst_ipv6));
8368 if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_PORTS)) {
8369 struct flow_match_ports match;
8371 flow_rule_match_ports(rule, &match);
8372 if (match.mask->src) {
8373 if (match.mask->src == cpu_to_be16(0xffff)) {
8374 field_flags |= I40E_CLOUD_FIELD_IIP;
8376 dev_err(&pf->pdev->dev, "Bad src port mask 0x%04x\n",
8377 be16_to_cpu(match.mask->src));
8378 return I40E_ERR_CONFIG;
8382 if (match.mask->dst) {
8383 if (match.mask->dst == cpu_to_be16(0xffff)) {
8384 field_flags |= I40E_CLOUD_FIELD_IIP;
8386 dev_err(&pf->pdev->dev, "Bad dst port mask 0x%04x\n",
8387 be16_to_cpu(match.mask->dst));
8388 return I40E_ERR_CONFIG;
8392 filter->dst_port = match.key->dst;
8393 filter->src_port = match.key->src;
8395 switch (filter->ip_proto) {
8400 dev_err(&pf->pdev->dev,
8401 "Only UDP and TCP transport are supported\n");
8405 filter->flags = field_flags;
8410 * i40e_handle_tclass: Forward to a traffic class on the device
8411 * @vsi: Pointer to VSI
8412 * @tc: traffic class index on the device
8413 * @filter: Pointer to cloud filter structure
8416 static int i40e_handle_tclass(struct i40e_vsi *vsi, u32 tc,
8417 struct i40e_cloud_filter *filter)
8419 struct i40e_channel *ch, *ch_tmp;
8421 /* direct to a traffic class on the same device */
8423 filter->seid = vsi->seid;
8425 } else if (vsi->tc_config.enabled_tc & BIT(tc)) {
8426 if (!filter->dst_port) {
8427 dev_err(&vsi->back->pdev->dev,
8428 "Specify destination port to direct to traffic class that is not default\n");
8431 if (list_empty(&vsi->ch_list))
8433 list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list,
8435 if (ch->seid == vsi->tc_seid_map[tc])
8436 filter->seid = ch->seid;
8440 dev_err(&vsi->back->pdev->dev, "TC is not enabled\n");
8445 * i40e_configure_clsflower - Configure tc flower filters
8446 * @vsi: Pointer to VSI
8447 * @cls_flower: Pointer to struct flow_cls_offload
8450 static int i40e_configure_clsflower(struct i40e_vsi *vsi,
8451 struct flow_cls_offload *cls_flower)
8453 int tc = tc_classid_to_hwtc(vsi->netdev, cls_flower->classid);
8454 struct i40e_cloud_filter *filter = NULL;
8455 struct i40e_pf *pf = vsi->back;
8459 dev_err(&vsi->back->pdev->dev, "Invalid traffic class\n");
8463 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
8464 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
8467 if (pf->fdir_pf_active_filters ||
8468 (!hlist_empty(&pf->fdir_filter_list))) {
8469 dev_err(&vsi->back->pdev->dev,
8470 "Flow Director Sideband filters exists, turn ntuple off to configure cloud filters\n");
8474 if (vsi->back->flags & I40E_FLAG_FD_SB_ENABLED) {
8475 dev_err(&vsi->back->pdev->dev,
8476 "Disable Flow Director Sideband, configuring Cloud filters via tc-flower\n");
8477 vsi->back->flags &= ~I40E_FLAG_FD_SB_ENABLED;
8478 vsi->back->flags |= I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
8481 filter = kzalloc(sizeof(*filter), GFP_KERNEL);
8485 filter->cookie = cls_flower->cookie;
8487 err = i40e_parse_cls_flower(vsi, cls_flower, filter);
8491 err = i40e_handle_tclass(vsi, tc, filter);
8495 /* Add cloud filter */
8496 if (filter->dst_port)
8497 err = i40e_add_del_cloud_filter_big_buf(vsi, filter, true);
8499 err = i40e_add_del_cloud_filter(vsi, filter, true);
8502 dev_err(&pf->pdev->dev,
8503 "Failed to add cloud filter, err %s\n",
8504 i40e_stat_str(&pf->hw, err));
8508 /* add filter to the ordered list */
8509 INIT_HLIST_NODE(&filter->cloud_node);
8511 hlist_add_head(&filter->cloud_node, &pf->cloud_filter_list);
8513 pf->num_cloud_filters++;
8522 * i40e_find_cloud_filter - Find the could filter in the list
8523 * @vsi: Pointer to VSI
8524 * @cookie: filter specific cookie
8527 static struct i40e_cloud_filter *i40e_find_cloud_filter(struct i40e_vsi *vsi,
8528 unsigned long *cookie)
8530 struct i40e_cloud_filter *filter = NULL;
8531 struct hlist_node *node2;
8533 hlist_for_each_entry_safe(filter, node2,
8534 &vsi->back->cloud_filter_list, cloud_node)
8535 if (!memcmp(cookie, &filter->cookie, sizeof(filter->cookie)))
8541 * i40e_delete_clsflower - Remove tc flower filters
8542 * @vsi: Pointer to VSI
8543 * @cls_flower: Pointer to struct flow_cls_offload
8546 static int i40e_delete_clsflower(struct i40e_vsi *vsi,
8547 struct flow_cls_offload *cls_flower)
8549 struct i40e_cloud_filter *filter = NULL;
8550 struct i40e_pf *pf = vsi->back;
8553 filter = i40e_find_cloud_filter(vsi, &cls_flower->cookie);
8558 hash_del(&filter->cloud_node);
8560 if (filter->dst_port)
8561 err = i40e_add_del_cloud_filter_big_buf(vsi, filter, false);
8563 err = i40e_add_del_cloud_filter(vsi, filter, false);
8567 dev_err(&pf->pdev->dev,
8568 "Failed to delete cloud filter, err %s\n",
8569 i40e_stat_str(&pf->hw, err));
8570 return i40e_aq_rc_to_posix(err, pf->hw.aq.asq_last_status);
8573 pf->num_cloud_filters--;
8574 if (!pf->num_cloud_filters)
8575 if ((pf->flags & I40E_FLAG_FD_SB_TO_CLOUD_FILTER) &&
8576 !(pf->flags & I40E_FLAG_FD_SB_INACTIVE)) {
8577 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
8578 pf->flags &= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
8579 pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
8585 * i40e_setup_tc_cls_flower - flower classifier offloads
8586 * @np: net device to configure
8587 * @cls_flower: offload data
8589 static int i40e_setup_tc_cls_flower(struct i40e_netdev_priv *np,
8590 struct flow_cls_offload *cls_flower)
8592 struct i40e_vsi *vsi = np->vsi;
8594 switch (cls_flower->command) {
8595 case FLOW_CLS_REPLACE:
8596 return i40e_configure_clsflower(vsi, cls_flower);
8597 case FLOW_CLS_DESTROY:
8598 return i40e_delete_clsflower(vsi, cls_flower);
8599 case FLOW_CLS_STATS:
8606 static int i40e_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
8609 struct i40e_netdev_priv *np = cb_priv;
8611 if (!tc_cls_can_offload_and_chain0(np->vsi->netdev, type_data))
8615 case TC_SETUP_CLSFLOWER:
8616 return i40e_setup_tc_cls_flower(np, type_data);
8623 static LIST_HEAD(i40e_block_cb_list);
8625 static int __i40e_setup_tc(struct net_device *netdev, enum tc_setup_type type,
8628 struct i40e_netdev_priv *np = netdev_priv(netdev);
8631 case TC_SETUP_QDISC_MQPRIO:
8632 return i40e_setup_tc(netdev, type_data);
8633 case TC_SETUP_BLOCK:
8634 return flow_block_cb_setup_simple(type_data,
8635 &i40e_block_cb_list,
8636 i40e_setup_tc_block_cb,
8644 * i40e_open - Called when a network interface is made active
8645 * @netdev: network interface device structure
8647 * The open entry point is called when a network interface is made
8648 * active by the system (IFF_UP). At this point all resources needed
8649 * for transmit and receive operations are allocated, the interrupt
8650 * handler is registered with the OS, the netdev watchdog subtask is
8651 * enabled, and the stack is notified that the interface is ready.
8653 * Returns 0 on success, negative value on failure
8655 int i40e_open(struct net_device *netdev)
8657 struct i40e_netdev_priv *np = netdev_priv(netdev);
8658 struct i40e_vsi *vsi = np->vsi;
8659 struct i40e_pf *pf = vsi->back;
8662 /* disallow open during test or if eeprom is broken */
8663 if (test_bit(__I40E_TESTING, pf->state) ||
8664 test_bit(__I40E_BAD_EEPROM, pf->state))
8667 netif_carrier_off(netdev);
8669 if (i40e_force_link_state(pf, true))
8672 err = i40e_vsi_open(vsi);
8676 /* configure global TSO hardware offload settings */
8677 wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
8678 TCP_FLAG_FIN) >> 16);
8679 wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
8681 TCP_FLAG_CWR) >> 16);
8682 wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
8683 udp_tunnel_get_rx_info(netdev);
8690 * @vsi: the VSI to open
8692 * Finish initialization of the VSI.
8694 * Returns 0 on success, negative value on failure
8696 * Note: expects to be called while under rtnl_lock()
8698 int i40e_vsi_open(struct i40e_vsi *vsi)
8700 struct i40e_pf *pf = vsi->back;
8701 char int_name[I40E_INT_NAME_STR_LEN];
8704 /* allocate descriptors */
8705 err = i40e_vsi_setup_tx_resources(vsi);
8708 err = i40e_vsi_setup_rx_resources(vsi);
8712 err = i40e_vsi_configure(vsi);
8717 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
8718 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
8719 err = i40e_vsi_request_irq(vsi, int_name);
8723 /* Notify the stack of the actual queue counts. */
8724 err = netif_set_real_num_tx_queues(vsi->netdev,
8725 vsi->num_queue_pairs);
8727 goto err_set_queues;
8729 err = netif_set_real_num_rx_queues(vsi->netdev,
8730 vsi->num_queue_pairs);
8732 goto err_set_queues;
8734 } else if (vsi->type == I40E_VSI_FDIR) {
8735 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
8736 dev_driver_string(&pf->pdev->dev),
8737 dev_name(&pf->pdev->dev));
8738 err = i40e_vsi_request_irq(vsi, int_name);
8745 err = i40e_up_complete(vsi);
8747 goto err_up_complete;
8754 i40e_vsi_free_irq(vsi);
8756 i40e_vsi_free_rx_resources(vsi);
8758 i40e_vsi_free_tx_resources(vsi);
8759 if (vsi == pf->vsi[pf->lan_vsi])
8760 i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
8766 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
8767 * @pf: Pointer to PF
8769 * This function destroys the hlist where all the Flow Director
8770 * filters were saved.
8772 static void i40e_fdir_filter_exit(struct i40e_pf *pf)
8774 struct i40e_fdir_filter *filter;
8775 struct i40e_flex_pit *pit_entry, *tmp;
8776 struct hlist_node *node2;
8778 hlist_for_each_entry_safe(filter, node2,
8779 &pf->fdir_filter_list, fdir_node) {
8780 hlist_del(&filter->fdir_node);
8784 list_for_each_entry_safe(pit_entry, tmp, &pf->l3_flex_pit_list, list) {
8785 list_del(&pit_entry->list);
8788 INIT_LIST_HEAD(&pf->l3_flex_pit_list);
8790 list_for_each_entry_safe(pit_entry, tmp, &pf->l4_flex_pit_list, list) {
8791 list_del(&pit_entry->list);
8794 INIT_LIST_HEAD(&pf->l4_flex_pit_list);
8796 pf->fdir_pf_active_filters = 0;
8797 i40e_reset_fdir_filter_cnt(pf);
8799 /* Reprogram the default input set for TCP/IPv4 */
8800 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
8801 I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
8802 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
8804 /* Reprogram the default input set for TCP/IPv6 */
8805 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV6_TCP,
8806 I40E_L3_V6_SRC_MASK | I40E_L3_V6_DST_MASK |
8807 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
8809 /* Reprogram the default input set for UDP/IPv4 */
8810 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_UDP,
8811 I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
8812 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
8814 /* Reprogram the default input set for UDP/IPv6 */
8815 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV6_UDP,
8816 I40E_L3_V6_SRC_MASK | I40E_L3_V6_DST_MASK |
8817 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
8819 /* Reprogram the default input set for SCTP/IPv4 */
8820 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_SCTP,
8821 I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
8822 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
8824 /* Reprogram the default input set for SCTP/IPv6 */
8825 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV6_SCTP,
8826 I40E_L3_V6_SRC_MASK | I40E_L3_V6_DST_MASK |
8827 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
8829 /* Reprogram the default input set for Other/IPv4 */
8830 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_OTHER,
8831 I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
8833 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_FRAG_IPV4,
8834 I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
8836 /* Reprogram the default input set for Other/IPv6 */
8837 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV6_OTHER,
8838 I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
8840 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_FRAG_IPV6,
8841 I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
8845 * i40e_cloud_filter_exit - Cleans up the cloud filters
8846 * @pf: Pointer to PF
8848 * This function destroys the hlist where all the cloud filters
8851 static void i40e_cloud_filter_exit(struct i40e_pf *pf)
8853 struct i40e_cloud_filter *cfilter;
8854 struct hlist_node *node;
8856 hlist_for_each_entry_safe(cfilter, node,
8857 &pf->cloud_filter_list, cloud_node) {
8858 hlist_del(&cfilter->cloud_node);
8861 pf->num_cloud_filters = 0;
8863 if ((pf->flags & I40E_FLAG_FD_SB_TO_CLOUD_FILTER) &&
8864 !(pf->flags & I40E_FLAG_FD_SB_INACTIVE)) {
8865 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
8866 pf->flags &= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
8867 pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
8872 * i40e_close - Disables a network interface
8873 * @netdev: network interface device structure
8875 * The close entry point is called when an interface is de-activated
8876 * by the OS. The hardware is still under the driver's control, but
8877 * this netdev interface is disabled.
8879 * Returns 0, this is not allowed to fail
8881 int i40e_close(struct net_device *netdev)
8883 struct i40e_netdev_priv *np = netdev_priv(netdev);
8884 struct i40e_vsi *vsi = np->vsi;
8886 i40e_vsi_close(vsi);
8892 * i40e_do_reset - Start a PF or Core Reset sequence
8893 * @pf: board private structure
8894 * @reset_flags: which reset is requested
8895 * @lock_acquired: indicates whether or not the lock has been acquired
8896 * before this function was called.
8898 * The essential difference in resets is that the PF Reset
8899 * doesn't clear the packet buffers, doesn't reset the PE
8900 * firmware, and doesn't bother the other PFs on the chip.
8902 void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags, bool lock_acquired)
8906 /* do the biggest reset indicated */
8907 if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
8909 /* Request a Global Reset
8911 * This will start the chip's countdown to the actual full
8912 * chip reset event, and a warning interrupt to be sent
8913 * to all PFs, including the requestor. Our handler
8914 * for the warning interrupt will deal with the shutdown
8915 * and recovery of the switch setup.
8917 dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
8918 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
8919 val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
8920 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
8922 } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
8924 /* Request a Core Reset
8926 * Same as Global Reset, except does *not* include the MAC/PHY
8928 dev_dbg(&pf->pdev->dev, "CoreR requested\n");
8929 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
8930 val |= I40E_GLGEN_RTRIG_CORER_MASK;
8931 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
8932 i40e_flush(&pf->hw);
8934 } else if (reset_flags & I40E_PF_RESET_FLAG) {
8936 /* Request a PF Reset
8938 * Resets only the PF-specific registers
8940 * This goes directly to the tear-down and rebuild of
8941 * the switch, since we need to do all the recovery as
8942 * for the Core Reset.
8944 dev_dbg(&pf->pdev->dev, "PFR requested\n");
8945 i40e_handle_reset_warning(pf, lock_acquired);
8947 } else if (reset_flags & I40E_PF_RESET_AND_REBUILD_FLAG) {
8948 /* Request a PF Reset
8950 * Resets PF and reinitializes PFs VSI.
8952 i40e_prep_for_reset(pf);
8953 i40e_reset_and_rebuild(pf, true, lock_acquired);
8954 dev_info(&pf->pdev->dev,
8955 pf->flags & I40E_FLAG_DISABLE_FW_LLDP ?
8956 "FW LLDP is disabled\n" :
8957 "FW LLDP is enabled\n");
8959 } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
8962 /* Find the VSI(s) that requested a re-init */
8963 dev_info(&pf->pdev->dev,
8964 "VSI reinit requested\n");
8965 for (v = 0; v < pf->num_alloc_vsi; v++) {
8966 struct i40e_vsi *vsi = pf->vsi[v];
8969 test_and_clear_bit(__I40E_VSI_REINIT_REQUESTED,
8971 i40e_vsi_reinit_locked(pf->vsi[v]);
8973 } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
8976 /* Find the VSI(s) that needs to be brought down */
8977 dev_info(&pf->pdev->dev, "VSI down requested\n");
8978 for (v = 0; v < pf->num_alloc_vsi; v++) {
8979 struct i40e_vsi *vsi = pf->vsi[v];
8982 test_and_clear_bit(__I40E_VSI_DOWN_REQUESTED,
8984 set_bit(__I40E_VSI_DOWN, vsi->state);
8989 dev_info(&pf->pdev->dev,
8990 "bad reset request 0x%08x\n", reset_flags);
8994 #ifdef CONFIG_I40E_DCB
8996 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
8997 * @pf: board private structure
8998 * @old_cfg: current DCB config
8999 * @new_cfg: new DCB config
9001 bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
9002 struct i40e_dcbx_config *old_cfg,
9003 struct i40e_dcbx_config *new_cfg)
9005 bool need_reconfig = false;
9007 /* Check if ETS configuration has changed */
9008 if (memcmp(&new_cfg->etscfg,
9010 sizeof(new_cfg->etscfg))) {
9011 /* If Priority Table has changed reconfig is needed */
9012 if (memcmp(&new_cfg->etscfg.prioritytable,
9013 &old_cfg->etscfg.prioritytable,
9014 sizeof(new_cfg->etscfg.prioritytable))) {
9015 need_reconfig = true;
9016 dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
9019 if (memcmp(&new_cfg->etscfg.tcbwtable,
9020 &old_cfg->etscfg.tcbwtable,
9021 sizeof(new_cfg->etscfg.tcbwtable)))
9022 dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
9024 if (memcmp(&new_cfg->etscfg.tsatable,
9025 &old_cfg->etscfg.tsatable,
9026 sizeof(new_cfg->etscfg.tsatable)))
9027 dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
9030 /* Check if PFC configuration has changed */
9031 if (memcmp(&new_cfg->pfc,
9033 sizeof(new_cfg->pfc))) {
9034 need_reconfig = true;
9035 dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
9038 /* Check if APP Table has changed */
9039 if (memcmp(&new_cfg->app,
9041 sizeof(new_cfg->app))) {
9042 need_reconfig = true;
9043 dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
9046 dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
9047 return need_reconfig;
9051 * i40e_handle_lldp_event - Handle LLDP Change MIB event
9052 * @pf: board private structure
9053 * @e: event info posted on ARQ
9055 static int i40e_handle_lldp_event(struct i40e_pf *pf,
9056 struct i40e_arq_event_info *e)
9058 struct i40e_aqc_lldp_get_mib *mib =
9059 (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
9060 struct i40e_hw *hw = &pf->hw;
9061 struct i40e_dcbx_config tmp_dcbx_cfg;
9062 bool need_reconfig = false;
9066 /* X710-T*L 2.5G and 5G speeds don't support DCB */
9067 if (I40E_IS_X710TL_DEVICE(hw->device_id) &&
9068 (hw->phy.link_info.link_speed &
9069 ~(I40E_LINK_SPEED_2_5GB | I40E_LINK_SPEED_5GB)) &&
9070 !(pf->flags & I40E_FLAG_DCB_CAPABLE))
9071 /* let firmware decide if the DCB should be disabled */
9072 pf->flags |= I40E_FLAG_DCB_CAPABLE;
9074 /* Not DCB capable or capability disabled */
9075 if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
9078 /* Ignore if event is not for Nearest Bridge */
9079 type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
9080 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
9081 dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
9082 if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
9085 /* Check MIB Type and return if event for Remote MIB update */
9086 type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
9087 dev_dbg(&pf->pdev->dev,
9088 "LLDP event mib type %s\n", type ? "remote" : "local");
9089 if (type == I40E_AQ_LLDP_MIB_REMOTE) {
9090 /* Update the remote cached instance and return */
9091 ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
9092 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
9093 &hw->remote_dcbx_config);
9097 /* Store the old configuration */
9098 tmp_dcbx_cfg = hw->local_dcbx_config;
9100 /* Reset the old DCBx configuration data */
9101 memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
9102 /* Get updated DCBX data from firmware */
9103 ret = i40e_get_dcb_config(&pf->hw);
9105 /* X710-T*L 2.5G and 5G speeds don't support DCB */
9106 if (I40E_IS_X710TL_DEVICE(hw->device_id) &&
9107 (hw->phy.link_info.link_speed &
9108 (I40E_LINK_SPEED_2_5GB | I40E_LINK_SPEED_5GB))) {
9109 dev_warn(&pf->pdev->dev,
9110 "DCB is not supported for X710-T*L 2.5/5G speeds\n");
9111 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
9113 dev_info(&pf->pdev->dev,
9114 "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
9115 i40e_stat_str(&pf->hw, ret),
9116 i40e_aq_str(&pf->hw,
9117 pf->hw.aq.asq_last_status));
9122 /* No change detected in DCBX configs */
9123 if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
9124 sizeof(tmp_dcbx_cfg))) {
9125 dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
9129 need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
9130 &hw->local_dcbx_config);
9132 i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
9137 /* Enable DCB tagging only when more than one TC */
9138 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
9139 pf->flags |= I40E_FLAG_DCB_ENABLED;
9141 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
9143 set_bit(__I40E_PORT_SUSPENDED, pf->state);
9144 /* Reconfiguration needed quiesce all VSIs */
9145 i40e_pf_quiesce_all_vsi(pf);
9147 /* Changes in configuration update VEB/VSI */
9148 i40e_dcb_reconfigure(pf);
9150 ret = i40e_resume_port_tx(pf);
9152 clear_bit(__I40E_PORT_SUSPENDED, pf->state);
9153 /* In case of error no point in resuming VSIs */
9157 /* Wait for the PF's queues to be disabled */
9158 ret = i40e_pf_wait_queues_disabled(pf);
9160 /* Schedule PF reset to recover */
9161 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
9162 i40e_service_event_schedule(pf);
9164 i40e_pf_unquiesce_all_vsi(pf);
9165 set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
9166 set_bit(__I40E_CLIENT_L2_CHANGE, pf->state);
9172 #endif /* CONFIG_I40E_DCB */
9175 * i40e_do_reset_safe - Protected reset path for userland calls.
9176 * @pf: board private structure
9177 * @reset_flags: which reset is requested
9180 void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
9183 i40e_do_reset(pf, reset_flags, true);
9188 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
9189 * @pf: board private structure
9190 * @e: event info posted on ARQ
9192 * Handler for LAN Queue Overflow Event generated by the firmware for PF
9195 static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
9196 struct i40e_arq_event_info *e)
9198 struct i40e_aqc_lan_overflow *data =
9199 (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
9200 u32 queue = le32_to_cpu(data->prtdcb_rupto);
9201 u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
9202 struct i40e_hw *hw = &pf->hw;
9206 dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
9209 /* Queue belongs to VF, find the VF and issue VF reset */
9210 if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
9211 >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
9212 vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
9213 >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
9214 vf_id -= hw->func_caps.vf_base_id;
9215 vf = &pf->vf[vf_id];
9216 i40e_vc_notify_vf_reset(vf);
9217 /* Allow VF to process pending reset notification */
9219 i40e_reset_vf(vf, false);
9224 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
9225 * @pf: board private structure
9227 u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
9231 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
9232 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
9237 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
9238 * @pf: board private structure
9240 u32 i40e_get_current_fd_count(struct i40e_pf *pf)
9244 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
9245 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
9246 ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
9247 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
9252 * i40e_get_global_fd_count - Get total FD filters programmed on device
9253 * @pf: board private structure
9255 u32 i40e_get_global_fd_count(struct i40e_pf *pf)
9259 val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
9260 fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
9261 ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
9262 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
9267 * i40e_reenable_fdir_sb - Restore FDir SB capability
9268 * @pf: board private structure
9270 static void i40e_reenable_fdir_sb(struct i40e_pf *pf)
9272 if (test_and_clear_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state))
9273 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
9274 (I40E_DEBUG_FD & pf->hw.debug_mask))
9275 dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
9279 * i40e_reenable_fdir_atr - Restore FDir ATR capability
9280 * @pf: board private structure
9282 static void i40e_reenable_fdir_atr(struct i40e_pf *pf)
9284 if (test_and_clear_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state)) {
9285 /* ATR uses the same filtering logic as SB rules. It only
9286 * functions properly if the input set mask is at the default
9287 * settings. It is safe to restore the default input set
9288 * because there are no active TCPv4 filter rules.
9290 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
9291 I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
9292 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
9294 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
9295 (I40E_DEBUG_FD & pf->hw.debug_mask))
9296 dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n");
9301 * i40e_delete_invalid_filter - Delete an invalid FDIR filter
9302 * @pf: board private structure
9303 * @filter: FDir filter to remove
9305 static void i40e_delete_invalid_filter(struct i40e_pf *pf,
9306 struct i40e_fdir_filter *filter)
9308 /* Update counters */
9309 pf->fdir_pf_active_filters--;
9312 switch (filter->flow_type) {
9314 pf->fd_tcp4_filter_cnt--;
9317 pf->fd_udp4_filter_cnt--;
9320 pf->fd_sctp4_filter_cnt--;
9323 pf->fd_tcp6_filter_cnt--;
9326 pf->fd_udp6_filter_cnt--;
9329 pf->fd_udp6_filter_cnt--;
9332 switch (filter->ipl4_proto) {
9334 pf->fd_tcp4_filter_cnt--;
9337 pf->fd_udp4_filter_cnt--;
9340 pf->fd_sctp4_filter_cnt--;
9343 pf->fd_ip4_filter_cnt--;
9347 case IPV6_USER_FLOW:
9348 switch (filter->ipl4_proto) {
9350 pf->fd_tcp6_filter_cnt--;
9353 pf->fd_udp6_filter_cnt--;
9356 pf->fd_sctp6_filter_cnt--;
9359 pf->fd_ip6_filter_cnt--;
9365 /* Remove the filter from the list and free memory */
9366 hlist_del(&filter->fdir_node);
9371 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
9372 * @pf: board private structure
9374 void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
9376 struct i40e_fdir_filter *filter;
9377 u32 fcnt_prog, fcnt_avail;
9378 struct hlist_node *node;
9380 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
9383 /* Check if we have enough room to re-enable FDir SB capability. */
9384 fcnt_prog = i40e_get_global_fd_count(pf);
9385 fcnt_avail = pf->fdir_pf_filter_count;
9386 if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
9387 (pf->fd_add_err == 0) ||
9388 (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt))
9389 i40e_reenable_fdir_sb(pf);
9391 /* We should wait for even more space before re-enabling ATR.
9392 * Additionally, we cannot enable ATR as long as we still have TCP SB
9395 if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) &&
9396 pf->fd_tcp4_filter_cnt == 0 && pf->fd_tcp6_filter_cnt == 0)
9397 i40e_reenable_fdir_atr(pf);
9399 /* if hw had a problem adding a filter, delete it */
9400 if (pf->fd_inv > 0) {
9401 hlist_for_each_entry_safe(filter, node,
9402 &pf->fdir_filter_list, fdir_node)
9403 if (filter->fd_id == pf->fd_inv)
9404 i40e_delete_invalid_filter(pf, filter);
9408 #define I40E_MIN_FD_FLUSH_INTERVAL 10
9409 #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
9411 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
9412 * @pf: board private structure
9414 static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
9416 unsigned long min_flush_time;
9417 int flush_wait_retry = 50;
9418 bool disable_atr = false;
9422 if (!time_after(jiffies, pf->fd_flush_timestamp +
9423 (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
9426 /* If the flush is happening too quick and we have mostly SB rules we
9427 * should not re-enable ATR for some time.
9429 min_flush_time = pf->fd_flush_timestamp +
9430 (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
9431 fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
9433 if (!(time_after(jiffies, min_flush_time)) &&
9434 (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
9435 if (I40E_DEBUG_FD & pf->hw.debug_mask)
9436 dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
9440 pf->fd_flush_timestamp = jiffies;
9441 set_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
9442 /* flush all filters */
9443 wr32(&pf->hw, I40E_PFQF_CTL_1,
9444 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
9445 i40e_flush(&pf->hw);
9449 /* Check FD flush status every 5-6msec */
9450 usleep_range(5000, 6000);
9451 reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
9452 if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
9454 } while (flush_wait_retry--);
9455 if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
9456 dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
9458 /* replay sideband filters */
9459 i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
9460 if (!disable_atr && !pf->fd_tcp4_filter_cnt)
9461 clear_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
9462 clear_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
9463 if (I40E_DEBUG_FD & pf->hw.debug_mask)
9464 dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
9469 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
9470 * @pf: board private structure
9472 u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
9474 return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
9478 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
9479 * @pf: board private structure
9481 static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
9484 /* if interface is down do nothing */
9485 if (test_bit(__I40E_DOWN, pf->state))
9488 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
9489 i40e_fdir_flush_and_replay(pf);
9491 i40e_fdir_check_and_reenable(pf);
9496 * i40e_vsi_link_event - notify VSI of a link event
9497 * @vsi: vsi to be notified
9498 * @link_up: link up or down
9500 static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
9502 if (!vsi || test_bit(__I40E_VSI_DOWN, vsi->state))
9505 switch (vsi->type) {
9507 if (!vsi->netdev || !vsi->netdev_registered)
9511 netif_carrier_on(vsi->netdev);
9512 netif_tx_wake_all_queues(vsi->netdev);
9514 netif_carrier_off(vsi->netdev);
9515 netif_tx_stop_all_queues(vsi->netdev);
9519 case I40E_VSI_SRIOV:
9520 case I40E_VSI_VMDQ2:
9522 case I40E_VSI_IWARP:
9523 case I40E_VSI_MIRROR:
9525 /* there is no notification for other VSIs */
9531 * i40e_veb_link_event - notify elements on the veb of a link event
9532 * @veb: veb to be notified
9533 * @link_up: link up or down
9535 static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
9540 if (!veb || !veb->pf)
9544 /* depth first... */
9545 for (i = 0; i < I40E_MAX_VEB; i++)
9546 if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
9547 i40e_veb_link_event(pf->veb[i], link_up);
9549 /* ... now the local VSIs */
9550 for (i = 0; i < pf->num_alloc_vsi; i++)
9551 if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
9552 i40e_vsi_link_event(pf->vsi[i], link_up);
9556 * i40e_link_event - Update netif_carrier status
9557 * @pf: board private structure
9559 static void i40e_link_event(struct i40e_pf *pf)
9561 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
9562 u8 new_link_speed, old_link_speed;
9564 bool new_link, old_link;
9565 #ifdef CONFIG_I40E_DCB
9567 #endif /* CONFIG_I40E_DCB */
9569 /* set this to force the get_link_status call to refresh state */
9570 pf->hw.phy.get_link_info = true;
9571 old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
9572 status = i40e_get_link_status(&pf->hw, &new_link);
9574 /* On success, disable temp link polling */
9575 if (status == I40E_SUCCESS) {
9576 clear_bit(__I40E_TEMP_LINK_POLLING, pf->state);
9578 /* Enable link polling temporarily until i40e_get_link_status
9579 * returns I40E_SUCCESS
9581 set_bit(__I40E_TEMP_LINK_POLLING, pf->state);
9582 dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
9587 old_link_speed = pf->hw.phy.link_info_old.link_speed;
9588 new_link_speed = pf->hw.phy.link_info.link_speed;
9590 if (new_link == old_link &&
9591 new_link_speed == old_link_speed &&
9592 (test_bit(__I40E_VSI_DOWN, vsi->state) ||
9593 new_link == netif_carrier_ok(vsi->netdev)))
9596 i40e_print_link_message(vsi, new_link);
9598 /* Notify the base of the switch tree connected to
9599 * the link. Floating VEBs are not notified.
9601 if (pf->lan_veb < I40E_MAX_VEB && pf->veb[pf->lan_veb])
9602 i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
9604 i40e_vsi_link_event(vsi, new_link);
9607 i40e_vc_notify_link_state(pf);
9609 if (pf->flags & I40E_FLAG_PTP)
9610 i40e_ptp_set_increment(pf);
9611 #ifdef CONFIG_I40E_DCB
9612 if (new_link == old_link)
9614 /* Not SW DCB so firmware will take care of default settings */
9615 if (pf->dcbx_cap & DCB_CAP_DCBX_LLD_MANAGED)
9618 /* We cover here only link down, as after link up in case of SW DCB
9619 * SW LLDP agent will take care of setting it up
9622 dev_dbg(&pf->pdev->dev, "Reconfig DCB to single TC as result of Link Down\n");
9623 memset(&pf->tmp_cfg, 0, sizeof(pf->tmp_cfg));
9624 err = i40e_dcb_sw_default_config(pf);
9626 pf->flags &= ~(I40E_FLAG_DCB_CAPABLE |
9627 I40E_FLAG_DCB_ENABLED);
9629 pf->dcbx_cap = DCB_CAP_DCBX_HOST |
9630 DCB_CAP_DCBX_VER_IEEE;
9631 pf->flags |= I40E_FLAG_DCB_CAPABLE;
9632 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
9635 #endif /* CONFIG_I40E_DCB */
9639 * i40e_watchdog_subtask - periodic checks not using event driven response
9640 * @pf: board private structure
9642 static void i40e_watchdog_subtask(struct i40e_pf *pf)
9646 /* if interface is down do nothing */
9647 if (test_bit(__I40E_DOWN, pf->state) ||
9648 test_bit(__I40E_CONFIG_BUSY, pf->state))
9651 /* make sure we don't do these things too often */
9652 if (time_before(jiffies, (pf->service_timer_previous +
9653 pf->service_timer_period)))
9655 pf->service_timer_previous = jiffies;
9657 if ((pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) ||
9658 test_bit(__I40E_TEMP_LINK_POLLING, pf->state))
9659 i40e_link_event(pf);
9661 /* Update the stats for active netdevs so the network stack
9662 * can look at updated numbers whenever it cares to
9664 for (i = 0; i < pf->num_alloc_vsi; i++)
9665 if (pf->vsi[i] && pf->vsi[i]->netdev)
9666 i40e_update_stats(pf->vsi[i]);
9668 if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
9669 /* Update the stats for the active switching components */
9670 for (i = 0; i < I40E_MAX_VEB; i++)
9672 i40e_update_veb_stats(pf->veb[i]);
9675 i40e_ptp_rx_hang(pf);
9676 i40e_ptp_tx_hang(pf);
9680 * i40e_reset_subtask - Set up for resetting the device and driver
9681 * @pf: board private structure
9683 static void i40e_reset_subtask(struct i40e_pf *pf)
9685 u32 reset_flags = 0;
9687 if (test_bit(__I40E_REINIT_REQUESTED, pf->state)) {
9688 reset_flags |= BIT(__I40E_REINIT_REQUESTED);
9689 clear_bit(__I40E_REINIT_REQUESTED, pf->state);
9691 if (test_bit(__I40E_PF_RESET_REQUESTED, pf->state)) {
9692 reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
9693 clear_bit(__I40E_PF_RESET_REQUESTED, pf->state);
9695 if (test_bit(__I40E_CORE_RESET_REQUESTED, pf->state)) {
9696 reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
9697 clear_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
9699 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state)) {
9700 reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
9701 clear_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state);
9703 if (test_bit(__I40E_DOWN_REQUESTED, pf->state)) {
9704 reset_flags |= BIT(__I40E_DOWN_REQUESTED);
9705 clear_bit(__I40E_DOWN_REQUESTED, pf->state);
9708 /* If there's a recovery already waiting, it takes
9709 * precedence before starting a new reset sequence.
9711 if (test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) {
9712 i40e_prep_for_reset(pf);
9714 i40e_rebuild(pf, false, false);
9717 /* If we're already down or resetting, just bail */
9719 !test_bit(__I40E_DOWN, pf->state) &&
9720 !test_bit(__I40E_CONFIG_BUSY, pf->state)) {
9721 i40e_do_reset(pf, reset_flags, false);
9726 * i40e_handle_link_event - Handle link event
9727 * @pf: board private structure
9728 * @e: event info posted on ARQ
9730 static void i40e_handle_link_event(struct i40e_pf *pf,
9731 struct i40e_arq_event_info *e)
9733 struct i40e_aqc_get_link_status *status =
9734 (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
9736 /* Do a new status request to re-enable LSE reporting
9737 * and load new status information into the hw struct
9738 * This completely ignores any state information
9739 * in the ARQ event info, instead choosing to always
9740 * issue the AQ update link status command.
9742 i40e_link_event(pf);
9744 /* Check if module meets thermal requirements */
9745 if (status->phy_type == I40E_PHY_TYPE_NOT_SUPPORTED_HIGH_TEMP) {
9746 dev_err(&pf->pdev->dev,
9747 "Rx/Tx is disabled on this device because the module does not meet thermal requirements.\n");
9748 dev_err(&pf->pdev->dev,
9749 "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
9751 /* check for unqualified module, if link is down, suppress
9752 * the message if link was forced to be down.
9754 if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
9755 (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
9756 (!(status->link_info & I40E_AQ_LINK_UP)) &&
9757 (!(pf->flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED))) {
9758 dev_err(&pf->pdev->dev,
9759 "Rx/Tx is disabled on this device because an unsupported SFP module type was detected.\n");
9760 dev_err(&pf->pdev->dev,
9761 "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
9767 * i40e_clean_adminq_subtask - Clean the AdminQ rings
9768 * @pf: board private structure
9770 static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
9772 struct i40e_arq_event_info event;
9773 struct i40e_hw *hw = &pf->hw;
9780 /* Do not run clean AQ when PF reset fails */
9781 if (test_bit(__I40E_RESET_FAILED, pf->state))
9784 /* check for error indications */
9785 val = rd32(&pf->hw, pf->hw.aq.arq.len);
9787 if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
9788 if (hw->debug_mask & I40E_DEBUG_AQ)
9789 dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
9790 val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
9792 if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
9793 if (hw->debug_mask & I40E_DEBUG_AQ)
9794 dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
9795 val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
9796 pf->arq_overflows++;
9798 if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
9799 if (hw->debug_mask & I40E_DEBUG_AQ)
9800 dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
9801 val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
9804 wr32(&pf->hw, pf->hw.aq.arq.len, val);
9806 val = rd32(&pf->hw, pf->hw.aq.asq.len);
9808 if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
9809 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
9810 dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
9811 val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
9813 if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
9814 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
9815 dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
9816 val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
9818 if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
9819 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
9820 dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
9821 val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
9824 wr32(&pf->hw, pf->hw.aq.asq.len, val);
9826 event.buf_len = I40E_MAX_AQ_BUF_SIZE;
9827 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
9832 ret = i40e_clean_arq_element(hw, &event, &pending);
9833 if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
9836 dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
9840 opcode = le16_to_cpu(event.desc.opcode);
9843 case i40e_aqc_opc_get_link_status:
9845 i40e_handle_link_event(pf, &event);
9848 case i40e_aqc_opc_send_msg_to_pf:
9849 ret = i40e_vc_process_vf_msg(pf,
9850 le16_to_cpu(event.desc.retval),
9851 le32_to_cpu(event.desc.cookie_high),
9852 le32_to_cpu(event.desc.cookie_low),
9856 case i40e_aqc_opc_lldp_update_mib:
9857 dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
9858 #ifdef CONFIG_I40E_DCB
9860 i40e_handle_lldp_event(pf, &event);
9862 #endif /* CONFIG_I40E_DCB */
9864 case i40e_aqc_opc_event_lan_overflow:
9865 dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
9866 i40e_handle_lan_overflow_event(pf, &event);
9868 case i40e_aqc_opc_send_msg_to_peer:
9869 dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
9871 case i40e_aqc_opc_nvm_erase:
9872 case i40e_aqc_opc_nvm_update:
9873 case i40e_aqc_opc_oem_post_update:
9874 i40e_debug(&pf->hw, I40E_DEBUG_NVM,
9875 "ARQ NVM operation 0x%04x completed\n",
9879 dev_info(&pf->pdev->dev,
9880 "ARQ: Unknown event 0x%04x ignored\n",
9884 } while (i++ < pf->adminq_work_limit);
9886 if (i < pf->adminq_work_limit)
9887 clear_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
9889 /* re-enable Admin queue interrupt cause */
9890 val = rd32(hw, I40E_PFINT_ICR0_ENA);
9891 val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
9892 wr32(hw, I40E_PFINT_ICR0_ENA, val);
9895 kfree(event.msg_buf);
9899 * i40e_verify_eeprom - make sure eeprom is good to use
9900 * @pf: board private structure
9902 static void i40e_verify_eeprom(struct i40e_pf *pf)
9906 err = i40e_diag_eeprom_test(&pf->hw);
9908 /* retry in case of garbage read */
9909 err = i40e_diag_eeprom_test(&pf->hw);
9911 dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
9913 set_bit(__I40E_BAD_EEPROM, pf->state);
9917 if (!err && test_bit(__I40E_BAD_EEPROM, pf->state)) {
9918 dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
9919 clear_bit(__I40E_BAD_EEPROM, pf->state);
9924 * i40e_enable_pf_switch_lb
9925 * @pf: pointer to the PF structure
9927 * enable switch loop back or die - no point in a return value
9929 static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
9931 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
9932 struct i40e_vsi_context ctxt;
9935 ctxt.seid = pf->main_vsi_seid;
9936 ctxt.pf_num = pf->hw.pf_id;
9938 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
9940 dev_info(&pf->pdev->dev,
9941 "couldn't get PF vsi config, err %s aq_err %s\n",
9942 i40e_stat_str(&pf->hw, ret),
9943 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
9946 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
9947 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9948 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9950 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
9952 dev_info(&pf->pdev->dev,
9953 "update vsi switch failed, err %s aq_err %s\n",
9954 i40e_stat_str(&pf->hw, ret),
9955 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
9960 * i40e_disable_pf_switch_lb
9961 * @pf: pointer to the PF structure
9963 * disable switch loop back or die - no point in a return value
9965 static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
9967 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
9968 struct i40e_vsi_context ctxt;
9971 ctxt.seid = pf->main_vsi_seid;
9972 ctxt.pf_num = pf->hw.pf_id;
9974 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
9976 dev_info(&pf->pdev->dev,
9977 "couldn't get PF vsi config, err %s aq_err %s\n",
9978 i40e_stat_str(&pf->hw, ret),
9979 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
9982 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
9983 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9984 ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9986 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
9988 dev_info(&pf->pdev->dev,
9989 "update vsi switch failed, err %s aq_err %s\n",
9990 i40e_stat_str(&pf->hw, ret),
9991 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
9996 * i40e_config_bridge_mode - Configure the HW bridge mode
9997 * @veb: pointer to the bridge instance
9999 * Configure the loop back mode for the LAN VSI that is downlink to the
10000 * specified HW bridge instance. It is expected this function is called
10001 * when a new HW bridge is instantiated.
10003 static void i40e_config_bridge_mode(struct i40e_veb *veb)
10005 struct i40e_pf *pf = veb->pf;
10007 if (pf->hw.debug_mask & I40E_DEBUG_LAN)
10008 dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
10009 veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
10010 if (veb->bridge_mode & BRIDGE_MODE_VEPA)
10011 i40e_disable_pf_switch_lb(pf);
10013 i40e_enable_pf_switch_lb(pf);
10017 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
10018 * @veb: pointer to the VEB instance
10020 * This is a recursive function that first builds the attached VSIs then
10021 * recurses in to build the next layer of VEB. We track the connections
10022 * through our own index numbers because the seid's from the HW could
10023 * change across the reset.
10025 static int i40e_reconstitute_veb(struct i40e_veb *veb)
10027 struct i40e_vsi *ctl_vsi = NULL;
10028 struct i40e_pf *pf = veb->pf;
10032 /* build VSI that owns this VEB, temporarily attached to base VEB */
10033 for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
10035 pf->vsi[v]->veb_idx == veb->idx &&
10036 pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
10037 ctl_vsi = pf->vsi[v];
10042 dev_info(&pf->pdev->dev,
10043 "missing owner VSI for veb_idx %d\n", veb->idx);
10045 goto end_reconstitute;
10047 if (ctl_vsi != pf->vsi[pf->lan_vsi])
10048 ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
10049 ret = i40e_add_vsi(ctl_vsi);
10051 dev_info(&pf->pdev->dev,
10052 "rebuild of veb_idx %d owner VSI failed: %d\n",
10054 goto end_reconstitute;
10056 i40e_vsi_reset_stats(ctl_vsi);
10058 /* create the VEB in the switch and move the VSI onto the VEB */
10059 ret = i40e_add_veb(veb, ctl_vsi);
10061 goto end_reconstitute;
10063 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
10064 veb->bridge_mode = BRIDGE_MODE_VEB;
10066 veb->bridge_mode = BRIDGE_MODE_VEPA;
10067 i40e_config_bridge_mode(veb);
10069 /* create the remaining VSIs attached to this VEB */
10070 for (v = 0; v < pf->num_alloc_vsi; v++) {
10071 if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
10074 if (pf->vsi[v]->veb_idx == veb->idx) {
10075 struct i40e_vsi *vsi = pf->vsi[v];
10077 vsi->uplink_seid = veb->seid;
10078 ret = i40e_add_vsi(vsi);
10080 dev_info(&pf->pdev->dev,
10081 "rebuild of vsi_idx %d failed: %d\n",
10083 goto end_reconstitute;
10085 i40e_vsi_reset_stats(vsi);
10089 /* create any VEBs attached to this VEB - RECURSION */
10090 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
10091 if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
10092 pf->veb[veb_idx]->uplink_seid = veb->seid;
10093 ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
10104 * i40e_get_capabilities - get info about the HW
10105 * @pf: the PF struct
10106 * @list_type: AQ capability to be queried
10108 static int i40e_get_capabilities(struct i40e_pf *pf,
10109 enum i40e_admin_queue_opc list_type)
10111 struct i40e_aqc_list_capabilities_element_resp *cap_buf;
10116 buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
10118 cap_buf = kzalloc(buf_len, GFP_KERNEL);
10122 /* this loads the data into the hw struct for us */
10123 err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
10124 &data_size, list_type,
10126 /* data loaded, buffer no longer needed */
10129 if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
10130 /* retry with a larger buffer */
10131 buf_len = data_size;
10132 } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
10133 dev_info(&pf->pdev->dev,
10134 "capability discovery failed, err %s aq_err %s\n",
10135 i40e_stat_str(&pf->hw, err),
10136 i40e_aq_str(&pf->hw,
10137 pf->hw.aq.asq_last_status));
10142 if (pf->hw.debug_mask & I40E_DEBUG_USER) {
10143 if (list_type == i40e_aqc_opc_list_func_capabilities) {
10144 dev_info(&pf->pdev->dev,
10145 "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",
10146 pf->hw.pf_id, pf->hw.func_caps.num_vfs,
10147 pf->hw.func_caps.num_msix_vectors,
10148 pf->hw.func_caps.num_msix_vectors_vf,
10149 pf->hw.func_caps.fd_filters_guaranteed,
10150 pf->hw.func_caps.fd_filters_best_effort,
10151 pf->hw.func_caps.num_tx_qp,
10152 pf->hw.func_caps.num_vsis);
10153 } else if (list_type == i40e_aqc_opc_list_dev_capabilities) {
10154 dev_info(&pf->pdev->dev,
10155 "switch_mode=0x%04x, function_valid=0x%08x\n",
10156 pf->hw.dev_caps.switch_mode,
10157 pf->hw.dev_caps.valid_functions);
10158 dev_info(&pf->pdev->dev,
10159 "SR-IOV=%d, num_vfs for all function=%u\n",
10160 pf->hw.dev_caps.sr_iov_1_1,
10161 pf->hw.dev_caps.num_vfs);
10162 dev_info(&pf->pdev->dev,
10163 "num_vsis=%u, num_rx:%u, num_tx=%u\n",
10164 pf->hw.dev_caps.num_vsis,
10165 pf->hw.dev_caps.num_rx_qp,
10166 pf->hw.dev_caps.num_tx_qp);
10169 if (list_type == i40e_aqc_opc_list_func_capabilities) {
10170 #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
10171 + pf->hw.func_caps.num_vfs)
10172 if (pf->hw.revision_id == 0 &&
10173 pf->hw.func_caps.num_vsis < DEF_NUM_VSI) {
10174 dev_info(&pf->pdev->dev,
10175 "got num_vsis %d, setting num_vsis to %d\n",
10176 pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
10177 pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
10183 static int i40e_vsi_clear(struct i40e_vsi *vsi);
10186 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
10187 * @pf: board private structure
10189 static void i40e_fdir_sb_setup(struct i40e_pf *pf)
10191 struct i40e_vsi *vsi;
10193 /* quick workaround for an NVM issue that leaves a critical register
10196 if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
10197 static const u32 hkey[] = {
10198 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
10199 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
10200 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
10204 for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
10205 wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
10208 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
10211 /* find existing VSI and see if it needs configuring */
10212 vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
10214 /* create a new VSI if none exists */
10216 vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
10217 pf->vsi[pf->lan_vsi]->seid, 0);
10219 dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
10220 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
10221 pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
10226 i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
10230 * i40e_fdir_teardown - release the Flow Director resources
10231 * @pf: board private structure
10233 static void i40e_fdir_teardown(struct i40e_pf *pf)
10235 struct i40e_vsi *vsi;
10237 i40e_fdir_filter_exit(pf);
10238 vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
10240 i40e_vsi_release(vsi);
10244 * i40e_rebuild_cloud_filters - Rebuilds cloud filters for VSIs
10245 * @vsi: PF main vsi
10246 * @seid: seid of main or channel VSIs
10248 * Rebuilds cloud filters associated with main VSI and channel VSIs if they
10249 * existed before reset
10251 static int i40e_rebuild_cloud_filters(struct i40e_vsi *vsi, u16 seid)
10253 struct i40e_cloud_filter *cfilter;
10254 struct i40e_pf *pf = vsi->back;
10255 struct hlist_node *node;
10258 /* Add cloud filters back if they exist */
10259 hlist_for_each_entry_safe(cfilter, node, &pf->cloud_filter_list,
10261 if (cfilter->seid != seid)
10264 if (cfilter->dst_port)
10265 ret = i40e_add_del_cloud_filter_big_buf(vsi, cfilter,
10268 ret = i40e_add_del_cloud_filter(vsi, cfilter, true);
10271 dev_dbg(&pf->pdev->dev,
10272 "Failed to rebuild cloud filter, err %s aq_err %s\n",
10273 i40e_stat_str(&pf->hw, ret),
10274 i40e_aq_str(&pf->hw,
10275 pf->hw.aq.asq_last_status));
10283 * i40e_rebuild_channels - Rebuilds channel VSIs if they existed before reset
10284 * @vsi: PF main vsi
10286 * Rebuilds channel VSIs if they existed before reset
10288 static int i40e_rebuild_channels(struct i40e_vsi *vsi)
10290 struct i40e_channel *ch, *ch_tmp;
10293 if (list_empty(&vsi->ch_list))
10296 list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
10297 if (!ch->initialized)
10299 /* Proceed with creation of channel (VMDq2) VSI */
10300 ret = i40e_add_channel(vsi->back, vsi->uplink_seid, ch);
10302 dev_info(&vsi->back->pdev->dev,
10303 "failed to rebuild channels using uplink_seid %u\n",
10307 /* Reconfigure TX queues using QTX_CTL register */
10308 ret = i40e_channel_config_tx_ring(vsi->back, vsi, ch);
10310 dev_info(&vsi->back->pdev->dev,
10311 "failed to configure TX rings for channel %u\n",
10315 /* update 'next_base_queue' */
10316 vsi->next_base_queue = vsi->next_base_queue +
10317 ch->num_queue_pairs;
10318 if (ch->max_tx_rate) {
10319 u64 credits = ch->max_tx_rate;
10321 if (i40e_set_bw_limit(vsi, ch->seid,
10325 do_div(credits, I40E_BW_CREDIT_DIVISOR);
10326 dev_dbg(&vsi->back->pdev->dev,
10327 "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
10332 ret = i40e_rebuild_cloud_filters(vsi, ch->seid);
10334 dev_dbg(&vsi->back->pdev->dev,
10335 "Failed to rebuild cloud filters for channel VSI %u\n",
10344 * i40e_prep_for_reset - prep for the core to reset
10345 * @pf: board private structure
10347 * Close up the VFs and other things in prep for PF Reset.
10349 static void i40e_prep_for_reset(struct i40e_pf *pf)
10351 struct i40e_hw *hw = &pf->hw;
10352 i40e_status ret = 0;
10355 clear_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
10356 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
10358 if (i40e_check_asq_alive(&pf->hw))
10359 i40e_vc_notify_reset(pf);
10361 dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
10363 /* quiesce the VSIs and their queues that are not already DOWN */
10364 i40e_pf_quiesce_all_vsi(pf);
10366 for (v = 0; v < pf->num_alloc_vsi; v++) {
10368 pf->vsi[v]->seid = 0;
10371 i40e_shutdown_adminq(&pf->hw);
10373 /* call shutdown HMC */
10374 if (hw->hmc.hmc_obj) {
10375 ret = i40e_shutdown_lan_hmc(hw);
10377 dev_warn(&pf->pdev->dev,
10378 "shutdown_lan_hmc failed: %d\n", ret);
10381 /* Save the current PTP time so that we can restore the time after the
10384 i40e_ptp_save_hw_time(pf);
10388 * i40e_send_version - update firmware with driver version
10391 static void i40e_send_version(struct i40e_pf *pf)
10393 struct i40e_driver_version dv;
10395 dv.major_version = 0xff;
10396 dv.minor_version = 0xff;
10397 dv.build_version = 0xff;
10398 dv.subbuild_version = 0;
10399 strlcpy(dv.driver_string, UTS_RELEASE, sizeof(dv.driver_string));
10400 i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
10404 * i40e_get_oem_version - get OEM specific version information
10405 * @hw: pointer to the hardware structure
10407 static void i40e_get_oem_version(struct i40e_hw *hw)
10409 u16 block_offset = 0xffff;
10410 u16 block_length = 0;
10411 u16 capabilities = 0;
10415 #define I40E_SR_NVM_OEM_VERSION_PTR 0x1B
10416 #define I40E_NVM_OEM_LENGTH_OFFSET 0x00
10417 #define I40E_NVM_OEM_CAPABILITIES_OFFSET 0x01
10418 #define I40E_NVM_OEM_GEN_OFFSET 0x02
10419 #define I40E_NVM_OEM_RELEASE_OFFSET 0x03
10420 #define I40E_NVM_OEM_CAPABILITIES_MASK 0x000F
10421 #define I40E_NVM_OEM_LENGTH 3
10423 /* Check if pointer to OEM version block is valid. */
10424 i40e_read_nvm_word(hw, I40E_SR_NVM_OEM_VERSION_PTR, &block_offset);
10425 if (block_offset == 0xffff)
10428 /* Check if OEM version block has correct length. */
10429 i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_LENGTH_OFFSET,
10431 if (block_length < I40E_NVM_OEM_LENGTH)
10434 /* Check if OEM version format is as expected. */
10435 i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_CAPABILITIES_OFFSET,
10437 if ((capabilities & I40E_NVM_OEM_CAPABILITIES_MASK) != 0)
10440 i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_GEN_OFFSET,
10442 i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_RELEASE_OFFSET,
10444 hw->nvm.oem_ver = (gen_snap << I40E_OEM_SNAP_SHIFT) | release;
10445 hw->nvm.eetrack = I40E_OEM_EETRACK_ID;
10449 * i40e_reset - wait for core reset to finish reset, reset pf if corer not seen
10450 * @pf: board private structure
10452 static int i40e_reset(struct i40e_pf *pf)
10454 struct i40e_hw *hw = &pf->hw;
10457 ret = i40e_pf_reset(hw);
10459 dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
10460 set_bit(__I40E_RESET_FAILED, pf->state);
10461 clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
10469 * i40e_rebuild - rebuild using a saved config
10470 * @pf: board private structure
10471 * @reinit: if the Main VSI needs to re-initialized.
10472 * @lock_acquired: indicates whether or not the lock has been acquired
10473 * before this function was called.
10475 static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired)
10477 int old_recovery_mode_bit = test_bit(__I40E_RECOVERY_MODE, pf->state);
10478 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
10479 struct i40e_hw *hw = &pf->hw;
10484 if (test_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state) &&
10485 i40e_check_recovery_mode(pf)) {
10486 i40e_set_ethtool_ops(pf->vsi[pf->lan_vsi]->netdev);
10489 if (test_bit(__I40E_DOWN, pf->state) &&
10490 !test_bit(__I40E_RECOVERY_MODE, pf->state) &&
10491 !old_recovery_mode_bit)
10492 goto clear_recovery;
10493 dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
10495 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
10496 ret = i40e_init_adminq(&pf->hw);
10498 dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
10499 i40e_stat_str(&pf->hw, ret),
10500 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
10501 goto clear_recovery;
10503 i40e_get_oem_version(&pf->hw);
10505 if (test_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state) &&
10506 ((hw->aq.fw_maj_ver == 4 && hw->aq.fw_min_ver <= 33) ||
10507 hw->aq.fw_maj_ver < 4) && hw->mac.type == I40E_MAC_XL710) {
10508 /* The following delay is necessary for 4.33 firmware and older
10509 * to recover after EMP reset. 200 ms should suffice but we
10510 * put here 300 ms to be sure that FW is ready to operate
10516 /* re-verify the eeprom if we just had an EMP reset */
10517 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state))
10518 i40e_verify_eeprom(pf);
10520 /* if we are going out of or into recovery mode we have to act
10521 * accordingly with regard to resources initialization
10522 * and deinitialization
10524 if (test_bit(__I40E_RECOVERY_MODE, pf->state) ||
10525 old_recovery_mode_bit) {
10526 if (i40e_get_capabilities(pf,
10527 i40e_aqc_opc_list_func_capabilities))
10530 if (test_bit(__I40E_RECOVERY_MODE, pf->state)) {
10531 /* we're staying in recovery mode so we'll reinitialize
10534 if (i40e_setup_misc_vector_for_recovery_mode(pf))
10537 if (!lock_acquired)
10539 /* we're going out of recovery mode so we'll free
10540 * the IRQ allocated specifically for recovery mode
10541 * and restore the interrupt scheme
10543 free_irq(pf->pdev->irq, pf);
10544 i40e_clear_interrupt_scheme(pf);
10545 if (i40e_restore_interrupt_scheme(pf))
10549 /* tell the firmware that we're starting */
10550 i40e_send_version(pf);
10552 /* bail out in case recovery mode was detected, as there is
10553 * no need for further configuration.
10558 i40e_clear_pxe_mode(hw);
10559 ret = i40e_get_capabilities(pf, i40e_aqc_opc_list_func_capabilities);
10561 goto end_core_reset;
10563 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
10564 hw->func_caps.num_rx_qp, 0, 0);
10566 dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
10567 goto end_core_reset;
10569 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
10571 dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
10572 goto end_core_reset;
10575 #ifdef CONFIG_I40E_DCB
10576 /* Enable FW to write a default DCB config on link-up
10577 * unless I40E_FLAG_TC_MQPRIO was enabled or DCB
10578 * is not supported with new link speed
10580 if (pf->flags & I40E_FLAG_TC_MQPRIO) {
10581 i40e_aq_set_dcb_parameters(hw, false, NULL);
10583 if (I40E_IS_X710TL_DEVICE(hw->device_id) &&
10584 (hw->phy.link_info.link_speed &
10585 (I40E_LINK_SPEED_2_5GB | I40E_LINK_SPEED_5GB))) {
10586 i40e_aq_set_dcb_parameters(hw, false, NULL);
10587 dev_warn(&pf->pdev->dev,
10588 "DCB is not supported for X710-T*L 2.5/5G speeds\n");
10589 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
10591 i40e_aq_set_dcb_parameters(hw, true, NULL);
10592 ret = i40e_init_pf_dcb(pf);
10594 dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n",
10596 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
10597 /* Continue without DCB enabled */
10602 #endif /* CONFIG_I40E_DCB */
10603 if (!lock_acquired)
10605 ret = i40e_setup_pf_switch(pf, reinit);
10609 /* The driver only wants link up/down and module qualification
10610 * reports from firmware. Note the negative logic.
10612 ret = i40e_aq_set_phy_int_mask(&pf->hw,
10613 ~(I40E_AQ_EVENT_LINK_UPDOWN |
10614 I40E_AQ_EVENT_MEDIA_NA |
10615 I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
10617 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
10618 i40e_stat_str(&pf->hw, ret),
10619 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
10621 /* Rebuild the VSIs and VEBs that existed before reset.
10622 * They are still in our local switch element arrays, so only
10623 * need to rebuild the switch model in the HW.
10625 * If there were VEBs but the reconstitution failed, we'll try
10626 * try to recover minimal use by getting the basic PF VSI working.
10628 if (vsi->uplink_seid != pf->mac_seid) {
10629 dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
10630 /* find the one VEB connected to the MAC, and find orphans */
10631 for (v = 0; v < I40E_MAX_VEB; v++) {
10635 if (pf->veb[v]->uplink_seid == pf->mac_seid ||
10636 pf->veb[v]->uplink_seid == 0) {
10637 ret = i40e_reconstitute_veb(pf->veb[v]);
10642 /* If Main VEB failed, we're in deep doodoo,
10643 * so give up rebuilding the switch and set up
10644 * for minimal rebuild of PF VSI.
10645 * If orphan failed, we'll report the error
10646 * but try to keep going.
10648 if (pf->veb[v]->uplink_seid == pf->mac_seid) {
10649 dev_info(&pf->pdev->dev,
10650 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
10652 vsi->uplink_seid = pf->mac_seid;
10654 } else if (pf->veb[v]->uplink_seid == 0) {
10655 dev_info(&pf->pdev->dev,
10656 "rebuild of orphan VEB failed: %d\n",
10663 if (vsi->uplink_seid == pf->mac_seid) {
10664 dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
10665 /* no VEB, so rebuild only the Main VSI */
10666 ret = i40e_add_vsi(vsi);
10668 dev_info(&pf->pdev->dev,
10669 "rebuild of Main VSI failed: %d\n", ret);
10674 if (vsi->mqprio_qopt.max_rate[0]) {
10675 u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
10678 do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
10679 ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
10683 credits = max_tx_rate;
10684 do_div(credits, I40E_BW_CREDIT_DIVISOR);
10685 dev_dbg(&vsi->back->pdev->dev,
10686 "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
10692 ret = i40e_rebuild_cloud_filters(vsi, vsi->seid);
10696 /* PF Main VSI is rebuild by now, go ahead and rebuild channel VSIs
10697 * for this main VSI if they exist
10699 ret = i40e_rebuild_channels(vsi);
10703 /* Reconfigure hardware for allowing smaller MSS in the case
10704 * of TSO, so that we avoid the MDD being fired and causing
10705 * a reset in the case of small MSS+TSO.
10707 #define I40E_REG_MSS 0x000E64DC
10708 #define I40E_REG_MSS_MIN_MASK 0x3FF0000
10709 #define I40E_64BYTE_MSS 0x400000
10710 val = rd32(hw, I40E_REG_MSS);
10711 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
10712 val &= ~I40E_REG_MSS_MIN_MASK;
10713 val |= I40E_64BYTE_MSS;
10714 wr32(hw, I40E_REG_MSS, val);
10717 if (pf->hw_features & I40E_HW_RESTART_AUTONEG) {
10719 ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
10721 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
10722 i40e_stat_str(&pf->hw, ret),
10723 i40e_aq_str(&pf->hw,
10724 pf->hw.aq.asq_last_status));
10726 /* reinit the misc interrupt */
10727 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
10728 ret = i40e_setup_misc_vector(pf);
10730 /* Add a filter to drop all Flow control frames from any VSI from being
10731 * transmitted. By doing so we stop a malicious VF from sending out
10732 * PAUSE or PFC frames and potentially controlling traffic for other
10734 * The FW can still send Flow control frames if enabled.
10736 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
10737 pf->main_vsi_seid);
10738 #ifdef CONFIG_I40E_DCB
10739 if (pf->flags & I40E_FLAG_DISABLE_FW_LLDP)
10740 i40e_set_lldp_forwarding(pf, true);
10741 #endif /* CONFIG_I40E_DCB */
10743 /* restart the VSIs that were rebuilt and running before the reset */
10744 i40e_pf_unquiesce_all_vsi(pf);
10746 /* Release the RTNL lock before we start resetting VFs */
10747 if (!lock_acquired)
10750 /* Restore promiscuous settings */
10751 ret = i40e_set_promiscuous(pf, pf->cur_promisc);
10753 dev_warn(&pf->pdev->dev,
10754 "Failed to restore promiscuous setting: %s, err %s aq_err %s\n",
10755 pf->cur_promisc ? "on" : "off",
10756 i40e_stat_str(&pf->hw, ret),
10757 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
10759 i40e_reset_all_vfs(pf, true);
10761 /* tell the firmware that we're starting */
10762 i40e_send_version(pf);
10764 /* We've already released the lock, so don't do it again */
10765 goto end_core_reset;
10768 if (!lock_acquired)
10771 clear_bit(__I40E_RESET_FAILED, pf->state);
10773 clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
10774 clear_bit(__I40E_TIMEOUT_RECOVERY_PENDING, pf->state);
10778 * i40e_reset_and_rebuild - reset and rebuild using a saved config
10779 * @pf: board private structure
10780 * @reinit: if the Main VSI needs to re-initialized.
10781 * @lock_acquired: indicates whether or not the lock has been acquired
10782 * before this function was called.
10784 static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit,
10785 bool lock_acquired)
10788 /* Now we wait for GRST to settle out.
10789 * We don't have to delete the VEBs or VSIs from the hw switch
10790 * because the reset will make them disappear.
10792 ret = i40e_reset(pf);
10794 i40e_rebuild(pf, reinit, lock_acquired);
10798 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
10799 * @pf: board private structure
10801 * Close up the VFs and other things in prep for a Core Reset,
10802 * then get ready to rebuild the world.
10803 * @lock_acquired: indicates whether or not the lock has been acquired
10804 * before this function was called.
10806 static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired)
10808 i40e_prep_for_reset(pf);
10809 i40e_reset_and_rebuild(pf, false, lock_acquired);
10813 * i40e_handle_mdd_event
10814 * @pf: pointer to the PF structure
10816 * Called from the MDD irq handler to identify possibly malicious vfs
10818 static void i40e_handle_mdd_event(struct i40e_pf *pf)
10820 struct i40e_hw *hw = &pf->hw;
10821 bool mdd_detected = false;
10822 struct i40e_vf *vf;
10826 if (!test_bit(__I40E_MDD_EVENT_PENDING, pf->state))
10829 /* find what triggered the MDD event */
10830 reg = rd32(hw, I40E_GL_MDET_TX);
10831 if (reg & I40E_GL_MDET_TX_VALID_MASK) {
10832 u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
10833 I40E_GL_MDET_TX_PF_NUM_SHIFT;
10834 u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
10835 I40E_GL_MDET_TX_VF_NUM_SHIFT;
10836 u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
10837 I40E_GL_MDET_TX_EVENT_SHIFT;
10838 u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
10839 I40E_GL_MDET_TX_QUEUE_SHIFT) -
10840 pf->hw.func_caps.base_queue;
10841 if (netif_msg_tx_err(pf))
10842 dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
10843 event, queue, pf_num, vf_num);
10844 wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
10845 mdd_detected = true;
10847 reg = rd32(hw, I40E_GL_MDET_RX);
10848 if (reg & I40E_GL_MDET_RX_VALID_MASK) {
10849 u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
10850 I40E_GL_MDET_RX_FUNCTION_SHIFT;
10851 u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
10852 I40E_GL_MDET_RX_EVENT_SHIFT;
10853 u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
10854 I40E_GL_MDET_RX_QUEUE_SHIFT) -
10855 pf->hw.func_caps.base_queue;
10856 if (netif_msg_rx_err(pf))
10857 dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
10858 event, queue, func);
10859 wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
10860 mdd_detected = true;
10863 if (mdd_detected) {
10864 reg = rd32(hw, I40E_PF_MDET_TX);
10865 if (reg & I40E_PF_MDET_TX_VALID_MASK) {
10866 wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
10867 dev_dbg(&pf->pdev->dev, "TX driver issue detected on PF\n");
10869 reg = rd32(hw, I40E_PF_MDET_RX);
10870 if (reg & I40E_PF_MDET_RX_VALID_MASK) {
10871 wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
10872 dev_dbg(&pf->pdev->dev, "RX driver issue detected on PF\n");
10876 /* see if one of the VFs needs its hand slapped */
10877 for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
10879 reg = rd32(hw, I40E_VP_MDET_TX(i));
10880 if (reg & I40E_VP_MDET_TX_VALID_MASK) {
10881 wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
10882 vf->num_mdd_events++;
10883 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
10885 dev_info(&pf->pdev->dev,
10886 "Use PF Control I/F to re-enable the VF\n");
10887 set_bit(I40E_VF_STATE_DISABLED, &vf->vf_states);
10890 reg = rd32(hw, I40E_VP_MDET_RX(i));
10891 if (reg & I40E_VP_MDET_RX_VALID_MASK) {
10892 wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
10893 vf->num_mdd_events++;
10894 dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
10896 dev_info(&pf->pdev->dev,
10897 "Use PF Control I/F to re-enable the VF\n");
10898 set_bit(I40E_VF_STATE_DISABLED, &vf->vf_states);
10902 /* re-enable mdd interrupt cause */
10903 clear_bit(__I40E_MDD_EVENT_PENDING, pf->state);
10904 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
10905 reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
10906 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
10911 * i40e_service_task - Run the driver's async subtasks
10912 * @work: pointer to work_struct containing our data
10914 static void i40e_service_task(struct work_struct *work)
10916 struct i40e_pf *pf = container_of(work,
10919 unsigned long start_time = jiffies;
10921 /* don't bother with service tasks if a reset is in progress */
10922 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
10923 test_bit(__I40E_SUSPENDED, pf->state))
10926 if (test_and_set_bit(__I40E_SERVICE_SCHED, pf->state))
10929 if (!test_bit(__I40E_RECOVERY_MODE, pf->state)) {
10930 i40e_detect_recover_hung(pf->vsi[pf->lan_vsi]);
10931 i40e_sync_filters_subtask(pf);
10932 i40e_reset_subtask(pf);
10933 i40e_handle_mdd_event(pf);
10934 i40e_vc_process_vflr_event(pf);
10935 i40e_watchdog_subtask(pf);
10936 i40e_fdir_reinit_subtask(pf);
10937 if (test_and_clear_bit(__I40E_CLIENT_RESET, pf->state)) {
10938 /* Client subtask will reopen next time through. */
10939 i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi],
10942 i40e_client_subtask(pf);
10943 if (test_and_clear_bit(__I40E_CLIENT_L2_CHANGE,
10945 i40e_notify_client_of_l2_param_changes(
10946 pf->vsi[pf->lan_vsi]);
10948 i40e_sync_filters_subtask(pf);
10950 i40e_reset_subtask(pf);
10953 i40e_clean_adminq_subtask(pf);
10955 /* flush memory to make sure state is correct before next watchdog */
10956 smp_mb__before_atomic();
10957 clear_bit(__I40E_SERVICE_SCHED, pf->state);
10959 /* If the tasks have taken longer than one timer cycle or there
10960 * is more work to be done, reschedule the service task now
10961 * rather than wait for the timer to tick again.
10963 if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
10964 test_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state) ||
10965 test_bit(__I40E_MDD_EVENT_PENDING, pf->state) ||
10966 test_bit(__I40E_VFLR_EVENT_PENDING, pf->state))
10967 i40e_service_event_schedule(pf);
10971 * i40e_service_timer - timer callback
10972 * @t: timer list pointer
10974 static void i40e_service_timer(struct timer_list *t)
10976 struct i40e_pf *pf = from_timer(pf, t, service_timer);
10978 mod_timer(&pf->service_timer,
10979 round_jiffies(jiffies + pf->service_timer_period));
10980 i40e_service_event_schedule(pf);
10984 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
10985 * @vsi: the VSI being configured
10987 static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
10989 struct i40e_pf *pf = vsi->back;
10991 switch (vsi->type) {
10992 case I40E_VSI_MAIN:
10993 vsi->alloc_queue_pairs = pf->num_lan_qps;
10994 if (!vsi->num_tx_desc)
10995 vsi->num_tx_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
10996 I40E_REQ_DESCRIPTOR_MULTIPLE);
10997 if (!vsi->num_rx_desc)
10998 vsi->num_rx_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
10999 I40E_REQ_DESCRIPTOR_MULTIPLE);
11000 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
11001 vsi->num_q_vectors = pf->num_lan_msix;
11003 vsi->num_q_vectors = 1;
11007 case I40E_VSI_FDIR:
11008 vsi->alloc_queue_pairs = 1;
11009 vsi->num_tx_desc = ALIGN(I40E_FDIR_RING_COUNT,
11010 I40E_REQ_DESCRIPTOR_MULTIPLE);
11011 vsi->num_rx_desc = ALIGN(I40E_FDIR_RING_COUNT,
11012 I40E_REQ_DESCRIPTOR_MULTIPLE);
11013 vsi->num_q_vectors = pf->num_fdsb_msix;
11016 case I40E_VSI_VMDQ2:
11017 vsi->alloc_queue_pairs = pf->num_vmdq_qps;
11018 if (!vsi->num_tx_desc)
11019 vsi->num_tx_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
11020 I40E_REQ_DESCRIPTOR_MULTIPLE);
11021 if (!vsi->num_rx_desc)
11022 vsi->num_rx_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
11023 I40E_REQ_DESCRIPTOR_MULTIPLE);
11024 vsi->num_q_vectors = pf->num_vmdq_msix;
11027 case I40E_VSI_SRIOV:
11028 vsi->alloc_queue_pairs = pf->num_vf_qps;
11029 if (!vsi->num_tx_desc)
11030 vsi->num_tx_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
11031 I40E_REQ_DESCRIPTOR_MULTIPLE);
11032 if (!vsi->num_rx_desc)
11033 vsi->num_rx_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
11034 I40E_REQ_DESCRIPTOR_MULTIPLE);
11046 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
11047 * @vsi: VSI pointer
11048 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
11050 * On error: returns error code (negative)
11051 * On success: returns 0
11053 static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
11055 struct i40e_ring **next_rings;
11059 /* allocate memory for both Tx, XDP Tx and Rx ring pointers */
11060 size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs *
11061 (i40e_enabled_xdp_vsi(vsi) ? 3 : 2);
11062 vsi->tx_rings = kzalloc(size, GFP_KERNEL);
11063 if (!vsi->tx_rings)
11065 next_rings = vsi->tx_rings + vsi->alloc_queue_pairs;
11066 if (i40e_enabled_xdp_vsi(vsi)) {
11067 vsi->xdp_rings = next_rings;
11068 next_rings += vsi->alloc_queue_pairs;
11070 vsi->rx_rings = next_rings;
11072 if (alloc_qvectors) {
11073 /* allocate memory for q_vector pointers */
11074 size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
11075 vsi->q_vectors = kzalloc(size, GFP_KERNEL);
11076 if (!vsi->q_vectors) {
11084 kfree(vsi->tx_rings);
11089 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
11090 * @pf: board private structure
11091 * @type: type of VSI
11093 * On error: returns error code (negative)
11094 * On success: returns vsi index in PF (positive)
11096 static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
11099 struct i40e_vsi *vsi;
11103 /* Need to protect the allocation of the VSIs at the PF level */
11104 mutex_lock(&pf->switch_mutex);
11106 /* VSI list may be fragmented if VSI creation/destruction has
11107 * been happening. We can afford to do a quick scan to look
11108 * for any free VSIs in the list.
11110 * find next empty vsi slot, looping back around if necessary
11113 while (i < pf->num_alloc_vsi && pf->vsi[i])
11115 if (i >= pf->num_alloc_vsi) {
11117 while (i < pf->next_vsi && pf->vsi[i])
11121 if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
11122 vsi_idx = i; /* Found one! */
11125 goto unlock_pf; /* out of VSI slots! */
11127 pf->next_vsi = ++i;
11129 vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
11136 set_bit(__I40E_VSI_DOWN, vsi->state);
11138 vsi->idx = vsi_idx;
11139 vsi->int_rate_limit = 0;
11140 vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
11141 pf->rss_table_size : 64;
11142 vsi->netdev_registered = false;
11143 vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
11144 hash_init(vsi->mac_filter_hash);
11145 vsi->irqs_ready = false;
11147 if (type == I40E_VSI_MAIN) {
11148 vsi->af_xdp_zc_qps = bitmap_zalloc(pf->num_lan_qps, GFP_KERNEL);
11149 if (!vsi->af_xdp_zc_qps)
11153 ret = i40e_set_num_rings_in_vsi(vsi);
11157 ret = i40e_vsi_alloc_arrays(vsi, true);
11161 /* Setup default MSIX irq handler for VSI */
11162 i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
11164 /* Initialize VSI lock */
11165 spin_lock_init(&vsi->mac_filter_hash_lock);
11166 pf->vsi[vsi_idx] = vsi;
11171 bitmap_free(vsi->af_xdp_zc_qps);
11172 pf->next_vsi = i - 1;
11175 mutex_unlock(&pf->switch_mutex);
11180 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
11181 * @vsi: VSI pointer
11182 * @free_qvectors: a bool to specify if q_vectors need to be freed.
11184 * On error: returns error code (negative)
11185 * On success: returns 0
11187 static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
11189 /* free the ring and vector containers */
11190 if (free_qvectors) {
11191 kfree(vsi->q_vectors);
11192 vsi->q_vectors = NULL;
11194 kfree(vsi->tx_rings);
11195 vsi->tx_rings = NULL;
11196 vsi->rx_rings = NULL;
11197 vsi->xdp_rings = NULL;
11201 * i40e_clear_rss_config_user - clear the user configured RSS hash keys
11203 * @vsi: Pointer to VSI structure
11205 static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
11210 kfree(vsi->rss_hkey_user);
11211 vsi->rss_hkey_user = NULL;
11213 kfree(vsi->rss_lut_user);
11214 vsi->rss_lut_user = NULL;
11218 * i40e_vsi_clear - Deallocate the VSI provided
11219 * @vsi: the VSI being un-configured
11221 static int i40e_vsi_clear(struct i40e_vsi *vsi)
11223 struct i40e_pf *pf;
11232 mutex_lock(&pf->switch_mutex);
11233 if (!pf->vsi[vsi->idx]) {
11234 dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](type %d)\n",
11235 vsi->idx, vsi->idx, vsi->type);
11239 if (pf->vsi[vsi->idx] != vsi) {
11240 dev_err(&pf->pdev->dev,
11241 "pf->vsi[%d](type %d) != vsi[%d](type %d): no free!\n",
11242 pf->vsi[vsi->idx]->idx,
11243 pf->vsi[vsi->idx]->type,
11244 vsi->idx, vsi->type);
11248 /* updates the PF for this cleared vsi */
11249 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
11250 i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
11252 bitmap_free(vsi->af_xdp_zc_qps);
11253 i40e_vsi_free_arrays(vsi, true);
11254 i40e_clear_rss_config_user(vsi);
11256 pf->vsi[vsi->idx] = NULL;
11257 if (vsi->idx < pf->next_vsi)
11258 pf->next_vsi = vsi->idx;
11261 mutex_unlock(&pf->switch_mutex);
11269 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
11270 * @vsi: the VSI being cleaned
11272 static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
11276 if (vsi->tx_rings && vsi->tx_rings[0]) {
11277 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
11278 kfree_rcu(vsi->tx_rings[i], rcu);
11279 WRITE_ONCE(vsi->tx_rings[i], NULL);
11280 WRITE_ONCE(vsi->rx_rings[i], NULL);
11281 if (vsi->xdp_rings)
11282 WRITE_ONCE(vsi->xdp_rings[i], NULL);
11288 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
11289 * @vsi: the VSI being configured
11291 static int i40e_alloc_rings(struct i40e_vsi *vsi)
11293 int i, qpv = i40e_enabled_xdp_vsi(vsi) ? 3 : 2;
11294 struct i40e_pf *pf = vsi->back;
11295 struct i40e_ring *ring;
11297 /* Set basic values in the rings to be used later during open() */
11298 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
11299 /* allocate space for both Tx and Rx in one shot */
11300 ring = kcalloc(qpv, sizeof(struct i40e_ring), GFP_KERNEL);
11304 ring->queue_index = i;
11305 ring->reg_idx = vsi->base_queue + i;
11306 ring->ring_active = false;
11308 ring->netdev = vsi->netdev;
11309 ring->dev = &pf->pdev->dev;
11310 ring->count = vsi->num_tx_desc;
11313 if (vsi->back->hw_features & I40E_HW_WB_ON_ITR_CAPABLE)
11314 ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
11315 ring->itr_setting = pf->tx_itr_default;
11316 WRITE_ONCE(vsi->tx_rings[i], ring++);
11318 if (!i40e_enabled_xdp_vsi(vsi))
11321 ring->queue_index = vsi->alloc_queue_pairs + i;
11322 ring->reg_idx = vsi->base_queue + ring->queue_index;
11323 ring->ring_active = false;
11325 ring->netdev = NULL;
11326 ring->dev = &pf->pdev->dev;
11327 ring->count = vsi->num_tx_desc;
11330 if (vsi->back->hw_features & I40E_HW_WB_ON_ITR_CAPABLE)
11331 ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
11332 set_ring_xdp(ring);
11333 ring->itr_setting = pf->tx_itr_default;
11334 WRITE_ONCE(vsi->xdp_rings[i], ring++);
11337 ring->queue_index = i;
11338 ring->reg_idx = vsi->base_queue + i;
11339 ring->ring_active = false;
11341 ring->netdev = vsi->netdev;
11342 ring->dev = &pf->pdev->dev;
11343 ring->count = vsi->num_rx_desc;
11346 ring->itr_setting = pf->rx_itr_default;
11347 WRITE_ONCE(vsi->rx_rings[i], ring);
11353 i40e_vsi_clear_rings(vsi);
11358 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
11359 * @pf: board private structure
11360 * @vectors: the number of MSI-X vectors to request
11362 * Returns the number of vectors reserved, or error
11364 static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
11366 vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
11367 I40E_MIN_MSIX, vectors);
11369 dev_info(&pf->pdev->dev,
11370 "MSI-X vector reservation failed: %d\n", vectors);
11378 * i40e_init_msix - Setup the MSIX capability
11379 * @pf: board private structure
11381 * Work with the OS to set up the MSIX vectors needed.
11383 * Returns the number of vectors reserved or negative on failure
11385 static int i40e_init_msix(struct i40e_pf *pf)
11387 struct i40e_hw *hw = &pf->hw;
11388 int cpus, extra_vectors;
11392 int iwarp_requested = 0;
11394 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
11397 /* The number of vectors we'll request will be comprised of:
11398 * - Add 1 for "other" cause for Admin Queue events, etc.
11399 * - The number of LAN queue pairs
11400 * - Queues being used for RSS.
11401 * We don't need as many as max_rss_size vectors.
11402 * use rss_size instead in the calculation since that
11403 * is governed by number of cpus in the system.
11404 * - assumes symmetric Tx/Rx pairing
11405 * - The number of VMDq pairs
11406 * - The CPU count within the NUMA node if iWARP is enabled
11407 * Once we count this up, try the request.
11409 * If we can't get what we want, we'll simplify to nearly nothing
11410 * and try again. If that still fails, we punt.
11412 vectors_left = hw->func_caps.num_msix_vectors;
11415 /* reserve one vector for miscellaneous handler */
11416 if (vectors_left) {
11421 /* reserve some vectors for the main PF traffic queues. Initially we
11422 * only reserve at most 50% of the available vectors, in the case that
11423 * the number of online CPUs is large. This ensures that we can enable
11424 * extra features as well. Once we've enabled the other features, we
11425 * will use any remaining vectors to reach as close as we can to the
11426 * number of online CPUs.
11428 cpus = num_online_cpus();
11429 pf->num_lan_msix = min_t(int, cpus, vectors_left / 2);
11430 vectors_left -= pf->num_lan_msix;
11432 /* reserve one vector for sideband flow director */
11433 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
11434 if (vectors_left) {
11435 pf->num_fdsb_msix = 1;
11439 pf->num_fdsb_msix = 0;
11443 /* can we reserve enough for iWARP? */
11444 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
11445 iwarp_requested = pf->num_iwarp_msix;
11448 pf->num_iwarp_msix = 0;
11449 else if (vectors_left < pf->num_iwarp_msix)
11450 pf->num_iwarp_msix = 1;
11451 v_budget += pf->num_iwarp_msix;
11452 vectors_left -= pf->num_iwarp_msix;
11455 /* any vectors left over go for VMDq support */
11456 if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
11457 if (!vectors_left) {
11458 pf->num_vmdq_msix = 0;
11459 pf->num_vmdq_qps = 0;
11461 int vmdq_vecs_wanted =
11462 pf->num_vmdq_vsis * pf->num_vmdq_qps;
11464 min_t(int, vectors_left, vmdq_vecs_wanted);
11466 /* if we're short on vectors for what's desired, we limit
11467 * the queues per vmdq. If this is still more than are
11468 * available, the user will need to change the number of
11469 * queues/vectors used by the PF later with the ethtool
11472 if (vectors_left < vmdq_vecs_wanted) {
11473 pf->num_vmdq_qps = 1;
11474 vmdq_vecs_wanted = pf->num_vmdq_vsis;
11475 vmdq_vecs = min_t(int,
11479 pf->num_vmdq_msix = pf->num_vmdq_qps;
11481 v_budget += vmdq_vecs;
11482 vectors_left -= vmdq_vecs;
11486 /* On systems with a large number of SMP cores, we previously limited
11487 * the number of vectors for num_lan_msix to be at most 50% of the
11488 * available vectors, to allow for other features. Now, we add back
11489 * the remaining vectors. However, we ensure that the total
11490 * num_lan_msix will not exceed num_online_cpus(). To do this, we
11491 * calculate the number of vectors we can add without going over the
11492 * cap of CPUs. For systems with a small number of CPUs this will be
11495 extra_vectors = min_t(int, cpus - pf->num_lan_msix, vectors_left);
11496 pf->num_lan_msix += extra_vectors;
11497 vectors_left -= extra_vectors;
11499 WARN(vectors_left < 0,
11500 "Calculation of remaining vectors underflowed. This is an accounting bug when determining total MSI-X vectors.\n");
11502 v_budget += pf->num_lan_msix;
11503 pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
11505 if (!pf->msix_entries)
11508 for (i = 0; i < v_budget; i++)
11509 pf->msix_entries[i].entry = i;
11510 v_actual = i40e_reserve_msix_vectors(pf, v_budget);
11512 if (v_actual < I40E_MIN_MSIX) {
11513 pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
11514 kfree(pf->msix_entries);
11515 pf->msix_entries = NULL;
11516 pci_disable_msix(pf->pdev);
11519 } else if (v_actual == I40E_MIN_MSIX) {
11520 /* Adjust for minimal MSIX use */
11521 pf->num_vmdq_vsis = 0;
11522 pf->num_vmdq_qps = 0;
11523 pf->num_lan_qps = 1;
11524 pf->num_lan_msix = 1;
11526 } else if (v_actual != v_budget) {
11527 /* If we have limited resources, we will start with no vectors
11528 * for the special features and then allocate vectors to some
11529 * of these features based on the policy and at the end disable
11530 * the features that did not get any vectors.
11534 dev_info(&pf->pdev->dev,
11535 "MSI-X vector limit reached with %d, wanted %d, attempting to redistribute vectors\n",
11536 v_actual, v_budget);
11537 /* reserve the misc vector */
11538 vec = v_actual - 1;
11540 /* Scale vector usage down */
11541 pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
11542 pf->num_vmdq_vsis = 1;
11543 pf->num_vmdq_qps = 1;
11545 /* partition out the remaining vectors */
11548 pf->num_lan_msix = 1;
11551 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
11552 pf->num_lan_msix = 1;
11553 pf->num_iwarp_msix = 1;
11555 pf->num_lan_msix = 2;
11559 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
11560 pf->num_iwarp_msix = min_t(int, (vec / 3),
11562 pf->num_vmdq_vsis = min_t(int, (vec / 3),
11563 I40E_DEFAULT_NUM_VMDQ_VSI);
11565 pf->num_vmdq_vsis = min_t(int, (vec / 2),
11566 I40E_DEFAULT_NUM_VMDQ_VSI);
11568 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
11569 pf->num_fdsb_msix = 1;
11572 pf->num_lan_msix = min_t(int,
11573 (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)),
11575 pf->num_lan_qps = pf->num_lan_msix;
11580 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
11581 (pf->num_fdsb_msix == 0)) {
11582 dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n");
11583 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
11584 pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
11586 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
11587 (pf->num_vmdq_msix == 0)) {
11588 dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
11589 pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
11592 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
11593 (pf->num_iwarp_msix == 0)) {
11594 dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n");
11595 pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
11597 i40e_debug(&pf->hw, I40E_DEBUG_INIT,
11598 "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n",
11600 pf->num_vmdq_msix * pf->num_vmdq_vsis,
11602 pf->num_iwarp_msix);
11608 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
11609 * @vsi: the VSI being configured
11610 * @v_idx: index of the vector in the vsi struct
11612 * We allocate one q_vector. If allocation fails we return -ENOMEM.
11614 static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx)
11616 struct i40e_q_vector *q_vector;
11618 /* allocate q_vector */
11619 q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
11623 q_vector->vsi = vsi;
11624 q_vector->v_idx = v_idx;
11625 cpumask_copy(&q_vector->affinity_mask, cpu_possible_mask);
11628 netif_napi_add(vsi->netdev, &q_vector->napi,
11629 i40e_napi_poll, NAPI_POLL_WEIGHT);
11631 /* tie q_vector and vsi together */
11632 vsi->q_vectors[v_idx] = q_vector;
11638 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
11639 * @vsi: the VSI being configured
11641 * We allocate one q_vector per queue interrupt. If allocation fails we
11644 static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
11646 struct i40e_pf *pf = vsi->back;
11647 int err, v_idx, num_q_vectors;
11649 /* if not MSIX, give the one vector only to the LAN VSI */
11650 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
11651 num_q_vectors = vsi->num_q_vectors;
11652 else if (vsi == pf->vsi[pf->lan_vsi])
11657 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
11658 err = i40e_vsi_alloc_q_vector(vsi, v_idx);
11667 i40e_free_q_vector(vsi, v_idx);
11673 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
11674 * @pf: board private structure to initialize
11676 static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
11681 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
11682 vectors = i40e_init_msix(pf);
11684 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
11685 I40E_FLAG_IWARP_ENABLED |
11686 I40E_FLAG_RSS_ENABLED |
11687 I40E_FLAG_DCB_CAPABLE |
11688 I40E_FLAG_DCB_ENABLED |
11689 I40E_FLAG_SRIOV_ENABLED |
11690 I40E_FLAG_FD_SB_ENABLED |
11691 I40E_FLAG_FD_ATR_ENABLED |
11692 I40E_FLAG_VMDQ_ENABLED);
11693 pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
11695 /* rework the queue expectations without MSIX */
11696 i40e_determine_queue_usage(pf);
11700 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
11701 (pf->flags & I40E_FLAG_MSI_ENABLED)) {
11702 dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
11703 vectors = pci_enable_msi(pf->pdev);
11705 dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
11707 pf->flags &= ~I40E_FLAG_MSI_ENABLED;
11709 vectors = 1; /* one MSI or Legacy vector */
11712 if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
11713 dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
11715 /* set up vector assignment tracking */
11716 size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
11717 pf->irq_pile = kzalloc(size, GFP_KERNEL);
11721 pf->irq_pile->num_entries = vectors;
11722 pf->irq_pile->search_hint = 0;
11724 /* track first vector for misc interrupts, ignore return */
11725 (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
11731 * i40e_restore_interrupt_scheme - Restore the interrupt scheme
11732 * @pf: private board data structure
11734 * Restore the interrupt scheme that was cleared when we suspended the
11735 * device. This should be called during resume to re-allocate the q_vectors
11736 * and reacquire IRQs.
11738 static int i40e_restore_interrupt_scheme(struct i40e_pf *pf)
11742 /* We cleared the MSI and MSI-X flags when disabling the old interrupt
11743 * scheme. We need to re-enabled them here in order to attempt to
11744 * re-acquire the MSI or MSI-X vectors
11746 pf->flags |= (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
11748 err = i40e_init_interrupt_scheme(pf);
11752 /* Now that we've re-acquired IRQs, we need to remap the vectors and
11753 * rings together again.
11755 for (i = 0; i < pf->num_alloc_vsi; i++) {
11757 err = i40e_vsi_alloc_q_vectors(pf->vsi[i]);
11760 i40e_vsi_map_rings_to_vectors(pf->vsi[i]);
11764 err = i40e_setup_misc_vector(pf);
11768 if (pf->flags & I40E_FLAG_IWARP_ENABLED)
11769 i40e_client_update_msix_info(pf);
11776 i40e_vsi_free_q_vectors(pf->vsi[i]);
11783 * i40e_setup_misc_vector_for_recovery_mode - Setup the misc vector to handle
11784 * non queue events in recovery mode
11785 * @pf: board private structure
11787 * This sets up the handler for MSIX 0 or MSI/legacy, which is used to manage
11788 * the non-queue interrupts, e.g. AdminQ and errors in recovery mode.
11789 * This is handled differently than in recovery mode since no Tx/Rx resources
11790 * are being allocated.
11792 static int i40e_setup_misc_vector_for_recovery_mode(struct i40e_pf *pf)
11796 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
11797 err = i40e_setup_misc_vector(pf);
11800 dev_info(&pf->pdev->dev,
11801 "MSI-X misc vector request failed, error %d\n",
11806 u32 flags = pf->flags & I40E_FLAG_MSI_ENABLED ? 0 : IRQF_SHARED;
11808 err = request_irq(pf->pdev->irq, i40e_intr, flags,
11812 dev_info(&pf->pdev->dev,
11813 "MSI/legacy misc vector request failed, error %d\n",
11817 i40e_enable_misc_int_causes(pf);
11818 i40e_irq_dynamic_enable_icr0(pf);
11825 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
11826 * @pf: board private structure
11828 * This sets up the handler for MSIX 0, which is used to manage the
11829 * non-queue interrupts, e.g. AdminQ and errors. This is not used
11830 * when in MSI or Legacy interrupt mode.
11832 static int i40e_setup_misc_vector(struct i40e_pf *pf)
11834 struct i40e_hw *hw = &pf->hw;
11837 /* Only request the IRQ once, the first time through. */
11838 if (!test_and_set_bit(__I40E_MISC_IRQ_REQUESTED, pf->state)) {
11839 err = request_irq(pf->msix_entries[0].vector,
11840 i40e_intr, 0, pf->int_name, pf);
11842 clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state);
11843 dev_info(&pf->pdev->dev,
11844 "request_irq for %s failed: %d\n",
11845 pf->int_name, err);
11850 i40e_enable_misc_int_causes(pf);
11852 /* associate no queues to the misc vector */
11853 wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
11854 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K >> 1);
11858 i40e_irq_dynamic_enable_icr0(pf);
11864 * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
11865 * @vsi: Pointer to vsi structure
11866 * @seed: Buffter to store the hash keys
11867 * @lut: Buffer to store the lookup table entries
11868 * @lut_size: Size of buffer to store the lookup table entries
11870 * Return 0 on success, negative on failure
11872 static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
11873 u8 *lut, u16 lut_size)
11875 struct i40e_pf *pf = vsi->back;
11876 struct i40e_hw *hw = &pf->hw;
11880 ret = i40e_aq_get_rss_key(hw, vsi->id,
11881 (struct i40e_aqc_get_set_rss_key_data *)seed);
11883 dev_info(&pf->pdev->dev,
11884 "Cannot get RSS key, err %s aq_err %s\n",
11885 i40e_stat_str(&pf->hw, ret),
11886 i40e_aq_str(&pf->hw,
11887 pf->hw.aq.asq_last_status));
11893 bool pf_lut = vsi->type == I40E_VSI_MAIN;
11895 ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
11897 dev_info(&pf->pdev->dev,
11898 "Cannot get RSS lut, err %s aq_err %s\n",
11899 i40e_stat_str(&pf->hw, ret),
11900 i40e_aq_str(&pf->hw,
11901 pf->hw.aq.asq_last_status));
11910 * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
11911 * @vsi: Pointer to vsi structure
11912 * @seed: RSS hash seed
11913 * @lut: Lookup table
11914 * @lut_size: Lookup table size
11916 * Returns 0 on success, negative on failure
11918 static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
11919 const u8 *lut, u16 lut_size)
11921 struct i40e_pf *pf = vsi->back;
11922 struct i40e_hw *hw = &pf->hw;
11923 u16 vf_id = vsi->vf_id;
11926 /* Fill out hash function seed */
11928 u32 *seed_dw = (u32 *)seed;
11930 if (vsi->type == I40E_VSI_MAIN) {
11931 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
11932 wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]);
11933 } else if (vsi->type == I40E_VSI_SRIOV) {
11934 for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++)
11935 wr32(hw, I40E_VFQF_HKEY1(i, vf_id), seed_dw[i]);
11937 dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n");
11942 u32 *lut_dw = (u32 *)lut;
11944 if (vsi->type == I40E_VSI_MAIN) {
11945 if (lut_size != I40E_HLUT_ARRAY_SIZE)
11947 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
11948 wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
11949 } else if (vsi->type == I40E_VSI_SRIOV) {
11950 if (lut_size != I40E_VF_HLUT_ARRAY_SIZE)
11952 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
11953 wr32(hw, I40E_VFQF_HLUT1(i, vf_id), lut_dw[i]);
11955 dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
11964 * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
11965 * @vsi: Pointer to VSI structure
11966 * @seed: Buffer to store the keys
11967 * @lut: Buffer to store the lookup table entries
11968 * @lut_size: Size of buffer to store the lookup table entries
11970 * Returns 0 on success, negative on failure
11972 static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
11973 u8 *lut, u16 lut_size)
11975 struct i40e_pf *pf = vsi->back;
11976 struct i40e_hw *hw = &pf->hw;
11980 u32 *seed_dw = (u32 *)seed;
11982 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
11983 seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
11986 u32 *lut_dw = (u32 *)lut;
11988 if (lut_size != I40E_HLUT_ARRAY_SIZE)
11990 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
11991 lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
11998 * i40e_config_rss - Configure RSS keys and lut
11999 * @vsi: Pointer to VSI structure
12000 * @seed: RSS hash seed
12001 * @lut: Lookup table
12002 * @lut_size: Lookup table size
12004 * Returns 0 on success, negative on failure
12006 int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
12008 struct i40e_pf *pf = vsi->back;
12010 if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)
12011 return i40e_config_rss_aq(vsi, seed, lut, lut_size);
12013 return i40e_config_rss_reg(vsi, seed, lut, lut_size);
12017 * i40e_get_rss - Get RSS keys and lut
12018 * @vsi: Pointer to VSI structure
12019 * @seed: Buffer to store the keys
12020 * @lut: Buffer to store the lookup table entries
12021 * @lut_size: Size of buffer to store the lookup table entries
12023 * Returns 0 on success, negative on failure
12025 int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
12027 struct i40e_pf *pf = vsi->back;
12029 if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)
12030 return i40e_get_rss_aq(vsi, seed, lut, lut_size);
12032 return i40e_get_rss_reg(vsi, seed, lut, lut_size);
12036 * i40e_fill_rss_lut - Fill the RSS lookup table with default values
12037 * @pf: Pointer to board private structure
12038 * @lut: Lookup table
12039 * @rss_table_size: Lookup table size
12040 * @rss_size: Range of queue number for hashing
12042 void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
12043 u16 rss_table_size, u16 rss_size)
12047 for (i = 0; i < rss_table_size; i++)
12048 lut[i] = i % rss_size;
12052 * i40e_pf_config_rss - Prepare for RSS if used
12053 * @pf: board private structure
12055 static int i40e_pf_config_rss(struct i40e_pf *pf)
12057 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
12058 u8 seed[I40E_HKEY_ARRAY_SIZE];
12060 struct i40e_hw *hw = &pf->hw;
12065 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
12066 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
12067 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
12068 hena |= i40e_pf_get_default_rss_hena(pf);
12070 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
12071 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
12073 /* Determine the RSS table size based on the hardware capabilities */
12074 reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
12075 reg_val = (pf->rss_table_size == 512) ?
12076 (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
12077 (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
12078 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val);
12080 /* Determine the RSS size of the VSI */
12081 if (!vsi->rss_size) {
12083 /* If the firmware does something weird during VSI init, we
12084 * could end up with zero TCs. Check for that to avoid
12085 * divide-by-zero. It probably won't pass traffic, but it also
12088 qcount = vsi->num_queue_pairs /
12089 (vsi->tc_config.numtc ? vsi->tc_config.numtc : 1);
12090 vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
12092 if (!vsi->rss_size)
12095 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
12099 /* Use user configured lut if there is one, otherwise use default */
12100 if (vsi->rss_lut_user)
12101 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
12103 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
12105 /* Use user configured hash key if there is one, otherwise
12108 if (vsi->rss_hkey_user)
12109 memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
12111 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
12112 ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
12119 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
12120 * @pf: board private structure
12121 * @queue_count: the requested queue count for rss.
12123 * returns 0 if rss is not enabled, if enabled returns the final rss queue
12124 * count which may be different from the requested queue count.
12125 * Note: expects to be called while under rtnl_lock()
12127 int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
12129 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
12132 if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
12135 queue_count = min_t(int, queue_count, num_online_cpus());
12136 new_rss_size = min_t(int, queue_count, pf->rss_size_max);
12138 if (queue_count != vsi->num_queue_pairs) {
12141 vsi->req_queue_pairs = queue_count;
12142 i40e_prep_for_reset(pf);
12144 pf->alloc_rss_size = new_rss_size;
12146 i40e_reset_and_rebuild(pf, true, true);
12148 /* Discard the user configured hash keys and lut, if less
12149 * queues are enabled.
12151 if (queue_count < vsi->rss_size) {
12152 i40e_clear_rss_config_user(vsi);
12153 dev_dbg(&pf->pdev->dev,
12154 "discard user configured hash keys and lut\n");
12157 /* Reset vsi->rss_size, as number of enabled queues changed */
12158 qcount = vsi->num_queue_pairs / vsi->tc_config.numtc;
12159 vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
12161 i40e_pf_config_rss(pf);
12163 dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n",
12164 vsi->req_queue_pairs, pf->rss_size_max);
12165 return pf->alloc_rss_size;
12169 * i40e_get_partition_bw_setting - Retrieve BW settings for this PF partition
12170 * @pf: board private structure
12172 i40e_status i40e_get_partition_bw_setting(struct i40e_pf *pf)
12174 i40e_status status;
12175 bool min_valid, max_valid;
12176 u32 max_bw, min_bw;
12178 status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
12179 &min_valid, &max_valid);
12183 pf->min_bw = min_bw;
12185 pf->max_bw = max_bw;
12192 * i40e_set_partition_bw_setting - Set BW settings for this PF partition
12193 * @pf: board private structure
12195 i40e_status i40e_set_partition_bw_setting(struct i40e_pf *pf)
12197 struct i40e_aqc_configure_partition_bw_data bw_data;
12198 i40e_status status;
12200 memset(&bw_data, 0, sizeof(bw_data));
12202 /* Set the valid bit for this PF */
12203 bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
12204 bw_data.max_bw[pf->hw.pf_id] = pf->max_bw & I40E_ALT_BW_VALUE_MASK;
12205 bw_data.min_bw[pf->hw.pf_id] = pf->min_bw & I40E_ALT_BW_VALUE_MASK;
12207 /* Set the new bandwidths */
12208 status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
12214 * i40e_commit_partition_bw_setting - Commit BW settings for this PF partition
12215 * @pf: board private structure
12217 i40e_status i40e_commit_partition_bw_setting(struct i40e_pf *pf)
12219 /* Commit temporary BW setting to permanent NVM image */
12220 enum i40e_admin_queue_err last_aq_status;
12224 if (pf->hw.partition_id != 1) {
12225 dev_info(&pf->pdev->dev,
12226 "Commit BW only works on partition 1! This is partition %d",
12227 pf->hw.partition_id);
12228 ret = I40E_NOT_SUPPORTED;
12229 goto bw_commit_out;
12232 /* Acquire NVM for read access */
12233 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
12234 last_aq_status = pf->hw.aq.asq_last_status;
12236 dev_info(&pf->pdev->dev,
12237 "Cannot acquire NVM for read access, err %s aq_err %s\n",
12238 i40e_stat_str(&pf->hw, ret),
12239 i40e_aq_str(&pf->hw, last_aq_status));
12240 goto bw_commit_out;
12243 /* Read word 0x10 of NVM - SW compatibility word 1 */
12244 ret = i40e_aq_read_nvm(&pf->hw,
12245 I40E_SR_NVM_CONTROL_WORD,
12246 0x10, sizeof(nvm_word), &nvm_word,
12248 /* Save off last admin queue command status before releasing
12251 last_aq_status = pf->hw.aq.asq_last_status;
12252 i40e_release_nvm(&pf->hw);
12254 dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
12255 i40e_stat_str(&pf->hw, ret),
12256 i40e_aq_str(&pf->hw, last_aq_status));
12257 goto bw_commit_out;
12260 /* Wait a bit for NVM release to complete */
12263 /* Acquire NVM for write access */
12264 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
12265 last_aq_status = pf->hw.aq.asq_last_status;
12267 dev_info(&pf->pdev->dev,
12268 "Cannot acquire NVM for write access, err %s aq_err %s\n",
12269 i40e_stat_str(&pf->hw, ret),
12270 i40e_aq_str(&pf->hw, last_aq_status));
12271 goto bw_commit_out;
12273 /* Write it back out unchanged to initiate update NVM,
12274 * which will force a write of the shadow (alt) RAM to
12275 * the NVM - thus storing the bandwidth values permanently.
12277 ret = i40e_aq_update_nvm(&pf->hw,
12278 I40E_SR_NVM_CONTROL_WORD,
12279 0x10, sizeof(nvm_word),
12280 &nvm_word, true, 0, NULL);
12281 /* Save off last admin queue command status before releasing
12284 last_aq_status = pf->hw.aq.asq_last_status;
12285 i40e_release_nvm(&pf->hw);
12287 dev_info(&pf->pdev->dev,
12288 "BW settings NOT SAVED, err %s aq_err %s\n",
12289 i40e_stat_str(&pf->hw, ret),
12290 i40e_aq_str(&pf->hw, last_aq_status));
12297 * i40e_is_total_port_shutdown_enabled - read NVM and return value
12298 * if total port shutdown feature is enabled for this PF
12299 * @pf: board private structure
12301 static bool i40e_is_total_port_shutdown_enabled(struct i40e_pf *pf)
12303 #define I40E_TOTAL_PORT_SHUTDOWN_ENABLED BIT(4)
12304 #define I40E_FEATURES_ENABLE_PTR 0x2A
12305 #define I40E_CURRENT_SETTING_PTR 0x2B
12306 #define I40E_LINK_BEHAVIOR_WORD_OFFSET 0x2D
12307 #define I40E_LINK_BEHAVIOR_WORD_LENGTH 0x1
12308 #define I40E_LINK_BEHAVIOR_OS_FORCED_ENABLED BIT(0)
12309 #define I40E_LINK_BEHAVIOR_PORT_BIT_LENGTH 4
12310 i40e_status read_status = I40E_SUCCESS;
12311 u16 sr_emp_sr_settings_ptr = 0;
12312 u16 features_enable = 0;
12313 u16 link_behavior = 0;
12316 read_status = i40e_read_nvm_word(&pf->hw,
12317 I40E_SR_EMP_SR_SETTINGS_PTR,
12318 &sr_emp_sr_settings_ptr);
12321 read_status = i40e_read_nvm_word(&pf->hw,
12322 sr_emp_sr_settings_ptr +
12323 I40E_FEATURES_ENABLE_PTR,
12327 if (I40E_TOTAL_PORT_SHUTDOWN_ENABLED & features_enable) {
12328 read_status = i40e_read_nvm_module_data(&pf->hw,
12329 I40E_SR_EMP_SR_SETTINGS_PTR,
12330 I40E_CURRENT_SETTING_PTR,
12331 I40E_LINK_BEHAVIOR_WORD_OFFSET,
12332 I40E_LINK_BEHAVIOR_WORD_LENGTH,
12336 link_behavior >>= (pf->hw.port * I40E_LINK_BEHAVIOR_PORT_BIT_LENGTH);
12337 ret = I40E_LINK_BEHAVIOR_OS_FORCED_ENABLED & link_behavior;
12342 dev_warn(&pf->pdev->dev,
12343 "total-port-shutdown feature is off due to read nvm error: %s\n",
12344 i40e_stat_str(&pf->hw, read_status));
12349 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
12350 * @pf: board private structure to initialize
12352 * i40e_sw_init initializes the Adapter private data structure.
12353 * Fields are initialized based on PCI device information and
12354 * OS network device settings (MTU size).
12356 static int i40e_sw_init(struct i40e_pf *pf)
12361 /* Set default capability flags */
12362 pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
12363 I40E_FLAG_MSI_ENABLED |
12364 I40E_FLAG_MSIX_ENABLED;
12366 /* Set default ITR */
12367 pf->rx_itr_default = I40E_ITR_RX_DEF;
12368 pf->tx_itr_default = I40E_ITR_TX_DEF;
12370 /* Depending on PF configurations, it is possible that the RSS
12371 * maximum might end up larger than the available queues
12373 pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
12374 pf->alloc_rss_size = 1;
12375 pf->rss_table_size = pf->hw.func_caps.rss_table_size;
12376 pf->rss_size_max = min_t(int, pf->rss_size_max,
12377 pf->hw.func_caps.num_tx_qp);
12378 if (pf->hw.func_caps.rss) {
12379 pf->flags |= I40E_FLAG_RSS_ENABLED;
12380 pf->alloc_rss_size = min_t(int, pf->rss_size_max,
12381 num_online_cpus());
12384 /* MFP mode enabled */
12385 if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
12386 pf->flags |= I40E_FLAG_MFP_ENABLED;
12387 dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
12388 if (i40e_get_partition_bw_setting(pf)) {
12389 dev_warn(&pf->pdev->dev,
12390 "Could not get partition bw settings\n");
12392 dev_info(&pf->pdev->dev,
12393 "Partition BW Min = %8.8x, Max = %8.8x\n",
12394 pf->min_bw, pf->max_bw);
12396 /* nudge the Tx scheduler */
12397 i40e_set_partition_bw_setting(pf);
12401 if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
12402 (pf->hw.func_caps.fd_filters_best_effort > 0)) {
12403 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
12404 pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
12405 if (pf->flags & I40E_FLAG_MFP_ENABLED &&
12406 pf->hw.num_partitions > 1)
12407 dev_info(&pf->pdev->dev,
12408 "Flow Director Sideband mode Disabled in MFP mode\n");
12410 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
12411 pf->fdir_pf_filter_count =
12412 pf->hw.func_caps.fd_filters_guaranteed;
12413 pf->hw.fdir_shared_filter_count =
12414 pf->hw.func_caps.fd_filters_best_effort;
12417 if (pf->hw.mac.type == I40E_MAC_X722) {
12418 pf->hw_features |= (I40E_HW_RSS_AQ_CAPABLE |
12419 I40E_HW_128_QP_RSS_CAPABLE |
12420 I40E_HW_ATR_EVICT_CAPABLE |
12421 I40E_HW_WB_ON_ITR_CAPABLE |
12422 I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE |
12423 I40E_HW_NO_PCI_LINK_CHECK |
12424 I40E_HW_USE_SET_LLDP_MIB |
12425 I40E_HW_GENEVE_OFFLOAD_CAPABLE |
12426 I40E_HW_PTP_L4_CAPABLE |
12427 I40E_HW_WOL_MC_MAGIC_PKT_WAKE |
12428 I40E_HW_OUTER_UDP_CSUM_CAPABLE);
12430 #define I40E_FDEVICT_PCTYPE_DEFAULT 0xc03
12431 if (rd32(&pf->hw, I40E_GLQF_FDEVICTENA(1)) !=
12432 I40E_FDEVICT_PCTYPE_DEFAULT) {
12433 dev_warn(&pf->pdev->dev,
12434 "FD EVICT PCTYPES are not right, disable FD HW EVICT\n");
12435 pf->hw_features &= ~I40E_HW_ATR_EVICT_CAPABLE;
12437 } else if ((pf->hw.aq.api_maj_ver > 1) ||
12438 ((pf->hw.aq.api_maj_ver == 1) &&
12439 (pf->hw.aq.api_min_ver > 4))) {
12440 /* Supported in FW API version higher than 1.4 */
12441 pf->hw_features |= I40E_HW_GENEVE_OFFLOAD_CAPABLE;
12444 /* Enable HW ATR eviction if possible */
12445 if (pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE)
12446 pf->flags |= I40E_FLAG_HW_ATR_EVICT_ENABLED;
12448 if ((pf->hw.mac.type == I40E_MAC_XL710) &&
12449 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
12450 (pf->hw.aq.fw_maj_ver < 4))) {
12451 pf->hw_features |= I40E_HW_RESTART_AUTONEG;
12452 /* No DCB support for FW < v4.33 */
12453 pf->hw_features |= I40E_HW_NO_DCB_SUPPORT;
12456 /* Disable FW LLDP if FW < v4.3 */
12457 if ((pf->hw.mac.type == I40E_MAC_XL710) &&
12458 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
12459 (pf->hw.aq.fw_maj_ver < 4)))
12460 pf->hw_features |= I40E_HW_STOP_FW_LLDP;
12462 /* Use the FW Set LLDP MIB API if FW > v4.40 */
12463 if ((pf->hw.mac.type == I40E_MAC_XL710) &&
12464 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) ||
12465 (pf->hw.aq.fw_maj_ver >= 5)))
12466 pf->hw_features |= I40E_HW_USE_SET_LLDP_MIB;
12468 /* Enable PTP L4 if FW > v6.0 */
12469 if (pf->hw.mac.type == I40E_MAC_XL710 &&
12470 pf->hw.aq.fw_maj_ver >= 6)
12471 pf->hw_features |= I40E_HW_PTP_L4_CAPABLE;
12473 if (pf->hw.func_caps.vmdq && num_online_cpus() != 1) {
12474 pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
12475 pf->flags |= I40E_FLAG_VMDQ_ENABLED;
12476 pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
12479 if (pf->hw.func_caps.iwarp && num_online_cpus() != 1) {
12480 pf->flags |= I40E_FLAG_IWARP_ENABLED;
12481 /* IWARP needs one extra vector for CQP just like MISC.*/
12482 pf->num_iwarp_msix = (int)num_online_cpus() + 1;
12484 /* Stopping FW LLDP engine is supported on XL710 and X722
12485 * starting from FW versions determined in i40e_init_adminq.
12486 * Stopping the FW LLDP engine is not supported on XL710
12487 * if NPAR is functioning so unset this hw flag in this case.
12489 if (pf->hw.mac.type == I40E_MAC_XL710 &&
12490 pf->hw.func_caps.npar_enable &&
12491 (pf->hw.flags & I40E_HW_FLAG_FW_LLDP_STOPPABLE))
12492 pf->hw.flags &= ~I40E_HW_FLAG_FW_LLDP_STOPPABLE;
12494 #ifdef CONFIG_PCI_IOV
12495 if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
12496 pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
12497 pf->flags |= I40E_FLAG_SRIOV_ENABLED;
12498 pf->num_req_vfs = min_t(int,
12499 pf->hw.func_caps.num_vfs,
12500 I40E_MAX_VF_COUNT);
12502 #endif /* CONFIG_PCI_IOV */
12503 pf->eeprom_version = 0xDEAD;
12504 pf->lan_veb = I40E_NO_VEB;
12505 pf->lan_vsi = I40E_NO_VSI;
12507 /* By default FW has this off for performance reasons */
12508 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
12510 /* set up queue assignment tracking */
12511 size = sizeof(struct i40e_lump_tracking)
12512 + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
12513 pf->qp_pile = kzalloc(size, GFP_KERNEL);
12514 if (!pf->qp_pile) {
12518 pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
12519 pf->qp_pile->search_hint = 0;
12521 pf->tx_timeout_recovery_level = 1;
12523 if (pf->hw.mac.type != I40E_MAC_X722 &&
12524 i40e_is_total_port_shutdown_enabled(pf)) {
12525 /* Link down on close must be on when total port shutdown
12526 * is enabled for a given port
12528 pf->flags |= (I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENABLED |
12529 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED);
12530 dev_info(&pf->pdev->dev,
12531 "total-port-shutdown was enabled, link-down-on-close is forced on\n");
12533 mutex_init(&pf->switch_mutex);
12540 * i40e_set_ntuple - set the ntuple feature flag and take action
12541 * @pf: board private structure to initialize
12542 * @features: the feature set that the stack is suggesting
12544 * returns a bool to indicate if reset needs to happen
12546 bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
12548 bool need_reset = false;
12550 /* Check if Flow Director n-tuple support was enabled or disabled. If
12551 * the state changed, we need to reset.
12553 if (features & NETIF_F_NTUPLE) {
12554 /* Enable filters and mark for reset */
12555 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
12557 /* enable FD_SB only if there is MSI-X vector and no cloud
12560 if (pf->num_fdsb_msix > 0 && !pf->num_cloud_filters) {
12561 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
12562 pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
12565 /* turn off filters, mark for reset and clear SW filter list */
12566 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
12568 i40e_fdir_filter_exit(pf);
12570 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
12571 clear_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state);
12572 pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
12574 /* reset fd counters */
12575 pf->fd_add_err = 0;
12576 pf->fd_atr_cnt = 0;
12577 /* if ATR was auto disabled it can be re-enabled. */
12578 if (test_and_clear_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state))
12579 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
12580 (I40E_DEBUG_FD & pf->hw.debug_mask))
12581 dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
12587 * i40e_clear_rss_lut - clear the rx hash lookup table
12588 * @vsi: the VSI being configured
12590 static void i40e_clear_rss_lut(struct i40e_vsi *vsi)
12592 struct i40e_pf *pf = vsi->back;
12593 struct i40e_hw *hw = &pf->hw;
12594 u16 vf_id = vsi->vf_id;
12597 if (vsi->type == I40E_VSI_MAIN) {
12598 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
12599 wr32(hw, I40E_PFQF_HLUT(i), 0);
12600 } else if (vsi->type == I40E_VSI_SRIOV) {
12601 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
12602 i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0);
12604 dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
12609 * i40e_set_features - set the netdev feature flags
12610 * @netdev: ptr to the netdev being adjusted
12611 * @features: the feature set that the stack is suggesting
12612 * Note: expects to be called while under rtnl_lock()
12614 static int i40e_set_features(struct net_device *netdev,
12615 netdev_features_t features)
12617 struct i40e_netdev_priv *np = netdev_priv(netdev);
12618 struct i40e_vsi *vsi = np->vsi;
12619 struct i40e_pf *pf = vsi->back;
12622 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
12623 i40e_pf_config_rss(pf);
12624 else if (!(features & NETIF_F_RXHASH) &&
12625 netdev->features & NETIF_F_RXHASH)
12626 i40e_clear_rss_lut(vsi);
12628 if (features & NETIF_F_HW_VLAN_CTAG_RX)
12629 i40e_vlan_stripping_enable(vsi);
12631 i40e_vlan_stripping_disable(vsi);
12633 if (!(features & NETIF_F_HW_TC) && pf->num_cloud_filters) {
12634 dev_err(&pf->pdev->dev,
12635 "Offloaded tc filters active, can't turn hw_tc_offload off");
12639 if (!(features & NETIF_F_HW_L2FW_DOFFLOAD) && vsi->macvlan_cnt)
12640 i40e_del_all_macvlans(vsi);
12642 need_reset = i40e_set_ntuple(pf, features);
12645 i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
12650 static int i40e_udp_tunnel_set_port(struct net_device *netdev,
12651 unsigned int table, unsigned int idx,
12652 struct udp_tunnel_info *ti)
12654 struct i40e_netdev_priv *np = netdev_priv(netdev);
12655 struct i40e_hw *hw = &np->vsi->back->hw;
12656 u8 type, filter_index;
12659 type = ti->type == UDP_TUNNEL_TYPE_VXLAN ? I40E_AQC_TUNNEL_TYPE_VXLAN :
12660 I40E_AQC_TUNNEL_TYPE_NGE;
12662 ret = i40e_aq_add_udp_tunnel(hw, ntohs(ti->port), type, &filter_index,
12665 netdev_info(netdev, "add UDP port failed, err %s aq_err %s\n",
12666 i40e_stat_str(hw, ret),
12667 i40e_aq_str(hw, hw->aq.asq_last_status));
12671 udp_tunnel_nic_set_port_priv(netdev, table, idx, filter_index);
12675 static int i40e_udp_tunnel_unset_port(struct net_device *netdev,
12676 unsigned int table, unsigned int idx,
12677 struct udp_tunnel_info *ti)
12679 struct i40e_netdev_priv *np = netdev_priv(netdev);
12680 struct i40e_hw *hw = &np->vsi->back->hw;
12683 ret = i40e_aq_del_udp_tunnel(hw, ti->hw_priv, NULL);
12685 netdev_info(netdev, "delete UDP port failed, err %s aq_err %s\n",
12686 i40e_stat_str(hw, ret),
12687 i40e_aq_str(hw, hw->aq.asq_last_status));
12694 static int i40e_get_phys_port_id(struct net_device *netdev,
12695 struct netdev_phys_item_id *ppid)
12697 struct i40e_netdev_priv *np = netdev_priv(netdev);
12698 struct i40e_pf *pf = np->vsi->back;
12699 struct i40e_hw *hw = &pf->hw;
12701 if (!(pf->hw_features & I40E_HW_PORT_ID_VALID))
12702 return -EOPNOTSUPP;
12704 ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
12705 memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
12711 * i40e_ndo_fdb_add - add an entry to the hardware database
12712 * @ndm: the input from the stack
12713 * @tb: pointer to array of nladdr (unused)
12714 * @dev: the net device pointer
12715 * @addr: the MAC address entry being added
12717 * @flags: instructions from stack about fdb operation
12718 * @extack: netlink extended ack, unused currently
12720 static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
12721 struct net_device *dev,
12722 const unsigned char *addr, u16 vid,
12724 struct netlink_ext_ack *extack)
12726 struct i40e_netdev_priv *np = netdev_priv(dev);
12727 struct i40e_pf *pf = np->vsi->back;
12730 if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
12731 return -EOPNOTSUPP;
12734 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
12738 /* Hardware does not support aging addresses so if a
12739 * ndm_state is given only allow permanent addresses
12741 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
12742 netdev_info(dev, "FDB only supports static addresses\n");
12746 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
12747 err = dev_uc_add_excl(dev, addr);
12748 else if (is_multicast_ether_addr(addr))
12749 err = dev_mc_add_excl(dev, addr);
12753 /* Only return duplicate errors if NLM_F_EXCL is set */
12754 if (err == -EEXIST && !(flags & NLM_F_EXCL))
12761 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
12762 * @dev: the netdev being configured
12763 * @nlh: RTNL message
12764 * @flags: bridge flags
12765 * @extack: netlink extended ack
12767 * Inserts a new hardware bridge if not already created and
12768 * enables the bridging mode requested (VEB or VEPA). If the
12769 * hardware bridge has already been inserted and the request
12770 * is to change the mode then that requires a PF reset to
12771 * allow rebuild of the components with required hardware
12772 * bridge mode enabled.
12774 * Note: expects to be called while under rtnl_lock()
12776 static int i40e_ndo_bridge_setlink(struct net_device *dev,
12777 struct nlmsghdr *nlh,
12779 struct netlink_ext_ack *extack)
12781 struct i40e_netdev_priv *np = netdev_priv(dev);
12782 struct i40e_vsi *vsi = np->vsi;
12783 struct i40e_pf *pf = vsi->back;
12784 struct i40e_veb *veb = NULL;
12785 struct nlattr *attr, *br_spec;
12788 /* Only for PF VSI for now */
12789 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
12790 return -EOPNOTSUPP;
12792 /* Find the HW bridge for PF VSI */
12793 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
12794 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
12798 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
12800 nla_for_each_nested(attr, br_spec, rem) {
12803 if (nla_type(attr) != IFLA_BRIDGE_MODE)
12806 mode = nla_get_u16(attr);
12807 if ((mode != BRIDGE_MODE_VEPA) &&
12808 (mode != BRIDGE_MODE_VEB))
12811 /* Insert a new HW bridge */
12813 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
12814 vsi->tc_config.enabled_tc);
12816 veb->bridge_mode = mode;
12817 i40e_config_bridge_mode(veb);
12819 /* No Bridge HW offload available */
12823 } else if (mode != veb->bridge_mode) {
12824 /* Existing HW bridge but different mode needs reset */
12825 veb->bridge_mode = mode;
12826 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
12827 if (mode == BRIDGE_MODE_VEB)
12828 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
12830 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
12831 i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
12840 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
12843 * @seq: RTNL message seq #
12844 * @dev: the netdev being configured
12845 * @filter_mask: unused
12846 * @nlflags: netlink flags passed in
12848 * Return the mode in which the hardware bridge is operating in
12851 static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
12852 struct net_device *dev,
12853 u32 __always_unused filter_mask,
12856 struct i40e_netdev_priv *np = netdev_priv(dev);
12857 struct i40e_vsi *vsi = np->vsi;
12858 struct i40e_pf *pf = vsi->back;
12859 struct i40e_veb *veb = NULL;
12862 /* Only for PF VSI for now */
12863 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
12864 return -EOPNOTSUPP;
12866 /* Find the HW bridge for the PF VSI */
12867 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
12868 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
12875 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
12876 0, 0, nlflags, filter_mask, NULL);
12880 * i40e_features_check - Validate encapsulated packet conforms to limits
12882 * @dev: This physical port's netdev
12883 * @features: Offload features that the stack believes apply
12885 static netdev_features_t i40e_features_check(struct sk_buff *skb,
12886 struct net_device *dev,
12887 netdev_features_t features)
12891 /* No point in doing any of this if neither checksum nor GSO are
12892 * being requested for this frame. We can rule out both by just
12893 * checking for CHECKSUM_PARTIAL
12895 if (skb->ip_summed != CHECKSUM_PARTIAL)
12898 /* We cannot support GSO if the MSS is going to be less than
12899 * 64 bytes. If it is then we need to drop support for GSO.
12901 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
12902 features &= ~NETIF_F_GSO_MASK;
12904 /* MACLEN can support at most 63 words */
12905 len = skb_network_header(skb) - skb->data;
12906 if (len & ~(63 * 2))
12909 /* IPLEN and EIPLEN can support at most 127 dwords */
12910 len = skb_transport_header(skb) - skb_network_header(skb);
12911 if (len & ~(127 * 4))
12914 if (skb->encapsulation) {
12915 /* L4TUNLEN can support 127 words */
12916 len = skb_inner_network_header(skb) - skb_transport_header(skb);
12917 if (len & ~(127 * 2))
12920 /* IPLEN can support at most 127 dwords */
12921 len = skb_inner_transport_header(skb) -
12922 skb_inner_network_header(skb);
12923 if (len & ~(127 * 4))
12927 /* No need to validate L4LEN as TCP is the only protocol with a
12928 * a flexible value and we support all possible values supported
12929 * by TCP, which is at most 15 dwords
12934 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
12938 * i40e_xdp_setup - add/remove an XDP program
12939 * @vsi: VSI to changed
12940 * @prog: XDP program
12941 * @extack: netlink extended ack
12943 static int i40e_xdp_setup(struct i40e_vsi *vsi, struct bpf_prog *prog,
12944 struct netlink_ext_ack *extack)
12946 int frame_size = vsi->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
12947 struct i40e_pf *pf = vsi->back;
12948 struct bpf_prog *old_prog;
12952 /* Don't allow frames that span over multiple buffers */
12953 if (frame_size > vsi->rx_buf_len) {
12954 NL_SET_ERR_MSG_MOD(extack, "MTU too large to enable XDP");
12958 /* When turning XDP on->off/off->on we reset and rebuild the rings. */
12959 need_reset = (i40e_enabled_xdp_vsi(vsi) != !!prog);
12962 i40e_prep_for_reset(pf);
12964 old_prog = xchg(&vsi->xdp_prog, prog);
12968 /* Wait until ndo_xsk_wakeup completes. */
12970 i40e_reset_and_rebuild(pf, true, true);
12973 for (i = 0; i < vsi->num_queue_pairs; i++)
12974 WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
12977 bpf_prog_put(old_prog);
12979 /* Kick start the NAPI context if there is an AF_XDP socket open
12980 * on that queue id. This so that receiving will start.
12982 if (need_reset && prog)
12983 for (i = 0; i < vsi->num_queue_pairs; i++)
12984 if (vsi->xdp_rings[i]->xsk_pool)
12985 (void)i40e_xsk_wakeup(vsi->netdev, i,
12992 * i40e_enter_busy_conf - Enters busy config state
12995 * Returns 0 on success, <0 for failure.
12997 static int i40e_enter_busy_conf(struct i40e_vsi *vsi)
12999 struct i40e_pf *pf = vsi->back;
13002 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
13006 usleep_range(1000, 2000);
13013 * i40e_exit_busy_conf - Exits busy config state
13016 static void i40e_exit_busy_conf(struct i40e_vsi *vsi)
13018 struct i40e_pf *pf = vsi->back;
13020 clear_bit(__I40E_CONFIG_BUSY, pf->state);
13024 * i40e_queue_pair_reset_stats - Resets all statistics for a queue pair
13026 * @queue_pair: queue pair
13028 static void i40e_queue_pair_reset_stats(struct i40e_vsi *vsi, int queue_pair)
13030 memset(&vsi->rx_rings[queue_pair]->rx_stats, 0,
13031 sizeof(vsi->rx_rings[queue_pair]->rx_stats));
13032 memset(&vsi->tx_rings[queue_pair]->stats, 0,
13033 sizeof(vsi->tx_rings[queue_pair]->stats));
13034 if (i40e_enabled_xdp_vsi(vsi)) {
13035 memset(&vsi->xdp_rings[queue_pair]->stats, 0,
13036 sizeof(vsi->xdp_rings[queue_pair]->stats));
13041 * i40e_queue_pair_clean_rings - Cleans all the rings of a queue pair
13043 * @queue_pair: queue pair
13045 static void i40e_queue_pair_clean_rings(struct i40e_vsi *vsi, int queue_pair)
13047 i40e_clean_tx_ring(vsi->tx_rings[queue_pair]);
13048 if (i40e_enabled_xdp_vsi(vsi)) {
13049 /* Make sure that in-progress ndo_xdp_xmit calls are
13053 i40e_clean_tx_ring(vsi->xdp_rings[queue_pair]);
13055 i40e_clean_rx_ring(vsi->rx_rings[queue_pair]);
13059 * i40e_queue_pair_toggle_napi - Enables/disables NAPI for a queue pair
13061 * @queue_pair: queue pair
13062 * @enable: true for enable, false for disable
13064 static void i40e_queue_pair_toggle_napi(struct i40e_vsi *vsi, int queue_pair,
13067 struct i40e_ring *rxr = vsi->rx_rings[queue_pair];
13068 struct i40e_q_vector *q_vector = rxr->q_vector;
13073 /* All rings in a qp belong to the same qvector. */
13074 if (q_vector->rx.ring || q_vector->tx.ring) {
13076 napi_enable(&q_vector->napi);
13078 napi_disable(&q_vector->napi);
13083 * i40e_queue_pair_toggle_rings - Enables/disables all rings for a queue pair
13085 * @queue_pair: queue pair
13086 * @enable: true for enable, false for disable
13088 * Returns 0 on success, <0 on failure.
13090 static int i40e_queue_pair_toggle_rings(struct i40e_vsi *vsi, int queue_pair,
13093 struct i40e_pf *pf = vsi->back;
13096 pf_q = vsi->base_queue + queue_pair;
13097 ret = i40e_control_wait_tx_q(vsi->seid, pf, pf_q,
13098 false /*is xdp*/, enable);
13100 dev_info(&pf->pdev->dev,
13101 "VSI seid %d Tx ring %d %sable timeout\n",
13102 vsi->seid, pf_q, (enable ? "en" : "dis"));
13106 i40e_control_rx_q(pf, pf_q, enable);
13107 ret = i40e_pf_rxq_wait(pf, pf_q, enable);
13109 dev_info(&pf->pdev->dev,
13110 "VSI seid %d Rx ring %d %sable timeout\n",
13111 vsi->seid, pf_q, (enable ? "en" : "dis"));
13115 /* Due to HW errata, on Rx disable only, the register can
13116 * indicate done before it really is. Needs 50ms to be sure
13121 if (!i40e_enabled_xdp_vsi(vsi))
13124 ret = i40e_control_wait_tx_q(vsi->seid, pf,
13125 pf_q + vsi->alloc_queue_pairs,
13126 true /*is xdp*/, enable);
13128 dev_info(&pf->pdev->dev,
13129 "VSI seid %d XDP Tx ring %d %sable timeout\n",
13130 vsi->seid, pf_q, (enable ? "en" : "dis"));
13137 * i40e_queue_pair_enable_irq - Enables interrupts for a queue pair
13139 * @queue_pair: queue_pair
13141 static void i40e_queue_pair_enable_irq(struct i40e_vsi *vsi, int queue_pair)
13143 struct i40e_ring *rxr = vsi->rx_rings[queue_pair];
13144 struct i40e_pf *pf = vsi->back;
13145 struct i40e_hw *hw = &pf->hw;
13147 /* All rings in a qp belong to the same qvector. */
13148 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
13149 i40e_irq_dynamic_enable(vsi, rxr->q_vector->v_idx);
13151 i40e_irq_dynamic_enable_icr0(pf);
13157 * i40e_queue_pair_disable_irq - Disables interrupts for a queue pair
13159 * @queue_pair: queue_pair
13161 static void i40e_queue_pair_disable_irq(struct i40e_vsi *vsi, int queue_pair)
13163 struct i40e_ring *rxr = vsi->rx_rings[queue_pair];
13164 struct i40e_pf *pf = vsi->back;
13165 struct i40e_hw *hw = &pf->hw;
13167 /* For simplicity, instead of removing the qp interrupt causes
13168 * from the interrupt linked list, we simply disable the interrupt, and
13169 * leave the list intact.
13171 * All rings in a qp belong to the same qvector.
13173 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
13174 u32 intpf = vsi->base_vector + rxr->q_vector->v_idx;
13176 wr32(hw, I40E_PFINT_DYN_CTLN(intpf - 1), 0);
13178 synchronize_irq(pf->msix_entries[intpf].vector);
13180 /* Legacy and MSI mode - this stops all interrupt handling */
13181 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
13182 wr32(hw, I40E_PFINT_DYN_CTL0, 0);
13184 synchronize_irq(pf->pdev->irq);
13189 * i40e_queue_pair_disable - Disables a queue pair
13191 * @queue_pair: queue pair
13193 * Returns 0 on success, <0 on failure.
13195 int i40e_queue_pair_disable(struct i40e_vsi *vsi, int queue_pair)
13199 err = i40e_enter_busy_conf(vsi);
13203 i40e_queue_pair_disable_irq(vsi, queue_pair);
13204 err = i40e_queue_pair_toggle_rings(vsi, queue_pair, false /* off */);
13205 i40e_queue_pair_toggle_napi(vsi, queue_pair, false /* off */);
13206 i40e_queue_pair_clean_rings(vsi, queue_pair);
13207 i40e_queue_pair_reset_stats(vsi, queue_pair);
13213 * i40e_queue_pair_enable - Enables a queue pair
13215 * @queue_pair: queue pair
13217 * Returns 0 on success, <0 on failure.
13219 int i40e_queue_pair_enable(struct i40e_vsi *vsi, int queue_pair)
13223 err = i40e_configure_tx_ring(vsi->tx_rings[queue_pair]);
13227 if (i40e_enabled_xdp_vsi(vsi)) {
13228 err = i40e_configure_tx_ring(vsi->xdp_rings[queue_pair]);
13233 err = i40e_configure_rx_ring(vsi->rx_rings[queue_pair]);
13237 err = i40e_queue_pair_toggle_rings(vsi, queue_pair, true /* on */);
13238 i40e_queue_pair_toggle_napi(vsi, queue_pair, true /* on */);
13239 i40e_queue_pair_enable_irq(vsi, queue_pair);
13241 i40e_exit_busy_conf(vsi);
13247 * i40e_xdp - implements ndo_bpf for i40e
13249 * @xdp: XDP command
13251 static int i40e_xdp(struct net_device *dev,
13252 struct netdev_bpf *xdp)
13254 struct i40e_netdev_priv *np = netdev_priv(dev);
13255 struct i40e_vsi *vsi = np->vsi;
13257 if (vsi->type != I40E_VSI_MAIN)
13260 switch (xdp->command) {
13261 case XDP_SETUP_PROG:
13262 return i40e_xdp_setup(vsi, xdp->prog, xdp->extack);
13263 case XDP_SETUP_XSK_POOL:
13264 return i40e_xsk_pool_setup(vsi, xdp->xsk.pool,
13265 xdp->xsk.queue_id);
13271 static const struct net_device_ops i40e_netdev_ops = {
13272 .ndo_open = i40e_open,
13273 .ndo_stop = i40e_close,
13274 .ndo_start_xmit = i40e_lan_xmit_frame,
13275 .ndo_get_stats64 = i40e_get_netdev_stats_struct,
13276 .ndo_set_rx_mode = i40e_set_rx_mode,
13277 .ndo_validate_addr = eth_validate_addr,
13278 .ndo_set_mac_address = i40e_set_mac,
13279 .ndo_change_mtu = i40e_change_mtu,
13280 .ndo_do_ioctl = i40e_ioctl,
13281 .ndo_tx_timeout = i40e_tx_timeout,
13282 .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
13283 .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
13284 #ifdef CONFIG_NET_POLL_CONTROLLER
13285 .ndo_poll_controller = i40e_netpoll,
13287 .ndo_setup_tc = __i40e_setup_tc,
13288 .ndo_set_features = i40e_set_features,
13289 .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
13290 .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
13291 .ndo_get_vf_stats = i40e_get_vf_stats,
13292 .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
13293 .ndo_get_vf_config = i40e_ndo_get_vf_config,
13294 .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
13295 .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
13296 .ndo_set_vf_trust = i40e_ndo_set_vf_trust,
13297 .ndo_get_phys_port_id = i40e_get_phys_port_id,
13298 .ndo_fdb_add = i40e_ndo_fdb_add,
13299 .ndo_features_check = i40e_features_check,
13300 .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
13301 .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
13302 .ndo_bpf = i40e_xdp,
13303 .ndo_xdp_xmit = i40e_xdp_xmit,
13304 .ndo_xsk_wakeup = i40e_xsk_wakeup,
13305 .ndo_dfwd_add_station = i40e_fwd_add,
13306 .ndo_dfwd_del_station = i40e_fwd_del,
13310 * i40e_config_netdev - Setup the netdev flags
13311 * @vsi: the VSI being configured
13313 * Returns 0 on success, negative value on failure
13315 static int i40e_config_netdev(struct i40e_vsi *vsi)
13317 struct i40e_pf *pf = vsi->back;
13318 struct i40e_hw *hw = &pf->hw;
13319 struct i40e_netdev_priv *np;
13320 struct net_device *netdev;
13321 u8 broadcast[ETH_ALEN];
13322 u8 mac_addr[ETH_ALEN];
13324 netdev_features_t hw_enc_features;
13325 netdev_features_t hw_features;
13327 etherdev_size = sizeof(struct i40e_netdev_priv);
13328 netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
13332 vsi->netdev = netdev;
13333 np = netdev_priv(netdev);
13336 hw_enc_features = NETIF_F_SG |
13338 NETIF_F_IPV6_CSUM |
13340 NETIF_F_SOFT_FEATURES |
13345 NETIF_F_GSO_GRE_CSUM |
13346 NETIF_F_GSO_PARTIAL |
13347 NETIF_F_GSO_IPXIP4 |
13348 NETIF_F_GSO_IPXIP6 |
13349 NETIF_F_GSO_UDP_TUNNEL |
13350 NETIF_F_GSO_UDP_TUNNEL_CSUM |
13351 NETIF_F_GSO_UDP_L4 |
13357 if (!(pf->hw_features & I40E_HW_OUTER_UDP_CSUM_CAPABLE))
13358 netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
13360 netdev->udp_tunnel_nic_info = &pf->udp_tunnel_nic;
13362 netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
13364 netdev->hw_enc_features |= hw_enc_features;
13366 /* record features VLANs can make use of */
13367 netdev->vlan_features |= hw_enc_features | NETIF_F_TSO_MANGLEID;
13369 /* enable macvlan offloads */
13370 netdev->hw_features |= NETIF_F_HW_L2FW_DOFFLOAD;
13372 hw_features = hw_enc_features |
13373 NETIF_F_HW_VLAN_CTAG_TX |
13374 NETIF_F_HW_VLAN_CTAG_RX;
13376 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
13377 hw_features |= NETIF_F_NTUPLE | NETIF_F_HW_TC;
13379 netdev->hw_features |= hw_features;
13381 netdev->features |= hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
13382 netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
13384 if (vsi->type == I40E_VSI_MAIN) {
13385 SET_NETDEV_DEV(netdev, &pf->pdev->dev);
13386 ether_addr_copy(mac_addr, hw->mac.perm_addr);
13387 /* The following steps are necessary for two reasons. First,
13388 * some older NVM configurations load a default MAC-VLAN
13389 * filter that will accept any tagged packet, and we want to
13390 * replace this with a normal filter. Additionally, it is
13391 * possible our MAC address was provided by the platform using
13392 * Open Firmware or similar.
13394 * Thus, we need to remove the default filter and install one
13395 * specific to the MAC address.
13397 i40e_rm_default_mac_filter(vsi, mac_addr);
13398 spin_lock_bh(&vsi->mac_filter_hash_lock);
13399 i40e_add_mac_filter(vsi, mac_addr);
13400 spin_unlock_bh(&vsi->mac_filter_hash_lock);
13402 /* Relate the VSI_VMDQ name to the VSI_MAIN name. Note that we
13403 * are still limited by IFNAMSIZ, but we're adding 'v%d\0' to
13404 * the end, which is 4 bytes long, so force truncation of the
13405 * original name by IFNAMSIZ - 4
13407 snprintf(netdev->name, IFNAMSIZ, "%.*sv%%d",
13409 pf->vsi[pf->lan_vsi]->netdev->name);
13410 eth_random_addr(mac_addr);
13412 spin_lock_bh(&vsi->mac_filter_hash_lock);
13413 i40e_add_mac_filter(vsi, mac_addr);
13414 spin_unlock_bh(&vsi->mac_filter_hash_lock);
13417 /* Add the broadcast filter so that we initially will receive
13418 * broadcast packets. Note that when a new VLAN is first added the
13419 * driver will convert all filters marked I40E_VLAN_ANY into VLAN
13420 * specific filters as part of transitioning into "vlan" operation.
13421 * When more VLANs are added, the driver will copy each existing MAC
13422 * filter and add it for the new VLAN.
13424 * Broadcast filters are handled specially by
13425 * i40e_sync_filters_subtask, as the driver must to set the broadcast
13426 * promiscuous bit instead of adding this directly as a MAC/VLAN
13427 * filter. The subtask will update the correct broadcast promiscuous
13428 * bits as VLANs become active or inactive.
13430 eth_broadcast_addr(broadcast);
13431 spin_lock_bh(&vsi->mac_filter_hash_lock);
13432 i40e_add_mac_filter(vsi, broadcast);
13433 spin_unlock_bh(&vsi->mac_filter_hash_lock);
13435 ether_addr_copy(netdev->dev_addr, mac_addr);
13436 ether_addr_copy(netdev->perm_addr, mac_addr);
13438 /* i40iw_net_event() reads 16 bytes from neigh->primary_key */
13439 netdev->neigh_priv_len = sizeof(u32) * 4;
13441 netdev->priv_flags |= IFF_UNICAST_FLT;
13442 netdev->priv_flags |= IFF_SUPP_NOFCS;
13443 /* Setup netdev TC information */
13444 i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
13446 netdev->netdev_ops = &i40e_netdev_ops;
13447 netdev->watchdog_timeo = 5 * HZ;
13448 i40e_set_ethtool_ops(netdev);
13450 /* MTU range: 68 - 9706 */
13451 netdev->min_mtu = ETH_MIN_MTU;
13452 netdev->max_mtu = I40E_MAX_RXBUFFER - I40E_PACKET_HDR_PAD;
13458 * i40e_vsi_delete - Delete a VSI from the switch
13459 * @vsi: the VSI being removed
13461 * Returns 0 on success, negative value on failure
13463 static void i40e_vsi_delete(struct i40e_vsi *vsi)
13465 /* remove default VSI is not allowed */
13466 if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
13469 i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
13473 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
13474 * @vsi: the VSI being queried
13476 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
13478 int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
13480 struct i40e_veb *veb;
13481 struct i40e_pf *pf = vsi->back;
13483 /* Uplink is not a bridge so default to VEB */
13484 if (vsi->veb_idx >= I40E_MAX_VEB)
13487 veb = pf->veb[vsi->veb_idx];
13489 dev_info(&pf->pdev->dev,
13490 "There is no veb associated with the bridge\n");
13494 /* Uplink is a bridge in VEPA mode */
13495 if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
13498 /* Uplink is a bridge in VEB mode */
13502 /* VEPA is now default bridge, so return 0 */
13507 * i40e_add_vsi - Add a VSI to the switch
13508 * @vsi: the VSI being configured
13510 * This initializes a VSI context depending on the VSI type to be added and
13511 * passes it down to the add_vsi aq command.
13513 static int i40e_add_vsi(struct i40e_vsi *vsi)
13516 struct i40e_pf *pf = vsi->back;
13517 struct i40e_hw *hw = &pf->hw;
13518 struct i40e_vsi_context ctxt;
13519 struct i40e_mac_filter *f;
13520 struct hlist_node *h;
13523 u8 enabled_tc = 0x1; /* TC0 enabled */
13526 memset(&ctxt, 0, sizeof(ctxt));
13527 switch (vsi->type) {
13528 case I40E_VSI_MAIN:
13529 /* The PF's main VSI is already setup as part of the
13530 * device initialization, so we'll not bother with
13531 * the add_vsi call, but we will retrieve the current
13534 ctxt.seid = pf->main_vsi_seid;
13535 ctxt.pf_num = pf->hw.pf_id;
13537 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
13538 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
13540 dev_info(&pf->pdev->dev,
13541 "couldn't get PF vsi config, err %s aq_err %s\n",
13542 i40e_stat_str(&pf->hw, ret),
13543 i40e_aq_str(&pf->hw,
13544 pf->hw.aq.asq_last_status));
13547 vsi->info = ctxt.info;
13548 vsi->info.valid_sections = 0;
13550 vsi->seid = ctxt.seid;
13551 vsi->id = ctxt.vsi_number;
13553 enabled_tc = i40e_pf_get_tc_map(pf);
13555 /* Source pruning is enabled by default, so the flag is
13556 * negative logic - if it's set, we need to fiddle with
13557 * the VSI to disable source pruning.
13559 if (pf->flags & I40E_FLAG_SOURCE_PRUNING_DISABLED) {
13560 memset(&ctxt, 0, sizeof(ctxt));
13561 ctxt.seid = pf->main_vsi_seid;
13562 ctxt.pf_num = pf->hw.pf_id;
13564 ctxt.info.valid_sections |=
13565 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
13566 ctxt.info.switch_id =
13567 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
13568 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
13570 dev_info(&pf->pdev->dev,
13571 "update vsi failed, err %s aq_err %s\n",
13572 i40e_stat_str(&pf->hw, ret),
13573 i40e_aq_str(&pf->hw,
13574 pf->hw.aq.asq_last_status));
13580 /* MFP mode setup queue map and update VSI */
13581 if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
13582 !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
13583 memset(&ctxt, 0, sizeof(ctxt));
13584 ctxt.seid = pf->main_vsi_seid;
13585 ctxt.pf_num = pf->hw.pf_id;
13587 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
13588 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
13590 dev_info(&pf->pdev->dev,
13591 "update vsi failed, err %s aq_err %s\n",
13592 i40e_stat_str(&pf->hw, ret),
13593 i40e_aq_str(&pf->hw,
13594 pf->hw.aq.asq_last_status));
13598 /* update the local VSI info queue map */
13599 i40e_vsi_update_queue_map(vsi, &ctxt);
13600 vsi->info.valid_sections = 0;
13602 /* Default/Main VSI is only enabled for TC0
13603 * reconfigure it to enable all TCs that are
13604 * available on the port in SFP mode.
13605 * For MFP case the iSCSI PF would use this
13606 * flow to enable LAN+iSCSI TC.
13608 ret = i40e_vsi_config_tc(vsi, enabled_tc);
13610 /* Single TC condition is not fatal,
13611 * message and continue
13613 dev_info(&pf->pdev->dev,
13614 "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
13616 i40e_stat_str(&pf->hw, ret),
13617 i40e_aq_str(&pf->hw,
13618 pf->hw.aq.asq_last_status));
13623 case I40E_VSI_FDIR:
13624 ctxt.pf_num = hw->pf_id;
13626 ctxt.uplink_seid = vsi->uplink_seid;
13627 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
13628 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
13629 if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
13630 (i40e_is_vsi_uplink_mode_veb(vsi))) {
13631 ctxt.info.valid_sections |=
13632 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
13633 ctxt.info.switch_id =
13634 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
13636 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
13639 case I40E_VSI_VMDQ2:
13640 ctxt.pf_num = hw->pf_id;
13642 ctxt.uplink_seid = vsi->uplink_seid;
13643 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
13644 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
13646 /* This VSI is connected to VEB so the switch_id
13647 * should be set to zero by default.
13649 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
13650 ctxt.info.valid_sections |=
13651 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
13652 ctxt.info.switch_id =
13653 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
13656 /* Setup the VSI tx/rx queue map for TC0 only for now */
13657 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
13660 case I40E_VSI_SRIOV:
13661 ctxt.pf_num = hw->pf_id;
13662 ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
13663 ctxt.uplink_seid = vsi->uplink_seid;
13664 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
13665 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
13667 /* This VSI is connected to VEB so the switch_id
13668 * should be set to zero by default.
13670 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
13671 ctxt.info.valid_sections |=
13672 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
13673 ctxt.info.switch_id =
13674 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
13677 if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
13678 ctxt.info.valid_sections |=
13679 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
13680 ctxt.info.queueing_opt_flags |=
13681 (I40E_AQ_VSI_QUE_OPT_TCP_ENA |
13682 I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI);
13685 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
13686 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
13687 if (pf->vf[vsi->vf_id].spoofchk) {
13688 ctxt.info.valid_sections |=
13689 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
13690 ctxt.info.sec_flags |=
13691 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
13692 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
13694 /* Setup the VSI tx/rx queue map for TC0 only for now */
13695 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
13698 case I40E_VSI_IWARP:
13699 /* send down message to iWARP */
13706 if (vsi->type != I40E_VSI_MAIN) {
13707 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
13709 dev_info(&vsi->back->pdev->dev,
13710 "add vsi failed, err %s aq_err %s\n",
13711 i40e_stat_str(&pf->hw, ret),
13712 i40e_aq_str(&pf->hw,
13713 pf->hw.aq.asq_last_status));
13717 vsi->info = ctxt.info;
13718 vsi->info.valid_sections = 0;
13719 vsi->seid = ctxt.seid;
13720 vsi->id = ctxt.vsi_number;
13723 vsi->active_filters = 0;
13724 clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
13725 spin_lock_bh(&vsi->mac_filter_hash_lock);
13726 /* If macvlan filters already exist, force them to get loaded */
13727 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
13728 f->state = I40E_FILTER_NEW;
13731 spin_unlock_bh(&vsi->mac_filter_hash_lock);
13734 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
13735 set_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state);
13738 /* Update VSI BW information */
13739 ret = i40e_vsi_get_bw_info(vsi);
13741 dev_info(&pf->pdev->dev,
13742 "couldn't get vsi bw info, err %s aq_err %s\n",
13743 i40e_stat_str(&pf->hw, ret),
13744 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
13745 /* VSI is already added so not tearing that up */
13754 * i40e_vsi_release - Delete a VSI and free its resources
13755 * @vsi: the VSI being removed
13757 * Returns 0 on success or < 0 on error
13759 int i40e_vsi_release(struct i40e_vsi *vsi)
13761 struct i40e_mac_filter *f;
13762 struct hlist_node *h;
13763 struct i40e_veb *veb = NULL;
13764 struct i40e_pf *pf;
13770 /* release of a VEB-owner or last VSI is not allowed */
13771 if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
13772 dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
13773 vsi->seid, vsi->uplink_seid);
13776 if (vsi == pf->vsi[pf->lan_vsi] &&
13777 !test_bit(__I40E_DOWN, pf->state)) {
13778 dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
13782 uplink_seid = vsi->uplink_seid;
13783 if (vsi->type != I40E_VSI_SRIOV) {
13784 if (vsi->netdev_registered) {
13785 vsi->netdev_registered = false;
13787 /* results in a call to i40e_close() */
13788 unregister_netdev(vsi->netdev);
13791 i40e_vsi_close(vsi);
13793 i40e_vsi_disable_irq(vsi);
13796 spin_lock_bh(&vsi->mac_filter_hash_lock);
13798 /* clear the sync flag on all filters */
13800 __dev_uc_unsync(vsi->netdev, NULL);
13801 __dev_mc_unsync(vsi->netdev, NULL);
13804 /* make sure any remaining filters are marked for deletion */
13805 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
13806 __i40e_del_filter(vsi, f);
13808 spin_unlock_bh(&vsi->mac_filter_hash_lock);
13810 i40e_sync_vsi_filters(vsi);
13812 i40e_vsi_delete(vsi);
13813 i40e_vsi_free_q_vectors(vsi);
13815 free_netdev(vsi->netdev);
13816 vsi->netdev = NULL;
13818 i40e_vsi_clear_rings(vsi);
13819 i40e_vsi_clear(vsi);
13821 /* If this was the last thing on the VEB, except for the
13822 * controlling VSI, remove the VEB, which puts the controlling
13823 * VSI onto the next level down in the switch.
13825 * Well, okay, there's one more exception here: don't remove
13826 * the orphan VEBs yet. We'll wait for an explicit remove request
13827 * from up the network stack.
13829 for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
13831 pf->vsi[i]->uplink_seid == uplink_seid &&
13832 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
13833 n++; /* count the VSIs */
13836 for (i = 0; i < I40E_MAX_VEB; i++) {
13839 if (pf->veb[i]->uplink_seid == uplink_seid)
13840 n++; /* count the VEBs */
13841 if (pf->veb[i]->seid == uplink_seid)
13844 if (n == 0 && veb && veb->uplink_seid != 0)
13845 i40e_veb_release(veb);
13851 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
13852 * @vsi: ptr to the VSI
13854 * This should only be called after i40e_vsi_mem_alloc() which allocates the
13855 * corresponding SW VSI structure and initializes num_queue_pairs for the
13856 * newly allocated VSI.
13858 * Returns 0 on success or negative on failure
13860 static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
13863 struct i40e_pf *pf = vsi->back;
13865 if (vsi->q_vectors[0]) {
13866 dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
13871 if (vsi->base_vector) {
13872 dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
13873 vsi->seid, vsi->base_vector);
13877 ret = i40e_vsi_alloc_q_vectors(vsi);
13879 dev_info(&pf->pdev->dev,
13880 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
13881 vsi->num_q_vectors, vsi->seid, ret);
13882 vsi->num_q_vectors = 0;
13883 goto vector_setup_out;
13886 /* In Legacy mode, we do not have to get any other vector since we
13887 * piggyback on the misc/ICR0 for queue interrupts.
13889 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
13891 if (vsi->num_q_vectors)
13892 vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
13893 vsi->num_q_vectors, vsi->idx);
13894 if (vsi->base_vector < 0) {
13895 dev_info(&pf->pdev->dev,
13896 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
13897 vsi->num_q_vectors, vsi->seid, vsi->base_vector);
13898 i40e_vsi_free_q_vectors(vsi);
13900 goto vector_setup_out;
13908 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
13909 * @vsi: pointer to the vsi.
13911 * This re-allocates a vsi's queue resources.
13913 * Returns pointer to the successfully allocated and configured VSI sw struct
13914 * on success, otherwise returns NULL on failure.
13916 static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
13918 u16 alloc_queue_pairs;
13919 struct i40e_pf *pf;
13928 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
13929 i40e_vsi_clear_rings(vsi);
13931 i40e_vsi_free_arrays(vsi, false);
13932 i40e_set_num_rings_in_vsi(vsi);
13933 ret = i40e_vsi_alloc_arrays(vsi, false);
13937 alloc_queue_pairs = vsi->alloc_queue_pairs *
13938 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
13940 ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
13942 dev_info(&pf->pdev->dev,
13943 "failed to get tracking for %d queues for VSI %d err %d\n",
13944 alloc_queue_pairs, vsi->seid, ret);
13947 vsi->base_queue = ret;
13949 /* Update the FW view of the VSI. Force a reset of TC and queue
13950 * layout configurations.
13952 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
13953 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
13954 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
13955 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
13956 if (vsi->type == I40E_VSI_MAIN)
13957 i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr);
13959 /* assign it some queues */
13960 ret = i40e_alloc_rings(vsi);
13964 /* map all of the rings to the q_vectors */
13965 i40e_vsi_map_rings_to_vectors(vsi);
13969 i40e_vsi_free_q_vectors(vsi);
13970 if (vsi->netdev_registered) {
13971 vsi->netdev_registered = false;
13972 unregister_netdev(vsi->netdev);
13973 free_netdev(vsi->netdev);
13974 vsi->netdev = NULL;
13976 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
13978 i40e_vsi_clear(vsi);
13983 * i40e_vsi_setup - Set up a VSI by a given type
13984 * @pf: board private structure
13986 * @uplink_seid: the switch element to link to
13987 * @param1: usage depends upon VSI type. For VF types, indicates VF id
13989 * This allocates the sw VSI structure and its queue resources, then add a VSI
13990 * to the identified VEB.
13992 * Returns pointer to the successfully allocated and configure VSI sw struct on
13993 * success, otherwise returns NULL on failure.
13995 struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
13996 u16 uplink_seid, u32 param1)
13998 struct i40e_vsi *vsi = NULL;
13999 struct i40e_veb *veb = NULL;
14000 u16 alloc_queue_pairs;
14004 /* The requested uplink_seid must be either
14005 * - the PF's port seid
14006 * no VEB is needed because this is the PF
14007 * or this is a Flow Director special case VSI
14008 * - seid of an existing VEB
14009 * - seid of a VSI that owns an existing VEB
14010 * - seid of a VSI that doesn't own a VEB
14011 * a new VEB is created and the VSI becomes the owner
14012 * - seid of the PF VSI, which is what creates the first VEB
14013 * this is a special case of the previous
14015 * Find which uplink_seid we were given and create a new VEB if needed
14017 for (i = 0; i < I40E_MAX_VEB; i++) {
14018 if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
14024 if (!veb && uplink_seid != pf->mac_seid) {
14026 for (i = 0; i < pf->num_alloc_vsi; i++) {
14027 if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
14033 dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
14038 if (vsi->uplink_seid == pf->mac_seid)
14039 veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
14040 vsi->tc_config.enabled_tc);
14041 else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
14042 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
14043 vsi->tc_config.enabled_tc);
14045 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
14046 dev_info(&vsi->back->pdev->dev,
14047 "New VSI creation error, uplink seid of LAN VSI expected.\n");
14050 /* We come up by default in VEPA mode if SRIOV is not
14051 * already enabled, in which case we can't force VEPA
14054 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
14055 veb->bridge_mode = BRIDGE_MODE_VEPA;
14056 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
14058 i40e_config_bridge_mode(veb);
14060 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
14061 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
14065 dev_info(&pf->pdev->dev, "couldn't add VEB\n");
14069 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
14070 uplink_seid = veb->seid;
14073 /* get vsi sw struct */
14074 v_idx = i40e_vsi_mem_alloc(pf, type);
14077 vsi = pf->vsi[v_idx];
14081 vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
14083 if (type == I40E_VSI_MAIN)
14084 pf->lan_vsi = v_idx;
14085 else if (type == I40E_VSI_SRIOV)
14086 vsi->vf_id = param1;
14087 /* assign it some queues */
14088 alloc_queue_pairs = vsi->alloc_queue_pairs *
14089 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
14091 ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
14093 dev_info(&pf->pdev->dev,
14094 "failed to get tracking for %d queues for VSI %d err=%d\n",
14095 alloc_queue_pairs, vsi->seid, ret);
14098 vsi->base_queue = ret;
14100 /* get a VSI from the hardware */
14101 vsi->uplink_seid = uplink_seid;
14102 ret = i40e_add_vsi(vsi);
14106 switch (vsi->type) {
14107 /* setup the netdev if needed */
14108 case I40E_VSI_MAIN:
14109 case I40E_VSI_VMDQ2:
14110 ret = i40e_config_netdev(vsi);
14113 ret = register_netdev(vsi->netdev);
14116 vsi->netdev_registered = true;
14117 netif_carrier_off(vsi->netdev);
14118 #ifdef CONFIG_I40E_DCB
14119 /* Setup DCB netlink interface */
14120 i40e_dcbnl_setup(vsi);
14121 #endif /* CONFIG_I40E_DCB */
14123 case I40E_VSI_FDIR:
14124 /* set up vectors and rings if needed */
14125 ret = i40e_vsi_setup_vectors(vsi);
14129 ret = i40e_alloc_rings(vsi);
14133 /* map all of the rings to the q_vectors */
14134 i40e_vsi_map_rings_to_vectors(vsi);
14136 i40e_vsi_reset_stats(vsi);
14139 /* no netdev or rings for the other VSI types */
14143 if ((pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) &&
14144 (vsi->type == I40E_VSI_VMDQ2)) {
14145 ret = i40e_vsi_config_rss(vsi);
14150 i40e_vsi_free_q_vectors(vsi);
14152 if (vsi->netdev_registered) {
14153 vsi->netdev_registered = false;
14154 unregister_netdev(vsi->netdev);
14155 free_netdev(vsi->netdev);
14156 vsi->netdev = NULL;
14159 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
14161 i40e_vsi_clear(vsi);
14167 * i40e_veb_get_bw_info - Query VEB BW information
14168 * @veb: the veb to query
14170 * Query the Tx scheduler BW configuration data for given VEB
14172 static int i40e_veb_get_bw_info(struct i40e_veb *veb)
14174 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
14175 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
14176 struct i40e_pf *pf = veb->pf;
14177 struct i40e_hw *hw = &pf->hw;
14182 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
14185 dev_info(&pf->pdev->dev,
14186 "query veb bw config failed, err %s aq_err %s\n",
14187 i40e_stat_str(&pf->hw, ret),
14188 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
14192 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
14195 dev_info(&pf->pdev->dev,
14196 "query veb bw ets config failed, err %s aq_err %s\n",
14197 i40e_stat_str(&pf->hw, ret),
14198 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
14202 veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
14203 veb->bw_max_quanta = ets_data.tc_bw_max;
14204 veb->is_abs_credits = bw_data.absolute_credits_enable;
14205 veb->enabled_tc = ets_data.tc_valid_bits;
14206 tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
14207 (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
14208 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
14209 veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
14210 veb->bw_tc_limit_credits[i] =
14211 le16_to_cpu(bw_data.tc_bw_limits[i]);
14212 veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
14220 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
14221 * @pf: board private structure
14223 * On error: returns error code (negative)
14224 * On success: returns vsi index in PF (positive)
14226 static int i40e_veb_mem_alloc(struct i40e_pf *pf)
14229 struct i40e_veb *veb;
14232 /* Need to protect the allocation of switch elements at the PF level */
14233 mutex_lock(&pf->switch_mutex);
14235 /* VEB list may be fragmented if VEB creation/destruction has
14236 * been happening. We can afford to do a quick scan to look
14237 * for any free slots in the list.
14239 * find next empty veb slot, looping back around if necessary
14242 while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
14244 if (i >= I40E_MAX_VEB) {
14246 goto err_alloc_veb; /* out of VEB slots! */
14249 veb = kzalloc(sizeof(*veb), GFP_KERNEL);
14252 goto err_alloc_veb;
14256 veb->enabled_tc = 1;
14261 mutex_unlock(&pf->switch_mutex);
14266 * i40e_switch_branch_release - Delete a branch of the switch tree
14267 * @branch: where to start deleting
14269 * This uses recursion to find the tips of the branch to be
14270 * removed, deleting until we get back to and can delete this VEB.
14272 static void i40e_switch_branch_release(struct i40e_veb *branch)
14274 struct i40e_pf *pf = branch->pf;
14275 u16 branch_seid = branch->seid;
14276 u16 veb_idx = branch->idx;
14279 /* release any VEBs on this VEB - RECURSION */
14280 for (i = 0; i < I40E_MAX_VEB; i++) {
14283 if (pf->veb[i]->uplink_seid == branch->seid)
14284 i40e_switch_branch_release(pf->veb[i]);
14287 /* Release the VSIs on this VEB, but not the owner VSI.
14289 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
14290 * the VEB itself, so don't use (*branch) after this loop.
14292 for (i = 0; i < pf->num_alloc_vsi; i++) {
14295 if (pf->vsi[i]->uplink_seid == branch_seid &&
14296 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
14297 i40e_vsi_release(pf->vsi[i]);
14301 /* There's one corner case where the VEB might not have been
14302 * removed, so double check it here and remove it if needed.
14303 * This case happens if the veb was created from the debugfs
14304 * commands and no VSIs were added to it.
14306 if (pf->veb[veb_idx])
14307 i40e_veb_release(pf->veb[veb_idx]);
14311 * i40e_veb_clear - remove veb struct
14312 * @veb: the veb to remove
14314 static void i40e_veb_clear(struct i40e_veb *veb)
14320 struct i40e_pf *pf = veb->pf;
14322 mutex_lock(&pf->switch_mutex);
14323 if (pf->veb[veb->idx] == veb)
14324 pf->veb[veb->idx] = NULL;
14325 mutex_unlock(&pf->switch_mutex);
14332 * i40e_veb_release - Delete a VEB and free its resources
14333 * @veb: the VEB being removed
14335 void i40e_veb_release(struct i40e_veb *veb)
14337 struct i40e_vsi *vsi = NULL;
14338 struct i40e_pf *pf;
14343 /* find the remaining VSI and check for extras */
14344 for (i = 0; i < pf->num_alloc_vsi; i++) {
14345 if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
14351 dev_info(&pf->pdev->dev,
14352 "can't remove VEB %d with %d VSIs left\n",
14357 /* move the remaining VSI to uplink veb */
14358 vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
14359 if (veb->uplink_seid) {
14360 vsi->uplink_seid = veb->uplink_seid;
14361 if (veb->uplink_seid == pf->mac_seid)
14362 vsi->veb_idx = I40E_NO_VEB;
14364 vsi->veb_idx = veb->veb_idx;
14367 vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
14368 vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
14371 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
14372 i40e_veb_clear(veb);
14376 * i40e_add_veb - create the VEB in the switch
14377 * @veb: the VEB to be instantiated
14378 * @vsi: the controlling VSI
14380 static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
14382 struct i40e_pf *pf = veb->pf;
14383 bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
14386 ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
14387 veb->enabled_tc, false,
14388 &veb->seid, enable_stats, NULL);
14390 /* get a VEB from the hardware */
14392 dev_info(&pf->pdev->dev,
14393 "couldn't add VEB, err %s aq_err %s\n",
14394 i40e_stat_str(&pf->hw, ret),
14395 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
14399 /* get statistics counter */
14400 ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
14401 &veb->stats_idx, NULL, NULL, NULL);
14403 dev_info(&pf->pdev->dev,
14404 "couldn't get VEB statistics idx, err %s aq_err %s\n",
14405 i40e_stat_str(&pf->hw, ret),
14406 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
14409 ret = i40e_veb_get_bw_info(veb);
14411 dev_info(&pf->pdev->dev,
14412 "couldn't get VEB bw info, err %s aq_err %s\n",
14413 i40e_stat_str(&pf->hw, ret),
14414 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
14415 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
14419 vsi->uplink_seid = veb->seid;
14420 vsi->veb_idx = veb->idx;
14421 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
14427 * i40e_veb_setup - Set up a VEB
14428 * @pf: board private structure
14429 * @flags: VEB setup flags
14430 * @uplink_seid: the switch element to link to
14431 * @vsi_seid: the initial VSI seid
14432 * @enabled_tc: Enabled TC bit-map
14434 * This allocates the sw VEB structure and links it into the switch
14435 * It is possible and legal for this to be a duplicate of an already
14436 * existing VEB. It is also possible for both uplink and vsi seids
14437 * to be zero, in order to create a floating VEB.
14439 * Returns pointer to the successfully allocated VEB sw struct on
14440 * success, otherwise returns NULL on failure.
14442 struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
14443 u16 uplink_seid, u16 vsi_seid,
14446 struct i40e_veb *veb, *uplink_veb = NULL;
14447 int vsi_idx, veb_idx;
14450 /* if one seid is 0, the other must be 0 to create a floating relay */
14451 if ((uplink_seid == 0 || vsi_seid == 0) &&
14452 (uplink_seid + vsi_seid != 0)) {
14453 dev_info(&pf->pdev->dev,
14454 "one, not both seid's are 0: uplink=%d vsi=%d\n",
14455 uplink_seid, vsi_seid);
14459 /* make sure there is such a vsi and uplink */
14460 for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
14461 if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
14463 if (vsi_idx == pf->num_alloc_vsi && vsi_seid != 0) {
14464 dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
14469 if (uplink_seid && uplink_seid != pf->mac_seid) {
14470 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
14471 if (pf->veb[veb_idx] &&
14472 pf->veb[veb_idx]->seid == uplink_seid) {
14473 uplink_veb = pf->veb[veb_idx];
14478 dev_info(&pf->pdev->dev,
14479 "uplink seid %d not found\n", uplink_seid);
14484 /* get veb sw struct */
14485 veb_idx = i40e_veb_mem_alloc(pf);
14488 veb = pf->veb[veb_idx];
14489 veb->flags = flags;
14490 veb->uplink_seid = uplink_seid;
14491 veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
14492 veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
14494 /* create the VEB in the switch */
14495 ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
14498 if (vsi_idx == pf->lan_vsi)
14499 pf->lan_veb = veb->idx;
14504 i40e_veb_clear(veb);
14510 * i40e_setup_pf_switch_element - set PF vars based on switch type
14511 * @pf: board private structure
14512 * @ele: element we are building info from
14513 * @num_reported: total number of elements
14514 * @printconfig: should we print the contents
14516 * helper function to assist in extracting a few useful SEID values.
14518 static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
14519 struct i40e_aqc_switch_config_element_resp *ele,
14520 u16 num_reported, bool printconfig)
14522 u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
14523 u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
14524 u8 element_type = ele->element_type;
14525 u16 seid = le16_to_cpu(ele->seid);
14528 dev_info(&pf->pdev->dev,
14529 "type=%d seid=%d uplink=%d downlink=%d\n",
14530 element_type, seid, uplink_seid, downlink_seid);
14532 switch (element_type) {
14533 case I40E_SWITCH_ELEMENT_TYPE_MAC:
14534 pf->mac_seid = seid;
14536 case I40E_SWITCH_ELEMENT_TYPE_VEB:
14538 if (uplink_seid != pf->mac_seid)
14540 if (pf->lan_veb >= I40E_MAX_VEB) {
14543 /* find existing or else empty VEB */
14544 for (v = 0; v < I40E_MAX_VEB; v++) {
14545 if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
14550 if (pf->lan_veb >= I40E_MAX_VEB) {
14551 v = i40e_veb_mem_alloc(pf);
14557 if (pf->lan_veb >= I40E_MAX_VEB)
14560 pf->veb[pf->lan_veb]->seid = seid;
14561 pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
14562 pf->veb[pf->lan_veb]->pf = pf;
14563 pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
14565 case I40E_SWITCH_ELEMENT_TYPE_VSI:
14566 if (num_reported != 1)
14568 /* This is immediately after a reset so we can assume this is
14571 pf->mac_seid = uplink_seid;
14572 pf->pf_seid = downlink_seid;
14573 pf->main_vsi_seid = seid;
14575 dev_info(&pf->pdev->dev,
14576 "pf_seid=%d main_vsi_seid=%d\n",
14577 pf->pf_seid, pf->main_vsi_seid);
14579 case I40E_SWITCH_ELEMENT_TYPE_PF:
14580 case I40E_SWITCH_ELEMENT_TYPE_VF:
14581 case I40E_SWITCH_ELEMENT_TYPE_EMP:
14582 case I40E_SWITCH_ELEMENT_TYPE_BMC:
14583 case I40E_SWITCH_ELEMENT_TYPE_PE:
14584 case I40E_SWITCH_ELEMENT_TYPE_PA:
14585 /* ignore these for now */
14588 dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
14589 element_type, seid);
14595 * i40e_fetch_switch_configuration - Get switch config from firmware
14596 * @pf: board private structure
14597 * @printconfig: should we print the contents
14599 * Get the current switch configuration from the device and
14600 * extract a few useful SEID values.
14602 int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
14604 struct i40e_aqc_get_switch_config_resp *sw_config;
14610 aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
14614 sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
14616 u16 num_reported, num_total;
14618 ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
14622 dev_info(&pf->pdev->dev,
14623 "get switch config failed err %s aq_err %s\n",
14624 i40e_stat_str(&pf->hw, ret),
14625 i40e_aq_str(&pf->hw,
14626 pf->hw.aq.asq_last_status));
14631 num_reported = le16_to_cpu(sw_config->header.num_reported);
14632 num_total = le16_to_cpu(sw_config->header.num_total);
14635 dev_info(&pf->pdev->dev,
14636 "header: %d reported %d total\n",
14637 num_reported, num_total);
14639 for (i = 0; i < num_reported; i++) {
14640 struct i40e_aqc_switch_config_element_resp *ele =
14641 &sw_config->element[i];
14643 i40e_setup_pf_switch_element(pf, ele, num_reported,
14646 } while (next_seid != 0);
14653 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
14654 * @pf: board private structure
14655 * @reinit: if the Main VSI needs to re-initialized.
14657 * Returns 0 on success, negative value on failure
14659 static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
14664 /* find out what's out there already */
14665 ret = i40e_fetch_switch_configuration(pf, false);
14667 dev_info(&pf->pdev->dev,
14668 "couldn't fetch switch config, err %s aq_err %s\n",
14669 i40e_stat_str(&pf->hw, ret),
14670 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
14673 i40e_pf_reset_stats(pf);
14675 /* set the switch config bit for the whole device to
14676 * support limited promisc or true promisc
14677 * when user requests promisc. The default is limited
14681 if ((pf->hw.pf_id == 0) &&
14682 !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
14683 flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
14684 pf->last_sw_conf_flags = flags;
14687 if (pf->hw.pf_id == 0) {
14690 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
14691 ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, 0,
14693 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
14694 dev_info(&pf->pdev->dev,
14695 "couldn't set switch config bits, err %s aq_err %s\n",
14696 i40e_stat_str(&pf->hw, ret),
14697 i40e_aq_str(&pf->hw,
14698 pf->hw.aq.asq_last_status));
14699 /* not a fatal problem, just keep going */
14701 pf->last_sw_conf_valid_flags = valid_flags;
14704 /* first time setup */
14705 if (pf->lan_vsi == I40E_NO_VSI || reinit) {
14706 struct i40e_vsi *vsi = NULL;
14709 /* Set up the PF VSI associated with the PF's main VSI
14710 * that is already in the HW switch
14712 if (pf->lan_veb < I40E_MAX_VEB && pf->veb[pf->lan_veb])
14713 uplink_seid = pf->veb[pf->lan_veb]->seid;
14715 uplink_seid = pf->mac_seid;
14716 if (pf->lan_vsi == I40E_NO_VSI)
14717 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
14719 vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
14721 dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
14722 i40e_cloud_filter_exit(pf);
14723 i40e_fdir_teardown(pf);
14727 /* force a reset of TC and queue layout configurations */
14728 u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
14730 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
14731 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
14732 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
14734 i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
14736 i40e_fdir_sb_setup(pf);
14738 /* Setup static PF queue filter control settings */
14739 ret = i40e_setup_pf_filter_control(pf);
14741 dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
14743 /* Failure here should not stop continuing other steps */
14746 /* enable RSS in the HW, even for only one queue, as the stack can use
14749 if ((pf->flags & I40E_FLAG_RSS_ENABLED))
14750 i40e_pf_config_rss(pf);
14752 /* fill in link information and enable LSE reporting */
14753 i40e_link_event(pf);
14755 /* Initialize user-specific link properties */
14756 pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
14757 I40E_AQ_AN_COMPLETED) ? true : false);
14761 /* repopulate tunnel port filters */
14762 udp_tunnel_nic_reset_ntf(pf->vsi[pf->lan_vsi]->netdev);
14768 * i40e_determine_queue_usage - Work out queue distribution
14769 * @pf: board private structure
14771 static void i40e_determine_queue_usage(struct i40e_pf *pf)
14776 pf->num_lan_qps = 0;
14778 /* Find the max queues to be put into basic use. We'll always be
14779 * using TC0, whether or not DCB is running, and TC0 will get the
14782 queues_left = pf->hw.func_caps.num_tx_qp;
14784 if ((queues_left == 1) ||
14785 !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
14786 /* one qp for PF, no queues for anything else */
14788 pf->alloc_rss_size = pf->num_lan_qps = 1;
14790 /* make sure all the fancies are disabled */
14791 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
14792 I40E_FLAG_IWARP_ENABLED |
14793 I40E_FLAG_FD_SB_ENABLED |
14794 I40E_FLAG_FD_ATR_ENABLED |
14795 I40E_FLAG_DCB_CAPABLE |
14796 I40E_FLAG_DCB_ENABLED |
14797 I40E_FLAG_SRIOV_ENABLED |
14798 I40E_FLAG_VMDQ_ENABLED);
14799 pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
14800 } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
14801 I40E_FLAG_FD_SB_ENABLED |
14802 I40E_FLAG_FD_ATR_ENABLED |
14803 I40E_FLAG_DCB_CAPABLE))) {
14804 /* one qp for PF */
14805 pf->alloc_rss_size = pf->num_lan_qps = 1;
14806 queues_left -= pf->num_lan_qps;
14808 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
14809 I40E_FLAG_IWARP_ENABLED |
14810 I40E_FLAG_FD_SB_ENABLED |
14811 I40E_FLAG_FD_ATR_ENABLED |
14812 I40E_FLAG_DCB_ENABLED |
14813 I40E_FLAG_VMDQ_ENABLED);
14814 pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
14816 /* Not enough queues for all TCs */
14817 if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
14818 (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
14819 pf->flags &= ~(I40E_FLAG_DCB_CAPABLE |
14820 I40E_FLAG_DCB_ENABLED);
14821 dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
14824 /* limit lan qps to the smaller of qps, cpus or msix */
14825 q_max = max_t(int, pf->rss_size_max, num_online_cpus());
14826 q_max = min_t(int, q_max, pf->hw.func_caps.num_tx_qp);
14827 q_max = min_t(int, q_max, pf->hw.func_caps.num_msix_vectors);
14828 pf->num_lan_qps = q_max;
14830 queues_left -= pf->num_lan_qps;
14833 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
14834 if (queues_left > 1) {
14835 queues_left -= 1; /* save 1 queue for FD */
14837 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
14838 pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
14839 dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
14843 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
14844 pf->num_vf_qps && pf->num_req_vfs && queues_left) {
14845 pf->num_req_vfs = min_t(int, pf->num_req_vfs,
14846 (queues_left / pf->num_vf_qps));
14847 queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
14850 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
14851 pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
14852 pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
14853 (queues_left / pf->num_vmdq_qps));
14854 queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
14857 pf->queues_left = queues_left;
14858 dev_dbg(&pf->pdev->dev,
14859 "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
14860 pf->hw.func_caps.num_tx_qp,
14861 !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
14862 pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
14863 pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
14868 * i40e_setup_pf_filter_control - Setup PF static filter control
14869 * @pf: PF to be setup
14871 * i40e_setup_pf_filter_control sets up a PF's initial filter control
14872 * settings. If PE/FCoE are enabled then it will also set the per PF
14873 * based filter sizes required for them. It also enables Flow director,
14874 * ethertype and macvlan type filter settings for the pf.
14876 * Returns 0 on success, negative on failure
14878 static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
14880 struct i40e_filter_control_settings *settings = &pf->filter_settings;
14882 settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
14884 /* Flow Director is enabled */
14885 if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
14886 settings->enable_fdir = true;
14888 /* Ethtype and MACVLAN filters enabled for PF */
14889 settings->enable_ethtype = true;
14890 settings->enable_macvlan = true;
14892 if (i40e_set_filter_control(&pf->hw, settings))
14898 #define INFO_STRING_LEN 255
14899 #define REMAIN(__x) (INFO_STRING_LEN - (__x))
14900 static void i40e_print_features(struct i40e_pf *pf)
14902 struct i40e_hw *hw = &pf->hw;
14906 buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
14910 i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
14911 #ifdef CONFIG_PCI_IOV
14912 i += scnprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
14914 i += scnprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d",
14915 pf->hw.func_caps.num_vsis,
14916 pf->vsi[pf->lan_vsi]->num_queue_pairs);
14917 if (pf->flags & I40E_FLAG_RSS_ENABLED)
14918 i += scnprintf(&buf[i], REMAIN(i), " RSS");
14919 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
14920 i += scnprintf(&buf[i], REMAIN(i), " FD_ATR");
14921 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
14922 i += scnprintf(&buf[i], REMAIN(i), " FD_SB");
14923 i += scnprintf(&buf[i], REMAIN(i), " NTUPLE");
14925 if (pf->flags & I40E_FLAG_DCB_CAPABLE)
14926 i += scnprintf(&buf[i], REMAIN(i), " DCB");
14927 i += scnprintf(&buf[i], REMAIN(i), " VxLAN");
14928 i += scnprintf(&buf[i], REMAIN(i), " Geneve");
14929 if (pf->flags & I40E_FLAG_PTP)
14930 i += scnprintf(&buf[i], REMAIN(i), " PTP");
14931 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
14932 i += scnprintf(&buf[i], REMAIN(i), " VEB");
14934 i += scnprintf(&buf[i], REMAIN(i), " VEPA");
14936 dev_info(&pf->pdev->dev, "%s\n", buf);
14938 WARN_ON(i > INFO_STRING_LEN);
14942 * i40e_get_platform_mac_addr - get platform-specific MAC address
14943 * @pdev: PCI device information struct
14944 * @pf: board private structure
14946 * Look up the MAC address for the device. First we'll try
14947 * eth_platform_get_mac_address, which will check Open Firmware, or arch
14948 * specific fallback. Otherwise, we'll default to the stored value in
14951 static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
14953 if (eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
14954 i40e_get_mac_addr(&pf->hw, pf->hw.mac.addr);
14958 * i40e_set_fec_in_flags - helper function for setting FEC options in flags
14959 * @fec_cfg: FEC option to set in flags
14960 * @flags: ptr to flags in which we set FEC option
14962 void i40e_set_fec_in_flags(u8 fec_cfg, u32 *flags)
14964 if (fec_cfg & I40E_AQ_SET_FEC_AUTO)
14965 *flags |= I40E_FLAG_RS_FEC | I40E_FLAG_BASE_R_FEC;
14966 if ((fec_cfg & I40E_AQ_SET_FEC_REQUEST_RS) ||
14967 (fec_cfg & I40E_AQ_SET_FEC_ABILITY_RS)) {
14968 *flags |= I40E_FLAG_RS_FEC;
14969 *flags &= ~I40E_FLAG_BASE_R_FEC;
14971 if ((fec_cfg & I40E_AQ_SET_FEC_REQUEST_KR) ||
14972 (fec_cfg & I40E_AQ_SET_FEC_ABILITY_KR)) {
14973 *flags |= I40E_FLAG_BASE_R_FEC;
14974 *flags &= ~I40E_FLAG_RS_FEC;
14977 *flags &= ~(I40E_FLAG_RS_FEC | I40E_FLAG_BASE_R_FEC);
14981 * i40e_check_recovery_mode - check if we are running transition firmware
14982 * @pf: board private structure
14984 * Check registers indicating the firmware runs in recovery mode. Sets the
14985 * appropriate driver state.
14987 * Returns true if the recovery mode was detected, false otherwise
14989 static bool i40e_check_recovery_mode(struct i40e_pf *pf)
14991 u32 val = rd32(&pf->hw, I40E_GL_FWSTS);
14993 if (val & I40E_GL_FWSTS_FWS1B_MASK) {
14994 dev_crit(&pf->pdev->dev, "Firmware recovery mode detected. Limiting functionality.\n");
14995 dev_crit(&pf->pdev->dev, "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for details on firmware recovery mode.\n");
14996 set_bit(__I40E_RECOVERY_MODE, pf->state);
15000 if (test_bit(__I40E_RECOVERY_MODE, pf->state))
15001 dev_info(&pf->pdev->dev, "Please do Power-On Reset to initialize adapter in normal mode with full functionality.\n");
15007 * i40e_pf_loop_reset - perform reset in a loop.
15008 * @pf: board private structure
15010 * This function is useful when a NIC is about to enter recovery mode.
15011 * When a NIC's internal data structures are corrupted the NIC's
15012 * firmware is going to enter recovery mode.
15013 * Right after a POR it takes about 7 minutes for firmware to enter
15014 * recovery mode. Until that time a NIC is in some kind of intermediate
15015 * state. After that time period the NIC almost surely enters
15016 * recovery mode. The only way for a driver to detect intermediate
15017 * state is to issue a series of pf-resets and check a return value.
15018 * If a PF reset returns success then the firmware could be in recovery
15019 * mode so the caller of this code needs to check for recovery mode
15020 * if this function returns success. There is a little chance that
15021 * firmware will hang in intermediate state forever.
15022 * Since waiting 7 minutes is quite a lot of time this function waits
15023 * 10 seconds and then gives up by returning an error.
15025 * Return 0 on success, negative on failure.
15027 static i40e_status i40e_pf_loop_reset(struct i40e_pf *pf)
15029 /* wait max 10 seconds for PF reset to succeed */
15030 const unsigned long time_end = jiffies + 10 * HZ;
15032 struct i40e_hw *hw = &pf->hw;
15035 ret = i40e_pf_reset(hw);
15036 while (ret != I40E_SUCCESS && time_before(jiffies, time_end)) {
15037 usleep_range(10000, 20000);
15038 ret = i40e_pf_reset(hw);
15041 if (ret == I40E_SUCCESS)
15044 dev_info(&pf->pdev->dev, "PF reset failed: %d\n", ret);
15050 * i40e_check_fw_empr - check if FW issued unexpected EMP Reset
15051 * @pf: board private structure
15053 * Check FW registers to determine if FW issued unexpected EMP Reset.
15054 * Every time when unexpected EMP Reset occurs the FW increments
15055 * a counter of unexpected EMP Resets. When the counter reaches 10
15056 * the FW should enter the Recovery mode
15058 * Returns true if FW issued unexpected EMP Reset
15060 static bool i40e_check_fw_empr(struct i40e_pf *pf)
15062 const u32 fw_sts = rd32(&pf->hw, I40E_GL_FWSTS) &
15063 I40E_GL_FWSTS_FWS1B_MASK;
15064 return (fw_sts > I40E_GL_FWSTS_FWS1B_EMPR_0) &&
15065 (fw_sts <= I40E_GL_FWSTS_FWS1B_EMPR_10);
15069 * i40e_handle_resets - handle EMP resets and PF resets
15070 * @pf: board private structure
15072 * Handle both EMP resets and PF resets and conclude whether there are
15073 * any issues regarding these resets. If there are any issues then
15074 * generate log entry.
15076 * Return 0 if NIC is healthy or negative value when there are issues
15079 static i40e_status i40e_handle_resets(struct i40e_pf *pf)
15081 const i40e_status pfr = i40e_pf_loop_reset(pf);
15082 const bool is_empr = i40e_check_fw_empr(pf);
15084 if (is_empr || pfr != I40E_SUCCESS)
15085 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");
15087 return is_empr ? I40E_ERR_RESET_FAILED : pfr;
15091 * i40e_init_recovery_mode - initialize subsystems needed in recovery mode
15092 * @pf: board private structure
15093 * @hw: ptr to the hardware info
15095 * This function does a minimal setup of all subsystems needed for running
15098 * Returns 0 on success, negative on failure
15100 static int i40e_init_recovery_mode(struct i40e_pf *pf, struct i40e_hw *hw)
15102 struct i40e_vsi *vsi;
15106 pci_save_state(pf->pdev);
15108 /* set up periodic task facility */
15109 timer_setup(&pf->service_timer, i40e_service_timer, 0);
15110 pf->service_timer_period = HZ;
15112 INIT_WORK(&pf->service_task, i40e_service_task);
15113 clear_bit(__I40E_SERVICE_SCHED, pf->state);
15115 err = i40e_init_interrupt_scheme(pf);
15117 goto err_switch_setup;
15119 /* The number of VSIs reported by the FW is the minimum guaranteed
15120 * to us; HW supports far more and we share the remaining pool with
15121 * the other PFs. We allocate space for more than the guarantee with
15122 * the understanding that we might not get them all later.
15124 if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
15125 pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
15127 pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
15129 /* Set up the vsi struct and our local tracking of the MAIN PF vsi. */
15130 pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
15134 goto err_switch_setup;
15137 /* We allocate one VSI which is needed as absolute minimum
15138 * in order to register the netdev
15140 v_idx = i40e_vsi_mem_alloc(pf, I40E_VSI_MAIN);
15142 goto err_switch_setup;
15143 pf->lan_vsi = v_idx;
15144 vsi = pf->vsi[v_idx];
15146 goto err_switch_setup;
15147 vsi->alloc_queue_pairs = 1;
15148 err = i40e_config_netdev(vsi);
15150 goto err_switch_setup;
15151 err = register_netdev(vsi->netdev);
15153 goto err_switch_setup;
15154 vsi->netdev_registered = true;
15155 i40e_dbg_pf_init(pf);
15157 err = i40e_setup_misc_vector_for_recovery_mode(pf);
15159 goto err_switch_setup;
15161 /* tell the firmware that we're starting */
15162 i40e_send_version(pf);
15164 /* since everything's happy, start the service_task timer */
15165 mod_timer(&pf->service_timer,
15166 round_jiffies(jiffies + pf->service_timer_period));
15171 i40e_reset_interrupt_capability(pf);
15172 del_timer_sync(&pf->service_timer);
15173 i40e_shutdown_adminq(hw);
15174 iounmap(hw->hw_addr);
15175 pci_disable_pcie_error_reporting(pf->pdev);
15176 pci_release_mem_regions(pf->pdev);
15177 pci_disable_device(pf->pdev);
15184 * i40e_probe - Device initialization routine
15185 * @pdev: PCI device information struct
15186 * @ent: entry in i40e_pci_tbl
15188 * i40e_probe initializes a PF identified by a pci_dev structure.
15189 * The OS initialization, configuring of the PF private structure,
15190 * and a hardware reset occur.
15192 * Returns 0 on success, negative on failure
15194 static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
15196 struct i40e_aq_get_phy_abilities_resp abilities;
15197 #ifdef CONFIG_I40E_DCB
15198 enum i40e_get_fw_lldp_status_resp lldp_status;
15199 i40e_status status;
15200 #endif /* CONFIG_I40E_DCB */
15201 struct i40e_pf *pf;
15202 struct i40e_hw *hw;
15203 static u16 pfs_found;
15210 err = pci_enable_device_mem(pdev);
15214 /* set up for high or low dma */
15215 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
15217 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
15219 dev_err(&pdev->dev,
15220 "DMA configuration failed: 0x%x\n", err);
15225 /* set up pci connections */
15226 err = pci_request_mem_regions(pdev, i40e_driver_name);
15228 dev_info(&pdev->dev,
15229 "pci_request_selected_regions failed %d\n", err);
15233 pci_enable_pcie_error_reporting(pdev);
15234 pci_set_master(pdev);
15236 /* Now that we have a PCI connection, we need to do the
15237 * low level device setup. This is primarily setting up
15238 * the Admin Queue structures and then querying for the
15239 * device's current profile information.
15241 pf = kzalloc(sizeof(*pf), GFP_KERNEL);
15248 set_bit(__I40E_DOWN, pf->state);
15253 pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
15254 I40E_MAX_CSR_SPACE);
15255 /* We believe that the highest register to read is
15256 * I40E_GLGEN_STAT_CLEAR, so we check if the BAR size
15257 * is not less than that before mapping to prevent a
15260 if (pf->ioremap_len < I40E_GLGEN_STAT_CLEAR) {
15261 dev_err(&pdev->dev, "Cannot map registers, bar size 0x%X too small, aborting\n",
15266 hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
15267 if (!hw->hw_addr) {
15269 dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
15270 (unsigned int)pci_resource_start(pdev, 0),
15271 pf->ioremap_len, err);
15274 hw->vendor_id = pdev->vendor;
15275 hw->device_id = pdev->device;
15276 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
15277 hw->subsystem_vendor_id = pdev->subsystem_vendor;
15278 hw->subsystem_device_id = pdev->subsystem_device;
15279 hw->bus.device = PCI_SLOT(pdev->devfn);
15280 hw->bus.func = PCI_FUNC(pdev->devfn);
15281 hw->bus.bus_id = pdev->bus->number;
15282 pf->instance = pfs_found;
15284 /* Select something other than the 802.1ad ethertype for the
15285 * switch to use internally and drop on ingress.
15287 hw->switch_tag = 0xffff;
15288 hw->first_tag = ETH_P_8021AD;
15289 hw->second_tag = ETH_P_8021Q;
15291 INIT_LIST_HEAD(&pf->l3_flex_pit_list);
15292 INIT_LIST_HEAD(&pf->l4_flex_pit_list);
15293 INIT_LIST_HEAD(&pf->ddp_old_prof);
15295 /* set up the locks for the AQ, do this only once in probe
15296 * and destroy them only once in remove
15298 mutex_init(&hw->aq.asq_mutex);
15299 mutex_init(&hw->aq.arq_mutex);
15301 pf->msg_enable = netif_msg_init(debug,
15306 pf->hw.debug_mask = debug;
15308 /* do a special CORER for clearing PXE mode once at init */
15309 if (hw->revision_id == 0 &&
15310 (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
15311 wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
15316 i40e_clear_pxe_mode(hw);
15319 /* Reset here to make sure all is clean and to define PF 'n' */
15322 err = i40e_set_mac_type(hw);
15324 dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
15329 err = i40e_handle_resets(pf);
15333 i40e_check_recovery_mode(pf);
15335 hw->aq.num_arq_entries = I40E_AQ_LEN;
15336 hw->aq.num_asq_entries = I40E_AQ_LEN;
15337 hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
15338 hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
15339 pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
15341 snprintf(pf->int_name, sizeof(pf->int_name) - 1,
15343 dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
15345 err = i40e_init_shared_code(hw);
15347 dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
15352 /* set up a default setting for link flow control */
15353 pf->hw.fc.requested_mode = I40E_FC_NONE;
15355 err = i40e_init_adminq(hw);
15357 if (err == I40E_ERR_FIRMWARE_API_VERSION)
15358 dev_info(&pdev->dev,
15359 "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",
15360 hw->aq.api_maj_ver,
15361 hw->aq.api_min_ver,
15362 I40E_FW_API_VERSION_MAJOR,
15363 I40E_FW_MINOR_VERSION(hw));
15365 dev_info(&pdev->dev,
15366 "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
15370 i40e_get_oem_version(hw);
15372 /* provide nvm, fw, api versions, vendor:device id, subsys vendor:device id */
15373 dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s [%04x:%04x] [%04x:%04x]\n",
15374 hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
15375 hw->aq.api_maj_ver, hw->aq.api_min_ver,
15376 i40e_nvm_version_str(hw), hw->vendor_id, hw->device_id,
15377 hw->subsystem_vendor_id, hw->subsystem_device_id);
15379 if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
15380 hw->aq.api_min_ver > I40E_FW_MINOR_VERSION(hw))
15381 dev_info(&pdev->dev,
15382 "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",
15383 hw->aq.api_maj_ver,
15384 hw->aq.api_min_ver,
15385 I40E_FW_API_VERSION_MAJOR,
15386 I40E_FW_MINOR_VERSION(hw));
15387 else if (hw->aq.api_maj_ver == 1 && hw->aq.api_min_ver < 4)
15388 dev_info(&pdev->dev,
15389 "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",
15390 hw->aq.api_maj_ver,
15391 hw->aq.api_min_ver,
15392 I40E_FW_API_VERSION_MAJOR,
15393 I40E_FW_MINOR_VERSION(hw));
15395 i40e_verify_eeprom(pf);
15397 /* Rev 0 hardware was never productized */
15398 if (hw->revision_id < 1)
15399 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");
15401 i40e_clear_pxe_mode(hw);
15403 err = i40e_get_capabilities(pf, i40e_aqc_opc_list_func_capabilities);
15405 goto err_adminq_setup;
15407 err = i40e_sw_init(pf);
15409 dev_info(&pdev->dev, "sw_init failed: %d\n", err);
15413 if (test_bit(__I40E_RECOVERY_MODE, pf->state))
15414 return i40e_init_recovery_mode(pf, hw);
15416 err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
15417 hw->func_caps.num_rx_qp, 0, 0);
15419 dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
15420 goto err_init_lan_hmc;
15423 err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
15425 dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
15427 goto err_configure_lan_hmc;
15430 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
15431 * Ignore error return codes because if it was already disabled via
15432 * hardware settings this will fail
15434 if (pf->hw_features & I40E_HW_STOP_FW_LLDP) {
15435 dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
15436 i40e_aq_stop_lldp(hw, true, false, NULL);
15439 /* allow a platform config to override the HW addr */
15440 i40e_get_platform_mac_addr(pdev, pf);
15442 if (!is_valid_ether_addr(hw->mac.addr)) {
15443 dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
15447 dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
15448 ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
15449 i40e_get_port_mac_addr(hw, hw->mac.port_addr);
15450 if (is_valid_ether_addr(hw->mac.port_addr))
15451 pf->hw_features |= I40E_HW_PORT_ID_VALID;
15453 pci_set_drvdata(pdev, pf);
15454 pci_save_state(pdev);
15456 #ifdef CONFIG_I40E_DCB
15457 status = i40e_get_fw_lldp_status(&pf->hw, &lldp_status);
15459 lldp_status == I40E_GET_FW_LLDP_STATUS_ENABLED) ?
15460 (pf->flags &= ~I40E_FLAG_DISABLE_FW_LLDP) :
15461 (pf->flags |= I40E_FLAG_DISABLE_FW_LLDP);
15462 dev_info(&pdev->dev,
15463 (pf->flags & I40E_FLAG_DISABLE_FW_LLDP) ?
15464 "FW LLDP is disabled\n" :
15465 "FW LLDP is enabled\n");
15467 /* Enable FW to write default DCB config on link-up */
15468 i40e_aq_set_dcb_parameters(hw, true, NULL);
15470 err = i40e_init_pf_dcb(pf);
15472 dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
15473 pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED);
15474 /* Continue without DCB enabled */
15476 #endif /* CONFIG_I40E_DCB */
15478 /* set up periodic task facility */
15479 timer_setup(&pf->service_timer, i40e_service_timer, 0);
15480 pf->service_timer_period = HZ;
15482 INIT_WORK(&pf->service_task, i40e_service_task);
15483 clear_bit(__I40E_SERVICE_SCHED, pf->state);
15485 /* NVM bit on means WoL disabled for the port */
15486 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
15487 if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
15488 pf->wol_en = false;
15491 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
15493 /* set up the main switch operations */
15494 i40e_determine_queue_usage(pf);
15495 err = i40e_init_interrupt_scheme(pf);
15497 goto err_switch_setup;
15499 pf->udp_tunnel_nic.set_port = i40e_udp_tunnel_set_port;
15500 pf->udp_tunnel_nic.unset_port = i40e_udp_tunnel_unset_port;
15501 pf->udp_tunnel_nic.flags = UDP_TUNNEL_NIC_INFO_MAY_SLEEP;
15502 pf->udp_tunnel_nic.shared = &pf->udp_tunnel_shared;
15503 pf->udp_tunnel_nic.tables[0].n_entries = I40E_MAX_PF_UDP_OFFLOAD_PORTS;
15504 pf->udp_tunnel_nic.tables[0].tunnel_types = UDP_TUNNEL_TYPE_VXLAN |
15505 UDP_TUNNEL_TYPE_GENEVE;
15507 /* The number of VSIs reported by the FW is the minimum guaranteed
15508 * to us; HW supports far more and we share the remaining pool with
15509 * the other PFs. We allocate space for more than the guarantee with
15510 * the understanding that we might not get them all later.
15512 if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
15513 pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
15515 pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
15516 if (pf->num_alloc_vsi > UDP_TUNNEL_NIC_MAX_SHARING_DEVICES) {
15517 dev_warn(&pf->pdev->dev,
15518 "limiting the VSI count due to UDP tunnel limitation %d > %d\n",
15519 pf->num_alloc_vsi, UDP_TUNNEL_NIC_MAX_SHARING_DEVICES);
15520 pf->num_alloc_vsi = UDP_TUNNEL_NIC_MAX_SHARING_DEVICES;
15523 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
15524 pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
15528 goto err_switch_setup;
15531 #ifdef CONFIG_PCI_IOV
15532 /* prep for VF support */
15533 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
15534 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
15535 !test_bit(__I40E_BAD_EEPROM, pf->state)) {
15536 if (pci_num_vf(pdev))
15537 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
15540 err = i40e_setup_pf_switch(pf, false);
15542 dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
15545 INIT_LIST_HEAD(&pf->vsi[pf->lan_vsi]->ch_list);
15547 /* if FDIR VSI was set up, start it now */
15548 for (i = 0; i < pf->num_alloc_vsi; i++) {
15549 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
15550 i40e_vsi_open(pf->vsi[i]);
15555 /* The driver only wants link up/down and module qualification
15556 * reports from firmware. Note the negative logic.
15558 err = i40e_aq_set_phy_int_mask(&pf->hw,
15559 ~(I40E_AQ_EVENT_LINK_UPDOWN |
15560 I40E_AQ_EVENT_MEDIA_NA |
15561 I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
15563 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
15564 i40e_stat_str(&pf->hw, err),
15565 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
15567 /* Reconfigure hardware for allowing smaller MSS in the case
15568 * of TSO, so that we avoid the MDD being fired and causing
15569 * a reset in the case of small MSS+TSO.
15571 val = rd32(hw, I40E_REG_MSS);
15572 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
15573 val &= ~I40E_REG_MSS_MIN_MASK;
15574 val |= I40E_64BYTE_MSS;
15575 wr32(hw, I40E_REG_MSS, val);
15578 if (pf->hw_features & I40E_HW_RESTART_AUTONEG) {
15580 err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
15582 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
15583 i40e_stat_str(&pf->hw, err),
15584 i40e_aq_str(&pf->hw,
15585 pf->hw.aq.asq_last_status));
15587 /* The main driver is (mostly) up and happy. We need to set this state
15588 * before setting up the misc vector or we get a race and the vector
15589 * ends up disabled forever.
15591 clear_bit(__I40E_DOWN, pf->state);
15593 /* In case of MSIX we are going to setup the misc vector right here
15594 * to handle admin queue events etc. In case of legacy and MSI
15595 * the misc functionality and queue processing is combined in
15596 * the same vector and that gets setup at open.
15598 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
15599 err = i40e_setup_misc_vector(pf);
15601 dev_info(&pdev->dev,
15602 "setup of misc vector failed: %d\n", err);
15603 i40e_cloud_filter_exit(pf);
15604 i40e_fdir_teardown(pf);
15609 #ifdef CONFIG_PCI_IOV
15610 /* prep for VF support */
15611 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
15612 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
15613 !test_bit(__I40E_BAD_EEPROM, pf->state)) {
15614 /* disable link interrupts for VFs */
15615 val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
15616 val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
15617 wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
15620 if (pci_num_vf(pdev)) {
15621 dev_info(&pdev->dev,
15622 "Active VFs found, allocating resources.\n");
15623 err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
15625 dev_info(&pdev->dev,
15626 "Error %d allocating resources for existing VFs\n",
15630 #endif /* CONFIG_PCI_IOV */
15632 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
15633 pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
15634 pf->num_iwarp_msix,
15635 I40E_IWARP_IRQ_PILE_ID);
15636 if (pf->iwarp_base_vector < 0) {
15637 dev_info(&pdev->dev,
15638 "failed to get tracking for %d vectors for IWARP err=%d\n",
15639 pf->num_iwarp_msix, pf->iwarp_base_vector);
15640 pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
15644 i40e_dbg_pf_init(pf);
15646 /* tell the firmware that we're starting */
15647 i40e_send_version(pf);
15649 /* since everything's happy, start the service_task timer */
15650 mod_timer(&pf->service_timer,
15651 round_jiffies(jiffies + pf->service_timer_period));
15653 /* add this PF to client device list and launch a client service task */
15654 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
15655 err = i40e_lan_add_device(pf);
15657 dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
15661 #define PCI_SPEED_SIZE 8
15662 #define PCI_WIDTH_SIZE 8
15663 /* Devices on the IOSF bus do not have this information
15664 * and will report PCI Gen 1 x 1 by default so don't bother
15667 if (!(pf->hw_features & I40E_HW_NO_PCI_LINK_CHECK)) {
15668 char speed[PCI_SPEED_SIZE] = "Unknown";
15669 char width[PCI_WIDTH_SIZE] = "Unknown";
15671 /* Get the negotiated link width and speed from PCI config
15674 pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
15677 i40e_set_pci_config_data(hw, link_status);
15679 switch (hw->bus.speed) {
15680 case i40e_bus_speed_8000:
15681 strlcpy(speed, "8.0", PCI_SPEED_SIZE); break;
15682 case i40e_bus_speed_5000:
15683 strlcpy(speed, "5.0", PCI_SPEED_SIZE); break;
15684 case i40e_bus_speed_2500:
15685 strlcpy(speed, "2.5", PCI_SPEED_SIZE); break;
15689 switch (hw->bus.width) {
15690 case i40e_bus_width_pcie_x8:
15691 strlcpy(width, "8", PCI_WIDTH_SIZE); break;
15692 case i40e_bus_width_pcie_x4:
15693 strlcpy(width, "4", PCI_WIDTH_SIZE); break;
15694 case i40e_bus_width_pcie_x2:
15695 strlcpy(width, "2", PCI_WIDTH_SIZE); break;
15696 case i40e_bus_width_pcie_x1:
15697 strlcpy(width, "1", PCI_WIDTH_SIZE); break;
15702 dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
15705 if (hw->bus.width < i40e_bus_width_pcie_x8 ||
15706 hw->bus.speed < i40e_bus_speed_8000) {
15707 dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
15708 dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
15712 /* get the requested speeds from the fw */
15713 err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
15715 dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
15716 i40e_stat_str(&pf->hw, err),
15717 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
15718 pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
15720 /* set the FEC config due to the board capabilities */
15721 i40e_set_fec_in_flags(abilities.fec_cfg_curr_mod_ext_info, &pf->flags);
15723 /* get the supported phy types from the fw */
15724 err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
15726 dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
15727 i40e_stat_str(&pf->hw, err),
15728 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
15730 /* make sure the MFS hasn't been set lower than the default */
15731 #define MAX_FRAME_SIZE_DEFAULT 0x2600
15732 val = (rd32(&pf->hw, I40E_PRTGL_SAH) &
15733 I40E_PRTGL_SAH_MFS_MASK) >> I40E_PRTGL_SAH_MFS_SHIFT;
15734 if (val < MAX_FRAME_SIZE_DEFAULT)
15735 dev_warn(&pdev->dev, "MFS for port %x has been set below the default: %x\n",
15738 /* Add a filter to drop all Flow control frames from any VSI from being
15739 * transmitted. By doing so we stop a malicious VF from sending out
15740 * PAUSE or PFC frames and potentially controlling traffic for other
15742 * The FW can still send Flow control frames if enabled.
15744 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
15745 pf->main_vsi_seid);
15746 #ifdef CONFIG_I40E_DCB
15747 if (pf->flags & I40E_FLAG_DISABLE_FW_LLDP)
15748 i40e_set_lldp_forwarding(pf, true);
15749 #endif /* CONFIG_I40E_DCB */
15751 if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) ||
15752 (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4))
15753 pf->hw_features |= I40E_HW_PHY_CONTROLS_LEDS;
15754 if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722)
15755 pf->hw_features |= I40E_HW_HAVE_CRT_RETIMER;
15756 /* print a string summarizing features */
15757 i40e_print_features(pf);
15761 /* Unwind what we've done if something failed in the setup */
15763 set_bit(__I40E_DOWN, pf->state);
15764 i40e_clear_interrupt_scheme(pf);
15767 i40e_reset_interrupt_capability(pf);
15768 del_timer_sync(&pf->service_timer);
15770 err_configure_lan_hmc:
15771 (void)i40e_shutdown_lan_hmc(hw);
15773 kfree(pf->qp_pile);
15777 iounmap(hw->hw_addr);
15781 pci_disable_pcie_error_reporting(pdev);
15782 pci_release_mem_regions(pdev);
15785 pci_disable_device(pdev);
15790 * i40e_remove - Device removal routine
15791 * @pdev: PCI device information struct
15793 * i40e_remove is called by the PCI subsystem to alert the driver
15794 * that is should release a PCI device. This could be caused by a
15795 * Hot-Plug event, or because the driver is going to be removed from
15798 static void i40e_remove(struct pci_dev *pdev)
15800 struct i40e_pf *pf = pci_get_drvdata(pdev);
15801 struct i40e_hw *hw = &pf->hw;
15802 i40e_status ret_code;
15805 i40e_dbg_pf_exit(pf);
15809 /* Disable RSS in hw */
15810 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
15811 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
15813 while (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
15814 usleep_range(1000, 2000);
15816 if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
15817 set_bit(__I40E_VF_RESETS_DISABLED, pf->state);
15819 pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
15821 /* no more scheduling of any task */
15822 set_bit(__I40E_SUSPENDED, pf->state);
15823 set_bit(__I40E_DOWN, pf->state);
15824 if (pf->service_timer.function)
15825 del_timer_sync(&pf->service_timer);
15826 if (pf->service_task.func)
15827 cancel_work_sync(&pf->service_task);
15829 if (test_bit(__I40E_RECOVERY_MODE, pf->state)) {
15830 struct i40e_vsi *vsi = pf->vsi[0];
15832 /* We know that we have allocated only one vsi for this PF,
15833 * it was just for registering netdevice, so the interface
15834 * could be visible in the 'ifconfig' output
15836 unregister_netdev(vsi->netdev);
15837 free_netdev(vsi->netdev);
15842 /* Client close must be called explicitly here because the timer
15843 * has been stopped.
15845 i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
15847 i40e_fdir_teardown(pf);
15849 /* If there is a switch structure or any orphans, remove them.
15850 * This will leave only the PF's VSI remaining.
15852 for (i = 0; i < I40E_MAX_VEB; i++) {
15856 if (pf->veb[i]->uplink_seid == pf->mac_seid ||
15857 pf->veb[i]->uplink_seid == 0)
15858 i40e_switch_branch_release(pf->veb[i]);
15861 /* Now we can shutdown the PF's VSI, just before we kill
15864 if (pf->vsi[pf->lan_vsi])
15865 i40e_vsi_release(pf->vsi[pf->lan_vsi]);
15867 i40e_cloud_filter_exit(pf);
15869 /* remove attached clients */
15870 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
15871 ret_code = i40e_lan_del_device(pf);
15873 dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
15877 /* shutdown and destroy the HMC */
15878 if (hw->hmc.hmc_obj) {
15879 ret_code = i40e_shutdown_lan_hmc(hw);
15881 dev_warn(&pdev->dev,
15882 "Failed to destroy the HMC resources: %d\n",
15887 /* Free MSI/legacy interrupt 0 when in recovery mode. */
15888 if (test_bit(__I40E_RECOVERY_MODE, pf->state) &&
15889 !(pf->flags & I40E_FLAG_MSIX_ENABLED))
15890 free_irq(pf->pdev->irq, pf);
15892 /* shutdown the adminq */
15893 i40e_shutdown_adminq(hw);
15895 /* destroy the locks only once, here */
15896 mutex_destroy(&hw->aq.arq_mutex);
15897 mutex_destroy(&hw->aq.asq_mutex);
15899 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
15901 i40e_clear_interrupt_scheme(pf);
15902 for (i = 0; i < pf->num_alloc_vsi; i++) {
15904 if (!test_bit(__I40E_RECOVERY_MODE, pf->state))
15905 i40e_vsi_clear_rings(pf->vsi[i]);
15906 i40e_vsi_clear(pf->vsi[i]);
15912 for (i = 0; i < I40E_MAX_VEB; i++) {
15917 kfree(pf->qp_pile);
15920 iounmap(hw->hw_addr);
15922 pci_release_mem_regions(pdev);
15924 pci_disable_pcie_error_reporting(pdev);
15925 pci_disable_device(pdev);
15929 * i40e_pci_error_detected - warning that something funky happened in PCI land
15930 * @pdev: PCI device information struct
15931 * @error: the type of PCI error
15933 * Called to warn that something happened and the error handling steps
15934 * are in progress. Allows the driver to quiesce things, be ready for
15937 static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
15938 pci_channel_state_t error)
15940 struct i40e_pf *pf = pci_get_drvdata(pdev);
15942 dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
15945 dev_info(&pdev->dev,
15946 "Cannot recover - error happened during device probe\n");
15947 return PCI_ERS_RESULT_DISCONNECT;
15950 /* shutdown all operations */
15951 if (!test_bit(__I40E_SUSPENDED, pf->state))
15952 i40e_prep_for_reset(pf);
15954 /* Request a slot reset */
15955 return PCI_ERS_RESULT_NEED_RESET;
15959 * i40e_pci_error_slot_reset - a PCI slot reset just happened
15960 * @pdev: PCI device information struct
15962 * Called to find if the driver can work with the device now that
15963 * the pci slot has been reset. If a basic connection seems good
15964 * (registers are readable and have sane content) then return a
15965 * happy little PCI_ERS_RESULT_xxx.
15967 static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
15969 struct i40e_pf *pf = pci_get_drvdata(pdev);
15970 pci_ers_result_t result;
15973 dev_dbg(&pdev->dev, "%s\n", __func__);
15974 if (pci_enable_device_mem(pdev)) {
15975 dev_info(&pdev->dev,
15976 "Cannot re-enable PCI device after reset.\n");
15977 result = PCI_ERS_RESULT_DISCONNECT;
15979 pci_set_master(pdev);
15980 pci_restore_state(pdev);
15981 pci_save_state(pdev);
15982 pci_wake_from_d3(pdev, false);
15984 reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
15986 result = PCI_ERS_RESULT_RECOVERED;
15988 result = PCI_ERS_RESULT_DISCONNECT;
15995 * i40e_pci_error_reset_prepare - prepare device driver for pci reset
15996 * @pdev: PCI device information struct
15998 static void i40e_pci_error_reset_prepare(struct pci_dev *pdev)
16000 struct i40e_pf *pf = pci_get_drvdata(pdev);
16002 i40e_prep_for_reset(pf);
16006 * i40e_pci_error_reset_done - pci reset done, device driver reset can begin
16007 * @pdev: PCI device information struct
16009 static void i40e_pci_error_reset_done(struct pci_dev *pdev)
16011 struct i40e_pf *pf = pci_get_drvdata(pdev);
16013 i40e_reset_and_rebuild(pf, false, false);
16017 * i40e_pci_error_resume - restart operations after PCI error recovery
16018 * @pdev: PCI device information struct
16020 * Called to allow the driver to bring things back up after PCI error
16021 * and/or reset recovery has finished.
16023 static void i40e_pci_error_resume(struct pci_dev *pdev)
16025 struct i40e_pf *pf = pci_get_drvdata(pdev);
16027 dev_dbg(&pdev->dev, "%s\n", __func__);
16028 if (test_bit(__I40E_SUSPENDED, pf->state))
16031 i40e_handle_reset_warning(pf, false);
16035 * i40e_enable_mc_magic_wake - enable multicast magic packet wake up
16036 * using the mac_address_write admin q function
16037 * @pf: pointer to i40e_pf struct
16039 static void i40e_enable_mc_magic_wake(struct i40e_pf *pf)
16041 struct i40e_hw *hw = &pf->hw;
16046 /* Get current MAC address in case it's an LAA */
16047 if (pf->vsi[pf->lan_vsi] && pf->vsi[pf->lan_vsi]->netdev) {
16048 ether_addr_copy(mac_addr,
16049 pf->vsi[pf->lan_vsi]->netdev->dev_addr);
16051 dev_err(&pf->pdev->dev,
16052 "Failed to retrieve MAC address; using default\n");
16053 ether_addr_copy(mac_addr, hw->mac.addr);
16056 /* The FW expects the mac address write cmd to first be called with
16057 * one of these flags before calling it again with the multicast
16060 flags = I40E_AQC_WRITE_TYPE_LAA_WOL;
16062 if (hw->func_caps.flex10_enable && hw->partition_id != 1)
16063 flags = I40E_AQC_WRITE_TYPE_LAA_ONLY;
16065 ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
16067 dev_err(&pf->pdev->dev,
16068 "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up");
16072 flags = I40E_AQC_MC_MAG_EN
16073 | I40E_AQC_WOL_PRESERVE_ON_PFR
16074 | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG;
16075 ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
16077 dev_err(&pf->pdev->dev,
16078 "Failed to enable Multicast Magic Packet wake up\n");
16082 * i40e_shutdown - PCI callback for shutting down
16083 * @pdev: PCI device information struct
16085 static void i40e_shutdown(struct pci_dev *pdev)
16087 struct i40e_pf *pf = pci_get_drvdata(pdev);
16088 struct i40e_hw *hw = &pf->hw;
16090 set_bit(__I40E_SUSPENDED, pf->state);
16091 set_bit(__I40E_DOWN, pf->state);
16093 del_timer_sync(&pf->service_timer);
16094 cancel_work_sync(&pf->service_task);
16095 i40e_cloud_filter_exit(pf);
16096 i40e_fdir_teardown(pf);
16098 /* Client close must be called explicitly here because the timer
16099 * has been stopped.
16101 i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
16103 if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE))
16104 i40e_enable_mc_magic_wake(pf);
16106 i40e_prep_for_reset(pf);
16108 wr32(hw, I40E_PFPM_APM,
16109 (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
16110 wr32(hw, I40E_PFPM_WUFC,
16111 (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
16113 /* Free MSI/legacy interrupt 0 when in recovery mode. */
16114 if (test_bit(__I40E_RECOVERY_MODE, pf->state) &&
16115 !(pf->flags & I40E_FLAG_MSIX_ENABLED))
16116 free_irq(pf->pdev->irq, pf);
16118 /* Since we're going to destroy queues during the
16119 * i40e_clear_interrupt_scheme() we should hold the RTNL lock for this
16123 i40e_clear_interrupt_scheme(pf);
16126 if (system_state == SYSTEM_POWER_OFF) {
16127 pci_wake_from_d3(pdev, pf->wol_en);
16128 pci_set_power_state(pdev, PCI_D3hot);
16133 * i40e_suspend - PM callback for moving to D3
16134 * @dev: generic device information structure
16136 static int __maybe_unused i40e_suspend(struct device *dev)
16138 struct i40e_pf *pf = dev_get_drvdata(dev);
16139 struct i40e_hw *hw = &pf->hw;
16141 /* If we're already suspended, then there is nothing to do */
16142 if (test_and_set_bit(__I40E_SUSPENDED, pf->state))
16145 set_bit(__I40E_DOWN, pf->state);
16147 /* Ensure service task will not be running */
16148 del_timer_sync(&pf->service_timer);
16149 cancel_work_sync(&pf->service_task);
16151 /* Client close must be called explicitly here because the timer
16152 * has been stopped.
16154 i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
16156 if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE))
16157 i40e_enable_mc_magic_wake(pf);
16159 /* Since we're going to destroy queues during the
16160 * i40e_clear_interrupt_scheme() we should hold the RTNL lock for this
16165 i40e_prep_for_reset(pf);
16167 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
16168 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
16170 /* Clear the interrupt scheme and release our IRQs so that the system
16171 * can safely hibernate even when there are a large number of CPUs.
16172 * Otherwise hibernation might fail when mapping all the vectors back
16175 i40e_clear_interrupt_scheme(pf);
16183 * i40e_resume - PM callback for waking up from D3
16184 * @dev: generic device information structure
16186 static int __maybe_unused i40e_resume(struct device *dev)
16188 struct i40e_pf *pf = dev_get_drvdata(dev);
16191 /* If we're not suspended, then there is nothing to do */
16192 if (!test_bit(__I40E_SUSPENDED, pf->state))
16195 /* We need to hold the RTNL lock prior to restoring interrupt schemes,
16196 * since we're going to be restoring queues
16200 /* We cleared the interrupt scheme when we suspended, so we need to
16201 * restore it now to resume device functionality.
16203 err = i40e_restore_interrupt_scheme(pf);
16205 dev_err(dev, "Cannot restore interrupt scheme: %d\n",
16209 clear_bit(__I40E_DOWN, pf->state);
16210 i40e_reset_and_rebuild(pf, false, true);
16214 /* Clear suspended state last after everything is recovered */
16215 clear_bit(__I40E_SUSPENDED, pf->state);
16217 /* Restart the service task */
16218 mod_timer(&pf->service_timer,
16219 round_jiffies(jiffies + pf->service_timer_period));
16224 static const struct pci_error_handlers i40e_err_handler = {
16225 .error_detected = i40e_pci_error_detected,
16226 .slot_reset = i40e_pci_error_slot_reset,
16227 .reset_prepare = i40e_pci_error_reset_prepare,
16228 .reset_done = i40e_pci_error_reset_done,
16229 .resume = i40e_pci_error_resume,
16232 static SIMPLE_DEV_PM_OPS(i40e_pm_ops, i40e_suspend, i40e_resume);
16234 static struct pci_driver i40e_driver = {
16235 .name = i40e_driver_name,
16236 .id_table = i40e_pci_tbl,
16237 .probe = i40e_probe,
16238 .remove = i40e_remove,
16240 .pm = &i40e_pm_ops,
16242 .shutdown = i40e_shutdown,
16243 .err_handler = &i40e_err_handler,
16244 .sriov_configure = i40e_pci_sriov_configure,
16248 * i40e_init_module - Driver registration routine
16250 * i40e_init_module is the first routine called when the driver is
16251 * loaded. All it does is register with the PCI subsystem.
16253 static int __init i40e_init_module(void)
16255 pr_info("%s: %s\n", i40e_driver_name, i40e_driver_string);
16256 pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
16258 /* There is no need to throttle the number of active tasks because
16259 * each device limits its own task using a state bit for scheduling
16260 * the service task, and the device tasks do not interfere with each
16261 * other, so we don't set a max task limit. We must set WQ_MEM_RECLAIM
16262 * since we need to be able to guarantee forward progress even under
16265 i40e_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, i40e_driver_name);
16267 pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
16272 return pci_register_driver(&i40e_driver);
16274 module_init(i40e_init_module);
16277 * i40e_exit_module - Driver exit cleanup routine
16279 * i40e_exit_module is called just before the driver is removed
16282 static void __exit i40e_exit_module(void)
16284 pci_unregister_driver(&i40e_driver);
16285 destroy_workqueue(i40e_wq);
16288 module_exit(i40e_exit_module);