1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2015 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 ******************************************************************************/
29 #include "i40e_diag.h"
30 #ifdef CONFIG_I40E_VXLAN
31 #include <net/vxlan.h>
34 const char i40e_driver_name
[] = "i40e";
35 static const char i40e_driver_string
[] =
36 "Intel(R) Ethernet Connection XL710 Network Driver";
40 #define DRV_VERSION_MAJOR 1
41 #define DRV_VERSION_MINOR 3
42 #define DRV_VERSION_BUILD 46
43 #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
44 __stringify(DRV_VERSION_MINOR) "." \
45 __stringify(DRV_VERSION_BUILD) DRV_KERN
46 const char i40e_driver_version_str
[] = DRV_VERSION
;
47 static const char i40e_copyright
[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
49 /* a bit of forward declarations */
50 static void i40e_vsi_reinit_locked(struct i40e_vsi
*vsi
);
51 static void i40e_handle_reset_warning(struct i40e_pf
*pf
);
52 static int i40e_add_vsi(struct i40e_vsi
*vsi
);
53 static int i40e_add_veb(struct i40e_veb
*veb
, struct i40e_vsi
*vsi
);
54 static int i40e_setup_pf_switch(struct i40e_pf
*pf
, bool reinit
);
55 static int i40e_setup_misc_vector(struct i40e_pf
*pf
);
56 static void i40e_determine_queue_usage(struct i40e_pf
*pf
);
57 static int i40e_setup_pf_filter_control(struct i40e_pf
*pf
);
58 static void i40e_fdir_sb_setup(struct i40e_pf
*pf
);
59 static int i40e_veb_get_bw_info(struct i40e_veb
*veb
);
61 /* i40e_pci_tbl - PCI Device ID Table
63 * Last entry must be all 0s
65 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
66 * Class, Class Mask, private data (not used) }
68 static const struct pci_device_id i40e_pci_tbl
[] = {
69 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_SFP_XL710
), 0},
70 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QEMU
), 0},
71 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_A
), 0},
72 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_B
), 0},
73 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_C
), 0},
74 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_A
), 0},
75 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_B
), 0},
76 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_C
), 0},
77 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T
), 0},
78 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T4
), 0},
79 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_20G_KR2
), 0},
80 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_SFP_X722
), 0},
81 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_1G_BASE_T_X722
), 0},
82 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T_X722
), 0},
83 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_20G_KR2
), 0},
84 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_20G_KR2_A
), 0},
85 /* required last entry */
88 MODULE_DEVICE_TABLE(pci
, i40e_pci_tbl
);
90 #define I40E_MAX_VF_COUNT 128
91 static int debug
= -1;
92 module_param(debug
, int, 0);
93 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
95 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
96 MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
97 MODULE_LICENSE("GPL");
98 MODULE_VERSION(DRV_VERSION
);
101 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
102 * @hw: pointer to the HW structure
103 * @mem: ptr to mem struct to fill out
104 * @size: size of memory requested
105 * @alignment: what to align the allocation to
107 int i40e_allocate_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
,
108 u64 size
, u32 alignment
)
110 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
112 mem
->size
= ALIGN(size
, alignment
);
113 mem
->va
= dma_zalloc_coherent(&pf
->pdev
->dev
, mem
->size
,
114 &mem
->pa
, GFP_KERNEL
);
122 * i40e_free_dma_mem_d - OS specific memory free for shared code
123 * @hw: pointer to the HW structure
124 * @mem: ptr to mem struct to free
126 int i40e_free_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
)
128 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
130 dma_free_coherent(&pf
->pdev
->dev
, mem
->size
, mem
->va
, mem
->pa
);
139 * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
140 * @hw: pointer to the HW structure
141 * @mem: ptr to mem struct to fill out
142 * @size: size of memory requested
144 int i40e_allocate_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
,
148 mem
->va
= kzalloc(size
, GFP_KERNEL
);
157 * i40e_free_virt_mem_d - OS specific memory free for shared code
158 * @hw: pointer to the HW structure
159 * @mem: ptr to mem struct to free
161 int i40e_free_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
)
163 /* it's ok to kfree a NULL pointer */
172 * i40e_get_lump - find a lump of free generic resource
173 * @pf: board private structure
174 * @pile: the pile of resource to search
175 * @needed: the number of items needed
176 * @id: an owner id to stick on the items assigned
178 * Returns the base item index of the lump, or negative for error
180 * The search_hint trick and lack of advanced fit-finding only work
181 * because we're highly likely to have all the same size lump requests.
182 * Linear search time and any fragmentation should be minimal.
184 static int i40e_get_lump(struct i40e_pf
*pf
, struct i40e_lump_tracking
*pile
,
190 if (!pile
|| needed
== 0 || id
>= I40E_PILE_VALID_BIT
) {
191 dev_info(&pf
->pdev
->dev
,
192 "param err: pile=%p needed=%d id=0x%04x\n",
197 /* start the linear search with an imperfect hint */
198 i
= pile
->search_hint
;
199 while (i
< pile
->num_entries
) {
200 /* skip already allocated entries */
201 if (pile
->list
[i
] & I40E_PILE_VALID_BIT
) {
206 /* do we have enough in this lump? */
207 for (j
= 0; (j
< needed
) && ((i
+j
) < pile
->num_entries
); j
++) {
208 if (pile
->list
[i
+j
] & I40E_PILE_VALID_BIT
)
213 /* there was enough, so assign it to the requestor */
214 for (j
= 0; j
< needed
; j
++)
215 pile
->list
[i
+j
] = id
| I40E_PILE_VALID_BIT
;
217 pile
->search_hint
= i
+ j
;
221 /* not enough, so skip over it and continue looking */
229 * i40e_put_lump - return a lump of generic resource
230 * @pile: the pile of resource to search
231 * @index: the base item index
232 * @id: the owner id of the items assigned
234 * Returns the count of items in the lump
236 static int i40e_put_lump(struct i40e_lump_tracking
*pile
, u16 index
, u16 id
)
238 int valid_id
= (id
| I40E_PILE_VALID_BIT
);
242 if (!pile
|| index
>= pile
->num_entries
)
246 i
< pile
->num_entries
&& pile
->list
[i
] == valid_id
;
252 if (count
&& index
< pile
->search_hint
)
253 pile
->search_hint
= index
;
259 * i40e_find_vsi_from_id - searches for the vsi with the given id
260 * @pf - the pf structure to search for the vsi
261 * @id - id of the vsi it is searching for
263 struct i40e_vsi
*i40e_find_vsi_from_id(struct i40e_pf
*pf
, u16 id
)
267 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
268 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->id
== id
))
275 * i40e_service_event_schedule - Schedule the service task to wake up
276 * @pf: board private structure
278 * If not already scheduled, this puts the task into the work queue
280 static void i40e_service_event_schedule(struct i40e_pf
*pf
)
282 if (!test_bit(__I40E_DOWN
, &pf
->state
) &&
283 !test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) &&
284 !test_and_set_bit(__I40E_SERVICE_SCHED
, &pf
->state
))
285 schedule_work(&pf
->service_task
);
289 * i40e_tx_timeout - Respond to a Tx Hang
290 * @netdev: network interface device structure
292 * If any port has noticed a Tx timeout, it is likely that the whole
293 * device is munged, not just the one netdev port, so go for the full
297 void i40e_tx_timeout(struct net_device
*netdev
)
299 static void i40e_tx_timeout(struct net_device
*netdev
)
302 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
303 struct i40e_vsi
*vsi
= np
->vsi
;
304 struct i40e_pf
*pf
= vsi
->back
;
305 struct i40e_ring
*tx_ring
= NULL
;
306 unsigned int i
, hung_queue
= 0;
309 pf
->tx_timeout_count
++;
311 /* find the stopped queue the same way the stack does */
312 for (i
= 0; i
< netdev
->num_tx_queues
; i
++) {
313 struct netdev_queue
*q
;
314 unsigned long trans_start
;
316 q
= netdev_get_tx_queue(netdev
, i
);
317 trans_start
= q
->trans_start
? : netdev
->trans_start
;
318 if (netif_xmit_stopped(q
) &&
320 (trans_start
+ netdev
->watchdog_timeo
))) {
326 if (i
== netdev
->num_tx_queues
) {
327 netdev_info(netdev
, "tx_timeout: no netdev hung queue found\n");
329 /* now that we have an index, find the tx_ring struct */
330 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
331 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
) {
333 vsi
->tx_rings
[i
]->queue_index
) {
334 tx_ring
= vsi
->tx_rings
[i
];
341 if (time_after(jiffies
, (pf
->tx_timeout_last_recovery
+ HZ
*20)))
342 pf
->tx_timeout_recovery_level
= 1; /* reset after some time */
343 else if (time_before(jiffies
,
344 (pf
->tx_timeout_last_recovery
+ netdev
->watchdog_timeo
)))
345 return; /* don't do any new action before the next timeout */
348 head
= i40e_get_head(tx_ring
);
349 /* Read interrupt register */
350 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
352 I40E_PFINT_DYN_CTLN(tx_ring
->q_vector
->v_idx
+
353 tx_ring
->vsi
->base_vector
- 1));
355 val
= rd32(&pf
->hw
, I40E_PFINT_DYN_CTL0
);
357 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",
358 vsi
->seid
, hung_queue
, tx_ring
->next_to_clean
,
359 head
, tx_ring
->next_to_use
,
360 readl(tx_ring
->tail
), val
);
363 pf
->tx_timeout_last_recovery
= jiffies
;
364 netdev_info(netdev
, "tx_timeout recovery level %d, hung_queue %d\n",
365 pf
->tx_timeout_recovery_level
, hung_queue
);
367 switch (pf
->tx_timeout_recovery_level
) {
369 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
372 set_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
);
375 set_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
);
378 netdev_err(netdev
, "tx_timeout recovery unsuccessful\n");
382 i40e_service_event_schedule(pf
);
383 pf
->tx_timeout_recovery_level
++;
387 * i40e_release_rx_desc - Store the new tail and head values
388 * @rx_ring: ring to bump
389 * @val: new head index
391 static inline void i40e_release_rx_desc(struct i40e_ring
*rx_ring
, u32 val
)
393 rx_ring
->next_to_use
= val
;
395 /* Force memory writes to complete before letting h/w
396 * know there are new descriptors to fetch. (Only
397 * applicable for weak-ordered memory model archs,
401 writel(val
, rx_ring
->tail
);
405 * i40e_get_vsi_stats_struct - Get System Network Statistics
406 * @vsi: the VSI we care about
408 * Returns the address of the device statistics structure.
409 * The statistics are actually updated from the service task.
411 struct rtnl_link_stats64
*i40e_get_vsi_stats_struct(struct i40e_vsi
*vsi
)
413 return &vsi
->net_stats
;
417 * i40e_get_netdev_stats_struct - Get statistics for netdev interface
418 * @netdev: network interface device structure
420 * Returns the address of the device statistics structure.
421 * The statistics are actually updated from the service task.
424 struct rtnl_link_stats64
*i40e_get_netdev_stats_struct(
425 struct net_device
*netdev
,
426 struct rtnl_link_stats64
*stats
)
428 static struct rtnl_link_stats64
*i40e_get_netdev_stats_struct(
429 struct net_device
*netdev
,
430 struct rtnl_link_stats64
*stats
)
433 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
434 struct i40e_ring
*tx_ring
, *rx_ring
;
435 struct i40e_vsi
*vsi
= np
->vsi
;
436 struct rtnl_link_stats64
*vsi_stats
= i40e_get_vsi_stats_struct(vsi
);
439 if (test_bit(__I40E_DOWN
, &vsi
->state
))
446 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
450 tx_ring
= ACCESS_ONCE(vsi
->tx_rings
[i
]);
455 start
= u64_stats_fetch_begin_irq(&tx_ring
->syncp
);
456 packets
= tx_ring
->stats
.packets
;
457 bytes
= tx_ring
->stats
.bytes
;
458 } while (u64_stats_fetch_retry_irq(&tx_ring
->syncp
, start
));
460 stats
->tx_packets
+= packets
;
461 stats
->tx_bytes
+= bytes
;
462 rx_ring
= &tx_ring
[1];
465 start
= u64_stats_fetch_begin_irq(&rx_ring
->syncp
);
466 packets
= rx_ring
->stats
.packets
;
467 bytes
= rx_ring
->stats
.bytes
;
468 } while (u64_stats_fetch_retry_irq(&rx_ring
->syncp
, start
));
470 stats
->rx_packets
+= packets
;
471 stats
->rx_bytes
+= bytes
;
475 /* following stats updated by i40e_watchdog_subtask() */
476 stats
->multicast
= vsi_stats
->multicast
;
477 stats
->tx_errors
= vsi_stats
->tx_errors
;
478 stats
->tx_dropped
= vsi_stats
->tx_dropped
;
479 stats
->rx_errors
= vsi_stats
->rx_errors
;
480 stats
->rx_dropped
= vsi_stats
->rx_dropped
;
481 stats
->rx_crc_errors
= vsi_stats
->rx_crc_errors
;
482 stats
->rx_length_errors
= vsi_stats
->rx_length_errors
;
488 * i40e_vsi_reset_stats - Resets all stats of the given vsi
489 * @vsi: the VSI to have its stats reset
491 void i40e_vsi_reset_stats(struct i40e_vsi
*vsi
)
493 struct rtnl_link_stats64
*ns
;
499 ns
= i40e_get_vsi_stats_struct(vsi
);
500 memset(ns
, 0, sizeof(*ns
));
501 memset(&vsi
->net_stats_offsets
, 0, sizeof(vsi
->net_stats_offsets
));
502 memset(&vsi
->eth_stats
, 0, sizeof(vsi
->eth_stats
));
503 memset(&vsi
->eth_stats_offsets
, 0, sizeof(vsi
->eth_stats_offsets
));
504 if (vsi
->rx_rings
&& vsi
->rx_rings
[0]) {
505 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
506 memset(&vsi
->rx_rings
[i
]->stats
, 0,
507 sizeof(vsi
->rx_rings
[i
]->stats
));
508 memset(&vsi
->rx_rings
[i
]->rx_stats
, 0,
509 sizeof(vsi
->rx_rings
[i
]->rx_stats
));
510 memset(&vsi
->tx_rings
[i
]->stats
, 0,
511 sizeof(vsi
->tx_rings
[i
]->stats
));
512 memset(&vsi
->tx_rings
[i
]->tx_stats
, 0,
513 sizeof(vsi
->tx_rings
[i
]->tx_stats
));
516 vsi
->stat_offsets_loaded
= false;
520 * i40e_pf_reset_stats - Reset all of the stats for the given PF
521 * @pf: the PF to be reset
523 void i40e_pf_reset_stats(struct i40e_pf
*pf
)
527 memset(&pf
->stats
, 0, sizeof(pf
->stats
));
528 memset(&pf
->stats_offsets
, 0, sizeof(pf
->stats_offsets
));
529 pf
->stat_offsets_loaded
= false;
531 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
533 memset(&pf
->veb
[i
]->stats
, 0,
534 sizeof(pf
->veb
[i
]->stats
));
535 memset(&pf
->veb
[i
]->stats_offsets
, 0,
536 sizeof(pf
->veb
[i
]->stats_offsets
));
537 pf
->veb
[i
]->stat_offsets_loaded
= false;
543 * i40e_stat_update48 - read and update a 48 bit stat from the chip
544 * @hw: ptr to the hardware info
545 * @hireg: the high 32 bit reg to read
546 * @loreg: the low 32 bit reg to read
547 * @offset_loaded: has the initial offset been loaded yet
548 * @offset: ptr to current offset value
549 * @stat: ptr to the stat
551 * Since the device stats are not reset at PFReset, they likely will not
552 * be zeroed when the driver starts. We'll save the first values read
553 * and use them as offsets to be subtracted from the raw values in order
554 * to report stats that count from zero. In the process, we also manage
555 * the potential roll-over.
557 static void i40e_stat_update48(struct i40e_hw
*hw
, u32 hireg
, u32 loreg
,
558 bool offset_loaded
, u64
*offset
, u64
*stat
)
562 if (hw
->device_id
== I40E_DEV_ID_QEMU
) {
563 new_data
= rd32(hw
, loreg
);
564 new_data
|= ((u64
)(rd32(hw
, hireg
) & 0xFFFF)) << 32;
566 new_data
= rd64(hw
, loreg
);
570 if (likely(new_data
>= *offset
))
571 *stat
= new_data
- *offset
;
573 *stat
= (new_data
+ BIT_ULL(48)) - *offset
;
574 *stat
&= 0xFFFFFFFFFFFFULL
;
578 * i40e_stat_update32 - read and update a 32 bit stat from the chip
579 * @hw: ptr to the hardware info
580 * @reg: the hw reg to read
581 * @offset_loaded: has the initial offset been loaded yet
582 * @offset: ptr to current offset value
583 * @stat: ptr to the stat
585 static void i40e_stat_update32(struct i40e_hw
*hw
, u32 reg
,
586 bool offset_loaded
, u64
*offset
, u64
*stat
)
590 new_data
= rd32(hw
, reg
);
593 if (likely(new_data
>= *offset
))
594 *stat
= (u32
)(new_data
- *offset
);
596 *stat
= (u32
)((new_data
+ BIT_ULL(32)) - *offset
);
600 * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
601 * @vsi: the VSI to be updated
603 void i40e_update_eth_stats(struct i40e_vsi
*vsi
)
605 int stat_idx
= le16_to_cpu(vsi
->info
.stat_counter_idx
);
606 struct i40e_pf
*pf
= vsi
->back
;
607 struct i40e_hw
*hw
= &pf
->hw
;
608 struct i40e_eth_stats
*oes
;
609 struct i40e_eth_stats
*es
; /* device's eth stats */
611 es
= &vsi
->eth_stats
;
612 oes
= &vsi
->eth_stats_offsets
;
614 /* Gather up the stats that the hw collects */
615 i40e_stat_update32(hw
, I40E_GLV_TEPC(stat_idx
),
616 vsi
->stat_offsets_loaded
,
617 &oes
->tx_errors
, &es
->tx_errors
);
618 i40e_stat_update32(hw
, I40E_GLV_RDPC(stat_idx
),
619 vsi
->stat_offsets_loaded
,
620 &oes
->rx_discards
, &es
->rx_discards
);
621 i40e_stat_update32(hw
, I40E_GLV_RUPP(stat_idx
),
622 vsi
->stat_offsets_loaded
,
623 &oes
->rx_unknown_protocol
, &es
->rx_unknown_protocol
);
624 i40e_stat_update32(hw
, I40E_GLV_TEPC(stat_idx
),
625 vsi
->stat_offsets_loaded
,
626 &oes
->tx_errors
, &es
->tx_errors
);
628 i40e_stat_update48(hw
, I40E_GLV_GORCH(stat_idx
),
629 I40E_GLV_GORCL(stat_idx
),
630 vsi
->stat_offsets_loaded
,
631 &oes
->rx_bytes
, &es
->rx_bytes
);
632 i40e_stat_update48(hw
, I40E_GLV_UPRCH(stat_idx
),
633 I40E_GLV_UPRCL(stat_idx
),
634 vsi
->stat_offsets_loaded
,
635 &oes
->rx_unicast
, &es
->rx_unicast
);
636 i40e_stat_update48(hw
, I40E_GLV_MPRCH(stat_idx
),
637 I40E_GLV_MPRCL(stat_idx
),
638 vsi
->stat_offsets_loaded
,
639 &oes
->rx_multicast
, &es
->rx_multicast
);
640 i40e_stat_update48(hw
, I40E_GLV_BPRCH(stat_idx
),
641 I40E_GLV_BPRCL(stat_idx
),
642 vsi
->stat_offsets_loaded
,
643 &oes
->rx_broadcast
, &es
->rx_broadcast
);
645 i40e_stat_update48(hw
, I40E_GLV_GOTCH(stat_idx
),
646 I40E_GLV_GOTCL(stat_idx
),
647 vsi
->stat_offsets_loaded
,
648 &oes
->tx_bytes
, &es
->tx_bytes
);
649 i40e_stat_update48(hw
, I40E_GLV_UPTCH(stat_idx
),
650 I40E_GLV_UPTCL(stat_idx
),
651 vsi
->stat_offsets_loaded
,
652 &oes
->tx_unicast
, &es
->tx_unicast
);
653 i40e_stat_update48(hw
, I40E_GLV_MPTCH(stat_idx
),
654 I40E_GLV_MPTCL(stat_idx
),
655 vsi
->stat_offsets_loaded
,
656 &oes
->tx_multicast
, &es
->tx_multicast
);
657 i40e_stat_update48(hw
, I40E_GLV_BPTCH(stat_idx
),
658 I40E_GLV_BPTCL(stat_idx
),
659 vsi
->stat_offsets_loaded
,
660 &oes
->tx_broadcast
, &es
->tx_broadcast
);
661 vsi
->stat_offsets_loaded
= true;
665 * i40e_update_veb_stats - Update Switch component statistics
666 * @veb: the VEB being updated
668 static void i40e_update_veb_stats(struct i40e_veb
*veb
)
670 struct i40e_pf
*pf
= veb
->pf
;
671 struct i40e_hw
*hw
= &pf
->hw
;
672 struct i40e_eth_stats
*oes
;
673 struct i40e_eth_stats
*es
; /* device's eth stats */
674 struct i40e_veb_tc_stats
*veb_oes
;
675 struct i40e_veb_tc_stats
*veb_es
;
678 idx
= veb
->stats_idx
;
680 oes
= &veb
->stats_offsets
;
681 veb_es
= &veb
->tc_stats
;
682 veb_oes
= &veb
->tc_stats_offsets
;
684 /* Gather up the stats that the hw collects */
685 i40e_stat_update32(hw
, I40E_GLSW_TDPC(idx
),
686 veb
->stat_offsets_loaded
,
687 &oes
->tx_discards
, &es
->tx_discards
);
688 if (hw
->revision_id
> 0)
689 i40e_stat_update32(hw
, I40E_GLSW_RUPP(idx
),
690 veb
->stat_offsets_loaded
,
691 &oes
->rx_unknown_protocol
,
692 &es
->rx_unknown_protocol
);
693 i40e_stat_update48(hw
, I40E_GLSW_GORCH(idx
), I40E_GLSW_GORCL(idx
),
694 veb
->stat_offsets_loaded
,
695 &oes
->rx_bytes
, &es
->rx_bytes
);
696 i40e_stat_update48(hw
, I40E_GLSW_UPRCH(idx
), I40E_GLSW_UPRCL(idx
),
697 veb
->stat_offsets_loaded
,
698 &oes
->rx_unicast
, &es
->rx_unicast
);
699 i40e_stat_update48(hw
, I40E_GLSW_MPRCH(idx
), I40E_GLSW_MPRCL(idx
),
700 veb
->stat_offsets_loaded
,
701 &oes
->rx_multicast
, &es
->rx_multicast
);
702 i40e_stat_update48(hw
, I40E_GLSW_BPRCH(idx
), I40E_GLSW_BPRCL(idx
),
703 veb
->stat_offsets_loaded
,
704 &oes
->rx_broadcast
, &es
->rx_broadcast
);
706 i40e_stat_update48(hw
, I40E_GLSW_GOTCH(idx
), I40E_GLSW_GOTCL(idx
),
707 veb
->stat_offsets_loaded
,
708 &oes
->tx_bytes
, &es
->tx_bytes
);
709 i40e_stat_update48(hw
, I40E_GLSW_UPTCH(idx
), I40E_GLSW_UPTCL(idx
),
710 veb
->stat_offsets_loaded
,
711 &oes
->tx_unicast
, &es
->tx_unicast
);
712 i40e_stat_update48(hw
, I40E_GLSW_MPTCH(idx
), I40E_GLSW_MPTCL(idx
),
713 veb
->stat_offsets_loaded
,
714 &oes
->tx_multicast
, &es
->tx_multicast
);
715 i40e_stat_update48(hw
, I40E_GLSW_BPTCH(idx
), I40E_GLSW_BPTCL(idx
),
716 veb
->stat_offsets_loaded
,
717 &oes
->tx_broadcast
, &es
->tx_broadcast
);
718 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
719 i40e_stat_update48(hw
, I40E_GLVEBTC_RPCH(i
, idx
),
720 I40E_GLVEBTC_RPCL(i
, idx
),
721 veb
->stat_offsets_loaded
,
722 &veb_oes
->tc_rx_packets
[i
],
723 &veb_es
->tc_rx_packets
[i
]);
724 i40e_stat_update48(hw
, I40E_GLVEBTC_RBCH(i
, idx
),
725 I40E_GLVEBTC_RBCL(i
, idx
),
726 veb
->stat_offsets_loaded
,
727 &veb_oes
->tc_rx_bytes
[i
],
728 &veb_es
->tc_rx_bytes
[i
]);
729 i40e_stat_update48(hw
, I40E_GLVEBTC_TPCH(i
, idx
),
730 I40E_GLVEBTC_TPCL(i
, idx
),
731 veb
->stat_offsets_loaded
,
732 &veb_oes
->tc_tx_packets
[i
],
733 &veb_es
->tc_tx_packets
[i
]);
734 i40e_stat_update48(hw
, I40E_GLVEBTC_TBCH(i
, idx
),
735 I40E_GLVEBTC_TBCL(i
, idx
),
736 veb
->stat_offsets_loaded
,
737 &veb_oes
->tc_tx_bytes
[i
],
738 &veb_es
->tc_tx_bytes
[i
]);
740 veb
->stat_offsets_loaded
= true;
745 * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters.
746 * @vsi: the VSI that is capable of doing FCoE
748 static void i40e_update_fcoe_stats(struct i40e_vsi
*vsi
)
750 struct i40e_pf
*pf
= vsi
->back
;
751 struct i40e_hw
*hw
= &pf
->hw
;
752 struct i40e_fcoe_stats
*ofs
;
753 struct i40e_fcoe_stats
*fs
; /* device's eth stats */
756 if (vsi
->type
!= I40E_VSI_FCOE
)
759 idx
= (pf
->pf_seid
- I40E_BASE_PF_SEID
) + I40E_FCOE_PF_STAT_OFFSET
;
760 fs
= &vsi
->fcoe_stats
;
761 ofs
= &vsi
->fcoe_stats_offsets
;
763 i40e_stat_update32(hw
, I40E_GL_FCOEPRC(idx
),
764 vsi
->fcoe_stat_offsets_loaded
,
765 &ofs
->rx_fcoe_packets
, &fs
->rx_fcoe_packets
);
766 i40e_stat_update48(hw
, I40E_GL_FCOEDWRCH(idx
), I40E_GL_FCOEDWRCL(idx
),
767 vsi
->fcoe_stat_offsets_loaded
,
768 &ofs
->rx_fcoe_dwords
, &fs
->rx_fcoe_dwords
);
769 i40e_stat_update32(hw
, I40E_GL_FCOERPDC(idx
),
770 vsi
->fcoe_stat_offsets_loaded
,
771 &ofs
->rx_fcoe_dropped
, &fs
->rx_fcoe_dropped
);
772 i40e_stat_update32(hw
, I40E_GL_FCOEPTC(idx
),
773 vsi
->fcoe_stat_offsets_loaded
,
774 &ofs
->tx_fcoe_packets
, &fs
->tx_fcoe_packets
);
775 i40e_stat_update48(hw
, I40E_GL_FCOEDWTCH(idx
), I40E_GL_FCOEDWTCL(idx
),
776 vsi
->fcoe_stat_offsets_loaded
,
777 &ofs
->tx_fcoe_dwords
, &fs
->tx_fcoe_dwords
);
778 i40e_stat_update32(hw
, I40E_GL_FCOECRC(idx
),
779 vsi
->fcoe_stat_offsets_loaded
,
780 &ofs
->fcoe_bad_fccrc
, &fs
->fcoe_bad_fccrc
);
781 i40e_stat_update32(hw
, I40E_GL_FCOELAST(idx
),
782 vsi
->fcoe_stat_offsets_loaded
,
783 &ofs
->fcoe_last_error
, &fs
->fcoe_last_error
);
784 i40e_stat_update32(hw
, I40E_GL_FCOEDDPC(idx
),
785 vsi
->fcoe_stat_offsets_loaded
,
786 &ofs
->fcoe_ddp_count
, &fs
->fcoe_ddp_count
);
788 vsi
->fcoe_stat_offsets_loaded
= true;
793 * i40e_update_link_xoff_rx - Update XOFF received in link flow control mode
794 * @pf: the corresponding PF
796 * Update the Rx XOFF counter (PAUSE frames) in link flow control mode
798 static void i40e_update_link_xoff_rx(struct i40e_pf
*pf
)
800 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
801 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
802 struct i40e_hw
*hw
= &pf
->hw
;
805 if ((hw
->fc
.current_mode
!= I40E_FC_FULL
) &&
806 (hw
->fc
.current_mode
!= I40E_FC_RX_PAUSE
))
809 xoff
= nsd
->link_xoff_rx
;
810 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFRXC(hw
->port
),
811 pf
->stat_offsets_loaded
,
812 &osd
->link_xoff_rx
, &nsd
->link_xoff_rx
);
814 /* No new LFC xoff rx */
815 if (!(nsd
->link_xoff_rx
- xoff
))
821 * i40e_update_prio_xoff_rx - Update XOFF received in PFC mode
822 * @pf: the corresponding PF
824 * Update the Rx XOFF counter (PAUSE frames) in PFC mode
826 static void i40e_update_prio_xoff_rx(struct i40e_pf
*pf
)
828 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
829 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
830 bool xoff
[I40E_MAX_TRAFFIC_CLASS
] = {false};
831 struct i40e_dcbx_config
*dcb_cfg
;
832 struct i40e_hw
*hw
= &pf
->hw
;
836 dcb_cfg
= &hw
->local_dcbx_config
;
838 /* Collect Link XOFF stats when PFC is disabled */
839 if (!dcb_cfg
->pfc
.pfcenable
) {
840 i40e_update_link_xoff_rx(pf
);
844 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
845 u64 prio_xoff
= nsd
->priority_xoff_rx
[i
];
847 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFRXC(hw
->port
, i
),
848 pf
->stat_offsets_loaded
,
849 &osd
->priority_xoff_rx
[i
],
850 &nsd
->priority_xoff_rx
[i
]);
852 /* No new PFC xoff rx */
853 if (!(nsd
->priority_xoff_rx
[i
] - prio_xoff
))
855 /* Get the TC for given priority */
856 tc
= dcb_cfg
->etscfg
.prioritytable
[i
];
862 * i40e_update_vsi_stats - Update the vsi statistics counters.
863 * @vsi: the VSI to be updated
865 * There are a few instances where we store the same stat in a
866 * couple of different structs. This is partly because we have
867 * the netdev stats that need to be filled out, which is slightly
868 * different from the "eth_stats" defined by the chip and used in
869 * VF communications. We sort it out here.
871 static void i40e_update_vsi_stats(struct i40e_vsi
*vsi
)
873 struct i40e_pf
*pf
= vsi
->back
;
874 struct rtnl_link_stats64
*ons
;
875 struct rtnl_link_stats64
*ns
; /* netdev stats */
876 struct i40e_eth_stats
*oes
;
877 struct i40e_eth_stats
*es
; /* device's eth stats */
878 u32 tx_restart
, tx_busy
;
888 if (test_bit(__I40E_DOWN
, &vsi
->state
) ||
889 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
892 ns
= i40e_get_vsi_stats_struct(vsi
);
893 ons
= &vsi
->net_stats_offsets
;
894 es
= &vsi
->eth_stats
;
895 oes
= &vsi
->eth_stats_offsets
;
897 /* Gather up the netdev and vsi stats that the driver collects
898 * on the fly during packet processing
902 tx_restart
= tx_busy
= tx_linearize
= 0;
906 for (q
= 0; q
< vsi
->num_queue_pairs
; q
++) {
908 p
= ACCESS_ONCE(vsi
->tx_rings
[q
]);
911 start
= u64_stats_fetch_begin_irq(&p
->syncp
);
912 packets
= p
->stats
.packets
;
913 bytes
= p
->stats
.bytes
;
914 } while (u64_stats_fetch_retry_irq(&p
->syncp
, start
));
917 tx_restart
+= p
->tx_stats
.restart_queue
;
918 tx_busy
+= p
->tx_stats
.tx_busy
;
919 tx_linearize
+= p
->tx_stats
.tx_linearize
;
921 /* Rx queue is part of the same block as Tx queue */
924 start
= u64_stats_fetch_begin_irq(&p
->syncp
);
925 packets
= p
->stats
.packets
;
926 bytes
= p
->stats
.bytes
;
927 } while (u64_stats_fetch_retry_irq(&p
->syncp
, start
));
930 rx_buf
+= p
->rx_stats
.alloc_buff_failed
;
931 rx_page
+= p
->rx_stats
.alloc_page_failed
;
934 vsi
->tx_restart
= tx_restart
;
935 vsi
->tx_busy
= tx_busy
;
936 vsi
->tx_linearize
= tx_linearize
;
937 vsi
->rx_page_failed
= rx_page
;
938 vsi
->rx_buf_failed
= rx_buf
;
940 ns
->rx_packets
= rx_p
;
942 ns
->tx_packets
= tx_p
;
945 /* update netdev stats from eth stats */
946 i40e_update_eth_stats(vsi
);
947 ons
->tx_errors
= oes
->tx_errors
;
948 ns
->tx_errors
= es
->tx_errors
;
949 ons
->multicast
= oes
->rx_multicast
;
950 ns
->multicast
= es
->rx_multicast
;
951 ons
->rx_dropped
= oes
->rx_discards
;
952 ns
->rx_dropped
= es
->rx_discards
;
953 ons
->tx_dropped
= oes
->tx_discards
;
954 ns
->tx_dropped
= es
->tx_discards
;
956 /* pull in a couple PF stats if this is the main vsi */
957 if (vsi
== pf
->vsi
[pf
->lan_vsi
]) {
958 ns
->rx_crc_errors
= pf
->stats
.crc_errors
;
959 ns
->rx_errors
= pf
->stats
.crc_errors
+ pf
->stats
.illegal_bytes
;
960 ns
->rx_length_errors
= pf
->stats
.rx_length_errors
;
965 * i40e_update_pf_stats - Update the PF statistics counters.
966 * @pf: the PF to be updated
968 static void i40e_update_pf_stats(struct i40e_pf
*pf
)
970 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
971 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
972 struct i40e_hw
*hw
= &pf
->hw
;
976 i40e_stat_update48(hw
, I40E_GLPRT_GORCH(hw
->port
),
977 I40E_GLPRT_GORCL(hw
->port
),
978 pf
->stat_offsets_loaded
,
979 &osd
->eth
.rx_bytes
, &nsd
->eth
.rx_bytes
);
980 i40e_stat_update48(hw
, I40E_GLPRT_GOTCH(hw
->port
),
981 I40E_GLPRT_GOTCL(hw
->port
),
982 pf
->stat_offsets_loaded
,
983 &osd
->eth
.tx_bytes
, &nsd
->eth
.tx_bytes
);
984 i40e_stat_update32(hw
, I40E_GLPRT_RDPC(hw
->port
),
985 pf
->stat_offsets_loaded
,
986 &osd
->eth
.rx_discards
,
987 &nsd
->eth
.rx_discards
);
988 i40e_stat_update48(hw
, I40E_GLPRT_UPRCH(hw
->port
),
989 I40E_GLPRT_UPRCL(hw
->port
),
990 pf
->stat_offsets_loaded
,
991 &osd
->eth
.rx_unicast
,
992 &nsd
->eth
.rx_unicast
);
993 i40e_stat_update48(hw
, I40E_GLPRT_MPRCH(hw
->port
),
994 I40E_GLPRT_MPRCL(hw
->port
),
995 pf
->stat_offsets_loaded
,
996 &osd
->eth
.rx_multicast
,
997 &nsd
->eth
.rx_multicast
);
998 i40e_stat_update48(hw
, I40E_GLPRT_BPRCH(hw
->port
),
999 I40E_GLPRT_BPRCL(hw
->port
),
1000 pf
->stat_offsets_loaded
,
1001 &osd
->eth
.rx_broadcast
,
1002 &nsd
->eth
.rx_broadcast
);
1003 i40e_stat_update48(hw
, I40E_GLPRT_UPTCH(hw
->port
),
1004 I40E_GLPRT_UPTCL(hw
->port
),
1005 pf
->stat_offsets_loaded
,
1006 &osd
->eth
.tx_unicast
,
1007 &nsd
->eth
.tx_unicast
);
1008 i40e_stat_update48(hw
, I40E_GLPRT_MPTCH(hw
->port
),
1009 I40E_GLPRT_MPTCL(hw
->port
),
1010 pf
->stat_offsets_loaded
,
1011 &osd
->eth
.tx_multicast
,
1012 &nsd
->eth
.tx_multicast
);
1013 i40e_stat_update48(hw
, I40E_GLPRT_BPTCH(hw
->port
),
1014 I40E_GLPRT_BPTCL(hw
->port
),
1015 pf
->stat_offsets_loaded
,
1016 &osd
->eth
.tx_broadcast
,
1017 &nsd
->eth
.tx_broadcast
);
1019 i40e_stat_update32(hw
, I40E_GLPRT_TDOLD(hw
->port
),
1020 pf
->stat_offsets_loaded
,
1021 &osd
->tx_dropped_link_down
,
1022 &nsd
->tx_dropped_link_down
);
1024 i40e_stat_update32(hw
, I40E_GLPRT_CRCERRS(hw
->port
),
1025 pf
->stat_offsets_loaded
,
1026 &osd
->crc_errors
, &nsd
->crc_errors
);
1028 i40e_stat_update32(hw
, I40E_GLPRT_ILLERRC(hw
->port
),
1029 pf
->stat_offsets_loaded
,
1030 &osd
->illegal_bytes
, &nsd
->illegal_bytes
);
1032 i40e_stat_update32(hw
, I40E_GLPRT_MLFC(hw
->port
),
1033 pf
->stat_offsets_loaded
,
1034 &osd
->mac_local_faults
,
1035 &nsd
->mac_local_faults
);
1036 i40e_stat_update32(hw
, I40E_GLPRT_MRFC(hw
->port
),
1037 pf
->stat_offsets_loaded
,
1038 &osd
->mac_remote_faults
,
1039 &nsd
->mac_remote_faults
);
1041 i40e_stat_update32(hw
, I40E_GLPRT_RLEC(hw
->port
),
1042 pf
->stat_offsets_loaded
,
1043 &osd
->rx_length_errors
,
1044 &nsd
->rx_length_errors
);
1046 i40e_stat_update32(hw
, I40E_GLPRT_LXONRXC(hw
->port
),
1047 pf
->stat_offsets_loaded
,
1048 &osd
->link_xon_rx
, &nsd
->link_xon_rx
);
1049 i40e_stat_update32(hw
, I40E_GLPRT_LXONTXC(hw
->port
),
1050 pf
->stat_offsets_loaded
,
1051 &osd
->link_xon_tx
, &nsd
->link_xon_tx
);
1052 i40e_update_prio_xoff_rx(pf
); /* handles I40E_GLPRT_LXOFFRXC */
1053 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFTXC(hw
->port
),
1054 pf
->stat_offsets_loaded
,
1055 &osd
->link_xoff_tx
, &nsd
->link_xoff_tx
);
1057 for (i
= 0; i
< 8; i
++) {
1058 i40e_stat_update32(hw
, I40E_GLPRT_PXONRXC(hw
->port
, i
),
1059 pf
->stat_offsets_loaded
,
1060 &osd
->priority_xon_rx
[i
],
1061 &nsd
->priority_xon_rx
[i
]);
1062 i40e_stat_update32(hw
, I40E_GLPRT_PXONTXC(hw
->port
, i
),
1063 pf
->stat_offsets_loaded
,
1064 &osd
->priority_xon_tx
[i
],
1065 &nsd
->priority_xon_tx
[i
]);
1066 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFTXC(hw
->port
, i
),
1067 pf
->stat_offsets_loaded
,
1068 &osd
->priority_xoff_tx
[i
],
1069 &nsd
->priority_xoff_tx
[i
]);
1070 i40e_stat_update32(hw
,
1071 I40E_GLPRT_RXON2OFFCNT(hw
->port
, i
),
1072 pf
->stat_offsets_loaded
,
1073 &osd
->priority_xon_2_xoff
[i
],
1074 &nsd
->priority_xon_2_xoff
[i
]);
1077 i40e_stat_update48(hw
, I40E_GLPRT_PRC64H(hw
->port
),
1078 I40E_GLPRT_PRC64L(hw
->port
),
1079 pf
->stat_offsets_loaded
,
1080 &osd
->rx_size_64
, &nsd
->rx_size_64
);
1081 i40e_stat_update48(hw
, I40E_GLPRT_PRC127H(hw
->port
),
1082 I40E_GLPRT_PRC127L(hw
->port
),
1083 pf
->stat_offsets_loaded
,
1084 &osd
->rx_size_127
, &nsd
->rx_size_127
);
1085 i40e_stat_update48(hw
, I40E_GLPRT_PRC255H(hw
->port
),
1086 I40E_GLPRT_PRC255L(hw
->port
),
1087 pf
->stat_offsets_loaded
,
1088 &osd
->rx_size_255
, &nsd
->rx_size_255
);
1089 i40e_stat_update48(hw
, I40E_GLPRT_PRC511H(hw
->port
),
1090 I40E_GLPRT_PRC511L(hw
->port
),
1091 pf
->stat_offsets_loaded
,
1092 &osd
->rx_size_511
, &nsd
->rx_size_511
);
1093 i40e_stat_update48(hw
, I40E_GLPRT_PRC1023H(hw
->port
),
1094 I40E_GLPRT_PRC1023L(hw
->port
),
1095 pf
->stat_offsets_loaded
,
1096 &osd
->rx_size_1023
, &nsd
->rx_size_1023
);
1097 i40e_stat_update48(hw
, I40E_GLPRT_PRC1522H(hw
->port
),
1098 I40E_GLPRT_PRC1522L(hw
->port
),
1099 pf
->stat_offsets_loaded
,
1100 &osd
->rx_size_1522
, &nsd
->rx_size_1522
);
1101 i40e_stat_update48(hw
, I40E_GLPRT_PRC9522H(hw
->port
),
1102 I40E_GLPRT_PRC9522L(hw
->port
),
1103 pf
->stat_offsets_loaded
,
1104 &osd
->rx_size_big
, &nsd
->rx_size_big
);
1106 i40e_stat_update48(hw
, I40E_GLPRT_PTC64H(hw
->port
),
1107 I40E_GLPRT_PTC64L(hw
->port
),
1108 pf
->stat_offsets_loaded
,
1109 &osd
->tx_size_64
, &nsd
->tx_size_64
);
1110 i40e_stat_update48(hw
, I40E_GLPRT_PTC127H(hw
->port
),
1111 I40E_GLPRT_PTC127L(hw
->port
),
1112 pf
->stat_offsets_loaded
,
1113 &osd
->tx_size_127
, &nsd
->tx_size_127
);
1114 i40e_stat_update48(hw
, I40E_GLPRT_PTC255H(hw
->port
),
1115 I40E_GLPRT_PTC255L(hw
->port
),
1116 pf
->stat_offsets_loaded
,
1117 &osd
->tx_size_255
, &nsd
->tx_size_255
);
1118 i40e_stat_update48(hw
, I40E_GLPRT_PTC511H(hw
->port
),
1119 I40E_GLPRT_PTC511L(hw
->port
),
1120 pf
->stat_offsets_loaded
,
1121 &osd
->tx_size_511
, &nsd
->tx_size_511
);
1122 i40e_stat_update48(hw
, I40E_GLPRT_PTC1023H(hw
->port
),
1123 I40E_GLPRT_PTC1023L(hw
->port
),
1124 pf
->stat_offsets_loaded
,
1125 &osd
->tx_size_1023
, &nsd
->tx_size_1023
);
1126 i40e_stat_update48(hw
, I40E_GLPRT_PTC1522H(hw
->port
),
1127 I40E_GLPRT_PTC1522L(hw
->port
),
1128 pf
->stat_offsets_loaded
,
1129 &osd
->tx_size_1522
, &nsd
->tx_size_1522
);
1130 i40e_stat_update48(hw
, I40E_GLPRT_PTC9522H(hw
->port
),
1131 I40E_GLPRT_PTC9522L(hw
->port
),
1132 pf
->stat_offsets_loaded
,
1133 &osd
->tx_size_big
, &nsd
->tx_size_big
);
1135 i40e_stat_update32(hw
, I40E_GLPRT_RUC(hw
->port
),
1136 pf
->stat_offsets_loaded
,
1137 &osd
->rx_undersize
, &nsd
->rx_undersize
);
1138 i40e_stat_update32(hw
, I40E_GLPRT_RFC(hw
->port
),
1139 pf
->stat_offsets_loaded
,
1140 &osd
->rx_fragments
, &nsd
->rx_fragments
);
1141 i40e_stat_update32(hw
, I40E_GLPRT_ROC(hw
->port
),
1142 pf
->stat_offsets_loaded
,
1143 &osd
->rx_oversize
, &nsd
->rx_oversize
);
1144 i40e_stat_update32(hw
, I40E_GLPRT_RJC(hw
->port
),
1145 pf
->stat_offsets_loaded
,
1146 &osd
->rx_jabber
, &nsd
->rx_jabber
);
1149 i40e_stat_update32(hw
,
1150 I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf
->hw
.pf_id
)),
1151 pf
->stat_offsets_loaded
,
1152 &osd
->fd_atr_match
, &nsd
->fd_atr_match
);
1153 i40e_stat_update32(hw
,
1154 I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf
->hw
.pf_id
)),
1155 pf
->stat_offsets_loaded
,
1156 &osd
->fd_sb_match
, &nsd
->fd_sb_match
);
1157 i40e_stat_update32(hw
,
1158 I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf
->hw
.pf_id
)),
1159 pf
->stat_offsets_loaded
,
1160 &osd
->fd_atr_tunnel_match
, &nsd
->fd_atr_tunnel_match
);
1162 val
= rd32(hw
, I40E_PRTPM_EEE_STAT
);
1163 nsd
->tx_lpi_status
=
1164 (val
& I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK
) >>
1165 I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT
;
1166 nsd
->rx_lpi_status
=
1167 (val
& I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK
) >>
1168 I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT
;
1169 i40e_stat_update32(hw
, I40E_PRTPM_TLPIC
,
1170 pf
->stat_offsets_loaded
,
1171 &osd
->tx_lpi_count
, &nsd
->tx_lpi_count
);
1172 i40e_stat_update32(hw
, I40E_PRTPM_RLPIC
,
1173 pf
->stat_offsets_loaded
,
1174 &osd
->rx_lpi_count
, &nsd
->rx_lpi_count
);
1176 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
&&
1177 !(pf
->auto_disable_flags
& I40E_FLAG_FD_SB_ENABLED
))
1178 nsd
->fd_sb_status
= true;
1180 nsd
->fd_sb_status
= false;
1182 if (pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
&&
1183 !(pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
))
1184 nsd
->fd_atr_status
= true;
1186 nsd
->fd_atr_status
= false;
1188 pf
->stat_offsets_loaded
= true;
1192 * i40e_update_stats - Update the various statistics counters.
1193 * @vsi: the VSI to be updated
1195 * Update the various stats for this VSI and its related entities.
1197 void i40e_update_stats(struct i40e_vsi
*vsi
)
1199 struct i40e_pf
*pf
= vsi
->back
;
1201 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
1202 i40e_update_pf_stats(pf
);
1204 i40e_update_vsi_stats(vsi
);
1206 i40e_update_fcoe_stats(vsi
);
1211 * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
1212 * @vsi: the VSI to be searched
1213 * @macaddr: the MAC address
1215 * @is_vf: make sure its a VF filter, else doesn't matter
1216 * @is_netdev: make sure its a netdev filter, else doesn't matter
1218 * Returns ptr to the filter object or NULL
1220 static struct i40e_mac_filter
*i40e_find_filter(struct i40e_vsi
*vsi
,
1221 u8
*macaddr
, s16 vlan
,
1222 bool is_vf
, bool is_netdev
)
1224 struct i40e_mac_filter
*f
;
1226 if (!vsi
|| !macaddr
)
1229 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1230 if ((ether_addr_equal(macaddr
, f
->macaddr
)) &&
1231 (vlan
== f
->vlan
) &&
1232 (!is_vf
|| f
->is_vf
) &&
1233 (!is_netdev
|| f
->is_netdev
))
1240 * i40e_find_mac - Find a mac addr in the macvlan filters list
1241 * @vsi: the VSI to be searched
1242 * @macaddr: the MAC address we are searching for
1243 * @is_vf: make sure its a VF filter, else doesn't matter
1244 * @is_netdev: make sure its a netdev filter, else doesn't matter
1246 * Returns the first filter with the provided MAC address or NULL if
1247 * MAC address was not found
1249 struct i40e_mac_filter
*i40e_find_mac(struct i40e_vsi
*vsi
, u8
*macaddr
,
1250 bool is_vf
, bool is_netdev
)
1252 struct i40e_mac_filter
*f
;
1254 if (!vsi
|| !macaddr
)
1257 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1258 if ((ether_addr_equal(macaddr
, f
->macaddr
)) &&
1259 (!is_vf
|| f
->is_vf
) &&
1260 (!is_netdev
|| f
->is_netdev
))
1267 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1268 * @vsi: the VSI to be searched
1270 * Returns true if VSI is in vlan mode or false otherwise
1272 bool i40e_is_vsi_in_vlan(struct i40e_vsi
*vsi
)
1274 struct i40e_mac_filter
*f
;
1276 /* Only -1 for all the filters denotes not in vlan mode
1277 * so we have to go through all the list in order to make sure
1279 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1280 if (f
->vlan
>= 0 || vsi
->info
.pvid
)
1288 * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
1289 * @vsi: the VSI to be searched
1290 * @macaddr: the mac address to be filtered
1291 * @is_vf: true if it is a VF
1292 * @is_netdev: true if it is a netdev
1294 * Goes through all the macvlan filters and adds a
1295 * macvlan filter for each unique vlan that already exists
1297 * Returns first filter found on success, else NULL
1299 struct i40e_mac_filter
*i40e_put_mac_in_vlan(struct i40e_vsi
*vsi
, u8
*macaddr
,
1300 bool is_vf
, bool is_netdev
)
1302 struct i40e_mac_filter
*f
;
1304 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1306 f
->vlan
= le16_to_cpu(vsi
->info
.pvid
);
1307 if (!i40e_find_filter(vsi
, macaddr
, f
->vlan
,
1308 is_vf
, is_netdev
)) {
1309 if (!i40e_add_filter(vsi
, macaddr
, f
->vlan
,
1315 return list_first_entry_or_null(&vsi
->mac_filter_list
,
1316 struct i40e_mac_filter
, list
);
1320 * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
1321 * @vsi: the PF Main VSI - inappropriate for any other VSI
1322 * @macaddr: the MAC address
1324 * Some older firmware configurations set up a default promiscuous VLAN
1325 * filter that needs to be removed.
1327 static int i40e_rm_default_mac_filter(struct i40e_vsi
*vsi
, u8
*macaddr
)
1329 struct i40e_aqc_remove_macvlan_element_data element
;
1330 struct i40e_pf
*pf
= vsi
->back
;
1333 /* Only appropriate for the PF main VSI */
1334 if (vsi
->type
!= I40E_VSI_MAIN
)
1337 memset(&element
, 0, sizeof(element
));
1338 ether_addr_copy(element
.mac_addr
, macaddr
);
1339 element
.vlan_tag
= 0;
1340 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
|
1341 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
1342 ret
= i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1350 * i40e_add_filter - Add a mac/vlan filter to the VSI
1351 * @vsi: the VSI to be searched
1352 * @macaddr: the MAC address
1354 * @is_vf: make sure its a VF filter, else doesn't matter
1355 * @is_netdev: make sure its a netdev filter, else doesn't matter
1357 * Returns ptr to the filter object or NULL when no memory available.
1359 * NOTE: This function is expected to be called with mac_filter_list_lock
1362 struct i40e_mac_filter
*i40e_add_filter(struct i40e_vsi
*vsi
,
1363 u8
*macaddr
, s16 vlan
,
1364 bool is_vf
, bool is_netdev
)
1366 struct i40e_mac_filter
*f
;
1368 if (!vsi
|| !macaddr
)
1371 f
= i40e_find_filter(vsi
, macaddr
, vlan
, is_vf
, is_netdev
);
1373 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
1375 goto add_filter_out
;
1377 ether_addr_copy(f
->macaddr
, macaddr
);
1381 INIT_LIST_HEAD(&f
->list
);
1382 list_add(&f
->list
, &vsi
->mac_filter_list
);
1385 /* increment counter and add a new flag if needed */
1391 } else if (is_netdev
) {
1392 if (!f
->is_netdev
) {
1393 f
->is_netdev
= true;
1400 /* changed tells sync_filters_subtask to
1401 * push the filter down to the firmware
1404 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1405 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1413 * i40e_del_filter - Remove a mac/vlan filter from the VSI
1414 * @vsi: the VSI to be searched
1415 * @macaddr: the MAC address
1417 * @is_vf: make sure it's a VF filter, else doesn't matter
1418 * @is_netdev: make sure it's a netdev filter, else doesn't matter
1420 * NOTE: This function is expected to be called with mac_filter_list_lock
1423 void i40e_del_filter(struct i40e_vsi
*vsi
,
1424 u8
*macaddr
, s16 vlan
,
1425 bool is_vf
, bool is_netdev
)
1427 struct i40e_mac_filter
*f
;
1429 if (!vsi
|| !macaddr
)
1432 f
= i40e_find_filter(vsi
, macaddr
, vlan
, is_vf
, is_netdev
);
1433 if (!f
|| f
->counter
== 0)
1441 } else if (is_netdev
) {
1443 f
->is_netdev
= false;
1447 /* make sure we don't remove a filter in use by VF or netdev */
1450 min_f
+= (f
->is_vf
? 1 : 0);
1451 min_f
+= (f
->is_netdev
? 1 : 0);
1453 if (f
->counter
> min_f
)
1457 /* counter == 0 tells sync_filters_subtask to
1458 * remove the filter from the firmware's list
1460 if (f
->counter
== 0) {
1462 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1463 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1468 * i40e_set_mac - NDO callback to set mac address
1469 * @netdev: network interface device structure
1470 * @p: pointer to an address structure
1472 * Returns 0 on success, negative on failure
1475 int i40e_set_mac(struct net_device
*netdev
, void *p
)
1477 static int i40e_set_mac(struct net_device
*netdev
, void *p
)
1480 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1481 struct i40e_vsi
*vsi
= np
->vsi
;
1482 struct i40e_pf
*pf
= vsi
->back
;
1483 struct i40e_hw
*hw
= &pf
->hw
;
1484 struct sockaddr
*addr
= p
;
1485 struct i40e_mac_filter
*f
;
1487 if (!is_valid_ether_addr(addr
->sa_data
))
1488 return -EADDRNOTAVAIL
;
1490 if (ether_addr_equal(netdev
->dev_addr
, addr
->sa_data
)) {
1491 netdev_info(netdev
, "already using mac address %pM\n",
1496 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
1497 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
1498 return -EADDRNOTAVAIL
;
1500 if (ether_addr_equal(hw
->mac
.addr
, addr
->sa_data
))
1501 netdev_info(netdev
, "returning to hw mac address %pM\n",
1504 netdev_info(netdev
, "set new mac address %pM\n", addr
->sa_data
);
1506 if (vsi
->type
== I40E_VSI_MAIN
) {
1509 ret
= i40e_aq_mac_address_write(&vsi
->back
->hw
,
1510 I40E_AQC_WRITE_TYPE_LAA_WOL
,
1511 addr
->sa_data
, NULL
);
1514 "Addr change for Main VSI failed: %d\n",
1516 return -EADDRNOTAVAIL
;
1520 if (ether_addr_equal(netdev
->dev_addr
, hw
->mac
.addr
)) {
1521 struct i40e_aqc_remove_macvlan_element_data element
;
1523 memset(&element
, 0, sizeof(element
));
1524 ether_addr_copy(element
.mac_addr
, netdev
->dev_addr
);
1525 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
1526 i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1528 spin_lock_bh(&vsi
->mac_filter_list_lock
);
1529 i40e_del_filter(vsi
, netdev
->dev_addr
, I40E_VLAN_ANY
,
1531 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
1534 if (ether_addr_equal(addr
->sa_data
, hw
->mac
.addr
)) {
1535 struct i40e_aqc_add_macvlan_element_data element
;
1537 memset(&element
, 0, sizeof(element
));
1538 ether_addr_copy(element
.mac_addr
, hw
->mac
.addr
);
1539 element
.flags
= cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
);
1540 i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1542 spin_lock_bh(&vsi
->mac_filter_list_lock
);
1543 f
= i40e_add_filter(vsi
, addr
->sa_data
, I40E_VLAN_ANY
,
1547 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
1550 i40e_sync_vsi_filters(vsi
, false);
1551 ether_addr_copy(netdev
->dev_addr
, addr
->sa_data
);
1557 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1558 * @vsi: the VSI being setup
1559 * @ctxt: VSI context structure
1560 * @enabled_tc: Enabled TCs bitmap
1561 * @is_add: True if called before Add VSI
1563 * Setup VSI queue mapping for enabled traffic classes.
1566 void i40e_vsi_setup_queue_map(struct i40e_vsi
*vsi
,
1567 struct i40e_vsi_context
*ctxt
,
1571 static void i40e_vsi_setup_queue_map(struct i40e_vsi
*vsi
,
1572 struct i40e_vsi_context
*ctxt
,
1577 struct i40e_pf
*pf
= vsi
->back
;
1587 sections
= I40E_AQ_VSI_PROP_QUEUE_MAP_VALID
;
1590 if (enabled_tc
&& (vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
1591 /* Find numtc from enabled TC bitmap */
1592 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1593 if (enabled_tc
& BIT_ULL(i
)) /* TC is enabled */
1597 dev_warn(&pf
->pdev
->dev
, "DCB is enabled but no TC enabled, forcing TC0\n");
1601 /* At least TC0 is enabled in case of non-DCB case */
1605 vsi
->tc_config
.numtc
= numtc
;
1606 vsi
->tc_config
.enabled_tc
= enabled_tc
? enabled_tc
: 1;
1607 /* Number of queues per enabled TC */
1608 /* In MFP case we can have a much lower count of MSIx
1609 * vectors available and so we need to lower the used
1612 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
1613 qcount
= min_t(int, vsi
->alloc_queue_pairs
, pf
->num_lan_msix
);
1615 qcount
= vsi
->alloc_queue_pairs
;
1616 num_tc_qps
= qcount
/ numtc
;
1617 num_tc_qps
= min_t(int, num_tc_qps
, i40e_pf_get_max_q_per_tc(pf
));
1619 /* Setup queue offset/count for all TCs for given VSI */
1620 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1621 /* See if the given TC is enabled for the given VSI */
1622 if (vsi
->tc_config
.enabled_tc
& BIT_ULL(i
)) {
1626 switch (vsi
->type
) {
1628 qcount
= min_t(int, pf
->rss_size
, num_tc_qps
);
1632 qcount
= num_tc_qps
;
1636 case I40E_VSI_SRIOV
:
1637 case I40E_VSI_VMDQ2
:
1639 qcount
= num_tc_qps
;
1643 vsi
->tc_config
.tc_info
[i
].qoffset
= offset
;
1644 vsi
->tc_config
.tc_info
[i
].qcount
= qcount
;
1646 /* find the next higher power-of-2 of num queue pairs */
1649 while (num_qps
&& (BIT_ULL(pow
) < qcount
)) {
1654 vsi
->tc_config
.tc_info
[i
].netdev_tc
= netdev_tc
++;
1656 (offset
<< I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT
) |
1657 (pow
<< I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT
);
1661 /* TC is not enabled so set the offset to
1662 * default queue and allocate one queue
1665 vsi
->tc_config
.tc_info
[i
].qoffset
= 0;
1666 vsi
->tc_config
.tc_info
[i
].qcount
= 1;
1667 vsi
->tc_config
.tc_info
[i
].netdev_tc
= 0;
1671 ctxt
->info
.tc_mapping
[i
] = cpu_to_le16(qmap
);
1674 /* Set actual Tx/Rx queue pairs */
1675 vsi
->num_queue_pairs
= offset
;
1676 if ((vsi
->type
== I40E_VSI_MAIN
) && (numtc
== 1)) {
1677 if (vsi
->req_queue_pairs
> 0)
1678 vsi
->num_queue_pairs
= vsi
->req_queue_pairs
;
1679 else if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
1680 vsi
->num_queue_pairs
= pf
->num_lan_msix
;
1683 /* Scheduler section valid can only be set for ADD VSI */
1685 sections
|= I40E_AQ_VSI_PROP_SCHED_VALID
;
1687 ctxt
->info
.up_enable_bits
= enabled_tc
;
1689 if (vsi
->type
== I40E_VSI_SRIOV
) {
1690 ctxt
->info
.mapping_flags
|=
1691 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG
);
1692 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
1693 ctxt
->info
.queue_mapping
[i
] =
1694 cpu_to_le16(vsi
->base_queue
+ i
);
1696 ctxt
->info
.mapping_flags
|=
1697 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG
);
1698 ctxt
->info
.queue_mapping
[0] = cpu_to_le16(vsi
->base_queue
);
1700 ctxt
->info
.valid_sections
|= cpu_to_le16(sections
);
1704 * i40e_set_rx_mode - NDO callback to set the netdev filters
1705 * @netdev: network interface device structure
1708 void i40e_set_rx_mode(struct net_device
*netdev
)
1710 static void i40e_set_rx_mode(struct net_device
*netdev
)
1713 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1714 struct i40e_mac_filter
*f
, *ftmp
;
1715 struct i40e_vsi
*vsi
= np
->vsi
;
1716 struct netdev_hw_addr
*uca
;
1717 struct netdev_hw_addr
*mca
;
1718 struct netdev_hw_addr
*ha
;
1720 spin_lock_bh(&vsi
->mac_filter_list_lock
);
1722 /* add addr if not already in the filter list */
1723 netdev_for_each_uc_addr(uca
, netdev
) {
1724 if (!i40e_find_mac(vsi
, uca
->addr
, false, true)) {
1725 if (i40e_is_vsi_in_vlan(vsi
))
1726 i40e_put_mac_in_vlan(vsi
, uca
->addr
,
1729 i40e_add_filter(vsi
, uca
->addr
, I40E_VLAN_ANY
,
1734 netdev_for_each_mc_addr(mca
, netdev
) {
1735 if (!i40e_find_mac(vsi
, mca
->addr
, false, true)) {
1736 if (i40e_is_vsi_in_vlan(vsi
))
1737 i40e_put_mac_in_vlan(vsi
, mca
->addr
,
1740 i40e_add_filter(vsi
, mca
->addr
, I40E_VLAN_ANY
,
1745 /* remove filter if not in netdev list */
1746 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1751 netdev_for_each_mc_addr(mca
, netdev
)
1752 if (ether_addr_equal(mca
->addr
, f
->macaddr
))
1753 goto bottom_of_search_loop
;
1755 netdev_for_each_uc_addr(uca
, netdev
)
1756 if (ether_addr_equal(uca
->addr
, f
->macaddr
))
1757 goto bottom_of_search_loop
;
1759 for_each_dev_addr(netdev
, ha
)
1760 if (ether_addr_equal(ha
->addr
, f
->macaddr
))
1761 goto bottom_of_search_loop
;
1763 /* f->macaddr wasn't found in uc, mc, or ha list so delete it */
1764 i40e_del_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
, false, true);
1766 bottom_of_search_loop
:
1769 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
1771 /* check for other flag changes */
1772 if (vsi
->current_netdev_flags
!= vsi
->netdev
->flags
) {
1773 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1774 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1779 * i40e_mac_filter_entry_clone - Clones a MAC filter entry
1780 * @src: source MAC filter entry to be clones
1782 * Returns the pointer to newly cloned MAC filter entry or NULL
1785 static struct i40e_mac_filter
*i40e_mac_filter_entry_clone(
1786 struct i40e_mac_filter
*src
)
1788 struct i40e_mac_filter
*f
;
1790 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
1795 INIT_LIST_HEAD(&f
->list
);
1801 * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
1802 * @vsi: pointer to vsi struct
1803 * @from: Pointer to list which contains MAC filter entries - changes to
1804 * those entries needs to be undone.
1806 * MAC filter entries from list were slated to be removed from device.
1808 static void i40e_undo_del_filter_entries(struct i40e_vsi
*vsi
,
1809 struct list_head
*from
)
1811 struct i40e_mac_filter
*f
, *ftmp
;
1813 list_for_each_entry_safe(f
, ftmp
, from
, list
) {
1815 /* Move the element back into MAC filter list*/
1816 list_move_tail(&f
->list
, &vsi
->mac_filter_list
);
1821 * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries
1822 * @vsi: pointer to vsi struct
1824 * MAC filter entries from list were slated to be added from device.
1826 static void i40e_undo_add_filter_entries(struct i40e_vsi
*vsi
)
1828 struct i40e_mac_filter
*f
, *ftmp
;
1830 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1831 if (!f
->changed
&& f
->counter
)
1837 * i40e_cleanup_add_list - Deletes the element from add list and release
1839 * @add_list: Pointer to list which contains MAC filter entries
1841 static void i40e_cleanup_add_list(struct list_head
*add_list
)
1843 struct i40e_mac_filter
*f
, *ftmp
;
1845 list_for_each_entry_safe(f
, ftmp
, add_list
, list
) {
1852 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
1853 * @vsi: ptr to the VSI
1854 * @grab_rtnl: whether RTNL needs to be grabbed
1856 * Push any outstanding VSI filter changes through the AdminQ.
1858 * Returns 0 or error value
1860 int i40e_sync_vsi_filters(struct i40e_vsi
*vsi
, bool grab_rtnl
)
1862 struct list_head tmp_del_list
, tmp_add_list
;
1863 struct i40e_mac_filter
*f
, *ftmp
, *fclone
;
1864 bool promisc_forced_on
= false;
1865 bool add_happened
= false;
1866 int filter_list_len
= 0;
1867 u32 changed_flags
= 0;
1868 bool err_cond
= false;
1869 i40e_status ret
= 0;
1876 /* empty array typed pointers, kcalloc later */
1877 struct i40e_aqc_add_macvlan_element_data
*add_list
;
1878 struct i40e_aqc_remove_macvlan_element_data
*del_list
;
1880 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &vsi
->state
))
1881 usleep_range(1000, 2000);
1885 changed_flags
= vsi
->current_netdev_flags
^ vsi
->netdev
->flags
;
1886 vsi
->current_netdev_flags
= vsi
->netdev
->flags
;
1889 INIT_LIST_HEAD(&tmp_del_list
);
1890 INIT_LIST_HEAD(&tmp_add_list
);
1892 if (vsi
->flags
& I40E_VSI_FLAG_FILTER_CHANGED
) {
1893 vsi
->flags
&= ~I40E_VSI_FLAG_FILTER_CHANGED
;
1895 spin_lock_bh(&vsi
->mac_filter_list_lock
);
1896 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1900 if (f
->counter
!= 0)
1904 /* Move the element into temporary del_list */
1905 list_move_tail(&f
->list
, &tmp_del_list
);
1908 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1912 if (f
->counter
== 0)
1916 /* Clone MAC filter entry and add into temporary list */
1917 fclone
= i40e_mac_filter_entry_clone(f
);
1922 list_add_tail(&fclone
->list
, &tmp_add_list
);
1925 /* if failed to clone MAC filter entry - undo */
1927 i40e_undo_del_filter_entries(vsi
, &tmp_del_list
);
1928 i40e_undo_add_filter_entries(vsi
);
1930 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
1933 i40e_cleanup_add_list(&tmp_add_list
);
1936 /* Now process 'del_list' outside the lock */
1937 if (!list_empty(&tmp_del_list
)) {
1938 filter_list_len
= pf
->hw
.aq
.asq_buf_size
/
1939 sizeof(struct i40e_aqc_remove_macvlan_element_data
);
1940 del_list
= kcalloc(filter_list_len
,
1941 sizeof(struct i40e_aqc_remove_macvlan_element_data
),
1944 i40e_cleanup_add_list(&tmp_add_list
);
1946 /* Undo VSI's MAC filter entry element updates */
1947 spin_lock_bh(&vsi
->mac_filter_list_lock
);
1948 i40e_undo_del_filter_entries(vsi
, &tmp_del_list
);
1949 i40e_undo_add_filter_entries(vsi
);
1950 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
1954 list_for_each_entry_safe(f
, ftmp
, &tmp_del_list
, list
) {
1957 /* add to delete list */
1958 ether_addr_copy(del_list
[num_del
].mac_addr
, f
->macaddr
);
1959 del_list
[num_del
].vlan_tag
=
1960 cpu_to_le16((u16
)(f
->vlan
==
1961 I40E_VLAN_ANY
? 0 : f
->vlan
));
1963 cmd_flags
|= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
1964 del_list
[num_del
].flags
= cmd_flags
;
1967 /* flush a full buffer */
1968 if (num_del
== filter_list_len
) {
1969 ret
= i40e_aq_remove_macvlan(&pf
->hw
,
1970 vsi
->seid
, del_list
, num_del
,
1972 aq_err
= pf
->hw
.aq
.asq_last_status
;
1974 memset(del_list
, 0, sizeof(*del_list
));
1976 if (ret
&& aq_err
!= I40E_AQ_RC_ENOENT
)
1977 dev_err(&pf
->pdev
->dev
,
1978 "ignoring delete macvlan error, err %s, aq_err %s while flushing a full buffer\n",
1979 i40e_stat_str(&pf
->hw
, ret
),
1980 i40e_aq_str(&pf
->hw
, aq_err
));
1982 /* Release memory for MAC filter entries which were
1983 * synced up with HW.
1990 ret
= i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
,
1991 del_list
, num_del
, NULL
);
1992 aq_err
= pf
->hw
.aq
.asq_last_status
;
1995 if (ret
&& aq_err
!= I40E_AQ_RC_ENOENT
)
1996 dev_info(&pf
->pdev
->dev
,
1997 "ignoring delete macvlan error, err %s aq_err %s\n",
1998 i40e_stat_str(&pf
->hw
, ret
),
1999 i40e_aq_str(&pf
->hw
, aq_err
));
2006 if (!list_empty(&tmp_add_list
)) {
2008 /* do all the adds now */
2009 filter_list_len
= pf
->hw
.aq
.asq_buf_size
/
2010 sizeof(struct i40e_aqc_add_macvlan_element_data
),
2011 add_list
= kcalloc(filter_list_len
,
2012 sizeof(struct i40e_aqc_add_macvlan_element_data
),
2015 /* Purge element from temporary lists */
2016 i40e_cleanup_add_list(&tmp_add_list
);
2018 /* Undo add filter entries from VSI MAC filter list */
2019 spin_lock_bh(&vsi
->mac_filter_list_lock
);
2020 i40e_undo_add_filter_entries(vsi
);
2021 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2025 list_for_each_entry_safe(f
, ftmp
, &tmp_add_list
, list
) {
2027 add_happened
= true;
2030 /* add to add array */
2031 ether_addr_copy(add_list
[num_add
].mac_addr
, f
->macaddr
);
2032 add_list
[num_add
].vlan_tag
=
2034 (u16
)(f
->vlan
== I40E_VLAN_ANY
? 0 : f
->vlan
));
2035 add_list
[num_add
].queue_number
= 0;
2037 cmd_flags
|= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
;
2038 add_list
[num_add
].flags
= cpu_to_le16(cmd_flags
);
2041 /* flush a full buffer */
2042 if (num_add
== filter_list_len
) {
2043 ret
= i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
,
2046 aq_err
= pf
->hw
.aq
.asq_last_status
;
2051 memset(add_list
, 0, sizeof(*add_list
));
2053 /* Entries from tmp_add_list were cloned from MAC
2054 * filter list, hence clean those cloned entries
2061 ret
= i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
,
2062 add_list
, num_add
, NULL
);
2063 aq_err
= pf
->hw
.aq
.asq_last_status
;
2069 if (add_happened
&& ret
&& aq_err
!= I40E_AQ_RC_EINVAL
) {
2070 dev_info(&pf
->pdev
->dev
,
2071 "add filter failed, err %s aq_err %s\n",
2072 i40e_stat_str(&pf
->hw
, ret
),
2073 i40e_aq_str(&pf
->hw
, aq_err
));
2074 if ((pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_ENOSPC
) &&
2075 !test_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
2077 promisc_forced_on
= true;
2078 set_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
2080 dev_info(&pf
->pdev
->dev
, "promiscuous mode forced on\n");
2085 /* check for changes in promiscuous modes */
2086 if (changed_flags
& IFF_ALLMULTI
) {
2087 bool cur_multipromisc
;
2089 cur_multipromisc
= !!(vsi
->current_netdev_flags
& IFF_ALLMULTI
);
2090 ret
= i40e_aq_set_vsi_multicast_promiscuous(&vsi
->back
->hw
,
2095 dev_info(&pf
->pdev
->dev
,
2096 "set multi promisc failed, err %s aq_err %s\n",
2097 i40e_stat_str(&pf
->hw
, ret
),
2098 i40e_aq_str(&pf
->hw
,
2099 pf
->hw
.aq
.asq_last_status
));
2101 if ((changed_flags
& IFF_PROMISC
) || promisc_forced_on
) {
2104 cur_promisc
= (!!(vsi
->current_netdev_flags
& IFF_PROMISC
) ||
2105 test_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
2107 if (vsi
->type
== I40E_VSI_MAIN
&& pf
->lan_veb
!= I40E_NO_VEB
) {
2108 /* set defport ON for Main VSI instead of true promisc
2109 * this way we will get all unicast/multicast and VLAN
2110 * promisc behavior but will not get VF or VMDq traffic
2111 * replicated on the Main VSI.
2113 if (pf
->cur_promisc
!= cur_promisc
) {
2114 pf
->cur_promisc
= cur_promisc
;
2116 i40e_do_reset_safe(pf
,
2117 BIT(__I40E_PF_RESET_REQUESTED
));
2120 BIT(__I40E_PF_RESET_REQUESTED
));
2123 ret
= i40e_aq_set_vsi_unicast_promiscuous(
2128 dev_info(&pf
->pdev
->dev
,
2129 "set unicast promisc failed, err %d, aq_err %d\n",
2130 ret
, pf
->hw
.aq
.asq_last_status
);
2131 ret
= i40e_aq_set_vsi_multicast_promiscuous(
2136 dev_info(&pf
->pdev
->dev
,
2137 "set multicast promisc failed, err %d, aq_err %d\n",
2138 ret
, pf
->hw
.aq
.asq_last_status
);
2140 ret
= i40e_aq_set_vsi_broadcast(&vsi
->back
->hw
,
2144 dev_info(&pf
->pdev
->dev
,
2145 "set brdcast promisc failed, err %s, aq_err %s\n",
2146 i40e_stat_str(&pf
->hw
, ret
),
2147 i40e_aq_str(&pf
->hw
,
2148 pf
->hw
.aq
.asq_last_status
));
2151 clear_bit(__I40E_CONFIG_BUSY
, &vsi
->state
);
2156 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
2157 * @pf: board private structure
2159 static void i40e_sync_filters_subtask(struct i40e_pf
*pf
)
2163 if (!pf
|| !(pf
->flags
& I40E_FLAG_FILTER_SYNC
))
2165 pf
->flags
&= ~I40E_FLAG_FILTER_SYNC
;
2167 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
2169 (pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_FILTER_CHANGED
))
2170 i40e_sync_vsi_filters(pf
->vsi
[v
], true);
2175 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
2176 * @netdev: network interface device structure
2177 * @new_mtu: new value for maximum frame size
2179 * Returns 0 on success, negative on failure
2181 static int i40e_change_mtu(struct net_device
*netdev
, int new_mtu
)
2183 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2184 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
2185 struct i40e_vsi
*vsi
= np
->vsi
;
2187 /* MTU < 68 is an error and causes problems on some kernels */
2188 if ((new_mtu
< 68) || (max_frame
> I40E_MAX_RXBUFFER
))
2191 netdev_info(netdev
, "changing MTU from %d to %d\n",
2192 netdev
->mtu
, new_mtu
);
2193 netdev
->mtu
= new_mtu
;
2194 if (netif_running(netdev
))
2195 i40e_vsi_reinit_locked(vsi
);
2201 * i40e_ioctl - Access the hwtstamp interface
2202 * @netdev: network interface device structure
2203 * @ifr: interface request data
2204 * @cmd: ioctl command
2206 int i40e_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
2208 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2209 struct i40e_pf
*pf
= np
->vsi
->back
;
2213 return i40e_ptp_get_ts_config(pf
, ifr
);
2215 return i40e_ptp_set_ts_config(pf
, ifr
);
2222 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
2223 * @vsi: the vsi being adjusted
2225 void i40e_vlan_stripping_enable(struct i40e_vsi
*vsi
)
2227 struct i40e_vsi_context ctxt
;
2230 if ((vsi
->info
.valid_sections
&
2231 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
2232 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_MODE_MASK
) == 0))
2233 return; /* already enabled */
2235 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2236 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
2237 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH
;
2239 ctxt
.seid
= vsi
->seid
;
2240 ctxt
.info
= vsi
->info
;
2241 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2243 dev_info(&vsi
->back
->pdev
->dev
,
2244 "update vlan stripping failed, err %s aq_err %s\n",
2245 i40e_stat_str(&vsi
->back
->hw
, ret
),
2246 i40e_aq_str(&vsi
->back
->hw
,
2247 vsi
->back
->hw
.aq
.asq_last_status
));
2252 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2253 * @vsi: the vsi being adjusted
2255 void i40e_vlan_stripping_disable(struct i40e_vsi
*vsi
)
2257 struct i40e_vsi_context ctxt
;
2260 if ((vsi
->info
.valid_sections
&
2261 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
2262 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_EMOD_MASK
) ==
2263 I40E_AQ_VSI_PVLAN_EMOD_MASK
))
2264 return; /* already disabled */
2266 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2267 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
2268 I40E_AQ_VSI_PVLAN_EMOD_NOTHING
;
2270 ctxt
.seid
= vsi
->seid
;
2271 ctxt
.info
= vsi
->info
;
2272 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2274 dev_info(&vsi
->back
->pdev
->dev
,
2275 "update vlan stripping failed, err %s aq_err %s\n",
2276 i40e_stat_str(&vsi
->back
->hw
, ret
),
2277 i40e_aq_str(&vsi
->back
->hw
,
2278 vsi
->back
->hw
.aq
.asq_last_status
));
2283 * i40e_vlan_rx_register - Setup or shutdown vlan offload
2284 * @netdev: network interface to be adjusted
2285 * @features: netdev features to test if VLAN offload is enabled or not
2287 static void i40e_vlan_rx_register(struct net_device
*netdev
, u32 features
)
2289 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2290 struct i40e_vsi
*vsi
= np
->vsi
;
2292 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
2293 i40e_vlan_stripping_enable(vsi
);
2295 i40e_vlan_stripping_disable(vsi
);
2299 * i40e_vsi_add_vlan - Add vsi membership for given vlan
2300 * @vsi: the vsi being configured
2301 * @vid: vlan id to be added (0 = untagged only , -1 = any)
2303 int i40e_vsi_add_vlan(struct i40e_vsi
*vsi
, s16 vid
)
2305 struct i40e_mac_filter
*f
, *add_f
;
2306 bool is_netdev
, is_vf
;
2308 is_vf
= (vsi
->type
== I40E_VSI_SRIOV
);
2309 is_netdev
= !!(vsi
->netdev
);
2311 /* Locked once because all functions invoked below iterates list*/
2312 spin_lock_bh(&vsi
->mac_filter_list_lock
);
2315 add_f
= i40e_add_filter(vsi
, vsi
->netdev
->dev_addr
, vid
,
2318 dev_info(&vsi
->back
->pdev
->dev
,
2319 "Could not add vlan filter %d for %pM\n",
2320 vid
, vsi
->netdev
->dev_addr
);
2321 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2326 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2327 add_f
= i40e_add_filter(vsi
, f
->macaddr
, vid
, is_vf
, is_netdev
);
2329 dev_info(&vsi
->back
->pdev
->dev
,
2330 "Could not add vlan filter %d for %pM\n",
2332 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2337 /* Now if we add a vlan tag, make sure to check if it is the first
2338 * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
2339 * with 0, so we now accept untagged and specified tagged traffic
2340 * (and not any taged and untagged)
2343 if (is_netdev
&& i40e_find_filter(vsi
, vsi
->netdev
->dev_addr
,
2345 is_vf
, is_netdev
)) {
2346 i40e_del_filter(vsi
, vsi
->netdev
->dev_addr
,
2347 I40E_VLAN_ANY
, is_vf
, is_netdev
);
2348 add_f
= i40e_add_filter(vsi
, vsi
->netdev
->dev_addr
, 0,
2351 dev_info(&vsi
->back
->pdev
->dev
,
2352 "Could not add filter 0 for %pM\n",
2353 vsi
->netdev
->dev_addr
);
2354 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2360 /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
2361 if (vid
> 0 && !vsi
->info
.pvid
) {
2362 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2363 if (!i40e_find_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2366 i40e_del_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2368 add_f
= i40e_add_filter(vsi
, f
->macaddr
,
2369 0, is_vf
, is_netdev
);
2371 dev_info(&vsi
->back
->pdev
->dev
,
2372 "Could not add filter 0 for %pM\n",
2374 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2380 /* Make sure to release before sync_vsi_filter because that
2381 * function will lock/unlock as necessary
2383 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2385 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
2386 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
2389 return i40e_sync_vsi_filters(vsi
, false);
2393 * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
2394 * @vsi: the vsi being configured
2395 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
2397 * Return: 0 on success or negative otherwise
2399 int i40e_vsi_kill_vlan(struct i40e_vsi
*vsi
, s16 vid
)
2401 struct net_device
*netdev
= vsi
->netdev
;
2402 struct i40e_mac_filter
*f
, *add_f
;
2403 bool is_vf
, is_netdev
;
2404 int filter_count
= 0;
2406 is_vf
= (vsi
->type
== I40E_VSI_SRIOV
);
2407 is_netdev
= !!(netdev
);
2409 /* Locked once because all functions invoked below iterates list */
2410 spin_lock_bh(&vsi
->mac_filter_list_lock
);
2413 i40e_del_filter(vsi
, netdev
->dev_addr
, vid
, is_vf
, is_netdev
);
2415 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
)
2416 i40e_del_filter(vsi
, f
->macaddr
, vid
, is_vf
, is_netdev
);
2418 /* go through all the filters for this VSI and if there is only
2419 * vid == 0 it means there are no other filters, so vid 0 must
2420 * be replaced with -1. This signifies that we should from now
2421 * on accept any traffic (with any tag present, or untagged)
2423 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2426 ether_addr_equal(netdev
->dev_addr
, f
->macaddr
))
2434 if (!filter_count
&& is_netdev
) {
2435 i40e_del_filter(vsi
, netdev
->dev_addr
, 0, is_vf
, is_netdev
);
2436 f
= i40e_add_filter(vsi
, netdev
->dev_addr
, I40E_VLAN_ANY
,
2439 dev_info(&vsi
->back
->pdev
->dev
,
2440 "Could not add filter %d for %pM\n",
2441 I40E_VLAN_ANY
, netdev
->dev_addr
);
2442 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2447 if (!filter_count
) {
2448 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2449 i40e_del_filter(vsi
, f
->macaddr
, 0, is_vf
, is_netdev
);
2450 add_f
= i40e_add_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2453 dev_info(&vsi
->back
->pdev
->dev
,
2454 "Could not add filter %d for %pM\n",
2455 I40E_VLAN_ANY
, f
->macaddr
);
2456 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2462 /* Make sure to release before sync_vsi_filter because that
2463 * function with lock/unlock as necessary
2465 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2467 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
2468 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
2471 return i40e_sync_vsi_filters(vsi
, false);
2475 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2476 * @netdev: network interface to be adjusted
2477 * @vid: vlan id to be added
2479 * net_device_ops implementation for adding vlan ids
2482 int i40e_vlan_rx_add_vid(struct net_device
*netdev
,
2483 __always_unused __be16 proto
, u16 vid
)
2485 static int i40e_vlan_rx_add_vid(struct net_device
*netdev
,
2486 __always_unused __be16 proto
, u16 vid
)
2489 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2490 struct i40e_vsi
*vsi
= np
->vsi
;
2496 netdev_info(netdev
, "adding %pM vid=%d\n", netdev
->dev_addr
, vid
);
2498 /* If the network stack called us with vid = 0 then
2499 * it is asking to receive priority tagged packets with
2500 * vlan id 0. Our HW receives them by default when configured
2501 * to receive untagged packets so there is no need to add an
2502 * extra filter for vlan 0 tagged packets.
2505 ret
= i40e_vsi_add_vlan(vsi
, vid
);
2507 if (!ret
&& (vid
< VLAN_N_VID
))
2508 set_bit(vid
, vsi
->active_vlans
);
2514 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2515 * @netdev: network interface to be adjusted
2516 * @vid: vlan id to be removed
2518 * net_device_ops implementation for removing vlan ids
2521 int i40e_vlan_rx_kill_vid(struct net_device
*netdev
,
2522 __always_unused __be16 proto
, u16 vid
)
2524 static int i40e_vlan_rx_kill_vid(struct net_device
*netdev
,
2525 __always_unused __be16 proto
, u16 vid
)
2528 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2529 struct i40e_vsi
*vsi
= np
->vsi
;
2531 netdev_info(netdev
, "removing %pM vid=%d\n", netdev
->dev_addr
, vid
);
2533 /* return code is ignored as there is nothing a user
2534 * can do about failure to remove and a log message was
2535 * already printed from the other function
2537 i40e_vsi_kill_vlan(vsi
, vid
);
2539 clear_bit(vid
, vsi
->active_vlans
);
2545 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2546 * @vsi: the vsi being brought back up
2548 static void i40e_restore_vlan(struct i40e_vsi
*vsi
)
2555 i40e_vlan_rx_register(vsi
->netdev
, vsi
->netdev
->features
);
2557 for_each_set_bit(vid
, vsi
->active_vlans
, VLAN_N_VID
)
2558 i40e_vlan_rx_add_vid(vsi
->netdev
, htons(ETH_P_8021Q
),
2563 * i40e_vsi_add_pvid - Add pvid for the VSI
2564 * @vsi: the vsi being adjusted
2565 * @vid: the vlan id to set as a PVID
2567 int i40e_vsi_add_pvid(struct i40e_vsi
*vsi
, u16 vid
)
2569 struct i40e_vsi_context ctxt
;
2572 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2573 vsi
->info
.pvid
= cpu_to_le16(vid
);
2574 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_TAGGED
|
2575 I40E_AQ_VSI_PVLAN_INSERT_PVID
|
2576 I40E_AQ_VSI_PVLAN_EMOD_STR
;
2578 ctxt
.seid
= vsi
->seid
;
2579 ctxt
.info
= vsi
->info
;
2580 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2582 dev_info(&vsi
->back
->pdev
->dev
,
2583 "add pvid failed, err %s aq_err %s\n",
2584 i40e_stat_str(&vsi
->back
->hw
, ret
),
2585 i40e_aq_str(&vsi
->back
->hw
,
2586 vsi
->back
->hw
.aq
.asq_last_status
));
2594 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2595 * @vsi: the vsi being adjusted
2597 * Just use the vlan_rx_register() service to put it back to normal
2599 void i40e_vsi_remove_pvid(struct i40e_vsi
*vsi
)
2601 i40e_vlan_stripping_disable(vsi
);
2607 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2608 * @vsi: ptr to the VSI
2610 * If this function returns with an error, then it's possible one or
2611 * more of the rings is populated (while the rest are not). It is the
2612 * callers duty to clean those orphaned rings.
2614 * Return 0 on success, negative on failure
2616 static int i40e_vsi_setup_tx_resources(struct i40e_vsi
*vsi
)
2620 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2621 err
= i40e_setup_tx_descriptors(vsi
->tx_rings
[i
]);
2627 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2628 * @vsi: ptr to the VSI
2630 * Free VSI's transmit software resources
2632 static void i40e_vsi_free_tx_resources(struct i40e_vsi
*vsi
)
2639 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2640 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
)
2641 i40e_free_tx_resources(vsi
->tx_rings
[i
]);
2645 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2646 * @vsi: ptr to the VSI
2648 * If this function returns with an error, then it's possible one or
2649 * more of the rings is populated (while the rest are not). It is the
2650 * callers duty to clean those orphaned rings.
2652 * Return 0 on success, negative on failure
2654 static int i40e_vsi_setup_rx_resources(struct i40e_vsi
*vsi
)
2658 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2659 err
= i40e_setup_rx_descriptors(vsi
->rx_rings
[i
]);
2661 i40e_fcoe_setup_ddp_resources(vsi
);
2667 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2668 * @vsi: ptr to the VSI
2670 * Free all receive software resources
2672 static void i40e_vsi_free_rx_resources(struct i40e_vsi
*vsi
)
2679 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2680 if (vsi
->rx_rings
[i
] && vsi
->rx_rings
[i
]->desc
)
2681 i40e_free_rx_resources(vsi
->rx_rings
[i
]);
2683 i40e_fcoe_free_ddp_resources(vsi
);
2688 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
2689 * @ring: The Tx ring to configure
2691 * This enables/disables XPS for a given Tx descriptor ring
2692 * based on the TCs enabled for the VSI that ring belongs to.
2694 static void i40e_config_xps_tx_ring(struct i40e_ring
*ring
)
2696 struct i40e_vsi
*vsi
= ring
->vsi
;
2699 if (!ring
->q_vector
|| !ring
->netdev
)
2702 /* Single TC mode enable XPS */
2703 if (vsi
->tc_config
.numtc
<= 1) {
2704 if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE
, &ring
->state
))
2705 netif_set_xps_queue(ring
->netdev
,
2706 &ring
->q_vector
->affinity_mask
,
2708 } else if (alloc_cpumask_var(&mask
, GFP_KERNEL
)) {
2709 /* Disable XPS to allow selection based on TC */
2710 bitmap_zero(cpumask_bits(mask
), nr_cpumask_bits
);
2711 netif_set_xps_queue(ring
->netdev
, mask
, ring
->queue_index
);
2712 free_cpumask_var(mask
);
2717 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2718 * @ring: The Tx ring to configure
2720 * Configure the Tx descriptor ring in the HMC context.
2722 static int i40e_configure_tx_ring(struct i40e_ring
*ring
)
2724 struct i40e_vsi
*vsi
= ring
->vsi
;
2725 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
2726 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2727 struct i40e_hmc_obj_txq tx_ctx
;
2728 i40e_status err
= 0;
2731 /* some ATR related tx ring init */
2732 if (vsi
->back
->flags
& I40E_FLAG_FD_ATR_ENABLED
) {
2733 ring
->atr_sample_rate
= vsi
->back
->atr_sample_rate
;
2734 ring
->atr_count
= 0;
2736 ring
->atr_sample_rate
= 0;
2740 i40e_config_xps_tx_ring(ring
);
2742 /* clear the context structure first */
2743 memset(&tx_ctx
, 0, sizeof(tx_ctx
));
2745 tx_ctx
.new_context
= 1;
2746 tx_ctx
.base
= (ring
->dma
/ 128);
2747 tx_ctx
.qlen
= ring
->count
;
2748 tx_ctx
.fd_ena
= !!(vsi
->back
->flags
& (I40E_FLAG_FD_SB_ENABLED
|
2749 I40E_FLAG_FD_ATR_ENABLED
));
2751 tx_ctx
.fc_ena
= (vsi
->type
== I40E_VSI_FCOE
);
2753 tx_ctx
.timesync_ena
= !!(vsi
->back
->flags
& I40E_FLAG_PTP
);
2754 /* FDIR VSI tx ring can still use RS bit and writebacks */
2755 if (vsi
->type
!= I40E_VSI_FDIR
)
2756 tx_ctx
.head_wb_ena
= 1;
2757 tx_ctx
.head_wb_addr
= ring
->dma
+
2758 (ring
->count
* sizeof(struct i40e_tx_desc
));
2760 /* As part of VSI creation/update, FW allocates certain
2761 * Tx arbitration queue sets for each TC enabled for
2762 * the VSI. The FW returns the handles to these queue
2763 * sets as part of the response buffer to Add VSI,
2764 * Update VSI, etc. AQ commands. It is expected that
2765 * these queue set handles be associated with the Tx
2766 * queues by the driver as part of the TX queue context
2767 * initialization. This has to be done regardless of
2768 * DCB as by default everything is mapped to TC0.
2770 tx_ctx
.rdylist
= le16_to_cpu(vsi
->info
.qs_handle
[ring
->dcb_tc
]);
2771 tx_ctx
.rdylist_act
= 0;
2773 /* clear the context in the HMC */
2774 err
= i40e_clear_lan_tx_queue_context(hw
, pf_q
);
2776 dev_info(&vsi
->back
->pdev
->dev
,
2777 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2778 ring
->queue_index
, pf_q
, err
);
2782 /* set the context in the HMC */
2783 err
= i40e_set_lan_tx_queue_context(hw
, pf_q
, &tx_ctx
);
2785 dev_info(&vsi
->back
->pdev
->dev
,
2786 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
2787 ring
->queue_index
, pf_q
, err
);
2791 /* Now associate this queue with this PCI function */
2792 if (vsi
->type
== I40E_VSI_VMDQ2
) {
2793 qtx_ctl
= I40E_QTX_CTL_VM_QUEUE
;
2794 qtx_ctl
|= ((vsi
->id
) << I40E_QTX_CTL_VFVM_INDX_SHIFT
) &
2795 I40E_QTX_CTL_VFVM_INDX_MASK
;
2797 qtx_ctl
= I40E_QTX_CTL_PF_QUEUE
;
2800 qtx_ctl
|= ((hw
->pf_id
<< I40E_QTX_CTL_PF_INDX_SHIFT
) &
2801 I40E_QTX_CTL_PF_INDX_MASK
);
2802 wr32(hw
, I40E_QTX_CTL(pf_q
), qtx_ctl
);
2805 /* cache tail off for easier writes later */
2806 ring
->tail
= hw
->hw_addr
+ I40E_QTX_TAIL(pf_q
);
2812 * i40e_configure_rx_ring - Configure a receive ring context
2813 * @ring: The Rx ring to configure
2815 * Configure the Rx descriptor ring in the HMC context.
2817 static int i40e_configure_rx_ring(struct i40e_ring
*ring
)
2819 struct i40e_vsi
*vsi
= ring
->vsi
;
2820 u32 chain_len
= vsi
->back
->hw
.func_caps
.rx_buf_chain_len
;
2821 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
2822 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2823 struct i40e_hmc_obj_rxq rx_ctx
;
2824 i40e_status err
= 0;
2828 /* clear the context structure first */
2829 memset(&rx_ctx
, 0, sizeof(rx_ctx
));
2831 ring
->rx_buf_len
= vsi
->rx_buf_len
;
2832 ring
->rx_hdr_len
= vsi
->rx_hdr_len
;
2834 rx_ctx
.dbuff
= ring
->rx_buf_len
>> I40E_RXQ_CTX_DBUFF_SHIFT
;
2835 rx_ctx
.hbuff
= ring
->rx_hdr_len
>> I40E_RXQ_CTX_HBUFF_SHIFT
;
2837 rx_ctx
.base
= (ring
->dma
/ 128);
2838 rx_ctx
.qlen
= ring
->count
;
2840 if (vsi
->back
->flags
& I40E_FLAG_16BYTE_RX_DESC_ENABLED
) {
2841 set_ring_16byte_desc_enabled(ring
);
2847 rx_ctx
.dtype
= vsi
->dtype
;
2849 set_ring_ps_enabled(ring
);
2850 rx_ctx
.hsplit_0
= I40E_RX_SPLIT_L2
|
2852 I40E_RX_SPLIT_TCP_UDP
|
2855 rx_ctx
.hsplit_0
= 0;
2858 rx_ctx
.rxmax
= min_t(u16
, vsi
->max_frame
,
2859 (chain_len
* ring
->rx_buf_len
));
2860 if (hw
->revision_id
== 0)
2861 rx_ctx
.lrxqthresh
= 0;
2863 rx_ctx
.lrxqthresh
= 2;
2864 rx_ctx
.crcstrip
= 1;
2866 /* this controls whether VLAN is stripped from inner headers */
2869 rx_ctx
.fc_ena
= (vsi
->type
== I40E_VSI_FCOE
);
2871 /* set the prefena field to 1 because the manual says to */
2874 /* clear the context in the HMC */
2875 err
= i40e_clear_lan_rx_queue_context(hw
, pf_q
);
2877 dev_info(&vsi
->back
->pdev
->dev
,
2878 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2879 ring
->queue_index
, pf_q
, err
);
2883 /* set the context in the HMC */
2884 err
= i40e_set_lan_rx_queue_context(hw
, pf_q
, &rx_ctx
);
2886 dev_info(&vsi
->back
->pdev
->dev
,
2887 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2888 ring
->queue_index
, pf_q
, err
);
2892 /* cache tail for quicker writes, and clear the reg before use */
2893 ring
->tail
= hw
->hw_addr
+ I40E_QRX_TAIL(pf_q
);
2894 writel(0, ring
->tail
);
2896 if (ring_is_ps_enabled(ring
)) {
2897 i40e_alloc_rx_headers(ring
);
2898 i40e_alloc_rx_buffers_ps(ring
, I40E_DESC_UNUSED(ring
));
2900 i40e_alloc_rx_buffers_1buf(ring
, I40E_DESC_UNUSED(ring
));
2907 * i40e_vsi_configure_tx - Configure the VSI for Tx
2908 * @vsi: VSI structure describing this set of rings and resources
2910 * Configure the Tx VSI for operation.
2912 static int i40e_vsi_configure_tx(struct i40e_vsi
*vsi
)
2917 for (i
= 0; (i
< vsi
->num_queue_pairs
) && !err
; i
++)
2918 err
= i40e_configure_tx_ring(vsi
->tx_rings
[i
]);
2924 * i40e_vsi_configure_rx - Configure the VSI for Rx
2925 * @vsi: the VSI being configured
2927 * Configure the Rx VSI for operation.
2929 static int i40e_vsi_configure_rx(struct i40e_vsi
*vsi
)
2934 if (vsi
->netdev
&& (vsi
->netdev
->mtu
> ETH_DATA_LEN
))
2935 vsi
->max_frame
= vsi
->netdev
->mtu
+ ETH_HLEN
2936 + ETH_FCS_LEN
+ VLAN_HLEN
;
2938 vsi
->max_frame
= I40E_RXBUFFER_2048
;
2940 /* figure out correct receive buffer length */
2941 switch (vsi
->back
->flags
& (I40E_FLAG_RX_1BUF_ENABLED
|
2942 I40E_FLAG_RX_PS_ENABLED
)) {
2943 case I40E_FLAG_RX_1BUF_ENABLED
:
2944 vsi
->rx_hdr_len
= 0;
2945 vsi
->rx_buf_len
= vsi
->max_frame
;
2946 vsi
->dtype
= I40E_RX_DTYPE_NO_SPLIT
;
2948 case I40E_FLAG_RX_PS_ENABLED
:
2949 vsi
->rx_hdr_len
= I40E_RX_HDR_SIZE
;
2950 vsi
->rx_buf_len
= I40E_RXBUFFER_2048
;
2951 vsi
->dtype
= I40E_RX_DTYPE_HEADER_SPLIT
;
2954 vsi
->rx_hdr_len
= I40E_RX_HDR_SIZE
;
2955 vsi
->rx_buf_len
= I40E_RXBUFFER_2048
;
2956 vsi
->dtype
= I40E_RX_DTYPE_SPLIT_ALWAYS
;
2961 /* setup rx buffer for FCoE */
2962 if ((vsi
->type
== I40E_VSI_FCOE
) &&
2963 (vsi
->back
->flags
& I40E_FLAG_FCOE_ENABLED
)) {
2964 vsi
->rx_hdr_len
= 0;
2965 vsi
->rx_buf_len
= I40E_RXBUFFER_3072
;
2966 vsi
->max_frame
= I40E_RXBUFFER_3072
;
2967 vsi
->dtype
= I40E_RX_DTYPE_NO_SPLIT
;
2970 #endif /* I40E_FCOE */
2971 /* round up for the chip's needs */
2972 vsi
->rx_hdr_len
= ALIGN(vsi
->rx_hdr_len
,
2973 BIT_ULL(I40E_RXQ_CTX_HBUFF_SHIFT
));
2974 vsi
->rx_buf_len
= ALIGN(vsi
->rx_buf_len
,
2975 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT
));
2977 /* set up individual rings */
2978 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2979 err
= i40e_configure_rx_ring(vsi
->rx_rings
[i
]);
2985 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
2986 * @vsi: ptr to the VSI
2988 static void i40e_vsi_config_dcb_rings(struct i40e_vsi
*vsi
)
2990 struct i40e_ring
*tx_ring
, *rx_ring
;
2991 u16 qoffset
, qcount
;
2994 if (!(vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
2995 /* Reset the TC information */
2996 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
2997 rx_ring
= vsi
->rx_rings
[i
];
2998 tx_ring
= vsi
->tx_rings
[i
];
2999 rx_ring
->dcb_tc
= 0;
3000 tx_ring
->dcb_tc
= 0;
3004 for (n
= 0; n
< I40E_MAX_TRAFFIC_CLASS
; n
++) {
3005 if (!(vsi
->tc_config
.enabled_tc
& BIT_ULL(n
)))
3008 qoffset
= vsi
->tc_config
.tc_info
[n
].qoffset
;
3009 qcount
= vsi
->tc_config
.tc_info
[n
].qcount
;
3010 for (i
= qoffset
; i
< (qoffset
+ qcount
); i
++) {
3011 rx_ring
= vsi
->rx_rings
[i
];
3012 tx_ring
= vsi
->tx_rings
[i
];
3013 rx_ring
->dcb_tc
= n
;
3014 tx_ring
->dcb_tc
= n
;
3020 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
3021 * @vsi: ptr to the VSI
3023 static void i40e_set_vsi_rx_mode(struct i40e_vsi
*vsi
)
3026 i40e_set_rx_mode(vsi
->netdev
);
3030 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
3031 * @vsi: Pointer to the targeted VSI
3033 * This function replays the hlist on the hw where all the SB Flow Director
3034 * filters were saved.
3036 static void i40e_fdir_filter_restore(struct i40e_vsi
*vsi
)
3038 struct i40e_fdir_filter
*filter
;
3039 struct i40e_pf
*pf
= vsi
->back
;
3040 struct hlist_node
*node
;
3042 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
3045 hlist_for_each_entry_safe(filter
, node
,
3046 &pf
->fdir_filter_list
, fdir_node
) {
3047 i40e_add_del_fdir(vsi
, filter
, true);
3052 * i40e_vsi_configure - Set up the VSI for action
3053 * @vsi: the VSI being configured
3055 static int i40e_vsi_configure(struct i40e_vsi
*vsi
)
3059 i40e_set_vsi_rx_mode(vsi
);
3060 i40e_restore_vlan(vsi
);
3061 i40e_vsi_config_dcb_rings(vsi
);
3062 err
= i40e_vsi_configure_tx(vsi
);
3064 err
= i40e_vsi_configure_rx(vsi
);
3070 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
3071 * @vsi: the VSI being configured
3073 static void i40e_vsi_configure_msix(struct i40e_vsi
*vsi
)
3075 struct i40e_pf
*pf
= vsi
->back
;
3076 struct i40e_hw
*hw
= &pf
->hw
;
3081 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
3082 * and PFINT_LNKLSTn registers, e.g.:
3083 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
3085 qp
= vsi
->base_queue
;
3086 vector
= vsi
->base_vector
;
3087 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vector
++) {
3088 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[i
];
3090 q_vector
->itr_countdown
= ITR_COUNTDOWN_START
;
3091 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
3092 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
3093 wr32(hw
, I40E_PFINT_ITRN(I40E_RX_ITR
, vector
- 1),
3095 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
3096 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
3097 wr32(hw
, I40E_PFINT_ITRN(I40E_TX_ITR
, vector
- 1),
3099 wr32(hw
, I40E_PFINT_RATEN(vector
- 1),
3100 INTRL_USEC_TO_REG(vsi
->int_rate_limit
));
3102 /* Linked list for the queuepairs assigned to this vector */
3103 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), qp
);
3104 for (q
= 0; q
< q_vector
->num_ringpairs
; q
++) {
3107 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3108 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
3109 (vector
<< I40E_QINT_RQCTL_MSIX_INDX_SHIFT
) |
3110 (qp
<< I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT
)|
3112 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT
);
3114 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
3116 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3117 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
3118 (vector
<< I40E_QINT_TQCTL_MSIX_INDX_SHIFT
) |
3119 ((qp
+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
)|
3121 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
3123 /* Terminate the linked list */
3124 if (q
== (q_vector
->num_ringpairs
- 1))
3125 val
|= (I40E_QUEUE_END_OF_LIST
3126 << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
3128 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
3137 * i40e_enable_misc_int_causes - enable the non-queue interrupts
3138 * @hw: ptr to the hardware info
3140 static void i40e_enable_misc_int_causes(struct i40e_pf
*pf
)
3142 struct i40e_hw
*hw
= &pf
->hw
;
3145 /* clear things first */
3146 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0); /* disable all */
3147 rd32(hw
, I40E_PFINT_ICR0
); /* read to clear */
3149 val
= I40E_PFINT_ICR0_ENA_ECC_ERR_MASK
|
3150 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
|
3151 I40E_PFINT_ICR0_ENA_GRST_MASK
|
3152 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK
|
3153 I40E_PFINT_ICR0_ENA_GPIO_MASK
|
3154 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK
|
3155 I40E_PFINT_ICR0_ENA_VFLR_MASK
|
3156 I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
3158 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
)
3159 val
|= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
;
3161 if (pf
->flags
& I40E_FLAG_PTP
)
3162 val
|= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
3164 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
3166 /* SW_ITR_IDX = 0, but don't change INTENA */
3167 wr32(hw
, I40E_PFINT_DYN_CTL0
, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK
|
3168 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK
);
3170 /* OTHER_ITR_IDX = 0 */
3171 wr32(hw
, I40E_PFINT_STAT_CTL0
, 0);
3175 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
3176 * @vsi: the VSI being configured
3178 static void i40e_configure_msi_and_legacy(struct i40e_vsi
*vsi
)
3180 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[0];
3181 struct i40e_pf
*pf
= vsi
->back
;
3182 struct i40e_hw
*hw
= &pf
->hw
;
3185 /* set the ITR configuration */
3186 q_vector
->itr_countdown
= ITR_COUNTDOWN_START
;
3187 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
3188 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
3189 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), q_vector
->rx
.itr
);
3190 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
3191 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
3192 wr32(hw
, I40E_PFINT_ITR0(I40E_TX_ITR
), q_vector
->tx
.itr
);
3194 i40e_enable_misc_int_causes(pf
);
3196 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
3197 wr32(hw
, I40E_PFINT_LNKLST0
, 0);
3199 /* Associate the queue pair to the vector and enable the queue int */
3200 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3201 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
3202 (I40E_QUEUE_TYPE_TX
<< I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
3204 wr32(hw
, I40E_QINT_RQCTL(0), val
);
3206 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3207 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
3208 (I40E_QUEUE_END_OF_LIST
<< I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
3210 wr32(hw
, I40E_QINT_TQCTL(0), val
);
3215 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
3216 * @pf: board private structure
3218 void i40e_irq_dynamic_disable_icr0(struct i40e_pf
*pf
)
3220 struct i40e_hw
*hw
= &pf
->hw
;
3222 wr32(hw
, I40E_PFINT_DYN_CTL0
,
3223 I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
);
3228 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
3229 * @pf: board private structure
3231 void i40e_irq_dynamic_enable_icr0(struct i40e_pf
*pf
)
3233 struct i40e_hw
*hw
= &pf
->hw
;
3236 val
= I40E_PFINT_DYN_CTL0_INTENA_MASK
|
3237 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK
|
3238 (I40E_ITR_NONE
<< I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT
);
3240 wr32(hw
, I40E_PFINT_DYN_CTL0
, val
);
3245 * i40e_irq_dynamic_disable - Disable default interrupt generation settings
3246 * @vsi: pointer to a vsi
3247 * @vector: disable a particular Hw Interrupt vector
3249 void i40e_irq_dynamic_disable(struct i40e_vsi
*vsi
, int vector
)
3251 struct i40e_pf
*pf
= vsi
->back
;
3252 struct i40e_hw
*hw
= &pf
->hw
;
3255 val
= I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
;
3256 wr32(hw
, I40E_PFINT_DYN_CTLN(vector
- 1), val
);
3261 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
3262 * @irq: interrupt number
3263 * @data: pointer to a q_vector
3265 static irqreturn_t
i40e_msix_clean_rings(int irq
, void *data
)
3267 struct i40e_q_vector
*q_vector
= data
;
3269 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
3272 napi_schedule_irqoff(&q_vector
->napi
);
3278 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3279 * @vsi: the VSI being configured
3280 * @basename: name for the vector
3282 * Allocates MSI-X vectors and requests interrupts from the kernel.
3284 static int i40e_vsi_request_irq_msix(struct i40e_vsi
*vsi
, char *basename
)
3286 int q_vectors
= vsi
->num_q_vectors
;
3287 struct i40e_pf
*pf
= vsi
->back
;
3288 int base
= vsi
->base_vector
;
3293 for (vector
= 0; vector
< q_vectors
; vector
++) {
3294 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[vector
];
3296 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
3297 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3298 "%s-%s-%d", basename
, "TxRx", rx_int_idx
++);
3300 } else if (q_vector
->rx
.ring
) {
3301 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3302 "%s-%s-%d", basename
, "rx", rx_int_idx
++);
3303 } else if (q_vector
->tx
.ring
) {
3304 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3305 "%s-%s-%d", basename
, "tx", tx_int_idx
++);
3307 /* skip this unused q_vector */
3310 err
= request_irq(pf
->msix_entries
[base
+ vector
].vector
,
3316 dev_info(&pf
->pdev
->dev
,
3317 "MSIX request_irq failed, error: %d\n", err
);
3318 goto free_queue_irqs
;
3320 /* assign the mask for this irq */
3321 irq_set_affinity_hint(pf
->msix_entries
[base
+ vector
].vector
,
3322 &q_vector
->affinity_mask
);
3325 vsi
->irqs_ready
= true;
3331 irq_set_affinity_hint(pf
->msix_entries
[base
+ vector
].vector
,
3333 free_irq(pf
->msix_entries
[base
+ vector
].vector
,
3334 &(vsi
->q_vectors
[vector
]));
3340 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3341 * @vsi: the VSI being un-configured
3343 static void i40e_vsi_disable_irq(struct i40e_vsi
*vsi
)
3345 struct i40e_pf
*pf
= vsi
->back
;
3346 struct i40e_hw
*hw
= &pf
->hw
;
3347 int base
= vsi
->base_vector
;
3350 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
3351 wr32(hw
, I40E_QINT_TQCTL(vsi
->tx_rings
[i
]->reg_idx
), 0);
3352 wr32(hw
, I40E_QINT_RQCTL(vsi
->rx_rings
[i
]->reg_idx
), 0);
3355 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3356 for (i
= vsi
->base_vector
;
3357 i
< (vsi
->num_q_vectors
+ vsi
->base_vector
); i
++)
3358 wr32(hw
, I40E_PFINT_DYN_CTLN(i
- 1), 0);
3361 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3362 synchronize_irq(pf
->msix_entries
[i
+ base
].vector
);
3364 /* Legacy and MSI mode - this stops all interrupt handling */
3365 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0);
3366 wr32(hw
, I40E_PFINT_DYN_CTL0
, 0);
3368 synchronize_irq(pf
->pdev
->irq
);
3373 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3374 * @vsi: the VSI being configured
3376 static int i40e_vsi_enable_irq(struct i40e_vsi
*vsi
)
3378 struct i40e_pf
*pf
= vsi
->back
;
3381 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3382 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3383 i40e_irq_dynamic_enable(vsi
, i
);
3385 i40e_irq_dynamic_enable_icr0(pf
);
3388 i40e_flush(&pf
->hw
);
3393 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
3394 * @pf: board private structure
3396 static void i40e_stop_misc_vector(struct i40e_pf
*pf
)
3399 wr32(&pf
->hw
, I40E_PFINT_ICR0_ENA
, 0);
3400 i40e_flush(&pf
->hw
);
3404 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3405 * @irq: interrupt number
3406 * @data: pointer to a q_vector
3408 * This is the handler used for all MSI/Legacy interrupts, and deals
3409 * with both queue and non-queue interrupts. This is also used in
3410 * MSIX mode to handle the non-queue interrupts.
3412 static irqreturn_t
i40e_intr(int irq
, void *data
)
3414 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
3415 struct i40e_hw
*hw
= &pf
->hw
;
3416 irqreturn_t ret
= IRQ_NONE
;
3417 u32 icr0
, icr0_remaining
;
3420 icr0
= rd32(hw
, I40E_PFINT_ICR0
);
3421 ena_mask
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
3423 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
3424 if ((icr0
& I40E_PFINT_ICR0_INTEVENT_MASK
) == 0)
3427 /* if interrupt but no bits showing, must be SWINT */
3428 if (((icr0
& ~I40E_PFINT_ICR0_INTEVENT_MASK
) == 0) ||
3429 (icr0
& I40E_PFINT_ICR0_SWINT_MASK
))
3432 if ((pf
->flags
& I40E_FLAG_IWARP_ENABLED
) &&
3433 (ena_mask
& I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
)) {
3434 ena_mask
&= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
;
3435 icr0
&= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
;
3436 dev_info(&pf
->pdev
->dev
, "cleared PE_CRITERR\n");
3439 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
3440 if (icr0
& I40E_PFINT_ICR0_QUEUE_0_MASK
) {
3441 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
3442 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[0];
3444 /* temporarily disable queue cause for NAPI processing */
3445 u32 qval
= rd32(hw
, I40E_QINT_RQCTL(0));
3447 qval
&= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK
;
3448 wr32(hw
, I40E_QINT_RQCTL(0), qval
);
3450 qval
= rd32(hw
, I40E_QINT_TQCTL(0));
3451 qval
&= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK
;
3452 wr32(hw
, I40E_QINT_TQCTL(0), qval
);
3454 if (!test_bit(__I40E_DOWN
, &pf
->state
))
3455 napi_schedule_irqoff(&q_vector
->napi
);
3458 if (icr0
& I40E_PFINT_ICR0_ADMINQ_MASK
) {
3459 ena_mask
&= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
3460 set_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
);
3463 if (icr0
& I40E_PFINT_ICR0_MAL_DETECT_MASK
) {
3464 ena_mask
&= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
3465 set_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
);
3468 if (icr0
& I40E_PFINT_ICR0_VFLR_MASK
) {
3469 ena_mask
&= ~I40E_PFINT_ICR0_ENA_VFLR_MASK
;
3470 set_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
);
3473 if (icr0
& I40E_PFINT_ICR0_GRST_MASK
) {
3474 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
))
3475 set_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
);
3476 ena_mask
&= ~I40E_PFINT_ICR0_ENA_GRST_MASK
;
3477 val
= rd32(hw
, I40E_GLGEN_RSTAT
);
3478 val
= (val
& I40E_GLGEN_RSTAT_RESET_TYPE_MASK
)
3479 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT
;
3480 if (val
== I40E_RESET_CORER
) {
3482 } else if (val
== I40E_RESET_GLOBR
) {
3484 } else if (val
== I40E_RESET_EMPR
) {
3486 set_bit(__I40E_EMP_RESET_INTR_RECEIVED
, &pf
->state
);
3490 if (icr0
& I40E_PFINT_ICR0_HMC_ERR_MASK
) {
3491 icr0
&= ~I40E_PFINT_ICR0_HMC_ERR_MASK
;
3492 dev_info(&pf
->pdev
->dev
, "HMC error interrupt\n");
3493 dev_info(&pf
->pdev
->dev
, "HMC error info 0x%x, HMC error data 0x%x\n",
3494 rd32(hw
, I40E_PFHMC_ERRORINFO
),
3495 rd32(hw
, I40E_PFHMC_ERRORDATA
));
3498 if (icr0
& I40E_PFINT_ICR0_TIMESYNC_MASK
) {
3499 u32 prttsyn_stat
= rd32(hw
, I40E_PRTTSYN_STAT_0
);
3501 if (prttsyn_stat
& I40E_PRTTSYN_STAT_0_TXTIME_MASK
) {
3502 icr0
&= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
3503 i40e_ptp_tx_hwtstamp(pf
);
3507 /* If a critical error is pending we have no choice but to reset the
3509 * Report and mask out any remaining unexpected interrupts.
3511 icr0_remaining
= icr0
& ena_mask
;
3512 if (icr0_remaining
) {
3513 dev_info(&pf
->pdev
->dev
, "unhandled interrupt icr0=0x%08x\n",
3515 if ((icr0_remaining
& I40E_PFINT_ICR0_PE_CRITERR_MASK
) ||
3516 (icr0_remaining
& I40E_PFINT_ICR0_PCI_EXCEPTION_MASK
) ||
3517 (icr0_remaining
& I40E_PFINT_ICR0_ECC_ERR_MASK
)) {
3518 dev_info(&pf
->pdev
->dev
, "device will be reset\n");
3519 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
3520 i40e_service_event_schedule(pf
);
3522 ena_mask
&= ~icr0_remaining
;
3527 /* re-enable interrupt causes */
3528 wr32(hw
, I40E_PFINT_ICR0_ENA
, ena_mask
);
3529 if (!test_bit(__I40E_DOWN
, &pf
->state
)) {
3530 i40e_service_event_schedule(pf
);
3531 i40e_irq_dynamic_enable_icr0(pf
);
3538 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3539 * @tx_ring: tx ring to clean
3540 * @budget: how many cleans we're allowed
3542 * Returns true if there's any budget left (e.g. the clean is finished)
3544 static bool i40e_clean_fdir_tx_irq(struct i40e_ring
*tx_ring
, int budget
)
3546 struct i40e_vsi
*vsi
= tx_ring
->vsi
;
3547 u16 i
= tx_ring
->next_to_clean
;
3548 struct i40e_tx_buffer
*tx_buf
;
3549 struct i40e_tx_desc
*tx_desc
;
3551 tx_buf
= &tx_ring
->tx_bi
[i
];
3552 tx_desc
= I40E_TX_DESC(tx_ring
, i
);
3553 i
-= tx_ring
->count
;
3556 struct i40e_tx_desc
*eop_desc
= tx_buf
->next_to_watch
;
3558 /* if next_to_watch is not set then there is no work pending */
3562 /* prevent any other reads prior to eop_desc */
3563 read_barrier_depends();
3565 /* if the descriptor isn't done, no work yet to do */
3566 if (!(eop_desc
->cmd_type_offset_bsz
&
3567 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE
)))
3570 /* clear next_to_watch to prevent false hangs */
3571 tx_buf
->next_to_watch
= NULL
;
3573 tx_desc
->buffer_addr
= 0;
3574 tx_desc
->cmd_type_offset_bsz
= 0;
3575 /* move past filter desc */
3580 i
-= tx_ring
->count
;
3581 tx_buf
= tx_ring
->tx_bi
;
3582 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
3584 /* unmap skb header data */
3585 dma_unmap_single(tx_ring
->dev
,
3586 dma_unmap_addr(tx_buf
, dma
),
3587 dma_unmap_len(tx_buf
, len
),
3589 if (tx_buf
->tx_flags
& I40E_TX_FLAGS_FD_SB
)
3590 kfree(tx_buf
->raw_buf
);
3592 tx_buf
->raw_buf
= NULL
;
3593 tx_buf
->tx_flags
= 0;
3594 tx_buf
->next_to_watch
= NULL
;
3595 dma_unmap_len_set(tx_buf
, len
, 0);
3596 tx_desc
->buffer_addr
= 0;
3597 tx_desc
->cmd_type_offset_bsz
= 0;
3599 /* move us past the eop_desc for start of next FD desc */
3604 i
-= tx_ring
->count
;
3605 tx_buf
= tx_ring
->tx_bi
;
3606 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
3609 /* update budget accounting */
3611 } while (likely(budget
));
3613 i
+= tx_ring
->count
;
3614 tx_ring
->next_to_clean
= i
;
3616 if (vsi
->back
->flags
& I40E_FLAG_MSIX_ENABLED
)
3617 i40e_irq_dynamic_enable(vsi
, tx_ring
->q_vector
->v_idx
);
3623 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
3624 * @irq: interrupt number
3625 * @data: pointer to a q_vector
3627 static irqreturn_t
i40e_fdir_clean_ring(int irq
, void *data
)
3629 struct i40e_q_vector
*q_vector
= data
;
3630 struct i40e_vsi
*vsi
;
3632 if (!q_vector
->tx
.ring
)
3635 vsi
= q_vector
->tx
.ring
->vsi
;
3636 i40e_clean_fdir_tx_irq(q_vector
->tx
.ring
, vsi
->work_limit
);
3642 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
3643 * @vsi: the VSI being configured
3644 * @v_idx: vector index
3645 * @qp_idx: queue pair index
3647 static void i40e_map_vector_to_qp(struct i40e_vsi
*vsi
, int v_idx
, int qp_idx
)
3649 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
3650 struct i40e_ring
*tx_ring
= vsi
->tx_rings
[qp_idx
];
3651 struct i40e_ring
*rx_ring
= vsi
->rx_rings
[qp_idx
];
3653 tx_ring
->q_vector
= q_vector
;
3654 tx_ring
->next
= q_vector
->tx
.ring
;
3655 q_vector
->tx
.ring
= tx_ring
;
3656 q_vector
->tx
.count
++;
3658 rx_ring
->q_vector
= q_vector
;
3659 rx_ring
->next
= q_vector
->rx
.ring
;
3660 q_vector
->rx
.ring
= rx_ring
;
3661 q_vector
->rx
.count
++;
3665 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
3666 * @vsi: the VSI being configured
3668 * This function maps descriptor rings to the queue-specific vectors
3669 * we were allotted through the MSI-X enabling code. Ideally, we'd have
3670 * one vector per queue pair, but on a constrained vector budget, we
3671 * group the queue pairs as "efficiently" as possible.
3673 static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi
*vsi
)
3675 int qp_remaining
= vsi
->num_queue_pairs
;
3676 int q_vectors
= vsi
->num_q_vectors
;
3681 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
3682 * group them so there are multiple queues per vector.
3683 * It is also important to go through all the vectors available to be
3684 * sure that if we don't use all the vectors, that the remaining vectors
3685 * are cleared. This is especially important when decreasing the
3686 * number of queues in use.
3688 for (; v_start
< q_vectors
; v_start
++) {
3689 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_start
];
3691 num_ringpairs
= DIV_ROUND_UP(qp_remaining
, q_vectors
- v_start
);
3693 q_vector
->num_ringpairs
= num_ringpairs
;
3695 q_vector
->rx
.count
= 0;
3696 q_vector
->tx
.count
= 0;
3697 q_vector
->rx
.ring
= NULL
;
3698 q_vector
->tx
.ring
= NULL
;
3700 while (num_ringpairs
--) {
3701 i40e_map_vector_to_qp(vsi
, v_start
, qp_idx
);
3709 * i40e_vsi_request_irq - Request IRQ from the OS
3710 * @vsi: the VSI being configured
3711 * @basename: name for the vector
3713 static int i40e_vsi_request_irq(struct i40e_vsi
*vsi
, char *basename
)
3715 struct i40e_pf
*pf
= vsi
->back
;
3718 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
3719 err
= i40e_vsi_request_irq_msix(vsi
, basename
);
3720 else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
)
3721 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, 0,
3724 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, IRQF_SHARED
,
3728 dev_info(&pf
->pdev
->dev
, "request_irq failed, Error %d\n", err
);
3733 #ifdef CONFIG_NET_POLL_CONTROLLER
3735 * i40e_netpoll - A Polling 'interrupt'handler
3736 * @netdev: network interface device structure
3738 * This is used by netconsole to send skbs without having to re-enable
3739 * interrupts. It's not called while the normal interrupt routine is executing.
3742 void i40e_netpoll(struct net_device
*netdev
)
3744 static void i40e_netpoll(struct net_device
*netdev
)
3747 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3748 struct i40e_vsi
*vsi
= np
->vsi
;
3749 struct i40e_pf
*pf
= vsi
->back
;
3752 /* if interface is down do nothing */
3753 if (test_bit(__I40E_DOWN
, &vsi
->state
))
3756 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3757 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3758 i40e_msix_clean_rings(0, vsi
->q_vectors
[i
]);
3760 i40e_intr(pf
->pdev
->irq
, netdev
);
3766 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
3767 * @pf: the PF being configured
3768 * @pf_q: the PF queue
3769 * @enable: enable or disable state of the queue
3771 * This routine will wait for the given Tx queue of the PF to reach the
3772 * enabled or disabled state.
3773 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3774 * multiple retries; else will return 0 in case of success.
3776 static int i40e_pf_txq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
3781 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
3782 tx_reg
= rd32(&pf
->hw
, I40E_QTX_ENA(pf_q
));
3783 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
3786 usleep_range(10, 20);
3788 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
3795 * i40e_vsi_control_tx - Start or stop a VSI's rings
3796 * @vsi: the VSI being configured
3797 * @enable: start or stop the rings
3799 static int i40e_vsi_control_tx(struct i40e_vsi
*vsi
, bool enable
)
3801 struct i40e_pf
*pf
= vsi
->back
;
3802 struct i40e_hw
*hw
= &pf
->hw
;
3803 int i
, j
, pf_q
, ret
= 0;
3806 pf_q
= vsi
->base_queue
;
3807 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
3809 /* warn the TX unit of coming changes */
3810 i40e_pre_tx_queue_cfg(&pf
->hw
, pf_q
, enable
);
3812 usleep_range(10, 20);
3814 for (j
= 0; j
< 50; j
++) {
3815 tx_reg
= rd32(hw
, I40E_QTX_ENA(pf_q
));
3816 if (((tx_reg
>> I40E_QTX_ENA_QENA_REQ_SHIFT
) & 1) ==
3817 ((tx_reg
>> I40E_QTX_ENA_QENA_STAT_SHIFT
) & 1))
3819 usleep_range(1000, 2000);
3821 /* Skip if the queue is already in the requested state */
3822 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
3825 /* turn on/off the queue */
3827 wr32(hw
, I40E_QTX_HEAD(pf_q
), 0);
3828 tx_reg
|= I40E_QTX_ENA_QENA_REQ_MASK
;
3830 tx_reg
&= ~I40E_QTX_ENA_QENA_REQ_MASK
;
3833 wr32(hw
, I40E_QTX_ENA(pf_q
), tx_reg
);
3834 /* No waiting for the Tx queue to disable */
3835 if (!enable
&& test_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
))
3838 /* wait for the change to finish */
3839 ret
= i40e_pf_txq_wait(pf
, pf_q
, enable
);
3841 dev_info(&pf
->pdev
->dev
,
3842 "VSI seid %d Tx ring %d %sable timeout\n",
3843 vsi
->seid
, pf_q
, (enable
? "en" : "dis"));
3848 if (hw
->revision_id
== 0)
3854 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
3855 * @pf: the PF being configured
3856 * @pf_q: the PF queue
3857 * @enable: enable or disable state of the queue
3859 * This routine will wait for the given Rx queue of the PF to reach the
3860 * enabled or disabled state.
3861 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3862 * multiple retries; else will return 0 in case of success.
3864 static int i40e_pf_rxq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
3869 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
3870 rx_reg
= rd32(&pf
->hw
, I40E_QRX_ENA(pf_q
));
3871 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
3874 usleep_range(10, 20);
3876 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
3883 * i40e_vsi_control_rx - Start or stop a VSI's rings
3884 * @vsi: the VSI being configured
3885 * @enable: start or stop the rings
3887 static int i40e_vsi_control_rx(struct i40e_vsi
*vsi
, bool enable
)
3889 struct i40e_pf
*pf
= vsi
->back
;
3890 struct i40e_hw
*hw
= &pf
->hw
;
3891 int i
, j
, pf_q
, ret
= 0;
3894 pf_q
= vsi
->base_queue
;
3895 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
3896 for (j
= 0; j
< 50; j
++) {
3897 rx_reg
= rd32(hw
, I40E_QRX_ENA(pf_q
));
3898 if (((rx_reg
>> I40E_QRX_ENA_QENA_REQ_SHIFT
) & 1) ==
3899 ((rx_reg
>> I40E_QRX_ENA_QENA_STAT_SHIFT
) & 1))
3901 usleep_range(1000, 2000);
3904 /* Skip if the queue is already in the requested state */
3905 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
3908 /* turn on/off the queue */
3910 rx_reg
|= I40E_QRX_ENA_QENA_REQ_MASK
;
3912 rx_reg
&= ~I40E_QRX_ENA_QENA_REQ_MASK
;
3913 wr32(hw
, I40E_QRX_ENA(pf_q
), rx_reg
);
3915 /* wait for the change to finish */
3916 ret
= i40e_pf_rxq_wait(pf
, pf_q
, enable
);
3918 dev_info(&pf
->pdev
->dev
,
3919 "VSI seid %d Rx ring %d %sable timeout\n",
3920 vsi
->seid
, pf_q
, (enable
? "en" : "dis"));
3929 * i40e_vsi_control_rings - Start or stop a VSI's rings
3930 * @vsi: the VSI being configured
3931 * @enable: start or stop the rings
3933 int i40e_vsi_control_rings(struct i40e_vsi
*vsi
, bool request
)
3937 /* do rx first for enable and last for disable */
3939 ret
= i40e_vsi_control_rx(vsi
, request
);
3942 ret
= i40e_vsi_control_tx(vsi
, request
);
3944 /* Ignore return value, we need to shutdown whatever we can */
3945 i40e_vsi_control_tx(vsi
, request
);
3946 i40e_vsi_control_rx(vsi
, request
);
3953 * i40e_vsi_free_irq - Free the irq association with the OS
3954 * @vsi: the VSI being configured
3956 static void i40e_vsi_free_irq(struct i40e_vsi
*vsi
)
3958 struct i40e_pf
*pf
= vsi
->back
;
3959 struct i40e_hw
*hw
= &pf
->hw
;
3960 int base
= vsi
->base_vector
;
3964 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3965 if (!vsi
->q_vectors
)
3968 if (!vsi
->irqs_ready
)
3971 vsi
->irqs_ready
= false;
3972 for (i
= 0; i
< vsi
->num_q_vectors
; i
++) {
3973 u16 vector
= i
+ base
;
3975 /* free only the irqs that were actually requested */
3976 if (!vsi
->q_vectors
[i
] ||
3977 !vsi
->q_vectors
[i
]->num_ringpairs
)
3980 /* clear the affinity_mask in the IRQ descriptor */
3981 irq_set_affinity_hint(pf
->msix_entries
[vector
].vector
,
3983 free_irq(pf
->msix_entries
[vector
].vector
,
3986 /* Tear down the interrupt queue link list
3988 * We know that they come in pairs and always
3989 * the Rx first, then the Tx. To clear the
3990 * link list, stick the EOL value into the
3991 * next_q field of the registers.
3993 val
= rd32(hw
, I40E_PFINT_LNKLSTN(vector
- 1));
3994 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
3995 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
3996 val
|= I40E_QUEUE_END_OF_LIST
3997 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
3998 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), val
);
4000 while (qp
!= I40E_QUEUE_END_OF_LIST
) {
4003 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
4005 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
4006 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
4007 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
4008 I40E_QINT_RQCTL_INTEVENT_MASK
);
4010 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
4011 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
4013 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
4015 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
4017 next
= (val
& I40E_QINT_TQCTL_NEXTQ_INDX_MASK
)
4018 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
;
4020 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
4021 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
4022 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
4023 I40E_QINT_TQCTL_INTEVENT_MASK
);
4025 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
4026 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
4028 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
4033 free_irq(pf
->pdev
->irq
, pf
);
4035 val
= rd32(hw
, I40E_PFINT_LNKLST0
);
4036 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
4037 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
4038 val
|= I40E_QUEUE_END_OF_LIST
4039 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT
;
4040 wr32(hw
, I40E_PFINT_LNKLST0
, val
);
4042 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
4043 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
4044 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
4045 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
4046 I40E_QINT_RQCTL_INTEVENT_MASK
);
4048 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
4049 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
4051 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
4053 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
4055 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
4056 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
4057 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
4058 I40E_QINT_TQCTL_INTEVENT_MASK
);
4060 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
4061 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
4063 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
4068 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
4069 * @vsi: the VSI being configured
4070 * @v_idx: Index of vector to be freed
4072 * This function frees the memory allocated to the q_vector. In addition if
4073 * NAPI is enabled it will delete any references to the NAPI struct prior
4074 * to freeing the q_vector.
4076 static void i40e_free_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
4078 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
4079 struct i40e_ring
*ring
;
4084 /* disassociate q_vector from rings */
4085 i40e_for_each_ring(ring
, q_vector
->tx
)
4086 ring
->q_vector
= NULL
;
4088 i40e_for_each_ring(ring
, q_vector
->rx
)
4089 ring
->q_vector
= NULL
;
4091 /* only VSI w/ an associated netdev is set up w/ NAPI */
4093 netif_napi_del(&q_vector
->napi
);
4095 vsi
->q_vectors
[v_idx
] = NULL
;
4097 kfree_rcu(q_vector
, rcu
);
4101 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
4102 * @vsi: the VSI being un-configured
4104 * This frees the memory allocated to the q_vectors and
4105 * deletes references to the NAPI struct.
4107 static void i40e_vsi_free_q_vectors(struct i40e_vsi
*vsi
)
4111 for (v_idx
= 0; v_idx
< vsi
->num_q_vectors
; v_idx
++)
4112 i40e_free_q_vector(vsi
, v_idx
);
4116 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
4117 * @pf: board private structure
4119 static void i40e_reset_interrupt_capability(struct i40e_pf
*pf
)
4121 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
4122 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
4123 pci_disable_msix(pf
->pdev
);
4124 kfree(pf
->msix_entries
);
4125 pf
->msix_entries
= NULL
;
4126 kfree(pf
->irq_pile
);
4127 pf
->irq_pile
= NULL
;
4128 } else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
) {
4129 pci_disable_msi(pf
->pdev
);
4131 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
);
4135 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
4136 * @pf: board private structure
4138 * We go through and clear interrupt specific resources and reset the structure
4139 * to pre-load conditions
4141 static void i40e_clear_interrupt_scheme(struct i40e_pf
*pf
)
4145 i40e_stop_misc_vector(pf
);
4146 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
4147 synchronize_irq(pf
->msix_entries
[0].vector
);
4148 free_irq(pf
->msix_entries
[0].vector
, pf
);
4151 i40e_put_lump(pf
->irq_pile
, 0, I40E_PILE_VALID_BIT
-1);
4152 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
4154 i40e_vsi_free_q_vectors(pf
->vsi
[i
]);
4155 i40e_reset_interrupt_capability(pf
);
4159 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
4160 * @vsi: the VSI being configured
4162 static void i40e_napi_enable_all(struct i40e_vsi
*vsi
)
4169 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++)
4170 napi_enable(&vsi
->q_vectors
[q_idx
]->napi
);
4174 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4175 * @vsi: the VSI being configured
4177 static void i40e_napi_disable_all(struct i40e_vsi
*vsi
)
4184 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++)
4185 napi_disable(&vsi
->q_vectors
[q_idx
]->napi
);
4189 * i40e_vsi_close - Shut down a VSI
4190 * @vsi: the vsi to be quelled
4192 static void i40e_vsi_close(struct i40e_vsi
*vsi
)
4194 if (!test_and_set_bit(__I40E_DOWN
, &vsi
->state
))
4196 i40e_vsi_free_irq(vsi
);
4197 i40e_vsi_free_tx_resources(vsi
);
4198 i40e_vsi_free_rx_resources(vsi
);
4199 vsi
->current_netdev_flags
= 0;
4203 * i40e_quiesce_vsi - Pause a given VSI
4204 * @vsi: the VSI being paused
4206 static void i40e_quiesce_vsi(struct i40e_vsi
*vsi
)
4208 if (test_bit(__I40E_DOWN
, &vsi
->state
))
4211 /* No need to disable FCoE VSI when Tx suspended */
4212 if ((test_bit(__I40E_PORT_TX_SUSPENDED
, &vsi
->back
->state
)) &&
4213 vsi
->type
== I40E_VSI_FCOE
) {
4214 dev_dbg(&vsi
->back
->pdev
->dev
,
4215 "VSI seid %d skipping FCoE VSI disable\n", vsi
->seid
);
4219 set_bit(__I40E_NEEDS_RESTART
, &vsi
->state
);
4220 if (vsi
->netdev
&& netif_running(vsi
->netdev
))
4221 vsi
->netdev
->netdev_ops
->ndo_stop(vsi
->netdev
);
4223 i40e_vsi_close(vsi
);
4227 * i40e_unquiesce_vsi - Resume a given VSI
4228 * @vsi: the VSI being resumed
4230 static void i40e_unquiesce_vsi(struct i40e_vsi
*vsi
)
4232 if (!test_bit(__I40E_NEEDS_RESTART
, &vsi
->state
))
4235 clear_bit(__I40E_NEEDS_RESTART
, &vsi
->state
);
4236 if (vsi
->netdev
&& netif_running(vsi
->netdev
))
4237 vsi
->netdev
->netdev_ops
->ndo_open(vsi
->netdev
);
4239 i40e_vsi_open(vsi
); /* this clears the DOWN bit */
4243 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
4246 static void i40e_pf_quiesce_all_vsi(struct i40e_pf
*pf
)
4250 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4252 i40e_quiesce_vsi(pf
->vsi
[v
]);
4257 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
4260 static void i40e_pf_unquiesce_all_vsi(struct i40e_pf
*pf
)
4264 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4266 i40e_unquiesce_vsi(pf
->vsi
[v
]);
4270 #ifdef CONFIG_I40E_DCB
4272 * i40e_vsi_wait_txq_disabled - Wait for VSI's queues to be disabled
4273 * @vsi: the VSI being configured
4275 * This function waits for the given VSI's Tx queues to be disabled.
4277 static int i40e_vsi_wait_txq_disabled(struct i40e_vsi
*vsi
)
4279 struct i40e_pf
*pf
= vsi
->back
;
4282 pf_q
= vsi
->base_queue
;
4283 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
4284 /* Check and wait for the disable status of the queue */
4285 ret
= i40e_pf_txq_wait(pf
, pf_q
, false);
4287 dev_info(&pf
->pdev
->dev
,
4288 "VSI seid %d Tx ring %d disable timeout\n",
4298 * i40e_pf_wait_txq_disabled - Wait for all queues of PF VSIs to be disabled
4301 * This function waits for the Tx queues to be in disabled state for all the
4302 * VSIs that are managed by this PF.
4304 static int i40e_pf_wait_txq_disabled(struct i40e_pf
*pf
)
4308 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
; v
++) {
4309 /* No need to wait for FCoE VSI queues */
4310 if (pf
->vsi
[v
] && pf
->vsi
[v
]->type
!= I40E_VSI_FCOE
) {
4311 ret
= i40e_vsi_wait_txq_disabled(pf
->vsi
[v
]);
4323 * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
4324 * @q_idx: TX queue number
4325 * @vsi: Pointer to VSI struct
4327 * This function checks specified queue for given VSI. Detects hung condition.
4328 * Sets hung bit since it is two step process. Before next run of service task
4329 * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not,
4330 * hung condition remain unchanged and during subsequent run, this function
4331 * issues SW interrupt to recover from hung condition.
4333 static void i40e_detect_recover_hung_queue(int q_idx
, struct i40e_vsi
*vsi
)
4335 struct i40e_ring
*tx_ring
= NULL
;
4337 u32 head
, val
, tx_pending
;
4342 /* now that we have an index, find the tx_ring struct */
4343 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
4344 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
) {
4345 if (q_idx
== vsi
->tx_rings
[i
]->queue_index
) {
4346 tx_ring
= vsi
->tx_rings
[i
];
4355 /* Read interrupt register */
4356 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
4358 I40E_PFINT_DYN_CTLN(tx_ring
->q_vector
->v_idx
+
4359 tx_ring
->vsi
->base_vector
- 1));
4361 val
= rd32(&pf
->hw
, I40E_PFINT_DYN_CTL0
);
4363 head
= i40e_get_head(tx_ring
);
4365 tx_pending
= i40e_get_tx_pending(tx_ring
);
4367 /* Interrupts are disabled and TX pending is non-zero,
4368 * trigger the SW interrupt (don't wait). Worst case
4369 * there will be one extra interrupt which may result
4370 * into not cleaning any queues because queues are cleaned.
4372 if (tx_pending
&& (!(val
& I40E_PFINT_DYN_CTLN_INTENA_MASK
)))
4373 i40e_force_wb(vsi
, tx_ring
->q_vector
);
4377 * i40e_detect_recover_hung - Function to detect and recover hung_queues
4378 * @pf: pointer to PF struct
4380 * LAN VSI has netdev and netdev has TX queues. This function is to check
4381 * each of those TX queues if they are hung, trigger recovery by issuing
4384 static void i40e_detect_recover_hung(struct i40e_pf
*pf
)
4386 struct net_device
*netdev
;
4387 struct i40e_vsi
*vsi
;
4390 /* Only for LAN VSI */
4391 vsi
= pf
->vsi
[pf
->lan_vsi
];
4396 /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
4397 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
4398 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
4401 /* Make sure type is MAIN VSI */
4402 if (vsi
->type
!= I40E_VSI_MAIN
)
4405 netdev
= vsi
->netdev
;
4409 /* Bail out if netif_carrier is not OK */
4410 if (!netif_carrier_ok(netdev
))
4413 /* Go thru' TX queues for netdev */
4414 for (i
= 0; i
< netdev
->num_tx_queues
; i
++) {
4415 struct netdev_queue
*q
;
4417 q
= netdev_get_tx_queue(netdev
, i
);
4419 i40e_detect_recover_hung_queue(i
, vsi
);
4424 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
4425 * @pf: pointer to PF
4427 * Get TC map for ISCSI PF type that will include iSCSI TC
4430 static u8
i40e_get_iscsi_tc_map(struct i40e_pf
*pf
)
4432 struct i40e_dcb_app_priority_table app
;
4433 struct i40e_hw
*hw
= &pf
->hw
;
4434 u8 enabled_tc
= 1; /* TC0 is always enabled */
4436 /* Get the iSCSI APP TLV */
4437 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4439 for (i
= 0; i
< dcbcfg
->numapps
; i
++) {
4440 app
= dcbcfg
->app
[i
];
4441 if (app
.selector
== I40E_APP_SEL_TCPIP
&&
4442 app
.protocolid
== I40E_APP_PROTOID_ISCSI
) {
4443 tc
= dcbcfg
->etscfg
.prioritytable
[app
.priority
];
4444 enabled_tc
|= BIT_ULL(tc
);
4453 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
4454 * @dcbcfg: the corresponding DCBx configuration structure
4456 * Return the number of TCs from given DCBx configuration
4458 static u8
i40e_dcb_get_num_tc(struct i40e_dcbx_config
*dcbcfg
)
4463 /* Scan the ETS Config Priority Table to find
4464 * traffic class enabled for a given priority
4465 * and use the traffic class index to get the
4466 * number of traffic classes enabled
4468 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
4469 if (dcbcfg
->etscfg
.prioritytable
[i
] > num_tc
)
4470 num_tc
= dcbcfg
->etscfg
.prioritytable
[i
];
4473 /* Traffic class index starts from zero so
4474 * increment to return the actual count
4480 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
4481 * @dcbcfg: the corresponding DCBx configuration structure
4483 * Query the current DCB configuration and return the number of
4484 * traffic classes enabled from the given DCBX config
4486 static u8
i40e_dcb_get_enabled_tc(struct i40e_dcbx_config
*dcbcfg
)
4488 u8 num_tc
= i40e_dcb_get_num_tc(dcbcfg
);
4492 for (i
= 0; i
< num_tc
; i
++)
4493 enabled_tc
|= BIT(i
);
4499 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
4500 * @pf: PF being queried
4502 * Return number of traffic classes enabled for the given PF
4504 static u8
i40e_pf_get_num_tc(struct i40e_pf
*pf
)
4506 struct i40e_hw
*hw
= &pf
->hw
;
4509 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4511 /* If DCB is not enabled then always in single TC */
4512 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
4515 /* SFP mode will be enabled for all TCs on port */
4516 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
4517 return i40e_dcb_get_num_tc(dcbcfg
);
4519 /* MFP mode return count of enabled TCs for this PF */
4520 if (pf
->hw
.func_caps
.iscsi
)
4521 enabled_tc
= i40e_get_iscsi_tc_map(pf
);
4523 return 1; /* Only TC0 */
4525 /* At least have TC0 */
4526 enabled_tc
= (enabled_tc
? enabled_tc
: 0x1);
4527 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4528 if (enabled_tc
& BIT_ULL(i
))
4535 * i40e_pf_get_default_tc - Get bitmap for first enabled TC
4536 * @pf: PF being queried
4538 * Return a bitmap for first enabled traffic class for this PF.
4540 static u8
i40e_pf_get_default_tc(struct i40e_pf
*pf
)
4542 u8 enabled_tc
= pf
->hw
.func_caps
.enabled_tcmap
;
4546 return 0x1; /* TC0 */
4548 /* Find the first enabled TC */
4549 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4550 if (enabled_tc
& BIT_ULL(i
))
4558 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
4559 * @pf: PF being queried
4561 * Return a bitmap for enabled traffic classes for this PF.
4563 static u8
i40e_pf_get_tc_map(struct i40e_pf
*pf
)
4565 /* If DCB is not enabled for this PF then just return default TC */
4566 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
4567 return i40e_pf_get_default_tc(pf
);
4569 /* SFP mode we want PF to be enabled for all TCs */
4570 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
4571 return i40e_dcb_get_enabled_tc(&pf
->hw
.local_dcbx_config
);
4573 /* MFP enabled and iSCSI PF type */
4574 if (pf
->hw
.func_caps
.iscsi
)
4575 return i40e_get_iscsi_tc_map(pf
);
4577 return i40e_pf_get_default_tc(pf
);
4581 * i40e_vsi_get_bw_info - Query VSI BW Information
4582 * @vsi: the VSI being queried
4584 * Returns 0 on success, negative value on failure
4586 static int i40e_vsi_get_bw_info(struct i40e_vsi
*vsi
)
4588 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config
= {0};
4589 struct i40e_aqc_query_vsi_bw_config_resp bw_config
= {0};
4590 struct i40e_pf
*pf
= vsi
->back
;
4591 struct i40e_hw
*hw
= &pf
->hw
;
4596 /* Get the VSI level BW configuration */
4597 ret
= i40e_aq_query_vsi_bw_config(hw
, vsi
->seid
, &bw_config
, NULL
);
4599 dev_info(&pf
->pdev
->dev
,
4600 "couldn't get PF vsi bw config, err %s aq_err %s\n",
4601 i40e_stat_str(&pf
->hw
, ret
),
4602 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4606 /* Get the VSI level BW configuration per TC */
4607 ret
= i40e_aq_query_vsi_ets_sla_config(hw
, vsi
->seid
, &bw_ets_config
,
4610 dev_info(&pf
->pdev
->dev
,
4611 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
4612 i40e_stat_str(&pf
->hw
, ret
),
4613 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4617 if (bw_config
.tc_valid_bits
!= bw_ets_config
.tc_valid_bits
) {
4618 dev_info(&pf
->pdev
->dev
,
4619 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
4620 bw_config
.tc_valid_bits
,
4621 bw_ets_config
.tc_valid_bits
);
4622 /* Still continuing */
4625 vsi
->bw_limit
= le16_to_cpu(bw_config
.port_bw_limit
);
4626 vsi
->bw_max_quanta
= bw_config
.max_bw
;
4627 tc_bw_max
= le16_to_cpu(bw_ets_config
.tc_bw_max
[0]) |
4628 (le16_to_cpu(bw_ets_config
.tc_bw_max
[1]) << 16);
4629 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4630 vsi
->bw_ets_share_credits
[i
] = bw_ets_config
.share_credits
[i
];
4631 vsi
->bw_ets_limit_credits
[i
] =
4632 le16_to_cpu(bw_ets_config
.credits
[i
]);
4633 /* 3 bits out of 4 for each TC */
4634 vsi
->bw_ets_max_quanta
[i
] = (u8
)((tc_bw_max
>> (i
*4)) & 0x7);
4641 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
4642 * @vsi: the VSI being configured
4643 * @enabled_tc: TC bitmap
4644 * @bw_credits: BW shared credits per TC
4646 * Returns 0 on success, negative value on failure
4648 static int i40e_vsi_configure_bw_alloc(struct i40e_vsi
*vsi
, u8 enabled_tc
,
4651 struct i40e_aqc_configure_vsi_tc_bw_data bw_data
;
4655 bw_data
.tc_valid_bits
= enabled_tc
;
4656 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
4657 bw_data
.tc_bw_credits
[i
] = bw_share
[i
];
4659 ret
= i40e_aq_config_vsi_tc_bw(&vsi
->back
->hw
, vsi
->seid
, &bw_data
,
4662 dev_info(&vsi
->back
->pdev
->dev
,
4663 "AQ command Config VSI BW allocation per TC failed = %d\n",
4664 vsi
->back
->hw
.aq
.asq_last_status
);
4668 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
4669 vsi
->info
.qs_handle
[i
] = bw_data
.qs_handles
[i
];
4675 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
4676 * @vsi: the VSI being configured
4677 * @enabled_tc: TC map to be enabled
4680 static void i40e_vsi_config_netdev_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
4682 struct net_device
*netdev
= vsi
->netdev
;
4683 struct i40e_pf
*pf
= vsi
->back
;
4684 struct i40e_hw
*hw
= &pf
->hw
;
4687 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4693 netdev_reset_tc(netdev
);
4697 /* Set up actual enabled TCs on the VSI */
4698 if (netdev_set_num_tc(netdev
, vsi
->tc_config
.numtc
))
4701 /* set per TC queues for the VSI */
4702 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4703 /* Only set TC queues for enabled tcs
4705 * e.g. For a VSI that has TC0 and TC3 enabled the
4706 * enabled_tc bitmap would be 0x00001001; the driver
4707 * will set the numtc for netdev as 2 that will be
4708 * referenced by the netdev layer as TC 0 and 1.
4710 if (vsi
->tc_config
.enabled_tc
& BIT_ULL(i
))
4711 netdev_set_tc_queue(netdev
,
4712 vsi
->tc_config
.tc_info
[i
].netdev_tc
,
4713 vsi
->tc_config
.tc_info
[i
].qcount
,
4714 vsi
->tc_config
.tc_info
[i
].qoffset
);
4717 /* Assign UP2TC map for the VSI */
4718 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
4719 /* Get the actual TC# for the UP */
4720 u8 ets_tc
= dcbcfg
->etscfg
.prioritytable
[i
];
4721 /* Get the mapped netdev TC# for the UP */
4722 netdev_tc
= vsi
->tc_config
.tc_info
[ets_tc
].netdev_tc
;
4723 netdev_set_prio_tc_map(netdev
, i
, netdev_tc
);
4728 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
4729 * @vsi: the VSI being configured
4730 * @ctxt: the ctxt buffer returned from AQ VSI update param command
4732 static void i40e_vsi_update_queue_map(struct i40e_vsi
*vsi
,
4733 struct i40e_vsi_context
*ctxt
)
4735 /* copy just the sections touched not the entire info
4736 * since not all sections are valid as returned by
4739 vsi
->info
.mapping_flags
= ctxt
->info
.mapping_flags
;
4740 memcpy(&vsi
->info
.queue_mapping
,
4741 &ctxt
->info
.queue_mapping
, sizeof(vsi
->info
.queue_mapping
));
4742 memcpy(&vsi
->info
.tc_mapping
, ctxt
->info
.tc_mapping
,
4743 sizeof(vsi
->info
.tc_mapping
));
4747 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
4748 * @vsi: VSI to be configured
4749 * @enabled_tc: TC bitmap
4751 * This configures a particular VSI for TCs that are mapped to the
4752 * given TC bitmap. It uses default bandwidth share for TCs across
4753 * VSIs to configure TC for a particular VSI.
4756 * It is expected that the VSI queues have been quisced before calling
4759 static int i40e_vsi_config_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
4761 u8 bw_share
[I40E_MAX_TRAFFIC_CLASS
] = {0};
4762 struct i40e_vsi_context ctxt
;
4766 /* Check if enabled_tc is same as existing or new TCs */
4767 if (vsi
->tc_config
.enabled_tc
== enabled_tc
)
4770 /* Enable ETS TCs with equal BW Share for now across all VSIs */
4771 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4772 if (enabled_tc
& BIT_ULL(i
))
4776 ret
= i40e_vsi_configure_bw_alloc(vsi
, enabled_tc
, bw_share
);
4778 dev_info(&vsi
->back
->pdev
->dev
,
4779 "Failed configuring TC map %d for VSI %d\n",
4780 enabled_tc
, vsi
->seid
);
4784 /* Update Queue Pairs Mapping for currently enabled UPs */
4785 ctxt
.seid
= vsi
->seid
;
4786 ctxt
.pf_num
= vsi
->back
->hw
.pf_id
;
4788 ctxt
.uplink_seid
= vsi
->uplink_seid
;
4789 ctxt
.info
= vsi
->info
;
4790 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
4792 /* Update the VSI after updating the VSI queue-mapping information */
4793 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
4795 dev_info(&vsi
->back
->pdev
->dev
,
4796 "Update vsi tc config failed, err %s aq_err %s\n",
4797 i40e_stat_str(&vsi
->back
->hw
, ret
),
4798 i40e_aq_str(&vsi
->back
->hw
,
4799 vsi
->back
->hw
.aq
.asq_last_status
));
4802 /* update the local VSI info with updated queue map */
4803 i40e_vsi_update_queue_map(vsi
, &ctxt
);
4804 vsi
->info
.valid_sections
= 0;
4806 /* Update current VSI BW information */
4807 ret
= i40e_vsi_get_bw_info(vsi
);
4809 dev_info(&vsi
->back
->pdev
->dev
,
4810 "Failed updating vsi bw info, err %s aq_err %s\n",
4811 i40e_stat_str(&vsi
->back
->hw
, ret
),
4812 i40e_aq_str(&vsi
->back
->hw
,
4813 vsi
->back
->hw
.aq
.asq_last_status
));
4817 /* Update the netdev TC setup */
4818 i40e_vsi_config_netdev_tc(vsi
, enabled_tc
);
4824 * i40e_veb_config_tc - Configure TCs for given VEB
4826 * @enabled_tc: TC bitmap
4828 * Configures given TC bitmap for VEB (switching) element
4830 int i40e_veb_config_tc(struct i40e_veb
*veb
, u8 enabled_tc
)
4832 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data
= {0};
4833 struct i40e_pf
*pf
= veb
->pf
;
4837 /* No TCs or already enabled TCs just return */
4838 if (!enabled_tc
|| veb
->enabled_tc
== enabled_tc
)
4841 bw_data
.tc_valid_bits
= enabled_tc
;
4842 /* bw_data.absolute_credits is not set (relative) */
4844 /* Enable ETS TCs with equal BW Share for now */
4845 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4846 if (enabled_tc
& BIT_ULL(i
))
4847 bw_data
.tc_bw_share_credits
[i
] = 1;
4850 ret
= i40e_aq_config_switch_comp_bw_config(&pf
->hw
, veb
->seid
,
4853 dev_info(&pf
->pdev
->dev
,
4854 "VEB bw config failed, err %s aq_err %s\n",
4855 i40e_stat_str(&pf
->hw
, ret
),
4856 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4860 /* Update the BW information */
4861 ret
= i40e_veb_get_bw_info(veb
);
4863 dev_info(&pf
->pdev
->dev
,
4864 "Failed getting veb bw config, err %s aq_err %s\n",
4865 i40e_stat_str(&pf
->hw
, ret
),
4866 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4873 #ifdef CONFIG_I40E_DCB
4875 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
4878 * Reconfigure VEB/VSIs on a given PF; it is assumed that
4879 * the caller would've quiesce all the VSIs before calling
4882 static void i40e_dcb_reconfigure(struct i40e_pf
*pf
)
4888 /* Enable the TCs available on PF to all VEBs */
4889 tc_map
= i40e_pf_get_tc_map(pf
);
4890 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
4893 ret
= i40e_veb_config_tc(pf
->veb
[v
], tc_map
);
4895 dev_info(&pf
->pdev
->dev
,
4896 "Failed configuring TC for VEB seid=%d\n",
4898 /* Will try to configure as many components */
4902 /* Update each VSI */
4903 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4907 /* - Enable all TCs for the LAN VSI
4909 * - For FCoE VSI only enable the TC configured
4910 * as per the APP TLV
4912 * - For all others keep them at TC0 for now
4914 if (v
== pf
->lan_vsi
)
4915 tc_map
= i40e_pf_get_tc_map(pf
);
4917 tc_map
= i40e_pf_get_default_tc(pf
);
4919 if (pf
->vsi
[v
]->type
== I40E_VSI_FCOE
)
4920 tc_map
= i40e_get_fcoe_tc_map(pf
);
4921 #endif /* #ifdef I40E_FCOE */
4923 ret
= i40e_vsi_config_tc(pf
->vsi
[v
], tc_map
);
4925 dev_info(&pf
->pdev
->dev
,
4926 "Failed configuring TC for VSI seid=%d\n",
4928 /* Will try to configure as many components */
4930 /* Re-configure VSI vectors based on updated TC map */
4931 i40e_vsi_map_rings_to_vectors(pf
->vsi
[v
]);
4932 if (pf
->vsi
[v
]->netdev
)
4933 i40e_dcbnl_set_all(pf
->vsi
[v
]);
4939 * i40e_resume_port_tx - Resume port Tx
4942 * Resume a port's Tx and issue a PF reset in case of failure to
4945 static int i40e_resume_port_tx(struct i40e_pf
*pf
)
4947 struct i40e_hw
*hw
= &pf
->hw
;
4950 ret
= i40e_aq_resume_port_tx(hw
, NULL
);
4952 dev_info(&pf
->pdev
->dev
,
4953 "Resume Port Tx failed, err %s aq_err %s\n",
4954 i40e_stat_str(&pf
->hw
, ret
),
4955 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4956 /* Schedule PF reset to recover */
4957 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
4958 i40e_service_event_schedule(pf
);
4965 * i40e_init_pf_dcb - Initialize DCB configuration
4966 * @pf: PF being configured
4968 * Query the current DCB configuration and cache it
4969 * in the hardware structure
4971 static int i40e_init_pf_dcb(struct i40e_pf
*pf
)
4973 struct i40e_hw
*hw
= &pf
->hw
;
4976 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
4977 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
4978 (pf
->hw
.aq
.fw_maj_ver
< 4))
4981 /* Get the initial DCB configuration */
4982 err
= i40e_init_dcb(hw
);
4984 /* Device/Function is not DCBX capable */
4985 if ((!hw
->func_caps
.dcb
) ||
4986 (hw
->dcbx_status
== I40E_DCBX_STATUS_DISABLED
)) {
4987 dev_info(&pf
->pdev
->dev
,
4988 "DCBX offload is not supported or is disabled for this PF.\n");
4990 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
)
4994 /* When status is not DISABLED then DCBX in FW */
4995 pf
->dcbx_cap
= DCB_CAP_DCBX_LLD_MANAGED
|
4996 DCB_CAP_DCBX_VER_IEEE
;
4998 pf
->flags
|= I40E_FLAG_DCB_CAPABLE
;
4999 /* Enable DCB tagging only when more than one TC */
5000 if (i40e_dcb_get_num_tc(&hw
->local_dcbx_config
) > 1)
5001 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
5002 dev_dbg(&pf
->pdev
->dev
,
5003 "DCBX offload is supported for this PF.\n");
5006 dev_info(&pf
->pdev
->dev
,
5007 "Query for DCB configuration failed, err %s aq_err %s\n",
5008 i40e_stat_str(&pf
->hw
, err
),
5009 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
5015 #endif /* CONFIG_I40E_DCB */
5016 #define SPEED_SIZE 14
5019 * i40e_print_link_message - print link up or down
5020 * @vsi: the VSI for which link needs a message
5022 void i40e_print_link_message(struct i40e_vsi
*vsi
, bool isup
)
5024 char *speed
= "Unknown";
5025 char *fc
= "Unknown";
5027 if (vsi
->current_isup
== isup
)
5029 vsi
->current_isup
= isup
;
5031 netdev_info(vsi
->netdev
, "NIC Link is Down\n");
5035 /* Warn user if link speed on NPAR enabled partition is not at
5038 if (vsi
->back
->hw
.func_caps
.npar_enable
&&
5039 (vsi
->back
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_1GB
||
5040 vsi
->back
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_100MB
))
5041 netdev_warn(vsi
->netdev
,
5042 "The partition detected link speed that is less than 10Gbps\n");
5044 switch (vsi
->back
->hw
.phy
.link_info
.link_speed
) {
5045 case I40E_LINK_SPEED_40GB
:
5048 case I40E_LINK_SPEED_20GB
:
5051 case I40E_LINK_SPEED_10GB
:
5054 case I40E_LINK_SPEED_1GB
:
5057 case I40E_LINK_SPEED_100MB
:
5064 switch (vsi
->back
->hw
.fc
.current_mode
) {
5068 case I40E_FC_TX_PAUSE
:
5071 case I40E_FC_RX_PAUSE
:
5079 netdev_info(vsi
->netdev
, "NIC Link is Up %sbps Full Duplex, Flow Control: %s\n",
5084 * i40e_up_complete - Finish the last steps of bringing up a connection
5085 * @vsi: the VSI being configured
5087 static int i40e_up_complete(struct i40e_vsi
*vsi
)
5089 struct i40e_pf
*pf
= vsi
->back
;
5092 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
5093 i40e_vsi_configure_msix(vsi
);
5095 i40e_configure_msi_and_legacy(vsi
);
5098 err
= i40e_vsi_control_rings(vsi
, true);
5102 clear_bit(__I40E_DOWN
, &vsi
->state
);
5103 i40e_napi_enable_all(vsi
);
5104 i40e_vsi_enable_irq(vsi
);
5106 if ((pf
->hw
.phy
.link_info
.link_info
& I40E_AQ_LINK_UP
) &&
5108 i40e_print_link_message(vsi
, true);
5109 netif_tx_start_all_queues(vsi
->netdev
);
5110 netif_carrier_on(vsi
->netdev
);
5111 } else if (vsi
->netdev
) {
5112 i40e_print_link_message(vsi
, false);
5113 /* need to check for qualified module here*/
5114 if ((pf
->hw
.phy
.link_info
.link_info
&
5115 I40E_AQ_MEDIA_AVAILABLE
) &&
5116 (!(pf
->hw
.phy
.link_info
.an_info
&
5117 I40E_AQ_QUALIFIED_MODULE
)))
5118 netdev_err(vsi
->netdev
,
5119 "the driver failed to link because an unqualified module was detected.");
5122 /* replay FDIR SB filters */
5123 if (vsi
->type
== I40E_VSI_FDIR
) {
5124 /* reset fd counters */
5125 pf
->fd_add_err
= pf
->fd_atr_cnt
= 0;
5126 if (pf
->fd_tcp_rule
> 0) {
5127 pf
->flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
5128 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5129 dev_info(&pf
->pdev
->dev
, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
5130 pf
->fd_tcp_rule
= 0;
5132 i40e_fdir_filter_restore(vsi
);
5134 i40e_service_event_schedule(pf
);
5140 * i40e_vsi_reinit_locked - Reset the VSI
5141 * @vsi: the VSI being configured
5143 * Rebuild the ring structs after some configuration
5144 * has changed, e.g. MTU size.
5146 static void i40e_vsi_reinit_locked(struct i40e_vsi
*vsi
)
5148 struct i40e_pf
*pf
= vsi
->back
;
5150 WARN_ON(in_interrupt());
5151 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
5152 usleep_range(1000, 2000);
5155 /* Give a VF some time to respond to the reset. The
5156 * two second wait is based upon the watchdog cycle in
5159 if (vsi
->type
== I40E_VSI_SRIOV
)
5162 clear_bit(__I40E_CONFIG_BUSY
, &pf
->state
);
5166 * i40e_up - Bring the connection back up after being down
5167 * @vsi: the VSI being configured
5169 int i40e_up(struct i40e_vsi
*vsi
)
5173 err
= i40e_vsi_configure(vsi
);
5175 err
= i40e_up_complete(vsi
);
5181 * i40e_down - Shutdown the connection processing
5182 * @vsi: the VSI being stopped
5184 void i40e_down(struct i40e_vsi
*vsi
)
5188 /* It is assumed that the caller of this function
5189 * sets the vsi->state __I40E_DOWN bit.
5192 netif_carrier_off(vsi
->netdev
);
5193 netif_tx_disable(vsi
->netdev
);
5195 i40e_vsi_disable_irq(vsi
);
5196 i40e_vsi_control_rings(vsi
, false);
5197 i40e_napi_disable_all(vsi
);
5199 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
5200 i40e_clean_tx_ring(vsi
->tx_rings
[i
]);
5201 i40e_clean_rx_ring(vsi
->rx_rings
[i
]);
5206 * i40e_setup_tc - configure multiple traffic classes
5207 * @netdev: net device to configure
5208 * @tc: number of traffic classes to enable
5211 int i40e_setup_tc(struct net_device
*netdev
, u8 tc
)
5213 static int i40e_setup_tc(struct net_device
*netdev
, u8 tc
)
5216 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
5217 struct i40e_vsi
*vsi
= np
->vsi
;
5218 struct i40e_pf
*pf
= vsi
->back
;
5223 /* Check if DCB enabled to continue */
5224 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
)) {
5225 netdev_info(netdev
, "DCB is not enabled for adapter\n");
5229 /* Check if MFP enabled */
5230 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
5231 netdev_info(netdev
, "Configuring TC not supported in MFP mode\n");
5235 /* Check whether tc count is within enabled limit */
5236 if (tc
> i40e_pf_get_num_tc(pf
)) {
5237 netdev_info(netdev
, "TC count greater than enabled on link for adapter\n");
5241 /* Generate TC map for number of tc requested */
5242 for (i
= 0; i
< tc
; i
++)
5243 enabled_tc
|= BIT_ULL(i
);
5245 /* Requesting same TC configuration as already enabled */
5246 if (enabled_tc
== vsi
->tc_config
.enabled_tc
)
5249 /* Quiesce VSI queues */
5250 i40e_quiesce_vsi(vsi
);
5252 /* Configure VSI for enabled TCs */
5253 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
5255 netdev_info(netdev
, "Failed configuring TC for VSI seid=%d\n",
5261 i40e_unquiesce_vsi(vsi
);
5268 * i40e_open - Called when a network interface is made active
5269 * @netdev: network interface device structure
5271 * The open entry point is called when a network interface is made
5272 * active by the system (IFF_UP). At this point all resources needed
5273 * for transmit and receive operations are allocated, the interrupt
5274 * handler is registered with the OS, the netdev watchdog subtask is
5275 * enabled, and the stack is notified that the interface is ready.
5277 * Returns 0 on success, negative value on failure
5279 int i40e_open(struct net_device
*netdev
)
5281 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
5282 struct i40e_vsi
*vsi
= np
->vsi
;
5283 struct i40e_pf
*pf
= vsi
->back
;
5286 /* disallow open during test or if eeprom is broken */
5287 if (test_bit(__I40E_TESTING
, &pf
->state
) ||
5288 test_bit(__I40E_BAD_EEPROM
, &pf
->state
))
5291 netif_carrier_off(netdev
);
5293 err
= i40e_vsi_open(vsi
);
5297 /* configure global TSO hardware offload settings */
5298 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_F
, be32_to_cpu(TCP_FLAG_PSH
|
5299 TCP_FLAG_FIN
) >> 16);
5300 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_M
, be32_to_cpu(TCP_FLAG_PSH
|
5302 TCP_FLAG_CWR
) >> 16);
5303 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_L
, be32_to_cpu(TCP_FLAG_CWR
) >> 16);
5305 #ifdef CONFIG_I40E_VXLAN
5306 vxlan_get_rx_port(netdev
);
5314 * @vsi: the VSI to open
5316 * Finish initialization of the VSI.
5318 * Returns 0 on success, negative value on failure
5320 int i40e_vsi_open(struct i40e_vsi
*vsi
)
5322 struct i40e_pf
*pf
= vsi
->back
;
5323 char int_name
[I40E_INT_NAME_STR_LEN
];
5326 /* allocate descriptors */
5327 err
= i40e_vsi_setup_tx_resources(vsi
);
5330 err
= i40e_vsi_setup_rx_resources(vsi
);
5334 err
= i40e_vsi_configure(vsi
);
5339 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s",
5340 dev_driver_string(&pf
->pdev
->dev
), vsi
->netdev
->name
);
5341 err
= i40e_vsi_request_irq(vsi
, int_name
);
5345 /* Notify the stack of the actual queue counts. */
5346 err
= netif_set_real_num_tx_queues(vsi
->netdev
,
5347 vsi
->num_queue_pairs
);
5349 goto err_set_queues
;
5351 err
= netif_set_real_num_rx_queues(vsi
->netdev
,
5352 vsi
->num_queue_pairs
);
5354 goto err_set_queues
;
5356 } else if (vsi
->type
== I40E_VSI_FDIR
) {
5357 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s:fdir",
5358 dev_driver_string(&pf
->pdev
->dev
),
5359 dev_name(&pf
->pdev
->dev
));
5360 err
= i40e_vsi_request_irq(vsi
, int_name
);
5367 err
= i40e_up_complete(vsi
);
5369 goto err_up_complete
;
5376 i40e_vsi_free_irq(vsi
);
5378 i40e_vsi_free_rx_resources(vsi
);
5380 i40e_vsi_free_tx_resources(vsi
);
5381 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
5382 i40e_do_reset(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
5388 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
5389 * @pf: Pointer to PF
5391 * This function destroys the hlist where all the Flow Director
5392 * filters were saved.
5394 static void i40e_fdir_filter_exit(struct i40e_pf
*pf
)
5396 struct i40e_fdir_filter
*filter
;
5397 struct hlist_node
*node2
;
5399 hlist_for_each_entry_safe(filter
, node2
,
5400 &pf
->fdir_filter_list
, fdir_node
) {
5401 hlist_del(&filter
->fdir_node
);
5404 pf
->fdir_pf_active_filters
= 0;
5408 * i40e_close - Disables a network interface
5409 * @netdev: network interface device structure
5411 * The close entry point is called when an interface is de-activated
5412 * by the OS. The hardware is still under the driver's control, but
5413 * this netdev interface is disabled.
5415 * Returns 0, this is not allowed to fail
5418 int i40e_close(struct net_device
*netdev
)
5420 static int i40e_close(struct net_device
*netdev
)
5423 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
5424 struct i40e_vsi
*vsi
= np
->vsi
;
5426 i40e_vsi_close(vsi
);
5432 * i40e_do_reset - Start a PF or Core Reset sequence
5433 * @pf: board private structure
5434 * @reset_flags: which reset is requested
5436 * The essential difference in resets is that the PF Reset
5437 * doesn't clear the packet buffers, doesn't reset the PE
5438 * firmware, and doesn't bother the other PFs on the chip.
5440 void i40e_do_reset(struct i40e_pf
*pf
, u32 reset_flags
)
5444 WARN_ON(in_interrupt());
5446 if (i40e_check_asq_alive(&pf
->hw
))
5447 i40e_vc_notify_reset(pf
);
5449 /* do the biggest reset indicated */
5450 if (reset_flags
& BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED
)) {
5452 /* Request a Global Reset
5454 * This will start the chip's countdown to the actual full
5455 * chip reset event, and a warning interrupt to be sent
5456 * to all PFs, including the requestor. Our handler
5457 * for the warning interrupt will deal with the shutdown
5458 * and recovery of the switch setup.
5460 dev_dbg(&pf
->pdev
->dev
, "GlobalR requested\n");
5461 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
5462 val
|= I40E_GLGEN_RTRIG_GLOBR_MASK
;
5463 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
5465 } else if (reset_flags
& BIT_ULL(__I40E_CORE_RESET_REQUESTED
)) {
5467 /* Request a Core Reset
5469 * Same as Global Reset, except does *not* include the MAC/PHY
5471 dev_dbg(&pf
->pdev
->dev
, "CoreR requested\n");
5472 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
5473 val
|= I40E_GLGEN_RTRIG_CORER_MASK
;
5474 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
5475 i40e_flush(&pf
->hw
);
5477 } else if (reset_flags
& BIT_ULL(__I40E_PF_RESET_REQUESTED
)) {
5479 /* Request a PF Reset
5481 * Resets only the PF-specific registers
5483 * This goes directly to the tear-down and rebuild of
5484 * the switch, since we need to do all the recovery as
5485 * for the Core Reset.
5487 dev_dbg(&pf
->pdev
->dev
, "PFR requested\n");
5488 i40e_handle_reset_warning(pf
);
5490 } else if (reset_flags
& BIT_ULL(__I40E_REINIT_REQUESTED
)) {
5493 /* Find the VSI(s) that requested a re-init */
5494 dev_info(&pf
->pdev
->dev
,
5495 "VSI reinit requested\n");
5496 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5497 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
5500 test_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
)) {
5501 i40e_vsi_reinit_locked(pf
->vsi
[v
]);
5502 clear_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
);
5505 } else if (reset_flags
& BIT_ULL(__I40E_DOWN_REQUESTED
)) {
5508 /* Find the VSI(s) that needs to be brought down */
5509 dev_info(&pf
->pdev
->dev
, "VSI down requested\n");
5510 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5511 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
5514 test_bit(__I40E_DOWN_REQUESTED
, &vsi
->state
)) {
5515 set_bit(__I40E_DOWN
, &vsi
->state
);
5517 clear_bit(__I40E_DOWN_REQUESTED
, &vsi
->state
);
5521 dev_info(&pf
->pdev
->dev
,
5522 "bad reset request 0x%08x\n", reset_flags
);
5526 #ifdef CONFIG_I40E_DCB
5528 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
5529 * @pf: board private structure
5530 * @old_cfg: current DCB config
5531 * @new_cfg: new DCB config
5533 bool i40e_dcb_need_reconfig(struct i40e_pf
*pf
,
5534 struct i40e_dcbx_config
*old_cfg
,
5535 struct i40e_dcbx_config
*new_cfg
)
5537 bool need_reconfig
= false;
5539 /* Check if ETS configuration has changed */
5540 if (memcmp(&new_cfg
->etscfg
,
5542 sizeof(new_cfg
->etscfg
))) {
5543 /* If Priority Table has changed reconfig is needed */
5544 if (memcmp(&new_cfg
->etscfg
.prioritytable
,
5545 &old_cfg
->etscfg
.prioritytable
,
5546 sizeof(new_cfg
->etscfg
.prioritytable
))) {
5547 need_reconfig
= true;
5548 dev_dbg(&pf
->pdev
->dev
, "ETS UP2TC changed.\n");
5551 if (memcmp(&new_cfg
->etscfg
.tcbwtable
,
5552 &old_cfg
->etscfg
.tcbwtable
,
5553 sizeof(new_cfg
->etscfg
.tcbwtable
)))
5554 dev_dbg(&pf
->pdev
->dev
, "ETS TC BW Table changed.\n");
5556 if (memcmp(&new_cfg
->etscfg
.tsatable
,
5557 &old_cfg
->etscfg
.tsatable
,
5558 sizeof(new_cfg
->etscfg
.tsatable
)))
5559 dev_dbg(&pf
->pdev
->dev
, "ETS TSA Table changed.\n");
5562 /* Check if PFC configuration has changed */
5563 if (memcmp(&new_cfg
->pfc
,
5565 sizeof(new_cfg
->pfc
))) {
5566 need_reconfig
= true;
5567 dev_dbg(&pf
->pdev
->dev
, "PFC config change detected.\n");
5570 /* Check if APP Table has changed */
5571 if (memcmp(&new_cfg
->app
,
5573 sizeof(new_cfg
->app
))) {
5574 need_reconfig
= true;
5575 dev_dbg(&pf
->pdev
->dev
, "APP Table change detected.\n");
5578 dev_dbg(&pf
->pdev
->dev
, "dcb need_reconfig=%d\n", need_reconfig
);
5579 return need_reconfig
;
5583 * i40e_handle_lldp_event - Handle LLDP Change MIB event
5584 * @pf: board private structure
5585 * @e: event info posted on ARQ
5587 static int i40e_handle_lldp_event(struct i40e_pf
*pf
,
5588 struct i40e_arq_event_info
*e
)
5590 struct i40e_aqc_lldp_get_mib
*mib
=
5591 (struct i40e_aqc_lldp_get_mib
*)&e
->desc
.params
.raw
;
5592 struct i40e_hw
*hw
= &pf
->hw
;
5593 struct i40e_dcbx_config tmp_dcbx_cfg
;
5594 bool need_reconfig
= false;
5598 /* Not DCB capable or capability disabled */
5599 if (!(pf
->flags
& I40E_FLAG_DCB_CAPABLE
))
5602 /* Ignore if event is not for Nearest Bridge */
5603 type
= ((mib
->type
>> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT
)
5604 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK
);
5605 dev_dbg(&pf
->pdev
->dev
, "LLDP event mib bridge type 0x%x\n", type
);
5606 if (type
!= I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
)
5609 /* Check MIB Type and return if event for Remote MIB update */
5610 type
= mib
->type
& I40E_AQ_LLDP_MIB_TYPE_MASK
;
5611 dev_dbg(&pf
->pdev
->dev
,
5612 "LLDP event mib type %s\n", type
? "remote" : "local");
5613 if (type
== I40E_AQ_LLDP_MIB_REMOTE
) {
5614 /* Update the remote cached instance and return */
5615 ret
= i40e_aq_get_dcb_config(hw
, I40E_AQ_LLDP_MIB_REMOTE
,
5616 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
,
5617 &hw
->remote_dcbx_config
);
5621 /* Store the old configuration */
5622 tmp_dcbx_cfg
= hw
->local_dcbx_config
;
5624 /* Reset the old DCBx configuration data */
5625 memset(&hw
->local_dcbx_config
, 0, sizeof(hw
->local_dcbx_config
));
5626 /* Get updated DCBX data from firmware */
5627 ret
= i40e_get_dcb_config(&pf
->hw
);
5629 dev_info(&pf
->pdev
->dev
,
5630 "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
5631 i40e_stat_str(&pf
->hw
, ret
),
5632 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
5636 /* No change detected in DCBX configs */
5637 if (!memcmp(&tmp_dcbx_cfg
, &hw
->local_dcbx_config
,
5638 sizeof(tmp_dcbx_cfg
))) {
5639 dev_dbg(&pf
->pdev
->dev
, "No change detected in DCBX configuration.\n");
5643 need_reconfig
= i40e_dcb_need_reconfig(pf
, &tmp_dcbx_cfg
,
5644 &hw
->local_dcbx_config
);
5646 i40e_dcbnl_flush_apps(pf
, &tmp_dcbx_cfg
, &hw
->local_dcbx_config
);
5651 /* Enable DCB tagging only when more than one TC */
5652 if (i40e_dcb_get_num_tc(&hw
->local_dcbx_config
) > 1)
5653 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
5655 pf
->flags
&= ~I40E_FLAG_DCB_ENABLED
;
5657 set_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
);
5658 /* Reconfiguration needed quiesce all VSIs */
5659 i40e_pf_quiesce_all_vsi(pf
);
5661 /* Changes in configuration update VEB/VSI */
5662 i40e_dcb_reconfigure(pf
);
5664 ret
= i40e_resume_port_tx(pf
);
5666 clear_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
);
5667 /* In case of error no point in resuming VSIs */
5671 /* Wait for the PF's Tx queues to be disabled */
5672 ret
= i40e_pf_wait_txq_disabled(pf
);
5674 /* Schedule PF reset to recover */
5675 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
5676 i40e_service_event_schedule(pf
);
5678 i40e_pf_unquiesce_all_vsi(pf
);
5684 #endif /* CONFIG_I40E_DCB */
5687 * i40e_do_reset_safe - Protected reset path for userland calls.
5688 * @pf: board private structure
5689 * @reset_flags: which reset is requested
5692 void i40e_do_reset_safe(struct i40e_pf
*pf
, u32 reset_flags
)
5695 i40e_do_reset(pf
, reset_flags
);
5700 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
5701 * @pf: board private structure
5702 * @e: event info posted on ARQ
5704 * Handler for LAN Queue Overflow Event generated by the firmware for PF
5707 static void i40e_handle_lan_overflow_event(struct i40e_pf
*pf
,
5708 struct i40e_arq_event_info
*e
)
5710 struct i40e_aqc_lan_overflow
*data
=
5711 (struct i40e_aqc_lan_overflow
*)&e
->desc
.params
.raw
;
5712 u32 queue
= le32_to_cpu(data
->prtdcb_rupto
);
5713 u32 qtx_ctl
= le32_to_cpu(data
->otx_ctl
);
5714 struct i40e_hw
*hw
= &pf
->hw
;
5718 dev_dbg(&pf
->pdev
->dev
, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
5721 /* Queue belongs to VF, find the VF and issue VF reset */
5722 if (((qtx_ctl
& I40E_QTX_CTL_PFVF_Q_MASK
)
5723 >> I40E_QTX_CTL_PFVF_Q_SHIFT
) == I40E_QTX_CTL_VF_QUEUE
) {
5724 vf_id
= (u16
)((qtx_ctl
& I40E_QTX_CTL_VFVM_INDX_MASK
)
5725 >> I40E_QTX_CTL_VFVM_INDX_SHIFT
);
5726 vf_id
-= hw
->func_caps
.vf_base_id
;
5727 vf
= &pf
->vf
[vf_id
];
5728 i40e_vc_notify_vf_reset(vf
);
5729 /* Allow VF to process pending reset notification */
5731 i40e_reset_vf(vf
, false);
5736 * i40e_service_event_complete - Finish up the service event
5737 * @pf: board private structure
5739 static void i40e_service_event_complete(struct i40e_pf
*pf
)
5741 BUG_ON(!test_bit(__I40E_SERVICE_SCHED
, &pf
->state
));
5743 /* flush memory to make sure state is correct before next watchog */
5744 smp_mb__before_atomic();
5745 clear_bit(__I40E_SERVICE_SCHED
, &pf
->state
);
5749 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
5750 * @pf: board private structure
5752 u32
i40e_get_cur_guaranteed_fd_count(struct i40e_pf
*pf
)
5756 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
5757 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
);
5762 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
5763 * @pf: board private structure
5765 u32
i40e_get_current_fd_count(struct i40e_pf
*pf
)
5769 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
5770 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
) +
5771 ((val
& I40E_PFQF_FDSTAT_BEST_CNT_MASK
) >>
5772 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT
);
5777 * i40e_get_global_fd_count - Get total FD filters programmed on device
5778 * @pf: board private structure
5780 u32
i40e_get_global_fd_count(struct i40e_pf
*pf
)
5784 val
= rd32(&pf
->hw
, I40E_GLQF_FDCNT_0
);
5785 fcnt_prog
= (val
& I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK
) +
5786 ((val
& I40E_GLQF_FDCNT_0_BESTCNT_MASK
) >>
5787 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT
);
5792 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
5793 * @pf: board private structure
5795 void i40e_fdir_check_and_reenable(struct i40e_pf
*pf
)
5797 struct i40e_fdir_filter
*filter
;
5798 u32 fcnt_prog
, fcnt_avail
;
5799 struct hlist_node
*node
;
5801 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
5804 /* Check if, FD SB or ATR was auto disabled and if there is enough room
5807 fcnt_prog
= i40e_get_global_fd_count(pf
);
5808 fcnt_avail
= pf
->fdir_pf_filter_count
;
5809 if ((fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM
)) ||
5810 (pf
->fd_add_err
== 0) ||
5811 (i40e_get_current_atr_cnt(pf
) < pf
->fd_atr_cnt
)) {
5812 if ((pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) &&
5813 (pf
->auto_disable_flags
& I40E_FLAG_FD_SB_ENABLED
)) {
5814 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
5815 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5816 dev_info(&pf
->pdev
->dev
, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
5819 /* Wait for some more space to be available to turn on ATR */
5820 if (fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM
* 2)) {
5821 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
5822 (pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
)) {
5823 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
5824 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5825 dev_info(&pf
->pdev
->dev
, "ATR is being enabled since we have space in the table now\n");
5829 /* if hw had a problem adding a filter, delete it */
5830 if (pf
->fd_inv
> 0) {
5831 hlist_for_each_entry_safe(filter
, node
,
5832 &pf
->fdir_filter_list
, fdir_node
) {
5833 if (filter
->fd_id
== pf
->fd_inv
) {
5834 hlist_del(&filter
->fdir_node
);
5836 pf
->fdir_pf_active_filters
--;
5842 #define I40E_MIN_FD_FLUSH_INTERVAL 10
5843 #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
5845 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
5846 * @pf: board private structure
5848 static void i40e_fdir_flush_and_replay(struct i40e_pf
*pf
)
5850 unsigned long min_flush_time
;
5851 int flush_wait_retry
= 50;
5852 bool disable_atr
= false;
5856 if (!(pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
)))
5859 if (!time_after(jiffies
, pf
->fd_flush_timestamp
+
5860 (I40E_MIN_FD_FLUSH_INTERVAL
* HZ
)))
5863 /* If the flush is happening too quick and we have mostly SB rules we
5864 * should not re-enable ATR for some time.
5866 min_flush_time
= pf
->fd_flush_timestamp
+
5867 (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE
* HZ
);
5868 fd_room
= pf
->fdir_pf_filter_count
- pf
->fdir_pf_active_filters
;
5870 if (!(time_after(jiffies
, min_flush_time
)) &&
5871 (fd_room
< I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR
)) {
5872 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5873 dev_info(&pf
->pdev
->dev
, "ATR disabled, not enough FD filter space.\n");
5877 pf
->fd_flush_timestamp
= jiffies
;
5878 pf
->flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
5879 /* flush all filters */
5880 wr32(&pf
->hw
, I40E_PFQF_CTL_1
,
5881 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
);
5882 i40e_flush(&pf
->hw
);
5886 /* Check FD flush status every 5-6msec */
5887 usleep_range(5000, 6000);
5888 reg
= rd32(&pf
->hw
, I40E_PFQF_CTL_1
);
5889 if (!(reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
))
5891 } while (flush_wait_retry
--);
5892 if (reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
) {
5893 dev_warn(&pf
->pdev
->dev
, "FD table did not flush, needs more time\n");
5895 /* replay sideband filters */
5896 i40e_fdir_filter_restore(pf
->vsi
[pf
->lan_vsi
]);
5898 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
5899 clear_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
);
5900 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5901 dev_info(&pf
->pdev
->dev
, "FD Filter table flushed and FD-SB replayed.\n");
5907 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
5908 * @pf: board private structure
5910 u32
i40e_get_current_atr_cnt(struct i40e_pf
*pf
)
5912 return i40e_get_current_fd_count(pf
) - pf
->fdir_pf_active_filters
;
5915 /* We can see up to 256 filter programming desc in transit if the filters are
5916 * being applied really fast; before we see the first
5917 * filter miss error on Rx queue 0. Accumulating enough error messages before
5918 * reacting will make sure we don't cause flush too often.
5920 #define I40E_MAX_FD_PROGRAM_ERROR 256
5923 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
5924 * @pf: board private structure
5926 static void i40e_fdir_reinit_subtask(struct i40e_pf
*pf
)
5929 /* if interface is down do nothing */
5930 if (test_bit(__I40E_DOWN
, &pf
->state
))
5933 if (!(pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
)))
5936 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
5937 i40e_fdir_flush_and_replay(pf
);
5939 i40e_fdir_check_and_reenable(pf
);
5944 * i40e_vsi_link_event - notify VSI of a link event
5945 * @vsi: vsi to be notified
5946 * @link_up: link up or down
5948 static void i40e_vsi_link_event(struct i40e_vsi
*vsi
, bool link_up
)
5950 if (!vsi
|| test_bit(__I40E_DOWN
, &vsi
->state
))
5953 switch (vsi
->type
) {
5958 if (!vsi
->netdev
|| !vsi
->netdev_registered
)
5962 netif_carrier_on(vsi
->netdev
);
5963 netif_tx_wake_all_queues(vsi
->netdev
);
5965 netif_carrier_off(vsi
->netdev
);
5966 netif_tx_stop_all_queues(vsi
->netdev
);
5970 case I40E_VSI_SRIOV
:
5971 case I40E_VSI_VMDQ2
:
5973 case I40E_VSI_MIRROR
:
5975 /* there is no notification for other VSIs */
5981 * i40e_veb_link_event - notify elements on the veb of a link event
5982 * @veb: veb to be notified
5983 * @link_up: link up or down
5985 static void i40e_veb_link_event(struct i40e_veb
*veb
, bool link_up
)
5990 if (!veb
|| !veb
->pf
)
5994 /* depth first... */
5995 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
5996 if (pf
->veb
[i
] && (pf
->veb
[i
]->uplink_seid
== veb
->seid
))
5997 i40e_veb_link_event(pf
->veb
[i
], link_up
);
5999 /* ... now the local VSIs */
6000 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
6001 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->uplink_seid
== veb
->seid
))
6002 i40e_vsi_link_event(pf
->vsi
[i
], link_up
);
6006 * i40e_link_event - Update netif_carrier status
6007 * @pf: board private structure
6009 static void i40e_link_event(struct i40e_pf
*pf
)
6011 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
6012 u8 new_link_speed
, old_link_speed
;
6014 bool new_link
, old_link
;
6016 /* set this to force the get_link_status call to refresh state */
6017 pf
->hw
.phy
.get_link_info
= true;
6019 old_link
= (pf
->hw
.phy
.link_info_old
.link_info
& I40E_AQ_LINK_UP
);
6021 status
= i40e_get_link_status(&pf
->hw
, &new_link
);
6023 dev_dbg(&pf
->pdev
->dev
, "couldn't get link state, status: %d\n",
6028 old_link_speed
= pf
->hw
.phy
.link_info_old
.link_speed
;
6029 new_link_speed
= pf
->hw
.phy
.link_info
.link_speed
;
6031 if (new_link
== old_link
&&
6032 new_link_speed
== old_link_speed
&&
6033 (test_bit(__I40E_DOWN
, &vsi
->state
) ||
6034 new_link
== netif_carrier_ok(vsi
->netdev
)))
6037 if (!test_bit(__I40E_DOWN
, &vsi
->state
))
6038 i40e_print_link_message(vsi
, new_link
);
6040 /* Notify the base of the switch tree connected to
6041 * the link. Floating VEBs are not notified.
6043 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
6044 i40e_veb_link_event(pf
->veb
[pf
->lan_veb
], new_link
);
6046 i40e_vsi_link_event(vsi
, new_link
);
6049 i40e_vc_notify_link_state(pf
);
6051 if (pf
->flags
& I40E_FLAG_PTP
)
6052 i40e_ptp_set_increment(pf
);
6056 * i40e_watchdog_subtask - periodic checks not using event driven response
6057 * @pf: board private structure
6059 static void i40e_watchdog_subtask(struct i40e_pf
*pf
)
6063 /* if interface is down do nothing */
6064 if (test_bit(__I40E_DOWN
, &pf
->state
) ||
6065 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
6068 /* make sure we don't do these things too often */
6069 if (time_before(jiffies
, (pf
->service_timer_previous
+
6070 pf
->service_timer_period
)))
6072 pf
->service_timer_previous
= jiffies
;
6074 if (pf
->flags
& I40E_FLAG_LINK_POLLING_ENABLED
)
6075 i40e_link_event(pf
);
6077 /* Update the stats for active netdevs so the network stack
6078 * can look at updated numbers whenever it cares to
6080 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
6081 if (pf
->vsi
[i
] && pf
->vsi
[i
]->netdev
)
6082 i40e_update_stats(pf
->vsi
[i
]);
6084 if (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
) {
6085 /* Update the stats for the active switching components */
6086 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
6088 i40e_update_veb_stats(pf
->veb
[i
]);
6091 i40e_ptp_rx_hang(pf
->vsi
[pf
->lan_vsi
]);
6095 * i40e_reset_subtask - Set up for resetting the device and driver
6096 * @pf: board private structure
6098 static void i40e_reset_subtask(struct i40e_pf
*pf
)
6100 u32 reset_flags
= 0;
6103 if (test_bit(__I40E_REINIT_REQUESTED
, &pf
->state
)) {
6104 reset_flags
|= BIT_ULL(__I40E_REINIT_REQUESTED
);
6105 clear_bit(__I40E_REINIT_REQUESTED
, &pf
->state
);
6107 if (test_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
)) {
6108 reset_flags
|= BIT_ULL(__I40E_PF_RESET_REQUESTED
);
6109 clear_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
6111 if (test_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
)) {
6112 reset_flags
|= BIT_ULL(__I40E_CORE_RESET_REQUESTED
);
6113 clear_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
);
6115 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
)) {
6116 reset_flags
|= BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED
);
6117 clear_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
);
6119 if (test_bit(__I40E_DOWN_REQUESTED
, &pf
->state
)) {
6120 reset_flags
|= BIT_ULL(__I40E_DOWN_REQUESTED
);
6121 clear_bit(__I40E_DOWN_REQUESTED
, &pf
->state
);
6124 /* If there's a recovery already waiting, it takes
6125 * precedence before starting a new reset sequence.
6127 if (test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
)) {
6128 i40e_handle_reset_warning(pf
);
6132 /* If we're already down or resetting, just bail */
6134 !test_bit(__I40E_DOWN
, &pf
->state
) &&
6135 !test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
6136 i40e_do_reset(pf
, reset_flags
);
6143 * i40e_handle_link_event - Handle link event
6144 * @pf: board private structure
6145 * @e: event info posted on ARQ
6147 static void i40e_handle_link_event(struct i40e_pf
*pf
,
6148 struct i40e_arq_event_info
*e
)
6150 struct i40e_hw
*hw
= &pf
->hw
;
6151 struct i40e_aqc_get_link_status
*status
=
6152 (struct i40e_aqc_get_link_status
*)&e
->desc
.params
.raw
;
6154 /* save off old link status information */
6155 hw
->phy
.link_info_old
= hw
->phy
.link_info
;
6157 /* Do a new status request to re-enable LSE reporting
6158 * and load new status information into the hw struct
6159 * This completely ignores any state information
6160 * in the ARQ event info, instead choosing to always
6161 * issue the AQ update link status command.
6163 i40e_link_event(pf
);
6165 /* check for unqualified module, if link is down */
6166 if ((status
->link_info
& I40E_AQ_MEDIA_AVAILABLE
) &&
6167 (!(status
->an_info
& I40E_AQ_QUALIFIED_MODULE
)) &&
6168 (!(status
->link_info
& I40E_AQ_LINK_UP
)))
6169 dev_err(&pf
->pdev
->dev
,
6170 "The driver failed to link because an unqualified module was detected.\n");
6174 * i40e_clean_adminq_subtask - Clean the AdminQ rings
6175 * @pf: board private structure
6177 static void i40e_clean_adminq_subtask(struct i40e_pf
*pf
)
6179 struct i40e_arq_event_info event
;
6180 struct i40e_hw
*hw
= &pf
->hw
;
6187 /* Do not run clean AQ when PF reset fails */
6188 if (test_bit(__I40E_RESET_FAILED
, &pf
->state
))
6191 /* check for error indications */
6192 val
= rd32(&pf
->hw
, pf
->hw
.aq
.arq
.len
);
6194 if (val
& I40E_PF_ARQLEN_ARQVFE_MASK
) {
6195 dev_info(&pf
->pdev
->dev
, "ARQ VF Error detected\n");
6196 val
&= ~I40E_PF_ARQLEN_ARQVFE_MASK
;
6198 if (val
& I40E_PF_ARQLEN_ARQOVFL_MASK
) {
6199 dev_info(&pf
->pdev
->dev
, "ARQ Overflow Error detected\n");
6200 val
&= ~I40E_PF_ARQLEN_ARQOVFL_MASK
;
6202 if (val
& I40E_PF_ARQLEN_ARQCRIT_MASK
) {
6203 dev_info(&pf
->pdev
->dev
, "ARQ Critical Error detected\n");
6204 val
&= ~I40E_PF_ARQLEN_ARQCRIT_MASK
;
6207 wr32(&pf
->hw
, pf
->hw
.aq
.arq
.len
, val
);
6209 val
= rd32(&pf
->hw
, pf
->hw
.aq
.asq
.len
);
6211 if (val
& I40E_PF_ATQLEN_ATQVFE_MASK
) {
6212 dev_info(&pf
->pdev
->dev
, "ASQ VF Error detected\n");
6213 val
&= ~I40E_PF_ATQLEN_ATQVFE_MASK
;
6215 if (val
& I40E_PF_ATQLEN_ATQOVFL_MASK
) {
6216 dev_info(&pf
->pdev
->dev
, "ASQ Overflow Error detected\n");
6217 val
&= ~I40E_PF_ATQLEN_ATQOVFL_MASK
;
6219 if (val
& I40E_PF_ATQLEN_ATQCRIT_MASK
) {
6220 dev_info(&pf
->pdev
->dev
, "ASQ Critical Error detected\n");
6221 val
&= ~I40E_PF_ATQLEN_ATQCRIT_MASK
;
6224 wr32(&pf
->hw
, pf
->hw
.aq
.asq
.len
, val
);
6226 event
.buf_len
= I40E_MAX_AQ_BUF_SIZE
;
6227 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
6232 ret
= i40e_clean_arq_element(hw
, &event
, &pending
);
6233 if (ret
== I40E_ERR_ADMIN_QUEUE_NO_WORK
)
6236 dev_info(&pf
->pdev
->dev
, "ARQ event error %d\n", ret
);
6240 opcode
= le16_to_cpu(event
.desc
.opcode
);
6243 case i40e_aqc_opc_get_link_status
:
6244 i40e_handle_link_event(pf
, &event
);
6246 case i40e_aqc_opc_send_msg_to_pf
:
6247 ret
= i40e_vc_process_vf_msg(pf
,
6248 le16_to_cpu(event
.desc
.retval
),
6249 le32_to_cpu(event
.desc
.cookie_high
),
6250 le32_to_cpu(event
.desc
.cookie_low
),
6254 case i40e_aqc_opc_lldp_update_mib
:
6255 dev_dbg(&pf
->pdev
->dev
, "ARQ: Update LLDP MIB event received\n");
6256 #ifdef CONFIG_I40E_DCB
6258 ret
= i40e_handle_lldp_event(pf
, &event
);
6260 #endif /* CONFIG_I40E_DCB */
6262 case i40e_aqc_opc_event_lan_overflow
:
6263 dev_dbg(&pf
->pdev
->dev
, "ARQ LAN queue overflow event received\n");
6264 i40e_handle_lan_overflow_event(pf
, &event
);
6266 case i40e_aqc_opc_send_msg_to_peer
:
6267 dev_info(&pf
->pdev
->dev
, "ARQ: Msg from other pf\n");
6269 case i40e_aqc_opc_nvm_erase
:
6270 case i40e_aqc_opc_nvm_update
:
6271 i40e_debug(&pf
->hw
, I40E_DEBUG_NVM
, "ARQ NVM operation completed\n");
6274 dev_info(&pf
->pdev
->dev
,
6275 "ARQ Error: Unknown event 0x%04x received\n",
6279 } while (pending
&& (i
++ < pf
->adminq_work_limit
));
6281 clear_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
);
6282 /* re-enable Admin queue interrupt cause */
6283 val
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
6284 val
|= I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
6285 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
6288 kfree(event
.msg_buf
);
6292 * i40e_verify_eeprom - make sure eeprom is good to use
6293 * @pf: board private structure
6295 static void i40e_verify_eeprom(struct i40e_pf
*pf
)
6299 err
= i40e_diag_eeprom_test(&pf
->hw
);
6301 /* retry in case of garbage read */
6302 err
= i40e_diag_eeprom_test(&pf
->hw
);
6304 dev_info(&pf
->pdev
->dev
, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
6306 set_bit(__I40E_BAD_EEPROM
, &pf
->state
);
6310 if (!err
&& test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
6311 dev_info(&pf
->pdev
->dev
, "eeprom check passed, Tx/Rx traffic enabled\n");
6312 clear_bit(__I40E_BAD_EEPROM
, &pf
->state
);
6317 * i40e_enable_pf_switch_lb
6318 * @pf: pointer to the PF structure
6320 * enable switch loop back or die - no point in a return value
6322 static void i40e_enable_pf_switch_lb(struct i40e_pf
*pf
)
6324 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
6325 struct i40e_vsi_context ctxt
;
6328 ctxt
.seid
= pf
->main_vsi_seid
;
6329 ctxt
.pf_num
= pf
->hw
.pf_id
;
6331 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
6333 dev_info(&pf
->pdev
->dev
,
6334 "couldn't get PF vsi config, err %s aq_err %s\n",
6335 i40e_stat_str(&pf
->hw
, ret
),
6336 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6339 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
6340 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
6341 ctxt
.info
.switch_id
|= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
6343 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
6345 dev_info(&pf
->pdev
->dev
,
6346 "update vsi switch failed, err %s aq_err %s\n",
6347 i40e_stat_str(&pf
->hw
, ret
),
6348 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6353 * i40e_disable_pf_switch_lb
6354 * @pf: pointer to the PF structure
6356 * disable switch loop back or die - no point in a return value
6358 static void i40e_disable_pf_switch_lb(struct i40e_pf
*pf
)
6360 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
6361 struct i40e_vsi_context ctxt
;
6364 ctxt
.seid
= pf
->main_vsi_seid
;
6365 ctxt
.pf_num
= pf
->hw
.pf_id
;
6367 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
6369 dev_info(&pf
->pdev
->dev
,
6370 "couldn't get PF vsi config, err %s aq_err %s\n",
6371 i40e_stat_str(&pf
->hw
, ret
),
6372 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6375 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
6376 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
6377 ctxt
.info
.switch_id
&= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
6379 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
6381 dev_info(&pf
->pdev
->dev
,
6382 "update vsi switch failed, err %s aq_err %s\n",
6383 i40e_stat_str(&pf
->hw
, ret
),
6384 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6389 * i40e_config_bridge_mode - Configure the HW bridge mode
6390 * @veb: pointer to the bridge instance
6392 * Configure the loop back mode for the LAN VSI that is downlink to the
6393 * specified HW bridge instance. It is expected this function is called
6394 * when a new HW bridge is instantiated.
6396 static void i40e_config_bridge_mode(struct i40e_veb
*veb
)
6398 struct i40e_pf
*pf
= veb
->pf
;
6400 if (pf
->hw
.debug_mask
& I40E_DEBUG_LAN
)
6401 dev_info(&pf
->pdev
->dev
, "enabling bridge mode: %s\n",
6402 veb
->bridge_mode
== BRIDGE_MODE_VEPA
? "VEPA" : "VEB");
6403 if (veb
->bridge_mode
& BRIDGE_MODE_VEPA
)
6404 i40e_disable_pf_switch_lb(pf
);
6406 i40e_enable_pf_switch_lb(pf
);
6410 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
6411 * @veb: pointer to the VEB instance
6413 * This is a recursive function that first builds the attached VSIs then
6414 * recurses in to build the next layer of VEB. We track the connections
6415 * through our own index numbers because the seid's from the HW could
6416 * change across the reset.
6418 static int i40e_reconstitute_veb(struct i40e_veb
*veb
)
6420 struct i40e_vsi
*ctl_vsi
= NULL
;
6421 struct i40e_pf
*pf
= veb
->pf
;
6425 /* build VSI that owns this VEB, temporarily attached to base VEB */
6426 for (v
= 0; v
< pf
->num_alloc_vsi
&& !ctl_vsi
; v
++) {
6428 pf
->vsi
[v
]->veb_idx
== veb
->idx
&&
6429 pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
6430 ctl_vsi
= pf
->vsi
[v
];
6435 dev_info(&pf
->pdev
->dev
,
6436 "missing owner VSI for veb_idx %d\n", veb
->idx
);
6438 goto end_reconstitute
;
6440 if (ctl_vsi
!= pf
->vsi
[pf
->lan_vsi
])
6441 ctl_vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
6442 ret
= i40e_add_vsi(ctl_vsi
);
6444 dev_info(&pf
->pdev
->dev
,
6445 "rebuild of veb_idx %d owner VSI failed: %d\n",
6447 goto end_reconstitute
;
6449 i40e_vsi_reset_stats(ctl_vsi
);
6451 /* create the VEB in the switch and move the VSI onto the VEB */
6452 ret
= i40e_add_veb(veb
, ctl_vsi
);
6454 goto end_reconstitute
;
6456 if (pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)
6457 veb
->bridge_mode
= BRIDGE_MODE_VEB
;
6459 veb
->bridge_mode
= BRIDGE_MODE_VEPA
;
6460 i40e_config_bridge_mode(veb
);
6462 /* create the remaining VSIs attached to this VEB */
6463 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
6464 if (!pf
->vsi
[v
] || pf
->vsi
[v
] == ctl_vsi
)
6467 if (pf
->vsi
[v
]->veb_idx
== veb
->idx
) {
6468 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
6470 vsi
->uplink_seid
= veb
->seid
;
6471 ret
= i40e_add_vsi(vsi
);
6473 dev_info(&pf
->pdev
->dev
,
6474 "rebuild of vsi_idx %d failed: %d\n",
6476 goto end_reconstitute
;
6478 i40e_vsi_reset_stats(vsi
);
6482 /* create any VEBs attached to this VEB - RECURSION */
6483 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
6484 if (pf
->veb
[veb_idx
] && pf
->veb
[veb_idx
]->veb_idx
== veb
->idx
) {
6485 pf
->veb
[veb_idx
]->uplink_seid
= veb
->seid
;
6486 ret
= i40e_reconstitute_veb(pf
->veb
[veb_idx
]);
6497 * i40e_get_capabilities - get info about the HW
6498 * @pf: the PF struct
6500 static int i40e_get_capabilities(struct i40e_pf
*pf
)
6502 struct i40e_aqc_list_capabilities_element_resp
*cap_buf
;
6507 buf_len
= 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp
);
6509 cap_buf
= kzalloc(buf_len
, GFP_KERNEL
);
6513 /* this loads the data into the hw struct for us */
6514 err
= i40e_aq_discover_capabilities(&pf
->hw
, cap_buf
, buf_len
,
6516 i40e_aqc_opc_list_func_capabilities
,
6518 /* data loaded, buffer no longer needed */
6521 if (pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_ENOMEM
) {
6522 /* retry with a larger buffer */
6523 buf_len
= data_size
;
6524 } else if (pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_OK
) {
6525 dev_info(&pf
->pdev
->dev
,
6526 "capability discovery failed, err %s aq_err %s\n",
6527 i40e_stat_str(&pf
->hw
, err
),
6528 i40e_aq_str(&pf
->hw
,
6529 pf
->hw
.aq
.asq_last_status
));
6534 if (pf
->hw
.debug_mask
& I40E_DEBUG_USER
)
6535 dev_info(&pf
->pdev
->dev
,
6536 "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",
6537 pf
->hw
.pf_id
, pf
->hw
.func_caps
.num_vfs
,
6538 pf
->hw
.func_caps
.num_msix_vectors
,
6539 pf
->hw
.func_caps
.num_msix_vectors_vf
,
6540 pf
->hw
.func_caps
.fd_filters_guaranteed
,
6541 pf
->hw
.func_caps
.fd_filters_best_effort
,
6542 pf
->hw
.func_caps
.num_tx_qp
,
6543 pf
->hw
.func_caps
.num_vsis
);
6545 #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
6546 + pf->hw.func_caps.num_vfs)
6547 if (pf
->hw
.revision_id
== 0 && (DEF_NUM_VSI
> pf
->hw
.func_caps
.num_vsis
)) {
6548 dev_info(&pf
->pdev
->dev
,
6549 "got num_vsis %d, setting num_vsis to %d\n",
6550 pf
->hw
.func_caps
.num_vsis
, DEF_NUM_VSI
);
6551 pf
->hw
.func_caps
.num_vsis
= DEF_NUM_VSI
;
6557 static int i40e_vsi_clear(struct i40e_vsi
*vsi
);
6560 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
6561 * @pf: board private structure
6563 static void i40e_fdir_sb_setup(struct i40e_pf
*pf
)
6565 struct i40e_vsi
*vsi
;
6568 /* quick workaround for an NVM issue that leaves a critical register
6571 if (!rd32(&pf
->hw
, I40E_GLQF_HKEY(0))) {
6572 static const u32 hkey
[] = {
6573 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
6574 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
6575 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
6578 for (i
= 0; i
<= I40E_GLQF_HKEY_MAX_INDEX
; i
++)
6579 wr32(&pf
->hw
, I40E_GLQF_HKEY(i
), hkey
[i
]);
6582 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
6585 /* find existing VSI and see if it needs configuring */
6587 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
6588 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
6594 /* create a new VSI if none exists */
6596 vsi
= i40e_vsi_setup(pf
, I40E_VSI_FDIR
,
6597 pf
->vsi
[pf
->lan_vsi
]->seid
, 0);
6599 dev_info(&pf
->pdev
->dev
, "Couldn't create FDir VSI\n");
6600 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
6605 i40e_vsi_setup_irqhandler(vsi
, i40e_fdir_clean_ring
);
6609 * i40e_fdir_teardown - release the Flow Director resources
6610 * @pf: board private structure
6612 static void i40e_fdir_teardown(struct i40e_pf
*pf
)
6616 i40e_fdir_filter_exit(pf
);
6617 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
6618 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
6619 i40e_vsi_release(pf
->vsi
[i
]);
6626 * i40e_prep_for_reset - prep for the core to reset
6627 * @pf: board private structure
6629 * Close up the VFs and other things in prep for PF Reset.
6631 static void i40e_prep_for_reset(struct i40e_pf
*pf
)
6633 struct i40e_hw
*hw
= &pf
->hw
;
6634 i40e_status ret
= 0;
6637 clear_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
);
6638 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
))
6641 dev_dbg(&pf
->pdev
->dev
, "Tearing down internal switch for reset\n");
6643 /* quiesce the VSIs and their queues that are not already DOWN */
6644 i40e_pf_quiesce_all_vsi(pf
);
6646 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
6648 pf
->vsi
[v
]->seid
= 0;
6651 i40e_shutdown_adminq(&pf
->hw
);
6653 /* call shutdown HMC */
6654 if (hw
->hmc
.hmc_obj
) {
6655 ret
= i40e_shutdown_lan_hmc(hw
);
6657 dev_warn(&pf
->pdev
->dev
,
6658 "shutdown_lan_hmc failed: %d\n", ret
);
6663 * i40e_send_version - update firmware with driver version
6666 static void i40e_send_version(struct i40e_pf
*pf
)
6668 struct i40e_driver_version dv
;
6670 dv
.major_version
= DRV_VERSION_MAJOR
;
6671 dv
.minor_version
= DRV_VERSION_MINOR
;
6672 dv
.build_version
= DRV_VERSION_BUILD
;
6673 dv
.subbuild_version
= 0;
6674 strlcpy(dv
.driver_string
, DRV_VERSION
, sizeof(dv
.driver_string
));
6675 i40e_aq_send_driver_version(&pf
->hw
, &dv
, NULL
);
6679 * i40e_reset_and_rebuild - reset and rebuild using a saved config
6680 * @pf: board private structure
6681 * @reinit: if the Main VSI needs to re-initialized.
6683 static void i40e_reset_and_rebuild(struct i40e_pf
*pf
, bool reinit
)
6685 struct i40e_hw
*hw
= &pf
->hw
;
6686 u8 set_fc_aq_fail
= 0;
6690 /* Now we wait for GRST to settle out.
6691 * We don't have to delete the VEBs or VSIs from the hw switch
6692 * because the reset will make them disappear.
6694 ret
= i40e_pf_reset(hw
);
6696 dev_info(&pf
->pdev
->dev
, "PF reset failed, %d\n", ret
);
6697 set_bit(__I40E_RESET_FAILED
, &pf
->state
);
6698 goto clear_recovery
;
6702 if (test_bit(__I40E_DOWN
, &pf
->state
))
6703 goto clear_recovery
;
6704 dev_dbg(&pf
->pdev
->dev
, "Rebuilding internal switch\n");
6706 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
6707 ret
= i40e_init_adminq(&pf
->hw
);
6709 dev_info(&pf
->pdev
->dev
, "Rebuild AdminQ failed, err %s aq_err %s\n",
6710 i40e_stat_str(&pf
->hw
, ret
),
6711 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6712 goto clear_recovery
;
6715 /* re-verify the eeprom if we just had an EMP reset */
6716 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED
, &pf
->state
))
6717 i40e_verify_eeprom(pf
);
6719 i40e_clear_pxe_mode(hw
);
6720 ret
= i40e_get_capabilities(pf
);
6722 goto end_core_reset
;
6724 ret
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
6725 hw
->func_caps
.num_rx_qp
,
6726 pf
->fcoe_hmc_cntx_num
, pf
->fcoe_hmc_filt_num
);
6728 dev_info(&pf
->pdev
->dev
, "init_lan_hmc failed: %d\n", ret
);
6729 goto end_core_reset
;
6731 ret
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
6733 dev_info(&pf
->pdev
->dev
, "configure_lan_hmc failed: %d\n", ret
);
6734 goto end_core_reset
;
6737 #ifdef CONFIG_I40E_DCB
6738 ret
= i40e_init_pf_dcb(pf
);
6740 dev_info(&pf
->pdev
->dev
, "DCB init failed %d, disabled\n", ret
);
6741 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
6742 /* Continue without DCB enabled */
6744 #endif /* CONFIG_I40E_DCB */
6746 i40e_init_pf_fcoe(pf
);
6749 /* do basic switch setup */
6750 ret
= i40e_setup_pf_switch(pf
, reinit
);
6752 goto end_core_reset
;
6754 /* driver is only interested in link up/down and module qualification
6755 * reports from firmware
6757 ret
= i40e_aq_set_phy_int_mask(&pf
->hw
,
6758 I40E_AQ_EVENT_LINK_UPDOWN
|
6759 I40E_AQ_EVENT_MODULE_QUAL_FAIL
, NULL
);
6761 dev_info(&pf
->pdev
->dev
, "set phy mask fail, err %s aq_err %s\n",
6762 i40e_stat_str(&pf
->hw
, ret
),
6763 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6765 /* make sure our flow control settings are restored */
6766 ret
= i40e_set_fc(&pf
->hw
, &set_fc_aq_fail
, true);
6768 dev_dbg(&pf
->pdev
->dev
, "setting flow control: ret = %s last_status = %s\n",
6769 i40e_stat_str(&pf
->hw
, ret
),
6770 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6772 /* Rebuild the VSIs and VEBs that existed before reset.
6773 * They are still in our local switch element arrays, so only
6774 * need to rebuild the switch model in the HW.
6776 * If there were VEBs but the reconstitution failed, we'll try
6777 * try to recover minimal use by getting the basic PF VSI working.
6779 if (pf
->vsi
[pf
->lan_vsi
]->uplink_seid
!= pf
->mac_seid
) {
6780 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild switch\n");
6781 /* find the one VEB connected to the MAC, and find orphans */
6782 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
6786 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
||
6787 pf
->veb
[v
]->uplink_seid
== 0) {
6788 ret
= i40e_reconstitute_veb(pf
->veb
[v
]);
6793 /* If Main VEB failed, we're in deep doodoo,
6794 * so give up rebuilding the switch and set up
6795 * for minimal rebuild of PF VSI.
6796 * If orphan failed, we'll report the error
6797 * but try to keep going.
6799 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
) {
6800 dev_info(&pf
->pdev
->dev
,
6801 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
6803 pf
->vsi
[pf
->lan_vsi
]->uplink_seid
6806 } else if (pf
->veb
[v
]->uplink_seid
== 0) {
6807 dev_info(&pf
->pdev
->dev
,
6808 "rebuild of orphan VEB failed: %d\n",
6815 if (pf
->vsi
[pf
->lan_vsi
]->uplink_seid
== pf
->mac_seid
) {
6816 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild PF VSI\n");
6817 /* no VEB, so rebuild only the Main VSI */
6818 ret
= i40e_add_vsi(pf
->vsi
[pf
->lan_vsi
]);
6820 dev_info(&pf
->pdev
->dev
,
6821 "rebuild of Main VSI failed: %d\n", ret
);
6822 goto end_core_reset
;
6826 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
6827 (pf
->hw
.aq
.fw_maj_ver
< 4)) {
6829 ret
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
6831 dev_info(&pf
->pdev
->dev
, "link restart failed, err %s aq_err %s\n",
6832 i40e_stat_str(&pf
->hw
, ret
),
6833 i40e_aq_str(&pf
->hw
,
6834 pf
->hw
.aq
.asq_last_status
));
6836 /* reinit the misc interrupt */
6837 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
6838 ret
= i40e_setup_misc_vector(pf
);
6840 /* Add a filter to drop all Flow control frames from any VSI from being
6841 * transmitted. By doing so we stop a malicious VF from sending out
6842 * PAUSE or PFC frames and potentially controlling traffic for other
6844 * The FW can still send Flow control frames if enabled.
6846 i40e_add_filter_to_drop_tx_flow_control_frames(&pf
->hw
,
6849 /* restart the VSIs that were rebuilt and running before the reset */
6850 i40e_pf_unquiesce_all_vsi(pf
);
6852 if (pf
->num_alloc_vfs
) {
6853 for (v
= 0; v
< pf
->num_alloc_vfs
; v
++)
6854 i40e_reset_vf(&pf
->vf
[v
], true);
6857 /* tell the firmware that we're starting */
6858 i40e_send_version(pf
);
6861 clear_bit(__I40E_RESET_FAILED
, &pf
->state
);
6863 clear_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
);
6867 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
6868 * @pf: board private structure
6870 * Close up the VFs and other things in prep for a Core Reset,
6871 * then get ready to rebuild the world.
6873 static void i40e_handle_reset_warning(struct i40e_pf
*pf
)
6875 i40e_prep_for_reset(pf
);
6876 i40e_reset_and_rebuild(pf
, false);
6880 * i40e_handle_mdd_event
6881 * @pf: pointer to the PF structure
6883 * Called from the MDD irq handler to identify possibly malicious vfs
6885 static void i40e_handle_mdd_event(struct i40e_pf
*pf
)
6887 struct i40e_hw
*hw
= &pf
->hw
;
6888 bool mdd_detected
= false;
6889 bool pf_mdd_detected
= false;
6894 if (!test_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
))
6897 /* find what triggered the MDD event */
6898 reg
= rd32(hw
, I40E_GL_MDET_TX
);
6899 if (reg
& I40E_GL_MDET_TX_VALID_MASK
) {
6900 u8 pf_num
= (reg
& I40E_GL_MDET_TX_PF_NUM_MASK
) >>
6901 I40E_GL_MDET_TX_PF_NUM_SHIFT
;
6902 u16 vf_num
= (reg
& I40E_GL_MDET_TX_VF_NUM_MASK
) >>
6903 I40E_GL_MDET_TX_VF_NUM_SHIFT
;
6904 u8 event
= (reg
& I40E_GL_MDET_TX_EVENT_MASK
) >>
6905 I40E_GL_MDET_TX_EVENT_SHIFT
;
6906 u16 queue
= ((reg
& I40E_GL_MDET_TX_QUEUE_MASK
) >>
6907 I40E_GL_MDET_TX_QUEUE_SHIFT
) -
6908 pf
->hw
.func_caps
.base_queue
;
6909 if (netif_msg_tx_err(pf
))
6910 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
6911 event
, queue
, pf_num
, vf_num
);
6912 wr32(hw
, I40E_GL_MDET_TX
, 0xffffffff);
6913 mdd_detected
= true;
6915 reg
= rd32(hw
, I40E_GL_MDET_RX
);
6916 if (reg
& I40E_GL_MDET_RX_VALID_MASK
) {
6917 u8 func
= (reg
& I40E_GL_MDET_RX_FUNCTION_MASK
) >>
6918 I40E_GL_MDET_RX_FUNCTION_SHIFT
;
6919 u8 event
= (reg
& I40E_GL_MDET_RX_EVENT_MASK
) >>
6920 I40E_GL_MDET_RX_EVENT_SHIFT
;
6921 u16 queue
= ((reg
& I40E_GL_MDET_RX_QUEUE_MASK
) >>
6922 I40E_GL_MDET_RX_QUEUE_SHIFT
) -
6923 pf
->hw
.func_caps
.base_queue
;
6924 if (netif_msg_rx_err(pf
))
6925 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
6926 event
, queue
, func
);
6927 wr32(hw
, I40E_GL_MDET_RX
, 0xffffffff);
6928 mdd_detected
= true;
6932 reg
= rd32(hw
, I40E_PF_MDET_TX
);
6933 if (reg
& I40E_PF_MDET_TX_VALID_MASK
) {
6934 wr32(hw
, I40E_PF_MDET_TX
, 0xFFFF);
6935 dev_info(&pf
->pdev
->dev
, "TX driver issue detected, PF reset issued\n");
6936 pf_mdd_detected
= true;
6938 reg
= rd32(hw
, I40E_PF_MDET_RX
);
6939 if (reg
& I40E_PF_MDET_RX_VALID_MASK
) {
6940 wr32(hw
, I40E_PF_MDET_RX
, 0xFFFF);
6941 dev_info(&pf
->pdev
->dev
, "RX driver issue detected, PF reset issued\n");
6942 pf_mdd_detected
= true;
6944 /* Queue belongs to the PF, initiate a reset */
6945 if (pf_mdd_detected
) {
6946 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
6947 i40e_service_event_schedule(pf
);
6951 /* see if one of the VFs needs its hand slapped */
6952 for (i
= 0; i
< pf
->num_alloc_vfs
&& mdd_detected
; i
++) {
6954 reg
= rd32(hw
, I40E_VP_MDET_TX(i
));
6955 if (reg
& I40E_VP_MDET_TX_VALID_MASK
) {
6956 wr32(hw
, I40E_VP_MDET_TX(i
), 0xFFFF);
6957 vf
->num_mdd_events
++;
6958 dev_info(&pf
->pdev
->dev
, "TX driver issue detected on VF %d\n",
6962 reg
= rd32(hw
, I40E_VP_MDET_RX(i
));
6963 if (reg
& I40E_VP_MDET_RX_VALID_MASK
) {
6964 wr32(hw
, I40E_VP_MDET_RX(i
), 0xFFFF);
6965 vf
->num_mdd_events
++;
6966 dev_info(&pf
->pdev
->dev
, "RX driver issue detected on VF %d\n",
6970 if (vf
->num_mdd_events
> I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED
) {
6971 dev_info(&pf
->pdev
->dev
,
6972 "Too many MDD events on VF %d, disabled\n", i
);
6973 dev_info(&pf
->pdev
->dev
,
6974 "Use PF Control I/F to re-enable the VF\n");
6975 set_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
);
6979 /* re-enable mdd interrupt cause */
6980 clear_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
);
6981 reg
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
6982 reg
|= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
6983 wr32(hw
, I40E_PFINT_ICR0_ENA
, reg
);
6987 #ifdef CONFIG_I40E_VXLAN
6989 * i40e_sync_vxlan_filters_subtask - Sync the VSI filter list with HW
6990 * @pf: board private structure
6992 static void i40e_sync_vxlan_filters_subtask(struct i40e_pf
*pf
)
6994 struct i40e_hw
*hw
= &pf
->hw
;
6999 if (!(pf
->flags
& I40E_FLAG_VXLAN_FILTER_SYNC
))
7002 pf
->flags
&= ~I40E_FLAG_VXLAN_FILTER_SYNC
;
7004 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
7005 if (pf
->pending_vxlan_bitmap
& BIT_ULL(i
)) {
7006 pf
->pending_vxlan_bitmap
&= ~BIT_ULL(i
);
7007 port
= pf
->vxlan_ports
[i
];
7009 ret
= i40e_aq_add_udp_tunnel(hw
, ntohs(port
),
7010 I40E_AQC_TUNNEL_TYPE_VXLAN
,
7013 ret
= i40e_aq_del_udp_tunnel(hw
, i
, NULL
);
7016 dev_info(&pf
->pdev
->dev
,
7017 "%s vxlan port %d, index %d failed, err %s aq_err %s\n",
7018 port
? "add" : "delete",
7020 i40e_stat_str(&pf
->hw
, ret
),
7021 i40e_aq_str(&pf
->hw
,
7022 pf
->hw
.aq
.asq_last_status
));
7023 pf
->vxlan_ports
[i
] = 0;
7031 * i40e_service_task - Run the driver's async subtasks
7032 * @work: pointer to work_struct containing our data
7034 static void i40e_service_task(struct work_struct
*work
)
7036 struct i40e_pf
*pf
= container_of(work
,
7039 unsigned long start_time
= jiffies
;
7041 /* don't bother with service tasks if a reset is in progress */
7042 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
)) {
7043 i40e_service_event_complete(pf
);
7047 i40e_detect_recover_hung(pf
);
7048 i40e_reset_subtask(pf
);
7049 i40e_handle_mdd_event(pf
);
7050 i40e_vc_process_vflr_event(pf
);
7051 i40e_watchdog_subtask(pf
);
7052 i40e_fdir_reinit_subtask(pf
);
7053 i40e_sync_filters_subtask(pf
);
7054 #ifdef CONFIG_I40E_VXLAN
7055 i40e_sync_vxlan_filters_subtask(pf
);
7057 i40e_clean_adminq_subtask(pf
);
7059 i40e_service_event_complete(pf
);
7061 /* If the tasks have taken longer than one timer cycle or there
7062 * is more work to be done, reschedule the service task now
7063 * rather than wait for the timer to tick again.
7065 if (time_after(jiffies
, (start_time
+ pf
->service_timer_period
)) ||
7066 test_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
) ||
7067 test_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
) ||
7068 test_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
))
7069 i40e_service_event_schedule(pf
);
7073 * i40e_service_timer - timer callback
7074 * @data: pointer to PF struct
7076 static void i40e_service_timer(unsigned long data
)
7078 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
7080 mod_timer(&pf
->service_timer
,
7081 round_jiffies(jiffies
+ pf
->service_timer_period
));
7082 i40e_service_event_schedule(pf
);
7086 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
7087 * @vsi: the VSI being configured
7089 static int i40e_set_num_rings_in_vsi(struct i40e_vsi
*vsi
)
7091 struct i40e_pf
*pf
= vsi
->back
;
7093 switch (vsi
->type
) {
7095 vsi
->alloc_queue_pairs
= pf
->num_lan_qps
;
7096 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
7097 I40E_REQ_DESCRIPTOR_MULTIPLE
);
7098 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
7099 vsi
->num_q_vectors
= pf
->num_lan_msix
;
7101 vsi
->num_q_vectors
= 1;
7106 vsi
->alloc_queue_pairs
= 1;
7107 vsi
->num_desc
= ALIGN(I40E_FDIR_RING_COUNT
,
7108 I40E_REQ_DESCRIPTOR_MULTIPLE
);
7109 vsi
->num_q_vectors
= 1;
7112 case I40E_VSI_VMDQ2
:
7113 vsi
->alloc_queue_pairs
= pf
->num_vmdq_qps
;
7114 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
7115 I40E_REQ_DESCRIPTOR_MULTIPLE
);
7116 vsi
->num_q_vectors
= pf
->num_vmdq_msix
;
7119 case I40E_VSI_SRIOV
:
7120 vsi
->alloc_queue_pairs
= pf
->num_vf_qps
;
7121 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
7122 I40E_REQ_DESCRIPTOR_MULTIPLE
);
7127 vsi
->alloc_queue_pairs
= pf
->num_fcoe_qps
;
7128 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
7129 I40E_REQ_DESCRIPTOR_MULTIPLE
);
7130 vsi
->num_q_vectors
= pf
->num_fcoe_msix
;
7133 #endif /* I40E_FCOE */
7143 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
7144 * @type: VSI pointer
7145 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
7147 * On error: returns error code (negative)
7148 * On success: returns 0
7150 static int i40e_vsi_alloc_arrays(struct i40e_vsi
*vsi
, bool alloc_qvectors
)
7155 /* allocate memory for both Tx and Rx ring pointers */
7156 size
= sizeof(struct i40e_ring
*) * vsi
->alloc_queue_pairs
* 2;
7157 vsi
->tx_rings
= kzalloc(size
, GFP_KERNEL
);
7160 vsi
->rx_rings
= &vsi
->tx_rings
[vsi
->alloc_queue_pairs
];
7162 if (alloc_qvectors
) {
7163 /* allocate memory for q_vector pointers */
7164 size
= sizeof(struct i40e_q_vector
*) * vsi
->num_q_vectors
;
7165 vsi
->q_vectors
= kzalloc(size
, GFP_KERNEL
);
7166 if (!vsi
->q_vectors
) {
7174 kfree(vsi
->tx_rings
);
7179 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
7180 * @pf: board private structure
7181 * @type: type of VSI
7183 * On error: returns error code (negative)
7184 * On success: returns vsi index in PF (positive)
7186 static int i40e_vsi_mem_alloc(struct i40e_pf
*pf
, enum i40e_vsi_type type
)
7189 struct i40e_vsi
*vsi
;
7193 /* Need to protect the allocation of the VSIs at the PF level */
7194 mutex_lock(&pf
->switch_mutex
);
7196 /* VSI list may be fragmented if VSI creation/destruction has
7197 * been happening. We can afford to do a quick scan to look
7198 * for any free VSIs in the list.
7200 * find next empty vsi slot, looping back around if necessary
7203 while (i
< pf
->num_alloc_vsi
&& pf
->vsi
[i
])
7205 if (i
>= pf
->num_alloc_vsi
) {
7207 while (i
< pf
->next_vsi
&& pf
->vsi
[i
])
7211 if (i
< pf
->num_alloc_vsi
&& !pf
->vsi
[i
]) {
7212 vsi_idx
= i
; /* Found one! */
7215 goto unlock_pf
; /* out of VSI slots! */
7219 vsi
= kzalloc(sizeof(*vsi
), GFP_KERNEL
);
7226 set_bit(__I40E_DOWN
, &vsi
->state
);
7229 vsi
->rx_itr_setting
= pf
->rx_itr_default
;
7230 vsi
->tx_itr_setting
= pf
->tx_itr_default
;
7231 vsi
->int_rate_limit
= 0;
7232 vsi
->rss_table_size
= (vsi
->type
== I40E_VSI_MAIN
) ?
7233 pf
->rss_table_size
: 64;
7234 vsi
->netdev_registered
= false;
7235 vsi
->work_limit
= I40E_DEFAULT_IRQ_WORK
;
7236 INIT_LIST_HEAD(&vsi
->mac_filter_list
);
7237 vsi
->irqs_ready
= false;
7239 ret
= i40e_set_num_rings_in_vsi(vsi
);
7243 ret
= i40e_vsi_alloc_arrays(vsi
, true);
7247 /* Setup default MSIX irq handler for VSI */
7248 i40e_vsi_setup_irqhandler(vsi
, i40e_msix_clean_rings
);
7250 /* Initialize VSI lock */
7251 spin_lock_init(&vsi
->mac_filter_list_lock
);
7252 pf
->vsi
[vsi_idx
] = vsi
;
7257 pf
->next_vsi
= i
- 1;
7260 mutex_unlock(&pf
->switch_mutex
);
7265 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
7266 * @type: VSI pointer
7267 * @free_qvectors: a bool to specify if q_vectors need to be freed.
7269 * On error: returns error code (negative)
7270 * On success: returns 0
7272 static void i40e_vsi_free_arrays(struct i40e_vsi
*vsi
, bool free_qvectors
)
7274 /* free the ring and vector containers */
7275 if (free_qvectors
) {
7276 kfree(vsi
->q_vectors
);
7277 vsi
->q_vectors
= NULL
;
7279 kfree(vsi
->tx_rings
);
7280 vsi
->tx_rings
= NULL
;
7281 vsi
->rx_rings
= NULL
;
7285 * i40e_vsi_clear - Deallocate the VSI provided
7286 * @vsi: the VSI being un-configured
7288 static int i40e_vsi_clear(struct i40e_vsi
*vsi
)
7299 mutex_lock(&pf
->switch_mutex
);
7300 if (!pf
->vsi
[vsi
->idx
]) {
7301 dev_err(&pf
->pdev
->dev
, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
7302 vsi
->idx
, vsi
->idx
, vsi
, vsi
->type
);
7306 if (pf
->vsi
[vsi
->idx
] != vsi
) {
7307 dev_err(&pf
->pdev
->dev
,
7308 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
7309 pf
->vsi
[vsi
->idx
]->idx
,
7311 pf
->vsi
[vsi
->idx
]->type
,
7312 vsi
->idx
, vsi
, vsi
->type
);
7316 /* updates the PF for this cleared vsi */
7317 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
7318 i40e_put_lump(pf
->irq_pile
, vsi
->base_vector
, vsi
->idx
);
7320 i40e_vsi_free_arrays(vsi
, true);
7322 pf
->vsi
[vsi
->idx
] = NULL
;
7323 if (vsi
->idx
< pf
->next_vsi
)
7324 pf
->next_vsi
= vsi
->idx
;
7327 mutex_unlock(&pf
->switch_mutex
);
7335 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
7336 * @vsi: the VSI being cleaned
7338 static void i40e_vsi_clear_rings(struct i40e_vsi
*vsi
)
7342 if (vsi
->tx_rings
&& vsi
->tx_rings
[0]) {
7343 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
7344 kfree_rcu(vsi
->tx_rings
[i
], rcu
);
7345 vsi
->tx_rings
[i
] = NULL
;
7346 vsi
->rx_rings
[i
] = NULL
;
7352 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
7353 * @vsi: the VSI being configured
7355 static int i40e_alloc_rings(struct i40e_vsi
*vsi
)
7357 struct i40e_ring
*tx_ring
, *rx_ring
;
7358 struct i40e_pf
*pf
= vsi
->back
;
7361 /* Set basic values in the rings to be used later during open() */
7362 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
7363 /* allocate space for both Tx and Rx in one shot */
7364 tx_ring
= kzalloc(sizeof(struct i40e_ring
) * 2, GFP_KERNEL
);
7368 tx_ring
->queue_index
= i
;
7369 tx_ring
->reg_idx
= vsi
->base_queue
+ i
;
7370 tx_ring
->ring_active
= false;
7372 tx_ring
->netdev
= vsi
->netdev
;
7373 tx_ring
->dev
= &pf
->pdev
->dev
;
7374 tx_ring
->count
= vsi
->num_desc
;
7376 tx_ring
->dcb_tc
= 0;
7377 if (vsi
->back
->flags
& I40E_FLAG_WB_ON_ITR_CAPABLE
)
7378 tx_ring
->flags
= I40E_TXR_FLAGS_WB_ON_ITR
;
7379 if (vsi
->back
->flags
& I40E_FLAG_OUTER_UDP_CSUM_CAPABLE
)
7380 tx_ring
->flags
|= I40E_TXR_FLAGS_OUTER_UDP_CSUM
;
7381 vsi
->tx_rings
[i
] = tx_ring
;
7383 rx_ring
= &tx_ring
[1];
7384 rx_ring
->queue_index
= i
;
7385 rx_ring
->reg_idx
= vsi
->base_queue
+ i
;
7386 rx_ring
->ring_active
= false;
7388 rx_ring
->netdev
= vsi
->netdev
;
7389 rx_ring
->dev
= &pf
->pdev
->dev
;
7390 rx_ring
->count
= vsi
->num_desc
;
7392 rx_ring
->dcb_tc
= 0;
7393 if (pf
->flags
& I40E_FLAG_16BYTE_RX_DESC_ENABLED
)
7394 set_ring_16byte_desc_enabled(rx_ring
);
7396 clear_ring_16byte_desc_enabled(rx_ring
);
7397 vsi
->rx_rings
[i
] = rx_ring
;
7403 i40e_vsi_clear_rings(vsi
);
7408 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
7409 * @pf: board private structure
7410 * @vectors: the number of MSI-X vectors to request
7412 * Returns the number of vectors reserved, or error
7414 static int i40e_reserve_msix_vectors(struct i40e_pf
*pf
, int vectors
)
7416 vectors
= pci_enable_msix_range(pf
->pdev
, pf
->msix_entries
,
7417 I40E_MIN_MSIX
, vectors
);
7419 dev_info(&pf
->pdev
->dev
,
7420 "MSI-X vector reservation failed: %d\n", vectors
);
7428 * i40e_init_msix - Setup the MSIX capability
7429 * @pf: board private structure
7431 * Work with the OS to set up the MSIX vectors needed.
7433 * Returns the number of vectors reserved or negative on failure
7435 static int i40e_init_msix(struct i40e_pf
*pf
)
7437 struct i40e_hw
*hw
= &pf
->hw
;
7442 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
7445 /* The number of vectors we'll request will be comprised of:
7446 * - Add 1 for "other" cause for Admin Queue events, etc.
7447 * - The number of LAN queue pairs
7448 * - Queues being used for RSS.
7449 * We don't need as many as max_rss_size vectors.
7450 * use rss_size instead in the calculation since that
7451 * is governed by number of cpus in the system.
7452 * - assumes symmetric Tx/Rx pairing
7453 * - The number of VMDq pairs
7455 * - The number of FCOE qps.
7457 * Once we count this up, try the request.
7459 * If we can't get what we want, we'll simplify to nearly nothing
7460 * and try again. If that still fails, we punt.
7462 vectors_left
= hw
->func_caps
.num_msix_vectors
;
7465 /* reserve one vector for miscellaneous handler */
7471 /* reserve vectors for the main PF traffic queues */
7472 pf
->num_lan_msix
= min_t(int, num_online_cpus(), vectors_left
);
7473 vectors_left
-= pf
->num_lan_msix
;
7474 v_budget
+= pf
->num_lan_msix
;
7476 /* reserve one vector for sideband flow director */
7477 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
7482 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7487 /* can we reserve enough for FCoE? */
7488 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7490 pf
->num_fcoe_msix
= 0;
7491 else if (vectors_left
>= pf
->num_fcoe_qps
)
7492 pf
->num_fcoe_msix
= pf
->num_fcoe_qps
;
7494 pf
->num_fcoe_msix
= 1;
7495 v_budget
+= pf
->num_fcoe_msix
;
7496 vectors_left
-= pf
->num_fcoe_msix
;
7500 /* any vectors left over go for VMDq support */
7501 if (pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) {
7502 int vmdq_vecs_wanted
= pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
;
7503 int vmdq_vecs
= min_t(int, vectors_left
, vmdq_vecs_wanted
);
7505 /* if we're short on vectors for what's desired, we limit
7506 * the queues per vmdq. If this is still more than are
7507 * available, the user will need to change the number of
7508 * queues/vectors used by the PF later with the ethtool
7511 if (vmdq_vecs
< vmdq_vecs_wanted
)
7512 pf
->num_vmdq_qps
= 1;
7513 pf
->num_vmdq_msix
= pf
->num_vmdq_qps
;
7515 v_budget
+= vmdq_vecs
;
7516 vectors_left
-= vmdq_vecs
;
7519 pf
->msix_entries
= kcalloc(v_budget
, sizeof(struct msix_entry
),
7521 if (!pf
->msix_entries
)
7524 for (i
= 0; i
< v_budget
; i
++)
7525 pf
->msix_entries
[i
].entry
= i
;
7526 v_actual
= i40e_reserve_msix_vectors(pf
, v_budget
);
7528 if (v_actual
!= v_budget
) {
7529 /* If we have limited resources, we will start with no vectors
7530 * for the special features and then allocate vectors to some
7531 * of these features based on the policy and at the end disable
7532 * the features that did not get any vectors.
7535 pf
->num_fcoe_qps
= 0;
7536 pf
->num_fcoe_msix
= 0;
7538 pf
->num_vmdq_msix
= 0;
7541 if (v_actual
< I40E_MIN_MSIX
) {
7542 pf
->flags
&= ~I40E_FLAG_MSIX_ENABLED
;
7543 kfree(pf
->msix_entries
);
7544 pf
->msix_entries
= NULL
;
7547 } else if (v_actual
== I40E_MIN_MSIX
) {
7548 /* Adjust for minimal MSIX use */
7549 pf
->num_vmdq_vsis
= 0;
7550 pf
->num_vmdq_qps
= 0;
7551 pf
->num_lan_qps
= 1;
7552 pf
->num_lan_msix
= 1;
7554 } else if (v_actual
!= v_budget
) {
7557 /* reserve the misc vector */
7560 /* Scale vector usage down */
7561 pf
->num_vmdq_msix
= 1; /* force VMDqs to only one vector */
7562 pf
->num_vmdq_vsis
= 1;
7563 pf
->num_vmdq_qps
= 1;
7564 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7566 /* partition out the remaining vectors */
7569 pf
->num_lan_msix
= 1;
7573 /* give one vector to FCoE */
7574 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7575 pf
->num_lan_msix
= 1;
7576 pf
->num_fcoe_msix
= 1;
7579 pf
->num_lan_msix
= 2;
7584 /* give one vector to FCoE */
7585 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7586 pf
->num_fcoe_msix
= 1;
7590 /* give the rest to the PF */
7591 pf
->num_lan_msix
= min_t(int, vec
, pf
->num_lan_qps
);
7596 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
7597 (pf
->num_vmdq_msix
== 0)) {
7598 dev_info(&pf
->pdev
->dev
, "VMDq disabled, not enough MSI-X vectors\n");
7599 pf
->flags
&= ~I40E_FLAG_VMDQ_ENABLED
;
7603 if ((pf
->flags
& I40E_FLAG_FCOE_ENABLED
) && (pf
->num_fcoe_msix
== 0)) {
7604 dev_info(&pf
->pdev
->dev
, "FCOE disabled, not enough MSI-X vectors\n");
7605 pf
->flags
&= ~I40E_FLAG_FCOE_ENABLED
;
7612 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
7613 * @vsi: the VSI being configured
7614 * @v_idx: index of the vector in the vsi struct
7616 * We allocate one q_vector. If allocation fails we return -ENOMEM.
7618 static int i40e_vsi_alloc_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
7620 struct i40e_q_vector
*q_vector
;
7622 /* allocate q_vector */
7623 q_vector
= kzalloc(sizeof(struct i40e_q_vector
), GFP_KERNEL
);
7627 q_vector
->vsi
= vsi
;
7628 q_vector
->v_idx
= v_idx
;
7629 cpumask_set_cpu(v_idx
, &q_vector
->affinity_mask
);
7631 netif_napi_add(vsi
->netdev
, &q_vector
->napi
,
7632 i40e_napi_poll
, NAPI_POLL_WEIGHT
);
7634 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
7635 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
7637 /* tie q_vector and vsi together */
7638 vsi
->q_vectors
[v_idx
] = q_vector
;
7644 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
7645 * @vsi: the VSI being configured
7647 * We allocate one q_vector per queue interrupt. If allocation fails we
7650 static int i40e_vsi_alloc_q_vectors(struct i40e_vsi
*vsi
)
7652 struct i40e_pf
*pf
= vsi
->back
;
7653 int v_idx
, num_q_vectors
;
7656 /* if not MSIX, give the one vector only to the LAN VSI */
7657 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
7658 num_q_vectors
= vsi
->num_q_vectors
;
7659 else if (vsi
== pf
->vsi
[pf
->lan_vsi
])
7664 for (v_idx
= 0; v_idx
< num_q_vectors
; v_idx
++) {
7665 err
= i40e_vsi_alloc_q_vector(vsi
, v_idx
);
7674 i40e_free_q_vector(vsi
, v_idx
);
7680 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
7681 * @pf: board private structure to initialize
7683 static int i40e_init_interrupt_scheme(struct i40e_pf
*pf
)
7688 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
7689 vectors
= i40e_init_msix(pf
);
7691 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
|
7693 I40E_FLAG_FCOE_ENABLED
|
7695 I40E_FLAG_RSS_ENABLED
|
7696 I40E_FLAG_DCB_CAPABLE
|
7697 I40E_FLAG_SRIOV_ENABLED
|
7698 I40E_FLAG_FD_SB_ENABLED
|
7699 I40E_FLAG_FD_ATR_ENABLED
|
7700 I40E_FLAG_VMDQ_ENABLED
);
7702 /* rework the queue expectations without MSIX */
7703 i40e_determine_queue_usage(pf
);
7707 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
7708 (pf
->flags
& I40E_FLAG_MSI_ENABLED
)) {
7709 dev_info(&pf
->pdev
->dev
, "MSI-X not available, trying MSI\n");
7710 vectors
= pci_enable_msi(pf
->pdev
);
7712 dev_info(&pf
->pdev
->dev
, "MSI init failed - %d\n",
7714 pf
->flags
&= ~I40E_FLAG_MSI_ENABLED
;
7716 vectors
= 1; /* one MSI or Legacy vector */
7719 if (!(pf
->flags
& (I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
)))
7720 dev_info(&pf
->pdev
->dev
, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
7722 /* set up vector assignment tracking */
7723 size
= sizeof(struct i40e_lump_tracking
) + (sizeof(u16
) * vectors
);
7724 pf
->irq_pile
= kzalloc(size
, GFP_KERNEL
);
7725 if (!pf
->irq_pile
) {
7726 dev_err(&pf
->pdev
->dev
, "error allocating irq_pile memory\n");
7729 pf
->irq_pile
->num_entries
= vectors
;
7730 pf
->irq_pile
->search_hint
= 0;
7732 /* track first vector for misc interrupts, ignore return */
7733 (void)i40e_get_lump(pf
, pf
->irq_pile
, 1, I40E_PILE_VALID_BIT
- 1);
7739 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
7740 * @pf: board private structure
7742 * This sets up the handler for MSIX 0, which is used to manage the
7743 * non-queue interrupts, e.g. AdminQ and errors. This is not used
7744 * when in MSI or Legacy interrupt mode.
7746 static int i40e_setup_misc_vector(struct i40e_pf
*pf
)
7748 struct i40e_hw
*hw
= &pf
->hw
;
7751 /* Only request the irq if this is the first time through, and
7752 * not when we're rebuilding after a Reset
7754 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
)) {
7755 err
= request_irq(pf
->msix_entries
[0].vector
,
7756 i40e_intr
, 0, pf
->int_name
, pf
);
7758 dev_info(&pf
->pdev
->dev
,
7759 "request_irq for %s failed: %d\n",
7765 i40e_enable_misc_int_causes(pf
);
7767 /* associate no queues to the misc vector */
7768 wr32(hw
, I40E_PFINT_LNKLST0
, I40E_QUEUE_END_OF_LIST
);
7769 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), I40E_ITR_8K
);
7773 i40e_irq_dynamic_enable_icr0(pf
);
7779 * i40e_config_rss_aq - Prepare for RSS using AQ commands
7780 * @vsi: vsi structure
7781 * @seed: RSS hash seed
7783 static int i40e_config_rss_aq(struct i40e_vsi
*vsi
, const u8
*seed
)
7785 struct i40e_aqc_get_set_rss_key_data rss_key
;
7786 struct i40e_pf
*pf
= vsi
->back
;
7787 struct i40e_hw
*hw
= &pf
->hw
;
7788 bool pf_lut
= false;
7792 memset(&rss_key
, 0, sizeof(rss_key
));
7793 memcpy(&rss_key
, seed
, sizeof(rss_key
));
7795 rss_lut
= kzalloc(pf
->rss_table_size
, GFP_KERNEL
);
7799 /* Populate the LUT with max no. of queues in round robin fashion */
7800 for (i
= 0; i
< vsi
->rss_table_size
; i
++)
7801 rss_lut
[i
] = i
% vsi
->rss_size
;
7803 ret
= i40e_aq_set_rss_key(hw
, vsi
->id
, &rss_key
);
7805 dev_info(&pf
->pdev
->dev
,
7806 "Cannot set RSS key, err %s aq_err %s\n",
7807 i40e_stat_str(&pf
->hw
, ret
),
7808 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
7809 goto config_rss_aq_out
;
7812 if (vsi
->type
== I40E_VSI_MAIN
)
7815 ret
= i40e_aq_set_rss_lut(hw
, vsi
->id
, pf_lut
, rss_lut
,
7816 vsi
->rss_table_size
);
7818 dev_info(&pf
->pdev
->dev
,
7819 "Cannot set RSS lut, err %s aq_err %s\n",
7820 i40e_stat_str(&pf
->hw
, ret
),
7821 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
7829 * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
7830 * @vsi: VSI structure
7832 static int i40e_vsi_config_rss(struct i40e_vsi
*vsi
)
7834 u8 seed
[I40E_HKEY_ARRAY_SIZE
];
7835 struct i40e_pf
*pf
= vsi
->back
;
7837 netdev_rss_key_fill((void *)seed
, I40E_HKEY_ARRAY_SIZE
);
7838 vsi
->rss_size
= min_t(int, pf
->rss_size
, vsi
->num_queue_pairs
);
7840 if (pf
->flags
& I40E_FLAG_RSS_AQ_CAPABLE
)
7841 return i40e_config_rss_aq(vsi
, seed
);
7847 * i40e_config_rss_reg - Prepare for RSS if used
7848 * @pf: board private structure
7849 * @seed: RSS hash seed
7851 static int i40e_config_rss_reg(struct i40e_pf
*pf
, const u8
*seed
)
7853 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
7854 struct i40e_hw
*hw
= &pf
->hw
;
7855 u32
*seed_dw
= (u32
*)seed
;
7856 u32 current_queue
= 0;
7860 /* Fill out hash function seed */
7861 for (i
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++)
7862 wr32(hw
, I40E_PFQF_HKEY(i
), seed_dw
[i
]);
7864 for (i
= 0; i
<= I40E_PFQF_HLUT_MAX_INDEX
; i
++) {
7866 for (j
= 0; j
< 4; j
++) {
7867 if (current_queue
== vsi
->rss_size
)
7869 lut
|= ((current_queue
) << (8 * j
));
7872 wr32(&pf
->hw
, I40E_PFQF_HLUT(i
), lut
);
7880 * i40e_config_rss - Prepare for RSS if used
7881 * @pf: board private structure
7883 static int i40e_config_rss(struct i40e_pf
*pf
)
7885 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
7886 u8 seed
[I40E_HKEY_ARRAY_SIZE
];
7887 struct i40e_hw
*hw
= &pf
->hw
;
7891 netdev_rss_key_fill((void *)seed
, I40E_HKEY_ARRAY_SIZE
);
7893 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
7894 hena
= (u64
)rd32(hw
, I40E_PFQF_HENA(0)) |
7895 ((u64
)rd32(hw
, I40E_PFQF_HENA(1)) << 32);
7896 hena
|= i40e_pf_get_default_rss_hena(pf
);
7898 wr32(hw
, I40E_PFQF_HENA(0), (u32
)hena
);
7899 wr32(hw
, I40E_PFQF_HENA(1), (u32
)(hena
>> 32));
7901 vsi
->rss_size
= min_t(int, pf
->rss_size
, vsi
->num_queue_pairs
);
7903 /* Determine the RSS table size based on the hardware capabilities */
7904 reg_val
= rd32(hw
, I40E_PFQF_CTL_0
);
7905 reg_val
= (pf
->rss_table_size
== 512) ?
7906 (reg_val
| I40E_PFQF_CTL_0_HASHLUTSIZE_512
) :
7907 (reg_val
& ~I40E_PFQF_CTL_0_HASHLUTSIZE_512
);
7908 wr32(hw
, I40E_PFQF_CTL_0
, reg_val
);
7910 if (pf
->flags
& I40E_FLAG_RSS_AQ_CAPABLE
)
7911 return i40e_config_rss_aq(pf
->vsi
[pf
->lan_vsi
], seed
);
7913 return i40e_config_rss_reg(pf
, seed
);
7917 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
7918 * @pf: board private structure
7919 * @queue_count: the requested queue count for rss.
7921 * returns 0 if rss is not enabled, if enabled returns the final rss queue
7922 * count which may be different from the requested queue count.
7924 int i40e_reconfig_rss_queues(struct i40e_pf
*pf
, int queue_count
)
7926 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
7929 if (!(pf
->flags
& I40E_FLAG_RSS_ENABLED
))
7932 new_rss_size
= min_t(int, queue_count
, pf
->rss_size_max
);
7934 if (queue_count
!= vsi
->num_queue_pairs
) {
7935 vsi
->req_queue_pairs
= queue_count
;
7936 i40e_prep_for_reset(pf
);
7938 pf
->rss_size
= new_rss_size
;
7940 i40e_reset_and_rebuild(pf
, true);
7941 i40e_config_rss(pf
);
7943 dev_info(&pf
->pdev
->dev
, "RSS count: %d\n", pf
->rss_size
);
7944 return pf
->rss_size
;
7948 * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition
7949 * @pf: board private structure
7951 i40e_status
i40e_get_npar_bw_setting(struct i40e_pf
*pf
)
7954 bool min_valid
, max_valid
;
7957 status
= i40e_read_bw_from_alt_ram(&pf
->hw
, &max_bw
, &min_bw
,
7958 &min_valid
, &max_valid
);
7962 pf
->npar_min_bw
= min_bw
;
7964 pf
->npar_max_bw
= max_bw
;
7971 * i40e_set_npar_bw_setting - Set BW settings for this PF partition
7972 * @pf: board private structure
7974 i40e_status
i40e_set_npar_bw_setting(struct i40e_pf
*pf
)
7976 struct i40e_aqc_configure_partition_bw_data bw_data
;
7979 /* Set the valid bit for this PF */
7980 bw_data
.pf_valid_bits
= cpu_to_le16(BIT(pf
->hw
.pf_id
));
7981 bw_data
.max_bw
[pf
->hw
.pf_id
] = pf
->npar_max_bw
& I40E_ALT_BW_VALUE_MASK
;
7982 bw_data
.min_bw
[pf
->hw
.pf_id
] = pf
->npar_min_bw
& I40E_ALT_BW_VALUE_MASK
;
7984 /* Set the new bandwidths */
7985 status
= i40e_aq_configure_partition_bw(&pf
->hw
, &bw_data
, NULL
);
7991 * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition
7992 * @pf: board private structure
7994 i40e_status
i40e_commit_npar_bw_setting(struct i40e_pf
*pf
)
7996 /* Commit temporary BW setting to permanent NVM image */
7997 enum i40e_admin_queue_err last_aq_status
;
8001 if (pf
->hw
.partition_id
!= 1) {
8002 dev_info(&pf
->pdev
->dev
,
8003 "Commit BW only works on partition 1! This is partition %d",
8004 pf
->hw
.partition_id
);
8005 ret
= I40E_NOT_SUPPORTED
;
8009 /* Acquire NVM for read access */
8010 ret
= i40e_acquire_nvm(&pf
->hw
, I40E_RESOURCE_READ
);
8011 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
8013 dev_info(&pf
->pdev
->dev
,
8014 "Cannot acquire NVM for read access, err %s aq_err %s\n",
8015 i40e_stat_str(&pf
->hw
, ret
),
8016 i40e_aq_str(&pf
->hw
, last_aq_status
));
8020 /* Read word 0x10 of NVM - SW compatibility word 1 */
8021 ret
= i40e_aq_read_nvm(&pf
->hw
,
8022 I40E_SR_NVM_CONTROL_WORD
,
8023 0x10, sizeof(nvm_word
), &nvm_word
,
8025 /* Save off last admin queue command status before releasing
8028 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
8029 i40e_release_nvm(&pf
->hw
);
8031 dev_info(&pf
->pdev
->dev
, "NVM read error, err %s aq_err %s\n",
8032 i40e_stat_str(&pf
->hw
, ret
),
8033 i40e_aq_str(&pf
->hw
, last_aq_status
));
8037 /* Wait a bit for NVM release to complete */
8040 /* Acquire NVM for write access */
8041 ret
= i40e_acquire_nvm(&pf
->hw
, I40E_RESOURCE_WRITE
);
8042 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
8044 dev_info(&pf
->pdev
->dev
,
8045 "Cannot acquire NVM for write access, err %s aq_err %s\n",
8046 i40e_stat_str(&pf
->hw
, ret
),
8047 i40e_aq_str(&pf
->hw
, last_aq_status
));
8050 /* Write it back out unchanged to initiate update NVM,
8051 * which will force a write of the shadow (alt) RAM to
8052 * the NVM - thus storing the bandwidth values permanently.
8054 ret
= i40e_aq_update_nvm(&pf
->hw
,
8055 I40E_SR_NVM_CONTROL_WORD
,
8056 0x10, sizeof(nvm_word
),
8057 &nvm_word
, true, NULL
);
8058 /* Save off last admin queue command status before releasing
8061 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
8062 i40e_release_nvm(&pf
->hw
);
8064 dev_info(&pf
->pdev
->dev
,
8065 "BW settings NOT SAVED, err %s aq_err %s\n",
8066 i40e_stat_str(&pf
->hw
, ret
),
8067 i40e_aq_str(&pf
->hw
, last_aq_status
));
8074 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
8075 * @pf: board private structure to initialize
8077 * i40e_sw_init initializes the Adapter private data structure.
8078 * Fields are initialized based on PCI device information and
8079 * OS network device settings (MTU size).
8081 static int i40e_sw_init(struct i40e_pf
*pf
)
8086 pf
->msg_enable
= netif_msg_init(I40E_DEFAULT_MSG_ENABLE
,
8087 (NETIF_MSG_DRV
|NETIF_MSG_PROBE
|NETIF_MSG_LINK
));
8088 pf
->hw
.debug_mask
= pf
->msg_enable
| I40E_DEBUG_DIAG
;
8089 if (debug
!= -1 && debug
!= I40E_DEFAULT_MSG_ENABLE
) {
8090 if (I40E_DEBUG_USER
& debug
)
8091 pf
->hw
.debug_mask
= debug
;
8092 pf
->msg_enable
= netif_msg_init((debug
& ~I40E_DEBUG_USER
),
8093 I40E_DEFAULT_MSG_ENABLE
);
8096 /* Set default capability flags */
8097 pf
->flags
= I40E_FLAG_RX_CSUM_ENABLED
|
8098 I40E_FLAG_MSI_ENABLED
|
8099 I40E_FLAG_LINK_POLLING_ENABLED
|
8100 I40E_FLAG_MSIX_ENABLED
;
8102 if (iommu_present(&pci_bus_type
))
8103 pf
->flags
|= I40E_FLAG_RX_PS_ENABLED
;
8105 pf
->flags
|= I40E_FLAG_RX_1BUF_ENABLED
;
8107 /* Set default ITR */
8108 pf
->rx_itr_default
= I40E_ITR_DYNAMIC
| I40E_ITR_RX_DEF
;
8109 pf
->tx_itr_default
= I40E_ITR_DYNAMIC
| I40E_ITR_TX_DEF
;
8111 /* Depending on PF configurations, it is possible that the RSS
8112 * maximum might end up larger than the available queues
8114 pf
->rss_size_max
= BIT(pf
->hw
.func_caps
.rss_table_entry_width
);
8116 pf
->rss_table_size
= pf
->hw
.func_caps
.rss_table_size
;
8117 pf
->rss_size_max
= min_t(int, pf
->rss_size_max
,
8118 pf
->hw
.func_caps
.num_tx_qp
);
8119 if (pf
->hw
.func_caps
.rss
) {
8120 pf
->flags
|= I40E_FLAG_RSS_ENABLED
;
8121 pf
->rss_size
= min_t(int, pf
->rss_size_max
, num_online_cpus());
8124 /* MFP mode enabled */
8125 if (pf
->hw
.func_caps
.npar_enable
|| pf
->hw
.func_caps
.flex10_enable
) {
8126 pf
->flags
|= I40E_FLAG_MFP_ENABLED
;
8127 dev_info(&pf
->pdev
->dev
, "MFP mode Enabled\n");
8128 if (i40e_get_npar_bw_setting(pf
))
8129 dev_warn(&pf
->pdev
->dev
,
8130 "Could not get NPAR bw settings\n");
8132 dev_info(&pf
->pdev
->dev
,
8133 "Min BW = %8.8x, Max BW = %8.8x\n",
8134 pf
->npar_min_bw
, pf
->npar_max_bw
);
8137 /* FW/NVM is not yet fixed in this regard */
8138 if ((pf
->hw
.func_caps
.fd_filters_guaranteed
> 0) ||
8139 (pf
->hw
.func_caps
.fd_filters_best_effort
> 0)) {
8140 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
8141 pf
->atr_sample_rate
= I40E_DEFAULT_ATR_SAMPLE_RATE
;
8142 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
&&
8143 pf
->hw
.num_partitions
> 1)
8144 dev_info(&pf
->pdev
->dev
,
8145 "Flow Director Sideband mode Disabled in MFP mode\n");
8147 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
8148 pf
->fdir_pf_filter_count
=
8149 pf
->hw
.func_caps
.fd_filters_guaranteed
;
8150 pf
->hw
.fdir_shared_filter_count
=
8151 pf
->hw
.func_caps
.fd_filters_best_effort
;
8154 if (pf
->hw
.func_caps
.vmdq
) {
8155 pf
->num_vmdq_vsis
= I40E_DEFAULT_NUM_VMDQ_VSI
;
8156 pf
->flags
|= I40E_FLAG_VMDQ_ENABLED
;
8157 pf
->num_vmdq_qps
= i40e_default_queues_per_vmdq(pf
);
8161 i40e_init_pf_fcoe(pf
);
8163 #endif /* I40E_FCOE */
8164 #ifdef CONFIG_PCI_IOV
8165 if (pf
->hw
.func_caps
.num_vfs
&& pf
->hw
.partition_id
== 1) {
8166 pf
->num_vf_qps
= I40E_DEFAULT_QUEUES_PER_VF
;
8167 pf
->flags
|= I40E_FLAG_SRIOV_ENABLED
;
8168 pf
->num_req_vfs
= min_t(int,
8169 pf
->hw
.func_caps
.num_vfs
,
8172 #endif /* CONFIG_PCI_IOV */
8173 if (pf
->hw
.mac
.type
== I40E_MAC_X722
) {
8174 pf
->flags
|= I40E_FLAG_RSS_AQ_CAPABLE
|
8175 I40E_FLAG_128_QP_RSS_CAPABLE
|
8176 I40E_FLAG_HW_ATR_EVICT_CAPABLE
|
8177 I40E_FLAG_OUTER_UDP_CSUM_CAPABLE
|
8178 I40E_FLAG_WB_ON_ITR_CAPABLE
|
8179 I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE
;
8181 pf
->eeprom_version
= 0xDEAD;
8182 pf
->lan_veb
= I40E_NO_VEB
;
8183 pf
->lan_vsi
= I40E_NO_VSI
;
8185 /* By default FW has this off for performance reasons */
8186 pf
->flags
&= ~I40E_FLAG_VEB_STATS_ENABLED
;
8188 /* set up queue assignment tracking */
8189 size
= sizeof(struct i40e_lump_tracking
)
8190 + (sizeof(u16
) * pf
->hw
.func_caps
.num_tx_qp
);
8191 pf
->qp_pile
= kzalloc(size
, GFP_KERNEL
);
8196 pf
->qp_pile
->num_entries
= pf
->hw
.func_caps
.num_tx_qp
;
8197 pf
->qp_pile
->search_hint
= 0;
8199 pf
->tx_timeout_recovery_level
= 1;
8201 mutex_init(&pf
->switch_mutex
);
8203 /* If NPAR is enabled nudge the Tx scheduler */
8204 if (pf
->hw
.func_caps
.npar_enable
&& (!i40e_get_npar_bw_setting(pf
)))
8205 i40e_set_npar_bw_setting(pf
);
8212 * i40e_set_ntuple - set the ntuple feature flag and take action
8213 * @pf: board private structure to initialize
8214 * @features: the feature set that the stack is suggesting
8216 * returns a bool to indicate if reset needs to happen
8218 bool i40e_set_ntuple(struct i40e_pf
*pf
, netdev_features_t features
)
8220 bool need_reset
= false;
8222 /* Check if Flow Director n-tuple support was enabled or disabled. If
8223 * the state changed, we need to reset.
8225 if (features
& NETIF_F_NTUPLE
) {
8226 /* Enable filters and mark for reset */
8227 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
8229 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
8231 /* turn off filters, mark for reset and clear SW filter list */
8232 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
8234 i40e_fdir_filter_exit(pf
);
8236 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
8237 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
8238 /* reset fd counters */
8239 pf
->fd_add_err
= pf
->fd_atr_cnt
= pf
->fd_tcp_rule
= 0;
8240 pf
->fdir_pf_active_filters
= 0;
8241 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
8242 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
8243 dev_info(&pf
->pdev
->dev
, "ATR re-enabled.\n");
8244 /* if ATR was auto disabled it can be re-enabled. */
8245 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
8246 (pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
))
8247 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
8253 * i40e_set_features - set the netdev feature flags
8254 * @netdev: ptr to the netdev being adjusted
8255 * @features: the feature set that the stack is suggesting
8257 static int i40e_set_features(struct net_device
*netdev
,
8258 netdev_features_t features
)
8260 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8261 struct i40e_vsi
*vsi
= np
->vsi
;
8262 struct i40e_pf
*pf
= vsi
->back
;
8265 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
8266 i40e_vlan_stripping_enable(vsi
);
8268 i40e_vlan_stripping_disable(vsi
);
8270 need_reset
= i40e_set_ntuple(pf
, features
);
8273 i40e_do_reset(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
8278 #ifdef CONFIG_I40E_VXLAN
8280 * i40e_get_vxlan_port_idx - Lookup a possibly offloaded for Rx UDP port
8281 * @pf: board private structure
8282 * @port: The UDP port to look up
8284 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
8286 static u8
i40e_get_vxlan_port_idx(struct i40e_pf
*pf
, __be16 port
)
8290 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
8291 if (pf
->vxlan_ports
[i
] == port
)
8299 * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up
8300 * @netdev: This physical port's netdev
8301 * @sa_family: Socket Family that VXLAN is notifying us about
8302 * @port: New UDP port number that VXLAN started listening to
8304 static void i40e_add_vxlan_port(struct net_device
*netdev
,
8305 sa_family_t sa_family
, __be16 port
)
8307 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8308 struct i40e_vsi
*vsi
= np
->vsi
;
8309 struct i40e_pf
*pf
= vsi
->back
;
8313 if (sa_family
== AF_INET6
)
8316 idx
= i40e_get_vxlan_port_idx(pf
, port
);
8318 /* Check if port already exists */
8319 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
8320 netdev_info(netdev
, "vxlan port %d already offloaded\n",
8325 /* Now check if there is space to add the new port */
8326 next_idx
= i40e_get_vxlan_port_idx(pf
, 0);
8328 if (next_idx
== I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
8329 netdev_info(netdev
, "maximum number of vxlan UDP ports reached, not adding port %d\n",
8334 /* New port: add it and mark its index in the bitmap */
8335 pf
->vxlan_ports
[next_idx
] = port
;
8336 pf
->pending_vxlan_bitmap
|= BIT_ULL(next_idx
);
8337 pf
->flags
|= I40E_FLAG_VXLAN_FILTER_SYNC
;
8341 * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away
8342 * @netdev: This physical port's netdev
8343 * @sa_family: Socket Family that VXLAN is notifying us about
8344 * @port: UDP port number that VXLAN stopped listening to
8346 static void i40e_del_vxlan_port(struct net_device
*netdev
,
8347 sa_family_t sa_family
, __be16 port
)
8349 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8350 struct i40e_vsi
*vsi
= np
->vsi
;
8351 struct i40e_pf
*pf
= vsi
->back
;
8354 if (sa_family
== AF_INET6
)
8357 idx
= i40e_get_vxlan_port_idx(pf
, port
);
8359 /* Check if port already exists */
8360 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
8361 /* if port exists, set it to 0 (mark for deletion)
8362 * and make it pending
8364 pf
->vxlan_ports
[idx
] = 0;
8365 pf
->pending_vxlan_bitmap
|= BIT_ULL(idx
);
8366 pf
->flags
|= I40E_FLAG_VXLAN_FILTER_SYNC
;
8368 netdev_warn(netdev
, "vxlan port %d was not found, not deleting\n",
8374 static int i40e_get_phys_port_id(struct net_device
*netdev
,
8375 struct netdev_phys_item_id
*ppid
)
8377 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8378 struct i40e_pf
*pf
= np
->vsi
->back
;
8379 struct i40e_hw
*hw
= &pf
->hw
;
8381 if (!(pf
->flags
& I40E_FLAG_PORT_ID_VALID
))
8384 ppid
->id_len
= min_t(int, sizeof(hw
->mac
.port_addr
), sizeof(ppid
->id
));
8385 memcpy(ppid
->id
, hw
->mac
.port_addr
, ppid
->id_len
);
8391 * i40e_ndo_fdb_add - add an entry to the hardware database
8392 * @ndm: the input from the stack
8393 * @tb: pointer to array of nladdr (unused)
8394 * @dev: the net device pointer
8395 * @addr: the MAC address entry being added
8396 * @flags: instructions from stack about fdb operation
8398 static int i40e_ndo_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
8399 struct net_device
*dev
,
8400 const unsigned char *addr
, u16 vid
,
8403 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
8404 struct i40e_pf
*pf
= np
->vsi
->back
;
8407 if (!(pf
->flags
& I40E_FLAG_SRIOV_ENABLED
))
8411 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev
->name
);
8415 /* Hardware does not support aging addresses so if a
8416 * ndm_state is given only allow permanent addresses
8418 if (ndm
->ndm_state
&& !(ndm
->ndm_state
& NUD_PERMANENT
)) {
8419 netdev_info(dev
, "FDB only supports static addresses\n");
8423 if (is_unicast_ether_addr(addr
) || is_link_local_ether_addr(addr
))
8424 err
= dev_uc_add_excl(dev
, addr
);
8425 else if (is_multicast_ether_addr(addr
))
8426 err
= dev_mc_add_excl(dev
, addr
);
8430 /* Only return duplicate errors if NLM_F_EXCL is set */
8431 if (err
== -EEXIST
&& !(flags
& NLM_F_EXCL
))
8438 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
8439 * @dev: the netdev being configured
8440 * @nlh: RTNL message
8442 * Inserts a new hardware bridge if not already created and
8443 * enables the bridging mode requested (VEB or VEPA). If the
8444 * hardware bridge has already been inserted and the request
8445 * is to change the mode then that requires a PF reset to
8446 * allow rebuild of the components with required hardware
8447 * bridge mode enabled.
8449 static int i40e_ndo_bridge_setlink(struct net_device
*dev
,
8450 struct nlmsghdr
*nlh
,
8453 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
8454 struct i40e_vsi
*vsi
= np
->vsi
;
8455 struct i40e_pf
*pf
= vsi
->back
;
8456 struct i40e_veb
*veb
= NULL
;
8457 struct nlattr
*attr
, *br_spec
;
8460 /* Only for PF VSI for now */
8461 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
)
8464 /* Find the HW bridge for PF VSI */
8465 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
8466 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
8470 br_spec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
8472 nla_for_each_nested(attr
, br_spec
, rem
) {
8475 if (nla_type(attr
) != IFLA_BRIDGE_MODE
)
8478 mode
= nla_get_u16(attr
);
8479 if ((mode
!= BRIDGE_MODE_VEPA
) &&
8480 (mode
!= BRIDGE_MODE_VEB
))
8483 /* Insert a new HW bridge */
8485 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
8486 vsi
->tc_config
.enabled_tc
);
8488 veb
->bridge_mode
= mode
;
8489 i40e_config_bridge_mode(veb
);
8491 /* No Bridge HW offload available */
8495 } else if (mode
!= veb
->bridge_mode
) {
8496 /* Existing HW bridge but different mode needs reset */
8497 veb
->bridge_mode
= mode
;
8498 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
8499 if (mode
== BRIDGE_MODE_VEB
)
8500 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
8502 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
8503 i40e_do_reset(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
8512 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
8515 * @seq: RTNL message seq #
8516 * @dev: the netdev being configured
8517 * @filter_mask: unused
8518 * @nlflags: netlink flags passed in
8520 * Return the mode in which the hardware bridge is operating in
8523 static int i40e_ndo_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
8524 struct net_device
*dev
,
8525 u32 __always_unused filter_mask
,
8528 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
8529 struct i40e_vsi
*vsi
= np
->vsi
;
8530 struct i40e_pf
*pf
= vsi
->back
;
8531 struct i40e_veb
*veb
= NULL
;
8534 /* Only for PF VSI for now */
8535 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
)
8538 /* Find the HW bridge for the PF VSI */
8539 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
8540 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
8547 return ndo_dflt_bridge_getlink(skb
, pid
, seq
, dev
, veb
->bridge_mode
,
8548 nlflags
, 0, 0, filter_mask
, NULL
);
8551 #define I40E_MAX_TUNNEL_HDR_LEN 80
8553 * i40e_features_check - Validate encapsulated packet conforms to limits
8555 * @dev: This physical port's netdev
8556 * @features: Offload features that the stack believes apply
8558 static netdev_features_t
i40e_features_check(struct sk_buff
*skb
,
8559 struct net_device
*dev
,
8560 netdev_features_t features
)
8562 if (skb
->encapsulation
&&
8563 (skb_inner_mac_header(skb
) - skb_transport_header(skb
) >
8564 I40E_MAX_TUNNEL_HDR_LEN
))
8565 return features
& ~(NETIF_F_ALL_CSUM
| NETIF_F_GSO_MASK
);
8570 static const struct net_device_ops i40e_netdev_ops
= {
8571 .ndo_open
= i40e_open
,
8572 .ndo_stop
= i40e_close
,
8573 .ndo_start_xmit
= i40e_lan_xmit_frame
,
8574 .ndo_get_stats64
= i40e_get_netdev_stats_struct
,
8575 .ndo_set_rx_mode
= i40e_set_rx_mode
,
8576 .ndo_validate_addr
= eth_validate_addr
,
8577 .ndo_set_mac_address
= i40e_set_mac
,
8578 .ndo_change_mtu
= i40e_change_mtu
,
8579 .ndo_do_ioctl
= i40e_ioctl
,
8580 .ndo_tx_timeout
= i40e_tx_timeout
,
8581 .ndo_vlan_rx_add_vid
= i40e_vlan_rx_add_vid
,
8582 .ndo_vlan_rx_kill_vid
= i40e_vlan_rx_kill_vid
,
8583 #ifdef CONFIG_NET_POLL_CONTROLLER
8584 .ndo_poll_controller
= i40e_netpoll
,
8586 .ndo_setup_tc
= i40e_setup_tc
,
8588 .ndo_fcoe_enable
= i40e_fcoe_enable
,
8589 .ndo_fcoe_disable
= i40e_fcoe_disable
,
8591 .ndo_set_features
= i40e_set_features
,
8592 .ndo_set_vf_mac
= i40e_ndo_set_vf_mac
,
8593 .ndo_set_vf_vlan
= i40e_ndo_set_vf_port_vlan
,
8594 .ndo_set_vf_rate
= i40e_ndo_set_vf_bw
,
8595 .ndo_get_vf_config
= i40e_ndo_get_vf_config
,
8596 .ndo_set_vf_link_state
= i40e_ndo_set_vf_link_state
,
8597 .ndo_set_vf_spoofchk
= i40e_ndo_set_vf_spoofchk
,
8598 #ifdef CONFIG_I40E_VXLAN
8599 .ndo_add_vxlan_port
= i40e_add_vxlan_port
,
8600 .ndo_del_vxlan_port
= i40e_del_vxlan_port
,
8602 .ndo_get_phys_port_id
= i40e_get_phys_port_id
,
8603 .ndo_fdb_add
= i40e_ndo_fdb_add
,
8604 .ndo_features_check
= i40e_features_check
,
8605 .ndo_bridge_getlink
= i40e_ndo_bridge_getlink
,
8606 .ndo_bridge_setlink
= i40e_ndo_bridge_setlink
,
8610 * i40e_config_netdev - Setup the netdev flags
8611 * @vsi: the VSI being configured
8613 * Returns 0 on success, negative value on failure
8615 static int i40e_config_netdev(struct i40e_vsi
*vsi
)
8617 u8 brdcast
[ETH_ALEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
8618 struct i40e_pf
*pf
= vsi
->back
;
8619 struct i40e_hw
*hw
= &pf
->hw
;
8620 struct i40e_netdev_priv
*np
;
8621 struct net_device
*netdev
;
8622 u8 mac_addr
[ETH_ALEN
];
8625 etherdev_size
= sizeof(struct i40e_netdev_priv
);
8626 netdev
= alloc_etherdev_mq(etherdev_size
, vsi
->alloc_queue_pairs
);
8630 vsi
->netdev
= netdev
;
8631 np
= netdev_priv(netdev
);
8634 netdev
->hw_enc_features
|= NETIF_F_IP_CSUM
|
8635 NETIF_F_GSO_UDP_TUNNEL
|
8639 netdev
->features
= NETIF_F_SG
|
8643 NETIF_F_GSO_UDP_TUNNEL
|
8645 NETIF_F_HW_VLAN_CTAG_TX
|
8646 NETIF_F_HW_VLAN_CTAG_RX
|
8647 NETIF_F_HW_VLAN_CTAG_FILTER
|
8656 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
8657 netdev
->features
|= NETIF_F_NTUPLE
;
8659 /* copy netdev features into list of user selectable features */
8660 netdev
->hw_features
|= netdev
->features
;
8662 if (vsi
->type
== I40E_VSI_MAIN
) {
8663 SET_NETDEV_DEV(netdev
, &pf
->pdev
->dev
);
8664 ether_addr_copy(mac_addr
, hw
->mac
.perm_addr
);
8665 /* The following steps are necessary to prevent reception
8666 * of tagged packets - some older NVM configurations load a
8667 * default a MAC-VLAN filter that accepts any tagged packet
8668 * which must be replaced by a normal filter.
8670 if (!i40e_rm_default_mac_filter(vsi
, mac_addr
)) {
8671 spin_lock_bh(&vsi
->mac_filter_list_lock
);
8672 i40e_add_filter(vsi
, mac_addr
,
8673 I40E_VLAN_ANY
, false, true);
8674 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
8677 /* relate the VSI_VMDQ name to the VSI_MAIN name */
8678 snprintf(netdev
->name
, IFNAMSIZ
, "%sv%%d",
8679 pf
->vsi
[pf
->lan_vsi
]->netdev
->name
);
8680 random_ether_addr(mac_addr
);
8682 spin_lock_bh(&vsi
->mac_filter_list_lock
);
8683 i40e_add_filter(vsi
, mac_addr
, I40E_VLAN_ANY
, false, false);
8684 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
8687 spin_lock_bh(&vsi
->mac_filter_list_lock
);
8688 i40e_add_filter(vsi
, brdcast
, I40E_VLAN_ANY
, false, false);
8689 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
8691 ether_addr_copy(netdev
->dev_addr
, mac_addr
);
8692 ether_addr_copy(netdev
->perm_addr
, mac_addr
);
8693 /* vlan gets same features (except vlan offload)
8694 * after any tweaks for specific VSI types
8696 netdev
->vlan_features
= netdev
->features
& ~(NETIF_F_HW_VLAN_CTAG_TX
|
8697 NETIF_F_HW_VLAN_CTAG_RX
|
8698 NETIF_F_HW_VLAN_CTAG_FILTER
);
8699 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
8700 netdev
->priv_flags
|= IFF_SUPP_NOFCS
;
8701 /* Setup netdev TC information */
8702 i40e_vsi_config_netdev_tc(vsi
, vsi
->tc_config
.enabled_tc
);
8704 netdev
->netdev_ops
= &i40e_netdev_ops
;
8705 netdev
->watchdog_timeo
= 5 * HZ
;
8706 i40e_set_ethtool_ops(netdev
);
8708 i40e_fcoe_config_netdev(netdev
, vsi
);
8715 * i40e_vsi_delete - Delete a VSI from the switch
8716 * @vsi: the VSI being removed
8718 * Returns 0 on success, negative value on failure
8720 static void i40e_vsi_delete(struct i40e_vsi
*vsi
)
8722 /* remove default VSI is not allowed */
8723 if (vsi
== vsi
->back
->vsi
[vsi
->back
->lan_vsi
])
8726 i40e_aq_delete_element(&vsi
->back
->hw
, vsi
->seid
, NULL
);
8730 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
8731 * @vsi: the VSI being queried
8733 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
8735 int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi
*vsi
)
8737 struct i40e_veb
*veb
;
8738 struct i40e_pf
*pf
= vsi
->back
;
8740 /* Uplink is not a bridge so default to VEB */
8741 if (vsi
->veb_idx
== I40E_NO_VEB
)
8744 veb
= pf
->veb
[vsi
->veb_idx
];
8746 dev_info(&pf
->pdev
->dev
,
8747 "There is no veb associated with the bridge\n");
8751 /* Uplink is a bridge in VEPA mode */
8752 if (veb
->bridge_mode
& BRIDGE_MODE_VEPA
) {
8755 /* Uplink is a bridge in VEB mode */
8759 /* VEPA is now default bridge, so return 0 */
8764 * i40e_add_vsi - Add a VSI to the switch
8765 * @vsi: the VSI being configured
8767 * This initializes a VSI context depending on the VSI type to be added and
8768 * passes it down to the add_vsi aq command.
8770 static int i40e_add_vsi(struct i40e_vsi
*vsi
)
8773 u8 laa_macaddr
[ETH_ALEN
];
8774 bool found_laa_mac_filter
= false;
8775 struct i40e_pf
*pf
= vsi
->back
;
8776 struct i40e_hw
*hw
= &pf
->hw
;
8777 struct i40e_vsi_context ctxt
;
8778 struct i40e_mac_filter
*f
, *ftmp
;
8780 u8 enabled_tc
= 0x1; /* TC0 enabled */
8783 memset(&ctxt
, 0, sizeof(ctxt
));
8784 switch (vsi
->type
) {
8786 /* The PF's main VSI is already setup as part of the
8787 * device initialization, so we'll not bother with
8788 * the add_vsi call, but we will retrieve the current
8791 ctxt
.seid
= pf
->main_vsi_seid
;
8792 ctxt
.pf_num
= pf
->hw
.pf_id
;
8794 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
8795 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
8797 dev_info(&pf
->pdev
->dev
,
8798 "couldn't get PF vsi config, err %s aq_err %s\n",
8799 i40e_stat_str(&pf
->hw
, ret
),
8800 i40e_aq_str(&pf
->hw
,
8801 pf
->hw
.aq
.asq_last_status
));
8804 vsi
->info
= ctxt
.info
;
8805 vsi
->info
.valid_sections
= 0;
8807 vsi
->seid
= ctxt
.seid
;
8808 vsi
->id
= ctxt
.vsi_number
;
8810 enabled_tc
= i40e_pf_get_tc_map(pf
);
8812 /* MFP mode setup queue map and update VSI */
8813 if ((pf
->flags
& I40E_FLAG_MFP_ENABLED
) &&
8814 !(pf
->hw
.func_caps
.iscsi
)) { /* NIC type PF */
8815 memset(&ctxt
, 0, sizeof(ctxt
));
8816 ctxt
.seid
= pf
->main_vsi_seid
;
8817 ctxt
.pf_num
= pf
->hw
.pf_id
;
8819 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
8820 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
8822 dev_info(&pf
->pdev
->dev
,
8823 "update vsi failed, err %s aq_err %s\n",
8824 i40e_stat_str(&pf
->hw
, ret
),
8825 i40e_aq_str(&pf
->hw
,
8826 pf
->hw
.aq
.asq_last_status
));
8830 /* update the local VSI info queue map */
8831 i40e_vsi_update_queue_map(vsi
, &ctxt
);
8832 vsi
->info
.valid_sections
= 0;
8834 /* Default/Main VSI is only enabled for TC0
8835 * reconfigure it to enable all TCs that are
8836 * available on the port in SFP mode.
8837 * For MFP case the iSCSI PF would use this
8838 * flow to enable LAN+iSCSI TC.
8840 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
8842 dev_info(&pf
->pdev
->dev
,
8843 "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
8845 i40e_stat_str(&pf
->hw
, ret
),
8846 i40e_aq_str(&pf
->hw
,
8847 pf
->hw
.aq
.asq_last_status
));
8854 ctxt
.pf_num
= hw
->pf_id
;
8856 ctxt
.uplink_seid
= vsi
->uplink_seid
;
8857 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
8858 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
8859 if ((pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
) &&
8860 (i40e_is_vsi_uplink_mode_veb(vsi
))) {
8861 ctxt
.info
.valid_sections
|=
8862 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
8863 ctxt
.info
.switch_id
=
8864 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
8866 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
8869 case I40E_VSI_VMDQ2
:
8870 ctxt
.pf_num
= hw
->pf_id
;
8872 ctxt
.uplink_seid
= vsi
->uplink_seid
;
8873 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
8874 ctxt
.flags
= I40E_AQ_VSI_TYPE_VMDQ2
;
8876 /* This VSI is connected to VEB so the switch_id
8877 * should be set to zero by default.
8879 if (i40e_is_vsi_uplink_mode_veb(vsi
)) {
8880 ctxt
.info
.valid_sections
|=
8881 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
8882 ctxt
.info
.switch_id
=
8883 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
8886 /* Setup the VSI tx/rx queue map for TC0 only for now */
8887 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
8890 case I40E_VSI_SRIOV
:
8891 ctxt
.pf_num
= hw
->pf_id
;
8892 ctxt
.vf_num
= vsi
->vf_id
+ hw
->func_caps
.vf_base_id
;
8893 ctxt
.uplink_seid
= vsi
->uplink_seid
;
8894 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
8895 ctxt
.flags
= I40E_AQ_VSI_TYPE_VF
;
8897 /* This VSI is connected to VEB so the switch_id
8898 * should be set to zero by default.
8900 if (i40e_is_vsi_uplink_mode_veb(vsi
)) {
8901 ctxt
.info
.valid_sections
|=
8902 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
8903 ctxt
.info
.switch_id
=
8904 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
8907 ctxt
.info
.valid_sections
|= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
8908 ctxt
.info
.port_vlan_flags
|= I40E_AQ_VSI_PVLAN_MODE_ALL
;
8909 if (pf
->vf
[vsi
->vf_id
].spoofchk
) {
8910 ctxt
.info
.valid_sections
|=
8911 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID
);
8912 ctxt
.info
.sec_flags
|=
8913 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK
|
8914 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK
);
8916 /* Setup the VSI tx/rx queue map for TC0 only for now */
8917 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
8922 ret
= i40e_fcoe_vsi_init(vsi
, &ctxt
);
8924 dev_info(&pf
->pdev
->dev
, "failed to initialize FCoE VSI\n");
8929 #endif /* I40E_FCOE */
8934 if (vsi
->type
!= I40E_VSI_MAIN
) {
8935 ret
= i40e_aq_add_vsi(hw
, &ctxt
, NULL
);
8937 dev_info(&vsi
->back
->pdev
->dev
,
8938 "add vsi failed, err %s aq_err %s\n",
8939 i40e_stat_str(&pf
->hw
, ret
),
8940 i40e_aq_str(&pf
->hw
,
8941 pf
->hw
.aq
.asq_last_status
));
8945 vsi
->info
= ctxt
.info
;
8946 vsi
->info
.valid_sections
= 0;
8947 vsi
->seid
= ctxt
.seid
;
8948 vsi
->id
= ctxt
.vsi_number
;
8951 spin_lock_bh(&vsi
->mac_filter_list_lock
);
8952 /* If macvlan filters already exist, force them to get loaded */
8953 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
8957 /* Expected to have only one MAC filter entry for LAA in list */
8958 if (f
->is_laa
&& vsi
->type
== I40E_VSI_MAIN
) {
8959 ether_addr_copy(laa_macaddr
, f
->macaddr
);
8960 found_laa_mac_filter
= true;
8963 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
8965 if (found_laa_mac_filter
) {
8966 struct i40e_aqc_remove_macvlan_element_data element
;
8968 memset(&element
, 0, sizeof(element
));
8969 ether_addr_copy(element
.mac_addr
, laa_macaddr
);
8970 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
8971 ret
= i40e_aq_remove_macvlan(hw
, vsi
->seid
,
8974 /* some older FW has a different default */
8976 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
8977 i40e_aq_remove_macvlan(hw
, vsi
->seid
,
8981 i40e_aq_mac_address_write(hw
,
8982 I40E_AQC_WRITE_TYPE_LAA_WOL
,
8987 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
8988 pf
->flags
|= I40E_FLAG_FILTER_SYNC
;
8991 /* Update VSI BW information */
8992 ret
= i40e_vsi_get_bw_info(vsi
);
8994 dev_info(&pf
->pdev
->dev
,
8995 "couldn't get vsi bw info, err %s aq_err %s\n",
8996 i40e_stat_str(&pf
->hw
, ret
),
8997 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
8998 /* VSI is already added so not tearing that up */
9007 * i40e_vsi_release - Delete a VSI and free its resources
9008 * @vsi: the VSI being removed
9010 * Returns 0 on success or < 0 on error
9012 int i40e_vsi_release(struct i40e_vsi
*vsi
)
9014 struct i40e_mac_filter
*f
, *ftmp
;
9015 struct i40e_veb
*veb
= NULL
;
9022 /* release of a VEB-owner or last VSI is not allowed */
9023 if (vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
9024 dev_info(&pf
->pdev
->dev
, "VSI %d has existing VEB %d\n",
9025 vsi
->seid
, vsi
->uplink_seid
);
9028 if (vsi
== pf
->vsi
[pf
->lan_vsi
] &&
9029 !test_bit(__I40E_DOWN
, &pf
->state
)) {
9030 dev_info(&pf
->pdev
->dev
, "Can't remove PF VSI\n");
9034 uplink_seid
= vsi
->uplink_seid
;
9035 if (vsi
->type
!= I40E_VSI_SRIOV
) {
9036 if (vsi
->netdev_registered
) {
9037 vsi
->netdev_registered
= false;
9039 /* results in a call to i40e_close() */
9040 unregister_netdev(vsi
->netdev
);
9043 i40e_vsi_close(vsi
);
9045 i40e_vsi_disable_irq(vsi
);
9048 spin_lock_bh(&vsi
->mac_filter_list_lock
);
9049 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
)
9050 i40e_del_filter(vsi
, f
->macaddr
, f
->vlan
,
9051 f
->is_vf
, f
->is_netdev
);
9052 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
9054 i40e_sync_vsi_filters(vsi
, false);
9056 i40e_vsi_delete(vsi
);
9057 i40e_vsi_free_q_vectors(vsi
);
9059 free_netdev(vsi
->netdev
);
9062 i40e_vsi_clear_rings(vsi
);
9063 i40e_vsi_clear(vsi
);
9065 /* If this was the last thing on the VEB, except for the
9066 * controlling VSI, remove the VEB, which puts the controlling
9067 * VSI onto the next level down in the switch.
9069 * Well, okay, there's one more exception here: don't remove
9070 * the orphan VEBs yet. We'll wait for an explicit remove request
9071 * from up the network stack.
9073 for (n
= 0, i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9075 pf
->vsi
[i
]->uplink_seid
== uplink_seid
&&
9076 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
9077 n
++; /* count the VSIs */
9080 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
9083 if (pf
->veb
[i
]->uplink_seid
== uplink_seid
)
9084 n
++; /* count the VEBs */
9085 if (pf
->veb
[i
]->seid
== uplink_seid
)
9088 if (n
== 0 && veb
&& veb
->uplink_seid
!= 0)
9089 i40e_veb_release(veb
);
9095 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
9096 * @vsi: ptr to the VSI
9098 * This should only be called after i40e_vsi_mem_alloc() which allocates the
9099 * corresponding SW VSI structure and initializes num_queue_pairs for the
9100 * newly allocated VSI.
9102 * Returns 0 on success or negative on failure
9104 static int i40e_vsi_setup_vectors(struct i40e_vsi
*vsi
)
9107 struct i40e_pf
*pf
= vsi
->back
;
9109 if (vsi
->q_vectors
[0]) {
9110 dev_info(&pf
->pdev
->dev
, "VSI %d has existing q_vectors\n",
9115 if (vsi
->base_vector
) {
9116 dev_info(&pf
->pdev
->dev
, "VSI %d has non-zero base vector %d\n",
9117 vsi
->seid
, vsi
->base_vector
);
9121 ret
= i40e_vsi_alloc_q_vectors(vsi
);
9123 dev_info(&pf
->pdev
->dev
,
9124 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
9125 vsi
->num_q_vectors
, vsi
->seid
, ret
);
9126 vsi
->num_q_vectors
= 0;
9127 goto vector_setup_out
;
9130 /* In Legacy mode, we do not have to get any other vector since we
9131 * piggyback on the misc/ICR0 for queue interrupts.
9133 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
9135 if (vsi
->num_q_vectors
)
9136 vsi
->base_vector
= i40e_get_lump(pf
, pf
->irq_pile
,
9137 vsi
->num_q_vectors
, vsi
->idx
);
9138 if (vsi
->base_vector
< 0) {
9139 dev_info(&pf
->pdev
->dev
,
9140 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
9141 vsi
->num_q_vectors
, vsi
->seid
, vsi
->base_vector
);
9142 i40e_vsi_free_q_vectors(vsi
);
9144 goto vector_setup_out
;
9152 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
9153 * @vsi: pointer to the vsi.
9155 * This re-allocates a vsi's queue resources.
9157 * Returns pointer to the successfully allocated and configured VSI sw struct
9158 * on success, otherwise returns NULL on failure.
9160 static struct i40e_vsi
*i40e_vsi_reinit_setup(struct i40e_vsi
*vsi
)
9162 struct i40e_pf
*pf
= vsi
->back
;
9166 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
9167 i40e_vsi_clear_rings(vsi
);
9169 i40e_vsi_free_arrays(vsi
, false);
9170 i40e_set_num_rings_in_vsi(vsi
);
9171 ret
= i40e_vsi_alloc_arrays(vsi
, false);
9175 ret
= i40e_get_lump(pf
, pf
->qp_pile
, vsi
->alloc_queue_pairs
, vsi
->idx
);
9177 dev_info(&pf
->pdev
->dev
,
9178 "failed to get tracking for %d queues for VSI %d err %d\n",
9179 vsi
->alloc_queue_pairs
, vsi
->seid
, ret
);
9182 vsi
->base_queue
= ret
;
9184 /* Update the FW view of the VSI. Force a reset of TC and queue
9185 * layout configurations.
9187 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
9188 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
9189 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
9190 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
9192 /* assign it some queues */
9193 ret
= i40e_alloc_rings(vsi
);
9197 /* map all of the rings to the q_vectors */
9198 i40e_vsi_map_rings_to_vectors(vsi
);
9202 i40e_vsi_free_q_vectors(vsi
);
9203 if (vsi
->netdev_registered
) {
9204 vsi
->netdev_registered
= false;
9205 unregister_netdev(vsi
->netdev
);
9206 free_netdev(vsi
->netdev
);
9209 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
9211 i40e_vsi_clear(vsi
);
9216 * i40e_vsi_setup - Set up a VSI by a given type
9217 * @pf: board private structure
9219 * @uplink_seid: the switch element to link to
9220 * @param1: usage depends upon VSI type. For VF types, indicates VF id
9222 * This allocates the sw VSI structure and its queue resources, then add a VSI
9223 * to the identified VEB.
9225 * Returns pointer to the successfully allocated and configure VSI sw struct on
9226 * success, otherwise returns NULL on failure.
9228 struct i40e_vsi
*i40e_vsi_setup(struct i40e_pf
*pf
, u8 type
,
9229 u16 uplink_seid
, u32 param1
)
9231 struct i40e_vsi
*vsi
= NULL
;
9232 struct i40e_veb
*veb
= NULL
;
9236 /* The requested uplink_seid must be either
9237 * - the PF's port seid
9238 * no VEB is needed because this is the PF
9239 * or this is a Flow Director special case VSI
9240 * - seid of an existing VEB
9241 * - seid of a VSI that owns an existing VEB
9242 * - seid of a VSI that doesn't own a VEB
9243 * a new VEB is created and the VSI becomes the owner
9244 * - seid of the PF VSI, which is what creates the first VEB
9245 * this is a special case of the previous
9247 * Find which uplink_seid we were given and create a new VEB if needed
9249 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
9250 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== uplink_seid
) {
9256 if (!veb
&& uplink_seid
!= pf
->mac_seid
) {
9258 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9259 if (pf
->vsi
[i
] && pf
->vsi
[i
]->seid
== uplink_seid
) {
9265 dev_info(&pf
->pdev
->dev
, "no such uplink_seid %d\n",
9270 if (vsi
->uplink_seid
== pf
->mac_seid
)
9271 veb
= i40e_veb_setup(pf
, 0, pf
->mac_seid
, vsi
->seid
,
9272 vsi
->tc_config
.enabled_tc
);
9273 else if ((vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0)
9274 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
9275 vsi
->tc_config
.enabled_tc
);
9277 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
) {
9278 dev_info(&vsi
->back
->pdev
->dev
,
9279 "New VSI creation error, uplink seid of LAN VSI expected.\n");
9282 /* We come up by default in VEPA mode if SRIOV is not
9283 * already enabled, in which case we can't force VEPA
9286 if (!(pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)) {
9287 veb
->bridge_mode
= BRIDGE_MODE_VEPA
;
9288 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
9290 i40e_config_bridge_mode(veb
);
9292 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
9293 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
9297 dev_info(&pf
->pdev
->dev
, "couldn't add VEB\n");
9301 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
9302 uplink_seid
= veb
->seid
;
9305 /* get vsi sw struct */
9306 v_idx
= i40e_vsi_mem_alloc(pf
, type
);
9309 vsi
= pf
->vsi
[v_idx
];
9313 vsi
->veb_idx
= (veb
? veb
->idx
: I40E_NO_VEB
);
9315 if (type
== I40E_VSI_MAIN
)
9316 pf
->lan_vsi
= v_idx
;
9317 else if (type
== I40E_VSI_SRIOV
)
9318 vsi
->vf_id
= param1
;
9319 /* assign it some queues */
9320 ret
= i40e_get_lump(pf
, pf
->qp_pile
, vsi
->alloc_queue_pairs
,
9323 dev_info(&pf
->pdev
->dev
,
9324 "failed to get tracking for %d queues for VSI %d err=%d\n",
9325 vsi
->alloc_queue_pairs
, vsi
->seid
, ret
);
9328 vsi
->base_queue
= ret
;
9330 /* get a VSI from the hardware */
9331 vsi
->uplink_seid
= uplink_seid
;
9332 ret
= i40e_add_vsi(vsi
);
9336 switch (vsi
->type
) {
9337 /* setup the netdev if needed */
9339 case I40E_VSI_VMDQ2
:
9341 ret
= i40e_config_netdev(vsi
);
9344 ret
= register_netdev(vsi
->netdev
);
9347 vsi
->netdev_registered
= true;
9348 netif_carrier_off(vsi
->netdev
);
9349 #ifdef CONFIG_I40E_DCB
9350 /* Setup DCB netlink interface */
9351 i40e_dcbnl_setup(vsi
);
9352 #endif /* CONFIG_I40E_DCB */
9356 /* set up vectors and rings if needed */
9357 ret
= i40e_vsi_setup_vectors(vsi
);
9361 ret
= i40e_alloc_rings(vsi
);
9365 /* map all of the rings to the q_vectors */
9366 i40e_vsi_map_rings_to_vectors(vsi
);
9368 i40e_vsi_reset_stats(vsi
);
9372 /* no netdev or rings for the other VSI types */
9376 if ((pf
->flags
& I40E_FLAG_RSS_AQ_CAPABLE
) &&
9377 (vsi
->type
== I40E_VSI_VMDQ2
)) {
9378 ret
= i40e_vsi_config_rss(vsi
);
9383 i40e_vsi_free_q_vectors(vsi
);
9385 if (vsi
->netdev_registered
) {
9386 vsi
->netdev_registered
= false;
9387 unregister_netdev(vsi
->netdev
);
9388 free_netdev(vsi
->netdev
);
9392 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
9394 i40e_vsi_clear(vsi
);
9400 * i40e_veb_get_bw_info - Query VEB BW information
9401 * @veb: the veb to query
9403 * Query the Tx scheduler BW configuration data for given VEB
9405 static int i40e_veb_get_bw_info(struct i40e_veb
*veb
)
9407 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data
;
9408 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data
;
9409 struct i40e_pf
*pf
= veb
->pf
;
9410 struct i40e_hw
*hw
= &pf
->hw
;
9415 ret
= i40e_aq_query_switch_comp_bw_config(hw
, veb
->seid
,
9418 dev_info(&pf
->pdev
->dev
,
9419 "query veb bw config failed, err %s aq_err %s\n",
9420 i40e_stat_str(&pf
->hw
, ret
),
9421 i40e_aq_str(&pf
->hw
, hw
->aq
.asq_last_status
));
9425 ret
= i40e_aq_query_switch_comp_ets_config(hw
, veb
->seid
,
9428 dev_info(&pf
->pdev
->dev
,
9429 "query veb bw ets config failed, err %s aq_err %s\n",
9430 i40e_stat_str(&pf
->hw
, ret
),
9431 i40e_aq_str(&pf
->hw
, hw
->aq
.asq_last_status
));
9435 veb
->bw_limit
= le16_to_cpu(ets_data
.port_bw_limit
);
9436 veb
->bw_max_quanta
= ets_data
.tc_bw_max
;
9437 veb
->is_abs_credits
= bw_data
.absolute_credits_enable
;
9438 veb
->enabled_tc
= ets_data
.tc_valid_bits
;
9439 tc_bw_max
= le16_to_cpu(bw_data
.tc_bw_max
[0]) |
9440 (le16_to_cpu(bw_data
.tc_bw_max
[1]) << 16);
9441 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
9442 veb
->bw_tc_share_credits
[i
] = bw_data
.tc_bw_share_credits
[i
];
9443 veb
->bw_tc_limit_credits
[i
] =
9444 le16_to_cpu(bw_data
.tc_bw_limits
[i
]);
9445 veb
->bw_tc_max_quanta
[i
] = ((tc_bw_max
>> (i
*4)) & 0x7);
9453 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
9454 * @pf: board private structure
9456 * On error: returns error code (negative)
9457 * On success: returns vsi index in PF (positive)
9459 static int i40e_veb_mem_alloc(struct i40e_pf
*pf
)
9462 struct i40e_veb
*veb
;
9465 /* Need to protect the allocation of switch elements at the PF level */
9466 mutex_lock(&pf
->switch_mutex
);
9468 /* VEB list may be fragmented if VEB creation/destruction has
9469 * been happening. We can afford to do a quick scan to look
9470 * for any free slots in the list.
9472 * find next empty veb slot, looping back around if necessary
9475 while ((i
< I40E_MAX_VEB
) && (pf
->veb
[i
] != NULL
))
9477 if (i
>= I40E_MAX_VEB
) {
9479 goto err_alloc_veb
; /* out of VEB slots! */
9482 veb
= kzalloc(sizeof(*veb
), GFP_KERNEL
);
9489 veb
->enabled_tc
= 1;
9494 mutex_unlock(&pf
->switch_mutex
);
9499 * i40e_switch_branch_release - Delete a branch of the switch tree
9500 * @branch: where to start deleting
9502 * This uses recursion to find the tips of the branch to be
9503 * removed, deleting until we get back to and can delete this VEB.
9505 static void i40e_switch_branch_release(struct i40e_veb
*branch
)
9507 struct i40e_pf
*pf
= branch
->pf
;
9508 u16 branch_seid
= branch
->seid
;
9509 u16 veb_idx
= branch
->idx
;
9512 /* release any VEBs on this VEB - RECURSION */
9513 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
9516 if (pf
->veb
[i
]->uplink_seid
== branch
->seid
)
9517 i40e_switch_branch_release(pf
->veb
[i
]);
9520 /* Release the VSIs on this VEB, but not the owner VSI.
9522 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
9523 * the VEB itself, so don't use (*branch) after this loop.
9525 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9528 if (pf
->vsi
[i
]->uplink_seid
== branch_seid
&&
9529 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
9530 i40e_vsi_release(pf
->vsi
[i
]);
9534 /* There's one corner case where the VEB might not have been
9535 * removed, so double check it here and remove it if needed.
9536 * This case happens if the veb was created from the debugfs
9537 * commands and no VSIs were added to it.
9539 if (pf
->veb
[veb_idx
])
9540 i40e_veb_release(pf
->veb
[veb_idx
]);
9544 * i40e_veb_clear - remove veb struct
9545 * @veb: the veb to remove
9547 static void i40e_veb_clear(struct i40e_veb
*veb
)
9553 struct i40e_pf
*pf
= veb
->pf
;
9555 mutex_lock(&pf
->switch_mutex
);
9556 if (pf
->veb
[veb
->idx
] == veb
)
9557 pf
->veb
[veb
->idx
] = NULL
;
9558 mutex_unlock(&pf
->switch_mutex
);
9565 * i40e_veb_release - Delete a VEB and free its resources
9566 * @veb: the VEB being removed
9568 void i40e_veb_release(struct i40e_veb
*veb
)
9570 struct i40e_vsi
*vsi
= NULL
;
9576 /* find the remaining VSI and check for extras */
9577 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9578 if (pf
->vsi
[i
] && pf
->vsi
[i
]->uplink_seid
== veb
->seid
) {
9584 dev_info(&pf
->pdev
->dev
,
9585 "can't remove VEB %d with %d VSIs left\n",
9590 /* move the remaining VSI to uplink veb */
9591 vsi
->flags
&= ~I40E_VSI_FLAG_VEB_OWNER
;
9592 if (veb
->uplink_seid
) {
9593 vsi
->uplink_seid
= veb
->uplink_seid
;
9594 if (veb
->uplink_seid
== pf
->mac_seid
)
9595 vsi
->veb_idx
= I40E_NO_VEB
;
9597 vsi
->veb_idx
= veb
->veb_idx
;
9600 vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
9601 vsi
->veb_idx
= pf
->vsi
[pf
->lan_vsi
]->veb_idx
;
9604 i40e_aq_delete_element(&pf
->hw
, veb
->seid
, NULL
);
9605 i40e_veb_clear(veb
);
9609 * i40e_add_veb - create the VEB in the switch
9610 * @veb: the VEB to be instantiated
9611 * @vsi: the controlling VSI
9613 static int i40e_add_veb(struct i40e_veb
*veb
, struct i40e_vsi
*vsi
)
9615 struct i40e_pf
*pf
= veb
->pf
;
9616 bool is_default
= veb
->pf
->cur_promisc
;
9617 bool is_cloud
= false;
9620 /* get a VEB from the hardware */
9621 ret
= i40e_aq_add_veb(&pf
->hw
, veb
->uplink_seid
, vsi
->seid
,
9622 veb
->enabled_tc
, is_default
,
9623 is_cloud
, &veb
->seid
, NULL
);
9625 dev_info(&pf
->pdev
->dev
,
9626 "couldn't add VEB, err %s aq_err %s\n",
9627 i40e_stat_str(&pf
->hw
, ret
),
9628 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9632 /* get statistics counter */
9633 ret
= i40e_aq_get_veb_parameters(&pf
->hw
, veb
->seid
, NULL
, NULL
,
9634 &veb
->stats_idx
, NULL
, NULL
, NULL
);
9636 dev_info(&pf
->pdev
->dev
,
9637 "couldn't get VEB statistics idx, err %s aq_err %s\n",
9638 i40e_stat_str(&pf
->hw
, ret
),
9639 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9642 ret
= i40e_veb_get_bw_info(veb
);
9644 dev_info(&pf
->pdev
->dev
,
9645 "couldn't get VEB bw info, err %s aq_err %s\n",
9646 i40e_stat_str(&pf
->hw
, ret
),
9647 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9648 i40e_aq_delete_element(&pf
->hw
, veb
->seid
, NULL
);
9652 vsi
->uplink_seid
= veb
->seid
;
9653 vsi
->veb_idx
= veb
->idx
;
9654 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
9660 * i40e_veb_setup - Set up a VEB
9661 * @pf: board private structure
9662 * @flags: VEB setup flags
9663 * @uplink_seid: the switch element to link to
9664 * @vsi_seid: the initial VSI seid
9665 * @enabled_tc: Enabled TC bit-map
9667 * This allocates the sw VEB structure and links it into the switch
9668 * It is possible and legal for this to be a duplicate of an already
9669 * existing VEB. It is also possible for both uplink and vsi seids
9670 * to be zero, in order to create a floating VEB.
9672 * Returns pointer to the successfully allocated VEB sw struct on
9673 * success, otherwise returns NULL on failure.
9675 struct i40e_veb
*i40e_veb_setup(struct i40e_pf
*pf
, u16 flags
,
9676 u16 uplink_seid
, u16 vsi_seid
,
9679 struct i40e_veb
*veb
, *uplink_veb
= NULL
;
9680 int vsi_idx
, veb_idx
;
9683 /* if one seid is 0, the other must be 0 to create a floating relay */
9684 if ((uplink_seid
== 0 || vsi_seid
== 0) &&
9685 (uplink_seid
+ vsi_seid
!= 0)) {
9686 dev_info(&pf
->pdev
->dev
,
9687 "one, not both seid's are 0: uplink=%d vsi=%d\n",
9688 uplink_seid
, vsi_seid
);
9692 /* make sure there is such a vsi and uplink */
9693 for (vsi_idx
= 0; vsi_idx
< pf
->num_alloc_vsi
; vsi_idx
++)
9694 if (pf
->vsi
[vsi_idx
] && pf
->vsi
[vsi_idx
]->seid
== vsi_seid
)
9696 if (vsi_idx
>= pf
->num_alloc_vsi
&& vsi_seid
!= 0) {
9697 dev_info(&pf
->pdev
->dev
, "vsi seid %d not found\n",
9702 if (uplink_seid
&& uplink_seid
!= pf
->mac_seid
) {
9703 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
9704 if (pf
->veb
[veb_idx
] &&
9705 pf
->veb
[veb_idx
]->seid
== uplink_seid
) {
9706 uplink_veb
= pf
->veb
[veb_idx
];
9711 dev_info(&pf
->pdev
->dev
,
9712 "uplink seid %d not found\n", uplink_seid
);
9717 /* get veb sw struct */
9718 veb_idx
= i40e_veb_mem_alloc(pf
);
9721 veb
= pf
->veb
[veb_idx
];
9723 veb
->uplink_seid
= uplink_seid
;
9724 veb
->veb_idx
= (uplink_veb
? uplink_veb
->idx
: I40E_NO_VEB
);
9725 veb
->enabled_tc
= (enabled_tc
? enabled_tc
: 0x1);
9727 /* create the VEB in the switch */
9728 ret
= i40e_add_veb(veb
, pf
->vsi
[vsi_idx
]);
9731 if (vsi_idx
== pf
->lan_vsi
)
9732 pf
->lan_veb
= veb
->idx
;
9737 i40e_veb_clear(veb
);
9743 * i40e_setup_pf_switch_element - set PF vars based on switch type
9744 * @pf: board private structure
9745 * @ele: element we are building info from
9746 * @num_reported: total number of elements
9747 * @printconfig: should we print the contents
9749 * helper function to assist in extracting a few useful SEID values.
9751 static void i40e_setup_pf_switch_element(struct i40e_pf
*pf
,
9752 struct i40e_aqc_switch_config_element_resp
*ele
,
9753 u16 num_reported
, bool printconfig
)
9755 u16 downlink_seid
= le16_to_cpu(ele
->downlink_seid
);
9756 u16 uplink_seid
= le16_to_cpu(ele
->uplink_seid
);
9757 u8 element_type
= ele
->element_type
;
9758 u16 seid
= le16_to_cpu(ele
->seid
);
9761 dev_info(&pf
->pdev
->dev
,
9762 "type=%d seid=%d uplink=%d downlink=%d\n",
9763 element_type
, seid
, uplink_seid
, downlink_seid
);
9765 switch (element_type
) {
9766 case I40E_SWITCH_ELEMENT_TYPE_MAC
:
9767 pf
->mac_seid
= seid
;
9769 case I40E_SWITCH_ELEMENT_TYPE_VEB
:
9771 if (uplink_seid
!= pf
->mac_seid
)
9773 if (pf
->lan_veb
== I40E_NO_VEB
) {
9776 /* find existing or else empty VEB */
9777 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
9778 if (pf
->veb
[v
] && (pf
->veb
[v
]->seid
== seid
)) {
9783 if (pf
->lan_veb
== I40E_NO_VEB
) {
9784 v
= i40e_veb_mem_alloc(pf
);
9791 pf
->veb
[pf
->lan_veb
]->seid
= seid
;
9792 pf
->veb
[pf
->lan_veb
]->uplink_seid
= pf
->mac_seid
;
9793 pf
->veb
[pf
->lan_veb
]->pf
= pf
;
9794 pf
->veb
[pf
->lan_veb
]->veb_idx
= I40E_NO_VEB
;
9796 case I40E_SWITCH_ELEMENT_TYPE_VSI
:
9797 if (num_reported
!= 1)
9799 /* This is immediately after a reset so we can assume this is
9802 pf
->mac_seid
= uplink_seid
;
9803 pf
->pf_seid
= downlink_seid
;
9804 pf
->main_vsi_seid
= seid
;
9806 dev_info(&pf
->pdev
->dev
,
9807 "pf_seid=%d main_vsi_seid=%d\n",
9808 pf
->pf_seid
, pf
->main_vsi_seid
);
9810 case I40E_SWITCH_ELEMENT_TYPE_PF
:
9811 case I40E_SWITCH_ELEMENT_TYPE_VF
:
9812 case I40E_SWITCH_ELEMENT_TYPE_EMP
:
9813 case I40E_SWITCH_ELEMENT_TYPE_BMC
:
9814 case I40E_SWITCH_ELEMENT_TYPE_PE
:
9815 case I40E_SWITCH_ELEMENT_TYPE_PA
:
9816 /* ignore these for now */
9819 dev_info(&pf
->pdev
->dev
, "unknown element type=%d seid=%d\n",
9820 element_type
, seid
);
9826 * i40e_fetch_switch_configuration - Get switch config from firmware
9827 * @pf: board private structure
9828 * @printconfig: should we print the contents
9830 * Get the current switch configuration from the device and
9831 * extract a few useful SEID values.
9833 int i40e_fetch_switch_configuration(struct i40e_pf
*pf
, bool printconfig
)
9835 struct i40e_aqc_get_switch_config_resp
*sw_config
;
9841 aq_buf
= kzalloc(I40E_AQ_LARGE_BUF
, GFP_KERNEL
);
9845 sw_config
= (struct i40e_aqc_get_switch_config_resp
*)aq_buf
;
9847 u16 num_reported
, num_total
;
9849 ret
= i40e_aq_get_switch_config(&pf
->hw
, sw_config
,
9853 dev_info(&pf
->pdev
->dev
,
9854 "get switch config failed err %s aq_err %s\n",
9855 i40e_stat_str(&pf
->hw
, ret
),
9856 i40e_aq_str(&pf
->hw
,
9857 pf
->hw
.aq
.asq_last_status
));
9862 num_reported
= le16_to_cpu(sw_config
->header
.num_reported
);
9863 num_total
= le16_to_cpu(sw_config
->header
.num_total
);
9866 dev_info(&pf
->pdev
->dev
,
9867 "header: %d reported %d total\n",
9868 num_reported
, num_total
);
9870 for (i
= 0; i
< num_reported
; i
++) {
9871 struct i40e_aqc_switch_config_element_resp
*ele
=
9872 &sw_config
->element
[i
];
9874 i40e_setup_pf_switch_element(pf
, ele
, num_reported
,
9877 } while (next_seid
!= 0);
9884 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
9885 * @pf: board private structure
9886 * @reinit: if the Main VSI needs to re-initialized.
9888 * Returns 0 on success, negative value on failure
9890 static int i40e_setup_pf_switch(struct i40e_pf
*pf
, bool reinit
)
9894 /* find out what's out there already */
9895 ret
= i40e_fetch_switch_configuration(pf
, false);
9897 dev_info(&pf
->pdev
->dev
,
9898 "couldn't fetch switch config, err %s aq_err %s\n",
9899 i40e_stat_str(&pf
->hw
, ret
),
9900 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9903 i40e_pf_reset_stats(pf
);
9905 /* first time setup */
9906 if (pf
->lan_vsi
== I40E_NO_VSI
|| reinit
) {
9907 struct i40e_vsi
*vsi
= NULL
;
9910 /* Set up the PF VSI associated with the PF's main VSI
9911 * that is already in the HW switch
9913 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
9914 uplink_seid
= pf
->veb
[pf
->lan_veb
]->seid
;
9916 uplink_seid
= pf
->mac_seid
;
9917 if (pf
->lan_vsi
== I40E_NO_VSI
)
9918 vsi
= i40e_vsi_setup(pf
, I40E_VSI_MAIN
, uplink_seid
, 0);
9920 vsi
= i40e_vsi_reinit_setup(pf
->vsi
[pf
->lan_vsi
]);
9922 dev_info(&pf
->pdev
->dev
, "setup of MAIN VSI failed\n");
9923 i40e_fdir_teardown(pf
);
9927 /* force a reset of TC and queue layout configurations */
9928 u8 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
9930 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
9931 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
9932 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
9934 i40e_vlan_stripping_disable(pf
->vsi
[pf
->lan_vsi
]);
9936 i40e_fdir_sb_setup(pf
);
9938 /* Setup static PF queue filter control settings */
9939 ret
= i40e_setup_pf_filter_control(pf
);
9941 dev_info(&pf
->pdev
->dev
, "setup_pf_filter_control failed: %d\n",
9943 /* Failure here should not stop continuing other steps */
9946 /* enable RSS in the HW, even for only one queue, as the stack can use
9949 if ((pf
->flags
& I40E_FLAG_RSS_ENABLED
))
9950 i40e_config_rss(pf
);
9952 /* fill in link information and enable LSE reporting */
9953 i40e_update_link_info(&pf
->hw
);
9954 i40e_link_event(pf
);
9956 /* Initialize user-specific link properties */
9957 pf
->fc_autoneg_status
= ((pf
->hw
.phy
.link_info
.an_info
&
9958 I40E_AQ_AN_COMPLETED
) ? true : false);
9966 * i40e_determine_queue_usage - Work out queue distribution
9967 * @pf: board private structure
9969 static void i40e_determine_queue_usage(struct i40e_pf
*pf
)
9973 pf
->num_lan_qps
= 0;
9975 pf
->num_fcoe_qps
= 0;
9978 /* Find the max queues to be put into basic use. We'll always be
9979 * using TC0, whether or not DCB is running, and TC0 will get the
9982 queues_left
= pf
->hw
.func_caps
.num_tx_qp
;
9984 if ((queues_left
== 1) ||
9985 !(pf
->flags
& I40E_FLAG_MSIX_ENABLED
)) {
9986 /* one qp for PF, no queues for anything else */
9988 pf
->rss_size
= pf
->num_lan_qps
= 1;
9990 /* make sure all the fancies are disabled */
9991 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
9993 I40E_FLAG_FCOE_ENABLED
|
9995 I40E_FLAG_FD_SB_ENABLED
|
9996 I40E_FLAG_FD_ATR_ENABLED
|
9997 I40E_FLAG_DCB_CAPABLE
|
9998 I40E_FLAG_SRIOV_ENABLED
|
9999 I40E_FLAG_VMDQ_ENABLED
);
10000 } else if (!(pf
->flags
& (I40E_FLAG_RSS_ENABLED
|
10001 I40E_FLAG_FD_SB_ENABLED
|
10002 I40E_FLAG_FD_ATR_ENABLED
|
10003 I40E_FLAG_DCB_CAPABLE
))) {
10004 /* one qp for PF */
10005 pf
->rss_size
= pf
->num_lan_qps
= 1;
10006 queues_left
-= pf
->num_lan_qps
;
10008 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
10010 I40E_FLAG_FCOE_ENABLED
|
10012 I40E_FLAG_FD_SB_ENABLED
|
10013 I40E_FLAG_FD_ATR_ENABLED
|
10014 I40E_FLAG_DCB_ENABLED
|
10015 I40E_FLAG_VMDQ_ENABLED
);
10017 /* Not enough queues for all TCs */
10018 if ((pf
->flags
& I40E_FLAG_DCB_CAPABLE
) &&
10019 (queues_left
< I40E_MAX_TRAFFIC_CLASS
)) {
10020 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
10021 dev_info(&pf
->pdev
->dev
, "not enough queues for DCB. DCB is disabled.\n");
10023 pf
->num_lan_qps
= max_t(int, pf
->rss_size_max
,
10024 num_online_cpus());
10025 pf
->num_lan_qps
= min_t(int, pf
->num_lan_qps
,
10026 pf
->hw
.func_caps
.num_tx_qp
);
10028 queues_left
-= pf
->num_lan_qps
;
10032 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
10033 if (I40E_DEFAULT_FCOE
<= queues_left
) {
10034 pf
->num_fcoe_qps
= I40E_DEFAULT_FCOE
;
10035 } else if (I40E_MINIMUM_FCOE
<= queues_left
) {
10036 pf
->num_fcoe_qps
= I40E_MINIMUM_FCOE
;
10038 pf
->num_fcoe_qps
= 0;
10039 pf
->flags
&= ~I40E_FLAG_FCOE_ENABLED
;
10040 dev_info(&pf
->pdev
->dev
, "not enough queues for FCoE. FCoE feature will be disabled\n");
10043 queues_left
-= pf
->num_fcoe_qps
;
10047 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
10048 if (queues_left
> 1) {
10049 queues_left
-= 1; /* save 1 queue for FD */
10051 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
10052 dev_info(&pf
->pdev
->dev
, "not enough queues for Flow Director. Flow Director feature is disabled\n");
10056 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
10057 pf
->num_vf_qps
&& pf
->num_req_vfs
&& queues_left
) {
10058 pf
->num_req_vfs
= min_t(int, pf
->num_req_vfs
,
10059 (queues_left
/ pf
->num_vf_qps
));
10060 queues_left
-= (pf
->num_req_vfs
* pf
->num_vf_qps
);
10063 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
10064 pf
->num_vmdq_vsis
&& pf
->num_vmdq_qps
&& queues_left
) {
10065 pf
->num_vmdq_vsis
= min_t(int, pf
->num_vmdq_vsis
,
10066 (queues_left
/ pf
->num_vmdq_qps
));
10067 queues_left
-= (pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
);
10070 pf
->queues_left
= queues_left
;
10071 dev_dbg(&pf
->pdev
->dev
,
10072 "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
10073 pf
->hw
.func_caps
.num_tx_qp
,
10074 !!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
),
10075 pf
->num_lan_qps
, pf
->rss_size
, pf
->num_req_vfs
, pf
->num_vf_qps
,
10076 pf
->num_vmdq_vsis
, pf
->num_vmdq_qps
, queues_left
);
10078 dev_dbg(&pf
->pdev
->dev
, "fcoe queues = %d\n", pf
->num_fcoe_qps
);
10083 * i40e_setup_pf_filter_control - Setup PF static filter control
10084 * @pf: PF to be setup
10086 * i40e_setup_pf_filter_control sets up a PF's initial filter control
10087 * settings. If PE/FCoE are enabled then it will also set the per PF
10088 * based filter sizes required for them. It also enables Flow director,
10089 * ethertype and macvlan type filter settings for the pf.
10091 * Returns 0 on success, negative on failure
10093 static int i40e_setup_pf_filter_control(struct i40e_pf
*pf
)
10095 struct i40e_filter_control_settings
*settings
= &pf
->filter_settings
;
10097 settings
->hash_lut_size
= I40E_HASH_LUT_SIZE_128
;
10099 /* Flow Director is enabled */
10100 if (pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
))
10101 settings
->enable_fdir
= true;
10103 /* Ethtype and MACVLAN filters enabled for PF */
10104 settings
->enable_ethtype
= true;
10105 settings
->enable_macvlan
= true;
10107 if (i40e_set_filter_control(&pf
->hw
, settings
))
10113 #define INFO_STRING_LEN 255
10114 static void i40e_print_features(struct i40e_pf
*pf
)
10116 struct i40e_hw
*hw
= &pf
->hw
;
10117 char *buf
, *string
;
10119 string
= kzalloc(INFO_STRING_LEN
, GFP_KERNEL
);
10121 dev_err(&pf
->pdev
->dev
, "Features string allocation failed\n");
10127 buf
+= sprintf(string
, "Features: PF-id[%d] ", hw
->pf_id
);
10128 #ifdef CONFIG_PCI_IOV
10129 buf
+= sprintf(buf
, "VFs: %d ", pf
->num_req_vfs
);
10131 buf
+= sprintf(buf
, "VSIs: %d QP: %d RX: %s ",
10132 pf
->hw
.func_caps
.num_vsis
,
10133 pf
->vsi
[pf
->lan_vsi
]->num_queue_pairs
,
10134 pf
->flags
& I40E_FLAG_RX_PS_ENABLED
? "PS" : "1BUF");
10136 if (pf
->flags
& I40E_FLAG_RSS_ENABLED
)
10137 buf
+= sprintf(buf
, "RSS ");
10138 if (pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
)
10139 buf
+= sprintf(buf
, "FD_ATR ");
10140 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
10141 buf
+= sprintf(buf
, "FD_SB ");
10142 buf
+= sprintf(buf
, "NTUPLE ");
10144 if (pf
->flags
& I40E_FLAG_DCB_CAPABLE
)
10145 buf
+= sprintf(buf
, "DCB ");
10146 #if IS_ENABLED(CONFIG_VXLAN)
10147 buf
+= sprintf(buf
, "VxLAN ");
10149 if (pf
->flags
& I40E_FLAG_PTP
)
10150 buf
+= sprintf(buf
, "PTP ");
10152 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
)
10153 buf
+= sprintf(buf
, "FCOE ");
10155 if (pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)
10156 buf
+= sprintf(buf
, "VEB ");
10158 buf
+= sprintf(buf
, "VEPA ");
10160 BUG_ON(buf
> (string
+ INFO_STRING_LEN
));
10161 dev_info(&pf
->pdev
->dev
, "%s\n", string
);
10166 * i40e_probe - Device initialization routine
10167 * @pdev: PCI device information struct
10168 * @ent: entry in i40e_pci_tbl
10170 * i40e_probe initializes a PF identified by a pci_dev structure.
10171 * The OS initialization, configuring of the PF private structure,
10172 * and a hardware reset occur.
10174 * Returns 0 on success, negative on failure
10176 static int i40e_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
10178 struct i40e_aq_get_phy_abilities_resp abilities
;
10179 struct i40e_pf
*pf
;
10180 struct i40e_hw
*hw
;
10181 static u16 pfs_found
;
10189 err
= pci_enable_device_mem(pdev
);
10193 /* set up for high or low dma */
10194 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
10196 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
10198 dev_err(&pdev
->dev
,
10199 "DMA configuration failed: 0x%x\n", err
);
10204 /* set up pci connections */
10205 err
= pci_request_selected_regions(pdev
, pci_select_bars(pdev
,
10206 IORESOURCE_MEM
), i40e_driver_name
);
10208 dev_info(&pdev
->dev
,
10209 "pci_request_selected_regions failed %d\n", err
);
10213 pci_enable_pcie_error_reporting(pdev
);
10214 pci_set_master(pdev
);
10216 /* Now that we have a PCI connection, we need to do the
10217 * low level device setup. This is primarily setting up
10218 * the Admin Queue structures and then querying for the
10219 * device's current profile information.
10221 pf
= kzalloc(sizeof(*pf
), GFP_KERNEL
);
10228 set_bit(__I40E_DOWN
, &pf
->state
);
10233 pf
->ioremap_len
= min_t(int, pci_resource_len(pdev
, 0),
10234 I40E_MAX_CSR_SPACE
);
10236 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0), pf
->ioremap_len
);
10237 if (!hw
->hw_addr
) {
10239 dev_info(&pdev
->dev
, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
10240 (unsigned int)pci_resource_start(pdev
, 0),
10241 pf
->ioremap_len
, err
);
10244 hw
->vendor_id
= pdev
->vendor
;
10245 hw
->device_id
= pdev
->device
;
10246 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
10247 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
10248 hw
->subsystem_device_id
= pdev
->subsystem_device
;
10249 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
10250 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
10251 pf
->instance
= pfs_found
;
10254 pf
->msg_enable
= pf
->hw
.debug_mask
;
10255 pf
->msg_enable
= debug
;
10258 /* do a special CORER for clearing PXE mode once at init */
10259 if (hw
->revision_id
== 0 &&
10260 (rd32(hw
, I40E_GLLAN_RCTL_0
) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK
)) {
10261 wr32(hw
, I40E_GLGEN_RTRIG
, I40E_GLGEN_RTRIG_CORER_MASK
);
10266 i40e_clear_pxe_mode(hw
);
10269 /* Reset here to make sure all is clean and to define PF 'n' */
10271 err
= i40e_pf_reset(hw
);
10273 dev_info(&pdev
->dev
, "Initial pf_reset failed: %d\n", err
);
10278 hw
->aq
.num_arq_entries
= I40E_AQ_LEN
;
10279 hw
->aq
.num_asq_entries
= I40E_AQ_LEN
;
10280 hw
->aq
.arq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
10281 hw
->aq
.asq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
10282 pf
->adminq_work_limit
= I40E_AQ_WORK_LIMIT
;
10284 snprintf(pf
->int_name
, sizeof(pf
->int_name
) - 1,
10286 dev_driver_string(&pf
->pdev
->dev
), dev_name(&pdev
->dev
));
10288 err
= i40e_init_shared_code(hw
);
10290 dev_warn(&pdev
->dev
, "unidentified MAC or BLANK NVM: %d\n",
10295 /* set up a default setting for link flow control */
10296 pf
->hw
.fc
.requested_mode
= I40E_FC_NONE
;
10298 /* set up the locks for the AQ, do this only once in probe
10299 * and destroy them only once in remove
10301 mutex_init(&hw
->aq
.asq_mutex
);
10302 mutex_init(&hw
->aq
.arq_mutex
);
10304 err
= i40e_init_adminq(hw
);
10306 /* provide nvm, fw, api versions */
10307 dev_info(&pdev
->dev
, "fw %d.%d.%05d api %d.%d nvm %s\n",
10308 hw
->aq
.fw_maj_ver
, hw
->aq
.fw_min_ver
, hw
->aq
.fw_build
,
10309 hw
->aq
.api_maj_ver
, hw
->aq
.api_min_ver
,
10310 i40e_nvm_version_str(hw
));
10313 dev_info(&pdev
->dev
,
10314 "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");
10318 if (hw
->aq
.api_maj_ver
== I40E_FW_API_VERSION_MAJOR
&&
10319 hw
->aq
.api_min_ver
> I40E_FW_API_VERSION_MINOR
)
10320 dev_info(&pdev
->dev
,
10321 "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");
10322 else if (hw
->aq
.api_maj_ver
< I40E_FW_API_VERSION_MAJOR
||
10323 hw
->aq
.api_min_ver
< (I40E_FW_API_VERSION_MINOR
- 1))
10324 dev_info(&pdev
->dev
,
10325 "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
10327 i40e_verify_eeprom(pf
);
10329 /* Rev 0 hardware was never productized */
10330 if (hw
->revision_id
< 1)
10331 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");
10333 i40e_clear_pxe_mode(hw
);
10334 err
= i40e_get_capabilities(pf
);
10336 goto err_adminq_setup
;
10338 err
= i40e_sw_init(pf
);
10340 dev_info(&pdev
->dev
, "sw_init failed: %d\n", err
);
10344 err
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
10345 hw
->func_caps
.num_rx_qp
,
10346 pf
->fcoe_hmc_cntx_num
, pf
->fcoe_hmc_filt_num
);
10348 dev_info(&pdev
->dev
, "init_lan_hmc failed: %d\n", err
);
10349 goto err_init_lan_hmc
;
10352 err
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
10354 dev_info(&pdev
->dev
, "configure_lan_hmc failed: %d\n", err
);
10356 goto err_configure_lan_hmc
;
10359 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
10360 * Ignore error return codes because if it was already disabled via
10361 * hardware settings this will fail
10363 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 3)) ||
10364 (pf
->hw
.aq
.fw_maj_ver
< 4)) {
10365 dev_info(&pdev
->dev
, "Stopping firmware LLDP agent.\n");
10366 i40e_aq_stop_lldp(hw
, true, NULL
);
10369 i40e_get_mac_addr(hw
, hw
->mac
.addr
);
10370 if (!is_valid_ether_addr(hw
->mac
.addr
)) {
10371 dev_info(&pdev
->dev
, "invalid MAC address %pM\n", hw
->mac
.addr
);
10375 dev_info(&pdev
->dev
, "MAC address: %pM\n", hw
->mac
.addr
);
10376 ether_addr_copy(hw
->mac
.perm_addr
, hw
->mac
.addr
);
10377 i40e_get_port_mac_addr(hw
, hw
->mac
.port_addr
);
10378 if (is_valid_ether_addr(hw
->mac
.port_addr
))
10379 pf
->flags
|= I40E_FLAG_PORT_ID_VALID
;
10381 err
= i40e_get_san_mac_addr(hw
, hw
->mac
.san_addr
);
10383 dev_info(&pdev
->dev
,
10384 "(non-fatal) SAN MAC retrieval failed: %d\n", err
);
10385 if (!is_valid_ether_addr(hw
->mac
.san_addr
)) {
10386 dev_warn(&pdev
->dev
, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
10388 ether_addr_copy(hw
->mac
.san_addr
, hw
->mac
.addr
);
10390 dev_info(&pf
->pdev
->dev
, "SAN MAC: %pM\n", hw
->mac
.san_addr
);
10391 #endif /* I40E_FCOE */
10393 pci_set_drvdata(pdev
, pf
);
10394 pci_save_state(pdev
);
10395 #ifdef CONFIG_I40E_DCB
10396 err
= i40e_init_pf_dcb(pf
);
10398 dev_info(&pdev
->dev
, "DCB init failed %d, disabled\n", err
);
10399 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
10400 /* Continue without DCB enabled */
10402 #endif /* CONFIG_I40E_DCB */
10404 /* set up periodic task facility */
10405 setup_timer(&pf
->service_timer
, i40e_service_timer
, (unsigned long)pf
);
10406 pf
->service_timer_period
= HZ
;
10408 INIT_WORK(&pf
->service_task
, i40e_service_task
);
10409 clear_bit(__I40E_SERVICE_SCHED
, &pf
->state
);
10410 pf
->flags
|= I40E_FLAG_NEED_LINK_UPDATE
;
10412 /* NVM bit on means WoL disabled for the port */
10413 i40e_read_nvm_word(hw
, I40E_SR_NVM_WAKE_ON_LAN
, &wol_nvm_bits
);
10414 if ((1 << hw
->port
) & wol_nvm_bits
|| hw
->partition_id
!= 1)
10415 pf
->wol_en
= false;
10418 device_set_wakeup_enable(&pf
->pdev
->dev
, pf
->wol_en
);
10420 /* set up the main switch operations */
10421 i40e_determine_queue_usage(pf
);
10422 err
= i40e_init_interrupt_scheme(pf
);
10424 goto err_switch_setup
;
10426 /* The number of VSIs reported by the FW is the minimum guaranteed
10427 * to us; HW supports far more and we share the remaining pool with
10428 * the other PFs. We allocate space for more than the guarantee with
10429 * the understanding that we might not get them all later.
10431 if (pf
->hw
.func_caps
.num_vsis
< I40E_MIN_VSI_ALLOC
)
10432 pf
->num_alloc_vsi
= I40E_MIN_VSI_ALLOC
;
10434 pf
->num_alloc_vsi
= pf
->hw
.func_caps
.num_vsis
;
10436 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
10437 len
= sizeof(struct i40e_vsi
*) * pf
->num_alloc_vsi
;
10438 pf
->vsi
= kzalloc(len
, GFP_KERNEL
);
10441 goto err_switch_setup
;
10444 #ifdef CONFIG_PCI_IOV
10445 /* prep for VF support */
10446 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
10447 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
10448 !test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
10449 if (pci_num_vf(pdev
))
10450 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
10453 err
= i40e_setup_pf_switch(pf
, false);
10455 dev_info(&pdev
->dev
, "setup_pf_switch failed: %d\n", err
);
10459 /* Make sure flow control is set according to current settings */
10460 err
= i40e_set_fc(hw
, &set_fc_aq_fail
, true);
10461 if (set_fc_aq_fail
& I40E_SET_FC_AQ_FAIL_GET
)
10462 dev_dbg(&pf
->pdev
->dev
,
10463 "Set fc with err %s aq_err %s on get_phy_cap\n",
10464 i40e_stat_str(hw
, err
),
10465 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
10466 if (set_fc_aq_fail
& I40E_SET_FC_AQ_FAIL_SET
)
10467 dev_dbg(&pf
->pdev
->dev
,
10468 "Set fc with err %s aq_err %s on set_phy_config\n",
10469 i40e_stat_str(hw
, err
),
10470 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
10471 if (set_fc_aq_fail
& I40E_SET_FC_AQ_FAIL_UPDATE
)
10472 dev_dbg(&pf
->pdev
->dev
,
10473 "Set fc with err %s aq_err %s on get_link_info\n",
10474 i40e_stat_str(hw
, err
),
10475 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
10477 /* if FDIR VSI was set up, start it now */
10478 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
10479 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
10480 i40e_vsi_open(pf
->vsi
[i
]);
10485 /* driver is only interested in link up/down and module qualification
10486 * reports from firmware
10488 err
= i40e_aq_set_phy_int_mask(&pf
->hw
,
10489 I40E_AQ_EVENT_LINK_UPDOWN
|
10490 I40E_AQ_EVENT_MODULE_QUAL_FAIL
, NULL
);
10492 dev_info(&pf
->pdev
->dev
, "set phy mask fail, err %s aq_err %s\n",
10493 i40e_stat_str(&pf
->hw
, err
),
10494 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10496 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
10497 (pf
->hw
.aq
.fw_maj_ver
< 4)) {
10499 err
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
10501 dev_info(&pf
->pdev
->dev
, "link restart failed, err %s aq_err %s\n",
10502 i40e_stat_str(&pf
->hw
, err
),
10503 i40e_aq_str(&pf
->hw
,
10504 pf
->hw
.aq
.asq_last_status
));
10506 /* The main driver is (mostly) up and happy. We need to set this state
10507 * before setting up the misc vector or we get a race and the vector
10508 * ends up disabled forever.
10510 clear_bit(__I40E_DOWN
, &pf
->state
);
10512 /* In case of MSIX we are going to setup the misc vector right here
10513 * to handle admin queue events etc. In case of legacy and MSI
10514 * the misc functionality and queue processing is combined in
10515 * the same vector and that gets setup at open.
10517 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
10518 err
= i40e_setup_misc_vector(pf
);
10520 dev_info(&pdev
->dev
,
10521 "setup of misc vector failed: %d\n", err
);
10526 #ifdef CONFIG_PCI_IOV
10527 /* prep for VF support */
10528 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
10529 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
10530 !test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
10533 /* disable link interrupts for VFs */
10534 val
= rd32(hw
, I40E_PFGEN_PORTMDIO_NUM
);
10535 val
&= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK
;
10536 wr32(hw
, I40E_PFGEN_PORTMDIO_NUM
, val
);
10539 if (pci_num_vf(pdev
)) {
10540 dev_info(&pdev
->dev
,
10541 "Active VFs found, allocating resources.\n");
10542 err
= i40e_alloc_vfs(pf
, pci_num_vf(pdev
));
10544 dev_info(&pdev
->dev
,
10545 "Error %d allocating resources for existing VFs\n",
10549 #endif /* CONFIG_PCI_IOV */
10553 i40e_dbg_pf_init(pf
);
10555 /* tell the firmware that we're starting */
10556 i40e_send_version(pf
);
10558 /* since everything's happy, start the service_task timer */
10559 mod_timer(&pf
->service_timer
,
10560 round_jiffies(jiffies
+ pf
->service_timer_period
));
10563 /* create FCoE interface */
10564 i40e_fcoe_vsi_setup(pf
);
10567 #define PCI_SPEED_SIZE 8
10568 #define PCI_WIDTH_SIZE 8
10569 /* Devices on the IOSF bus do not have this information
10570 * and will report PCI Gen 1 x 1 by default so don't bother
10573 if (!(pf
->flags
& I40E_FLAG_NO_PCI_LINK_CHECK
)) {
10574 char speed
[PCI_SPEED_SIZE
] = "Unknown";
10575 char width
[PCI_WIDTH_SIZE
] = "Unknown";
10577 /* Get the negotiated link width and speed from PCI config
10580 pcie_capability_read_word(pf
->pdev
, PCI_EXP_LNKSTA
,
10583 i40e_set_pci_config_data(hw
, link_status
);
10585 switch (hw
->bus
.speed
) {
10586 case i40e_bus_speed_8000
:
10587 strncpy(speed
, "8.0", PCI_SPEED_SIZE
); break;
10588 case i40e_bus_speed_5000
:
10589 strncpy(speed
, "5.0", PCI_SPEED_SIZE
); break;
10590 case i40e_bus_speed_2500
:
10591 strncpy(speed
, "2.5", PCI_SPEED_SIZE
); break;
10595 switch (hw
->bus
.width
) {
10596 case i40e_bus_width_pcie_x8
:
10597 strncpy(width
, "8", PCI_WIDTH_SIZE
); break;
10598 case i40e_bus_width_pcie_x4
:
10599 strncpy(width
, "4", PCI_WIDTH_SIZE
); break;
10600 case i40e_bus_width_pcie_x2
:
10601 strncpy(width
, "2", PCI_WIDTH_SIZE
); break;
10602 case i40e_bus_width_pcie_x1
:
10603 strncpy(width
, "1", PCI_WIDTH_SIZE
); break;
10608 dev_info(&pdev
->dev
, "PCI-Express: Speed %sGT/s Width x%s\n",
10611 if (hw
->bus
.width
< i40e_bus_width_pcie_x8
||
10612 hw
->bus
.speed
< i40e_bus_speed_8000
) {
10613 dev_warn(&pdev
->dev
, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
10614 dev_warn(&pdev
->dev
, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
10618 /* get the requested speeds from the fw */
10619 err
= i40e_aq_get_phy_capabilities(hw
, false, false, &abilities
, NULL
);
10621 dev_dbg(&pf
->pdev
->dev
, "get requested speeds ret = %s last_status = %s\n",
10622 i40e_stat_str(&pf
->hw
, err
),
10623 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10624 pf
->hw
.phy
.link_info
.requested_speeds
= abilities
.link_speed
;
10626 /* get the supported phy types from the fw */
10627 err
= i40e_aq_get_phy_capabilities(hw
, false, true, &abilities
, NULL
);
10629 dev_dbg(&pf
->pdev
->dev
, "get supported phy types ret = %s last_status = %s\n",
10630 i40e_stat_str(&pf
->hw
, err
),
10631 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10632 pf
->hw
.phy
.phy_types
= le32_to_cpu(abilities
.phy_type
);
10634 /* Add a filter to drop all Flow control frames from any VSI from being
10635 * transmitted. By doing so we stop a malicious VF from sending out
10636 * PAUSE or PFC frames and potentially controlling traffic for other
10638 * The FW can still send Flow control frames if enabled.
10640 i40e_add_filter_to_drop_tx_flow_control_frames(&pf
->hw
,
10641 pf
->main_vsi_seid
);
10643 /* print a string summarizing features */
10644 i40e_print_features(pf
);
10648 /* Unwind what we've done if something failed in the setup */
10650 set_bit(__I40E_DOWN
, &pf
->state
);
10651 i40e_clear_interrupt_scheme(pf
);
10654 i40e_reset_interrupt_capability(pf
);
10655 del_timer_sync(&pf
->service_timer
);
10657 err_configure_lan_hmc
:
10658 (void)i40e_shutdown_lan_hmc(hw
);
10660 kfree(pf
->qp_pile
);
10663 (void)i40e_shutdown_adminq(hw
);
10665 iounmap(hw
->hw_addr
);
10669 pci_disable_pcie_error_reporting(pdev
);
10670 pci_release_selected_regions(pdev
,
10671 pci_select_bars(pdev
, IORESOURCE_MEM
));
10674 pci_disable_device(pdev
);
10679 * i40e_remove - Device removal routine
10680 * @pdev: PCI device information struct
10682 * i40e_remove is called by the PCI subsystem to alert the driver
10683 * that is should release a PCI device. This could be caused by a
10684 * Hot-Plug event, or because the driver is going to be removed from
10687 static void i40e_remove(struct pci_dev
*pdev
)
10689 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10690 struct i40e_hw
*hw
= &pf
->hw
;
10691 i40e_status ret_code
;
10694 i40e_dbg_pf_exit(pf
);
10698 /* Disable RSS in hw */
10699 wr32(hw
, I40E_PFQF_HENA(0), 0);
10700 wr32(hw
, I40E_PFQF_HENA(1), 0);
10702 /* no more scheduling of any task */
10703 set_bit(__I40E_DOWN
, &pf
->state
);
10704 del_timer_sync(&pf
->service_timer
);
10705 cancel_work_sync(&pf
->service_task
);
10707 if (pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) {
10709 pf
->flags
&= ~I40E_FLAG_SRIOV_ENABLED
;
10712 i40e_fdir_teardown(pf
);
10714 /* If there is a switch structure or any orphans, remove them.
10715 * This will leave only the PF's VSI remaining.
10717 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
10721 if (pf
->veb
[i
]->uplink_seid
== pf
->mac_seid
||
10722 pf
->veb
[i
]->uplink_seid
== 0)
10723 i40e_switch_branch_release(pf
->veb
[i
]);
10726 /* Now we can shutdown the PF's VSI, just before we kill
10729 if (pf
->vsi
[pf
->lan_vsi
])
10730 i40e_vsi_release(pf
->vsi
[pf
->lan_vsi
]);
10732 /* shutdown and destroy the HMC */
10733 if (pf
->hw
.hmc
.hmc_obj
) {
10734 ret_code
= i40e_shutdown_lan_hmc(&pf
->hw
);
10736 dev_warn(&pdev
->dev
,
10737 "Failed to destroy the HMC resources: %d\n",
10741 /* shutdown the adminq */
10742 ret_code
= i40e_shutdown_adminq(&pf
->hw
);
10744 dev_warn(&pdev
->dev
,
10745 "Failed to destroy the Admin Queue resources: %d\n",
10748 /* destroy the locks only once, here */
10749 mutex_destroy(&hw
->aq
.arq_mutex
);
10750 mutex_destroy(&hw
->aq
.asq_mutex
);
10752 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
10753 i40e_clear_interrupt_scheme(pf
);
10754 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
10756 i40e_vsi_clear_rings(pf
->vsi
[i
]);
10757 i40e_vsi_clear(pf
->vsi
[i
]);
10762 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
10767 kfree(pf
->qp_pile
);
10770 iounmap(pf
->hw
.hw_addr
);
10772 pci_release_selected_regions(pdev
,
10773 pci_select_bars(pdev
, IORESOURCE_MEM
));
10775 pci_disable_pcie_error_reporting(pdev
);
10776 pci_disable_device(pdev
);
10780 * i40e_pci_error_detected - warning that something funky happened in PCI land
10781 * @pdev: PCI device information struct
10783 * Called to warn that something happened and the error handling steps
10784 * are in progress. Allows the driver to quiesce things, be ready for
10787 static pci_ers_result_t
i40e_pci_error_detected(struct pci_dev
*pdev
,
10788 enum pci_channel_state error
)
10790 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10792 dev_info(&pdev
->dev
, "%s: error %d\n", __func__
, error
);
10794 /* shutdown all operations */
10795 if (!test_bit(__I40E_SUSPENDED
, &pf
->state
)) {
10797 i40e_prep_for_reset(pf
);
10801 /* Request a slot reset */
10802 return PCI_ERS_RESULT_NEED_RESET
;
10806 * i40e_pci_error_slot_reset - a PCI slot reset just happened
10807 * @pdev: PCI device information struct
10809 * Called to find if the driver can work with the device now that
10810 * the pci slot has been reset. If a basic connection seems good
10811 * (registers are readable and have sane content) then return a
10812 * happy little PCI_ERS_RESULT_xxx.
10814 static pci_ers_result_t
i40e_pci_error_slot_reset(struct pci_dev
*pdev
)
10816 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10817 pci_ers_result_t result
;
10821 dev_dbg(&pdev
->dev
, "%s\n", __func__
);
10822 if (pci_enable_device_mem(pdev
)) {
10823 dev_info(&pdev
->dev
,
10824 "Cannot re-enable PCI device after reset.\n");
10825 result
= PCI_ERS_RESULT_DISCONNECT
;
10827 pci_set_master(pdev
);
10828 pci_restore_state(pdev
);
10829 pci_save_state(pdev
);
10830 pci_wake_from_d3(pdev
, false);
10832 reg
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
10834 result
= PCI_ERS_RESULT_RECOVERED
;
10836 result
= PCI_ERS_RESULT_DISCONNECT
;
10839 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
10841 dev_info(&pdev
->dev
,
10842 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
10844 /* non-fatal, continue */
10851 * i40e_pci_error_resume - restart operations after PCI error recovery
10852 * @pdev: PCI device information struct
10854 * Called to allow the driver to bring things back up after PCI error
10855 * and/or reset recovery has finished.
10857 static void i40e_pci_error_resume(struct pci_dev
*pdev
)
10859 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10861 dev_dbg(&pdev
->dev
, "%s\n", __func__
);
10862 if (test_bit(__I40E_SUSPENDED
, &pf
->state
))
10866 i40e_handle_reset_warning(pf
);
10871 * i40e_shutdown - PCI callback for shutting down
10872 * @pdev: PCI device information struct
10874 static void i40e_shutdown(struct pci_dev
*pdev
)
10876 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10877 struct i40e_hw
*hw
= &pf
->hw
;
10879 set_bit(__I40E_SUSPENDED
, &pf
->state
);
10880 set_bit(__I40E_DOWN
, &pf
->state
);
10882 i40e_prep_for_reset(pf
);
10885 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
10886 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
10888 del_timer_sync(&pf
->service_timer
);
10889 cancel_work_sync(&pf
->service_task
);
10890 i40e_fdir_teardown(pf
);
10893 i40e_prep_for_reset(pf
);
10896 wr32(hw
, I40E_PFPM_APM
,
10897 (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
10898 wr32(hw
, I40E_PFPM_WUFC
,
10899 (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
10901 i40e_clear_interrupt_scheme(pf
);
10903 if (system_state
== SYSTEM_POWER_OFF
) {
10904 pci_wake_from_d3(pdev
, pf
->wol_en
);
10905 pci_set_power_state(pdev
, PCI_D3hot
);
10911 * i40e_suspend - PCI callback for moving to D3
10912 * @pdev: PCI device information struct
10914 static int i40e_suspend(struct pci_dev
*pdev
, pm_message_t state
)
10916 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10917 struct i40e_hw
*hw
= &pf
->hw
;
10919 set_bit(__I40E_SUSPENDED
, &pf
->state
);
10920 set_bit(__I40E_DOWN
, &pf
->state
);
10923 i40e_prep_for_reset(pf
);
10926 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
10927 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
10929 pci_wake_from_d3(pdev
, pf
->wol_en
);
10930 pci_set_power_state(pdev
, PCI_D3hot
);
10936 * i40e_resume - PCI callback for waking up from D3
10937 * @pdev: PCI device information struct
10939 static int i40e_resume(struct pci_dev
*pdev
)
10941 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10944 pci_set_power_state(pdev
, PCI_D0
);
10945 pci_restore_state(pdev
);
10946 /* pci_restore_state() clears dev->state_saves, so
10947 * call pci_save_state() again to restore it.
10949 pci_save_state(pdev
);
10951 err
= pci_enable_device_mem(pdev
);
10953 dev_err(&pdev
->dev
, "Cannot enable PCI device from suspend\n");
10956 pci_set_master(pdev
);
10958 /* no wakeup events while running */
10959 pci_wake_from_d3(pdev
, false);
10961 /* handling the reset will rebuild the device state */
10962 if (test_and_clear_bit(__I40E_SUSPENDED
, &pf
->state
)) {
10963 clear_bit(__I40E_DOWN
, &pf
->state
);
10965 i40e_reset_and_rebuild(pf
, false);
10973 static const struct pci_error_handlers i40e_err_handler
= {
10974 .error_detected
= i40e_pci_error_detected
,
10975 .slot_reset
= i40e_pci_error_slot_reset
,
10976 .resume
= i40e_pci_error_resume
,
10979 static struct pci_driver i40e_driver
= {
10980 .name
= i40e_driver_name
,
10981 .id_table
= i40e_pci_tbl
,
10982 .probe
= i40e_probe
,
10983 .remove
= i40e_remove
,
10985 .suspend
= i40e_suspend
,
10986 .resume
= i40e_resume
,
10988 .shutdown
= i40e_shutdown
,
10989 .err_handler
= &i40e_err_handler
,
10990 .sriov_configure
= i40e_pci_sriov_configure
,
10994 * i40e_init_module - Driver registration routine
10996 * i40e_init_module is the first routine called when the driver is
10997 * loaded. All it does is register with the PCI subsystem.
10999 static int __init
i40e_init_module(void)
11001 pr_info("%s: %s - version %s\n", i40e_driver_name
,
11002 i40e_driver_string
, i40e_driver_version_str
);
11003 pr_info("%s: %s\n", i40e_driver_name
, i40e_copyright
);
11006 return pci_register_driver(&i40e_driver
);
11008 module_init(i40e_init_module
);
11011 * i40e_exit_module - Driver exit cleanup routine
11013 * i40e_exit_module is called just before the driver is removed
11016 static void __exit
i40e_exit_module(void)
11018 pci_unregister_driver(&i40e_driver
);
11021 module_exit(i40e_exit_module
);