1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
4 #include <linux/etherdevice.h>
5 #include <linux/of_net.h>
11 #include "i40e_diag.h"
12 #include <net/udp_tunnel.h>
13 /* All i40e tracepoints are defined by the include below, which
14 * must be included exactly once across the whole kernel with
15 * CREATE_TRACE_POINTS defined
17 #define CREATE_TRACE_POINTS
18 #include "i40e_trace.h"
20 const char i40e_driver_name
[] = "i40e";
21 static const char i40e_driver_string
[] =
22 "Intel(R) Ethernet Connection XL710 Network Driver";
26 #define DRV_VERSION_MAJOR 2
27 #define DRV_VERSION_MINOR 3
28 #define DRV_VERSION_BUILD 2
29 #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
30 __stringify(DRV_VERSION_MINOR) "." \
31 __stringify(DRV_VERSION_BUILD) DRV_KERN
32 const char i40e_driver_version_str
[] = DRV_VERSION
;
33 static const char i40e_copyright
[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
35 /* a bit of forward declarations */
36 static void i40e_vsi_reinit_locked(struct i40e_vsi
*vsi
);
37 static void i40e_handle_reset_warning(struct i40e_pf
*pf
, bool lock_acquired
);
38 static int i40e_add_vsi(struct i40e_vsi
*vsi
);
39 static int i40e_add_veb(struct i40e_veb
*veb
, struct i40e_vsi
*vsi
);
40 static int i40e_setup_pf_switch(struct i40e_pf
*pf
, bool reinit
);
41 static int i40e_setup_misc_vector(struct i40e_pf
*pf
);
42 static void i40e_determine_queue_usage(struct i40e_pf
*pf
);
43 static int i40e_setup_pf_filter_control(struct i40e_pf
*pf
);
44 static void i40e_prep_for_reset(struct i40e_pf
*pf
, bool lock_acquired
);
45 static int i40e_reset(struct i40e_pf
*pf
);
46 static void i40e_rebuild(struct i40e_pf
*pf
, bool reinit
, bool lock_acquired
);
47 static void i40e_fdir_sb_setup(struct i40e_pf
*pf
);
48 static int i40e_veb_get_bw_info(struct i40e_veb
*veb
);
49 static int i40e_get_capabilities(struct i40e_pf
*pf
,
50 enum i40e_admin_queue_opc list_type
);
53 /* i40e_pci_tbl - PCI Device ID Table
55 * Last entry must be all 0s
57 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
58 * Class, Class Mask, private data (not used) }
60 static const struct pci_device_id i40e_pci_tbl
[] = {
61 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_SFP_XL710
), 0},
62 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QEMU
), 0},
63 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_B
), 0},
64 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_C
), 0},
65 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_A
), 0},
66 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_B
), 0},
67 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_C
), 0},
68 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T
), 0},
69 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T4
), 0},
70 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_X722
), 0},
71 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_X722
), 0},
72 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_SFP_X722
), 0},
73 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_1G_BASE_T_X722
), 0},
74 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T_X722
), 0},
75 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_SFP_I_X722
), 0},
76 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_20G_KR2
), 0},
77 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_20G_KR2_A
), 0},
78 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_25G_B
), 0},
79 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_25G_SFP28
), 0},
80 /* required last entry */
83 MODULE_DEVICE_TABLE(pci
, i40e_pci_tbl
);
85 #define I40E_MAX_VF_COUNT 128
86 static int debug
= -1;
87 module_param(debug
, uint
, 0);
88 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXX)");
90 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
91 MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
92 MODULE_LICENSE("GPL");
93 MODULE_VERSION(DRV_VERSION
);
95 static struct workqueue_struct
*i40e_wq
;
98 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
99 * @hw: pointer to the HW structure
100 * @mem: ptr to mem struct to fill out
101 * @size: size of memory requested
102 * @alignment: what to align the allocation to
104 int i40e_allocate_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
,
105 u64 size
, u32 alignment
)
107 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
109 mem
->size
= ALIGN(size
, alignment
);
110 mem
->va
= dma_zalloc_coherent(&pf
->pdev
->dev
, mem
->size
,
111 &mem
->pa
, GFP_KERNEL
);
119 * i40e_free_dma_mem_d - OS specific memory free for shared code
120 * @hw: pointer to the HW structure
121 * @mem: ptr to mem struct to free
123 int i40e_free_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
)
125 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
127 dma_free_coherent(&pf
->pdev
->dev
, mem
->size
, mem
->va
, mem
->pa
);
136 * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
137 * @hw: pointer to the HW structure
138 * @mem: ptr to mem struct to fill out
139 * @size: size of memory requested
141 int i40e_allocate_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
,
145 mem
->va
= kzalloc(size
, GFP_KERNEL
);
154 * i40e_free_virt_mem_d - OS specific memory free for shared code
155 * @hw: pointer to the HW structure
156 * @mem: ptr to mem struct to free
158 int i40e_free_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
)
160 /* it's ok to kfree a NULL pointer */
169 * i40e_get_lump - find a lump of free generic resource
170 * @pf: board private structure
171 * @pile: the pile of resource to search
172 * @needed: the number of items needed
173 * @id: an owner id to stick on the items assigned
175 * Returns the base item index of the lump, or negative for error
177 * The search_hint trick and lack of advanced fit-finding only work
178 * because we're highly likely to have all the same size lump requests.
179 * Linear search time and any fragmentation should be minimal.
181 static int i40e_get_lump(struct i40e_pf
*pf
, struct i40e_lump_tracking
*pile
,
187 if (!pile
|| needed
== 0 || id
>= I40E_PILE_VALID_BIT
) {
188 dev_info(&pf
->pdev
->dev
,
189 "param err: pile=%s needed=%d id=0x%04x\n",
190 pile
? "<valid>" : "<null>", needed
, id
);
194 /* start the linear search with an imperfect hint */
195 i
= pile
->search_hint
;
196 while (i
< pile
->num_entries
) {
197 /* skip already allocated entries */
198 if (pile
->list
[i
] & I40E_PILE_VALID_BIT
) {
203 /* do we have enough in this lump? */
204 for (j
= 0; (j
< needed
) && ((i
+j
) < pile
->num_entries
); j
++) {
205 if (pile
->list
[i
+j
] & I40E_PILE_VALID_BIT
)
210 /* there was enough, so assign it to the requestor */
211 for (j
= 0; j
< needed
; j
++)
212 pile
->list
[i
+j
] = id
| I40E_PILE_VALID_BIT
;
214 pile
->search_hint
= i
+ j
;
218 /* not enough, so skip over it and continue looking */
226 * i40e_put_lump - return a lump of generic resource
227 * @pile: the pile of resource to search
228 * @index: the base item index
229 * @id: the owner id of the items assigned
231 * Returns the count of items in the lump
233 static int i40e_put_lump(struct i40e_lump_tracking
*pile
, u16 index
, u16 id
)
235 int valid_id
= (id
| I40E_PILE_VALID_BIT
);
239 if (!pile
|| index
>= pile
->num_entries
)
243 i
< pile
->num_entries
&& pile
->list
[i
] == valid_id
;
249 if (count
&& index
< pile
->search_hint
)
250 pile
->search_hint
= index
;
256 * i40e_find_vsi_from_id - searches for the vsi with the given id
257 * @pf: the pf structure to search for the vsi
258 * @id: id of the vsi it is searching for
260 struct i40e_vsi
*i40e_find_vsi_from_id(struct i40e_pf
*pf
, u16 id
)
264 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
265 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->id
== id
))
272 * i40e_service_event_schedule - Schedule the service task to wake up
273 * @pf: board private structure
275 * If not already scheduled, this puts the task into the work queue
277 void i40e_service_event_schedule(struct i40e_pf
*pf
)
279 if (!test_bit(__I40E_DOWN
, pf
->state
) &&
280 !test_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
))
281 queue_work(i40e_wq
, &pf
->service_task
);
285 * i40e_tx_timeout - Respond to a Tx Hang
286 * @netdev: network interface device structure
288 * If any port has noticed a Tx timeout, it is likely that the whole
289 * device is munged, not just the one netdev port, so go for the full
292 static void i40e_tx_timeout(struct net_device
*netdev
)
294 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
295 struct i40e_vsi
*vsi
= np
->vsi
;
296 struct i40e_pf
*pf
= vsi
->back
;
297 struct i40e_ring
*tx_ring
= NULL
;
298 unsigned int i
, hung_queue
= 0;
301 pf
->tx_timeout_count
++;
303 /* find the stopped queue the same way the stack does */
304 for (i
= 0; i
< netdev
->num_tx_queues
; i
++) {
305 struct netdev_queue
*q
;
306 unsigned long trans_start
;
308 q
= netdev_get_tx_queue(netdev
, i
);
309 trans_start
= q
->trans_start
;
310 if (netif_xmit_stopped(q
) &&
312 (trans_start
+ netdev
->watchdog_timeo
))) {
318 if (i
== netdev
->num_tx_queues
) {
319 netdev_info(netdev
, "tx_timeout: no netdev hung queue found\n");
321 /* now that we have an index, find the tx_ring struct */
322 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
323 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
) {
325 vsi
->tx_rings
[i
]->queue_index
) {
326 tx_ring
= vsi
->tx_rings
[i
];
333 if (time_after(jiffies
, (pf
->tx_timeout_last_recovery
+ HZ
*20)))
334 pf
->tx_timeout_recovery_level
= 1; /* reset after some time */
335 else if (time_before(jiffies
,
336 (pf
->tx_timeout_last_recovery
+ netdev
->watchdog_timeo
)))
337 return; /* don't do any new action before the next timeout */
339 /* don't kick off another recovery if one is already pending */
340 if (test_and_set_bit(__I40E_TIMEOUT_RECOVERY_PENDING
, pf
->state
))
344 head
= i40e_get_head(tx_ring
);
345 /* Read interrupt register */
346 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
348 I40E_PFINT_DYN_CTLN(tx_ring
->q_vector
->v_idx
+
349 tx_ring
->vsi
->base_vector
- 1));
351 val
= rd32(&pf
->hw
, I40E_PFINT_DYN_CTL0
);
353 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",
354 vsi
->seid
, hung_queue
, tx_ring
->next_to_clean
,
355 head
, tx_ring
->next_to_use
,
356 readl(tx_ring
->tail
), val
);
359 pf
->tx_timeout_last_recovery
= jiffies
;
360 netdev_info(netdev
, "tx_timeout recovery level %d, hung_queue %d\n",
361 pf
->tx_timeout_recovery_level
, hung_queue
);
363 switch (pf
->tx_timeout_recovery_level
) {
365 set_bit(__I40E_PF_RESET_REQUESTED
, pf
->state
);
368 set_bit(__I40E_CORE_RESET_REQUESTED
, pf
->state
);
371 set_bit(__I40E_GLOBAL_RESET_REQUESTED
, pf
->state
);
374 netdev_err(netdev
, "tx_timeout recovery unsuccessful\n");
378 i40e_service_event_schedule(pf
);
379 pf
->tx_timeout_recovery_level
++;
383 * i40e_get_vsi_stats_struct - Get System Network Statistics
384 * @vsi: the VSI we care about
386 * Returns the address of the device statistics structure.
387 * The statistics are actually updated from the service task.
389 struct rtnl_link_stats64
*i40e_get_vsi_stats_struct(struct i40e_vsi
*vsi
)
391 return &vsi
->net_stats
;
395 * i40e_get_netdev_stats_struct_tx - populate stats from a Tx ring
396 * @ring: Tx ring to get statistics from
397 * @stats: statistics entry to be updated
399 static void i40e_get_netdev_stats_struct_tx(struct i40e_ring
*ring
,
400 struct rtnl_link_stats64
*stats
)
406 start
= u64_stats_fetch_begin_irq(&ring
->syncp
);
407 packets
= ring
->stats
.packets
;
408 bytes
= ring
->stats
.bytes
;
409 } while (u64_stats_fetch_retry_irq(&ring
->syncp
, start
));
411 stats
->tx_packets
+= packets
;
412 stats
->tx_bytes
+= bytes
;
416 * i40e_get_netdev_stats_struct - Get statistics for netdev interface
417 * @netdev: network interface device structure
418 * @stats: data structure to store statistics
420 * Returns the address of the device statistics structure.
421 * The statistics are actually updated from the service task.
423 static void i40e_get_netdev_stats_struct(struct net_device
*netdev
,
424 struct rtnl_link_stats64
*stats
)
426 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
427 struct i40e_vsi
*vsi
= np
->vsi
;
428 struct rtnl_link_stats64
*vsi_stats
= i40e_get_vsi_stats_struct(vsi
);
429 struct i40e_ring
*ring
;
432 if (test_bit(__I40E_VSI_DOWN
, vsi
->state
))
439 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
443 ring
= READ_ONCE(vsi
->tx_rings
[i
]);
446 i40e_get_netdev_stats_struct_tx(ring
, stats
);
448 if (i40e_enabled_xdp_vsi(vsi
)) {
450 i40e_get_netdev_stats_struct_tx(ring
, stats
);
455 start
= u64_stats_fetch_begin_irq(&ring
->syncp
);
456 packets
= ring
->stats
.packets
;
457 bytes
= ring
->stats
.bytes
;
458 } while (u64_stats_fetch_retry_irq(&ring
->syncp
, start
));
460 stats
->rx_packets
+= packets
;
461 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
;
477 * i40e_vsi_reset_stats - Resets all stats of the given vsi
478 * @vsi: the VSI to have its stats reset
480 void i40e_vsi_reset_stats(struct i40e_vsi
*vsi
)
482 struct rtnl_link_stats64
*ns
;
488 ns
= i40e_get_vsi_stats_struct(vsi
);
489 memset(ns
, 0, sizeof(*ns
));
490 memset(&vsi
->net_stats_offsets
, 0, sizeof(vsi
->net_stats_offsets
));
491 memset(&vsi
->eth_stats
, 0, sizeof(vsi
->eth_stats
));
492 memset(&vsi
->eth_stats_offsets
, 0, sizeof(vsi
->eth_stats_offsets
));
493 if (vsi
->rx_rings
&& vsi
->rx_rings
[0]) {
494 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
495 memset(&vsi
->rx_rings
[i
]->stats
, 0,
496 sizeof(vsi
->rx_rings
[i
]->stats
));
497 memset(&vsi
->rx_rings
[i
]->rx_stats
, 0,
498 sizeof(vsi
->rx_rings
[i
]->rx_stats
));
499 memset(&vsi
->tx_rings
[i
]->stats
, 0,
500 sizeof(vsi
->tx_rings
[i
]->stats
));
501 memset(&vsi
->tx_rings
[i
]->tx_stats
, 0,
502 sizeof(vsi
->tx_rings
[i
]->tx_stats
));
505 vsi
->stat_offsets_loaded
= false;
509 * i40e_pf_reset_stats - Reset all of the stats for the given PF
510 * @pf: the PF to be reset
512 void i40e_pf_reset_stats(struct i40e_pf
*pf
)
516 memset(&pf
->stats
, 0, sizeof(pf
->stats
));
517 memset(&pf
->stats_offsets
, 0, sizeof(pf
->stats_offsets
));
518 pf
->stat_offsets_loaded
= false;
520 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
522 memset(&pf
->veb
[i
]->stats
, 0,
523 sizeof(pf
->veb
[i
]->stats
));
524 memset(&pf
->veb
[i
]->stats_offsets
, 0,
525 sizeof(pf
->veb
[i
]->stats_offsets
));
526 pf
->veb
[i
]->stat_offsets_loaded
= false;
529 pf
->hw_csum_rx_error
= 0;
533 * i40e_stat_update48 - read and update a 48 bit stat from the chip
534 * @hw: ptr to the hardware info
535 * @hireg: the high 32 bit reg to read
536 * @loreg: the low 32 bit reg to read
537 * @offset_loaded: has the initial offset been loaded yet
538 * @offset: ptr to current offset value
539 * @stat: ptr to the stat
541 * Since the device stats are not reset at PFReset, they likely will not
542 * be zeroed when the driver starts. We'll save the first values read
543 * and use them as offsets to be subtracted from the raw values in order
544 * to report stats that count from zero. In the process, we also manage
545 * the potential roll-over.
547 static void i40e_stat_update48(struct i40e_hw
*hw
, u32 hireg
, u32 loreg
,
548 bool offset_loaded
, u64
*offset
, u64
*stat
)
552 if (hw
->device_id
== I40E_DEV_ID_QEMU
) {
553 new_data
= rd32(hw
, loreg
);
554 new_data
|= ((u64
)(rd32(hw
, hireg
) & 0xFFFF)) << 32;
556 new_data
= rd64(hw
, loreg
);
560 if (likely(new_data
>= *offset
))
561 *stat
= new_data
- *offset
;
563 *stat
= (new_data
+ BIT_ULL(48)) - *offset
;
564 *stat
&= 0xFFFFFFFFFFFFULL
;
568 * i40e_stat_update32 - read and update a 32 bit stat from the chip
569 * @hw: ptr to the hardware info
570 * @reg: the hw reg to read
571 * @offset_loaded: has the initial offset been loaded yet
572 * @offset: ptr to current offset value
573 * @stat: ptr to the stat
575 static void i40e_stat_update32(struct i40e_hw
*hw
, u32 reg
,
576 bool offset_loaded
, u64
*offset
, u64
*stat
)
580 new_data
= rd32(hw
, reg
);
583 if (likely(new_data
>= *offset
))
584 *stat
= (u32
)(new_data
- *offset
);
586 *stat
= (u32
)((new_data
+ BIT_ULL(32)) - *offset
);
590 * i40e_stat_update_and_clear32 - read and clear hw reg, update a 32 bit stat
591 * @hw: ptr to the hardware info
592 * @reg: the hw reg to read and clear
593 * @stat: ptr to the stat
595 static void i40e_stat_update_and_clear32(struct i40e_hw
*hw
, u32 reg
, u64
*stat
)
597 u32 new_data
= rd32(hw
, reg
);
599 wr32(hw
, reg
, 1); /* must write a nonzero value to clear register */
604 * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
605 * @vsi: the VSI to be updated
607 void i40e_update_eth_stats(struct i40e_vsi
*vsi
)
609 int stat_idx
= le16_to_cpu(vsi
->info
.stat_counter_idx
);
610 struct i40e_pf
*pf
= vsi
->back
;
611 struct i40e_hw
*hw
= &pf
->hw
;
612 struct i40e_eth_stats
*oes
;
613 struct i40e_eth_stats
*es
; /* device's eth stats */
615 es
= &vsi
->eth_stats
;
616 oes
= &vsi
->eth_stats_offsets
;
618 /* Gather up the stats that the hw collects */
619 i40e_stat_update32(hw
, I40E_GLV_TEPC(stat_idx
),
620 vsi
->stat_offsets_loaded
,
621 &oes
->tx_errors
, &es
->tx_errors
);
622 i40e_stat_update32(hw
, I40E_GLV_RDPC(stat_idx
),
623 vsi
->stat_offsets_loaded
,
624 &oes
->rx_discards
, &es
->rx_discards
);
625 i40e_stat_update32(hw
, I40E_GLV_RUPP(stat_idx
),
626 vsi
->stat_offsets_loaded
,
627 &oes
->rx_unknown_protocol
, &es
->rx_unknown_protocol
);
628 i40e_stat_update32(hw
, I40E_GLV_TEPC(stat_idx
),
629 vsi
->stat_offsets_loaded
,
630 &oes
->tx_errors
, &es
->tx_errors
);
632 i40e_stat_update48(hw
, I40E_GLV_GORCH(stat_idx
),
633 I40E_GLV_GORCL(stat_idx
),
634 vsi
->stat_offsets_loaded
,
635 &oes
->rx_bytes
, &es
->rx_bytes
);
636 i40e_stat_update48(hw
, I40E_GLV_UPRCH(stat_idx
),
637 I40E_GLV_UPRCL(stat_idx
),
638 vsi
->stat_offsets_loaded
,
639 &oes
->rx_unicast
, &es
->rx_unicast
);
640 i40e_stat_update48(hw
, I40E_GLV_MPRCH(stat_idx
),
641 I40E_GLV_MPRCL(stat_idx
),
642 vsi
->stat_offsets_loaded
,
643 &oes
->rx_multicast
, &es
->rx_multicast
);
644 i40e_stat_update48(hw
, I40E_GLV_BPRCH(stat_idx
),
645 I40E_GLV_BPRCL(stat_idx
),
646 vsi
->stat_offsets_loaded
,
647 &oes
->rx_broadcast
, &es
->rx_broadcast
);
649 i40e_stat_update48(hw
, I40E_GLV_GOTCH(stat_idx
),
650 I40E_GLV_GOTCL(stat_idx
),
651 vsi
->stat_offsets_loaded
,
652 &oes
->tx_bytes
, &es
->tx_bytes
);
653 i40e_stat_update48(hw
, I40E_GLV_UPTCH(stat_idx
),
654 I40E_GLV_UPTCL(stat_idx
),
655 vsi
->stat_offsets_loaded
,
656 &oes
->tx_unicast
, &es
->tx_unicast
);
657 i40e_stat_update48(hw
, I40E_GLV_MPTCH(stat_idx
),
658 I40E_GLV_MPTCL(stat_idx
),
659 vsi
->stat_offsets_loaded
,
660 &oes
->tx_multicast
, &es
->tx_multicast
);
661 i40e_stat_update48(hw
, I40E_GLV_BPTCH(stat_idx
),
662 I40E_GLV_BPTCL(stat_idx
),
663 vsi
->stat_offsets_loaded
,
664 &oes
->tx_broadcast
, &es
->tx_broadcast
);
665 vsi
->stat_offsets_loaded
= true;
669 * i40e_update_veb_stats - Update Switch component statistics
670 * @veb: the VEB being updated
672 static void i40e_update_veb_stats(struct i40e_veb
*veb
)
674 struct i40e_pf
*pf
= veb
->pf
;
675 struct i40e_hw
*hw
= &pf
->hw
;
676 struct i40e_eth_stats
*oes
;
677 struct i40e_eth_stats
*es
; /* device's eth stats */
678 struct i40e_veb_tc_stats
*veb_oes
;
679 struct i40e_veb_tc_stats
*veb_es
;
682 idx
= veb
->stats_idx
;
684 oes
= &veb
->stats_offsets
;
685 veb_es
= &veb
->tc_stats
;
686 veb_oes
= &veb
->tc_stats_offsets
;
688 /* Gather up the stats that the hw collects */
689 i40e_stat_update32(hw
, I40E_GLSW_TDPC(idx
),
690 veb
->stat_offsets_loaded
,
691 &oes
->tx_discards
, &es
->tx_discards
);
692 if (hw
->revision_id
> 0)
693 i40e_stat_update32(hw
, I40E_GLSW_RUPP(idx
),
694 veb
->stat_offsets_loaded
,
695 &oes
->rx_unknown_protocol
,
696 &es
->rx_unknown_protocol
);
697 i40e_stat_update48(hw
, I40E_GLSW_GORCH(idx
), I40E_GLSW_GORCL(idx
),
698 veb
->stat_offsets_loaded
,
699 &oes
->rx_bytes
, &es
->rx_bytes
);
700 i40e_stat_update48(hw
, I40E_GLSW_UPRCH(idx
), I40E_GLSW_UPRCL(idx
),
701 veb
->stat_offsets_loaded
,
702 &oes
->rx_unicast
, &es
->rx_unicast
);
703 i40e_stat_update48(hw
, I40E_GLSW_MPRCH(idx
), I40E_GLSW_MPRCL(idx
),
704 veb
->stat_offsets_loaded
,
705 &oes
->rx_multicast
, &es
->rx_multicast
);
706 i40e_stat_update48(hw
, I40E_GLSW_BPRCH(idx
), I40E_GLSW_BPRCL(idx
),
707 veb
->stat_offsets_loaded
,
708 &oes
->rx_broadcast
, &es
->rx_broadcast
);
710 i40e_stat_update48(hw
, I40E_GLSW_GOTCH(idx
), I40E_GLSW_GOTCL(idx
),
711 veb
->stat_offsets_loaded
,
712 &oes
->tx_bytes
, &es
->tx_bytes
);
713 i40e_stat_update48(hw
, I40E_GLSW_UPTCH(idx
), I40E_GLSW_UPTCL(idx
),
714 veb
->stat_offsets_loaded
,
715 &oes
->tx_unicast
, &es
->tx_unicast
);
716 i40e_stat_update48(hw
, I40E_GLSW_MPTCH(idx
), I40E_GLSW_MPTCL(idx
),
717 veb
->stat_offsets_loaded
,
718 &oes
->tx_multicast
, &es
->tx_multicast
);
719 i40e_stat_update48(hw
, I40E_GLSW_BPTCH(idx
), I40E_GLSW_BPTCL(idx
),
720 veb
->stat_offsets_loaded
,
721 &oes
->tx_broadcast
, &es
->tx_broadcast
);
722 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
723 i40e_stat_update48(hw
, I40E_GLVEBTC_RPCH(i
, idx
),
724 I40E_GLVEBTC_RPCL(i
, idx
),
725 veb
->stat_offsets_loaded
,
726 &veb_oes
->tc_rx_packets
[i
],
727 &veb_es
->tc_rx_packets
[i
]);
728 i40e_stat_update48(hw
, I40E_GLVEBTC_RBCH(i
, idx
),
729 I40E_GLVEBTC_RBCL(i
, idx
),
730 veb
->stat_offsets_loaded
,
731 &veb_oes
->tc_rx_bytes
[i
],
732 &veb_es
->tc_rx_bytes
[i
]);
733 i40e_stat_update48(hw
, I40E_GLVEBTC_TPCH(i
, idx
),
734 I40E_GLVEBTC_TPCL(i
, idx
),
735 veb
->stat_offsets_loaded
,
736 &veb_oes
->tc_tx_packets
[i
],
737 &veb_es
->tc_tx_packets
[i
]);
738 i40e_stat_update48(hw
, I40E_GLVEBTC_TBCH(i
, idx
),
739 I40E_GLVEBTC_TBCL(i
, idx
),
740 veb
->stat_offsets_loaded
,
741 &veb_oes
->tc_tx_bytes
[i
],
742 &veb_es
->tc_tx_bytes
[i
]);
744 veb
->stat_offsets_loaded
= true;
748 * i40e_update_vsi_stats - Update the vsi statistics counters.
749 * @vsi: the VSI to be updated
751 * There are a few instances where we store the same stat in a
752 * couple of different structs. This is partly because we have
753 * the netdev stats that need to be filled out, which is slightly
754 * different from the "eth_stats" defined by the chip and used in
755 * VF communications. We sort it out here.
757 static void i40e_update_vsi_stats(struct i40e_vsi
*vsi
)
759 struct i40e_pf
*pf
= vsi
->back
;
760 struct rtnl_link_stats64
*ons
;
761 struct rtnl_link_stats64
*ns
; /* netdev stats */
762 struct i40e_eth_stats
*oes
;
763 struct i40e_eth_stats
*es
; /* device's eth stats */
764 u32 tx_restart
, tx_busy
;
775 if (test_bit(__I40E_VSI_DOWN
, vsi
->state
) ||
776 test_bit(__I40E_CONFIG_BUSY
, pf
->state
))
779 ns
= i40e_get_vsi_stats_struct(vsi
);
780 ons
= &vsi
->net_stats_offsets
;
781 es
= &vsi
->eth_stats
;
782 oes
= &vsi
->eth_stats_offsets
;
784 /* Gather up the netdev and vsi stats that the driver collects
785 * on the fly during packet processing
789 tx_restart
= tx_busy
= tx_linearize
= tx_force_wb
= 0;
793 for (q
= 0; q
< vsi
->num_queue_pairs
; q
++) {
795 p
= READ_ONCE(vsi
->tx_rings
[q
]);
798 start
= u64_stats_fetch_begin_irq(&p
->syncp
);
799 packets
= p
->stats
.packets
;
800 bytes
= p
->stats
.bytes
;
801 } while (u64_stats_fetch_retry_irq(&p
->syncp
, start
));
804 tx_restart
+= p
->tx_stats
.restart_queue
;
805 tx_busy
+= p
->tx_stats
.tx_busy
;
806 tx_linearize
+= p
->tx_stats
.tx_linearize
;
807 tx_force_wb
+= p
->tx_stats
.tx_force_wb
;
809 /* Rx queue is part of the same block as Tx queue */
812 start
= u64_stats_fetch_begin_irq(&p
->syncp
);
813 packets
= p
->stats
.packets
;
814 bytes
= p
->stats
.bytes
;
815 } while (u64_stats_fetch_retry_irq(&p
->syncp
, start
));
818 rx_buf
+= p
->rx_stats
.alloc_buff_failed
;
819 rx_page
+= p
->rx_stats
.alloc_page_failed
;
822 vsi
->tx_restart
= tx_restart
;
823 vsi
->tx_busy
= tx_busy
;
824 vsi
->tx_linearize
= tx_linearize
;
825 vsi
->tx_force_wb
= tx_force_wb
;
826 vsi
->rx_page_failed
= rx_page
;
827 vsi
->rx_buf_failed
= rx_buf
;
829 ns
->rx_packets
= rx_p
;
831 ns
->tx_packets
= tx_p
;
834 /* update netdev stats from eth stats */
835 i40e_update_eth_stats(vsi
);
836 ons
->tx_errors
= oes
->tx_errors
;
837 ns
->tx_errors
= es
->tx_errors
;
838 ons
->multicast
= oes
->rx_multicast
;
839 ns
->multicast
= es
->rx_multicast
;
840 ons
->rx_dropped
= oes
->rx_discards
;
841 ns
->rx_dropped
= es
->rx_discards
;
842 ons
->tx_dropped
= oes
->tx_discards
;
843 ns
->tx_dropped
= es
->tx_discards
;
845 /* pull in a couple PF stats if this is the main vsi */
846 if (vsi
== pf
->vsi
[pf
->lan_vsi
]) {
847 ns
->rx_crc_errors
= pf
->stats
.crc_errors
;
848 ns
->rx_errors
= pf
->stats
.crc_errors
+ pf
->stats
.illegal_bytes
;
849 ns
->rx_length_errors
= pf
->stats
.rx_length_errors
;
854 * i40e_update_pf_stats - Update the PF statistics counters.
855 * @pf: the PF to be updated
857 static void i40e_update_pf_stats(struct i40e_pf
*pf
)
859 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
860 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
861 struct i40e_hw
*hw
= &pf
->hw
;
865 i40e_stat_update48(hw
, I40E_GLPRT_GORCH(hw
->port
),
866 I40E_GLPRT_GORCL(hw
->port
),
867 pf
->stat_offsets_loaded
,
868 &osd
->eth
.rx_bytes
, &nsd
->eth
.rx_bytes
);
869 i40e_stat_update48(hw
, I40E_GLPRT_GOTCH(hw
->port
),
870 I40E_GLPRT_GOTCL(hw
->port
),
871 pf
->stat_offsets_loaded
,
872 &osd
->eth
.tx_bytes
, &nsd
->eth
.tx_bytes
);
873 i40e_stat_update32(hw
, I40E_GLPRT_RDPC(hw
->port
),
874 pf
->stat_offsets_loaded
,
875 &osd
->eth
.rx_discards
,
876 &nsd
->eth
.rx_discards
);
877 i40e_stat_update48(hw
, I40E_GLPRT_UPRCH(hw
->port
),
878 I40E_GLPRT_UPRCL(hw
->port
),
879 pf
->stat_offsets_loaded
,
880 &osd
->eth
.rx_unicast
,
881 &nsd
->eth
.rx_unicast
);
882 i40e_stat_update48(hw
, I40E_GLPRT_MPRCH(hw
->port
),
883 I40E_GLPRT_MPRCL(hw
->port
),
884 pf
->stat_offsets_loaded
,
885 &osd
->eth
.rx_multicast
,
886 &nsd
->eth
.rx_multicast
);
887 i40e_stat_update48(hw
, I40E_GLPRT_BPRCH(hw
->port
),
888 I40E_GLPRT_BPRCL(hw
->port
),
889 pf
->stat_offsets_loaded
,
890 &osd
->eth
.rx_broadcast
,
891 &nsd
->eth
.rx_broadcast
);
892 i40e_stat_update48(hw
, I40E_GLPRT_UPTCH(hw
->port
),
893 I40E_GLPRT_UPTCL(hw
->port
),
894 pf
->stat_offsets_loaded
,
895 &osd
->eth
.tx_unicast
,
896 &nsd
->eth
.tx_unicast
);
897 i40e_stat_update48(hw
, I40E_GLPRT_MPTCH(hw
->port
),
898 I40E_GLPRT_MPTCL(hw
->port
),
899 pf
->stat_offsets_loaded
,
900 &osd
->eth
.tx_multicast
,
901 &nsd
->eth
.tx_multicast
);
902 i40e_stat_update48(hw
, I40E_GLPRT_BPTCH(hw
->port
),
903 I40E_GLPRT_BPTCL(hw
->port
),
904 pf
->stat_offsets_loaded
,
905 &osd
->eth
.tx_broadcast
,
906 &nsd
->eth
.tx_broadcast
);
908 i40e_stat_update32(hw
, I40E_GLPRT_TDOLD(hw
->port
),
909 pf
->stat_offsets_loaded
,
910 &osd
->tx_dropped_link_down
,
911 &nsd
->tx_dropped_link_down
);
913 i40e_stat_update32(hw
, I40E_GLPRT_CRCERRS(hw
->port
),
914 pf
->stat_offsets_loaded
,
915 &osd
->crc_errors
, &nsd
->crc_errors
);
917 i40e_stat_update32(hw
, I40E_GLPRT_ILLERRC(hw
->port
),
918 pf
->stat_offsets_loaded
,
919 &osd
->illegal_bytes
, &nsd
->illegal_bytes
);
921 i40e_stat_update32(hw
, I40E_GLPRT_MLFC(hw
->port
),
922 pf
->stat_offsets_loaded
,
923 &osd
->mac_local_faults
,
924 &nsd
->mac_local_faults
);
925 i40e_stat_update32(hw
, I40E_GLPRT_MRFC(hw
->port
),
926 pf
->stat_offsets_loaded
,
927 &osd
->mac_remote_faults
,
928 &nsd
->mac_remote_faults
);
930 i40e_stat_update32(hw
, I40E_GLPRT_RLEC(hw
->port
),
931 pf
->stat_offsets_loaded
,
932 &osd
->rx_length_errors
,
933 &nsd
->rx_length_errors
);
935 i40e_stat_update32(hw
, I40E_GLPRT_LXONRXC(hw
->port
),
936 pf
->stat_offsets_loaded
,
937 &osd
->link_xon_rx
, &nsd
->link_xon_rx
);
938 i40e_stat_update32(hw
, I40E_GLPRT_LXONTXC(hw
->port
),
939 pf
->stat_offsets_loaded
,
940 &osd
->link_xon_tx
, &nsd
->link_xon_tx
);
941 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFRXC(hw
->port
),
942 pf
->stat_offsets_loaded
,
943 &osd
->link_xoff_rx
, &nsd
->link_xoff_rx
);
944 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFTXC(hw
->port
),
945 pf
->stat_offsets_loaded
,
946 &osd
->link_xoff_tx
, &nsd
->link_xoff_tx
);
948 for (i
= 0; i
< 8; i
++) {
949 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFRXC(hw
->port
, i
),
950 pf
->stat_offsets_loaded
,
951 &osd
->priority_xoff_rx
[i
],
952 &nsd
->priority_xoff_rx
[i
]);
953 i40e_stat_update32(hw
, I40E_GLPRT_PXONRXC(hw
->port
, i
),
954 pf
->stat_offsets_loaded
,
955 &osd
->priority_xon_rx
[i
],
956 &nsd
->priority_xon_rx
[i
]);
957 i40e_stat_update32(hw
, I40E_GLPRT_PXONTXC(hw
->port
, i
),
958 pf
->stat_offsets_loaded
,
959 &osd
->priority_xon_tx
[i
],
960 &nsd
->priority_xon_tx
[i
]);
961 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFTXC(hw
->port
, i
),
962 pf
->stat_offsets_loaded
,
963 &osd
->priority_xoff_tx
[i
],
964 &nsd
->priority_xoff_tx
[i
]);
965 i40e_stat_update32(hw
,
966 I40E_GLPRT_RXON2OFFCNT(hw
->port
, i
),
967 pf
->stat_offsets_loaded
,
968 &osd
->priority_xon_2_xoff
[i
],
969 &nsd
->priority_xon_2_xoff
[i
]);
972 i40e_stat_update48(hw
, I40E_GLPRT_PRC64H(hw
->port
),
973 I40E_GLPRT_PRC64L(hw
->port
),
974 pf
->stat_offsets_loaded
,
975 &osd
->rx_size_64
, &nsd
->rx_size_64
);
976 i40e_stat_update48(hw
, I40E_GLPRT_PRC127H(hw
->port
),
977 I40E_GLPRT_PRC127L(hw
->port
),
978 pf
->stat_offsets_loaded
,
979 &osd
->rx_size_127
, &nsd
->rx_size_127
);
980 i40e_stat_update48(hw
, I40E_GLPRT_PRC255H(hw
->port
),
981 I40E_GLPRT_PRC255L(hw
->port
),
982 pf
->stat_offsets_loaded
,
983 &osd
->rx_size_255
, &nsd
->rx_size_255
);
984 i40e_stat_update48(hw
, I40E_GLPRT_PRC511H(hw
->port
),
985 I40E_GLPRT_PRC511L(hw
->port
),
986 pf
->stat_offsets_loaded
,
987 &osd
->rx_size_511
, &nsd
->rx_size_511
);
988 i40e_stat_update48(hw
, I40E_GLPRT_PRC1023H(hw
->port
),
989 I40E_GLPRT_PRC1023L(hw
->port
),
990 pf
->stat_offsets_loaded
,
991 &osd
->rx_size_1023
, &nsd
->rx_size_1023
);
992 i40e_stat_update48(hw
, I40E_GLPRT_PRC1522H(hw
->port
),
993 I40E_GLPRT_PRC1522L(hw
->port
),
994 pf
->stat_offsets_loaded
,
995 &osd
->rx_size_1522
, &nsd
->rx_size_1522
);
996 i40e_stat_update48(hw
, I40E_GLPRT_PRC9522H(hw
->port
),
997 I40E_GLPRT_PRC9522L(hw
->port
),
998 pf
->stat_offsets_loaded
,
999 &osd
->rx_size_big
, &nsd
->rx_size_big
);
1001 i40e_stat_update48(hw
, I40E_GLPRT_PTC64H(hw
->port
),
1002 I40E_GLPRT_PTC64L(hw
->port
),
1003 pf
->stat_offsets_loaded
,
1004 &osd
->tx_size_64
, &nsd
->tx_size_64
);
1005 i40e_stat_update48(hw
, I40E_GLPRT_PTC127H(hw
->port
),
1006 I40E_GLPRT_PTC127L(hw
->port
),
1007 pf
->stat_offsets_loaded
,
1008 &osd
->tx_size_127
, &nsd
->tx_size_127
);
1009 i40e_stat_update48(hw
, I40E_GLPRT_PTC255H(hw
->port
),
1010 I40E_GLPRT_PTC255L(hw
->port
),
1011 pf
->stat_offsets_loaded
,
1012 &osd
->tx_size_255
, &nsd
->tx_size_255
);
1013 i40e_stat_update48(hw
, I40E_GLPRT_PTC511H(hw
->port
),
1014 I40E_GLPRT_PTC511L(hw
->port
),
1015 pf
->stat_offsets_loaded
,
1016 &osd
->tx_size_511
, &nsd
->tx_size_511
);
1017 i40e_stat_update48(hw
, I40E_GLPRT_PTC1023H(hw
->port
),
1018 I40E_GLPRT_PTC1023L(hw
->port
),
1019 pf
->stat_offsets_loaded
,
1020 &osd
->tx_size_1023
, &nsd
->tx_size_1023
);
1021 i40e_stat_update48(hw
, I40E_GLPRT_PTC1522H(hw
->port
),
1022 I40E_GLPRT_PTC1522L(hw
->port
),
1023 pf
->stat_offsets_loaded
,
1024 &osd
->tx_size_1522
, &nsd
->tx_size_1522
);
1025 i40e_stat_update48(hw
, I40E_GLPRT_PTC9522H(hw
->port
),
1026 I40E_GLPRT_PTC9522L(hw
->port
),
1027 pf
->stat_offsets_loaded
,
1028 &osd
->tx_size_big
, &nsd
->tx_size_big
);
1030 i40e_stat_update32(hw
, I40E_GLPRT_RUC(hw
->port
),
1031 pf
->stat_offsets_loaded
,
1032 &osd
->rx_undersize
, &nsd
->rx_undersize
);
1033 i40e_stat_update32(hw
, I40E_GLPRT_RFC(hw
->port
),
1034 pf
->stat_offsets_loaded
,
1035 &osd
->rx_fragments
, &nsd
->rx_fragments
);
1036 i40e_stat_update32(hw
, I40E_GLPRT_ROC(hw
->port
),
1037 pf
->stat_offsets_loaded
,
1038 &osd
->rx_oversize
, &nsd
->rx_oversize
);
1039 i40e_stat_update32(hw
, I40E_GLPRT_RJC(hw
->port
),
1040 pf
->stat_offsets_loaded
,
1041 &osd
->rx_jabber
, &nsd
->rx_jabber
);
1044 i40e_stat_update_and_clear32(hw
,
1045 I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(hw
->pf_id
)),
1046 &nsd
->fd_atr_match
);
1047 i40e_stat_update_and_clear32(hw
,
1048 I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(hw
->pf_id
)),
1050 i40e_stat_update_and_clear32(hw
,
1051 I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(hw
->pf_id
)),
1052 &nsd
->fd_atr_tunnel_match
);
1054 val
= rd32(hw
, I40E_PRTPM_EEE_STAT
);
1055 nsd
->tx_lpi_status
=
1056 (val
& I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK
) >>
1057 I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT
;
1058 nsd
->rx_lpi_status
=
1059 (val
& I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK
) >>
1060 I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT
;
1061 i40e_stat_update32(hw
, I40E_PRTPM_TLPIC
,
1062 pf
->stat_offsets_loaded
,
1063 &osd
->tx_lpi_count
, &nsd
->tx_lpi_count
);
1064 i40e_stat_update32(hw
, I40E_PRTPM_RLPIC
,
1065 pf
->stat_offsets_loaded
,
1066 &osd
->rx_lpi_count
, &nsd
->rx_lpi_count
);
1068 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
&&
1069 !test_bit(__I40E_FD_SB_AUTO_DISABLED
, pf
->state
))
1070 nsd
->fd_sb_status
= true;
1072 nsd
->fd_sb_status
= false;
1074 if (pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
&&
1075 !test_bit(__I40E_FD_ATR_AUTO_DISABLED
, pf
->state
))
1076 nsd
->fd_atr_status
= true;
1078 nsd
->fd_atr_status
= false;
1080 pf
->stat_offsets_loaded
= true;
1084 * i40e_update_stats - Update the various statistics counters.
1085 * @vsi: the VSI to be updated
1087 * Update the various stats for this VSI and its related entities.
1089 void i40e_update_stats(struct i40e_vsi
*vsi
)
1091 struct i40e_pf
*pf
= vsi
->back
;
1093 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
1094 i40e_update_pf_stats(pf
);
1096 i40e_update_vsi_stats(vsi
);
1100 * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
1101 * @vsi: the VSI to be searched
1102 * @macaddr: the MAC address
1105 * Returns ptr to the filter object or NULL
1107 static struct i40e_mac_filter
*i40e_find_filter(struct i40e_vsi
*vsi
,
1108 const u8
*macaddr
, s16 vlan
)
1110 struct i40e_mac_filter
*f
;
1113 if (!vsi
|| !macaddr
)
1116 key
= i40e_addr_to_hkey(macaddr
);
1117 hash_for_each_possible(vsi
->mac_filter_hash
, f
, hlist
, key
) {
1118 if ((ether_addr_equal(macaddr
, f
->macaddr
)) &&
1126 * i40e_find_mac - Find a mac addr in the macvlan filters list
1127 * @vsi: the VSI to be searched
1128 * @macaddr: the MAC address we are searching for
1130 * Returns the first filter with the provided MAC address or NULL if
1131 * MAC address was not found
1133 struct i40e_mac_filter
*i40e_find_mac(struct i40e_vsi
*vsi
, const u8
*macaddr
)
1135 struct i40e_mac_filter
*f
;
1138 if (!vsi
|| !macaddr
)
1141 key
= i40e_addr_to_hkey(macaddr
);
1142 hash_for_each_possible(vsi
->mac_filter_hash
, f
, hlist
, key
) {
1143 if ((ether_addr_equal(macaddr
, f
->macaddr
)))
1150 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1151 * @vsi: the VSI to be searched
1153 * Returns true if VSI is in vlan mode or false otherwise
1155 bool i40e_is_vsi_in_vlan(struct i40e_vsi
*vsi
)
1157 /* If we have a PVID, always operate in VLAN mode */
1161 /* We need to operate in VLAN mode whenever we have any filters with
1162 * a VLAN other than I40E_VLAN_ALL. We could check the table each
1163 * time, incurring search cost repeatedly. However, we can notice two
1166 * 1) the only place where we can gain a VLAN filter is in
1169 * 2) the only place where filters are actually removed is in
1170 * i40e_sync_filters_subtask.
1172 * Thus, we can simply use a boolean value, has_vlan_filters which we
1173 * will set to true when we add a VLAN filter in i40e_add_filter. Then
1174 * we have to perform the full search after deleting filters in
1175 * i40e_sync_filters_subtask, but we already have to search
1176 * filters here and can perform the check at the same time. This
1177 * results in avoiding embedding a loop for VLAN mode inside another
1178 * loop over all the filters, and should maintain correctness as noted
1181 return vsi
->has_vlan_filter
;
1185 * i40e_correct_mac_vlan_filters - Correct non-VLAN filters if necessary
1186 * @vsi: the VSI to configure
1187 * @tmp_add_list: list of filters ready to be added
1188 * @tmp_del_list: list of filters ready to be deleted
1189 * @vlan_filters: the number of active VLAN filters
1191 * Update VLAN=0 and VLAN=-1 (I40E_VLAN_ANY) filters properly so that they
1192 * behave as expected. If we have any active VLAN filters remaining or about
1193 * to be added then we need to update non-VLAN filters to be marked as VLAN=0
1194 * so that they only match against untagged traffic. If we no longer have any
1195 * active VLAN filters, we need to make all non-VLAN filters marked as VLAN=-1
1196 * so that they match against both tagged and untagged traffic. In this way,
1197 * we ensure that we correctly receive the desired traffic. This ensures that
1198 * when we have an active VLAN we will receive only untagged traffic and
1199 * traffic matching active VLANs. If we have no active VLANs then we will
1200 * operate in non-VLAN mode and receive all traffic, tagged or untagged.
1202 * Finally, in a similar fashion, this function also corrects filters when
1203 * there is an active PVID assigned to this VSI.
1205 * In case of memory allocation failure return -ENOMEM. Otherwise, return 0.
1207 * This function is only expected to be called from within
1208 * i40e_sync_vsi_filters.
1210 * NOTE: This function expects to be called while under the
1211 * mac_filter_hash_lock
1213 static int i40e_correct_mac_vlan_filters(struct i40e_vsi
*vsi
,
1214 struct hlist_head
*tmp_add_list
,
1215 struct hlist_head
*tmp_del_list
,
1218 s16 pvid
= le16_to_cpu(vsi
->info
.pvid
);
1219 struct i40e_mac_filter
*f
, *add_head
;
1220 struct i40e_new_mac_filter
*new;
1221 struct hlist_node
*h
;
1224 /* To determine if a particular filter needs to be replaced we
1225 * have the three following conditions:
1227 * a) if we have a PVID assigned, then all filters which are
1228 * not marked as VLAN=PVID must be replaced with filters that
1230 * b) otherwise, if we have any active VLANS, all filters
1231 * which are marked as VLAN=-1 must be replaced with
1232 * filters marked as VLAN=0
1233 * c) finally, if we do not have any active VLANS, all filters
1234 * which are marked as VLAN=0 must be replaced with filters
1238 /* Update the filters about to be added in place */
1239 hlist_for_each_entry(new, tmp_add_list
, hlist
) {
1240 if (pvid
&& new->f
->vlan
!= pvid
)
1241 new->f
->vlan
= pvid
;
1242 else if (vlan_filters
&& new->f
->vlan
== I40E_VLAN_ANY
)
1244 else if (!vlan_filters
&& new->f
->vlan
== 0)
1245 new->f
->vlan
= I40E_VLAN_ANY
;
1248 /* Update the remaining active filters */
1249 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
1250 /* Combine the checks for whether a filter needs to be changed
1251 * and then determine the new VLAN inside the if block, in
1252 * order to avoid duplicating code for adding the new filter
1253 * then deleting the old filter.
1255 if ((pvid
&& f
->vlan
!= pvid
) ||
1256 (vlan_filters
&& f
->vlan
== I40E_VLAN_ANY
) ||
1257 (!vlan_filters
&& f
->vlan
== 0)) {
1258 /* Determine the new vlan we will be adding */
1261 else if (vlan_filters
)
1264 new_vlan
= I40E_VLAN_ANY
;
1266 /* Create the new filter */
1267 add_head
= i40e_add_filter(vsi
, f
->macaddr
, new_vlan
);
1271 /* Create a temporary i40e_new_mac_filter */
1272 new = kzalloc(sizeof(*new), GFP_ATOMIC
);
1277 new->state
= add_head
->state
;
1279 /* Add the new filter to the tmp list */
1280 hlist_add_head(&new->hlist
, tmp_add_list
);
1282 /* Put the original filter into the delete list */
1283 f
->state
= I40E_FILTER_REMOVE
;
1284 hash_del(&f
->hlist
);
1285 hlist_add_head(&f
->hlist
, tmp_del_list
);
1289 vsi
->has_vlan_filter
= !!vlan_filters
;
1295 * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
1296 * @vsi: the PF Main VSI - inappropriate for any other VSI
1297 * @macaddr: the MAC address
1299 * Remove whatever filter the firmware set up so the driver can manage
1300 * its own filtering intelligently.
1302 static void i40e_rm_default_mac_filter(struct i40e_vsi
*vsi
, u8
*macaddr
)
1304 struct i40e_aqc_remove_macvlan_element_data element
;
1305 struct i40e_pf
*pf
= vsi
->back
;
1307 /* Only appropriate for the PF main VSI */
1308 if (vsi
->type
!= I40E_VSI_MAIN
)
1311 memset(&element
, 0, sizeof(element
));
1312 ether_addr_copy(element
.mac_addr
, macaddr
);
1313 element
.vlan_tag
= 0;
1314 /* Ignore error returns, some firmware does it this way... */
1315 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
1316 i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1318 memset(&element
, 0, sizeof(element
));
1319 ether_addr_copy(element
.mac_addr
, macaddr
);
1320 element
.vlan_tag
= 0;
1321 /* ...and some firmware does it this way. */
1322 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
|
1323 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
1324 i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1328 * i40e_add_filter - Add a mac/vlan filter to the VSI
1329 * @vsi: the VSI to be searched
1330 * @macaddr: the MAC address
1333 * Returns ptr to the filter object or NULL when no memory available.
1335 * NOTE: This function is expected to be called with mac_filter_hash_lock
1338 struct i40e_mac_filter
*i40e_add_filter(struct i40e_vsi
*vsi
,
1339 const u8
*macaddr
, s16 vlan
)
1341 struct i40e_mac_filter
*f
;
1344 if (!vsi
|| !macaddr
)
1347 f
= i40e_find_filter(vsi
, macaddr
, vlan
);
1349 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
1353 /* Update the boolean indicating if we need to function in
1357 vsi
->has_vlan_filter
= true;
1359 ether_addr_copy(f
->macaddr
, macaddr
);
1361 f
->state
= I40E_FILTER_NEW
;
1362 INIT_HLIST_NODE(&f
->hlist
);
1364 key
= i40e_addr_to_hkey(macaddr
);
1365 hash_add(vsi
->mac_filter_hash
, &f
->hlist
, key
);
1367 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1368 set_bit(__I40E_MACVLAN_SYNC_PENDING
, vsi
->back
->state
);
1371 /* If we're asked to add a filter that has been marked for removal, it
1372 * is safe to simply restore it to active state. __i40e_del_filter
1373 * will have simply deleted any filters which were previously marked
1374 * NEW or FAILED, so if it is currently marked REMOVE it must have
1375 * previously been ACTIVE. Since we haven't yet run the sync filters
1376 * task, just restore this filter to the ACTIVE state so that the
1377 * sync task leaves it in place
1379 if (f
->state
== I40E_FILTER_REMOVE
)
1380 f
->state
= I40E_FILTER_ACTIVE
;
1386 * __i40e_del_filter - Remove a specific filter from the VSI
1387 * @vsi: VSI to remove from
1388 * @f: the filter to remove from the list
1390 * This function should be called instead of i40e_del_filter only if you know
1391 * the exact filter you will remove already, such as via i40e_find_filter or
1394 * NOTE: This function is expected to be called with mac_filter_hash_lock
1396 * ANOTHER NOTE: This function MUST be called from within the context of
1397 * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
1398 * instead of list_for_each_entry().
1400 void __i40e_del_filter(struct i40e_vsi
*vsi
, struct i40e_mac_filter
*f
)
1405 /* If the filter was never added to firmware then we can just delete it
1406 * directly and we don't want to set the status to remove or else an
1407 * admin queue command will unnecessarily fire.
1409 if ((f
->state
== I40E_FILTER_FAILED
) ||
1410 (f
->state
== I40E_FILTER_NEW
)) {
1411 hash_del(&f
->hlist
);
1414 f
->state
= I40E_FILTER_REMOVE
;
1417 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1418 set_bit(__I40E_MACVLAN_SYNC_PENDING
, vsi
->back
->state
);
1422 * i40e_del_filter - Remove a MAC/VLAN filter from the VSI
1423 * @vsi: the VSI to be searched
1424 * @macaddr: the MAC address
1427 * NOTE: This function is expected to be called with mac_filter_hash_lock
1429 * ANOTHER NOTE: This function MUST be called from within the context of
1430 * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
1431 * instead of list_for_each_entry().
1433 void i40e_del_filter(struct i40e_vsi
*vsi
, const u8
*macaddr
, s16 vlan
)
1435 struct i40e_mac_filter
*f
;
1437 if (!vsi
|| !macaddr
)
1440 f
= i40e_find_filter(vsi
, macaddr
, vlan
);
1441 __i40e_del_filter(vsi
, f
);
1445 * i40e_add_mac_filter - Add a MAC filter for all active VLANs
1446 * @vsi: the VSI to be searched
1447 * @macaddr: the mac address to be filtered
1449 * If we're not in VLAN mode, just add the filter to I40E_VLAN_ANY. Otherwise,
1450 * go through all the macvlan filters and add a macvlan filter for each
1451 * unique vlan that already exists. If a PVID has been assigned, instead only
1452 * add the macaddr to that VLAN.
1454 * Returns last filter added on success, else NULL
1456 struct i40e_mac_filter
*i40e_add_mac_filter(struct i40e_vsi
*vsi
,
1459 struct i40e_mac_filter
*f
, *add
= NULL
;
1460 struct hlist_node
*h
;
1464 return i40e_add_filter(vsi
, macaddr
,
1465 le16_to_cpu(vsi
->info
.pvid
));
1467 if (!i40e_is_vsi_in_vlan(vsi
))
1468 return i40e_add_filter(vsi
, macaddr
, I40E_VLAN_ANY
);
1470 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
1471 if (f
->state
== I40E_FILTER_REMOVE
)
1473 add
= i40e_add_filter(vsi
, macaddr
, f
->vlan
);
1482 * i40e_del_mac_filter - Remove a MAC filter from all VLANs
1483 * @vsi: the VSI to be searched
1484 * @macaddr: the mac address to be removed
1486 * Removes a given MAC address from a VSI regardless of what VLAN it has been
1489 * Returns 0 for success, or error
1491 int i40e_del_mac_filter(struct i40e_vsi
*vsi
, const u8
*macaddr
)
1493 struct i40e_mac_filter
*f
;
1494 struct hlist_node
*h
;
1498 WARN(!spin_is_locked(&vsi
->mac_filter_hash_lock
),
1499 "Missing mac_filter_hash_lock\n");
1500 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
1501 if (ether_addr_equal(macaddr
, f
->macaddr
)) {
1502 __i40e_del_filter(vsi
, f
);
1514 * i40e_set_mac - NDO callback to set mac address
1515 * @netdev: network interface device structure
1516 * @p: pointer to an address structure
1518 * Returns 0 on success, negative on failure
1520 static int i40e_set_mac(struct net_device
*netdev
, void *p
)
1522 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1523 struct i40e_vsi
*vsi
= np
->vsi
;
1524 struct i40e_pf
*pf
= vsi
->back
;
1525 struct i40e_hw
*hw
= &pf
->hw
;
1526 struct sockaddr
*addr
= p
;
1528 if (!is_valid_ether_addr(addr
->sa_data
))
1529 return -EADDRNOTAVAIL
;
1531 if (ether_addr_equal(netdev
->dev_addr
, addr
->sa_data
)) {
1532 netdev_info(netdev
, "already using mac address %pM\n",
1537 if (test_bit(__I40E_VSI_DOWN
, vsi
->back
->state
) ||
1538 test_bit(__I40E_RESET_RECOVERY_PENDING
, vsi
->back
->state
))
1539 return -EADDRNOTAVAIL
;
1541 if (ether_addr_equal(hw
->mac
.addr
, addr
->sa_data
))
1542 netdev_info(netdev
, "returning to hw mac address %pM\n",
1545 netdev_info(netdev
, "set new mac address %pM\n", addr
->sa_data
);
1547 /* Copy the address first, so that we avoid a possible race with
1549 * - Remove old address from MAC filter
1550 * - Copy new address
1551 * - Add new address to MAC filter
1553 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
1554 i40e_del_mac_filter(vsi
, netdev
->dev_addr
);
1555 ether_addr_copy(netdev
->dev_addr
, addr
->sa_data
);
1556 i40e_add_mac_filter(vsi
, netdev
->dev_addr
);
1557 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
1559 if (vsi
->type
== I40E_VSI_MAIN
) {
1562 ret
= i40e_aq_mac_address_write(&vsi
->back
->hw
,
1563 I40E_AQC_WRITE_TYPE_LAA_WOL
,
1564 addr
->sa_data
, NULL
);
1566 netdev_info(netdev
, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n",
1567 i40e_stat_str(hw
, ret
),
1568 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
1571 /* schedule our worker thread which will take care of
1572 * applying the new filter changes
1574 i40e_service_event_schedule(vsi
->back
);
1579 * i40e_config_rss_aq - Prepare for RSS using AQ commands
1580 * @vsi: vsi structure
1581 * @seed: RSS hash seed
1583 static int i40e_config_rss_aq(struct i40e_vsi
*vsi
, const u8
*seed
,
1584 u8
*lut
, u16 lut_size
)
1586 struct i40e_pf
*pf
= vsi
->back
;
1587 struct i40e_hw
*hw
= &pf
->hw
;
1591 struct i40e_aqc_get_set_rss_key_data
*seed_dw
=
1592 (struct i40e_aqc_get_set_rss_key_data
*)seed
;
1593 ret
= i40e_aq_set_rss_key(hw
, vsi
->id
, seed_dw
);
1595 dev_info(&pf
->pdev
->dev
,
1596 "Cannot set RSS key, err %s aq_err %s\n",
1597 i40e_stat_str(hw
, ret
),
1598 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
1603 bool pf_lut
= vsi
->type
== I40E_VSI_MAIN
? true : false;
1605 ret
= i40e_aq_set_rss_lut(hw
, vsi
->id
, pf_lut
, lut
, lut_size
);
1607 dev_info(&pf
->pdev
->dev
,
1608 "Cannot set RSS lut, err %s aq_err %s\n",
1609 i40e_stat_str(hw
, ret
),
1610 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
1618 * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
1619 * @vsi: VSI structure
1621 static int i40e_vsi_config_rss(struct i40e_vsi
*vsi
)
1623 struct i40e_pf
*pf
= vsi
->back
;
1624 u8 seed
[I40E_HKEY_ARRAY_SIZE
];
1628 if (!(pf
->hw_features
& I40E_HW_RSS_AQ_CAPABLE
))
1631 vsi
->rss_size
= min_t(int, pf
->alloc_rss_size
,
1632 vsi
->num_queue_pairs
);
1635 lut
= kzalloc(vsi
->rss_table_size
, GFP_KERNEL
);
1639 /* Use the user configured hash keys and lookup table if there is one,
1640 * otherwise use default
1642 if (vsi
->rss_lut_user
)
1643 memcpy(lut
, vsi
->rss_lut_user
, vsi
->rss_table_size
);
1645 i40e_fill_rss_lut(pf
, lut
, vsi
->rss_table_size
, vsi
->rss_size
);
1646 if (vsi
->rss_hkey_user
)
1647 memcpy(seed
, vsi
->rss_hkey_user
, I40E_HKEY_ARRAY_SIZE
);
1649 netdev_rss_key_fill((void *)seed
, I40E_HKEY_ARRAY_SIZE
);
1650 ret
= i40e_config_rss_aq(vsi
, seed
, lut
, vsi
->rss_table_size
);
1656 * i40e_vsi_setup_queue_map_mqprio - Prepares mqprio based tc_config
1657 * @vsi: the VSI being configured,
1658 * @ctxt: VSI context structure
1659 * @enabled_tc: number of traffic classes to enable
1661 * Prepares VSI tc_config to have queue configurations based on MQPRIO options.
1663 static int i40e_vsi_setup_queue_map_mqprio(struct i40e_vsi
*vsi
,
1664 struct i40e_vsi_context
*ctxt
,
1667 u16 qcount
= 0, max_qcount
, qmap
, sections
= 0;
1668 int i
, override_q
, pow
, num_qps
, ret
;
1669 u8 netdev_tc
= 0, offset
= 0;
1671 if (vsi
->type
!= I40E_VSI_MAIN
)
1673 sections
= I40E_AQ_VSI_PROP_QUEUE_MAP_VALID
;
1674 sections
|= I40E_AQ_VSI_PROP_SCHED_VALID
;
1675 vsi
->tc_config
.numtc
= vsi
->mqprio_qopt
.qopt
.num_tc
;
1676 vsi
->tc_config
.enabled_tc
= enabled_tc
? enabled_tc
: 1;
1677 num_qps
= vsi
->mqprio_qopt
.qopt
.count
[0];
1679 /* find the next higher power-of-2 of num queue pairs */
1680 pow
= ilog2(num_qps
);
1681 if (!is_power_of_2(num_qps
))
1683 qmap
= (offset
<< I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT
) |
1684 (pow
<< I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT
);
1686 /* Setup queue offset/count for all TCs for given VSI */
1687 max_qcount
= vsi
->mqprio_qopt
.qopt
.count
[0];
1688 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1689 /* See if the given TC is enabled for the given VSI */
1690 if (vsi
->tc_config
.enabled_tc
& BIT(i
)) {
1691 offset
= vsi
->mqprio_qopt
.qopt
.offset
[i
];
1692 qcount
= vsi
->mqprio_qopt
.qopt
.count
[i
];
1693 if (qcount
> max_qcount
)
1694 max_qcount
= qcount
;
1695 vsi
->tc_config
.tc_info
[i
].qoffset
= offset
;
1696 vsi
->tc_config
.tc_info
[i
].qcount
= qcount
;
1697 vsi
->tc_config
.tc_info
[i
].netdev_tc
= netdev_tc
++;
1699 /* TC is not enabled so set the offset to
1700 * default queue and allocate one queue
1703 vsi
->tc_config
.tc_info
[i
].qoffset
= 0;
1704 vsi
->tc_config
.tc_info
[i
].qcount
= 1;
1705 vsi
->tc_config
.tc_info
[i
].netdev_tc
= 0;
1709 /* Set actual Tx/Rx queue pairs */
1710 vsi
->num_queue_pairs
= offset
+ qcount
;
1712 /* Setup queue TC[0].qmap for given VSI context */
1713 ctxt
->info
.tc_mapping
[0] = cpu_to_le16(qmap
);
1714 ctxt
->info
.mapping_flags
|= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG
);
1715 ctxt
->info
.queue_mapping
[0] = cpu_to_le16(vsi
->base_queue
);
1716 ctxt
->info
.valid_sections
|= cpu_to_le16(sections
);
1718 /* Reconfigure RSS for main VSI with max queue count */
1719 vsi
->rss_size
= max_qcount
;
1720 ret
= i40e_vsi_config_rss(vsi
);
1722 dev_info(&vsi
->back
->pdev
->dev
,
1723 "Failed to reconfig rss for num_queues (%u)\n",
1727 vsi
->reconfig_rss
= true;
1728 dev_dbg(&vsi
->back
->pdev
->dev
,
1729 "Reconfigured rss with num_queues (%u)\n", max_qcount
);
1731 /* Find queue count available for channel VSIs and starting offset
1734 override_q
= vsi
->mqprio_qopt
.qopt
.count
[0];
1735 if (override_q
&& override_q
< vsi
->num_queue_pairs
) {
1736 vsi
->cnt_q_avail
= vsi
->num_queue_pairs
- override_q
;
1737 vsi
->next_base_queue
= override_q
;
1743 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1744 * @vsi: the VSI being setup
1745 * @ctxt: VSI context structure
1746 * @enabled_tc: Enabled TCs bitmap
1747 * @is_add: True if called before Add VSI
1749 * Setup VSI queue mapping for enabled traffic classes.
1751 static void i40e_vsi_setup_queue_map(struct i40e_vsi
*vsi
,
1752 struct i40e_vsi_context
*ctxt
,
1756 struct i40e_pf
*pf
= vsi
->back
;
1766 sections
= I40E_AQ_VSI_PROP_QUEUE_MAP_VALID
;
1769 /* Number of queues per enabled TC */
1770 num_tc_qps
= vsi
->alloc_queue_pairs
;
1771 if (enabled_tc
&& (vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
1772 /* Find numtc from enabled TC bitmap */
1773 for (i
= 0, numtc
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1774 if (enabled_tc
& BIT(i
)) /* TC is enabled */
1778 dev_warn(&pf
->pdev
->dev
, "DCB is enabled but no TC enabled, forcing TC0\n");
1781 num_tc_qps
= num_tc_qps
/ numtc
;
1782 num_tc_qps
= min_t(int, num_tc_qps
,
1783 i40e_pf_get_max_q_per_tc(pf
));
1786 vsi
->tc_config
.numtc
= numtc
;
1787 vsi
->tc_config
.enabled_tc
= enabled_tc
? enabled_tc
: 1;
1789 /* Do not allow use more TC queue pairs than MSI-X vectors exist */
1790 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
1791 num_tc_qps
= min_t(int, num_tc_qps
, pf
->num_lan_msix
);
1793 /* Setup queue offset/count for all TCs for given VSI */
1794 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1795 /* See if the given TC is enabled for the given VSI */
1796 if (vsi
->tc_config
.enabled_tc
& BIT(i
)) {
1800 switch (vsi
->type
) {
1802 if (!(pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
|
1803 I40E_FLAG_FD_ATR_ENABLED
)) ||
1804 vsi
->tc_config
.enabled_tc
!= 1) {
1805 qcount
= min_t(int, pf
->alloc_rss_size
,
1811 case I40E_VSI_SRIOV
:
1812 case I40E_VSI_VMDQ2
:
1814 qcount
= num_tc_qps
;
1818 vsi
->tc_config
.tc_info
[i
].qoffset
= offset
;
1819 vsi
->tc_config
.tc_info
[i
].qcount
= qcount
;
1821 /* find the next higher power-of-2 of num queue pairs */
1824 while (num_qps
&& (BIT_ULL(pow
) < qcount
)) {
1829 vsi
->tc_config
.tc_info
[i
].netdev_tc
= netdev_tc
++;
1831 (offset
<< I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT
) |
1832 (pow
<< I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT
);
1836 /* TC is not enabled so set the offset to
1837 * default queue and allocate one queue
1840 vsi
->tc_config
.tc_info
[i
].qoffset
= 0;
1841 vsi
->tc_config
.tc_info
[i
].qcount
= 1;
1842 vsi
->tc_config
.tc_info
[i
].netdev_tc
= 0;
1846 ctxt
->info
.tc_mapping
[i
] = cpu_to_le16(qmap
);
1849 /* Set actual Tx/Rx queue pairs */
1850 vsi
->num_queue_pairs
= offset
;
1851 if ((vsi
->type
== I40E_VSI_MAIN
) && (numtc
== 1)) {
1852 if (vsi
->req_queue_pairs
> 0)
1853 vsi
->num_queue_pairs
= vsi
->req_queue_pairs
;
1854 else if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
1855 vsi
->num_queue_pairs
= pf
->num_lan_msix
;
1858 /* Scheduler section valid can only be set for ADD VSI */
1860 sections
|= I40E_AQ_VSI_PROP_SCHED_VALID
;
1862 ctxt
->info
.up_enable_bits
= enabled_tc
;
1864 if (vsi
->type
== I40E_VSI_SRIOV
) {
1865 ctxt
->info
.mapping_flags
|=
1866 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG
);
1867 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
1868 ctxt
->info
.queue_mapping
[i
] =
1869 cpu_to_le16(vsi
->base_queue
+ i
);
1871 ctxt
->info
.mapping_flags
|=
1872 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG
);
1873 ctxt
->info
.queue_mapping
[0] = cpu_to_le16(vsi
->base_queue
);
1875 ctxt
->info
.valid_sections
|= cpu_to_le16(sections
);
1879 * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address
1880 * @netdev: the netdevice
1881 * @addr: address to add
1883 * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
1884 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
1886 static int i40e_addr_sync(struct net_device
*netdev
, const u8
*addr
)
1888 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1889 struct i40e_vsi
*vsi
= np
->vsi
;
1891 if (i40e_add_mac_filter(vsi
, addr
))
1898 * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
1899 * @netdev: the netdevice
1900 * @addr: address to add
1902 * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
1903 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
1905 static int i40e_addr_unsync(struct net_device
*netdev
, const u8
*addr
)
1907 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1908 struct i40e_vsi
*vsi
= np
->vsi
;
1910 /* Under some circumstances, we might receive a request to delete
1911 * our own device address from our uc list. Because we store the
1912 * device address in the VSI's MAC/VLAN filter list, we need to ignore
1913 * such requests and not delete our device address from this list.
1915 if (ether_addr_equal(addr
, netdev
->dev_addr
))
1918 i40e_del_mac_filter(vsi
, addr
);
1924 * i40e_set_rx_mode - NDO callback to set the netdev filters
1925 * @netdev: network interface device structure
1927 static void i40e_set_rx_mode(struct net_device
*netdev
)
1929 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1930 struct i40e_vsi
*vsi
= np
->vsi
;
1932 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
1934 __dev_uc_sync(netdev
, i40e_addr_sync
, i40e_addr_unsync
);
1935 __dev_mc_sync(netdev
, i40e_addr_sync
, i40e_addr_unsync
);
1937 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
1939 /* check for other flag changes */
1940 if (vsi
->current_netdev_flags
!= vsi
->netdev
->flags
) {
1941 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1942 set_bit(__I40E_MACVLAN_SYNC_PENDING
, vsi
->back
->state
);
1947 * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
1948 * @vsi: Pointer to VSI struct
1949 * @from: Pointer to list which contains MAC filter entries - changes to
1950 * those entries needs to be undone.
1952 * MAC filter entries from this list were slated for deletion.
1954 static void i40e_undo_del_filter_entries(struct i40e_vsi
*vsi
,
1955 struct hlist_head
*from
)
1957 struct i40e_mac_filter
*f
;
1958 struct hlist_node
*h
;
1960 hlist_for_each_entry_safe(f
, h
, from
, hlist
) {
1961 u64 key
= i40e_addr_to_hkey(f
->macaddr
);
1963 /* Move the element back into MAC filter list*/
1964 hlist_del(&f
->hlist
);
1965 hash_add(vsi
->mac_filter_hash
, &f
->hlist
, key
);
1970 * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries
1971 * @vsi: Pointer to vsi struct
1972 * @from: Pointer to list which contains MAC filter entries - changes to
1973 * those entries needs to be undone.
1975 * MAC filter entries from this list were slated for addition.
1977 static void i40e_undo_add_filter_entries(struct i40e_vsi
*vsi
,
1978 struct hlist_head
*from
)
1980 struct i40e_new_mac_filter
*new;
1981 struct hlist_node
*h
;
1983 hlist_for_each_entry_safe(new, h
, from
, hlist
) {
1984 /* We can simply free the wrapper structure */
1985 hlist_del(&new->hlist
);
1991 * i40e_next_entry - Get the next non-broadcast filter from a list
1992 * @next: pointer to filter in list
1994 * Returns the next non-broadcast filter in the list. Required so that we
1995 * ignore broadcast filters within the list, since these are not handled via
1996 * the normal firmware update path.
1999 struct i40e_new_mac_filter
*i40e_next_filter(struct i40e_new_mac_filter
*next
)
2001 hlist_for_each_entry_continue(next
, hlist
) {
2002 if (!is_broadcast_ether_addr(next
->f
->macaddr
))
2010 * i40e_update_filter_state - Update filter state based on return data
2012 * @count: Number of filters added
2013 * @add_list: return data from fw
2014 * @add_head: pointer to first filter in current batch
2016 * MAC filter entries from list were slated to be added to device. Returns
2017 * number of successful filters. Note that 0 does NOT mean success!
2020 i40e_update_filter_state(int count
,
2021 struct i40e_aqc_add_macvlan_element_data
*add_list
,
2022 struct i40e_new_mac_filter
*add_head
)
2027 for (i
= 0; i
< count
; i
++) {
2028 /* Always check status of each filter. We don't need to check
2029 * the firmware return status because we pre-set the filter
2030 * status to I40E_AQC_MM_ERR_NO_RES when sending the filter
2031 * request to the adminq. Thus, if it no longer matches then
2032 * we know the filter is active.
2034 if (add_list
[i
].match_method
== I40E_AQC_MM_ERR_NO_RES
) {
2035 add_head
->state
= I40E_FILTER_FAILED
;
2037 add_head
->state
= I40E_FILTER_ACTIVE
;
2041 add_head
= i40e_next_filter(add_head
);
2050 * i40e_aqc_del_filters - Request firmware to delete a set of filters
2051 * @vsi: ptr to the VSI
2052 * @vsi_name: name to display in messages
2053 * @list: the list of filters to send to firmware
2054 * @num_del: the number of filters to delete
2055 * @retval: Set to -EIO on failure to delete
2057 * Send a request to firmware via AdminQ to delete a set of filters. Uses
2058 * *retval instead of a return value so that success does not force ret_val to
2059 * be set to 0. This ensures that a sequence of calls to this function
2060 * preserve the previous value of *retval on successful delete.
2063 void i40e_aqc_del_filters(struct i40e_vsi
*vsi
, const char *vsi_name
,
2064 struct i40e_aqc_remove_macvlan_element_data
*list
,
2065 int num_del
, int *retval
)
2067 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2071 aq_ret
= i40e_aq_remove_macvlan(hw
, vsi
->seid
, list
, num_del
, NULL
);
2072 aq_err
= hw
->aq
.asq_last_status
;
2074 /* Explicitly ignore and do not report when firmware returns ENOENT */
2075 if (aq_ret
&& !(aq_err
== I40E_AQ_RC_ENOENT
)) {
2077 dev_info(&vsi
->back
->pdev
->dev
,
2078 "ignoring delete macvlan error on %s, err %s, aq_err %s\n",
2079 vsi_name
, i40e_stat_str(hw
, aq_ret
),
2080 i40e_aq_str(hw
, aq_err
));
2085 * i40e_aqc_add_filters - Request firmware to add a set of filters
2086 * @vsi: ptr to the VSI
2087 * @vsi_name: name to display in messages
2088 * @list: the list of filters to send to firmware
2089 * @add_head: Position in the add hlist
2090 * @num_add: the number of filters to add
2092 * Send a request to firmware via AdminQ to add a chunk of filters. Will set
2093 * __I40E_VSI_OVERFLOW_PROMISC bit in vsi->state if the firmware has run out of
2094 * space for more filters.
2097 void i40e_aqc_add_filters(struct i40e_vsi
*vsi
, const char *vsi_name
,
2098 struct i40e_aqc_add_macvlan_element_data
*list
,
2099 struct i40e_new_mac_filter
*add_head
,
2102 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2105 i40e_aq_add_macvlan(hw
, vsi
->seid
, list
, num_add
, NULL
);
2106 aq_err
= hw
->aq
.asq_last_status
;
2107 fcnt
= i40e_update_filter_state(num_add
, list
, add_head
);
2109 if (fcnt
!= num_add
) {
2110 set_bit(__I40E_VSI_OVERFLOW_PROMISC
, vsi
->state
);
2111 dev_warn(&vsi
->back
->pdev
->dev
,
2112 "Error %s adding RX filters on %s, promiscuous mode forced on\n",
2113 i40e_aq_str(hw
, aq_err
),
2119 * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags
2120 * @vsi: pointer to the VSI
2121 * @vsi_name: the VSI name
2124 * This function sets or clears the promiscuous broadcast flags for VLAN
2125 * filters in order to properly receive broadcast frames. Assumes that only
2126 * broadcast filters are passed.
2128 * Returns status indicating success or failure;
2131 i40e_aqc_broadcast_filter(struct i40e_vsi
*vsi
, const char *vsi_name
,
2132 struct i40e_mac_filter
*f
)
2134 bool enable
= f
->state
== I40E_FILTER_NEW
;
2135 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2138 if (f
->vlan
== I40E_VLAN_ANY
) {
2139 aq_ret
= i40e_aq_set_vsi_broadcast(hw
,
2144 aq_ret
= i40e_aq_set_vsi_bc_promisc_on_vlan(hw
,
2152 set_bit(__I40E_VSI_OVERFLOW_PROMISC
, vsi
->state
);
2153 dev_warn(&vsi
->back
->pdev
->dev
,
2154 "Error %s, forcing overflow promiscuous on %s\n",
2155 i40e_aq_str(hw
, hw
->aq
.asq_last_status
),
2163 * i40e_set_promiscuous - set promiscuous mode
2164 * @pf: board private structure
2165 * @promisc: promisc on or off
2167 * There are different ways of setting promiscuous mode on a PF depending on
2168 * what state/environment we're in. This identifies and sets it appropriately.
2169 * Returns 0 on success.
2171 static int i40e_set_promiscuous(struct i40e_pf
*pf
, bool promisc
)
2173 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
2174 struct i40e_hw
*hw
= &pf
->hw
;
2177 if (vsi
->type
== I40E_VSI_MAIN
&&
2178 pf
->lan_veb
!= I40E_NO_VEB
&&
2179 !(pf
->flags
& I40E_FLAG_MFP_ENABLED
)) {
2180 /* set defport ON for Main VSI instead of true promisc
2181 * this way we will get all unicast/multicast and VLAN
2182 * promisc behavior but will not get VF or VMDq traffic
2183 * replicated on the Main VSI.
2186 aq_ret
= i40e_aq_set_default_vsi(hw
,
2190 aq_ret
= i40e_aq_clear_default_vsi(hw
,
2194 dev_info(&pf
->pdev
->dev
,
2195 "Set default VSI failed, err %s, aq_err %s\n",
2196 i40e_stat_str(hw
, aq_ret
),
2197 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
2200 aq_ret
= i40e_aq_set_vsi_unicast_promiscuous(
2206 dev_info(&pf
->pdev
->dev
,
2207 "set unicast promisc failed, err %s, aq_err %s\n",
2208 i40e_stat_str(hw
, aq_ret
),
2209 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
2211 aq_ret
= i40e_aq_set_vsi_multicast_promiscuous(
2216 dev_info(&pf
->pdev
->dev
,
2217 "set multicast promisc failed, err %s, aq_err %s\n",
2218 i40e_stat_str(hw
, aq_ret
),
2219 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
2224 pf
->cur_promisc
= promisc
;
2230 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
2231 * @vsi: ptr to the VSI
2233 * Push any outstanding VSI filter changes through the AdminQ.
2235 * Returns 0 or error value
2237 int i40e_sync_vsi_filters(struct i40e_vsi
*vsi
)
2239 struct hlist_head tmp_add_list
, tmp_del_list
;
2240 struct i40e_mac_filter
*f
;
2241 struct i40e_new_mac_filter
*new, *add_head
= NULL
;
2242 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2243 bool old_overflow
, new_overflow
;
2244 unsigned int failed_filters
= 0;
2245 unsigned int vlan_filters
= 0;
2246 char vsi_name
[16] = "PF";
2247 int filter_list_len
= 0;
2248 i40e_status aq_ret
= 0;
2249 u32 changed_flags
= 0;
2250 struct hlist_node
*h
;
2259 /* empty array typed pointers, kcalloc later */
2260 struct i40e_aqc_add_macvlan_element_data
*add_list
;
2261 struct i40e_aqc_remove_macvlan_element_data
*del_list
;
2263 while (test_and_set_bit(__I40E_VSI_SYNCING_FILTERS
, vsi
->state
))
2264 usleep_range(1000, 2000);
2267 old_overflow
= test_bit(__I40E_VSI_OVERFLOW_PROMISC
, vsi
->state
);
2270 changed_flags
= vsi
->current_netdev_flags
^ vsi
->netdev
->flags
;
2271 vsi
->current_netdev_flags
= vsi
->netdev
->flags
;
2274 INIT_HLIST_HEAD(&tmp_add_list
);
2275 INIT_HLIST_HEAD(&tmp_del_list
);
2277 if (vsi
->type
== I40E_VSI_SRIOV
)
2278 snprintf(vsi_name
, sizeof(vsi_name
) - 1, "VF %d", vsi
->vf_id
);
2279 else if (vsi
->type
!= I40E_VSI_MAIN
)
2280 snprintf(vsi_name
, sizeof(vsi_name
) - 1, "vsi %d", vsi
->seid
);
2282 if (vsi
->flags
& I40E_VSI_FLAG_FILTER_CHANGED
) {
2283 vsi
->flags
&= ~I40E_VSI_FLAG_FILTER_CHANGED
;
2285 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2286 /* Create a list of filters to delete. */
2287 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
2288 if (f
->state
== I40E_FILTER_REMOVE
) {
2289 /* Move the element into temporary del_list */
2290 hash_del(&f
->hlist
);
2291 hlist_add_head(&f
->hlist
, &tmp_del_list
);
2293 /* Avoid counting removed filters */
2296 if (f
->state
== I40E_FILTER_NEW
) {
2297 /* Create a temporary i40e_new_mac_filter */
2298 new = kzalloc(sizeof(*new), GFP_ATOMIC
);
2300 goto err_no_memory_locked
;
2302 /* Store pointer to the real filter */
2304 new->state
= f
->state
;
2306 /* Add it to the hash list */
2307 hlist_add_head(&new->hlist
, &tmp_add_list
);
2310 /* Count the number of active (current and new) VLAN
2311 * filters we have now. Does not count filters which
2312 * are marked for deletion.
2318 retval
= i40e_correct_mac_vlan_filters(vsi
,
2323 goto err_no_memory_locked
;
2325 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2328 /* Now process 'del_list' outside the lock */
2329 if (!hlist_empty(&tmp_del_list
)) {
2330 filter_list_len
= hw
->aq
.asq_buf_size
/
2331 sizeof(struct i40e_aqc_remove_macvlan_element_data
);
2332 list_size
= filter_list_len
*
2333 sizeof(struct i40e_aqc_remove_macvlan_element_data
);
2334 del_list
= kzalloc(list_size
, GFP_ATOMIC
);
2338 hlist_for_each_entry_safe(f
, h
, &tmp_del_list
, hlist
) {
2341 /* handle broadcast filters by updating the broadcast
2342 * promiscuous flag and release filter list.
2344 if (is_broadcast_ether_addr(f
->macaddr
)) {
2345 i40e_aqc_broadcast_filter(vsi
, vsi_name
, f
);
2347 hlist_del(&f
->hlist
);
2352 /* add to delete list */
2353 ether_addr_copy(del_list
[num_del
].mac_addr
, f
->macaddr
);
2354 if (f
->vlan
== I40E_VLAN_ANY
) {
2355 del_list
[num_del
].vlan_tag
= 0;
2356 cmd_flags
|= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
2358 del_list
[num_del
].vlan_tag
=
2359 cpu_to_le16((u16
)(f
->vlan
));
2362 cmd_flags
|= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
2363 del_list
[num_del
].flags
= cmd_flags
;
2366 /* flush a full buffer */
2367 if (num_del
== filter_list_len
) {
2368 i40e_aqc_del_filters(vsi
, vsi_name
, del_list
,
2370 memset(del_list
, 0, list_size
);
2373 /* Release memory for MAC filter entries which were
2374 * synced up with HW.
2376 hlist_del(&f
->hlist
);
2381 i40e_aqc_del_filters(vsi
, vsi_name
, del_list
,
2389 if (!hlist_empty(&tmp_add_list
)) {
2390 /* Do all the adds now. */
2391 filter_list_len
= hw
->aq
.asq_buf_size
/
2392 sizeof(struct i40e_aqc_add_macvlan_element_data
);
2393 list_size
= filter_list_len
*
2394 sizeof(struct i40e_aqc_add_macvlan_element_data
);
2395 add_list
= kzalloc(list_size
, GFP_ATOMIC
);
2400 hlist_for_each_entry_safe(new, h
, &tmp_add_list
, hlist
) {
2401 /* handle broadcast filters by updating the broadcast
2402 * promiscuous flag instead of adding a MAC filter.
2404 if (is_broadcast_ether_addr(new->f
->macaddr
)) {
2405 if (i40e_aqc_broadcast_filter(vsi
, vsi_name
,
2407 new->state
= I40E_FILTER_FAILED
;
2409 new->state
= I40E_FILTER_ACTIVE
;
2413 /* add to add array */
2417 ether_addr_copy(add_list
[num_add
].mac_addr
,
2419 if (new->f
->vlan
== I40E_VLAN_ANY
) {
2420 add_list
[num_add
].vlan_tag
= 0;
2421 cmd_flags
|= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN
;
2423 add_list
[num_add
].vlan_tag
=
2424 cpu_to_le16((u16
)(new->f
->vlan
));
2426 add_list
[num_add
].queue_number
= 0;
2427 /* set invalid match method for later detection */
2428 add_list
[num_add
].match_method
= I40E_AQC_MM_ERR_NO_RES
;
2429 cmd_flags
|= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
;
2430 add_list
[num_add
].flags
= cpu_to_le16(cmd_flags
);
2433 /* flush a full buffer */
2434 if (num_add
== filter_list_len
) {
2435 i40e_aqc_add_filters(vsi
, vsi_name
, add_list
,
2437 memset(add_list
, 0, list_size
);
2442 i40e_aqc_add_filters(vsi
, vsi_name
, add_list
, add_head
,
2445 /* Now move all of the filters from the temp add list back to
2448 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2449 hlist_for_each_entry_safe(new, h
, &tmp_add_list
, hlist
) {
2450 /* Only update the state if we're still NEW */
2451 if (new->f
->state
== I40E_FILTER_NEW
)
2452 new->f
->state
= new->state
;
2453 hlist_del(&new->hlist
);
2456 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2461 /* Determine the number of active and failed filters. */
2462 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2463 vsi
->active_filters
= 0;
2464 hash_for_each(vsi
->mac_filter_hash
, bkt
, f
, hlist
) {
2465 if (f
->state
== I40E_FILTER_ACTIVE
)
2466 vsi
->active_filters
++;
2467 else if (f
->state
== I40E_FILTER_FAILED
)
2470 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2472 /* Check if we are able to exit overflow promiscuous mode. We can
2473 * safely exit if we didn't just enter, we no longer have any failed
2474 * filters, and we have reduced filters below the threshold value.
2476 if (old_overflow
&& !failed_filters
&&
2477 vsi
->active_filters
< vsi
->promisc_threshold
) {
2478 dev_info(&pf
->pdev
->dev
,
2479 "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
2481 clear_bit(__I40E_VSI_OVERFLOW_PROMISC
, vsi
->state
);
2482 vsi
->promisc_threshold
= 0;
2485 /* if the VF is not trusted do not do promisc */
2486 if ((vsi
->type
== I40E_VSI_SRIOV
) && !pf
->vf
[vsi
->vf_id
].trusted
) {
2487 clear_bit(__I40E_VSI_OVERFLOW_PROMISC
, vsi
->state
);
2491 new_overflow
= test_bit(__I40E_VSI_OVERFLOW_PROMISC
, vsi
->state
);
2493 /* If we are entering overflow promiscuous, we need to calculate a new
2494 * threshold for when we are safe to exit
2496 if (!old_overflow
&& new_overflow
)
2497 vsi
->promisc_threshold
= (vsi
->active_filters
* 3) / 4;
2499 /* check for changes in promiscuous modes */
2500 if (changed_flags
& IFF_ALLMULTI
) {
2501 bool cur_multipromisc
;
2503 cur_multipromisc
= !!(vsi
->current_netdev_flags
& IFF_ALLMULTI
);
2504 aq_ret
= i40e_aq_set_vsi_multicast_promiscuous(&vsi
->back
->hw
,
2509 retval
= i40e_aq_rc_to_posix(aq_ret
,
2510 hw
->aq
.asq_last_status
);
2511 dev_info(&pf
->pdev
->dev
,
2512 "set multi promisc failed on %s, err %s aq_err %s\n",
2514 i40e_stat_str(hw
, aq_ret
),
2515 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
2519 if ((changed_flags
& IFF_PROMISC
) || old_overflow
!= new_overflow
) {
2522 cur_promisc
= (!!(vsi
->current_netdev_flags
& IFF_PROMISC
) ||
2524 aq_ret
= i40e_set_promiscuous(pf
, cur_promisc
);
2526 retval
= i40e_aq_rc_to_posix(aq_ret
,
2527 hw
->aq
.asq_last_status
);
2528 dev_info(&pf
->pdev
->dev
,
2529 "Setting promiscuous %s failed on %s, err %s aq_err %s\n",
2530 cur_promisc
? "on" : "off",
2532 i40e_stat_str(hw
, aq_ret
),
2533 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
2537 /* if something went wrong then set the changed flag so we try again */
2539 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
2541 clear_bit(__I40E_VSI_SYNCING_FILTERS
, vsi
->state
);
2545 /* Restore elements on the temporary add and delete lists */
2546 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2547 err_no_memory_locked
:
2548 i40e_undo_del_filter_entries(vsi
, &tmp_del_list
);
2549 i40e_undo_add_filter_entries(vsi
, &tmp_add_list
);
2550 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2552 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
2553 clear_bit(__I40E_VSI_SYNCING_FILTERS
, vsi
->state
);
2558 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
2559 * @pf: board private structure
2561 static void i40e_sync_filters_subtask(struct i40e_pf
*pf
)
2567 if (!test_and_clear_bit(__I40E_MACVLAN_SYNC_PENDING
, pf
->state
))
2570 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
2572 (pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_FILTER_CHANGED
)) {
2573 int ret
= i40e_sync_vsi_filters(pf
->vsi
[v
]);
2576 /* come back and try again later */
2577 set_bit(__I40E_MACVLAN_SYNC_PENDING
,
2586 * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP
2589 static int i40e_max_xdp_frame_size(struct i40e_vsi
*vsi
)
2591 if (PAGE_SIZE
>= 8192 || (vsi
->back
->flags
& I40E_FLAG_LEGACY_RX
))
2592 return I40E_RXBUFFER_2048
;
2594 return I40E_RXBUFFER_3072
;
2598 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
2599 * @netdev: network interface device structure
2600 * @new_mtu: new value for maximum frame size
2602 * Returns 0 on success, negative on failure
2604 static int i40e_change_mtu(struct net_device
*netdev
, int new_mtu
)
2606 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2607 struct i40e_vsi
*vsi
= np
->vsi
;
2608 struct i40e_pf
*pf
= vsi
->back
;
2610 if (i40e_enabled_xdp_vsi(vsi
)) {
2611 int frame_size
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
2613 if (frame_size
> i40e_max_xdp_frame_size(vsi
))
2617 netdev_info(netdev
, "changing MTU from %d to %d\n",
2618 netdev
->mtu
, new_mtu
);
2619 netdev
->mtu
= new_mtu
;
2620 if (netif_running(netdev
))
2621 i40e_vsi_reinit_locked(vsi
);
2622 set_bit(__I40E_CLIENT_SERVICE_REQUESTED
, pf
->state
);
2623 set_bit(__I40E_CLIENT_L2_CHANGE
, pf
->state
);
2628 * i40e_ioctl - Access the hwtstamp interface
2629 * @netdev: network interface device structure
2630 * @ifr: interface request data
2631 * @cmd: ioctl command
2633 int i40e_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
2635 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2636 struct i40e_pf
*pf
= np
->vsi
->back
;
2640 return i40e_ptp_get_ts_config(pf
, ifr
);
2642 return i40e_ptp_set_ts_config(pf
, ifr
);
2649 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
2650 * @vsi: the vsi being adjusted
2652 void i40e_vlan_stripping_enable(struct i40e_vsi
*vsi
)
2654 struct i40e_vsi_context ctxt
;
2657 if ((vsi
->info
.valid_sections
&
2658 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
2659 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_MODE_MASK
) == 0))
2660 return; /* already enabled */
2662 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2663 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
2664 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH
;
2666 ctxt
.seid
= vsi
->seid
;
2667 ctxt
.info
= vsi
->info
;
2668 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2670 dev_info(&vsi
->back
->pdev
->dev
,
2671 "update vlan stripping failed, err %s aq_err %s\n",
2672 i40e_stat_str(&vsi
->back
->hw
, ret
),
2673 i40e_aq_str(&vsi
->back
->hw
,
2674 vsi
->back
->hw
.aq
.asq_last_status
));
2679 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2680 * @vsi: the vsi being adjusted
2682 void i40e_vlan_stripping_disable(struct i40e_vsi
*vsi
)
2684 struct i40e_vsi_context ctxt
;
2687 if ((vsi
->info
.valid_sections
&
2688 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
2689 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_EMOD_MASK
) ==
2690 I40E_AQ_VSI_PVLAN_EMOD_MASK
))
2691 return; /* already disabled */
2693 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2694 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
2695 I40E_AQ_VSI_PVLAN_EMOD_NOTHING
;
2697 ctxt
.seid
= vsi
->seid
;
2698 ctxt
.info
= vsi
->info
;
2699 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2701 dev_info(&vsi
->back
->pdev
->dev
,
2702 "update vlan stripping failed, err %s aq_err %s\n",
2703 i40e_stat_str(&vsi
->back
->hw
, ret
),
2704 i40e_aq_str(&vsi
->back
->hw
,
2705 vsi
->back
->hw
.aq
.asq_last_status
));
2710 * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address
2711 * @vsi: the vsi being configured
2712 * @vid: vlan id to be added (0 = untagged only , -1 = any)
2714 * This is a helper function for adding a new MAC/VLAN filter with the
2715 * specified VLAN for each existing MAC address already in the hash table.
2716 * This function does *not* perform any accounting to update filters based on
2719 * NOTE: this function expects to be called while under the
2720 * mac_filter_hash_lock
2722 int i40e_add_vlan_all_mac(struct i40e_vsi
*vsi
, s16 vid
)
2724 struct i40e_mac_filter
*f
, *add_f
;
2725 struct hlist_node
*h
;
2728 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
2729 if (f
->state
== I40E_FILTER_REMOVE
)
2731 add_f
= i40e_add_filter(vsi
, f
->macaddr
, vid
);
2733 dev_info(&vsi
->back
->pdev
->dev
,
2734 "Could not add vlan filter %d for %pM\n",
2744 * i40e_vsi_add_vlan - Add VSI membership for given VLAN
2745 * @vsi: the VSI being configured
2746 * @vid: VLAN id to be added
2748 int i40e_vsi_add_vlan(struct i40e_vsi
*vsi
, u16 vid
)
2755 /* The network stack will attempt to add VID=0, with the intention to
2756 * receive priority tagged packets with a VLAN of 0. Our HW receives
2757 * these packets by default when configured to receive untagged
2758 * packets, so we don't need to add a filter for this case.
2759 * Additionally, HW interprets adding a VID=0 filter as meaning to
2760 * receive *only* tagged traffic and stops receiving untagged traffic.
2761 * Thus, we do not want to actually add a filter for VID=0
2766 /* Locked once because all functions invoked below iterates list*/
2767 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2768 err
= i40e_add_vlan_all_mac(vsi
, vid
);
2769 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2773 /* schedule our worker thread which will take care of
2774 * applying the new filter changes
2776 i40e_service_event_schedule(vsi
->back
);
2781 * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN
2782 * @vsi: the vsi being configured
2783 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
2785 * This function should be used to remove all VLAN filters which match the
2786 * given VID. It does not schedule the service event and does not take the
2787 * mac_filter_hash_lock so it may be combined with other operations under
2788 * a single invocation of the mac_filter_hash_lock.
2790 * NOTE: this function expects to be called while under the
2791 * mac_filter_hash_lock
2793 void i40e_rm_vlan_all_mac(struct i40e_vsi
*vsi
, s16 vid
)
2795 struct i40e_mac_filter
*f
;
2796 struct hlist_node
*h
;
2799 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
2801 __i40e_del_filter(vsi
, f
);
2806 * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN
2807 * @vsi: the VSI being configured
2808 * @vid: VLAN id to be removed
2810 void i40e_vsi_kill_vlan(struct i40e_vsi
*vsi
, u16 vid
)
2812 if (!vid
|| vsi
->info
.pvid
)
2815 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2816 i40e_rm_vlan_all_mac(vsi
, vid
);
2817 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2819 /* schedule our worker thread which will take care of
2820 * applying the new filter changes
2822 i40e_service_event_schedule(vsi
->back
);
2826 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2827 * @netdev: network interface to be adjusted
2828 * @proto: unused protocol value
2829 * @vid: vlan id to be added
2831 * net_device_ops implementation for adding vlan ids
2833 static int i40e_vlan_rx_add_vid(struct net_device
*netdev
,
2834 __always_unused __be16 proto
, u16 vid
)
2836 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2837 struct i40e_vsi
*vsi
= np
->vsi
;
2840 if (vid
>= VLAN_N_VID
)
2843 ret
= i40e_vsi_add_vlan(vsi
, vid
);
2845 set_bit(vid
, vsi
->active_vlans
);
2851 * i40e_vlan_rx_add_vid_up - Add a vlan id filter to HW offload in UP path
2852 * @netdev: network interface to be adjusted
2853 * @proto: unused protocol value
2854 * @vid: vlan id to be added
2856 static void i40e_vlan_rx_add_vid_up(struct net_device
*netdev
,
2857 __always_unused __be16 proto
, u16 vid
)
2859 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2860 struct i40e_vsi
*vsi
= np
->vsi
;
2862 if (vid
>= VLAN_N_VID
)
2864 set_bit(vid
, vsi
->active_vlans
);
2868 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2869 * @netdev: network interface to be adjusted
2870 * @proto: unused protocol value
2871 * @vid: vlan id to be removed
2873 * net_device_ops implementation for removing vlan ids
2875 static int i40e_vlan_rx_kill_vid(struct net_device
*netdev
,
2876 __always_unused __be16 proto
, u16 vid
)
2878 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2879 struct i40e_vsi
*vsi
= np
->vsi
;
2881 /* return code is ignored as there is nothing a user
2882 * can do about failure to remove and a log message was
2883 * already printed from the other function
2885 i40e_vsi_kill_vlan(vsi
, vid
);
2887 clear_bit(vid
, vsi
->active_vlans
);
2893 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2894 * @vsi: the vsi being brought back up
2896 static void i40e_restore_vlan(struct i40e_vsi
*vsi
)
2903 if (vsi
->netdev
->features
& NETIF_F_HW_VLAN_CTAG_RX
)
2904 i40e_vlan_stripping_enable(vsi
);
2906 i40e_vlan_stripping_disable(vsi
);
2908 for_each_set_bit(vid
, vsi
->active_vlans
, VLAN_N_VID
)
2909 i40e_vlan_rx_add_vid_up(vsi
->netdev
, htons(ETH_P_8021Q
),
2914 * i40e_vsi_add_pvid - Add pvid for the VSI
2915 * @vsi: the vsi being adjusted
2916 * @vid: the vlan id to set as a PVID
2918 int i40e_vsi_add_pvid(struct i40e_vsi
*vsi
, u16 vid
)
2920 struct i40e_vsi_context ctxt
;
2923 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2924 vsi
->info
.pvid
= cpu_to_le16(vid
);
2925 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_TAGGED
|
2926 I40E_AQ_VSI_PVLAN_INSERT_PVID
|
2927 I40E_AQ_VSI_PVLAN_EMOD_STR
;
2929 ctxt
.seid
= vsi
->seid
;
2930 ctxt
.info
= vsi
->info
;
2931 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2933 dev_info(&vsi
->back
->pdev
->dev
,
2934 "add pvid failed, err %s aq_err %s\n",
2935 i40e_stat_str(&vsi
->back
->hw
, ret
),
2936 i40e_aq_str(&vsi
->back
->hw
,
2937 vsi
->back
->hw
.aq
.asq_last_status
));
2945 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2946 * @vsi: the vsi being adjusted
2948 * Just use the vlan_rx_register() service to put it back to normal
2950 void i40e_vsi_remove_pvid(struct i40e_vsi
*vsi
)
2952 i40e_vlan_stripping_disable(vsi
);
2958 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2959 * @vsi: ptr to the VSI
2961 * If this function returns with an error, then it's possible one or
2962 * more of the rings is populated (while the rest are not). It is the
2963 * callers duty to clean those orphaned rings.
2965 * Return 0 on success, negative on failure
2967 static int i40e_vsi_setup_tx_resources(struct i40e_vsi
*vsi
)
2971 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2972 err
= i40e_setup_tx_descriptors(vsi
->tx_rings
[i
]);
2974 if (!i40e_enabled_xdp_vsi(vsi
))
2977 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2978 err
= i40e_setup_tx_descriptors(vsi
->xdp_rings
[i
]);
2984 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2985 * @vsi: ptr to the VSI
2987 * Free VSI's transmit software resources
2989 static void i40e_vsi_free_tx_resources(struct i40e_vsi
*vsi
)
2993 if (vsi
->tx_rings
) {
2994 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2995 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
)
2996 i40e_free_tx_resources(vsi
->tx_rings
[i
]);
2999 if (vsi
->xdp_rings
) {
3000 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
3001 if (vsi
->xdp_rings
[i
] && vsi
->xdp_rings
[i
]->desc
)
3002 i40e_free_tx_resources(vsi
->xdp_rings
[i
]);
3007 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
3008 * @vsi: ptr to the VSI
3010 * If this function returns with an error, then it's possible one or
3011 * more of the rings is populated (while the rest are not). It is the
3012 * callers duty to clean those orphaned rings.
3014 * Return 0 on success, negative on failure
3016 static int i40e_vsi_setup_rx_resources(struct i40e_vsi
*vsi
)
3020 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
3021 err
= i40e_setup_rx_descriptors(vsi
->rx_rings
[i
]);
3026 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
3027 * @vsi: ptr to the VSI
3029 * Free all receive software resources
3031 static void i40e_vsi_free_rx_resources(struct i40e_vsi
*vsi
)
3038 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
3039 if (vsi
->rx_rings
[i
] && vsi
->rx_rings
[i
]->desc
)
3040 i40e_free_rx_resources(vsi
->rx_rings
[i
]);
3044 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
3045 * @ring: The Tx ring to configure
3047 * This enables/disables XPS for a given Tx descriptor ring
3048 * based on the TCs enabled for the VSI that ring belongs to.
3050 static void i40e_config_xps_tx_ring(struct i40e_ring
*ring
)
3054 if (!ring
->q_vector
|| !ring
->netdev
|| ring
->ch
)
3057 /* We only initialize XPS once, so as not to overwrite user settings */
3058 if (test_and_set_bit(__I40E_TX_XPS_INIT_DONE
, ring
->state
))
3061 cpu
= cpumask_local_spread(ring
->q_vector
->v_idx
, -1);
3062 netif_set_xps_queue(ring
->netdev
, get_cpu_mask(cpu
),
3067 * i40e_configure_tx_ring - Configure a transmit ring context and rest
3068 * @ring: The Tx ring to configure
3070 * Configure the Tx descriptor ring in the HMC context.
3072 static int i40e_configure_tx_ring(struct i40e_ring
*ring
)
3074 struct i40e_vsi
*vsi
= ring
->vsi
;
3075 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
3076 struct i40e_hw
*hw
= &vsi
->back
->hw
;
3077 struct i40e_hmc_obj_txq tx_ctx
;
3078 i40e_status err
= 0;
3081 /* some ATR related tx ring init */
3082 if (vsi
->back
->flags
& I40E_FLAG_FD_ATR_ENABLED
) {
3083 ring
->atr_sample_rate
= vsi
->back
->atr_sample_rate
;
3084 ring
->atr_count
= 0;
3086 ring
->atr_sample_rate
= 0;
3090 i40e_config_xps_tx_ring(ring
);
3092 /* clear the context structure first */
3093 memset(&tx_ctx
, 0, sizeof(tx_ctx
));
3095 tx_ctx
.new_context
= 1;
3096 tx_ctx
.base
= (ring
->dma
/ 128);
3097 tx_ctx
.qlen
= ring
->count
;
3098 tx_ctx
.fd_ena
= !!(vsi
->back
->flags
& (I40E_FLAG_FD_SB_ENABLED
|
3099 I40E_FLAG_FD_ATR_ENABLED
));
3100 tx_ctx
.timesync_ena
= !!(vsi
->back
->flags
& I40E_FLAG_PTP
);
3101 /* FDIR VSI tx ring can still use RS bit and writebacks */
3102 if (vsi
->type
!= I40E_VSI_FDIR
)
3103 tx_ctx
.head_wb_ena
= 1;
3104 tx_ctx
.head_wb_addr
= ring
->dma
+
3105 (ring
->count
* sizeof(struct i40e_tx_desc
));
3107 /* As part of VSI creation/update, FW allocates certain
3108 * Tx arbitration queue sets for each TC enabled for
3109 * the VSI. The FW returns the handles to these queue
3110 * sets as part of the response buffer to Add VSI,
3111 * Update VSI, etc. AQ commands. It is expected that
3112 * these queue set handles be associated with the Tx
3113 * queues by the driver as part of the TX queue context
3114 * initialization. This has to be done regardless of
3115 * DCB as by default everything is mapped to TC0.
3120 le16_to_cpu(ring
->ch
->info
.qs_handle
[ring
->dcb_tc
]);
3123 tx_ctx
.rdylist
= le16_to_cpu(vsi
->info
.qs_handle
[ring
->dcb_tc
]);
3125 tx_ctx
.rdylist_act
= 0;
3127 /* clear the context in the HMC */
3128 err
= i40e_clear_lan_tx_queue_context(hw
, pf_q
);
3130 dev_info(&vsi
->back
->pdev
->dev
,
3131 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
3132 ring
->queue_index
, pf_q
, err
);
3136 /* set the context in the HMC */
3137 err
= i40e_set_lan_tx_queue_context(hw
, pf_q
, &tx_ctx
);
3139 dev_info(&vsi
->back
->pdev
->dev
,
3140 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
3141 ring
->queue_index
, pf_q
, err
);
3145 /* Now associate this queue with this PCI function */
3147 if (ring
->ch
->type
== I40E_VSI_VMDQ2
)
3148 qtx_ctl
= I40E_QTX_CTL_VM_QUEUE
;
3152 qtx_ctl
|= (ring
->ch
->vsi_number
<<
3153 I40E_QTX_CTL_VFVM_INDX_SHIFT
) &
3154 I40E_QTX_CTL_VFVM_INDX_MASK
;
3156 if (vsi
->type
== I40E_VSI_VMDQ2
) {
3157 qtx_ctl
= I40E_QTX_CTL_VM_QUEUE
;
3158 qtx_ctl
|= ((vsi
->id
) << I40E_QTX_CTL_VFVM_INDX_SHIFT
) &
3159 I40E_QTX_CTL_VFVM_INDX_MASK
;
3161 qtx_ctl
= I40E_QTX_CTL_PF_QUEUE
;
3165 qtx_ctl
|= ((hw
->pf_id
<< I40E_QTX_CTL_PF_INDX_SHIFT
) &
3166 I40E_QTX_CTL_PF_INDX_MASK
);
3167 wr32(hw
, I40E_QTX_CTL(pf_q
), qtx_ctl
);
3170 /* cache tail off for easier writes later */
3171 ring
->tail
= hw
->hw_addr
+ I40E_QTX_TAIL(pf_q
);
3177 * i40e_configure_rx_ring - Configure a receive ring context
3178 * @ring: The Rx ring to configure
3180 * Configure the Rx descriptor ring in the HMC context.
3182 static int i40e_configure_rx_ring(struct i40e_ring
*ring
)
3184 struct i40e_vsi
*vsi
= ring
->vsi
;
3185 u32 chain_len
= vsi
->back
->hw
.func_caps
.rx_buf_chain_len
;
3186 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
3187 struct i40e_hw
*hw
= &vsi
->back
->hw
;
3188 struct i40e_hmc_obj_rxq rx_ctx
;
3189 i40e_status err
= 0;
3191 bitmap_zero(ring
->state
, __I40E_RING_STATE_NBITS
);
3193 /* clear the context structure first */
3194 memset(&rx_ctx
, 0, sizeof(rx_ctx
));
3196 ring
->rx_buf_len
= vsi
->rx_buf_len
;
3198 rx_ctx
.dbuff
= DIV_ROUND_UP(ring
->rx_buf_len
,
3199 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT
));
3201 rx_ctx
.base
= (ring
->dma
/ 128);
3202 rx_ctx
.qlen
= ring
->count
;
3204 /* use 32 byte descriptors */
3207 /* descriptor type is always zero
3210 rx_ctx
.hsplit_0
= 0;
3212 rx_ctx
.rxmax
= min_t(u16
, vsi
->max_frame
, chain_len
* ring
->rx_buf_len
);
3213 if (hw
->revision_id
== 0)
3214 rx_ctx
.lrxqthresh
= 0;
3216 rx_ctx
.lrxqthresh
= 1;
3217 rx_ctx
.crcstrip
= 1;
3219 /* this controls whether VLAN is stripped from inner headers */
3221 /* set the prefena field to 1 because the manual says to */
3224 /* clear the context in the HMC */
3225 err
= i40e_clear_lan_rx_queue_context(hw
, pf_q
);
3227 dev_info(&vsi
->back
->pdev
->dev
,
3228 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
3229 ring
->queue_index
, pf_q
, err
);
3233 /* set the context in the HMC */
3234 err
= i40e_set_lan_rx_queue_context(hw
, pf_q
, &rx_ctx
);
3236 dev_info(&vsi
->back
->pdev
->dev
,
3237 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
3238 ring
->queue_index
, pf_q
, err
);
3242 /* configure Rx buffer alignment */
3243 if (!vsi
->netdev
|| (vsi
->back
->flags
& I40E_FLAG_LEGACY_RX
))
3244 clear_ring_build_skb_enabled(ring
);
3246 set_ring_build_skb_enabled(ring
);
3248 /* cache tail for quicker writes, and clear the reg before use */
3249 ring
->tail
= hw
->hw_addr
+ I40E_QRX_TAIL(pf_q
);
3250 writel(0, ring
->tail
);
3252 i40e_alloc_rx_buffers(ring
, I40E_DESC_UNUSED(ring
));
3258 * i40e_vsi_configure_tx - Configure the VSI for Tx
3259 * @vsi: VSI structure describing this set of rings and resources
3261 * Configure the Tx VSI for operation.
3263 static int i40e_vsi_configure_tx(struct i40e_vsi
*vsi
)
3268 for (i
= 0; (i
< vsi
->num_queue_pairs
) && !err
; i
++)
3269 err
= i40e_configure_tx_ring(vsi
->tx_rings
[i
]);
3271 if (!i40e_enabled_xdp_vsi(vsi
))
3274 for (i
= 0; (i
< vsi
->num_queue_pairs
) && !err
; i
++)
3275 err
= i40e_configure_tx_ring(vsi
->xdp_rings
[i
]);
3281 * i40e_vsi_configure_rx - Configure the VSI for Rx
3282 * @vsi: the VSI being configured
3284 * Configure the Rx VSI for operation.
3286 static int i40e_vsi_configure_rx(struct i40e_vsi
*vsi
)
3291 if (!vsi
->netdev
|| (vsi
->back
->flags
& I40E_FLAG_LEGACY_RX
)) {
3292 vsi
->max_frame
= I40E_MAX_RXBUFFER
;
3293 vsi
->rx_buf_len
= I40E_RXBUFFER_2048
;
3294 #if (PAGE_SIZE < 8192)
3295 } else if (!I40E_2K_TOO_SMALL_WITH_PADDING
&&
3296 (vsi
->netdev
->mtu
<= ETH_DATA_LEN
)) {
3297 vsi
->max_frame
= I40E_RXBUFFER_1536
- NET_IP_ALIGN
;
3298 vsi
->rx_buf_len
= I40E_RXBUFFER_1536
- NET_IP_ALIGN
;
3301 vsi
->max_frame
= I40E_MAX_RXBUFFER
;
3302 vsi
->rx_buf_len
= (PAGE_SIZE
< 8192) ? I40E_RXBUFFER_3072
:
3306 /* set up individual rings */
3307 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
3308 err
= i40e_configure_rx_ring(vsi
->rx_rings
[i
]);
3314 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
3315 * @vsi: ptr to the VSI
3317 static void i40e_vsi_config_dcb_rings(struct i40e_vsi
*vsi
)
3319 struct i40e_ring
*tx_ring
, *rx_ring
;
3320 u16 qoffset
, qcount
;
3323 if (!(vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
3324 /* Reset the TC information */
3325 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
3326 rx_ring
= vsi
->rx_rings
[i
];
3327 tx_ring
= vsi
->tx_rings
[i
];
3328 rx_ring
->dcb_tc
= 0;
3329 tx_ring
->dcb_tc
= 0;
3334 for (n
= 0; n
< I40E_MAX_TRAFFIC_CLASS
; n
++) {
3335 if (!(vsi
->tc_config
.enabled_tc
& BIT_ULL(n
)))
3338 qoffset
= vsi
->tc_config
.tc_info
[n
].qoffset
;
3339 qcount
= vsi
->tc_config
.tc_info
[n
].qcount
;
3340 for (i
= qoffset
; i
< (qoffset
+ qcount
); i
++) {
3341 rx_ring
= vsi
->rx_rings
[i
];
3342 tx_ring
= vsi
->tx_rings
[i
];
3343 rx_ring
->dcb_tc
= n
;
3344 tx_ring
->dcb_tc
= n
;
3350 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
3351 * @vsi: ptr to the VSI
3353 static void i40e_set_vsi_rx_mode(struct i40e_vsi
*vsi
)
3356 i40e_set_rx_mode(vsi
->netdev
);
3360 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
3361 * @vsi: Pointer to the targeted VSI
3363 * This function replays the hlist on the hw where all the SB Flow Director
3364 * filters were saved.
3366 static void i40e_fdir_filter_restore(struct i40e_vsi
*vsi
)
3368 struct i40e_fdir_filter
*filter
;
3369 struct i40e_pf
*pf
= vsi
->back
;
3370 struct hlist_node
*node
;
3372 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
3375 /* Reset FDir counters as we're replaying all existing filters */
3376 pf
->fd_tcp4_filter_cnt
= 0;
3377 pf
->fd_udp4_filter_cnt
= 0;
3378 pf
->fd_sctp4_filter_cnt
= 0;
3379 pf
->fd_ip4_filter_cnt
= 0;
3381 hlist_for_each_entry_safe(filter
, node
,
3382 &pf
->fdir_filter_list
, fdir_node
) {
3383 i40e_add_del_fdir(vsi
, filter
, true);
3388 * i40e_vsi_configure - Set up the VSI for action
3389 * @vsi: the VSI being configured
3391 static int i40e_vsi_configure(struct i40e_vsi
*vsi
)
3395 i40e_set_vsi_rx_mode(vsi
);
3396 i40e_restore_vlan(vsi
);
3397 i40e_vsi_config_dcb_rings(vsi
);
3398 err
= i40e_vsi_configure_tx(vsi
);
3400 err
= i40e_vsi_configure_rx(vsi
);
3406 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
3407 * @vsi: the VSI being configured
3409 static void i40e_vsi_configure_msix(struct i40e_vsi
*vsi
)
3411 bool has_xdp
= i40e_enabled_xdp_vsi(vsi
);
3412 struct i40e_pf
*pf
= vsi
->back
;
3413 struct i40e_hw
*hw
= &pf
->hw
;
3418 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
3419 * and PFINT_LNKLSTn registers, e.g.:
3420 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
3422 qp
= vsi
->base_queue
;
3423 vector
= vsi
->base_vector
;
3424 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vector
++) {
3425 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[i
];
3427 q_vector
->rx
.next_update
= jiffies
+ 1;
3428 q_vector
->rx
.target_itr
=
3429 ITR_TO_REG(vsi
->rx_rings
[i
]->itr_setting
);
3430 wr32(hw
, I40E_PFINT_ITRN(I40E_RX_ITR
, vector
- 1),
3431 q_vector
->rx
.target_itr
);
3432 q_vector
->rx
.current_itr
= q_vector
->rx
.target_itr
;
3434 q_vector
->tx
.next_update
= jiffies
+ 1;
3435 q_vector
->tx
.target_itr
=
3436 ITR_TO_REG(vsi
->tx_rings
[i
]->itr_setting
);
3437 wr32(hw
, I40E_PFINT_ITRN(I40E_TX_ITR
, vector
- 1),
3438 q_vector
->tx
.target_itr
);
3439 q_vector
->tx
.current_itr
= q_vector
->tx
.target_itr
;
3441 wr32(hw
, I40E_PFINT_RATEN(vector
- 1),
3442 i40e_intrl_usec_to_reg(vsi
->int_rate_limit
));
3444 /* Linked list for the queuepairs assigned to this vector */
3445 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), qp
);
3446 for (q
= 0; q
< q_vector
->num_ringpairs
; q
++) {
3447 u32 nextqp
= has_xdp
? qp
+ vsi
->alloc_queue_pairs
: qp
;
3450 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3451 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
3452 (vector
<< I40E_QINT_RQCTL_MSIX_INDX_SHIFT
) |
3453 (nextqp
<< I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT
) |
3454 (I40E_QUEUE_TYPE_TX
<<
3455 I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT
);
3457 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
3460 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3461 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
3462 (vector
<< I40E_QINT_TQCTL_MSIX_INDX_SHIFT
) |
3463 (qp
<< I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
) |
3464 (I40E_QUEUE_TYPE_TX
<<
3465 I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
3467 wr32(hw
, I40E_QINT_TQCTL(nextqp
), val
);
3470 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3471 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
3472 (vector
<< I40E_QINT_TQCTL_MSIX_INDX_SHIFT
) |
3473 ((qp
+ 1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
) |
3474 (I40E_QUEUE_TYPE_RX
<<
3475 I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
3477 /* Terminate the linked list */
3478 if (q
== (q_vector
->num_ringpairs
- 1))
3479 val
|= (I40E_QUEUE_END_OF_LIST
<<
3480 I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
3482 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
3491 * i40e_enable_misc_int_causes - enable the non-queue interrupts
3492 * @pf: pointer to private device data structure
3494 static void i40e_enable_misc_int_causes(struct i40e_pf
*pf
)
3496 struct i40e_hw
*hw
= &pf
->hw
;
3499 /* clear things first */
3500 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0); /* disable all */
3501 rd32(hw
, I40E_PFINT_ICR0
); /* read to clear */
3503 val
= I40E_PFINT_ICR0_ENA_ECC_ERR_MASK
|
3504 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
|
3505 I40E_PFINT_ICR0_ENA_GRST_MASK
|
3506 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK
|
3507 I40E_PFINT_ICR0_ENA_GPIO_MASK
|
3508 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK
|
3509 I40E_PFINT_ICR0_ENA_VFLR_MASK
|
3510 I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
3512 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
)
3513 val
|= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
;
3515 if (pf
->flags
& I40E_FLAG_PTP
)
3516 val
|= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
3518 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
3520 /* SW_ITR_IDX = 0, but don't change INTENA */
3521 wr32(hw
, I40E_PFINT_DYN_CTL0
, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK
|
3522 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK
);
3524 /* OTHER_ITR_IDX = 0 */
3525 wr32(hw
, I40E_PFINT_STAT_CTL0
, 0);
3529 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
3530 * @vsi: the VSI being configured
3532 static void i40e_configure_msi_and_legacy(struct i40e_vsi
*vsi
)
3534 u32 nextqp
= i40e_enabled_xdp_vsi(vsi
) ? vsi
->alloc_queue_pairs
: 0;
3535 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[0];
3536 struct i40e_pf
*pf
= vsi
->back
;
3537 struct i40e_hw
*hw
= &pf
->hw
;
3540 /* set the ITR configuration */
3541 q_vector
->rx
.next_update
= jiffies
+ 1;
3542 q_vector
->rx
.target_itr
= ITR_TO_REG(vsi
->rx_rings
[0]->itr_setting
);
3543 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), q_vector
->rx
.target_itr
);
3544 q_vector
->rx
.current_itr
= q_vector
->rx
.target_itr
;
3545 q_vector
->tx
.next_update
= jiffies
+ 1;
3546 q_vector
->tx
.target_itr
= ITR_TO_REG(vsi
->tx_rings
[0]->itr_setting
);
3547 wr32(hw
, I40E_PFINT_ITR0(I40E_TX_ITR
), q_vector
->tx
.target_itr
);
3548 q_vector
->tx
.current_itr
= q_vector
->tx
.target_itr
;
3550 i40e_enable_misc_int_causes(pf
);
3552 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
3553 wr32(hw
, I40E_PFINT_LNKLST0
, 0);
3555 /* Associate the queue pair to the vector and enable the queue int */
3556 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3557 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
3558 (nextqp
<< I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT
)|
3559 (I40E_QUEUE_TYPE_TX
<< I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
3561 wr32(hw
, I40E_QINT_RQCTL(0), val
);
3563 if (i40e_enabled_xdp_vsi(vsi
)) {
3564 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3565 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
)|
3567 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
3569 wr32(hw
, I40E_QINT_TQCTL(nextqp
), val
);
3572 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3573 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
3574 (I40E_QUEUE_END_OF_LIST
<< I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
3576 wr32(hw
, I40E_QINT_TQCTL(0), val
);
3581 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
3582 * @pf: board private structure
3584 void i40e_irq_dynamic_disable_icr0(struct i40e_pf
*pf
)
3586 struct i40e_hw
*hw
= &pf
->hw
;
3588 wr32(hw
, I40E_PFINT_DYN_CTL0
,
3589 I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
);
3594 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
3595 * @pf: board private structure
3597 void i40e_irq_dynamic_enable_icr0(struct i40e_pf
*pf
)
3599 struct i40e_hw
*hw
= &pf
->hw
;
3602 val
= I40E_PFINT_DYN_CTL0_INTENA_MASK
|
3603 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK
|
3604 (I40E_ITR_NONE
<< I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT
);
3606 wr32(hw
, I40E_PFINT_DYN_CTL0
, val
);
3611 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
3612 * @irq: interrupt number
3613 * @data: pointer to a q_vector
3615 static irqreturn_t
i40e_msix_clean_rings(int irq
, void *data
)
3617 struct i40e_q_vector
*q_vector
= data
;
3619 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
3622 napi_schedule_irqoff(&q_vector
->napi
);
3628 * i40e_irq_affinity_notify - Callback for affinity changes
3629 * @notify: context as to what irq was changed
3630 * @mask: the new affinity mask
3632 * This is a callback function used by the irq_set_affinity_notifier function
3633 * so that we may register to receive changes to the irq affinity masks.
3635 static void i40e_irq_affinity_notify(struct irq_affinity_notify
*notify
,
3636 const cpumask_t
*mask
)
3638 struct i40e_q_vector
*q_vector
=
3639 container_of(notify
, struct i40e_q_vector
, affinity_notify
);
3641 cpumask_copy(&q_vector
->affinity_mask
, mask
);
3645 * i40e_irq_affinity_release - Callback for affinity notifier release
3646 * @ref: internal core kernel usage
3648 * This is a callback function used by the irq_set_affinity_notifier function
3649 * to inform the current notification subscriber that they will no longer
3650 * receive notifications.
3652 static void i40e_irq_affinity_release(struct kref
*ref
) {}
3655 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3656 * @vsi: the VSI being configured
3657 * @basename: name for the vector
3659 * Allocates MSI-X vectors and requests interrupts from the kernel.
3661 static int i40e_vsi_request_irq_msix(struct i40e_vsi
*vsi
, char *basename
)
3663 int q_vectors
= vsi
->num_q_vectors
;
3664 struct i40e_pf
*pf
= vsi
->back
;
3665 int base
= vsi
->base_vector
;
3672 for (vector
= 0; vector
< q_vectors
; vector
++) {
3673 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[vector
];
3675 irq_num
= pf
->msix_entries
[base
+ vector
].vector
;
3677 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
3678 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3679 "%s-%s-%d", basename
, "TxRx", rx_int_idx
++);
3681 } else if (q_vector
->rx
.ring
) {
3682 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3683 "%s-%s-%d", basename
, "rx", rx_int_idx
++);
3684 } else if (q_vector
->tx
.ring
) {
3685 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3686 "%s-%s-%d", basename
, "tx", tx_int_idx
++);
3688 /* skip this unused q_vector */
3691 err
= request_irq(irq_num
,
3697 dev_info(&pf
->pdev
->dev
,
3698 "MSIX request_irq failed, error: %d\n", err
);
3699 goto free_queue_irqs
;
3702 /* register for affinity change notifications */
3703 q_vector
->affinity_notify
.notify
= i40e_irq_affinity_notify
;
3704 q_vector
->affinity_notify
.release
= i40e_irq_affinity_release
;
3705 irq_set_affinity_notifier(irq_num
, &q_vector
->affinity_notify
);
3706 /* Spread affinity hints out across online CPUs.
3708 * get_cpu_mask returns a static constant mask with
3709 * a permanent lifetime so it's ok to pass to
3710 * irq_set_affinity_hint without making a copy.
3712 cpu
= cpumask_local_spread(q_vector
->v_idx
, -1);
3713 irq_set_affinity_hint(irq_num
, get_cpu_mask(cpu
));
3716 vsi
->irqs_ready
= true;
3722 irq_num
= pf
->msix_entries
[base
+ vector
].vector
;
3723 irq_set_affinity_notifier(irq_num
, NULL
);
3724 irq_set_affinity_hint(irq_num
, NULL
);
3725 free_irq(irq_num
, &vsi
->q_vectors
[vector
]);
3731 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3732 * @vsi: the VSI being un-configured
3734 static void i40e_vsi_disable_irq(struct i40e_vsi
*vsi
)
3736 struct i40e_pf
*pf
= vsi
->back
;
3737 struct i40e_hw
*hw
= &pf
->hw
;
3738 int base
= vsi
->base_vector
;
3741 /* disable interrupt causation from each queue */
3742 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
3745 val
= rd32(hw
, I40E_QINT_TQCTL(vsi
->tx_rings
[i
]->reg_idx
));
3746 val
&= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK
;
3747 wr32(hw
, I40E_QINT_TQCTL(vsi
->tx_rings
[i
]->reg_idx
), val
);
3749 val
= rd32(hw
, I40E_QINT_RQCTL(vsi
->rx_rings
[i
]->reg_idx
));
3750 val
&= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK
;
3751 wr32(hw
, I40E_QINT_RQCTL(vsi
->rx_rings
[i
]->reg_idx
), val
);
3753 if (!i40e_enabled_xdp_vsi(vsi
))
3755 wr32(hw
, I40E_QINT_TQCTL(vsi
->xdp_rings
[i
]->reg_idx
), 0);
3758 /* disable each interrupt */
3759 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3760 for (i
= vsi
->base_vector
;
3761 i
< (vsi
->num_q_vectors
+ vsi
->base_vector
); i
++)
3762 wr32(hw
, I40E_PFINT_DYN_CTLN(i
- 1), 0);
3765 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3766 synchronize_irq(pf
->msix_entries
[i
+ base
].vector
);
3768 /* Legacy and MSI mode - this stops all interrupt handling */
3769 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0);
3770 wr32(hw
, I40E_PFINT_DYN_CTL0
, 0);
3772 synchronize_irq(pf
->pdev
->irq
);
3777 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3778 * @vsi: the VSI being configured
3780 static int i40e_vsi_enable_irq(struct i40e_vsi
*vsi
)
3782 struct i40e_pf
*pf
= vsi
->back
;
3785 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3786 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3787 i40e_irq_dynamic_enable(vsi
, i
);
3789 i40e_irq_dynamic_enable_icr0(pf
);
3792 i40e_flush(&pf
->hw
);
3797 * i40e_free_misc_vector - Free the vector that handles non-queue events
3798 * @pf: board private structure
3800 static void i40e_free_misc_vector(struct i40e_pf
*pf
)
3803 wr32(&pf
->hw
, I40E_PFINT_ICR0_ENA
, 0);
3804 i40e_flush(&pf
->hw
);
3806 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
&& pf
->msix_entries
) {
3807 synchronize_irq(pf
->msix_entries
[0].vector
);
3808 free_irq(pf
->msix_entries
[0].vector
, pf
);
3809 clear_bit(__I40E_MISC_IRQ_REQUESTED
, pf
->state
);
3814 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3815 * @irq: interrupt number
3816 * @data: pointer to a q_vector
3818 * This is the handler used for all MSI/Legacy interrupts, and deals
3819 * with both queue and non-queue interrupts. This is also used in
3820 * MSIX mode to handle the non-queue interrupts.
3822 static irqreturn_t
i40e_intr(int irq
, void *data
)
3824 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
3825 struct i40e_hw
*hw
= &pf
->hw
;
3826 irqreturn_t ret
= IRQ_NONE
;
3827 u32 icr0
, icr0_remaining
;
3830 icr0
= rd32(hw
, I40E_PFINT_ICR0
);
3831 ena_mask
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
3833 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
3834 if ((icr0
& I40E_PFINT_ICR0_INTEVENT_MASK
) == 0)
3837 /* if interrupt but no bits showing, must be SWINT */
3838 if (((icr0
& ~I40E_PFINT_ICR0_INTEVENT_MASK
) == 0) ||
3839 (icr0
& I40E_PFINT_ICR0_SWINT_MASK
))
3842 if ((pf
->flags
& I40E_FLAG_IWARP_ENABLED
) &&
3843 (icr0
& I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
)) {
3844 ena_mask
&= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
;
3845 dev_dbg(&pf
->pdev
->dev
, "cleared PE_CRITERR\n");
3846 set_bit(__I40E_CORE_RESET_REQUESTED
, pf
->state
);
3849 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
3850 if (icr0
& I40E_PFINT_ICR0_QUEUE_0_MASK
) {
3851 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
3852 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[0];
3854 /* We do not have a way to disarm Queue causes while leaving
3855 * interrupt enabled for all other causes, ideally
3856 * interrupt should be disabled while we are in NAPI but
3857 * this is not a performance path and napi_schedule()
3858 * can deal with rescheduling.
3860 if (!test_bit(__I40E_DOWN
, pf
->state
))
3861 napi_schedule_irqoff(&q_vector
->napi
);
3864 if (icr0
& I40E_PFINT_ICR0_ADMINQ_MASK
) {
3865 ena_mask
&= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
3866 set_bit(__I40E_ADMINQ_EVENT_PENDING
, pf
->state
);
3867 i40e_debug(&pf
->hw
, I40E_DEBUG_NVM
, "AdminQ event\n");
3870 if (icr0
& I40E_PFINT_ICR0_MAL_DETECT_MASK
) {
3871 ena_mask
&= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
3872 set_bit(__I40E_MDD_EVENT_PENDING
, pf
->state
);
3875 if (icr0
& I40E_PFINT_ICR0_VFLR_MASK
) {
3876 ena_mask
&= ~I40E_PFINT_ICR0_ENA_VFLR_MASK
;
3877 set_bit(__I40E_VFLR_EVENT_PENDING
, pf
->state
);
3880 if (icr0
& I40E_PFINT_ICR0_GRST_MASK
) {
3881 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
))
3882 set_bit(__I40E_RESET_INTR_RECEIVED
, pf
->state
);
3883 ena_mask
&= ~I40E_PFINT_ICR0_ENA_GRST_MASK
;
3884 val
= rd32(hw
, I40E_GLGEN_RSTAT
);
3885 val
= (val
& I40E_GLGEN_RSTAT_RESET_TYPE_MASK
)
3886 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT
;
3887 if (val
== I40E_RESET_CORER
) {
3889 } else if (val
== I40E_RESET_GLOBR
) {
3891 } else if (val
== I40E_RESET_EMPR
) {
3893 set_bit(__I40E_EMP_RESET_INTR_RECEIVED
, pf
->state
);
3897 if (icr0
& I40E_PFINT_ICR0_HMC_ERR_MASK
) {
3898 icr0
&= ~I40E_PFINT_ICR0_HMC_ERR_MASK
;
3899 dev_info(&pf
->pdev
->dev
, "HMC error interrupt\n");
3900 dev_info(&pf
->pdev
->dev
, "HMC error info 0x%x, HMC error data 0x%x\n",
3901 rd32(hw
, I40E_PFHMC_ERRORINFO
),
3902 rd32(hw
, I40E_PFHMC_ERRORDATA
));
3905 if (icr0
& I40E_PFINT_ICR0_TIMESYNC_MASK
) {
3906 u32 prttsyn_stat
= rd32(hw
, I40E_PRTTSYN_STAT_0
);
3908 if (prttsyn_stat
& I40E_PRTTSYN_STAT_0_TXTIME_MASK
) {
3909 icr0
&= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
3910 i40e_ptp_tx_hwtstamp(pf
);
3914 /* If a critical error is pending we have no choice but to reset the
3916 * Report and mask out any remaining unexpected interrupts.
3918 icr0_remaining
= icr0
& ena_mask
;
3919 if (icr0_remaining
) {
3920 dev_info(&pf
->pdev
->dev
, "unhandled interrupt icr0=0x%08x\n",
3922 if ((icr0_remaining
& I40E_PFINT_ICR0_PE_CRITERR_MASK
) ||
3923 (icr0_remaining
& I40E_PFINT_ICR0_PCI_EXCEPTION_MASK
) ||
3924 (icr0_remaining
& I40E_PFINT_ICR0_ECC_ERR_MASK
)) {
3925 dev_info(&pf
->pdev
->dev
, "device will be reset\n");
3926 set_bit(__I40E_PF_RESET_REQUESTED
, pf
->state
);
3927 i40e_service_event_schedule(pf
);
3929 ena_mask
&= ~icr0_remaining
;
3934 /* re-enable interrupt causes */
3935 wr32(hw
, I40E_PFINT_ICR0_ENA
, ena_mask
);
3936 if (!test_bit(__I40E_DOWN
, pf
->state
)) {
3937 i40e_service_event_schedule(pf
);
3938 i40e_irq_dynamic_enable_icr0(pf
);
3945 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3946 * @tx_ring: tx ring to clean
3947 * @budget: how many cleans we're allowed
3949 * Returns true if there's any budget left (e.g. the clean is finished)
3951 static bool i40e_clean_fdir_tx_irq(struct i40e_ring
*tx_ring
, int budget
)
3953 struct i40e_vsi
*vsi
= tx_ring
->vsi
;
3954 u16 i
= tx_ring
->next_to_clean
;
3955 struct i40e_tx_buffer
*tx_buf
;
3956 struct i40e_tx_desc
*tx_desc
;
3958 tx_buf
= &tx_ring
->tx_bi
[i
];
3959 tx_desc
= I40E_TX_DESC(tx_ring
, i
);
3960 i
-= tx_ring
->count
;
3963 struct i40e_tx_desc
*eop_desc
= tx_buf
->next_to_watch
;
3965 /* if next_to_watch is not set then there is no work pending */
3969 /* prevent any other reads prior to eop_desc */
3972 /* if the descriptor isn't done, no work yet to do */
3973 if (!(eop_desc
->cmd_type_offset_bsz
&
3974 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE
)))
3977 /* clear next_to_watch to prevent false hangs */
3978 tx_buf
->next_to_watch
= NULL
;
3980 tx_desc
->buffer_addr
= 0;
3981 tx_desc
->cmd_type_offset_bsz
= 0;
3982 /* move past filter desc */
3987 i
-= tx_ring
->count
;
3988 tx_buf
= tx_ring
->tx_bi
;
3989 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
3991 /* unmap skb header data */
3992 dma_unmap_single(tx_ring
->dev
,
3993 dma_unmap_addr(tx_buf
, dma
),
3994 dma_unmap_len(tx_buf
, len
),
3996 if (tx_buf
->tx_flags
& I40E_TX_FLAGS_FD_SB
)
3997 kfree(tx_buf
->raw_buf
);
3999 tx_buf
->raw_buf
= NULL
;
4000 tx_buf
->tx_flags
= 0;
4001 tx_buf
->next_to_watch
= NULL
;
4002 dma_unmap_len_set(tx_buf
, len
, 0);
4003 tx_desc
->buffer_addr
= 0;
4004 tx_desc
->cmd_type_offset_bsz
= 0;
4006 /* move us past the eop_desc for start of next FD desc */
4011 i
-= tx_ring
->count
;
4012 tx_buf
= tx_ring
->tx_bi
;
4013 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
4016 /* update budget accounting */
4018 } while (likely(budget
));
4020 i
+= tx_ring
->count
;
4021 tx_ring
->next_to_clean
= i
;
4023 if (vsi
->back
->flags
& I40E_FLAG_MSIX_ENABLED
)
4024 i40e_irq_dynamic_enable(vsi
, tx_ring
->q_vector
->v_idx
);
4030 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
4031 * @irq: interrupt number
4032 * @data: pointer to a q_vector
4034 static irqreturn_t
i40e_fdir_clean_ring(int irq
, void *data
)
4036 struct i40e_q_vector
*q_vector
= data
;
4037 struct i40e_vsi
*vsi
;
4039 if (!q_vector
->tx
.ring
)
4042 vsi
= q_vector
->tx
.ring
->vsi
;
4043 i40e_clean_fdir_tx_irq(q_vector
->tx
.ring
, vsi
->work_limit
);
4049 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
4050 * @vsi: the VSI being configured
4051 * @v_idx: vector index
4052 * @qp_idx: queue pair index
4054 static void i40e_map_vector_to_qp(struct i40e_vsi
*vsi
, int v_idx
, int qp_idx
)
4056 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
4057 struct i40e_ring
*tx_ring
= vsi
->tx_rings
[qp_idx
];
4058 struct i40e_ring
*rx_ring
= vsi
->rx_rings
[qp_idx
];
4060 tx_ring
->q_vector
= q_vector
;
4061 tx_ring
->next
= q_vector
->tx
.ring
;
4062 q_vector
->tx
.ring
= tx_ring
;
4063 q_vector
->tx
.count
++;
4065 /* Place XDP Tx ring in the same q_vector ring list as regular Tx */
4066 if (i40e_enabled_xdp_vsi(vsi
)) {
4067 struct i40e_ring
*xdp_ring
= vsi
->xdp_rings
[qp_idx
];
4069 xdp_ring
->q_vector
= q_vector
;
4070 xdp_ring
->next
= q_vector
->tx
.ring
;
4071 q_vector
->tx
.ring
= xdp_ring
;
4072 q_vector
->tx
.count
++;
4075 rx_ring
->q_vector
= q_vector
;
4076 rx_ring
->next
= q_vector
->rx
.ring
;
4077 q_vector
->rx
.ring
= rx_ring
;
4078 q_vector
->rx
.count
++;
4082 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
4083 * @vsi: the VSI being configured
4085 * This function maps descriptor rings to the queue-specific vectors
4086 * we were allotted through the MSI-X enabling code. Ideally, we'd have
4087 * one vector per queue pair, but on a constrained vector budget, we
4088 * group the queue pairs as "efficiently" as possible.
4090 static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi
*vsi
)
4092 int qp_remaining
= vsi
->num_queue_pairs
;
4093 int q_vectors
= vsi
->num_q_vectors
;
4098 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
4099 * group them so there are multiple queues per vector.
4100 * It is also important to go through all the vectors available to be
4101 * sure that if we don't use all the vectors, that the remaining vectors
4102 * are cleared. This is especially important when decreasing the
4103 * number of queues in use.
4105 for (; v_start
< q_vectors
; v_start
++) {
4106 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_start
];
4108 num_ringpairs
= DIV_ROUND_UP(qp_remaining
, q_vectors
- v_start
);
4110 q_vector
->num_ringpairs
= num_ringpairs
;
4111 q_vector
->reg_idx
= q_vector
->v_idx
+ vsi
->base_vector
- 1;
4113 q_vector
->rx
.count
= 0;
4114 q_vector
->tx
.count
= 0;
4115 q_vector
->rx
.ring
= NULL
;
4116 q_vector
->tx
.ring
= NULL
;
4118 while (num_ringpairs
--) {
4119 i40e_map_vector_to_qp(vsi
, v_start
, qp_idx
);
4127 * i40e_vsi_request_irq - Request IRQ from the OS
4128 * @vsi: the VSI being configured
4129 * @basename: name for the vector
4131 static int i40e_vsi_request_irq(struct i40e_vsi
*vsi
, char *basename
)
4133 struct i40e_pf
*pf
= vsi
->back
;
4136 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
4137 err
= i40e_vsi_request_irq_msix(vsi
, basename
);
4138 else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
)
4139 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, 0,
4142 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, IRQF_SHARED
,
4146 dev_info(&pf
->pdev
->dev
, "request_irq failed, Error %d\n", err
);
4151 #ifdef CONFIG_NET_POLL_CONTROLLER
4153 * i40e_netpoll - A Polling 'interrupt' handler
4154 * @netdev: network interface device structure
4156 * This is used by netconsole to send skbs without having to re-enable
4157 * interrupts. It's not called while the normal interrupt routine is executing.
4159 static void i40e_netpoll(struct net_device
*netdev
)
4161 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
4162 struct i40e_vsi
*vsi
= np
->vsi
;
4163 struct i40e_pf
*pf
= vsi
->back
;
4166 /* if interface is down do nothing */
4167 if (test_bit(__I40E_VSI_DOWN
, vsi
->state
))
4170 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
4171 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
4172 i40e_msix_clean_rings(0, vsi
->q_vectors
[i
]);
4174 i40e_intr(pf
->pdev
->irq
, netdev
);
4179 #define I40E_QTX_ENA_WAIT_COUNT 50
4182 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
4183 * @pf: the PF being configured
4184 * @pf_q: the PF queue
4185 * @enable: enable or disable state of the queue
4187 * This routine will wait for the given Tx queue of the PF to reach the
4188 * enabled or disabled state.
4189 * Returns -ETIMEDOUT in case of failing to reach the requested state after
4190 * multiple retries; else will return 0 in case of success.
4192 static int i40e_pf_txq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
4197 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
4198 tx_reg
= rd32(&pf
->hw
, I40E_QTX_ENA(pf_q
));
4199 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
4202 usleep_range(10, 20);
4204 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
4211 * i40e_control_tx_q - Start or stop a particular Tx queue
4212 * @pf: the PF structure
4213 * @pf_q: the PF queue to configure
4214 * @enable: start or stop the queue
4216 * This function enables or disables a single queue. Note that any delay
4217 * required after the operation is expected to be handled by the caller of
4220 static void i40e_control_tx_q(struct i40e_pf
*pf
, int pf_q
, bool enable
)
4222 struct i40e_hw
*hw
= &pf
->hw
;
4226 /* warn the TX unit of coming changes */
4227 i40e_pre_tx_queue_cfg(&pf
->hw
, pf_q
, enable
);
4229 usleep_range(10, 20);
4231 for (i
= 0; i
< I40E_QTX_ENA_WAIT_COUNT
; i
++) {
4232 tx_reg
= rd32(hw
, I40E_QTX_ENA(pf_q
));
4233 if (((tx_reg
>> I40E_QTX_ENA_QENA_REQ_SHIFT
) & 1) ==
4234 ((tx_reg
>> I40E_QTX_ENA_QENA_STAT_SHIFT
) & 1))
4236 usleep_range(1000, 2000);
4239 /* Skip if the queue is already in the requested state */
4240 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
4243 /* turn on/off the queue */
4245 wr32(hw
, I40E_QTX_HEAD(pf_q
), 0);
4246 tx_reg
|= I40E_QTX_ENA_QENA_REQ_MASK
;
4248 tx_reg
&= ~I40E_QTX_ENA_QENA_REQ_MASK
;
4251 wr32(hw
, I40E_QTX_ENA(pf_q
), tx_reg
);
4255 * i40e_control_wait_tx_q - Start/stop Tx queue and wait for completion
4257 * @pf: the PF structure
4258 * @pf_q: the PF queue to configure
4259 * @is_xdp: true if the queue is used for XDP
4260 * @enable: start or stop the queue
4262 int i40e_control_wait_tx_q(int seid
, struct i40e_pf
*pf
, int pf_q
,
4263 bool is_xdp
, bool enable
)
4267 i40e_control_tx_q(pf
, pf_q
, enable
);
4269 /* wait for the change to finish */
4270 ret
= i40e_pf_txq_wait(pf
, pf_q
, enable
);
4272 dev_info(&pf
->pdev
->dev
,
4273 "VSI seid %d %sTx ring %d %sable timeout\n",
4274 seid
, (is_xdp
? "XDP " : ""), pf_q
,
4275 (enable
? "en" : "dis"));
4282 * i40e_vsi_control_tx - Start or stop a VSI's rings
4283 * @vsi: the VSI being configured
4284 * @enable: start or stop the rings
4286 static int i40e_vsi_control_tx(struct i40e_vsi
*vsi
, bool enable
)
4288 struct i40e_pf
*pf
= vsi
->back
;
4289 int i
, pf_q
, ret
= 0;
4291 pf_q
= vsi
->base_queue
;
4292 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
4293 ret
= i40e_control_wait_tx_q(vsi
->seid
, pf
,
4295 false /*is xdp*/, enable
);
4299 if (!i40e_enabled_xdp_vsi(vsi
))
4302 ret
= i40e_control_wait_tx_q(vsi
->seid
, pf
,
4303 pf_q
+ vsi
->alloc_queue_pairs
,
4304 true /*is xdp*/, enable
);
4312 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
4313 * @pf: the PF being configured
4314 * @pf_q: the PF queue
4315 * @enable: enable or disable state of the queue
4317 * This routine will wait for the given Rx queue of the PF to reach the
4318 * enabled or disabled state.
4319 * Returns -ETIMEDOUT in case of failing to reach the requested state after
4320 * multiple retries; else will return 0 in case of success.
4322 static int i40e_pf_rxq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
4327 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
4328 rx_reg
= rd32(&pf
->hw
, I40E_QRX_ENA(pf_q
));
4329 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
4332 usleep_range(10, 20);
4334 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
4341 * i40e_control_rx_q - Start or stop a particular Rx queue
4342 * @pf: the PF structure
4343 * @pf_q: the PF queue to configure
4344 * @enable: start or stop the queue
4346 * This function enables or disables a single queue. Note that
4347 * any delay required after the operation is expected to be
4348 * handled by the caller of this function.
4350 static void i40e_control_rx_q(struct i40e_pf
*pf
, int pf_q
, bool enable
)
4352 struct i40e_hw
*hw
= &pf
->hw
;
4356 for (i
= 0; i
< I40E_QTX_ENA_WAIT_COUNT
; i
++) {
4357 rx_reg
= rd32(hw
, I40E_QRX_ENA(pf_q
));
4358 if (((rx_reg
>> I40E_QRX_ENA_QENA_REQ_SHIFT
) & 1) ==
4359 ((rx_reg
>> I40E_QRX_ENA_QENA_STAT_SHIFT
) & 1))
4361 usleep_range(1000, 2000);
4364 /* Skip if the queue is already in the requested state */
4365 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
4368 /* turn on/off the queue */
4370 rx_reg
|= I40E_QRX_ENA_QENA_REQ_MASK
;
4372 rx_reg
&= ~I40E_QRX_ENA_QENA_REQ_MASK
;
4374 wr32(hw
, I40E_QRX_ENA(pf_q
), rx_reg
);
4378 * i40e_control_wait_rx_q
4379 * @pf: the PF structure
4380 * @pf_q: queue being configured
4381 * @enable: start or stop the rings
4383 * This function enables or disables a single queue along with waiting
4384 * for the change to finish. The caller of this function should handle
4385 * the delays needed in the case of disabling queues.
4387 int i40e_control_wait_rx_q(struct i40e_pf
*pf
, int pf_q
, bool enable
)
4391 i40e_control_rx_q(pf
, pf_q
, enable
);
4393 /* wait for the change to finish */
4394 ret
= i40e_pf_rxq_wait(pf
, pf_q
, enable
);
4402 * i40e_vsi_control_rx - Start or stop a VSI's rings
4403 * @vsi: the VSI being configured
4404 * @enable: start or stop the rings
4406 static int i40e_vsi_control_rx(struct i40e_vsi
*vsi
, bool enable
)
4408 struct i40e_pf
*pf
= vsi
->back
;
4409 int i
, pf_q
, ret
= 0;
4411 pf_q
= vsi
->base_queue
;
4412 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
4413 ret
= i40e_control_wait_rx_q(pf
, pf_q
, enable
);
4415 dev_info(&pf
->pdev
->dev
,
4416 "VSI seid %d Rx ring %d %sable timeout\n",
4417 vsi
->seid
, pf_q
, (enable
? "en" : "dis"));
4422 /* Due to HW errata, on Rx disable only, the register can indicate done
4423 * before it really is. Needs 50ms to be sure
4432 * i40e_vsi_start_rings - Start a VSI's rings
4433 * @vsi: the VSI being configured
4435 int i40e_vsi_start_rings(struct i40e_vsi
*vsi
)
4439 /* do rx first for enable and last for disable */
4440 ret
= i40e_vsi_control_rx(vsi
, true);
4443 ret
= i40e_vsi_control_tx(vsi
, true);
4449 * i40e_vsi_stop_rings - Stop a VSI's rings
4450 * @vsi: the VSI being configured
4452 void i40e_vsi_stop_rings(struct i40e_vsi
*vsi
)
4454 /* When port TX is suspended, don't wait */
4455 if (test_bit(__I40E_PORT_SUSPENDED
, vsi
->back
->state
))
4456 return i40e_vsi_stop_rings_no_wait(vsi
);
4458 /* do rx first for enable and last for disable
4459 * Ignore return value, we need to shutdown whatever we can
4461 i40e_vsi_control_tx(vsi
, false);
4462 i40e_vsi_control_rx(vsi
, false);
4466 * i40e_vsi_stop_rings_no_wait - Stop a VSI's rings and do not delay
4467 * @vsi: the VSI being shutdown
4469 * This function stops all the rings for a VSI but does not delay to verify
4470 * that rings have been disabled. It is expected that the caller is shutting
4471 * down multiple VSIs at once and will delay together for all the VSIs after
4472 * initiating the shutdown. This is particularly useful for shutting down lots
4473 * of VFs together. Otherwise, a large delay can be incurred while configuring
4474 * each VSI in serial.
4476 void i40e_vsi_stop_rings_no_wait(struct i40e_vsi
*vsi
)
4478 struct i40e_pf
*pf
= vsi
->back
;
4481 pf_q
= vsi
->base_queue
;
4482 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
4483 i40e_control_tx_q(pf
, pf_q
, false);
4484 i40e_control_rx_q(pf
, pf_q
, false);
4489 * i40e_vsi_free_irq - Free the irq association with the OS
4490 * @vsi: the VSI being configured
4492 static void i40e_vsi_free_irq(struct i40e_vsi
*vsi
)
4494 struct i40e_pf
*pf
= vsi
->back
;
4495 struct i40e_hw
*hw
= &pf
->hw
;
4496 int base
= vsi
->base_vector
;
4500 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
4501 if (!vsi
->q_vectors
)
4504 if (!vsi
->irqs_ready
)
4507 vsi
->irqs_ready
= false;
4508 for (i
= 0; i
< vsi
->num_q_vectors
; i
++) {
4513 irq_num
= pf
->msix_entries
[vector
].vector
;
4515 /* free only the irqs that were actually requested */
4516 if (!vsi
->q_vectors
[i
] ||
4517 !vsi
->q_vectors
[i
]->num_ringpairs
)
4520 /* clear the affinity notifier in the IRQ descriptor */
4521 irq_set_affinity_notifier(irq_num
, NULL
);
4522 /* remove our suggested affinity mask for this IRQ */
4523 irq_set_affinity_hint(irq_num
, NULL
);
4524 synchronize_irq(irq_num
);
4525 free_irq(irq_num
, vsi
->q_vectors
[i
]);
4527 /* Tear down the interrupt queue link list
4529 * We know that they come in pairs and always
4530 * the Rx first, then the Tx. To clear the
4531 * link list, stick the EOL value into the
4532 * next_q field of the registers.
4534 val
= rd32(hw
, I40E_PFINT_LNKLSTN(vector
- 1));
4535 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
4536 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
4537 val
|= I40E_QUEUE_END_OF_LIST
4538 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
4539 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), val
);
4541 while (qp
!= I40E_QUEUE_END_OF_LIST
) {
4544 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
4546 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
4547 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
4548 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
4549 I40E_QINT_RQCTL_INTEVENT_MASK
);
4551 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
4552 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
4554 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
4556 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
4558 next
= (val
& I40E_QINT_TQCTL_NEXTQ_INDX_MASK
)
4559 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
;
4561 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
4562 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
4563 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
4564 I40E_QINT_TQCTL_INTEVENT_MASK
);
4566 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
4567 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
4569 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
4574 free_irq(pf
->pdev
->irq
, pf
);
4576 val
= rd32(hw
, I40E_PFINT_LNKLST0
);
4577 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
4578 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
4579 val
|= I40E_QUEUE_END_OF_LIST
4580 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT
;
4581 wr32(hw
, I40E_PFINT_LNKLST0
, val
);
4583 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
4584 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
4585 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
4586 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
4587 I40E_QINT_RQCTL_INTEVENT_MASK
);
4589 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
4590 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
4592 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
4594 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
4596 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
4597 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
4598 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
4599 I40E_QINT_TQCTL_INTEVENT_MASK
);
4601 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
4602 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
4604 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
4609 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
4610 * @vsi: the VSI being configured
4611 * @v_idx: Index of vector to be freed
4613 * This function frees the memory allocated to the q_vector. In addition if
4614 * NAPI is enabled it will delete any references to the NAPI struct prior
4615 * to freeing the q_vector.
4617 static void i40e_free_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
4619 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
4620 struct i40e_ring
*ring
;
4625 /* disassociate q_vector from rings */
4626 i40e_for_each_ring(ring
, q_vector
->tx
)
4627 ring
->q_vector
= NULL
;
4629 i40e_for_each_ring(ring
, q_vector
->rx
)
4630 ring
->q_vector
= NULL
;
4632 /* only VSI w/ an associated netdev is set up w/ NAPI */
4634 netif_napi_del(&q_vector
->napi
);
4636 vsi
->q_vectors
[v_idx
] = NULL
;
4638 kfree_rcu(q_vector
, rcu
);
4642 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
4643 * @vsi: the VSI being un-configured
4645 * This frees the memory allocated to the q_vectors and
4646 * deletes references to the NAPI struct.
4648 static void i40e_vsi_free_q_vectors(struct i40e_vsi
*vsi
)
4652 for (v_idx
= 0; v_idx
< vsi
->num_q_vectors
; v_idx
++)
4653 i40e_free_q_vector(vsi
, v_idx
);
4657 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
4658 * @pf: board private structure
4660 static void i40e_reset_interrupt_capability(struct i40e_pf
*pf
)
4662 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
4663 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
4664 pci_disable_msix(pf
->pdev
);
4665 kfree(pf
->msix_entries
);
4666 pf
->msix_entries
= NULL
;
4667 kfree(pf
->irq_pile
);
4668 pf
->irq_pile
= NULL
;
4669 } else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
) {
4670 pci_disable_msi(pf
->pdev
);
4672 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
);
4676 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
4677 * @pf: board private structure
4679 * We go through and clear interrupt specific resources and reset the structure
4680 * to pre-load conditions
4682 static void i40e_clear_interrupt_scheme(struct i40e_pf
*pf
)
4686 i40e_free_misc_vector(pf
);
4688 i40e_put_lump(pf
->irq_pile
, pf
->iwarp_base_vector
,
4689 I40E_IWARP_IRQ_PILE_ID
);
4691 i40e_put_lump(pf
->irq_pile
, 0, I40E_PILE_VALID_BIT
-1);
4692 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
4694 i40e_vsi_free_q_vectors(pf
->vsi
[i
]);
4695 i40e_reset_interrupt_capability(pf
);
4699 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
4700 * @vsi: the VSI being configured
4702 static void i40e_napi_enable_all(struct i40e_vsi
*vsi
)
4709 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++) {
4710 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[q_idx
];
4712 if (q_vector
->rx
.ring
|| q_vector
->tx
.ring
)
4713 napi_enable(&q_vector
->napi
);
4718 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4719 * @vsi: the VSI being configured
4721 static void i40e_napi_disable_all(struct i40e_vsi
*vsi
)
4728 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++) {
4729 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[q_idx
];
4731 if (q_vector
->rx
.ring
|| q_vector
->tx
.ring
)
4732 napi_disable(&q_vector
->napi
);
4737 * i40e_vsi_close - Shut down a VSI
4738 * @vsi: the vsi to be quelled
4740 static void i40e_vsi_close(struct i40e_vsi
*vsi
)
4742 struct i40e_pf
*pf
= vsi
->back
;
4743 if (!test_and_set_bit(__I40E_VSI_DOWN
, vsi
->state
))
4745 i40e_vsi_free_irq(vsi
);
4746 i40e_vsi_free_tx_resources(vsi
);
4747 i40e_vsi_free_rx_resources(vsi
);
4748 vsi
->current_netdev_flags
= 0;
4749 set_bit(__I40E_CLIENT_SERVICE_REQUESTED
, pf
->state
);
4750 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
))
4751 set_bit(__I40E_CLIENT_RESET
, pf
->state
);
4755 * i40e_quiesce_vsi - Pause a given VSI
4756 * @vsi: the VSI being paused
4758 static void i40e_quiesce_vsi(struct i40e_vsi
*vsi
)
4760 if (test_bit(__I40E_VSI_DOWN
, vsi
->state
))
4763 set_bit(__I40E_VSI_NEEDS_RESTART
, vsi
->state
);
4764 if (vsi
->netdev
&& netif_running(vsi
->netdev
))
4765 vsi
->netdev
->netdev_ops
->ndo_stop(vsi
->netdev
);
4767 i40e_vsi_close(vsi
);
4771 * i40e_unquiesce_vsi - Resume a given VSI
4772 * @vsi: the VSI being resumed
4774 static void i40e_unquiesce_vsi(struct i40e_vsi
*vsi
)
4776 if (!test_and_clear_bit(__I40E_VSI_NEEDS_RESTART
, vsi
->state
))
4779 if (vsi
->netdev
&& netif_running(vsi
->netdev
))
4780 vsi
->netdev
->netdev_ops
->ndo_open(vsi
->netdev
);
4782 i40e_vsi_open(vsi
); /* this clears the DOWN bit */
4786 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
4789 static void i40e_pf_quiesce_all_vsi(struct i40e_pf
*pf
)
4793 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4795 i40e_quiesce_vsi(pf
->vsi
[v
]);
4800 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
4803 static void i40e_pf_unquiesce_all_vsi(struct i40e_pf
*pf
)
4807 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4809 i40e_unquiesce_vsi(pf
->vsi
[v
]);
4814 * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
4815 * @vsi: the VSI being configured
4817 * Wait until all queues on a given VSI have been disabled.
4819 int i40e_vsi_wait_queues_disabled(struct i40e_vsi
*vsi
)
4821 struct i40e_pf
*pf
= vsi
->back
;
4824 pf_q
= vsi
->base_queue
;
4825 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
4826 /* Check and wait for the Tx queue */
4827 ret
= i40e_pf_txq_wait(pf
, pf_q
, false);
4829 dev_info(&pf
->pdev
->dev
,
4830 "VSI seid %d Tx ring %d disable timeout\n",
4835 if (!i40e_enabled_xdp_vsi(vsi
))
4838 /* Check and wait for the XDP Tx queue */
4839 ret
= i40e_pf_txq_wait(pf
, pf_q
+ vsi
->alloc_queue_pairs
,
4842 dev_info(&pf
->pdev
->dev
,
4843 "VSI seid %d XDP Tx ring %d disable timeout\n",
4848 /* Check and wait for the Rx queue */
4849 ret
= i40e_pf_rxq_wait(pf
, pf_q
, false);
4851 dev_info(&pf
->pdev
->dev
,
4852 "VSI seid %d Rx ring %d disable timeout\n",
4861 #ifdef CONFIG_I40E_DCB
4863 * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
4866 * This function waits for the queues to be in disabled state for all the
4867 * VSIs that are managed by this PF.
4869 static int i40e_pf_wait_queues_disabled(struct i40e_pf
*pf
)
4873 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
; v
++) {
4875 ret
= i40e_vsi_wait_queues_disabled(pf
->vsi
[v
]);
4887 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
4888 * @pf: pointer to PF
4890 * Get TC map for ISCSI PF type that will include iSCSI TC
4893 static u8
i40e_get_iscsi_tc_map(struct i40e_pf
*pf
)
4895 struct i40e_dcb_app_priority_table app
;
4896 struct i40e_hw
*hw
= &pf
->hw
;
4897 u8 enabled_tc
= 1; /* TC0 is always enabled */
4899 /* Get the iSCSI APP TLV */
4900 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4902 for (i
= 0; i
< dcbcfg
->numapps
; i
++) {
4903 app
= dcbcfg
->app
[i
];
4904 if (app
.selector
== I40E_APP_SEL_TCPIP
&&
4905 app
.protocolid
== I40E_APP_PROTOID_ISCSI
) {
4906 tc
= dcbcfg
->etscfg
.prioritytable
[app
.priority
];
4907 enabled_tc
|= BIT(tc
);
4916 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
4917 * @dcbcfg: the corresponding DCBx configuration structure
4919 * Return the number of TCs from given DCBx configuration
4921 static u8
i40e_dcb_get_num_tc(struct i40e_dcbx_config
*dcbcfg
)
4923 int i
, tc_unused
= 0;
4927 /* Scan the ETS Config Priority Table to find
4928 * traffic class enabled for a given priority
4929 * and create a bitmask of enabled TCs
4931 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++)
4932 num_tc
|= BIT(dcbcfg
->etscfg
.prioritytable
[i
]);
4934 /* Now scan the bitmask to check for
4935 * contiguous TCs starting with TC0
4937 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4938 if (num_tc
& BIT(i
)) {
4942 pr_err("Non-contiguous TC - Disabling DCB\n");
4950 /* There is always at least TC0 */
4958 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
4959 * @dcbcfg: the corresponding DCBx configuration structure
4961 * Query the current DCB configuration and return the number of
4962 * traffic classes enabled from the given DCBX config
4964 static u8
i40e_dcb_get_enabled_tc(struct i40e_dcbx_config
*dcbcfg
)
4966 u8 num_tc
= i40e_dcb_get_num_tc(dcbcfg
);
4970 for (i
= 0; i
< num_tc
; i
++)
4971 enabled_tc
|= BIT(i
);
4977 * i40e_mqprio_get_enabled_tc - Get enabled traffic classes
4978 * @pf: PF being queried
4980 * Query the current MQPRIO configuration and return the number of
4981 * traffic classes enabled.
4983 static u8
i40e_mqprio_get_enabled_tc(struct i40e_pf
*pf
)
4985 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
4986 u8 num_tc
= vsi
->mqprio_qopt
.qopt
.num_tc
;
4987 u8 enabled_tc
= 1, i
;
4989 for (i
= 1; i
< num_tc
; i
++)
4990 enabled_tc
|= BIT(i
);
4995 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
4996 * @pf: PF being queried
4998 * Return number of traffic classes enabled for the given PF
5000 static u8
i40e_pf_get_num_tc(struct i40e_pf
*pf
)
5002 struct i40e_hw
*hw
= &pf
->hw
;
5003 u8 i
, enabled_tc
= 1;
5005 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
5007 if (pf
->flags
& I40E_FLAG_TC_MQPRIO
)
5008 return pf
->vsi
[pf
->lan_vsi
]->mqprio_qopt
.qopt
.num_tc
;
5010 /* If neither MQPRIO nor DCB is enabled, then always use single TC */
5011 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
5014 /* SFP mode will be enabled for all TCs on port */
5015 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
5016 return i40e_dcb_get_num_tc(dcbcfg
);
5018 /* MFP mode return count of enabled TCs for this PF */
5019 if (pf
->hw
.func_caps
.iscsi
)
5020 enabled_tc
= i40e_get_iscsi_tc_map(pf
);
5022 return 1; /* Only TC0 */
5024 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
5025 if (enabled_tc
& BIT(i
))
5032 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
5033 * @pf: PF being queried
5035 * Return a bitmap for enabled traffic classes for this PF.
5037 static u8
i40e_pf_get_tc_map(struct i40e_pf
*pf
)
5039 if (pf
->flags
& I40E_FLAG_TC_MQPRIO
)
5040 return i40e_mqprio_get_enabled_tc(pf
);
5042 /* If neither MQPRIO nor DCB is enabled for this PF then just return
5045 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
5046 return I40E_DEFAULT_TRAFFIC_CLASS
;
5048 /* SFP mode we want PF to be enabled for all TCs */
5049 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
5050 return i40e_dcb_get_enabled_tc(&pf
->hw
.local_dcbx_config
);
5052 /* MFP enabled and iSCSI PF type */
5053 if (pf
->hw
.func_caps
.iscsi
)
5054 return i40e_get_iscsi_tc_map(pf
);
5056 return I40E_DEFAULT_TRAFFIC_CLASS
;
5060 * i40e_vsi_get_bw_info - Query VSI BW Information
5061 * @vsi: the VSI being queried
5063 * Returns 0 on success, negative value on failure
5065 static int i40e_vsi_get_bw_info(struct i40e_vsi
*vsi
)
5067 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config
= {0};
5068 struct i40e_aqc_query_vsi_bw_config_resp bw_config
= {0};
5069 struct i40e_pf
*pf
= vsi
->back
;
5070 struct i40e_hw
*hw
= &pf
->hw
;
5075 /* Get the VSI level BW configuration */
5076 ret
= i40e_aq_query_vsi_bw_config(hw
, vsi
->seid
, &bw_config
, NULL
);
5078 dev_info(&pf
->pdev
->dev
,
5079 "couldn't get PF vsi bw config, err %s aq_err %s\n",
5080 i40e_stat_str(&pf
->hw
, ret
),
5081 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
5085 /* Get the VSI level BW configuration per TC */
5086 ret
= i40e_aq_query_vsi_ets_sla_config(hw
, vsi
->seid
, &bw_ets_config
,
5089 dev_info(&pf
->pdev
->dev
,
5090 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
5091 i40e_stat_str(&pf
->hw
, ret
),
5092 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
5096 if (bw_config
.tc_valid_bits
!= bw_ets_config
.tc_valid_bits
) {
5097 dev_info(&pf
->pdev
->dev
,
5098 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
5099 bw_config
.tc_valid_bits
,
5100 bw_ets_config
.tc_valid_bits
);
5101 /* Still continuing */
5104 vsi
->bw_limit
= le16_to_cpu(bw_config
.port_bw_limit
);
5105 vsi
->bw_max_quanta
= bw_config
.max_bw
;
5106 tc_bw_max
= le16_to_cpu(bw_ets_config
.tc_bw_max
[0]) |
5107 (le16_to_cpu(bw_ets_config
.tc_bw_max
[1]) << 16);
5108 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
5109 vsi
->bw_ets_share_credits
[i
] = bw_ets_config
.share_credits
[i
];
5110 vsi
->bw_ets_limit_credits
[i
] =
5111 le16_to_cpu(bw_ets_config
.credits
[i
]);
5112 /* 3 bits out of 4 for each TC */
5113 vsi
->bw_ets_max_quanta
[i
] = (u8
)((tc_bw_max
>> (i
*4)) & 0x7);
5120 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
5121 * @vsi: the VSI being configured
5122 * @enabled_tc: TC bitmap
5123 * @bw_share: BW shared credits per TC
5125 * Returns 0 on success, negative value on failure
5127 static int i40e_vsi_configure_bw_alloc(struct i40e_vsi
*vsi
, u8 enabled_tc
,
5130 struct i40e_aqc_configure_vsi_tc_bw_data bw_data
;
5131 struct i40e_pf
*pf
= vsi
->back
;
5135 /* There is no need to reset BW when mqprio mode is on. */
5136 if (pf
->flags
& I40E_FLAG_TC_MQPRIO
)
5138 if (!vsi
->mqprio_qopt
.qopt
.hw
&& !(pf
->flags
& I40E_FLAG_DCB_ENABLED
)) {
5139 ret
= i40e_set_bw_limit(vsi
, vsi
->seid
, 0);
5141 dev_info(&pf
->pdev
->dev
,
5142 "Failed to reset tx rate for vsi->seid %u\n",
5146 bw_data
.tc_valid_bits
= enabled_tc
;
5147 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
5148 bw_data
.tc_bw_credits
[i
] = bw_share
[i
];
5150 ret
= i40e_aq_config_vsi_tc_bw(&pf
->hw
, vsi
->seid
, &bw_data
, NULL
);
5152 dev_info(&pf
->pdev
->dev
,
5153 "AQ command Config VSI BW allocation per TC failed = %d\n",
5154 pf
->hw
.aq
.asq_last_status
);
5158 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
5159 vsi
->info
.qs_handle
[i
] = bw_data
.qs_handles
[i
];
5165 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
5166 * @vsi: the VSI being configured
5167 * @enabled_tc: TC map to be enabled
5170 static void i40e_vsi_config_netdev_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
5172 struct net_device
*netdev
= vsi
->netdev
;
5173 struct i40e_pf
*pf
= vsi
->back
;
5174 struct i40e_hw
*hw
= &pf
->hw
;
5177 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
5183 netdev_reset_tc(netdev
);
5187 /* Set up actual enabled TCs on the VSI */
5188 if (netdev_set_num_tc(netdev
, vsi
->tc_config
.numtc
))
5191 /* set per TC queues for the VSI */
5192 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
5193 /* Only set TC queues for enabled tcs
5195 * e.g. For a VSI that has TC0 and TC3 enabled the
5196 * enabled_tc bitmap would be 0x00001001; the driver
5197 * will set the numtc for netdev as 2 that will be
5198 * referenced by the netdev layer as TC 0 and 1.
5200 if (vsi
->tc_config
.enabled_tc
& BIT(i
))
5201 netdev_set_tc_queue(netdev
,
5202 vsi
->tc_config
.tc_info
[i
].netdev_tc
,
5203 vsi
->tc_config
.tc_info
[i
].qcount
,
5204 vsi
->tc_config
.tc_info
[i
].qoffset
);
5207 if (pf
->flags
& I40E_FLAG_TC_MQPRIO
)
5210 /* Assign UP2TC map for the VSI */
5211 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
5212 /* Get the actual TC# for the UP */
5213 u8 ets_tc
= dcbcfg
->etscfg
.prioritytable
[i
];
5214 /* Get the mapped netdev TC# for the UP */
5215 netdev_tc
= vsi
->tc_config
.tc_info
[ets_tc
].netdev_tc
;
5216 netdev_set_prio_tc_map(netdev
, i
, netdev_tc
);
5221 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
5222 * @vsi: the VSI being configured
5223 * @ctxt: the ctxt buffer returned from AQ VSI update param command
5225 static void i40e_vsi_update_queue_map(struct i40e_vsi
*vsi
,
5226 struct i40e_vsi_context
*ctxt
)
5228 /* copy just the sections touched not the entire info
5229 * since not all sections are valid as returned by
5232 vsi
->info
.mapping_flags
= ctxt
->info
.mapping_flags
;
5233 memcpy(&vsi
->info
.queue_mapping
,
5234 &ctxt
->info
.queue_mapping
, sizeof(vsi
->info
.queue_mapping
));
5235 memcpy(&vsi
->info
.tc_mapping
, ctxt
->info
.tc_mapping
,
5236 sizeof(vsi
->info
.tc_mapping
));
5240 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
5241 * @vsi: VSI to be configured
5242 * @enabled_tc: TC bitmap
5244 * This configures a particular VSI for TCs that are mapped to the
5245 * given TC bitmap. It uses default bandwidth share for TCs across
5246 * VSIs to configure TC for a particular VSI.
5249 * It is expected that the VSI queues have been quisced before calling
5252 static int i40e_vsi_config_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
5254 u8 bw_share
[I40E_MAX_TRAFFIC_CLASS
] = {0};
5255 struct i40e_pf
*pf
= vsi
->back
;
5256 struct i40e_hw
*hw
= &pf
->hw
;
5257 struct i40e_vsi_context ctxt
;
5261 /* Check if enabled_tc is same as existing or new TCs */
5262 if (vsi
->tc_config
.enabled_tc
== enabled_tc
&&
5263 vsi
->mqprio_qopt
.mode
!= TC_MQPRIO_MODE_CHANNEL
)
5266 /* Enable ETS TCs with equal BW Share for now across all VSIs */
5267 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
5268 if (enabled_tc
& BIT(i
))
5272 ret
= i40e_vsi_configure_bw_alloc(vsi
, enabled_tc
, bw_share
);
5274 struct i40e_aqc_query_vsi_bw_config_resp bw_config
= {0};
5276 dev_info(&pf
->pdev
->dev
,
5277 "Failed configuring TC map %d for VSI %d\n",
5278 enabled_tc
, vsi
->seid
);
5279 ret
= i40e_aq_query_vsi_bw_config(hw
, vsi
->seid
,
5282 dev_info(&pf
->pdev
->dev
,
5283 "Failed querying vsi bw info, err %s aq_err %s\n",
5284 i40e_stat_str(hw
, ret
),
5285 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
5288 if ((bw_config
.tc_valid_bits
& enabled_tc
) != enabled_tc
) {
5289 u8 valid_tc
= bw_config
.tc_valid_bits
& enabled_tc
;
5292 valid_tc
= bw_config
.tc_valid_bits
;
5293 /* Always enable TC0, no matter what */
5295 dev_info(&pf
->pdev
->dev
,
5296 "Requested tc 0x%x, but FW reports 0x%x as valid. Attempting to use 0x%x.\n",
5297 enabled_tc
, bw_config
.tc_valid_bits
, valid_tc
);
5298 enabled_tc
= valid_tc
;
5301 ret
= i40e_vsi_configure_bw_alloc(vsi
, enabled_tc
, bw_share
);
5303 dev_err(&pf
->pdev
->dev
,
5304 "Unable to configure TC map %d for VSI %d\n",
5305 enabled_tc
, vsi
->seid
);
5310 /* Update Queue Pairs Mapping for currently enabled UPs */
5311 ctxt
.seid
= vsi
->seid
;
5312 ctxt
.pf_num
= vsi
->back
->hw
.pf_id
;
5314 ctxt
.uplink_seid
= vsi
->uplink_seid
;
5315 ctxt
.info
= vsi
->info
;
5316 if (vsi
->back
->flags
& I40E_FLAG_TC_MQPRIO
) {
5317 ret
= i40e_vsi_setup_queue_map_mqprio(vsi
, &ctxt
, enabled_tc
);
5321 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
5324 /* On destroying the qdisc, reset vsi->rss_size, as number of enabled
5327 if (!vsi
->mqprio_qopt
.qopt
.hw
&& vsi
->reconfig_rss
) {
5328 vsi
->rss_size
= min_t(int, vsi
->back
->alloc_rss_size
,
5329 vsi
->num_queue_pairs
);
5330 ret
= i40e_vsi_config_rss(vsi
);
5332 dev_info(&vsi
->back
->pdev
->dev
,
5333 "Failed to reconfig rss for num_queues\n");
5336 vsi
->reconfig_rss
= false;
5338 if (vsi
->back
->flags
& I40E_FLAG_IWARP_ENABLED
) {
5339 ctxt
.info
.valid_sections
|=
5340 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID
);
5341 ctxt
.info
.queueing_opt_flags
|= I40E_AQ_VSI_QUE_OPT_TCP_ENA
;
5344 /* Update the VSI after updating the VSI queue-mapping
5347 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
5349 dev_info(&pf
->pdev
->dev
,
5350 "Update vsi tc config failed, err %s aq_err %s\n",
5351 i40e_stat_str(hw
, ret
),
5352 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
5355 /* update the local VSI info with updated queue map */
5356 i40e_vsi_update_queue_map(vsi
, &ctxt
);
5357 vsi
->info
.valid_sections
= 0;
5359 /* Update current VSI BW information */
5360 ret
= i40e_vsi_get_bw_info(vsi
);
5362 dev_info(&pf
->pdev
->dev
,
5363 "Failed updating vsi bw info, err %s aq_err %s\n",
5364 i40e_stat_str(hw
, ret
),
5365 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
5369 /* Update the netdev TC setup */
5370 i40e_vsi_config_netdev_tc(vsi
, enabled_tc
);
5376 * i40e_get_link_speed - Returns link speed for the interface
5377 * @vsi: VSI to be configured
5380 static int i40e_get_link_speed(struct i40e_vsi
*vsi
)
5382 struct i40e_pf
*pf
= vsi
->back
;
5384 switch (pf
->hw
.phy
.link_info
.link_speed
) {
5385 case I40E_LINK_SPEED_40GB
:
5387 case I40E_LINK_SPEED_25GB
:
5389 case I40E_LINK_SPEED_20GB
:
5391 case I40E_LINK_SPEED_10GB
:
5393 case I40E_LINK_SPEED_1GB
:
5401 * i40e_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate
5402 * @vsi: VSI to be configured
5403 * @seid: seid of the channel/VSI
5404 * @max_tx_rate: max TX rate to be configured as BW limit
5406 * Helper function to set BW limit for a given VSI
5408 int i40e_set_bw_limit(struct i40e_vsi
*vsi
, u16 seid
, u64 max_tx_rate
)
5410 struct i40e_pf
*pf
= vsi
->back
;
5415 speed
= i40e_get_link_speed(vsi
);
5416 if (max_tx_rate
> speed
) {
5417 dev_err(&pf
->pdev
->dev
,
5418 "Invalid max tx rate %llu specified for VSI seid %d.",
5422 if (max_tx_rate
&& max_tx_rate
< 50) {
5423 dev_warn(&pf
->pdev
->dev
,
5424 "Setting max tx rate to minimum usable value of 50Mbps.\n");
5428 /* Tx rate credits are in values of 50Mbps, 0 is disabled */
5429 credits
= max_tx_rate
;
5430 do_div(credits
, I40E_BW_CREDIT_DIVISOR
);
5431 ret
= i40e_aq_config_vsi_bw_limit(&pf
->hw
, seid
, credits
,
5432 I40E_MAX_BW_INACTIVE_ACCUM
, NULL
);
5434 dev_err(&pf
->pdev
->dev
,
5435 "Failed set tx rate (%llu Mbps) for vsi->seid %u, err %s aq_err %s\n",
5436 max_tx_rate
, seid
, i40e_stat_str(&pf
->hw
, ret
),
5437 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
5442 * i40e_remove_queue_channels - Remove queue channels for the TCs
5443 * @vsi: VSI to be configured
5445 * Remove queue channels for the TCs
5447 static void i40e_remove_queue_channels(struct i40e_vsi
*vsi
)
5449 enum i40e_admin_queue_err last_aq_status
;
5450 struct i40e_cloud_filter
*cfilter
;
5451 struct i40e_channel
*ch
, *ch_tmp
;
5452 struct i40e_pf
*pf
= vsi
->back
;
5453 struct hlist_node
*node
;
5456 /* Reset rss size that was stored when reconfiguring rss for
5457 * channel VSIs with non-power-of-2 queue count.
5459 vsi
->current_rss_size
= 0;
5461 /* perform cleanup for channels if they exist */
5462 if (list_empty(&vsi
->ch_list
))
5465 list_for_each_entry_safe(ch
, ch_tmp
, &vsi
->ch_list
, list
) {
5466 struct i40e_vsi
*p_vsi
;
5468 list_del(&ch
->list
);
5469 p_vsi
= ch
->parent_vsi
;
5470 if (!p_vsi
|| !ch
->initialized
) {
5474 /* Reset queue contexts */
5475 for (i
= 0; i
< ch
->num_queue_pairs
; i
++) {
5476 struct i40e_ring
*tx_ring
, *rx_ring
;
5479 pf_q
= ch
->base_queue
+ i
;
5480 tx_ring
= vsi
->tx_rings
[pf_q
];
5483 rx_ring
= vsi
->rx_rings
[pf_q
];
5487 /* Reset BW configured for this VSI via mqprio */
5488 ret
= i40e_set_bw_limit(vsi
, ch
->seid
, 0);
5490 dev_info(&vsi
->back
->pdev
->dev
,
5491 "Failed to reset tx rate for ch->seid %u\n",
5494 /* delete cloud filters associated with this channel */
5495 hlist_for_each_entry_safe(cfilter
, node
,
5496 &pf
->cloud_filter_list
, cloud_node
) {
5497 if (cfilter
->seid
!= ch
->seid
)
5500 hash_del(&cfilter
->cloud_node
);
5501 if (cfilter
->dst_port
)
5502 ret
= i40e_add_del_cloud_filter_big_buf(vsi
,
5506 ret
= i40e_add_del_cloud_filter(vsi
, cfilter
,
5508 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
5510 dev_info(&pf
->pdev
->dev
,
5511 "Failed to delete cloud filter, err %s aq_err %s\n",
5512 i40e_stat_str(&pf
->hw
, ret
),
5513 i40e_aq_str(&pf
->hw
, last_aq_status
));
5517 /* delete VSI from FW */
5518 ret
= i40e_aq_delete_element(&vsi
->back
->hw
, ch
->seid
,
5521 dev_err(&vsi
->back
->pdev
->dev
,
5522 "unable to remove channel (%d) for parent VSI(%d)\n",
5523 ch
->seid
, p_vsi
->seid
);
5526 INIT_LIST_HEAD(&vsi
->ch_list
);
5530 * i40e_is_any_channel - channel exist or not
5531 * @vsi: ptr to VSI to which channels are associated with
5533 * Returns true or false if channel(s) exist for associated VSI or not
5535 static bool i40e_is_any_channel(struct i40e_vsi
*vsi
)
5537 struct i40e_channel
*ch
, *ch_tmp
;
5539 list_for_each_entry_safe(ch
, ch_tmp
, &vsi
->ch_list
, list
) {
5540 if (ch
->initialized
)
5548 * i40e_get_max_queues_for_channel
5549 * @vsi: ptr to VSI to which channels are associated with
5551 * Helper function which returns max value among the queue counts set on the
5552 * channels/TCs created.
5554 static int i40e_get_max_queues_for_channel(struct i40e_vsi
*vsi
)
5556 struct i40e_channel
*ch
, *ch_tmp
;
5559 list_for_each_entry_safe(ch
, ch_tmp
, &vsi
->ch_list
, list
) {
5560 if (!ch
->initialized
)
5562 if (ch
->num_queue_pairs
> max
)
5563 max
= ch
->num_queue_pairs
;
5570 * i40e_validate_num_queues - validate num_queues w.r.t channel
5571 * @pf: ptr to PF device
5572 * @num_queues: number of queues
5573 * @vsi: the parent VSI
5574 * @reconfig_rss: indicates should the RSS be reconfigured or not
5576 * This function validates number of queues in the context of new channel
5577 * which is being established and determines if RSS should be reconfigured
5578 * or not for parent VSI.
5580 static int i40e_validate_num_queues(struct i40e_pf
*pf
, int num_queues
,
5581 struct i40e_vsi
*vsi
, bool *reconfig_rss
)
5588 *reconfig_rss
= false;
5589 if (vsi
->current_rss_size
) {
5590 if (num_queues
> vsi
->current_rss_size
) {
5591 dev_dbg(&pf
->pdev
->dev
,
5592 "Error: num_queues (%d) > vsi's current_size(%d)\n",
5593 num_queues
, vsi
->current_rss_size
);
5595 } else if ((num_queues
< vsi
->current_rss_size
) &&
5596 (!is_power_of_2(num_queues
))) {
5597 dev_dbg(&pf
->pdev
->dev
,
5598 "Error: num_queues (%d) < vsi's current_size(%d), but not power of 2\n",
5599 num_queues
, vsi
->current_rss_size
);
5604 if (!is_power_of_2(num_queues
)) {
5605 /* Find the max num_queues configured for channel if channel
5607 * if channel exist, then enforce 'num_queues' to be more than
5608 * max ever queues configured for channel.
5610 max_ch_queues
= i40e_get_max_queues_for_channel(vsi
);
5611 if (num_queues
< max_ch_queues
) {
5612 dev_dbg(&pf
->pdev
->dev
,
5613 "Error: num_queues (%d) < max queues configured for channel(%d)\n",
5614 num_queues
, max_ch_queues
);
5617 *reconfig_rss
= true;
5624 * i40e_vsi_reconfig_rss - reconfig RSS based on specified rss_size
5625 * @vsi: the VSI being setup
5626 * @rss_size: size of RSS, accordingly LUT gets reprogrammed
5628 * This function reconfigures RSS by reprogramming LUTs using 'rss_size'
5630 static int i40e_vsi_reconfig_rss(struct i40e_vsi
*vsi
, u16 rss_size
)
5632 struct i40e_pf
*pf
= vsi
->back
;
5633 u8 seed
[I40E_HKEY_ARRAY_SIZE
];
5634 struct i40e_hw
*hw
= &pf
->hw
;
5642 if (rss_size
> vsi
->rss_size
)
5645 local_rss_size
= min_t(int, vsi
->rss_size
, rss_size
);
5646 lut
= kzalloc(vsi
->rss_table_size
, GFP_KERNEL
);
5650 /* Ignoring user configured lut if there is one */
5651 i40e_fill_rss_lut(pf
, lut
, vsi
->rss_table_size
, local_rss_size
);
5653 /* Use user configured hash key if there is one, otherwise
5656 if (vsi
->rss_hkey_user
)
5657 memcpy(seed
, vsi
->rss_hkey_user
, I40E_HKEY_ARRAY_SIZE
);
5659 netdev_rss_key_fill((void *)seed
, I40E_HKEY_ARRAY_SIZE
);
5661 ret
= i40e_config_rss(vsi
, seed
, lut
, vsi
->rss_table_size
);
5663 dev_info(&pf
->pdev
->dev
,
5664 "Cannot set RSS lut, err %s aq_err %s\n",
5665 i40e_stat_str(hw
, ret
),
5666 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
5672 /* Do the update w.r.t. storing rss_size */
5673 if (!vsi
->orig_rss_size
)
5674 vsi
->orig_rss_size
= vsi
->rss_size
;
5675 vsi
->current_rss_size
= local_rss_size
;
5681 * i40e_channel_setup_queue_map - Setup a channel queue map
5682 * @pf: ptr to PF device
5683 * @vsi: the VSI being setup
5684 * @ctxt: VSI context structure
5685 * @ch: ptr to channel structure
5687 * Setup queue map for a specific channel
5689 static void i40e_channel_setup_queue_map(struct i40e_pf
*pf
,
5690 struct i40e_vsi_context
*ctxt
,
5691 struct i40e_channel
*ch
)
5693 u16 qcount
, qmap
, sections
= 0;
5697 sections
= I40E_AQ_VSI_PROP_QUEUE_MAP_VALID
;
5698 sections
|= I40E_AQ_VSI_PROP_SCHED_VALID
;
5700 qcount
= min_t(int, ch
->num_queue_pairs
, pf
->num_lan_msix
);
5701 ch
->num_queue_pairs
= qcount
;
5703 /* find the next higher power-of-2 of num queue pairs */
5704 pow
= ilog2(qcount
);
5705 if (!is_power_of_2(qcount
))
5708 qmap
= (offset
<< I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT
) |
5709 (pow
<< I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT
);
5711 /* Setup queue TC[0].qmap for given VSI context */
5712 ctxt
->info
.tc_mapping
[0] = cpu_to_le16(qmap
);
5714 ctxt
->info
.up_enable_bits
= 0x1; /* TC0 enabled */
5715 ctxt
->info
.mapping_flags
|= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG
);
5716 ctxt
->info
.queue_mapping
[0] = cpu_to_le16(ch
->base_queue
);
5717 ctxt
->info
.valid_sections
|= cpu_to_le16(sections
);
5721 * i40e_add_channel - add a channel by adding VSI
5722 * @pf: ptr to PF device
5723 * @uplink_seid: underlying HW switching element (VEB) ID
5724 * @ch: ptr to channel structure
5726 * Add a channel (VSI) using add_vsi and queue_map
5728 static int i40e_add_channel(struct i40e_pf
*pf
, u16 uplink_seid
,
5729 struct i40e_channel
*ch
)
5731 struct i40e_hw
*hw
= &pf
->hw
;
5732 struct i40e_vsi_context ctxt
;
5733 u8 enabled_tc
= 0x1; /* TC0 enabled */
5736 if (ch
->type
!= I40E_VSI_VMDQ2
) {
5737 dev_info(&pf
->pdev
->dev
,
5738 "add new vsi failed, ch->type %d\n", ch
->type
);
5742 memset(&ctxt
, 0, sizeof(ctxt
));
5743 ctxt
.pf_num
= hw
->pf_id
;
5745 ctxt
.uplink_seid
= uplink_seid
;
5746 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
5747 if (ch
->type
== I40E_VSI_VMDQ2
)
5748 ctxt
.flags
= I40E_AQ_VSI_TYPE_VMDQ2
;
5750 if (pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
) {
5751 ctxt
.info
.valid_sections
|=
5752 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
5753 ctxt
.info
.switch_id
=
5754 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
5757 /* Set queue map for a given VSI context */
5758 i40e_channel_setup_queue_map(pf
, &ctxt
, ch
);
5760 /* Now time to create VSI */
5761 ret
= i40e_aq_add_vsi(hw
, &ctxt
, NULL
);
5763 dev_info(&pf
->pdev
->dev
,
5764 "add new vsi failed, err %s aq_err %s\n",
5765 i40e_stat_str(&pf
->hw
, ret
),
5766 i40e_aq_str(&pf
->hw
,
5767 pf
->hw
.aq
.asq_last_status
));
5771 /* Success, update channel */
5772 ch
->enabled_tc
= enabled_tc
;
5773 ch
->seid
= ctxt
.seid
;
5774 ch
->vsi_number
= ctxt
.vsi_number
;
5775 ch
->stat_counter_idx
= cpu_to_le16(ctxt
.info
.stat_counter_idx
);
5777 /* copy just the sections touched not the entire info
5778 * since not all sections are valid as returned by
5781 ch
->info
.mapping_flags
= ctxt
.info
.mapping_flags
;
5782 memcpy(&ch
->info
.queue_mapping
,
5783 &ctxt
.info
.queue_mapping
, sizeof(ctxt
.info
.queue_mapping
));
5784 memcpy(&ch
->info
.tc_mapping
, ctxt
.info
.tc_mapping
,
5785 sizeof(ctxt
.info
.tc_mapping
));
5790 static int i40e_channel_config_bw(struct i40e_vsi
*vsi
, struct i40e_channel
*ch
,
5793 struct i40e_aqc_configure_vsi_tc_bw_data bw_data
;
5797 bw_data
.tc_valid_bits
= ch
->enabled_tc
;
5798 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
5799 bw_data
.tc_bw_credits
[i
] = bw_share
[i
];
5801 ret
= i40e_aq_config_vsi_tc_bw(&vsi
->back
->hw
, ch
->seid
,
5804 dev_info(&vsi
->back
->pdev
->dev
,
5805 "Config VSI BW allocation per TC failed, aq_err: %d for new_vsi->seid %u\n",
5806 vsi
->back
->hw
.aq
.asq_last_status
, ch
->seid
);
5810 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
5811 ch
->info
.qs_handle
[i
] = bw_data
.qs_handles
[i
];
5817 * i40e_channel_config_tx_ring - config TX ring associated with new channel
5818 * @pf: ptr to PF device
5819 * @vsi: the VSI being setup
5820 * @ch: ptr to channel structure
5822 * Configure TX rings associated with channel (VSI) since queues are being
5825 static int i40e_channel_config_tx_ring(struct i40e_pf
*pf
,
5826 struct i40e_vsi
*vsi
,
5827 struct i40e_channel
*ch
)
5831 u8 bw_share
[I40E_MAX_TRAFFIC_CLASS
] = {0};
5833 /* Enable ETS TCs with equal BW Share for now across all VSIs */
5834 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
5835 if (ch
->enabled_tc
& BIT(i
))
5839 /* configure BW for new VSI */
5840 ret
= i40e_channel_config_bw(vsi
, ch
, bw_share
);
5842 dev_info(&vsi
->back
->pdev
->dev
,
5843 "Failed configuring TC map %d for channel (seid %u)\n",
5844 ch
->enabled_tc
, ch
->seid
);
5848 for (i
= 0; i
< ch
->num_queue_pairs
; i
++) {
5849 struct i40e_ring
*tx_ring
, *rx_ring
;
5852 pf_q
= ch
->base_queue
+ i
;
5854 /* Get to TX ring ptr of main VSI, for re-setup TX queue
5857 tx_ring
= vsi
->tx_rings
[pf_q
];
5860 /* Get the RX ring ptr */
5861 rx_ring
= vsi
->rx_rings
[pf_q
];
5869 * i40e_setup_hw_channel - setup new channel
5870 * @pf: ptr to PF device
5871 * @vsi: the VSI being setup
5872 * @ch: ptr to channel structure
5873 * @uplink_seid: underlying HW switching element (VEB) ID
5874 * @type: type of channel to be created (VMDq2/VF)
5876 * Setup new channel (VSI) based on specified type (VMDq2/VF)
5877 * and configures TX rings accordingly
5879 static inline int i40e_setup_hw_channel(struct i40e_pf
*pf
,
5880 struct i40e_vsi
*vsi
,
5881 struct i40e_channel
*ch
,
5882 u16 uplink_seid
, u8 type
)
5886 ch
->initialized
= false;
5887 ch
->base_queue
= vsi
->next_base_queue
;
5890 /* Proceed with creation of channel (VMDq2) VSI */
5891 ret
= i40e_add_channel(pf
, uplink_seid
, ch
);
5893 dev_info(&pf
->pdev
->dev
,
5894 "failed to add_channel using uplink_seid %u\n",
5899 /* Mark the successful creation of channel */
5900 ch
->initialized
= true;
5902 /* Reconfigure TX queues using QTX_CTL register */
5903 ret
= i40e_channel_config_tx_ring(pf
, vsi
, ch
);
5905 dev_info(&pf
->pdev
->dev
,
5906 "failed to configure TX rings for channel %u\n",
5911 /* update 'next_base_queue' */
5912 vsi
->next_base_queue
= vsi
->next_base_queue
+ ch
->num_queue_pairs
;
5913 dev_dbg(&pf
->pdev
->dev
,
5914 "Added channel: vsi_seid %u, vsi_number %u, stat_counter_idx %u, num_queue_pairs %u, pf->next_base_queue %d\n",
5915 ch
->seid
, ch
->vsi_number
, ch
->stat_counter_idx
,
5916 ch
->num_queue_pairs
,
5917 vsi
->next_base_queue
);
5922 * i40e_setup_channel - setup new channel using uplink element
5923 * @pf: ptr to PF device
5924 * @type: type of channel to be created (VMDq2/VF)
5925 * @uplink_seid: underlying HW switching element (VEB) ID
5926 * @ch: ptr to channel structure
5928 * Setup new channel (VSI) based on specified type (VMDq2/VF)
5929 * and uplink switching element (uplink_seid)
5931 static bool i40e_setup_channel(struct i40e_pf
*pf
, struct i40e_vsi
*vsi
,
5932 struct i40e_channel
*ch
)
5938 if (vsi
->type
== I40E_VSI_MAIN
) {
5939 vsi_type
= I40E_VSI_VMDQ2
;
5941 dev_err(&pf
->pdev
->dev
, "unsupported parent vsi type(%d)\n",
5946 /* underlying switching element */
5947 seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
5949 /* create channel (VSI), configure TX rings */
5950 ret
= i40e_setup_hw_channel(pf
, vsi
, ch
, seid
, vsi_type
);
5952 dev_err(&pf
->pdev
->dev
, "failed to setup hw_channel\n");
5956 return ch
->initialized
? true : false;
5960 * i40e_validate_and_set_switch_mode - sets up switch mode correctly
5961 * @vsi: ptr to VSI which has PF backing
5963 * Sets up switch mode correctly if it needs to be changed and perform
5964 * what are allowed modes.
5966 static int i40e_validate_and_set_switch_mode(struct i40e_vsi
*vsi
)
5969 struct i40e_pf
*pf
= vsi
->back
;
5970 struct i40e_hw
*hw
= &pf
->hw
;
5973 ret
= i40e_get_capabilities(pf
, i40e_aqc_opc_list_dev_capabilities
);
5977 if (hw
->dev_caps
.switch_mode
) {
5978 /* if switch mode is set, support mode2 (non-tunneled for
5979 * cloud filter) for now
5981 u32 switch_mode
= hw
->dev_caps
.switch_mode
&
5982 I40E_SWITCH_MODE_MASK
;
5983 if (switch_mode
>= I40E_CLOUD_FILTER_MODE1
) {
5984 if (switch_mode
== I40E_CLOUD_FILTER_MODE2
)
5986 dev_err(&pf
->pdev
->dev
,
5987 "Invalid switch_mode (%d), only non-tunneled mode for cloud filter is supported\n",
5988 hw
->dev_caps
.switch_mode
);
5993 /* Set Bit 7 to be valid */
5994 mode
= I40E_AQ_SET_SWITCH_BIT7_VALID
;
5996 /* Set L4type for TCP support */
5997 mode
|= I40E_AQ_SET_SWITCH_L4_TYPE_TCP
;
5999 /* Set cloud filter mode */
6000 mode
|= I40E_AQ_SET_SWITCH_MODE_NON_TUNNEL
;
6002 /* Prep mode field for set_switch_config */
6003 ret
= i40e_aq_set_switch_config(hw
, pf
->last_sw_conf_flags
,
6004 pf
->last_sw_conf_valid_flags
,
6006 if (ret
&& hw
->aq
.asq_last_status
!= I40E_AQ_RC_ESRCH
)
6007 dev_err(&pf
->pdev
->dev
,
6008 "couldn't set switch config bits, err %s aq_err %s\n",
6009 i40e_stat_str(hw
, ret
),
6011 hw
->aq
.asq_last_status
));
6017 * i40e_create_queue_channel - function to create channel
6018 * @vsi: VSI to be configured
6019 * @ch: ptr to channel (it contains channel specific params)
6021 * This function creates channel (VSI) using num_queues specified by user,
6022 * reconfigs RSS if needed.
6024 int i40e_create_queue_channel(struct i40e_vsi
*vsi
,
6025 struct i40e_channel
*ch
)
6027 struct i40e_pf
*pf
= vsi
->back
;
6034 if (!ch
->num_queue_pairs
) {
6035 dev_err(&pf
->pdev
->dev
, "Invalid num_queues requested: %d\n",
6036 ch
->num_queue_pairs
);
6040 /* validate user requested num_queues for channel */
6041 err
= i40e_validate_num_queues(pf
, ch
->num_queue_pairs
, vsi
,
6044 dev_info(&pf
->pdev
->dev
, "Failed to validate num_queues (%d)\n",
6045 ch
->num_queue_pairs
);
6049 /* By default we are in VEPA mode, if this is the first VF/VMDq
6050 * VSI to be added switch to VEB mode.
6052 if ((!(pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)) ||
6053 (!i40e_is_any_channel(vsi
))) {
6054 if (!is_power_of_2(vsi
->tc_config
.tc_info
[0].qcount
)) {
6055 dev_dbg(&pf
->pdev
->dev
,
6056 "Failed to create channel. Override queues (%u) not power of 2\n",
6057 vsi
->tc_config
.tc_info
[0].qcount
);
6061 if (!(pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)) {
6062 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
6064 if (vsi
->type
== I40E_VSI_MAIN
) {
6065 if (pf
->flags
& I40E_FLAG_TC_MQPRIO
)
6066 i40e_do_reset(pf
, I40E_PF_RESET_FLAG
,
6069 i40e_do_reset_safe(pf
,
6070 I40E_PF_RESET_FLAG
);
6073 /* now onwards for main VSI, number of queues will be value
6074 * of TC0's queue count
6078 /* By this time, vsi->cnt_q_avail shall be set to non-zero and
6079 * it should be more than num_queues
6081 if (!vsi
->cnt_q_avail
|| vsi
->cnt_q_avail
< ch
->num_queue_pairs
) {
6082 dev_dbg(&pf
->pdev
->dev
,
6083 "Error: cnt_q_avail (%u) less than num_queues %d\n",
6084 vsi
->cnt_q_avail
, ch
->num_queue_pairs
);
6088 /* reconfig_rss only if vsi type is MAIN_VSI */
6089 if (reconfig_rss
&& (vsi
->type
== I40E_VSI_MAIN
)) {
6090 err
= i40e_vsi_reconfig_rss(vsi
, ch
->num_queue_pairs
);
6092 dev_info(&pf
->pdev
->dev
,
6093 "Error: unable to reconfig rss for num_queues (%u)\n",
6094 ch
->num_queue_pairs
);
6099 if (!i40e_setup_channel(pf
, vsi
, ch
)) {
6100 dev_info(&pf
->pdev
->dev
, "Failed to setup channel\n");
6104 dev_info(&pf
->pdev
->dev
,
6105 "Setup channel (id:%u) utilizing num_queues %d\n",
6106 ch
->seid
, ch
->num_queue_pairs
);
6108 /* configure VSI for BW limit */
6109 if (ch
->max_tx_rate
) {
6110 u64 credits
= ch
->max_tx_rate
;
6112 if (i40e_set_bw_limit(vsi
, ch
->seid
, ch
->max_tx_rate
))
6115 do_div(credits
, I40E_BW_CREDIT_DIVISOR
);
6116 dev_dbg(&pf
->pdev
->dev
,
6117 "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
6123 /* in case of VF, this will be main SRIOV VSI */
6124 ch
->parent_vsi
= vsi
;
6126 /* and update main_vsi's count for queue_available to use */
6127 vsi
->cnt_q_avail
-= ch
->num_queue_pairs
;
6133 * i40e_configure_queue_channels - Add queue channel for the given TCs
6134 * @vsi: VSI to be configured
6136 * Configures queue channel mapping to the given TCs
6138 static int i40e_configure_queue_channels(struct i40e_vsi
*vsi
)
6140 struct i40e_channel
*ch
;
6144 /* Create app vsi with the TCs. Main VSI with TC0 is already set up */
6145 vsi
->tc_seid_map
[0] = vsi
->seid
;
6146 for (i
= 1; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
6147 if (vsi
->tc_config
.enabled_tc
& BIT(i
)) {
6148 ch
= kzalloc(sizeof(*ch
), GFP_KERNEL
);
6154 INIT_LIST_HEAD(&ch
->list
);
6155 ch
->num_queue_pairs
=
6156 vsi
->tc_config
.tc_info
[i
].qcount
;
6158 vsi
->tc_config
.tc_info
[i
].qoffset
;
6160 /* Bandwidth limit through tc interface is in bytes/s,
6163 max_rate
= vsi
->mqprio_qopt
.max_rate
[i
];
6164 do_div(max_rate
, I40E_BW_MBPS_DIVISOR
);
6165 ch
->max_tx_rate
= max_rate
;
6167 list_add_tail(&ch
->list
, &vsi
->ch_list
);
6169 ret
= i40e_create_queue_channel(vsi
, ch
);
6171 dev_err(&vsi
->back
->pdev
->dev
,
6172 "Failed creating queue channel with TC%d: queues %d\n",
6173 i
, ch
->num_queue_pairs
);
6176 vsi
->tc_seid_map
[i
] = ch
->seid
;
6182 i40e_remove_queue_channels(vsi
);
6187 * i40e_veb_config_tc - Configure TCs for given VEB
6189 * @enabled_tc: TC bitmap
6191 * Configures given TC bitmap for VEB (switching) element
6193 int i40e_veb_config_tc(struct i40e_veb
*veb
, u8 enabled_tc
)
6195 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data
= {0};
6196 struct i40e_pf
*pf
= veb
->pf
;
6200 /* No TCs or already enabled TCs just return */
6201 if (!enabled_tc
|| veb
->enabled_tc
== enabled_tc
)
6204 bw_data
.tc_valid_bits
= enabled_tc
;
6205 /* bw_data.absolute_credits is not set (relative) */
6207 /* Enable ETS TCs with equal BW Share for now */
6208 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
6209 if (enabled_tc
& BIT(i
))
6210 bw_data
.tc_bw_share_credits
[i
] = 1;
6213 ret
= i40e_aq_config_switch_comp_bw_config(&pf
->hw
, veb
->seid
,
6216 dev_info(&pf
->pdev
->dev
,
6217 "VEB bw config failed, err %s aq_err %s\n",
6218 i40e_stat_str(&pf
->hw
, ret
),
6219 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6223 /* Update the BW information */
6224 ret
= i40e_veb_get_bw_info(veb
);
6226 dev_info(&pf
->pdev
->dev
,
6227 "Failed getting veb bw config, err %s aq_err %s\n",
6228 i40e_stat_str(&pf
->hw
, ret
),
6229 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6236 #ifdef CONFIG_I40E_DCB
6238 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
6241 * Reconfigure VEB/VSIs on a given PF; it is assumed that
6242 * the caller would've quiesce all the VSIs before calling
6245 static void i40e_dcb_reconfigure(struct i40e_pf
*pf
)
6251 /* Enable the TCs available on PF to all VEBs */
6252 tc_map
= i40e_pf_get_tc_map(pf
);
6253 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
6256 ret
= i40e_veb_config_tc(pf
->veb
[v
], tc_map
);
6258 dev_info(&pf
->pdev
->dev
,
6259 "Failed configuring TC for VEB seid=%d\n",
6261 /* Will try to configure as many components */
6265 /* Update each VSI */
6266 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
6270 /* - Enable all TCs for the LAN VSI
6271 * - For all others keep them at TC0 for now
6273 if (v
== pf
->lan_vsi
)
6274 tc_map
= i40e_pf_get_tc_map(pf
);
6276 tc_map
= I40E_DEFAULT_TRAFFIC_CLASS
;
6278 ret
= i40e_vsi_config_tc(pf
->vsi
[v
], tc_map
);
6280 dev_info(&pf
->pdev
->dev
,
6281 "Failed configuring TC for VSI seid=%d\n",
6283 /* Will try to configure as many components */
6285 /* Re-configure VSI vectors based on updated TC map */
6286 i40e_vsi_map_rings_to_vectors(pf
->vsi
[v
]);
6287 if (pf
->vsi
[v
]->netdev
)
6288 i40e_dcbnl_set_all(pf
->vsi
[v
]);
6294 * i40e_resume_port_tx - Resume port Tx
6297 * Resume a port's Tx and issue a PF reset in case of failure to
6300 static int i40e_resume_port_tx(struct i40e_pf
*pf
)
6302 struct i40e_hw
*hw
= &pf
->hw
;
6305 ret
= i40e_aq_resume_port_tx(hw
, NULL
);
6307 dev_info(&pf
->pdev
->dev
,
6308 "Resume Port Tx failed, err %s aq_err %s\n",
6309 i40e_stat_str(&pf
->hw
, ret
),
6310 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6311 /* Schedule PF reset to recover */
6312 set_bit(__I40E_PF_RESET_REQUESTED
, pf
->state
);
6313 i40e_service_event_schedule(pf
);
6320 * i40e_init_pf_dcb - Initialize DCB configuration
6321 * @pf: PF being configured
6323 * Query the current DCB configuration and cache it
6324 * in the hardware structure
6326 static int i40e_init_pf_dcb(struct i40e_pf
*pf
)
6328 struct i40e_hw
*hw
= &pf
->hw
;
6331 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable
6332 * Also do not enable DCBx if FW LLDP agent is disabled
6334 if ((pf
->hw_features
& I40E_HW_NO_DCB_SUPPORT
) ||
6335 (pf
->flags
& I40E_FLAG_DISABLE_FW_LLDP
))
6338 /* Get the initial DCB configuration */
6339 err
= i40e_init_dcb(hw
);
6341 /* Device/Function is not DCBX capable */
6342 if ((!hw
->func_caps
.dcb
) ||
6343 (hw
->dcbx_status
== I40E_DCBX_STATUS_DISABLED
)) {
6344 dev_info(&pf
->pdev
->dev
,
6345 "DCBX offload is not supported or is disabled for this PF.\n");
6347 /* When status is not DISABLED then DCBX in FW */
6348 pf
->dcbx_cap
= DCB_CAP_DCBX_LLD_MANAGED
|
6349 DCB_CAP_DCBX_VER_IEEE
;
6351 pf
->flags
|= I40E_FLAG_DCB_CAPABLE
;
6352 /* Enable DCB tagging only when more than one TC
6353 * or explicitly disable if only one TC
6355 if (i40e_dcb_get_num_tc(&hw
->local_dcbx_config
) > 1)
6356 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
6358 pf
->flags
&= ~I40E_FLAG_DCB_ENABLED
;
6359 dev_dbg(&pf
->pdev
->dev
,
6360 "DCBX offload is supported for this PF.\n");
6362 } else if (pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_EPERM
) {
6363 dev_info(&pf
->pdev
->dev
, "FW LLDP disabled for this PF.\n");
6364 pf
->flags
|= I40E_FLAG_DISABLE_FW_LLDP
;
6366 dev_info(&pf
->pdev
->dev
,
6367 "Query for DCB configuration failed, err %s aq_err %s\n",
6368 i40e_stat_str(&pf
->hw
, err
),
6369 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6375 #endif /* CONFIG_I40E_DCB */
6376 #define SPEED_SIZE 14
6379 * i40e_print_link_message - print link up or down
6380 * @vsi: the VSI for which link needs a message
6381 * @isup: true of link is up, false otherwise
6383 void i40e_print_link_message(struct i40e_vsi
*vsi
, bool isup
)
6385 enum i40e_aq_link_speed new_speed
;
6386 struct i40e_pf
*pf
= vsi
->back
;
6387 char *speed
= "Unknown";
6388 char *fc
= "Unknown";
6393 new_speed
= pf
->hw
.phy
.link_info
.link_speed
;
6395 if ((vsi
->current_isup
== isup
) && (vsi
->current_speed
== new_speed
))
6397 vsi
->current_isup
= isup
;
6398 vsi
->current_speed
= new_speed
;
6400 netdev_info(vsi
->netdev
, "NIC Link is Down\n");
6404 /* Warn user if link speed on NPAR enabled partition is not at
6407 if (pf
->hw
.func_caps
.npar_enable
&&
6408 (pf
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_1GB
||
6409 pf
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_100MB
))
6410 netdev_warn(vsi
->netdev
,
6411 "The partition detected link speed that is less than 10Gbps\n");
6413 switch (pf
->hw
.phy
.link_info
.link_speed
) {
6414 case I40E_LINK_SPEED_40GB
:
6417 case I40E_LINK_SPEED_20GB
:
6420 case I40E_LINK_SPEED_25GB
:
6423 case I40E_LINK_SPEED_10GB
:
6426 case I40E_LINK_SPEED_1GB
:
6429 case I40E_LINK_SPEED_100MB
:
6436 switch (pf
->hw
.fc
.current_mode
) {
6440 case I40E_FC_TX_PAUSE
:
6443 case I40E_FC_RX_PAUSE
:
6451 if (pf
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_25GB
) {
6452 req_fec
= ", Requested FEC: None";
6453 fec
= ", FEC: None";
6454 an
= ", Autoneg: False";
6456 if (pf
->hw
.phy
.link_info
.an_info
& I40E_AQ_AN_COMPLETED
)
6457 an
= ", Autoneg: True";
6459 if (pf
->hw
.phy
.link_info
.fec_info
&
6460 I40E_AQ_CONFIG_FEC_KR_ENA
)
6461 fec
= ", FEC: CL74 FC-FEC/BASE-R";
6462 else if (pf
->hw
.phy
.link_info
.fec_info
&
6463 I40E_AQ_CONFIG_FEC_RS_ENA
)
6464 fec
= ", FEC: CL108 RS-FEC";
6466 /* 'CL108 RS-FEC' should be displayed when RS is requested, or
6467 * both RS and FC are requested
6469 if (vsi
->back
->hw
.phy
.link_info
.req_fec_info
&
6470 (I40E_AQ_REQUEST_FEC_KR
| I40E_AQ_REQUEST_FEC_RS
)) {
6471 if (vsi
->back
->hw
.phy
.link_info
.req_fec_info
&
6472 I40E_AQ_REQUEST_FEC_RS
)
6473 req_fec
= ", Requested FEC: CL108 RS-FEC";
6475 req_fec
= ", Requested FEC: CL74 FC-FEC/BASE-R";
6479 netdev_info(vsi
->netdev
, "NIC Link is Up, %sbps Full Duplex%s%s%s, Flow Control: %s\n",
6480 speed
, req_fec
, fec
, an
, fc
);
6484 * i40e_up_complete - Finish the last steps of bringing up a connection
6485 * @vsi: the VSI being configured
6487 static int i40e_up_complete(struct i40e_vsi
*vsi
)
6489 struct i40e_pf
*pf
= vsi
->back
;
6492 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
6493 i40e_vsi_configure_msix(vsi
);
6495 i40e_configure_msi_and_legacy(vsi
);
6498 err
= i40e_vsi_start_rings(vsi
);
6502 clear_bit(__I40E_VSI_DOWN
, vsi
->state
);
6503 i40e_napi_enable_all(vsi
);
6504 i40e_vsi_enable_irq(vsi
);
6506 if ((pf
->hw
.phy
.link_info
.link_info
& I40E_AQ_LINK_UP
) &&
6508 i40e_print_link_message(vsi
, true);
6509 netif_tx_start_all_queues(vsi
->netdev
);
6510 netif_carrier_on(vsi
->netdev
);
6513 /* replay FDIR SB filters */
6514 if (vsi
->type
== I40E_VSI_FDIR
) {
6515 /* reset fd counters */
6518 i40e_fdir_filter_restore(vsi
);
6521 /* On the next run of the service_task, notify any clients of the new
6524 set_bit(__I40E_CLIENT_SERVICE_REQUESTED
, pf
->state
);
6525 i40e_service_event_schedule(pf
);
6531 * i40e_vsi_reinit_locked - Reset the VSI
6532 * @vsi: the VSI being configured
6534 * Rebuild the ring structs after some configuration
6535 * has changed, e.g. MTU size.
6537 static void i40e_vsi_reinit_locked(struct i40e_vsi
*vsi
)
6539 struct i40e_pf
*pf
= vsi
->back
;
6541 WARN_ON(in_interrupt());
6542 while (test_and_set_bit(__I40E_CONFIG_BUSY
, pf
->state
))
6543 usleep_range(1000, 2000);
6547 clear_bit(__I40E_CONFIG_BUSY
, pf
->state
);
6551 * i40e_up - Bring the connection back up after being down
6552 * @vsi: the VSI being configured
6554 int i40e_up(struct i40e_vsi
*vsi
)
6558 err
= i40e_vsi_configure(vsi
);
6560 err
= i40e_up_complete(vsi
);
6566 * i40e_force_link_state - Force the link status
6567 * @pf: board private structure
6568 * @is_up: whether the link state should be forced up or down
6570 static i40e_status
i40e_force_link_state(struct i40e_pf
*pf
, bool is_up
)
6572 struct i40e_aq_get_phy_abilities_resp abilities
;
6573 struct i40e_aq_set_phy_config config
= {0};
6574 struct i40e_hw
*hw
= &pf
->hw
;
6578 /* Get the current phy config */
6579 err
= i40e_aq_get_phy_capabilities(hw
, false, false, &abilities
,
6582 dev_err(&pf
->pdev
->dev
,
6583 "failed to get phy cap., ret = %s last_status = %s\n",
6584 i40e_stat_str(hw
, err
),
6585 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
6589 /* If link needs to go up, but was not forced to go down,
6590 * no need for a flap
6592 if (is_up
&& abilities
.phy_type
!= 0)
6593 return I40E_SUCCESS
;
6595 /* To force link we need to set bits for all supported PHY types,
6596 * but there are now more than 32, so we need to split the bitmap
6597 * across two fields.
6599 mask
= I40E_PHY_TYPES_BITMASK
;
6600 config
.phy_type
= is_up
? cpu_to_le32((u32
)(mask
& 0xffffffff)) : 0;
6601 config
.phy_type_ext
= is_up
? (u8
)((mask
>> 32) & 0xff) : 0;
6602 /* Copy the old settings, except of phy_type */
6603 config
.abilities
= abilities
.abilities
;
6604 config
.link_speed
= abilities
.link_speed
;
6605 config
.eee_capability
= abilities
.eee_capability
;
6606 config
.eeer
= abilities
.eeer_val
;
6607 config
.low_power_ctrl
= abilities
.d3_lpan
;
6608 config
.fec_config
= abilities
.fec_cfg_curr_mod_ext_info
&
6609 I40E_AQ_PHY_FEC_CONFIG_MASK
;
6610 err
= i40e_aq_set_phy_config(hw
, &config
, NULL
);
6613 dev_err(&pf
->pdev
->dev
,
6614 "set phy config ret = %s last_status = %s\n",
6615 i40e_stat_str(&pf
->hw
, err
),
6616 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6620 /* Update the link info */
6621 err
= i40e_update_link_info(hw
);
6623 /* Wait a little bit (on 40G cards it sometimes takes a really
6624 * long time for link to come back from the atomic reset)
6628 i40e_update_link_info(hw
);
6631 i40e_aq_set_link_restart_an(hw
, true, NULL
);
6633 return I40E_SUCCESS
;
6637 * i40e_down - Shutdown the connection processing
6638 * @vsi: the VSI being stopped
6640 void i40e_down(struct i40e_vsi
*vsi
)
6644 /* It is assumed that the caller of this function
6645 * sets the vsi->state __I40E_VSI_DOWN bit.
6648 netif_carrier_off(vsi
->netdev
);
6649 netif_tx_disable(vsi
->netdev
);
6651 i40e_vsi_disable_irq(vsi
);
6652 i40e_vsi_stop_rings(vsi
);
6653 if (vsi
->type
== I40E_VSI_MAIN
&&
6654 vsi
->back
->flags
& I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED
)
6655 i40e_force_link_state(vsi
->back
, false);
6656 i40e_napi_disable_all(vsi
);
6658 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
6659 i40e_clean_tx_ring(vsi
->tx_rings
[i
]);
6660 if (i40e_enabled_xdp_vsi(vsi
))
6661 i40e_clean_tx_ring(vsi
->xdp_rings
[i
]);
6662 i40e_clean_rx_ring(vsi
->rx_rings
[i
]);
6668 * i40e_validate_mqprio_qopt- validate queue mapping info
6669 * @vsi: the VSI being configured
6670 * @mqprio_qopt: queue parametrs
6672 static int i40e_validate_mqprio_qopt(struct i40e_vsi
*vsi
,
6673 struct tc_mqprio_qopt_offload
*mqprio_qopt
)
6675 u64 sum_max_rate
= 0;
6679 if (mqprio_qopt
->qopt
.offset
[0] != 0 ||
6680 mqprio_qopt
->qopt
.num_tc
< 1 ||
6681 mqprio_qopt
->qopt
.num_tc
> I40E_MAX_TRAFFIC_CLASS
)
6683 for (i
= 0; ; i
++) {
6684 if (!mqprio_qopt
->qopt
.count
[i
])
6686 if (mqprio_qopt
->min_rate
[i
]) {
6687 dev_err(&vsi
->back
->pdev
->dev
,
6688 "Invalid min tx rate (greater than 0) specified\n");
6691 max_rate
= mqprio_qopt
->max_rate
[i
];
6692 do_div(max_rate
, I40E_BW_MBPS_DIVISOR
);
6693 sum_max_rate
+= max_rate
;
6695 if (i
>= mqprio_qopt
->qopt
.num_tc
- 1)
6697 if (mqprio_qopt
->qopt
.offset
[i
+ 1] !=
6698 (mqprio_qopt
->qopt
.offset
[i
] + mqprio_qopt
->qopt
.count
[i
]))
6701 if (vsi
->num_queue_pairs
<
6702 (mqprio_qopt
->qopt
.offset
[i
] + mqprio_qopt
->qopt
.count
[i
])) {
6705 if (sum_max_rate
> i40e_get_link_speed(vsi
)) {
6706 dev_err(&vsi
->back
->pdev
->dev
,
6707 "Invalid max tx rate specified\n");
6714 * i40e_vsi_set_default_tc_config - set default values for tc configuration
6715 * @vsi: the VSI being configured
6717 static void i40e_vsi_set_default_tc_config(struct i40e_vsi
*vsi
)
6722 /* Only TC0 is enabled */
6723 vsi
->tc_config
.numtc
= 1;
6724 vsi
->tc_config
.enabled_tc
= 1;
6725 qcount
= min_t(int, vsi
->alloc_queue_pairs
,
6726 i40e_pf_get_max_q_per_tc(vsi
->back
));
6727 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
6728 /* For the TC that is not enabled set the offset to to default
6729 * queue and allocate one queue for the given TC.
6731 vsi
->tc_config
.tc_info
[i
].qoffset
= 0;
6733 vsi
->tc_config
.tc_info
[i
].qcount
= qcount
;
6735 vsi
->tc_config
.tc_info
[i
].qcount
= 1;
6736 vsi
->tc_config
.tc_info
[i
].netdev_tc
= 0;
6741 * i40e_setup_tc - configure multiple traffic classes
6742 * @netdev: net device to configure
6743 * @type_data: tc offload data
6745 static int i40e_setup_tc(struct net_device
*netdev
, void *type_data
)
6747 struct tc_mqprio_qopt_offload
*mqprio_qopt
= type_data
;
6748 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
6749 struct i40e_vsi
*vsi
= np
->vsi
;
6750 struct i40e_pf
*pf
= vsi
->back
;
6751 u8 enabled_tc
= 0, num_tc
, hw
;
6752 bool need_reset
= false;
6757 num_tc
= mqprio_qopt
->qopt
.num_tc
;
6758 hw
= mqprio_qopt
->qopt
.hw
;
6759 mode
= mqprio_qopt
->mode
;
6761 pf
->flags
&= ~I40E_FLAG_TC_MQPRIO
;
6762 memcpy(&vsi
->mqprio_qopt
, mqprio_qopt
, sizeof(*mqprio_qopt
));
6766 /* Check if MFP enabled */
6767 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
6769 "Configuring TC not supported in MFP mode\n");
6773 case TC_MQPRIO_MODE_DCB
:
6774 pf
->flags
&= ~I40E_FLAG_TC_MQPRIO
;
6776 /* Check if DCB enabled to continue */
6777 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
)) {
6779 "DCB is not enabled for adapter\n");
6783 /* Check whether tc count is within enabled limit */
6784 if (num_tc
> i40e_pf_get_num_tc(pf
)) {
6786 "TC count greater than enabled on link for adapter\n");
6790 case TC_MQPRIO_MODE_CHANNEL
:
6791 if (pf
->flags
& I40E_FLAG_DCB_ENABLED
) {
6793 "Full offload of TC Mqprio options is not supported when DCB is enabled\n");
6796 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
6798 ret
= i40e_validate_mqprio_qopt(vsi
, mqprio_qopt
);
6801 memcpy(&vsi
->mqprio_qopt
, mqprio_qopt
,
6802 sizeof(*mqprio_qopt
));
6803 pf
->flags
|= I40E_FLAG_TC_MQPRIO
;
6804 pf
->flags
&= ~I40E_FLAG_DCB_ENABLED
;
6811 /* Generate TC map for number of tc requested */
6812 for (i
= 0; i
< num_tc
; i
++)
6813 enabled_tc
|= BIT(i
);
6815 /* Requesting same TC configuration as already enabled */
6816 if (enabled_tc
== vsi
->tc_config
.enabled_tc
&&
6817 mode
!= TC_MQPRIO_MODE_CHANNEL
)
6820 /* Quiesce VSI queues */
6821 i40e_quiesce_vsi(vsi
);
6823 if (!hw
&& !(pf
->flags
& I40E_FLAG_TC_MQPRIO
))
6824 i40e_remove_queue_channels(vsi
);
6826 /* Configure VSI for enabled TCs */
6827 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
6829 netdev_info(netdev
, "Failed configuring TC for VSI seid=%d\n",
6835 if (pf
->flags
& I40E_FLAG_TC_MQPRIO
) {
6836 if (vsi
->mqprio_qopt
.max_rate
[0]) {
6837 u64 max_tx_rate
= vsi
->mqprio_qopt
.max_rate
[0];
6839 do_div(max_tx_rate
, I40E_BW_MBPS_DIVISOR
);
6840 ret
= i40e_set_bw_limit(vsi
, vsi
->seid
, max_tx_rate
);
6842 u64 credits
= max_tx_rate
;
6844 do_div(credits
, I40E_BW_CREDIT_DIVISOR
);
6845 dev_dbg(&vsi
->back
->pdev
->dev
,
6846 "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
6855 ret
= i40e_configure_queue_channels(vsi
);
6858 "Failed configuring queue channels\n");
6865 /* Reset the configuration data to defaults, only TC0 is enabled */
6867 i40e_vsi_set_default_tc_config(vsi
);
6872 i40e_unquiesce_vsi(vsi
);
6877 * i40e_set_cld_element - sets cloud filter element data
6878 * @filter: cloud filter rule
6879 * @cld: ptr to cloud filter element data
6881 * This is helper function to copy data into cloud filter element
6884 i40e_set_cld_element(struct i40e_cloud_filter
*filter
,
6885 struct i40e_aqc_cloud_filters_element_data
*cld
)
6890 memset(cld
, 0, sizeof(*cld
));
6891 ether_addr_copy(cld
->outer_mac
, filter
->dst_mac
);
6892 ether_addr_copy(cld
->inner_mac
, filter
->src_mac
);
6894 if (filter
->n_proto
!= ETH_P_IP
&& filter
->n_proto
!= ETH_P_IPV6
)
6897 if (filter
->n_proto
== ETH_P_IPV6
) {
6898 #define IPV6_MAX_INDEX (ARRAY_SIZE(filter->dst_ipv6) - 1)
6899 for (i
= 0, j
= 0; i
< ARRAY_SIZE(filter
->dst_ipv6
);
6901 ipa
= be32_to_cpu(filter
->dst_ipv6
[IPV6_MAX_INDEX
- i
]);
6902 ipa
= cpu_to_le32(ipa
);
6903 memcpy(&cld
->ipaddr
.raw_v6
.data
[j
], &ipa
, sizeof(ipa
));
6906 ipa
= be32_to_cpu(filter
->dst_ipv4
);
6907 memcpy(&cld
->ipaddr
.v4
.data
, &ipa
, sizeof(ipa
));
6910 cld
->inner_vlan
= cpu_to_le16(ntohs(filter
->vlan_id
));
6912 /* tenant_id is not supported by FW now, once the support is enabled
6913 * fill the cld->tenant_id with cpu_to_le32(filter->tenant_id)
6915 if (filter
->tenant_id
)
6920 * i40e_add_del_cloud_filter - Add/del cloud filter
6921 * @vsi: pointer to VSI
6922 * @filter: cloud filter rule
6923 * @add: if true, add, if false, delete
6925 * Add or delete a cloud filter for a specific flow spec.
6926 * Returns 0 if the filter were successfully added.
6928 int i40e_add_del_cloud_filter(struct i40e_vsi
*vsi
,
6929 struct i40e_cloud_filter
*filter
, bool add
)
6931 struct i40e_aqc_cloud_filters_element_data cld_filter
;
6932 struct i40e_pf
*pf
= vsi
->back
;
6934 static const u16 flag_table
[128] = {
6935 [I40E_CLOUD_FILTER_FLAGS_OMAC
] =
6936 I40E_AQC_ADD_CLOUD_FILTER_OMAC
,
6937 [I40E_CLOUD_FILTER_FLAGS_IMAC
] =
6938 I40E_AQC_ADD_CLOUD_FILTER_IMAC
,
6939 [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN
] =
6940 I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN
,
6941 [I40E_CLOUD_FILTER_FLAGS_IMAC_TEN_ID
] =
6942 I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID
,
6943 [I40E_CLOUD_FILTER_FLAGS_OMAC_TEN_ID_IMAC
] =
6944 I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC
,
6945 [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN_TEN_ID
] =
6946 I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID
,
6947 [I40E_CLOUD_FILTER_FLAGS_IIP
] =
6948 I40E_AQC_ADD_CLOUD_FILTER_IIP
,
6951 if (filter
->flags
>= ARRAY_SIZE(flag_table
))
6952 return I40E_ERR_CONFIG
;
6954 /* copy element needed to add cloud filter from filter */
6955 i40e_set_cld_element(filter
, &cld_filter
);
6957 if (filter
->tunnel_type
!= I40E_CLOUD_TNL_TYPE_NONE
)
6958 cld_filter
.flags
= cpu_to_le16(filter
->tunnel_type
<<
6959 I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT
);
6961 if (filter
->n_proto
== ETH_P_IPV6
)
6962 cld_filter
.flags
|= cpu_to_le16(flag_table
[filter
->flags
] |
6963 I40E_AQC_ADD_CLOUD_FLAGS_IPV6
);
6965 cld_filter
.flags
|= cpu_to_le16(flag_table
[filter
->flags
] |
6966 I40E_AQC_ADD_CLOUD_FLAGS_IPV4
);
6969 ret
= i40e_aq_add_cloud_filters(&pf
->hw
, filter
->seid
,
6972 ret
= i40e_aq_rem_cloud_filters(&pf
->hw
, filter
->seid
,
6975 dev_dbg(&pf
->pdev
->dev
,
6976 "Failed to %s cloud filter using l4 port %u, err %d aq_err %d\n",
6977 add
? "add" : "delete", filter
->dst_port
, ret
,
6978 pf
->hw
.aq
.asq_last_status
);
6980 dev_info(&pf
->pdev
->dev
,
6981 "%s cloud filter for VSI: %d\n",
6982 add
? "Added" : "Deleted", filter
->seid
);
6987 * i40e_add_del_cloud_filter_big_buf - Add/del cloud filter using big_buf
6988 * @vsi: pointer to VSI
6989 * @filter: cloud filter rule
6990 * @add: if true, add, if false, delete
6992 * Add or delete a cloud filter for a specific flow spec using big buffer.
6993 * Returns 0 if the filter were successfully added.
6995 int i40e_add_del_cloud_filter_big_buf(struct i40e_vsi
*vsi
,
6996 struct i40e_cloud_filter
*filter
,
6999 struct i40e_aqc_cloud_filters_element_bb cld_filter
;
7000 struct i40e_pf
*pf
= vsi
->back
;
7003 /* Both (src/dst) valid mac_addr are not supported */
7004 if ((is_valid_ether_addr(filter
->dst_mac
) &&
7005 is_valid_ether_addr(filter
->src_mac
)) ||
7006 (is_multicast_ether_addr(filter
->dst_mac
) &&
7007 is_multicast_ether_addr(filter
->src_mac
)))
7010 /* Big buffer cloud filter needs 'L4 port' to be non-zero. Also, UDP
7011 * ports are not supported via big buffer now.
7013 if (!filter
->dst_port
|| filter
->ip_proto
== IPPROTO_UDP
)
7016 /* adding filter using src_port/src_ip is not supported at this stage */
7017 if (filter
->src_port
|| filter
->src_ipv4
||
7018 !ipv6_addr_any(&filter
->ip
.v6
.src_ip6
))
7021 /* copy element needed to add cloud filter from filter */
7022 i40e_set_cld_element(filter
, &cld_filter
.element
);
7024 if (is_valid_ether_addr(filter
->dst_mac
) ||
7025 is_valid_ether_addr(filter
->src_mac
) ||
7026 is_multicast_ether_addr(filter
->dst_mac
) ||
7027 is_multicast_ether_addr(filter
->src_mac
)) {
7028 /* MAC + IP : unsupported mode */
7029 if (filter
->dst_ipv4
)
7032 /* since we validated that L4 port must be valid before
7033 * we get here, start with respective "flags" value
7034 * and update if vlan is present or not
7036 cld_filter
.element
.flags
=
7037 cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_PORT
);
7039 if (filter
->vlan_id
) {
7040 cld_filter
.element
.flags
=
7041 cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_VLAN_PORT
);
7044 } else if (filter
->dst_ipv4
||
7045 !ipv6_addr_any(&filter
->ip
.v6
.dst_ip6
)) {
7046 cld_filter
.element
.flags
=
7047 cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_IP_PORT
);
7048 if (filter
->n_proto
== ETH_P_IPV6
)
7049 cld_filter
.element
.flags
|=
7050 cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV6
);
7052 cld_filter
.element
.flags
|=
7053 cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV4
);
7055 dev_err(&pf
->pdev
->dev
,
7056 "either mac or ip has to be valid for cloud filter\n");
7060 /* Now copy L4 port in Byte 6..7 in general fields */
7061 cld_filter
.general_fields
[I40E_AQC_ADD_CLOUD_FV_FLU_0X16_WORD0
] =
7062 be16_to_cpu(filter
->dst_port
);
7065 /* Validate current device switch mode, change if necessary */
7066 ret
= i40e_validate_and_set_switch_mode(vsi
);
7068 dev_err(&pf
->pdev
->dev
,
7069 "failed to set switch mode, ret %d\n",
7074 ret
= i40e_aq_add_cloud_filters_bb(&pf
->hw
, filter
->seid
,
7077 ret
= i40e_aq_rem_cloud_filters_bb(&pf
->hw
, filter
->seid
,
7082 dev_dbg(&pf
->pdev
->dev
,
7083 "Failed to %s cloud filter(big buffer) err %d aq_err %d\n",
7084 add
? "add" : "delete", ret
, pf
->hw
.aq
.asq_last_status
);
7086 dev_info(&pf
->pdev
->dev
,
7087 "%s cloud filter for VSI: %d, L4 port: %d\n",
7088 add
? "add" : "delete", filter
->seid
,
7089 ntohs(filter
->dst_port
));
7094 * i40e_parse_cls_flower - Parse tc flower filters provided by kernel
7095 * @vsi: Pointer to VSI
7096 * @cls_flower: Pointer to struct tc_cls_flower_offload
7097 * @filter: Pointer to cloud filter structure
7100 static int i40e_parse_cls_flower(struct i40e_vsi
*vsi
,
7101 struct tc_cls_flower_offload
*f
,
7102 struct i40e_cloud_filter
*filter
)
7104 u16 n_proto_mask
= 0, n_proto_key
= 0, addr_type
= 0;
7105 struct i40e_pf
*pf
= vsi
->back
;
7108 if (f
->dissector
->used_keys
&
7109 ~(BIT(FLOW_DISSECTOR_KEY_CONTROL
) |
7110 BIT(FLOW_DISSECTOR_KEY_BASIC
) |
7111 BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS
) |
7112 BIT(FLOW_DISSECTOR_KEY_VLAN
) |
7113 BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS
) |
7114 BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS
) |
7115 BIT(FLOW_DISSECTOR_KEY_PORTS
) |
7116 BIT(FLOW_DISSECTOR_KEY_ENC_KEYID
))) {
7117 dev_err(&pf
->pdev
->dev
, "Unsupported key used: 0x%x\n",
7118 f
->dissector
->used_keys
);
7122 if (dissector_uses_key(f
->dissector
, FLOW_DISSECTOR_KEY_ENC_KEYID
)) {
7123 struct flow_dissector_key_keyid
*key
=
7124 skb_flow_dissector_target(f
->dissector
,
7125 FLOW_DISSECTOR_KEY_ENC_KEYID
,
7128 struct flow_dissector_key_keyid
*mask
=
7129 skb_flow_dissector_target(f
->dissector
,
7130 FLOW_DISSECTOR_KEY_ENC_KEYID
,
7133 if (mask
->keyid
!= 0)
7134 field_flags
|= I40E_CLOUD_FIELD_TEN_ID
;
7136 filter
->tenant_id
= be32_to_cpu(key
->keyid
);
7139 if (dissector_uses_key(f
->dissector
, FLOW_DISSECTOR_KEY_BASIC
)) {
7140 struct flow_dissector_key_basic
*key
=
7141 skb_flow_dissector_target(f
->dissector
,
7142 FLOW_DISSECTOR_KEY_BASIC
,
7145 struct flow_dissector_key_basic
*mask
=
7146 skb_flow_dissector_target(f
->dissector
,
7147 FLOW_DISSECTOR_KEY_BASIC
,
7150 n_proto_key
= ntohs(key
->n_proto
);
7151 n_proto_mask
= ntohs(mask
->n_proto
);
7153 if (n_proto_key
== ETH_P_ALL
) {
7157 filter
->n_proto
= n_proto_key
& n_proto_mask
;
7158 filter
->ip_proto
= key
->ip_proto
;
7161 if (dissector_uses_key(f
->dissector
, FLOW_DISSECTOR_KEY_ETH_ADDRS
)) {
7162 struct flow_dissector_key_eth_addrs
*key
=
7163 skb_flow_dissector_target(f
->dissector
,
7164 FLOW_DISSECTOR_KEY_ETH_ADDRS
,
7167 struct flow_dissector_key_eth_addrs
*mask
=
7168 skb_flow_dissector_target(f
->dissector
,
7169 FLOW_DISSECTOR_KEY_ETH_ADDRS
,
7172 /* use is_broadcast and is_zero to check for all 0xf or 0 */
7173 if (!is_zero_ether_addr(mask
->dst
)) {
7174 if (is_broadcast_ether_addr(mask
->dst
)) {
7175 field_flags
|= I40E_CLOUD_FIELD_OMAC
;
7177 dev_err(&pf
->pdev
->dev
, "Bad ether dest mask %pM\n",
7179 return I40E_ERR_CONFIG
;
7183 if (!is_zero_ether_addr(mask
->src
)) {
7184 if (is_broadcast_ether_addr(mask
->src
)) {
7185 field_flags
|= I40E_CLOUD_FIELD_IMAC
;
7187 dev_err(&pf
->pdev
->dev
, "Bad ether src mask %pM\n",
7189 return I40E_ERR_CONFIG
;
7192 ether_addr_copy(filter
->dst_mac
, key
->dst
);
7193 ether_addr_copy(filter
->src_mac
, key
->src
);
7196 if (dissector_uses_key(f
->dissector
, FLOW_DISSECTOR_KEY_VLAN
)) {
7197 struct flow_dissector_key_vlan
*key
=
7198 skb_flow_dissector_target(f
->dissector
,
7199 FLOW_DISSECTOR_KEY_VLAN
,
7201 struct flow_dissector_key_vlan
*mask
=
7202 skb_flow_dissector_target(f
->dissector
,
7203 FLOW_DISSECTOR_KEY_VLAN
,
7206 if (mask
->vlan_id
) {
7207 if (mask
->vlan_id
== VLAN_VID_MASK
) {
7208 field_flags
|= I40E_CLOUD_FIELD_IVLAN
;
7211 dev_err(&pf
->pdev
->dev
, "Bad vlan mask 0x%04x\n",
7213 return I40E_ERR_CONFIG
;
7217 filter
->vlan_id
= cpu_to_be16(key
->vlan_id
);
7220 if (dissector_uses_key(f
->dissector
, FLOW_DISSECTOR_KEY_CONTROL
)) {
7221 struct flow_dissector_key_control
*key
=
7222 skb_flow_dissector_target(f
->dissector
,
7223 FLOW_DISSECTOR_KEY_CONTROL
,
7226 addr_type
= key
->addr_type
;
7229 if (addr_type
== FLOW_DISSECTOR_KEY_IPV4_ADDRS
) {
7230 struct flow_dissector_key_ipv4_addrs
*key
=
7231 skb_flow_dissector_target(f
->dissector
,
7232 FLOW_DISSECTOR_KEY_IPV4_ADDRS
,
7234 struct flow_dissector_key_ipv4_addrs
*mask
=
7235 skb_flow_dissector_target(f
->dissector
,
7236 FLOW_DISSECTOR_KEY_IPV4_ADDRS
,
7240 if (mask
->dst
== cpu_to_be32(0xffffffff)) {
7241 field_flags
|= I40E_CLOUD_FIELD_IIP
;
7243 dev_err(&pf
->pdev
->dev
, "Bad ip dst mask %pI4b\n",
7245 return I40E_ERR_CONFIG
;
7250 if (mask
->src
== cpu_to_be32(0xffffffff)) {
7251 field_flags
|= I40E_CLOUD_FIELD_IIP
;
7253 dev_err(&pf
->pdev
->dev
, "Bad ip src mask %pI4b\n",
7255 return I40E_ERR_CONFIG
;
7259 if (field_flags
& I40E_CLOUD_FIELD_TEN_ID
) {
7260 dev_err(&pf
->pdev
->dev
, "Tenant id not allowed for ip filter\n");
7261 return I40E_ERR_CONFIG
;
7263 filter
->dst_ipv4
= key
->dst
;
7264 filter
->src_ipv4
= key
->src
;
7267 if (addr_type
== FLOW_DISSECTOR_KEY_IPV6_ADDRS
) {
7268 struct flow_dissector_key_ipv6_addrs
*key
=
7269 skb_flow_dissector_target(f
->dissector
,
7270 FLOW_DISSECTOR_KEY_IPV6_ADDRS
,
7272 struct flow_dissector_key_ipv6_addrs
*mask
=
7273 skb_flow_dissector_target(f
->dissector
,
7274 FLOW_DISSECTOR_KEY_IPV6_ADDRS
,
7277 /* src and dest IPV6 address should not be LOOPBACK
7278 * (0:0:0:0:0:0:0:1), which can be represented as ::1
7280 if (ipv6_addr_loopback(&key
->dst
) ||
7281 ipv6_addr_loopback(&key
->src
)) {
7282 dev_err(&pf
->pdev
->dev
,
7283 "Bad ipv6, addr is LOOPBACK\n");
7284 return I40E_ERR_CONFIG
;
7286 if (!ipv6_addr_any(&mask
->dst
) || !ipv6_addr_any(&mask
->src
))
7287 field_flags
|= I40E_CLOUD_FIELD_IIP
;
7289 memcpy(&filter
->src_ipv6
, &key
->src
.s6_addr32
,
7290 sizeof(filter
->src_ipv6
));
7291 memcpy(&filter
->dst_ipv6
, &key
->dst
.s6_addr32
,
7292 sizeof(filter
->dst_ipv6
));
7295 if (dissector_uses_key(f
->dissector
, FLOW_DISSECTOR_KEY_PORTS
)) {
7296 struct flow_dissector_key_ports
*key
=
7297 skb_flow_dissector_target(f
->dissector
,
7298 FLOW_DISSECTOR_KEY_PORTS
,
7300 struct flow_dissector_key_ports
*mask
=
7301 skb_flow_dissector_target(f
->dissector
,
7302 FLOW_DISSECTOR_KEY_PORTS
,
7306 if (mask
->src
== cpu_to_be16(0xffff)) {
7307 field_flags
|= I40E_CLOUD_FIELD_IIP
;
7309 dev_err(&pf
->pdev
->dev
, "Bad src port mask 0x%04x\n",
7310 be16_to_cpu(mask
->src
));
7311 return I40E_ERR_CONFIG
;
7316 if (mask
->dst
== cpu_to_be16(0xffff)) {
7317 field_flags
|= I40E_CLOUD_FIELD_IIP
;
7319 dev_err(&pf
->pdev
->dev
, "Bad dst port mask 0x%04x\n",
7320 be16_to_cpu(mask
->dst
));
7321 return I40E_ERR_CONFIG
;
7325 filter
->dst_port
= key
->dst
;
7326 filter
->src_port
= key
->src
;
7328 switch (filter
->ip_proto
) {
7333 dev_err(&pf
->pdev
->dev
,
7334 "Only UDP and TCP transport are supported\n");
7338 filter
->flags
= field_flags
;
7343 * i40e_handle_tclass: Forward to a traffic class on the device
7344 * @vsi: Pointer to VSI
7345 * @tc: traffic class index on the device
7346 * @filter: Pointer to cloud filter structure
7349 static int i40e_handle_tclass(struct i40e_vsi
*vsi
, u32 tc
,
7350 struct i40e_cloud_filter
*filter
)
7352 struct i40e_channel
*ch
, *ch_tmp
;
7354 /* direct to a traffic class on the same device */
7356 filter
->seid
= vsi
->seid
;
7358 } else if (vsi
->tc_config
.enabled_tc
& BIT(tc
)) {
7359 if (!filter
->dst_port
) {
7360 dev_err(&vsi
->back
->pdev
->dev
,
7361 "Specify destination port to direct to traffic class that is not default\n");
7364 if (list_empty(&vsi
->ch_list
))
7366 list_for_each_entry_safe(ch
, ch_tmp
, &vsi
->ch_list
,
7368 if (ch
->seid
== vsi
->tc_seid_map
[tc
])
7369 filter
->seid
= ch
->seid
;
7373 dev_err(&vsi
->back
->pdev
->dev
, "TC is not enabled\n");
7378 * i40e_configure_clsflower - Configure tc flower filters
7379 * @vsi: Pointer to VSI
7380 * @cls_flower: Pointer to struct tc_cls_flower_offload
7383 static int i40e_configure_clsflower(struct i40e_vsi
*vsi
,
7384 struct tc_cls_flower_offload
*cls_flower
)
7386 int tc
= tc_classid_to_hwtc(vsi
->netdev
, cls_flower
->classid
);
7387 struct i40e_cloud_filter
*filter
= NULL
;
7388 struct i40e_pf
*pf
= vsi
->back
;
7392 dev_err(&vsi
->back
->pdev
->dev
, "Invalid traffic class\n");
7396 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
) ||
7397 test_bit(__I40E_RESET_INTR_RECEIVED
, pf
->state
))
7400 if (pf
->fdir_pf_active_filters
||
7401 (!hlist_empty(&pf
->fdir_filter_list
))) {
7402 dev_err(&vsi
->back
->pdev
->dev
,
7403 "Flow Director Sideband filters exists, turn ntuple off to configure cloud filters\n");
7407 if (vsi
->back
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
7408 dev_err(&vsi
->back
->pdev
->dev
,
7409 "Disable Flow Director Sideband, configuring Cloud filters via tc-flower\n");
7410 vsi
->back
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7411 vsi
->back
->flags
|= I40E_FLAG_FD_SB_TO_CLOUD_FILTER
;
7414 filter
= kzalloc(sizeof(*filter
), GFP_KERNEL
);
7418 filter
->cookie
= cls_flower
->cookie
;
7420 err
= i40e_parse_cls_flower(vsi
, cls_flower
, filter
);
7424 err
= i40e_handle_tclass(vsi
, tc
, filter
);
7428 /* Add cloud filter */
7429 if (filter
->dst_port
)
7430 err
= i40e_add_del_cloud_filter_big_buf(vsi
, filter
, true);
7432 err
= i40e_add_del_cloud_filter(vsi
, filter
, true);
7435 dev_err(&pf
->pdev
->dev
,
7436 "Failed to add cloud filter, err %s\n",
7437 i40e_stat_str(&pf
->hw
, err
));
7441 /* add filter to the ordered list */
7442 INIT_HLIST_NODE(&filter
->cloud_node
);
7444 hlist_add_head(&filter
->cloud_node
, &pf
->cloud_filter_list
);
7446 pf
->num_cloud_filters
++;
7455 * i40e_find_cloud_filter - Find the could filter in the list
7456 * @vsi: Pointer to VSI
7457 * @cookie: filter specific cookie
7460 static struct i40e_cloud_filter
*i40e_find_cloud_filter(struct i40e_vsi
*vsi
,
7461 unsigned long *cookie
)
7463 struct i40e_cloud_filter
*filter
= NULL
;
7464 struct hlist_node
*node2
;
7466 hlist_for_each_entry_safe(filter
, node2
,
7467 &vsi
->back
->cloud_filter_list
, cloud_node
)
7468 if (!memcmp(cookie
, &filter
->cookie
, sizeof(filter
->cookie
)))
7474 * i40e_delete_clsflower - Remove tc flower filters
7475 * @vsi: Pointer to VSI
7476 * @cls_flower: Pointer to struct tc_cls_flower_offload
7479 static int i40e_delete_clsflower(struct i40e_vsi
*vsi
,
7480 struct tc_cls_flower_offload
*cls_flower
)
7482 struct i40e_cloud_filter
*filter
= NULL
;
7483 struct i40e_pf
*pf
= vsi
->back
;
7486 filter
= i40e_find_cloud_filter(vsi
, &cls_flower
->cookie
);
7491 hash_del(&filter
->cloud_node
);
7493 if (filter
->dst_port
)
7494 err
= i40e_add_del_cloud_filter_big_buf(vsi
, filter
, false);
7496 err
= i40e_add_del_cloud_filter(vsi
, filter
, false);
7500 dev_err(&pf
->pdev
->dev
,
7501 "Failed to delete cloud filter, err %s\n",
7502 i40e_stat_str(&pf
->hw
, err
));
7503 return i40e_aq_rc_to_posix(err
, pf
->hw
.aq
.asq_last_status
);
7506 pf
->num_cloud_filters
--;
7507 if (!pf
->num_cloud_filters
)
7508 if ((pf
->flags
& I40E_FLAG_FD_SB_TO_CLOUD_FILTER
) &&
7509 !(pf
->flags
& I40E_FLAG_FD_SB_INACTIVE
)) {
7510 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
7511 pf
->flags
&= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER
;
7512 pf
->flags
&= ~I40E_FLAG_FD_SB_INACTIVE
;
7518 * i40e_setup_tc_cls_flower - flower classifier offloads
7519 * @netdev: net device to configure
7520 * @type_data: offload data
7522 static int i40e_setup_tc_cls_flower(struct i40e_netdev_priv
*np
,
7523 struct tc_cls_flower_offload
*cls_flower
)
7525 struct i40e_vsi
*vsi
= np
->vsi
;
7527 switch (cls_flower
->command
) {
7528 case TC_CLSFLOWER_REPLACE
:
7529 return i40e_configure_clsflower(vsi
, cls_flower
);
7530 case TC_CLSFLOWER_DESTROY
:
7531 return i40e_delete_clsflower(vsi
, cls_flower
);
7532 case TC_CLSFLOWER_STATS
:
7539 static int i40e_setup_tc_block_cb(enum tc_setup_type type
, void *type_data
,
7542 struct i40e_netdev_priv
*np
= cb_priv
;
7544 if (!tc_cls_can_offload_and_chain0(np
->vsi
->netdev
, type_data
))
7548 case TC_SETUP_CLSFLOWER
:
7549 return i40e_setup_tc_cls_flower(np
, type_data
);
7556 static int i40e_setup_tc_block(struct net_device
*dev
,
7557 struct tc_block_offload
*f
)
7559 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
7561 if (f
->binder_type
!= TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS
)
7564 switch (f
->command
) {
7566 return tcf_block_cb_register(f
->block
, i40e_setup_tc_block_cb
,
7568 case TC_BLOCK_UNBIND
:
7569 tcf_block_cb_unregister(f
->block
, i40e_setup_tc_block_cb
, np
);
7576 static int __i40e_setup_tc(struct net_device
*netdev
, enum tc_setup_type type
,
7580 case TC_SETUP_QDISC_MQPRIO
:
7581 return i40e_setup_tc(netdev
, type_data
);
7582 case TC_SETUP_BLOCK
:
7583 return i40e_setup_tc_block(netdev
, type_data
);
7590 * i40e_open - Called when a network interface is made active
7591 * @netdev: network interface device structure
7593 * The open entry point is called when a network interface is made
7594 * active by the system (IFF_UP). At this point all resources needed
7595 * for transmit and receive operations are allocated, the interrupt
7596 * handler is registered with the OS, the netdev watchdog subtask is
7597 * enabled, and the stack is notified that the interface is ready.
7599 * Returns 0 on success, negative value on failure
7601 int i40e_open(struct net_device
*netdev
)
7603 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7604 struct i40e_vsi
*vsi
= np
->vsi
;
7605 struct i40e_pf
*pf
= vsi
->back
;
7608 /* disallow open during test or if eeprom is broken */
7609 if (test_bit(__I40E_TESTING
, pf
->state
) ||
7610 test_bit(__I40E_BAD_EEPROM
, pf
->state
))
7613 netif_carrier_off(netdev
);
7615 if (i40e_force_link_state(pf
, true))
7618 err
= i40e_vsi_open(vsi
);
7622 /* configure global TSO hardware offload settings */
7623 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_F
, be32_to_cpu(TCP_FLAG_PSH
|
7624 TCP_FLAG_FIN
) >> 16);
7625 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_M
, be32_to_cpu(TCP_FLAG_PSH
|
7627 TCP_FLAG_CWR
) >> 16);
7628 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_L
, be32_to_cpu(TCP_FLAG_CWR
) >> 16);
7630 udp_tunnel_get_rx_info(netdev
);
7637 * @vsi: the VSI to open
7639 * Finish initialization of the VSI.
7641 * Returns 0 on success, negative value on failure
7643 * Note: expects to be called while under rtnl_lock()
7645 int i40e_vsi_open(struct i40e_vsi
*vsi
)
7647 struct i40e_pf
*pf
= vsi
->back
;
7648 char int_name
[I40E_INT_NAME_STR_LEN
];
7651 /* allocate descriptors */
7652 err
= i40e_vsi_setup_tx_resources(vsi
);
7655 err
= i40e_vsi_setup_rx_resources(vsi
);
7659 err
= i40e_vsi_configure(vsi
);
7664 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s",
7665 dev_driver_string(&pf
->pdev
->dev
), vsi
->netdev
->name
);
7666 err
= i40e_vsi_request_irq(vsi
, int_name
);
7670 /* Notify the stack of the actual queue counts. */
7671 err
= netif_set_real_num_tx_queues(vsi
->netdev
,
7672 vsi
->num_queue_pairs
);
7674 goto err_set_queues
;
7676 err
= netif_set_real_num_rx_queues(vsi
->netdev
,
7677 vsi
->num_queue_pairs
);
7679 goto err_set_queues
;
7681 } else if (vsi
->type
== I40E_VSI_FDIR
) {
7682 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s:fdir",
7683 dev_driver_string(&pf
->pdev
->dev
),
7684 dev_name(&pf
->pdev
->dev
));
7685 err
= i40e_vsi_request_irq(vsi
, int_name
);
7692 err
= i40e_up_complete(vsi
);
7694 goto err_up_complete
;
7701 i40e_vsi_free_irq(vsi
);
7703 i40e_vsi_free_rx_resources(vsi
);
7705 i40e_vsi_free_tx_resources(vsi
);
7706 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
7707 i40e_do_reset(pf
, I40E_PF_RESET_FLAG
, true);
7713 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
7714 * @pf: Pointer to PF
7716 * This function destroys the hlist where all the Flow Director
7717 * filters were saved.
7719 static void i40e_fdir_filter_exit(struct i40e_pf
*pf
)
7721 struct i40e_fdir_filter
*filter
;
7722 struct i40e_flex_pit
*pit_entry
, *tmp
;
7723 struct hlist_node
*node2
;
7725 hlist_for_each_entry_safe(filter
, node2
,
7726 &pf
->fdir_filter_list
, fdir_node
) {
7727 hlist_del(&filter
->fdir_node
);
7731 list_for_each_entry_safe(pit_entry
, tmp
, &pf
->l3_flex_pit_list
, list
) {
7732 list_del(&pit_entry
->list
);
7735 INIT_LIST_HEAD(&pf
->l3_flex_pit_list
);
7737 list_for_each_entry_safe(pit_entry
, tmp
, &pf
->l4_flex_pit_list
, list
) {
7738 list_del(&pit_entry
->list
);
7741 INIT_LIST_HEAD(&pf
->l4_flex_pit_list
);
7743 pf
->fdir_pf_active_filters
= 0;
7744 pf
->fd_tcp4_filter_cnt
= 0;
7745 pf
->fd_udp4_filter_cnt
= 0;
7746 pf
->fd_sctp4_filter_cnt
= 0;
7747 pf
->fd_ip4_filter_cnt
= 0;
7749 /* Reprogram the default input set for TCP/IPv4 */
7750 i40e_write_fd_input_set(pf
, I40E_FILTER_PCTYPE_NONF_IPV4_TCP
,
7751 I40E_L3_SRC_MASK
| I40E_L3_DST_MASK
|
7752 I40E_L4_SRC_MASK
| I40E_L4_DST_MASK
);
7754 /* Reprogram the default input set for UDP/IPv4 */
7755 i40e_write_fd_input_set(pf
, I40E_FILTER_PCTYPE_NONF_IPV4_UDP
,
7756 I40E_L3_SRC_MASK
| I40E_L3_DST_MASK
|
7757 I40E_L4_SRC_MASK
| I40E_L4_DST_MASK
);
7759 /* Reprogram the default input set for SCTP/IPv4 */
7760 i40e_write_fd_input_set(pf
, I40E_FILTER_PCTYPE_NONF_IPV4_SCTP
,
7761 I40E_L3_SRC_MASK
| I40E_L3_DST_MASK
|
7762 I40E_L4_SRC_MASK
| I40E_L4_DST_MASK
);
7764 /* Reprogram the default input set for Other/IPv4 */
7765 i40e_write_fd_input_set(pf
, I40E_FILTER_PCTYPE_NONF_IPV4_OTHER
,
7766 I40E_L3_SRC_MASK
| I40E_L3_DST_MASK
);
7768 i40e_write_fd_input_set(pf
, I40E_FILTER_PCTYPE_FRAG_IPV4
,
7769 I40E_L3_SRC_MASK
| I40E_L3_DST_MASK
);
7773 * i40e_cloud_filter_exit - Cleans up the cloud filters
7774 * @pf: Pointer to PF
7776 * This function destroys the hlist where all the cloud filters
7779 static void i40e_cloud_filter_exit(struct i40e_pf
*pf
)
7781 struct i40e_cloud_filter
*cfilter
;
7782 struct hlist_node
*node
;
7784 hlist_for_each_entry_safe(cfilter
, node
,
7785 &pf
->cloud_filter_list
, cloud_node
) {
7786 hlist_del(&cfilter
->cloud_node
);
7789 pf
->num_cloud_filters
= 0;
7791 if ((pf
->flags
& I40E_FLAG_FD_SB_TO_CLOUD_FILTER
) &&
7792 !(pf
->flags
& I40E_FLAG_FD_SB_INACTIVE
)) {
7793 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
7794 pf
->flags
&= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER
;
7795 pf
->flags
&= ~I40E_FLAG_FD_SB_INACTIVE
;
7800 * i40e_close - Disables a network interface
7801 * @netdev: network interface device structure
7803 * The close entry point is called when an interface is de-activated
7804 * by the OS. The hardware is still under the driver's control, but
7805 * this netdev interface is disabled.
7807 * Returns 0, this is not allowed to fail
7809 int i40e_close(struct net_device
*netdev
)
7811 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7812 struct i40e_vsi
*vsi
= np
->vsi
;
7814 i40e_vsi_close(vsi
);
7820 * i40e_do_reset - Start a PF or Core Reset sequence
7821 * @pf: board private structure
7822 * @reset_flags: which reset is requested
7823 * @lock_acquired: indicates whether or not the lock has been acquired
7824 * before this function was called.
7826 * The essential difference in resets is that the PF Reset
7827 * doesn't clear the packet buffers, doesn't reset the PE
7828 * firmware, and doesn't bother the other PFs on the chip.
7830 void i40e_do_reset(struct i40e_pf
*pf
, u32 reset_flags
, bool lock_acquired
)
7834 WARN_ON(in_interrupt());
7837 /* do the biggest reset indicated */
7838 if (reset_flags
& BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED
)) {
7840 /* Request a Global Reset
7842 * This will start the chip's countdown to the actual full
7843 * chip reset event, and a warning interrupt to be sent
7844 * to all PFs, including the requestor. Our handler
7845 * for the warning interrupt will deal with the shutdown
7846 * and recovery of the switch setup.
7848 dev_dbg(&pf
->pdev
->dev
, "GlobalR requested\n");
7849 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
7850 val
|= I40E_GLGEN_RTRIG_GLOBR_MASK
;
7851 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
7853 } else if (reset_flags
& BIT_ULL(__I40E_CORE_RESET_REQUESTED
)) {
7855 /* Request a Core Reset
7857 * Same as Global Reset, except does *not* include the MAC/PHY
7859 dev_dbg(&pf
->pdev
->dev
, "CoreR requested\n");
7860 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
7861 val
|= I40E_GLGEN_RTRIG_CORER_MASK
;
7862 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
7863 i40e_flush(&pf
->hw
);
7865 } else if (reset_flags
& I40E_PF_RESET_FLAG
) {
7867 /* Request a PF Reset
7869 * Resets only the PF-specific registers
7871 * This goes directly to the tear-down and rebuild of
7872 * the switch, since we need to do all the recovery as
7873 * for the Core Reset.
7875 dev_dbg(&pf
->pdev
->dev
, "PFR requested\n");
7876 i40e_handle_reset_warning(pf
, lock_acquired
);
7878 } else if (reset_flags
& BIT_ULL(__I40E_REINIT_REQUESTED
)) {
7881 /* Find the VSI(s) that requested a re-init */
7882 dev_info(&pf
->pdev
->dev
,
7883 "VSI reinit requested\n");
7884 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
7885 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
7888 test_and_clear_bit(__I40E_VSI_REINIT_REQUESTED
,
7890 i40e_vsi_reinit_locked(pf
->vsi
[v
]);
7892 } else if (reset_flags
& BIT_ULL(__I40E_DOWN_REQUESTED
)) {
7895 /* Find the VSI(s) that needs to be brought down */
7896 dev_info(&pf
->pdev
->dev
, "VSI down requested\n");
7897 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
7898 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
7901 test_and_clear_bit(__I40E_VSI_DOWN_REQUESTED
,
7903 set_bit(__I40E_VSI_DOWN
, vsi
->state
);
7908 dev_info(&pf
->pdev
->dev
,
7909 "bad reset request 0x%08x\n", reset_flags
);
7913 #ifdef CONFIG_I40E_DCB
7915 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
7916 * @pf: board private structure
7917 * @old_cfg: current DCB config
7918 * @new_cfg: new DCB config
7920 bool i40e_dcb_need_reconfig(struct i40e_pf
*pf
,
7921 struct i40e_dcbx_config
*old_cfg
,
7922 struct i40e_dcbx_config
*new_cfg
)
7924 bool need_reconfig
= false;
7926 /* Check if ETS configuration has changed */
7927 if (memcmp(&new_cfg
->etscfg
,
7929 sizeof(new_cfg
->etscfg
))) {
7930 /* If Priority Table has changed reconfig is needed */
7931 if (memcmp(&new_cfg
->etscfg
.prioritytable
,
7932 &old_cfg
->etscfg
.prioritytable
,
7933 sizeof(new_cfg
->etscfg
.prioritytable
))) {
7934 need_reconfig
= true;
7935 dev_dbg(&pf
->pdev
->dev
, "ETS UP2TC changed.\n");
7938 if (memcmp(&new_cfg
->etscfg
.tcbwtable
,
7939 &old_cfg
->etscfg
.tcbwtable
,
7940 sizeof(new_cfg
->etscfg
.tcbwtable
)))
7941 dev_dbg(&pf
->pdev
->dev
, "ETS TC BW Table changed.\n");
7943 if (memcmp(&new_cfg
->etscfg
.tsatable
,
7944 &old_cfg
->etscfg
.tsatable
,
7945 sizeof(new_cfg
->etscfg
.tsatable
)))
7946 dev_dbg(&pf
->pdev
->dev
, "ETS TSA Table changed.\n");
7949 /* Check if PFC configuration has changed */
7950 if (memcmp(&new_cfg
->pfc
,
7952 sizeof(new_cfg
->pfc
))) {
7953 need_reconfig
= true;
7954 dev_dbg(&pf
->pdev
->dev
, "PFC config change detected.\n");
7957 /* Check if APP Table has changed */
7958 if (memcmp(&new_cfg
->app
,
7960 sizeof(new_cfg
->app
))) {
7961 need_reconfig
= true;
7962 dev_dbg(&pf
->pdev
->dev
, "APP Table change detected.\n");
7965 dev_dbg(&pf
->pdev
->dev
, "dcb need_reconfig=%d\n", need_reconfig
);
7966 return need_reconfig
;
7970 * i40e_handle_lldp_event - Handle LLDP Change MIB event
7971 * @pf: board private structure
7972 * @e: event info posted on ARQ
7974 static int i40e_handle_lldp_event(struct i40e_pf
*pf
,
7975 struct i40e_arq_event_info
*e
)
7977 struct i40e_aqc_lldp_get_mib
*mib
=
7978 (struct i40e_aqc_lldp_get_mib
*)&e
->desc
.params
.raw
;
7979 struct i40e_hw
*hw
= &pf
->hw
;
7980 struct i40e_dcbx_config tmp_dcbx_cfg
;
7981 bool need_reconfig
= false;
7985 /* Not DCB capable or capability disabled */
7986 if (!(pf
->flags
& I40E_FLAG_DCB_CAPABLE
))
7989 /* Ignore if event is not for Nearest Bridge */
7990 type
= ((mib
->type
>> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT
)
7991 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK
);
7992 dev_dbg(&pf
->pdev
->dev
, "LLDP event mib bridge type 0x%x\n", type
);
7993 if (type
!= I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
)
7996 /* Check MIB Type and return if event for Remote MIB update */
7997 type
= mib
->type
& I40E_AQ_LLDP_MIB_TYPE_MASK
;
7998 dev_dbg(&pf
->pdev
->dev
,
7999 "LLDP event mib type %s\n", type
? "remote" : "local");
8000 if (type
== I40E_AQ_LLDP_MIB_REMOTE
) {
8001 /* Update the remote cached instance and return */
8002 ret
= i40e_aq_get_dcb_config(hw
, I40E_AQ_LLDP_MIB_REMOTE
,
8003 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
,
8004 &hw
->remote_dcbx_config
);
8008 /* Store the old configuration */
8009 tmp_dcbx_cfg
= hw
->local_dcbx_config
;
8011 /* Reset the old DCBx configuration data */
8012 memset(&hw
->local_dcbx_config
, 0, sizeof(hw
->local_dcbx_config
));
8013 /* Get updated DCBX data from firmware */
8014 ret
= i40e_get_dcb_config(&pf
->hw
);
8016 dev_info(&pf
->pdev
->dev
,
8017 "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
8018 i40e_stat_str(&pf
->hw
, ret
),
8019 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
8023 /* No change detected in DCBX configs */
8024 if (!memcmp(&tmp_dcbx_cfg
, &hw
->local_dcbx_config
,
8025 sizeof(tmp_dcbx_cfg
))) {
8026 dev_dbg(&pf
->pdev
->dev
, "No change detected in DCBX configuration.\n");
8030 need_reconfig
= i40e_dcb_need_reconfig(pf
, &tmp_dcbx_cfg
,
8031 &hw
->local_dcbx_config
);
8033 i40e_dcbnl_flush_apps(pf
, &tmp_dcbx_cfg
, &hw
->local_dcbx_config
);
8038 /* Enable DCB tagging only when more than one TC */
8039 if (i40e_dcb_get_num_tc(&hw
->local_dcbx_config
) > 1)
8040 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
8042 pf
->flags
&= ~I40E_FLAG_DCB_ENABLED
;
8044 set_bit(__I40E_PORT_SUSPENDED
, pf
->state
);
8045 /* Reconfiguration needed quiesce all VSIs */
8046 i40e_pf_quiesce_all_vsi(pf
);
8048 /* Changes in configuration update VEB/VSI */
8049 i40e_dcb_reconfigure(pf
);
8051 ret
= i40e_resume_port_tx(pf
);
8053 clear_bit(__I40E_PORT_SUSPENDED
, pf
->state
);
8054 /* In case of error no point in resuming VSIs */
8058 /* Wait for the PF's queues to be disabled */
8059 ret
= i40e_pf_wait_queues_disabled(pf
);
8061 /* Schedule PF reset to recover */
8062 set_bit(__I40E_PF_RESET_REQUESTED
, pf
->state
);
8063 i40e_service_event_schedule(pf
);
8065 i40e_pf_unquiesce_all_vsi(pf
);
8066 set_bit(__I40E_CLIENT_SERVICE_REQUESTED
, pf
->state
);
8067 set_bit(__I40E_CLIENT_L2_CHANGE
, pf
->state
);
8073 #endif /* CONFIG_I40E_DCB */
8076 * i40e_do_reset_safe - Protected reset path for userland calls.
8077 * @pf: board private structure
8078 * @reset_flags: which reset is requested
8081 void i40e_do_reset_safe(struct i40e_pf
*pf
, u32 reset_flags
)
8084 i40e_do_reset(pf
, reset_flags
, true);
8089 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
8090 * @pf: board private structure
8091 * @e: event info posted on ARQ
8093 * Handler for LAN Queue Overflow Event generated by the firmware for PF
8096 static void i40e_handle_lan_overflow_event(struct i40e_pf
*pf
,
8097 struct i40e_arq_event_info
*e
)
8099 struct i40e_aqc_lan_overflow
*data
=
8100 (struct i40e_aqc_lan_overflow
*)&e
->desc
.params
.raw
;
8101 u32 queue
= le32_to_cpu(data
->prtdcb_rupto
);
8102 u32 qtx_ctl
= le32_to_cpu(data
->otx_ctl
);
8103 struct i40e_hw
*hw
= &pf
->hw
;
8107 dev_dbg(&pf
->pdev
->dev
, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
8110 /* Queue belongs to VF, find the VF and issue VF reset */
8111 if (((qtx_ctl
& I40E_QTX_CTL_PFVF_Q_MASK
)
8112 >> I40E_QTX_CTL_PFVF_Q_SHIFT
) == I40E_QTX_CTL_VF_QUEUE
) {
8113 vf_id
= (u16
)((qtx_ctl
& I40E_QTX_CTL_VFVM_INDX_MASK
)
8114 >> I40E_QTX_CTL_VFVM_INDX_SHIFT
);
8115 vf_id
-= hw
->func_caps
.vf_base_id
;
8116 vf
= &pf
->vf
[vf_id
];
8117 i40e_vc_notify_vf_reset(vf
);
8118 /* Allow VF to process pending reset notification */
8120 i40e_reset_vf(vf
, false);
8125 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
8126 * @pf: board private structure
8128 u32
i40e_get_cur_guaranteed_fd_count(struct i40e_pf
*pf
)
8132 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
8133 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
);
8138 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
8139 * @pf: board private structure
8141 u32
i40e_get_current_fd_count(struct i40e_pf
*pf
)
8145 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
8146 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
) +
8147 ((val
& I40E_PFQF_FDSTAT_BEST_CNT_MASK
) >>
8148 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT
);
8153 * i40e_get_global_fd_count - Get total FD filters programmed on device
8154 * @pf: board private structure
8156 u32
i40e_get_global_fd_count(struct i40e_pf
*pf
)
8160 val
= rd32(&pf
->hw
, I40E_GLQF_FDCNT_0
);
8161 fcnt_prog
= (val
& I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK
) +
8162 ((val
& I40E_GLQF_FDCNT_0_BESTCNT_MASK
) >>
8163 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT
);
8168 * i40e_reenable_fdir_sb - Restore FDir SB capability
8169 * @pf: board private structure
8171 static void i40e_reenable_fdir_sb(struct i40e_pf
*pf
)
8173 if (test_and_clear_bit(__I40E_FD_SB_AUTO_DISABLED
, pf
->state
))
8174 if ((pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) &&
8175 (I40E_DEBUG_FD
& pf
->hw
.debug_mask
))
8176 dev_info(&pf
->pdev
->dev
, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
8180 * i40e_reenable_fdir_atr - Restore FDir ATR capability
8181 * @pf: board private structure
8183 static void i40e_reenable_fdir_atr(struct i40e_pf
*pf
)
8185 if (test_and_clear_bit(__I40E_FD_ATR_AUTO_DISABLED
, pf
->state
)) {
8186 /* ATR uses the same filtering logic as SB rules. It only
8187 * functions properly if the input set mask is at the default
8188 * settings. It is safe to restore the default input set
8189 * because there are no active TCPv4 filter rules.
8191 i40e_write_fd_input_set(pf
, I40E_FILTER_PCTYPE_NONF_IPV4_TCP
,
8192 I40E_L3_SRC_MASK
| I40E_L3_DST_MASK
|
8193 I40E_L4_SRC_MASK
| I40E_L4_DST_MASK
);
8195 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
8196 (I40E_DEBUG_FD
& pf
->hw
.debug_mask
))
8197 dev_info(&pf
->pdev
->dev
, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n");
8202 * i40e_delete_invalid_filter - Delete an invalid FDIR filter
8203 * @pf: board private structure
8204 * @filter: FDir filter to remove
8206 static void i40e_delete_invalid_filter(struct i40e_pf
*pf
,
8207 struct i40e_fdir_filter
*filter
)
8209 /* Update counters */
8210 pf
->fdir_pf_active_filters
--;
8213 switch (filter
->flow_type
) {
8215 pf
->fd_tcp4_filter_cnt
--;
8218 pf
->fd_udp4_filter_cnt
--;
8221 pf
->fd_sctp4_filter_cnt
--;
8224 switch (filter
->ip4_proto
) {
8226 pf
->fd_tcp4_filter_cnt
--;
8229 pf
->fd_udp4_filter_cnt
--;
8232 pf
->fd_sctp4_filter_cnt
--;
8235 pf
->fd_ip4_filter_cnt
--;
8241 /* Remove the filter from the list and free memory */
8242 hlist_del(&filter
->fdir_node
);
8247 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
8248 * @pf: board private structure
8250 void i40e_fdir_check_and_reenable(struct i40e_pf
*pf
)
8252 struct i40e_fdir_filter
*filter
;
8253 u32 fcnt_prog
, fcnt_avail
;
8254 struct hlist_node
*node
;
8256 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, pf
->state
))
8259 /* Check if we have enough room to re-enable FDir SB capability. */
8260 fcnt_prog
= i40e_get_global_fd_count(pf
);
8261 fcnt_avail
= pf
->fdir_pf_filter_count
;
8262 if ((fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM
)) ||
8263 (pf
->fd_add_err
== 0) ||
8264 (i40e_get_current_atr_cnt(pf
) < pf
->fd_atr_cnt
))
8265 i40e_reenable_fdir_sb(pf
);
8267 /* We should wait for even more space before re-enabling ATR.
8268 * Additionally, we cannot enable ATR as long as we still have TCP SB
8271 if ((fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR
)) &&
8272 (pf
->fd_tcp4_filter_cnt
== 0))
8273 i40e_reenable_fdir_atr(pf
);
8275 /* if hw had a problem adding a filter, delete it */
8276 if (pf
->fd_inv
> 0) {
8277 hlist_for_each_entry_safe(filter
, node
,
8278 &pf
->fdir_filter_list
, fdir_node
)
8279 if (filter
->fd_id
== pf
->fd_inv
)
8280 i40e_delete_invalid_filter(pf
, filter
);
8284 #define I40E_MIN_FD_FLUSH_INTERVAL 10
8285 #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
8287 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
8288 * @pf: board private structure
8290 static void i40e_fdir_flush_and_replay(struct i40e_pf
*pf
)
8292 unsigned long min_flush_time
;
8293 int flush_wait_retry
= 50;
8294 bool disable_atr
= false;
8298 if (!time_after(jiffies
, pf
->fd_flush_timestamp
+
8299 (I40E_MIN_FD_FLUSH_INTERVAL
* HZ
)))
8302 /* If the flush is happening too quick and we have mostly SB rules we
8303 * should not re-enable ATR for some time.
8305 min_flush_time
= pf
->fd_flush_timestamp
+
8306 (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE
* HZ
);
8307 fd_room
= pf
->fdir_pf_filter_count
- pf
->fdir_pf_active_filters
;
8309 if (!(time_after(jiffies
, min_flush_time
)) &&
8310 (fd_room
< I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR
)) {
8311 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
8312 dev_info(&pf
->pdev
->dev
, "ATR disabled, not enough FD filter space.\n");
8316 pf
->fd_flush_timestamp
= jiffies
;
8317 set_bit(__I40E_FD_ATR_AUTO_DISABLED
, pf
->state
);
8318 /* flush all filters */
8319 wr32(&pf
->hw
, I40E_PFQF_CTL_1
,
8320 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
);
8321 i40e_flush(&pf
->hw
);
8325 /* Check FD flush status every 5-6msec */
8326 usleep_range(5000, 6000);
8327 reg
= rd32(&pf
->hw
, I40E_PFQF_CTL_1
);
8328 if (!(reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
))
8330 } while (flush_wait_retry
--);
8331 if (reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
) {
8332 dev_warn(&pf
->pdev
->dev
, "FD table did not flush, needs more time\n");
8334 /* replay sideband filters */
8335 i40e_fdir_filter_restore(pf
->vsi
[pf
->lan_vsi
]);
8336 if (!disable_atr
&& !pf
->fd_tcp4_filter_cnt
)
8337 clear_bit(__I40E_FD_ATR_AUTO_DISABLED
, pf
->state
);
8338 clear_bit(__I40E_FD_FLUSH_REQUESTED
, pf
->state
);
8339 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
8340 dev_info(&pf
->pdev
->dev
, "FD Filter table flushed and FD-SB replayed.\n");
8345 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
8346 * @pf: board private structure
8348 u32
i40e_get_current_atr_cnt(struct i40e_pf
*pf
)
8350 return i40e_get_current_fd_count(pf
) - pf
->fdir_pf_active_filters
;
8353 /* We can see up to 256 filter programming desc in transit if the filters are
8354 * being applied really fast; before we see the first
8355 * filter miss error on Rx queue 0. Accumulating enough error messages before
8356 * reacting will make sure we don't cause flush too often.
8358 #define I40E_MAX_FD_PROGRAM_ERROR 256
8361 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
8362 * @pf: board private structure
8364 static void i40e_fdir_reinit_subtask(struct i40e_pf
*pf
)
8367 /* if interface is down do nothing */
8368 if (test_bit(__I40E_DOWN
, pf
->state
))
8371 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, pf
->state
))
8372 i40e_fdir_flush_and_replay(pf
);
8374 i40e_fdir_check_and_reenable(pf
);
8379 * i40e_vsi_link_event - notify VSI of a link event
8380 * @vsi: vsi to be notified
8381 * @link_up: link up or down
8383 static void i40e_vsi_link_event(struct i40e_vsi
*vsi
, bool link_up
)
8385 if (!vsi
|| test_bit(__I40E_VSI_DOWN
, vsi
->state
))
8388 switch (vsi
->type
) {
8390 if (!vsi
->netdev
|| !vsi
->netdev_registered
)
8394 netif_carrier_on(vsi
->netdev
);
8395 netif_tx_wake_all_queues(vsi
->netdev
);
8397 netif_carrier_off(vsi
->netdev
);
8398 netif_tx_stop_all_queues(vsi
->netdev
);
8402 case I40E_VSI_SRIOV
:
8403 case I40E_VSI_VMDQ2
:
8405 case I40E_VSI_IWARP
:
8406 case I40E_VSI_MIRROR
:
8408 /* there is no notification for other VSIs */
8414 * i40e_veb_link_event - notify elements on the veb of a link event
8415 * @veb: veb to be notified
8416 * @link_up: link up or down
8418 static void i40e_veb_link_event(struct i40e_veb
*veb
, bool link_up
)
8423 if (!veb
|| !veb
->pf
)
8427 /* depth first... */
8428 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
8429 if (pf
->veb
[i
] && (pf
->veb
[i
]->uplink_seid
== veb
->seid
))
8430 i40e_veb_link_event(pf
->veb
[i
], link_up
);
8432 /* ... now the local VSIs */
8433 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
8434 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->uplink_seid
== veb
->seid
))
8435 i40e_vsi_link_event(pf
->vsi
[i
], link_up
);
8439 * i40e_link_event - Update netif_carrier status
8440 * @pf: board private structure
8442 static void i40e_link_event(struct i40e_pf
*pf
)
8444 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
8445 u8 new_link_speed
, old_link_speed
;
8447 bool new_link
, old_link
;
8449 /* save off old link status information */
8450 pf
->hw
.phy
.link_info_old
= pf
->hw
.phy
.link_info
;
8452 /* set this to force the get_link_status call to refresh state */
8453 pf
->hw
.phy
.get_link_info
= true;
8455 old_link
= (pf
->hw
.phy
.link_info_old
.link_info
& I40E_AQ_LINK_UP
);
8457 status
= i40e_get_link_status(&pf
->hw
, &new_link
);
8459 /* On success, disable temp link polling */
8460 if (status
== I40E_SUCCESS
) {
8461 clear_bit(__I40E_TEMP_LINK_POLLING
, pf
->state
);
8463 /* Enable link polling temporarily until i40e_get_link_status
8464 * returns I40E_SUCCESS
8466 set_bit(__I40E_TEMP_LINK_POLLING
, pf
->state
);
8467 dev_dbg(&pf
->pdev
->dev
, "couldn't get link state, status: %d\n",
8472 old_link_speed
= pf
->hw
.phy
.link_info_old
.link_speed
;
8473 new_link_speed
= pf
->hw
.phy
.link_info
.link_speed
;
8475 if (new_link
== old_link
&&
8476 new_link_speed
== old_link_speed
&&
8477 (test_bit(__I40E_VSI_DOWN
, vsi
->state
) ||
8478 new_link
== netif_carrier_ok(vsi
->netdev
)))
8481 i40e_print_link_message(vsi
, new_link
);
8483 /* Notify the base of the switch tree connected to
8484 * the link. Floating VEBs are not notified.
8486 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
8487 i40e_veb_link_event(pf
->veb
[pf
->lan_veb
], new_link
);
8489 i40e_vsi_link_event(vsi
, new_link
);
8492 i40e_vc_notify_link_state(pf
);
8494 if (pf
->flags
& I40E_FLAG_PTP
)
8495 i40e_ptp_set_increment(pf
);
8499 * i40e_watchdog_subtask - periodic checks not using event driven response
8500 * @pf: board private structure
8502 static void i40e_watchdog_subtask(struct i40e_pf
*pf
)
8506 /* if interface is down do nothing */
8507 if (test_bit(__I40E_DOWN
, pf
->state
) ||
8508 test_bit(__I40E_CONFIG_BUSY
, pf
->state
))
8511 /* make sure we don't do these things too often */
8512 if (time_before(jiffies
, (pf
->service_timer_previous
+
8513 pf
->service_timer_period
)))
8515 pf
->service_timer_previous
= jiffies
;
8517 if ((pf
->flags
& I40E_FLAG_LINK_POLLING_ENABLED
) ||
8518 test_bit(__I40E_TEMP_LINK_POLLING
, pf
->state
))
8519 i40e_link_event(pf
);
8521 /* Update the stats for active netdevs so the network stack
8522 * can look at updated numbers whenever it cares to
8524 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
8525 if (pf
->vsi
[i
] && pf
->vsi
[i
]->netdev
)
8526 i40e_update_stats(pf
->vsi
[i
]);
8528 if (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
) {
8529 /* Update the stats for the active switching components */
8530 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
8532 i40e_update_veb_stats(pf
->veb
[i
]);
8535 i40e_ptp_rx_hang(pf
);
8536 i40e_ptp_tx_hang(pf
);
8540 * i40e_reset_subtask - Set up for resetting the device and driver
8541 * @pf: board private structure
8543 static void i40e_reset_subtask(struct i40e_pf
*pf
)
8545 u32 reset_flags
= 0;
8547 if (test_bit(__I40E_REINIT_REQUESTED
, pf
->state
)) {
8548 reset_flags
|= BIT(__I40E_REINIT_REQUESTED
);
8549 clear_bit(__I40E_REINIT_REQUESTED
, pf
->state
);
8551 if (test_bit(__I40E_PF_RESET_REQUESTED
, pf
->state
)) {
8552 reset_flags
|= BIT(__I40E_PF_RESET_REQUESTED
);
8553 clear_bit(__I40E_PF_RESET_REQUESTED
, pf
->state
);
8555 if (test_bit(__I40E_CORE_RESET_REQUESTED
, pf
->state
)) {
8556 reset_flags
|= BIT(__I40E_CORE_RESET_REQUESTED
);
8557 clear_bit(__I40E_CORE_RESET_REQUESTED
, pf
->state
);
8559 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED
, pf
->state
)) {
8560 reset_flags
|= BIT(__I40E_GLOBAL_RESET_REQUESTED
);
8561 clear_bit(__I40E_GLOBAL_RESET_REQUESTED
, pf
->state
);
8563 if (test_bit(__I40E_DOWN_REQUESTED
, pf
->state
)) {
8564 reset_flags
|= BIT(__I40E_DOWN_REQUESTED
);
8565 clear_bit(__I40E_DOWN_REQUESTED
, pf
->state
);
8568 /* If there's a recovery already waiting, it takes
8569 * precedence before starting a new reset sequence.
8571 if (test_bit(__I40E_RESET_INTR_RECEIVED
, pf
->state
)) {
8572 i40e_prep_for_reset(pf
, false);
8574 i40e_rebuild(pf
, false, false);
8577 /* If we're already down or resetting, just bail */
8579 !test_bit(__I40E_DOWN
, pf
->state
) &&
8580 !test_bit(__I40E_CONFIG_BUSY
, pf
->state
)) {
8581 i40e_do_reset(pf
, reset_flags
, false);
8586 * i40e_handle_link_event - Handle link event
8587 * @pf: board private structure
8588 * @e: event info posted on ARQ
8590 static void i40e_handle_link_event(struct i40e_pf
*pf
,
8591 struct i40e_arq_event_info
*e
)
8593 struct i40e_aqc_get_link_status
*status
=
8594 (struct i40e_aqc_get_link_status
*)&e
->desc
.params
.raw
;
8596 /* Do a new status request to re-enable LSE reporting
8597 * and load new status information into the hw struct
8598 * This completely ignores any state information
8599 * in the ARQ event info, instead choosing to always
8600 * issue the AQ update link status command.
8602 i40e_link_event(pf
);
8604 /* Check if module meets thermal requirements */
8605 if (status
->phy_type
== I40E_PHY_TYPE_NOT_SUPPORTED_HIGH_TEMP
) {
8606 dev_err(&pf
->pdev
->dev
,
8607 "Rx/Tx is disabled on this device because the module does not meet thermal requirements.\n");
8608 dev_err(&pf
->pdev
->dev
,
8609 "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
8611 /* check for unqualified module, if link is down, suppress
8612 * the message if link was forced to be down.
8614 if ((status
->link_info
& I40E_AQ_MEDIA_AVAILABLE
) &&
8615 (!(status
->an_info
& I40E_AQ_QUALIFIED_MODULE
)) &&
8616 (!(status
->link_info
& I40E_AQ_LINK_UP
)) &&
8617 (!(pf
->flags
& I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED
))) {
8618 dev_err(&pf
->pdev
->dev
,
8619 "Rx/Tx is disabled on this device because an unsupported SFP module type was detected.\n");
8620 dev_err(&pf
->pdev
->dev
,
8621 "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
8627 * i40e_clean_adminq_subtask - Clean the AdminQ rings
8628 * @pf: board private structure
8630 static void i40e_clean_adminq_subtask(struct i40e_pf
*pf
)
8632 struct i40e_arq_event_info event
;
8633 struct i40e_hw
*hw
= &pf
->hw
;
8640 /* Do not run clean AQ when PF reset fails */
8641 if (test_bit(__I40E_RESET_FAILED
, pf
->state
))
8644 /* check for error indications */
8645 val
= rd32(&pf
->hw
, pf
->hw
.aq
.arq
.len
);
8647 if (val
& I40E_PF_ARQLEN_ARQVFE_MASK
) {
8648 if (hw
->debug_mask
& I40E_DEBUG_AQ
)
8649 dev_info(&pf
->pdev
->dev
, "ARQ VF Error detected\n");
8650 val
&= ~I40E_PF_ARQLEN_ARQVFE_MASK
;
8652 if (val
& I40E_PF_ARQLEN_ARQOVFL_MASK
) {
8653 if (hw
->debug_mask
& I40E_DEBUG_AQ
)
8654 dev_info(&pf
->pdev
->dev
, "ARQ Overflow Error detected\n");
8655 val
&= ~I40E_PF_ARQLEN_ARQOVFL_MASK
;
8656 pf
->arq_overflows
++;
8658 if (val
& I40E_PF_ARQLEN_ARQCRIT_MASK
) {
8659 if (hw
->debug_mask
& I40E_DEBUG_AQ
)
8660 dev_info(&pf
->pdev
->dev
, "ARQ Critical Error detected\n");
8661 val
&= ~I40E_PF_ARQLEN_ARQCRIT_MASK
;
8664 wr32(&pf
->hw
, pf
->hw
.aq
.arq
.len
, val
);
8666 val
= rd32(&pf
->hw
, pf
->hw
.aq
.asq
.len
);
8668 if (val
& I40E_PF_ATQLEN_ATQVFE_MASK
) {
8669 if (pf
->hw
.debug_mask
& I40E_DEBUG_AQ
)
8670 dev_info(&pf
->pdev
->dev
, "ASQ VF Error detected\n");
8671 val
&= ~I40E_PF_ATQLEN_ATQVFE_MASK
;
8673 if (val
& I40E_PF_ATQLEN_ATQOVFL_MASK
) {
8674 if (pf
->hw
.debug_mask
& I40E_DEBUG_AQ
)
8675 dev_info(&pf
->pdev
->dev
, "ASQ Overflow Error detected\n");
8676 val
&= ~I40E_PF_ATQLEN_ATQOVFL_MASK
;
8678 if (val
& I40E_PF_ATQLEN_ATQCRIT_MASK
) {
8679 if (pf
->hw
.debug_mask
& I40E_DEBUG_AQ
)
8680 dev_info(&pf
->pdev
->dev
, "ASQ Critical Error detected\n");
8681 val
&= ~I40E_PF_ATQLEN_ATQCRIT_MASK
;
8684 wr32(&pf
->hw
, pf
->hw
.aq
.asq
.len
, val
);
8686 event
.buf_len
= I40E_MAX_AQ_BUF_SIZE
;
8687 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
8692 ret
= i40e_clean_arq_element(hw
, &event
, &pending
);
8693 if (ret
== I40E_ERR_ADMIN_QUEUE_NO_WORK
)
8696 dev_info(&pf
->pdev
->dev
, "ARQ event error %d\n", ret
);
8700 opcode
= le16_to_cpu(event
.desc
.opcode
);
8703 case i40e_aqc_opc_get_link_status
:
8704 i40e_handle_link_event(pf
, &event
);
8706 case i40e_aqc_opc_send_msg_to_pf
:
8707 ret
= i40e_vc_process_vf_msg(pf
,
8708 le16_to_cpu(event
.desc
.retval
),
8709 le32_to_cpu(event
.desc
.cookie_high
),
8710 le32_to_cpu(event
.desc
.cookie_low
),
8714 case i40e_aqc_opc_lldp_update_mib
:
8715 dev_dbg(&pf
->pdev
->dev
, "ARQ: Update LLDP MIB event received\n");
8716 #ifdef CONFIG_I40E_DCB
8718 ret
= i40e_handle_lldp_event(pf
, &event
);
8720 #endif /* CONFIG_I40E_DCB */
8722 case i40e_aqc_opc_event_lan_overflow
:
8723 dev_dbg(&pf
->pdev
->dev
, "ARQ LAN queue overflow event received\n");
8724 i40e_handle_lan_overflow_event(pf
, &event
);
8726 case i40e_aqc_opc_send_msg_to_peer
:
8727 dev_info(&pf
->pdev
->dev
, "ARQ: Msg from other pf\n");
8729 case i40e_aqc_opc_nvm_erase
:
8730 case i40e_aqc_opc_nvm_update
:
8731 case i40e_aqc_opc_oem_post_update
:
8732 i40e_debug(&pf
->hw
, I40E_DEBUG_NVM
,
8733 "ARQ NVM operation 0x%04x completed\n",
8737 dev_info(&pf
->pdev
->dev
,
8738 "ARQ: Unknown event 0x%04x ignored\n",
8742 } while (i
++ < pf
->adminq_work_limit
);
8744 if (i
< pf
->adminq_work_limit
)
8745 clear_bit(__I40E_ADMINQ_EVENT_PENDING
, pf
->state
);
8747 /* re-enable Admin queue interrupt cause */
8748 val
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
8749 val
|= I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
8750 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
8753 kfree(event
.msg_buf
);
8757 * i40e_verify_eeprom - make sure eeprom is good to use
8758 * @pf: board private structure
8760 static void i40e_verify_eeprom(struct i40e_pf
*pf
)
8764 err
= i40e_diag_eeprom_test(&pf
->hw
);
8766 /* retry in case of garbage read */
8767 err
= i40e_diag_eeprom_test(&pf
->hw
);
8769 dev_info(&pf
->pdev
->dev
, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
8771 set_bit(__I40E_BAD_EEPROM
, pf
->state
);
8775 if (!err
&& test_bit(__I40E_BAD_EEPROM
, pf
->state
)) {
8776 dev_info(&pf
->pdev
->dev
, "eeprom check passed, Tx/Rx traffic enabled\n");
8777 clear_bit(__I40E_BAD_EEPROM
, pf
->state
);
8782 * i40e_enable_pf_switch_lb
8783 * @pf: pointer to the PF structure
8785 * enable switch loop back or die - no point in a return value
8787 static void i40e_enable_pf_switch_lb(struct i40e_pf
*pf
)
8789 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
8790 struct i40e_vsi_context ctxt
;
8793 ctxt
.seid
= pf
->main_vsi_seid
;
8794 ctxt
.pf_num
= pf
->hw
.pf_id
;
8796 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
8798 dev_info(&pf
->pdev
->dev
,
8799 "couldn't get PF vsi config, err %s aq_err %s\n",
8800 i40e_stat_str(&pf
->hw
, ret
),
8801 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
8804 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
8805 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
8806 ctxt
.info
.switch_id
|= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
8808 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
8810 dev_info(&pf
->pdev
->dev
,
8811 "update vsi switch failed, err %s aq_err %s\n",
8812 i40e_stat_str(&pf
->hw
, ret
),
8813 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
8818 * i40e_disable_pf_switch_lb
8819 * @pf: pointer to the PF structure
8821 * disable switch loop back or die - no point in a return value
8823 static void i40e_disable_pf_switch_lb(struct i40e_pf
*pf
)
8825 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
8826 struct i40e_vsi_context ctxt
;
8829 ctxt
.seid
= pf
->main_vsi_seid
;
8830 ctxt
.pf_num
= pf
->hw
.pf_id
;
8832 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
8834 dev_info(&pf
->pdev
->dev
,
8835 "couldn't get PF vsi config, err %s aq_err %s\n",
8836 i40e_stat_str(&pf
->hw
, ret
),
8837 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
8840 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
8841 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
8842 ctxt
.info
.switch_id
&= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
8844 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
8846 dev_info(&pf
->pdev
->dev
,
8847 "update vsi switch failed, err %s aq_err %s\n",
8848 i40e_stat_str(&pf
->hw
, ret
),
8849 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
8854 * i40e_config_bridge_mode - Configure the HW bridge mode
8855 * @veb: pointer to the bridge instance
8857 * Configure the loop back mode for the LAN VSI that is downlink to the
8858 * specified HW bridge instance. It is expected this function is called
8859 * when a new HW bridge is instantiated.
8861 static void i40e_config_bridge_mode(struct i40e_veb
*veb
)
8863 struct i40e_pf
*pf
= veb
->pf
;
8865 if (pf
->hw
.debug_mask
& I40E_DEBUG_LAN
)
8866 dev_info(&pf
->pdev
->dev
, "enabling bridge mode: %s\n",
8867 veb
->bridge_mode
== BRIDGE_MODE_VEPA
? "VEPA" : "VEB");
8868 if (veb
->bridge_mode
& BRIDGE_MODE_VEPA
)
8869 i40e_disable_pf_switch_lb(pf
);
8871 i40e_enable_pf_switch_lb(pf
);
8875 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
8876 * @veb: pointer to the VEB instance
8878 * This is a recursive function that first builds the attached VSIs then
8879 * recurses in to build the next layer of VEB. We track the connections
8880 * through our own index numbers because the seid's from the HW could
8881 * change across the reset.
8883 static int i40e_reconstitute_veb(struct i40e_veb
*veb
)
8885 struct i40e_vsi
*ctl_vsi
= NULL
;
8886 struct i40e_pf
*pf
= veb
->pf
;
8890 /* build VSI that owns this VEB, temporarily attached to base VEB */
8891 for (v
= 0; v
< pf
->num_alloc_vsi
&& !ctl_vsi
; v
++) {
8893 pf
->vsi
[v
]->veb_idx
== veb
->idx
&&
8894 pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
8895 ctl_vsi
= pf
->vsi
[v
];
8900 dev_info(&pf
->pdev
->dev
,
8901 "missing owner VSI for veb_idx %d\n", veb
->idx
);
8903 goto end_reconstitute
;
8905 if (ctl_vsi
!= pf
->vsi
[pf
->lan_vsi
])
8906 ctl_vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
8907 ret
= i40e_add_vsi(ctl_vsi
);
8909 dev_info(&pf
->pdev
->dev
,
8910 "rebuild of veb_idx %d owner VSI failed: %d\n",
8912 goto end_reconstitute
;
8914 i40e_vsi_reset_stats(ctl_vsi
);
8916 /* create the VEB in the switch and move the VSI onto the VEB */
8917 ret
= i40e_add_veb(veb
, ctl_vsi
);
8919 goto end_reconstitute
;
8921 if (pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)
8922 veb
->bridge_mode
= BRIDGE_MODE_VEB
;
8924 veb
->bridge_mode
= BRIDGE_MODE_VEPA
;
8925 i40e_config_bridge_mode(veb
);
8927 /* create the remaining VSIs attached to this VEB */
8928 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
8929 if (!pf
->vsi
[v
] || pf
->vsi
[v
] == ctl_vsi
)
8932 if (pf
->vsi
[v
]->veb_idx
== veb
->idx
) {
8933 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
8935 vsi
->uplink_seid
= veb
->seid
;
8936 ret
= i40e_add_vsi(vsi
);
8938 dev_info(&pf
->pdev
->dev
,
8939 "rebuild of vsi_idx %d failed: %d\n",
8941 goto end_reconstitute
;
8943 i40e_vsi_reset_stats(vsi
);
8947 /* create any VEBs attached to this VEB - RECURSION */
8948 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
8949 if (pf
->veb
[veb_idx
] && pf
->veb
[veb_idx
]->veb_idx
== veb
->idx
) {
8950 pf
->veb
[veb_idx
]->uplink_seid
= veb
->seid
;
8951 ret
= i40e_reconstitute_veb(pf
->veb
[veb_idx
]);
8962 * i40e_get_capabilities - get info about the HW
8963 * @pf: the PF struct
8965 static int i40e_get_capabilities(struct i40e_pf
*pf
,
8966 enum i40e_admin_queue_opc list_type
)
8968 struct i40e_aqc_list_capabilities_element_resp
*cap_buf
;
8973 buf_len
= 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp
);
8975 cap_buf
= kzalloc(buf_len
, GFP_KERNEL
);
8979 /* this loads the data into the hw struct for us */
8980 err
= i40e_aq_discover_capabilities(&pf
->hw
, cap_buf
, buf_len
,
8981 &data_size
, list_type
,
8983 /* data loaded, buffer no longer needed */
8986 if (pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_ENOMEM
) {
8987 /* retry with a larger buffer */
8988 buf_len
= data_size
;
8989 } else if (pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_OK
) {
8990 dev_info(&pf
->pdev
->dev
,
8991 "capability discovery failed, err %s aq_err %s\n",
8992 i40e_stat_str(&pf
->hw
, err
),
8993 i40e_aq_str(&pf
->hw
,
8994 pf
->hw
.aq
.asq_last_status
));
8999 if (pf
->hw
.debug_mask
& I40E_DEBUG_USER
) {
9000 if (list_type
== i40e_aqc_opc_list_func_capabilities
) {
9001 dev_info(&pf
->pdev
->dev
,
9002 "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",
9003 pf
->hw
.pf_id
, pf
->hw
.func_caps
.num_vfs
,
9004 pf
->hw
.func_caps
.num_msix_vectors
,
9005 pf
->hw
.func_caps
.num_msix_vectors_vf
,
9006 pf
->hw
.func_caps
.fd_filters_guaranteed
,
9007 pf
->hw
.func_caps
.fd_filters_best_effort
,
9008 pf
->hw
.func_caps
.num_tx_qp
,
9009 pf
->hw
.func_caps
.num_vsis
);
9010 } else if (list_type
== i40e_aqc_opc_list_dev_capabilities
) {
9011 dev_info(&pf
->pdev
->dev
,
9012 "switch_mode=0x%04x, function_valid=0x%08x\n",
9013 pf
->hw
.dev_caps
.switch_mode
,
9014 pf
->hw
.dev_caps
.valid_functions
);
9015 dev_info(&pf
->pdev
->dev
,
9016 "SR-IOV=%d, num_vfs for all function=%u\n",
9017 pf
->hw
.dev_caps
.sr_iov_1_1
,
9018 pf
->hw
.dev_caps
.num_vfs
);
9019 dev_info(&pf
->pdev
->dev
,
9020 "num_vsis=%u, num_rx:%u, num_tx=%u\n",
9021 pf
->hw
.dev_caps
.num_vsis
,
9022 pf
->hw
.dev_caps
.num_rx_qp
,
9023 pf
->hw
.dev_caps
.num_tx_qp
);
9026 if (list_type
== i40e_aqc_opc_list_func_capabilities
) {
9027 #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
9028 + pf->hw.func_caps.num_vfs)
9029 if (pf
->hw
.revision_id
== 0 &&
9030 pf
->hw
.func_caps
.num_vsis
< DEF_NUM_VSI
) {
9031 dev_info(&pf
->pdev
->dev
,
9032 "got num_vsis %d, setting num_vsis to %d\n",
9033 pf
->hw
.func_caps
.num_vsis
, DEF_NUM_VSI
);
9034 pf
->hw
.func_caps
.num_vsis
= DEF_NUM_VSI
;
9040 static int i40e_vsi_clear(struct i40e_vsi
*vsi
);
9043 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
9044 * @pf: board private structure
9046 static void i40e_fdir_sb_setup(struct i40e_pf
*pf
)
9048 struct i40e_vsi
*vsi
;
9050 /* quick workaround for an NVM issue that leaves a critical register
9053 if (!rd32(&pf
->hw
, I40E_GLQF_HKEY(0))) {
9054 static const u32 hkey
[] = {
9055 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
9056 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
9057 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
9061 for (i
= 0; i
<= I40E_GLQF_HKEY_MAX_INDEX
; i
++)
9062 wr32(&pf
->hw
, I40E_GLQF_HKEY(i
), hkey
[i
]);
9065 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
9068 /* find existing VSI and see if it needs configuring */
9069 vsi
= i40e_find_vsi_by_type(pf
, I40E_VSI_FDIR
);
9071 /* create a new VSI if none exists */
9073 vsi
= i40e_vsi_setup(pf
, I40E_VSI_FDIR
,
9074 pf
->vsi
[pf
->lan_vsi
]->seid
, 0);
9076 dev_info(&pf
->pdev
->dev
, "Couldn't create FDir VSI\n");
9077 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
9078 pf
->flags
|= I40E_FLAG_FD_SB_INACTIVE
;
9083 i40e_vsi_setup_irqhandler(vsi
, i40e_fdir_clean_ring
);
9087 * i40e_fdir_teardown - release the Flow Director resources
9088 * @pf: board private structure
9090 static void i40e_fdir_teardown(struct i40e_pf
*pf
)
9092 struct i40e_vsi
*vsi
;
9094 i40e_fdir_filter_exit(pf
);
9095 vsi
= i40e_find_vsi_by_type(pf
, I40E_VSI_FDIR
);
9097 i40e_vsi_release(vsi
);
9101 * i40e_rebuild_cloud_filters - Rebuilds cloud filters for VSIs
9103 * @seid: seid of main or channel VSIs
9105 * Rebuilds cloud filters associated with main VSI and channel VSIs if they
9106 * existed before reset
9108 static int i40e_rebuild_cloud_filters(struct i40e_vsi
*vsi
, u16 seid
)
9110 struct i40e_cloud_filter
*cfilter
;
9111 struct i40e_pf
*pf
= vsi
->back
;
9112 struct hlist_node
*node
;
9115 /* Add cloud filters back if they exist */
9116 hlist_for_each_entry_safe(cfilter
, node
, &pf
->cloud_filter_list
,
9118 if (cfilter
->seid
!= seid
)
9121 if (cfilter
->dst_port
)
9122 ret
= i40e_add_del_cloud_filter_big_buf(vsi
, cfilter
,
9125 ret
= i40e_add_del_cloud_filter(vsi
, cfilter
, true);
9128 dev_dbg(&pf
->pdev
->dev
,
9129 "Failed to rebuild cloud filter, err %s aq_err %s\n",
9130 i40e_stat_str(&pf
->hw
, ret
),
9131 i40e_aq_str(&pf
->hw
,
9132 pf
->hw
.aq
.asq_last_status
));
9140 * i40e_rebuild_channels - Rebuilds channel VSIs if they existed before reset
9143 * Rebuilds channel VSIs if they existed before reset
9145 static int i40e_rebuild_channels(struct i40e_vsi
*vsi
)
9147 struct i40e_channel
*ch
, *ch_tmp
;
9150 if (list_empty(&vsi
->ch_list
))
9153 list_for_each_entry_safe(ch
, ch_tmp
, &vsi
->ch_list
, list
) {
9154 if (!ch
->initialized
)
9156 /* Proceed with creation of channel (VMDq2) VSI */
9157 ret
= i40e_add_channel(vsi
->back
, vsi
->uplink_seid
, ch
);
9159 dev_info(&vsi
->back
->pdev
->dev
,
9160 "failed to rebuild channels using uplink_seid %u\n",
9164 /* Reconfigure TX queues using QTX_CTL register */
9165 ret
= i40e_channel_config_tx_ring(vsi
->back
, vsi
, ch
);
9167 dev_info(&vsi
->back
->pdev
->dev
,
9168 "failed to configure TX rings for channel %u\n",
9172 /* update 'next_base_queue' */
9173 vsi
->next_base_queue
= vsi
->next_base_queue
+
9174 ch
->num_queue_pairs
;
9175 if (ch
->max_tx_rate
) {
9176 u64 credits
= ch
->max_tx_rate
;
9178 if (i40e_set_bw_limit(vsi
, ch
->seid
,
9182 do_div(credits
, I40E_BW_CREDIT_DIVISOR
);
9183 dev_dbg(&vsi
->back
->pdev
->dev
,
9184 "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
9189 ret
= i40e_rebuild_cloud_filters(vsi
, ch
->seid
);
9191 dev_dbg(&vsi
->back
->pdev
->dev
,
9192 "Failed to rebuild cloud filters for channel VSI %u\n",
9201 * i40e_prep_for_reset - prep for the core to reset
9202 * @pf: board private structure
9203 * @lock_acquired: indicates whether or not the lock has been acquired
9204 * before this function was called.
9206 * Close up the VFs and other things in prep for PF Reset.
9208 static void i40e_prep_for_reset(struct i40e_pf
*pf
, bool lock_acquired
)
9210 struct i40e_hw
*hw
= &pf
->hw
;
9211 i40e_status ret
= 0;
9214 clear_bit(__I40E_RESET_INTR_RECEIVED
, pf
->state
);
9215 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
))
9217 if (i40e_check_asq_alive(&pf
->hw
))
9218 i40e_vc_notify_reset(pf
);
9220 dev_dbg(&pf
->pdev
->dev
, "Tearing down internal switch for reset\n");
9222 /* quiesce the VSIs and their queues that are not already DOWN */
9223 /* pf_quiesce_all_vsi modifies netdev structures -rtnl_lock needed */
9226 i40e_pf_quiesce_all_vsi(pf
);
9230 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
9232 pf
->vsi
[v
]->seid
= 0;
9235 i40e_shutdown_adminq(&pf
->hw
);
9237 /* call shutdown HMC */
9238 if (hw
->hmc
.hmc_obj
) {
9239 ret
= i40e_shutdown_lan_hmc(hw
);
9241 dev_warn(&pf
->pdev
->dev
,
9242 "shutdown_lan_hmc failed: %d\n", ret
);
9247 * i40e_send_version - update firmware with driver version
9250 static void i40e_send_version(struct i40e_pf
*pf
)
9252 struct i40e_driver_version dv
;
9254 dv
.major_version
= DRV_VERSION_MAJOR
;
9255 dv
.minor_version
= DRV_VERSION_MINOR
;
9256 dv
.build_version
= DRV_VERSION_BUILD
;
9257 dv
.subbuild_version
= 0;
9258 strlcpy(dv
.driver_string
, DRV_VERSION
, sizeof(dv
.driver_string
));
9259 i40e_aq_send_driver_version(&pf
->hw
, &dv
, NULL
);
9263 * i40e_get_oem_version - get OEM specific version information
9264 * @hw: pointer to the hardware structure
9266 static void i40e_get_oem_version(struct i40e_hw
*hw
)
9268 u16 block_offset
= 0xffff;
9269 u16 block_length
= 0;
9270 u16 capabilities
= 0;
9274 #define I40E_SR_NVM_OEM_VERSION_PTR 0x1B
9275 #define I40E_NVM_OEM_LENGTH_OFFSET 0x00
9276 #define I40E_NVM_OEM_CAPABILITIES_OFFSET 0x01
9277 #define I40E_NVM_OEM_GEN_OFFSET 0x02
9278 #define I40E_NVM_OEM_RELEASE_OFFSET 0x03
9279 #define I40E_NVM_OEM_CAPABILITIES_MASK 0x000F
9280 #define I40E_NVM_OEM_LENGTH 3
9282 /* Check if pointer to OEM version block is valid. */
9283 i40e_read_nvm_word(hw
, I40E_SR_NVM_OEM_VERSION_PTR
, &block_offset
);
9284 if (block_offset
== 0xffff)
9287 /* Check if OEM version block has correct length. */
9288 i40e_read_nvm_word(hw
, block_offset
+ I40E_NVM_OEM_LENGTH_OFFSET
,
9290 if (block_length
< I40E_NVM_OEM_LENGTH
)
9293 /* Check if OEM version format is as expected. */
9294 i40e_read_nvm_word(hw
, block_offset
+ I40E_NVM_OEM_CAPABILITIES_OFFSET
,
9296 if ((capabilities
& I40E_NVM_OEM_CAPABILITIES_MASK
) != 0)
9299 i40e_read_nvm_word(hw
, block_offset
+ I40E_NVM_OEM_GEN_OFFSET
,
9301 i40e_read_nvm_word(hw
, block_offset
+ I40E_NVM_OEM_RELEASE_OFFSET
,
9303 hw
->nvm
.oem_ver
= (gen_snap
<< I40E_OEM_SNAP_SHIFT
) | release
;
9304 hw
->nvm
.eetrack
= I40E_OEM_EETRACK_ID
;
9308 * i40e_reset - wait for core reset to finish reset, reset pf if corer not seen
9309 * @pf: board private structure
9311 static int i40e_reset(struct i40e_pf
*pf
)
9313 struct i40e_hw
*hw
= &pf
->hw
;
9316 ret
= i40e_pf_reset(hw
);
9318 dev_info(&pf
->pdev
->dev
, "PF reset failed, %d\n", ret
);
9319 set_bit(__I40E_RESET_FAILED
, pf
->state
);
9320 clear_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
);
9328 * i40e_rebuild - rebuild using a saved config
9329 * @pf: board private structure
9330 * @reinit: if the Main VSI needs to re-initialized.
9331 * @lock_acquired: indicates whether or not the lock has been acquired
9332 * before this function was called.
9334 static void i40e_rebuild(struct i40e_pf
*pf
, bool reinit
, bool lock_acquired
)
9336 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
9337 struct i40e_hw
*hw
= &pf
->hw
;
9338 u8 set_fc_aq_fail
= 0;
9343 if (test_bit(__I40E_DOWN
, pf
->state
))
9344 goto clear_recovery
;
9345 dev_dbg(&pf
->pdev
->dev
, "Rebuilding internal switch\n");
9347 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
9348 ret
= i40e_init_adminq(&pf
->hw
);
9350 dev_info(&pf
->pdev
->dev
, "Rebuild AdminQ failed, err %s aq_err %s\n",
9351 i40e_stat_str(&pf
->hw
, ret
),
9352 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9353 goto clear_recovery
;
9355 i40e_get_oem_version(&pf
->hw
);
9357 if (test_bit(__I40E_EMP_RESET_INTR_RECEIVED
, pf
->state
) &&
9358 ((hw
->aq
.fw_maj_ver
== 4 && hw
->aq
.fw_min_ver
<= 33) ||
9359 hw
->aq
.fw_maj_ver
< 4) && hw
->mac
.type
== I40E_MAC_XL710
) {
9360 /* The following delay is necessary for 4.33 firmware and older
9361 * to recover after EMP reset. 200 ms should suffice but we
9362 * put here 300 ms to be sure that FW is ready to operate
9368 /* re-verify the eeprom if we just had an EMP reset */
9369 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED
, pf
->state
))
9370 i40e_verify_eeprom(pf
);
9372 i40e_clear_pxe_mode(hw
);
9373 ret
= i40e_get_capabilities(pf
, i40e_aqc_opc_list_func_capabilities
);
9375 goto end_core_reset
;
9377 ret
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
9378 hw
->func_caps
.num_rx_qp
, 0, 0);
9380 dev_info(&pf
->pdev
->dev
, "init_lan_hmc failed: %d\n", ret
);
9381 goto end_core_reset
;
9383 ret
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
9385 dev_info(&pf
->pdev
->dev
, "configure_lan_hmc failed: %d\n", ret
);
9386 goto end_core_reset
;
9389 /* Enable FW to write a default DCB config on link-up */
9390 i40e_aq_set_dcb_parameters(hw
, true, NULL
);
9392 #ifdef CONFIG_I40E_DCB
9393 ret
= i40e_init_pf_dcb(pf
);
9395 dev_info(&pf
->pdev
->dev
, "DCB init failed %d, disabled\n", ret
);
9396 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
9397 /* Continue without DCB enabled */
9399 #endif /* CONFIG_I40E_DCB */
9400 /* do basic switch setup */
9403 ret
= i40e_setup_pf_switch(pf
, reinit
);
9407 /* The driver only wants link up/down and module qualification
9408 * reports from firmware. Note the negative logic.
9410 ret
= i40e_aq_set_phy_int_mask(&pf
->hw
,
9411 ~(I40E_AQ_EVENT_LINK_UPDOWN
|
9412 I40E_AQ_EVENT_MEDIA_NA
|
9413 I40E_AQ_EVENT_MODULE_QUAL_FAIL
), NULL
);
9415 dev_info(&pf
->pdev
->dev
, "set phy mask fail, err %s aq_err %s\n",
9416 i40e_stat_str(&pf
->hw
, ret
),
9417 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9419 /* make sure our flow control settings are restored */
9420 ret
= i40e_set_fc(&pf
->hw
, &set_fc_aq_fail
, true);
9422 dev_dbg(&pf
->pdev
->dev
, "setting flow control: ret = %s last_status = %s\n",
9423 i40e_stat_str(&pf
->hw
, ret
),
9424 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9426 /* Rebuild the VSIs and VEBs that existed before reset.
9427 * They are still in our local switch element arrays, so only
9428 * need to rebuild the switch model in the HW.
9430 * If there were VEBs but the reconstitution failed, we'll try
9431 * try to recover minimal use by getting the basic PF VSI working.
9433 if (vsi
->uplink_seid
!= pf
->mac_seid
) {
9434 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild switch\n");
9435 /* find the one VEB connected to the MAC, and find orphans */
9436 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
9440 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
||
9441 pf
->veb
[v
]->uplink_seid
== 0) {
9442 ret
= i40e_reconstitute_veb(pf
->veb
[v
]);
9447 /* If Main VEB failed, we're in deep doodoo,
9448 * so give up rebuilding the switch and set up
9449 * for minimal rebuild of PF VSI.
9450 * If orphan failed, we'll report the error
9451 * but try to keep going.
9453 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
) {
9454 dev_info(&pf
->pdev
->dev
,
9455 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
9457 vsi
->uplink_seid
= pf
->mac_seid
;
9459 } else if (pf
->veb
[v
]->uplink_seid
== 0) {
9460 dev_info(&pf
->pdev
->dev
,
9461 "rebuild of orphan VEB failed: %d\n",
9468 if (vsi
->uplink_seid
== pf
->mac_seid
) {
9469 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild PF VSI\n");
9470 /* no VEB, so rebuild only the Main VSI */
9471 ret
= i40e_add_vsi(vsi
);
9473 dev_info(&pf
->pdev
->dev
,
9474 "rebuild of Main VSI failed: %d\n", ret
);
9479 if (vsi
->mqprio_qopt
.max_rate
[0]) {
9480 u64 max_tx_rate
= vsi
->mqprio_qopt
.max_rate
[0];
9483 do_div(max_tx_rate
, I40E_BW_MBPS_DIVISOR
);
9484 ret
= i40e_set_bw_limit(vsi
, vsi
->seid
, max_tx_rate
);
9488 credits
= max_tx_rate
;
9489 do_div(credits
, I40E_BW_CREDIT_DIVISOR
);
9490 dev_dbg(&vsi
->back
->pdev
->dev
,
9491 "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
9497 ret
= i40e_rebuild_cloud_filters(vsi
, vsi
->seid
);
9501 /* PF Main VSI is rebuild by now, go ahead and rebuild channel VSIs
9502 * for this main VSI if they exist
9504 ret
= i40e_rebuild_channels(vsi
);
9508 /* Reconfigure hardware for allowing smaller MSS in the case
9509 * of TSO, so that we avoid the MDD being fired and causing
9510 * a reset in the case of small MSS+TSO.
9512 #define I40E_REG_MSS 0x000E64DC
9513 #define I40E_REG_MSS_MIN_MASK 0x3FF0000
9514 #define I40E_64BYTE_MSS 0x400000
9515 val
= rd32(hw
, I40E_REG_MSS
);
9516 if ((val
& I40E_REG_MSS_MIN_MASK
) > I40E_64BYTE_MSS
) {
9517 val
&= ~I40E_REG_MSS_MIN_MASK
;
9518 val
|= I40E_64BYTE_MSS
;
9519 wr32(hw
, I40E_REG_MSS
, val
);
9522 if (pf
->hw_features
& I40E_HW_RESTART_AUTONEG
) {
9524 ret
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
9526 dev_info(&pf
->pdev
->dev
, "link restart failed, err %s aq_err %s\n",
9527 i40e_stat_str(&pf
->hw
, ret
),
9528 i40e_aq_str(&pf
->hw
,
9529 pf
->hw
.aq
.asq_last_status
));
9531 /* reinit the misc interrupt */
9532 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
9533 ret
= i40e_setup_misc_vector(pf
);
9535 /* Add a filter to drop all Flow control frames from any VSI from being
9536 * transmitted. By doing so we stop a malicious VF from sending out
9537 * PAUSE or PFC frames and potentially controlling traffic for other
9539 * The FW can still send Flow control frames if enabled.
9541 i40e_add_filter_to_drop_tx_flow_control_frames(&pf
->hw
,
9544 /* restart the VSIs that were rebuilt and running before the reset */
9545 i40e_pf_unquiesce_all_vsi(pf
);
9547 /* Release the RTNL lock before we start resetting VFs */
9551 /* Restore promiscuous settings */
9552 ret
= i40e_set_promiscuous(pf
, pf
->cur_promisc
);
9554 dev_warn(&pf
->pdev
->dev
,
9555 "Failed to restore promiscuous setting: %s, err %s aq_err %s\n",
9556 pf
->cur_promisc
? "on" : "off",
9557 i40e_stat_str(&pf
->hw
, ret
),
9558 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9560 i40e_reset_all_vfs(pf
, true);
9562 /* tell the firmware that we're starting */
9563 i40e_send_version(pf
);
9565 /* We've already released the lock, so don't do it again */
9566 goto end_core_reset
;
9572 clear_bit(__I40E_RESET_FAILED
, pf
->state
);
9574 clear_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
);
9575 clear_bit(__I40E_TIMEOUT_RECOVERY_PENDING
, pf
->state
);
9579 * i40e_reset_and_rebuild - reset and rebuild using a saved config
9580 * @pf: board private structure
9581 * @reinit: if the Main VSI needs to re-initialized.
9582 * @lock_acquired: indicates whether or not the lock has been acquired
9583 * before this function was called.
9585 static void i40e_reset_and_rebuild(struct i40e_pf
*pf
, bool reinit
,
9589 /* Now we wait for GRST to settle out.
9590 * We don't have to delete the VEBs or VSIs from the hw switch
9591 * because the reset will make them disappear.
9593 ret
= i40e_reset(pf
);
9595 i40e_rebuild(pf
, reinit
, lock_acquired
);
9599 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
9600 * @pf: board private structure
9602 * Close up the VFs and other things in prep for a Core Reset,
9603 * then get ready to rebuild the world.
9604 * @lock_acquired: indicates whether or not the lock has been acquired
9605 * before this function was called.
9607 static void i40e_handle_reset_warning(struct i40e_pf
*pf
, bool lock_acquired
)
9609 i40e_prep_for_reset(pf
, lock_acquired
);
9610 i40e_reset_and_rebuild(pf
, false, lock_acquired
);
9614 * i40e_handle_mdd_event
9615 * @pf: pointer to the PF structure
9617 * Called from the MDD irq handler to identify possibly malicious vfs
9619 static void i40e_handle_mdd_event(struct i40e_pf
*pf
)
9621 struct i40e_hw
*hw
= &pf
->hw
;
9622 bool mdd_detected
= false;
9623 bool pf_mdd_detected
= false;
9628 if (!test_bit(__I40E_MDD_EVENT_PENDING
, pf
->state
))
9631 /* find what triggered the MDD event */
9632 reg
= rd32(hw
, I40E_GL_MDET_TX
);
9633 if (reg
& I40E_GL_MDET_TX_VALID_MASK
) {
9634 u8 pf_num
= (reg
& I40E_GL_MDET_TX_PF_NUM_MASK
) >>
9635 I40E_GL_MDET_TX_PF_NUM_SHIFT
;
9636 u16 vf_num
= (reg
& I40E_GL_MDET_TX_VF_NUM_MASK
) >>
9637 I40E_GL_MDET_TX_VF_NUM_SHIFT
;
9638 u8 event
= (reg
& I40E_GL_MDET_TX_EVENT_MASK
) >>
9639 I40E_GL_MDET_TX_EVENT_SHIFT
;
9640 u16 queue
= ((reg
& I40E_GL_MDET_TX_QUEUE_MASK
) >>
9641 I40E_GL_MDET_TX_QUEUE_SHIFT
) -
9642 pf
->hw
.func_caps
.base_queue
;
9643 if (netif_msg_tx_err(pf
))
9644 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
9645 event
, queue
, pf_num
, vf_num
);
9646 wr32(hw
, I40E_GL_MDET_TX
, 0xffffffff);
9647 mdd_detected
= true;
9649 reg
= rd32(hw
, I40E_GL_MDET_RX
);
9650 if (reg
& I40E_GL_MDET_RX_VALID_MASK
) {
9651 u8 func
= (reg
& I40E_GL_MDET_RX_FUNCTION_MASK
) >>
9652 I40E_GL_MDET_RX_FUNCTION_SHIFT
;
9653 u8 event
= (reg
& I40E_GL_MDET_RX_EVENT_MASK
) >>
9654 I40E_GL_MDET_RX_EVENT_SHIFT
;
9655 u16 queue
= ((reg
& I40E_GL_MDET_RX_QUEUE_MASK
) >>
9656 I40E_GL_MDET_RX_QUEUE_SHIFT
) -
9657 pf
->hw
.func_caps
.base_queue
;
9658 if (netif_msg_rx_err(pf
))
9659 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
9660 event
, queue
, func
);
9661 wr32(hw
, I40E_GL_MDET_RX
, 0xffffffff);
9662 mdd_detected
= true;
9666 reg
= rd32(hw
, I40E_PF_MDET_TX
);
9667 if (reg
& I40E_PF_MDET_TX_VALID_MASK
) {
9668 wr32(hw
, I40E_PF_MDET_TX
, 0xFFFF);
9669 dev_info(&pf
->pdev
->dev
, "TX driver issue detected, PF reset issued\n");
9670 pf_mdd_detected
= true;
9672 reg
= rd32(hw
, I40E_PF_MDET_RX
);
9673 if (reg
& I40E_PF_MDET_RX_VALID_MASK
) {
9674 wr32(hw
, I40E_PF_MDET_RX
, 0xFFFF);
9675 dev_info(&pf
->pdev
->dev
, "RX driver issue detected, PF reset issued\n");
9676 pf_mdd_detected
= true;
9678 /* Queue belongs to the PF, initiate a reset */
9679 if (pf_mdd_detected
) {
9680 set_bit(__I40E_PF_RESET_REQUESTED
, pf
->state
);
9681 i40e_service_event_schedule(pf
);
9685 /* see if one of the VFs needs its hand slapped */
9686 for (i
= 0; i
< pf
->num_alloc_vfs
&& mdd_detected
; i
++) {
9688 reg
= rd32(hw
, I40E_VP_MDET_TX(i
));
9689 if (reg
& I40E_VP_MDET_TX_VALID_MASK
) {
9690 wr32(hw
, I40E_VP_MDET_TX(i
), 0xFFFF);
9691 vf
->num_mdd_events
++;
9692 dev_info(&pf
->pdev
->dev
, "TX driver issue detected on VF %d\n",
9696 reg
= rd32(hw
, I40E_VP_MDET_RX(i
));
9697 if (reg
& I40E_VP_MDET_RX_VALID_MASK
) {
9698 wr32(hw
, I40E_VP_MDET_RX(i
), 0xFFFF);
9699 vf
->num_mdd_events
++;
9700 dev_info(&pf
->pdev
->dev
, "RX driver issue detected on VF %d\n",
9704 if (vf
->num_mdd_events
> I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED
) {
9705 dev_info(&pf
->pdev
->dev
,
9706 "Too many MDD events on VF %d, disabled\n", i
);
9707 dev_info(&pf
->pdev
->dev
,
9708 "Use PF Control I/F to re-enable the VF\n");
9709 set_bit(I40E_VF_STATE_DISABLED
, &vf
->vf_states
);
9713 /* re-enable mdd interrupt cause */
9714 clear_bit(__I40E_MDD_EVENT_PENDING
, pf
->state
);
9715 reg
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
9716 reg
|= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
9717 wr32(hw
, I40E_PFINT_ICR0_ENA
, reg
);
9721 static const char *i40e_tunnel_name(u8 type
)
9724 case UDP_TUNNEL_TYPE_VXLAN
:
9726 case UDP_TUNNEL_TYPE_GENEVE
:
9734 * i40e_sync_udp_filters - Trigger a sync event for existing UDP filters
9735 * @pf: board private structure
9737 static void i40e_sync_udp_filters(struct i40e_pf
*pf
)
9741 /* loop through and set pending bit for all active UDP filters */
9742 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
9743 if (pf
->udp_ports
[i
].port
)
9744 pf
->pending_udp_bitmap
|= BIT_ULL(i
);
9747 set_bit(__I40E_UDP_FILTER_SYNC_PENDING
, pf
->state
);
9751 * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
9752 * @pf: board private structure
9754 static void i40e_sync_udp_filters_subtask(struct i40e_pf
*pf
)
9756 struct i40e_hw
*hw
= &pf
->hw
;
9757 u8 filter_index
, type
;
9761 if (!test_and_clear_bit(__I40E_UDP_FILTER_SYNC_PENDING
, pf
->state
))
9764 /* acquire RTNL to maintain state of flags and port requests */
9767 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
9768 if (pf
->pending_udp_bitmap
& BIT_ULL(i
)) {
9769 struct i40e_udp_port_config
*udp_port
;
9770 i40e_status ret
= 0;
9772 udp_port
= &pf
->udp_ports
[i
];
9773 pf
->pending_udp_bitmap
&= ~BIT_ULL(i
);
9775 port
= READ_ONCE(udp_port
->port
);
9776 type
= READ_ONCE(udp_port
->type
);
9777 filter_index
= READ_ONCE(udp_port
->filter_index
);
9779 /* release RTNL while we wait on AQ command */
9783 ret
= i40e_aq_add_udp_tunnel(hw
, port
,
9787 else if (filter_index
!= I40E_UDP_PORT_INDEX_UNUSED
)
9788 ret
= i40e_aq_del_udp_tunnel(hw
, filter_index
,
9791 /* reacquire RTNL so we can update filter_index */
9795 dev_info(&pf
->pdev
->dev
,
9796 "%s %s port %d, index %d failed, err %s aq_err %s\n",
9797 i40e_tunnel_name(type
),
9798 port
? "add" : "delete",
9801 i40e_stat_str(&pf
->hw
, ret
),
9802 i40e_aq_str(&pf
->hw
,
9803 pf
->hw
.aq
.asq_last_status
));
9805 /* failed to add, just reset port,
9806 * drop pending bit for any deletion
9809 pf
->pending_udp_bitmap
&= ~BIT_ULL(i
);
9812 /* record filter index on success */
9813 udp_port
->filter_index
= filter_index
;
9822 * i40e_service_task - Run the driver's async subtasks
9823 * @work: pointer to work_struct containing our data
9825 static void i40e_service_task(struct work_struct
*work
)
9827 struct i40e_pf
*pf
= container_of(work
,
9830 unsigned long start_time
= jiffies
;
9832 /* don't bother with service tasks if a reset is in progress */
9833 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, pf
->state
))
9836 if (test_and_set_bit(__I40E_SERVICE_SCHED
, pf
->state
))
9839 i40e_detect_recover_hung(pf
->vsi
[pf
->lan_vsi
]);
9840 i40e_sync_filters_subtask(pf
);
9841 i40e_reset_subtask(pf
);
9842 i40e_handle_mdd_event(pf
);
9843 i40e_vc_process_vflr_event(pf
);
9844 i40e_watchdog_subtask(pf
);
9845 i40e_fdir_reinit_subtask(pf
);
9846 if (test_and_clear_bit(__I40E_CLIENT_RESET
, pf
->state
)) {
9847 /* Client subtask will reopen next time through. */
9848 i40e_notify_client_of_netdev_close(pf
->vsi
[pf
->lan_vsi
], true);
9850 i40e_client_subtask(pf
);
9851 if (test_and_clear_bit(__I40E_CLIENT_L2_CHANGE
,
9853 i40e_notify_client_of_l2_param_changes(
9854 pf
->vsi
[pf
->lan_vsi
]);
9856 i40e_sync_filters_subtask(pf
);
9857 i40e_sync_udp_filters_subtask(pf
);
9858 i40e_clean_adminq_subtask(pf
);
9860 /* flush memory to make sure state is correct before next watchdog */
9861 smp_mb__before_atomic();
9862 clear_bit(__I40E_SERVICE_SCHED
, pf
->state
);
9864 /* If the tasks have taken longer than one timer cycle or there
9865 * is more work to be done, reschedule the service task now
9866 * rather than wait for the timer to tick again.
9868 if (time_after(jiffies
, (start_time
+ pf
->service_timer_period
)) ||
9869 test_bit(__I40E_ADMINQ_EVENT_PENDING
, pf
->state
) ||
9870 test_bit(__I40E_MDD_EVENT_PENDING
, pf
->state
) ||
9871 test_bit(__I40E_VFLR_EVENT_PENDING
, pf
->state
))
9872 i40e_service_event_schedule(pf
);
9876 * i40e_service_timer - timer callback
9877 * @data: pointer to PF struct
9879 static void i40e_service_timer(struct timer_list
*t
)
9881 struct i40e_pf
*pf
= from_timer(pf
, t
, service_timer
);
9883 mod_timer(&pf
->service_timer
,
9884 round_jiffies(jiffies
+ pf
->service_timer_period
));
9885 i40e_service_event_schedule(pf
);
9889 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
9890 * @vsi: the VSI being configured
9892 static int i40e_set_num_rings_in_vsi(struct i40e_vsi
*vsi
)
9894 struct i40e_pf
*pf
= vsi
->back
;
9896 switch (vsi
->type
) {
9898 vsi
->alloc_queue_pairs
= pf
->num_lan_qps
;
9899 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
9900 I40E_REQ_DESCRIPTOR_MULTIPLE
);
9901 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
9902 vsi
->num_q_vectors
= pf
->num_lan_msix
;
9904 vsi
->num_q_vectors
= 1;
9909 vsi
->alloc_queue_pairs
= 1;
9910 vsi
->num_desc
= ALIGN(I40E_FDIR_RING_COUNT
,
9911 I40E_REQ_DESCRIPTOR_MULTIPLE
);
9912 vsi
->num_q_vectors
= pf
->num_fdsb_msix
;
9915 case I40E_VSI_VMDQ2
:
9916 vsi
->alloc_queue_pairs
= pf
->num_vmdq_qps
;
9917 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
9918 I40E_REQ_DESCRIPTOR_MULTIPLE
);
9919 vsi
->num_q_vectors
= pf
->num_vmdq_msix
;
9922 case I40E_VSI_SRIOV
:
9923 vsi
->alloc_queue_pairs
= pf
->num_vf_qps
;
9924 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
9925 I40E_REQ_DESCRIPTOR_MULTIPLE
);
9937 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
9939 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
9941 * On error: returns error code (negative)
9942 * On success: returns 0
9944 static int i40e_vsi_alloc_arrays(struct i40e_vsi
*vsi
, bool alloc_qvectors
)
9946 struct i40e_ring
**next_rings
;
9950 /* allocate memory for both Tx, XDP Tx and Rx ring pointers */
9951 size
= sizeof(struct i40e_ring
*) * vsi
->alloc_queue_pairs
*
9952 (i40e_enabled_xdp_vsi(vsi
) ? 3 : 2);
9953 vsi
->tx_rings
= kzalloc(size
, GFP_KERNEL
);
9956 next_rings
= vsi
->tx_rings
+ vsi
->alloc_queue_pairs
;
9957 if (i40e_enabled_xdp_vsi(vsi
)) {
9958 vsi
->xdp_rings
= next_rings
;
9959 next_rings
+= vsi
->alloc_queue_pairs
;
9961 vsi
->rx_rings
= next_rings
;
9963 if (alloc_qvectors
) {
9964 /* allocate memory for q_vector pointers */
9965 size
= sizeof(struct i40e_q_vector
*) * vsi
->num_q_vectors
;
9966 vsi
->q_vectors
= kzalloc(size
, GFP_KERNEL
);
9967 if (!vsi
->q_vectors
) {
9975 kfree(vsi
->tx_rings
);
9980 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
9981 * @pf: board private structure
9982 * @type: type of VSI
9984 * On error: returns error code (negative)
9985 * On success: returns vsi index in PF (positive)
9987 static int i40e_vsi_mem_alloc(struct i40e_pf
*pf
, enum i40e_vsi_type type
)
9990 struct i40e_vsi
*vsi
;
9994 /* Need to protect the allocation of the VSIs at the PF level */
9995 mutex_lock(&pf
->switch_mutex
);
9997 /* VSI list may be fragmented if VSI creation/destruction has
9998 * been happening. We can afford to do a quick scan to look
9999 * for any free VSIs in the list.
10001 * find next empty vsi slot, looping back around if necessary
10004 while (i
< pf
->num_alloc_vsi
&& pf
->vsi
[i
])
10006 if (i
>= pf
->num_alloc_vsi
) {
10008 while (i
< pf
->next_vsi
&& pf
->vsi
[i
])
10012 if (i
< pf
->num_alloc_vsi
&& !pf
->vsi
[i
]) {
10013 vsi_idx
= i
; /* Found one! */
10016 goto unlock_pf
; /* out of VSI slots! */
10018 pf
->next_vsi
= ++i
;
10020 vsi
= kzalloc(sizeof(*vsi
), GFP_KERNEL
);
10027 set_bit(__I40E_VSI_DOWN
, vsi
->state
);
10029 vsi
->idx
= vsi_idx
;
10030 vsi
->int_rate_limit
= 0;
10031 vsi
->rss_table_size
= (vsi
->type
== I40E_VSI_MAIN
) ?
10032 pf
->rss_table_size
: 64;
10033 vsi
->netdev_registered
= false;
10034 vsi
->work_limit
= I40E_DEFAULT_IRQ_WORK
;
10035 hash_init(vsi
->mac_filter_hash
);
10036 vsi
->irqs_ready
= false;
10038 ret
= i40e_set_num_rings_in_vsi(vsi
);
10042 ret
= i40e_vsi_alloc_arrays(vsi
, true);
10046 /* Setup default MSIX irq handler for VSI */
10047 i40e_vsi_setup_irqhandler(vsi
, i40e_msix_clean_rings
);
10049 /* Initialize VSI lock */
10050 spin_lock_init(&vsi
->mac_filter_hash_lock
);
10051 pf
->vsi
[vsi_idx
] = vsi
;
10056 pf
->next_vsi
= i
- 1;
10059 mutex_unlock(&pf
->switch_mutex
);
10064 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
10065 * @vsi: VSI pointer
10066 * @free_qvectors: a bool to specify if q_vectors need to be freed.
10068 * On error: returns error code (negative)
10069 * On success: returns 0
10071 static void i40e_vsi_free_arrays(struct i40e_vsi
*vsi
, bool free_qvectors
)
10073 /* free the ring and vector containers */
10074 if (free_qvectors
) {
10075 kfree(vsi
->q_vectors
);
10076 vsi
->q_vectors
= NULL
;
10078 kfree(vsi
->tx_rings
);
10079 vsi
->tx_rings
= NULL
;
10080 vsi
->rx_rings
= NULL
;
10081 vsi
->xdp_rings
= NULL
;
10085 * i40e_clear_rss_config_user - clear the user configured RSS hash keys
10087 * @vsi: Pointer to VSI structure
10089 static void i40e_clear_rss_config_user(struct i40e_vsi
*vsi
)
10094 kfree(vsi
->rss_hkey_user
);
10095 vsi
->rss_hkey_user
= NULL
;
10097 kfree(vsi
->rss_lut_user
);
10098 vsi
->rss_lut_user
= NULL
;
10102 * i40e_vsi_clear - Deallocate the VSI provided
10103 * @vsi: the VSI being un-configured
10105 static int i40e_vsi_clear(struct i40e_vsi
*vsi
)
10107 struct i40e_pf
*pf
;
10116 mutex_lock(&pf
->switch_mutex
);
10117 if (!pf
->vsi
[vsi
->idx
]) {
10118 dev_err(&pf
->pdev
->dev
, "pf->vsi[%d] is NULL, just free vsi[%d](type %d)\n",
10119 vsi
->idx
, vsi
->idx
, vsi
->type
);
10123 if (pf
->vsi
[vsi
->idx
] != vsi
) {
10124 dev_err(&pf
->pdev
->dev
,
10125 "pf->vsi[%d](type %d) != vsi[%d](type %d): no free!\n",
10126 pf
->vsi
[vsi
->idx
]->idx
,
10127 pf
->vsi
[vsi
->idx
]->type
,
10128 vsi
->idx
, vsi
->type
);
10132 /* updates the PF for this cleared vsi */
10133 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
10134 i40e_put_lump(pf
->irq_pile
, vsi
->base_vector
, vsi
->idx
);
10136 i40e_vsi_free_arrays(vsi
, true);
10137 i40e_clear_rss_config_user(vsi
);
10139 pf
->vsi
[vsi
->idx
] = NULL
;
10140 if (vsi
->idx
< pf
->next_vsi
)
10141 pf
->next_vsi
= vsi
->idx
;
10144 mutex_unlock(&pf
->switch_mutex
);
10152 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
10153 * @vsi: the VSI being cleaned
10155 static void i40e_vsi_clear_rings(struct i40e_vsi
*vsi
)
10159 if (vsi
->tx_rings
&& vsi
->tx_rings
[0]) {
10160 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
10161 kfree_rcu(vsi
->tx_rings
[i
], rcu
);
10162 vsi
->tx_rings
[i
] = NULL
;
10163 vsi
->rx_rings
[i
] = NULL
;
10164 if (vsi
->xdp_rings
)
10165 vsi
->xdp_rings
[i
] = NULL
;
10171 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
10172 * @vsi: the VSI being configured
10174 static int i40e_alloc_rings(struct i40e_vsi
*vsi
)
10176 int i
, qpv
= i40e_enabled_xdp_vsi(vsi
) ? 3 : 2;
10177 struct i40e_pf
*pf
= vsi
->back
;
10178 struct i40e_ring
*ring
;
10180 /* Set basic values in the rings to be used later during open() */
10181 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
10182 /* allocate space for both Tx and Rx in one shot */
10183 ring
= kcalloc(qpv
, sizeof(struct i40e_ring
), GFP_KERNEL
);
10187 ring
->queue_index
= i
;
10188 ring
->reg_idx
= vsi
->base_queue
+ i
;
10189 ring
->ring_active
= false;
10191 ring
->netdev
= vsi
->netdev
;
10192 ring
->dev
= &pf
->pdev
->dev
;
10193 ring
->count
= vsi
->num_desc
;
10196 if (vsi
->back
->hw_features
& I40E_HW_WB_ON_ITR_CAPABLE
)
10197 ring
->flags
= I40E_TXR_FLAGS_WB_ON_ITR
;
10198 ring
->itr_setting
= pf
->tx_itr_default
;
10199 vsi
->tx_rings
[i
] = ring
++;
10201 if (!i40e_enabled_xdp_vsi(vsi
))
10204 ring
->queue_index
= vsi
->alloc_queue_pairs
+ i
;
10205 ring
->reg_idx
= vsi
->base_queue
+ ring
->queue_index
;
10206 ring
->ring_active
= false;
10208 ring
->netdev
= NULL
;
10209 ring
->dev
= &pf
->pdev
->dev
;
10210 ring
->count
= vsi
->num_desc
;
10213 if (vsi
->back
->hw_features
& I40E_HW_WB_ON_ITR_CAPABLE
)
10214 ring
->flags
= I40E_TXR_FLAGS_WB_ON_ITR
;
10215 set_ring_xdp(ring
);
10216 ring
->itr_setting
= pf
->tx_itr_default
;
10217 vsi
->xdp_rings
[i
] = ring
++;
10220 ring
->queue_index
= i
;
10221 ring
->reg_idx
= vsi
->base_queue
+ i
;
10222 ring
->ring_active
= false;
10224 ring
->netdev
= vsi
->netdev
;
10225 ring
->dev
= &pf
->pdev
->dev
;
10226 ring
->count
= vsi
->num_desc
;
10229 ring
->itr_setting
= pf
->rx_itr_default
;
10230 vsi
->rx_rings
[i
] = ring
;
10236 i40e_vsi_clear_rings(vsi
);
10241 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
10242 * @pf: board private structure
10243 * @vectors: the number of MSI-X vectors to request
10245 * Returns the number of vectors reserved, or error
10247 static int i40e_reserve_msix_vectors(struct i40e_pf
*pf
, int vectors
)
10249 vectors
= pci_enable_msix_range(pf
->pdev
, pf
->msix_entries
,
10250 I40E_MIN_MSIX
, vectors
);
10252 dev_info(&pf
->pdev
->dev
,
10253 "MSI-X vector reservation failed: %d\n", vectors
);
10261 * i40e_init_msix - Setup the MSIX capability
10262 * @pf: board private structure
10264 * Work with the OS to set up the MSIX vectors needed.
10266 * Returns the number of vectors reserved or negative on failure
10268 static int i40e_init_msix(struct i40e_pf
*pf
)
10270 struct i40e_hw
*hw
= &pf
->hw
;
10271 int cpus
, extra_vectors
;
10275 int iwarp_requested
= 0;
10277 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
10280 /* The number of vectors we'll request will be comprised of:
10281 * - Add 1 for "other" cause for Admin Queue events, etc.
10282 * - The number of LAN queue pairs
10283 * - Queues being used for RSS.
10284 * We don't need as many as max_rss_size vectors.
10285 * use rss_size instead in the calculation since that
10286 * is governed by number of cpus in the system.
10287 * - assumes symmetric Tx/Rx pairing
10288 * - The number of VMDq pairs
10289 * - The CPU count within the NUMA node if iWARP is enabled
10290 * Once we count this up, try the request.
10292 * If we can't get what we want, we'll simplify to nearly nothing
10293 * and try again. If that still fails, we punt.
10295 vectors_left
= hw
->func_caps
.num_msix_vectors
;
10298 /* reserve one vector for miscellaneous handler */
10299 if (vectors_left
) {
10304 /* reserve some vectors for the main PF traffic queues. Initially we
10305 * only reserve at most 50% of the available vectors, in the case that
10306 * the number of online CPUs is large. This ensures that we can enable
10307 * extra features as well. Once we've enabled the other features, we
10308 * will use any remaining vectors to reach as close as we can to the
10309 * number of online CPUs.
10311 cpus
= num_online_cpus();
10312 pf
->num_lan_msix
= min_t(int, cpus
, vectors_left
/ 2);
10313 vectors_left
-= pf
->num_lan_msix
;
10315 /* reserve one vector for sideband flow director */
10316 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
10317 if (vectors_left
) {
10318 pf
->num_fdsb_msix
= 1;
10322 pf
->num_fdsb_msix
= 0;
10326 /* can we reserve enough for iWARP? */
10327 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
) {
10328 iwarp_requested
= pf
->num_iwarp_msix
;
10331 pf
->num_iwarp_msix
= 0;
10332 else if (vectors_left
< pf
->num_iwarp_msix
)
10333 pf
->num_iwarp_msix
= 1;
10334 v_budget
+= pf
->num_iwarp_msix
;
10335 vectors_left
-= pf
->num_iwarp_msix
;
10338 /* any vectors left over go for VMDq support */
10339 if (pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) {
10340 if (!vectors_left
) {
10341 pf
->num_vmdq_msix
= 0;
10342 pf
->num_vmdq_qps
= 0;
10344 int vmdq_vecs_wanted
=
10345 pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
;
10347 min_t(int, vectors_left
, vmdq_vecs_wanted
);
10349 /* if we're short on vectors for what's desired, we limit
10350 * the queues per vmdq. If this is still more than are
10351 * available, the user will need to change the number of
10352 * queues/vectors used by the PF later with the ethtool
10355 if (vectors_left
< vmdq_vecs_wanted
) {
10356 pf
->num_vmdq_qps
= 1;
10357 vmdq_vecs_wanted
= pf
->num_vmdq_vsis
;
10358 vmdq_vecs
= min_t(int,
10362 pf
->num_vmdq_msix
= pf
->num_vmdq_qps
;
10364 v_budget
+= vmdq_vecs
;
10365 vectors_left
-= vmdq_vecs
;
10369 /* On systems with a large number of SMP cores, we previously limited
10370 * the number of vectors for num_lan_msix to be at most 50% of the
10371 * available vectors, to allow for other features. Now, we add back
10372 * the remaining vectors. However, we ensure that the total
10373 * num_lan_msix will not exceed num_online_cpus(). To do this, we
10374 * calculate the number of vectors we can add without going over the
10375 * cap of CPUs. For systems with a small number of CPUs this will be
10378 extra_vectors
= min_t(int, cpus
- pf
->num_lan_msix
, vectors_left
);
10379 pf
->num_lan_msix
+= extra_vectors
;
10380 vectors_left
-= extra_vectors
;
10382 WARN(vectors_left
< 0,
10383 "Calculation of remaining vectors underflowed. This is an accounting bug when determining total MSI-X vectors.\n");
10385 v_budget
+= pf
->num_lan_msix
;
10386 pf
->msix_entries
= kcalloc(v_budget
, sizeof(struct msix_entry
),
10388 if (!pf
->msix_entries
)
10391 for (i
= 0; i
< v_budget
; i
++)
10392 pf
->msix_entries
[i
].entry
= i
;
10393 v_actual
= i40e_reserve_msix_vectors(pf
, v_budget
);
10395 if (v_actual
< I40E_MIN_MSIX
) {
10396 pf
->flags
&= ~I40E_FLAG_MSIX_ENABLED
;
10397 kfree(pf
->msix_entries
);
10398 pf
->msix_entries
= NULL
;
10399 pci_disable_msix(pf
->pdev
);
10402 } else if (v_actual
== I40E_MIN_MSIX
) {
10403 /* Adjust for minimal MSIX use */
10404 pf
->num_vmdq_vsis
= 0;
10405 pf
->num_vmdq_qps
= 0;
10406 pf
->num_lan_qps
= 1;
10407 pf
->num_lan_msix
= 1;
10409 } else if (v_actual
!= v_budget
) {
10410 /* If we have limited resources, we will start with no vectors
10411 * for the special features and then allocate vectors to some
10412 * of these features based on the policy and at the end disable
10413 * the features that did not get any vectors.
10417 dev_info(&pf
->pdev
->dev
,
10418 "MSI-X vector limit reached with %d, wanted %d, attempting to redistribute vectors\n",
10419 v_actual
, v_budget
);
10420 /* reserve the misc vector */
10421 vec
= v_actual
- 1;
10423 /* Scale vector usage down */
10424 pf
->num_vmdq_msix
= 1; /* force VMDqs to only one vector */
10425 pf
->num_vmdq_vsis
= 1;
10426 pf
->num_vmdq_qps
= 1;
10428 /* partition out the remaining vectors */
10431 pf
->num_lan_msix
= 1;
10434 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
) {
10435 pf
->num_lan_msix
= 1;
10436 pf
->num_iwarp_msix
= 1;
10438 pf
->num_lan_msix
= 2;
10442 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
) {
10443 pf
->num_iwarp_msix
= min_t(int, (vec
/ 3),
10445 pf
->num_vmdq_vsis
= min_t(int, (vec
/ 3),
10446 I40E_DEFAULT_NUM_VMDQ_VSI
);
10448 pf
->num_vmdq_vsis
= min_t(int, (vec
/ 2),
10449 I40E_DEFAULT_NUM_VMDQ_VSI
);
10451 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
10452 pf
->num_fdsb_msix
= 1;
10455 pf
->num_lan_msix
= min_t(int,
10456 (vec
- (pf
->num_iwarp_msix
+ pf
->num_vmdq_vsis
)),
10458 pf
->num_lan_qps
= pf
->num_lan_msix
;
10463 if ((pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) &&
10464 (pf
->num_fdsb_msix
== 0)) {
10465 dev_info(&pf
->pdev
->dev
, "Sideband Flowdir disabled, not enough MSI-X vectors\n");
10466 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
10467 pf
->flags
|= I40E_FLAG_FD_SB_INACTIVE
;
10469 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
10470 (pf
->num_vmdq_msix
== 0)) {
10471 dev_info(&pf
->pdev
->dev
, "VMDq disabled, not enough MSI-X vectors\n");
10472 pf
->flags
&= ~I40E_FLAG_VMDQ_ENABLED
;
10475 if ((pf
->flags
& I40E_FLAG_IWARP_ENABLED
) &&
10476 (pf
->num_iwarp_msix
== 0)) {
10477 dev_info(&pf
->pdev
->dev
, "IWARP disabled, not enough MSI-X vectors\n");
10478 pf
->flags
&= ~I40E_FLAG_IWARP_ENABLED
;
10480 i40e_debug(&pf
->hw
, I40E_DEBUG_INIT
,
10481 "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n",
10483 pf
->num_vmdq_msix
* pf
->num_vmdq_vsis
,
10485 pf
->num_iwarp_msix
);
10491 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
10492 * @vsi: the VSI being configured
10493 * @v_idx: index of the vector in the vsi struct
10494 * @cpu: cpu to be used on affinity_mask
10496 * We allocate one q_vector. If allocation fails we return -ENOMEM.
10498 static int i40e_vsi_alloc_q_vector(struct i40e_vsi
*vsi
, int v_idx
, int cpu
)
10500 struct i40e_q_vector
*q_vector
;
10502 /* allocate q_vector */
10503 q_vector
= kzalloc(sizeof(struct i40e_q_vector
), GFP_KERNEL
);
10507 q_vector
->vsi
= vsi
;
10508 q_vector
->v_idx
= v_idx
;
10509 cpumask_copy(&q_vector
->affinity_mask
, cpu_possible_mask
);
10512 netif_napi_add(vsi
->netdev
, &q_vector
->napi
,
10513 i40e_napi_poll
, NAPI_POLL_WEIGHT
);
10515 /* tie q_vector and vsi together */
10516 vsi
->q_vectors
[v_idx
] = q_vector
;
10522 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
10523 * @vsi: the VSI being configured
10525 * We allocate one q_vector per queue interrupt. If allocation fails we
10528 static int i40e_vsi_alloc_q_vectors(struct i40e_vsi
*vsi
)
10530 struct i40e_pf
*pf
= vsi
->back
;
10531 int err
, v_idx
, num_q_vectors
, current_cpu
;
10533 /* if not MSIX, give the one vector only to the LAN VSI */
10534 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
10535 num_q_vectors
= vsi
->num_q_vectors
;
10536 else if (vsi
== pf
->vsi
[pf
->lan_vsi
])
10541 current_cpu
= cpumask_first(cpu_online_mask
);
10543 for (v_idx
= 0; v_idx
< num_q_vectors
; v_idx
++) {
10544 err
= i40e_vsi_alloc_q_vector(vsi
, v_idx
, current_cpu
);
10547 current_cpu
= cpumask_next(current_cpu
, cpu_online_mask
);
10548 if (unlikely(current_cpu
>= nr_cpu_ids
))
10549 current_cpu
= cpumask_first(cpu_online_mask
);
10556 i40e_free_q_vector(vsi
, v_idx
);
10562 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
10563 * @pf: board private structure to initialize
10565 static int i40e_init_interrupt_scheme(struct i40e_pf
*pf
)
10570 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
10571 vectors
= i40e_init_msix(pf
);
10573 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
|
10574 I40E_FLAG_IWARP_ENABLED
|
10575 I40E_FLAG_RSS_ENABLED
|
10576 I40E_FLAG_DCB_CAPABLE
|
10577 I40E_FLAG_DCB_ENABLED
|
10578 I40E_FLAG_SRIOV_ENABLED
|
10579 I40E_FLAG_FD_SB_ENABLED
|
10580 I40E_FLAG_FD_ATR_ENABLED
|
10581 I40E_FLAG_VMDQ_ENABLED
);
10582 pf
->flags
|= I40E_FLAG_FD_SB_INACTIVE
;
10584 /* rework the queue expectations without MSIX */
10585 i40e_determine_queue_usage(pf
);
10589 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
10590 (pf
->flags
& I40E_FLAG_MSI_ENABLED
)) {
10591 dev_info(&pf
->pdev
->dev
, "MSI-X not available, trying MSI\n");
10592 vectors
= pci_enable_msi(pf
->pdev
);
10594 dev_info(&pf
->pdev
->dev
, "MSI init failed - %d\n",
10596 pf
->flags
&= ~I40E_FLAG_MSI_ENABLED
;
10598 vectors
= 1; /* one MSI or Legacy vector */
10601 if (!(pf
->flags
& (I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
)))
10602 dev_info(&pf
->pdev
->dev
, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
10604 /* set up vector assignment tracking */
10605 size
= sizeof(struct i40e_lump_tracking
) + (sizeof(u16
) * vectors
);
10606 pf
->irq_pile
= kzalloc(size
, GFP_KERNEL
);
10610 pf
->irq_pile
->num_entries
= vectors
;
10611 pf
->irq_pile
->search_hint
= 0;
10613 /* track first vector for misc interrupts, ignore return */
10614 (void)i40e_get_lump(pf
, pf
->irq_pile
, 1, I40E_PILE_VALID_BIT
- 1);
10620 * i40e_restore_interrupt_scheme - Restore the interrupt scheme
10621 * @pf: private board data structure
10623 * Restore the interrupt scheme that was cleared when we suspended the
10624 * device. This should be called during resume to re-allocate the q_vectors
10625 * and reacquire IRQs.
10627 static int i40e_restore_interrupt_scheme(struct i40e_pf
*pf
)
10631 /* We cleared the MSI and MSI-X flags when disabling the old interrupt
10632 * scheme. We need to re-enabled them here in order to attempt to
10633 * re-acquire the MSI or MSI-X vectors
10635 pf
->flags
|= (I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
);
10637 err
= i40e_init_interrupt_scheme(pf
);
10641 /* Now that we've re-acquired IRQs, we need to remap the vectors and
10642 * rings together again.
10644 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
10646 err
= i40e_vsi_alloc_q_vectors(pf
->vsi
[i
]);
10649 i40e_vsi_map_rings_to_vectors(pf
->vsi
[i
]);
10653 err
= i40e_setup_misc_vector(pf
);
10657 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
)
10658 i40e_client_update_msix_info(pf
);
10665 i40e_vsi_free_q_vectors(pf
->vsi
[i
]);
10672 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
10673 * @pf: board private structure
10675 * This sets up the handler for MSIX 0, which is used to manage the
10676 * non-queue interrupts, e.g. AdminQ and errors. This is not used
10677 * when in MSI or Legacy interrupt mode.
10679 static int i40e_setup_misc_vector(struct i40e_pf
*pf
)
10681 struct i40e_hw
*hw
= &pf
->hw
;
10684 /* Only request the IRQ once, the first time through. */
10685 if (!test_and_set_bit(__I40E_MISC_IRQ_REQUESTED
, pf
->state
)) {
10686 err
= request_irq(pf
->msix_entries
[0].vector
,
10687 i40e_intr
, 0, pf
->int_name
, pf
);
10689 clear_bit(__I40E_MISC_IRQ_REQUESTED
, pf
->state
);
10690 dev_info(&pf
->pdev
->dev
,
10691 "request_irq for %s failed: %d\n",
10692 pf
->int_name
, err
);
10697 i40e_enable_misc_int_causes(pf
);
10699 /* associate no queues to the misc vector */
10700 wr32(hw
, I40E_PFINT_LNKLST0
, I40E_QUEUE_END_OF_LIST
);
10701 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), I40E_ITR_8K
);
10705 i40e_irq_dynamic_enable_icr0(pf
);
10711 * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
10712 * @vsi: Pointer to vsi structure
10713 * @seed: Buffter to store the hash keys
10714 * @lut: Buffer to store the lookup table entries
10715 * @lut_size: Size of buffer to store the lookup table entries
10717 * Return 0 on success, negative on failure
10719 static int i40e_get_rss_aq(struct i40e_vsi
*vsi
, const u8
*seed
,
10720 u8
*lut
, u16 lut_size
)
10722 struct i40e_pf
*pf
= vsi
->back
;
10723 struct i40e_hw
*hw
= &pf
->hw
;
10727 ret
= i40e_aq_get_rss_key(hw
, vsi
->id
,
10728 (struct i40e_aqc_get_set_rss_key_data
*)seed
);
10730 dev_info(&pf
->pdev
->dev
,
10731 "Cannot get RSS key, err %s aq_err %s\n",
10732 i40e_stat_str(&pf
->hw
, ret
),
10733 i40e_aq_str(&pf
->hw
,
10734 pf
->hw
.aq
.asq_last_status
));
10740 bool pf_lut
= vsi
->type
== I40E_VSI_MAIN
? true : false;
10742 ret
= i40e_aq_get_rss_lut(hw
, vsi
->id
, pf_lut
, lut
, lut_size
);
10744 dev_info(&pf
->pdev
->dev
,
10745 "Cannot get RSS lut, err %s aq_err %s\n",
10746 i40e_stat_str(&pf
->hw
, ret
),
10747 i40e_aq_str(&pf
->hw
,
10748 pf
->hw
.aq
.asq_last_status
));
10757 * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
10758 * @vsi: Pointer to vsi structure
10759 * @seed: RSS hash seed
10760 * @lut: Lookup table
10761 * @lut_size: Lookup table size
10763 * Returns 0 on success, negative on failure
10765 static int i40e_config_rss_reg(struct i40e_vsi
*vsi
, const u8
*seed
,
10766 const u8
*lut
, u16 lut_size
)
10768 struct i40e_pf
*pf
= vsi
->back
;
10769 struct i40e_hw
*hw
= &pf
->hw
;
10770 u16 vf_id
= vsi
->vf_id
;
10773 /* Fill out hash function seed */
10775 u32
*seed_dw
= (u32
*)seed
;
10777 if (vsi
->type
== I40E_VSI_MAIN
) {
10778 for (i
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++)
10779 wr32(hw
, I40E_PFQF_HKEY(i
), seed_dw
[i
]);
10780 } else if (vsi
->type
== I40E_VSI_SRIOV
) {
10781 for (i
= 0; i
<= I40E_VFQF_HKEY1_MAX_INDEX
; i
++)
10782 wr32(hw
, I40E_VFQF_HKEY1(i
, vf_id
), seed_dw
[i
]);
10784 dev_err(&pf
->pdev
->dev
, "Cannot set RSS seed - invalid VSI type\n");
10789 u32
*lut_dw
= (u32
*)lut
;
10791 if (vsi
->type
== I40E_VSI_MAIN
) {
10792 if (lut_size
!= I40E_HLUT_ARRAY_SIZE
)
10794 for (i
= 0; i
<= I40E_PFQF_HLUT_MAX_INDEX
; i
++)
10795 wr32(hw
, I40E_PFQF_HLUT(i
), lut_dw
[i
]);
10796 } else if (vsi
->type
== I40E_VSI_SRIOV
) {
10797 if (lut_size
!= I40E_VF_HLUT_ARRAY_SIZE
)
10799 for (i
= 0; i
<= I40E_VFQF_HLUT_MAX_INDEX
; i
++)
10800 wr32(hw
, I40E_VFQF_HLUT1(i
, vf_id
), lut_dw
[i
]);
10802 dev_err(&pf
->pdev
->dev
, "Cannot set RSS LUT - invalid VSI type\n");
10811 * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
10812 * @vsi: Pointer to VSI structure
10813 * @seed: Buffer to store the keys
10814 * @lut: Buffer to store the lookup table entries
10815 * @lut_size: Size of buffer to store the lookup table entries
10817 * Returns 0 on success, negative on failure
10819 static int i40e_get_rss_reg(struct i40e_vsi
*vsi
, u8
*seed
,
10820 u8
*lut
, u16 lut_size
)
10822 struct i40e_pf
*pf
= vsi
->back
;
10823 struct i40e_hw
*hw
= &pf
->hw
;
10827 u32
*seed_dw
= (u32
*)seed
;
10829 for (i
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++)
10830 seed_dw
[i
] = i40e_read_rx_ctl(hw
, I40E_PFQF_HKEY(i
));
10833 u32
*lut_dw
= (u32
*)lut
;
10835 if (lut_size
!= I40E_HLUT_ARRAY_SIZE
)
10837 for (i
= 0; i
<= I40E_PFQF_HLUT_MAX_INDEX
; i
++)
10838 lut_dw
[i
] = rd32(hw
, I40E_PFQF_HLUT(i
));
10845 * i40e_config_rss - Configure RSS keys and lut
10846 * @vsi: Pointer to VSI structure
10847 * @seed: RSS hash seed
10848 * @lut: Lookup table
10849 * @lut_size: Lookup table size
10851 * Returns 0 on success, negative on failure
10853 int i40e_config_rss(struct i40e_vsi
*vsi
, u8
*seed
, u8
*lut
, u16 lut_size
)
10855 struct i40e_pf
*pf
= vsi
->back
;
10857 if (pf
->hw_features
& I40E_HW_RSS_AQ_CAPABLE
)
10858 return i40e_config_rss_aq(vsi
, seed
, lut
, lut_size
);
10860 return i40e_config_rss_reg(vsi
, seed
, lut
, lut_size
);
10864 * i40e_get_rss - Get RSS keys and lut
10865 * @vsi: Pointer to VSI structure
10866 * @seed: Buffer to store the keys
10867 * @lut: Buffer to store the lookup table entries
10868 * @lut_size: Size of buffer to store the lookup table entries
10870 * Returns 0 on success, negative on failure
10872 int i40e_get_rss(struct i40e_vsi
*vsi
, u8
*seed
, u8
*lut
, u16 lut_size
)
10874 struct i40e_pf
*pf
= vsi
->back
;
10876 if (pf
->hw_features
& I40E_HW_RSS_AQ_CAPABLE
)
10877 return i40e_get_rss_aq(vsi
, seed
, lut
, lut_size
);
10879 return i40e_get_rss_reg(vsi
, seed
, lut
, lut_size
);
10883 * i40e_fill_rss_lut - Fill the RSS lookup table with default values
10884 * @pf: Pointer to board private structure
10885 * @lut: Lookup table
10886 * @rss_table_size: Lookup table size
10887 * @rss_size: Range of queue number for hashing
10889 void i40e_fill_rss_lut(struct i40e_pf
*pf
, u8
*lut
,
10890 u16 rss_table_size
, u16 rss_size
)
10894 for (i
= 0; i
< rss_table_size
; i
++)
10895 lut
[i
] = i
% rss_size
;
10899 * i40e_pf_config_rss - Prepare for RSS if used
10900 * @pf: board private structure
10902 static int i40e_pf_config_rss(struct i40e_pf
*pf
)
10904 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
10905 u8 seed
[I40E_HKEY_ARRAY_SIZE
];
10907 struct i40e_hw
*hw
= &pf
->hw
;
10912 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
10913 hena
= (u64
)i40e_read_rx_ctl(hw
, I40E_PFQF_HENA(0)) |
10914 ((u64
)i40e_read_rx_ctl(hw
, I40E_PFQF_HENA(1)) << 32);
10915 hena
|= i40e_pf_get_default_rss_hena(pf
);
10917 i40e_write_rx_ctl(hw
, I40E_PFQF_HENA(0), (u32
)hena
);
10918 i40e_write_rx_ctl(hw
, I40E_PFQF_HENA(1), (u32
)(hena
>> 32));
10920 /* Determine the RSS table size based on the hardware capabilities */
10921 reg_val
= i40e_read_rx_ctl(hw
, I40E_PFQF_CTL_0
);
10922 reg_val
= (pf
->rss_table_size
== 512) ?
10923 (reg_val
| I40E_PFQF_CTL_0_HASHLUTSIZE_512
) :
10924 (reg_val
& ~I40E_PFQF_CTL_0_HASHLUTSIZE_512
);
10925 i40e_write_rx_ctl(hw
, I40E_PFQF_CTL_0
, reg_val
);
10927 /* Determine the RSS size of the VSI */
10928 if (!vsi
->rss_size
) {
10930 /* If the firmware does something weird during VSI init, we
10931 * could end up with zero TCs. Check for that to avoid
10932 * divide-by-zero. It probably won't pass traffic, but it also
10935 qcount
= vsi
->num_queue_pairs
/
10936 (vsi
->tc_config
.numtc
? vsi
->tc_config
.numtc
: 1);
10937 vsi
->rss_size
= min_t(int, pf
->alloc_rss_size
, qcount
);
10939 if (!vsi
->rss_size
)
10942 lut
= kzalloc(vsi
->rss_table_size
, GFP_KERNEL
);
10946 /* Use user configured lut if there is one, otherwise use default */
10947 if (vsi
->rss_lut_user
)
10948 memcpy(lut
, vsi
->rss_lut_user
, vsi
->rss_table_size
);
10950 i40e_fill_rss_lut(pf
, lut
, vsi
->rss_table_size
, vsi
->rss_size
);
10952 /* Use user configured hash key if there is one, otherwise
10955 if (vsi
->rss_hkey_user
)
10956 memcpy(seed
, vsi
->rss_hkey_user
, I40E_HKEY_ARRAY_SIZE
);
10958 netdev_rss_key_fill((void *)seed
, I40E_HKEY_ARRAY_SIZE
);
10959 ret
= i40e_config_rss(vsi
, seed
, lut
, vsi
->rss_table_size
);
10966 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
10967 * @pf: board private structure
10968 * @queue_count: the requested queue count for rss.
10970 * returns 0 if rss is not enabled, if enabled returns the final rss queue
10971 * count which may be different from the requested queue count.
10972 * Note: expects to be called while under rtnl_lock()
10974 int i40e_reconfig_rss_queues(struct i40e_pf
*pf
, int queue_count
)
10976 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
10979 if (!(pf
->flags
& I40E_FLAG_RSS_ENABLED
))
10982 new_rss_size
= min_t(int, queue_count
, pf
->rss_size_max
);
10984 if (queue_count
!= vsi
->num_queue_pairs
) {
10987 vsi
->req_queue_pairs
= queue_count
;
10988 i40e_prep_for_reset(pf
, true);
10990 pf
->alloc_rss_size
= new_rss_size
;
10992 i40e_reset_and_rebuild(pf
, true, true);
10994 /* Discard the user configured hash keys and lut, if less
10995 * queues are enabled.
10997 if (queue_count
< vsi
->rss_size
) {
10998 i40e_clear_rss_config_user(vsi
);
10999 dev_dbg(&pf
->pdev
->dev
,
11000 "discard user configured hash keys and lut\n");
11003 /* Reset vsi->rss_size, as number of enabled queues changed */
11004 qcount
= vsi
->num_queue_pairs
/ vsi
->tc_config
.numtc
;
11005 vsi
->rss_size
= min_t(int, pf
->alloc_rss_size
, qcount
);
11007 i40e_pf_config_rss(pf
);
11009 dev_info(&pf
->pdev
->dev
, "User requested queue count/HW max RSS count: %d/%d\n",
11010 vsi
->req_queue_pairs
, pf
->rss_size_max
);
11011 return pf
->alloc_rss_size
;
11015 * i40e_get_partition_bw_setting - Retrieve BW settings for this PF partition
11016 * @pf: board private structure
11018 i40e_status
i40e_get_partition_bw_setting(struct i40e_pf
*pf
)
11020 i40e_status status
;
11021 bool min_valid
, max_valid
;
11022 u32 max_bw
, min_bw
;
11024 status
= i40e_read_bw_from_alt_ram(&pf
->hw
, &max_bw
, &min_bw
,
11025 &min_valid
, &max_valid
);
11029 pf
->min_bw
= min_bw
;
11031 pf
->max_bw
= max_bw
;
11038 * i40e_set_partition_bw_setting - Set BW settings for this PF partition
11039 * @pf: board private structure
11041 i40e_status
i40e_set_partition_bw_setting(struct i40e_pf
*pf
)
11043 struct i40e_aqc_configure_partition_bw_data bw_data
;
11044 i40e_status status
;
11046 /* Set the valid bit for this PF */
11047 bw_data
.pf_valid_bits
= cpu_to_le16(BIT(pf
->hw
.pf_id
));
11048 bw_data
.max_bw
[pf
->hw
.pf_id
] = pf
->max_bw
& I40E_ALT_BW_VALUE_MASK
;
11049 bw_data
.min_bw
[pf
->hw
.pf_id
] = pf
->min_bw
& I40E_ALT_BW_VALUE_MASK
;
11051 /* Set the new bandwidths */
11052 status
= i40e_aq_configure_partition_bw(&pf
->hw
, &bw_data
, NULL
);
11058 * i40e_commit_partition_bw_setting - Commit BW settings for this PF partition
11059 * @pf: board private structure
11061 i40e_status
i40e_commit_partition_bw_setting(struct i40e_pf
*pf
)
11063 /* Commit temporary BW setting to permanent NVM image */
11064 enum i40e_admin_queue_err last_aq_status
;
11068 if (pf
->hw
.partition_id
!= 1) {
11069 dev_info(&pf
->pdev
->dev
,
11070 "Commit BW only works on partition 1! This is partition %d",
11071 pf
->hw
.partition_id
);
11072 ret
= I40E_NOT_SUPPORTED
;
11073 goto bw_commit_out
;
11076 /* Acquire NVM for read access */
11077 ret
= i40e_acquire_nvm(&pf
->hw
, I40E_RESOURCE_READ
);
11078 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
11080 dev_info(&pf
->pdev
->dev
,
11081 "Cannot acquire NVM for read access, err %s aq_err %s\n",
11082 i40e_stat_str(&pf
->hw
, ret
),
11083 i40e_aq_str(&pf
->hw
, last_aq_status
));
11084 goto bw_commit_out
;
11087 /* Read word 0x10 of NVM - SW compatibility word 1 */
11088 ret
= i40e_aq_read_nvm(&pf
->hw
,
11089 I40E_SR_NVM_CONTROL_WORD
,
11090 0x10, sizeof(nvm_word
), &nvm_word
,
11092 /* Save off last admin queue command status before releasing
11095 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
11096 i40e_release_nvm(&pf
->hw
);
11098 dev_info(&pf
->pdev
->dev
, "NVM read error, err %s aq_err %s\n",
11099 i40e_stat_str(&pf
->hw
, ret
),
11100 i40e_aq_str(&pf
->hw
, last_aq_status
));
11101 goto bw_commit_out
;
11104 /* Wait a bit for NVM release to complete */
11107 /* Acquire NVM for write access */
11108 ret
= i40e_acquire_nvm(&pf
->hw
, I40E_RESOURCE_WRITE
);
11109 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
11111 dev_info(&pf
->pdev
->dev
,
11112 "Cannot acquire NVM for write access, err %s aq_err %s\n",
11113 i40e_stat_str(&pf
->hw
, ret
),
11114 i40e_aq_str(&pf
->hw
, last_aq_status
));
11115 goto bw_commit_out
;
11117 /* Write it back out unchanged to initiate update NVM,
11118 * which will force a write of the shadow (alt) RAM to
11119 * the NVM - thus storing the bandwidth values permanently.
11121 ret
= i40e_aq_update_nvm(&pf
->hw
,
11122 I40E_SR_NVM_CONTROL_WORD
,
11123 0x10, sizeof(nvm_word
),
11124 &nvm_word
, true, 0, NULL
);
11125 /* Save off last admin queue command status before releasing
11128 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
11129 i40e_release_nvm(&pf
->hw
);
11131 dev_info(&pf
->pdev
->dev
,
11132 "BW settings NOT SAVED, err %s aq_err %s\n",
11133 i40e_stat_str(&pf
->hw
, ret
),
11134 i40e_aq_str(&pf
->hw
, last_aq_status
));
11141 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
11142 * @pf: board private structure to initialize
11144 * i40e_sw_init initializes the Adapter private data structure.
11145 * Fields are initialized based on PCI device information and
11146 * OS network device settings (MTU size).
11148 static int i40e_sw_init(struct i40e_pf
*pf
)
11153 /* Set default capability flags */
11154 pf
->flags
= I40E_FLAG_RX_CSUM_ENABLED
|
11155 I40E_FLAG_MSI_ENABLED
|
11156 I40E_FLAG_MSIX_ENABLED
;
11158 /* Set default ITR */
11159 pf
->rx_itr_default
= I40E_ITR_RX_DEF
;
11160 pf
->tx_itr_default
= I40E_ITR_TX_DEF
;
11162 /* Depending on PF configurations, it is possible that the RSS
11163 * maximum might end up larger than the available queues
11165 pf
->rss_size_max
= BIT(pf
->hw
.func_caps
.rss_table_entry_width
);
11166 pf
->alloc_rss_size
= 1;
11167 pf
->rss_table_size
= pf
->hw
.func_caps
.rss_table_size
;
11168 pf
->rss_size_max
= min_t(int, pf
->rss_size_max
,
11169 pf
->hw
.func_caps
.num_tx_qp
);
11170 if (pf
->hw
.func_caps
.rss
) {
11171 pf
->flags
|= I40E_FLAG_RSS_ENABLED
;
11172 pf
->alloc_rss_size
= min_t(int, pf
->rss_size_max
,
11173 num_online_cpus());
11176 /* MFP mode enabled */
11177 if (pf
->hw
.func_caps
.npar_enable
|| pf
->hw
.func_caps
.flex10_enable
) {
11178 pf
->flags
|= I40E_FLAG_MFP_ENABLED
;
11179 dev_info(&pf
->pdev
->dev
, "MFP mode Enabled\n");
11180 if (i40e_get_partition_bw_setting(pf
)) {
11181 dev_warn(&pf
->pdev
->dev
,
11182 "Could not get partition bw settings\n");
11184 dev_info(&pf
->pdev
->dev
,
11185 "Partition BW Min = %8.8x, Max = %8.8x\n",
11186 pf
->min_bw
, pf
->max_bw
);
11188 /* nudge the Tx scheduler */
11189 i40e_set_partition_bw_setting(pf
);
11193 if ((pf
->hw
.func_caps
.fd_filters_guaranteed
> 0) ||
11194 (pf
->hw
.func_caps
.fd_filters_best_effort
> 0)) {
11195 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
11196 pf
->atr_sample_rate
= I40E_DEFAULT_ATR_SAMPLE_RATE
;
11197 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
&&
11198 pf
->hw
.num_partitions
> 1)
11199 dev_info(&pf
->pdev
->dev
,
11200 "Flow Director Sideband mode Disabled in MFP mode\n");
11202 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
11203 pf
->fdir_pf_filter_count
=
11204 pf
->hw
.func_caps
.fd_filters_guaranteed
;
11205 pf
->hw
.fdir_shared_filter_count
=
11206 pf
->hw
.func_caps
.fd_filters_best_effort
;
11209 if (pf
->hw
.mac
.type
== I40E_MAC_X722
) {
11210 pf
->hw_features
|= (I40E_HW_RSS_AQ_CAPABLE
|
11211 I40E_HW_128_QP_RSS_CAPABLE
|
11212 I40E_HW_ATR_EVICT_CAPABLE
|
11213 I40E_HW_WB_ON_ITR_CAPABLE
|
11214 I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE
|
11215 I40E_HW_NO_PCI_LINK_CHECK
|
11216 I40E_HW_USE_SET_LLDP_MIB
|
11217 I40E_HW_GENEVE_OFFLOAD_CAPABLE
|
11218 I40E_HW_PTP_L4_CAPABLE
|
11219 I40E_HW_WOL_MC_MAGIC_PKT_WAKE
|
11220 I40E_HW_OUTER_UDP_CSUM_CAPABLE
);
11222 #define I40E_FDEVICT_PCTYPE_DEFAULT 0xc03
11223 if (rd32(&pf
->hw
, I40E_GLQF_FDEVICTENA(1)) !=
11224 I40E_FDEVICT_PCTYPE_DEFAULT
) {
11225 dev_warn(&pf
->pdev
->dev
,
11226 "FD EVICT PCTYPES are not right, disable FD HW EVICT\n");
11227 pf
->hw_features
&= ~I40E_HW_ATR_EVICT_CAPABLE
;
11229 } else if ((pf
->hw
.aq
.api_maj_ver
> 1) ||
11230 ((pf
->hw
.aq
.api_maj_ver
== 1) &&
11231 (pf
->hw
.aq
.api_min_ver
> 4))) {
11232 /* Supported in FW API version higher than 1.4 */
11233 pf
->hw_features
|= I40E_HW_GENEVE_OFFLOAD_CAPABLE
;
11236 /* Enable HW ATR eviction if possible */
11237 if (pf
->hw_features
& I40E_HW_ATR_EVICT_CAPABLE
)
11238 pf
->flags
|= I40E_FLAG_HW_ATR_EVICT_ENABLED
;
11240 if ((pf
->hw
.mac
.type
== I40E_MAC_XL710
) &&
11241 (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
11242 (pf
->hw
.aq
.fw_maj_ver
< 4))) {
11243 pf
->hw_features
|= I40E_HW_RESTART_AUTONEG
;
11244 /* No DCB support for FW < v4.33 */
11245 pf
->hw_features
|= I40E_HW_NO_DCB_SUPPORT
;
11248 /* Disable FW LLDP if FW < v4.3 */
11249 if ((pf
->hw
.mac
.type
== I40E_MAC_XL710
) &&
11250 (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 3)) ||
11251 (pf
->hw
.aq
.fw_maj_ver
< 4)))
11252 pf
->hw_features
|= I40E_HW_STOP_FW_LLDP
;
11254 /* Use the FW Set LLDP MIB API if FW > v4.40 */
11255 if ((pf
->hw
.mac
.type
== I40E_MAC_XL710
) &&
11256 (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
>= 40)) ||
11257 (pf
->hw
.aq
.fw_maj_ver
>= 5)))
11258 pf
->hw_features
|= I40E_HW_USE_SET_LLDP_MIB
;
11260 /* Enable PTP L4 if FW > v6.0 */
11261 if (pf
->hw
.mac
.type
== I40E_MAC_XL710
&&
11262 pf
->hw
.aq
.fw_maj_ver
>= 6)
11263 pf
->hw_features
|= I40E_HW_PTP_L4_CAPABLE
;
11265 if (pf
->hw
.func_caps
.vmdq
&& num_online_cpus() != 1) {
11266 pf
->num_vmdq_vsis
= I40E_DEFAULT_NUM_VMDQ_VSI
;
11267 pf
->flags
|= I40E_FLAG_VMDQ_ENABLED
;
11268 pf
->num_vmdq_qps
= i40e_default_queues_per_vmdq(pf
);
11271 if (pf
->hw
.func_caps
.iwarp
&& num_online_cpus() != 1) {
11272 pf
->flags
|= I40E_FLAG_IWARP_ENABLED
;
11273 /* IWARP needs one extra vector for CQP just like MISC.*/
11274 pf
->num_iwarp_msix
= (int)num_online_cpus() + 1;
11276 /* Stopping the FW LLDP engine is only supported on the
11277 * XL710 with a FW ver >= 1.7. Also, stopping FW LLDP
11278 * engine is not supported if NPAR is functioning on this
11281 if (pf
->hw
.mac
.type
== I40E_MAC_XL710
&&
11282 !pf
->hw
.func_caps
.npar_enable
&&
11283 (pf
->hw
.aq
.api_maj_ver
> 1 ||
11284 (pf
->hw
.aq
.api_maj_ver
== 1 && pf
->hw
.aq
.api_min_ver
> 6)))
11285 pf
->hw_features
|= I40E_HW_STOPPABLE_FW_LLDP
;
11287 #ifdef CONFIG_PCI_IOV
11288 if (pf
->hw
.func_caps
.num_vfs
&& pf
->hw
.partition_id
== 1) {
11289 pf
->num_vf_qps
= I40E_DEFAULT_QUEUES_PER_VF
;
11290 pf
->flags
|= I40E_FLAG_SRIOV_ENABLED
;
11291 pf
->num_req_vfs
= min_t(int,
11292 pf
->hw
.func_caps
.num_vfs
,
11293 I40E_MAX_VF_COUNT
);
11295 #endif /* CONFIG_PCI_IOV */
11296 pf
->eeprom_version
= 0xDEAD;
11297 pf
->lan_veb
= I40E_NO_VEB
;
11298 pf
->lan_vsi
= I40E_NO_VSI
;
11300 /* By default FW has this off for performance reasons */
11301 pf
->flags
&= ~I40E_FLAG_VEB_STATS_ENABLED
;
11303 /* set up queue assignment tracking */
11304 size
= sizeof(struct i40e_lump_tracking
)
11305 + (sizeof(u16
) * pf
->hw
.func_caps
.num_tx_qp
);
11306 pf
->qp_pile
= kzalloc(size
, GFP_KERNEL
);
11307 if (!pf
->qp_pile
) {
11311 pf
->qp_pile
->num_entries
= pf
->hw
.func_caps
.num_tx_qp
;
11312 pf
->qp_pile
->search_hint
= 0;
11314 pf
->tx_timeout_recovery_level
= 1;
11316 mutex_init(&pf
->switch_mutex
);
11323 * i40e_set_ntuple - set the ntuple feature flag and take action
11324 * @pf: board private structure to initialize
11325 * @features: the feature set that the stack is suggesting
11327 * returns a bool to indicate if reset needs to happen
11329 bool i40e_set_ntuple(struct i40e_pf
*pf
, netdev_features_t features
)
11331 bool need_reset
= false;
11333 /* Check if Flow Director n-tuple support was enabled or disabled. If
11334 * the state changed, we need to reset.
11336 if (features
& NETIF_F_NTUPLE
) {
11337 /* Enable filters and mark for reset */
11338 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
11340 /* enable FD_SB only if there is MSI-X vector and no cloud
11343 if (pf
->num_fdsb_msix
> 0 && !pf
->num_cloud_filters
) {
11344 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
11345 pf
->flags
&= ~I40E_FLAG_FD_SB_INACTIVE
;
11348 /* turn off filters, mark for reset and clear SW filter list */
11349 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
11351 i40e_fdir_filter_exit(pf
);
11353 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
11354 clear_bit(__I40E_FD_SB_AUTO_DISABLED
, pf
->state
);
11355 pf
->flags
|= I40E_FLAG_FD_SB_INACTIVE
;
11357 /* reset fd counters */
11358 pf
->fd_add_err
= 0;
11359 pf
->fd_atr_cnt
= 0;
11360 /* if ATR was auto disabled it can be re-enabled. */
11361 if (test_and_clear_bit(__I40E_FD_ATR_AUTO_DISABLED
, pf
->state
))
11362 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
11363 (I40E_DEBUG_FD
& pf
->hw
.debug_mask
))
11364 dev_info(&pf
->pdev
->dev
, "ATR re-enabled.\n");
11370 * i40e_clear_rss_lut - clear the rx hash lookup table
11371 * @vsi: the VSI being configured
11373 static void i40e_clear_rss_lut(struct i40e_vsi
*vsi
)
11375 struct i40e_pf
*pf
= vsi
->back
;
11376 struct i40e_hw
*hw
= &pf
->hw
;
11377 u16 vf_id
= vsi
->vf_id
;
11380 if (vsi
->type
== I40E_VSI_MAIN
) {
11381 for (i
= 0; i
<= I40E_PFQF_HLUT_MAX_INDEX
; i
++)
11382 wr32(hw
, I40E_PFQF_HLUT(i
), 0);
11383 } else if (vsi
->type
== I40E_VSI_SRIOV
) {
11384 for (i
= 0; i
<= I40E_VFQF_HLUT_MAX_INDEX
; i
++)
11385 i40e_write_rx_ctl(hw
, I40E_VFQF_HLUT1(i
, vf_id
), 0);
11387 dev_err(&pf
->pdev
->dev
, "Cannot set RSS LUT - invalid VSI type\n");
11392 * i40e_set_features - set the netdev feature flags
11393 * @netdev: ptr to the netdev being adjusted
11394 * @features: the feature set that the stack is suggesting
11395 * Note: expects to be called while under rtnl_lock()
11397 static int i40e_set_features(struct net_device
*netdev
,
11398 netdev_features_t features
)
11400 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
11401 struct i40e_vsi
*vsi
= np
->vsi
;
11402 struct i40e_pf
*pf
= vsi
->back
;
11405 if (features
& NETIF_F_RXHASH
&& !(netdev
->features
& NETIF_F_RXHASH
))
11406 i40e_pf_config_rss(pf
);
11407 else if (!(features
& NETIF_F_RXHASH
) &&
11408 netdev
->features
& NETIF_F_RXHASH
)
11409 i40e_clear_rss_lut(vsi
);
11411 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
11412 i40e_vlan_stripping_enable(vsi
);
11414 i40e_vlan_stripping_disable(vsi
);
11416 if (!(features
& NETIF_F_HW_TC
) && pf
->num_cloud_filters
) {
11417 dev_err(&pf
->pdev
->dev
,
11418 "Offloaded tc filters active, can't turn hw_tc_offload off");
11422 need_reset
= i40e_set_ntuple(pf
, features
);
11425 i40e_do_reset(pf
, I40E_PF_RESET_FLAG
, true);
11431 * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
11432 * @pf: board private structure
11433 * @port: The UDP port to look up
11435 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
11437 static u8
i40e_get_udp_port_idx(struct i40e_pf
*pf
, u16 port
)
11441 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
11442 /* Do not report ports with pending deletions as
11445 if (!port
&& (pf
->pending_udp_bitmap
& BIT_ULL(i
)))
11447 if (pf
->udp_ports
[i
].port
== port
)
11455 * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
11456 * @netdev: This physical port's netdev
11457 * @ti: Tunnel endpoint information
11459 static void i40e_udp_tunnel_add(struct net_device
*netdev
,
11460 struct udp_tunnel_info
*ti
)
11462 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
11463 struct i40e_vsi
*vsi
= np
->vsi
;
11464 struct i40e_pf
*pf
= vsi
->back
;
11465 u16 port
= ntohs(ti
->port
);
11469 idx
= i40e_get_udp_port_idx(pf
, port
);
11471 /* Check if port already exists */
11472 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
11473 netdev_info(netdev
, "port %d already offloaded\n", port
);
11477 /* Now check if there is space to add the new port */
11478 next_idx
= i40e_get_udp_port_idx(pf
, 0);
11480 if (next_idx
== I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
11481 netdev_info(netdev
, "maximum number of offloaded UDP ports reached, not adding port %d\n",
11486 switch (ti
->type
) {
11487 case UDP_TUNNEL_TYPE_VXLAN
:
11488 pf
->udp_ports
[next_idx
].type
= I40E_AQC_TUNNEL_TYPE_VXLAN
;
11490 case UDP_TUNNEL_TYPE_GENEVE
:
11491 if (!(pf
->hw_features
& I40E_HW_GENEVE_OFFLOAD_CAPABLE
))
11493 pf
->udp_ports
[next_idx
].type
= I40E_AQC_TUNNEL_TYPE_NGE
;
11499 /* New port: add it and mark its index in the bitmap */
11500 pf
->udp_ports
[next_idx
].port
= port
;
11501 pf
->udp_ports
[next_idx
].filter_index
= I40E_UDP_PORT_INDEX_UNUSED
;
11502 pf
->pending_udp_bitmap
|= BIT_ULL(next_idx
);
11503 set_bit(__I40E_UDP_FILTER_SYNC_PENDING
, pf
->state
);
11507 * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
11508 * @netdev: This physical port's netdev
11509 * @ti: Tunnel endpoint information
11511 static void i40e_udp_tunnel_del(struct net_device
*netdev
,
11512 struct udp_tunnel_info
*ti
)
11514 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
11515 struct i40e_vsi
*vsi
= np
->vsi
;
11516 struct i40e_pf
*pf
= vsi
->back
;
11517 u16 port
= ntohs(ti
->port
);
11520 idx
= i40e_get_udp_port_idx(pf
, port
);
11522 /* Check if port already exists */
11523 if (idx
>= I40E_MAX_PF_UDP_OFFLOAD_PORTS
)
11526 switch (ti
->type
) {
11527 case UDP_TUNNEL_TYPE_VXLAN
:
11528 if (pf
->udp_ports
[idx
].type
!= I40E_AQC_TUNNEL_TYPE_VXLAN
)
11531 case UDP_TUNNEL_TYPE_GENEVE
:
11532 if (pf
->udp_ports
[idx
].type
!= I40E_AQC_TUNNEL_TYPE_NGE
)
11539 /* if port exists, set it to 0 (mark for deletion)
11540 * and make it pending
11542 pf
->udp_ports
[idx
].port
= 0;
11544 /* Toggle pending bit instead of setting it. This way if we are
11545 * deleting a port that has yet to be added we just clear the pending
11546 * bit and don't have to worry about it.
11548 pf
->pending_udp_bitmap
^= BIT_ULL(idx
);
11549 set_bit(__I40E_UDP_FILTER_SYNC_PENDING
, pf
->state
);
11553 netdev_warn(netdev
, "UDP port %d was not found, not deleting\n",
11557 static int i40e_get_phys_port_id(struct net_device
*netdev
,
11558 struct netdev_phys_item_id
*ppid
)
11560 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
11561 struct i40e_pf
*pf
= np
->vsi
->back
;
11562 struct i40e_hw
*hw
= &pf
->hw
;
11564 if (!(pf
->hw_features
& I40E_HW_PORT_ID_VALID
))
11565 return -EOPNOTSUPP
;
11567 ppid
->id_len
= min_t(int, sizeof(hw
->mac
.port_addr
), sizeof(ppid
->id
));
11568 memcpy(ppid
->id
, hw
->mac
.port_addr
, ppid
->id_len
);
11574 * i40e_ndo_fdb_add - add an entry to the hardware database
11575 * @ndm: the input from the stack
11576 * @tb: pointer to array of nladdr (unused)
11577 * @dev: the net device pointer
11578 * @addr: the MAC address entry being added
11580 * @flags: instructions from stack about fdb operation
11582 static int i40e_ndo_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
11583 struct net_device
*dev
,
11584 const unsigned char *addr
, u16 vid
,
11587 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
11588 struct i40e_pf
*pf
= np
->vsi
->back
;
11591 if (!(pf
->flags
& I40E_FLAG_SRIOV_ENABLED
))
11592 return -EOPNOTSUPP
;
11595 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev
->name
);
11599 /* Hardware does not support aging addresses so if a
11600 * ndm_state is given only allow permanent addresses
11602 if (ndm
->ndm_state
&& !(ndm
->ndm_state
& NUD_PERMANENT
)) {
11603 netdev_info(dev
, "FDB only supports static addresses\n");
11607 if (is_unicast_ether_addr(addr
) || is_link_local_ether_addr(addr
))
11608 err
= dev_uc_add_excl(dev
, addr
);
11609 else if (is_multicast_ether_addr(addr
))
11610 err
= dev_mc_add_excl(dev
, addr
);
11614 /* Only return duplicate errors if NLM_F_EXCL is set */
11615 if (err
== -EEXIST
&& !(flags
& NLM_F_EXCL
))
11622 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
11623 * @dev: the netdev being configured
11624 * @nlh: RTNL message
11625 * @flags: bridge flags
11627 * Inserts a new hardware bridge if not already created and
11628 * enables the bridging mode requested (VEB or VEPA). If the
11629 * hardware bridge has already been inserted and the request
11630 * is to change the mode then that requires a PF reset to
11631 * allow rebuild of the components with required hardware
11632 * bridge mode enabled.
11634 * Note: expects to be called while under rtnl_lock()
11636 static int i40e_ndo_bridge_setlink(struct net_device
*dev
,
11637 struct nlmsghdr
*nlh
,
11640 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
11641 struct i40e_vsi
*vsi
= np
->vsi
;
11642 struct i40e_pf
*pf
= vsi
->back
;
11643 struct i40e_veb
*veb
= NULL
;
11644 struct nlattr
*attr
, *br_spec
;
11647 /* Only for PF VSI for now */
11648 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
)
11649 return -EOPNOTSUPP
;
11651 /* Find the HW bridge for PF VSI */
11652 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
11653 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
11657 br_spec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
11659 nla_for_each_nested(attr
, br_spec
, rem
) {
11662 if (nla_type(attr
) != IFLA_BRIDGE_MODE
)
11665 mode
= nla_get_u16(attr
);
11666 if ((mode
!= BRIDGE_MODE_VEPA
) &&
11667 (mode
!= BRIDGE_MODE_VEB
))
11670 /* Insert a new HW bridge */
11672 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
11673 vsi
->tc_config
.enabled_tc
);
11675 veb
->bridge_mode
= mode
;
11676 i40e_config_bridge_mode(veb
);
11678 /* No Bridge HW offload available */
11682 } else if (mode
!= veb
->bridge_mode
) {
11683 /* Existing HW bridge but different mode needs reset */
11684 veb
->bridge_mode
= mode
;
11685 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
11686 if (mode
== BRIDGE_MODE_VEB
)
11687 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
11689 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
11690 i40e_do_reset(pf
, I40E_PF_RESET_FLAG
, true);
11699 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
11702 * @seq: RTNL message seq #
11703 * @dev: the netdev being configured
11704 * @filter_mask: unused
11705 * @nlflags: netlink flags passed in
11707 * Return the mode in which the hardware bridge is operating in
11710 static int i40e_ndo_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
11711 struct net_device
*dev
,
11712 u32 __always_unused filter_mask
,
11715 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
11716 struct i40e_vsi
*vsi
= np
->vsi
;
11717 struct i40e_pf
*pf
= vsi
->back
;
11718 struct i40e_veb
*veb
= NULL
;
11721 /* Only for PF VSI for now */
11722 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
)
11723 return -EOPNOTSUPP
;
11725 /* Find the HW bridge for the PF VSI */
11726 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
11727 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
11734 return ndo_dflt_bridge_getlink(skb
, pid
, seq
, dev
, veb
->bridge_mode
,
11735 0, 0, nlflags
, filter_mask
, NULL
);
11739 * i40e_features_check - Validate encapsulated packet conforms to limits
11741 * @dev: This physical port's netdev
11742 * @features: Offload features that the stack believes apply
11744 static netdev_features_t
i40e_features_check(struct sk_buff
*skb
,
11745 struct net_device
*dev
,
11746 netdev_features_t features
)
11750 /* No point in doing any of this if neither checksum nor GSO are
11751 * being requested for this frame. We can rule out both by just
11752 * checking for CHECKSUM_PARTIAL
11754 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
11757 /* We cannot support GSO if the MSS is going to be less than
11758 * 64 bytes. If it is then we need to drop support for GSO.
11760 if (skb_is_gso(skb
) && (skb_shinfo(skb
)->gso_size
< 64))
11761 features
&= ~NETIF_F_GSO_MASK
;
11763 /* MACLEN can support at most 63 words */
11764 len
= skb_network_header(skb
) - skb
->data
;
11765 if (len
& ~(63 * 2))
11768 /* IPLEN and EIPLEN can support at most 127 dwords */
11769 len
= skb_transport_header(skb
) - skb_network_header(skb
);
11770 if (len
& ~(127 * 4))
11773 if (skb
->encapsulation
) {
11774 /* L4TUNLEN can support 127 words */
11775 len
= skb_inner_network_header(skb
) - skb_transport_header(skb
);
11776 if (len
& ~(127 * 2))
11779 /* IPLEN can support at most 127 dwords */
11780 len
= skb_inner_transport_header(skb
) -
11781 skb_inner_network_header(skb
);
11782 if (len
& ~(127 * 4))
11786 /* No need to validate L4LEN as TCP is the only protocol with a
11787 * a flexible value and we support all possible values supported
11788 * by TCP, which is at most 15 dwords
11793 return features
& ~(NETIF_F_CSUM_MASK
| NETIF_F_GSO_MASK
);
11797 * i40e_xdp_setup - add/remove an XDP program
11798 * @vsi: VSI to changed
11799 * @prog: XDP program
11801 static int i40e_xdp_setup(struct i40e_vsi
*vsi
,
11802 struct bpf_prog
*prog
)
11804 int frame_size
= vsi
->netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
11805 struct i40e_pf
*pf
= vsi
->back
;
11806 struct bpf_prog
*old_prog
;
11810 /* Don't allow frames that span over multiple buffers */
11811 if (frame_size
> vsi
->rx_buf_len
)
11814 if (!i40e_enabled_xdp_vsi(vsi
) && !prog
)
11817 /* When turning XDP on->off/off->on we reset and rebuild the rings. */
11818 need_reset
= (i40e_enabled_xdp_vsi(vsi
) != !!prog
);
11821 i40e_prep_for_reset(pf
, true);
11823 old_prog
= xchg(&vsi
->xdp_prog
, prog
);
11826 i40e_reset_and_rebuild(pf
, true, true);
11828 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
11829 WRITE_ONCE(vsi
->rx_rings
[i
]->xdp_prog
, vsi
->xdp_prog
);
11832 bpf_prog_put(old_prog
);
11838 * i40e_xdp - implements ndo_bpf for i40e
11840 * @xdp: XDP command
11842 static int i40e_xdp(struct net_device
*dev
,
11843 struct netdev_bpf
*xdp
)
11845 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
11846 struct i40e_vsi
*vsi
= np
->vsi
;
11848 if (vsi
->type
!= I40E_VSI_MAIN
)
11851 switch (xdp
->command
) {
11852 case XDP_SETUP_PROG
:
11853 return i40e_xdp_setup(vsi
, xdp
->prog
);
11854 case XDP_QUERY_PROG
:
11855 xdp
->prog_id
= vsi
->xdp_prog
? vsi
->xdp_prog
->aux
->id
: 0;
11862 static const struct net_device_ops i40e_netdev_ops
= {
11863 .ndo_open
= i40e_open
,
11864 .ndo_stop
= i40e_close
,
11865 .ndo_start_xmit
= i40e_lan_xmit_frame
,
11866 .ndo_get_stats64
= i40e_get_netdev_stats_struct
,
11867 .ndo_set_rx_mode
= i40e_set_rx_mode
,
11868 .ndo_validate_addr
= eth_validate_addr
,
11869 .ndo_set_mac_address
= i40e_set_mac
,
11870 .ndo_change_mtu
= i40e_change_mtu
,
11871 .ndo_do_ioctl
= i40e_ioctl
,
11872 .ndo_tx_timeout
= i40e_tx_timeout
,
11873 .ndo_vlan_rx_add_vid
= i40e_vlan_rx_add_vid
,
11874 .ndo_vlan_rx_kill_vid
= i40e_vlan_rx_kill_vid
,
11875 #ifdef CONFIG_NET_POLL_CONTROLLER
11876 .ndo_poll_controller
= i40e_netpoll
,
11878 .ndo_setup_tc
= __i40e_setup_tc
,
11879 .ndo_set_features
= i40e_set_features
,
11880 .ndo_set_vf_mac
= i40e_ndo_set_vf_mac
,
11881 .ndo_set_vf_vlan
= i40e_ndo_set_vf_port_vlan
,
11882 .ndo_set_vf_rate
= i40e_ndo_set_vf_bw
,
11883 .ndo_get_vf_config
= i40e_ndo_get_vf_config
,
11884 .ndo_set_vf_link_state
= i40e_ndo_set_vf_link_state
,
11885 .ndo_set_vf_spoofchk
= i40e_ndo_set_vf_spoofchk
,
11886 .ndo_set_vf_trust
= i40e_ndo_set_vf_trust
,
11887 .ndo_udp_tunnel_add
= i40e_udp_tunnel_add
,
11888 .ndo_udp_tunnel_del
= i40e_udp_tunnel_del
,
11889 .ndo_get_phys_port_id
= i40e_get_phys_port_id
,
11890 .ndo_fdb_add
= i40e_ndo_fdb_add
,
11891 .ndo_features_check
= i40e_features_check
,
11892 .ndo_bridge_getlink
= i40e_ndo_bridge_getlink
,
11893 .ndo_bridge_setlink
= i40e_ndo_bridge_setlink
,
11894 .ndo_bpf
= i40e_xdp
,
11895 .ndo_xdp_xmit
= i40e_xdp_xmit
,
11899 * i40e_config_netdev - Setup the netdev flags
11900 * @vsi: the VSI being configured
11902 * Returns 0 on success, negative value on failure
11904 static int i40e_config_netdev(struct i40e_vsi
*vsi
)
11906 struct i40e_pf
*pf
= vsi
->back
;
11907 struct i40e_hw
*hw
= &pf
->hw
;
11908 struct i40e_netdev_priv
*np
;
11909 struct net_device
*netdev
;
11910 u8 broadcast
[ETH_ALEN
];
11911 u8 mac_addr
[ETH_ALEN
];
11913 netdev_features_t hw_enc_features
;
11914 netdev_features_t hw_features
;
11916 etherdev_size
= sizeof(struct i40e_netdev_priv
);
11917 netdev
= alloc_etherdev_mq(etherdev_size
, vsi
->alloc_queue_pairs
);
11921 vsi
->netdev
= netdev
;
11922 np
= netdev_priv(netdev
);
11925 hw_enc_features
= NETIF_F_SG
|
11927 NETIF_F_IPV6_CSUM
|
11929 NETIF_F_SOFT_FEATURES
|
11934 NETIF_F_GSO_GRE_CSUM
|
11935 NETIF_F_GSO_PARTIAL
|
11936 NETIF_F_GSO_IPXIP4
|
11937 NETIF_F_GSO_IPXIP6
|
11938 NETIF_F_GSO_UDP_TUNNEL
|
11939 NETIF_F_GSO_UDP_TUNNEL_CSUM
|
11945 if (!(pf
->hw_features
& I40E_HW_OUTER_UDP_CSUM_CAPABLE
))
11946 netdev
->gso_partial_features
|= NETIF_F_GSO_UDP_TUNNEL_CSUM
;
11948 netdev
->gso_partial_features
|= NETIF_F_GSO_GRE_CSUM
;
11950 netdev
->hw_enc_features
|= hw_enc_features
;
11952 /* record features VLANs can make use of */
11953 netdev
->vlan_features
|= hw_enc_features
| NETIF_F_TSO_MANGLEID
;
11955 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
11956 netdev
->hw_features
|= NETIF_F_NTUPLE
| NETIF_F_HW_TC
;
11958 hw_features
= hw_enc_features
|
11959 NETIF_F_HW_VLAN_CTAG_TX
|
11960 NETIF_F_HW_VLAN_CTAG_RX
;
11962 netdev
->hw_features
|= hw_features
;
11964 netdev
->features
|= hw_features
| NETIF_F_HW_VLAN_CTAG_FILTER
;
11965 netdev
->hw_enc_features
|= NETIF_F_TSO_MANGLEID
;
11967 if (vsi
->type
== I40E_VSI_MAIN
) {
11968 SET_NETDEV_DEV(netdev
, &pf
->pdev
->dev
);
11969 ether_addr_copy(mac_addr
, hw
->mac
.perm_addr
);
11970 /* The following steps are necessary for two reasons. First,
11971 * some older NVM configurations load a default MAC-VLAN
11972 * filter that will accept any tagged packet, and we want to
11973 * replace this with a normal filter. Additionally, it is
11974 * possible our MAC address was provided by the platform using
11975 * Open Firmware or similar.
11977 * Thus, we need to remove the default filter and install one
11978 * specific to the MAC address.
11980 i40e_rm_default_mac_filter(vsi
, mac_addr
);
11981 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
11982 i40e_add_mac_filter(vsi
, mac_addr
);
11983 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
11985 /* Relate the VSI_VMDQ name to the VSI_MAIN name. Note that we
11986 * are still limited by IFNAMSIZ, but we're adding 'v%d\0' to
11987 * the end, which is 4 bytes long, so force truncation of the
11988 * original name by IFNAMSIZ - 4
11990 snprintf(netdev
->name
, IFNAMSIZ
, "%.*sv%%d",
11992 pf
->vsi
[pf
->lan_vsi
]->netdev
->name
);
11993 eth_random_addr(mac_addr
);
11995 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
11996 i40e_add_mac_filter(vsi
, mac_addr
);
11997 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
12000 /* Add the broadcast filter so that we initially will receive
12001 * broadcast packets. Note that when a new VLAN is first added the
12002 * driver will convert all filters marked I40E_VLAN_ANY into VLAN
12003 * specific filters as part of transitioning into "vlan" operation.
12004 * When more VLANs are added, the driver will copy each existing MAC
12005 * filter and add it for the new VLAN.
12007 * Broadcast filters are handled specially by
12008 * i40e_sync_filters_subtask, as the driver must to set the broadcast
12009 * promiscuous bit instead of adding this directly as a MAC/VLAN
12010 * filter. The subtask will update the correct broadcast promiscuous
12011 * bits as VLANs become active or inactive.
12013 eth_broadcast_addr(broadcast
);
12014 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
12015 i40e_add_mac_filter(vsi
, broadcast
);
12016 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
12018 ether_addr_copy(netdev
->dev_addr
, mac_addr
);
12019 ether_addr_copy(netdev
->perm_addr
, mac_addr
);
12021 /* i40iw_net_event() reads 16 bytes from neigh->primary_key */
12022 netdev
->neigh_priv_len
= sizeof(u32
) * 4;
12024 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
12025 netdev
->priv_flags
|= IFF_SUPP_NOFCS
;
12026 /* Setup netdev TC information */
12027 i40e_vsi_config_netdev_tc(vsi
, vsi
->tc_config
.enabled_tc
);
12029 netdev
->netdev_ops
= &i40e_netdev_ops
;
12030 netdev
->watchdog_timeo
= 5 * HZ
;
12031 i40e_set_ethtool_ops(netdev
);
12033 /* MTU range: 68 - 9706 */
12034 netdev
->min_mtu
= ETH_MIN_MTU
;
12035 netdev
->max_mtu
= I40E_MAX_RXBUFFER
- I40E_PACKET_HDR_PAD
;
12041 * i40e_vsi_delete - Delete a VSI from the switch
12042 * @vsi: the VSI being removed
12044 * Returns 0 on success, negative value on failure
12046 static void i40e_vsi_delete(struct i40e_vsi
*vsi
)
12048 /* remove default VSI is not allowed */
12049 if (vsi
== vsi
->back
->vsi
[vsi
->back
->lan_vsi
])
12052 i40e_aq_delete_element(&vsi
->back
->hw
, vsi
->seid
, NULL
);
12056 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
12057 * @vsi: the VSI being queried
12059 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
12061 int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi
*vsi
)
12063 struct i40e_veb
*veb
;
12064 struct i40e_pf
*pf
= vsi
->back
;
12066 /* Uplink is not a bridge so default to VEB */
12067 if (vsi
->veb_idx
== I40E_NO_VEB
)
12070 veb
= pf
->veb
[vsi
->veb_idx
];
12072 dev_info(&pf
->pdev
->dev
,
12073 "There is no veb associated with the bridge\n");
12077 /* Uplink is a bridge in VEPA mode */
12078 if (veb
->bridge_mode
& BRIDGE_MODE_VEPA
) {
12081 /* Uplink is a bridge in VEB mode */
12085 /* VEPA is now default bridge, so return 0 */
12090 * i40e_add_vsi - Add a VSI to the switch
12091 * @vsi: the VSI being configured
12093 * This initializes a VSI context depending on the VSI type to be added and
12094 * passes it down to the add_vsi aq command.
12096 static int i40e_add_vsi(struct i40e_vsi
*vsi
)
12099 struct i40e_pf
*pf
= vsi
->back
;
12100 struct i40e_hw
*hw
= &pf
->hw
;
12101 struct i40e_vsi_context ctxt
;
12102 struct i40e_mac_filter
*f
;
12103 struct hlist_node
*h
;
12106 u8 enabled_tc
= 0x1; /* TC0 enabled */
12109 memset(&ctxt
, 0, sizeof(ctxt
));
12110 switch (vsi
->type
) {
12111 case I40E_VSI_MAIN
:
12112 /* The PF's main VSI is already setup as part of the
12113 * device initialization, so we'll not bother with
12114 * the add_vsi call, but we will retrieve the current
12117 ctxt
.seid
= pf
->main_vsi_seid
;
12118 ctxt
.pf_num
= pf
->hw
.pf_id
;
12120 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
12121 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
12123 dev_info(&pf
->pdev
->dev
,
12124 "couldn't get PF vsi config, err %s aq_err %s\n",
12125 i40e_stat_str(&pf
->hw
, ret
),
12126 i40e_aq_str(&pf
->hw
,
12127 pf
->hw
.aq
.asq_last_status
));
12130 vsi
->info
= ctxt
.info
;
12131 vsi
->info
.valid_sections
= 0;
12133 vsi
->seid
= ctxt
.seid
;
12134 vsi
->id
= ctxt
.vsi_number
;
12136 enabled_tc
= i40e_pf_get_tc_map(pf
);
12138 /* Source pruning is enabled by default, so the flag is
12139 * negative logic - if it's set, we need to fiddle with
12140 * the VSI to disable source pruning.
12142 if (pf
->flags
& I40E_FLAG_SOURCE_PRUNING_DISABLED
) {
12143 memset(&ctxt
, 0, sizeof(ctxt
));
12144 ctxt
.seid
= pf
->main_vsi_seid
;
12145 ctxt
.pf_num
= pf
->hw
.pf_id
;
12147 ctxt
.info
.valid_sections
|=
12148 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
12149 ctxt
.info
.switch_id
=
12150 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB
);
12151 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
12153 dev_info(&pf
->pdev
->dev
,
12154 "update vsi failed, err %s aq_err %s\n",
12155 i40e_stat_str(&pf
->hw
, ret
),
12156 i40e_aq_str(&pf
->hw
,
12157 pf
->hw
.aq
.asq_last_status
));
12163 /* MFP mode setup queue map and update VSI */
12164 if ((pf
->flags
& I40E_FLAG_MFP_ENABLED
) &&
12165 !(pf
->hw
.func_caps
.iscsi
)) { /* NIC type PF */
12166 memset(&ctxt
, 0, sizeof(ctxt
));
12167 ctxt
.seid
= pf
->main_vsi_seid
;
12168 ctxt
.pf_num
= pf
->hw
.pf_id
;
12170 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
12171 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
12173 dev_info(&pf
->pdev
->dev
,
12174 "update vsi failed, err %s aq_err %s\n",
12175 i40e_stat_str(&pf
->hw
, ret
),
12176 i40e_aq_str(&pf
->hw
,
12177 pf
->hw
.aq
.asq_last_status
));
12181 /* update the local VSI info queue map */
12182 i40e_vsi_update_queue_map(vsi
, &ctxt
);
12183 vsi
->info
.valid_sections
= 0;
12185 /* Default/Main VSI is only enabled for TC0
12186 * reconfigure it to enable all TCs that are
12187 * available on the port in SFP mode.
12188 * For MFP case the iSCSI PF would use this
12189 * flow to enable LAN+iSCSI TC.
12191 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
12193 /* Single TC condition is not fatal,
12194 * message and continue
12196 dev_info(&pf
->pdev
->dev
,
12197 "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
12199 i40e_stat_str(&pf
->hw
, ret
),
12200 i40e_aq_str(&pf
->hw
,
12201 pf
->hw
.aq
.asq_last_status
));
12206 case I40E_VSI_FDIR
:
12207 ctxt
.pf_num
= hw
->pf_id
;
12209 ctxt
.uplink_seid
= vsi
->uplink_seid
;
12210 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
12211 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
12212 if ((pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
) &&
12213 (i40e_is_vsi_uplink_mode_veb(vsi
))) {
12214 ctxt
.info
.valid_sections
|=
12215 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
12216 ctxt
.info
.switch_id
=
12217 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
12219 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
12222 case I40E_VSI_VMDQ2
:
12223 ctxt
.pf_num
= hw
->pf_id
;
12225 ctxt
.uplink_seid
= vsi
->uplink_seid
;
12226 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
12227 ctxt
.flags
= I40E_AQ_VSI_TYPE_VMDQ2
;
12229 /* This VSI is connected to VEB so the switch_id
12230 * should be set to zero by default.
12232 if (i40e_is_vsi_uplink_mode_veb(vsi
)) {
12233 ctxt
.info
.valid_sections
|=
12234 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
12235 ctxt
.info
.switch_id
=
12236 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
12239 /* Setup the VSI tx/rx queue map for TC0 only for now */
12240 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
12243 case I40E_VSI_SRIOV
:
12244 ctxt
.pf_num
= hw
->pf_id
;
12245 ctxt
.vf_num
= vsi
->vf_id
+ hw
->func_caps
.vf_base_id
;
12246 ctxt
.uplink_seid
= vsi
->uplink_seid
;
12247 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
12248 ctxt
.flags
= I40E_AQ_VSI_TYPE_VF
;
12250 /* This VSI is connected to VEB so the switch_id
12251 * should be set to zero by default.
12253 if (i40e_is_vsi_uplink_mode_veb(vsi
)) {
12254 ctxt
.info
.valid_sections
|=
12255 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
12256 ctxt
.info
.switch_id
=
12257 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
12260 if (vsi
->back
->flags
& I40E_FLAG_IWARP_ENABLED
) {
12261 ctxt
.info
.valid_sections
|=
12262 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID
);
12263 ctxt
.info
.queueing_opt_flags
|=
12264 (I40E_AQ_VSI_QUE_OPT_TCP_ENA
|
12265 I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI
);
12268 ctxt
.info
.valid_sections
|= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
12269 ctxt
.info
.port_vlan_flags
|= I40E_AQ_VSI_PVLAN_MODE_ALL
;
12270 if (pf
->vf
[vsi
->vf_id
].spoofchk
) {
12271 ctxt
.info
.valid_sections
|=
12272 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID
);
12273 ctxt
.info
.sec_flags
|=
12274 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK
|
12275 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK
);
12277 /* Setup the VSI tx/rx queue map for TC0 only for now */
12278 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
12281 case I40E_VSI_IWARP
:
12282 /* send down message to iWARP */
12289 if (vsi
->type
!= I40E_VSI_MAIN
) {
12290 ret
= i40e_aq_add_vsi(hw
, &ctxt
, NULL
);
12292 dev_info(&vsi
->back
->pdev
->dev
,
12293 "add vsi failed, err %s aq_err %s\n",
12294 i40e_stat_str(&pf
->hw
, ret
),
12295 i40e_aq_str(&pf
->hw
,
12296 pf
->hw
.aq
.asq_last_status
));
12300 vsi
->info
= ctxt
.info
;
12301 vsi
->info
.valid_sections
= 0;
12302 vsi
->seid
= ctxt
.seid
;
12303 vsi
->id
= ctxt
.vsi_number
;
12306 vsi
->active_filters
= 0;
12307 clear_bit(__I40E_VSI_OVERFLOW_PROMISC
, vsi
->state
);
12308 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
12309 /* If macvlan filters already exist, force them to get loaded */
12310 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
12311 f
->state
= I40E_FILTER_NEW
;
12314 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
12317 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
12318 set_bit(__I40E_MACVLAN_SYNC_PENDING
, pf
->state
);
12321 /* Update VSI BW information */
12322 ret
= i40e_vsi_get_bw_info(vsi
);
12324 dev_info(&pf
->pdev
->dev
,
12325 "couldn't get vsi bw info, err %s aq_err %s\n",
12326 i40e_stat_str(&pf
->hw
, ret
),
12327 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
12328 /* VSI is already added so not tearing that up */
12337 * i40e_vsi_release - Delete a VSI and free its resources
12338 * @vsi: the VSI being removed
12340 * Returns 0 on success or < 0 on error
12342 int i40e_vsi_release(struct i40e_vsi
*vsi
)
12344 struct i40e_mac_filter
*f
;
12345 struct hlist_node
*h
;
12346 struct i40e_veb
*veb
= NULL
;
12347 struct i40e_pf
*pf
;
12353 /* release of a VEB-owner or last VSI is not allowed */
12354 if (vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
12355 dev_info(&pf
->pdev
->dev
, "VSI %d has existing VEB %d\n",
12356 vsi
->seid
, vsi
->uplink_seid
);
12359 if (vsi
== pf
->vsi
[pf
->lan_vsi
] &&
12360 !test_bit(__I40E_DOWN
, pf
->state
)) {
12361 dev_info(&pf
->pdev
->dev
, "Can't remove PF VSI\n");
12365 uplink_seid
= vsi
->uplink_seid
;
12366 if (vsi
->type
!= I40E_VSI_SRIOV
) {
12367 if (vsi
->netdev_registered
) {
12368 vsi
->netdev_registered
= false;
12370 /* results in a call to i40e_close() */
12371 unregister_netdev(vsi
->netdev
);
12374 i40e_vsi_close(vsi
);
12376 i40e_vsi_disable_irq(vsi
);
12379 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
12381 /* clear the sync flag on all filters */
12383 __dev_uc_unsync(vsi
->netdev
, NULL
);
12384 __dev_mc_unsync(vsi
->netdev
, NULL
);
12387 /* make sure any remaining filters are marked for deletion */
12388 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
)
12389 __i40e_del_filter(vsi
, f
);
12391 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
12393 i40e_sync_vsi_filters(vsi
);
12395 i40e_vsi_delete(vsi
);
12396 i40e_vsi_free_q_vectors(vsi
);
12398 free_netdev(vsi
->netdev
);
12399 vsi
->netdev
= NULL
;
12401 i40e_vsi_clear_rings(vsi
);
12402 i40e_vsi_clear(vsi
);
12404 /* If this was the last thing on the VEB, except for the
12405 * controlling VSI, remove the VEB, which puts the controlling
12406 * VSI onto the next level down in the switch.
12408 * Well, okay, there's one more exception here: don't remove
12409 * the orphan VEBs yet. We'll wait for an explicit remove request
12410 * from up the network stack.
12412 for (n
= 0, i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
12414 pf
->vsi
[i
]->uplink_seid
== uplink_seid
&&
12415 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
12416 n
++; /* count the VSIs */
12419 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
12422 if (pf
->veb
[i
]->uplink_seid
== uplink_seid
)
12423 n
++; /* count the VEBs */
12424 if (pf
->veb
[i
]->seid
== uplink_seid
)
12427 if (n
== 0 && veb
&& veb
->uplink_seid
!= 0)
12428 i40e_veb_release(veb
);
12434 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
12435 * @vsi: ptr to the VSI
12437 * This should only be called after i40e_vsi_mem_alloc() which allocates the
12438 * corresponding SW VSI structure and initializes num_queue_pairs for the
12439 * newly allocated VSI.
12441 * Returns 0 on success or negative on failure
12443 static int i40e_vsi_setup_vectors(struct i40e_vsi
*vsi
)
12446 struct i40e_pf
*pf
= vsi
->back
;
12448 if (vsi
->q_vectors
[0]) {
12449 dev_info(&pf
->pdev
->dev
, "VSI %d has existing q_vectors\n",
12454 if (vsi
->base_vector
) {
12455 dev_info(&pf
->pdev
->dev
, "VSI %d has non-zero base vector %d\n",
12456 vsi
->seid
, vsi
->base_vector
);
12460 ret
= i40e_vsi_alloc_q_vectors(vsi
);
12462 dev_info(&pf
->pdev
->dev
,
12463 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
12464 vsi
->num_q_vectors
, vsi
->seid
, ret
);
12465 vsi
->num_q_vectors
= 0;
12466 goto vector_setup_out
;
12469 /* In Legacy mode, we do not have to get any other vector since we
12470 * piggyback on the misc/ICR0 for queue interrupts.
12472 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
12474 if (vsi
->num_q_vectors
)
12475 vsi
->base_vector
= i40e_get_lump(pf
, pf
->irq_pile
,
12476 vsi
->num_q_vectors
, vsi
->idx
);
12477 if (vsi
->base_vector
< 0) {
12478 dev_info(&pf
->pdev
->dev
,
12479 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
12480 vsi
->num_q_vectors
, vsi
->seid
, vsi
->base_vector
);
12481 i40e_vsi_free_q_vectors(vsi
);
12483 goto vector_setup_out
;
12491 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
12492 * @vsi: pointer to the vsi.
12494 * This re-allocates a vsi's queue resources.
12496 * Returns pointer to the successfully allocated and configured VSI sw struct
12497 * on success, otherwise returns NULL on failure.
12499 static struct i40e_vsi
*i40e_vsi_reinit_setup(struct i40e_vsi
*vsi
)
12501 u16 alloc_queue_pairs
;
12502 struct i40e_pf
*pf
;
12511 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
12512 i40e_vsi_clear_rings(vsi
);
12514 i40e_vsi_free_arrays(vsi
, false);
12515 i40e_set_num_rings_in_vsi(vsi
);
12516 ret
= i40e_vsi_alloc_arrays(vsi
, false);
12520 alloc_queue_pairs
= vsi
->alloc_queue_pairs
*
12521 (i40e_enabled_xdp_vsi(vsi
) ? 2 : 1);
12523 ret
= i40e_get_lump(pf
, pf
->qp_pile
, alloc_queue_pairs
, vsi
->idx
);
12525 dev_info(&pf
->pdev
->dev
,
12526 "failed to get tracking for %d queues for VSI %d err %d\n",
12527 alloc_queue_pairs
, vsi
->seid
, ret
);
12530 vsi
->base_queue
= ret
;
12532 /* Update the FW view of the VSI. Force a reset of TC and queue
12533 * layout configurations.
12535 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
12536 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
12537 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
12538 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
12539 if (vsi
->type
== I40E_VSI_MAIN
)
12540 i40e_rm_default_mac_filter(vsi
, pf
->hw
.mac
.perm_addr
);
12542 /* assign it some queues */
12543 ret
= i40e_alloc_rings(vsi
);
12547 /* map all of the rings to the q_vectors */
12548 i40e_vsi_map_rings_to_vectors(vsi
);
12552 i40e_vsi_free_q_vectors(vsi
);
12553 if (vsi
->netdev_registered
) {
12554 vsi
->netdev_registered
= false;
12555 unregister_netdev(vsi
->netdev
);
12556 free_netdev(vsi
->netdev
);
12557 vsi
->netdev
= NULL
;
12559 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
12561 i40e_vsi_clear(vsi
);
12566 * i40e_vsi_setup - Set up a VSI by a given type
12567 * @pf: board private structure
12569 * @uplink_seid: the switch element to link to
12570 * @param1: usage depends upon VSI type. For VF types, indicates VF id
12572 * This allocates the sw VSI structure and its queue resources, then add a VSI
12573 * to the identified VEB.
12575 * Returns pointer to the successfully allocated and configure VSI sw struct on
12576 * success, otherwise returns NULL on failure.
12578 struct i40e_vsi
*i40e_vsi_setup(struct i40e_pf
*pf
, u8 type
,
12579 u16 uplink_seid
, u32 param1
)
12581 struct i40e_vsi
*vsi
= NULL
;
12582 struct i40e_veb
*veb
= NULL
;
12583 u16 alloc_queue_pairs
;
12587 /* The requested uplink_seid must be either
12588 * - the PF's port seid
12589 * no VEB is needed because this is the PF
12590 * or this is a Flow Director special case VSI
12591 * - seid of an existing VEB
12592 * - seid of a VSI that owns an existing VEB
12593 * - seid of a VSI that doesn't own a VEB
12594 * a new VEB is created and the VSI becomes the owner
12595 * - seid of the PF VSI, which is what creates the first VEB
12596 * this is a special case of the previous
12598 * Find which uplink_seid we were given and create a new VEB if needed
12600 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
12601 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== uplink_seid
) {
12607 if (!veb
&& uplink_seid
!= pf
->mac_seid
) {
12609 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
12610 if (pf
->vsi
[i
] && pf
->vsi
[i
]->seid
== uplink_seid
) {
12616 dev_info(&pf
->pdev
->dev
, "no such uplink_seid %d\n",
12621 if (vsi
->uplink_seid
== pf
->mac_seid
)
12622 veb
= i40e_veb_setup(pf
, 0, pf
->mac_seid
, vsi
->seid
,
12623 vsi
->tc_config
.enabled_tc
);
12624 else if ((vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0)
12625 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
12626 vsi
->tc_config
.enabled_tc
);
12628 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
) {
12629 dev_info(&vsi
->back
->pdev
->dev
,
12630 "New VSI creation error, uplink seid of LAN VSI expected.\n");
12633 /* We come up by default in VEPA mode if SRIOV is not
12634 * already enabled, in which case we can't force VEPA
12637 if (!(pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)) {
12638 veb
->bridge_mode
= BRIDGE_MODE_VEPA
;
12639 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
12641 i40e_config_bridge_mode(veb
);
12643 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
12644 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
12648 dev_info(&pf
->pdev
->dev
, "couldn't add VEB\n");
12652 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
12653 uplink_seid
= veb
->seid
;
12656 /* get vsi sw struct */
12657 v_idx
= i40e_vsi_mem_alloc(pf
, type
);
12660 vsi
= pf
->vsi
[v_idx
];
12664 vsi
->veb_idx
= (veb
? veb
->idx
: I40E_NO_VEB
);
12666 if (type
== I40E_VSI_MAIN
)
12667 pf
->lan_vsi
= v_idx
;
12668 else if (type
== I40E_VSI_SRIOV
)
12669 vsi
->vf_id
= param1
;
12670 /* assign it some queues */
12671 alloc_queue_pairs
= vsi
->alloc_queue_pairs
*
12672 (i40e_enabled_xdp_vsi(vsi
) ? 2 : 1);
12674 ret
= i40e_get_lump(pf
, pf
->qp_pile
, alloc_queue_pairs
, vsi
->idx
);
12676 dev_info(&pf
->pdev
->dev
,
12677 "failed to get tracking for %d queues for VSI %d err=%d\n",
12678 alloc_queue_pairs
, vsi
->seid
, ret
);
12681 vsi
->base_queue
= ret
;
12683 /* get a VSI from the hardware */
12684 vsi
->uplink_seid
= uplink_seid
;
12685 ret
= i40e_add_vsi(vsi
);
12689 switch (vsi
->type
) {
12690 /* setup the netdev if needed */
12691 case I40E_VSI_MAIN
:
12692 case I40E_VSI_VMDQ2
:
12693 ret
= i40e_config_netdev(vsi
);
12696 ret
= register_netdev(vsi
->netdev
);
12699 vsi
->netdev_registered
= true;
12700 netif_carrier_off(vsi
->netdev
);
12701 #ifdef CONFIG_I40E_DCB
12702 /* Setup DCB netlink interface */
12703 i40e_dcbnl_setup(vsi
);
12704 #endif /* CONFIG_I40E_DCB */
12707 case I40E_VSI_FDIR
:
12708 /* set up vectors and rings if needed */
12709 ret
= i40e_vsi_setup_vectors(vsi
);
12713 ret
= i40e_alloc_rings(vsi
);
12717 /* map all of the rings to the q_vectors */
12718 i40e_vsi_map_rings_to_vectors(vsi
);
12720 i40e_vsi_reset_stats(vsi
);
12724 /* no netdev or rings for the other VSI types */
12728 if ((pf
->hw_features
& I40E_HW_RSS_AQ_CAPABLE
) &&
12729 (vsi
->type
== I40E_VSI_VMDQ2
)) {
12730 ret
= i40e_vsi_config_rss(vsi
);
12735 i40e_vsi_free_q_vectors(vsi
);
12737 if (vsi
->netdev_registered
) {
12738 vsi
->netdev_registered
= false;
12739 unregister_netdev(vsi
->netdev
);
12740 free_netdev(vsi
->netdev
);
12741 vsi
->netdev
= NULL
;
12744 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
12746 i40e_vsi_clear(vsi
);
12752 * i40e_veb_get_bw_info - Query VEB BW information
12753 * @veb: the veb to query
12755 * Query the Tx scheduler BW configuration data for given VEB
12757 static int i40e_veb_get_bw_info(struct i40e_veb
*veb
)
12759 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data
;
12760 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data
;
12761 struct i40e_pf
*pf
= veb
->pf
;
12762 struct i40e_hw
*hw
= &pf
->hw
;
12767 ret
= i40e_aq_query_switch_comp_bw_config(hw
, veb
->seid
,
12770 dev_info(&pf
->pdev
->dev
,
12771 "query veb bw config failed, err %s aq_err %s\n",
12772 i40e_stat_str(&pf
->hw
, ret
),
12773 i40e_aq_str(&pf
->hw
, hw
->aq
.asq_last_status
));
12777 ret
= i40e_aq_query_switch_comp_ets_config(hw
, veb
->seid
,
12780 dev_info(&pf
->pdev
->dev
,
12781 "query veb bw ets config failed, err %s aq_err %s\n",
12782 i40e_stat_str(&pf
->hw
, ret
),
12783 i40e_aq_str(&pf
->hw
, hw
->aq
.asq_last_status
));
12787 veb
->bw_limit
= le16_to_cpu(ets_data
.port_bw_limit
);
12788 veb
->bw_max_quanta
= ets_data
.tc_bw_max
;
12789 veb
->is_abs_credits
= bw_data
.absolute_credits_enable
;
12790 veb
->enabled_tc
= ets_data
.tc_valid_bits
;
12791 tc_bw_max
= le16_to_cpu(bw_data
.tc_bw_max
[0]) |
12792 (le16_to_cpu(bw_data
.tc_bw_max
[1]) << 16);
12793 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
12794 veb
->bw_tc_share_credits
[i
] = bw_data
.tc_bw_share_credits
[i
];
12795 veb
->bw_tc_limit_credits
[i
] =
12796 le16_to_cpu(bw_data
.tc_bw_limits
[i
]);
12797 veb
->bw_tc_max_quanta
[i
] = ((tc_bw_max
>> (i
*4)) & 0x7);
12805 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
12806 * @pf: board private structure
12808 * On error: returns error code (negative)
12809 * On success: returns vsi index in PF (positive)
12811 static int i40e_veb_mem_alloc(struct i40e_pf
*pf
)
12814 struct i40e_veb
*veb
;
12817 /* Need to protect the allocation of switch elements at the PF level */
12818 mutex_lock(&pf
->switch_mutex
);
12820 /* VEB list may be fragmented if VEB creation/destruction has
12821 * been happening. We can afford to do a quick scan to look
12822 * for any free slots in the list.
12824 * find next empty veb slot, looping back around if necessary
12827 while ((i
< I40E_MAX_VEB
) && (pf
->veb
[i
] != NULL
))
12829 if (i
>= I40E_MAX_VEB
) {
12831 goto err_alloc_veb
; /* out of VEB slots! */
12834 veb
= kzalloc(sizeof(*veb
), GFP_KERNEL
);
12837 goto err_alloc_veb
;
12841 veb
->enabled_tc
= 1;
12846 mutex_unlock(&pf
->switch_mutex
);
12851 * i40e_switch_branch_release - Delete a branch of the switch tree
12852 * @branch: where to start deleting
12854 * This uses recursion to find the tips of the branch to be
12855 * removed, deleting until we get back to and can delete this VEB.
12857 static void i40e_switch_branch_release(struct i40e_veb
*branch
)
12859 struct i40e_pf
*pf
= branch
->pf
;
12860 u16 branch_seid
= branch
->seid
;
12861 u16 veb_idx
= branch
->idx
;
12864 /* release any VEBs on this VEB - RECURSION */
12865 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
12868 if (pf
->veb
[i
]->uplink_seid
== branch
->seid
)
12869 i40e_switch_branch_release(pf
->veb
[i
]);
12872 /* Release the VSIs on this VEB, but not the owner VSI.
12874 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
12875 * the VEB itself, so don't use (*branch) after this loop.
12877 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
12880 if (pf
->vsi
[i
]->uplink_seid
== branch_seid
&&
12881 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
12882 i40e_vsi_release(pf
->vsi
[i
]);
12886 /* There's one corner case where the VEB might not have been
12887 * removed, so double check it here and remove it if needed.
12888 * This case happens if the veb was created from the debugfs
12889 * commands and no VSIs were added to it.
12891 if (pf
->veb
[veb_idx
])
12892 i40e_veb_release(pf
->veb
[veb_idx
]);
12896 * i40e_veb_clear - remove veb struct
12897 * @veb: the veb to remove
12899 static void i40e_veb_clear(struct i40e_veb
*veb
)
12905 struct i40e_pf
*pf
= veb
->pf
;
12907 mutex_lock(&pf
->switch_mutex
);
12908 if (pf
->veb
[veb
->idx
] == veb
)
12909 pf
->veb
[veb
->idx
] = NULL
;
12910 mutex_unlock(&pf
->switch_mutex
);
12917 * i40e_veb_release - Delete a VEB and free its resources
12918 * @veb: the VEB being removed
12920 void i40e_veb_release(struct i40e_veb
*veb
)
12922 struct i40e_vsi
*vsi
= NULL
;
12923 struct i40e_pf
*pf
;
12928 /* find the remaining VSI and check for extras */
12929 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
12930 if (pf
->vsi
[i
] && pf
->vsi
[i
]->uplink_seid
== veb
->seid
) {
12936 dev_info(&pf
->pdev
->dev
,
12937 "can't remove VEB %d with %d VSIs left\n",
12942 /* move the remaining VSI to uplink veb */
12943 vsi
->flags
&= ~I40E_VSI_FLAG_VEB_OWNER
;
12944 if (veb
->uplink_seid
) {
12945 vsi
->uplink_seid
= veb
->uplink_seid
;
12946 if (veb
->uplink_seid
== pf
->mac_seid
)
12947 vsi
->veb_idx
= I40E_NO_VEB
;
12949 vsi
->veb_idx
= veb
->veb_idx
;
12952 vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
12953 vsi
->veb_idx
= pf
->vsi
[pf
->lan_vsi
]->veb_idx
;
12956 i40e_aq_delete_element(&pf
->hw
, veb
->seid
, NULL
);
12957 i40e_veb_clear(veb
);
12961 * i40e_add_veb - create the VEB in the switch
12962 * @veb: the VEB to be instantiated
12963 * @vsi: the controlling VSI
12965 static int i40e_add_veb(struct i40e_veb
*veb
, struct i40e_vsi
*vsi
)
12967 struct i40e_pf
*pf
= veb
->pf
;
12968 bool enable_stats
= !!(pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
);
12971 ret
= i40e_aq_add_veb(&pf
->hw
, veb
->uplink_seid
, vsi
->seid
,
12972 veb
->enabled_tc
, false,
12973 &veb
->seid
, enable_stats
, NULL
);
12975 /* get a VEB from the hardware */
12977 dev_info(&pf
->pdev
->dev
,
12978 "couldn't add VEB, err %s aq_err %s\n",
12979 i40e_stat_str(&pf
->hw
, ret
),
12980 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
12984 /* get statistics counter */
12985 ret
= i40e_aq_get_veb_parameters(&pf
->hw
, veb
->seid
, NULL
, NULL
,
12986 &veb
->stats_idx
, NULL
, NULL
, NULL
);
12988 dev_info(&pf
->pdev
->dev
,
12989 "couldn't get VEB statistics idx, err %s aq_err %s\n",
12990 i40e_stat_str(&pf
->hw
, ret
),
12991 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
12994 ret
= i40e_veb_get_bw_info(veb
);
12996 dev_info(&pf
->pdev
->dev
,
12997 "couldn't get VEB bw info, err %s aq_err %s\n",
12998 i40e_stat_str(&pf
->hw
, ret
),
12999 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
13000 i40e_aq_delete_element(&pf
->hw
, veb
->seid
, NULL
);
13004 vsi
->uplink_seid
= veb
->seid
;
13005 vsi
->veb_idx
= veb
->idx
;
13006 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
13012 * i40e_veb_setup - Set up a VEB
13013 * @pf: board private structure
13014 * @flags: VEB setup flags
13015 * @uplink_seid: the switch element to link to
13016 * @vsi_seid: the initial VSI seid
13017 * @enabled_tc: Enabled TC bit-map
13019 * This allocates the sw VEB structure and links it into the switch
13020 * It is possible and legal for this to be a duplicate of an already
13021 * existing VEB. It is also possible for both uplink and vsi seids
13022 * to be zero, in order to create a floating VEB.
13024 * Returns pointer to the successfully allocated VEB sw struct on
13025 * success, otherwise returns NULL on failure.
13027 struct i40e_veb
*i40e_veb_setup(struct i40e_pf
*pf
, u16 flags
,
13028 u16 uplink_seid
, u16 vsi_seid
,
13031 struct i40e_veb
*veb
, *uplink_veb
= NULL
;
13032 int vsi_idx
, veb_idx
;
13035 /* if one seid is 0, the other must be 0 to create a floating relay */
13036 if ((uplink_seid
== 0 || vsi_seid
== 0) &&
13037 (uplink_seid
+ vsi_seid
!= 0)) {
13038 dev_info(&pf
->pdev
->dev
,
13039 "one, not both seid's are 0: uplink=%d vsi=%d\n",
13040 uplink_seid
, vsi_seid
);
13044 /* make sure there is such a vsi and uplink */
13045 for (vsi_idx
= 0; vsi_idx
< pf
->num_alloc_vsi
; vsi_idx
++)
13046 if (pf
->vsi
[vsi_idx
] && pf
->vsi
[vsi_idx
]->seid
== vsi_seid
)
13048 if (vsi_idx
>= pf
->num_alloc_vsi
&& vsi_seid
!= 0) {
13049 dev_info(&pf
->pdev
->dev
, "vsi seid %d not found\n",
13054 if (uplink_seid
&& uplink_seid
!= pf
->mac_seid
) {
13055 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
13056 if (pf
->veb
[veb_idx
] &&
13057 pf
->veb
[veb_idx
]->seid
== uplink_seid
) {
13058 uplink_veb
= pf
->veb
[veb_idx
];
13063 dev_info(&pf
->pdev
->dev
,
13064 "uplink seid %d not found\n", uplink_seid
);
13069 /* get veb sw struct */
13070 veb_idx
= i40e_veb_mem_alloc(pf
);
13073 veb
= pf
->veb
[veb_idx
];
13074 veb
->flags
= flags
;
13075 veb
->uplink_seid
= uplink_seid
;
13076 veb
->veb_idx
= (uplink_veb
? uplink_veb
->idx
: I40E_NO_VEB
);
13077 veb
->enabled_tc
= (enabled_tc
? enabled_tc
: 0x1);
13079 /* create the VEB in the switch */
13080 ret
= i40e_add_veb(veb
, pf
->vsi
[vsi_idx
]);
13083 if (vsi_idx
== pf
->lan_vsi
)
13084 pf
->lan_veb
= veb
->idx
;
13089 i40e_veb_clear(veb
);
13095 * i40e_setup_pf_switch_element - set PF vars based on switch type
13096 * @pf: board private structure
13097 * @ele: element we are building info from
13098 * @num_reported: total number of elements
13099 * @printconfig: should we print the contents
13101 * helper function to assist in extracting a few useful SEID values.
13103 static void i40e_setup_pf_switch_element(struct i40e_pf
*pf
,
13104 struct i40e_aqc_switch_config_element_resp
*ele
,
13105 u16 num_reported
, bool printconfig
)
13107 u16 downlink_seid
= le16_to_cpu(ele
->downlink_seid
);
13108 u16 uplink_seid
= le16_to_cpu(ele
->uplink_seid
);
13109 u8 element_type
= ele
->element_type
;
13110 u16 seid
= le16_to_cpu(ele
->seid
);
13113 dev_info(&pf
->pdev
->dev
,
13114 "type=%d seid=%d uplink=%d downlink=%d\n",
13115 element_type
, seid
, uplink_seid
, downlink_seid
);
13117 switch (element_type
) {
13118 case I40E_SWITCH_ELEMENT_TYPE_MAC
:
13119 pf
->mac_seid
= seid
;
13121 case I40E_SWITCH_ELEMENT_TYPE_VEB
:
13123 if (uplink_seid
!= pf
->mac_seid
)
13125 if (pf
->lan_veb
== I40E_NO_VEB
) {
13128 /* find existing or else empty VEB */
13129 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
13130 if (pf
->veb
[v
] && (pf
->veb
[v
]->seid
== seid
)) {
13135 if (pf
->lan_veb
== I40E_NO_VEB
) {
13136 v
= i40e_veb_mem_alloc(pf
);
13143 pf
->veb
[pf
->lan_veb
]->seid
= seid
;
13144 pf
->veb
[pf
->lan_veb
]->uplink_seid
= pf
->mac_seid
;
13145 pf
->veb
[pf
->lan_veb
]->pf
= pf
;
13146 pf
->veb
[pf
->lan_veb
]->veb_idx
= I40E_NO_VEB
;
13148 case I40E_SWITCH_ELEMENT_TYPE_VSI
:
13149 if (num_reported
!= 1)
13151 /* This is immediately after a reset so we can assume this is
13154 pf
->mac_seid
= uplink_seid
;
13155 pf
->pf_seid
= downlink_seid
;
13156 pf
->main_vsi_seid
= seid
;
13158 dev_info(&pf
->pdev
->dev
,
13159 "pf_seid=%d main_vsi_seid=%d\n",
13160 pf
->pf_seid
, pf
->main_vsi_seid
);
13162 case I40E_SWITCH_ELEMENT_TYPE_PF
:
13163 case I40E_SWITCH_ELEMENT_TYPE_VF
:
13164 case I40E_SWITCH_ELEMENT_TYPE_EMP
:
13165 case I40E_SWITCH_ELEMENT_TYPE_BMC
:
13166 case I40E_SWITCH_ELEMENT_TYPE_PE
:
13167 case I40E_SWITCH_ELEMENT_TYPE_PA
:
13168 /* ignore these for now */
13171 dev_info(&pf
->pdev
->dev
, "unknown element type=%d seid=%d\n",
13172 element_type
, seid
);
13178 * i40e_fetch_switch_configuration - Get switch config from firmware
13179 * @pf: board private structure
13180 * @printconfig: should we print the contents
13182 * Get the current switch configuration from the device and
13183 * extract a few useful SEID values.
13185 int i40e_fetch_switch_configuration(struct i40e_pf
*pf
, bool printconfig
)
13187 struct i40e_aqc_get_switch_config_resp
*sw_config
;
13193 aq_buf
= kzalloc(I40E_AQ_LARGE_BUF
, GFP_KERNEL
);
13197 sw_config
= (struct i40e_aqc_get_switch_config_resp
*)aq_buf
;
13199 u16 num_reported
, num_total
;
13201 ret
= i40e_aq_get_switch_config(&pf
->hw
, sw_config
,
13205 dev_info(&pf
->pdev
->dev
,
13206 "get switch config failed err %s aq_err %s\n",
13207 i40e_stat_str(&pf
->hw
, ret
),
13208 i40e_aq_str(&pf
->hw
,
13209 pf
->hw
.aq
.asq_last_status
));
13214 num_reported
= le16_to_cpu(sw_config
->header
.num_reported
);
13215 num_total
= le16_to_cpu(sw_config
->header
.num_total
);
13218 dev_info(&pf
->pdev
->dev
,
13219 "header: %d reported %d total\n",
13220 num_reported
, num_total
);
13222 for (i
= 0; i
< num_reported
; i
++) {
13223 struct i40e_aqc_switch_config_element_resp
*ele
=
13224 &sw_config
->element
[i
];
13226 i40e_setup_pf_switch_element(pf
, ele
, num_reported
,
13229 } while (next_seid
!= 0);
13236 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
13237 * @pf: board private structure
13238 * @reinit: if the Main VSI needs to re-initialized.
13240 * Returns 0 on success, negative value on failure
13242 static int i40e_setup_pf_switch(struct i40e_pf
*pf
, bool reinit
)
13247 /* find out what's out there already */
13248 ret
= i40e_fetch_switch_configuration(pf
, false);
13250 dev_info(&pf
->pdev
->dev
,
13251 "couldn't fetch switch config, err %s aq_err %s\n",
13252 i40e_stat_str(&pf
->hw
, ret
),
13253 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
13256 i40e_pf_reset_stats(pf
);
13258 /* set the switch config bit for the whole device to
13259 * support limited promisc or true promisc
13260 * when user requests promisc. The default is limited
13264 if ((pf
->hw
.pf_id
== 0) &&
13265 !(pf
->flags
& I40E_FLAG_TRUE_PROMISC_SUPPORT
)) {
13266 flags
= I40E_AQ_SET_SWITCH_CFG_PROMISC
;
13267 pf
->last_sw_conf_flags
= flags
;
13270 if (pf
->hw
.pf_id
== 0) {
13273 valid_flags
= I40E_AQ_SET_SWITCH_CFG_PROMISC
;
13274 ret
= i40e_aq_set_switch_config(&pf
->hw
, flags
, valid_flags
, 0,
13276 if (ret
&& pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_ESRCH
) {
13277 dev_info(&pf
->pdev
->dev
,
13278 "couldn't set switch config bits, err %s aq_err %s\n",
13279 i40e_stat_str(&pf
->hw
, ret
),
13280 i40e_aq_str(&pf
->hw
,
13281 pf
->hw
.aq
.asq_last_status
));
13282 /* not a fatal problem, just keep going */
13284 pf
->last_sw_conf_valid_flags
= valid_flags
;
13287 /* first time setup */
13288 if (pf
->lan_vsi
== I40E_NO_VSI
|| reinit
) {
13289 struct i40e_vsi
*vsi
= NULL
;
13292 /* Set up the PF VSI associated with the PF's main VSI
13293 * that is already in the HW switch
13295 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
13296 uplink_seid
= pf
->veb
[pf
->lan_veb
]->seid
;
13298 uplink_seid
= pf
->mac_seid
;
13299 if (pf
->lan_vsi
== I40E_NO_VSI
)
13300 vsi
= i40e_vsi_setup(pf
, I40E_VSI_MAIN
, uplink_seid
, 0);
13302 vsi
= i40e_vsi_reinit_setup(pf
->vsi
[pf
->lan_vsi
]);
13304 dev_info(&pf
->pdev
->dev
, "setup of MAIN VSI failed\n");
13305 i40e_cloud_filter_exit(pf
);
13306 i40e_fdir_teardown(pf
);
13310 /* force a reset of TC and queue layout configurations */
13311 u8 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
13313 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
13314 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
13315 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
13317 i40e_vlan_stripping_disable(pf
->vsi
[pf
->lan_vsi
]);
13319 i40e_fdir_sb_setup(pf
);
13321 /* Setup static PF queue filter control settings */
13322 ret
= i40e_setup_pf_filter_control(pf
);
13324 dev_info(&pf
->pdev
->dev
, "setup_pf_filter_control failed: %d\n",
13326 /* Failure here should not stop continuing other steps */
13329 /* enable RSS in the HW, even for only one queue, as the stack can use
13332 if ((pf
->flags
& I40E_FLAG_RSS_ENABLED
))
13333 i40e_pf_config_rss(pf
);
13335 /* fill in link information and enable LSE reporting */
13336 i40e_link_event(pf
);
13338 /* Initialize user-specific link properties */
13339 pf
->fc_autoneg_status
= ((pf
->hw
.phy
.link_info
.an_info
&
13340 I40E_AQ_AN_COMPLETED
) ? true : false);
13344 /* repopulate tunnel port filters */
13345 i40e_sync_udp_filters(pf
);
13351 * i40e_determine_queue_usage - Work out queue distribution
13352 * @pf: board private structure
13354 static void i40e_determine_queue_usage(struct i40e_pf
*pf
)
13359 pf
->num_lan_qps
= 0;
13361 /* Find the max queues to be put into basic use. We'll always be
13362 * using TC0, whether or not DCB is running, and TC0 will get the
13365 queues_left
= pf
->hw
.func_caps
.num_tx_qp
;
13367 if ((queues_left
== 1) ||
13368 !(pf
->flags
& I40E_FLAG_MSIX_ENABLED
)) {
13369 /* one qp for PF, no queues for anything else */
13371 pf
->alloc_rss_size
= pf
->num_lan_qps
= 1;
13373 /* make sure all the fancies are disabled */
13374 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
13375 I40E_FLAG_IWARP_ENABLED
|
13376 I40E_FLAG_FD_SB_ENABLED
|
13377 I40E_FLAG_FD_ATR_ENABLED
|
13378 I40E_FLAG_DCB_CAPABLE
|
13379 I40E_FLAG_DCB_ENABLED
|
13380 I40E_FLAG_SRIOV_ENABLED
|
13381 I40E_FLAG_VMDQ_ENABLED
);
13382 pf
->flags
|= I40E_FLAG_FD_SB_INACTIVE
;
13383 } else if (!(pf
->flags
& (I40E_FLAG_RSS_ENABLED
|
13384 I40E_FLAG_FD_SB_ENABLED
|
13385 I40E_FLAG_FD_ATR_ENABLED
|
13386 I40E_FLAG_DCB_CAPABLE
))) {
13387 /* one qp for PF */
13388 pf
->alloc_rss_size
= pf
->num_lan_qps
= 1;
13389 queues_left
-= pf
->num_lan_qps
;
13391 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
13392 I40E_FLAG_IWARP_ENABLED
|
13393 I40E_FLAG_FD_SB_ENABLED
|
13394 I40E_FLAG_FD_ATR_ENABLED
|
13395 I40E_FLAG_DCB_ENABLED
|
13396 I40E_FLAG_VMDQ_ENABLED
);
13397 pf
->flags
|= I40E_FLAG_FD_SB_INACTIVE
;
13399 /* Not enough queues for all TCs */
13400 if ((pf
->flags
& I40E_FLAG_DCB_CAPABLE
) &&
13401 (queues_left
< I40E_MAX_TRAFFIC_CLASS
)) {
13402 pf
->flags
&= ~(I40E_FLAG_DCB_CAPABLE
|
13403 I40E_FLAG_DCB_ENABLED
);
13404 dev_info(&pf
->pdev
->dev
, "not enough queues for DCB. DCB is disabled.\n");
13407 /* limit lan qps to the smaller of qps, cpus or msix */
13408 q_max
= max_t(int, pf
->rss_size_max
, num_online_cpus());
13409 q_max
= min_t(int, q_max
, pf
->hw
.func_caps
.num_tx_qp
);
13410 q_max
= min_t(int, q_max
, pf
->hw
.func_caps
.num_msix_vectors
);
13411 pf
->num_lan_qps
= q_max
;
13413 queues_left
-= pf
->num_lan_qps
;
13416 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
13417 if (queues_left
> 1) {
13418 queues_left
-= 1; /* save 1 queue for FD */
13420 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
13421 pf
->flags
|= I40E_FLAG_FD_SB_INACTIVE
;
13422 dev_info(&pf
->pdev
->dev
, "not enough queues for Flow Director. Flow Director feature is disabled\n");
13426 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
13427 pf
->num_vf_qps
&& pf
->num_req_vfs
&& queues_left
) {
13428 pf
->num_req_vfs
= min_t(int, pf
->num_req_vfs
,
13429 (queues_left
/ pf
->num_vf_qps
));
13430 queues_left
-= (pf
->num_req_vfs
* pf
->num_vf_qps
);
13433 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
13434 pf
->num_vmdq_vsis
&& pf
->num_vmdq_qps
&& queues_left
) {
13435 pf
->num_vmdq_vsis
= min_t(int, pf
->num_vmdq_vsis
,
13436 (queues_left
/ pf
->num_vmdq_qps
));
13437 queues_left
-= (pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
);
13440 pf
->queues_left
= queues_left
;
13441 dev_dbg(&pf
->pdev
->dev
,
13442 "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
13443 pf
->hw
.func_caps
.num_tx_qp
,
13444 !!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
),
13445 pf
->num_lan_qps
, pf
->alloc_rss_size
, pf
->num_req_vfs
,
13446 pf
->num_vf_qps
, pf
->num_vmdq_vsis
, pf
->num_vmdq_qps
,
13451 * i40e_setup_pf_filter_control - Setup PF static filter control
13452 * @pf: PF to be setup
13454 * i40e_setup_pf_filter_control sets up a PF's initial filter control
13455 * settings. If PE/FCoE are enabled then it will also set the per PF
13456 * based filter sizes required for them. It also enables Flow director,
13457 * ethertype and macvlan type filter settings for the pf.
13459 * Returns 0 on success, negative on failure
13461 static int i40e_setup_pf_filter_control(struct i40e_pf
*pf
)
13463 struct i40e_filter_control_settings
*settings
= &pf
->filter_settings
;
13465 settings
->hash_lut_size
= I40E_HASH_LUT_SIZE_128
;
13467 /* Flow Director is enabled */
13468 if (pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
))
13469 settings
->enable_fdir
= true;
13471 /* Ethtype and MACVLAN filters enabled for PF */
13472 settings
->enable_ethtype
= true;
13473 settings
->enable_macvlan
= true;
13475 if (i40e_set_filter_control(&pf
->hw
, settings
))
13481 #define INFO_STRING_LEN 255
13482 #define REMAIN(__x) (INFO_STRING_LEN - (__x))
13483 static void i40e_print_features(struct i40e_pf
*pf
)
13485 struct i40e_hw
*hw
= &pf
->hw
;
13489 buf
= kmalloc(INFO_STRING_LEN
, GFP_KERNEL
);
13493 i
= snprintf(buf
, INFO_STRING_LEN
, "Features: PF-id[%d]", hw
->pf_id
);
13494 #ifdef CONFIG_PCI_IOV
13495 i
+= snprintf(&buf
[i
], REMAIN(i
), " VFs: %d", pf
->num_req_vfs
);
13497 i
+= snprintf(&buf
[i
], REMAIN(i
), " VSIs: %d QP: %d",
13498 pf
->hw
.func_caps
.num_vsis
,
13499 pf
->vsi
[pf
->lan_vsi
]->num_queue_pairs
);
13500 if (pf
->flags
& I40E_FLAG_RSS_ENABLED
)
13501 i
+= snprintf(&buf
[i
], REMAIN(i
), " RSS");
13502 if (pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
)
13503 i
+= snprintf(&buf
[i
], REMAIN(i
), " FD_ATR");
13504 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
13505 i
+= snprintf(&buf
[i
], REMAIN(i
), " FD_SB");
13506 i
+= snprintf(&buf
[i
], REMAIN(i
), " NTUPLE");
13508 if (pf
->flags
& I40E_FLAG_DCB_CAPABLE
)
13509 i
+= snprintf(&buf
[i
], REMAIN(i
), " DCB");
13510 i
+= snprintf(&buf
[i
], REMAIN(i
), " VxLAN");
13511 i
+= snprintf(&buf
[i
], REMAIN(i
), " Geneve");
13512 if (pf
->flags
& I40E_FLAG_PTP
)
13513 i
+= snprintf(&buf
[i
], REMAIN(i
), " PTP");
13514 if (pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)
13515 i
+= snprintf(&buf
[i
], REMAIN(i
), " VEB");
13517 i
+= snprintf(&buf
[i
], REMAIN(i
), " VEPA");
13519 dev_info(&pf
->pdev
->dev
, "%s\n", buf
);
13521 WARN_ON(i
> INFO_STRING_LEN
);
13525 * i40e_get_platform_mac_addr - get platform-specific MAC address
13526 * @pdev: PCI device information struct
13527 * @pf: board private structure
13529 * Look up the MAC address for the device. First we'll try
13530 * eth_platform_get_mac_address, which will check Open Firmware, or arch
13531 * specific fallback. Otherwise, we'll default to the stored value in
13534 static void i40e_get_platform_mac_addr(struct pci_dev
*pdev
, struct i40e_pf
*pf
)
13536 if (eth_platform_get_mac_address(&pdev
->dev
, pf
->hw
.mac
.addr
))
13537 i40e_get_mac_addr(&pf
->hw
, pf
->hw
.mac
.addr
);
13541 * i40e_probe - Device initialization routine
13542 * @pdev: PCI device information struct
13543 * @ent: entry in i40e_pci_tbl
13545 * i40e_probe initializes a PF identified by a pci_dev structure.
13546 * The OS initialization, configuring of the PF private structure,
13547 * and a hardware reset occur.
13549 * Returns 0 on success, negative on failure
13551 static int i40e_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
13553 struct i40e_aq_get_phy_abilities_resp abilities
;
13554 struct i40e_pf
*pf
;
13555 struct i40e_hw
*hw
;
13556 static u16 pfs_found
;
13564 err
= pci_enable_device_mem(pdev
);
13568 /* set up for high or low dma */
13569 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
13571 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
13573 dev_err(&pdev
->dev
,
13574 "DMA configuration failed: 0x%x\n", err
);
13579 /* set up pci connections */
13580 err
= pci_request_mem_regions(pdev
, i40e_driver_name
);
13582 dev_info(&pdev
->dev
,
13583 "pci_request_selected_regions failed %d\n", err
);
13587 pci_enable_pcie_error_reporting(pdev
);
13588 pci_set_master(pdev
);
13590 /* Now that we have a PCI connection, we need to do the
13591 * low level device setup. This is primarily setting up
13592 * the Admin Queue structures and then querying for the
13593 * device's current profile information.
13595 pf
= kzalloc(sizeof(*pf
), GFP_KERNEL
);
13602 set_bit(__I40E_DOWN
, pf
->state
);
13607 pf
->ioremap_len
= min_t(int, pci_resource_len(pdev
, 0),
13608 I40E_MAX_CSR_SPACE
);
13610 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0), pf
->ioremap_len
);
13611 if (!hw
->hw_addr
) {
13613 dev_info(&pdev
->dev
, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
13614 (unsigned int)pci_resource_start(pdev
, 0),
13615 pf
->ioremap_len
, err
);
13618 hw
->vendor_id
= pdev
->vendor
;
13619 hw
->device_id
= pdev
->device
;
13620 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
13621 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
13622 hw
->subsystem_device_id
= pdev
->subsystem_device
;
13623 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
13624 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
13625 hw
->bus
.bus_id
= pdev
->bus
->number
;
13626 pf
->instance
= pfs_found
;
13628 /* Select something other than the 802.1ad ethertype for the
13629 * switch to use internally and drop on ingress.
13631 hw
->switch_tag
= 0xffff;
13632 hw
->first_tag
= ETH_P_8021AD
;
13633 hw
->second_tag
= ETH_P_8021Q
;
13635 INIT_LIST_HEAD(&pf
->l3_flex_pit_list
);
13636 INIT_LIST_HEAD(&pf
->l4_flex_pit_list
);
13638 /* set up the locks for the AQ, do this only once in probe
13639 * and destroy them only once in remove
13641 mutex_init(&hw
->aq
.asq_mutex
);
13642 mutex_init(&hw
->aq
.arq_mutex
);
13644 pf
->msg_enable
= netif_msg_init(debug
,
13649 pf
->hw
.debug_mask
= debug
;
13651 /* do a special CORER for clearing PXE mode once at init */
13652 if (hw
->revision_id
== 0 &&
13653 (rd32(hw
, I40E_GLLAN_RCTL_0
) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK
)) {
13654 wr32(hw
, I40E_GLGEN_RTRIG
, I40E_GLGEN_RTRIG_CORER_MASK
);
13659 i40e_clear_pxe_mode(hw
);
13662 /* Reset here to make sure all is clean and to define PF 'n' */
13664 err
= i40e_pf_reset(hw
);
13666 dev_info(&pdev
->dev
, "Initial pf_reset failed: %d\n", err
);
13671 hw
->aq
.num_arq_entries
= I40E_AQ_LEN
;
13672 hw
->aq
.num_asq_entries
= I40E_AQ_LEN
;
13673 hw
->aq
.arq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
13674 hw
->aq
.asq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
13675 pf
->adminq_work_limit
= I40E_AQ_WORK_LIMIT
;
13677 snprintf(pf
->int_name
, sizeof(pf
->int_name
) - 1,
13679 dev_driver_string(&pf
->pdev
->dev
), dev_name(&pdev
->dev
));
13681 err
= i40e_init_shared_code(hw
);
13683 dev_warn(&pdev
->dev
, "unidentified MAC or BLANK NVM: %d\n",
13688 /* set up a default setting for link flow control */
13689 pf
->hw
.fc
.requested_mode
= I40E_FC_NONE
;
13691 err
= i40e_init_adminq(hw
);
13693 if (err
== I40E_ERR_FIRMWARE_API_VERSION
)
13694 dev_info(&pdev
->dev
,
13695 "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");
13697 dev_info(&pdev
->dev
,
13698 "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
13702 i40e_get_oem_version(hw
);
13704 /* provide nvm, fw, api versions */
13705 dev_info(&pdev
->dev
, "fw %d.%d.%05d api %d.%d nvm %s\n",
13706 hw
->aq
.fw_maj_ver
, hw
->aq
.fw_min_ver
, hw
->aq
.fw_build
,
13707 hw
->aq
.api_maj_ver
, hw
->aq
.api_min_ver
,
13708 i40e_nvm_version_str(hw
));
13710 if (hw
->aq
.api_maj_ver
== I40E_FW_API_VERSION_MAJOR
&&
13711 hw
->aq
.api_min_ver
> I40E_FW_MINOR_VERSION(hw
))
13712 dev_info(&pdev
->dev
,
13713 "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");
13714 else if (hw
->aq
.api_maj_ver
== 1 && hw
->aq
.api_min_ver
< 4)
13715 dev_info(&pdev
->dev
,
13716 "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
13718 i40e_verify_eeprom(pf
);
13720 /* Rev 0 hardware was never productized */
13721 if (hw
->revision_id
< 1)
13722 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");
13724 i40e_clear_pxe_mode(hw
);
13725 err
= i40e_get_capabilities(pf
, i40e_aqc_opc_list_func_capabilities
);
13727 goto err_adminq_setup
;
13729 err
= i40e_sw_init(pf
);
13731 dev_info(&pdev
->dev
, "sw_init failed: %d\n", err
);
13735 err
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
13736 hw
->func_caps
.num_rx_qp
, 0, 0);
13738 dev_info(&pdev
->dev
, "init_lan_hmc failed: %d\n", err
);
13739 goto err_init_lan_hmc
;
13742 err
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
13744 dev_info(&pdev
->dev
, "configure_lan_hmc failed: %d\n", err
);
13746 goto err_configure_lan_hmc
;
13749 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
13750 * Ignore error return codes because if it was already disabled via
13751 * hardware settings this will fail
13753 if (pf
->hw_features
& I40E_HW_STOP_FW_LLDP
) {
13754 dev_info(&pdev
->dev
, "Stopping firmware LLDP agent.\n");
13755 i40e_aq_stop_lldp(hw
, true, NULL
);
13758 /* allow a platform config to override the HW addr */
13759 i40e_get_platform_mac_addr(pdev
, pf
);
13761 if (!is_valid_ether_addr(hw
->mac
.addr
)) {
13762 dev_info(&pdev
->dev
, "invalid MAC address %pM\n", hw
->mac
.addr
);
13766 dev_info(&pdev
->dev
, "MAC address: %pM\n", hw
->mac
.addr
);
13767 ether_addr_copy(hw
->mac
.perm_addr
, hw
->mac
.addr
);
13768 i40e_get_port_mac_addr(hw
, hw
->mac
.port_addr
);
13769 if (is_valid_ether_addr(hw
->mac
.port_addr
))
13770 pf
->hw_features
|= I40E_HW_PORT_ID_VALID
;
13772 pci_set_drvdata(pdev
, pf
);
13773 pci_save_state(pdev
);
13775 /* Enable FW to write default DCB config on link-up */
13776 i40e_aq_set_dcb_parameters(hw
, true, NULL
);
13778 #ifdef CONFIG_I40E_DCB
13779 err
= i40e_init_pf_dcb(pf
);
13781 dev_info(&pdev
->dev
, "DCB init failed %d, disabled\n", err
);
13782 pf
->flags
&= ~(I40E_FLAG_DCB_CAPABLE
| I40E_FLAG_DCB_ENABLED
);
13783 /* Continue without DCB enabled */
13785 #endif /* CONFIG_I40E_DCB */
13787 /* set up periodic task facility */
13788 timer_setup(&pf
->service_timer
, i40e_service_timer
, 0);
13789 pf
->service_timer_period
= HZ
;
13791 INIT_WORK(&pf
->service_task
, i40e_service_task
);
13792 clear_bit(__I40E_SERVICE_SCHED
, pf
->state
);
13794 /* NVM bit on means WoL disabled for the port */
13795 i40e_read_nvm_word(hw
, I40E_SR_NVM_WAKE_ON_LAN
, &wol_nvm_bits
);
13796 if (BIT (hw
->port
) & wol_nvm_bits
|| hw
->partition_id
!= 1)
13797 pf
->wol_en
= false;
13800 device_set_wakeup_enable(&pf
->pdev
->dev
, pf
->wol_en
);
13802 /* set up the main switch operations */
13803 i40e_determine_queue_usage(pf
);
13804 err
= i40e_init_interrupt_scheme(pf
);
13806 goto err_switch_setup
;
13808 /* The number of VSIs reported by the FW is the minimum guaranteed
13809 * to us; HW supports far more and we share the remaining pool with
13810 * the other PFs. We allocate space for more than the guarantee with
13811 * the understanding that we might not get them all later.
13813 if (pf
->hw
.func_caps
.num_vsis
< I40E_MIN_VSI_ALLOC
)
13814 pf
->num_alloc_vsi
= I40E_MIN_VSI_ALLOC
;
13816 pf
->num_alloc_vsi
= pf
->hw
.func_caps
.num_vsis
;
13818 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
13819 pf
->vsi
= kcalloc(pf
->num_alloc_vsi
, sizeof(struct i40e_vsi
*),
13823 goto err_switch_setup
;
13826 #ifdef CONFIG_PCI_IOV
13827 /* prep for VF support */
13828 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
13829 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
13830 !test_bit(__I40E_BAD_EEPROM
, pf
->state
)) {
13831 if (pci_num_vf(pdev
))
13832 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
13835 err
= i40e_setup_pf_switch(pf
, false);
13837 dev_info(&pdev
->dev
, "setup_pf_switch failed: %d\n", err
);
13840 INIT_LIST_HEAD(&pf
->vsi
[pf
->lan_vsi
]->ch_list
);
13842 /* Make sure flow control is set according to current settings */
13843 err
= i40e_set_fc(hw
, &set_fc_aq_fail
, true);
13844 if (set_fc_aq_fail
& I40E_SET_FC_AQ_FAIL_GET
)
13845 dev_dbg(&pf
->pdev
->dev
,
13846 "Set fc with err %s aq_err %s on get_phy_cap\n",
13847 i40e_stat_str(hw
, err
),
13848 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
13849 if (set_fc_aq_fail
& I40E_SET_FC_AQ_FAIL_SET
)
13850 dev_dbg(&pf
->pdev
->dev
,
13851 "Set fc with err %s aq_err %s on set_phy_config\n",
13852 i40e_stat_str(hw
, err
),
13853 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
13854 if (set_fc_aq_fail
& I40E_SET_FC_AQ_FAIL_UPDATE
)
13855 dev_dbg(&pf
->pdev
->dev
,
13856 "Set fc with err %s aq_err %s on get_link_info\n",
13857 i40e_stat_str(hw
, err
),
13858 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
13860 /* if FDIR VSI was set up, start it now */
13861 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
13862 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
13863 i40e_vsi_open(pf
->vsi
[i
]);
13868 /* The driver only wants link up/down and module qualification
13869 * reports from firmware. Note the negative logic.
13871 err
= i40e_aq_set_phy_int_mask(&pf
->hw
,
13872 ~(I40E_AQ_EVENT_LINK_UPDOWN
|
13873 I40E_AQ_EVENT_MEDIA_NA
|
13874 I40E_AQ_EVENT_MODULE_QUAL_FAIL
), NULL
);
13876 dev_info(&pf
->pdev
->dev
, "set phy mask fail, err %s aq_err %s\n",
13877 i40e_stat_str(&pf
->hw
, err
),
13878 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
13880 /* Reconfigure hardware for allowing smaller MSS in the case
13881 * of TSO, so that we avoid the MDD being fired and causing
13882 * a reset in the case of small MSS+TSO.
13884 val
= rd32(hw
, I40E_REG_MSS
);
13885 if ((val
& I40E_REG_MSS_MIN_MASK
) > I40E_64BYTE_MSS
) {
13886 val
&= ~I40E_REG_MSS_MIN_MASK
;
13887 val
|= I40E_64BYTE_MSS
;
13888 wr32(hw
, I40E_REG_MSS
, val
);
13891 if (pf
->hw_features
& I40E_HW_RESTART_AUTONEG
) {
13893 err
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
13895 dev_info(&pf
->pdev
->dev
, "link restart failed, err %s aq_err %s\n",
13896 i40e_stat_str(&pf
->hw
, err
),
13897 i40e_aq_str(&pf
->hw
,
13898 pf
->hw
.aq
.asq_last_status
));
13900 /* The main driver is (mostly) up and happy. We need to set this state
13901 * before setting up the misc vector or we get a race and the vector
13902 * ends up disabled forever.
13904 clear_bit(__I40E_DOWN
, pf
->state
);
13906 /* In case of MSIX we are going to setup the misc vector right here
13907 * to handle admin queue events etc. In case of legacy and MSI
13908 * the misc functionality and queue processing is combined in
13909 * the same vector and that gets setup at open.
13911 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
13912 err
= i40e_setup_misc_vector(pf
);
13914 dev_info(&pdev
->dev
,
13915 "setup of misc vector failed: %d\n", err
);
13920 #ifdef CONFIG_PCI_IOV
13921 /* prep for VF support */
13922 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
13923 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
13924 !test_bit(__I40E_BAD_EEPROM
, pf
->state
)) {
13925 /* disable link interrupts for VFs */
13926 val
= rd32(hw
, I40E_PFGEN_PORTMDIO_NUM
);
13927 val
&= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK
;
13928 wr32(hw
, I40E_PFGEN_PORTMDIO_NUM
, val
);
13931 if (pci_num_vf(pdev
)) {
13932 dev_info(&pdev
->dev
,
13933 "Active VFs found, allocating resources.\n");
13934 err
= i40e_alloc_vfs(pf
, pci_num_vf(pdev
));
13936 dev_info(&pdev
->dev
,
13937 "Error %d allocating resources for existing VFs\n",
13941 #endif /* CONFIG_PCI_IOV */
13943 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
) {
13944 pf
->iwarp_base_vector
= i40e_get_lump(pf
, pf
->irq_pile
,
13945 pf
->num_iwarp_msix
,
13946 I40E_IWARP_IRQ_PILE_ID
);
13947 if (pf
->iwarp_base_vector
< 0) {
13948 dev_info(&pdev
->dev
,
13949 "failed to get tracking for %d vectors for IWARP err=%d\n",
13950 pf
->num_iwarp_msix
, pf
->iwarp_base_vector
);
13951 pf
->flags
&= ~I40E_FLAG_IWARP_ENABLED
;
13955 i40e_dbg_pf_init(pf
);
13957 /* tell the firmware that we're starting */
13958 i40e_send_version(pf
);
13960 /* since everything's happy, start the service_task timer */
13961 mod_timer(&pf
->service_timer
,
13962 round_jiffies(jiffies
+ pf
->service_timer_period
));
13964 /* add this PF to client device list and launch a client service task */
13965 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
) {
13966 err
= i40e_lan_add_device(pf
);
13968 dev_info(&pdev
->dev
, "Failed to add PF to client API service list: %d\n",
13972 #define PCI_SPEED_SIZE 8
13973 #define PCI_WIDTH_SIZE 8
13974 /* Devices on the IOSF bus do not have this information
13975 * and will report PCI Gen 1 x 1 by default so don't bother
13978 if (!(pf
->hw_features
& I40E_HW_NO_PCI_LINK_CHECK
)) {
13979 char speed
[PCI_SPEED_SIZE
] = "Unknown";
13980 char width
[PCI_WIDTH_SIZE
] = "Unknown";
13982 /* Get the negotiated link width and speed from PCI config
13985 pcie_capability_read_word(pf
->pdev
, PCI_EXP_LNKSTA
,
13988 i40e_set_pci_config_data(hw
, link_status
);
13990 switch (hw
->bus
.speed
) {
13991 case i40e_bus_speed_8000
:
13992 strncpy(speed
, "8.0", PCI_SPEED_SIZE
); break;
13993 case i40e_bus_speed_5000
:
13994 strncpy(speed
, "5.0", PCI_SPEED_SIZE
); break;
13995 case i40e_bus_speed_2500
:
13996 strncpy(speed
, "2.5", PCI_SPEED_SIZE
); break;
14000 switch (hw
->bus
.width
) {
14001 case i40e_bus_width_pcie_x8
:
14002 strncpy(width
, "8", PCI_WIDTH_SIZE
); break;
14003 case i40e_bus_width_pcie_x4
:
14004 strncpy(width
, "4", PCI_WIDTH_SIZE
); break;
14005 case i40e_bus_width_pcie_x2
:
14006 strncpy(width
, "2", PCI_WIDTH_SIZE
); break;
14007 case i40e_bus_width_pcie_x1
:
14008 strncpy(width
, "1", PCI_WIDTH_SIZE
); break;
14013 dev_info(&pdev
->dev
, "PCI-Express: Speed %sGT/s Width x%s\n",
14016 if (hw
->bus
.width
< i40e_bus_width_pcie_x8
||
14017 hw
->bus
.speed
< i40e_bus_speed_8000
) {
14018 dev_warn(&pdev
->dev
, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
14019 dev_warn(&pdev
->dev
, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
14023 /* get the requested speeds from the fw */
14024 err
= i40e_aq_get_phy_capabilities(hw
, false, false, &abilities
, NULL
);
14026 dev_dbg(&pf
->pdev
->dev
, "get requested speeds ret = %s last_status = %s\n",
14027 i40e_stat_str(&pf
->hw
, err
),
14028 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
14029 pf
->hw
.phy
.link_info
.requested_speeds
= abilities
.link_speed
;
14031 /* get the supported phy types from the fw */
14032 err
= i40e_aq_get_phy_capabilities(hw
, false, true, &abilities
, NULL
);
14034 dev_dbg(&pf
->pdev
->dev
, "get supported phy types ret = %s last_status = %s\n",
14035 i40e_stat_str(&pf
->hw
, err
),
14036 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
14038 /* Add a filter to drop all Flow control frames from any VSI from being
14039 * transmitted. By doing so we stop a malicious VF from sending out
14040 * PAUSE or PFC frames and potentially controlling traffic for other
14042 * The FW can still send Flow control frames if enabled.
14044 i40e_add_filter_to_drop_tx_flow_control_frames(&pf
->hw
,
14045 pf
->main_vsi_seid
);
14047 if ((pf
->hw
.device_id
== I40E_DEV_ID_10G_BASE_T
) ||
14048 (pf
->hw
.device_id
== I40E_DEV_ID_10G_BASE_T4
))
14049 pf
->hw_features
|= I40E_HW_PHY_CONTROLS_LEDS
;
14050 if (pf
->hw
.device_id
== I40E_DEV_ID_SFP_I_X722
)
14051 pf
->hw_features
|= I40E_HW_HAVE_CRT_RETIMER
;
14052 /* print a string summarizing features */
14053 i40e_print_features(pf
);
14057 /* Unwind what we've done if something failed in the setup */
14059 set_bit(__I40E_DOWN
, pf
->state
);
14060 i40e_clear_interrupt_scheme(pf
);
14063 i40e_reset_interrupt_capability(pf
);
14064 del_timer_sync(&pf
->service_timer
);
14066 err_configure_lan_hmc
:
14067 (void)i40e_shutdown_lan_hmc(hw
);
14069 kfree(pf
->qp_pile
);
14073 iounmap(hw
->hw_addr
);
14077 pci_disable_pcie_error_reporting(pdev
);
14078 pci_release_mem_regions(pdev
);
14081 pci_disable_device(pdev
);
14086 * i40e_remove - Device removal routine
14087 * @pdev: PCI device information struct
14089 * i40e_remove is called by the PCI subsystem to alert the driver
14090 * that is should release a PCI device. This could be caused by a
14091 * Hot-Plug event, or because the driver is going to be removed from
14094 static void i40e_remove(struct pci_dev
*pdev
)
14096 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
14097 struct i40e_hw
*hw
= &pf
->hw
;
14098 i40e_status ret_code
;
14101 i40e_dbg_pf_exit(pf
);
14105 /* Disable RSS in hw */
14106 i40e_write_rx_ctl(hw
, I40E_PFQF_HENA(0), 0);
14107 i40e_write_rx_ctl(hw
, I40E_PFQF_HENA(1), 0);
14109 /* no more scheduling of any task */
14110 set_bit(__I40E_SUSPENDED
, pf
->state
);
14111 set_bit(__I40E_DOWN
, pf
->state
);
14112 if (pf
->service_timer
.function
)
14113 del_timer_sync(&pf
->service_timer
);
14114 if (pf
->service_task
.func
)
14115 cancel_work_sync(&pf
->service_task
);
14117 /* Client close must be called explicitly here because the timer
14118 * has been stopped.
14120 i40e_notify_client_of_netdev_close(pf
->vsi
[pf
->lan_vsi
], false);
14122 if (pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) {
14124 pf
->flags
&= ~I40E_FLAG_SRIOV_ENABLED
;
14127 i40e_fdir_teardown(pf
);
14129 /* If there is a switch structure or any orphans, remove them.
14130 * This will leave only the PF's VSI remaining.
14132 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
14136 if (pf
->veb
[i
]->uplink_seid
== pf
->mac_seid
||
14137 pf
->veb
[i
]->uplink_seid
== 0)
14138 i40e_switch_branch_release(pf
->veb
[i
]);
14141 /* Now we can shutdown the PF's VSI, just before we kill
14144 if (pf
->vsi
[pf
->lan_vsi
])
14145 i40e_vsi_release(pf
->vsi
[pf
->lan_vsi
]);
14147 i40e_cloud_filter_exit(pf
);
14149 /* remove attached clients */
14150 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
) {
14151 ret_code
= i40e_lan_del_device(pf
);
14153 dev_warn(&pdev
->dev
, "Failed to delete client device: %d\n",
14157 /* shutdown and destroy the HMC */
14158 if (hw
->hmc
.hmc_obj
) {
14159 ret_code
= i40e_shutdown_lan_hmc(hw
);
14161 dev_warn(&pdev
->dev
,
14162 "Failed to destroy the HMC resources: %d\n",
14166 /* shutdown the adminq */
14167 i40e_shutdown_adminq(hw
);
14169 /* destroy the locks only once, here */
14170 mutex_destroy(&hw
->aq
.arq_mutex
);
14171 mutex_destroy(&hw
->aq
.asq_mutex
);
14173 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
14174 i40e_clear_interrupt_scheme(pf
);
14175 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
14177 i40e_vsi_clear_rings(pf
->vsi
[i
]);
14178 i40e_vsi_clear(pf
->vsi
[i
]);
14183 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
14188 kfree(pf
->qp_pile
);
14191 iounmap(hw
->hw_addr
);
14193 pci_release_mem_regions(pdev
);
14195 pci_disable_pcie_error_reporting(pdev
);
14196 pci_disable_device(pdev
);
14200 * i40e_pci_error_detected - warning that something funky happened in PCI land
14201 * @pdev: PCI device information struct
14202 * @error: the type of PCI error
14204 * Called to warn that something happened and the error handling steps
14205 * are in progress. Allows the driver to quiesce things, be ready for
14208 static pci_ers_result_t
i40e_pci_error_detected(struct pci_dev
*pdev
,
14209 enum pci_channel_state error
)
14211 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
14213 dev_info(&pdev
->dev
, "%s: error %d\n", __func__
, error
);
14216 dev_info(&pdev
->dev
,
14217 "Cannot recover - error happened during device probe\n");
14218 return PCI_ERS_RESULT_DISCONNECT
;
14221 /* shutdown all operations */
14222 if (!test_bit(__I40E_SUSPENDED
, pf
->state
))
14223 i40e_prep_for_reset(pf
, false);
14225 /* Request a slot reset */
14226 return PCI_ERS_RESULT_NEED_RESET
;
14230 * i40e_pci_error_slot_reset - a PCI slot reset just happened
14231 * @pdev: PCI device information struct
14233 * Called to find if the driver can work with the device now that
14234 * the pci slot has been reset. If a basic connection seems good
14235 * (registers are readable and have sane content) then return a
14236 * happy little PCI_ERS_RESULT_xxx.
14238 static pci_ers_result_t
i40e_pci_error_slot_reset(struct pci_dev
*pdev
)
14240 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
14241 pci_ers_result_t result
;
14245 dev_dbg(&pdev
->dev
, "%s\n", __func__
);
14246 if (pci_enable_device_mem(pdev
)) {
14247 dev_info(&pdev
->dev
,
14248 "Cannot re-enable PCI device after reset.\n");
14249 result
= PCI_ERS_RESULT_DISCONNECT
;
14251 pci_set_master(pdev
);
14252 pci_restore_state(pdev
);
14253 pci_save_state(pdev
);
14254 pci_wake_from_d3(pdev
, false);
14256 reg
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
14258 result
= PCI_ERS_RESULT_RECOVERED
;
14260 result
= PCI_ERS_RESULT_DISCONNECT
;
14263 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
14265 dev_info(&pdev
->dev
,
14266 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
14268 /* non-fatal, continue */
14275 * i40e_pci_error_reset_prepare - prepare device driver for pci reset
14276 * @pdev: PCI device information struct
14278 static void i40e_pci_error_reset_prepare(struct pci_dev
*pdev
)
14280 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
14282 i40e_prep_for_reset(pf
, false);
14286 * i40e_pci_error_reset_done - pci reset done, device driver reset can begin
14287 * @pdev: PCI device information struct
14289 static void i40e_pci_error_reset_done(struct pci_dev
*pdev
)
14291 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
14293 i40e_reset_and_rebuild(pf
, false, false);
14297 * i40e_pci_error_resume - restart operations after PCI error recovery
14298 * @pdev: PCI device information struct
14300 * Called to allow the driver to bring things back up after PCI error
14301 * and/or reset recovery has finished.
14303 static void i40e_pci_error_resume(struct pci_dev
*pdev
)
14305 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
14307 dev_dbg(&pdev
->dev
, "%s\n", __func__
);
14308 if (test_bit(__I40E_SUSPENDED
, pf
->state
))
14311 i40e_handle_reset_warning(pf
, false);
14315 * i40e_enable_mc_magic_wake - enable multicast magic packet wake up
14316 * using the mac_address_write admin q function
14317 * @pf: pointer to i40e_pf struct
14319 static void i40e_enable_mc_magic_wake(struct i40e_pf
*pf
)
14321 struct i40e_hw
*hw
= &pf
->hw
;
14326 /* Get current MAC address in case it's an LAA */
14327 if (pf
->vsi
[pf
->lan_vsi
] && pf
->vsi
[pf
->lan_vsi
]->netdev
) {
14328 ether_addr_copy(mac_addr
,
14329 pf
->vsi
[pf
->lan_vsi
]->netdev
->dev_addr
);
14331 dev_err(&pf
->pdev
->dev
,
14332 "Failed to retrieve MAC address; using default\n");
14333 ether_addr_copy(mac_addr
, hw
->mac
.addr
);
14336 /* The FW expects the mac address write cmd to first be called with
14337 * one of these flags before calling it again with the multicast
14340 flags
= I40E_AQC_WRITE_TYPE_LAA_WOL
;
14342 if (hw
->func_caps
.flex10_enable
&& hw
->partition_id
!= 1)
14343 flags
= I40E_AQC_WRITE_TYPE_LAA_ONLY
;
14345 ret
= i40e_aq_mac_address_write(hw
, flags
, mac_addr
, NULL
);
14347 dev_err(&pf
->pdev
->dev
,
14348 "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up");
14352 flags
= I40E_AQC_MC_MAG_EN
14353 | I40E_AQC_WOL_PRESERVE_ON_PFR
14354 | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG
;
14355 ret
= i40e_aq_mac_address_write(hw
, flags
, mac_addr
, NULL
);
14357 dev_err(&pf
->pdev
->dev
,
14358 "Failed to enable Multicast Magic Packet wake up\n");
14362 * i40e_shutdown - PCI callback for shutting down
14363 * @pdev: PCI device information struct
14365 static void i40e_shutdown(struct pci_dev
*pdev
)
14367 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
14368 struct i40e_hw
*hw
= &pf
->hw
;
14370 set_bit(__I40E_SUSPENDED
, pf
->state
);
14371 set_bit(__I40E_DOWN
, pf
->state
);
14373 del_timer_sync(&pf
->service_timer
);
14374 cancel_work_sync(&pf
->service_task
);
14375 i40e_cloud_filter_exit(pf
);
14376 i40e_fdir_teardown(pf
);
14378 /* Client close must be called explicitly here because the timer
14379 * has been stopped.
14381 i40e_notify_client_of_netdev_close(pf
->vsi
[pf
->lan_vsi
], false);
14383 if (pf
->wol_en
&& (pf
->hw_features
& I40E_HW_WOL_MC_MAGIC_PKT_WAKE
))
14384 i40e_enable_mc_magic_wake(pf
);
14386 i40e_prep_for_reset(pf
, false);
14388 wr32(hw
, I40E_PFPM_APM
,
14389 (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
14390 wr32(hw
, I40E_PFPM_WUFC
,
14391 (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
14393 i40e_clear_interrupt_scheme(pf
);
14395 if (system_state
== SYSTEM_POWER_OFF
) {
14396 pci_wake_from_d3(pdev
, pf
->wol_en
);
14397 pci_set_power_state(pdev
, PCI_D3hot
);
14402 * i40e_suspend - PM callback for moving to D3
14403 * @dev: generic device information structure
14405 static int __maybe_unused
i40e_suspend(struct device
*dev
)
14407 struct pci_dev
*pdev
= to_pci_dev(dev
);
14408 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
14409 struct i40e_hw
*hw
= &pf
->hw
;
14411 /* If we're already suspended, then there is nothing to do */
14412 if (test_and_set_bit(__I40E_SUSPENDED
, pf
->state
))
14415 set_bit(__I40E_DOWN
, pf
->state
);
14417 /* Ensure service task will not be running */
14418 del_timer_sync(&pf
->service_timer
);
14419 cancel_work_sync(&pf
->service_task
);
14421 /* Client close must be called explicitly here because the timer
14422 * has been stopped.
14424 i40e_notify_client_of_netdev_close(pf
->vsi
[pf
->lan_vsi
], false);
14426 if (pf
->wol_en
&& (pf
->hw_features
& I40E_HW_WOL_MC_MAGIC_PKT_WAKE
))
14427 i40e_enable_mc_magic_wake(pf
);
14429 /* Since we're going to destroy queues during the
14430 * i40e_clear_interrupt_scheme() we should hold the RTNL lock for this
14435 i40e_prep_for_reset(pf
, true);
14437 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
14438 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
14440 /* Clear the interrupt scheme and release our IRQs so that the system
14441 * can safely hibernate even when there are a large number of CPUs.
14442 * Otherwise hibernation might fail when mapping all the vectors back
14445 i40e_clear_interrupt_scheme(pf
);
14453 * i40e_resume - PM callback for waking up from D3
14454 * @dev: generic device information structure
14456 static int __maybe_unused
i40e_resume(struct device
*dev
)
14458 struct pci_dev
*pdev
= to_pci_dev(dev
);
14459 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
14462 /* If we're not suspended, then there is nothing to do */
14463 if (!test_bit(__I40E_SUSPENDED
, pf
->state
))
14466 /* We need to hold the RTNL lock prior to restoring interrupt schemes,
14467 * since we're going to be restoring queues
14471 /* We cleared the interrupt scheme when we suspended, so we need to
14472 * restore it now to resume device functionality.
14474 err
= i40e_restore_interrupt_scheme(pf
);
14476 dev_err(&pdev
->dev
, "Cannot restore interrupt scheme: %d\n",
14480 clear_bit(__I40E_DOWN
, pf
->state
);
14481 i40e_reset_and_rebuild(pf
, false, true);
14485 /* Clear suspended state last after everything is recovered */
14486 clear_bit(__I40E_SUSPENDED
, pf
->state
);
14488 /* Restart the service task */
14489 mod_timer(&pf
->service_timer
,
14490 round_jiffies(jiffies
+ pf
->service_timer_period
));
14495 static const struct pci_error_handlers i40e_err_handler
= {
14496 .error_detected
= i40e_pci_error_detected
,
14497 .slot_reset
= i40e_pci_error_slot_reset
,
14498 .reset_prepare
= i40e_pci_error_reset_prepare
,
14499 .reset_done
= i40e_pci_error_reset_done
,
14500 .resume
= i40e_pci_error_resume
,
14503 static SIMPLE_DEV_PM_OPS(i40e_pm_ops
, i40e_suspend
, i40e_resume
);
14505 static struct pci_driver i40e_driver
= {
14506 .name
= i40e_driver_name
,
14507 .id_table
= i40e_pci_tbl
,
14508 .probe
= i40e_probe
,
14509 .remove
= i40e_remove
,
14511 .pm
= &i40e_pm_ops
,
14513 .shutdown
= i40e_shutdown
,
14514 .err_handler
= &i40e_err_handler
,
14515 .sriov_configure
= i40e_pci_sriov_configure
,
14519 * i40e_init_module - Driver registration routine
14521 * i40e_init_module is the first routine called when the driver is
14522 * loaded. All it does is register with the PCI subsystem.
14524 static int __init
i40e_init_module(void)
14526 pr_info("%s: %s - version %s\n", i40e_driver_name
,
14527 i40e_driver_string
, i40e_driver_version_str
);
14528 pr_info("%s: %s\n", i40e_driver_name
, i40e_copyright
);
14530 /* There is no need to throttle the number of active tasks because
14531 * each device limits its own task using a state bit for scheduling
14532 * the service task, and the device tasks do not interfere with each
14533 * other, so we don't set a max task limit. We must set WQ_MEM_RECLAIM
14534 * since we need to be able to guarantee forward progress even under
14537 i40e_wq
= alloc_workqueue("%s", WQ_MEM_RECLAIM
, 0, i40e_driver_name
);
14539 pr_err("%s: Failed to create workqueue\n", i40e_driver_name
);
14544 return pci_register_driver(&i40e_driver
);
14546 module_init(i40e_init_module
);
14549 * i40e_exit_module - Driver exit cleanup routine
14551 * i40e_exit_module is called just before the driver is removed
14554 static void __exit
i40e_exit_module(void)
14556 pci_unregister_driver(&i40e_driver
);
14557 destroy_workqueue(i40e_wq
);
14560 module_exit(i40e_exit_module
);