1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2016 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 ******************************************************************************/
27 #include <linux/etherdevice.h>
28 #include <linux/of_net.h>
29 #include <linux/pci.h>
33 #include "i40e_diag.h"
34 #include <net/udp_tunnel.h>
36 const char i40e_driver_name
[] = "i40e";
37 static const char i40e_driver_string
[] =
38 "Intel(R) Ethernet Connection XL710 Network Driver";
42 #define DRV_VERSION_MAJOR 1
43 #define DRV_VERSION_MINOR 6
44 #define DRV_VERSION_BUILD 25
45 #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
46 __stringify(DRV_VERSION_MINOR) "." \
47 __stringify(DRV_VERSION_BUILD) DRV_KERN
48 const char i40e_driver_version_str
[] = DRV_VERSION
;
49 static const char i40e_copyright
[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
51 /* a bit of forward declarations */
52 static void i40e_vsi_reinit_locked(struct i40e_vsi
*vsi
);
53 static void i40e_handle_reset_warning(struct i40e_pf
*pf
);
54 static int i40e_add_vsi(struct i40e_vsi
*vsi
);
55 static int i40e_add_veb(struct i40e_veb
*veb
, struct i40e_vsi
*vsi
);
56 static int i40e_setup_pf_switch(struct i40e_pf
*pf
, bool reinit
);
57 static int i40e_setup_misc_vector(struct i40e_pf
*pf
);
58 static void i40e_determine_queue_usage(struct i40e_pf
*pf
);
59 static int i40e_setup_pf_filter_control(struct i40e_pf
*pf
);
60 static void i40e_fdir_sb_setup(struct i40e_pf
*pf
);
61 static int i40e_veb_get_bw_info(struct i40e_veb
*veb
);
63 /* i40e_pci_tbl - PCI Device ID Table
65 * Last entry must be all 0s
67 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
68 * Class, Class Mask, private data (not used) }
70 static const struct pci_device_id i40e_pci_tbl
[] = {
71 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_SFP_XL710
), 0},
72 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QEMU
), 0},
73 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_B
), 0},
74 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_C
), 0},
75 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_A
), 0},
76 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_B
), 0},
77 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_C
), 0},
78 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T
), 0},
79 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T4
), 0},
80 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_20G_KR2
), 0},
81 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_X722
), 0},
82 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_X722
), 0},
83 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_SFP_X722
), 0},
84 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_1G_BASE_T_X722
), 0},
85 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T_X722
), 0},
86 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_SFP_I_X722
), 0},
87 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_20G_KR2
), 0},
88 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_20G_KR2_A
), 0},
89 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_25G_B
), 0},
90 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_25G_SFP28
), 0},
91 /* required last entry */
94 MODULE_DEVICE_TABLE(pci
, i40e_pci_tbl
);
96 #define I40E_MAX_VF_COUNT 128
97 static int debug
= -1;
98 module_param(debug
, uint
, 0);
99 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXX)");
101 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
102 MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
103 MODULE_LICENSE("GPL");
104 MODULE_VERSION(DRV_VERSION
);
106 static struct workqueue_struct
*i40e_wq
;
109 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
110 * @hw: pointer to the HW structure
111 * @mem: ptr to mem struct to fill out
112 * @size: size of memory requested
113 * @alignment: what to align the allocation to
115 int i40e_allocate_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
,
116 u64 size
, u32 alignment
)
118 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
120 mem
->size
= ALIGN(size
, alignment
);
121 mem
->va
= dma_zalloc_coherent(&pf
->pdev
->dev
, mem
->size
,
122 &mem
->pa
, GFP_KERNEL
);
130 * i40e_free_dma_mem_d - OS specific memory free for shared code
131 * @hw: pointer to the HW structure
132 * @mem: ptr to mem struct to free
134 int i40e_free_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
)
136 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
138 dma_free_coherent(&pf
->pdev
->dev
, mem
->size
, mem
->va
, mem
->pa
);
147 * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
148 * @hw: pointer to the HW structure
149 * @mem: ptr to mem struct to fill out
150 * @size: size of memory requested
152 int i40e_allocate_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
,
156 mem
->va
= kzalloc(size
, GFP_KERNEL
);
165 * i40e_free_virt_mem_d - OS specific memory free for shared code
166 * @hw: pointer to the HW structure
167 * @mem: ptr to mem struct to free
169 int i40e_free_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
)
171 /* it's ok to kfree a NULL pointer */
180 * i40e_get_lump - find a lump of free generic resource
181 * @pf: board private structure
182 * @pile: the pile of resource to search
183 * @needed: the number of items needed
184 * @id: an owner id to stick on the items assigned
186 * Returns the base item index of the lump, or negative for error
188 * The search_hint trick and lack of advanced fit-finding only work
189 * because we're highly likely to have all the same size lump requests.
190 * Linear search time and any fragmentation should be minimal.
192 static int i40e_get_lump(struct i40e_pf
*pf
, struct i40e_lump_tracking
*pile
,
198 if (!pile
|| needed
== 0 || id
>= I40E_PILE_VALID_BIT
) {
199 dev_info(&pf
->pdev
->dev
,
200 "param err: pile=%p needed=%d id=0x%04x\n",
205 /* start the linear search with an imperfect hint */
206 i
= pile
->search_hint
;
207 while (i
< pile
->num_entries
) {
208 /* skip already allocated entries */
209 if (pile
->list
[i
] & I40E_PILE_VALID_BIT
) {
214 /* do we have enough in this lump? */
215 for (j
= 0; (j
< needed
) && ((i
+j
) < pile
->num_entries
); j
++) {
216 if (pile
->list
[i
+j
] & I40E_PILE_VALID_BIT
)
221 /* there was enough, so assign it to the requestor */
222 for (j
= 0; j
< needed
; j
++)
223 pile
->list
[i
+j
] = id
| I40E_PILE_VALID_BIT
;
225 pile
->search_hint
= i
+ j
;
229 /* not enough, so skip over it and continue looking */
237 * i40e_put_lump - return a lump of generic resource
238 * @pile: the pile of resource to search
239 * @index: the base item index
240 * @id: the owner id of the items assigned
242 * Returns the count of items in the lump
244 static int i40e_put_lump(struct i40e_lump_tracking
*pile
, u16 index
, u16 id
)
246 int valid_id
= (id
| I40E_PILE_VALID_BIT
);
250 if (!pile
|| index
>= pile
->num_entries
)
254 i
< pile
->num_entries
&& pile
->list
[i
] == valid_id
;
260 if (count
&& index
< pile
->search_hint
)
261 pile
->search_hint
= index
;
267 * i40e_find_vsi_from_id - searches for the vsi with the given id
268 * @pf - the pf structure to search for the vsi
269 * @id - id of the vsi it is searching for
271 struct i40e_vsi
*i40e_find_vsi_from_id(struct i40e_pf
*pf
, u16 id
)
275 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
276 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->id
== id
))
283 * i40e_service_event_schedule - Schedule the service task to wake up
284 * @pf: board private structure
286 * If not already scheduled, this puts the task into the work queue
288 void i40e_service_event_schedule(struct i40e_pf
*pf
)
290 if (!test_bit(__I40E_DOWN
, &pf
->state
) &&
291 !test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
))
292 queue_work(i40e_wq
, &pf
->service_task
);
296 * i40e_tx_timeout - Respond to a Tx Hang
297 * @netdev: network interface device structure
299 * If any port has noticed a Tx timeout, it is likely that the whole
300 * device is munged, not just the one netdev port, so go for the full
304 void i40e_tx_timeout(struct net_device
*netdev
)
306 static void i40e_tx_timeout(struct net_device
*netdev
)
309 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
310 struct i40e_vsi
*vsi
= np
->vsi
;
311 struct i40e_pf
*pf
= vsi
->back
;
312 struct i40e_ring
*tx_ring
= NULL
;
313 unsigned int i
, hung_queue
= 0;
316 pf
->tx_timeout_count
++;
318 /* find the stopped queue the same way the stack does */
319 for (i
= 0; i
< netdev
->num_tx_queues
; i
++) {
320 struct netdev_queue
*q
;
321 unsigned long trans_start
;
323 q
= netdev_get_tx_queue(netdev
, i
);
324 trans_start
= q
->trans_start
;
325 if (netif_xmit_stopped(q
) &&
327 (trans_start
+ netdev
->watchdog_timeo
))) {
333 if (i
== netdev
->num_tx_queues
) {
334 netdev_info(netdev
, "tx_timeout: no netdev hung queue found\n");
336 /* now that we have an index, find the tx_ring struct */
337 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
338 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
) {
340 vsi
->tx_rings
[i
]->queue_index
) {
341 tx_ring
= vsi
->tx_rings
[i
];
348 if (time_after(jiffies
, (pf
->tx_timeout_last_recovery
+ HZ
*20)))
349 pf
->tx_timeout_recovery_level
= 1; /* reset after some time */
350 else if (time_before(jiffies
,
351 (pf
->tx_timeout_last_recovery
+ netdev
->watchdog_timeo
)))
352 return; /* don't do any new action before the next timeout */
355 head
= i40e_get_head(tx_ring
);
356 /* Read interrupt register */
357 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
359 I40E_PFINT_DYN_CTLN(tx_ring
->q_vector
->v_idx
+
360 tx_ring
->vsi
->base_vector
- 1));
362 val
= rd32(&pf
->hw
, I40E_PFINT_DYN_CTL0
);
364 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",
365 vsi
->seid
, hung_queue
, tx_ring
->next_to_clean
,
366 head
, tx_ring
->next_to_use
,
367 readl(tx_ring
->tail
), val
);
370 pf
->tx_timeout_last_recovery
= jiffies
;
371 netdev_info(netdev
, "tx_timeout recovery level %d, hung_queue %d\n",
372 pf
->tx_timeout_recovery_level
, hung_queue
);
374 switch (pf
->tx_timeout_recovery_level
) {
376 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
379 set_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
);
382 set_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
);
385 netdev_err(netdev
, "tx_timeout recovery unsuccessful\n");
389 i40e_service_event_schedule(pf
);
390 pf
->tx_timeout_recovery_level
++;
394 * i40e_get_vsi_stats_struct - Get System Network Statistics
395 * @vsi: the VSI we care about
397 * Returns the address of the device statistics structure.
398 * The statistics are actually updated from the service task.
400 struct rtnl_link_stats64
*i40e_get_vsi_stats_struct(struct i40e_vsi
*vsi
)
402 return &vsi
->net_stats
;
406 * i40e_get_netdev_stats_struct - Get statistics for netdev interface
407 * @netdev: network interface device structure
409 * Returns the address of the device statistics structure.
410 * The statistics are actually updated from the service task.
415 void i40e_get_netdev_stats_struct(struct net_device
*netdev
,
416 struct rtnl_link_stats64
*stats
)
418 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
419 struct i40e_ring
*tx_ring
, *rx_ring
;
420 struct i40e_vsi
*vsi
= np
->vsi
;
421 struct rtnl_link_stats64
*vsi_stats
= i40e_get_vsi_stats_struct(vsi
);
424 if (test_bit(__I40E_DOWN
, &vsi
->state
))
431 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
435 tx_ring
= ACCESS_ONCE(vsi
->tx_rings
[i
]);
440 start
= u64_stats_fetch_begin_irq(&tx_ring
->syncp
);
441 packets
= tx_ring
->stats
.packets
;
442 bytes
= tx_ring
->stats
.bytes
;
443 } while (u64_stats_fetch_retry_irq(&tx_ring
->syncp
, start
));
445 stats
->tx_packets
+= packets
;
446 stats
->tx_bytes
+= bytes
;
447 rx_ring
= &tx_ring
[1];
450 start
= u64_stats_fetch_begin_irq(&rx_ring
->syncp
);
451 packets
= rx_ring
->stats
.packets
;
452 bytes
= rx_ring
->stats
.bytes
;
453 } while (u64_stats_fetch_retry_irq(&rx_ring
->syncp
, start
));
455 stats
->rx_packets
+= packets
;
456 stats
->rx_bytes
+= bytes
;
460 /* following stats updated by i40e_watchdog_subtask() */
461 stats
->multicast
= vsi_stats
->multicast
;
462 stats
->tx_errors
= vsi_stats
->tx_errors
;
463 stats
->tx_dropped
= vsi_stats
->tx_dropped
;
464 stats
->rx_errors
= vsi_stats
->rx_errors
;
465 stats
->rx_dropped
= vsi_stats
->rx_dropped
;
466 stats
->rx_crc_errors
= vsi_stats
->rx_crc_errors
;
467 stats
->rx_length_errors
= vsi_stats
->rx_length_errors
;
471 * i40e_vsi_reset_stats - Resets all stats of the given vsi
472 * @vsi: the VSI to have its stats reset
474 void i40e_vsi_reset_stats(struct i40e_vsi
*vsi
)
476 struct rtnl_link_stats64
*ns
;
482 ns
= i40e_get_vsi_stats_struct(vsi
);
483 memset(ns
, 0, sizeof(*ns
));
484 memset(&vsi
->net_stats_offsets
, 0, sizeof(vsi
->net_stats_offsets
));
485 memset(&vsi
->eth_stats
, 0, sizeof(vsi
->eth_stats
));
486 memset(&vsi
->eth_stats_offsets
, 0, sizeof(vsi
->eth_stats_offsets
));
487 if (vsi
->rx_rings
&& vsi
->rx_rings
[0]) {
488 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
489 memset(&vsi
->rx_rings
[i
]->stats
, 0,
490 sizeof(vsi
->rx_rings
[i
]->stats
));
491 memset(&vsi
->rx_rings
[i
]->rx_stats
, 0,
492 sizeof(vsi
->rx_rings
[i
]->rx_stats
));
493 memset(&vsi
->tx_rings
[i
]->stats
, 0,
494 sizeof(vsi
->tx_rings
[i
]->stats
));
495 memset(&vsi
->tx_rings
[i
]->tx_stats
, 0,
496 sizeof(vsi
->tx_rings
[i
]->tx_stats
));
499 vsi
->stat_offsets_loaded
= false;
503 * i40e_pf_reset_stats - Reset all of the stats for the given PF
504 * @pf: the PF to be reset
506 void i40e_pf_reset_stats(struct i40e_pf
*pf
)
510 memset(&pf
->stats
, 0, sizeof(pf
->stats
));
511 memset(&pf
->stats_offsets
, 0, sizeof(pf
->stats_offsets
));
512 pf
->stat_offsets_loaded
= false;
514 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
516 memset(&pf
->veb
[i
]->stats
, 0,
517 sizeof(pf
->veb
[i
]->stats
));
518 memset(&pf
->veb
[i
]->stats_offsets
, 0,
519 sizeof(pf
->veb
[i
]->stats_offsets
));
520 pf
->veb
[i
]->stat_offsets_loaded
= false;
523 pf
->hw_csum_rx_error
= 0;
527 * i40e_stat_update48 - read and update a 48 bit stat from the chip
528 * @hw: ptr to the hardware info
529 * @hireg: the high 32 bit reg to read
530 * @loreg: the low 32 bit reg to read
531 * @offset_loaded: has the initial offset been loaded yet
532 * @offset: ptr to current offset value
533 * @stat: ptr to the stat
535 * Since the device stats are not reset at PFReset, they likely will not
536 * be zeroed when the driver starts. We'll save the first values read
537 * and use them as offsets to be subtracted from the raw values in order
538 * to report stats that count from zero. In the process, we also manage
539 * the potential roll-over.
541 static void i40e_stat_update48(struct i40e_hw
*hw
, u32 hireg
, u32 loreg
,
542 bool offset_loaded
, u64
*offset
, u64
*stat
)
546 if (hw
->device_id
== I40E_DEV_ID_QEMU
) {
547 new_data
= rd32(hw
, loreg
);
548 new_data
|= ((u64
)(rd32(hw
, hireg
) & 0xFFFF)) << 32;
550 new_data
= rd64(hw
, loreg
);
554 if (likely(new_data
>= *offset
))
555 *stat
= new_data
- *offset
;
557 *stat
= (new_data
+ BIT_ULL(48)) - *offset
;
558 *stat
&= 0xFFFFFFFFFFFFULL
;
562 * i40e_stat_update32 - read and update a 32 bit stat from the chip
563 * @hw: ptr to the hardware info
564 * @reg: the hw reg to read
565 * @offset_loaded: has the initial offset been loaded yet
566 * @offset: ptr to current offset value
567 * @stat: ptr to the stat
569 static void i40e_stat_update32(struct i40e_hw
*hw
, u32 reg
,
570 bool offset_loaded
, u64
*offset
, u64
*stat
)
574 new_data
= rd32(hw
, reg
);
577 if (likely(new_data
>= *offset
))
578 *stat
= (u32
)(new_data
- *offset
);
580 *stat
= (u32
)((new_data
+ BIT_ULL(32)) - *offset
);
584 * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
585 * @vsi: the VSI to be updated
587 void i40e_update_eth_stats(struct i40e_vsi
*vsi
)
589 int stat_idx
= le16_to_cpu(vsi
->info
.stat_counter_idx
);
590 struct i40e_pf
*pf
= vsi
->back
;
591 struct i40e_hw
*hw
= &pf
->hw
;
592 struct i40e_eth_stats
*oes
;
593 struct i40e_eth_stats
*es
; /* device's eth stats */
595 es
= &vsi
->eth_stats
;
596 oes
= &vsi
->eth_stats_offsets
;
598 /* Gather up the stats that the hw collects */
599 i40e_stat_update32(hw
, I40E_GLV_TEPC(stat_idx
),
600 vsi
->stat_offsets_loaded
,
601 &oes
->tx_errors
, &es
->tx_errors
);
602 i40e_stat_update32(hw
, I40E_GLV_RDPC(stat_idx
),
603 vsi
->stat_offsets_loaded
,
604 &oes
->rx_discards
, &es
->rx_discards
);
605 i40e_stat_update32(hw
, I40E_GLV_RUPP(stat_idx
),
606 vsi
->stat_offsets_loaded
,
607 &oes
->rx_unknown_protocol
, &es
->rx_unknown_protocol
);
608 i40e_stat_update32(hw
, I40E_GLV_TEPC(stat_idx
),
609 vsi
->stat_offsets_loaded
,
610 &oes
->tx_errors
, &es
->tx_errors
);
612 i40e_stat_update48(hw
, I40E_GLV_GORCH(stat_idx
),
613 I40E_GLV_GORCL(stat_idx
),
614 vsi
->stat_offsets_loaded
,
615 &oes
->rx_bytes
, &es
->rx_bytes
);
616 i40e_stat_update48(hw
, I40E_GLV_UPRCH(stat_idx
),
617 I40E_GLV_UPRCL(stat_idx
),
618 vsi
->stat_offsets_loaded
,
619 &oes
->rx_unicast
, &es
->rx_unicast
);
620 i40e_stat_update48(hw
, I40E_GLV_MPRCH(stat_idx
),
621 I40E_GLV_MPRCL(stat_idx
),
622 vsi
->stat_offsets_loaded
,
623 &oes
->rx_multicast
, &es
->rx_multicast
);
624 i40e_stat_update48(hw
, I40E_GLV_BPRCH(stat_idx
),
625 I40E_GLV_BPRCL(stat_idx
),
626 vsi
->stat_offsets_loaded
,
627 &oes
->rx_broadcast
, &es
->rx_broadcast
);
629 i40e_stat_update48(hw
, I40E_GLV_GOTCH(stat_idx
),
630 I40E_GLV_GOTCL(stat_idx
),
631 vsi
->stat_offsets_loaded
,
632 &oes
->tx_bytes
, &es
->tx_bytes
);
633 i40e_stat_update48(hw
, I40E_GLV_UPTCH(stat_idx
),
634 I40E_GLV_UPTCL(stat_idx
),
635 vsi
->stat_offsets_loaded
,
636 &oes
->tx_unicast
, &es
->tx_unicast
);
637 i40e_stat_update48(hw
, I40E_GLV_MPTCH(stat_idx
),
638 I40E_GLV_MPTCL(stat_idx
),
639 vsi
->stat_offsets_loaded
,
640 &oes
->tx_multicast
, &es
->tx_multicast
);
641 i40e_stat_update48(hw
, I40E_GLV_BPTCH(stat_idx
),
642 I40E_GLV_BPTCL(stat_idx
),
643 vsi
->stat_offsets_loaded
,
644 &oes
->tx_broadcast
, &es
->tx_broadcast
);
645 vsi
->stat_offsets_loaded
= true;
649 * i40e_update_veb_stats - Update Switch component statistics
650 * @veb: the VEB being updated
652 static void i40e_update_veb_stats(struct i40e_veb
*veb
)
654 struct i40e_pf
*pf
= veb
->pf
;
655 struct i40e_hw
*hw
= &pf
->hw
;
656 struct i40e_eth_stats
*oes
;
657 struct i40e_eth_stats
*es
; /* device's eth stats */
658 struct i40e_veb_tc_stats
*veb_oes
;
659 struct i40e_veb_tc_stats
*veb_es
;
662 idx
= veb
->stats_idx
;
664 oes
= &veb
->stats_offsets
;
665 veb_es
= &veb
->tc_stats
;
666 veb_oes
= &veb
->tc_stats_offsets
;
668 /* Gather up the stats that the hw collects */
669 i40e_stat_update32(hw
, I40E_GLSW_TDPC(idx
),
670 veb
->stat_offsets_loaded
,
671 &oes
->tx_discards
, &es
->tx_discards
);
672 if (hw
->revision_id
> 0)
673 i40e_stat_update32(hw
, I40E_GLSW_RUPP(idx
),
674 veb
->stat_offsets_loaded
,
675 &oes
->rx_unknown_protocol
,
676 &es
->rx_unknown_protocol
);
677 i40e_stat_update48(hw
, I40E_GLSW_GORCH(idx
), I40E_GLSW_GORCL(idx
),
678 veb
->stat_offsets_loaded
,
679 &oes
->rx_bytes
, &es
->rx_bytes
);
680 i40e_stat_update48(hw
, I40E_GLSW_UPRCH(idx
), I40E_GLSW_UPRCL(idx
),
681 veb
->stat_offsets_loaded
,
682 &oes
->rx_unicast
, &es
->rx_unicast
);
683 i40e_stat_update48(hw
, I40E_GLSW_MPRCH(idx
), I40E_GLSW_MPRCL(idx
),
684 veb
->stat_offsets_loaded
,
685 &oes
->rx_multicast
, &es
->rx_multicast
);
686 i40e_stat_update48(hw
, I40E_GLSW_BPRCH(idx
), I40E_GLSW_BPRCL(idx
),
687 veb
->stat_offsets_loaded
,
688 &oes
->rx_broadcast
, &es
->rx_broadcast
);
690 i40e_stat_update48(hw
, I40E_GLSW_GOTCH(idx
), I40E_GLSW_GOTCL(idx
),
691 veb
->stat_offsets_loaded
,
692 &oes
->tx_bytes
, &es
->tx_bytes
);
693 i40e_stat_update48(hw
, I40E_GLSW_UPTCH(idx
), I40E_GLSW_UPTCL(idx
),
694 veb
->stat_offsets_loaded
,
695 &oes
->tx_unicast
, &es
->tx_unicast
);
696 i40e_stat_update48(hw
, I40E_GLSW_MPTCH(idx
), I40E_GLSW_MPTCL(idx
),
697 veb
->stat_offsets_loaded
,
698 &oes
->tx_multicast
, &es
->tx_multicast
);
699 i40e_stat_update48(hw
, I40E_GLSW_BPTCH(idx
), I40E_GLSW_BPTCL(idx
),
700 veb
->stat_offsets_loaded
,
701 &oes
->tx_broadcast
, &es
->tx_broadcast
);
702 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
703 i40e_stat_update48(hw
, I40E_GLVEBTC_RPCH(i
, idx
),
704 I40E_GLVEBTC_RPCL(i
, idx
),
705 veb
->stat_offsets_loaded
,
706 &veb_oes
->tc_rx_packets
[i
],
707 &veb_es
->tc_rx_packets
[i
]);
708 i40e_stat_update48(hw
, I40E_GLVEBTC_RBCH(i
, idx
),
709 I40E_GLVEBTC_RBCL(i
, idx
),
710 veb
->stat_offsets_loaded
,
711 &veb_oes
->tc_rx_bytes
[i
],
712 &veb_es
->tc_rx_bytes
[i
]);
713 i40e_stat_update48(hw
, I40E_GLVEBTC_TPCH(i
, idx
),
714 I40E_GLVEBTC_TPCL(i
, idx
),
715 veb
->stat_offsets_loaded
,
716 &veb_oes
->tc_tx_packets
[i
],
717 &veb_es
->tc_tx_packets
[i
]);
718 i40e_stat_update48(hw
, I40E_GLVEBTC_TBCH(i
, idx
),
719 I40E_GLVEBTC_TBCL(i
, idx
),
720 veb
->stat_offsets_loaded
,
721 &veb_oes
->tc_tx_bytes
[i
],
722 &veb_es
->tc_tx_bytes
[i
]);
724 veb
->stat_offsets_loaded
= true;
729 * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters.
730 * @vsi: the VSI that is capable of doing FCoE
732 static void i40e_update_fcoe_stats(struct i40e_vsi
*vsi
)
734 struct i40e_pf
*pf
= vsi
->back
;
735 struct i40e_hw
*hw
= &pf
->hw
;
736 struct i40e_fcoe_stats
*ofs
;
737 struct i40e_fcoe_stats
*fs
; /* device's eth stats */
740 if (vsi
->type
!= I40E_VSI_FCOE
)
743 idx
= hw
->pf_id
+ I40E_FCOE_PF_STAT_OFFSET
;
744 fs
= &vsi
->fcoe_stats
;
745 ofs
= &vsi
->fcoe_stats_offsets
;
747 i40e_stat_update32(hw
, I40E_GL_FCOEPRC(idx
),
748 vsi
->fcoe_stat_offsets_loaded
,
749 &ofs
->rx_fcoe_packets
, &fs
->rx_fcoe_packets
);
750 i40e_stat_update48(hw
, I40E_GL_FCOEDWRCH(idx
), I40E_GL_FCOEDWRCL(idx
),
751 vsi
->fcoe_stat_offsets_loaded
,
752 &ofs
->rx_fcoe_dwords
, &fs
->rx_fcoe_dwords
);
753 i40e_stat_update32(hw
, I40E_GL_FCOERPDC(idx
),
754 vsi
->fcoe_stat_offsets_loaded
,
755 &ofs
->rx_fcoe_dropped
, &fs
->rx_fcoe_dropped
);
756 i40e_stat_update32(hw
, I40E_GL_FCOEPTC(idx
),
757 vsi
->fcoe_stat_offsets_loaded
,
758 &ofs
->tx_fcoe_packets
, &fs
->tx_fcoe_packets
);
759 i40e_stat_update48(hw
, I40E_GL_FCOEDWTCH(idx
), I40E_GL_FCOEDWTCL(idx
),
760 vsi
->fcoe_stat_offsets_loaded
,
761 &ofs
->tx_fcoe_dwords
, &fs
->tx_fcoe_dwords
);
762 i40e_stat_update32(hw
, I40E_GL_FCOECRC(idx
),
763 vsi
->fcoe_stat_offsets_loaded
,
764 &ofs
->fcoe_bad_fccrc
, &fs
->fcoe_bad_fccrc
);
765 i40e_stat_update32(hw
, I40E_GL_FCOELAST(idx
),
766 vsi
->fcoe_stat_offsets_loaded
,
767 &ofs
->fcoe_last_error
, &fs
->fcoe_last_error
);
768 i40e_stat_update32(hw
, I40E_GL_FCOEDDPC(idx
),
769 vsi
->fcoe_stat_offsets_loaded
,
770 &ofs
->fcoe_ddp_count
, &fs
->fcoe_ddp_count
);
772 vsi
->fcoe_stat_offsets_loaded
= true;
777 * i40e_update_vsi_stats - Update the vsi statistics counters.
778 * @vsi: the VSI to be updated
780 * There are a few instances where we store the same stat in a
781 * couple of different structs. This is partly because we have
782 * the netdev stats that need to be filled out, which is slightly
783 * different from the "eth_stats" defined by the chip and used in
784 * VF communications. We sort it out here.
786 static void i40e_update_vsi_stats(struct i40e_vsi
*vsi
)
788 struct i40e_pf
*pf
= vsi
->back
;
789 struct rtnl_link_stats64
*ons
;
790 struct rtnl_link_stats64
*ns
; /* netdev stats */
791 struct i40e_eth_stats
*oes
;
792 struct i40e_eth_stats
*es
; /* device's eth stats */
793 u32 tx_restart
, tx_busy
;
794 u64 tx_lost_interrupt
;
805 if (test_bit(__I40E_DOWN
, &vsi
->state
) ||
806 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
809 ns
= i40e_get_vsi_stats_struct(vsi
);
810 ons
= &vsi
->net_stats_offsets
;
811 es
= &vsi
->eth_stats
;
812 oes
= &vsi
->eth_stats_offsets
;
814 /* Gather up the netdev and vsi stats that the driver collects
815 * on the fly during packet processing
819 tx_restart
= tx_busy
= tx_linearize
= tx_force_wb
= 0;
820 tx_lost_interrupt
= 0;
824 for (q
= 0; q
< vsi
->num_queue_pairs
; q
++) {
826 p
= ACCESS_ONCE(vsi
->tx_rings
[q
]);
829 start
= u64_stats_fetch_begin_irq(&p
->syncp
);
830 packets
= p
->stats
.packets
;
831 bytes
= p
->stats
.bytes
;
832 } while (u64_stats_fetch_retry_irq(&p
->syncp
, start
));
835 tx_restart
+= p
->tx_stats
.restart_queue
;
836 tx_busy
+= p
->tx_stats
.tx_busy
;
837 tx_linearize
+= p
->tx_stats
.tx_linearize
;
838 tx_force_wb
+= p
->tx_stats
.tx_force_wb
;
839 tx_lost_interrupt
+= p
->tx_stats
.tx_lost_interrupt
;
841 /* Rx queue is part of the same block as Tx queue */
844 start
= u64_stats_fetch_begin_irq(&p
->syncp
);
845 packets
= p
->stats
.packets
;
846 bytes
= p
->stats
.bytes
;
847 } while (u64_stats_fetch_retry_irq(&p
->syncp
, start
));
850 rx_buf
+= p
->rx_stats
.alloc_buff_failed
;
851 rx_page
+= p
->rx_stats
.alloc_page_failed
;
854 vsi
->tx_restart
= tx_restart
;
855 vsi
->tx_busy
= tx_busy
;
856 vsi
->tx_linearize
= tx_linearize
;
857 vsi
->tx_force_wb
= tx_force_wb
;
858 vsi
->tx_lost_interrupt
= tx_lost_interrupt
;
859 vsi
->rx_page_failed
= rx_page
;
860 vsi
->rx_buf_failed
= rx_buf
;
862 ns
->rx_packets
= rx_p
;
864 ns
->tx_packets
= tx_p
;
867 /* update netdev stats from eth stats */
868 i40e_update_eth_stats(vsi
);
869 ons
->tx_errors
= oes
->tx_errors
;
870 ns
->tx_errors
= es
->tx_errors
;
871 ons
->multicast
= oes
->rx_multicast
;
872 ns
->multicast
= es
->rx_multicast
;
873 ons
->rx_dropped
= oes
->rx_discards
;
874 ns
->rx_dropped
= es
->rx_discards
;
875 ons
->tx_dropped
= oes
->tx_discards
;
876 ns
->tx_dropped
= es
->tx_discards
;
878 /* pull in a couple PF stats if this is the main vsi */
879 if (vsi
== pf
->vsi
[pf
->lan_vsi
]) {
880 ns
->rx_crc_errors
= pf
->stats
.crc_errors
;
881 ns
->rx_errors
= pf
->stats
.crc_errors
+ pf
->stats
.illegal_bytes
;
882 ns
->rx_length_errors
= pf
->stats
.rx_length_errors
;
887 * i40e_update_pf_stats - Update the PF statistics counters.
888 * @pf: the PF to be updated
890 static void i40e_update_pf_stats(struct i40e_pf
*pf
)
892 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
893 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
894 struct i40e_hw
*hw
= &pf
->hw
;
898 i40e_stat_update48(hw
, I40E_GLPRT_GORCH(hw
->port
),
899 I40E_GLPRT_GORCL(hw
->port
),
900 pf
->stat_offsets_loaded
,
901 &osd
->eth
.rx_bytes
, &nsd
->eth
.rx_bytes
);
902 i40e_stat_update48(hw
, I40E_GLPRT_GOTCH(hw
->port
),
903 I40E_GLPRT_GOTCL(hw
->port
),
904 pf
->stat_offsets_loaded
,
905 &osd
->eth
.tx_bytes
, &nsd
->eth
.tx_bytes
);
906 i40e_stat_update32(hw
, I40E_GLPRT_RDPC(hw
->port
),
907 pf
->stat_offsets_loaded
,
908 &osd
->eth
.rx_discards
,
909 &nsd
->eth
.rx_discards
);
910 i40e_stat_update48(hw
, I40E_GLPRT_UPRCH(hw
->port
),
911 I40E_GLPRT_UPRCL(hw
->port
),
912 pf
->stat_offsets_loaded
,
913 &osd
->eth
.rx_unicast
,
914 &nsd
->eth
.rx_unicast
);
915 i40e_stat_update48(hw
, I40E_GLPRT_MPRCH(hw
->port
),
916 I40E_GLPRT_MPRCL(hw
->port
),
917 pf
->stat_offsets_loaded
,
918 &osd
->eth
.rx_multicast
,
919 &nsd
->eth
.rx_multicast
);
920 i40e_stat_update48(hw
, I40E_GLPRT_BPRCH(hw
->port
),
921 I40E_GLPRT_BPRCL(hw
->port
),
922 pf
->stat_offsets_loaded
,
923 &osd
->eth
.rx_broadcast
,
924 &nsd
->eth
.rx_broadcast
);
925 i40e_stat_update48(hw
, I40E_GLPRT_UPTCH(hw
->port
),
926 I40E_GLPRT_UPTCL(hw
->port
),
927 pf
->stat_offsets_loaded
,
928 &osd
->eth
.tx_unicast
,
929 &nsd
->eth
.tx_unicast
);
930 i40e_stat_update48(hw
, I40E_GLPRT_MPTCH(hw
->port
),
931 I40E_GLPRT_MPTCL(hw
->port
),
932 pf
->stat_offsets_loaded
,
933 &osd
->eth
.tx_multicast
,
934 &nsd
->eth
.tx_multicast
);
935 i40e_stat_update48(hw
, I40E_GLPRT_BPTCH(hw
->port
),
936 I40E_GLPRT_BPTCL(hw
->port
),
937 pf
->stat_offsets_loaded
,
938 &osd
->eth
.tx_broadcast
,
939 &nsd
->eth
.tx_broadcast
);
941 i40e_stat_update32(hw
, I40E_GLPRT_TDOLD(hw
->port
),
942 pf
->stat_offsets_loaded
,
943 &osd
->tx_dropped_link_down
,
944 &nsd
->tx_dropped_link_down
);
946 i40e_stat_update32(hw
, I40E_GLPRT_CRCERRS(hw
->port
),
947 pf
->stat_offsets_loaded
,
948 &osd
->crc_errors
, &nsd
->crc_errors
);
950 i40e_stat_update32(hw
, I40E_GLPRT_ILLERRC(hw
->port
),
951 pf
->stat_offsets_loaded
,
952 &osd
->illegal_bytes
, &nsd
->illegal_bytes
);
954 i40e_stat_update32(hw
, I40E_GLPRT_MLFC(hw
->port
),
955 pf
->stat_offsets_loaded
,
956 &osd
->mac_local_faults
,
957 &nsd
->mac_local_faults
);
958 i40e_stat_update32(hw
, I40E_GLPRT_MRFC(hw
->port
),
959 pf
->stat_offsets_loaded
,
960 &osd
->mac_remote_faults
,
961 &nsd
->mac_remote_faults
);
963 i40e_stat_update32(hw
, I40E_GLPRT_RLEC(hw
->port
),
964 pf
->stat_offsets_loaded
,
965 &osd
->rx_length_errors
,
966 &nsd
->rx_length_errors
);
968 i40e_stat_update32(hw
, I40E_GLPRT_LXONRXC(hw
->port
),
969 pf
->stat_offsets_loaded
,
970 &osd
->link_xon_rx
, &nsd
->link_xon_rx
);
971 i40e_stat_update32(hw
, I40E_GLPRT_LXONTXC(hw
->port
),
972 pf
->stat_offsets_loaded
,
973 &osd
->link_xon_tx
, &nsd
->link_xon_tx
);
974 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFRXC(hw
->port
),
975 pf
->stat_offsets_loaded
,
976 &osd
->link_xoff_rx
, &nsd
->link_xoff_rx
);
977 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFTXC(hw
->port
),
978 pf
->stat_offsets_loaded
,
979 &osd
->link_xoff_tx
, &nsd
->link_xoff_tx
);
981 for (i
= 0; i
< 8; i
++) {
982 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFRXC(hw
->port
, i
),
983 pf
->stat_offsets_loaded
,
984 &osd
->priority_xoff_rx
[i
],
985 &nsd
->priority_xoff_rx
[i
]);
986 i40e_stat_update32(hw
, I40E_GLPRT_PXONRXC(hw
->port
, i
),
987 pf
->stat_offsets_loaded
,
988 &osd
->priority_xon_rx
[i
],
989 &nsd
->priority_xon_rx
[i
]);
990 i40e_stat_update32(hw
, I40E_GLPRT_PXONTXC(hw
->port
, i
),
991 pf
->stat_offsets_loaded
,
992 &osd
->priority_xon_tx
[i
],
993 &nsd
->priority_xon_tx
[i
]);
994 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFTXC(hw
->port
, i
),
995 pf
->stat_offsets_loaded
,
996 &osd
->priority_xoff_tx
[i
],
997 &nsd
->priority_xoff_tx
[i
]);
998 i40e_stat_update32(hw
,
999 I40E_GLPRT_RXON2OFFCNT(hw
->port
, i
),
1000 pf
->stat_offsets_loaded
,
1001 &osd
->priority_xon_2_xoff
[i
],
1002 &nsd
->priority_xon_2_xoff
[i
]);
1005 i40e_stat_update48(hw
, I40E_GLPRT_PRC64H(hw
->port
),
1006 I40E_GLPRT_PRC64L(hw
->port
),
1007 pf
->stat_offsets_loaded
,
1008 &osd
->rx_size_64
, &nsd
->rx_size_64
);
1009 i40e_stat_update48(hw
, I40E_GLPRT_PRC127H(hw
->port
),
1010 I40E_GLPRT_PRC127L(hw
->port
),
1011 pf
->stat_offsets_loaded
,
1012 &osd
->rx_size_127
, &nsd
->rx_size_127
);
1013 i40e_stat_update48(hw
, I40E_GLPRT_PRC255H(hw
->port
),
1014 I40E_GLPRT_PRC255L(hw
->port
),
1015 pf
->stat_offsets_loaded
,
1016 &osd
->rx_size_255
, &nsd
->rx_size_255
);
1017 i40e_stat_update48(hw
, I40E_GLPRT_PRC511H(hw
->port
),
1018 I40E_GLPRT_PRC511L(hw
->port
),
1019 pf
->stat_offsets_loaded
,
1020 &osd
->rx_size_511
, &nsd
->rx_size_511
);
1021 i40e_stat_update48(hw
, I40E_GLPRT_PRC1023H(hw
->port
),
1022 I40E_GLPRT_PRC1023L(hw
->port
),
1023 pf
->stat_offsets_loaded
,
1024 &osd
->rx_size_1023
, &nsd
->rx_size_1023
);
1025 i40e_stat_update48(hw
, I40E_GLPRT_PRC1522H(hw
->port
),
1026 I40E_GLPRT_PRC1522L(hw
->port
),
1027 pf
->stat_offsets_loaded
,
1028 &osd
->rx_size_1522
, &nsd
->rx_size_1522
);
1029 i40e_stat_update48(hw
, I40E_GLPRT_PRC9522H(hw
->port
),
1030 I40E_GLPRT_PRC9522L(hw
->port
),
1031 pf
->stat_offsets_loaded
,
1032 &osd
->rx_size_big
, &nsd
->rx_size_big
);
1034 i40e_stat_update48(hw
, I40E_GLPRT_PTC64H(hw
->port
),
1035 I40E_GLPRT_PTC64L(hw
->port
),
1036 pf
->stat_offsets_loaded
,
1037 &osd
->tx_size_64
, &nsd
->tx_size_64
);
1038 i40e_stat_update48(hw
, I40E_GLPRT_PTC127H(hw
->port
),
1039 I40E_GLPRT_PTC127L(hw
->port
),
1040 pf
->stat_offsets_loaded
,
1041 &osd
->tx_size_127
, &nsd
->tx_size_127
);
1042 i40e_stat_update48(hw
, I40E_GLPRT_PTC255H(hw
->port
),
1043 I40E_GLPRT_PTC255L(hw
->port
),
1044 pf
->stat_offsets_loaded
,
1045 &osd
->tx_size_255
, &nsd
->tx_size_255
);
1046 i40e_stat_update48(hw
, I40E_GLPRT_PTC511H(hw
->port
),
1047 I40E_GLPRT_PTC511L(hw
->port
),
1048 pf
->stat_offsets_loaded
,
1049 &osd
->tx_size_511
, &nsd
->tx_size_511
);
1050 i40e_stat_update48(hw
, I40E_GLPRT_PTC1023H(hw
->port
),
1051 I40E_GLPRT_PTC1023L(hw
->port
),
1052 pf
->stat_offsets_loaded
,
1053 &osd
->tx_size_1023
, &nsd
->tx_size_1023
);
1054 i40e_stat_update48(hw
, I40E_GLPRT_PTC1522H(hw
->port
),
1055 I40E_GLPRT_PTC1522L(hw
->port
),
1056 pf
->stat_offsets_loaded
,
1057 &osd
->tx_size_1522
, &nsd
->tx_size_1522
);
1058 i40e_stat_update48(hw
, I40E_GLPRT_PTC9522H(hw
->port
),
1059 I40E_GLPRT_PTC9522L(hw
->port
),
1060 pf
->stat_offsets_loaded
,
1061 &osd
->tx_size_big
, &nsd
->tx_size_big
);
1063 i40e_stat_update32(hw
, I40E_GLPRT_RUC(hw
->port
),
1064 pf
->stat_offsets_loaded
,
1065 &osd
->rx_undersize
, &nsd
->rx_undersize
);
1066 i40e_stat_update32(hw
, I40E_GLPRT_RFC(hw
->port
),
1067 pf
->stat_offsets_loaded
,
1068 &osd
->rx_fragments
, &nsd
->rx_fragments
);
1069 i40e_stat_update32(hw
, I40E_GLPRT_ROC(hw
->port
),
1070 pf
->stat_offsets_loaded
,
1071 &osd
->rx_oversize
, &nsd
->rx_oversize
);
1072 i40e_stat_update32(hw
, I40E_GLPRT_RJC(hw
->port
),
1073 pf
->stat_offsets_loaded
,
1074 &osd
->rx_jabber
, &nsd
->rx_jabber
);
1077 i40e_stat_update32(hw
,
1078 I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf
->hw
.pf_id
)),
1079 pf
->stat_offsets_loaded
,
1080 &osd
->fd_atr_match
, &nsd
->fd_atr_match
);
1081 i40e_stat_update32(hw
,
1082 I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf
->hw
.pf_id
)),
1083 pf
->stat_offsets_loaded
,
1084 &osd
->fd_sb_match
, &nsd
->fd_sb_match
);
1085 i40e_stat_update32(hw
,
1086 I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf
->hw
.pf_id
)),
1087 pf
->stat_offsets_loaded
,
1088 &osd
->fd_atr_tunnel_match
, &nsd
->fd_atr_tunnel_match
);
1090 val
= rd32(hw
, I40E_PRTPM_EEE_STAT
);
1091 nsd
->tx_lpi_status
=
1092 (val
& I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK
) >>
1093 I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT
;
1094 nsd
->rx_lpi_status
=
1095 (val
& I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK
) >>
1096 I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT
;
1097 i40e_stat_update32(hw
, I40E_PRTPM_TLPIC
,
1098 pf
->stat_offsets_loaded
,
1099 &osd
->tx_lpi_count
, &nsd
->tx_lpi_count
);
1100 i40e_stat_update32(hw
, I40E_PRTPM_RLPIC
,
1101 pf
->stat_offsets_loaded
,
1102 &osd
->rx_lpi_count
, &nsd
->rx_lpi_count
);
1104 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
&&
1105 !(pf
->auto_disable_flags
& I40E_FLAG_FD_SB_ENABLED
))
1106 nsd
->fd_sb_status
= true;
1108 nsd
->fd_sb_status
= false;
1110 if (pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
&&
1111 !(pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
))
1112 nsd
->fd_atr_status
= true;
1114 nsd
->fd_atr_status
= false;
1116 pf
->stat_offsets_loaded
= true;
1120 * i40e_update_stats - Update the various statistics counters.
1121 * @vsi: the VSI to be updated
1123 * Update the various stats for this VSI and its related entities.
1125 void i40e_update_stats(struct i40e_vsi
*vsi
)
1127 struct i40e_pf
*pf
= vsi
->back
;
1129 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
1130 i40e_update_pf_stats(pf
);
1132 i40e_update_vsi_stats(vsi
);
1134 i40e_update_fcoe_stats(vsi
);
1139 * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
1140 * @vsi: the VSI to be searched
1141 * @macaddr: the MAC address
1144 * Returns ptr to the filter object or NULL
1146 static struct i40e_mac_filter
*i40e_find_filter(struct i40e_vsi
*vsi
,
1147 const u8
*macaddr
, s16 vlan
)
1149 struct i40e_mac_filter
*f
;
1152 if (!vsi
|| !macaddr
)
1155 key
= i40e_addr_to_hkey(macaddr
);
1156 hash_for_each_possible(vsi
->mac_filter_hash
, f
, hlist
, key
) {
1157 if ((ether_addr_equal(macaddr
, f
->macaddr
)) &&
1165 * i40e_find_mac - Find a mac addr in the macvlan filters list
1166 * @vsi: the VSI to be searched
1167 * @macaddr: the MAC address we are searching for
1169 * Returns the first filter with the provided MAC address or NULL if
1170 * MAC address was not found
1172 struct i40e_mac_filter
*i40e_find_mac(struct i40e_vsi
*vsi
, const u8
*macaddr
)
1174 struct i40e_mac_filter
*f
;
1177 if (!vsi
|| !macaddr
)
1180 key
= i40e_addr_to_hkey(macaddr
);
1181 hash_for_each_possible(vsi
->mac_filter_hash
, f
, hlist
, key
) {
1182 if ((ether_addr_equal(macaddr
, f
->macaddr
)))
1189 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1190 * @vsi: the VSI to be searched
1192 * Returns true if VSI is in vlan mode or false otherwise
1194 bool i40e_is_vsi_in_vlan(struct i40e_vsi
*vsi
)
1196 /* If we have a PVID, always operate in VLAN mode */
1200 /* We need to operate in VLAN mode whenever we have any filters with
1201 * a VLAN other than I40E_VLAN_ALL. We could check the table each
1202 * time, incurring search cost repeatedly. However, we can notice two
1205 * 1) the only place where we can gain a VLAN filter is in
1208 * 2) the only place where filters are actually removed is in
1209 * i40e_sync_filters_subtask.
1211 * Thus, we can simply use a boolean value, has_vlan_filters which we
1212 * will set to true when we add a VLAN filter in i40e_add_filter. Then
1213 * we have to perform the full search after deleting filters in
1214 * i40e_sync_filters_subtask, but we already have to search
1215 * filters here and can perform the check at the same time. This
1216 * results in avoiding embedding a loop for VLAN mode inside another
1217 * loop over all the filters, and should maintain correctness as noted
1220 return vsi
->has_vlan_filter
;
1224 * i40e_correct_mac_vlan_filters - Correct non-VLAN filters if necessary
1225 * @vsi: the VSI to configure
1226 * @tmp_add_list: list of filters ready to be added
1227 * @tmp_del_list: list of filters ready to be deleted
1228 * @vlan_filters: the number of active VLAN filters
1230 * Update VLAN=0 and VLAN=-1 (I40E_VLAN_ANY) filters properly so that they
1231 * behave as expected. If we have any active VLAN filters remaining or about
1232 * to be added then we need to update non-VLAN filters to be marked as VLAN=0
1233 * so that they only match against untagged traffic. If we no longer have any
1234 * active VLAN filters, we need to make all non-VLAN filters marked as VLAN=-1
1235 * so that they match against both tagged and untagged traffic. In this way,
1236 * we ensure that we correctly receive the desired traffic. This ensures that
1237 * when we have an active VLAN we will receive only untagged traffic and
1238 * traffic matching active VLANs. If we have no active VLANs then we will
1239 * operate in non-VLAN mode and receive all traffic, tagged or untagged.
1241 * Finally, in a similar fashion, this function also corrects filters when
1242 * there is an active PVID assigned to this VSI.
1244 * In case of memory allocation failure return -ENOMEM. Otherwise, return 0.
1246 * This function is only expected to be called from within
1247 * i40e_sync_vsi_filters.
1249 * NOTE: This function expects to be called while under the
1250 * mac_filter_hash_lock
1252 static int i40e_correct_mac_vlan_filters(struct i40e_vsi
*vsi
,
1253 struct hlist_head
*tmp_add_list
,
1254 struct hlist_head
*tmp_del_list
,
1257 struct i40e_mac_filter
*f
, *add_head
;
1258 struct hlist_node
*h
;
1261 /* To determine if a particular filter needs to be replaced we
1262 * have the three following conditions:
1264 * a) if we have a PVID assigned, then all filters which are
1265 * not marked as VLAN=PVID must be replaced with filters that
1267 * b) otherwise, if we have any active VLANS, all filters
1268 * which are marked as VLAN=-1 must be replaced with
1269 * filters marked as VLAN=0
1270 * c) finally, if we do not have any active VLANS, all filters
1271 * which are marked as VLAN=0 must be replaced with filters
1275 /* Update the filters about to be added in place */
1276 hlist_for_each_entry(f
, tmp_add_list
, hlist
) {
1277 if (vsi
->info
.pvid
&& f
->vlan
!= vsi
->info
.pvid
)
1278 f
->vlan
= vsi
->info
.pvid
;
1279 else if (vlan_filters
&& f
->vlan
== I40E_VLAN_ANY
)
1281 else if (!vlan_filters
&& f
->vlan
== 0)
1282 f
->vlan
= I40E_VLAN_ANY
;
1285 /* Update the remaining active filters */
1286 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
1287 /* Combine the checks for whether a filter needs to be changed
1288 * and then determine the new VLAN inside the if block, in
1289 * order to avoid duplicating code for adding the new filter
1290 * then deleting the old filter.
1292 if ((vsi
->info
.pvid
&& f
->vlan
!= vsi
->info
.pvid
) ||
1293 (vlan_filters
&& f
->vlan
== I40E_VLAN_ANY
) ||
1294 (!vlan_filters
&& f
->vlan
== 0)) {
1295 /* Determine the new vlan we will be adding */
1297 new_vlan
= vsi
->info
.pvid
;
1298 else if (vlan_filters
)
1301 new_vlan
= I40E_VLAN_ANY
;
1303 /* Create the new filter */
1304 add_head
= i40e_add_filter(vsi
, f
->macaddr
, new_vlan
);
1308 /* Put the replacement filter into the add list */
1309 hash_del(&add_head
->hlist
);
1310 hlist_add_head(&add_head
->hlist
, tmp_add_list
);
1312 /* Put the original filter into the delete list */
1313 f
->state
= I40E_FILTER_REMOVE
;
1314 hash_del(&f
->hlist
);
1315 hlist_add_head(&f
->hlist
, tmp_del_list
);
1319 vsi
->has_vlan_filter
= !!vlan_filters
;
1325 * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
1326 * @vsi: the PF Main VSI - inappropriate for any other VSI
1327 * @macaddr: the MAC address
1329 * Remove whatever filter the firmware set up so the driver can manage
1330 * its own filtering intelligently.
1332 static void i40e_rm_default_mac_filter(struct i40e_vsi
*vsi
, u8
*macaddr
)
1334 struct i40e_aqc_remove_macvlan_element_data element
;
1335 struct i40e_pf
*pf
= vsi
->back
;
1337 /* Only appropriate for the PF main VSI */
1338 if (vsi
->type
!= I40E_VSI_MAIN
)
1341 memset(&element
, 0, sizeof(element
));
1342 ether_addr_copy(element
.mac_addr
, macaddr
);
1343 element
.vlan_tag
= 0;
1344 /* Ignore error returns, some firmware does it this way... */
1345 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
1346 i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1348 memset(&element
, 0, sizeof(element
));
1349 ether_addr_copy(element
.mac_addr
, macaddr
);
1350 element
.vlan_tag
= 0;
1351 /* ...and some firmware does it this way. */
1352 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
|
1353 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
1354 i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1358 * i40e_add_filter - Add a mac/vlan filter to the VSI
1359 * @vsi: the VSI to be searched
1360 * @macaddr: the MAC address
1363 * Returns ptr to the filter object or NULL when no memory available.
1365 * NOTE: This function is expected to be called with mac_filter_hash_lock
1368 struct i40e_mac_filter
*i40e_add_filter(struct i40e_vsi
*vsi
,
1369 const u8
*macaddr
, s16 vlan
)
1371 struct i40e_mac_filter
*f
;
1374 if (!vsi
|| !macaddr
)
1377 f
= i40e_find_filter(vsi
, macaddr
, vlan
);
1379 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
1383 /* Update the boolean indicating if we need to function in
1387 vsi
->has_vlan_filter
= true;
1389 ether_addr_copy(f
->macaddr
, macaddr
);
1391 /* If we're in overflow promisc mode, set the state directly
1392 * to failed, so we don't bother to try sending the filter
1395 if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC
, &vsi
->state
))
1396 f
->state
= I40E_FILTER_FAILED
;
1398 f
->state
= I40E_FILTER_NEW
;
1399 INIT_HLIST_NODE(&f
->hlist
);
1401 key
= i40e_addr_to_hkey(macaddr
);
1402 hash_add(vsi
->mac_filter_hash
, &f
->hlist
, key
);
1404 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1405 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1408 /* If we're asked to add a filter that has been marked for removal, it
1409 * is safe to simply restore it to active state. __i40e_del_filter
1410 * will have simply deleted any filters which were previously marked
1411 * NEW or FAILED, so if it is currently marked REMOVE it must have
1412 * previously been ACTIVE. Since we haven't yet run the sync filters
1413 * task, just restore this filter to the ACTIVE state so that the
1414 * sync task leaves it in place
1416 if (f
->state
== I40E_FILTER_REMOVE
)
1417 f
->state
= I40E_FILTER_ACTIVE
;
1423 * __i40e_del_filter - Remove a specific filter from the VSI
1424 * @vsi: VSI to remove from
1425 * @f: the filter to remove from the list
1427 * This function should be called instead of i40e_del_filter only if you know
1428 * the exact filter you will remove already, such as via i40e_find_filter or
1431 * NOTE: This function is expected to be called with mac_filter_hash_lock
1433 * ANOTHER NOTE: This function MUST be called from within the context of
1434 * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
1435 * instead of list_for_each_entry().
1437 void __i40e_del_filter(struct i40e_vsi
*vsi
, struct i40e_mac_filter
*f
)
1442 if ((f
->state
== I40E_FILTER_FAILED
) ||
1443 (f
->state
== I40E_FILTER_NEW
)) {
1444 /* this one never got added by the FW. Just remove it,
1445 * no need to sync anything.
1447 hash_del(&f
->hlist
);
1450 f
->state
= I40E_FILTER_REMOVE
;
1451 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1452 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1457 * i40e_del_filter - Remove a MAC/VLAN filter from the VSI
1458 * @vsi: the VSI to be searched
1459 * @macaddr: the MAC address
1462 * NOTE: This function is expected to be called with mac_filter_hash_lock
1464 * ANOTHER NOTE: This function MUST be called from within the context of
1465 * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
1466 * instead of list_for_each_entry().
1468 void i40e_del_filter(struct i40e_vsi
*vsi
, const u8
*macaddr
, s16 vlan
)
1470 struct i40e_mac_filter
*f
;
1472 if (!vsi
|| !macaddr
)
1475 f
= i40e_find_filter(vsi
, macaddr
, vlan
);
1476 __i40e_del_filter(vsi
, f
);
1480 * i40e_add_mac_filter - Add a MAC filter for all active VLANs
1481 * @vsi: the VSI to be searched
1482 * @macaddr: the mac address to be filtered
1484 * If we're not in VLAN mode, just add the filter to I40E_VLAN_ANY. Otherwise,
1485 * go through all the macvlan filters and add a macvlan filter for each
1486 * unique vlan that already exists. If a PVID has been assigned, instead only
1487 * add the macaddr to that VLAN.
1489 * Returns last filter added on success, else NULL
1491 struct i40e_mac_filter
*i40e_add_mac_filter(struct i40e_vsi
*vsi
,
1494 struct i40e_mac_filter
*f
, *add
= NULL
;
1495 struct hlist_node
*h
;
1499 return i40e_add_filter(vsi
, macaddr
,
1500 le16_to_cpu(vsi
->info
.pvid
));
1502 if (!i40e_is_vsi_in_vlan(vsi
))
1503 return i40e_add_filter(vsi
, macaddr
, I40E_VLAN_ANY
);
1505 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
1506 if (f
->state
== I40E_FILTER_REMOVE
)
1508 add
= i40e_add_filter(vsi
, macaddr
, f
->vlan
);
1517 * i40e_del_mac_filter - Remove a MAC filter from all VLANs
1518 * @vsi: the VSI to be searched
1519 * @macaddr: the mac address to be removed
1521 * Removes a given MAC address from a VSI regardless of what VLAN it has been
1524 * Returns 0 for success, or error
1526 int i40e_del_mac_filter(struct i40e_vsi
*vsi
, const u8
*macaddr
)
1528 struct i40e_mac_filter
*f
;
1529 struct hlist_node
*h
;
1533 WARN(!spin_is_locked(&vsi
->mac_filter_hash_lock
),
1534 "Missing mac_filter_hash_lock\n");
1535 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
1536 if (ether_addr_equal(macaddr
, f
->macaddr
)) {
1537 __i40e_del_filter(vsi
, f
);
1549 * i40e_set_mac - NDO callback to set mac address
1550 * @netdev: network interface device structure
1551 * @p: pointer to an address structure
1553 * Returns 0 on success, negative on failure
1556 int i40e_set_mac(struct net_device
*netdev
, void *p
)
1558 static int i40e_set_mac(struct net_device
*netdev
, void *p
)
1561 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1562 struct i40e_vsi
*vsi
= np
->vsi
;
1563 struct i40e_pf
*pf
= vsi
->back
;
1564 struct i40e_hw
*hw
= &pf
->hw
;
1565 struct sockaddr
*addr
= p
;
1567 if (!is_valid_ether_addr(addr
->sa_data
))
1568 return -EADDRNOTAVAIL
;
1570 if (ether_addr_equal(netdev
->dev_addr
, addr
->sa_data
)) {
1571 netdev_info(netdev
, "already using mac address %pM\n",
1576 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
1577 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
1578 return -EADDRNOTAVAIL
;
1580 if (ether_addr_equal(hw
->mac
.addr
, addr
->sa_data
))
1581 netdev_info(netdev
, "returning to hw mac address %pM\n",
1584 netdev_info(netdev
, "set new mac address %pM\n", addr
->sa_data
);
1586 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
1587 i40e_del_mac_filter(vsi
, netdev
->dev_addr
);
1588 i40e_add_mac_filter(vsi
, addr
->sa_data
);
1589 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
1590 ether_addr_copy(netdev
->dev_addr
, addr
->sa_data
);
1591 if (vsi
->type
== I40E_VSI_MAIN
) {
1594 ret
= i40e_aq_mac_address_write(&vsi
->back
->hw
,
1595 I40E_AQC_WRITE_TYPE_LAA_WOL
,
1596 addr
->sa_data
, NULL
);
1598 netdev_info(netdev
, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n",
1599 i40e_stat_str(hw
, ret
),
1600 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
1603 /* schedule our worker thread which will take care of
1604 * applying the new filter changes
1606 i40e_service_event_schedule(vsi
->back
);
1611 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1612 * @vsi: the VSI being setup
1613 * @ctxt: VSI context structure
1614 * @enabled_tc: Enabled TCs bitmap
1615 * @is_add: True if called before Add VSI
1617 * Setup VSI queue mapping for enabled traffic classes.
1620 void i40e_vsi_setup_queue_map(struct i40e_vsi
*vsi
,
1621 struct i40e_vsi_context
*ctxt
,
1625 static void i40e_vsi_setup_queue_map(struct i40e_vsi
*vsi
,
1626 struct i40e_vsi_context
*ctxt
,
1631 struct i40e_pf
*pf
= vsi
->back
;
1641 sections
= I40E_AQ_VSI_PROP_QUEUE_MAP_VALID
;
1644 if (enabled_tc
&& (vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
1645 /* Find numtc from enabled TC bitmap */
1646 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1647 if (enabled_tc
& BIT(i
)) /* TC is enabled */
1651 dev_warn(&pf
->pdev
->dev
, "DCB is enabled but no TC enabled, forcing TC0\n");
1655 /* At least TC0 is enabled in case of non-DCB case */
1659 vsi
->tc_config
.numtc
= numtc
;
1660 vsi
->tc_config
.enabled_tc
= enabled_tc
? enabled_tc
: 1;
1661 /* Number of queues per enabled TC */
1662 qcount
= vsi
->alloc_queue_pairs
;
1664 num_tc_qps
= qcount
/ numtc
;
1665 num_tc_qps
= min_t(int, num_tc_qps
, i40e_pf_get_max_q_per_tc(pf
));
1667 /* Setup queue offset/count for all TCs for given VSI */
1668 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1669 /* See if the given TC is enabled for the given VSI */
1670 if (vsi
->tc_config
.enabled_tc
& BIT(i
)) {
1674 switch (vsi
->type
) {
1676 qcount
= min_t(int, pf
->alloc_rss_size
,
1681 qcount
= num_tc_qps
;
1685 case I40E_VSI_SRIOV
:
1686 case I40E_VSI_VMDQ2
:
1688 qcount
= num_tc_qps
;
1692 vsi
->tc_config
.tc_info
[i
].qoffset
= offset
;
1693 vsi
->tc_config
.tc_info
[i
].qcount
= qcount
;
1695 /* find the next higher power-of-2 of num queue pairs */
1698 while (num_qps
&& (BIT_ULL(pow
) < qcount
)) {
1703 vsi
->tc_config
.tc_info
[i
].netdev_tc
= netdev_tc
++;
1705 (offset
<< I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT
) |
1706 (pow
<< I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT
);
1710 /* TC is not enabled so set the offset to
1711 * default queue and allocate one queue
1714 vsi
->tc_config
.tc_info
[i
].qoffset
= 0;
1715 vsi
->tc_config
.tc_info
[i
].qcount
= 1;
1716 vsi
->tc_config
.tc_info
[i
].netdev_tc
= 0;
1720 ctxt
->info
.tc_mapping
[i
] = cpu_to_le16(qmap
);
1723 /* Set actual Tx/Rx queue pairs */
1724 vsi
->num_queue_pairs
= offset
;
1725 if ((vsi
->type
== I40E_VSI_MAIN
) && (numtc
== 1)) {
1726 if (vsi
->req_queue_pairs
> 0)
1727 vsi
->num_queue_pairs
= vsi
->req_queue_pairs
;
1728 else if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
1729 vsi
->num_queue_pairs
= pf
->num_lan_msix
;
1732 /* Scheduler section valid can only be set for ADD VSI */
1734 sections
|= I40E_AQ_VSI_PROP_SCHED_VALID
;
1736 ctxt
->info
.up_enable_bits
= enabled_tc
;
1738 if (vsi
->type
== I40E_VSI_SRIOV
) {
1739 ctxt
->info
.mapping_flags
|=
1740 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG
);
1741 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
1742 ctxt
->info
.queue_mapping
[i
] =
1743 cpu_to_le16(vsi
->base_queue
+ i
);
1745 ctxt
->info
.mapping_flags
|=
1746 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG
);
1747 ctxt
->info
.queue_mapping
[0] = cpu_to_le16(vsi
->base_queue
);
1749 ctxt
->info
.valid_sections
|= cpu_to_le16(sections
);
1753 * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address
1754 * @netdev: the netdevice
1755 * @addr: address to add
1757 * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
1758 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
1760 static int i40e_addr_sync(struct net_device
*netdev
, const u8
*addr
)
1762 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1763 struct i40e_vsi
*vsi
= np
->vsi
;
1765 if (i40e_add_mac_filter(vsi
, addr
))
1772 * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
1773 * @netdev: the netdevice
1774 * @addr: address to add
1776 * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
1777 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
1779 static int i40e_addr_unsync(struct net_device
*netdev
, const u8
*addr
)
1781 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1782 struct i40e_vsi
*vsi
= np
->vsi
;
1784 i40e_del_mac_filter(vsi
, addr
);
1790 * i40e_set_rx_mode - NDO callback to set the netdev filters
1791 * @netdev: network interface device structure
1794 void i40e_set_rx_mode(struct net_device
*netdev
)
1796 static void i40e_set_rx_mode(struct net_device
*netdev
)
1799 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1800 struct i40e_vsi
*vsi
= np
->vsi
;
1802 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
1804 __dev_uc_sync(netdev
, i40e_addr_sync
, i40e_addr_unsync
);
1805 __dev_mc_sync(netdev
, i40e_addr_sync
, i40e_addr_unsync
);
1807 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
1809 /* check for other flag changes */
1810 if (vsi
->current_netdev_flags
!= vsi
->netdev
->flags
) {
1811 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1812 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1815 /* schedule our worker thread which will take care of
1816 * applying the new filter changes
1818 i40e_service_event_schedule(vsi
->back
);
1822 * i40e_undo_filter_entries - Undo the changes made to MAC filter entries
1823 * @vsi: Pointer to VSI struct
1824 * @from: Pointer to list which contains MAC filter entries - changes to
1825 * those entries needs to be undone.
1827 * MAC filter entries from list were slated to be sent to firmware, either for
1828 * addition or deletion.
1830 static void i40e_undo_filter_entries(struct i40e_vsi
*vsi
,
1831 struct hlist_head
*from
)
1833 struct i40e_mac_filter
*f
;
1834 struct hlist_node
*h
;
1836 hlist_for_each_entry_safe(f
, h
, from
, hlist
) {
1837 u64 key
= i40e_addr_to_hkey(f
->macaddr
);
1839 /* Move the element back into MAC filter list*/
1840 hlist_del(&f
->hlist
);
1841 hash_add(vsi
->mac_filter_hash
, &f
->hlist
, key
);
1846 * i40e_update_filter_state - Update filter state based on return data
1848 * @count: Number of filters added
1849 * @add_list: return data from fw
1850 * @head: pointer to first filter in current batch
1852 * MAC filter entries from list were slated to be added to device. Returns
1853 * number of successful filters. Note that 0 does NOT mean success!
1856 i40e_update_filter_state(int count
,
1857 struct i40e_aqc_add_macvlan_element_data
*add_list
,
1858 struct i40e_mac_filter
*add_head
)
1863 for (i
= 0; i
< count
; i
++) {
1864 /* Always check status of each filter. We don't need to check
1865 * the firmware return status because we pre-set the filter
1866 * status to I40E_AQC_MM_ERR_NO_RES when sending the filter
1867 * request to the adminq. Thus, if it no longer matches then
1868 * we know the filter is active.
1870 if (add_list
[i
].match_method
== I40E_AQC_MM_ERR_NO_RES
) {
1871 add_head
->state
= I40E_FILTER_FAILED
;
1873 add_head
->state
= I40E_FILTER_ACTIVE
;
1877 add_head
= hlist_entry(add_head
->hlist
.next
,
1878 typeof(struct i40e_mac_filter
),
1886 * i40e_aqc_del_filters - Request firmware to delete a set of filters
1887 * @vsi: ptr to the VSI
1888 * @vsi_name: name to display in messages
1889 * @list: the list of filters to send to firmware
1890 * @num_del: the number of filters to delete
1891 * @retval: Set to -EIO on failure to delete
1893 * Send a request to firmware via AdminQ to delete a set of filters. Uses
1894 * *retval instead of a return value so that success does not force ret_val to
1895 * be set to 0. This ensures that a sequence of calls to this function
1896 * preserve the previous value of *retval on successful delete.
1899 void i40e_aqc_del_filters(struct i40e_vsi
*vsi
, const char *vsi_name
,
1900 struct i40e_aqc_remove_macvlan_element_data
*list
,
1901 int num_del
, int *retval
)
1903 struct i40e_hw
*hw
= &vsi
->back
->hw
;
1907 aq_ret
= i40e_aq_remove_macvlan(hw
, vsi
->seid
, list
, num_del
, NULL
);
1908 aq_err
= hw
->aq
.asq_last_status
;
1910 /* Explicitly ignore and do not report when firmware returns ENOENT */
1911 if (aq_ret
&& !(aq_err
== I40E_AQ_RC_ENOENT
)) {
1913 dev_info(&vsi
->back
->pdev
->dev
,
1914 "ignoring delete macvlan error on %s, err %s, aq_err %s\n",
1915 vsi_name
, i40e_stat_str(hw
, aq_ret
),
1916 i40e_aq_str(hw
, aq_err
));
1921 * i40e_aqc_add_filters - Request firmware to add a set of filters
1922 * @vsi: ptr to the VSI
1923 * @vsi_name: name to display in messages
1924 * @list: the list of filters to send to firmware
1925 * @add_head: Position in the add hlist
1926 * @num_add: the number of filters to add
1927 * @promisc_change: set to true on exit if promiscuous mode was forced on
1929 * Send a request to firmware via AdminQ to add a chunk of filters. Will set
1930 * promisc_changed to true if the firmware has run out of space for more
1934 void i40e_aqc_add_filters(struct i40e_vsi
*vsi
, const char *vsi_name
,
1935 struct i40e_aqc_add_macvlan_element_data
*list
,
1936 struct i40e_mac_filter
*add_head
,
1937 int num_add
, bool *promisc_changed
)
1939 struct i40e_hw
*hw
= &vsi
->back
->hw
;
1942 i40e_aq_add_macvlan(hw
, vsi
->seid
, list
, num_add
, NULL
);
1943 aq_err
= hw
->aq
.asq_last_status
;
1944 fcnt
= i40e_update_filter_state(num_add
, list
, add_head
);
1946 if (fcnt
!= num_add
) {
1947 *promisc_changed
= true;
1948 set_bit(__I40E_FILTER_OVERFLOW_PROMISC
, &vsi
->state
);
1949 dev_warn(&vsi
->back
->pdev
->dev
,
1950 "Error %s adding RX filters on %s, promiscuous mode forced on\n",
1951 i40e_aq_str(hw
, aq_err
),
1957 * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags
1958 * @vsi: pointer to the VSI
1961 * This function sets or clears the promiscuous broadcast flags for VLAN
1962 * filters in order to properly receive broadcast frames. Assumes that only
1963 * broadcast filters are passed.
1966 void i40e_aqc_broadcast_filter(struct i40e_vsi
*vsi
, const char *vsi_name
,
1967 struct i40e_mac_filter
*f
)
1969 bool enable
= f
->state
== I40E_FILTER_NEW
;
1970 struct i40e_hw
*hw
= &vsi
->back
->hw
;
1973 if (f
->vlan
== I40E_VLAN_ANY
) {
1974 aq_ret
= i40e_aq_set_vsi_broadcast(hw
,
1979 aq_ret
= i40e_aq_set_vsi_bc_promisc_on_vlan(hw
,
1987 dev_warn(&vsi
->back
->pdev
->dev
,
1988 "Error %s setting broadcast promiscuous mode on %s\n",
1989 i40e_aq_str(hw
, hw
->aq
.asq_last_status
),
1991 f
->state
= I40E_FILTER_FAILED
;
1992 } else if (enable
) {
1993 f
->state
= I40E_FILTER_ACTIVE
;
1998 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
1999 * @vsi: ptr to the VSI
2001 * Push any outstanding VSI filter changes through the AdminQ.
2003 * Returns 0 or error value
2005 int i40e_sync_vsi_filters(struct i40e_vsi
*vsi
)
2007 struct hlist_head tmp_add_list
, tmp_del_list
;
2008 struct i40e_mac_filter
*f
, *add_head
= NULL
;
2009 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2010 unsigned int failed_filters
= 0;
2011 unsigned int vlan_filters
= 0;
2012 bool promisc_changed
= false;
2013 char vsi_name
[16] = "PF";
2014 int filter_list_len
= 0;
2015 i40e_status aq_ret
= 0;
2016 u32 changed_flags
= 0;
2017 struct hlist_node
*h
;
2026 /* empty array typed pointers, kcalloc later */
2027 struct i40e_aqc_add_macvlan_element_data
*add_list
;
2028 struct i40e_aqc_remove_macvlan_element_data
*del_list
;
2030 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &vsi
->state
))
2031 usleep_range(1000, 2000);
2035 changed_flags
= vsi
->current_netdev_flags
^ vsi
->netdev
->flags
;
2036 vsi
->current_netdev_flags
= vsi
->netdev
->flags
;
2039 INIT_HLIST_HEAD(&tmp_add_list
);
2040 INIT_HLIST_HEAD(&tmp_del_list
);
2042 if (vsi
->type
== I40E_VSI_SRIOV
)
2043 snprintf(vsi_name
, sizeof(vsi_name
) - 1, "VF %d", vsi
->vf_id
);
2044 else if (vsi
->type
!= I40E_VSI_MAIN
)
2045 snprintf(vsi_name
, sizeof(vsi_name
) - 1, "vsi %d", vsi
->seid
);
2047 if (vsi
->flags
& I40E_VSI_FLAG_FILTER_CHANGED
) {
2048 vsi
->flags
&= ~I40E_VSI_FLAG_FILTER_CHANGED
;
2050 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2051 /* Create a list of filters to delete. */
2052 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
2053 if (f
->state
== I40E_FILTER_REMOVE
) {
2054 /* Move the element into temporary del_list */
2055 hash_del(&f
->hlist
);
2056 hlist_add_head(&f
->hlist
, &tmp_del_list
);
2058 /* Avoid counting removed filters */
2061 if (f
->state
== I40E_FILTER_NEW
) {
2062 hash_del(&f
->hlist
);
2063 hlist_add_head(&f
->hlist
, &tmp_add_list
);
2066 /* Count the number of active (current and new) VLAN
2067 * filters we have now. Does not count filters which
2068 * are marked for deletion.
2074 retval
= i40e_correct_mac_vlan_filters(vsi
,
2079 goto err_no_memory_locked
;
2081 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2084 /* Now process 'del_list' outside the lock */
2085 if (!hlist_empty(&tmp_del_list
)) {
2086 filter_list_len
= hw
->aq
.asq_buf_size
/
2087 sizeof(struct i40e_aqc_remove_macvlan_element_data
);
2088 list_size
= filter_list_len
*
2089 sizeof(struct i40e_aqc_remove_macvlan_element_data
);
2090 del_list
= kzalloc(list_size
, GFP_ATOMIC
);
2094 hlist_for_each_entry_safe(f
, h
, &tmp_del_list
, hlist
) {
2097 /* handle broadcast filters by updating the broadcast
2098 * promiscuous flag instead of deleting a MAC filter.
2100 if (is_broadcast_ether_addr(f
->macaddr
)) {
2101 i40e_aqc_broadcast_filter(vsi
, vsi_name
, f
);
2103 hlist_del(&f
->hlist
);
2108 /* add to delete list */
2109 ether_addr_copy(del_list
[num_del
].mac_addr
, f
->macaddr
);
2110 if (f
->vlan
== I40E_VLAN_ANY
) {
2111 del_list
[num_del
].vlan_tag
= 0;
2112 cmd_flags
|= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
2114 del_list
[num_del
].vlan_tag
=
2115 cpu_to_le16((u16
)(f
->vlan
));
2118 cmd_flags
|= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
2119 del_list
[num_del
].flags
= cmd_flags
;
2122 /* flush a full buffer */
2123 if (num_del
== filter_list_len
) {
2124 i40e_aqc_del_filters(vsi
, vsi_name
, del_list
,
2126 memset(del_list
, 0, list_size
);
2129 /* Release memory for MAC filter entries which were
2130 * synced up with HW.
2132 hlist_del(&f
->hlist
);
2137 i40e_aqc_del_filters(vsi
, vsi_name
, del_list
,
2145 if (!hlist_empty(&tmp_add_list
)) {
2146 /* Do all the adds now. */
2147 filter_list_len
= hw
->aq
.asq_buf_size
/
2148 sizeof(struct i40e_aqc_add_macvlan_element_data
);
2149 list_size
= filter_list_len
*
2150 sizeof(struct i40e_aqc_add_macvlan_element_data
);
2151 add_list
= kzalloc(list_size
, GFP_ATOMIC
);
2156 hlist_for_each_entry_safe(f
, h
, &tmp_add_list
, hlist
) {
2157 if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
2159 f
->state
= I40E_FILTER_FAILED
;
2163 /* handle broadcast filters by updating the broadcast
2164 * promiscuous flag instead of adding a MAC filter.
2166 if (is_broadcast_ether_addr(f
->macaddr
)) {
2167 u64 key
= i40e_addr_to_hkey(f
->macaddr
);
2168 i40e_aqc_broadcast_filter(vsi
, vsi_name
, f
);
2170 hlist_del(&f
->hlist
);
2171 hash_add(vsi
->mac_filter_hash
, &f
->hlist
, key
);
2175 /* add to add array */
2179 ether_addr_copy(add_list
[num_add
].mac_addr
, f
->macaddr
);
2180 if (f
->vlan
== I40E_VLAN_ANY
) {
2181 add_list
[num_add
].vlan_tag
= 0;
2182 cmd_flags
|= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN
;
2184 add_list
[num_add
].vlan_tag
=
2185 cpu_to_le16((u16
)(f
->vlan
));
2187 add_list
[num_add
].queue_number
= 0;
2188 /* set invalid match method for later detection */
2189 add_list
[num_add
].match_method
= I40E_AQC_MM_ERR_NO_RES
;
2190 cmd_flags
|= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
;
2191 add_list
[num_add
].flags
= cpu_to_le16(cmd_flags
);
2194 /* flush a full buffer */
2195 if (num_add
== filter_list_len
) {
2196 i40e_aqc_add_filters(vsi
, vsi_name
, add_list
,
2199 memset(add_list
, 0, list_size
);
2204 i40e_aqc_add_filters(vsi
, vsi_name
, add_list
, add_head
,
2205 num_add
, &promisc_changed
);
2207 /* Now move all of the filters from the temp add list back to
2210 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2211 hlist_for_each_entry_safe(f
, h
, &tmp_add_list
, hlist
) {
2212 u64 key
= i40e_addr_to_hkey(f
->macaddr
);
2214 hlist_del(&f
->hlist
);
2215 hash_add(vsi
->mac_filter_hash
, &f
->hlist
, key
);
2217 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2222 /* Determine the number of active and failed filters. */
2223 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2224 vsi
->active_filters
= 0;
2225 hash_for_each(vsi
->mac_filter_hash
, bkt
, f
, hlist
) {
2226 if (f
->state
== I40E_FILTER_ACTIVE
)
2227 vsi
->active_filters
++;
2228 else if (f
->state
== I40E_FILTER_FAILED
)
2231 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2233 /* If promiscuous mode has changed, we need to calculate a new
2234 * threshold for when we are safe to exit
2236 if (promisc_changed
)
2237 vsi
->promisc_threshold
= (vsi
->active_filters
* 3) / 4;
2239 /* Check if we are able to exit overflow promiscuous mode. We can
2240 * safely exit if we didn't just enter, we no longer have any failed
2241 * filters, and we have reduced filters below the threshold value.
2243 if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC
, &vsi
->state
) &&
2244 !promisc_changed
&& !failed_filters
&&
2245 (vsi
->active_filters
< vsi
->promisc_threshold
)) {
2246 dev_info(&pf
->pdev
->dev
,
2247 "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
2249 clear_bit(__I40E_FILTER_OVERFLOW_PROMISC
, &vsi
->state
);
2250 promisc_changed
= true;
2251 vsi
->promisc_threshold
= 0;
2254 /* if the VF is not trusted do not do promisc */
2255 if ((vsi
->type
== I40E_VSI_SRIOV
) && !pf
->vf
[vsi
->vf_id
].trusted
) {
2256 clear_bit(__I40E_FILTER_OVERFLOW_PROMISC
, &vsi
->state
);
2260 /* check for changes in promiscuous modes */
2261 if (changed_flags
& IFF_ALLMULTI
) {
2262 bool cur_multipromisc
;
2264 cur_multipromisc
= !!(vsi
->current_netdev_flags
& IFF_ALLMULTI
);
2265 aq_ret
= i40e_aq_set_vsi_multicast_promiscuous(&vsi
->back
->hw
,
2270 retval
= i40e_aq_rc_to_posix(aq_ret
,
2271 hw
->aq
.asq_last_status
);
2272 dev_info(&pf
->pdev
->dev
,
2273 "set multi promisc failed on %s, err %s aq_err %s\n",
2275 i40e_stat_str(hw
, aq_ret
),
2276 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
2279 if ((changed_flags
& IFF_PROMISC
) ||
2281 test_bit(__I40E_FILTER_OVERFLOW_PROMISC
, &vsi
->state
))) {
2284 cur_promisc
= (!!(vsi
->current_netdev_flags
& IFF_PROMISC
) ||
2285 test_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
2287 if ((vsi
->type
== I40E_VSI_MAIN
) &&
2288 (pf
->lan_veb
!= I40E_NO_VEB
) &&
2289 !(pf
->flags
& I40E_FLAG_MFP_ENABLED
)) {
2290 /* set defport ON for Main VSI instead of true promisc
2291 * this way we will get all unicast/multicast and VLAN
2292 * promisc behavior but will not get VF or VMDq traffic
2293 * replicated on the Main VSI.
2295 if (pf
->cur_promisc
!= cur_promisc
) {
2296 pf
->cur_promisc
= cur_promisc
;
2299 i40e_aq_set_default_vsi(hw
,
2304 i40e_aq_clear_default_vsi(hw
,
2308 retval
= i40e_aq_rc_to_posix(aq_ret
,
2309 hw
->aq
.asq_last_status
);
2310 dev_info(&pf
->pdev
->dev
,
2311 "Set default VSI failed on %s, err %s, aq_err %s\n",
2313 i40e_stat_str(hw
, aq_ret
),
2315 hw
->aq
.asq_last_status
));
2319 aq_ret
= i40e_aq_set_vsi_unicast_promiscuous(
2326 i40e_aq_rc_to_posix(aq_ret
,
2327 hw
->aq
.asq_last_status
);
2328 dev_info(&pf
->pdev
->dev
,
2329 "set unicast promisc failed on %s, err %s, aq_err %s\n",
2331 i40e_stat_str(hw
, aq_ret
),
2333 hw
->aq
.asq_last_status
));
2335 aq_ret
= i40e_aq_set_vsi_multicast_promiscuous(
2341 i40e_aq_rc_to_posix(aq_ret
,
2342 hw
->aq
.asq_last_status
);
2343 dev_info(&pf
->pdev
->dev
,
2344 "set multicast promisc failed on %s, err %s, aq_err %s\n",
2346 i40e_stat_str(hw
, aq_ret
),
2348 hw
->aq
.asq_last_status
));
2351 aq_ret
= i40e_aq_set_vsi_broadcast(&vsi
->back
->hw
,
2355 retval
= i40e_aq_rc_to_posix(aq_ret
,
2356 pf
->hw
.aq
.asq_last_status
);
2357 dev_info(&pf
->pdev
->dev
,
2358 "set brdcast promisc failed, err %s, aq_err %s\n",
2359 i40e_stat_str(hw
, aq_ret
),
2361 hw
->aq
.asq_last_status
));
2365 /* if something went wrong then set the changed flag so we try again */
2367 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
2369 clear_bit(__I40E_CONFIG_BUSY
, &vsi
->state
);
2373 /* Restore elements on the temporary add and delete lists */
2374 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2375 err_no_memory_locked
:
2376 i40e_undo_filter_entries(vsi
, &tmp_del_list
);
2377 i40e_undo_filter_entries(vsi
, &tmp_add_list
);
2378 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2380 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
2381 clear_bit(__I40E_CONFIG_BUSY
, &vsi
->state
);
2386 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
2387 * @pf: board private structure
2389 static void i40e_sync_filters_subtask(struct i40e_pf
*pf
)
2393 if (!pf
|| !(pf
->flags
& I40E_FLAG_FILTER_SYNC
))
2395 pf
->flags
&= ~I40E_FLAG_FILTER_SYNC
;
2397 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
2399 (pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_FILTER_CHANGED
)) {
2400 int ret
= i40e_sync_vsi_filters(pf
->vsi
[v
]);
2403 /* come back and try again later */
2404 pf
->flags
|= I40E_FLAG_FILTER_SYNC
;
2412 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
2413 * @netdev: network interface device structure
2414 * @new_mtu: new value for maximum frame size
2416 * Returns 0 on success, negative on failure
2418 static int i40e_change_mtu(struct net_device
*netdev
, int new_mtu
)
2420 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2421 struct i40e_vsi
*vsi
= np
->vsi
;
2423 netdev_info(netdev
, "changing MTU from %d to %d\n",
2424 netdev
->mtu
, new_mtu
);
2425 netdev
->mtu
= new_mtu
;
2426 if (netif_running(netdev
))
2427 i40e_vsi_reinit_locked(vsi
);
2428 i40e_notify_client_of_l2_param_changes(vsi
);
2433 * i40e_ioctl - Access the hwtstamp interface
2434 * @netdev: network interface device structure
2435 * @ifr: interface request data
2436 * @cmd: ioctl command
2438 int i40e_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
2440 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2441 struct i40e_pf
*pf
= np
->vsi
->back
;
2445 return i40e_ptp_get_ts_config(pf
, ifr
);
2447 return i40e_ptp_set_ts_config(pf
, ifr
);
2454 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
2455 * @vsi: the vsi being adjusted
2457 void i40e_vlan_stripping_enable(struct i40e_vsi
*vsi
)
2459 struct i40e_vsi_context ctxt
;
2462 if ((vsi
->info
.valid_sections
&
2463 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
2464 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_MODE_MASK
) == 0))
2465 return; /* already enabled */
2467 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2468 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
2469 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH
;
2471 ctxt
.seid
= vsi
->seid
;
2472 ctxt
.info
= vsi
->info
;
2473 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2475 dev_info(&vsi
->back
->pdev
->dev
,
2476 "update vlan stripping failed, err %s aq_err %s\n",
2477 i40e_stat_str(&vsi
->back
->hw
, ret
),
2478 i40e_aq_str(&vsi
->back
->hw
,
2479 vsi
->back
->hw
.aq
.asq_last_status
));
2484 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2485 * @vsi: the vsi being adjusted
2487 void i40e_vlan_stripping_disable(struct i40e_vsi
*vsi
)
2489 struct i40e_vsi_context ctxt
;
2492 if ((vsi
->info
.valid_sections
&
2493 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
2494 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_EMOD_MASK
) ==
2495 I40E_AQ_VSI_PVLAN_EMOD_MASK
))
2496 return; /* already disabled */
2498 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2499 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
2500 I40E_AQ_VSI_PVLAN_EMOD_NOTHING
;
2502 ctxt
.seid
= vsi
->seid
;
2503 ctxt
.info
= vsi
->info
;
2504 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2506 dev_info(&vsi
->back
->pdev
->dev
,
2507 "update vlan stripping failed, err %s aq_err %s\n",
2508 i40e_stat_str(&vsi
->back
->hw
, ret
),
2509 i40e_aq_str(&vsi
->back
->hw
,
2510 vsi
->back
->hw
.aq
.asq_last_status
));
2515 * i40e_vlan_rx_register - Setup or shutdown vlan offload
2516 * @netdev: network interface to be adjusted
2517 * @features: netdev features to test if VLAN offload is enabled or not
2519 static void i40e_vlan_rx_register(struct net_device
*netdev
, u32 features
)
2521 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2522 struct i40e_vsi
*vsi
= np
->vsi
;
2524 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
2525 i40e_vlan_stripping_enable(vsi
);
2527 i40e_vlan_stripping_disable(vsi
);
2531 * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address
2532 * @vsi: the vsi being configured
2533 * @vid: vlan id to be added (0 = untagged only , -1 = any)
2535 * This is a helper function for adding a new MAC/VLAN filter with the
2536 * specified VLAN for each existing MAC address already in the hash table.
2537 * This function does *not* perform any accounting to update filters based on
2540 * NOTE: this function expects to be called while under the
2541 * mac_filter_hash_lock
2543 int i40e_add_vlan_all_mac(struct i40e_vsi
*vsi
, s16 vid
)
2545 struct i40e_mac_filter
*f
, *add_f
;
2546 struct hlist_node
*h
;
2549 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
2550 if (f
->state
== I40E_FILTER_REMOVE
)
2552 add_f
= i40e_add_filter(vsi
, f
->macaddr
, vid
);
2554 dev_info(&vsi
->back
->pdev
->dev
,
2555 "Could not add vlan filter %d for %pM\n",
2565 * i40e_vsi_add_vlan - Add VSI membership for given VLAN
2566 * @vsi: the VSI being configured
2567 * @vid: VLAN id to be added
2569 int i40e_vsi_add_vlan(struct i40e_vsi
*vsi
, u16 vid
)
2573 if (!vid
|| vsi
->info
.pvid
)
2576 /* Locked once because all functions invoked below iterates list*/
2577 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2578 err
= i40e_add_vlan_all_mac(vsi
, vid
);
2579 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2583 /* schedule our worker thread which will take care of
2584 * applying the new filter changes
2586 i40e_service_event_schedule(vsi
->back
);
2591 * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN
2592 * @vsi: the vsi being configured
2593 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
2595 * This function should be used to remove all VLAN filters which match the
2596 * given VID. It does not schedule the service event and does not take the
2597 * mac_filter_hash_lock so it may be combined with other operations under
2598 * a single invocation of the mac_filter_hash_lock.
2600 * NOTE: this function expects to be called while under the
2601 * mac_filter_hash_lock
2603 void i40e_rm_vlan_all_mac(struct i40e_vsi
*vsi
, s16 vid
)
2605 struct i40e_mac_filter
*f
;
2606 struct hlist_node
*h
;
2609 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
2611 __i40e_del_filter(vsi
, f
);
2616 * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN
2617 * @vsi: the VSI being configured
2618 * @vid: VLAN id to be removed
2620 void i40e_vsi_kill_vlan(struct i40e_vsi
*vsi
, u16 vid
)
2622 if (!vid
|| vsi
->info
.pvid
)
2625 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2626 i40e_rm_vlan_all_mac(vsi
, vid
);
2627 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2629 /* schedule our worker thread which will take care of
2630 * applying the new filter changes
2632 i40e_service_event_schedule(vsi
->back
);
2636 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2637 * @netdev: network interface to be adjusted
2638 * @vid: vlan id to be added
2640 * net_device_ops implementation for adding vlan ids
2643 int i40e_vlan_rx_add_vid(struct net_device
*netdev
,
2644 __always_unused __be16 proto
, u16 vid
)
2646 static int i40e_vlan_rx_add_vid(struct net_device
*netdev
,
2647 __always_unused __be16 proto
, u16 vid
)
2650 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2651 struct i40e_vsi
*vsi
= np
->vsi
;
2654 if (vid
>= VLAN_N_VID
)
2657 /* If the network stack called us with vid = 0 then
2658 * it is asking to receive priority tagged packets with
2659 * vlan id 0. Our HW receives them by default when configured
2660 * to receive untagged packets so there is no need to add an
2661 * extra filter for vlan 0 tagged packets.
2664 ret
= i40e_vsi_add_vlan(vsi
, vid
);
2667 set_bit(vid
, vsi
->active_vlans
);
2673 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2674 * @netdev: network interface to be adjusted
2675 * @vid: vlan id to be removed
2677 * net_device_ops implementation for removing vlan ids
2680 int i40e_vlan_rx_kill_vid(struct net_device
*netdev
,
2681 __always_unused __be16 proto
, u16 vid
)
2683 static int i40e_vlan_rx_kill_vid(struct net_device
*netdev
,
2684 __always_unused __be16 proto
, u16 vid
)
2687 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2688 struct i40e_vsi
*vsi
= np
->vsi
;
2690 /* return code is ignored as there is nothing a user
2691 * can do about failure to remove and a log message was
2692 * already printed from the other function
2694 i40e_vsi_kill_vlan(vsi
, vid
);
2696 clear_bit(vid
, vsi
->active_vlans
);
2702 * i40e_macaddr_init - explicitly write the mac address filters
2704 * @vsi: pointer to the vsi
2705 * @macaddr: the MAC address
2707 * This is needed when the macaddr has been obtained by other
2708 * means than the default, e.g., from Open Firmware or IDPROM.
2709 * Returns 0 on success, negative on failure
2711 static int i40e_macaddr_init(struct i40e_vsi
*vsi
, u8
*macaddr
)
2714 struct i40e_aqc_add_macvlan_element_data element
;
2716 ret
= i40e_aq_mac_address_write(&vsi
->back
->hw
,
2717 I40E_AQC_WRITE_TYPE_LAA_WOL
,
2720 dev_info(&vsi
->back
->pdev
->dev
,
2721 "Addr change for VSI failed: %d\n", ret
);
2722 return -EADDRNOTAVAIL
;
2725 memset(&element
, 0, sizeof(element
));
2726 ether_addr_copy(element
.mac_addr
, macaddr
);
2727 element
.flags
= cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
);
2728 ret
= i40e_aq_add_macvlan(&vsi
->back
->hw
, vsi
->seid
, &element
, 1, NULL
);
2730 dev_info(&vsi
->back
->pdev
->dev
,
2731 "add filter failed err %s aq_err %s\n",
2732 i40e_stat_str(&vsi
->back
->hw
, ret
),
2733 i40e_aq_str(&vsi
->back
->hw
,
2734 vsi
->back
->hw
.aq
.asq_last_status
));
2740 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2741 * @vsi: the vsi being brought back up
2743 static void i40e_restore_vlan(struct i40e_vsi
*vsi
)
2750 i40e_vlan_rx_register(vsi
->netdev
, vsi
->netdev
->features
);
2752 for_each_set_bit(vid
, vsi
->active_vlans
, VLAN_N_VID
)
2753 i40e_vlan_rx_add_vid(vsi
->netdev
, htons(ETH_P_8021Q
),
2758 * i40e_vsi_add_pvid - Add pvid for the VSI
2759 * @vsi: the vsi being adjusted
2760 * @vid: the vlan id to set as a PVID
2762 int i40e_vsi_add_pvid(struct i40e_vsi
*vsi
, u16 vid
)
2764 struct i40e_vsi_context ctxt
;
2767 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2768 vsi
->info
.pvid
= cpu_to_le16(vid
);
2769 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_TAGGED
|
2770 I40E_AQ_VSI_PVLAN_INSERT_PVID
|
2771 I40E_AQ_VSI_PVLAN_EMOD_STR
;
2773 ctxt
.seid
= vsi
->seid
;
2774 ctxt
.info
= vsi
->info
;
2775 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2777 dev_info(&vsi
->back
->pdev
->dev
,
2778 "add pvid failed, err %s aq_err %s\n",
2779 i40e_stat_str(&vsi
->back
->hw
, ret
),
2780 i40e_aq_str(&vsi
->back
->hw
,
2781 vsi
->back
->hw
.aq
.asq_last_status
));
2789 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2790 * @vsi: the vsi being adjusted
2792 * Just use the vlan_rx_register() service to put it back to normal
2794 void i40e_vsi_remove_pvid(struct i40e_vsi
*vsi
)
2796 i40e_vlan_stripping_disable(vsi
);
2802 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2803 * @vsi: ptr to the VSI
2805 * If this function returns with an error, then it's possible one or
2806 * more of the rings is populated (while the rest are not). It is the
2807 * callers duty to clean those orphaned rings.
2809 * Return 0 on success, negative on failure
2811 static int i40e_vsi_setup_tx_resources(struct i40e_vsi
*vsi
)
2815 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2816 err
= i40e_setup_tx_descriptors(vsi
->tx_rings
[i
]);
2822 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2823 * @vsi: ptr to the VSI
2825 * Free VSI's transmit software resources
2827 static void i40e_vsi_free_tx_resources(struct i40e_vsi
*vsi
)
2834 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2835 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
)
2836 i40e_free_tx_resources(vsi
->tx_rings
[i
]);
2840 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2841 * @vsi: ptr to the VSI
2843 * If this function returns with an error, then it's possible one or
2844 * more of the rings is populated (while the rest are not). It is the
2845 * callers duty to clean those orphaned rings.
2847 * Return 0 on success, negative on failure
2849 static int i40e_vsi_setup_rx_resources(struct i40e_vsi
*vsi
)
2853 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2854 err
= i40e_setup_rx_descriptors(vsi
->rx_rings
[i
]);
2856 i40e_fcoe_setup_ddp_resources(vsi
);
2862 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2863 * @vsi: ptr to the VSI
2865 * Free all receive software resources
2867 static void i40e_vsi_free_rx_resources(struct i40e_vsi
*vsi
)
2874 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2875 if (vsi
->rx_rings
[i
] && vsi
->rx_rings
[i
]->desc
)
2876 i40e_free_rx_resources(vsi
->rx_rings
[i
]);
2878 i40e_fcoe_free_ddp_resources(vsi
);
2883 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
2884 * @ring: The Tx ring to configure
2886 * This enables/disables XPS for a given Tx descriptor ring
2887 * based on the TCs enabled for the VSI that ring belongs to.
2889 static void i40e_config_xps_tx_ring(struct i40e_ring
*ring
)
2891 struct i40e_vsi
*vsi
= ring
->vsi
;
2894 if (!ring
->q_vector
|| !ring
->netdev
)
2897 /* Single TC mode enable XPS */
2898 if (vsi
->tc_config
.numtc
<= 1) {
2899 if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE
, &ring
->state
))
2900 netif_set_xps_queue(ring
->netdev
,
2901 &ring
->q_vector
->affinity_mask
,
2903 } else if (alloc_cpumask_var(&mask
, GFP_KERNEL
)) {
2904 /* Disable XPS to allow selection based on TC */
2905 bitmap_zero(cpumask_bits(mask
), nr_cpumask_bits
);
2906 netif_set_xps_queue(ring
->netdev
, mask
, ring
->queue_index
);
2907 free_cpumask_var(mask
);
2910 /* schedule our worker thread which will take care of
2911 * applying the new filter changes
2913 i40e_service_event_schedule(vsi
->back
);
2917 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2918 * @ring: The Tx ring to configure
2920 * Configure the Tx descriptor ring in the HMC context.
2922 static int i40e_configure_tx_ring(struct i40e_ring
*ring
)
2924 struct i40e_vsi
*vsi
= ring
->vsi
;
2925 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
2926 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2927 struct i40e_hmc_obj_txq tx_ctx
;
2928 i40e_status err
= 0;
2931 /* some ATR related tx ring init */
2932 if (vsi
->back
->flags
& I40E_FLAG_FD_ATR_ENABLED
) {
2933 ring
->atr_sample_rate
= vsi
->back
->atr_sample_rate
;
2934 ring
->atr_count
= 0;
2936 ring
->atr_sample_rate
= 0;
2940 i40e_config_xps_tx_ring(ring
);
2942 /* clear the context structure first */
2943 memset(&tx_ctx
, 0, sizeof(tx_ctx
));
2945 tx_ctx
.new_context
= 1;
2946 tx_ctx
.base
= (ring
->dma
/ 128);
2947 tx_ctx
.qlen
= ring
->count
;
2948 tx_ctx
.fd_ena
= !!(vsi
->back
->flags
& (I40E_FLAG_FD_SB_ENABLED
|
2949 I40E_FLAG_FD_ATR_ENABLED
));
2951 tx_ctx
.fc_ena
= (vsi
->type
== I40E_VSI_FCOE
);
2953 tx_ctx
.timesync_ena
= !!(vsi
->back
->flags
& I40E_FLAG_PTP
);
2954 /* FDIR VSI tx ring can still use RS bit and writebacks */
2955 if (vsi
->type
!= I40E_VSI_FDIR
)
2956 tx_ctx
.head_wb_ena
= 1;
2957 tx_ctx
.head_wb_addr
= ring
->dma
+
2958 (ring
->count
* sizeof(struct i40e_tx_desc
));
2960 /* As part of VSI creation/update, FW allocates certain
2961 * Tx arbitration queue sets for each TC enabled for
2962 * the VSI. The FW returns the handles to these queue
2963 * sets as part of the response buffer to Add VSI,
2964 * Update VSI, etc. AQ commands. It is expected that
2965 * these queue set handles be associated with the Tx
2966 * queues by the driver as part of the TX queue context
2967 * initialization. This has to be done regardless of
2968 * DCB as by default everything is mapped to TC0.
2970 tx_ctx
.rdylist
= le16_to_cpu(vsi
->info
.qs_handle
[ring
->dcb_tc
]);
2971 tx_ctx
.rdylist_act
= 0;
2973 /* clear the context in the HMC */
2974 err
= i40e_clear_lan_tx_queue_context(hw
, pf_q
);
2976 dev_info(&vsi
->back
->pdev
->dev
,
2977 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2978 ring
->queue_index
, pf_q
, err
);
2982 /* set the context in the HMC */
2983 err
= i40e_set_lan_tx_queue_context(hw
, pf_q
, &tx_ctx
);
2985 dev_info(&vsi
->back
->pdev
->dev
,
2986 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
2987 ring
->queue_index
, pf_q
, err
);
2991 /* Now associate this queue with this PCI function */
2992 if (vsi
->type
== I40E_VSI_VMDQ2
) {
2993 qtx_ctl
= I40E_QTX_CTL_VM_QUEUE
;
2994 qtx_ctl
|= ((vsi
->id
) << I40E_QTX_CTL_VFVM_INDX_SHIFT
) &
2995 I40E_QTX_CTL_VFVM_INDX_MASK
;
2997 qtx_ctl
= I40E_QTX_CTL_PF_QUEUE
;
3000 qtx_ctl
|= ((hw
->pf_id
<< I40E_QTX_CTL_PF_INDX_SHIFT
) &
3001 I40E_QTX_CTL_PF_INDX_MASK
);
3002 wr32(hw
, I40E_QTX_CTL(pf_q
), qtx_ctl
);
3005 /* cache tail off for easier writes later */
3006 ring
->tail
= hw
->hw_addr
+ I40E_QTX_TAIL(pf_q
);
3012 * i40e_configure_rx_ring - Configure a receive ring context
3013 * @ring: The Rx ring to configure
3015 * Configure the Rx descriptor ring in the HMC context.
3017 static int i40e_configure_rx_ring(struct i40e_ring
*ring
)
3019 struct i40e_vsi
*vsi
= ring
->vsi
;
3020 u32 chain_len
= vsi
->back
->hw
.func_caps
.rx_buf_chain_len
;
3021 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
3022 struct i40e_hw
*hw
= &vsi
->back
->hw
;
3023 struct i40e_hmc_obj_rxq rx_ctx
;
3024 i40e_status err
= 0;
3028 /* clear the context structure first */
3029 memset(&rx_ctx
, 0, sizeof(rx_ctx
));
3031 ring
->rx_buf_len
= vsi
->rx_buf_len
;
3033 rx_ctx
.dbuff
= ring
->rx_buf_len
>> I40E_RXQ_CTX_DBUFF_SHIFT
;
3035 rx_ctx
.base
= (ring
->dma
/ 128);
3036 rx_ctx
.qlen
= ring
->count
;
3038 /* use 32 byte descriptors */
3041 /* descriptor type is always zero
3044 rx_ctx
.hsplit_0
= 0;
3046 rx_ctx
.rxmax
= min_t(u16
, vsi
->max_frame
, chain_len
* ring
->rx_buf_len
);
3047 if (hw
->revision_id
== 0)
3048 rx_ctx
.lrxqthresh
= 0;
3050 rx_ctx
.lrxqthresh
= 2;
3051 rx_ctx
.crcstrip
= 1;
3053 /* this controls whether VLAN is stripped from inner headers */
3056 rx_ctx
.fc_ena
= (vsi
->type
== I40E_VSI_FCOE
);
3058 /* set the prefena field to 1 because the manual says to */
3061 /* clear the context in the HMC */
3062 err
= i40e_clear_lan_rx_queue_context(hw
, pf_q
);
3064 dev_info(&vsi
->back
->pdev
->dev
,
3065 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
3066 ring
->queue_index
, pf_q
, err
);
3070 /* set the context in the HMC */
3071 err
= i40e_set_lan_rx_queue_context(hw
, pf_q
, &rx_ctx
);
3073 dev_info(&vsi
->back
->pdev
->dev
,
3074 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
3075 ring
->queue_index
, pf_q
, err
);
3079 /* cache tail for quicker writes, and clear the reg before use */
3080 ring
->tail
= hw
->hw_addr
+ I40E_QRX_TAIL(pf_q
);
3081 writel(0, ring
->tail
);
3083 i40e_alloc_rx_buffers(ring
, I40E_DESC_UNUSED(ring
));
3089 * i40e_vsi_configure_tx - Configure the VSI for Tx
3090 * @vsi: VSI structure describing this set of rings and resources
3092 * Configure the Tx VSI for operation.
3094 static int i40e_vsi_configure_tx(struct i40e_vsi
*vsi
)
3099 for (i
= 0; (i
< vsi
->num_queue_pairs
) && !err
; i
++)
3100 err
= i40e_configure_tx_ring(vsi
->tx_rings
[i
]);
3106 * i40e_vsi_configure_rx - Configure the VSI for Rx
3107 * @vsi: the VSI being configured
3109 * Configure the Rx VSI for operation.
3111 static int i40e_vsi_configure_rx(struct i40e_vsi
*vsi
)
3116 if (vsi
->netdev
&& (vsi
->netdev
->mtu
> ETH_DATA_LEN
))
3117 vsi
->max_frame
= vsi
->netdev
->mtu
+ ETH_HLEN
3118 + ETH_FCS_LEN
+ VLAN_HLEN
;
3120 vsi
->max_frame
= I40E_RXBUFFER_2048
;
3122 vsi
->rx_buf_len
= I40E_RXBUFFER_2048
;
3125 /* setup rx buffer for FCoE */
3126 if ((vsi
->type
== I40E_VSI_FCOE
) &&
3127 (vsi
->back
->flags
& I40E_FLAG_FCOE_ENABLED
)) {
3128 vsi
->rx_buf_len
= I40E_RXBUFFER_3072
;
3129 vsi
->max_frame
= I40E_RXBUFFER_3072
;
3132 #endif /* I40E_FCOE */
3133 /* round up for the chip's needs */
3134 vsi
->rx_buf_len
= ALIGN(vsi
->rx_buf_len
,
3135 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT
));
3137 /* set up individual rings */
3138 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
3139 err
= i40e_configure_rx_ring(vsi
->rx_rings
[i
]);
3145 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
3146 * @vsi: ptr to the VSI
3148 static void i40e_vsi_config_dcb_rings(struct i40e_vsi
*vsi
)
3150 struct i40e_ring
*tx_ring
, *rx_ring
;
3151 u16 qoffset
, qcount
;
3154 if (!(vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
3155 /* Reset the TC information */
3156 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
3157 rx_ring
= vsi
->rx_rings
[i
];
3158 tx_ring
= vsi
->tx_rings
[i
];
3159 rx_ring
->dcb_tc
= 0;
3160 tx_ring
->dcb_tc
= 0;
3164 for (n
= 0; n
< I40E_MAX_TRAFFIC_CLASS
; n
++) {
3165 if (!(vsi
->tc_config
.enabled_tc
& BIT_ULL(n
)))
3168 qoffset
= vsi
->tc_config
.tc_info
[n
].qoffset
;
3169 qcount
= vsi
->tc_config
.tc_info
[n
].qcount
;
3170 for (i
= qoffset
; i
< (qoffset
+ qcount
); i
++) {
3171 rx_ring
= vsi
->rx_rings
[i
];
3172 tx_ring
= vsi
->tx_rings
[i
];
3173 rx_ring
->dcb_tc
= n
;
3174 tx_ring
->dcb_tc
= n
;
3180 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
3181 * @vsi: ptr to the VSI
3183 static void i40e_set_vsi_rx_mode(struct i40e_vsi
*vsi
)
3185 struct i40e_pf
*pf
= vsi
->back
;
3189 i40e_set_rx_mode(vsi
->netdev
);
3191 if (!!(pf
->flags
& I40E_FLAG_PF_MAC
)) {
3192 err
= i40e_macaddr_init(vsi
, pf
->hw
.mac
.addr
);
3194 dev_warn(&pf
->pdev
->dev
,
3195 "could not set up macaddr; err %d\n", err
);
3201 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
3202 * @vsi: Pointer to the targeted VSI
3204 * This function replays the hlist on the hw where all the SB Flow Director
3205 * filters were saved.
3207 static void i40e_fdir_filter_restore(struct i40e_vsi
*vsi
)
3209 struct i40e_fdir_filter
*filter
;
3210 struct i40e_pf
*pf
= vsi
->back
;
3211 struct hlist_node
*node
;
3213 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
3216 hlist_for_each_entry_safe(filter
, node
,
3217 &pf
->fdir_filter_list
, fdir_node
) {
3218 i40e_add_del_fdir(vsi
, filter
, true);
3223 * i40e_vsi_configure - Set up the VSI for action
3224 * @vsi: the VSI being configured
3226 static int i40e_vsi_configure(struct i40e_vsi
*vsi
)
3230 i40e_set_vsi_rx_mode(vsi
);
3231 i40e_restore_vlan(vsi
);
3232 i40e_vsi_config_dcb_rings(vsi
);
3233 err
= i40e_vsi_configure_tx(vsi
);
3235 err
= i40e_vsi_configure_rx(vsi
);
3241 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
3242 * @vsi: the VSI being configured
3244 static void i40e_vsi_configure_msix(struct i40e_vsi
*vsi
)
3246 struct i40e_pf
*pf
= vsi
->back
;
3247 struct i40e_hw
*hw
= &pf
->hw
;
3252 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
3253 * and PFINT_LNKLSTn registers, e.g.:
3254 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
3256 qp
= vsi
->base_queue
;
3257 vector
= vsi
->base_vector
;
3258 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vector
++) {
3259 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[i
];
3261 q_vector
->itr_countdown
= ITR_COUNTDOWN_START
;
3262 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_rings
[i
]->rx_itr_setting
);
3263 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
3264 wr32(hw
, I40E_PFINT_ITRN(I40E_RX_ITR
, vector
- 1),
3266 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_rings
[i
]->tx_itr_setting
);
3267 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
3268 wr32(hw
, I40E_PFINT_ITRN(I40E_TX_ITR
, vector
- 1),
3270 wr32(hw
, I40E_PFINT_RATEN(vector
- 1),
3271 i40e_intrl_usec_to_reg(vsi
->int_rate_limit
));
3273 /* Linked list for the queuepairs assigned to this vector */
3274 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), qp
);
3275 for (q
= 0; q
< q_vector
->num_ringpairs
; q
++) {
3278 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3279 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
3280 (vector
<< I40E_QINT_RQCTL_MSIX_INDX_SHIFT
) |
3281 (qp
<< I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT
)|
3283 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT
);
3285 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
3287 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3288 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
3289 (vector
<< I40E_QINT_TQCTL_MSIX_INDX_SHIFT
) |
3290 ((qp
+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
)|
3292 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
3294 /* Terminate the linked list */
3295 if (q
== (q_vector
->num_ringpairs
- 1))
3296 val
|= (I40E_QUEUE_END_OF_LIST
3297 << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
3299 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
3308 * i40e_enable_misc_int_causes - enable the non-queue interrupts
3309 * @hw: ptr to the hardware info
3311 static void i40e_enable_misc_int_causes(struct i40e_pf
*pf
)
3313 struct i40e_hw
*hw
= &pf
->hw
;
3316 /* clear things first */
3317 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0); /* disable all */
3318 rd32(hw
, I40E_PFINT_ICR0
); /* read to clear */
3320 val
= I40E_PFINT_ICR0_ENA_ECC_ERR_MASK
|
3321 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
|
3322 I40E_PFINT_ICR0_ENA_GRST_MASK
|
3323 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK
|
3324 I40E_PFINT_ICR0_ENA_GPIO_MASK
|
3325 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK
|
3326 I40E_PFINT_ICR0_ENA_VFLR_MASK
|
3327 I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
3329 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
)
3330 val
|= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
;
3332 if (pf
->flags
& I40E_FLAG_PTP
)
3333 val
|= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
3335 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
3337 /* SW_ITR_IDX = 0, but don't change INTENA */
3338 wr32(hw
, I40E_PFINT_DYN_CTL0
, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK
|
3339 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK
);
3341 /* OTHER_ITR_IDX = 0 */
3342 wr32(hw
, I40E_PFINT_STAT_CTL0
, 0);
3346 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
3347 * @vsi: the VSI being configured
3349 static void i40e_configure_msi_and_legacy(struct i40e_vsi
*vsi
)
3351 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[0];
3352 struct i40e_pf
*pf
= vsi
->back
;
3353 struct i40e_hw
*hw
= &pf
->hw
;
3356 /* set the ITR configuration */
3357 q_vector
->itr_countdown
= ITR_COUNTDOWN_START
;
3358 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_rings
[0]->rx_itr_setting
);
3359 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
3360 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), q_vector
->rx
.itr
);
3361 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_rings
[0]->tx_itr_setting
);
3362 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
3363 wr32(hw
, I40E_PFINT_ITR0(I40E_TX_ITR
), q_vector
->tx
.itr
);
3365 i40e_enable_misc_int_causes(pf
);
3367 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
3368 wr32(hw
, I40E_PFINT_LNKLST0
, 0);
3370 /* Associate the queue pair to the vector and enable the queue int */
3371 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3372 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
3373 (I40E_QUEUE_TYPE_TX
<< I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
3375 wr32(hw
, I40E_QINT_RQCTL(0), val
);
3377 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3378 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
3379 (I40E_QUEUE_END_OF_LIST
<< I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
3381 wr32(hw
, I40E_QINT_TQCTL(0), val
);
3386 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
3387 * @pf: board private structure
3389 void i40e_irq_dynamic_disable_icr0(struct i40e_pf
*pf
)
3391 struct i40e_hw
*hw
= &pf
->hw
;
3393 wr32(hw
, I40E_PFINT_DYN_CTL0
,
3394 I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
);
3399 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
3400 * @pf: board private structure
3401 * @clearpba: true when all pending interrupt events should be cleared
3403 void i40e_irq_dynamic_enable_icr0(struct i40e_pf
*pf
, bool clearpba
)
3405 struct i40e_hw
*hw
= &pf
->hw
;
3408 val
= I40E_PFINT_DYN_CTL0_INTENA_MASK
|
3409 (clearpba
? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK
: 0) |
3410 (I40E_ITR_NONE
<< I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT
);
3412 wr32(hw
, I40E_PFINT_DYN_CTL0
, val
);
3417 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
3418 * @irq: interrupt number
3419 * @data: pointer to a q_vector
3421 static irqreturn_t
i40e_msix_clean_rings(int irq
, void *data
)
3423 struct i40e_q_vector
*q_vector
= data
;
3425 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
3428 napi_schedule_irqoff(&q_vector
->napi
);
3434 * i40e_irq_affinity_notify - Callback for affinity changes
3435 * @notify: context as to what irq was changed
3436 * @mask: the new affinity mask
3438 * This is a callback function used by the irq_set_affinity_notifier function
3439 * so that we may register to receive changes to the irq affinity masks.
3441 static void i40e_irq_affinity_notify(struct irq_affinity_notify
*notify
,
3442 const cpumask_t
*mask
)
3444 struct i40e_q_vector
*q_vector
=
3445 container_of(notify
, struct i40e_q_vector
, affinity_notify
);
3447 q_vector
->affinity_mask
= *mask
;
3451 * i40e_irq_affinity_release - Callback for affinity notifier release
3452 * @ref: internal core kernel usage
3454 * This is a callback function used by the irq_set_affinity_notifier function
3455 * to inform the current notification subscriber that they will no longer
3456 * receive notifications.
3458 static void i40e_irq_affinity_release(struct kref
*ref
) {}
3461 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3462 * @vsi: the VSI being configured
3463 * @basename: name for the vector
3465 * Allocates MSI-X vectors and requests interrupts from the kernel.
3467 static int i40e_vsi_request_irq_msix(struct i40e_vsi
*vsi
, char *basename
)
3469 int q_vectors
= vsi
->num_q_vectors
;
3470 struct i40e_pf
*pf
= vsi
->back
;
3471 int base
= vsi
->base_vector
;
3477 for (vector
= 0; vector
< q_vectors
; vector
++) {
3478 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[vector
];
3480 irq_num
= pf
->msix_entries
[base
+ vector
].vector
;
3482 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
3483 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3484 "%s-%s-%d", basename
, "TxRx", rx_int_idx
++);
3486 } else if (q_vector
->rx
.ring
) {
3487 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3488 "%s-%s-%d", basename
, "rx", rx_int_idx
++);
3489 } else if (q_vector
->tx
.ring
) {
3490 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3491 "%s-%s-%d", basename
, "tx", tx_int_idx
++);
3493 /* skip this unused q_vector */
3496 err
= request_irq(irq_num
,
3502 dev_info(&pf
->pdev
->dev
,
3503 "MSIX request_irq failed, error: %d\n", err
);
3504 goto free_queue_irqs
;
3507 /* register for affinity change notifications */
3508 q_vector
->affinity_notify
.notify
= i40e_irq_affinity_notify
;
3509 q_vector
->affinity_notify
.release
= i40e_irq_affinity_release
;
3510 irq_set_affinity_notifier(irq_num
, &q_vector
->affinity_notify
);
3511 /* assign the mask for this irq */
3512 irq_set_affinity_hint(irq_num
, &q_vector
->affinity_mask
);
3515 vsi
->irqs_ready
= true;
3521 irq_num
= pf
->msix_entries
[base
+ vector
].vector
;
3522 irq_set_affinity_notifier(irq_num
, NULL
);
3523 irq_set_affinity_hint(irq_num
, NULL
);
3524 free_irq(irq_num
, &vsi
->q_vectors
[vector
]);
3530 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3531 * @vsi: the VSI being un-configured
3533 static void i40e_vsi_disable_irq(struct i40e_vsi
*vsi
)
3535 struct i40e_pf
*pf
= vsi
->back
;
3536 struct i40e_hw
*hw
= &pf
->hw
;
3537 int base
= vsi
->base_vector
;
3540 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
3541 wr32(hw
, I40E_QINT_TQCTL(vsi
->tx_rings
[i
]->reg_idx
), 0);
3542 wr32(hw
, I40E_QINT_RQCTL(vsi
->rx_rings
[i
]->reg_idx
), 0);
3545 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3546 for (i
= vsi
->base_vector
;
3547 i
< (vsi
->num_q_vectors
+ vsi
->base_vector
); i
++)
3548 wr32(hw
, I40E_PFINT_DYN_CTLN(i
- 1), 0);
3551 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3552 synchronize_irq(pf
->msix_entries
[i
+ base
].vector
);
3554 /* Legacy and MSI mode - this stops all interrupt handling */
3555 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0);
3556 wr32(hw
, I40E_PFINT_DYN_CTL0
, 0);
3558 synchronize_irq(pf
->pdev
->irq
);
3563 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3564 * @vsi: the VSI being configured
3566 static int i40e_vsi_enable_irq(struct i40e_vsi
*vsi
)
3568 struct i40e_pf
*pf
= vsi
->back
;
3571 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3572 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3573 i40e_irq_dynamic_enable(vsi
, i
);
3575 i40e_irq_dynamic_enable_icr0(pf
, true);
3578 i40e_flush(&pf
->hw
);
3583 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
3584 * @pf: board private structure
3586 static void i40e_stop_misc_vector(struct i40e_pf
*pf
)
3589 wr32(&pf
->hw
, I40E_PFINT_ICR0_ENA
, 0);
3590 i40e_flush(&pf
->hw
);
3594 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3595 * @irq: interrupt number
3596 * @data: pointer to a q_vector
3598 * This is the handler used for all MSI/Legacy interrupts, and deals
3599 * with both queue and non-queue interrupts. This is also used in
3600 * MSIX mode to handle the non-queue interrupts.
3602 static irqreturn_t
i40e_intr(int irq
, void *data
)
3604 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
3605 struct i40e_hw
*hw
= &pf
->hw
;
3606 irqreturn_t ret
= IRQ_NONE
;
3607 u32 icr0
, icr0_remaining
;
3610 icr0
= rd32(hw
, I40E_PFINT_ICR0
);
3611 ena_mask
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
3613 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
3614 if ((icr0
& I40E_PFINT_ICR0_INTEVENT_MASK
) == 0)
3617 /* if interrupt but no bits showing, must be SWINT */
3618 if (((icr0
& ~I40E_PFINT_ICR0_INTEVENT_MASK
) == 0) ||
3619 (icr0
& I40E_PFINT_ICR0_SWINT_MASK
))
3622 if ((pf
->flags
& I40E_FLAG_IWARP_ENABLED
) &&
3623 (ena_mask
& I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
)) {
3624 ena_mask
&= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
;
3625 icr0
&= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
;
3626 dev_dbg(&pf
->pdev
->dev
, "cleared PE_CRITERR\n");
3629 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
3630 if (icr0
& I40E_PFINT_ICR0_QUEUE_0_MASK
) {
3631 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
3632 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[0];
3634 /* We do not have a way to disarm Queue causes while leaving
3635 * interrupt enabled for all other causes, ideally
3636 * interrupt should be disabled while we are in NAPI but
3637 * this is not a performance path and napi_schedule()
3638 * can deal with rescheduling.
3640 if (!test_bit(__I40E_DOWN
, &pf
->state
))
3641 napi_schedule_irqoff(&q_vector
->napi
);
3644 if (icr0
& I40E_PFINT_ICR0_ADMINQ_MASK
) {
3645 ena_mask
&= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
3646 set_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
);
3647 i40e_debug(&pf
->hw
, I40E_DEBUG_NVM
, "AdminQ event\n");
3650 if (icr0
& I40E_PFINT_ICR0_MAL_DETECT_MASK
) {
3651 ena_mask
&= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
3652 set_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
);
3655 if (icr0
& I40E_PFINT_ICR0_VFLR_MASK
) {
3656 ena_mask
&= ~I40E_PFINT_ICR0_ENA_VFLR_MASK
;
3657 set_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
);
3660 if (icr0
& I40E_PFINT_ICR0_GRST_MASK
) {
3661 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
))
3662 set_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
);
3663 ena_mask
&= ~I40E_PFINT_ICR0_ENA_GRST_MASK
;
3664 val
= rd32(hw
, I40E_GLGEN_RSTAT
);
3665 val
= (val
& I40E_GLGEN_RSTAT_RESET_TYPE_MASK
)
3666 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT
;
3667 if (val
== I40E_RESET_CORER
) {
3669 } else if (val
== I40E_RESET_GLOBR
) {
3671 } else if (val
== I40E_RESET_EMPR
) {
3673 set_bit(__I40E_EMP_RESET_INTR_RECEIVED
, &pf
->state
);
3677 if (icr0
& I40E_PFINT_ICR0_HMC_ERR_MASK
) {
3678 icr0
&= ~I40E_PFINT_ICR0_HMC_ERR_MASK
;
3679 dev_info(&pf
->pdev
->dev
, "HMC error interrupt\n");
3680 dev_info(&pf
->pdev
->dev
, "HMC error info 0x%x, HMC error data 0x%x\n",
3681 rd32(hw
, I40E_PFHMC_ERRORINFO
),
3682 rd32(hw
, I40E_PFHMC_ERRORDATA
));
3685 if (icr0
& I40E_PFINT_ICR0_TIMESYNC_MASK
) {
3686 u32 prttsyn_stat
= rd32(hw
, I40E_PRTTSYN_STAT_0
);
3688 if (prttsyn_stat
& I40E_PRTTSYN_STAT_0_TXTIME_MASK
) {
3689 icr0
&= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
3690 i40e_ptp_tx_hwtstamp(pf
);
3694 /* If a critical error is pending we have no choice but to reset the
3696 * Report and mask out any remaining unexpected interrupts.
3698 icr0_remaining
= icr0
& ena_mask
;
3699 if (icr0_remaining
) {
3700 dev_info(&pf
->pdev
->dev
, "unhandled interrupt icr0=0x%08x\n",
3702 if ((icr0_remaining
& I40E_PFINT_ICR0_PE_CRITERR_MASK
) ||
3703 (icr0_remaining
& I40E_PFINT_ICR0_PCI_EXCEPTION_MASK
) ||
3704 (icr0_remaining
& I40E_PFINT_ICR0_ECC_ERR_MASK
)) {
3705 dev_info(&pf
->pdev
->dev
, "device will be reset\n");
3706 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
3707 i40e_service_event_schedule(pf
);
3709 ena_mask
&= ~icr0_remaining
;
3714 /* re-enable interrupt causes */
3715 wr32(hw
, I40E_PFINT_ICR0_ENA
, ena_mask
);
3716 if (!test_bit(__I40E_DOWN
, &pf
->state
)) {
3717 i40e_service_event_schedule(pf
);
3718 i40e_irq_dynamic_enable_icr0(pf
, false);
3725 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3726 * @tx_ring: tx ring to clean
3727 * @budget: how many cleans we're allowed
3729 * Returns true if there's any budget left (e.g. the clean is finished)
3731 static bool i40e_clean_fdir_tx_irq(struct i40e_ring
*tx_ring
, int budget
)
3733 struct i40e_vsi
*vsi
= tx_ring
->vsi
;
3734 u16 i
= tx_ring
->next_to_clean
;
3735 struct i40e_tx_buffer
*tx_buf
;
3736 struct i40e_tx_desc
*tx_desc
;
3738 tx_buf
= &tx_ring
->tx_bi
[i
];
3739 tx_desc
= I40E_TX_DESC(tx_ring
, i
);
3740 i
-= tx_ring
->count
;
3743 struct i40e_tx_desc
*eop_desc
= tx_buf
->next_to_watch
;
3745 /* if next_to_watch is not set then there is no work pending */
3749 /* prevent any other reads prior to eop_desc */
3750 read_barrier_depends();
3752 /* if the descriptor isn't done, no work yet to do */
3753 if (!(eop_desc
->cmd_type_offset_bsz
&
3754 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE
)))
3757 /* clear next_to_watch to prevent false hangs */
3758 tx_buf
->next_to_watch
= NULL
;
3760 tx_desc
->buffer_addr
= 0;
3761 tx_desc
->cmd_type_offset_bsz
= 0;
3762 /* move past filter desc */
3767 i
-= tx_ring
->count
;
3768 tx_buf
= tx_ring
->tx_bi
;
3769 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
3771 /* unmap skb header data */
3772 dma_unmap_single(tx_ring
->dev
,
3773 dma_unmap_addr(tx_buf
, dma
),
3774 dma_unmap_len(tx_buf
, len
),
3776 if (tx_buf
->tx_flags
& I40E_TX_FLAGS_FD_SB
)
3777 kfree(tx_buf
->raw_buf
);
3779 tx_buf
->raw_buf
= NULL
;
3780 tx_buf
->tx_flags
= 0;
3781 tx_buf
->next_to_watch
= NULL
;
3782 dma_unmap_len_set(tx_buf
, len
, 0);
3783 tx_desc
->buffer_addr
= 0;
3784 tx_desc
->cmd_type_offset_bsz
= 0;
3786 /* move us past the eop_desc for start of next FD desc */
3791 i
-= tx_ring
->count
;
3792 tx_buf
= tx_ring
->tx_bi
;
3793 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
3796 /* update budget accounting */
3798 } while (likely(budget
));
3800 i
+= tx_ring
->count
;
3801 tx_ring
->next_to_clean
= i
;
3803 if (vsi
->back
->flags
& I40E_FLAG_MSIX_ENABLED
)
3804 i40e_irq_dynamic_enable(vsi
, tx_ring
->q_vector
->v_idx
);
3810 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
3811 * @irq: interrupt number
3812 * @data: pointer to a q_vector
3814 static irqreturn_t
i40e_fdir_clean_ring(int irq
, void *data
)
3816 struct i40e_q_vector
*q_vector
= data
;
3817 struct i40e_vsi
*vsi
;
3819 if (!q_vector
->tx
.ring
)
3822 vsi
= q_vector
->tx
.ring
->vsi
;
3823 i40e_clean_fdir_tx_irq(q_vector
->tx
.ring
, vsi
->work_limit
);
3829 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
3830 * @vsi: the VSI being configured
3831 * @v_idx: vector index
3832 * @qp_idx: queue pair index
3834 static void i40e_map_vector_to_qp(struct i40e_vsi
*vsi
, int v_idx
, int qp_idx
)
3836 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
3837 struct i40e_ring
*tx_ring
= vsi
->tx_rings
[qp_idx
];
3838 struct i40e_ring
*rx_ring
= vsi
->rx_rings
[qp_idx
];
3840 tx_ring
->q_vector
= q_vector
;
3841 tx_ring
->next
= q_vector
->tx
.ring
;
3842 q_vector
->tx
.ring
= tx_ring
;
3843 q_vector
->tx
.count
++;
3845 rx_ring
->q_vector
= q_vector
;
3846 rx_ring
->next
= q_vector
->rx
.ring
;
3847 q_vector
->rx
.ring
= rx_ring
;
3848 q_vector
->rx
.count
++;
3852 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
3853 * @vsi: the VSI being configured
3855 * This function maps descriptor rings to the queue-specific vectors
3856 * we were allotted through the MSI-X enabling code. Ideally, we'd have
3857 * one vector per queue pair, but on a constrained vector budget, we
3858 * group the queue pairs as "efficiently" as possible.
3860 static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi
*vsi
)
3862 int qp_remaining
= vsi
->num_queue_pairs
;
3863 int q_vectors
= vsi
->num_q_vectors
;
3868 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
3869 * group them so there are multiple queues per vector.
3870 * It is also important to go through all the vectors available to be
3871 * sure that if we don't use all the vectors, that the remaining vectors
3872 * are cleared. This is especially important when decreasing the
3873 * number of queues in use.
3875 for (; v_start
< q_vectors
; v_start
++) {
3876 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_start
];
3878 num_ringpairs
= DIV_ROUND_UP(qp_remaining
, q_vectors
- v_start
);
3880 q_vector
->num_ringpairs
= num_ringpairs
;
3882 q_vector
->rx
.count
= 0;
3883 q_vector
->tx
.count
= 0;
3884 q_vector
->rx
.ring
= NULL
;
3885 q_vector
->tx
.ring
= NULL
;
3887 while (num_ringpairs
--) {
3888 i40e_map_vector_to_qp(vsi
, v_start
, qp_idx
);
3896 * i40e_vsi_request_irq - Request IRQ from the OS
3897 * @vsi: the VSI being configured
3898 * @basename: name for the vector
3900 static int i40e_vsi_request_irq(struct i40e_vsi
*vsi
, char *basename
)
3902 struct i40e_pf
*pf
= vsi
->back
;
3905 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
3906 err
= i40e_vsi_request_irq_msix(vsi
, basename
);
3907 else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
)
3908 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, 0,
3911 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, IRQF_SHARED
,
3915 dev_info(&pf
->pdev
->dev
, "request_irq failed, Error %d\n", err
);
3920 #ifdef CONFIG_NET_POLL_CONTROLLER
3922 * i40e_netpoll - A Polling 'interrupt' handler
3923 * @netdev: network interface device structure
3925 * This is used by netconsole to send skbs without having to re-enable
3926 * interrupts. It's not called while the normal interrupt routine is executing.
3929 void i40e_netpoll(struct net_device
*netdev
)
3931 static void i40e_netpoll(struct net_device
*netdev
)
3934 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3935 struct i40e_vsi
*vsi
= np
->vsi
;
3936 struct i40e_pf
*pf
= vsi
->back
;
3939 /* if interface is down do nothing */
3940 if (test_bit(__I40E_DOWN
, &vsi
->state
))
3943 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3944 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3945 i40e_msix_clean_rings(0, vsi
->q_vectors
[i
]);
3947 i40e_intr(pf
->pdev
->irq
, netdev
);
3953 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
3954 * @pf: the PF being configured
3955 * @pf_q: the PF queue
3956 * @enable: enable or disable state of the queue
3958 * This routine will wait for the given Tx queue of the PF to reach the
3959 * enabled or disabled state.
3960 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3961 * multiple retries; else will return 0 in case of success.
3963 static int i40e_pf_txq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
3968 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
3969 tx_reg
= rd32(&pf
->hw
, I40E_QTX_ENA(pf_q
));
3970 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
3973 usleep_range(10, 20);
3975 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
3982 * i40e_vsi_control_tx - Start or stop a VSI's rings
3983 * @vsi: the VSI being configured
3984 * @enable: start or stop the rings
3986 static int i40e_vsi_control_tx(struct i40e_vsi
*vsi
, bool enable
)
3988 struct i40e_pf
*pf
= vsi
->back
;
3989 struct i40e_hw
*hw
= &pf
->hw
;
3990 int i
, j
, pf_q
, ret
= 0;
3993 pf_q
= vsi
->base_queue
;
3994 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
3996 /* warn the TX unit of coming changes */
3997 i40e_pre_tx_queue_cfg(&pf
->hw
, pf_q
, enable
);
3999 usleep_range(10, 20);
4001 for (j
= 0; j
< 50; j
++) {
4002 tx_reg
= rd32(hw
, I40E_QTX_ENA(pf_q
));
4003 if (((tx_reg
>> I40E_QTX_ENA_QENA_REQ_SHIFT
) & 1) ==
4004 ((tx_reg
>> I40E_QTX_ENA_QENA_STAT_SHIFT
) & 1))
4006 usleep_range(1000, 2000);
4008 /* Skip if the queue is already in the requested state */
4009 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
4012 /* turn on/off the queue */
4014 wr32(hw
, I40E_QTX_HEAD(pf_q
), 0);
4015 tx_reg
|= I40E_QTX_ENA_QENA_REQ_MASK
;
4017 tx_reg
&= ~I40E_QTX_ENA_QENA_REQ_MASK
;
4020 wr32(hw
, I40E_QTX_ENA(pf_q
), tx_reg
);
4021 /* No waiting for the Tx queue to disable */
4022 if (!enable
&& test_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
))
4025 /* wait for the change to finish */
4026 ret
= i40e_pf_txq_wait(pf
, pf_q
, enable
);
4028 dev_info(&pf
->pdev
->dev
,
4029 "VSI seid %d Tx ring %d %sable timeout\n",
4030 vsi
->seid
, pf_q
, (enable
? "en" : "dis"));
4035 if (hw
->revision_id
== 0)
4041 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
4042 * @pf: the PF being configured
4043 * @pf_q: the PF queue
4044 * @enable: enable or disable state of the queue
4046 * This routine will wait for the given Rx queue of the PF to reach the
4047 * enabled or disabled state.
4048 * Returns -ETIMEDOUT in case of failing to reach the requested state after
4049 * multiple retries; else will return 0 in case of success.
4051 static int i40e_pf_rxq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
4056 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
4057 rx_reg
= rd32(&pf
->hw
, I40E_QRX_ENA(pf_q
));
4058 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
4061 usleep_range(10, 20);
4063 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
4070 * i40e_vsi_control_rx - Start or stop a VSI's rings
4071 * @vsi: the VSI being configured
4072 * @enable: start or stop the rings
4074 static int i40e_vsi_control_rx(struct i40e_vsi
*vsi
, bool enable
)
4076 struct i40e_pf
*pf
= vsi
->back
;
4077 struct i40e_hw
*hw
= &pf
->hw
;
4078 int i
, j
, pf_q
, ret
= 0;
4081 pf_q
= vsi
->base_queue
;
4082 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
4083 for (j
= 0; j
< 50; j
++) {
4084 rx_reg
= rd32(hw
, I40E_QRX_ENA(pf_q
));
4085 if (((rx_reg
>> I40E_QRX_ENA_QENA_REQ_SHIFT
) & 1) ==
4086 ((rx_reg
>> I40E_QRX_ENA_QENA_STAT_SHIFT
) & 1))
4088 usleep_range(1000, 2000);
4091 /* Skip if the queue is already in the requested state */
4092 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
4095 /* turn on/off the queue */
4097 rx_reg
|= I40E_QRX_ENA_QENA_REQ_MASK
;
4099 rx_reg
&= ~I40E_QRX_ENA_QENA_REQ_MASK
;
4100 wr32(hw
, I40E_QRX_ENA(pf_q
), rx_reg
);
4101 /* No waiting for the Tx queue to disable */
4102 if (!enable
&& test_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
))
4105 /* wait for the change to finish */
4106 ret
= i40e_pf_rxq_wait(pf
, pf_q
, enable
);
4108 dev_info(&pf
->pdev
->dev
,
4109 "VSI seid %d Rx ring %d %sable timeout\n",
4110 vsi
->seid
, pf_q
, (enable
? "en" : "dis"));
4119 * i40e_vsi_start_rings - Start a VSI's rings
4120 * @vsi: the VSI being configured
4122 int i40e_vsi_start_rings(struct i40e_vsi
*vsi
)
4126 /* do rx first for enable and last for disable */
4127 ret
= i40e_vsi_control_rx(vsi
, true);
4130 ret
= i40e_vsi_control_tx(vsi
, true);
4136 * i40e_vsi_stop_rings - Stop a VSI's rings
4137 * @vsi: the VSI being configured
4139 void i40e_vsi_stop_rings(struct i40e_vsi
*vsi
)
4141 /* do rx first for enable and last for disable
4142 * Ignore return value, we need to shutdown whatever we can
4144 i40e_vsi_control_tx(vsi
, false);
4145 i40e_vsi_control_rx(vsi
, false);
4149 * i40e_vsi_free_irq - Free the irq association with the OS
4150 * @vsi: the VSI being configured
4152 static void i40e_vsi_free_irq(struct i40e_vsi
*vsi
)
4154 struct i40e_pf
*pf
= vsi
->back
;
4155 struct i40e_hw
*hw
= &pf
->hw
;
4156 int base
= vsi
->base_vector
;
4160 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
4161 if (!vsi
->q_vectors
)
4164 if (!vsi
->irqs_ready
)
4167 vsi
->irqs_ready
= false;
4168 for (i
= 0; i
< vsi
->num_q_vectors
; i
++) {
4173 irq_num
= pf
->msix_entries
[vector
].vector
;
4175 /* free only the irqs that were actually requested */
4176 if (!vsi
->q_vectors
[i
] ||
4177 !vsi
->q_vectors
[i
]->num_ringpairs
)
4180 /* clear the affinity notifier in the IRQ descriptor */
4181 irq_set_affinity_notifier(irq_num
, NULL
);
4182 /* clear the affinity_mask in the IRQ descriptor */
4183 irq_set_affinity_hint(irq_num
, NULL
);
4184 synchronize_irq(irq_num
);
4185 free_irq(irq_num
, vsi
->q_vectors
[i
]);
4187 /* Tear down the interrupt queue link list
4189 * We know that they come in pairs and always
4190 * the Rx first, then the Tx. To clear the
4191 * link list, stick the EOL value into the
4192 * next_q field of the registers.
4194 val
= rd32(hw
, I40E_PFINT_LNKLSTN(vector
- 1));
4195 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
4196 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
4197 val
|= I40E_QUEUE_END_OF_LIST
4198 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
4199 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), val
);
4201 while (qp
!= I40E_QUEUE_END_OF_LIST
) {
4204 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
4206 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
4207 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
4208 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
4209 I40E_QINT_RQCTL_INTEVENT_MASK
);
4211 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
4212 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
4214 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
4216 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
4218 next
= (val
& I40E_QINT_TQCTL_NEXTQ_INDX_MASK
)
4219 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
;
4221 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
4222 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
4223 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
4224 I40E_QINT_TQCTL_INTEVENT_MASK
);
4226 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
4227 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
4229 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
4234 free_irq(pf
->pdev
->irq
, pf
);
4236 val
= rd32(hw
, I40E_PFINT_LNKLST0
);
4237 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
4238 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
4239 val
|= I40E_QUEUE_END_OF_LIST
4240 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT
;
4241 wr32(hw
, I40E_PFINT_LNKLST0
, val
);
4243 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
4244 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
4245 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
4246 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
4247 I40E_QINT_RQCTL_INTEVENT_MASK
);
4249 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
4250 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
4252 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
4254 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
4256 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
4257 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
4258 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
4259 I40E_QINT_TQCTL_INTEVENT_MASK
);
4261 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
4262 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
4264 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
4269 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
4270 * @vsi: the VSI being configured
4271 * @v_idx: Index of vector to be freed
4273 * This function frees the memory allocated to the q_vector. In addition if
4274 * NAPI is enabled it will delete any references to the NAPI struct prior
4275 * to freeing the q_vector.
4277 static void i40e_free_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
4279 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
4280 struct i40e_ring
*ring
;
4285 /* disassociate q_vector from rings */
4286 i40e_for_each_ring(ring
, q_vector
->tx
)
4287 ring
->q_vector
= NULL
;
4289 i40e_for_each_ring(ring
, q_vector
->rx
)
4290 ring
->q_vector
= NULL
;
4292 /* only VSI w/ an associated netdev is set up w/ NAPI */
4294 netif_napi_del(&q_vector
->napi
);
4296 vsi
->q_vectors
[v_idx
] = NULL
;
4298 kfree_rcu(q_vector
, rcu
);
4302 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
4303 * @vsi: the VSI being un-configured
4305 * This frees the memory allocated to the q_vectors and
4306 * deletes references to the NAPI struct.
4308 static void i40e_vsi_free_q_vectors(struct i40e_vsi
*vsi
)
4312 for (v_idx
= 0; v_idx
< vsi
->num_q_vectors
; v_idx
++)
4313 i40e_free_q_vector(vsi
, v_idx
);
4317 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
4318 * @pf: board private structure
4320 static void i40e_reset_interrupt_capability(struct i40e_pf
*pf
)
4322 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
4323 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
4324 pci_disable_msix(pf
->pdev
);
4325 kfree(pf
->msix_entries
);
4326 pf
->msix_entries
= NULL
;
4327 kfree(pf
->irq_pile
);
4328 pf
->irq_pile
= NULL
;
4329 } else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
) {
4330 pci_disable_msi(pf
->pdev
);
4332 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
);
4336 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
4337 * @pf: board private structure
4339 * We go through and clear interrupt specific resources and reset the structure
4340 * to pre-load conditions
4342 static void i40e_clear_interrupt_scheme(struct i40e_pf
*pf
)
4346 i40e_stop_misc_vector(pf
);
4347 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
&& pf
->msix_entries
) {
4348 synchronize_irq(pf
->msix_entries
[0].vector
);
4349 free_irq(pf
->msix_entries
[0].vector
, pf
);
4352 i40e_put_lump(pf
->irq_pile
, pf
->iwarp_base_vector
,
4353 I40E_IWARP_IRQ_PILE_ID
);
4355 i40e_put_lump(pf
->irq_pile
, 0, I40E_PILE_VALID_BIT
-1);
4356 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
4358 i40e_vsi_free_q_vectors(pf
->vsi
[i
]);
4359 i40e_reset_interrupt_capability(pf
);
4363 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
4364 * @vsi: the VSI being configured
4366 static void i40e_napi_enable_all(struct i40e_vsi
*vsi
)
4373 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++)
4374 napi_enable(&vsi
->q_vectors
[q_idx
]->napi
);
4378 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4379 * @vsi: the VSI being configured
4381 static void i40e_napi_disable_all(struct i40e_vsi
*vsi
)
4388 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++)
4389 napi_disable(&vsi
->q_vectors
[q_idx
]->napi
);
4393 * i40e_vsi_close - Shut down a VSI
4394 * @vsi: the vsi to be quelled
4396 static void i40e_vsi_close(struct i40e_vsi
*vsi
)
4400 if (!test_and_set_bit(__I40E_DOWN
, &vsi
->state
))
4402 i40e_vsi_free_irq(vsi
);
4403 i40e_vsi_free_tx_resources(vsi
);
4404 i40e_vsi_free_rx_resources(vsi
);
4405 vsi
->current_netdev_flags
= 0;
4406 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
4408 i40e_notify_client_of_netdev_close(vsi
, reset
);
4412 * i40e_quiesce_vsi - Pause a given VSI
4413 * @vsi: the VSI being paused
4415 static void i40e_quiesce_vsi(struct i40e_vsi
*vsi
)
4417 if (test_bit(__I40E_DOWN
, &vsi
->state
))
4420 /* No need to disable FCoE VSI when Tx suspended */
4421 if ((test_bit(__I40E_PORT_TX_SUSPENDED
, &vsi
->back
->state
)) &&
4422 vsi
->type
== I40E_VSI_FCOE
) {
4423 dev_dbg(&vsi
->back
->pdev
->dev
,
4424 "VSI seid %d skipping FCoE VSI disable\n", vsi
->seid
);
4428 set_bit(__I40E_NEEDS_RESTART
, &vsi
->state
);
4429 if (vsi
->netdev
&& netif_running(vsi
->netdev
))
4430 vsi
->netdev
->netdev_ops
->ndo_stop(vsi
->netdev
);
4432 i40e_vsi_close(vsi
);
4436 * i40e_unquiesce_vsi - Resume a given VSI
4437 * @vsi: the VSI being resumed
4439 static void i40e_unquiesce_vsi(struct i40e_vsi
*vsi
)
4441 if (!test_bit(__I40E_NEEDS_RESTART
, &vsi
->state
))
4444 clear_bit(__I40E_NEEDS_RESTART
, &vsi
->state
);
4445 if (vsi
->netdev
&& netif_running(vsi
->netdev
))
4446 vsi
->netdev
->netdev_ops
->ndo_open(vsi
->netdev
);
4448 i40e_vsi_open(vsi
); /* this clears the DOWN bit */
4452 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
4455 static void i40e_pf_quiesce_all_vsi(struct i40e_pf
*pf
)
4459 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4461 i40e_quiesce_vsi(pf
->vsi
[v
]);
4466 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
4469 static void i40e_pf_unquiesce_all_vsi(struct i40e_pf
*pf
)
4473 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4475 i40e_unquiesce_vsi(pf
->vsi
[v
]);
4479 #ifdef CONFIG_I40E_DCB
4481 * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
4482 * @vsi: the VSI being configured
4484 * This function waits for the given VSI's queues to be disabled.
4486 static int i40e_vsi_wait_queues_disabled(struct i40e_vsi
*vsi
)
4488 struct i40e_pf
*pf
= vsi
->back
;
4491 pf_q
= vsi
->base_queue
;
4492 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
4493 /* Check and wait for the disable status of the queue */
4494 ret
= i40e_pf_txq_wait(pf
, pf_q
, false);
4496 dev_info(&pf
->pdev
->dev
,
4497 "VSI seid %d Tx ring %d disable timeout\n",
4503 pf_q
= vsi
->base_queue
;
4504 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
4505 /* Check and wait for the disable status of the queue */
4506 ret
= i40e_pf_rxq_wait(pf
, pf_q
, false);
4508 dev_info(&pf
->pdev
->dev
,
4509 "VSI seid %d Rx ring %d disable timeout\n",
4519 * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
4522 * This function waits for the queues to be in disabled state for all the
4523 * VSIs that are managed by this PF.
4525 static int i40e_pf_wait_queues_disabled(struct i40e_pf
*pf
)
4529 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
; v
++) {
4530 /* No need to wait for FCoE VSI queues */
4531 if (pf
->vsi
[v
] && pf
->vsi
[v
]->type
!= I40E_VSI_FCOE
) {
4532 ret
= i40e_vsi_wait_queues_disabled(pf
->vsi
[v
]);
4544 * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
4545 * @q_idx: TX queue number
4546 * @vsi: Pointer to VSI struct
4548 * This function checks specified queue for given VSI. Detects hung condition.
4549 * Sets hung bit since it is two step process. Before next run of service task
4550 * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not,
4551 * hung condition remain unchanged and during subsequent run, this function
4552 * issues SW interrupt to recover from hung condition.
4554 static void i40e_detect_recover_hung_queue(int q_idx
, struct i40e_vsi
*vsi
)
4556 struct i40e_ring
*tx_ring
= NULL
;
4558 u32 head
, val
, tx_pending_hw
;
4563 /* now that we have an index, find the tx_ring struct */
4564 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
4565 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
) {
4566 if (q_idx
== vsi
->tx_rings
[i
]->queue_index
) {
4567 tx_ring
= vsi
->tx_rings
[i
];
4576 /* Read interrupt register */
4577 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
4579 I40E_PFINT_DYN_CTLN(tx_ring
->q_vector
->v_idx
+
4580 tx_ring
->vsi
->base_vector
- 1));
4582 val
= rd32(&pf
->hw
, I40E_PFINT_DYN_CTL0
);
4584 head
= i40e_get_head(tx_ring
);
4586 tx_pending_hw
= i40e_get_tx_pending(tx_ring
, false);
4588 /* HW is done executing descriptors, updated HEAD write back,
4589 * but SW hasn't processed those descriptors. If interrupt is
4590 * not generated from this point ON, it could result into
4591 * dev_watchdog detecting timeout on those netdev_queue,
4592 * hence proactively trigger SW interrupt.
4594 if (tx_pending_hw
&& (!(val
& I40E_PFINT_DYN_CTLN_INTENA_MASK
))) {
4595 /* NAPI Poll didn't run and clear since it was set */
4596 if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT
,
4597 &tx_ring
->q_vector
->hung_detected
)) {
4598 netdev_info(vsi
->netdev
, "VSI_seid %d, Hung TX queue %d, tx_pending_hw: %d, NTC:0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x\n",
4599 vsi
->seid
, q_idx
, tx_pending_hw
,
4600 tx_ring
->next_to_clean
, head
,
4601 tx_ring
->next_to_use
,
4602 readl(tx_ring
->tail
));
4603 netdev_info(vsi
->netdev
, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n",
4604 vsi
->seid
, q_idx
, val
);
4605 i40e_force_wb(vsi
, tx_ring
->q_vector
);
4607 /* First Chance - detected possible hung */
4608 set_bit(I40E_Q_VECTOR_HUNG_DETECT
,
4609 &tx_ring
->q_vector
->hung_detected
);
4613 /* This is the case where we have interrupts missing,
4614 * so the tx_pending in HW will most likely be 0, but we
4615 * will have tx_pending in SW since the WB happened but the
4616 * interrupt got lost.
4618 if ((!tx_pending_hw
) && i40e_get_tx_pending(tx_ring
, true) &&
4619 (!(val
& I40E_PFINT_DYN_CTLN_INTENA_MASK
))) {
4620 if (napi_reschedule(&tx_ring
->q_vector
->napi
))
4621 tx_ring
->tx_stats
.tx_lost_interrupt
++;
4626 * i40e_detect_recover_hung - Function to detect and recover hung_queues
4627 * @pf: pointer to PF struct
4629 * LAN VSI has netdev and netdev has TX queues. This function is to check
4630 * each of those TX queues if they are hung, trigger recovery by issuing
4633 static void i40e_detect_recover_hung(struct i40e_pf
*pf
)
4635 struct net_device
*netdev
;
4636 struct i40e_vsi
*vsi
;
4639 /* Only for LAN VSI */
4640 vsi
= pf
->vsi
[pf
->lan_vsi
];
4645 /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
4646 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
4647 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
4650 /* Make sure type is MAIN VSI */
4651 if (vsi
->type
!= I40E_VSI_MAIN
)
4654 netdev
= vsi
->netdev
;
4658 /* Bail out if netif_carrier is not OK */
4659 if (!netif_carrier_ok(netdev
))
4662 /* Go thru' TX queues for netdev */
4663 for (i
= 0; i
< netdev
->num_tx_queues
; i
++) {
4664 struct netdev_queue
*q
;
4666 q
= netdev_get_tx_queue(netdev
, i
);
4668 i40e_detect_recover_hung_queue(i
, vsi
);
4673 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
4674 * @pf: pointer to PF
4676 * Get TC map for ISCSI PF type that will include iSCSI TC
4679 static u8
i40e_get_iscsi_tc_map(struct i40e_pf
*pf
)
4681 struct i40e_dcb_app_priority_table app
;
4682 struct i40e_hw
*hw
= &pf
->hw
;
4683 u8 enabled_tc
= 1; /* TC0 is always enabled */
4685 /* Get the iSCSI APP TLV */
4686 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4688 for (i
= 0; i
< dcbcfg
->numapps
; i
++) {
4689 app
= dcbcfg
->app
[i
];
4690 if (app
.selector
== I40E_APP_SEL_TCPIP
&&
4691 app
.protocolid
== I40E_APP_PROTOID_ISCSI
) {
4692 tc
= dcbcfg
->etscfg
.prioritytable
[app
.priority
];
4693 enabled_tc
|= BIT(tc
);
4702 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
4703 * @dcbcfg: the corresponding DCBx configuration structure
4705 * Return the number of TCs from given DCBx configuration
4707 static u8
i40e_dcb_get_num_tc(struct i40e_dcbx_config
*dcbcfg
)
4709 int i
, tc_unused
= 0;
4713 /* Scan the ETS Config Priority Table to find
4714 * traffic class enabled for a given priority
4715 * and create a bitmask of enabled TCs
4717 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++)
4718 num_tc
|= BIT(dcbcfg
->etscfg
.prioritytable
[i
]);
4720 /* Now scan the bitmask to check for
4721 * contiguous TCs starting with TC0
4723 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4724 if (num_tc
& BIT(i
)) {
4728 pr_err("Non-contiguous TC - Disabling DCB\n");
4736 /* There is always at least TC0 */
4744 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
4745 * @dcbcfg: the corresponding DCBx configuration structure
4747 * Query the current DCB configuration and return the number of
4748 * traffic classes enabled from the given DCBX config
4750 static u8
i40e_dcb_get_enabled_tc(struct i40e_dcbx_config
*dcbcfg
)
4752 u8 num_tc
= i40e_dcb_get_num_tc(dcbcfg
);
4756 for (i
= 0; i
< num_tc
; i
++)
4757 enabled_tc
|= BIT(i
);
4763 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
4764 * @pf: PF being queried
4766 * Return number of traffic classes enabled for the given PF
4768 static u8
i40e_pf_get_num_tc(struct i40e_pf
*pf
)
4770 struct i40e_hw
*hw
= &pf
->hw
;
4771 u8 i
, enabled_tc
= 1;
4773 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4775 /* If DCB is not enabled then always in single TC */
4776 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
4779 /* SFP mode will be enabled for all TCs on port */
4780 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
4781 return i40e_dcb_get_num_tc(dcbcfg
);
4783 /* MFP mode return count of enabled TCs for this PF */
4784 if (pf
->hw
.func_caps
.iscsi
)
4785 enabled_tc
= i40e_get_iscsi_tc_map(pf
);
4787 return 1; /* Only TC0 */
4789 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4790 if (enabled_tc
& BIT(i
))
4797 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
4798 * @pf: PF being queried
4800 * Return a bitmap for enabled traffic classes for this PF.
4802 static u8
i40e_pf_get_tc_map(struct i40e_pf
*pf
)
4804 /* If DCB is not enabled for this PF then just return default TC */
4805 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
4806 return I40E_DEFAULT_TRAFFIC_CLASS
;
4808 /* SFP mode we want PF to be enabled for all TCs */
4809 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
4810 return i40e_dcb_get_enabled_tc(&pf
->hw
.local_dcbx_config
);
4812 /* MFP enabled and iSCSI PF type */
4813 if (pf
->hw
.func_caps
.iscsi
)
4814 return i40e_get_iscsi_tc_map(pf
);
4816 return I40E_DEFAULT_TRAFFIC_CLASS
;
4820 * i40e_vsi_get_bw_info - Query VSI BW Information
4821 * @vsi: the VSI being queried
4823 * Returns 0 on success, negative value on failure
4825 static int i40e_vsi_get_bw_info(struct i40e_vsi
*vsi
)
4827 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config
= {0};
4828 struct i40e_aqc_query_vsi_bw_config_resp bw_config
= {0};
4829 struct i40e_pf
*pf
= vsi
->back
;
4830 struct i40e_hw
*hw
= &pf
->hw
;
4835 /* Get the VSI level BW configuration */
4836 ret
= i40e_aq_query_vsi_bw_config(hw
, vsi
->seid
, &bw_config
, NULL
);
4838 dev_info(&pf
->pdev
->dev
,
4839 "couldn't get PF vsi bw config, err %s aq_err %s\n",
4840 i40e_stat_str(&pf
->hw
, ret
),
4841 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4845 /* Get the VSI level BW configuration per TC */
4846 ret
= i40e_aq_query_vsi_ets_sla_config(hw
, vsi
->seid
, &bw_ets_config
,
4849 dev_info(&pf
->pdev
->dev
,
4850 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
4851 i40e_stat_str(&pf
->hw
, ret
),
4852 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4856 if (bw_config
.tc_valid_bits
!= bw_ets_config
.tc_valid_bits
) {
4857 dev_info(&pf
->pdev
->dev
,
4858 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
4859 bw_config
.tc_valid_bits
,
4860 bw_ets_config
.tc_valid_bits
);
4861 /* Still continuing */
4864 vsi
->bw_limit
= le16_to_cpu(bw_config
.port_bw_limit
);
4865 vsi
->bw_max_quanta
= bw_config
.max_bw
;
4866 tc_bw_max
= le16_to_cpu(bw_ets_config
.tc_bw_max
[0]) |
4867 (le16_to_cpu(bw_ets_config
.tc_bw_max
[1]) << 16);
4868 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4869 vsi
->bw_ets_share_credits
[i
] = bw_ets_config
.share_credits
[i
];
4870 vsi
->bw_ets_limit_credits
[i
] =
4871 le16_to_cpu(bw_ets_config
.credits
[i
]);
4872 /* 3 bits out of 4 for each TC */
4873 vsi
->bw_ets_max_quanta
[i
] = (u8
)((tc_bw_max
>> (i
*4)) & 0x7);
4880 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
4881 * @vsi: the VSI being configured
4882 * @enabled_tc: TC bitmap
4883 * @bw_credits: BW shared credits per TC
4885 * Returns 0 on success, negative value on failure
4887 static int i40e_vsi_configure_bw_alloc(struct i40e_vsi
*vsi
, u8 enabled_tc
,
4890 struct i40e_aqc_configure_vsi_tc_bw_data bw_data
;
4894 bw_data
.tc_valid_bits
= enabled_tc
;
4895 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
4896 bw_data
.tc_bw_credits
[i
] = bw_share
[i
];
4898 ret
= i40e_aq_config_vsi_tc_bw(&vsi
->back
->hw
, vsi
->seid
, &bw_data
,
4901 dev_info(&vsi
->back
->pdev
->dev
,
4902 "AQ command Config VSI BW allocation per TC failed = %d\n",
4903 vsi
->back
->hw
.aq
.asq_last_status
);
4907 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
4908 vsi
->info
.qs_handle
[i
] = bw_data
.qs_handles
[i
];
4914 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
4915 * @vsi: the VSI being configured
4916 * @enabled_tc: TC map to be enabled
4919 static void i40e_vsi_config_netdev_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
4921 struct net_device
*netdev
= vsi
->netdev
;
4922 struct i40e_pf
*pf
= vsi
->back
;
4923 struct i40e_hw
*hw
= &pf
->hw
;
4926 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4932 netdev_reset_tc(netdev
);
4936 /* Set up actual enabled TCs on the VSI */
4937 if (netdev_set_num_tc(netdev
, vsi
->tc_config
.numtc
))
4940 /* set per TC queues for the VSI */
4941 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4942 /* Only set TC queues for enabled tcs
4944 * e.g. For a VSI that has TC0 and TC3 enabled the
4945 * enabled_tc bitmap would be 0x00001001; the driver
4946 * will set the numtc for netdev as 2 that will be
4947 * referenced by the netdev layer as TC 0 and 1.
4949 if (vsi
->tc_config
.enabled_tc
& BIT(i
))
4950 netdev_set_tc_queue(netdev
,
4951 vsi
->tc_config
.tc_info
[i
].netdev_tc
,
4952 vsi
->tc_config
.tc_info
[i
].qcount
,
4953 vsi
->tc_config
.tc_info
[i
].qoffset
);
4956 /* Assign UP2TC map for the VSI */
4957 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
4958 /* Get the actual TC# for the UP */
4959 u8 ets_tc
= dcbcfg
->etscfg
.prioritytable
[i
];
4960 /* Get the mapped netdev TC# for the UP */
4961 netdev_tc
= vsi
->tc_config
.tc_info
[ets_tc
].netdev_tc
;
4962 netdev_set_prio_tc_map(netdev
, i
, netdev_tc
);
4967 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
4968 * @vsi: the VSI being configured
4969 * @ctxt: the ctxt buffer returned from AQ VSI update param command
4971 static void i40e_vsi_update_queue_map(struct i40e_vsi
*vsi
,
4972 struct i40e_vsi_context
*ctxt
)
4974 /* copy just the sections touched not the entire info
4975 * since not all sections are valid as returned by
4978 vsi
->info
.mapping_flags
= ctxt
->info
.mapping_flags
;
4979 memcpy(&vsi
->info
.queue_mapping
,
4980 &ctxt
->info
.queue_mapping
, sizeof(vsi
->info
.queue_mapping
));
4981 memcpy(&vsi
->info
.tc_mapping
, ctxt
->info
.tc_mapping
,
4982 sizeof(vsi
->info
.tc_mapping
));
4986 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
4987 * @vsi: VSI to be configured
4988 * @enabled_tc: TC bitmap
4990 * This configures a particular VSI for TCs that are mapped to the
4991 * given TC bitmap. It uses default bandwidth share for TCs across
4992 * VSIs to configure TC for a particular VSI.
4995 * It is expected that the VSI queues have been quisced before calling
4998 static int i40e_vsi_config_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
5000 u8 bw_share
[I40E_MAX_TRAFFIC_CLASS
] = {0};
5001 struct i40e_vsi_context ctxt
;
5005 /* Check if enabled_tc is same as existing or new TCs */
5006 if (vsi
->tc_config
.enabled_tc
== enabled_tc
)
5009 /* Enable ETS TCs with equal BW Share for now across all VSIs */
5010 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
5011 if (enabled_tc
& BIT(i
))
5015 ret
= i40e_vsi_configure_bw_alloc(vsi
, enabled_tc
, bw_share
);
5017 dev_info(&vsi
->back
->pdev
->dev
,
5018 "Failed configuring TC map %d for VSI %d\n",
5019 enabled_tc
, vsi
->seid
);
5023 /* Update Queue Pairs Mapping for currently enabled UPs */
5024 ctxt
.seid
= vsi
->seid
;
5025 ctxt
.pf_num
= vsi
->back
->hw
.pf_id
;
5027 ctxt
.uplink_seid
= vsi
->uplink_seid
;
5028 ctxt
.info
= vsi
->info
;
5029 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
5031 if (vsi
->back
->flags
& I40E_FLAG_IWARP_ENABLED
) {
5032 ctxt
.info
.valid_sections
|=
5033 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID
);
5034 ctxt
.info
.queueing_opt_flags
|= I40E_AQ_VSI_QUE_OPT_TCP_ENA
;
5037 /* Update the VSI after updating the VSI queue-mapping information */
5038 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
5040 dev_info(&vsi
->back
->pdev
->dev
,
5041 "Update vsi tc config failed, err %s aq_err %s\n",
5042 i40e_stat_str(&vsi
->back
->hw
, ret
),
5043 i40e_aq_str(&vsi
->back
->hw
,
5044 vsi
->back
->hw
.aq
.asq_last_status
));
5047 /* update the local VSI info with updated queue map */
5048 i40e_vsi_update_queue_map(vsi
, &ctxt
);
5049 vsi
->info
.valid_sections
= 0;
5051 /* Update current VSI BW information */
5052 ret
= i40e_vsi_get_bw_info(vsi
);
5054 dev_info(&vsi
->back
->pdev
->dev
,
5055 "Failed updating vsi bw info, err %s aq_err %s\n",
5056 i40e_stat_str(&vsi
->back
->hw
, ret
),
5057 i40e_aq_str(&vsi
->back
->hw
,
5058 vsi
->back
->hw
.aq
.asq_last_status
));
5062 /* Update the netdev TC setup */
5063 i40e_vsi_config_netdev_tc(vsi
, enabled_tc
);
5069 * i40e_veb_config_tc - Configure TCs for given VEB
5071 * @enabled_tc: TC bitmap
5073 * Configures given TC bitmap for VEB (switching) element
5075 int i40e_veb_config_tc(struct i40e_veb
*veb
, u8 enabled_tc
)
5077 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data
= {0};
5078 struct i40e_pf
*pf
= veb
->pf
;
5082 /* No TCs or already enabled TCs just return */
5083 if (!enabled_tc
|| veb
->enabled_tc
== enabled_tc
)
5086 bw_data
.tc_valid_bits
= enabled_tc
;
5087 /* bw_data.absolute_credits is not set (relative) */
5089 /* Enable ETS TCs with equal BW Share for now */
5090 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
5091 if (enabled_tc
& BIT(i
))
5092 bw_data
.tc_bw_share_credits
[i
] = 1;
5095 ret
= i40e_aq_config_switch_comp_bw_config(&pf
->hw
, veb
->seid
,
5098 dev_info(&pf
->pdev
->dev
,
5099 "VEB bw config failed, err %s aq_err %s\n",
5100 i40e_stat_str(&pf
->hw
, ret
),
5101 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
5105 /* Update the BW information */
5106 ret
= i40e_veb_get_bw_info(veb
);
5108 dev_info(&pf
->pdev
->dev
,
5109 "Failed getting veb bw config, err %s aq_err %s\n",
5110 i40e_stat_str(&pf
->hw
, ret
),
5111 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
5118 #ifdef CONFIG_I40E_DCB
5120 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
5123 * Reconfigure VEB/VSIs on a given PF; it is assumed that
5124 * the caller would've quiesce all the VSIs before calling
5127 static void i40e_dcb_reconfigure(struct i40e_pf
*pf
)
5133 /* Enable the TCs available on PF to all VEBs */
5134 tc_map
= i40e_pf_get_tc_map(pf
);
5135 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
5138 ret
= i40e_veb_config_tc(pf
->veb
[v
], tc_map
);
5140 dev_info(&pf
->pdev
->dev
,
5141 "Failed configuring TC for VEB seid=%d\n",
5143 /* Will try to configure as many components */
5147 /* Update each VSI */
5148 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5152 /* - Enable all TCs for the LAN VSI
5154 * - For FCoE VSI only enable the TC configured
5155 * as per the APP TLV
5157 * - For all others keep them at TC0 for now
5159 if (v
== pf
->lan_vsi
)
5160 tc_map
= i40e_pf_get_tc_map(pf
);
5162 tc_map
= I40E_DEFAULT_TRAFFIC_CLASS
;
5164 if (pf
->vsi
[v
]->type
== I40E_VSI_FCOE
)
5165 tc_map
= i40e_get_fcoe_tc_map(pf
);
5166 #endif /* #ifdef I40E_FCOE */
5168 ret
= i40e_vsi_config_tc(pf
->vsi
[v
], tc_map
);
5170 dev_info(&pf
->pdev
->dev
,
5171 "Failed configuring TC for VSI seid=%d\n",
5173 /* Will try to configure as many components */
5175 /* Re-configure VSI vectors based on updated TC map */
5176 i40e_vsi_map_rings_to_vectors(pf
->vsi
[v
]);
5177 if (pf
->vsi
[v
]->netdev
)
5178 i40e_dcbnl_set_all(pf
->vsi
[v
]);
5184 * i40e_resume_port_tx - Resume port Tx
5187 * Resume a port's Tx and issue a PF reset in case of failure to
5190 static int i40e_resume_port_tx(struct i40e_pf
*pf
)
5192 struct i40e_hw
*hw
= &pf
->hw
;
5195 ret
= i40e_aq_resume_port_tx(hw
, NULL
);
5197 dev_info(&pf
->pdev
->dev
,
5198 "Resume Port Tx failed, err %s aq_err %s\n",
5199 i40e_stat_str(&pf
->hw
, ret
),
5200 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
5201 /* Schedule PF reset to recover */
5202 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
5203 i40e_service_event_schedule(pf
);
5210 * i40e_init_pf_dcb - Initialize DCB configuration
5211 * @pf: PF being configured
5213 * Query the current DCB configuration and cache it
5214 * in the hardware structure
5216 static int i40e_init_pf_dcb(struct i40e_pf
*pf
)
5218 struct i40e_hw
*hw
= &pf
->hw
;
5221 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
5222 if (pf
->flags
& I40E_FLAG_NO_DCB_SUPPORT
)
5225 /* Get the initial DCB configuration */
5226 err
= i40e_init_dcb(hw
);
5228 /* Device/Function is not DCBX capable */
5229 if ((!hw
->func_caps
.dcb
) ||
5230 (hw
->dcbx_status
== I40E_DCBX_STATUS_DISABLED
)) {
5231 dev_info(&pf
->pdev
->dev
,
5232 "DCBX offload is not supported or is disabled for this PF.\n");
5234 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
)
5238 /* When status is not DISABLED then DCBX in FW */
5239 pf
->dcbx_cap
= DCB_CAP_DCBX_LLD_MANAGED
|
5240 DCB_CAP_DCBX_VER_IEEE
;
5242 pf
->flags
|= I40E_FLAG_DCB_CAPABLE
;
5243 /* Enable DCB tagging only when more than one TC
5244 * or explicitly disable if only one TC
5246 if (i40e_dcb_get_num_tc(&hw
->local_dcbx_config
) > 1)
5247 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
5249 pf
->flags
&= ~I40E_FLAG_DCB_ENABLED
;
5250 dev_dbg(&pf
->pdev
->dev
,
5251 "DCBX offload is supported for this PF.\n");
5254 dev_info(&pf
->pdev
->dev
,
5255 "Query for DCB configuration failed, err %s aq_err %s\n",
5256 i40e_stat_str(&pf
->hw
, err
),
5257 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
5263 #endif /* CONFIG_I40E_DCB */
5264 #define SPEED_SIZE 14
5267 * i40e_print_link_message - print link up or down
5268 * @vsi: the VSI for which link needs a message
5270 void i40e_print_link_message(struct i40e_vsi
*vsi
, bool isup
)
5272 enum i40e_aq_link_speed new_speed
;
5273 char *speed
= "Unknown";
5274 char *fc
= "Unknown";
5276 new_speed
= vsi
->back
->hw
.phy
.link_info
.link_speed
;
5278 if ((vsi
->current_isup
== isup
) && (vsi
->current_speed
== new_speed
))
5280 vsi
->current_isup
= isup
;
5281 vsi
->current_speed
= new_speed
;
5283 netdev_info(vsi
->netdev
, "NIC Link is Down\n");
5287 /* Warn user if link speed on NPAR enabled partition is not at
5290 if (vsi
->back
->hw
.func_caps
.npar_enable
&&
5291 (vsi
->back
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_1GB
||
5292 vsi
->back
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_100MB
))
5293 netdev_warn(vsi
->netdev
,
5294 "The partition detected link speed that is less than 10Gbps\n");
5296 switch (vsi
->back
->hw
.phy
.link_info
.link_speed
) {
5297 case I40E_LINK_SPEED_40GB
:
5300 case I40E_LINK_SPEED_20GB
:
5303 case I40E_LINK_SPEED_25GB
:
5306 case I40E_LINK_SPEED_10GB
:
5309 case I40E_LINK_SPEED_1GB
:
5312 case I40E_LINK_SPEED_100MB
:
5319 switch (vsi
->back
->hw
.fc
.current_mode
) {
5323 case I40E_FC_TX_PAUSE
:
5326 case I40E_FC_RX_PAUSE
:
5334 netdev_info(vsi
->netdev
, "NIC Link is Up %sbps Full Duplex, Flow Control: %s\n",
5339 * i40e_up_complete - Finish the last steps of bringing up a connection
5340 * @vsi: the VSI being configured
5342 static int i40e_up_complete(struct i40e_vsi
*vsi
)
5344 struct i40e_pf
*pf
= vsi
->back
;
5347 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
5348 i40e_vsi_configure_msix(vsi
);
5350 i40e_configure_msi_and_legacy(vsi
);
5353 err
= i40e_vsi_start_rings(vsi
);
5357 clear_bit(__I40E_DOWN
, &vsi
->state
);
5358 i40e_napi_enable_all(vsi
);
5359 i40e_vsi_enable_irq(vsi
);
5361 if ((pf
->hw
.phy
.link_info
.link_info
& I40E_AQ_LINK_UP
) &&
5363 i40e_print_link_message(vsi
, true);
5364 netif_tx_start_all_queues(vsi
->netdev
);
5365 netif_carrier_on(vsi
->netdev
);
5366 } else if (vsi
->netdev
) {
5367 i40e_print_link_message(vsi
, false);
5368 /* need to check for qualified module here*/
5369 if ((pf
->hw
.phy
.link_info
.link_info
&
5370 I40E_AQ_MEDIA_AVAILABLE
) &&
5371 (!(pf
->hw
.phy
.link_info
.an_info
&
5372 I40E_AQ_QUALIFIED_MODULE
)))
5373 netdev_err(vsi
->netdev
,
5374 "the driver failed to link because an unqualified module was detected.");
5377 /* replay FDIR SB filters */
5378 if (vsi
->type
== I40E_VSI_FDIR
) {
5379 /* reset fd counters */
5380 pf
->fd_add_err
= pf
->fd_atr_cnt
= 0;
5381 if (pf
->fd_tcp_rule
> 0) {
5382 pf
->auto_disable_flags
|= I40E_FLAG_FD_ATR_ENABLED
;
5383 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5384 dev_info(&pf
->pdev
->dev
, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
5385 pf
->fd_tcp_rule
= 0;
5387 i40e_fdir_filter_restore(vsi
);
5390 /* On the next run of the service_task, notify any clients of the new
5393 pf
->flags
|= I40E_FLAG_SERVICE_CLIENT_REQUESTED
;
5394 i40e_service_event_schedule(pf
);
5400 * i40e_vsi_reinit_locked - Reset the VSI
5401 * @vsi: the VSI being configured
5403 * Rebuild the ring structs after some configuration
5404 * has changed, e.g. MTU size.
5406 static void i40e_vsi_reinit_locked(struct i40e_vsi
*vsi
)
5408 struct i40e_pf
*pf
= vsi
->back
;
5410 WARN_ON(in_interrupt());
5411 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
5412 usleep_range(1000, 2000);
5416 clear_bit(__I40E_CONFIG_BUSY
, &pf
->state
);
5420 * i40e_up - Bring the connection back up after being down
5421 * @vsi: the VSI being configured
5423 int i40e_up(struct i40e_vsi
*vsi
)
5427 err
= i40e_vsi_configure(vsi
);
5429 err
= i40e_up_complete(vsi
);
5435 * i40e_down - Shutdown the connection processing
5436 * @vsi: the VSI being stopped
5438 void i40e_down(struct i40e_vsi
*vsi
)
5442 /* It is assumed that the caller of this function
5443 * sets the vsi->state __I40E_DOWN bit.
5446 netif_carrier_off(vsi
->netdev
);
5447 netif_tx_disable(vsi
->netdev
);
5449 i40e_vsi_disable_irq(vsi
);
5450 i40e_vsi_stop_rings(vsi
);
5451 i40e_napi_disable_all(vsi
);
5453 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
5454 i40e_clean_tx_ring(vsi
->tx_rings
[i
]);
5455 i40e_clean_rx_ring(vsi
->rx_rings
[i
]);
5458 i40e_notify_client_of_netdev_close(vsi
, false);
5463 * i40e_setup_tc - configure multiple traffic classes
5464 * @netdev: net device to configure
5465 * @tc: number of traffic classes to enable
5467 static int i40e_setup_tc(struct net_device
*netdev
, u8 tc
)
5469 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
5470 struct i40e_vsi
*vsi
= np
->vsi
;
5471 struct i40e_pf
*pf
= vsi
->back
;
5476 /* Check if DCB enabled to continue */
5477 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
)) {
5478 netdev_info(netdev
, "DCB is not enabled for adapter\n");
5482 /* Check if MFP enabled */
5483 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
5484 netdev_info(netdev
, "Configuring TC not supported in MFP mode\n");
5488 /* Check whether tc count is within enabled limit */
5489 if (tc
> i40e_pf_get_num_tc(pf
)) {
5490 netdev_info(netdev
, "TC count greater than enabled on link for adapter\n");
5494 /* Generate TC map for number of tc requested */
5495 for (i
= 0; i
< tc
; i
++)
5496 enabled_tc
|= BIT(i
);
5498 /* Requesting same TC configuration as already enabled */
5499 if (enabled_tc
== vsi
->tc_config
.enabled_tc
)
5502 /* Quiesce VSI queues */
5503 i40e_quiesce_vsi(vsi
);
5505 /* Configure VSI for enabled TCs */
5506 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
5508 netdev_info(netdev
, "Failed configuring TC for VSI seid=%d\n",
5514 i40e_unquiesce_vsi(vsi
);
5521 int __i40e_setup_tc(struct net_device
*netdev
, u32 handle
, __be16 proto
,
5522 struct tc_to_netdev
*tc
)
5524 static int __i40e_setup_tc(struct net_device
*netdev
, u32 handle
, __be16 proto
,
5525 struct tc_to_netdev
*tc
)
5528 if (handle
!= TC_H_ROOT
|| tc
->type
!= TC_SETUP_MQPRIO
)
5530 return i40e_setup_tc(netdev
, tc
->tc
);
5534 * i40e_open - Called when a network interface is made active
5535 * @netdev: network interface device structure
5537 * The open entry point is called when a network interface is made
5538 * active by the system (IFF_UP). At this point all resources needed
5539 * for transmit and receive operations are allocated, the interrupt
5540 * handler is registered with the OS, the netdev watchdog subtask is
5541 * enabled, and the stack is notified that the interface is ready.
5543 * Returns 0 on success, negative value on failure
5545 int i40e_open(struct net_device
*netdev
)
5547 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
5548 struct i40e_vsi
*vsi
= np
->vsi
;
5549 struct i40e_pf
*pf
= vsi
->back
;
5552 /* disallow open during test or if eeprom is broken */
5553 if (test_bit(__I40E_TESTING
, &pf
->state
) ||
5554 test_bit(__I40E_BAD_EEPROM
, &pf
->state
))
5557 netif_carrier_off(netdev
);
5559 err
= i40e_vsi_open(vsi
);
5563 /* configure global TSO hardware offload settings */
5564 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_F
, be32_to_cpu(TCP_FLAG_PSH
|
5565 TCP_FLAG_FIN
) >> 16);
5566 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_M
, be32_to_cpu(TCP_FLAG_PSH
|
5568 TCP_FLAG_CWR
) >> 16);
5569 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_L
, be32_to_cpu(TCP_FLAG_CWR
) >> 16);
5571 udp_tunnel_get_rx_info(netdev
);
5578 * @vsi: the VSI to open
5580 * Finish initialization of the VSI.
5582 * Returns 0 on success, negative value on failure
5584 int i40e_vsi_open(struct i40e_vsi
*vsi
)
5586 struct i40e_pf
*pf
= vsi
->back
;
5587 char int_name
[I40E_INT_NAME_STR_LEN
];
5590 /* allocate descriptors */
5591 err
= i40e_vsi_setup_tx_resources(vsi
);
5594 err
= i40e_vsi_setup_rx_resources(vsi
);
5598 err
= i40e_vsi_configure(vsi
);
5603 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s",
5604 dev_driver_string(&pf
->pdev
->dev
), vsi
->netdev
->name
);
5605 err
= i40e_vsi_request_irq(vsi
, int_name
);
5609 /* Notify the stack of the actual queue counts. */
5610 err
= netif_set_real_num_tx_queues(vsi
->netdev
,
5611 vsi
->num_queue_pairs
);
5613 goto err_set_queues
;
5615 err
= netif_set_real_num_rx_queues(vsi
->netdev
,
5616 vsi
->num_queue_pairs
);
5618 goto err_set_queues
;
5620 } else if (vsi
->type
== I40E_VSI_FDIR
) {
5621 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s:fdir",
5622 dev_driver_string(&pf
->pdev
->dev
),
5623 dev_name(&pf
->pdev
->dev
));
5624 err
= i40e_vsi_request_irq(vsi
, int_name
);
5631 err
= i40e_up_complete(vsi
);
5633 goto err_up_complete
;
5640 i40e_vsi_free_irq(vsi
);
5642 i40e_vsi_free_rx_resources(vsi
);
5644 i40e_vsi_free_tx_resources(vsi
);
5645 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
5646 i40e_do_reset(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
5652 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
5653 * @pf: Pointer to PF
5655 * This function destroys the hlist where all the Flow Director
5656 * filters were saved.
5658 static void i40e_fdir_filter_exit(struct i40e_pf
*pf
)
5660 struct i40e_fdir_filter
*filter
;
5661 struct hlist_node
*node2
;
5663 hlist_for_each_entry_safe(filter
, node2
,
5664 &pf
->fdir_filter_list
, fdir_node
) {
5665 hlist_del(&filter
->fdir_node
);
5668 pf
->fdir_pf_active_filters
= 0;
5672 * i40e_close - Disables a network interface
5673 * @netdev: network interface device structure
5675 * The close entry point is called when an interface is de-activated
5676 * by the OS. The hardware is still under the driver's control, but
5677 * this netdev interface is disabled.
5679 * Returns 0, this is not allowed to fail
5681 int i40e_close(struct net_device
*netdev
)
5683 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
5684 struct i40e_vsi
*vsi
= np
->vsi
;
5686 i40e_vsi_close(vsi
);
5692 * i40e_do_reset - Start a PF or Core Reset sequence
5693 * @pf: board private structure
5694 * @reset_flags: which reset is requested
5696 * The essential difference in resets is that the PF Reset
5697 * doesn't clear the packet buffers, doesn't reset the PE
5698 * firmware, and doesn't bother the other PFs on the chip.
5700 void i40e_do_reset(struct i40e_pf
*pf
, u32 reset_flags
)
5704 WARN_ON(in_interrupt());
5707 /* do the biggest reset indicated */
5708 if (reset_flags
& BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED
)) {
5710 /* Request a Global Reset
5712 * This will start the chip's countdown to the actual full
5713 * chip reset event, and a warning interrupt to be sent
5714 * to all PFs, including the requestor. Our handler
5715 * for the warning interrupt will deal with the shutdown
5716 * and recovery of the switch setup.
5718 dev_dbg(&pf
->pdev
->dev
, "GlobalR requested\n");
5719 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
5720 val
|= I40E_GLGEN_RTRIG_GLOBR_MASK
;
5721 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
5723 } else if (reset_flags
& BIT_ULL(__I40E_CORE_RESET_REQUESTED
)) {
5725 /* Request a Core Reset
5727 * Same as Global Reset, except does *not* include the MAC/PHY
5729 dev_dbg(&pf
->pdev
->dev
, "CoreR requested\n");
5730 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
5731 val
|= I40E_GLGEN_RTRIG_CORER_MASK
;
5732 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
5733 i40e_flush(&pf
->hw
);
5735 } else if (reset_flags
& BIT_ULL(__I40E_PF_RESET_REQUESTED
)) {
5737 /* Request a PF Reset
5739 * Resets only the PF-specific registers
5741 * This goes directly to the tear-down and rebuild of
5742 * the switch, since we need to do all the recovery as
5743 * for the Core Reset.
5745 dev_dbg(&pf
->pdev
->dev
, "PFR requested\n");
5746 i40e_handle_reset_warning(pf
);
5748 } else if (reset_flags
& BIT_ULL(__I40E_REINIT_REQUESTED
)) {
5751 /* Find the VSI(s) that requested a re-init */
5752 dev_info(&pf
->pdev
->dev
,
5753 "VSI reinit requested\n");
5754 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5755 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
5758 test_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
)) {
5759 i40e_vsi_reinit_locked(pf
->vsi
[v
]);
5760 clear_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
);
5763 } else if (reset_flags
& BIT_ULL(__I40E_DOWN_REQUESTED
)) {
5766 /* Find the VSI(s) that needs to be brought down */
5767 dev_info(&pf
->pdev
->dev
, "VSI down requested\n");
5768 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5769 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
5772 test_bit(__I40E_DOWN_REQUESTED
, &vsi
->state
)) {
5773 set_bit(__I40E_DOWN
, &vsi
->state
);
5775 clear_bit(__I40E_DOWN_REQUESTED
, &vsi
->state
);
5779 dev_info(&pf
->pdev
->dev
,
5780 "bad reset request 0x%08x\n", reset_flags
);
5784 #ifdef CONFIG_I40E_DCB
5786 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
5787 * @pf: board private structure
5788 * @old_cfg: current DCB config
5789 * @new_cfg: new DCB config
5791 bool i40e_dcb_need_reconfig(struct i40e_pf
*pf
,
5792 struct i40e_dcbx_config
*old_cfg
,
5793 struct i40e_dcbx_config
*new_cfg
)
5795 bool need_reconfig
= false;
5797 /* Check if ETS configuration has changed */
5798 if (memcmp(&new_cfg
->etscfg
,
5800 sizeof(new_cfg
->etscfg
))) {
5801 /* If Priority Table has changed reconfig is needed */
5802 if (memcmp(&new_cfg
->etscfg
.prioritytable
,
5803 &old_cfg
->etscfg
.prioritytable
,
5804 sizeof(new_cfg
->etscfg
.prioritytable
))) {
5805 need_reconfig
= true;
5806 dev_dbg(&pf
->pdev
->dev
, "ETS UP2TC changed.\n");
5809 if (memcmp(&new_cfg
->etscfg
.tcbwtable
,
5810 &old_cfg
->etscfg
.tcbwtable
,
5811 sizeof(new_cfg
->etscfg
.tcbwtable
)))
5812 dev_dbg(&pf
->pdev
->dev
, "ETS TC BW Table changed.\n");
5814 if (memcmp(&new_cfg
->etscfg
.tsatable
,
5815 &old_cfg
->etscfg
.tsatable
,
5816 sizeof(new_cfg
->etscfg
.tsatable
)))
5817 dev_dbg(&pf
->pdev
->dev
, "ETS TSA Table changed.\n");
5820 /* Check if PFC configuration has changed */
5821 if (memcmp(&new_cfg
->pfc
,
5823 sizeof(new_cfg
->pfc
))) {
5824 need_reconfig
= true;
5825 dev_dbg(&pf
->pdev
->dev
, "PFC config change detected.\n");
5828 /* Check if APP Table has changed */
5829 if (memcmp(&new_cfg
->app
,
5831 sizeof(new_cfg
->app
))) {
5832 need_reconfig
= true;
5833 dev_dbg(&pf
->pdev
->dev
, "APP Table change detected.\n");
5836 dev_dbg(&pf
->pdev
->dev
, "dcb need_reconfig=%d\n", need_reconfig
);
5837 return need_reconfig
;
5841 * i40e_handle_lldp_event - Handle LLDP Change MIB event
5842 * @pf: board private structure
5843 * @e: event info posted on ARQ
5845 static int i40e_handle_lldp_event(struct i40e_pf
*pf
,
5846 struct i40e_arq_event_info
*e
)
5848 struct i40e_aqc_lldp_get_mib
*mib
=
5849 (struct i40e_aqc_lldp_get_mib
*)&e
->desc
.params
.raw
;
5850 struct i40e_hw
*hw
= &pf
->hw
;
5851 struct i40e_dcbx_config tmp_dcbx_cfg
;
5852 bool need_reconfig
= false;
5856 /* Not DCB capable or capability disabled */
5857 if (!(pf
->flags
& I40E_FLAG_DCB_CAPABLE
))
5860 /* Ignore if event is not for Nearest Bridge */
5861 type
= ((mib
->type
>> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT
)
5862 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK
);
5863 dev_dbg(&pf
->pdev
->dev
, "LLDP event mib bridge type 0x%x\n", type
);
5864 if (type
!= I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
)
5867 /* Check MIB Type and return if event for Remote MIB update */
5868 type
= mib
->type
& I40E_AQ_LLDP_MIB_TYPE_MASK
;
5869 dev_dbg(&pf
->pdev
->dev
,
5870 "LLDP event mib type %s\n", type
? "remote" : "local");
5871 if (type
== I40E_AQ_LLDP_MIB_REMOTE
) {
5872 /* Update the remote cached instance and return */
5873 ret
= i40e_aq_get_dcb_config(hw
, I40E_AQ_LLDP_MIB_REMOTE
,
5874 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
,
5875 &hw
->remote_dcbx_config
);
5879 /* Store the old configuration */
5880 tmp_dcbx_cfg
= hw
->local_dcbx_config
;
5882 /* Reset the old DCBx configuration data */
5883 memset(&hw
->local_dcbx_config
, 0, sizeof(hw
->local_dcbx_config
));
5884 /* Get updated DCBX data from firmware */
5885 ret
= i40e_get_dcb_config(&pf
->hw
);
5887 dev_info(&pf
->pdev
->dev
,
5888 "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
5889 i40e_stat_str(&pf
->hw
, ret
),
5890 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
5894 /* No change detected in DCBX configs */
5895 if (!memcmp(&tmp_dcbx_cfg
, &hw
->local_dcbx_config
,
5896 sizeof(tmp_dcbx_cfg
))) {
5897 dev_dbg(&pf
->pdev
->dev
, "No change detected in DCBX configuration.\n");
5901 need_reconfig
= i40e_dcb_need_reconfig(pf
, &tmp_dcbx_cfg
,
5902 &hw
->local_dcbx_config
);
5904 i40e_dcbnl_flush_apps(pf
, &tmp_dcbx_cfg
, &hw
->local_dcbx_config
);
5909 /* Enable DCB tagging only when more than one TC */
5910 if (i40e_dcb_get_num_tc(&hw
->local_dcbx_config
) > 1)
5911 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
5913 pf
->flags
&= ~I40E_FLAG_DCB_ENABLED
;
5915 set_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
);
5916 /* Reconfiguration needed quiesce all VSIs */
5917 i40e_pf_quiesce_all_vsi(pf
);
5919 /* Changes in configuration update VEB/VSI */
5920 i40e_dcb_reconfigure(pf
);
5922 ret
= i40e_resume_port_tx(pf
);
5924 clear_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
);
5925 /* In case of error no point in resuming VSIs */
5929 /* Wait for the PF's queues to be disabled */
5930 ret
= i40e_pf_wait_queues_disabled(pf
);
5932 /* Schedule PF reset to recover */
5933 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
5934 i40e_service_event_schedule(pf
);
5936 i40e_pf_unquiesce_all_vsi(pf
);
5937 /* Notify the client for the DCB changes */
5938 i40e_notify_client_of_l2_param_changes(pf
->vsi
[pf
->lan_vsi
]);
5944 #endif /* CONFIG_I40E_DCB */
5947 * i40e_do_reset_safe - Protected reset path for userland calls.
5948 * @pf: board private structure
5949 * @reset_flags: which reset is requested
5952 void i40e_do_reset_safe(struct i40e_pf
*pf
, u32 reset_flags
)
5955 i40e_do_reset(pf
, reset_flags
);
5960 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
5961 * @pf: board private structure
5962 * @e: event info posted on ARQ
5964 * Handler for LAN Queue Overflow Event generated by the firmware for PF
5967 static void i40e_handle_lan_overflow_event(struct i40e_pf
*pf
,
5968 struct i40e_arq_event_info
*e
)
5970 struct i40e_aqc_lan_overflow
*data
=
5971 (struct i40e_aqc_lan_overflow
*)&e
->desc
.params
.raw
;
5972 u32 queue
= le32_to_cpu(data
->prtdcb_rupto
);
5973 u32 qtx_ctl
= le32_to_cpu(data
->otx_ctl
);
5974 struct i40e_hw
*hw
= &pf
->hw
;
5978 dev_dbg(&pf
->pdev
->dev
, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
5981 /* Queue belongs to VF, find the VF and issue VF reset */
5982 if (((qtx_ctl
& I40E_QTX_CTL_PFVF_Q_MASK
)
5983 >> I40E_QTX_CTL_PFVF_Q_SHIFT
) == I40E_QTX_CTL_VF_QUEUE
) {
5984 vf_id
= (u16
)((qtx_ctl
& I40E_QTX_CTL_VFVM_INDX_MASK
)
5985 >> I40E_QTX_CTL_VFVM_INDX_SHIFT
);
5986 vf_id
-= hw
->func_caps
.vf_base_id
;
5987 vf
= &pf
->vf
[vf_id
];
5988 i40e_vc_notify_vf_reset(vf
);
5989 /* Allow VF to process pending reset notification */
5991 i40e_reset_vf(vf
, false);
5996 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
5997 * @pf: board private structure
5999 u32
i40e_get_cur_guaranteed_fd_count(struct i40e_pf
*pf
)
6003 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
6004 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
);
6009 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
6010 * @pf: board private structure
6012 u32
i40e_get_current_fd_count(struct i40e_pf
*pf
)
6016 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
6017 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
) +
6018 ((val
& I40E_PFQF_FDSTAT_BEST_CNT_MASK
) >>
6019 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT
);
6024 * i40e_get_global_fd_count - Get total FD filters programmed on device
6025 * @pf: board private structure
6027 u32
i40e_get_global_fd_count(struct i40e_pf
*pf
)
6031 val
= rd32(&pf
->hw
, I40E_GLQF_FDCNT_0
);
6032 fcnt_prog
= (val
& I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK
) +
6033 ((val
& I40E_GLQF_FDCNT_0_BESTCNT_MASK
) >>
6034 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT
);
6039 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
6040 * @pf: board private structure
6042 void i40e_fdir_check_and_reenable(struct i40e_pf
*pf
)
6044 struct i40e_fdir_filter
*filter
;
6045 u32 fcnt_prog
, fcnt_avail
;
6046 struct hlist_node
*node
;
6048 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
6051 /* Check if, FD SB or ATR was auto disabled and if there is enough room
6054 fcnt_prog
= i40e_get_global_fd_count(pf
);
6055 fcnt_avail
= pf
->fdir_pf_filter_count
;
6056 if ((fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM
)) ||
6057 (pf
->fd_add_err
== 0) ||
6058 (i40e_get_current_atr_cnt(pf
) < pf
->fd_atr_cnt
)) {
6059 if ((pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) &&
6060 (pf
->auto_disable_flags
& I40E_FLAG_FD_SB_ENABLED
)) {
6061 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
6062 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
6063 dev_info(&pf
->pdev
->dev
, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
6067 /* Wait for some more space to be available to turn on ATR. We also
6068 * must check that no existing ntuple rules for TCP are in effect
6070 if (fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM
* 2)) {
6071 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
6072 (pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
6073 (pf
->fd_tcp_rule
== 0)) {
6074 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
6075 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
6076 dev_info(&pf
->pdev
->dev
, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n");
6080 /* if hw had a problem adding a filter, delete it */
6081 if (pf
->fd_inv
> 0) {
6082 hlist_for_each_entry_safe(filter
, node
,
6083 &pf
->fdir_filter_list
, fdir_node
) {
6084 if (filter
->fd_id
== pf
->fd_inv
) {
6085 hlist_del(&filter
->fdir_node
);
6087 pf
->fdir_pf_active_filters
--;
6093 #define I40E_MIN_FD_FLUSH_INTERVAL 10
6094 #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
6096 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
6097 * @pf: board private structure
6099 static void i40e_fdir_flush_and_replay(struct i40e_pf
*pf
)
6101 unsigned long min_flush_time
;
6102 int flush_wait_retry
= 50;
6103 bool disable_atr
= false;
6107 if (!time_after(jiffies
, pf
->fd_flush_timestamp
+
6108 (I40E_MIN_FD_FLUSH_INTERVAL
* HZ
)))
6111 /* If the flush is happening too quick and we have mostly SB rules we
6112 * should not re-enable ATR for some time.
6114 min_flush_time
= pf
->fd_flush_timestamp
+
6115 (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE
* HZ
);
6116 fd_room
= pf
->fdir_pf_filter_count
- pf
->fdir_pf_active_filters
;
6118 if (!(time_after(jiffies
, min_flush_time
)) &&
6119 (fd_room
< I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR
)) {
6120 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
6121 dev_info(&pf
->pdev
->dev
, "ATR disabled, not enough FD filter space.\n");
6125 pf
->fd_flush_timestamp
= jiffies
;
6126 pf
->auto_disable_flags
|= I40E_FLAG_FD_ATR_ENABLED
;
6127 /* flush all filters */
6128 wr32(&pf
->hw
, I40E_PFQF_CTL_1
,
6129 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
);
6130 i40e_flush(&pf
->hw
);
6134 /* Check FD flush status every 5-6msec */
6135 usleep_range(5000, 6000);
6136 reg
= rd32(&pf
->hw
, I40E_PFQF_CTL_1
);
6137 if (!(reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
))
6139 } while (flush_wait_retry
--);
6140 if (reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
) {
6141 dev_warn(&pf
->pdev
->dev
, "FD table did not flush, needs more time\n");
6143 /* replay sideband filters */
6144 i40e_fdir_filter_restore(pf
->vsi
[pf
->lan_vsi
]);
6146 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
6147 clear_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
);
6148 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
6149 dev_info(&pf
->pdev
->dev
, "FD Filter table flushed and FD-SB replayed.\n");
6154 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
6155 * @pf: board private structure
6157 u32
i40e_get_current_atr_cnt(struct i40e_pf
*pf
)
6159 return i40e_get_current_fd_count(pf
) - pf
->fdir_pf_active_filters
;
6162 /* We can see up to 256 filter programming desc in transit if the filters are
6163 * being applied really fast; before we see the first
6164 * filter miss error on Rx queue 0. Accumulating enough error messages before
6165 * reacting will make sure we don't cause flush too often.
6167 #define I40E_MAX_FD_PROGRAM_ERROR 256
6170 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
6171 * @pf: board private structure
6173 static void i40e_fdir_reinit_subtask(struct i40e_pf
*pf
)
6176 /* if interface is down do nothing */
6177 if (test_bit(__I40E_DOWN
, &pf
->state
))
6180 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
6181 i40e_fdir_flush_and_replay(pf
);
6183 i40e_fdir_check_and_reenable(pf
);
6188 * i40e_vsi_link_event - notify VSI of a link event
6189 * @vsi: vsi to be notified
6190 * @link_up: link up or down
6192 static void i40e_vsi_link_event(struct i40e_vsi
*vsi
, bool link_up
)
6194 if (!vsi
|| test_bit(__I40E_DOWN
, &vsi
->state
))
6197 switch (vsi
->type
) {
6202 if (!vsi
->netdev
|| !vsi
->netdev_registered
)
6206 netif_carrier_on(vsi
->netdev
);
6207 netif_tx_wake_all_queues(vsi
->netdev
);
6209 netif_carrier_off(vsi
->netdev
);
6210 netif_tx_stop_all_queues(vsi
->netdev
);
6214 case I40E_VSI_SRIOV
:
6215 case I40E_VSI_VMDQ2
:
6217 case I40E_VSI_IWARP
:
6218 case I40E_VSI_MIRROR
:
6220 /* there is no notification for other VSIs */
6226 * i40e_veb_link_event - notify elements on the veb of a link event
6227 * @veb: veb to be notified
6228 * @link_up: link up or down
6230 static void i40e_veb_link_event(struct i40e_veb
*veb
, bool link_up
)
6235 if (!veb
|| !veb
->pf
)
6239 /* depth first... */
6240 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
6241 if (pf
->veb
[i
] && (pf
->veb
[i
]->uplink_seid
== veb
->seid
))
6242 i40e_veb_link_event(pf
->veb
[i
], link_up
);
6244 /* ... now the local VSIs */
6245 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
6246 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->uplink_seid
== veb
->seid
))
6247 i40e_vsi_link_event(pf
->vsi
[i
], link_up
);
6251 * i40e_link_event - Update netif_carrier status
6252 * @pf: board private structure
6254 static void i40e_link_event(struct i40e_pf
*pf
)
6256 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
6257 u8 new_link_speed
, old_link_speed
;
6259 bool new_link
, old_link
;
6261 /* save off old link status information */
6262 pf
->hw
.phy
.link_info_old
= pf
->hw
.phy
.link_info
;
6264 /* set this to force the get_link_status call to refresh state */
6265 pf
->hw
.phy
.get_link_info
= true;
6267 old_link
= (pf
->hw
.phy
.link_info_old
.link_info
& I40E_AQ_LINK_UP
);
6269 status
= i40e_get_link_status(&pf
->hw
, &new_link
);
6271 dev_dbg(&pf
->pdev
->dev
, "couldn't get link state, status: %d\n",
6276 old_link_speed
= pf
->hw
.phy
.link_info_old
.link_speed
;
6277 new_link_speed
= pf
->hw
.phy
.link_info
.link_speed
;
6279 if (new_link
== old_link
&&
6280 new_link_speed
== old_link_speed
&&
6281 (test_bit(__I40E_DOWN
, &vsi
->state
) ||
6282 new_link
== netif_carrier_ok(vsi
->netdev
)))
6285 if (!test_bit(__I40E_DOWN
, &vsi
->state
))
6286 i40e_print_link_message(vsi
, new_link
);
6288 /* Notify the base of the switch tree connected to
6289 * the link. Floating VEBs are not notified.
6291 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
6292 i40e_veb_link_event(pf
->veb
[pf
->lan_veb
], new_link
);
6294 i40e_vsi_link_event(vsi
, new_link
);
6297 i40e_vc_notify_link_state(pf
);
6299 if (pf
->flags
& I40E_FLAG_PTP
)
6300 i40e_ptp_set_increment(pf
);
6304 * i40e_watchdog_subtask - periodic checks not using event driven response
6305 * @pf: board private structure
6307 static void i40e_watchdog_subtask(struct i40e_pf
*pf
)
6311 /* if interface is down do nothing */
6312 if (test_bit(__I40E_DOWN
, &pf
->state
) ||
6313 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
6316 /* make sure we don't do these things too often */
6317 if (time_before(jiffies
, (pf
->service_timer_previous
+
6318 pf
->service_timer_period
)))
6320 pf
->service_timer_previous
= jiffies
;
6322 if (pf
->flags
& I40E_FLAG_LINK_POLLING_ENABLED
)
6323 i40e_link_event(pf
);
6325 /* Update the stats for active netdevs so the network stack
6326 * can look at updated numbers whenever it cares to
6328 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
6329 if (pf
->vsi
[i
] && pf
->vsi
[i
]->netdev
)
6330 i40e_update_stats(pf
->vsi
[i
]);
6332 if (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
) {
6333 /* Update the stats for the active switching components */
6334 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
6336 i40e_update_veb_stats(pf
->veb
[i
]);
6339 i40e_ptp_rx_hang(pf
->vsi
[pf
->lan_vsi
]);
6343 * i40e_reset_subtask - Set up for resetting the device and driver
6344 * @pf: board private structure
6346 static void i40e_reset_subtask(struct i40e_pf
*pf
)
6348 u32 reset_flags
= 0;
6351 if (test_bit(__I40E_REINIT_REQUESTED
, &pf
->state
)) {
6352 reset_flags
|= BIT(__I40E_REINIT_REQUESTED
);
6353 clear_bit(__I40E_REINIT_REQUESTED
, &pf
->state
);
6355 if (test_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
)) {
6356 reset_flags
|= BIT(__I40E_PF_RESET_REQUESTED
);
6357 clear_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
6359 if (test_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
)) {
6360 reset_flags
|= BIT(__I40E_CORE_RESET_REQUESTED
);
6361 clear_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
);
6363 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
)) {
6364 reset_flags
|= BIT(__I40E_GLOBAL_RESET_REQUESTED
);
6365 clear_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
);
6367 if (test_bit(__I40E_DOWN_REQUESTED
, &pf
->state
)) {
6368 reset_flags
|= BIT(__I40E_DOWN_REQUESTED
);
6369 clear_bit(__I40E_DOWN_REQUESTED
, &pf
->state
);
6372 /* If there's a recovery already waiting, it takes
6373 * precedence before starting a new reset sequence.
6375 if (test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
)) {
6376 i40e_handle_reset_warning(pf
);
6380 /* If we're already down or resetting, just bail */
6382 !test_bit(__I40E_DOWN
, &pf
->state
) &&
6383 !test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
6384 i40e_do_reset(pf
, reset_flags
);
6391 * i40e_handle_link_event - Handle link event
6392 * @pf: board private structure
6393 * @e: event info posted on ARQ
6395 static void i40e_handle_link_event(struct i40e_pf
*pf
,
6396 struct i40e_arq_event_info
*e
)
6398 struct i40e_aqc_get_link_status
*status
=
6399 (struct i40e_aqc_get_link_status
*)&e
->desc
.params
.raw
;
6401 /* Do a new status request to re-enable LSE reporting
6402 * and load new status information into the hw struct
6403 * This completely ignores any state information
6404 * in the ARQ event info, instead choosing to always
6405 * issue the AQ update link status command.
6407 i40e_link_event(pf
);
6409 /* check for unqualified module, if link is down */
6410 if ((status
->link_info
& I40E_AQ_MEDIA_AVAILABLE
) &&
6411 (!(status
->an_info
& I40E_AQ_QUALIFIED_MODULE
)) &&
6412 (!(status
->link_info
& I40E_AQ_LINK_UP
)))
6413 dev_err(&pf
->pdev
->dev
,
6414 "The driver failed to link because an unqualified module was detected.\n");
6418 * i40e_clean_adminq_subtask - Clean the AdminQ rings
6419 * @pf: board private structure
6421 static void i40e_clean_adminq_subtask(struct i40e_pf
*pf
)
6423 struct i40e_arq_event_info event
;
6424 struct i40e_hw
*hw
= &pf
->hw
;
6431 /* Do not run clean AQ when PF reset fails */
6432 if (test_bit(__I40E_RESET_FAILED
, &pf
->state
))
6435 /* check for error indications */
6436 val
= rd32(&pf
->hw
, pf
->hw
.aq
.arq
.len
);
6438 if (val
& I40E_PF_ARQLEN_ARQVFE_MASK
) {
6439 if (hw
->debug_mask
& I40E_DEBUG_AQ
)
6440 dev_info(&pf
->pdev
->dev
, "ARQ VF Error detected\n");
6441 val
&= ~I40E_PF_ARQLEN_ARQVFE_MASK
;
6443 if (val
& I40E_PF_ARQLEN_ARQOVFL_MASK
) {
6444 if (hw
->debug_mask
& I40E_DEBUG_AQ
)
6445 dev_info(&pf
->pdev
->dev
, "ARQ Overflow Error detected\n");
6446 val
&= ~I40E_PF_ARQLEN_ARQOVFL_MASK
;
6447 pf
->arq_overflows
++;
6449 if (val
& I40E_PF_ARQLEN_ARQCRIT_MASK
) {
6450 if (hw
->debug_mask
& I40E_DEBUG_AQ
)
6451 dev_info(&pf
->pdev
->dev
, "ARQ Critical Error detected\n");
6452 val
&= ~I40E_PF_ARQLEN_ARQCRIT_MASK
;
6455 wr32(&pf
->hw
, pf
->hw
.aq
.arq
.len
, val
);
6457 val
= rd32(&pf
->hw
, pf
->hw
.aq
.asq
.len
);
6459 if (val
& I40E_PF_ATQLEN_ATQVFE_MASK
) {
6460 if (pf
->hw
.debug_mask
& I40E_DEBUG_AQ
)
6461 dev_info(&pf
->pdev
->dev
, "ASQ VF Error detected\n");
6462 val
&= ~I40E_PF_ATQLEN_ATQVFE_MASK
;
6464 if (val
& I40E_PF_ATQLEN_ATQOVFL_MASK
) {
6465 if (pf
->hw
.debug_mask
& I40E_DEBUG_AQ
)
6466 dev_info(&pf
->pdev
->dev
, "ASQ Overflow Error detected\n");
6467 val
&= ~I40E_PF_ATQLEN_ATQOVFL_MASK
;
6469 if (val
& I40E_PF_ATQLEN_ATQCRIT_MASK
) {
6470 if (pf
->hw
.debug_mask
& I40E_DEBUG_AQ
)
6471 dev_info(&pf
->pdev
->dev
, "ASQ Critical Error detected\n");
6472 val
&= ~I40E_PF_ATQLEN_ATQCRIT_MASK
;
6475 wr32(&pf
->hw
, pf
->hw
.aq
.asq
.len
, val
);
6477 event
.buf_len
= I40E_MAX_AQ_BUF_SIZE
;
6478 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
6483 ret
= i40e_clean_arq_element(hw
, &event
, &pending
);
6484 if (ret
== I40E_ERR_ADMIN_QUEUE_NO_WORK
)
6487 dev_info(&pf
->pdev
->dev
, "ARQ event error %d\n", ret
);
6491 opcode
= le16_to_cpu(event
.desc
.opcode
);
6494 case i40e_aqc_opc_get_link_status
:
6495 i40e_handle_link_event(pf
, &event
);
6497 case i40e_aqc_opc_send_msg_to_pf
:
6498 ret
= i40e_vc_process_vf_msg(pf
,
6499 le16_to_cpu(event
.desc
.retval
),
6500 le32_to_cpu(event
.desc
.cookie_high
),
6501 le32_to_cpu(event
.desc
.cookie_low
),
6505 case i40e_aqc_opc_lldp_update_mib
:
6506 dev_dbg(&pf
->pdev
->dev
, "ARQ: Update LLDP MIB event received\n");
6507 #ifdef CONFIG_I40E_DCB
6509 ret
= i40e_handle_lldp_event(pf
, &event
);
6511 #endif /* CONFIG_I40E_DCB */
6513 case i40e_aqc_opc_event_lan_overflow
:
6514 dev_dbg(&pf
->pdev
->dev
, "ARQ LAN queue overflow event received\n");
6515 i40e_handle_lan_overflow_event(pf
, &event
);
6517 case i40e_aqc_opc_send_msg_to_peer
:
6518 dev_info(&pf
->pdev
->dev
, "ARQ: Msg from other pf\n");
6520 case i40e_aqc_opc_nvm_erase
:
6521 case i40e_aqc_opc_nvm_update
:
6522 case i40e_aqc_opc_oem_post_update
:
6523 i40e_debug(&pf
->hw
, I40E_DEBUG_NVM
,
6524 "ARQ NVM operation 0x%04x completed\n",
6528 dev_info(&pf
->pdev
->dev
,
6529 "ARQ: Unknown event 0x%04x ignored\n",
6533 } while (pending
&& (i
++ < pf
->adminq_work_limit
));
6535 clear_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
);
6536 /* re-enable Admin queue interrupt cause */
6537 val
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
6538 val
|= I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
6539 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
6542 kfree(event
.msg_buf
);
6546 * i40e_verify_eeprom - make sure eeprom is good to use
6547 * @pf: board private structure
6549 static void i40e_verify_eeprom(struct i40e_pf
*pf
)
6553 err
= i40e_diag_eeprom_test(&pf
->hw
);
6555 /* retry in case of garbage read */
6556 err
= i40e_diag_eeprom_test(&pf
->hw
);
6558 dev_info(&pf
->pdev
->dev
, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
6560 set_bit(__I40E_BAD_EEPROM
, &pf
->state
);
6564 if (!err
&& test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
6565 dev_info(&pf
->pdev
->dev
, "eeprom check passed, Tx/Rx traffic enabled\n");
6566 clear_bit(__I40E_BAD_EEPROM
, &pf
->state
);
6571 * i40e_enable_pf_switch_lb
6572 * @pf: pointer to the PF structure
6574 * enable switch loop back or die - no point in a return value
6576 static void i40e_enable_pf_switch_lb(struct i40e_pf
*pf
)
6578 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
6579 struct i40e_vsi_context ctxt
;
6582 ctxt
.seid
= pf
->main_vsi_seid
;
6583 ctxt
.pf_num
= pf
->hw
.pf_id
;
6585 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
6587 dev_info(&pf
->pdev
->dev
,
6588 "couldn't get PF vsi config, err %s aq_err %s\n",
6589 i40e_stat_str(&pf
->hw
, ret
),
6590 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6593 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
6594 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
6595 ctxt
.info
.switch_id
|= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
6597 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
6599 dev_info(&pf
->pdev
->dev
,
6600 "update vsi switch failed, err %s aq_err %s\n",
6601 i40e_stat_str(&pf
->hw
, ret
),
6602 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6607 * i40e_disable_pf_switch_lb
6608 * @pf: pointer to the PF structure
6610 * disable switch loop back or die - no point in a return value
6612 static void i40e_disable_pf_switch_lb(struct i40e_pf
*pf
)
6614 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
6615 struct i40e_vsi_context ctxt
;
6618 ctxt
.seid
= pf
->main_vsi_seid
;
6619 ctxt
.pf_num
= pf
->hw
.pf_id
;
6621 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
6623 dev_info(&pf
->pdev
->dev
,
6624 "couldn't get PF vsi config, err %s aq_err %s\n",
6625 i40e_stat_str(&pf
->hw
, ret
),
6626 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6629 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
6630 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
6631 ctxt
.info
.switch_id
&= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
6633 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
6635 dev_info(&pf
->pdev
->dev
,
6636 "update vsi switch failed, err %s aq_err %s\n",
6637 i40e_stat_str(&pf
->hw
, ret
),
6638 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6643 * i40e_config_bridge_mode - Configure the HW bridge mode
6644 * @veb: pointer to the bridge instance
6646 * Configure the loop back mode for the LAN VSI that is downlink to the
6647 * specified HW bridge instance. It is expected this function is called
6648 * when a new HW bridge is instantiated.
6650 static void i40e_config_bridge_mode(struct i40e_veb
*veb
)
6652 struct i40e_pf
*pf
= veb
->pf
;
6654 if (pf
->hw
.debug_mask
& I40E_DEBUG_LAN
)
6655 dev_info(&pf
->pdev
->dev
, "enabling bridge mode: %s\n",
6656 veb
->bridge_mode
== BRIDGE_MODE_VEPA
? "VEPA" : "VEB");
6657 if (veb
->bridge_mode
& BRIDGE_MODE_VEPA
)
6658 i40e_disable_pf_switch_lb(pf
);
6660 i40e_enable_pf_switch_lb(pf
);
6664 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
6665 * @veb: pointer to the VEB instance
6667 * This is a recursive function that first builds the attached VSIs then
6668 * recurses in to build the next layer of VEB. We track the connections
6669 * through our own index numbers because the seid's from the HW could
6670 * change across the reset.
6672 static int i40e_reconstitute_veb(struct i40e_veb
*veb
)
6674 struct i40e_vsi
*ctl_vsi
= NULL
;
6675 struct i40e_pf
*pf
= veb
->pf
;
6679 /* build VSI that owns this VEB, temporarily attached to base VEB */
6680 for (v
= 0; v
< pf
->num_alloc_vsi
&& !ctl_vsi
; v
++) {
6682 pf
->vsi
[v
]->veb_idx
== veb
->idx
&&
6683 pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
6684 ctl_vsi
= pf
->vsi
[v
];
6689 dev_info(&pf
->pdev
->dev
,
6690 "missing owner VSI for veb_idx %d\n", veb
->idx
);
6692 goto end_reconstitute
;
6694 if (ctl_vsi
!= pf
->vsi
[pf
->lan_vsi
])
6695 ctl_vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
6696 ret
= i40e_add_vsi(ctl_vsi
);
6698 dev_info(&pf
->pdev
->dev
,
6699 "rebuild of veb_idx %d owner VSI failed: %d\n",
6701 goto end_reconstitute
;
6703 i40e_vsi_reset_stats(ctl_vsi
);
6705 /* create the VEB in the switch and move the VSI onto the VEB */
6706 ret
= i40e_add_veb(veb
, ctl_vsi
);
6708 goto end_reconstitute
;
6710 if (pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)
6711 veb
->bridge_mode
= BRIDGE_MODE_VEB
;
6713 veb
->bridge_mode
= BRIDGE_MODE_VEPA
;
6714 i40e_config_bridge_mode(veb
);
6716 /* create the remaining VSIs attached to this VEB */
6717 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
6718 if (!pf
->vsi
[v
] || pf
->vsi
[v
] == ctl_vsi
)
6721 if (pf
->vsi
[v
]->veb_idx
== veb
->idx
) {
6722 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
6724 vsi
->uplink_seid
= veb
->seid
;
6725 ret
= i40e_add_vsi(vsi
);
6727 dev_info(&pf
->pdev
->dev
,
6728 "rebuild of vsi_idx %d failed: %d\n",
6730 goto end_reconstitute
;
6732 i40e_vsi_reset_stats(vsi
);
6736 /* create any VEBs attached to this VEB - RECURSION */
6737 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
6738 if (pf
->veb
[veb_idx
] && pf
->veb
[veb_idx
]->veb_idx
== veb
->idx
) {
6739 pf
->veb
[veb_idx
]->uplink_seid
= veb
->seid
;
6740 ret
= i40e_reconstitute_veb(pf
->veb
[veb_idx
]);
6751 * i40e_get_capabilities - get info about the HW
6752 * @pf: the PF struct
6754 static int i40e_get_capabilities(struct i40e_pf
*pf
)
6756 struct i40e_aqc_list_capabilities_element_resp
*cap_buf
;
6761 buf_len
= 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp
);
6763 cap_buf
= kzalloc(buf_len
, GFP_KERNEL
);
6767 /* this loads the data into the hw struct for us */
6768 err
= i40e_aq_discover_capabilities(&pf
->hw
, cap_buf
, buf_len
,
6770 i40e_aqc_opc_list_func_capabilities
,
6772 /* data loaded, buffer no longer needed */
6775 if (pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_ENOMEM
) {
6776 /* retry with a larger buffer */
6777 buf_len
= data_size
;
6778 } else if (pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_OK
) {
6779 dev_info(&pf
->pdev
->dev
,
6780 "capability discovery failed, err %s aq_err %s\n",
6781 i40e_stat_str(&pf
->hw
, err
),
6782 i40e_aq_str(&pf
->hw
,
6783 pf
->hw
.aq
.asq_last_status
));
6788 if (pf
->hw
.debug_mask
& I40E_DEBUG_USER
)
6789 dev_info(&pf
->pdev
->dev
,
6790 "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",
6791 pf
->hw
.pf_id
, pf
->hw
.func_caps
.num_vfs
,
6792 pf
->hw
.func_caps
.num_msix_vectors
,
6793 pf
->hw
.func_caps
.num_msix_vectors_vf
,
6794 pf
->hw
.func_caps
.fd_filters_guaranteed
,
6795 pf
->hw
.func_caps
.fd_filters_best_effort
,
6796 pf
->hw
.func_caps
.num_tx_qp
,
6797 pf
->hw
.func_caps
.num_vsis
);
6799 #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
6800 + pf->hw.func_caps.num_vfs)
6801 if (pf
->hw
.revision_id
== 0 && (DEF_NUM_VSI
> pf
->hw
.func_caps
.num_vsis
)) {
6802 dev_info(&pf
->pdev
->dev
,
6803 "got num_vsis %d, setting num_vsis to %d\n",
6804 pf
->hw
.func_caps
.num_vsis
, DEF_NUM_VSI
);
6805 pf
->hw
.func_caps
.num_vsis
= DEF_NUM_VSI
;
6811 static int i40e_vsi_clear(struct i40e_vsi
*vsi
);
6814 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
6815 * @pf: board private structure
6817 static void i40e_fdir_sb_setup(struct i40e_pf
*pf
)
6819 struct i40e_vsi
*vsi
;
6821 /* quick workaround for an NVM issue that leaves a critical register
6824 if (!rd32(&pf
->hw
, I40E_GLQF_HKEY(0))) {
6825 static const u32 hkey
[] = {
6826 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
6827 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
6828 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
6832 for (i
= 0; i
<= I40E_GLQF_HKEY_MAX_INDEX
; i
++)
6833 wr32(&pf
->hw
, I40E_GLQF_HKEY(i
), hkey
[i
]);
6836 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
6839 /* find existing VSI and see if it needs configuring */
6840 vsi
= i40e_find_vsi_by_type(pf
, I40E_VSI_FDIR
);
6842 /* create a new VSI if none exists */
6844 vsi
= i40e_vsi_setup(pf
, I40E_VSI_FDIR
,
6845 pf
->vsi
[pf
->lan_vsi
]->seid
, 0);
6847 dev_info(&pf
->pdev
->dev
, "Couldn't create FDir VSI\n");
6848 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
6853 i40e_vsi_setup_irqhandler(vsi
, i40e_fdir_clean_ring
);
6857 * i40e_fdir_teardown - release the Flow Director resources
6858 * @pf: board private structure
6860 static void i40e_fdir_teardown(struct i40e_pf
*pf
)
6862 struct i40e_vsi
*vsi
;
6864 i40e_fdir_filter_exit(pf
);
6865 vsi
= i40e_find_vsi_by_type(pf
, I40E_VSI_FDIR
);
6867 i40e_vsi_release(vsi
);
6871 * i40e_prep_for_reset - prep for the core to reset
6872 * @pf: board private structure
6874 * Close up the VFs and other things in prep for PF Reset.
6876 static void i40e_prep_for_reset(struct i40e_pf
*pf
)
6878 struct i40e_hw
*hw
= &pf
->hw
;
6879 i40e_status ret
= 0;
6882 clear_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
);
6883 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
))
6885 if (i40e_check_asq_alive(&pf
->hw
))
6886 i40e_vc_notify_reset(pf
);
6888 dev_dbg(&pf
->pdev
->dev
, "Tearing down internal switch for reset\n");
6890 /* quiesce the VSIs and their queues that are not already DOWN */
6891 i40e_pf_quiesce_all_vsi(pf
);
6893 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
6895 pf
->vsi
[v
]->seid
= 0;
6898 i40e_shutdown_adminq(&pf
->hw
);
6900 /* call shutdown HMC */
6901 if (hw
->hmc
.hmc_obj
) {
6902 ret
= i40e_shutdown_lan_hmc(hw
);
6904 dev_warn(&pf
->pdev
->dev
,
6905 "shutdown_lan_hmc failed: %d\n", ret
);
6910 * i40e_send_version - update firmware with driver version
6913 static void i40e_send_version(struct i40e_pf
*pf
)
6915 struct i40e_driver_version dv
;
6917 dv
.major_version
= DRV_VERSION_MAJOR
;
6918 dv
.minor_version
= DRV_VERSION_MINOR
;
6919 dv
.build_version
= DRV_VERSION_BUILD
;
6920 dv
.subbuild_version
= 0;
6921 strlcpy(dv
.driver_string
, DRV_VERSION
, sizeof(dv
.driver_string
));
6922 i40e_aq_send_driver_version(&pf
->hw
, &dv
, NULL
);
6926 * i40e_reset_and_rebuild - reset and rebuild using a saved config
6927 * @pf: board private structure
6928 * @reinit: if the Main VSI needs to re-initialized.
6930 static void i40e_reset_and_rebuild(struct i40e_pf
*pf
, bool reinit
)
6932 struct i40e_hw
*hw
= &pf
->hw
;
6933 u8 set_fc_aq_fail
= 0;
6938 /* Now we wait for GRST to settle out.
6939 * We don't have to delete the VEBs or VSIs from the hw switch
6940 * because the reset will make them disappear.
6942 ret
= i40e_pf_reset(hw
);
6944 dev_info(&pf
->pdev
->dev
, "PF reset failed, %d\n", ret
);
6945 set_bit(__I40E_RESET_FAILED
, &pf
->state
);
6946 goto clear_recovery
;
6950 if (test_bit(__I40E_DOWN
, &pf
->state
))
6951 goto clear_recovery
;
6952 dev_dbg(&pf
->pdev
->dev
, "Rebuilding internal switch\n");
6954 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
6955 ret
= i40e_init_adminq(&pf
->hw
);
6957 dev_info(&pf
->pdev
->dev
, "Rebuild AdminQ failed, err %s aq_err %s\n",
6958 i40e_stat_str(&pf
->hw
, ret
),
6959 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6960 goto clear_recovery
;
6963 /* re-verify the eeprom if we just had an EMP reset */
6964 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED
, &pf
->state
))
6965 i40e_verify_eeprom(pf
);
6967 i40e_clear_pxe_mode(hw
);
6968 ret
= i40e_get_capabilities(pf
);
6970 goto end_core_reset
;
6972 ret
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
6973 hw
->func_caps
.num_rx_qp
,
6974 pf
->fcoe_hmc_cntx_num
, pf
->fcoe_hmc_filt_num
);
6976 dev_info(&pf
->pdev
->dev
, "init_lan_hmc failed: %d\n", ret
);
6977 goto end_core_reset
;
6979 ret
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
6981 dev_info(&pf
->pdev
->dev
, "configure_lan_hmc failed: %d\n", ret
);
6982 goto end_core_reset
;
6985 #ifdef CONFIG_I40E_DCB
6986 ret
= i40e_init_pf_dcb(pf
);
6988 dev_info(&pf
->pdev
->dev
, "DCB init failed %d, disabled\n", ret
);
6989 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
6990 /* Continue without DCB enabled */
6992 #endif /* CONFIG_I40E_DCB */
6994 i40e_init_pf_fcoe(pf
);
6997 /* do basic switch setup */
6998 ret
= i40e_setup_pf_switch(pf
, reinit
);
7000 goto end_core_reset
;
7002 /* The driver only wants link up/down and module qualification
7003 * reports from firmware. Note the negative logic.
7005 ret
= i40e_aq_set_phy_int_mask(&pf
->hw
,
7006 ~(I40E_AQ_EVENT_LINK_UPDOWN
|
7007 I40E_AQ_EVENT_MEDIA_NA
|
7008 I40E_AQ_EVENT_MODULE_QUAL_FAIL
), NULL
);
7010 dev_info(&pf
->pdev
->dev
, "set phy mask fail, err %s aq_err %s\n",
7011 i40e_stat_str(&pf
->hw
, ret
),
7012 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
7014 /* make sure our flow control settings are restored */
7015 ret
= i40e_set_fc(&pf
->hw
, &set_fc_aq_fail
, true);
7017 dev_dbg(&pf
->pdev
->dev
, "setting flow control: ret = %s last_status = %s\n",
7018 i40e_stat_str(&pf
->hw
, ret
),
7019 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
7021 /* Rebuild the VSIs and VEBs that existed before reset.
7022 * They are still in our local switch element arrays, so only
7023 * need to rebuild the switch model in the HW.
7025 * If there were VEBs but the reconstitution failed, we'll try
7026 * try to recover minimal use by getting the basic PF VSI working.
7028 if (pf
->vsi
[pf
->lan_vsi
]->uplink_seid
!= pf
->mac_seid
) {
7029 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild switch\n");
7030 /* find the one VEB connected to the MAC, and find orphans */
7031 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
7035 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
||
7036 pf
->veb
[v
]->uplink_seid
== 0) {
7037 ret
= i40e_reconstitute_veb(pf
->veb
[v
]);
7042 /* If Main VEB failed, we're in deep doodoo,
7043 * so give up rebuilding the switch and set up
7044 * for minimal rebuild of PF VSI.
7045 * If orphan failed, we'll report the error
7046 * but try to keep going.
7048 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
) {
7049 dev_info(&pf
->pdev
->dev
,
7050 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
7052 pf
->vsi
[pf
->lan_vsi
]->uplink_seid
7055 } else if (pf
->veb
[v
]->uplink_seid
== 0) {
7056 dev_info(&pf
->pdev
->dev
,
7057 "rebuild of orphan VEB failed: %d\n",
7064 if (pf
->vsi
[pf
->lan_vsi
]->uplink_seid
== pf
->mac_seid
) {
7065 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild PF VSI\n");
7066 /* no VEB, so rebuild only the Main VSI */
7067 ret
= i40e_add_vsi(pf
->vsi
[pf
->lan_vsi
]);
7069 dev_info(&pf
->pdev
->dev
,
7070 "rebuild of Main VSI failed: %d\n", ret
);
7071 goto end_core_reset
;
7075 /* Reconfigure hardware for allowing smaller MSS in the case
7076 * of TSO, so that we avoid the MDD being fired and causing
7077 * a reset in the case of small MSS+TSO.
7079 #define I40E_REG_MSS 0x000E64DC
7080 #define I40E_REG_MSS_MIN_MASK 0x3FF0000
7081 #define I40E_64BYTE_MSS 0x400000
7082 val
= rd32(hw
, I40E_REG_MSS
);
7083 if ((val
& I40E_REG_MSS_MIN_MASK
) > I40E_64BYTE_MSS
) {
7084 val
&= ~I40E_REG_MSS_MIN_MASK
;
7085 val
|= I40E_64BYTE_MSS
;
7086 wr32(hw
, I40E_REG_MSS
, val
);
7089 if (pf
->flags
& I40E_FLAG_RESTART_AUTONEG
) {
7091 ret
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
7093 dev_info(&pf
->pdev
->dev
, "link restart failed, err %s aq_err %s\n",
7094 i40e_stat_str(&pf
->hw
, ret
),
7095 i40e_aq_str(&pf
->hw
,
7096 pf
->hw
.aq
.asq_last_status
));
7098 /* reinit the misc interrupt */
7099 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
7100 ret
= i40e_setup_misc_vector(pf
);
7102 /* Add a filter to drop all Flow control frames from any VSI from being
7103 * transmitted. By doing so we stop a malicious VF from sending out
7104 * PAUSE or PFC frames and potentially controlling traffic for other
7106 * The FW can still send Flow control frames if enabled.
7108 i40e_add_filter_to_drop_tx_flow_control_frames(&pf
->hw
,
7111 /* restart the VSIs that were rebuilt and running before the reset */
7112 i40e_pf_unquiesce_all_vsi(pf
);
7114 if (pf
->num_alloc_vfs
) {
7115 for (v
= 0; v
< pf
->num_alloc_vfs
; v
++)
7116 i40e_reset_vf(&pf
->vf
[v
], true);
7119 /* tell the firmware that we're starting */
7120 i40e_send_version(pf
);
7123 clear_bit(__I40E_RESET_FAILED
, &pf
->state
);
7125 clear_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
);
7129 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
7130 * @pf: board private structure
7132 * Close up the VFs and other things in prep for a Core Reset,
7133 * then get ready to rebuild the world.
7135 static void i40e_handle_reset_warning(struct i40e_pf
*pf
)
7137 i40e_prep_for_reset(pf
);
7138 i40e_reset_and_rebuild(pf
, false);
7142 * i40e_handle_mdd_event
7143 * @pf: pointer to the PF structure
7145 * Called from the MDD irq handler to identify possibly malicious vfs
7147 static void i40e_handle_mdd_event(struct i40e_pf
*pf
)
7149 struct i40e_hw
*hw
= &pf
->hw
;
7150 bool mdd_detected
= false;
7151 bool pf_mdd_detected
= false;
7156 if (!test_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
))
7159 /* find what triggered the MDD event */
7160 reg
= rd32(hw
, I40E_GL_MDET_TX
);
7161 if (reg
& I40E_GL_MDET_TX_VALID_MASK
) {
7162 u8 pf_num
= (reg
& I40E_GL_MDET_TX_PF_NUM_MASK
) >>
7163 I40E_GL_MDET_TX_PF_NUM_SHIFT
;
7164 u16 vf_num
= (reg
& I40E_GL_MDET_TX_VF_NUM_MASK
) >>
7165 I40E_GL_MDET_TX_VF_NUM_SHIFT
;
7166 u8 event
= (reg
& I40E_GL_MDET_TX_EVENT_MASK
) >>
7167 I40E_GL_MDET_TX_EVENT_SHIFT
;
7168 u16 queue
= ((reg
& I40E_GL_MDET_TX_QUEUE_MASK
) >>
7169 I40E_GL_MDET_TX_QUEUE_SHIFT
) -
7170 pf
->hw
.func_caps
.base_queue
;
7171 if (netif_msg_tx_err(pf
))
7172 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
7173 event
, queue
, pf_num
, vf_num
);
7174 wr32(hw
, I40E_GL_MDET_TX
, 0xffffffff);
7175 mdd_detected
= true;
7177 reg
= rd32(hw
, I40E_GL_MDET_RX
);
7178 if (reg
& I40E_GL_MDET_RX_VALID_MASK
) {
7179 u8 func
= (reg
& I40E_GL_MDET_RX_FUNCTION_MASK
) >>
7180 I40E_GL_MDET_RX_FUNCTION_SHIFT
;
7181 u8 event
= (reg
& I40E_GL_MDET_RX_EVENT_MASK
) >>
7182 I40E_GL_MDET_RX_EVENT_SHIFT
;
7183 u16 queue
= ((reg
& I40E_GL_MDET_RX_QUEUE_MASK
) >>
7184 I40E_GL_MDET_RX_QUEUE_SHIFT
) -
7185 pf
->hw
.func_caps
.base_queue
;
7186 if (netif_msg_rx_err(pf
))
7187 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
7188 event
, queue
, func
);
7189 wr32(hw
, I40E_GL_MDET_RX
, 0xffffffff);
7190 mdd_detected
= true;
7194 reg
= rd32(hw
, I40E_PF_MDET_TX
);
7195 if (reg
& I40E_PF_MDET_TX_VALID_MASK
) {
7196 wr32(hw
, I40E_PF_MDET_TX
, 0xFFFF);
7197 dev_info(&pf
->pdev
->dev
, "TX driver issue detected, PF reset issued\n");
7198 pf_mdd_detected
= true;
7200 reg
= rd32(hw
, I40E_PF_MDET_RX
);
7201 if (reg
& I40E_PF_MDET_RX_VALID_MASK
) {
7202 wr32(hw
, I40E_PF_MDET_RX
, 0xFFFF);
7203 dev_info(&pf
->pdev
->dev
, "RX driver issue detected, PF reset issued\n");
7204 pf_mdd_detected
= true;
7206 /* Queue belongs to the PF, initiate a reset */
7207 if (pf_mdd_detected
) {
7208 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
7209 i40e_service_event_schedule(pf
);
7213 /* see if one of the VFs needs its hand slapped */
7214 for (i
= 0; i
< pf
->num_alloc_vfs
&& mdd_detected
; i
++) {
7216 reg
= rd32(hw
, I40E_VP_MDET_TX(i
));
7217 if (reg
& I40E_VP_MDET_TX_VALID_MASK
) {
7218 wr32(hw
, I40E_VP_MDET_TX(i
), 0xFFFF);
7219 vf
->num_mdd_events
++;
7220 dev_info(&pf
->pdev
->dev
, "TX driver issue detected on VF %d\n",
7224 reg
= rd32(hw
, I40E_VP_MDET_RX(i
));
7225 if (reg
& I40E_VP_MDET_RX_VALID_MASK
) {
7226 wr32(hw
, I40E_VP_MDET_RX(i
), 0xFFFF);
7227 vf
->num_mdd_events
++;
7228 dev_info(&pf
->pdev
->dev
, "RX driver issue detected on VF %d\n",
7232 if (vf
->num_mdd_events
> I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED
) {
7233 dev_info(&pf
->pdev
->dev
,
7234 "Too many MDD events on VF %d, disabled\n", i
);
7235 dev_info(&pf
->pdev
->dev
,
7236 "Use PF Control I/F to re-enable the VF\n");
7237 set_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
);
7241 /* re-enable mdd interrupt cause */
7242 clear_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
);
7243 reg
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
7244 reg
|= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
7245 wr32(hw
, I40E_PFINT_ICR0_ENA
, reg
);
7250 * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
7251 * @pf: board private structure
7253 static void i40e_sync_udp_filters_subtask(struct i40e_pf
*pf
)
7255 struct i40e_hw
*hw
= &pf
->hw
;
7260 if (!(pf
->flags
& I40E_FLAG_UDP_FILTER_SYNC
))
7263 pf
->flags
&= ~I40E_FLAG_UDP_FILTER_SYNC
;
7265 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
7266 if (pf
->pending_udp_bitmap
& BIT_ULL(i
)) {
7267 pf
->pending_udp_bitmap
&= ~BIT_ULL(i
);
7268 port
= pf
->udp_ports
[i
].index
;
7270 ret
= i40e_aq_add_udp_tunnel(hw
, port
,
7271 pf
->udp_ports
[i
].type
,
7274 ret
= i40e_aq_del_udp_tunnel(hw
, i
, NULL
);
7277 dev_dbg(&pf
->pdev
->dev
,
7278 "%s %s port %d, index %d failed, err %s aq_err %s\n",
7279 pf
->udp_ports
[i
].type
? "vxlan" : "geneve",
7280 port
? "add" : "delete",
7282 i40e_stat_str(&pf
->hw
, ret
),
7283 i40e_aq_str(&pf
->hw
,
7284 pf
->hw
.aq
.asq_last_status
));
7285 pf
->udp_ports
[i
].index
= 0;
7292 * i40e_service_task - Run the driver's async subtasks
7293 * @work: pointer to work_struct containing our data
7295 static void i40e_service_task(struct work_struct
*work
)
7297 struct i40e_pf
*pf
= container_of(work
,
7300 unsigned long start_time
= jiffies
;
7302 /* don't bother with service tasks if a reset is in progress */
7303 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
)) {
7307 if (test_and_set_bit(__I40E_SERVICE_SCHED
, &pf
->state
))
7310 i40e_detect_recover_hung(pf
);
7311 i40e_sync_filters_subtask(pf
);
7312 i40e_reset_subtask(pf
);
7313 i40e_handle_mdd_event(pf
);
7314 i40e_vc_process_vflr_event(pf
);
7315 i40e_watchdog_subtask(pf
);
7316 i40e_fdir_reinit_subtask(pf
);
7317 i40e_client_subtask(pf
);
7318 i40e_sync_filters_subtask(pf
);
7319 i40e_sync_udp_filters_subtask(pf
);
7320 i40e_clean_adminq_subtask(pf
);
7322 /* flush memory to make sure state is correct before next watchdog */
7323 smp_mb__before_atomic();
7324 clear_bit(__I40E_SERVICE_SCHED
, &pf
->state
);
7326 /* If the tasks have taken longer than one timer cycle or there
7327 * is more work to be done, reschedule the service task now
7328 * rather than wait for the timer to tick again.
7330 if (time_after(jiffies
, (start_time
+ pf
->service_timer_period
)) ||
7331 test_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
) ||
7332 test_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
) ||
7333 test_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
))
7334 i40e_service_event_schedule(pf
);
7338 * i40e_service_timer - timer callback
7339 * @data: pointer to PF struct
7341 static void i40e_service_timer(unsigned long data
)
7343 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
7345 mod_timer(&pf
->service_timer
,
7346 round_jiffies(jiffies
+ pf
->service_timer_period
));
7347 i40e_service_event_schedule(pf
);
7351 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
7352 * @vsi: the VSI being configured
7354 static int i40e_set_num_rings_in_vsi(struct i40e_vsi
*vsi
)
7356 struct i40e_pf
*pf
= vsi
->back
;
7358 switch (vsi
->type
) {
7360 vsi
->alloc_queue_pairs
= pf
->num_lan_qps
;
7361 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
7362 I40E_REQ_DESCRIPTOR_MULTIPLE
);
7363 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
7364 vsi
->num_q_vectors
= pf
->num_lan_msix
;
7366 vsi
->num_q_vectors
= 1;
7371 vsi
->alloc_queue_pairs
= 1;
7372 vsi
->num_desc
= ALIGN(I40E_FDIR_RING_COUNT
,
7373 I40E_REQ_DESCRIPTOR_MULTIPLE
);
7374 vsi
->num_q_vectors
= pf
->num_fdsb_msix
;
7377 case I40E_VSI_VMDQ2
:
7378 vsi
->alloc_queue_pairs
= pf
->num_vmdq_qps
;
7379 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
7380 I40E_REQ_DESCRIPTOR_MULTIPLE
);
7381 vsi
->num_q_vectors
= pf
->num_vmdq_msix
;
7384 case I40E_VSI_SRIOV
:
7385 vsi
->alloc_queue_pairs
= pf
->num_vf_qps
;
7386 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
7387 I40E_REQ_DESCRIPTOR_MULTIPLE
);
7392 vsi
->alloc_queue_pairs
= pf
->num_fcoe_qps
;
7393 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
7394 I40E_REQ_DESCRIPTOR_MULTIPLE
);
7395 vsi
->num_q_vectors
= pf
->num_fcoe_msix
;
7398 #endif /* I40E_FCOE */
7408 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
7409 * @type: VSI pointer
7410 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
7412 * On error: returns error code (negative)
7413 * On success: returns 0
7415 static int i40e_vsi_alloc_arrays(struct i40e_vsi
*vsi
, bool alloc_qvectors
)
7420 /* allocate memory for both Tx and Rx ring pointers */
7421 size
= sizeof(struct i40e_ring
*) * vsi
->alloc_queue_pairs
* 2;
7422 vsi
->tx_rings
= kzalloc(size
, GFP_KERNEL
);
7425 vsi
->rx_rings
= &vsi
->tx_rings
[vsi
->alloc_queue_pairs
];
7427 if (alloc_qvectors
) {
7428 /* allocate memory for q_vector pointers */
7429 size
= sizeof(struct i40e_q_vector
*) * vsi
->num_q_vectors
;
7430 vsi
->q_vectors
= kzalloc(size
, GFP_KERNEL
);
7431 if (!vsi
->q_vectors
) {
7439 kfree(vsi
->tx_rings
);
7444 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
7445 * @pf: board private structure
7446 * @type: type of VSI
7448 * On error: returns error code (negative)
7449 * On success: returns vsi index in PF (positive)
7451 static int i40e_vsi_mem_alloc(struct i40e_pf
*pf
, enum i40e_vsi_type type
)
7454 struct i40e_vsi
*vsi
;
7458 /* Need to protect the allocation of the VSIs at the PF level */
7459 mutex_lock(&pf
->switch_mutex
);
7461 /* VSI list may be fragmented if VSI creation/destruction has
7462 * been happening. We can afford to do a quick scan to look
7463 * for any free VSIs in the list.
7465 * find next empty vsi slot, looping back around if necessary
7468 while (i
< pf
->num_alloc_vsi
&& pf
->vsi
[i
])
7470 if (i
>= pf
->num_alloc_vsi
) {
7472 while (i
< pf
->next_vsi
&& pf
->vsi
[i
])
7476 if (i
< pf
->num_alloc_vsi
&& !pf
->vsi
[i
]) {
7477 vsi_idx
= i
; /* Found one! */
7480 goto unlock_pf
; /* out of VSI slots! */
7484 vsi
= kzalloc(sizeof(*vsi
), GFP_KERNEL
);
7491 set_bit(__I40E_DOWN
, &vsi
->state
);
7494 vsi
->int_rate_limit
= 0;
7495 vsi
->rss_table_size
= (vsi
->type
== I40E_VSI_MAIN
) ?
7496 pf
->rss_table_size
: 64;
7497 vsi
->netdev_registered
= false;
7498 vsi
->work_limit
= I40E_DEFAULT_IRQ_WORK
;
7499 hash_init(vsi
->mac_filter_hash
);
7500 vsi
->irqs_ready
= false;
7502 ret
= i40e_set_num_rings_in_vsi(vsi
);
7506 ret
= i40e_vsi_alloc_arrays(vsi
, true);
7510 /* Setup default MSIX irq handler for VSI */
7511 i40e_vsi_setup_irqhandler(vsi
, i40e_msix_clean_rings
);
7513 /* Initialize VSI lock */
7514 spin_lock_init(&vsi
->mac_filter_hash_lock
);
7515 pf
->vsi
[vsi_idx
] = vsi
;
7520 pf
->next_vsi
= i
- 1;
7523 mutex_unlock(&pf
->switch_mutex
);
7528 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
7529 * @type: VSI pointer
7530 * @free_qvectors: a bool to specify if q_vectors need to be freed.
7532 * On error: returns error code (negative)
7533 * On success: returns 0
7535 static void i40e_vsi_free_arrays(struct i40e_vsi
*vsi
, bool free_qvectors
)
7537 /* free the ring and vector containers */
7538 if (free_qvectors
) {
7539 kfree(vsi
->q_vectors
);
7540 vsi
->q_vectors
= NULL
;
7542 kfree(vsi
->tx_rings
);
7543 vsi
->tx_rings
= NULL
;
7544 vsi
->rx_rings
= NULL
;
7548 * i40e_clear_rss_config_user - clear the user configured RSS hash keys
7550 * @vsi: Pointer to VSI structure
7552 static void i40e_clear_rss_config_user(struct i40e_vsi
*vsi
)
7557 kfree(vsi
->rss_hkey_user
);
7558 vsi
->rss_hkey_user
= NULL
;
7560 kfree(vsi
->rss_lut_user
);
7561 vsi
->rss_lut_user
= NULL
;
7565 * i40e_vsi_clear - Deallocate the VSI provided
7566 * @vsi: the VSI being un-configured
7568 static int i40e_vsi_clear(struct i40e_vsi
*vsi
)
7579 mutex_lock(&pf
->switch_mutex
);
7580 if (!pf
->vsi
[vsi
->idx
]) {
7581 dev_err(&pf
->pdev
->dev
, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
7582 vsi
->idx
, vsi
->idx
, vsi
, vsi
->type
);
7586 if (pf
->vsi
[vsi
->idx
] != vsi
) {
7587 dev_err(&pf
->pdev
->dev
,
7588 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
7589 pf
->vsi
[vsi
->idx
]->idx
,
7591 pf
->vsi
[vsi
->idx
]->type
,
7592 vsi
->idx
, vsi
, vsi
->type
);
7596 /* updates the PF for this cleared vsi */
7597 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
7598 i40e_put_lump(pf
->irq_pile
, vsi
->base_vector
, vsi
->idx
);
7600 i40e_vsi_free_arrays(vsi
, true);
7601 i40e_clear_rss_config_user(vsi
);
7603 pf
->vsi
[vsi
->idx
] = NULL
;
7604 if (vsi
->idx
< pf
->next_vsi
)
7605 pf
->next_vsi
= vsi
->idx
;
7608 mutex_unlock(&pf
->switch_mutex
);
7616 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
7617 * @vsi: the VSI being cleaned
7619 static void i40e_vsi_clear_rings(struct i40e_vsi
*vsi
)
7623 if (vsi
->tx_rings
&& vsi
->tx_rings
[0]) {
7624 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
7625 kfree_rcu(vsi
->tx_rings
[i
], rcu
);
7626 vsi
->tx_rings
[i
] = NULL
;
7627 vsi
->rx_rings
[i
] = NULL
;
7633 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
7634 * @vsi: the VSI being configured
7636 static int i40e_alloc_rings(struct i40e_vsi
*vsi
)
7638 struct i40e_ring
*tx_ring
, *rx_ring
;
7639 struct i40e_pf
*pf
= vsi
->back
;
7642 /* Set basic values in the rings to be used later during open() */
7643 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
7644 /* allocate space for both Tx and Rx in one shot */
7645 tx_ring
= kzalloc(sizeof(struct i40e_ring
) * 2, GFP_KERNEL
);
7649 tx_ring
->queue_index
= i
;
7650 tx_ring
->reg_idx
= vsi
->base_queue
+ i
;
7651 tx_ring
->ring_active
= false;
7653 tx_ring
->netdev
= vsi
->netdev
;
7654 tx_ring
->dev
= &pf
->pdev
->dev
;
7655 tx_ring
->count
= vsi
->num_desc
;
7657 tx_ring
->dcb_tc
= 0;
7658 if (vsi
->back
->flags
& I40E_FLAG_WB_ON_ITR_CAPABLE
)
7659 tx_ring
->flags
= I40E_TXR_FLAGS_WB_ON_ITR
;
7660 tx_ring
->tx_itr_setting
= pf
->tx_itr_default
;
7661 vsi
->tx_rings
[i
] = tx_ring
;
7663 rx_ring
= &tx_ring
[1];
7664 rx_ring
->queue_index
= i
;
7665 rx_ring
->reg_idx
= vsi
->base_queue
+ i
;
7666 rx_ring
->ring_active
= false;
7668 rx_ring
->netdev
= vsi
->netdev
;
7669 rx_ring
->dev
= &pf
->pdev
->dev
;
7670 rx_ring
->count
= vsi
->num_desc
;
7672 rx_ring
->dcb_tc
= 0;
7673 rx_ring
->rx_itr_setting
= pf
->rx_itr_default
;
7674 vsi
->rx_rings
[i
] = rx_ring
;
7680 i40e_vsi_clear_rings(vsi
);
7685 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
7686 * @pf: board private structure
7687 * @vectors: the number of MSI-X vectors to request
7689 * Returns the number of vectors reserved, or error
7691 static int i40e_reserve_msix_vectors(struct i40e_pf
*pf
, int vectors
)
7693 vectors
= pci_enable_msix_range(pf
->pdev
, pf
->msix_entries
,
7694 I40E_MIN_MSIX
, vectors
);
7696 dev_info(&pf
->pdev
->dev
,
7697 "MSI-X vector reservation failed: %d\n", vectors
);
7705 * i40e_init_msix - Setup the MSIX capability
7706 * @pf: board private structure
7708 * Work with the OS to set up the MSIX vectors needed.
7710 * Returns the number of vectors reserved or negative on failure
7712 static int i40e_init_msix(struct i40e_pf
*pf
)
7714 struct i40e_hw
*hw
= &pf
->hw
;
7718 int iwarp_requested
= 0;
7720 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
7723 /* The number of vectors we'll request will be comprised of:
7724 * - Add 1 for "other" cause for Admin Queue events, etc.
7725 * - The number of LAN queue pairs
7726 * - Queues being used for RSS.
7727 * We don't need as many as max_rss_size vectors.
7728 * use rss_size instead in the calculation since that
7729 * is governed by number of cpus in the system.
7730 * - assumes symmetric Tx/Rx pairing
7731 * - The number of VMDq pairs
7732 * - The CPU count within the NUMA node if iWARP is enabled
7734 * - The number of FCOE qps.
7736 * Once we count this up, try the request.
7738 * If we can't get what we want, we'll simplify to nearly nothing
7739 * and try again. If that still fails, we punt.
7741 vectors_left
= hw
->func_caps
.num_msix_vectors
;
7744 /* reserve one vector for miscellaneous handler */
7750 /* reserve vectors for the main PF traffic queues */
7751 pf
->num_lan_msix
= min_t(int, num_online_cpus(), vectors_left
);
7752 vectors_left
-= pf
->num_lan_msix
;
7753 v_budget
+= pf
->num_lan_msix
;
7755 /* reserve one vector for sideband flow director */
7756 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
7758 pf
->num_fdsb_msix
= 1;
7762 pf
->num_fdsb_msix
= 0;
7767 /* can we reserve enough for FCoE? */
7768 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7770 pf
->num_fcoe_msix
= 0;
7771 else if (vectors_left
>= pf
->num_fcoe_qps
)
7772 pf
->num_fcoe_msix
= pf
->num_fcoe_qps
;
7774 pf
->num_fcoe_msix
= 1;
7775 v_budget
+= pf
->num_fcoe_msix
;
7776 vectors_left
-= pf
->num_fcoe_msix
;
7780 /* can we reserve enough for iWARP? */
7781 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
) {
7782 iwarp_requested
= pf
->num_iwarp_msix
;
7785 pf
->num_iwarp_msix
= 0;
7786 else if (vectors_left
< pf
->num_iwarp_msix
)
7787 pf
->num_iwarp_msix
= 1;
7788 v_budget
+= pf
->num_iwarp_msix
;
7789 vectors_left
-= pf
->num_iwarp_msix
;
7792 /* any vectors left over go for VMDq support */
7793 if (pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) {
7794 int vmdq_vecs_wanted
= pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
;
7795 int vmdq_vecs
= min_t(int, vectors_left
, vmdq_vecs_wanted
);
7797 if (!vectors_left
) {
7798 pf
->num_vmdq_msix
= 0;
7799 pf
->num_vmdq_qps
= 0;
7801 /* if we're short on vectors for what's desired, we limit
7802 * the queues per vmdq. If this is still more than are
7803 * available, the user will need to change the number of
7804 * queues/vectors used by the PF later with the ethtool
7807 if (vmdq_vecs
< vmdq_vecs_wanted
)
7808 pf
->num_vmdq_qps
= 1;
7809 pf
->num_vmdq_msix
= pf
->num_vmdq_qps
;
7811 v_budget
+= vmdq_vecs
;
7812 vectors_left
-= vmdq_vecs
;
7816 pf
->msix_entries
= kcalloc(v_budget
, sizeof(struct msix_entry
),
7818 if (!pf
->msix_entries
)
7821 for (i
= 0; i
< v_budget
; i
++)
7822 pf
->msix_entries
[i
].entry
= i
;
7823 v_actual
= i40e_reserve_msix_vectors(pf
, v_budget
);
7825 if (v_actual
< I40E_MIN_MSIX
) {
7826 pf
->flags
&= ~I40E_FLAG_MSIX_ENABLED
;
7827 kfree(pf
->msix_entries
);
7828 pf
->msix_entries
= NULL
;
7829 pci_disable_msix(pf
->pdev
);
7832 } else if (v_actual
== I40E_MIN_MSIX
) {
7833 /* Adjust for minimal MSIX use */
7834 pf
->num_vmdq_vsis
= 0;
7835 pf
->num_vmdq_qps
= 0;
7836 pf
->num_lan_qps
= 1;
7837 pf
->num_lan_msix
= 1;
7839 } else if (!vectors_left
) {
7840 /* If we have limited resources, we will start with no vectors
7841 * for the special features and then allocate vectors to some
7842 * of these features based on the policy and at the end disable
7843 * the features that did not get any vectors.
7847 dev_info(&pf
->pdev
->dev
,
7848 "MSI-X vector limit reached, attempting to redistribute vectors\n");
7849 /* reserve the misc vector */
7852 /* Scale vector usage down */
7853 pf
->num_vmdq_msix
= 1; /* force VMDqs to only one vector */
7854 pf
->num_vmdq_vsis
= 1;
7855 pf
->num_vmdq_qps
= 1;
7857 pf
->num_fcoe_qps
= 0;
7858 pf
->num_fcoe_msix
= 0;
7861 /* partition out the remaining vectors */
7864 pf
->num_lan_msix
= 1;
7867 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
) {
7868 pf
->num_lan_msix
= 1;
7869 pf
->num_iwarp_msix
= 1;
7871 pf
->num_lan_msix
= 2;
7874 /* give one vector to FCoE */
7875 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7876 pf
->num_lan_msix
= 1;
7877 pf
->num_fcoe_msix
= 1;
7882 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
) {
7883 pf
->num_iwarp_msix
= min_t(int, (vec
/ 3),
7885 pf
->num_vmdq_vsis
= min_t(int, (vec
/ 3),
7886 I40E_DEFAULT_NUM_VMDQ_VSI
);
7888 pf
->num_vmdq_vsis
= min_t(int, (vec
/ 2),
7889 I40E_DEFAULT_NUM_VMDQ_VSI
);
7891 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
7892 pf
->num_fdsb_msix
= 1;
7895 pf
->num_lan_msix
= min_t(int,
7896 (vec
- (pf
->num_iwarp_msix
+ pf
->num_vmdq_vsis
)),
7898 pf
->num_lan_qps
= pf
->num_lan_msix
;
7900 /* give one vector to FCoE */
7901 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7902 pf
->num_fcoe_msix
= 1;
7910 if ((pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) &&
7911 (pf
->num_fdsb_msix
== 0)) {
7912 dev_info(&pf
->pdev
->dev
, "Sideband Flowdir disabled, not enough MSI-X vectors\n");
7913 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7915 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
7916 (pf
->num_vmdq_msix
== 0)) {
7917 dev_info(&pf
->pdev
->dev
, "VMDq disabled, not enough MSI-X vectors\n");
7918 pf
->flags
&= ~I40E_FLAG_VMDQ_ENABLED
;
7921 if ((pf
->flags
& I40E_FLAG_IWARP_ENABLED
) &&
7922 (pf
->num_iwarp_msix
== 0)) {
7923 dev_info(&pf
->pdev
->dev
, "IWARP disabled, not enough MSI-X vectors\n");
7924 pf
->flags
&= ~I40E_FLAG_IWARP_ENABLED
;
7928 if ((pf
->flags
& I40E_FLAG_FCOE_ENABLED
) && (pf
->num_fcoe_msix
== 0)) {
7929 dev_info(&pf
->pdev
->dev
, "FCOE disabled, not enough MSI-X vectors\n");
7930 pf
->flags
&= ~I40E_FLAG_FCOE_ENABLED
;
7933 i40e_debug(&pf
->hw
, I40E_DEBUG_INIT
,
7934 "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n",
7936 pf
->num_vmdq_msix
* pf
->num_vmdq_vsis
,
7938 pf
->num_iwarp_msix
);
7944 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
7945 * @vsi: the VSI being configured
7946 * @v_idx: index of the vector in the vsi struct
7947 * @cpu: cpu to be used on affinity_mask
7949 * We allocate one q_vector. If allocation fails we return -ENOMEM.
7951 static int i40e_vsi_alloc_q_vector(struct i40e_vsi
*vsi
, int v_idx
, int cpu
)
7953 struct i40e_q_vector
*q_vector
;
7955 /* allocate q_vector */
7956 q_vector
= kzalloc(sizeof(struct i40e_q_vector
), GFP_KERNEL
);
7960 q_vector
->vsi
= vsi
;
7961 q_vector
->v_idx
= v_idx
;
7962 cpumask_set_cpu(cpu
, &q_vector
->affinity_mask
);
7965 netif_napi_add(vsi
->netdev
, &q_vector
->napi
,
7966 i40e_napi_poll
, NAPI_POLL_WEIGHT
);
7968 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
7969 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
7971 /* tie q_vector and vsi together */
7972 vsi
->q_vectors
[v_idx
] = q_vector
;
7978 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
7979 * @vsi: the VSI being configured
7981 * We allocate one q_vector per queue interrupt. If allocation fails we
7984 static int i40e_vsi_alloc_q_vectors(struct i40e_vsi
*vsi
)
7986 struct i40e_pf
*pf
= vsi
->back
;
7987 int err
, v_idx
, num_q_vectors
, current_cpu
;
7989 /* if not MSIX, give the one vector only to the LAN VSI */
7990 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
7991 num_q_vectors
= vsi
->num_q_vectors
;
7992 else if (vsi
== pf
->vsi
[pf
->lan_vsi
])
7997 current_cpu
= cpumask_first(cpu_online_mask
);
7999 for (v_idx
= 0; v_idx
< num_q_vectors
; v_idx
++) {
8000 err
= i40e_vsi_alloc_q_vector(vsi
, v_idx
, current_cpu
);
8003 current_cpu
= cpumask_next(current_cpu
, cpu_online_mask
);
8004 if (unlikely(current_cpu
>= nr_cpu_ids
))
8005 current_cpu
= cpumask_first(cpu_online_mask
);
8012 i40e_free_q_vector(vsi
, v_idx
);
8018 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
8019 * @pf: board private structure to initialize
8021 static int i40e_init_interrupt_scheme(struct i40e_pf
*pf
)
8026 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
8027 vectors
= i40e_init_msix(pf
);
8029 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
|
8030 I40E_FLAG_IWARP_ENABLED
|
8032 I40E_FLAG_FCOE_ENABLED
|
8034 I40E_FLAG_RSS_ENABLED
|
8035 I40E_FLAG_DCB_CAPABLE
|
8036 I40E_FLAG_DCB_ENABLED
|
8037 I40E_FLAG_SRIOV_ENABLED
|
8038 I40E_FLAG_FD_SB_ENABLED
|
8039 I40E_FLAG_FD_ATR_ENABLED
|
8040 I40E_FLAG_VMDQ_ENABLED
);
8042 /* rework the queue expectations without MSIX */
8043 i40e_determine_queue_usage(pf
);
8047 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
8048 (pf
->flags
& I40E_FLAG_MSI_ENABLED
)) {
8049 dev_info(&pf
->pdev
->dev
, "MSI-X not available, trying MSI\n");
8050 vectors
= pci_enable_msi(pf
->pdev
);
8052 dev_info(&pf
->pdev
->dev
, "MSI init failed - %d\n",
8054 pf
->flags
&= ~I40E_FLAG_MSI_ENABLED
;
8056 vectors
= 1; /* one MSI or Legacy vector */
8059 if (!(pf
->flags
& (I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
)))
8060 dev_info(&pf
->pdev
->dev
, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
8062 /* set up vector assignment tracking */
8063 size
= sizeof(struct i40e_lump_tracking
) + (sizeof(u16
) * vectors
);
8064 pf
->irq_pile
= kzalloc(size
, GFP_KERNEL
);
8065 if (!pf
->irq_pile
) {
8066 dev_err(&pf
->pdev
->dev
, "error allocating irq_pile memory\n");
8069 pf
->irq_pile
->num_entries
= vectors
;
8070 pf
->irq_pile
->search_hint
= 0;
8072 /* track first vector for misc interrupts, ignore return */
8073 (void)i40e_get_lump(pf
, pf
->irq_pile
, 1, I40E_PILE_VALID_BIT
- 1);
8079 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
8080 * @pf: board private structure
8082 * This sets up the handler for MSIX 0, which is used to manage the
8083 * non-queue interrupts, e.g. AdminQ and errors. This is not used
8084 * when in MSI or Legacy interrupt mode.
8086 static int i40e_setup_misc_vector(struct i40e_pf
*pf
)
8088 struct i40e_hw
*hw
= &pf
->hw
;
8091 /* Only request the irq if this is the first time through, and
8092 * not when we're rebuilding after a Reset
8094 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
)) {
8095 err
= request_irq(pf
->msix_entries
[0].vector
,
8096 i40e_intr
, 0, pf
->int_name
, pf
);
8098 dev_info(&pf
->pdev
->dev
,
8099 "request_irq for %s failed: %d\n",
8105 i40e_enable_misc_int_causes(pf
);
8107 /* associate no queues to the misc vector */
8108 wr32(hw
, I40E_PFINT_LNKLST0
, I40E_QUEUE_END_OF_LIST
);
8109 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), I40E_ITR_8K
);
8113 i40e_irq_dynamic_enable_icr0(pf
, true);
8119 * i40e_config_rss_aq - Prepare for RSS using AQ commands
8120 * @vsi: vsi structure
8121 * @seed: RSS hash seed
8123 static int i40e_config_rss_aq(struct i40e_vsi
*vsi
, const u8
*seed
,
8124 u8
*lut
, u16 lut_size
)
8126 struct i40e_pf
*pf
= vsi
->back
;
8127 struct i40e_hw
*hw
= &pf
->hw
;
8131 struct i40e_aqc_get_set_rss_key_data
*seed_dw
=
8132 (struct i40e_aqc_get_set_rss_key_data
*)seed
;
8133 ret
= i40e_aq_set_rss_key(hw
, vsi
->id
, seed_dw
);
8135 dev_info(&pf
->pdev
->dev
,
8136 "Cannot set RSS key, err %s aq_err %s\n",
8137 i40e_stat_str(hw
, ret
),
8138 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
8143 bool pf_lut
= vsi
->type
== I40E_VSI_MAIN
? true : false;
8145 ret
= i40e_aq_set_rss_lut(hw
, vsi
->id
, pf_lut
, lut
, lut_size
);
8147 dev_info(&pf
->pdev
->dev
,
8148 "Cannot set RSS lut, err %s aq_err %s\n",
8149 i40e_stat_str(hw
, ret
),
8150 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
8158 * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
8159 * @vsi: Pointer to vsi structure
8160 * @seed: Buffter to store the hash keys
8161 * @lut: Buffer to store the lookup table entries
8162 * @lut_size: Size of buffer to store the lookup table entries
8164 * Return 0 on success, negative on failure
8166 static int i40e_get_rss_aq(struct i40e_vsi
*vsi
, const u8
*seed
,
8167 u8
*lut
, u16 lut_size
)
8169 struct i40e_pf
*pf
= vsi
->back
;
8170 struct i40e_hw
*hw
= &pf
->hw
;
8174 ret
= i40e_aq_get_rss_key(hw
, vsi
->id
,
8175 (struct i40e_aqc_get_set_rss_key_data
*)seed
);
8177 dev_info(&pf
->pdev
->dev
,
8178 "Cannot get RSS key, err %s aq_err %s\n",
8179 i40e_stat_str(&pf
->hw
, ret
),
8180 i40e_aq_str(&pf
->hw
,
8181 pf
->hw
.aq
.asq_last_status
));
8187 bool pf_lut
= vsi
->type
== I40E_VSI_MAIN
? true : false;
8189 ret
= i40e_aq_get_rss_lut(hw
, vsi
->id
, pf_lut
, lut
, lut_size
);
8191 dev_info(&pf
->pdev
->dev
,
8192 "Cannot get RSS lut, err %s aq_err %s\n",
8193 i40e_stat_str(&pf
->hw
, ret
),
8194 i40e_aq_str(&pf
->hw
,
8195 pf
->hw
.aq
.asq_last_status
));
8204 * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
8205 * @vsi: VSI structure
8207 static int i40e_vsi_config_rss(struct i40e_vsi
*vsi
)
8209 u8 seed
[I40E_HKEY_ARRAY_SIZE
];
8210 struct i40e_pf
*pf
= vsi
->back
;
8214 if (!(pf
->flags
& I40E_FLAG_RSS_AQ_CAPABLE
))
8218 vsi
->rss_size
= min_t(int, pf
->alloc_rss_size
,
8219 vsi
->num_queue_pairs
);
8223 lut
= kzalloc(vsi
->rss_table_size
, GFP_KERNEL
);
8226 /* Use the user configured hash keys and lookup table if there is one,
8227 * otherwise use default
8229 if (vsi
->rss_lut_user
)
8230 memcpy(lut
, vsi
->rss_lut_user
, vsi
->rss_table_size
);
8232 i40e_fill_rss_lut(pf
, lut
, vsi
->rss_table_size
, vsi
->rss_size
);
8233 if (vsi
->rss_hkey_user
)
8234 memcpy(seed
, vsi
->rss_hkey_user
, I40E_HKEY_ARRAY_SIZE
);
8236 netdev_rss_key_fill((void *)seed
, I40E_HKEY_ARRAY_SIZE
);
8237 ret
= i40e_config_rss_aq(vsi
, seed
, lut
, vsi
->rss_table_size
);
8244 * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
8245 * @vsi: Pointer to vsi structure
8246 * @seed: RSS hash seed
8247 * @lut: Lookup table
8248 * @lut_size: Lookup table size
8250 * Returns 0 on success, negative on failure
8252 static int i40e_config_rss_reg(struct i40e_vsi
*vsi
, const u8
*seed
,
8253 const u8
*lut
, u16 lut_size
)
8255 struct i40e_pf
*pf
= vsi
->back
;
8256 struct i40e_hw
*hw
= &pf
->hw
;
8257 u16 vf_id
= vsi
->vf_id
;
8260 /* Fill out hash function seed */
8262 u32
*seed_dw
= (u32
*)seed
;
8264 if (vsi
->type
== I40E_VSI_MAIN
) {
8265 for (i
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++)
8266 i40e_write_rx_ctl(hw
, I40E_PFQF_HKEY(i
),
8268 } else if (vsi
->type
== I40E_VSI_SRIOV
) {
8269 for (i
= 0; i
<= I40E_VFQF_HKEY1_MAX_INDEX
; i
++)
8270 i40e_write_rx_ctl(hw
,
8271 I40E_VFQF_HKEY1(i
, vf_id
),
8274 dev_err(&pf
->pdev
->dev
, "Cannot set RSS seed - invalid VSI type\n");
8279 u32
*lut_dw
= (u32
*)lut
;
8281 if (vsi
->type
== I40E_VSI_MAIN
) {
8282 if (lut_size
!= I40E_HLUT_ARRAY_SIZE
)
8284 for (i
= 0; i
<= I40E_PFQF_HLUT_MAX_INDEX
; i
++)
8285 wr32(hw
, I40E_PFQF_HLUT(i
), lut_dw
[i
]);
8286 } else if (vsi
->type
== I40E_VSI_SRIOV
) {
8287 if (lut_size
!= I40E_VF_HLUT_ARRAY_SIZE
)
8289 for (i
= 0; i
<= I40E_VFQF_HLUT_MAX_INDEX
; i
++)
8290 i40e_write_rx_ctl(hw
,
8291 I40E_VFQF_HLUT1(i
, vf_id
),
8294 dev_err(&pf
->pdev
->dev
, "Cannot set RSS LUT - invalid VSI type\n");
8303 * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
8304 * @vsi: Pointer to VSI structure
8305 * @seed: Buffer to store the keys
8306 * @lut: Buffer to store the lookup table entries
8307 * @lut_size: Size of buffer to store the lookup table entries
8309 * Returns 0 on success, negative on failure
8311 static int i40e_get_rss_reg(struct i40e_vsi
*vsi
, u8
*seed
,
8312 u8
*lut
, u16 lut_size
)
8314 struct i40e_pf
*pf
= vsi
->back
;
8315 struct i40e_hw
*hw
= &pf
->hw
;
8319 u32
*seed_dw
= (u32
*)seed
;
8321 for (i
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++)
8322 seed_dw
[i
] = i40e_read_rx_ctl(hw
, I40E_PFQF_HKEY(i
));
8325 u32
*lut_dw
= (u32
*)lut
;
8327 if (lut_size
!= I40E_HLUT_ARRAY_SIZE
)
8329 for (i
= 0; i
<= I40E_PFQF_HLUT_MAX_INDEX
; i
++)
8330 lut_dw
[i
] = rd32(hw
, I40E_PFQF_HLUT(i
));
8337 * i40e_config_rss - Configure RSS keys and lut
8338 * @vsi: Pointer to VSI structure
8339 * @seed: RSS hash seed
8340 * @lut: Lookup table
8341 * @lut_size: Lookup table size
8343 * Returns 0 on success, negative on failure
8345 int i40e_config_rss(struct i40e_vsi
*vsi
, u8
*seed
, u8
*lut
, u16 lut_size
)
8347 struct i40e_pf
*pf
= vsi
->back
;
8349 if (pf
->flags
& I40E_FLAG_RSS_AQ_CAPABLE
)
8350 return i40e_config_rss_aq(vsi
, seed
, lut
, lut_size
);
8352 return i40e_config_rss_reg(vsi
, seed
, lut
, lut_size
);
8356 * i40e_get_rss - Get RSS keys and lut
8357 * @vsi: Pointer to VSI structure
8358 * @seed: Buffer to store the keys
8359 * @lut: Buffer to store the lookup table entries
8360 * lut_size: Size of buffer to store the lookup table entries
8362 * Returns 0 on success, negative on failure
8364 int i40e_get_rss(struct i40e_vsi
*vsi
, u8
*seed
, u8
*lut
, u16 lut_size
)
8366 struct i40e_pf
*pf
= vsi
->back
;
8368 if (pf
->flags
& I40E_FLAG_RSS_AQ_CAPABLE
)
8369 return i40e_get_rss_aq(vsi
, seed
, lut
, lut_size
);
8371 return i40e_get_rss_reg(vsi
, seed
, lut
, lut_size
);
8375 * i40e_fill_rss_lut - Fill the RSS lookup table with default values
8376 * @pf: Pointer to board private structure
8377 * @lut: Lookup table
8378 * @rss_table_size: Lookup table size
8379 * @rss_size: Range of queue number for hashing
8381 void i40e_fill_rss_lut(struct i40e_pf
*pf
, u8
*lut
,
8382 u16 rss_table_size
, u16 rss_size
)
8386 for (i
= 0; i
< rss_table_size
; i
++)
8387 lut
[i
] = i
% rss_size
;
8391 * i40e_pf_config_rss - Prepare for RSS if used
8392 * @pf: board private structure
8394 static int i40e_pf_config_rss(struct i40e_pf
*pf
)
8396 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
8397 u8 seed
[I40E_HKEY_ARRAY_SIZE
];
8399 struct i40e_hw
*hw
= &pf
->hw
;
8404 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
8405 hena
= (u64
)i40e_read_rx_ctl(hw
, I40E_PFQF_HENA(0)) |
8406 ((u64
)i40e_read_rx_ctl(hw
, I40E_PFQF_HENA(1)) << 32);
8407 hena
|= i40e_pf_get_default_rss_hena(pf
);
8409 i40e_write_rx_ctl(hw
, I40E_PFQF_HENA(0), (u32
)hena
);
8410 i40e_write_rx_ctl(hw
, I40E_PFQF_HENA(1), (u32
)(hena
>> 32));
8412 /* Determine the RSS table size based on the hardware capabilities */
8413 reg_val
= i40e_read_rx_ctl(hw
, I40E_PFQF_CTL_0
);
8414 reg_val
= (pf
->rss_table_size
== 512) ?
8415 (reg_val
| I40E_PFQF_CTL_0_HASHLUTSIZE_512
) :
8416 (reg_val
& ~I40E_PFQF_CTL_0_HASHLUTSIZE_512
);
8417 i40e_write_rx_ctl(hw
, I40E_PFQF_CTL_0
, reg_val
);
8419 /* Determine the RSS size of the VSI */
8421 vsi
->rss_size
= min_t(int, pf
->alloc_rss_size
,
8422 vsi
->num_queue_pairs
);
8426 lut
= kzalloc(vsi
->rss_table_size
, GFP_KERNEL
);
8430 /* Use user configured lut if there is one, otherwise use default */
8431 if (vsi
->rss_lut_user
)
8432 memcpy(lut
, vsi
->rss_lut_user
, vsi
->rss_table_size
);
8434 i40e_fill_rss_lut(pf
, lut
, vsi
->rss_table_size
, vsi
->rss_size
);
8436 /* Use user configured hash key if there is one, otherwise
8439 if (vsi
->rss_hkey_user
)
8440 memcpy(seed
, vsi
->rss_hkey_user
, I40E_HKEY_ARRAY_SIZE
);
8442 netdev_rss_key_fill((void *)seed
, I40E_HKEY_ARRAY_SIZE
);
8443 ret
= i40e_config_rss(vsi
, seed
, lut
, vsi
->rss_table_size
);
8450 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
8451 * @pf: board private structure
8452 * @queue_count: the requested queue count for rss.
8454 * returns 0 if rss is not enabled, if enabled returns the final rss queue
8455 * count which may be different from the requested queue count.
8457 int i40e_reconfig_rss_queues(struct i40e_pf
*pf
, int queue_count
)
8459 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
8462 if (!(pf
->flags
& I40E_FLAG_RSS_ENABLED
))
8465 new_rss_size
= min_t(int, queue_count
, pf
->rss_size_max
);
8467 if (queue_count
!= vsi
->num_queue_pairs
) {
8468 vsi
->req_queue_pairs
= queue_count
;
8469 i40e_prep_for_reset(pf
);
8471 pf
->alloc_rss_size
= new_rss_size
;
8473 i40e_reset_and_rebuild(pf
, true);
8475 /* Discard the user configured hash keys and lut, if less
8476 * queues are enabled.
8478 if (queue_count
< vsi
->rss_size
) {
8479 i40e_clear_rss_config_user(vsi
);
8480 dev_dbg(&pf
->pdev
->dev
,
8481 "discard user configured hash keys and lut\n");
8484 /* Reset vsi->rss_size, as number of enabled queues changed */
8485 vsi
->rss_size
= min_t(int, pf
->alloc_rss_size
,
8486 vsi
->num_queue_pairs
);
8488 i40e_pf_config_rss(pf
);
8490 dev_info(&pf
->pdev
->dev
, "User requested queue count/HW max RSS count: %d/%d\n",
8491 vsi
->req_queue_pairs
, pf
->rss_size_max
);
8492 return pf
->alloc_rss_size
;
8496 * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition
8497 * @pf: board private structure
8499 i40e_status
i40e_get_npar_bw_setting(struct i40e_pf
*pf
)
8502 bool min_valid
, max_valid
;
8505 status
= i40e_read_bw_from_alt_ram(&pf
->hw
, &max_bw
, &min_bw
,
8506 &min_valid
, &max_valid
);
8510 pf
->npar_min_bw
= min_bw
;
8512 pf
->npar_max_bw
= max_bw
;
8519 * i40e_set_npar_bw_setting - Set BW settings for this PF partition
8520 * @pf: board private structure
8522 i40e_status
i40e_set_npar_bw_setting(struct i40e_pf
*pf
)
8524 struct i40e_aqc_configure_partition_bw_data bw_data
;
8527 /* Set the valid bit for this PF */
8528 bw_data
.pf_valid_bits
= cpu_to_le16(BIT(pf
->hw
.pf_id
));
8529 bw_data
.max_bw
[pf
->hw
.pf_id
] = pf
->npar_max_bw
& I40E_ALT_BW_VALUE_MASK
;
8530 bw_data
.min_bw
[pf
->hw
.pf_id
] = pf
->npar_min_bw
& I40E_ALT_BW_VALUE_MASK
;
8532 /* Set the new bandwidths */
8533 status
= i40e_aq_configure_partition_bw(&pf
->hw
, &bw_data
, NULL
);
8539 * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition
8540 * @pf: board private structure
8542 i40e_status
i40e_commit_npar_bw_setting(struct i40e_pf
*pf
)
8544 /* Commit temporary BW setting to permanent NVM image */
8545 enum i40e_admin_queue_err last_aq_status
;
8549 if (pf
->hw
.partition_id
!= 1) {
8550 dev_info(&pf
->pdev
->dev
,
8551 "Commit BW only works on partition 1! This is partition %d",
8552 pf
->hw
.partition_id
);
8553 ret
= I40E_NOT_SUPPORTED
;
8557 /* Acquire NVM for read access */
8558 ret
= i40e_acquire_nvm(&pf
->hw
, I40E_RESOURCE_READ
);
8559 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
8561 dev_info(&pf
->pdev
->dev
,
8562 "Cannot acquire NVM for read access, err %s aq_err %s\n",
8563 i40e_stat_str(&pf
->hw
, ret
),
8564 i40e_aq_str(&pf
->hw
, last_aq_status
));
8568 /* Read word 0x10 of NVM - SW compatibility word 1 */
8569 ret
= i40e_aq_read_nvm(&pf
->hw
,
8570 I40E_SR_NVM_CONTROL_WORD
,
8571 0x10, sizeof(nvm_word
), &nvm_word
,
8573 /* Save off last admin queue command status before releasing
8576 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
8577 i40e_release_nvm(&pf
->hw
);
8579 dev_info(&pf
->pdev
->dev
, "NVM read error, err %s aq_err %s\n",
8580 i40e_stat_str(&pf
->hw
, ret
),
8581 i40e_aq_str(&pf
->hw
, last_aq_status
));
8585 /* Wait a bit for NVM release to complete */
8588 /* Acquire NVM for write access */
8589 ret
= i40e_acquire_nvm(&pf
->hw
, I40E_RESOURCE_WRITE
);
8590 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
8592 dev_info(&pf
->pdev
->dev
,
8593 "Cannot acquire NVM for write access, err %s aq_err %s\n",
8594 i40e_stat_str(&pf
->hw
, ret
),
8595 i40e_aq_str(&pf
->hw
, last_aq_status
));
8598 /* Write it back out unchanged to initiate update NVM,
8599 * which will force a write of the shadow (alt) RAM to
8600 * the NVM - thus storing the bandwidth values permanently.
8602 ret
= i40e_aq_update_nvm(&pf
->hw
,
8603 I40E_SR_NVM_CONTROL_WORD
,
8604 0x10, sizeof(nvm_word
),
8605 &nvm_word
, true, NULL
);
8606 /* Save off last admin queue command status before releasing
8609 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
8610 i40e_release_nvm(&pf
->hw
);
8612 dev_info(&pf
->pdev
->dev
,
8613 "BW settings NOT SAVED, err %s aq_err %s\n",
8614 i40e_stat_str(&pf
->hw
, ret
),
8615 i40e_aq_str(&pf
->hw
, last_aq_status
));
8622 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
8623 * @pf: board private structure to initialize
8625 * i40e_sw_init initializes the Adapter private data structure.
8626 * Fields are initialized based on PCI device information and
8627 * OS network device settings (MTU size).
8629 static int i40e_sw_init(struct i40e_pf
*pf
)
8634 /* Set default capability flags */
8635 pf
->flags
= I40E_FLAG_RX_CSUM_ENABLED
|
8636 I40E_FLAG_MSI_ENABLED
|
8637 I40E_FLAG_MSIX_ENABLED
;
8639 /* Set default ITR */
8640 pf
->rx_itr_default
= I40E_ITR_DYNAMIC
| I40E_ITR_RX_DEF
;
8641 pf
->tx_itr_default
= I40E_ITR_DYNAMIC
| I40E_ITR_TX_DEF
;
8643 /* Depending on PF configurations, it is possible that the RSS
8644 * maximum might end up larger than the available queues
8646 pf
->rss_size_max
= BIT(pf
->hw
.func_caps
.rss_table_entry_width
);
8647 pf
->alloc_rss_size
= 1;
8648 pf
->rss_table_size
= pf
->hw
.func_caps
.rss_table_size
;
8649 pf
->rss_size_max
= min_t(int, pf
->rss_size_max
,
8650 pf
->hw
.func_caps
.num_tx_qp
);
8651 if (pf
->hw
.func_caps
.rss
) {
8652 pf
->flags
|= I40E_FLAG_RSS_ENABLED
;
8653 pf
->alloc_rss_size
= min_t(int, pf
->rss_size_max
,
8657 /* MFP mode enabled */
8658 if (pf
->hw
.func_caps
.npar_enable
|| pf
->hw
.func_caps
.flex10_enable
) {
8659 pf
->flags
|= I40E_FLAG_MFP_ENABLED
;
8660 dev_info(&pf
->pdev
->dev
, "MFP mode Enabled\n");
8661 if (i40e_get_npar_bw_setting(pf
))
8662 dev_warn(&pf
->pdev
->dev
,
8663 "Could not get NPAR bw settings\n");
8665 dev_info(&pf
->pdev
->dev
,
8666 "Min BW = %8.8x, Max BW = %8.8x\n",
8667 pf
->npar_min_bw
, pf
->npar_max_bw
);
8670 /* FW/NVM is not yet fixed in this regard */
8671 if ((pf
->hw
.func_caps
.fd_filters_guaranteed
> 0) ||
8672 (pf
->hw
.func_caps
.fd_filters_best_effort
> 0)) {
8673 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
8674 pf
->atr_sample_rate
= I40E_DEFAULT_ATR_SAMPLE_RATE
;
8675 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
&&
8676 pf
->hw
.num_partitions
> 1)
8677 dev_info(&pf
->pdev
->dev
,
8678 "Flow Director Sideband mode Disabled in MFP mode\n");
8680 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
8681 pf
->fdir_pf_filter_count
=
8682 pf
->hw
.func_caps
.fd_filters_guaranteed
;
8683 pf
->hw
.fdir_shared_filter_count
=
8684 pf
->hw
.func_caps
.fd_filters_best_effort
;
8687 if ((pf
->hw
.mac
.type
== I40E_MAC_XL710
) &&
8688 (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
8689 (pf
->hw
.aq
.fw_maj_ver
< 4))) {
8690 pf
->flags
|= I40E_FLAG_RESTART_AUTONEG
;
8691 /* No DCB support for FW < v4.33 */
8692 pf
->flags
|= I40E_FLAG_NO_DCB_SUPPORT
;
8695 /* Disable FW LLDP if FW < v4.3 */
8696 if ((pf
->hw
.mac
.type
== I40E_MAC_XL710
) &&
8697 (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 3)) ||
8698 (pf
->hw
.aq
.fw_maj_ver
< 4)))
8699 pf
->flags
|= I40E_FLAG_STOP_FW_LLDP
;
8701 /* Use the FW Set LLDP MIB API if FW > v4.40 */
8702 if ((pf
->hw
.mac
.type
== I40E_MAC_XL710
) &&
8703 (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
>= 40)) ||
8704 (pf
->hw
.aq
.fw_maj_ver
>= 5)))
8705 pf
->flags
|= I40E_FLAG_USE_SET_LLDP_MIB
;
8707 if (pf
->hw
.func_caps
.vmdq
) {
8708 pf
->num_vmdq_vsis
= I40E_DEFAULT_NUM_VMDQ_VSI
;
8709 pf
->flags
|= I40E_FLAG_VMDQ_ENABLED
;
8710 pf
->num_vmdq_qps
= i40e_default_queues_per_vmdq(pf
);
8713 if (pf
->hw
.func_caps
.iwarp
) {
8714 pf
->flags
|= I40E_FLAG_IWARP_ENABLED
;
8715 /* IWARP needs one extra vector for CQP just like MISC.*/
8716 pf
->num_iwarp_msix
= (int)num_online_cpus() + 1;
8720 i40e_init_pf_fcoe(pf
);
8722 #endif /* I40E_FCOE */
8723 #ifdef CONFIG_PCI_IOV
8724 if (pf
->hw
.func_caps
.num_vfs
&& pf
->hw
.partition_id
== 1) {
8725 pf
->num_vf_qps
= I40E_DEFAULT_QUEUES_PER_VF
;
8726 pf
->flags
|= I40E_FLAG_SRIOV_ENABLED
;
8727 pf
->num_req_vfs
= min_t(int,
8728 pf
->hw
.func_caps
.num_vfs
,
8731 #endif /* CONFIG_PCI_IOV */
8732 if (pf
->hw
.mac
.type
== I40E_MAC_X722
) {
8733 pf
->flags
|= I40E_FLAG_RSS_AQ_CAPABLE
|
8734 I40E_FLAG_128_QP_RSS_CAPABLE
|
8735 I40E_FLAG_HW_ATR_EVICT_CAPABLE
|
8736 I40E_FLAG_OUTER_UDP_CSUM_CAPABLE
|
8737 I40E_FLAG_WB_ON_ITR_CAPABLE
|
8738 I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE
|
8739 I40E_FLAG_NO_PCI_LINK_CHECK
|
8740 I40E_FLAG_USE_SET_LLDP_MIB
|
8741 I40E_FLAG_GENEVE_OFFLOAD_CAPABLE
|
8742 I40E_FLAG_PTP_L4_CAPABLE
;
8743 } else if ((pf
->hw
.aq
.api_maj_ver
> 1) ||
8744 ((pf
->hw
.aq
.api_maj_ver
== 1) &&
8745 (pf
->hw
.aq
.api_min_ver
> 4))) {
8746 /* Supported in FW API version higher than 1.4 */
8747 pf
->flags
|= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE
;
8748 pf
->auto_disable_flags
= I40E_FLAG_HW_ATR_EVICT_CAPABLE
;
8750 pf
->auto_disable_flags
= I40E_FLAG_HW_ATR_EVICT_CAPABLE
;
8753 pf
->eeprom_version
= 0xDEAD;
8754 pf
->lan_veb
= I40E_NO_VEB
;
8755 pf
->lan_vsi
= I40E_NO_VSI
;
8757 /* By default FW has this off for performance reasons */
8758 pf
->flags
&= ~I40E_FLAG_VEB_STATS_ENABLED
;
8760 /* set up queue assignment tracking */
8761 size
= sizeof(struct i40e_lump_tracking
)
8762 + (sizeof(u16
) * pf
->hw
.func_caps
.num_tx_qp
);
8763 pf
->qp_pile
= kzalloc(size
, GFP_KERNEL
);
8768 pf
->qp_pile
->num_entries
= pf
->hw
.func_caps
.num_tx_qp
;
8769 pf
->qp_pile
->search_hint
= 0;
8771 pf
->tx_timeout_recovery_level
= 1;
8773 mutex_init(&pf
->switch_mutex
);
8775 /* If NPAR is enabled nudge the Tx scheduler */
8776 if (pf
->hw
.func_caps
.npar_enable
&& (!i40e_get_npar_bw_setting(pf
)))
8777 i40e_set_npar_bw_setting(pf
);
8784 * i40e_set_ntuple - set the ntuple feature flag and take action
8785 * @pf: board private structure to initialize
8786 * @features: the feature set that the stack is suggesting
8788 * returns a bool to indicate if reset needs to happen
8790 bool i40e_set_ntuple(struct i40e_pf
*pf
, netdev_features_t features
)
8792 bool need_reset
= false;
8794 /* Check if Flow Director n-tuple support was enabled or disabled. If
8795 * the state changed, we need to reset.
8797 if (features
& NETIF_F_NTUPLE
) {
8798 /* Enable filters and mark for reset */
8799 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
8801 /* enable FD_SB only if there is MSI-X vector */
8802 if (pf
->num_fdsb_msix
> 0)
8803 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
8805 /* turn off filters, mark for reset and clear SW filter list */
8806 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
8808 i40e_fdir_filter_exit(pf
);
8810 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
8811 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
8812 /* reset fd counters */
8813 pf
->fd_add_err
= pf
->fd_atr_cnt
= pf
->fd_tcp_rule
= 0;
8814 pf
->fdir_pf_active_filters
= 0;
8815 /* if ATR was auto disabled it can be re-enabled. */
8816 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
8817 (pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
)) {
8818 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
8819 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
8820 dev_info(&pf
->pdev
->dev
, "ATR re-enabled.\n");
8827 * i40e_clear_rss_lut - clear the rx hash lookup table
8828 * @vsi: the VSI being configured
8830 static void i40e_clear_rss_lut(struct i40e_vsi
*vsi
)
8832 struct i40e_pf
*pf
= vsi
->back
;
8833 struct i40e_hw
*hw
= &pf
->hw
;
8834 u16 vf_id
= vsi
->vf_id
;
8837 if (vsi
->type
== I40E_VSI_MAIN
) {
8838 for (i
= 0; i
<= I40E_PFQF_HLUT_MAX_INDEX
; i
++)
8839 wr32(hw
, I40E_PFQF_HLUT(i
), 0);
8840 } else if (vsi
->type
== I40E_VSI_SRIOV
) {
8841 for (i
= 0; i
<= I40E_VFQF_HLUT_MAX_INDEX
; i
++)
8842 i40e_write_rx_ctl(hw
, I40E_VFQF_HLUT1(i
, vf_id
), 0);
8844 dev_err(&pf
->pdev
->dev
, "Cannot set RSS LUT - invalid VSI type\n");
8849 * i40e_set_features - set the netdev feature flags
8850 * @netdev: ptr to the netdev being adjusted
8851 * @features: the feature set that the stack is suggesting
8853 static int i40e_set_features(struct net_device
*netdev
,
8854 netdev_features_t features
)
8856 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8857 struct i40e_vsi
*vsi
= np
->vsi
;
8858 struct i40e_pf
*pf
= vsi
->back
;
8861 if (features
& NETIF_F_RXHASH
&& !(netdev
->features
& NETIF_F_RXHASH
))
8862 i40e_pf_config_rss(pf
);
8863 else if (!(features
& NETIF_F_RXHASH
) &&
8864 netdev
->features
& NETIF_F_RXHASH
)
8865 i40e_clear_rss_lut(vsi
);
8867 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
8868 i40e_vlan_stripping_enable(vsi
);
8870 i40e_vlan_stripping_disable(vsi
);
8872 need_reset
= i40e_set_ntuple(pf
, features
);
8875 i40e_do_reset(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
8881 * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
8882 * @pf: board private structure
8883 * @port: The UDP port to look up
8885 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
8887 static u8
i40e_get_udp_port_idx(struct i40e_pf
*pf
, __be16 port
)
8891 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
8892 if (pf
->udp_ports
[i
].index
== port
)
8900 * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
8901 * @netdev: This physical port's netdev
8902 * @ti: Tunnel endpoint information
8904 static void i40e_udp_tunnel_add(struct net_device
*netdev
,
8905 struct udp_tunnel_info
*ti
)
8907 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8908 struct i40e_vsi
*vsi
= np
->vsi
;
8909 struct i40e_pf
*pf
= vsi
->back
;
8910 __be16 port
= ti
->port
;
8914 idx
= i40e_get_udp_port_idx(pf
, port
);
8916 /* Check if port already exists */
8917 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
8918 netdev_info(netdev
, "port %d already offloaded\n",
8923 /* Now check if there is space to add the new port */
8924 next_idx
= i40e_get_udp_port_idx(pf
, 0);
8926 if (next_idx
== I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
8927 netdev_info(netdev
, "maximum number of offloaded UDP ports reached, not adding port %d\n",
8933 case UDP_TUNNEL_TYPE_VXLAN
:
8934 pf
->udp_ports
[next_idx
].type
= I40E_AQC_TUNNEL_TYPE_VXLAN
;
8936 case UDP_TUNNEL_TYPE_GENEVE
:
8937 if (!(pf
->flags
& I40E_FLAG_GENEVE_OFFLOAD_CAPABLE
))
8939 pf
->udp_ports
[next_idx
].type
= I40E_AQC_TUNNEL_TYPE_NGE
;
8945 /* New port: add it and mark its index in the bitmap */
8946 pf
->udp_ports
[next_idx
].index
= port
;
8947 pf
->pending_udp_bitmap
|= BIT_ULL(next_idx
);
8948 pf
->flags
|= I40E_FLAG_UDP_FILTER_SYNC
;
8952 * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
8953 * @netdev: This physical port's netdev
8954 * @ti: Tunnel endpoint information
8956 static void i40e_udp_tunnel_del(struct net_device
*netdev
,
8957 struct udp_tunnel_info
*ti
)
8959 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8960 struct i40e_vsi
*vsi
= np
->vsi
;
8961 struct i40e_pf
*pf
= vsi
->back
;
8962 __be16 port
= ti
->port
;
8965 idx
= i40e_get_udp_port_idx(pf
, port
);
8967 /* Check if port already exists */
8968 if (idx
>= I40E_MAX_PF_UDP_OFFLOAD_PORTS
)
8972 case UDP_TUNNEL_TYPE_VXLAN
:
8973 if (pf
->udp_ports
[idx
].type
!= I40E_AQC_TUNNEL_TYPE_VXLAN
)
8976 case UDP_TUNNEL_TYPE_GENEVE
:
8977 if (pf
->udp_ports
[idx
].type
!= I40E_AQC_TUNNEL_TYPE_NGE
)
8984 /* if port exists, set it to 0 (mark for deletion)
8985 * and make it pending
8987 pf
->udp_ports
[idx
].index
= 0;
8988 pf
->pending_udp_bitmap
|= BIT_ULL(idx
);
8989 pf
->flags
|= I40E_FLAG_UDP_FILTER_SYNC
;
8993 netdev_warn(netdev
, "UDP port %d was not found, not deleting\n",
8997 static int i40e_get_phys_port_id(struct net_device
*netdev
,
8998 struct netdev_phys_item_id
*ppid
)
9000 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
9001 struct i40e_pf
*pf
= np
->vsi
->back
;
9002 struct i40e_hw
*hw
= &pf
->hw
;
9004 if (!(pf
->flags
& I40E_FLAG_PORT_ID_VALID
))
9007 ppid
->id_len
= min_t(int, sizeof(hw
->mac
.port_addr
), sizeof(ppid
->id
));
9008 memcpy(ppid
->id
, hw
->mac
.port_addr
, ppid
->id_len
);
9014 * i40e_ndo_fdb_add - add an entry to the hardware database
9015 * @ndm: the input from the stack
9016 * @tb: pointer to array of nladdr (unused)
9017 * @dev: the net device pointer
9018 * @addr: the MAC address entry being added
9019 * @flags: instructions from stack about fdb operation
9021 static int i40e_ndo_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
9022 struct net_device
*dev
,
9023 const unsigned char *addr
, u16 vid
,
9026 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
9027 struct i40e_pf
*pf
= np
->vsi
->back
;
9030 if (!(pf
->flags
& I40E_FLAG_SRIOV_ENABLED
))
9034 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev
->name
);
9038 /* Hardware does not support aging addresses so if a
9039 * ndm_state is given only allow permanent addresses
9041 if (ndm
->ndm_state
&& !(ndm
->ndm_state
& NUD_PERMANENT
)) {
9042 netdev_info(dev
, "FDB only supports static addresses\n");
9046 if (is_unicast_ether_addr(addr
) || is_link_local_ether_addr(addr
))
9047 err
= dev_uc_add_excl(dev
, addr
);
9048 else if (is_multicast_ether_addr(addr
))
9049 err
= dev_mc_add_excl(dev
, addr
);
9053 /* Only return duplicate errors if NLM_F_EXCL is set */
9054 if (err
== -EEXIST
&& !(flags
& NLM_F_EXCL
))
9061 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
9062 * @dev: the netdev being configured
9063 * @nlh: RTNL message
9065 * Inserts a new hardware bridge if not already created and
9066 * enables the bridging mode requested (VEB or VEPA). If the
9067 * hardware bridge has already been inserted and the request
9068 * is to change the mode then that requires a PF reset to
9069 * allow rebuild of the components with required hardware
9070 * bridge mode enabled.
9072 static int i40e_ndo_bridge_setlink(struct net_device
*dev
,
9073 struct nlmsghdr
*nlh
,
9076 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
9077 struct i40e_vsi
*vsi
= np
->vsi
;
9078 struct i40e_pf
*pf
= vsi
->back
;
9079 struct i40e_veb
*veb
= NULL
;
9080 struct nlattr
*attr
, *br_spec
;
9083 /* Only for PF VSI for now */
9084 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
)
9087 /* Find the HW bridge for PF VSI */
9088 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
9089 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
9093 br_spec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
9095 nla_for_each_nested(attr
, br_spec
, rem
) {
9098 if (nla_type(attr
) != IFLA_BRIDGE_MODE
)
9101 mode
= nla_get_u16(attr
);
9102 if ((mode
!= BRIDGE_MODE_VEPA
) &&
9103 (mode
!= BRIDGE_MODE_VEB
))
9106 /* Insert a new HW bridge */
9108 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
9109 vsi
->tc_config
.enabled_tc
);
9111 veb
->bridge_mode
= mode
;
9112 i40e_config_bridge_mode(veb
);
9114 /* No Bridge HW offload available */
9118 } else if (mode
!= veb
->bridge_mode
) {
9119 /* Existing HW bridge but different mode needs reset */
9120 veb
->bridge_mode
= mode
;
9121 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
9122 if (mode
== BRIDGE_MODE_VEB
)
9123 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
9125 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
9126 i40e_do_reset(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
9135 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
9138 * @seq: RTNL message seq #
9139 * @dev: the netdev being configured
9140 * @filter_mask: unused
9141 * @nlflags: netlink flags passed in
9143 * Return the mode in which the hardware bridge is operating in
9146 static int i40e_ndo_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
9147 struct net_device
*dev
,
9148 u32 __always_unused filter_mask
,
9151 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
9152 struct i40e_vsi
*vsi
= np
->vsi
;
9153 struct i40e_pf
*pf
= vsi
->back
;
9154 struct i40e_veb
*veb
= NULL
;
9157 /* Only for PF VSI for now */
9158 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
)
9161 /* Find the HW bridge for the PF VSI */
9162 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
9163 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
9170 return ndo_dflt_bridge_getlink(skb
, pid
, seq
, dev
, veb
->bridge_mode
,
9171 0, 0, nlflags
, filter_mask
, NULL
);
9175 * i40e_features_check - Validate encapsulated packet conforms to limits
9177 * @dev: This physical port's netdev
9178 * @features: Offload features that the stack believes apply
9180 static netdev_features_t
i40e_features_check(struct sk_buff
*skb
,
9181 struct net_device
*dev
,
9182 netdev_features_t features
)
9186 /* No point in doing any of this if neither checksum nor GSO are
9187 * being requested for this frame. We can rule out both by just
9188 * checking for CHECKSUM_PARTIAL
9190 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
9193 /* We cannot support GSO if the MSS is going to be less than
9194 * 64 bytes. If it is then we need to drop support for GSO.
9196 if (skb_is_gso(skb
) && (skb_shinfo(skb
)->gso_size
< 64))
9197 features
&= ~NETIF_F_GSO_MASK
;
9199 /* MACLEN can support at most 63 words */
9200 len
= skb_network_header(skb
) - skb
->data
;
9201 if (len
& ~(63 * 2))
9204 /* IPLEN and EIPLEN can support at most 127 dwords */
9205 len
= skb_transport_header(skb
) - skb_network_header(skb
);
9206 if (len
& ~(127 * 4))
9209 if (skb
->encapsulation
) {
9210 /* L4TUNLEN can support 127 words */
9211 len
= skb_inner_network_header(skb
) - skb_transport_header(skb
);
9212 if (len
& ~(127 * 2))
9215 /* IPLEN can support at most 127 dwords */
9216 len
= skb_inner_transport_header(skb
) -
9217 skb_inner_network_header(skb
);
9218 if (len
& ~(127 * 4))
9222 /* No need to validate L4LEN as TCP is the only protocol with a
9223 * a flexible value and we support all possible values supported
9224 * by TCP, which is at most 15 dwords
9229 return features
& ~(NETIF_F_CSUM_MASK
| NETIF_F_GSO_MASK
);
9232 static const struct net_device_ops i40e_netdev_ops
= {
9233 .ndo_open
= i40e_open
,
9234 .ndo_stop
= i40e_close
,
9235 .ndo_start_xmit
= i40e_lan_xmit_frame
,
9236 .ndo_get_stats64
= i40e_get_netdev_stats_struct
,
9237 .ndo_set_rx_mode
= i40e_set_rx_mode
,
9238 .ndo_validate_addr
= eth_validate_addr
,
9239 .ndo_set_mac_address
= i40e_set_mac
,
9240 .ndo_change_mtu
= i40e_change_mtu
,
9241 .ndo_do_ioctl
= i40e_ioctl
,
9242 .ndo_tx_timeout
= i40e_tx_timeout
,
9243 .ndo_vlan_rx_add_vid
= i40e_vlan_rx_add_vid
,
9244 .ndo_vlan_rx_kill_vid
= i40e_vlan_rx_kill_vid
,
9245 #ifdef CONFIG_NET_POLL_CONTROLLER
9246 .ndo_poll_controller
= i40e_netpoll
,
9248 .ndo_setup_tc
= __i40e_setup_tc
,
9250 .ndo_fcoe_enable
= i40e_fcoe_enable
,
9251 .ndo_fcoe_disable
= i40e_fcoe_disable
,
9253 .ndo_set_features
= i40e_set_features
,
9254 .ndo_set_vf_mac
= i40e_ndo_set_vf_mac
,
9255 .ndo_set_vf_vlan
= i40e_ndo_set_vf_port_vlan
,
9256 .ndo_set_vf_rate
= i40e_ndo_set_vf_bw
,
9257 .ndo_get_vf_config
= i40e_ndo_get_vf_config
,
9258 .ndo_set_vf_link_state
= i40e_ndo_set_vf_link_state
,
9259 .ndo_set_vf_spoofchk
= i40e_ndo_set_vf_spoofchk
,
9260 .ndo_set_vf_trust
= i40e_ndo_set_vf_trust
,
9261 .ndo_udp_tunnel_add
= i40e_udp_tunnel_add
,
9262 .ndo_udp_tunnel_del
= i40e_udp_tunnel_del
,
9263 .ndo_get_phys_port_id
= i40e_get_phys_port_id
,
9264 .ndo_fdb_add
= i40e_ndo_fdb_add
,
9265 .ndo_features_check
= i40e_features_check
,
9266 .ndo_bridge_getlink
= i40e_ndo_bridge_getlink
,
9267 .ndo_bridge_setlink
= i40e_ndo_bridge_setlink
,
9271 * i40e_config_netdev - Setup the netdev flags
9272 * @vsi: the VSI being configured
9274 * Returns 0 on success, negative value on failure
9276 static int i40e_config_netdev(struct i40e_vsi
*vsi
)
9278 struct i40e_pf
*pf
= vsi
->back
;
9279 struct i40e_hw
*hw
= &pf
->hw
;
9280 struct i40e_netdev_priv
*np
;
9281 struct net_device
*netdev
;
9282 u8 broadcast
[ETH_ALEN
];
9283 u8 mac_addr
[ETH_ALEN
];
9286 etherdev_size
= sizeof(struct i40e_netdev_priv
);
9287 netdev
= alloc_etherdev_mq(etherdev_size
, vsi
->alloc_queue_pairs
);
9291 vsi
->netdev
= netdev
;
9292 np
= netdev_priv(netdev
);
9295 netdev
->hw_enc_features
|= NETIF_F_SG
|
9299 NETIF_F_SOFT_FEATURES
|
9304 NETIF_F_GSO_GRE_CSUM
|
9305 NETIF_F_GSO_IPXIP4
|
9306 NETIF_F_GSO_IPXIP6
|
9307 NETIF_F_GSO_UDP_TUNNEL
|
9308 NETIF_F_GSO_UDP_TUNNEL_CSUM
|
9309 NETIF_F_GSO_PARTIAL
|
9315 if (!(pf
->flags
& I40E_FLAG_OUTER_UDP_CSUM_CAPABLE
))
9316 netdev
->gso_partial_features
|= NETIF_F_GSO_UDP_TUNNEL_CSUM
;
9318 netdev
->gso_partial_features
|= NETIF_F_GSO_GRE_CSUM
;
9320 /* record features VLANs can make use of */
9321 netdev
->vlan_features
|= netdev
->hw_enc_features
|
9322 NETIF_F_TSO_MANGLEID
;
9324 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
9325 netdev
->hw_features
|= NETIF_F_NTUPLE
;
9327 netdev
->hw_features
|= netdev
->hw_enc_features
|
9328 NETIF_F_HW_VLAN_CTAG_TX
|
9329 NETIF_F_HW_VLAN_CTAG_RX
;
9331 netdev
->features
|= netdev
->hw_features
| NETIF_F_HW_VLAN_CTAG_FILTER
;
9332 netdev
->hw_enc_features
|= NETIF_F_TSO_MANGLEID
;
9334 if (vsi
->type
== I40E_VSI_MAIN
) {
9335 SET_NETDEV_DEV(netdev
, &pf
->pdev
->dev
);
9336 ether_addr_copy(mac_addr
, hw
->mac
.perm_addr
);
9337 /* The following steps are necessary to prevent reception
9338 * of tagged packets - some older NVM configurations load a
9339 * default a MAC-VLAN filter that accepts any tagged packet
9340 * which must be replaced by a normal filter.
9342 i40e_rm_default_mac_filter(vsi
, mac_addr
);
9343 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
9344 i40e_add_mac_filter(vsi
, mac_addr
);
9345 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
9347 /* relate the VSI_VMDQ name to the VSI_MAIN name */
9348 snprintf(netdev
->name
, IFNAMSIZ
, "%sv%%d",
9349 pf
->vsi
[pf
->lan_vsi
]->netdev
->name
);
9350 random_ether_addr(mac_addr
);
9352 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
9353 i40e_add_mac_filter(vsi
, mac_addr
);
9354 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
9357 /* Add the broadcast filter so that we initially will receive
9358 * broadcast packets. Note that when a new VLAN is first added the
9359 * driver will convert all filters marked I40E_VLAN_ANY into VLAN
9360 * specific filters as part of transitioning into "vlan" operation.
9361 * When more VLANs are added, the driver will copy each existing MAC
9362 * filter and add it for the new VLAN.
9364 * Broadcast filters are handled specially by
9365 * i40e_sync_filters_subtask, as the driver must to set the broadcast
9366 * promiscuous bit instead of adding this directly as a MAC/VLAN
9367 * filter. The subtask will update the correct broadcast promiscuous
9368 * bits as VLANs become active or inactive.
9370 eth_broadcast_addr(broadcast
);
9371 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
9372 i40e_add_mac_filter(vsi
, broadcast
);
9373 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
9375 ether_addr_copy(netdev
->dev_addr
, mac_addr
);
9376 ether_addr_copy(netdev
->perm_addr
, mac_addr
);
9378 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
9379 netdev
->priv_flags
|= IFF_SUPP_NOFCS
;
9380 /* Setup netdev TC information */
9381 i40e_vsi_config_netdev_tc(vsi
, vsi
->tc_config
.enabled_tc
);
9383 netdev
->netdev_ops
= &i40e_netdev_ops
;
9384 netdev
->watchdog_timeo
= 5 * HZ
;
9385 i40e_set_ethtool_ops(netdev
);
9387 i40e_fcoe_config_netdev(netdev
, vsi
);
9390 /* MTU range: 68 - 9706 */
9391 netdev
->min_mtu
= ETH_MIN_MTU
;
9392 netdev
->max_mtu
= I40E_MAX_RXBUFFER
-
9393 (ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
);
9399 * i40e_vsi_delete - Delete a VSI from the switch
9400 * @vsi: the VSI being removed
9402 * Returns 0 on success, negative value on failure
9404 static void i40e_vsi_delete(struct i40e_vsi
*vsi
)
9406 /* remove default VSI is not allowed */
9407 if (vsi
== vsi
->back
->vsi
[vsi
->back
->lan_vsi
])
9410 i40e_aq_delete_element(&vsi
->back
->hw
, vsi
->seid
, NULL
);
9414 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
9415 * @vsi: the VSI being queried
9417 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
9419 int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi
*vsi
)
9421 struct i40e_veb
*veb
;
9422 struct i40e_pf
*pf
= vsi
->back
;
9424 /* Uplink is not a bridge so default to VEB */
9425 if (vsi
->veb_idx
== I40E_NO_VEB
)
9428 veb
= pf
->veb
[vsi
->veb_idx
];
9430 dev_info(&pf
->pdev
->dev
,
9431 "There is no veb associated with the bridge\n");
9435 /* Uplink is a bridge in VEPA mode */
9436 if (veb
->bridge_mode
& BRIDGE_MODE_VEPA
) {
9439 /* Uplink is a bridge in VEB mode */
9443 /* VEPA is now default bridge, so return 0 */
9448 * i40e_add_vsi - Add a VSI to the switch
9449 * @vsi: the VSI being configured
9451 * This initializes a VSI context depending on the VSI type to be added and
9452 * passes it down to the add_vsi aq command.
9454 static int i40e_add_vsi(struct i40e_vsi
*vsi
)
9457 struct i40e_pf
*pf
= vsi
->back
;
9458 struct i40e_hw
*hw
= &pf
->hw
;
9459 struct i40e_vsi_context ctxt
;
9460 struct i40e_mac_filter
*f
;
9461 struct hlist_node
*h
;
9464 u8 enabled_tc
= 0x1; /* TC0 enabled */
9467 memset(&ctxt
, 0, sizeof(ctxt
));
9468 switch (vsi
->type
) {
9470 /* The PF's main VSI is already setup as part of the
9471 * device initialization, so we'll not bother with
9472 * the add_vsi call, but we will retrieve the current
9475 ctxt
.seid
= pf
->main_vsi_seid
;
9476 ctxt
.pf_num
= pf
->hw
.pf_id
;
9478 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
9479 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
9481 dev_info(&pf
->pdev
->dev
,
9482 "couldn't get PF vsi config, err %s aq_err %s\n",
9483 i40e_stat_str(&pf
->hw
, ret
),
9484 i40e_aq_str(&pf
->hw
,
9485 pf
->hw
.aq
.asq_last_status
));
9488 vsi
->info
= ctxt
.info
;
9489 vsi
->info
.valid_sections
= 0;
9491 vsi
->seid
= ctxt
.seid
;
9492 vsi
->id
= ctxt
.vsi_number
;
9494 enabled_tc
= i40e_pf_get_tc_map(pf
);
9496 /* MFP mode setup queue map and update VSI */
9497 if ((pf
->flags
& I40E_FLAG_MFP_ENABLED
) &&
9498 !(pf
->hw
.func_caps
.iscsi
)) { /* NIC type PF */
9499 memset(&ctxt
, 0, sizeof(ctxt
));
9500 ctxt
.seid
= pf
->main_vsi_seid
;
9501 ctxt
.pf_num
= pf
->hw
.pf_id
;
9503 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
9504 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
9506 dev_info(&pf
->pdev
->dev
,
9507 "update vsi failed, err %s aq_err %s\n",
9508 i40e_stat_str(&pf
->hw
, ret
),
9509 i40e_aq_str(&pf
->hw
,
9510 pf
->hw
.aq
.asq_last_status
));
9514 /* update the local VSI info queue map */
9515 i40e_vsi_update_queue_map(vsi
, &ctxt
);
9516 vsi
->info
.valid_sections
= 0;
9518 /* Default/Main VSI is only enabled for TC0
9519 * reconfigure it to enable all TCs that are
9520 * available on the port in SFP mode.
9521 * For MFP case the iSCSI PF would use this
9522 * flow to enable LAN+iSCSI TC.
9524 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
9526 dev_info(&pf
->pdev
->dev
,
9527 "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
9529 i40e_stat_str(&pf
->hw
, ret
),
9530 i40e_aq_str(&pf
->hw
,
9531 pf
->hw
.aq
.asq_last_status
));
9538 ctxt
.pf_num
= hw
->pf_id
;
9540 ctxt
.uplink_seid
= vsi
->uplink_seid
;
9541 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
9542 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
9543 if ((pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
) &&
9544 (i40e_is_vsi_uplink_mode_veb(vsi
))) {
9545 ctxt
.info
.valid_sections
|=
9546 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
9547 ctxt
.info
.switch_id
=
9548 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
9550 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
9553 case I40E_VSI_VMDQ2
:
9554 ctxt
.pf_num
= hw
->pf_id
;
9556 ctxt
.uplink_seid
= vsi
->uplink_seid
;
9557 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
9558 ctxt
.flags
= I40E_AQ_VSI_TYPE_VMDQ2
;
9560 /* This VSI is connected to VEB so the switch_id
9561 * should be set to zero by default.
9563 if (i40e_is_vsi_uplink_mode_veb(vsi
)) {
9564 ctxt
.info
.valid_sections
|=
9565 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
9566 ctxt
.info
.switch_id
=
9567 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
9570 /* Setup the VSI tx/rx queue map for TC0 only for now */
9571 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
9574 case I40E_VSI_SRIOV
:
9575 ctxt
.pf_num
= hw
->pf_id
;
9576 ctxt
.vf_num
= vsi
->vf_id
+ hw
->func_caps
.vf_base_id
;
9577 ctxt
.uplink_seid
= vsi
->uplink_seid
;
9578 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
9579 ctxt
.flags
= I40E_AQ_VSI_TYPE_VF
;
9581 /* This VSI is connected to VEB so the switch_id
9582 * should be set to zero by default.
9584 if (i40e_is_vsi_uplink_mode_veb(vsi
)) {
9585 ctxt
.info
.valid_sections
|=
9586 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
9587 ctxt
.info
.switch_id
=
9588 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
9591 if (vsi
->back
->flags
& I40E_FLAG_IWARP_ENABLED
) {
9592 ctxt
.info
.valid_sections
|=
9593 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID
);
9594 ctxt
.info
.queueing_opt_flags
|=
9595 (I40E_AQ_VSI_QUE_OPT_TCP_ENA
|
9596 I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI
);
9599 ctxt
.info
.valid_sections
|= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
9600 ctxt
.info
.port_vlan_flags
|= I40E_AQ_VSI_PVLAN_MODE_ALL
;
9601 if (pf
->vf
[vsi
->vf_id
].spoofchk
) {
9602 ctxt
.info
.valid_sections
|=
9603 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID
);
9604 ctxt
.info
.sec_flags
|=
9605 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK
|
9606 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK
);
9608 /* Setup the VSI tx/rx queue map for TC0 only for now */
9609 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
9614 ret
= i40e_fcoe_vsi_init(vsi
, &ctxt
);
9616 dev_info(&pf
->pdev
->dev
, "failed to initialize FCoE VSI\n");
9621 #endif /* I40E_FCOE */
9622 case I40E_VSI_IWARP
:
9623 /* send down message to iWARP */
9630 if (vsi
->type
!= I40E_VSI_MAIN
) {
9631 ret
= i40e_aq_add_vsi(hw
, &ctxt
, NULL
);
9633 dev_info(&vsi
->back
->pdev
->dev
,
9634 "add vsi failed, err %s aq_err %s\n",
9635 i40e_stat_str(&pf
->hw
, ret
),
9636 i40e_aq_str(&pf
->hw
,
9637 pf
->hw
.aq
.asq_last_status
));
9641 vsi
->info
= ctxt
.info
;
9642 vsi
->info
.valid_sections
= 0;
9643 vsi
->seid
= ctxt
.seid
;
9644 vsi
->id
= ctxt
.vsi_number
;
9647 vsi
->active_filters
= 0;
9648 clear_bit(__I40E_FILTER_OVERFLOW_PROMISC
, &vsi
->state
);
9649 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
9650 /* If macvlan filters already exist, force them to get loaded */
9651 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
) {
9652 f
->state
= I40E_FILTER_NEW
;
9655 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
9658 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
9659 pf
->flags
|= I40E_FLAG_FILTER_SYNC
;
9662 /* Update VSI BW information */
9663 ret
= i40e_vsi_get_bw_info(vsi
);
9665 dev_info(&pf
->pdev
->dev
,
9666 "couldn't get vsi bw info, err %s aq_err %s\n",
9667 i40e_stat_str(&pf
->hw
, ret
),
9668 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9669 /* VSI is already added so not tearing that up */
9678 * i40e_vsi_release - Delete a VSI and free its resources
9679 * @vsi: the VSI being removed
9681 * Returns 0 on success or < 0 on error
9683 int i40e_vsi_release(struct i40e_vsi
*vsi
)
9685 struct i40e_mac_filter
*f
;
9686 struct hlist_node
*h
;
9687 struct i40e_veb
*veb
= NULL
;
9694 /* release of a VEB-owner or last VSI is not allowed */
9695 if (vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
9696 dev_info(&pf
->pdev
->dev
, "VSI %d has existing VEB %d\n",
9697 vsi
->seid
, vsi
->uplink_seid
);
9700 if (vsi
== pf
->vsi
[pf
->lan_vsi
] &&
9701 !test_bit(__I40E_DOWN
, &pf
->state
)) {
9702 dev_info(&pf
->pdev
->dev
, "Can't remove PF VSI\n");
9706 uplink_seid
= vsi
->uplink_seid
;
9707 if (vsi
->type
!= I40E_VSI_SRIOV
) {
9708 if (vsi
->netdev_registered
) {
9709 vsi
->netdev_registered
= false;
9711 /* results in a call to i40e_close() */
9712 unregister_netdev(vsi
->netdev
);
9715 i40e_vsi_close(vsi
);
9717 i40e_vsi_disable_irq(vsi
);
9720 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
9722 /* clear the sync flag on all filters */
9724 __dev_uc_unsync(vsi
->netdev
, NULL
);
9725 __dev_mc_unsync(vsi
->netdev
, NULL
);
9728 /* make sure any remaining filters are marked for deletion */
9729 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
)
9730 __i40e_del_filter(vsi
, f
);
9732 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
9734 i40e_sync_vsi_filters(vsi
);
9736 i40e_vsi_delete(vsi
);
9737 i40e_vsi_free_q_vectors(vsi
);
9739 free_netdev(vsi
->netdev
);
9742 i40e_vsi_clear_rings(vsi
);
9743 i40e_vsi_clear(vsi
);
9745 /* If this was the last thing on the VEB, except for the
9746 * controlling VSI, remove the VEB, which puts the controlling
9747 * VSI onto the next level down in the switch.
9749 * Well, okay, there's one more exception here: don't remove
9750 * the orphan VEBs yet. We'll wait for an explicit remove request
9751 * from up the network stack.
9753 for (n
= 0, i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9755 pf
->vsi
[i
]->uplink_seid
== uplink_seid
&&
9756 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
9757 n
++; /* count the VSIs */
9760 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
9763 if (pf
->veb
[i
]->uplink_seid
== uplink_seid
)
9764 n
++; /* count the VEBs */
9765 if (pf
->veb
[i
]->seid
== uplink_seid
)
9768 if (n
== 0 && veb
&& veb
->uplink_seid
!= 0)
9769 i40e_veb_release(veb
);
9775 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
9776 * @vsi: ptr to the VSI
9778 * This should only be called after i40e_vsi_mem_alloc() which allocates the
9779 * corresponding SW VSI structure and initializes num_queue_pairs for the
9780 * newly allocated VSI.
9782 * Returns 0 on success or negative on failure
9784 static int i40e_vsi_setup_vectors(struct i40e_vsi
*vsi
)
9787 struct i40e_pf
*pf
= vsi
->back
;
9789 if (vsi
->q_vectors
[0]) {
9790 dev_info(&pf
->pdev
->dev
, "VSI %d has existing q_vectors\n",
9795 if (vsi
->base_vector
) {
9796 dev_info(&pf
->pdev
->dev
, "VSI %d has non-zero base vector %d\n",
9797 vsi
->seid
, vsi
->base_vector
);
9801 ret
= i40e_vsi_alloc_q_vectors(vsi
);
9803 dev_info(&pf
->pdev
->dev
,
9804 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
9805 vsi
->num_q_vectors
, vsi
->seid
, ret
);
9806 vsi
->num_q_vectors
= 0;
9807 goto vector_setup_out
;
9810 /* In Legacy mode, we do not have to get any other vector since we
9811 * piggyback on the misc/ICR0 for queue interrupts.
9813 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
9815 if (vsi
->num_q_vectors
)
9816 vsi
->base_vector
= i40e_get_lump(pf
, pf
->irq_pile
,
9817 vsi
->num_q_vectors
, vsi
->idx
);
9818 if (vsi
->base_vector
< 0) {
9819 dev_info(&pf
->pdev
->dev
,
9820 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
9821 vsi
->num_q_vectors
, vsi
->seid
, vsi
->base_vector
);
9822 i40e_vsi_free_q_vectors(vsi
);
9824 goto vector_setup_out
;
9832 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
9833 * @vsi: pointer to the vsi.
9835 * This re-allocates a vsi's queue resources.
9837 * Returns pointer to the successfully allocated and configured VSI sw struct
9838 * on success, otherwise returns NULL on failure.
9840 static struct i40e_vsi
*i40e_vsi_reinit_setup(struct i40e_vsi
*vsi
)
9851 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
9852 i40e_vsi_clear_rings(vsi
);
9854 i40e_vsi_free_arrays(vsi
, false);
9855 i40e_set_num_rings_in_vsi(vsi
);
9856 ret
= i40e_vsi_alloc_arrays(vsi
, false);
9860 ret
= i40e_get_lump(pf
, pf
->qp_pile
, vsi
->alloc_queue_pairs
, vsi
->idx
);
9862 dev_info(&pf
->pdev
->dev
,
9863 "failed to get tracking for %d queues for VSI %d err %d\n",
9864 vsi
->alloc_queue_pairs
, vsi
->seid
, ret
);
9867 vsi
->base_queue
= ret
;
9869 /* Update the FW view of the VSI. Force a reset of TC and queue
9870 * layout configurations.
9872 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
9873 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
9874 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
9875 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
9876 if (vsi
->type
== I40E_VSI_MAIN
)
9877 i40e_rm_default_mac_filter(vsi
, pf
->hw
.mac
.perm_addr
);
9879 /* assign it some queues */
9880 ret
= i40e_alloc_rings(vsi
);
9884 /* map all of the rings to the q_vectors */
9885 i40e_vsi_map_rings_to_vectors(vsi
);
9889 i40e_vsi_free_q_vectors(vsi
);
9890 if (vsi
->netdev_registered
) {
9891 vsi
->netdev_registered
= false;
9892 unregister_netdev(vsi
->netdev
);
9893 free_netdev(vsi
->netdev
);
9896 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
9898 i40e_vsi_clear(vsi
);
9903 * i40e_vsi_setup - Set up a VSI by a given type
9904 * @pf: board private structure
9906 * @uplink_seid: the switch element to link to
9907 * @param1: usage depends upon VSI type. For VF types, indicates VF id
9909 * This allocates the sw VSI structure and its queue resources, then add a VSI
9910 * to the identified VEB.
9912 * Returns pointer to the successfully allocated and configure VSI sw struct on
9913 * success, otherwise returns NULL on failure.
9915 struct i40e_vsi
*i40e_vsi_setup(struct i40e_pf
*pf
, u8 type
,
9916 u16 uplink_seid
, u32 param1
)
9918 struct i40e_vsi
*vsi
= NULL
;
9919 struct i40e_veb
*veb
= NULL
;
9923 /* The requested uplink_seid must be either
9924 * - the PF's port seid
9925 * no VEB is needed because this is the PF
9926 * or this is a Flow Director special case VSI
9927 * - seid of an existing VEB
9928 * - seid of a VSI that owns an existing VEB
9929 * - seid of a VSI that doesn't own a VEB
9930 * a new VEB is created and the VSI becomes the owner
9931 * - seid of the PF VSI, which is what creates the first VEB
9932 * this is a special case of the previous
9934 * Find which uplink_seid we were given and create a new VEB if needed
9936 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
9937 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== uplink_seid
) {
9943 if (!veb
&& uplink_seid
!= pf
->mac_seid
) {
9945 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9946 if (pf
->vsi
[i
] && pf
->vsi
[i
]->seid
== uplink_seid
) {
9952 dev_info(&pf
->pdev
->dev
, "no such uplink_seid %d\n",
9957 if (vsi
->uplink_seid
== pf
->mac_seid
)
9958 veb
= i40e_veb_setup(pf
, 0, pf
->mac_seid
, vsi
->seid
,
9959 vsi
->tc_config
.enabled_tc
);
9960 else if ((vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0)
9961 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
9962 vsi
->tc_config
.enabled_tc
);
9964 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
) {
9965 dev_info(&vsi
->back
->pdev
->dev
,
9966 "New VSI creation error, uplink seid of LAN VSI expected.\n");
9969 /* We come up by default in VEPA mode if SRIOV is not
9970 * already enabled, in which case we can't force VEPA
9973 if (!(pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)) {
9974 veb
->bridge_mode
= BRIDGE_MODE_VEPA
;
9975 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
9977 i40e_config_bridge_mode(veb
);
9979 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
9980 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
9984 dev_info(&pf
->pdev
->dev
, "couldn't add VEB\n");
9988 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
9989 uplink_seid
= veb
->seid
;
9992 /* get vsi sw struct */
9993 v_idx
= i40e_vsi_mem_alloc(pf
, type
);
9996 vsi
= pf
->vsi
[v_idx
];
10000 vsi
->veb_idx
= (veb
? veb
->idx
: I40E_NO_VEB
);
10002 if (type
== I40E_VSI_MAIN
)
10003 pf
->lan_vsi
= v_idx
;
10004 else if (type
== I40E_VSI_SRIOV
)
10005 vsi
->vf_id
= param1
;
10006 /* assign it some queues */
10007 ret
= i40e_get_lump(pf
, pf
->qp_pile
, vsi
->alloc_queue_pairs
,
10010 dev_info(&pf
->pdev
->dev
,
10011 "failed to get tracking for %d queues for VSI %d err=%d\n",
10012 vsi
->alloc_queue_pairs
, vsi
->seid
, ret
);
10015 vsi
->base_queue
= ret
;
10017 /* get a VSI from the hardware */
10018 vsi
->uplink_seid
= uplink_seid
;
10019 ret
= i40e_add_vsi(vsi
);
10023 switch (vsi
->type
) {
10024 /* setup the netdev if needed */
10025 case I40E_VSI_MAIN
:
10026 /* Apply relevant filters if a platform-specific mac
10027 * address was selected.
10029 if (!!(pf
->flags
& I40E_FLAG_PF_MAC
)) {
10030 ret
= i40e_macaddr_init(vsi
, pf
->hw
.mac
.addr
);
10032 dev_warn(&pf
->pdev
->dev
,
10033 "could not set up macaddr; err %d\n",
10037 case I40E_VSI_VMDQ2
:
10038 case I40E_VSI_FCOE
:
10039 ret
= i40e_config_netdev(vsi
);
10042 ret
= register_netdev(vsi
->netdev
);
10045 vsi
->netdev_registered
= true;
10046 netif_carrier_off(vsi
->netdev
);
10047 #ifdef CONFIG_I40E_DCB
10048 /* Setup DCB netlink interface */
10049 i40e_dcbnl_setup(vsi
);
10050 #endif /* CONFIG_I40E_DCB */
10053 case I40E_VSI_FDIR
:
10054 /* set up vectors and rings if needed */
10055 ret
= i40e_vsi_setup_vectors(vsi
);
10059 ret
= i40e_alloc_rings(vsi
);
10063 /* map all of the rings to the q_vectors */
10064 i40e_vsi_map_rings_to_vectors(vsi
);
10066 i40e_vsi_reset_stats(vsi
);
10070 /* no netdev or rings for the other VSI types */
10074 if ((pf
->flags
& I40E_FLAG_RSS_AQ_CAPABLE
) &&
10075 (vsi
->type
== I40E_VSI_VMDQ2
)) {
10076 ret
= i40e_vsi_config_rss(vsi
);
10081 i40e_vsi_free_q_vectors(vsi
);
10083 if (vsi
->netdev_registered
) {
10084 vsi
->netdev_registered
= false;
10085 unregister_netdev(vsi
->netdev
);
10086 free_netdev(vsi
->netdev
);
10087 vsi
->netdev
= NULL
;
10090 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
10092 i40e_vsi_clear(vsi
);
10098 * i40e_veb_get_bw_info - Query VEB BW information
10099 * @veb: the veb to query
10101 * Query the Tx scheduler BW configuration data for given VEB
10103 static int i40e_veb_get_bw_info(struct i40e_veb
*veb
)
10105 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data
;
10106 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data
;
10107 struct i40e_pf
*pf
= veb
->pf
;
10108 struct i40e_hw
*hw
= &pf
->hw
;
10113 ret
= i40e_aq_query_switch_comp_bw_config(hw
, veb
->seid
,
10116 dev_info(&pf
->pdev
->dev
,
10117 "query veb bw config failed, err %s aq_err %s\n",
10118 i40e_stat_str(&pf
->hw
, ret
),
10119 i40e_aq_str(&pf
->hw
, hw
->aq
.asq_last_status
));
10123 ret
= i40e_aq_query_switch_comp_ets_config(hw
, veb
->seid
,
10126 dev_info(&pf
->pdev
->dev
,
10127 "query veb bw ets config failed, err %s aq_err %s\n",
10128 i40e_stat_str(&pf
->hw
, ret
),
10129 i40e_aq_str(&pf
->hw
, hw
->aq
.asq_last_status
));
10133 veb
->bw_limit
= le16_to_cpu(ets_data
.port_bw_limit
);
10134 veb
->bw_max_quanta
= ets_data
.tc_bw_max
;
10135 veb
->is_abs_credits
= bw_data
.absolute_credits_enable
;
10136 veb
->enabled_tc
= ets_data
.tc_valid_bits
;
10137 tc_bw_max
= le16_to_cpu(bw_data
.tc_bw_max
[0]) |
10138 (le16_to_cpu(bw_data
.tc_bw_max
[1]) << 16);
10139 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
10140 veb
->bw_tc_share_credits
[i
] = bw_data
.tc_bw_share_credits
[i
];
10141 veb
->bw_tc_limit_credits
[i
] =
10142 le16_to_cpu(bw_data
.tc_bw_limits
[i
]);
10143 veb
->bw_tc_max_quanta
[i
] = ((tc_bw_max
>> (i
*4)) & 0x7);
10151 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
10152 * @pf: board private structure
10154 * On error: returns error code (negative)
10155 * On success: returns vsi index in PF (positive)
10157 static int i40e_veb_mem_alloc(struct i40e_pf
*pf
)
10160 struct i40e_veb
*veb
;
10163 /* Need to protect the allocation of switch elements at the PF level */
10164 mutex_lock(&pf
->switch_mutex
);
10166 /* VEB list may be fragmented if VEB creation/destruction has
10167 * been happening. We can afford to do a quick scan to look
10168 * for any free slots in the list.
10170 * find next empty veb slot, looping back around if necessary
10173 while ((i
< I40E_MAX_VEB
) && (pf
->veb
[i
] != NULL
))
10175 if (i
>= I40E_MAX_VEB
) {
10177 goto err_alloc_veb
; /* out of VEB slots! */
10180 veb
= kzalloc(sizeof(*veb
), GFP_KERNEL
);
10183 goto err_alloc_veb
;
10187 veb
->enabled_tc
= 1;
10192 mutex_unlock(&pf
->switch_mutex
);
10197 * i40e_switch_branch_release - Delete a branch of the switch tree
10198 * @branch: where to start deleting
10200 * This uses recursion to find the tips of the branch to be
10201 * removed, deleting until we get back to and can delete this VEB.
10203 static void i40e_switch_branch_release(struct i40e_veb
*branch
)
10205 struct i40e_pf
*pf
= branch
->pf
;
10206 u16 branch_seid
= branch
->seid
;
10207 u16 veb_idx
= branch
->idx
;
10210 /* release any VEBs on this VEB - RECURSION */
10211 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
10214 if (pf
->veb
[i
]->uplink_seid
== branch
->seid
)
10215 i40e_switch_branch_release(pf
->veb
[i
]);
10218 /* Release the VSIs on this VEB, but not the owner VSI.
10220 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
10221 * the VEB itself, so don't use (*branch) after this loop.
10223 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
10226 if (pf
->vsi
[i
]->uplink_seid
== branch_seid
&&
10227 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
10228 i40e_vsi_release(pf
->vsi
[i
]);
10232 /* There's one corner case where the VEB might not have been
10233 * removed, so double check it here and remove it if needed.
10234 * This case happens if the veb was created from the debugfs
10235 * commands and no VSIs were added to it.
10237 if (pf
->veb
[veb_idx
])
10238 i40e_veb_release(pf
->veb
[veb_idx
]);
10242 * i40e_veb_clear - remove veb struct
10243 * @veb: the veb to remove
10245 static void i40e_veb_clear(struct i40e_veb
*veb
)
10251 struct i40e_pf
*pf
= veb
->pf
;
10253 mutex_lock(&pf
->switch_mutex
);
10254 if (pf
->veb
[veb
->idx
] == veb
)
10255 pf
->veb
[veb
->idx
] = NULL
;
10256 mutex_unlock(&pf
->switch_mutex
);
10263 * i40e_veb_release - Delete a VEB and free its resources
10264 * @veb: the VEB being removed
10266 void i40e_veb_release(struct i40e_veb
*veb
)
10268 struct i40e_vsi
*vsi
= NULL
;
10269 struct i40e_pf
*pf
;
10274 /* find the remaining VSI and check for extras */
10275 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
10276 if (pf
->vsi
[i
] && pf
->vsi
[i
]->uplink_seid
== veb
->seid
) {
10282 dev_info(&pf
->pdev
->dev
,
10283 "can't remove VEB %d with %d VSIs left\n",
10288 /* move the remaining VSI to uplink veb */
10289 vsi
->flags
&= ~I40E_VSI_FLAG_VEB_OWNER
;
10290 if (veb
->uplink_seid
) {
10291 vsi
->uplink_seid
= veb
->uplink_seid
;
10292 if (veb
->uplink_seid
== pf
->mac_seid
)
10293 vsi
->veb_idx
= I40E_NO_VEB
;
10295 vsi
->veb_idx
= veb
->veb_idx
;
10298 vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
10299 vsi
->veb_idx
= pf
->vsi
[pf
->lan_vsi
]->veb_idx
;
10302 i40e_aq_delete_element(&pf
->hw
, veb
->seid
, NULL
);
10303 i40e_veb_clear(veb
);
10307 * i40e_add_veb - create the VEB in the switch
10308 * @veb: the VEB to be instantiated
10309 * @vsi: the controlling VSI
10311 static int i40e_add_veb(struct i40e_veb
*veb
, struct i40e_vsi
*vsi
)
10313 struct i40e_pf
*pf
= veb
->pf
;
10314 bool enable_stats
= !!(pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
);
10317 ret
= i40e_aq_add_veb(&pf
->hw
, veb
->uplink_seid
, vsi
->seid
,
10318 veb
->enabled_tc
, false,
10319 &veb
->seid
, enable_stats
, NULL
);
10321 /* get a VEB from the hardware */
10323 dev_info(&pf
->pdev
->dev
,
10324 "couldn't add VEB, err %s aq_err %s\n",
10325 i40e_stat_str(&pf
->hw
, ret
),
10326 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10330 /* get statistics counter */
10331 ret
= i40e_aq_get_veb_parameters(&pf
->hw
, veb
->seid
, NULL
, NULL
,
10332 &veb
->stats_idx
, NULL
, NULL
, NULL
);
10334 dev_info(&pf
->pdev
->dev
,
10335 "couldn't get VEB statistics idx, err %s aq_err %s\n",
10336 i40e_stat_str(&pf
->hw
, ret
),
10337 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10340 ret
= i40e_veb_get_bw_info(veb
);
10342 dev_info(&pf
->pdev
->dev
,
10343 "couldn't get VEB bw info, err %s aq_err %s\n",
10344 i40e_stat_str(&pf
->hw
, ret
),
10345 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10346 i40e_aq_delete_element(&pf
->hw
, veb
->seid
, NULL
);
10350 vsi
->uplink_seid
= veb
->seid
;
10351 vsi
->veb_idx
= veb
->idx
;
10352 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
10358 * i40e_veb_setup - Set up a VEB
10359 * @pf: board private structure
10360 * @flags: VEB setup flags
10361 * @uplink_seid: the switch element to link to
10362 * @vsi_seid: the initial VSI seid
10363 * @enabled_tc: Enabled TC bit-map
10365 * This allocates the sw VEB structure and links it into the switch
10366 * It is possible and legal for this to be a duplicate of an already
10367 * existing VEB. It is also possible for both uplink and vsi seids
10368 * to be zero, in order to create a floating VEB.
10370 * Returns pointer to the successfully allocated VEB sw struct on
10371 * success, otherwise returns NULL on failure.
10373 struct i40e_veb
*i40e_veb_setup(struct i40e_pf
*pf
, u16 flags
,
10374 u16 uplink_seid
, u16 vsi_seid
,
10377 struct i40e_veb
*veb
, *uplink_veb
= NULL
;
10378 int vsi_idx
, veb_idx
;
10381 /* if one seid is 0, the other must be 0 to create a floating relay */
10382 if ((uplink_seid
== 0 || vsi_seid
== 0) &&
10383 (uplink_seid
+ vsi_seid
!= 0)) {
10384 dev_info(&pf
->pdev
->dev
,
10385 "one, not both seid's are 0: uplink=%d vsi=%d\n",
10386 uplink_seid
, vsi_seid
);
10390 /* make sure there is such a vsi and uplink */
10391 for (vsi_idx
= 0; vsi_idx
< pf
->num_alloc_vsi
; vsi_idx
++)
10392 if (pf
->vsi
[vsi_idx
] && pf
->vsi
[vsi_idx
]->seid
== vsi_seid
)
10394 if (vsi_idx
>= pf
->num_alloc_vsi
&& vsi_seid
!= 0) {
10395 dev_info(&pf
->pdev
->dev
, "vsi seid %d not found\n",
10400 if (uplink_seid
&& uplink_seid
!= pf
->mac_seid
) {
10401 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
10402 if (pf
->veb
[veb_idx
] &&
10403 pf
->veb
[veb_idx
]->seid
== uplink_seid
) {
10404 uplink_veb
= pf
->veb
[veb_idx
];
10409 dev_info(&pf
->pdev
->dev
,
10410 "uplink seid %d not found\n", uplink_seid
);
10415 /* get veb sw struct */
10416 veb_idx
= i40e_veb_mem_alloc(pf
);
10419 veb
= pf
->veb
[veb_idx
];
10420 veb
->flags
= flags
;
10421 veb
->uplink_seid
= uplink_seid
;
10422 veb
->veb_idx
= (uplink_veb
? uplink_veb
->idx
: I40E_NO_VEB
);
10423 veb
->enabled_tc
= (enabled_tc
? enabled_tc
: 0x1);
10425 /* create the VEB in the switch */
10426 ret
= i40e_add_veb(veb
, pf
->vsi
[vsi_idx
]);
10429 if (vsi_idx
== pf
->lan_vsi
)
10430 pf
->lan_veb
= veb
->idx
;
10435 i40e_veb_clear(veb
);
10441 * i40e_setup_pf_switch_element - set PF vars based on switch type
10442 * @pf: board private structure
10443 * @ele: element we are building info from
10444 * @num_reported: total number of elements
10445 * @printconfig: should we print the contents
10447 * helper function to assist in extracting a few useful SEID values.
10449 static void i40e_setup_pf_switch_element(struct i40e_pf
*pf
,
10450 struct i40e_aqc_switch_config_element_resp
*ele
,
10451 u16 num_reported
, bool printconfig
)
10453 u16 downlink_seid
= le16_to_cpu(ele
->downlink_seid
);
10454 u16 uplink_seid
= le16_to_cpu(ele
->uplink_seid
);
10455 u8 element_type
= ele
->element_type
;
10456 u16 seid
= le16_to_cpu(ele
->seid
);
10459 dev_info(&pf
->pdev
->dev
,
10460 "type=%d seid=%d uplink=%d downlink=%d\n",
10461 element_type
, seid
, uplink_seid
, downlink_seid
);
10463 switch (element_type
) {
10464 case I40E_SWITCH_ELEMENT_TYPE_MAC
:
10465 pf
->mac_seid
= seid
;
10467 case I40E_SWITCH_ELEMENT_TYPE_VEB
:
10469 if (uplink_seid
!= pf
->mac_seid
)
10471 if (pf
->lan_veb
== I40E_NO_VEB
) {
10474 /* find existing or else empty VEB */
10475 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
10476 if (pf
->veb
[v
] && (pf
->veb
[v
]->seid
== seid
)) {
10481 if (pf
->lan_veb
== I40E_NO_VEB
) {
10482 v
= i40e_veb_mem_alloc(pf
);
10489 pf
->veb
[pf
->lan_veb
]->seid
= seid
;
10490 pf
->veb
[pf
->lan_veb
]->uplink_seid
= pf
->mac_seid
;
10491 pf
->veb
[pf
->lan_veb
]->pf
= pf
;
10492 pf
->veb
[pf
->lan_veb
]->veb_idx
= I40E_NO_VEB
;
10494 case I40E_SWITCH_ELEMENT_TYPE_VSI
:
10495 if (num_reported
!= 1)
10497 /* This is immediately after a reset so we can assume this is
10500 pf
->mac_seid
= uplink_seid
;
10501 pf
->pf_seid
= downlink_seid
;
10502 pf
->main_vsi_seid
= seid
;
10504 dev_info(&pf
->pdev
->dev
,
10505 "pf_seid=%d main_vsi_seid=%d\n",
10506 pf
->pf_seid
, pf
->main_vsi_seid
);
10508 case I40E_SWITCH_ELEMENT_TYPE_PF
:
10509 case I40E_SWITCH_ELEMENT_TYPE_VF
:
10510 case I40E_SWITCH_ELEMENT_TYPE_EMP
:
10511 case I40E_SWITCH_ELEMENT_TYPE_BMC
:
10512 case I40E_SWITCH_ELEMENT_TYPE_PE
:
10513 case I40E_SWITCH_ELEMENT_TYPE_PA
:
10514 /* ignore these for now */
10517 dev_info(&pf
->pdev
->dev
, "unknown element type=%d seid=%d\n",
10518 element_type
, seid
);
10524 * i40e_fetch_switch_configuration - Get switch config from firmware
10525 * @pf: board private structure
10526 * @printconfig: should we print the contents
10528 * Get the current switch configuration from the device and
10529 * extract a few useful SEID values.
10531 int i40e_fetch_switch_configuration(struct i40e_pf
*pf
, bool printconfig
)
10533 struct i40e_aqc_get_switch_config_resp
*sw_config
;
10539 aq_buf
= kzalloc(I40E_AQ_LARGE_BUF
, GFP_KERNEL
);
10543 sw_config
= (struct i40e_aqc_get_switch_config_resp
*)aq_buf
;
10545 u16 num_reported
, num_total
;
10547 ret
= i40e_aq_get_switch_config(&pf
->hw
, sw_config
,
10551 dev_info(&pf
->pdev
->dev
,
10552 "get switch config failed err %s aq_err %s\n",
10553 i40e_stat_str(&pf
->hw
, ret
),
10554 i40e_aq_str(&pf
->hw
,
10555 pf
->hw
.aq
.asq_last_status
));
10560 num_reported
= le16_to_cpu(sw_config
->header
.num_reported
);
10561 num_total
= le16_to_cpu(sw_config
->header
.num_total
);
10564 dev_info(&pf
->pdev
->dev
,
10565 "header: %d reported %d total\n",
10566 num_reported
, num_total
);
10568 for (i
= 0; i
< num_reported
; i
++) {
10569 struct i40e_aqc_switch_config_element_resp
*ele
=
10570 &sw_config
->element
[i
];
10572 i40e_setup_pf_switch_element(pf
, ele
, num_reported
,
10575 } while (next_seid
!= 0);
10582 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
10583 * @pf: board private structure
10584 * @reinit: if the Main VSI needs to re-initialized.
10586 * Returns 0 on success, negative value on failure
10588 static int i40e_setup_pf_switch(struct i40e_pf
*pf
, bool reinit
)
10593 /* find out what's out there already */
10594 ret
= i40e_fetch_switch_configuration(pf
, false);
10596 dev_info(&pf
->pdev
->dev
,
10597 "couldn't fetch switch config, err %s aq_err %s\n",
10598 i40e_stat_str(&pf
->hw
, ret
),
10599 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10602 i40e_pf_reset_stats(pf
);
10604 /* set the switch config bit for the whole device to
10605 * support limited promisc or true promisc
10606 * when user requests promisc. The default is limited
10610 if ((pf
->hw
.pf_id
== 0) &&
10611 !(pf
->flags
& I40E_FLAG_TRUE_PROMISC_SUPPORT
))
10612 flags
= I40E_AQ_SET_SWITCH_CFG_PROMISC
;
10614 if (pf
->hw
.pf_id
== 0) {
10617 valid_flags
= I40E_AQ_SET_SWITCH_CFG_PROMISC
;
10618 ret
= i40e_aq_set_switch_config(&pf
->hw
, flags
, valid_flags
,
10620 if (ret
&& pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_ESRCH
) {
10621 dev_info(&pf
->pdev
->dev
,
10622 "couldn't set switch config bits, err %s aq_err %s\n",
10623 i40e_stat_str(&pf
->hw
, ret
),
10624 i40e_aq_str(&pf
->hw
,
10625 pf
->hw
.aq
.asq_last_status
));
10626 /* not a fatal problem, just keep going */
10630 /* first time setup */
10631 if (pf
->lan_vsi
== I40E_NO_VSI
|| reinit
) {
10632 struct i40e_vsi
*vsi
= NULL
;
10635 /* Set up the PF VSI associated with the PF's main VSI
10636 * that is already in the HW switch
10638 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
10639 uplink_seid
= pf
->veb
[pf
->lan_veb
]->seid
;
10641 uplink_seid
= pf
->mac_seid
;
10642 if (pf
->lan_vsi
== I40E_NO_VSI
)
10643 vsi
= i40e_vsi_setup(pf
, I40E_VSI_MAIN
, uplink_seid
, 0);
10645 vsi
= i40e_vsi_reinit_setup(pf
->vsi
[pf
->lan_vsi
]);
10647 dev_info(&pf
->pdev
->dev
, "setup of MAIN VSI failed\n");
10648 i40e_fdir_teardown(pf
);
10652 /* force a reset of TC and queue layout configurations */
10653 u8 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
10655 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
10656 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
10657 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
10659 i40e_vlan_stripping_disable(pf
->vsi
[pf
->lan_vsi
]);
10661 i40e_fdir_sb_setup(pf
);
10663 /* Setup static PF queue filter control settings */
10664 ret
= i40e_setup_pf_filter_control(pf
);
10666 dev_info(&pf
->pdev
->dev
, "setup_pf_filter_control failed: %d\n",
10668 /* Failure here should not stop continuing other steps */
10671 /* enable RSS in the HW, even for only one queue, as the stack can use
10674 if ((pf
->flags
& I40E_FLAG_RSS_ENABLED
))
10675 i40e_pf_config_rss(pf
);
10677 /* fill in link information and enable LSE reporting */
10678 i40e_update_link_info(&pf
->hw
);
10679 i40e_link_event(pf
);
10681 /* Initialize user-specific link properties */
10682 pf
->fc_autoneg_status
= ((pf
->hw
.phy
.link_info
.an_info
&
10683 I40E_AQ_AN_COMPLETED
) ? true : false);
10691 * i40e_determine_queue_usage - Work out queue distribution
10692 * @pf: board private structure
10694 static void i40e_determine_queue_usage(struct i40e_pf
*pf
)
10698 pf
->num_lan_qps
= 0;
10700 pf
->num_fcoe_qps
= 0;
10703 /* Find the max queues to be put into basic use. We'll always be
10704 * using TC0, whether or not DCB is running, and TC0 will get the
10707 queues_left
= pf
->hw
.func_caps
.num_tx_qp
;
10709 if ((queues_left
== 1) ||
10710 !(pf
->flags
& I40E_FLAG_MSIX_ENABLED
)) {
10711 /* one qp for PF, no queues for anything else */
10713 pf
->alloc_rss_size
= pf
->num_lan_qps
= 1;
10715 /* make sure all the fancies are disabled */
10716 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
10717 I40E_FLAG_IWARP_ENABLED
|
10719 I40E_FLAG_FCOE_ENABLED
|
10721 I40E_FLAG_FD_SB_ENABLED
|
10722 I40E_FLAG_FD_ATR_ENABLED
|
10723 I40E_FLAG_DCB_CAPABLE
|
10724 I40E_FLAG_DCB_ENABLED
|
10725 I40E_FLAG_SRIOV_ENABLED
|
10726 I40E_FLAG_VMDQ_ENABLED
);
10727 } else if (!(pf
->flags
& (I40E_FLAG_RSS_ENABLED
|
10728 I40E_FLAG_FD_SB_ENABLED
|
10729 I40E_FLAG_FD_ATR_ENABLED
|
10730 I40E_FLAG_DCB_CAPABLE
))) {
10731 /* one qp for PF */
10732 pf
->alloc_rss_size
= pf
->num_lan_qps
= 1;
10733 queues_left
-= pf
->num_lan_qps
;
10735 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
10736 I40E_FLAG_IWARP_ENABLED
|
10738 I40E_FLAG_FCOE_ENABLED
|
10740 I40E_FLAG_FD_SB_ENABLED
|
10741 I40E_FLAG_FD_ATR_ENABLED
|
10742 I40E_FLAG_DCB_ENABLED
|
10743 I40E_FLAG_VMDQ_ENABLED
);
10745 /* Not enough queues for all TCs */
10746 if ((pf
->flags
& I40E_FLAG_DCB_CAPABLE
) &&
10747 (queues_left
< I40E_MAX_TRAFFIC_CLASS
)) {
10748 pf
->flags
&= ~(I40E_FLAG_DCB_CAPABLE
|
10749 I40E_FLAG_DCB_ENABLED
);
10750 dev_info(&pf
->pdev
->dev
, "not enough queues for DCB. DCB is disabled.\n");
10752 pf
->num_lan_qps
= max_t(int, pf
->rss_size_max
,
10753 num_online_cpus());
10754 pf
->num_lan_qps
= min_t(int, pf
->num_lan_qps
,
10755 pf
->hw
.func_caps
.num_tx_qp
);
10757 queues_left
-= pf
->num_lan_qps
;
10761 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
10762 if (I40E_DEFAULT_FCOE
<= queues_left
) {
10763 pf
->num_fcoe_qps
= I40E_DEFAULT_FCOE
;
10764 } else if (I40E_MINIMUM_FCOE
<= queues_left
) {
10765 pf
->num_fcoe_qps
= I40E_MINIMUM_FCOE
;
10767 pf
->num_fcoe_qps
= 0;
10768 pf
->flags
&= ~I40E_FLAG_FCOE_ENABLED
;
10769 dev_info(&pf
->pdev
->dev
, "not enough queues for FCoE. FCoE feature will be disabled\n");
10772 queues_left
-= pf
->num_fcoe_qps
;
10776 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
10777 if (queues_left
> 1) {
10778 queues_left
-= 1; /* save 1 queue for FD */
10780 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
10781 dev_info(&pf
->pdev
->dev
, "not enough queues for Flow Director. Flow Director feature is disabled\n");
10785 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
10786 pf
->num_vf_qps
&& pf
->num_req_vfs
&& queues_left
) {
10787 pf
->num_req_vfs
= min_t(int, pf
->num_req_vfs
,
10788 (queues_left
/ pf
->num_vf_qps
));
10789 queues_left
-= (pf
->num_req_vfs
* pf
->num_vf_qps
);
10792 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
10793 pf
->num_vmdq_vsis
&& pf
->num_vmdq_qps
&& queues_left
) {
10794 pf
->num_vmdq_vsis
= min_t(int, pf
->num_vmdq_vsis
,
10795 (queues_left
/ pf
->num_vmdq_qps
));
10796 queues_left
-= (pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
);
10799 pf
->queues_left
= queues_left
;
10800 dev_dbg(&pf
->pdev
->dev
,
10801 "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
10802 pf
->hw
.func_caps
.num_tx_qp
,
10803 !!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
),
10804 pf
->num_lan_qps
, pf
->alloc_rss_size
, pf
->num_req_vfs
,
10805 pf
->num_vf_qps
, pf
->num_vmdq_vsis
, pf
->num_vmdq_qps
,
10808 dev_dbg(&pf
->pdev
->dev
, "fcoe queues = %d\n", pf
->num_fcoe_qps
);
10813 * i40e_setup_pf_filter_control - Setup PF static filter control
10814 * @pf: PF to be setup
10816 * i40e_setup_pf_filter_control sets up a PF's initial filter control
10817 * settings. If PE/FCoE are enabled then it will also set the per PF
10818 * based filter sizes required for them. It also enables Flow director,
10819 * ethertype and macvlan type filter settings for the pf.
10821 * Returns 0 on success, negative on failure
10823 static int i40e_setup_pf_filter_control(struct i40e_pf
*pf
)
10825 struct i40e_filter_control_settings
*settings
= &pf
->filter_settings
;
10827 settings
->hash_lut_size
= I40E_HASH_LUT_SIZE_128
;
10829 /* Flow Director is enabled */
10830 if (pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
))
10831 settings
->enable_fdir
= true;
10833 /* Ethtype and MACVLAN filters enabled for PF */
10834 settings
->enable_ethtype
= true;
10835 settings
->enable_macvlan
= true;
10837 if (i40e_set_filter_control(&pf
->hw
, settings
))
10843 #define INFO_STRING_LEN 255
10844 #define REMAIN(__x) (INFO_STRING_LEN - (__x))
10845 static void i40e_print_features(struct i40e_pf
*pf
)
10847 struct i40e_hw
*hw
= &pf
->hw
;
10851 buf
= kmalloc(INFO_STRING_LEN
, GFP_KERNEL
);
10855 i
= snprintf(buf
, INFO_STRING_LEN
, "Features: PF-id[%d]", hw
->pf_id
);
10856 #ifdef CONFIG_PCI_IOV
10857 i
+= snprintf(&buf
[i
], REMAIN(i
), " VFs: %d", pf
->num_req_vfs
);
10859 i
+= snprintf(&buf
[i
], REMAIN(i
), " VSIs: %d QP: %d",
10860 pf
->hw
.func_caps
.num_vsis
,
10861 pf
->vsi
[pf
->lan_vsi
]->num_queue_pairs
);
10862 if (pf
->flags
& I40E_FLAG_RSS_ENABLED
)
10863 i
+= snprintf(&buf
[i
], REMAIN(i
), " RSS");
10864 if (pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
)
10865 i
+= snprintf(&buf
[i
], REMAIN(i
), " FD_ATR");
10866 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
10867 i
+= snprintf(&buf
[i
], REMAIN(i
), " FD_SB");
10868 i
+= snprintf(&buf
[i
], REMAIN(i
), " NTUPLE");
10870 if (pf
->flags
& I40E_FLAG_DCB_CAPABLE
)
10871 i
+= snprintf(&buf
[i
], REMAIN(i
), " DCB");
10872 i
+= snprintf(&buf
[i
], REMAIN(i
), " VxLAN");
10873 i
+= snprintf(&buf
[i
], REMAIN(i
), " Geneve");
10874 if (pf
->flags
& I40E_FLAG_PTP
)
10875 i
+= snprintf(&buf
[i
], REMAIN(i
), " PTP");
10877 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
)
10878 i
+= snprintf(&buf
[i
], REMAIN(i
), " FCOE");
10880 if (pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)
10881 i
+= snprintf(&buf
[i
], REMAIN(i
), " VEB");
10883 i
+= snprintf(&buf
[i
], REMAIN(i
), " VEPA");
10885 dev_info(&pf
->pdev
->dev
, "%s\n", buf
);
10887 WARN_ON(i
> INFO_STRING_LEN
);
10891 * i40e_get_platform_mac_addr - get platform-specific MAC address
10893 * @pdev: PCI device information struct
10894 * @pf: board private structure
10896 * Look up the MAC address in Open Firmware on systems that support it,
10897 * and use IDPROM on SPARC if no OF address is found. On return, the
10898 * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value
10899 * has been selected.
10901 static void i40e_get_platform_mac_addr(struct pci_dev
*pdev
, struct i40e_pf
*pf
)
10903 pf
->flags
&= ~I40E_FLAG_PF_MAC
;
10904 if (!eth_platform_get_mac_address(&pdev
->dev
, pf
->hw
.mac
.addr
))
10905 pf
->flags
|= I40E_FLAG_PF_MAC
;
10909 * i40e_probe - Device initialization routine
10910 * @pdev: PCI device information struct
10911 * @ent: entry in i40e_pci_tbl
10913 * i40e_probe initializes a PF identified by a pci_dev structure.
10914 * The OS initialization, configuring of the PF private structure,
10915 * and a hardware reset occur.
10917 * Returns 0 on success, negative on failure
10919 static int i40e_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
10921 struct i40e_aq_get_phy_abilities_resp abilities
;
10922 struct i40e_pf
*pf
;
10923 struct i40e_hw
*hw
;
10924 static u16 pfs_found
;
10932 err
= pci_enable_device_mem(pdev
);
10936 /* set up for high or low dma */
10937 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
10939 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
10941 dev_err(&pdev
->dev
,
10942 "DMA configuration failed: 0x%x\n", err
);
10947 /* set up pci connections */
10948 err
= pci_request_mem_regions(pdev
, i40e_driver_name
);
10950 dev_info(&pdev
->dev
,
10951 "pci_request_selected_regions failed %d\n", err
);
10955 pci_enable_pcie_error_reporting(pdev
);
10956 pci_set_master(pdev
);
10958 /* Now that we have a PCI connection, we need to do the
10959 * low level device setup. This is primarily setting up
10960 * the Admin Queue structures and then querying for the
10961 * device's current profile information.
10963 pf
= kzalloc(sizeof(*pf
), GFP_KERNEL
);
10970 set_bit(__I40E_DOWN
, &pf
->state
);
10975 pf
->ioremap_len
= min_t(int, pci_resource_len(pdev
, 0),
10976 I40E_MAX_CSR_SPACE
);
10978 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0), pf
->ioremap_len
);
10979 if (!hw
->hw_addr
) {
10981 dev_info(&pdev
->dev
, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
10982 (unsigned int)pci_resource_start(pdev
, 0),
10983 pf
->ioremap_len
, err
);
10986 hw
->vendor_id
= pdev
->vendor
;
10987 hw
->device_id
= pdev
->device
;
10988 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
10989 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
10990 hw
->subsystem_device_id
= pdev
->subsystem_device
;
10991 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
10992 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
10993 pf
->instance
= pfs_found
;
10995 /* set up the locks for the AQ, do this only once in probe
10996 * and destroy them only once in remove
10998 mutex_init(&hw
->aq
.asq_mutex
);
10999 mutex_init(&hw
->aq
.arq_mutex
);
11001 pf
->msg_enable
= netif_msg_init(debug
,
11006 pf
->hw
.debug_mask
= debug
;
11008 /* do a special CORER for clearing PXE mode once at init */
11009 if (hw
->revision_id
== 0 &&
11010 (rd32(hw
, I40E_GLLAN_RCTL_0
) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK
)) {
11011 wr32(hw
, I40E_GLGEN_RTRIG
, I40E_GLGEN_RTRIG_CORER_MASK
);
11016 i40e_clear_pxe_mode(hw
);
11019 /* Reset here to make sure all is clean and to define PF 'n' */
11021 err
= i40e_pf_reset(hw
);
11023 dev_info(&pdev
->dev
, "Initial pf_reset failed: %d\n", err
);
11028 hw
->aq
.num_arq_entries
= I40E_AQ_LEN
;
11029 hw
->aq
.num_asq_entries
= I40E_AQ_LEN
;
11030 hw
->aq
.arq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
11031 hw
->aq
.asq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
11032 pf
->adminq_work_limit
= I40E_AQ_WORK_LIMIT
;
11034 snprintf(pf
->int_name
, sizeof(pf
->int_name
) - 1,
11036 dev_driver_string(&pf
->pdev
->dev
), dev_name(&pdev
->dev
));
11038 err
= i40e_init_shared_code(hw
);
11040 dev_warn(&pdev
->dev
, "unidentified MAC or BLANK NVM: %d\n",
11045 /* set up a default setting for link flow control */
11046 pf
->hw
.fc
.requested_mode
= I40E_FC_NONE
;
11048 err
= i40e_init_adminq(hw
);
11050 if (err
== I40E_ERR_FIRMWARE_API_VERSION
)
11051 dev_info(&pdev
->dev
,
11052 "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");
11054 dev_info(&pdev
->dev
,
11055 "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
11060 /* provide nvm, fw, api versions */
11061 dev_info(&pdev
->dev
, "fw %d.%d.%05d api %d.%d nvm %s\n",
11062 hw
->aq
.fw_maj_ver
, hw
->aq
.fw_min_ver
, hw
->aq
.fw_build
,
11063 hw
->aq
.api_maj_ver
, hw
->aq
.api_min_ver
,
11064 i40e_nvm_version_str(hw
));
11066 if (hw
->aq
.api_maj_ver
== I40E_FW_API_VERSION_MAJOR
&&
11067 hw
->aq
.api_min_ver
> I40E_FW_API_VERSION_MINOR
)
11068 dev_info(&pdev
->dev
,
11069 "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");
11070 else if (hw
->aq
.api_maj_ver
< I40E_FW_API_VERSION_MAJOR
||
11071 hw
->aq
.api_min_ver
< (I40E_FW_API_VERSION_MINOR
- 1))
11072 dev_info(&pdev
->dev
,
11073 "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
11075 i40e_verify_eeprom(pf
);
11077 /* Rev 0 hardware was never productized */
11078 if (hw
->revision_id
< 1)
11079 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");
11081 i40e_clear_pxe_mode(hw
);
11082 err
= i40e_get_capabilities(pf
);
11084 goto err_adminq_setup
;
11086 err
= i40e_sw_init(pf
);
11088 dev_info(&pdev
->dev
, "sw_init failed: %d\n", err
);
11092 err
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
11093 hw
->func_caps
.num_rx_qp
,
11094 pf
->fcoe_hmc_cntx_num
, pf
->fcoe_hmc_filt_num
);
11096 dev_info(&pdev
->dev
, "init_lan_hmc failed: %d\n", err
);
11097 goto err_init_lan_hmc
;
11100 err
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
11102 dev_info(&pdev
->dev
, "configure_lan_hmc failed: %d\n", err
);
11104 goto err_configure_lan_hmc
;
11107 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
11108 * Ignore error return codes because if it was already disabled via
11109 * hardware settings this will fail
11111 if (pf
->flags
& I40E_FLAG_STOP_FW_LLDP
) {
11112 dev_info(&pdev
->dev
, "Stopping firmware LLDP agent.\n");
11113 i40e_aq_stop_lldp(hw
, true, NULL
);
11116 i40e_get_mac_addr(hw
, hw
->mac
.addr
);
11117 /* allow a platform config to override the HW addr */
11118 i40e_get_platform_mac_addr(pdev
, pf
);
11119 if (!is_valid_ether_addr(hw
->mac
.addr
)) {
11120 dev_info(&pdev
->dev
, "invalid MAC address %pM\n", hw
->mac
.addr
);
11124 dev_info(&pdev
->dev
, "MAC address: %pM\n", hw
->mac
.addr
);
11125 ether_addr_copy(hw
->mac
.perm_addr
, hw
->mac
.addr
);
11126 i40e_get_port_mac_addr(hw
, hw
->mac
.port_addr
);
11127 if (is_valid_ether_addr(hw
->mac
.port_addr
))
11128 pf
->flags
|= I40E_FLAG_PORT_ID_VALID
;
11130 err
= i40e_get_san_mac_addr(hw
, hw
->mac
.san_addr
);
11132 dev_info(&pdev
->dev
,
11133 "(non-fatal) SAN MAC retrieval failed: %d\n", err
);
11134 if (!is_valid_ether_addr(hw
->mac
.san_addr
)) {
11135 dev_warn(&pdev
->dev
, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
11137 ether_addr_copy(hw
->mac
.san_addr
, hw
->mac
.addr
);
11139 dev_info(&pf
->pdev
->dev
, "SAN MAC: %pM\n", hw
->mac
.san_addr
);
11140 #endif /* I40E_FCOE */
11142 pci_set_drvdata(pdev
, pf
);
11143 pci_save_state(pdev
);
11144 #ifdef CONFIG_I40E_DCB
11145 err
= i40e_init_pf_dcb(pf
);
11147 dev_info(&pdev
->dev
, "DCB init failed %d, disabled\n", err
);
11148 pf
->flags
&= ~(I40E_FLAG_DCB_CAPABLE
| I40E_FLAG_DCB_ENABLED
);
11149 /* Continue without DCB enabled */
11151 #endif /* CONFIG_I40E_DCB */
11153 /* set up periodic task facility */
11154 setup_timer(&pf
->service_timer
, i40e_service_timer
, (unsigned long)pf
);
11155 pf
->service_timer_period
= HZ
;
11157 INIT_WORK(&pf
->service_task
, i40e_service_task
);
11158 clear_bit(__I40E_SERVICE_SCHED
, &pf
->state
);
11159 pf
->flags
|= I40E_FLAG_NEED_LINK_UPDATE
;
11161 /* NVM bit on means WoL disabled for the port */
11162 i40e_read_nvm_word(hw
, I40E_SR_NVM_WAKE_ON_LAN
, &wol_nvm_bits
);
11163 if (BIT (hw
->port
) & wol_nvm_bits
|| hw
->partition_id
!= 1)
11164 pf
->wol_en
= false;
11167 device_set_wakeup_enable(&pf
->pdev
->dev
, pf
->wol_en
);
11169 /* set up the main switch operations */
11170 i40e_determine_queue_usage(pf
);
11171 err
= i40e_init_interrupt_scheme(pf
);
11173 goto err_switch_setup
;
11175 /* The number of VSIs reported by the FW is the minimum guaranteed
11176 * to us; HW supports far more and we share the remaining pool with
11177 * the other PFs. We allocate space for more than the guarantee with
11178 * the understanding that we might not get them all later.
11180 if (pf
->hw
.func_caps
.num_vsis
< I40E_MIN_VSI_ALLOC
)
11181 pf
->num_alloc_vsi
= I40E_MIN_VSI_ALLOC
;
11183 pf
->num_alloc_vsi
= pf
->hw
.func_caps
.num_vsis
;
11185 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
11186 pf
->vsi
= kcalloc(pf
->num_alloc_vsi
, sizeof(struct i40e_vsi
*),
11190 goto err_switch_setup
;
11193 #ifdef CONFIG_PCI_IOV
11194 /* prep for VF support */
11195 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
11196 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
11197 !test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
11198 if (pci_num_vf(pdev
))
11199 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
11202 err
= i40e_setup_pf_switch(pf
, false);
11204 dev_info(&pdev
->dev
, "setup_pf_switch failed: %d\n", err
);
11208 /* Make sure flow control is set according to current settings */
11209 err
= i40e_set_fc(hw
, &set_fc_aq_fail
, true);
11210 if (set_fc_aq_fail
& I40E_SET_FC_AQ_FAIL_GET
)
11211 dev_dbg(&pf
->pdev
->dev
,
11212 "Set fc with err %s aq_err %s on get_phy_cap\n",
11213 i40e_stat_str(hw
, err
),
11214 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
11215 if (set_fc_aq_fail
& I40E_SET_FC_AQ_FAIL_SET
)
11216 dev_dbg(&pf
->pdev
->dev
,
11217 "Set fc with err %s aq_err %s on set_phy_config\n",
11218 i40e_stat_str(hw
, err
),
11219 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
11220 if (set_fc_aq_fail
& I40E_SET_FC_AQ_FAIL_UPDATE
)
11221 dev_dbg(&pf
->pdev
->dev
,
11222 "Set fc with err %s aq_err %s on get_link_info\n",
11223 i40e_stat_str(hw
, err
),
11224 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
11226 /* if FDIR VSI was set up, start it now */
11227 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
11228 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
11229 i40e_vsi_open(pf
->vsi
[i
]);
11234 /* The driver only wants link up/down and module qualification
11235 * reports from firmware. Note the negative logic.
11237 err
= i40e_aq_set_phy_int_mask(&pf
->hw
,
11238 ~(I40E_AQ_EVENT_LINK_UPDOWN
|
11239 I40E_AQ_EVENT_MEDIA_NA
|
11240 I40E_AQ_EVENT_MODULE_QUAL_FAIL
), NULL
);
11242 dev_info(&pf
->pdev
->dev
, "set phy mask fail, err %s aq_err %s\n",
11243 i40e_stat_str(&pf
->hw
, err
),
11244 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
11246 /* Reconfigure hardware for allowing smaller MSS in the case
11247 * of TSO, so that we avoid the MDD being fired and causing
11248 * a reset in the case of small MSS+TSO.
11250 val
= rd32(hw
, I40E_REG_MSS
);
11251 if ((val
& I40E_REG_MSS_MIN_MASK
) > I40E_64BYTE_MSS
) {
11252 val
&= ~I40E_REG_MSS_MIN_MASK
;
11253 val
|= I40E_64BYTE_MSS
;
11254 wr32(hw
, I40E_REG_MSS
, val
);
11257 if (pf
->flags
& I40E_FLAG_RESTART_AUTONEG
) {
11259 err
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
11261 dev_info(&pf
->pdev
->dev
, "link restart failed, err %s aq_err %s\n",
11262 i40e_stat_str(&pf
->hw
, err
),
11263 i40e_aq_str(&pf
->hw
,
11264 pf
->hw
.aq
.asq_last_status
));
11266 /* The main driver is (mostly) up and happy. We need to set this state
11267 * before setting up the misc vector or we get a race and the vector
11268 * ends up disabled forever.
11270 clear_bit(__I40E_DOWN
, &pf
->state
);
11272 /* In case of MSIX we are going to setup the misc vector right here
11273 * to handle admin queue events etc. In case of legacy and MSI
11274 * the misc functionality and queue processing is combined in
11275 * the same vector and that gets setup at open.
11277 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
11278 err
= i40e_setup_misc_vector(pf
);
11280 dev_info(&pdev
->dev
,
11281 "setup of misc vector failed: %d\n", err
);
11286 #ifdef CONFIG_PCI_IOV
11287 /* prep for VF support */
11288 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
11289 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
11290 !test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
11291 /* disable link interrupts for VFs */
11292 val
= rd32(hw
, I40E_PFGEN_PORTMDIO_NUM
);
11293 val
&= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK
;
11294 wr32(hw
, I40E_PFGEN_PORTMDIO_NUM
, val
);
11297 if (pci_num_vf(pdev
)) {
11298 dev_info(&pdev
->dev
,
11299 "Active VFs found, allocating resources.\n");
11300 err
= i40e_alloc_vfs(pf
, pci_num_vf(pdev
));
11302 dev_info(&pdev
->dev
,
11303 "Error %d allocating resources for existing VFs\n",
11307 #endif /* CONFIG_PCI_IOV */
11309 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
) {
11310 pf
->iwarp_base_vector
= i40e_get_lump(pf
, pf
->irq_pile
,
11311 pf
->num_iwarp_msix
,
11312 I40E_IWARP_IRQ_PILE_ID
);
11313 if (pf
->iwarp_base_vector
< 0) {
11314 dev_info(&pdev
->dev
,
11315 "failed to get tracking for %d vectors for IWARP err=%d\n",
11316 pf
->num_iwarp_msix
, pf
->iwarp_base_vector
);
11317 pf
->flags
&= ~I40E_FLAG_IWARP_ENABLED
;
11321 i40e_dbg_pf_init(pf
);
11323 /* tell the firmware that we're starting */
11324 i40e_send_version(pf
);
11326 /* since everything's happy, start the service_task timer */
11327 mod_timer(&pf
->service_timer
,
11328 round_jiffies(jiffies
+ pf
->service_timer_period
));
11330 /* add this PF to client device list and launch a client service task */
11331 err
= i40e_lan_add_device(pf
);
11333 dev_info(&pdev
->dev
, "Failed to add PF to client API service list: %d\n",
11337 /* create FCoE interface */
11338 i40e_fcoe_vsi_setup(pf
);
11341 #define PCI_SPEED_SIZE 8
11342 #define PCI_WIDTH_SIZE 8
11343 /* Devices on the IOSF bus do not have this information
11344 * and will report PCI Gen 1 x 1 by default so don't bother
11347 if (!(pf
->flags
& I40E_FLAG_NO_PCI_LINK_CHECK
)) {
11348 char speed
[PCI_SPEED_SIZE
] = "Unknown";
11349 char width
[PCI_WIDTH_SIZE
] = "Unknown";
11351 /* Get the negotiated link width and speed from PCI config
11354 pcie_capability_read_word(pf
->pdev
, PCI_EXP_LNKSTA
,
11357 i40e_set_pci_config_data(hw
, link_status
);
11359 switch (hw
->bus
.speed
) {
11360 case i40e_bus_speed_8000
:
11361 strncpy(speed
, "8.0", PCI_SPEED_SIZE
); break;
11362 case i40e_bus_speed_5000
:
11363 strncpy(speed
, "5.0", PCI_SPEED_SIZE
); break;
11364 case i40e_bus_speed_2500
:
11365 strncpy(speed
, "2.5", PCI_SPEED_SIZE
); break;
11369 switch (hw
->bus
.width
) {
11370 case i40e_bus_width_pcie_x8
:
11371 strncpy(width
, "8", PCI_WIDTH_SIZE
); break;
11372 case i40e_bus_width_pcie_x4
:
11373 strncpy(width
, "4", PCI_WIDTH_SIZE
); break;
11374 case i40e_bus_width_pcie_x2
:
11375 strncpy(width
, "2", PCI_WIDTH_SIZE
); break;
11376 case i40e_bus_width_pcie_x1
:
11377 strncpy(width
, "1", PCI_WIDTH_SIZE
); break;
11382 dev_info(&pdev
->dev
, "PCI-Express: Speed %sGT/s Width x%s\n",
11385 if (hw
->bus
.width
< i40e_bus_width_pcie_x8
||
11386 hw
->bus
.speed
< i40e_bus_speed_8000
) {
11387 dev_warn(&pdev
->dev
, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
11388 dev_warn(&pdev
->dev
, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
11392 /* get the requested speeds from the fw */
11393 err
= i40e_aq_get_phy_capabilities(hw
, false, false, &abilities
, NULL
);
11395 dev_dbg(&pf
->pdev
->dev
, "get requested speeds ret = %s last_status = %s\n",
11396 i40e_stat_str(&pf
->hw
, err
),
11397 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
11398 pf
->hw
.phy
.link_info
.requested_speeds
= abilities
.link_speed
;
11400 /* get the supported phy types from the fw */
11401 err
= i40e_aq_get_phy_capabilities(hw
, false, true, &abilities
, NULL
);
11403 dev_dbg(&pf
->pdev
->dev
, "get supported phy types ret = %s last_status = %s\n",
11404 i40e_stat_str(&pf
->hw
, err
),
11405 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
11407 /* Add a filter to drop all Flow control frames from any VSI from being
11408 * transmitted. By doing so we stop a malicious VF from sending out
11409 * PAUSE or PFC frames and potentially controlling traffic for other
11411 * The FW can still send Flow control frames if enabled.
11413 i40e_add_filter_to_drop_tx_flow_control_frames(&pf
->hw
,
11414 pf
->main_vsi_seid
);
11416 if ((pf
->hw
.device_id
== I40E_DEV_ID_10G_BASE_T
) ||
11417 (pf
->hw
.device_id
== I40E_DEV_ID_10G_BASE_T4
))
11418 pf
->flags
|= I40E_FLAG_PHY_CONTROLS_LEDS
;
11419 if (pf
->hw
.device_id
== I40E_DEV_ID_SFP_I_X722
)
11420 pf
->flags
|= I40E_FLAG_HAVE_CRT_RETIMER
;
11421 /* print a string summarizing features */
11422 i40e_print_features(pf
);
11426 /* Unwind what we've done if something failed in the setup */
11428 set_bit(__I40E_DOWN
, &pf
->state
);
11429 i40e_clear_interrupt_scheme(pf
);
11432 i40e_reset_interrupt_capability(pf
);
11433 del_timer_sync(&pf
->service_timer
);
11435 err_configure_lan_hmc
:
11436 (void)i40e_shutdown_lan_hmc(hw
);
11438 kfree(pf
->qp_pile
);
11442 iounmap(hw
->hw_addr
);
11446 pci_disable_pcie_error_reporting(pdev
);
11447 pci_release_mem_regions(pdev
);
11450 pci_disable_device(pdev
);
11455 * i40e_remove - Device removal routine
11456 * @pdev: PCI device information struct
11458 * i40e_remove is called by the PCI subsystem to alert the driver
11459 * that is should release a PCI device. This could be caused by a
11460 * Hot-Plug event, or because the driver is going to be removed from
11463 static void i40e_remove(struct pci_dev
*pdev
)
11465 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
11466 struct i40e_hw
*hw
= &pf
->hw
;
11467 i40e_status ret_code
;
11470 i40e_dbg_pf_exit(pf
);
11474 /* Disable RSS in hw */
11475 i40e_write_rx_ctl(hw
, I40E_PFQF_HENA(0), 0);
11476 i40e_write_rx_ctl(hw
, I40E_PFQF_HENA(1), 0);
11478 /* no more scheduling of any task */
11479 set_bit(__I40E_SUSPENDED
, &pf
->state
);
11480 set_bit(__I40E_DOWN
, &pf
->state
);
11481 if (pf
->service_timer
.data
)
11482 del_timer_sync(&pf
->service_timer
);
11483 if (pf
->service_task
.func
)
11484 cancel_work_sync(&pf
->service_task
);
11486 if (pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) {
11488 pf
->flags
&= ~I40E_FLAG_SRIOV_ENABLED
;
11491 i40e_fdir_teardown(pf
);
11493 /* If there is a switch structure or any orphans, remove them.
11494 * This will leave only the PF's VSI remaining.
11496 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
11500 if (pf
->veb
[i
]->uplink_seid
== pf
->mac_seid
||
11501 pf
->veb
[i
]->uplink_seid
== 0)
11502 i40e_switch_branch_release(pf
->veb
[i
]);
11505 /* Now we can shutdown the PF's VSI, just before we kill
11508 if (pf
->vsi
[pf
->lan_vsi
])
11509 i40e_vsi_release(pf
->vsi
[pf
->lan_vsi
]);
11511 /* remove attached clients */
11512 ret_code
= i40e_lan_del_device(pf
);
11514 dev_warn(&pdev
->dev
, "Failed to delete client device: %d\n",
11518 /* shutdown and destroy the HMC */
11519 if (hw
->hmc
.hmc_obj
) {
11520 ret_code
= i40e_shutdown_lan_hmc(hw
);
11522 dev_warn(&pdev
->dev
,
11523 "Failed to destroy the HMC resources: %d\n",
11527 /* shutdown the adminq */
11528 i40e_shutdown_adminq(hw
);
11530 /* destroy the locks only once, here */
11531 mutex_destroy(&hw
->aq
.arq_mutex
);
11532 mutex_destroy(&hw
->aq
.asq_mutex
);
11534 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
11535 i40e_clear_interrupt_scheme(pf
);
11536 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
11538 i40e_vsi_clear_rings(pf
->vsi
[i
]);
11539 i40e_vsi_clear(pf
->vsi
[i
]);
11544 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
11549 kfree(pf
->qp_pile
);
11552 iounmap(hw
->hw_addr
);
11554 pci_release_mem_regions(pdev
);
11556 pci_disable_pcie_error_reporting(pdev
);
11557 pci_disable_device(pdev
);
11561 * i40e_pci_error_detected - warning that something funky happened in PCI land
11562 * @pdev: PCI device information struct
11564 * Called to warn that something happened and the error handling steps
11565 * are in progress. Allows the driver to quiesce things, be ready for
11568 static pci_ers_result_t
i40e_pci_error_detected(struct pci_dev
*pdev
,
11569 enum pci_channel_state error
)
11571 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
11573 dev_info(&pdev
->dev
, "%s: error %d\n", __func__
, error
);
11576 dev_info(&pdev
->dev
,
11577 "Cannot recover - error happened during device probe\n");
11578 return PCI_ERS_RESULT_DISCONNECT
;
11581 /* shutdown all operations */
11582 if (!test_bit(__I40E_SUSPENDED
, &pf
->state
)) {
11584 i40e_prep_for_reset(pf
);
11588 /* Request a slot reset */
11589 return PCI_ERS_RESULT_NEED_RESET
;
11593 * i40e_pci_error_slot_reset - a PCI slot reset just happened
11594 * @pdev: PCI device information struct
11596 * Called to find if the driver can work with the device now that
11597 * the pci slot has been reset. If a basic connection seems good
11598 * (registers are readable and have sane content) then return a
11599 * happy little PCI_ERS_RESULT_xxx.
11601 static pci_ers_result_t
i40e_pci_error_slot_reset(struct pci_dev
*pdev
)
11603 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
11604 pci_ers_result_t result
;
11608 dev_dbg(&pdev
->dev
, "%s\n", __func__
);
11609 if (pci_enable_device_mem(pdev
)) {
11610 dev_info(&pdev
->dev
,
11611 "Cannot re-enable PCI device after reset.\n");
11612 result
= PCI_ERS_RESULT_DISCONNECT
;
11614 pci_set_master(pdev
);
11615 pci_restore_state(pdev
);
11616 pci_save_state(pdev
);
11617 pci_wake_from_d3(pdev
, false);
11619 reg
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
11621 result
= PCI_ERS_RESULT_RECOVERED
;
11623 result
= PCI_ERS_RESULT_DISCONNECT
;
11626 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
11628 dev_info(&pdev
->dev
,
11629 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
11631 /* non-fatal, continue */
11638 * i40e_pci_error_resume - restart operations after PCI error recovery
11639 * @pdev: PCI device information struct
11641 * Called to allow the driver to bring things back up after PCI error
11642 * and/or reset recovery has finished.
11644 static void i40e_pci_error_resume(struct pci_dev
*pdev
)
11646 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
11648 dev_dbg(&pdev
->dev
, "%s\n", __func__
);
11649 if (test_bit(__I40E_SUSPENDED
, &pf
->state
))
11653 i40e_handle_reset_warning(pf
);
11658 * i40e_shutdown - PCI callback for shutting down
11659 * @pdev: PCI device information struct
11661 static void i40e_shutdown(struct pci_dev
*pdev
)
11663 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
11664 struct i40e_hw
*hw
= &pf
->hw
;
11666 set_bit(__I40E_SUSPENDED
, &pf
->state
);
11667 set_bit(__I40E_DOWN
, &pf
->state
);
11669 i40e_prep_for_reset(pf
);
11672 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
11673 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
11675 del_timer_sync(&pf
->service_timer
);
11676 cancel_work_sync(&pf
->service_task
);
11677 i40e_fdir_teardown(pf
);
11680 i40e_prep_for_reset(pf
);
11683 wr32(hw
, I40E_PFPM_APM
,
11684 (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
11685 wr32(hw
, I40E_PFPM_WUFC
,
11686 (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
11688 i40e_clear_interrupt_scheme(pf
);
11690 if (system_state
== SYSTEM_POWER_OFF
) {
11691 pci_wake_from_d3(pdev
, pf
->wol_en
);
11692 pci_set_power_state(pdev
, PCI_D3hot
);
11698 * i40e_suspend - PCI callback for moving to D3
11699 * @pdev: PCI device information struct
11701 static int i40e_suspend(struct pci_dev
*pdev
, pm_message_t state
)
11703 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
11704 struct i40e_hw
*hw
= &pf
->hw
;
11707 set_bit(__I40E_SUSPENDED
, &pf
->state
);
11708 set_bit(__I40E_DOWN
, &pf
->state
);
11711 i40e_prep_for_reset(pf
);
11714 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
11715 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
11717 i40e_stop_misc_vector(pf
);
11719 retval
= pci_save_state(pdev
);
11723 pci_wake_from_d3(pdev
, pf
->wol_en
);
11724 pci_set_power_state(pdev
, PCI_D3hot
);
11730 * i40e_resume - PCI callback for waking up from D3
11731 * @pdev: PCI device information struct
11733 static int i40e_resume(struct pci_dev
*pdev
)
11735 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
11738 pci_set_power_state(pdev
, PCI_D0
);
11739 pci_restore_state(pdev
);
11740 /* pci_restore_state() clears dev->state_saves, so
11741 * call pci_save_state() again to restore it.
11743 pci_save_state(pdev
);
11745 err
= pci_enable_device_mem(pdev
);
11747 dev_err(&pdev
->dev
, "Cannot enable PCI device from suspend\n");
11750 pci_set_master(pdev
);
11752 /* no wakeup events while running */
11753 pci_wake_from_d3(pdev
, false);
11755 /* handling the reset will rebuild the device state */
11756 if (test_and_clear_bit(__I40E_SUSPENDED
, &pf
->state
)) {
11757 clear_bit(__I40E_DOWN
, &pf
->state
);
11759 i40e_reset_and_rebuild(pf
, false);
11767 static const struct pci_error_handlers i40e_err_handler
= {
11768 .error_detected
= i40e_pci_error_detected
,
11769 .slot_reset
= i40e_pci_error_slot_reset
,
11770 .resume
= i40e_pci_error_resume
,
11773 static struct pci_driver i40e_driver
= {
11774 .name
= i40e_driver_name
,
11775 .id_table
= i40e_pci_tbl
,
11776 .probe
= i40e_probe
,
11777 .remove
= i40e_remove
,
11779 .suspend
= i40e_suspend
,
11780 .resume
= i40e_resume
,
11782 .shutdown
= i40e_shutdown
,
11783 .err_handler
= &i40e_err_handler
,
11784 .sriov_configure
= i40e_pci_sriov_configure
,
11788 * i40e_init_module - Driver registration routine
11790 * i40e_init_module is the first routine called when the driver is
11791 * loaded. All it does is register with the PCI subsystem.
11793 static int __init
i40e_init_module(void)
11795 pr_info("%s: %s - version %s\n", i40e_driver_name
,
11796 i40e_driver_string
, i40e_driver_version_str
);
11797 pr_info("%s: %s\n", i40e_driver_name
, i40e_copyright
);
11799 /* we will see if single thread per module is enough for now,
11800 * it can't be any worse than using the system workqueue which
11801 * was already single threaded
11803 i40e_wq
= alloc_workqueue("%s", WQ_UNBOUND
| WQ_MEM_RECLAIM
, 1,
11806 pr_err("%s: Failed to create workqueue\n", i40e_driver_name
);
11811 return pci_register_driver(&i40e_driver
);
11813 module_init(i40e_init_module
);
11816 * i40e_exit_module - Driver exit cleanup routine
11818 * i40e_exit_module is called just before the driver is removed
11821 static void __exit
i40e_exit_module(void)
11823 pci_unregister_driver(&i40e_driver
);
11824 destroy_workqueue(i40e_wq
);
11827 module_exit(i40e_exit_module
);