1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2016 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 ******************************************************************************/
27 #include <linux/etherdevice.h>
28 #include <linux/of_net.h>
29 #include <linux/pci.h>
33 #include "i40e_diag.h"
34 #include <net/udp_tunnel.h>
36 const char i40e_driver_name[] = "i40e";
37 static const char i40e_driver_string[] =
38 "Intel(R) Ethernet Connection XL710 Network Driver";
42 #define DRV_VERSION_MAJOR 1
43 #define DRV_VERSION_MINOR 6
44 #define DRV_VERSION_BUILD 4
45 #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
46 __stringify(DRV_VERSION_MINOR) "." \
47 __stringify(DRV_VERSION_BUILD) DRV_KERN
48 const char i40e_driver_version_str[] = DRV_VERSION;
49 static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
51 /* a bit of forward declarations */
52 static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
53 static void i40e_handle_reset_warning(struct i40e_pf *pf);
54 static int i40e_add_vsi(struct i40e_vsi *vsi);
55 static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
56 static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
57 static int i40e_setup_misc_vector(struct i40e_pf *pf);
58 static void i40e_determine_queue_usage(struct i40e_pf *pf);
59 static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
60 static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
61 u16 rss_table_size, u16 rss_size);
62 static void i40e_fdir_sb_setup(struct i40e_pf *pf);
63 static int i40e_veb_get_bw_info(struct i40e_veb *veb);
65 /* i40e_pci_tbl - PCI Device ID Table
67 * Last entry must be all 0s
69 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
70 * Class, Class Mask, private data (not used) }
72 static const struct pci_device_id i40e_pci_tbl[] = {
73 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
74 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
75 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
76 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
77 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
78 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
79 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
80 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0},
81 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0},
82 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
83 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0},
84 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0},
85 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0},
86 {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0},
87 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0},
88 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0},
89 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_I_X722), 0},
90 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
91 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0},
92 /* required last entry */
95 MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
97 #define I40E_MAX_VF_COUNT 128
98 static int debug = -1;
99 module_param(debug, int, 0);
100 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
102 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
103 MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
104 MODULE_LICENSE("GPL");
105 MODULE_VERSION(DRV_VERSION);
107 static struct workqueue_struct *i40e_wq;
110 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
111 * @hw: pointer to the HW structure
112 * @mem: ptr to mem struct to fill out
113 * @size: size of memory requested
114 * @alignment: what to align the allocation to
116 int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
117 u64 size, u32 alignment)
119 struct i40e_pf *pf = (struct i40e_pf *)hw->back;
121 mem->size = ALIGN(size, alignment);
122 mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
123 &mem->pa, GFP_KERNEL);
131 * i40e_free_dma_mem_d - OS specific memory free for shared code
132 * @hw: pointer to the HW structure
133 * @mem: ptr to mem struct to free
135 int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
137 struct i40e_pf *pf = (struct i40e_pf *)hw->back;
139 dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
148 * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
149 * @hw: pointer to the HW structure
150 * @mem: ptr to mem struct to fill out
151 * @size: size of memory requested
153 int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
157 mem->va = kzalloc(size, GFP_KERNEL);
166 * i40e_free_virt_mem_d - OS specific memory free for shared code
167 * @hw: pointer to the HW structure
168 * @mem: ptr to mem struct to free
170 int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
172 /* it's ok to kfree a NULL pointer */
181 * i40e_get_lump - find a lump of free generic resource
182 * @pf: board private structure
183 * @pile: the pile of resource to search
184 * @needed: the number of items needed
185 * @id: an owner id to stick on the items assigned
187 * Returns the base item index of the lump, or negative for error
189 * The search_hint trick and lack of advanced fit-finding only work
190 * because we're highly likely to have all the same size lump requests.
191 * Linear search time and any fragmentation should be minimal.
193 static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
199 if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
200 dev_info(&pf->pdev->dev,
201 "param err: pile=%p needed=%d id=0x%04x\n",
206 /* start the linear search with an imperfect hint */
207 i = pile->search_hint;
208 while (i < pile->num_entries) {
209 /* skip already allocated entries */
210 if (pile->list[i] & I40E_PILE_VALID_BIT) {
215 /* do we have enough in this lump? */
216 for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
217 if (pile->list[i+j] & I40E_PILE_VALID_BIT)
222 /* there was enough, so assign it to the requestor */
223 for (j = 0; j < needed; j++)
224 pile->list[i+j] = id | I40E_PILE_VALID_BIT;
226 pile->search_hint = i + j;
230 /* not enough, so skip over it and continue looking */
238 * i40e_put_lump - return a lump of generic resource
239 * @pile: the pile of resource to search
240 * @index: the base item index
241 * @id: the owner id of the items assigned
243 * Returns the count of items in the lump
245 static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
247 int valid_id = (id | I40E_PILE_VALID_BIT);
251 if (!pile || index >= pile->num_entries)
255 i < pile->num_entries && pile->list[i] == valid_id;
261 if (count && index < pile->search_hint)
262 pile->search_hint = index;
268 * i40e_find_vsi_from_id - searches for the vsi with the given id
269 * @pf - the pf structure to search for the vsi
270 * @id - id of the vsi it is searching for
272 struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id)
276 for (i = 0; i < pf->num_alloc_vsi; i++)
277 if (pf->vsi[i] && (pf->vsi[i]->id == id))
284 * i40e_service_event_schedule - Schedule the service task to wake up
285 * @pf: board private structure
287 * If not already scheduled, this puts the task into the work queue
289 void i40e_service_event_schedule(struct i40e_pf *pf)
291 if (!test_bit(__I40E_DOWN, &pf->state) &&
292 !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) &&
293 !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state))
294 queue_work(i40e_wq, &pf->service_task);
298 * i40e_tx_timeout - Respond to a Tx Hang
299 * @netdev: network interface device structure
301 * If any port has noticed a Tx timeout, it is likely that the whole
302 * device is munged, not just the one netdev port, so go for the full
306 void i40e_tx_timeout(struct net_device *netdev)
308 static void i40e_tx_timeout(struct net_device *netdev)
311 struct i40e_netdev_priv *np = netdev_priv(netdev);
312 struct i40e_vsi *vsi = np->vsi;
313 struct i40e_pf *pf = vsi->back;
314 struct i40e_ring *tx_ring = NULL;
315 unsigned int i, hung_queue = 0;
318 pf->tx_timeout_count++;
320 /* find the stopped queue the same way the stack does */
321 for (i = 0; i < netdev->num_tx_queues; i++) {
322 struct netdev_queue *q;
323 unsigned long trans_start;
325 q = netdev_get_tx_queue(netdev, i);
326 trans_start = q->trans_start;
327 if (netif_xmit_stopped(q) &&
329 (trans_start + netdev->watchdog_timeo))) {
335 if (i == netdev->num_tx_queues) {
336 netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
338 /* now that we have an index, find the tx_ring struct */
339 for (i = 0; i < vsi->num_queue_pairs; i++) {
340 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
342 vsi->tx_rings[i]->queue_index) {
343 tx_ring = vsi->tx_rings[i];
350 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
351 pf->tx_timeout_recovery_level = 1; /* reset after some time */
352 else if (time_before(jiffies,
353 (pf->tx_timeout_last_recovery + netdev->watchdog_timeo)))
354 return; /* don't do any new action before the next timeout */
357 head = i40e_get_head(tx_ring);
358 /* Read interrupt register */
359 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
361 I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
362 tx_ring->vsi->base_vector - 1));
364 val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
366 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",
367 vsi->seid, hung_queue, tx_ring->next_to_clean,
368 head, tx_ring->next_to_use,
369 readl(tx_ring->tail), val);
372 pf->tx_timeout_last_recovery = jiffies;
373 netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
374 pf->tx_timeout_recovery_level, hung_queue);
376 switch (pf->tx_timeout_recovery_level) {
378 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
381 set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
384 set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
387 netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
391 i40e_service_event_schedule(pf);
392 pf->tx_timeout_recovery_level++;
396 * i40e_get_vsi_stats_struct - Get System Network Statistics
397 * @vsi: the VSI we care about
399 * Returns the address of the device statistics structure.
400 * The statistics are actually updated from the service task.
402 struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
404 return &vsi->net_stats;
408 * i40e_get_netdev_stats_struct - Get statistics for netdev interface
409 * @netdev: network interface device structure
411 * Returns the address of the device statistics structure.
412 * The statistics are actually updated from the service task.
415 struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
416 struct net_device *netdev,
417 struct rtnl_link_stats64 *stats)
419 static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
420 struct net_device *netdev,
421 struct rtnl_link_stats64 *stats)
424 struct i40e_netdev_priv *np = netdev_priv(netdev);
425 struct i40e_ring *tx_ring, *rx_ring;
426 struct i40e_vsi *vsi = np->vsi;
427 struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
430 if (test_bit(__I40E_DOWN, &vsi->state))
437 for (i = 0; i < vsi->num_queue_pairs; i++) {
441 tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
446 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
447 packets = tx_ring->stats.packets;
448 bytes = tx_ring->stats.bytes;
449 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
451 stats->tx_packets += packets;
452 stats->tx_bytes += bytes;
453 rx_ring = &tx_ring[1];
456 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
457 packets = rx_ring->stats.packets;
458 bytes = rx_ring->stats.bytes;
459 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
461 stats->rx_packets += packets;
462 stats->rx_bytes += bytes;
466 /* following stats updated by i40e_watchdog_subtask() */
467 stats->multicast = vsi_stats->multicast;
468 stats->tx_errors = vsi_stats->tx_errors;
469 stats->tx_dropped = vsi_stats->tx_dropped;
470 stats->rx_errors = vsi_stats->rx_errors;
471 stats->rx_dropped = vsi_stats->rx_dropped;
472 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
473 stats->rx_length_errors = vsi_stats->rx_length_errors;
479 * i40e_vsi_reset_stats - Resets all stats of the given vsi
480 * @vsi: the VSI to have its stats reset
482 void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
484 struct rtnl_link_stats64 *ns;
490 ns = i40e_get_vsi_stats_struct(vsi);
491 memset(ns, 0, sizeof(*ns));
492 memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
493 memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
494 memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
495 if (vsi->rx_rings && vsi->rx_rings[0]) {
496 for (i = 0; i < vsi->num_queue_pairs; i++) {
497 memset(&vsi->rx_rings[i]->stats, 0,
498 sizeof(vsi->rx_rings[i]->stats));
499 memset(&vsi->rx_rings[i]->rx_stats, 0,
500 sizeof(vsi->rx_rings[i]->rx_stats));
501 memset(&vsi->tx_rings[i]->stats, 0,
502 sizeof(vsi->tx_rings[i]->stats));
503 memset(&vsi->tx_rings[i]->tx_stats, 0,
504 sizeof(vsi->tx_rings[i]->tx_stats));
507 vsi->stat_offsets_loaded = false;
511 * i40e_pf_reset_stats - Reset all of the stats for the given PF
512 * @pf: the PF to be reset
514 void i40e_pf_reset_stats(struct i40e_pf *pf)
518 memset(&pf->stats, 0, sizeof(pf->stats));
519 memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
520 pf->stat_offsets_loaded = false;
522 for (i = 0; i < I40E_MAX_VEB; i++) {
524 memset(&pf->veb[i]->stats, 0,
525 sizeof(pf->veb[i]->stats));
526 memset(&pf->veb[i]->stats_offsets, 0,
527 sizeof(pf->veb[i]->stats_offsets));
528 pf->veb[i]->stat_offsets_loaded = false;
534 * i40e_stat_update48 - read and update a 48 bit stat from the chip
535 * @hw: ptr to the hardware info
536 * @hireg: the high 32 bit reg to read
537 * @loreg: the low 32 bit reg to read
538 * @offset_loaded: has the initial offset been loaded yet
539 * @offset: ptr to current offset value
540 * @stat: ptr to the stat
542 * Since the device stats are not reset at PFReset, they likely will not
543 * be zeroed when the driver starts. We'll save the first values read
544 * and use them as offsets to be subtracted from the raw values in order
545 * to report stats that count from zero. In the process, we also manage
546 * the potential roll-over.
548 static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
549 bool offset_loaded, u64 *offset, u64 *stat)
553 if (hw->device_id == I40E_DEV_ID_QEMU) {
554 new_data = rd32(hw, loreg);
555 new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
557 new_data = rd64(hw, loreg);
561 if (likely(new_data >= *offset))
562 *stat = new_data - *offset;
564 *stat = (new_data + BIT_ULL(48)) - *offset;
565 *stat &= 0xFFFFFFFFFFFFULL;
569 * i40e_stat_update32 - read and update a 32 bit stat from the chip
570 * @hw: ptr to the hardware info
571 * @reg: the hw reg to read
572 * @offset_loaded: has the initial offset been loaded yet
573 * @offset: ptr to current offset value
574 * @stat: ptr to the stat
576 static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
577 bool offset_loaded, u64 *offset, u64 *stat)
581 new_data = rd32(hw, reg);
584 if (likely(new_data >= *offset))
585 *stat = (u32)(new_data - *offset);
587 *stat = (u32)((new_data + BIT_ULL(32)) - *offset);
591 * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
592 * @vsi: the VSI to be updated
594 void i40e_update_eth_stats(struct i40e_vsi *vsi)
596 int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
597 struct i40e_pf *pf = vsi->back;
598 struct i40e_hw *hw = &pf->hw;
599 struct i40e_eth_stats *oes;
600 struct i40e_eth_stats *es; /* device's eth stats */
602 es = &vsi->eth_stats;
603 oes = &vsi->eth_stats_offsets;
605 /* Gather up the stats that the hw collects */
606 i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
607 vsi->stat_offsets_loaded,
608 &oes->tx_errors, &es->tx_errors);
609 i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
610 vsi->stat_offsets_loaded,
611 &oes->rx_discards, &es->rx_discards);
612 i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
613 vsi->stat_offsets_loaded,
614 &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
615 i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
616 vsi->stat_offsets_loaded,
617 &oes->tx_errors, &es->tx_errors);
619 i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
620 I40E_GLV_GORCL(stat_idx),
621 vsi->stat_offsets_loaded,
622 &oes->rx_bytes, &es->rx_bytes);
623 i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
624 I40E_GLV_UPRCL(stat_idx),
625 vsi->stat_offsets_loaded,
626 &oes->rx_unicast, &es->rx_unicast);
627 i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
628 I40E_GLV_MPRCL(stat_idx),
629 vsi->stat_offsets_loaded,
630 &oes->rx_multicast, &es->rx_multicast);
631 i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
632 I40E_GLV_BPRCL(stat_idx),
633 vsi->stat_offsets_loaded,
634 &oes->rx_broadcast, &es->rx_broadcast);
636 i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
637 I40E_GLV_GOTCL(stat_idx),
638 vsi->stat_offsets_loaded,
639 &oes->tx_bytes, &es->tx_bytes);
640 i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
641 I40E_GLV_UPTCL(stat_idx),
642 vsi->stat_offsets_loaded,
643 &oes->tx_unicast, &es->tx_unicast);
644 i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
645 I40E_GLV_MPTCL(stat_idx),
646 vsi->stat_offsets_loaded,
647 &oes->tx_multicast, &es->tx_multicast);
648 i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
649 I40E_GLV_BPTCL(stat_idx),
650 vsi->stat_offsets_loaded,
651 &oes->tx_broadcast, &es->tx_broadcast);
652 vsi->stat_offsets_loaded = true;
656 * i40e_update_veb_stats - Update Switch component statistics
657 * @veb: the VEB being updated
659 static void i40e_update_veb_stats(struct i40e_veb *veb)
661 struct i40e_pf *pf = veb->pf;
662 struct i40e_hw *hw = &pf->hw;
663 struct i40e_eth_stats *oes;
664 struct i40e_eth_stats *es; /* device's eth stats */
665 struct i40e_veb_tc_stats *veb_oes;
666 struct i40e_veb_tc_stats *veb_es;
669 idx = veb->stats_idx;
671 oes = &veb->stats_offsets;
672 veb_es = &veb->tc_stats;
673 veb_oes = &veb->tc_stats_offsets;
675 /* Gather up the stats that the hw collects */
676 i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
677 veb->stat_offsets_loaded,
678 &oes->tx_discards, &es->tx_discards);
679 if (hw->revision_id > 0)
680 i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
681 veb->stat_offsets_loaded,
682 &oes->rx_unknown_protocol,
683 &es->rx_unknown_protocol);
684 i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
685 veb->stat_offsets_loaded,
686 &oes->rx_bytes, &es->rx_bytes);
687 i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
688 veb->stat_offsets_loaded,
689 &oes->rx_unicast, &es->rx_unicast);
690 i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
691 veb->stat_offsets_loaded,
692 &oes->rx_multicast, &es->rx_multicast);
693 i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
694 veb->stat_offsets_loaded,
695 &oes->rx_broadcast, &es->rx_broadcast);
697 i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
698 veb->stat_offsets_loaded,
699 &oes->tx_bytes, &es->tx_bytes);
700 i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
701 veb->stat_offsets_loaded,
702 &oes->tx_unicast, &es->tx_unicast);
703 i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
704 veb->stat_offsets_loaded,
705 &oes->tx_multicast, &es->tx_multicast);
706 i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
707 veb->stat_offsets_loaded,
708 &oes->tx_broadcast, &es->tx_broadcast);
709 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
710 i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx),
711 I40E_GLVEBTC_RPCL(i, idx),
712 veb->stat_offsets_loaded,
713 &veb_oes->tc_rx_packets[i],
714 &veb_es->tc_rx_packets[i]);
715 i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx),
716 I40E_GLVEBTC_RBCL(i, idx),
717 veb->stat_offsets_loaded,
718 &veb_oes->tc_rx_bytes[i],
719 &veb_es->tc_rx_bytes[i]);
720 i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx),
721 I40E_GLVEBTC_TPCL(i, idx),
722 veb->stat_offsets_loaded,
723 &veb_oes->tc_tx_packets[i],
724 &veb_es->tc_tx_packets[i]);
725 i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx),
726 I40E_GLVEBTC_TBCL(i, idx),
727 veb->stat_offsets_loaded,
728 &veb_oes->tc_tx_bytes[i],
729 &veb_es->tc_tx_bytes[i]);
731 veb->stat_offsets_loaded = true;
736 * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters.
737 * @vsi: the VSI that is capable of doing FCoE
739 static void i40e_update_fcoe_stats(struct i40e_vsi *vsi)
741 struct i40e_pf *pf = vsi->back;
742 struct i40e_hw *hw = &pf->hw;
743 struct i40e_fcoe_stats *ofs;
744 struct i40e_fcoe_stats *fs; /* device's eth stats */
747 if (vsi->type != I40E_VSI_FCOE)
750 idx = hw->pf_id + I40E_FCOE_PF_STAT_OFFSET;
751 fs = &vsi->fcoe_stats;
752 ofs = &vsi->fcoe_stats_offsets;
754 i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx),
755 vsi->fcoe_stat_offsets_loaded,
756 &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets);
757 i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx),
758 vsi->fcoe_stat_offsets_loaded,
759 &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords);
760 i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx),
761 vsi->fcoe_stat_offsets_loaded,
762 &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped);
763 i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx),
764 vsi->fcoe_stat_offsets_loaded,
765 &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets);
766 i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx),
767 vsi->fcoe_stat_offsets_loaded,
768 &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords);
769 i40e_stat_update32(hw, I40E_GL_FCOECRC(idx),
770 vsi->fcoe_stat_offsets_loaded,
771 &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc);
772 i40e_stat_update32(hw, I40E_GL_FCOELAST(idx),
773 vsi->fcoe_stat_offsets_loaded,
774 &ofs->fcoe_last_error, &fs->fcoe_last_error);
775 i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx),
776 vsi->fcoe_stat_offsets_loaded,
777 &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count);
779 vsi->fcoe_stat_offsets_loaded = true;
784 * i40e_update_vsi_stats - Update the vsi statistics counters.
785 * @vsi: the VSI to be updated
787 * There are a few instances where we store the same stat in a
788 * couple of different structs. This is partly because we have
789 * the netdev stats that need to be filled out, which is slightly
790 * different from the "eth_stats" defined by the chip and used in
791 * VF communications. We sort it out here.
793 static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
795 struct i40e_pf *pf = vsi->back;
796 struct rtnl_link_stats64 *ons;
797 struct rtnl_link_stats64 *ns; /* netdev stats */
798 struct i40e_eth_stats *oes;
799 struct i40e_eth_stats *es; /* device's eth stats */
800 u32 tx_restart, tx_busy;
801 u64 tx_lost_interrupt;
812 if (test_bit(__I40E_DOWN, &vsi->state) ||
813 test_bit(__I40E_CONFIG_BUSY, &pf->state))
816 ns = i40e_get_vsi_stats_struct(vsi);
817 ons = &vsi->net_stats_offsets;
818 es = &vsi->eth_stats;
819 oes = &vsi->eth_stats_offsets;
821 /* Gather up the netdev and vsi stats that the driver collects
822 * on the fly during packet processing
826 tx_restart = tx_busy = tx_linearize = tx_force_wb = 0;
827 tx_lost_interrupt = 0;
831 for (q = 0; q < vsi->num_queue_pairs; q++) {
833 p = ACCESS_ONCE(vsi->tx_rings[q]);
836 start = u64_stats_fetch_begin_irq(&p->syncp);
837 packets = p->stats.packets;
838 bytes = p->stats.bytes;
839 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
842 tx_restart += p->tx_stats.restart_queue;
843 tx_busy += p->tx_stats.tx_busy;
844 tx_linearize += p->tx_stats.tx_linearize;
845 tx_force_wb += p->tx_stats.tx_force_wb;
846 tx_lost_interrupt += p->tx_stats.tx_lost_interrupt;
848 /* Rx queue is part of the same block as Tx queue */
851 start = u64_stats_fetch_begin_irq(&p->syncp);
852 packets = p->stats.packets;
853 bytes = p->stats.bytes;
854 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
857 rx_buf += p->rx_stats.alloc_buff_failed;
858 rx_page += p->rx_stats.alloc_page_failed;
861 vsi->tx_restart = tx_restart;
862 vsi->tx_busy = tx_busy;
863 vsi->tx_linearize = tx_linearize;
864 vsi->tx_force_wb = tx_force_wb;
865 vsi->tx_lost_interrupt = tx_lost_interrupt;
866 vsi->rx_page_failed = rx_page;
867 vsi->rx_buf_failed = rx_buf;
869 ns->rx_packets = rx_p;
871 ns->tx_packets = tx_p;
874 /* update netdev stats from eth stats */
875 i40e_update_eth_stats(vsi);
876 ons->tx_errors = oes->tx_errors;
877 ns->tx_errors = es->tx_errors;
878 ons->multicast = oes->rx_multicast;
879 ns->multicast = es->rx_multicast;
880 ons->rx_dropped = oes->rx_discards;
881 ns->rx_dropped = es->rx_discards;
882 ons->tx_dropped = oes->tx_discards;
883 ns->tx_dropped = es->tx_discards;
885 /* pull in a couple PF stats if this is the main vsi */
886 if (vsi == pf->vsi[pf->lan_vsi]) {
887 ns->rx_crc_errors = pf->stats.crc_errors;
888 ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
889 ns->rx_length_errors = pf->stats.rx_length_errors;
894 * i40e_update_pf_stats - Update the PF statistics counters.
895 * @pf: the PF to be updated
897 static void i40e_update_pf_stats(struct i40e_pf *pf)
899 struct i40e_hw_port_stats *osd = &pf->stats_offsets;
900 struct i40e_hw_port_stats *nsd = &pf->stats;
901 struct i40e_hw *hw = &pf->hw;
905 i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
906 I40E_GLPRT_GORCL(hw->port),
907 pf->stat_offsets_loaded,
908 &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
909 i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
910 I40E_GLPRT_GOTCL(hw->port),
911 pf->stat_offsets_loaded,
912 &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
913 i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
914 pf->stat_offsets_loaded,
915 &osd->eth.rx_discards,
916 &nsd->eth.rx_discards);
917 i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
918 I40E_GLPRT_UPRCL(hw->port),
919 pf->stat_offsets_loaded,
920 &osd->eth.rx_unicast,
921 &nsd->eth.rx_unicast);
922 i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
923 I40E_GLPRT_MPRCL(hw->port),
924 pf->stat_offsets_loaded,
925 &osd->eth.rx_multicast,
926 &nsd->eth.rx_multicast);
927 i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
928 I40E_GLPRT_BPRCL(hw->port),
929 pf->stat_offsets_loaded,
930 &osd->eth.rx_broadcast,
931 &nsd->eth.rx_broadcast);
932 i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
933 I40E_GLPRT_UPTCL(hw->port),
934 pf->stat_offsets_loaded,
935 &osd->eth.tx_unicast,
936 &nsd->eth.tx_unicast);
937 i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
938 I40E_GLPRT_MPTCL(hw->port),
939 pf->stat_offsets_loaded,
940 &osd->eth.tx_multicast,
941 &nsd->eth.tx_multicast);
942 i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
943 I40E_GLPRT_BPTCL(hw->port),
944 pf->stat_offsets_loaded,
945 &osd->eth.tx_broadcast,
946 &nsd->eth.tx_broadcast);
948 i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
949 pf->stat_offsets_loaded,
950 &osd->tx_dropped_link_down,
951 &nsd->tx_dropped_link_down);
953 i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
954 pf->stat_offsets_loaded,
955 &osd->crc_errors, &nsd->crc_errors);
957 i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
958 pf->stat_offsets_loaded,
959 &osd->illegal_bytes, &nsd->illegal_bytes);
961 i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
962 pf->stat_offsets_loaded,
963 &osd->mac_local_faults,
964 &nsd->mac_local_faults);
965 i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
966 pf->stat_offsets_loaded,
967 &osd->mac_remote_faults,
968 &nsd->mac_remote_faults);
970 i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
971 pf->stat_offsets_loaded,
972 &osd->rx_length_errors,
973 &nsd->rx_length_errors);
975 i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
976 pf->stat_offsets_loaded,
977 &osd->link_xon_rx, &nsd->link_xon_rx);
978 i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
979 pf->stat_offsets_loaded,
980 &osd->link_xon_tx, &nsd->link_xon_tx);
981 i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
982 pf->stat_offsets_loaded,
983 &osd->link_xoff_rx, &nsd->link_xoff_rx);
984 i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
985 pf->stat_offsets_loaded,
986 &osd->link_xoff_tx, &nsd->link_xoff_tx);
988 for (i = 0; i < 8; i++) {
989 i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
990 pf->stat_offsets_loaded,
991 &osd->priority_xoff_rx[i],
992 &nsd->priority_xoff_rx[i]);
993 i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
994 pf->stat_offsets_loaded,
995 &osd->priority_xon_rx[i],
996 &nsd->priority_xon_rx[i]);
997 i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
998 pf->stat_offsets_loaded,
999 &osd->priority_xon_tx[i],
1000 &nsd->priority_xon_tx[i]);
1001 i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
1002 pf->stat_offsets_loaded,
1003 &osd->priority_xoff_tx[i],
1004 &nsd->priority_xoff_tx[i]);
1005 i40e_stat_update32(hw,
1006 I40E_GLPRT_RXON2OFFCNT(hw->port, i),
1007 pf->stat_offsets_loaded,
1008 &osd->priority_xon_2_xoff[i],
1009 &nsd->priority_xon_2_xoff[i]);
1012 i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
1013 I40E_GLPRT_PRC64L(hw->port),
1014 pf->stat_offsets_loaded,
1015 &osd->rx_size_64, &nsd->rx_size_64);
1016 i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
1017 I40E_GLPRT_PRC127L(hw->port),
1018 pf->stat_offsets_loaded,
1019 &osd->rx_size_127, &nsd->rx_size_127);
1020 i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
1021 I40E_GLPRT_PRC255L(hw->port),
1022 pf->stat_offsets_loaded,
1023 &osd->rx_size_255, &nsd->rx_size_255);
1024 i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
1025 I40E_GLPRT_PRC511L(hw->port),
1026 pf->stat_offsets_loaded,
1027 &osd->rx_size_511, &nsd->rx_size_511);
1028 i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
1029 I40E_GLPRT_PRC1023L(hw->port),
1030 pf->stat_offsets_loaded,
1031 &osd->rx_size_1023, &nsd->rx_size_1023);
1032 i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
1033 I40E_GLPRT_PRC1522L(hw->port),
1034 pf->stat_offsets_loaded,
1035 &osd->rx_size_1522, &nsd->rx_size_1522);
1036 i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
1037 I40E_GLPRT_PRC9522L(hw->port),
1038 pf->stat_offsets_loaded,
1039 &osd->rx_size_big, &nsd->rx_size_big);
1041 i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
1042 I40E_GLPRT_PTC64L(hw->port),
1043 pf->stat_offsets_loaded,
1044 &osd->tx_size_64, &nsd->tx_size_64);
1045 i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
1046 I40E_GLPRT_PTC127L(hw->port),
1047 pf->stat_offsets_loaded,
1048 &osd->tx_size_127, &nsd->tx_size_127);
1049 i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
1050 I40E_GLPRT_PTC255L(hw->port),
1051 pf->stat_offsets_loaded,
1052 &osd->tx_size_255, &nsd->tx_size_255);
1053 i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
1054 I40E_GLPRT_PTC511L(hw->port),
1055 pf->stat_offsets_loaded,
1056 &osd->tx_size_511, &nsd->tx_size_511);
1057 i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
1058 I40E_GLPRT_PTC1023L(hw->port),
1059 pf->stat_offsets_loaded,
1060 &osd->tx_size_1023, &nsd->tx_size_1023);
1061 i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
1062 I40E_GLPRT_PTC1522L(hw->port),
1063 pf->stat_offsets_loaded,
1064 &osd->tx_size_1522, &nsd->tx_size_1522);
1065 i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
1066 I40E_GLPRT_PTC9522L(hw->port),
1067 pf->stat_offsets_loaded,
1068 &osd->tx_size_big, &nsd->tx_size_big);
1070 i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
1071 pf->stat_offsets_loaded,
1072 &osd->rx_undersize, &nsd->rx_undersize);
1073 i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
1074 pf->stat_offsets_loaded,
1075 &osd->rx_fragments, &nsd->rx_fragments);
1076 i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
1077 pf->stat_offsets_loaded,
1078 &osd->rx_oversize, &nsd->rx_oversize);
1079 i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
1080 pf->stat_offsets_loaded,
1081 &osd->rx_jabber, &nsd->rx_jabber);
1084 i40e_stat_update32(hw,
1085 I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf->hw.pf_id)),
1086 pf->stat_offsets_loaded,
1087 &osd->fd_atr_match, &nsd->fd_atr_match);
1088 i40e_stat_update32(hw,
1089 I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf->hw.pf_id)),
1090 pf->stat_offsets_loaded,
1091 &osd->fd_sb_match, &nsd->fd_sb_match);
1092 i40e_stat_update32(hw,
1093 I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)),
1094 pf->stat_offsets_loaded,
1095 &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match);
1097 val = rd32(hw, I40E_PRTPM_EEE_STAT);
1098 nsd->tx_lpi_status =
1099 (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
1100 I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
1101 nsd->rx_lpi_status =
1102 (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
1103 I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
1104 i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
1105 pf->stat_offsets_loaded,
1106 &osd->tx_lpi_count, &nsd->tx_lpi_count);
1107 i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
1108 pf->stat_offsets_loaded,
1109 &osd->rx_lpi_count, &nsd->rx_lpi_count);
1111 if (pf->flags & I40E_FLAG_FD_SB_ENABLED &&
1112 !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED))
1113 nsd->fd_sb_status = true;
1115 nsd->fd_sb_status = false;
1117 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED &&
1118 !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED))
1119 nsd->fd_atr_status = true;
1121 nsd->fd_atr_status = false;
1123 pf->stat_offsets_loaded = true;
1127 * i40e_update_stats - Update the various statistics counters.
1128 * @vsi: the VSI to be updated
1130 * Update the various stats for this VSI and its related entities.
1132 void i40e_update_stats(struct i40e_vsi *vsi)
1134 struct i40e_pf *pf = vsi->back;
1136 if (vsi == pf->vsi[pf->lan_vsi])
1137 i40e_update_pf_stats(pf);
1139 i40e_update_vsi_stats(vsi);
1141 i40e_update_fcoe_stats(vsi);
1146 * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
1147 * @vsi: the VSI to be searched
1148 * @macaddr: the MAC address
1150 * @is_vf: make sure its a VF filter, else doesn't matter
1151 * @is_netdev: make sure its a netdev filter, else doesn't matter
1153 * Returns ptr to the filter object or NULL
1155 static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
1156 u8 *macaddr, s16 vlan,
1157 bool is_vf, bool is_netdev)
1159 struct i40e_mac_filter *f;
1161 if (!vsi || !macaddr)
1164 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1165 if ((ether_addr_equal(macaddr, f->macaddr)) &&
1166 (vlan == f->vlan) &&
1167 (!is_vf || f->is_vf) &&
1168 (!is_netdev || f->is_netdev))
1175 * i40e_find_mac - Find a mac addr in the macvlan filters list
1176 * @vsi: the VSI to be searched
1177 * @macaddr: the MAC address we are searching for
1178 * @is_vf: make sure its a VF filter, else doesn't matter
1179 * @is_netdev: make sure its a netdev filter, else doesn't matter
1181 * Returns the first filter with the provided MAC address or NULL if
1182 * MAC address was not found
1184 struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr,
1185 bool is_vf, bool is_netdev)
1187 struct i40e_mac_filter *f;
1189 if (!vsi || !macaddr)
1192 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1193 if ((ether_addr_equal(macaddr, f->macaddr)) &&
1194 (!is_vf || f->is_vf) &&
1195 (!is_netdev || f->is_netdev))
1202 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1203 * @vsi: the VSI to be searched
1205 * Returns true if VSI is in vlan mode or false otherwise
1207 bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
1209 struct i40e_mac_filter *f;
1211 /* Only -1 for all the filters denotes not in vlan mode
1212 * so we have to go through all the list in order to make sure
1214 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1215 if (f->vlan >= 0 || vsi->info.pvid)
1223 * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
1224 * @vsi: the VSI to be searched
1225 * @macaddr: the mac address to be filtered
1226 * @is_vf: true if it is a VF
1227 * @is_netdev: true if it is a netdev
1229 * Goes through all the macvlan filters and adds a
1230 * macvlan filter for each unique vlan that already exists
1232 * Returns first filter found on success, else NULL
1234 struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr,
1235 bool is_vf, bool is_netdev)
1237 struct i40e_mac_filter *f;
1239 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1241 f->vlan = le16_to_cpu(vsi->info.pvid);
1242 if (!i40e_find_filter(vsi, macaddr, f->vlan,
1243 is_vf, is_netdev)) {
1244 if (!i40e_add_filter(vsi, macaddr, f->vlan,
1250 return list_first_entry_or_null(&vsi->mac_filter_list,
1251 struct i40e_mac_filter, list);
1255 * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS
1256 * @vsi: the VSI to be searched
1257 * @macaddr: the mac address to be removed
1258 * @is_vf: true if it is a VF
1259 * @is_netdev: true if it is a netdev
1261 * Removes a given MAC address from a VSI, regardless of VLAN
1263 * Returns 0 for success, or error
1265 int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, u8 *macaddr,
1266 bool is_vf, bool is_netdev)
1268 struct i40e_mac_filter *f = NULL;
1271 WARN(!spin_is_locked(&vsi->mac_filter_list_lock),
1272 "Missing mac_filter_list_lock\n");
1273 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1274 if ((ether_addr_equal(macaddr, f->macaddr)) &&
1275 (is_vf == f->is_vf) &&
1276 (is_netdev == f->is_netdev)) {
1283 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1284 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1291 * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
1292 * @vsi: the PF Main VSI - inappropriate for any other VSI
1293 * @macaddr: the MAC address
1295 * Some older firmware configurations set up a default promiscuous VLAN
1296 * filter that needs to be removed.
1298 static int i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
1300 struct i40e_aqc_remove_macvlan_element_data element;
1301 struct i40e_pf *pf = vsi->back;
1304 /* Only appropriate for the PF main VSI */
1305 if (vsi->type != I40E_VSI_MAIN)
1308 memset(&element, 0, sizeof(element));
1309 ether_addr_copy(element.mac_addr, macaddr);
1310 element.vlan_tag = 0;
1311 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
1312 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
1313 ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1321 * i40e_add_filter - Add a mac/vlan filter to the VSI
1322 * @vsi: the VSI to be searched
1323 * @macaddr: the MAC address
1325 * @is_vf: make sure its a VF filter, else doesn't matter
1326 * @is_netdev: make sure its a netdev filter, else doesn't matter
1328 * Returns ptr to the filter object or NULL when no memory available.
1330 * NOTE: This function is expected to be called with mac_filter_list_lock
1333 struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
1334 u8 *macaddr, s16 vlan,
1335 bool is_vf, bool is_netdev)
1337 struct i40e_mac_filter *f;
1339 if (!vsi || !macaddr)
1342 f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
1344 f = kzalloc(sizeof(*f), GFP_ATOMIC);
1346 goto add_filter_out;
1348 ether_addr_copy(f->macaddr, macaddr);
1352 INIT_LIST_HEAD(&f->list);
1353 list_add_tail(&f->list, &vsi->mac_filter_list);
1356 /* increment counter and add a new flag if needed */
1362 } else if (is_netdev) {
1363 if (!f->is_netdev) {
1364 f->is_netdev = true;
1371 /* changed tells sync_filters_subtask to
1372 * push the filter down to the firmware
1375 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1376 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1384 * i40e_del_filter - Remove a mac/vlan filter from the VSI
1385 * @vsi: the VSI to be searched
1386 * @macaddr: the MAC address
1388 * @is_vf: make sure it's a VF filter, else doesn't matter
1389 * @is_netdev: make sure it's a netdev filter, else doesn't matter
1391 * NOTE: This function is expected to be called with mac_filter_list_lock
1394 void i40e_del_filter(struct i40e_vsi *vsi,
1395 u8 *macaddr, s16 vlan,
1396 bool is_vf, bool is_netdev)
1398 struct i40e_mac_filter *f;
1400 if (!vsi || !macaddr)
1403 f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
1404 if (!f || f->counter == 0)
1412 } else if (is_netdev) {
1414 f->is_netdev = false;
1418 /* make sure we don't remove a filter in use by VF or netdev */
1421 min_f += (f->is_vf ? 1 : 0);
1422 min_f += (f->is_netdev ? 1 : 0);
1424 if (f->counter > min_f)
1428 /* counter == 0 tells sync_filters_subtask to
1429 * remove the filter from the firmware's list
1431 if (f->counter == 0) {
1433 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1434 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1439 * i40e_set_mac - NDO callback to set mac address
1440 * @netdev: network interface device structure
1441 * @p: pointer to an address structure
1443 * Returns 0 on success, negative on failure
1446 int i40e_set_mac(struct net_device *netdev, void *p)
1448 static int i40e_set_mac(struct net_device *netdev, void *p)
1451 struct i40e_netdev_priv *np = netdev_priv(netdev);
1452 struct i40e_vsi *vsi = np->vsi;
1453 struct i40e_pf *pf = vsi->back;
1454 struct i40e_hw *hw = &pf->hw;
1455 struct sockaddr *addr = p;
1456 struct i40e_mac_filter *f;
1458 if (!is_valid_ether_addr(addr->sa_data))
1459 return -EADDRNOTAVAIL;
1461 if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
1462 netdev_info(netdev, "already using mac address %pM\n",
1467 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
1468 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
1469 return -EADDRNOTAVAIL;
1471 if (ether_addr_equal(hw->mac.addr, addr->sa_data))
1472 netdev_info(netdev, "returning to hw mac address %pM\n",
1475 netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
1477 if (vsi->type == I40E_VSI_MAIN) {
1480 ret = i40e_aq_mac_address_write(&vsi->back->hw,
1481 I40E_AQC_WRITE_TYPE_LAA_WOL,
1482 addr->sa_data, NULL);
1485 "Addr change for Main VSI failed: %d\n",
1487 return -EADDRNOTAVAIL;
1491 if (ether_addr_equal(netdev->dev_addr, hw->mac.addr)) {
1492 struct i40e_aqc_remove_macvlan_element_data element;
1494 memset(&element, 0, sizeof(element));
1495 ether_addr_copy(element.mac_addr, netdev->dev_addr);
1496 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
1497 i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1499 spin_lock_bh(&vsi->mac_filter_list_lock);
1500 i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
1502 spin_unlock_bh(&vsi->mac_filter_list_lock);
1505 if (ether_addr_equal(addr->sa_data, hw->mac.addr)) {
1506 struct i40e_aqc_add_macvlan_element_data element;
1508 memset(&element, 0, sizeof(element));
1509 ether_addr_copy(element.mac_addr, hw->mac.addr);
1510 element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH);
1511 i40e_aq_add_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1513 spin_lock_bh(&vsi->mac_filter_list_lock);
1514 f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY,
1518 spin_unlock_bh(&vsi->mac_filter_list_lock);
1521 ether_addr_copy(netdev->dev_addr, addr->sa_data);
1523 /* schedule our worker thread which will take care of
1524 * applying the new filter changes
1526 i40e_service_event_schedule(vsi->back);
1531 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1532 * @vsi: the VSI being setup
1533 * @ctxt: VSI context structure
1534 * @enabled_tc: Enabled TCs bitmap
1535 * @is_add: True if called before Add VSI
1537 * Setup VSI queue mapping for enabled traffic classes.
1540 void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
1541 struct i40e_vsi_context *ctxt,
1545 static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
1546 struct i40e_vsi_context *ctxt,
1551 struct i40e_pf *pf = vsi->back;
1561 sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
1564 if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
1565 /* Find numtc from enabled TC bitmap */
1566 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1567 if (enabled_tc & BIT(i)) /* TC is enabled */
1571 dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
1575 /* At least TC0 is enabled in case of non-DCB case */
1579 vsi->tc_config.numtc = numtc;
1580 vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
1581 /* Number of queues per enabled TC */
1582 qcount = vsi->alloc_queue_pairs;
1584 num_tc_qps = qcount / numtc;
1585 num_tc_qps = min_t(int, num_tc_qps, i40e_pf_get_max_q_per_tc(pf));
1587 /* Setup queue offset/count for all TCs for given VSI */
1588 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1589 /* See if the given TC is enabled for the given VSI */
1590 if (vsi->tc_config.enabled_tc & BIT(i)) {
1594 switch (vsi->type) {
1596 qcount = min_t(int, pf->alloc_rss_size,
1601 qcount = num_tc_qps;
1605 case I40E_VSI_SRIOV:
1606 case I40E_VSI_VMDQ2:
1608 qcount = num_tc_qps;
1612 vsi->tc_config.tc_info[i].qoffset = offset;
1613 vsi->tc_config.tc_info[i].qcount = qcount;
1615 /* find the next higher power-of-2 of num queue pairs */
1618 while (num_qps && (BIT_ULL(pow) < qcount)) {
1623 vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
1625 (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
1626 (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
1630 /* TC is not enabled so set the offset to
1631 * default queue and allocate one queue
1634 vsi->tc_config.tc_info[i].qoffset = 0;
1635 vsi->tc_config.tc_info[i].qcount = 1;
1636 vsi->tc_config.tc_info[i].netdev_tc = 0;
1640 ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
1643 /* Set actual Tx/Rx queue pairs */
1644 vsi->num_queue_pairs = offset;
1645 if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
1646 if (vsi->req_queue_pairs > 0)
1647 vsi->num_queue_pairs = vsi->req_queue_pairs;
1648 else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
1649 vsi->num_queue_pairs = pf->num_lan_msix;
1652 /* Scheduler section valid can only be set for ADD VSI */
1654 sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
1656 ctxt->info.up_enable_bits = enabled_tc;
1658 if (vsi->type == I40E_VSI_SRIOV) {
1659 ctxt->info.mapping_flags |=
1660 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
1661 for (i = 0; i < vsi->num_queue_pairs; i++)
1662 ctxt->info.queue_mapping[i] =
1663 cpu_to_le16(vsi->base_queue + i);
1665 ctxt->info.mapping_flags |=
1666 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
1667 ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
1669 ctxt->info.valid_sections |= cpu_to_le16(sections);
1673 * i40e_set_rx_mode - NDO callback to set the netdev filters
1674 * @netdev: network interface device structure
1677 void i40e_set_rx_mode(struct net_device *netdev)
1679 static void i40e_set_rx_mode(struct net_device *netdev)
1682 struct i40e_netdev_priv *np = netdev_priv(netdev);
1683 struct i40e_mac_filter *f, *ftmp;
1684 struct i40e_vsi *vsi = np->vsi;
1685 struct netdev_hw_addr *uca;
1686 struct netdev_hw_addr *mca;
1687 struct netdev_hw_addr *ha;
1689 spin_lock_bh(&vsi->mac_filter_list_lock);
1691 /* add addr if not already in the filter list */
1692 netdev_for_each_uc_addr(uca, netdev) {
1693 if (!i40e_find_mac(vsi, uca->addr, false, true)) {
1694 if (i40e_is_vsi_in_vlan(vsi))
1695 i40e_put_mac_in_vlan(vsi, uca->addr,
1698 i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY,
1703 netdev_for_each_mc_addr(mca, netdev) {
1704 if (!i40e_find_mac(vsi, mca->addr, false, true)) {
1705 if (i40e_is_vsi_in_vlan(vsi))
1706 i40e_put_mac_in_vlan(vsi, mca->addr,
1709 i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY,
1714 /* remove filter if not in netdev list */
1715 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1720 netdev_for_each_mc_addr(mca, netdev)
1721 if (ether_addr_equal(mca->addr, f->macaddr))
1722 goto bottom_of_search_loop;
1724 netdev_for_each_uc_addr(uca, netdev)
1725 if (ether_addr_equal(uca->addr, f->macaddr))
1726 goto bottom_of_search_loop;
1728 for_each_dev_addr(netdev, ha)
1729 if (ether_addr_equal(ha->addr, f->macaddr))
1730 goto bottom_of_search_loop;
1732 /* f->macaddr wasn't found in uc, mc, or ha list so delete it */
1733 i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, false, true);
1735 bottom_of_search_loop:
1738 spin_unlock_bh(&vsi->mac_filter_list_lock);
1740 /* check for other flag changes */
1741 if (vsi->current_netdev_flags != vsi->netdev->flags) {
1742 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1743 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1746 /* schedule our worker thread which will take care of
1747 * applying the new filter changes
1749 i40e_service_event_schedule(vsi->back);
1753 * i40e_mac_filter_entry_clone - Clones a MAC filter entry
1754 * @src: source MAC filter entry to be clones
1756 * Returns the pointer to newly cloned MAC filter entry or NULL
1759 static struct i40e_mac_filter *i40e_mac_filter_entry_clone(
1760 struct i40e_mac_filter *src)
1762 struct i40e_mac_filter *f;
1764 f = kzalloc(sizeof(*f), GFP_ATOMIC);
1769 INIT_LIST_HEAD(&f->list);
1775 * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
1776 * @vsi: pointer to vsi struct
1777 * @from: Pointer to list which contains MAC filter entries - changes to
1778 * those entries needs to be undone.
1780 * MAC filter entries from list were slated to be removed from device.
1782 static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi,
1783 struct list_head *from)
1785 struct i40e_mac_filter *f, *ftmp;
1787 list_for_each_entry_safe(f, ftmp, from, list) {
1789 /* Move the element back into MAC filter list*/
1790 list_move_tail(&f->list, &vsi->mac_filter_list);
1795 * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries
1796 * @vsi: pointer to vsi struct
1798 * MAC filter entries from list were slated to be added from device.
1800 static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi)
1802 struct i40e_mac_filter *f, *ftmp;
1804 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1805 if (!f->changed && f->counter)
1811 * i40e_cleanup_add_list - Deletes the element from add list and release
1813 * @add_list: Pointer to list which contains MAC filter entries
1815 static void i40e_cleanup_add_list(struct list_head *add_list)
1817 struct i40e_mac_filter *f, *ftmp;
1819 list_for_each_entry_safe(f, ftmp, add_list, list) {
1826 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
1827 * @vsi: ptr to the VSI
1829 * Push any outstanding VSI filter changes through the AdminQ.
1831 * Returns 0 or error value
1833 int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
1835 struct list_head tmp_del_list, tmp_add_list;
1836 struct i40e_mac_filter *f, *ftmp, *fclone;
1837 struct i40e_hw *hw = &vsi->back->hw;
1838 bool promisc_forced_on = false;
1839 bool add_happened = false;
1840 char vsi_name[16] = "PF";
1841 int filter_list_len = 0;
1842 u32 changed_flags = 0;
1843 i40e_status aq_ret = 0;
1844 bool err_cond = false;
1852 /* empty array typed pointers, kcalloc later */
1853 struct i40e_aqc_add_macvlan_element_data *add_list;
1854 struct i40e_aqc_remove_macvlan_element_data *del_list;
1856 while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state))
1857 usleep_range(1000, 2000);
1861 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
1862 vsi->current_netdev_flags = vsi->netdev->flags;
1865 INIT_LIST_HEAD(&tmp_del_list);
1866 INIT_LIST_HEAD(&tmp_add_list);
1868 if (vsi->type == I40E_VSI_SRIOV)
1869 snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id);
1870 else if (vsi->type != I40E_VSI_MAIN)
1871 snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid);
1873 if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
1874 vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
1876 spin_lock_bh(&vsi->mac_filter_list_lock);
1877 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1881 if (f->counter != 0)
1885 /* Move the element into temporary del_list */
1886 list_move_tail(&f->list, &tmp_del_list);
1889 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1893 if (f->counter == 0)
1897 /* Clone MAC filter entry and add into temporary list */
1898 fclone = i40e_mac_filter_entry_clone(f);
1903 list_add_tail(&fclone->list, &tmp_add_list);
1906 /* if failed to clone MAC filter entry - undo */
1908 i40e_undo_del_filter_entries(vsi, &tmp_del_list);
1909 i40e_undo_add_filter_entries(vsi);
1911 spin_unlock_bh(&vsi->mac_filter_list_lock);
1914 i40e_cleanup_add_list(&tmp_add_list);
1920 /* Now process 'del_list' outside the lock */
1921 if (!list_empty(&tmp_del_list)) {
1924 filter_list_len = hw->aq.asq_buf_size /
1925 sizeof(struct i40e_aqc_remove_macvlan_element_data);
1926 del_list_size = filter_list_len *
1927 sizeof(struct i40e_aqc_remove_macvlan_element_data);
1928 del_list = kzalloc(del_list_size, GFP_ATOMIC);
1930 i40e_cleanup_add_list(&tmp_add_list);
1932 /* Undo VSI's MAC filter entry element updates */
1933 spin_lock_bh(&vsi->mac_filter_list_lock);
1934 i40e_undo_del_filter_entries(vsi, &tmp_del_list);
1935 i40e_undo_add_filter_entries(vsi);
1936 spin_unlock_bh(&vsi->mac_filter_list_lock);
1941 list_for_each_entry_safe(f, ftmp, &tmp_del_list, list) {
1944 /* add to delete list */
1945 ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
1946 del_list[num_del].vlan_tag =
1947 cpu_to_le16((u16)(f->vlan ==
1948 I40E_VLAN_ANY ? 0 : f->vlan));
1950 cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
1951 del_list[num_del].flags = cmd_flags;
1954 /* flush a full buffer */
1955 if (num_del == filter_list_len) {
1957 i40e_aq_remove_macvlan(hw, vsi->seid,
1960 aq_err = hw->aq.asq_last_status;
1962 memset(del_list, 0, del_list_size);
1964 if (aq_ret && aq_err != I40E_AQ_RC_ENOENT) {
1966 dev_err(&pf->pdev->dev,
1967 "ignoring delete macvlan error on %s, err %s, aq_err %s while flushing a full buffer\n",
1969 i40e_stat_str(hw, aq_ret),
1970 i40e_aq_str(hw, aq_err));
1973 /* Release memory for MAC filter entries which were
1974 * synced up with HW.
1981 aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, del_list,
1983 aq_err = hw->aq.asq_last_status;
1986 if (aq_ret && aq_err != I40E_AQ_RC_ENOENT)
1987 dev_info(&pf->pdev->dev,
1988 "ignoring delete macvlan error on %s, err %s aq_err %s\n",
1990 i40e_stat_str(hw, aq_ret),
1991 i40e_aq_str(hw, aq_err));
1998 if (!list_empty(&tmp_add_list)) {
2001 /* do all the adds now */
2002 filter_list_len = hw->aq.asq_buf_size /
2003 sizeof(struct i40e_aqc_add_macvlan_element_data),
2004 add_list_size = filter_list_len *
2005 sizeof(struct i40e_aqc_add_macvlan_element_data);
2006 add_list = kzalloc(add_list_size, GFP_ATOMIC);
2008 /* Purge element from temporary lists */
2009 i40e_cleanup_add_list(&tmp_add_list);
2011 /* Undo add filter entries from VSI MAC filter list */
2012 spin_lock_bh(&vsi->mac_filter_list_lock);
2013 i40e_undo_add_filter_entries(vsi);
2014 spin_unlock_bh(&vsi->mac_filter_list_lock);
2019 list_for_each_entry_safe(f, ftmp, &tmp_add_list, list) {
2021 add_happened = true;
2024 /* add to add array */
2025 ether_addr_copy(add_list[num_add].mac_addr, f->macaddr);
2026 add_list[num_add].vlan_tag =
2028 (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan));
2029 add_list[num_add].queue_number = 0;
2031 cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
2032 add_list[num_add].flags = cpu_to_le16(cmd_flags);
2035 /* flush a full buffer */
2036 if (num_add == filter_list_len) {
2037 aq_ret = i40e_aq_add_macvlan(hw, vsi->seid,
2040 aq_err = hw->aq.asq_last_status;
2045 memset(add_list, 0, add_list_size);
2047 /* Entries from tmp_add_list were cloned from MAC
2048 * filter list, hence clean those cloned entries
2055 aq_ret = i40e_aq_add_macvlan(hw, vsi->seid,
2056 add_list, num_add, NULL);
2057 aq_err = hw->aq.asq_last_status;
2063 if (add_happened && aq_ret && aq_err != I40E_AQ_RC_EINVAL) {
2064 retval = i40e_aq_rc_to_posix(aq_ret, aq_err);
2065 dev_info(&pf->pdev->dev,
2066 "add filter failed on %s, err %s aq_err %s\n",
2068 i40e_stat_str(hw, aq_ret),
2069 i40e_aq_str(hw, aq_err));
2070 if ((hw->aq.asq_last_status == I40E_AQ_RC_ENOSPC) &&
2071 !test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
2073 promisc_forced_on = true;
2074 set_bit(__I40E_FILTER_OVERFLOW_PROMISC,
2076 dev_info(&pf->pdev->dev, "promiscuous mode forced on %s\n",
2082 /* if the VF is not trusted do not do promisc */
2083 if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) {
2084 clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
2088 /* check for changes in promiscuous modes */
2089 if (changed_flags & IFF_ALLMULTI) {
2090 bool cur_multipromisc;
2092 cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
2093 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
2098 retval = i40e_aq_rc_to_posix(aq_ret,
2099 hw->aq.asq_last_status);
2100 dev_info(&pf->pdev->dev,
2101 "set multi promisc failed on %s, err %s aq_err %s\n",
2103 i40e_stat_str(hw, aq_ret),
2104 i40e_aq_str(hw, hw->aq.asq_last_status));
2107 if ((changed_flags & IFF_PROMISC) || promisc_forced_on) {
2110 cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
2111 test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
2113 if ((vsi->type == I40E_VSI_MAIN) &&
2114 (pf->lan_veb != I40E_NO_VEB) &&
2115 !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
2116 /* set defport ON for Main VSI instead of true promisc
2117 * this way we will get all unicast/multicast and VLAN
2118 * promisc behavior but will not get VF or VMDq traffic
2119 * replicated on the Main VSI.
2121 if (pf->cur_promisc != cur_promisc) {
2122 pf->cur_promisc = cur_promisc;
2125 i40e_aq_set_default_vsi(hw,
2130 i40e_aq_clear_default_vsi(hw,
2134 retval = i40e_aq_rc_to_posix(aq_ret,
2135 hw->aq.asq_last_status);
2136 dev_info(&pf->pdev->dev,
2137 "Set default VSI failed on %s, err %s, aq_err %s\n",
2139 i40e_stat_str(hw, aq_ret),
2141 hw->aq.asq_last_status));
2145 aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
2152 i40e_aq_rc_to_posix(aq_ret,
2153 hw->aq.asq_last_status);
2154 dev_info(&pf->pdev->dev,
2155 "set unicast promisc failed on %s, err %s, aq_err %s\n",
2157 i40e_stat_str(hw, aq_ret),
2159 hw->aq.asq_last_status));
2161 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
2167 i40e_aq_rc_to_posix(aq_ret,
2168 hw->aq.asq_last_status);
2169 dev_info(&pf->pdev->dev,
2170 "set multicast promisc failed on %s, err %s, aq_err %s\n",
2172 i40e_stat_str(hw, aq_ret),
2174 hw->aq.asq_last_status));
2177 aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
2181 retval = i40e_aq_rc_to_posix(aq_ret,
2182 pf->hw.aq.asq_last_status);
2183 dev_info(&pf->pdev->dev,
2184 "set brdcast promisc failed, err %s, aq_err %s\n",
2185 i40e_stat_str(hw, aq_ret),
2187 hw->aq.asq_last_status));
2191 /* if something went wrong then set the changed flag so we try again */
2193 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
2195 clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
2200 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
2201 * @pf: board private structure
2203 static void i40e_sync_filters_subtask(struct i40e_pf *pf)
2207 if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
2209 pf->flags &= ~I40E_FLAG_FILTER_SYNC;
2211 for (v = 0; v < pf->num_alloc_vsi; v++) {
2213 (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
2214 int ret = i40e_sync_vsi_filters(pf->vsi[v]);
2217 /* come back and try again later */
2218 pf->flags |= I40E_FLAG_FILTER_SYNC;
2226 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
2227 * @netdev: network interface device structure
2228 * @new_mtu: new value for maximum frame size
2230 * Returns 0 on success, negative on failure
2232 static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
2234 struct i40e_netdev_priv *np = netdev_priv(netdev);
2235 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
2236 struct i40e_vsi *vsi = np->vsi;
2238 /* MTU < 68 is an error and causes problems on some kernels */
2239 if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
2242 netdev_info(netdev, "changing MTU from %d to %d\n",
2243 netdev->mtu, new_mtu);
2244 netdev->mtu = new_mtu;
2245 if (netif_running(netdev))
2246 i40e_vsi_reinit_locked(vsi);
2247 i40e_notify_client_of_l2_param_changes(vsi);
2252 * i40e_ioctl - Access the hwtstamp interface
2253 * @netdev: network interface device structure
2254 * @ifr: interface request data
2255 * @cmd: ioctl command
2257 int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2259 struct i40e_netdev_priv *np = netdev_priv(netdev);
2260 struct i40e_pf *pf = np->vsi->back;
2264 return i40e_ptp_get_ts_config(pf, ifr);
2266 return i40e_ptp_set_ts_config(pf, ifr);
2273 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
2274 * @vsi: the vsi being adjusted
2276 void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
2278 struct i40e_vsi_context ctxt;
2281 if ((vsi->info.valid_sections &
2282 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2283 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
2284 return; /* already enabled */
2286 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2287 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2288 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
2290 ctxt.seid = vsi->seid;
2291 ctxt.info = vsi->info;
2292 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2294 dev_info(&vsi->back->pdev->dev,
2295 "update vlan stripping failed, err %s aq_err %s\n",
2296 i40e_stat_str(&vsi->back->hw, ret),
2297 i40e_aq_str(&vsi->back->hw,
2298 vsi->back->hw.aq.asq_last_status));
2303 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2304 * @vsi: the vsi being adjusted
2306 void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
2308 struct i40e_vsi_context ctxt;
2311 if ((vsi->info.valid_sections &
2312 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2313 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
2314 I40E_AQ_VSI_PVLAN_EMOD_MASK))
2315 return; /* already disabled */
2317 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2318 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2319 I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
2321 ctxt.seid = vsi->seid;
2322 ctxt.info = vsi->info;
2323 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2325 dev_info(&vsi->back->pdev->dev,
2326 "update vlan stripping failed, err %s aq_err %s\n",
2327 i40e_stat_str(&vsi->back->hw, ret),
2328 i40e_aq_str(&vsi->back->hw,
2329 vsi->back->hw.aq.asq_last_status));
2334 * i40e_vlan_rx_register - Setup or shutdown vlan offload
2335 * @netdev: network interface to be adjusted
2336 * @features: netdev features to test if VLAN offload is enabled or not
2338 static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
2340 struct i40e_netdev_priv *np = netdev_priv(netdev);
2341 struct i40e_vsi *vsi = np->vsi;
2343 if (features & NETIF_F_HW_VLAN_CTAG_RX)
2344 i40e_vlan_stripping_enable(vsi);
2346 i40e_vlan_stripping_disable(vsi);
2350 * i40e_vsi_add_vlan - Add vsi membership for given vlan
2351 * @vsi: the vsi being configured
2352 * @vid: vlan id to be added (0 = untagged only , -1 = any)
2354 int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid)
2356 struct i40e_mac_filter *f, *add_f;
2357 bool is_netdev, is_vf;
2359 is_vf = (vsi->type == I40E_VSI_SRIOV);
2360 is_netdev = !!(vsi->netdev);
2362 /* Locked once because all functions invoked below iterates list*/
2363 spin_lock_bh(&vsi->mac_filter_list_lock);
2366 add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid,
2369 dev_info(&vsi->back->pdev->dev,
2370 "Could not add vlan filter %d for %pM\n",
2371 vid, vsi->netdev->dev_addr);
2372 spin_unlock_bh(&vsi->mac_filter_list_lock);
2377 list_for_each_entry(f, &vsi->mac_filter_list, list) {
2378 add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
2380 dev_info(&vsi->back->pdev->dev,
2381 "Could not add vlan filter %d for %pM\n",
2383 spin_unlock_bh(&vsi->mac_filter_list_lock);
2388 /* Now if we add a vlan tag, make sure to check if it is the first
2389 * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
2390 * with 0, so we now accept untagged and specified tagged traffic
2391 * (and not any taged and untagged)
2394 if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr,
2396 is_vf, is_netdev)) {
2397 i40e_del_filter(vsi, vsi->netdev->dev_addr,
2398 I40E_VLAN_ANY, is_vf, is_netdev);
2399 add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0,
2402 dev_info(&vsi->back->pdev->dev,
2403 "Could not add filter 0 for %pM\n",
2404 vsi->netdev->dev_addr);
2405 spin_unlock_bh(&vsi->mac_filter_list_lock);
2411 /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
2412 if (vid > 0 && !vsi->info.pvid) {
2413 list_for_each_entry(f, &vsi->mac_filter_list, list) {
2414 if (!i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY,
2417 i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY,
2419 add_f = i40e_add_filter(vsi, f->macaddr,
2420 0, is_vf, is_netdev);
2422 dev_info(&vsi->back->pdev->dev,
2423 "Could not add filter 0 for %pM\n",
2425 spin_unlock_bh(&vsi->mac_filter_list_lock);
2431 spin_unlock_bh(&vsi->mac_filter_list_lock);
2433 /* schedule our worker thread which will take care of
2434 * applying the new filter changes
2436 i40e_service_event_schedule(vsi->back);
2441 * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
2442 * @vsi: the vsi being configured
2443 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
2445 * Return: 0 on success or negative otherwise
2447 int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid)
2449 struct net_device *netdev = vsi->netdev;
2450 struct i40e_mac_filter *f, *add_f;
2451 bool is_vf, is_netdev;
2452 int filter_count = 0;
2454 is_vf = (vsi->type == I40E_VSI_SRIOV);
2455 is_netdev = !!(netdev);
2457 /* Locked once because all functions invoked below iterates list */
2458 spin_lock_bh(&vsi->mac_filter_list_lock);
2461 i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev);
2463 list_for_each_entry(f, &vsi->mac_filter_list, list)
2464 i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
2466 /* go through all the filters for this VSI and if there is only
2467 * vid == 0 it means there are no other filters, so vid 0 must
2468 * be replaced with -1. This signifies that we should from now
2469 * on accept any traffic (with any tag present, or untagged)
2471 list_for_each_entry(f, &vsi->mac_filter_list, list) {
2474 ether_addr_equal(netdev->dev_addr, f->macaddr))
2482 if (!filter_count && is_netdev) {
2483 i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev);
2484 f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
2487 dev_info(&vsi->back->pdev->dev,
2488 "Could not add filter %d for %pM\n",
2489 I40E_VLAN_ANY, netdev->dev_addr);
2490 spin_unlock_bh(&vsi->mac_filter_list_lock);
2495 if (!filter_count) {
2496 list_for_each_entry(f, &vsi->mac_filter_list, list) {
2497 i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev);
2498 add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY,
2501 dev_info(&vsi->back->pdev->dev,
2502 "Could not add filter %d for %pM\n",
2503 I40E_VLAN_ANY, f->macaddr);
2504 spin_unlock_bh(&vsi->mac_filter_list_lock);
2510 spin_unlock_bh(&vsi->mac_filter_list_lock);
2512 /* schedule our worker thread which will take care of
2513 * applying the new filter changes
2515 i40e_service_event_schedule(vsi->back);
2520 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2521 * @netdev: network interface to be adjusted
2522 * @vid: vlan id to be added
2524 * net_device_ops implementation for adding vlan ids
2527 int i40e_vlan_rx_add_vid(struct net_device *netdev,
2528 __always_unused __be16 proto, u16 vid)
2530 static int i40e_vlan_rx_add_vid(struct net_device *netdev,
2531 __always_unused __be16 proto, u16 vid)
2534 struct i40e_netdev_priv *np = netdev_priv(netdev);
2535 struct i40e_vsi *vsi = np->vsi;
2541 netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid);
2543 /* If the network stack called us with vid = 0 then
2544 * it is asking to receive priority tagged packets with
2545 * vlan id 0. Our HW receives them by default when configured
2546 * to receive untagged packets so there is no need to add an
2547 * extra filter for vlan 0 tagged packets.
2550 ret = i40e_vsi_add_vlan(vsi, vid);
2552 if (!ret && (vid < VLAN_N_VID))
2553 set_bit(vid, vsi->active_vlans);
2559 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2560 * @netdev: network interface to be adjusted
2561 * @vid: vlan id to be removed
2563 * net_device_ops implementation for removing vlan ids
2566 int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2567 __always_unused __be16 proto, u16 vid)
2569 static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2570 __always_unused __be16 proto, u16 vid)
2573 struct i40e_netdev_priv *np = netdev_priv(netdev);
2574 struct i40e_vsi *vsi = np->vsi;
2576 netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid);
2578 /* return code is ignored as there is nothing a user
2579 * can do about failure to remove and a log message was
2580 * already printed from the other function
2582 i40e_vsi_kill_vlan(vsi, vid);
2584 clear_bit(vid, vsi->active_vlans);
2590 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2591 * @vsi: the vsi being brought back up
2593 static void i40e_restore_vlan(struct i40e_vsi *vsi)
2600 i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
2602 for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
2603 i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
2608 * i40e_vsi_add_pvid - Add pvid for the VSI
2609 * @vsi: the vsi being adjusted
2610 * @vid: the vlan id to set as a PVID
2612 int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
2614 struct i40e_vsi_context ctxt;
2617 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2618 vsi->info.pvid = cpu_to_le16(vid);
2619 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
2620 I40E_AQ_VSI_PVLAN_INSERT_PVID |
2621 I40E_AQ_VSI_PVLAN_EMOD_STR;
2623 ctxt.seid = vsi->seid;
2624 ctxt.info = vsi->info;
2625 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2627 dev_info(&vsi->back->pdev->dev,
2628 "add pvid failed, err %s aq_err %s\n",
2629 i40e_stat_str(&vsi->back->hw, ret),
2630 i40e_aq_str(&vsi->back->hw,
2631 vsi->back->hw.aq.asq_last_status));
2639 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2640 * @vsi: the vsi being adjusted
2642 * Just use the vlan_rx_register() service to put it back to normal
2644 void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
2646 i40e_vlan_stripping_disable(vsi);
2652 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2653 * @vsi: ptr to the VSI
2655 * If this function returns with an error, then it's possible one or
2656 * more of the rings is populated (while the rest are not). It is the
2657 * callers duty to clean those orphaned rings.
2659 * Return 0 on success, negative on failure
2661 static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
2665 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
2666 err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
2672 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2673 * @vsi: ptr to the VSI
2675 * Free VSI's transmit software resources
2677 static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
2684 for (i = 0; i < vsi->num_queue_pairs; i++)
2685 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
2686 i40e_free_tx_resources(vsi->tx_rings[i]);
2690 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2691 * @vsi: ptr to the VSI
2693 * If this function returns with an error, then it's possible one or
2694 * more of the rings is populated (while the rest are not). It is the
2695 * callers duty to clean those orphaned rings.
2697 * Return 0 on success, negative on failure
2699 static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
2703 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
2704 err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
2706 i40e_fcoe_setup_ddp_resources(vsi);
2712 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2713 * @vsi: ptr to the VSI
2715 * Free all receive software resources
2717 static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
2724 for (i = 0; i < vsi->num_queue_pairs; i++)
2725 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
2726 i40e_free_rx_resources(vsi->rx_rings[i]);
2728 i40e_fcoe_free_ddp_resources(vsi);
2733 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
2734 * @ring: The Tx ring to configure
2736 * This enables/disables XPS for a given Tx descriptor ring
2737 * based on the TCs enabled for the VSI that ring belongs to.
2739 static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
2741 struct i40e_vsi *vsi = ring->vsi;
2744 if (!ring->q_vector || !ring->netdev)
2747 /* Single TC mode enable XPS */
2748 if (vsi->tc_config.numtc <= 1) {
2749 if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
2750 netif_set_xps_queue(ring->netdev,
2751 &ring->q_vector->affinity_mask,
2753 } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) {
2754 /* Disable XPS to allow selection based on TC */
2755 bitmap_zero(cpumask_bits(mask), nr_cpumask_bits);
2756 netif_set_xps_queue(ring->netdev, mask, ring->queue_index);
2757 free_cpumask_var(mask);
2760 /* schedule our worker thread which will take care of
2761 * applying the new filter changes
2763 i40e_service_event_schedule(vsi->back);
2767 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2768 * @ring: The Tx ring to configure
2770 * Configure the Tx descriptor ring in the HMC context.
2772 static int i40e_configure_tx_ring(struct i40e_ring *ring)
2774 struct i40e_vsi *vsi = ring->vsi;
2775 u16 pf_q = vsi->base_queue + ring->queue_index;
2776 struct i40e_hw *hw = &vsi->back->hw;
2777 struct i40e_hmc_obj_txq tx_ctx;
2778 i40e_status err = 0;
2781 /* some ATR related tx ring init */
2782 if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
2783 ring->atr_sample_rate = vsi->back->atr_sample_rate;
2784 ring->atr_count = 0;
2786 ring->atr_sample_rate = 0;
2790 i40e_config_xps_tx_ring(ring);
2792 /* clear the context structure first */
2793 memset(&tx_ctx, 0, sizeof(tx_ctx));
2795 tx_ctx.new_context = 1;
2796 tx_ctx.base = (ring->dma / 128);
2797 tx_ctx.qlen = ring->count;
2798 tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
2799 I40E_FLAG_FD_ATR_ENABLED));
2801 tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
2803 tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
2804 /* FDIR VSI tx ring can still use RS bit and writebacks */
2805 if (vsi->type != I40E_VSI_FDIR)
2806 tx_ctx.head_wb_ena = 1;
2807 tx_ctx.head_wb_addr = ring->dma +
2808 (ring->count * sizeof(struct i40e_tx_desc));
2810 /* As part of VSI creation/update, FW allocates certain
2811 * Tx arbitration queue sets for each TC enabled for
2812 * the VSI. The FW returns the handles to these queue
2813 * sets as part of the response buffer to Add VSI,
2814 * Update VSI, etc. AQ commands. It is expected that
2815 * these queue set handles be associated with the Tx
2816 * queues by the driver as part of the TX queue context
2817 * initialization. This has to be done regardless of
2818 * DCB as by default everything is mapped to TC0.
2820 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
2821 tx_ctx.rdylist_act = 0;
2823 /* clear the context in the HMC */
2824 err = i40e_clear_lan_tx_queue_context(hw, pf_q);
2826 dev_info(&vsi->back->pdev->dev,
2827 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2828 ring->queue_index, pf_q, err);
2832 /* set the context in the HMC */
2833 err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
2835 dev_info(&vsi->back->pdev->dev,
2836 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
2837 ring->queue_index, pf_q, err);
2841 /* Now associate this queue with this PCI function */
2842 if (vsi->type == I40E_VSI_VMDQ2) {
2843 qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
2844 qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
2845 I40E_QTX_CTL_VFVM_INDX_MASK;
2847 qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
2850 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
2851 I40E_QTX_CTL_PF_INDX_MASK);
2852 wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
2855 /* cache tail off for easier writes later */
2856 ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
2862 * i40e_configure_rx_ring - Configure a receive ring context
2863 * @ring: The Rx ring to configure
2865 * Configure the Rx descriptor ring in the HMC context.
2867 static int i40e_configure_rx_ring(struct i40e_ring *ring)
2869 struct i40e_vsi *vsi = ring->vsi;
2870 u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
2871 u16 pf_q = vsi->base_queue + ring->queue_index;
2872 struct i40e_hw *hw = &vsi->back->hw;
2873 struct i40e_hmc_obj_rxq rx_ctx;
2874 i40e_status err = 0;
2878 /* clear the context structure first */
2879 memset(&rx_ctx, 0, sizeof(rx_ctx));
2881 ring->rx_buf_len = vsi->rx_buf_len;
2883 rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
2885 rx_ctx.base = (ring->dma / 128);
2886 rx_ctx.qlen = ring->count;
2888 /* use 32 byte descriptors */
2891 /* descriptor type is always zero
2894 rx_ctx.hsplit_0 = 0;
2896 rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len);
2897 if (hw->revision_id == 0)
2898 rx_ctx.lrxqthresh = 0;
2900 rx_ctx.lrxqthresh = 2;
2901 rx_ctx.crcstrip = 1;
2903 /* this controls whether VLAN is stripped from inner headers */
2906 rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
2908 /* set the prefena field to 1 because the manual says to */
2911 /* clear the context in the HMC */
2912 err = i40e_clear_lan_rx_queue_context(hw, pf_q);
2914 dev_info(&vsi->back->pdev->dev,
2915 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2916 ring->queue_index, pf_q, err);
2920 /* set the context in the HMC */
2921 err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
2923 dev_info(&vsi->back->pdev->dev,
2924 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2925 ring->queue_index, pf_q, err);
2929 /* cache tail for quicker writes, and clear the reg before use */
2930 ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
2931 writel(0, ring->tail);
2933 i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
2939 * i40e_vsi_configure_tx - Configure the VSI for Tx
2940 * @vsi: VSI structure describing this set of rings and resources
2942 * Configure the Tx VSI for operation.
2944 static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
2949 for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
2950 err = i40e_configure_tx_ring(vsi->tx_rings[i]);
2956 * i40e_vsi_configure_rx - Configure the VSI for Rx
2957 * @vsi: the VSI being configured
2959 * Configure the Rx VSI for operation.
2961 static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
2966 if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN))
2967 vsi->max_frame = vsi->netdev->mtu + ETH_HLEN
2968 + ETH_FCS_LEN + VLAN_HLEN;
2970 vsi->max_frame = I40E_RXBUFFER_2048;
2972 vsi->rx_buf_len = I40E_RXBUFFER_2048;
2975 /* setup rx buffer for FCoE */
2976 if ((vsi->type == I40E_VSI_FCOE) &&
2977 (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) {
2978 vsi->rx_buf_len = I40E_RXBUFFER_3072;
2979 vsi->max_frame = I40E_RXBUFFER_3072;
2982 #endif /* I40E_FCOE */
2983 /* round up for the chip's needs */
2984 vsi->rx_buf_len = ALIGN(vsi->rx_buf_len,
2985 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
2987 /* set up individual rings */
2988 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
2989 err = i40e_configure_rx_ring(vsi->rx_rings[i]);
2995 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
2996 * @vsi: ptr to the VSI
2998 static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
3000 struct i40e_ring *tx_ring, *rx_ring;
3001 u16 qoffset, qcount;
3004 if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
3005 /* Reset the TC information */
3006 for (i = 0; i < vsi->num_queue_pairs; i++) {
3007 rx_ring = vsi->rx_rings[i];
3008 tx_ring = vsi->tx_rings[i];
3009 rx_ring->dcb_tc = 0;
3010 tx_ring->dcb_tc = 0;
3014 for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
3015 if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
3018 qoffset = vsi->tc_config.tc_info[n].qoffset;
3019 qcount = vsi->tc_config.tc_info[n].qcount;
3020 for (i = qoffset; i < (qoffset + qcount); i++) {
3021 rx_ring = vsi->rx_rings[i];
3022 tx_ring = vsi->tx_rings[i];
3023 rx_ring->dcb_tc = n;
3024 tx_ring->dcb_tc = n;
3030 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
3031 * @vsi: ptr to the VSI
3033 static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
3036 i40e_set_rx_mode(vsi->netdev);
3040 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
3041 * @vsi: Pointer to the targeted VSI
3043 * This function replays the hlist on the hw where all the SB Flow Director
3044 * filters were saved.
3046 static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
3048 struct i40e_fdir_filter *filter;
3049 struct i40e_pf *pf = vsi->back;
3050 struct hlist_node *node;
3052 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3055 hlist_for_each_entry_safe(filter, node,
3056 &pf->fdir_filter_list, fdir_node) {
3057 i40e_add_del_fdir(vsi, filter, true);
3062 * i40e_vsi_configure - Set up the VSI for action
3063 * @vsi: the VSI being configured
3065 static int i40e_vsi_configure(struct i40e_vsi *vsi)
3069 i40e_set_vsi_rx_mode(vsi);
3070 i40e_restore_vlan(vsi);
3071 i40e_vsi_config_dcb_rings(vsi);
3072 err = i40e_vsi_configure_tx(vsi);
3074 err = i40e_vsi_configure_rx(vsi);
3080 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
3081 * @vsi: the VSI being configured
3083 static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
3085 struct i40e_pf *pf = vsi->back;
3086 struct i40e_hw *hw = &pf->hw;
3091 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
3092 * and PFINT_LNKLSTn registers, e.g.:
3093 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
3095 qp = vsi->base_queue;
3096 vector = vsi->base_vector;
3097 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
3098 struct i40e_q_vector *q_vector = vsi->q_vectors[i];
3100 q_vector->itr_countdown = ITR_COUNTDOWN_START;
3101 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[i]->rx_itr_setting);
3102 q_vector->rx.latency_range = I40E_LOW_LATENCY;
3103 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
3105 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[i]->tx_itr_setting);
3106 q_vector->tx.latency_range = I40E_LOW_LATENCY;
3107 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
3109 wr32(hw, I40E_PFINT_RATEN(vector - 1),
3110 INTRL_USEC_TO_REG(vsi->int_rate_limit));
3112 /* Linked list for the queuepairs assigned to this vector */
3113 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
3114 for (q = 0; q < q_vector->num_ringpairs; q++) {
3117 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3118 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3119 (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
3120 (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
3122 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
3124 wr32(hw, I40E_QINT_RQCTL(qp), val);
3126 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3127 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3128 (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
3129 ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)|
3131 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3133 /* Terminate the linked list */
3134 if (q == (q_vector->num_ringpairs - 1))
3135 val |= (I40E_QUEUE_END_OF_LIST
3136 << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3138 wr32(hw, I40E_QINT_TQCTL(qp), val);
3147 * i40e_enable_misc_int_causes - enable the non-queue interrupts
3148 * @hw: ptr to the hardware info
3150 static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
3152 struct i40e_hw *hw = &pf->hw;
3155 /* clear things first */
3156 wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
3157 rd32(hw, I40E_PFINT_ICR0); /* read to clear */
3159 val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
3160 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
3161 I40E_PFINT_ICR0_ENA_GRST_MASK |
3162 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
3163 I40E_PFINT_ICR0_ENA_GPIO_MASK |
3164 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
3165 I40E_PFINT_ICR0_ENA_VFLR_MASK |
3166 I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
3168 if (pf->flags & I40E_FLAG_IWARP_ENABLED)
3169 val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3171 if (pf->flags & I40E_FLAG_PTP)
3172 val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
3174 wr32(hw, I40E_PFINT_ICR0_ENA, val);
3176 /* SW_ITR_IDX = 0, but don't change INTENA */
3177 wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
3178 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
3180 /* OTHER_ITR_IDX = 0 */
3181 wr32(hw, I40E_PFINT_STAT_CTL0, 0);
3185 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
3186 * @vsi: the VSI being configured
3188 static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
3190 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
3191 struct i40e_pf *pf = vsi->back;
3192 struct i40e_hw *hw = &pf->hw;
3195 /* set the ITR configuration */
3196 q_vector->itr_countdown = ITR_COUNTDOWN_START;
3197 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[0]->rx_itr_setting);
3198 q_vector->rx.latency_range = I40E_LOW_LATENCY;
3199 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
3200 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[0]->tx_itr_setting);
3201 q_vector->tx.latency_range = I40E_LOW_LATENCY;
3202 wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
3204 i40e_enable_misc_int_causes(pf);
3206 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
3207 wr32(hw, I40E_PFINT_LNKLST0, 0);
3209 /* Associate the queue pair to the vector and enable the queue int */
3210 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3211 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3212 (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3214 wr32(hw, I40E_QINT_RQCTL(0), val);
3216 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3217 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3218 (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3220 wr32(hw, I40E_QINT_TQCTL(0), val);
3225 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
3226 * @pf: board private structure
3228 void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
3230 struct i40e_hw *hw = &pf->hw;
3232 wr32(hw, I40E_PFINT_DYN_CTL0,
3233 I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
3238 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
3239 * @pf: board private structure
3240 * @clearpba: true when all pending interrupt events should be cleared
3242 void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba)
3244 struct i40e_hw *hw = &pf->hw;
3247 val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
3248 (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) |
3249 (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
3251 wr32(hw, I40E_PFINT_DYN_CTL0, val);
3256 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
3257 * @irq: interrupt number
3258 * @data: pointer to a q_vector
3260 static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
3262 struct i40e_q_vector *q_vector = data;
3264 if (!q_vector->tx.ring && !q_vector->rx.ring)
3267 napi_schedule_irqoff(&q_vector->napi);
3273 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3274 * @vsi: the VSI being configured
3275 * @basename: name for the vector
3277 * Allocates MSI-X vectors and requests interrupts from the kernel.
3279 static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
3281 int q_vectors = vsi->num_q_vectors;
3282 struct i40e_pf *pf = vsi->back;
3283 int base = vsi->base_vector;
3288 for (vector = 0; vector < q_vectors; vector++) {
3289 struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
3291 if (q_vector->tx.ring && q_vector->rx.ring) {
3292 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3293 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
3295 } else if (q_vector->rx.ring) {
3296 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3297 "%s-%s-%d", basename, "rx", rx_int_idx++);
3298 } else if (q_vector->tx.ring) {
3299 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3300 "%s-%s-%d", basename, "tx", tx_int_idx++);
3302 /* skip this unused q_vector */
3305 err = request_irq(pf->msix_entries[base + vector].vector,
3311 dev_info(&pf->pdev->dev,
3312 "MSIX request_irq failed, error: %d\n", err);
3313 goto free_queue_irqs;
3315 /* assign the mask for this irq */
3316 irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
3317 &q_vector->affinity_mask);
3320 vsi->irqs_ready = true;
3326 irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
3328 free_irq(pf->msix_entries[base + vector].vector,
3329 &(vsi->q_vectors[vector]));
3335 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3336 * @vsi: the VSI being un-configured
3338 static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
3340 struct i40e_pf *pf = vsi->back;
3341 struct i40e_hw *hw = &pf->hw;
3342 int base = vsi->base_vector;
3345 for (i = 0; i < vsi->num_queue_pairs; i++) {
3346 wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
3347 wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
3350 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3351 for (i = vsi->base_vector;
3352 i < (vsi->num_q_vectors + vsi->base_vector); i++)
3353 wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
3356 for (i = 0; i < vsi->num_q_vectors; i++)
3357 synchronize_irq(pf->msix_entries[i + base].vector);
3359 /* Legacy and MSI mode - this stops all interrupt handling */
3360 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
3361 wr32(hw, I40E_PFINT_DYN_CTL0, 0);
3363 synchronize_irq(pf->pdev->irq);
3368 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3369 * @vsi: the VSI being configured
3371 static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
3373 struct i40e_pf *pf = vsi->back;
3376 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3377 for (i = 0; i < vsi->num_q_vectors; i++)
3378 i40e_irq_dynamic_enable(vsi, i);
3380 i40e_irq_dynamic_enable_icr0(pf, true);
3383 i40e_flush(&pf->hw);
3388 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
3389 * @pf: board private structure
3391 static void i40e_stop_misc_vector(struct i40e_pf *pf)
3394 wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
3395 i40e_flush(&pf->hw);
3399 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3400 * @irq: interrupt number
3401 * @data: pointer to a q_vector
3403 * This is the handler used for all MSI/Legacy interrupts, and deals
3404 * with both queue and non-queue interrupts. This is also used in
3405 * MSIX mode to handle the non-queue interrupts.
3407 static irqreturn_t i40e_intr(int irq, void *data)
3409 struct i40e_pf *pf = (struct i40e_pf *)data;
3410 struct i40e_hw *hw = &pf->hw;
3411 irqreturn_t ret = IRQ_NONE;
3412 u32 icr0, icr0_remaining;
3415 icr0 = rd32(hw, I40E_PFINT_ICR0);
3416 ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
3418 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
3419 if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
3422 /* if interrupt but no bits showing, must be SWINT */
3423 if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
3424 (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
3427 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
3428 (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
3429 ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3430 icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3431 dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n");
3434 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
3435 if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
3436 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
3437 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
3439 /* We do not have a way to disarm Queue causes while leaving
3440 * interrupt enabled for all other causes, ideally
3441 * interrupt should be disabled while we are in NAPI but
3442 * this is not a performance path and napi_schedule()
3443 * can deal with rescheduling.
3445 if (!test_bit(__I40E_DOWN, &pf->state))
3446 napi_schedule_irqoff(&q_vector->napi);
3449 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
3450 ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
3451 set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
3452 i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
3455 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
3456 ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
3457 set_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
3460 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
3461 ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
3462 set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
3465 if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
3466 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
3467 set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
3468 ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
3469 val = rd32(hw, I40E_GLGEN_RSTAT);
3470 val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
3471 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
3472 if (val == I40E_RESET_CORER) {
3474 } else if (val == I40E_RESET_GLOBR) {
3476 } else if (val == I40E_RESET_EMPR) {
3478 set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state);
3482 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
3483 icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
3484 dev_info(&pf->pdev->dev, "HMC error interrupt\n");
3485 dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
3486 rd32(hw, I40E_PFHMC_ERRORINFO),
3487 rd32(hw, I40E_PFHMC_ERRORDATA));
3490 if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
3491 u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
3493 if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
3494 icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
3495 i40e_ptp_tx_hwtstamp(pf);
3499 /* If a critical error is pending we have no choice but to reset the
3501 * Report and mask out any remaining unexpected interrupts.
3503 icr0_remaining = icr0 & ena_mask;
3504 if (icr0_remaining) {
3505 dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
3507 if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
3508 (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
3509 (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
3510 dev_info(&pf->pdev->dev, "device will be reset\n");
3511 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
3512 i40e_service_event_schedule(pf);
3514 ena_mask &= ~icr0_remaining;
3519 /* re-enable interrupt causes */
3520 wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
3521 if (!test_bit(__I40E_DOWN, &pf->state)) {
3522 i40e_service_event_schedule(pf);
3523 i40e_irq_dynamic_enable_icr0(pf, false);
3530 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3531 * @tx_ring: tx ring to clean
3532 * @budget: how many cleans we're allowed
3534 * Returns true if there's any budget left (e.g. the clean is finished)
3536 static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
3538 struct i40e_vsi *vsi = tx_ring->vsi;
3539 u16 i = tx_ring->next_to_clean;
3540 struct i40e_tx_buffer *tx_buf;
3541 struct i40e_tx_desc *tx_desc;
3543 tx_buf = &tx_ring->tx_bi[i];
3544 tx_desc = I40E_TX_DESC(tx_ring, i);
3545 i -= tx_ring->count;
3548 struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
3550 /* if next_to_watch is not set then there is no work pending */
3554 /* prevent any other reads prior to eop_desc */
3555 read_barrier_depends();
3557 /* if the descriptor isn't done, no work yet to do */
3558 if (!(eop_desc->cmd_type_offset_bsz &
3559 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
3562 /* clear next_to_watch to prevent false hangs */
3563 tx_buf->next_to_watch = NULL;
3565 tx_desc->buffer_addr = 0;
3566 tx_desc->cmd_type_offset_bsz = 0;
3567 /* move past filter desc */
3572 i -= tx_ring->count;
3573 tx_buf = tx_ring->tx_bi;
3574 tx_desc = I40E_TX_DESC(tx_ring, 0);
3576 /* unmap skb header data */
3577 dma_unmap_single(tx_ring->dev,
3578 dma_unmap_addr(tx_buf, dma),
3579 dma_unmap_len(tx_buf, len),
3581 if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
3582 kfree(tx_buf->raw_buf);
3584 tx_buf->raw_buf = NULL;
3585 tx_buf->tx_flags = 0;
3586 tx_buf->next_to_watch = NULL;
3587 dma_unmap_len_set(tx_buf, len, 0);
3588 tx_desc->buffer_addr = 0;
3589 tx_desc->cmd_type_offset_bsz = 0;
3591 /* move us past the eop_desc for start of next FD desc */
3596 i -= tx_ring->count;
3597 tx_buf = tx_ring->tx_bi;
3598 tx_desc = I40E_TX_DESC(tx_ring, 0);
3601 /* update budget accounting */
3603 } while (likely(budget));
3605 i += tx_ring->count;
3606 tx_ring->next_to_clean = i;
3608 if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
3609 i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
3615 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
3616 * @irq: interrupt number
3617 * @data: pointer to a q_vector
3619 static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
3621 struct i40e_q_vector *q_vector = data;
3622 struct i40e_vsi *vsi;
3624 if (!q_vector->tx.ring)
3627 vsi = q_vector->tx.ring->vsi;
3628 i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
3634 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
3635 * @vsi: the VSI being configured
3636 * @v_idx: vector index
3637 * @qp_idx: queue pair index
3639 static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
3641 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
3642 struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
3643 struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
3645 tx_ring->q_vector = q_vector;
3646 tx_ring->next = q_vector->tx.ring;
3647 q_vector->tx.ring = tx_ring;
3648 q_vector->tx.count++;
3650 rx_ring->q_vector = q_vector;
3651 rx_ring->next = q_vector->rx.ring;
3652 q_vector->rx.ring = rx_ring;
3653 q_vector->rx.count++;
3657 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
3658 * @vsi: the VSI being configured
3660 * This function maps descriptor rings to the queue-specific vectors
3661 * we were allotted through the MSI-X enabling code. Ideally, we'd have
3662 * one vector per queue pair, but on a constrained vector budget, we
3663 * group the queue pairs as "efficiently" as possible.
3665 static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
3667 int qp_remaining = vsi->num_queue_pairs;
3668 int q_vectors = vsi->num_q_vectors;
3673 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
3674 * group them so there are multiple queues per vector.
3675 * It is also important to go through all the vectors available to be
3676 * sure that if we don't use all the vectors, that the remaining vectors
3677 * are cleared. This is especially important when decreasing the
3678 * number of queues in use.
3680 for (; v_start < q_vectors; v_start++) {
3681 struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
3683 num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
3685 q_vector->num_ringpairs = num_ringpairs;
3687 q_vector->rx.count = 0;
3688 q_vector->tx.count = 0;
3689 q_vector->rx.ring = NULL;
3690 q_vector->tx.ring = NULL;
3692 while (num_ringpairs--) {
3693 i40e_map_vector_to_qp(vsi, v_start, qp_idx);
3701 * i40e_vsi_request_irq - Request IRQ from the OS
3702 * @vsi: the VSI being configured
3703 * @basename: name for the vector
3705 static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
3707 struct i40e_pf *pf = vsi->back;
3710 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
3711 err = i40e_vsi_request_irq_msix(vsi, basename);
3712 else if (pf->flags & I40E_FLAG_MSI_ENABLED)
3713 err = request_irq(pf->pdev->irq, i40e_intr, 0,
3716 err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
3720 dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
3725 #ifdef CONFIG_NET_POLL_CONTROLLER
3727 * i40e_netpoll - A Polling 'interrupt' handler
3728 * @netdev: network interface device structure
3730 * This is used by netconsole to send skbs without having to re-enable
3731 * interrupts. It's not called while the normal interrupt routine is executing.
3734 void i40e_netpoll(struct net_device *netdev)
3736 static void i40e_netpoll(struct net_device *netdev)
3739 struct i40e_netdev_priv *np = netdev_priv(netdev);
3740 struct i40e_vsi *vsi = np->vsi;
3741 struct i40e_pf *pf = vsi->back;
3744 /* if interface is down do nothing */
3745 if (test_bit(__I40E_DOWN, &vsi->state))
3748 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3749 for (i = 0; i < vsi->num_q_vectors; i++)
3750 i40e_msix_clean_rings(0, vsi->q_vectors[i]);
3752 i40e_intr(pf->pdev->irq, netdev);
3758 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
3759 * @pf: the PF being configured
3760 * @pf_q: the PF queue
3761 * @enable: enable or disable state of the queue
3763 * This routine will wait for the given Tx queue of the PF to reach the
3764 * enabled or disabled state.
3765 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3766 * multiple retries; else will return 0 in case of success.
3768 static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
3773 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
3774 tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
3775 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
3778 usleep_range(10, 20);
3780 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
3787 * i40e_vsi_control_tx - Start or stop a VSI's rings
3788 * @vsi: the VSI being configured
3789 * @enable: start or stop the rings
3791 static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
3793 struct i40e_pf *pf = vsi->back;
3794 struct i40e_hw *hw = &pf->hw;
3795 int i, j, pf_q, ret = 0;
3798 pf_q = vsi->base_queue;
3799 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
3801 /* warn the TX unit of coming changes */
3802 i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
3804 usleep_range(10, 20);
3806 for (j = 0; j < 50; j++) {
3807 tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
3808 if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
3809 ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
3811 usleep_range(1000, 2000);
3813 /* Skip if the queue is already in the requested state */
3814 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
3817 /* turn on/off the queue */
3819 wr32(hw, I40E_QTX_HEAD(pf_q), 0);
3820 tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
3822 tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
3825 wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
3826 /* No waiting for the Tx queue to disable */
3827 if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
3830 /* wait for the change to finish */
3831 ret = i40e_pf_txq_wait(pf, pf_q, enable);
3833 dev_info(&pf->pdev->dev,
3834 "VSI seid %d Tx ring %d %sable timeout\n",
3835 vsi->seid, pf_q, (enable ? "en" : "dis"));
3840 if (hw->revision_id == 0)
3846 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
3847 * @pf: the PF being configured
3848 * @pf_q: the PF queue
3849 * @enable: enable or disable state of the queue
3851 * This routine will wait for the given Rx queue of the PF to reach the
3852 * enabled or disabled state.
3853 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3854 * multiple retries; else will return 0 in case of success.
3856 static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
3861 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
3862 rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
3863 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
3866 usleep_range(10, 20);
3868 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
3875 * i40e_vsi_control_rx - Start or stop a VSI's rings
3876 * @vsi: the VSI being configured
3877 * @enable: start or stop the rings
3879 static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
3881 struct i40e_pf *pf = vsi->back;
3882 struct i40e_hw *hw = &pf->hw;
3883 int i, j, pf_q, ret = 0;
3886 pf_q = vsi->base_queue;
3887 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
3888 for (j = 0; j < 50; j++) {
3889 rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
3890 if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
3891 ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
3893 usleep_range(1000, 2000);
3896 /* Skip if the queue is already in the requested state */
3897 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
3900 /* turn on/off the queue */
3902 rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
3904 rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
3905 wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
3906 /* No waiting for the Tx queue to disable */
3907 if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
3910 /* wait for the change to finish */
3911 ret = i40e_pf_rxq_wait(pf, pf_q, enable);
3913 dev_info(&pf->pdev->dev,
3914 "VSI seid %d Rx ring %d %sable timeout\n",
3915 vsi->seid, pf_q, (enable ? "en" : "dis"));
3924 * i40e_vsi_control_rings - Start or stop a VSI's rings
3925 * @vsi: the VSI being configured
3926 * @enable: start or stop the rings
3928 int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request)
3932 /* do rx first for enable and last for disable */
3934 ret = i40e_vsi_control_rx(vsi, request);
3937 ret = i40e_vsi_control_tx(vsi, request);
3939 /* Ignore return value, we need to shutdown whatever we can */
3940 i40e_vsi_control_tx(vsi, request);
3941 i40e_vsi_control_rx(vsi, request);
3948 * i40e_vsi_free_irq - Free the irq association with the OS
3949 * @vsi: the VSI being configured
3951 static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
3953 struct i40e_pf *pf = vsi->back;
3954 struct i40e_hw *hw = &pf->hw;
3955 int base = vsi->base_vector;
3959 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3960 if (!vsi->q_vectors)
3963 if (!vsi->irqs_ready)
3966 vsi->irqs_ready = false;
3967 for (i = 0; i < vsi->num_q_vectors; i++) {
3968 u16 vector = i + base;
3970 /* free only the irqs that were actually requested */
3971 if (!vsi->q_vectors[i] ||
3972 !vsi->q_vectors[i]->num_ringpairs)
3975 /* clear the affinity_mask in the IRQ descriptor */
3976 irq_set_affinity_hint(pf->msix_entries[vector].vector,
3978 synchronize_irq(pf->msix_entries[vector].vector);
3979 free_irq(pf->msix_entries[vector].vector,
3982 /* Tear down the interrupt queue link list
3984 * We know that they come in pairs and always
3985 * the Rx first, then the Tx. To clear the
3986 * link list, stick the EOL value into the
3987 * next_q field of the registers.
3989 val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
3990 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
3991 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
3992 val |= I40E_QUEUE_END_OF_LIST
3993 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
3994 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
3996 while (qp != I40E_QUEUE_END_OF_LIST) {
3999 val = rd32(hw, I40E_QINT_RQCTL(qp));
4001 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4002 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4003 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4004 I40E_QINT_RQCTL_INTEVENT_MASK);
4006 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4007 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4009 wr32(hw, I40E_QINT_RQCTL(qp), val);
4011 val = rd32(hw, I40E_QINT_TQCTL(qp));
4013 next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
4014 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
4016 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4017 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4018 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4019 I40E_QINT_TQCTL_INTEVENT_MASK);
4021 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4022 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4024 wr32(hw, I40E_QINT_TQCTL(qp), val);
4029 free_irq(pf->pdev->irq, pf);
4031 val = rd32(hw, I40E_PFINT_LNKLST0);
4032 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
4033 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4034 val |= I40E_QUEUE_END_OF_LIST
4035 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
4036 wr32(hw, I40E_PFINT_LNKLST0, val);
4038 val = rd32(hw, I40E_QINT_RQCTL(qp));
4039 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4040 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4041 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4042 I40E_QINT_RQCTL_INTEVENT_MASK);
4044 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4045 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4047 wr32(hw, I40E_QINT_RQCTL(qp), val);
4049 val = rd32(hw, I40E_QINT_TQCTL(qp));
4051 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4052 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4053 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4054 I40E_QINT_TQCTL_INTEVENT_MASK);
4056 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4057 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4059 wr32(hw, I40E_QINT_TQCTL(qp), val);
4064 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
4065 * @vsi: the VSI being configured
4066 * @v_idx: Index of vector to be freed
4068 * This function frees the memory allocated to the q_vector. In addition if
4069 * NAPI is enabled it will delete any references to the NAPI struct prior
4070 * to freeing the q_vector.
4072 static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
4074 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
4075 struct i40e_ring *ring;
4080 /* disassociate q_vector from rings */
4081 i40e_for_each_ring(ring, q_vector->tx)
4082 ring->q_vector = NULL;
4084 i40e_for_each_ring(ring, q_vector->rx)
4085 ring->q_vector = NULL;
4087 /* only VSI w/ an associated netdev is set up w/ NAPI */
4089 netif_napi_del(&q_vector->napi);
4091 vsi->q_vectors[v_idx] = NULL;
4093 kfree_rcu(q_vector, rcu);
4097 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
4098 * @vsi: the VSI being un-configured
4100 * This frees the memory allocated to the q_vectors and
4101 * deletes references to the NAPI struct.
4103 static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
4107 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
4108 i40e_free_q_vector(vsi, v_idx);
4112 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
4113 * @pf: board private structure
4115 static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
4117 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
4118 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4119 pci_disable_msix(pf->pdev);
4120 kfree(pf->msix_entries);
4121 pf->msix_entries = NULL;
4122 kfree(pf->irq_pile);
4123 pf->irq_pile = NULL;
4124 } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
4125 pci_disable_msi(pf->pdev);
4127 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
4131 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
4132 * @pf: board private structure
4134 * We go through and clear interrupt specific resources and reset the structure
4135 * to pre-load conditions
4137 static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
4141 i40e_stop_misc_vector(pf);
4142 if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
4143 synchronize_irq(pf->msix_entries[0].vector);
4144 free_irq(pf->msix_entries[0].vector, pf);
4147 i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
4148 I40E_IWARP_IRQ_PILE_ID);
4150 i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
4151 for (i = 0; i < pf->num_alloc_vsi; i++)
4153 i40e_vsi_free_q_vectors(pf->vsi[i]);
4154 i40e_reset_interrupt_capability(pf);
4158 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
4159 * @vsi: the VSI being configured
4161 static void i40e_napi_enable_all(struct i40e_vsi *vsi)
4168 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
4169 napi_enable(&vsi->q_vectors[q_idx]->napi);
4173 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4174 * @vsi: the VSI being configured
4176 static void i40e_napi_disable_all(struct i40e_vsi *vsi)
4183 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
4184 napi_disable(&vsi->q_vectors[q_idx]->napi);
4188 * i40e_vsi_close - Shut down a VSI
4189 * @vsi: the vsi to be quelled
4191 static void i40e_vsi_close(struct i40e_vsi *vsi)
4195 if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
4197 i40e_vsi_free_irq(vsi);
4198 i40e_vsi_free_tx_resources(vsi);
4199 i40e_vsi_free_rx_resources(vsi);
4200 vsi->current_netdev_flags = 0;
4201 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
4203 i40e_notify_client_of_netdev_close(vsi, reset);
4207 * i40e_quiesce_vsi - Pause a given VSI
4208 * @vsi: the VSI being paused
4210 static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
4212 if (test_bit(__I40E_DOWN, &vsi->state))
4215 /* No need to disable FCoE VSI when Tx suspended */
4216 if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) &&
4217 vsi->type == I40E_VSI_FCOE) {
4218 dev_dbg(&vsi->back->pdev->dev,
4219 "VSI seid %d skipping FCoE VSI disable\n", vsi->seid);
4223 set_bit(__I40E_NEEDS_RESTART, &vsi->state);
4224 if (vsi->netdev && netif_running(vsi->netdev))
4225 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
4227 i40e_vsi_close(vsi);
4231 * i40e_unquiesce_vsi - Resume a given VSI
4232 * @vsi: the VSI being resumed
4234 static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
4236 if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state))
4239 clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
4240 if (vsi->netdev && netif_running(vsi->netdev))
4241 vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
4243 i40e_vsi_open(vsi); /* this clears the DOWN bit */
4247 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
4250 static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
4254 for (v = 0; v < pf->num_alloc_vsi; v++) {
4256 i40e_quiesce_vsi(pf->vsi[v]);
4261 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
4264 static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
4268 for (v = 0; v < pf->num_alloc_vsi; v++) {
4270 i40e_unquiesce_vsi(pf->vsi[v]);
4274 #ifdef CONFIG_I40E_DCB
4276 * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
4277 * @vsi: the VSI being configured
4279 * This function waits for the given VSI's queues to be disabled.
4281 static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
4283 struct i40e_pf *pf = vsi->back;
4286 pf_q = vsi->base_queue;
4287 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
4288 /* Check and wait for the disable status of the queue */
4289 ret = i40e_pf_txq_wait(pf, pf_q, false);
4291 dev_info(&pf->pdev->dev,
4292 "VSI seid %d Tx ring %d disable timeout\n",
4298 pf_q = vsi->base_queue;
4299 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
4300 /* Check and wait for the disable status of the queue */
4301 ret = i40e_pf_rxq_wait(pf, pf_q, false);
4303 dev_info(&pf->pdev->dev,
4304 "VSI seid %d Rx ring %d disable timeout\n",
4314 * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
4317 * This function waits for the queues to be in disabled state for all the
4318 * VSIs that are managed by this PF.
4320 static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
4324 for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
4325 /* No need to wait for FCoE VSI queues */
4326 if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) {
4327 ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
4339 * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
4340 * @q_idx: TX queue number
4341 * @vsi: Pointer to VSI struct
4343 * This function checks specified queue for given VSI. Detects hung condition.
4344 * Sets hung bit since it is two step process. Before next run of service task
4345 * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not,
4346 * hung condition remain unchanged and during subsequent run, this function
4347 * issues SW interrupt to recover from hung condition.
4349 static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi)
4351 struct i40e_ring *tx_ring = NULL;
4353 u32 head, val, tx_pending_hw;
4358 /* now that we have an index, find the tx_ring struct */
4359 for (i = 0; i < vsi->num_queue_pairs; i++) {
4360 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
4361 if (q_idx == vsi->tx_rings[i]->queue_index) {
4362 tx_ring = vsi->tx_rings[i];
4371 /* Read interrupt register */
4372 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
4374 I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
4375 tx_ring->vsi->base_vector - 1));
4377 val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
4379 head = i40e_get_head(tx_ring);
4381 tx_pending_hw = i40e_get_tx_pending(tx_ring, false);
4383 /* HW is done executing descriptors, updated HEAD write back,
4384 * but SW hasn't processed those descriptors. If interrupt is
4385 * not generated from this point ON, it could result into
4386 * dev_watchdog detecting timeout on those netdev_queue,
4387 * hence proactively trigger SW interrupt.
4389 if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
4390 /* NAPI Poll didn't run and clear since it was set */
4391 if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT,
4392 &tx_ring->q_vector->hung_detected)) {
4393 netdev_info(vsi->netdev, "VSI_seid %d, Hung TX queue %d, tx_pending_hw: %d, NTC:0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x\n",
4394 vsi->seid, q_idx, tx_pending_hw,
4395 tx_ring->next_to_clean, head,
4396 tx_ring->next_to_use,
4397 readl(tx_ring->tail));
4398 netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n",
4399 vsi->seid, q_idx, val);
4400 i40e_force_wb(vsi, tx_ring->q_vector);
4402 /* First Chance - detected possible hung */
4403 set_bit(I40E_Q_VECTOR_HUNG_DETECT,
4404 &tx_ring->q_vector->hung_detected);
4408 /* This is the case where we have interrupts missing,
4409 * so the tx_pending in HW will most likely be 0, but we
4410 * will have tx_pending in SW since the WB happened but the
4411 * interrupt got lost.
4413 if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) &&
4414 (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
4415 if (napi_reschedule(&tx_ring->q_vector->napi))
4416 tx_ring->tx_stats.tx_lost_interrupt++;
4421 * i40e_detect_recover_hung - Function to detect and recover hung_queues
4422 * @pf: pointer to PF struct
4424 * LAN VSI has netdev and netdev has TX queues. This function is to check
4425 * each of those TX queues if they are hung, trigger recovery by issuing
4428 static void i40e_detect_recover_hung(struct i40e_pf *pf)
4430 struct net_device *netdev;
4431 struct i40e_vsi *vsi;
4434 /* Only for LAN VSI */
4435 vsi = pf->vsi[pf->lan_vsi];
4440 /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
4441 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
4442 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
4445 /* Make sure type is MAIN VSI */
4446 if (vsi->type != I40E_VSI_MAIN)
4449 netdev = vsi->netdev;
4453 /* Bail out if netif_carrier is not OK */
4454 if (!netif_carrier_ok(netdev))
4457 /* Go thru' TX queues for netdev */
4458 for (i = 0; i < netdev->num_tx_queues; i++) {
4459 struct netdev_queue *q;
4461 q = netdev_get_tx_queue(netdev, i);
4463 i40e_detect_recover_hung_queue(i, vsi);
4468 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
4469 * @pf: pointer to PF
4471 * Get TC map for ISCSI PF type that will include iSCSI TC
4474 static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
4476 struct i40e_dcb_app_priority_table app;
4477 struct i40e_hw *hw = &pf->hw;
4478 u8 enabled_tc = 1; /* TC0 is always enabled */
4480 /* Get the iSCSI APP TLV */
4481 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4483 for (i = 0; i < dcbcfg->numapps; i++) {
4484 app = dcbcfg->app[i];
4485 if (app.selector == I40E_APP_SEL_TCPIP &&
4486 app.protocolid == I40E_APP_PROTOID_ISCSI) {
4487 tc = dcbcfg->etscfg.prioritytable[app.priority];
4488 enabled_tc |= BIT(tc);
4497 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
4498 * @dcbcfg: the corresponding DCBx configuration structure
4500 * Return the number of TCs from given DCBx configuration
4502 static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
4507 /* Scan the ETS Config Priority Table to find
4508 * traffic class enabled for a given priority
4509 * and use the traffic class index to get the
4510 * number of traffic classes enabled
4512 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
4513 if (dcbcfg->etscfg.prioritytable[i] > num_tc)
4514 num_tc = dcbcfg->etscfg.prioritytable[i];
4517 /* Traffic class index starts from zero so
4518 * increment to return the actual count
4524 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
4525 * @dcbcfg: the corresponding DCBx configuration structure
4527 * Query the current DCB configuration and return the number of
4528 * traffic classes enabled from the given DCBX config
4530 static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
4532 u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
4536 for (i = 0; i < num_tc; i++)
4537 enabled_tc |= BIT(i);
4543 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
4544 * @pf: PF being queried
4546 * Return number of traffic classes enabled for the given PF
4548 static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
4550 struct i40e_hw *hw = &pf->hw;
4553 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4555 /* If DCB is not enabled then always in single TC */
4556 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
4559 /* SFP mode will be enabled for all TCs on port */
4560 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
4561 return i40e_dcb_get_num_tc(dcbcfg);
4563 /* MFP mode return count of enabled TCs for this PF */
4564 if (pf->hw.func_caps.iscsi)
4565 enabled_tc = i40e_get_iscsi_tc_map(pf);
4567 return 1; /* Only TC0 */
4569 /* At least have TC0 */
4570 enabled_tc = (enabled_tc ? enabled_tc : 0x1);
4571 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4572 if (enabled_tc & BIT(i))
4579 * i40e_pf_get_default_tc - Get bitmap for first enabled TC
4580 * @pf: PF being queried
4582 * Return a bitmap for first enabled traffic class for this PF.
4584 static u8 i40e_pf_get_default_tc(struct i40e_pf *pf)
4586 u8 enabled_tc = pf->hw.func_caps.enabled_tcmap;
4590 return 0x1; /* TC0 */
4592 /* Find the first enabled TC */
4593 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4594 if (enabled_tc & BIT(i))
4602 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
4603 * @pf: PF being queried
4605 * Return a bitmap for enabled traffic classes for this PF.
4607 static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
4609 /* If DCB is not enabled for this PF then just return default TC */
4610 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
4611 return i40e_pf_get_default_tc(pf);
4613 /* SFP mode we want PF to be enabled for all TCs */
4614 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
4615 return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
4617 /* MFP enabled and iSCSI PF type */
4618 if (pf->hw.func_caps.iscsi)
4619 return i40e_get_iscsi_tc_map(pf);
4621 return i40e_pf_get_default_tc(pf);
4625 * i40e_vsi_get_bw_info - Query VSI BW Information
4626 * @vsi: the VSI being queried
4628 * Returns 0 on success, negative value on failure
4630 static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
4632 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
4633 struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
4634 struct i40e_pf *pf = vsi->back;
4635 struct i40e_hw *hw = &pf->hw;
4640 /* Get the VSI level BW configuration */
4641 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
4643 dev_info(&pf->pdev->dev,
4644 "couldn't get PF vsi bw config, err %s aq_err %s\n",
4645 i40e_stat_str(&pf->hw, ret),
4646 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
4650 /* Get the VSI level BW configuration per TC */
4651 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
4654 dev_info(&pf->pdev->dev,
4655 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
4656 i40e_stat_str(&pf->hw, ret),
4657 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
4661 if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
4662 dev_info(&pf->pdev->dev,
4663 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
4664 bw_config.tc_valid_bits,
4665 bw_ets_config.tc_valid_bits);
4666 /* Still continuing */
4669 vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
4670 vsi->bw_max_quanta = bw_config.max_bw;
4671 tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
4672 (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
4673 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4674 vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
4675 vsi->bw_ets_limit_credits[i] =
4676 le16_to_cpu(bw_ets_config.credits[i]);
4677 /* 3 bits out of 4 for each TC */
4678 vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
4685 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
4686 * @vsi: the VSI being configured
4687 * @enabled_tc: TC bitmap
4688 * @bw_credits: BW shared credits per TC
4690 * Returns 0 on success, negative value on failure
4692 static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
4695 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
4699 bw_data.tc_valid_bits = enabled_tc;
4700 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4701 bw_data.tc_bw_credits[i] = bw_share[i];
4703 ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
4706 dev_info(&vsi->back->pdev->dev,
4707 "AQ command Config VSI BW allocation per TC failed = %d\n",
4708 vsi->back->hw.aq.asq_last_status);
4712 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4713 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
4719 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
4720 * @vsi: the VSI being configured
4721 * @enabled_tc: TC map to be enabled
4724 static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
4726 struct net_device *netdev = vsi->netdev;
4727 struct i40e_pf *pf = vsi->back;
4728 struct i40e_hw *hw = &pf->hw;
4731 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4737 netdev_reset_tc(netdev);
4741 /* Set up actual enabled TCs on the VSI */
4742 if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
4745 /* set per TC queues for the VSI */
4746 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4747 /* Only set TC queues for enabled tcs
4749 * e.g. For a VSI that has TC0 and TC3 enabled the
4750 * enabled_tc bitmap would be 0x00001001; the driver
4751 * will set the numtc for netdev as 2 that will be
4752 * referenced by the netdev layer as TC 0 and 1.
4754 if (vsi->tc_config.enabled_tc & BIT(i))
4755 netdev_set_tc_queue(netdev,
4756 vsi->tc_config.tc_info[i].netdev_tc,
4757 vsi->tc_config.tc_info[i].qcount,
4758 vsi->tc_config.tc_info[i].qoffset);
4761 /* Assign UP2TC map for the VSI */
4762 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
4763 /* Get the actual TC# for the UP */
4764 u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
4765 /* Get the mapped netdev TC# for the UP */
4766 netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
4767 netdev_set_prio_tc_map(netdev, i, netdev_tc);
4772 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
4773 * @vsi: the VSI being configured
4774 * @ctxt: the ctxt buffer returned from AQ VSI update param command
4776 static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
4777 struct i40e_vsi_context *ctxt)
4779 /* copy just the sections touched not the entire info
4780 * since not all sections are valid as returned by
4783 vsi->info.mapping_flags = ctxt->info.mapping_flags;
4784 memcpy(&vsi->info.queue_mapping,
4785 &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
4786 memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
4787 sizeof(vsi->info.tc_mapping));
4791 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
4792 * @vsi: VSI to be configured
4793 * @enabled_tc: TC bitmap
4795 * This configures a particular VSI for TCs that are mapped to the
4796 * given TC bitmap. It uses default bandwidth share for TCs across
4797 * VSIs to configure TC for a particular VSI.
4800 * It is expected that the VSI queues have been quisced before calling
4803 static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
4805 u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
4806 struct i40e_vsi_context ctxt;
4810 /* Check if enabled_tc is same as existing or new TCs */
4811 if (vsi->tc_config.enabled_tc == enabled_tc)
4814 /* Enable ETS TCs with equal BW Share for now across all VSIs */
4815 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4816 if (enabled_tc & BIT(i))
4820 ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
4822 dev_info(&vsi->back->pdev->dev,
4823 "Failed configuring TC map %d for VSI %d\n",
4824 enabled_tc, vsi->seid);
4828 /* Update Queue Pairs Mapping for currently enabled UPs */
4829 ctxt.seid = vsi->seid;
4830 ctxt.pf_num = vsi->back->hw.pf_id;
4832 ctxt.uplink_seid = vsi->uplink_seid;
4833 ctxt.info = vsi->info;
4834 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
4836 if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
4837 ctxt.info.valid_sections |=
4838 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
4839 ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
4842 /* Update the VSI after updating the VSI queue-mapping information */
4843 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
4845 dev_info(&vsi->back->pdev->dev,
4846 "Update vsi tc config failed, err %s aq_err %s\n",
4847 i40e_stat_str(&vsi->back->hw, ret),
4848 i40e_aq_str(&vsi->back->hw,
4849 vsi->back->hw.aq.asq_last_status));
4852 /* update the local VSI info with updated queue map */
4853 i40e_vsi_update_queue_map(vsi, &ctxt);
4854 vsi->info.valid_sections = 0;
4856 /* Update current VSI BW information */
4857 ret = i40e_vsi_get_bw_info(vsi);
4859 dev_info(&vsi->back->pdev->dev,
4860 "Failed updating vsi bw info, err %s aq_err %s\n",
4861 i40e_stat_str(&vsi->back->hw, ret),
4862 i40e_aq_str(&vsi->back->hw,
4863 vsi->back->hw.aq.asq_last_status));
4867 /* Update the netdev TC setup */
4868 i40e_vsi_config_netdev_tc(vsi, enabled_tc);
4874 * i40e_veb_config_tc - Configure TCs for given VEB
4876 * @enabled_tc: TC bitmap
4878 * Configures given TC bitmap for VEB (switching) element
4880 int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
4882 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
4883 struct i40e_pf *pf = veb->pf;
4887 /* No TCs or already enabled TCs just return */
4888 if (!enabled_tc || veb->enabled_tc == enabled_tc)
4891 bw_data.tc_valid_bits = enabled_tc;
4892 /* bw_data.absolute_credits is not set (relative) */
4894 /* Enable ETS TCs with equal BW Share for now */
4895 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4896 if (enabled_tc & BIT(i))
4897 bw_data.tc_bw_share_credits[i] = 1;
4900 ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
4903 dev_info(&pf->pdev->dev,
4904 "VEB bw config failed, err %s aq_err %s\n",
4905 i40e_stat_str(&pf->hw, ret),
4906 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
4910 /* Update the BW information */
4911 ret = i40e_veb_get_bw_info(veb);
4913 dev_info(&pf->pdev->dev,
4914 "Failed getting veb bw config, err %s aq_err %s\n",
4915 i40e_stat_str(&pf->hw, ret),
4916 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
4923 #ifdef CONFIG_I40E_DCB
4925 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
4928 * Reconfigure VEB/VSIs on a given PF; it is assumed that
4929 * the caller would've quiesce all the VSIs before calling
4932 static void i40e_dcb_reconfigure(struct i40e_pf *pf)
4938 /* Enable the TCs available on PF to all VEBs */
4939 tc_map = i40e_pf_get_tc_map(pf);
4940 for (v = 0; v < I40E_MAX_VEB; v++) {
4943 ret = i40e_veb_config_tc(pf->veb[v], tc_map);
4945 dev_info(&pf->pdev->dev,
4946 "Failed configuring TC for VEB seid=%d\n",
4948 /* Will try to configure as many components */
4952 /* Update each VSI */
4953 for (v = 0; v < pf->num_alloc_vsi; v++) {
4957 /* - Enable all TCs for the LAN VSI
4959 * - For FCoE VSI only enable the TC configured
4960 * as per the APP TLV
4962 * - For all others keep them at TC0 for now
4964 if (v == pf->lan_vsi)
4965 tc_map = i40e_pf_get_tc_map(pf);
4967 tc_map = i40e_pf_get_default_tc(pf);
4969 if (pf->vsi[v]->type == I40E_VSI_FCOE)
4970 tc_map = i40e_get_fcoe_tc_map(pf);
4971 #endif /* #ifdef I40E_FCOE */
4973 ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
4975 dev_info(&pf->pdev->dev,
4976 "Failed configuring TC for VSI seid=%d\n",
4978 /* Will try to configure as many components */
4980 /* Re-configure VSI vectors based on updated TC map */
4981 i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
4982 if (pf->vsi[v]->netdev)
4983 i40e_dcbnl_set_all(pf->vsi[v]);
4989 * i40e_resume_port_tx - Resume port Tx
4992 * Resume a port's Tx and issue a PF reset in case of failure to
4995 static int i40e_resume_port_tx(struct i40e_pf *pf)
4997 struct i40e_hw *hw = &pf->hw;
5000 ret = i40e_aq_resume_port_tx(hw, NULL);
5002 dev_info(&pf->pdev->dev,
5003 "Resume Port Tx failed, err %s aq_err %s\n",
5004 i40e_stat_str(&pf->hw, ret),
5005 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
5006 /* Schedule PF reset to recover */
5007 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
5008 i40e_service_event_schedule(pf);
5015 * i40e_init_pf_dcb - Initialize DCB configuration
5016 * @pf: PF being configured
5018 * Query the current DCB configuration and cache it
5019 * in the hardware structure
5021 static int i40e_init_pf_dcb(struct i40e_pf *pf)
5023 struct i40e_hw *hw = &pf->hw;
5026 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
5027 if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT)
5030 /* Get the initial DCB configuration */
5031 err = i40e_init_dcb(hw);
5033 /* Device/Function is not DCBX capable */
5034 if ((!hw->func_caps.dcb) ||
5035 (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
5036 dev_info(&pf->pdev->dev,
5037 "DCBX offload is not supported or is disabled for this PF.\n");
5039 if (pf->flags & I40E_FLAG_MFP_ENABLED)
5043 /* When status is not DISABLED then DCBX in FW */
5044 pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
5045 DCB_CAP_DCBX_VER_IEEE;
5047 pf->flags |= I40E_FLAG_DCB_CAPABLE;
5048 /* Enable DCB tagging only when more than one TC */
5049 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
5050 pf->flags |= I40E_FLAG_DCB_ENABLED;
5051 dev_dbg(&pf->pdev->dev,
5052 "DCBX offload is supported for this PF.\n");
5055 dev_info(&pf->pdev->dev,
5056 "Query for DCB configuration failed, err %s aq_err %s\n",
5057 i40e_stat_str(&pf->hw, err),
5058 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
5064 #endif /* CONFIG_I40E_DCB */
5065 #define SPEED_SIZE 14
5068 * i40e_print_link_message - print link up or down
5069 * @vsi: the VSI for which link needs a message
5071 void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
5073 char *speed = "Unknown";
5074 char *fc = "Unknown";
5076 if (vsi->current_isup == isup)
5078 vsi->current_isup = isup;
5080 netdev_info(vsi->netdev, "NIC Link is Down\n");
5084 /* Warn user if link speed on NPAR enabled partition is not at
5087 if (vsi->back->hw.func_caps.npar_enable &&
5088 (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
5089 vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
5090 netdev_warn(vsi->netdev,
5091 "The partition detected link speed that is less than 10Gbps\n");
5093 switch (vsi->back->hw.phy.link_info.link_speed) {
5094 case I40E_LINK_SPEED_40GB:
5097 case I40E_LINK_SPEED_20GB:
5100 case I40E_LINK_SPEED_10GB:
5103 case I40E_LINK_SPEED_1GB:
5106 case I40E_LINK_SPEED_100MB:
5113 switch (vsi->back->hw.fc.current_mode) {
5117 case I40E_FC_TX_PAUSE:
5120 case I40E_FC_RX_PAUSE:
5128 netdev_info(vsi->netdev, "NIC Link is Up %sbps Full Duplex, Flow Control: %s\n",
5133 * i40e_up_complete - Finish the last steps of bringing up a connection
5134 * @vsi: the VSI being configured
5136 static int i40e_up_complete(struct i40e_vsi *vsi)
5138 struct i40e_pf *pf = vsi->back;
5141 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
5142 i40e_vsi_configure_msix(vsi);
5144 i40e_configure_msi_and_legacy(vsi);
5147 err = i40e_vsi_control_rings(vsi, true);
5151 clear_bit(__I40E_DOWN, &vsi->state);
5152 i40e_napi_enable_all(vsi);
5153 i40e_vsi_enable_irq(vsi);
5155 if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
5157 i40e_print_link_message(vsi, true);
5158 netif_tx_start_all_queues(vsi->netdev);
5159 netif_carrier_on(vsi->netdev);
5160 } else if (vsi->netdev) {
5161 i40e_print_link_message(vsi, false);
5162 /* need to check for qualified module here*/
5163 if ((pf->hw.phy.link_info.link_info &
5164 I40E_AQ_MEDIA_AVAILABLE) &&
5165 (!(pf->hw.phy.link_info.an_info &
5166 I40E_AQ_QUALIFIED_MODULE)))
5167 netdev_err(vsi->netdev,
5168 "the driver failed to link because an unqualified module was detected.");
5171 /* replay FDIR SB filters */
5172 if (vsi->type == I40E_VSI_FDIR) {
5173 /* reset fd counters */
5174 pf->fd_add_err = pf->fd_atr_cnt = 0;
5175 if (pf->fd_tcp_rule > 0) {
5176 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
5177 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5178 dev_info(&pf->pdev->dev, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
5179 pf->fd_tcp_rule = 0;
5181 i40e_fdir_filter_restore(vsi);
5184 /* On the next run of the service_task, notify any clients of the new
5187 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
5188 i40e_service_event_schedule(pf);
5194 * i40e_vsi_reinit_locked - Reset the VSI
5195 * @vsi: the VSI being configured
5197 * Rebuild the ring structs after some configuration
5198 * has changed, e.g. MTU size.
5200 static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
5202 struct i40e_pf *pf = vsi->back;
5204 WARN_ON(in_interrupt());
5205 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
5206 usleep_range(1000, 2000);
5210 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
5214 * i40e_up - Bring the connection back up after being down
5215 * @vsi: the VSI being configured
5217 int i40e_up(struct i40e_vsi *vsi)
5221 err = i40e_vsi_configure(vsi);
5223 err = i40e_up_complete(vsi);
5229 * i40e_down - Shutdown the connection processing
5230 * @vsi: the VSI being stopped
5232 void i40e_down(struct i40e_vsi *vsi)
5236 /* It is assumed that the caller of this function
5237 * sets the vsi->state __I40E_DOWN bit.
5240 netif_carrier_off(vsi->netdev);
5241 netif_tx_disable(vsi->netdev);
5243 i40e_vsi_disable_irq(vsi);
5244 i40e_vsi_control_rings(vsi, false);
5245 i40e_napi_disable_all(vsi);
5247 for (i = 0; i < vsi->num_queue_pairs; i++) {
5248 i40e_clean_tx_ring(vsi->tx_rings[i]);
5249 i40e_clean_rx_ring(vsi->rx_rings[i]);
5252 i40e_notify_client_of_netdev_close(vsi, false);
5257 * i40e_setup_tc - configure multiple traffic classes
5258 * @netdev: net device to configure
5259 * @tc: number of traffic classes to enable
5261 static int i40e_setup_tc(struct net_device *netdev, u8 tc)
5263 struct i40e_netdev_priv *np = netdev_priv(netdev);
5264 struct i40e_vsi *vsi = np->vsi;
5265 struct i40e_pf *pf = vsi->back;
5270 /* Check if DCB enabled to continue */
5271 if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
5272 netdev_info(netdev, "DCB is not enabled for adapter\n");
5276 /* Check if MFP enabled */
5277 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
5278 netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
5282 /* Check whether tc count is within enabled limit */
5283 if (tc > i40e_pf_get_num_tc(pf)) {
5284 netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
5288 /* Generate TC map for number of tc requested */
5289 for (i = 0; i < tc; i++)
5290 enabled_tc |= BIT(i);
5292 /* Requesting same TC configuration as already enabled */
5293 if (enabled_tc == vsi->tc_config.enabled_tc)
5296 /* Quiesce VSI queues */
5297 i40e_quiesce_vsi(vsi);
5299 /* Configure VSI for enabled TCs */
5300 ret = i40e_vsi_config_tc(vsi, enabled_tc);
5302 netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
5308 i40e_unquiesce_vsi(vsi);
5315 int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
5316 struct tc_to_netdev *tc)
5318 static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
5319 struct tc_to_netdev *tc)
5322 if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO)
5324 return i40e_setup_tc(netdev, tc->tc);
5328 * i40e_open - Called when a network interface is made active
5329 * @netdev: network interface device structure
5331 * The open entry point is called when a network interface is made
5332 * active by the system (IFF_UP). At this point all resources needed
5333 * for transmit and receive operations are allocated, the interrupt
5334 * handler is registered with the OS, the netdev watchdog subtask is
5335 * enabled, and the stack is notified that the interface is ready.
5337 * Returns 0 on success, negative value on failure
5339 int i40e_open(struct net_device *netdev)
5341 struct i40e_netdev_priv *np = netdev_priv(netdev);
5342 struct i40e_vsi *vsi = np->vsi;
5343 struct i40e_pf *pf = vsi->back;
5346 /* disallow open during test or if eeprom is broken */
5347 if (test_bit(__I40E_TESTING, &pf->state) ||
5348 test_bit(__I40E_BAD_EEPROM, &pf->state))
5351 netif_carrier_off(netdev);
5353 err = i40e_vsi_open(vsi);
5357 /* configure global TSO hardware offload settings */
5358 wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
5359 TCP_FLAG_FIN) >> 16);
5360 wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
5362 TCP_FLAG_CWR) >> 16);
5363 wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
5365 udp_tunnel_get_rx_info(netdev);
5366 i40e_notify_client_of_netdev_open(vsi);
5373 * @vsi: the VSI to open
5375 * Finish initialization of the VSI.
5377 * Returns 0 on success, negative value on failure
5379 int i40e_vsi_open(struct i40e_vsi *vsi)
5381 struct i40e_pf *pf = vsi->back;
5382 char int_name[I40E_INT_NAME_STR_LEN];
5385 /* allocate descriptors */
5386 err = i40e_vsi_setup_tx_resources(vsi);
5389 err = i40e_vsi_setup_rx_resources(vsi);
5393 err = i40e_vsi_configure(vsi);
5398 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
5399 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
5400 err = i40e_vsi_request_irq(vsi, int_name);
5404 /* Notify the stack of the actual queue counts. */
5405 err = netif_set_real_num_tx_queues(vsi->netdev,
5406 vsi->num_queue_pairs);
5408 goto err_set_queues;
5410 err = netif_set_real_num_rx_queues(vsi->netdev,
5411 vsi->num_queue_pairs);
5413 goto err_set_queues;
5415 } else if (vsi->type == I40E_VSI_FDIR) {
5416 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
5417 dev_driver_string(&pf->pdev->dev),
5418 dev_name(&pf->pdev->dev));
5419 err = i40e_vsi_request_irq(vsi, int_name);
5426 err = i40e_up_complete(vsi);
5428 goto err_up_complete;
5435 i40e_vsi_free_irq(vsi);
5437 i40e_vsi_free_rx_resources(vsi);
5439 i40e_vsi_free_tx_resources(vsi);
5440 if (vsi == pf->vsi[pf->lan_vsi])
5441 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
5447 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
5448 * @pf: Pointer to PF
5450 * This function destroys the hlist where all the Flow Director
5451 * filters were saved.
5453 static void i40e_fdir_filter_exit(struct i40e_pf *pf)
5455 struct i40e_fdir_filter *filter;
5456 struct hlist_node *node2;
5458 hlist_for_each_entry_safe(filter, node2,
5459 &pf->fdir_filter_list, fdir_node) {
5460 hlist_del(&filter->fdir_node);
5463 pf->fdir_pf_active_filters = 0;
5467 * i40e_close - Disables a network interface
5468 * @netdev: network interface device structure
5470 * The close entry point is called when an interface is de-activated
5471 * by the OS. The hardware is still under the driver's control, but
5472 * this netdev interface is disabled.
5474 * Returns 0, this is not allowed to fail
5476 int i40e_close(struct net_device *netdev)
5478 struct i40e_netdev_priv *np = netdev_priv(netdev);
5479 struct i40e_vsi *vsi = np->vsi;
5481 i40e_vsi_close(vsi);
5487 * i40e_do_reset - Start a PF or Core Reset sequence
5488 * @pf: board private structure
5489 * @reset_flags: which reset is requested
5491 * The essential difference in resets is that the PF Reset
5492 * doesn't clear the packet buffers, doesn't reset the PE
5493 * firmware, and doesn't bother the other PFs on the chip.
5495 void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags)
5499 WARN_ON(in_interrupt());
5502 /* do the biggest reset indicated */
5503 if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
5505 /* Request a Global Reset
5507 * This will start the chip's countdown to the actual full
5508 * chip reset event, and a warning interrupt to be sent
5509 * to all PFs, including the requestor. Our handler
5510 * for the warning interrupt will deal with the shutdown
5511 * and recovery of the switch setup.
5513 dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
5514 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
5515 val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
5516 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
5518 } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
5520 /* Request a Core Reset
5522 * Same as Global Reset, except does *not* include the MAC/PHY
5524 dev_dbg(&pf->pdev->dev, "CoreR requested\n");
5525 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
5526 val |= I40E_GLGEN_RTRIG_CORER_MASK;
5527 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
5528 i40e_flush(&pf->hw);
5530 } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) {
5532 /* Request a PF Reset
5534 * Resets only the PF-specific registers
5536 * This goes directly to the tear-down and rebuild of
5537 * the switch, since we need to do all the recovery as
5538 * for the Core Reset.
5540 dev_dbg(&pf->pdev->dev, "PFR requested\n");
5541 i40e_handle_reset_warning(pf);
5543 } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
5546 /* Find the VSI(s) that requested a re-init */
5547 dev_info(&pf->pdev->dev,
5548 "VSI reinit requested\n");
5549 for (v = 0; v < pf->num_alloc_vsi; v++) {
5550 struct i40e_vsi *vsi = pf->vsi[v];
5553 test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) {
5554 i40e_vsi_reinit_locked(pf->vsi[v]);
5555 clear_bit(__I40E_REINIT_REQUESTED, &vsi->state);
5558 } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
5561 /* Find the VSI(s) that needs to be brought down */
5562 dev_info(&pf->pdev->dev, "VSI down requested\n");
5563 for (v = 0; v < pf->num_alloc_vsi; v++) {
5564 struct i40e_vsi *vsi = pf->vsi[v];
5567 test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) {
5568 set_bit(__I40E_DOWN, &vsi->state);
5570 clear_bit(__I40E_DOWN_REQUESTED, &vsi->state);
5574 dev_info(&pf->pdev->dev,
5575 "bad reset request 0x%08x\n", reset_flags);
5579 #ifdef CONFIG_I40E_DCB
5581 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
5582 * @pf: board private structure
5583 * @old_cfg: current DCB config
5584 * @new_cfg: new DCB config
5586 bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
5587 struct i40e_dcbx_config *old_cfg,
5588 struct i40e_dcbx_config *new_cfg)
5590 bool need_reconfig = false;
5592 /* Check if ETS configuration has changed */
5593 if (memcmp(&new_cfg->etscfg,
5595 sizeof(new_cfg->etscfg))) {
5596 /* If Priority Table has changed reconfig is needed */
5597 if (memcmp(&new_cfg->etscfg.prioritytable,
5598 &old_cfg->etscfg.prioritytable,
5599 sizeof(new_cfg->etscfg.prioritytable))) {
5600 need_reconfig = true;
5601 dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
5604 if (memcmp(&new_cfg->etscfg.tcbwtable,
5605 &old_cfg->etscfg.tcbwtable,
5606 sizeof(new_cfg->etscfg.tcbwtable)))
5607 dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
5609 if (memcmp(&new_cfg->etscfg.tsatable,
5610 &old_cfg->etscfg.tsatable,
5611 sizeof(new_cfg->etscfg.tsatable)))
5612 dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
5615 /* Check if PFC configuration has changed */
5616 if (memcmp(&new_cfg->pfc,
5618 sizeof(new_cfg->pfc))) {
5619 need_reconfig = true;
5620 dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
5623 /* Check if APP Table has changed */
5624 if (memcmp(&new_cfg->app,
5626 sizeof(new_cfg->app))) {
5627 need_reconfig = true;
5628 dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
5631 dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
5632 return need_reconfig;
5636 * i40e_handle_lldp_event - Handle LLDP Change MIB event
5637 * @pf: board private structure
5638 * @e: event info posted on ARQ
5640 static int i40e_handle_lldp_event(struct i40e_pf *pf,
5641 struct i40e_arq_event_info *e)
5643 struct i40e_aqc_lldp_get_mib *mib =
5644 (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
5645 struct i40e_hw *hw = &pf->hw;
5646 struct i40e_dcbx_config tmp_dcbx_cfg;
5647 bool need_reconfig = false;
5651 /* Not DCB capable or capability disabled */
5652 if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
5655 /* Ignore if event is not for Nearest Bridge */
5656 type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
5657 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
5658 dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
5659 if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
5662 /* Check MIB Type and return if event for Remote MIB update */
5663 type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
5664 dev_dbg(&pf->pdev->dev,
5665 "LLDP event mib type %s\n", type ? "remote" : "local");
5666 if (type == I40E_AQ_LLDP_MIB_REMOTE) {
5667 /* Update the remote cached instance and return */
5668 ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
5669 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
5670 &hw->remote_dcbx_config);
5674 /* Store the old configuration */
5675 tmp_dcbx_cfg = hw->local_dcbx_config;
5677 /* Reset the old DCBx configuration data */
5678 memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
5679 /* Get updated DCBX data from firmware */
5680 ret = i40e_get_dcb_config(&pf->hw);
5682 dev_info(&pf->pdev->dev,
5683 "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
5684 i40e_stat_str(&pf->hw, ret),
5685 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
5689 /* No change detected in DCBX configs */
5690 if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
5691 sizeof(tmp_dcbx_cfg))) {
5692 dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
5696 need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
5697 &hw->local_dcbx_config);
5699 i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
5704 /* Enable DCB tagging only when more than one TC */
5705 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
5706 pf->flags |= I40E_FLAG_DCB_ENABLED;
5708 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
5710 set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
5711 /* Reconfiguration needed quiesce all VSIs */
5712 i40e_pf_quiesce_all_vsi(pf);
5714 /* Changes in configuration update VEB/VSI */
5715 i40e_dcb_reconfigure(pf);
5717 ret = i40e_resume_port_tx(pf);
5719 clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
5720 /* In case of error no point in resuming VSIs */
5724 /* Wait for the PF's queues to be disabled */
5725 ret = i40e_pf_wait_queues_disabled(pf);
5727 /* Schedule PF reset to recover */
5728 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
5729 i40e_service_event_schedule(pf);
5731 i40e_pf_unquiesce_all_vsi(pf);
5732 /* Notify the client for the DCB changes */
5733 i40e_notify_client_of_l2_param_changes(pf->vsi[pf->lan_vsi]);
5739 #endif /* CONFIG_I40E_DCB */
5742 * i40e_do_reset_safe - Protected reset path for userland calls.
5743 * @pf: board private structure
5744 * @reset_flags: which reset is requested
5747 void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
5750 i40e_do_reset(pf, reset_flags);
5755 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
5756 * @pf: board private structure
5757 * @e: event info posted on ARQ
5759 * Handler for LAN Queue Overflow Event generated by the firmware for PF
5762 static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
5763 struct i40e_arq_event_info *e)
5765 struct i40e_aqc_lan_overflow *data =
5766 (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
5767 u32 queue = le32_to_cpu(data->prtdcb_rupto);
5768 u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
5769 struct i40e_hw *hw = &pf->hw;
5773 dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
5776 /* Queue belongs to VF, find the VF and issue VF reset */
5777 if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
5778 >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
5779 vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
5780 >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
5781 vf_id -= hw->func_caps.vf_base_id;
5782 vf = &pf->vf[vf_id];
5783 i40e_vc_notify_vf_reset(vf);
5784 /* Allow VF to process pending reset notification */
5786 i40e_reset_vf(vf, false);
5791 * i40e_service_event_complete - Finish up the service event
5792 * @pf: board private structure
5794 static void i40e_service_event_complete(struct i40e_pf *pf)
5796 WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state));
5798 /* flush memory to make sure state is correct before next watchog */
5799 smp_mb__before_atomic();
5800 clear_bit(__I40E_SERVICE_SCHED, &pf->state);
5804 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
5805 * @pf: board private structure
5807 u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
5811 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
5812 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
5817 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
5818 * @pf: board private structure
5820 u32 i40e_get_current_fd_count(struct i40e_pf *pf)
5824 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
5825 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
5826 ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
5827 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
5832 * i40e_get_global_fd_count - Get total FD filters programmed on device
5833 * @pf: board private structure
5835 u32 i40e_get_global_fd_count(struct i40e_pf *pf)
5839 val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
5840 fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
5841 ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
5842 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
5847 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
5848 * @pf: board private structure
5850 void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
5852 struct i40e_fdir_filter *filter;
5853 u32 fcnt_prog, fcnt_avail;
5854 struct hlist_node *node;
5856 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
5859 /* Check if, FD SB or ATR was auto disabled and if there is enough room
5862 fcnt_prog = i40e_get_global_fd_count(pf);
5863 fcnt_avail = pf->fdir_pf_filter_count;
5864 if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
5865 (pf->fd_add_err == 0) ||
5866 (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
5867 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
5868 (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) {
5869 pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
5870 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5871 dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
5874 /* Wait for some more space to be available to turn on ATR */
5875 if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) {
5876 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
5877 (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) {
5878 pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
5879 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5880 dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table now\n");
5884 /* if hw had a problem adding a filter, delete it */
5885 if (pf->fd_inv > 0) {
5886 hlist_for_each_entry_safe(filter, node,
5887 &pf->fdir_filter_list, fdir_node) {
5888 if (filter->fd_id == pf->fd_inv) {
5889 hlist_del(&filter->fdir_node);
5891 pf->fdir_pf_active_filters--;
5897 #define I40E_MIN_FD_FLUSH_INTERVAL 10
5898 #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
5900 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
5901 * @pf: board private structure
5903 static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
5905 unsigned long min_flush_time;
5906 int flush_wait_retry = 50;
5907 bool disable_atr = false;
5911 if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED)))
5914 if (!time_after(jiffies, pf->fd_flush_timestamp +
5915 (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
5918 /* If the flush is happening too quick and we have mostly SB rules we
5919 * should not re-enable ATR for some time.
5921 min_flush_time = pf->fd_flush_timestamp +
5922 (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
5923 fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
5925 if (!(time_after(jiffies, min_flush_time)) &&
5926 (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
5927 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5928 dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
5932 pf->fd_flush_timestamp = jiffies;
5933 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
5934 /* flush all filters */
5935 wr32(&pf->hw, I40E_PFQF_CTL_1,
5936 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
5937 i40e_flush(&pf->hw);
5941 /* Check FD flush status every 5-6msec */
5942 usleep_range(5000, 6000);
5943 reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
5944 if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
5946 } while (flush_wait_retry--);
5947 if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
5948 dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
5950 /* replay sideband filters */
5951 i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
5953 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
5954 clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
5955 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5956 dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
5961 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
5962 * @pf: board private structure
5964 u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
5966 return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
5969 /* We can see up to 256 filter programming desc in transit if the filters are
5970 * being applied really fast; before we see the first
5971 * filter miss error on Rx queue 0. Accumulating enough error messages before
5972 * reacting will make sure we don't cause flush too often.
5974 #define I40E_MAX_FD_PROGRAM_ERROR 256
5977 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
5978 * @pf: board private structure
5980 static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
5983 /* if interface is down do nothing */
5984 if (test_bit(__I40E_DOWN, &pf->state))
5987 if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED)))
5990 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
5991 i40e_fdir_flush_and_replay(pf);
5993 i40e_fdir_check_and_reenable(pf);
5998 * i40e_vsi_link_event - notify VSI of a link event
5999 * @vsi: vsi to be notified
6000 * @link_up: link up or down
6002 static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
6004 if (!vsi || test_bit(__I40E_DOWN, &vsi->state))
6007 switch (vsi->type) {
6012 if (!vsi->netdev || !vsi->netdev_registered)
6016 netif_carrier_on(vsi->netdev);
6017 netif_tx_wake_all_queues(vsi->netdev);
6019 netif_carrier_off(vsi->netdev);
6020 netif_tx_stop_all_queues(vsi->netdev);
6024 case I40E_VSI_SRIOV:
6025 case I40E_VSI_VMDQ2:
6027 case I40E_VSI_IWARP:
6028 case I40E_VSI_MIRROR:
6030 /* there is no notification for other VSIs */
6036 * i40e_veb_link_event - notify elements on the veb of a link event
6037 * @veb: veb to be notified
6038 * @link_up: link up or down
6040 static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
6045 if (!veb || !veb->pf)
6049 /* depth first... */
6050 for (i = 0; i < I40E_MAX_VEB; i++)
6051 if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
6052 i40e_veb_link_event(pf->veb[i], link_up);
6054 /* ... now the local VSIs */
6055 for (i = 0; i < pf->num_alloc_vsi; i++)
6056 if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
6057 i40e_vsi_link_event(pf->vsi[i], link_up);
6061 * i40e_link_event - Update netif_carrier status
6062 * @pf: board private structure
6064 static void i40e_link_event(struct i40e_pf *pf)
6066 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
6067 u8 new_link_speed, old_link_speed;
6069 bool new_link, old_link;
6071 /* save off old link status information */
6072 pf->hw.phy.link_info_old = pf->hw.phy.link_info;
6074 /* set this to force the get_link_status call to refresh state */
6075 pf->hw.phy.get_link_info = true;
6077 old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
6079 status = i40e_get_link_status(&pf->hw, &new_link);
6081 dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
6086 old_link_speed = pf->hw.phy.link_info_old.link_speed;
6087 new_link_speed = pf->hw.phy.link_info.link_speed;
6089 if (new_link == old_link &&
6090 new_link_speed == old_link_speed &&
6091 (test_bit(__I40E_DOWN, &vsi->state) ||
6092 new_link == netif_carrier_ok(vsi->netdev)))
6095 if (!test_bit(__I40E_DOWN, &vsi->state))
6096 i40e_print_link_message(vsi, new_link);
6098 /* Notify the base of the switch tree connected to
6099 * the link. Floating VEBs are not notified.
6101 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
6102 i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
6104 i40e_vsi_link_event(vsi, new_link);
6107 i40e_vc_notify_link_state(pf);
6109 if (pf->flags & I40E_FLAG_PTP)
6110 i40e_ptp_set_increment(pf);
6114 * i40e_watchdog_subtask - periodic checks not using event driven response
6115 * @pf: board private structure
6117 static void i40e_watchdog_subtask(struct i40e_pf *pf)
6121 /* if interface is down do nothing */
6122 if (test_bit(__I40E_DOWN, &pf->state) ||
6123 test_bit(__I40E_CONFIG_BUSY, &pf->state))
6126 /* make sure we don't do these things too often */
6127 if (time_before(jiffies, (pf->service_timer_previous +
6128 pf->service_timer_period)))
6130 pf->service_timer_previous = jiffies;
6132 if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED)
6133 i40e_link_event(pf);
6135 /* Update the stats for active netdevs so the network stack
6136 * can look at updated numbers whenever it cares to
6138 for (i = 0; i < pf->num_alloc_vsi; i++)
6139 if (pf->vsi[i] && pf->vsi[i]->netdev)
6140 i40e_update_stats(pf->vsi[i]);
6142 if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
6143 /* Update the stats for the active switching components */
6144 for (i = 0; i < I40E_MAX_VEB; i++)
6146 i40e_update_veb_stats(pf->veb[i]);
6149 i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]);
6153 * i40e_reset_subtask - Set up for resetting the device and driver
6154 * @pf: board private structure
6156 static void i40e_reset_subtask(struct i40e_pf *pf)
6158 u32 reset_flags = 0;
6161 if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) {
6162 reset_flags |= BIT(__I40E_REINIT_REQUESTED);
6163 clear_bit(__I40E_REINIT_REQUESTED, &pf->state);
6165 if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) {
6166 reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
6167 clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
6169 if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) {
6170 reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
6171 clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
6173 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) {
6174 reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
6175 clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
6177 if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) {
6178 reset_flags |= BIT(__I40E_DOWN_REQUESTED);
6179 clear_bit(__I40E_DOWN_REQUESTED, &pf->state);
6182 /* If there's a recovery already waiting, it takes
6183 * precedence before starting a new reset sequence.
6185 if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) {
6186 i40e_handle_reset_warning(pf);
6190 /* If we're already down or resetting, just bail */
6192 !test_bit(__I40E_DOWN, &pf->state) &&
6193 !test_bit(__I40E_CONFIG_BUSY, &pf->state))
6194 i40e_do_reset(pf, reset_flags);
6201 * i40e_handle_link_event - Handle link event
6202 * @pf: board private structure
6203 * @e: event info posted on ARQ
6205 static void i40e_handle_link_event(struct i40e_pf *pf,
6206 struct i40e_arq_event_info *e)
6208 struct i40e_aqc_get_link_status *status =
6209 (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
6211 /* Do a new status request to re-enable LSE reporting
6212 * and load new status information into the hw struct
6213 * This completely ignores any state information
6214 * in the ARQ event info, instead choosing to always
6215 * issue the AQ update link status command.
6217 i40e_link_event(pf);
6219 /* check for unqualified module, if link is down */
6220 if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
6221 (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
6222 (!(status->link_info & I40E_AQ_LINK_UP)))
6223 dev_err(&pf->pdev->dev,
6224 "The driver failed to link because an unqualified module was detected.\n");
6228 * i40e_clean_adminq_subtask - Clean the AdminQ rings
6229 * @pf: board private structure
6231 static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
6233 struct i40e_arq_event_info event;
6234 struct i40e_hw *hw = &pf->hw;
6241 /* Do not run clean AQ when PF reset fails */
6242 if (test_bit(__I40E_RESET_FAILED, &pf->state))
6245 /* check for error indications */
6246 val = rd32(&pf->hw, pf->hw.aq.arq.len);
6248 if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
6249 if (hw->debug_mask & I40E_DEBUG_AQ)
6250 dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
6251 val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
6253 if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
6254 if (hw->debug_mask & I40E_DEBUG_AQ)
6255 dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
6256 val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
6257 pf->arq_overflows++;
6259 if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
6260 if (hw->debug_mask & I40E_DEBUG_AQ)
6261 dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
6262 val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
6265 wr32(&pf->hw, pf->hw.aq.arq.len, val);
6267 val = rd32(&pf->hw, pf->hw.aq.asq.len);
6269 if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
6270 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6271 dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
6272 val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
6274 if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
6275 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6276 dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
6277 val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
6279 if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
6280 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6281 dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
6282 val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
6285 wr32(&pf->hw, pf->hw.aq.asq.len, val);
6287 event.buf_len = I40E_MAX_AQ_BUF_SIZE;
6288 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
6293 ret = i40e_clean_arq_element(hw, &event, &pending);
6294 if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
6297 dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
6301 opcode = le16_to_cpu(event.desc.opcode);
6304 case i40e_aqc_opc_get_link_status:
6305 i40e_handle_link_event(pf, &event);
6307 case i40e_aqc_opc_send_msg_to_pf:
6308 ret = i40e_vc_process_vf_msg(pf,
6309 le16_to_cpu(event.desc.retval),
6310 le32_to_cpu(event.desc.cookie_high),
6311 le32_to_cpu(event.desc.cookie_low),
6315 case i40e_aqc_opc_lldp_update_mib:
6316 dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
6317 #ifdef CONFIG_I40E_DCB
6319 ret = i40e_handle_lldp_event(pf, &event);
6321 #endif /* CONFIG_I40E_DCB */
6323 case i40e_aqc_opc_event_lan_overflow:
6324 dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
6325 i40e_handle_lan_overflow_event(pf, &event);
6327 case i40e_aqc_opc_send_msg_to_peer:
6328 dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
6330 case i40e_aqc_opc_nvm_erase:
6331 case i40e_aqc_opc_nvm_update:
6332 case i40e_aqc_opc_oem_post_update:
6333 i40e_debug(&pf->hw, I40E_DEBUG_NVM,
6334 "ARQ NVM operation 0x%04x completed\n",
6338 dev_info(&pf->pdev->dev,
6339 "ARQ: Unknown event 0x%04x ignored\n",
6343 } while (pending && (i++ < pf->adminq_work_limit));
6345 clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
6346 /* re-enable Admin queue interrupt cause */
6347 val = rd32(hw, I40E_PFINT_ICR0_ENA);
6348 val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
6349 wr32(hw, I40E_PFINT_ICR0_ENA, val);
6352 kfree(event.msg_buf);
6356 * i40e_verify_eeprom - make sure eeprom is good to use
6357 * @pf: board private structure
6359 static void i40e_verify_eeprom(struct i40e_pf *pf)
6363 err = i40e_diag_eeprom_test(&pf->hw);
6365 /* retry in case of garbage read */
6366 err = i40e_diag_eeprom_test(&pf->hw);
6368 dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
6370 set_bit(__I40E_BAD_EEPROM, &pf->state);
6374 if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) {
6375 dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
6376 clear_bit(__I40E_BAD_EEPROM, &pf->state);
6381 * i40e_enable_pf_switch_lb
6382 * @pf: pointer to the PF structure
6384 * enable switch loop back or die - no point in a return value
6386 static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
6388 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
6389 struct i40e_vsi_context ctxt;
6392 ctxt.seid = pf->main_vsi_seid;
6393 ctxt.pf_num = pf->hw.pf_id;
6395 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
6397 dev_info(&pf->pdev->dev,
6398 "couldn't get PF vsi config, err %s aq_err %s\n",
6399 i40e_stat_str(&pf->hw, ret),
6400 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6403 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6404 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6405 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6407 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
6409 dev_info(&pf->pdev->dev,
6410 "update vsi switch failed, err %s aq_err %s\n",
6411 i40e_stat_str(&pf->hw, ret),
6412 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6417 * i40e_disable_pf_switch_lb
6418 * @pf: pointer to the PF structure
6420 * disable switch loop back or die - no point in a return value
6422 static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
6424 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
6425 struct i40e_vsi_context ctxt;
6428 ctxt.seid = pf->main_vsi_seid;
6429 ctxt.pf_num = pf->hw.pf_id;
6431 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
6433 dev_info(&pf->pdev->dev,
6434 "couldn't get PF vsi config, err %s aq_err %s\n",
6435 i40e_stat_str(&pf->hw, ret),
6436 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6439 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6440 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6441 ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6443 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
6445 dev_info(&pf->pdev->dev,
6446 "update vsi switch failed, err %s aq_err %s\n",
6447 i40e_stat_str(&pf->hw, ret),
6448 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6453 * i40e_config_bridge_mode - Configure the HW bridge mode
6454 * @veb: pointer to the bridge instance
6456 * Configure the loop back mode for the LAN VSI that is downlink to the
6457 * specified HW bridge instance. It is expected this function is called
6458 * when a new HW bridge is instantiated.
6460 static void i40e_config_bridge_mode(struct i40e_veb *veb)
6462 struct i40e_pf *pf = veb->pf;
6464 if (pf->hw.debug_mask & I40E_DEBUG_LAN)
6465 dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
6466 veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
6467 if (veb->bridge_mode & BRIDGE_MODE_VEPA)
6468 i40e_disable_pf_switch_lb(pf);
6470 i40e_enable_pf_switch_lb(pf);
6474 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
6475 * @veb: pointer to the VEB instance
6477 * This is a recursive function that first builds the attached VSIs then
6478 * recurses in to build the next layer of VEB. We track the connections
6479 * through our own index numbers because the seid's from the HW could
6480 * change across the reset.
6482 static int i40e_reconstitute_veb(struct i40e_veb *veb)
6484 struct i40e_vsi *ctl_vsi = NULL;
6485 struct i40e_pf *pf = veb->pf;
6489 /* build VSI that owns this VEB, temporarily attached to base VEB */
6490 for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
6492 pf->vsi[v]->veb_idx == veb->idx &&
6493 pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
6494 ctl_vsi = pf->vsi[v];
6499 dev_info(&pf->pdev->dev,
6500 "missing owner VSI for veb_idx %d\n", veb->idx);
6502 goto end_reconstitute;
6504 if (ctl_vsi != pf->vsi[pf->lan_vsi])
6505 ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
6506 ret = i40e_add_vsi(ctl_vsi);
6508 dev_info(&pf->pdev->dev,
6509 "rebuild of veb_idx %d owner VSI failed: %d\n",
6511 goto end_reconstitute;
6513 i40e_vsi_reset_stats(ctl_vsi);
6515 /* create the VEB in the switch and move the VSI onto the VEB */
6516 ret = i40e_add_veb(veb, ctl_vsi);
6518 goto end_reconstitute;
6520 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
6521 veb->bridge_mode = BRIDGE_MODE_VEB;
6523 veb->bridge_mode = BRIDGE_MODE_VEPA;
6524 i40e_config_bridge_mode(veb);
6526 /* create the remaining VSIs attached to this VEB */
6527 for (v = 0; v < pf->num_alloc_vsi; v++) {
6528 if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
6531 if (pf->vsi[v]->veb_idx == veb->idx) {
6532 struct i40e_vsi *vsi = pf->vsi[v];
6534 vsi->uplink_seid = veb->seid;
6535 ret = i40e_add_vsi(vsi);
6537 dev_info(&pf->pdev->dev,
6538 "rebuild of vsi_idx %d failed: %d\n",
6540 goto end_reconstitute;
6542 i40e_vsi_reset_stats(vsi);
6546 /* create any VEBs attached to this VEB - RECURSION */
6547 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
6548 if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
6549 pf->veb[veb_idx]->uplink_seid = veb->seid;
6550 ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
6561 * i40e_get_capabilities - get info about the HW
6562 * @pf: the PF struct
6564 static int i40e_get_capabilities(struct i40e_pf *pf)
6566 struct i40e_aqc_list_capabilities_element_resp *cap_buf;
6571 buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
6573 cap_buf = kzalloc(buf_len, GFP_KERNEL);
6577 /* this loads the data into the hw struct for us */
6578 err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
6580 i40e_aqc_opc_list_func_capabilities,
6582 /* data loaded, buffer no longer needed */
6585 if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
6586 /* retry with a larger buffer */
6587 buf_len = data_size;
6588 } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
6589 dev_info(&pf->pdev->dev,
6590 "capability discovery failed, err %s aq_err %s\n",
6591 i40e_stat_str(&pf->hw, err),
6592 i40e_aq_str(&pf->hw,
6593 pf->hw.aq.asq_last_status));
6598 if (pf->hw.debug_mask & I40E_DEBUG_USER)
6599 dev_info(&pf->pdev->dev,
6600 "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",
6601 pf->hw.pf_id, pf->hw.func_caps.num_vfs,
6602 pf->hw.func_caps.num_msix_vectors,
6603 pf->hw.func_caps.num_msix_vectors_vf,
6604 pf->hw.func_caps.fd_filters_guaranteed,
6605 pf->hw.func_caps.fd_filters_best_effort,
6606 pf->hw.func_caps.num_tx_qp,
6607 pf->hw.func_caps.num_vsis);
6609 #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
6610 + pf->hw.func_caps.num_vfs)
6611 if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
6612 dev_info(&pf->pdev->dev,
6613 "got num_vsis %d, setting num_vsis to %d\n",
6614 pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
6615 pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
6621 static int i40e_vsi_clear(struct i40e_vsi *vsi);
6624 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
6625 * @pf: board private structure
6627 static void i40e_fdir_sb_setup(struct i40e_pf *pf)
6629 struct i40e_vsi *vsi;
6632 /* quick workaround for an NVM issue that leaves a critical register
6635 if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
6636 static const u32 hkey[] = {
6637 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
6638 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
6639 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
6642 for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
6643 wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
6646 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
6649 /* find existing VSI and see if it needs configuring */
6651 for (i = 0; i < pf->num_alloc_vsi; i++) {
6652 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
6658 /* create a new VSI if none exists */
6660 vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
6661 pf->vsi[pf->lan_vsi]->seid, 0);
6663 dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
6664 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
6669 i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
6673 * i40e_fdir_teardown - release the Flow Director resources
6674 * @pf: board private structure
6676 static void i40e_fdir_teardown(struct i40e_pf *pf)
6680 i40e_fdir_filter_exit(pf);
6681 for (i = 0; i < pf->num_alloc_vsi; i++) {
6682 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
6683 i40e_vsi_release(pf->vsi[i]);
6690 * i40e_prep_for_reset - prep for the core to reset
6691 * @pf: board private structure
6693 * Close up the VFs and other things in prep for PF Reset.
6695 static void i40e_prep_for_reset(struct i40e_pf *pf)
6697 struct i40e_hw *hw = &pf->hw;
6698 i40e_status ret = 0;
6701 clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
6702 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
6704 if (i40e_check_asq_alive(&pf->hw))
6705 i40e_vc_notify_reset(pf);
6707 dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
6709 /* quiesce the VSIs and their queues that are not already DOWN */
6710 i40e_pf_quiesce_all_vsi(pf);
6712 for (v = 0; v < pf->num_alloc_vsi; v++) {
6714 pf->vsi[v]->seid = 0;
6717 i40e_shutdown_adminq(&pf->hw);
6719 /* call shutdown HMC */
6720 if (hw->hmc.hmc_obj) {
6721 ret = i40e_shutdown_lan_hmc(hw);
6723 dev_warn(&pf->pdev->dev,
6724 "shutdown_lan_hmc failed: %d\n", ret);
6729 * i40e_send_version - update firmware with driver version
6732 static void i40e_send_version(struct i40e_pf *pf)
6734 struct i40e_driver_version dv;
6736 dv.major_version = DRV_VERSION_MAJOR;
6737 dv.minor_version = DRV_VERSION_MINOR;
6738 dv.build_version = DRV_VERSION_BUILD;
6739 dv.subbuild_version = 0;
6740 strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
6741 i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
6745 * i40e_reset_and_rebuild - reset and rebuild using a saved config
6746 * @pf: board private structure
6747 * @reinit: if the Main VSI needs to re-initialized.
6749 static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
6751 struct i40e_hw *hw = &pf->hw;
6752 u8 set_fc_aq_fail = 0;
6757 /* Now we wait for GRST to settle out.
6758 * We don't have to delete the VEBs or VSIs from the hw switch
6759 * because the reset will make them disappear.
6761 ret = i40e_pf_reset(hw);
6763 dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
6764 set_bit(__I40E_RESET_FAILED, &pf->state);
6765 goto clear_recovery;
6769 if (test_bit(__I40E_DOWN, &pf->state))
6770 goto clear_recovery;
6771 dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
6773 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
6774 ret = i40e_init_adminq(&pf->hw);
6776 dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
6777 i40e_stat_str(&pf->hw, ret),
6778 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6779 goto clear_recovery;
6782 /* re-verify the eeprom if we just had an EMP reset */
6783 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state))
6784 i40e_verify_eeprom(pf);
6786 i40e_clear_pxe_mode(hw);
6787 ret = i40e_get_capabilities(pf);
6789 goto end_core_reset;
6791 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
6792 hw->func_caps.num_rx_qp,
6793 pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
6795 dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
6796 goto end_core_reset;
6798 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
6800 dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
6801 goto end_core_reset;
6804 #ifdef CONFIG_I40E_DCB
6805 ret = i40e_init_pf_dcb(pf);
6807 dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
6808 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
6809 /* Continue without DCB enabled */
6811 #endif /* CONFIG_I40E_DCB */
6813 i40e_init_pf_fcoe(pf);
6816 /* do basic switch setup */
6817 ret = i40e_setup_pf_switch(pf, reinit);
6819 goto end_core_reset;
6821 /* The driver only wants link up/down and module qualification
6822 * reports from firmware. Note the negative logic.
6824 ret = i40e_aq_set_phy_int_mask(&pf->hw,
6825 ~(I40E_AQ_EVENT_LINK_UPDOWN |
6826 I40E_AQ_EVENT_MEDIA_NA |
6827 I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
6829 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
6830 i40e_stat_str(&pf->hw, ret),
6831 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6833 /* make sure our flow control settings are restored */
6834 ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
6836 dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
6837 i40e_stat_str(&pf->hw, ret),
6838 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6840 /* Rebuild the VSIs and VEBs that existed before reset.
6841 * They are still in our local switch element arrays, so only
6842 * need to rebuild the switch model in the HW.
6844 * If there were VEBs but the reconstitution failed, we'll try
6845 * try to recover minimal use by getting the basic PF VSI working.
6847 if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
6848 dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
6849 /* find the one VEB connected to the MAC, and find orphans */
6850 for (v = 0; v < I40E_MAX_VEB; v++) {
6854 if (pf->veb[v]->uplink_seid == pf->mac_seid ||
6855 pf->veb[v]->uplink_seid == 0) {
6856 ret = i40e_reconstitute_veb(pf->veb[v]);
6861 /* If Main VEB failed, we're in deep doodoo,
6862 * so give up rebuilding the switch and set up
6863 * for minimal rebuild of PF VSI.
6864 * If orphan failed, we'll report the error
6865 * but try to keep going.
6867 if (pf->veb[v]->uplink_seid == pf->mac_seid) {
6868 dev_info(&pf->pdev->dev,
6869 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
6871 pf->vsi[pf->lan_vsi]->uplink_seid
6874 } else if (pf->veb[v]->uplink_seid == 0) {
6875 dev_info(&pf->pdev->dev,
6876 "rebuild of orphan VEB failed: %d\n",
6883 if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
6884 dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
6885 /* no VEB, so rebuild only the Main VSI */
6886 ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
6888 dev_info(&pf->pdev->dev,
6889 "rebuild of Main VSI failed: %d\n", ret);
6890 goto end_core_reset;
6894 /* Reconfigure hardware for allowing smaller MSS in the case
6895 * of TSO, so that we avoid the MDD being fired and causing
6896 * a reset in the case of small MSS+TSO.
6898 #define I40E_REG_MSS 0x000E64DC
6899 #define I40E_REG_MSS_MIN_MASK 0x3FF0000
6900 #define I40E_64BYTE_MSS 0x400000
6901 val = rd32(hw, I40E_REG_MSS);
6902 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
6903 val &= ~I40E_REG_MSS_MIN_MASK;
6904 val |= I40E_64BYTE_MSS;
6905 wr32(hw, I40E_REG_MSS, val);
6908 if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
6910 ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
6912 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
6913 i40e_stat_str(&pf->hw, ret),
6914 i40e_aq_str(&pf->hw,
6915 pf->hw.aq.asq_last_status));
6917 /* reinit the misc interrupt */
6918 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
6919 ret = i40e_setup_misc_vector(pf);
6921 /* Add a filter to drop all Flow control frames from any VSI from being
6922 * transmitted. By doing so we stop a malicious VF from sending out
6923 * PAUSE or PFC frames and potentially controlling traffic for other
6925 * The FW can still send Flow control frames if enabled.
6927 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
6930 /* restart the VSIs that were rebuilt and running before the reset */
6931 i40e_pf_unquiesce_all_vsi(pf);
6933 if (pf->num_alloc_vfs) {
6934 for (v = 0; v < pf->num_alloc_vfs; v++)
6935 i40e_reset_vf(&pf->vf[v], true);
6938 /* tell the firmware that we're starting */
6939 i40e_send_version(pf);
6942 clear_bit(__I40E_RESET_FAILED, &pf->state);
6944 clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
6948 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
6949 * @pf: board private structure
6951 * Close up the VFs and other things in prep for a Core Reset,
6952 * then get ready to rebuild the world.
6954 static void i40e_handle_reset_warning(struct i40e_pf *pf)
6956 i40e_prep_for_reset(pf);
6957 i40e_reset_and_rebuild(pf, false);
6961 * i40e_handle_mdd_event
6962 * @pf: pointer to the PF structure
6964 * Called from the MDD irq handler to identify possibly malicious vfs
6966 static void i40e_handle_mdd_event(struct i40e_pf *pf)
6968 struct i40e_hw *hw = &pf->hw;
6969 bool mdd_detected = false;
6970 bool pf_mdd_detected = false;
6975 if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state))
6978 /* find what triggered the MDD event */
6979 reg = rd32(hw, I40E_GL_MDET_TX);
6980 if (reg & I40E_GL_MDET_TX_VALID_MASK) {
6981 u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
6982 I40E_GL_MDET_TX_PF_NUM_SHIFT;
6983 u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
6984 I40E_GL_MDET_TX_VF_NUM_SHIFT;
6985 u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
6986 I40E_GL_MDET_TX_EVENT_SHIFT;
6987 u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
6988 I40E_GL_MDET_TX_QUEUE_SHIFT) -
6989 pf->hw.func_caps.base_queue;
6990 if (netif_msg_tx_err(pf))
6991 dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
6992 event, queue, pf_num, vf_num);
6993 wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
6994 mdd_detected = true;
6996 reg = rd32(hw, I40E_GL_MDET_RX);
6997 if (reg & I40E_GL_MDET_RX_VALID_MASK) {
6998 u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
6999 I40E_GL_MDET_RX_FUNCTION_SHIFT;
7000 u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
7001 I40E_GL_MDET_RX_EVENT_SHIFT;
7002 u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
7003 I40E_GL_MDET_RX_QUEUE_SHIFT) -
7004 pf->hw.func_caps.base_queue;
7005 if (netif_msg_rx_err(pf))
7006 dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
7007 event, queue, func);
7008 wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
7009 mdd_detected = true;
7013 reg = rd32(hw, I40E_PF_MDET_TX);
7014 if (reg & I40E_PF_MDET_TX_VALID_MASK) {
7015 wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
7016 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
7017 pf_mdd_detected = true;
7019 reg = rd32(hw, I40E_PF_MDET_RX);
7020 if (reg & I40E_PF_MDET_RX_VALID_MASK) {
7021 wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
7022 dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
7023 pf_mdd_detected = true;
7025 /* Queue belongs to the PF, initiate a reset */
7026 if (pf_mdd_detected) {
7027 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
7028 i40e_service_event_schedule(pf);
7032 /* see if one of the VFs needs its hand slapped */
7033 for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
7035 reg = rd32(hw, I40E_VP_MDET_TX(i));
7036 if (reg & I40E_VP_MDET_TX_VALID_MASK) {
7037 wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
7038 vf->num_mdd_events++;
7039 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
7043 reg = rd32(hw, I40E_VP_MDET_RX(i));
7044 if (reg & I40E_VP_MDET_RX_VALID_MASK) {
7045 wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
7046 vf->num_mdd_events++;
7047 dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
7051 if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
7052 dev_info(&pf->pdev->dev,
7053 "Too many MDD events on VF %d, disabled\n", i);
7054 dev_info(&pf->pdev->dev,
7055 "Use PF Control I/F to re-enable the VF\n");
7056 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
7060 /* re-enable mdd interrupt cause */
7061 clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
7062 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
7063 reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
7064 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
7069 * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
7070 * @pf: board private structure
7072 static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
7074 struct i40e_hw *hw = &pf->hw;
7079 if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC))
7082 pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC;
7084 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
7085 if (pf->pending_udp_bitmap & BIT_ULL(i)) {
7086 pf->pending_udp_bitmap &= ~BIT_ULL(i);
7087 port = pf->udp_ports[i].index;
7089 ret = i40e_aq_add_udp_tunnel(hw, ntohs(port),
7090 pf->udp_ports[i].type,
7093 ret = i40e_aq_del_udp_tunnel(hw, i, NULL);
7096 dev_dbg(&pf->pdev->dev,
7097 "%s %s port %d, index %d failed, err %s aq_err %s\n",
7098 pf->udp_ports[i].type ? "vxlan" : "geneve",
7099 port ? "add" : "delete",
7101 i40e_stat_str(&pf->hw, ret),
7102 i40e_aq_str(&pf->hw,
7103 pf->hw.aq.asq_last_status));
7104 pf->udp_ports[i].index = 0;
7111 * i40e_service_task - Run the driver's async subtasks
7112 * @work: pointer to work_struct containing our data
7114 static void i40e_service_task(struct work_struct *work)
7116 struct i40e_pf *pf = container_of(work,
7119 unsigned long start_time = jiffies;
7121 /* don't bother with service tasks if a reset is in progress */
7122 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
7123 i40e_service_event_complete(pf);
7127 i40e_detect_recover_hung(pf);
7128 i40e_sync_filters_subtask(pf);
7129 i40e_reset_subtask(pf);
7130 i40e_handle_mdd_event(pf);
7131 i40e_vc_process_vflr_event(pf);
7132 i40e_watchdog_subtask(pf);
7133 i40e_fdir_reinit_subtask(pf);
7134 i40e_client_subtask(pf);
7135 i40e_sync_filters_subtask(pf);
7136 i40e_sync_udp_filters_subtask(pf);
7137 i40e_clean_adminq_subtask(pf);
7139 i40e_service_event_complete(pf);
7141 /* If the tasks have taken longer than one timer cycle or there
7142 * is more work to be done, reschedule the service task now
7143 * rather than wait for the timer to tick again.
7145 if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
7146 test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) ||
7147 test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) ||
7148 test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
7149 i40e_service_event_schedule(pf);
7153 * i40e_service_timer - timer callback
7154 * @data: pointer to PF struct
7156 static void i40e_service_timer(unsigned long data)
7158 struct i40e_pf *pf = (struct i40e_pf *)data;
7160 mod_timer(&pf->service_timer,
7161 round_jiffies(jiffies + pf->service_timer_period));
7162 i40e_service_event_schedule(pf);
7166 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
7167 * @vsi: the VSI being configured
7169 static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
7171 struct i40e_pf *pf = vsi->back;
7173 switch (vsi->type) {
7175 vsi->alloc_queue_pairs = pf->num_lan_qps;
7176 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7177 I40E_REQ_DESCRIPTOR_MULTIPLE);
7178 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7179 vsi->num_q_vectors = pf->num_lan_msix;
7181 vsi->num_q_vectors = 1;
7186 vsi->alloc_queue_pairs = 1;
7187 vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
7188 I40E_REQ_DESCRIPTOR_MULTIPLE);
7189 vsi->num_q_vectors = pf->num_fdsb_msix;
7192 case I40E_VSI_VMDQ2:
7193 vsi->alloc_queue_pairs = pf->num_vmdq_qps;
7194 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7195 I40E_REQ_DESCRIPTOR_MULTIPLE);
7196 vsi->num_q_vectors = pf->num_vmdq_msix;
7199 case I40E_VSI_SRIOV:
7200 vsi->alloc_queue_pairs = pf->num_vf_qps;
7201 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7202 I40E_REQ_DESCRIPTOR_MULTIPLE);
7207 vsi->alloc_queue_pairs = pf->num_fcoe_qps;
7208 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7209 I40E_REQ_DESCRIPTOR_MULTIPLE);
7210 vsi->num_q_vectors = pf->num_fcoe_msix;
7213 #endif /* I40E_FCOE */
7223 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
7224 * @type: VSI pointer
7225 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
7227 * On error: returns error code (negative)
7228 * On success: returns 0
7230 static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
7235 /* allocate memory for both Tx and Rx ring pointers */
7236 size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2;
7237 vsi->tx_rings = kzalloc(size, GFP_KERNEL);
7240 vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs];
7242 if (alloc_qvectors) {
7243 /* allocate memory for q_vector pointers */
7244 size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
7245 vsi->q_vectors = kzalloc(size, GFP_KERNEL);
7246 if (!vsi->q_vectors) {
7254 kfree(vsi->tx_rings);
7259 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
7260 * @pf: board private structure
7261 * @type: type of VSI
7263 * On error: returns error code (negative)
7264 * On success: returns vsi index in PF (positive)
7266 static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
7269 struct i40e_vsi *vsi;
7273 /* Need to protect the allocation of the VSIs at the PF level */
7274 mutex_lock(&pf->switch_mutex);
7276 /* VSI list may be fragmented if VSI creation/destruction has
7277 * been happening. We can afford to do a quick scan to look
7278 * for any free VSIs in the list.
7280 * find next empty vsi slot, looping back around if necessary
7283 while (i < pf->num_alloc_vsi && pf->vsi[i])
7285 if (i >= pf->num_alloc_vsi) {
7287 while (i < pf->next_vsi && pf->vsi[i])
7291 if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
7292 vsi_idx = i; /* Found one! */
7295 goto unlock_pf; /* out of VSI slots! */
7299 vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
7306 set_bit(__I40E_DOWN, &vsi->state);
7309 vsi->int_rate_limit = 0;
7310 vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
7311 pf->rss_table_size : 64;
7312 vsi->netdev_registered = false;
7313 vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
7314 INIT_LIST_HEAD(&vsi->mac_filter_list);
7315 vsi->irqs_ready = false;
7317 ret = i40e_set_num_rings_in_vsi(vsi);
7321 ret = i40e_vsi_alloc_arrays(vsi, true);
7325 /* Setup default MSIX irq handler for VSI */
7326 i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
7328 /* Initialize VSI lock */
7329 spin_lock_init(&vsi->mac_filter_list_lock);
7330 pf->vsi[vsi_idx] = vsi;
7335 pf->next_vsi = i - 1;
7338 mutex_unlock(&pf->switch_mutex);
7343 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
7344 * @type: VSI pointer
7345 * @free_qvectors: a bool to specify if q_vectors need to be freed.
7347 * On error: returns error code (negative)
7348 * On success: returns 0
7350 static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
7352 /* free the ring and vector containers */
7353 if (free_qvectors) {
7354 kfree(vsi->q_vectors);
7355 vsi->q_vectors = NULL;
7357 kfree(vsi->tx_rings);
7358 vsi->tx_rings = NULL;
7359 vsi->rx_rings = NULL;
7363 * i40e_clear_rss_config_user - clear the user configured RSS hash keys
7365 * @vsi: Pointer to VSI structure
7367 static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
7372 kfree(vsi->rss_hkey_user);
7373 vsi->rss_hkey_user = NULL;
7375 kfree(vsi->rss_lut_user);
7376 vsi->rss_lut_user = NULL;
7380 * i40e_vsi_clear - Deallocate the VSI provided
7381 * @vsi: the VSI being un-configured
7383 static int i40e_vsi_clear(struct i40e_vsi *vsi)
7394 mutex_lock(&pf->switch_mutex);
7395 if (!pf->vsi[vsi->idx]) {
7396 dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
7397 vsi->idx, vsi->idx, vsi, vsi->type);
7401 if (pf->vsi[vsi->idx] != vsi) {
7402 dev_err(&pf->pdev->dev,
7403 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
7404 pf->vsi[vsi->idx]->idx,
7406 pf->vsi[vsi->idx]->type,
7407 vsi->idx, vsi, vsi->type);
7411 /* updates the PF for this cleared vsi */
7412 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
7413 i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
7415 i40e_vsi_free_arrays(vsi, true);
7416 i40e_clear_rss_config_user(vsi);
7418 pf->vsi[vsi->idx] = NULL;
7419 if (vsi->idx < pf->next_vsi)
7420 pf->next_vsi = vsi->idx;
7423 mutex_unlock(&pf->switch_mutex);
7431 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
7432 * @vsi: the VSI being cleaned
7434 static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
7438 if (vsi->tx_rings && vsi->tx_rings[0]) {
7439 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
7440 kfree_rcu(vsi->tx_rings[i], rcu);
7441 vsi->tx_rings[i] = NULL;
7442 vsi->rx_rings[i] = NULL;
7448 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
7449 * @vsi: the VSI being configured
7451 static int i40e_alloc_rings(struct i40e_vsi *vsi)
7453 struct i40e_ring *tx_ring, *rx_ring;
7454 struct i40e_pf *pf = vsi->back;
7457 /* Set basic values in the rings to be used later during open() */
7458 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
7459 /* allocate space for both Tx and Rx in one shot */
7460 tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
7464 tx_ring->queue_index = i;
7465 tx_ring->reg_idx = vsi->base_queue + i;
7466 tx_ring->ring_active = false;
7468 tx_ring->netdev = vsi->netdev;
7469 tx_ring->dev = &pf->pdev->dev;
7470 tx_ring->count = vsi->num_desc;
7472 tx_ring->dcb_tc = 0;
7473 if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
7474 tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
7475 tx_ring->tx_itr_setting = pf->tx_itr_default;
7476 vsi->tx_rings[i] = tx_ring;
7478 rx_ring = &tx_ring[1];
7479 rx_ring->queue_index = i;
7480 rx_ring->reg_idx = vsi->base_queue + i;
7481 rx_ring->ring_active = false;
7483 rx_ring->netdev = vsi->netdev;
7484 rx_ring->dev = &pf->pdev->dev;
7485 rx_ring->count = vsi->num_desc;
7487 rx_ring->dcb_tc = 0;
7488 rx_ring->rx_itr_setting = pf->rx_itr_default;
7489 vsi->rx_rings[i] = rx_ring;
7495 i40e_vsi_clear_rings(vsi);
7500 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
7501 * @pf: board private structure
7502 * @vectors: the number of MSI-X vectors to request
7504 * Returns the number of vectors reserved, or error
7506 static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
7508 vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
7509 I40E_MIN_MSIX, vectors);
7511 dev_info(&pf->pdev->dev,
7512 "MSI-X vector reservation failed: %d\n", vectors);
7520 * i40e_init_msix - Setup the MSIX capability
7521 * @pf: board private structure
7523 * Work with the OS to set up the MSIX vectors needed.
7525 * Returns the number of vectors reserved or negative on failure
7527 static int i40e_init_msix(struct i40e_pf *pf)
7529 struct i40e_hw *hw = &pf->hw;
7533 int iwarp_requested = 0;
7535 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
7538 /* The number of vectors we'll request will be comprised of:
7539 * - Add 1 for "other" cause for Admin Queue events, etc.
7540 * - The number of LAN queue pairs
7541 * - Queues being used for RSS.
7542 * We don't need as many as max_rss_size vectors.
7543 * use rss_size instead in the calculation since that
7544 * is governed by number of cpus in the system.
7545 * - assumes symmetric Tx/Rx pairing
7546 * - The number of VMDq pairs
7547 * - The CPU count within the NUMA node if iWARP is enabled
7549 * - The number of FCOE qps.
7551 * Once we count this up, try the request.
7553 * If we can't get what we want, we'll simplify to nearly nothing
7554 * and try again. If that still fails, we punt.
7556 vectors_left = hw->func_caps.num_msix_vectors;
7559 /* reserve one vector for miscellaneous handler */
7565 /* reserve vectors for the main PF traffic queues */
7566 pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left);
7567 vectors_left -= pf->num_lan_msix;
7568 v_budget += pf->num_lan_msix;
7570 /* reserve one vector for sideband flow director */
7571 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
7573 pf->num_fdsb_msix = 1;
7577 pf->num_fdsb_msix = 0;
7578 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
7583 /* can we reserve enough for FCoE? */
7584 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
7586 pf->num_fcoe_msix = 0;
7587 else if (vectors_left >= pf->num_fcoe_qps)
7588 pf->num_fcoe_msix = pf->num_fcoe_qps;
7590 pf->num_fcoe_msix = 1;
7591 v_budget += pf->num_fcoe_msix;
7592 vectors_left -= pf->num_fcoe_msix;
7596 /* can we reserve enough for iWARP? */
7597 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
7599 pf->num_iwarp_msix = 0;
7600 else if (vectors_left < pf->num_iwarp_msix)
7601 pf->num_iwarp_msix = 1;
7602 v_budget += pf->num_iwarp_msix;
7603 vectors_left -= pf->num_iwarp_msix;
7606 /* any vectors left over go for VMDq support */
7607 if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
7608 int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps;
7609 int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted);
7611 /* if we're short on vectors for what's desired, we limit
7612 * the queues per vmdq. If this is still more than are
7613 * available, the user will need to change the number of
7614 * queues/vectors used by the PF later with the ethtool
7617 if (vmdq_vecs < vmdq_vecs_wanted)
7618 pf->num_vmdq_qps = 1;
7619 pf->num_vmdq_msix = pf->num_vmdq_qps;
7621 v_budget += vmdq_vecs;
7622 vectors_left -= vmdq_vecs;
7625 pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
7627 if (!pf->msix_entries)
7630 for (i = 0; i < v_budget; i++)
7631 pf->msix_entries[i].entry = i;
7632 v_actual = i40e_reserve_msix_vectors(pf, v_budget);
7634 if (v_actual != v_budget) {
7635 /* If we have limited resources, we will start with no vectors
7636 * for the special features and then allocate vectors to some
7637 * of these features based on the policy and at the end disable
7638 * the features that did not get any vectors.
7640 iwarp_requested = pf->num_iwarp_msix;
7641 pf->num_iwarp_msix = 0;
7643 pf->num_fcoe_qps = 0;
7644 pf->num_fcoe_msix = 0;
7646 pf->num_vmdq_msix = 0;
7649 if (v_actual < I40E_MIN_MSIX) {
7650 pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
7651 kfree(pf->msix_entries);
7652 pf->msix_entries = NULL;
7655 } else if (v_actual == I40E_MIN_MSIX) {
7656 /* Adjust for minimal MSIX use */
7657 pf->num_vmdq_vsis = 0;
7658 pf->num_vmdq_qps = 0;
7659 pf->num_lan_qps = 1;
7660 pf->num_lan_msix = 1;
7662 } else if (v_actual != v_budget) {
7665 /* reserve the misc vector */
7668 /* Scale vector usage down */
7669 pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
7670 pf->num_vmdq_vsis = 1;
7671 pf->num_vmdq_qps = 1;
7672 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
7674 /* partition out the remaining vectors */
7677 pf->num_lan_msix = 1;
7680 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
7681 pf->num_lan_msix = 1;
7682 pf->num_iwarp_msix = 1;
7684 pf->num_lan_msix = 2;
7687 /* give one vector to FCoE */
7688 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
7689 pf->num_lan_msix = 1;
7690 pf->num_fcoe_msix = 1;
7695 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
7696 pf->num_iwarp_msix = min_t(int, (vec / 3),
7698 pf->num_vmdq_vsis = min_t(int, (vec / 3),
7699 I40E_DEFAULT_NUM_VMDQ_VSI);
7701 pf->num_vmdq_vsis = min_t(int, (vec / 2),
7702 I40E_DEFAULT_NUM_VMDQ_VSI);
7704 pf->num_lan_msix = min_t(int,
7705 (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)),
7708 /* give one vector to FCoE */
7709 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
7710 pf->num_fcoe_msix = 1;
7718 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
7719 (pf->num_vmdq_msix == 0)) {
7720 dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
7721 pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
7724 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
7725 (pf->num_iwarp_msix == 0)) {
7726 dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n");
7727 pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
7731 if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) {
7732 dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n");
7733 pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
7740 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
7741 * @vsi: the VSI being configured
7742 * @v_idx: index of the vector in the vsi struct
7744 * We allocate one q_vector. If allocation fails we return -ENOMEM.
7746 static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx)
7748 struct i40e_q_vector *q_vector;
7750 /* allocate q_vector */
7751 q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
7755 q_vector->vsi = vsi;
7756 q_vector->v_idx = v_idx;
7757 cpumask_set_cpu(v_idx, &q_vector->affinity_mask);
7759 netif_napi_add(vsi->netdev, &q_vector->napi,
7760 i40e_napi_poll, NAPI_POLL_WEIGHT);
7762 q_vector->rx.latency_range = I40E_LOW_LATENCY;
7763 q_vector->tx.latency_range = I40E_LOW_LATENCY;
7765 /* tie q_vector and vsi together */
7766 vsi->q_vectors[v_idx] = q_vector;
7772 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
7773 * @vsi: the VSI being configured
7775 * We allocate one q_vector per queue interrupt. If allocation fails we
7778 static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
7780 struct i40e_pf *pf = vsi->back;
7781 int v_idx, num_q_vectors;
7784 /* if not MSIX, give the one vector only to the LAN VSI */
7785 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7786 num_q_vectors = vsi->num_q_vectors;
7787 else if (vsi == pf->vsi[pf->lan_vsi])
7792 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
7793 err = i40e_vsi_alloc_q_vector(vsi, v_idx);
7802 i40e_free_q_vector(vsi, v_idx);
7808 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
7809 * @pf: board private structure to initialize
7811 static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
7816 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
7817 vectors = i40e_init_msix(pf);
7819 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
7820 I40E_FLAG_IWARP_ENABLED |
7822 I40E_FLAG_FCOE_ENABLED |
7824 I40E_FLAG_RSS_ENABLED |
7825 I40E_FLAG_DCB_CAPABLE |
7826 I40E_FLAG_SRIOV_ENABLED |
7827 I40E_FLAG_FD_SB_ENABLED |
7828 I40E_FLAG_FD_ATR_ENABLED |
7829 I40E_FLAG_VMDQ_ENABLED);
7831 /* rework the queue expectations without MSIX */
7832 i40e_determine_queue_usage(pf);
7836 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
7837 (pf->flags & I40E_FLAG_MSI_ENABLED)) {
7838 dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
7839 vectors = pci_enable_msi(pf->pdev);
7841 dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
7843 pf->flags &= ~I40E_FLAG_MSI_ENABLED;
7845 vectors = 1; /* one MSI or Legacy vector */
7848 if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
7849 dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
7851 /* set up vector assignment tracking */
7852 size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
7853 pf->irq_pile = kzalloc(size, GFP_KERNEL);
7854 if (!pf->irq_pile) {
7855 dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n");
7858 pf->irq_pile->num_entries = vectors;
7859 pf->irq_pile->search_hint = 0;
7861 /* track first vector for misc interrupts, ignore return */
7862 (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
7868 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
7869 * @pf: board private structure
7871 * This sets up the handler for MSIX 0, which is used to manage the
7872 * non-queue interrupts, e.g. AdminQ and errors. This is not used
7873 * when in MSI or Legacy interrupt mode.
7875 static int i40e_setup_misc_vector(struct i40e_pf *pf)
7877 struct i40e_hw *hw = &pf->hw;
7880 /* Only request the irq if this is the first time through, and
7881 * not when we're rebuilding after a Reset
7883 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
7884 err = request_irq(pf->msix_entries[0].vector,
7885 i40e_intr, 0, pf->int_name, pf);
7887 dev_info(&pf->pdev->dev,
7888 "request_irq for %s failed: %d\n",
7894 i40e_enable_misc_int_causes(pf);
7896 /* associate no queues to the misc vector */
7897 wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
7898 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
7902 i40e_irq_dynamic_enable_icr0(pf, true);
7908 * i40e_config_rss_aq - Prepare for RSS using AQ commands
7909 * @vsi: vsi structure
7910 * @seed: RSS hash seed
7912 static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
7913 u8 *lut, u16 lut_size)
7915 struct i40e_aqc_get_set_rss_key_data rss_key;
7916 struct i40e_pf *pf = vsi->back;
7917 struct i40e_hw *hw = &pf->hw;
7918 bool pf_lut = false;
7922 memset(&rss_key, 0, sizeof(rss_key));
7923 memcpy(&rss_key, seed, sizeof(rss_key));
7925 rss_lut = kzalloc(pf->rss_table_size, GFP_KERNEL);
7929 /* Populate the LUT with max no. of queues in round robin fashion */
7930 for (i = 0; i < vsi->rss_table_size; i++)
7931 rss_lut[i] = i % vsi->rss_size;
7933 ret = i40e_aq_set_rss_key(hw, vsi->id, &rss_key);
7935 dev_info(&pf->pdev->dev,
7936 "Cannot set RSS key, err %s aq_err %s\n",
7937 i40e_stat_str(&pf->hw, ret),
7938 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
7939 goto config_rss_aq_out;
7942 if (vsi->type == I40E_VSI_MAIN)
7945 ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, rss_lut,
7946 vsi->rss_table_size);
7948 dev_info(&pf->pdev->dev,
7949 "Cannot set RSS lut, err %s aq_err %s\n",
7950 i40e_stat_str(&pf->hw, ret),
7951 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
7959 * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
7960 * @vsi: VSI structure
7962 static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
7964 u8 seed[I40E_HKEY_ARRAY_SIZE];
7965 struct i40e_pf *pf = vsi->back;
7969 if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE))
7972 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
7976 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
7977 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
7978 vsi->rss_size = min_t(int, pf->alloc_rss_size, vsi->num_queue_pairs);
7979 ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
7986 * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
7987 * @vsi: Pointer to vsi structure
7988 * @seed: Buffter to store the hash keys
7989 * @lut: Buffer to store the lookup table entries
7990 * @lut_size: Size of buffer to store the lookup table entries
7992 * Return 0 on success, negative on failure
7994 static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
7995 u8 *lut, u16 lut_size)
7997 struct i40e_pf *pf = vsi->back;
7998 struct i40e_hw *hw = &pf->hw;
8002 ret = i40e_aq_get_rss_key(hw, vsi->id,
8003 (struct i40e_aqc_get_set_rss_key_data *)seed);
8005 dev_info(&pf->pdev->dev,
8006 "Cannot get RSS key, err %s aq_err %s\n",
8007 i40e_stat_str(&pf->hw, ret),
8008 i40e_aq_str(&pf->hw,
8009 pf->hw.aq.asq_last_status));
8015 bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
8017 ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
8019 dev_info(&pf->pdev->dev,
8020 "Cannot get RSS lut, err %s aq_err %s\n",
8021 i40e_stat_str(&pf->hw, ret),
8022 i40e_aq_str(&pf->hw,
8023 pf->hw.aq.asq_last_status));
8032 * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
8033 * @vsi: Pointer to vsi structure
8034 * @seed: RSS hash seed
8035 * @lut: Lookup table
8036 * @lut_size: Lookup table size
8038 * Returns 0 on success, negative on failure
8040 static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
8041 const u8 *lut, u16 lut_size)
8043 struct i40e_pf *pf = vsi->back;
8044 struct i40e_hw *hw = &pf->hw;
8045 u16 vf_id = vsi->vf_id;
8048 /* Fill out hash function seed */
8050 u32 *seed_dw = (u32 *)seed;
8052 if (vsi->type == I40E_VSI_MAIN) {
8053 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
8054 i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i),
8056 } else if (vsi->type == I40E_VSI_SRIOV) {
8057 for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++)
8058 i40e_write_rx_ctl(hw,
8059 I40E_VFQF_HKEY1(i, vf_id),
8062 dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n");
8067 u32 *lut_dw = (u32 *)lut;
8069 if (vsi->type == I40E_VSI_MAIN) {
8070 if (lut_size != I40E_HLUT_ARRAY_SIZE)
8072 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
8073 wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
8074 } else if (vsi->type == I40E_VSI_SRIOV) {
8075 if (lut_size != I40E_VF_HLUT_ARRAY_SIZE)
8077 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
8078 i40e_write_rx_ctl(hw,
8079 I40E_VFQF_HLUT1(i, vf_id),
8082 dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
8091 * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
8092 * @vsi: Pointer to VSI structure
8093 * @seed: Buffer to store the keys
8094 * @lut: Buffer to store the lookup table entries
8095 * @lut_size: Size of buffer to store the lookup table entries
8097 * Returns 0 on success, negative on failure
8099 static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
8100 u8 *lut, u16 lut_size)
8102 struct i40e_pf *pf = vsi->back;
8103 struct i40e_hw *hw = &pf->hw;
8107 u32 *seed_dw = (u32 *)seed;
8109 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
8110 seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
8113 u32 *lut_dw = (u32 *)lut;
8115 if (lut_size != I40E_HLUT_ARRAY_SIZE)
8117 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
8118 lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
8125 * i40e_config_rss - Configure RSS keys and lut
8126 * @vsi: Pointer to VSI structure
8127 * @seed: RSS hash seed
8128 * @lut: Lookup table
8129 * @lut_size: Lookup table size
8131 * Returns 0 on success, negative on failure
8133 int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
8135 struct i40e_pf *pf = vsi->back;
8137 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
8138 return i40e_config_rss_aq(vsi, seed, lut, lut_size);
8140 return i40e_config_rss_reg(vsi, seed, lut, lut_size);
8144 * i40e_get_rss - Get RSS keys and lut
8145 * @vsi: Pointer to VSI structure
8146 * @seed: Buffer to store the keys
8147 * @lut: Buffer to store the lookup table entries
8148 * lut_size: Size of buffer to store the lookup table entries
8150 * Returns 0 on success, negative on failure
8152 int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
8154 struct i40e_pf *pf = vsi->back;
8156 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
8157 return i40e_get_rss_aq(vsi, seed, lut, lut_size);
8159 return i40e_get_rss_reg(vsi, seed, lut, lut_size);
8163 * i40e_fill_rss_lut - Fill the RSS lookup table with default values
8164 * @pf: Pointer to board private structure
8165 * @lut: Lookup table
8166 * @rss_table_size: Lookup table size
8167 * @rss_size: Range of queue number for hashing
8169 static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
8170 u16 rss_table_size, u16 rss_size)
8174 for (i = 0; i < rss_table_size; i++)
8175 lut[i] = i % rss_size;
8179 * i40e_pf_config_rss - Prepare for RSS if used
8180 * @pf: board private structure
8182 static int i40e_pf_config_rss(struct i40e_pf *pf)
8184 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
8185 u8 seed[I40E_HKEY_ARRAY_SIZE];
8187 struct i40e_hw *hw = &pf->hw;
8192 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
8193 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
8194 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
8195 hena |= i40e_pf_get_default_rss_hena(pf);
8197 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
8198 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
8200 /* Determine the RSS table size based on the hardware capabilities */
8201 reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
8202 reg_val = (pf->rss_table_size == 512) ?
8203 (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
8204 (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
8205 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val);
8207 /* Determine the RSS size of the VSI */
8209 vsi->rss_size = min_t(int, pf->alloc_rss_size,
8210 vsi->num_queue_pairs);
8212 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
8216 /* Use user configured lut if there is one, otherwise use default */
8217 if (vsi->rss_lut_user)
8218 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
8220 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
8222 /* Use user configured hash key if there is one, otherwise
8225 if (vsi->rss_hkey_user)
8226 memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
8228 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
8229 ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
8236 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
8237 * @pf: board private structure
8238 * @queue_count: the requested queue count for rss.
8240 * returns 0 if rss is not enabled, if enabled returns the final rss queue
8241 * count which may be different from the requested queue count.
8243 int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
8245 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
8248 if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
8251 new_rss_size = min_t(int, queue_count, pf->rss_size_max);
8253 if (queue_count != vsi->num_queue_pairs) {
8254 vsi->req_queue_pairs = queue_count;
8255 i40e_prep_for_reset(pf);
8257 pf->alloc_rss_size = new_rss_size;
8259 i40e_reset_and_rebuild(pf, true);
8261 /* Discard the user configured hash keys and lut, if less
8262 * queues are enabled.
8264 if (queue_count < vsi->rss_size) {
8265 i40e_clear_rss_config_user(vsi);
8266 dev_dbg(&pf->pdev->dev,
8267 "discard user configured hash keys and lut\n");
8270 /* Reset vsi->rss_size, as number of enabled queues changed */
8271 vsi->rss_size = min_t(int, pf->alloc_rss_size,
8272 vsi->num_queue_pairs);
8274 i40e_pf_config_rss(pf);
8276 dev_info(&pf->pdev->dev, "RSS count/HW max RSS count: %d/%d\n",
8277 pf->alloc_rss_size, pf->rss_size_max);
8278 return pf->alloc_rss_size;
8282 * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition
8283 * @pf: board private structure
8285 i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf)
8288 bool min_valid, max_valid;
8291 status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
8292 &min_valid, &max_valid);
8296 pf->npar_min_bw = min_bw;
8298 pf->npar_max_bw = max_bw;
8305 * i40e_set_npar_bw_setting - Set BW settings for this PF partition
8306 * @pf: board private structure
8308 i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf)
8310 struct i40e_aqc_configure_partition_bw_data bw_data;
8313 /* Set the valid bit for this PF */
8314 bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
8315 bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK;
8316 bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK;
8318 /* Set the new bandwidths */
8319 status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
8325 * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition
8326 * @pf: board private structure
8328 i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf)
8330 /* Commit temporary BW setting to permanent NVM image */
8331 enum i40e_admin_queue_err last_aq_status;
8335 if (pf->hw.partition_id != 1) {
8336 dev_info(&pf->pdev->dev,
8337 "Commit BW only works on partition 1! This is partition %d",
8338 pf->hw.partition_id);
8339 ret = I40E_NOT_SUPPORTED;
8343 /* Acquire NVM for read access */
8344 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
8345 last_aq_status = pf->hw.aq.asq_last_status;
8347 dev_info(&pf->pdev->dev,
8348 "Cannot acquire NVM for read access, err %s aq_err %s\n",
8349 i40e_stat_str(&pf->hw, ret),
8350 i40e_aq_str(&pf->hw, last_aq_status));
8354 /* Read word 0x10 of NVM - SW compatibility word 1 */
8355 ret = i40e_aq_read_nvm(&pf->hw,
8356 I40E_SR_NVM_CONTROL_WORD,
8357 0x10, sizeof(nvm_word), &nvm_word,
8359 /* Save off last admin queue command status before releasing
8362 last_aq_status = pf->hw.aq.asq_last_status;
8363 i40e_release_nvm(&pf->hw);
8365 dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
8366 i40e_stat_str(&pf->hw, ret),
8367 i40e_aq_str(&pf->hw, last_aq_status));
8371 /* Wait a bit for NVM release to complete */
8374 /* Acquire NVM for write access */
8375 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
8376 last_aq_status = pf->hw.aq.asq_last_status;
8378 dev_info(&pf->pdev->dev,
8379 "Cannot acquire NVM for write access, err %s aq_err %s\n",
8380 i40e_stat_str(&pf->hw, ret),
8381 i40e_aq_str(&pf->hw, last_aq_status));
8384 /* Write it back out unchanged to initiate update NVM,
8385 * which will force a write of the shadow (alt) RAM to
8386 * the NVM - thus storing the bandwidth values permanently.
8388 ret = i40e_aq_update_nvm(&pf->hw,
8389 I40E_SR_NVM_CONTROL_WORD,
8390 0x10, sizeof(nvm_word),
8391 &nvm_word, true, NULL);
8392 /* Save off last admin queue command status before releasing
8395 last_aq_status = pf->hw.aq.asq_last_status;
8396 i40e_release_nvm(&pf->hw);
8398 dev_info(&pf->pdev->dev,
8399 "BW settings NOT SAVED, err %s aq_err %s\n",
8400 i40e_stat_str(&pf->hw, ret),
8401 i40e_aq_str(&pf->hw, last_aq_status));
8408 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
8409 * @pf: board private structure to initialize
8411 * i40e_sw_init initializes the Adapter private data structure.
8412 * Fields are initialized based on PCI device information and
8413 * OS network device settings (MTU size).
8415 static int i40e_sw_init(struct i40e_pf *pf)
8420 pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE,
8421 (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK));
8422 if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) {
8423 if (I40E_DEBUG_USER & debug)
8424 pf->hw.debug_mask = debug;
8425 pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER),
8426 I40E_DEFAULT_MSG_ENABLE);
8429 /* Set default capability flags */
8430 pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
8431 I40E_FLAG_MSI_ENABLED |
8432 I40E_FLAG_MSIX_ENABLED;
8434 /* Set default ITR */
8435 pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF;
8436 pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF;
8438 /* Depending on PF configurations, it is possible that the RSS
8439 * maximum might end up larger than the available queues
8441 pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
8442 pf->alloc_rss_size = 1;
8443 pf->rss_table_size = pf->hw.func_caps.rss_table_size;
8444 pf->rss_size_max = min_t(int, pf->rss_size_max,
8445 pf->hw.func_caps.num_tx_qp);
8446 if (pf->hw.func_caps.rss) {
8447 pf->flags |= I40E_FLAG_RSS_ENABLED;
8448 pf->alloc_rss_size = min_t(int, pf->rss_size_max,
8452 /* MFP mode enabled */
8453 if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
8454 pf->flags |= I40E_FLAG_MFP_ENABLED;
8455 dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
8456 if (i40e_get_npar_bw_setting(pf))
8457 dev_warn(&pf->pdev->dev,
8458 "Could not get NPAR bw settings\n");
8460 dev_info(&pf->pdev->dev,
8461 "Min BW = %8.8x, Max BW = %8.8x\n",
8462 pf->npar_min_bw, pf->npar_max_bw);
8465 /* FW/NVM is not yet fixed in this regard */
8466 if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
8467 (pf->hw.func_caps.fd_filters_best_effort > 0)) {
8468 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
8469 pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
8470 if (pf->flags & I40E_FLAG_MFP_ENABLED &&
8471 pf->hw.num_partitions > 1)
8472 dev_info(&pf->pdev->dev,
8473 "Flow Director Sideband mode Disabled in MFP mode\n");
8475 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
8476 pf->fdir_pf_filter_count =
8477 pf->hw.func_caps.fd_filters_guaranteed;
8478 pf->hw.fdir_shared_filter_count =
8479 pf->hw.func_caps.fd_filters_best_effort;
8482 if (i40e_is_mac_710(&pf->hw) &&
8483 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
8484 (pf->hw.aq.fw_maj_ver < 4))) {
8485 pf->flags |= I40E_FLAG_RESTART_AUTONEG;
8486 /* No DCB support for FW < v4.33 */
8487 pf->flags |= I40E_FLAG_NO_DCB_SUPPORT;
8490 /* Disable FW LLDP if FW < v4.3 */
8491 if (i40e_is_mac_710(&pf->hw) &&
8492 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
8493 (pf->hw.aq.fw_maj_ver < 4)))
8494 pf->flags |= I40E_FLAG_STOP_FW_LLDP;
8496 /* Use the FW Set LLDP MIB API if FW > v4.40 */
8497 if (i40e_is_mac_710(&pf->hw) &&
8498 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) ||
8499 (pf->hw.aq.fw_maj_ver >= 5)))
8500 pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB;
8502 if (pf->hw.func_caps.vmdq) {
8503 pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
8504 pf->flags |= I40E_FLAG_VMDQ_ENABLED;
8505 pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
8508 if (pf->hw.func_caps.iwarp) {
8509 pf->flags |= I40E_FLAG_IWARP_ENABLED;
8510 /* IWARP needs one extra vector for CQP just like MISC.*/
8511 pf->num_iwarp_msix = (int)num_online_cpus() + 1;
8515 i40e_init_pf_fcoe(pf);
8517 #endif /* I40E_FCOE */
8518 #ifdef CONFIG_PCI_IOV
8519 if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
8520 pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
8521 pf->flags |= I40E_FLAG_SRIOV_ENABLED;
8522 pf->num_req_vfs = min_t(int,
8523 pf->hw.func_caps.num_vfs,
8526 #endif /* CONFIG_PCI_IOV */
8527 if (pf->hw.mac.type == I40E_MAC_X722) {
8528 pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE |
8529 I40E_FLAG_128_QP_RSS_CAPABLE |
8530 I40E_FLAG_HW_ATR_EVICT_CAPABLE |
8531 I40E_FLAG_OUTER_UDP_CSUM_CAPABLE |
8532 I40E_FLAG_WB_ON_ITR_CAPABLE |
8533 I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE |
8534 I40E_FLAG_NO_PCI_LINK_CHECK |
8535 I40E_FLAG_100M_SGMII_CAPABLE |
8536 I40E_FLAG_USE_SET_LLDP_MIB |
8537 I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
8538 } else if ((pf->hw.aq.api_maj_ver > 1) ||
8539 ((pf->hw.aq.api_maj_ver == 1) &&
8540 (pf->hw.aq.api_min_ver > 4))) {
8541 /* Supported in FW API version higher than 1.4 */
8542 pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
8543 pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
8545 pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
8548 pf->eeprom_version = 0xDEAD;
8549 pf->lan_veb = I40E_NO_VEB;
8550 pf->lan_vsi = I40E_NO_VSI;
8552 /* By default FW has this off for performance reasons */
8553 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
8555 /* set up queue assignment tracking */
8556 size = sizeof(struct i40e_lump_tracking)
8557 + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
8558 pf->qp_pile = kzalloc(size, GFP_KERNEL);
8563 pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
8564 pf->qp_pile->search_hint = 0;
8566 pf->tx_timeout_recovery_level = 1;
8568 mutex_init(&pf->switch_mutex);
8570 /* If NPAR is enabled nudge the Tx scheduler */
8571 if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf)))
8572 i40e_set_npar_bw_setting(pf);
8579 * i40e_set_ntuple - set the ntuple feature flag and take action
8580 * @pf: board private structure to initialize
8581 * @features: the feature set that the stack is suggesting
8583 * returns a bool to indicate if reset needs to happen
8585 bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
8587 bool need_reset = false;
8589 /* Check if Flow Director n-tuple support was enabled or disabled. If
8590 * the state changed, we need to reset.
8592 if (features & NETIF_F_NTUPLE) {
8593 /* Enable filters and mark for reset */
8594 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
8596 /* enable FD_SB only if there is MSI-X vector */
8597 if (pf->num_fdsb_msix > 0)
8598 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
8600 /* turn off filters, mark for reset and clear SW filter list */
8601 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
8603 i40e_fdir_filter_exit(pf);
8605 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
8606 pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
8607 /* reset fd counters */
8608 pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0;
8609 pf->fdir_pf_active_filters = 0;
8610 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
8611 if (I40E_DEBUG_FD & pf->hw.debug_mask)
8612 dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
8613 /* if ATR was auto disabled it can be re-enabled. */
8614 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
8615 (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED))
8616 pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
8622 * i40e_set_features - set the netdev feature flags
8623 * @netdev: ptr to the netdev being adjusted
8624 * @features: the feature set that the stack is suggesting
8626 static int i40e_set_features(struct net_device *netdev,
8627 netdev_features_t features)
8629 struct i40e_netdev_priv *np = netdev_priv(netdev);
8630 struct i40e_vsi *vsi = np->vsi;
8631 struct i40e_pf *pf = vsi->back;
8634 if (features & NETIF_F_HW_VLAN_CTAG_RX)
8635 i40e_vlan_stripping_enable(vsi);
8637 i40e_vlan_stripping_disable(vsi);
8639 need_reset = i40e_set_ntuple(pf, features);
8642 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
8648 * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
8649 * @pf: board private structure
8650 * @port: The UDP port to look up
8652 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
8654 static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, __be16 port)
8658 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
8659 if (pf->udp_ports[i].index == port)
8667 * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
8668 * @netdev: This physical port's netdev
8669 * @ti: Tunnel endpoint information
8671 static void i40e_udp_tunnel_add(struct net_device *netdev,
8672 struct udp_tunnel_info *ti)
8674 struct i40e_netdev_priv *np = netdev_priv(netdev);
8675 struct i40e_vsi *vsi = np->vsi;
8676 struct i40e_pf *pf = vsi->back;
8677 __be16 port = ti->port;
8681 idx = i40e_get_udp_port_idx(pf, port);
8683 /* Check if port already exists */
8684 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
8685 netdev_info(netdev, "port %d already offloaded\n",
8690 /* Now check if there is space to add the new port */
8691 next_idx = i40e_get_udp_port_idx(pf, 0);
8693 if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
8694 netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n",
8700 case UDP_TUNNEL_TYPE_VXLAN:
8701 pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
8703 case UDP_TUNNEL_TYPE_GENEVE:
8704 if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE))
8706 pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
8712 /* New port: add it and mark its index in the bitmap */
8713 pf->udp_ports[next_idx].index = port;
8714 pf->pending_udp_bitmap |= BIT_ULL(next_idx);
8715 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
8719 * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
8720 * @netdev: This physical port's netdev
8721 * @ti: Tunnel endpoint information
8723 static void i40e_udp_tunnel_del(struct net_device *netdev,
8724 struct udp_tunnel_info *ti)
8726 struct i40e_netdev_priv *np = netdev_priv(netdev);
8727 struct i40e_vsi *vsi = np->vsi;
8728 struct i40e_pf *pf = vsi->back;
8729 __be16 port = ti->port;
8732 idx = i40e_get_udp_port_idx(pf, port);
8734 /* Check if port already exists */
8735 if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS)
8739 case UDP_TUNNEL_TYPE_VXLAN:
8740 if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN)
8743 case UDP_TUNNEL_TYPE_GENEVE:
8744 if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE)
8751 /* if port exists, set it to 0 (mark for deletion)
8752 * and make it pending
8754 pf->udp_ports[idx].index = 0;
8755 pf->pending_udp_bitmap |= BIT_ULL(idx);
8756 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
8760 netdev_warn(netdev, "UDP port %d was not found, not deleting\n",
8764 static int i40e_get_phys_port_id(struct net_device *netdev,
8765 struct netdev_phys_item_id *ppid)
8767 struct i40e_netdev_priv *np = netdev_priv(netdev);
8768 struct i40e_pf *pf = np->vsi->back;
8769 struct i40e_hw *hw = &pf->hw;
8771 if (!(pf->flags & I40E_FLAG_PORT_ID_VALID))
8774 ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
8775 memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
8781 * i40e_ndo_fdb_add - add an entry to the hardware database
8782 * @ndm: the input from the stack
8783 * @tb: pointer to array of nladdr (unused)
8784 * @dev: the net device pointer
8785 * @addr: the MAC address entry being added
8786 * @flags: instructions from stack about fdb operation
8788 static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
8789 struct net_device *dev,
8790 const unsigned char *addr, u16 vid,
8793 struct i40e_netdev_priv *np = netdev_priv(dev);
8794 struct i40e_pf *pf = np->vsi->back;
8797 if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
8801 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
8805 /* Hardware does not support aging addresses so if a
8806 * ndm_state is given only allow permanent addresses
8808 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
8809 netdev_info(dev, "FDB only supports static addresses\n");
8813 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
8814 err = dev_uc_add_excl(dev, addr);
8815 else if (is_multicast_ether_addr(addr))
8816 err = dev_mc_add_excl(dev, addr);
8820 /* Only return duplicate errors if NLM_F_EXCL is set */
8821 if (err == -EEXIST && !(flags & NLM_F_EXCL))
8828 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
8829 * @dev: the netdev being configured
8830 * @nlh: RTNL message
8832 * Inserts a new hardware bridge if not already created and
8833 * enables the bridging mode requested (VEB or VEPA). If the
8834 * hardware bridge has already been inserted and the request
8835 * is to change the mode then that requires a PF reset to
8836 * allow rebuild of the components with required hardware
8837 * bridge mode enabled.
8839 static int i40e_ndo_bridge_setlink(struct net_device *dev,
8840 struct nlmsghdr *nlh,
8843 struct i40e_netdev_priv *np = netdev_priv(dev);
8844 struct i40e_vsi *vsi = np->vsi;
8845 struct i40e_pf *pf = vsi->back;
8846 struct i40e_veb *veb = NULL;
8847 struct nlattr *attr, *br_spec;
8850 /* Only for PF VSI for now */
8851 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
8854 /* Find the HW bridge for PF VSI */
8855 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
8856 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
8860 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
8862 nla_for_each_nested(attr, br_spec, rem) {
8865 if (nla_type(attr) != IFLA_BRIDGE_MODE)
8868 mode = nla_get_u16(attr);
8869 if ((mode != BRIDGE_MODE_VEPA) &&
8870 (mode != BRIDGE_MODE_VEB))
8873 /* Insert a new HW bridge */
8875 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
8876 vsi->tc_config.enabled_tc);
8878 veb->bridge_mode = mode;
8879 i40e_config_bridge_mode(veb);
8881 /* No Bridge HW offload available */
8885 } else if (mode != veb->bridge_mode) {
8886 /* Existing HW bridge but different mode needs reset */
8887 veb->bridge_mode = mode;
8888 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
8889 if (mode == BRIDGE_MODE_VEB)
8890 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
8892 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
8893 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
8902 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
8905 * @seq: RTNL message seq #
8906 * @dev: the netdev being configured
8907 * @filter_mask: unused
8908 * @nlflags: netlink flags passed in
8910 * Return the mode in which the hardware bridge is operating in
8913 static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
8914 struct net_device *dev,
8915 u32 __always_unused filter_mask,
8918 struct i40e_netdev_priv *np = netdev_priv(dev);
8919 struct i40e_vsi *vsi = np->vsi;
8920 struct i40e_pf *pf = vsi->back;
8921 struct i40e_veb *veb = NULL;
8924 /* Only for PF VSI for now */
8925 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
8928 /* Find the HW bridge for the PF VSI */
8929 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
8930 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
8937 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
8938 nlflags, 0, 0, filter_mask, NULL);
8941 /* Hardware supports L4 tunnel length of 128B (=2^7) which includes
8942 * inner mac plus all inner ethertypes.
8944 #define I40E_MAX_TUNNEL_HDR_LEN 128
8946 * i40e_features_check - Validate encapsulated packet conforms to limits
8948 * @dev: This physical port's netdev
8949 * @features: Offload features that the stack believes apply
8951 static netdev_features_t i40e_features_check(struct sk_buff *skb,
8952 struct net_device *dev,
8953 netdev_features_t features)
8955 if (skb->encapsulation &&
8956 ((skb_inner_network_header(skb) - skb_transport_header(skb)) >
8957 I40E_MAX_TUNNEL_HDR_LEN))
8958 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
8963 static const struct net_device_ops i40e_netdev_ops = {
8964 .ndo_open = i40e_open,
8965 .ndo_stop = i40e_close,
8966 .ndo_start_xmit = i40e_lan_xmit_frame,
8967 .ndo_get_stats64 = i40e_get_netdev_stats_struct,
8968 .ndo_set_rx_mode = i40e_set_rx_mode,
8969 .ndo_validate_addr = eth_validate_addr,
8970 .ndo_set_mac_address = i40e_set_mac,
8971 .ndo_change_mtu = i40e_change_mtu,
8972 .ndo_do_ioctl = i40e_ioctl,
8973 .ndo_tx_timeout = i40e_tx_timeout,
8974 .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
8975 .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
8976 #ifdef CONFIG_NET_POLL_CONTROLLER
8977 .ndo_poll_controller = i40e_netpoll,
8979 .ndo_setup_tc = __i40e_setup_tc,
8981 .ndo_fcoe_enable = i40e_fcoe_enable,
8982 .ndo_fcoe_disable = i40e_fcoe_disable,
8984 .ndo_set_features = i40e_set_features,
8985 .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
8986 .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
8987 .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
8988 .ndo_get_vf_config = i40e_ndo_get_vf_config,
8989 .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
8990 .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
8991 .ndo_set_vf_trust = i40e_ndo_set_vf_trust,
8992 .ndo_udp_tunnel_add = i40e_udp_tunnel_add,
8993 .ndo_udp_tunnel_del = i40e_udp_tunnel_del,
8994 .ndo_get_phys_port_id = i40e_get_phys_port_id,
8995 .ndo_fdb_add = i40e_ndo_fdb_add,
8996 .ndo_features_check = i40e_features_check,
8997 .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
8998 .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
9002 * i40e_config_netdev - Setup the netdev flags
9003 * @vsi: the VSI being configured
9005 * Returns 0 on success, negative value on failure
9007 static int i40e_config_netdev(struct i40e_vsi *vsi)
9009 u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
9010 struct i40e_pf *pf = vsi->back;
9011 struct i40e_hw *hw = &pf->hw;
9012 struct i40e_netdev_priv *np;
9013 struct net_device *netdev;
9014 u8 mac_addr[ETH_ALEN];
9017 etherdev_size = sizeof(struct i40e_netdev_priv);
9018 netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
9022 vsi->netdev = netdev;
9023 np = netdev_priv(netdev);
9026 netdev->hw_enc_features |= NETIF_F_SG |
9030 NETIF_F_SOFT_FEATURES |
9035 NETIF_F_GSO_GRE_CSUM |
9036 NETIF_F_GSO_IPXIP4 |
9037 NETIF_F_GSO_IPXIP6 |
9038 NETIF_F_GSO_UDP_TUNNEL |
9039 NETIF_F_GSO_UDP_TUNNEL_CSUM |
9040 NETIF_F_GSO_PARTIAL |
9046 if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE))
9047 netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
9049 netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
9051 /* record features VLANs can make use of */
9052 netdev->vlan_features |= netdev->hw_enc_features |
9053 NETIF_F_TSO_MANGLEID;
9055 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
9056 netdev->hw_features |= NETIF_F_NTUPLE;
9058 netdev->hw_features |= netdev->hw_enc_features |
9059 NETIF_F_HW_VLAN_CTAG_TX |
9060 NETIF_F_HW_VLAN_CTAG_RX;
9062 netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
9063 netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
9065 if (vsi->type == I40E_VSI_MAIN) {
9066 SET_NETDEV_DEV(netdev, &pf->pdev->dev);
9067 ether_addr_copy(mac_addr, hw->mac.perm_addr);
9068 /* The following steps are necessary to prevent reception
9069 * of tagged packets - some older NVM configurations load a
9070 * default a MAC-VLAN filter that accepts any tagged packet
9071 * which must be replaced by a normal filter.
9073 if (!i40e_rm_default_mac_filter(vsi, mac_addr)) {
9074 spin_lock_bh(&vsi->mac_filter_list_lock);
9075 i40e_add_filter(vsi, mac_addr,
9076 I40E_VLAN_ANY, false, true);
9077 spin_unlock_bh(&vsi->mac_filter_list_lock);
9079 } else if ((pf->hw.aq.api_maj_ver > 1) ||
9080 ((pf->hw.aq.api_maj_ver == 1) &&
9081 (pf->hw.aq.api_min_ver > 4))) {
9082 /* Supported in FW API version higher than 1.4 */
9083 pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
9084 pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
9086 /* relate the VSI_VMDQ name to the VSI_MAIN name */
9087 snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
9088 pf->vsi[pf->lan_vsi]->netdev->name);
9089 random_ether_addr(mac_addr);
9091 spin_lock_bh(&vsi->mac_filter_list_lock);
9092 i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false);
9093 spin_unlock_bh(&vsi->mac_filter_list_lock);
9096 spin_lock_bh(&vsi->mac_filter_list_lock);
9097 i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false);
9098 spin_unlock_bh(&vsi->mac_filter_list_lock);
9100 ether_addr_copy(netdev->dev_addr, mac_addr);
9101 ether_addr_copy(netdev->perm_addr, mac_addr);
9103 netdev->priv_flags |= IFF_UNICAST_FLT;
9104 netdev->priv_flags |= IFF_SUPP_NOFCS;
9105 /* Setup netdev TC information */
9106 i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
9108 netdev->netdev_ops = &i40e_netdev_ops;
9109 netdev->watchdog_timeo = 5 * HZ;
9110 i40e_set_ethtool_ops(netdev);
9112 i40e_fcoe_config_netdev(netdev, vsi);
9119 * i40e_vsi_delete - Delete a VSI from the switch
9120 * @vsi: the VSI being removed
9122 * Returns 0 on success, negative value on failure
9124 static void i40e_vsi_delete(struct i40e_vsi *vsi)
9126 /* remove default VSI is not allowed */
9127 if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
9130 i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
9134 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
9135 * @vsi: the VSI being queried
9137 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
9139 int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
9141 struct i40e_veb *veb;
9142 struct i40e_pf *pf = vsi->back;
9144 /* Uplink is not a bridge so default to VEB */
9145 if (vsi->veb_idx == I40E_NO_VEB)
9148 veb = pf->veb[vsi->veb_idx];
9150 dev_info(&pf->pdev->dev,
9151 "There is no veb associated with the bridge\n");
9155 /* Uplink is a bridge in VEPA mode */
9156 if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
9159 /* Uplink is a bridge in VEB mode */
9163 /* VEPA is now default bridge, so return 0 */
9168 * i40e_add_vsi - Add a VSI to the switch
9169 * @vsi: the VSI being configured
9171 * This initializes a VSI context depending on the VSI type to be added and
9172 * passes it down to the add_vsi aq command.
9174 static int i40e_add_vsi(struct i40e_vsi *vsi)
9177 u8 laa_macaddr[ETH_ALEN];
9178 bool found_laa_mac_filter = false;
9179 struct i40e_pf *pf = vsi->back;
9180 struct i40e_hw *hw = &pf->hw;
9181 struct i40e_vsi_context ctxt;
9182 struct i40e_mac_filter *f, *ftmp;
9184 u8 enabled_tc = 0x1; /* TC0 enabled */
9187 memset(&ctxt, 0, sizeof(ctxt));
9188 switch (vsi->type) {
9190 /* The PF's main VSI is already setup as part of the
9191 * device initialization, so we'll not bother with
9192 * the add_vsi call, but we will retrieve the current
9195 ctxt.seid = pf->main_vsi_seid;
9196 ctxt.pf_num = pf->hw.pf_id;
9198 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
9199 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
9201 dev_info(&pf->pdev->dev,
9202 "couldn't get PF vsi config, err %s aq_err %s\n",
9203 i40e_stat_str(&pf->hw, ret),
9204 i40e_aq_str(&pf->hw,
9205 pf->hw.aq.asq_last_status));
9208 vsi->info = ctxt.info;
9209 vsi->info.valid_sections = 0;
9211 vsi->seid = ctxt.seid;
9212 vsi->id = ctxt.vsi_number;
9214 enabled_tc = i40e_pf_get_tc_map(pf);
9216 /* MFP mode setup queue map and update VSI */
9217 if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
9218 !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
9219 memset(&ctxt, 0, sizeof(ctxt));
9220 ctxt.seid = pf->main_vsi_seid;
9221 ctxt.pf_num = pf->hw.pf_id;
9223 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
9224 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
9226 dev_info(&pf->pdev->dev,
9227 "update vsi failed, err %s aq_err %s\n",
9228 i40e_stat_str(&pf->hw, ret),
9229 i40e_aq_str(&pf->hw,
9230 pf->hw.aq.asq_last_status));
9234 /* update the local VSI info queue map */
9235 i40e_vsi_update_queue_map(vsi, &ctxt);
9236 vsi->info.valid_sections = 0;
9238 /* Default/Main VSI is only enabled for TC0
9239 * reconfigure it to enable all TCs that are
9240 * available on the port in SFP mode.
9241 * For MFP case the iSCSI PF would use this
9242 * flow to enable LAN+iSCSI TC.
9244 ret = i40e_vsi_config_tc(vsi, enabled_tc);
9246 dev_info(&pf->pdev->dev,
9247 "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
9249 i40e_stat_str(&pf->hw, ret),
9250 i40e_aq_str(&pf->hw,
9251 pf->hw.aq.asq_last_status));
9258 ctxt.pf_num = hw->pf_id;
9260 ctxt.uplink_seid = vsi->uplink_seid;
9261 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
9262 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
9263 if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
9264 (i40e_is_vsi_uplink_mode_veb(vsi))) {
9265 ctxt.info.valid_sections |=
9266 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9267 ctxt.info.switch_id =
9268 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9270 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
9273 case I40E_VSI_VMDQ2:
9274 ctxt.pf_num = hw->pf_id;
9276 ctxt.uplink_seid = vsi->uplink_seid;
9277 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
9278 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
9280 /* This VSI is connected to VEB so the switch_id
9281 * should be set to zero by default.
9283 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
9284 ctxt.info.valid_sections |=
9285 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9286 ctxt.info.switch_id =
9287 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9290 /* Setup the VSI tx/rx queue map for TC0 only for now */
9291 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
9294 case I40E_VSI_SRIOV:
9295 ctxt.pf_num = hw->pf_id;
9296 ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
9297 ctxt.uplink_seid = vsi->uplink_seid;
9298 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
9299 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
9301 /* This VSI is connected to VEB so the switch_id
9302 * should be set to zero by default.
9304 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
9305 ctxt.info.valid_sections |=
9306 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9307 ctxt.info.switch_id =
9308 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9311 if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
9312 ctxt.info.valid_sections |=
9313 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
9314 ctxt.info.queueing_opt_flags |=
9315 (I40E_AQ_VSI_QUE_OPT_TCP_ENA |
9316 I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI);
9319 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
9320 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
9321 if (pf->vf[vsi->vf_id].spoofchk) {
9322 ctxt.info.valid_sections |=
9323 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
9324 ctxt.info.sec_flags |=
9325 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
9326 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
9328 /* Setup the VSI tx/rx queue map for TC0 only for now */
9329 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
9334 ret = i40e_fcoe_vsi_init(vsi, &ctxt);
9336 dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n");
9341 #endif /* I40E_FCOE */
9342 case I40E_VSI_IWARP:
9343 /* send down message to iWARP */
9350 if (vsi->type != I40E_VSI_MAIN) {
9351 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
9353 dev_info(&vsi->back->pdev->dev,
9354 "add vsi failed, err %s aq_err %s\n",
9355 i40e_stat_str(&pf->hw, ret),
9356 i40e_aq_str(&pf->hw,
9357 pf->hw.aq.asq_last_status));
9361 vsi->info = ctxt.info;
9362 vsi->info.valid_sections = 0;
9363 vsi->seid = ctxt.seid;
9364 vsi->id = ctxt.vsi_number;
9367 spin_lock_bh(&vsi->mac_filter_list_lock);
9368 /* If macvlan filters already exist, force them to get loaded */
9369 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
9373 /* Expected to have only one MAC filter entry for LAA in list */
9374 if (f->is_laa && vsi->type == I40E_VSI_MAIN) {
9375 ether_addr_copy(laa_macaddr, f->macaddr);
9376 found_laa_mac_filter = true;
9379 spin_unlock_bh(&vsi->mac_filter_list_lock);
9381 if (found_laa_mac_filter) {
9382 struct i40e_aqc_remove_macvlan_element_data element;
9384 memset(&element, 0, sizeof(element));
9385 ether_addr_copy(element.mac_addr, laa_macaddr);
9386 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
9387 ret = i40e_aq_remove_macvlan(hw, vsi->seid,
9390 /* some older FW has a different default */
9392 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
9393 i40e_aq_remove_macvlan(hw, vsi->seid,
9397 i40e_aq_mac_address_write(hw,
9398 I40E_AQC_WRITE_TYPE_LAA_WOL,
9403 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
9404 pf->flags |= I40E_FLAG_FILTER_SYNC;
9407 /* Update VSI BW information */
9408 ret = i40e_vsi_get_bw_info(vsi);
9410 dev_info(&pf->pdev->dev,
9411 "couldn't get vsi bw info, err %s aq_err %s\n",
9412 i40e_stat_str(&pf->hw, ret),
9413 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
9414 /* VSI is already added so not tearing that up */
9423 * i40e_vsi_release - Delete a VSI and free its resources
9424 * @vsi: the VSI being removed
9426 * Returns 0 on success or < 0 on error
9428 int i40e_vsi_release(struct i40e_vsi *vsi)
9430 struct i40e_mac_filter *f, *ftmp;
9431 struct i40e_veb *veb = NULL;
9438 /* release of a VEB-owner or last VSI is not allowed */
9439 if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
9440 dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
9441 vsi->seid, vsi->uplink_seid);
9444 if (vsi == pf->vsi[pf->lan_vsi] &&
9445 !test_bit(__I40E_DOWN, &pf->state)) {
9446 dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
9450 uplink_seid = vsi->uplink_seid;
9451 if (vsi->type != I40E_VSI_SRIOV) {
9452 if (vsi->netdev_registered) {
9453 vsi->netdev_registered = false;
9455 /* results in a call to i40e_close() */
9456 unregister_netdev(vsi->netdev);
9459 i40e_vsi_close(vsi);
9461 i40e_vsi_disable_irq(vsi);
9464 spin_lock_bh(&vsi->mac_filter_list_lock);
9465 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list)
9466 i40e_del_filter(vsi, f->macaddr, f->vlan,
9467 f->is_vf, f->is_netdev);
9468 spin_unlock_bh(&vsi->mac_filter_list_lock);
9470 i40e_sync_vsi_filters(vsi);
9472 i40e_vsi_delete(vsi);
9473 i40e_vsi_free_q_vectors(vsi);
9475 free_netdev(vsi->netdev);
9478 i40e_vsi_clear_rings(vsi);
9479 i40e_vsi_clear(vsi);
9481 /* If this was the last thing on the VEB, except for the
9482 * controlling VSI, remove the VEB, which puts the controlling
9483 * VSI onto the next level down in the switch.
9485 * Well, okay, there's one more exception here: don't remove
9486 * the orphan VEBs yet. We'll wait for an explicit remove request
9487 * from up the network stack.
9489 for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
9491 pf->vsi[i]->uplink_seid == uplink_seid &&
9492 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
9493 n++; /* count the VSIs */
9496 for (i = 0; i < I40E_MAX_VEB; i++) {
9499 if (pf->veb[i]->uplink_seid == uplink_seid)
9500 n++; /* count the VEBs */
9501 if (pf->veb[i]->seid == uplink_seid)
9504 if (n == 0 && veb && veb->uplink_seid != 0)
9505 i40e_veb_release(veb);
9511 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
9512 * @vsi: ptr to the VSI
9514 * This should only be called after i40e_vsi_mem_alloc() which allocates the
9515 * corresponding SW VSI structure and initializes num_queue_pairs for the
9516 * newly allocated VSI.
9518 * Returns 0 on success or negative on failure
9520 static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
9523 struct i40e_pf *pf = vsi->back;
9525 if (vsi->q_vectors[0]) {
9526 dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
9531 if (vsi->base_vector) {
9532 dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
9533 vsi->seid, vsi->base_vector);
9537 ret = i40e_vsi_alloc_q_vectors(vsi);
9539 dev_info(&pf->pdev->dev,
9540 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
9541 vsi->num_q_vectors, vsi->seid, ret);
9542 vsi->num_q_vectors = 0;
9543 goto vector_setup_out;
9546 /* In Legacy mode, we do not have to get any other vector since we
9547 * piggyback on the misc/ICR0 for queue interrupts.
9549 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
9551 if (vsi->num_q_vectors)
9552 vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
9553 vsi->num_q_vectors, vsi->idx);
9554 if (vsi->base_vector < 0) {
9555 dev_info(&pf->pdev->dev,
9556 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
9557 vsi->num_q_vectors, vsi->seid, vsi->base_vector);
9558 i40e_vsi_free_q_vectors(vsi);
9560 goto vector_setup_out;
9568 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
9569 * @vsi: pointer to the vsi.
9571 * This re-allocates a vsi's queue resources.
9573 * Returns pointer to the successfully allocated and configured VSI sw struct
9574 * on success, otherwise returns NULL on failure.
9576 static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
9587 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
9588 i40e_vsi_clear_rings(vsi);
9590 i40e_vsi_free_arrays(vsi, false);
9591 i40e_set_num_rings_in_vsi(vsi);
9592 ret = i40e_vsi_alloc_arrays(vsi, false);
9596 ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx);
9598 dev_info(&pf->pdev->dev,
9599 "failed to get tracking for %d queues for VSI %d err %d\n",
9600 vsi->alloc_queue_pairs, vsi->seid, ret);
9603 vsi->base_queue = ret;
9605 /* Update the FW view of the VSI. Force a reset of TC and queue
9606 * layout configurations.
9608 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
9609 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
9610 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
9611 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
9613 /* assign it some queues */
9614 ret = i40e_alloc_rings(vsi);
9618 /* map all of the rings to the q_vectors */
9619 i40e_vsi_map_rings_to_vectors(vsi);
9623 i40e_vsi_free_q_vectors(vsi);
9624 if (vsi->netdev_registered) {
9625 vsi->netdev_registered = false;
9626 unregister_netdev(vsi->netdev);
9627 free_netdev(vsi->netdev);
9630 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
9632 i40e_vsi_clear(vsi);
9637 * i40e_macaddr_init - explicitly write the mac address filters.
9639 * @vsi: pointer to the vsi.
9640 * @macaddr: the MAC address
9642 * This is needed when the macaddr has been obtained by other
9643 * means than the default, e.g., from Open Firmware or IDPROM.
9644 * Returns 0 on success, negative on failure
9646 static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr)
9649 struct i40e_aqc_add_macvlan_element_data element;
9651 ret = i40e_aq_mac_address_write(&vsi->back->hw,
9652 I40E_AQC_WRITE_TYPE_LAA_WOL,
9655 dev_info(&vsi->back->pdev->dev,
9656 "Addr change for VSI failed: %d\n", ret);
9657 return -EADDRNOTAVAIL;
9660 memset(&element, 0, sizeof(element));
9661 ether_addr_copy(element.mac_addr, macaddr);
9662 element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH);
9663 ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL);
9665 dev_info(&vsi->back->pdev->dev,
9666 "add filter failed err %s aq_err %s\n",
9667 i40e_stat_str(&vsi->back->hw, ret),
9668 i40e_aq_str(&vsi->back->hw,
9669 vsi->back->hw.aq.asq_last_status));
9675 * i40e_vsi_setup - Set up a VSI by a given type
9676 * @pf: board private structure
9678 * @uplink_seid: the switch element to link to
9679 * @param1: usage depends upon VSI type. For VF types, indicates VF id
9681 * This allocates the sw VSI structure and its queue resources, then add a VSI
9682 * to the identified VEB.
9684 * Returns pointer to the successfully allocated and configure VSI sw struct on
9685 * success, otherwise returns NULL on failure.
9687 struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
9688 u16 uplink_seid, u32 param1)
9690 struct i40e_vsi *vsi = NULL;
9691 struct i40e_veb *veb = NULL;
9695 /* The requested uplink_seid must be either
9696 * - the PF's port seid
9697 * no VEB is needed because this is the PF
9698 * or this is a Flow Director special case VSI
9699 * - seid of an existing VEB
9700 * - seid of a VSI that owns an existing VEB
9701 * - seid of a VSI that doesn't own a VEB
9702 * a new VEB is created and the VSI becomes the owner
9703 * - seid of the PF VSI, which is what creates the first VEB
9704 * this is a special case of the previous
9706 * Find which uplink_seid we were given and create a new VEB if needed
9708 for (i = 0; i < I40E_MAX_VEB; i++) {
9709 if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
9715 if (!veb && uplink_seid != pf->mac_seid) {
9717 for (i = 0; i < pf->num_alloc_vsi; i++) {
9718 if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
9724 dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
9729 if (vsi->uplink_seid == pf->mac_seid)
9730 veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
9731 vsi->tc_config.enabled_tc);
9732 else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
9733 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
9734 vsi->tc_config.enabled_tc);
9736 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
9737 dev_info(&vsi->back->pdev->dev,
9738 "New VSI creation error, uplink seid of LAN VSI expected.\n");
9741 /* We come up by default in VEPA mode if SRIOV is not
9742 * already enabled, in which case we can't force VEPA
9745 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
9746 veb->bridge_mode = BRIDGE_MODE_VEPA;
9747 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
9749 i40e_config_bridge_mode(veb);
9751 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
9752 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
9756 dev_info(&pf->pdev->dev, "couldn't add VEB\n");
9760 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
9761 uplink_seid = veb->seid;
9764 /* get vsi sw struct */
9765 v_idx = i40e_vsi_mem_alloc(pf, type);
9768 vsi = pf->vsi[v_idx];
9772 vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
9774 if (type == I40E_VSI_MAIN)
9775 pf->lan_vsi = v_idx;
9776 else if (type == I40E_VSI_SRIOV)
9777 vsi->vf_id = param1;
9778 /* assign it some queues */
9779 ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs,
9782 dev_info(&pf->pdev->dev,
9783 "failed to get tracking for %d queues for VSI %d err=%d\n",
9784 vsi->alloc_queue_pairs, vsi->seid, ret);
9787 vsi->base_queue = ret;
9789 /* get a VSI from the hardware */
9790 vsi->uplink_seid = uplink_seid;
9791 ret = i40e_add_vsi(vsi);
9795 switch (vsi->type) {
9796 /* setup the netdev if needed */
9798 /* Apply relevant filters if a platform-specific mac
9799 * address was selected.
9801 if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
9802 ret = i40e_macaddr_init(vsi, pf->hw.mac.addr);
9804 dev_warn(&pf->pdev->dev,
9805 "could not set up macaddr; err %d\n",
9809 case I40E_VSI_VMDQ2:
9811 ret = i40e_config_netdev(vsi);
9814 ret = register_netdev(vsi->netdev);
9817 vsi->netdev_registered = true;
9818 netif_carrier_off(vsi->netdev);
9819 #ifdef CONFIG_I40E_DCB
9820 /* Setup DCB netlink interface */
9821 i40e_dcbnl_setup(vsi);
9822 #endif /* CONFIG_I40E_DCB */
9826 /* set up vectors and rings if needed */
9827 ret = i40e_vsi_setup_vectors(vsi);
9831 ret = i40e_alloc_rings(vsi);
9835 /* map all of the rings to the q_vectors */
9836 i40e_vsi_map_rings_to_vectors(vsi);
9838 i40e_vsi_reset_stats(vsi);
9842 /* no netdev or rings for the other VSI types */
9846 if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) &&
9847 (vsi->type == I40E_VSI_VMDQ2)) {
9848 ret = i40e_vsi_config_rss(vsi);
9853 i40e_vsi_free_q_vectors(vsi);
9855 if (vsi->netdev_registered) {
9856 vsi->netdev_registered = false;
9857 unregister_netdev(vsi->netdev);
9858 free_netdev(vsi->netdev);
9862 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
9864 i40e_vsi_clear(vsi);
9870 * i40e_veb_get_bw_info - Query VEB BW information
9871 * @veb: the veb to query
9873 * Query the Tx scheduler BW configuration data for given VEB
9875 static int i40e_veb_get_bw_info(struct i40e_veb *veb)
9877 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
9878 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
9879 struct i40e_pf *pf = veb->pf;
9880 struct i40e_hw *hw = &pf->hw;
9885 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
9888 dev_info(&pf->pdev->dev,
9889 "query veb bw config failed, err %s aq_err %s\n",
9890 i40e_stat_str(&pf->hw, ret),
9891 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
9895 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
9898 dev_info(&pf->pdev->dev,
9899 "query veb bw ets config failed, err %s aq_err %s\n",
9900 i40e_stat_str(&pf->hw, ret),
9901 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
9905 veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
9906 veb->bw_max_quanta = ets_data.tc_bw_max;
9907 veb->is_abs_credits = bw_data.absolute_credits_enable;
9908 veb->enabled_tc = ets_data.tc_valid_bits;
9909 tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
9910 (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
9911 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
9912 veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
9913 veb->bw_tc_limit_credits[i] =
9914 le16_to_cpu(bw_data.tc_bw_limits[i]);
9915 veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
9923 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
9924 * @pf: board private structure
9926 * On error: returns error code (negative)
9927 * On success: returns vsi index in PF (positive)
9929 static int i40e_veb_mem_alloc(struct i40e_pf *pf)
9932 struct i40e_veb *veb;
9935 /* Need to protect the allocation of switch elements at the PF level */
9936 mutex_lock(&pf->switch_mutex);
9938 /* VEB list may be fragmented if VEB creation/destruction has
9939 * been happening. We can afford to do a quick scan to look
9940 * for any free slots in the list.
9942 * find next empty veb slot, looping back around if necessary
9945 while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
9947 if (i >= I40E_MAX_VEB) {
9949 goto err_alloc_veb; /* out of VEB slots! */
9952 veb = kzalloc(sizeof(*veb), GFP_KERNEL);
9959 veb->enabled_tc = 1;
9964 mutex_unlock(&pf->switch_mutex);
9969 * i40e_switch_branch_release - Delete a branch of the switch tree
9970 * @branch: where to start deleting
9972 * This uses recursion to find the tips of the branch to be
9973 * removed, deleting until we get back to and can delete this VEB.
9975 static void i40e_switch_branch_release(struct i40e_veb *branch)
9977 struct i40e_pf *pf = branch->pf;
9978 u16 branch_seid = branch->seid;
9979 u16 veb_idx = branch->idx;
9982 /* release any VEBs on this VEB - RECURSION */
9983 for (i = 0; i < I40E_MAX_VEB; i++) {
9986 if (pf->veb[i]->uplink_seid == branch->seid)
9987 i40e_switch_branch_release(pf->veb[i]);
9990 /* Release the VSIs on this VEB, but not the owner VSI.
9992 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
9993 * the VEB itself, so don't use (*branch) after this loop.
9995 for (i = 0; i < pf->num_alloc_vsi; i++) {
9998 if (pf->vsi[i]->uplink_seid == branch_seid &&
9999 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
10000 i40e_vsi_release(pf->vsi[i]);
10004 /* There's one corner case where the VEB might not have been
10005 * removed, so double check it here and remove it if needed.
10006 * This case happens if the veb was created from the debugfs
10007 * commands and no VSIs were added to it.
10009 if (pf->veb[veb_idx])
10010 i40e_veb_release(pf->veb[veb_idx]);
10014 * i40e_veb_clear - remove veb struct
10015 * @veb: the veb to remove
10017 static void i40e_veb_clear(struct i40e_veb *veb)
10023 struct i40e_pf *pf = veb->pf;
10025 mutex_lock(&pf->switch_mutex);
10026 if (pf->veb[veb->idx] == veb)
10027 pf->veb[veb->idx] = NULL;
10028 mutex_unlock(&pf->switch_mutex);
10035 * i40e_veb_release - Delete a VEB and free its resources
10036 * @veb: the VEB being removed
10038 void i40e_veb_release(struct i40e_veb *veb)
10040 struct i40e_vsi *vsi = NULL;
10041 struct i40e_pf *pf;
10046 /* find the remaining VSI and check for extras */
10047 for (i = 0; i < pf->num_alloc_vsi; i++) {
10048 if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
10054 dev_info(&pf->pdev->dev,
10055 "can't remove VEB %d with %d VSIs left\n",
10060 /* move the remaining VSI to uplink veb */
10061 vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
10062 if (veb->uplink_seid) {
10063 vsi->uplink_seid = veb->uplink_seid;
10064 if (veb->uplink_seid == pf->mac_seid)
10065 vsi->veb_idx = I40E_NO_VEB;
10067 vsi->veb_idx = veb->veb_idx;
10070 vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
10071 vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
10074 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
10075 i40e_veb_clear(veb);
10079 * i40e_add_veb - create the VEB in the switch
10080 * @veb: the VEB to be instantiated
10081 * @vsi: the controlling VSI
10083 static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
10085 struct i40e_pf *pf = veb->pf;
10086 bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
10089 ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
10090 veb->enabled_tc, false,
10091 &veb->seid, enable_stats, NULL);
10093 /* get a VEB from the hardware */
10095 dev_info(&pf->pdev->dev,
10096 "couldn't add VEB, err %s aq_err %s\n",
10097 i40e_stat_str(&pf->hw, ret),
10098 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
10102 /* get statistics counter */
10103 ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
10104 &veb->stats_idx, NULL, NULL, NULL);
10106 dev_info(&pf->pdev->dev,
10107 "couldn't get VEB statistics idx, err %s aq_err %s\n",
10108 i40e_stat_str(&pf->hw, ret),
10109 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
10112 ret = i40e_veb_get_bw_info(veb);
10114 dev_info(&pf->pdev->dev,
10115 "couldn't get VEB bw info, err %s aq_err %s\n",
10116 i40e_stat_str(&pf->hw, ret),
10117 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
10118 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
10122 vsi->uplink_seid = veb->seid;
10123 vsi->veb_idx = veb->idx;
10124 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
10130 * i40e_veb_setup - Set up a VEB
10131 * @pf: board private structure
10132 * @flags: VEB setup flags
10133 * @uplink_seid: the switch element to link to
10134 * @vsi_seid: the initial VSI seid
10135 * @enabled_tc: Enabled TC bit-map
10137 * This allocates the sw VEB structure and links it into the switch
10138 * It is possible and legal for this to be a duplicate of an already
10139 * existing VEB. It is also possible for both uplink and vsi seids
10140 * to be zero, in order to create a floating VEB.
10142 * Returns pointer to the successfully allocated VEB sw struct on
10143 * success, otherwise returns NULL on failure.
10145 struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
10146 u16 uplink_seid, u16 vsi_seid,
10149 struct i40e_veb *veb, *uplink_veb = NULL;
10150 int vsi_idx, veb_idx;
10153 /* if one seid is 0, the other must be 0 to create a floating relay */
10154 if ((uplink_seid == 0 || vsi_seid == 0) &&
10155 (uplink_seid + vsi_seid != 0)) {
10156 dev_info(&pf->pdev->dev,
10157 "one, not both seid's are 0: uplink=%d vsi=%d\n",
10158 uplink_seid, vsi_seid);
10162 /* make sure there is such a vsi and uplink */
10163 for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
10164 if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
10166 if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
10167 dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
10172 if (uplink_seid && uplink_seid != pf->mac_seid) {
10173 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
10174 if (pf->veb[veb_idx] &&
10175 pf->veb[veb_idx]->seid == uplink_seid) {
10176 uplink_veb = pf->veb[veb_idx];
10181 dev_info(&pf->pdev->dev,
10182 "uplink seid %d not found\n", uplink_seid);
10187 /* get veb sw struct */
10188 veb_idx = i40e_veb_mem_alloc(pf);
10191 veb = pf->veb[veb_idx];
10192 veb->flags = flags;
10193 veb->uplink_seid = uplink_seid;
10194 veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
10195 veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
10197 /* create the VEB in the switch */
10198 ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
10201 if (vsi_idx == pf->lan_vsi)
10202 pf->lan_veb = veb->idx;
10207 i40e_veb_clear(veb);
10213 * i40e_setup_pf_switch_element - set PF vars based on switch type
10214 * @pf: board private structure
10215 * @ele: element we are building info from
10216 * @num_reported: total number of elements
10217 * @printconfig: should we print the contents
10219 * helper function to assist in extracting a few useful SEID values.
10221 static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
10222 struct i40e_aqc_switch_config_element_resp *ele,
10223 u16 num_reported, bool printconfig)
10225 u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
10226 u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
10227 u8 element_type = ele->element_type;
10228 u16 seid = le16_to_cpu(ele->seid);
10231 dev_info(&pf->pdev->dev,
10232 "type=%d seid=%d uplink=%d downlink=%d\n",
10233 element_type, seid, uplink_seid, downlink_seid);
10235 switch (element_type) {
10236 case I40E_SWITCH_ELEMENT_TYPE_MAC:
10237 pf->mac_seid = seid;
10239 case I40E_SWITCH_ELEMENT_TYPE_VEB:
10241 if (uplink_seid != pf->mac_seid)
10243 if (pf->lan_veb == I40E_NO_VEB) {
10246 /* find existing or else empty VEB */
10247 for (v = 0; v < I40E_MAX_VEB; v++) {
10248 if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
10253 if (pf->lan_veb == I40E_NO_VEB) {
10254 v = i40e_veb_mem_alloc(pf);
10261 pf->veb[pf->lan_veb]->seid = seid;
10262 pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
10263 pf->veb[pf->lan_veb]->pf = pf;
10264 pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
10266 case I40E_SWITCH_ELEMENT_TYPE_VSI:
10267 if (num_reported != 1)
10269 /* This is immediately after a reset so we can assume this is
10272 pf->mac_seid = uplink_seid;
10273 pf->pf_seid = downlink_seid;
10274 pf->main_vsi_seid = seid;
10276 dev_info(&pf->pdev->dev,
10277 "pf_seid=%d main_vsi_seid=%d\n",
10278 pf->pf_seid, pf->main_vsi_seid);
10280 case I40E_SWITCH_ELEMENT_TYPE_PF:
10281 case I40E_SWITCH_ELEMENT_TYPE_VF:
10282 case I40E_SWITCH_ELEMENT_TYPE_EMP:
10283 case I40E_SWITCH_ELEMENT_TYPE_BMC:
10284 case I40E_SWITCH_ELEMENT_TYPE_PE:
10285 case I40E_SWITCH_ELEMENT_TYPE_PA:
10286 /* ignore these for now */
10289 dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
10290 element_type, seid);
10296 * i40e_fetch_switch_configuration - Get switch config from firmware
10297 * @pf: board private structure
10298 * @printconfig: should we print the contents
10300 * Get the current switch configuration from the device and
10301 * extract a few useful SEID values.
10303 int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
10305 struct i40e_aqc_get_switch_config_resp *sw_config;
10311 aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
10315 sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
10317 u16 num_reported, num_total;
10319 ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
10323 dev_info(&pf->pdev->dev,
10324 "get switch config failed err %s aq_err %s\n",
10325 i40e_stat_str(&pf->hw, ret),
10326 i40e_aq_str(&pf->hw,
10327 pf->hw.aq.asq_last_status));
10332 num_reported = le16_to_cpu(sw_config->header.num_reported);
10333 num_total = le16_to_cpu(sw_config->header.num_total);
10336 dev_info(&pf->pdev->dev,
10337 "header: %d reported %d total\n",
10338 num_reported, num_total);
10340 for (i = 0; i < num_reported; i++) {
10341 struct i40e_aqc_switch_config_element_resp *ele =
10342 &sw_config->element[i];
10344 i40e_setup_pf_switch_element(pf, ele, num_reported,
10347 } while (next_seid != 0);
10354 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
10355 * @pf: board private structure
10356 * @reinit: if the Main VSI needs to re-initialized.
10358 * Returns 0 on success, negative value on failure
10360 static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
10365 /* find out what's out there already */
10366 ret = i40e_fetch_switch_configuration(pf, false);
10368 dev_info(&pf->pdev->dev,
10369 "couldn't fetch switch config, err %s aq_err %s\n",
10370 i40e_stat_str(&pf->hw, ret),
10371 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
10374 i40e_pf_reset_stats(pf);
10376 /* set the switch config bit for the whole device to
10377 * support limited promisc or true promisc
10378 * when user requests promisc. The default is limited
10382 if ((pf->hw.pf_id == 0) &&
10383 !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
10384 flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
10386 if (pf->hw.pf_id == 0) {
10389 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
10390 ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags,
10392 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
10393 dev_info(&pf->pdev->dev,
10394 "couldn't set switch config bits, err %s aq_err %s\n",
10395 i40e_stat_str(&pf->hw, ret),
10396 i40e_aq_str(&pf->hw,
10397 pf->hw.aq.asq_last_status));
10398 /* not a fatal problem, just keep going */
10402 /* first time setup */
10403 if (pf->lan_vsi == I40E_NO_VSI || reinit) {
10404 struct i40e_vsi *vsi = NULL;
10407 /* Set up the PF VSI associated with the PF's main VSI
10408 * that is already in the HW switch
10410 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
10411 uplink_seid = pf->veb[pf->lan_veb]->seid;
10413 uplink_seid = pf->mac_seid;
10414 if (pf->lan_vsi == I40E_NO_VSI)
10415 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
10417 vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
10419 dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
10420 i40e_fdir_teardown(pf);
10424 /* force a reset of TC and queue layout configurations */
10425 u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
10427 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
10428 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
10429 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
10431 i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
10433 i40e_fdir_sb_setup(pf);
10435 /* Setup static PF queue filter control settings */
10436 ret = i40e_setup_pf_filter_control(pf);
10438 dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
10440 /* Failure here should not stop continuing other steps */
10443 /* enable RSS in the HW, even for only one queue, as the stack can use
10446 if ((pf->flags & I40E_FLAG_RSS_ENABLED))
10447 i40e_pf_config_rss(pf);
10449 /* fill in link information and enable LSE reporting */
10450 i40e_update_link_info(&pf->hw);
10451 i40e_link_event(pf);
10453 /* Initialize user-specific link properties */
10454 pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
10455 I40E_AQ_AN_COMPLETED) ? true : false);
10463 * i40e_determine_queue_usage - Work out queue distribution
10464 * @pf: board private structure
10466 static void i40e_determine_queue_usage(struct i40e_pf *pf)
10470 pf->num_lan_qps = 0;
10472 pf->num_fcoe_qps = 0;
10475 /* Find the max queues to be put into basic use. We'll always be
10476 * using TC0, whether or not DCB is running, and TC0 will get the
10479 queues_left = pf->hw.func_caps.num_tx_qp;
10481 if ((queues_left == 1) ||
10482 !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
10483 /* one qp for PF, no queues for anything else */
10485 pf->alloc_rss_size = pf->num_lan_qps = 1;
10487 /* make sure all the fancies are disabled */
10488 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
10489 I40E_FLAG_IWARP_ENABLED |
10491 I40E_FLAG_FCOE_ENABLED |
10493 I40E_FLAG_FD_SB_ENABLED |
10494 I40E_FLAG_FD_ATR_ENABLED |
10495 I40E_FLAG_DCB_CAPABLE |
10496 I40E_FLAG_SRIOV_ENABLED |
10497 I40E_FLAG_VMDQ_ENABLED);
10498 } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
10499 I40E_FLAG_FD_SB_ENABLED |
10500 I40E_FLAG_FD_ATR_ENABLED |
10501 I40E_FLAG_DCB_CAPABLE))) {
10502 /* one qp for PF */
10503 pf->alloc_rss_size = pf->num_lan_qps = 1;
10504 queues_left -= pf->num_lan_qps;
10506 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
10507 I40E_FLAG_IWARP_ENABLED |
10509 I40E_FLAG_FCOE_ENABLED |
10511 I40E_FLAG_FD_SB_ENABLED |
10512 I40E_FLAG_FD_ATR_ENABLED |
10513 I40E_FLAG_DCB_ENABLED |
10514 I40E_FLAG_VMDQ_ENABLED);
10516 /* Not enough queues for all TCs */
10517 if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
10518 (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
10519 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
10520 dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
10522 pf->num_lan_qps = max_t(int, pf->rss_size_max,
10523 num_online_cpus());
10524 pf->num_lan_qps = min_t(int, pf->num_lan_qps,
10525 pf->hw.func_caps.num_tx_qp);
10527 queues_left -= pf->num_lan_qps;
10531 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
10532 if (I40E_DEFAULT_FCOE <= queues_left) {
10533 pf->num_fcoe_qps = I40E_DEFAULT_FCOE;
10534 } else if (I40E_MINIMUM_FCOE <= queues_left) {
10535 pf->num_fcoe_qps = I40E_MINIMUM_FCOE;
10537 pf->num_fcoe_qps = 0;
10538 pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
10539 dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n");
10542 queues_left -= pf->num_fcoe_qps;
10546 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
10547 if (queues_left > 1) {
10548 queues_left -= 1; /* save 1 queue for FD */
10550 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
10551 dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
10555 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
10556 pf->num_vf_qps && pf->num_req_vfs && queues_left) {
10557 pf->num_req_vfs = min_t(int, pf->num_req_vfs,
10558 (queues_left / pf->num_vf_qps));
10559 queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
10562 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
10563 pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
10564 pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
10565 (queues_left / pf->num_vmdq_qps));
10566 queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
10569 pf->queues_left = queues_left;
10570 dev_dbg(&pf->pdev->dev,
10571 "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
10572 pf->hw.func_caps.num_tx_qp,
10573 !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
10574 pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
10575 pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
10578 dev_dbg(&pf->pdev->dev, "fcoe queues = %d\n", pf->num_fcoe_qps);
10583 * i40e_setup_pf_filter_control - Setup PF static filter control
10584 * @pf: PF to be setup
10586 * i40e_setup_pf_filter_control sets up a PF's initial filter control
10587 * settings. If PE/FCoE are enabled then it will also set the per PF
10588 * based filter sizes required for them. It also enables Flow director,
10589 * ethertype and macvlan type filter settings for the pf.
10591 * Returns 0 on success, negative on failure
10593 static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
10595 struct i40e_filter_control_settings *settings = &pf->filter_settings;
10597 settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
10599 /* Flow Director is enabled */
10600 if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
10601 settings->enable_fdir = true;
10603 /* Ethtype and MACVLAN filters enabled for PF */
10604 settings->enable_ethtype = true;
10605 settings->enable_macvlan = true;
10607 if (i40e_set_filter_control(&pf->hw, settings))
10613 #define INFO_STRING_LEN 255
10614 #define REMAIN(__x) (INFO_STRING_LEN - (__x))
10615 static void i40e_print_features(struct i40e_pf *pf)
10617 struct i40e_hw *hw = &pf->hw;
10621 buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
10625 i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
10626 #ifdef CONFIG_PCI_IOV
10627 i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
10629 i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d",
10630 pf->hw.func_caps.num_vsis,
10631 pf->vsi[pf->lan_vsi]->num_queue_pairs);
10632 if (pf->flags & I40E_FLAG_RSS_ENABLED)
10633 i += snprintf(&buf[i], REMAIN(i), " RSS");
10634 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
10635 i += snprintf(&buf[i], REMAIN(i), " FD_ATR");
10636 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
10637 i += snprintf(&buf[i], REMAIN(i), " FD_SB");
10638 i += snprintf(&buf[i], REMAIN(i), " NTUPLE");
10640 if (pf->flags & I40E_FLAG_DCB_CAPABLE)
10641 i += snprintf(&buf[i], REMAIN(i), " DCB");
10642 i += snprintf(&buf[i], REMAIN(i), " VxLAN");
10643 i += snprintf(&buf[i], REMAIN(i), " Geneve");
10644 if (pf->flags & I40E_FLAG_PTP)
10645 i += snprintf(&buf[i], REMAIN(i), " PTP");
10647 if (pf->flags & I40E_FLAG_FCOE_ENABLED)
10648 i += snprintf(&buf[i], REMAIN(i), " FCOE");
10650 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
10651 i += snprintf(&buf[i], REMAIN(i), " VEB");
10653 i += snprintf(&buf[i], REMAIN(i), " VEPA");
10655 dev_info(&pf->pdev->dev, "%s\n", buf);
10657 WARN_ON(i > INFO_STRING_LEN);
10661 * i40e_get_platform_mac_addr - get platform-specific MAC address
10663 * @pdev: PCI device information struct
10664 * @pf: board private structure
10666 * Look up the MAC address in Open Firmware on systems that support it,
10667 * and use IDPROM on SPARC if no OF address is found. On return, the
10668 * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value
10669 * has been selected.
10671 static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
10673 pf->flags &= ~I40E_FLAG_PF_MAC;
10674 if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
10675 pf->flags |= I40E_FLAG_PF_MAC;
10679 * i40e_probe - Device initialization routine
10680 * @pdev: PCI device information struct
10681 * @ent: entry in i40e_pci_tbl
10683 * i40e_probe initializes a PF identified by a pci_dev structure.
10684 * The OS initialization, configuring of the PF private structure,
10685 * and a hardware reset occur.
10687 * Returns 0 on success, negative on failure
10689 static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
10691 struct i40e_aq_get_phy_abilities_resp abilities;
10692 struct i40e_pf *pf;
10693 struct i40e_hw *hw;
10694 static u16 pfs_found;
10702 err = pci_enable_device_mem(pdev);
10706 /* set up for high or low dma */
10707 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
10709 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
10711 dev_err(&pdev->dev,
10712 "DMA configuration failed: 0x%x\n", err);
10717 /* set up pci connections */
10718 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
10719 IORESOURCE_MEM), i40e_driver_name);
10721 dev_info(&pdev->dev,
10722 "pci_request_selected_regions failed %d\n", err);
10726 pci_enable_pcie_error_reporting(pdev);
10727 pci_set_master(pdev);
10729 /* Now that we have a PCI connection, we need to do the
10730 * low level device setup. This is primarily setting up
10731 * the Admin Queue structures and then querying for the
10732 * device's current profile information.
10734 pf = kzalloc(sizeof(*pf), GFP_KERNEL);
10741 set_bit(__I40E_DOWN, &pf->state);
10746 pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
10747 I40E_MAX_CSR_SPACE);
10749 hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
10750 if (!hw->hw_addr) {
10752 dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
10753 (unsigned int)pci_resource_start(pdev, 0),
10754 pf->ioremap_len, err);
10757 hw->vendor_id = pdev->vendor;
10758 hw->device_id = pdev->device;
10759 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
10760 hw->subsystem_vendor_id = pdev->subsystem_vendor;
10761 hw->subsystem_device_id = pdev->subsystem_device;
10762 hw->bus.device = PCI_SLOT(pdev->devfn);
10763 hw->bus.func = PCI_FUNC(pdev->devfn);
10764 pf->instance = pfs_found;
10766 /* set up the locks for the AQ, do this only once in probe
10767 * and destroy them only once in remove
10769 mutex_init(&hw->aq.asq_mutex);
10770 mutex_init(&hw->aq.arq_mutex);
10773 pf->msg_enable = pf->hw.debug_mask;
10774 pf->msg_enable = debug;
10777 /* do a special CORER for clearing PXE mode once at init */
10778 if (hw->revision_id == 0 &&
10779 (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
10780 wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
10785 i40e_clear_pxe_mode(hw);
10788 /* Reset here to make sure all is clean and to define PF 'n' */
10790 err = i40e_pf_reset(hw);
10792 dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
10797 hw->aq.num_arq_entries = I40E_AQ_LEN;
10798 hw->aq.num_asq_entries = I40E_AQ_LEN;
10799 hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
10800 hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
10801 pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
10803 snprintf(pf->int_name, sizeof(pf->int_name) - 1,
10805 dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
10807 err = i40e_init_shared_code(hw);
10809 dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
10814 /* set up a default setting for link flow control */
10815 pf->hw.fc.requested_mode = I40E_FC_NONE;
10817 err = i40e_init_adminq(hw);
10819 if (err == I40E_ERR_FIRMWARE_API_VERSION)
10820 dev_info(&pdev->dev,
10821 "The driver for the device stopped because the NVM image is newer than expected. You must install the most recent version of the network driver.\n");
10823 dev_info(&pdev->dev,
10824 "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
10829 /* provide nvm, fw, api versions */
10830 dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
10831 hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
10832 hw->aq.api_maj_ver, hw->aq.api_min_ver,
10833 i40e_nvm_version_str(hw));
10835 if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
10836 hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR)
10837 dev_info(&pdev->dev,
10838 "The driver for the device detected a newer version of the NVM image than expected. Please install the most recent version of the network driver.\n");
10839 else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR ||
10840 hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1))
10841 dev_info(&pdev->dev,
10842 "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
10844 i40e_verify_eeprom(pf);
10846 /* Rev 0 hardware was never productized */
10847 if (hw->revision_id < 1)
10848 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");
10850 i40e_clear_pxe_mode(hw);
10851 err = i40e_get_capabilities(pf);
10853 goto err_adminq_setup;
10855 err = i40e_sw_init(pf);
10857 dev_info(&pdev->dev, "sw_init failed: %d\n", err);
10861 err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
10862 hw->func_caps.num_rx_qp,
10863 pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
10865 dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
10866 goto err_init_lan_hmc;
10869 err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
10871 dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
10873 goto err_configure_lan_hmc;
10876 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
10877 * Ignore error return codes because if it was already disabled via
10878 * hardware settings this will fail
10880 if (pf->flags & I40E_FLAG_STOP_FW_LLDP) {
10881 dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
10882 i40e_aq_stop_lldp(hw, true, NULL);
10885 i40e_get_mac_addr(hw, hw->mac.addr);
10886 /* allow a platform config to override the HW addr */
10887 i40e_get_platform_mac_addr(pdev, pf);
10888 if (!is_valid_ether_addr(hw->mac.addr)) {
10889 dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
10893 dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
10894 ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
10895 i40e_get_port_mac_addr(hw, hw->mac.port_addr);
10896 if (is_valid_ether_addr(hw->mac.port_addr))
10897 pf->flags |= I40E_FLAG_PORT_ID_VALID;
10899 err = i40e_get_san_mac_addr(hw, hw->mac.san_addr);
10901 dev_info(&pdev->dev,
10902 "(non-fatal) SAN MAC retrieval failed: %d\n", err);
10903 if (!is_valid_ether_addr(hw->mac.san_addr)) {
10904 dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
10906 ether_addr_copy(hw->mac.san_addr, hw->mac.addr);
10908 dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr);
10909 #endif /* I40E_FCOE */
10911 pci_set_drvdata(pdev, pf);
10912 pci_save_state(pdev);
10913 #ifdef CONFIG_I40E_DCB
10914 err = i40e_init_pf_dcb(pf);
10916 dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
10917 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
10918 /* Continue without DCB enabled */
10920 #endif /* CONFIG_I40E_DCB */
10922 /* set up periodic task facility */
10923 setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
10924 pf->service_timer_period = HZ;
10926 INIT_WORK(&pf->service_task, i40e_service_task);
10927 clear_bit(__I40E_SERVICE_SCHED, &pf->state);
10928 pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
10930 /* NVM bit on means WoL disabled for the port */
10931 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
10932 if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
10933 pf->wol_en = false;
10936 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
10938 /* set up the main switch operations */
10939 i40e_determine_queue_usage(pf);
10940 err = i40e_init_interrupt_scheme(pf);
10942 goto err_switch_setup;
10944 /* The number of VSIs reported by the FW is the minimum guaranteed
10945 * to us; HW supports far more and we share the remaining pool with
10946 * the other PFs. We allocate space for more than the guarantee with
10947 * the understanding that we might not get them all later.
10949 if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
10950 pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
10952 pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
10954 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
10955 pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
10959 goto err_switch_setup;
10962 #ifdef CONFIG_PCI_IOV
10963 /* prep for VF support */
10964 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
10965 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
10966 !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
10967 if (pci_num_vf(pdev))
10968 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
10971 err = i40e_setup_pf_switch(pf, false);
10973 dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
10977 /* Make sure flow control is set according to current settings */
10978 err = i40e_set_fc(hw, &set_fc_aq_fail, true);
10979 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET)
10980 dev_dbg(&pf->pdev->dev,
10981 "Set fc with err %s aq_err %s on get_phy_cap\n",
10982 i40e_stat_str(hw, err),
10983 i40e_aq_str(hw, hw->aq.asq_last_status));
10984 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET)
10985 dev_dbg(&pf->pdev->dev,
10986 "Set fc with err %s aq_err %s on set_phy_config\n",
10987 i40e_stat_str(hw, err),
10988 i40e_aq_str(hw, hw->aq.asq_last_status));
10989 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE)
10990 dev_dbg(&pf->pdev->dev,
10991 "Set fc with err %s aq_err %s on get_link_info\n",
10992 i40e_stat_str(hw, err),
10993 i40e_aq_str(hw, hw->aq.asq_last_status));
10995 /* if FDIR VSI was set up, start it now */
10996 for (i = 0; i < pf->num_alloc_vsi; i++) {
10997 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
10998 i40e_vsi_open(pf->vsi[i]);
11003 /* The driver only wants link up/down and module qualification
11004 * reports from firmware. Note the negative logic.
11006 err = i40e_aq_set_phy_int_mask(&pf->hw,
11007 ~(I40E_AQ_EVENT_LINK_UPDOWN |
11008 I40E_AQ_EVENT_MEDIA_NA |
11009 I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
11011 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
11012 i40e_stat_str(&pf->hw, err),
11013 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
11015 /* Reconfigure hardware for allowing smaller MSS in the case
11016 * of TSO, so that we avoid the MDD being fired and causing
11017 * a reset in the case of small MSS+TSO.
11019 val = rd32(hw, I40E_REG_MSS);
11020 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
11021 val &= ~I40E_REG_MSS_MIN_MASK;
11022 val |= I40E_64BYTE_MSS;
11023 wr32(hw, I40E_REG_MSS, val);
11026 if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
11028 err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
11030 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
11031 i40e_stat_str(&pf->hw, err),
11032 i40e_aq_str(&pf->hw,
11033 pf->hw.aq.asq_last_status));
11035 /* The main driver is (mostly) up and happy. We need to set this state
11036 * before setting up the misc vector or we get a race and the vector
11037 * ends up disabled forever.
11039 clear_bit(__I40E_DOWN, &pf->state);
11041 /* In case of MSIX we are going to setup the misc vector right here
11042 * to handle admin queue events etc. In case of legacy and MSI
11043 * the misc functionality and queue processing is combined in
11044 * the same vector and that gets setup at open.
11046 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
11047 err = i40e_setup_misc_vector(pf);
11049 dev_info(&pdev->dev,
11050 "setup of misc vector failed: %d\n", err);
11055 #ifdef CONFIG_PCI_IOV
11056 /* prep for VF support */
11057 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
11058 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
11059 !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
11060 /* disable link interrupts for VFs */
11061 val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
11062 val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
11063 wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
11066 if (pci_num_vf(pdev)) {
11067 dev_info(&pdev->dev,
11068 "Active VFs found, allocating resources.\n");
11069 err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
11071 dev_info(&pdev->dev,
11072 "Error %d allocating resources for existing VFs\n",
11076 #endif /* CONFIG_PCI_IOV */
11078 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
11079 pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
11080 pf->num_iwarp_msix,
11081 I40E_IWARP_IRQ_PILE_ID);
11082 if (pf->iwarp_base_vector < 0) {
11083 dev_info(&pdev->dev,
11084 "failed to get tracking for %d vectors for IWARP err=%d\n",
11085 pf->num_iwarp_msix, pf->iwarp_base_vector);
11086 pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
11090 i40e_dbg_pf_init(pf);
11092 /* tell the firmware that we're starting */
11093 i40e_send_version(pf);
11095 /* since everything's happy, start the service_task timer */
11096 mod_timer(&pf->service_timer,
11097 round_jiffies(jiffies + pf->service_timer_period));
11099 /* add this PF to client device list and launch a client service task */
11100 err = i40e_lan_add_device(pf);
11102 dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
11106 /* create FCoE interface */
11107 i40e_fcoe_vsi_setup(pf);
11110 #define PCI_SPEED_SIZE 8
11111 #define PCI_WIDTH_SIZE 8
11112 /* Devices on the IOSF bus do not have this information
11113 * and will report PCI Gen 1 x 1 by default so don't bother
11116 if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) {
11117 char speed[PCI_SPEED_SIZE] = "Unknown";
11118 char width[PCI_WIDTH_SIZE] = "Unknown";
11120 /* Get the negotiated link width and speed from PCI config
11123 pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
11126 i40e_set_pci_config_data(hw, link_status);
11128 switch (hw->bus.speed) {
11129 case i40e_bus_speed_8000:
11130 strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
11131 case i40e_bus_speed_5000:
11132 strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
11133 case i40e_bus_speed_2500:
11134 strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
11138 switch (hw->bus.width) {
11139 case i40e_bus_width_pcie_x8:
11140 strncpy(width, "8", PCI_WIDTH_SIZE); break;
11141 case i40e_bus_width_pcie_x4:
11142 strncpy(width, "4", PCI_WIDTH_SIZE); break;
11143 case i40e_bus_width_pcie_x2:
11144 strncpy(width, "2", PCI_WIDTH_SIZE); break;
11145 case i40e_bus_width_pcie_x1:
11146 strncpy(width, "1", PCI_WIDTH_SIZE); break;
11151 dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
11154 if (hw->bus.width < i40e_bus_width_pcie_x8 ||
11155 hw->bus.speed < i40e_bus_speed_8000) {
11156 dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
11157 dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
11161 /* get the requested speeds from the fw */
11162 err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
11164 dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
11165 i40e_stat_str(&pf->hw, err),
11166 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
11167 pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
11169 /* get the supported phy types from the fw */
11170 err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
11172 dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
11173 i40e_stat_str(&pf->hw, err),
11174 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
11175 pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type);
11177 /* Add a filter to drop all Flow control frames from any VSI from being
11178 * transmitted. By doing so we stop a malicious VF from sending out
11179 * PAUSE or PFC frames and potentially controlling traffic for other
11181 * The FW can still send Flow control frames if enabled.
11183 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
11184 pf->main_vsi_seid);
11186 if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) ||
11187 (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4))
11188 pf->flags |= I40E_FLAG_HAVE_10GBASET_PHY;
11190 /* print a string summarizing features */
11191 i40e_print_features(pf);
11195 /* Unwind what we've done if something failed in the setup */
11197 set_bit(__I40E_DOWN, &pf->state);
11198 i40e_clear_interrupt_scheme(pf);
11201 i40e_reset_interrupt_capability(pf);
11202 del_timer_sync(&pf->service_timer);
11204 err_configure_lan_hmc:
11205 (void)i40e_shutdown_lan_hmc(hw);
11207 kfree(pf->qp_pile);
11211 iounmap(hw->hw_addr);
11215 pci_disable_pcie_error_reporting(pdev);
11216 pci_release_selected_regions(pdev,
11217 pci_select_bars(pdev, IORESOURCE_MEM));
11220 pci_disable_device(pdev);
11225 * i40e_remove - Device removal routine
11226 * @pdev: PCI device information struct
11228 * i40e_remove is called by the PCI subsystem to alert the driver
11229 * that is should release a PCI device. This could be caused by a
11230 * Hot-Plug event, or because the driver is going to be removed from
11233 static void i40e_remove(struct pci_dev *pdev)
11235 struct i40e_pf *pf = pci_get_drvdata(pdev);
11236 struct i40e_hw *hw = &pf->hw;
11237 i40e_status ret_code;
11240 i40e_dbg_pf_exit(pf);
11244 /* Disable RSS in hw */
11245 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
11246 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
11248 /* no more scheduling of any task */
11249 set_bit(__I40E_SUSPENDED, &pf->state);
11250 set_bit(__I40E_DOWN, &pf->state);
11251 if (pf->service_timer.data)
11252 del_timer_sync(&pf->service_timer);
11253 if (pf->service_task.func)
11254 cancel_work_sync(&pf->service_task);
11256 if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
11258 pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
11261 i40e_fdir_teardown(pf);
11263 /* If there is a switch structure or any orphans, remove them.
11264 * This will leave only the PF's VSI remaining.
11266 for (i = 0; i < I40E_MAX_VEB; i++) {
11270 if (pf->veb[i]->uplink_seid == pf->mac_seid ||
11271 pf->veb[i]->uplink_seid == 0)
11272 i40e_switch_branch_release(pf->veb[i]);
11275 /* Now we can shutdown the PF's VSI, just before we kill
11278 if (pf->vsi[pf->lan_vsi])
11279 i40e_vsi_release(pf->vsi[pf->lan_vsi]);
11281 /* remove attached clients */
11282 ret_code = i40e_lan_del_device(pf);
11284 dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
11288 /* shutdown and destroy the HMC */
11289 if (hw->hmc.hmc_obj) {
11290 ret_code = i40e_shutdown_lan_hmc(hw);
11292 dev_warn(&pdev->dev,
11293 "Failed to destroy the HMC resources: %d\n",
11297 /* shutdown the adminq */
11298 ret_code = i40e_shutdown_adminq(hw);
11300 dev_warn(&pdev->dev,
11301 "Failed to destroy the Admin Queue resources: %d\n",
11304 /* destroy the locks only once, here */
11305 mutex_destroy(&hw->aq.arq_mutex);
11306 mutex_destroy(&hw->aq.asq_mutex);
11308 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
11309 i40e_clear_interrupt_scheme(pf);
11310 for (i = 0; i < pf->num_alloc_vsi; i++) {
11312 i40e_vsi_clear_rings(pf->vsi[i]);
11313 i40e_vsi_clear(pf->vsi[i]);
11318 for (i = 0; i < I40E_MAX_VEB; i++) {
11323 kfree(pf->qp_pile);
11326 iounmap(hw->hw_addr);
11328 pci_release_selected_regions(pdev,
11329 pci_select_bars(pdev, IORESOURCE_MEM));
11331 pci_disable_pcie_error_reporting(pdev);
11332 pci_disable_device(pdev);
11336 * i40e_pci_error_detected - warning that something funky happened in PCI land
11337 * @pdev: PCI device information struct
11339 * Called to warn that something happened and the error handling steps
11340 * are in progress. Allows the driver to quiesce things, be ready for
11343 static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
11344 enum pci_channel_state error)
11346 struct i40e_pf *pf = pci_get_drvdata(pdev);
11348 dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
11350 /* shutdown all operations */
11351 if (!test_bit(__I40E_SUSPENDED, &pf->state)) {
11353 i40e_prep_for_reset(pf);
11357 /* Request a slot reset */
11358 return PCI_ERS_RESULT_NEED_RESET;
11362 * i40e_pci_error_slot_reset - a PCI slot reset just happened
11363 * @pdev: PCI device information struct
11365 * Called to find if the driver can work with the device now that
11366 * the pci slot has been reset. If a basic connection seems good
11367 * (registers are readable and have sane content) then return a
11368 * happy little PCI_ERS_RESULT_xxx.
11370 static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
11372 struct i40e_pf *pf = pci_get_drvdata(pdev);
11373 pci_ers_result_t result;
11377 dev_dbg(&pdev->dev, "%s\n", __func__);
11378 if (pci_enable_device_mem(pdev)) {
11379 dev_info(&pdev->dev,
11380 "Cannot re-enable PCI device after reset.\n");
11381 result = PCI_ERS_RESULT_DISCONNECT;
11383 pci_set_master(pdev);
11384 pci_restore_state(pdev);
11385 pci_save_state(pdev);
11386 pci_wake_from_d3(pdev, false);
11388 reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
11390 result = PCI_ERS_RESULT_RECOVERED;
11392 result = PCI_ERS_RESULT_DISCONNECT;
11395 err = pci_cleanup_aer_uncorrect_error_status(pdev);
11397 dev_info(&pdev->dev,
11398 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
11400 /* non-fatal, continue */
11407 * i40e_pci_error_resume - restart operations after PCI error recovery
11408 * @pdev: PCI device information struct
11410 * Called to allow the driver to bring things back up after PCI error
11411 * and/or reset recovery has finished.
11413 static void i40e_pci_error_resume(struct pci_dev *pdev)
11415 struct i40e_pf *pf = pci_get_drvdata(pdev);
11417 dev_dbg(&pdev->dev, "%s\n", __func__);
11418 if (test_bit(__I40E_SUSPENDED, &pf->state))
11422 i40e_handle_reset_warning(pf);
11427 * i40e_shutdown - PCI callback for shutting down
11428 * @pdev: PCI device information struct
11430 static void i40e_shutdown(struct pci_dev *pdev)
11432 struct i40e_pf *pf = pci_get_drvdata(pdev);
11433 struct i40e_hw *hw = &pf->hw;
11435 set_bit(__I40E_SUSPENDED, &pf->state);
11436 set_bit(__I40E_DOWN, &pf->state);
11438 i40e_prep_for_reset(pf);
11441 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
11442 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
11444 del_timer_sync(&pf->service_timer);
11445 cancel_work_sync(&pf->service_task);
11446 i40e_fdir_teardown(pf);
11449 i40e_prep_for_reset(pf);
11452 wr32(hw, I40E_PFPM_APM,
11453 (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
11454 wr32(hw, I40E_PFPM_WUFC,
11455 (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
11457 i40e_clear_interrupt_scheme(pf);
11459 if (system_state == SYSTEM_POWER_OFF) {
11460 pci_wake_from_d3(pdev, pf->wol_en);
11461 pci_set_power_state(pdev, PCI_D3hot);
11467 * i40e_suspend - PCI callback for moving to D3
11468 * @pdev: PCI device information struct
11470 static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
11472 struct i40e_pf *pf = pci_get_drvdata(pdev);
11473 struct i40e_hw *hw = &pf->hw;
11476 set_bit(__I40E_SUSPENDED, &pf->state);
11477 set_bit(__I40E_DOWN, &pf->state);
11480 i40e_prep_for_reset(pf);
11483 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
11484 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
11486 i40e_stop_misc_vector(pf);
11488 retval = pci_save_state(pdev);
11492 pci_wake_from_d3(pdev, pf->wol_en);
11493 pci_set_power_state(pdev, PCI_D3hot);
11499 * i40e_resume - PCI callback for waking up from D3
11500 * @pdev: PCI device information struct
11502 static int i40e_resume(struct pci_dev *pdev)
11504 struct i40e_pf *pf = pci_get_drvdata(pdev);
11507 pci_set_power_state(pdev, PCI_D0);
11508 pci_restore_state(pdev);
11509 /* pci_restore_state() clears dev->state_saves, so
11510 * call pci_save_state() again to restore it.
11512 pci_save_state(pdev);
11514 err = pci_enable_device_mem(pdev);
11516 dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
11519 pci_set_master(pdev);
11521 /* no wakeup events while running */
11522 pci_wake_from_d3(pdev, false);
11524 /* handling the reset will rebuild the device state */
11525 if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) {
11526 clear_bit(__I40E_DOWN, &pf->state);
11528 i40e_reset_and_rebuild(pf, false);
11536 static const struct pci_error_handlers i40e_err_handler = {
11537 .error_detected = i40e_pci_error_detected,
11538 .slot_reset = i40e_pci_error_slot_reset,
11539 .resume = i40e_pci_error_resume,
11542 static struct pci_driver i40e_driver = {
11543 .name = i40e_driver_name,
11544 .id_table = i40e_pci_tbl,
11545 .probe = i40e_probe,
11546 .remove = i40e_remove,
11548 .suspend = i40e_suspend,
11549 .resume = i40e_resume,
11551 .shutdown = i40e_shutdown,
11552 .err_handler = &i40e_err_handler,
11553 .sriov_configure = i40e_pci_sriov_configure,
11557 * i40e_init_module - Driver registration routine
11559 * i40e_init_module is the first routine called when the driver is
11560 * loaded. All it does is register with the PCI subsystem.
11562 static int __init i40e_init_module(void)
11564 pr_info("%s: %s - version %s\n", i40e_driver_name,
11565 i40e_driver_string, i40e_driver_version_str);
11566 pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
11568 /* we will see if single thread per module is enough for now,
11569 * it can't be any worse than using the system workqueue which
11570 * was already single threaded
11572 i40e_wq = create_singlethread_workqueue(i40e_driver_name);
11574 pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
11579 return pci_register_driver(&i40e_driver);
11581 module_init(i40e_init_module);
11584 * i40e_exit_module - Driver exit cleanup routine
11586 * i40e_exit_module is called just before the driver is removed
11589 static void __exit i40e_exit_module(void)
11591 pci_unregister_driver(&i40e_driver);
11592 destroy_workqueue(i40e_wq);
11595 module_exit(i40e_exit_module);