1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2015 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 ******************************************************************************/
29 #include "i40e_diag.h"
30 #if IS_ENABLED(CONFIG_VXLAN)
31 #include <net/vxlan.h>
33 #if IS_ENABLED(CONFIG_GENEVE)
34 #include <net/geneve.h>
37 const char i40e_driver_name
[] = "i40e";
38 static const char i40e_driver_string
[] =
39 "Intel(R) Ethernet Connection XL710 Network Driver";
43 #define DRV_VERSION_MAJOR 1
44 #define DRV_VERSION_MINOR 4
45 #define DRV_VERSION_BUILD 8
46 #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
47 __stringify(DRV_VERSION_MINOR) "." \
48 __stringify(DRV_VERSION_BUILD) DRV_KERN
49 const char i40e_driver_version_str
[] = DRV_VERSION
;
50 static const char i40e_copyright
[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
52 /* a bit of forward declarations */
53 static void i40e_vsi_reinit_locked(struct i40e_vsi
*vsi
);
54 static void i40e_handle_reset_warning(struct i40e_pf
*pf
);
55 static int i40e_add_vsi(struct i40e_vsi
*vsi
);
56 static int i40e_add_veb(struct i40e_veb
*veb
, struct i40e_vsi
*vsi
);
57 static int i40e_setup_pf_switch(struct i40e_pf
*pf
, bool reinit
);
58 static int i40e_setup_misc_vector(struct i40e_pf
*pf
);
59 static void i40e_determine_queue_usage(struct i40e_pf
*pf
);
60 static int i40e_setup_pf_filter_control(struct i40e_pf
*pf
);
61 static void i40e_fill_rss_lut(struct i40e_pf
*pf
, u8
*lut
,
62 u16 rss_table_size
, u16 rss_size
);
63 static void i40e_fdir_sb_setup(struct i40e_pf
*pf
);
64 static int i40e_veb_get_bw_info(struct i40e_veb
*veb
);
66 /* i40e_pci_tbl - PCI Device ID Table
68 * Last entry must be all 0s
70 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
71 * Class, Class Mask, private data (not used) }
73 static const struct pci_device_id i40e_pci_tbl
[] = {
74 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_SFP_XL710
), 0},
75 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QEMU
), 0},
76 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_A
), 0},
77 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_B
), 0},
78 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_C
), 0},
79 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_A
), 0},
80 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_B
), 0},
81 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_C
), 0},
82 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T
), 0},
83 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T4
), 0},
84 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_20G_KR2
), 0},
85 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_SFP_X722
), 0},
86 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_1G_BASE_T_X722
), 0},
87 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T_X722
), 0},
88 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_20G_KR2
), 0},
89 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_20G_KR2_A
), 0},
90 /* required last entry */
93 MODULE_DEVICE_TABLE(pci
, i40e_pci_tbl
);
95 #define I40E_MAX_VF_COUNT 128
96 static int debug
= -1;
97 module_param(debug
, int, 0);
98 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
100 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
101 MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
102 MODULE_LICENSE("GPL");
103 MODULE_VERSION(DRV_VERSION
);
106 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
107 * @hw: pointer to the HW structure
108 * @mem: ptr to mem struct to fill out
109 * @size: size of memory requested
110 * @alignment: what to align the allocation to
112 int i40e_allocate_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
,
113 u64 size
, u32 alignment
)
115 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
117 mem
->size
= ALIGN(size
, alignment
);
118 mem
->va
= dma_zalloc_coherent(&pf
->pdev
->dev
, mem
->size
,
119 &mem
->pa
, GFP_KERNEL
);
127 * i40e_free_dma_mem_d - OS specific memory free for shared code
128 * @hw: pointer to the HW structure
129 * @mem: ptr to mem struct to free
131 int i40e_free_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
)
133 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
135 dma_free_coherent(&pf
->pdev
->dev
, mem
->size
, mem
->va
, mem
->pa
);
144 * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
145 * @hw: pointer to the HW structure
146 * @mem: ptr to mem struct to fill out
147 * @size: size of memory requested
149 int i40e_allocate_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
,
153 mem
->va
= kzalloc(size
, GFP_KERNEL
);
162 * i40e_free_virt_mem_d - OS specific memory free for shared code
163 * @hw: pointer to the HW structure
164 * @mem: ptr to mem struct to free
166 int i40e_free_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
)
168 /* it's ok to kfree a NULL pointer */
177 * i40e_get_lump - find a lump of free generic resource
178 * @pf: board private structure
179 * @pile: the pile of resource to search
180 * @needed: the number of items needed
181 * @id: an owner id to stick on the items assigned
183 * Returns the base item index of the lump, or negative for error
185 * The search_hint trick and lack of advanced fit-finding only work
186 * because we're highly likely to have all the same size lump requests.
187 * Linear search time and any fragmentation should be minimal.
189 static int i40e_get_lump(struct i40e_pf
*pf
, struct i40e_lump_tracking
*pile
,
195 if (!pile
|| needed
== 0 || id
>= I40E_PILE_VALID_BIT
) {
196 dev_info(&pf
->pdev
->dev
,
197 "param err: pile=%p needed=%d id=0x%04x\n",
202 /* start the linear search with an imperfect hint */
203 i
= pile
->search_hint
;
204 while (i
< pile
->num_entries
) {
205 /* skip already allocated entries */
206 if (pile
->list
[i
] & I40E_PILE_VALID_BIT
) {
211 /* do we have enough in this lump? */
212 for (j
= 0; (j
< needed
) && ((i
+j
) < pile
->num_entries
); j
++) {
213 if (pile
->list
[i
+j
] & I40E_PILE_VALID_BIT
)
218 /* there was enough, so assign it to the requestor */
219 for (j
= 0; j
< needed
; j
++)
220 pile
->list
[i
+j
] = id
| I40E_PILE_VALID_BIT
;
222 pile
->search_hint
= i
+ j
;
226 /* not enough, so skip over it and continue looking */
234 * i40e_put_lump - return a lump of generic resource
235 * @pile: the pile of resource to search
236 * @index: the base item index
237 * @id: the owner id of the items assigned
239 * Returns the count of items in the lump
241 static int i40e_put_lump(struct i40e_lump_tracking
*pile
, u16 index
, u16 id
)
243 int valid_id
= (id
| I40E_PILE_VALID_BIT
);
247 if (!pile
|| index
>= pile
->num_entries
)
251 i
< pile
->num_entries
&& pile
->list
[i
] == valid_id
;
257 if (count
&& index
< pile
->search_hint
)
258 pile
->search_hint
= index
;
264 * i40e_find_vsi_from_id - searches for the vsi with the given id
265 * @pf - the pf structure to search for the vsi
266 * @id - id of the vsi it is searching for
268 struct i40e_vsi
*i40e_find_vsi_from_id(struct i40e_pf
*pf
, u16 id
)
272 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
273 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->id
== id
))
280 * i40e_service_event_schedule - Schedule the service task to wake up
281 * @pf: board private structure
283 * If not already scheduled, this puts the task into the work queue
285 static void i40e_service_event_schedule(struct i40e_pf
*pf
)
287 if (!test_bit(__I40E_DOWN
, &pf
->state
) &&
288 !test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) &&
289 !test_and_set_bit(__I40E_SERVICE_SCHED
, &pf
->state
))
290 schedule_work(&pf
->service_task
);
294 * i40e_tx_timeout - Respond to a Tx Hang
295 * @netdev: network interface device structure
297 * If any port has noticed a Tx timeout, it is likely that the whole
298 * device is munged, not just the one netdev port, so go for the full
302 void i40e_tx_timeout(struct net_device
*netdev
)
304 static void i40e_tx_timeout(struct net_device
*netdev
)
307 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
308 struct i40e_vsi
*vsi
= np
->vsi
;
309 struct i40e_pf
*pf
= vsi
->back
;
310 struct i40e_ring
*tx_ring
= NULL
;
311 unsigned int i
, hung_queue
= 0;
314 pf
->tx_timeout_count
++;
316 /* find the stopped queue the same way the stack does */
317 for (i
= 0; i
< netdev
->num_tx_queues
; i
++) {
318 struct netdev_queue
*q
;
319 unsigned long trans_start
;
321 q
= netdev_get_tx_queue(netdev
, i
);
322 trans_start
= q
->trans_start
? : netdev
->trans_start
;
323 if (netif_xmit_stopped(q
) &&
325 (trans_start
+ netdev
->watchdog_timeo
))) {
331 if (i
== netdev
->num_tx_queues
) {
332 netdev_info(netdev
, "tx_timeout: no netdev hung queue found\n");
334 /* now that we have an index, find the tx_ring struct */
335 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
336 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
) {
338 vsi
->tx_rings
[i
]->queue_index
) {
339 tx_ring
= vsi
->tx_rings
[i
];
346 if (time_after(jiffies
, (pf
->tx_timeout_last_recovery
+ HZ
*20)))
347 pf
->tx_timeout_recovery_level
= 1; /* reset after some time */
348 else if (time_before(jiffies
,
349 (pf
->tx_timeout_last_recovery
+ netdev
->watchdog_timeo
)))
350 return; /* don't do any new action before the next timeout */
353 head
= i40e_get_head(tx_ring
);
354 /* Read interrupt register */
355 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
357 I40E_PFINT_DYN_CTLN(tx_ring
->q_vector
->v_idx
+
358 tx_ring
->vsi
->base_vector
- 1));
360 val
= rd32(&pf
->hw
, I40E_PFINT_DYN_CTL0
);
362 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",
363 vsi
->seid
, hung_queue
, tx_ring
->next_to_clean
,
364 head
, tx_ring
->next_to_use
,
365 readl(tx_ring
->tail
), val
);
368 pf
->tx_timeout_last_recovery
= jiffies
;
369 netdev_info(netdev
, "tx_timeout recovery level %d, hung_queue %d\n",
370 pf
->tx_timeout_recovery_level
, hung_queue
);
372 switch (pf
->tx_timeout_recovery_level
) {
374 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
377 set_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
);
380 set_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
);
383 netdev_err(netdev
, "tx_timeout recovery unsuccessful\n");
387 i40e_service_event_schedule(pf
);
388 pf
->tx_timeout_recovery_level
++;
392 * i40e_release_rx_desc - Store the new tail and head values
393 * @rx_ring: ring to bump
394 * @val: new head index
396 static inline void i40e_release_rx_desc(struct i40e_ring
*rx_ring
, u32 val
)
398 rx_ring
->next_to_use
= val
;
400 /* Force memory writes to complete before letting h/w
401 * know there are new descriptors to fetch. (Only
402 * applicable for weak-ordered memory model archs,
406 writel(val
, rx_ring
->tail
);
410 * i40e_get_vsi_stats_struct - Get System Network Statistics
411 * @vsi: the VSI we care about
413 * Returns the address of the device statistics structure.
414 * The statistics are actually updated from the service task.
416 struct rtnl_link_stats64
*i40e_get_vsi_stats_struct(struct i40e_vsi
*vsi
)
418 return &vsi
->net_stats
;
422 * i40e_get_netdev_stats_struct - Get statistics for netdev interface
423 * @netdev: network interface device structure
425 * Returns the address of the device statistics structure.
426 * The statistics are actually updated from the service task.
429 struct rtnl_link_stats64
*i40e_get_netdev_stats_struct(
430 struct net_device
*netdev
,
431 struct rtnl_link_stats64
*stats
)
433 static struct rtnl_link_stats64
*i40e_get_netdev_stats_struct(
434 struct net_device
*netdev
,
435 struct rtnl_link_stats64
*stats
)
438 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
439 struct i40e_ring
*tx_ring
, *rx_ring
;
440 struct i40e_vsi
*vsi
= np
->vsi
;
441 struct rtnl_link_stats64
*vsi_stats
= i40e_get_vsi_stats_struct(vsi
);
444 if (test_bit(__I40E_DOWN
, &vsi
->state
))
451 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
455 tx_ring
= ACCESS_ONCE(vsi
->tx_rings
[i
]);
460 start
= u64_stats_fetch_begin_irq(&tx_ring
->syncp
);
461 packets
= tx_ring
->stats
.packets
;
462 bytes
= tx_ring
->stats
.bytes
;
463 } while (u64_stats_fetch_retry_irq(&tx_ring
->syncp
, start
));
465 stats
->tx_packets
+= packets
;
466 stats
->tx_bytes
+= bytes
;
467 rx_ring
= &tx_ring
[1];
470 start
= u64_stats_fetch_begin_irq(&rx_ring
->syncp
);
471 packets
= rx_ring
->stats
.packets
;
472 bytes
= rx_ring
->stats
.bytes
;
473 } while (u64_stats_fetch_retry_irq(&rx_ring
->syncp
, start
));
475 stats
->rx_packets
+= packets
;
476 stats
->rx_bytes
+= bytes
;
480 /* following stats updated by i40e_watchdog_subtask() */
481 stats
->multicast
= vsi_stats
->multicast
;
482 stats
->tx_errors
= vsi_stats
->tx_errors
;
483 stats
->tx_dropped
= vsi_stats
->tx_dropped
;
484 stats
->rx_errors
= vsi_stats
->rx_errors
;
485 stats
->rx_dropped
= vsi_stats
->rx_dropped
;
486 stats
->rx_crc_errors
= vsi_stats
->rx_crc_errors
;
487 stats
->rx_length_errors
= vsi_stats
->rx_length_errors
;
493 * i40e_vsi_reset_stats - Resets all stats of the given vsi
494 * @vsi: the VSI to have its stats reset
496 void i40e_vsi_reset_stats(struct i40e_vsi
*vsi
)
498 struct rtnl_link_stats64
*ns
;
504 ns
= i40e_get_vsi_stats_struct(vsi
);
505 memset(ns
, 0, sizeof(*ns
));
506 memset(&vsi
->net_stats_offsets
, 0, sizeof(vsi
->net_stats_offsets
));
507 memset(&vsi
->eth_stats
, 0, sizeof(vsi
->eth_stats
));
508 memset(&vsi
->eth_stats_offsets
, 0, sizeof(vsi
->eth_stats_offsets
));
509 if (vsi
->rx_rings
&& vsi
->rx_rings
[0]) {
510 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
511 memset(&vsi
->rx_rings
[i
]->stats
, 0,
512 sizeof(vsi
->rx_rings
[i
]->stats
));
513 memset(&vsi
->rx_rings
[i
]->rx_stats
, 0,
514 sizeof(vsi
->rx_rings
[i
]->rx_stats
));
515 memset(&vsi
->tx_rings
[i
]->stats
, 0,
516 sizeof(vsi
->tx_rings
[i
]->stats
));
517 memset(&vsi
->tx_rings
[i
]->tx_stats
, 0,
518 sizeof(vsi
->tx_rings
[i
]->tx_stats
));
521 vsi
->stat_offsets_loaded
= false;
525 * i40e_pf_reset_stats - Reset all of the stats for the given PF
526 * @pf: the PF to be reset
528 void i40e_pf_reset_stats(struct i40e_pf
*pf
)
532 memset(&pf
->stats
, 0, sizeof(pf
->stats
));
533 memset(&pf
->stats_offsets
, 0, sizeof(pf
->stats_offsets
));
534 pf
->stat_offsets_loaded
= false;
536 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
538 memset(&pf
->veb
[i
]->stats
, 0,
539 sizeof(pf
->veb
[i
]->stats
));
540 memset(&pf
->veb
[i
]->stats_offsets
, 0,
541 sizeof(pf
->veb
[i
]->stats_offsets
));
542 pf
->veb
[i
]->stat_offsets_loaded
= false;
548 * i40e_stat_update48 - read and update a 48 bit stat from the chip
549 * @hw: ptr to the hardware info
550 * @hireg: the high 32 bit reg to read
551 * @loreg: the low 32 bit reg to read
552 * @offset_loaded: has the initial offset been loaded yet
553 * @offset: ptr to current offset value
554 * @stat: ptr to the stat
556 * Since the device stats are not reset at PFReset, they likely will not
557 * be zeroed when the driver starts. We'll save the first values read
558 * and use them as offsets to be subtracted from the raw values in order
559 * to report stats that count from zero. In the process, we also manage
560 * the potential roll-over.
562 static void i40e_stat_update48(struct i40e_hw
*hw
, u32 hireg
, u32 loreg
,
563 bool offset_loaded
, u64
*offset
, u64
*stat
)
567 if (hw
->device_id
== I40E_DEV_ID_QEMU
) {
568 new_data
= rd32(hw
, loreg
);
569 new_data
|= ((u64
)(rd32(hw
, hireg
) & 0xFFFF)) << 32;
571 new_data
= rd64(hw
, loreg
);
575 if (likely(new_data
>= *offset
))
576 *stat
= new_data
- *offset
;
578 *stat
= (new_data
+ BIT_ULL(48)) - *offset
;
579 *stat
&= 0xFFFFFFFFFFFFULL
;
583 * i40e_stat_update32 - read and update a 32 bit stat from the chip
584 * @hw: ptr to the hardware info
585 * @reg: the hw reg to read
586 * @offset_loaded: has the initial offset been loaded yet
587 * @offset: ptr to current offset value
588 * @stat: ptr to the stat
590 static void i40e_stat_update32(struct i40e_hw
*hw
, u32 reg
,
591 bool offset_loaded
, u64
*offset
, u64
*stat
)
595 new_data
= rd32(hw
, reg
);
598 if (likely(new_data
>= *offset
))
599 *stat
= (u32
)(new_data
- *offset
);
601 *stat
= (u32
)((new_data
+ BIT_ULL(32)) - *offset
);
605 * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
606 * @vsi: the VSI to be updated
608 void i40e_update_eth_stats(struct i40e_vsi
*vsi
)
610 int stat_idx
= le16_to_cpu(vsi
->info
.stat_counter_idx
);
611 struct i40e_pf
*pf
= vsi
->back
;
612 struct i40e_hw
*hw
= &pf
->hw
;
613 struct i40e_eth_stats
*oes
;
614 struct i40e_eth_stats
*es
; /* device's eth stats */
616 es
= &vsi
->eth_stats
;
617 oes
= &vsi
->eth_stats_offsets
;
619 /* Gather up the stats that the hw collects */
620 i40e_stat_update32(hw
, I40E_GLV_TEPC(stat_idx
),
621 vsi
->stat_offsets_loaded
,
622 &oes
->tx_errors
, &es
->tx_errors
);
623 i40e_stat_update32(hw
, I40E_GLV_RDPC(stat_idx
),
624 vsi
->stat_offsets_loaded
,
625 &oes
->rx_discards
, &es
->rx_discards
);
626 i40e_stat_update32(hw
, I40E_GLV_RUPP(stat_idx
),
627 vsi
->stat_offsets_loaded
,
628 &oes
->rx_unknown_protocol
, &es
->rx_unknown_protocol
);
629 i40e_stat_update32(hw
, I40E_GLV_TEPC(stat_idx
),
630 vsi
->stat_offsets_loaded
,
631 &oes
->tx_errors
, &es
->tx_errors
);
633 i40e_stat_update48(hw
, I40E_GLV_GORCH(stat_idx
),
634 I40E_GLV_GORCL(stat_idx
),
635 vsi
->stat_offsets_loaded
,
636 &oes
->rx_bytes
, &es
->rx_bytes
);
637 i40e_stat_update48(hw
, I40E_GLV_UPRCH(stat_idx
),
638 I40E_GLV_UPRCL(stat_idx
),
639 vsi
->stat_offsets_loaded
,
640 &oes
->rx_unicast
, &es
->rx_unicast
);
641 i40e_stat_update48(hw
, I40E_GLV_MPRCH(stat_idx
),
642 I40E_GLV_MPRCL(stat_idx
),
643 vsi
->stat_offsets_loaded
,
644 &oes
->rx_multicast
, &es
->rx_multicast
);
645 i40e_stat_update48(hw
, I40E_GLV_BPRCH(stat_idx
),
646 I40E_GLV_BPRCL(stat_idx
),
647 vsi
->stat_offsets_loaded
,
648 &oes
->rx_broadcast
, &es
->rx_broadcast
);
650 i40e_stat_update48(hw
, I40E_GLV_GOTCH(stat_idx
),
651 I40E_GLV_GOTCL(stat_idx
),
652 vsi
->stat_offsets_loaded
,
653 &oes
->tx_bytes
, &es
->tx_bytes
);
654 i40e_stat_update48(hw
, I40E_GLV_UPTCH(stat_idx
),
655 I40E_GLV_UPTCL(stat_idx
),
656 vsi
->stat_offsets_loaded
,
657 &oes
->tx_unicast
, &es
->tx_unicast
);
658 i40e_stat_update48(hw
, I40E_GLV_MPTCH(stat_idx
),
659 I40E_GLV_MPTCL(stat_idx
),
660 vsi
->stat_offsets_loaded
,
661 &oes
->tx_multicast
, &es
->tx_multicast
);
662 i40e_stat_update48(hw
, I40E_GLV_BPTCH(stat_idx
),
663 I40E_GLV_BPTCL(stat_idx
),
664 vsi
->stat_offsets_loaded
,
665 &oes
->tx_broadcast
, &es
->tx_broadcast
);
666 vsi
->stat_offsets_loaded
= true;
670 * i40e_update_veb_stats - Update Switch component statistics
671 * @veb: the VEB being updated
673 static void i40e_update_veb_stats(struct i40e_veb
*veb
)
675 struct i40e_pf
*pf
= veb
->pf
;
676 struct i40e_hw
*hw
= &pf
->hw
;
677 struct i40e_eth_stats
*oes
;
678 struct i40e_eth_stats
*es
; /* device's eth stats */
679 struct i40e_veb_tc_stats
*veb_oes
;
680 struct i40e_veb_tc_stats
*veb_es
;
683 idx
= veb
->stats_idx
;
685 oes
= &veb
->stats_offsets
;
686 veb_es
= &veb
->tc_stats
;
687 veb_oes
= &veb
->tc_stats_offsets
;
689 /* Gather up the stats that the hw collects */
690 i40e_stat_update32(hw
, I40E_GLSW_TDPC(idx
),
691 veb
->stat_offsets_loaded
,
692 &oes
->tx_discards
, &es
->tx_discards
);
693 if (hw
->revision_id
> 0)
694 i40e_stat_update32(hw
, I40E_GLSW_RUPP(idx
),
695 veb
->stat_offsets_loaded
,
696 &oes
->rx_unknown_protocol
,
697 &es
->rx_unknown_protocol
);
698 i40e_stat_update48(hw
, I40E_GLSW_GORCH(idx
), I40E_GLSW_GORCL(idx
),
699 veb
->stat_offsets_loaded
,
700 &oes
->rx_bytes
, &es
->rx_bytes
);
701 i40e_stat_update48(hw
, I40E_GLSW_UPRCH(idx
), I40E_GLSW_UPRCL(idx
),
702 veb
->stat_offsets_loaded
,
703 &oes
->rx_unicast
, &es
->rx_unicast
);
704 i40e_stat_update48(hw
, I40E_GLSW_MPRCH(idx
), I40E_GLSW_MPRCL(idx
),
705 veb
->stat_offsets_loaded
,
706 &oes
->rx_multicast
, &es
->rx_multicast
);
707 i40e_stat_update48(hw
, I40E_GLSW_BPRCH(idx
), I40E_GLSW_BPRCL(idx
),
708 veb
->stat_offsets_loaded
,
709 &oes
->rx_broadcast
, &es
->rx_broadcast
);
711 i40e_stat_update48(hw
, I40E_GLSW_GOTCH(idx
), I40E_GLSW_GOTCL(idx
),
712 veb
->stat_offsets_loaded
,
713 &oes
->tx_bytes
, &es
->tx_bytes
);
714 i40e_stat_update48(hw
, I40E_GLSW_UPTCH(idx
), I40E_GLSW_UPTCL(idx
),
715 veb
->stat_offsets_loaded
,
716 &oes
->tx_unicast
, &es
->tx_unicast
);
717 i40e_stat_update48(hw
, I40E_GLSW_MPTCH(idx
), I40E_GLSW_MPTCL(idx
),
718 veb
->stat_offsets_loaded
,
719 &oes
->tx_multicast
, &es
->tx_multicast
);
720 i40e_stat_update48(hw
, I40E_GLSW_BPTCH(idx
), I40E_GLSW_BPTCL(idx
),
721 veb
->stat_offsets_loaded
,
722 &oes
->tx_broadcast
, &es
->tx_broadcast
);
723 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
724 i40e_stat_update48(hw
, I40E_GLVEBTC_RPCH(i
, idx
),
725 I40E_GLVEBTC_RPCL(i
, idx
),
726 veb
->stat_offsets_loaded
,
727 &veb_oes
->tc_rx_packets
[i
],
728 &veb_es
->tc_rx_packets
[i
]);
729 i40e_stat_update48(hw
, I40E_GLVEBTC_RBCH(i
, idx
),
730 I40E_GLVEBTC_RBCL(i
, idx
),
731 veb
->stat_offsets_loaded
,
732 &veb_oes
->tc_rx_bytes
[i
],
733 &veb_es
->tc_rx_bytes
[i
]);
734 i40e_stat_update48(hw
, I40E_GLVEBTC_TPCH(i
, idx
),
735 I40E_GLVEBTC_TPCL(i
, idx
),
736 veb
->stat_offsets_loaded
,
737 &veb_oes
->tc_tx_packets
[i
],
738 &veb_es
->tc_tx_packets
[i
]);
739 i40e_stat_update48(hw
, I40E_GLVEBTC_TBCH(i
, idx
),
740 I40E_GLVEBTC_TBCL(i
, idx
),
741 veb
->stat_offsets_loaded
,
742 &veb_oes
->tc_tx_bytes
[i
],
743 &veb_es
->tc_tx_bytes
[i
]);
745 veb
->stat_offsets_loaded
= true;
750 * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters.
751 * @vsi: the VSI that is capable of doing FCoE
753 static void i40e_update_fcoe_stats(struct i40e_vsi
*vsi
)
755 struct i40e_pf
*pf
= vsi
->back
;
756 struct i40e_hw
*hw
= &pf
->hw
;
757 struct i40e_fcoe_stats
*ofs
;
758 struct i40e_fcoe_stats
*fs
; /* device's eth stats */
761 if (vsi
->type
!= I40E_VSI_FCOE
)
764 idx
= (pf
->pf_seid
- I40E_BASE_PF_SEID
) + I40E_FCOE_PF_STAT_OFFSET
;
765 fs
= &vsi
->fcoe_stats
;
766 ofs
= &vsi
->fcoe_stats_offsets
;
768 i40e_stat_update32(hw
, I40E_GL_FCOEPRC(idx
),
769 vsi
->fcoe_stat_offsets_loaded
,
770 &ofs
->rx_fcoe_packets
, &fs
->rx_fcoe_packets
);
771 i40e_stat_update48(hw
, I40E_GL_FCOEDWRCH(idx
), I40E_GL_FCOEDWRCL(idx
),
772 vsi
->fcoe_stat_offsets_loaded
,
773 &ofs
->rx_fcoe_dwords
, &fs
->rx_fcoe_dwords
);
774 i40e_stat_update32(hw
, I40E_GL_FCOERPDC(idx
),
775 vsi
->fcoe_stat_offsets_loaded
,
776 &ofs
->rx_fcoe_dropped
, &fs
->rx_fcoe_dropped
);
777 i40e_stat_update32(hw
, I40E_GL_FCOEPTC(idx
),
778 vsi
->fcoe_stat_offsets_loaded
,
779 &ofs
->tx_fcoe_packets
, &fs
->tx_fcoe_packets
);
780 i40e_stat_update48(hw
, I40E_GL_FCOEDWTCH(idx
), I40E_GL_FCOEDWTCL(idx
),
781 vsi
->fcoe_stat_offsets_loaded
,
782 &ofs
->tx_fcoe_dwords
, &fs
->tx_fcoe_dwords
);
783 i40e_stat_update32(hw
, I40E_GL_FCOECRC(idx
),
784 vsi
->fcoe_stat_offsets_loaded
,
785 &ofs
->fcoe_bad_fccrc
, &fs
->fcoe_bad_fccrc
);
786 i40e_stat_update32(hw
, I40E_GL_FCOELAST(idx
),
787 vsi
->fcoe_stat_offsets_loaded
,
788 &ofs
->fcoe_last_error
, &fs
->fcoe_last_error
);
789 i40e_stat_update32(hw
, I40E_GL_FCOEDDPC(idx
),
790 vsi
->fcoe_stat_offsets_loaded
,
791 &ofs
->fcoe_ddp_count
, &fs
->fcoe_ddp_count
);
793 vsi
->fcoe_stat_offsets_loaded
= true;
798 * i40e_update_vsi_stats - Update the vsi statistics counters.
799 * @vsi: the VSI to be updated
801 * There are a few instances where we store the same stat in a
802 * couple of different structs. This is partly because we have
803 * the netdev stats that need to be filled out, which is slightly
804 * different from the "eth_stats" defined by the chip and used in
805 * VF communications. We sort it out here.
807 static void i40e_update_vsi_stats(struct i40e_vsi
*vsi
)
809 struct i40e_pf
*pf
= vsi
->back
;
810 struct rtnl_link_stats64
*ons
;
811 struct rtnl_link_stats64
*ns
; /* netdev stats */
812 struct i40e_eth_stats
*oes
;
813 struct i40e_eth_stats
*es
; /* device's eth stats */
814 u32 tx_restart
, tx_busy
;
825 if (test_bit(__I40E_DOWN
, &vsi
->state
) ||
826 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
829 ns
= i40e_get_vsi_stats_struct(vsi
);
830 ons
= &vsi
->net_stats_offsets
;
831 es
= &vsi
->eth_stats
;
832 oes
= &vsi
->eth_stats_offsets
;
834 /* Gather up the netdev and vsi stats that the driver collects
835 * on the fly during packet processing
839 tx_restart
= tx_busy
= tx_linearize
= tx_force_wb
= 0;
843 for (q
= 0; q
< vsi
->num_queue_pairs
; q
++) {
845 p
= ACCESS_ONCE(vsi
->tx_rings
[q
]);
848 start
= u64_stats_fetch_begin_irq(&p
->syncp
);
849 packets
= p
->stats
.packets
;
850 bytes
= p
->stats
.bytes
;
851 } while (u64_stats_fetch_retry_irq(&p
->syncp
, start
));
854 tx_restart
+= p
->tx_stats
.restart_queue
;
855 tx_busy
+= p
->tx_stats
.tx_busy
;
856 tx_linearize
+= p
->tx_stats
.tx_linearize
;
857 tx_force_wb
+= p
->tx_stats
.tx_force_wb
;
859 /* Rx queue is part of the same block as Tx queue */
862 start
= u64_stats_fetch_begin_irq(&p
->syncp
);
863 packets
= p
->stats
.packets
;
864 bytes
= p
->stats
.bytes
;
865 } while (u64_stats_fetch_retry_irq(&p
->syncp
, start
));
868 rx_buf
+= p
->rx_stats
.alloc_buff_failed
;
869 rx_page
+= p
->rx_stats
.alloc_page_failed
;
872 vsi
->tx_restart
= tx_restart
;
873 vsi
->tx_busy
= tx_busy
;
874 vsi
->tx_linearize
= tx_linearize
;
875 vsi
->tx_force_wb
= tx_force_wb
;
876 vsi
->rx_page_failed
= rx_page
;
877 vsi
->rx_buf_failed
= rx_buf
;
879 ns
->rx_packets
= rx_p
;
881 ns
->tx_packets
= tx_p
;
884 /* update netdev stats from eth stats */
885 i40e_update_eth_stats(vsi
);
886 ons
->tx_errors
= oes
->tx_errors
;
887 ns
->tx_errors
= es
->tx_errors
;
888 ons
->multicast
= oes
->rx_multicast
;
889 ns
->multicast
= es
->rx_multicast
;
890 ons
->rx_dropped
= oes
->rx_discards
;
891 ns
->rx_dropped
= es
->rx_discards
;
892 ons
->tx_dropped
= oes
->tx_discards
;
893 ns
->tx_dropped
= es
->tx_discards
;
895 /* pull in a couple PF stats if this is the main vsi */
896 if (vsi
== pf
->vsi
[pf
->lan_vsi
]) {
897 ns
->rx_crc_errors
= pf
->stats
.crc_errors
;
898 ns
->rx_errors
= pf
->stats
.crc_errors
+ pf
->stats
.illegal_bytes
;
899 ns
->rx_length_errors
= pf
->stats
.rx_length_errors
;
904 * i40e_update_pf_stats - Update the PF statistics counters.
905 * @pf: the PF to be updated
907 static void i40e_update_pf_stats(struct i40e_pf
*pf
)
909 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
910 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
911 struct i40e_hw
*hw
= &pf
->hw
;
915 i40e_stat_update48(hw
, I40E_GLPRT_GORCH(hw
->port
),
916 I40E_GLPRT_GORCL(hw
->port
),
917 pf
->stat_offsets_loaded
,
918 &osd
->eth
.rx_bytes
, &nsd
->eth
.rx_bytes
);
919 i40e_stat_update48(hw
, I40E_GLPRT_GOTCH(hw
->port
),
920 I40E_GLPRT_GOTCL(hw
->port
),
921 pf
->stat_offsets_loaded
,
922 &osd
->eth
.tx_bytes
, &nsd
->eth
.tx_bytes
);
923 i40e_stat_update32(hw
, I40E_GLPRT_RDPC(hw
->port
),
924 pf
->stat_offsets_loaded
,
925 &osd
->eth
.rx_discards
,
926 &nsd
->eth
.rx_discards
);
927 i40e_stat_update48(hw
, I40E_GLPRT_UPRCH(hw
->port
),
928 I40E_GLPRT_UPRCL(hw
->port
),
929 pf
->stat_offsets_loaded
,
930 &osd
->eth
.rx_unicast
,
931 &nsd
->eth
.rx_unicast
);
932 i40e_stat_update48(hw
, I40E_GLPRT_MPRCH(hw
->port
),
933 I40E_GLPRT_MPRCL(hw
->port
),
934 pf
->stat_offsets_loaded
,
935 &osd
->eth
.rx_multicast
,
936 &nsd
->eth
.rx_multicast
);
937 i40e_stat_update48(hw
, I40E_GLPRT_BPRCH(hw
->port
),
938 I40E_GLPRT_BPRCL(hw
->port
),
939 pf
->stat_offsets_loaded
,
940 &osd
->eth
.rx_broadcast
,
941 &nsd
->eth
.rx_broadcast
);
942 i40e_stat_update48(hw
, I40E_GLPRT_UPTCH(hw
->port
),
943 I40E_GLPRT_UPTCL(hw
->port
),
944 pf
->stat_offsets_loaded
,
945 &osd
->eth
.tx_unicast
,
946 &nsd
->eth
.tx_unicast
);
947 i40e_stat_update48(hw
, I40E_GLPRT_MPTCH(hw
->port
),
948 I40E_GLPRT_MPTCL(hw
->port
),
949 pf
->stat_offsets_loaded
,
950 &osd
->eth
.tx_multicast
,
951 &nsd
->eth
.tx_multicast
);
952 i40e_stat_update48(hw
, I40E_GLPRT_BPTCH(hw
->port
),
953 I40E_GLPRT_BPTCL(hw
->port
),
954 pf
->stat_offsets_loaded
,
955 &osd
->eth
.tx_broadcast
,
956 &nsd
->eth
.tx_broadcast
);
958 i40e_stat_update32(hw
, I40E_GLPRT_TDOLD(hw
->port
),
959 pf
->stat_offsets_loaded
,
960 &osd
->tx_dropped_link_down
,
961 &nsd
->tx_dropped_link_down
);
963 i40e_stat_update32(hw
, I40E_GLPRT_CRCERRS(hw
->port
),
964 pf
->stat_offsets_loaded
,
965 &osd
->crc_errors
, &nsd
->crc_errors
);
967 i40e_stat_update32(hw
, I40E_GLPRT_ILLERRC(hw
->port
),
968 pf
->stat_offsets_loaded
,
969 &osd
->illegal_bytes
, &nsd
->illegal_bytes
);
971 i40e_stat_update32(hw
, I40E_GLPRT_MLFC(hw
->port
),
972 pf
->stat_offsets_loaded
,
973 &osd
->mac_local_faults
,
974 &nsd
->mac_local_faults
);
975 i40e_stat_update32(hw
, I40E_GLPRT_MRFC(hw
->port
),
976 pf
->stat_offsets_loaded
,
977 &osd
->mac_remote_faults
,
978 &nsd
->mac_remote_faults
);
980 i40e_stat_update32(hw
, I40E_GLPRT_RLEC(hw
->port
),
981 pf
->stat_offsets_loaded
,
982 &osd
->rx_length_errors
,
983 &nsd
->rx_length_errors
);
985 i40e_stat_update32(hw
, I40E_GLPRT_LXONRXC(hw
->port
),
986 pf
->stat_offsets_loaded
,
987 &osd
->link_xon_rx
, &nsd
->link_xon_rx
);
988 i40e_stat_update32(hw
, I40E_GLPRT_LXONTXC(hw
->port
),
989 pf
->stat_offsets_loaded
,
990 &osd
->link_xon_tx
, &nsd
->link_xon_tx
);
991 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFRXC(hw
->port
),
992 pf
->stat_offsets_loaded
,
993 &osd
->link_xoff_rx
, &nsd
->link_xoff_rx
);
994 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFTXC(hw
->port
),
995 pf
->stat_offsets_loaded
,
996 &osd
->link_xoff_tx
, &nsd
->link_xoff_tx
);
998 for (i
= 0; i
< 8; i
++) {
999 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFRXC(hw
->port
, i
),
1000 pf
->stat_offsets_loaded
,
1001 &osd
->priority_xoff_rx
[i
],
1002 &nsd
->priority_xoff_rx
[i
]);
1003 i40e_stat_update32(hw
, I40E_GLPRT_PXONRXC(hw
->port
, i
),
1004 pf
->stat_offsets_loaded
,
1005 &osd
->priority_xon_rx
[i
],
1006 &nsd
->priority_xon_rx
[i
]);
1007 i40e_stat_update32(hw
, I40E_GLPRT_PXONTXC(hw
->port
, i
),
1008 pf
->stat_offsets_loaded
,
1009 &osd
->priority_xon_tx
[i
],
1010 &nsd
->priority_xon_tx
[i
]);
1011 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFTXC(hw
->port
, i
),
1012 pf
->stat_offsets_loaded
,
1013 &osd
->priority_xoff_tx
[i
],
1014 &nsd
->priority_xoff_tx
[i
]);
1015 i40e_stat_update32(hw
,
1016 I40E_GLPRT_RXON2OFFCNT(hw
->port
, i
),
1017 pf
->stat_offsets_loaded
,
1018 &osd
->priority_xon_2_xoff
[i
],
1019 &nsd
->priority_xon_2_xoff
[i
]);
1022 i40e_stat_update48(hw
, I40E_GLPRT_PRC64H(hw
->port
),
1023 I40E_GLPRT_PRC64L(hw
->port
),
1024 pf
->stat_offsets_loaded
,
1025 &osd
->rx_size_64
, &nsd
->rx_size_64
);
1026 i40e_stat_update48(hw
, I40E_GLPRT_PRC127H(hw
->port
),
1027 I40E_GLPRT_PRC127L(hw
->port
),
1028 pf
->stat_offsets_loaded
,
1029 &osd
->rx_size_127
, &nsd
->rx_size_127
);
1030 i40e_stat_update48(hw
, I40E_GLPRT_PRC255H(hw
->port
),
1031 I40E_GLPRT_PRC255L(hw
->port
),
1032 pf
->stat_offsets_loaded
,
1033 &osd
->rx_size_255
, &nsd
->rx_size_255
);
1034 i40e_stat_update48(hw
, I40E_GLPRT_PRC511H(hw
->port
),
1035 I40E_GLPRT_PRC511L(hw
->port
),
1036 pf
->stat_offsets_loaded
,
1037 &osd
->rx_size_511
, &nsd
->rx_size_511
);
1038 i40e_stat_update48(hw
, I40E_GLPRT_PRC1023H(hw
->port
),
1039 I40E_GLPRT_PRC1023L(hw
->port
),
1040 pf
->stat_offsets_loaded
,
1041 &osd
->rx_size_1023
, &nsd
->rx_size_1023
);
1042 i40e_stat_update48(hw
, I40E_GLPRT_PRC1522H(hw
->port
),
1043 I40E_GLPRT_PRC1522L(hw
->port
),
1044 pf
->stat_offsets_loaded
,
1045 &osd
->rx_size_1522
, &nsd
->rx_size_1522
);
1046 i40e_stat_update48(hw
, I40E_GLPRT_PRC9522H(hw
->port
),
1047 I40E_GLPRT_PRC9522L(hw
->port
),
1048 pf
->stat_offsets_loaded
,
1049 &osd
->rx_size_big
, &nsd
->rx_size_big
);
1051 i40e_stat_update48(hw
, I40E_GLPRT_PTC64H(hw
->port
),
1052 I40E_GLPRT_PTC64L(hw
->port
),
1053 pf
->stat_offsets_loaded
,
1054 &osd
->tx_size_64
, &nsd
->tx_size_64
);
1055 i40e_stat_update48(hw
, I40E_GLPRT_PTC127H(hw
->port
),
1056 I40E_GLPRT_PTC127L(hw
->port
),
1057 pf
->stat_offsets_loaded
,
1058 &osd
->tx_size_127
, &nsd
->tx_size_127
);
1059 i40e_stat_update48(hw
, I40E_GLPRT_PTC255H(hw
->port
),
1060 I40E_GLPRT_PTC255L(hw
->port
),
1061 pf
->stat_offsets_loaded
,
1062 &osd
->tx_size_255
, &nsd
->tx_size_255
);
1063 i40e_stat_update48(hw
, I40E_GLPRT_PTC511H(hw
->port
),
1064 I40E_GLPRT_PTC511L(hw
->port
),
1065 pf
->stat_offsets_loaded
,
1066 &osd
->tx_size_511
, &nsd
->tx_size_511
);
1067 i40e_stat_update48(hw
, I40E_GLPRT_PTC1023H(hw
->port
),
1068 I40E_GLPRT_PTC1023L(hw
->port
),
1069 pf
->stat_offsets_loaded
,
1070 &osd
->tx_size_1023
, &nsd
->tx_size_1023
);
1071 i40e_stat_update48(hw
, I40E_GLPRT_PTC1522H(hw
->port
),
1072 I40E_GLPRT_PTC1522L(hw
->port
),
1073 pf
->stat_offsets_loaded
,
1074 &osd
->tx_size_1522
, &nsd
->tx_size_1522
);
1075 i40e_stat_update48(hw
, I40E_GLPRT_PTC9522H(hw
->port
),
1076 I40E_GLPRT_PTC9522L(hw
->port
),
1077 pf
->stat_offsets_loaded
,
1078 &osd
->tx_size_big
, &nsd
->tx_size_big
);
1080 i40e_stat_update32(hw
, I40E_GLPRT_RUC(hw
->port
),
1081 pf
->stat_offsets_loaded
,
1082 &osd
->rx_undersize
, &nsd
->rx_undersize
);
1083 i40e_stat_update32(hw
, I40E_GLPRT_RFC(hw
->port
),
1084 pf
->stat_offsets_loaded
,
1085 &osd
->rx_fragments
, &nsd
->rx_fragments
);
1086 i40e_stat_update32(hw
, I40E_GLPRT_ROC(hw
->port
),
1087 pf
->stat_offsets_loaded
,
1088 &osd
->rx_oversize
, &nsd
->rx_oversize
);
1089 i40e_stat_update32(hw
, I40E_GLPRT_RJC(hw
->port
),
1090 pf
->stat_offsets_loaded
,
1091 &osd
->rx_jabber
, &nsd
->rx_jabber
);
1094 i40e_stat_update32(hw
,
1095 I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf
->hw
.pf_id
)),
1096 pf
->stat_offsets_loaded
,
1097 &osd
->fd_atr_match
, &nsd
->fd_atr_match
);
1098 i40e_stat_update32(hw
,
1099 I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf
->hw
.pf_id
)),
1100 pf
->stat_offsets_loaded
,
1101 &osd
->fd_sb_match
, &nsd
->fd_sb_match
);
1102 i40e_stat_update32(hw
,
1103 I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf
->hw
.pf_id
)),
1104 pf
->stat_offsets_loaded
,
1105 &osd
->fd_atr_tunnel_match
, &nsd
->fd_atr_tunnel_match
);
1107 val
= rd32(hw
, I40E_PRTPM_EEE_STAT
);
1108 nsd
->tx_lpi_status
=
1109 (val
& I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK
) >>
1110 I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT
;
1111 nsd
->rx_lpi_status
=
1112 (val
& I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK
) >>
1113 I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT
;
1114 i40e_stat_update32(hw
, I40E_PRTPM_TLPIC
,
1115 pf
->stat_offsets_loaded
,
1116 &osd
->tx_lpi_count
, &nsd
->tx_lpi_count
);
1117 i40e_stat_update32(hw
, I40E_PRTPM_RLPIC
,
1118 pf
->stat_offsets_loaded
,
1119 &osd
->rx_lpi_count
, &nsd
->rx_lpi_count
);
1121 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
&&
1122 !(pf
->auto_disable_flags
& I40E_FLAG_FD_SB_ENABLED
))
1123 nsd
->fd_sb_status
= true;
1125 nsd
->fd_sb_status
= false;
1127 if (pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
&&
1128 !(pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
))
1129 nsd
->fd_atr_status
= true;
1131 nsd
->fd_atr_status
= false;
1133 pf
->stat_offsets_loaded
= true;
1137 * i40e_update_stats - Update the various statistics counters.
1138 * @vsi: the VSI to be updated
1140 * Update the various stats for this VSI and its related entities.
1142 void i40e_update_stats(struct i40e_vsi
*vsi
)
1144 struct i40e_pf
*pf
= vsi
->back
;
1146 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
1147 i40e_update_pf_stats(pf
);
1149 i40e_update_vsi_stats(vsi
);
1151 i40e_update_fcoe_stats(vsi
);
1156 * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
1157 * @vsi: the VSI to be searched
1158 * @macaddr: the MAC address
1160 * @is_vf: make sure its a VF filter, else doesn't matter
1161 * @is_netdev: make sure its a netdev filter, else doesn't matter
1163 * Returns ptr to the filter object or NULL
1165 static struct i40e_mac_filter
*i40e_find_filter(struct i40e_vsi
*vsi
,
1166 u8
*macaddr
, s16 vlan
,
1167 bool is_vf
, bool is_netdev
)
1169 struct i40e_mac_filter
*f
;
1171 if (!vsi
|| !macaddr
)
1174 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1175 if ((ether_addr_equal(macaddr
, f
->macaddr
)) &&
1176 (vlan
== f
->vlan
) &&
1177 (!is_vf
|| f
->is_vf
) &&
1178 (!is_netdev
|| f
->is_netdev
))
1185 * i40e_find_mac - Find a mac addr in the macvlan filters list
1186 * @vsi: the VSI to be searched
1187 * @macaddr: the MAC address we are searching for
1188 * @is_vf: make sure its a VF filter, else doesn't matter
1189 * @is_netdev: make sure its a netdev filter, else doesn't matter
1191 * Returns the first filter with the provided MAC address or NULL if
1192 * MAC address was not found
1194 struct i40e_mac_filter
*i40e_find_mac(struct i40e_vsi
*vsi
, u8
*macaddr
,
1195 bool is_vf
, bool is_netdev
)
1197 struct i40e_mac_filter
*f
;
1199 if (!vsi
|| !macaddr
)
1202 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1203 if ((ether_addr_equal(macaddr
, f
->macaddr
)) &&
1204 (!is_vf
|| f
->is_vf
) &&
1205 (!is_netdev
|| f
->is_netdev
))
1212 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1213 * @vsi: the VSI to be searched
1215 * Returns true if VSI is in vlan mode or false otherwise
1217 bool i40e_is_vsi_in_vlan(struct i40e_vsi
*vsi
)
1219 struct i40e_mac_filter
*f
;
1221 /* Only -1 for all the filters denotes not in vlan mode
1222 * so we have to go through all the list in order to make sure
1224 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1225 if (f
->vlan
>= 0 || vsi
->info
.pvid
)
1233 * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
1234 * @vsi: the VSI to be searched
1235 * @macaddr: the mac address to be filtered
1236 * @is_vf: true if it is a VF
1237 * @is_netdev: true if it is a netdev
1239 * Goes through all the macvlan filters and adds a
1240 * macvlan filter for each unique vlan that already exists
1242 * Returns first filter found on success, else NULL
1244 struct i40e_mac_filter
*i40e_put_mac_in_vlan(struct i40e_vsi
*vsi
, u8
*macaddr
,
1245 bool is_vf
, bool is_netdev
)
1247 struct i40e_mac_filter
*f
;
1249 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1251 f
->vlan
= le16_to_cpu(vsi
->info
.pvid
);
1252 if (!i40e_find_filter(vsi
, macaddr
, f
->vlan
,
1253 is_vf
, is_netdev
)) {
1254 if (!i40e_add_filter(vsi
, macaddr
, f
->vlan
,
1260 return list_first_entry_or_null(&vsi
->mac_filter_list
,
1261 struct i40e_mac_filter
, list
);
1265 * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS
1266 * @vsi: the VSI to be searched
1267 * @macaddr: the mac address to be removed
1268 * @is_vf: true if it is a VF
1269 * @is_netdev: true if it is a netdev
1271 * Removes a given MAC address from a VSI, regardless of VLAN
1273 * Returns 0 for success, or error
1275 int i40e_del_mac_all_vlan(struct i40e_vsi
*vsi
, u8
*macaddr
,
1276 bool is_vf
, bool is_netdev
)
1278 struct i40e_mac_filter
*f
= NULL
;
1281 WARN(!spin_is_locked(&vsi
->mac_filter_list_lock
),
1282 "Missing mac_filter_list_lock\n");
1283 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1284 if ((ether_addr_equal(macaddr
, f
->macaddr
)) &&
1285 (is_vf
== f
->is_vf
) &&
1286 (is_netdev
== f
->is_netdev
)) {
1293 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1294 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1301 * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
1302 * @vsi: the PF Main VSI - inappropriate for any other VSI
1303 * @macaddr: the MAC address
1305 * Some older firmware configurations set up a default promiscuous VLAN
1306 * filter that needs to be removed.
1308 static int i40e_rm_default_mac_filter(struct i40e_vsi
*vsi
, u8
*macaddr
)
1310 struct i40e_aqc_remove_macvlan_element_data element
;
1311 struct i40e_pf
*pf
= vsi
->back
;
1314 /* Only appropriate for the PF main VSI */
1315 if (vsi
->type
!= I40E_VSI_MAIN
)
1318 memset(&element
, 0, sizeof(element
));
1319 ether_addr_copy(element
.mac_addr
, macaddr
);
1320 element
.vlan_tag
= 0;
1321 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
|
1322 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
1323 ret
= i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1331 * i40e_add_filter - Add a mac/vlan filter to the VSI
1332 * @vsi: the VSI to be searched
1333 * @macaddr: the MAC address
1335 * @is_vf: make sure its a VF filter, else doesn't matter
1336 * @is_netdev: make sure its a netdev filter, else doesn't matter
1338 * Returns ptr to the filter object or NULL when no memory available.
1340 * NOTE: This function is expected to be called with mac_filter_list_lock
1343 struct i40e_mac_filter
*i40e_add_filter(struct i40e_vsi
*vsi
,
1344 u8
*macaddr
, s16 vlan
,
1345 bool is_vf
, bool is_netdev
)
1347 struct i40e_mac_filter
*f
;
1349 if (!vsi
|| !macaddr
)
1352 f
= i40e_find_filter(vsi
, macaddr
, vlan
, is_vf
, is_netdev
);
1354 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
1356 goto add_filter_out
;
1358 ether_addr_copy(f
->macaddr
, macaddr
);
1362 INIT_LIST_HEAD(&f
->list
);
1363 list_add(&f
->list
, &vsi
->mac_filter_list
);
1366 /* increment counter and add a new flag if needed */
1372 } else if (is_netdev
) {
1373 if (!f
->is_netdev
) {
1374 f
->is_netdev
= true;
1381 /* changed tells sync_filters_subtask to
1382 * push the filter down to the firmware
1385 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1386 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1394 * i40e_del_filter - Remove a mac/vlan filter from the VSI
1395 * @vsi: the VSI to be searched
1396 * @macaddr: the MAC address
1398 * @is_vf: make sure it's a VF filter, else doesn't matter
1399 * @is_netdev: make sure it's a netdev filter, else doesn't matter
1401 * NOTE: This function is expected to be called with mac_filter_list_lock
1404 void i40e_del_filter(struct i40e_vsi
*vsi
,
1405 u8
*macaddr
, s16 vlan
,
1406 bool is_vf
, bool is_netdev
)
1408 struct i40e_mac_filter
*f
;
1410 if (!vsi
|| !macaddr
)
1413 f
= i40e_find_filter(vsi
, macaddr
, vlan
, is_vf
, is_netdev
);
1414 if (!f
|| f
->counter
== 0)
1422 } else if (is_netdev
) {
1424 f
->is_netdev
= false;
1428 /* make sure we don't remove a filter in use by VF or netdev */
1431 min_f
+= (f
->is_vf
? 1 : 0);
1432 min_f
+= (f
->is_netdev
? 1 : 0);
1434 if (f
->counter
> min_f
)
1438 /* counter == 0 tells sync_filters_subtask to
1439 * remove the filter from the firmware's list
1441 if (f
->counter
== 0) {
1443 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1444 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1449 * i40e_set_mac - NDO callback to set mac address
1450 * @netdev: network interface device structure
1451 * @p: pointer to an address structure
1453 * Returns 0 on success, negative on failure
1456 int i40e_set_mac(struct net_device
*netdev
, void *p
)
1458 static int i40e_set_mac(struct net_device
*netdev
, void *p
)
1461 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1462 struct i40e_vsi
*vsi
= np
->vsi
;
1463 struct i40e_pf
*pf
= vsi
->back
;
1464 struct i40e_hw
*hw
= &pf
->hw
;
1465 struct sockaddr
*addr
= p
;
1466 struct i40e_mac_filter
*f
;
1468 if (!is_valid_ether_addr(addr
->sa_data
))
1469 return -EADDRNOTAVAIL
;
1471 if (ether_addr_equal(netdev
->dev_addr
, addr
->sa_data
)) {
1472 netdev_info(netdev
, "already using mac address %pM\n",
1477 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
1478 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
1479 return -EADDRNOTAVAIL
;
1481 if (ether_addr_equal(hw
->mac
.addr
, addr
->sa_data
))
1482 netdev_info(netdev
, "returning to hw mac address %pM\n",
1485 netdev_info(netdev
, "set new mac address %pM\n", addr
->sa_data
);
1487 if (vsi
->type
== I40E_VSI_MAIN
) {
1490 ret
= i40e_aq_mac_address_write(&vsi
->back
->hw
,
1491 I40E_AQC_WRITE_TYPE_LAA_WOL
,
1492 addr
->sa_data
, NULL
);
1495 "Addr change for Main VSI failed: %d\n",
1497 return -EADDRNOTAVAIL
;
1501 if (ether_addr_equal(netdev
->dev_addr
, hw
->mac
.addr
)) {
1502 struct i40e_aqc_remove_macvlan_element_data element
;
1504 memset(&element
, 0, sizeof(element
));
1505 ether_addr_copy(element
.mac_addr
, netdev
->dev_addr
);
1506 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
1507 i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1509 spin_lock_bh(&vsi
->mac_filter_list_lock
);
1510 i40e_del_filter(vsi
, netdev
->dev_addr
, I40E_VLAN_ANY
,
1512 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
1515 if (ether_addr_equal(addr
->sa_data
, hw
->mac
.addr
)) {
1516 struct i40e_aqc_add_macvlan_element_data element
;
1518 memset(&element
, 0, sizeof(element
));
1519 ether_addr_copy(element
.mac_addr
, hw
->mac
.addr
);
1520 element
.flags
= cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
);
1521 i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1523 spin_lock_bh(&vsi
->mac_filter_list_lock
);
1524 f
= i40e_add_filter(vsi
, addr
->sa_data
, I40E_VLAN_ANY
,
1528 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
1531 ether_addr_copy(netdev
->dev_addr
, addr
->sa_data
);
1533 return i40e_sync_vsi_filters(vsi
);
1537 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1538 * @vsi: the VSI being setup
1539 * @ctxt: VSI context structure
1540 * @enabled_tc: Enabled TCs bitmap
1541 * @is_add: True if called before Add VSI
1543 * Setup VSI queue mapping for enabled traffic classes.
1546 void i40e_vsi_setup_queue_map(struct i40e_vsi
*vsi
,
1547 struct i40e_vsi_context
*ctxt
,
1551 static void i40e_vsi_setup_queue_map(struct i40e_vsi
*vsi
,
1552 struct i40e_vsi_context
*ctxt
,
1557 struct i40e_pf
*pf
= vsi
->back
;
1567 sections
= I40E_AQ_VSI_PROP_QUEUE_MAP_VALID
;
1570 if (enabled_tc
&& (vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
1571 /* Find numtc from enabled TC bitmap */
1572 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1573 if (enabled_tc
& BIT(i
)) /* TC is enabled */
1577 dev_warn(&pf
->pdev
->dev
, "DCB is enabled but no TC enabled, forcing TC0\n");
1581 /* At least TC0 is enabled in case of non-DCB case */
1585 vsi
->tc_config
.numtc
= numtc
;
1586 vsi
->tc_config
.enabled_tc
= enabled_tc
? enabled_tc
: 1;
1587 /* Number of queues per enabled TC */
1588 /* In MFP case we can have a much lower count of MSIx
1589 * vectors available and so we need to lower the used
1592 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
1593 qcount
= min_t(int, vsi
->alloc_queue_pairs
, pf
->num_lan_msix
);
1595 qcount
= vsi
->alloc_queue_pairs
;
1596 num_tc_qps
= qcount
/ numtc
;
1597 num_tc_qps
= min_t(int, num_tc_qps
, i40e_pf_get_max_q_per_tc(pf
));
1599 /* Setup queue offset/count for all TCs for given VSI */
1600 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1601 /* See if the given TC is enabled for the given VSI */
1602 if (vsi
->tc_config
.enabled_tc
& BIT(i
)) {
1606 switch (vsi
->type
) {
1608 qcount
= min_t(int, pf
->alloc_rss_size
,
1613 qcount
= num_tc_qps
;
1617 case I40E_VSI_SRIOV
:
1618 case I40E_VSI_VMDQ2
:
1620 qcount
= num_tc_qps
;
1624 vsi
->tc_config
.tc_info
[i
].qoffset
= offset
;
1625 vsi
->tc_config
.tc_info
[i
].qcount
= qcount
;
1627 /* find the next higher power-of-2 of num queue pairs */
1630 while (num_qps
&& (BIT_ULL(pow
) < qcount
)) {
1635 vsi
->tc_config
.tc_info
[i
].netdev_tc
= netdev_tc
++;
1637 (offset
<< I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT
) |
1638 (pow
<< I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT
);
1642 /* TC is not enabled so set the offset to
1643 * default queue and allocate one queue
1646 vsi
->tc_config
.tc_info
[i
].qoffset
= 0;
1647 vsi
->tc_config
.tc_info
[i
].qcount
= 1;
1648 vsi
->tc_config
.tc_info
[i
].netdev_tc
= 0;
1652 ctxt
->info
.tc_mapping
[i
] = cpu_to_le16(qmap
);
1655 /* Set actual Tx/Rx queue pairs */
1656 vsi
->num_queue_pairs
= offset
;
1657 if ((vsi
->type
== I40E_VSI_MAIN
) && (numtc
== 1)) {
1658 if (vsi
->req_queue_pairs
> 0)
1659 vsi
->num_queue_pairs
= vsi
->req_queue_pairs
;
1660 else if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
1661 vsi
->num_queue_pairs
= pf
->num_lan_msix
;
1664 /* Scheduler section valid can only be set for ADD VSI */
1666 sections
|= I40E_AQ_VSI_PROP_SCHED_VALID
;
1668 ctxt
->info
.up_enable_bits
= enabled_tc
;
1670 if (vsi
->type
== I40E_VSI_SRIOV
) {
1671 ctxt
->info
.mapping_flags
|=
1672 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG
);
1673 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
1674 ctxt
->info
.queue_mapping
[i
] =
1675 cpu_to_le16(vsi
->base_queue
+ i
);
1677 ctxt
->info
.mapping_flags
|=
1678 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG
);
1679 ctxt
->info
.queue_mapping
[0] = cpu_to_le16(vsi
->base_queue
);
1681 ctxt
->info
.valid_sections
|= cpu_to_le16(sections
);
1685 * i40e_set_rx_mode - NDO callback to set the netdev filters
1686 * @netdev: network interface device structure
1689 void i40e_set_rx_mode(struct net_device
*netdev
)
1691 static void i40e_set_rx_mode(struct net_device
*netdev
)
1694 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1695 struct i40e_mac_filter
*f
, *ftmp
;
1696 struct i40e_vsi
*vsi
= np
->vsi
;
1697 struct netdev_hw_addr
*uca
;
1698 struct netdev_hw_addr
*mca
;
1699 struct netdev_hw_addr
*ha
;
1701 spin_lock_bh(&vsi
->mac_filter_list_lock
);
1703 /* add addr if not already in the filter list */
1704 netdev_for_each_uc_addr(uca
, netdev
) {
1705 if (!i40e_find_mac(vsi
, uca
->addr
, false, true)) {
1706 if (i40e_is_vsi_in_vlan(vsi
))
1707 i40e_put_mac_in_vlan(vsi
, uca
->addr
,
1710 i40e_add_filter(vsi
, uca
->addr
, I40E_VLAN_ANY
,
1715 netdev_for_each_mc_addr(mca
, netdev
) {
1716 if (!i40e_find_mac(vsi
, mca
->addr
, false, true)) {
1717 if (i40e_is_vsi_in_vlan(vsi
))
1718 i40e_put_mac_in_vlan(vsi
, mca
->addr
,
1721 i40e_add_filter(vsi
, mca
->addr
, I40E_VLAN_ANY
,
1726 /* remove filter if not in netdev list */
1727 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1732 netdev_for_each_mc_addr(mca
, netdev
)
1733 if (ether_addr_equal(mca
->addr
, f
->macaddr
))
1734 goto bottom_of_search_loop
;
1736 netdev_for_each_uc_addr(uca
, netdev
)
1737 if (ether_addr_equal(uca
->addr
, f
->macaddr
))
1738 goto bottom_of_search_loop
;
1740 for_each_dev_addr(netdev
, ha
)
1741 if (ether_addr_equal(ha
->addr
, f
->macaddr
))
1742 goto bottom_of_search_loop
;
1744 /* f->macaddr wasn't found in uc, mc, or ha list so delete it */
1745 i40e_del_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
, false, true);
1747 bottom_of_search_loop
:
1750 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
1752 /* check for other flag changes */
1753 if (vsi
->current_netdev_flags
!= vsi
->netdev
->flags
) {
1754 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1755 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1760 * i40e_mac_filter_entry_clone - Clones a MAC filter entry
1761 * @src: source MAC filter entry to be clones
1763 * Returns the pointer to newly cloned MAC filter entry or NULL
1766 static struct i40e_mac_filter
*i40e_mac_filter_entry_clone(
1767 struct i40e_mac_filter
*src
)
1769 struct i40e_mac_filter
*f
;
1771 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
1776 INIT_LIST_HEAD(&f
->list
);
1782 * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
1783 * @vsi: pointer to vsi struct
1784 * @from: Pointer to list which contains MAC filter entries - changes to
1785 * those entries needs to be undone.
1787 * MAC filter entries from list were slated to be removed from device.
1789 static void i40e_undo_del_filter_entries(struct i40e_vsi
*vsi
,
1790 struct list_head
*from
)
1792 struct i40e_mac_filter
*f
, *ftmp
;
1794 list_for_each_entry_safe(f
, ftmp
, from
, list
) {
1796 /* Move the element back into MAC filter list*/
1797 list_move_tail(&f
->list
, &vsi
->mac_filter_list
);
1802 * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries
1803 * @vsi: pointer to vsi struct
1805 * MAC filter entries from list were slated to be added from device.
1807 static void i40e_undo_add_filter_entries(struct i40e_vsi
*vsi
)
1809 struct i40e_mac_filter
*f
, *ftmp
;
1811 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1812 if (!f
->changed
&& f
->counter
)
1818 * i40e_cleanup_add_list - Deletes the element from add list and release
1820 * @add_list: Pointer to list which contains MAC filter entries
1822 static void i40e_cleanup_add_list(struct list_head
*add_list
)
1824 struct i40e_mac_filter
*f
, *ftmp
;
1826 list_for_each_entry_safe(f
, ftmp
, add_list
, list
) {
1833 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
1834 * @vsi: ptr to the VSI
1836 * Push any outstanding VSI filter changes through the AdminQ.
1838 * Returns 0 or error value
1840 int i40e_sync_vsi_filters(struct i40e_vsi
*vsi
)
1842 struct list_head tmp_del_list
, tmp_add_list
;
1843 struct i40e_mac_filter
*f
, *ftmp
, *fclone
;
1844 bool promisc_forced_on
= false;
1845 bool add_happened
= false;
1846 int filter_list_len
= 0;
1847 u32 changed_flags
= 0;
1848 i40e_status aq_ret
= 0;
1849 bool err_cond
= false;
1857 /* empty array typed pointers, kcalloc later */
1858 struct i40e_aqc_add_macvlan_element_data
*add_list
;
1859 struct i40e_aqc_remove_macvlan_element_data
*del_list
;
1861 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &vsi
->state
))
1862 usleep_range(1000, 2000);
1866 changed_flags
= vsi
->current_netdev_flags
^ vsi
->netdev
->flags
;
1867 vsi
->current_netdev_flags
= vsi
->netdev
->flags
;
1870 INIT_LIST_HEAD(&tmp_del_list
);
1871 INIT_LIST_HEAD(&tmp_add_list
);
1873 if (vsi
->flags
& I40E_VSI_FLAG_FILTER_CHANGED
) {
1874 vsi
->flags
&= ~I40E_VSI_FLAG_FILTER_CHANGED
;
1876 spin_lock_bh(&vsi
->mac_filter_list_lock
);
1877 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1881 if (f
->counter
!= 0)
1885 /* Move the element into temporary del_list */
1886 list_move_tail(&f
->list
, &tmp_del_list
);
1889 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1893 if (f
->counter
== 0)
1897 /* Clone MAC filter entry and add into temporary list */
1898 fclone
= i40e_mac_filter_entry_clone(f
);
1903 list_add_tail(&fclone
->list
, &tmp_add_list
);
1906 /* if failed to clone MAC filter entry - undo */
1908 i40e_undo_del_filter_entries(vsi
, &tmp_del_list
);
1909 i40e_undo_add_filter_entries(vsi
);
1911 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
1914 i40e_cleanup_add_list(&tmp_add_list
);
1920 /* Now process 'del_list' outside the lock */
1921 if (!list_empty(&tmp_del_list
)) {
1924 filter_list_len
= pf
->hw
.aq
.asq_buf_size
/
1925 sizeof(struct i40e_aqc_remove_macvlan_element_data
);
1926 del_list_size
= filter_list_len
*
1927 sizeof(struct i40e_aqc_remove_macvlan_element_data
);
1928 del_list
= kzalloc(del_list_size
, GFP_KERNEL
);
1930 i40e_cleanup_add_list(&tmp_add_list
);
1932 /* Undo VSI's MAC filter entry element updates */
1933 spin_lock_bh(&vsi
->mac_filter_list_lock
);
1934 i40e_undo_del_filter_entries(vsi
, &tmp_del_list
);
1935 i40e_undo_add_filter_entries(vsi
);
1936 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
1941 list_for_each_entry_safe(f
, ftmp
, &tmp_del_list
, list
) {
1944 /* add to delete list */
1945 ether_addr_copy(del_list
[num_del
].mac_addr
, f
->macaddr
);
1946 del_list
[num_del
].vlan_tag
=
1947 cpu_to_le16((u16
)(f
->vlan
==
1948 I40E_VLAN_ANY
? 0 : f
->vlan
));
1950 cmd_flags
|= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
1951 del_list
[num_del
].flags
= cmd_flags
;
1954 /* flush a full buffer */
1955 if (num_del
== filter_list_len
) {
1956 aq_ret
= i40e_aq_remove_macvlan(&pf
->hw
,
1961 aq_err
= pf
->hw
.aq
.asq_last_status
;
1963 memset(del_list
, 0, del_list_size
);
1965 if (aq_ret
&& aq_err
!= I40E_AQ_RC_ENOENT
) {
1967 dev_err(&pf
->pdev
->dev
,
1968 "ignoring delete macvlan error, err %s, aq_err %s while flushing a full buffer\n",
1969 i40e_stat_str(&pf
->hw
, aq_ret
),
1970 i40e_aq_str(&pf
->hw
, aq_err
));
1973 /* Release memory for MAC filter entries which were
1974 * synced up with HW.
1981 aq_ret
= i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
,
1984 aq_err
= pf
->hw
.aq
.asq_last_status
;
1987 if (aq_ret
&& aq_err
!= I40E_AQ_RC_ENOENT
)
1988 dev_info(&pf
->pdev
->dev
,
1989 "ignoring delete macvlan error, err %s aq_err %s\n",
1990 i40e_stat_str(&pf
->hw
, aq_ret
),
1991 i40e_aq_str(&pf
->hw
, aq_err
));
1998 if (!list_empty(&tmp_add_list
)) {
2001 /* do all the adds now */
2002 filter_list_len
= pf
->hw
.aq
.asq_buf_size
/
2003 sizeof(struct i40e_aqc_add_macvlan_element_data
),
2004 add_list_size
= filter_list_len
*
2005 sizeof(struct i40e_aqc_add_macvlan_element_data
);
2006 add_list
= kzalloc(add_list_size
, GFP_KERNEL
);
2008 /* Purge element from temporary lists */
2009 i40e_cleanup_add_list(&tmp_add_list
);
2011 /* Undo add filter entries from VSI MAC filter list */
2012 spin_lock_bh(&vsi
->mac_filter_list_lock
);
2013 i40e_undo_add_filter_entries(vsi
);
2014 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2019 list_for_each_entry_safe(f
, ftmp
, &tmp_add_list
, list
) {
2021 add_happened
= true;
2024 /* add to add array */
2025 ether_addr_copy(add_list
[num_add
].mac_addr
, f
->macaddr
);
2026 add_list
[num_add
].vlan_tag
=
2028 (u16
)(f
->vlan
== I40E_VLAN_ANY
? 0 : f
->vlan
));
2029 add_list
[num_add
].queue_number
= 0;
2031 cmd_flags
|= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
;
2032 add_list
[num_add
].flags
= cpu_to_le16(cmd_flags
);
2035 /* flush a full buffer */
2036 if (num_add
== filter_list_len
) {
2037 aq_ret
= i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
,
2040 aq_err
= pf
->hw
.aq
.asq_last_status
;
2045 memset(add_list
, 0, add_list_size
);
2047 /* Entries from tmp_add_list were cloned from MAC
2048 * filter list, hence clean those cloned entries
2055 aq_ret
= i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
,
2056 add_list
, num_add
, NULL
);
2057 aq_err
= pf
->hw
.aq
.asq_last_status
;
2063 if (add_happened
&& aq_ret
&& aq_err
!= I40E_AQ_RC_EINVAL
) {
2064 retval
= i40e_aq_rc_to_posix(aq_ret
, aq_err
);
2065 dev_info(&pf
->pdev
->dev
,
2066 "add filter failed, err %s aq_err %s\n",
2067 i40e_stat_str(&pf
->hw
, aq_ret
),
2068 i40e_aq_str(&pf
->hw
, aq_err
));
2069 if ((pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_ENOSPC
) &&
2070 !test_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
2072 promisc_forced_on
= true;
2073 set_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
2075 dev_info(&pf
->pdev
->dev
, "promiscuous mode forced on\n");
2080 /* check for changes in promiscuous modes */
2081 if (changed_flags
& IFF_ALLMULTI
) {
2082 bool cur_multipromisc
;
2084 cur_multipromisc
= !!(vsi
->current_netdev_flags
& IFF_ALLMULTI
);
2085 aq_ret
= i40e_aq_set_vsi_multicast_promiscuous(&vsi
->back
->hw
,
2090 retval
= i40e_aq_rc_to_posix(aq_ret
,
2091 pf
->hw
.aq
.asq_last_status
);
2092 dev_info(&pf
->pdev
->dev
,
2093 "set multi promisc failed, err %s aq_err %s\n",
2094 i40e_stat_str(&pf
->hw
, aq_ret
),
2095 i40e_aq_str(&pf
->hw
,
2096 pf
->hw
.aq
.asq_last_status
));
2099 if ((changed_flags
& IFF_PROMISC
) || promisc_forced_on
) {
2102 cur_promisc
= (!!(vsi
->current_netdev_flags
& IFF_PROMISC
) ||
2103 test_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
2105 if (vsi
->type
== I40E_VSI_MAIN
&& pf
->lan_veb
!= I40E_NO_VEB
) {
2106 /* set defport ON for Main VSI instead of true promisc
2107 * this way we will get all unicast/multicast and VLAN
2108 * promisc behavior but will not get VF or VMDq traffic
2109 * replicated on the Main VSI.
2111 if (pf
->cur_promisc
!= cur_promisc
) {
2112 pf
->cur_promisc
= cur_promisc
;
2113 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
2116 aq_ret
= i40e_aq_set_vsi_unicast_promiscuous(
2122 i40e_aq_rc_to_posix(aq_ret
,
2123 pf
->hw
.aq
.asq_last_status
);
2124 dev_info(&pf
->pdev
->dev
,
2125 "set unicast promisc failed, err %d, aq_err %d\n",
2126 aq_ret
, pf
->hw
.aq
.asq_last_status
);
2128 aq_ret
= i40e_aq_set_vsi_multicast_promiscuous(
2134 i40e_aq_rc_to_posix(aq_ret
,
2135 pf
->hw
.aq
.asq_last_status
);
2136 dev_info(&pf
->pdev
->dev
,
2137 "set multicast promisc failed, err %d, aq_err %d\n",
2138 aq_ret
, pf
->hw
.aq
.asq_last_status
);
2141 aq_ret
= i40e_aq_set_vsi_broadcast(&vsi
->back
->hw
,
2145 retval
= i40e_aq_rc_to_posix(aq_ret
,
2146 pf
->hw
.aq
.asq_last_status
);
2147 dev_info(&pf
->pdev
->dev
,
2148 "set brdcast promisc failed, err %s, aq_err %s\n",
2149 i40e_stat_str(&pf
->hw
, aq_ret
),
2150 i40e_aq_str(&pf
->hw
,
2151 pf
->hw
.aq
.asq_last_status
));
2155 clear_bit(__I40E_CONFIG_BUSY
, &vsi
->state
);
2160 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
2161 * @pf: board private structure
2163 static void i40e_sync_filters_subtask(struct i40e_pf
*pf
)
2167 if (!pf
|| !(pf
->flags
& I40E_FLAG_FILTER_SYNC
))
2169 pf
->flags
&= ~I40E_FLAG_FILTER_SYNC
;
2171 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
2173 (pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_FILTER_CHANGED
)) {
2174 int ret
= i40e_sync_vsi_filters(pf
->vsi
[v
]);
2177 /* come back and try again later */
2178 pf
->flags
|= I40E_FLAG_FILTER_SYNC
;
2186 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
2187 * @netdev: network interface device structure
2188 * @new_mtu: new value for maximum frame size
2190 * Returns 0 on success, negative on failure
2192 static int i40e_change_mtu(struct net_device
*netdev
, int new_mtu
)
2194 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2195 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
2196 struct i40e_vsi
*vsi
= np
->vsi
;
2198 /* MTU < 68 is an error and causes problems on some kernels */
2199 if ((new_mtu
< 68) || (max_frame
> I40E_MAX_RXBUFFER
))
2202 netdev_info(netdev
, "changing MTU from %d to %d\n",
2203 netdev
->mtu
, new_mtu
);
2204 netdev
->mtu
= new_mtu
;
2205 if (netif_running(netdev
))
2206 i40e_vsi_reinit_locked(vsi
);
2212 * i40e_ioctl - Access the hwtstamp interface
2213 * @netdev: network interface device structure
2214 * @ifr: interface request data
2215 * @cmd: ioctl command
2217 int i40e_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
2219 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2220 struct i40e_pf
*pf
= np
->vsi
->back
;
2224 return i40e_ptp_get_ts_config(pf
, ifr
);
2226 return i40e_ptp_set_ts_config(pf
, ifr
);
2233 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
2234 * @vsi: the vsi being adjusted
2236 void i40e_vlan_stripping_enable(struct i40e_vsi
*vsi
)
2238 struct i40e_vsi_context ctxt
;
2241 if ((vsi
->info
.valid_sections
&
2242 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
2243 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_MODE_MASK
) == 0))
2244 return; /* already enabled */
2246 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2247 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
2248 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH
;
2250 ctxt
.seid
= vsi
->seid
;
2251 ctxt
.info
= vsi
->info
;
2252 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2254 dev_info(&vsi
->back
->pdev
->dev
,
2255 "update vlan stripping failed, err %s aq_err %s\n",
2256 i40e_stat_str(&vsi
->back
->hw
, ret
),
2257 i40e_aq_str(&vsi
->back
->hw
,
2258 vsi
->back
->hw
.aq
.asq_last_status
));
2263 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2264 * @vsi: the vsi being adjusted
2266 void i40e_vlan_stripping_disable(struct i40e_vsi
*vsi
)
2268 struct i40e_vsi_context ctxt
;
2271 if ((vsi
->info
.valid_sections
&
2272 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
2273 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_EMOD_MASK
) ==
2274 I40E_AQ_VSI_PVLAN_EMOD_MASK
))
2275 return; /* already disabled */
2277 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2278 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
2279 I40E_AQ_VSI_PVLAN_EMOD_NOTHING
;
2281 ctxt
.seid
= vsi
->seid
;
2282 ctxt
.info
= vsi
->info
;
2283 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2285 dev_info(&vsi
->back
->pdev
->dev
,
2286 "update vlan stripping failed, err %s aq_err %s\n",
2287 i40e_stat_str(&vsi
->back
->hw
, ret
),
2288 i40e_aq_str(&vsi
->back
->hw
,
2289 vsi
->back
->hw
.aq
.asq_last_status
));
2294 * i40e_vlan_rx_register - Setup or shutdown vlan offload
2295 * @netdev: network interface to be adjusted
2296 * @features: netdev features to test if VLAN offload is enabled or not
2298 static void i40e_vlan_rx_register(struct net_device
*netdev
, u32 features
)
2300 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2301 struct i40e_vsi
*vsi
= np
->vsi
;
2303 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
2304 i40e_vlan_stripping_enable(vsi
);
2306 i40e_vlan_stripping_disable(vsi
);
2310 * i40e_vsi_add_vlan - Add vsi membership for given vlan
2311 * @vsi: the vsi being configured
2312 * @vid: vlan id to be added (0 = untagged only , -1 = any)
2314 int i40e_vsi_add_vlan(struct i40e_vsi
*vsi
, s16 vid
)
2316 struct i40e_mac_filter
*f
, *add_f
;
2317 bool is_netdev
, is_vf
;
2319 is_vf
= (vsi
->type
== I40E_VSI_SRIOV
);
2320 is_netdev
= !!(vsi
->netdev
);
2322 /* Locked once because all functions invoked below iterates list*/
2323 spin_lock_bh(&vsi
->mac_filter_list_lock
);
2326 add_f
= i40e_add_filter(vsi
, vsi
->netdev
->dev_addr
, vid
,
2329 dev_info(&vsi
->back
->pdev
->dev
,
2330 "Could not add vlan filter %d for %pM\n",
2331 vid
, vsi
->netdev
->dev_addr
);
2332 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2337 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2338 add_f
= i40e_add_filter(vsi
, f
->macaddr
, vid
, is_vf
, is_netdev
);
2340 dev_info(&vsi
->back
->pdev
->dev
,
2341 "Could not add vlan filter %d for %pM\n",
2343 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2348 /* Now if we add a vlan tag, make sure to check if it is the first
2349 * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
2350 * with 0, so we now accept untagged and specified tagged traffic
2351 * (and not any taged and untagged)
2354 if (is_netdev
&& i40e_find_filter(vsi
, vsi
->netdev
->dev_addr
,
2356 is_vf
, is_netdev
)) {
2357 i40e_del_filter(vsi
, vsi
->netdev
->dev_addr
,
2358 I40E_VLAN_ANY
, is_vf
, is_netdev
);
2359 add_f
= i40e_add_filter(vsi
, vsi
->netdev
->dev_addr
, 0,
2362 dev_info(&vsi
->back
->pdev
->dev
,
2363 "Could not add filter 0 for %pM\n",
2364 vsi
->netdev
->dev_addr
);
2365 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2371 /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
2372 if (vid
> 0 && !vsi
->info
.pvid
) {
2373 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2374 if (!i40e_find_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2377 i40e_del_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2379 add_f
= i40e_add_filter(vsi
, f
->macaddr
,
2380 0, is_vf
, is_netdev
);
2382 dev_info(&vsi
->back
->pdev
->dev
,
2383 "Could not add filter 0 for %pM\n",
2385 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2391 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2393 /* schedule our worker thread which will take care of
2394 * applying the new filter changes
2396 i40e_service_event_schedule(vsi
->back
);
2401 * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
2402 * @vsi: the vsi being configured
2403 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
2405 * Return: 0 on success or negative otherwise
2407 int i40e_vsi_kill_vlan(struct i40e_vsi
*vsi
, s16 vid
)
2409 struct net_device
*netdev
= vsi
->netdev
;
2410 struct i40e_mac_filter
*f
, *add_f
;
2411 bool is_vf
, is_netdev
;
2412 int filter_count
= 0;
2414 is_vf
= (vsi
->type
== I40E_VSI_SRIOV
);
2415 is_netdev
= !!(netdev
);
2417 /* Locked once because all functions invoked below iterates list */
2418 spin_lock_bh(&vsi
->mac_filter_list_lock
);
2421 i40e_del_filter(vsi
, netdev
->dev_addr
, vid
, is_vf
, is_netdev
);
2423 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
)
2424 i40e_del_filter(vsi
, f
->macaddr
, vid
, is_vf
, is_netdev
);
2426 /* go through all the filters for this VSI and if there is only
2427 * vid == 0 it means there are no other filters, so vid 0 must
2428 * be replaced with -1. This signifies that we should from now
2429 * on accept any traffic (with any tag present, or untagged)
2431 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2434 ether_addr_equal(netdev
->dev_addr
, f
->macaddr
))
2442 if (!filter_count
&& is_netdev
) {
2443 i40e_del_filter(vsi
, netdev
->dev_addr
, 0, is_vf
, is_netdev
);
2444 f
= i40e_add_filter(vsi
, netdev
->dev_addr
, I40E_VLAN_ANY
,
2447 dev_info(&vsi
->back
->pdev
->dev
,
2448 "Could not add filter %d for %pM\n",
2449 I40E_VLAN_ANY
, netdev
->dev_addr
);
2450 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2455 if (!filter_count
) {
2456 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2457 i40e_del_filter(vsi
, f
->macaddr
, 0, is_vf
, is_netdev
);
2458 add_f
= i40e_add_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2461 dev_info(&vsi
->back
->pdev
->dev
,
2462 "Could not add filter %d for %pM\n",
2463 I40E_VLAN_ANY
, f
->macaddr
);
2464 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2470 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2472 /* schedule our worker thread which will take care of
2473 * applying the new filter changes
2475 i40e_service_event_schedule(vsi
->back
);
2480 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2481 * @netdev: network interface to be adjusted
2482 * @vid: vlan id to be added
2484 * net_device_ops implementation for adding vlan ids
2487 int i40e_vlan_rx_add_vid(struct net_device
*netdev
,
2488 __always_unused __be16 proto
, u16 vid
)
2490 static int i40e_vlan_rx_add_vid(struct net_device
*netdev
,
2491 __always_unused __be16 proto
, u16 vid
)
2494 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2495 struct i40e_vsi
*vsi
= np
->vsi
;
2501 netdev_info(netdev
, "adding %pM vid=%d\n", netdev
->dev_addr
, vid
);
2503 /* If the network stack called us with vid = 0 then
2504 * it is asking to receive priority tagged packets with
2505 * vlan id 0. Our HW receives them by default when configured
2506 * to receive untagged packets so there is no need to add an
2507 * extra filter for vlan 0 tagged packets.
2510 ret
= i40e_vsi_add_vlan(vsi
, vid
);
2512 if (!ret
&& (vid
< VLAN_N_VID
))
2513 set_bit(vid
, vsi
->active_vlans
);
2519 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2520 * @netdev: network interface to be adjusted
2521 * @vid: vlan id to be removed
2523 * net_device_ops implementation for removing vlan ids
2526 int i40e_vlan_rx_kill_vid(struct net_device
*netdev
,
2527 __always_unused __be16 proto
, u16 vid
)
2529 static int i40e_vlan_rx_kill_vid(struct net_device
*netdev
,
2530 __always_unused __be16 proto
, u16 vid
)
2533 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2534 struct i40e_vsi
*vsi
= np
->vsi
;
2536 netdev_info(netdev
, "removing %pM vid=%d\n", netdev
->dev_addr
, vid
);
2538 /* return code is ignored as there is nothing a user
2539 * can do about failure to remove and a log message was
2540 * already printed from the other function
2542 i40e_vsi_kill_vlan(vsi
, vid
);
2544 clear_bit(vid
, vsi
->active_vlans
);
2550 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2551 * @vsi: the vsi being brought back up
2553 static void i40e_restore_vlan(struct i40e_vsi
*vsi
)
2560 i40e_vlan_rx_register(vsi
->netdev
, vsi
->netdev
->features
);
2562 for_each_set_bit(vid
, vsi
->active_vlans
, VLAN_N_VID
)
2563 i40e_vlan_rx_add_vid(vsi
->netdev
, htons(ETH_P_8021Q
),
2568 * i40e_vsi_add_pvid - Add pvid for the VSI
2569 * @vsi: the vsi being adjusted
2570 * @vid: the vlan id to set as a PVID
2572 int i40e_vsi_add_pvid(struct i40e_vsi
*vsi
, u16 vid
)
2574 struct i40e_vsi_context ctxt
;
2577 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2578 vsi
->info
.pvid
= cpu_to_le16(vid
);
2579 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_TAGGED
|
2580 I40E_AQ_VSI_PVLAN_INSERT_PVID
|
2581 I40E_AQ_VSI_PVLAN_EMOD_STR
;
2583 ctxt
.seid
= vsi
->seid
;
2584 ctxt
.info
= vsi
->info
;
2585 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2587 dev_info(&vsi
->back
->pdev
->dev
,
2588 "add pvid failed, err %s aq_err %s\n",
2589 i40e_stat_str(&vsi
->back
->hw
, ret
),
2590 i40e_aq_str(&vsi
->back
->hw
,
2591 vsi
->back
->hw
.aq
.asq_last_status
));
2599 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2600 * @vsi: the vsi being adjusted
2602 * Just use the vlan_rx_register() service to put it back to normal
2604 void i40e_vsi_remove_pvid(struct i40e_vsi
*vsi
)
2606 i40e_vlan_stripping_disable(vsi
);
2612 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2613 * @vsi: ptr to the VSI
2615 * If this function returns with an error, then it's possible one or
2616 * more of the rings is populated (while the rest are not). It is the
2617 * callers duty to clean those orphaned rings.
2619 * Return 0 on success, negative on failure
2621 static int i40e_vsi_setup_tx_resources(struct i40e_vsi
*vsi
)
2625 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2626 err
= i40e_setup_tx_descriptors(vsi
->tx_rings
[i
]);
2632 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2633 * @vsi: ptr to the VSI
2635 * Free VSI's transmit software resources
2637 static void i40e_vsi_free_tx_resources(struct i40e_vsi
*vsi
)
2644 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2645 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
)
2646 i40e_free_tx_resources(vsi
->tx_rings
[i
]);
2650 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2651 * @vsi: ptr to the VSI
2653 * If this function returns with an error, then it's possible one or
2654 * more of the rings is populated (while the rest are not). It is the
2655 * callers duty to clean those orphaned rings.
2657 * Return 0 on success, negative on failure
2659 static int i40e_vsi_setup_rx_resources(struct i40e_vsi
*vsi
)
2663 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2664 err
= i40e_setup_rx_descriptors(vsi
->rx_rings
[i
]);
2666 i40e_fcoe_setup_ddp_resources(vsi
);
2672 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2673 * @vsi: ptr to the VSI
2675 * Free all receive software resources
2677 static void i40e_vsi_free_rx_resources(struct i40e_vsi
*vsi
)
2684 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2685 if (vsi
->rx_rings
[i
] && vsi
->rx_rings
[i
]->desc
)
2686 i40e_free_rx_resources(vsi
->rx_rings
[i
]);
2688 i40e_fcoe_free_ddp_resources(vsi
);
2693 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
2694 * @ring: The Tx ring to configure
2696 * This enables/disables XPS for a given Tx descriptor ring
2697 * based on the TCs enabled for the VSI that ring belongs to.
2699 static void i40e_config_xps_tx_ring(struct i40e_ring
*ring
)
2701 struct i40e_vsi
*vsi
= ring
->vsi
;
2704 if (!ring
->q_vector
|| !ring
->netdev
)
2707 /* Single TC mode enable XPS */
2708 if (vsi
->tc_config
.numtc
<= 1) {
2709 if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE
, &ring
->state
))
2710 netif_set_xps_queue(ring
->netdev
,
2711 &ring
->q_vector
->affinity_mask
,
2713 } else if (alloc_cpumask_var(&mask
, GFP_KERNEL
)) {
2714 /* Disable XPS to allow selection based on TC */
2715 bitmap_zero(cpumask_bits(mask
), nr_cpumask_bits
);
2716 netif_set_xps_queue(ring
->netdev
, mask
, ring
->queue_index
);
2717 free_cpumask_var(mask
);
2720 /* schedule our worker thread which will take care of
2721 * applying the new filter changes
2723 i40e_service_event_schedule(vsi
->back
);
2727 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2728 * @ring: The Tx ring to configure
2730 * Configure the Tx descriptor ring in the HMC context.
2732 static int i40e_configure_tx_ring(struct i40e_ring
*ring
)
2734 struct i40e_vsi
*vsi
= ring
->vsi
;
2735 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
2736 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2737 struct i40e_hmc_obj_txq tx_ctx
;
2738 i40e_status err
= 0;
2741 /* some ATR related tx ring init */
2742 if (vsi
->back
->flags
& I40E_FLAG_FD_ATR_ENABLED
) {
2743 ring
->atr_sample_rate
= vsi
->back
->atr_sample_rate
;
2744 ring
->atr_count
= 0;
2746 ring
->atr_sample_rate
= 0;
2750 i40e_config_xps_tx_ring(ring
);
2752 /* clear the context structure first */
2753 memset(&tx_ctx
, 0, sizeof(tx_ctx
));
2755 tx_ctx
.new_context
= 1;
2756 tx_ctx
.base
= (ring
->dma
/ 128);
2757 tx_ctx
.qlen
= ring
->count
;
2758 tx_ctx
.fd_ena
= !!(vsi
->back
->flags
& (I40E_FLAG_FD_SB_ENABLED
|
2759 I40E_FLAG_FD_ATR_ENABLED
));
2761 tx_ctx
.fc_ena
= (vsi
->type
== I40E_VSI_FCOE
);
2763 tx_ctx
.timesync_ena
= !!(vsi
->back
->flags
& I40E_FLAG_PTP
);
2764 /* FDIR VSI tx ring can still use RS bit and writebacks */
2765 if (vsi
->type
!= I40E_VSI_FDIR
)
2766 tx_ctx
.head_wb_ena
= 1;
2767 tx_ctx
.head_wb_addr
= ring
->dma
+
2768 (ring
->count
* sizeof(struct i40e_tx_desc
));
2770 /* As part of VSI creation/update, FW allocates certain
2771 * Tx arbitration queue sets for each TC enabled for
2772 * the VSI. The FW returns the handles to these queue
2773 * sets as part of the response buffer to Add VSI,
2774 * Update VSI, etc. AQ commands. It is expected that
2775 * these queue set handles be associated with the Tx
2776 * queues by the driver as part of the TX queue context
2777 * initialization. This has to be done regardless of
2778 * DCB as by default everything is mapped to TC0.
2780 tx_ctx
.rdylist
= le16_to_cpu(vsi
->info
.qs_handle
[ring
->dcb_tc
]);
2781 tx_ctx
.rdylist_act
= 0;
2783 /* clear the context in the HMC */
2784 err
= i40e_clear_lan_tx_queue_context(hw
, pf_q
);
2786 dev_info(&vsi
->back
->pdev
->dev
,
2787 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2788 ring
->queue_index
, pf_q
, err
);
2792 /* set the context in the HMC */
2793 err
= i40e_set_lan_tx_queue_context(hw
, pf_q
, &tx_ctx
);
2795 dev_info(&vsi
->back
->pdev
->dev
,
2796 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
2797 ring
->queue_index
, pf_q
, err
);
2801 /* Now associate this queue with this PCI function */
2802 if (vsi
->type
== I40E_VSI_VMDQ2
) {
2803 qtx_ctl
= I40E_QTX_CTL_VM_QUEUE
;
2804 qtx_ctl
|= ((vsi
->id
) << I40E_QTX_CTL_VFVM_INDX_SHIFT
) &
2805 I40E_QTX_CTL_VFVM_INDX_MASK
;
2807 qtx_ctl
= I40E_QTX_CTL_PF_QUEUE
;
2810 qtx_ctl
|= ((hw
->pf_id
<< I40E_QTX_CTL_PF_INDX_SHIFT
) &
2811 I40E_QTX_CTL_PF_INDX_MASK
);
2812 wr32(hw
, I40E_QTX_CTL(pf_q
), qtx_ctl
);
2815 /* cache tail off for easier writes later */
2816 ring
->tail
= hw
->hw_addr
+ I40E_QTX_TAIL(pf_q
);
2822 * i40e_configure_rx_ring - Configure a receive ring context
2823 * @ring: The Rx ring to configure
2825 * Configure the Rx descriptor ring in the HMC context.
2827 static int i40e_configure_rx_ring(struct i40e_ring
*ring
)
2829 struct i40e_vsi
*vsi
= ring
->vsi
;
2830 u32 chain_len
= vsi
->back
->hw
.func_caps
.rx_buf_chain_len
;
2831 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
2832 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2833 struct i40e_hmc_obj_rxq rx_ctx
;
2834 i40e_status err
= 0;
2838 /* clear the context structure first */
2839 memset(&rx_ctx
, 0, sizeof(rx_ctx
));
2841 ring
->rx_buf_len
= vsi
->rx_buf_len
;
2842 ring
->rx_hdr_len
= vsi
->rx_hdr_len
;
2844 rx_ctx
.dbuff
= ring
->rx_buf_len
>> I40E_RXQ_CTX_DBUFF_SHIFT
;
2845 rx_ctx
.hbuff
= ring
->rx_hdr_len
>> I40E_RXQ_CTX_HBUFF_SHIFT
;
2847 rx_ctx
.base
= (ring
->dma
/ 128);
2848 rx_ctx
.qlen
= ring
->count
;
2850 if (vsi
->back
->flags
& I40E_FLAG_16BYTE_RX_DESC_ENABLED
) {
2851 set_ring_16byte_desc_enabled(ring
);
2857 rx_ctx
.dtype
= vsi
->dtype
;
2859 set_ring_ps_enabled(ring
);
2860 rx_ctx
.hsplit_0
= I40E_RX_SPLIT_L2
|
2862 I40E_RX_SPLIT_TCP_UDP
|
2865 rx_ctx
.hsplit_0
= 0;
2868 rx_ctx
.rxmax
= min_t(u16
, vsi
->max_frame
,
2869 (chain_len
* ring
->rx_buf_len
));
2870 if (hw
->revision_id
== 0)
2871 rx_ctx
.lrxqthresh
= 0;
2873 rx_ctx
.lrxqthresh
= 2;
2874 rx_ctx
.crcstrip
= 1;
2876 /* this controls whether VLAN is stripped from inner headers */
2879 rx_ctx
.fc_ena
= (vsi
->type
== I40E_VSI_FCOE
);
2881 /* set the prefena field to 1 because the manual says to */
2884 /* clear the context in the HMC */
2885 err
= i40e_clear_lan_rx_queue_context(hw
, pf_q
);
2887 dev_info(&vsi
->back
->pdev
->dev
,
2888 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2889 ring
->queue_index
, pf_q
, err
);
2893 /* set the context in the HMC */
2894 err
= i40e_set_lan_rx_queue_context(hw
, pf_q
, &rx_ctx
);
2896 dev_info(&vsi
->back
->pdev
->dev
,
2897 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2898 ring
->queue_index
, pf_q
, err
);
2902 /* cache tail for quicker writes, and clear the reg before use */
2903 ring
->tail
= hw
->hw_addr
+ I40E_QRX_TAIL(pf_q
);
2904 writel(0, ring
->tail
);
2906 if (ring_is_ps_enabled(ring
)) {
2907 i40e_alloc_rx_headers(ring
);
2908 i40e_alloc_rx_buffers_ps(ring
, I40E_DESC_UNUSED(ring
));
2910 i40e_alloc_rx_buffers_1buf(ring
, I40E_DESC_UNUSED(ring
));
2917 * i40e_vsi_configure_tx - Configure the VSI for Tx
2918 * @vsi: VSI structure describing this set of rings and resources
2920 * Configure the Tx VSI for operation.
2922 static int i40e_vsi_configure_tx(struct i40e_vsi
*vsi
)
2927 for (i
= 0; (i
< vsi
->num_queue_pairs
) && !err
; i
++)
2928 err
= i40e_configure_tx_ring(vsi
->tx_rings
[i
]);
2934 * i40e_vsi_configure_rx - Configure the VSI for Rx
2935 * @vsi: the VSI being configured
2937 * Configure the Rx VSI for operation.
2939 static int i40e_vsi_configure_rx(struct i40e_vsi
*vsi
)
2944 if (vsi
->netdev
&& (vsi
->netdev
->mtu
> ETH_DATA_LEN
))
2945 vsi
->max_frame
= vsi
->netdev
->mtu
+ ETH_HLEN
2946 + ETH_FCS_LEN
+ VLAN_HLEN
;
2948 vsi
->max_frame
= I40E_RXBUFFER_2048
;
2950 /* figure out correct receive buffer length */
2951 switch (vsi
->back
->flags
& (I40E_FLAG_RX_1BUF_ENABLED
|
2952 I40E_FLAG_RX_PS_ENABLED
)) {
2953 case I40E_FLAG_RX_1BUF_ENABLED
:
2954 vsi
->rx_hdr_len
= 0;
2955 vsi
->rx_buf_len
= vsi
->max_frame
;
2956 vsi
->dtype
= I40E_RX_DTYPE_NO_SPLIT
;
2958 case I40E_FLAG_RX_PS_ENABLED
:
2959 vsi
->rx_hdr_len
= I40E_RX_HDR_SIZE
;
2960 vsi
->rx_buf_len
= I40E_RXBUFFER_2048
;
2961 vsi
->dtype
= I40E_RX_DTYPE_HEADER_SPLIT
;
2964 vsi
->rx_hdr_len
= I40E_RX_HDR_SIZE
;
2965 vsi
->rx_buf_len
= I40E_RXBUFFER_2048
;
2966 vsi
->dtype
= I40E_RX_DTYPE_SPLIT_ALWAYS
;
2971 /* setup rx buffer for FCoE */
2972 if ((vsi
->type
== I40E_VSI_FCOE
) &&
2973 (vsi
->back
->flags
& I40E_FLAG_FCOE_ENABLED
)) {
2974 vsi
->rx_hdr_len
= 0;
2975 vsi
->rx_buf_len
= I40E_RXBUFFER_3072
;
2976 vsi
->max_frame
= I40E_RXBUFFER_3072
;
2977 vsi
->dtype
= I40E_RX_DTYPE_NO_SPLIT
;
2980 #endif /* I40E_FCOE */
2981 /* round up for the chip's needs */
2982 vsi
->rx_hdr_len
= ALIGN(vsi
->rx_hdr_len
,
2983 BIT_ULL(I40E_RXQ_CTX_HBUFF_SHIFT
));
2984 vsi
->rx_buf_len
= ALIGN(vsi
->rx_buf_len
,
2985 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT
));
2987 /* set up individual rings */
2988 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2989 err
= i40e_configure_rx_ring(vsi
->rx_rings
[i
]);
2995 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
2996 * @vsi: ptr to the VSI
2998 static void i40e_vsi_config_dcb_rings(struct i40e_vsi
*vsi
)
3000 struct i40e_ring
*tx_ring
, *rx_ring
;
3001 u16 qoffset
, qcount
;
3004 if (!(vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
3005 /* Reset the TC information */
3006 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
3007 rx_ring
= vsi
->rx_rings
[i
];
3008 tx_ring
= vsi
->tx_rings
[i
];
3009 rx_ring
->dcb_tc
= 0;
3010 tx_ring
->dcb_tc
= 0;
3014 for (n
= 0; n
< I40E_MAX_TRAFFIC_CLASS
; n
++) {
3015 if (!(vsi
->tc_config
.enabled_tc
& BIT_ULL(n
)))
3018 qoffset
= vsi
->tc_config
.tc_info
[n
].qoffset
;
3019 qcount
= vsi
->tc_config
.tc_info
[n
].qcount
;
3020 for (i
= qoffset
; i
< (qoffset
+ qcount
); i
++) {
3021 rx_ring
= vsi
->rx_rings
[i
];
3022 tx_ring
= vsi
->tx_rings
[i
];
3023 rx_ring
->dcb_tc
= n
;
3024 tx_ring
->dcb_tc
= n
;
3030 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
3031 * @vsi: ptr to the VSI
3033 static void i40e_set_vsi_rx_mode(struct i40e_vsi
*vsi
)
3036 i40e_set_rx_mode(vsi
->netdev
);
3040 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
3041 * @vsi: Pointer to the targeted VSI
3043 * This function replays the hlist on the hw where all the SB Flow Director
3044 * filters were saved.
3046 static void i40e_fdir_filter_restore(struct i40e_vsi
*vsi
)
3048 struct i40e_fdir_filter
*filter
;
3049 struct i40e_pf
*pf
= vsi
->back
;
3050 struct hlist_node
*node
;
3052 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
3055 hlist_for_each_entry_safe(filter
, node
,
3056 &pf
->fdir_filter_list
, fdir_node
) {
3057 i40e_add_del_fdir(vsi
, filter
, true);
3062 * i40e_vsi_configure - Set up the VSI for action
3063 * @vsi: the VSI being configured
3065 static int i40e_vsi_configure(struct i40e_vsi
*vsi
)
3069 i40e_set_vsi_rx_mode(vsi
);
3070 i40e_restore_vlan(vsi
);
3071 i40e_vsi_config_dcb_rings(vsi
);
3072 err
= i40e_vsi_configure_tx(vsi
);
3074 err
= i40e_vsi_configure_rx(vsi
);
3080 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
3081 * @vsi: the VSI being configured
3083 static void i40e_vsi_configure_msix(struct i40e_vsi
*vsi
)
3085 struct i40e_pf
*pf
= vsi
->back
;
3086 struct i40e_hw
*hw
= &pf
->hw
;
3091 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
3092 * and PFINT_LNKLSTn registers, e.g.:
3093 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
3095 qp
= vsi
->base_queue
;
3096 vector
= vsi
->base_vector
;
3097 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vector
++) {
3098 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[i
];
3100 q_vector
->itr_countdown
= ITR_COUNTDOWN_START
;
3101 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
3102 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
3103 wr32(hw
, I40E_PFINT_ITRN(I40E_RX_ITR
, vector
- 1),
3105 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
3106 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
3107 wr32(hw
, I40E_PFINT_ITRN(I40E_TX_ITR
, vector
- 1),
3109 wr32(hw
, I40E_PFINT_RATEN(vector
- 1),
3110 INTRL_USEC_TO_REG(vsi
->int_rate_limit
));
3112 /* Linked list for the queuepairs assigned to this vector */
3113 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), qp
);
3114 for (q
= 0; q
< q_vector
->num_ringpairs
; q
++) {
3117 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3118 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
3119 (vector
<< I40E_QINT_RQCTL_MSIX_INDX_SHIFT
) |
3120 (qp
<< I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT
)|
3122 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT
);
3124 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
3126 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3127 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
3128 (vector
<< I40E_QINT_TQCTL_MSIX_INDX_SHIFT
) |
3129 ((qp
+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
)|
3131 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
3133 /* Terminate the linked list */
3134 if (q
== (q_vector
->num_ringpairs
- 1))
3135 val
|= (I40E_QUEUE_END_OF_LIST
3136 << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
3138 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
3147 * i40e_enable_misc_int_causes - enable the non-queue interrupts
3148 * @hw: ptr to the hardware info
3150 static void i40e_enable_misc_int_causes(struct i40e_pf
*pf
)
3152 struct i40e_hw
*hw
= &pf
->hw
;
3155 /* clear things first */
3156 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0); /* disable all */
3157 rd32(hw
, I40E_PFINT_ICR0
); /* read to clear */
3159 val
= I40E_PFINT_ICR0_ENA_ECC_ERR_MASK
|
3160 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
|
3161 I40E_PFINT_ICR0_ENA_GRST_MASK
|
3162 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK
|
3163 I40E_PFINT_ICR0_ENA_GPIO_MASK
|
3164 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK
|
3165 I40E_PFINT_ICR0_ENA_VFLR_MASK
|
3166 I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
3168 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
)
3169 val
|= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
;
3171 if (pf
->flags
& I40E_FLAG_PTP
)
3172 val
|= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
3174 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
3176 /* SW_ITR_IDX = 0, but don't change INTENA */
3177 wr32(hw
, I40E_PFINT_DYN_CTL0
, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK
|
3178 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK
);
3180 /* OTHER_ITR_IDX = 0 */
3181 wr32(hw
, I40E_PFINT_STAT_CTL0
, 0);
3185 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
3186 * @vsi: the VSI being configured
3188 static void i40e_configure_msi_and_legacy(struct i40e_vsi
*vsi
)
3190 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[0];
3191 struct i40e_pf
*pf
= vsi
->back
;
3192 struct i40e_hw
*hw
= &pf
->hw
;
3195 /* set the ITR configuration */
3196 q_vector
->itr_countdown
= ITR_COUNTDOWN_START
;
3197 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
3198 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
3199 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), q_vector
->rx
.itr
);
3200 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
3201 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
3202 wr32(hw
, I40E_PFINT_ITR0(I40E_TX_ITR
), q_vector
->tx
.itr
);
3204 i40e_enable_misc_int_causes(pf
);
3206 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
3207 wr32(hw
, I40E_PFINT_LNKLST0
, 0);
3209 /* Associate the queue pair to the vector and enable the queue int */
3210 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3211 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
3212 (I40E_QUEUE_TYPE_TX
<< I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
3214 wr32(hw
, I40E_QINT_RQCTL(0), val
);
3216 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3217 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
3218 (I40E_QUEUE_END_OF_LIST
<< I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
3220 wr32(hw
, I40E_QINT_TQCTL(0), val
);
3225 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
3226 * @pf: board private structure
3228 void i40e_irq_dynamic_disable_icr0(struct i40e_pf
*pf
)
3230 struct i40e_hw
*hw
= &pf
->hw
;
3232 wr32(hw
, I40E_PFINT_DYN_CTL0
,
3233 I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
);
3238 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
3239 * @pf: board private structure
3241 void i40e_irq_dynamic_enable_icr0(struct i40e_pf
*pf
)
3243 struct i40e_hw
*hw
= &pf
->hw
;
3246 val
= I40E_PFINT_DYN_CTL0_INTENA_MASK
|
3247 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK
|
3248 (I40E_ITR_NONE
<< I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT
);
3250 wr32(hw
, I40E_PFINT_DYN_CTL0
, val
);
3255 * i40e_irq_dynamic_disable - Disable default interrupt generation settings
3256 * @vsi: pointer to a vsi
3257 * @vector: disable a particular Hw Interrupt vector
3259 void i40e_irq_dynamic_disable(struct i40e_vsi
*vsi
, int vector
)
3261 struct i40e_pf
*pf
= vsi
->back
;
3262 struct i40e_hw
*hw
= &pf
->hw
;
3265 val
= I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
;
3266 wr32(hw
, I40E_PFINT_DYN_CTLN(vector
- 1), val
);
3271 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
3272 * @irq: interrupt number
3273 * @data: pointer to a q_vector
3275 static irqreturn_t
i40e_msix_clean_rings(int irq
, void *data
)
3277 struct i40e_q_vector
*q_vector
= data
;
3279 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
3282 napi_schedule_irqoff(&q_vector
->napi
);
3288 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3289 * @vsi: the VSI being configured
3290 * @basename: name for the vector
3292 * Allocates MSI-X vectors and requests interrupts from the kernel.
3294 static int i40e_vsi_request_irq_msix(struct i40e_vsi
*vsi
, char *basename
)
3296 int q_vectors
= vsi
->num_q_vectors
;
3297 struct i40e_pf
*pf
= vsi
->back
;
3298 int base
= vsi
->base_vector
;
3303 for (vector
= 0; vector
< q_vectors
; vector
++) {
3304 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[vector
];
3306 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
3307 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3308 "%s-%s-%d", basename
, "TxRx", rx_int_idx
++);
3310 } else if (q_vector
->rx
.ring
) {
3311 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3312 "%s-%s-%d", basename
, "rx", rx_int_idx
++);
3313 } else if (q_vector
->tx
.ring
) {
3314 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3315 "%s-%s-%d", basename
, "tx", tx_int_idx
++);
3317 /* skip this unused q_vector */
3320 err
= request_irq(pf
->msix_entries
[base
+ vector
].vector
,
3326 dev_info(&pf
->pdev
->dev
,
3327 "MSIX request_irq failed, error: %d\n", err
);
3328 goto free_queue_irqs
;
3330 /* assign the mask for this irq */
3331 irq_set_affinity_hint(pf
->msix_entries
[base
+ vector
].vector
,
3332 &q_vector
->affinity_mask
);
3335 vsi
->irqs_ready
= true;
3341 irq_set_affinity_hint(pf
->msix_entries
[base
+ vector
].vector
,
3343 free_irq(pf
->msix_entries
[base
+ vector
].vector
,
3344 &(vsi
->q_vectors
[vector
]));
3350 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3351 * @vsi: the VSI being un-configured
3353 static void i40e_vsi_disable_irq(struct i40e_vsi
*vsi
)
3355 struct i40e_pf
*pf
= vsi
->back
;
3356 struct i40e_hw
*hw
= &pf
->hw
;
3357 int base
= vsi
->base_vector
;
3360 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
3361 wr32(hw
, I40E_QINT_TQCTL(vsi
->tx_rings
[i
]->reg_idx
), 0);
3362 wr32(hw
, I40E_QINT_RQCTL(vsi
->rx_rings
[i
]->reg_idx
), 0);
3365 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3366 for (i
= vsi
->base_vector
;
3367 i
< (vsi
->num_q_vectors
+ vsi
->base_vector
); i
++)
3368 wr32(hw
, I40E_PFINT_DYN_CTLN(i
- 1), 0);
3371 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3372 synchronize_irq(pf
->msix_entries
[i
+ base
].vector
);
3374 /* Legacy and MSI mode - this stops all interrupt handling */
3375 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0);
3376 wr32(hw
, I40E_PFINT_DYN_CTL0
, 0);
3378 synchronize_irq(pf
->pdev
->irq
);
3383 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3384 * @vsi: the VSI being configured
3386 static int i40e_vsi_enable_irq(struct i40e_vsi
*vsi
)
3388 struct i40e_pf
*pf
= vsi
->back
;
3391 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3392 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3393 i40e_irq_dynamic_enable(vsi
, i
);
3395 i40e_irq_dynamic_enable_icr0(pf
);
3398 i40e_flush(&pf
->hw
);
3403 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
3404 * @pf: board private structure
3406 static void i40e_stop_misc_vector(struct i40e_pf
*pf
)
3409 wr32(&pf
->hw
, I40E_PFINT_ICR0_ENA
, 0);
3410 i40e_flush(&pf
->hw
);
3414 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3415 * @irq: interrupt number
3416 * @data: pointer to a q_vector
3418 * This is the handler used for all MSI/Legacy interrupts, and deals
3419 * with both queue and non-queue interrupts. This is also used in
3420 * MSIX mode to handle the non-queue interrupts.
3422 static irqreturn_t
i40e_intr(int irq
, void *data
)
3424 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
3425 struct i40e_hw
*hw
= &pf
->hw
;
3426 irqreturn_t ret
= IRQ_NONE
;
3427 u32 icr0
, icr0_remaining
;
3430 icr0
= rd32(hw
, I40E_PFINT_ICR0
);
3431 ena_mask
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
3433 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
3434 if ((icr0
& I40E_PFINT_ICR0_INTEVENT_MASK
) == 0)
3437 /* if interrupt but no bits showing, must be SWINT */
3438 if (((icr0
& ~I40E_PFINT_ICR0_INTEVENT_MASK
) == 0) ||
3439 (icr0
& I40E_PFINT_ICR0_SWINT_MASK
))
3442 if ((pf
->flags
& I40E_FLAG_IWARP_ENABLED
) &&
3443 (ena_mask
& I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
)) {
3444 ena_mask
&= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
;
3445 icr0
&= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
;
3446 dev_info(&pf
->pdev
->dev
, "cleared PE_CRITERR\n");
3449 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
3450 if (icr0
& I40E_PFINT_ICR0_QUEUE_0_MASK
) {
3451 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
3452 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[0];
3454 /* temporarily disable queue cause for NAPI processing */
3455 u32 qval
= rd32(hw
, I40E_QINT_RQCTL(0));
3457 qval
&= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK
;
3458 wr32(hw
, I40E_QINT_RQCTL(0), qval
);
3460 qval
= rd32(hw
, I40E_QINT_TQCTL(0));
3461 qval
&= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK
;
3462 wr32(hw
, I40E_QINT_TQCTL(0), qval
);
3464 if (!test_bit(__I40E_DOWN
, &pf
->state
))
3465 napi_schedule_irqoff(&q_vector
->napi
);
3468 if (icr0
& I40E_PFINT_ICR0_ADMINQ_MASK
) {
3469 ena_mask
&= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
3470 set_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
);
3473 if (icr0
& I40E_PFINT_ICR0_MAL_DETECT_MASK
) {
3474 ena_mask
&= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
3475 set_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
);
3478 if (icr0
& I40E_PFINT_ICR0_VFLR_MASK
) {
3479 ena_mask
&= ~I40E_PFINT_ICR0_ENA_VFLR_MASK
;
3480 set_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
);
3483 if (icr0
& I40E_PFINT_ICR0_GRST_MASK
) {
3484 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
))
3485 set_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
);
3486 ena_mask
&= ~I40E_PFINT_ICR0_ENA_GRST_MASK
;
3487 val
= rd32(hw
, I40E_GLGEN_RSTAT
);
3488 val
= (val
& I40E_GLGEN_RSTAT_RESET_TYPE_MASK
)
3489 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT
;
3490 if (val
== I40E_RESET_CORER
) {
3492 } else if (val
== I40E_RESET_GLOBR
) {
3494 } else if (val
== I40E_RESET_EMPR
) {
3496 set_bit(__I40E_EMP_RESET_INTR_RECEIVED
, &pf
->state
);
3500 if (icr0
& I40E_PFINT_ICR0_HMC_ERR_MASK
) {
3501 icr0
&= ~I40E_PFINT_ICR0_HMC_ERR_MASK
;
3502 dev_info(&pf
->pdev
->dev
, "HMC error interrupt\n");
3503 dev_info(&pf
->pdev
->dev
, "HMC error info 0x%x, HMC error data 0x%x\n",
3504 rd32(hw
, I40E_PFHMC_ERRORINFO
),
3505 rd32(hw
, I40E_PFHMC_ERRORDATA
));
3508 if (icr0
& I40E_PFINT_ICR0_TIMESYNC_MASK
) {
3509 u32 prttsyn_stat
= rd32(hw
, I40E_PRTTSYN_STAT_0
);
3511 if (prttsyn_stat
& I40E_PRTTSYN_STAT_0_TXTIME_MASK
) {
3512 icr0
&= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
3513 i40e_ptp_tx_hwtstamp(pf
);
3517 /* If a critical error is pending we have no choice but to reset the
3519 * Report and mask out any remaining unexpected interrupts.
3521 icr0_remaining
= icr0
& ena_mask
;
3522 if (icr0_remaining
) {
3523 dev_info(&pf
->pdev
->dev
, "unhandled interrupt icr0=0x%08x\n",
3525 if ((icr0_remaining
& I40E_PFINT_ICR0_PE_CRITERR_MASK
) ||
3526 (icr0_remaining
& I40E_PFINT_ICR0_PCI_EXCEPTION_MASK
) ||
3527 (icr0_remaining
& I40E_PFINT_ICR0_ECC_ERR_MASK
)) {
3528 dev_info(&pf
->pdev
->dev
, "device will be reset\n");
3529 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
3530 i40e_service_event_schedule(pf
);
3532 ena_mask
&= ~icr0_remaining
;
3537 /* re-enable interrupt causes */
3538 wr32(hw
, I40E_PFINT_ICR0_ENA
, ena_mask
);
3539 if (!test_bit(__I40E_DOWN
, &pf
->state
)) {
3540 i40e_service_event_schedule(pf
);
3541 i40e_irq_dynamic_enable_icr0(pf
);
3548 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3549 * @tx_ring: tx ring to clean
3550 * @budget: how many cleans we're allowed
3552 * Returns true if there's any budget left (e.g. the clean is finished)
3554 static bool i40e_clean_fdir_tx_irq(struct i40e_ring
*tx_ring
, int budget
)
3556 struct i40e_vsi
*vsi
= tx_ring
->vsi
;
3557 u16 i
= tx_ring
->next_to_clean
;
3558 struct i40e_tx_buffer
*tx_buf
;
3559 struct i40e_tx_desc
*tx_desc
;
3561 tx_buf
= &tx_ring
->tx_bi
[i
];
3562 tx_desc
= I40E_TX_DESC(tx_ring
, i
);
3563 i
-= tx_ring
->count
;
3566 struct i40e_tx_desc
*eop_desc
= tx_buf
->next_to_watch
;
3568 /* if next_to_watch is not set then there is no work pending */
3572 /* prevent any other reads prior to eop_desc */
3573 read_barrier_depends();
3575 /* if the descriptor isn't done, no work yet to do */
3576 if (!(eop_desc
->cmd_type_offset_bsz
&
3577 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE
)))
3580 /* clear next_to_watch to prevent false hangs */
3581 tx_buf
->next_to_watch
= NULL
;
3583 tx_desc
->buffer_addr
= 0;
3584 tx_desc
->cmd_type_offset_bsz
= 0;
3585 /* move past filter desc */
3590 i
-= tx_ring
->count
;
3591 tx_buf
= tx_ring
->tx_bi
;
3592 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
3594 /* unmap skb header data */
3595 dma_unmap_single(tx_ring
->dev
,
3596 dma_unmap_addr(tx_buf
, dma
),
3597 dma_unmap_len(tx_buf
, len
),
3599 if (tx_buf
->tx_flags
& I40E_TX_FLAGS_FD_SB
)
3600 kfree(tx_buf
->raw_buf
);
3602 tx_buf
->raw_buf
= NULL
;
3603 tx_buf
->tx_flags
= 0;
3604 tx_buf
->next_to_watch
= NULL
;
3605 dma_unmap_len_set(tx_buf
, len
, 0);
3606 tx_desc
->buffer_addr
= 0;
3607 tx_desc
->cmd_type_offset_bsz
= 0;
3609 /* move us past the eop_desc for start of next FD desc */
3614 i
-= tx_ring
->count
;
3615 tx_buf
= tx_ring
->tx_bi
;
3616 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
3619 /* update budget accounting */
3621 } while (likely(budget
));
3623 i
+= tx_ring
->count
;
3624 tx_ring
->next_to_clean
= i
;
3626 if (vsi
->back
->flags
& I40E_FLAG_MSIX_ENABLED
)
3627 i40e_irq_dynamic_enable(vsi
, tx_ring
->q_vector
->v_idx
);
3633 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
3634 * @irq: interrupt number
3635 * @data: pointer to a q_vector
3637 static irqreturn_t
i40e_fdir_clean_ring(int irq
, void *data
)
3639 struct i40e_q_vector
*q_vector
= data
;
3640 struct i40e_vsi
*vsi
;
3642 if (!q_vector
->tx
.ring
)
3645 vsi
= q_vector
->tx
.ring
->vsi
;
3646 i40e_clean_fdir_tx_irq(q_vector
->tx
.ring
, vsi
->work_limit
);
3652 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
3653 * @vsi: the VSI being configured
3654 * @v_idx: vector index
3655 * @qp_idx: queue pair index
3657 static void i40e_map_vector_to_qp(struct i40e_vsi
*vsi
, int v_idx
, int qp_idx
)
3659 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
3660 struct i40e_ring
*tx_ring
= vsi
->tx_rings
[qp_idx
];
3661 struct i40e_ring
*rx_ring
= vsi
->rx_rings
[qp_idx
];
3663 tx_ring
->q_vector
= q_vector
;
3664 tx_ring
->next
= q_vector
->tx
.ring
;
3665 q_vector
->tx
.ring
= tx_ring
;
3666 q_vector
->tx
.count
++;
3668 rx_ring
->q_vector
= q_vector
;
3669 rx_ring
->next
= q_vector
->rx
.ring
;
3670 q_vector
->rx
.ring
= rx_ring
;
3671 q_vector
->rx
.count
++;
3675 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
3676 * @vsi: the VSI being configured
3678 * This function maps descriptor rings to the queue-specific vectors
3679 * we were allotted through the MSI-X enabling code. Ideally, we'd have
3680 * one vector per queue pair, but on a constrained vector budget, we
3681 * group the queue pairs as "efficiently" as possible.
3683 static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi
*vsi
)
3685 int qp_remaining
= vsi
->num_queue_pairs
;
3686 int q_vectors
= vsi
->num_q_vectors
;
3691 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
3692 * group them so there are multiple queues per vector.
3693 * It is also important to go through all the vectors available to be
3694 * sure that if we don't use all the vectors, that the remaining vectors
3695 * are cleared. This is especially important when decreasing the
3696 * number of queues in use.
3698 for (; v_start
< q_vectors
; v_start
++) {
3699 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_start
];
3701 num_ringpairs
= DIV_ROUND_UP(qp_remaining
, q_vectors
- v_start
);
3703 q_vector
->num_ringpairs
= num_ringpairs
;
3705 q_vector
->rx
.count
= 0;
3706 q_vector
->tx
.count
= 0;
3707 q_vector
->rx
.ring
= NULL
;
3708 q_vector
->tx
.ring
= NULL
;
3710 while (num_ringpairs
--) {
3711 i40e_map_vector_to_qp(vsi
, v_start
, qp_idx
);
3719 * i40e_vsi_request_irq - Request IRQ from the OS
3720 * @vsi: the VSI being configured
3721 * @basename: name for the vector
3723 static int i40e_vsi_request_irq(struct i40e_vsi
*vsi
, char *basename
)
3725 struct i40e_pf
*pf
= vsi
->back
;
3728 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
3729 err
= i40e_vsi_request_irq_msix(vsi
, basename
);
3730 else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
)
3731 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, 0,
3734 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, IRQF_SHARED
,
3738 dev_info(&pf
->pdev
->dev
, "request_irq failed, Error %d\n", err
);
3743 #ifdef CONFIG_NET_POLL_CONTROLLER
3745 * i40e_netpoll - A Polling 'interrupt'handler
3746 * @netdev: network interface device structure
3748 * This is used by netconsole to send skbs without having to re-enable
3749 * interrupts. It's not called while the normal interrupt routine is executing.
3752 void i40e_netpoll(struct net_device
*netdev
)
3754 static void i40e_netpoll(struct net_device
*netdev
)
3757 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3758 struct i40e_vsi
*vsi
= np
->vsi
;
3759 struct i40e_pf
*pf
= vsi
->back
;
3762 /* if interface is down do nothing */
3763 if (test_bit(__I40E_DOWN
, &vsi
->state
))
3766 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3767 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3768 i40e_msix_clean_rings(0, vsi
->q_vectors
[i
]);
3770 i40e_intr(pf
->pdev
->irq
, netdev
);
3776 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
3777 * @pf: the PF being configured
3778 * @pf_q: the PF queue
3779 * @enable: enable or disable state of the queue
3781 * This routine will wait for the given Tx queue of the PF to reach the
3782 * enabled or disabled state.
3783 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3784 * multiple retries; else will return 0 in case of success.
3786 static int i40e_pf_txq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
3791 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
3792 tx_reg
= rd32(&pf
->hw
, I40E_QTX_ENA(pf_q
));
3793 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
3796 usleep_range(10, 20);
3798 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
3805 * i40e_vsi_control_tx - Start or stop a VSI's rings
3806 * @vsi: the VSI being configured
3807 * @enable: start or stop the rings
3809 static int i40e_vsi_control_tx(struct i40e_vsi
*vsi
, bool enable
)
3811 struct i40e_pf
*pf
= vsi
->back
;
3812 struct i40e_hw
*hw
= &pf
->hw
;
3813 int i
, j
, pf_q
, ret
= 0;
3816 pf_q
= vsi
->base_queue
;
3817 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
3819 /* warn the TX unit of coming changes */
3820 i40e_pre_tx_queue_cfg(&pf
->hw
, pf_q
, enable
);
3822 usleep_range(10, 20);
3824 for (j
= 0; j
< 50; j
++) {
3825 tx_reg
= rd32(hw
, I40E_QTX_ENA(pf_q
));
3826 if (((tx_reg
>> I40E_QTX_ENA_QENA_REQ_SHIFT
) & 1) ==
3827 ((tx_reg
>> I40E_QTX_ENA_QENA_STAT_SHIFT
) & 1))
3829 usleep_range(1000, 2000);
3831 /* Skip if the queue is already in the requested state */
3832 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
3835 /* turn on/off the queue */
3837 wr32(hw
, I40E_QTX_HEAD(pf_q
), 0);
3838 tx_reg
|= I40E_QTX_ENA_QENA_REQ_MASK
;
3840 tx_reg
&= ~I40E_QTX_ENA_QENA_REQ_MASK
;
3843 wr32(hw
, I40E_QTX_ENA(pf_q
), tx_reg
);
3844 /* No waiting for the Tx queue to disable */
3845 if (!enable
&& test_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
))
3848 /* wait for the change to finish */
3849 ret
= i40e_pf_txq_wait(pf
, pf_q
, enable
);
3851 dev_info(&pf
->pdev
->dev
,
3852 "VSI seid %d Tx ring %d %sable timeout\n",
3853 vsi
->seid
, pf_q
, (enable
? "en" : "dis"));
3858 if (hw
->revision_id
== 0)
3864 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
3865 * @pf: the PF being configured
3866 * @pf_q: the PF queue
3867 * @enable: enable or disable state of the queue
3869 * This routine will wait for the given Rx queue of the PF to reach the
3870 * enabled or disabled state.
3871 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3872 * multiple retries; else will return 0 in case of success.
3874 static int i40e_pf_rxq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
3879 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
3880 rx_reg
= rd32(&pf
->hw
, I40E_QRX_ENA(pf_q
));
3881 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
3884 usleep_range(10, 20);
3886 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
3893 * i40e_vsi_control_rx - Start or stop a VSI's rings
3894 * @vsi: the VSI being configured
3895 * @enable: start or stop the rings
3897 static int i40e_vsi_control_rx(struct i40e_vsi
*vsi
, bool enable
)
3899 struct i40e_pf
*pf
= vsi
->back
;
3900 struct i40e_hw
*hw
= &pf
->hw
;
3901 int i
, j
, pf_q
, ret
= 0;
3904 pf_q
= vsi
->base_queue
;
3905 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
3906 for (j
= 0; j
< 50; j
++) {
3907 rx_reg
= rd32(hw
, I40E_QRX_ENA(pf_q
));
3908 if (((rx_reg
>> I40E_QRX_ENA_QENA_REQ_SHIFT
) & 1) ==
3909 ((rx_reg
>> I40E_QRX_ENA_QENA_STAT_SHIFT
) & 1))
3911 usleep_range(1000, 2000);
3914 /* Skip if the queue is already in the requested state */
3915 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
3918 /* turn on/off the queue */
3920 rx_reg
|= I40E_QRX_ENA_QENA_REQ_MASK
;
3922 rx_reg
&= ~I40E_QRX_ENA_QENA_REQ_MASK
;
3923 wr32(hw
, I40E_QRX_ENA(pf_q
), rx_reg
);
3925 /* wait for the change to finish */
3926 ret
= i40e_pf_rxq_wait(pf
, pf_q
, enable
);
3928 dev_info(&pf
->pdev
->dev
,
3929 "VSI seid %d Rx ring %d %sable timeout\n",
3930 vsi
->seid
, pf_q
, (enable
? "en" : "dis"));
3939 * i40e_vsi_control_rings - Start or stop a VSI's rings
3940 * @vsi: the VSI being configured
3941 * @enable: start or stop the rings
3943 int i40e_vsi_control_rings(struct i40e_vsi
*vsi
, bool request
)
3947 /* do rx first for enable and last for disable */
3949 ret
= i40e_vsi_control_rx(vsi
, request
);
3952 ret
= i40e_vsi_control_tx(vsi
, request
);
3954 /* Ignore return value, we need to shutdown whatever we can */
3955 i40e_vsi_control_tx(vsi
, request
);
3956 i40e_vsi_control_rx(vsi
, request
);
3963 * i40e_vsi_free_irq - Free the irq association with the OS
3964 * @vsi: the VSI being configured
3966 static void i40e_vsi_free_irq(struct i40e_vsi
*vsi
)
3968 struct i40e_pf
*pf
= vsi
->back
;
3969 struct i40e_hw
*hw
= &pf
->hw
;
3970 int base
= vsi
->base_vector
;
3974 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3975 if (!vsi
->q_vectors
)
3978 if (!vsi
->irqs_ready
)
3981 vsi
->irqs_ready
= false;
3982 for (i
= 0; i
< vsi
->num_q_vectors
; i
++) {
3983 u16 vector
= i
+ base
;
3985 /* free only the irqs that were actually requested */
3986 if (!vsi
->q_vectors
[i
] ||
3987 !vsi
->q_vectors
[i
]->num_ringpairs
)
3990 /* clear the affinity_mask in the IRQ descriptor */
3991 irq_set_affinity_hint(pf
->msix_entries
[vector
].vector
,
3993 free_irq(pf
->msix_entries
[vector
].vector
,
3996 /* Tear down the interrupt queue link list
3998 * We know that they come in pairs and always
3999 * the Rx first, then the Tx. To clear the
4000 * link list, stick the EOL value into the
4001 * next_q field of the registers.
4003 val
= rd32(hw
, I40E_PFINT_LNKLSTN(vector
- 1));
4004 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
4005 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
4006 val
|= I40E_QUEUE_END_OF_LIST
4007 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
4008 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), val
);
4010 while (qp
!= I40E_QUEUE_END_OF_LIST
) {
4013 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
4015 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
4016 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
4017 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
4018 I40E_QINT_RQCTL_INTEVENT_MASK
);
4020 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
4021 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
4023 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
4025 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
4027 next
= (val
& I40E_QINT_TQCTL_NEXTQ_INDX_MASK
)
4028 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
;
4030 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
4031 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
4032 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
4033 I40E_QINT_TQCTL_INTEVENT_MASK
);
4035 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
4036 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
4038 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
4043 free_irq(pf
->pdev
->irq
, pf
);
4045 val
= rd32(hw
, I40E_PFINT_LNKLST0
);
4046 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
4047 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
4048 val
|= I40E_QUEUE_END_OF_LIST
4049 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT
;
4050 wr32(hw
, I40E_PFINT_LNKLST0
, val
);
4052 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
4053 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
4054 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
4055 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
4056 I40E_QINT_RQCTL_INTEVENT_MASK
);
4058 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
4059 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
4061 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
4063 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
4065 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
4066 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
4067 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
4068 I40E_QINT_TQCTL_INTEVENT_MASK
);
4070 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
4071 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
4073 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
4078 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
4079 * @vsi: the VSI being configured
4080 * @v_idx: Index of vector to be freed
4082 * This function frees the memory allocated to the q_vector. In addition if
4083 * NAPI is enabled it will delete any references to the NAPI struct prior
4084 * to freeing the q_vector.
4086 static void i40e_free_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
4088 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
4089 struct i40e_ring
*ring
;
4094 /* disassociate q_vector from rings */
4095 i40e_for_each_ring(ring
, q_vector
->tx
)
4096 ring
->q_vector
= NULL
;
4098 i40e_for_each_ring(ring
, q_vector
->rx
)
4099 ring
->q_vector
= NULL
;
4101 /* only VSI w/ an associated netdev is set up w/ NAPI */
4103 netif_napi_del(&q_vector
->napi
);
4105 vsi
->q_vectors
[v_idx
] = NULL
;
4107 kfree_rcu(q_vector
, rcu
);
4111 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
4112 * @vsi: the VSI being un-configured
4114 * This frees the memory allocated to the q_vectors and
4115 * deletes references to the NAPI struct.
4117 static void i40e_vsi_free_q_vectors(struct i40e_vsi
*vsi
)
4121 for (v_idx
= 0; v_idx
< vsi
->num_q_vectors
; v_idx
++)
4122 i40e_free_q_vector(vsi
, v_idx
);
4126 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
4127 * @pf: board private structure
4129 static void i40e_reset_interrupt_capability(struct i40e_pf
*pf
)
4131 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
4132 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
4133 pci_disable_msix(pf
->pdev
);
4134 kfree(pf
->msix_entries
);
4135 pf
->msix_entries
= NULL
;
4136 kfree(pf
->irq_pile
);
4137 pf
->irq_pile
= NULL
;
4138 } else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
) {
4139 pci_disable_msi(pf
->pdev
);
4141 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
);
4145 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
4146 * @pf: board private structure
4148 * We go through and clear interrupt specific resources and reset the structure
4149 * to pre-load conditions
4151 static void i40e_clear_interrupt_scheme(struct i40e_pf
*pf
)
4155 i40e_stop_misc_vector(pf
);
4156 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
4157 synchronize_irq(pf
->msix_entries
[0].vector
);
4158 free_irq(pf
->msix_entries
[0].vector
, pf
);
4161 i40e_put_lump(pf
->irq_pile
, 0, I40E_PILE_VALID_BIT
-1);
4162 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
4164 i40e_vsi_free_q_vectors(pf
->vsi
[i
]);
4165 i40e_reset_interrupt_capability(pf
);
4169 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
4170 * @vsi: the VSI being configured
4172 static void i40e_napi_enable_all(struct i40e_vsi
*vsi
)
4179 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++)
4180 napi_enable(&vsi
->q_vectors
[q_idx
]->napi
);
4184 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4185 * @vsi: the VSI being configured
4187 static void i40e_napi_disable_all(struct i40e_vsi
*vsi
)
4194 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++)
4195 napi_disable(&vsi
->q_vectors
[q_idx
]->napi
);
4199 * i40e_vsi_close - Shut down a VSI
4200 * @vsi: the vsi to be quelled
4202 static void i40e_vsi_close(struct i40e_vsi
*vsi
)
4204 if (!test_and_set_bit(__I40E_DOWN
, &vsi
->state
))
4206 i40e_vsi_free_irq(vsi
);
4207 i40e_vsi_free_tx_resources(vsi
);
4208 i40e_vsi_free_rx_resources(vsi
);
4209 vsi
->current_netdev_flags
= 0;
4213 * i40e_quiesce_vsi - Pause a given VSI
4214 * @vsi: the VSI being paused
4216 static void i40e_quiesce_vsi(struct i40e_vsi
*vsi
)
4218 if (test_bit(__I40E_DOWN
, &vsi
->state
))
4221 /* No need to disable FCoE VSI when Tx suspended */
4222 if ((test_bit(__I40E_PORT_TX_SUSPENDED
, &vsi
->back
->state
)) &&
4223 vsi
->type
== I40E_VSI_FCOE
) {
4224 dev_dbg(&vsi
->back
->pdev
->dev
,
4225 "VSI seid %d skipping FCoE VSI disable\n", vsi
->seid
);
4229 set_bit(__I40E_NEEDS_RESTART
, &vsi
->state
);
4230 if (vsi
->netdev
&& netif_running(vsi
->netdev
))
4231 vsi
->netdev
->netdev_ops
->ndo_stop(vsi
->netdev
);
4233 i40e_vsi_close(vsi
);
4237 * i40e_unquiesce_vsi - Resume a given VSI
4238 * @vsi: the VSI being resumed
4240 static void i40e_unquiesce_vsi(struct i40e_vsi
*vsi
)
4242 if (!test_bit(__I40E_NEEDS_RESTART
, &vsi
->state
))
4245 clear_bit(__I40E_NEEDS_RESTART
, &vsi
->state
);
4246 if (vsi
->netdev
&& netif_running(vsi
->netdev
))
4247 vsi
->netdev
->netdev_ops
->ndo_open(vsi
->netdev
);
4249 i40e_vsi_open(vsi
); /* this clears the DOWN bit */
4253 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
4256 static void i40e_pf_quiesce_all_vsi(struct i40e_pf
*pf
)
4260 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4262 i40e_quiesce_vsi(pf
->vsi
[v
]);
4267 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
4270 static void i40e_pf_unquiesce_all_vsi(struct i40e_pf
*pf
)
4274 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4276 i40e_unquiesce_vsi(pf
->vsi
[v
]);
4280 #ifdef CONFIG_I40E_DCB
4282 * i40e_vsi_wait_txq_disabled - Wait for VSI's queues to be disabled
4283 * @vsi: the VSI being configured
4285 * This function waits for the given VSI's Tx queues to be disabled.
4287 static int i40e_vsi_wait_txq_disabled(struct i40e_vsi
*vsi
)
4289 struct i40e_pf
*pf
= vsi
->back
;
4292 pf_q
= vsi
->base_queue
;
4293 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
4294 /* Check and wait for the disable status of the queue */
4295 ret
= i40e_pf_txq_wait(pf
, pf_q
, false);
4297 dev_info(&pf
->pdev
->dev
,
4298 "VSI seid %d Tx ring %d disable timeout\n",
4308 * i40e_pf_wait_txq_disabled - Wait for all queues of PF VSIs to be disabled
4311 * This function waits for the Tx queues to be in disabled state for all the
4312 * VSIs that are managed by this PF.
4314 static int i40e_pf_wait_txq_disabled(struct i40e_pf
*pf
)
4318 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
; v
++) {
4319 /* No need to wait for FCoE VSI queues */
4320 if (pf
->vsi
[v
] && pf
->vsi
[v
]->type
!= I40E_VSI_FCOE
) {
4321 ret
= i40e_vsi_wait_txq_disabled(pf
->vsi
[v
]);
4333 * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
4334 * @q_idx: TX queue number
4335 * @vsi: Pointer to VSI struct
4337 * This function checks specified queue for given VSI. Detects hung condition.
4338 * Sets hung bit since it is two step process. Before next run of service task
4339 * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not,
4340 * hung condition remain unchanged and during subsequent run, this function
4341 * issues SW interrupt to recover from hung condition.
4343 static void i40e_detect_recover_hung_queue(int q_idx
, struct i40e_vsi
*vsi
)
4345 struct i40e_ring
*tx_ring
= NULL
;
4347 u32 head
, val
, tx_pending
;
4352 /* now that we have an index, find the tx_ring struct */
4353 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
4354 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
) {
4355 if (q_idx
== vsi
->tx_rings
[i
]->queue_index
) {
4356 tx_ring
= vsi
->tx_rings
[i
];
4365 /* Read interrupt register */
4366 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
4368 I40E_PFINT_DYN_CTLN(tx_ring
->q_vector
->v_idx
+
4369 tx_ring
->vsi
->base_vector
- 1));
4371 val
= rd32(&pf
->hw
, I40E_PFINT_DYN_CTL0
);
4373 /* Bail out if interrupts are disabled because napi_poll
4374 * execution in-progress or will get scheduled soon.
4375 * napi_poll cleans TX and RX queues and updates 'next_to_clean'.
4377 if (!(val
& I40E_PFINT_DYN_CTLN_INTENA_MASK
))
4380 head
= i40e_get_head(tx_ring
);
4382 tx_pending
= i40e_get_tx_pending(tx_ring
);
4384 /* HW is done executing descriptors, updated HEAD write back,
4385 * but SW hasn't processed those descriptors. If interrupt is
4386 * not generated from this point ON, it could result into
4387 * dev_watchdog detecting timeout on those netdev_queue,
4388 * hence proactively trigger SW interrupt.
4391 /* NAPI Poll didn't run and clear since it was set */
4392 if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT
,
4393 &tx_ring
->q_vector
->hung_detected
)) {
4394 netdev_info(vsi
->netdev
, "VSI_seid %d, Hung TX queue %d, tx_pending: %d, NTC:0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x\n",
4395 vsi
->seid
, q_idx
, tx_pending
,
4396 tx_ring
->next_to_clean
, head
,
4397 tx_ring
->next_to_use
,
4398 readl(tx_ring
->tail
));
4399 netdev_info(vsi
->netdev
, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n",
4400 vsi
->seid
, q_idx
, val
);
4401 i40e_force_wb(vsi
, tx_ring
->q_vector
);
4403 /* First Chance - detected possible hung */
4404 set_bit(I40E_Q_VECTOR_HUNG_DETECT
,
4405 &tx_ring
->q_vector
->hung_detected
);
4411 * i40e_detect_recover_hung - Function to detect and recover hung_queues
4412 * @pf: pointer to PF struct
4414 * LAN VSI has netdev and netdev has TX queues. This function is to check
4415 * each of those TX queues if they are hung, trigger recovery by issuing
4418 static void i40e_detect_recover_hung(struct i40e_pf
*pf
)
4420 struct net_device
*netdev
;
4421 struct i40e_vsi
*vsi
;
4424 /* Only for LAN VSI */
4425 vsi
= pf
->vsi
[pf
->lan_vsi
];
4430 /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
4431 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
4432 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
4435 /* Make sure type is MAIN VSI */
4436 if (vsi
->type
!= I40E_VSI_MAIN
)
4439 netdev
= vsi
->netdev
;
4443 /* Bail out if netif_carrier is not OK */
4444 if (!netif_carrier_ok(netdev
))
4447 /* Go thru' TX queues for netdev */
4448 for (i
= 0; i
< netdev
->num_tx_queues
; i
++) {
4449 struct netdev_queue
*q
;
4451 q
= netdev_get_tx_queue(netdev
, i
);
4453 i40e_detect_recover_hung_queue(i
, vsi
);
4458 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
4459 * @pf: pointer to PF
4461 * Get TC map for ISCSI PF type that will include iSCSI TC
4464 static u8
i40e_get_iscsi_tc_map(struct i40e_pf
*pf
)
4466 struct i40e_dcb_app_priority_table app
;
4467 struct i40e_hw
*hw
= &pf
->hw
;
4468 u8 enabled_tc
= 1; /* TC0 is always enabled */
4470 /* Get the iSCSI APP TLV */
4471 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4473 for (i
= 0; i
< dcbcfg
->numapps
; i
++) {
4474 app
= dcbcfg
->app
[i
];
4475 if (app
.selector
== I40E_APP_SEL_TCPIP
&&
4476 app
.protocolid
== I40E_APP_PROTOID_ISCSI
) {
4477 tc
= dcbcfg
->etscfg
.prioritytable
[app
.priority
];
4478 enabled_tc
|= BIT(tc
);
4487 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
4488 * @dcbcfg: the corresponding DCBx configuration structure
4490 * Return the number of TCs from given DCBx configuration
4492 static u8
i40e_dcb_get_num_tc(struct i40e_dcbx_config
*dcbcfg
)
4497 /* Scan the ETS Config Priority Table to find
4498 * traffic class enabled for a given priority
4499 * and use the traffic class index to get the
4500 * number of traffic classes enabled
4502 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
4503 if (dcbcfg
->etscfg
.prioritytable
[i
] > num_tc
)
4504 num_tc
= dcbcfg
->etscfg
.prioritytable
[i
];
4507 /* Traffic class index starts from zero so
4508 * increment to return the actual count
4514 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
4515 * @dcbcfg: the corresponding DCBx configuration structure
4517 * Query the current DCB configuration and return the number of
4518 * traffic classes enabled from the given DCBX config
4520 static u8
i40e_dcb_get_enabled_tc(struct i40e_dcbx_config
*dcbcfg
)
4522 u8 num_tc
= i40e_dcb_get_num_tc(dcbcfg
);
4526 for (i
= 0; i
< num_tc
; i
++)
4527 enabled_tc
|= BIT(i
);
4533 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
4534 * @pf: PF being queried
4536 * Return number of traffic classes enabled for the given PF
4538 static u8
i40e_pf_get_num_tc(struct i40e_pf
*pf
)
4540 struct i40e_hw
*hw
= &pf
->hw
;
4543 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4545 /* If DCB is not enabled then always in single TC */
4546 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
4549 /* SFP mode will be enabled for all TCs on port */
4550 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
4551 return i40e_dcb_get_num_tc(dcbcfg
);
4553 /* MFP mode return count of enabled TCs for this PF */
4554 if (pf
->hw
.func_caps
.iscsi
)
4555 enabled_tc
= i40e_get_iscsi_tc_map(pf
);
4557 return 1; /* Only TC0 */
4559 /* At least have TC0 */
4560 enabled_tc
= (enabled_tc
? enabled_tc
: 0x1);
4561 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4562 if (enabled_tc
& BIT(i
))
4569 * i40e_pf_get_default_tc - Get bitmap for first enabled TC
4570 * @pf: PF being queried
4572 * Return a bitmap for first enabled traffic class for this PF.
4574 static u8
i40e_pf_get_default_tc(struct i40e_pf
*pf
)
4576 u8 enabled_tc
= pf
->hw
.func_caps
.enabled_tcmap
;
4580 return 0x1; /* TC0 */
4582 /* Find the first enabled TC */
4583 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4584 if (enabled_tc
& BIT(i
))
4592 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
4593 * @pf: PF being queried
4595 * Return a bitmap for enabled traffic classes for this PF.
4597 static u8
i40e_pf_get_tc_map(struct i40e_pf
*pf
)
4599 /* If DCB is not enabled for this PF then just return default TC */
4600 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
4601 return i40e_pf_get_default_tc(pf
);
4603 /* SFP mode we want PF to be enabled for all TCs */
4604 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
4605 return i40e_dcb_get_enabled_tc(&pf
->hw
.local_dcbx_config
);
4607 /* MFP enabled and iSCSI PF type */
4608 if (pf
->hw
.func_caps
.iscsi
)
4609 return i40e_get_iscsi_tc_map(pf
);
4611 return i40e_pf_get_default_tc(pf
);
4615 * i40e_vsi_get_bw_info - Query VSI BW Information
4616 * @vsi: the VSI being queried
4618 * Returns 0 on success, negative value on failure
4620 static int i40e_vsi_get_bw_info(struct i40e_vsi
*vsi
)
4622 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config
= {0};
4623 struct i40e_aqc_query_vsi_bw_config_resp bw_config
= {0};
4624 struct i40e_pf
*pf
= vsi
->back
;
4625 struct i40e_hw
*hw
= &pf
->hw
;
4630 /* Get the VSI level BW configuration */
4631 ret
= i40e_aq_query_vsi_bw_config(hw
, vsi
->seid
, &bw_config
, NULL
);
4633 dev_info(&pf
->pdev
->dev
,
4634 "couldn't get PF vsi bw config, err %s aq_err %s\n",
4635 i40e_stat_str(&pf
->hw
, ret
),
4636 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4640 /* Get the VSI level BW configuration per TC */
4641 ret
= i40e_aq_query_vsi_ets_sla_config(hw
, vsi
->seid
, &bw_ets_config
,
4644 dev_info(&pf
->pdev
->dev
,
4645 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
4646 i40e_stat_str(&pf
->hw
, ret
),
4647 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4651 if (bw_config
.tc_valid_bits
!= bw_ets_config
.tc_valid_bits
) {
4652 dev_info(&pf
->pdev
->dev
,
4653 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
4654 bw_config
.tc_valid_bits
,
4655 bw_ets_config
.tc_valid_bits
);
4656 /* Still continuing */
4659 vsi
->bw_limit
= le16_to_cpu(bw_config
.port_bw_limit
);
4660 vsi
->bw_max_quanta
= bw_config
.max_bw
;
4661 tc_bw_max
= le16_to_cpu(bw_ets_config
.tc_bw_max
[0]) |
4662 (le16_to_cpu(bw_ets_config
.tc_bw_max
[1]) << 16);
4663 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4664 vsi
->bw_ets_share_credits
[i
] = bw_ets_config
.share_credits
[i
];
4665 vsi
->bw_ets_limit_credits
[i
] =
4666 le16_to_cpu(bw_ets_config
.credits
[i
]);
4667 /* 3 bits out of 4 for each TC */
4668 vsi
->bw_ets_max_quanta
[i
] = (u8
)((tc_bw_max
>> (i
*4)) & 0x7);
4675 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
4676 * @vsi: the VSI being configured
4677 * @enabled_tc: TC bitmap
4678 * @bw_credits: BW shared credits per TC
4680 * Returns 0 on success, negative value on failure
4682 static int i40e_vsi_configure_bw_alloc(struct i40e_vsi
*vsi
, u8 enabled_tc
,
4685 struct i40e_aqc_configure_vsi_tc_bw_data bw_data
;
4689 bw_data
.tc_valid_bits
= enabled_tc
;
4690 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
4691 bw_data
.tc_bw_credits
[i
] = bw_share
[i
];
4693 ret
= i40e_aq_config_vsi_tc_bw(&vsi
->back
->hw
, vsi
->seid
, &bw_data
,
4696 dev_info(&vsi
->back
->pdev
->dev
,
4697 "AQ command Config VSI BW allocation per TC failed = %d\n",
4698 vsi
->back
->hw
.aq
.asq_last_status
);
4702 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
4703 vsi
->info
.qs_handle
[i
] = bw_data
.qs_handles
[i
];
4709 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
4710 * @vsi: the VSI being configured
4711 * @enabled_tc: TC map to be enabled
4714 static void i40e_vsi_config_netdev_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
4716 struct net_device
*netdev
= vsi
->netdev
;
4717 struct i40e_pf
*pf
= vsi
->back
;
4718 struct i40e_hw
*hw
= &pf
->hw
;
4721 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4727 netdev_reset_tc(netdev
);
4731 /* Set up actual enabled TCs on the VSI */
4732 if (netdev_set_num_tc(netdev
, vsi
->tc_config
.numtc
))
4735 /* set per TC queues for the VSI */
4736 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4737 /* Only set TC queues for enabled tcs
4739 * e.g. For a VSI that has TC0 and TC3 enabled the
4740 * enabled_tc bitmap would be 0x00001001; the driver
4741 * will set the numtc for netdev as 2 that will be
4742 * referenced by the netdev layer as TC 0 and 1.
4744 if (vsi
->tc_config
.enabled_tc
& BIT(i
))
4745 netdev_set_tc_queue(netdev
,
4746 vsi
->tc_config
.tc_info
[i
].netdev_tc
,
4747 vsi
->tc_config
.tc_info
[i
].qcount
,
4748 vsi
->tc_config
.tc_info
[i
].qoffset
);
4751 /* Assign UP2TC map for the VSI */
4752 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
4753 /* Get the actual TC# for the UP */
4754 u8 ets_tc
= dcbcfg
->etscfg
.prioritytable
[i
];
4755 /* Get the mapped netdev TC# for the UP */
4756 netdev_tc
= vsi
->tc_config
.tc_info
[ets_tc
].netdev_tc
;
4757 netdev_set_prio_tc_map(netdev
, i
, netdev_tc
);
4762 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
4763 * @vsi: the VSI being configured
4764 * @ctxt: the ctxt buffer returned from AQ VSI update param command
4766 static void i40e_vsi_update_queue_map(struct i40e_vsi
*vsi
,
4767 struct i40e_vsi_context
*ctxt
)
4769 /* copy just the sections touched not the entire info
4770 * since not all sections are valid as returned by
4773 vsi
->info
.mapping_flags
= ctxt
->info
.mapping_flags
;
4774 memcpy(&vsi
->info
.queue_mapping
,
4775 &ctxt
->info
.queue_mapping
, sizeof(vsi
->info
.queue_mapping
));
4776 memcpy(&vsi
->info
.tc_mapping
, ctxt
->info
.tc_mapping
,
4777 sizeof(vsi
->info
.tc_mapping
));
4781 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
4782 * @vsi: VSI to be configured
4783 * @enabled_tc: TC bitmap
4785 * This configures a particular VSI for TCs that are mapped to the
4786 * given TC bitmap. It uses default bandwidth share for TCs across
4787 * VSIs to configure TC for a particular VSI.
4790 * It is expected that the VSI queues have been quisced before calling
4793 static int i40e_vsi_config_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
4795 u8 bw_share
[I40E_MAX_TRAFFIC_CLASS
] = {0};
4796 struct i40e_vsi_context ctxt
;
4800 /* Check if enabled_tc is same as existing or new TCs */
4801 if (vsi
->tc_config
.enabled_tc
== enabled_tc
)
4804 /* Enable ETS TCs with equal BW Share for now across all VSIs */
4805 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4806 if (enabled_tc
& BIT(i
))
4810 ret
= i40e_vsi_configure_bw_alloc(vsi
, enabled_tc
, bw_share
);
4812 dev_info(&vsi
->back
->pdev
->dev
,
4813 "Failed configuring TC map %d for VSI %d\n",
4814 enabled_tc
, vsi
->seid
);
4818 /* Update Queue Pairs Mapping for currently enabled UPs */
4819 ctxt
.seid
= vsi
->seid
;
4820 ctxt
.pf_num
= vsi
->back
->hw
.pf_id
;
4822 ctxt
.uplink_seid
= vsi
->uplink_seid
;
4823 ctxt
.info
= vsi
->info
;
4824 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
4826 /* Update the VSI after updating the VSI queue-mapping information */
4827 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
4829 dev_info(&vsi
->back
->pdev
->dev
,
4830 "Update vsi tc config failed, err %s aq_err %s\n",
4831 i40e_stat_str(&vsi
->back
->hw
, ret
),
4832 i40e_aq_str(&vsi
->back
->hw
,
4833 vsi
->back
->hw
.aq
.asq_last_status
));
4836 /* update the local VSI info with updated queue map */
4837 i40e_vsi_update_queue_map(vsi
, &ctxt
);
4838 vsi
->info
.valid_sections
= 0;
4840 /* Update current VSI BW information */
4841 ret
= i40e_vsi_get_bw_info(vsi
);
4843 dev_info(&vsi
->back
->pdev
->dev
,
4844 "Failed updating vsi bw info, err %s aq_err %s\n",
4845 i40e_stat_str(&vsi
->back
->hw
, ret
),
4846 i40e_aq_str(&vsi
->back
->hw
,
4847 vsi
->back
->hw
.aq
.asq_last_status
));
4851 /* Update the netdev TC setup */
4852 i40e_vsi_config_netdev_tc(vsi
, enabled_tc
);
4858 * i40e_veb_config_tc - Configure TCs for given VEB
4860 * @enabled_tc: TC bitmap
4862 * Configures given TC bitmap for VEB (switching) element
4864 int i40e_veb_config_tc(struct i40e_veb
*veb
, u8 enabled_tc
)
4866 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data
= {0};
4867 struct i40e_pf
*pf
= veb
->pf
;
4871 /* No TCs or already enabled TCs just return */
4872 if (!enabled_tc
|| veb
->enabled_tc
== enabled_tc
)
4875 bw_data
.tc_valid_bits
= enabled_tc
;
4876 /* bw_data.absolute_credits is not set (relative) */
4878 /* Enable ETS TCs with equal BW Share for now */
4879 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4880 if (enabled_tc
& BIT(i
))
4881 bw_data
.tc_bw_share_credits
[i
] = 1;
4884 ret
= i40e_aq_config_switch_comp_bw_config(&pf
->hw
, veb
->seid
,
4887 dev_info(&pf
->pdev
->dev
,
4888 "VEB bw config failed, err %s aq_err %s\n",
4889 i40e_stat_str(&pf
->hw
, ret
),
4890 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4894 /* Update the BW information */
4895 ret
= i40e_veb_get_bw_info(veb
);
4897 dev_info(&pf
->pdev
->dev
,
4898 "Failed getting veb bw config, err %s aq_err %s\n",
4899 i40e_stat_str(&pf
->hw
, ret
),
4900 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4907 #ifdef CONFIG_I40E_DCB
4909 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
4912 * Reconfigure VEB/VSIs on a given PF; it is assumed that
4913 * the caller would've quiesce all the VSIs before calling
4916 static void i40e_dcb_reconfigure(struct i40e_pf
*pf
)
4922 /* Enable the TCs available on PF to all VEBs */
4923 tc_map
= i40e_pf_get_tc_map(pf
);
4924 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
4927 ret
= i40e_veb_config_tc(pf
->veb
[v
], tc_map
);
4929 dev_info(&pf
->pdev
->dev
,
4930 "Failed configuring TC for VEB seid=%d\n",
4932 /* Will try to configure as many components */
4936 /* Update each VSI */
4937 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4941 /* - Enable all TCs for the LAN VSI
4943 * - For FCoE VSI only enable the TC configured
4944 * as per the APP TLV
4946 * - For all others keep them at TC0 for now
4948 if (v
== pf
->lan_vsi
)
4949 tc_map
= i40e_pf_get_tc_map(pf
);
4951 tc_map
= i40e_pf_get_default_tc(pf
);
4953 if (pf
->vsi
[v
]->type
== I40E_VSI_FCOE
)
4954 tc_map
= i40e_get_fcoe_tc_map(pf
);
4955 #endif /* #ifdef I40E_FCOE */
4957 ret
= i40e_vsi_config_tc(pf
->vsi
[v
], tc_map
);
4959 dev_info(&pf
->pdev
->dev
,
4960 "Failed configuring TC for VSI seid=%d\n",
4962 /* Will try to configure as many components */
4964 /* Re-configure VSI vectors based on updated TC map */
4965 i40e_vsi_map_rings_to_vectors(pf
->vsi
[v
]);
4966 if (pf
->vsi
[v
]->netdev
)
4967 i40e_dcbnl_set_all(pf
->vsi
[v
]);
4973 * i40e_resume_port_tx - Resume port Tx
4976 * Resume a port's Tx and issue a PF reset in case of failure to
4979 static int i40e_resume_port_tx(struct i40e_pf
*pf
)
4981 struct i40e_hw
*hw
= &pf
->hw
;
4984 ret
= i40e_aq_resume_port_tx(hw
, NULL
);
4986 dev_info(&pf
->pdev
->dev
,
4987 "Resume Port Tx failed, err %s aq_err %s\n",
4988 i40e_stat_str(&pf
->hw
, ret
),
4989 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4990 /* Schedule PF reset to recover */
4991 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
4992 i40e_service_event_schedule(pf
);
4999 * i40e_init_pf_dcb - Initialize DCB configuration
5000 * @pf: PF being configured
5002 * Query the current DCB configuration and cache it
5003 * in the hardware structure
5005 static int i40e_init_pf_dcb(struct i40e_pf
*pf
)
5007 struct i40e_hw
*hw
= &pf
->hw
;
5010 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
5011 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
5012 (pf
->hw
.aq
.fw_maj_ver
< 4))
5015 /* Get the initial DCB configuration */
5016 err
= i40e_init_dcb(hw
);
5018 /* Device/Function is not DCBX capable */
5019 if ((!hw
->func_caps
.dcb
) ||
5020 (hw
->dcbx_status
== I40E_DCBX_STATUS_DISABLED
)) {
5021 dev_info(&pf
->pdev
->dev
,
5022 "DCBX offload is not supported or is disabled for this PF.\n");
5024 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
)
5028 /* When status is not DISABLED then DCBX in FW */
5029 pf
->dcbx_cap
= DCB_CAP_DCBX_LLD_MANAGED
|
5030 DCB_CAP_DCBX_VER_IEEE
;
5032 pf
->flags
|= I40E_FLAG_DCB_CAPABLE
;
5033 /* Enable DCB tagging only when more than one TC */
5034 if (i40e_dcb_get_num_tc(&hw
->local_dcbx_config
) > 1)
5035 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
5036 dev_dbg(&pf
->pdev
->dev
,
5037 "DCBX offload is supported for this PF.\n");
5040 dev_info(&pf
->pdev
->dev
,
5041 "Query for DCB configuration failed, err %s aq_err %s\n",
5042 i40e_stat_str(&pf
->hw
, err
),
5043 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
5049 #endif /* CONFIG_I40E_DCB */
5050 #define SPEED_SIZE 14
5053 * i40e_print_link_message - print link up or down
5054 * @vsi: the VSI for which link needs a message
5056 void i40e_print_link_message(struct i40e_vsi
*vsi
, bool isup
)
5058 char *speed
= "Unknown";
5059 char *fc
= "Unknown";
5061 if (vsi
->current_isup
== isup
)
5063 vsi
->current_isup
= isup
;
5065 netdev_info(vsi
->netdev
, "NIC Link is Down\n");
5069 /* Warn user if link speed on NPAR enabled partition is not at
5072 if (vsi
->back
->hw
.func_caps
.npar_enable
&&
5073 (vsi
->back
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_1GB
||
5074 vsi
->back
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_100MB
))
5075 netdev_warn(vsi
->netdev
,
5076 "The partition detected link speed that is less than 10Gbps\n");
5078 switch (vsi
->back
->hw
.phy
.link_info
.link_speed
) {
5079 case I40E_LINK_SPEED_40GB
:
5082 case I40E_LINK_SPEED_20GB
:
5085 case I40E_LINK_SPEED_10GB
:
5088 case I40E_LINK_SPEED_1GB
:
5091 case I40E_LINK_SPEED_100MB
:
5098 switch (vsi
->back
->hw
.fc
.current_mode
) {
5102 case I40E_FC_TX_PAUSE
:
5105 case I40E_FC_RX_PAUSE
:
5113 netdev_info(vsi
->netdev
, "NIC Link is Up %sbps Full Duplex, Flow Control: %s\n",
5118 * i40e_up_complete - Finish the last steps of bringing up a connection
5119 * @vsi: the VSI being configured
5121 static int i40e_up_complete(struct i40e_vsi
*vsi
)
5123 struct i40e_pf
*pf
= vsi
->back
;
5126 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
5127 i40e_vsi_configure_msix(vsi
);
5129 i40e_configure_msi_and_legacy(vsi
);
5132 err
= i40e_vsi_control_rings(vsi
, true);
5136 clear_bit(__I40E_DOWN
, &vsi
->state
);
5137 i40e_napi_enable_all(vsi
);
5138 i40e_vsi_enable_irq(vsi
);
5140 if ((pf
->hw
.phy
.link_info
.link_info
& I40E_AQ_LINK_UP
) &&
5142 i40e_print_link_message(vsi
, true);
5143 netif_tx_start_all_queues(vsi
->netdev
);
5144 netif_carrier_on(vsi
->netdev
);
5145 } else if (vsi
->netdev
) {
5146 i40e_print_link_message(vsi
, false);
5147 /* need to check for qualified module here*/
5148 if ((pf
->hw
.phy
.link_info
.link_info
&
5149 I40E_AQ_MEDIA_AVAILABLE
) &&
5150 (!(pf
->hw
.phy
.link_info
.an_info
&
5151 I40E_AQ_QUALIFIED_MODULE
)))
5152 netdev_err(vsi
->netdev
,
5153 "the driver failed to link because an unqualified module was detected.");
5156 /* replay FDIR SB filters */
5157 if (vsi
->type
== I40E_VSI_FDIR
) {
5158 /* reset fd counters */
5159 pf
->fd_add_err
= pf
->fd_atr_cnt
= 0;
5160 if (pf
->fd_tcp_rule
> 0) {
5161 pf
->flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
5162 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5163 dev_info(&pf
->pdev
->dev
, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
5164 pf
->fd_tcp_rule
= 0;
5166 i40e_fdir_filter_restore(vsi
);
5168 i40e_service_event_schedule(pf
);
5174 * i40e_vsi_reinit_locked - Reset the VSI
5175 * @vsi: the VSI being configured
5177 * Rebuild the ring structs after some configuration
5178 * has changed, e.g. MTU size.
5180 static void i40e_vsi_reinit_locked(struct i40e_vsi
*vsi
)
5182 struct i40e_pf
*pf
= vsi
->back
;
5184 WARN_ON(in_interrupt());
5185 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
5186 usleep_range(1000, 2000);
5189 /* Give a VF some time to respond to the reset. The
5190 * two second wait is based upon the watchdog cycle in
5193 if (vsi
->type
== I40E_VSI_SRIOV
)
5196 clear_bit(__I40E_CONFIG_BUSY
, &pf
->state
);
5200 * i40e_up - Bring the connection back up after being down
5201 * @vsi: the VSI being configured
5203 int i40e_up(struct i40e_vsi
*vsi
)
5207 err
= i40e_vsi_configure(vsi
);
5209 err
= i40e_up_complete(vsi
);
5215 * i40e_down - Shutdown the connection processing
5216 * @vsi: the VSI being stopped
5218 void i40e_down(struct i40e_vsi
*vsi
)
5222 /* It is assumed that the caller of this function
5223 * sets the vsi->state __I40E_DOWN bit.
5226 netif_carrier_off(vsi
->netdev
);
5227 netif_tx_disable(vsi
->netdev
);
5229 i40e_vsi_disable_irq(vsi
);
5230 i40e_vsi_control_rings(vsi
, false);
5231 i40e_napi_disable_all(vsi
);
5233 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
5234 i40e_clean_tx_ring(vsi
->tx_rings
[i
]);
5235 i40e_clean_rx_ring(vsi
->rx_rings
[i
]);
5240 * i40e_setup_tc - configure multiple traffic classes
5241 * @netdev: net device to configure
5242 * @tc: number of traffic classes to enable
5245 int i40e_setup_tc(struct net_device
*netdev
, u8 tc
)
5247 static int i40e_setup_tc(struct net_device
*netdev
, u8 tc
)
5250 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
5251 struct i40e_vsi
*vsi
= np
->vsi
;
5252 struct i40e_pf
*pf
= vsi
->back
;
5257 /* Check if DCB enabled to continue */
5258 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
)) {
5259 netdev_info(netdev
, "DCB is not enabled for adapter\n");
5263 /* Check if MFP enabled */
5264 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
5265 netdev_info(netdev
, "Configuring TC not supported in MFP mode\n");
5269 /* Check whether tc count is within enabled limit */
5270 if (tc
> i40e_pf_get_num_tc(pf
)) {
5271 netdev_info(netdev
, "TC count greater than enabled on link for adapter\n");
5275 /* Generate TC map for number of tc requested */
5276 for (i
= 0; i
< tc
; i
++)
5277 enabled_tc
|= BIT(i
);
5279 /* Requesting same TC configuration as already enabled */
5280 if (enabled_tc
== vsi
->tc_config
.enabled_tc
)
5283 /* Quiesce VSI queues */
5284 i40e_quiesce_vsi(vsi
);
5286 /* Configure VSI for enabled TCs */
5287 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
5289 netdev_info(netdev
, "Failed configuring TC for VSI seid=%d\n",
5295 i40e_unquiesce_vsi(vsi
);
5302 * i40e_open - Called when a network interface is made active
5303 * @netdev: network interface device structure
5305 * The open entry point is called when a network interface is made
5306 * active by the system (IFF_UP). At this point all resources needed
5307 * for transmit and receive operations are allocated, the interrupt
5308 * handler is registered with the OS, the netdev watchdog subtask is
5309 * enabled, and the stack is notified that the interface is ready.
5311 * Returns 0 on success, negative value on failure
5313 int i40e_open(struct net_device
*netdev
)
5315 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
5316 struct i40e_vsi
*vsi
= np
->vsi
;
5317 struct i40e_pf
*pf
= vsi
->back
;
5320 /* disallow open during test or if eeprom is broken */
5321 if (test_bit(__I40E_TESTING
, &pf
->state
) ||
5322 test_bit(__I40E_BAD_EEPROM
, &pf
->state
))
5325 netif_carrier_off(netdev
);
5327 err
= i40e_vsi_open(vsi
);
5331 /* configure global TSO hardware offload settings */
5332 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_F
, be32_to_cpu(TCP_FLAG_PSH
|
5333 TCP_FLAG_FIN
) >> 16);
5334 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_M
, be32_to_cpu(TCP_FLAG_PSH
|
5336 TCP_FLAG_CWR
) >> 16);
5337 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_L
, be32_to_cpu(TCP_FLAG_CWR
) >> 16);
5339 #ifdef CONFIG_I40E_VXLAN
5340 vxlan_get_rx_port(netdev
);
5348 * @vsi: the VSI to open
5350 * Finish initialization of the VSI.
5352 * Returns 0 on success, negative value on failure
5354 int i40e_vsi_open(struct i40e_vsi
*vsi
)
5356 struct i40e_pf
*pf
= vsi
->back
;
5357 char int_name
[I40E_INT_NAME_STR_LEN
];
5360 /* allocate descriptors */
5361 err
= i40e_vsi_setup_tx_resources(vsi
);
5364 err
= i40e_vsi_setup_rx_resources(vsi
);
5368 err
= i40e_vsi_configure(vsi
);
5373 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s",
5374 dev_driver_string(&pf
->pdev
->dev
), vsi
->netdev
->name
);
5375 err
= i40e_vsi_request_irq(vsi
, int_name
);
5379 /* Notify the stack of the actual queue counts. */
5380 err
= netif_set_real_num_tx_queues(vsi
->netdev
,
5381 vsi
->num_queue_pairs
);
5383 goto err_set_queues
;
5385 err
= netif_set_real_num_rx_queues(vsi
->netdev
,
5386 vsi
->num_queue_pairs
);
5388 goto err_set_queues
;
5390 } else if (vsi
->type
== I40E_VSI_FDIR
) {
5391 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s:fdir",
5392 dev_driver_string(&pf
->pdev
->dev
),
5393 dev_name(&pf
->pdev
->dev
));
5394 err
= i40e_vsi_request_irq(vsi
, int_name
);
5401 err
= i40e_up_complete(vsi
);
5403 goto err_up_complete
;
5410 i40e_vsi_free_irq(vsi
);
5412 i40e_vsi_free_rx_resources(vsi
);
5414 i40e_vsi_free_tx_resources(vsi
);
5415 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
5416 i40e_do_reset(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
5422 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
5423 * @pf: Pointer to PF
5425 * This function destroys the hlist where all the Flow Director
5426 * filters were saved.
5428 static void i40e_fdir_filter_exit(struct i40e_pf
*pf
)
5430 struct i40e_fdir_filter
*filter
;
5431 struct hlist_node
*node2
;
5433 hlist_for_each_entry_safe(filter
, node2
,
5434 &pf
->fdir_filter_list
, fdir_node
) {
5435 hlist_del(&filter
->fdir_node
);
5438 pf
->fdir_pf_active_filters
= 0;
5442 * i40e_close - Disables a network interface
5443 * @netdev: network interface device structure
5445 * The close entry point is called when an interface is de-activated
5446 * by the OS. The hardware is still under the driver's control, but
5447 * this netdev interface is disabled.
5449 * Returns 0, this is not allowed to fail
5452 int i40e_close(struct net_device
*netdev
)
5454 static int i40e_close(struct net_device
*netdev
)
5457 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
5458 struct i40e_vsi
*vsi
= np
->vsi
;
5460 i40e_vsi_close(vsi
);
5466 * i40e_do_reset - Start a PF or Core Reset sequence
5467 * @pf: board private structure
5468 * @reset_flags: which reset is requested
5470 * The essential difference in resets is that the PF Reset
5471 * doesn't clear the packet buffers, doesn't reset the PE
5472 * firmware, and doesn't bother the other PFs on the chip.
5474 void i40e_do_reset(struct i40e_pf
*pf
, u32 reset_flags
)
5478 WARN_ON(in_interrupt());
5480 if (i40e_check_asq_alive(&pf
->hw
))
5481 i40e_vc_notify_reset(pf
);
5483 /* do the biggest reset indicated */
5484 if (reset_flags
& BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED
)) {
5486 /* Request a Global Reset
5488 * This will start the chip's countdown to the actual full
5489 * chip reset event, and a warning interrupt to be sent
5490 * to all PFs, including the requestor. Our handler
5491 * for the warning interrupt will deal with the shutdown
5492 * and recovery of the switch setup.
5494 dev_dbg(&pf
->pdev
->dev
, "GlobalR requested\n");
5495 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
5496 val
|= I40E_GLGEN_RTRIG_GLOBR_MASK
;
5497 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
5499 } else if (reset_flags
& BIT_ULL(__I40E_CORE_RESET_REQUESTED
)) {
5501 /* Request a Core Reset
5503 * Same as Global Reset, except does *not* include the MAC/PHY
5505 dev_dbg(&pf
->pdev
->dev
, "CoreR requested\n");
5506 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
5507 val
|= I40E_GLGEN_RTRIG_CORER_MASK
;
5508 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
5509 i40e_flush(&pf
->hw
);
5511 } else if (reset_flags
& BIT_ULL(__I40E_PF_RESET_REQUESTED
)) {
5513 /* Request a PF Reset
5515 * Resets only the PF-specific registers
5517 * This goes directly to the tear-down and rebuild of
5518 * the switch, since we need to do all the recovery as
5519 * for the Core Reset.
5521 dev_dbg(&pf
->pdev
->dev
, "PFR requested\n");
5522 i40e_handle_reset_warning(pf
);
5524 } else if (reset_flags
& BIT_ULL(__I40E_REINIT_REQUESTED
)) {
5527 /* Find the VSI(s) that requested a re-init */
5528 dev_info(&pf
->pdev
->dev
,
5529 "VSI reinit requested\n");
5530 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5531 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
5534 test_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
)) {
5535 i40e_vsi_reinit_locked(pf
->vsi
[v
]);
5536 clear_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
);
5539 } else if (reset_flags
& BIT_ULL(__I40E_DOWN_REQUESTED
)) {
5542 /* Find the VSI(s) that needs to be brought down */
5543 dev_info(&pf
->pdev
->dev
, "VSI down requested\n");
5544 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5545 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
5548 test_bit(__I40E_DOWN_REQUESTED
, &vsi
->state
)) {
5549 set_bit(__I40E_DOWN
, &vsi
->state
);
5551 clear_bit(__I40E_DOWN_REQUESTED
, &vsi
->state
);
5555 dev_info(&pf
->pdev
->dev
,
5556 "bad reset request 0x%08x\n", reset_flags
);
5560 #ifdef CONFIG_I40E_DCB
5562 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
5563 * @pf: board private structure
5564 * @old_cfg: current DCB config
5565 * @new_cfg: new DCB config
5567 bool i40e_dcb_need_reconfig(struct i40e_pf
*pf
,
5568 struct i40e_dcbx_config
*old_cfg
,
5569 struct i40e_dcbx_config
*new_cfg
)
5571 bool need_reconfig
= false;
5573 /* Check if ETS configuration has changed */
5574 if (memcmp(&new_cfg
->etscfg
,
5576 sizeof(new_cfg
->etscfg
))) {
5577 /* If Priority Table has changed reconfig is needed */
5578 if (memcmp(&new_cfg
->etscfg
.prioritytable
,
5579 &old_cfg
->etscfg
.prioritytable
,
5580 sizeof(new_cfg
->etscfg
.prioritytable
))) {
5581 need_reconfig
= true;
5582 dev_dbg(&pf
->pdev
->dev
, "ETS UP2TC changed.\n");
5585 if (memcmp(&new_cfg
->etscfg
.tcbwtable
,
5586 &old_cfg
->etscfg
.tcbwtable
,
5587 sizeof(new_cfg
->etscfg
.tcbwtable
)))
5588 dev_dbg(&pf
->pdev
->dev
, "ETS TC BW Table changed.\n");
5590 if (memcmp(&new_cfg
->etscfg
.tsatable
,
5591 &old_cfg
->etscfg
.tsatable
,
5592 sizeof(new_cfg
->etscfg
.tsatable
)))
5593 dev_dbg(&pf
->pdev
->dev
, "ETS TSA Table changed.\n");
5596 /* Check if PFC configuration has changed */
5597 if (memcmp(&new_cfg
->pfc
,
5599 sizeof(new_cfg
->pfc
))) {
5600 need_reconfig
= true;
5601 dev_dbg(&pf
->pdev
->dev
, "PFC config change detected.\n");
5604 /* Check if APP Table has changed */
5605 if (memcmp(&new_cfg
->app
,
5607 sizeof(new_cfg
->app
))) {
5608 need_reconfig
= true;
5609 dev_dbg(&pf
->pdev
->dev
, "APP Table change detected.\n");
5612 dev_dbg(&pf
->pdev
->dev
, "dcb need_reconfig=%d\n", need_reconfig
);
5613 return need_reconfig
;
5617 * i40e_handle_lldp_event - Handle LLDP Change MIB event
5618 * @pf: board private structure
5619 * @e: event info posted on ARQ
5621 static int i40e_handle_lldp_event(struct i40e_pf
*pf
,
5622 struct i40e_arq_event_info
*e
)
5624 struct i40e_aqc_lldp_get_mib
*mib
=
5625 (struct i40e_aqc_lldp_get_mib
*)&e
->desc
.params
.raw
;
5626 struct i40e_hw
*hw
= &pf
->hw
;
5627 struct i40e_dcbx_config tmp_dcbx_cfg
;
5628 bool need_reconfig
= false;
5632 /* Not DCB capable or capability disabled */
5633 if (!(pf
->flags
& I40E_FLAG_DCB_CAPABLE
))
5636 /* Ignore if event is not for Nearest Bridge */
5637 type
= ((mib
->type
>> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT
)
5638 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK
);
5639 dev_dbg(&pf
->pdev
->dev
, "LLDP event mib bridge type 0x%x\n", type
);
5640 if (type
!= I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
)
5643 /* Check MIB Type and return if event for Remote MIB update */
5644 type
= mib
->type
& I40E_AQ_LLDP_MIB_TYPE_MASK
;
5645 dev_dbg(&pf
->pdev
->dev
,
5646 "LLDP event mib type %s\n", type
? "remote" : "local");
5647 if (type
== I40E_AQ_LLDP_MIB_REMOTE
) {
5648 /* Update the remote cached instance and return */
5649 ret
= i40e_aq_get_dcb_config(hw
, I40E_AQ_LLDP_MIB_REMOTE
,
5650 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
,
5651 &hw
->remote_dcbx_config
);
5655 /* Store the old configuration */
5656 tmp_dcbx_cfg
= hw
->local_dcbx_config
;
5658 /* Reset the old DCBx configuration data */
5659 memset(&hw
->local_dcbx_config
, 0, sizeof(hw
->local_dcbx_config
));
5660 /* Get updated DCBX data from firmware */
5661 ret
= i40e_get_dcb_config(&pf
->hw
);
5663 dev_info(&pf
->pdev
->dev
,
5664 "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
5665 i40e_stat_str(&pf
->hw
, ret
),
5666 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
5670 /* No change detected in DCBX configs */
5671 if (!memcmp(&tmp_dcbx_cfg
, &hw
->local_dcbx_config
,
5672 sizeof(tmp_dcbx_cfg
))) {
5673 dev_dbg(&pf
->pdev
->dev
, "No change detected in DCBX configuration.\n");
5677 need_reconfig
= i40e_dcb_need_reconfig(pf
, &tmp_dcbx_cfg
,
5678 &hw
->local_dcbx_config
);
5680 i40e_dcbnl_flush_apps(pf
, &tmp_dcbx_cfg
, &hw
->local_dcbx_config
);
5685 /* Enable DCB tagging only when more than one TC */
5686 if (i40e_dcb_get_num_tc(&hw
->local_dcbx_config
) > 1)
5687 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
5689 pf
->flags
&= ~I40E_FLAG_DCB_ENABLED
;
5691 set_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
);
5692 /* Reconfiguration needed quiesce all VSIs */
5693 i40e_pf_quiesce_all_vsi(pf
);
5695 /* Changes in configuration update VEB/VSI */
5696 i40e_dcb_reconfigure(pf
);
5698 ret
= i40e_resume_port_tx(pf
);
5700 clear_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
);
5701 /* In case of error no point in resuming VSIs */
5705 /* Wait for the PF's Tx queues to be disabled */
5706 ret
= i40e_pf_wait_txq_disabled(pf
);
5708 /* Schedule PF reset to recover */
5709 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
5710 i40e_service_event_schedule(pf
);
5712 i40e_pf_unquiesce_all_vsi(pf
);
5718 #endif /* CONFIG_I40E_DCB */
5721 * i40e_do_reset_safe - Protected reset path for userland calls.
5722 * @pf: board private structure
5723 * @reset_flags: which reset is requested
5726 void i40e_do_reset_safe(struct i40e_pf
*pf
, u32 reset_flags
)
5729 i40e_do_reset(pf
, reset_flags
);
5734 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
5735 * @pf: board private structure
5736 * @e: event info posted on ARQ
5738 * Handler for LAN Queue Overflow Event generated by the firmware for PF
5741 static void i40e_handle_lan_overflow_event(struct i40e_pf
*pf
,
5742 struct i40e_arq_event_info
*e
)
5744 struct i40e_aqc_lan_overflow
*data
=
5745 (struct i40e_aqc_lan_overflow
*)&e
->desc
.params
.raw
;
5746 u32 queue
= le32_to_cpu(data
->prtdcb_rupto
);
5747 u32 qtx_ctl
= le32_to_cpu(data
->otx_ctl
);
5748 struct i40e_hw
*hw
= &pf
->hw
;
5752 dev_dbg(&pf
->pdev
->dev
, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
5755 /* Queue belongs to VF, find the VF and issue VF reset */
5756 if (((qtx_ctl
& I40E_QTX_CTL_PFVF_Q_MASK
)
5757 >> I40E_QTX_CTL_PFVF_Q_SHIFT
) == I40E_QTX_CTL_VF_QUEUE
) {
5758 vf_id
= (u16
)((qtx_ctl
& I40E_QTX_CTL_VFVM_INDX_MASK
)
5759 >> I40E_QTX_CTL_VFVM_INDX_SHIFT
);
5760 vf_id
-= hw
->func_caps
.vf_base_id
;
5761 vf
= &pf
->vf
[vf_id
];
5762 i40e_vc_notify_vf_reset(vf
);
5763 /* Allow VF to process pending reset notification */
5765 i40e_reset_vf(vf
, false);
5770 * i40e_service_event_complete - Finish up the service event
5771 * @pf: board private structure
5773 static void i40e_service_event_complete(struct i40e_pf
*pf
)
5775 WARN_ON(!test_bit(__I40E_SERVICE_SCHED
, &pf
->state
));
5777 /* flush memory to make sure state is correct before next watchog */
5778 smp_mb__before_atomic();
5779 clear_bit(__I40E_SERVICE_SCHED
, &pf
->state
);
5783 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
5784 * @pf: board private structure
5786 u32
i40e_get_cur_guaranteed_fd_count(struct i40e_pf
*pf
)
5790 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
5791 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
);
5796 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
5797 * @pf: board private structure
5799 u32
i40e_get_current_fd_count(struct i40e_pf
*pf
)
5803 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
5804 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
) +
5805 ((val
& I40E_PFQF_FDSTAT_BEST_CNT_MASK
) >>
5806 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT
);
5811 * i40e_get_global_fd_count - Get total FD filters programmed on device
5812 * @pf: board private structure
5814 u32
i40e_get_global_fd_count(struct i40e_pf
*pf
)
5818 val
= rd32(&pf
->hw
, I40E_GLQF_FDCNT_0
);
5819 fcnt_prog
= (val
& I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK
) +
5820 ((val
& I40E_GLQF_FDCNT_0_BESTCNT_MASK
) >>
5821 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT
);
5826 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
5827 * @pf: board private structure
5829 void i40e_fdir_check_and_reenable(struct i40e_pf
*pf
)
5831 struct i40e_fdir_filter
*filter
;
5832 u32 fcnt_prog
, fcnt_avail
;
5833 struct hlist_node
*node
;
5835 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
5838 /* Check if, FD SB or ATR was auto disabled and if there is enough room
5841 fcnt_prog
= i40e_get_global_fd_count(pf
);
5842 fcnt_avail
= pf
->fdir_pf_filter_count
;
5843 if ((fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM
)) ||
5844 (pf
->fd_add_err
== 0) ||
5845 (i40e_get_current_atr_cnt(pf
) < pf
->fd_atr_cnt
)) {
5846 if ((pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) &&
5847 (pf
->auto_disable_flags
& I40E_FLAG_FD_SB_ENABLED
)) {
5848 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
5849 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5850 dev_info(&pf
->pdev
->dev
, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
5853 /* Wait for some more space to be available to turn on ATR */
5854 if (fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM
* 2)) {
5855 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
5856 (pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
)) {
5857 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
5858 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5859 dev_info(&pf
->pdev
->dev
, "ATR is being enabled since we have space in the table now\n");
5863 /* if hw had a problem adding a filter, delete it */
5864 if (pf
->fd_inv
> 0) {
5865 hlist_for_each_entry_safe(filter
, node
,
5866 &pf
->fdir_filter_list
, fdir_node
) {
5867 if (filter
->fd_id
== pf
->fd_inv
) {
5868 hlist_del(&filter
->fdir_node
);
5870 pf
->fdir_pf_active_filters
--;
5876 #define I40E_MIN_FD_FLUSH_INTERVAL 10
5877 #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
5879 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
5880 * @pf: board private structure
5882 static void i40e_fdir_flush_and_replay(struct i40e_pf
*pf
)
5884 unsigned long min_flush_time
;
5885 int flush_wait_retry
= 50;
5886 bool disable_atr
= false;
5890 if (!(pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
)))
5893 if (!time_after(jiffies
, pf
->fd_flush_timestamp
+
5894 (I40E_MIN_FD_FLUSH_INTERVAL
* HZ
)))
5897 /* If the flush is happening too quick and we have mostly SB rules we
5898 * should not re-enable ATR for some time.
5900 min_flush_time
= pf
->fd_flush_timestamp
+
5901 (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE
* HZ
);
5902 fd_room
= pf
->fdir_pf_filter_count
- pf
->fdir_pf_active_filters
;
5904 if (!(time_after(jiffies
, min_flush_time
)) &&
5905 (fd_room
< I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR
)) {
5906 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5907 dev_info(&pf
->pdev
->dev
, "ATR disabled, not enough FD filter space.\n");
5911 pf
->fd_flush_timestamp
= jiffies
;
5912 pf
->flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
5913 /* flush all filters */
5914 wr32(&pf
->hw
, I40E_PFQF_CTL_1
,
5915 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
);
5916 i40e_flush(&pf
->hw
);
5920 /* Check FD flush status every 5-6msec */
5921 usleep_range(5000, 6000);
5922 reg
= rd32(&pf
->hw
, I40E_PFQF_CTL_1
);
5923 if (!(reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
))
5925 } while (flush_wait_retry
--);
5926 if (reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
) {
5927 dev_warn(&pf
->pdev
->dev
, "FD table did not flush, needs more time\n");
5929 /* replay sideband filters */
5930 i40e_fdir_filter_restore(pf
->vsi
[pf
->lan_vsi
]);
5932 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
5933 clear_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
);
5934 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5935 dev_info(&pf
->pdev
->dev
, "FD Filter table flushed and FD-SB replayed.\n");
5941 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
5942 * @pf: board private structure
5944 u32
i40e_get_current_atr_cnt(struct i40e_pf
*pf
)
5946 return i40e_get_current_fd_count(pf
) - pf
->fdir_pf_active_filters
;
5949 /* We can see up to 256 filter programming desc in transit if the filters are
5950 * being applied really fast; before we see the first
5951 * filter miss error on Rx queue 0. Accumulating enough error messages before
5952 * reacting will make sure we don't cause flush too often.
5954 #define I40E_MAX_FD_PROGRAM_ERROR 256
5957 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
5958 * @pf: board private structure
5960 static void i40e_fdir_reinit_subtask(struct i40e_pf
*pf
)
5963 /* if interface is down do nothing */
5964 if (test_bit(__I40E_DOWN
, &pf
->state
))
5967 if (!(pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
)))
5970 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
5971 i40e_fdir_flush_and_replay(pf
);
5973 i40e_fdir_check_and_reenable(pf
);
5978 * i40e_vsi_link_event - notify VSI of a link event
5979 * @vsi: vsi to be notified
5980 * @link_up: link up or down
5982 static void i40e_vsi_link_event(struct i40e_vsi
*vsi
, bool link_up
)
5984 if (!vsi
|| test_bit(__I40E_DOWN
, &vsi
->state
))
5987 switch (vsi
->type
) {
5992 if (!vsi
->netdev
|| !vsi
->netdev_registered
)
5996 netif_carrier_on(vsi
->netdev
);
5997 netif_tx_wake_all_queues(vsi
->netdev
);
5999 netif_carrier_off(vsi
->netdev
);
6000 netif_tx_stop_all_queues(vsi
->netdev
);
6004 case I40E_VSI_SRIOV
:
6005 case I40E_VSI_VMDQ2
:
6007 case I40E_VSI_MIRROR
:
6009 /* there is no notification for other VSIs */
6015 * i40e_veb_link_event - notify elements on the veb of a link event
6016 * @veb: veb to be notified
6017 * @link_up: link up or down
6019 static void i40e_veb_link_event(struct i40e_veb
*veb
, bool link_up
)
6024 if (!veb
|| !veb
->pf
)
6028 /* depth first... */
6029 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
6030 if (pf
->veb
[i
] && (pf
->veb
[i
]->uplink_seid
== veb
->seid
))
6031 i40e_veb_link_event(pf
->veb
[i
], link_up
);
6033 /* ... now the local VSIs */
6034 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
6035 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->uplink_seid
== veb
->seid
))
6036 i40e_vsi_link_event(pf
->vsi
[i
], link_up
);
6040 * i40e_link_event - Update netif_carrier status
6041 * @pf: board private structure
6043 static void i40e_link_event(struct i40e_pf
*pf
)
6045 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
6046 u8 new_link_speed
, old_link_speed
;
6048 bool new_link
, old_link
;
6050 /* save off old link status information */
6051 pf
->hw
.phy
.link_info_old
= pf
->hw
.phy
.link_info
;
6053 /* set this to force the get_link_status call to refresh state */
6054 pf
->hw
.phy
.get_link_info
= true;
6056 old_link
= (pf
->hw
.phy
.link_info_old
.link_info
& I40E_AQ_LINK_UP
);
6058 status
= i40e_get_link_status(&pf
->hw
, &new_link
);
6060 dev_dbg(&pf
->pdev
->dev
, "couldn't get link state, status: %d\n",
6065 old_link_speed
= pf
->hw
.phy
.link_info_old
.link_speed
;
6066 new_link_speed
= pf
->hw
.phy
.link_info
.link_speed
;
6068 if (new_link
== old_link
&&
6069 new_link_speed
== old_link_speed
&&
6070 (test_bit(__I40E_DOWN
, &vsi
->state
) ||
6071 new_link
== netif_carrier_ok(vsi
->netdev
)))
6074 if (!test_bit(__I40E_DOWN
, &vsi
->state
))
6075 i40e_print_link_message(vsi
, new_link
);
6077 /* Notify the base of the switch tree connected to
6078 * the link. Floating VEBs are not notified.
6080 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
6081 i40e_veb_link_event(pf
->veb
[pf
->lan_veb
], new_link
);
6083 i40e_vsi_link_event(vsi
, new_link
);
6086 i40e_vc_notify_link_state(pf
);
6088 if (pf
->flags
& I40E_FLAG_PTP
)
6089 i40e_ptp_set_increment(pf
);
6093 * i40e_watchdog_subtask - periodic checks not using event driven response
6094 * @pf: board private structure
6096 static void i40e_watchdog_subtask(struct i40e_pf
*pf
)
6100 /* if interface is down do nothing */
6101 if (test_bit(__I40E_DOWN
, &pf
->state
) ||
6102 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
6105 /* make sure we don't do these things too often */
6106 if (time_before(jiffies
, (pf
->service_timer_previous
+
6107 pf
->service_timer_period
)))
6109 pf
->service_timer_previous
= jiffies
;
6111 if (pf
->flags
& I40E_FLAG_LINK_POLLING_ENABLED
)
6112 i40e_link_event(pf
);
6114 /* Update the stats for active netdevs so the network stack
6115 * can look at updated numbers whenever it cares to
6117 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
6118 if (pf
->vsi
[i
] && pf
->vsi
[i
]->netdev
)
6119 i40e_update_stats(pf
->vsi
[i
]);
6121 if (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
) {
6122 /* Update the stats for the active switching components */
6123 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
6125 i40e_update_veb_stats(pf
->veb
[i
]);
6128 i40e_ptp_rx_hang(pf
->vsi
[pf
->lan_vsi
]);
6132 * i40e_reset_subtask - Set up for resetting the device and driver
6133 * @pf: board private structure
6135 static void i40e_reset_subtask(struct i40e_pf
*pf
)
6137 u32 reset_flags
= 0;
6140 if (test_bit(__I40E_REINIT_REQUESTED
, &pf
->state
)) {
6141 reset_flags
|= BIT(__I40E_REINIT_REQUESTED
);
6142 clear_bit(__I40E_REINIT_REQUESTED
, &pf
->state
);
6144 if (test_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
)) {
6145 reset_flags
|= BIT(__I40E_PF_RESET_REQUESTED
);
6146 clear_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
6148 if (test_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
)) {
6149 reset_flags
|= BIT(__I40E_CORE_RESET_REQUESTED
);
6150 clear_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
);
6152 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
)) {
6153 reset_flags
|= BIT(__I40E_GLOBAL_RESET_REQUESTED
);
6154 clear_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
);
6156 if (test_bit(__I40E_DOWN_REQUESTED
, &pf
->state
)) {
6157 reset_flags
|= BIT(__I40E_DOWN_REQUESTED
);
6158 clear_bit(__I40E_DOWN_REQUESTED
, &pf
->state
);
6161 /* If there's a recovery already waiting, it takes
6162 * precedence before starting a new reset sequence.
6164 if (test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
)) {
6165 i40e_handle_reset_warning(pf
);
6169 /* If we're already down or resetting, just bail */
6171 !test_bit(__I40E_DOWN
, &pf
->state
) &&
6172 !test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
6173 i40e_do_reset(pf
, reset_flags
);
6180 * i40e_handle_link_event - Handle link event
6181 * @pf: board private structure
6182 * @e: event info posted on ARQ
6184 static void i40e_handle_link_event(struct i40e_pf
*pf
,
6185 struct i40e_arq_event_info
*e
)
6187 struct i40e_aqc_get_link_status
*status
=
6188 (struct i40e_aqc_get_link_status
*)&e
->desc
.params
.raw
;
6190 /* Do a new status request to re-enable LSE reporting
6191 * and load new status information into the hw struct
6192 * This completely ignores any state information
6193 * in the ARQ event info, instead choosing to always
6194 * issue the AQ update link status command.
6196 i40e_link_event(pf
);
6198 /* check for unqualified module, if link is down */
6199 if ((status
->link_info
& I40E_AQ_MEDIA_AVAILABLE
) &&
6200 (!(status
->an_info
& I40E_AQ_QUALIFIED_MODULE
)) &&
6201 (!(status
->link_info
& I40E_AQ_LINK_UP
)))
6202 dev_err(&pf
->pdev
->dev
,
6203 "The driver failed to link because an unqualified module was detected.\n");
6207 * i40e_clean_adminq_subtask - Clean the AdminQ rings
6208 * @pf: board private structure
6210 static void i40e_clean_adminq_subtask(struct i40e_pf
*pf
)
6212 struct i40e_arq_event_info event
;
6213 struct i40e_hw
*hw
= &pf
->hw
;
6220 /* Do not run clean AQ when PF reset fails */
6221 if (test_bit(__I40E_RESET_FAILED
, &pf
->state
))
6224 /* check for error indications */
6225 val
= rd32(&pf
->hw
, pf
->hw
.aq
.arq
.len
);
6227 if (val
& I40E_PF_ARQLEN_ARQVFE_MASK
) {
6228 if (hw
->debug_mask
& I40E_DEBUG_AQ
)
6229 dev_info(&pf
->pdev
->dev
, "ARQ VF Error detected\n");
6230 val
&= ~I40E_PF_ARQLEN_ARQVFE_MASK
;
6232 if (val
& I40E_PF_ARQLEN_ARQOVFL_MASK
) {
6233 if (hw
->debug_mask
& I40E_DEBUG_AQ
)
6234 dev_info(&pf
->pdev
->dev
, "ARQ Overflow Error detected\n");
6235 val
&= ~I40E_PF_ARQLEN_ARQOVFL_MASK
;
6237 if (val
& I40E_PF_ARQLEN_ARQCRIT_MASK
) {
6238 if (hw
->debug_mask
& I40E_DEBUG_AQ
)
6239 dev_info(&pf
->pdev
->dev
, "ARQ Critical Error detected\n");
6240 val
&= ~I40E_PF_ARQLEN_ARQCRIT_MASK
;
6243 wr32(&pf
->hw
, pf
->hw
.aq
.arq
.len
, val
);
6245 val
= rd32(&pf
->hw
, pf
->hw
.aq
.asq
.len
);
6247 if (val
& I40E_PF_ATQLEN_ATQVFE_MASK
) {
6248 if (pf
->hw
.debug_mask
& I40E_DEBUG_AQ
)
6249 dev_info(&pf
->pdev
->dev
, "ASQ VF Error detected\n");
6250 val
&= ~I40E_PF_ATQLEN_ATQVFE_MASK
;
6252 if (val
& I40E_PF_ATQLEN_ATQOVFL_MASK
) {
6253 if (pf
->hw
.debug_mask
& I40E_DEBUG_AQ
)
6254 dev_info(&pf
->pdev
->dev
, "ASQ Overflow Error detected\n");
6255 val
&= ~I40E_PF_ATQLEN_ATQOVFL_MASK
;
6257 if (val
& I40E_PF_ATQLEN_ATQCRIT_MASK
) {
6258 if (pf
->hw
.debug_mask
& I40E_DEBUG_AQ
)
6259 dev_info(&pf
->pdev
->dev
, "ASQ Critical Error detected\n");
6260 val
&= ~I40E_PF_ATQLEN_ATQCRIT_MASK
;
6263 wr32(&pf
->hw
, pf
->hw
.aq
.asq
.len
, val
);
6265 event
.buf_len
= I40E_MAX_AQ_BUF_SIZE
;
6266 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
6271 ret
= i40e_clean_arq_element(hw
, &event
, &pending
);
6272 if (ret
== I40E_ERR_ADMIN_QUEUE_NO_WORK
)
6275 dev_info(&pf
->pdev
->dev
, "ARQ event error %d\n", ret
);
6279 opcode
= le16_to_cpu(event
.desc
.opcode
);
6282 case i40e_aqc_opc_get_link_status
:
6283 i40e_handle_link_event(pf
, &event
);
6285 case i40e_aqc_opc_send_msg_to_pf
:
6286 ret
= i40e_vc_process_vf_msg(pf
,
6287 le16_to_cpu(event
.desc
.retval
),
6288 le32_to_cpu(event
.desc
.cookie_high
),
6289 le32_to_cpu(event
.desc
.cookie_low
),
6293 case i40e_aqc_opc_lldp_update_mib
:
6294 dev_dbg(&pf
->pdev
->dev
, "ARQ: Update LLDP MIB event received\n");
6295 #ifdef CONFIG_I40E_DCB
6297 ret
= i40e_handle_lldp_event(pf
, &event
);
6299 #endif /* CONFIG_I40E_DCB */
6301 case i40e_aqc_opc_event_lan_overflow
:
6302 dev_dbg(&pf
->pdev
->dev
, "ARQ LAN queue overflow event received\n");
6303 i40e_handle_lan_overflow_event(pf
, &event
);
6305 case i40e_aqc_opc_send_msg_to_peer
:
6306 dev_info(&pf
->pdev
->dev
, "ARQ: Msg from other pf\n");
6308 case i40e_aqc_opc_nvm_erase
:
6309 case i40e_aqc_opc_nvm_update
:
6310 case i40e_aqc_opc_oem_post_update
:
6311 i40e_debug(&pf
->hw
, I40E_DEBUG_NVM
, "ARQ NVM operation completed\n");
6314 dev_info(&pf
->pdev
->dev
,
6315 "ARQ Error: Unknown event 0x%04x received\n",
6319 } while (pending
&& (i
++ < pf
->adminq_work_limit
));
6321 clear_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
);
6322 /* re-enable Admin queue interrupt cause */
6323 val
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
6324 val
|= I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
6325 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
6328 kfree(event
.msg_buf
);
6332 * i40e_verify_eeprom - make sure eeprom is good to use
6333 * @pf: board private structure
6335 static void i40e_verify_eeprom(struct i40e_pf
*pf
)
6339 err
= i40e_diag_eeprom_test(&pf
->hw
);
6341 /* retry in case of garbage read */
6342 err
= i40e_diag_eeprom_test(&pf
->hw
);
6344 dev_info(&pf
->pdev
->dev
, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
6346 set_bit(__I40E_BAD_EEPROM
, &pf
->state
);
6350 if (!err
&& test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
6351 dev_info(&pf
->pdev
->dev
, "eeprom check passed, Tx/Rx traffic enabled\n");
6352 clear_bit(__I40E_BAD_EEPROM
, &pf
->state
);
6357 * i40e_enable_pf_switch_lb
6358 * @pf: pointer to the PF structure
6360 * enable switch loop back or die - no point in a return value
6362 static void i40e_enable_pf_switch_lb(struct i40e_pf
*pf
)
6364 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
6365 struct i40e_vsi_context ctxt
;
6368 ctxt
.seid
= pf
->main_vsi_seid
;
6369 ctxt
.pf_num
= pf
->hw
.pf_id
;
6371 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
6373 dev_info(&pf
->pdev
->dev
,
6374 "couldn't get PF vsi config, err %s aq_err %s\n",
6375 i40e_stat_str(&pf
->hw
, ret
),
6376 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6379 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
6380 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
6381 ctxt
.info
.switch_id
|= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
6383 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
6385 dev_info(&pf
->pdev
->dev
,
6386 "update vsi switch failed, err %s aq_err %s\n",
6387 i40e_stat_str(&pf
->hw
, ret
),
6388 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6393 * i40e_disable_pf_switch_lb
6394 * @pf: pointer to the PF structure
6396 * disable switch loop back or die - no point in a return value
6398 static void i40e_disable_pf_switch_lb(struct i40e_pf
*pf
)
6400 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
6401 struct i40e_vsi_context ctxt
;
6404 ctxt
.seid
= pf
->main_vsi_seid
;
6405 ctxt
.pf_num
= pf
->hw
.pf_id
;
6407 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
6409 dev_info(&pf
->pdev
->dev
,
6410 "couldn't get PF vsi config, err %s aq_err %s\n",
6411 i40e_stat_str(&pf
->hw
, ret
),
6412 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6415 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
6416 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
6417 ctxt
.info
.switch_id
&= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
6419 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
6421 dev_info(&pf
->pdev
->dev
,
6422 "update vsi switch failed, err %s aq_err %s\n",
6423 i40e_stat_str(&pf
->hw
, ret
),
6424 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6429 * i40e_config_bridge_mode - Configure the HW bridge mode
6430 * @veb: pointer to the bridge instance
6432 * Configure the loop back mode for the LAN VSI that is downlink to the
6433 * specified HW bridge instance. It is expected this function is called
6434 * when a new HW bridge is instantiated.
6436 static void i40e_config_bridge_mode(struct i40e_veb
*veb
)
6438 struct i40e_pf
*pf
= veb
->pf
;
6440 if (pf
->hw
.debug_mask
& I40E_DEBUG_LAN
)
6441 dev_info(&pf
->pdev
->dev
, "enabling bridge mode: %s\n",
6442 veb
->bridge_mode
== BRIDGE_MODE_VEPA
? "VEPA" : "VEB");
6443 if (veb
->bridge_mode
& BRIDGE_MODE_VEPA
)
6444 i40e_disable_pf_switch_lb(pf
);
6446 i40e_enable_pf_switch_lb(pf
);
6450 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
6451 * @veb: pointer to the VEB instance
6453 * This is a recursive function that first builds the attached VSIs then
6454 * recurses in to build the next layer of VEB. We track the connections
6455 * through our own index numbers because the seid's from the HW could
6456 * change across the reset.
6458 static int i40e_reconstitute_veb(struct i40e_veb
*veb
)
6460 struct i40e_vsi
*ctl_vsi
= NULL
;
6461 struct i40e_pf
*pf
= veb
->pf
;
6465 /* build VSI that owns this VEB, temporarily attached to base VEB */
6466 for (v
= 0; v
< pf
->num_alloc_vsi
&& !ctl_vsi
; v
++) {
6468 pf
->vsi
[v
]->veb_idx
== veb
->idx
&&
6469 pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
6470 ctl_vsi
= pf
->vsi
[v
];
6475 dev_info(&pf
->pdev
->dev
,
6476 "missing owner VSI for veb_idx %d\n", veb
->idx
);
6478 goto end_reconstitute
;
6480 if (ctl_vsi
!= pf
->vsi
[pf
->lan_vsi
])
6481 ctl_vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
6482 ret
= i40e_add_vsi(ctl_vsi
);
6484 dev_info(&pf
->pdev
->dev
,
6485 "rebuild of veb_idx %d owner VSI failed: %d\n",
6487 goto end_reconstitute
;
6489 i40e_vsi_reset_stats(ctl_vsi
);
6491 /* create the VEB in the switch and move the VSI onto the VEB */
6492 ret
= i40e_add_veb(veb
, ctl_vsi
);
6494 goto end_reconstitute
;
6496 if (pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)
6497 veb
->bridge_mode
= BRIDGE_MODE_VEB
;
6499 veb
->bridge_mode
= BRIDGE_MODE_VEPA
;
6500 i40e_config_bridge_mode(veb
);
6502 /* create the remaining VSIs attached to this VEB */
6503 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
6504 if (!pf
->vsi
[v
] || pf
->vsi
[v
] == ctl_vsi
)
6507 if (pf
->vsi
[v
]->veb_idx
== veb
->idx
) {
6508 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
6510 vsi
->uplink_seid
= veb
->seid
;
6511 ret
= i40e_add_vsi(vsi
);
6513 dev_info(&pf
->pdev
->dev
,
6514 "rebuild of vsi_idx %d failed: %d\n",
6516 goto end_reconstitute
;
6518 i40e_vsi_reset_stats(vsi
);
6522 /* create any VEBs attached to this VEB - RECURSION */
6523 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
6524 if (pf
->veb
[veb_idx
] && pf
->veb
[veb_idx
]->veb_idx
== veb
->idx
) {
6525 pf
->veb
[veb_idx
]->uplink_seid
= veb
->seid
;
6526 ret
= i40e_reconstitute_veb(pf
->veb
[veb_idx
]);
6537 * i40e_get_capabilities - get info about the HW
6538 * @pf: the PF struct
6540 static int i40e_get_capabilities(struct i40e_pf
*pf
)
6542 struct i40e_aqc_list_capabilities_element_resp
*cap_buf
;
6547 buf_len
= 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp
);
6549 cap_buf
= kzalloc(buf_len
, GFP_KERNEL
);
6553 /* this loads the data into the hw struct for us */
6554 err
= i40e_aq_discover_capabilities(&pf
->hw
, cap_buf
, buf_len
,
6556 i40e_aqc_opc_list_func_capabilities
,
6558 /* data loaded, buffer no longer needed */
6561 if (pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_ENOMEM
) {
6562 /* retry with a larger buffer */
6563 buf_len
= data_size
;
6564 } else if (pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_OK
) {
6565 dev_info(&pf
->pdev
->dev
,
6566 "capability discovery failed, err %s aq_err %s\n",
6567 i40e_stat_str(&pf
->hw
, err
),
6568 i40e_aq_str(&pf
->hw
,
6569 pf
->hw
.aq
.asq_last_status
));
6574 if (pf
->hw
.debug_mask
& I40E_DEBUG_USER
)
6575 dev_info(&pf
->pdev
->dev
,
6576 "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",
6577 pf
->hw
.pf_id
, pf
->hw
.func_caps
.num_vfs
,
6578 pf
->hw
.func_caps
.num_msix_vectors
,
6579 pf
->hw
.func_caps
.num_msix_vectors_vf
,
6580 pf
->hw
.func_caps
.fd_filters_guaranteed
,
6581 pf
->hw
.func_caps
.fd_filters_best_effort
,
6582 pf
->hw
.func_caps
.num_tx_qp
,
6583 pf
->hw
.func_caps
.num_vsis
);
6585 #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
6586 + pf->hw.func_caps.num_vfs)
6587 if (pf
->hw
.revision_id
== 0 && (DEF_NUM_VSI
> pf
->hw
.func_caps
.num_vsis
)) {
6588 dev_info(&pf
->pdev
->dev
,
6589 "got num_vsis %d, setting num_vsis to %d\n",
6590 pf
->hw
.func_caps
.num_vsis
, DEF_NUM_VSI
);
6591 pf
->hw
.func_caps
.num_vsis
= DEF_NUM_VSI
;
6597 static int i40e_vsi_clear(struct i40e_vsi
*vsi
);
6600 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
6601 * @pf: board private structure
6603 static void i40e_fdir_sb_setup(struct i40e_pf
*pf
)
6605 struct i40e_vsi
*vsi
;
6608 /* quick workaround for an NVM issue that leaves a critical register
6611 if (!rd32(&pf
->hw
, I40E_GLQF_HKEY(0))) {
6612 static const u32 hkey
[] = {
6613 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
6614 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
6615 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
6618 for (i
= 0; i
<= I40E_GLQF_HKEY_MAX_INDEX
; i
++)
6619 wr32(&pf
->hw
, I40E_GLQF_HKEY(i
), hkey
[i
]);
6622 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
6625 /* find existing VSI and see if it needs configuring */
6627 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
6628 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
6634 /* create a new VSI if none exists */
6636 vsi
= i40e_vsi_setup(pf
, I40E_VSI_FDIR
,
6637 pf
->vsi
[pf
->lan_vsi
]->seid
, 0);
6639 dev_info(&pf
->pdev
->dev
, "Couldn't create FDir VSI\n");
6640 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
6645 i40e_vsi_setup_irqhandler(vsi
, i40e_fdir_clean_ring
);
6649 * i40e_fdir_teardown - release the Flow Director resources
6650 * @pf: board private structure
6652 static void i40e_fdir_teardown(struct i40e_pf
*pf
)
6656 i40e_fdir_filter_exit(pf
);
6657 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
6658 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
6659 i40e_vsi_release(pf
->vsi
[i
]);
6666 * i40e_prep_for_reset - prep for the core to reset
6667 * @pf: board private structure
6669 * Close up the VFs and other things in prep for PF Reset.
6671 static void i40e_prep_for_reset(struct i40e_pf
*pf
)
6673 struct i40e_hw
*hw
= &pf
->hw
;
6674 i40e_status ret
= 0;
6677 clear_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
);
6678 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
))
6681 dev_dbg(&pf
->pdev
->dev
, "Tearing down internal switch for reset\n");
6683 /* quiesce the VSIs and their queues that are not already DOWN */
6684 i40e_pf_quiesce_all_vsi(pf
);
6686 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
6688 pf
->vsi
[v
]->seid
= 0;
6691 i40e_shutdown_adminq(&pf
->hw
);
6693 /* call shutdown HMC */
6694 if (hw
->hmc
.hmc_obj
) {
6695 ret
= i40e_shutdown_lan_hmc(hw
);
6697 dev_warn(&pf
->pdev
->dev
,
6698 "shutdown_lan_hmc failed: %d\n", ret
);
6703 * i40e_send_version - update firmware with driver version
6706 static void i40e_send_version(struct i40e_pf
*pf
)
6708 struct i40e_driver_version dv
;
6710 dv
.major_version
= DRV_VERSION_MAJOR
;
6711 dv
.minor_version
= DRV_VERSION_MINOR
;
6712 dv
.build_version
= DRV_VERSION_BUILD
;
6713 dv
.subbuild_version
= 0;
6714 strlcpy(dv
.driver_string
, DRV_VERSION
, sizeof(dv
.driver_string
));
6715 i40e_aq_send_driver_version(&pf
->hw
, &dv
, NULL
);
6719 * i40e_reset_and_rebuild - reset and rebuild using a saved config
6720 * @pf: board private structure
6721 * @reinit: if the Main VSI needs to re-initialized.
6723 static void i40e_reset_and_rebuild(struct i40e_pf
*pf
, bool reinit
)
6725 struct i40e_hw
*hw
= &pf
->hw
;
6726 u8 set_fc_aq_fail
= 0;
6731 /* Now we wait for GRST to settle out.
6732 * We don't have to delete the VEBs or VSIs from the hw switch
6733 * because the reset will make them disappear.
6735 ret
= i40e_pf_reset(hw
);
6737 dev_info(&pf
->pdev
->dev
, "PF reset failed, %d\n", ret
);
6738 set_bit(__I40E_RESET_FAILED
, &pf
->state
);
6739 goto clear_recovery
;
6743 if (test_bit(__I40E_DOWN
, &pf
->state
))
6744 goto clear_recovery
;
6745 dev_dbg(&pf
->pdev
->dev
, "Rebuilding internal switch\n");
6747 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
6748 ret
= i40e_init_adminq(&pf
->hw
);
6750 dev_info(&pf
->pdev
->dev
, "Rebuild AdminQ failed, err %s aq_err %s\n",
6751 i40e_stat_str(&pf
->hw
, ret
),
6752 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6753 goto clear_recovery
;
6756 /* re-verify the eeprom if we just had an EMP reset */
6757 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED
, &pf
->state
))
6758 i40e_verify_eeprom(pf
);
6760 i40e_clear_pxe_mode(hw
);
6761 ret
= i40e_get_capabilities(pf
);
6763 goto end_core_reset
;
6765 ret
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
6766 hw
->func_caps
.num_rx_qp
,
6767 pf
->fcoe_hmc_cntx_num
, pf
->fcoe_hmc_filt_num
);
6769 dev_info(&pf
->pdev
->dev
, "init_lan_hmc failed: %d\n", ret
);
6770 goto end_core_reset
;
6772 ret
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
6774 dev_info(&pf
->pdev
->dev
, "configure_lan_hmc failed: %d\n", ret
);
6775 goto end_core_reset
;
6778 #ifdef CONFIG_I40E_DCB
6779 ret
= i40e_init_pf_dcb(pf
);
6781 dev_info(&pf
->pdev
->dev
, "DCB init failed %d, disabled\n", ret
);
6782 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
6783 /* Continue without DCB enabled */
6785 #endif /* CONFIG_I40E_DCB */
6787 i40e_init_pf_fcoe(pf
);
6790 /* do basic switch setup */
6791 ret
= i40e_setup_pf_switch(pf
, reinit
);
6793 goto end_core_reset
;
6795 /* driver is only interested in link up/down and module qualification
6796 * reports from firmware
6798 ret
= i40e_aq_set_phy_int_mask(&pf
->hw
,
6799 I40E_AQ_EVENT_LINK_UPDOWN
|
6800 I40E_AQ_EVENT_MODULE_QUAL_FAIL
, NULL
);
6802 dev_info(&pf
->pdev
->dev
, "set phy mask fail, err %s aq_err %s\n",
6803 i40e_stat_str(&pf
->hw
, ret
),
6804 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6806 /* make sure our flow control settings are restored */
6807 ret
= i40e_set_fc(&pf
->hw
, &set_fc_aq_fail
, true);
6809 dev_dbg(&pf
->pdev
->dev
, "setting flow control: ret = %s last_status = %s\n",
6810 i40e_stat_str(&pf
->hw
, ret
),
6811 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6813 /* Rebuild the VSIs and VEBs that existed before reset.
6814 * They are still in our local switch element arrays, so only
6815 * need to rebuild the switch model in the HW.
6817 * If there were VEBs but the reconstitution failed, we'll try
6818 * try to recover minimal use by getting the basic PF VSI working.
6820 if (pf
->vsi
[pf
->lan_vsi
]->uplink_seid
!= pf
->mac_seid
) {
6821 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild switch\n");
6822 /* find the one VEB connected to the MAC, and find orphans */
6823 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
6827 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
||
6828 pf
->veb
[v
]->uplink_seid
== 0) {
6829 ret
= i40e_reconstitute_veb(pf
->veb
[v
]);
6834 /* If Main VEB failed, we're in deep doodoo,
6835 * so give up rebuilding the switch and set up
6836 * for minimal rebuild of PF VSI.
6837 * If orphan failed, we'll report the error
6838 * but try to keep going.
6840 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
) {
6841 dev_info(&pf
->pdev
->dev
,
6842 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
6844 pf
->vsi
[pf
->lan_vsi
]->uplink_seid
6847 } else if (pf
->veb
[v
]->uplink_seid
== 0) {
6848 dev_info(&pf
->pdev
->dev
,
6849 "rebuild of orphan VEB failed: %d\n",
6856 if (pf
->vsi
[pf
->lan_vsi
]->uplink_seid
== pf
->mac_seid
) {
6857 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild PF VSI\n");
6858 /* no VEB, so rebuild only the Main VSI */
6859 ret
= i40e_add_vsi(pf
->vsi
[pf
->lan_vsi
]);
6861 dev_info(&pf
->pdev
->dev
,
6862 "rebuild of Main VSI failed: %d\n", ret
);
6863 goto end_core_reset
;
6867 /* Reconfigure hardware for allowing smaller MSS in the case
6868 * of TSO, so that we avoid the MDD being fired and causing
6869 * a reset in the case of small MSS+TSO.
6871 #define I40E_REG_MSS 0x000E64DC
6872 #define I40E_REG_MSS_MIN_MASK 0x3FF0000
6873 #define I40E_64BYTE_MSS 0x400000
6874 val
= rd32(hw
, I40E_REG_MSS
);
6875 if ((val
& I40E_REG_MSS_MIN_MASK
) > I40E_64BYTE_MSS
) {
6876 val
&= ~I40E_REG_MSS_MIN_MASK
;
6877 val
|= I40E_64BYTE_MSS
;
6878 wr32(hw
, I40E_REG_MSS
, val
);
6881 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
6882 (pf
->hw
.aq
.fw_maj_ver
< 4)) {
6884 ret
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
6886 dev_info(&pf
->pdev
->dev
, "link restart failed, err %s aq_err %s\n",
6887 i40e_stat_str(&pf
->hw
, ret
),
6888 i40e_aq_str(&pf
->hw
,
6889 pf
->hw
.aq
.asq_last_status
));
6891 /* reinit the misc interrupt */
6892 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
6893 ret
= i40e_setup_misc_vector(pf
);
6895 /* Add a filter to drop all Flow control frames from any VSI from being
6896 * transmitted. By doing so we stop a malicious VF from sending out
6897 * PAUSE or PFC frames and potentially controlling traffic for other
6899 * The FW can still send Flow control frames if enabled.
6901 i40e_add_filter_to_drop_tx_flow_control_frames(&pf
->hw
,
6904 /* restart the VSIs that were rebuilt and running before the reset */
6905 i40e_pf_unquiesce_all_vsi(pf
);
6907 if (pf
->num_alloc_vfs
) {
6908 for (v
= 0; v
< pf
->num_alloc_vfs
; v
++)
6909 i40e_reset_vf(&pf
->vf
[v
], true);
6912 /* tell the firmware that we're starting */
6913 i40e_send_version(pf
);
6916 clear_bit(__I40E_RESET_FAILED
, &pf
->state
);
6918 clear_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
);
6922 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
6923 * @pf: board private structure
6925 * Close up the VFs and other things in prep for a Core Reset,
6926 * then get ready to rebuild the world.
6928 static void i40e_handle_reset_warning(struct i40e_pf
*pf
)
6930 i40e_prep_for_reset(pf
);
6931 i40e_reset_and_rebuild(pf
, false);
6935 * i40e_handle_mdd_event
6936 * @pf: pointer to the PF structure
6938 * Called from the MDD irq handler to identify possibly malicious vfs
6940 static void i40e_handle_mdd_event(struct i40e_pf
*pf
)
6942 struct i40e_hw
*hw
= &pf
->hw
;
6943 bool mdd_detected
= false;
6944 bool pf_mdd_detected
= false;
6949 if (!test_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
))
6952 /* find what triggered the MDD event */
6953 reg
= rd32(hw
, I40E_GL_MDET_TX
);
6954 if (reg
& I40E_GL_MDET_TX_VALID_MASK
) {
6955 u8 pf_num
= (reg
& I40E_GL_MDET_TX_PF_NUM_MASK
) >>
6956 I40E_GL_MDET_TX_PF_NUM_SHIFT
;
6957 u16 vf_num
= (reg
& I40E_GL_MDET_TX_VF_NUM_MASK
) >>
6958 I40E_GL_MDET_TX_VF_NUM_SHIFT
;
6959 u8 event
= (reg
& I40E_GL_MDET_TX_EVENT_MASK
) >>
6960 I40E_GL_MDET_TX_EVENT_SHIFT
;
6961 u16 queue
= ((reg
& I40E_GL_MDET_TX_QUEUE_MASK
) >>
6962 I40E_GL_MDET_TX_QUEUE_SHIFT
) -
6963 pf
->hw
.func_caps
.base_queue
;
6964 if (netif_msg_tx_err(pf
))
6965 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
6966 event
, queue
, pf_num
, vf_num
);
6967 wr32(hw
, I40E_GL_MDET_TX
, 0xffffffff);
6968 mdd_detected
= true;
6970 reg
= rd32(hw
, I40E_GL_MDET_RX
);
6971 if (reg
& I40E_GL_MDET_RX_VALID_MASK
) {
6972 u8 func
= (reg
& I40E_GL_MDET_RX_FUNCTION_MASK
) >>
6973 I40E_GL_MDET_RX_FUNCTION_SHIFT
;
6974 u8 event
= (reg
& I40E_GL_MDET_RX_EVENT_MASK
) >>
6975 I40E_GL_MDET_RX_EVENT_SHIFT
;
6976 u16 queue
= ((reg
& I40E_GL_MDET_RX_QUEUE_MASK
) >>
6977 I40E_GL_MDET_RX_QUEUE_SHIFT
) -
6978 pf
->hw
.func_caps
.base_queue
;
6979 if (netif_msg_rx_err(pf
))
6980 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
6981 event
, queue
, func
);
6982 wr32(hw
, I40E_GL_MDET_RX
, 0xffffffff);
6983 mdd_detected
= true;
6987 reg
= rd32(hw
, I40E_PF_MDET_TX
);
6988 if (reg
& I40E_PF_MDET_TX_VALID_MASK
) {
6989 wr32(hw
, I40E_PF_MDET_TX
, 0xFFFF);
6990 dev_info(&pf
->pdev
->dev
, "TX driver issue detected, PF reset issued\n");
6991 pf_mdd_detected
= true;
6993 reg
= rd32(hw
, I40E_PF_MDET_RX
);
6994 if (reg
& I40E_PF_MDET_RX_VALID_MASK
) {
6995 wr32(hw
, I40E_PF_MDET_RX
, 0xFFFF);
6996 dev_info(&pf
->pdev
->dev
, "RX driver issue detected, PF reset issued\n");
6997 pf_mdd_detected
= true;
6999 /* Queue belongs to the PF, initiate a reset */
7000 if (pf_mdd_detected
) {
7001 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
7002 i40e_service_event_schedule(pf
);
7006 /* see if one of the VFs needs its hand slapped */
7007 for (i
= 0; i
< pf
->num_alloc_vfs
&& mdd_detected
; i
++) {
7009 reg
= rd32(hw
, I40E_VP_MDET_TX(i
));
7010 if (reg
& I40E_VP_MDET_TX_VALID_MASK
) {
7011 wr32(hw
, I40E_VP_MDET_TX(i
), 0xFFFF);
7012 vf
->num_mdd_events
++;
7013 dev_info(&pf
->pdev
->dev
, "TX driver issue detected on VF %d\n",
7017 reg
= rd32(hw
, I40E_VP_MDET_RX(i
));
7018 if (reg
& I40E_VP_MDET_RX_VALID_MASK
) {
7019 wr32(hw
, I40E_VP_MDET_RX(i
), 0xFFFF);
7020 vf
->num_mdd_events
++;
7021 dev_info(&pf
->pdev
->dev
, "RX driver issue detected on VF %d\n",
7025 if (vf
->num_mdd_events
> I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED
) {
7026 dev_info(&pf
->pdev
->dev
,
7027 "Too many MDD events on VF %d, disabled\n", i
);
7028 dev_info(&pf
->pdev
->dev
,
7029 "Use PF Control I/F to re-enable the VF\n");
7030 set_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
);
7034 /* re-enable mdd interrupt cause */
7035 clear_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
);
7036 reg
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
7037 reg
|= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
7038 wr32(hw
, I40E_PFINT_ICR0_ENA
, reg
);
7043 * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
7044 * @pf: board private structure
7046 static void i40e_sync_udp_filters_subtask(struct i40e_pf
*pf
)
7048 #if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE)
7049 struct i40e_hw
*hw
= &pf
->hw
;
7054 if (!(pf
->flags
& I40E_FLAG_UDP_FILTER_SYNC
))
7057 pf
->flags
&= ~I40E_FLAG_UDP_FILTER_SYNC
;
7059 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
7060 if (pf
->pending_udp_bitmap
& BIT_ULL(i
)) {
7061 pf
->pending_udp_bitmap
&= ~BIT_ULL(i
);
7062 port
= pf
->udp_ports
[i
].index
;
7064 ret
= i40e_aq_add_udp_tunnel(hw
, ntohs(port
),
7065 pf
->udp_ports
[i
].type
,
7068 ret
= i40e_aq_del_udp_tunnel(hw
, i
, NULL
);
7071 dev_info(&pf
->pdev
->dev
,
7072 "%s vxlan port %d, index %d failed, err %s aq_err %s\n",
7073 port
? "add" : "delete",
7075 i40e_stat_str(&pf
->hw
, ret
),
7076 i40e_aq_str(&pf
->hw
,
7077 pf
->hw
.aq
.asq_last_status
));
7078 pf
->udp_ports
[i
].index
= 0;
7086 * i40e_service_task - Run the driver's async subtasks
7087 * @work: pointer to work_struct containing our data
7089 static void i40e_service_task(struct work_struct
*work
)
7091 struct i40e_pf
*pf
= container_of(work
,
7094 unsigned long start_time
= jiffies
;
7096 /* don't bother with service tasks if a reset is in progress */
7097 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
)) {
7098 i40e_service_event_complete(pf
);
7102 i40e_detect_recover_hung(pf
);
7103 i40e_reset_subtask(pf
);
7104 i40e_handle_mdd_event(pf
);
7105 i40e_vc_process_vflr_event(pf
);
7106 i40e_watchdog_subtask(pf
);
7107 i40e_fdir_reinit_subtask(pf
);
7108 i40e_sync_filters_subtask(pf
);
7109 #if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE)
7110 i40e_sync_udp_filters_subtask(pf
);
7112 i40e_clean_adminq_subtask(pf
);
7114 i40e_service_event_complete(pf
);
7116 /* If the tasks have taken longer than one timer cycle or there
7117 * is more work to be done, reschedule the service task now
7118 * rather than wait for the timer to tick again.
7120 if (time_after(jiffies
, (start_time
+ pf
->service_timer_period
)) ||
7121 test_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
) ||
7122 test_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
) ||
7123 test_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
))
7124 i40e_service_event_schedule(pf
);
7128 * i40e_service_timer - timer callback
7129 * @data: pointer to PF struct
7131 static void i40e_service_timer(unsigned long data
)
7133 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
7135 mod_timer(&pf
->service_timer
,
7136 round_jiffies(jiffies
+ pf
->service_timer_period
));
7137 i40e_service_event_schedule(pf
);
7141 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
7142 * @vsi: the VSI being configured
7144 static int i40e_set_num_rings_in_vsi(struct i40e_vsi
*vsi
)
7146 struct i40e_pf
*pf
= vsi
->back
;
7148 switch (vsi
->type
) {
7150 vsi
->alloc_queue_pairs
= pf
->num_lan_qps
;
7151 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
7152 I40E_REQ_DESCRIPTOR_MULTIPLE
);
7153 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
7154 vsi
->num_q_vectors
= pf
->num_lan_msix
;
7156 vsi
->num_q_vectors
= 1;
7161 vsi
->alloc_queue_pairs
= 1;
7162 vsi
->num_desc
= ALIGN(I40E_FDIR_RING_COUNT
,
7163 I40E_REQ_DESCRIPTOR_MULTIPLE
);
7164 vsi
->num_q_vectors
= 1;
7167 case I40E_VSI_VMDQ2
:
7168 vsi
->alloc_queue_pairs
= pf
->num_vmdq_qps
;
7169 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
7170 I40E_REQ_DESCRIPTOR_MULTIPLE
);
7171 vsi
->num_q_vectors
= pf
->num_vmdq_msix
;
7174 case I40E_VSI_SRIOV
:
7175 vsi
->alloc_queue_pairs
= pf
->num_vf_qps
;
7176 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
7177 I40E_REQ_DESCRIPTOR_MULTIPLE
);
7182 vsi
->alloc_queue_pairs
= pf
->num_fcoe_qps
;
7183 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
7184 I40E_REQ_DESCRIPTOR_MULTIPLE
);
7185 vsi
->num_q_vectors
= pf
->num_fcoe_msix
;
7188 #endif /* I40E_FCOE */
7198 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
7199 * @type: VSI pointer
7200 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
7202 * On error: returns error code (negative)
7203 * On success: returns 0
7205 static int i40e_vsi_alloc_arrays(struct i40e_vsi
*vsi
, bool alloc_qvectors
)
7210 /* allocate memory for both Tx and Rx ring pointers */
7211 size
= sizeof(struct i40e_ring
*) * vsi
->alloc_queue_pairs
* 2;
7212 vsi
->tx_rings
= kzalloc(size
, GFP_KERNEL
);
7215 vsi
->rx_rings
= &vsi
->tx_rings
[vsi
->alloc_queue_pairs
];
7217 if (alloc_qvectors
) {
7218 /* allocate memory for q_vector pointers */
7219 size
= sizeof(struct i40e_q_vector
*) * vsi
->num_q_vectors
;
7220 vsi
->q_vectors
= kzalloc(size
, GFP_KERNEL
);
7221 if (!vsi
->q_vectors
) {
7229 kfree(vsi
->tx_rings
);
7234 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
7235 * @pf: board private structure
7236 * @type: type of VSI
7238 * On error: returns error code (negative)
7239 * On success: returns vsi index in PF (positive)
7241 static int i40e_vsi_mem_alloc(struct i40e_pf
*pf
, enum i40e_vsi_type type
)
7244 struct i40e_vsi
*vsi
;
7248 /* Need to protect the allocation of the VSIs at the PF level */
7249 mutex_lock(&pf
->switch_mutex
);
7251 /* VSI list may be fragmented if VSI creation/destruction has
7252 * been happening. We can afford to do a quick scan to look
7253 * for any free VSIs in the list.
7255 * find next empty vsi slot, looping back around if necessary
7258 while (i
< pf
->num_alloc_vsi
&& pf
->vsi
[i
])
7260 if (i
>= pf
->num_alloc_vsi
) {
7262 while (i
< pf
->next_vsi
&& pf
->vsi
[i
])
7266 if (i
< pf
->num_alloc_vsi
&& !pf
->vsi
[i
]) {
7267 vsi_idx
= i
; /* Found one! */
7270 goto unlock_pf
; /* out of VSI slots! */
7274 vsi
= kzalloc(sizeof(*vsi
), GFP_KERNEL
);
7281 set_bit(__I40E_DOWN
, &vsi
->state
);
7284 vsi
->rx_itr_setting
= pf
->rx_itr_default
;
7285 vsi
->tx_itr_setting
= pf
->tx_itr_default
;
7286 vsi
->int_rate_limit
= 0;
7287 vsi
->rss_table_size
= (vsi
->type
== I40E_VSI_MAIN
) ?
7288 pf
->rss_table_size
: 64;
7289 vsi
->netdev_registered
= false;
7290 vsi
->work_limit
= I40E_DEFAULT_IRQ_WORK
;
7291 INIT_LIST_HEAD(&vsi
->mac_filter_list
);
7292 vsi
->irqs_ready
= false;
7294 ret
= i40e_set_num_rings_in_vsi(vsi
);
7298 ret
= i40e_vsi_alloc_arrays(vsi
, true);
7302 /* Setup default MSIX irq handler for VSI */
7303 i40e_vsi_setup_irqhandler(vsi
, i40e_msix_clean_rings
);
7305 /* Initialize VSI lock */
7306 spin_lock_init(&vsi
->mac_filter_list_lock
);
7307 pf
->vsi
[vsi_idx
] = vsi
;
7312 pf
->next_vsi
= i
- 1;
7315 mutex_unlock(&pf
->switch_mutex
);
7320 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
7321 * @type: VSI pointer
7322 * @free_qvectors: a bool to specify if q_vectors need to be freed.
7324 * On error: returns error code (negative)
7325 * On success: returns 0
7327 static void i40e_vsi_free_arrays(struct i40e_vsi
*vsi
, bool free_qvectors
)
7329 /* free the ring and vector containers */
7330 if (free_qvectors
) {
7331 kfree(vsi
->q_vectors
);
7332 vsi
->q_vectors
= NULL
;
7334 kfree(vsi
->tx_rings
);
7335 vsi
->tx_rings
= NULL
;
7336 vsi
->rx_rings
= NULL
;
7340 * i40e_clear_rss_config_user - clear the user configured RSS hash keys
7342 * @vsi: Pointer to VSI structure
7344 static void i40e_clear_rss_config_user(struct i40e_vsi
*vsi
)
7349 kfree(vsi
->rss_hkey_user
);
7350 vsi
->rss_hkey_user
= NULL
;
7352 kfree(vsi
->rss_lut_user
);
7353 vsi
->rss_lut_user
= NULL
;
7357 * i40e_vsi_clear - Deallocate the VSI provided
7358 * @vsi: the VSI being un-configured
7360 static int i40e_vsi_clear(struct i40e_vsi
*vsi
)
7371 mutex_lock(&pf
->switch_mutex
);
7372 if (!pf
->vsi
[vsi
->idx
]) {
7373 dev_err(&pf
->pdev
->dev
, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
7374 vsi
->idx
, vsi
->idx
, vsi
, vsi
->type
);
7378 if (pf
->vsi
[vsi
->idx
] != vsi
) {
7379 dev_err(&pf
->pdev
->dev
,
7380 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
7381 pf
->vsi
[vsi
->idx
]->idx
,
7383 pf
->vsi
[vsi
->idx
]->type
,
7384 vsi
->idx
, vsi
, vsi
->type
);
7388 /* updates the PF for this cleared vsi */
7389 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
7390 i40e_put_lump(pf
->irq_pile
, vsi
->base_vector
, vsi
->idx
);
7392 i40e_vsi_free_arrays(vsi
, true);
7393 i40e_clear_rss_config_user(vsi
);
7395 pf
->vsi
[vsi
->idx
] = NULL
;
7396 if (vsi
->idx
< pf
->next_vsi
)
7397 pf
->next_vsi
= vsi
->idx
;
7400 mutex_unlock(&pf
->switch_mutex
);
7408 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
7409 * @vsi: the VSI being cleaned
7411 static void i40e_vsi_clear_rings(struct i40e_vsi
*vsi
)
7415 if (vsi
->tx_rings
&& vsi
->tx_rings
[0]) {
7416 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
7417 kfree_rcu(vsi
->tx_rings
[i
], rcu
);
7418 vsi
->tx_rings
[i
] = NULL
;
7419 vsi
->rx_rings
[i
] = NULL
;
7425 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
7426 * @vsi: the VSI being configured
7428 static int i40e_alloc_rings(struct i40e_vsi
*vsi
)
7430 struct i40e_ring
*tx_ring
, *rx_ring
;
7431 struct i40e_pf
*pf
= vsi
->back
;
7434 /* Set basic values in the rings to be used later during open() */
7435 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
7436 /* allocate space for both Tx and Rx in one shot */
7437 tx_ring
= kzalloc(sizeof(struct i40e_ring
) * 2, GFP_KERNEL
);
7441 tx_ring
->queue_index
= i
;
7442 tx_ring
->reg_idx
= vsi
->base_queue
+ i
;
7443 tx_ring
->ring_active
= false;
7445 tx_ring
->netdev
= vsi
->netdev
;
7446 tx_ring
->dev
= &pf
->pdev
->dev
;
7447 tx_ring
->count
= vsi
->num_desc
;
7449 tx_ring
->dcb_tc
= 0;
7450 if (vsi
->back
->flags
& I40E_FLAG_WB_ON_ITR_CAPABLE
)
7451 tx_ring
->flags
= I40E_TXR_FLAGS_WB_ON_ITR
;
7452 if (vsi
->back
->flags
& I40E_FLAG_OUTER_UDP_CSUM_CAPABLE
)
7453 tx_ring
->flags
|= I40E_TXR_FLAGS_OUTER_UDP_CSUM
;
7454 vsi
->tx_rings
[i
] = tx_ring
;
7456 rx_ring
= &tx_ring
[1];
7457 rx_ring
->queue_index
= i
;
7458 rx_ring
->reg_idx
= vsi
->base_queue
+ i
;
7459 rx_ring
->ring_active
= false;
7461 rx_ring
->netdev
= vsi
->netdev
;
7462 rx_ring
->dev
= &pf
->pdev
->dev
;
7463 rx_ring
->count
= vsi
->num_desc
;
7465 rx_ring
->dcb_tc
= 0;
7466 if (pf
->flags
& I40E_FLAG_16BYTE_RX_DESC_ENABLED
)
7467 set_ring_16byte_desc_enabled(rx_ring
);
7469 clear_ring_16byte_desc_enabled(rx_ring
);
7470 vsi
->rx_rings
[i
] = rx_ring
;
7476 i40e_vsi_clear_rings(vsi
);
7481 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
7482 * @pf: board private structure
7483 * @vectors: the number of MSI-X vectors to request
7485 * Returns the number of vectors reserved, or error
7487 static int i40e_reserve_msix_vectors(struct i40e_pf
*pf
, int vectors
)
7489 vectors
= pci_enable_msix_range(pf
->pdev
, pf
->msix_entries
,
7490 I40E_MIN_MSIX
, vectors
);
7492 dev_info(&pf
->pdev
->dev
,
7493 "MSI-X vector reservation failed: %d\n", vectors
);
7501 * i40e_init_msix - Setup the MSIX capability
7502 * @pf: board private structure
7504 * Work with the OS to set up the MSIX vectors needed.
7506 * Returns the number of vectors reserved or negative on failure
7508 static int i40e_init_msix(struct i40e_pf
*pf
)
7510 struct i40e_hw
*hw
= &pf
->hw
;
7515 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
7518 /* The number of vectors we'll request will be comprised of:
7519 * - Add 1 for "other" cause for Admin Queue events, etc.
7520 * - The number of LAN queue pairs
7521 * - Queues being used for RSS.
7522 * We don't need as many as max_rss_size vectors.
7523 * use rss_size instead in the calculation since that
7524 * is governed by number of cpus in the system.
7525 * - assumes symmetric Tx/Rx pairing
7526 * - The number of VMDq pairs
7528 * - The number of FCOE qps.
7530 * Once we count this up, try the request.
7532 * If we can't get what we want, we'll simplify to nearly nothing
7533 * and try again. If that still fails, we punt.
7535 vectors_left
= hw
->func_caps
.num_msix_vectors
;
7538 /* reserve one vector for miscellaneous handler */
7544 /* reserve vectors for the main PF traffic queues */
7545 pf
->num_lan_msix
= min_t(int, num_online_cpus(), vectors_left
);
7546 vectors_left
-= pf
->num_lan_msix
;
7547 v_budget
+= pf
->num_lan_msix
;
7549 /* reserve one vector for sideband flow director */
7550 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
7555 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7560 /* can we reserve enough for FCoE? */
7561 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7563 pf
->num_fcoe_msix
= 0;
7564 else if (vectors_left
>= pf
->num_fcoe_qps
)
7565 pf
->num_fcoe_msix
= pf
->num_fcoe_qps
;
7567 pf
->num_fcoe_msix
= 1;
7568 v_budget
+= pf
->num_fcoe_msix
;
7569 vectors_left
-= pf
->num_fcoe_msix
;
7573 /* any vectors left over go for VMDq support */
7574 if (pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) {
7575 int vmdq_vecs_wanted
= pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
;
7576 int vmdq_vecs
= min_t(int, vectors_left
, vmdq_vecs_wanted
);
7578 /* if we're short on vectors for what's desired, we limit
7579 * the queues per vmdq. If this is still more than are
7580 * available, the user will need to change the number of
7581 * queues/vectors used by the PF later with the ethtool
7584 if (vmdq_vecs
< vmdq_vecs_wanted
)
7585 pf
->num_vmdq_qps
= 1;
7586 pf
->num_vmdq_msix
= pf
->num_vmdq_qps
;
7588 v_budget
+= vmdq_vecs
;
7589 vectors_left
-= vmdq_vecs
;
7592 pf
->msix_entries
= kcalloc(v_budget
, sizeof(struct msix_entry
),
7594 if (!pf
->msix_entries
)
7597 for (i
= 0; i
< v_budget
; i
++)
7598 pf
->msix_entries
[i
].entry
= i
;
7599 v_actual
= i40e_reserve_msix_vectors(pf
, v_budget
);
7601 if (v_actual
!= v_budget
) {
7602 /* If we have limited resources, we will start with no vectors
7603 * for the special features and then allocate vectors to some
7604 * of these features based on the policy and at the end disable
7605 * the features that did not get any vectors.
7608 pf
->num_fcoe_qps
= 0;
7609 pf
->num_fcoe_msix
= 0;
7611 pf
->num_vmdq_msix
= 0;
7614 if (v_actual
< I40E_MIN_MSIX
) {
7615 pf
->flags
&= ~I40E_FLAG_MSIX_ENABLED
;
7616 kfree(pf
->msix_entries
);
7617 pf
->msix_entries
= NULL
;
7620 } else if (v_actual
== I40E_MIN_MSIX
) {
7621 /* Adjust for minimal MSIX use */
7622 pf
->num_vmdq_vsis
= 0;
7623 pf
->num_vmdq_qps
= 0;
7624 pf
->num_lan_qps
= 1;
7625 pf
->num_lan_msix
= 1;
7627 } else if (v_actual
!= v_budget
) {
7630 /* reserve the misc vector */
7633 /* Scale vector usage down */
7634 pf
->num_vmdq_msix
= 1; /* force VMDqs to only one vector */
7635 pf
->num_vmdq_vsis
= 1;
7636 pf
->num_vmdq_qps
= 1;
7637 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7639 /* partition out the remaining vectors */
7642 pf
->num_lan_msix
= 1;
7646 /* give one vector to FCoE */
7647 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7648 pf
->num_lan_msix
= 1;
7649 pf
->num_fcoe_msix
= 1;
7652 pf
->num_lan_msix
= 2;
7657 /* give one vector to FCoE */
7658 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7659 pf
->num_fcoe_msix
= 1;
7663 /* give the rest to the PF */
7664 pf
->num_lan_msix
= min_t(int, vec
, pf
->num_lan_qps
);
7669 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
7670 (pf
->num_vmdq_msix
== 0)) {
7671 dev_info(&pf
->pdev
->dev
, "VMDq disabled, not enough MSI-X vectors\n");
7672 pf
->flags
&= ~I40E_FLAG_VMDQ_ENABLED
;
7676 if ((pf
->flags
& I40E_FLAG_FCOE_ENABLED
) && (pf
->num_fcoe_msix
== 0)) {
7677 dev_info(&pf
->pdev
->dev
, "FCOE disabled, not enough MSI-X vectors\n");
7678 pf
->flags
&= ~I40E_FLAG_FCOE_ENABLED
;
7685 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
7686 * @vsi: the VSI being configured
7687 * @v_idx: index of the vector in the vsi struct
7689 * We allocate one q_vector. If allocation fails we return -ENOMEM.
7691 static int i40e_vsi_alloc_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
7693 struct i40e_q_vector
*q_vector
;
7695 /* allocate q_vector */
7696 q_vector
= kzalloc(sizeof(struct i40e_q_vector
), GFP_KERNEL
);
7700 q_vector
->vsi
= vsi
;
7701 q_vector
->v_idx
= v_idx
;
7702 cpumask_set_cpu(v_idx
, &q_vector
->affinity_mask
);
7704 netif_napi_add(vsi
->netdev
, &q_vector
->napi
,
7705 i40e_napi_poll
, NAPI_POLL_WEIGHT
);
7707 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
7708 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
7710 /* tie q_vector and vsi together */
7711 vsi
->q_vectors
[v_idx
] = q_vector
;
7717 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
7718 * @vsi: the VSI being configured
7720 * We allocate one q_vector per queue interrupt. If allocation fails we
7723 static int i40e_vsi_alloc_q_vectors(struct i40e_vsi
*vsi
)
7725 struct i40e_pf
*pf
= vsi
->back
;
7726 int v_idx
, num_q_vectors
;
7729 /* if not MSIX, give the one vector only to the LAN VSI */
7730 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
7731 num_q_vectors
= vsi
->num_q_vectors
;
7732 else if (vsi
== pf
->vsi
[pf
->lan_vsi
])
7737 for (v_idx
= 0; v_idx
< num_q_vectors
; v_idx
++) {
7738 err
= i40e_vsi_alloc_q_vector(vsi
, v_idx
);
7747 i40e_free_q_vector(vsi
, v_idx
);
7753 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
7754 * @pf: board private structure to initialize
7756 static int i40e_init_interrupt_scheme(struct i40e_pf
*pf
)
7761 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
7762 vectors
= i40e_init_msix(pf
);
7764 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
|
7766 I40E_FLAG_FCOE_ENABLED
|
7768 I40E_FLAG_RSS_ENABLED
|
7769 I40E_FLAG_DCB_CAPABLE
|
7770 I40E_FLAG_SRIOV_ENABLED
|
7771 I40E_FLAG_FD_SB_ENABLED
|
7772 I40E_FLAG_FD_ATR_ENABLED
|
7773 I40E_FLAG_VMDQ_ENABLED
);
7775 /* rework the queue expectations without MSIX */
7776 i40e_determine_queue_usage(pf
);
7780 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
7781 (pf
->flags
& I40E_FLAG_MSI_ENABLED
)) {
7782 dev_info(&pf
->pdev
->dev
, "MSI-X not available, trying MSI\n");
7783 vectors
= pci_enable_msi(pf
->pdev
);
7785 dev_info(&pf
->pdev
->dev
, "MSI init failed - %d\n",
7787 pf
->flags
&= ~I40E_FLAG_MSI_ENABLED
;
7789 vectors
= 1; /* one MSI or Legacy vector */
7792 if (!(pf
->flags
& (I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
)))
7793 dev_info(&pf
->pdev
->dev
, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
7795 /* set up vector assignment tracking */
7796 size
= sizeof(struct i40e_lump_tracking
) + (sizeof(u16
) * vectors
);
7797 pf
->irq_pile
= kzalloc(size
, GFP_KERNEL
);
7798 if (!pf
->irq_pile
) {
7799 dev_err(&pf
->pdev
->dev
, "error allocating irq_pile memory\n");
7802 pf
->irq_pile
->num_entries
= vectors
;
7803 pf
->irq_pile
->search_hint
= 0;
7805 /* track first vector for misc interrupts, ignore return */
7806 (void)i40e_get_lump(pf
, pf
->irq_pile
, 1, I40E_PILE_VALID_BIT
- 1);
7812 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
7813 * @pf: board private structure
7815 * This sets up the handler for MSIX 0, which is used to manage the
7816 * non-queue interrupts, e.g. AdminQ and errors. This is not used
7817 * when in MSI or Legacy interrupt mode.
7819 static int i40e_setup_misc_vector(struct i40e_pf
*pf
)
7821 struct i40e_hw
*hw
= &pf
->hw
;
7824 /* Only request the irq if this is the first time through, and
7825 * not when we're rebuilding after a Reset
7827 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
)) {
7828 err
= request_irq(pf
->msix_entries
[0].vector
,
7829 i40e_intr
, 0, pf
->int_name
, pf
);
7831 dev_info(&pf
->pdev
->dev
,
7832 "request_irq for %s failed: %d\n",
7838 i40e_enable_misc_int_causes(pf
);
7840 /* associate no queues to the misc vector */
7841 wr32(hw
, I40E_PFINT_LNKLST0
, I40E_QUEUE_END_OF_LIST
);
7842 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), I40E_ITR_8K
);
7846 i40e_irq_dynamic_enable_icr0(pf
);
7852 * i40e_config_rss_aq - Prepare for RSS using AQ commands
7853 * @vsi: vsi structure
7854 * @seed: RSS hash seed
7856 static int i40e_config_rss_aq(struct i40e_vsi
*vsi
, const u8
*seed
,
7857 u8
*lut
, u16 lut_size
)
7859 struct i40e_aqc_get_set_rss_key_data rss_key
;
7860 struct i40e_pf
*pf
= vsi
->back
;
7861 struct i40e_hw
*hw
= &pf
->hw
;
7862 bool pf_lut
= false;
7866 memset(&rss_key
, 0, sizeof(rss_key
));
7867 memcpy(&rss_key
, seed
, sizeof(rss_key
));
7869 rss_lut
= kzalloc(pf
->rss_table_size
, GFP_KERNEL
);
7873 /* Populate the LUT with max no. of queues in round robin fashion */
7874 for (i
= 0; i
< vsi
->rss_table_size
; i
++)
7875 rss_lut
[i
] = i
% vsi
->rss_size
;
7877 ret
= i40e_aq_set_rss_key(hw
, vsi
->id
, &rss_key
);
7879 dev_info(&pf
->pdev
->dev
,
7880 "Cannot set RSS key, err %s aq_err %s\n",
7881 i40e_stat_str(&pf
->hw
, ret
),
7882 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
7883 goto config_rss_aq_out
;
7886 if (vsi
->type
== I40E_VSI_MAIN
)
7889 ret
= i40e_aq_set_rss_lut(hw
, vsi
->id
, pf_lut
, rss_lut
,
7890 vsi
->rss_table_size
);
7892 dev_info(&pf
->pdev
->dev
,
7893 "Cannot set RSS lut, err %s aq_err %s\n",
7894 i40e_stat_str(&pf
->hw
, ret
),
7895 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
7903 * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
7904 * @vsi: VSI structure
7906 static int i40e_vsi_config_rss(struct i40e_vsi
*vsi
)
7908 u8 seed
[I40E_HKEY_ARRAY_SIZE
];
7909 struct i40e_pf
*pf
= vsi
->back
;
7913 if (!(pf
->flags
& I40E_FLAG_RSS_AQ_CAPABLE
))
7916 lut
= kzalloc(vsi
->rss_table_size
, GFP_KERNEL
);
7920 i40e_fill_rss_lut(pf
, lut
, vsi
->rss_table_size
, vsi
->rss_size
);
7921 netdev_rss_key_fill((void *)seed
, I40E_HKEY_ARRAY_SIZE
);
7922 vsi
->rss_size
= min_t(int, pf
->alloc_rss_size
, vsi
->num_queue_pairs
);
7923 ret
= i40e_config_rss_aq(vsi
, seed
, lut
, vsi
->rss_table_size
);
7930 * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
7931 * @vsi: Pointer to vsi structure
7932 * @seed: RSS hash seed
7933 * @lut: Lookup table
7934 * @lut_size: Lookup table size
7936 * Returns 0 on success, negative on failure
7938 static int i40e_config_rss_reg(struct i40e_vsi
*vsi
, const u8
*seed
,
7939 const u8
*lut
, u16 lut_size
)
7941 struct i40e_pf
*pf
= vsi
->back
;
7942 struct i40e_hw
*hw
= &pf
->hw
;
7945 /* Fill out hash function seed */
7947 u32
*seed_dw
= (u32
*)seed
;
7949 for (i
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++)
7950 wr32(hw
, I40E_PFQF_HKEY(i
), seed_dw
[i
]);
7954 u32
*lut_dw
= (u32
*)lut
;
7956 if (lut_size
!= I40E_HLUT_ARRAY_SIZE
)
7959 for (i
= 0; i
<= I40E_PFQF_HLUT_MAX_INDEX
; i
++)
7960 wr32(hw
, I40E_PFQF_HLUT(i
), lut_dw
[i
]);
7968 * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
7969 * @vsi: Pointer to VSI structure
7970 * @seed: Buffer to store the keys
7971 * @lut: Buffer to store the lookup table entries
7972 * @lut_size: Size of buffer to store the lookup table entries
7974 * Returns 0 on success, negative on failure
7976 static int i40e_get_rss_reg(struct i40e_vsi
*vsi
, u8
*seed
,
7977 u8
*lut
, u16 lut_size
)
7979 struct i40e_pf
*pf
= vsi
->back
;
7980 struct i40e_hw
*hw
= &pf
->hw
;
7984 u32
*seed_dw
= (u32
*)seed
;
7986 for (i
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++)
7987 seed_dw
[i
] = rd32(hw
, I40E_PFQF_HKEY(i
));
7990 u32
*lut_dw
= (u32
*)lut
;
7992 if (lut_size
!= I40E_HLUT_ARRAY_SIZE
)
7994 for (i
= 0; i
<= I40E_PFQF_HLUT_MAX_INDEX
; i
++)
7995 lut_dw
[i
] = rd32(hw
, I40E_PFQF_HLUT(i
));
8002 * i40e_config_rss - Configure RSS keys and lut
8003 * @vsi: Pointer to VSI structure
8004 * @seed: RSS hash seed
8005 * @lut: Lookup table
8006 * @lut_size: Lookup table size
8008 * Returns 0 on success, negative on failure
8010 int i40e_config_rss(struct i40e_vsi
*vsi
, u8
*seed
, u8
*lut
, u16 lut_size
)
8012 struct i40e_pf
*pf
= vsi
->back
;
8014 if (pf
->flags
& I40E_FLAG_RSS_AQ_CAPABLE
)
8015 return i40e_config_rss_aq(vsi
, seed
, lut
, lut_size
);
8017 return i40e_config_rss_reg(vsi
, seed
, lut
, lut_size
);
8021 * i40e_get_rss - Get RSS keys and lut
8022 * @vsi: Pointer to VSI structure
8023 * @seed: Buffer to store the keys
8024 * @lut: Buffer to store the lookup table entries
8025 * lut_size: Size of buffer to store the lookup table entries
8027 * Returns 0 on success, negative on failure
8029 int i40e_get_rss(struct i40e_vsi
*vsi
, u8
*seed
, u8
*lut
, u16 lut_size
)
8031 return i40e_get_rss_reg(vsi
, seed
, lut
, lut_size
);
8035 * i40e_fill_rss_lut - Fill the RSS lookup table with default values
8036 * @pf: Pointer to board private structure
8037 * @lut: Lookup table
8038 * @rss_table_size: Lookup table size
8039 * @rss_size: Range of queue number for hashing
8041 static void i40e_fill_rss_lut(struct i40e_pf
*pf
, u8
*lut
,
8042 u16 rss_table_size
, u16 rss_size
)
8046 for (i
= 0; i
< rss_table_size
; i
++)
8047 lut
[i
] = i
% rss_size
;
8051 * i40e_pf_config_rss - Prepare for RSS if used
8052 * @pf: board private structure
8054 static int i40e_pf_config_rss(struct i40e_pf
*pf
)
8056 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
8057 u8 seed
[I40E_HKEY_ARRAY_SIZE
];
8059 struct i40e_hw
*hw
= &pf
->hw
;
8064 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
8065 hena
= (u64
)rd32(hw
, I40E_PFQF_HENA(0)) |
8066 ((u64
)rd32(hw
, I40E_PFQF_HENA(1)) << 32);
8067 hena
|= i40e_pf_get_default_rss_hena(pf
);
8069 wr32(hw
, I40E_PFQF_HENA(0), (u32
)hena
);
8070 wr32(hw
, I40E_PFQF_HENA(1), (u32
)(hena
>> 32));
8072 /* Determine the RSS table size based on the hardware capabilities */
8073 reg_val
= rd32(hw
, I40E_PFQF_CTL_0
);
8074 reg_val
= (pf
->rss_table_size
== 512) ?
8075 (reg_val
| I40E_PFQF_CTL_0_HASHLUTSIZE_512
) :
8076 (reg_val
& ~I40E_PFQF_CTL_0_HASHLUTSIZE_512
);
8077 wr32(hw
, I40E_PFQF_CTL_0
, reg_val
);
8079 /* Determine the RSS size of the VSI */
8081 vsi
->rss_size
= min_t(int, pf
->alloc_rss_size
,
8082 vsi
->num_queue_pairs
);
8084 lut
= kzalloc(vsi
->rss_table_size
, GFP_KERNEL
);
8088 /* Use user configured lut if there is one, otherwise use default */
8089 if (vsi
->rss_lut_user
)
8090 memcpy(lut
, vsi
->rss_lut_user
, vsi
->rss_table_size
);
8092 i40e_fill_rss_lut(pf
, lut
, vsi
->rss_table_size
, vsi
->rss_size
);
8094 /* Use user configured hash key if there is one, otherwise
8097 if (vsi
->rss_hkey_user
)
8098 memcpy(seed
, vsi
->rss_hkey_user
, I40E_HKEY_ARRAY_SIZE
);
8100 netdev_rss_key_fill((void *)seed
, I40E_HKEY_ARRAY_SIZE
);
8101 ret
= i40e_config_rss(vsi
, seed
, lut
, vsi
->rss_table_size
);
8108 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
8109 * @pf: board private structure
8110 * @queue_count: the requested queue count for rss.
8112 * returns 0 if rss is not enabled, if enabled returns the final rss queue
8113 * count which may be different from the requested queue count.
8115 int i40e_reconfig_rss_queues(struct i40e_pf
*pf
, int queue_count
)
8117 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
8120 if (!(pf
->flags
& I40E_FLAG_RSS_ENABLED
))
8123 new_rss_size
= min_t(int, queue_count
, pf
->rss_size_max
);
8125 if (queue_count
!= vsi
->num_queue_pairs
) {
8126 vsi
->req_queue_pairs
= queue_count
;
8127 i40e_prep_for_reset(pf
);
8129 pf
->alloc_rss_size
= new_rss_size
;
8131 i40e_reset_and_rebuild(pf
, true);
8133 /* Discard the user configured hash keys and lut, if less
8134 * queues are enabled.
8136 if (queue_count
< vsi
->rss_size
) {
8137 i40e_clear_rss_config_user(vsi
);
8138 dev_dbg(&pf
->pdev
->dev
,
8139 "discard user configured hash keys and lut\n");
8142 /* Reset vsi->rss_size, as number of enabled queues changed */
8143 vsi
->rss_size
= min_t(int, pf
->alloc_rss_size
,
8144 vsi
->num_queue_pairs
);
8146 i40e_pf_config_rss(pf
);
8148 dev_info(&pf
->pdev
->dev
, "RSS count/HW max RSS count: %d/%d\n",
8149 pf
->alloc_rss_size
, pf
->rss_size_max
);
8150 return pf
->alloc_rss_size
;
8154 * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition
8155 * @pf: board private structure
8157 i40e_status
i40e_get_npar_bw_setting(struct i40e_pf
*pf
)
8160 bool min_valid
, max_valid
;
8163 status
= i40e_read_bw_from_alt_ram(&pf
->hw
, &max_bw
, &min_bw
,
8164 &min_valid
, &max_valid
);
8168 pf
->npar_min_bw
= min_bw
;
8170 pf
->npar_max_bw
= max_bw
;
8177 * i40e_set_npar_bw_setting - Set BW settings for this PF partition
8178 * @pf: board private structure
8180 i40e_status
i40e_set_npar_bw_setting(struct i40e_pf
*pf
)
8182 struct i40e_aqc_configure_partition_bw_data bw_data
;
8185 /* Set the valid bit for this PF */
8186 bw_data
.pf_valid_bits
= cpu_to_le16(BIT(pf
->hw
.pf_id
));
8187 bw_data
.max_bw
[pf
->hw
.pf_id
] = pf
->npar_max_bw
& I40E_ALT_BW_VALUE_MASK
;
8188 bw_data
.min_bw
[pf
->hw
.pf_id
] = pf
->npar_min_bw
& I40E_ALT_BW_VALUE_MASK
;
8190 /* Set the new bandwidths */
8191 status
= i40e_aq_configure_partition_bw(&pf
->hw
, &bw_data
, NULL
);
8197 * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition
8198 * @pf: board private structure
8200 i40e_status
i40e_commit_npar_bw_setting(struct i40e_pf
*pf
)
8202 /* Commit temporary BW setting to permanent NVM image */
8203 enum i40e_admin_queue_err last_aq_status
;
8207 if (pf
->hw
.partition_id
!= 1) {
8208 dev_info(&pf
->pdev
->dev
,
8209 "Commit BW only works on partition 1! This is partition %d",
8210 pf
->hw
.partition_id
);
8211 ret
= I40E_NOT_SUPPORTED
;
8215 /* Acquire NVM for read access */
8216 ret
= i40e_acquire_nvm(&pf
->hw
, I40E_RESOURCE_READ
);
8217 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
8219 dev_info(&pf
->pdev
->dev
,
8220 "Cannot acquire NVM for read access, err %s aq_err %s\n",
8221 i40e_stat_str(&pf
->hw
, ret
),
8222 i40e_aq_str(&pf
->hw
, last_aq_status
));
8226 /* Read word 0x10 of NVM - SW compatibility word 1 */
8227 ret
= i40e_aq_read_nvm(&pf
->hw
,
8228 I40E_SR_NVM_CONTROL_WORD
,
8229 0x10, sizeof(nvm_word
), &nvm_word
,
8231 /* Save off last admin queue command status before releasing
8234 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
8235 i40e_release_nvm(&pf
->hw
);
8237 dev_info(&pf
->pdev
->dev
, "NVM read error, err %s aq_err %s\n",
8238 i40e_stat_str(&pf
->hw
, ret
),
8239 i40e_aq_str(&pf
->hw
, last_aq_status
));
8243 /* Wait a bit for NVM release to complete */
8246 /* Acquire NVM for write access */
8247 ret
= i40e_acquire_nvm(&pf
->hw
, I40E_RESOURCE_WRITE
);
8248 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
8250 dev_info(&pf
->pdev
->dev
,
8251 "Cannot acquire NVM for write access, err %s aq_err %s\n",
8252 i40e_stat_str(&pf
->hw
, ret
),
8253 i40e_aq_str(&pf
->hw
, last_aq_status
));
8256 /* Write it back out unchanged to initiate update NVM,
8257 * which will force a write of the shadow (alt) RAM to
8258 * the NVM - thus storing the bandwidth values permanently.
8260 ret
= i40e_aq_update_nvm(&pf
->hw
,
8261 I40E_SR_NVM_CONTROL_WORD
,
8262 0x10, sizeof(nvm_word
),
8263 &nvm_word
, true, NULL
);
8264 /* Save off last admin queue command status before releasing
8267 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
8268 i40e_release_nvm(&pf
->hw
);
8270 dev_info(&pf
->pdev
->dev
,
8271 "BW settings NOT SAVED, err %s aq_err %s\n",
8272 i40e_stat_str(&pf
->hw
, ret
),
8273 i40e_aq_str(&pf
->hw
, last_aq_status
));
8280 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
8281 * @pf: board private structure to initialize
8283 * i40e_sw_init initializes the Adapter private data structure.
8284 * Fields are initialized based on PCI device information and
8285 * OS network device settings (MTU size).
8287 static int i40e_sw_init(struct i40e_pf
*pf
)
8292 pf
->msg_enable
= netif_msg_init(I40E_DEFAULT_MSG_ENABLE
,
8293 (NETIF_MSG_DRV
|NETIF_MSG_PROBE
|NETIF_MSG_LINK
));
8294 pf
->hw
.debug_mask
= pf
->msg_enable
| I40E_DEBUG_DIAG
;
8295 if (debug
!= -1 && debug
!= I40E_DEFAULT_MSG_ENABLE
) {
8296 if (I40E_DEBUG_USER
& debug
)
8297 pf
->hw
.debug_mask
= debug
;
8298 pf
->msg_enable
= netif_msg_init((debug
& ~I40E_DEBUG_USER
),
8299 I40E_DEFAULT_MSG_ENABLE
);
8302 /* Set default capability flags */
8303 pf
->flags
= I40E_FLAG_RX_CSUM_ENABLED
|
8304 I40E_FLAG_MSI_ENABLED
|
8305 I40E_FLAG_LINK_POLLING_ENABLED
|
8306 I40E_FLAG_MSIX_ENABLED
;
8308 if (iommu_present(&pci_bus_type
))
8309 pf
->flags
|= I40E_FLAG_RX_PS_ENABLED
;
8311 pf
->flags
|= I40E_FLAG_RX_1BUF_ENABLED
;
8313 /* Set default ITR */
8314 pf
->rx_itr_default
= I40E_ITR_DYNAMIC
| I40E_ITR_RX_DEF
;
8315 pf
->tx_itr_default
= I40E_ITR_DYNAMIC
| I40E_ITR_TX_DEF
;
8317 /* Depending on PF configurations, it is possible that the RSS
8318 * maximum might end up larger than the available queues
8320 pf
->rss_size_max
= BIT(pf
->hw
.func_caps
.rss_table_entry_width
);
8321 pf
->alloc_rss_size
= 1;
8322 pf
->rss_table_size
= pf
->hw
.func_caps
.rss_table_size
;
8323 pf
->rss_size_max
= min_t(int, pf
->rss_size_max
,
8324 pf
->hw
.func_caps
.num_tx_qp
);
8325 if (pf
->hw
.func_caps
.rss
) {
8326 pf
->flags
|= I40E_FLAG_RSS_ENABLED
;
8327 pf
->alloc_rss_size
= min_t(int, pf
->rss_size_max
,
8331 /* MFP mode enabled */
8332 if (pf
->hw
.func_caps
.npar_enable
|| pf
->hw
.func_caps
.flex10_enable
) {
8333 pf
->flags
|= I40E_FLAG_MFP_ENABLED
;
8334 dev_info(&pf
->pdev
->dev
, "MFP mode Enabled\n");
8335 if (i40e_get_npar_bw_setting(pf
))
8336 dev_warn(&pf
->pdev
->dev
,
8337 "Could not get NPAR bw settings\n");
8339 dev_info(&pf
->pdev
->dev
,
8340 "Min BW = %8.8x, Max BW = %8.8x\n",
8341 pf
->npar_min_bw
, pf
->npar_max_bw
);
8344 /* FW/NVM is not yet fixed in this regard */
8345 if ((pf
->hw
.func_caps
.fd_filters_guaranteed
> 0) ||
8346 (pf
->hw
.func_caps
.fd_filters_best_effort
> 0)) {
8347 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
8348 pf
->atr_sample_rate
= I40E_DEFAULT_ATR_SAMPLE_RATE
;
8349 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
&&
8350 pf
->hw
.num_partitions
> 1)
8351 dev_info(&pf
->pdev
->dev
,
8352 "Flow Director Sideband mode Disabled in MFP mode\n");
8354 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
8355 pf
->fdir_pf_filter_count
=
8356 pf
->hw
.func_caps
.fd_filters_guaranteed
;
8357 pf
->hw
.fdir_shared_filter_count
=
8358 pf
->hw
.func_caps
.fd_filters_best_effort
;
8361 if (pf
->hw
.func_caps
.vmdq
) {
8362 pf
->num_vmdq_vsis
= I40E_DEFAULT_NUM_VMDQ_VSI
;
8363 pf
->flags
|= I40E_FLAG_VMDQ_ENABLED
;
8364 pf
->num_vmdq_qps
= i40e_default_queues_per_vmdq(pf
);
8368 i40e_init_pf_fcoe(pf
);
8370 #endif /* I40E_FCOE */
8371 #ifdef CONFIG_PCI_IOV
8372 if (pf
->hw
.func_caps
.num_vfs
&& pf
->hw
.partition_id
== 1) {
8373 pf
->num_vf_qps
= I40E_DEFAULT_QUEUES_PER_VF
;
8374 pf
->flags
|= I40E_FLAG_SRIOV_ENABLED
;
8375 pf
->num_req_vfs
= min_t(int,
8376 pf
->hw
.func_caps
.num_vfs
,
8379 #endif /* CONFIG_PCI_IOV */
8380 if (pf
->hw
.mac
.type
== I40E_MAC_X722
) {
8381 pf
->flags
|= I40E_FLAG_RSS_AQ_CAPABLE
|
8382 I40E_FLAG_128_QP_RSS_CAPABLE
|
8383 I40E_FLAG_HW_ATR_EVICT_CAPABLE
|
8384 I40E_FLAG_OUTER_UDP_CSUM_CAPABLE
|
8385 I40E_FLAG_WB_ON_ITR_CAPABLE
|
8386 I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE
|
8387 I40E_FLAG_GENEVE_OFFLOAD_CAPABLE
;
8389 pf
->eeprom_version
= 0xDEAD;
8390 pf
->lan_veb
= I40E_NO_VEB
;
8391 pf
->lan_vsi
= I40E_NO_VSI
;
8393 /* By default FW has this off for performance reasons */
8394 pf
->flags
&= ~I40E_FLAG_VEB_STATS_ENABLED
;
8396 /* set up queue assignment tracking */
8397 size
= sizeof(struct i40e_lump_tracking
)
8398 + (sizeof(u16
) * pf
->hw
.func_caps
.num_tx_qp
);
8399 pf
->qp_pile
= kzalloc(size
, GFP_KERNEL
);
8404 pf
->qp_pile
->num_entries
= pf
->hw
.func_caps
.num_tx_qp
;
8405 pf
->qp_pile
->search_hint
= 0;
8407 pf
->tx_timeout_recovery_level
= 1;
8409 mutex_init(&pf
->switch_mutex
);
8411 /* If NPAR is enabled nudge the Tx scheduler */
8412 if (pf
->hw
.func_caps
.npar_enable
&& (!i40e_get_npar_bw_setting(pf
)))
8413 i40e_set_npar_bw_setting(pf
);
8420 * i40e_set_ntuple - set the ntuple feature flag and take action
8421 * @pf: board private structure to initialize
8422 * @features: the feature set that the stack is suggesting
8424 * returns a bool to indicate if reset needs to happen
8426 bool i40e_set_ntuple(struct i40e_pf
*pf
, netdev_features_t features
)
8428 bool need_reset
= false;
8430 /* Check if Flow Director n-tuple support was enabled or disabled. If
8431 * the state changed, we need to reset.
8433 if (features
& NETIF_F_NTUPLE
) {
8434 /* Enable filters and mark for reset */
8435 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
8437 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
8439 /* turn off filters, mark for reset and clear SW filter list */
8440 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
8442 i40e_fdir_filter_exit(pf
);
8444 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
8445 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
8446 /* reset fd counters */
8447 pf
->fd_add_err
= pf
->fd_atr_cnt
= pf
->fd_tcp_rule
= 0;
8448 pf
->fdir_pf_active_filters
= 0;
8449 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
8450 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
8451 dev_info(&pf
->pdev
->dev
, "ATR re-enabled.\n");
8452 /* if ATR was auto disabled it can be re-enabled. */
8453 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
8454 (pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
))
8455 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
8461 * i40e_set_features - set the netdev feature flags
8462 * @netdev: ptr to the netdev being adjusted
8463 * @features: the feature set that the stack is suggesting
8465 static int i40e_set_features(struct net_device
*netdev
,
8466 netdev_features_t features
)
8468 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8469 struct i40e_vsi
*vsi
= np
->vsi
;
8470 struct i40e_pf
*pf
= vsi
->back
;
8473 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
8474 i40e_vlan_stripping_enable(vsi
);
8476 i40e_vlan_stripping_disable(vsi
);
8478 need_reset
= i40e_set_ntuple(pf
, features
);
8481 i40e_do_reset(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
8486 #if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE)
8488 * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
8489 * @pf: board private structure
8490 * @port: The UDP port to look up
8492 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
8494 static u8
i40e_get_udp_port_idx(struct i40e_pf
*pf
, __be16 port
)
8498 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
8499 if (pf
->udp_ports
[i
].index
== port
)
8508 * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up
8509 * @netdev: This physical port's netdev
8510 * @sa_family: Socket Family that VXLAN is notifying us about
8511 * @port: New UDP port number that VXLAN started listening to
8513 static void i40e_add_vxlan_port(struct net_device
*netdev
,
8514 sa_family_t sa_family
, __be16 port
)
8516 #if IS_ENABLED(CONFIG_VXLAN)
8517 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8518 struct i40e_vsi
*vsi
= np
->vsi
;
8519 struct i40e_pf
*pf
= vsi
->back
;
8523 if (sa_family
== AF_INET6
)
8526 idx
= i40e_get_udp_port_idx(pf
, port
);
8528 /* Check if port already exists */
8529 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
8530 netdev_info(netdev
, "vxlan port %d already offloaded\n",
8535 /* Now check if there is space to add the new port */
8536 next_idx
= i40e_get_udp_port_idx(pf
, 0);
8538 if (next_idx
== I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
8539 netdev_info(netdev
, "maximum number of vxlan UDP ports reached, not adding port %d\n",
8544 /* New port: add it and mark its index in the bitmap */
8545 pf
->udp_ports
[next_idx
].index
= port
;
8546 pf
->udp_ports
[next_idx
].type
= I40E_AQC_TUNNEL_TYPE_VXLAN
;
8547 pf
->pending_udp_bitmap
|= BIT_ULL(next_idx
);
8548 pf
->flags
|= I40E_FLAG_UDP_FILTER_SYNC
;
8553 * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away
8554 * @netdev: This physical port's netdev
8555 * @sa_family: Socket Family that VXLAN is notifying us about
8556 * @port: UDP port number that VXLAN stopped listening to
8558 static void i40e_del_vxlan_port(struct net_device
*netdev
,
8559 sa_family_t sa_family
, __be16 port
)
8561 #if IS_ENABLED(CONFIG_VXLAN)
8562 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8563 struct i40e_vsi
*vsi
= np
->vsi
;
8564 struct i40e_pf
*pf
= vsi
->back
;
8567 if (sa_family
== AF_INET6
)
8570 idx
= i40e_get_udp_port_idx(pf
, port
);
8572 /* Check if port already exists */
8573 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
8574 /* if port exists, set it to 0 (mark for deletion)
8575 * and make it pending
8577 pf
->udp_ports
[idx
].index
= 0;
8578 pf
->pending_udp_bitmap
|= BIT_ULL(idx
);
8579 pf
->flags
|= I40E_FLAG_UDP_FILTER_SYNC
;
8581 netdev_warn(netdev
, "vxlan port %d was not found, not deleting\n",
8588 * i40e_add_geneve_port - Get notifications about GENEVE ports that come up
8589 * @netdev: This physical port's netdev
8590 * @sa_family: Socket Family that GENEVE is notifying us about
8591 * @port: New UDP port number that GENEVE started listening to
8593 static void i40e_add_geneve_port(struct net_device
*netdev
,
8594 sa_family_t sa_family
, __be16 port
)
8596 #if IS_ENABLED(CONFIG_GENEVE)
8597 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8598 struct i40e_vsi
*vsi
= np
->vsi
;
8599 struct i40e_pf
*pf
= vsi
->back
;
8603 if (sa_family
== AF_INET6
)
8606 idx
= i40e_get_udp_port_idx(pf
, port
);
8608 /* Check if port already exists */
8609 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
8610 netdev_info(netdev
, "udp port %d already offloaded\n",
8615 /* Now check if there is space to add the new port */
8616 next_idx
= i40e_get_udp_port_idx(pf
, 0);
8618 if (next_idx
== I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
8619 netdev_info(netdev
, "maximum number of UDP ports reached, not adding port %d\n",
8624 /* New port: add it and mark its index in the bitmap */
8625 pf
->udp_ports
[next_idx
].index
= port
;
8626 pf
->udp_ports
[next_idx
].type
= I40E_AQC_TUNNEL_TYPE_NGE
;
8627 pf
->pending_udp_bitmap
|= BIT_ULL(next_idx
);
8628 pf
->flags
|= I40E_FLAG_UDP_FILTER_SYNC
;
8630 dev_info(&pf
->pdev
->dev
, "adding geneve port %d\n", ntohs(port
));
8635 * i40e_del_geneve_port - Get notifications about GENEVE ports that go away
8636 * @netdev: This physical port's netdev
8637 * @sa_family: Socket Family that GENEVE is notifying us about
8638 * @port: UDP port number that GENEVE stopped listening to
8640 static void i40e_del_geneve_port(struct net_device
*netdev
,
8641 sa_family_t sa_family
, __be16 port
)
8643 #if IS_ENABLED(CONFIG_GENEVE)
8644 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8645 struct i40e_vsi
*vsi
= np
->vsi
;
8646 struct i40e_pf
*pf
= vsi
->back
;
8649 if (sa_family
== AF_INET6
)
8652 idx
= i40e_get_udp_port_idx(pf
, port
);
8654 /* Check if port already exists */
8655 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
8656 /* if port exists, set it to 0 (mark for deletion)
8657 * and make it pending
8659 pf
->udp_ports
[idx
].index
= 0;
8660 pf
->pending_udp_bitmap
|= BIT_ULL(idx
);
8661 pf
->flags
|= I40E_FLAG_UDP_FILTER_SYNC
;
8663 dev_info(&pf
->pdev
->dev
, "deleting geneve port %d\n",
8666 netdev_warn(netdev
, "geneve port %d was not found, not deleting\n",
8672 static int i40e_get_phys_port_id(struct net_device
*netdev
,
8673 struct netdev_phys_item_id
*ppid
)
8675 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8676 struct i40e_pf
*pf
= np
->vsi
->back
;
8677 struct i40e_hw
*hw
= &pf
->hw
;
8679 if (!(pf
->flags
& I40E_FLAG_PORT_ID_VALID
))
8682 ppid
->id_len
= min_t(int, sizeof(hw
->mac
.port_addr
), sizeof(ppid
->id
));
8683 memcpy(ppid
->id
, hw
->mac
.port_addr
, ppid
->id_len
);
8689 * i40e_ndo_fdb_add - add an entry to the hardware database
8690 * @ndm: the input from the stack
8691 * @tb: pointer to array of nladdr (unused)
8692 * @dev: the net device pointer
8693 * @addr: the MAC address entry being added
8694 * @flags: instructions from stack about fdb operation
8696 static int i40e_ndo_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
8697 struct net_device
*dev
,
8698 const unsigned char *addr
, u16 vid
,
8701 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
8702 struct i40e_pf
*pf
= np
->vsi
->back
;
8705 if (!(pf
->flags
& I40E_FLAG_SRIOV_ENABLED
))
8709 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev
->name
);
8713 /* Hardware does not support aging addresses so if a
8714 * ndm_state is given only allow permanent addresses
8716 if (ndm
->ndm_state
&& !(ndm
->ndm_state
& NUD_PERMANENT
)) {
8717 netdev_info(dev
, "FDB only supports static addresses\n");
8721 if (is_unicast_ether_addr(addr
) || is_link_local_ether_addr(addr
))
8722 err
= dev_uc_add_excl(dev
, addr
);
8723 else if (is_multicast_ether_addr(addr
))
8724 err
= dev_mc_add_excl(dev
, addr
);
8728 /* Only return duplicate errors if NLM_F_EXCL is set */
8729 if (err
== -EEXIST
&& !(flags
& NLM_F_EXCL
))
8736 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
8737 * @dev: the netdev being configured
8738 * @nlh: RTNL message
8740 * Inserts a new hardware bridge if not already created and
8741 * enables the bridging mode requested (VEB or VEPA). If the
8742 * hardware bridge has already been inserted and the request
8743 * is to change the mode then that requires a PF reset to
8744 * allow rebuild of the components with required hardware
8745 * bridge mode enabled.
8747 static int i40e_ndo_bridge_setlink(struct net_device
*dev
,
8748 struct nlmsghdr
*nlh
,
8751 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
8752 struct i40e_vsi
*vsi
= np
->vsi
;
8753 struct i40e_pf
*pf
= vsi
->back
;
8754 struct i40e_veb
*veb
= NULL
;
8755 struct nlattr
*attr
, *br_spec
;
8758 /* Only for PF VSI for now */
8759 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
)
8762 /* Find the HW bridge for PF VSI */
8763 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
8764 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
8768 br_spec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
8770 nla_for_each_nested(attr
, br_spec
, rem
) {
8773 if (nla_type(attr
) != IFLA_BRIDGE_MODE
)
8776 mode
= nla_get_u16(attr
);
8777 if ((mode
!= BRIDGE_MODE_VEPA
) &&
8778 (mode
!= BRIDGE_MODE_VEB
))
8781 /* Insert a new HW bridge */
8783 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
8784 vsi
->tc_config
.enabled_tc
);
8786 veb
->bridge_mode
= mode
;
8787 i40e_config_bridge_mode(veb
);
8789 /* No Bridge HW offload available */
8793 } else if (mode
!= veb
->bridge_mode
) {
8794 /* Existing HW bridge but different mode needs reset */
8795 veb
->bridge_mode
= mode
;
8796 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
8797 if (mode
== BRIDGE_MODE_VEB
)
8798 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
8800 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
8801 i40e_do_reset(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
8810 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
8813 * @seq: RTNL message seq #
8814 * @dev: the netdev being configured
8815 * @filter_mask: unused
8816 * @nlflags: netlink flags passed in
8818 * Return the mode in which the hardware bridge is operating in
8821 static int i40e_ndo_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
8822 struct net_device
*dev
,
8823 u32 __always_unused filter_mask
,
8826 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
8827 struct i40e_vsi
*vsi
= np
->vsi
;
8828 struct i40e_pf
*pf
= vsi
->back
;
8829 struct i40e_veb
*veb
= NULL
;
8832 /* Only for PF VSI for now */
8833 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
)
8836 /* Find the HW bridge for the PF VSI */
8837 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
8838 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
8845 return ndo_dflt_bridge_getlink(skb
, pid
, seq
, dev
, veb
->bridge_mode
,
8846 nlflags
, 0, 0, filter_mask
, NULL
);
8849 /* Hardware supports L4 tunnel length of 128B (=2^7) which includes
8850 * inner mac plus all inner ethertypes.
8852 #define I40E_MAX_TUNNEL_HDR_LEN 128
8854 * i40e_features_check - Validate encapsulated packet conforms to limits
8856 * @dev: This physical port's netdev
8857 * @features: Offload features that the stack believes apply
8859 static netdev_features_t
i40e_features_check(struct sk_buff
*skb
,
8860 struct net_device
*dev
,
8861 netdev_features_t features
)
8863 if (skb
->encapsulation
&&
8864 ((skb_inner_network_header(skb
) - skb_transport_header(skb
)) >
8865 I40E_MAX_TUNNEL_HDR_LEN
))
8866 return features
& ~(NETIF_F_CSUM_MASK
| NETIF_F_GSO_MASK
);
8871 static const struct net_device_ops i40e_netdev_ops
= {
8872 .ndo_open
= i40e_open
,
8873 .ndo_stop
= i40e_close
,
8874 .ndo_start_xmit
= i40e_lan_xmit_frame
,
8875 .ndo_get_stats64
= i40e_get_netdev_stats_struct
,
8876 .ndo_set_rx_mode
= i40e_set_rx_mode
,
8877 .ndo_validate_addr
= eth_validate_addr
,
8878 .ndo_set_mac_address
= i40e_set_mac
,
8879 .ndo_change_mtu
= i40e_change_mtu
,
8880 .ndo_do_ioctl
= i40e_ioctl
,
8881 .ndo_tx_timeout
= i40e_tx_timeout
,
8882 .ndo_vlan_rx_add_vid
= i40e_vlan_rx_add_vid
,
8883 .ndo_vlan_rx_kill_vid
= i40e_vlan_rx_kill_vid
,
8884 #ifdef CONFIG_NET_POLL_CONTROLLER
8885 .ndo_poll_controller
= i40e_netpoll
,
8887 .ndo_setup_tc
= i40e_setup_tc
,
8889 .ndo_fcoe_enable
= i40e_fcoe_enable
,
8890 .ndo_fcoe_disable
= i40e_fcoe_disable
,
8892 .ndo_set_features
= i40e_set_features
,
8893 .ndo_set_vf_mac
= i40e_ndo_set_vf_mac
,
8894 .ndo_set_vf_vlan
= i40e_ndo_set_vf_port_vlan
,
8895 .ndo_set_vf_rate
= i40e_ndo_set_vf_bw
,
8896 .ndo_get_vf_config
= i40e_ndo_get_vf_config
,
8897 .ndo_set_vf_link_state
= i40e_ndo_set_vf_link_state
,
8898 .ndo_set_vf_spoofchk
= i40e_ndo_set_vf_spoofchk
,
8899 #if IS_ENABLED(CONFIG_VXLAN)
8900 .ndo_add_vxlan_port
= i40e_add_vxlan_port
,
8901 .ndo_del_vxlan_port
= i40e_del_vxlan_port
,
8903 #if IS_ENABLED(CONFIG_GENEVE)
8904 .ndo_add_geneve_port
= i40e_add_geneve_port
,
8905 .ndo_del_geneve_port
= i40e_del_geneve_port
,
8907 .ndo_get_phys_port_id
= i40e_get_phys_port_id
,
8908 .ndo_fdb_add
= i40e_ndo_fdb_add
,
8909 .ndo_features_check
= i40e_features_check
,
8910 .ndo_bridge_getlink
= i40e_ndo_bridge_getlink
,
8911 .ndo_bridge_setlink
= i40e_ndo_bridge_setlink
,
8915 * i40e_config_netdev - Setup the netdev flags
8916 * @vsi: the VSI being configured
8918 * Returns 0 on success, negative value on failure
8920 static int i40e_config_netdev(struct i40e_vsi
*vsi
)
8922 u8 brdcast
[ETH_ALEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
8923 struct i40e_pf
*pf
= vsi
->back
;
8924 struct i40e_hw
*hw
= &pf
->hw
;
8925 struct i40e_netdev_priv
*np
;
8926 struct net_device
*netdev
;
8927 u8 mac_addr
[ETH_ALEN
];
8930 etherdev_size
= sizeof(struct i40e_netdev_priv
);
8931 netdev
= alloc_etherdev_mq(etherdev_size
, vsi
->alloc_queue_pairs
);
8935 vsi
->netdev
= netdev
;
8936 np
= netdev_priv(netdev
);
8939 netdev
->hw_enc_features
|= NETIF_F_IP_CSUM
|
8941 NETIF_F_GSO_UDP_TUNNEL
|
8945 netdev
->features
= NETIF_F_SG
|
8949 NETIF_F_GSO_UDP_TUNNEL
|
8951 NETIF_F_HW_VLAN_CTAG_TX
|
8952 NETIF_F_HW_VLAN_CTAG_RX
|
8953 NETIF_F_HW_VLAN_CTAG_FILTER
|
8962 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
8963 netdev
->features
|= NETIF_F_NTUPLE
;
8965 /* copy netdev features into list of user selectable features */
8966 netdev
->hw_features
|= netdev
->features
;
8968 if (vsi
->type
== I40E_VSI_MAIN
) {
8969 SET_NETDEV_DEV(netdev
, &pf
->pdev
->dev
);
8970 ether_addr_copy(mac_addr
, hw
->mac
.perm_addr
);
8971 /* The following steps are necessary to prevent reception
8972 * of tagged packets - some older NVM configurations load a
8973 * default a MAC-VLAN filter that accepts any tagged packet
8974 * which must be replaced by a normal filter.
8976 if (!i40e_rm_default_mac_filter(vsi
, mac_addr
)) {
8977 spin_lock_bh(&vsi
->mac_filter_list_lock
);
8978 i40e_add_filter(vsi
, mac_addr
,
8979 I40E_VLAN_ANY
, false, true);
8980 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
8983 /* relate the VSI_VMDQ name to the VSI_MAIN name */
8984 snprintf(netdev
->name
, IFNAMSIZ
, "%sv%%d",
8985 pf
->vsi
[pf
->lan_vsi
]->netdev
->name
);
8986 random_ether_addr(mac_addr
);
8988 spin_lock_bh(&vsi
->mac_filter_list_lock
);
8989 i40e_add_filter(vsi
, mac_addr
, I40E_VLAN_ANY
, false, false);
8990 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
8993 spin_lock_bh(&vsi
->mac_filter_list_lock
);
8994 i40e_add_filter(vsi
, brdcast
, I40E_VLAN_ANY
, false, false);
8995 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
8997 ether_addr_copy(netdev
->dev_addr
, mac_addr
);
8998 ether_addr_copy(netdev
->perm_addr
, mac_addr
);
8999 /* vlan gets same features (except vlan offload)
9000 * after any tweaks for specific VSI types
9002 netdev
->vlan_features
= netdev
->features
& ~(NETIF_F_HW_VLAN_CTAG_TX
|
9003 NETIF_F_HW_VLAN_CTAG_RX
|
9004 NETIF_F_HW_VLAN_CTAG_FILTER
);
9005 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
9006 netdev
->priv_flags
|= IFF_SUPP_NOFCS
;
9007 /* Setup netdev TC information */
9008 i40e_vsi_config_netdev_tc(vsi
, vsi
->tc_config
.enabled_tc
);
9010 netdev
->netdev_ops
= &i40e_netdev_ops
;
9011 netdev
->watchdog_timeo
= 5 * HZ
;
9012 i40e_set_ethtool_ops(netdev
);
9014 i40e_fcoe_config_netdev(netdev
, vsi
);
9021 * i40e_vsi_delete - Delete a VSI from the switch
9022 * @vsi: the VSI being removed
9024 * Returns 0 on success, negative value on failure
9026 static void i40e_vsi_delete(struct i40e_vsi
*vsi
)
9028 /* remove default VSI is not allowed */
9029 if (vsi
== vsi
->back
->vsi
[vsi
->back
->lan_vsi
])
9032 i40e_aq_delete_element(&vsi
->back
->hw
, vsi
->seid
, NULL
);
9036 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
9037 * @vsi: the VSI being queried
9039 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
9041 int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi
*vsi
)
9043 struct i40e_veb
*veb
;
9044 struct i40e_pf
*pf
= vsi
->back
;
9046 /* Uplink is not a bridge so default to VEB */
9047 if (vsi
->veb_idx
== I40E_NO_VEB
)
9050 veb
= pf
->veb
[vsi
->veb_idx
];
9052 dev_info(&pf
->pdev
->dev
,
9053 "There is no veb associated with the bridge\n");
9057 /* Uplink is a bridge in VEPA mode */
9058 if (veb
->bridge_mode
& BRIDGE_MODE_VEPA
) {
9061 /* Uplink is a bridge in VEB mode */
9065 /* VEPA is now default bridge, so return 0 */
9070 * i40e_add_vsi - Add a VSI to the switch
9071 * @vsi: the VSI being configured
9073 * This initializes a VSI context depending on the VSI type to be added and
9074 * passes it down to the add_vsi aq command.
9076 static int i40e_add_vsi(struct i40e_vsi
*vsi
)
9079 u8 laa_macaddr
[ETH_ALEN
];
9080 bool found_laa_mac_filter
= false;
9081 struct i40e_pf
*pf
= vsi
->back
;
9082 struct i40e_hw
*hw
= &pf
->hw
;
9083 struct i40e_vsi_context ctxt
;
9084 struct i40e_mac_filter
*f
, *ftmp
;
9086 u8 enabled_tc
= 0x1; /* TC0 enabled */
9089 memset(&ctxt
, 0, sizeof(ctxt
));
9090 switch (vsi
->type
) {
9092 /* The PF's main VSI is already setup as part of the
9093 * device initialization, so we'll not bother with
9094 * the add_vsi call, but we will retrieve the current
9097 ctxt
.seid
= pf
->main_vsi_seid
;
9098 ctxt
.pf_num
= pf
->hw
.pf_id
;
9100 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
9101 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
9103 dev_info(&pf
->pdev
->dev
,
9104 "couldn't get PF vsi config, err %s aq_err %s\n",
9105 i40e_stat_str(&pf
->hw
, ret
),
9106 i40e_aq_str(&pf
->hw
,
9107 pf
->hw
.aq
.asq_last_status
));
9110 vsi
->info
= ctxt
.info
;
9111 vsi
->info
.valid_sections
= 0;
9113 vsi
->seid
= ctxt
.seid
;
9114 vsi
->id
= ctxt
.vsi_number
;
9116 enabled_tc
= i40e_pf_get_tc_map(pf
);
9118 /* MFP mode setup queue map and update VSI */
9119 if ((pf
->flags
& I40E_FLAG_MFP_ENABLED
) &&
9120 !(pf
->hw
.func_caps
.iscsi
)) { /* NIC type PF */
9121 memset(&ctxt
, 0, sizeof(ctxt
));
9122 ctxt
.seid
= pf
->main_vsi_seid
;
9123 ctxt
.pf_num
= pf
->hw
.pf_id
;
9125 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
9126 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
9128 dev_info(&pf
->pdev
->dev
,
9129 "update vsi failed, 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
));
9136 /* update the local VSI info queue map */
9137 i40e_vsi_update_queue_map(vsi
, &ctxt
);
9138 vsi
->info
.valid_sections
= 0;
9140 /* Default/Main VSI is only enabled for TC0
9141 * reconfigure it to enable all TCs that are
9142 * available on the port in SFP mode.
9143 * For MFP case the iSCSI PF would use this
9144 * flow to enable LAN+iSCSI TC.
9146 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
9148 dev_info(&pf
->pdev
->dev
,
9149 "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
9151 i40e_stat_str(&pf
->hw
, ret
),
9152 i40e_aq_str(&pf
->hw
,
9153 pf
->hw
.aq
.asq_last_status
));
9160 ctxt
.pf_num
= hw
->pf_id
;
9162 ctxt
.uplink_seid
= vsi
->uplink_seid
;
9163 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
9164 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
9165 if ((pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
) &&
9166 (i40e_is_vsi_uplink_mode_veb(vsi
))) {
9167 ctxt
.info
.valid_sections
|=
9168 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
9169 ctxt
.info
.switch_id
=
9170 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
9172 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
9175 case I40E_VSI_VMDQ2
:
9176 ctxt
.pf_num
= hw
->pf_id
;
9178 ctxt
.uplink_seid
= vsi
->uplink_seid
;
9179 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
9180 ctxt
.flags
= I40E_AQ_VSI_TYPE_VMDQ2
;
9182 /* This VSI is connected to VEB so the switch_id
9183 * should be set to zero by default.
9185 if (i40e_is_vsi_uplink_mode_veb(vsi
)) {
9186 ctxt
.info
.valid_sections
|=
9187 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
9188 ctxt
.info
.switch_id
=
9189 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
9192 /* Setup the VSI tx/rx queue map for TC0 only for now */
9193 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
9196 case I40E_VSI_SRIOV
:
9197 ctxt
.pf_num
= hw
->pf_id
;
9198 ctxt
.vf_num
= vsi
->vf_id
+ hw
->func_caps
.vf_base_id
;
9199 ctxt
.uplink_seid
= vsi
->uplink_seid
;
9200 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
9201 ctxt
.flags
= I40E_AQ_VSI_TYPE_VF
;
9203 /* This VSI is connected to VEB so the switch_id
9204 * should be set to zero by default.
9206 if (i40e_is_vsi_uplink_mode_veb(vsi
)) {
9207 ctxt
.info
.valid_sections
|=
9208 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
9209 ctxt
.info
.switch_id
=
9210 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
9213 ctxt
.info
.valid_sections
|= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
9214 ctxt
.info
.port_vlan_flags
|= I40E_AQ_VSI_PVLAN_MODE_ALL
;
9215 if (pf
->vf
[vsi
->vf_id
].spoofchk
) {
9216 ctxt
.info
.valid_sections
|=
9217 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID
);
9218 ctxt
.info
.sec_flags
|=
9219 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK
|
9220 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK
);
9222 /* Setup the VSI tx/rx queue map for TC0 only for now */
9223 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
9228 ret
= i40e_fcoe_vsi_init(vsi
, &ctxt
);
9230 dev_info(&pf
->pdev
->dev
, "failed to initialize FCoE VSI\n");
9235 #endif /* I40E_FCOE */
9240 if (vsi
->type
!= I40E_VSI_MAIN
) {
9241 ret
= i40e_aq_add_vsi(hw
, &ctxt
, NULL
);
9243 dev_info(&vsi
->back
->pdev
->dev
,
9244 "add vsi failed, err %s aq_err %s\n",
9245 i40e_stat_str(&pf
->hw
, ret
),
9246 i40e_aq_str(&pf
->hw
,
9247 pf
->hw
.aq
.asq_last_status
));
9251 vsi
->info
= ctxt
.info
;
9252 vsi
->info
.valid_sections
= 0;
9253 vsi
->seid
= ctxt
.seid
;
9254 vsi
->id
= ctxt
.vsi_number
;
9257 spin_lock_bh(&vsi
->mac_filter_list_lock
);
9258 /* If macvlan filters already exist, force them to get loaded */
9259 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
9263 /* Expected to have only one MAC filter entry for LAA in list */
9264 if (f
->is_laa
&& vsi
->type
== I40E_VSI_MAIN
) {
9265 ether_addr_copy(laa_macaddr
, f
->macaddr
);
9266 found_laa_mac_filter
= true;
9269 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
9271 if (found_laa_mac_filter
) {
9272 struct i40e_aqc_remove_macvlan_element_data element
;
9274 memset(&element
, 0, sizeof(element
));
9275 ether_addr_copy(element
.mac_addr
, laa_macaddr
);
9276 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
9277 ret
= i40e_aq_remove_macvlan(hw
, vsi
->seid
,
9280 /* some older FW has a different default */
9282 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
9283 i40e_aq_remove_macvlan(hw
, vsi
->seid
,
9287 i40e_aq_mac_address_write(hw
,
9288 I40E_AQC_WRITE_TYPE_LAA_WOL
,
9293 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
9294 pf
->flags
|= I40E_FLAG_FILTER_SYNC
;
9297 /* Update VSI BW information */
9298 ret
= i40e_vsi_get_bw_info(vsi
);
9300 dev_info(&pf
->pdev
->dev
,
9301 "couldn't get vsi bw info, err %s aq_err %s\n",
9302 i40e_stat_str(&pf
->hw
, ret
),
9303 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9304 /* VSI is already added so not tearing that up */
9313 * i40e_vsi_release - Delete a VSI and free its resources
9314 * @vsi: the VSI being removed
9316 * Returns 0 on success or < 0 on error
9318 int i40e_vsi_release(struct i40e_vsi
*vsi
)
9320 struct i40e_mac_filter
*f
, *ftmp
;
9321 struct i40e_veb
*veb
= NULL
;
9328 /* release of a VEB-owner or last VSI is not allowed */
9329 if (vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
9330 dev_info(&pf
->pdev
->dev
, "VSI %d has existing VEB %d\n",
9331 vsi
->seid
, vsi
->uplink_seid
);
9334 if (vsi
== pf
->vsi
[pf
->lan_vsi
] &&
9335 !test_bit(__I40E_DOWN
, &pf
->state
)) {
9336 dev_info(&pf
->pdev
->dev
, "Can't remove PF VSI\n");
9340 uplink_seid
= vsi
->uplink_seid
;
9341 if (vsi
->type
!= I40E_VSI_SRIOV
) {
9342 if (vsi
->netdev_registered
) {
9343 vsi
->netdev_registered
= false;
9345 /* results in a call to i40e_close() */
9346 unregister_netdev(vsi
->netdev
);
9349 i40e_vsi_close(vsi
);
9351 i40e_vsi_disable_irq(vsi
);
9354 spin_lock_bh(&vsi
->mac_filter_list_lock
);
9355 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
)
9356 i40e_del_filter(vsi
, f
->macaddr
, f
->vlan
,
9357 f
->is_vf
, f
->is_netdev
);
9358 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
9360 i40e_sync_vsi_filters(vsi
);
9362 i40e_vsi_delete(vsi
);
9363 i40e_vsi_free_q_vectors(vsi
);
9365 free_netdev(vsi
->netdev
);
9368 i40e_vsi_clear_rings(vsi
);
9369 i40e_vsi_clear(vsi
);
9371 /* If this was the last thing on the VEB, except for the
9372 * controlling VSI, remove the VEB, which puts the controlling
9373 * VSI onto the next level down in the switch.
9375 * Well, okay, there's one more exception here: don't remove
9376 * the orphan VEBs yet. We'll wait for an explicit remove request
9377 * from up the network stack.
9379 for (n
= 0, i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9381 pf
->vsi
[i
]->uplink_seid
== uplink_seid
&&
9382 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
9383 n
++; /* count the VSIs */
9386 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
9389 if (pf
->veb
[i
]->uplink_seid
== uplink_seid
)
9390 n
++; /* count the VEBs */
9391 if (pf
->veb
[i
]->seid
== uplink_seid
)
9394 if (n
== 0 && veb
&& veb
->uplink_seid
!= 0)
9395 i40e_veb_release(veb
);
9401 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
9402 * @vsi: ptr to the VSI
9404 * This should only be called after i40e_vsi_mem_alloc() which allocates the
9405 * corresponding SW VSI structure and initializes num_queue_pairs for the
9406 * newly allocated VSI.
9408 * Returns 0 on success or negative on failure
9410 static int i40e_vsi_setup_vectors(struct i40e_vsi
*vsi
)
9413 struct i40e_pf
*pf
= vsi
->back
;
9415 if (vsi
->q_vectors
[0]) {
9416 dev_info(&pf
->pdev
->dev
, "VSI %d has existing q_vectors\n",
9421 if (vsi
->base_vector
) {
9422 dev_info(&pf
->pdev
->dev
, "VSI %d has non-zero base vector %d\n",
9423 vsi
->seid
, vsi
->base_vector
);
9427 ret
= i40e_vsi_alloc_q_vectors(vsi
);
9429 dev_info(&pf
->pdev
->dev
,
9430 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
9431 vsi
->num_q_vectors
, vsi
->seid
, ret
);
9432 vsi
->num_q_vectors
= 0;
9433 goto vector_setup_out
;
9436 /* In Legacy mode, we do not have to get any other vector since we
9437 * piggyback on the misc/ICR0 for queue interrupts.
9439 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
9441 if (vsi
->num_q_vectors
)
9442 vsi
->base_vector
= i40e_get_lump(pf
, pf
->irq_pile
,
9443 vsi
->num_q_vectors
, vsi
->idx
);
9444 if (vsi
->base_vector
< 0) {
9445 dev_info(&pf
->pdev
->dev
,
9446 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
9447 vsi
->num_q_vectors
, vsi
->seid
, vsi
->base_vector
);
9448 i40e_vsi_free_q_vectors(vsi
);
9450 goto vector_setup_out
;
9458 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
9459 * @vsi: pointer to the vsi.
9461 * This re-allocates a vsi's queue resources.
9463 * Returns pointer to the successfully allocated and configured VSI sw struct
9464 * on success, otherwise returns NULL on failure.
9466 static struct i40e_vsi
*i40e_vsi_reinit_setup(struct i40e_vsi
*vsi
)
9468 struct i40e_pf
*pf
= vsi
->back
;
9472 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
9473 i40e_vsi_clear_rings(vsi
);
9475 i40e_vsi_free_arrays(vsi
, false);
9476 i40e_set_num_rings_in_vsi(vsi
);
9477 ret
= i40e_vsi_alloc_arrays(vsi
, false);
9481 ret
= i40e_get_lump(pf
, pf
->qp_pile
, vsi
->alloc_queue_pairs
, vsi
->idx
);
9483 dev_info(&pf
->pdev
->dev
,
9484 "failed to get tracking for %d queues for VSI %d err %d\n",
9485 vsi
->alloc_queue_pairs
, vsi
->seid
, ret
);
9488 vsi
->base_queue
= ret
;
9490 /* Update the FW view of the VSI. Force a reset of TC and queue
9491 * layout configurations.
9493 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
9494 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
9495 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
9496 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
9498 /* assign it some queues */
9499 ret
= i40e_alloc_rings(vsi
);
9503 /* map all of the rings to the q_vectors */
9504 i40e_vsi_map_rings_to_vectors(vsi
);
9508 i40e_vsi_free_q_vectors(vsi
);
9509 if (vsi
->netdev_registered
) {
9510 vsi
->netdev_registered
= false;
9511 unregister_netdev(vsi
->netdev
);
9512 free_netdev(vsi
->netdev
);
9515 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
9517 i40e_vsi_clear(vsi
);
9522 * i40e_vsi_setup - Set up a VSI by a given type
9523 * @pf: board private structure
9525 * @uplink_seid: the switch element to link to
9526 * @param1: usage depends upon VSI type. For VF types, indicates VF id
9528 * This allocates the sw VSI structure and its queue resources, then add a VSI
9529 * to the identified VEB.
9531 * Returns pointer to the successfully allocated and configure VSI sw struct on
9532 * success, otherwise returns NULL on failure.
9534 struct i40e_vsi
*i40e_vsi_setup(struct i40e_pf
*pf
, u8 type
,
9535 u16 uplink_seid
, u32 param1
)
9537 struct i40e_vsi
*vsi
= NULL
;
9538 struct i40e_veb
*veb
= NULL
;
9542 /* The requested uplink_seid must be either
9543 * - the PF's port seid
9544 * no VEB is needed because this is the PF
9545 * or this is a Flow Director special case VSI
9546 * - seid of an existing VEB
9547 * - seid of a VSI that owns an existing VEB
9548 * - seid of a VSI that doesn't own a VEB
9549 * a new VEB is created and the VSI becomes the owner
9550 * - seid of the PF VSI, which is what creates the first VEB
9551 * this is a special case of the previous
9553 * Find which uplink_seid we were given and create a new VEB if needed
9555 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
9556 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== uplink_seid
) {
9562 if (!veb
&& uplink_seid
!= pf
->mac_seid
) {
9564 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9565 if (pf
->vsi
[i
] && pf
->vsi
[i
]->seid
== uplink_seid
) {
9571 dev_info(&pf
->pdev
->dev
, "no such uplink_seid %d\n",
9576 if (vsi
->uplink_seid
== pf
->mac_seid
)
9577 veb
= i40e_veb_setup(pf
, 0, pf
->mac_seid
, vsi
->seid
,
9578 vsi
->tc_config
.enabled_tc
);
9579 else if ((vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0)
9580 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
9581 vsi
->tc_config
.enabled_tc
);
9583 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
) {
9584 dev_info(&vsi
->back
->pdev
->dev
,
9585 "New VSI creation error, uplink seid of LAN VSI expected.\n");
9588 /* We come up by default in VEPA mode if SRIOV is not
9589 * already enabled, in which case we can't force VEPA
9592 if (!(pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)) {
9593 veb
->bridge_mode
= BRIDGE_MODE_VEPA
;
9594 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
9596 i40e_config_bridge_mode(veb
);
9598 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
9599 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
9603 dev_info(&pf
->pdev
->dev
, "couldn't add VEB\n");
9607 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
9608 uplink_seid
= veb
->seid
;
9611 /* get vsi sw struct */
9612 v_idx
= i40e_vsi_mem_alloc(pf
, type
);
9615 vsi
= pf
->vsi
[v_idx
];
9619 vsi
->veb_idx
= (veb
? veb
->idx
: I40E_NO_VEB
);
9621 if (type
== I40E_VSI_MAIN
)
9622 pf
->lan_vsi
= v_idx
;
9623 else if (type
== I40E_VSI_SRIOV
)
9624 vsi
->vf_id
= param1
;
9625 /* assign it some queues */
9626 ret
= i40e_get_lump(pf
, pf
->qp_pile
, vsi
->alloc_queue_pairs
,
9629 dev_info(&pf
->pdev
->dev
,
9630 "failed to get tracking for %d queues for VSI %d err=%d\n",
9631 vsi
->alloc_queue_pairs
, vsi
->seid
, ret
);
9634 vsi
->base_queue
= ret
;
9636 /* get a VSI from the hardware */
9637 vsi
->uplink_seid
= uplink_seid
;
9638 ret
= i40e_add_vsi(vsi
);
9642 switch (vsi
->type
) {
9643 /* setup the netdev if needed */
9645 case I40E_VSI_VMDQ2
:
9647 ret
= i40e_config_netdev(vsi
);
9650 ret
= register_netdev(vsi
->netdev
);
9653 vsi
->netdev_registered
= true;
9654 netif_carrier_off(vsi
->netdev
);
9655 #ifdef CONFIG_I40E_DCB
9656 /* Setup DCB netlink interface */
9657 i40e_dcbnl_setup(vsi
);
9658 #endif /* CONFIG_I40E_DCB */
9662 /* set up vectors and rings if needed */
9663 ret
= i40e_vsi_setup_vectors(vsi
);
9667 ret
= i40e_alloc_rings(vsi
);
9671 /* map all of the rings to the q_vectors */
9672 i40e_vsi_map_rings_to_vectors(vsi
);
9674 i40e_vsi_reset_stats(vsi
);
9678 /* no netdev or rings for the other VSI types */
9682 if ((pf
->flags
& I40E_FLAG_RSS_AQ_CAPABLE
) &&
9683 (vsi
->type
== I40E_VSI_VMDQ2
)) {
9684 ret
= i40e_vsi_config_rss(vsi
);
9689 i40e_vsi_free_q_vectors(vsi
);
9691 if (vsi
->netdev_registered
) {
9692 vsi
->netdev_registered
= false;
9693 unregister_netdev(vsi
->netdev
);
9694 free_netdev(vsi
->netdev
);
9698 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
9700 i40e_vsi_clear(vsi
);
9706 * i40e_veb_get_bw_info - Query VEB BW information
9707 * @veb: the veb to query
9709 * Query the Tx scheduler BW configuration data for given VEB
9711 static int i40e_veb_get_bw_info(struct i40e_veb
*veb
)
9713 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data
;
9714 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data
;
9715 struct i40e_pf
*pf
= veb
->pf
;
9716 struct i40e_hw
*hw
= &pf
->hw
;
9721 ret
= i40e_aq_query_switch_comp_bw_config(hw
, veb
->seid
,
9724 dev_info(&pf
->pdev
->dev
,
9725 "query veb bw config failed, err %s aq_err %s\n",
9726 i40e_stat_str(&pf
->hw
, ret
),
9727 i40e_aq_str(&pf
->hw
, hw
->aq
.asq_last_status
));
9731 ret
= i40e_aq_query_switch_comp_ets_config(hw
, veb
->seid
,
9734 dev_info(&pf
->pdev
->dev
,
9735 "query veb bw ets config failed, err %s aq_err %s\n",
9736 i40e_stat_str(&pf
->hw
, ret
),
9737 i40e_aq_str(&pf
->hw
, hw
->aq
.asq_last_status
));
9741 veb
->bw_limit
= le16_to_cpu(ets_data
.port_bw_limit
);
9742 veb
->bw_max_quanta
= ets_data
.tc_bw_max
;
9743 veb
->is_abs_credits
= bw_data
.absolute_credits_enable
;
9744 veb
->enabled_tc
= ets_data
.tc_valid_bits
;
9745 tc_bw_max
= le16_to_cpu(bw_data
.tc_bw_max
[0]) |
9746 (le16_to_cpu(bw_data
.tc_bw_max
[1]) << 16);
9747 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
9748 veb
->bw_tc_share_credits
[i
] = bw_data
.tc_bw_share_credits
[i
];
9749 veb
->bw_tc_limit_credits
[i
] =
9750 le16_to_cpu(bw_data
.tc_bw_limits
[i
]);
9751 veb
->bw_tc_max_quanta
[i
] = ((tc_bw_max
>> (i
*4)) & 0x7);
9759 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
9760 * @pf: board private structure
9762 * On error: returns error code (negative)
9763 * On success: returns vsi index in PF (positive)
9765 static int i40e_veb_mem_alloc(struct i40e_pf
*pf
)
9768 struct i40e_veb
*veb
;
9771 /* Need to protect the allocation of switch elements at the PF level */
9772 mutex_lock(&pf
->switch_mutex
);
9774 /* VEB list may be fragmented if VEB creation/destruction has
9775 * been happening. We can afford to do a quick scan to look
9776 * for any free slots in the list.
9778 * find next empty veb slot, looping back around if necessary
9781 while ((i
< I40E_MAX_VEB
) && (pf
->veb
[i
] != NULL
))
9783 if (i
>= I40E_MAX_VEB
) {
9785 goto err_alloc_veb
; /* out of VEB slots! */
9788 veb
= kzalloc(sizeof(*veb
), GFP_KERNEL
);
9795 veb
->enabled_tc
= 1;
9800 mutex_unlock(&pf
->switch_mutex
);
9805 * i40e_switch_branch_release - Delete a branch of the switch tree
9806 * @branch: where to start deleting
9808 * This uses recursion to find the tips of the branch to be
9809 * removed, deleting until we get back to and can delete this VEB.
9811 static void i40e_switch_branch_release(struct i40e_veb
*branch
)
9813 struct i40e_pf
*pf
= branch
->pf
;
9814 u16 branch_seid
= branch
->seid
;
9815 u16 veb_idx
= branch
->idx
;
9818 /* release any VEBs on this VEB - RECURSION */
9819 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
9822 if (pf
->veb
[i
]->uplink_seid
== branch
->seid
)
9823 i40e_switch_branch_release(pf
->veb
[i
]);
9826 /* Release the VSIs on this VEB, but not the owner VSI.
9828 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
9829 * the VEB itself, so don't use (*branch) after this loop.
9831 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9834 if (pf
->vsi
[i
]->uplink_seid
== branch_seid
&&
9835 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
9836 i40e_vsi_release(pf
->vsi
[i
]);
9840 /* There's one corner case where the VEB might not have been
9841 * removed, so double check it here and remove it if needed.
9842 * This case happens if the veb was created from the debugfs
9843 * commands and no VSIs were added to it.
9845 if (pf
->veb
[veb_idx
])
9846 i40e_veb_release(pf
->veb
[veb_idx
]);
9850 * i40e_veb_clear - remove veb struct
9851 * @veb: the veb to remove
9853 static void i40e_veb_clear(struct i40e_veb
*veb
)
9859 struct i40e_pf
*pf
= veb
->pf
;
9861 mutex_lock(&pf
->switch_mutex
);
9862 if (pf
->veb
[veb
->idx
] == veb
)
9863 pf
->veb
[veb
->idx
] = NULL
;
9864 mutex_unlock(&pf
->switch_mutex
);
9871 * i40e_veb_release - Delete a VEB and free its resources
9872 * @veb: the VEB being removed
9874 void i40e_veb_release(struct i40e_veb
*veb
)
9876 struct i40e_vsi
*vsi
= NULL
;
9882 /* find the remaining VSI and check for extras */
9883 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9884 if (pf
->vsi
[i
] && pf
->vsi
[i
]->uplink_seid
== veb
->seid
) {
9890 dev_info(&pf
->pdev
->dev
,
9891 "can't remove VEB %d with %d VSIs left\n",
9896 /* move the remaining VSI to uplink veb */
9897 vsi
->flags
&= ~I40E_VSI_FLAG_VEB_OWNER
;
9898 if (veb
->uplink_seid
) {
9899 vsi
->uplink_seid
= veb
->uplink_seid
;
9900 if (veb
->uplink_seid
== pf
->mac_seid
)
9901 vsi
->veb_idx
= I40E_NO_VEB
;
9903 vsi
->veb_idx
= veb
->veb_idx
;
9906 vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
9907 vsi
->veb_idx
= pf
->vsi
[pf
->lan_vsi
]->veb_idx
;
9910 i40e_aq_delete_element(&pf
->hw
, veb
->seid
, NULL
);
9911 i40e_veb_clear(veb
);
9915 * i40e_add_veb - create the VEB in the switch
9916 * @veb: the VEB to be instantiated
9917 * @vsi: the controlling VSI
9919 static int i40e_add_veb(struct i40e_veb
*veb
, struct i40e_vsi
*vsi
)
9921 struct i40e_pf
*pf
= veb
->pf
;
9922 bool is_default
= veb
->pf
->cur_promisc
;
9923 bool is_cloud
= false;
9926 /* get a VEB from the hardware */
9927 ret
= i40e_aq_add_veb(&pf
->hw
, veb
->uplink_seid
, vsi
->seid
,
9928 veb
->enabled_tc
, is_default
,
9929 is_cloud
, &veb
->seid
, NULL
);
9931 dev_info(&pf
->pdev
->dev
,
9932 "couldn't add VEB, err %s aq_err %s\n",
9933 i40e_stat_str(&pf
->hw
, ret
),
9934 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9938 /* get statistics counter */
9939 ret
= i40e_aq_get_veb_parameters(&pf
->hw
, veb
->seid
, NULL
, NULL
,
9940 &veb
->stats_idx
, NULL
, NULL
, NULL
);
9942 dev_info(&pf
->pdev
->dev
,
9943 "couldn't get VEB statistics idx, err %s aq_err %s\n",
9944 i40e_stat_str(&pf
->hw
, ret
),
9945 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9948 ret
= i40e_veb_get_bw_info(veb
);
9950 dev_info(&pf
->pdev
->dev
,
9951 "couldn't get VEB bw info, err %s aq_err %s\n",
9952 i40e_stat_str(&pf
->hw
, ret
),
9953 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9954 i40e_aq_delete_element(&pf
->hw
, veb
->seid
, NULL
);
9958 vsi
->uplink_seid
= veb
->seid
;
9959 vsi
->veb_idx
= veb
->idx
;
9960 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
9966 * i40e_veb_setup - Set up a VEB
9967 * @pf: board private structure
9968 * @flags: VEB setup flags
9969 * @uplink_seid: the switch element to link to
9970 * @vsi_seid: the initial VSI seid
9971 * @enabled_tc: Enabled TC bit-map
9973 * This allocates the sw VEB structure and links it into the switch
9974 * It is possible and legal for this to be a duplicate of an already
9975 * existing VEB. It is also possible for both uplink and vsi seids
9976 * to be zero, in order to create a floating VEB.
9978 * Returns pointer to the successfully allocated VEB sw struct on
9979 * success, otherwise returns NULL on failure.
9981 struct i40e_veb
*i40e_veb_setup(struct i40e_pf
*pf
, u16 flags
,
9982 u16 uplink_seid
, u16 vsi_seid
,
9985 struct i40e_veb
*veb
, *uplink_veb
= NULL
;
9986 int vsi_idx
, veb_idx
;
9989 /* if one seid is 0, the other must be 0 to create a floating relay */
9990 if ((uplink_seid
== 0 || vsi_seid
== 0) &&
9991 (uplink_seid
+ vsi_seid
!= 0)) {
9992 dev_info(&pf
->pdev
->dev
,
9993 "one, not both seid's are 0: uplink=%d vsi=%d\n",
9994 uplink_seid
, vsi_seid
);
9998 /* make sure there is such a vsi and uplink */
9999 for (vsi_idx
= 0; vsi_idx
< pf
->num_alloc_vsi
; vsi_idx
++)
10000 if (pf
->vsi
[vsi_idx
] && pf
->vsi
[vsi_idx
]->seid
== vsi_seid
)
10002 if (vsi_idx
>= pf
->num_alloc_vsi
&& vsi_seid
!= 0) {
10003 dev_info(&pf
->pdev
->dev
, "vsi seid %d not found\n",
10008 if (uplink_seid
&& uplink_seid
!= pf
->mac_seid
) {
10009 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
10010 if (pf
->veb
[veb_idx
] &&
10011 pf
->veb
[veb_idx
]->seid
== uplink_seid
) {
10012 uplink_veb
= pf
->veb
[veb_idx
];
10017 dev_info(&pf
->pdev
->dev
,
10018 "uplink seid %d not found\n", uplink_seid
);
10023 /* get veb sw struct */
10024 veb_idx
= i40e_veb_mem_alloc(pf
);
10027 veb
= pf
->veb
[veb_idx
];
10028 veb
->flags
= flags
;
10029 veb
->uplink_seid
= uplink_seid
;
10030 veb
->veb_idx
= (uplink_veb
? uplink_veb
->idx
: I40E_NO_VEB
);
10031 veb
->enabled_tc
= (enabled_tc
? enabled_tc
: 0x1);
10033 /* create the VEB in the switch */
10034 ret
= i40e_add_veb(veb
, pf
->vsi
[vsi_idx
]);
10037 if (vsi_idx
== pf
->lan_vsi
)
10038 pf
->lan_veb
= veb
->idx
;
10043 i40e_veb_clear(veb
);
10049 * i40e_setup_pf_switch_element - set PF vars based on switch type
10050 * @pf: board private structure
10051 * @ele: element we are building info from
10052 * @num_reported: total number of elements
10053 * @printconfig: should we print the contents
10055 * helper function to assist in extracting a few useful SEID values.
10057 static void i40e_setup_pf_switch_element(struct i40e_pf
*pf
,
10058 struct i40e_aqc_switch_config_element_resp
*ele
,
10059 u16 num_reported
, bool printconfig
)
10061 u16 downlink_seid
= le16_to_cpu(ele
->downlink_seid
);
10062 u16 uplink_seid
= le16_to_cpu(ele
->uplink_seid
);
10063 u8 element_type
= ele
->element_type
;
10064 u16 seid
= le16_to_cpu(ele
->seid
);
10067 dev_info(&pf
->pdev
->dev
,
10068 "type=%d seid=%d uplink=%d downlink=%d\n",
10069 element_type
, seid
, uplink_seid
, downlink_seid
);
10071 switch (element_type
) {
10072 case I40E_SWITCH_ELEMENT_TYPE_MAC
:
10073 pf
->mac_seid
= seid
;
10075 case I40E_SWITCH_ELEMENT_TYPE_VEB
:
10077 if (uplink_seid
!= pf
->mac_seid
)
10079 if (pf
->lan_veb
== I40E_NO_VEB
) {
10082 /* find existing or else empty VEB */
10083 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
10084 if (pf
->veb
[v
] && (pf
->veb
[v
]->seid
== seid
)) {
10089 if (pf
->lan_veb
== I40E_NO_VEB
) {
10090 v
= i40e_veb_mem_alloc(pf
);
10097 pf
->veb
[pf
->lan_veb
]->seid
= seid
;
10098 pf
->veb
[pf
->lan_veb
]->uplink_seid
= pf
->mac_seid
;
10099 pf
->veb
[pf
->lan_veb
]->pf
= pf
;
10100 pf
->veb
[pf
->lan_veb
]->veb_idx
= I40E_NO_VEB
;
10102 case I40E_SWITCH_ELEMENT_TYPE_VSI
:
10103 if (num_reported
!= 1)
10105 /* This is immediately after a reset so we can assume this is
10108 pf
->mac_seid
= uplink_seid
;
10109 pf
->pf_seid
= downlink_seid
;
10110 pf
->main_vsi_seid
= seid
;
10112 dev_info(&pf
->pdev
->dev
,
10113 "pf_seid=%d main_vsi_seid=%d\n",
10114 pf
->pf_seid
, pf
->main_vsi_seid
);
10116 case I40E_SWITCH_ELEMENT_TYPE_PF
:
10117 case I40E_SWITCH_ELEMENT_TYPE_VF
:
10118 case I40E_SWITCH_ELEMENT_TYPE_EMP
:
10119 case I40E_SWITCH_ELEMENT_TYPE_BMC
:
10120 case I40E_SWITCH_ELEMENT_TYPE_PE
:
10121 case I40E_SWITCH_ELEMENT_TYPE_PA
:
10122 /* ignore these for now */
10125 dev_info(&pf
->pdev
->dev
, "unknown element type=%d seid=%d\n",
10126 element_type
, seid
);
10132 * i40e_fetch_switch_configuration - Get switch config from firmware
10133 * @pf: board private structure
10134 * @printconfig: should we print the contents
10136 * Get the current switch configuration from the device and
10137 * extract a few useful SEID values.
10139 int i40e_fetch_switch_configuration(struct i40e_pf
*pf
, bool printconfig
)
10141 struct i40e_aqc_get_switch_config_resp
*sw_config
;
10147 aq_buf
= kzalloc(I40E_AQ_LARGE_BUF
, GFP_KERNEL
);
10151 sw_config
= (struct i40e_aqc_get_switch_config_resp
*)aq_buf
;
10153 u16 num_reported
, num_total
;
10155 ret
= i40e_aq_get_switch_config(&pf
->hw
, sw_config
,
10159 dev_info(&pf
->pdev
->dev
,
10160 "get switch config failed err %s aq_err %s\n",
10161 i40e_stat_str(&pf
->hw
, ret
),
10162 i40e_aq_str(&pf
->hw
,
10163 pf
->hw
.aq
.asq_last_status
));
10168 num_reported
= le16_to_cpu(sw_config
->header
.num_reported
);
10169 num_total
= le16_to_cpu(sw_config
->header
.num_total
);
10172 dev_info(&pf
->pdev
->dev
,
10173 "header: %d reported %d total\n",
10174 num_reported
, num_total
);
10176 for (i
= 0; i
< num_reported
; i
++) {
10177 struct i40e_aqc_switch_config_element_resp
*ele
=
10178 &sw_config
->element
[i
];
10180 i40e_setup_pf_switch_element(pf
, ele
, num_reported
,
10183 } while (next_seid
!= 0);
10190 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
10191 * @pf: board private structure
10192 * @reinit: if the Main VSI needs to re-initialized.
10194 * Returns 0 on success, negative value on failure
10196 static int i40e_setup_pf_switch(struct i40e_pf
*pf
, bool reinit
)
10200 /* find out what's out there already */
10201 ret
= i40e_fetch_switch_configuration(pf
, false);
10203 dev_info(&pf
->pdev
->dev
,
10204 "couldn't fetch switch config, err %s aq_err %s\n",
10205 i40e_stat_str(&pf
->hw
, ret
),
10206 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10209 i40e_pf_reset_stats(pf
);
10211 /* first time setup */
10212 if (pf
->lan_vsi
== I40E_NO_VSI
|| reinit
) {
10213 struct i40e_vsi
*vsi
= NULL
;
10216 /* Set up the PF VSI associated with the PF's main VSI
10217 * that is already in the HW switch
10219 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
10220 uplink_seid
= pf
->veb
[pf
->lan_veb
]->seid
;
10222 uplink_seid
= pf
->mac_seid
;
10223 if (pf
->lan_vsi
== I40E_NO_VSI
)
10224 vsi
= i40e_vsi_setup(pf
, I40E_VSI_MAIN
, uplink_seid
, 0);
10226 vsi
= i40e_vsi_reinit_setup(pf
->vsi
[pf
->lan_vsi
]);
10228 dev_info(&pf
->pdev
->dev
, "setup of MAIN VSI failed\n");
10229 i40e_fdir_teardown(pf
);
10233 /* force a reset of TC and queue layout configurations */
10234 u8 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
10236 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
10237 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
10238 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
10240 i40e_vlan_stripping_disable(pf
->vsi
[pf
->lan_vsi
]);
10242 i40e_fdir_sb_setup(pf
);
10244 /* Setup static PF queue filter control settings */
10245 ret
= i40e_setup_pf_filter_control(pf
);
10247 dev_info(&pf
->pdev
->dev
, "setup_pf_filter_control failed: %d\n",
10249 /* Failure here should not stop continuing other steps */
10252 /* enable RSS in the HW, even for only one queue, as the stack can use
10255 if ((pf
->flags
& I40E_FLAG_RSS_ENABLED
))
10256 i40e_pf_config_rss(pf
);
10258 /* fill in link information and enable LSE reporting */
10259 i40e_update_link_info(&pf
->hw
);
10260 i40e_link_event(pf
);
10262 /* Initialize user-specific link properties */
10263 pf
->fc_autoneg_status
= ((pf
->hw
.phy
.link_info
.an_info
&
10264 I40E_AQ_AN_COMPLETED
) ? true : false);
10272 * i40e_determine_queue_usage - Work out queue distribution
10273 * @pf: board private structure
10275 static void i40e_determine_queue_usage(struct i40e_pf
*pf
)
10279 pf
->num_lan_qps
= 0;
10281 pf
->num_fcoe_qps
= 0;
10284 /* Find the max queues to be put into basic use. We'll always be
10285 * using TC0, whether or not DCB is running, and TC0 will get the
10288 queues_left
= pf
->hw
.func_caps
.num_tx_qp
;
10290 if ((queues_left
== 1) ||
10291 !(pf
->flags
& I40E_FLAG_MSIX_ENABLED
)) {
10292 /* one qp for PF, no queues for anything else */
10294 pf
->alloc_rss_size
= pf
->num_lan_qps
= 1;
10296 /* make sure all the fancies are disabled */
10297 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
10299 I40E_FLAG_FCOE_ENABLED
|
10301 I40E_FLAG_FD_SB_ENABLED
|
10302 I40E_FLAG_FD_ATR_ENABLED
|
10303 I40E_FLAG_DCB_CAPABLE
|
10304 I40E_FLAG_SRIOV_ENABLED
|
10305 I40E_FLAG_VMDQ_ENABLED
);
10306 } else if (!(pf
->flags
& (I40E_FLAG_RSS_ENABLED
|
10307 I40E_FLAG_FD_SB_ENABLED
|
10308 I40E_FLAG_FD_ATR_ENABLED
|
10309 I40E_FLAG_DCB_CAPABLE
))) {
10310 /* one qp for PF */
10311 pf
->alloc_rss_size
= pf
->num_lan_qps
= 1;
10312 queues_left
-= pf
->num_lan_qps
;
10314 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
10316 I40E_FLAG_FCOE_ENABLED
|
10318 I40E_FLAG_FD_SB_ENABLED
|
10319 I40E_FLAG_FD_ATR_ENABLED
|
10320 I40E_FLAG_DCB_ENABLED
|
10321 I40E_FLAG_VMDQ_ENABLED
);
10323 /* Not enough queues for all TCs */
10324 if ((pf
->flags
& I40E_FLAG_DCB_CAPABLE
) &&
10325 (queues_left
< I40E_MAX_TRAFFIC_CLASS
)) {
10326 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
10327 dev_info(&pf
->pdev
->dev
, "not enough queues for DCB. DCB is disabled.\n");
10329 pf
->num_lan_qps
= max_t(int, pf
->rss_size_max
,
10330 num_online_cpus());
10331 pf
->num_lan_qps
= min_t(int, pf
->num_lan_qps
,
10332 pf
->hw
.func_caps
.num_tx_qp
);
10334 queues_left
-= pf
->num_lan_qps
;
10338 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
10339 if (I40E_DEFAULT_FCOE
<= queues_left
) {
10340 pf
->num_fcoe_qps
= I40E_DEFAULT_FCOE
;
10341 } else if (I40E_MINIMUM_FCOE
<= queues_left
) {
10342 pf
->num_fcoe_qps
= I40E_MINIMUM_FCOE
;
10344 pf
->num_fcoe_qps
= 0;
10345 pf
->flags
&= ~I40E_FLAG_FCOE_ENABLED
;
10346 dev_info(&pf
->pdev
->dev
, "not enough queues for FCoE. FCoE feature will be disabled\n");
10349 queues_left
-= pf
->num_fcoe_qps
;
10353 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
10354 if (queues_left
> 1) {
10355 queues_left
-= 1; /* save 1 queue for FD */
10357 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
10358 dev_info(&pf
->pdev
->dev
, "not enough queues for Flow Director. Flow Director feature is disabled\n");
10362 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
10363 pf
->num_vf_qps
&& pf
->num_req_vfs
&& queues_left
) {
10364 pf
->num_req_vfs
= min_t(int, pf
->num_req_vfs
,
10365 (queues_left
/ pf
->num_vf_qps
));
10366 queues_left
-= (pf
->num_req_vfs
* pf
->num_vf_qps
);
10369 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
10370 pf
->num_vmdq_vsis
&& pf
->num_vmdq_qps
&& queues_left
) {
10371 pf
->num_vmdq_vsis
= min_t(int, pf
->num_vmdq_vsis
,
10372 (queues_left
/ pf
->num_vmdq_qps
));
10373 queues_left
-= (pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
);
10376 pf
->queues_left
= queues_left
;
10377 dev_dbg(&pf
->pdev
->dev
,
10378 "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
10379 pf
->hw
.func_caps
.num_tx_qp
,
10380 !!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
),
10381 pf
->num_lan_qps
, pf
->alloc_rss_size
, pf
->num_req_vfs
,
10382 pf
->num_vf_qps
, pf
->num_vmdq_vsis
, pf
->num_vmdq_qps
,
10385 dev_dbg(&pf
->pdev
->dev
, "fcoe queues = %d\n", pf
->num_fcoe_qps
);
10390 * i40e_setup_pf_filter_control - Setup PF static filter control
10391 * @pf: PF to be setup
10393 * i40e_setup_pf_filter_control sets up a PF's initial filter control
10394 * settings. If PE/FCoE are enabled then it will also set the per PF
10395 * based filter sizes required for them. It also enables Flow director,
10396 * ethertype and macvlan type filter settings for the pf.
10398 * Returns 0 on success, negative on failure
10400 static int i40e_setup_pf_filter_control(struct i40e_pf
*pf
)
10402 struct i40e_filter_control_settings
*settings
= &pf
->filter_settings
;
10404 settings
->hash_lut_size
= I40E_HASH_LUT_SIZE_128
;
10406 /* Flow Director is enabled */
10407 if (pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
))
10408 settings
->enable_fdir
= true;
10410 /* Ethtype and MACVLAN filters enabled for PF */
10411 settings
->enable_ethtype
= true;
10412 settings
->enable_macvlan
= true;
10414 if (i40e_set_filter_control(&pf
->hw
, settings
))
10420 #define INFO_STRING_LEN 255
10421 #define REMAIN(__x) (INFO_STRING_LEN - (__x))
10422 static void i40e_print_features(struct i40e_pf
*pf
)
10424 struct i40e_hw
*hw
= &pf
->hw
;
10428 buf
= kmalloc(INFO_STRING_LEN
, GFP_KERNEL
);
10432 i
= snprintf(buf
, INFO_STRING_LEN
, "Features: PF-id[%d]", hw
->pf_id
);
10433 #ifdef CONFIG_PCI_IOV
10434 i
+= snprintf(&buf
[i
], REMAIN(i
), " VFs: %d", pf
->num_req_vfs
);
10436 i
+= snprintf(&buf
[i
], REMAIN(i
), " VSIs: %d QP: %d RX: %s",
10437 pf
->hw
.func_caps
.num_vsis
,
10438 pf
->vsi
[pf
->lan_vsi
]->num_queue_pairs
,
10439 pf
->flags
& I40E_FLAG_RX_PS_ENABLED
? "PS" : "1BUF");
10441 if (pf
->flags
& I40E_FLAG_RSS_ENABLED
)
10442 i
+= snprintf(&buf
[i
], REMAIN(i
), " RSS");
10443 if (pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
)
10444 i
+= snprintf(&buf
[i
], REMAIN(i
), " FD_ATR");
10445 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
10446 i
+= snprintf(&buf
[i
], REMAIN(i
), " FD_SB");
10447 i
+= snprintf(&buf
[i
], REMAIN(i
), " NTUPLE");
10449 if (pf
->flags
& I40E_FLAG_DCB_CAPABLE
)
10450 i
+= snprintf(&buf
[i
], REMAIN(i
), " DCB");
10451 #if IS_ENABLED(CONFIG_VXLAN)
10452 i
+= snprintf(&buf
[i
], REMAIN(i
), " VxLAN");
10454 #if IS_ENABLED(CONFIG_GENEVE)
10455 i
+= snprintf(&buf
[i
], REMAIN(i
), " Geneve");
10457 if (pf
->flags
& I40E_FLAG_PTP
)
10458 i
+= snprintf(&buf
[i
], REMAIN(i
), " PTP");
10460 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
)
10461 i
+= snprintf(&buf
[i
], REMAIN(i
), " FCOE");
10463 if (pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)
10464 i
+= snprintf(&buf
[i
], REMAIN(i
), " VEB");
10466 i
+= snprintf(&buf
[i
], REMAIN(i
), " VEPA");
10468 dev_info(&pf
->pdev
->dev
, "%s\n", buf
);
10470 WARN_ON(i
> INFO_STRING_LEN
);
10474 * i40e_probe - Device initialization routine
10475 * @pdev: PCI device information struct
10476 * @ent: entry in i40e_pci_tbl
10478 * i40e_probe initializes a PF identified by a pci_dev structure.
10479 * The OS initialization, configuring of the PF private structure,
10480 * and a hardware reset occur.
10482 * Returns 0 on success, negative on failure
10484 static int i40e_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
10486 struct i40e_aq_get_phy_abilities_resp abilities
;
10487 struct i40e_pf
*pf
;
10488 struct i40e_hw
*hw
;
10489 static u16 pfs_found
;
10498 err
= pci_enable_device_mem(pdev
);
10502 /* set up for high or low dma */
10503 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
10505 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
10507 dev_err(&pdev
->dev
,
10508 "DMA configuration failed: 0x%x\n", err
);
10513 /* set up pci connections */
10514 err
= pci_request_selected_regions(pdev
, pci_select_bars(pdev
,
10515 IORESOURCE_MEM
), i40e_driver_name
);
10517 dev_info(&pdev
->dev
,
10518 "pci_request_selected_regions failed %d\n", err
);
10522 pci_enable_pcie_error_reporting(pdev
);
10523 pci_set_master(pdev
);
10525 /* Now that we have a PCI connection, we need to do the
10526 * low level device setup. This is primarily setting up
10527 * the Admin Queue structures and then querying for the
10528 * device's current profile information.
10530 pf
= kzalloc(sizeof(*pf
), GFP_KERNEL
);
10537 set_bit(__I40E_DOWN
, &pf
->state
);
10542 pf
->ioremap_len
= min_t(int, pci_resource_len(pdev
, 0),
10543 I40E_MAX_CSR_SPACE
);
10545 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0), pf
->ioremap_len
);
10546 if (!hw
->hw_addr
) {
10548 dev_info(&pdev
->dev
, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
10549 (unsigned int)pci_resource_start(pdev
, 0),
10550 pf
->ioremap_len
, err
);
10553 hw
->vendor_id
= pdev
->vendor
;
10554 hw
->device_id
= pdev
->device
;
10555 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
10556 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
10557 hw
->subsystem_device_id
= pdev
->subsystem_device
;
10558 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
10559 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
10560 pf
->instance
= pfs_found
;
10563 pf
->msg_enable
= pf
->hw
.debug_mask
;
10564 pf
->msg_enable
= debug
;
10567 /* do a special CORER for clearing PXE mode once at init */
10568 if (hw
->revision_id
== 0 &&
10569 (rd32(hw
, I40E_GLLAN_RCTL_0
) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK
)) {
10570 wr32(hw
, I40E_GLGEN_RTRIG
, I40E_GLGEN_RTRIG_CORER_MASK
);
10575 i40e_clear_pxe_mode(hw
);
10578 /* Reset here to make sure all is clean and to define PF 'n' */
10580 err
= i40e_pf_reset(hw
);
10582 dev_info(&pdev
->dev
, "Initial pf_reset failed: %d\n", err
);
10587 hw
->aq
.num_arq_entries
= I40E_AQ_LEN
;
10588 hw
->aq
.num_asq_entries
= I40E_AQ_LEN
;
10589 hw
->aq
.arq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
10590 hw
->aq
.asq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
10591 pf
->adminq_work_limit
= I40E_AQ_WORK_LIMIT
;
10593 snprintf(pf
->int_name
, sizeof(pf
->int_name
) - 1,
10595 dev_driver_string(&pf
->pdev
->dev
), dev_name(&pdev
->dev
));
10597 err
= i40e_init_shared_code(hw
);
10599 dev_warn(&pdev
->dev
, "unidentified MAC or BLANK NVM: %d\n",
10604 /* set up a default setting for link flow control */
10605 pf
->hw
.fc
.requested_mode
= I40E_FC_NONE
;
10607 err
= i40e_init_adminq(hw
);
10609 if (err
== I40E_ERR_FIRMWARE_API_VERSION
)
10610 dev_info(&pdev
->dev
,
10611 "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");
10613 dev_info(&pdev
->dev
,
10614 "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
10619 /* provide nvm, fw, api versions */
10620 dev_info(&pdev
->dev
, "fw %d.%d.%05d api %d.%d nvm %s\n",
10621 hw
->aq
.fw_maj_ver
, hw
->aq
.fw_min_ver
, hw
->aq
.fw_build
,
10622 hw
->aq
.api_maj_ver
, hw
->aq
.api_min_ver
,
10623 i40e_nvm_version_str(hw
));
10625 if (hw
->aq
.api_maj_ver
== I40E_FW_API_VERSION_MAJOR
&&
10626 hw
->aq
.api_min_ver
> I40E_FW_API_VERSION_MINOR
)
10627 dev_info(&pdev
->dev
,
10628 "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");
10629 else if (hw
->aq
.api_maj_ver
< I40E_FW_API_VERSION_MAJOR
||
10630 hw
->aq
.api_min_ver
< (I40E_FW_API_VERSION_MINOR
- 1))
10631 dev_info(&pdev
->dev
,
10632 "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
10634 i40e_verify_eeprom(pf
);
10636 /* Rev 0 hardware was never productized */
10637 if (hw
->revision_id
< 1)
10638 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");
10640 i40e_clear_pxe_mode(hw
);
10641 err
= i40e_get_capabilities(pf
);
10643 goto err_adminq_setup
;
10645 err
= i40e_sw_init(pf
);
10647 dev_info(&pdev
->dev
, "sw_init failed: %d\n", err
);
10651 err
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
10652 hw
->func_caps
.num_rx_qp
,
10653 pf
->fcoe_hmc_cntx_num
, pf
->fcoe_hmc_filt_num
);
10655 dev_info(&pdev
->dev
, "init_lan_hmc failed: %d\n", err
);
10656 goto err_init_lan_hmc
;
10659 err
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
10661 dev_info(&pdev
->dev
, "configure_lan_hmc failed: %d\n", err
);
10663 goto err_configure_lan_hmc
;
10666 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
10667 * Ignore error return codes because if it was already disabled via
10668 * hardware settings this will fail
10670 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 3)) ||
10671 (pf
->hw
.aq
.fw_maj_ver
< 4)) {
10672 dev_info(&pdev
->dev
, "Stopping firmware LLDP agent.\n");
10673 i40e_aq_stop_lldp(hw
, true, NULL
);
10676 i40e_get_mac_addr(hw
, hw
->mac
.addr
);
10677 if (!is_valid_ether_addr(hw
->mac
.addr
)) {
10678 dev_info(&pdev
->dev
, "invalid MAC address %pM\n", hw
->mac
.addr
);
10682 dev_info(&pdev
->dev
, "MAC address: %pM\n", hw
->mac
.addr
);
10683 ether_addr_copy(hw
->mac
.perm_addr
, hw
->mac
.addr
);
10684 i40e_get_port_mac_addr(hw
, hw
->mac
.port_addr
);
10685 if (is_valid_ether_addr(hw
->mac
.port_addr
))
10686 pf
->flags
|= I40E_FLAG_PORT_ID_VALID
;
10688 err
= i40e_get_san_mac_addr(hw
, hw
->mac
.san_addr
);
10690 dev_info(&pdev
->dev
,
10691 "(non-fatal) SAN MAC retrieval failed: %d\n", err
);
10692 if (!is_valid_ether_addr(hw
->mac
.san_addr
)) {
10693 dev_warn(&pdev
->dev
, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
10695 ether_addr_copy(hw
->mac
.san_addr
, hw
->mac
.addr
);
10697 dev_info(&pf
->pdev
->dev
, "SAN MAC: %pM\n", hw
->mac
.san_addr
);
10698 #endif /* I40E_FCOE */
10700 pci_set_drvdata(pdev
, pf
);
10701 pci_save_state(pdev
);
10702 #ifdef CONFIG_I40E_DCB
10703 err
= i40e_init_pf_dcb(pf
);
10705 dev_info(&pdev
->dev
, "DCB init failed %d, disabled\n", err
);
10706 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
10707 /* Continue without DCB enabled */
10709 #endif /* CONFIG_I40E_DCB */
10711 /* set up periodic task facility */
10712 setup_timer(&pf
->service_timer
, i40e_service_timer
, (unsigned long)pf
);
10713 pf
->service_timer_period
= HZ
;
10715 INIT_WORK(&pf
->service_task
, i40e_service_task
);
10716 clear_bit(__I40E_SERVICE_SCHED
, &pf
->state
);
10717 pf
->flags
|= I40E_FLAG_NEED_LINK_UPDATE
;
10719 /* NVM bit on means WoL disabled for the port */
10720 i40e_read_nvm_word(hw
, I40E_SR_NVM_WAKE_ON_LAN
, &wol_nvm_bits
);
10721 if (BIT (hw
->port
) & wol_nvm_bits
|| hw
->partition_id
!= 1)
10722 pf
->wol_en
= false;
10725 device_set_wakeup_enable(&pf
->pdev
->dev
, pf
->wol_en
);
10727 /* set up the main switch operations */
10728 i40e_determine_queue_usage(pf
);
10729 err
= i40e_init_interrupt_scheme(pf
);
10731 goto err_switch_setup
;
10733 /* The number of VSIs reported by the FW is the minimum guaranteed
10734 * to us; HW supports far more and we share the remaining pool with
10735 * the other PFs. We allocate space for more than the guarantee with
10736 * the understanding that we might not get them all later.
10738 if (pf
->hw
.func_caps
.num_vsis
< I40E_MIN_VSI_ALLOC
)
10739 pf
->num_alloc_vsi
= I40E_MIN_VSI_ALLOC
;
10741 pf
->num_alloc_vsi
= pf
->hw
.func_caps
.num_vsis
;
10743 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
10744 len
= sizeof(struct i40e_vsi
*) * pf
->num_alloc_vsi
;
10745 pf
->vsi
= kzalloc(len
, GFP_KERNEL
);
10748 goto err_switch_setup
;
10751 #ifdef CONFIG_PCI_IOV
10752 /* prep for VF support */
10753 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
10754 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
10755 !test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
10756 if (pci_num_vf(pdev
))
10757 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
10760 err
= i40e_setup_pf_switch(pf
, false);
10762 dev_info(&pdev
->dev
, "setup_pf_switch failed: %d\n", err
);
10766 /* Make sure flow control is set according to current settings */
10767 err
= i40e_set_fc(hw
, &set_fc_aq_fail
, true);
10768 if (set_fc_aq_fail
& I40E_SET_FC_AQ_FAIL_GET
)
10769 dev_dbg(&pf
->pdev
->dev
,
10770 "Set fc with err %s aq_err %s on get_phy_cap\n",
10771 i40e_stat_str(hw
, err
),
10772 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
10773 if (set_fc_aq_fail
& I40E_SET_FC_AQ_FAIL_SET
)
10774 dev_dbg(&pf
->pdev
->dev
,
10775 "Set fc with err %s aq_err %s on set_phy_config\n",
10776 i40e_stat_str(hw
, err
),
10777 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
10778 if (set_fc_aq_fail
& I40E_SET_FC_AQ_FAIL_UPDATE
)
10779 dev_dbg(&pf
->pdev
->dev
,
10780 "Set fc with err %s aq_err %s on get_link_info\n",
10781 i40e_stat_str(hw
, err
),
10782 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
10784 /* if FDIR VSI was set up, start it now */
10785 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
10786 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
10787 i40e_vsi_open(pf
->vsi
[i
]);
10792 /* driver is only interested in link up/down and module qualification
10793 * reports from firmware
10795 err
= i40e_aq_set_phy_int_mask(&pf
->hw
,
10796 I40E_AQ_EVENT_LINK_UPDOWN
|
10797 I40E_AQ_EVENT_MODULE_QUAL_FAIL
, NULL
);
10799 dev_info(&pf
->pdev
->dev
, "set phy mask fail, err %s aq_err %s\n",
10800 i40e_stat_str(&pf
->hw
, err
),
10801 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10803 /* Reconfigure hardware for allowing smaller MSS in the case
10804 * of TSO, so that we avoid the MDD being fired and causing
10805 * a reset in the case of small MSS+TSO.
10807 val
= rd32(hw
, I40E_REG_MSS
);
10808 if ((val
& I40E_REG_MSS_MIN_MASK
) > I40E_64BYTE_MSS
) {
10809 val
&= ~I40E_REG_MSS_MIN_MASK
;
10810 val
|= I40E_64BYTE_MSS
;
10811 wr32(hw
, I40E_REG_MSS
, val
);
10814 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
10815 (pf
->hw
.aq
.fw_maj_ver
< 4)) {
10817 err
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
10819 dev_info(&pf
->pdev
->dev
, "link restart failed, err %s aq_err %s\n",
10820 i40e_stat_str(&pf
->hw
, err
),
10821 i40e_aq_str(&pf
->hw
,
10822 pf
->hw
.aq
.asq_last_status
));
10824 /* The main driver is (mostly) up and happy. We need to set this state
10825 * before setting up the misc vector or we get a race and the vector
10826 * ends up disabled forever.
10828 clear_bit(__I40E_DOWN
, &pf
->state
);
10830 /* In case of MSIX we are going to setup the misc vector right here
10831 * to handle admin queue events etc. In case of legacy and MSI
10832 * the misc functionality and queue processing is combined in
10833 * the same vector and that gets setup at open.
10835 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
10836 err
= i40e_setup_misc_vector(pf
);
10838 dev_info(&pdev
->dev
,
10839 "setup of misc vector failed: %d\n", err
);
10844 #ifdef CONFIG_PCI_IOV
10845 /* prep for VF support */
10846 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
10847 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
10848 !test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
10851 /* disable link interrupts for VFs */
10852 val
= rd32(hw
, I40E_PFGEN_PORTMDIO_NUM
);
10853 val
&= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK
;
10854 wr32(hw
, I40E_PFGEN_PORTMDIO_NUM
, val
);
10857 if (pci_num_vf(pdev
)) {
10858 dev_info(&pdev
->dev
,
10859 "Active VFs found, allocating resources.\n");
10860 err
= i40e_alloc_vfs(pf
, pci_num_vf(pdev
));
10862 dev_info(&pdev
->dev
,
10863 "Error %d allocating resources for existing VFs\n",
10867 #endif /* CONFIG_PCI_IOV */
10871 i40e_dbg_pf_init(pf
);
10873 /* tell the firmware that we're starting */
10874 i40e_send_version(pf
);
10876 /* since everything's happy, start the service_task timer */
10877 mod_timer(&pf
->service_timer
,
10878 round_jiffies(jiffies
+ pf
->service_timer_period
));
10881 /* create FCoE interface */
10882 i40e_fcoe_vsi_setup(pf
);
10885 #define PCI_SPEED_SIZE 8
10886 #define PCI_WIDTH_SIZE 8
10887 /* Devices on the IOSF bus do not have this information
10888 * and will report PCI Gen 1 x 1 by default so don't bother
10891 if (!(pf
->flags
& I40E_FLAG_NO_PCI_LINK_CHECK
)) {
10892 char speed
[PCI_SPEED_SIZE
] = "Unknown";
10893 char width
[PCI_WIDTH_SIZE
] = "Unknown";
10895 /* Get the negotiated link width and speed from PCI config
10898 pcie_capability_read_word(pf
->pdev
, PCI_EXP_LNKSTA
,
10901 i40e_set_pci_config_data(hw
, link_status
);
10903 switch (hw
->bus
.speed
) {
10904 case i40e_bus_speed_8000
:
10905 strncpy(speed
, "8.0", PCI_SPEED_SIZE
); break;
10906 case i40e_bus_speed_5000
:
10907 strncpy(speed
, "5.0", PCI_SPEED_SIZE
); break;
10908 case i40e_bus_speed_2500
:
10909 strncpy(speed
, "2.5", PCI_SPEED_SIZE
); break;
10913 switch (hw
->bus
.width
) {
10914 case i40e_bus_width_pcie_x8
:
10915 strncpy(width
, "8", PCI_WIDTH_SIZE
); break;
10916 case i40e_bus_width_pcie_x4
:
10917 strncpy(width
, "4", PCI_WIDTH_SIZE
); break;
10918 case i40e_bus_width_pcie_x2
:
10919 strncpy(width
, "2", PCI_WIDTH_SIZE
); break;
10920 case i40e_bus_width_pcie_x1
:
10921 strncpy(width
, "1", PCI_WIDTH_SIZE
); break;
10926 dev_info(&pdev
->dev
, "PCI-Express: Speed %sGT/s Width x%s\n",
10929 if (hw
->bus
.width
< i40e_bus_width_pcie_x8
||
10930 hw
->bus
.speed
< i40e_bus_speed_8000
) {
10931 dev_warn(&pdev
->dev
, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
10932 dev_warn(&pdev
->dev
, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
10936 /* get the requested speeds from the fw */
10937 err
= i40e_aq_get_phy_capabilities(hw
, false, false, &abilities
, NULL
);
10939 dev_dbg(&pf
->pdev
->dev
, "get requested speeds ret = %s last_status = %s\n",
10940 i40e_stat_str(&pf
->hw
, err
),
10941 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10942 pf
->hw
.phy
.link_info
.requested_speeds
= abilities
.link_speed
;
10944 /* get the supported phy types from the fw */
10945 err
= i40e_aq_get_phy_capabilities(hw
, false, true, &abilities
, NULL
);
10947 dev_dbg(&pf
->pdev
->dev
, "get supported phy types ret = %s last_status = %s\n",
10948 i40e_stat_str(&pf
->hw
, err
),
10949 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10950 pf
->hw
.phy
.phy_types
= le32_to_cpu(abilities
.phy_type
);
10952 /* Add a filter to drop all Flow control frames from any VSI from being
10953 * transmitted. By doing so we stop a malicious VF from sending out
10954 * PAUSE or PFC frames and potentially controlling traffic for other
10956 * The FW can still send Flow control frames if enabled.
10958 i40e_add_filter_to_drop_tx_flow_control_frames(&pf
->hw
,
10959 pf
->main_vsi_seid
);
10961 /* print a string summarizing features */
10962 i40e_print_features(pf
);
10966 /* Unwind what we've done if something failed in the setup */
10968 set_bit(__I40E_DOWN
, &pf
->state
);
10969 i40e_clear_interrupt_scheme(pf
);
10972 i40e_reset_interrupt_capability(pf
);
10973 del_timer_sync(&pf
->service_timer
);
10975 err_configure_lan_hmc
:
10976 (void)i40e_shutdown_lan_hmc(hw
);
10978 kfree(pf
->qp_pile
);
10981 (void)i40e_shutdown_adminq(hw
);
10983 iounmap(hw
->hw_addr
);
10987 pci_disable_pcie_error_reporting(pdev
);
10988 pci_release_selected_regions(pdev
,
10989 pci_select_bars(pdev
, IORESOURCE_MEM
));
10992 pci_disable_device(pdev
);
10997 * i40e_remove - Device removal routine
10998 * @pdev: PCI device information struct
11000 * i40e_remove is called by the PCI subsystem to alert the driver
11001 * that is should release a PCI device. This could be caused by a
11002 * Hot-Plug event, or because the driver is going to be removed from
11005 static void i40e_remove(struct pci_dev
*pdev
)
11007 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
11008 struct i40e_hw
*hw
= &pf
->hw
;
11009 i40e_status ret_code
;
11012 i40e_dbg_pf_exit(pf
);
11016 /* Disable RSS in hw */
11017 wr32(hw
, I40E_PFQF_HENA(0), 0);
11018 wr32(hw
, I40E_PFQF_HENA(1), 0);
11020 /* no more scheduling of any task */
11021 set_bit(__I40E_DOWN
, &pf
->state
);
11022 del_timer_sync(&pf
->service_timer
);
11023 cancel_work_sync(&pf
->service_task
);
11024 i40e_fdir_teardown(pf
);
11026 if (pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) {
11028 pf
->flags
&= ~I40E_FLAG_SRIOV_ENABLED
;
11031 i40e_fdir_teardown(pf
);
11033 /* If there is a switch structure or any orphans, remove them.
11034 * This will leave only the PF's VSI remaining.
11036 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
11040 if (pf
->veb
[i
]->uplink_seid
== pf
->mac_seid
||
11041 pf
->veb
[i
]->uplink_seid
== 0)
11042 i40e_switch_branch_release(pf
->veb
[i
]);
11045 /* Now we can shutdown the PF's VSI, just before we kill
11048 if (pf
->vsi
[pf
->lan_vsi
])
11049 i40e_vsi_release(pf
->vsi
[pf
->lan_vsi
]);
11051 /* shutdown and destroy the HMC */
11052 if (pf
->hw
.hmc
.hmc_obj
) {
11053 ret_code
= i40e_shutdown_lan_hmc(&pf
->hw
);
11055 dev_warn(&pdev
->dev
,
11056 "Failed to destroy the HMC resources: %d\n",
11060 /* shutdown the adminq */
11061 ret_code
= i40e_shutdown_adminq(&pf
->hw
);
11063 dev_warn(&pdev
->dev
,
11064 "Failed to destroy the Admin Queue resources: %d\n",
11067 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
11068 i40e_clear_interrupt_scheme(pf
);
11069 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
11071 i40e_vsi_clear_rings(pf
->vsi
[i
]);
11072 i40e_vsi_clear(pf
->vsi
[i
]);
11077 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
11082 kfree(pf
->qp_pile
);
11085 iounmap(pf
->hw
.hw_addr
);
11087 pci_release_selected_regions(pdev
,
11088 pci_select_bars(pdev
, IORESOURCE_MEM
));
11090 pci_disable_pcie_error_reporting(pdev
);
11091 pci_disable_device(pdev
);
11095 * i40e_pci_error_detected - warning that something funky happened in PCI land
11096 * @pdev: PCI device information struct
11098 * Called to warn that something happened and the error handling steps
11099 * are in progress. Allows the driver to quiesce things, be ready for
11102 static pci_ers_result_t
i40e_pci_error_detected(struct pci_dev
*pdev
,
11103 enum pci_channel_state error
)
11105 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
11107 dev_info(&pdev
->dev
, "%s: error %d\n", __func__
, error
);
11109 /* shutdown all operations */
11110 if (!test_bit(__I40E_SUSPENDED
, &pf
->state
)) {
11112 i40e_prep_for_reset(pf
);
11116 /* Request a slot reset */
11117 return PCI_ERS_RESULT_NEED_RESET
;
11121 * i40e_pci_error_slot_reset - a PCI slot reset just happened
11122 * @pdev: PCI device information struct
11124 * Called to find if the driver can work with the device now that
11125 * the pci slot has been reset. If a basic connection seems good
11126 * (registers are readable and have sane content) then return a
11127 * happy little PCI_ERS_RESULT_xxx.
11129 static pci_ers_result_t
i40e_pci_error_slot_reset(struct pci_dev
*pdev
)
11131 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
11132 pci_ers_result_t result
;
11136 dev_dbg(&pdev
->dev
, "%s\n", __func__
);
11137 if (pci_enable_device_mem(pdev
)) {
11138 dev_info(&pdev
->dev
,
11139 "Cannot re-enable PCI device after reset.\n");
11140 result
= PCI_ERS_RESULT_DISCONNECT
;
11142 pci_set_master(pdev
);
11143 pci_restore_state(pdev
);
11144 pci_save_state(pdev
);
11145 pci_wake_from_d3(pdev
, false);
11147 reg
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
11149 result
= PCI_ERS_RESULT_RECOVERED
;
11151 result
= PCI_ERS_RESULT_DISCONNECT
;
11154 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
11156 dev_info(&pdev
->dev
,
11157 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
11159 /* non-fatal, continue */
11166 * i40e_pci_error_resume - restart operations after PCI error recovery
11167 * @pdev: PCI device information struct
11169 * Called to allow the driver to bring things back up after PCI error
11170 * and/or reset recovery has finished.
11172 static void i40e_pci_error_resume(struct pci_dev
*pdev
)
11174 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
11176 dev_dbg(&pdev
->dev
, "%s\n", __func__
);
11177 if (test_bit(__I40E_SUSPENDED
, &pf
->state
))
11181 i40e_handle_reset_warning(pf
);
11186 * i40e_shutdown - PCI callback for shutting down
11187 * @pdev: PCI device information struct
11189 static void i40e_shutdown(struct pci_dev
*pdev
)
11191 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
11192 struct i40e_hw
*hw
= &pf
->hw
;
11194 set_bit(__I40E_SUSPENDED
, &pf
->state
);
11195 set_bit(__I40E_DOWN
, &pf
->state
);
11197 i40e_prep_for_reset(pf
);
11200 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
11201 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
11203 del_timer_sync(&pf
->service_timer
);
11204 cancel_work_sync(&pf
->service_task
);
11205 i40e_fdir_teardown(pf
);
11208 i40e_prep_for_reset(pf
);
11211 wr32(hw
, I40E_PFPM_APM
,
11212 (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
11213 wr32(hw
, I40E_PFPM_WUFC
,
11214 (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
11216 i40e_clear_interrupt_scheme(pf
);
11218 if (system_state
== SYSTEM_POWER_OFF
) {
11219 pci_wake_from_d3(pdev
, pf
->wol_en
);
11220 pci_set_power_state(pdev
, PCI_D3hot
);
11226 * i40e_suspend - PCI callback for moving to D3
11227 * @pdev: PCI device information struct
11229 static int i40e_suspend(struct pci_dev
*pdev
, pm_message_t state
)
11231 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
11232 struct i40e_hw
*hw
= &pf
->hw
;
11234 set_bit(__I40E_SUSPENDED
, &pf
->state
);
11235 set_bit(__I40E_DOWN
, &pf
->state
);
11238 i40e_prep_for_reset(pf
);
11241 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
11242 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
11244 pci_wake_from_d3(pdev
, pf
->wol_en
);
11245 pci_set_power_state(pdev
, PCI_D3hot
);
11251 * i40e_resume - PCI callback for waking up from D3
11252 * @pdev: PCI device information struct
11254 static int i40e_resume(struct pci_dev
*pdev
)
11256 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
11259 pci_set_power_state(pdev
, PCI_D0
);
11260 pci_restore_state(pdev
);
11261 /* pci_restore_state() clears dev->state_saves, so
11262 * call pci_save_state() again to restore it.
11264 pci_save_state(pdev
);
11266 err
= pci_enable_device_mem(pdev
);
11268 dev_err(&pdev
->dev
, "Cannot enable PCI device from suspend\n");
11271 pci_set_master(pdev
);
11273 /* no wakeup events while running */
11274 pci_wake_from_d3(pdev
, false);
11276 /* handling the reset will rebuild the device state */
11277 if (test_and_clear_bit(__I40E_SUSPENDED
, &pf
->state
)) {
11278 clear_bit(__I40E_DOWN
, &pf
->state
);
11280 i40e_reset_and_rebuild(pf
, false);
11288 static const struct pci_error_handlers i40e_err_handler
= {
11289 .error_detected
= i40e_pci_error_detected
,
11290 .slot_reset
= i40e_pci_error_slot_reset
,
11291 .resume
= i40e_pci_error_resume
,
11294 static struct pci_driver i40e_driver
= {
11295 .name
= i40e_driver_name
,
11296 .id_table
= i40e_pci_tbl
,
11297 .probe
= i40e_probe
,
11298 .remove
= i40e_remove
,
11300 .suspend
= i40e_suspend
,
11301 .resume
= i40e_resume
,
11303 .shutdown
= i40e_shutdown
,
11304 .err_handler
= &i40e_err_handler
,
11305 .sriov_configure
= i40e_pci_sriov_configure
,
11309 * i40e_init_module - Driver registration routine
11311 * i40e_init_module is the first routine called when the driver is
11312 * loaded. All it does is register with the PCI subsystem.
11314 static int __init
i40e_init_module(void)
11316 pr_info("%s: %s - version %s\n", i40e_driver_name
,
11317 i40e_driver_string
, i40e_driver_version_str
);
11318 pr_info("%s: %s\n", i40e_driver_name
, i40e_copyright
);
11321 return pci_register_driver(&i40e_driver
);
11323 module_init(i40e_init_module
);
11326 * i40e_exit_module - Driver exit cleanup routine
11328 * i40e_exit_module is called just before the driver is removed
11331 static void __exit
i40e_exit_module(void)
11333 pci_unregister_driver(&i40e_driver
);
11336 module_exit(i40e_exit_module
);