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 6
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_20G_KR2
), 0},
79 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_SFP_X722
), 0},
80 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_1G_BASE_T_X722
), 0},
81 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T_X722
), 0},
82 /* required last entry */
85 MODULE_DEVICE_TABLE(pci
, i40e_pci_tbl
);
87 #define I40E_MAX_VF_COUNT 128
88 static int debug
= -1;
89 module_param(debug
, int, 0);
90 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
92 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
93 MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
94 MODULE_LICENSE("GPL");
95 MODULE_VERSION(DRV_VERSION
);
98 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
99 * @hw: pointer to the HW structure
100 * @mem: ptr to mem struct to fill out
101 * @size: size of memory requested
102 * @alignment: what to align the allocation to
104 int i40e_allocate_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
,
105 u64 size
, u32 alignment
)
107 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
109 mem
->size
= ALIGN(size
, alignment
);
110 mem
->va
= dma_zalloc_coherent(&pf
->pdev
->dev
, mem
->size
,
111 &mem
->pa
, GFP_KERNEL
);
119 * i40e_free_dma_mem_d - OS specific memory free for shared code
120 * @hw: pointer to the HW structure
121 * @mem: ptr to mem struct to free
123 int i40e_free_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
)
125 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
127 dma_free_coherent(&pf
->pdev
->dev
, mem
->size
, mem
->va
, mem
->pa
);
136 * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
137 * @hw: pointer to the HW structure
138 * @mem: ptr to mem struct to fill out
139 * @size: size of memory requested
141 int i40e_allocate_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
,
145 mem
->va
= kzalloc(size
, GFP_KERNEL
);
154 * i40e_free_virt_mem_d - OS specific memory free for shared code
155 * @hw: pointer to the HW structure
156 * @mem: ptr to mem struct to free
158 int i40e_free_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
)
160 /* it's ok to kfree a NULL pointer */
169 * i40e_get_lump - find a lump of free generic resource
170 * @pf: board private structure
171 * @pile: the pile of resource to search
172 * @needed: the number of items needed
173 * @id: an owner id to stick on the items assigned
175 * Returns the base item index of the lump, or negative for error
177 * The search_hint trick and lack of advanced fit-finding only work
178 * because we're highly likely to have all the same size lump requests.
179 * Linear search time and any fragmentation should be minimal.
181 static int i40e_get_lump(struct i40e_pf
*pf
, struct i40e_lump_tracking
*pile
,
187 if (!pile
|| needed
== 0 || id
>= I40E_PILE_VALID_BIT
) {
188 dev_info(&pf
->pdev
->dev
,
189 "param err: pile=%p needed=%d id=0x%04x\n",
194 /* start the linear search with an imperfect hint */
195 i
= pile
->search_hint
;
196 while (i
< pile
->num_entries
) {
197 /* skip already allocated entries */
198 if (pile
->list
[i
] & I40E_PILE_VALID_BIT
) {
203 /* do we have enough in this lump? */
204 for (j
= 0; (j
< needed
) && ((i
+j
) < pile
->num_entries
); j
++) {
205 if (pile
->list
[i
+j
] & I40E_PILE_VALID_BIT
)
210 /* there was enough, so assign it to the requestor */
211 for (j
= 0; j
< needed
; j
++)
212 pile
->list
[i
+j
] = id
| I40E_PILE_VALID_BIT
;
214 pile
->search_hint
= i
+ j
;
217 /* not enough, so skip over it and continue looking */
226 * i40e_put_lump - return a lump of generic resource
227 * @pile: the pile of resource to search
228 * @index: the base item index
229 * @id: the owner id of the items assigned
231 * Returns the count of items in the lump
233 static int i40e_put_lump(struct i40e_lump_tracking
*pile
, u16 index
, u16 id
)
235 int valid_id
= (id
| I40E_PILE_VALID_BIT
);
239 if (!pile
|| index
>= pile
->num_entries
)
243 i
< pile
->num_entries
&& pile
->list
[i
] == valid_id
;
249 if (count
&& index
< pile
->search_hint
)
250 pile
->search_hint
= index
;
256 * i40e_find_vsi_from_id - searches for the vsi with the given id
257 * @pf - the pf structure to search for the vsi
258 * @id - id of the vsi it is searching for
260 struct i40e_vsi
*i40e_find_vsi_from_id(struct i40e_pf
*pf
, u16 id
)
264 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
265 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->id
== id
))
272 * i40e_service_event_schedule - Schedule the service task to wake up
273 * @pf: board private structure
275 * If not already scheduled, this puts the task into the work queue
277 static void i40e_service_event_schedule(struct i40e_pf
*pf
)
279 if (!test_bit(__I40E_DOWN
, &pf
->state
) &&
280 !test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) &&
281 !test_and_set_bit(__I40E_SERVICE_SCHED
, &pf
->state
))
282 schedule_work(&pf
->service_task
);
286 * i40e_tx_timeout - Respond to a Tx Hang
287 * @netdev: network interface device structure
289 * If any port has noticed a Tx timeout, it is likely that the whole
290 * device is munged, not just the one netdev port, so go for the full
294 void i40e_tx_timeout(struct net_device
*netdev
)
296 static void i40e_tx_timeout(struct net_device
*netdev
)
299 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
300 struct i40e_vsi
*vsi
= np
->vsi
;
301 struct i40e_pf
*pf
= vsi
->back
;
303 pf
->tx_timeout_count
++;
305 if (time_after(jiffies
, (pf
->tx_timeout_last_recovery
+ HZ
*20)))
306 pf
->tx_timeout_recovery_level
= 1;
307 pf
->tx_timeout_last_recovery
= jiffies
;
308 netdev_info(netdev
, "tx_timeout recovery level %d\n",
309 pf
->tx_timeout_recovery_level
);
311 switch (pf
->tx_timeout_recovery_level
) {
313 /* disable and re-enable queues for the VSI */
314 if (in_interrupt()) {
315 set_bit(__I40E_REINIT_REQUESTED
, &pf
->state
);
316 set_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
);
318 i40e_vsi_reinit_locked(vsi
);
322 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
325 set_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
);
328 set_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
);
331 netdev_err(netdev
, "tx_timeout recovery unsuccessful\n");
332 set_bit(__I40E_DOWN_REQUESTED
, &pf
->state
);
333 set_bit(__I40E_DOWN_REQUESTED
, &vsi
->state
);
336 i40e_service_event_schedule(pf
);
337 pf
->tx_timeout_recovery_level
++;
341 * i40e_release_rx_desc - Store the new tail and head values
342 * @rx_ring: ring to bump
343 * @val: new head index
345 static inline void i40e_release_rx_desc(struct i40e_ring
*rx_ring
, u32 val
)
347 rx_ring
->next_to_use
= val
;
349 /* Force memory writes to complete before letting h/w
350 * know there are new descriptors to fetch. (Only
351 * applicable for weak-ordered memory model archs,
355 writel(val
, rx_ring
->tail
);
359 * i40e_get_vsi_stats_struct - Get System Network Statistics
360 * @vsi: the VSI we care about
362 * Returns the address of the device statistics structure.
363 * The statistics are actually updated from the service task.
365 struct rtnl_link_stats64
*i40e_get_vsi_stats_struct(struct i40e_vsi
*vsi
)
367 return &vsi
->net_stats
;
371 * i40e_get_netdev_stats_struct - Get statistics for netdev interface
372 * @netdev: network interface device structure
374 * Returns the address of the device statistics structure.
375 * The statistics are actually updated from the service task.
378 struct rtnl_link_stats64
*i40e_get_netdev_stats_struct(
379 struct net_device
*netdev
,
380 struct rtnl_link_stats64
*stats
)
382 static struct rtnl_link_stats64
*i40e_get_netdev_stats_struct(
383 struct net_device
*netdev
,
384 struct rtnl_link_stats64
*stats
)
387 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
388 struct i40e_ring
*tx_ring
, *rx_ring
;
389 struct i40e_vsi
*vsi
= np
->vsi
;
390 struct rtnl_link_stats64
*vsi_stats
= i40e_get_vsi_stats_struct(vsi
);
393 if (test_bit(__I40E_DOWN
, &vsi
->state
))
400 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
404 tx_ring
= ACCESS_ONCE(vsi
->tx_rings
[i
]);
409 start
= u64_stats_fetch_begin_irq(&tx_ring
->syncp
);
410 packets
= tx_ring
->stats
.packets
;
411 bytes
= tx_ring
->stats
.bytes
;
412 } while (u64_stats_fetch_retry_irq(&tx_ring
->syncp
, start
));
414 stats
->tx_packets
+= packets
;
415 stats
->tx_bytes
+= bytes
;
416 rx_ring
= &tx_ring
[1];
419 start
= u64_stats_fetch_begin_irq(&rx_ring
->syncp
);
420 packets
= rx_ring
->stats
.packets
;
421 bytes
= rx_ring
->stats
.bytes
;
422 } while (u64_stats_fetch_retry_irq(&rx_ring
->syncp
, start
));
424 stats
->rx_packets
+= packets
;
425 stats
->rx_bytes
+= bytes
;
429 /* following stats updated by i40e_watchdog_subtask() */
430 stats
->multicast
= vsi_stats
->multicast
;
431 stats
->tx_errors
= vsi_stats
->tx_errors
;
432 stats
->tx_dropped
= vsi_stats
->tx_dropped
;
433 stats
->rx_errors
= vsi_stats
->rx_errors
;
434 stats
->rx_crc_errors
= vsi_stats
->rx_crc_errors
;
435 stats
->rx_length_errors
= vsi_stats
->rx_length_errors
;
441 * i40e_vsi_reset_stats - Resets all stats of the given vsi
442 * @vsi: the VSI to have its stats reset
444 void i40e_vsi_reset_stats(struct i40e_vsi
*vsi
)
446 struct rtnl_link_stats64
*ns
;
452 ns
= i40e_get_vsi_stats_struct(vsi
);
453 memset(ns
, 0, sizeof(*ns
));
454 memset(&vsi
->net_stats_offsets
, 0, sizeof(vsi
->net_stats_offsets
));
455 memset(&vsi
->eth_stats
, 0, sizeof(vsi
->eth_stats
));
456 memset(&vsi
->eth_stats_offsets
, 0, sizeof(vsi
->eth_stats_offsets
));
457 if (vsi
->rx_rings
&& vsi
->rx_rings
[0]) {
458 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
459 memset(&vsi
->rx_rings
[i
]->stats
, 0 ,
460 sizeof(vsi
->rx_rings
[i
]->stats
));
461 memset(&vsi
->rx_rings
[i
]->rx_stats
, 0 ,
462 sizeof(vsi
->rx_rings
[i
]->rx_stats
));
463 memset(&vsi
->tx_rings
[i
]->stats
, 0 ,
464 sizeof(vsi
->tx_rings
[i
]->stats
));
465 memset(&vsi
->tx_rings
[i
]->tx_stats
, 0,
466 sizeof(vsi
->tx_rings
[i
]->tx_stats
));
469 vsi
->stat_offsets_loaded
= false;
473 * i40e_pf_reset_stats - Reset all of the stats for the given PF
474 * @pf: the PF to be reset
476 void i40e_pf_reset_stats(struct i40e_pf
*pf
)
480 memset(&pf
->stats
, 0, sizeof(pf
->stats
));
481 memset(&pf
->stats_offsets
, 0, sizeof(pf
->stats_offsets
));
482 pf
->stat_offsets_loaded
= false;
484 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
486 memset(&pf
->veb
[i
]->stats
, 0,
487 sizeof(pf
->veb
[i
]->stats
));
488 memset(&pf
->veb
[i
]->stats_offsets
, 0,
489 sizeof(pf
->veb
[i
]->stats_offsets
));
490 pf
->veb
[i
]->stat_offsets_loaded
= false;
496 * i40e_stat_update48 - read and update a 48 bit stat from the chip
497 * @hw: ptr to the hardware info
498 * @hireg: the high 32 bit reg to read
499 * @loreg: the low 32 bit reg to read
500 * @offset_loaded: has the initial offset been loaded yet
501 * @offset: ptr to current offset value
502 * @stat: ptr to the stat
504 * Since the device stats are not reset at PFReset, they likely will not
505 * be zeroed when the driver starts. We'll save the first values read
506 * and use them as offsets to be subtracted from the raw values in order
507 * to report stats that count from zero. In the process, we also manage
508 * the potential roll-over.
510 static void i40e_stat_update48(struct i40e_hw
*hw
, u32 hireg
, u32 loreg
,
511 bool offset_loaded
, u64
*offset
, u64
*stat
)
515 if (hw
->device_id
== I40E_DEV_ID_QEMU
) {
516 new_data
= rd32(hw
, loreg
);
517 new_data
|= ((u64
)(rd32(hw
, hireg
) & 0xFFFF)) << 32;
519 new_data
= rd64(hw
, loreg
);
523 if (likely(new_data
>= *offset
))
524 *stat
= new_data
- *offset
;
526 *stat
= (new_data
+ BIT_ULL(48)) - *offset
;
527 *stat
&= 0xFFFFFFFFFFFFULL
;
531 * i40e_stat_update32 - read and update a 32 bit stat from the chip
532 * @hw: ptr to the hardware info
533 * @reg: the hw reg to read
534 * @offset_loaded: has the initial offset been loaded yet
535 * @offset: ptr to current offset value
536 * @stat: ptr to the stat
538 static void i40e_stat_update32(struct i40e_hw
*hw
, u32 reg
,
539 bool offset_loaded
, u64
*offset
, u64
*stat
)
543 new_data
= rd32(hw
, reg
);
546 if (likely(new_data
>= *offset
))
547 *stat
= (u32
)(new_data
- *offset
);
549 *stat
= (u32
)((new_data
+ BIT_ULL(32)) - *offset
);
553 * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
554 * @vsi: the VSI to be updated
556 void i40e_update_eth_stats(struct i40e_vsi
*vsi
)
558 int stat_idx
= le16_to_cpu(vsi
->info
.stat_counter_idx
);
559 struct i40e_pf
*pf
= vsi
->back
;
560 struct i40e_hw
*hw
= &pf
->hw
;
561 struct i40e_eth_stats
*oes
;
562 struct i40e_eth_stats
*es
; /* device's eth stats */
564 es
= &vsi
->eth_stats
;
565 oes
= &vsi
->eth_stats_offsets
;
567 /* Gather up the stats that the hw collects */
568 i40e_stat_update32(hw
, I40E_GLV_TEPC(stat_idx
),
569 vsi
->stat_offsets_loaded
,
570 &oes
->tx_errors
, &es
->tx_errors
);
571 i40e_stat_update32(hw
, I40E_GLV_RDPC(stat_idx
),
572 vsi
->stat_offsets_loaded
,
573 &oes
->rx_discards
, &es
->rx_discards
);
574 i40e_stat_update32(hw
, I40E_GLV_RUPP(stat_idx
),
575 vsi
->stat_offsets_loaded
,
576 &oes
->rx_unknown_protocol
, &es
->rx_unknown_protocol
);
577 i40e_stat_update32(hw
, I40E_GLV_TEPC(stat_idx
),
578 vsi
->stat_offsets_loaded
,
579 &oes
->tx_errors
, &es
->tx_errors
);
581 i40e_stat_update48(hw
, I40E_GLV_GORCH(stat_idx
),
582 I40E_GLV_GORCL(stat_idx
),
583 vsi
->stat_offsets_loaded
,
584 &oes
->rx_bytes
, &es
->rx_bytes
);
585 i40e_stat_update48(hw
, I40E_GLV_UPRCH(stat_idx
),
586 I40E_GLV_UPRCL(stat_idx
),
587 vsi
->stat_offsets_loaded
,
588 &oes
->rx_unicast
, &es
->rx_unicast
);
589 i40e_stat_update48(hw
, I40E_GLV_MPRCH(stat_idx
),
590 I40E_GLV_MPRCL(stat_idx
),
591 vsi
->stat_offsets_loaded
,
592 &oes
->rx_multicast
, &es
->rx_multicast
);
593 i40e_stat_update48(hw
, I40E_GLV_BPRCH(stat_idx
),
594 I40E_GLV_BPRCL(stat_idx
),
595 vsi
->stat_offsets_loaded
,
596 &oes
->rx_broadcast
, &es
->rx_broadcast
);
598 i40e_stat_update48(hw
, I40E_GLV_GOTCH(stat_idx
),
599 I40E_GLV_GOTCL(stat_idx
),
600 vsi
->stat_offsets_loaded
,
601 &oes
->tx_bytes
, &es
->tx_bytes
);
602 i40e_stat_update48(hw
, I40E_GLV_UPTCH(stat_idx
),
603 I40E_GLV_UPTCL(stat_idx
),
604 vsi
->stat_offsets_loaded
,
605 &oes
->tx_unicast
, &es
->tx_unicast
);
606 i40e_stat_update48(hw
, I40E_GLV_MPTCH(stat_idx
),
607 I40E_GLV_MPTCL(stat_idx
),
608 vsi
->stat_offsets_loaded
,
609 &oes
->tx_multicast
, &es
->tx_multicast
);
610 i40e_stat_update48(hw
, I40E_GLV_BPTCH(stat_idx
),
611 I40E_GLV_BPTCL(stat_idx
),
612 vsi
->stat_offsets_loaded
,
613 &oes
->tx_broadcast
, &es
->tx_broadcast
);
614 vsi
->stat_offsets_loaded
= true;
618 * i40e_update_veb_stats - Update Switch component statistics
619 * @veb: the VEB being updated
621 static void i40e_update_veb_stats(struct i40e_veb
*veb
)
623 struct i40e_pf
*pf
= veb
->pf
;
624 struct i40e_hw
*hw
= &pf
->hw
;
625 struct i40e_eth_stats
*oes
;
626 struct i40e_eth_stats
*es
; /* device's eth stats */
629 idx
= veb
->stats_idx
;
631 oes
= &veb
->stats_offsets
;
633 /* Gather up the stats that the hw collects */
634 i40e_stat_update32(hw
, I40E_GLSW_TDPC(idx
),
635 veb
->stat_offsets_loaded
,
636 &oes
->tx_discards
, &es
->tx_discards
);
637 if (hw
->revision_id
> 0)
638 i40e_stat_update32(hw
, I40E_GLSW_RUPP(idx
),
639 veb
->stat_offsets_loaded
,
640 &oes
->rx_unknown_protocol
,
641 &es
->rx_unknown_protocol
);
642 i40e_stat_update48(hw
, I40E_GLSW_GORCH(idx
), I40E_GLSW_GORCL(idx
),
643 veb
->stat_offsets_loaded
,
644 &oes
->rx_bytes
, &es
->rx_bytes
);
645 i40e_stat_update48(hw
, I40E_GLSW_UPRCH(idx
), I40E_GLSW_UPRCL(idx
),
646 veb
->stat_offsets_loaded
,
647 &oes
->rx_unicast
, &es
->rx_unicast
);
648 i40e_stat_update48(hw
, I40E_GLSW_MPRCH(idx
), I40E_GLSW_MPRCL(idx
),
649 veb
->stat_offsets_loaded
,
650 &oes
->rx_multicast
, &es
->rx_multicast
);
651 i40e_stat_update48(hw
, I40E_GLSW_BPRCH(idx
), I40E_GLSW_BPRCL(idx
),
652 veb
->stat_offsets_loaded
,
653 &oes
->rx_broadcast
, &es
->rx_broadcast
);
655 i40e_stat_update48(hw
, I40E_GLSW_GOTCH(idx
), I40E_GLSW_GOTCL(idx
),
656 veb
->stat_offsets_loaded
,
657 &oes
->tx_bytes
, &es
->tx_bytes
);
658 i40e_stat_update48(hw
, I40E_GLSW_UPTCH(idx
), I40E_GLSW_UPTCL(idx
),
659 veb
->stat_offsets_loaded
,
660 &oes
->tx_unicast
, &es
->tx_unicast
);
661 i40e_stat_update48(hw
, I40E_GLSW_MPTCH(idx
), I40E_GLSW_MPTCL(idx
),
662 veb
->stat_offsets_loaded
,
663 &oes
->tx_multicast
, &es
->tx_multicast
);
664 i40e_stat_update48(hw
, I40E_GLSW_BPTCH(idx
), I40E_GLSW_BPTCL(idx
),
665 veb
->stat_offsets_loaded
,
666 &oes
->tx_broadcast
, &es
->tx_broadcast
);
667 veb
->stat_offsets_loaded
= true;
672 * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters.
673 * @vsi: the VSI that is capable of doing FCoE
675 static void i40e_update_fcoe_stats(struct i40e_vsi
*vsi
)
677 struct i40e_pf
*pf
= vsi
->back
;
678 struct i40e_hw
*hw
= &pf
->hw
;
679 struct i40e_fcoe_stats
*ofs
;
680 struct i40e_fcoe_stats
*fs
; /* device's eth stats */
683 if (vsi
->type
!= I40E_VSI_FCOE
)
686 idx
= (pf
->pf_seid
- I40E_BASE_PF_SEID
) + I40E_FCOE_PF_STAT_OFFSET
;
687 fs
= &vsi
->fcoe_stats
;
688 ofs
= &vsi
->fcoe_stats_offsets
;
690 i40e_stat_update32(hw
, I40E_GL_FCOEPRC(idx
),
691 vsi
->fcoe_stat_offsets_loaded
,
692 &ofs
->rx_fcoe_packets
, &fs
->rx_fcoe_packets
);
693 i40e_stat_update48(hw
, I40E_GL_FCOEDWRCH(idx
), I40E_GL_FCOEDWRCL(idx
),
694 vsi
->fcoe_stat_offsets_loaded
,
695 &ofs
->rx_fcoe_dwords
, &fs
->rx_fcoe_dwords
);
696 i40e_stat_update32(hw
, I40E_GL_FCOERPDC(idx
),
697 vsi
->fcoe_stat_offsets_loaded
,
698 &ofs
->rx_fcoe_dropped
, &fs
->rx_fcoe_dropped
);
699 i40e_stat_update32(hw
, I40E_GL_FCOEPTC(idx
),
700 vsi
->fcoe_stat_offsets_loaded
,
701 &ofs
->tx_fcoe_packets
, &fs
->tx_fcoe_packets
);
702 i40e_stat_update48(hw
, I40E_GL_FCOEDWTCH(idx
), I40E_GL_FCOEDWTCL(idx
),
703 vsi
->fcoe_stat_offsets_loaded
,
704 &ofs
->tx_fcoe_dwords
, &fs
->tx_fcoe_dwords
);
705 i40e_stat_update32(hw
, I40E_GL_FCOECRC(idx
),
706 vsi
->fcoe_stat_offsets_loaded
,
707 &ofs
->fcoe_bad_fccrc
, &fs
->fcoe_bad_fccrc
);
708 i40e_stat_update32(hw
, I40E_GL_FCOELAST(idx
),
709 vsi
->fcoe_stat_offsets_loaded
,
710 &ofs
->fcoe_last_error
, &fs
->fcoe_last_error
);
711 i40e_stat_update32(hw
, I40E_GL_FCOEDDPC(idx
),
712 vsi
->fcoe_stat_offsets_loaded
,
713 &ofs
->fcoe_ddp_count
, &fs
->fcoe_ddp_count
);
715 vsi
->fcoe_stat_offsets_loaded
= true;
720 * i40e_update_link_xoff_rx - Update XOFF received in link flow control mode
721 * @pf: the corresponding PF
723 * Update the Rx XOFF counter (PAUSE frames) in link flow control mode
725 static void i40e_update_link_xoff_rx(struct i40e_pf
*pf
)
727 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
728 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
729 struct i40e_hw
*hw
= &pf
->hw
;
733 if ((hw
->fc
.current_mode
!= I40E_FC_FULL
) &&
734 (hw
->fc
.current_mode
!= I40E_FC_RX_PAUSE
))
737 xoff
= nsd
->link_xoff_rx
;
738 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFRXC(hw
->port
),
739 pf
->stat_offsets_loaded
,
740 &osd
->link_xoff_rx
, &nsd
->link_xoff_rx
);
742 /* No new LFC xoff rx */
743 if (!(nsd
->link_xoff_rx
- xoff
))
746 /* Clear the __I40E_HANG_CHECK_ARMED bit for all Tx rings */
747 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
748 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
750 if (!vsi
|| !vsi
->tx_rings
[0])
753 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
754 struct i40e_ring
*ring
= vsi
->tx_rings
[i
];
755 clear_bit(__I40E_HANG_CHECK_ARMED
, &ring
->state
);
761 * i40e_update_prio_xoff_rx - Update XOFF received in PFC mode
762 * @pf: the corresponding PF
764 * Update the Rx XOFF counter (PAUSE frames) in PFC mode
766 static void i40e_update_prio_xoff_rx(struct i40e_pf
*pf
)
768 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
769 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
770 bool xoff
[I40E_MAX_TRAFFIC_CLASS
] = {false};
771 struct i40e_dcbx_config
*dcb_cfg
;
772 struct i40e_hw
*hw
= &pf
->hw
;
776 dcb_cfg
= &hw
->local_dcbx_config
;
778 /* Collect Link XOFF stats when PFC is disabled */
779 if (!dcb_cfg
->pfc
.pfcenable
) {
780 i40e_update_link_xoff_rx(pf
);
784 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
785 u64 prio_xoff
= nsd
->priority_xoff_rx
[i
];
786 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFRXC(hw
->port
, i
),
787 pf
->stat_offsets_loaded
,
788 &osd
->priority_xoff_rx
[i
],
789 &nsd
->priority_xoff_rx
[i
]);
791 /* No new PFC xoff rx */
792 if (!(nsd
->priority_xoff_rx
[i
] - prio_xoff
))
794 /* Get the TC for given priority */
795 tc
= dcb_cfg
->etscfg
.prioritytable
[i
];
799 /* Clear the __I40E_HANG_CHECK_ARMED bit for Tx rings */
800 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
801 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
803 if (!vsi
|| !vsi
->tx_rings
[0])
806 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
807 struct i40e_ring
*ring
= vsi
->tx_rings
[i
];
811 clear_bit(__I40E_HANG_CHECK_ARMED
,
818 * i40e_update_vsi_stats - Update the vsi statistics counters.
819 * @vsi: the VSI to be updated
821 * There are a few instances where we store the same stat in a
822 * couple of different structs. This is partly because we have
823 * the netdev stats that need to be filled out, which is slightly
824 * different from the "eth_stats" defined by the chip and used in
825 * VF communications. We sort it out here.
827 static void i40e_update_vsi_stats(struct i40e_vsi
*vsi
)
829 struct i40e_pf
*pf
= vsi
->back
;
830 struct rtnl_link_stats64
*ons
;
831 struct rtnl_link_stats64
*ns
; /* netdev stats */
832 struct i40e_eth_stats
*oes
;
833 struct i40e_eth_stats
*es
; /* device's eth stats */
834 u32 tx_restart
, tx_busy
;
843 if (test_bit(__I40E_DOWN
, &vsi
->state
) ||
844 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
847 ns
= i40e_get_vsi_stats_struct(vsi
);
848 ons
= &vsi
->net_stats_offsets
;
849 es
= &vsi
->eth_stats
;
850 oes
= &vsi
->eth_stats_offsets
;
852 /* Gather up the netdev and vsi stats that the driver collects
853 * on the fly during packet processing
857 tx_restart
= tx_busy
= 0;
861 for (q
= 0; q
< vsi
->num_queue_pairs
; q
++) {
863 p
= ACCESS_ONCE(vsi
->tx_rings
[q
]);
866 start
= u64_stats_fetch_begin_irq(&p
->syncp
);
867 packets
= p
->stats
.packets
;
868 bytes
= p
->stats
.bytes
;
869 } while (u64_stats_fetch_retry_irq(&p
->syncp
, start
));
872 tx_restart
+= p
->tx_stats
.restart_queue
;
873 tx_busy
+= p
->tx_stats
.tx_busy
;
875 /* Rx queue is part of the same block as Tx queue */
878 start
= u64_stats_fetch_begin_irq(&p
->syncp
);
879 packets
= p
->stats
.packets
;
880 bytes
= p
->stats
.bytes
;
881 } while (u64_stats_fetch_retry_irq(&p
->syncp
, start
));
884 rx_buf
+= p
->rx_stats
.alloc_buff_failed
;
885 rx_page
+= p
->rx_stats
.alloc_page_failed
;
888 vsi
->tx_restart
= tx_restart
;
889 vsi
->tx_busy
= tx_busy
;
890 vsi
->rx_page_failed
= rx_page
;
891 vsi
->rx_buf_failed
= rx_buf
;
893 ns
->rx_packets
= rx_p
;
895 ns
->tx_packets
= tx_p
;
898 /* update netdev stats from eth stats */
899 i40e_update_eth_stats(vsi
);
900 ons
->tx_errors
= oes
->tx_errors
;
901 ns
->tx_errors
= es
->tx_errors
;
902 ons
->multicast
= oes
->rx_multicast
;
903 ns
->multicast
= es
->rx_multicast
;
904 ons
->rx_dropped
= oes
->rx_discards
;
905 ns
->rx_dropped
= es
->rx_discards
;
906 ons
->tx_dropped
= oes
->tx_discards
;
907 ns
->tx_dropped
= es
->tx_discards
;
909 /* pull in a couple PF stats if this is the main vsi */
910 if (vsi
== pf
->vsi
[pf
->lan_vsi
]) {
911 ns
->rx_crc_errors
= pf
->stats
.crc_errors
;
912 ns
->rx_errors
= pf
->stats
.crc_errors
+ pf
->stats
.illegal_bytes
;
913 ns
->rx_length_errors
= pf
->stats
.rx_length_errors
;
918 * i40e_update_pf_stats - Update the PF statistics counters.
919 * @pf: the PF to be updated
921 static void i40e_update_pf_stats(struct i40e_pf
*pf
)
923 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
924 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
925 struct i40e_hw
*hw
= &pf
->hw
;
929 i40e_stat_update48(hw
, I40E_GLPRT_GORCH(hw
->port
),
930 I40E_GLPRT_GORCL(hw
->port
),
931 pf
->stat_offsets_loaded
,
932 &osd
->eth
.rx_bytes
, &nsd
->eth
.rx_bytes
);
933 i40e_stat_update48(hw
, I40E_GLPRT_GOTCH(hw
->port
),
934 I40E_GLPRT_GOTCL(hw
->port
),
935 pf
->stat_offsets_loaded
,
936 &osd
->eth
.tx_bytes
, &nsd
->eth
.tx_bytes
);
937 i40e_stat_update32(hw
, I40E_GLPRT_RDPC(hw
->port
),
938 pf
->stat_offsets_loaded
,
939 &osd
->eth
.rx_discards
,
940 &nsd
->eth
.rx_discards
);
941 i40e_stat_update48(hw
, I40E_GLPRT_UPRCH(hw
->port
),
942 I40E_GLPRT_UPRCL(hw
->port
),
943 pf
->stat_offsets_loaded
,
944 &osd
->eth
.rx_unicast
,
945 &nsd
->eth
.rx_unicast
);
946 i40e_stat_update48(hw
, I40E_GLPRT_MPRCH(hw
->port
),
947 I40E_GLPRT_MPRCL(hw
->port
),
948 pf
->stat_offsets_loaded
,
949 &osd
->eth
.rx_multicast
,
950 &nsd
->eth
.rx_multicast
);
951 i40e_stat_update48(hw
, I40E_GLPRT_BPRCH(hw
->port
),
952 I40E_GLPRT_BPRCL(hw
->port
),
953 pf
->stat_offsets_loaded
,
954 &osd
->eth
.rx_broadcast
,
955 &nsd
->eth
.rx_broadcast
);
956 i40e_stat_update48(hw
, I40E_GLPRT_UPTCH(hw
->port
),
957 I40E_GLPRT_UPTCL(hw
->port
),
958 pf
->stat_offsets_loaded
,
959 &osd
->eth
.tx_unicast
,
960 &nsd
->eth
.tx_unicast
);
961 i40e_stat_update48(hw
, I40E_GLPRT_MPTCH(hw
->port
),
962 I40E_GLPRT_MPTCL(hw
->port
),
963 pf
->stat_offsets_loaded
,
964 &osd
->eth
.tx_multicast
,
965 &nsd
->eth
.tx_multicast
);
966 i40e_stat_update48(hw
, I40E_GLPRT_BPTCH(hw
->port
),
967 I40E_GLPRT_BPTCL(hw
->port
),
968 pf
->stat_offsets_loaded
,
969 &osd
->eth
.tx_broadcast
,
970 &nsd
->eth
.tx_broadcast
);
972 i40e_stat_update32(hw
, I40E_GLPRT_TDOLD(hw
->port
),
973 pf
->stat_offsets_loaded
,
974 &osd
->tx_dropped_link_down
,
975 &nsd
->tx_dropped_link_down
);
977 i40e_stat_update32(hw
, I40E_GLPRT_CRCERRS(hw
->port
),
978 pf
->stat_offsets_loaded
,
979 &osd
->crc_errors
, &nsd
->crc_errors
);
981 i40e_stat_update32(hw
, I40E_GLPRT_ILLERRC(hw
->port
),
982 pf
->stat_offsets_loaded
,
983 &osd
->illegal_bytes
, &nsd
->illegal_bytes
);
985 i40e_stat_update32(hw
, I40E_GLPRT_MLFC(hw
->port
),
986 pf
->stat_offsets_loaded
,
987 &osd
->mac_local_faults
,
988 &nsd
->mac_local_faults
);
989 i40e_stat_update32(hw
, I40E_GLPRT_MRFC(hw
->port
),
990 pf
->stat_offsets_loaded
,
991 &osd
->mac_remote_faults
,
992 &nsd
->mac_remote_faults
);
994 i40e_stat_update32(hw
, I40E_GLPRT_RLEC(hw
->port
),
995 pf
->stat_offsets_loaded
,
996 &osd
->rx_length_errors
,
997 &nsd
->rx_length_errors
);
999 i40e_stat_update32(hw
, I40E_GLPRT_LXONRXC(hw
->port
),
1000 pf
->stat_offsets_loaded
,
1001 &osd
->link_xon_rx
, &nsd
->link_xon_rx
);
1002 i40e_stat_update32(hw
, I40E_GLPRT_LXONTXC(hw
->port
),
1003 pf
->stat_offsets_loaded
,
1004 &osd
->link_xon_tx
, &nsd
->link_xon_tx
);
1005 i40e_update_prio_xoff_rx(pf
); /* handles I40E_GLPRT_LXOFFRXC */
1006 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFTXC(hw
->port
),
1007 pf
->stat_offsets_loaded
,
1008 &osd
->link_xoff_tx
, &nsd
->link_xoff_tx
);
1010 for (i
= 0; i
< 8; i
++) {
1011 i40e_stat_update32(hw
, I40E_GLPRT_PXONRXC(hw
->port
, i
),
1012 pf
->stat_offsets_loaded
,
1013 &osd
->priority_xon_rx
[i
],
1014 &nsd
->priority_xon_rx
[i
]);
1015 i40e_stat_update32(hw
, I40E_GLPRT_PXONTXC(hw
->port
, i
),
1016 pf
->stat_offsets_loaded
,
1017 &osd
->priority_xon_tx
[i
],
1018 &nsd
->priority_xon_tx
[i
]);
1019 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFTXC(hw
->port
, i
),
1020 pf
->stat_offsets_loaded
,
1021 &osd
->priority_xoff_tx
[i
],
1022 &nsd
->priority_xoff_tx
[i
]);
1023 i40e_stat_update32(hw
,
1024 I40E_GLPRT_RXON2OFFCNT(hw
->port
, i
),
1025 pf
->stat_offsets_loaded
,
1026 &osd
->priority_xon_2_xoff
[i
],
1027 &nsd
->priority_xon_2_xoff
[i
]);
1030 i40e_stat_update48(hw
, I40E_GLPRT_PRC64H(hw
->port
),
1031 I40E_GLPRT_PRC64L(hw
->port
),
1032 pf
->stat_offsets_loaded
,
1033 &osd
->rx_size_64
, &nsd
->rx_size_64
);
1034 i40e_stat_update48(hw
, I40E_GLPRT_PRC127H(hw
->port
),
1035 I40E_GLPRT_PRC127L(hw
->port
),
1036 pf
->stat_offsets_loaded
,
1037 &osd
->rx_size_127
, &nsd
->rx_size_127
);
1038 i40e_stat_update48(hw
, I40E_GLPRT_PRC255H(hw
->port
),
1039 I40E_GLPRT_PRC255L(hw
->port
),
1040 pf
->stat_offsets_loaded
,
1041 &osd
->rx_size_255
, &nsd
->rx_size_255
);
1042 i40e_stat_update48(hw
, I40E_GLPRT_PRC511H(hw
->port
),
1043 I40E_GLPRT_PRC511L(hw
->port
),
1044 pf
->stat_offsets_loaded
,
1045 &osd
->rx_size_511
, &nsd
->rx_size_511
);
1046 i40e_stat_update48(hw
, I40E_GLPRT_PRC1023H(hw
->port
),
1047 I40E_GLPRT_PRC1023L(hw
->port
),
1048 pf
->stat_offsets_loaded
,
1049 &osd
->rx_size_1023
, &nsd
->rx_size_1023
);
1050 i40e_stat_update48(hw
, I40E_GLPRT_PRC1522H(hw
->port
),
1051 I40E_GLPRT_PRC1522L(hw
->port
),
1052 pf
->stat_offsets_loaded
,
1053 &osd
->rx_size_1522
, &nsd
->rx_size_1522
);
1054 i40e_stat_update48(hw
, I40E_GLPRT_PRC9522H(hw
->port
),
1055 I40E_GLPRT_PRC9522L(hw
->port
),
1056 pf
->stat_offsets_loaded
,
1057 &osd
->rx_size_big
, &nsd
->rx_size_big
);
1059 i40e_stat_update48(hw
, I40E_GLPRT_PTC64H(hw
->port
),
1060 I40E_GLPRT_PTC64L(hw
->port
),
1061 pf
->stat_offsets_loaded
,
1062 &osd
->tx_size_64
, &nsd
->tx_size_64
);
1063 i40e_stat_update48(hw
, I40E_GLPRT_PTC127H(hw
->port
),
1064 I40E_GLPRT_PTC127L(hw
->port
),
1065 pf
->stat_offsets_loaded
,
1066 &osd
->tx_size_127
, &nsd
->tx_size_127
);
1067 i40e_stat_update48(hw
, I40E_GLPRT_PTC255H(hw
->port
),
1068 I40E_GLPRT_PTC255L(hw
->port
),
1069 pf
->stat_offsets_loaded
,
1070 &osd
->tx_size_255
, &nsd
->tx_size_255
);
1071 i40e_stat_update48(hw
, I40E_GLPRT_PTC511H(hw
->port
),
1072 I40E_GLPRT_PTC511L(hw
->port
),
1073 pf
->stat_offsets_loaded
,
1074 &osd
->tx_size_511
, &nsd
->tx_size_511
);
1075 i40e_stat_update48(hw
, I40E_GLPRT_PTC1023H(hw
->port
),
1076 I40E_GLPRT_PTC1023L(hw
->port
),
1077 pf
->stat_offsets_loaded
,
1078 &osd
->tx_size_1023
, &nsd
->tx_size_1023
);
1079 i40e_stat_update48(hw
, I40E_GLPRT_PTC1522H(hw
->port
),
1080 I40E_GLPRT_PTC1522L(hw
->port
),
1081 pf
->stat_offsets_loaded
,
1082 &osd
->tx_size_1522
, &nsd
->tx_size_1522
);
1083 i40e_stat_update48(hw
, I40E_GLPRT_PTC9522H(hw
->port
),
1084 I40E_GLPRT_PTC9522L(hw
->port
),
1085 pf
->stat_offsets_loaded
,
1086 &osd
->tx_size_big
, &nsd
->tx_size_big
);
1088 i40e_stat_update32(hw
, I40E_GLPRT_RUC(hw
->port
),
1089 pf
->stat_offsets_loaded
,
1090 &osd
->rx_undersize
, &nsd
->rx_undersize
);
1091 i40e_stat_update32(hw
, I40E_GLPRT_RFC(hw
->port
),
1092 pf
->stat_offsets_loaded
,
1093 &osd
->rx_fragments
, &nsd
->rx_fragments
);
1094 i40e_stat_update32(hw
, I40E_GLPRT_ROC(hw
->port
),
1095 pf
->stat_offsets_loaded
,
1096 &osd
->rx_oversize
, &nsd
->rx_oversize
);
1097 i40e_stat_update32(hw
, I40E_GLPRT_RJC(hw
->port
),
1098 pf
->stat_offsets_loaded
,
1099 &osd
->rx_jabber
, &nsd
->rx_jabber
);
1102 i40e_stat_update32(hw
,
1103 I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf
->hw
.pf_id
)),
1104 pf
->stat_offsets_loaded
,
1105 &osd
->fd_atr_match
, &nsd
->fd_atr_match
);
1106 i40e_stat_update32(hw
,
1107 I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf
->hw
.pf_id
)),
1108 pf
->stat_offsets_loaded
,
1109 &osd
->fd_sb_match
, &nsd
->fd_sb_match
);
1110 i40e_stat_update32(hw
,
1111 I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf
->hw
.pf_id
)),
1112 pf
->stat_offsets_loaded
,
1113 &osd
->fd_atr_tunnel_match
, &nsd
->fd_atr_tunnel_match
);
1115 val
= rd32(hw
, I40E_PRTPM_EEE_STAT
);
1116 nsd
->tx_lpi_status
=
1117 (val
& I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK
) >>
1118 I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT
;
1119 nsd
->rx_lpi_status
=
1120 (val
& I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK
) >>
1121 I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT
;
1122 i40e_stat_update32(hw
, I40E_PRTPM_TLPIC
,
1123 pf
->stat_offsets_loaded
,
1124 &osd
->tx_lpi_count
, &nsd
->tx_lpi_count
);
1125 i40e_stat_update32(hw
, I40E_PRTPM_RLPIC
,
1126 pf
->stat_offsets_loaded
,
1127 &osd
->rx_lpi_count
, &nsd
->rx_lpi_count
);
1129 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
&&
1130 !(pf
->auto_disable_flags
& I40E_FLAG_FD_SB_ENABLED
))
1131 nsd
->fd_sb_status
= true;
1133 nsd
->fd_sb_status
= false;
1135 if (pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
&&
1136 !(pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
))
1137 nsd
->fd_atr_status
= true;
1139 nsd
->fd_atr_status
= false;
1141 pf
->stat_offsets_loaded
= true;
1145 * i40e_update_stats - Update the various statistics counters.
1146 * @vsi: the VSI to be updated
1148 * Update the various stats for this VSI and its related entities.
1150 void i40e_update_stats(struct i40e_vsi
*vsi
)
1152 struct i40e_pf
*pf
= vsi
->back
;
1154 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
1155 i40e_update_pf_stats(pf
);
1157 i40e_update_vsi_stats(vsi
);
1159 i40e_update_fcoe_stats(vsi
);
1164 * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
1165 * @vsi: the VSI to be searched
1166 * @macaddr: the MAC address
1168 * @is_vf: make sure its a VF filter, else doesn't matter
1169 * @is_netdev: make sure its a netdev filter, else doesn't matter
1171 * Returns ptr to the filter object or NULL
1173 static struct i40e_mac_filter
*i40e_find_filter(struct i40e_vsi
*vsi
,
1174 u8
*macaddr
, s16 vlan
,
1175 bool is_vf
, bool is_netdev
)
1177 struct i40e_mac_filter
*f
;
1179 if (!vsi
|| !macaddr
)
1182 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1183 if ((ether_addr_equal(macaddr
, f
->macaddr
)) &&
1184 (vlan
== f
->vlan
) &&
1185 (!is_vf
|| f
->is_vf
) &&
1186 (!is_netdev
|| f
->is_netdev
))
1193 * i40e_find_mac - Find a mac addr in the macvlan filters list
1194 * @vsi: the VSI to be searched
1195 * @macaddr: the MAC address we are searching for
1196 * @is_vf: make sure its a VF filter, else doesn't matter
1197 * @is_netdev: make sure its a netdev filter, else doesn't matter
1199 * Returns the first filter with the provided MAC address or NULL if
1200 * MAC address was not found
1202 struct i40e_mac_filter
*i40e_find_mac(struct i40e_vsi
*vsi
, u8
*macaddr
,
1203 bool is_vf
, bool is_netdev
)
1205 struct i40e_mac_filter
*f
;
1207 if (!vsi
|| !macaddr
)
1210 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1211 if ((ether_addr_equal(macaddr
, f
->macaddr
)) &&
1212 (!is_vf
|| f
->is_vf
) &&
1213 (!is_netdev
|| f
->is_netdev
))
1220 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1221 * @vsi: the VSI to be searched
1223 * Returns true if VSI is in vlan mode or false otherwise
1225 bool i40e_is_vsi_in_vlan(struct i40e_vsi
*vsi
)
1227 struct i40e_mac_filter
*f
;
1229 /* Only -1 for all the filters denotes not in vlan mode
1230 * so we have to go through all the list in order to make sure
1232 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1241 * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
1242 * @vsi: the VSI to be searched
1243 * @macaddr: the mac address to be filtered
1244 * @is_vf: true if it is a VF
1245 * @is_netdev: true if it is a netdev
1247 * Goes through all the macvlan filters and adds a
1248 * macvlan filter for each unique vlan that already exists
1250 * Returns first filter found on success, else NULL
1252 struct i40e_mac_filter
*i40e_put_mac_in_vlan(struct i40e_vsi
*vsi
, u8
*macaddr
,
1253 bool is_vf
, bool is_netdev
)
1255 struct i40e_mac_filter
*f
;
1257 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1258 if (!i40e_find_filter(vsi
, macaddr
, f
->vlan
,
1259 is_vf
, is_netdev
)) {
1260 if (!i40e_add_filter(vsi
, macaddr
, f
->vlan
,
1266 return list_first_entry_or_null(&vsi
->mac_filter_list
,
1267 struct i40e_mac_filter
, list
);
1271 * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
1272 * @vsi: the PF Main VSI - inappropriate for any other VSI
1273 * @macaddr: the MAC address
1275 * Some older firmware configurations set up a default promiscuous VLAN
1276 * filter that needs to be removed.
1278 static int i40e_rm_default_mac_filter(struct i40e_vsi
*vsi
, u8
*macaddr
)
1280 struct i40e_aqc_remove_macvlan_element_data element
;
1281 struct i40e_pf
*pf
= vsi
->back
;
1284 /* Only appropriate for the PF main VSI */
1285 if (vsi
->type
!= I40E_VSI_MAIN
)
1288 memset(&element
, 0, sizeof(element
));
1289 ether_addr_copy(element
.mac_addr
, macaddr
);
1290 element
.vlan_tag
= 0;
1291 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
|
1292 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
1293 ret
= i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1301 * i40e_add_filter - Add a mac/vlan filter to the VSI
1302 * @vsi: the VSI to be searched
1303 * @macaddr: the MAC address
1305 * @is_vf: make sure its a VF filter, else doesn't matter
1306 * @is_netdev: make sure its a netdev filter, else doesn't matter
1308 * Returns ptr to the filter object or NULL when no memory available.
1310 struct i40e_mac_filter
*i40e_add_filter(struct i40e_vsi
*vsi
,
1311 u8
*macaddr
, s16 vlan
,
1312 bool is_vf
, bool is_netdev
)
1314 struct i40e_mac_filter
*f
;
1316 if (!vsi
|| !macaddr
)
1319 f
= i40e_find_filter(vsi
, macaddr
, vlan
, is_vf
, is_netdev
);
1321 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
1323 goto add_filter_out
;
1325 ether_addr_copy(f
->macaddr
, macaddr
);
1329 INIT_LIST_HEAD(&f
->list
);
1330 list_add(&f
->list
, &vsi
->mac_filter_list
);
1333 /* increment counter and add a new flag if needed */
1339 } else if (is_netdev
) {
1340 if (!f
->is_netdev
) {
1341 f
->is_netdev
= true;
1348 /* changed tells sync_filters_subtask to
1349 * push the filter down to the firmware
1352 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1353 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1361 * i40e_del_filter - Remove a mac/vlan filter from the VSI
1362 * @vsi: the VSI to be searched
1363 * @macaddr: the MAC address
1365 * @is_vf: make sure it's a VF filter, else doesn't matter
1366 * @is_netdev: make sure it's a netdev filter, else doesn't matter
1368 void i40e_del_filter(struct i40e_vsi
*vsi
,
1369 u8
*macaddr
, s16 vlan
,
1370 bool is_vf
, bool is_netdev
)
1372 struct i40e_mac_filter
*f
;
1374 if (!vsi
|| !macaddr
)
1377 f
= i40e_find_filter(vsi
, macaddr
, vlan
, is_vf
, is_netdev
);
1378 if (!f
|| f
->counter
== 0)
1386 } else if (is_netdev
) {
1388 f
->is_netdev
= false;
1392 /* make sure we don't remove a filter in use by VF or netdev */
1394 min_f
+= (f
->is_vf
? 1 : 0);
1395 min_f
+= (f
->is_netdev
? 1 : 0);
1397 if (f
->counter
> min_f
)
1401 /* counter == 0 tells sync_filters_subtask to
1402 * remove the filter from the firmware's list
1404 if (f
->counter
== 0) {
1406 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1407 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1412 * i40e_set_mac - NDO callback to set mac address
1413 * @netdev: network interface device structure
1414 * @p: pointer to an address structure
1416 * Returns 0 on success, negative on failure
1419 int i40e_set_mac(struct net_device
*netdev
, void *p
)
1421 static int i40e_set_mac(struct net_device
*netdev
, void *p
)
1424 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1425 struct i40e_vsi
*vsi
= np
->vsi
;
1426 struct i40e_pf
*pf
= vsi
->back
;
1427 struct i40e_hw
*hw
= &pf
->hw
;
1428 struct sockaddr
*addr
= p
;
1429 struct i40e_mac_filter
*f
;
1431 if (!is_valid_ether_addr(addr
->sa_data
))
1432 return -EADDRNOTAVAIL
;
1434 if (ether_addr_equal(netdev
->dev_addr
, addr
->sa_data
)) {
1435 netdev_info(netdev
, "already using mac address %pM\n",
1440 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
1441 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
1442 return -EADDRNOTAVAIL
;
1444 if (ether_addr_equal(hw
->mac
.addr
, addr
->sa_data
))
1445 netdev_info(netdev
, "returning to hw mac address %pM\n",
1448 netdev_info(netdev
, "set new mac address %pM\n", addr
->sa_data
);
1450 if (vsi
->type
== I40E_VSI_MAIN
) {
1452 ret
= i40e_aq_mac_address_write(&vsi
->back
->hw
,
1453 I40E_AQC_WRITE_TYPE_LAA_WOL
,
1454 addr
->sa_data
, NULL
);
1457 "Addr change for Main VSI failed: %d\n",
1459 return -EADDRNOTAVAIL
;
1463 if (ether_addr_equal(netdev
->dev_addr
, hw
->mac
.addr
)) {
1464 struct i40e_aqc_remove_macvlan_element_data element
;
1466 memset(&element
, 0, sizeof(element
));
1467 ether_addr_copy(element
.mac_addr
, netdev
->dev_addr
);
1468 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
1469 i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1471 i40e_del_filter(vsi
, netdev
->dev_addr
, I40E_VLAN_ANY
,
1475 if (ether_addr_equal(addr
->sa_data
, hw
->mac
.addr
)) {
1476 struct i40e_aqc_add_macvlan_element_data element
;
1478 memset(&element
, 0, sizeof(element
));
1479 ether_addr_copy(element
.mac_addr
, hw
->mac
.addr
);
1480 element
.flags
= cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
);
1481 i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1483 f
= i40e_add_filter(vsi
, addr
->sa_data
, I40E_VLAN_ANY
,
1489 i40e_sync_vsi_filters(vsi
);
1490 ether_addr_copy(netdev
->dev_addr
, addr
->sa_data
);
1496 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1497 * @vsi: the VSI being setup
1498 * @ctxt: VSI context structure
1499 * @enabled_tc: Enabled TCs bitmap
1500 * @is_add: True if called before Add VSI
1502 * Setup VSI queue mapping for enabled traffic classes.
1505 void i40e_vsi_setup_queue_map(struct i40e_vsi
*vsi
,
1506 struct i40e_vsi_context
*ctxt
,
1510 static void i40e_vsi_setup_queue_map(struct i40e_vsi
*vsi
,
1511 struct i40e_vsi_context
*ctxt
,
1516 struct i40e_pf
*pf
= vsi
->back
;
1526 sections
= I40E_AQ_VSI_PROP_QUEUE_MAP_VALID
;
1529 if (enabled_tc
&& (vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
1530 /* Find numtc from enabled TC bitmap */
1531 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1532 if (enabled_tc
& BIT_ULL(i
)) /* TC is enabled */
1536 dev_warn(&pf
->pdev
->dev
, "DCB is enabled but no TC enabled, forcing TC0\n");
1540 /* At least TC0 is enabled in case of non-DCB case */
1544 vsi
->tc_config
.numtc
= numtc
;
1545 vsi
->tc_config
.enabled_tc
= enabled_tc
? enabled_tc
: 1;
1546 /* Number of queues per enabled TC */
1547 /* In MFP case we can have a much lower count of MSIx
1548 * vectors available and so we need to lower the used
1551 qcount
= min_t(int, vsi
->alloc_queue_pairs
, pf
->num_lan_msix
);
1552 num_tc_qps
= qcount
/ numtc
;
1553 num_tc_qps
= min_t(int, num_tc_qps
, I40E_MAX_QUEUES_PER_TC
);
1555 /* Setup queue offset/count for all TCs for given VSI */
1556 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1557 /* See if the given TC is enabled for the given VSI */
1558 if (vsi
->tc_config
.enabled_tc
& BIT_ULL(i
)) {
1562 switch (vsi
->type
) {
1564 qcount
= min_t(int, pf
->rss_size
, num_tc_qps
);
1568 qcount
= num_tc_qps
;
1572 case I40E_VSI_SRIOV
:
1573 case I40E_VSI_VMDQ2
:
1575 qcount
= num_tc_qps
;
1579 vsi
->tc_config
.tc_info
[i
].qoffset
= offset
;
1580 vsi
->tc_config
.tc_info
[i
].qcount
= qcount
;
1582 /* find the next higher power-of-2 of num queue pairs */
1585 while (num_qps
&& (BIT_ULL(pow
) < qcount
)) {
1590 vsi
->tc_config
.tc_info
[i
].netdev_tc
= netdev_tc
++;
1592 (offset
<< I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT
) |
1593 (pow
<< I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT
);
1597 /* TC is not enabled so set the offset to
1598 * default queue and allocate one queue
1601 vsi
->tc_config
.tc_info
[i
].qoffset
= 0;
1602 vsi
->tc_config
.tc_info
[i
].qcount
= 1;
1603 vsi
->tc_config
.tc_info
[i
].netdev_tc
= 0;
1607 ctxt
->info
.tc_mapping
[i
] = cpu_to_le16(qmap
);
1610 /* Set actual Tx/Rx queue pairs */
1611 vsi
->num_queue_pairs
= offset
;
1612 if ((vsi
->type
== I40E_VSI_MAIN
) && (numtc
== 1)) {
1613 if (vsi
->req_queue_pairs
> 0)
1614 vsi
->num_queue_pairs
= vsi
->req_queue_pairs
;
1616 vsi
->num_queue_pairs
= pf
->num_lan_msix
;
1619 /* Scheduler section valid can only be set for ADD VSI */
1621 sections
|= I40E_AQ_VSI_PROP_SCHED_VALID
;
1623 ctxt
->info
.up_enable_bits
= enabled_tc
;
1625 if (vsi
->type
== I40E_VSI_SRIOV
) {
1626 ctxt
->info
.mapping_flags
|=
1627 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG
);
1628 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
1629 ctxt
->info
.queue_mapping
[i
] =
1630 cpu_to_le16(vsi
->base_queue
+ i
);
1632 ctxt
->info
.mapping_flags
|=
1633 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG
);
1634 ctxt
->info
.queue_mapping
[0] = cpu_to_le16(vsi
->base_queue
);
1636 ctxt
->info
.valid_sections
|= cpu_to_le16(sections
);
1640 * i40e_set_rx_mode - NDO callback to set the netdev filters
1641 * @netdev: network interface device structure
1644 void i40e_set_rx_mode(struct net_device
*netdev
)
1646 static void i40e_set_rx_mode(struct net_device
*netdev
)
1649 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1650 struct i40e_mac_filter
*f
, *ftmp
;
1651 struct i40e_vsi
*vsi
= np
->vsi
;
1652 struct netdev_hw_addr
*uca
;
1653 struct netdev_hw_addr
*mca
;
1654 struct netdev_hw_addr
*ha
;
1656 /* add addr if not already in the filter list */
1657 netdev_for_each_uc_addr(uca
, netdev
) {
1658 if (!i40e_find_mac(vsi
, uca
->addr
, false, true)) {
1659 if (i40e_is_vsi_in_vlan(vsi
))
1660 i40e_put_mac_in_vlan(vsi
, uca
->addr
,
1663 i40e_add_filter(vsi
, uca
->addr
, I40E_VLAN_ANY
,
1668 netdev_for_each_mc_addr(mca
, netdev
) {
1669 if (!i40e_find_mac(vsi
, mca
->addr
, false, true)) {
1670 if (i40e_is_vsi_in_vlan(vsi
))
1671 i40e_put_mac_in_vlan(vsi
, mca
->addr
,
1674 i40e_add_filter(vsi
, mca
->addr
, I40E_VLAN_ANY
,
1679 /* remove filter if not in netdev list */
1680 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1686 if (is_multicast_ether_addr(f
->macaddr
)) {
1687 netdev_for_each_mc_addr(mca
, netdev
) {
1688 if (ether_addr_equal(mca
->addr
, f
->macaddr
)) {
1694 netdev_for_each_uc_addr(uca
, netdev
) {
1695 if (ether_addr_equal(uca
->addr
, f
->macaddr
)) {
1701 for_each_dev_addr(netdev
, ha
) {
1702 if (ether_addr_equal(ha
->addr
, f
->macaddr
)) {
1710 vsi
, f
->macaddr
, I40E_VLAN_ANY
, false, true);
1713 /* check for other flag changes */
1714 if (vsi
->current_netdev_flags
!= vsi
->netdev
->flags
) {
1715 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1716 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1721 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
1722 * @vsi: ptr to the VSI
1724 * Push any outstanding VSI filter changes through the AdminQ.
1726 * Returns 0 or error value
1728 int i40e_sync_vsi_filters(struct i40e_vsi
*vsi
)
1730 struct i40e_mac_filter
*f
, *ftmp
;
1731 bool promisc_forced_on
= false;
1732 bool add_happened
= false;
1733 int filter_list_len
= 0;
1734 u32 changed_flags
= 0;
1735 i40e_status ret
= 0;
1742 /* empty array typed pointers, kcalloc later */
1743 struct i40e_aqc_add_macvlan_element_data
*add_list
;
1744 struct i40e_aqc_remove_macvlan_element_data
*del_list
;
1746 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &vsi
->state
))
1747 usleep_range(1000, 2000);
1751 changed_flags
= vsi
->current_netdev_flags
^ vsi
->netdev
->flags
;
1752 vsi
->current_netdev_flags
= vsi
->netdev
->flags
;
1755 if (vsi
->flags
& I40E_VSI_FLAG_FILTER_CHANGED
) {
1756 vsi
->flags
&= ~I40E_VSI_FLAG_FILTER_CHANGED
;
1758 filter_list_len
= pf
->hw
.aq
.asq_buf_size
/
1759 sizeof(struct i40e_aqc_remove_macvlan_element_data
);
1760 del_list
= kcalloc(filter_list_len
,
1761 sizeof(struct i40e_aqc_remove_macvlan_element_data
),
1766 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1770 if (f
->counter
!= 0)
1775 /* add to delete list */
1776 ether_addr_copy(del_list
[num_del
].mac_addr
, f
->macaddr
);
1777 del_list
[num_del
].vlan_tag
=
1778 cpu_to_le16((u16
)(f
->vlan
==
1779 I40E_VLAN_ANY
? 0 : f
->vlan
));
1781 cmd_flags
|= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
1782 del_list
[num_del
].flags
= cmd_flags
;
1785 /* unlink from filter list */
1789 /* flush a full buffer */
1790 if (num_del
== filter_list_len
) {
1791 ret
= i40e_aq_remove_macvlan(&pf
->hw
,
1792 vsi
->seid
, del_list
, num_del
,
1794 aq_err
= pf
->hw
.aq
.asq_last_status
;
1796 memset(del_list
, 0, sizeof(*del_list
));
1798 if (ret
&& aq_err
!= I40E_AQ_RC_ENOENT
)
1799 dev_info(&pf
->pdev
->dev
,
1800 "ignoring delete macvlan error, err %s, aq_err %s while flushing a full buffer\n",
1801 i40e_stat_str(&pf
->hw
, ret
),
1802 i40e_aq_str(&pf
->hw
, aq_err
));
1806 ret
= i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
,
1807 del_list
, num_del
, NULL
);
1808 aq_err
= pf
->hw
.aq
.asq_last_status
;
1811 if (ret
&& aq_err
!= I40E_AQ_RC_ENOENT
)
1812 dev_info(&pf
->pdev
->dev
,
1813 "ignoring delete macvlan error, err %s aq_err %s\n",
1814 i40e_stat_str(&pf
->hw
, ret
),
1815 i40e_aq_str(&pf
->hw
, aq_err
));
1821 /* do all the adds now */
1822 filter_list_len
= pf
->hw
.aq
.asq_buf_size
/
1823 sizeof(struct i40e_aqc_add_macvlan_element_data
),
1824 add_list
= kcalloc(filter_list_len
,
1825 sizeof(struct i40e_aqc_add_macvlan_element_data
),
1830 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1834 if (f
->counter
== 0)
1837 add_happened
= true;
1840 /* add to add array */
1841 ether_addr_copy(add_list
[num_add
].mac_addr
, f
->macaddr
);
1842 add_list
[num_add
].vlan_tag
=
1844 (u16
)(f
->vlan
== I40E_VLAN_ANY
? 0 : f
->vlan
));
1845 add_list
[num_add
].queue_number
= 0;
1847 cmd_flags
|= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
;
1848 add_list
[num_add
].flags
= cpu_to_le16(cmd_flags
);
1851 /* flush a full buffer */
1852 if (num_add
== filter_list_len
) {
1853 ret
= i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
,
1856 aq_err
= pf
->hw
.aq
.asq_last_status
;
1861 memset(add_list
, 0, sizeof(*add_list
));
1865 ret
= i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
,
1866 add_list
, num_add
, NULL
);
1867 aq_err
= pf
->hw
.aq
.asq_last_status
;
1873 if (add_happened
&& ret
&& aq_err
!= I40E_AQ_RC_EINVAL
) {
1874 dev_info(&pf
->pdev
->dev
,
1875 "add filter failed, err %s aq_err %s\n",
1876 i40e_stat_str(&pf
->hw
, ret
),
1877 i40e_aq_str(&pf
->hw
, aq_err
));
1878 if ((pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_ENOSPC
) &&
1879 !test_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
1881 promisc_forced_on
= true;
1882 set_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
1884 dev_info(&pf
->pdev
->dev
, "promiscuous mode forced on\n");
1889 /* check for changes in promiscuous modes */
1890 if (changed_flags
& IFF_ALLMULTI
) {
1891 bool cur_multipromisc
;
1892 cur_multipromisc
= !!(vsi
->current_netdev_flags
& IFF_ALLMULTI
);
1893 ret
= i40e_aq_set_vsi_multicast_promiscuous(&vsi
->back
->hw
,
1898 dev_info(&pf
->pdev
->dev
,
1899 "set multi promisc failed, err %s aq_err %s\n",
1900 i40e_stat_str(&pf
->hw
, ret
),
1901 i40e_aq_str(&pf
->hw
,
1902 pf
->hw
.aq
.asq_last_status
));
1904 if ((changed_flags
& IFF_PROMISC
) || promisc_forced_on
) {
1906 cur_promisc
= (!!(vsi
->current_netdev_flags
& IFF_PROMISC
) ||
1907 test_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
1909 ret
= i40e_aq_set_vsi_unicast_promiscuous(&vsi
->back
->hw
,
1913 dev_info(&pf
->pdev
->dev
,
1914 "set uni promisc failed, err %s, aq_err %s\n",
1915 i40e_stat_str(&pf
->hw
, ret
),
1916 i40e_aq_str(&pf
->hw
,
1917 pf
->hw
.aq
.asq_last_status
));
1918 ret
= i40e_aq_set_vsi_broadcast(&vsi
->back
->hw
,
1922 dev_info(&pf
->pdev
->dev
,
1923 "set brdcast promisc failed, err %s, aq_err %s\n",
1924 i40e_stat_str(&pf
->hw
, ret
),
1925 i40e_aq_str(&pf
->hw
,
1926 pf
->hw
.aq
.asq_last_status
));
1929 clear_bit(__I40E_CONFIG_BUSY
, &vsi
->state
);
1934 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
1935 * @pf: board private structure
1937 static void i40e_sync_filters_subtask(struct i40e_pf
*pf
)
1941 if (!pf
|| !(pf
->flags
& I40E_FLAG_FILTER_SYNC
))
1943 pf
->flags
&= ~I40E_FLAG_FILTER_SYNC
;
1945 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
1947 (pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_FILTER_CHANGED
))
1948 i40e_sync_vsi_filters(pf
->vsi
[v
]);
1953 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
1954 * @netdev: network interface device structure
1955 * @new_mtu: new value for maximum frame size
1957 * Returns 0 on success, negative on failure
1959 static int i40e_change_mtu(struct net_device
*netdev
, int new_mtu
)
1961 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1962 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
1963 struct i40e_vsi
*vsi
= np
->vsi
;
1965 /* MTU < 68 is an error and causes problems on some kernels */
1966 if ((new_mtu
< 68) || (max_frame
> I40E_MAX_RXBUFFER
))
1969 netdev_info(netdev
, "changing MTU from %d to %d\n",
1970 netdev
->mtu
, new_mtu
);
1971 netdev
->mtu
= new_mtu
;
1972 if (netif_running(netdev
))
1973 i40e_vsi_reinit_locked(vsi
);
1979 * i40e_ioctl - Access the hwtstamp interface
1980 * @netdev: network interface device structure
1981 * @ifr: interface request data
1982 * @cmd: ioctl command
1984 int i40e_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
1986 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1987 struct i40e_pf
*pf
= np
->vsi
->back
;
1991 return i40e_ptp_get_ts_config(pf
, ifr
);
1993 return i40e_ptp_set_ts_config(pf
, ifr
);
2000 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
2001 * @vsi: the vsi being adjusted
2003 void i40e_vlan_stripping_enable(struct i40e_vsi
*vsi
)
2005 struct i40e_vsi_context ctxt
;
2008 if ((vsi
->info
.valid_sections
&
2009 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
2010 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_MODE_MASK
) == 0))
2011 return; /* already enabled */
2013 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2014 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
2015 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH
;
2017 ctxt
.seid
= vsi
->seid
;
2018 ctxt
.info
= vsi
->info
;
2019 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2021 dev_info(&vsi
->back
->pdev
->dev
,
2022 "update vlan stripping failed, err %s aq_err %s\n",
2023 i40e_stat_str(&vsi
->back
->hw
, ret
),
2024 i40e_aq_str(&vsi
->back
->hw
,
2025 vsi
->back
->hw
.aq
.asq_last_status
));
2030 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2031 * @vsi: the vsi being adjusted
2033 void i40e_vlan_stripping_disable(struct i40e_vsi
*vsi
)
2035 struct i40e_vsi_context ctxt
;
2038 if ((vsi
->info
.valid_sections
&
2039 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
2040 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_EMOD_MASK
) ==
2041 I40E_AQ_VSI_PVLAN_EMOD_MASK
))
2042 return; /* already disabled */
2044 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2045 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
2046 I40E_AQ_VSI_PVLAN_EMOD_NOTHING
;
2048 ctxt
.seid
= vsi
->seid
;
2049 ctxt
.info
= vsi
->info
;
2050 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2052 dev_info(&vsi
->back
->pdev
->dev
,
2053 "update vlan stripping failed, err %s aq_err %s\n",
2054 i40e_stat_str(&vsi
->back
->hw
, ret
),
2055 i40e_aq_str(&vsi
->back
->hw
,
2056 vsi
->back
->hw
.aq
.asq_last_status
));
2061 * i40e_vlan_rx_register - Setup or shutdown vlan offload
2062 * @netdev: network interface to be adjusted
2063 * @features: netdev features to test if VLAN offload is enabled or not
2065 static void i40e_vlan_rx_register(struct net_device
*netdev
, u32 features
)
2067 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2068 struct i40e_vsi
*vsi
= np
->vsi
;
2070 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
2071 i40e_vlan_stripping_enable(vsi
);
2073 i40e_vlan_stripping_disable(vsi
);
2077 * i40e_vsi_add_vlan - Add vsi membership for given vlan
2078 * @vsi: the vsi being configured
2079 * @vid: vlan id to be added (0 = untagged only , -1 = any)
2081 int i40e_vsi_add_vlan(struct i40e_vsi
*vsi
, s16 vid
)
2083 struct i40e_mac_filter
*f
, *add_f
;
2084 bool is_netdev
, is_vf
;
2086 is_vf
= (vsi
->type
== I40E_VSI_SRIOV
);
2087 is_netdev
= !!(vsi
->netdev
);
2090 add_f
= i40e_add_filter(vsi
, vsi
->netdev
->dev_addr
, vid
,
2093 dev_info(&vsi
->back
->pdev
->dev
,
2094 "Could not add vlan filter %d for %pM\n",
2095 vid
, vsi
->netdev
->dev_addr
);
2100 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2101 add_f
= i40e_add_filter(vsi
, f
->macaddr
, vid
, is_vf
, is_netdev
);
2103 dev_info(&vsi
->back
->pdev
->dev
,
2104 "Could not add vlan filter %d for %pM\n",
2110 /* Now if we add a vlan tag, make sure to check if it is the first
2111 * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
2112 * with 0, so we now accept untagged and specified tagged traffic
2113 * (and not any taged and untagged)
2116 if (is_netdev
&& i40e_find_filter(vsi
, vsi
->netdev
->dev_addr
,
2118 is_vf
, is_netdev
)) {
2119 i40e_del_filter(vsi
, vsi
->netdev
->dev_addr
,
2120 I40E_VLAN_ANY
, is_vf
, is_netdev
);
2121 add_f
= i40e_add_filter(vsi
, vsi
->netdev
->dev_addr
, 0,
2124 dev_info(&vsi
->back
->pdev
->dev
,
2125 "Could not add filter 0 for %pM\n",
2126 vsi
->netdev
->dev_addr
);
2132 /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
2133 if (vid
> 0 && !vsi
->info
.pvid
) {
2134 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2135 if (i40e_find_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2136 is_vf
, is_netdev
)) {
2137 i40e_del_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2139 add_f
= i40e_add_filter(vsi
, f
->macaddr
,
2140 0, is_vf
, is_netdev
);
2142 dev_info(&vsi
->back
->pdev
->dev
,
2143 "Could not add filter 0 for %pM\n",
2151 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
2152 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
2155 return i40e_sync_vsi_filters(vsi
);
2159 * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
2160 * @vsi: the vsi being configured
2161 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
2163 * Return: 0 on success or negative otherwise
2165 int i40e_vsi_kill_vlan(struct i40e_vsi
*vsi
, s16 vid
)
2167 struct net_device
*netdev
= vsi
->netdev
;
2168 struct i40e_mac_filter
*f
, *add_f
;
2169 bool is_vf
, is_netdev
;
2170 int filter_count
= 0;
2172 is_vf
= (vsi
->type
== I40E_VSI_SRIOV
);
2173 is_netdev
= !!(netdev
);
2176 i40e_del_filter(vsi
, netdev
->dev_addr
, vid
, is_vf
, is_netdev
);
2178 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
)
2179 i40e_del_filter(vsi
, f
->macaddr
, vid
, is_vf
, is_netdev
);
2181 /* go through all the filters for this VSI and if there is only
2182 * vid == 0 it means there are no other filters, so vid 0 must
2183 * be replaced with -1. This signifies that we should from now
2184 * on accept any traffic (with any tag present, or untagged)
2186 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2189 ether_addr_equal(netdev
->dev_addr
, f
->macaddr
))
2197 if (!filter_count
&& is_netdev
) {
2198 i40e_del_filter(vsi
, netdev
->dev_addr
, 0, is_vf
, is_netdev
);
2199 f
= i40e_add_filter(vsi
, netdev
->dev_addr
, I40E_VLAN_ANY
,
2202 dev_info(&vsi
->back
->pdev
->dev
,
2203 "Could not add filter %d for %pM\n",
2204 I40E_VLAN_ANY
, netdev
->dev_addr
);
2209 if (!filter_count
) {
2210 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2211 i40e_del_filter(vsi
, f
->macaddr
, 0, is_vf
, is_netdev
);
2212 add_f
= i40e_add_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2215 dev_info(&vsi
->back
->pdev
->dev
,
2216 "Could not add filter %d for %pM\n",
2217 I40E_VLAN_ANY
, f
->macaddr
);
2223 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
2224 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
2227 return i40e_sync_vsi_filters(vsi
);
2231 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2232 * @netdev: network interface to be adjusted
2233 * @vid: vlan id to be added
2235 * net_device_ops implementation for adding vlan ids
2238 int i40e_vlan_rx_add_vid(struct net_device
*netdev
,
2239 __always_unused __be16 proto
, u16 vid
)
2241 static int i40e_vlan_rx_add_vid(struct net_device
*netdev
,
2242 __always_unused __be16 proto
, u16 vid
)
2245 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2246 struct i40e_vsi
*vsi
= np
->vsi
;
2252 netdev_info(netdev
, "adding %pM vid=%d\n", netdev
->dev_addr
, vid
);
2254 /* If the network stack called us with vid = 0 then
2255 * it is asking to receive priority tagged packets with
2256 * vlan id 0. Our HW receives them by default when configured
2257 * to receive untagged packets so there is no need to add an
2258 * extra filter for vlan 0 tagged packets.
2261 ret
= i40e_vsi_add_vlan(vsi
, vid
);
2263 if (!ret
&& (vid
< VLAN_N_VID
))
2264 set_bit(vid
, vsi
->active_vlans
);
2270 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2271 * @netdev: network interface to be adjusted
2272 * @vid: vlan id to be removed
2274 * net_device_ops implementation for removing vlan ids
2277 int i40e_vlan_rx_kill_vid(struct net_device
*netdev
,
2278 __always_unused __be16 proto
, u16 vid
)
2280 static int i40e_vlan_rx_kill_vid(struct net_device
*netdev
,
2281 __always_unused __be16 proto
, u16 vid
)
2284 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2285 struct i40e_vsi
*vsi
= np
->vsi
;
2287 netdev_info(netdev
, "removing %pM vid=%d\n", netdev
->dev_addr
, vid
);
2289 /* return code is ignored as there is nothing a user
2290 * can do about failure to remove and a log message was
2291 * already printed from the other function
2293 i40e_vsi_kill_vlan(vsi
, vid
);
2295 clear_bit(vid
, vsi
->active_vlans
);
2301 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2302 * @vsi: the vsi being brought back up
2304 static void i40e_restore_vlan(struct i40e_vsi
*vsi
)
2311 i40e_vlan_rx_register(vsi
->netdev
, vsi
->netdev
->features
);
2313 for_each_set_bit(vid
, vsi
->active_vlans
, VLAN_N_VID
)
2314 i40e_vlan_rx_add_vid(vsi
->netdev
, htons(ETH_P_8021Q
),
2319 * i40e_vsi_add_pvid - Add pvid for the VSI
2320 * @vsi: the vsi being adjusted
2321 * @vid: the vlan id to set as a PVID
2323 int i40e_vsi_add_pvid(struct i40e_vsi
*vsi
, u16 vid
)
2325 struct i40e_vsi_context ctxt
;
2328 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2329 vsi
->info
.pvid
= cpu_to_le16(vid
);
2330 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_TAGGED
|
2331 I40E_AQ_VSI_PVLAN_INSERT_PVID
|
2332 I40E_AQ_VSI_PVLAN_EMOD_STR
;
2334 ctxt
.seid
= vsi
->seid
;
2335 ctxt
.info
= vsi
->info
;
2336 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2338 dev_info(&vsi
->back
->pdev
->dev
,
2339 "add pvid failed, err %s aq_err %s\n",
2340 i40e_stat_str(&vsi
->back
->hw
, ret
),
2341 i40e_aq_str(&vsi
->back
->hw
,
2342 vsi
->back
->hw
.aq
.asq_last_status
));
2350 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2351 * @vsi: the vsi being adjusted
2353 * Just use the vlan_rx_register() service to put it back to normal
2355 void i40e_vsi_remove_pvid(struct i40e_vsi
*vsi
)
2357 i40e_vlan_stripping_disable(vsi
);
2363 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2364 * @vsi: ptr to the VSI
2366 * If this function returns with an error, then it's possible one or
2367 * more of the rings is populated (while the rest are not). It is the
2368 * callers duty to clean those orphaned rings.
2370 * Return 0 on success, negative on failure
2372 static int i40e_vsi_setup_tx_resources(struct i40e_vsi
*vsi
)
2376 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2377 err
= i40e_setup_tx_descriptors(vsi
->tx_rings
[i
]);
2383 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2384 * @vsi: ptr to the VSI
2386 * Free VSI's transmit software resources
2388 static void i40e_vsi_free_tx_resources(struct i40e_vsi
*vsi
)
2395 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2396 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
)
2397 i40e_free_tx_resources(vsi
->tx_rings
[i
]);
2401 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2402 * @vsi: ptr to the VSI
2404 * If this function returns with an error, then it's possible one or
2405 * more of the rings is populated (while the rest are not). It is the
2406 * callers duty to clean those orphaned rings.
2408 * Return 0 on success, negative on failure
2410 static int i40e_vsi_setup_rx_resources(struct i40e_vsi
*vsi
)
2414 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2415 err
= i40e_setup_rx_descriptors(vsi
->rx_rings
[i
]);
2417 i40e_fcoe_setup_ddp_resources(vsi
);
2423 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2424 * @vsi: ptr to the VSI
2426 * Free all receive software resources
2428 static void i40e_vsi_free_rx_resources(struct i40e_vsi
*vsi
)
2435 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2436 if (vsi
->rx_rings
[i
] && vsi
->rx_rings
[i
]->desc
)
2437 i40e_free_rx_resources(vsi
->rx_rings
[i
]);
2439 i40e_fcoe_free_ddp_resources(vsi
);
2444 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
2445 * @ring: The Tx ring to configure
2447 * This enables/disables XPS for a given Tx descriptor ring
2448 * based on the TCs enabled for the VSI that ring belongs to.
2450 static void i40e_config_xps_tx_ring(struct i40e_ring
*ring
)
2452 struct i40e_vsi
*vsi
= ring
->vsi
;
2455 if (!ring
->q_vector
|| !ring
->netdev
)
2458 /* Single TC mode enable XPS */
2459 if (vsi
->tc_config
.numtc
<= 1) {
2460 if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE
, &ring
->state
))
2461 netif_set_xps_queue(ring
->netdev
,
2462 &ring
->q_vector
->affinity_mask
,
2464 } else if (alloc_cpumask_var(&mask
, GFP_KERNEL
)) {
2465 /* Disable XPS to allow selection based on TC */
2466 bitmap_zero(cpumask_bits(mask
), nr_cpumask_bits
);
2467 netif_set_xps_queue(ring
->netdev
, mask
, ring
->queue_index
);
2468 free_cpumask_var(mask
);
2473 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2474 * @ring: The Tx ring to configure
2476 * Configure the Tx descriptor ring in the HMC context.
2478 static int i40e_configure_tx_ring(struct i40e_ring
*ring
)
2480 struct i40e_vsi
*vsi
= ring
->vsi
;
2481 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
2482 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2483 struct i40e_hmc_obj_txq tx_ctx
;
2484 i40e_status err
= 0;
2487 /* some ATR related tx ring init */
2488 if (vsi
->back
->flags
& I40E_FLAG_FD_ATR_ENABLED
) {
2489 ring
->atr_sample_rate
= vsi
->back
->atr_sample_rate
;
2490 ring
->atr_count
= 0;
2492 ring
->atr_sample_rate
= 0;
2496 i40e_config_xps_tx_ring(ring
);
2498 /* clear the context structure first */
2499 memset(&tx_ctx
, 0, sizeof(tx_ctx
));
2501 tx_ctx
.new_context
= 1;
2502 tx_ctx
.base
= (ring
->dma
/ 128);
2503 tx_ctx
.qlen
= ring
->count
;
2504 tx_ctx
.fd_ena
= !!(vsi
->back
->flags
& (I40E_FLAG_FD_SB_ENABLED
|
2505 I40E_FLAG_FD_ATR_ENABLED
));
2507 tx_ctx
.fc_ena
= (vsi
->type
== I40E_VSI_FCOE
);
2509 tx_ctx
.timesync_ena
= !!(vsi
->back
->flags
& I40E_FLAG_PTP
);
2510 /* FDIR VSI tx ring can still use RS bit and writebacks */
2511 if (vsi
->type
!= I40E_VSI_FDIR
)
2512 tx_ctx
.head_wb_ena
= 1;
2513 tx_ctx
.head_wb_addr
= ring
->dma
+
2514 (ring
->count
* sizeof(struct i40e_tx_desc
));
2516 /* As part of VSI creation/update, FW allocates certain
2517 * Tx arbitration queue sets for each TC enabled for
2518 * the VSI. The FW returns the handles to these queue
2519 * sets as part of the response buffer to Add VSI,
2520 * Update VSI, etc. AQ commands. It is expected that
2521 * these queue set handles be associated with the Tx
2522 * queues by the driver as part of the TX queue context
2523 * initialization. This has to be done regardless of
2524 * DCB as by default everything is mapped to TC0.
2526 tx_ctx
.rdylist
= le16_to_cpu(vsi
->info
.qs_handle
[ring
->dcb_tc
]);
2527 tx_ctx
.rdylist_act
= 0;
2529 /* clear the context in the HMC */
2530 err
= i40e_clear_lan_tx_queue_context(hw
, pf_q
);
2532 dev_info(&vsi
->back
->pdev
->dev
,
2533 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2534 ring
->queue_index
, pf_q
, err
);
2538 /* set the context in the HMC */
2539 err
= i40e_set_lan_tx_queue_context(hw
, pf_q
, &tx_ctx
);
2541 dev_info(&vsi
->back
->pdev
->dev
,
2542 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
2543 ring
->queue_index
, pf_q
, err
);
2547 /* Now associate this queue with this PCI function */
2548 if (vsi
->type
== I40E_VSI_VMDQ2
) {
2549 qtx_ctl
= I40E_QTX_CTL_VM_QUEUE
;
2550 qtx_ctl
|= ((vsi
->id
) << I40E_QTX_CTL_VFVM_INDX_SHIFT
) &
2551 I40E_QTX_CTL_VFVM_INDX_MASK
;
2553 qtx_ctl
= I40E_QTX_CTL_PF_QUEUE
;
2556 qtx_ctl
|= ((hw
->pf_id
<< I40E_QTX_CTL_PF_INDX_SHIFT
) &
2557 I40E_QTX_CTL_PF_INDX_MASK
);
2558 wr32(hw
, I40E_QTX_CTL(pf_q
), qtx_ctl
);
2561 clear_bit(__I40E_HANG_CHECK_ARMED
, &ring
->state
);
2563 /* cache tail off for easier writes later */
2564 ring
->tail
= hw
->hw_addr
+ I40E_QTX_TAIL(pf_q
);
2570 * i40e_configure_rx_ring - Configure a receive ring context
2571 * @ring: The Rx ring to configure
2573 * Configure the Rx descriptor ring in the HMC context.
2575 static int i40e_configure_rx_ring(struct i40e_ring
*ring
)
2577 struct i40e_vsi
*vsi
= ring
->vsi
;
2578 u32 chain_len
= vsi
->back
->hw
.func_caps
.rx_buf_chain_len
;
2579 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
2580 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2581 struct i40e_hmc_obj_rxq rx_ctx
;
2582 i40e_status err
= 0;
2586 /* clear the context structure first */
2587 memset(&rx_ctx
, 0, sizeof(rx_ctx
));
2589 ring
->rx_buf_len
= vsi
->rx_buf_len
;
2590 ring
->rx_hdr_len
= vsi
->rx_hdr_len
;
2592 rx_ctx
.dbuff
= ring
->rx_buf_len
>> I40E_RXQ_CTX_DBUFF_SHIFT
;
2593 rx_ctx
.hbuff
= ring
->rx_hdr_len
>> I40E_RXQ_CTX_HBUFF_SHIFT
;
2595 rx_ctx
.base
= (ring
->dma
/ 128);
2596 rx_ctx
.qlen
= ring
->count
;
2598 if (vsi
->back
->flags
& I40E_FLAG_16BYTE_RX_DESC_ENABLED
) {
2599 set_ring_16byte_desc_enabled(ring
);
2605 rx_ctx
.dtype
= vsi
->dtype
;
2607 set_ring_ps_enabled(ring
);
2608 rx_ctx
.hsplit_0
= I40E_RX_SPLIT_L2
|
2610 I40E_RX_SPLIT_TCP_UDP
|
2613 rx_ctx
.hsplit_0
= 0;
2616 rx_ctx
.rxmax
= min_t(u16
, vsi
->max_frame
,
2617 (chain_len
* ring
->rx_buf_len
));
2618 if (hw
->revision_id
== 0)
2619 rx_ctx
.lrxqthresh
= 0;
2621 rx_ctx
.lrxqthresh
= 2;
2622 rx_ctx
.crcstrip
= 1;
2626 rx_ctx
.fc_ena
= (vsi
->type
== I40E_VSI_FCOE
);
2628 /* set the prefena field to 1 because the manual says to */
2631 /* clear the context in the HMC */
2632 err
= i40e_clear_lan_rx_queue_context(hw
, pf_q
);
2634 dev_info(&vsi
->back
->pdev
->dev
,
2635 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2636 ring
->queue_index
, pf_q
, err
);
2640 /* set the context in the HMC */
2641 err
= i40e_set_lan_rx_queue_context(hw
, pf_q
, &rx_ctx
);
2643 dev_info(&vsi
->back
->pdev
->dev
,
2644 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2645 ring
->queue_index
, pf_q
, err
);
2649 /* cache tail for quicker writes, and clear the reg before use */
2650 ring
->tail
= hw
->hw_addr
+ I40E_QRX_TAIL(pf_q
);
2651 writel(0, ring
->tail
);
2653 if (ring_is_ps_enabled(ring
)) {
2654 i40e_alloc_rx_headers(ring
);
2655 i40e_alloc_rx_buffers_ps(ring
, I40E_DESC_UNUSED(ring
));
2657 i40e_alloc_rx_buffers_1buf(ring
, I40E_DESC_UNUSED(ring
));
2664 * i40e_vsi_configure_tx - Configure the VSI for Tx
2665 * @vsi: VSI structure describing this set of rings and resources
2667 * Configure the Tx VSI for operation.
2669 static int i40e_vsi_configure_tx(struct i40e_vsi
*vsi
)
2674 for (i
= 0; (i
< vsi
->num_queue_pairs
) && !err
; i
++)
2675 err
= i40e_configure_tx_ring(vsi
->tx_rings
[i
]);
2681 * i40e_vsi_configure_rx - Configure the VSI for Rx
2682 * @vsi: the VSI being configured
2684 * Configure the Rx VSI for operation.
2686 static int i40e_vsi_configure_rx(struct i40e_vsi
*vsi
)
2691 if (vsi
->netdev
&& (vsi
->netdev
->mtu
> ETH_DATA_LEN
))
2692 vsi
->max_frame
= vsi
->netdev
->mtu
+ ETH_HLEN
2693 + ETH_FCS_LEN
+ VLAN_HLEN
;
2695 vsi
->max_frame
= I40E_RXBUFFER_2048
;
2697 /* figure out correct receive buffer length */
2698 switch (vsi
->back
->flags
& (I40E_FLAG_RX_1BUF_ENABLED
|
2699 I40E_FLAG_RX_PS_ENABLED
)) {
2700 case I40E_FLAG_RX_1BUF_ENABLED
:
2701 vsi
->rx_hdr_len
= 0;
2702 vsi
->rx_buf_len
= vsi
->max_frame
;
2703 vsi
->dtype
= I40E_RX_DTYPE_NO_SPLIT
;
2705 case I40E_FLAG_RX_PS_ENABLED
:
2706 vsi
->rx_hdr_len
= I40E_RX_HDR_SIZE
;
2707 vsi
->rx_buf_len
= I40E_RXBUFFER_2048
;
2708 vsi
->dtype
= I40E_RX_DTYPE_HEADER_SPLIT
;
2711 vsi
->rx_hdr_len
= I40E_RX_HDR_SIZE
;
2712 vsi
->rx_buf_len
= I40E_RXBUFFER_2048
;
2713 vsi
->dtype
= I40E_RX_DTYPE_SPLIT_ALWAYS
;
2718 /* setup rx buffer for FCoE */
2719 if ((vsi
->type
== I40E_VSI_FCOE
) &&
2720 (vsi
->back
->flags
& I40E_FLAG_FCOE_ENABLED
)) {
2721 vsi
->rx_hdr_len
= 0;
2722 vsi
->rx_buf_len
= I40E_RXBUFFER_3072
;
2723 vsi
->max_frame
= I40E_RXBUFFER_3072
;
2724 vsi
->dtype
= I40E_RX_DTYPE_NO_SPLIT
;
2727 #endif /* I40E_FCOE */
2728 /* round up for the chip's needs */
2729 vsi
->rx_hdr_len
= ALIGN(vsi
->rx_hdr_len
,
2730 BIT_ULL(I40E_RXQ_CTX_HBUFF_SHIFT
));
2731 vsi
->rx_buf_len
= ALIGN(vsi
->rx_buf_len
,
2732 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT
));
2734 /* set up individual rings */
2735 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2736 err
= i40e_configure_rx_ring(vsi
->rx_rings
[i
]);
2742 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
2743 * @vsi: ptr to the VSI
2745 static void i40e_vsi_config_dcb_rings(struct i40e_vsi
*vsi
)
2747 struct i40e_ring
*tx_ring
, *rx_ring
;
2748 u16 qoffset
, qcount
;
2751 if (!(vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
2752 /* Reset the TC information */
2753 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
2754 rx_ring
= vsi
->rx_rings
[i
];
2755 tx_ring
= vsi
->tx_rings
[i
];
2756 rx_ring
->dcb_tc
= 0;
2757 tx_ring
->dcb_tc
= 0;
2761 for (n
= 0; n
< I40E_MAX_TRAFFIC_CLASS
; n
++) {
2762 if (!(vsi
->tc_config
.enabled_tc
& BIT_ULL(n
)))
2765 qoffset
= vsi
->tc_config
.tc_info
[n
].qoffset
;
2766 qcount
= vsi
->tc_config
.tc_info
[n
].qcount
;
2767 for (i
= qoffset
; i
< (qoffset
+ qcount
); i
++) {
2768 rx_ring
= vsi
->rx_rings
[i
];
2769 tx_ring
= vsi
->tx_rings
[i
];
2770 rx_ring
->dcb_tc
= n
;
2771 tx_ring
->dcb_tc
= n
;
2777 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
2778 * @vsi: ptr to the VSI
2780 static void i40e_set_vsi_rx_mode(struct i40e_vsi
*vsi
)
2783 i40e_set_rx_mode(vsi
->netdev
);
2787 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
2788 * @vsi: Pointer to the targeted VSI
2790 * This function replays the hlist on the hw where all the SB Flow Director
2791 * filters were saved.
2793 static void i40e_fdir_filter_restore(struct i40e_vsi
*vsi
)
2795 struct i40e_fdir_filter
*filter
;
2796 struct i40e_pf
*pf
= vsi
->back
;
2797 struct hlist_node
*node
;
2799 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
2802 hlist_for_each_entry_safe(filter
, node
,
2803 &pf
->fdir_filter_list
, fdir_node
) {
2804 i40e_add_del_fdir(vsi
, filter
, true);
2809 * i40e_vsi_configure - Set up the VSI for action
2810 * @vsi: the VSI being configured
2812 static int i40e_vsi_configure(struct i40e_vsi
*vsi
)
2816 i40e_set_vsi_rx_mode(vsi
);
2817 i40e_restore_vlan(vsi
);
2818 i40e_vsi_config_dcb_rings(vsi
);
2819 err
= i40e_vsi_configure_tx(vsi
);
2821 err
= i40e_vsi_configure_rx(vsi
);
2827 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
2828 * @vsi: the VSI being configured
2830 static void i40e_vsi_configure_msix(struct i40e_vsi
*vsi
)
2832 struct i40e_pf
*pf
= vsi
->back
;
2833 struct i40e_q_vector
*q_vector
;
2834 struct i40e_hw
*hw
= &pf
->hw
;
2840 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
2841 * and PFINT_LNKLSTn registers, e.g.:
2842 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
2844 qp
= vsi
->base_queue
;
2845 vector
= vsi
->base_vector
;
2846 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vector
++) {
2847 q_vector
= vsi
->q_vectors
[i
];
2848 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
2849 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
2850 wr32(hw
, I40E_PFINT_ITRN(I40E_RX_ITR
, vector
- 1),
2852 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
2853 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
2854 wr32(hw
, I40E_PFINT_ITRN(I40E_TX_ITR
, vector
- 1),
2857 /* Linked list for the queuepairs assigned to this vector */
2858 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), qp
);
2859 for (q
= 0; q
< q_vector
->num_ringpairs
; q
++) {
2860 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
2861 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
2862 (vector
<< I40E_QINT_RQCTL_MSIX_INDX_SHIFT
) |
2863 (qp
<< I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT
)|
2865 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT
);
2867 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
2869 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
2870 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
2871 (vector
<< I40E_QINT_TQCTL_MSIX_INDX_SHIFT
) |
2872 ((qp
+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
)|
2874 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
2876 /* Terminate the linked list */
2877 if (q
== (q_vector
->num_ringpairs
- 1))
2878 val
|= (I40E_QUEUE_END_OF_LIST
2879 << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
2881 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
2890 * i40e_enable_misc_int_causes - enable the non-queue interrupts
2891 * @hw: ptr to the hardware info
2893 static void i40e_enable_misc_int_causes(struct i40e_pf
*pf
)
2895 struct i40e_hw
*hw
= &pf
->hw
;
2898 /* clear things first */
2899 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0); /* disable all */
2900 rd32(hw
, I40E_PFINT_ICR0
); /* read to clear */
2902 val
= I40E_PFINT_ICR0_ENA_ECC_ERR_MASK
|
2903 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
|
2904 I40E_PFINT_ICR0_ENA_GRST_MASK
|
2905 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK
|
2906 I40E_PFINT_ICR0_ENA_GPIO_MASK
|
2907 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK
|
2908 I40E_PFINT_ICR0_ENA_VFLR_MASK
|
2909 I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
2911 if (pf
->flags
& I40E_FLAG_PTP
)
2912 val
|= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
2914 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
2916 /* SW_ITR_IDX = 0, but don't change INTENA */
2917 wr32(hw
, I40E_PFINT_DYN_CTL0
, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK
|
2918 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK
);
2920 /* OTHER_ITR_IDX = 0 */
2921 wr32(hw
, I40E_PFINT_STAT_CTL0
, 0);
2925 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
2926 * @vsi: the VSI being configured
2928 static void i40e_configure_msi_and_legacy(struct i40e_vsi
*vsi
)
2930 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[0];
2931 struct i40e_pf
*pf
= vsi
->back
;
2932 struct i40e_hw
*hw
= &pf
->hw
;
2935 /* set the ITR configuration */
2936 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
2937 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
2938 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), q_vector
->rx
.itr
);
2939 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
2940 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
2941 wr32(hw
, I40E_PFINT_ITR0(I40E_TX_ITR
), q_vector
->tx
.itr
);
2943 i40e_enable_misc_int_causes(pf
);
2945 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
2946 wr32(hw
, I40E_PFINT_LNKLST0
, 0);
2948 /* Associate the queue pair to the vector and enable the queue int */
2949 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
2950 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
2951 (I40E_QUEUE_TYPE_TX
<< I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
2953 wr32(hw
, I40E_QINT_RQCTL(0), val
);
2955 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
2956 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
2957 (I40E_QUEUE_END_OF_LIST
<< I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
2959 wr32(hw
, I40E_QINT_TQCTL(0), val
);
2964 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
2965 * @pf: board private structure
2967 void i40e_irq_dynamic_disable_icr0(struct i40e_pf
*pf
)
2969 struct i40e_hw
*hw
= &pf
->hw
;
2971 wr32(hw
, I40E_PFINT_DYN_CTL0
,
2972 I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
);
2977 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
2978 * @pf: board private structure
2980 void i40e_irq_dynamic_enable_icr0(struct i40e_pf
*pf
)
2982 struct i40e_hw
*hw
= &pf
->hw
;
2985 val
= I40E_PFINT_DYN_CTL0_INTENA_MASK
|
2986 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK
|
2987 (I40E_ITR_NONE
<< I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT
);
2989 wr32(hw
, I40E_PFINT_DYN_CTL0
, val
);
2994 * i40e_irq_dynamic_enable - Enable default interrupt generation settings
2995 * @vsi: pointer to a vsi
2996 * @vector: enable a particular Hw Interrupt vector
2998 void i40e_irq_dynamic_enable(struct i40e_vsi
*vsi
, int vector
)
3000 struct i40e_pf
*pf
= vsi
->back
;
3001 struct i40e_hw
*hw
= &pf
->hw
;
3004 val
= I40E_PFINT_DYN_CTLN_INTENA_MASK
|
3005 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK
|
3006 (I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
);
3007 wr32(hw
, I40E_PFINT_DYN_CTLN(vector
- 1), val
);
3008 /* skip the flush */
3012 * i40e_irq_dynamic_disable - Disable default interrupt generation settings
3013 * @vsi: pointer to a vsi
3014 * @vector: disable a particular Hw Interrupt vector
3016 void i40e_irq_dynamic_disable(struct i40e_vsi
*vsi
, int vector
)
3018 struct i40e_pf
*pf
= vsi
->back
;
3019 struct i40e_hw
*hw
= &pf
->hw
;
3022 val
= I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
;
3023 wr32(hw
, I40E_PFINT_DYN_CTLN(vector
- 1), val
);
3028 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
3029 * @irq: interrupt number
3030 * @data: pointer to a q_vector
3032 static irqreturn_t
i40e_msix_clean_rings(int irq
, void *data
)
3034 struct i40e_q_vector
*q_vector
= data
;
3036 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
3039 napi_schedule(&q_vector
->napi
);
3045 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3046 * @vsi: the VSI being configured
3047 * @basename: name for the vector
3049 * Allocates MSI-X vectors and requests interrupts from the kernel.
3051 static int i40e_vsi_request_irq_msix(struct i40e_vsi
*vsi
, char *basename
)
3053 int q_vectors
= vsi
->num_q_vectors
;
3054 struct i40e_pf
*pf
= vsi
->back
;
3055 int base
= vsi
->base_vector
;
3060 for (vector
= 0; vector
< q_vectors
; vector
++) {
3061 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[vector
];
3063 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
3064 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3065 "%s-%s-%d", basename
, "TxRx", rx_int_idx
++);
3067 } else if (q_vector
->rx
.ring
) {
3068 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3069 "%s-%s-%d", basename
, "rx", rx_int_idx
++);
3070 } else if (q_vector
->tx
.ring
) {
3071 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3072 "%s-%s-%d", basename
, "tx", tx_int_idx
++);
3074 /* skip this unused q_vector */
3077 err
= request_irq(pf
->msix_entries
[base
+ vector
].vector
,
3083 dev_info(&pf
->pdev
->dev
,
3084 "%s: request_irq failed, error: %d\n",
3086 goto free_queue_irqs
;
3088 /* assign the mask for this irq */
3089 irq_set_affinity_hint(pf
->msix_entries
[base
+ vector
].vector
,
3090 &q_vector
->affinity_mask
);
3093 vsi
->irqs_ready
= true;
3099 irq_set_affinity_hint(pf
->msix_entries
[base
+ vector
].vector
,
3101 free_irq(pf
->msix_entries
[base
+ vector
].vector
,
3102 &(vsi
->q_vectors
[vector
]));
3108 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3109 * @vsi: the VSI being un-configured
3111 static void i40e_vsi_disable_irq(struct i40e_vsi
*vsi
)
3113 struct i40e_pf
*pf
= vsi
->back
;
3114 struct i40e_hw
*hw
= &pf
->hw
;
3115 int base
= vsi
->base_vector
;
3118 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
3119 wr32(hw
, I40E_QINT_TQCTL(vsi
->tx_rings
[i
]->reg_idx
), 0);
3120 wr32(hw
, I40E_QINT_RQCTL(vsi
->rx_rings
[i
]->reg_idx
), 0);
3123 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3124 for (i
= vsi
->base_vector
;
3125 i
< (vsi
->num_q_vectors
+ vsi
->base_vector
); i
++)
3126 wr32(hw
, I40E_PFINT_DYN_CTLN(i
- 1), 0);
3129 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3130 synchronize_irq(pf
->msix_entries
[i
+ base
].vector
);
3132 /* Legacy and MSI mode - this stops all interrupt handling */
3133 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0);
3134 wr32(hw
, I40E_PFINT_DYN_CTL0
, 0);
3136 synchronize_irq(pf
->pdev
->irq
);
3141 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3142 * @vsi: the VSI being configured
3144 static int i40e_vsi_enable_irq(struct i40e_vsi
*vsi
)
3146 struct i40e_pf
*pf
= vsi
->back
;
3149 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3150 for (i
= vsi
->base_vector
;
3151 i
< (vsi
->num_q_vectors
+ vsi
->base_vector
); i
++)
3152 i40e_irq_dynamic_enable(vsi
, i
);
3154 i40e_irq_dynamic_enable_icr0(pf
);
3157 i40e_flush(&pf
->hw
);
3162 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
3163 * @pf: board private structure
3165 static void i40e_stop_misc_vector(struct i40e_pf
*pf
)
3168 wr32(&pf
->hw
, I40E_PFINT_ICR0_ENA
, 0);
3169 i40e_flush(&pf
->hw
);
3173 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3174 * @irq: interrupt number
3175 * @data: pointer to a q_vector
3177 * This is the handler used for all MSI/Legacy interrupts, and deals
3178 * with both queue and non-queue interrupts. This is also used in
3179 * MSIX mode to handle the non-queue interrupts.
3181 static irqreturn_t
i40e_intr(int irq
, void *data
)
3183 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
3184 struct i40e_hw
*hw
= &pf
->hw
;
3185 irqreturn_t ret
= IRQ_NONE
;
3186 u32 icr0
, icr0_remaining
;
3189 icr0
= rd32(hw
, I40E_PFINT_ICR0
);
3190 ena_mask
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
3192 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
3193 if ((icr0
& I40E_PFINT_ICR0_INTEVENT_MASK
) == 0)
3196 /* if interrupt but no bits showing, must be SWINT */
3197 if (((icr0
& ~I40E_PFINT_ICR0_INTEVENT_MASK
) == 0) ||
3198 (icr0
& I40E_PFINT_ICR0_SWINT_MASK
))
3201 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
3202 if (icr0
& I40E_PFINT_ICR0_QUEUE_0_MASK
) {
3204 /* temporarily disable queue cause for NAPI processing */
3205 u32 qval
= rd32(hw
, I40E_QINT_RQCTL(0));
3206 qval
&= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK
;
3207 wr32(hw
, I40E_QINT_RQCTL(0), qval
);
3209 qval
= rd32(hw
, I40E_QINT_TQCTL(0));
3210 qval
&= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK
;
3211 wr32(hw
, I40E_QINT_TQCTL(0), qval
);
3213 if (!test_bit(__I40E_DOWN
, &pf
->state
))
3214 napi_schedule(&pf
->vsi
[pf
->lan_vsi
]->q_vectors
[0]->napi
);
3217 if (icr0
& I40E_PFINT_ICR0_ADMINQ_MASK
) {
3218 ena_mask
&= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
3219 set_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
);
3222 if (icr0
& I40E_PFINT_ICR0_MAL_DETECT_MASK
) {
3223 ena_mask
&= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
3224 set_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
);
3227 if (icr0
& I40E_PFINT_ICR0_VFLR_MASK
) {
3228 ena_mask
&= ~I40E_PFINT_ICR0_ENA_VFLR_MASK
;
3229 set_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
);
3232 if (icr0
& I40E_PFINT_ICR0_GRST_MASK
) {
3233 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
))
3234 set_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
);
3235 ena_mask
&= ~I40E_PFINT_ICR0_ENA_GRST_MASK
;
3236 val
= rd32(hw
, I40E_GLGEN_RSTAT
);
3237 val
= (val
& I40E_GLGEN_RSTAT_RESET_TYPE_MASK
)
3238 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT
;
3239 if (val
== I40E_RESET_CORER
) {
3241 } else if (val
== I40E_RESET_GLOBR
) {
3243 } else if (val
== I40E_RESET_EMPR
) {
3245 set_bit(__I40E_EMP_RESET_INTR_RECEIVED
, &pf
->state
);
3249 if (icr0
& I40E_PFINT_ICR0_HMC_ERR_MASK
) {
3250 icr0
&= ~I40E_PFINT_ICR0_HMC_ERR_MASK
;
3251 dev_info(&pf
->pdev
->dev
, "HMC error interrupt\n");
3252 dev_info(&pf
->pdev
->dev
, "HMC error info 0x%x, HMC error data 0x%x\n",
3253 rd32(hw
, I40E_PFHMC_ERRORINFO
),
3254 rd32(hw
, I40E_PFHMC_ERRORDATA
));
3257 if (icr0
& I40E_PFINT_ICR0_TIMESYNC_MASK
) {
3258 u32 prttsyn_stat
= rd32(hw
, I40E_PRTTSYN_STAT_0
);
3260 if (prttsyn_stat
& I40E_PRTTSYN_STAT_0_TXTIME_MASK
) {
3261 icr0
&= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
3262 i40e_ptp_tx_hwtstamp(pf
);
3266 /* If a critical error is pending we have no choice but to reset the
3268 * Report and mask out any remaining unexpected interrupts.
3270 icr0_remaining
= icr0
& ena_mask
;
3271 if (icr0_remaining
) {
3272 dev_info(&pf
->pdev
->dev
, "unhandled interrupt icr0=0x%08x\n",
3274 if ((icr0_remaining
& I40E_PFINT_ICR0_PE_CRITERR_MASK
) ||
3275 (icr0_remaining
& I40E_PFINT_ICR0_PCI_EXCEPTION_MASK
) ||
3276 (icr0_remaining
& I40E_PFINT_ICR0_ECC_ERR_MASK
)) {
3277 dev_info(&pf
->pdev
->dev
, "device will be reset\n");
3278 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
3279 i40e_service_event_schedule(pf
);
3281 ena_mask
&= ~icr0_remaining
;
3286 /* re-enable interrupt causes */
3287 wr32(hw
, I40E_PFINT_ICR0_ENA
, ena_mask
);
3288 if (!test_bit(__I40E_DOWN
, &pf
->state
)) {
3289 i40e_service_event_schedule(pf
);
3290 i40e_irq_dynamic_enable_icr0(pf
);
3297 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3298 * @tx_ring: tx ring to clean
3299 * @budget: how many cleans we're allowed
3301 * Returns true if there's any budget left (e.g. the clean is finished)
3303 static bool i40e_clean_fdir_tx_irq(struct i40e_ring
*tx_ring
, int budget
)
3305 struct i40e_vsi
*vsi
= tx_ring
->vsi
;
3306 u16 i
= tx_ring
->next_to_clean
;
3307 struct i40e_tx_buffer
*tx_buf
;
3308 struct i40e_tx_desc
*tx_desc
;
3310 tx_buf
= &tx_ring
->tx_bi
[i
];
3311 tx_desc
= I40E_TX_DESC(tx_ring
, i
);
3312 i
-= tx_ring
->count
;
3315 struct i40e_tx_desc
*eop_desc
= tx_buf
->next_to_watch
;
3317 /* if next_to_watch is not set then there is no work pending */
3321 /* prevent any other reads prior to eop_desc */
3322 read_barrier_depends();
3324 /* if the descriptor isn't done, no work yet to do */
3325 if (!(eop_desc
->cmd_type_offset_bsz
&
3326 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE
)))
3329 /* clear next_to_watch to prevent false hangs */
3330 tx_buf
->next_to_watch
= NULL
;
3332 tx_desc
->buffer_addr
= 0;
3333 tx_desc
->cmd_type_offset_bsz
= 0;
3334 /* move past filter desc */
3339 i
-= tx_ring
->count
;
3340 tx_buf
= tx_ring
->tx_bi
;
3341 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
3343 /* unmap skb header data */
3344 dma_unmap_single(tx_ring
->dev
,
3345 dma_unmap_addr(tx_buf
, dma
),
3346 dma_unmap_len(tx_buf
, len
),
3348 if (tx_buf
->tx_flags
& I40E_TX_FLAGS_FD_SB
)
3349 kfree(tx_buf
->raw_buf
);
3351 tx_buf
->raw_buf
= NULL
;
3352 tx_buf
->tx_flags
= 0;
3353 tx_buf
->next_to_watch
= NULL
;
3354 dma_unmap_len_set(tx_buf
, len
, 0);
3355 tx_desc
->buffer_addr
= 0;
3356 tx_desc
->cmd_type_offset_bsz
= 0;
3358 /* move us past the eop_desc for start of next FD desc */
3363 i
-= tx_ring
->count
;
3364 tx_buf
= tx_ring
->tx_bi
;
3365 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
3368 /* update budget accounting */
3370 } while (likely(budget
));
3372 i
+= tx_ring
->count
;
3373 tx_ring
->next_to_clean
= i
;
3375 if (vsi
->back
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3376 i40e_irq_dynamic_enable(vsi
,
3377 tx_ring
->q_vector
->v_idx
+ vsi
->base_vector
);
3383 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
3384 * @irq: interrupt number
3385 * @data: pointer to a q_vector
3387 static irqreturn_t
i40e_fdir_clean_ring(int irq
, void *data
)
3389 struct i40e_q_vector
*q_vector
= data
;
3390 struct i40e_vsi
*vsi
;
3392 if (!q_vector
->tx
.ring
)
3395 vsi
= q_vector
->tx
.ring
->vsi
;
3396 i40e_clean_fdir_tx_irq(q_vector
->tx
.ring
, vsi
->work_limit
);
3402 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
3403 * @vsi: the VSI being configured
3404 * @v_idx: vector index
3405 * @qp_idx: queue pair index
3407 static void map_vector_to_qp(struct i40e_vsi
*vsi
, int v_idx
, int qp_idx
)
3409 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
3410 struct i40e_ring
*tx_ring
= vsi
->tx_rings
[qp_idx
];
3411 struct i40e_ring
*rx_ring
= vsi
->rx_rings
[qp_idx
];
3413 tx_ring
->q_vector
= q_vector
;
3414 tx_ring
->next
= q_vector
->tx
.ring
;
3415 q_vector
->tx
.ring
= tx_ring
;
3416 q_vector
->tx
.count
++;
3418 rx_ring
->q_vector
= q_vector
;
3419 rx_ring
->next
= q_vector
->rx
.ring
;
3420 q_vector
->rx
.ring
= rx_ring
;
3421 q_vector
->rx
.count
++;
3425 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
3426 * @vsi: the VSI being configured
3428 * This function maps descriptor rings to the queue-specific vectors
3429 * we were allotted through the MSI-X enabling code. Ideally, we'd have
3430 * one vector per queue pair, but on a constrained vector budget, we
3431 * group the queue pairs as "efficiently" as possible.
3433 static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi
*vsi
)
3435 int qp_remaining
= vsi
->num_queue_pairs
;
3436 int q_vectors
= vsi
->num_q_vectors
;
3441 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
3442 * group them so there are multiple queues per vector.
3443 * It is also important to go through all the vectors available to be
3444 * sure that if we don't use all the vectors, that the remaining vectors
3445 * are cleared. This is especially important when decreasing the
3446 * number of queues in use.
3448 for (; v_start
< q_vectors
; v_start
++) {
3449 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_start
];
3451 num_ringpairs
= DIV_ROUND_UP(qp_remaining
, q_vectors
- v_start
);
3453 q_vector
->num_ringpairs
= num_ringpairs
;
3455 q_vector
->rx
.count
= 0;
3456 q_vector
->tx
.count
= 0;
3457 q_vector
->rx
.ring
= NULL
;
3458 q_vector
->tx
.ring
= NULL
;
3460 while (num_ringpairs
--) {
3461 map_vector_to_qp(vsi
, v_start
, qp_idx
);
3469 * i40e_vsi_request_irq - Request IRQ from the OS
3470 * @vsi: the VSI being configured
3471 * @basename: name for the vector
3473 static int i40e_vsi_request_irq(struct i40e_vsi
*vsi
, char *basename
)
3475 struct i40e_pf
*pf
= vsi
->back
;
3478 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
3479 err
= i40e_vsi_request_irq_msix(vsi
, basename
);
3480 else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
)
3481 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, 0,
3484 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, IRQF_SHARED
,
3488 dev_info(&pf
->pdev
->dev
, "request_irq failed, Error %d\n", err
);
3493 #ifdef CONFIG_NET_POLL_CONTROLLER
3495 * i40e_netpoll - A Polling 'interrupt'handler
3496 * @netdev: network interface device structure
3498 * This is used by netconsole to send skbs without having to re-enable
3499 * interrupts. It's not called while the normal interrupt routine is executing.
3502 void i40e_netpoll(struct net_device
*netdev
)
3504 static void i40e_netpoll(struct net_device
*netdev
)
3507 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3508 struct i40e_vsi
*vsi
= np
->vsi
;
3509 struct i40e_pf
*pf
= vsi
->back
;
3512 /* if interface is down do nothing */
3513 if (test_bit(__I40E_DOWN
, &vsi
->state
))
3516 pf
->flags
|= I40E_FLAG_IN_NETPOLL
;
3517 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3518 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3519 i40e_msix_clean_rings(0, vsi
->q_vectors
[i
]);
3521 i40e_intr(pf
->pdev
->irq
, netdev
);
3523 pf
->flags
&= ~I40E_FLAG_IN_NETPOLL
;
3528 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
3529 * @pf: the PF being configured
3530 * @pf_q: the PF queue
3531 * @enable: enable or disable state of the queue
3533 * This routine will wait for the given Tx queue of the PF to reach the
3534 * enabled or disabled state.
3535 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3536 * multiple retries; else will return 0 in case of success.
3538 static int i40e_pf_txq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
3543 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
3544 tx_reg
= rd32(&pf
->hw
, I40E_QTX_ENA(pf_q
));
3545 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
3548 usleep_range(10, 20);
3550 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
3557 * i40e_vsi_control_tx - Start or stop a VSI's rings
3558 * @vsi: the VSI being configured
3559 * @enable: start or stop the rings
3561 static int i40e_vsi_control_tx(struct i40e_vsi
*vsi
, bool enable
)
3563 struct i40e_pf
*pf
= vsi
->back
;
3564 struct i40e_hw
*hw
= &pf
->hw
;
3565 int i
, j
, pf_q
, ret
= 0;
3568 pf_q
= vsi
->base_queue
;
3569 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
3571 /* warn the TX unit of coming changes */
3572 i40e_pre_tx_queue_cfg(&pf
->hw
, pf_q
, enable
);
3574 usleep_range(10, 20);
3576 for (j
= 0; j
< 50; j
++) {
3577 tx_reg
= rd32(hw
, I40E_QTX_ENA(pf_q
));
3578 if (((tx_reg
>> I40E_QTX_ENA_QENA_REQ_SHIFT
) & 1) ==
3579 ((tx_reg
>> I40E_QTX_ENA_QENA_STAT_SHIFT
) & 1))
3581 usleep_range(1000, 2000);
3583 /* Skip if the queue is already in the requested state */
3584 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
3587 /* turn on/off the queue */
3589 wr32(hw
, I40E_QTX_HEAD(pf_q
), 0);
3590 tx_reg
|= I40E_QTX_ENA_QENA_REQ_MASK
;
3592 tx_reg
&= ~I40E_QTX_ENA_QENA_REQ_MASK
;
3595 wr32(hw
, I40E_QTX_ENA(pf_q
), tx_reg
);
3596 /* No waiting for the Tx queue to disable */
3597 if (!enable
&& test_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
))
3600 /* wait for the change to finish */
3601 ret
= i40e_pf_txq_wait(pf
, pf_q
, enable
);
3603 dev_info(&pf
->pdev
->dev
,
3604 "%s: VSI seid %d Tx ring %d %sable timeout\n",
3605 __func__
, vsi
->seid
, pf_q
,
3606 (enable
? "en" : "dis"));
3611 if (hw
->revision_id
== 0)
3617 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
3618 * @pf: the PF being configured
3619 * @pf_q: the PF queue
3620 * @enable: enable or disable state of the queue
3622 * This routine will wait for the given Rx queue of the PF to reach the
3623 * enabled or disabled state.
3624 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3625 * multiple retries; else will return 0 in case of success.
3627 static int i40e_pf_rxq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
3632 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
3633 rx_reg
= rd32(&pf
->hw
, I40E_QRX_ENA(pf_q
));
3634 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
3637 usleep_range(10, 20);
3639 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
3646 * i40e_vsi_control_rx - Start or stop a VSI's rings
3647 * @vsi: the VSI being configured
3648 * @enable: start or stop the rings
3650 static int i40e_vsi_control_rx(struct i40e_vsi
*vsi
, bool enable
)
3652 struct i40e_pf
*pf
= vsi
->back
;
3653 struct i40e_hw
*hw
= &pf
->hw
;
3654 int i
, j
, pf_q
, ret
= 0;
3657 pf_q
= vsi
->base_queue
;
3658 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
3659 for (j
= 0; j
< 50; j
++) {
3660 rx_reg
= rd32(hw
, I40E_QRX_ENA(pf_q
));
3661 if (((rx_reg
>> I40E_QRX_ENA_QENA_REQ_SHIFT
) & 1) ==
3662 ((rx_reg
>> I40E_QRX_ENA_QENA_STAT_SHIFT
) & 1))
3664 usleep_range(1000, 2000);
3667 /* Skip if the queue is already in the requested state */
3668 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
3671 /* turn on/off the queue */
3673 rx_reg
|= I40E_QRX_ENA_QENA_REQ_MASK
;
3675 rx_reg
&= ~I40E_QRX_ENA_QENA_REQ_MASK
;
3676 wr32(hw
, I40E_QRX_ENA(pf_q
), rx_reg
);
3678 /* wait for the change to finish */
3679 ret
= i40e_pf_rxq_wait(pf
, pf_q
, enable
);
3681 dev_info(&pf
->pdev
->dev
,
3682 "%s: VSI seid %d Rx ring %d %sable timeout\n",
3683 __func__
, vsi
->seid
, pf_q
,
3684 (enable
? "en" : "dis"));
3693 * i40e_vsi_control_rings - Start or stop a VSI's rings
3694 * @vsi: the VSI being configured
3695 * @enable: start or stop the rings
3697 int i40e_vsi_control_rings(struct i40e_vsi
*vsi
, bool request
)
3701 /* do rx first for enable and last for disable */
3703 ret
= i40e_vsi_control_rx(vsi
, request
);
3706 ret
= i40e_vsi_control_tx(vsi
, request
);
3708 /* Ignore return value, we need to shutdown whatever we can */
3709 i40e_vsi_control_tx(vsi
, request
);
3710 i40e_vsi_control_rx(vsi
, request
);
3717 * i40e_vsi_free_irq - Free the irq association with the OS
3718 * @vsi: the VSI being configured
3720 static void i40e_vsi_free_irq(struct i40e_vsi
*vsi
)
3722 struct i40e_pf
*pf
= vsi
->back
;
3723 struct i40e_hw
*hw
= &pf
->hw
;
3724 int base
= vsi
->base_vector
;
3728 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3729 if (!vsi
->q_vectors
)
3732 if (!vsi
->irqs_ready
)
3735 vsi
->irqs_ready
= false;
3736 for (i
= 0; i
< vsi
->num_q_vectors
; i
++) {
3737 u16 vector
= i
+ base
;
3739 /* free only the irqs that were actually requested */
3740 if (!vsi
->q_vectors
[i
] ||
3741 !vsi
->q_vectors
[i
]->num_ringpairs
)
3744 /* clear the affinity_mask in the IRQ descriptor */
3745 irq_set_affinity_hint(pf
->msix_entries
[vector
].vector
,
3747 free_irq(pf
->msix_entries
[vector
].vector
,
3750 /* Tear down the interrupt queue link list
3752 * We know that they come in pairs and always
3753 * the Rx first, then the Tx. To clear the
3754 * link list, stick the EOL value into the
3755 * next_q field of the registers.
3757 val
= rd32(hw
, I40E_PFINT_LNKLSTN(vector
- 1));
3758 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
3759 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
3760 val
|= I40E_QUEUE_END_OF_LIST
3761 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
3762 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), val
);
3764 while (qp
!= I40E_QUEUE_END_OF_LIST
) {
3767 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
3769 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
3770 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
3771 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3772 I40E_QINT_RQCTL_INTEVENT_MASK
);
3774 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
3775 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
3777 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
3779 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
3781 next
= (val
& I40E_QINT_TQCTL_NEXTQ_INDX_MASK
)
3782 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
;
3784 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
3785 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
3786 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3787 I40E_QINT_TQCTL_INTEVENT_MASK
);
3789 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
3790 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
3792 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
3797 free_irq(pf
->pdev
->irq
, pf
);
3799 val
= rd32(hw
, I40E_PFINT_LNKLST0
);
3800 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
3801 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
3802 val
|= I40E_QUEUE_END_OF_LIST
3803 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT
;
3804 wr32(hw
, I40E_PFINT_LNKLST0
, val
);
3806 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
3807 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
3808 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
3809 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3810 I40E_QINT_RQCTL_INTEVENT_MASK
);
3812 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
3813 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
3815 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
3817 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
3819 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
3820 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
3821 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3822 I40E_QINT_TQCTL_INTEVENT_MASK
);
3824 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
3825 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
3827 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
3832 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
3833 * @vsi: the VSI being configured
3834 * @v_idx: Index of vector to be freed
3836 * This function frees the memory allocated to the q_vector. In addition if
3837 * NAPI is enabled it will delete any references to the NAPI struct prior
3838 * to freeing the q_vector.
3840 static void i40e_free_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
3842 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
3843 struct i40e_ring
*ring
;
3848 /* disassociate q_vector from rings */
3849 i40e_for_each_ring(ring
, q_vector
->tx
)
3850 ring
->q_vector
= NULL
;
3852 i40e_for_each_ring(ring
, q_vector
->rx
)
3853 ring
->q_vector
= NULL
;
3855 /* only VSI w/ an associated netdev is set up w/ NAPI */
3857 netif_napi_del(&q_vector
->napi
);
3859 vsi
->q_vectors
[v_idx
] = NULL
;
3861 kfree_rcu(q_vector
, rcu
);
3865 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
3866 * @vsi: the VSI being un-configured
3868 * This frees the memory allocated to the q_vectors and
3869 * deletes references to the NAPI struct.
3871 static void i40e_vsi_free_q_vectors(struct i40e_vsi
*vsi
)
3875 for (v_idx
= 0; v_idx
< vsi
->num_q_vectors
; v_idx
++)
3876 i40e_free_q_vector(vsi
, v_idx
);
3880 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
3881 * @pf: board private structure
3883 static void i40e_reset_interrupt_capability(struct i40e_pf
*pf
)
3885 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
3886 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3887 pci_disable_msix(pf
->pdev
);
3888 kfree(pf
->msix_entries
);
3889 pf
->msix_entries
= NULL
;
3890 kfree(pf
->irq_pile
);
3891 pf
->irq_pile
= NULL
;
3892 } else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
) {
3893 pci_disable_msi(pf
->pdev
);
3895 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
);
3899 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
3900 * @pf: board private structure
3902 * We go through and clear interrupt specific resources and reset the structure
3903 * to pre-load conditions
3905 static void i40e_clear_interrupt_scheme(struct i40e_pf
*pf
)
3909 i40e_stop_misc_vector(pf
);
3910 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3911 synchronize_irq(pf
->msix_entries
[0].vector
);
3912 free_irq(pf
->msix_entries
[0].vector
, pf
);
3915 i40e_put_lump(pf
->irq_pile
, 0, I40E_PILE_VALID_BIT
-1);
3916 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
3918 i40e_vsi_free_q_vectors(pf
->vsi
[i
]);
3919 i40e_reset_interrupt_capability(pf
);
3923 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
3924 * @vsi: the VSI being configured
3926 static void i40e_napi_enable_all(struct i40e_vsi
*vsi
)
3933 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++)
3934 napi_enable(&vsi
->q_vectors
[q_idx
]->napi
);
3938 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
3939 * @vsi: the VSI being configured
3941 static void i40e_napi_disable_all(struct i40e_vsi
*vsi
)
3948 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++)
3949 napi_disable(&vsi
->q_vectors
[q_idx
]->napi
);
3953 * i40e_vsi_close - Shut down a VSI
3954 * @vsi: the vsi to be quelled
3956 static void i40e_vsi_close(struct i40e_vsi
*vsi
)
3958 if (!test_and_set_bit(__I40E_DOWN
, &vsi
->state
))
3960 i40e_vsi_free_irq(vsi
);
3961 i40e_vsi_free_tx_resources(vsi
);
3962 i40e_vsi_free_rx_resources(vsi
);
3966 * i40e_quiesce_vsi - Pause a given VSI
3967 * @vsi: the VSI being paused
3969 static void i40e_quiesce_vsi(struct i40e_vsi
*vsi
)
3971 if (test_bit(__I40E_DOWN
, &vsi
->state
))
3974 /* No need to disable FCoE VSI when Tx suspended */
3975 if ((test_bit(__I40E_PORT_TX_SUSPENDED
, &vsi
->back
->state
)) &&
3976 vsi
->type
== I40E_VSI_FCOE
) {
3977 dev_dbg(&vsi
->back
->pdev
->dev
,
3978 "%s: VSI seid %d skipping FCoE VSI disable\n",
3979 __func__
, vsi
->seid
);
3983 set_bit(__I40E_NEEDS_RESTART
, &vsi
->state
);
3984 if (vsi
->netdev
&& netif_running(vsi
->netdev
)) {
3985 vsi
->netdev
->netdev_ops
->ndo_stop(vsi
->netdev
);
3987 i40e_vsi_close(vsi
);
3992 * i40e_unquiesce_vsi - Resume a given VSI
3993 * @vsi: the VSI being resumed
3995 static void i40e_unquiesce_vsi(struct i40e_vsi
*vsi
)
3997 if (!test_bit(__I40E_NEEDS_RESTART
, &vsi
->state
))
4000 clear_bit(__I40E_NEEDS_RESTART
, &vsi
->state
);
4001 if (vsi
->netdev
&& netif_running(vsi
->netdev
))
4002 vsi
->netdev
->netdev_ops
->ndo_open(vsi
->netdev
);
4004 i40e_vsi_open(vsi
); /* this clears the DOWN bit */
4008 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
4011 static void i40e_pf_quiesce_all_vsi(struct i40e_pf
*pf
)
4015 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4017 i40e_quiesce_vsi(pf
->vsi
[v
]);
4022 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
4025 static void i40e_pf_unquiesce_all_vsi(struct i40e_pf
*pf
)
4029 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4031 i40e_unquiesce_vsi(pf
->vsi
[v
]);
4035 #ifdef CONFIG_I40E_DCB
4037 * i40e_vsi_wait_txq_disabled - Wait for VSI's queues to be disabled
4038 * @vsi: the VSI being configured
4040 * This function waits for the given VSI's Tx queues to be disabled.
4042 static int i40e_vsi_wait_txq_disabled(struct i40e_vsi
*vsi
)
4044 struct i40e_pf
*pf
= vsi
->back
;
4047 pf_q
= vsi
->base_queue
;
4048 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
4049 /* Check and wait for the disable status of the queue */
4050 ret
= i40e_pf_txq_wait(pf
, pf_q
, false);
4052 dev_info(&pf
->pdev
->dev
,
4053 "%s: VSI seid %d Tx ring %d disable timeout\n",
4054 __func__
, vsi
->seid
, pf_q
);
4063 * i40e_pf_wait_txq_disabled - Wait for all queues of PF VSIs to be disabled
4066 * This function waits for the Tx queues to be in disabled state for all the
4067 * VSIs that are managed by this PF.
4069 static int i40e_pf_wait_txq_disabled(struct i40e_pf
*pf
)
4073 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
; v
++) {
4074 /* No need to wait for FCoE VSI queues */
4075 if (pf
->vsi
[v
] && pf
->vsi
[v
]->type
!= I40E_VSI_FCOE
) {
4076 ret
= i40e_vsi_wait_txq_disabled(pf
->vsi
[v
]);
4087 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
4088 * @pf: pointer to PF
4090 * Get TC map for ISCSI PF type that will include iSCSI TC
4093 static u8
i40e_get_iscsi_tc_map(struct i40e_pf
*pf
)
4095 struct i40e_dcb_app_priority_table app
;
4096 struct i40e_hw
*hw
= &pf
->hw
;
4097 u8 enabled_tc
= 1; /* TC0 is always enabled */
4099 /* Get the iSCSI APP TLV */
4100 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4102 for (i
= 0; i
< dcbcfg
->numapps
; i
++) {
4103 app
= dcbcfg
->app
[i
];
4104 if (app
.selector
== I40E_APP_SEL_TCPIP
&&
4105 app
.protocolid
== I40E_APP_PROTOID_ISCSI
) {
4106 tc
= dcbcfg
->etscfg
.prioritytable
[app
.priority
];
4107 enabled_tc
|= BIT_ULL(tc
);
4116 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
4117 * @dcbcfg: the corresponding DCBx configuration structure
4119 * Return the number of TCs from given DCBx configuration
4121 static u8
i40e_dcb_get_num_tc(struct i40e_dcbx_config
*dcbcfg
)
4126 /* Scan the ETS Config Priority Table to find
4127 * traffic class enabled for a given priority
4128 * and use the traffic class index to get the
4129 * number of traffic classes enabled
4131 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
4132 if (dcbcfg
->etscfg
.prioritytable
[i
] > num_tc
)
4133 num_tc
= dcbcfg
->etscfg
.prioritytable
[i
];
4136 /* Traffic class index starts from zero so
4137 * increment to return the actual count
4143 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
4144 * @dcbcfg: the corresponding DCBx configuration structure
4146 * Query the current DCB configuration and return the number of
4147 * traffic classes enabled from the given DCBX config
4149 static u8
i40e_dcb_get_enabled_tc(struct i40e_dcbx_config
*dcbcfg
)
4151 u8 num_tc
= i40e_dcb_get_num_tc(dcbcfg
);
4155 for (i
= 0; i
< num_tc
; i
++)
4156 enabled_tc
|= BIT(i
);
4162 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
4163 * @pf: PF being queried
4165 * Return number of traffic classes enabled for the given PF
4167 static u8
i40e_pf_get_num_tc(struct i40e_pf
*pf
)
4169 struct i40e_hw
*hw
= &pf
->hw
;
4172 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4174 /* If DCB is not enabled then always in single TC */
4175 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
4178 /* SFP mode will be enabled for all TCs on port */
4179 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
4180 return i40e_dcb_get_num_tc(dcbcfg
);
4182 /* MFP mode return count of enabled TCs for this PF */
4183 if (pf
->hw
.func_caps
.iscsi
)
4184 enabled_tc
= i40e_get_iscsi_tc_map(pf
);
4186 return 1; /* Only TC0 */
4188 /* At least have TC0 */
4189 enabled_tc
= (enabled_tc
? enabled_tc
: 0x1);
4190 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4191 if (enabled_tc
& BIT_ULL(i
))
4198 * i40e_pf_get_default_tc - Get bitmap for first enabled TC
4199 * @pf: PF being queried
4201 * Return a bitmap for first enabled traffic class for this PF.
4203 static u8
i40e_pf_get_default_tc(struct i40e_pf
*pf
)
4205 u8 enabled_tc
= pf
->hw
.func_caps
.enabled_tcmap
;
4209 return 0x1; /* TC0 */
4211 /* Find the first enabled TC */
4212 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4213 if (enabled_tc
& BIT_ULL(i
))
4221 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
4222 * @pf: PF being queried
4224 * Return a bitmap for enabled traffic classes for this PF.
4226 static u8
i40e_pf_get_tc_map(struct i40e_pf
*pf
)
4228 /* If DCB is not enabled for this PF then just return default TC */
4229 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
4230 return i40e_pf_get_default_tc(pf
);
4232 /* SFP mode we want PF to be enabled for all TCs */
4233 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
4234 return i40e_dcb_get_enabled_tc(&pf
->hw
.local_dcbx_config
);
4236 /* MFP enabled and iSCSI PF type */
4237 if (pf
->hw
.func_caps
.iscsi
)
4238 return i40e_get_iscsi_tc_map(pf
);
4240 return i40e_pf_get_default_tc(pf
);
4244 * i40e_vsi_get_bw_info - Query VSI BW Information
4245 * @vsi: the VSI being queried
4247 * Returns 0 on success, negative value on failure
4249 static int i40e_vsi_get_bw_info(struct i40e_vsi
*vsi
)
4251 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config
= {0};
4252 struct i40e_aqc_query_vsi_bw_config_resp bw_config
= {0};
4253 struct i40e_pf
*pf
= vsi
->back
;
4254 struct i40e_hw
*hw
= &pf
->hw
;
4259 /* Get the VSI level BW configuration */
4260 ret
= i40e_aq_query_vsi_bw_config(hw
, vsi
->seid
, &bw_config
, NULL
);
4262 dev_info(&pf
->pdev
->dev
,
4263 "couldn't get PF vsi bw config, err %s aq_err %s\n",
4264 i40e_stat_str(&pf
->hw
, ret
),
4265 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4269 /* Get the VSI level BW configuration per TC */
4270 ret
= i40e_aq_query_vsi_ets_sla_config(hw
, vsi
->seid
, &bw_ets_config
,
4273 dev_info(&pf
->pdev
->dev
,
4274 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
4275 i40e_stat_str(&pf
->hw
, ret
),
4276 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4280 if (bw_config
.tc_valid_bits
!= bw_ets_config
.tc_valid_bits
) {
4281 dev_info(&pf
->pdev
->dev
,
4282 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
4283 bw_config
.tc_valid_bits
,
4284 bw_ets_config
.tc_valid_bits
);
4285 /* Still continuing */
4288 vsi
->bw_limit
= le16_to_cpu(bw_config
.port_bw_limit
);
4289 vsi
->bw_max_quanta
= bw_config
.max_bw
;
4290 tc_bw_max
= le16_to_cpu(bw_ets_config
.tc_bw_max
[0]) |
4291 (le16_to_cpu(bw_ets_config
.tc_bw_max
[1]) << 16);
4292 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4293 vsi
->bw_ets_share_credits
[i
] = bw_ets_config
.share_credits
[i
];
4294 vsi
->bw_ets_limit_credits
[i
] =
4295 le16_to_cpu(bw_ets_config
.credits
[i
]);
4296 /* 3 bits out of 4 for each TC */
4297 vsi
->bw_ets_max_quanta
[i
] = (u8
)((tc_bw_max
>> (i
*4)) & 0x7);
4304 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
4305 * @vsi: the VSI being configured
4306 * @enabled_tc: TC bitmap
4307 * @bw_credits: BW shared credits per TC
4309 * Returns 0 on success, negative value on failure
4311 static int i40e_vsi_configure_bw_alloc(struct i40e_vsi
*vsi
, u8 enabled_tc
,
4314 struct i40e_aqc_configure_vsi_tc_bw_data bw_data
;
4318 bw_data
.tc_valid_bits
= enabled_tc
;
4319 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
4320 bw_data
.tc_bw_credits
[i
] = bw_share
[i
];
4322 ret
= i40e_aq_config_vsi_tc_bw(&vsi
->back
->hw
, vsi
->seid
, &bw_data
,
4325 dev_info(&vsi
->back
->pdev
->dev
,
4326 "AQ command Config VSI BW allocation per TC failed = %d\n",
4327 vsi
->back
->hw
.aq
.asq_last_status
);
4331 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
4332 vsi
->info
.qs_handle
[i
] = bw_data
.qs_handles
[i
];
4338 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
4339 * @vsi: the VSI being configured
4340 * @enabled_tc: TC map to be enabled
4343 static void i40e_vsi_config_netdev_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
4345 struct net_device
*netdev
= vsi
->netdev
;
4346 struct i40e_pf
*pf
= vsi
->back
;
4347 struct i40e_hw
*hw
= &pf
->hw
;
4350 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4356 netdev_reset_tc(netdev
);
4360 /* Set up actual enabled TCs on the VSI */
4361 if (netdev_set_num_tc(netdev
, vsi
->tc_config
.numtc
))
4364 /* set per TC queues for the VSI */
4365 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4366 /* Only set TC queues for enabled tcs
4368 * e.g. For a VSI that has TC0 and TC3 enabled the
4369 * enabled_tc bitmap would be 0x00001001; the driver
4370 * will set the numtc for netdev as 2 that will be
4371 * referenced by the netdev layer as TC 0 and 1.
4373 if (vsi
->tc_config
.enabled_tc
& BIT_ULL(i
))
4374 netdev_set_tc_queue(netdev
,
4375 vsi
->tc_config
.tc_info
[i
].netdev_tc
,
4376 vsi
->tc_config
.tc_info
[i
].qcount
,
4377 vsi
->tc_config
.tc_info
[i
].qoffset
);
4380 /* Assign UP2TC map for the VSI */
4381 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
4382 /* Get the actual TC# for the UP */
4383 u8 ets_tc
= dcbcfg
->etscfg
.prioritytable
[i
];
4384 /* Get the mapped netdev TC# for the UP */
4385 netdev_tc
= vsi
->tc_config
.tc_info
[ets_tc
].netdev_tc
;
4386 netdev_set_prio_tc_map(netdev
, i
, netdev_tc
);
4391 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
4392 * @vsi: the VSI being configured
4393 * @ctxt: the ctxt buffer returned from AQ VSI update param command
4395 static void i40e_vsi_update_queue_map(struct i40e_vsi
*vsi
,
4396 struct i40e_vsi_context
*ctxt
)
4398 /* copy just the sections touched not the entire info
4399 * since not all sections are valid as returned by
4402 vsi
->info
.mapping_flags
= ctxt
->info
.mapping_flags
;
4403 memcpy(&vsi
->info
.queue_mapping
,
4404 &ctxt
->info
.queue_mapping
, sizeof(vsi
->info
.queue_mapping
));
4405 memcpy(&vsi
->info
.tc_mapping
, ctxt
->info
.tc_mapping
,
4406 sizeof(vsi
->info
.tc_mapping
));
4410 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
4411 * @vsi: VSI to be configured
4412 * @enabled_tc: TC bitmap
4414 * This configures a particular VSI for TCs that are mapped to the
4415 * given TC bitmap. It uses default bandwidth share for TCs across
4416 * VSIs to configure TC for a particular VSI.
4419 * It is expected that the VSI queues have been quisced before calling
4422 static int i40e_vsi_config_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
4424 u8 bw_share
[I40E_MAX_TRAFFIC_CLASS
] = {0};
4425 struct i40e_vsi_context ctxt
;
4429 /* Check if enabled_tc is same as existing or new TCs */
4430 if (vsi
->tc_config
.enabled_tc
== enabled_tc
)
4433 /* Enable ETS TCs with equal BW Share for now across all VSIs */
4434 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4435 if (enabled_tc
& BIT_ULL(i
))
4439 ret
= i40e_vsi_configure_bw_alloc(vsi
, enabled_tc
, bw_share
);
4441 dev_info(&vsi
->back
->pdev
->dev
,
4442 "Failed configuring TC map %d for VSI %d\n",
4443 enabled_tc
, vsi
->seid
);
4447 /* Update Queue Pairs Mapping for currently enabled UPs */
4448 ctxt
.seid
= vsi
->seid
;
4449 ctxt
.pf_num
= vsi
->back
->hw
.pf_id
;
4451 ctxt
.uplink_seid
= vsi
->uplink_seid
;
4452 ctxt
.info
= vsi
->info
;
4453 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
4455 /* Update the VSI after updating the VSI queue-mapping information */
4456 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
4458 dev_info(&vsi
->back
->pdev
->dev
,
4459 "Update vsi tc config failed, err %s aq_err %s\n",
4460 i40e_stat_str(&vsi
->back
->hw
, ret
),
4461 i40e_aq_str(&vsi
->back
->hw
,
4462 vsi
->back
->hw
.aq
.asq_last_status
));
4465 /* update the local VSI info with updated queue map */
4466 i40e_vsi_update_queue_map(vsi
, &ctxt
);
4467 vsi
->info
.valid_sections
= 0;
4469 /* Update current VSI BW information */
4470 ret
= i40e_vsi_get_bw_info(vsi
);
4472 dev_info(&vsi
->back
->pdev
->dev
,
4473 "Failed updating vsi bw info, err %s aq_err %s\n",
4474 i40e_stat_str(&vsi
->back
->hw
, ret
),
4475 i40e_aq_str(&vsi
->back
->hw
,
4476 vsi
->back
->hw
.aq
.asq_last_status
));
4480 /* Update the netdev TC setup */
4481 i40e_vsi_config_netdev_tc(vsi
, enabled_tc
);
4487 * i40e_veb_config_tc - Configure TCs for given VEB
4489 * @enabled_tc: TC bitmap
4491 * Configures given TC bitmap for VEB (switching) element
4493 int i40e_veb_config_tc(struct i40e_veb
*veb
, u8 enabled_tc
)
4495 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data
= {0};
4496 struct i40e_pf
*pf
= veb
->pf
;
4500 /* No TCs or already enabled TCs just return */
4501 if (!enabled_tc
|| veb
->enabled_tc
== enabled_tc
)
4504 bw_data
.tc_valid_bits
= enabled_tc
;
4505 /* bw_data.absolute_credits is not set (relative) */
4507 /* Enable ETS TCs with equal BW Share for now */
4508 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4509 if (enabled_tc
& BIT_ULL(i
))
4510 bw_data
.tc_bw_share_credits
[i
] = 1;
4513 ret
= i40e_aq_config_switch_comp_bw_config(&pf
->hw
, veb
->seid
,
4516 dev_info(&pf
->pdev
->dev
,
4517 "VEB bw config failed, err %s aq_err %s\n",
4518 i40e_stat_str(&pf
->hw
, ret
),
4519 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4523 /* Update the BW information */
4524 ret
= i40e_veb_get_bw_info(veb
);
4526 dev_info(&pf
->pdev
->dev
,
4527 "Failed getting veb bw config, err %s aq_err %s\n",
4528 i40e_stat_str(&pf
->hw
, ret
),
4529 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4536 #ifdef CONFIG_I40E_DCB
4538 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
4541 * Reconfigure VEB/VSIs on a given PF; it is assumed that
4542 * the caller would've quiesce all the VSIs before calling
4545 static void i40e_dcb_reconfigure(struct i40e_pf
*pf
)
4551 /* Enable the TCs available on PF to all VEBs */
4552 tc_map
= i40e_pf_get_tc_map(pf
);
4553 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
4556 ret
= i40e_veb_config_tc(pf
->veb
[v
], tc_map
);
4558 dev_info(&pf
->pdev
->dev
,
4559 "Failed configuring TC for VEB seid=%d\n",
4561 /* Will try to configure as many components */
4565 /* Update each VSI */
4566 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4570 /* - Enable all TCs for the LAN VSI
4572 * - For FCoE VSI only enable the TC configured
4573 * as per the APP TLV
4575 * - For all others keep them at TC0 for now
4577 if (v
== pf
->lan_vsi
)
4578 tc_map
= i40e_pf_get_tc_map(pf
);
4580 tc_map
= i40e_pf_get_default_tc(pf
);
4582 if (pf
->vsi
[v
]->type
== I40E_VSI_FCOE
)
4583 tc_map
= i40e_get_fcoe_tc_map(pf
);
4584 #endif /* #ifdef I40E_FCOE */
4586 ret
= i40e_vsi_config_tc(pf
->vsi
[v
], tc_map
);
4588 dev_info(&pf
->pdev
->dev
,
4589 "Failed configuring TC for VSI seid=%d\n",
4591 /* Will try to configure as many components */
4593 /* Re-configure VSI vectors based on updated TC map */
4594 i40e_vsi_map_rings_to_vectors(pf
->vsi
[v
]);
4595 if (pf
->vsi
[v
]->netdev
)
4596 i40e_dcbnl_set_all(pf
->vsi
[v
]);
4602 * i40e_resume_port_tx - Resume port Tx
4605 * Resume a port's Tx and issue a PF reset in case of failure to
4608 static int i40e_resume_port_tx(struct i40e_pf
*pf
)
4610 struct i40e_hw
*hw
= &pf
->hw
;
4613 ret
= i40e_aq_resume_port_tx(hw
, NULL
);
4615 dev_info(&pf
->pdev
->dev
,
4616 "Resume Port Tx failed, err %s aq_err %s\n",
4617 i40e_stat_str(&pf
->hw
, ret
),
4618 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4619 /* Schedule PF reset to recover */
4620 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
4621 i40e_service_event_schedule(pf
);
4628 * i40e_init_pf_dcb - Initialize DCB configuration
4629 * @pf: PF being configured
4631 * Query the current DCB configuration and cache it
4632 * in the hardware structure
4634 static int i40e_init_pf_dcb(struct i40e_pf
*pf
)
4636 struct i40e_hw
*hw
= &pf
->hw
;
4639 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
4640 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
4641 (pf
->hw
.aq
.fw_maj_ver
< 4))
4644 /* Get the initial DCB configuration */
4645 err
= i40e_init_dcb(hw
);
4647 /* Device/Function is not DCBX capable */
4648 if ((!hw
->func_caps
.dcb
) ||
4649 (hw
->dcbx_status
== I40E_DCBX_STATUS_DISABLED
)) {
4650 dev_info(&pf
->pdev
->dev
,
4651 "DCBX offload is not supported or is disabled for this PF.\n");
4653 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
)
4657 /* When status is not DISABLED then DCBX in FW */
4658 pf
->dcbx_cap
= DCB_CAP_DCBX_LLD_MANAGED
|
4659 DCB_CAP_DCBX_VER_IEEE
;
4661 pf
->flags
|= I40E_FLAG_DCB_CAPABLE
;
4662 /* Enable DCB tagging only when more than one TC */
4663 if (i40e_dcb_get_num_tc(&hw
->local_dcbx_config
) > 1)
4664 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
4665 dev_dbg(&pf
->pdev
->dev
,
4666 "DCBX offload is supported for this PF.\n");
4669 dev_info(&pf
->pdev
->dev
,
4670 "Query for DCB configuration failed, err %s aq_err %s\n",
4671 i40e_stat_str(&pf
->hw
, err
),
4672 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4678 #endif /* CONFIG_I40E_DCB */
4679 #define SPEED_SIZE 14
4682 * i40e_print_link_message - print link up or down
4683 * @vsi: the VSI for which link needs a message
4685 static void i40e_print_link_message(struct i40e_vsi
*vsi
, bool isup
)
4687 char speed
[SPEED_SIZE
] = "Unknown";
4688 char fc
[FC_SIZE
] = "RX/TX";
4691 netdev_info(vsi
->netdev
, "NIC Link is Down\n");
4695 /* Warn user if link speed on NPAR enabled partition is not at
4698 if (vsi
->back
->hw
.func_caps
.npar_enable
&&
4699 (vsi
->back
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_1GB
||
4700 vsi
->back
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_100MB
))
4701 netdev_warn(vsi
->netdev
,
4702 "The partition detected link speed that is less than 10Gbps\n");
4704 switch (vsi
->back
->hw
.phy
.link_info
.link_speed
) {
4705 case I40E_LINK_SPEED_40GB
:
4706 strlcpy(speed
, "40 Gbps", SPEED_SIZE
);
4708 case I40E_LINK_SPEED_20GB
:
4709 strncpy(speed
, "20 Gbps", SPEED_SIZE
);
4711 case I40E_LINK_SPEED_10GB
:
4712 strlcpy(speed
, "10 Gbps", SPEED_SIZE
);
4714 case I40E_LINK_SPEED_1GB
:
4715 strlcpy(speed
, "1000 Mbps", SPEED_SIZE
);
4717 case I40E_LINK_SPEED_100MB
:
4718 strncpy(speed
, "100 Mbps", SPEED_SIZE
);
4724 switch (vsi
->back
->hw
.fc
.current_mode
) {
4726 strlcpy(fc
, "RX/TX", FC_SIZE
);
4728 case I40E_FC_TX_PAUSE
:
4729 strlcpy(fc
, "TX", FC_SIZE
);
4731 case I40E_FC_RX_PAUSE
:
4732 strlcpy(fc
, "RX", FC_SIZE
);
4735 strlcpy(fc
, "None", FC_SIZE
);
4739 netdev_info(vsi
->netdev
, "NIC Link is Up %s Full Duplex, Flow Control: %s\n",
4744 * i40e_up_complete - Finish the last steps of bringing up a connection
4745 * @vsi: the VSI being configured
4747 static int i40e_up_complete(struct i40e_vsi
*vsi
)
4749 struct i40e_pf
*pf
= vsi
->back
;
4752 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
4753 i40e_vsi_configure_msix(vsi
);
4755 i40e_configure_msi_and_legacy(vsi
);
4758 err
= i40e_vsi_control_rings(vsi
, true);
4762 clear_bit(__I40E_DOWN
, &vsi
->state
);
4763 i40e_napi_enable_all(vsi
);
4764 i40e_vsi_enable_irq(vsi
);
4766 if ((pf
->hw
.phy
.link_info
.link_info
& I40E_AQ_LINK_UP
) &&
4768 i40e_print_link_message(vsi
, true);
4769 netif_tx_start_all_queues(vsi
->netdev
);
4770 netif_carrier_on(vsi
->netdev
);
4771 } else if (vsi
->netdev
) {
4772 i40e_print_link_message(vsi
, false);
4773 /* need to check for qualified module here*/
4774 if ((pf
->hw
.phy
.link_info
.link_info
&
4775 I40E_AQ_MEDIA_AVAILABLE
) &&
4776 (!(pf
->hw
.phy
.link_info
.an_info
&
4777 I40E_AQ_QUALIFIED_MODULE
)))
4778 netdev_err(vsi
->netdev
,
4779 "the driver failed to link because an unqualified module was detected.");
4782 /* replay FDIR SB filters */
4783 if (vsi
->type
== I40E_VSI_FDIR
) {
4784 /* reset fd counters */
4785 pf
->fd_add_err
= pf
->fd_atr_cnt
= 0;
4786 if (pf
->fd_tcp_rule
> 0) {
4787 pf
->flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
4788 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
4789 dev_info(&pf
->pdev
->dev
, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
4790 pf
->fd_tcp_rule
= 0;
4792 i40e_fdir_filter_restore(vsi
);
4794 i40e_service_event_schedule(pf
);
4800 * i40e_vsi_reinit_locked - Reset the VSI
4801 * @vsi: the VSI being configured
4803 * Rebuild the ring structs after some configuration
4804 * has changed, e.g. MTU size.
4806 static void i40e_vsi_reinit_locked(struct i40e_vsi
*vsi
)
4808 struct i40e_pf
*pf
= vsi
->back
;
4810 WARN_ON(in_interrupt());
4811 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
4812 usleep_range(1000, 2000);
4815 /* Give a VF some time to respond to the reset. The
4816 * two second wait is based upon the watchdog cycle in
4819 if (vsi
->type
== I40E_VSI_SRIOV
)
4822 clear_bit(__I40E_CONFIG_BUSY
, &pf
->state
);
4826 * i40e_up - Bring the connection back up after being down
4827 * @vsi: the VSI being configured
4829 int i40e_up(struct i40e_vsi
*vsi
)
4833 err
= i40e_vsi_configure(vsi
);
4835 err
= i40e_up_complete(vsi
);
4841 * i40e_down - Shutdown the connection processing
4842 * @vsi: the VSI being stopped
4844 void i40e_down(struct i40e_vsi
*vsi
)
4848 /* It is assumed that the caller of this function
4849 * sets the vsi->state __I40E_DOWN bit.
4852 netif_carrier_off(vsi
->netdev
);
4853 netif_tx_disable(vsi
->netdev
);
4855 i40e_vsi_disable_irq(vsi
);
4856 i40e_vsi_control_rings(vsi
, false);
4857 i40e_napi_disable_all(vsi
);
4859 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
4860 i40e_clean_tx_ring(vsi
->tx_rings
[i
]);
4861 i40e_clean_rx_ring(vsi
->rx_rings
[i
]);
4866 * i40e_setup_tc - configure multiple traffic classes
4867 * @netdev: net device to configure
4868 * @tc: number of traffic classes to enable
4871 int i40e_setup_tc(struct net_device
*netdev
, u8 tc
)
4873 static int i40e_setup_tc(struct net_device
*netdev
, u8 tc
)
4876 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
4877 struct i40e_vsi
*vsi
= np
->vsi
;
4878 struct i40e_pf
*pf
= vsi
->back
;
4883 /* Check if DCB enabled to continue */
4884 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
)) {
4885 netdev_info(netdev
, "DCB is not enabled for adapter\n");
4889 /* Check if MFP enabled */
4890 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
4891 netdev_info(netdev
, "Configuring TC not supported in MFP mode\n");
4895 /* Check whether tc count is within enabled limit */
4896 if (tc
> i40e_pf_get_num_tc(pf
)) {
4897 netdev_info(netdev
, "TC count greater than enabled on link for adapter\n");
4901 /* Generate TC map for number of tc requested */
4902 for (i
= 0; i
< tc
; i
++)
4903 enabled_tc
|= BIT_ULL(i
);
4905 /* Requesting same TC configuration as already enabled */
4906 if (enabled_tc
== vsi
->tc_config
.enabled_tc
)
4909 /* Quiesce VSI queues */
4910 i40e_quiesce_vsi(vsi
);
4912 /* Configure VSI for enabled TCs */
4913 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
4915 netdev_info(netdev
, "Failed configuring TC for VSI seid=%d\n",
4921 i40e_unquiesce_vsi(vsi
);
4928 * i40e_open - Called when a network interface is made active
4929 * @netdev: network interface device structure
4931 * The open entry point is called when a network interface is made
4932 * active by the system (IFF_UP). At this point all resources needed
4933 * for transmit and receive operations are allocated, the interrupt
4934 * handler is registered with the OS, the netdev watchdog subtask is
4935 * enabled, and the stack is notified that the interface is ready.
4937 * Returns 0 on success, negative value on failure
4939 int i40e_open(struct net_device
*netdev
)
4941 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
4942 struct i40e_vsi
*vsi
= np
->vsi
;
4943 struct i40e_pf
*pf
= vsi
->back
;
4946 /* disallow open during test or if eeprom is broken */
4947 if (test_bit(__I40E_TESTING
, &pf
->state
) ||
4948 test_bit(__I40E_BAD_EEPROM
, &pf
->state
))
4951 netif_carrier_off(netdev
);
4953 err
= i40e_vsi_open(vsi
);
4957 /* configure global TSO hardware offload settings */
4958 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_F
, be32_to_cpu(TCP_FLAG_PSH
|
4959 TCP_FLAG_FIN
) >> 16);
4960 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_M
, be32_to_cpu(TCP_FLAG_PSH
|
4962 TCP_FLAG_CWR
) >> 16);
4963 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_L
, be32_to_cpu(TCP_FLAG_CWR
) >> 16);
4965 #ifdef CONFIG_I40E_VXLAN
4966 vxlan_get_rx_port(netdev
);
4974 * @vsi: the VSI to open
4976 * Finish initialization of the VSI.
4978 * Returns 0 on success, negative value on failure
4980 int i40e_vsi_open(struct i40e_vsi
*vsi
)
4982 struct i40e_pf
*pf
= vsi
->back
;
4983 char int_name
[I40E_INT_NAME_STR_LEN
];
4986 /* allocate descriptors */
4987 err
= i40e_vsi_setup_tx_resources(vsi
);
4990 err
= i40e_vsi_setup_rx_resources(vsi
);
4994 err
= i40e_vsi_configure(vsi
);
4999 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s",
5000 dev_driver_string(&pf
->pdev
->dev
), vsi
->netdev
->name
);
5001 err
= i40e_vsi_request_irq(vsi
, int_name
);
5005 /* Notify the stack of the actual queue counts. */
5006 err
= netif_set_real_num_tx_queues(vsi
->netdev
,
5007 vsi
->num_queue_pairs
);
5009 goto err_set_queues
;
5011 err
= netif_set_real_num_rx_queues(vsi
->netdev
,
5012 vsi
->num_queue_pairs
);
5014 goto err_set_queues
;
5016 } else if (vsi
->type
== I40E_VSI_FDIR
) {
5017 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s:fdir",
5018 dev_driver_string(&pf
->pdev
->dev
),
5019 dev_name(&pf
->pdev
->dev
));
5020 err
= i40e_vsi_request_irq(vsi
, int_name
);
5027 err
= i40e_up_complete(vsi
);
5029 goto err_up_complete
;
5036 i40e_vsi_free_irq(vsi
);
5038 i40e_vsi_free_rx_resources(vsi
);
5040 i40e_vsi_free_tx_resources(vsi
);
5041 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
5042 i40e_do_reset(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
5048 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
5049 * @pf: Pointer to PF
5051 * This function destroys the hlist where all the Flow Director
5052 * filters were saved.
5054 static void i40e_fdir_filter_exit(struct i40e_pf
*pf
)
5056 struct i40e_fdir_filter
*filter
;
5057 struct hlist_node
*node2
;
5059 hlist_for_each_entry_safe(filter
, node2
,
5060 &pf
->fdir_filter_list
, fdir_node
) {
5061 hlist_del(&filter
->fdir_node
);
5064 pf
->fdir_pf_active_filters
= 0;
5068 * i40e_close - Disables a network interface
5069 * @netdev: network interface device structure
5071 * The close entry point is called when an interface is de-activated
5072 * by the OS. The hardware is still under the driver's control, but
5073 * this netdev interface is disabled.
5075 * Returns 0, this is not allowed to fail
5078 int i40e_close(struct net_device
*netdev
)
5080 static int i40e_close(struct net_device
*netdev
)
5083 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
5084 struct i40e_vsi
*vsi
= np
->vsi
;
5086 i40e_vsi_close(vsi
);
5092 * i40e_do_reset - Start a PF or Core Reset sequence
5093 * @pf: board private structure
5094 * @reset_flags: which reset is requested
5096 * The essential difference in resets is that the PF Reset
5097 * doesn't clear the packet buffers, doesn't reset the PE
5098 * firmware, and doesn't bother the other PFs on the chip.
5100 void i40e_do_reset(struct i40e_pf
*pf
, u32 reset_flags
)
5104 WARN_ON(in_interrupt());
5106 if (i40e_check_asq_alive(&pf
->hw
))
5107 i40e_vc_notify_reset(pf
);
5109 /* do the biggest reset indicated */
5110 if (reset_flags
& BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED
)) {
5112 /* Request a Global Reset
5114 * This will start the chip's countdown to the actual full
5115 * chip reset event, and a warning interrupt to be sent
5116 * to all PFs, including the requestor. Our handler
5117 * for the warning interrupt will deal with the shutdown
5118 * and recovery of the switch setup.
5120 dev_dbg(&pf
->pdev
->dev
, "GlobalR requested\n");
5121 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
5122 val
|= I40E_GLGEN_RTRIG_GLOBR_MASK
;
5123 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
5125 } else if (reset_flags
& BIT_ULL(__I40E_CORE_RESET_REQUESTED
)) {
5127 /* Request a Core Reset
5129 * Same as Global Reset, except does *not* include the MAC/PHY
5131 dev_dbg(&pf
->pdev
->dev
, "CoreR requested\n");
5132 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
5133 val
|= I40E_GLGEN_RTRIG_CORER_MASK
;
5134 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
5135 i40e_flush(&pf
->hw
);
5137 } else if (reset_flags
& BIT_ULL(__I40E_PF_RESET_REQUESTED
)) {
5139 /* Request a PF Reset
5141 * Resets only the PF-specific registers
5143 * This goes directly to the tear-down and rebuild of
5144 * the switch, since we need to do all the recovery as
5145 * for the Core Reset.
5147 dev_dbg(&pf
->pdev
->dev
, "PFR requested\n");
5148 i40e_handle_reset_warning(pf
);
5150 } else if (reset_flags
& BIT_ULL(__I40E_REINIT_REQUESTED
)) {
5153 /* Find the VSI(s) that requested a re-init */
5154 dev_info(&pf
->pdev
->dev
,
5155 "VSI reinit requested\n");
5156 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5157 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
5159 test_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
)) {
5160 i40e_vsi_reinit_locked(pf
->vsi
[v
]);
5161 clear_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
);
5165 /* no further action needed, so return now */
5167 } else if (reset_flags
& BIT_ULL(__I40E_DOWN_REQUESTED
)) {
5170 /* Find the VSI(s) that needs to be brought down */
5171 dev_info(&pf
->pdev
->dev
, "VSI down requested\n");
5172 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5173 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
5175 test_bit(__I40E_DOWN_REQUESTED
, &vsi
->state
)) {
5176 set_bit(__I40E_DOWN
, &vsi
->state
);
5178 clear_bit(__I40E_DOWN_REQUESTED
, &vsi
->state
);
5182 /* no further action needed, so return now */
5185 dev_info(&pf
->pdev
->dev
,
5186 "bad reset request 0x%08x\n", reset_flags
);
5191 #ifdef CONFIG_I40E_DCB
5193 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
5194 * @pf: board private structure
5195 * @old_cfg: current DCB config
5196 * @new_cfg: new DCB config
5198 bool i40e_dcb_need_reconfig(struct i40e_pf
*pf
,
5199 struct i40e_dcbx_config
*old_cfg
,
5200 struct i40e_dcbx_config
*new_cfg
)
5202 bool need_reconfig
= false;
5204 /* Check if ETS configuration has changed */
5205 if (memcmp(&new_cfg
->etscfg
,
5207 sizeof(new_cfg
->etscfg
))) {
5208 /* If Priority Table has changed reconfig is needed */
5209 if (memcmp(&new_cfg
->etscfg
.prioritytable
,
5210 &old_cfg
->etscfg
.prioritytable
,
5211 sizeof(new_cfg
->etscfg
.prioritytable
))) {
5212 need_reconfig
= true;
5213 dev_dbg(&pf
->pdev
->dev
, "ETS UP2TC changed.\n");
5216 if (memcmp(&new_cfg
->etscfg
.tcbwtable
,
5217 &old_cfg
->etscfg
.tcbwtable
,
5218 sizeof(new_cfg
->etscfg
.tcbwtable
)))
5219 dev_dbg(&pf
->pdev
->dev
, "ETS TC BW Table changed.\n");
5221 if (memcmp(&new_cfg
->etscfg
.tsatable
,
5222 &old_cfg
->etscfg
.tsatable
,
5223 sizeof(new_cfg
->etscfg
.tsatable
)))
5224 dev_dbg(&pf
->pdev
->dev
, "ETS TSA Table changed.\n");
5227 /* Check if PFC configuration has changed */
5228 if (memcmp(&new_cfg
->pfc
,
5230 sizeof(new_cfg
->pfc
))) {
5231 need_reconfig
= true;
5232 dev_dbg(&pf
->pdev
->dev
, "PFC config change detected.\n");
5235 /* Check if APP Table has changed */
5236 if (memcmp(&new_cfg
->app
,
5238 sizeof(new_cfg
->app
))) {
5239 need_reconfig
= true;
5240 dev_dbg(&pf
->pdev
->dev
, "APP Table change detected.\n");
5243 dev_dbg(&pf
->pdev
->dev
, "%s: need_reconfig=%d\n", __func__
,
5245 return need_reconfig
;
5249 * i40e_handle_lldp_event - Handle LLDP Change MIB event
5250 * @pf: board private structure
5251 * @e: event info posted on ARQ
5253 static int i40e_handle_lldp_event(struct i40e_pf
*pf
,
5254 struct i40e_arq_event_info
*e
)
5256 struct i40e_aqc_lldp_get_mib
*mib
=
5257 (struct i40e_aqc_lldp_get_mib
*)&e
->desc
.params
.raw
;
5258 struct i40e_hw
*hw
= &pf
->hw
;
5259 struct i40e_dcbx_config tmp_dcbx_cfg
;
5260 bool need_reconfig
= false;
5264 /* Not DCB capable or capability disabled */
5265 if (!(pf
->flags
& I40E_FLAG_DCB_CAPABLE
))
5268 /* Ignore if event is not for Nearest Bridge */
5269 type
= ((mib
->type
>> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT
)
5270 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK
);
5271 dev_dbg(&pf
->pdev
->dev
,
5272 "%s: LLDP event mib bridge type 0x%x\n", __func__
, type
);
5273 if (type
!= I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
)
5276 /* Check MIB Type and return if event for Remote MIB update */
5277 type
= mib
->type
& I40E_AQ_LLDP_MIB_TYPE_MASK
;
5278 dev_dbg(&pf
->pdev
->dev
,
5279 "%s: LLDP event mib type %s\n", __func__
,
5280 type
? "remote" : "local");
5281 if (type
== I40E_AQ_LLDP_MIB_REMOTE
) {
5282 /* Update the remote cached instance and return */
5283 ret
= i40e_aq_get_dcb_config(hw
, I40E_AQ_LLDP_MIB_REMOTE
,
5284 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
,
5285 &hw
->remote_dcbx_config
);
5289 /* Store the old configuration */
5290 tmp_dcbx_cfg
= hw
->local_dcbx_config
;
5292 /* Reset the old DCBx configuration data */
5293 memset(&hw
->local_dcbx_config
, 0, sizeof(hw
->local_dcbx_config
));
5294 /* Get updated DCBX data from firmware */
5295 ret
= i40e_get_dcb_config(&pf
->hw
);
5297 dev_info(&pf
->pdev
->dev
,
5298 "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
5299 i40e_stat_str(&pf
->hw
, ret
),
5300 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
5304 /* No change detected in DCBX configs */
5305 if (!memcmp(&tmp_dcbx_cfg
, &hw
->local_dcbx_config
,
5306 sizeof(tmp_dcbx_cfg
))) {
5307 dev_dbg(&pf
->pdev
->dev
, "No change detected in DCBX configuration.\n");
5311 need_reconfig
= i40e_dcb_need_reconfig(pf
, &tmp_dcbx_cfg
,
5312 &hw
->local_dcbx_config
);
5314 i40e_dcbnl_flush_apps(pf
, &tmp_dcbx_cfg
, &hw
->local_dcbx_config
);
5319 /* Enable DCB tagging only when more than one TC */
5320 if (i40e_dcb_get_num_tc(&hw
->local_dcbx_config
) > 1)
5321 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
5323 pf
->flags
&= ~I40E_FLAG_DCB_ENABLED
;
5325 set_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
);
5326 /* Reconfiguration needed quiesce all VSIs */
5327 i40e_pf_quiesce_all_vsi(pf
);
5329 /* Changes in configuration update VEB/VSI */
5330 i40e_dcb_reconfigure(pf
);
5332 ret
= i40e_resume_port_tx(pf
);
5334 clear_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
);
5335 /* In case of error no point in resuming VSIs */
5339 /* Wait for the PF's Tx queues to be disabled */
5340 ret
= i40e_pf_wait_txq_disabled(pf
);
5342 /* Schedule PF reset to recover */
5343 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
5344 i40e_service_event_schedule(pf
);
5346 i40e_pf_unquiesce_all_vsi(pf
);
5352 #endif /* CONFIG_I40E_DCB */
5355 * i40e_do_reset_safe - Protected reset path for userland calls.
5356 * @pf: board private structure
5357 * @reset_flags: which reset is requested
5360 void i40e_do_reset_safe(struct i40e_pf
*pf
, u32 reset_flags
)
5363 i40e_do_reset(pf
, reset_flags
);
5368 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
5369 * @pf: board private structure
5370 * @e: event info posted on ARQ
5372 * Handler for LAN Queue Overflow Event generated by the firmware for PF
5375 static void i40e_handle_lan_overflow_event(struct i40e_pf
*pf
,
5376 struct i40e_arq_event_info
*e
)
5378 struct i40e_aqc_lan_overflow
*data
=
5379 (struct i40e_aqc_lan_overflow
*)&e
->desc
.params
.raw
;
5380 u32 queue
= le32_to_cpu(data
->prtdcb_rupto
);
5381 u32 qtx_ctl
= le32_to_cpu(data
->otx_ctl
);
5382 struct i40e_hw
*hw
= &pf
->hw
;
5386 dev_dbg(&pf
->pdev
->dev
, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
5389 /* Queue belongs to VF, find the VF and issue VF reset */
5390 if (((qtx_ctl
& I40E_QTX_CTL_PFVF_Q_MASK
)
5391 >> I40E_QTX_CTL_PFVF_Q_SHIFT
) == I40E_QTX_CTL_VF_QUEUE
) {
5392 vf_id
= (u16
)((qtx_ctl
& I40E_QTX_CTL_VFVM_INDX_MASK
)
5393 >> I40E_QTX_CTL_VFVM_INDX_SHIFT
);
5394 vf_id
-= hw
->func_caps
.vf_base_id
;
5395 vf
= &pf
->vf
[vf_id
];
5396 i40e_vc_notify_vf_reset(vf
);
5397 /* Allow VF to process pending reset notification */
5399 i40e_reset_vf(vf
, false);
5404 * i40e_service_event_complete - Finish up the service event
5405 * @pf: board private structure
5407 static void i40e_service_event_complete(struct i40e_pf
*pf
)
5409 BUG_ON(!test_bit(__I40E_SERVICE_SCHED
, &pf
->state
));
5411 /* flush memory to make sure state is correct before next watchog */
5412 smp_mb__before_atomic();
5413 clear_bit(__I40E_SERVICE_SCHED
, &pf
->state
);
5417 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
5418 * @pf: board private structure
5420 u32
i40e_get_cur_guaranteed_fd_count(struct i40e_pf
*pf
)
5424 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
5425 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
);
5430 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
5431 * @pf: board private structure
5433 u32
i40e_get_current_fd_count(struct i40e_pf
*pf
)
5437 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
5438 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
) +
5439 ((val
& I40E_PFQF_FDSTAT_BEST_CNT_MASK
) >>
5440 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT
);
5445 * i40e_get_global_fd_count - Get total FD filters programmed on device
5446 * @pf: board private structure
5448 u32
i40e_get_global_fd_count(struct i40e_pf
*pf
)
5452 val
= rd32(&pf
->hw
, I40E_GLQF_FDCNT_0
);
5453 fcnt_prog
= (val
& I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK
) +
5454 ((val
& I40E_GLQF_FDCNT_0_BESTCNT_MASK
) >>
5455 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT
);
5460 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
5461 * @pf: board private structure
5463 void i40e_fdir_check_and_reenable(struct i40e_pf
*pf
)
5465 u32 fcnt_prog
, fcnt_avail
;
5467 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
5470 /* Check if, FD SB or ATR was auto disabled and if there is enough room
5473 fcnt_prog
= i40e_get_global_fd_count(pf
);
5474 fcnt_avail
= pf
->fdir_pf_filter_count
;
5475 if ((fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM
)) ||
5476 (pf
->fd_add_err
== 0) ||
5477 (i40e_get_current_atr_cnt(pf
) < pf
->fd_atr_cnt
)) {
5478 if ((pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) &&
5479 (pf
->auto_disable_flags
& I40E_FLAG_FD_SB_ENABLED
)) {
5480 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
5481 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5482 dev_info(&pf
->pdev
->dev
, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
5485 /* Wait for some more space to be available to turn on ATR */
5486 if (fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM
* 2)) {
5487 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
5488 (pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
)) {
5489 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
5490 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5491 dev_info(&pf
->pdev
->dev
, "ATR is being enabled since we have space in the table now\n");
5496 #define I40E_MIN_FD_FLUSH_INTERVAL 10
5497 #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
5499 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
5500 * @pf: board private structure
5502 static void i40e_fdir_flush_and_replay(struct i40e_pf
*pf
)
5504 unsigned long min_flush_time
;
5505 int flush_wait_retry
= 50;
5506 bool disable_atr
= false;
5510 if (!(pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
)))
5513 if (time_after(jiffies
, pf
->fd_flush_timestamp
+
5514 (I40E_MIN_FD_FLUSH_INTERVAL
* HZ
))) {
5515 /* If the flush is happening too quick and we have mostly
5516 * SB rules we should not re-enable ATR for some time.
5518 min_flush_time
= pf
->fd_flush_timestamp
5519 + (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE
* HZ
);
5520 fd_room
= pf
->fdir_pf_filter_count
- pf
->fdir_pf_active_filters
;
5522 if (!(time_after(jiffies
, min_flush_time
)) &&
5523 (fd_room
< I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR
)) {
5524 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5525 dev_info(&pf
->pdev
->dev
, "ATR disabled, not enough FD filter space.\n");
5529 pf
->fd_flush_timestamp
= jiffies
;
5530 pf
->flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
5531 /* flush all filters */
5532 wr32(&pf
->hw
, I40E_PFQF_CTL_1
,
5533 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
);
5534 i40e_flush(&pf
->hw
);
5538 /* Check FD flush status every 5-6msec */
5539 usleep_range(5000, 6000);
5540 reg
= rd32(&pf
->hw
, I40E_PFQF_CTL_1
);
5541 if (!(reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
))
5543 } while (flush_wait_retry
--);
5544 if (reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
) {
5545 dev_warn(&pf
->pdev
->dev
, "FD table did not flush, needs more time\n");
5547 /* replay sideband filters */
5548 i40e_fdir_filter_restore(pf
->vsi
[pf
->lan_vsi
]);
5550 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
5551 clear_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
);
5552 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5553 dev_info(&pf
->pdev
->dev
, "FD Filter table flushed and FD-SB replayed.\n");
5559 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
5560 * @pf: board private structure
5562 u32
i40e_get_current_atr_cnt(struct i40e_pf
*pf
)
5564 return i40e_get_current_fd_count(pf
) - pf
->fdir_pf_active_filters
;
5567 /* We can see up to 256 filter programming desc in transit if the filters are
5568 * being applied really fast; before we see the first
5569 * filter miss error on Rx queue 0. Accumulating enough error messages before
5570 * reacting will make sure we don't cause flush too often.
5572 #define I40E_MAX_FD_PROGRAM_ERROR 256
5575 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
5576 * @pf: board private structure
5578 static void i40e_fdir_reinit_subtask(struct i40e_pf
*pf
)
5581 /* if interface is down do nothing */
5582 if (test_bit(__I40E_DOWN
, &pf
->state
))
5585 if (!(pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
)))
5588 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
5589 i40e_fdir_flush_and_replay(pf
);
5591 i40e_fdir_check_and_reenable(pf
);
5596 * i40e_vsi_link_event - notify VSI of a link event
5597 * @vsi: vsi to be notified
5598 * @link_up: link up or down
5600 static void i40e_vsi_link_event(struct i40e_vsi
*vsi
, bool link_up
)
5602 if (!vsi
|| test_bit(__I40E_DOWN
, &vsi
->state
))
5605 switch (vsi
->type
) {
5610 if (!vsi
->netdev
|| !vsi
->netdev_registered
)
5614 netif_carrier_on(vsi
->netdev
);
5615 netif_tx_wake_all_queues(vsi
->netdev
);
5617 netif_carrier_off(vsi
->netdev
);
5618 netif_tx_stop_all_queues(vsi
->netdev
);
5622 case I40E_VSI_SRIOV
:
5623 case I40E_VSI_VMDQ2
:
5625 case I40E_VSI_MIRROR
:
5627 /* there is no notification for other VSIs */
5633 * i40e_veb_link_event - notify elements on the veb of a link event
5634 * @veb: veb to be notified
5635 * @link_up: link up or down
5637 static void i40e_veb_link_event(struct i40e_veb
*veb
, bool link_up
)
5642 if (!veb
|| !veb
->pf
)
5646 /* depth first... */
5647 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
5648 if (pf
->veb
[i
] && (pf
->veb
[i
]->uplink_seid
== veb
->seid
))
5649 i40e_veb_link_event(pf
->veb
[i
], link_up
);
5651 /* ... now the local VSIs */
5652 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
5653 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->uplink_seid
== veb
->seid
))
5654 i40e_vsi_link_event(pf
->vsi
[i
], link_up
);
5658 * i40e_link_event - Update netif_carrier status
5659 * @pf: board private structure
5661 static void i40e_link_event(struct i40e_pf
*pf
)
5663 bool new_link
, old_link
;
5664 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
5665 u8 new_link_speed
, old_link_speed
;
5667 /* set this to force the get_link_status call to refresh state */
5668 pf
->hw
.phy
.get_link_info
= true;
5670 old_link
= (pf
->hw
.phy
.link_info_old
.link_info
& I40E_AQ_LINK_UP
);
5671 new_link
= i40e_get_link_status(&pf
->hw
);
5672 old_link_speed
= pf
->hw
.phy
.link_info_old
.link_speed
;
5673 new_link_speed
= pf
->hw
.phy
.link_info
.link_speed
;
5675 if (new_link
== old_link
&&
5676 new_link_speed
== old_link_speed
&&
5677 (test_bit(__I40E_DOWN
, &vsi
->state
) ||
5678 new_link
== netif_carrier_ok(vsi
->netdev
)))
5681 if (!test_bit(__I40E_DOWN
, &vsi
->state
))
5682 i40e_print_link_message(vsi
, new_link
);
5684 /* Notify the base of the switch tree connected to
5685 * the link. Floating VEBs are not notified.
5687 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
5688 i40e_veb_link_event(pf
->veb
[pf
->lan_veb
], new_link
);
5690 i40e_vsi_link_event(vsi
, new_link
);
5693 i40e_vc_notify_link_state(pf
);
5695 if (pf
->flags
& I40E_FLAG_PTP
)
5696 i40e_ptp_set_increment(pf
);
5700 * i40e_check_hang_subtask - Check for hung queues and dropped interrupts
5701 * @pf: board private structure
5703 * Set the per-queue flags to request a check for stuck queues in the irq
5704 * clean functions, then force interrupts to be sure the irq clean is called.
5706 static void i40e_check_hang_subtask(struct i40e_pf
*pf
)
5710 /* If we're down or resetting, just bail */
5711 if (test_bit(__I40E_DOWN
, &pf
->state
) ||
5712 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
5715 /* for each VSI/netdev
5717 * set the check flag
5719 * force an interrupt
5721 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5722 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
5726 test_bit(__I40E_DOWN
, &vsi
->state
) ||
5727 (vsi
->netdev
&& !netif_carrier_ok(vsi
->netdev
)))
5730 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
5731 set_check_for_tx_hang(vsi
->tx_rings
[i
]);
5732 if (test_bit(__I40E_HANG_CHECK_ARMED
,
5733 &vsi
->tx_rings
[i
]->state
))
5738 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
)) {
5739 wr32(&vsi
->back
->hw
, I40E_PFINT_DYN_CTL0
,
5740 (I40E_PFINT_DYN_CTL0_INTENA_MASK
|
5741 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK
|
5742 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK
|
5743 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK
|
5744 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK
));
5746 u16 vec
= vsi
->base_vector
- 1;
5747 u32 val
= (I40E_PFINT_DYN_CTLN_INTENA_MASK
|
5748 I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK
|
5749 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK
|
5750 I40E_PFINT_DYN_CTLN_SW_ITR_INDX_ENA_MASK
|
5751 I40E_PFINT_DYN_CTLN_SW_ITR_INDX_MASK
);
5752 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vec
++)
5753 wr32(&vsi
->back
->hw
,
5754 I40E_PFINT_DYN_CTLN(vec
), val
);
5756 i40e_flush(&vsi
->back
->hw
);
5762 * i40e_watchdog_subtask - periodic checks not using event driven response
5763 * @pf: board private structure
5765 static void i40e_watchdog_subtask(struct i40e_pf
*pf
)
5769 /* if interface is down do nothing */
5770 if (test_bit(__I40E_DOWN
, &pf
->state
) ||
5771 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
5774 /* make sure we don't do these things too often */
5775 if (time_before(jiffies
, (pf
->service_timer_previous
+
5776 pf
->service_timer_period
)))
5778 pf
->service_timer_previous
= jiffies
;
5780 i40e_check_hang_subtask(pf
);
5781 i40e_link_event(pf
);
5783 /* Update the stats for active netdevs so the network stack
5784 * can look at updated numbers whenever it cares to
5786 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
5787 if (pf
->vsi
[i
] && pf
->vsi
[i
]->netdev
)
5788 i40e_update_stats(pf
->vsi
[i
]);
5790 /* Update the stats for the active switching components */
5791 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
5793 i40e_update_veb_stats(pf
->veb
[i
]);
5795 i40e_ptp_rx_hang(pf
->vsi
[pf
->lan_vsi
]);
5799 * i40e_reset_subtask - Set up for resetting the device and driver
5800 * @pf: board private structure
5802 static void i40e_reset_subtask(struct i40e_pf
*pf
)
5804 u32 reset_flags
= 0;
5807 if (test_bit(__I40E_REINIT_REQUESTED
, &pf
->state
)) {
5808 reset_flags
|= BIT_ULL(__I40E_REINIT_REQUESTED
);
5809 clear_bit(__I40E_REINIT_REQUESTED
, &pf
->state
);
5811 if (test_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
)) {
5812 reset_flags
|= BIT_ULL(__I40E_PF_RESET_REQUESTED
);
5813 clear_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
5815 if (test_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
)) {
5816 reset_flags
|= BIT_ULL(__I40E_CORE_RESET_REQUESTED
);
5817 clear_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
);
5819 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
)) {
5820 reset_flags
|= BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED
);
5821 clear_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
);
5823 if (test_bit(__I40E_DOWN_REQUESTED
, &pf
->state
)) {
5824 reset_flags
|= BIT_ULL(__I40E_DOWN_REQUESTED
);
5825 clear_bit(__I40E_DOWN_REQUESTED
, &pf
->state
);
5828 /* If there's a recovery already waiting, it takes
5829 * precedence before starting a new reset sequence.
5831 if (test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
)) {
5832 i40e_handle_reset_warning(pf
);
5836 /* If we're already down or resetting, just bail */
5838 !test_bit(__I40E_DOWN
, &pf
->state
) &&
5839 !test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
5840 i40e_do_reset(pf
, reset_flags
);
5847 * i40e_handle_link_event - Handle link event
5848 * @pf: board private structure
5849 * @e: event info posted on ARQ
5851 static void i40e_handle_link_event(struct i40e_pf
*pf
,
5852 struct i40e_arq_event_info
*e
)
5854 struct i40e_hw
*hw
= &pf
->hw
;
5855 struct i40e_aqc_get_link_status
*status
=
5856 (struct i40e_aqc_get_link_status
*)&e
->desc
.params
.raw
;
5858 /* save off old link status information */
5859 hw
->phy
.link_info_old
= hw
->phy
.link_info
;
5861 /* Do a new status request to re-enable LSE reporting
5862 * and load new status information into the hw struct
5863 * This completely ignores any state information
5864 * in the ARQ event info, instead choosing to always
5865 * issue the AQ update link status command.
5867 i40e_link_event(pf
);
5869 /* check for unqualified module, if link is down */
5870 if ((status
->link_info
& I40E_AQ_MEDIA_AVAILABLE
) &&
5871 (!(status
->an_info
& I40E_AQ_QUALIFIED_MODULE
)) &&
5872 (!(status
->link_info
& I40E_AQ_LINK_UP
)))
5873 dev_err(&pf
->pdev
->dev
,
5874 "The driver failed to link because an unqualified module was detected.\n");
5878 * i40e_clean_adminq_subtask - Clean the AdminQ rings
5879 * @pf: board private structure
5881 static void i40e_clean_adminq_subtask(struct i40e_pf
*pf
)
5883 struct i40e_arq_event_info event
;
5884 struct i40e_hw
*hw
= &pf
->hw
;
5891 /* Do not run clean AQ when PF reset fails */
5892 if (test_bit(__I40E_RESET_FAILED
, &pf
->state
))
5895 /* check for error indications */
5896 val
= rd32(&pf
->hw
, pf
->hw
.aq
.arq
.len
);
5898 if (val
& I40E_PF_ARQLEN_ARQVFE_MASK
) {
5899 dev_info(&pf
->pdev
->dev
, "ARQ VF Error detected\n");
5900 val
&= ~I40E_PF_ARQLEN_ARQVFE_MASK
;
5902 if (val
& I40E_PF_ARQLEN_ARQOVFL_MASK
) {
5903 dev_info(&pf
->pdev
->dev
, "ARQ Overflow Error detected\n");
5904 val
&= ~I40E_PF_ARQLEN_ARQOVFL_MASK
;
5906 if (val
& I40E_PF_ARQLEN_ARQCRIT_MASK
) {
5907 dev_info(&pf
->pdev
->dev
, "ARQ Critical Error detected\n");
5908 val
&= ~I40E_PF_ARQLEN_ARQCRIT_MASK
;
5911 wr32(&pf
->hw
, pf
->hw
.aq
.arq
.len
, val
);
5913 val
= rd32(&pf
->hw
, pf
->hw
.aq
.asq
.len
);
5915 if (val
& I40E_PF_ATQLEN_ATQVFE_MASK
) {
5916 dev_info(&pf
->pdev
->dev
, "ASQ VF Error detected\n");
5917 val
&= ~I40E_PF_ATQLEN_ATQVFE_MASK
;
5919 if (val
& I40E_PF_ATQLEN_ATQOVFL_MASK
) {
5920 dev_info(&pf
->pdev
->dev
, "ASQ Overflow Error detected\n");
5921 val
&= ~I40E_PF_ATQLEN_ATQOVFL_MASK
;
5923 if (val
& I40E_PF_ATQLEN_ATQCRIT_MASK
) {
5924 dev_info(&pf
->pdev
->dev
, "ASQ Critical Error detected\n");
5925 val
&= ~I40E_PF_ATQLEN_ATQCRIT_MASK
;
5928 wr32(&pf
->hw
, pf
->hw
.aq
.asq
.len
, val
);
5930 event
.buf_len
= I40E_MAX_AQ_BUF_SIZE
;
5931 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
5936 ret
= i40e_clean_arq_element(hw
, &event
, &pending
);
5937 if (ret
== I40E_ERR_ADMIN_QUEUE_NO_WORK
)
5940 dev_info(&pf
->pdev
->dev
, "ARQ event error %d\n", ret
);
5944 opcode
= le16_to_cpu(event
.desc
.opcode
);
5947 case i40e_aqc_opc_get_link_status
:
5948 i40e_handle_link_event(pf
, &event
);
5950 case i40e_aqc_opc_send_msg_to_pf
:
5951 ret
= i40e_vc_process_vf_msg(pf
,
5952 le16_to_cpu(event
.desc
.retval
),
5953 le32_to_cpu(event
.desc
.cookie_high
),
5954 le32_to_cpu(event
.desc
.cookie_low
),
5958 case i40e_aqc_opc_lldp_update_mib
:
5959 dev_dbg(&pf
->pdev
->dev
, "ARQ: Update LLDP MIB event received\n");
5960 #ifdef CONFIG_I40E_DCB
5962 ret
= i40e_handle_lldp_event(pf
, &event
);
5964 #endif /* CONFIG_I40E_DCB */
5966 case i40e_aqc_opc_event_lan_overflow
:
5967 dev_dbg(&pf
->pdev
->dev
, "ARQ LAN queue overflow event received\n");
5968 i40e_handle_lan_overflow_event(pf
, &event
);
5970 case i40e_aqc_opc_send_msg_to_peer
:
5971 dev_info(&pf
->pdev
->dev
, "ARQ: Msg from other pf\n");
5973 case i40e_aqc_opc_nvm_erase
:
5974 case i40e_aqc_opc_nvm_update
:
5975 i40e_debug(&pf
->hw
, I40E_DEBUG_NVM
, "ARQ NVM operation completed\n");
5978 dev_info(&pf
->pdev
->dev
,
5979 "ARQ Error: Unknown event 0x%04x received\n",
5983 } while (pending
&& (i
++ < pf
->adminq_work_limit
));
5985 clear_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
);
5986 /* re-enable Admin queue interrupt cause */
5987 val
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
5988 val
|= I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
5989 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
5992 kfree(event
.msg_buf
);
5996 * i40e_verify_eeprom - make sure eeprom is good to use
5997 * @pf: board private structure
5999 static void i40e_verify_eeprom(struct i40e_pf
*pf
)
6003 err
= i40e_diag_eeprom_test(&pf
->hw
);
6005 /* retry in case of garbage read */
6006 err
= i40e_diag_eeprom_test(&pf
->hw
);
6008 dev_info(&pf
->pdev
->dev
, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
6010 set_bit(__I40E_BAD_EEPROM
, &pf
->state
);
6014 if (!err
&& test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
6015 dev_info(&pf
->pdev
->dev
, "eeprom check passed, Tx/Rx traffic enabled\n");
6016 clear_bit(__I40E_BAD_EEPROM
, &pf
->state
);
6021 * i40e_enable_pf_switch_lb
6022 * @pf: pointer to the PF structure
6024 * enable switch loop back or die - no point in a return value
6026 static void i40e_enable_pf_switch_lb(struct i40e_pf
*pf
)
6028 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
6029 struct i40e_vsi_context ctxt
;
6032 ctxt
.seid
= pf
->main_vsi_seid
;
6033 ctxt
.pf_num
= pf
->hw
.pf_id
;
6035 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
6037 dev_info(&pf
->pdev
->dev
,
6038 "couldn't get PF vsi config, err %s aq_err %s\n",
6039 i40e_stat_str(&pf
->hw
, ret
),
6040 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6043 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
6044 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
6045 ctxt
.info
.switch_id
|= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
6047 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
6049 dev_info(&pf
->pdev
->dev
,
6050 "update vsi switch failed, err %s aq_err %s\n",
6051 i40e_stat_str(&pf
->hw
, ret
),
6052 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6057 * i40e_disable_pf_switch_lb
6058 * @pf: pointer to the PF structure
6060 * disable switch loop back or die - no point in a return value
6062 static void i40e_disable_pf_switch_lb(struct i40e_pf
*pf
)
6064 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
6065 struct i40e_vsi_context ctxt
;
6068 ctxt
.seid
= pf
->main_vsi_seid
;
6069 ctxt
.pf_num
= pf
->hw
.pf_id
;
6071 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
6073 dev_info(&pf
->pdev
->dev
,
6074 "couldn't get PF vsi config, err %s aq_err %s\n",
6075 i40e_stat_str(&pf
->hw
, ret
),
6076 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6079 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
6080 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
6081 ctxt
.info
.switch_id
&= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
6083 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
6085 dev_info(&pf
->pdev
->dev
,
6086 "update vsi switch failed, err %s aq_err %s\n",
6087 i40e_stat_str(&pf
->hw
, ret
),
6088 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6093 * i40e_config_bridge_mode - Configure the HW bridge mode
6094 * @veb: pointer to the bridge instance
6096 * Configure the loop back mode for the LAN VSI that is downlink to the
6097 * specified HW bridge instance. It is expected this function is called
6098 * when a new HW bridge is instantiated.
6100 static void i40e_config_bridge_mode(struct i40e_veb
*veb
)
6102 struct i40e_pf
*pf
= veb
->pf
;
6104 dev_info(&pf
->pdev
->dev
, "enabling bridge mode: %s\n",
6105 veb
->bridge_mode
== BRIDGE_MODE_VEPA
? "VEPA" : "VEB");
6106 if (veb
->bridge_mode
& BRIDGE_MODE_VEPA
)
6107 i40e_disable_pf_switch_lb(pf
);
6109 i40e_enable_pf_switch_lb(pf
);
6113 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
6114 * @veb: pointer to the VEB instance
6116 * This is a recursive function that first builds the attached VSIs then
6117 * recurses in to build the next layer of VEB. We track the connections
6118 * through our own index numbers because the seid's from the HW could
6119 * change across the reset.
6121 static int i40e_reconstitute_veb(struct i40e_veb
*veb
)
6123 struct i40e_vsi
*ctl_vsi
= NULL
;
6124 struct i40e_pf
*pf
= veb
->pf
;
6128 /* build VSI that owns this VEB, temporarily attached to base VEB */
6129 for (v
= 0; v
< pf
->num_alloc_vsi
&& !ctl_vsi
; v
++) {
6131 pf
->vsi
[v
]->veb_idx
== veb
->idx
&&
6132 pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
6133 ctl_vsi
= pf
->vsi
[v
];
6138 dev_info(&pf
->pdev
->dev
,
6139 "missing owner VSI for veb_idx %d\n", veb
->idx
);
6141 goto end_reconstitute
;
6143 if (ctl_vsi
!= pf
->vsi
[pf
->lan_vsi
])
6144 ctl_vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
6145 ret
= i40e_add_vsi(ctl_vsi
);
6147 dev_info(&pf
->pdev
->dev
,
6148 "rebuild of veb_idx %d owner VSI failed: %d\n",
6150 goto end_reconstitute
;
6152 i40e_vsi_reset_stats(ctl_vsi
);
6154 /* create the VEB in the switch and move the VSI onto the VEB */
6155 ret
= i40e_add_veb(veb
, ctl_vsi
);
6157 goto end_reconstitute
;
6159 if (pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)
6160 veb
->bridge_mode
= BRIDGE_MODE_VEB
;
6162 veb
->bridge_mode
= BRIDGE_MODE_VEPA
;
6163 i40e_config_bridge_mode(veb
);
6165 /* create the remaining VSIs attached to this VEB */
6166 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
6167 if (!pf
->vsi
[v
] || pf
->vsi
[v
] == ctl_vsi
)
6170 if (pf
->vsi
[v
]->veb_idx
== veb
->idx
) {
6171 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
6172 vsi
->uplink_seid
= veb
->seid
;
6173 ret
= i40e_add_vsi(vsi
);
6175 dev_info(&pf
->pdev
->dev
,
6176 "rebuild of vsi_idx %d failed: %d\n",
6178 goto end_reconstitute
;
6180 i40e_vsi_reset_stats(vsi
);
6184 /* create any VEBs attached to this VEB - RECURSION */
6185 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
6186 if (pf
->veb
[veb_idx
] && pf
->veb
[veb_idx
]->veb_idx
== veb
->idx
) {
6187 pf
->veb
[veb_idx
]->uplink_seid
= veb
->seid
;
6188 ret
= i40e_reconstitute_veb(pf
->veb
[veb_idx
]);
6199 * i40e_get_capabilities - get info about the HW
6200 * @pf: the PF struct
6202 static int i40e_get_capabilities(struct i40e_pf
*pf
)
6204 struct i40e_aqc_list_capabilities_element_resp
*cap_buf
;
6209 buf_len
= 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp
);
6211 cap_buf
= kzalloc(buf_len
, GFP_KERNEL
);
6215 /* this loads the data into the hw struct for us */
6216 err
= i40e_aq_discover_capabilities(&pf
->hw
, cap_buf
, buf_len
,
6218 i40e_aqc_opc_list_func_capabilities
,
6220 /* data loaded, buffer no longer needed */
6223 if (pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_ENOMEM
) {
6224 /* retry with a larger buffer */
6225 buf_len
= data_size
;
6226 } else if (pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_OK
) {
6227 dev_info(&pf
->pdev
->dev
,
6228 "capability discovery failed, err %s aq_err %s\n",
6229 i40e_stat_str(&pf
->hw
, err
),
6230 i40e_aq_str(&pf
->hw
,
6231 pf
->hw
.aq
.asq_last_status
));
6236 if (((pf
->hw
.aq
.fw_maj_ver
== 2) && (pf
->hw
.aq
.fw_min_ver
< 22)) ||
6237 (pf
->hw
.aq
.fw_maj_ver
< 2)) {
6238 pf
->hw
.func_caps
.num_msix_vectors
++;
6239 pf
->hw
.func_caps
.num_msix_vectors_vf
++;
6242 if (pf
->hw
.debug_mask
& I40E_DEBUG_USER
)
6243 dev_info(&pf
->pdev
->dev
,
6244 "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",
6245 pf
->hw
.pf_id
, pf
->hw
.func_caps
.num_vfs
,
6246 pf
->hw
.func_caps
.num_msix_vectors
,
6247 pf
->hw
.func_caps
.num_msix_vectors_vf
,
6248 pf
->hw
.func_caps
.fd_filters_guaranteed
,
6249 pf
->hw
.func_caps
.fd_filters_best_effort
,
6250 pf
->hw
.func_caps
.num_tx_qp
,
6251 pf
->hw
.func_caps
.num_vsis
);
6253 #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
6254 + pf->hw.func_caps.num_vfs)
6255 if (pf
->hw
.revision_id
== 0 && (DEF_NUM_VSI
> pf
->hw
.func_caps
.num_vsis
)) {
6256 dev_info(&pf
->pdev
->dev
,
6257 "got num_vsis %d, setting num_vsis to %d\n",
6258 pf
->hw
.func_caps
.num_vsis
, DEF_NUM_VSI
);
6259 pf
->hw
.func_caps
.num_vsis
= DEF_NUM_VSI
;
6265 static int i40e_vsi_clear(struct i40e_vsi
*vsi
);
6268 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
6269 * @pf: board private structure
6271 static void i40e_fdir_sb_setup(struct i40e_pf
*pf
)
6273 struct i40e_vsi
*vsi
;
6276 /* quick workaround for an NVM issue that leaves a critical register
6279 if (!rd32(&pf
->hw
, I40E_GLQF_HKEY(0))) {
6280 static const u32 hkey
[] = {
6281 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
6282 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
6283 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
6286 for (i
= 0; i
<= I40E_GLQF_HKEY_MAX_INDEX
; i
++)
6287 wr32(&pf
->hw
, I40E_GLQF_HKEY(i
), hkey
[i
]);
6290 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
6293 /* find existing VSI and see if it needs configuring */
6295 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
6296 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
6302 /* create a new VSI if none exists */
6304 vsi
= i40e_vsi_setup(pf
, I40E_VSI_FDIR
,
6305 pf
->vsi
[pf
->lan_vsi
]->seid
, 0);
6307 dev_info(&pf
->pdev
->dev
, "Couldn't create FDir VSI\n");
6308 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
6313 i40e_vsi_setup_irqhandler(vsi
, i40e_fdir_clean_ring
);
6317 * i40e_fdir_teardown - release the Flow Director resources
6318 * @pf: board private structure
6320 static void i40e_fdir_teardown(struct i40e_pf
*pf
)
6324 i40e_fdir_filter_exit(pf
);
6325 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
6326 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
6327 i40e_vsi_release(pf
->vsi
[i
]);
6334 * i40e_prep_for_reset - prep for the core to reset
6335 * @pf: board private structure
6337 * Close up the VFs and other things in prep for PF Reset.
6339 static void i40e_prep_for_reset(struct i40e_pf
*pf
)
6341 struct i40e_hw
*hw
= &pf
->hw
;
6342 i40e_status ret
= 0;
6345 clear_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
);
6346 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
))
6349 dev_dbg(&pf
->pdev
->dev
, "Tearing down internal switch for reset\n");
6351 /* quiesce the VSIs and their queues that are not already DOWN */
6352 i40e_pf_quiesce_all_vsi(pf
);
6354 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
6356 pf
->vsi
[v
]->seid
= 0;
6359 i40e_shutdown_adminq(&pf
->hw
);
6361 /* call shutdown HMC */
6362 if (hw
->hmc
.hmc_obj
) {
6363 ret
= i40e_shutdown_lan_hmc(hw
);
6365 dev_warn(&pf
->pdev
->dev
,
6366 "shutdown_lan_hmc failed: %d\n", ret
);
6371 * i40e_send_version - update firmware with driver version
6374 static void i40e_send_version(struct i40e_pf
*pf
)
6376 struct i40e_driver_version dv
;
6378 dv
.major_version
= DRV_VERSION_MAJOR
;
6379 dv
.minor_version
= DRV_VERSION_MINOR
;
6380 dv
.build_version
= DRV_VERSION_BUILD
;
6381 dv
.subbuild_version
= 0;
6382 strlcpy(dv
.driver_string
, DRV_VERSION
, sizeof(dv
.driver_string
));
6383 i40e_aq_send_driver_version(&pf
->hw
, &dv
, NULL
);
6387 * i40e_reset_and_rebuild - reset and rebuild using a saved config
6388 * @pf: board private structure
6389 * @reinit: if the Main VSI needs to re-initialized.
6391 static void i40e_reset_and_rebuild(struct i40e_pf
*pf
, bool reinit
)
6393 struct i40e_hw
*hw
= &pf
->hw
;
6394 u8 set_fc_aq_fail
= 0;
6398 /* Now we wait for GRST to settle out.
6399 * We don't have to delete the VEBs or VSIs from the hw switch
6400 * because the reset will make them disappear.
6402 ret
= i40e_pf_reset(hw
);
6404 dev_info(&pf
->pdev
->dev
, "PF reset failed, %d\n", ret
);
6405 set_bit(__I40E_RESET_FAILED
, &pf
->state
);
6406 goto clear_recovery
;
6410 if (test_bit(__I40E_DOWN
, &pf
->state
))
6411 goto clear_recovery
;
6412 dev_dbg(&pf
->pdev
->dev
, "Rebuilding internal switch\n");
6414 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
6415 ret
= i40e_init_adminq(&pf
->hw
);
6417 dev_info(&pf
->pdev
->dev
, "Rebuild AdminQ failed, err %s aq_err %s\n",
6418 i40e_stat_str(&pf
->hw
, ret
),
6419 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6420 goto clear_recovery
;
6423 /* re-verify the eeprom if we just had an EMP reset */
6424 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED
, &pf
->state
))
6425 i40e_verify_eeprom(pf
);
6427 i40e_clear_pxe_mode(hw
);
6428 ret
= i40e_get_capabilities(pf
);
6430 goto end_core_reset
;
6432 ret
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
6433 hw
->func_caps
.num_rx_qp
,
6434 pf
->fcoe_hmc_cntx_num
, pf
->fcoe_hmc_filt_num
);
6436 dev_info(&pf
->pdev
->dev
, "init_lan_hmc failed: %d\n", ret
);
6437 goto end_core_reset
;
6439 ret
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
6441 dev_info(&pf
->pdev
->dev
, "configure_lan_hmc failed: %d\n", ret
);
6442 goto end_core_reset
;
6445 #ifdef CONFIG_I40E_DCB
6446 ret
= i40e_init_pf_dcb(pf
);
6448 dev_info(&pf
->pdev
->dev
, "DCB init failed %d, disabled\n", ret
);
6449 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
6450 /* Continue without DCB enabled */
6452 #endif /* CONFIG_I40E_DCB */
6454 ret
= i40e_init_pf_fcoe(pf
);
6456 dev_info(&pf
->pdev
->dev
, "init_pf_fcoe failed: %d\n", ret
);
6459 /* do basic switch setup */
6460 ret
= i40e_setup_pf_switch(pf
, reinit
);
6462 goto end_core_reset
;
6464 /* driver is only interested in link up/down and module qualification
6465 * reports from firmware
6467 ret
= i40e_aq_set_phy_int_mask(&pf
->hw
,
6468 I40E_AQ_EVENT_LINK_UPDOWN
|
6469 I40E_AQ_EVENT_MODULE_QUAL_FAIL
, NULL
);
6471 dev_info(&pf
->pdev
->dev
, "set phy mask fail, err %s aq_err %s\n",
6472 i40e_stat_str(&pf
->hw
, ret
),
6473 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6475 /* make sure our flow control settings are restored */
6476 ret
= i40e_set_fc(&pf
->hw
, &set_fc_aq_fail
, true);
6478 dev_info(&pf
->pdev
->dev
, "set fc fail, err %s aq_err %s\n",
6479 i40e_stat_str(&pf
->hw
, ret
),
6480 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6482 /* Rebuild the VSIs and VEBs that existed before reset.
6483 * They are still in our local switch element arrays, so only
6484 * need to rebuild the switch model in the HW.
6486 * If there were VEBs but the reconstitution failed, we'll try
6487 * try to recover minimal use by getting the basic PF VSI working.
6489 if (pf
->vsi
[pf
->lan_vsi
]->uplink_seid
!= pf
->mac_seid
) {
6490 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild switch\n");
6491 /* find the one VEB connected to the MAC, and find orphans */
6492 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
6496 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
||
6497 pf
->veb
[v
]->uplink_seid
== 0) {
6498 ret
= i40e_reconstitute_veb(pf
->veb
[v
]);
6503 /* If Main VEB failed, we're in deep doodoo,
6504 * so give up rebuilding the switch and set up
6505 * for minimal rebuild of PF VSI.
6506 * If orphan failed, we'll report the error
6507 * but try to keep going.
6509 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
) {
6510 dev_info(&pf
->pdev
->dev
,
6511 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
6513 pf
->vsi
[pf
->lan_vsi
]->uplink_seid
6516 } else if (pf
->veb
[v
]->uplink_seid
== 0) {
6517 dev_info(&pf
->pdev
->dev
,
6518 "rebuild of orphan VEB failed: %d\n",
6525 if (pf
->vsi
[pf
->lan_vsi
]->uplink_seid
== pf
->mac_seid
) {
6526 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild PF VSI\n");
6527 /* no VEB, so rebuild only the Main VSI */
6528 ret
= i40e_add_vsi(pf
->vsi
[pf
->lan_vsi
]);
6530 dev_info(&pf
->pdev
->dev
,
6531 "rebuild of Main VSI failed: %d\n", ret
);
6532 goto end_core_reset
;
6536 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
6537 (pf
->hw
.aq
.fw_maj_ver
< 4)) {
6539 ret
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
6541 dev_info(&pf
->pdev
->dev
, "link restart failed, err %s aq_err %s\n",
6542 i40e_stat_str(&pf
->hw
, ret
),
6543 i40e_aq_str(&pf
->hw
,
6544 pf
->hw
.aq
.asq_last_status
));
6546 /* reinit the misc interrupt */
6547 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
6548 ret
= i40e_setup_misc_vector(pf
);
6550 /* restart the VSIs that were rebuilt and running before the reset */
6551 i40e_pf_unquiesce_all_vsi(pf
);
6553 if (pf
->num_alloc_vfs
) {
6554 for (v
= 0; v
< pf
->num_alloc_vfs
; v
++)
6555 i40e_reset_vf(&pf
->vf
[v
], true);
6558 /* tell the firmware that we're starting */
6559 i40e_send_version(pf
);
6562 clear_bit(__I40E_RESET_FAILED
, &pf
->state
);
6564 clear_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
);
6568 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
6569 * @pf: board private structure
6571 * Close up the VFs and other things in prep for a Core Reset,
6572 * then get ready to rebuild the world.
6574 static void i40e_handle_reset_warning(struct i40e_pf
*pf
)
6576 i40e_prep_for_reset(pf
);
6577 i40e_reset_and_rebuild(pf
, false);
6581 * i40e_handle_mdd_event
6582 * @pf: pointer to the PF structure
6584 * Called from the MDD irq handler to identify possibly malicious vfs
6586 static void i40e_handle_mdd_event(struct i40e_pf
*pf
)
6588 struct i40e_hw
*hw
= &pf
->hw
;
6589 bool mdd_detected
= false;
6590 bool pf_mdd_detected
= false;
6595 if (!test_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
))
6598 /* find what triggered the MDD event */
6599 reg
= rd32(hw
, I40E_GL_MDET_TX
);
6600 if (reg
& I40E_GL_MDET_TX_VALID_MASK
) {
6601 u8 pf_num
= (reg
& I40E_GL_MDET_TX_PF_NUM_MASK
) >>
6602 I40E_GL_MDET_TX_PF_NUM_SHIFT
;
6603 u16 vf_num
= (reg
& I40E_GL_MDET_TX_VF_NUM_MASK
) >>
6604 I40E_GL_MDET_TX_VF_NUM_SHIFT
;
6605 u8 event
= (reg
& I40E_GL_MDET_TX_EVENT_MASK
) >>
6606 I40E_GL_MDET_TX_EVENT_SHIFT
;
6607 u16 queue
= ((reg
& I40E_GL_MDET_TX_QUEUE_MASK
) >>
6608 I40E_GL_MDET_TX_QUEUE_SHIFT
) -
6609 pf
->hw
.func_caps
.base_queue
;
6610 if (netif_msg_tx_err(pf
))
6611 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
6612 event
, queue
, pf_num
, vf_num
);
6613 wr32(hw
, I40E_GL_MDET_TX
, 0xffffffff);
6614 mdd_detected
= true;
6616 reg
= rd32(hw
, I40E_GL_MDET_RX
);
6617 if (reg
& I40E_GL_MDET_RX_VALID_MASK
) {
6618 u8 func
= (reg
& I40E_GL_MDET_RX_FUNCTION_MASK
) >>
6619 I40E_GL_MDET_RX_FUNCTION_SHIFT
;
6620 u8 event
= (reg
& I40E_GL_MDET_RX_EVENT_MASK
) >>
6621 I40E_GL_MDET_RX_EVENT_SHIFT
;
6622 u16 queue
= ((reg
& I40E_GL_MDET_RX_QUEUE_MASK
) >>
6623 I40E_GL_MDET_RX_QUEUE_SHIFT
) -
6624 pf
->hw
.func_caps
.base_queue
;
6625 if (netif_msg_rx_err(pf
))
6626 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
6627 event
, queue
, func
);
6628 wr32(hw
, I40E_GL_MDET_RX
, 0xffffffff);
6629 mdd_detected
= true;
6633 reg
= rd32(hw
, I40E_PF_MDET_TX
);
6634 if (reg
& I40E_PF_MDET_TX_VALID_MASK
) {
6635 wr32(hw
, I40E_PF_MDET_TX
, 0xFFFF);
6636 dev_info(&pf
->pdev
->dev
, "TX driver issue detected, PF reset issued\n");
6637 pf_mdd_detected
= true;
6639 reg
= rd32(hw
, I40E_PF_MDET_RX
);
6640 if (reg
& I40E_PF_MDET_RX_VALID_MASK
) {
6641 wr32(hw
, I40E_PF_MDET_RX
, 0xFFFF);
6642 dev_info(&pf
->pdev
->dev
, "RX driver issue detected, PF reset issued\n");
6643 pf_mdd_detected
= true;
6645 /* Queue belongs to the PF, initiate a reset */
6646 if (pf_mdd_detected
) {
6647 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
6648 i40e_service_event_schedule(pf
);
6652 /* see if one of the VFs needs its hand slapped */
6653 for (i
= 0; i
< pf
->num_alloc_vfs
&& mdd_detected
; i
++) {
6655 reg
= rd32(hw
, I40E_VP_MDET_TX(i
));
6656 if (reg
& I40E_VP_MDET_TX_VALID_MASK
) {
6657 wr32(hw
, I40E_VP_MDET_TX(i
), 0xFFFF);
6658 vf
->num_mdd_events
++;
6659 dev_info(&pf
->pdev
->dev
, "TX driver issue detected on VF %d\n",
6663 reg
= rd32(hw
, I40E_VP_MDET_RX(i
));
6664 if (reg
& I40E_VP_MDET_RX_VALID_MASK
) {
6665 wr32(hw
, I40E_VP_MDET_RX(i
), 0xFFFF);
6666 vf
->num_mdd_events
++;
6667 dev_info(&pf
->pdev
->dev
, "RX driver issue detected on VF %d\n",
6671 if (vf
->num_mdd_events
> I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED
) {
6672 dev_info(&pf
->pdev
->dev
,
6673 "Too many MDD events on VF %d, disabled\n", i
);
6674 dev_info(&pf
->pdev
->dev
,
6675 "Use PF Control I/F to re-enable the VF\n");
6676 set_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
);
6680 /* re-enable mdd interrupt cause */
6681 clear_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
);
6682 reg
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
6683 reg
|= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
6684 wr32(hw
, I40E_PFINT_ICR0_ENA
, reg
);
6688 #ifdef CONFIG_I40E_VXLAN
6690 * i40e_sync_vxlan_filters_subtask - Sync the VSI filter list with HW
6691 * @pf: board private structure
6693 static void i40e_sync_vxlan_filters_subtask(struct i40e_pf
*pf
)
6695 struct i40e_hw
*hw
= &pf
->hw
;
6700 if (!(pf
->flags
& I40E_FLAG_VXLAN_FILTER_SYNC
))
6703 pf
->flags
&= ~I40E_FLAG_VXLAN_FILTER_SYNC
;
6705 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
6706 if (pf
->pending_vxlan_bitmap
& BIT_ULL(i
)) {
6707 pf
->pending_vxlan_bitmap
&= ~BIT_ULL(i
);
6708 port
= pf
->vxlan_ports
[i
];
6710 ret
= i40e_aq_add_udp_tunnel(hw
, ntohs(port
),
6711 I40E_AQC_TUNNEL_TYPE_VXLAN
,
6714 ret
= i40e_aq_del_udp_tunnel(hw
, i
, NULL
);
6717 dev_info(&pf
->pdev
->dev
,
6718 "%s vxlan port %d, index %d failed, err %s aq_err %s\n",
6719 port
? "add" : "delete",
6721 i40e_stat_str(&pf
->hw
, ret
),
6722 i40e_aq_str(&pf
->hw
,
6723 pf
->hw
.aq
.asq_last_status
));
6724 pf
->vxlan_ports
[i
] = 0;
6732 * i40e_service_task - Run the driver's async subtasks
6733 * @work: pointer to work_struct containing our data
6735 static void i40e_service_task(struct work_struct
*work
)
6737 struct i40e_pf
*pf
= container_of(work
,
6740 unsigned long start_time
= jiffies
;
6742 /* don't bother with service tasks if a reset is in progress */
6743 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
)) {
6744 i40e_service_event_complete(pf
);
6748 i40e_reset_subtask(pf
);
6749 i40e_handle_mdd_event(pf
);
6750 i40e_vc_process_vflr_event(pf
);
6751 i40e_watchdog_subtask(pf
);
6752 i40e_fdir_reinit_subtask(pf
);
6753 i40e_sync_filters_subtask(pf
);
6754 #ifdef CONFIG_I40E_VXLAN
6755 i40e_sync_vxlan_filters_subtask(pf
);
6757 i40e_clean_adminq_subtask(pf
);
6759 i40e_service_event_complete(pf
);
6761 /* If the tasks have taken longer than one timer cycle or there
6762 * is more work to be done, reschedule the service task now
6763 * rather than wait for the timer to tick again.
6765 if (time_after(jiffies
, (start_time
+ pf
->service_timer_period
)) ||
6766 test_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
) ||
6767 test_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
) ||
6768 test_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
))
6769 i40e_service_event_schedule(pf
);
6773 * i40e_service_timer - timer callback
6774 * @data: pointer to PF struct
6776 static void i40e_service_timer(unsigned long data
)
6778 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
6780 mod_timer(&pf
->service_timer
,
6781 round_jiffies(jiffies
+ pf
->service_timer_period
));
6782 i40e_service_event_schedule(pf
);
6786 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
6787 * @vsi: the VSI being configured
6789 static int i40e_set_num_rings_in_vsi(struct i40e_vsi
*vsi
)
6791 struct i40e_pf
*pf
= vsi
->back
;
6793 switch (vsi
->type
) {
6795 vsi
->alloc_queue_pairs
= pf
->num_lan_qps
;
6796 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
6797 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6798 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
6799 vsi
->num_q_vectors
= pf
->num_lan_msix
;
6801 vsi
->num_q_vectors
= 1;
6806 vsi
->alloc_queue_pairs
= 1;
6807 vsi
->num_desc
= ALIGN(I40E_FDIR_RING_COUNT
,
6808 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6809 vsi
->num_q_vectors
= 1;
6812 case I40E_VSI_VMDQ2
:
6813 vsi
->alloc_queue_pairs
= pf
->num_vmdq_qps
;
6814 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
6815 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6816 vsi
->num_q_vectors
= pf
->num_vmdq_msix
;
6819 case I40E_VSI_SRIOV
:
6820 vsi
->alloc_queue_pairs
= pf
->num_vf_qps
;
6821 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
6822 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6827 vsi
->alloc_queue_pairs
= pf
->num_fcoe_qps
;
6828 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
6829 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6830 vsi
->num_q_vectors
= pf
->num_fcoe_msix
;
6833 #endif /* I40E_FCOE */
6843 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
6844 * @type: VSI pointer
6845 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
6847 * On error: returns error code (negative)
6848 * On success: returns 0
6850 static int i40e_vsi_alloc_arrays(struct i40e_vsi
*vsi
, bool alloc_qvectors
)
6855 /* allocate memory for both Tx and Rx ring pointers */
6856 size
= sizeof(struct i40e_ring
*) * vsi
->alloc_queue_pairs
* 2;
6857 vsi
->tx_rings
= kzalloc(size
, GFP_KERNEL
);
6860 vsi
->rx_rings
= &vsi
->tx_rings
[vsi
->alloc_queue_pairs
];
6862 if (alloc_qvectors
) {
6863 /* allocate memory for q_vector pointers */
6864 size
= sizeof(struct i40e_q_vector
*) * vsi
->num_q_vectors
;
6865 vsi
->q_vectors
= kzalloc(size
, GFP_KERNEL
);
6866 if (!vsi
->q_vectors
) {
6874 kfree(vsi
->tx_rings
);
6879 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
6880 * @pf: board private structure
6881 * @type: type of VSI
6883 * On error: returns error code (negative)
6884 * On success: returns vsi index in PF (positive)
6886 static int i40e_vsi_mem_alloc(struct i40e_pf
*pf
, enum i40e_vsi_type type
)
6889 struct i40e_vsi
*vsi
;
6893 /* Need to protect the allocation of the VSIs at the PF level */
6894 mutex_lock(&pf
->switch_mutex
);
6896 /* VSI list may be fragmented if VSI creation/destruction has
6897 * been happening. We can afford to do a quick scan to look
6898 * for any free VSIs in the list.
6900 * find next empty vsi slot, looping back around if necessary
6903 while (i
< pf
->num_alloc_vsi
&& pf
->vsi
[i
])
6905 if (i
>= pf
->num_alloc_vsi
) {
6907 while (i
< pf
->next_vsi
&& pf
->vsi
[i
])
6911 if (i
< pf
->num_alloc_vsi
&& !pf
->vsi
[i
]) {
6912 vsi_idx
= i
; /* Found one! */
6915 goto unlock_pf
; /* out of VSI slots! */
6919 vsi
= kzalloc(sizeof(*vsi
), GFP_KERNEL
);
6926 set_bit(__I40E_DOWN
, &vsi
->state
);
6929 vsi
->rx_itr_setting
= pf
->rx_itr_default
;
6930 vsi
->tx_itr_setting
= pf
->tx_itr_default
;
6931 vsi
->rss_table_size
= (vsi
->type
== I40E_VSI_MAIN
) ?
6932 pf
->rss_table_size
: 64;
6933 vsi
->netdev_registered
= false;
6934 vsi
->work_limit
= I40E_DEFAULT_IRQ_WORK
;
6935 INIT_LIST_HEAD(&vsi
->mac_filter_list
);
6936 vsi
->irqs_ready
= false;
6938 ret
= i40e_set_num_rings_in_vsi(vsi
);
6942 ret
= i40e_vsi_alloc_arrays(vsi
, true);
6946 /* Setup default MSIX irq handler for VSI */
6947 i40e_vsi_setup_irqhandler(vsi
, i40e_msix_clean_rings
);
6949 pf
->vsi
[vsi_idx
] = vsi
;
6954 pf
->next_vsi
= i
- 1;
6957 mutex_unlock(&pf
->switch_mutex
);
6962 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
6963 * @type: VSI pointer
6964 * @free_qvectors: a bool to specify if q_vectors need to be freed.
6966 * On error: returns error code (negative)
6967 * On success: returns 0
6969 static void i40e_vsi_free_arrays(struct i40e_vsi
*vsi
, bool free_qvectors
)
6971 /* free the ring and vector containers */
6972 if (free_qvectors
) {
6973 kfree(vsi
->q_vectors
);
6974 vsi
->q_vectors
= NULL
;
6976 kfree(vsi
->tx_rings
);
6977 vsi
->tx_rings
= NULL
;
6978 vsi
->rx_rings
= NULL
;
6982 * i40e_vsi_clear - Deallocate the VSI provided
6983 * @vsi: the VSI being un-configured
6985 static int i40e_vsi_clear(struct i40e_vsi
*vsi
)
6996 mutex_lock(&pf
->switch_mutex
);
6997 if (!pf
->vsi
[vsi
->idx
]) {
6998 dev_err(&pf
->pdev
->dev
, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
6999 vsi
->idx
, vsi
->idx
, vsi
, vsi
->type
);
7003 if (pf
->vsi
[vsi
->idx
] != vsi
) {
7004 dev_err(&pf
->pdev
->dev
,
7005 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
7006 pf
->vsi
[vsi
->idx
]->idx
,
7008 pf
->vsi
[vsi
->idx
]->type
,
7009 vsi
->idx
, vsi
, vsi
->type
);
7013 /* updates the PF for this cleared vsi */
7014 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
7015 i40e_put_lump(pf
->irq_pile
, vsi
->base_vector
, vsi
->idx
);
7017 i40e_vsi_free_arrays(vsi
, true);
7019 pf
->vsi
[vsi
->idx
] = NULL
;
7020 if (vsi
->idx
< pf
->next_vsi
)
7021 pf
->next_vsi
= vsi
->idx
;
7024 mutex_unlock(&pf
->switch_mutex
);
7032 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
7033 * @vsi: the VSI being cleaned
7035 static void i40e_vsi_clear_rings(struct i40e_vsi
*vsi
)
7039 if (vsi
->tx_rings
&& vsi
->tx_rings
[0]) {
7040 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
7041 kfree_rcu(vsi
->tx_rings
[i
], rcu
);
7042 vsi
->tx_rings
[i
] = NULL
;
7043 vsi
->rx_rings
[i
] = NULL
;
7049 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
7050 * @vsi: the VSI being configured
7052 static int i40e_alloc_rings(struct i40e_vsi
*vsi
)
7054 struct i40e_ring
*tx_ring
, *rx_ring
;
7055 struct i40e_pf
*pf
= vsi
->back
;
7058 /* Set basic values in the rings to be used later during open() */
7059 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
7060 /* allocate space for both Tx and Rx in one shot */
7061 tx_ring
= kzalloc(sizeof(struct i40e_ring
) * 2, GFP_KERNEL
);
7065 tx_ring
->queue_index
= i
;
7066 tx_ring
->reg_idx
= vsi
->base_queue
+ i
;
7067 tx_ring
->ring_active
= false;
7069 tx_ring
->netdev
= vsi
->netdev
;
7070 tx_ring
->dev
= &pf
->pdev
->dev
;
7071 tx_ring
->count
= vsi
->num_desc
;
7073 tx_ring
->dcb_tc
= 0;
7074 vsi
->tx_rings
[i
] = tx_ring
;
7076 rx_ring
= &tx_ring
[1];
7077 rx_ring
->queue_index
= i
;
7078 rx_ring
->reg_idx
= vsi
->base_queue
+ i
;
7079 rx_ring
->ring_active
= false;
7081 rx_ring
->netdev
= vsi
->netdev
;
7082 rx_ring
->dev
= &pf
->pdev
->dev
;
7083 rx_ring
->count
= vsi
->num_desc
;
7085 rx_ring
->dcb_tc
= 0;
7086 if (pf
->flags
& I40E_FLAG_16BYTE_RX_DESC_ENABLED
)
7087 set_ring_16byte_desc_enabled(rx_ring
);
7089 clear_ring_16byte_desc_enabled(rx_ring
);
7090 vsi
->rx_rings
[i
] = rx_ring
;
7096 i40e_vsi_clear_rings(vsi
);
7101 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
7102 * @pf: board private structure
7103 * @vectors: the number of MSI-X vectors to request
7105 * Returns the number of vectors reserved, or error
7107 static int i40e_reserve_msix_vectors(struct i40e_pf
*pf
, int vectors
)
7109 vectors
= pci_enable_msix_range(pf
->pdev
, pf
->msix_entries
,
7110 I40E_MIN_MSIX
, vectors
);
7112 dev_info(&pf
->pdev
->dev
,
7113 "MSI-X vector reservation failed: %d\n", vectors
);
7121 * i40e_init_msix - Setup the MSIX capability
7122 * @pf: board private structure
7124 * Work with the OS to set up the MSIX vectors needed.
7126 * Returns the number of vectors reserved or negative on failure
7128 static int i40e_init_msix(struct i40e_pf
*pf
)
7130 struct i40e_hw
*hw
= &pf
->hw
;
7135 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
7138 /* The number of vectors we'll request will be comprised of:
7139 * - Add 1 for "other" cause for Admin Queue events, etc.
7140 * - The number of LAN queue pairs
7141 * - Queues being used for RSS.
7142 * We don't need as many as max_rss_size vectors.
7143 * use rss_size instead in the calculation since that
7144 * is governed by number of cpus in the system.
7145 * - assumes symmetric Tx/Rx pairing
7146 * - The number of VMDq pairs
7148 * - The number of FCOE qps.
7150 * Once we count this up, try the request.
7152 * If we can't get what we want, we'll simplify to nearly nothing
7153 * and try again. If that still fails, we punt.
7155 vectors_left
= hw
->func_caps
.num_msix_vectors
;
7158 /* reserve one vector for miscellaneous handler */
7164 /* reserve vectors for the main PF traffic queues */
7165 pf
->num_lan_msix
= min_t(int, num_online_cpus(), vectors_left
);
7166 vectors_left
-= pf
->num_lan_msix
;
7167 v_budget
+= pf
->num_lan_msix
;
7169 /* reserve one vector for sideband flow director */
7170 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
7175 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7180 /* can we reserve enough for FCoE? */
7181 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7183 pf
->num_fcoe_msix
= 0;
7184 else if (vectors_left
>= pf
->num_fcoe_qps
)
7185 pf
->num_fcoe_msix
= pf
->num_fcoe_qps
;
7187 pf
->num_fcoe_msix
= 1;
7188 v_budget
+= pf
->num_fcoe_msix
;
7189 vectors_left
-= pf
->num_fcoe_msix
;
7193 /* any vectors left over go for VMDq support */
7194 if (pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) {
7195 int vmdq_vecs_wanted
= pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
;
7196 int vmdq_vecs
= min_t(int, vectors_left
, vmdq_vecs_wanted
);
7198 /* if we're short on vectors for what's desired, we limit
7199 * the queues per vmdq. If this is still more than are
7200 * available, the user will need to change the number of
7201 * queues/vectors used by the PF later with the ethtool
7204 if (vmdq_vecs
< vmdq_vecs_wanted
)
7205 pf
->num_vmdq_qps
= 1;
7206 pf
->num_vmdq_msix
= pf
->num_vmdq_qps
;
7208 v_budget
+= vmdq_vecs
;
7209 vectors_left
-= vmdq_vecs
;
7212 pf
->msix_entries
= kcalloc(v_budget
, sizeof(struct msix_entry
),
7214 if (!pf
->msix_entries
)
7217 for (i
= 0; i
< v_budget
; i
++)
7218 pf
->msix_entries
[i
].entry
= i
;
7219 v_actual
= i40e_reserve_msix_vectors(pf
, v_budget
);
7221 if (v_actual
!= v_budget
) {
7222 /* If we have limited resources, we will start with no vectors
7223 * for the special features and then allocate vectors to some
7224 * of these features based on the policy and at the end disable
7225 * the features that did not get any vectors.
7228 pf
->num_fcoe_qps
= 0;
7229 pf
->num_fcoe_msix
= 0;
7231 pf
->num_vmdq_msix
= 0;
7234 if (v_actual
< I40E_MIN_MSIX
) {
7235 pf
->flags
&= ~I40E_FLAG_MSIX_ENABLED
;
7236 kfree(pf
->msix_entries
);
7237 pf
->msix_entries
= NULL
;
7240 } else if (v_actual
== I40E_MIN_MSIX
) {
7241 /* Adjust for minimal MSIX use */
7242 pf
->num_vmdq_vsis
= 0;
7243 pf
->num_vmdq_qps
= 0;
7244 pf
->num_lan_qps
= 1;
7245 pf
->num_lan_msix
= 1;
7247 } else if (v_actual
!= v_budget
) {
7250 /* reserve the misc vector */
7253 /* Scale vector usage down */
7254 pf
->num_vmdq_msix
= 1; /* force VMDqs to only one vector */
7255 pf
->num_vmdq_vsis
= 1;
7256 pf
->num_vmdq_qps
= 1;
7257 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7259 /* partition out the remaining vectors */
7262 pf
->num_lan_msix
= 1;
7266 /* give one vector to FCoE */
7267 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7268 pf
->num_lan_msix
= 1;
7269 pf
->num_fcoe_msix
= 1;
7272 pf
->num_lan_msix
= 2;
7277 /* give one vector to FCoE */
7278 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7279 pf
->num_fcoe_msix
= 1;
7283 /* give the rest to the PF */
7284 pf
->num_lan_msix
= min_t(int, vec
, pf
->num_lan_qps
);
7289 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
7290 (pf
->num_vmdq_msix
== 0)) {
7291 dev_info(&pf
->pdev
->dev
, "VMDq disabled, not enough MSI-X vectors\n");
7292 pf
->flags
&= ~I40E_FLAG_VMDQ_ENABLED
;
7296 if ((pf
->flags
& I40E_FLAG_FCOE_ENABLED
) && (pf
->num_fcoe_msix
== 0)) {
7297 dev_info(&pf
->pdev
->dev
, "FCOE disabled, not enough MSI-X vectors\n");
7298 pf
->flags
&= ~I40E_FLAG_FCOE_ENABLED
;
7305 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
7306 * @vsi: the VSI being configured
7307 * @v_idx: index of the vector in the vsi struct
7309 * We allocate one q_vector. If allocation fails we return -ENOMEM.
7311 static int i40e_vsi_alloc_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
7313 struct i40e_q_vector
*q_vector
;
7315 /* allocate q_vector */
7316 q_vector
= kzalloc(sizeof(struct i40e_q_vector
), GFP_KERNEL
);
7320 q_vector
->vsi
= vsi
;
7321 q_vector
->v_idx
= v_idx
;
7322 cpumask_set_cpu(v_idx
, &q_vector
->affinity_mask
);
7324 netif_napi_add(vsi
->netdev
, &q_vector
->napi
,
7325 i40e_napi_poll
, NAPI_POLL_WEIGHT
);
7327 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
7328 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
7330 /* tie q_vector and vsi together */
7331 vsi
->q_vectors
[v_idx
] = q_vector
;
7337 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
7338 * @vsi: the VSI being configured
7340 * We allocate one q_vector per queue interrupt. If allocation fails we
7343 static int i40e_vsi_alloc_q_vectors(struct i40e_vsi
*vsi
)
7345 struct i40e_pf
*pf
= vsi
->back
;
7346 int v_idx
, num_q_vectors
;
7349 /* if not MSIX, give the one vector only to the LAN VSI */
7350 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
7351 num_q_vectors
= vsi
->num_q_vectors
;
7352 else if (vsi
== pf
->vsi
[pf
->lan_vsi
])
7357 for (v_idx
= 0; v_idx
< num_q_vectors
; v_idx
++) {
7358 err
= i40e_vsi_alloc_q_vector(vsi
, v_idx
);
7367 i40e_free_q_vector(vsi
, v_idx
);
7373 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
7374 * @pf: board private structure to initialize
7376 static int i40e_init_interrupt_scheme(struct i40e_pf
*pf
)
7381 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
7382 vectors
= i40e_init_msix(pf
);
7384 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
|
7386 I40E_FLAG_FCOE_ENABLED
|
7388 I40E_FLAG_RSS_ENABLED
|
7389 I40E_FLAG_DCB_CAPABLE
|
7390 I40E_FLAG_SRIOV_ENABLED
|
7391 I40E_FLAG_FD_SB_ENABLED
|
7392 I40E_FLAG_FD_ATR_ENABLED
|
7393 I40E_FLAG_VMDQ_ENABLED
);
7395 /* rework the queue expectations without MSIX */
7396 i40e_determine_queue_usage(pf
);
7400 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
7401 (pf
->flags
& I40E_FLAG_MSI_ENABLED
)) {
7402 dev_info(&pf
->pdev
->dev
, "MSI-X not available, trying MSI\n");
7403 vectors
= pci_enable_msi(pf
->pdev
);
7405 dev_info(&pf
->pdev
->dev
, "MSI init failed - %d\n",
7407 pf
->flags
&= ~I40E_FLAG_MSI_ENABLED
;
7409 vectors
= 1; /* one MSI or Legacy vector */
7412 if (!(pf
->flags
& (I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
)))
7413 dev_info(&pf
->pdev
->dev
, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
7415 /* set up vector assignment tracking */
7416 size
= sizeof(struct i40e_lump_tracking
) + (sizeof(u16
) * vectors
);
7417 pf
->irq_pile
= kzalloc(size
, GFP_KERNEL
);
7418 if (!pf
->irq_pile
) {
7419 dev_err(&pf
->pdev
->dev
, "error allocating irq_pile memory\n");
7422 pf
->irq_pile
->num_entries
= vectors
;
7423 pf
->irq_pile
->search_hint
= 0;
7425 /* track first vector for misc interrupts, ignore return */
7426 (void)i40e_get_lump(pf
, pf
->irq_pile
, 1, I40E_PILE_VALID_BIT
- 1);
7432 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
7433 * @pf: board private structure
7435 * This sets up the handler for MSIX 0, which is used to manage the
7436 * non-queue interrupts, e.g. AdminQ and errors. This is not used
7437 * when in MSI or Legacy interrupt mode.
7439 static int i40e_setup_misc_vector(struct i40e_pf
*pf
)
7441 struct i40e_hw
*hw
= &pf
->hw
;
7444 /* Only request the irq if this is the first time through, and
7445 * not when we're rebuilding after a Reset
7447 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
)) {
7448 err
= request_irq(pf
->msix_entries
[0].vector
,
7449 i40e_intr
, 0, pf
->int_name
, pf
);
7451 dev_info(&pf
->pdev
->dev
,
7452 "request_irq for %s failed: %d\n",
7458 i40e_enable_misc_int_causes(pf
);
7460 /* associate no queues to the misc vector */
7461 wr32(hw
, I40E_PFINT_LNKLST0
, I40E_QUEUE_END_OF_LIST
);
7462 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), I40E_ITR_8K
);
7466 i40e_irq_dynamic_enable_icr0(pf
);
7472 * i40e_config_rss - Prepare for RSS if used
7473 * @pf: board private structure
7475 static int i40e_config_rss(struct i40e_pf
*pf
)
7477 u32 rss_key
[I40E_PFQF_HKEY_MAX_INDEX
+ 1];
7478 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
7479 struct i40e_hw
*hw
= &pf
->hw
;
7485 netdev_rss_key_fill(rss_key
, sizeof(rss_key
));
7486 for (i
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++)
7487 wr32(hw
, I40E_PFQF_HKEY(i
), rss_key
[i
]);
7489 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
7490 hena
= (u64
)rd32(hw
, I40E_PFQF_HENA(0)) |
7491 ((u64
)rd32(hw
, I40E_PFQF_HENA(1)) << 32);
7492 hena
|= I40E_DEFAULT_RSS_HENA
;
7493 wr32(hw
, I40E_PFQF_HENA(0), (u32
)hena
);
7494 wr32(hw
, I40E_PFQF_HENA(1), (u32
)(hena
>> 32));
7496 vsi
->rss_size
= min_t(int, pf
->rss_size
, vsi
->num_queue_pairs
);
7498 /* Check capability and Set table size and register per hw expectation*/
7499 reg_val
= rd32(hw
, I40E_PFQF_CTL_0
);
7500 if (pf
->rss_table_size
== 512)
7501 reg_val
|= I40E_PFQF_CTL_0_HASHLUTSIZE_512
;
7503 reg_val
&= ~I40E_PFQF_CTL_0_HASHLUTSIZE_512
;
7504 wr32(hw
, I40E_PFQF_CTL_0
, reg_val
);
7506 /* Populate the LUT with max no. of queues in round robin fashion */
7507 for (i
= 0, j
= 0; i
< pf
->rss_table_size
; i
++, j
++) {
7509 /* The assumption is that lan qp count will be the highest
7510 * qp count for any PF VSI that needs RSS.
7511 * If multiple VSIs need RSS support, all the qp counts
7512 * for those VSIs should be a power of 2 for RSS to work.
7513 * If LAN VSI is the only consumer for RSS then this requirement
7516 if (j
== vsi
->rss_size
)
7518 /* lut = 4-byte sliding window of 4 lut entries */
7519 lut
= (lut
<< 8) | (j
&
7520 (BIT(pf
->hw
.func_caps
.rss_table_entry_width
) - 1));
7521 /* On i = 3, we have 4 entries in lut; write to the register */
7523 wr32(hw
, I40E_PFQF_HLUT(i
>> 2), lut
);
7531 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
7532 * @pf: board private structure
7533 * @queue_count: the requested queue count for rss.
7535 * returns 0 if rss is not enabled, if enabled returns the final rss queue
7536 * count which may be different from the requested queue count.
7538 int i40e_reconfig_rss_queues(struct i40e_pf
*pf
, int queue_count
)
7540 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
7543 if (!(pf
->flags
& I40E_FLAG_RSS_ENABLED
))
7546 new_rss_size
= min_t(int, queue_count
, pf
->rss_size_max
);
7548 if (queue_count
!= vsi
->num_queue_pairs
) {
7549 vsi
->req_queue_pairs
= queue_count
;
7550 i40e_prep_for_reset(pf
);
7552 pf
->rss_size
= new_rss_size
;
7554 i40e_reset_and_rebuild(pf
, true);
7555 i40e_config_rss(pf
);
7557 dev_info(&pf
->pdev
->dev
, "RSS count: %d\n", pf
->rss_size
);
7558 return pf
->rss_size
;
7562 * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition
7563 * @pf: board private structure
7565 i40e_status
i40e_get_npar_bw_setting(struct i40e_pf
*pf
)
7568 bool min_valid
, max_valid
;
7571 status
= i40e_read_bw_from_alt_ram(&pf
->hw
, &max_bw
, &min_bw
,
7572 &min_valid
, &max_valid
);
7576 pf
->npar_min_bw
= min_bw
;
7578 pf
->npar_max_bw
= max_bw
;
7585 * i40e_set_npar_bw_setting - Set BW settings for this PF partition
7586 * @pf: board private structure
7588 i40e_status
i40e_set_npar_bw_setting(struct i40e_pf
*pf
)
7590 struct i40e_aqc_configure_partition_bw_data bw_data
;
7593 /* Set the valid bit for this PF */
7594 bw_data
.pf_valid_bits
= cpu_to_le16(BIT(pf
->hw
.pf_id
));
7595 bw_data
.max_bw
[pf
->hw
.pf_id
] = pf
->npar_max_bw
& I40E_ALT_BW_VALUE_MASK
;
7596 bw_data
.min_bw
[pf
->hw
.pf_id
] = pf
->npar_min_bw
& I40E_ALT_BW_VALUE_MASK
;
7598 /* Set the new bandwidths */
7599 status
= i40e_aq_configure_partition_bw(&pf
->hw
, &bw_data
, NULL
);
7605 * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition
7606 * @pf: board private structure
7608 i40e_status
i40e_commit_npar_bw_setting(struct i40e_pf
*pf
)
7610 /* Commit temporary BW setting to permanent NVM image */
7611 enum i40e_admin_queue_err last_aq_status
;
7615 if (pf
->hw
.partition_id
!= 1) {
7616 dev_info(&pf
->pdev
->dev
,
7617 "Commit BW only works on partition 1! This is partition %d",
7618 pf
->hw
.partition_id
);
7619 ret
= I40E_NOT_SUPPORTED
;
7623 /* Acquire NVM for read access */
7624 ret
= i40e_acquire_nvm(&pf
->hw
, I40E_RESOURCE_READ
);
7625 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
7627 dev_info(&pf
->pdev
->dev
,
7628 "Cannot acquire NVM for read access, err %s aq_err %s\n",
7629 i40e_stat_str(&pf
->hw
, ret
),
7630 i40e_aq_str(&pf
->hw
, last_aq_status
));
7634 /* Read word 0x10 of NVM - SW compatibility word 1 */
7635 ret
= i40e_aq_read_nvm(&pf
->hw
,
7636 I40E_SR_NVM_CONTROL_WORD
,
7637 0x10, sizeof(nvm_word
), &nvm_word
,
7639 /* Save off last admin queue command status before releasing
7642 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
7643 i40e_release_nvm(&pf
->hw
);
7645 dev_info(&pf
->pdev
->dev
, "NVM read error, err %s aq_err %s\n",
7646 i40e_stat_str(&pf
->hw
, ret
),
7647 i40e_aq_str(&pf
->hw
, last_aq_status
));
7651 /* Wait a bit for NVM release to complete */
7654 /* Acquire NVM for write access */
7655 ret
= i40e_acquire_nvm(&pf
->hw
, I40E_RESOURCE_WRITE
);
7656 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
7658 dev_info(&pf
->pdev
->dev
,
7659 "Cannot acquire NVM for write access, err %s aq_err %s\n",
7660 i40e_stat_str(&pf
->hw
, ret
),
7661 i40e_aq_str(&pf
->hw
, last_aq_status
));
7664 /* Write it back out unchanged to initiate update NVM,
7665 * which will force a write of the shadow (alt) RAM to
7666 * the NVM - thus storing the bandwidth values permanently.
7668 ret
= i40e_aq_update_nvm(&pf
->hw
,
7669 I40E_SR_NVM_CONTROL_WORD
,
7670 0x10, sizeof(nvm_word
),
7671 &nvm_word
, true, NULL
);
7672 /* Save off last admin queue command status before releasing
7675 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
7676 i40e_release_nvm(&pf
->hw
);
7678 dev_info(&pf
->pdev
->dev
,
7679 "BW settings NOT SAVED, err %s aq_err %s\n",
7680 i40e_stat_str(&pf
->hw
, ret
),
7681 i40e_aq_str(&pf
->hw
, last_aq_status
));
7688 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
7689 * @pf: board private structure to initialize
7691 * i40e_sw_init initializes the Adapter private data structure.
7692 * Fields are initialized based on PCI device information and
7693 * OS network device settings (MTU size).
7695 static int i40e_sw_init(struct i40e_pf
*pf
)
7700 pf
->msg_enable
= netif_msg_init(I40E_DEFAULT_MSG_ENABLE
,
7701 (NETIF_MSG_DRV
|NETIF_MSG_PROBE
|NETIF_MSG_LINK
));
7702 pf
->hw
.debug_mask
= pf
->msg_enable
| I40E_DEBUG_DIAG
;
7703 if (debug
!= -1 && debug
!= I40E_DEFAULT_MSG_ENABLE
) {
7704 if (I40E_DEBUG_USER
& debug
)
7705 pf
->hw
.debug_mask
= debug
;
7706 pf
->msg_enable
= netif_msg_init((debug
& ~I40E_DEBUG_USER
),
7707 I40E_DEFAULT_MSG_ENABLE
);
7710 /* Set default capability flags */
7711 pf
->flags
= I40E_FLAG_RX_CSUM_ENABLED
|
7712 I40E_FLAG_MSI_ENABLED
|
7713 I40E_FLAG_MSIX_ENABLED
;
7715 if (iommu_present(&pci_bus_type
))
7716 pf
->flags
|= I40E_FLAG_RX_PS_ENABLED
;
7718 pf
->flags
|= I40E_FLAG_RX_1BUF_ENABLED
;
7720 /* Set default ITR */
7721 pf
->rx_itr_default
= I40E_ITR_DYNAMIC
| I40E_ITR_RX_DEF
;
7722 pf
->tx_itr_default
= I40E_ITR_DYNAMIC
| I40E_ITR_TX_DEF
;
7724 /* Depending on PF configurations, it is possible that the RSS
7725 * maximum might end up larger than the available queues
7727 pf
->rss_size_max
= BIT(pf
->hw
.func_caps
.rss_table_entry_width
);
7729 pf
->rss_table_size
= pf
->hw
.func_caps
.rss_table_size
;
7730 pf
->rss_size_max
= min_t(int, pf
->rss_size_max
,
7731 pf
->hw
.func_caps
.num_tx_qp
);
7732 if (pf
->hw
.func_caps
.rss
) {
7733 pf
->flags
|= I40E_FLAG_RSS_ENABLED
;
7734 pf
->rss_size
= min_t(int, pf
->rss_size_max
, num_online_cpus());
7737 /* MFP mode enabled */
7738 if (pf
->hw
.func_caps
.npar_enable
|| pf
->hw
.func_caps
.flex10_enable
) {
7739 pf
->flags
|= I40E_FLAG_MFP_ENABLED
;
7740 dev_info(&pf
->pdev
->dev
, "MFP mode Enabled\n");
7741 if (i40e_get_npar_bw_setting(pf
))
7742 dev_warn(&pf
->pdev
->dev
,
7743 "Could not get NPAR bw settings\n");
7745 dev_info(&pf
->pdev
->dev
,
7746 "Min BW = %8.8x, Max BW = %8.8x\n",
7747 pf
->npar_min_bw
, pf
->npar_max_bw
);
7750 /* FW/NVM is not yet fixed in this regard */
7751 if ((pf
->hw
.func_caps
.fd_filters_guaranteed
> 0) ||
7752 (pf
->hw
.func_caps
.fd_filters_best_effort
> 0)) {
7753 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
7754 pf
->atr_sample_rate
= I40E_DEFAULT_ATR_SAMPLE_RATE
;
7755 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
)) {
7756 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
7758 dev_info(&pf
->pdev
->dev
,
7759 "Flow Director Sideband mode Disabled in MFP mode\n");
7761 pf
->fdir_pf_filter_count
=
7762 pf
->hw
.func_caps
.fd_filters_guaranteed
;
7763 pf
->hw
.fdir_shared_filter_count
=
7764 pf
->hw
.func_caps
.fd_filters_best_effort
;
7767 if (pf
->hw
.func_caps
.vmdq
) {
7768 pf
->flags
|= I40E_FLAG_VMDQ_ENABLED
;
7769 pf
->num_vmdq_vsis
= I40E_DEFAULT_NUM_VMDQ_VSI
;
7770 pf
->num_vmdq_qps
= I40E_DEFAULT_QUEUES_PER_VMDQ
;
7774 err
= i40e_init_pf_fcoe(pf
);
7776 dev_info(&pf
->pdev
->dev
, "init_pf_fcoe failed: %d\n", err
);
7778 #endif /* I40E_FCOE */
7779 #ifdef CONFIG_PCI_IOV
7780 if (pf
->hw
.func_caps
.num_vfs
&& pf
->hw
.partition_id
== 1) {
7781 pf
->num_vf_qps
= I40E_DEFAULT_QUEUES_PER_VF
;
7782 pf
->flags
|= I40E_FLAG_SRIOV_ENABLED
;
7783 pf
->num_req_vfs
= min_t(int,
7784 pf
->hw
.func_caps
.num_vfs
,
7787 #endif /* CONFIG_PCI_IOV */
7788 pf
->eeprom_version
= 0xDEAD;
7789 pf
->lan_veb
= I40E_NO_VEB
;
7790 pf
->lan_vsi
= I40E_NO_VSI
;
7792 /* set up queue assignment tracking */
7793 size
= sizeof(struct i40e_lump_tracking
)
7794 + (sizeof(u16
) * pf
->hw
.func_caps
.num_tx_qp
);
7795 pf
->qp_pile
= kzalloc(size
, GFP_KERNEL
);
7800 pf
->qp_pile
->num_entries
= pf
->hw
.func_caps
.num_tx_qp
;
7801 pf
->qp_pile
->search_hint
= 0;
7803 pf
->tx_timeout_recovery_level
= 1;
7805 mutex_init(&pf
->switch_mutex
);
7807 /* If NPAR is enabled nudge the Tx scheduler */
7808 if (pf
->hw
.func_caps
.npar_enable
&& (!i40e_get_npar_bw_setting(pf
)))
7809 i40e_set_npar_bw_setting(pf
);
7816 * i40e_set_ntuple - set the ntuple feature flag and take action
7817 * @pf: board private structure to initialize
7818 * @features: the feature set that the stack is suggesting
7820 * returns a bool to indicate if reset needs to happen
7822 bool i40e_set_ntuple(struct i40e_pf
*pf
, netdev_features_t features
)
7824 bool need_reset
= false;
7826 /* Check if Flow Director n-tuple support was enabled or disabled. If
7827 * the state changed, we need to reset.
7829 if (features
& NETIF_F_NTUPLE
) {
7830 /* Enable filters and mark for reset */
7831 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
7833 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
7835 /* turn off filters, mark for reset and clear SW filter list */
7836 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
7838 i40e_fdir_filter_exit(pf
);
7840 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7841 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7842 /* reset fd counters */
7843 pf
->fd_add_err
= pf
->fd_atr_cnt
= pf
->fd_tcp_rule
= 0;
7844 pf
->fdir_pf_active_filters
= 0;
7845 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
7846 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
7847 dev_info(&pf
->pdev
->dev
, "ATR re-enabled.\n");
7848 /* if ATR was auto disabled it can be re-enabled. */
7849 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
7850 (pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
))
7851 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
7857 * i40e_set_features - set the netdev feature flags
7858 * @netdev: ptr to the netdev being adjusted
7859 * @features: the feature set that the stack is suggesting
7861 static int i40e_set_features(struct net_device
*netdev
,
7862 netdev_features_t features
)
7864 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7865 struct i40e_vsi
*vsi
= np
->vsi
;
7866 struct i40e_pf
*pf
= vsi
->back
;
7869 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
7870 i40e_vlan_stripping_enable(vsi
);
7872 i40e_vlan_stripping_disable(vsi
);
7874 need_reset
= i40e_set_ntuple(pf
, features
);
7877 i40e_do_reset(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
7882 #ifdef CONFIG_I40E_VXLAN
7884 * i40e_get_vxlan_port_idx - Lookup a possibly offloaded for Rx UDP port
7885 * @pf: board private structure
7886 * @port: The UDP port to look up
7888 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
7890 static u8
i40e_get_vxlan_port_idx(struct i40e_pf
*pf
, __be16 port
)
7894 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
7895 if (pf
->vxlan_ports
[i
] == port
)
7903 * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up
7904 * @netdev: This physical port's netdev
7905 * @sa_family: Socket Family that VXLAN is notifying us about
7906 * @port: New UDP port number that VXLAN started listening to
7908 static void i40e_add_vxlan_port(struct net_device
*netdev
,
7909 sa_family_t sa_family
, __be16 port
)
7911 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7912 struct i40e_vsi
*vsi
= np
->vsi
;
7913 struct i40e_pf
*pf
= vsi
->back
;
7917 if (sa_family
== AF_INET6
)
7920 idx
= i40e_get_vxlan_port_idx(pf
, port
);
7922 /* Check if port already exists */
7923 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
7924 netdev_info(netdev
, "vxlan port %d already offloaded\n",
7929 /* Now check if there is space to add the new port */
7930 next_idx
= i40e_get_vxlan_port_idx(pf
, 0);
7932 if (next_idx
== I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
7933 netdev_info(netdev
, "maximum number of vxlan UDP ports reached, not adding port %d\n",
7938 /* New port: add it and mark its index in the bitmap */
7939 pf
->vxlan_ports
[next_idx
] = port
;
7940 pf
->pending_vxlan_bitmap
|= BIT_ULL(next_idx
);
7941 pf
->flags
|= I40E_FLAG_VXLAN_FILTER_SYNC
;
7943 dev_info(&pf
->pdev
->dev
, "adding vxlan port %d\n", ntohs(port
));
7947 * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away
7948 * @netdev: This physical port's netdev
7949 * @sa_family: Socket Family that VXLAN is notifying us about
7950 * @port: UDP port number that VXLAN stopped listening to
7952 static void i40e_del_vxlan_port(struct net_device
*netdev
,
7953 sa_family_t sa_family
, __be16 port
)
7955 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7956 struct i40e_vsi
*vsi
= np
->vsi
;
7957 struct i40e_pf
*pf
= vsi
->back
;
7960 if (sa_family
== AF_INET6
)
7963 idx
= i40e_get_vxlan_port_idx(pf
, port
);
7965 /* Check if port already exists */
7966 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
7967 /* if port exists, set it to 0 (mark for deletion)
7968 * and make it pending
7970 pf
->vxlan_ports
[idx
] = 0;
7971 pf
->pending_vxlan_bitmap
|= BIT_ULL(idx
);
7972 pf
->flags
|= I40E_FLAG_VXLAN_FILTER_SYNC
;
7974 dev_info(&pf
->pdev
->dev
, "deleting vxlan port %d\n",
7977 netdev_warn(netdev
, "vxlan port %d was not found, not deleting\n",
7983 static int i40e_get_phys_port_id(struct net_device
*netdev
,
7984 struct netdev_phys_item_id
*ppid
)
7986 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7987 struct i40e_pf
*pf
= np
->vsi
->back
;
7988 struct i40e_hw
*hw
= &pf
->hw
;
7990 if (!(pf
->flags
& I40E_FLAG_PORT_ID_VALID
))
7993 ppid
->id_len
= min_t(int, sizeof(hw
->mac
.port_addr
), sizeof(ppid
->id
));
7994 memcpy(ppid
->id
, hw
->mac
.port_addr
, ppid
->id_len
);
8000 * i40e_ndo_fdb_add - add an entry to the hardware database
8001 * @ndm: the input from the stack
8002 * @tb: pointer to array of nladdr (unused)
8003 * @dev: the net device pointer
8004 * @addr: the MAC address entry being added
8005 * @flags: instructions from stack about fdb operation
8007 static int i40e_ndo_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
8008 struct net_device
*dev
,
8009 const unsigned char *addr
, u16 vid
,
8012 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
8013 struct i40e_pf
*pf
= np
->vsi
->back
;
8016 if (!(pf
->flags
& I40E_FLAG_SRIOV_ENABLED
))
8020 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev
->name
);
8024 /* Hardware does not support aging addresses so if a
8025 * ndm_state is given only allow permanent addresses
8027 if (ndm
->ndm_state
&& !(ndm
->ndm_state
& NUD_PERMANENT
)) {
8028 netdev_info(dev
, "FDB only supports static addresses\n");
8032 if (is_unicast_ether_addr(addr
) || is_link_local_ether_addr(addr
))
8033 err
= dev_uc_add_excl(dev
, addr
);
8034 else if (is_multicast_ether_addr(addr
))
8035 err
= dev_mc_add_excl(dev
, addr
);
8039 /* Only return duplicate errors if NLM_F_EXCL is set */
8040 if (err
== -EEXIST
&& !(flags
& NLM_F_EXCL
))
8047 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
8048 * @dev: the netdev being configured
8049 * @nlh: RTNL message
8051 * Inserts a new hardware bridge if not already created and
8052 * enables the bridging mode requested (VEB or VEPA). If the
8053 * hardware bridge has already been inserted and the request
8054 * is to change the mode then that requires a PF reset to
8055 * allow rebuild of the components with required hardware
8056 * bridge mode enabled.
8058 static int i40e_ndo_bridge_setlink(struct net_device
*dev
,
8059 struct nlmsghdr
*nlh
,
8062 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
8063 struct i40e_vsi
*vsi
= np
->vsi
;
8064 struct i40e_pf
*pf
= vsi
->back
;
8065 struct i40e_veb
*veb
= NULL
;
8066 struct nlattr
*attr
, *br_spec
;
8069 /* Only for PF VSI for now */
8070 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
)
8073 /* Find the HW bridge for PF VSI */
8074 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
8075 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
8079 br_spec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
8081 nla_for_each_nested(attr
, br_spec
, rem
) {
8084 if (nla_type(attr
) != IFLA_BRIDGE_MODE
)
8087 mode
= nla_get_u16(attr
);
8088 if ((mode
!= BRIDGE_MODE_VEPA
) &&
8089 (mode
!= BRIDGE_MODE_VEB
))
8092 /* Insert a new HW bridge */
8094 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
8095 vsi
->tc_config
.enabled_tc
);
8097 veb
->bridge_mode
= mode
;
8098 i40e_config_bridge_mode(veb
);
8100 /* No Bridge HW offload available */
8104 } else if (mode
!= veb
->bridge_mode
) {
8105 /* Existing HW bridge but different mode needs reset */
8106 veb
->bridge_mode
= mode
;
8107 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
8108 if (mode
== BRIDGE_MODE_VEB
)
8109 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
8111 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
8112 i40e_do_reset(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
8121 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
8124 * @seq: RTNL message seq #
8125 * @dev: the netdev being configured
8126 * @filter_mask: unused
8128 * Return the mode in which the hardware bridge is operating in
8131 static int i40e_ndo_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
8132 struct net_device
*dev
,
8133 u32 filter_mask
, int nlflags
)
8135 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
8136 struct i40e_vsi
*vsi
= np
->vsi
;
8137 struct i40e_pf
*pf
= vsi
->back
;
8138 struct i40e_veb
*veb
= NULL
;
8141 /* Only for PF VSI for now */
8142 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
)
8145 /* Find the HW bridge for the PF VSI */
8146 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
8147 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
8154 return ndo_dflt_bridge_getlink(skb
, pid
, seq
, dev
, veb
->bridge_mode
,
8155 nlflags
, 0, 0, filter_mask
, NULL
);
8158 #define I40E_MAX_TUNNEL_HDR_LEN 80
8160 * i40e_features_check - Validate encapsulated packet conforms to limits
8162 * @netdev: This physical port's netdev
8163 * @features: Offload features that the stack believes apply
8165 static netdev_features_t
i40e_features_check(struct sk_buff
*skb
,
8166 struct net_device
*dev
,
8167 netdev_features_t features
)
8169 if (skb
->encapsulation
&&
8170 (skb_inner_mac_header(skb
) - skb_transport_header(skb
) >
8171 I40E_MAX_TUNNEL_HDR_LEN
))
8172 return features
& ~(NETIF_F_ALL_CSUM
| NETIF_F_GSO_MASK
);
8177 static const struct net_device_ops i40e_netdev_ops
= {
8178 .ndo_open
= i40e_open
,
8179 .ndo_stop
= i40e_close
,
8180 .ndo_start_xmit
= i40e_lan_xmit_frame
,
8181 .ndo_get_stats64
= i40e_get_netdev_stats_struct
,
8182 .ndo_set_rx_mode
= i40e_set_rx_mode
,
8183 .ndo_validate_addr
= eth_validate_addr
,
8184 .ndo_set_mac_address
= i40e_set_mac
,
8185 .ndo_change_mtu
= i40e_change_mtu
,
8186 .ndo_do_ioctl
= i40e_ioctl
,
8187 .ndo_tx_timeout
= i40e_tx_timeout
,
8188 .ndo_vlan_rx_add_vid
= i40e_vlan_rx_add_vid
,
8189 .ndo_vlan_rx_kill_vid
= i40e_vlan_rx_kill_vid
,
8190 #ifdef CONFIG_NET_POLL_CONTROLLER
8191 .ndo_poll_controller
= i40e_netpoll
,
8193 .ndo_setup_tc
= i40e_setup_tc
,
8195 .ndo_fcoe_enable
= i40e_fcoe_enable
,
8196 .ndo_fcoe_disable
= i40e_fcoe_disable
,
8198 .ndo_set_features
= i40e_set_features
,
8199 .ndo_set_vf_mac
= i40e_ndo_set_vf_mac
,
8200 .ndo_set_vf_vlan
= i40e_ndo_set_vf_port_vlan
,
8201 .ndo_set_vf_rate
= i40e_ndo_set_vf_bw
,
8202 .ndo_get_vf_config
= i40e_ndo_get_vf_config
,
8203 .ndo_set_vf_link_state
= i40e_ndo_set_vf_link_state
,
8204 .ndo_set_vf_spoofchk
= i40e_ndo_set_vf_spoofchk
,
8205 #ifdef CONFIG_I40E_VXLAN
8206 .ndo_add_vxlan_port
= i40e_add_vxlan_port
,
8207 .ndo_del_vxlan_port
= i40e_del_vxlan_port
,
8209 .ndo_get_phys_port_id
= i40e_get_phys_port_id
,
8210 .ndo_fdb_add
= i40e_ndo_fdb_add
,
8211 .ndo_features_check
= i40e_features_check
,
8212 .ndo_bridge_getlink
= i40e_ndo_bridge_getlink
,
8213 .ndo_bridge_setlink
= i40e_ndo_bridge_setlink
,
8217 * i40e_config_netdev - Setup the netdev flags
8218 * @vsi: the VSI being configured
8220 * Returns 0 on success, negative value on failure
8222 static int i40e_config_netdev(struct i40e_vsi
*vsi
)
8224 u8 brdcast
[ETH_ALEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
8225 struct i40e_pf
*pf
= vsi
->back
;
8226 struct i40e_hw
*hw
= &pf
->hw
;
8227 struct i40e_netdev_priv
*np
;
8228 struct net_device
*netdev
;
8229 u8 mac_addr
[ETH_ALEN
];
8232 etherdev_size
= sizeof(struct i40e_netdev_priv
);
8233 netdev
= alloc_etherdev_mq(etherdev_size
, vsi
->alloc_queue_pairs
);
8237 vsi
->netdev
= netdev
;
8238 np
= netdev_priv(netdev
);
8241 netdev
->hw_enc_features
|= NETIF_F_IP_CSUM
|
8242 NETIF_F_GSO_UDP_TUNNEL
|
8245 netdev
->features
= NETIF_F_SG
|
8249 NETIF_F_GSO_UDP_TUNNEL
|
8250 NETIF_F_HW_VLAN_CTAG_TX
|
8251 NETIF_F_HW_VLAN_CTAG_RX
|
8252 NETIF_F_HW_VLAN_CTAG_FILTER
|
8261 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
8262 netdev
->features
|= NETIF_F_NTUPLE
;
8264 /* copy netdev features into list of user selectable features */
8265 netdev
->hw_features
|= netdev
->features
;
8267 if (vsi
->type
== I40E_VSI_MAIN
) {
8268 SET_NETDEV_DEV(netdev
, &pf
->pdev
->dev
);
8269 ether_addr_copy(mac_addr
, hw
->mac
.perm_addr
);
8270 /* The following steps are necessary to prevent reception
8271 * of tagged packets - some older NVM configurations load a
8272 * default a MAC-VLAN filter that accepts any tagged packet
8273 * which must be replaced by a normal filter.
8275 if (!i40e_rm_default_mac_filter(vsi
, mac_addr
))
8276 i40e_add_filter(vsi
, mac_addr
,
8277 I40E_VLAN_ANY
, false, true);
8279 /* relate the VSI_VMDQ name to the VSI_MAIN name */
8280 snprintf(netdev
->name
, IFNAMSIZ
, "%sv%%d",
8281 pf
->vsi
[pf
->lan_vsi
]->netdev
->name
);
8282 random_ether_addr(mac_addr
);
8283 i40e_add_filter(vsi
, mac_addr
, I40E_VLAN_ANY
, false, false);
8285 i40e_add_filter(vsi
, brdcast
, I40E_VLAN_ANY
, false, false);
8287 ether_addr_copy(netdev
->dev_addr
, mac_addr
);
8288 ether_addr_copy(netdev
->perm_addr
, mac_addr
);
8289 /* vlan gets same features (except vlan offload)
8290 * after any tweaks for specific VSI types
8292 netdev
->vlan_features
= netdev
->features
& ~(NETIF_F_HW_VLAN_CTAG_TX
|
8293 NETIF_F_HW_VLAN_CTAG_RX
|
8294 NETIF_F_HW_VLAN_CTAG_FILTER
);
8295 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
8296 netdev
->priv_flags
|= IFF_SUPP_NOFCS
;
8297 /* Setup netdev TC information */
8298 i40e_vsi_config_netdev_tc(vsi
, vsi
->tc_config
.enabled_tc
);
8300 netdev
->netdev_ops
= &i40e_netdev_ops
;
8301 netdev
->watchdog_timeo
= 5 * HZ
;
8302 i40e_set_ethtool_ops(netdev
);
8304 i40e_fcoe_config_netdev(netdev
, vsi
);
8311 * i40e_vsi_delete - Delete a VSI from the switch
8312 * @vsi: the VSI being removed
8314 * Returns 0 on success, negative value on failure
8316 static void i40e_vsi_delete(struct i40e_vsi
*vsi
)
8318 /* remove default VSI is not allowed */
8319 if (vsi
== vsi
->back
->vsi
[vsi
->back
->lan_vsi
])
8322 i40e_aq_delete_element(&vsi
->back
->hw
, vsi
->seid
, NULL
);
8326 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
8327 * @vsi: the VSI being queried
8329 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
8331 int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi
*vsi
)
8333 struct i40e_veb
*veb
;
8334 struct i40e_pf
*pf
= vsi
->back
;
8336 /* Uplink is not a bridge so default to VEB */
8337 if (vsi
->veb_idx
== I40E_NO_VEB
)
8340 veb
= pf
->veb
[vsi
->veb_idx
];
8341 /* Uplink is a bridge in VEPA mode */
8342 if (veb
&& (veb
->bridge_mode
& BRIDGE_MODE_VEPA
))
8345 /* Uplink is a bridge in VEB mode */
8350 * i40e_add_vsi - Add a VSI to the switch
8351 * @vsi: the VSI being configured
8353 * This initializes a VSI context depending on the VSI type to be added and
8354 * passes it down to the add_vsi aq command.
8356 static int i40e_add_vsi(struct i40e_vsi
*vsi
)
8359 struct i40e_mac_filter
*f
, *ftmp
;
8360 struct i40e_pf
*pf
= vsi
->back
;
8361 struct i40e_hw
*hw
= &pf
->hw
;
8362 struct i40e_vsi_context ctxt
;
8363 u8 enabled_tc
= 0x1; /* TC0 enabled */
8366 memset(&ctxt
, 0, sizeof(ctxt
));
8367 switch (vsi
->type
) {
8369 /* The PF's main VSI is already setup as part of the
8370 * device initialization, so we'll not bother with
8371 * the add_vsi call, but we will retrieve the current
8374 ctxt
.seid
= pf
->main_vsi_seid
;
8375 ctxt
.pf_num
= pf
->hw
.pf_id
;
8377 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
8378 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
8380 dev_info(&pf
->pdev
->dev
,
8381 "couldn't get PF vsi config, err %s aq_err %s\n",
8382 i40e_stat_str(&pf
->hw
, ret
),
8383 i40e_aq_str(&pf
->hw
,
8384 pf
->hw
.aq
.asq_last_status
));
8387 vsi
->info
= ctxt
.info
;
8388 vsi
->info
.valid_sections
= 0;
8390 vsi
->seid
= ctxt
.seid
;
8391 vsi
->id
= ctxt
.vsi_number
;
8393 enabled_tc
= i40e_pf_get_tc_map(pf
);
8395 /* MFP mode setup queue map and update VSI */
8396 if ((pf
->flags
& I40E_FLAG_MFP_ENABLED
) &&
8397 !(pf
->hw
.func_caps
.iscsi
)) { /* NIC type PF */
8398 memset(&ctxt
, 0, sizeof(ctxt
));
8399 ctxt
.seid
= pf
->main_vsi_seid
;
8400 ctxt
.pf_num
= pf
->hw
.pf_id
;
8402 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
8403 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
8405 dev_info(&pf
->pdev
->dev
,
8406 "update vsi failed, err %s aq_err %s\n",
8407 i40e_stat_str(&pf
->hw
, ret
),
8408 i40e_aq_str(&pf
->hw
,
8409 pf
->hw
.aq
.asq_last_status
));
8413 /* update the local VSI info queue map */
8414 i40e_vsi_update_queue_map(vsi
, &ctxt
);
8415 vsi
->info
.valid_sections
= 0;
8417 /* Default/Main VSI is only enabled for TC0
8418 * reconfigure it to enable all TCs that are
8419 * available on the port in SFP mode.
8420 * For MFP case the iSCSI PF would use this
8421 * flow to enable LAN+iSCSI TC.
8423 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
8425 dev_info(&pf
->pdev
->dev
,
8426 "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
8428 i40e_stat_str(&pf
->hw
, ret
),
8429 i40e_aq_str(&pf
->hw
,
8430 pf
->hw
.aq
.asq_last_status
));
8437 ctxt
.pf_num
= hw
->pf_id
;
8439 ctxt
.uplink_seid
= vsi
->uplink_seid
;
8440 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
8441 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
8442 if ((pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
) &&
8443 (i40e_is_vsi_uplink_mode_veb(vsi
))) {
8444 ctxt
.info
.valid_sections
|=
8445 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
8446 ctxt
.info
.switch_id
=
8447 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
8449 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
8452 case I40E_VSI_VMDQ2
:
8453 ctxt
.pf_num
= hw
->pf_id
;
8455 ctxt
.uplink_seid
= vsi
->uplink_seid
;
8456 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
8457 ctxt
.flags
= I40E_AQ_VSI_TYPE_VMDQ2
;
8459 /* This VSI is connected to VEB so the switch_id
8460 * should be set to zero by default.
8462 if (i40e_is_vsi_uplink_mode_veb(vsi
)) {
8463 ctxt
.info
.valid_sections
|=
8464 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
8465 ctxt
.info
.switch_id
=
8466 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
8469 /* Setup the VSI tx/rx queue map for TC0 only for now */
8470 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
8473 case I40E_VSI_SRIOV
:
8474 ctxt
.pf_num
= hw
->pf_id
;
8475 ctxt
.vf_num
= vsi
->vf_id
+ hw
->func_caps
.vf_base_id
;
8476 ctxt
.uplink_seid
= vsi
->uplink_seid
;
8477 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
8478 ctxt
.flags
= I40E_AQ_VSI_TYPE_VF
;
8480 /* This VSI is connected to VEB so the switch_id
8481 * should be set to zero by default.
8483 if (i40e_is_vsi_uplink_mode_veb(vsi
)) {
8484 ctxt
.info
.valid_sections
|=
8485 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
8486 ctxt
.info
.switch_id
=
8487 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
8490 ctxt
.info
.valid_sections
|= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
8491 ctxt
.info
.port_vlan_flags
|= I40E_AQ_VSI_PVLAN_MODE_ALL
;
8492 if (pf
->vf
[vsi
->vf_id
].spoofchk
) {
8493 ctxt
.info
.valid_sections
|=
8494 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID
);
8495 ctxt
.info
.sec_flags
|=
8496 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK
|
8497 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK
);
8499 /* Setup the VSI tx/rx queue map for TC0 only for now */
8500 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
8505 ret
= i40e_fcoe_vsi_init(vsi
, &ctxt
);
8507 dev_info(&pf
->pdev
->dev
, "failed to initialize FCoE VSI\n");
8512 #endif /* I40E_FCOE */
8517 if (vsi
->type
!= I40E_VSI_MAIN
) {
8518 ret
= i40e_aq_add_vsi(hw
, &ctxt
, NULL
);
8520 dev_info(&vsi
->back
->pdev
->dev
,
8521 "add vsi failed, err %s aq_err %s\n",
8522 i40e_stat_str(&pf
->hw
, ret
),
8523 i40e_aq_str(&pf
->hw
,
8524 pf
->hw
.aq
.asq_last_status
));
8528 vsi
->info
= ctxt
.info
;
8529 vsi
->info
.valid_sections
= 0;
8530 vsi
->seid
= ctxt
.seid
;
8531 vsi
->id
= ctxt
.vsi_number
;
8534 /* If macvlan filters already exist, force them to get loaded */
8535 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
8539 if (f
->is_laa
&& vsi
->type
== I40E_VSI_MAIN
) {
8540 struct i40e_aqc_remove_macvlan_element_data element
;
8542 memset(&element
, 0, sizeof(element
));
8543 ether_addr_copy(element
.mac_addr
, f
->macaddr
);
8544 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
8545 ret
= i40e_aq_remove_macvlan(hw
, vsi
->seid
,
8548 /* some older FW has a different default */
8550 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
8551 i40e_aq_remove_macvlan(hw
, vsi
->seid
,
8555 i40e_aq_mac_address_write(hw
,
8556 I40E_AQC_WRITE_TYPE_LAA_WOL
,
8561 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
8562 pf
->flags
|= I40E_FLAG_FILTER_SYNC
;
8565 /* Update VSI BW information */
8566 ret
= i40e_vsi_get_bw_info(vsi
);
8568 dev_info(&pf
->pdev
->dev
,
8569 "couldn't get vsi bw info, err %s aq_err %s\n",
8570 i40e_stat_str(&pf
->hw
, ret
),
8571 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
8572 /* VSI is already added so not tearing that up */
8581 * i40e_vsi_release - Delete a VSI and free its resources
8582 * @vsi: the VSI being removed
8584 * Returns 0 on success or < 0 on error
8586 int i40e_vsi_release(struct i40e_vsi
*vsi
)
8588 struct i40e_mac_filter
*f
, *ftmp
;
8589 struct i40e_veb
*veb
= NULL
;
8596 /* release of a VEB-owner or last VSI is not allowed */
8597 if (vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
8598 dev_info(&pf
->pdev
->dev
, "VSI %d has existing VEB %d\n",
8599 vsi
->seid
, vsi
->uplink_seid
);
8602 if (vsi
== pf
->vsi
[pf
->lan_vsi
] &&
8603 !test_bit(__I40E_DOWN
, &pf
->state
)) {
8604 dev_info(&pf
->pdev
->dev
, "Can't remove PF VSI\n");
8608 uplink_seid
= vsi
->uplink_seid
;
8609 if (vsi
->type
!= I40E_VSI_SRIOV
) {
8610 if (vsi
->netdev_registered
) {
8611 vsi
->netdev_registered
= false;
8613 /* results in a call to i40e_close() */
8614 unregister_netdev(vsi
->netdev
);
8617 i40e_vsi_close(vsi
);
8619 i40e_vsi_disable_irq(vsi
);
8622 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
)
8623 i40e_del_filter(vsi
, f
->macaddr
, f
->vlan
,
8624 f
->is_vf
, f
->is_netdev
);
8625 i40e_sync_vsi_filters(vsi
);
8627 i40e_vsi_delete(vsi
);
8628 i40e_vsi_free_q_vectors(vsi
);
8630 free_netdev(vsi
->netdev
);
8633 i40e_vsi_clear_rings(vsi
);
8634 i40e_vsi_clear(vsi
);
8636 /* If this was the last thing on the VEB, except for the
8637 * controlling VSI, remove the VEB, which puts the controlling
8638 * VSI onto the next level down in the switch.
8640 * Well, okay, there's one more exception here: don't remove
8641 * the orphan VEBs yet. We'll wait for an explicit remove request
8642 * from up the network stack.
8644 for (n
= 0, i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
8646 pf
->vsi
[i
]->uplink_seid
== uplink_seid
&&
8647 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
8648 n
++; /* count the VSIs */
8651 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
8654 if (pf
->veb
[i
]->uplink_seid
== uplink_seid
)
8655 n
++; /* count the VEBs */
8656 if (pf
->veb
[i
]->seid
== uplink_seid
)
8659 if (n
== 0 && veb
&& veb
->uplink_seid
!= 0)
8660 i40e_veb_release(veb
);
8666 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
8667 * @vsi: ptr to the VSI
8669 * This should only be called after i40e_vsi_mem_alloc() which allocates the
8670 * corresponding SW VSI structure and initializes num_queue_pairs for the
8671 * newly allocated VSI.
8673 * Returns 0 on success or negative on failure
8675 static int i40e_vsi_setup_vectors(struct i40e_vsi
*vsi
)
8678 struct i40e_pf
*pf
= vsi
->back
;
8680 if (vsi
->q_vectors
[0]) {
8681 dev_info(&pf
->pdev
->dev
, "VSI %d has existing q_vectors\n",
8686 if (vsi
->base_vector
) {
8687 dev_info(&pf
->pdev
->dev
, "VSI %d has non-zero base vector %d\n",
8688 vsi
->seid
, vsi
->base_vector
);
8692 ret
= i40e_vsi_alloc_q_vectors(vsi
);
8694 dev_info(&pf
->pdev
->dev
,
8695 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
8696 vsi
->num_q_vectors
, vsi
->seid
, ret
);
8697 vsi
->num_q_vectors
= 0;
8698 goto vector_setup_out
;
8701 if (vsi
->num_q_vectors
)
8702 vsi
->base_vector
= i40e_get_lump(pf
, pf
->irq_pile
,
8703 vsi
->num_q_vectors
, vsi
->idx
);
8704 if (vsi
->base_vector
< 0) {
8705 dev_info(&pf
->pdev
->dev
,
8706 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
8707 vsi
->num_q_vectors
, vsi
->seid
, vsi
->base_vector
);
8708 i40e_vsi_free_q_vectors(vsi
);
8710 goto vector_setup_out
;
8718 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
8719 * @vsi: pointer to the vsi.
8721 * This re-allocates a vsi's queue resources.
8723 * Returns pointer to the successfully allocated and configured VSI sw struct
8724 * on success, otherwise returns NULL on failure.
8726 static struct i40e_vsi
*i40e_vsi_reinit_setup(struct i40e_vsi
*vsi
)
8728 struct i40e_pf
*pf
= vsi
->back
;
8732 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
8733 i40e_vsi_clear_rings(vsi
);
8735 i40e_vsi_free_arrays(vsi
, false);
8736 i40e_set_num_rings_in_vsi(vsi
);
8737 ret
= i40e_vsi_alloc_arrays(vsi
, false);
8741 ret
= i40e_get_lump(pf
, pf
->qp_pile
, vsi
->alloc_queue_pairs
, vsi
->idx
);
8743 dev_info(&pf
->pdev
->dev
,
8744 "failed to get tracking for %d queues for VSI %d err %d\n",
8745 vsi
->alloc_queue_pairs
, vsi
->seid
, ret
);
8748 vsi
->base_queue
= ret
;
8750 /* Update the FW view of the VSI. Force a reset of TC and queue
8751 * layout configurations.
8753 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
8754 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
8755 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
8756 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
8758 /* assign it some queues */
8759 ret
= i40e_alloc_rings(vsi
);
8763 /* map all of the rings to the q_vectors */
8764 i40e_vsi_map_rings_to_vectors(vsi
);
8768 i40e_vsi_free_q_vectors(vsi
);
8769 if (vsi
->netdev_registered
) {
8770 vsi
->netdev_registered
= false;
8771 unregister_netdev(vsi
->netdev
);
8772 free_netdev(vsi
->netdev
);
8775 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
8777 i40e_vsi_clear(vsi
);
8782 * i40e_vsi_setup - Set up a VSI by a given type
8783 * @pf: board private structure
8785 * @uplink_seid: the switch element to link to
8786 * @param1: usage depends upon VSI type. For VF types, indicates VF id
8788 * This allocates the sw VSI structure and its queue resources, then add a VSI
8789 * to the identified VEB.
8791 * Returns pointer to the successfully allocated and configure VSI sw struct on
8792 * success, otherwise returns NULL on failure.
8794 struct i40e_vsi
*i40e_vsi_setup(struct i40e_pf
*pf
, u8 type
,
8795 u16 uplink_seid
, u32 param1
)
8797 struct i40e_vsi
*vsi
= NULL
;
8798 struct i40e_veb
*veb
= NULL
;
8802 /* The requested uplink_seid must be either
8803 * - the PF's port seid
8804 * no VEB is needed because this is the PF
8805 * or this is a Flow Director special case VSI
8806 * - seid of an existing VEB
8807 * - seid of a VSI that owns an existing VEB
8808 * - seid of a VSI that doesn't own a VEB
8809 * a new VEB is created and the VSI becomes the owner
8810 * - seid of the PF VSI, which is what creates the first VEB
8811 * this is a special case of the previous
8813 * Find which uplink_seid we were given and create a new VEB if needed
8815 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
8816 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== uplink_seid
) {
8822 if (!veb
&& uplink_seid
!= pf
->mac_seid
) {
8824 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
8825 if (pf
->vsi
[i
] && pf
->vsi
[i
]->seid
== uplink_seid
) {
8831 dev_info(&pf
->pdev
->dev
, "no such uplink_seid %d\n",
8836 if (vsi
->uplink_seid
== pf
->mac_seid
)
8837 veb
= i40e_veb_setup(pf
, 0, pf
->mac_seid
, vsi
->seid
,
8838 vsi
->tc_config
.enabled_tc
);
8839 else if ((vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0)
8840 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
8841 vsi
->tc_config
.enabled_tc
);
8843 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
) {
8844 dev_info(&vsi
->back
->pdev
->dev
,
8845 "%s: New VSI creation error, uplink seid of LAN VSI expected.\n",
8849 /* We come up by default in VEPA mode if SRIOV is not
8850 * already enabled, in which case we can't force VEPA
8853 if (!(pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)) {
8854 veb
->bridge_mode
= BRIDGE_MODE_VEPA
;
8855 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
8857 i40e_config_bridge_mode(veb
);
8859 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
8860 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
8864 dev_info(&pf
->pdev
->dev
, "couldn't add VEB\n");
8868 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
8869 uplink_seid
= veb
->seid
;
8872 /* get vsi sw struct */
8873 v_idx
= i40e_vsi_mem_alloc(pf
, type
);
8876 vsi
= pf
->vsi
[v_idx
];
8880 vsi
->veb_idx
= (veb
? veb
->idx
: I40E_NO_VEB
);
8882 if (type
== I40E_VSI_MAIN
)
8883 pf
->lan_vsi
= v_idx
;
8884 else if (type
== I40E_VSI_SRIOV
)
8885 vsi
->vf_id
= param1
;
8886 /* assign it some queues */
8887 ret
= i40e_get_lump(pf
, pf
->qp_pile
, vsi
->alloc_queue_pairs
,
8890 dev_info(&pf
->pdev
->dev
,
8891 "failed to get tracking for %d queues for VSI %d err=%d\n",
8892 vsi
->alloc_queue_pairs
, vsi
->seid
, ret
);
8895 vsi
->base_queue
= ret
;
8897 /* get a VSI from the hardware */
8898 vsi
->uplink_seid
= uplink_seid
;
8899 ret
= i40e_add_vsi(vsi
);
8903 switch (vsi
->type
) {
8904 /* setup the netdev if needed */
8906 case I40E_VSI_VMDQ2
:
8908 ret
= i40e_config_netdev(vsi
);
8911 ret
= register_netdev(vsi
->netdev
);
8914 vsi
->netdev_registered
= true;
8915 netif_carrier_off(vsi
->netdev
);
8916 #ifdef CONFIG_I40E_DCB
8917 /* Setup DCB netlink interface */
8918 i40e_dcbnl_setup(vsi
);
8919 #endif /* CONFIG_I40E_DCB */
8923 /* set up vectors and rings if needed */
8924 ret
= i40e_vsi_setup_vectors(vsi
);
8928 ret
= i40e_alloc_rings(vsi
);
8932 /* map all of the rings to the q_vectors */
8933 i40e_vsi_map_rings_to_vectors(vsi
);
8935 i40e_vsi_reset_stats(vsi
);
8939 /* no netdev or rings for the other VSI types */
8946 i40e_vsi_free_q_vectors(vsi
);
8948 if (vsi
->netdev_registered
) {
8949 vsi
->netdev_registered
= false;
8950 unregister_netdev(vsi
->netdev
);
8951 free_netdev(vsi
->netdev
);
8955 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
8957 i40e_vsi_clear(vsi
);
8963 * i40e_veb_get_bw_info - Query VEB BW information
8964 * @veb: the veb to query
8966 * Query the Tx scheduler BW configuration data for given VEB
8968 static int i40e_veb_get_bw_info(struct i40e_veb
*veb
)
8970 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data
;
8971 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data
;
8972 struct i40e_pf
*pf
= veb
->pf
;
8973 struct i40e_hw
*hw
= &pf
->hw
;
8978 ret
= i40e_aq_query_switch_comp_bw_config(hw
, veb
->seid
,
8981 dev_info(&pf
->pdev
->dev
,
8982 "query veb bw config failed, err %s aq_err %s\n",
8983 i40e_stat_str(&pf
->hw
, ret
),
8984 i40e_aq_str(&pf
->hw
, hw
->aq
.asq_last_status
));
8988 ret
= i40e_aq_query_switch_comp_ets_config(hw
, veb
->seid
,
8991 dev_info(&pf
->pdev
->dev
,
8992 "query veb bw ets config failed, err %s aq_err %s\n",
8993 i40e_stat_str(&pf
->hw
, ret
),
8994 i40e_aq_str(&pf
->hw
, hw
->aq
.asq_last_status
));
8998 veb
->bw_limit
= le16_to_cpu(ets_data
.port_bw_limit
);
8999 veb
->bw_max_quanta
= ets_data
.tc_bw_max
;
9000 veb
->is_abs_credits
= bw_data
.absolute_credits_enable
;
9001 veb
->enabled_tc
= ets_data
.tc_valid_bits
;
9002 tc_bw_max
= le16_to_cpu(bw_data
.tc_bw_max
[0]) |
9003 (le16_to_cpu(bw_data
.tc_bw_max
[1]) << 16);
9004 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
9005 veb
->bw_tc_share_credits
[i
] = bw_data
.tc_bw_share_credits
[i
];
9006 veb
->bw_tc_limit_credits
[i
] =
9007 le16_to_cpu(bw_data
.tc_bw_limits
[i
]);
9008 veb
->bw_tc_max_quanta
[i
] = ((tc_bw_max
>> (i
*4)) & 0x7);
9016 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
9017 * @pf: board private structure
9019 * On error: returns error code (negative)
9020 * On success: returns vsi index in PF (positive)
9022 static int i40e_veb_mem_alloc(struct i40e_pf
*pf
)
9025 struct i40e_veb
*veb
;
9028 /* Need to protect the allocation of switch elements at the PF level */
9029 mutex_lock(&pf
->switch_mutex
);
9031 /* VEB list may be fragmented if VEB creation/destruction has
9032 * been happening. We can afford to do a quick scan to look
9033 * for any free slots in the list.
9035 * find next empty veb slot, looping back around if necessary
9038 while ((i
< I40E_MAX_VEB
) && (pf
->veb
[i
] != NULL
))
9040 if (i
>= I40E_MAX_VEB
) {
9042 goto err_alloc_veb
; /* out of VEB slots! */
9045 veb
= kzalloc(sizeof(*veb
), GFP_KERNEL
);
9052 veb
->enabled_tc
= 1;
9057 mutex_unlock(&pf
->switch_mutex
);
9062 * i40e_switch_branch_release - Delete a branch of the switch tree
9063 * @branch: where to start deleting
9065 * This uses recursion to find the tips of the branch to be
9066 * removed, deleting until we get back to and can delete this VEB.
9068 static void i40e_switch_branch_release(struct i40e_veb
*branch
)
9070 struct i40e_pf
*pf
= branch
->pf
;
9071 u16 branch_seid
= branch
->seid
;
9072 u16 veb_idx
= branch
->idx
;
9075 /* release any VEBs on this VEB - RECURSION */
9076 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
9079 if (pf
->veb
[i
]->uplink_seid
== branch
->seid
)
9080 i40e_switch_branch_release(pf
->veb
[i
]);
9083 /* Release the VSIs on this VEB, but not the owner VSI.
9085 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
9086 * the VEB itself, so don't use (*branch) after this loop.
9088 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9091 if (pf
->vsi
[i
]->uplink_seid
== branch_seid
&&
9092 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
9093 i40e_vsi_release(pf
->vsi
[i
]);
9097 /* There's one corner case where the VEB might not have been
9098 * removed, so double check it here and remove it if needed.
9099 * This case happens if the veb was created from the debugfs
9100 * commands and no VSIs were added to it.
9102 if (pf
->veb
[veb_idx
])
9103 i40e_veb_release(pf
->veb
[veb_idx
]);
9107 * i40e_veb_clear - remove veb struct
9108 * @veb: the veb to remove
9110 static void i40e_veb_clear(struct i40e_veb
*veb
)
9116 struct i40e_pf
*pf
= veb
->pf
;
9118 mutex_lock(&pf
->switch_mutex
);
9119 if (pf
->veb
[veb
->idx
] == veb
)
9120 pf
->veb
[veb
->idx
] = NULL
;
9121 mutex_unlock(&pf
->switch_mutex
);
9128 * i40e_veb_release - Delete a VEB and free its resources
9129 * @veb: the VEB being removed
9131 void i40e_veb_release(struct i40e_veb
*veb
)
9133 struct i40e_vsi
*vsi
= NULL
;
9139 /* find the remaining VSI and check for extras */
9140 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9141 if (pf
->vsi
[i
] && pf
->vsi
[i
]->uplink_seid
== veb
->seid
) {
9147 dev_info(&pf
->pdev
->dev
,
9148 "can't remove VEB %d with %d VSIs left\n",
9153 /* move the remaining VSI to uplink veb */
9154 vsi
->flags
&= ~I40E_VSI_FLAG_VEB_OWNER
;
9155 if (veb
->uplink_seid
) {
9156 vsi
->uplink_seid
= veb
->uplink_seid
;
9157 if (veb
->uplink_seid
== pf
->mac_seid
)
9158 vsi
->veb_idx
= I40E_NO_VEB
;
9160 vsi
->veb_idx
= veb
->veb_idx
;
9163 vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
9164 vsi
->veb_idx
= pf
->vsi
[pf
->lan_vsi
]->veb_idx
;
9167 i40e_aq_delete_element(&pf
->hw
, veb
->seid
, NULL
);
9168 i40e_veb_clear(veb
);
9172 * i40e_add_veb - create the VEB in the switch
9173 * @veb: the VEB to be instantiated
9174 * @vsi: the controlling VSI
9176 static int i40e_add_veb(struct i40e_veb
*veb
, struct i40e_vsi
*vsi
)
9178 struct i40e_pf
*pf
= veb
->pf
;
9179 bool is_default
= false;
9180 bool is_cloud
= false;
9183 /* get a VEB from the hardware */
9184 ret
= i40e_aq_add_veb(&pf
->hw
, veb
->uplink_seid
, vsi
->seid
,
9185 veb
->enabled_tc
, is_default
,
9186 is_cloud
, &veb
->seid
, NULL
);
9188 dev_info(&pf
->pdev
->dev
,
9189 "couldn't add VEB, err %s aq_err %s\n",
9190 i40e_stat_str(&pf
->hw
, ret
),
9191 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9195 /* get statistics counter */
9196 ret
= i40e_aq_get_veb_parameters(&pf
->hw
, veb
->seid
, NULL
, NULL
,
9197 &veb
->stats_idx
, NULL
, NULL
, NULL
);
9199 dev_info(&pf
->pdev
->dev
,
9200 "couldn't get VEB statistics idx, err %s aq_err %s\n",
9201 i40e_stat_str(&pf
->hw
, ret
),
9202 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9205 ret
= i40e_veb_get_bw_info(veb
);
9207 dev_info(&pf
->pdev
->dev
,
9208 "couldn't get VEB bw info, err %s aq_err %s\n",
9209 i40e_stat_str(&pf
->hw
, ret
),
9210 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9211 i40e_aq_delete_element(&pf
->hw
, veb
->seid
, NULL
);
9215 vsi
->uplink_seid
= veb
->seid
;
9216 vsi
->veb_idx
= veb
->idx
;
9217 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
9223 * i40e_veb_setup - Set up a VEB
9224 * @pf: board private structure
9225 * @flags: VEB setup flags
9226 * @uplink_seid: the switch element to link to
9227 * @vsi_seid: the initial VSI seid
9228 * @enabled_tc: Enabled TC bit-map
9230 * This allocates the sw VEB structure and links it into the switch
9231 * It is possible and legal for this to be a duplicate of an already
9232 * existing VEB. It is also possible for both uplink and vsi seids
9233 * to be zero, in order to create a floating VEB.
9235 * Returns pointer to the successfully allocated VEB sw struct on
9236 * success, otherwise returns NULL on failure.
9238 struct i40e_veb
*i40e_veb_setup(struct i40e_pf
*pf
, u16 flags
,
9239 u16 uplink_seid
, u16 vsi_seid
,
9242 struct i40e_veb
*veb
, *uplink_veb
= NULL
;
9243 int vsi_idx
, veb_idx
;
9246 /* if one seid is 0, the other must be 0 to create a floating relay */
9247 if ((uplink_seid
== 0 || vsi_seid
== 0) &&
9248 (uplink_seid
+ vsi_seid
!= 0)) {
9249 dev_info(&pf
->pdev
->dev
,
9250 "one, not both seid's are 0: uplink=%d vsi=%d\n",
9251 uplink_seid
, vsi_seid
);
9255 /* make sure there is such a vsi and uplink */
9256 for (vsi_idx
= 0; vsi_idx
< pf
->num_alloc_vsi
; vsi_idx
++)
9257 if (pf
->vsi
[vsi_idx
] && pf
->vsi
[vsi_idx
]->seid
== vsi_seid
)
9259 if (vsi_idx
>= pf
->num_alloc_vsi
&& vsi_seid
!= 0) {
9260 dev_info(&pf
->pdev
->dev
, "vsi seid %d not found\n",
9265 if (uplink_seid
&& uplink_seid
!= pf
->mac_seid
) {
9266 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
9267 if (pf
->veb
[veb_idx
] &&
9268 pf
->veb
[veb_idx
]->seid
== uplink_seid
) {
9269 uplink_veb
= pf
->veb
[veb_idx
];
9274 dev_info(&pf
->pdev
->dev
,
9275 "uplink seid %d not found\n", uplink_seid
);
9280 /* get veb sw struct */
9281 veb_idx
= i40e_veb_mem_alloc(pf
);
9284 veb
= pf
->veb
[veb_idx
];
9286 veb
->uplink_seid
= uplink_seid
;
9287 veb
->veb_idx
= (uplink_veb
? uplink_veb
->idx
: I40E_NO_VEB
);
9288 veb
->enabled_tc
= (enabled_tc
? enabled_tc
: 0x1);
9290 /* create the VEB in the switch */
9291 ret
= i40e_add_veb(veb
, pf
->vsi
[vsi_idx
]);
9294 if (vsi_idx
== pf
->lan_vsi
)
9295 pf
->lan_veb
= veb
->idx
;
9300 i40e_veb_clear(veb
);
9306 * i40e_setup_pf_switch_element - set PF vars based on switch type
9307 * @pf: board private structure
9308 * @ele: element we are building info from
9309 * @num_reported: total number of elements
9310 * @printconfig: should we print the contents
9312 * helper function to assist in extracting a few useful SEID values.
9314 static void i40e_setup_pf_switch_element(struct i40e_pf
*pf
,
9315 struct i40e_aqc_switch_config_element_resp
*ele
,
9316 u16 num_reported
, bool printconfig
)
9318 u16 downlink_seid
= le16_to_cpu(ele
->downlink_seid
);
9319 u16 uplink_seid
= le16_to_cpu(ele
->uplink_seid
);
9320 u8 element_type
= ele
->element_type
;
9321 u16 seid
= le16_to_cpu(ele
->seid
);
9324 dev_info(&pf
->pdev
->dev
,
9325 "type=%d seid=%d uplink=%d downlink=%d\n",
9326 element_type
, seid
, uplink_seid
, downlink_seid
);
9328 switch (element_type
) {
9329 case I40E_SWITCH_ELEMENT_TYPE_MAC
:
9330 pf
->mac_seid
= seid
;
9332 case I40E_SWITCH_ELEMENT_TYPE_VEB
:
9334 if (uplink_seid
!= pf
->mac_seid
)
9336 if (pf
->lan_veb
== I40E_NO_VEB
) {
9339 /* find existing or else empty VEB */
9340 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
9341 if (pf
->veb
[v
] && (pf
->veb
[v
]->seid
== seid
)) {
9346 if (pf
->lan_veb
== I40E_NO_VEB
) {
9347 v
= i40e_veb_mem_alloc(pf
);
9354 pf
->veb
[pf
->lan_veb
]->seid
= seid
;
9355 pf
->veb
[pf
->lan_veb
]->uplink_seid
= pf
->mac_seid
;
9356 pf
->veb
[pf
->lan_veb
]->pf
= pf
;
9357 pf
->veb
[pf
->lan_veb
]->veb_idx
= I40E_NO_VEB
;
9359 case I40E_SWITCH_ELEMENT_TYPE_VSI
:
9360 if (num_reported
!= 1)
9362 /* This is immediately after a reset so we can assume this is
9365 pf
->mac_seid
= uplink_seid
;
9366 pf
->pf_seid
= downlink_seid
;
9367 pf
->main_vsi_seid
= seid
;
9369 dev_info(&pf
->pdev
->dev
,
9370 "pf_seid=%d main_vsi_seid=%d\n",
9371 pf
->pf_seid
, pf
->main_vsi_seid
);
9373 case I40E_SWITCH_ELEMENT_TYPE_PF
:
9374 case I40E_SWITCH_ELEMENT_TYPE_VF
:
9375 case I40E_SWITCH_ELEMENT_TYPE_EMP
:
9376 case I40E_SWITCH_ELEMENT_TYPE_BMC
:
9377 case I40E_SWITCH_ELEMENT_TYPE_PE
:
9378 case I40E_SWITCH_ELEMENT_TYPE_PA
:
9379 /* ignore these for now */
9382 dev_info(&pf
->pdev
->dev
, "unknown element type=%d seid=%d\n",
9383 element_type
, seid
);
9389 * i40e_fetch_switch_configuration - Get switch config from firmware
9390 * @pf: board private structure
9391 * @printconfig: should we print the contents
9393 * Get the current switch configuration from the device and
9394 * extract a few useful SEID values.
9396 int i40e_fetch_switch_configuration(struct i40e_pf
*pf
, bool printconfig
)
9398 struct i40e_aqc_get_switch_config_resp
*sw_config
;
9404 aq_buf
= kzalloc(I40E_AQ_LARGE_BUF
, GFP_KERNEL
);
9408 sw_config
= (struct i40e_aqc_get_switch_config_resp
*)aq_buf
;
9410 u16 num_reported
, num_total
;
9412 ret
= i40e_aq_get_switch_config(&pf
->hw
, sw_config
,
9416 dev_info(&pf
->pdev
->dev
,
9417 "get switch config failed err %s aq_err %s\n",
9418 i40e_stat_str(&pf
->hw
, ret
),
9419 i40e_aq_str(&pf
->hw
,
9420 pf
->hw
.aq
.asq_last_status
));
9425 num_reported
= le16_to_cpu(sw_config
->header
.num_reported
);
9426 num_total
= le16_to_cpu(sw_config
->header
.num_total
);
9429 dev_info(&pf
->pdev
->dev
,
9430 "header: %d reported %d total\n",
9431 num_reported
, num_total
);
9433 for (i
= 0; i
< num_reported
; i
++) {
9434 struct i40e_aqc_switch_config_element_resp
*ele
=
9435 &sw_config
->element
[i
];
9437 i40e_setup_pf_switch_element(pf
, ele
, num_reported
,
9440 } while (next_seid
!= 0);
9447 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
9448 * @pf: board private structure
9449 * @reinit: if the Main VSI needs to re-initialized.
9451 * Returns 0 on success, negative value on failure
9453 static int i40e_setup_pf_switch(struct i40e_pf
*pf
, bool reinit
)
9457 /* find out what's out there already */
9458 ret
= i40e_fetch_switch_configuration(pf
, false);
9460 dev_info(&pf
->pdev
->dev
,
9461 "couldn't fetch switch config, err %s aq_err %s\n",
9462 i40e_stat_str(&pf
->hw
, ret
),
9463 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9466 i40e_pf_reset_stats(pf
);
9468 /* first time setup */
9469 if (pf
->lan_vsi
== I40E_NO_VSI
|| reinit
) {
9470 struct i40e_vsi
*vsi
= NULL
;
9473 /* Set up the PF VSI associated with the PF's main VSI
9474 * that is already in the HW switch
9476 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
9477 uplink_seid
= pf
->veb
[pf
->lan_veb
]->seid
;
9479 uplink_seid
= pf
->mac_seid
;
9480 if (pf
->lan_vsi
== I40E_NO_VSI
)
9481 vsi
= i40e_vsi_setup(pf
, I40E_VSI_MAIN
, uplink_seid
, 0);
9483 vsi
= i40e_vsi_reinit_setup(pf
->vsi
[pf
->lan_vsi
]);
9485 dev_info(&pf
->pdev
->dev
, "setup of MAIN VSI failed\n");
9486 i40e_fdir_teardown(pf
);
9490 /* force a reset of TC and queue layout configurations */
9491 u8 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
9492 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
9493 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
9494 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
9496 i40e_vlan_stripping_disable(pf
->vsi
[pf
->lan_vsi
]);
9498 i40e_fdir_sb_setup(pf
);
9500 /* Setup static PF queue filter control settings */
9501 ret
= i40e_setup_pf_filter_control(pf
);
9503 dev_info(&pf
->pdev
->dev
, "setup_pf_filter_control failed: %d\n",
9505 /* Failure here should not stop continuing other steps */
9508 /* enable RSS in the HW, even for only one queue, as the stack can use
9511 if ((pf
->flags
& I40E_FLAG_RSS_ENABLED
))
9512 i40e_config_rss(pf
);
9514 /* fill in link information and enable LSE reporting */
9515 i40e_aq_get_link_info(&pf
->hw
, true, NULL
, NULL
);
9516 i40e_link_event(pf
);
9518 /* Initialize user-specific link properties */
9519 pf
->fc_autoneg_status
= ((pf
->hw
.phy
.link_info
.an_info
&
9520 I40E_AQ_AN_COMPLETED
) ? true : false);
9528 * i40e_determine_queue_usage - Work out queue distribution
9529 * @pf: board private structure
9531 static void i40e_determine_queue_usage(struct i40e_pf
*pf
)
9535 pf
->num_lan_qps
= 0;
9537 pf
->num_fcoe_qps
= 0;
9540 /* Find the max queues to be put into basic use. We'll always be
9541 * using TC0, whether or not DCB is running, and TC0 will get the
9544 queues_left
= pf
->hw
.func_caps
.num_tx_qp
;
9546 if ((queues_left
== 1) ||
9547 !(pf
->flags
& I40E_FLAG_MSIX_ENABLED
)) {
9548 /* one qp for PF, no queues for anything else */
9550 pf
->rss_size
= pf
->num_lan_qps
= 1;
9552 /* make sure all the fancies are disabled */
9553 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
9555 I40E_FLAG_FCOE_ENABLED
|
9557 I40E_FLAG_FD_SB_ENABLED
|
9558 I40E_FLAG_FD_ATR_ENABLED
|
9559 I40E_FLAG_DCB_CAPABLE
|
9560 I40E_FLAG_SRIOV_ENABLED
|
9561 I40E_FLAG_VMDQ_ENABLED
);
9562 } else if (!(pf
->flags
& (I40E_FLAG_RSS_ENABLED
|
9563 I40E_FLAG_FD_SB_ENABLED
|
9564 I40E_FLAG_FD_ATR_ENABLED
|
9565 I40E_FLAG_DCB_CAPABLE
))) {
9567 pf
->rss_size
= pf
->num_lan_qps
= 1;
9568 queues_left
-= pf
->num_lan_qps
;
9570 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
9572 I40E_FLAG_FCOE_ENABLED
|
9574 I40E_FLAG_FD_SB_ENABLED
|
9575 I40E_FLAG_FD_ATR_ENABLED
|
9576 I40E_FLAG_DCB_ENABLED
|
9577 I40E_FLAG_VMDQ_ENABLED
);
9579 /* Not enough queues for all TCs */
9580 if ((pf
->flags
& I40E_FLAG_DCB_CAPABLE
) &&
9581 (queues_left
< I40E_MAX_TRAFFIC_CLASS
)) {
9582 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
9583 dev_info(&pf
->pdev
->dev
, "not enough queues for DCB. DCB is disabled.\n");
9585 pf
->num_lan_qps
= max_t(int, pf
->rss_size_max
,
9587 pf
->num_lan_qps
= min_t(int, pf
->num_lan_qps
,
9588 pf
->hw
.func_caps
.num_tx_qp
);
9590 queues_left
-= pf
->num_lan_qps
;
9594 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
9595 if (I40E_DEFAULT_FCOE
<= queues_left
) {
9596 pf
->num_fcoe_qps
= I40E_DEFAULT_FCOE
;
9597 } else if (I40E_MINIMUM_FCOE
<= queues_left
) {
9598 pf
->num_fcoe_qps
= I40E_MINIMUM_FCOE
;
9600 pf
->num_fcoe_qps
= 0;
9601 pf
->flags
&= ~I40E_FLAG_FCOE_ENABLED
;
9602 dev_info(&pf
->pdev
->dev
, "not enough queues for FCoE. FCoE feature will be disabled\n");
9605 queues_left
-= pf
->num_fcoe_qps
;
9609 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
9610 if (queues_left
> 1) {
9611 queues_left
-= 1; /* save 1 queue for FD */
9613 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
9614 dev_info(&pf
->pdev
->dev
, "not enough queues for Flow Director. Flow Director feature is disabled\n");
9618 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
9619 pf
->num_vf_qps
&& pf
->num_req_vfs
&& queues_left
) {
9620 pf
->num_req_vfs
= min_t(int, pf
->num_req_vfs
,
9621 (queues_left
/ pf
->num_vf_qps
));
9622 queues_left
-= (pf
->num_req_vfs
* pf
->num_vf_qps
);
9625 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
9626 pf
->num_vmdq_vsis
&& pf
->num_vmdq_qps
&& queues_left
) {
9627 pf
->num_vmdq_vsis
= min_t(int, pf
->num_vmdq_vsis
,
9628 (queues_left
/ pf
->num_vmdq_qps
));
9629 queues_left
-= (pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
);
9632 pf
->queues_left
= queues_left
;
9634 dev_info(&pf
->pdev
->dev
, "fcoe queues = %d\n", pf
->num_fcoe_qps
);
9639 * i40e_setup_pf_filter_control - Setup PF static filter control
9640 * @pf: PF to be setup
9642 * i40e_setup_pf_filter_control sets up a PF's initial filter control
9643 * settings. If PE/FCoE are enabled then it will also set the per PF
9644 * based filter sizes required for them. It also enables Flow director,
9645 * ethertype and macvlan type filter settings for the pf.
9647 * Returns 0 on success, negative on failure
9649 static int i40e_setup_pf_filter_control(struct i40e_pf
*pf
)
9651 struct i40e_filter_control_settings
*settings
= &pf
->filter_settings
;
9653 settings
->hash_lut_size
= I40E_HASH_LUT_SIZE_128
;
9655 /* Flow Director is enabled */
9656 if (pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
))
9657 settings
->enable_fdir
= true;
9659 /* Ethtype and MACVLAN filters enabled for PF */
9660 settings
->enable_ethtype
= true;
9661 settings
->enable_macvlan
= true;
9663 if (i40e_set_filter_control(&pf
->hw
, settings
))
9669 #define INFO_STRING_LEN 255
9670 static void i40e_print_features(struct i40e_pf
*pf
)
9672 struct i40e_hw
*hw
= &pf
->hw
;
9675 string
= kzalloc(INFO_STRING_LEN
, GFP_KERNEL
);
9677 dev_err(&pf
->pdev
->dev
, "Features string allocation failed\n");
9683 buf
+= sprintf(string
, "Features: PF-id[%d] ", hw
->pf_id
);
9684 #ifdef CONFIG_PCI_IOV
9685 buf
+= sprintf(buf
, "VFs: %d ", pf
->num_req_vfs
);
9687 buf
+= sprintf(buf
, "VSIs: %d QP: %d RX: %s ",
9688 pf
->hw
.func_caps
.num_vsis
,
9689 pf
->vsi
[pf
->lan_vsi
]->num_queue_pairs
,
9690 pf
->flags
& I40E_FLAG_RX_PS_ENABLED
? "PS" : "1BUF");
9692 if (pf
->flags
& I40E_FLAG_RSS_ENABLED
)
9693 buf
+= sprintf(buf
, "RSS ");
9694 if (pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
)
9695 buf
+= sprintf(buf
, "FD_ATR ");
9696 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
9697 buf
+= sprintf(buf
, "FD_SB ");
9698 buf
+= sprintf(buf
, "NTUPLE ");
9700 if (pf
->flags
& I40E_FLAG_DCB_CAPABLE
)
9701 buf
+= sprintf(buf
, "DCB ");
9702 if (pf
->flags
& I40E_FLAG_PTP
)
9703 buf
+= sprintf(buf
, "PTP ");
9705 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
)
9706 buf
+= sprintf(buf
, "FCOE ");
9709 BUG_ON(buf
> (string
+ INFO_STRING_LEN
));
9710 dev_info(&pf
->pdev
->dev
, "%s\n", string
);
9715 * i40e_probe - Device initialization routine
9716 * @pdev: PCI device information struct
9717 * @ent: entry in i40e_pci_tbl
9719 * i40e_probe initializes a PF identified by a pci_dev structure.
9720 * The OS initialization, configuring of the PF private structure,
9721 * and a hardware reset occur.
9723 * Returns 0 on success, negative on failure
9725 static int i40e_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
9727 struct i40e_aq_get_phy_abilities_resp abilities
;
9728 unsigned long ioremap_len
;
9731 static u16 pfs_found
;
9737 err
= pci_enable_device_mem(pdev
);
9741 /* set up for high or low dma */
9742 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
9744 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
9747 "DMA configuration failed: 0x%x\n", err
);
9752 /* set up pci connections */
9753 err
= pci_request_selected_regions(pdev
, pci_select_bars(pdev
,
9754 IORESOURCE_MEM
), i40e_driver_name
);
9756 dev_info(&pdev
->dev
,
9757 "pci_request_selected_regions failed %d\n", err
);
9761 pci_enable_pcie_error_reporting(pdev
);
9762 pci_set_master(pdev
);
9764 /* Now that we have a PCI connection, we need to do the
9765 * low level device setup. This is primarily setting up
9766 * the Admin Queue structures and then querying for the
9767 * device's current profile information.
9769 pf
= kzalloc(sizeof(*pf
), GFP_KERNEL
);
9776 set_bit(__I40E_DOWN
, &pf
->state
);
9781 ioremap_len
= min_t(unsigned long, pci_resource_len(pdev
, 0),
9782 I40E_MAX_CSR_SPACE
);
9784 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0), ioremap_len
);
9787 dev_info(&pdev
->dev
, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
9788 (unsigned int)pci_resource_start(pdev
, 0),
9789 (unsigned int)pci_resource_len(pdev
, 0), err
);
9792 hw
->vendor_id
= pdev
->vendor
;
9793 hw
->device_id
= pdev
->device
;
9794 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
9795 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
9796 hw
->subsystem_device_id
= pdev
->subsystem_device
;
9797 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
9798 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
9799 pf
->instance
= pfs_found
;
9802 pf
->msg_enable
= pf
->hw
.debug_mask
;
9803 pf
->msg_enable
= debug
;
9806 /* do a special CORER for clearing PXE mode once at init */
9807 if (hw
->revision_id
== 0 &&
9808 (rd32(hw
, I40E_GLLAN_RCTL_0
) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK
)) {
9809 wr32(hw
, I40E_GLGEN_RTRIG
, I40E_GLGEN_RTRIG_CORER_MASK
);
9814 i40e_clear_pxe_mode(hw
);
9817 /* Reset here to make sure all is clean and to define PF 'n' */
9819 err
= i40e_pf_reset(hw
);
9821 dev_info(&pdev
->dev
, "Initial pf_reset failed: %d\n", err
);
9826 hw
->aq
.num_arq_entries
= I40E_AQ_LEN
;
9827 hw
->aq
.num_asq_entries
= I40E_AQ_LEN
;
9828 hw
->aq
.arq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
9829 hw
->aq
.asq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
9830 pf
->adminq_work_limit
= I40E_AQ_WORK_LIMIT
;
9832 snprintf(pf
->int_name
, sizeof(pf
->int_name
) - 1,
9834 dev_driver_string(&pf
->pdev
->dev
), dev_name(&pdev
->dev
));
9836 err
= i40e_init_shared_code(hw
);
9838 dev_warn(&pdev
->dev
, "unidentified MAC or BLANK NVM: %d\n",
9843 /* set up a default setting for link flow control */
9844 pf
->hw
.fc
.requested_mode
= I40E_FC_NONE
;
9846 err
= i40e_init_adminq(hw
);
9847 dev_info(&pdev
->dev
, "%s\n", i40e_fw_version_str(hw
));
9849 dev_info(&pdev
->dev
,
9850 "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");
9854 if (hw
->aq
.api_maj_ver
== I40E_FW_API_VERSION_MAJOR
&&
9855 hw
->aq
.api_min_ver
> I40E_FW_API_VERSION_MINOR
)
9856 dev_info(&pdev
->dev
,
9857 "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");
9858 else if (hw
->aq
.api_maj_ver
< I40E_FW_API_VERSION_MAJOR
||
9859 hw
->aq
.api_min_ver
< (I40E_FW_API_VERSION_MINOR
- 1))
9860 dev_info(&pdev
->dev
,
9861 "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
9863 i40e_verify_eeprom(pf
);
9865 /* Rev 0 hardware was never productized */
9866 if (hw
->revision_id
< 1)
9867 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");
9869 i40e_clear_pxe_mode(hw
);
9870 err
= i40e_get_capabilities(pf
);
9872 goto err_adminq_setup
;
9874 err
= i40e_sw_init(pf
);
9876 dev_info(&pdev
->dev
, "sw_init failed: %d\n", err
);
9880 err
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
9881 hw
->func_caps
.num_rx_qp
,
9882 pf
->fcoe_hmc_cntx_num
, pf
->fcoe_hmc_filt_num
);
9884 dev_info(&pdev
->dev
, "init_lan_hmc failed: %d\n", err
);
9885 goto err_init_lan_hmc
;
9888 err
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
9890 dev_info(&pdev
->dev
, "configure_lan_hmc failed: %d\n", err
);
9892 goto err_configure_lan_hmc
;
9895 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
9896 * Ignore error return codes because if it was already disabled via
9897 * hardware settings this will fail
9899 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 3)) ||
9900 (pf
->hw
.aq
.fw_maj_ver
< 4)) {
9901 dev_info(&pdev
->dev
, "Stopping firmware LLDP agent.\n");
9902 i40e_aq_stop_lldp(hw
, true, NULL
);
9905 i40e_get_mac_addr(hw
, hw
->mac
.addr
);
9906 if (!is_valid_ether_addr(hw
->mac
.addr
)) {
9907 dev_info(&pdev
->dev
, "invalid MAC address %pM\n", hw
->mac
.addr
);
9911 dev_info(&pdev
->dev
, "MAC address: %pM\n", hw
->mac
.addr
);
9912 ether_addr_copy(hw
->mac
.perm_addr
, hw
->mac
.addr
);
9913 i40e_get_port_mac_addr(hw
, hw
->mac
.port_addr
);
9914 if (is_valid_ether_addr(hw
->mac
.port_addr
))
9915 pf
->flags
|= I40E_FLAG_PORT_ID_VALID
;
9917 err
= i40e_get_san_mac_addr(hw
, hw
->mac
.san_addr
);
9919 dev_info(&pdev
->dev
,
9920 "(non-fatal) SAN MAC retrieval failed: %d\n", err
);
9921 if (!is_valid_ether_addr(hw
->mac
.san_addr
)) {
9922 dev_warn(&pdev
->dev
, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
9924 ether_addr_copy(hw
->mac
.san_addr
, hw
->mac
.addr
);
9926 dev_info(&pf
->pdev
->dev
, "SAN MAC: %pM\n", hw
->mac
.san_addr
);
9927 #endif /* I40E_FCOE */
9929 pci_set_drvdata(pdev
, pf
);
9930 pci_save_state(pdev
);
9931 #ifdef CONFIG_I40E_DCB
9932 err
= i40e_init_pf_dcb(pf
);
9934 dev_info(&pdev
->dev
, "DCB init failed %d, disabled\n", err
);
9935 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
9936 /* Continue without DCB enabled */
9938 #endif /* CONFIG_I40E_DCB */
9940 /* set up periodic task facility */
9941 setup_timer(&pf
->service_timer
, i40e_service_timer
, (unsigned long)pf
);
9942 pf
->service_timer_period
= HZ
;
9944 INIT_WORK(&pf
->service_task
, i40e_service_task
);
9945 clear_bit(__I40E_SERVICE_SCHED
, &pf
->state
);
9946 pf
->flags
|= I40E_FLAG_NEED_LINK_UPDATE
;
9947 pf
->link_check_timeout
= jiffies
;
9949 /* WoL defaults to disabled */
9951 device_set_wakeup_enable(&pf
->pdev
->dev
, pf
->wol_en
);
9953 /* set up the main switch operations */
9954 i40e_determine_queue_usage(pf
);
9955 err
= i40e_init_interrupt_scheme(pf
);
9957 goto err_switch_setup
;
9959 /* The number of VSIs reported by the FW is the minimum guaranteed
9960 * to us; HW supports far more and we share the remaining pool with
9961 * the other PFs. We allocate space for more than the guarantee with
9962 * the understanding that we might not get them all later.
9964 if (pf
->hw
.func_caps
.num_vsis
< I40E_MIN_VSI_ALLOC
)
9965 pf
->num_alloc_vsi
= I40E_MIN_VSI_ALLOC
;
9967 pf
->num_alloc_vsi
= pf
->hw
.func_caps
.num_vsis
;
9969 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
9970 len
= sizeof(struct i40e_vsi
*) * pf
->num_alloc_vsi
;
9971 pf
->vsi
= kzalloc(len
, GFP_KERNEL
);
9974 goto err_switch_setup
;
9977 #ifdef CONFIG_PCI_IOV
9978 /* prep for VF support */
9979 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
9980 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
9981 !test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
9982 if (pci_num_vf(pdev
))
9983 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
9986 err
= i40e_setup_pf_switch(pf
, false);
9988 dev_info(&pdev
->dev
, "setup_pf_switch failed: %d\n", err
);
9991 /* if FDIR VSI was set up, start it now */
9992 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9993 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
9994 i40e_vsi_open(pf
->vsi
[i
]);
9999 /* driver is only interested in link up/down and module qualification
10000 * reports from firmware
10002 err
= i40e_aq_set_phy_int_mask(&pf
->hw
,
10003 I40E_AQ_EVENT_LINK_UPDOWN
|
10004 I40E_AQ_EVENT_MODULE_QUAL_FAIL
, NULL
);
10006 dev_info(&pf
->pdev
->dev
, "set phy mask fail, err %s aq_err %s\n",
10007 i40e_stat_str(&pf
->hw
, err
),
10008 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10010 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
10011 (pf
->hw
.aq
.fw_maj_ver
< 4)) {
10013 err
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
10015 dev_info(&pf
->pdev
->dev
, "link restart failed, err %s aq_err %s\n",
10016 i40e_stat_str(&pf
->hw
, err
),
10017 i40e_aq_str(&pf
->hw
,
10018 pf
->hw
.aq
.asq_last_status
));
10020 /* The main driver is (mostly) up and happy. We need to set this state
10021 * before setting up the misc vector or we get a race and the vector
10022 * ends up disabled forever.
10024 clear_bit(__I40E_DOWN
, &pf
->state
);
10026 /* In case of MSIX we are going to setup the misc vector right here
10027 * to handle admin queue events etc. In case of legacy and MSI
10028 * the misc functionality and queue processing is combined in
10029 * the same vector and that gets setup at open.
10031 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
10032 err
= i40e_setup_misc_vector(pf
);
10034 dev_info(&pdev
->dev
,
10035 "setup of misc vector failed: %d\n", err
);
10040 #ifdef CONFIG_PCI_IOV
10041 /* prep for VF support */
10042 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
10043 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
10044 !test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
10047 /* disable link interrupts for VFs */
10048 val
= rd32(hw
, I40E_PFGEN_PORTMDIO_NUM
);
10049 val
&= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK
;
10050 wr32(hw
, I40E_PFGEN_PORTMDIO_NUM
, val
);
10053 if (pci_num_vf(pdev
)) {
10054 dev_info(&pdev
->dev
,
10055 "Active VFs found, allocating resources.\n");
10056 err
= i40e_alloc_vfs(pf
, pci_num_vf(pdev
));
10058 dev_info(&pdev
->dev
,
10059 "Error %d allocating resources for existing VFs\n",
10063 #endif /* CONFIG_PCI_IOV */
10067 i40e_dbg_pf_init(pf
);
10069 /* tell the firmware that we're starting */
10070 i40e_send_version(pf
);
10072 /* since everything's happy, start the service_task timer */
10073 mod_timer(&pf
->service_timer
,
10074 round_jiffies(jiffies
+ pf
->service_timer_period
));
10077 /* create FCoE interface */
10078 i40e_fcoe_vsi_setup(pf
);
10081 /* Get the negotiated link width and speed from PCI config space */
10082 pcie_capability_read_word(pf
->pdev
, PCI_EXP_LNKSTA
, &link_status
);
10084 i40e_set_pci_config_data(hw
, link_status
);
10086 dev_info(&pdev
->dev
, "PCI-Express: %s %s\n",
10087 (hw
->bus
.speed
== i40e_bus_speed_8000
? "Speed 8.0GT/s" :
10088 hw
->bus
.speed
== i40e_bus_speed_5000
? "Speed 5.0GT/s" :
10089 hw
->bus
.speed
== i40e_bus_speed_2500
? "Speed 2.5GT/s" :
10091 (hw
->bus
.width
== i40e_bus_width_pcie_x8
? "Width x8" :
10092 hw
->bus
.width
== i40e_bus_width_pcie_x4
? "Width x4" :
10093 hw
->bus
.width
== i40e_bus_width_pcie_x2
? "Width x2" :
10094 hw
->bus
.width
== i40e_bus_width_pcie_x1
? "Width x1" :
10097 if (hw
->bus
.width
< i40e_bus_width_pcie_x8
||
10098 hw
->bus
.speed
< i40e_bus_speed_8000
) {
10099 dev_warn(&pdev
->dev
, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
10100 dev_warn(&pdev
->dev
, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
10103 /* get the requested speeds from the fw */
10104 err
= i40e_aq_get_phy_capabilities(hw
, false, false, &abilities
, NULL
);
10106 dev_info(&pf
->pdev
->dev
,
10107 "get phy capabilities failed, err %s aq_err %s, advertised speed settings may not be correct\n",
10108 i40e_stat_str(&pf
->hw
, err
),
10109 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10110 pf
->hw
.phy
.link_info
.requested_speeds
= abilities
.link_speed
;
10112 /* print a string summarizing features */
10113 i40e_print_features(pf
);
10117 /* Unwind what we've done if something failed in the setup */
10119 set_bit(__I40E_DOWN
, &pf
->state
);
10120 i40e_clear_interrupt_scheme(pf
);
10123 i40e_reset_interrupt_capability(pf
);
10124 del_timer_sync(&pf
->service_timer
);
10126 err_configure_lan_hmc
:
10127 (void)i40e_shutdown_lan_hmc(hw
);
10129 kfree(pf
->qp_pile
);
10132 (void)i40e_shutdown_adminq(hw
);
10134 iounmap(hw
->hw_addr
);
10138 pci_disable_pcie_error_reporting(pdev
);
10139 pci_release_selected_regions(pdev
,
10140 pci_select_bars(pdev
, IORESOURCE_MEM
));
10143 pci_disable_device(pdev
);
10148 * i40e_remove - Device removal routine
10149 * @pdev: PCI device information struct
10151 * i40e_remove is called by the PCI subsystem to alert the driver
10152 * that is should release a PCI device. This could be caused by a
10153 * Hot-Plug event, or because the driver is going to be removed from
10156 static void i40e_remove(struct pci_dev
*pdev
)
10158 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10159 i40e_status ret_code
;
10162 i40e_dbg_pf_exit(pf
);
10166 /* no more scheduling of any task */
10167 set_bit(__I40E_DOWN
, &pf
->state
);
10168 del_timer_sync(&pf
->service_timer
);
10169 cancel_work_sync(&pf
->service_task
);
10170 i40e_fdir_teardown(pf
);
10172 if (pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) {
10174 pf
->flags
&= ~I40E_FLAG_SRIOV_ENABLED
;
10177 i40e_fdir_teardown(pf
);
10179 /* If there is a switch structure or any orphans, remove them.
10180 * This will leave only the PF's VSI remaining.
10182 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
10186 if (pf
->veb
[i
]->uplink_seid
== pf
->mac_seid
||
10187 pf
->veb
[i
]->uplink_seid
== 0)
10188 i40e_switch_branch_release(pf
->veb
[i
]);
10191 /* Now we can shutdown the PF's VSI, just before we kill
10194 if (pf
->vsi
[pf
->lan_vsi
])
10195 i40e_vsi_release(pf
->vsi
[pf
->lan_vsi
]);
10197 /* shutdown and destroy the HMC */
10198 if (pf
->hw
.hmc
.hmc_obj
) {
10199 ret_code
= i40e_shutdown_lan_hmc(&pf
->hw
);
10201 dev_warn(&pdev
->dev
,
10202 "Failed to destroy the HMC resources: %d\n",
10206 /* shutdown the adminq */
10207 ret_code
= i40e_shutdown_adminq(&pf
->hw
);
10209 dev_warn(&pdev
->dev
,
10210 "Failed to destroy the Admin Queue resources: %d\n",
10213 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
10214 i40e_clear_interrupt_scheme(pf
);
10215 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
10217 i40e_vsi_clear_rings(pf
->vsi
[i
]);
10218 i40e_vsi_clear(pf
->vsi
[i
]);
10223 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
10228 kfree(pf
->qp_pile
);
10231 iounmap(pf
->hw
.hw_addr
);
10233 pci_release_selected_regions(pdev
,
10234 pci_select_bars(pdev
, IORESOURCE_MEM
));
10236 pci_disable_pcie_error_reporting(pdev
);
10237 pci_disable_device(pdev
);
10241 * i40e_pci_error_detected - warning that something funky happened in PCI land
10242 * @pdev: PCI device information struct
10244 * Called to warn that something happened and the error handling steps
10245 * are in progress. Allows the driver to quiesce things, be ready for
10248 static pci_ers_result_t
i40e_pci_error_detected(struct pci_dev
*pdev
,
10249 enum pci_channel_state error
)
10251 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10253 dev_info(&pdev
->dev
, "%s: error %d\n", __func__
, error
);
10255 /* shutdown all operations */
10256 if (!test_bit(__I40E_SUSPENDED
, &pf
->state
)) {
10258 i40e_prep_for_reset(pf
);
10262 /* Request a slot reset */
10263 return PCI_ERS_RESULT_NEED_RESET
;
10267 * i40e_pci_error_slot_reset - a PCI slot reset just happened
10268 * @pdev: PCI device information struct
10270 * Called to find if the driver can work with the device now that
10271 * the pci slot has been reset. If a basic connection seems good
10272 * (registers are readable and have sane content) then return a
10273 * happy little PCI_ERS_RESULT_xxx.
10275 static pci_ers_result_t
i40e_pci_error_slot_reset(struct pci_dev
*pdev
)
10277 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10278 pci_ers_result_t result
;
10282 dev_info(&pdev
->dev
, "%s\n", __func__
);
10283 if (pci_enable_device_mem(pdev
)) {
10284 dev_info(&pdev
->dev
,
10285 "Cannot re-enable PCI device after reset.\n");
10286 result
= PCI_ERS_RESULT_DISCONNECT
;
10288 pci_set_master(pdev
);
10289 pci_restore_state(pdev
);
10290 pci_save_state(pdev
);
10291 pci_wake_from_d3(pdev
, false);
10293 reg
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
10295 result
= PCI_ERS_RESULT_RECOVERED
;
10297 result
= PCI_ERS_RESULT_DISCONNECT
;
10300 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
10302 dev_info(&pdev
->dev
,
10303 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
10305 /* non-fatal, continue */
10312 * i40e_pci_error_resume - restart operations after PCI error recovery
10313 * @pdev: PCI device information struct
10315 * Called to allow the driver to bring things back up after PCI error
10316 * and/or reset recovery has finished.
10318 static void i40e_pci_error_resume(struct pci_dev
*pdev
)
10320 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10322 dev_info(&pdev
->dev
, "%s\n", __func__
);
10323 if (test_bit(__I40E_SUSPENDED
, &pf
->state
))
10327 i40e_handle_reset_warning(pf
);
10332 * i40e_shutdown - PCI callback for shutting down
10333 * @pdev: PCI device information struct
10335 static void i40e_shutdown(struct pci_dev
*pdev
)
10337 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10338 struct i40e_hw
*hw
= &pf
->hw
;
10340 set_bit(__I40E_SUSPENDED
, &pf
->state
);
10341 set_bit(__I40E_DOWN
, &pf
->state
);
10343 i40e_prep_for_reset(pf
);
10346 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
10347 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
10349 i40e_clear_interrupt_scheme(pf
);
10351 if (system_state
== SYSTEM_POWER_OFF
) {
10352 pci_wake_from_d3(pdev
, pf
->wol_en
);
10353 pci_set_power_state(pdev
, PCI_D3hot
);
10359 * i40e_suspend - PCI callback for moving to D3
10360 * @pdev: PCI device information struct
10362 static int i40e_suspend(struct pci_dev
*pdev
, pm_message_t state
)
10364 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10365 struct i40e_hw
*hw
= &pf
->hw
;
10367 set_bit(__I40E_SUSPENDED
, &pf
->state
);
10368 set_bit(__I40E_DOWN
, &pf
->state
);
10369 del_timer_sync(&pf
->service_timer
);
10370 cancel_work_sync(&pf
->service_task
);
10371 i40e_fdir_teardown(pf
);
10374 i40e_prep_for_reset(pf
);
10377 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
10378 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
10380 pci_wake_from_d3(pdev
, pf
->wol_en
);
10381 pci_set_power_state(pdev
, PCI_D3hot
);
10387 * i40e_resume - PCI callback for waking up from D3
10388 * @pdev: PCI device information struct
10390 static int i40e_resume(struct pci_dev
*pdev
)
10392 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10395 pci_set_power_state(pdev
, PCI_D0
);
10396 pci_restore_state(pdev
);
10397 /* pci_restore_state() clears dev->state_saves, so
10398 * call pci_save_state() again to restore it.
10400 pci_save_state(pdev
);
10402 err
= pci_enable_device_mem(pdev
);
10404 dev_err(&pdev
->dev
,
10405 "%s: Cannot enable PCI device from suspend\n",
10409 pci_set_master(pdev
);
10411 /* no wakeup events while running */
10412 pci_wake_from_d3(pdev
, false);
10414 /* handling the reset will rebuild the device state */
10415 if (test_and_clear_bit(__I40E_SUSPENDED
, &pf
->state
)) {
10416 clear_bit(__I40E_DOWN
, &pf
->state
);
10418 i40e_reset_and_rebuild(pf
, false);
10426 static const struct pci_error_handlers i40e_err_handler
= {
10427 .error_detected
= i40e_pci_error_detected
,
10428 .slot_reset
= i40e_pci_error_slot_reset
,
10429 .resume
= i40e_pci_error_resume
,
10432 static struct pci_driver i40e_driver
= {
10433 .name
= i40e_driver_name
,
10434 .id_table
= i40e_pci_tbl
,
10435 .probe
= i40e_probe
,
10436 .remove
= i40e_remove
,
10438 .suspend
= i40e_suspend
,
10439 .resume
= i40e_resume
,
10441 .shutdown
= i40e_shutdown
,
10442 .err_handler
= &i40e_err_handler
,
10443 .sriov_configure
= i40e_pci_sriov_configure
,
10447 * i40e_init_module - Driver registration routine
10449 * i40e_init_module is the first routine called when the driver is
10450 * loaded. All it does is register with the PCI subsystem.
10452 static int __init
i40e_init_module(void)
10454 pr_info("%s: %s - version %s\n", i40e_driver_name
,
10455 i40e_driver_string
, i40e_driver_version_str
);
10456 pr_info("%s: %s\n", i40e_driver_name
, i40e_copyright
);
10459 return pci_register_driver(&i40e_driver
);
10461 module_init(i40e_init_module
);
10464 * i40e_exit_module - Driver exit cleanup routine
10466 * i40e_exit_module is called just before the driver is removed
10469 static void __exit
i40e_exit_module(void)
10471 pci_unregister_driver(&i40e_driver
);
10474 module_exit(i40e_exit_module
);