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
) {
1259 f
->vlan
= le16_to_cpu(vsi
->info
.pvid
);
1260 if (!i40e_find_filter(vsi
, macaddr
, f
->vlan
,
1261 is_vf
, is_netdev
)) {
1262 if (!i40e_add_filter(vsi
, macaddr
, f
->vlan
,
1268 return list_first_entry_or_null(&vsi
->mac_filter_list
,
1269 struct i40e_mac_filter
, list
);
1273 * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
1274 * @vsi: the PF Main VSI - inappropriate for any other VSI
1275 * @macaddr: the MAC address
1277 * Some older firmware configurations set up a default promiscuous VLAN
1278 * filter that needs to be removed.
1280 static int i40e_rm_default_mac_filter(struct i40e_vsi
*vsi
, u8
*macaddr
)
1282 struct i40e_aqc_remove_macvlan_element_data element
;
1283 struct i40e_pf
*pf
= vsi
->back
;
1286 /* Only appropriate for the PF main VSI */
1287 if (vsi
->type
!= I40E_VSI_MAIN
)
1290 memset(&element
, 0, sizeof(element
));
1291 ether_addr_copy(element
.mac_addr
, macaddr
);
1292 element
.vlan_tag
= 0;
1293 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
|
1294 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
1295 ret
= i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1303 * i40e_add_filter - Add a mac/vlan filter to the VSI
1304 * @vsi: the VSI to be searched
1305 * @macaddr: the MAC address
1307 * @is_vf: make sure its a VF filter, else doesn't matter
1308 * @is_netdev: make sure its a netdev filter, else doesn't matter
1310 * Returns ptr to the filter object or NULL when no memory available.
1312 struct i40e_mac_filter
*i40e_add_filter(struct i40e_vsi
*vsi
,
1313 u8
*macaddr
, s16 vlan
,
1314 bool is_vf
, bool is_netdev
)
1316 struct i40e_mac_filter
*f
;
1318 if (!vsi
|| !macaddr
)
1321 f
= i40e_find_filter(vsi
, macaddr
, vlan
, is_vf
, is_netdev
);
1323 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
1325 goto add_filter_out
;
1327 ether_addr_copy(f
->macaddr
, macaddr
);
1331 INIT_LIST_HEAD(&f
->list
);
1332 list_add(&f
->list
, &vsi
->mac_filter_list
);
1335 /* increment counter and add a new flag if needed */
1341 } else if (is_netdev
) {
1342 if (!f
->is_netdev
) {
1343 f
->is_netdev
= true;
1350 /* changed tells sync_filters_subtask to
1351 * push the filter down to the firmware
1354 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1355 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1363 * i40e_del_filter - Remove a mac/vlan filter from the VSI
1364 * @vsi: the VSI to be searched
1365 * @macaddr: the MAC address
1367 * @is_vf: make sure it's a VF filter, else doesn't matter
1368 * @is_netdev: make sure it's a netdev filter, else doesn't matter
1370 void i40e_del_filter(struct i40e_vsi
*vsi
,
1371 u8
*macaddr
, s16 vlan
,
1372 bool is_vf
, bool is_netdev
)
1374 struct i40e_mac_filter
*f
;
1376 if (!vsi
|| !macaddr
)
1379 f
= i40e_find_filter(vsi
, macaddr
, vlan
, is_vf
, is_netdev
);
1380 if (!f
|| f
->counter
== 0)
1388 } else if (is_netdev
) {
1390 f
->is_netdev
= false;
1394 /* make sure we don't remove a filter in use by VF or netdev */
1396 min_f
+= (f
->is_vf
? 1 : 0);
1397 min_f
+= (f
->is_netdev
? 1 : 0);
1399 if (f
->counter
> min_f
)
1403 /* counter == 0 tells sync_filters_subtask to
1404 * remove the filter from the firmware's list
1406 if (f
->counter
== 0) {
1408 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1409 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1414 * i40e_set_mac - NDO callback to set mac address
1415 * @netdev: network interface device structure
1416 * @p: pointer to an address structure
1418 * Returns 0 on success, negative on failure
1421 int i40e_set_mac(struct net_device
*netdev
, void *p
)
1423 static int i40e_set_mac(struct net_device
*netdev
, void *p
)
1426 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1427 struct i40e_vsi
*vsi
= np
->vsi
;
1428 struct i40e_pf
*pf
= vsi
->back
;
1429 struct i40e_hw
*hw
= &pf
->hw
;
1430 struct sockaddr
*addr
= p
;
1431 struct i40e_mac_filter
*f
;
1433 if (!is_valid_ether_addr(addr
->sa_data
))
1434 return -EADDRNOTAVAIL
;
1436 if (ether_addr_equal(netdev
->dev_addr
, addr
->sa_data
)) {
1437 netdev_info(netdev
, "already using mac address %pM\n",
1442 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
1443 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
1444 return -EADDRNOTAVAIL
;
1446 if (ether_addr_equal(hw
->mac
.addr
, addr
->sa_data
))
1447 netdev_info(netdev
, "returning to hw mac address %pM\n",
1450 netdev_info(netdev
, "set new mac address %pM\n", addr
->sa_data
);
1452 if (vsi
->type
== I40E_VSI_MAIN
) {
1454 ret
= i40e_aq_mac_address_write(&vsi
->back
->hw
,
1455 I40E_AQC_WRITE_TYPE_LAA_WOL
,
1456 addr
->sa_data
, NULL
);
1459 "Addr change for Main VSI failed: %d\n",
1461 return -EADDRNOTAVAIL
;
1465 if (ether_addr_equal(netdev
->dev_addr
, hw
->mac
.addr
)) {
1466 struct i40e_aqc_remove_macvlan_element_data element
;
1468 memset(&element
, 0, sizeof(element
));
1469 ether_addr_copy(element
.mac_addr
, netdev
->dev_addr
);
1470 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
1471 i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1473 i40e_del_filter(vsi
, netdev
->dev_addr
, I40E_VLAN_ANY
,
1477 if (ether_addr_equal(addr
->sa_data
, hw
->mac
.addr
)) {
1478 struct i40e_aqc_add_macvlan_element_data element
;
1480 memset(&element
, 0, sizeof(element
));
1481 ether_addr_copy(element
.mac_addr
, hw
->mac
.addr
);
1482 element
.flags
= cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
);
1483 i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1485 f
= i40e_add_filter(vsi
, addr
->sa_data
, I40E_VLAN_ANY
,
1491 i40e_sync_vsi_filters(vsi
);
1492 ether_addr_copy(netdev
->dev_addr
, addr
->sa_data
);
1498 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1499 * @vsi: the VSI being setup
1500 * @ctxt: VSI context structure
1501 * @enabled_tc: Enabled TCs bitmap
1502 * @is_add: True if called before Add VSI
1504 * Setup VSI queue mapping for enabled traffic classes.
1507 void i40e_vsi_setup_queue_map(struct i40e_vsi
*vsi
,
1508 struct i40e_vsi_context
*ctxt
,
1512 static void i40e_vsi_setup_queue_map(struct i40e_vsi
*vsi
,
1513 struct i40e_vsi_context
*ctxt
,
1518 struct i40e_pf
*pf
= vsi
->back
;
1528 sections
= I40E_AQ_VSI_PROP_QUEUE_MAP_VALID
;
1531 if (enabled_tc
&& (vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
1532 /* Find numtc from enabled TC bitmap */
1533 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1534 if (enabled_tc
& BIT_ULL(i
)) /* TC is enabled */
1538 dev_warn(&pf
->pdev
->dev
, "DCB is enabled but no TC enabled, forcing TC0\n");
1542 /* At least TC0 is enabled in case of non-DCB case */
1546 vsi
->tc_config
.numtc
= numtc
;
1547 vsi
->tc_config
.enabled_tc
= enabled_tc
? enabled_tc
: 1;
1548 /* Number of queues per enabled TC */
1549 /* In MFP case we can have a much lower count of MSIx
1550 * vectors available and so we need to lower the used
1553 qcount
= min_t(int, vsi
->alloc_queue_pairs
, pf
->num_lan_msix
);
1554 num_tc_qps
= qcount
/ numtc
;
1555 num_tc_qps
= min_t(int, num_tc_qps
, i40e_pf_get_max_q_per_tc(pf
));
1557 /* Setup queue offset/count for all TCs for given VSI */
1558 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1559 /* See if the given TC is enabled for the given VSI */
1560 if (vsi
->tc_config
.enabled_tc
& BIT_ULL(i
)) {
1564 switch (vsi
->type
) {
1566 qcount
= min_t(int, pf
->rss_size
, num_tc_qps
);
1570 qcount
= num_tc_qps
;
1574 case I40E_VSI_SRIOV
:
1575 case I40E_VSI_VMDQ2
:
1577 qcount
= num_tc_qps
;
1581 vsi
->tc_config
.tc_info
[i
].qoffset
= offset
;
1582 vsi
->tc_config
.tc_info
[i
].qcount
= qcount
;
1584 /* find the next higher power-of-2 of num queue pairs */
1587 while (num_qps
&& (BIT_ULL(pow
) < qcount
)) {
1592 vsi
->tc_config
.tc_info
[i
].netdev_tc
= netdev_tc
++;
1594 (offset
<< I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT
) |
1595 (pow
<< I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT
);
1599 /* TC is not enabled so set the offset to
1600 * default queue and allocate one queue
1603 vsi
->tc_config
.tc_info
[i
].qoffset
= 0;
1604 vsi
->tc_config
.tc_info
[i
].qcount
= 1;
1605 vsi
->tc_config
.tc_info
[i
].netdev_tc
= 0;
1609 ctxt
->info
.tc_mapping
[i
] = cpu_to_le16(qmap
);
1612 /* Set actual Tx/Rx queue pairs */
1613 vsi
->num_queue_pairs
= offset
;
1614 if ((vsi
->type
== I40E_VSI_MAIN
) && (numtc
== 1)) {
1615 if (vsi
->req_queue_pairs
> 0)
1616 vsi
->num_queue_pairs
= vsi
->req_queue_pairs
;
1618 vsi
->num_queue_pairs
= pf
->num_lan_msix
;
1621 /* Scheduler section valid can only be set for ADD VSI */
1623 sections
|= I40E_AQ_VSI_PROP_SCHED_VALID
;
1625 ctxt
->info
.up_enable_bits
= enabled_tc
;
1627 if (vsi
->type
== I40E_VSI_SRIOV
) {
1628 ctxt
->info
.mapping_flags
|=
1629 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG
);
1630 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
1631 ctxt
->info
.queue_mapping
[i
] =
1632 cpu_to_le16(vsi
->base_queue
+ i
);
1634 ctxt
->info
.mapping_flags
|=
1635 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG
);
1636 ctxt
->info
.queue_mapping
[0] = cpu_to_le16(vsi
->base_queue
);
1638 ctxt
->info
.valid_sections
|= cpu_to_le16(sections
);
1642 * i40e_set_rx_mode - NDO callback to set the netdev filters
1643 * @netdev: network interface device structure
1646 void i40e_set_rx_mode(struct net_device
*netdev
)
1648 static void i40e_set_rx_mode(struct net_device
*netdev
)
1651 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1652 struct i40e_mac_filter
*f
, *ftmp
;
1653 struct i40e_vsi
*vsi
= np
->vsi
;
1654 struct netdev_hw_addr
*uca
;
1655 struct netdev_hw_addr
*mca
;
1656 struct netdev_hw_addr
*ha
;
1658 /* add addr if not already in the filter list */
1659 netdev_for_each_uc_addr(uca
, netdev
) {
1660 if (!i40e_find_mac(vsi
, uca
->addr
, false, true)) {
1661 if (i40e_is_vsi_in_vlan(vsi
))
1662 i40e_put_mac_in_vlan(vsi
, uca
->addr
,
1665 i40e_add_filter(vsi
, uca
->addr
, I40E_VLAN_ANY
,
1670 netdev_for_each_mc_addr(mca
, netdev
) {
1671 if (!i40e_find_mac(vsi
, mca
->addr
, false, true)) {
1672 if (i40e_is_vsi_in_vlan(vsi
))
1673 i40e_put_mac_in_vlan(vsi
, mca
->addr
,
1676 i40e_add_filter(vsi
, mca
->addr
, I40E_VLAN_ANY
,
1681 /* remove filter if not in netdev list */
1682 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1688 if (is_multicast_ether_addr(f
->macaddr
)) {
1689 netdev_for_each_mc_addr(mca
, netdev
) {
1690 if (ether_addr_equal(mca
->addr
, f
->macaddr
)) {
1696 netdev_for_each_uc_addr(uca
, netdev
) {
1697 if (ether_addr_equal(uca
->addr
, f
->macaddr
)) {
1703 for_each_dev_addr(netdev
, ha
) {
1704 if (ether_addr_equal(ha
->addr
, f
->macaddr
)) {
1712 vsi
, f
->macaddr
, I40E_VLAN_ANY
, false, true);
1715 /* check for other flag changes */
1716 if (vsi
->current_netdev_flags
!= vsi
->netdev
->flags
) {
1717 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1718 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1723 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
1724 * @vsi: ptr to the VSI
1726 * Push any outstanding VSI filter changes through the AdminQ.
1728 * Returns 0 or error value
1730 int i40e_sync_vsi_filters(struct i40e_vsi
*vsi
)
1732 struct i40e_mac_filter
*f
, *ftmp
;
1733 bool promisc_forced_on
= false;
1734 bool add_happened
= false;
1735 int filter_list_len
= 0;
1736 u32 changed_flags
= 0;
1737 i40e_status ret
= 0;
1744 /* empty array typed pointers, kcalloc later */
1745 struct i40e_aqc_add_macvlan_element_data
*add_list
;
1746 struct i40e_aqc_remove_macvlan_element_data
*del_list
;
1748 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &vsi
->state
))
1749 usleep_range(1000, 2000);
1753 changed_flags
= vsi
->current_netdev_flags
^ vsi
->netdev
->flags
;
1754 vsi
->current_netdev_flags
= vsi
->netdev
->flags
;
1757 if (vsi
->flags
& I40E_VSI_FLAG_FILTER_CHANGED
) {
1758 vsi
->flags
&= ~I40E_VSI_FLAG_FILTER_CHANGED
;
1760 filter_list_len
= pf
->hw
.aq
.asq_buf_size
/
1761 sizeof(struct i40e_aqc_remove_macvlan_element_data
);
1762 del_list
= kcalloc(filter_list_len
,
1763 sizeof(struct i40e_aqc_remove_macvlan_element_data
),
1768 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1772 if (f
->counter
!= 0)
1777 /* add to delete list */
1778 ether_addr_copy(del_list
[num_del
].mac_addr
, f
->macaddr
);
1779 del_list
[num_del
].vlan_tag
=
1780 cpu_to_le16((u16
)(f
->vlan
==
1781 I40E_VLAN_ANY
? 0 : f
->vlan
));
1783 cmd_flags
|= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
1784 del_list
[num_del
].flags
= cmd_flags
;
1787 /* unlink from filter list */
1791 /* flush a full buffer */
1792 if (num_del
== filter_list_len
) {
1793 ret
= i40e_aq_remove_macvlan(&pf
->hw
,
1794 vsi
->seid
, del_list
, num_del
,
1796 aq_err
= pf
->hw
.aq
.asq_last_status
;
1798 memset(del_list
, 0, sizeof(*del_list
));
1800 if (ret
&& aq_err
!= I40E_AQ_RC_ENOENT
)
1801 dev_info(&pf
->pdev
->dev
,
1802 "ignoring delete macvlan error, err %s, aq_err %s while flushing a full buffer\n",
1803 i40e_stat_str(&pf
->hw
, ret
),
1804 i40e_aq_str(&pf
->hw
, aq_err
));
1808 ret
= i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
,
1809 del_list
, num_del
, NULL
);
1810 aq_err
= pf
->hw
.aq
.asq_last_status
;
1813 if (ret
&& aq_err
!= I40E_AQ_RC_ENOENT
)
1814 dev_info(&pf
->pdev
->dev
,
1815 "ignoring delete macvlan error, err %s aq_err %s\n",
1816 i40e_stat_str(&pf
->hw
, ret
),
1817 i40e_aq_str(&pf
->hw
, aq_err
));
1823 /* do all the adds now */
1824 filter_list_len
= pf
->hw
.aq
.asq_buf_size
/
1825 sizeof(struct i40e_aqc_add_macvlan_element_data
),
1826 add_list
= kcalloc(filter_list_len
,
1827 sizeof(struct i40e_aqc_add_macvlan_element_data
),
1832 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1836 if (f
->counter
== 0)
1839 add_happened
= true;
1842 /* add to add array */
1843 ether_addr_copy(add_list
[num_add
].mac_addr
, f
->macaddr
);
1844 add_list
[num_add
].vlan_tag
=
1846 (u16
)(f
->vlan
== I40E_VLAN_ANY
? 0 : f
->vlan
));
1847 add_list
[num_add
].queue_number
= 0;
1849 cmd_flags
|= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
;
1850 add_list
[num_add
].flags
= cpu_to_le16(cmd_flags
);
1853 /* flush a full buffer */
1854 if (num_add
== filter_list_len
) {
1855 ret
= i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
,
1858 aq_err
= pf
->hw
.aq
.asq_last_status
;
1863 memset(add_list
, 0, sizeof(*add_list
));
1867 ret
= i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
,
1868 add_list
, num_add
, NULL
);
1869 aq_err
= pf
->hw
.aq
.asq_last_status
;
1875 if (add_happened
&& ret
&& aq_err
!= I40E_AQ_RC_EINVAL
) {
1876 dev_info(&pf
->pdev
->dev
,
1877 "add filter failed, err %s aq_err %s\n",
1878 i40e_stat_str(&pf
->hw
, ret
),
1879 i40e_aq_str(&pf
->hw
, aq_err
));
1880 if ((pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_ENOSPC
) &&
1881 !test_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
1883 promisc_forced_on
= true;
1884 set_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
1886 dev_info(&pf
->pdev
->dev
, "promiscuous mode forced on\n");
1891 /* check for changes in promiscuous modes */
1892 if (changed_flags
& IFF_ALLMULTI
) {
1893 bool cur_multipromisc
;
1894 cur_multipromisc
= !!(vsi
->current_netdev_flags
& IFF_ALLMULTI
);
1895 ret
= i40e_aq_set_vsi_multicast_promiscuous(&vsi
->back
->hw
,
1900 dev_info(&pf
->pdev
->dev
,
1901 "set multi promisc failed, err %s aq_err %s\n",
1902 i40e_stat_str(&pf
->hw
, ret
),
1903 i40e_aq_str(&pf
->hw
,
1904 pf
->hw
.aq
.asq_last_status
));
1906 if ((changed_flags
& IFF_PROMISC
) || promisc_forced_on
) {
1908 cur_promisc
= (!!(vsi
->current_netdev_flags
& IFF_PROMISC
) ||
1909 test_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
1911 ret
= i40e_aq_set_vsi_unicast_promiscuous(&vsi
->back
->hw
,
1915 dev_info(&pf
->pdev
->dev
,
1916 "set uni promisc failed, err %s, aq_err %s\n",
1917 i40e_stat_str(&pf
->hw
, ret
),
1918 i40e_aq_str(&pf
->hw
,
1919 pf
->hw
.aq
.asq_last_status
));
1920 ret
= i40e_aq_set_vsi_broadcast(&vsi
->back
->hw
,
1924 dev_info(&pf
->pdev
->dev
,
1925 "set brdcast promisc failed, err %s, aq_err %s\n",
1926 i40e_stat_str(&pf
->hw
, ret
),
1927 i40e_aq_str(&pf
->hw
,
1928 pf
->hw
.aq
.asq_last_status
));
1931 clear_bit(__I40E_CONFIG_BUSY
, &vsi
->state
);
1936 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
1937 * @pf: board private structure
1939 static void i40e_sync_filters_subtask(struct i40e_pf
*pf
)
1943 if (!pf
|| !(pf
->flags
& I40E_FLAG_FILTER_SYNC
))
1945 pf
->flags
&= ~I40E_FLAG_FILTER_SYNC
;
1947 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
1949 (pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_FILTER_CHANGED
))
1950 i40e_sync_vsi_filters(pf
->vsi
[v
]);
1955 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
1956 * @netdev: network interface device structure
1957 * @new_mtu: new value for maximum frame size
1959 * Returns 0 on success, negative on failure
1961 static int i40e_change_mtu(struct net_device
*netdev
, int new_mtu
)
1963 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1964 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
1965 struct i40e_vsi
*vsi
= np
->vsi
;
1967 /* MTU < 68 is an error and causes problems on some kernels */
1968 if ((new_mtu
< 68) || (max_frame
> I40E_MAX_RXBUFFER
))
1971 netdev_info(netdev
, "changing MTU from %d to %d\n",
1972 netdev
->mtu
, new_mtu
);
1973 netdev
->mtu
= new_mtu
;
1974 if (netif_running(netdev
))
1975 i40e_vsi_reinit_locked(vsi
);
1981 * i40e_ioctl - Access the hwtstamp interface
1982 * @netdev: network interface device structure
1983 * @ifr: interface request data
1984 * @cmd: ioctl command
1986 int i40e_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
1988 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1989 struct i40e_pf
*pf
= np
->vsi
->back
;
1993 return i40e_ptp_get_ts_config(pf
, ifr
);
1995 return i40e_ptp_set_ts_config(pf
, ifr
);
2002 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
2003 * @vsi: the vsi being adjusted
2005 void i40e_vlan_stripping_enable(struct i40e_vsi
*vsi
)
2007 struct i40e_vsi_context ctxt
;
2010 if ((vsi
->info
.valid_sections
&
2011 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
2012 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_MODE_MASK
) == 0))
2013 return; /* already enabled */
2015 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2016 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
2017 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH
;
2019 ctxt
.seid
= vsi
->seid
;
2020 ctxt
.info
= vsi
->info
;
2021 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2023 dev_info(&vsi
->back
->pdev
->dev
,
2024 "update vlan stripping failed, err %s aq_err %s\n",
2025 i40e_stat_str(&vsi
->back
->hw
, ret
),
2026 i40e_aq_str(&vsi
->back
->hw
,
2027 vsi
->back
->hw
.aq
.asq_last_status
));
2032 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2033 * @vsi: the vsi being adjusted
2035 void i40e_vlan_stripping_disable(struct i40e_vsi
*vsi
)
2037 struct i40e_vsi_context ctxt
;
2040 if ((vsi
->info
.valid_sections
&
2041 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
2042 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_EMOD_MASK
) ==
2043 I40E_AQ_VSI_PVLAN_EMOD_MASK
))
2044 return; /* already disabled */
2046 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2047 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
2048 I40E_AQ_VSI_PVLAN_EMOD_NOTHING
;
2050 ctxt
.seid
= vsi
->seid
;
2051 ctxt
.info
= vsi
->info
;
2052 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2054 dev_info(&vsi
->back
->pdev
->dev
,
2055 "update vlan stripping failed, err %s aq_err %s\n",
2056 i40e_stat_str(&vsi
->back
->hw
, ret
),
2057 i40e_aq_str(&vsi
->back
->hw
,
2058 vsi
->back
->hw
.aq
.asq_last_status
));
2063 * i40e_vlan_rx_register - Setup or shutdown vlan offload
2064 * @netdev: network interface to be adjusted
2065 * @features: netdev features to test if VLAN offload is enabled or not
2067 static void i40e_vlan_rx_register(struct net_device
*netdev
, u32 features
)
2069 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2070 struct i40e_vsi
*vsi
= np
->vsi
;
2072 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
2073 i40e_vlan_stripping_enable(vsi
);
2075 i40e_vlan_stripping_disable(vsi
);
2079 * i40e_vsi_add_vlan - Add vsi membership for given vlan
2080 * @vsi: the vsi being configured
2081 * @vid: vlan id to be added (0 = untagged only , -1 = any)
2083 int i40e_vsi_add_vlan(struct i40e_vsi
*vsi
, s16 vid
)
2085 struct i40e_mac_filter
*f
, *add_f
;
2086 bool is_netdev
, is_vf
;
2088 is_vf
= (vsi
->type
== I40E_VSI_SRIOV
);
2089 is_netdev
= !!(vsi
->netdev
);
2092 add_f
= i40e_add_filter(vsi
, vsi
->netdev
->dev_addr
, vid
,
2095 dev_info(&vsi
->back
->pdev
->dev
,
2096 "Could not add vlan filter %d for %pM\n",
2097 vid
, vsi
->netdev
->dev_addr
);
2102 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2103 add_f
= i40e_add_filter(vsi
, f
->macaddr
, vid
, is_vf
, is_netdev
);
2105 dev_info(&vsi
->back
->pdev
->dev
,
2106 "Could not add vlan filter %d for %pM\n",
2112 /* Now if we add a vlan tag, make sure to check if it is the first
2113 * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
2114 * with 0, so we now accept untagged and specified tagged traffic
2115 * (and not any taged and untagged)
2118 if (is_netdev
&& i40e_find_filter(vsi
, vsi
->netdev
->dev_addr
,
2120 is_vf
, is_netdev
)) {
2121 i40e_del_filter(vsi
, vsi
->netdev
->dev_addr
,
2122 I40E_VLAN_ANY
, is_vf
, is_netdev
);
2123 add_f
= i40e_add_filter(vsi
, vsi
->netdev
->dev_addr
, 0,
2126 dev_info(&vsi
->back
->pdev
->dev
,
2127 "Could not add filter 0 for %pM\n",
2128 vsi
->netdev
->dev_addr
);
2134 /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
2135 if (vid
> 0 && !vsi
->info
.pvid
) {
2136 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2137 if (i40e_find_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2138 is_vf
, is_netdev
)) {
2139 i40e_del_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2141 add_f
= i40e_add_filter(vsi
, f
->macaddr
,
2142 0, is_vf
, is_netdev
);
2144 dev_info(&vsi
->back
->pdev
->dev
,
2145 "Could not add filter 0 for %pM\n",
2153 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
2154 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
2157 return i40e_sync_vsi_filters(vsi
);
2161 * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
2162 * @vsi: the vsi being configured
2163 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
2165 * Return: 0 on success or negative otherwise
2167 int i40e_vsi_kill_vlan(struct i40e_vsi
*vsi
, s16 vid
)
2169 struct net_device
*netdev
= vsi
->netdev
;
2170 struct i40e_mac_filter
*f
, *add_f
;
2171 bool is_vf
, is_netdev
;
2172 int filter_count
= 0;
2174 is_vf
= (vsi
->type
== I40E_VSI_SRIOV
);
2175 is_netdev
= !!(netdev
);
2178 i40e_del_filter(vsi
, netdev
->dev_addr
, vid
, is_vf
, is_netdev
);
2180 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
)
2181 i40e_del_filter(vsi
, f
->macaddr
, vid
, is_vf
, is_netdev
);
2183 /* go through all the filters for this VSI and if there is only
2184 * vid == 0 it means there are no other filters, so vid 0 must
2185 * be replaced with -1. This signifies that we should from now
2186 * on accept any traffic (with any tag present, or untagged)
2188 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2191 ether_addr_equal(netdev
->dev_addr
, f
->macaddr
))
2199 if (!filter_count
&& is_netdev
) {
2200 i40e_del_filter(vsi
, netdev
->dev_addr
, 0, is_vf
, is_netdev
);
2201 f
= i40e_add_filter(vsi
, netdev
->dev_addr
, I40E_VLAN_ANY
,
2204 dev_info(&vsi
->back
->pdev
->dev
,
2205 "Could not add filter %d for %pM\n",
2206 I40E_VLAN_ANY
, netdev
->dev_addr
);
2211 if (!filter_count
) {
2212 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2213 i40e_del_filter(vsi
, f
->macaddr
, 0, is_vf
, is_netdev
);
2214 add_f
= i40e_add_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2217 dev_info(&vsi
->back
->pdev
->dev
,
2218 "Could not add filter %d for %pM\n",
2219 I40E_VLAN_ANY
, f
->macaddr
);
2225 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
2226 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
2229 return i40e_sync_vsi_filters(vsi
);
2233 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2234 * @netdev: network interface to be adjusted
2235 * @vid: vlan id to be added
2237 * net_device_ops implementation for adding vlan ids
2240 int i40e_vlan_rx_add_vid(struct net_device
*netdev
,
2241 __always_unused __be16 proto
, u16 vid
)
2243 static int i40e_vlan_rx_add_vid(struct net_device
*netdev
,
2244 __always_unused __be16 proto
, u16 vid
)
2247 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2248 struct i40e_vsi
*vsi
= np
->vsi
;
2254 netdev_info(netdev
, "adding %pM vid=%d\n", netdev
->dev_addr
, vid
);
2256 /* If the network stack called us with vid = 0 then
2257 * it is asking to receive priority tagged packets with
2258 * vlan id 0. Our HW receives them by default when configured
2259 * to receive untagged packets so there is no need to add an
2260 * extra filter for vlan 0 tagged packets.
2263 ret
= i40e_vsi_add_vlan(vsi
, vid
);
2265 if (!ret
&& (vid
< VLAN_N_VID
))
2266 set_bit(vid
, vsi
->active_vlans
);
2272 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2273 * @netdev: network interface to be adjusted
2274 * @vid: vlan id to be removed
2276 * net_device_ops implementation for removing vlan ids
2279 int i40e_vlan_rx_kill_vid(struct net_device
*netdev
,
2280 __always_unused __be16 proto
, u16 vid
)
2282 static int i40e_vlan_rx_kill_vid(struct net_device
*netdev
,
2283 __always_unused __be16 proto
, u16 vid
)
2286 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2287 struct i40e_vsi
*vsi
= np
->vsi
;
2289 netdev_info(netdev
, "removing %pM vid=%d\n", netdev
->dev_addr
, vid
);
2291 /* return code is ignored as there is nothing a user
2292 * can do about failure to remove and a log message was
2293 * already printed from the other function
2295 i40e_vsi_kill_vlan(vsi
, vid
);
2297 clear_bit(vid
, vsi
->active_vlans
);
2303 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2304 * @vsi: the vsi being brought back up
2306 static void i40e_restore_vlan(struct i40e_vsi
*vsi
)
2313 i40e_vlan_rx_register(vsi
->netdev
, vsi
->netdev
->features
);
2315 for_each_set_bit(vid
, vsi
->active_vlans
, VLAN_N_VID
)
2316 i40e_vlan_rx_add_vid(vsi
->netdev
, htons(ETH_P_8021Q
),
2321 * i40e_vsi_add_pvid - Add pvid for the VSI
2322 * @vsi: the vsi being adjusted
2323 * @vid: the vlan id to set as a PVID
2325 int i40e_vsi_add_pvid(struct i40e_vsi
*vsi
, u16 vid
)
2327 struct i40e_vsi_context ctxt
;
2330 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2331 vsi
->info
.pvid
= cpu_to_le16(vid
);
2332 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_TAGGED
|
2333 I40E_AQ_VSI_PVLAN_INSERT_PVID
|
2334 I40E_AQ_VSI_PVLAN_EMOD_STR
;
2336 ctxt
.seid
= vsi
->seid
;
2337 ctxt
.info
= vsi
->info
;
2338 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2340 dev_info(&vsi
->back
->pdev
->dev
,
2341 "add pvid failed, err %s aq_err %s\n",
2342 i40e_stat_str(&vsi
->back
->hw
, ret
),
2343 i40e_aq_str(&vsi
->back
->hw
,
2344 vsi
->back
->hw
.aq
.asq_last_status
));
2352 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2353 * @vsi: the vsi being adjusted
2355 * Just use the vlan_rx_register() service to put it back to normal
2357 void i40e_vsi_remove_pvid(struct i40e_vsi
*vsi
)
2359 i40e_vlan_stripping_disable(vsi
);
2365 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2366 * @vsi: ptr to the VSI
2368 * If this function returns with an error, then it's possible one or
2369 * more of the rings is populated (while the rest are not). It is the
2370 * callers duty to clean those orphaned rings.
2372 * Return 0 on success, negative on failure
2374 static int i40e_vsi_setup_tx_resources(struct i40e_vsi
*vsi
)
2378 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2379 err
= i40e_setup_tx_descriptors(vsi
->tx_rings
[i
]);
2385 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2386 * @vsi: ptr to the VSI
2388 * Free VSI's transmit software resources
2390 static void i40e_vsi_free_tx_resources(struct i40e_vsi
*vsi
)
2397 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2398 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
)
2399 i40e_free_tx_resources(vsi
->tx_rings
[i
]);
2403 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2404 * @vsi: ptr to the VSI
2406 * If this function returns with an error, then it's possible one or
2407 * more of the rings is populated (while the rest are not). It is the
2408 * callers duty to clean those orphaned rings.
2410 * Return 0 on success, negative on failure
2412 static int i40e_vsi_setup_rx_resources(struct i40e_vsi
*vsi
)
2416 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2417 err
= i40e_setup_rx_descriptors(vsi
->rx_rings
[i
]);
2419 i40e_fcoe_setup_ddp_resources(vsi
);
2425 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2426 * @vsi: ptr to the VSI
2428 * Free all receive software resources
2430 static void i40e_vsi_free_rx_resources(struct i40e_vsi
*vsi
)
2437 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2438 if (vsi
->rx_rings
[i
] && vsi
->rx_rings
[i
]->desc
)
2439 i40e_free_rx_resources(vsi
->rx_rings
[i
]);
2441 i40e_fcoe_free_ddp_resources(vsi
);
2446 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
2447 * @ring: The Tx ring to configure
2449 * This enables/disables XPS for a given Tx descriptor ring
2450 * based on the TCs enabled for the VSI that ring belongs to.
2452 static void i40e_config_xps_tx_ring(struct i40e_ring
*ring
)
2454 struct i40e_vsi
*vsi
= ring
->vsi
;
2457 if (!ring
->q_vector
|| !ring
->netdev
)
2460 /* Single TC mode enable XPS */
2461 if (vsi
->tc_config
.numtc
<= 1) {
2462 if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE
, &ring
->state
))
2463 netif_set_xps_queue(ring
->netdev
,
2464 &ring
->q_vector
->affinity_mask
,
2466 } else if (alloc_cpumask_var(&mask
, GFP_KERNEL
)) {
2467 /* Disable XPS to allow selection based on TC */
2468 bitmap_zero(cpumask_bits(mask
), nr_cpumask_bits
);
2469 netif_set_xps_queue(ring
->netdev
, mask
, ring
->queue_index
);
2470 free_cpumask_var(mask
);
2475 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2476 * @ring: The Tx ring to configure
2478 * Configure the Tx descriptor ring in the HMC context.
2480 static int i40e_configure_tx_ring(struct i40e_ring
*ring
)
2482 struct i40e_vsi
*vsi
= ring
->vsi
;
2483 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
2484 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2485 struct i40e_hmc_obj_txq tx_ctx
;
2486 i40e_status err
= 0;
2489 /* some ATR related tx ring init */
2490 if (vsi
->back
->flags
& I40E_FLAG_FD_ATR_ENABLED
) {
2491 ring
->atr_sample_rate
= vsi
->back
->atr_sample_rate
;
2492 ring
->atr_count
= 0;
2494 ring
->atr_sample_rate
= 0;
2498 i40e_config_xps_tx_ring(ring
);
2500 /* clear the context structure first */
2501 memset(&tx_ctx
, 0, sizeof(tx_ctx
));
2503 tx_ctx
.new_context
= 1;
2504 tx_ctx
.base
= (ring
->dma
/ 128);
2505 tx_ctx
.qlen
= ring
->count
;
2506 tx_ctx
.fd_ena
= !!(vsi
->back
->flags
& (I40E_FLAG_FD_SB_ENABLED
|
2507 I40E_FLAG_FD_ATR_ENABLED
));
2509 tx_ctx
.fc_ena
= (vsi
->type
== I40E_VSI_FCOE
);
2511 tx_ctx
.timesync_ena
= !!(vsi
->back
->flags
& I40E_FLAG_PTP
);
2512 /* FDIR VSI tx ring can still use RS bit and writebacks */
2513 if (vsi
->type
!= I40E_VSI_FDIR
)
2514 tx_ctx
.head_wb_ena
= 1;
2515 tx_ctx
.head_wb_addr
= ring
->dma
+
2516 (ring
->count
* sizeof(struct i40e_tx_desc
));
2518 /* As part of VSI creation/update, FW allocates certain
2519 * Tx arbitration queue sets for each TC enabled for
2520 * the VSI. The FW returns the handles to these queue
2521 * sets as part of the response buffer to Add VSI,
2522 * Update VSI, etc. AQ commands. It is expected that
2523 * these queue set handles be associated with the Tx
2524 * queues by the driver as part of the TX queue context
2525 * initialization. This has to be done regardless of
2526 * DCB as by default everything is mapped to TC0.
2528 tx_ctx
.rdylist
= le16_to_cpu(vsi
->info
.qs_handle
[ring
->dcb_tc
]);
2529 tx_ctx
.rdylist_act
= 0;
2531 /* clear the context in the HMC */
2532 err
= i40e_clear_lan_tx_queue_context(hw
, pf_q
);
2534 dev_info(&vsi
->back
->pdev
->dev
,
2535 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2536 ring
->queue_index
, pf_q
, err
);
2540 /* set the context in the HMC */
2541 err
= i40e_set_lan_tx_queue_context(hw
, pf_q
, &tx_ctx
);
2543 dev_info(&vsi
->back
->pdev
->dev
,
2544 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
2545 ring
->queue_index
, pf_q
, err
);
2549 /* Now associate this queue with this PCI function */
2550 if (vsi
->type
== I40E_VSI_VMDQ2
) {
2551 qtx_ctl
= I40E_QTX_CTL_VM_QUEUE
;
2552 qtx_ctl
|= ((vsi
->id
) << I40E_QTX_CTL_VFVM_INDX_SHIFT
) &
2553 I40E_QTX_CTL_VFVM_INDX_MASK
;
2555 qtx_ctl
= I40E_QTX_CTL_PF_QUEUE
;
2558 qtx_ctl
|= ((hw
->pf_id
<< I40E_QTX_CTL_PF_INDX_SHIFT
) &
2559 I40E_QTX_CTL_PF_INDX_MASK
);
2560 wr32(hw
, I40E_QTX_CTL(pf_q
), qtx_ctl
);
2563 clear_bit(__I40E_HANG_CHECK_ARMED
, &ring
->state
);
2565 /* cache tail off for easier writes later */
2566 ring
->tail
= hw
->hw_addr
+ I40E_QTX_TAIL(pf_q
);
2572 * i40e_configure_rx_ring - Configure a receive ring context
2573 * @ring: The Rx ring to configure
2575 * Configure the Rx descriptor ring in the HMC context.
2577 static int i40e_configure_rx_ring(struct i40e_ring
*ring
)
2579 struct i40e_vsi
*vsi
= ring
->vsi
;
2580 u32 chain_len
= vsi
->back
->hw
.func_caps
.rx_buf_chain_len
;
2581 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
2582 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2583 struct i40e_hmc_obj_rxq rx_ctx
;
2584 i40e_status err
= 0;
2588 /* clear the context structure first */
2589 memset(&rx_ctx
, 0, sizeof(rx_ctx
));
2591 ring
->rx_buf_len
= vsi
->rx_buf_len
;
2592 ring
->rx_hdr_len
= vsi
->rx_hdr_len
;
2594 rx_ctx
.dbuff
= ring
->rx_buf_len
>> I40E_RXQ_CTX_DBUFF_SHIFT
;
2595 rx_ctx
.hbuff
= ring
->rx_hdr_len
>> I40E_RXQ_CTX_HBUFF_SHIFT
;
2597 rx_ctx
.base
= (ring
->dma
/ 128);
2598 rx_ctx
.qlen
= ring
->count
;
2600 if (vsi
->back
->flags
& I40E_FLAG_16BYTE_RX_DESC_ENABLED
) {
2601 set_ring_16byte_desc_enabled(ring
);
2607 rx_ctx
.dtype
= vsi
->dtype
;
2609 set_ring_ps_enabled(ring
);
2610 rx_ctx
.hsplit_0
= I40E_RX_SPLIT_L2
|
2612 I40E_RX_SPLIT_TCP_UDP
|
2615 rx_ctx
.hsplit_0
= 0;
2618 rx_ctx
.rxmax
= min_t(u16
, vsi
->max_frame
,
2619 (chain_len
* ring
->rx_buf_len
));
2620 if (hw
->revision_id
== 0)
2621 rx_ctx
.lrxqthresh
= 0;
2623 rx_ctx
.lrxqthresh
= 2;
2624 rx_ctx
.crcstrip
= 1;
2628 rx_ctx
.fc_ena
= (vsi
->type
== I40E_VSI_FCOE
);
2630 /* set the prefena field to 1 because the manual says to */
2633 /* clear the context in the HMC */
2634 err
= i40e_clear_lan_rx_queue_context(hw
, pf_q
);
2636 dev_info(&vsi
->back
->pdev
->dev
,
2637 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2638 ring
->queue_index
, pf_q
, err
);
2642 /* set the context in the HMC */
2643 err
= i40e_set_lan_rx_queue_context(hw
, pf_q
, &rx_ctx
);
2645 dev_info(&vsi
->back
->pdev
->dev
,
2646 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2647 ring
->queue_index
, pf_q
, err
);
2651 /* cache tail for quicker writes, and clear the reg before use */
2652 ring
->tail
= hw
->hw_addr
+ I40E_QRX_TAIL(pf_q
);
2653 writel(0, ring
->tail
);
2655 if (ring_is_ps_enabled(ring
)) {
2656 i40e_alloc_rx_headers(ring
);
2657 i40e_alloc_rx_buffers_ps(ring
, I40E_DESC_UNUSED(ring
));
2659 i40e_alloc_rx_buffers_1buf(ring
, I40E_DESC_UNUSED(ring
));
2666 * i40e_vsi_configure_tx - Configure the VSI for Tx
2667 * @vsi: VSI structure describing this set of rings and resources
2669 * Configure the Tx VSI for operation.
2671 static int i40e_vsi_configure_tx(struct i40e_vsi
*vsi
)
2676 for (i
= 0; (i
< vsi
->num_queue_pairs
) && !err
; i
++)
2677 err
= i40e_configure_tx_ring(vsi
->tx_rings
[i
]);
2683 * i40e_vsi_configure_rx - Configure the VSI for Rx
2684 * @vsi: the VSI being configured
2686 * Configure the Rx VSI for operation.
2688 static int i40e_vsi_configure_rx(struct i40e_vsi
*vsi
)
2693 if (vsi
->netdev
&& (vsi
->netdev
->mtu
> ETH_DATA_LEN
))
2694 vsi
->max_frame
= vsi
->netdev
->mtu
+ ETH_HLEN
2695 + ETH_FCS_LEN
+ VLAN_HLEN
;
2697 vsi
->max_frame
= I40E_RXBUFFER_2048
;
2699 /* figure out correct receive buffer length */
2700 switch (vsi
->back
->flags
& (I40E_FLAG_RX_1BUF_ENABLED
|
2701 I40E_FLAG_RX_PS_ENABLED
)) {
2702 case I40E_FLAG_RX_1BUF_ENABLED
:
2703 vsi
->rx_hdr_len
= 0;
2704 vsi
->rx_buf_len
= vsi
->max_frame
;
2705 vsi
->dtype
= I40E_RX_DTYPE_NO_SPLIT
;
2707 case I40E_FLAG_RX_PS_ENABLED
:
2708 vsi
->rx_hdr_len
= I40E_RX_HDR_SIZE
;
2709 vsi
->rx_buf_len
= I40E_RXBUFFER_2048
;
2710 vsi
->dtype
= I40E_RX_DTYPE_HEADER_SPLIT
;
2713 vsi
->rx_hdr_len
= I40E_RX_HDR_SIZE
;
2714 vsi
->rx_buf_len
= I40E_RXBUFFER_2048
;
2715 vsi
->dtype
= I40E_RX_DTYPE_SPLIT_ALWAYS
;
2720 /* setup rx buffer for FCoE */
2721 if ((vsi
->type
== I40E_VSI_FCOE
) &&
2722 (vsi
->back
->flags
& I40E_FLAG_FCOE_ENABLED
)) {
2723 vsi
->rx_hdr_len
= 0;
2724 vsi
->rx_buf_len
= I40E_RXBUFFER_3072
;
2725 vsi
->max_frame
= I40E_RXBUFFER_3072
;
2726 vsi
->dtype
= I40E_RX_DTYPE_NO_SPLIT
;
2729 #endif /* I40E_FCOE */
2730 /* round up for the chip's needs */
2731 vsi
->rx_hdr_len
= ALIGN(vsi
->rx_hdr_len
,
2732 BIT_ULL(I40E_RXQ_CTX_HBUFF_SHIFT
));
2733 vsi
->rx_buf_len
= ALIGN(vsi
->rx_buf_len
,
2734 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT
));
2736 /* set up individual rings */
2737 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2738 err
= i40e_configure_rx_ring(vsi
->rx_rings
[i
]);
2744 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
2745 * @vsi: ptr to the VSI
2747 static void i40e_vsi_config_dcb_rings(struct i40e_vsi
*vsi
)
2749 struct i40e_ring
*tx_ring
, *rx_ring
;
2750 u16 qoffset
, qcount
;
2753 if (!(vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
2754 /* Reset the TC information */
2755 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
2756 rx_ring
= vsi
->rx_rings
[i
];
2757 tx_ring
= vsi
->tx_rings
[i
];
2758 rx_ring
->dcb_tc
= 0;
2759 tx_ring
->dcb_tc
= 0;
2763 for (n
= 0; n
< I40E_MAX_TRAFFIC_CLASS
; n
++) {
2764 if (!(vsi
->tc_config
.enabled_tc
& BIT_ULL(n
)))
2767 qoffset
= vsi
->tc_config
.tc_info
[n
].qoffset
;
2768 qcount
= vsi
->tc_config
.tc_info
[n
].qcount
;
2769 for (i
= qoffset
; i
< (qoffset
+ qcount
); i
++) {
2770 rx_ring
= vsi
->rx_rings
[i
];
2771 tx_ring
= vsi
->tx_rings
[i
];
2772 rx_ring
->dcb_tc
= n
;
2773 tx_ring
->dcb_tc
= n
;
2779 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
2780 * @vsi: ptr to the VSI
2782 static void i40e_set_vsi_rx_mode(struct i40e_vsi
*vsi
)
2785 i40e_set_rx_mode(vsi
->netdev
);
2789 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
2790 * @vsi: Pointer to the targeted VSI
2792 * This function replays the hlist on the hw where all the SB Flow Director
2793 * filters were saved.
2795 static void i40e_fdir_filter_restore(struct i40e_vsi
*vsi
)
2797 struct i40e_fdir_filter
*filter
;
2798 struct i40e_pf
*pf
= vsi
->back
;
2799 struct hlist_node
*node
;
2801 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
2804 hlist_for_each_entry_safe(filter
, node
,
2805 &pf
->fdir_filter_list
, fdir_node
) {
2806 i40e_add_del_fdir(vsi
, filter
, true);
2811 * i40e_vsi_configure - Set up the VSI for action
2812 * @vsi: the VSI being configured
2814 static int i40e_vsi_configure(struct i40e_vsi
*vsi
)
2818 i40e_set_vsi_rx_mode(vsi
);
2819 i40e_restore_vlan(vsi
);
2820 i40e_vsi_config_dcb_rings(vsi
);
2821 err
= i40e_vsi_configure_tx(vsi
);
2823 err
= i40e_vsi_configure_rx(vsi
);
2829 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
2830 * @vsi: the VSI being configured
2832 static void i40e_vsi_configure_msix(struct i40e_vsi
*vsi
)
2834 struct i40e_pf
*pf
= vsi
->back
;
2835 struct i40e_q_vector
*q_vector
;
2836 struct i40e_hw
*hw
= &pf
->hw
;
2842 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
2843 * and PFINT_LNKLSTn registers, e.g.:
2844 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
2846 qp
= vsi
->base_queue
;
2847 vector
= vsi
->base_vector
;
2848 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vector
++) {
2849 q_vector
= vsi
->q_vectors
[i
];
2850 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
2851 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
2852 wr32(hw
, I40E_PFINT_ITRN(I40E_RX_ITR
, vector
- 1),
2854 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
2855 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
2856 wr32(hw
, I40E_PFINT_ITRN(I40E_TX_ITR
, vector
- 1),
2859 /* Linked list for the queuepairs assigned to this vector */
2860 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), qp
);
2861 for (q
= 0; q
< q_vector
->num_ringpairs
; q
++) {
2862 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
2863 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
2864 (vector
<< I40E_QINT_RQCTL_MSIX_INDX_SHIFT
) |
2865 (qp
<< I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT
)|
2867 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT
);
2869 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
2871 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
2872 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
2873 (vector
<< I40E_QINT_TQCTL_MSIX_INDX_SHIFT
) |
2874 ((qp
+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
)|
2876 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
2878 /* Terminate the linked list */
2879 if (q
== (q_vector
->num_ringpairs
- 1))
2880 val
|= (I40E_QUEUE_END_OF_LIST
2881 << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
2883 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
2892 * i40e_enable_misc_int_causes - enable the non-queue interrupts
2893 * @hw: ptr to the hardware info
2895 static void i40e_enable_misc_int_causes(struct i40e_pf
*pf
)
2897 struct i40e_hw
*hw
= &pf
->hw
;
2900 /* clear things first */
2901 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0); /* disable all */
2902 rd32(hw
, I40E_PFINT_ICR0
); /* read to clear */
2904 val
= I40E_PFINT_ICR0_ENA_ECC_ERR_MASK
|
2905 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
|
2906 I40E_PFINT_ICR0_ENA_GRST_MASK
|
2907 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK
|
2908 I40E_PFINT_ICR0_ENA_GPIO_MASK
|
2909 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK
|
2910 I40E_PFINT_ICR0_ENA_VFLR_MASK
|
2911 I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
2913 if (pf
->flags
& I40E_FLAG_IWARP_ENABLED
)
2914 val
|= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
;
2916 if (pf
->flags
& I40E_FLAG_PTP
)
2917 val
|= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
2919 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
2921 /* SW_ITR_IDX = 0, but don't change INTENA */
2922 wr32(hw
, I40E_PFINT_DYN_CTL0
, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK
|
2923 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK
);
2925 /* OTHER_ITR_IDX = 0 */
2926 wr32(hw
, I40E_PFINT_STAT_CTL0
, 0);
2930 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
2931 * @vsi: the VSI being configured
2933 static void i40e_configure_msi_and_legacy(struct i40e_vsi
*vsi
)
2935 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[0];
2936 struct i40e_pf
*pf
= vsi
->back
;
2937 struct i40e_hw
*hw
= &pf
->hw
;
2940 /* set the ITR configuration */
2941 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
2942 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
2943 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), q_vector
->rx
.itr
);
2944 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
2945 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
2946 wr32(hw
, I40E_PFINT_ITR0(I40E_TX_ITR
), q_vector
->tx
.itr
);
2948 i40e_enable_misc_int_causes(pf
);
2950 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
2951 wr32(hw
, I40E_PFINT_LNKLST0
, 0);
2953 /* Associate the queue pair to the vector and enable the queue int */
2954 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
2955 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
2956 (I40E_QUEUE_TYPE_TX
<< I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
2958 wr32(hw
, I40E_QINT_RQCTL(0), val
);
2960 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
2961 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
2962 (I40E_QUEUE_END_OF_LIST
<< I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
2964 wr32(hw
, I40E_QINT_TQCTL(0), val
);
2969 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
2970 * @pf: board private structure
2972 void i40e_irq_dynamic_disable_icr0(struct i40e_pf
*pf
)
2974 struct i40e_hw
*hw
= &pf
->hw
;
2976 wr32(hw
, I40E_PFINT_DYN_CTL0
,
2977 I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
);
2982 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
2983 * @pf: board private structure
2985 void i40e_irq_dynamic_enable_icr0(struct i40e_pf
*pf
)
2987 struct i40e_hw
*hw
= &pf
->hw
;
2990 val
= I40E_PFINT_DYN_CTL0_INTENA_MASK
|
2991 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK
|
2992 (I40E_ITR_NONE
<< I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT
);
2994 wr32(hw
, I40E_PFINT_DYN_CTL0
, val
);
2999 * i40e_irq_dynamic_enable - Enable default interrupt generation settings
3000 * @vsi: pointer to a vsi
3001 * @vector: enable a particular Hw Interrupt vector
3003 void i40e_irq_dynamic_enable(struct i40e_vsi
*vsi
, int vector
)
3005 struct i40e_pf
*pf
= vsi
->back
;
3006 struct i40e_hw
*hw
= &pf
->hw
;
3009 val
= I40E_PFINT_DYN_CTLN_INTENA_MASK
|
3010 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK
|
3011 (I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
);
3012 wr32(hw
, I40E_PFINT_DYN_CTLN(vector
- 1), val
);
3013 /* skip the flush */
3017 * i40e_irq_dynamic_disable - Disable default interrupt generation settings
3018 * @vsi: pointer to a vsi
3019 * @vector: disable a particular Hw Interrupt vector
3021 void i40e_irq_dynamic_disable(struct i40e_vsi
*vsi
, int vector
)
3023 struct i40e_pf
*pf
= vsi
->back
;
3024 struct i40e_hw
*hw
= &pf
->hw
;
3027 val
= I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
;
3028 wr32(hw
, I40E_PFINT_DYN_CTLN(vector
- 1), val
);
3033 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
3034 * @irq: interrupt number
3035 * @data: pointer to a q_vector
3037 static irqreturn_t
i40e_msix_clean_rings(int irq
, void *data
)
3039 struct i40e_q_vector
*q_vector
= data
;
3041 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
3044 napi_schedule(&q_vector
->napi
);
3050 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3051 * @vsi: the VSI being configured
3052 * @basename: name for the vector
3054 * Allocates MSI-X vectors and requests interrupts from the kernel.
3056 static int i40e_vsi_request_irq_msix(struct i40e_vsi
*vsi
, char *basename
)
3058 int q_vectors
= vsi
->num_q_vectors
;
3059 struct i40e_pf
*pf
= vsi
->back
;
3060 int base
= vsi
->base_vector
;
3065 for (vector
= 0; vector
< q_vectors
; vector
++) {
3066 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[vector
];
3068 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
3069 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3070 "%s-%s-%d", basename
, "TxRx", rx_int_idx
++);
3072 } else if (q_vector
->rx
.ring
) {
3073 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3074 "%s-%s-%d", basename
, "rx", rx_int_idx
++);
3075 } else if (q_vector
->tx
.ring
) {
3076 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3077 "%s-%s-%d", basename
, "tx", tx_int_idx
++);
3079 /* skip this unused q_vector */
3082 err
= request_irq(pf
->msix_entries
[base
+ vector
].vector
,
3088 dev_info(&pf
->pdev
->dev
,
3089 "%s: request_irq failed, error: %d\n",
3091 goto free_queue_irqs
;
3093 /* assign the mask for this irq */
3094 irq_set_affinity_hint(pf
->msix_entries
[base
+ vector
].vector
,
3095 &q_vector
->affinity_mask
);
3098 vsi
->irqs_ready
= true;
3104 irq_set_affinity_hint(pf
->msix_entries
[base
+ vector
].vector
,
3106 free_irq(pf
->msix_entries
[base
+ vector
].vector
,
3107 &(vsi
->q_vectors
[vector
]));
3113 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3114 * @vsi: the VSI being un-configured
3116 static void i40e_vsi_disable_irq(struct i40e_vsi
*vsi
)
3118 struct i40e_pf
*pf
= vsi
->back
;
3119 struct i40e_hw
*hw
= &pf
->hw
;
3120 int base
= vsi
->base_vector
;
3123 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
3124 wr32(hw
, I40E_QINT_TQCTL(vsi
->tx_rings
[i
]->reg_idx
), 0);
3125 wr32(hw
, I40E_QINT_RQCTL(vsi
->rx_rings
[i
]->reg_idx
), 0);
3128 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3129 for (i
= vsi
->base_vector
;
3130 i
< (vsi
->num_q_vectors
+ vsi
->base_vector
); i
++)
3131 wr32(hw
, I40E_PFINT_DYN_CTLN(i
- 1), 0);
3134 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3135 synchronize_irq(pf
->msix_entries
[i
+ base
].vector
);
3137 /* Legacy and MSI mode - this stops all interrupt handling */
3138 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0);
3139 wr32(hw
, I40E_PFINT_DYN_CTL0
, 0);
3141 synchronize_irq(pf
->pdev
->irq
);
3146 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3147 * @vsi: the VSI being configured
3149 static int i40e_vsi_enable_irq(struct i40e_vsi
*vsi
)
3151 struct i40e_pf
*pf
= vsi
->back
;
3154 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3155 for (i
= vsi
->base_vector
;
3156 i
< (vsi
->num_q_vectors
+ vsi
->base_vector
); i
++)
3157 i40e_irq_dynamic_enable(vsi
, i
);
3159 i40e_irq_dynamic_enable_icr0(pf
);
3162 i40e_flush(&pf
->hw
);
3167 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
3168 * @pf: board private structure
3170 static void i40e_stop_misc_vector(struct i40e_pf
*pf
)
3173 wr32(&pf
->hw
, I40E_PFINT_ICR0_ENA
, 0);
3174 i40e_flush(&pf
->hw
);
3178 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3179 * @irq: interrupt number
3180 * @data: pointer to a q_vector
3182 * This is the handler used for all MSI/Legacy interrupts, and deals
3183 * with both queue and non-queue interrupts. This is also used in
3184 * MSIX mode to handle the non-queue interrupts.
3186 static irqreturn_t
i40e_intr(int irq
, void *data
)
3188 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
3189 struct i40e_hw
*hw
= &pf
->hw
;
3190 irqreturn_t ret
= IRQ_NONE
;
3191 u32 icr0
, icr0_remaining
;
3194 icr0
= rd32(hw
, I40E_PFINT_ICR0
);
3195 ena_mask
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
3197 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
3198 if ((icr0
& I40E_PFINT_ICR0_INTEVENT_MASK
) == 0)
3201 /* if interrupt but no bits showing, must be SWINT */
3202 if (((icr0
& ~I40E_PFINT_ICR0_INTEVENT_MASK
) == 0) ||
3203 (icr0
& I40E_PFINT_ICR0_SWINT_MASK
))
3206 if ((pf
->flags
& I40E_FLAG_IWARP_ENABLED
) &&
3207 (ena_mask
& I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
)) {
3208 ena_mask
&= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
;
3209 icr0
&= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK
;
3210 dev_info(&pf
->pdev
->dev
, "cleared PE_CRITERR\n");
3213 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
3214 if (icr0
& I40E_PFINT_ICR0_QUEUE_0_MASK
) {
3216 /* temporarily disable queue cause for NAPI processing */
3217 u32 qval
= rd32(hw
, I40E_QINT_RQCTL(0));
3218 qval
&= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK
;
3219 wr32(hw
, I40E_QINT_RQCTL(0), qval
);
3221 qval
= rd32(hw
, I40E_QINT_TQCTL(0));
3222 qval
&= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK
;
3223 wr32(hw
, I40E_QINT_TQCTL(0), qval
);
3225 if (!test_bit(__I40E_DOWN
, &pf
->state
))
3226 napi_schedule(&pf
->vsi
[pf
->lan_vsi
]->q_vectors
[0]->napi
);
3229 if (icr0
& I40E_PFINT_ICR0_ADMINQ_MASK
) {
3230 ena_mask
&= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
3231 set_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
);
3234 if (icr0
& I40E_PFINT_ICR0_MAL_DETECT_MASK
) {
3235 ena_mask
&= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
3236 set_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
);
3239 if (icr0
& I40E_PFINT_ICR0_VFLR_MASK
) {
3240 ena_mask
&= ~I40E_PFINT_ICR0_ENA_VFLR_MASK
;
3241 set_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
);
3244 if (icr0
& I40E_PFINT_ICR0_GRST_MASK
) {
3245 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
))
3246 set_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
);
3247 ena_mask
&= ~I40E_PFINT_ICR0_ENA_GRST_MASK
;
3248 val
= rd32(hw
, I40E_GLGEN_RSTAT
);
3249 val
= (val
& I40E_GLGEN_RSTAT_RESET_TYPE_MASK
)
3250 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT
;
3251 if (val
== I40E_RESET_CORER
) {
3253 } else if (val
== I40E_RESET_GLOBR
) {
3255 } else if (val
== I40E_RESET_EMPR
) {
3257 set_bit(__I40E_EMP_RESET_INTR_RECEIVED
, &pf
->state
);
3261 if (icr0
& I40E_PFINT_ICR0_HMC_ERR_MASK
) {
3262 icr0
&= ~I40E_PFINT_ICR0_HMC_ERR_MASK
;
3263 dev_info(&pf
->pdev
->dev
, "HMC error interrupt\n");
3264 dev_info(&pf
->pdev
->dev
, "HMC error info 0x%x, HMC error data 0x%x\n",
3265 rd32(hw
, I40E_PFHMC_ERRORINFO
),
3266 rd32(hw
, I40E_PFHMC_ERRORDATA
));
3269 if (icr0
& I40E_PFINT_ICR0_TIMESYNC_MASK
) {
3270 u32 prttsyn_stat
= rd32(hw
, I40E_PRTTSYN_STAT_0
);
3272 if (prttsyn_stat
& I40E_PRTTSYN_STAT_0_TXTIME_MASK
) {
3273 icr0
&= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
3274 i40e_ptp_tx_hwtstamp(pf
);
3278 /* If a critical error is pending we have no choice but to reset the
3280 * Report and mask out any remaining unexpected interrupts.
3282 icr0_remaining
= icr0
& ena_mask
;
3283 if (icr0_remaining
) {
3284 dev_info(&pf
->pdev
->dev
, "unhandled interrupt icr0=0x%08x\n",
3286 if ((icr0_remaining
& I40E_PFINT_ICR0_PE_CRITERR_MASK
) ||
3287 (icr0_remaining
& I40E_PFINT_ICR0_PCI_EXCEPTION_MASK
) ||
3288 (icr0_remaining
& I40E_PFINT_ICR0_ECC_ERR_MASK
)) {
3289 dev_info(&pf
->pdev
->dev
, "device will be reset\n");
3290 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
3291 i40e_service_event_schedule(pf
);
3293 ena_mask
&= ~icr0_remaining
;
3298 /* re-enable interrupt causes */
3299 wr32(hw
, I40E_PFINT_ICR0_ENA
, ena_mask
);
3300 if (!test_bit(__I40E_DOWN
, &pf
->state
)) {
3301 i40e_service_event_schedule(pf
);
3302 i40e_irq_dynamic_enable_icr0(pf
);
3309 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3310 * @tx_ring: tx ring to clean
3311 * @budget: how many cleans we're allowed
3313 * Returns true if there's any budget left (e.g. the clean is finished)
3315 static bool i40e_clean_fdir_tx_irq(struct i40e_ring
*tx_ring
, int budget
)
3317 struct i40e_vsi
*vsi
= tx_ring
->vsi
;
3318 u16 i
= tx_ring
->next_to_clean
;
3319 struct i40e_tx_buffer
*tx_buf
;
3320 struct i40e_tx_desc
*tx_desc
;
3322 tx_buf
= &tx_ring
->tx_bi
[i
];
3323 tx_desc
= I40E_TX_DESC(tx_ring
, i
);
3324 i
-= tx_ring
->count
;
3327 struct i40e_tx_desc
*eop_desc
= tx_buf
->next_to_watch
;
3329 /* if next_to_watch is not set then there is no work pending */
3333 /* prevent any other reads prior to eop_desc */
3334 read_barrier_depends();
3336 /* if the descriptor isn't done, no work yet to do */
3337 if (!(eop_desc
->cmd_type_offset_bsz
&
3338 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE
)))
3341 /* clear next_to_watch to prevent false hangs */
3342 tx_buf
->next_to_watch
= NULL
;
3344 tx_desc
->buffer_addr
= 0;
3345 tx_desc
->cmd_type_offset_bsz
= 0;
3346 /* move past filter desc */
3351 i
-= tx_ring
->count
;
3352 tx_buf
= tx_ring
->tx_bi
;
3353 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
3355 /* unmap skb header data */
3356 dma_unmap_single(tx_ring
->dev
,
3357 dma_unmap_addr(tx_buf
, dma
),
3358 dma_unmap_len(tx_buf
, len
),
3360 if (tx_buf
->tx_flags
& I40E_TX_FLAGS_FD_SB
)
3361 kfree(tx_buf
->raw_buf
);
3363 tx_buf
->raw_buf
= NULL
;
3364 tx_buf
->tx_flags
= 0;
3365 tx_buf
->next_to_watch
= NULL
;
3366 dma_unmap_len_set(tx_buf
, len
, 0);
3367 tx_desc
->buffer_addr
= 0;
3368 tx_desc
->cmd_type_offset_bsz
= 0;
3370 /* move us past the eop_desc for start of next FD desc */
3375 i
-= tx_ring
->count
;
3376 tx_buf
= tx_ring
->tx_bi
;
3377 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
3380 /* update budget accounting */
3382 } while (likely(budget
));
3384 i
+= tx_ring
->count
;
3385 tx_ring
->next_to_clean
= i
;
3387 if (vsi
->back
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3388 i40e_irq_dynamic_enable(vsi
,
3389 tx_ring
->q_vector
->v_idx
+ vsi
->base_vector
);
3395 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
3396 * @irq: interrupt number
3397 * @data: pointer to a q_vector
3399 static irqreturn_t
i40e_fdir_clean_ring(int irq
, void *data
)
3401 struct i40e_q_vector
*q_vector
= data
;
3402 struct i40e_vsi
*vsi
;
3404 if (!q_vector
->tx
.ring
)
3407 vsi
= q_vector
->tx
.ring
->vsi
;
3408 i40e_clean_fdir_tx_irq(q_vector
->tx
.ring
, vsi
->work_limit
);
3414 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
3415 * @vsi: the VSI being configured
3416 * @v_idx: vector index
3417 * @qp_idx: queue pair index
3419 static void map_vector_to_qp(struct i40e_vsi
*vsi
, int v_idx
, int qp_idx
)
3421 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
3422 struct i40e_ring
*tx_ring
= vsi
->tx_rings
[qp_idx
];
3423 struct i40e_ring
*rx_ring
= vsi
->rx_rings
[qp_idx
];
3425 tx_ring
->q_vector
= q_vector
;
3426 tx_ring
->next
= q_vector
->tx
.ring
;
3427 q_vector
->tx
.ring
= tx_ring
;
3428 q_vector
->tx
.count
++;
3430 rx_ring
->q_vector
= q_vector
;
3431 rx_ring
->next
= q_vector
->rx
.ring
;
3432 q_vector
->rx
.ring
= rx_ring
;
3433 q_vector
->rx
.count
++;
3437 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
3438 * @vsi: the VSI being configured
3440 * This function maps descriptor rings to the queue-specific vectors
3441 * we were allotted through the MSI-X enabling code. Ideally, we'd have
3442 * one vector per queue pair, but on a constrained vector budget, we
3443 * group the queue pairs as "efficiently" as possible.
3445 static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi
*vsi
)
3447 int qp_remaining
= vsi
->num_queue_pairs
;
3448 int q_vectors
= vsi
->num_q_vectors
;
3453 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
3454 * group them so there are multiple queues per vector.
3455 * It is also important to go through all the vectors available to be
3456 * sure that if we don't use all the vectors, that the remaining vectors
3457 * are cleared. This is especially important when decreasing the
3458 * number of queues in use.
3460 for (; v_start
< q_vectors
; v_start
++) {
3461 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_start
];
3463 num_ringpairs
= DIV_ROUND_UP(qp_remaining
, q_vectors
- v_start
);
3465 q_vector
->num_ringpairs
= num_ringpairs
;
3467 q_vector
->rx
.count
= 0;
3468 q_vector
->tx
.count
= 0;
3469 q_vector
->rx
.ring
= NULL
;
3470 q_vector
->tx
.ring
= NULL
;
3472 while (num_ringpairs
--) {
3473 map_vector_to_qp(vsi
, v_start
, qp_idx
);
3481 * i40e_vsi_request_irq - Request IRQ from the OS
3482 * @vsi: the VSI being configured
3483 * @basename: name for the vector
3485 static int i40e_vsi_request_irq(struct i40e_vsi
*vsi
, char *basename
)
3487 struct i40e_pf
*pf
= vsi
->back
;
3490 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
3491 err
= i40e_vsi_request_irq_msix(vsi
, basename
);
3492 else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
)
3493 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, 0,
3496 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, IRQF_SHARED
,
3500 dev_info(&pf
->pdev
->dev
, "request_irq failed, Error %d\n", err
);
3505 #ifdef CONFIG_NET_POLL_CONTROLLER
3507 * i40e_netpoll - A Polling 'interrupt'handler
3508 * @netdev: network interface device structure
3510 * This is used by netconsole to send skbs without having to re-enable
3511 * interrupts. It's not called while the normal interrupt routine is executing.
3514 void i40e_netpoll(struct net_device
*netdev
)
3516 static void i40e_netpoll(struct net_device
*netdev
)
3519 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3520 struct i40e_vsi
*vsi
= np
->vsi
;
3521 struct i40e_pf
*pf
= vsi
->back
;
3524 /* if interface is down do nothing */
3525 if (test_bit(__I40E_DOWN
, &vsi
->state
))
3528 pf
->flags
|= I40E_FLAG_IN_NETPOLL
;
3529 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3530 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3531 i40e_msix_clean_rings(0, vsi
->q_vectors
[i
]);
3533 i40e_intr(pf
->pdev
->irq
, netdev
);
3535 pf
->flags
&= ~I40E_FLAG_IN_NETPOLL
;
3540 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
3541 * @pf: the PF being configured
3542 * @pf_q: the PF queue
3543 * @enable: enable or disable state of the queue
3545 * This routine will wait for the given Tx queue of the PF to reach the
3546 * enabled or disabled state.
3547 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3548 * multiple retries; else will return 0 in case of success.
3550 static int i40e_pf_txq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
3555 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
3556 tx_reg
= rd32(&pf
->hw
, I40E_QTX_ENA(pf_q
));
3557 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
3560 usleep_range(10, 20);
3562 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
3569 * i40e_vsi_control_tx - Start or stop a VSI's rings
3570 * @vsi: the VSI being configured
3571 * @enable: start or stop the rings
3573 static int i40e_vsi_control_tx(struct i40e_vsi
*vsi
, bool enable
)
3575 struct i40e_pf
*pf
= vsi
->back
;
3576 struct i40e_hw
*hw
= &pf
->hw
;
3577 int i
, j
, pf_q
, ret
= 0;
3580 pf_q
= vsi
->base_queue
;
3581 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
3583 /* warn the TX unit of coming changes */
3584 i40e_pre_tx_queue_cfg(&pf
->hw
, pf_q
, enable
);
3586 usleep_range(10, 20);
3588 for (j
= 0; j
< 50; j
++) {
3589 tx_reg
= rd32(hw
, I40E_QTX_ENA(pf_q
));
3590 if (((tx_reg
>> I40E_QTX_ENA_QENA_REQ_SHIFT
) & 1) ==
3591 ((tx_reg
>> I40E_QTX_ENA_QENA_STAT_SHIFT
) & 1))
3593 usleep_range(1000, 2000);
3595 /* Skip if the queue is already in the requested state */
3596 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
3599 /* turn on/off the queue */
3601 wr32(hw
, I40E_QTX_HEAD(pf_q
), 0);
3602 tx_reg
|= I40E_QTX_ENA_QENA_REQ_MASK
;
3604 tx_reg
&= ~I40E_QTX_ENA_QENA_REQ_MASK
;
3607 wr32(hw
, I40E_QTX_ENA(pf_q
), tx_reg
);
3608 /* No waiting for the Tx queue to disable */
3609 if (!enable
&& test_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
))
3612 /* wait for the change to finish */
3613 ret
= i40e_pf_txq_wait(pf
, pf_q
, enable
);
3615 dev_info(&pf
->pdev
->dev
,
3616 "%s: VSI seid %d Tx ring %d %sable timeout\n",
3617 __func__
, vsi
->seid
, pf_q
,
3618 (enable
? "en" : "dis"));
3623 if (hw
->revision_id
== 0)
3629 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
3630 * @pf: the PF being configured
3631 * @pf_q: the PF queue
3632 * @enable: enable or disable state of the queue
3634 * This routine will wait for the given Rx queue of the PF to reach the
3635 * enabled or disabled state.
3636 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3637 * multiple retries; else will return 0 in case of success.
3639 static int i40e_pf_rxq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
3644 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
3645 rx_reg
= rd32(&pf
->hw
, I40E_QRX_ENA(pf_q
));
3646 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
3649 usleep_range(10, 20);
3651 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
3658 * i40e_vsi_control_rx - Start or stop a VSI's rings
3659 * @vsi: the VSI being configured
3660 * @enable: start or stop the rings
3662 static int i40e_vsi_control_rx(struct i40e_vsi
*vsi
, bool enable
)
3664 struct i40e_pf
*pf
= vsi
->back
;
3665 struct i40e_hw
*hw
= &pf
->hw
;
3666 int i
, j
, pf_q
, ret
= 0;
3669 pf_q
= vsi
->base_queue
;
3670 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
3671 for (j
= 0; j
< 50; j
++) {
3672 rx_reg
= rd32(hw
, I40E_QRX_ENA(pf_q
));
3673 if (((rx_reg
>> I40E_QRX_ENA_QENA_REQ_SHIFT
) & 1) ==
3674 ((rx_reg
>> I40E_QRX_ENA_QENA_STAT_SHIFT
) & 1))
3676 usleep_range(1000, 2000);
3679 /* Skip if the queue is already in the requested state */
3680 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
3683 /* turn on/off the queue */
3685 rx_reg
|= I40E_QRX_ENA_QENA_REQ_MASK
;
3687 rx_reg
&= ~I40E_QRX_ENA_QENA_REQ_MASK
;
3688 wr32(hw
, I40E_QRX_ENA(pf_q
), rx_reg
);
3690 /* wait for the change to finish */
3691 ret
= i40e_pf_rxq_wait(pf
, pf_q
, enable
);
3693 dev_info(&pf
->pdev
->dev
,
3694 "%s: VSI seid %d Rx ring %d %sable timeout\n",
3695 __func__
, vsi
->seid
, pf_q
,
3696 (enable
? "en" : "dis"));
3705 * i40e_vsi_control_rings - Start or stop a VSI's rings
3706 * @vsi: the VSI being configured
3707 * @enable: start or stop the rings
3709 int i40e_vsi_control_rings(struct i40e_vsi
*vsi
, bool request
)
3713 /* do rx first for enable and last for disable */
3715 ret
= i40e_vsi_control_rx(vsi
, request
);
3718 ret
= i40e_vsi_control_tx(vsi
, request
);
3720 /* Ignore return value, we need to shutdown whatever we can */
3721 i40e_vsi_control_tx(vsi
, request
);
3722 i40e_vsi_control_rx(vsi
, request
);
3729 * i40e_vsi_free_irq - Free the irq association with the OS
3730 * @vsi: the VSI being configured
3732 static void i40e_vsi_free_irq(struct i40e_vsi
*vsi
)
3734 struct i40e_pf
*pf
= vsi
->back
;
3735 struct i40e_hw
*hw
= &pf
->hw
;
3736 int base
= vsi
->base_vector
;
3740 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3741 if (!vsi
->q_vectors
)
3744 if (!vsi
->irqs_ready
)
3747 vsi
->irqs_ready
= false;
3748 for (i
= 0; i
< vsi
->num_q_vectors
; i
++) {
3749 u16 vector
= i
+ base
;
3751 /* free only the irqs that were actually requested */
3752 if (!vsi
->q_vectors
[i
] ||
3753 !vsi
->q_vectors
[i
]->num_ringpairs
)
3756 /* clear the affinity_mask in the IRQ descriptor */
3757 irq_set_affinity_hint(pf
->msix_entries
[vector
].vector
,
3759 free_irq(pf
->msix_entries
[vector
].vector
,
3762 /* Tear down the interrupt queue link list
3764 * We know that they come in pairs and always
3765 * the Rx first, then the Tx. To clear the
3766 * link list, stick the EOL value into the
3767 * next_q field of the registers.
3769 val
= rd32(hw
, I40E_PFINT_LNKLSTN(vector
- 1));
3770 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
3771 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
3772 val
|= I40E_QUEUE_END_OF_LIST
3773 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
3774 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), val
);
3776 while (qp
!= I40E_QUEUE_END_OF_LIST
) {
3779 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
3781 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
3782 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
3783 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3784 I40E_QINT_RQCTL_INTEVENT_MASK
);
3786 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
3787 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
3789 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
3791 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
3793 next
= (val
& I40E_QINT_TQCTL_NEXTQ_INDX_MASK
)
3794 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
;
3796 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
3797 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
3798 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3799 I40E_QINT_TQCTL_INTEVENT_MASK
);
3801 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
3802 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
3804 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
3809 free_irq(pf
->pdev
->irq
, pf
);
3811 val
= rd32(hw
, I40E_PFINT_LNKLST0
);
3812 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
3813 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
3814 val
|= I40E_QUEUE_END_OF_LIST
3815 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT
;
3816 wr32(hw
, I40E_PFINT_LNKLST0
, val
);
3818 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
3819 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
3820 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
3821 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3822 I40E_QINT_RQCTL_INTEVENT_MASK
);
3824 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
3825 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
3827 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
3829 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
3831 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
3832 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
3833 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3834 I40E_QINT_TQCTL_INTEVENT_MASK
);
3836 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
3837 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
3839 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
3844 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
3845 * @vsi: the VSI being configured
3846 * @v_idx: Index of vector to be freed
3848 * This function frees the memory allocated to the q_vector. In addition if
3849 * NAPI is enabled it will delete any references to the NAPI struct prior
3850 * to freeing the q_vector.
3852 static void i40e_free_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
3854 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
3855 struct i40e_ring
*ring
;
3860 /* disassociate q_vector from rings */
3861 i40e_for_each_ring(ring
, q_vector
->tx
)
3862 ring
->q_vector
= NULL
;
3864 i40e_for_each_ring(ring
, q_vector
->rx
)
3865 ring
->q_vector
= NULL
;
3867 /* only VSI w/ an associated netdev is set up w/ NAPI */
3869 netif_napi_del(&q_vector
->napi
);
3871 vsi
->q_vectors
[v_idx
] = NULL
;
3873 kfree_rcu(q_vector
, rcu
);
3877 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
3878 * @vsi: the VSI being un-configured
3880 * This frees the memory allocated to the q_vectors and
3881 * deletes references to the NAPI struct.
3883 static void i40e_vsi_free_q_vectors(struct i40e_vsi
*vsi
)
3887 for (v_idx
= 0; v_idx
< vsi
->num_q_vectors
; v_idx
++)
3888 i40e_free_q_vector(vsi
, v_idx
);
3892 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
3893 * @pf: board private structure
3895 static void i40e_reset_interrupt_capability(struct i40e_pf
*pf
)
3897 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
3898 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3899 pci_disable_msix(pf
->pdev
);
3900 kfree(pf
->msix_entries
);
3901 pf
->msix_entries
= NULL
;
3902 kfree(pf
->irq_pile
);
3903 pf
->irq_pile
= NULL
;
3904 } else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
) {
3905 pci_disable_msi(pf
->pdev
);
3907 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
);
3911 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
3912 * @pf: board private structure
3914 * We go through and clear interrupt specific resources and reset the structure
3915 * to pre-load conditions
3917 static void i40e_clear_interrupt_scheme(struct i40e_pf
*pf
)
3921 i40e_stop_misc_vector(pf
);
3922 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3923 synchronize_irq(pf
->msix_entries
[0].vector
);
3924 free_irq(pf
->msix_entries
[0].vector
, pf
);
3927 i40e_put_lump(pf
->irq_pile
, 0, I40E_PILE_VALID_BIT
-1);
3928 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
3930 i40e_vsi_free_q_vectors(pf
->vsi
[i
]);
3931 i40e_reset_interrupt_capability(pf
);
3935 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
3936 * @vsi: the VSI being configured
3938 static void i40e_napi_enable_all(struct i40e_vsi
*vsi
)
3945 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++)
3946 napi_enable(&vsi
->q_vectors
[q_idx
]->napi
);
3950 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
3951 * @vsi: the VSI being configured
3953 static void i40e_napi_disable_all(struct i40e_vsi
*vsi
)
3960 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++)
3961 napi_disable(&vsi
->q_vectors
[q_idx
]->napi
);
3965 * i40e_vsi_close - Shut down a VSI
3966 * @vsi: the vsi to be quelled
3968 static void i40e_vsi_close(struct i40e_vsi
*vsi
)
3970 if (!test_and_set_bit(__I40E_DOWN
, &vsi
->state
))
3972 i40e_vsi_free_irq(vsi
);
3973 i40e_vsi_free_tx_resources(vsi
);
3974 i40e_vsi_free_rx_resources(vsi
);
3978 * i40e_quiesce_vsi - Pause a given VSI
3979 * @vsi: the VSI being paused
3981 static void i40e_quiesce_vsi(struct i40e_vsi
*vsi
)
3983 if (test_bit(__I40E_DOWN
, &vsi
->state
))
3986 /* No need to disable FCoE VSI when Tx suspended */
3987 if ((test_bit(__I40E_PORT_TX_SUSPENDED
, &vsi
->back
->state
)) &&
3988 vsi
->type
== I40E_VSI_FCOE
) {
3989 dev_dbg(&vsi
->back
->pdev
->dev
,
3990 "%s: VSI seid %d skipping FCoE VSI disable\n",
3991 __func__
, vsi
->seid
);
3995 set_bit(__I40E_NEEDS_RESTART
, &vsi
->state
);
3996 if (vsi
->netdev
&& netif_running(vsi
->netdev
)) {
3997 vsi
->netdev
->netdev_ops
->ndo_stop(vsi
->netdev
);
3999 i40e_vsi_close(vsi
);
4004 * i40e_unquiesce_vsi - Resume a given VSI
4005 * @vsi: the VSI being resumed
4007 static void i40e_unquiesce_vsi(struct i40e_vsi
*vsi
)
4009 if (!test_bit(__I40E_NEEDS_RESTART
, &vsi
->state
))
4012 clear_bit(__I40E_NEEDS_RESTART
, &vsi
->state
);
4013 if (vsi
->netdev
&& netif_running(vsi
->netdev
))
4014 vsi
->netdev
->netdev_ops
->ndo_open(vsi
->netdev
);
4016 i40e_vsi_open(vsi
); /* this clears the DOWN bit */
4020 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
4023 static void i40e_pf_quiesce_all_vsi(struct i40e_pf
*pf
)
4027 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4029 i40e_quiesce_vsi(pf
->vsi
[v
]);
4034 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
4037 static void i40e_pf_unquiesce_all_vsi(struct i40e_pf
*pf
)
4041 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4043 i40e_unquiesce_vsi(pf
->vsi
[v
]);
4047 #ifdef CONFIG_I40E_DCB
4049 * i40e_vsi_wait_txq_disabled - Wait for VSI's queues to be disabled
4050 * @vsi: the VSI being configured
4052 * This function waits for the given VSI's Tx queues to be disabled.
4054 static int i40e_vsi_wait_txq_disabled(struct i40e_vsi
*vsi
)
4056 struct i40e_pf
*pf
= vsi
->back
;
4059 pf_q
= vsi
->base_queue
;
4060 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
4061 /* Check and wait for the disable status of the queue */
4062 ret
= i40e_pf_txq_wait(pf
, pf_q
, false);
4064 dev_info(&pf
->pdev
->dev
,
4065 "%s: VSI seid %d Tx ring %d disable timeout\n",
4066 __func__
, vsi
->seid
, pf_q
);
4075 * i40e_pf_wait_txq_disabled - Wait for all queues of PF VSIs to be disabled
4078 * This function waits for the Tx queues to be in disabled state for all the
4079 * VSIs that are managed by this PF.
4081 static int i40e_pf_wait_txq_disabled(struct i40e_pf
*pf
)
4085 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
; v
++) {
4086 /* No need to wait for FCoE VSI queues */
4087 if (pf
->vsi
[v
] && pf
->vsi
[v
]->type
!= I40E_VSI_FCOE
) {
4088 ret
= i40e_vsi_wait_txq_disabled(pf
->vsi
[v
]);
4099 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
4100 * @pf: pointer to PF
4102 * Get TC map for ISCSI PF type that will include iSCSI TC
4105 static u8
i40e_get_iscsi_tc_map(struct i40e_pf
*pf
)
4107 struct i40e_dcb_app_priority_table app
;
4108 struct i40e_hw
*hw
= &pf
->hw
;
4109 u8 enabled_tc
= 1; /* TC0 is always enabled */
4111 /* Get the iSCSI APP TLV */
4112 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4114 for (i
= 0; i
< dcbcfg
->numapps
; i
++) {
4115 app
= dcbcfg
->app
[i
];
4116 if (app
.selector
== I40E_APP_SEL_TCPIP
&&
4117 app
.protocolid
== I40E_APP_PROTOID_ISCSI
) {
4118 tc
= dcbcfg
->etscfg
.prioritytable
[app
.priority
];
4119 enabled_tc
|= BIT_ULL(tc
);
4128 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
4129 * @dcbcfg: the corresponding DCBx configuration structure
4131 * Return the number of TCs from given DCBx configuration
4133 static u8
i40e_dcb_get_num_tc(struct i40e_dcbx_config
*dcbcfg
)
4138 /* Scan the ETS Config Priority Table to find
4139 * traffic class enabled for a given priority
4140 * and use the traffic class index to get the
4141 * number of traffic classes enabled
4143 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
4144 if (dcbcfg
->etscfg
.prioritytable
[i
] > num_tc
)
4145 num_tc
= dcbcfg
->etscfg
.prioritytable
[i
];
4148 /* Traffic class index starts from zero so
4149 * increment to return the actual count
4155 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
4156 * @dcbcfg: the corresponding DCBx configuration structure
4158 * Query the current DCB configuration and return the number of
4159 * traffic classes enabled from the given DCBX config
4161 static u8
i40e_dcb_get_enabled_tc(struct i40e_dcbx_config
*dcbcfg
)
4163 u8 num_tc
= i40e_dcb_get_num_tc(dcbcfg
);
4167 for (i
= 0; i
< num_tc
; i
++)
4168 enabled_tc
|= BIT(i
);
4174 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
4175 * @pf: PF being queried
4177 * Return number of traffic classes enabled for the given PF
4179 static u8
i40e_pf_get_num_tc(struct i40e_pf
*pf
)
4181 struct i40e_hw
*hw
= &pf
->hw
;
4184 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4186 /* If DCB is not enabled then always in single TC */
4187 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
4190 /* SFP mode will be enabled for all TCs on port */
4191 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
4192 return i40e_dcb_get_num_tc(dcbcfg
);
4194 /* MFP mode return count of enabled TCs for this PF */
4195 if (pf
->hw
.func_caps
.iscsi
)
4196 enabled_tc
= i40e_get_iscsi_tc_map(pf
);
4198 return 1; /* Only TC0 */
4200 /* At least have TC0 */
4201 enabled_tc
= (enabled_tc
? enabled_tc
: 0x1);
4202 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4203 if (enabled_tc
& BIT_ULL(i
))
4210 * i40e_pf_get_default_tc - Get bitmap for first enabled TC
4211 * @pf: PF being queried
4213 * Return a bitmap for first enabled traffic class for this PF.
4215 static u8
i40e_pf_get_default_tc(struct i40e_pf
*pf
)
4217 u8 enabled_tc
= pf
->hw
.func_caps
.enabled_tcmap
;
4221 return 0x1; /* TC0 */
4223 /* Find the first enabled TC */
4224 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4225 if (enabled_tc
& BIT_ULL(i
))
4233 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
4234 * @pf: PF being queried
4236 * Return a bitmap for enabled traffic classes for this PF.
4238 static u8
i40e_pf_get_tc_map(struct i40e_pf
*pf
)
4240 /* If DCB is not enabled for this PF then just return default TC */
4241 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
4242 return i40e_pf_get_default_tc(pf
);
4244 /* SFP mode we want PF to be enabled for all TCs */
4245 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
4246 return i40e_dcb_get_enabled_tc(&pf
->hw
.local_dcbx_config
);
4248 /* MFP enabled and iSCSI PF type */
4249 if (pf
->hw
.func_caps
.iscsi
)
4250 return i40e_get_iscsi_tc_map(pf
);
4252 return i40e_pf_get_default_tc(pf
);
4256 * i40e_vsi_get_bw_info - Query VSI BW Information
4257 * @vsi: the VSI being queried
4259 * Returns 0 on success, negative value on failure
4261 static int i40e_vsi_get_bw_info(struct i40e_vsi
*vsi
)
4263 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config
= {0};
4264 struct i40e_aqc_query_vsi_bw_config_resp bw_config
= {0};
4265 struct i40e_pf
*pf
= vsi
->back
;
4266 struct i40e_hw
*hw
= &pf
->hw
;
4271 /* Get the VSI level BW configuration */
4272 ret
= i40e_aq_query_vsi_bw_config(hw
, vsi
->seid
, &bw_config
, NULL
);
4274 dev_info(&pf
->pdev
->dev
,
4275 "couldn't get PF vsi bw config, err %s aq_err %s\n",
4276 i40e_stat_str(&pf
->hw
, ret
),
4277 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4281 /* Get the VSI level BW configuration per TC */
4282 ret
= i40e_aq_query_vsi_ets_sla_config(hw
, vsi
->seid
, &bw_ets_config
,
4285 dev_info(&pf
->pdev
->dev
,
4286 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
4287 i40e_stat_str(&pf
->hw
, ret
),
4288 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4292 if (bw_config
.tc_valid_bits
!= bw_ets_config
.tc_valid_bits
) {
4293 dev_info(&pf
->pdev
->dev
,
4294 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
4295 bw_config
.tc_valid_bits
,
4296 bw_ets_config
.tc_valid_bits
);
4297 /* Still continuing */
4300 vsi
->bw_limit
= le16_to_cpu(bw_config
.port_bw_limit
);
4301 vsi
->bw_max_quanta
= bw_config
.max_bw
;
4302 tc_bw_max
= le16_to_cpu(bw_ets_config
.tc_bw_max
[0]) |
4303 (le16_to_cpu(bw_ets_config
.tc_bw_max
[1]) << 16);
4304 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4305 vsi
->bw_ets_share_credits
[i
] = bw_ets_config
.share_credits
[i
];
4306 vsi
->bw_ets_limit_credits
[i
] =
4307 le16_to_cpu(bw_ets_config
.credits
[i
]);
4308 /* 3 bits out of 4 for each TC */
4309 vsi
->bw_ets_max_quanta
[i
] = (u8
)((tc_bw_max
>> (i
*4)) & 0x7);
4316 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
4317 * @vsi: the VSI being configured
4318 * @enabled_tc: TC bitmap
4319 * @bw_credits: BW shared credits per TC
4321 * Returns 0 on success, negative value on failure
4323 static int i40e_vsi_configure_bw_alloc(struct i40e_vsi
*vsi
, u8 enabled_tc
,
4326 struct i40e_aqc_configure_vsi_tc_bw_data bw_data
;
4330 bw_data
.tc_valid_bits
= enabled_tc
;
4331 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
4332 bw_data
.tc_bw_credits
[i
] = bw_share
[i
];
4334 ret
= i40e_aq_config_vsi_tc_bw(&vsi
->back
->hw
, vsi
->seid
, &bw_data
,
4337 dev_info(&vsi
->back
->pdev
->dev
,
4338 "AQ command Config VSI BW allocation per TC failed = %d\n",
4339 vsi
->back
->hw
.aq
.asq_last_status
);
4343 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
4344 vsi
->info
.qs_handle
[i
] = bw_data
.qs_handles
[i
];
4350 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
4351 * @vsi: the VSI being configured
4352 * @enabled_tc: TC map to be enabled
4355 static void i40e_vsi_config_netdev_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
4357 struct net_device
*netdev
= vsi
->netdev
;
4358 struct i40e_pf
*pf
= vsi
->back
;
4359 struct i40e_hw
*hw
= &pf
->hw
;
4362 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4368 netdev_reset_tc(netdev
);
4372 /* Set up actual enabled TCs on the VSI */
4373 if (netdev_set_num_tc(netdev
, vsi
->tc_config
.numtc
))
4376 /* set per TC queues for the VSI */
4377 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4378 /* Only set TC queues for enabled tcs
4380 * e.g. For a VSI that has TC0 and TC3 enabled the
4381 * enabled_tc bitmap would be 0x00001001; the driver
4382 * will set the numtc for netdev as 2 that will be
4383 * referenced by the netdev layer as TC 0 and 1.
4385 if (vsi
->tc_config
.enabled_tc
& BIT_ULL(i
))
4386 netdev_set_tc_queue(netdev
,
4387 vsi
->tc_config
.tc_info
[i
].netdev_tc
,
4388 vsi
->tc_config
.tc_info
[i
].qcount
,
4389 vsi
->tc_config
.tc_info
[i
].qoffset
);
4392 /* Assign UP2TC map for the VSI */
4393 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
4394 /* Get the actual TC# for the UP */
4395 u8 ets_tc
= dcbcfg
->etscfg
.prioritytable
[i
];
4396 /* Get the mapped netdev TC# for the UP */
4397 netdev_tc
= vsi
->tc_config
.tc_info
[ets_tc
].netdev_tc
;
4398 netdev_set_prio_tc_map(netdev
, i
, netdev_tc
);
4403 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
4404 * @vsi: the VSI being configured
4405 * @ctxt: the ctxt buffer returned from AQ VSI update param command
4407 static void i40e_vsi_update_queue_map(struct i40e_vsi
*vsi
,
4408 struct i40e_vsi_context
*ctxt
)
4410 /* copy just the sections touched not the entire info
4411 * since not all sections are valid as returned by
4414 vsi
->info
.mapping_flags
= ctxt
->info
.mapping_flags
;
4415 memcpy(&vsi
->info
.queue_mapping
,
4416 &ctxt
->info
.queue_mapping
, sizeof(vsi
->info
.queue_mapping
));
4417 memcpy(&vsi
->info
.tc_mapping
, ctxt
->info
.tc_mapping
,
4418 sizeof(vsi
->info
.tc_mapping
));
4422 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
4423 * @vsi: VSI to be configured
4424 * @enabled_tc: TC bitmap
4426 * This configures a particular VSI for TCs that are mapped to the
4427 * given TC bitmap. It uses default bandwidth share for TCs across
4428 * VSIs to configure TC for a particular VSI.
4431 * It is expected that the VSI queues have been quisced before calling
4434 static int i40e_vsi_config_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
4436 u8 bw_share
[I40E_MAX_TRAFFIC_CLASS
] = {0};
4437 struct i40e_vsi_context ctxt
;
4441 /* Check if enabled_tc is same as existing or new TCs */
4442 if (vsi
->tc_config
.enabled_tc
== enabled_tc
)
4445 /* Enable ETS TCs with equal BW Share for now across all VSIs */
4446 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4447 if (enabled_tc
& BIT_ULL(i
))
4451 ret
= i40e_vsi_configure_bw_alloc(vsi
, enabled_tc
, bw_share
);
4453 dev_info(&vsi
->back
->pdev
->dev
,
4454 "Failed configuring TC map %d for VSI %d\n",
4455 enabled_tc
, vsi
->seid
);
4459 /* Update Queue Pairs Mapping for currently enabled UPs */
4460 ctxt
.seid
= vsi
->seid
;
4461 ctxt
.pf_num
= vsi
->back
->hw
.pf_id
;
4463 ctxt
.uplink_seid
= vsi
->uplink_seid
;
4464 ctxt
.info
= vsi
->info
;
4465 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
4467 /* Update the VSI after updating the VSI queue-mapping information */
4468 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
4470 dev_info(&vsi
->back
->pdev
->dev
,
4471 "Update vsi tc config failed, err %s aq_err %s\n",
4472 i40e_stat_str(&vsi
->back
->hw
, ret
),
4473 i40e_aq_str(&vsi
->back
->hw
,
4474 vsi
->back
->hw
.aq
.asq_last_status
));
4477 /* update the local VSI info with updated queue map */
4478 i40e_vsi_update_queue_map(vsi
, &ctxt
);
4479 vsi
->info
.valid_sections
= 0;
4481 /* Update current VSI BW information */
4482 ret
= i40e_vsi_get_bw_info(vsi
);
4484 dev_info(&vsi
->back
->pdev
->dev
,
4485 "Failed updating vsi bw info, err %s aq_err %s\n",
4486 i40e_stat_str(&vsi
->back
->hw
, ret
),
4487 i40e_aq_str(&vsi
->back
->hw
,
4488 vsi
->back
->hw
.aq
.asq_last_status
));
4492 /* Update the netdev TC setup */
4493 i40e_vsi_config_netdev_tc(vsi
, enabled_tc
);
4499 * i40e_veb_config_tc - Configure TCs for given VEB
4501 * @enabled_tc: TC bitmap
4503 * Configures given TC bitmap for VEB (switching) element
4505 int i40e_veb_config_tc(struct i40e_veb
*veb
, u8 enabled_tc
)
4507 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data
= {0};
4508 struct i40e_pf
*pf
= veb
->pf
;
4512 /* No TCs or already enabled TCs just return */
4513 if (!enabled_tc
|| veb
->enabled_tc
== enabled_tc
)
4516 bw_data
.tc_valid_bits
= enabled_tc
;
4517 /* bw_data.absolute_credits is not set (relative) */
4519 /* Enable ETS TCs with equal BW Share for now */
4520 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4521 if (enabled_tc
& BIT_ULL(i
))
4522 bw_data
.tc_bw_share_credits
[i
] = 1;
4525 ret
= i40e_aq_config_switch_comp_bw_config(&pf
->hw
, veb
->seid
,
4528 dev_info(&pf
->pdev
->dev
,
4529 "VEB bw config failed, err %s aq_err %s\n",
4530 i40e_stat_str(&pf
->hw
, ret
),
4531 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4535 /* Update the BW information */
4536 ret
= i40e_veb_get_bw_info(veb
);
4538 dev_info(&pf
->pdev
->dev
,
4539 "Failed getting veb bw config, err %s aq_err %s\n",
4540 i40e_stat_str(&pf
->hw
, ret
),
4541 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4548 #ifdef CONFIG_I40E_DCB
4550 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
4553 * Reconfigure VEB/VSIs on a given PF; it is assumed that
4554 * the caller would've quiesce all the VSIs before calling
4557 static void i40e_dcb_reconfigure(struct i40e_pf
*pf
)
4563 /* Enable the TCs available on PF to all VEBs */
4564 tc_map
= i40e_pf_get_tc_map(pf
);
4565 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
4568 ret
= i40e_veb_config_tc(pf
->veb
[v
], tc_map
);
4570 dev_info(&pf
->pdev
->dev
,
4571 "Failed configuring TC for VEB seid=%d\n",
4573 /* Will try to configure as many components */
4577 /* Update each VSI */
4578 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4582 /* - Enable all TCs for the LAN VSI
4584 * - For FCoE VSI only enable the TC configured
4585 * as per the APP TLV
4587 * - For all others keep them at TC0 for now
4589 if (v
== pf
->lan_vsi
)
4590 tc_map
= i40e_pf_get_tc_map(pf
);
4592 tc_map
= i40e_pf_get_default_tc(pf
);
4594 if (pf
->vsi
[v
]->type
== I40E_VSI_FCOE
)
4595 tc_map
= i40e_get_fcoe_tc_map(pf
);
4596 #endif /* #ifdef I40E_FCOE */
4598 ret
= i40e_vsi_config_tc(pf
->vsi
[v
], tc_map
);
4600 dev_info(&pf
->pdev
->dev
,
4601 "Failed configuring TC for VSI seid=%d\n",
4603 /* Will try to configure as many components */
4605 /* Re-configure VSI vectors based on updated TC map */
4606 i40e_vsi_map_rings_to_vectors(pf
->vsi
[v
]);
4607 if (pf
->vsi
[v
]->netdev
)
4608 i40e_dcbnl_set_all(pf
->vsi
[v
]);
4614 * i40e_resume_port_tx - Resume port Tx
4617 * Resume a port's Tx and issue a PF reset in case of failure to
4620 static int i40e_resume_port_tx(struct i40e_pf
*pf
)
4622 struct i40e_hw
*hw
= &pf
->hw
;
4625 ret
= i40e_aq_resume_port_tx(hw
, NULL
);
4627 dev_info(&pf
->pdev
->dev
,
4628 "Resume Port Tx failed, err %s aq_err %s\n",
4629 i40e_stat_str(&pf
->hw
, ret
),
4630 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4631 /* Schedule PF reset to recover */
4632 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
4633 i40e_service_event_schedule(pf
);
4640 * i40e_init_pf_dcb - Initialize DCB configuration
4641 * @pf: PF being configured
4643 * Query the current DCB configuration and cache it
4644 * in the hardware structure
4646 static int i40e_init_pf_dcb(struct i40e_pf
*pf
)
4648 struct i40e_hw
*hw
= &pf
->hw
;
4651 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
4652 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
4653 (pf
->hw
.aq
.fw_maj_ver
< 4))
4656 /* Get the initial DCB configuration */
4657 err
= i40e_init_dcb(hw
);
4659 /* Device/Function is not DCBX capable */
4660 if ((!hw
->func_caps
.dcb
) ||
4661 (hw
->dcbx_status
== I40E_DCBX_STATUS_DISABLED
)) {
4662 dev_info(&pf
->pdev
->dev
,
4663 "DCBX offload is not supported or is disabled for this PF.\n");
4665 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
)
4669 /* When status is not DISABLED then DCBX in FW */
4670 pf
->dcbx_cap
= DCB_CAP_DCBX_LLD_MANAGED
|
4671 DCB_CAP_DCBX_VER_IEEE
;
4673 pf
->flags
|= I40E_FLAG_DCB_CAPABLE
;
4674 /* Enable DCB tagging only when more than one TC */
4675 if (i40e_dcb_get_num_tc(&hw
->local_dcbx_config
) > 1)
4676 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
4677 dev_dbg(&pf
->pdev
->dev
,
4678 "DCBX offload is supported for this PF.\n");
4681 dev_info(&pf
->pdev
->dev
,
4682 "Query for DCB configuration failed, err %s aq_err %s\n",
4683 i40e_stat_str(&pf
->hw
, err
),
4684 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
4690 #endif /* CONFIG_I40E_DCB */
4691 #define SPEED_SIZE 14
4694 * i40e_print_link_message - print link up or down
4695 * @vsi: the VSI for which link needs a message
4697 static void i40e_print_link_message(struct i40e_vsi
*vsi
, bool isup
)
4699 char speed
[SPEED_SIZE
] = "Unknown";
4700 char fc
[FC_SIZE
] = "RX/TX";
4703 netdev_info(vsi
->netdev
, "NIC Link is Down\n");
4707 /* Warn user if link speed on NPAR enabled partition is not at
4710 if (vsi
->back
->hw
.func_caps
.npar_enable
&&
4711 (vsi
->back
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_1GB
||
4712 vsi
->back
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_100MB
))
4713 netdev_warn(vsi
->netdev
,
4714 "The partition detected link speed that is less than 10Gbps\n");
4716 switch (vsi
->back
->hw
.phy
.link_info
.link_speed
) {
4717 case I40E_LINK_SPEED_40GB
:
4718 strlcpy(speed
, "40 Gbps", SPEED_SIZE
);
4720 case I40E_LINK_SPEED_20GB
:
4721 strncpy(speed
, "20 Gbps", SPEED_SIZE
);
4723 case I40E_LINK_SPEED_10GB
:
4724 strlcpy(speed
, "10 Gbps", SPEED_SIZE
);
4726 case I40E_LINK_SPEED_1GB
:
4727 strlcpy(speed
, "1000 Mbps", SPEED_SIZE
);
4729 case I40E_LINK_SPEED_100MB
:
4730 strncpy(speed
, "100 Mbps", SPEED_SIZE
);
4736 switch (vsi
->back
->hw
.fc
.current_mode
) {
4738 strlcpy(fc
, "RX/TX", FC_SIZE
);
4740 case I40E_FC_TX_PAUSE
:
4741 strlcpy(fc
, "TX", FC_SIZE
);
4743 case I40E_FC_RX_PAUSE
:
4744 strlcpy(fc
, "RX", FC_SIZE
);
4747 strlcpy(fc
, "None", FC_SIZE
);
4751 netdev_info(vsi
->netdev
, "NIC Link is Up %s Full Duplex, Flow Control: %s\n",
4756 * i40e_up_complete - Finish the last steps of bringing up a connection
4757 * @vsi: the VSI being configured
4759 static int i40e_up_complete(struct i40e_vsi
*vsi
)
4761 struct i40e_pf
*pf
= vsi
->back
;
4764 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
4765 i40e_vsi_configure_msix(vsi
);
4767 i40e_configure_msi_and_legacy(vsi
);
4770 err
= i40e_vsi_control_rings(vsi
, true);
4774 clear_bit(__I40E_DOWN
, &vsi
->state
);
4775 i40e_napi_enable_all(vsi
);
4776 i40e_vsi_enable_irq(vsi
);
4778 if ((pf
->hw
.phy
.link_info
.link_info
& I40E_AQ_LINK_UP
) &&
4780 i40e_print_link_message(vsi
, true);
4781 netif_tx_start_all_queues(vsi
->netdev
);
4782 netif_carrier_on(vsi
->netdev
);
4783 } else if (vsi
->netdev
) {
4784 i40e_print_link_message(vsi
, false);
4785 /* need to check for qualified module here*/
4786 if ((pf
->hw
.phy
.link_info
.link_info
&
4787 I40E_AQ_MEDIA_AVAILABLE
) &&
4788 (!(pf
->hw
.phy
.link_info
.an_info
&
4789 I40E_AQ_QUALIFIED_MODULE
)))
4790 netdev_err(vsi
->netdev
,
4791 "the driver failed to link because an unqualified module was detected.");
4794 /* replay FDIR SB filters */
4795 if (vsi
->type
== I40E_VSI_FDIR
) {
4796 /* reset fd counters */
4797 pf
->fd_add_err
= pf
->fd_atr_cnt
= 0;
4798 if (pf
->fd_tcp_rule
> 0) {
4799 pf
->flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
4800 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
4801 dev_info(&pf
->pdev
->dev
, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
4802 pf
->fd_tcp_rule
= 0;
4804 i40e_fdir_filter_restore(vsi
);
4806 i40e_service_event_schedule(pf
);
4812 * i40e_vsi_reinit_locked - Reset the VSI
4813 * @vsi: the VSI being configured
4815 * Rebuild the ring structs after some configuration
4816 * has changed, e.g. MTU size.
4818 static void i40e_vsi_reinit_locked(struct i40e_vsi
*vsi
)
4820 struct i40e_pf
*pf
= vsi
->back
;
4822 WARN_ON(in_interrupt());
4823 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
4824 usleep_range(1000, 2000);
4827 /* Give a VF some time to respond to the reset. The
4828 * two second wait is based upon the watchdog cycle in
4831 if (vsi
->type
== I40E_VSI_SRIOV
)
4834 clear_bit(__I40E_CONFIG_BUSY
, &pf
->state
);
4838 * i40e_up - Bring the connection back up after being down
4839 * @vsi: the VSI being configured
4841 int i40e_up(struct i40e_vsi
*vsi
)
4845 err
= i40e_vsi_configure(vsi
);
4847 err
= i40e_up_complete(vsi
);
4853 * i40e_down - Shutdown the connection processing
4854 * @vsi: the VSI being stopped
4856 void i40e_down(struct i40e_vsi
*vsi
)
4860 /* It is assumed that the caller of this function
4861 * sets the vsi->state __I40E_DOWN bit.
4864 netif_carrier_off(vsi
->netdev
);
4865 netif_tx_disable(vsi
->netdev
);
4867 i40e_vsi_disable_irq(vsi
);
4868 i40e_vsi_control_rings(vsi
, false);
4869 i40e_napi_disable_all(vsi
);
4871 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
4872 i40e_clean_tx_ring(vsi
->tx_rings
[i
]);
4873 i40e_clean_rx_ring(vsi
->rx_rings
[i
]);
4878 * i40e_setup_tc - configure multiple traffic classes
4879 * @netdev: net device to configure
4880 * @tc: number of traffic classes to enable
4883 int i40e_setup_tc(struct net_device
*netdev
, u8 tc
)
4885 static int i40e_setup_tc(struct net_device
*netdev
, u8 tc
)
4888 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
4889 struct i40e_vsi
*vsi
= np
->vsi
;
4890 struct i40e_pf
*pf
= vsi
->back
;
4895 /* Check if DCB enabled to continue */
4896 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
)) {
4897 netdev_info(netdev
, "DCB is not enabled for adapter\n");
4901 /* Check if MFP enabled */
4902 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
4903 netdev_info(netdev
, "Configuring TC not supported in MFP mode\n");
4907 /* Check whether tc count is within enabled limit */
4908 if (tc
> i40e_pf_get_num_tc(pf
)) {
4909 netdev_info(netdev
, "TC count greater than enabled on link for adapter\n");
4913 /* Generate TC map for number of tc requested */
4914 for (i
= 0; i
< tc
; i
++)
4915 enabled_tc
|= BIT_ULL(i
);
4917 /* Requesting same TC configuration as already enabled */
4918 if (enabled_tc
== vsi
->tc_config
.enabled_tc
)
4921 /* Quiesce VSI queues */
4922 i40e_quiesce_vsi(vsi
);
4924 /* Configure VSI for enabled TCs */
4925 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
4927 netdev_info(netdev
, "Failed configuring TC for VSI seid=%d\n",
4933 i40e_unquiesce_vsi(vsi
);
4940 * i40e_open - Called when a network interface is made active
4941 * @netdev: network interface device structure
4943 * The open entry point is called when a network interface is made
4944 * active by the system (IFF_UP). At this point all resources needed
4945 * for transmit and receive operations are allocated, the interrupt
4946 * handler is registered with the OS, the netdev watchdog subtask is
4947 * enabled, and the stack is notified that the interface is ready.
4949 * Returns 0 on success, negative value on failure
4951 int i40e_open(struct net_device
*netdev
)
4953 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
4954 struct i40e_vsi
*vsi
= np
->vsi
;
4955 struct i40e_pf
*pf
= vsi
->back
;
4958 /* disallow open during test or if eeprom is broken */
4959 if (test_bit(__I40E_TESTING
, &pf
->state
) ||
4960 test_bit(__I40E_BAD_EEPROM
, &pf
->state
))
4963 netif_carrier_off(netdev
);
4965 err
= i40e_vsi_open(vsi
);
4969 /* configure global TSO hardware offload settings */
4970 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_F
, be32_to_cpu(TCP_FLAG_PSH
|
4971 TCP_FLAG_FIN
) >> 16);
4972 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_M
, be32_to_cpu(TCP_FLAG_PSH
|
4974 TCP_FLAG_CWR
) >> 16);
4975 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_L
, be32_to_cpu(TCP_FLAG_CWR
) >> 16);
4977 #ifdef CONFIG_I40E_VXLAN
4978 vxlan_get_rx_port(netdev
);
4986 * @vsi: the VSI to open
4988 * Finish initialization of the VSI.
4990 * Returns 0 on success, negative value on failure
4992 int i40e_vsi_open(struct i40e_vsi
*vsi
)
4994 struct i40e_pf
*pf
= vsi
->back
;
4995 char int_name
[I40E_INT_NAME_STR_LEN
];
4998 /* allocate descriptors */
4999 err
= i40e_vsi_setup_tx_resources(vsi
);
5002 err
= i40e_vsi_setup_rx_resources(vsi
);
5006 err
= i40e_vsi_configure(vsi
);
5011 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s",
5012 dev_driver_string(&pf
->pdev
->dev
), vsi
->netdev
->name
);
5013 err
= i40e_vsi_request_irq(vsi
, int_name
);
5017 /* Notify the stack of the actual queue counts. */
5018 err
= netif_set_real_num_tx_queues(vsi
->netdev
,
5019 vsi
->num_queue_pairs
);
5021 goto err_set_queues
;
5023 err
= netif_set_real_num_rx_queues(vsi
->netdev
,
5024 vsi
->num_queue_pairs
);
5026 goto err_set_queues
;
5028 } else if (vsi
->type
== I40E_VSI_FDIR
) {
5029 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s:fdir",
5030 dev_driver_string(&pf
->pdev
->dev
),
5031 dev_name(&pf
->pdev
->dev
));
5032 err
= i40e_vsi_request_irq(vsi
, int_name
);
5039 err
= i40e_up_complete(vsi
);
5041 goto err_up_complete
;
5048 i40e_vsi_free_irq(vsi
);
5050 i40e_vsi_free_rx_resources(vsi
);
5052 i40e_vsi_free_tx_resources(vsi
);
5053 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
5054 i40e_do_reset(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
5060 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
5061 * @pf: Pointer to PF
5063 * This function destroys the hlist where all the Flow Director
5064 * filters were saved.
5066 static void i40e_fdir_filter_exit(struct i40e_pf
*pf
)
5068 struct i40e_fdir_filter
*filter
;
5069 struct hlist_node
*node2
;
5071 hlist_for_each_entry_safe(filter
, node2
,
5072 &pf
->fdir_filter_list
, fdir_node
) {
5073 hlist_del(&filter
->fdir_node
);
5076 pf
->fdir_pf_active_filters
= 0;
5080 * i40e_close - Disables a network interface
5081 * @netdev: network interface device structure
5083 * The close entry point is called when an interface is de-activated
5084 * by the OS. The hardware is still under the driver's control, but
5085 * this netdev interface is disabled.
5087 * Returns 0, this is not allowed to fail
5090 int i40e_close(struct net_device
*netdev
)
5092 static int i40e_close(struct net_device
*netdev
)
5095 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
5096 struct i40e_vsi
*vsi
= np
->vsi
;
5098 i40e_vsi_close(vsi
);
5104 * i40e_do_reset - Start a PF or Core Reset sequence
5105 * @pf: board private structure
5106 * @reset_flags: which reset is requested
5108 * The essential difference in resets is that the PF Reset
5109 * doesn't clear the packet buffers, doesn't reset the PE
5110 * firmware, and doesn't bother the other PFs on the chip.
5112 void i40e_do_reset(struct i40e_pf
*pf
, u32 reset_flags
)
5116 WARN_ON(in_interrupt());
5118 if (i40e_check_asq_alive(&pf
->hw
))
5119 i40e_vc_notify_reset(pf
);
5121 /* do the biggest reset indicated */
5122 if (reset_flags
& BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED
)) {
5124 /* Request a Global Reset
5126 * This will start the chip's countdown to the actual full
5127 * chip reset event, and a warning interrupt to be sent
5128 * to all PFs, including the requestor. Our handler
5129 * for the warning interrupt will deal with the shutdown
5130 * and recovery of the switch setup.
5132 dev_dbg(&pf
->pdev
->dev
, "GlobalR requested\n");
5133 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
5134 val
|= I40E_GLGEN_RTRIG_GLOBR_MASK
;
5135 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
5137 } else if (reset_flags
& BIT_ULL(__I40E_CORE_RESET_REQUESTED
)) {
5139 /* Request a Core Reset
5141 * Same as Global Reset, except does *not* include the MAC/PHY
5143 dev_dbg(&pf
->pdev
->dev
, "CoreR requested\n");
5144 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
5145 val
|= I40E_GLGEN_RTRIG_CORER_MASK
;
5146 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
5147 i40e_flush(&pf
->hw
);
5149 } else if (reset_flags
& BIT_ULL(__I40E_PF_RESET_REQUESTED
)) {
5151 /* Request a PF Reset
5153 * Resets only the PF-specific registers
5155 * This goes directly to the tear-down and rebuild of
5156 * the switch, since we need to do all the recovery as
5157 * for the Core Reset.
5159 dev_dbg(&pf
->pdev
->dev
, "PFR requested\n");
5160 i40e_handle_reset_warning(pf
);
5162 } else if (reset_flags
& BIT_ULL(__I40E_REINIT_REQUESTED
)) {
5165 /* Find the VSI(s) that requested a re-init */
5166 dev_info(&pf
->pdev
->dev
,
5167 "VSI reinit requested\n");
5168 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5169 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
5171 test_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
)) {
5172 i40e_vsi_reinit_locked(pf
->vsi
[v
]);
5173 clear_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
);
5177 /* no further action needed, so return now */
5179 } else if (reset_flags
& BIT_ULL(__I40E_DOWN_REQUESTED
)) {
5182 /* Find the VSI(s) that needs to be brought down */
5183 dev_info(&pf
->pdev
->dev
, "VSI down requested\n");
5184 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5185 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
5187 test_bit(__I40E_DOWN_REQUESTED
, &vsi
->state
)) {
5188 set_bit(__I40E_DOWN
, &vsi
->state
);
5190 clear_bit(__I40E_DOWN_REQUESTED
, &vsi
->state
);
5194 /* no further action needed, so return now */
5197 dev_info(&pf
->pdev
->dev
,
5198 "bad reset request 0x%08x\n", reset_flags
);
5203 #ifdef CONFIG_I40E_DCB
5205 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
5206 * @pf: board private structure
5207 * @old_cfg: current DCB config
5208 * @new_cfg: new DCB config
5210 bool i40e_dcb_need_reconfig(struct i40e_pf
*pf
,
5211 struct i40e_dcbx_config
*old_cfg
,
5212 struct i40e_dcbx_config
*new_cfg
)
5214 bool need_reconfig
= false;
5216 /* Check if ETS configuration has changed */
5217 if (memcmp(&new_cfg
->etscfg
,
5219 sizeof(new_cfg
->etscfg
))) {
5220 /* If Priority Table has changed reconfig is needed */
5221 if (memcmp(&new_cfg
->etscfg
.prioritytable
,
5222 &old_cfg
->etscfg
.prioritytable
,
5223 sizeof(new_cfg
->etscfg
.prioritytable
))) {
5224 need_reconfig
= true;
5225 dev_dbg(&pf
->pdev
->dev
, "ETS UP2TC changed.\n");
5228 if (memcmp(&new_cfg
->etscfg
.tcbwtable
,
5229 &old_cfg
->etscfg
.tcbwtable
,
5230 sizeof(new_cfg
->etscfg
.tcbwtable
)))
5231 dev_dbg(&pf
->pdev
->dev
, "ETS TC BW Table changed.\n");
5233 if (memcmp(&new_cfg
->etscfg
.tsatable
,
5234 &old_cfg
->etscfg
.tsatable
,
5235 sizeof(new_cfg
->etscfg
.tsatable
)))
5236 dev_dbg(&pf
->pdev
->dev
, "ETS TSA Table changed.\n");
5239 /* Check if PFC configuration has changed */
5240 if (memcmp(&new_cfg
->pfc
,
5242 sizeof(new_cfg
->pfc
))) {
5243 need_reconfig
= true;
5244 dev_dbg(&pf
->pdev
->dev
, "PFC config change detected.\n");
5247 /* Check if APP Table has changed */
5248 if (memcmp(&new_cfg
->app
,
5250 sizeof(new_cfg
->app
))) {
5251 need_reconfig
= true;
5252 dev_dbg(&pf
->pdev
->dev
, "APP Table change detected.\n");
5255 dev_dbg(&pf
->pdev
->dev
, "%s: need_reconfig=%d\n", __func__
,
5257 return need_reconfig
;
5261 * i40e_handle_lldp_event - Handle LLDP Change MIB event
5262 * @pf: board private structure
5263 * @e: event info posted on ARQ
5265 static int i40e_handle_lldp_event(struct i40e_pf
*pf
,
5266 struct i40e_arq_event_info
*e
)
5268 struct i40e_aqc_lldp_get_mib
*mib
=
5269 (struct i40e_aqc_lldp_get_mib
*)&e
->desc
.params
.raw
;
5270 struct i40e_hw
*hw
= &pf
->hw
;
5271 struct i40e_dcbx_config tmp_dcbx_cfg
;
5272 bool need_reconfig
= false;
5276 /* Not DCB capable or capability disabled */
5277 if (!(pf
->flags
& I40E_FLAG_DCB_CAPABLE
))
5280 /* Ignore if event is not for Nearest Bridge */
5281 type
= ((mib
->type
>> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT
)
5282 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK
);
5283 dev_dbg(&pf
->pdev
->dev
,
5284 "%s: LLDP event mib bridge type 0x%x\n", __func__
, type
);
5285 if (type
!= I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
)
5288 /* Check MIB Type and return if event for Remote MIB update */
5289 type
= mib
->type
& I40E_AQ_LLDP_MIB_TYPE_MASK
;
5290 dev_dbg(&pf
->pdev
->dev
,
5291 "%s: LLDP event mib type %s\n", __func__
,
5292 type
? "remote" : "local");
5293 if (type
== I40E_AQ_LLDP_MIB_REMOTE
) {
5294 /* Update the remote cached instance and return */
5295 ret
= i40e_aq_get_dcb_config(hw
, I40E_AQ_LLDP_MIB_REMOTE
,
5296 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
,
5297 &hw
->remote_dcbx_config
);
5301 /* Store the old configuration */
5302 tmp_dcbx_cfg
= hw
->local_dcbx_config
;
5304 /* Reset the old DCBx configuration data */
5305 memset(&hw
->local_dcbx_config
, 0, sizeof(hw
->local_dcbx_config
));
5306 /* Get updated DCBX data from firmware */
5307 ret
= i40e_get_dcb_config(&pf
->hw
);
5309 dev_info(&pf
->pdev
->dev
,
5310 "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
5311 i40e_stat_str(&pf
->hw
, ret
),
5312 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
5316 /* No change detected in DCBX configs */
5317 if (!memcmp(&tmp_dcbx_cfg
, &hw
->local_dcbx_config
,
5318 sizeof(tmp_dcbx_cfg
))) {
5319 dev_dbg(&pf
->pdev
->dev
, "No change detected in DCBX configuration.\n");
5323 need_reconfig
= i40e_dcb_need_reconfig(pf
, &tmp_dcbx_cfg
,
5324 &hw
->local_dcbx_config
);
5326 i40e_dcbnl_flush_apps(pf
, &tmp_dcbx_cfg
, &hw
->local_dcbx_config
);
5331 /* Enable DCB tagging only when more than one TC */
5332 if (i40e_dcb_get_num_tc(&hw
->local_dcbx_config
) > 1)
5333 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
5335 pf
->flags
&= ~I40E_FLAG_DCB_ENABLED
;
5337 set_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
);
5338 /* Reconfiguration needed quiesce all VSIs */
5339 i40e_pf_quiesce_all_vsi(pf
);
5341 /* Changes in configuration update VEB/VSI */
5342 i40e_dcb_reconfigure(pf
);
5344 ret
= i40e_resume_port_tx(pf
);
5346 clear_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
);
5347 /* In case of error no point in resuming VSIs */
5351 /* Wait for the PF's Tx queues to be disabled */
5352 ret
= i40e_pf_wait_txq_disabled(pf
);
5354 /* Schedule PF reset to recover */
5355 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
5356 i40e_service_event_schedule(pf
);
5358 i40e_pf_unquiesce_all_vsi(pf
);
5364 #endif /* CONFIG_I40E_DCB */
5367 * i40e_do_reset_safe - Protected reset path for userland calls.
5368 * @pf: board private structure
5369 * @reset_flags: which reset is requested
5372 void i40e_do_reset_safe(struct i40e_pf
*pf
, u32 reset_flags
)
5375 i40e_do_reset(pf
, reset_flags
);
5380 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
5381 * @pf: board private structure
5382 * @e: event info posted on ARQ
5384 * Handler for LAN Queue Overflow Event generated by the firmware for PF
5387 static void i40e_handle_lan_overflow_event(struct i40e_pf
*pf
,
5388 struct i40e_arq_event_info
*e
)
5390 struct i40e_aqc_lan_overflow
*data
=
5391 (struct i40e_aqc_lan_overflow
*)&e
->desc
.params
.raw
;
5392 u32 queue
= le32_to_cpu(data
->prtdcb_rupto
);
5393 u32 qtx_ctl
= le32_to_cpu(data
->otx_ctl
);
5394 struct i40e_hw
*hw
= &pf
->hw
;
5398 dev_dbg(&pf
->pdev
->dev
, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
5401 /* Queue belongs to VF, find the VF and issue VF reset */
5402 if (((qtx_ctl
& I40E_QTX_CTL_PFVF_Q_MASK
)
5403 >> I40E_QTX_CTL_PFVF_Q_SHIFT
) == I40E_QTX_CTL_VF_QUEUE
) {
5404 vf_id
= (u16
)((qtx_ctl
& I40E_QTX_CTL_VFVM_INDX_MASK
)
5405 >> I40E_QTX_CTL_VFVM_INDX_SHIFT
);
5406 vf_id
-= hw
->func_caps
.vf_base_id
;
5407 vf
= &pf
->vf
[vf_id
];
5408 i40e_vc_notify_vf_reset(vf
);
5409 /* Allow VF to process pending reset notification */
5411 i40e_reset_vf(vf
, false);
5416 * i40e_service_event_complete - Finish up the service event
5417 * @pf: board private structure
5419 static void i40e_service_event_complete(struct i40e_pf
*pf
)
5421 BUG_ON(!test_bit(__I40E_SERVICE_SCHED
, &pf
->state
));
5423 /* flush memory to make sure state is correct before next watchog */
5424 smp_mb__before_atomic();
5425 clear_bit(__I40E_SERVICE_SCHED
, &pf
->state
);
5429 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
5430 * @pf: board private structure
5432 u32
i40e_get_cur_guaranteed_fd_count(struct i40e_pf
*pf
)
5436 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
5437 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
);
5442 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
5443 * @pf: board private structure
5445 u32
i40e_get_current_fd_count(struct i40e_pf
*pf
)
5449 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
5450 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
) +
5451 ((val
& I40E_PFQF_FDSTAT_BEST_CNT_MASK
) >>
5452 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT
);
5457 * i40e_get_global_fd_count - Get total FD filters programmed on device
5458 * @pf: board private structure
5460 u32
i40e_get_global_fd_count(struct i40e_pf
*pf
)
5464 val
= rd32(&pf
->hw
, I40E_GLQF_FDCNT_0
);
5465 fcnt_prog
= (val
& I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK
) +
5466 ((val
& I40E_GLQF_FDCNT_0_BESTCNT_MASK
) >>
5467 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT
);
5472 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
5473 * @pf: board private structure
5475 void i40e_fdir_check_and_reenable(struct i40e_pf
*pf
)
5477 u32 fcnt_prog
, fcnt_avail
;
5479 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
5482 /* Check if, FD SB or ATR was auto disabled and if there is enough room
5485 fcnt_prog
= i40e_get_global_fd_count(pf
);
5486 fcnt_avail
= pf
->fdir_pf_filter_count
;
5487 if ((fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM
)) ||
5488 (pf
->fd_add_err
== 0) ||
5489 (i40e_get_current_atr_cnt(pf
) < pf
->fd_atr_cnt
)) {
5490 if ((pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) &&
5491 (pf
->auto_disable_flags
& I40E_FLAG_FD_SB_ENABLED
)) {
5492 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
5493 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5494 dev_info(&pf
->pdev
->dev
, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
5497 /* Wait for some more space to be available to turn on ATR */
5498 if (fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM
* 2)) {
5499 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
5500 (pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
)) {
5501 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
5502 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5503 dev_info(&pf
->pdev
->dev
, "ATR is being enabled since we have space in the table now\n");
5508 #define I40E_MIN_FD_FLUSH_INTERVAL 10
5509 #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
5511 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
5512 * @pf: board private structure
5514 static void i40e_fdir_flush_and_replay(struct i40e_pf
*pf
)
5516 unsigned long min_flush_time
;
5517 int flush_wait_retry
= 50;
5518 bool disable_atr
= false;
5522 if (!(pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
)))
5525 if (time_after(jiffies
, pf
->fd_flush_timestamp
+
5526 (I40E_MIN_FD_FLUSH_INTERVAL
* HZ
))) {
5527 /* If the flush is happening too quick and we have mostly
5528 * SB rules we should not re-enable ATR for some time.
5530 min_flush_time
= pf
->fd_flush_timestamp
5531 + (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE
* HZ
);
5532 fd_room
= pf
->fdir_pf_filter_count
- pf
->fdir_pf_active_filters
;
5534 if (!(time_after(jiffies
, min_flush_time
)) &&
5535 (fd_room
< I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR
)) {
5536 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5537 dev_info(&pf
->pdev
->dev
, "ATR disabled, not enough FD filter space.\n");
5541 pf
->fd_flush_timestamp
= jiffies
;
5542 pf
->flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
5543 /* flush all filters */
5544 wr32(&pf
->hw
, I40E_PFQF_CTL_1
,
5545 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
);
5546 i40e_flush(&pf
->hw
);
5550 /* Check FD flush status every 5-6msec */
5551 usleep_range(5000, 6000);
5552 reg
= rd32(&pf
->hw
, I40E_PFQF_CTL_1
);
5553 if (!(reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
))
5555 } while (flush_wait_retry
--);
5556 if (reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
) {
5557 dev_warn(&pf
->pdev
->dev
, "FD table did not flush, needs more time\n");
5559 /* replay sideband filters */
5560 i40e_fdir_filter_restore(pf
->vsi
[pf
->lan_vsi
]);
5562 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
5563 clear_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
);
5564 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5565 dev_info(&pf
->pdev
->dev
, "FD Filter table flushed and FD-SB replayed.\n");
5571 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
5572 * @pf: board private structure
5574 u32
i40e_get_current_atr_cnt(struct i40e_pf
*pf
)
5576 return i40e_get_current_fd_count(pf
) - pf
->fdir_pf_active_filters
;
5579 /* We can see up to 256 filter programming desc in transit if the filters are
5580 * being applied really fast; before we see the first
5581 * filter miss error on Rx queue 0. Accumulating enough error messages before
5582 * reacting will make sure we don't cause flush too often.
5584 #define I40E_MAX_FD_PROGRAM_ERROR 256
5587 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
5588 * @pf: board private structure
5590 static void i40e_fdir_reinit_subtask(struct i40e_pf
*pf
)
5593 /* if interface is down do nothing */
5594 if (test_bit(__I40E_DOWN
, &pf
->state
))
5597 if (!(pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
)))
5600 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
5601 i40e_fdir_flush_and_replay(pf
);
5603 i40e_fdir_check_and_reenable(pf
);
5608 * i40e_vsi_link_event - notify VSI of a link event
5609 * @vsi: vsi to be notified
5610 * @link_up: link up or down
5612 static void i40e_vsi_link_event(struct i40e_vsi
*vsi
, bool link_up
)
5614 if (!vsi
|| test_bit(__I40E_DOWN
, &vsi
->state
))
5617 switch (vsi
->type
) {
5622 if (!vsi
->netdev
|| !vsi
->netdev_registered
)
5626 netif_carrier_on(vsi
->netdev
);
5627 netif_tx_wake_all_queues(vsi
->netdev
);
5629 netif_carrier_off(vsi
->netdev
);
5630 netif_tx_stop_all_queues(vsi
->netdev
);
5634 case I40E_VSI_SRIOV
:
5635 case I40E_VSI_VMDQ2
:
5637 case I40E_VSI_MIRROR
:
5639 /* there is no notification for other VSIs */
5645 * i40e_veb_link_event - notify elements on the veb of a link event
5646 * @veb: veb to be notified
5647 * @link_up: link up or down
5649 static void i40e_veb_link_event(struct i40e_veb
*veb
, bool link_up
)
5654 if (!veb
|| !veb
->pf
)
5658 /* depth first... */
5659 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
5660 if (pf
->veb
[i
] && (pf
->veb
[i
]->uplink_seid
== veb
->seid
))
5661 i40e_veb_link_event(pf
->veb
[i
], link_up
);
5663 /* ... now the local VSIs */
5664 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
5665 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->uplink_seid
== veb
->seid
))
5666 i40e_vsi_link_event(pf
->vsi
[i
], link_up
);
5670 * i40e_link_event - Update netif_carrier status
5671 * @pf: board private structure
5673 static void i40e_link_event(struct i40e_pf
*pf
)
5675 bool new_link
, old_link
;
5676 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
5677 u8 new_link_speed
, old_link_speed
;
5679 /* set this to force the get_link_status call to refresh state */
5680 pf
->hw
.phy
.get_link_info
= true;
5682 old_link
= (pf
->hw
.phy
.link_info_old
.link_info
& I40E_AQ_LINK_UP
);
5683 new_link
= i40e_get_link_status(&pf
->hw
);
5684 old_link_speed
= pf
->hw
.phy
.link_info_old
.link_speed
;
5685 new_link_speed
= pf
->hw
.phy
.link_info
.link_speed
;
5687 if (new_link
== old_link
&&
5688 new_link_speed
== old_link_speed
&&
5689 (test_bit(__I40E_DOWN
, &vsi
->state
) ||
5690 new_link
== netif_carrier_ok(vsi
->netdev
)))
5693 if (!test_bit(__I40E_DOWN
, &vsi
->state
))
5694 i40e_print_link_message(vsi
, new_link
);
5696 /* Notify the base of the switch tree connected to
5697 * the link. Floating VEBs are not notified.
5699 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
5700 i40e_veb_link_event(pf
->veb
[pf
->lan_veb
], new_link
);
5702 i40e_vsi_link_event(vsi
, new_link
);
5705 i40e_vc_notify_link_state(pf
);
5707 if (pf
->flags
& I40E_FLAG_PTP
)
5708 i40e_ptp_set_increment(pf
);
5712 * i40e_check_hang_subtask - Check for hung queues and dropped interrupts
5713 * @pf: board private structure
5715 * Set the per-queue flags to request a check for stuck queues in the irq
5716 * clean functions, then force interrupts to be sure the irq clean is called.
5718 static void i40e_check_hang_subtask(struct i40e_pf
*pf
)
5722 /* If we're down or resetting, just bail */
5723 if (test_bit(__I40E_DOWN
, &pf
->state
) ||
5724 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
5727 /* for each VSI/netdev
5729 * set the check flag
5731 * force an interrupt
5733 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5734 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
5738 test_bit(__I40E_DOWN
, &vsi
->state
) ||
5739 (vsi
->netdev
&& !netif_carrier_ok(vsi
->netdev
)))
5742 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
5743 set_check_for_tx_hang(vsi
->tx_rings
[i
]);
5744 if (test_bit(__I40E_HANG_CHECK_ARMED
,
5745 &vsi
->tx_rings
[i
]->state
))
5750 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
)) {
5751 wr32(&vsi
->back
->hw
, I40E_PFINT_DYN_CTL0
,
5752 (I40E_PFINT_DYN_CTL0_INTENA_MASK
|
5753 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK
|
5754 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK
|
5755 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK
|
5756 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK
));
5758 u16 vec
= vsi
->base_vector
- 1;
5759 u32 val
= (I40E_PFINT_DYN_CTLN_INTENA_MASK
|
5760 I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK
|
5761 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK
|
5762 I40E_PFINT_DYN_CTLN_SW_ITR_INDX_ENA_MASK
|
5763 I40E_PFINT_DYN_CTLN_SW_ITR_INDX_MASK
);
5764 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vec
++)
5765 wr32(&vsi
->back
->hw
,
5766 I40E_PFINT_DYN_CTLN(vec
), val
);
5768 i40e_flush(&vsi
->back
->hw
);
5774 * i40e_watchdog_subtask - periodic checks not using event driven response
5775 * @pf: board private structure
5777 static void i40e_watchdog_subtask(struct i40e_pf
*pf
)
5781 /* if interface is down do nothing */
5782 if (test_bit(__I40E_DOWN
, &pf
->state
) ||
5783 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
5786 /* make sure we don't do these things too often */
5787 if (time_before(jiffies
, (pf
->service_timer_previous
+
5788 pf
->service_timer_period
)))
5790 pf
->service_timer_previous
= jiffies
;
5792 i40e_check_hang_subtask(pf
);
5793 i40e_link_event(pf
);
5795 /* Update the stats for active netdevs so the network stack
5796 * can look at updated numbers whenever it cares to
5798 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
5799 if (pf
->vsi
[i
] && pf
->vsi
[i
]->netdev
)
5800 i40e_update_stats(pf
->vsi
[i
]);
5802 /* Update the stats for the active switching components */
5803 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
5805 i40e_update_veb_stats(pf
->veb
[i
]);
5807 i40e_ptp_rx_hang(pf
->vsi
[pf
->lan_vsi
]);
5811 * i40e_reset_subtask - Set up for resetting the device and driver
5812 * @pf: board private structure
5814 static void i40e_reset_subtask(struct i40e_pf
*pf
)
5816 u32 reset_flags
= 0;
5819 if (test_bit(__I40E_REINIT_REQUESTED
, &pf
->state
)) {
5820 reset_flags
|= BIT_ULL(__I40E_REINIT_REQUESTED
);
5821 clear_bit(__I40E_REINIT_REQUESTED
, &pf
->state
);
5823 if (test_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
)) {
5824 reset_flags
|= BIT_ULL(__I40E_PF_RESET_REQUESTED
);
5825 clear_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
5827 if (test_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
)) {
5828 reset_flags
|= BIT_ULL(__I40E_CORE_RESET_REQUESTED
);
5829 clear_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
);
5831 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
)) {
5832 reset_flags
|= BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED
);
5833 clear_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
);
5835 if (test_bit(__I40E_DOWN_REQUESTED
, &pf
->state
)) {
5836 reset_flags
|= BIT_ULL(__I40E_DOWN_REQUESTED
);
5837 clear_bit(__I40E_DOWN_REQUESTED
, &pf
->state
);
5840 /* If there's a recovery already waiting, it takes
5841 * precedence before starting a new reset sequence.
5843 if (test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
)) {
5844 i40e_handle_reset_warning(pf
);
5848 /* If we're already down or resetting, just bail */
5850 !test_bit(__I40E_DOWN
, &pf
->state
) &&
5851 !test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
5852 i40e_do_reset(pf
, reset_flags
);
5859 * i40e_handle_link_event - Handle link event
5860 * @pf: board private structure
5861 * @e: event info posted on ARQ
5863 static void i40e_handle_link_event(struct i40e_pf
*pf
,
5864 struct i40e_arq_event_info
*e
)
5866 struct i40e_hw
*hw
= &pf
->hw
;
5867 struct i40e_aqc_get_link_status
*status
=
5868 (struct i40e_aqc_get_link_status
*)&e
->desc
.params
.raw
;
5870 /* save off old link status information */
5871 hw
->phy
.link_info_old
= hw
->phy
.link_info
;
5873 /* Do a new status request to re-enable LSE reporting
5874 * and load new status information into the hw struct
5875 * This completely ignores any state information
5876 * in the ARQ event info, instead choosing to always
5877 * issue the AQ update link status command.
5879 i40e_link_event(pf
);
5881 /* check for unqualified module, if link is down */
5882 if ((status
->link_info
& I40E_AQ_MEDIA_AVAILABLE
) &&
5883 (!(status
->an_info
& I40E_AQ_QUALIFIED_MODULE
)) &&
5884 (!(status
->link_info
& I40E_AQ_LINK_UP
)))
5885 dev_err(&pf
->pdev
->dev
,
5886 "The driver failed to link because an unqualified module was detected.\n");
5890 * i40e_clean_adminq_subtask - Clean the AdminQ rings
5891 * @pf: board private structure
5893 static void i40e_clean_adminq_subtask(struct i40e_pf
*pf
)
5895 struct i40e_arq_event_info event
;
5896 struct i40e_hw
*hw
= &pf
->hw
;
5903 /* Do not run clean AQ when PF reset fails */
5904 if (test_bit(__I40E_RESET_FAILED
, &pf
->state
))
5907 /* check for error indications */
5908 val
= rd32(&pf
->hw
, pf
->hw
.aq
.arq
.len
);
5910 if (val
& I40E_PF_ARQLEN_ARQVFE_MASK
) {
5911 dev_info(&pf
->pdev
->dev
, "ARQ VF Error detected\n");
5912 val
&= ~I40E_PF_ARQLEN_ARQVFE_MASK
;
5914 if (val
& I40E_PF_ARQLEN_ARQOVFL_MASK
) {
5915 dev_info(&pf
->pdev
->dev
, "ARQ Overflow Error detected\n");
5916 val
&= ~I40E_PF_ARQLEN_ARQOVFL_MASK
;
5918 if (val
& I40E_PF_ARQLEN_ARQCRIT_MASK
) {
5919 dev_info(&pf
->pdev
->dev
, "ARQ Critical Error detected\n");
5920 val
&= ~I40E_PF_ARQLEN_ARQCRIT_MASK
;
5923 wr32(&pf
->hw
, pf
->hw
.aq
.arq
.len
, val
);
5925 val
= rd32(&pf
->hw
, pf
->hw
.aq
.asq
.len
);
5927 if (val
& I40E_PF_ATQLEN_ATQVFE_MASK
) {
5928 dev_info(&pf
->pdev
->dev
, "ASQ VF Error detected\n");
5929 val
&= ~I40E_PF_ATQLEN_ATQVFE_MASK
;
5931 if (val
& I40E_PF_ATQLEN_ATQOVFL_MASK
) {
5932 dev_info(&pf
->pdev
->dev
, "ASQ Overflow Error detected\n");
5933 val
&= ~I40E_PF_ATQLEN_ATQOVFL_MASK
;
5935 if (val
& I40E_PF_ATQLEN_ATQCRIT_MASK
) {
5936 dev_info(&pf
->pdev
->dev
, "ASQ Critical Error detected\n");
5937 val
&= ~I40E_PF_ATQLEN_ATQCRIT_MASK
;
5940 wr32(&pf
->hw
, pf
->hw
.aq
.asq
.len
, val
);
5942 event
.buf_len
= I40E_MAX_AQ_BUF_SIZE
;
5943 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
5948 ret
= i40e_clean_arq_element(hw
, &event
, &pending
);
5949 if (ret
== I40E_ERR_ADMIN_QUEUE_NO_WORK
)
5952 dev_info(&pf
->pdev
->dev
, "ARQ event error %d\n", ret
);
5956 opcode
= le16_to_cpu(event
.desc
.opcode
);
5959 case i40e_aqc_opc_get_link_status
:
5960 i40e_handle_link_event(pf
, &event
);
5962 case i40e_aqc_opc_send_msg_to_pf
:
5963 ret
= i40e_vc_process_vf_msg(pf
,
5964 le16_to_cpu(event
.desc
.retval
),
5965 le32_to_cpu(event
.desc
.cookie_high
),
5966 le32_to_cpu(event
.desc
.cookie_low
),
5970 case i40e_aqc_opc_lldp_update_mib
:
5971 dev_dbg(&pf
->pdev
->dev
, "ARQ: Update LLDP MIB event received\n");
5972 #ifdef CONFIG_I40E_DCB
5974 ret
= i40e_handle_lldp_event(pf
, &event
);
5976 #endif /* CONFIG_I40E_DCB */
5978 case i40e_aqc_opc_event_lan_overflow
:
5979 dev_dbg(&pf
->pdev
->dev
, "ARQ LAN queue overflow event received\n");
5980 i40e_handle_lan_overflow_event(pf
, &event
);
5982 case i40e_aqc_opc_send_msg_to_peer
:
5983 dev_info(&pf
->pdev
->dev
, "ARQ: Msg from other pf\n");
5985 case i40e_aqc_opc_nvm_erase
:
5986 case i40e_aqc_opc_nvm_update
:
5987 i40e_debug(&pf
->hw
, I40E_DEBUG_NVM
, "ARQ NVM operation completed\n");
5990 dev_info(&pf
->pdev
->dev
,
5991 "ARQ Error: Unknown event 0x%04x received\n",
5995 } while (pending
&& (i
++ < pf
->adminq_work_limit
));
5997 clear_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
);
5998 /* re-enable Admin queue interrupt cause */
5999 val
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
6000 val
|= I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
6001 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
6004 kfree(event
.msg_buf
);
6008 * i40e_verify_eeprom - make sure eeprom is good to use
6009 * @pf: board private structure
6011 static void i40e_verify_eeprom(struct i40e_pf
*pf
)
6015 err
= i40e_diag_eeprom_test(&pf
->hw
);
6017 /* retry in case of garbage read */
6018 err
= i40e_diag_eeprom_test(&pf
->hw
);
6020 dev_info(&pf
->pdev
->dev
, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
6022 set_bit(__I40E_BAD_EEPROM
, &pf
->state
);
6026 if (!err
&& test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
6027 dev_info(&pf
->pdev
->dev
, "eeprom check passed, Tx/Rx traffic enabled\n");
6028 clear_bit(__I40E_BAD_EEPROM
, &pf
->state
);
6033 * i40e_enable_pf_switch_lb
6034 * @pf: pointer to the PF structure
6036 * enable switch loop back or die - no point in a return value
6038 static void i40e_enable_pf_switch_lb(struct i40e_pf
*pf
)
6040 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
6041 struct i40e_vsi_context ctxt
;
6044 ctxt
.seid
= pf
->main_vsi_seid
;
6045 ctxt
.pf_num
= pf
->hw
.pf_id
;
6047 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
6049 dev_info(&pf
->pdev
->dev
,
6050 "couldn't get PF vsi config, 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
));
6055 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
6056 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
6057 ctxt
.info
.switch_id
|= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
6059 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
6061 dev_info(&pf
->pdev
->dev
,
6062 "update vsi switch failed, err %s aq_err %s\n",
6063 i40e_stat_str(&pf
->hw
, ret
),
6064 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6069 * i40e_disable_pf_switch_lb
6070 * @pf: pointer to the PF structure
6072 * disable switch loop back or die - no point in a return value
6074 static void i40e_disable_pf_switch_lb(struct i40e_pf
*pf
)
6076 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
6077 struct i40e_vsi_context ctxt
;
6080 ctxt
.seid
= pf
->main_vsi_seid
;
6081 ctxt
.pf_num
= pf
->hw
.pf_id
;
6083 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
6085 dev_info(&pf
->pdev
->dev
,
6086 "couldn't get PF vsi config, 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
));
6091 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
6092 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
6093 ctxt
.info
.switch_id
&= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
6095 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
6097 dev_info(&pf
->pdev
->dev
,
6098 "update vsi switch failed, err %s aq_err %s\n",
6099 i40e_stat_str(&pf
->hw
, ret
),
6100 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6105 * i40e_config_bridge_mode - Configure the HW bridge mode
6106 * @veb: pointer to the bridge instance
6108 * Configure the loop back mode for the LAN VSI that is downlink to the
6109 * specified HW bridge instance. It is expected this function is called
6110 * when a new HW bridge is instantiated.
6112 static void i40e_config_bridge_mode(struct i40e_veb
*veb
)
6114 struct i40e_pf
*pf
= veb
->pf
;
6116 dev_info(&pf
->pdev
->dev
, "enabling bridge mode: %s\n",
6117 veb
->bridge_mode
== BRIDGE_MODE_VEPA
? "VEPA" : "VEB");
6118 if (veb
->bridge_mode
& BRIDGE_MODE_VEPA
)
6119 i40e_disable_pf_switch_lb(pf
);
6121 i40e_enable_pf_switch_lb(pf
);
6125 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
6126 * @veb: pointer to the VEB instance
6128 * This is a recursive function that first builds the attached VSIs then
6129 * recurses in to build the next layer of VEB. We track the connections
6130 * through our own index numbers because the seid's from the HW could
6131 * change across the reset.
6133 static int i40e_reconstitute_veb(struct i40e_veb
*veb
)
6135 struct i40e_vsi
*ctl_vsi
= NULL
;
6136 struct i40e_pf
*pf
= veb
->pf
;
6140 /* build VSI that owns this VEB, temporarily attached to base VEB */
6141 for (v
= 0; v
< pf
->num_alloc_vsi
&& !ctl_vsi
; v
++) {
6143 pf
->vsi
[v
]->veb_idx
== veb
->idx
&&
6144 pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
6145 ctl_vsi
= pf
->vsi
[v
];
6150 dev_info(&pf
->pdev
->dev
,
6151 "missing owner VSI for veb_idx %d\n", veb
->idx
);
6153 goto end_reconstitute
;
6155 if (ctl_vsi
!= pf
->vsi
[pf
->lan_vsi
])
6156 ctl_vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
6157 ret
= i40e_add_vsi(ctl_vsi
);
6159 dev_info(&pf
->pdev
->dev
,
6160 "rebuild of veb_idx %d owner VSI failed: %d\n",
6162 goto end_reconstitute
;
6164 i40e_vsi_reset_stats(ctl_vsi
);
6166 /* create the VEB in the switch and move the VSI onto the VEB */
6167 ret
= i40e_add_veb(veb
, ctl_vsi
);
6169 goto end_reconstitute
;
6171 if (pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)
6172 veb
->bridge_mode
= BRIDGE_MODE_VEB
;
6174 veb
->bridge_mode
= BRIDGE_MODE_VEPA
;
6175 i40e_config_bridge_mode(veb
);
6177 /* create the remaining VSIs attached to this VEB */
6178 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
6179 if (!pf
->vsi
[v
] || pf
->vsi
[v
] == ctl_vsi
)
6182 if (pf
->vsi
[v
]->veb_idx
== veb
->idx
) {
6183 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
6184 vsi
->uplink_seid
= veb
->seid
;
6185 ret
= i40e_add_vsi(vsi
);
6187 dev_info(&pf
->pdev
->dev
,
6188 "rebuild of vsi_idx %d failed: %d\n",
6190 goto end_reconstitute
;
6192 i40e_vsi_reset_stats(vsi
);
6196 /* create any VEBs attached to this VEB - RECURSION */
6197 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
6198 if (pf
->veb
[veb_idx
] && pf
->veb
[veb_idx
]->veb_idx
== veb
->idx
) {
6199 pf
->veb
[veb_idx
]->uplink_seid
= veb
->seid
;
6200 ret
= i40e_reconstitute_veb(pf
->veb
[veb_idx
]);
6211 * i40e_get_capabilities - get info about the HW
6212 * @pf: the PF struct
6214 static int i40e_get_capabilities(struct i40e_pf
*pf
)
6216 struct i40e_aqc_list_capabilities_element_resp
*cap_buf
;
6221 buf_len
= 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp
);
6223 cap_buf
= kzalloc(buf_len
, GFP_KERNEL
);
6227 /* this loads the data into the hw struct for us */
6228 err
= i40e_aq_discover_capabilities(&pf
->hw
, cap_buf
, buf_len
,
6230 i40e_aqc_opc_list_func_capabilities
,
6232 /* data loaded, buffer no longer needed */
6235 if (pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_ENOMEM
) {
6236 /* retry with a larger buffer */
6237 buf_len
= data_size
;
6238 } else if (pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_OK
) {
6239 dev_info(&pf
->pdev
->dev
,
6240 "capability discovery failed, err %s aq_err %s\n",
6241 i40e_stat_str(&pf
->hw
, err
),
6242 i40e_aq_str(&pf
->hw
,
6243 pf
->hw
.aq
.asq_last_status
));
6248 if (((pf
->hw
.aq
.fw_maj_ver
== 2) && (pf
->hw
.aq
.fw_min_ver
< 22)) ||
6249 (pf
->hw
.aq
.fw_maj_ver
< 2)) {
6250 pf
->hw
.func_caps
.num_msix_vectors
++;
6251 pf
->hw
.func_caps
.num_msix_vectors_vf
++;
6254 if (pf
->hw
.debug_mask
& I40E_DEBUG_USER
)
6255 dev_info(&pf
->pdev
->dev
,
6256 "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",
6257 pf
->hw
.pf_id
, pf
->hw
.func_caps
.num_vfs
,
6258 pf
->hw
.func_caps
.num_msix_vectors
,
6259 pf
->hw
.func_caps
.num_msix_vectors_vf
,
6260 pf
->hw
.func_caps
.fd_filters_guaranteed
,
6261 pf
->hw
.func_caps
.fd_filters_best_effort
,
6262 pf
->hw
.func_caps
.num_tx_qp
,
6263 pf
->hw
.func_caps
.num_vsis
);
6265 #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
6266 + pf->hw.func_caps.num_vfs)
6267 if (pf
->hw
.revision_id
== 0 && (DEF_NUM_VSI
> pf
->hw
.func_caps
.num_vsis
)) {
6268 dev_info(&pf
->pdev
->dev
,
6269 "got num_vsis %d, setting num_vsis to %d\n",
6270 pf
->hw
.func_caps
.num_vsis
, DEF_NUM_VSI
);
6271 pf
->hw
.func_caps
.num_vsis
= DEF_NUM_VSI
;
6277 static int i40e_vsi_clear(struct i40e_vsi
*vsi
);
6280 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
6281 * @pf: board private structure
6283 static void i40e_fdir_sb_setup(struct i40e_pf
*pf
)
6285 struct i40e_vsi
*vsi
;
6288 /* quick workaround for an NVM issue that leaves a critical register
6291 if (!rd32(&pf
->hw
, I40E_GLQF_HKEY(0))) {
6292 static const u32 hkey
[] = {
6293 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
6294 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
6295 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
6298 for (i
= 0; i
<= I40E_GLQF_HKEY_MAX_INDEX
; i
++)
6299 wr32(&pf
->hw
, I40E_GLQF_HKEY(i
), hkey
[i
]);
6302 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
6305 /* find existing VSI and see if it needs configuring */
6307 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
6308 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
6314 /* create a new VSI if none exists */
6316 vsi
= i40e_vsi_setup(pf
, I40E_VSI_FDIR
,
6317 pf
->vsi
[pf
->lan_vsi
]->seid
, 0);
6319 dev_info(&pf
->pdev
->dev
, "Couldn't create FDir VSI\n");
6320 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
6325 i40e_vsi_setup_irqhandler(vsi
, i40e_fdir_clean_ring
);
6329 * i40e_fdir_teardown - release the Flow Director resources
6330 * @pf: board private structure
6332 static void i40e_fdir_teardown(struct i40e_pf
*pf
)
6336 i40e_fdir_filter_exit(pf
);
6337 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
6338 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
6339 i40e_vsi_release(pf
->vsi
[i
]);
6346 * i40e_prep_for_reset - prep for the core to reset
6347 * @pf: board private structure
6349 * Close up the VFs and other things in prep for PF Reset.
6351 static void i40e_prep_for_reset(struct i40e_pf
*pf
)
6353 struct i40e_hw
*hw
= &pf
->hw
;
6354 i40e_status ret
= 0;
6357 clear_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
);
6358 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
))
6361 dev_dbg(&pf
->pdev
->dev
, "Tearing down internal switch for reset\n");
6363 /* quiesce the VSIs and their queues that are not already DOWN */
6364 i40e_pf_quiesce_all_vsi(pf
);
6366 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
6368 pf
->vsi
[v
]->seid
= 0;
6371 i40e_shutdown_adminq(&pf
->hw
);
6373 /* call shutdown HMC */
6374 if (hw
->hmc
.hmc_obj
) {
6375 ret
= i40e_shutdown_lan_hmc(hw
);
6377 dev_warn(&pf
->pdev
->dev
,
6378 "shutdown_lan_hmc failed: %d\n", ret
);
6383 * i40e_send_version - update firmware with driver version
6386 static void i40e_send_version(struct i40e_pf
*pf
)
6388 struct i40e_driver_version dv
;
6390 dv
.major_version
= DRV_VERSION_MAJOR
;
6391 dv
.minor_version
= DRV_VERSION_MINOR
;
6392 dv
.build_version
= DRV_VERSION_BUILD
;
6393 dv
.subbuild_version
= 0;
6394 strlcpy(dv
.driver_string
, DRV_VERSION
, sizeof(dv
.driver_string
));
6395 i40e_aq_send_driver_version(&pf
->hw
, &dv
, NULL
);
6399 * i40e_reset_and_rebuild - reset and rebuild using a saved config
6400 * @pf: board private structure
6401 * @reinit: if the Main VSI needs to re-initialized.
6403 static void i40e_reset_and_rebuild(struct i40e_pf
*pf
, bool reinit
)
6405 struct i40e_hw
*hw
= &pf
->hw
;
6406 u8 set_fc_aq_fail
= 0;
6410 /* Now we wait for GRST to settle out.
6411 * We don't have to delete the VEBs or VSIs from the hw switch
6412 * because the reset will make them disappear.
6414 ret
= i40e_pf_reset(hw
);
6416 dev_info(&pf
->pdev
->dev
, "PF reset failed, %d\n", ret
);
6417 set_bit(__I40E_RESET_FAILED
, &pf
->state
);
6418 goto clear_recovery
;
6422 if (test_bit(__I40E_DOWN
, &pf
->state
))
6423 goto clear_recovery
;
6424 dev_dbg(&pf
->pdev
->dev
, "Rebuilding internal switch\n");
6426 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
6427 ret
= i40e_init_adminq(&pf
->hw
);
6429 dev_info(&pf
->pdev
->dev
, "Rebuild AdminQ failed, err %s aq_err %s\n",
6430 i40e_stat_str(&pf
->hw
, ret
),
6431 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6432 goto clear_recovery
;
6435 /* re-verify the eeprom if we just had an EMP reset */
6436 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED
, &pf
->state
))
6437 i40e_verify_eeprom(pf
);
6439 i40e_clear_pxe_mode(hw
);
6440 ret
= i40e_get_capabilities(pf
);
6442 goto end_core_reset
;
6444 ret
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
6445 hw
->func_caps
.num_rx_qp
,
6446 pf
->fcoe_hmc_cntx_num
, pf
->fcoe_hmc_filt_num
);
6448 dev_info(&pf
->pdev
->dev
, "init_lan_hmc failed: %d\n", ret
);
6449 goto end_core_reset
;
6451 ret
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
6453 dev_info(&pf
->pdev
->dev
, "configure_lan_hmc failed: %d\n", ret
);
6454 goto end_core_reset
;
6457 #ifdef CONFIG_I40E_DCB
6458 ret
= i40e_init_pf_dcb(pf
);
6460 dev_info(&pf
->pdev
->dev
, "DCB init failed %d, disabled\n", ret
);
6461 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
6462 /* Continue without DCB enabled */
6464 #endif /* CONFIG_I40E_DCB */
6466 ret
= i40e_init_pf_fcoe(pf
);
6468 dev_info(&pf
->pdev
->dev
, "init_pf_fcoe failed: %d\n", ret
);
6471 /* do basic switch setup */
6472 ret
= i40e_setup_pf_switch(pf
, reinit
);
6474 goto end_core_reset
;
6476 /* driver is only interested in link up/down and module qualification
6477 * reports from firmware
6479 ret
= i40e_aq_set_phy_int_mask(&pf
->hw
,
6480 I40E_AQ_EVENT_LINK_UPDOWN
|
6481 I40E_AQ_EVENT_MODULE_QUAL_FAIL
, NULL
);
6483 dev_info(&pf
->pdev
->dev
, "set phy mask fail, err %s aq_err %s\n",
6484 i40e_stat_str(&pf
->hw
, ret
),
6485 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6487 /* make sure our flow control settings are restored */
6488 ret
= i40e_set_fc(&pf
->hw
, &set_fc_aq_fail
, true);
6490 dev_info(&pf
->pdev
->dev
, "set fc fail, err %s aq_err %s\n",
6491 i40e_stat_str(&pf
->hw
, ret
),
6492 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
6494 /* Rebuild the VSIs and VEBs that existed before reset.
6495 * They are still in our local switch element arrays, so only
6496 * need to rebuild the switch model in the HW.
6498 * If there were VEBs but the reconstitution failed, we'll try
6499 * try to recover minimal use by getting the basic PF VSI working.
6501 if (pf
->vsi
[pf
->lan_vsi
]->uplink_seid
!= pf
->mac_seid
) {
6502 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild switch\n");
6503 /* find the one VEB connected to the MAC, and find orphans */
6504 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
6508 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
||
6509 pf
->veb
[v
]->uplink_seid
== 0) {
6510 ret
= i40e_reconstitute_veb(pf
->veb
[v
]);
6515 /* If Main VEB failed, we're in deep doodoo,
6516 * so give up rebuilding the switch and set up
6517 * for minimal rebuild of PF VSI.
6518 * If orphan failed, we'll report the error
6519 * but try to keep going.
6521 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
) {
6522 dev_info(&pf
->pdev
->dev
,
6523 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
6525 pf
->vsi
[pf
->lan_vsi
]->uplink_seid
6528 } else if (pf
->veb
[v
]->uplink_seid
== 0) {
6529 dev_info(&pf
->pdev
->dev
,
6530 "rebuild of orphan VEB failed: %d\n",
6537 if (pf
->vsi
[pf
->lan_vsi
]->uplink_seid
== pf
->mac_seid
) {
6538 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild PF VSI\n");
6539 /* no VEB, so rebuild only the Main VSI */
6540 ret
= i40e_add_vsi(pf
->vsi
[pf
->lan_vsi
]);
6542 dev_info(&pf
->pdev
->dev
,
6543 "rebuild of Main VSI failed: %d\n", ret
);
6544 goto end_core_reset
;
6548 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
6549 (pf
->hw
.aq
.fw_maj_ver
< 4)) {
6551 ret
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
6553 dev_info(&pf
->pdev
->dev
, "link restart failed, err %s aq_err %s\n",
6554 i40e_stat_str(&pf
->hw
, ret
),
6555 i40e_aq_str(&pf
->hw
,
6556 pf
->hw
.aq
.asq_last_status
));
6558 /* reinit the misc interrupt */
6559 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
6560 ret
= i40e_setup_misc_vector(pf
);
6562 /* restart the VSIs that were rebuilt and running before the reset */
6563 i40e_pf_unquiesce_all_vsi(pf
);
6565 if (pf
->num_alloc_vfs
) {
6566 for (v
= 0; v
< pf
->num_alloc_vfs
; v
++)
6567 i40e_reset_vf(&pf
->vf
[v
], true);
6570 /* tell the firmware that we're starting */
6571 i40e_send_version(pf
);
6574 clear_bit(__I40E_RESET_FAILED
, &pf
->state
);
6576 clear_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
);
6580 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
6581 * @pf: board private structure
6583 * Close up the VFs and other things in prep for a Core Reset,
6584 * then get ready to rebuild the world.
6586 static void i40e_handle_reset_warning(struct i40e_pf
*pf
)
6588 i40e_prep_for_reset(pf
);
6589 i40e_reset_and_rebuild(pf
, false);
6593 * i40e_handle_mdd_event
6594 * @pf: pointer to the PF structure
6596 * Called from the MDD irq handler to identify possibly malicious vfs
6598 static void i40e_handle_mdd_event(struct i40e_pf
*pf
)
6600 struct i40e_hw
*hw
= &pf
->hw
;
6601 bool mdd_detected
= false;
6602 bool pf_mdd_detected
= false;
6607 if (!test_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
))
6610 /* find what triggered the MDD event */
6611 reg
= rd32(hw
, I40E_GL_MDET_TX
);
6612 if (reg
& I40E_GL_MDET_TX_VALID_MASK
) {
6613 u8 pf_num
= (reg
& I40E_GL_MDET_TX_PF_NUM_MASK
) >>
6614 I40E_GL_MDET_TX_PF_NUM_SHIFT
;
6615 u16 vf_num
= (reg
& I40E_GL_MDET_TX_VF_NUM_MASK
) >>
6616 I40E_GL_MDET_TX_VF_NUM_SHIFT
;
6617 u8 event
= (reg
& I40E_GL_MDET_TX_EVENT_MASK
) >>
6618 I40E_GL_MDET_TX_EVENT_SHIFT
;
6619 u16 queue
= ((reg
& I40E_GL_MDET_TX_QUEUE_MASK
) >>
6620 I40E_GL_MDET_TX_QUEUE_SHIFT
) -
6621 pf
->hw
.func_caps
.base_queue
;
6622 if (netif_msg_tx_err(pf
))
6623 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
6624 event
, queue
, pf_num
, vf_num
);
6625 wr32(hw
, I40E_GL_MDET_TX
, 0xffffffff);
6626 mdd_detected
= true;
6628 reg
= rd32(hw
, I40E_GL_MDET_RX
);
6629 if (reg
& I40E_GL_MDET_RX_VALID_MASK
) {
6630 u8 func
= (reg
& I40E_GL_MDET_RX_FUNCTION_MASK
) >>
6631 I40E_GL_MDET_RX_FUNCTION_SHIFT
;
6632 u8 event
= (reg
& I40E_GL_MDET_RX_EVENT_MASK
) >>
6633 I40E_GL_MDET_RX_EVENT_SHIFT
;
6634 u16 queue
= ((reg
& I40E_GL_MDET_RX_QUEUE_MASK
) >>
6635 I40E_GL_MDET_RX_QUEUE_SHIFT
) -
6636 pf
->hw
.func_caps
.base_queue
;
6637 if (netif_msg_rx_err(pf
))
6638 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
6639 event
, queue
, func
);
6640 wr32(hw
, I40E_GL_MDET_RX
, 0xffffffff);
6641 mdd_detected
= true;
6645 reg
= rd32(hw
, I40E_PF_MDET_TX
);
6646 if (reg
& I40E_PF_MDET_TX_VALID_MASK
) {
6647 wr32(hw
, I40E_PF_MDET_TX
, 0xFFFF);
6648 dev_info(&pf
->pdev
->dev
, "TX driver issue detected, PF reset issued\n");
6649 pf_mdd_detected
= true;
6651 reg
= rd32(hw
, I40E_PF_MDET_RX
);
6652 if (reg
& I40E_PF_MDET_RX_VALID_MASK
) {
6653 wr32(hw
, I40E_PF_MDET_RX
, 0xFFFF);
6654 dev_info(&pf
->pdev
->dev
, "RX driver issue detected, PF reset issued\n");
6655 pf_mdd_detected
= true;
6657 /* Queue belongs to the PF, initiate a reset */
6658 if (pf_mdd_detected
) {
6659 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
6660 i40e_service_event_schedule(pf
);
6664 /* see if one of the VFs needs its hand slapped */
6665 for (i
= 0; i
< pf
->num_alloc_vfs
&& mdd_detected
; i
++) {
6667 reg
= rd32(hw
, I40E_VP_MDET_TX(i
));
6668 if (reg
& I40E_VP_MDET_TX_VALID_MASK
) {
6669 wr32(hw
, I40E_VP_MDET_TX(i
), 0xFFFF);
6670 vf
->num_mdd_events
++;
6671 dev_info(&pf
->pdev
->dev
, "TX driver issue detected on VF %d\n",
6675 reg
= rd32(hw
, I40E_VP_MDET_RX(i
));
6676 if (reg
& I40E_VP_MDET_RX_VALID_MASK
) {
6677 wr32(hw
, I40E_VP_MDET_RX(i
), 0xFFFF);
6678 vf
->num_mdd_events
++;
6679 dev_info(&pf
->pdev
->dev
, "RX driver issue detected on VF %d\n",
6683 if (vf
->num_mdd_events
> I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED
) {
6684 dev_info(&pf
->pdev
->dev
,
6685 "Too many MDD events on VF %d, disabled\n", i
);
6686 dev_info(&pf
->pdev
->dev
,
6687 "Use PF Control I/F to re-enable the VF\n");
6688 set_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
);
6692 /* re-enable mdd interrupt cause */
6693 clear_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
);
6694 reg
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
6695 reg
|= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
6696 wr32(hw
, I40E_PFINT_ICR0_ENA
, reg
);
6700 #ifdef CONFIG_I40E_VXLAN
6702 * i40e_sync_vxlan_filters_subtask - Sync the VSI filter list with HW
6703 * @pf: board private structure
6705 static void i40e_sync_vxlan_filters_subtask(struct i40e_pf
*pf
)
6707 struct i40e_hw
*hw
= &pf
->hw
;
6712 if (!(pf
->flags
& I40E_FLAG_VXLAN_FILTER_SYNC
))
6715 pf
->flags
&= ~I40E_FLAG_VXLAN_FILTER_SYNC
;
6717 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
6718 if (pf
->pending_vxlan_bitmap
& BIT_ULL(i
)) {
6719 pf
->pending_vxlan_bitmap
&= ~BIT_ULL(i
);
6720 port
= pf
->vxlan_ports
[i
];
6722 ret
= i40e_aq_add_udp_tunnel(hw
, ntohs(port
),
6723 I40E_AQC_TUNNEL_TYPE_VXLAN
,
6726 ret
= i40e_aq_del_udp_tunnel(hw
, i
, NULL
);
6729 dev_info(&pf
->pdev
->dev
,
6730 "%s vxlan port %d, index %d failed, err %s aq_err %s\n",
6731 port
? "add" : "delete",
6733 i40e_stat_str(&pf
->hw
, ret
),
6734 i40e_aq_str(&pf
->hw
,
6735 pf
->hw
.aq
.asq_last_status
));
6736 pf
->vxlan_ports
[i
] = 0;
6744 * i40e_service_task - Run the driver's async subtasks
6745 * @work: pointer to work_struct containing our data
6747 static void i40e_service_task(struct work_struct
*work
)
6749 struct i40e_pf
*pf
= container_of(work
,
6752 unsigned long start_time
= jiffies
;
6754 /* don't bother with service tasks if a reset is in progress */
6755 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
)) {
6756 i40e_service_event_complete(pf
);
6760 i40e_reset_subtask(pf
);
6761 i40e_handle_mdd_event(pf
);
6762 i40e_vc_process_vflr_event(pf
);
6763 i40e_watchdog_subtask(pf
);
6764 i40e_fdir_reinit_subtask(pf
);
6765 i40e_sync_filters_subtask(pf
);
6766 #ifdef CONFIG_I40E_VXLAN
6767 i40e_sync_vxlan_filters_subtask(pf
);
6769 i40e_clean_adminq_subtask(pf
);
6771 i40e_service_event_complete(pf
);
6773 /* If the tasks have taken longer than one timer cycle or there
6774 * is more work to be done, reschedule the service task now
6775 * rather than wait for the timer to tick again.
6777 if (time_after(jiffies
, (start_time
+ pf
->service_timer_period
)) ||
6778 test_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
) ||
6779 test_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
) ||
6780 test_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
))
6781 i40e_service_event_schedule(pf
);
6785 * i40e_service_timer - timer callback
6786 * @data: pointer to PF struct
6788 static void i40e_service_timer(unsigned long data
)
6790 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
6792 mod_timer(&pf
->service_timer
,
6793 round_jiffies(jiffies
+ pf
->service_timer_period
));
6794 i40e_service_event_schedule(pf
);
6798 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
6799 * @vsi: the VSI being configured
6801 static int i40e_set_num_rings_in_vsi(struct i40e_vsi
*vsi
)
6803 struct i40e_pf
*pf
= vsi
->back
;
6805 switch (vsi
->type
) {
6807 vsi
->alloc_queue_pairs
= pf
->num_lan_qps
;
6808 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
6809 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6810 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
6811 vsi
->num_q_vectors
= pf
->num_lan_msix
;
6813 vsi
->num_q_vectors
= 1;
6818 vsi
->alloc_queue_pairs
= 1;
6819 vsi
->num_desc
= ALIGN(I40E_FDIR_RING_COUNT
,
6820 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6821 vsi
->num_q_vectors
= 1;
6824 case I40E_VSI_VMDQ2
:
6825 vsi
->alloc_queue_pairs
= pf
->num_vmdq_qps
;
6826 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
6827 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6828 vsi
->num_q_vectors
= pf
->num_vmdq_msix
;
6831 case I40E_VSI_SRIOV
:
6832 vsi
->alloc_queue_pairs
= pf
->num_vf_qps
;
6833 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
6834 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6839 vsi
->alloc_queue_pairs
= pf
->num_fcoe_qps
;
6840 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
6841 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6842 vsi
->num_q_vectors
= pf
->num_fcoe_msix
;
6845 #endif /* I40E_FCOE */
6855 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
6856 * @type: VSI pointer
6857 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
6859 * On error: returns error code (negative)
6860 * On success: returns 0
6862 static int i40e_vsi_alloc_arrays(struct i40e_vsi
*vsi
, bool alloc_qvectors
)
6867 /* allocate memory for both Tx and Rx ring pointers */
6868 size
= sizeof(struct i40e_ring
*) * vsi
->alloc_queue_pairs
* 2;
6869 vsi
->tx_rings
= kzalloc(size
, GFP_KERNEL
);
6872 vsi
->rx_rings
= &vsi
->tx_rings
[vsi
->alloc_queue_pairs
];
6874 if (alloc_qvectors
) {
6875 /* allocate memory for q_vector pointers */
6876 size
= sizeof(struct i40e_q_vector
*) * vsi
->num_q_vectors
;
6877 vsi
->q_vectors
= kzalloc(size
, GFP_KERNEL
);
6878 if (!vsi
->q_vectors
) {
6886 kfree(vsi
->tx_rings
);
6891 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
6892 * @pf: board private structure
6893 * @type: type of VSI
6895 * On error: returns error code (negative)
6896 * On success: returns vsi index in PF (positive)
6898 static int i40e_vsi_mem_alloc(struct i40e_pf
*pf
, enum i40e_vsi_type type
)
6901 struct i40e_vsi
*vsi
;
6905 /* Need to protect the allocation of the VSIs at the PF level */
6906 mutex_lock(&pf
->switch_mutex
);
6908 /* VSI list may be fragmented if VSI creation/destruction has
6909 * been happening. We can afford to do a quick scan to look
6910 * for any free VSIs in the list.
6912 * find next empty vsi slot, looping back around if necessary
6915 while (i
< pf
->num_alloc_vsi
&& pf
->vsi
[i
])
6917 if (i
>= pf
->num_alloc_vsi
) {
6919 while (i
< pf
->next_vsi
&& pf
->vsi
[i
])
6923 if (i
< pf
->num_alloc_vsi
&& !pf
->vsi
[i
]) {
6924 vsi_idx
= i
; /* Found one! */
6927 goto unlock_pf
; /* out of VSI slots! */
6931 vsi
= kzalloc(sizeof(*vsi
), GFP_KERNEL
);
6938 set_bit(__I40E_DOWN
, &vsi
->state
);
6941 vsi
->rx_itr_setting
= pf
->rx_itr_default
;
6942 vsi
->tx_itr_setting
= pf
->tx_itr_default
;
6943 vsi
->rss_table_size
= (vsi
->type
== I40E_VSI_MAIN
) ?
6944 pf
->rss_table_size
: 64;
6945 vsi
->netdev_registered
= false;
6946 vsi
->work_limit
= I40E_DEFAULT_IRQ_WORK
;
6947 INIT_LIST_HEAD(&vsi
->mac_filter_list
);
6948 vsi
->irqs_ready
= false;
6950 ret
= i40e_set_num_rings_in_vsi(vsi
);
6954 ret
= i40e_vsi_alloc_arrays(vsi
, true);
6958 /* Setup default MSIX irq handler for VSI */
6959 i40e_vsi_setup_irqhandler(vsi
, i40e_msix_clean_rings
);
6961 pf
->vsi
[vsi_idx
] = vsi
;
6966 pf
->next_vsi
= i
- 1;
6969 mutex_unlock(&pf
->switch_mutex
);
6974 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
6975 * @type: VSI pointer
6976 * @free_qvectors: a bool to specify if q_vectors need to be freed.
6978 * On error: returns error code (negative)
6979 * On success: returns 0
6981 static void i40e_vsi_free_arrays(struct i40e_vsi
*vsi
, bool free_qvectors
)
6983 /* free the ring and vector containers */
6984 if (free_qvectors
) {
6985 kfree(vsi
->q_vectors
);
6986 vsi
->q_vectors
= NULL
;
6988 kfree(vsi
->tx_rings
);
6989 vsi
->tx_rings
= NULL
;
6990 vsi
->rx_rings
= NULL
;
6994 * i40e_vsi_clear - Deallocate the VSI provided
6995 * @vsi: the VSI being un-configured
6997 static int i40e_vsi_clear(struct i40e_vsi
*vsi
)
7008 mutex_lock(&pf
->switch_mutex
);
7009 if (!pf
->vsi
[vsi
->idx
]) {
7010 dev_err(&pf
->pdev
->dev
, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
7011 vsi
->idx
, vsi
->idx
, vsi
, vsi
->type
);
7015 if (pf
->vsi
[vsi
->idx
] != vsi
) {
7016 dev_err(&pf
->pdev
->dev
,
7017 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
7018 pf
->vsi
[vsi
->idx
]->idx
,
7020 pf
->vsi
[vsi
->idx
]->type
,
7021 vsi
->idx
, vsi
, vsi
->type
);
7025 /* updates the PF for this cleared vsi */
7026 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
7027 i40e_put_lump(pf
->irq_pile
, vsi
->base_vector
, vsi
->idx
);
7029 i40e_vsi_free_arrays(vsi
, true);
7031 pf
->vsi
[vsi
->idx
] = NULL
;
7032 if (vsi
->idx
< pf
->next_vsi
)
7033 pf
->next_vsi
= vsi
->idx
;
7036 mutex_unlock(&pf
->switch_mutex
);
7044 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
7045 * @vsi: the VSI being cleaned
7047 static void i40e_vsi_clear_rings(struct i40e_vsi
*vsi
)
7051 if (vsi
->tx_rings
&& vsi
->tx_rings
[0]) {
7052 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
7053 kfree_rcu(vsi
->tx_rings
[i
], rcu
);
7054 vsi
->tx_rings
[i
] = NULL
;
7055 vsi
->rx_rings
[i
] = NULL
;
7061 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
7062 * @vsi: the VSI being configured
7064 static int i40e_alloc_rings(struct i40e_vsi
*vsi
)
7066 struct i40e_ring
*tx_ring
, *rx_ring
;
7067 struct i40e_pf
*pf
= vsi
->back
;
7070 /* Set basic values in the rings to be used later during open() */
7071 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
7072 /* allocate space for both Tx and Rx in one shot */
7073 tx_ring
= kzalloc(sizeof(struct i40e_ring
) * 2, GFP_KERNEL
);
7077 tx_ring
->queue_index
= i
;
7078 tx_ring
->reg_idx
= vsi
->base_queue
+ i
;
7079 tx_ring
->ring_active
= false;
7081 tx_ring
->netdev
= vsi
->netdev
;
7082 tx_ring
->dev
= &pf
->pdev
->dev
;
7083 tx_ring
->count
= vsi
->num_desc
;
7085 tx_ring
->dcb_tc
= 0;
7086 if (vsi
->back
->flags
& I40E_FLAG_WB_ON_ITR_CAPABLE
)
7087 tx_ring
->flags
= I40E_TXR_FLAGS_WB_ON_ITR
;
7088 if (vsi
->back
->flags
& I40E_FLAG_OUTER_UDP_CSUM_CAPABLE
)
7089 tx_ring
->flags
|= I40E_TXR_FLAGS_OUTER_UDP_CSUM
;
7090 vsi
->tx_rings
[i
] = tx_ring
;
7092 rx_ring
= &tx_ring
[1];
7093 rx_ring
->queue_index
= i
;
7094 rx_ring
->reg_idx
= vsi
->base_queue
+ i
;
7095 rx_ring
->ring_active
= false;
7097 rx_ring
->netdev
= vsi
->netdev
;
7098 rx_ring
->dev
= &pf
->pdev
->dev
;
7099 rx_ring
->count
= vsi
->num_desc
;
7101 rx_ring
->dcb_tc
= 0;
7102 if (pf
->flags
& I40E_FLAG_16BYTE_RX_DESC_ENABLED
)
7103 set_ring_16byte_desc_enabled(rx_ring
);
7105 clear_ring_16byte_desc_enabled(rx_ring
);
7106 vsi
->rx_rings
[i
] = rx_ring
;
7112 i40e_vsi_clear_rings(vsi
);
7117 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
7118 * @pf: board private structure
7119 * @vectors: the number of MSI-X vectors to request
7121 * Returns the number of vectors reserved, or error
7123 static int i40e_reserve_msix_vectors(struct i40e_pf
*pf
, int vectors
)
7125 vectors
= pci_enable_msix_range(pf
->pdev
, pf
->msix_entries
,
7126 I40E_MIN_MSIX
, vectors
);
7128 dev_info(&pf
->pdev
->dev
,
7129 "MSI-X vector reservation failed: %d\n", vectors
);
7137 * i40e_init_msix - Setup the MSIX capability
7138 * @pf: board private structure
7140 * Work with the OS to set up the MSIX vectors needed.
7142 * Returns the number of vectors reserved or negative on failure
7144 static int i40e_init_msix(struct i40e_pf
*pf
)
7146 struct i40e_hw
*hw
= &pf
->hw
;
7151 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
7154 /* The number of vectors we'll request will be comprised of:
7155 * - Add 1 for "other" cause for Admin Queue events, etc.
7156 * - The number of LAN queue pairs
7157 * - Queues being used for RSS.
7158 * We don't need as many as max_rss_size vectors.
7159 * use rss_size instead in the calculation since that
7160 * is governed by number of cpus in the system.
7161 * - assumes symmetric Tx/Rx pairing
7162 * - The number of VMDq pairs
7164 * - The number of FCOE qps.
7166 * Once we count this up, try the request.
7168 * If we can't get what we want, we'll simplify to nearly nothing
7169 * and try again. If that still fails, we punt.
7171 vectors_left
= hw
->func_caps
.num_msix_vectors
;
7174 /* reserve one vector for miscellaneous handler */
7180 /* reserve vectors for the main PF traffic queues */
7181 pf
->num_lan_msix
= min_t(int, num_online_cpus(), vectors_left
);
7182 vectors_left
-= pf
->num_lan_msix
;
7183 v_budget
+= pf
->num_lan_msix
;
7185 /* reserve one vector for sideband flow director */
7186 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
7191 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7196 /* can we reserve enough for FCoE? */
7197 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7199 pf
->num_fcoe_msix
= 0;
7200 else if (vectors_left
>= pf
->num_fcoe_qps
)
7201 pf
->num_fcoe_msix
= pf
->num_fcoe_qps
;
7203 pf
->num_fcoe_msix
= 1;
7204 v_budget
+= pf
->num_fcoe_msix
;
7205 vectors_left
-= pf
->num_fcoe_msix
;
7209 /* any vectors left over go for VMDq support */
7210 if (pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) {
7211 int vmdq_vecs_wanted
= pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
;
7212 int vmdq_vecs
= min_t(int, vectors_left
, vmdq_vecs_wanted
);
7214 /* if we're short on vectors for what's desired, we limit
7215 * the queues per vmdq. If this is still more than are
7216 * available, the user will need to change the number of
7217 * queues/vectors used by the PF later with the ethtool
7220 if (vmdq_vecs
< vmdq_vecs_wanted
)
7221 pf
->num_vmdq_qps
= 1;
7222 pf
->num_vmdq_msix
= pf
->num_vmdq_qps
;
7224 v_budget
+= vmdq_vecs
;
7225 vectors_left
-= vmdq_vecs
;
7228 pf
->msix_entries
= kcalloc(v_budget
, sizeof(struct msix_entry
),
7230 if (!pf
->msix_entries
)
7233 for (i
= 0; i
< v_budget
; i
++)
7234 pf
->msix_entries
[i
].entry
= i
;
7235 v_actual
= i40e_reserve_msix_vectors(pf
, v_budget
);
7237 if (v_actual
!= v_budget
) {
7238 /* If we have limited resources, we will start with no vectors
7239 * for the special features and then allocate vectors to some
7240 * of these features based on the policy and at the end disable
7241 * the features that did not get any vectors.
7244 pf
->num_fcoe_qps
= 0;
7245 pf
->num_fcoe_msix
= 0;
7247 pf
->num_vmdq_msix
= 0;
7250 if (v_actual
< I40E_MIN_MSIX
) {
7251 pf
->flags
&= ~I40E_FLAG_MSIX_ENABLED
;
7252 kfree(pf
->msix_entries
);
7253 pf
->msix_entries
= NULL
;
7256 } else if (v_actual
== I40E_MIN_MSIX
) {
7257 /* Adjust for minimal MSIX use */
7258 pf
->num_vmdq_vsis
= 0;
7259 pf
->num_vmdq_qps
= 0;
7260 pf
->num_lan_qps
= 1;
7261 pf
->num_lan_msix
= 1;
7263 } else if (v_actual
!= v_budget
) {
7266 /* reserve the misc vector */
7269 /* Scale vector usage down */
7270 pf
->num_vmdq_msix
= 1; /* force VMDqs to only one vector */
7271 pf
->num_vmdq_vsis
= 1;
7272 pf
->num_vmdq_qps
= 1;
7273 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7275 /* partition out the remaining vectors */
7278 pf
->num_lan_msix
= 1;
7282 /* give one vector to FCoE */
7283 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7284 pf
->num_lan_msix
= 1;
7285 pf
->num_fcoe_msix
= 1;
7288 pf
->num_lan_msix
= 2;
7293 /* give one vector to FCoE */
7294 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7295 pf
->num_fcoe_msix
= 1;
7299 /* give the rest to the PF */
7300 pf
->num_lan_msix
= min_t(int, vec
, pf
->num_lan_qps
);
7305 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
7306 (pf
->num_vmdq_msix
== 0)) {
7307 dev_info(&pf
->pdev
->dev
, "VMDq disabled, not enough MSI-X vectors\n");
7308 pf
->flags
&= ~I40E_FLAG_VMDQ_ENABLED
;
7312 if ((pf
->flags
& I40E_FLAG_FCOE_ENABLED
) && (pf
->num_fcoe_msix
== 0)) {
7313 dev_info(&pf
->pdev
->dev
, "FCOE disabled, not enough MSI-X vectors\n");
7314 pf
->flags
&= ~I40E_FLAG_FCOE_ENABLED
;
7321 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
7322 * @vsi: the VSI being configured
7323 * @v_idx: index of the vector in the vsi struct
7325 * We allocate one q_vector. If allocation fails we return -ENOMEM.
7327 static int i40e_vsi_alloc_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
7329 struct i40e_q_vector
*q_vector
;
7331 /* allocate q_vector */
7332 q_vector
= kzalloc(sizeof(struct i40e_q_vector
), GFP_KERNEL
);
7336 q_vector
->vsi
= vsi
;
7337 q_vector
->v_idx
= v_idx
;
7338 cpumask_set_cpu(v_idx
, &q_vector
->affinity_mask
);
7340 netif_napi_add(vsi
->netdev
, &q_vector
->napi
,
7341 i40e_napi_poll
, NAPI_POLL_WEIGHT
);
7343 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
7344 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
7346 /* tie q_vector and vsi together */
7347 vsi
->q_vectors
[v_idx
] = q_vector
;
7353 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
7354 * @vsi: the VSI being configured
7356 * We allocate one q_vector per queue interrupt. If allocation fails we
7359 static int i40e_vsi_alloc_q_vectors(struct i40e_vsi
*vsi
)
7361 struct i40e_pf
*pf
= vsi
->back
;
7362 int v_idx
, num_q_vectors
;
7365 /* if not MSIX, give the one vector only to the LAN VSI */
7366 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
7367 num_q_vectors
= vsi
->num_q_vectors
;
7368 else if (vsi
== pf
->vsi
[pf
->lan_vsi
])
7373 for (v_idx
= 0; v_idx
< num_q_vectors
; v_idx
++) {
7374 err
= i40e_vsi_alloc_q_vector(vsi
, v_idx
);
7383 i40e_free_q_vector(vsi
, v_idx
);
7389 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
7390 * @pf: board private structure to initialize
7392 static int i40e_init_interrupt_scheme(struct i40e_pf
*pf
)
7397 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
7398 vectors
= i40e_init_msix(pf
);
7400 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
|
7402 I40E_FLAG_FCOE_ENABLED
|
7404 I40E_FLAG_RSS_ENABLED
|
7405 I40E_FLAG_DCB_CAPABLE
|
7406 I40E_FLAG_SRIOV_ENABLED
|
7407 I40E_FLAG_FD_SB_ENABLED
|
7408 I40E_FLAG_FD_ATR_ENABLED
|
7409 I40E_FLAG_VMDQ_ENABLED
);
7411 /* rework the queue expectations without MSIX */
7412 i40e_determine_queue_usage(pf
);
7416 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
7417 (pf
->flags
& I40E_FLAG_MSI_ENABLED
)) {
7418 dev_info(&pf
->pdev
->dev
, "MSI-X not available, trying MSI\n");
7419 vectors
= pci_enable_msi(pf
->pdev
);
7421 dev_info(&pf
->pdev
->dev
, "MSI init failed - %d\n",
7423 pf
->flags
&= ~I40E_FLAG_MSI_ENABLED
;
7425 vectors
= 1; /* one MSI or Legacy vector */
7428 if (!(pf
->flags
& (I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
)))
7429 dev_info(&pf
->pdev
->dev
, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
7431 /* set up vector assignment tracking */
7432 size
= sizeof(struct i40e_lump_tracking
) + (sizeof(u16
) * vectors
);
7433 pf
->irq_pile
= kzalloc(size
, GFP_KERNEL
);
7434 if (!pf
->irq_pile
) {
7435 dev_err(&pf
->pdev
->dev
, "error allocating irq_pile memory\n");
7438 pf
->irq_pile
->num_entries
= vectors
;
7439 pf
->irq_pile
->search_hint
= 0;
7441 /* track first vector for misc interrupts, ignore return */
7442 (void)i40e_get_lump(pf
, pf
->irq_pile
, 1, I40E_PILE_VALID_BIT
- 1);
7448 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
7449 * @pf: board private structure
7451 * This sets up the handler for MSIX 0, which is used to manage the
7452 * non-queue interrupts, e.g. AdminQ and errors. This is not used
7453 * when in MSI or Legacy interrupt mode.
7455 static int i40e_setup_misc_vector(struct i40e_pf
*pf
)
7457 struct i40e_hw
*hw
= &pf
->hw
;
7460 /* Only request the irq if this is the first time through, and
7461 * not when we're rebuilding after a Reset
7463 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
)) {
7464 err
= request_irq(pf
->msix_entries
[0].vector
,
7465 i40e_intr
, 0, pf
->int_name
, pf
);
7467 dev_info(&pf
->pdev
->dev
,
7468 "request_irq for %s failed: %d\n",
7474 i40e_enable_misc_int_causes(pf
);
7476 /* associate no queues to the misc vector */
7477 wr32(hw
, I40E_PFINT_LNKLST0
, I40E_QUEUE_END_OF_LIST
);
7478 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), I40E_ITR_8K
);
7482 i40e_irq_dynamic_enable_icr0(pf
);
7488 * i40e_config_rss_aq - Prepare for RSS using AQ commands
7489 * @vsi: vsi structure
7490 * @seed: RSS hash seed
7492 static int i40e_config_rss_aq(struct i40e_vsi
*vsi
, const u8
*seed
)
7494 struct i40e_aqc_get_set_rss_key_data rss_key
;
7495 struct i40e_pf
*pf
= vsi
->back
;
7496 struct i40e_hw
*hw
= &pf
->hw
;
7497 bool pf_lut
= false;
7501 memset(&rss_key
, 0, sizeof(rss_key
));
7502 memcpy(&rss_key
, seed
, sizeof(rss_key
));
7504 rss_lut
= kzalloc(pf
->rss_table_size
, GFP_KERNEL
);
7508 /* Populate the LUT with max no. of queues in round robin fashion */
7509 for (i
= 0; i
< vsi
->rss_table_size
; i
++)
7510 rss_lut
[i
] = i
% vsi
->rss_size
;
7512 ret
= i40e_aq_set_rss_key(hw
, vsi
->id
, &rss_key
);
7514 dev_info(&pf
->pdev
->dev
,
7515 "Cannot set RSS key, err %s aq_err %s\n",
7516 i40e_stat_str(&pf
->hw
, ret
),
7517 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
7521 if (vsi
->type
== I40E_VSI_MAIN
)
7524 ret
= i40e_aq_set_rss_lut(hw
, vsi
->id
, pf_lut
, rss_lut
,
7525 vsi
->rss_table_size
);
7527 dev_info(&pf
->pdev
->dev
,
7528 "Cannot set RSS lut, err %s aq_err %s\n",
7529 i40e_stat_str(&pf
->hw
, ret
),
7530 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
7536 * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
7537 * @vsi: VSI structure
7539 static int i40e_vsi_config_rss(struct i40e_vsi
*vsi
)
7541 u8 seed
[I40E_HKEY_ARRAY_SIZE
];
7542 struct i40e_pf
*pf
= vsi
->back
;
7544 netdev_rss_key_fill((void *)seed
, I40E_HKEY_ARRAY_SIZE
);
7545 vsi
->rss_size
= min_t(int, pf
->rss_size
, vsi
->num_queue_pairs
);
7547 if (pf
->flags
& I40E_FLAG_RSS_AQ_CAPABLE
)
7548 return i40e_config_rss_aq(vsi
, seed
);
7554 * i40e_config_rss_reg - Prepare for RSS if used
7555 * @pf: board private structure
7556 * @seed: RSS hash seed
7558 static int i40e_config_rss_reg(struct i40e_pf
*pf
, const u8
*seed
)
7560 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
7561 struct i40e_hw
*hw
= &pf
->hw
;
7562 u32
*seed_dw
= (u32
*)seed
;
7563 u32 current_queue
= 0;
7567 /* Fill out hash function seed */
7568 for (i
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++)
7569 wr32(hw
, I40E_PFQF_HKEY(i
), seed_dw
[i
]);
7571 for (i
= 0; i
<= I40E_PFQF_HLUT_MAX_INDEX
; i
++) {
7573 for (j
= 0; j
< 4; j
++) {
7574 if (current_queue
== vsi
->rss_size
)
7576 lut
|= ((current_queue
) << (8 * j
));
7579 wr32(&pf
->hw
, I40E_PFQF_HLUT(i
), lut
);
7587 * i40e_config_rss - Prepare for RSS if used
7588 * @pf: board private structure
7590 static int i40e_config_rss(struct i40e_pf
*pf
)
7592 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
7593 u8 seed
[I40E_HKEY_ARRAY_SIZE
];
7594 struct i40e_hw
*hw
= &pf
->hw
;
7598 netdev_rss_key_fill((void *)seed
, I40E_HKEY_ARRAY_SIZE
);
7600 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
7601 hena
= (u64
)rd32(hw
, I40E_PFQF_HENA(0)) |
7602 ((u64
)rd32(hw
, I40E_PFQF_HENA(1)) << 32);
7603 hena
|= i40e_pf_get_default_rss_hena(pf
);
7605 wr32(hw
, I40E_PFQF_HENA(0), (u32
)hena
);
7606 wr32(hw
, I40E_PFQF_HENA(1), (u32
)(hena
>> 32));
7608 vsi
->rss_size
= min_t(int, pf
->rss_size
, vsi
->num_queue_pairs
);
7610 /* Determine the RSS table size based on the hardware capabilities */
7611 reg_val
= rd32(hw
, I40E_PFQF_CTL_0
);
7612 reg_val
= (pf
->rss_table_size
== 512) ?
7613 (reg_val
| I40E_PFQF_CTL_0_HASHLUTSIZE_512
) :
7614 (reg_val
& ~I40E_PFQF_CTL_0_HASHLUTSIZE_512
);
7615 wr32(hw
, I40E_PFQF_CTL_0
, reg_val
);
7617 if (pf
->flags
& I40E_FLAG_RSS_AQ_CAPABLE
)
7618 return i40e_config_rss_aq(pf
->vsi
[pf
->lan_vsi
], seed
);
7620 return i40e_config_rss_reg(pf
, seed
);
7624 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
7625 * @pf: board private structure
7626 * @queue_count: the requested queue count for rss.
7628 * returns 0 if rss is not enabled, if enabled returns the final rss queue
7629 * count which may be different from the requested queue count.
7631 int i40e_reconfig_rss_queues(struct i40e_pf
*pf
, int queue_count
)
7633 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
7636 if (!(pf
->flags
& I40E_FLAG_RSS_ENABLED
))
7639 new_rss_size
= min_t(int, queue_count
, pf
->rss_size_max
);
7641 if (queue_count
!= vsi
->num_queue_pairs
) {
7642 vsi
->req_queue_pairs
= queue_count
;
7643 i40e_prep_for_reset(pf
);
7645 pf
->rss_size
= new_rss_size
;
7647 i40e_reset_and_rebuild(pf
, true);
7648 i40e_config_rss(pf
);
7650 dev_info(&pf
->pdev
->dev
, "RSS count: %d\n", pf
->rss_size
);
7651 return pf
->rss_size
;
7655 * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition
7656 * @pf: board private structure
7658 i40e_status
i40e_get_npar_bw_setting(struct i40e_pf
*pf
)
7661 bool min_valid
, max_valid
;
7664 status
= i40e_read_bw_from_alt_ram(&pf
->hw
, &max_bw
, &min_bw
,
7665 &min_valid
, &max_valid
);
7669 pf
->npar_min_bw
= min_bw
;
7671 pf
->npar_max_bw
= max_bw
;
7678 * i40e_set_npar_bw_setting - Set BW settings for this PF partition
7679 * @pf: board private structure
7681 i40e_status
i40e_set_npar_bw_setting(struct i40e_pf
*pf
)
7683 struct i40e_aqc_configure_partition_bw_data bw_data
;
7686 /* Set the valid bit for this PF */
7687 bw_data
.pf_valid_bits
= cpu_to_le16(BIT(pf
->hw
.pf_id
));
7688 bw_data
.max_bw
[pf
->hw
.pf_id
] = pf
->npar_max_bw
& I40E_ALT_BW_VALUE_MASK
;
7689 bw_data
.min_bw
[pf
->hw
.pf_id
] = pf
->npar_min_bw
& I40E_ALT_BW_VALUE_MASK
;
7691 /* Set the new bandwidths */
7692 status
= i40e_aq_configure_partition_bw(&pf
->hw
, &bw_data
, NULL
);
7698 * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition
7699 * @pf: board private structure
7701 i40e_status
i40e_commit_npar_bw_setting(struct i40e_pf
*pf
)
7703 /* Commit temporary BW setting to permanent NVM image */
7704 enum i40e_admin_queue_err last_aq_status
;
7708 if (pf
->hw
.partition_id
!= 1) {
7709 dev_info(&pf
->pdev
->dev
,
7710 "Commit BW only works on partition 1! This is partition %d",
7711 pf
->hw
.partition_id
);
7712 ret
= I40E_NOT_SUPPORTED
;
7716 /* Acquire NVM for read access */
7717 ret
= i40e_acquire_nvm(&pf
->hw
, I40E_RESOURCE_READ
);
7718 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
7720 dev_info(&pf
->pdev
->dev
,
7721 "Cannot acquire NVM for read access, err %s aq_err %s\n",
7722 i40e_stat_str(&pf
->hw
, ret
),
7723 i40e_aq_str(&pf
->hw
, last_aq_status
));
7727 /* Read word 0x10 of NVM - SW compatibility word 1 */
7728 ret
= i40e_aq_read_nvm(&pf
->hw
,
7729 I40E_SR_NVM_CONTROL_WORD
,
7730 0x10, sizeof(nvm_word
), &nvm_word
,
7732 /* Save off last admin queue command status before releasing
7735 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
7736 i40e_release_nvm(&pf
->hw
);
7738 dev_info(&pf
->pdev
->dev
, "NVM read error, err %s aq_err %s\n",
7739 i40e_stat_str(&pf
->hw
, ret
),
7740 i40e_aq_str(&pf
->hw
, last_aq_status
));
7744 /* Wait a bit for NVM release to complete */
7747 /* Acquire NVM for write access */
7748 ret
= i40e_acquire_nvm(&pf
->hw
, I40E_RESOURCE_WRITE
);
7749 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
7751 dev_info(&pf
->pdev
->dev
,
7752 "Cannot acquire NVM for write access, err %s aq_err %s\n",
7753 i40e_stat_str(&pf
->hw
, ret
),
7754 i40e_aq_str(&pf
->hw
, last_aq_status
));
7757 /* Write it back out unchanged to initiate update NVM,
7758 * which will force a write of the shadow (alt) RAM to
7759 * the NVM - thus storing the bandwidth values permanently.
7761 ret
= i40e_aq_update_nvm(&pf
->hw
,
7762 I40E_SR_NVM_CONTROL_WORD
,
7763 0x10, sizeof(nvm_word
),
7764 &nvm_word
, true, NULL
);
7765 /* Save off last admin queue command status before releasing
7768 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
7769 i40e_release_nvm(&pf
->hw
);
7771 dev_info(&pf
->pdev
->dev
,
7772 "BW settings NOT SAVED, err %s aq_err %s\n",
7773 i40e_stat_str(&pf
->hw
, ret
),
7774 i40e_aq_str(&pf
->hw
, last_aq_status
));
7781 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
7782 * @pf: board private structure to initialize
7784 * i40e_sw_init initializes the Adapter private data structure.
7785 * Fields are initialized based on PCI device information and
7786 * OS network device settings (MTU size).
7788 static int i40e_sw_init(struct i40e_pf
*pf
)
7793 pf
->msg_enable
= netif_msg_init(I40E_DEFAULT_MSG_ENABLE
,
7794 (NETIF_MSG_DRV
|NETIF_MSG_PROBE
|NETIF_MSG_LINK
));
7795 pf
->hw
.debug_mask
= pf
->msg_enable
| I40E_DEBUG_DIAG
;
7796 if (debug
!= -1 && debug
!= I40E_DEFAULT_MSG_ENABLE
) {
7797 if (I40E_DEBUG_USER
& debug
)
7798 pf
->hw
.debug_mask
= debug
;
7799 pf
->msg_enable
= netif_msg_init((debug
& ~I40E_DEBUG_USER
),
7800 I40E_DEFAULT_MSG_ENABLE
);
7803 /* Set default capability flags */
7804 pf
->flags
= I40E_FLAG_RX_CSUM_ENABLED
|
7805 I40E_FLAG_MSI_ENABLED
|
7806 I40E_FLAG_MSIX_ENABLED
;
7808 if (iommu_present(&pci_bus_type
))
7809 pf
->flags
|= I40E_FLAG_RX_PS_ENABLED
;
7811 pf
->flags
|= I40E_FLAG_RX_1BUF_ENABLED
;
7813 /* Set default ITR */
7814 pf
->rx_itr_default
= I40E_ITR_DYNAMIC
| I40E_ITR_RX_DEF
;
7815 pf
->tx_itr_default
= I40E_ITR_DYNAMIC
| I40E_ITR_TX_DEF
;
7817 /* Depending on PF configurations, it is possible that the RSS
7818 * maximum might end up larger than the available queues
7820 pf
->rss_size_max
= BIT(pf
->hw
.func_caps
.rss_table_entry_width
);
7822 pf
->rss_table_size
= pf
->hw
.func_caps
.rss_table_size
;
7823 pf
->rss_size_max
= min_t(int, pf
->rss_size_max
,
7824 pf
->hw
.func_caps
.num_tx_qp
);
7825 if (pf
->hw
.func_caps
.rss
) {
7826 pf
->flags
|= I40E_FLAG_RSS_ENABLED
;
7827 pf
->rss_size
= min_t(int, pf
->rss_size_max
, num_online_cpus());
7830 /* MFP mode enabled */
7831 if (pf
->hw
.func_caps
.npar_enable
|| pf
->hw
.func_caps
.flex10_enable
) {
7832 pf
->flags
|= I40E_FLAG_MFP_ENABLED
;
7833 dev_info(&pf
->pdev
->dev
, "MFP mode Enabled\n");
7834 if (i40e_get_npar_bw_setting(pf
))
7835 dev_warn(&pf
->pdev
->dev
,
7836 "Could not get NPAR bw settings\n");
7838 dev_info(&pf
->pdev
->dev
,
7839 "Min BW = %8.8x, Max BW = %8.8x\n",
7840 pf
->npar_min_bw
, pf
->npar_max_bw
);
7843 /* FW/NVM is not yet fixed in this regard */
7844 if ((pf
->hw
.func_caps
.fd_filters_guaranteed
> 0) ||
7845 (pf
->hw
.func_caps
.fd_filters_best_effort
> 0)) {
7846 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
7847 pf
->atr_sample_rate
= I40E_DEFAULT_ATR_SAMPLE_RATE
;
7848 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
)) {
7849 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
7851 dev_info(&pf
->pdev
->dev
,
7852 "Flow Director Sideband mode Disabled in MFP mode\n");
7854 pf
->fdir_pf_filter_count
=
7855 pf
->hw
.func_caps
.fd_filters_guaranteed
;
7856 pf
->hw
.fdir_shared_filter_count
=
7857 pf
->hw
.func_caps
.fd_filters_best_effort
;
7860 if (pf
->hw
.func_caps
.vmdq
) {
7861 pf
->num_vmdq_vsis
= I40E_DEFAULT_NUM_VMDQ_VSI
;
7862 pf
->flags
|= I40E_FLAG_VMDQ_ENABLED
;
7866 err
= i40e_init_pf_fcoe(pf
);
7868 dev_info(&pf
->pdev
->dev
, "init_pf_fcoe failed: %d\n", err
);
7870 #endif /* I40E_FCOE */
7871 #ifdef CONFIG_PCI_IOV
7872 if (pf
->hw
.func_caps
.num_vfs
&& pf
->hw
.partition_id
== 1) {
7873 pf
->num_vf_qps
= I40E_DEFAULT_QUEUES_PER_VF
;
7874 pf
->flags
|= I40E_FLAG_SRIOV_ENABLED
;
7875 pf
->num_req_vfs
= min_t(int,
7876 pf
->hw
.func_caps
.num_vfs
,
7879 #endif /* CONFIG_PCI_IOV */
7880 if (pf
->hw
.mac
.type
== I40E_MAC_X722
) {
7881 pf
->flags
|= I40E_FLAG_RSS_AQ_CAPABLE
|
7882 I40E_FLAG_128_QP_RSS_CAPABLE
|
7883 I40E_FLAG_HW_ATR_EVICT_CAPABLE
|
7884 I40E_FLAG_OUTER_UDP_CSUM_CAPABLE
|
7885 I40E_FLAG_WB_ON_ITR_CAPABLE
|
7886 I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE
;
7888 pf
->eeprom_version
= 0xDEAD;
7889 pf
->lan_veb
= I40E_NO_VEB
;
7890 pf
->lan_vsi
= I40E_NO_VSI
;
7892 /* set up queue assignment tracking */
7893 size
= sizeof(struct i40e_lump_tracking
)
7894 + (sizeof(u16
) * pf
->hw
.func_caps
.num_tx_qp
);
7895 pf
->qp_pile
= kzalloc(size
, GFP_KERNEL
);
7900 pf
->qp_pile
->num_entries
= pf
->hw
.func_caps
.num_tx_qp
;
7901 pf
->qp_pile
->search_hint
= 0;
7903 pf
->tx_timeout_recovery_level
= 1;
7905 mutex_init(&pf
->switch_mutex
);
7907 /* If NPAR is enabled nudge the Tx scheduler */
7908 if (pf
->hw
.func_caps
.npar_enable
&& (!i40e_get_npar_bw_setting(pf
)))
7909 i40e_set_npar_bw_setting(pf
);
7916 * i40e_set_ntuple - set the ntuple feature flag and take action
7917 * @pf: board private structure to initialize
7918 * @features: the feature set that the stack is suggesting
7920 * returns a bool to indicate if reset needs to happen
7922 bool i40e_set_ntuple(struct i40e_pf
*pf
, netdev_features_t features
)
7924 bool need_reset
= false;
7926 /* Check if Flow Director n-tuple support was enabled or disabled. If
7927 * the state changed, we need to reset.
7929 if (features
& NETIF_F_NTUPLE
) {
7930 /* Enable filters and mark for reset */
7931 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
7933 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
7935 /* turn off filters, mark for reset and clear SW filter list */
7936 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
7938 i40e_fdir_filter_exit(pf
);
7940 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7941 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7942 /* reset fd counters */
7943 pf
->fd_add_err
= pf
->fd_atr_cnt
= pf
->fd_tcp_rule
= 0;
7944 pf
->fdir_pf_active_filters
= 0;
7945 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
7946 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
7947 dev_info(&pf
->pdev
->dev
, "ATR re-enabled.\n");
7948 /* if ATR was auto disabled it can be re-enabled. */
7949 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
7950 (pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
))
7951 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
7957 * i40e_set_features - set the netdev feature flags
7958 * @netdev: ptr to the netdev being adjusted
7959 * @features: the feature set that the stack is suggesting
7961 static int i40e_set_features(struct net_device
*netdev
,
7962 netdev_features_t features
)
7964 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7965 struct i40e_vsi
*vsi
= np
->vsi
;
7966 struct i40e_pf
*pf
= vsi
->back
;
7969 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
7970 i40e_vlan_stripping_enable(vsi
);
7972 i40e_vlan_stripping_disable(vsi
);
7974 need_reset
= i40e_set_ntuple(pf
, features
);
7977 i40e_do_reset(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
7982 #ifdef CONFIG_I40E_VXLAN
7984 * i40e_get_vxlan_port_idx - Lookup a possibly offloaded for Rx UDP port
7985 * @pf: board private structure
7986 * @port: The UDP port to look up
7988 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
7990 static u8
i40e_get_vxlan_port_idx(struct i40e_pf
*pf
, __be16 port
)
7994 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
7995 if (pf
->vxlan_ports
[i
] == port
)
8003 * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up
8004 * @netdev: This physical port's netdev
8005 * @sa_family: Socket Family that VXLAN is notifying us about
8006 * @port: New UDP port number that VXLAN started listening to
8008 static void i40e_add_vxlan_port(struct net_device
*netdev
,
8009 sa_family_t sa_family
, __be16 port
)
8011 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8012 struct i40e_vsi
*vsi
= np
->vsi
;
8013 struct i40e_pf
*pf
= vsi
->back
;
8017 if (sa_family
== AF_INET6
)
8020 idx
= i40e_get_vxlan_port_idx(pf
, port
);
8022 /* Check if port already exists */
8023 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
8024 netdev_info(netdev
, "vxlan port %d already offloaded\n",
8029 /* Now check if there is space to add the new port */
8030 next_idx
= i40e_get_vxlan_port_idx(pf
, 0);
8032 if (next_idx
== I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
8033 netdev_info(netdev
, "maximum number of vxlan UDP ports reached, not adding port %d\n",
8038 /* New port: add it and mark its index in the bitmap */
8039 pf
->vxlan_ports
[next_idx
] = port
;
8040 pf
->pending_vxlan_bitmap
|= BIT_ULL(next_idx
);
8041 pf
->flags
|= I40E_FLAG_VXLAN_FILTER_SYNC
;
8043 dev_info(&pf
->pdev
->dev
, "adding vxlan port %d\n", ntohs(port
));
8047 * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away
8048 * @netdev: This physical port's netdev
8049 * @sa_family: Socket Family that VXLAN is notifying us about
8050 * @port: UDP port number that VXLAN stopped listening to
8052 static void i40e_del_vxlan_port(struct net_device
*netdev
,
8053 sa_family_t sa_family
, __be16 port
)
8055 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8056 struct i40e_vsi
*vsi
= np
->vsi
;
8057 struct i40e_pf
*pf
= vsi
->back
;
8060 if (sa_family
== AF_INET6
)
8063 idx
= i40e_get_vxlan_port_idx(pf
, port
);
8065 /* Check if port already exists */
8066 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
8067 /* if port exists, set it to 0 (mark for deletion)
8068 * and make it pending
8070 pf
->vxlan_ports
[idx
] = 0;
8071 pf
->pending_vxlan_bitmap
|= BIT_ULL(idx
);
8072 pf
->flags
|= I40E_FLAG_VXLAN_FILTER_SYNC
;
8074 dev_info(&pf
->pdev
->dev
, "deleting vxlan port %d\n",
8077 netdev_warn(netdev
, "vxlan port %d was not found, not deleting\n",
8083 static int i40e_get_phys_port_id(struct net_device
*netdev
,
8084 struct netdev_phys_item_id
*ppid
)
8086 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
8087 struct i40e_pf
*pf
= np
->vsi
->back
;
8088 struct i40e_hw
*hw
= &pf
->hw
;
8090 if (!(pf
->flags
& I40E_FLAG_PORT_ID_VALID
))
8093 ppid
->id_len
= min_t(int, sizeof(hw
->mac
.port_addr
), sizeof(ppid
->id
));
8094 memcpy(ppid
->id
, hw
->mac
.port_addr
, ppid
->id_len
);
8100 * i40e_ndo_fdb_add - add an entry to the hardware database
8101 * @ndm: the input from the stack
8102 * @tb: pointer to array of nladdr (unused)
8103 * @dev: the net device pointer
8104 * @addr: the MAC address entry being added
8105 * @flags: instructions from stack about fdb operation
8107 static int i40e_ndo_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
8108 struct net_device
*dev
,
8109 const unsigned char *addr
, u16 vid
,
8112 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
8113 struct i40e_pf
*pf
= np
->vsi
->back
;
8116 if (!(pf
->flags
& I40E_FLAG_SRIOV_ENABLED
))
8120 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev
->name
);
8124 /* Hardware does not support aging addresses so if a
8125 * ndm_state is given only allow permanent addresses
8127 if (ndm
->ndm_state
&& !(ndm
->ndm_state
& NUD_PERMANENT
)) {
8128 netdev_info(dev
, "FDB only supports static addresses\n");
8132 if (is_unicast_ether_addr(addr
) || is_link_local_ether_addr(addr
))
8133 err
= dev_uc_add_excl(dev
, addr
);
8134 else if (is_multicast_ether_addr(addr
))
8135 err
= dev_mc_add_excl(dev
, addr
);
8139 /* Only return duplicate errors if NLM_F_EXCL is set */
8140 if (err
== -EEXIST
&& !(flags
& NLM_F_EXCL
))
8147 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
8148 * @dev: the netdev being configured
8149 * @nlh: RTNL message
8151 * Inserts a new hardware bridge if not already created and
8152 * enables the bridging mode requested (VEB or VEPA). If the
8153 * hardware bridge has already been inserted and the request
8154 * is to change the mode then that requires a PF reset to
8155 * allow rebuild of the components with required hardware
8156 * bridge mode enabled.
8158 static int i40e_ndo_bridge_setlink(struct net_device
*dev
,
8159 struct nlmsghdr
*nlh
,
8162 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
8163 struct i40e_vsi
*vsi
= np
->vsi
;
8164 struct i40e_pf
*pf
= vsi
->back
;
8165 struct i40e_veb
*veb
= NULL
;
8166 struct nlattr
*attr
, *br_spec
;
8169 /* Only for PF VSI for now */
8170 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
)
8173 /* Find the HW bridge for PF VSI */
8174 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
8175 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
8179 br_spec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
8181 nla_for_each_nested(attr
, br_spec
, rem
) {
8184 if (nla_type(attr
) != IFLA_BRIDGE_MODE
)
8187 mode
= nla_get_u16(attr
);
8188 if ((mode
!= BRIDGE_MODE_VEPA
) &&
8189 (mode
!= BRIDGE_MODE_VEB
))
8192 /* Insert a new HW bridge */
8194 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
8195 vsi
->tc_config
.enabled_tc
);
8197 veb
->bridge_mode
= mode
;
8198 i40e_config_bridge_mode(veb
);
8200 /* No Bridge HW offload available */
8204 } else if (mode
!= veb
->bridge_mode
) {
8205 /* Existing HW bridge but different mode needs reset */
8206 veb
->bridge_mode
= mode
;
8207 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
8208 if (mode
== BRIDGE_MODE_VEB
)
8209 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
8211 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
8212 i40e_do_reset(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
8221 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
8224 * @seq: RTNL message seq #
8225 * @dev: the netdev being configured
8226 * @filter_mask: unused
8228 * Return the mode in which the hardware bridge is operating in
8231 static int i40e_ndo_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
8232 struct net_device
*dev
,
8233 u32 filter_mask
, int nlflags
)
8235 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
8236 struct i40e_vsi
*vsi
= np
->vsi
;
8237 struct i40e_pf
*pf
= vsi
->back
;
8238 struct i40e_veb
*veb
= NULL
;
8241 /* Only for PF VSI for now */
8242 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
)
8245 /* Find the HW bridge for the PF VSI */
8246 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
8247 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
8254 return ndo_dflt_bridge_getlink(skb
, pid
, seq
, dev
, veb
->bridge_mode
,
8255 nlflags
, 0, 0, filter_mask
, NULL
);
8258 #define I40E_MAX_TUNNEL_HDR_LEN 80
8260 * i40e_features_check - Validate encapsulated packet conforms to limits
8262 * @netdev: This physical port's netdev
8263 * @features: Offload features that the stack believes apply
8265 static netdev_features_t
i40e_features_check(struct sk_buff
*skb
,
8266 struct net_device
*dev
,
8267 netdev_features_t features
)
8269 if (skb
->encapsulation
&&
8270 (skb_inner_mac_header(skb
) - skb_transport_header(skb
) >
8271 I40E_MAX_TUNNEL_HDR_LEN
))
8272 return features
& ~(NETIF_F_ALL_CSUM
| NETIF_F_GSO_MASK
);
8277 static const struct net_device_ops i40e_netdev_ops
= {
8278 .ndo_open
= i40e_open
,
8279 .ndo_stop
= i40e_close
,
8280 .ndo_start_xmit
= i40e_lan_xmit_frame
,
8281 .ndo_get_stats64
= i40e_get_netdev_stats_struct
,
8282 .ndo_set_rx_mode
= i40e_set_rx_mode
,
8283 .ndo_validate_addr
= eth_validate_addr
,
8284 .ndo_set_mac_address
= i40e_set_mac
,
8285 .ndo_change_mtu
= i40e_change_mtu
,
8286 .ndo_do_ioctl
= i40e_ioctl
,
8287 .ndo_tx_timeout
= i40e_tx_timeout
,
8288 .ndo_vlan_rx_add_vid
= i40e_vlan_rx_add_vid
,
8289 .ndo_vlan_rx_kill_vid
= i40e_vlan_rx_kill_vid
,
8290 #ifdef CONFIG_NET_POLL_CONTROLLER
8291 .ndo_poll_controller
= i40e_netpoll
,
8293 .ndo_setup_tc
= i40e_setup_tc
,
8295 .ndo_fcoe_enable
= i40e_fcoe_enable
,
8296 .ndo_fcoe_disable
= i40e_fcoe_disable
,
8298 .ndo_set_features
= i40e_set_features
,
8299 .ndo_set_vf_mac
= i40e_ndo_set_vf_mac
,
8300 .ndo_set_vf_vlan
= i40e_ndo_set_vf_port_vlan
,
8301 .ndo_set_vf_rate
= i40e_ndo_set_vf_bw
,
8302 .ndo_get_vf_config
= i40e_ndo_get_vf_config
,
8303 .ndo_set_vf_link_state
= i40e_ndo_set_vf_link_state
,
8304 .ndo_set_vf_spoofchk
= i40e_ndo_set_vf_spoofchk
,
8305 #ifdef CONFIG_I40E_VXLAN
8306 .ndo_add_vxlan_port
= i40e_add_vxlan_port
,
8307 .ndo_del_vxlan_port
= i40e_del_vxlan_port
,
8309 .ndo_get_phys_port_id
= i40e_get_phys_port_id
,
8310 .ndo_fdb_add
= i40e_ndo_fdb_add
,
8311 .ndo_features_check
= i40e_features_check
,
8312 .ndo_bridge_getlink
= i40e_ndo_bridge_getlink
,
8313 .ndo_bridge_setlink
= i40e_ndo_bridge_setlink
,
8317 * i40e_config_netdev - Setup the netdev flags
8318 * @vsi: the VSI being configured
8320 * Returns 0 on success, negative value on failure
8322 static int i40e_config_netdev(struct i40e_vsi
*vsi
)
8324 u8 brdcast
[ETH_ALEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
8325 struct i40e_pf
*pf
= vsi
->back
;
8326 struct i40e_hw
*hw
= &pf
->hw
;
8327 struct i40e_netdev_priv
*np
;
8328 struct net_device
*netdev
;
8329 u8 mac_addr
[ETH_ALEN
];
8332 etherdev_size
= sizeof(struct i40e_netdev_priv
);
8333 netdev
= alloc_etherdev_mq(etherdev_size
, vsi
->alloc_queue_pairs
);
8337 vsi
->netdev
= netdev
;
8338 np
= netdev_priv(netdev
);
8341 netdev
->hw_enc_features
|= NETIF_F_IP_CSUM
|
8342 NETIF_F_GSO_UDP_TUNNEL
|
8345 netdev
->features
= NETIF_F_SG
|
8349 NETIF_F_GSO_UDP_TUNNEL
|
8350 NETIF_F_HW_VLAN_CTAG_TX
|
8351 NETIF_F_HW_VLAN_CTAG_RX
|
8352 NETIF_F_HW_VLAN_CTAG_FILTER
|
8361 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
8362 netdev
->features
|= NETIF_F_NTUPLE
;
8364 /* copy netdev features into list of user selectable features */
8365 netdev
->hw_features
|= netdev
->features
;
8367 if (vsi
->type
== I40E_VSI_MAIN
) {
8368 SET_NETDEV_DEV(netdev
, &pf
->pdev
->dev
);
8369 ether_addr_copy(mac_addr
, hw
->mac
.perm_addr
);
8370 /* The following steps are necessary to prevent reception
8371 * of tagged packets - some older NVM configurations load a
8372 * default a MAC-VLAN filter that accepts any tagged packet
8373 * which must be replaced by a normal filter.
8375 if (!i40e_rm_default_mac_filter(vsi
, mac_addr
))
8376 i40e_add_filter(vsi
, mac_addr
,
8377 I40E_VLAN_ANY
, false, true);
8379 /* relate the VSI_VMDQ name to the VSI_MAIN name */
8380 snprintf(netdev
->name
, IFNAMSIZ
, "%sv%%d",
8381 pf
->vsi
[pf
->lan_vsi
]->netdev
->name
);
8382 random_ether_addr(mac_addr
);
8383 i40e_add_filter(vsi
, mac_addr
, I40E_VLAN_ANY
, false, false);
8385 i40e_add_filter(vsi
, brdcast
, I40E_VLAN_ANY
, false, false);
8387 ether_addr_copy(netdev
->dev_addr
, mac_addr
);
8388 ether_addr_copy(netdev
->perm_addr
, mac_addr
);
8389 /* vlan gets same features (except vlan offload)
8390 * after any tweaks for specific VSI types
8392 netdev
->vlan_features
= netdev
->features
& ~(NETIF_F_HW_VLAN_CTAG_TX
|
8393 NETIF_F_HW_VLAN_CTAG_RX
|
8394 NETIF_F_HW_VLAN_CTAG_FILTER
);
8395 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
8396 netdev
->priv_flags
|= IFF_SUPP_NOFCS
;
8397 /* Setup netdev TC information */
8398 i40e_vsi_config_netdev_tc(vsi
, vsi
->tc_config
.enabled_tc
);
8400 netdev
->netdev_ops
= &i40e_netdev_ops
;
8401 netdev
->watchdog_timeo
= 5 * HZ
;
8402 i40e_set_ethtool_ops(netdev
);
8404 i40e_fcoe_config_netdev(netdev
, vsi
);
8411 * i40e_vsi_delete - Delete a VSI from the switch
8412 * @vsi: the VSI being removed
8414 * Returns 0 on success, negative value on failure
8416 static void i40e_vsi_delete(struct i40e_vsi
*vsi
)
8418 /* remove default VSI is not allowed */
8419 if (vsi
== vsi
->back
->vsi
[vsi
->back
->lan_vsi
])
8422 i40e_aq_delete_element(&vsi
->back
->hw
, vsi
->seid
, NULL
);
8426 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
8427 * @vsi: the VSI being queried
8429 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
8431 int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi
*vsi
)
8433 struct i40e_veb
*veb
;
8434 struct i40e_pf
*pf
= vsi
->back
;
8436 /* Uplink is not a bridge so default to VEB */
8437 if (vsi
->veb_idx
== I40E_NO_VEB
)
8440 veb
= pf
->veb
[vsi
->veb_idx
];
8441 /* Uplink is a bridge in VEPA mode */
8442 if (veb
&& (veb
->bridge_mode
& BRIDGE_MODE_VEPA
))
8445 /* Uplink is a bridge in VEB mode */
8450 * i40e_add_vsi - Add a VSI to the switch
8451 * @vsi: the VSI being configured
8453 * This initializes a VSI context depending on the VSI type to be added and
8454 * passes it down to the add_vsi aq command.
8456 static int i40e_add_vsi(struct i40e_vsi
*vsi
)
8459 struct i40e_mac_filter
*f
, *ftmp
;
8460 struct i40e_pf
*pf
= vsi
->back
;
8461 struct i40e_hw
*hw
= &pf
->hw
;
8462 struct i40e_vsi_context ctxt
;
8463 u8 enabled_tc
= 0x1; /* TC0 enabled */
8466 memset(&ctxt
, 0, sizeof(ctxt
));
8467 switch (vsi
->type
) {
8469 /* The PF's main VSI is already setup as part of the
8470 * device initialization, so we'll not bother with
8471 * the add_vsi call, but we will retrieve the current
8474 ctxt
.seid
= pf
->main_vsi_seid
;
8475 ctxt
.pf_num
= pf
->hw
.pf_id
;
8477 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
8478 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
8480 dev_info(&pf
->pdev
->dev
,
8481 "couldn't get PF vsi config, err %s aq_err %s\n",
8482 i40e_stat_str(&pf
->hw
, ret
),
8483 i40e_aq_str(&pf
->hw
,
8484 pf
->hw
.aq
.asq_last_status
));
8487 vsi
->info
= ctxt
.info
;
8488 vsi
->info
.valid_sections
= 0;
8490 vsi
->seid
= ctxt
.seid
;
8491 vsi
->id
= ctxt
.vsi_number
;
8493 enabled_tc
= i40e_pf_get_tc_map(pf
);
8495 /* MFP mode setup queue map and update VSI */
8496 if ((pf
->flags
& I40E_FLAG_MFP_ENABLED
) &&
8497 !(pf
->hw
.func_caps
.iscsi
)) { /* NIC type PF */
8498 memset(&ctxt
, 0, sizeof(ctxt
));
8499 ctxt
.seid
= pf
->main_vsi_seid
;
8500 ctxt
.pf_num
= pf
->hw
.pf_id
;
8502 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
8503 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
8505 dev_info(&pf
->pdev
->dev
,
8506 "update vsi failed, err %s aq_err %s\n",
8507 i40e_stat_str(&pf
->hw
, ret
),
8508 i40e_aq_str(&pf
->hw
,
8509 pf
->hw
.aq
.asq_last_status
));
8513 /* update the local VSI info queue map */
8514 i40e_vsi_update_queue_map(vsi
, &ctxt
);
8515 vsi
->info
.valid_sections
= 0;
8517 /* Default/Main VSI is only enabled for TC0
8518 * reconfigure it to enable all TCs that are
8519 * available on the port in SFP mode.
8520 * For MFP case the iSCSI PF would use this
8521 * flow to enable LAN+iSCSI TC.
8523 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
8525 dev_info(&pf
->pdev
->dev
,
8526 "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
8528 i40e_stat_str(&pf
->hw
, ret
),
8529 i40e_aq_str(&pf
->hw
,
8530 pf
->hw
.aq
.asq_last_status
));
8537 ctxt
.pf_num
= hw
->pf_id
;
8539 ctxt
.uplink_seid
= vsi
->uplink_seid
;
8540 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
8541 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
8542 if ((pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
) &&
8543 (i40e_is_vsi_uplink_mode_veb(vsi
))) {
8544 ctxt
.info
.valid_sections
|=
8545 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
8546 ctxt
.info
.switch_id
=
8547 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
8549 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
8552 case I40E_VSI_VMDQ2
:
8553 ctxt
.pf_num
= hw
->pf_id
;
8555 ctxt
.uplink_seid
= vsi
->uplink_seid
;
8556 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
8557 ctxt
.flags
= I40E_AQ_VSI_TYPE_VMDQ2
;
8559 /* This VSI is connected to VEB so the switch_id
8560 * should be set to zero by default.
8562 if (i40e_is_vsi_uplink_mode_veb(vsi
)) {
8563 ctxt
.info
.valid_sections
|=
8564 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
8565 ctxt
.info
.switch_id
=
8566 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
8569 /* Setup the VSI tx/rx queue map for TC0 only for now */
8570 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
8573 case I40E_VSI_SRIOV
:
8574 ctxt
.pf_num
= hw
->pf_id
;
8575 ctxt
.vf_num
= vsi
->vf_id
+ hw
->func_caps
.vf_base_id
;
8576 ctxt
.uplink_seid
= vsi
->uplink_seid
;
8577 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
8578 ctxt
.flags
= I40E_AQ_VSI_TYPE_VF
;
8580 /* This VSI is connected to VEB so the switch_id
8581 * should be set to zero by default.
8583 if (i40e_is_vsi_uplink_mode_veb(vsi
)) {
8584 ctxt
.info
.valid_sections
|=
8585 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
8586 ctxt
.info
.switch_id
=
8587 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
8590 ctxt
.info
.valid_sections
|= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
8591 ctxt
.info
.port_vlan_flags
|= I40E_AQ_VSI_PVLAN_MODE_ALL
;
8592 if (pf
->vf
[vsi
->vf_id
].spoofchk
) {
8593 ctxt
.info
.valid_sections
|=
8594 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID
);
8595 ctxt
.info
.sec_flags
|=
8596 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK
|
8597 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK
);
8599 /* Setup the VSI tx/rx queue map for TC0 only for now */
8600 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
8605 ret
= i40e_fcoe_vsi_init(vsi
, &ctxt
);
8607 dev_info(&pf
->pdev
->dev
, "failed to initialize FCoE VSI\n");
8612 #endif /* I40E_FCOE */
8617 if (vsi
->type
!= I40E_VSI_MAIN
) {
8618 ret
= i40e_aq_add_vsi(hw
, &ctxt
, NULL
);
8620 dev_info(&vsi
->back
->pdev
->dev
,
8621 "add vsi failed, err %s aq_err %s\n",
8622 i40e_stat_str(&pf
->hw
, ret
),
8623 i40e_aq_str(&pf
->hw
,
8624 pf
->hw
.aq
.asq_last_status
));
8628 vsi
->info
= ctxt
.info
;
8629 vsi
->info
.valid_sections
= 0;
8630 vsi
->seid
= ctxt
.seid
;
8631 vsi
->id
= ctxt
.vsi_number
;
8634 /* If macvlan filters already exist, force them to get loaded */
8635 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
8639 if (f
->is_laa
&& vsi
->type
== I40E_VSI_MAIN
) {
8640 struct i40e_aqc_remove_macvlan_element_data element
;
8642 memset(&element
, 0, sizeof(element
));
8643 ether_addr_copy(element
.mac_addr
, f
->macaddr
);
8644 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
8645 ret
= i40e_aq_remove_macvlan(hw
, vsi
->seid
,
8648 /* some older FW has a different default */
8650 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
8651 i40e_aq_remove_macvlan(hw
, vsi
->seid
,
8655 i40e_aq_mac_address_write(hw
,
8656 I40E_AQC_WRITE_TYPE_LAA_WOL
,
8661 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
8662 pf
->flags
|= I40E_FLAG_FILTER_SYNC
;
8665 /* Update VSI BW information */
8666 ret
= i40e_vsi_get_bw_info(vsi
);
8668 dev_info(&pf
->pdev
->dev
,
8669 "couldn't get vsi bw info, err %s aq_err %s\n",
8670 i40e_stat_str(&pf
->hw
, ret
),
8671 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
8672 /* VSI is already added so not tearing that up */
8681 * i40e_vsi_release - Delete a VSI and free its resources
8682 * @vsi: the VSI being removed
8684 * Returns 0 on success or < 0 on error
8686 int i40e_vsi_release(struct i40e_vsi
*vsi
)
8688 struct i40e_mac_filter
*f
, *ftmp
;
8689 struct i40e_veb
*veb
= NULL
;
8696 /* release of a VEB-owner or last VSI is not allowed */
8697 if (vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
8698 dev_info(&pf
->pdev
->dev
, "VSI %d has existing VEB %d\n",
8699 vsi
->seid
, vsi
->uplink_seid
);
8702 if (vsi
== pf
->vsi
[pf
->lan_vsi
] &&
8703 !test_bit(__I40E_DOWN
, &pf
->state
)) {
8704 dev_info(&pf
->pdev
->dev
, "Can't remove PF VSI\n");
8708 uplink_seid
= vsi
->uplink_seid
;
8709 if (vsi
->type
!= I40E_VSI_SRIOV
) {
8710 if (vsi
->netdev_registered
) {
8711 vsi
->netdev_registered
= false;
8713 /* results in a call to i40e_close() */
8714 unregister_netdev(vsi
->netdev
);
8717 i40e_vsi_close(vsi
);
8719 i40e_vsi_disable_irq(vsi
);
8722 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
)
8723 i40e_del_filter(vsi
, f
->macaddr
, f
->vlan
,
8724 f
->is_vf
, f
->is_netdev
);
8725 i40e_sync_vsi_filters(vsi
);
8727 i40e_vsi_delete(vsi
);
8728 i40e_vsi_free_q_vectors(vsi
);
8730 free_netdev(vsi
->netdev
);
8733 i40e_vsi_clear_rings(vsi
);
8734 i40e_vsi_clear(vsi
);
8736 /* If this was the last thing on the VEB, except for the
8737 * controlling VSI, remove the VEB, which puts the controlling
8738 * VSI onto the next level down in the switch.
8740 * Well, okay, there's one more exception here: don't remove
8741 * the orphan VEBs yet. We'll wait for an explicit remove request
8742 * from up the network stack.
8744 for (n
= 0, i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
8746 pf
->vsi
[i
]->uplink_seid
== uplink_seid
&&
8747 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
8748 n
++; /* count the VSIs */
8751 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
8754 if (pf
->veb
[i
]->uplink_seid
== uplink_seid
)
8755 n
++; /* count the VEBs */
8756 if (pf
->veb
[i
]->seid
== uplink_seid
)
8759 if (n
== 0 && veb
&& veb
->uplink_seid
!= 0)
8760 i40e_veb_release(veb
);
8766 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
8767 * @vsi: ptr to the VSI
8769 * This should only be called after i40e_vsi_mem_alloc() which allocates the
8770 * corresponding SW VSI structure and initializes num_queue_pairs for the
8771 * newly allocated VSI.
8773 * Returns 0 on success or negative on failure
8775 static int i40e_vsi_setup_vectors(struct i40e_vsi
*vsi
)
8778 struct i40e_pf
*pf
= vsi
->back
;
8780 if (vsi
->q_vectors
[0]) {
8781 dev_info(&pf
->pdev
->dev
, "VSI %d has existing q_vectors\n",
8786 if (vsi
->base_vector
) {
8787 dev_info(&pf
->pdev
->dev
, "VSI %d has non-zero base vector %d\n",
8788 vsi
->seid
, vsi
->base_vector
);
8792 ret
= i40e_vsi_alloc_q_vectors(vsi
);
8794 dev_info(&pf
->pdev
->dev
,
8795 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
8796 vsi
->num_q_vectors
, vsi
->seid
, ret
);
8797 vsi
->num_q_vectors
= 0;
8798 goto vector_setup_out
;
8801 if (vsi
->num_q_vectors
)
8802 vsi
->base_vector
= i40e_get_lump(pf
, pf
->irq_pile
,
8803 vsi
->num_q_vectors
, vsi
->idx
);
8804 if (vsi
->base_vector
< 0) {
8805 dev_info(&pf
->pdev
->dev
,
8806 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
8807 vsi
->num_q_vectors
, vsi
->seid
, vsi
->base_vector
);
8808 i40e_vsi_free_q_vectors(vsi
);
8810 goto vector_setup_out
;
8818 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
8819 * @vsi: pointer to the vsi.
8821 * This re-allocates a vsi's queue resources.
8823 * Returns pointer to the successfully allocated and configured VSI sw struct
8824 * on success, otherwise returns NULL on failure.
8826 static struct i40e_vsi
*i40e_vsi_reinit_setup(struct i40e_vsi
*vsi
)
8828 struct i40e_pf
*pf
= vsi
->back
;
8832 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
8833 i40e_vsi_clear_rings(vsi
);
8835 i40e_vsi_free_arrays(vsi
, false);
8836 i40e_set_num_rings_in_vsi(vsi
);
8837 ret
= i40e_vsi_alloc_arrays(vsi
, false);
8841 ret
= i40e_get_lump(pf
, pf
->qp_pile
, vsi
->alloc_queue_pairs
, vsi
->idx
);
8843 dev_info(&pf
->pdev
->dev
,
8844 "failed to get tracking for %d queues for VSI %d err %d\n",
8845 vsi
->alloc_queue_pairs
, vsi
->seid
, ret
);
8848 vsi
->base_queue
= ret
;
8850 /* Update the FW view of the VSI. Force a reset of TC and queue
8851 * layout configurations.
8853 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
8854 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
8855 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
8856 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
8858 /* assign it some queues */
8859 ret
= i40e_alloc_rings(vsi
);
8863 /* map all of the rings to the q_vectors */
8864 i40e_vsi_map_rings_to_vectors(vsi
);
8868 i40e_vsi_free_q_vectors(vsi
);
8869 if (vsi
->netdev_registered
) {
8870 vsi
->netdev_registered
= false;
8871 unregister_netdev(vsi
->netdev
);
8872 free_netdev(vsi
->netdev
);
8875 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
8877 i40e_vsi_clear(vsi
);
8882 * i40e_vsi_setup - Set up a VSI by a given type
8883 * @pf: board private structure
8885 * @uplink_seid: the switch element to link to
8886 * @param1: usage depends upon VSI type. For VF types, indicates VF id
8888 * This allocates the sw VSI structure and its queue resources, then add a VSI
8889 * to the identified VEB.
8891 * Returns pointer to the successfully allocated and configure VSI sw struct on
8892 * success, otherwise returns NULL on failure.
8894 struct i40e_vsi
*i40e_vsi_setup(struct i40e_pf
*pf
, u8 type
,
8895 u16 uplink_seid
, u32 param1
)
8897 struct i40e_vsi
*vsi
= NULL
;
8898 struct i40e_veb
*veb
= NULL
;
8902 /* The requested uplink_seid must be either
8903 * - the PF's port seid
8904 * no VEB is needed because this is the PF
8905 * or this is a Flow Director special case VSI
8906 * - seid of an existing VEB
8907 * - seid of a VSI that owns an existing VEB
8908 * - seid of a VSI that doesn't own a VEB
8909 * a new VEB is created and the VSI becomes the owner
8910 * - seid of the PF VSI, which is what creates the first VEB
8911 * this is a special case of the previous
8913 * Find which uplink_seid we were given and create a new VEB if needed
8915 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
8916 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== uplink_seid
) {
8922 if (!veb
&& uplink_seid
!= pf
->mac_seid
) {
8924 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
8925 if (pf
->vsi
[i
] && pf
->vsi
[i
]->seid
== uplink_seid
) {
8931 dev_info(&pf
->pdev
->dev
, "no such uplink_seid %d\n",
8936 if (vsi
->uplink_seid
== pf
->mac_seid
)
8937 veb
= i40e_veb_setup(pf
, 0, pf
->mac_seid
, vsi
->seid
,
8938 vsi
->tc_config
.enabled_tc
);
8939 else if ((vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0)
8940 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
8941 vsi
->tc_config
.enabled_tc
);
8943 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
) {
8944 dev_info(&vsi
->back
->pdev
->dev
,
8945 "%s: New VSI creation error, uplink seid of LAN VSI expected.\n",
8949 /* We come up by default in VEPA mode if SRIOV is not
8950 * already enabled, in which case we can't force VEPA
8953 if (!(pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)) {
8954 veb
->bridge_mode
= BRIDGE_MODE_VEPA
;
8955 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
8957 i40e_config_bridge_mode(veb
);
8959 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
8960 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
8964 dev_info(&pf
->pdev
->dev
, "couldn't add VEB\n");
8968 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
8969 uplink_seid
= veb
->seid
;
8972 /* get vsi sw struct */
8973 v_idx
= i40e_vsi_mem_alloc(pf
, type
);
8976 vsi
= pf
->vsi
[v_idx
];
8980 vsi
->veb_idx
= (veb
? veb
->idx
: I40E_NO_VEB
);
8982 if (type
== I40E_VSI_MAIN
)
8983 pf
->lan_vsi
= v_idx
;
8984 else if (type
== I40E_VSI_SRIOV
)
8985 vsi
->vf_id
= param1
;
8986 /* assign it some queues */
8987 ret
= i40e_get_lump(pf
, pf
->qp_pile
, vsi
->alloc_queue_pairs
,
8990 dev_info(&pf
->pdev
->dev
,
8991 "failed to get tracking for %d queues for VSI %d err=%d\n",
8992 vsi
->alloc_queue_pairs
, vsi
->seid
, ret
);
8995 vsi
->base_queue
= ret
;
8997 /* get a VSI from the hardware */
8998 vsi
->uplink_seid
= uplink_seid
;
8999 ret
= i40e_add_vsi(vsi
);
9003 switch (vsi
->type
) {
9004 /* setup the netdev if needed */
9006 case I40E_VSI_VMDQ2
:
9008 ret
= i40e_config_netdev(vsi
);
9011 ret
= register_netdev(vsi
->netdev
);
9014 vsi
->netdev_registered
= true;
9015 netif_carrier_off(vsi
->netdev
);
9016 #ifdef CONFIG_I40E_DCB
9017 /* Setup DCB netlink interface */
9018 i40e_dcbnl_setup(vsi
);
9019 #endif /* CONFIG_I40E_DCB */
9023 /* set up vectors and rings if needed */
9024 ret
= i40e_vsi_setup_vectors(vsi
);
9028 ret
= i40e_alloc_rings(vsi
);
9032 /* map all of the rings to the q_vectors */
9033 i40e_vsi_map_rings_to_vectors(vsi
);
9035 i40e_vsi_reset_stats(vsi
);
9039 /* no netdev or rings for the other VSI types */
9043 if ((pf
->flags
& I40E_FLAG_RSS_AQ_CAPABLE
) &&
9044 (vsi
->type
== I40E_VSI_VMDQ2
)) {
9045 ret
= i40e_vsi_config_rss(vsi
);
9050 i40e_vsi_free_q_vectors(vsi
);
9052 if (vsi
->netdev_registered
) {
9053 vsi
->netdev_registered
= false;
9054 unregister_netdev(vsi
->netdev
);
9055 free_netdev(vsi
->netdev
);
9059 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
9061 i40e_vsi_clear(vsi
);
9067 * i40e_veb_get_bw_info - Query VEB BW information
9068 * @veb: the veb to query
9070 * Query the Tx scheduler BW configuration data for given VEB
9072 static int i40e_veb_get_bw_info(struct i40e_veb
*veb
)
9074 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data
;
9075 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data
;
9076 struct i40e_pf
*pf
= veb
->pf
;
9077 struct i40e_hw
*hw
= &pf
->hw
;
9082 ret
= i40e_aq_query_switch_comp_bw_config(hw
, veb
->seid
,
9085 dev_info(&pf
->pdev
->dev
,
9086 "query veb bw config failed, err %s aq_err %s\n",
9087 i40e_stat_str(&pf
->hw
, ret
),
9088 i40e_aq_str(&pf
->hw
, hw
->aq
.asq_last_status
));
9092 ret
= i40e_aq_query_switch_comp_ets_config(hw
, veb
->seid
,
9095 dev_info(&pf
->pdev
->dev
,
9096 "query veb bw ets config failed, err %s aq_err %s\n",
9097 i40e_stat_str(&pf
->hw
, ret
),
9098 i40e_aq_str(&pf
->hw
, hw
->aq
.asq_last_status
));
9102 veb
->bw_limit
= le16_to_cpu(ets_data
.port_bw_limit
);
9103 veb
->bw_max_quanta
= ets_data
.tc_bw_max
;
9104 veb
->is_abs_credits
= bw_data
.absolute_credits_enable
;
9105 veb
->enabled_tc
= ets_data
.tc_valid_bits
;
9106 tc_bw_max
= le16_to_cpu(bw_data
.tc_bw_max
[0]) |
9107 (le16_to_cpu(bw_data
.tc_bw_max
[1]) << 16);
9108 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
9109 veb
->bw_tc_share_credits
[i
] = bw_data
.tc_bw_share_credits
[i
];
9110 veb
->bw_tc_limit_credits
[i
] =
9111 le16_to_cpu(bw_data
.tc_bw_limits
[i
]);
9112 veb
->bw_tc_max_quanta
[i
] = ((tc_bw_max
>> (i
*4)) & 0x7);
9120 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
9121 * @pf: board private structure
9123 * On error: returns error code (negative)
9124 * On success: returns vsi index in PF (positive)
9126 static int i40e_veb_mem_alloc(struct i40e_pf
*pf
)
9129 struct i40e_veb
*veb
;
9132 /* Need to protect the allocation of switch elements at the PF level */
9133 mutex_lock(&pf
->switch_mutex
);
9135 /* VEB list may be fragmented if VEB creation/destruction has
9136 * been happening. We can afford to do a quick scan to look
9137 * for any free slots in the list.
9139 * find next empty veb slot, looping back around if necessary
9142 while ((i
< I40E_MAX_VEB
) && (pf
->veb
[i
] != NULL
))
9144 if (i
>= I40E_MAX_VEB
) {
9146 goto err_alloc_veb
; /* out of VEB slots! */
9149 veb
= kzalloc(sizeof(*veb
), GFP_KERNEL
);
9156 veb
->enabled_tc
= 1;
9161 mutex_unlock(&pf
->switch_mutex
);
9166 * i40e_switch_branch_release - Delete a branch of the switch tree
9167 * @branch: where to start deleting
9169 * This uses recursion to find the tips of the branch to be
9170 * removed, deleting until we get back to and can delete this VEB.
9172 static void i40e_switch_branch_release(struct i40e_veb
*branch
)
9174 struct i40e_pf
*pf
= branch
->pf
;
9175 u16 branch_seid
= branch
->seid
;
9176 u16 veb_idx
= branch
->idx
;
9179 /* release any VEBs on this VEB - RECURSION */
9180 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
9183 if (pf
->veb
[i
]->uplink_seid
== branch
->seid
)
9184 i40e_switch_branch_release(pf
->veb
[i
]);
9187 /* Release the VSIs on this VEB, but not the owner VSI.
9189 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
9190 * the VEB itself, so don't use (*branch) after this loop.
9192 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9195 if (pf
->vsi
[i
]->uplink_seid
== branch_seid
&&
9196 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
9197 i40e_vsi_release(pf
->vsi
[i
]);
9201 /* There's one corner case where the VEB might not have been
9202 * removed, so double check it here and remove it if needed.
9203 * This case happens if the veb was created from the debugfs
9204 * commands and no VSIs were added to it.
9206 if (pf
->veb
[veb_idx
])
9207 i40e_veb_release(pf
->veb
[veb_idx
]);
9211 * i40e_veb_clear - remove veb struct
9212 * @veb: the veb to remove
9214 static void i40e_veb_clear(struct i40e_veb
*veb
)
9220 struct i40e_pf
*pf
= veb
->pf
;
9222 mutex_lock(&pf
->switch_mutex
);
9223 if (pf
->veb
[veb
->idx
] == veb
)
9224 pf
->veb
[veb
->idx
] = NULL
;
9225 mutex_unlock(&pf
->switch_mutex
);
9232 * i40e_veb_release - Delete a VEB and free its resources
9233 * @veb: the VEB being removed
9235 void i40e_veb_release(struct i40e_veb
*veb
)
9237 struct i40e_vsi
*vsi
= NULL
;
9243 /* find the remaining VSI and check for extras */
9244 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9245 if (pf
->vsi
[i
] && pf
->vsi
[i
]->uplink_seid
== veb
->seid
) {
9251 dev_info(&pf
->pdev
->dev
,
9252 "can't remove VEB %d with %d VSIs left\n",
9257 /* move the remaining VSI to uplink veb */
9258 vsi
->flags
&= ~I40E_VSI_FLAG_VEB_OWNER
;
9259 if (veb
->uplink_seid
) {
9260 vsi
->uplink_seid
= veb
->uplink_seid
;
9261 if (veb
->uplink_seid
== pf
->mac_seid
)
9262 vsi
->veb_idx
= I40E_NO_VEB
;
9264 vsi
->veb_idx
= veb
->veb_idx
;
9267 vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
9268 vsi
->veb_idx
= pf
->vsi
[pf
->lan_vsi
]->veb_idx
;
9271 i40e_aq_delete_element(&pf
->hw
, veb
->seid
, NULL
);
9272 i40e_veb_clear(veb
);
9276 * i40e_add_veb - create the VEB in the switch
9277 * @veb: the VEB to be instantiated
9278 * @vsi: the controlling VSI
9280 static int i40e_add_veb(struct i40e_veb
*veb
, struct i40e_vsi
*vsi
)
9282 struct i40e_pf
*pf
= veb
->pf
;
9283 bool is_default
= false;
9284 bool is_cloud
= false;
9287 /* get a VEB from the hardware */
9288 ret
= i40e_aq_add_veb(&pf
->hw
, veb
->uplink_seid
, vsi
->seid
,
9289 veb
->enabled_tc
, is_default
,
9290 is_cloud
, &veb
->seid
, NULL
);
9292 dev_info(&pf
->pdev
->dev
,
9293 "couldn't add VEB, err %s aq_err %s\n",
9294 i40e_stat_str(&pf
->hw
, ret
),
9295 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9299 /* get statistics counter */
9300 ret
= i40e_aq_get_veb_parameters(&pf
->hw
, veb
->seid
, NULL
, NULL
,
9301 &veb
->stats_idx
, NULL
, NULL
, NULL
);
9303 dev_info(&pf
->pdev
->dev
,
9304 "couldn't get VEB statistics idx, err %s aq_err %s\n",
9305 i40e_stat_str(&pf
->hw
, ret
),
9306 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9309 ret
= i40e_veb_get_bw_info(veb
);
9311 dev_info(&pf
->pdev
->dev
,
9312 "couldn't get VEB bw info, err %s aq_err %s\n",
9313 i40e_stat_str(&pf
->hw
, ret
),
9314 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9315 i40e_aq_delete_element(&pf
->hw
, veb
->seid
, NULL
);
9319 vsi
->uplink_seid
= veb
->seid
;
9320 vsi
->veb_idx
= veb
->idx
;
9321 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
9327 * i40e_veb_setup - Set up a VEB
9328 * @pf: board private structure
9329 * @flags: VEB setup flags
9330 * @uplink_seid: the switch element to link to
9331 * @vsi_seid: the initial VSI seid
9332 * @enabled_tc: Enabled TC bit-map
9334 * This allocates the sw VEB structure and links it into the switch
9335 * It is possible and legal for this to be a duplicate of an already
9336 * existing VEB. It is also possible for both uplink and vsi seids
9337 * to be zero, in order to create a floating VEB.
9339 * Returns pointer to the successfully allocated VEB sw struct on
9340 * success, otherwise returns NULL on failure.
9342 struct i40e_veb
*i40e_veb_setup(struct i40e_pf
*pf
, u16 flags
,
9343 u16 uplink_seid
, u16 vsi_seid
,
9346 struct i40e_veb
*veb
, *uplink_veb
= NULL
;
9347 int vsi_idx
, veb_idx
;
9350 /* if one seid is 0, the other must be 0 to create a floating relay */
9351 if ((uplink_seid
== 0 || vsi_seid
== 0) &&
9352 (uplink_seid
+ vsi_seid
!= 0)) {
9353 dev_info(&pf
->pdev
->dev
,
9354 "one, not both seid's are 0: uplink=%d vsi=%d\n",
9355 uplink_seid
, vsi_seid
);
9359 /* make sure there is such a vsi and uplink */
9360 for (vsi_idx
= 0; vsi_idx
< pf
->num_alloc_vsi
; vsi_idx
++)
9361 if (pf
->vsi
[vsi_idx
] && pf
->vsi
[vsi_idx
]->seid
== vsi_seid
)
9363 if (vsi_idx
>= pf
->num_alloc_vsi
&& vsi_seid
!= 0) {
9364 dev_info(&pf
->pdev
->dev
, "vsi seid %d not found\n",
9369 if (uplink_seid
&& uplink_seid
!= pf
->mac_seid
) {
9370 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
9371 if (pf
->veb
[veb_idx
] &&
9372 pf
->veb
[veb_idx
]->seid
== uplink_seid
) {
9373 uplink_veb
= pf
->veb
[veb_idx
];
9378 dev_info(&pf
->pdev
->dev
,
9379 "uplink seid %d not found\n", uplink_seid
);
9384 /* get veb sw struct */
9385 veb_idx
= i40e_veb_mem_alloc(pf
);
9388 veb
= pf
->veb
[veb_idx
];
9390 veb
->uplink_seid
= uplink_seid
;
9391 veb
->veb_idx
= (uplink_veb
? uplink_veb
->idx
: I40E_NO_VEB
);
9392 veb
->enabled_tc
= (enabled_tc
? enabled_tc
: 0x1);
9394 /* create the VEB in the switch */
9395 ret
= i40e_add_veb(veb
, pf
->vsi
[vsi_idx
]);
9398 if (vsi_idx
== pf
->lan_vsi
)
9399 pf
->lan_veb
= veb
->idx
;
9404 i40e_veb_clear(veb
);
9410 * i40e_setup_pf_switch_element - set PF vars based on switch type
9411 * @pf: board private structure
9412 * @ele: element we are building info from
9413 * @num_reported: total number of elements
9414 * @printconfig: should we print the contents
9416 * helper function to assist in extracting a few useful SEID values.
9418 static void i40e_setup_pf_switch_element(struct i40e_pf
*pf
,
9419 struct i40e_aqc_switch_config_element_resp
*ele
,
9420 u16 num_reported
, bool printconfig
)
9422 u16 downlink_seid
= le16_to_cpu(ele
->downlink_seid
);
9423 u16 uplink_seid
= le16_to_cpu(ele
->uplink_seid
);
9424 u8 element_type
= ele
->element_type
;
9425 u16 seid
= le16_to_cpu(ele
->seid
);
9428 dev_info(&pf
->pdev
->dev
,
9429 "type=%d seid=%d uplink=%d downlink=%d\n",
9430 element_type
, seid
, uplink_seid
, downlink_seid
);
9432 switch (element_type
) {
9433 case I40E_SWITCH_ELEMENT_TYPE_MAC
:
9434 pf
->mac_seid
= seid
;
9436 case I40E_SWITCH_ELEMENT_TYPE_VEB
:
9438 if (uplink_seid
!= pf
->mac_seid
)
9440 if (pf
->lan_veb
== I40E_NO_VEB
) {
9443 /* find existing or else empty VEB */
9444 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
9445 if (pf
->veb
[v
] && (pf
->veb
[v
]->seid
== seid
)) {
9450 if (pf
->lan_veb
== I40E_NO_VEB
) {
9451 v
= i40e_veb_mem_alloc(pf
);
9458 pf
->veb
[pf
->lan_veb
]->seid
= seid
;
9459 pf
->veb
[pf
->lan_veb
]->uplink_seid
= pf
->mac_seid
;
9460 pf
->veb
[pf
->lan_veb
]->pf
= pf
;
9461 pf
->veb
[pf
->lan_veb
]->veb_idx
= I40E_NO_VEB
;
9463 case I40E_SWITCH_ELEMENT_TYPE_VSI
:
9464 if (num_reported
!= 1)
9466 /* This is immediately after a reset so we can assume this is
9469 pf
->mac_seid
= uplink_seid
;
9470 pf
->pf_seid
= downlink_seid
;
9471 pf
->main_vsi_seid
= seid
;
9473 dev_info(&pf
->pdev
->dev
,
9474 "pf_seid=%d main_vsi_seid=%d\n",
9475 pf
->pf_seid
, pf
->main_vsi_seid
);
9477 case I40E_SWITCH_ELEMENT_TYPE_PF
:
9478 case I40E_SWITCH_ELEMENT_TYPE_VF
:
9479 case I40E_SWITCH_ELEMENT_TYPE_EMP
:
9480 case I40E_SWITCH_ELEMENT_TYPE_BMC
:
9481 case I40E_SWITCH_ELEMENT_TYPE_PE
:
9482 case I40E_SWITCH_ELEMENT_TYPE_PA
:
9483 /* ignore these for now */
9486 dev_info(&pf
->pdev
->dev
, "unknown element type=%d seid=%d\n",
9487 element_type
, seid
);
9493 * i40e_fetch_switch_configuration - Get switch config from firmware
9494 * @pf: board private structure
9495 * @printconfig: should we print the contents
9497 * Get the current switch configuration from the device and
9498 * extract a few useful SEID values.
9500 int i40e_fetch_switch_configuration(struct i40e_pf
*pf
, bool printconfig
)
9502 struct i40e_aqc_get_switch_config_resp
*sw_config
;
9508 aq_buf
= kzalloc(I40E_AQ_LARGE_BUF
, GFP_KERNEL
);
9512 sw_config
= (struct i40e_aqc_get_switch_config_resp
*)aq_buf
;
9514 u16 num_reported
, num_total
;
9516 ret
= i40e_aq_get_switch_config(&pf
->hw
, sw_config
,
9520 dev_info(&pf
->pdev
->dev
,
9521 "get switch config failed err %s aq_err %s\n",
9522 i40e_stat_str(&pf
->hw
, ret
),
9523 i40e_aq_str(&pf
->hw
,
9524 pf
->hw
.aq
.asq_last_status
));
9529 num_reported
= le16_to_cpu(sw_config
->header
.num_reported
);
9530 num_total
= le16_to_cpu(sw_config
->header
.num_total
);
9533 dev_info(&pf
->pdev
->dev
,
9534 "header: %d reported %d total\n",
9535 num_reported
, num_total
);
9537 for (i
= 0; i
< num_reported
; i
++) {
9538 struct i40e_aqc_switch_config_element_resp
*ele
=
9539 &sw_config
->element
[i
];
9541 i40e_setup_pf_switch_element(pf
, ele
, num_reported
,
9544 } while (next_seid
!= 0);
9551 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
9552 * @pf: board private structure
9553 * @reinit: if the Main VSI needs to re-initialized.
9555 * Returns 0 on success, negative value on failure
9557 static int i40e_setup_pf_switch(struct i40e_pf
*pf
, bool reinit
)
9561 /* find out what's out there already */
9562 ret
= i40e_fetch_switch_configuration(pf
, false);
9564 dev_info(&pf
->pdev
->dev
,
9565 "couldn't fetch switch config, err %s aq_err %s\n",
9566 i40e_stat_str(&pf
->hw
, ret
),
9567 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
9570 i40e_pf_reset_stats(pf
);
9572 /* first time setup */
9573 if (pf
->lan_vsi
== I40E_NO_VSI
|| reinit
) {
9574 struct i40e_vsi
*vsi
= NULL
;
9577 /* Set up the PF VSI associated with the PF's main VSI
9578 * that is already in the HW switch
9580 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
9581 uplink_seid
= pf
->veb
[pf
->lan_veb
]->seid
;
9583 uplink_seid
= pf
->mac_seid
;
9584 if (pf
->lan_vsi
== I40E_NO_VSI
)
9585 vsi
= i40e_vsi_setup(pf
, I40E_VSI_MAIN
, uplink_seid
, 0);
9587 vsi
= i40e_vsi_reinit_setup(pf
->vsi
[pf
->lan_vsi
]);
9589 dev_info(&pf
->pdev
->dev
, "setup of MAIN VSI failed\n");
9590 i40e_fdir_teardown(pf
);
9594 /* force a reset of TC and queue layout configurations */
9595 u8 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
9596 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
9597 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
9598 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
9600 i40e_vlan_stripping_disable(pf
->vsi
[pf
->lan_vsi
]);
9602 i40e_fdir_sb_setup(pf
);
9604 /* Setup static PF queue filter control settings */
9605 ret
= i40e_setup_pf_filter_control(pf
);
9607 dev_info(&pf
->pdev
->dev
, "setup_pf_filter_control failed: %d\n",
9609 /* Failure here should not stop continuing other steps */
9612 /* enable RSS in the HW, even for only one queue, as the stack can use
9615 if ((pf
->flags
& I40E_FLAG_RSS_ENABLED
))
9616 i40e_config_rss(pf
);
9618 /* fill in link information and enable LSE reporting */
9619 i40e_aq_get_link_info(&pf
->hw
, true, NULL
, NULL
);
9620 i40e_link_event(pf
);
9622 /* Initialize user-specific link properties */
9623 pf
->fc_autoneg_status
= ((pf
->hw
.phy
.link_info
.an_info
&
9624 I40E_AQ_AN_COMPLETED
) ? true : false);
9632 * i40e_determine_queue_usage - Work out queue distribution
9633 * @pf: board private structure
9635 static void i40e_determine_queue_usage(struct i40e_pf
*pf
)
9639 pf
->num_lan_qps
= 0;
9641 pf
->num_fcoe_qps
= 0;
9644 /* Find the max queues to be put into basic use. We'll always be
9645 * using TC0, whether or not DCB is running, and TC0 will get the
9648 queues_left
= pf
->hw
.func_caps
.num_tx_qp
;
9650 if ((queues_left
== 1) ||
9651 !(pf
->flags
& I40E_FLAG_MSIX_ENABLED
)) {
9652 /* one qp for PF, no queues for anything else */
9654 pf
->rss_size
= pf
->num_lan_qps
= 1;
9656 /* make sure all the fancies are disabled */
9657 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
9659 I40E_FLAG_FCOE_ENABLED
|
9661 I40E_FLAG_FD_SB_ENABLED
|
9662 I40E_FLAG_FD_ATR_ENABLED
|
9663 I40E_FLAG_DCB_CAPABLE
|
9664 I40E_FLAG_SRIOV_ENABLED
|
9665 I40E_FLAG_VMDQ_ENABLED
);
9666 } else if (!(pf
->flags
& (I40E_FLAG_RSS_ENABLED
|
9667 I40E_FLAG_FD_SB_ENABLED
|
9668 I40E_FLAG_FD_ATR_ENABLED
|
9669 I40E_FLAG_DCB_CAPABLE
))) {
9671 pf
->rss_size
= pf
->num_lan_qps
= 1;
9672 queues_left
-= pf
->num_lan_qps
;
9674 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
9676 I40E_FLAG_FCOE_ENABLED
|
9678 I40E_FLAG_FD_SB_ENABLED
|
9679 I40E_FLAG_FD_ATR_ENABLED
|
9680 I40E_FLAG_DCB_ENABLED
|
9681 I40E_FLAG_VMDQ_ENABLED
);
9683 /* Not enough queues for all TCs */
9684 if ((pf
->flags
& I40E_FLAG_DCB_CAPABLE
) &&
9685 (queues_left
< I40E_MAX_TRAFFIC_CLASS
)) {
9686 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
9687 dev_info(&pf
->pdev
->dev
, "not enough queues for DCB. DCB is disabled.\n");
9689 pf
->num_lan_qps
= max_t(int, pf
->rss_size_max
,
9691 pf
->num_lan_qps
= min_t(int, pf
->num_lan_qps
,
9692 pf
->hw
.func_caps
.num_tx_qp
);
9694 queues_left
-= pf
->num_lan_qps
;
9698 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
9699 if (I40E_DEFAULT_FCOE
<= queues_left
) {
9700 pf
->num_fcoe_qps
= I40E_DEFAULT_FCOE
;
9701 } else if (I40E_MINIMUM_FCOE
<= queues_left
) {
9702 pf
->num_fcoe_qps
= I40E_MINIMUM_FCOE
;
9704 pf
->num_fcoe_qps
= 0;
9705 pf
->flags
&= ~I40E_FLAG_FCOE_ENABLED
;
9706 dev_info(&pf
->pdev
->dev
, "not enough queues for FCoE. FCoE feature will be disabled\n");
9709 queues_left
-= pf
->num_fcoe_qps
;
9713 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
9714 if (queues_left
> 1) {
9715 queues_left
-= 1; /* save 1 queue for FD */
9717 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
9718 dev_info(&pf
->pdev
->dev
, "not enough queues for Flow Director. Flow Director feature is disabled\n");
9722 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
9723 pf
->num_vf_qps
&& pf
->num_req_vfs
&& queues_left
) {
9724 pf
->num_req_vfs
= min_t(int, pf
->num_req_vfs
,
9725 (queues_left
/ pf
->num_vf_qps
));
9726 queues_left
-= (pf
->num_req_vfs
* pf
->num_vf_qps
);
9729 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
9730 pf
->num_vmdq_vsis
&& pf
->num_vmdq_qps
&& queues_left
) {
9731 pf
->num_vmdq_vsis
= min_t(int, pf
->num_vmdq_vsis
,
9732 (queues_left
/ pf
->num_vmdq_qps
));
9733 queues_left
-= (pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
);
9736 pf
->queues_left
= queues_left
;
9738 dev_info(&pf
->pdev
->dev
, "fcoe queues = %d\n", pf
->num_fcoe_qps
);
9743 * i40e_setup_pf_filter_control - Setup PF static filter control
9744 * @pf: PF to be setup
9746 * i40e_setup_pf_filter_control sets up a PF's initial filter control
9747 * settings. If PE/FCoE are enabled then it will also set the per PF
9748 * based filter sizes required for them. It also enables Flow director,
9749 * ethertype and macvlan type filter settings for the pf.
9751 * Returns 0 on success, negative on failure
9753 static int i40e_setup_pf_filter_control(struct i40e_pf
*pf
)
9755 struct i40e_filter_control_settings
*settings
= &pf
->filter_settings
;
9757 settings
->hash_lut_size
= I40E_HASH_LUT_SIZE_128
;
9759 /* Flow Director is enabled */
9760 if (pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
))
9761 settings
->enable_fdir
= true;
9763 /* Ethtype and MACVLAN filters enabled for PF */
9764 settings
->enable_ethtype
= true;
9765 settings
->enable_macvlan
= true;
9767 if (i40e_set_filter_control(&pf
->hw
, settings
))
9773 #define INFO_STRING_LEN 255
9774 static void i40e_print_features(struct i40e_pf
*pf
)
9776 struct i40e_hw
*hw
= &pf
->hw
;
9779 string
= kzalloc(INFO_STRING_LEN
, GFP_KERNEL
);
9781 dev_err(&pf
->pdev
->dev
, "Features string allocation failed\n");
9787 buf
+= sprintf(string
, "Features: PF-id[%d] ", hw
->pf_id
);
9788 #ifdef CONFIG_PCI_IOV
9789 buf
+= sprintf(buf
, "VFs: %d ", pf
->num_req_vfs
);
9791 buf
+= sprintf(buf
, "VSIs: %d QP: %d RX: %s ",
9792 pf
->hw
.func_caps
.num_vsis
,
9793 pf
->vsi
[pf
->lan_vsi
]->num_queue_pairs
,
9794 pf
->flags
& I40E_FLAG_RX_PS_ENABLED
? "PS" : "1BUF");
9796 if (pf
->flags
& I40E_FLAG_RSS_ENABLED
)
9797 buf
+= sprintf(buf
, "RSS ");
9798 if (pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
)
9799 buf
+= sprintf(buf
, "FD_ATR ");
9800 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
9801 buf
+= sprintf(buf
, "FD_SB ");
9802 buf
+= sprintf(buf
, "NTUPLE ");
9804 if (pf
->flags
& I40E_FLAG_DCB_CAPABLE
)
9805 buf
+= sprintf(buf
, "DCB ");
9806 if (pf
->flags
& I40E_FLAG_PTP
)
9807 buf
+= sprintf(buf
, "PTP ");
9809 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
)
9810 buf
+= sprintf(buf
, "FCOE ");
9813 BUG_ON(buf
> (string
+ INFO_STRING_LEN
));
9814 dev_info(&pf
->pdev
->dev
, "%s\n", string
);
9819 * i40e_probe - Device initialization routine
9820 * @pdev: PCI device information struct
9821 * @ent: entry in i40e_pci_tbl
9823 * i40e_probe initializes a PF identified by a pci_dev structure.
9824 * The OS initialization, configuring of the PF private structure,
9825 * and a hardware reset occur.
9827 * Returns 0 on success, negative on failure
9829 static int i40e_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
9831 struct i40e_aq_get_phy_abilities_resp abilities
;
9832 unsigned long ioremap_len
;
9835 static u16 pfs_found
;
9841 err
= pci_enable_device_mem(pdev
);
9845 /* set up for high or low dma */
9846 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
9848 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
9851 "DMA configuration failed: 0x%x\n", err
);
9856 /* set up pci connections */
9857 err
= pci_request_selected_regions(pdev
, pci_select_bars(pdev
,
9858 IORESOURCE_MEM
), i40e_driver_name
);
9860 dev_info(&pdev
->dev
,
9861 "pci_request_selected_regions failed %d\n", err
);
9865 pci_enable_pcie_error_reporting(pdev
);
9866 pci_set_master(pdev
);
9868 /* Now that we have a PCI connection, we need to do the
9869 * low level device setup. This is primarily setting up
9870 * the Admin Queue structures and then querying for the
9871 * device's current profile information.
9873 pf
= kzalloc(sizeof(*pf
), GFP_KERNEL
);
9880 set_bit(__I40E_DOWN
, &pf
->state
);
9885 ioremap_len
= min_t(unsigned long, pci_resource_len(pdev
, 0),
9886 I40E_MAX_CSR_SPACE
);
9888 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0), ioremap_len
);
9891 dev_info(&pdev
->dev
, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
9892 (unsigned int)pci_resource_start(pdev
, 0),
9893 (unsigned int)pci_resource_len(pdev
, 0), err
);
9896 hw
->vendor_id
= pdev
->vendor
;
9897 hw
->device_id
= pdev
->device
;
9898 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
9899 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
9900 hw
->subsystem_device_id
= pdev
->subsystem_device
;
9901 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
9902 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
9903 pf
->instance
= pfs_found
;
9906 pf
->msg_enable
= pf
->hw
.debug_mask
;
9907 pf
->msg_enable
= debug
;
9910 /* do a special CORER for clearing PXE mode once at init */
9911 if (hw
->revision_id
== 0 &&
9912 (rd32(hw
, I40E_GLLAN_RCTL_0
) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK
)) {
9913 wr32(hw
, I40E_GLGEN_RTRIG
, I40E_GLGEN_RTRIG_CORER_MASK
);
9918 i40e_clear_pxe_mode(hw
);
9921 /* Reset here to make sure all is clean and to define PF 'n' */
9923 err
= i40e_pf_reset(hw
);
9925 dev_info(&pdev
->dev
, "Initial pf_reset failed: %d\n", err
);
9930 hw
->aq
.num_arq_entries
= I40E_AQ_LEN
;
9931 hw
->aq
.num_asq_entries
= I40E_AQ_LEN
;
9932 hw
->aq
.arq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
9933 hw
->aq
.asq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
9934 pf
->adminq_work_limit
= I40E_AQ_WORK_LIMIT
;
9936 snprintf(pf
->int_name
, sizeof(pf
->int_name
) - 1,
9938 dev_driver_string(&pf
->pdev
->dev
), dev_name(&pdev
->dev
));
9940 err
= i40e_init_shared_code(hw
);
9942 dev_warn(&pdev
->dev
, "unidentified MAC or BLANK NVM: %d\n",
9947 /* set up a default setting for link flow control */
9948 pf
->hw
.fc
.requested_mode
= I40E_FC_NONE
;
9950 err
= i40e_init_adminq(hw
);
9951 dev_info(&pdev
->dev
, "%s\n", i40e_fw_version_str(hw
));
9953 dev_info(&pdev
->dev
,
9954 "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");
9958 if (hw
->aq
.api_maj_ver
== I40E_FW_API_VERSION_MAJOR
&&
9959 hw
->aq
.api_min_ver
> I40E_FW_API_VERSION_MINOR
)
9960 dev_info(&pdev
->dev
,
9961 "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");
9962 else if (hw
->aq
.api_maj_ver
< I40E_FW_API_VERSION_MAJOR
||
9963 hw
->aq
.api_min_ver
< (I40E_FW_API_VERSION_MINOR
- 1))
9964 dev_info(&pdev
->dev
,
9965 "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
9967 i40e_verify_eeprom(pf
);
9969 /* Rev 0 hardware was never productized */
9970 if (hw
->revision_id
< 1)
9971 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");
9973 i40e_clear_pxe_mode(hw
);
9974 err
= i40e_get_capabilities(pf
);
9976 goto err_adminq_setup
;
9978 err
= i40e_sw_init(pf
);
9980 dev_info(&pdev
->dev
, "sw_init failed: %d\n", err
);
9984 err
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
9985 hw
->func_caps
.num_rx_qp
,
9986 pf
->fcoe_hmc_cntx_num
, pf
->fcoe_hmc_filt_num
);
9988 dev_info(&pdev
->dev
, "init_lan_hmc failed: %d\n", err
);
9989 goto err_init_lan_hmc
;
9992 err
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
9994 dev_info(&pdev
->dev
, "configure_lan_hmc failed: %d\n", err
);
9996 goto err_configure_lan_hmc
;
9999 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
10000 * Ignore error return codes because if it was already disabled via
10001 * hardware settings this will fail
10003 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 3)) ||
10004 (pf
->hw
.aq
.fw_maj_ver
< 4)) {
10005 dev_info(&pdev
->dev
, "Stopping firmware LLDP agent.\n");
10006 i40e_aq_stop_lldp(hw
, true, NULL
);
10009 i40e_get_mac_addr(hw
, hw
->mac
.addr
);
10010 if (!is_valid_ether_addr(hw
->mac
.addr
)) {
10011 dev_info(&pdev
->dev
, "invalid MAC address %pM\n", hw
->mac
.addr
);
10015 dev_info(&pdev
->dev
, "MAC address: %pM\n", hw
->mac
.addr
);
10016 ether_addr_copy(hw
->mac
.perm_addr
, hw
->mac
.addr
);
10017 i40e_get_port_mac_addr(hw
, hw
->mac
.port_addr
);
10018 if (is_valid_ether_addr(hw
->mac
.port_addr
))
10019 pf
->flags
|= I40E_FLAG_PORT_ID_VALID
;
10021 err
= i40e_get_san_mac_addr(hw
, hw
->mac
.san_addr
);
10023 dev_info(&pdev
->dev
,
10024 "(non-fatal) SAN MAC retrieval failed: %d\n", err
);
10025 if (!is_valid_ether_addr(hw
->mac
.san_addr
)) {
10026 dev_warn(&pdev
->dev
, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
10028 ether_addr_copy(hw
->mac
.san_addr
, hw
->mac
.addr
);
10030 dev_info(&pf
->pdev
->dev
, "SAN MAC: %pM\n", hw
->mac
.san_addr
);
10031 #endif /* I40E_FCOE */
10033 pci_set_drvdata(pdev
, pf
);
10034 pci_save_state(pdev
);
10035 #ifdef CONFIG_I40E_DCB
10036 err
= i40e_init_pf_dcb(pf
);
10038 dev_info(&pdev
->dev
, "DCB init failed %d, disabled\n", err
);
10039 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
10040 /* Continue without DCB enabled */
10042 #endif /* CONFIG_I40E_DCB */
10044 /* set up periodic task facility */
10045 setup_timer(&pf
->service_timer
, i40e_service_timer
, (unsigned long)pf
);
10046 pf
->service_timer_period
= HZ
;
10048 INIT_WORK(&pf
->service_task
, i40e_service_task
);
10049 clear_bit(__I40E_SERVICE_SCHED
, &pf
->state
);
10050 pf
->flags
|= I40E_FLAG_NEED_LINK_UPDATE
;
10051 pf
->link_check_timeout
= jiffies
;
10053 /* WoL defaults to disabled */
10054 pf
->wol_en
= false;
10055 device_set_wakeup_enable(&pf
->pdev
->dev
, pf
->wol_en
);
10057 /* set up the main switch operations */
10058 i40e_determine_queue_usage(pf
);
10059 err
= i40e_init_interrupt_scheme(pf
);
10061 goto err_switch_setup
;
10063 /* The number of VSIs reported by the FW is the minimum guaranteed
10064 * to us; HW supports far more and we share the remaining pool with
10065 * the other PFs. We allocate space for more than the guarantee with
10066 * the understanding that we might not get them all later.
10068 if (pf
->hw
.func_caps
.num_vsis
< I40E_MIN_VSI_ALLOC
)
10069 pf
->num_alloc_vsi
= I40E_MIN_VSI_ALLOC
;
10071 pf
->num_alloc_vsi
= pf
->hw
.func_caps
.num_vsis
;
10073 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
10074 len
= sizeof(struct i40e_vsi
*) * pf
->num_alloc_vsi
;
10075 pf
->vsi
= kzalloc(len
, GFP_KERNEL
);
10078 goto err_switch_setup
;
10081 #ifdef CONFIG_PCI_IOV
10082 /* prep for VF support */
10083 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
10084 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
10085 !test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
10086 if (pci_num_vf(pdev
))
10087 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
10090 err
= i40e_setup_pf_switch(pf
, false);
10092 dev_info(&pdev
->dev
, "setup_pf_switch failed: %d\n", err
);
10095 /* if FDIR VSI was set up, start it now */
10096 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
10097 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
10098 i40e_vsi_open(pf
->vsi
[i
]);
10103 /* driver is only interested in link up/down and module qualification
10104 * reports from firmware
10106 err
= i40e_aq_set_phy_int_mask(&pf
->hw
,
10107 I40E_AQ_EVENT_LINK_UPDOWN
|
10108 I40E_AQ_EVENT_MODULE_QUAL_FAIL
, NULL
);
10110 dev_info(&pf
->pdev
->dev
, "set phy mask fail, err %s aq_err %s\n",
10111 i40e_stat_str(&pf
->hw
, err
),
10112 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10114 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
10115 (pf
->hw
.aq
.fw_maj_ver
< 4)) {
10117 err
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
10119 dev_info(&pf
->pdev
->dev
, "link restart failed, err %s aq_err %s\n",
10120 i40e_stat_str(&pf
->hw
, err
),
10121 i40e_aq_str(&pf
->hw
,
10122 pf
->hw
.aq
.asq_last_status
));
10124 /* The main driver is (mostly) up and happy. We need to set this state
10125 * before setting up the misc vector or we get a race and the vector
10126 * ends up disabled forever.
10128 clear_bit(__I40E_DOWN
, &pf
->state
);
10130 /* In case of MSIX we are going to setup the misc vector right here
10131 * to handle admin queue events etc. In case of legacy and MSI
10132 * the misc functionality and queue processing is combined in
10133 * the same vector and that gets setup at open.
10135 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
10136 err
= i40e_setup_misc_vector(pf
);
10138 dev_info(&pdev
->dev
,
10139 "setup of misc vector failed: %d\n", err
);
10144 #ifdef CONFIG_PCI_IOV
10145 /* prep for VF support */
10146 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
10147 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
10148 !test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
10151 /* disable link interrupts for VFs */
10152 val
= rd32(hw
, I40E_PFGEN_PORTMDIO_NUM
);
10153 val
&= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK
;
10154 wr32(hw
, I40E_PFGEN_PORTMDIO_NUM
, val
);
10157 if (pci_num_vf(pdev
)) {
10158 dev_info(&pdev
->dev
,
10159 "Active VFs found, allocating resources.\n");
10160 err
= i40e_alloc_vfs(pf
, pci_num_vf(pdev
));
10162 dev_info(&pdev
->dev
,
10163 "Error %d allocating resources for existing VFs\n",
10167 #endif /* CONFIG_PCI_IOV */
10171 i40e_dbg_pf_init(pf
);
10173 /* tell the firmware that we're starting */
10174 i40e_send_version(pf
);
10176 /* since everything's happy, start the service_task timer */
10177 mod_timer(&pf
->service_timer
,
10178 round_jiffies(jiffies
+ pf
->service_timer_period
));
10181 /* create FCoE interface */
10182 i40e_fcoe_vsi_setup(pf
);
10185 /* Get the negotiated link width and speed from PCI config space */
10186 pcie_capability_read_word(pf
->pdev
, PCI_EXP_LNKSTA
, &link_status
);
10188 i40e_set_pci_config_data(hw
, link_status
);
10190 dev_info(&pdev
->dev
, "PCI-Express: %s %s\n",
10191 (hw
->bus
.speed
== i40e_bus_speed_8000
? "Speed 8.0GT/s" :
10192 hw
->bus
.speed
== i40e_bus_speed_5000
? "Speed 5.0GT/s" :
10193 hw
->bus
.speed
== i40e_bus_speed_2500
? "Speed 2.5GT/s" :
10195 (hw
->bus
.width
== i40e_bus_width_pcie_x8
? "Width x8" :
10196 hw
->bus
.width
== i40e_bus_width_pcie_x4
? "Width x4" :
10197 hw
->bus
.width
== i40e_bus_width_pcie_x2
? "Width x2" :
10198 hw
->bus
.width
== i40e_bus_width_pcie_x1
? "Width x1" :
10201 if (hw
->bus
.width
< i40e_bus_width_pcie_x8
||
10202 hw
->bus
.speed
< i40e_bus_speed_8000
) {
10203 dev_warn(&pdev
->dev
, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
10204 dev_warn(&pdev
->dev
, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
10207 /* get the requested speeds from the fw */
10208 err
= i40e_aq_get_phy_capabilities(hw
, false, false, &abilities
, NULL
);
10210 dev_info(&pf
->pdev
->dev
,
10211 "get phy capabilities failed, err %s aq_err %s, advertised speed settings may not be correct\n",
10212 i40e_stat_str(&pf
->hw
, err
),
10213 i40e_aq_str(&pf
->hw
, pf
->hw
.aq
.asq_last_status
));
10214 pf
->hw
.phy
.link_info
.requested_speeds
= abilities
.link_speed
;
10216 /* print a string summarizing features */
10217 i40e_print_features(pf
);
10221 /* Unwind what we've done if something failed in the setup */
10223 set_bit(__I40E_DOWN
, &pf
->state
);
10224 i40e_clear_interrupt_scheme(pf
);
10227 i40e_reset_interrupt_capability(pf
);
10228 del_timer_sync(&pf
->service_timer
);
10230 err_configure_lan_hmc
:
10231 (void)i40e_shutdown_lan_hmc(hw
);
10233 kfree(pf
->qp_pile
);
10236 (void)i40e_shutdown_adminq(hw
);
10238 iounmap(hw
->hw_addr
);
10242 pci_disable_pcie_error_reporting(pdev
);
10243 pci_release_selected_regions(pdev
,
10244 pci_select_bars(pdev
, IORESOURCE_MEM
));
10247 pci_disable_device(pdev
);
10252 * i40e_remove - Device removal routine
10253 * @pdev: PCI device information struct
10255 * i40e_remove is called by the PCI subsystem to alert the driver
10256 * that is should release a PCI device. This could be caused by a
10257 * Hot-Plug event, or because the driver is going to be removed from
10260 static void i40e_remove(struct pci_dev
*pdev
)
10262 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10263 i40e_status ret_code
;
10266 i40e_dbg_pf_exit(pf
);
10270 /* no more scheduling of any task */
10271 set_bit(__I40E_DOWN
, &pf
->state
);
10272 del_timer_sync(&pf
->service_timer
);
10273 cancel_work_sync(&pf
->service_task
);
10274 i40e_fdir_teardown(pf
);
10276 if (pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) {
10278 pf
->flags
&= ~I40E_FLAG_SRIOV_ENABLED
;
10281 i40e_fdir_teardown(pf
);
10283 /* If there is a switch structure or any orphans, remove them.
10284 * This will leave only the PF's VSI remaining.
10286 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
10290 if (pf
->veb
[i
]->uplink_seid
== pf
->mac_seid
||
10291 pf
->veb
[i
]->uplink_seid
== 0)
10292 i40e_switch_branch_release(pf
->veb
[i
]);
10295 /* Now we can shutdown the PF's VSI, just before we kill
10298 if (pf
->vsi
[pf
->lan_vsi
])
10299 i40e_vsi_release(pf
->vsi
[pf
->lan_vsi
]);
10301 /* shutdown and destroy the HMC */
10302 if (pf
->hw
.hmc
.hmc_obj
) {
10303 ret_code
= i40e_shutdown_lan_hmc(&pf
->hw
);
10305 dev_warn(&pdev
->dev
,
10306 "Failed to destroy the HMC resources: %d\n",
10310 /* shutdown the adminq */
10311 ret_code
= i40e_shutdown_adminq(&pf
->hw
);
10313 dev_warn(&pdev
->dev
,
10314 "Failed to destroy the Admin Queue resources: %d\n",
10317 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
10318 i40e_clear_interrupt_scheme(pf
);
10319 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
10321 i40e_vsi_clear_rings(pf
->vsi
[i
]);
10322 i40e_vsi_clear(pf
->vsi
[i
]);
10327 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
10332 kfree(pf
->qp_pile
);
10335 iounmap(pf
->hw
.hw_addr
);
10337 pci_release_selected_regions(pdev
,
10338 pci_select_bars(pdev
, IORESOURCE_MEM
));
10340 pci_disable_pcie_error_reporting(pdev
);
10341 pci_disable_device(pdev
);
10345 * i40e_pci_error_detected - warning that something funky happened in PCI land
10346 * @pdev: PCI device information struct
10348 * Called to warn that something happened and the error handling steps
10349 * are in progress. Allows the driver to quiesce things, be ready for
10352 static pci_ers_result_t
i40e_pci_error_detected(struct pci_dev
*pdev
,
10353 enum pci_channel_state error
)
10355 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10357 dev_info(&pdev
->dev
, "%s: error %d\n", __func__
, error
);
10359 /* shutdown all operations */
10360 if (!test_bit(__I40E_SUSPENDED
, &pf
->state
)) {
10362 i40e_prep_for_reset(pf
);
10366 /* Request a slot reset */
10367 return PCI_ERS_RESULT_NEED_RESET
;
10371 * i40e_pci_error_slot_reset - a PCI slot reset just happened
10372 * @pdev: PCI device information struct
10374 * Called to find if the driver can work with the device now that
10375 * the pci slot has been reset. If a basic connection seems good
10376 * (registers are readable and have sane content) then return a
10377 * happy little PCI_ERS_RESULT_xxx.
10379 static pci_ers_result_t
i40e_pci_error_slot_reset(struct pci_dev
*pdev
)
10381 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10382 pci_ers_result_t result
;
10386 dev_info(&pdev
->dev
, "%s\n", __func__
);
10387 if (pci_enable_device_mem(pdev
)) {
10388 dev_info(&pdev
->dev
,
10389 "Cannot re-enable PCI device after reset.\n");
10390 result
= PCI_ERS_RESULT_DISCONNECT
;
10392 pci_set_master(pdev
);
10393 pci_restore_state(pdev
);
10394 pci_save_state(pdev
);
10395 pci_wake_from_d3(pdev
, false);
10397 reg
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
10399 result
= PCI_ERS_RESULT_RECOVERED
;
10401 result
= PCI_ERS_RESULT_DISCONNECT
;
10404 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
10406 dev_info(&pdev
->dev
,
10407 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
10409 /* non-fatal, continue */
10416 * i40e_pci_error_resume - restart operations after PCI error recovery
10417 * @pdev: PCI device information struct
10419 * Called to allow the driver to bring things back up after PCI error
10420 * and/or reset recovery has finished.
10422 static void i40e_pci_error_resume(struct pci_dev
*pdev
)
10424 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10426 dev_info(&pdev
->dev
, "%s\n", __func__
);
10427 if (test_bit(__I40E_SUSPENDED
, &pf
->state
))
10431 i40e_handle_reset_warning(pf
);
10436 * i40e_shutdown - PCI callback for shutting down
10437 * @pdev: PCI device information struct
10439 static void i40e_shutdown(struct pci_dev
*pdev
)
10441 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10442 struct i40e_hw
*hw
= &pf
->hw
;
10444 set_bit(__I40E_SUSPENDED
, &pf
->state
);
10445 set_bit(__I40E_DOWN
, &pf
->state
);
10447 i40e_prep_for_reset(pf
);
10450 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
10451 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
10453 i40e_clear_interrupt_scheme(pf
);
10455 if (system_state
== SYSTEM_POWER_OFF
) {
10456 pci_wake_from_d3(pdev
, pf
->wol_en
);
10457 pci_set_power_state(pdev
, PCI_D3hot
);
10463 * i40e_suspend - PCI callback for moving to D3
10464 * @pdev: PCI device information struct
10466 static int i40e_suspend(struct pci_dev
*pdev
, pm_message_t state
)
10468 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10469 struct i40e_hw
*hw
= &pf
->hw
;
10471 set_bit(__I40E_SUSPENDED
, &pf
->state
);
10472 set_bit(__I40E_DOWN
, &pf
->state
);
10473 del_timer_sync(&pf
->service_timer
);
10474 cancel_work_sync(&pf
->service_task
);
10475 i40e_fdir_teardown(pf
);
10478 i40e_prep_for_reset(pf
);
10481 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
10482 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
10484 pci_wake_from_d3(pdev
, pf
->wol_en
);
10485 pci_set_power_state(pdev
, PCI_D3hot
);
10491 * i40e_resume - PCI callback for waking up from D3
10492 * @pdev: PCI device information struct
10494 static int i40e_resume(struct pci_dev
*pdev
)
10496 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10499 pci_set_power_state(pdev
, PCI_D0
);
10500 pci_restore_state(pdev
);
10501 /* pci_restore_state() clears dev->state_saves, so
10502 * call pci_save_state() again to restore it.
10504 pci_save_state(pdev
);
10506 err
= pci_enable_device_mem(pdev
);
10508 dev_err(&pdev
->dev
,
10509 "%s: Cannot enable PCI device from suspend\n",
10513 pci_set_master(pdev
);
10515 /* no wakeup events while running */
10516 pci_wake_from_d3(pdev
, false);
10518 /* handling the reset will rebuild the device state */
10519 if (test_and_clear_bit(__I40E_SUSPENDED
, &pf
->state
)) {
10520 clear_bit(__I40E_DOWN
, &pf
->state
);
10522 i40e_reset_and_rebuild(pf
, false);
10530 static const struct pci_error_handlers i40e_err_handler
= {
10531 .error_detected
= i40e_pci_error_detected
,
10532 .slot_reset
= i40e_pci_error_slot_reset
,
10533 .resume
= i40e_pci_error_resume
,
10536 static struct pci_driver i40e_driver
= {
10537 .name
= i40e_driver_name
,
10538 .id_table
= i40e_pci_tbl
,
10539 .probe
= i40e_probe
,
10540 .remove
= i40e_remove
,
10542 .suspend
= i40e_suspend
,
10543 .resume
= i40e_resume
,
10545 .shutdown
= i40e_shutdown
,
10546 .err_handler
= &i40e_err_handler
,
10547 .sriov_configure
= i40e_pci_sriov_configure
,
10551 * i40e_init_module - Driver registration routine
10553 * i40e_init_module is the first routine called when the driver is
10554 * loaded. All it does is register with the PCI subsystem.
10556 static int __init
i40e_init_module(void)
10558 pr_info("%s: %s - version %s\n", i40e_driver_name
,
10559 i40e_driver_string
, i40e_driver_version_str
);
10560 pr_info("%s: %s\n", i40e_driver_name
, i40e_copyright
);
10563 return pci_register_driver(&i40e_driver
);
10565 module_init(i40e_init_module
);
10568 * i40e_exit_module - Driver exit cleanup routine
10570 * i40e_exit_module is called just before the driver is removed
10573 static void __exit
i40e_exit_module(void)
10575 pci_unregister_driver(&i40e_driver
);
10578 module_exit(i40e_exit_module
);