1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2014 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 #ifdef CONFIG_I40E_VXLAN
30 #include <net/vxlan.h>
33 const char i40e_driver_name
[] = "i40e";
34 static const char i40e_driver_string
[] =
35 "Intel(R) Ethernet Connection XL710 Network Driver";
39 #define DRV_VERSION_MAJOR 0
40 #define DRV_VERSION_MINOR 3
41 #define DRV_VERSION_BUILD 30
42 #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
43 __stringify(DRV_VERSION_MINOR) "." \
44 __stringify(DRV_VERSION_BUILD) DRV_KERN
45 const char i40e_driver_version_str
[] = DRV_VERSION
;
46 static const char i40e_copyright
[] = "Copyright (c) 2013 Intel Corporation.";
48 /* a bit of forward declarations */
49 static void i40e_vsi_reinit_locked(struct i40e_vsi
*vsi
);
50 static void i40e_handle_reset_warning(struct i40e_pf
*pf
);
51 static int i40e_add_vsi(struct i40e_vsi
*vsi
);
52 static int i40e_add_veb(struct i40e_veb
*veb
, struct i40e_vsi
*vsi
);
53 static int i40e_setup_pf_switch(struct i40e_pf
*pf
, bool reinit
);
54 static int i40e_setup_misc_vector(struct i40e_pf
*pf
);
55 static void i40e_determine_queue_usage(struct i40e_pf
*pf
);
56 static int i40e_setup_pf_filter_control(struct i40e_pf
*pf
);
58 /* i40e_pci_tbl - PCI Device ID Table
60 * Last entry must be all 0s
62 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
63 * Class, Class Mask, private data (not used) }
65 static DEFINE_PCI_DEVICE_TABLE(i40e_pci_tbl
) = {
66 {PCI_VDEVICE(INTEL
, I40E_SFP_XL710_DEVICE_ID
), 0},
67 {PCI_VDEVICE(INTEL
, I40E_SFP_X710_DEVICE_ID
), 0},
68 {PCI_VDEVICE(INTEL
, I40E_QEMU_DEVICE_ID
), 0},
69 {PCI_VDEVICE(INTEL
, I40E_KX_A_DEVICE_ID
), 0},
70 {PCI_VDEVICE(INTEL
, I40E_KX_B_DEVICE_ID
), 0},
71 {PCI_VDEVICE(INTEL
, I40E_KX_C_DEVICE_ID
), 0},
72 {PCI_VDEVICE(INTEL
, I40E_KX_D_DEVICE_ID
), 0},
73 {PCI_VDEVICE(INTEL
, I40E_QSFP_A_DEVICE_ID
), 0},
74 {PCI_VDEVICE(INTEL
, I40E_QSFP_B_DEVICE_ID
), 0},
75 {PCI_VDEVICE(INTEL
, I40E_QSFP_C_DEVICE_ID
), 0},
76 /* required last entry */
79 MODULE_DEVICE_TABLE(pci
, i40e_pci_tbl
);
81 #define I40E_MAX_VF_COUNT 128
82 static int debug
= -1;
83 module_param(debug
, int, 0);
84 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
86 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
87 MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
88 MODULE_LICENSE("GPL");
89 MODULE_VERSION(DRV_VERSION
);
92 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
93 * @hw: pointer to the HW structure
94 * @mem: ptr to mem struct to fill out
95 * @size: size of memory requested
96 * @alignment: what to align the allocation to
98 int i40e_allocate_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
,
99 u64 size
, u32 alignment
)
101 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
103 mem
->size
= ALIGN(size
, alignment
);
104 mem
->va
= dma_zalloc_coherent(&pf
->pdev
->dev
, mem
->size
,
105 &mem
->pa
, GFP_KERNEL
);
113 * i40e_free_dma_mem_d - OS specific memory free for shared code
114 * @hw: pointer to the HW structure
115 * @mem: ptr to mem struct to free
117 int i40e_free_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
)
119 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
121 dma_free_coherent(&pf
->pdev
->dev
, mem
->size
, mem
->va
, mem
->pa
);
130 * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
131 * @hw: pointer to the HW structure
132 * @mem: ptr to mem struct to fill out
133 * @size: size of memory requested
135 int i40e_allocate_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
,
139 mem
->va
= kzalloc(size
, GFP_KERNEL
);
148 * i40e_free_virt_mem_d - OS specific memory free for shared code
149 * @hw: pointer to the HW structure
150 * @mem: ptr to mem struct to free
152 int i40e_free_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
)
154 /* it's ok to kfree a NULL pointer */
163 * i40e_get_lump - find a lump of free generic resource
164 * @pf: board private structure
165 * @pile: the pile of resource to search
166 * @needed: the number of items needed
167 * @id: an owner id to stick on the items assigned
169 * Returns the base item index of the lump, or negative for error
171 * The search_hint trick and lack of advanced fit-finding only work
172 * because we're highly likely to have all the same size lump requests.
173 * Linear search time and any fragmentation should be minimal.
175 static int i40e_get_lump(struct i40e_pf
*pf
, struct i40e_lump_tracking
*pile
,
181 if (!pile
|| needed
== 0 || id
>= I40E_PILE_VALID_BIT
) {
182 dev_info(&pf
->pdev
->dev
,
183 "param err: pile=%p needed=%d id=0x%04x\n",
188 /* start the linear search with an imperfect hint */
189 i
= pile
->search_hint
;
190 while (i
< pile
->num_entries
) {
191 /* skip already allocated entries */
192 if (pile
->list
[i
] & I40E_PILE_VALID_BIT
) {
197 /* do we have enough in this lump? */
198 for (j
= 0; (j
< needed
) && ((i
+j
) < pile
->num_entries
); j
++) {
199 if (pile
->list
[i
+j
] & I40E_PILE_VALID_BIT
)
204 /* there was enough, so assign it to the requestor */
205 for (j
= 0; j
< needed
; j
++)
206 pile
->list
[i
+j
] = id
| I40E_PILE_VALID_BIT
;
208 pile
->search_hint
= i
+ j
;
211 /* not enough, so skip over it and continue looking */
220 * i40e_put_lump - return a lump of generic resource
221 * @pile: the pile of resource to search
222 * @index: the base item index
223 * @id: the owner id of the items assigned
225 * Returns the count of items in the lump
227 static int i40e_put_lump(struct i40e_lump_tracking
*pile
, u16 index
, u16 id
)
229 int valid_id
= (id
| I40E_PILE_VALID_BIT
);
233 if (!pile
|| index
>= pile
->num_entries
)
237 i
< pile
->num_entries
&& pile
->list
[i
] == valid_id
;
243 if (count
&& index
< pile
->search_hint
)
244 pile
->search_hint
= index
;
250 * i40e_service_event_schedule - Schedule the service task to wake up
251 * @pf: board private structure
253 * If not already scheduled, this puts the task into the work queue
255 static void i40e_service_event_schedule(struct i40e_pf
*pf
)
257 if (!test_bit(__I40E_DOWN
, &pf
->state
) &&
258 !test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) &&
259 !test_and_set_bit(__I40E_SERVICE_SCHED
, &pf
->state
))
260 schedule_work(&pf
->service_task
);
264 * i40e_tx_timeout - Respond to a Tx Hang
265 * @netdev: network interface device structure
267 * If any port has noticed a Tx timeout, it is likely that the whole
268 * device is munged, not just the one netdev port, so go for the full
271 static void i40e_tx_timeout(struct net_device
*netdev
)
273 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
274 struct i40e_vsi
*vsi
= np
->vsi
;
275 struct i40e_pf
*pf
= vsi
->back
;
277 pf
->tx_timeout_count
++;
279 if (time_after(jiffies
, (pf
->tx_timeout_last_recovery
+ HZ
*20)))
280 pf
->tx_timeout_recovery_level
= 0;
281 pf
->tx_timeout_last_recovery
= jiffies
;
282 netdev_info(netdev
, "tx_timeout recovery level %d\n",
283 pf
->tx_timeout_recovery_level
);
285 switch (pf
->tx_timeout_recovery_level
) {
287 /* disable and re-enable queues for the VSI */
288 if (in_interrupt()) {
289 set_bit(__I40E_REINIT_REQUESTED
, &pf
->state
);
290 set_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
);
292 i40e_vsi_reinit_locked(vsi
);
296 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
299 set_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
);
302 set_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
);
305 netdev_err(netdev
, "tx_timeout recovery unsuccessful\n");
309 i40e_service_event_schedule(pf
);
310 pf
->tx_timeout_recovery_level
++;
314 * i40e_release_rx_desc - Store the new tail and head values
315 * @rx_ring: ring to bump
316 * @val: new head index
318 static inline void i40e_release_rx_desc(struct i40e_ring
*rx_ring
, u32 val
)
320 rx_ring
->next_to_use
= val
;
322 /* Force memory writes to complete before letting h/w
323 * know there are new descriptors to fetch. (Only
324 * applicable for weak-ordered memory model archs,
328 writel(val
, rx_ring
->tail
);
332 * i40e_get_vsi_stats_struct - Get System Network Statistics
333 * @vsi: the VSI we care about
335 * Returns the address of the device statistics structure.
336 * The statistics are actually updated from the service task.
338 struct rtnl_link_stats64
*i40e_get_vsi_stats_struct(struct i40e_vsi
*vsi
)
340 return &vsi
->net_stats
;
344 * i40e_get_netdev_stats_struct - Get statistics for netdev interface
345 * @netdev: network interface device structure
347 * Returns the address of the device statistics structure.
348 * The statistics are actually updated from the service task.
350 static struct rtnl_link_stats64
*i40e_get_netdev_stats_struct(
351 struct net_device
*netdev
,
352 struct rtnl_link_stats64
*stats
)
354 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
355 struct i40e_vsi
*vsi
= np
->vsi
;
356 struct rtnl_link_stats64
*vsi_stats
= i40e_get_vsi_stats_struct(vsi
);
359 if (test_bit(__I40E_DOWN
, &vsi
->state
))
366 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
367 struct i40e_ring
*tx_ring
, *rx_ring
;
371 tx_ring
= ACCESS_ONCE(vsi
->tx_rings
[i
]);
376 start
= u64_stats_fetch_begin_bh(&tx_ring
->syncp
);
377 packets
= tx_ring
->stats
.packets
;
378 bytes
= tx_ring
->stats
.bytes
;
379 } while (u64_stats_fetch_retry_bh(&tx_ring
->syncp
, start
));
381 stats
->tx_packets
+= packets
;
382 stats
->tx_bytes
+= bytes
;
383 rx_ring
= &tx_ring
[1];
386 start
= u64_stats_fetch_begin_bh(&rx_ring
->syncp
);
387 packets
= rx_ring
->stats
.packets
;
388 bytes
= rx_ring
->stats
.bytes
;
389 } while (u64_stats_fetch_retry_bh(&rx_ring
->syncp
, start
));
391 stats
->rx_packets
+= packets
;
392 stats
->rx_bytes
+= bytes
;
396 /* following stats updated by ixgbe_watchdog_task() */
397 stats
->multicast
= vsi_stats
->multicast
;
398 stats
->tx_errors
= vsi_stats
->tx_errors
;
399 stats
->tx_dropped
= vsi_stats
->tx_dropped
;
400 stats
->rx_errors
= vsi_stats
->rx_errors
;
401 stats
->rx_crc_errors
= vsi_stats
->rx_crc_errors
;
402 stats
->rx_length_errors
= vsi_stats
->rx_length_errors
;
408 * i40e_vsi_reset_stats - Resets all stats of the given vsi
409 * @vsi: the VSI to have its stats reset
411 void i40e_vsi_reset_stats(struct i40e_vsi
*vsi
)
413 struct rtnl_link_stats64
*ns
;
419 ns
= i40e_get_vsi_stats_struct(vsi
);
420 memset(ns
, 0, sizeof(*ns
));
421 memset(&vsi
->net_stats_offsets
, 0, sizeof(vsi
->net_stats_offsets
));
422 memset(&vsi
->eth_stats
, 0, sizeof(vsi
->eth_stats
));
423 memset(&vsi
->eth_stats_offsets
, 0, sizeof(vsi
->eth_stats_offsets
));
424 if (vsi
->rx_rings
&& vsi
->rx_rings
[0]) {
425 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
426 memset(&vsi
->rx_rings
[i
]->stats
, 0 ,
427 sizeof(vsi
->rx_rings
[i
]->stats
));
428 memset(&vsi
->rx_rings
[i
]->rx_stats
, 0 ,
429 sizeof(vsi
->rx_rings
[i
]->rx_stats
));
430 memset(&vsi
->tx_rings
[i
]->stats
, 0 ,
431 sizeof(vsi
->tx_rings
[i
]->stats
));
432 memset(&vsi
->tx_rings
[i
]->tx_stats
, 0,
433 sizeof(vsi
->tx_rings
[i
]->tx_stats
));
436 vsi
->stat_offsets_loaded
= false;
440 * i40e_pf_reset_stats - Reset all of the stats for the given pf
441 * @pf: the PF to be reset
443 void i40e_pf_reset_stats(struct i40e_pf
*pf
)
445 memset(&pf
->stats
, 0, sizeof(pf
->stats
));
446 memset(&pf
->stats_offsets
, 0, sizeof(pf
->stats_offsets
));
447 pf
->stat_offsets_loaded
= false;
451 * i40e_stat_update48 - read and update a 48 bit stat from the chip
452 * @hw: ptr to the hardware info
453 * @hireg: the high 32 bit reg to read
454 * @loreg: the low 32 bit reg to read
455 * @offset_loaded: has the initial offset been loaded yet
456 * @offset: ptr to current offset value
457 * @stat: ptr to the stat
459 * Since the device stats are not reset at PFReset, they likely will not
460 * be zeroed when the driver starts. We'll save the first values read
461 * and use them as offsets to be subtracted from the raw values in order
462 * to report stats that count from zero. In the process, we also manage
463 * the potential roll-over.
465 static void i40e_stat_update48(struct i40e_hw
*hw
, u32 hireg
, u32 loreg
,
466 bool offset_loaded
, u64
*offset
, u64
*stat
)
470 if (hw
->device_id
== I40E_QEMU_DEVICE_ID
) {
471 new_data
= rd32(hw
, loreg
);
472 new_data
|= ((u64
)(rd32(hw
, hireg
) & 0xFFFF)) << 32;
474 new_data
= rd64(hw
, loreg
);
478 if (likely(new_data
>= *offset
))
479 *stat
= new_data
- *offset
;
481 *stat
= (new_data
+ ((u64
)1 << 48)) - *offset
;
482 *stat
&= 0xFFFFFFFFFFFFULL
;
486 * i40e_stat_update32 - read and update a 32 bit stat from the chip
487 * @hw: ptr to the hardware info
488 * @reg: the hw reg to read
489 * @offset_loaded: has the initial offset been loaded yet
490 * @offset: ptr to current offset value
491 * @stat: ptr to the stat
493 static void i40e_stat_update32(struct i40e_hw
*hw
, u32 reg
,
494 bool offset_loaded
, u64
*offset
, u64
*stat
)
498 new_data
= rd32(hw
, reg
);
501 if (likely(new_data
>= *offset
))
502 *stat
= (u32
)(new_data
- *offset
);
504 *stat
= (u32
)((new_data
+ ((u64
)1 << 32)) - *offset
);
508 * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
509 * @vsi: the VSI to be updated
511 void i40e_update_eth_stats(struct i40e_vsi
*vsi
)
513 int stat_idx
= le16_to_cpu(vsi
->info
.stat_counter_idx
);
514 struct i40e_pf
*pf
= vsi
->back
;
515 struct i40e_hw
*hw
= &pf
->hw
;
516 struct i40e_eth_stats
*oes
;
517 struct i40e_eth_stats
*es
; /* device's eth stats */
519 es
= &vsi
->eth_stats
;
520 oes
= &vsi
->eth_stats_offsets
;
522 /* Gather up the stats that the hw collects */
523 i40e_stat_update32(hw
, I40E_GLV_TEPC(stat_idx
),
524 vsi
->stat_offsets_loaded
,
525 &oes
->tx_errors
, &es
->tx_errors
);
526 i40e_stat_update32(hw
, I40E_GLV_RDPC(stat_idx
),
527 vsi
->stat_offsets_loaded
,
528 &oes
->rx_discards
, &es
->rx_discards
);
530 i40e_stat_update48(hw
, I40E_GLV_GORCH(stat_idx
),
531 I40E_GLV_GORCL(stat_idx
),
532 vsi
->stat_offsets_loaded
,
533 &oes
->rx_bytes
, &es
->rx_bytes
);
534 i40e_stat_update48(hw
, I40E_GLV_UPRCH(stat_idx
),
535 I40E_GLV_UPRCL(stat_idx
),
536 vsi
->stat_offsets_loaded
,
537 &oes
->rx_unicast
, &es
->rx_unicast
);
538 i40e_stat_update48(hw
, I40E_GLV_MPRCH(stat_idx
),
539 I40E_GLV_MPRCL(stat_idx
),
540 vsi
->stat_offsets_loaded
,
541 &oes
->rx_multicast
, &es
->rx_multicast
);
542 i40e_stat_update48(hw
, I40E_GLV_BPRCH(stat_idx
),
543 I40E_GLV_BPRCL(stat_idx
),
544 vsi
->stat_offsets_loaded
,
545 &oes
->rx_broadcast
, &es
->rx_broadcast
);
547 i40e_stat_update48(hw
, I40E_GLV_GOTCH(stat_idx
),
548 I40E_GLV_GOTCL(stat_idx
),
549 vsi
->stat_offsets_loaded
,
550 &oes
->tx_bytes
, &es
->tx_bytes
);
551 i40e_stat_update48(hw
, I40E_GLV_UPTCH(stat_idx
),
552 I40E_GLV_UPTCL(stat_idx
),
553 vsi
->stat_offsets_loaded
,
554 &oes
->tx_unicast
, &es
->tx_unicast
);
555 i40e_stat_update48(hw
, I40E_GLV_MPTCH(stat_idx
),
556 I40E_GLV_MPTCL(stat_idx
),
557 vsi
->stat_offsets_loaded
,
558 &oes
->tx_multicast
, &es
->tx_multicast
);
559 i40e_stat_update48(hw
, I40E_GLV_BPTCH(stat_idx
),
560 I40E_GLV_BPTCL(stat_idx
),
561 vsi
->stat_offsets_loaded
,
562 &oes
->tx_broadcast
, &es
->tx_broadcast
);
563 vsi
->stat_offsets_loaded
= true;
567 * i40e_update_veb_stats - Update Switch component statistics
568 * @veb: the VEB being updated
570 static void i40e_update_veb_stats(struct i40e_veb
*veb
)
572 struct i40e_pf
*pf
= veb
->pf
;
573 struct i40e_hw
*hw
= &pf
->hw
;
574 struct i40e_eth_stats
*oes
;
575 struct i40e_eth_stats
*es
; /* device's eth stats */
578 idx
= veb
->stats_idx
;
580 oes
= &veb
->stats_offsets
;
582 /* Gather up the stats that the hw collects */
583 i40e_stat_update32(hw
, I40E_GLSW_TDPC(idx
),
584 veb
->stat_offsets_loaded
,
585 &oes
->tx_discards
, &es
->tx_discards
);
586 if (hw
->revision_id
> 0)
587 i40e_stat_update32(hw
, I40E_GLSW_RUPP(idx
),
588 veb
->stat_offsets_loaded
,
589 &oes
->rx_unknown_protocol
,
590 &es
->rx_unknown_protocol
);
591 i40e_stat_update48(hw
, I40E_GLSW_GORCH(idx
), I40E_GLSW_GORCL(idx
),
592 veb
->stat_offsets_loaded
,
593 &oes
->rx_bytes
, &es
->rx_bytes
);
594 i40e_stat_update48(hw
, I40E_GLSW_UPRCH(idx
), I40E_GLSW_UPRCL(idx
),
595 veb
->stat_offsets_loaded
,
596 &oes
->rx_unicast
, &es
->rx_unicast
);
597 i40e_stat_update48(hw
, I40E_GLSW_MPRCH(idx
), I40E_GLSW_MPRCL(idx
),
598 veb
->stat_offsets_loaded
,
599 &oes
->rx_multicast
, &es
->rx_multicast
);
600 i40e_stat_update48(hw
, I40E_GLSW_BPRCH(idx
), I40E_GLSW_BPRCL(idx
),
601 veb
->stat_offsets_loaded
,
602 &oes
->rx_broadcast
, &es
->rx_broadcast
);
604 i40e_stat_update48(hw
, I40E_GLSW_GOTCH(idx
), I40E_GLSW_GOTCL(idx
),
605 veb
->stat_offsets_loaded
,
606 &oes
->tx_bytes
, &es
->tx_bytes
);
607 i40e_stat_update48(hw
, I40E_GLSW_UPTCH(idx
), I40E_GLSW_UPTCL(idx
),
608 veb
->stat_offsets_loaded
,
609 &oes
->tx_unicast
, &es
->tx_unicast
);
610 i40e_stat_update48(hw
, I40E_GLSW_MPTCH(idx
), I40E_GLSW_MPTCL(idx
),
611 veb
->stat_offsets_loaded
,
612 &oes
->tx_multicast
, &es
->tx_multicast
);
613 i40e_stat_update48(hw
, I40E_GLSW_BPTCH(idx
), I40E_GLSW_BPTCL(idx
),
614 veb
->stat_offsets_loaded
,
615 &oes
->tx_broadcast
, &es
->tx_broadcast
);
616 veb
->stat_offsets_loaded
= true;
620 * i40e_update_link_xoff_rx - Update XOFF received in link flow control mode
621 * @pf: the corresponding PF
623 * Update the Rx XOFF counter (PAUSE frames) in link flow control mode
625 static void i40e_update_link_xoff_rx(struct i40e_pf
*pf
)
627 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
628 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
629 struct i40e_hw
*hw
= &pf
->hw
;
633 if ((hw
->fc
.current_mode
!= I40E_FC_FULL
) &&
634 (hw
->fc
.current_mode
!= I40E_FC_RX_PAUSE
))
637 xoff
= nsd
->link_xoff_rx
;
638 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFRXC(hw
->port
),
639 pf
->stat_offsets_loaded
,
640 &osd
->link_xoff_rx
, &nsd
->link_xoff_rx
);
642 /* No new LFC xoff rx */
643 if (!(nsd
->link_xoff_rx
- xoff
))
646 /* Clear the __I40E_HANG_CHECK_ARMED bit for all Tx rings */
647 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
; v
++) {
648 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
653 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
654 struct i40e_ring
*ring
= vsi
->tx_rings
[i
];
655 clear_bit(__I40E_HANG_CHECK_ARMED
, &ring
->state
);
661 * i40e_update_prio_xoff_rx - Update XOFF received in PFC mode
662 * @pf: the corresponding PF
664 * Update the Rx XOFF counter (PAUSE frames) in PFC mode
666 static void i40e_update_prio_xoff_rx(struct i40e_pf
*pf
)
668 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
669 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
670 bool xoff
[I40E_MAX_TRAFFIC_CLASS
] = {false};
671 struct i40e_dcbx_config
*dcb_cfg
;
672 struct i40e_hw
*hw
= &pf
->hw
;
676 dcb_cfg
= &hw
->local_dcbx_config
;
678 /* See if DCB enabled with PFC TC */
679 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
) ||
680 !(dcb_cfg
->pfc
.pfcenable
)) {
681 i40e_update_link_xoff_rx(pf
);
685 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
686 u64 prio_xoff
= nsd
->priority_xoff_rx
[i
];
687 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFRXC(hw
->port
, i
),
688 pf
->stat_offsets_loaded
,
689 &osd
->priority_xoff_rx
[i
],
690 &nsd
->priority_xoff_rx
[i
]);
692 /* No new PFC xoff rx */
693 if (!(nsd
->priority_xoff_rx
[i
] - prio_xoff
))
695 /* Get the TC for given priority */
696 tc
= dcb_cfg
->etscfg
.prioritytable
[i
];
700 /* Clear the __I40E_HANG_CHECK_ARMED bit for Tx rings */
701 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
; v
++) {
702 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
707 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
708 struct i40e_ring
*ring
= vsi
->tx_rings
[i
];
712 clear_bit(__I40E_HANG_CHECK_ARMED
,
719 * i40e_update_stats - Update the board statistics counters.
720 * @vsi: the VSI to be updated
722 * There are a few instances where we store the same stat in a
723 * couple of different structs. This is partly because we have
724 * the netdev stats that need to be filled out, which is slightly
725 * different from the "eth_stats" defined by the chip and used in
726 * VF communications. We sort it all out here in a central place.
728 void i40e_update_stats(struct i40e_vsi
*vsi
)
730 struct i40e_pf
*pf
= vsi
->back
;
731 struct i40e_hw
*hw
= &pf
->hw
;
732 struct rtnl_link_stats64
*ons
;
733 struct rtnl_link_stats64
*ns
; /* netdev stats */
734 struct i40e_eth_stats
*oes
;
735 struct i40e_eth_stats
*es
; /* device's eth stats */
736 u32 tx_restart
, tx_busy
;
743 if (test_bit(__I40E_DOWN
, &vsi
->state
) ||
744 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
747 ns
= i40e_get_vsi_stats_struct(vsi
);
748 ons
= &vsi
->net_stats_offsets
;
749 es
= &vsi
->eth_stats
;
750 oes
= &vsi
->eth_stats_offsets
;
752 /* Gather up the netdev and vsi stats that the driver collects
753 * on the fly during packet processing
757 tx_restart
= tx_busy
= 0;
761 for (q
= 0; q
< vsi
->num_queue_pairs
; q
++) {
767 p
= ACCESS_ONCE(vsi
->tx_rings
[q
]);
770 start
= u64_stats_fetch_begin_bh(&p
->syncp
);
771 packets
= p
->stats
.packets
;
772 bytes
= p
->stats
.bytes
;
773 } while (u64_stats_fetch_retry_bh(&p
->syncp
, start
));
776 tx_restart
+= p
->tx_stats
.restart_queue
;
777 tx_busy
+= p
->tx_stats
.tx_busy
;
779 /* Rx queue is part of the same block as Tx queue */
782 start
= u64_stats_fetch_begin_bh(&p
->syncp
);
783 packets
= p
->stats
.packets
;
784 bytes
= p
->stats
.bytes
;
785 } while (u64_stats_fetch_retry_bh(&p
->syncp
, start
));
788 rx_buf
+= p
->rx_stats
.alloc_buff_failed
;
789 rx_page
+= p
->rx_stats
.alloc_page_failed
;
792 vsi
->tx_restart
= tx_restart
;
793 vsi
->tx_busy
= tx_busy
;
794 vsi
->rx_page_failed
= rx_page
;
795 vsi
->rx_buf_failed
= rx_buf
;
797 ns
->rx_packets
= rx_p
;
799 ns
->tx_packets
= tx_p
;
802 i40e_update_eth_stats(vsi
);
803 /* update netdev stats from eth stats */
804 ons
->rx_errors
= oes
->rx_errors
;
805 ns
->rx_errors
= es
->rx_errors
;
806 ons
->tx_errors
= oes
->tx_errors
;
807 ns
->tx_errors
= es
->tx_errors
;
808 ons
->multicast
= oes
->rx_multicast
;
809 ns
->multicast
= es
->rx_multicast
;
810 ons
->tx_dropped
= oes
->tx_discards
;
811 ns
->tx_dropped
= es
->tx_discards
;
813 /* Get the port data only if this is the main PF VSI */
814 if (vsi
== pf
->vsi
[pf
->lan_vsi
]) {
815 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
816 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
818 i40e_stat_update48(hw
, I40E_GLPRT_GORCH(hw
->port
),
819 I40E_GLPRT_GORCL(hw
->port
),
820 pf
->stat_offsets_loaded
,
821 &osd
->eth
.rx_bytes
, &nsd
->eth
.rx_bytes
);
822 i40e_stat_update48(hw
, I40E_GLPRT_GOTCH(hw
->port
),
823 I40E_GLPRT_GOTCL(hw
->port
),
824 pf
->stat_offsets_loaded
,
825 &osd
->eth
.tx_bytes
, &nsd
->eth
.tx_bytes
);
826 i40e_stat_update32(hw
, I40E_GLPRT_RDPC(hw
->port
),
827 pf
->stat_offsets_loaded
,
828 &osd
->eth
.rx_discards
,
829 &nsd
->eth
.rx_discards
);
830 i40e_stat_update32(hw
, I40E_GLPRT_TDPC(hw
->port
),
831 pf
->stat_offsets_loaded
,
832 &osd
->eth
.tx_discards
,
833 &nsd
->eth
.tx_discards
);
834 i40e_stat_update48(hw
, I40E_GLPRT_MPRCH(hw
->port
),
835 I40E_GLPRT_MPRCL(hw
->port
),
836 pf
->stat_offsets_loaded
,
837 &osd
->eth
.rx_multicast
,
838 &nsd
->eth
.rx_multicast
);
840 i40e_stat_update32(hw
, I40E_GLPRT_TDOLD(hw
->port
),
841 pf
->stat_offsets_loaded
,
842 &osd
->tx_dropped_link_down
,
843 &nsd
->tx_dropped_link_down
);
845 i40e_stat_update32(hw
, I40E_GLPRT_CRCERRS(hw
->port
),
846 pf
->stat_offsets_loaded
,
847 &osd
->crc_errors
, &nsd
->crc_errors
);
848 ns
->rx_crc_errors
= nsd
->crc_errors
;
850 i40e_stat_update32(hw
, I40E_GLPRT_ILLERRC(hw
->port
),
851 pf
->stat_offsets_loaded
,
852 &osd
->illegal_bytes
, &nsd
->illegal_bytes
);
853 ns
->rx_errors
= nsd
->crc_errors
854 + nsd
->illegal_bytes
;
856 i40e_stat_update32(hw
, I40E_GLPRT_MLFC(hw
->port
),
857 pf
->stat_offsets_loaded
,
858 &osd
->mac_local_faults
,
859 &nsd
->mac_local_faults
);
860 i40e_stat_update32(hw
, I40E_GLPRT_MRFC(hw
->port
),
861 pf
->stat_offsets_loaded
,
862 &osd
->mac_remote_faults
,
863 &nsd
->mac_remote_faults
);
865 i40e_stat_update32(hw
, I40E_GLPRT_RLEC(hw
->port
),
866 pf
->stat_offsets_loaded
,
867 &osd
->rx_length_errors
,
868 &nsd
->rx_length_errors
);
869 ns
->rx_length_errors
= nsd
->rx_length_errors
;
871 i40e_stat_update32(hw
, I40E_GLPRT_LXONRXC(hw
->port
),
872 pf
->stat_offsets_loaded
,
873 &osd
->link_xon_rx
, &nsd
->link_xon_rx
);
874 i40e_stat_update32(hw
, I40E_GLPRT_LXONTXC(hw
->port
),
875 pf
->stat_offsets_loaded
,
876 &osd
->link_xon_tx
, &nsd
->link_xon_tx
);
877 i40e_update_prio_xoff_rx(pf
); /* handles I40E_GLPRT_LXOFFRXC */
878 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFTXC(hw
->port
),
879 pf
->stat_offsets_loaded
,
880 &osd
->link_xoff_tx
, &nsd
->link_xoff_tx
);
882 for (i
= 0; i
< 8; i
++) {
883 i40e_stat_update32(hw
, I40E_GLPRT_PXONRXC(hw
->port
, i
),
884 pf
->stat_offsets_loaded
,
885 &osd
->priority_xon_rx
[i
],
886 &nsd
->priority_xon_rx
[i
]);
887 i40e_stat_update32(hw
, I40E_GLPRT_PXONTXC(hw
->port
, i
),
888 pf
->stat_offsets_loaded
,
889 &osd
->priority_xon_tx
[i
],
890 &nsd
->priority_xon_tx
[i
]);
891 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFTXC(hw
->port
, i
),
892 pf
->stat_offsets_loaded
,
893 &osd
->priority_xoff_tx
[i
],
894 &nsd
->priority_xoff_tx
[i
]);
895 i40e_stat_update32(hw
,
896 I40E_GLPRT_RXON2OFFCNT(hw
->port
, i
),
897 pf
->stat_offsets_loaded
,
898 &osd
->priority_xon_2_xoff
[i
],
899 &nsd
->priority_xon_2_xoff
[i
]);
902 i40e_stat_update48(hw
, I40E_GLPRT_PRC64H(hw
->port
),
903 I40E_GLPRT_PRC64L(hw
->port
),
904 pf
->stat_offsets_loaded
,
905 &osd
->rx_size_64
, &nsd
->rx_size_64
);
906 i40e_stat_update48(hw
, I40E_GLPRT_PRC127H(hw
->port
),
907 I40E_GLPRT_PRC127L(hw
->port
),
908 pf
->stat_offsets_loaded
,
909 &osd
->rx_size_127
, &nsd
->rx_size_127
);
910 i40e_stat_update48(hw
, I40E_GLPRT_PRC255H(hw
->port
),
911 I40E_GLPRT_PRC255L(hw
->port
),
912 pf
->stat_offsets_loaded
,
913 &osd
->rx_size_255
, &nsd
->rx_size_255
);
914 i40e_stat_update48(hw
, I40E_GLPRT_PRC511H(hw
->port
),
915 I40E_GLPRT_PRC511L(hw
->port
),
916 pf
->stat_offsets_loaded
,
917 &osd
->rx_size_511
, &nsd
->rx_size_511
);
918 i40e_stat_update48(hw
, I40E_GLPRT_PRC1023H(hw
->port
),
919 I40E_GLPRT_PRC1023L(hw
->port
),
920 pf
->stat_offsets_loaded
,
921 &osd
->rx_size_1023
, &nsd
->rx_size_1023
);
922 i40e_stat_update48(hw
, I40E_GLPRT_PRC1522H(hw
->port
),
923 I40E_GLPRT_PRC1522L(hw
->port
),
924 pf
->stat_offsets_loaded
,
925 &osd
->rx_size_1522
, &nsd
->rx_size_1522
);
926 i40e_stat_update48(hw
, I40E_GLPRT_PRC9522H(hw
->port
),
927 I40E_GLPRT_PRC9522L(hw
->port
),
928 pf
->stat_offsets_loaded
,
929 &osd
->rx_size_big
, &nsd
->rx_size_big
);
931 i40e_stat_update48(hw
, I40E_GLPRT_PTC64H(hw
->port
),
932 I40E_GLPRT_PTC64L(hw
->port
),
933 pf
->stat_offsets_loaded
,
934 &osd
->tx_size_64
, &nsd
->tx_size_64
);
935 i40e_stat_update48(hw
, I40E_GLPRT_PTC127H(hw
->port
),
936 I40E_GLPRT_PTC127L(hw
->port
),
937 pf
->stat_offsets_loaded
,
938 &osd
->tx_size_127
, &nsd
->tx_size_127
);
939 i40e_stat_update48(hw
, I40E_GLPRT_PTC255H(hw
->port
),
940 I40E_GLPRT_PTC255L(hw
->port
),
941 pf
->stat_offsets_loaded
,
942 &osd
->tx_size_255
, &nsd
->tx_size_255
);
943 i40e_stat_update48(hw
, I40E_GLPRT_PTC511H(hw
->port
),
944 I40E_GLPRT_PTC511L(hw
->port
),
945 pf
->stat_offsets_loaded
,
946 &osd
->tx_size_511
, &nsd
->tx_size_511
);
947 i40e_stat_update48(hw
, I40E_GLPRT_PTC1023H(hw
->port
),
948 I40E_GLPRT_PTC1023L(hw
->port
),
949 pf
->stat_offsets_loaded
,
950 &osd
->tx_size_1023
, &nsd
->tx_size_1023
);
951 i40e_stat_update48(hw
, I40E_GLPRT_PTC1522H(hw
->port
),
952 I40E_GLPRT_PTC1522L(hw
->port
),
953 pf
->stat_offsets_loaded
,
954 &osd
->tx_size_1522
, &nsd
->tx_size_1522
);
955 i40e_stat_update48(hw
, I40E_GLPRT_PTC9522H(hw
->port
),
956 I40E_GLPRT_PTC9522L(hw
->port
),
957 pf
->stat_offsets_loaded
,
958 &osd
->tx_size_big
, &nsd
->tx_size_big
);
960 i40e_stat_update32(hw
, I40E_GLPRT_RUC(hw
->port
),
961 pf
->stat_offsets_loaded
,
962 &osd
->rx_undersize
, &nsd
->rx_undersize
);
963 i40e_stat_update32(hw
, I40E_GLPRT_RFC(hw
->port
),
964 pf
->stat_offsets_loaded
,
965 &osd
->rx_fragments
, &nsd
->rx_fragments
);
966 i40e_stat_update32(hw
, I40E_GLPRT_ROC(hw
->port
),
967 pf
->stat_offsets_loaded
,
968 &osd
->rx_oversize
, &nsd
->rx_oversize
);
969 i40e_stat_update32(hw
, I40E_GLPRT_RJC(hw
->port
),
970 pf
->stat_offsets_loaded
,
971 &osd
->rx_jabber
, &nsd
->rx_jabber
);
974 pf
->stat_offsets_loaded
= true;
978 * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
979 * @vsi: the VSI to be searched
980 * @macaddr: the MAC address
982 * @is_vf: make sure its a vf filter, else doesn't matter
983 * @is_netdev: make sure its a netdev filter, else doesn't matter
985 * Returns ptr to the filter object or NULL
987 static struct i40e_mac_filter
*i40e_find_filter(struct i40e_vsi
*vsi
,
988 u8
*macaddr
, s16 vlan
,
989 bool is_vf
, bool is_netdev
)
991 struct i40e_mac_filter
*f
;
993 if (!vsi
|| !macaddr
)
996 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
997 if ((ether_addr_equal(macaddr
, f
->macaddr
)) &&
999 (!is_vf
|| f
->is_vf
) &&
1000 (!is_netdev
|| f
->is_netdev
))
1007 * i40e_find_mac - Find a mac addr in the macvlan filters list
1008 * @vsi: the VSI to be searched
1009 * @macaddr: the MAC address we are searching for
1010 * @is_vf: make sure its a vf filter, else doesn't matter
1011 * @is_netdev: make sure its a netdev filter, else doesn't matter
1013 * Returns the first filter with the provided MAC address or NULL if
1014 * MAC address was not found
1016 struct i40e_mac_filter
*i40e_find_mac(struct i40e_vsi
*vsi
, u8
*macaddr
,
1017 bool is_vf
, bool is_netdev
)
1019 struct i40e_mac_filter
*f
;
1021 if (!vsi
|| !macaddr
)
1024 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1025 if ((ether_addr_equal(macaddr
, f
->macaddr
)) &&
1026 (!is_vf
|| f
->is_vf
) &&
1027 (!is_netdev
|| f
->is_netdev
))
1034 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1035 * @vsi: the VSI to be searched
1037 * Returns true if VSI is in vlan mode or false otherwise
1039 bool i40e_is_vsi_in_vlan(struct i40e_vsi
*vsi
)
1041 struct i40e_mac_filter
*f
;
1043 /* Only -1 for all the filters denotes not in vlan mode
1044 * so we have to go through all the list in order to make sure
1046 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1055 * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
1056 * @vsi: the VSI to be searched
1057 * @macaddr: the mac address to be filtered
1058 * @is_vf: true if it is a vf
1059 * @is_netdev: true if it is a netdev
1061 * Goes through all the macvlan filters and adds a
1062 * macvlan filter for each unique vlan that already exists
1064 * Returns first filter found on success, else NULL
1066 struct i40e_mac_filter
*i40e_put_mac_in_vlan(struct i40e_vsi
*vsi
, u8
*macaddr
,
1067 bool is_vf
, bool is_netdev
)
1069 struct i40e_mac_filter
*f
;
1071 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1072 if (!i40e_find_filter(vsi
, macaddr
, f
->vlan
,
1073 is_vf
, is_netdev
)) {
1074 if (!i40e_add_filter(vsi
, macaddr
, f
->vlan
,
1080 return list_first_entry_or_null(&vsi
->mac_filter_list
,
1081 struct i40e_mac_filter
, list
);
1085 * i40e_add_filter - Add a mac/vlan filter to the VSI
1086 * @vsi: the VSI to be searched
1087 * @macaddr: the MAC address
1089 * @is_vf: make sure its a vf filter, else doesn't matter
1090 * @is_netdev: make sure its a netdev filter, else doesn't matter
1092 * Returns ptr to the filter object or NULL when no memory available.
1094 struct i40e_mac_filter
*i40e_add_filter(struct i40e_vsi
*vsi
,
1095 u8
*macaddr
, s16 vlan
,
1096 bool is_vf
, bool is_netdev
)
1098 struct i40e_mac_filter
*f
;
1100 if (!vsi
|| !macaddr
)
1103 f
= i40e_find_filter(vsi
, macaddr
, vlan
, is_vf
, is_netdev
);
1105 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
1107 goto add_filter_out
;
1109 memcpy(f
->macaddr
, macaddr
, ETH_ALEN
);
1113 INIT_LIST_HEAD(&f
->list
);
1114 list_add(&f
->list
, &vsi
->mac_filter_list
);
1117 /* increment counter and add a new flag if needed */
1123 } else if (is_netdev
) {
1124 if (!f
->is_netdev
) {
1125 f
->is_netdev
= true;
1132 /* changed tells sync_filters_subtask to
1133 * push the filter down to the firmware
1136 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1137 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1145 * i40e_del_filter - Remove a mac/vlan filter from the VSI
1146 * @vsi: the VSI to be searched
1147 * @macaddr: the MAC address
1149 * @is_vf: make sure it's a vf filter, else doesn't matter
1150 * @is_netdev: make sure it's a netdev filter, else doesn't matter
1152 void i40e_del_filter(struct i40e_vsi
*vsi
,
1153 u8
*macaddr
, s16 vlan
,
1154 bool is_vf
, bool is_netdev
)
1156 struct i40e_mac_filter
*f
;
1158 if (!vsi
|| !macaddr
)
1161 f
= i40e_find_filter(vsi
, macaddr
, vlan
, is_vf
, is_netdev
);
1162 if (!f
|| f
->counter
== 0)
1170 } else if (is_netdev
) {
1172 f
->is_netdev
= false;
1176 /* make sure we don't remove a filter in use by vf or netdev */
1178 min_f
+= (f
->is_vf
? 1 : 0);
1179 min_f
+= (f
->is_netdev
? 1 : 0);
1181 if (f
->counter
> min_f
)
1185 /* counter == 0 tells sync_filters_subtask to
1186 * remove the filter from the firmware's list
1188 if (f
->counter
== 0) {
1190 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1191 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1196 * i40e_set_mac - NDO callback to set mac address
1197 * @netdev: network interface device structure
1198 * @p: pointer to an address structure
1200 * Returns 0 on success, negative on failure
1202 static int i40e_set_mac(struct net_device
*netdev
, void *p
)
1204 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1205 struct i40e_vsi
*vsi
= np
->vsi
;
1206 struct sockaddr
*addr
= p
;
1207 struct i40e_mac_filter
*f
;
1209 if (!is_valid_ether_addr(addr
->sa_data
))
1210 return -EADDRNOTAVAIL
;
1212 netdev_info(netdev
, "set mac address=%pM\n", addr
->sa_data
);
1214 if (ether_addr_equal(netdev
->dev_addr
, addr
->sa_data
))
1217 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
1218 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
1219 return -EADDRNOTAVAIL
;
1221 if (vsi
->type
== I40E_VSI_MAIN
) {
1223 ret
= i40e_aq_mac_address_write(&vsi
->back
->hw
,
1224 I40E_AQC_WRITE_TYPE_LAA_ONLY
,
1225 addr
->sa_data
, NULL
);
1228 "Addr change for Main VSI failed: %d\n",
1230 return -EADDRNOTAVAIL
;
1233 memcpy(vsi
->back
->hw
.mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
1236 /* In order to be sure to not drop any packets, add the new address
1237 * then delete the old one.
1239 f
= i40e_add_filter(vsi
, addr
->sa_data
, I40E_VLAN_ANY
, false, false);
1243 i40e_sync_vsi_filters(vsi
);
1244 i40e_del_filter(vsi
, netdev
->dev_addr
, I40E_VLAN_ANY
, false, false);
1245 i40e_sync_vsi_filters(vsi
);
1247 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
1253 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1254 * @vsi: the VSI being setup
1255 * @ctxt: VSI context structure
1256 * @enabled_tc: Enabled TCs bitmap
1257 * @is_add: True if called before Add VSI
1259 * Setup VSI queue mapping for enabled traffic classes.
1261 static void i40e_vsi_setup_queue_map(struct i40e_vsi
*vsi
,
1262 struct i40e_vsi_context
*ctxt
,
1266 struct i40e_pf
*pf
= vsi
->back
;
1275 sections
= I40E_AQ_VSI_PROP_QUEUE_MAP_VALID
;
1278 if (enabled_tc
&& (vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
1279 /* Find numtc from enabled TC bitmap */
1280 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1281 if (enabled_tc
& (1 << i
)) /* TC is enabled */
1285 dev_warn(&pf
->pdev
->dev
, "DCB is enabled but no TC enabled, forcing TC0\n");
1289 /* At least TC0 is enabled in case of non-DCB case */
1293 vsi
->tc_config
.numtc
= numtc
;
1294 vsi
->tc_config
.enabled_tc
= enabled_tc
? enabled_tc
: 1;
1296 /* Setup queue offset/count for all TCs for given VSI */
1297 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1298 /* See if the given TC is enabled for the given VSI */
1299 if (vsi
->tc_config
.enabled_tc
& (1 << i
)) { /* TC is enabled */
1302 vsi
->tc_config
.tc_info
[i
].qoffset
= offset
;
1303 switch (vsi
->type
) {
1306 qcount
= pf
->rss_size
;
1308 qcount
= pf
->num_tc_qps
;
1309 vsi
->tc_config
.tc_info
[i
].qcount
= qcount
;
1312 case I40E_VSI_SRIOV
:
1313 case I40E_VSI_VMDQ2
:
1315 qcount
= vsi
->alloc_queue_pairs
;
1316 vsi
->tc_config
.tc_info
[i
].qcount
= qcount
;
1321 /* find the power-of-2 of the number of queue pairs */
1322 num_qps
= vsi
->tc_config
.tc_info
[i
].qcount
;
1325 ((1 << pow
) < vsi
->tc_config
.tc_info
[i
].qcount
)) {
1330 vsi
->tc_config
.tc_info
[i
].netdev_tc
= netdev_tc
++;
1332 (offset
<< I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT
) |
1333 (pow
<< I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT
);
1335 offset
+= vsi
->tc_config
.tc_info
[i
].qcount
;
1337 /* TC is not enabled so set the offset to
1338 * default queue and allocate one queue
1341 vsi
->tc_config
.tc_info
[i
].qoffset
= 0;
1342 vsi
->tc_config
.tc_info
[i
].qcount
= 1;
1343 vsi
->tc_config
.tc_info
[i
].netdev_tc
= 0;
1347 ctxt
->info
.tc_mapping
[i
] = cpu_to_le16(qmap
);
1350 /* Set actual Tx/Rx queue pairs */
1351 vsi
->num_queue_pairs
= offset
;
1353 /* Scheduler section valid can only be set for ADD VSI */
1355 sections
|= I40E_AQ_VSI_PROP_SCHED_VALID
;
1357 ctxt
->info
.up_enable_bits
= enabled_tc
;
1359 if (vsi
->type
== I40E_VSI_SRIOV
) {
1360 ctxt
->info
.mapping_flags
|=
1361 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG
);
1362 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
1363 ctxt
->info
.queue_mapping
[i
] =
1364 cpu_to_le16(vsi
->base_queue
+ i
);
1366 ctxt
->info
.mapping_flags
|=
1367 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG
);
1368 ctxt
->info
.queue_mapping
[0] = cpu_to_le16(vsi
->base_queue
);
1370 ctxt
->info
.valid_sections
|= cpu_to_le16(sections
);
1374 * i40e_set_rx_mode - NDO callback to set the netdev filters
1375 * @netdev: network interface device structure
1377 static void i40e_set_rx_mode(struct net_device
*netdev
)
1379 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1380 struct i40e_mac_filter
*f
, *ftmp
;
1381 struct i40e_vsi
*vsi
= np
->vsi
;
1382 struct netdev_hw_addr
*uca
;
1383 struct netdev_hw_addr
*mca
;
1384 struct netdev_hw_addr
*ha
;
1386 /* add addr if not already in the filter list */
1387 netdev_for_each_uc_addr(uca
, netdev
) {
1388 if (!i40e_find_mac(vsi
, uca
->addr
, false, true)) {
1389 if (i40e_is_vsi_in_vlan(vsi
))
1390 i40e_put_mac_in_vlan(vsi
, uca
->addr
,
1393 i40e_add_filter(vsi
, uca
->addr
, I40E_VLAN_ANY
,
1398 netdev_for_each_mc_addr(mca
, netdev
) {
1399 if (!i40e_find_mac(vsi
, mca
->addr
, false, true)) {
1400 if (i40e_is_vsi_in_vlan(vsi
))
1401 i40e_put_mac_in_vlan(vsi
, mca
->addr
,
1404 i40e_add_filter(vsi
, mca
->addr
, I40E_VLAN_ANY
,
1409 /* remove filter if not in netdev list */
1410 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1416 if (is_multicast_ether_addr(f
->macaddr
)) {
1417 netdev_for_each_mc_addr(mca
, netdev
) {
1418 if (ether_addr_equal(mca
->addr
, f
->macaddr
)) {
1424 netdev_for_each_uc_addr(uca
, netdev
) {
1425 if (ether_addr_equal(uca
->addr
, f
->macaddr
)) {
1431 for_each_dev_addr(netdev
, ha
) {
1432 if (ether_addr_equal(ha
->addr
, f
->macaddr
)) {
1440 vsi
, f
->macaddr
, I40E_VLAN_ANY
, false, true);
1443 /* check for other flag changes */
1444 if (vsi
->current_netdev_flags
!= vsi
->netdev
->flags
) {
1445 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1446 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1451 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
1452 * @vsi: ptr to the VSI
1454 * Push any outstanding VSI filter changes through the AdminQ.
1456 * Returns 0 or error value
1458 int i40e_sync_vsi_filters(struct i40e_vsi
*vsi
)
1460 struct i40e_mac_filter
*f
, *ftmp
;
1461 bool promisc_forced_on
= false;
1462 bool add_happened
= false;
1463 int filter_list_len
= 0;
1464 u32 changed_flags
= 0;
1465 i40e_status aq_ret
= 0;
1471 /* empty array typed pointers, kcalloc later */
1472 struct i40e_aqc_add_macvlan_element_data
*add_list
;
1473 struct i40e_aqc_remove_macvlan_element_data
*del_list
;
1475 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &vsi
->state
))
1476 usleep_range(1000, 2000);
1480 changed_flags
= vsi
->current_netdev_flags
^ vsi
->netdev
->flags
;
1481 vsi
->current_netdev_flags
= vsi
->netdev
->flags
;
1484 if (vsi
->flags
& I40E_VSI_FLAG_FILTER_CHANGED
) {
1485 vsi
->flags
&= ~I40E_VSI_FLAG_FILTER_CHANGED
;
1487 filter_list_len
= pf
->hw
.aq
.asq_buf_size
/
1488 sizeof(struct i40e_aqc_remove_macvlan_element_data
);
1489 del_list
= kcalloc(filter_list_len
,
1490 sizeof(struct i40e_aqc_remove_macvlan_element_data
),
1495 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1499 if (f
->counter
!= 0)
1504 /* add to delete list */
1505 memcpy(del_list
[num_del
].mac_addr
,
1506 f
->macaddr
, ETH_ALEN
);
1507 del_list
[num_del
].vlan_tag
=
1508 cpu_to_le16((u16
)(f
->vlan
==
1509 I40E_VLAN_ANY
? 0 : f
->vlan
));
1511 cmd_flags
|= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
1512 del_list
[num_del
].flags
= cmd_flags
;
1515 /* unlink from filter list */
1519 /* flush a full buffer */
1520 if (num_del
== filter_list_len
) {
1521 aq_ret
= i40e_aq_remove_macvlan(&pf
->hw
,
1522 vsi
->seid
, del_list
, num_del
,
1525 memset(del_list
, 0, sizeof(*del_list
));
1528 dev_info(&pf
->pdev
->dev
,
1529 "ignoring delete macvlan error, err %d, aq_err %d while flushing a full buffer\n",
1531 pf
->hw
.aq
.asq_last_status
);
1535 aq_ret
= i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
,
1536 del_list
, num_del
, NULL
);
1540 dev_info(&pf
->pdev
->dev
,
1541 "ignoring delete macvlan error, err %d, aq_err %d\n",
1542 aq_ret
, pf
->hw
.aq
.asq_last_status
);
1548 /* do all the adds now */
1549 filter_list_len
= pf
->hw
.aq
.asq_buf_size
/
1550 sizeof(struct i40e_aqc_add_macvlan_element_data
),
1551 add_list
= kcalloc(filter_list_len
,
1552 sizeof(struct i40e_aqc_add_macvlan_element_data
),
1557 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1561 if (f
->counter
== 0)
1564 add_happened
= true;
1567 /* add to add array */
1568 memcpy(add_list
[num_add
].mac_addr
,
1569 f
->macaddr
, ETH_ALEN
);
1570 add_list
[num_add
].vlan_tag
=
1572 (u16
)(f
->vlan
== I40E_VLAN_ANY
? 0 : f
->vlan
));
1573 add_list
[num_add
].queue_number
= 0;
1575 cmd_flags
|= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
;
1576 add_list
[num_add
].flags
= cpu_to_le16(cmd_flags
);
1579 /* flush a full buffer */
1580 if (num_add
== filter_list_len
) {
1581 aq_ret
= i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
,
1588 memset(add_list
, 0, sizeof(*add_list
));
1592 aq_ret
= i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
,
1593 add_list
, num_add
, NULL
);
1599 if (add_happened
&& (!aq_ret
)) {
1601 } else if (add_happened
&& (aq_ret
)) {
1602 dev_info(&pf
->pdev
->dev
,
1603 "add filter failed, err %d, aq_err %d\n",
1604 aq_ret
, pf
->hw
.aq
.asq_last_status
);
1605 if ((pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_ENOSPC
) &&
1606 !test_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
1608 promisc_forced_on
= true;
1609 set_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
1611 dev_info(&pf
->pdev
->dev
, "promiscuous mode forced on\n");
1616 /* check for changes in promiscuous modes */
1617 if (changed_flags
& IFF_ALLMULTI
) {
1618 bool cur_multipromisc
;
1619 cur_multipromisc
= !!(vsi
->current_netdev_flags
& IFF_ALLMULTI
);
1620 aq_ret
= i40e_aq_set_vsi_multicast_promiscuous(&vsi
->back
->hw
,
1625 dev_info(&pf
->pdev
->dev
,
1626 "set multi promisc failed, err %d, aq_err %d\n",
1627 aq_ret
, pf
->hw
.aq
.asq_last_status
);
1629 if ((changed_flags
& IFF_PROMISC
) || promisc_forced_on
) {
1631 cur_promisc
= (!!(vsi
->current_netdev_flags
& IFF_PROMISC
) ||
1632 test_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
1634 aq_ret
= i40e_aq_set_vsi_unicast_promiscuous(&vsi
->back
->hw
,
1638 dev_info(&pf
->pdev
->dev
,
1639 "set uni promisc failed, err %d, aq_err %d\n",
1640 aq_ret
, pf
->hw
.aq
.asq_last_status
);
1641 aq_ret
= i40e_aq_set_vsi_broadcast(&vsi
->back
->hw
,
1645 dev_info(&pf
->pdev
->dev
,
1646 "set brdcast promisc failed, err %d, aq_err %d\n",
1647 aq_ret
, pf
->hw
.aq
.asq_last_status
);
1650 clear_bit(__I40E_CONFIG_BUSY
, &vsi
->state
);
1655 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
1656 * @pf: board private structure
1658 static void i40e_sync_filters_subtask(struct i40e_pf
*pf
)
1662 if (!pf
|| !(pf
->flags
& I40E_FLAG_FILTER_SYNC
))
1664 pf
->flags
&= ~I40E_FLAG_FILTER_SYNC
;
1666 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
; v
++) {
1668 (pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_FILTER_CHANGED
))
1669 i40e_sync_vsi_filters(pf
->vsi
[v
]);
1674 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
1675 * @netdev: network interface device structure
1676 * @new_mtu: new value for maximum frame size
1678 * Returns 0 on success, negative on failure
1680 static int i40e_change_mtu(struct net_device
*netdev
, int new_mtu
)
1682 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1683 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
1684 struct i40e_vsi
*vsi
= np
->vsi
;
1686 /* MTU < 68 is an error and causes problems on some kernels */
1687 if ((new_mtu
< 68) || (max_frame
> I40E_MAX_RXBUFFER
))
1690 netdev_info(netdev
, "changing MTU from %d to %d\n",
1691 netdev
->mtu
, new_mtu
);
1692 netdev
->mtu
= new_mtu
;
1693 if (netif_running(netdev
))
1694 i40e_vsi_reinit_locked(vsi
);
1700 * i40e_ioctl - Access the hwtstamp interface
1701 * @netdev: network interface device structure
1702 * @ifr: interface request data
1703 * @cmd: ioctl command
1705 int i40e_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
1707 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1708 struct i40e_pf
*pf
= np
->vsi
->back
;
1712 return i40e_ptp_get_ts_config(pf
, ifr
);
1714 return i40e_ptp_set_ts_config(pf
, ifr
);
1721 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
1722 * @vsi: the vsi being adjusted
1724 void i40e_vlan_stripping_enable(struct i40e_vsi
*vsi
)
1726 struct i40e_vsi_context ctxt
;
1729 if ((vsi
->info
.valid_sections
&
1730 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
1731 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_MODE_MASK
) == 0))
1732 return; /* already enabled */
1734 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
1735 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
1736 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH
;
1738 ctxt
.seid
= vsi
->seid
;
1739 memcpy(&ctxt
.info
, &vsi
->info
, sizeof(vsi
->info
));
1740 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
1742 dev_info(&vsi
->back
->pdev
->dev
,
1743 "%s: update vsi failed, aq_err=%d\n",
1744 __func__
, vsi
->back
->hw
.aq
.asq_last_status
);
1749 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
1750 * @vsi: the vsi being adjusted
1752 void i40e_vlan_stripping_disable(struct i40e_vsi
*vsi
)
1754 struct i40e_vsi_context ctxt
;
1757 if ((vsi
->info
.valid_sections
&
1758 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
1759 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_EMOD_MASK
) ==
1760 I40E_AQ_VSI_PVLAN_EMOD_MASK
))
1761 return; /* already disabled */
1763 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
1764 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
1765 I40E_AQ_VSI_PVLAN_EMOD_NOTHING
;
1767 ctxt
.seid
= vsi
->seid
;
1768 memcpy(&ctxt
.info
, &vsi
->info
, sizeof(vsi
->info
));
1769 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
1771 dev_info(&vsi
->back
->pdev
->dev
,
1772 "%s: update vsi failed, aq_err=%d\n",
1773 __func__
, vsi
->back
->hw
.aq
.asq_last_status
);
1778 * i40e_vlan_rx_register - Setup or shutdown vlan offload
1779 * @netdev: network interface to be adjusted
1780 * @features: netdev features to test if VLAN offload is enabled or not
1782 static void i40e_vlan_rx_register(struct net_device
*netdev
, u32 features
)
1784 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1785 struct i40e_vsi
*vsi
= np
->vsi
;
1787 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
1788 i40e_vlan_stripping_enable(vsi
);
1790 i40e_vlan_stripping_disable(vsi
);
1794 * i40e_vsi_add_vlan - Add vsi membership for given vlan
1795 * @vsi: the vsi being configured
1796 * @vid: vlan id to be added (0 = untagged only , -1 = any)
1798 int i40e_vsi_add_vlan(struct i40e_vsi
*vsi
, s16 vid
)
1800 struct i40e_mac_filter
*f
, *add_f
;
1801 bool is_netdev
, is_vf
;
1803 is_vf
= (vsi
->type
== I40E_VSI_SRIOV
);
1804 is_netdev
= !!(vsi
->netdev
);
1807 add_f
= i40e_add_filter(vsi
, vsi
->netdev
->dev_addr
, vid
,
1810 dev_info(&vsi
->back
->pdev
->dev
,
1811 "Could not add vlan filter %d for %pM\n",
1812 vid
, vsi
->netdev
->dev_addr
);
1817 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1818 add_f
= i40e_add_filter(vsi
, f
->macaddr
, vid
, is_vf
, is_netdev
);
1820 dev_info(&vsi
->back
->pdev
->dev
,
1821 "Could not add vlan filter %d for %pM\n",
1827 /* Now if we add a vlan tag, make sure to check if it is the first
1828 * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
1829 * with 0, so we now accept untagged and specified tagged traffic
1830 * (and not any taged and untagged)
1833 if (is_netdev
&& i40e_find_filter(vsi
, vsi
->netdev
->dev_addr
,
1835 is_vf
, is_netdev
)) {
1836 i40e_del_filter(vsi
, vsi
->netdev
->dev_addr
,
1837 I40E_VLAN_ANY
, is_vf
, is_netdev
);
1838 add_f
= i40e_add_filter(vsi
, vsi
->netdev
->dev_addr
, 0,
1841 dev_info(&vsi
->back
->pdev
->dev
,
1842 "Could not add filter 0 for %pM\n",
1843 vsi
->netdev
->dev_addr
);
1849 /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
1850 if (vid
> 0 && !vsi
->info
.pvid
) {
1851 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1852 if (i40e_find_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
1853 is_vf
, is_netdev
)) {
1854 i40e_del_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
1856 add_f
= i40e_add_filter(vsi
, f
->macaddr
,
1857 0, is_vf
, is_netdev
);
1859 dev_info(&vsi
->back
->pdev
->dev
,
1860 "Could not add filter 0 for %pM\n",
1868 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
1869 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
1872 return i40e_sync_vsi_filters(vsi
);
1876 * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
1877 * @vsi: the vsi being configured
1878 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
1880 * Return: 0 on success or negative otherwise
1882 int i40e_vsi_kill_vlan(struct i40e_vsi
*vsi
, s16 vid
)
1884 struct net_device
*netdev
= vsi
->netdev
;
1885 struct i40e_mac_filter
*f
, *add_f
;
1886 bool is_vf
, is_netdev
;
1887 int filter_count
= 0;
1889 is_vf
= (vsi
->type
== I40E_VSI_SRIOV
);
1890 is_netdev
= !!(netdev
);
1893 i40e_del_filter(vsi
, netdev
->dev_addr
, vid
, is_vf
, is_netdev
);
1895 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
)
1896 i40e_del_filter(vsi
, f
->macaddr
, vid
, is_vf
, is_netdev
);
1898 /* go through all the filters for this VSI and if there is only
1899 * vid == 0 it means there are no other filters, so vid 0 must
1900 * be replaced with -1. This signifies that we should from now
1901 * on accept any traffic (with any tag present, or untagged)
1903 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1906 ether_addr_equal(netdev
->dev_addr
, f
->macaddr
))
1914 if (!filter_count
&& is_netdev
) {
1915 i40e_del_filter(vsi
, netdev
->dev_addr
, 0, is_vf
, is_netdev
);
1916 f
= i40e_add_filter(vsi
, netdev
->dev_addr
, I40E_VLAN_ANY
,
1919 dev_info(&vsi
->back
->pdev
->dev
,
1920 "Could not add filter %d for %pM\n",
1921 I40E_VLAN_ANY
, netdev
->dev_addr
);
1926 if (!filter_count
) {
1927 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1928 i40e_del_filter(vsi
, f
->macaddr
, 0, is_vf
, is_netdev
);
1929 add_f
= i40e_add_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
1932 dev_info(&vsi
->back
->pdev
->dev
,
1933 "Could not add filter %d for %pM\n",
1934 I40E_VLAN_ANY
, f
->macaddr
);
1940 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
1941 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
1944 return i40e_sync_vsi_filters(vsi
);
1948 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
1949 * @netdev: network interface to be adjusted
1950 * @vid: vlan id to be added
1952 * net_device_ops implementation for adding vlan ids
1954 static int i40e_vlan_rx_add_vid(struct net_device
*netdev
,
1955 __always_unused __be16 proto
, u16 vid
)
1957 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1958 struct i40e_vsi
*vsi
= np
->vsi
;
1964 netdev_info(netdev
, "adding %pM vid=%d\n", netdev
->dev_addr
, vid
);
1966 /* If the network stack called us with vid = 0, we should
1967 * indicate to i40e_vsi_add_vlan() that we want to receive
1968 * any traffic (i.e. with any vlan tag, or untagged)
1970 ret
= i40e_vsi_add_vlan(vsi
, vid
? vid
: I40E_VLAN_ANY
);
1972 if (!ret
&& (vid
< VLAN_N_VID
))
1973 set_bit(vid
, vsi
->active_vlans
);
1979 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
1980 * @netdev: network interface to be adjusted
1981 * @vid: vlan id to be removed
1983 * net_device_ops implementation for adding vlan ids
1985 static int i40e_vlan_rx_kill_vid(struct net_device
*netdev
,
1986 __always_unused __be16 proto
, u16 vid
)
1988 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1989 struct i40e_vsi
*vsi
= np
->vsi
;
1991 netdev_info(netdev
, "removing %pM vid=%d\n", netdev
->dev_addr
, vid
);
1993 /* return code is ignored as there is nothing a user
1994 * can do about failure to remove and a log message was
1995 * already printed from the other function
1997 i40e_vsi_kill_vlan(vsi
, vid
);
1999 clear_bit(vid
, vsi
->active_vlans
);
2005 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2006 * @vsi: the vsi being brought back up
2008 static void i40e_restore_vlan(struct i40e_vsi
*vsi
)
2015 i40e_vlan_rx_register(vsi
->netdev
, vsi
->netdev
->features
);
2017 for_each_set_bit(vid
, vsi
->active_vlans
, VLAN_N_VID
)
2018 i40e_vlan_rx_add_vid(vsi
->netdev
, htons(ETH_P_8021Q
),
2023 * i40e_vsi_add_pvid - Add pvid for the VSI
2024 * @vsi: the vsi being adjusted
2025 * @vid: the vlan id to set as a PVID
2027 int i40e_vsi_add_pvid(struct i40e_vsi
*vsi
, u16 vid
)
2029 struct i40e_vsi_context ctxt
;
2032 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2033 vsi
->info
.pvid
= cpu_to_le16(vid
);
2034 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_TAGGED
|
2035 I40E_AQ_VSI_PVLAN_INSERT_PVID
|
2036 I40E_AQ_VSI_PVLAN_EMOD_STR
;
2038 ctxt
.seid
= vsi
->seid
;
2039 memcpy(&ctxt
.info
, &vsi
->info
, sizeof(vsi
->info
));
2040 aq_ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2042 dev_info(&vsi
->back
->pdev
->dev
,
2043 "%s: update vsi failed, aq_err=%d\n",
2044 __func__
, vsi
->back
->hw
.aq
.asq_last_status
);
2052 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2053 * @vsi: the vsi being adjusted
2055 * Just use the vlan_rx_register() service to put it back to normal
2057 void i40e_vsi_remove_pvid(struct i40e_vsi
*vsi
)
2059 i40e_vlan_stripping_disable(vsi
);
2065 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2066 * @vsi: ptr to the VSI
2068 * If this function returns with an error, then it's possible one or
2069 * more of the rings is populated (while the rest are not). It is the
2070 * callers duty to clean those orphaned rings.
2072 * Return 0 on success, negative on failure
2074 static int i40e_vsi_setup_tx_resources(struct i40e_vsi
*vsi
)
2078 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2079 err
= i40e_setup_tx_descriptors(vsi
->tx_rings
[i
]);
2085 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2086 * @vsi: ptr to the VSI
2088 * Free VSI's transmit software resources
2090 static void i40e_vsi_free_tx_resources(struct i40e_vsi
*vsi
)
2097 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2098 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
)
2099 i40e_free_tx_resources(vsi
->tx_rings
[i
]);
2103 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2104 * @vsi: ptr to the VSI
2106 * If this function returns with an error, then it's possible one or
2107 * more of the rings is populated (while the rest are not). It is the
2108 * callers duty to clean those orphaned rings.
2110 * Return 0 on success, negative on failure
2112 static int i40e_vsi_setup_rx_resources(struct i40e_vsi
*vsi
)
2116 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2117 err
= i40e_setup_rx_descriptors(vsi
->rx_rings
[i
]);
2122 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2123 * @vsi: ptr to the VSI
2125 * Free all receive software resources
2127 static void i40e_vsi_free_rx_resources(struct i40e_vsi
*vsi
)
2134 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2135 if (vsi
->rx_rings
[i
] && vsi
->rx_rings
[i
]->desc
)
2136 i40e_free_rx_resources(vsi
->rx_rings
[i
]);
2140 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2141 * @ring: The Tx ring to configure
2143 * Configure the Tx descriptor ring in the HMC context.
2145 static int i40e_configure_tx_ring(struct i40e_ring
*ring
)
2147 struct i40e_vsi
*vsi
= ring
->vsi
;
2148 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
2149 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2150 struct i40e_hmc_obj_txq tx_ctx
;
2151 i40e_status err
= 0;
2154 /* some ATR related tx ring init */
2155 if (vsi
->back
->flags
& I40E_FLAG_FDIR_ATR_ENABLED
) {
2156 ring
->atr_sample_rate
= vsi
->back
->atr_sample_rate
;
2157 ring
->atr_count
= 0;
2159 ring
->atr_sample_rate
= 0;
2162 /* initialize XPS */
2163 if (ring
->q_vector
&& ring
->netdev
&&
2164 !test_and_set_bit(__I40E_TX_XPS_INIT_DONE
, &ring
->state
))
2165 netif_set_xps_queue(ring
->netdev
,
2166 &ring
->q_vector
->affinity_mask
,
2169 /* clear the context structure first */
2170 memset(&tx_ctx
, 0, sizeof(tx_ctx
));
2172 tx_ctx
.new_context
= 1;
2173 tx_ctx
.base
= (ring
->dma
/ 128);
2174 tx_ctx
.qlen
= ring
->count
;
2175 tx_ctx
.fd_ena
= !!(vsi
->back
->flags
& (I40E_FLAG_FDIR_ENABLED
|
2176 I40E_FLAG_FDIR_ATR_ENABLED
));
2177 tx_ctx
.timesync_ena
= !!(vsi
->back
->flags
& I40E_FLAG_PTP
);
2179 /* As part of VSI creation/update, FW allocates certain
2180 * Tx arbitration queue sets for each TC enabled for
2181 * the VSI. The FW returns the handles to these queue
2182 * sets as part of the response buffer to Add VSI,
2183 * Update VSI, etc. AQ commands. It is expected that
2184 * these queue set handles be associated with the Tx
2185 * queues by the driver as part of the TX queue context
2186 * initialization. This has to be done regardless of
2187 * DCB as by default everything is mapped to TC0.
2189 tx_ctx
.rdylist
= le16_to_cpu(vsi
->info
.qs_handle
[ring
->dcb_tc
]);
2190 tx_ctx
.rdylist_act
= 0;
2192 /* clear the context in the HMC */
2193 err
= i40e_clear_lan_tx_queue_context(hw
, pf_q
);
2195 dev_info(&vsi
->back
->pdev
->dev
,
2196 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2197 ring
->queue_index
, pf_q
, err
);
2201 /* set the context in the HMC */
2202 err
= i40e_set_lan_tx_queue_context(hw
, pf_q
, &tx_ctx
);
2204 dev_info(&vsi
->back
->pdev
->dev
,
2205 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
2206 ring
->queue_index
, pf_q
, err
);
2210 /* Now associate this queue with this PCI function */
2211 if (vsi
->type
== I40E_VSI_VMDQ2
)
2212 qtx_ctl
= I40E_QTX_CTL_VM_QUEUE
;
2214 qtx_ctl
= I40E_QTX_CTL_PF_QUEUE
;
2215 qtx_ctl
|= ((hw
->pf_id
<< I40E_QTX_CTL_PF_INDX_SHIFT
) &
2216 I40E_QTX_CTL_PF_INDX_MASK
);
2217 wr32(hw
, I40E_QTX_CTL(pf_q
), qtx_ctl
);
2220 clear_bit(__I40E_HANG_CHECK_ARMED
, &ring
->state
);
2222 /* cache tail off for easier writes later */
2223 ring
->tail
= hw
->hw_addr
+ I40E_QTX_TAIL(pf_q
);
2229 * i40e_configure_rx_ring - Configure a receive ring context
2230 * @ring: The Rx ring to configure
2232 * Configure the Rx descriptor ring in the HMC context.
2234 static int i40e_configure_rx_ring(struct i40e_ring
*ring
)
2236 struct i40e_vsi
*vsi
= ring
->vsi
;
2237 u32 chain_len
= vsi
->back
->hw
.func_caps
.rx_buf_chain_len
;
2238 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
2239 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2240 struct i40e_hmc_obj_rxq rx_ctx
;
2241 i40e_status err
= 0;
2245 /* clear the context structure first */
2246 memset(&rx_ctx
, 0, sizeof(rx_ctx
));
2248 ring
->rx_buf_len
= vsi
->rx_buf_len
;
2249 ring
->rx_hdr_len
= vsi
->rx_hdr_len
;
2251 rx_ctx
.dbuff
= ring
->rx_buf_len
>> I40E_RXQ_CTX_DBUFF_SHIFT
;
2252 rx_ctx
.hbuff
= ring
->rx_hdr_len
>> I40E_RXQ_CTX_HBUFF_SHIFT
;
2254 rx_ctx
.base
= (ring
->dma
/ 128);
2255 rx_ctx
.qlen
= ring
->count
;
2257 if (vsi
->back
->flags
& I40E_FLAG_16BYTE_RX_DESC_ENABLED
) {
2258 set_ring_16byte_desc_enabled(ring
);
2264 rx_ctx
.dtype
= vsi
->dtype
;
2266 set_ring_ps_enabled(ring
);
2267 rx_ctx
.hsplit_0
= I40E_RX_SPLIT_L2
|
2269 I40E_RX_SPLIT_TCP_UDP
|
2272 rx_ctx
.hsplit_0
= 0;
2275 rx_ctx
.rxmax
= min_t(u16
, vsi
->max_frame
,
2276 (chain_len
* ring
->rx_buf_len
));
2277 rx_ctx
.tphrdesc_ena
= 1;
2278 rx_ctx
.tphwdesc_ena
= 1;
2279 rx_ctx
.tphdata_ena
= 1;
2280 rx_ctx
.tphhead_ena
= 1;
2281 if (hw
->revision_id
== 0)
2282 rx_ctx
.lrxqthresh
= 0;
2284 rx_ctx
.lrxqthresh
= 2;
2285 rx_ctx
.crcstrip
= 1;
2289 /* clear the context in the HMC */
2290 err
= i40e_clear_lan_rx_queue_context(hw
, pf_q
);
2292 dev_info(&vsi
->back
->pdev
->dev
,
2293 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2294 ring
->queue_index
, pf_q
, err
);
2298 /* set the context in the HMC */
2299 err
= i40e_set_lan_rx_queue_context(hw
, pf_q
, &rx_ctx
);
2301 dev_info(&vsi
->back
->pdev
->dev
,
2302 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2303 ring
->queue_index
, pf_q
, err
);
2307 /* cache tail for quicker writes, and clear the reg before use */
2308 ring
->tail
= hw
->hw_addr
+ I40E_QRX_TAIL(pf_q
);
2309 writel(0, ring
->tail
);
2311 i40e_alloc_rx_buffers(ring
, I40E_DESC_UNUSED(ring
));
2317 * i40e_vsi_configure_tx - Configure the VSI for Tx
2318 * @vsi: VSI structure describing this set of rings and resources
2320 * Configure the Tx VSI for operation.
2322 static int i40e_vsi_configure_tx(struct i40e_vsi
*vsi
)
2327 for (i
= 0; (i
< vsi
->num_queue_pairs
) && !err
; i
++)
2328 err
= i40e_configure_tx_ring(vsi
->tx_rings
[i
]);
2334 * i40e_vsi_configure_rx - Configure the VSI for Rx
2335 * @vsi: the VSI being configured
2337 * Configure the Rx VSI for operation.
2339 static int i40e_vsi_configure_rx(struct i40e_vsi
*vsi
)
2344 if (vsi
->netdev
&& (vsi
->netdev
->mtu
> ETH_DATA_LEN
))
2345 vsi
->max_frame
= vsi
->netdev
->mtu
+ ETH_HLEN
2346 + ETH_FCS_LEN
+ VLAN_HLEN
;
2348 vsi
->max_frame
= I40E_RXBUFFER_2048
;
2350 /* figure out correct receive buffer length */
2351 switch (vsi
->back
->flags
& (I40E_FLAG_RX_1BUF_ENABLED
|
2352 I40E_FLAG_RX_PS_ENABLED
)) {
2353 case I40E_FLAG_RX_1BUF_ENABLED
:
2354 vsi
->rx_hdr_len
= 0;
2355 vsi
->rx_buf_len
= vsi
->max_frame
;
2356 vsi
->dtype
= I40E_RX_DTYPE_NO_SPLIT
;
2358 case I40E_FLAG_RX_PS_ENABLED
:
2359 vsi
->rx_hdr_len
= I40E_RX_HDR_SIZE
;
2360 vsi
->rx_buf_len
= I40E_RXBUFFER_2048
;
2361 vsi
->dtype
= I40E_RX_DTYPE_HEADER_SPLIT
;
2364 vsi
->rx_hdr_len
= I40E_RX_HDR_SIZE
;
2365 vsi
->rx_buf_len
= I40E_RXBUFFER_2048
;
2366 vsi
->dtype
= I40E_RX_DTYPE_SPLIT_ALWAYS
;
2370 /* round up for the chip's needs */
2371 vsi
->rx_hdr_len
= ALIGN(vsi
->rx_hdr_len
,
2372 (1 << I40E_RXQ_CTX_HBUFF_SHIFT
));
2373 vsi
->rx_buf_len
= ALIGN(vsi
->rx_buf_len
,
2374 (1 << I40E_RXQ_CTX_DBUFF_SHIFT
));
2376 /* set up individual rings */
2377 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2378 err
= i40e_configure_rx_ring(vsi
->rx_rings
[i
]);
2384 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
2385 * @vsi: ptr to the VSI
2387 static void i40e_vsi_config_dcb_rings(struct i40e_vsi
*vsi
)
2389 u16 qoffset
, qcount
;
2392 if (!(vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
))
2395 for (n
= 0; n
< I40E_MAX_TRAFFIC_CLASS
; n
++) {
2396 if (!(vsi
->tc_config
.enabled_tc
& (1 << n
)))
2399 qoffset
= vsi
->tc_config
.tc_info
[n
].qoffset
;
2400 qcount
= vsi
->tc_config
.tc_info
[n
].qcount
;
2401 for (i
= qoffset
; i
< (qoffset
+ qcount
); i
++) {
2402 struct i40e_ring
*rx_ring
= vsi
->rx_rings
[i
];
2403 struct i40e_ring
*tx_ring
= vsi
->tx_rings
[i
];
2404 rx_ring
->dcb_tc
= n
;
2405 tx_ring
->dcb_tc
= n
;
2411 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
2412 * @vsi: ptr to the VSI
2414 static void i40e_set_vsi_rx_mode(struct i40e_vsi
*vsi
)
2417 i40e_set_rx_mode(vsi
->netdev
);
2421 * i40e_vsi_configure - Set up the VSI for action
2422 * @vsi: the VSI being configured
2424 static int i40e_vsi_configure(struct i40e_vsi
*vsi
)
2428 i40e_set_vsi_rx_mode(vsi
);
2429 i40e_restore_vlan(vsi
);
2430 i40e_vsi_config_dcb_rings(vsi
);
2431 err
= i40e_vsi_configure_tx(vsi
);
2433 err
= i40e_vsi_configure_rx(vsi
);
2439 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
2440 * @vsi: the VSI being configured
2442 static void i40e_vsi_configure_msix(struct i40e_vsi
*vsi
)
2444 struct i40e_pf
*pf
= vsi
->back
;
2445 struct i40e_q_vector
*q_vector
;
2446 struct i40e_hw
*hw
= &pf
->hw
;
2452 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
2453 * and PFINT_LNKLSTn registers, e.g.:
2454 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
2456 qp
= vsi
->base_queue
;
2457 vector
= vsi
->base_vector
;
2458 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vector
++) {
2459 q_vector
= vsi
->q_vectors
[i
];
2460 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
2461 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
2462 wr32(hw
, I40E_PFINT_ITRN(I40E_RX_ITR
, vector
- 1),
2464 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
2465 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
2466 wr32(hw
, I40E_PFINT_ITRN(I40E_TX_ITR
, vector
- 1),
2469 /* Linked list for the queuepairs assigned to this vector */
2470 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), qp
);
2471 for (q
= 0; q
< q_vector
->num_ringpairs
; q
++) {
2472 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
2473 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
2474 (vector
<< I40E_QINT_RQCTL_MSIX_INDX_SHIFT
) |
2475 (qp
<< I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT
)|
2477 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT
);
2479 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
2481 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
2482 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
2483 (vector
<< I40E_QINT_TQCTL_MSIX_INDX_SHIFT
) |
2484 ((qp
+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
)|
2486 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
2488 /* Terminate the linked list */
2489 if (q
== (q_vector
->num_ringpairs
- 1))
2490 val
|= (I40E_QUEUE_END_OF_LIST
2491 << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
2493 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
2502 * i40e_enable_misc_int_causes - enable the non-queue interrupts
2503 * @hw: ptr to the hardware info
2505 static void i40e_enable_misc_int_causes(struct i40e_hw
*hw
)
2509 /* clear things first */
2510 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0); /* disable all */
2511 rd32(hw
, I40E_PFINT_ICR0
); /* read to clear */
2513 val
= I40E_PFINT_ICR0_ENA_ECC_ERR_MASK
|
2514 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
|
2515 I40E_PFINT_ICR0_ENA_GRST_MASK
|
2516 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK
|
2517 I40E_PFINT_ICR0_ENA_GPIO_MASK
|
2518 I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
|
2519 I40E_PFINT_ICR0_ENA_STORM_DETECT_MASK
|
2520 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK
|
2521 I40E_PFINT_ICR0_ENA_VFLR_MASK
|
2522 I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
2524 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
2526 /* SW_ITR_IDX = 0, but don't change INTENA */
2527 wr32(hw
, I40E_PFINT_DYN_CTL0
, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK
|
2528 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK
);
2530 /* OTHER_ITR_IDX = 0 */
2531 wr32(hw
, I40E_PFINT_STAT_CTL0
, 0);
2535 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
2536 * @vsi: the VSI being configured
2538 static void i40e_configure_msi_and_legacy(struct i40e_vsi
*vsi
)
2540 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[0];
2541 struct i40e_pf
*pf
= vsi
->back
;
2542 struct i40e_hw
*hw
= &pf
->hw
;
2545 /* set the ITR configuration */
2546 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
2547 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
2548 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), q_vector
->rx
.itr
);
2549 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
2550 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
2551 wr32(hw
, I40E_PFINT_ITR0(I40E_TX_ITR
), q_vector
->tx
.itr
);
2553 i40e_enable_misc_int_causes(hw
);
2555 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
2556 wr32(hw
, I40E_PFINT_LNKLST0
, 0);
2558 /* Associate the queue pair to the vector and enable the q int */
2559 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
2560 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
2561 (I40E_QUEUE_TYPE_TX
<< I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
2563 wr32(hw
, I40E_QINT_RQCTL(0), val
);
2565 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
2566 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
2567 (I40E_QUEUE_END_OF_LIST
<< I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
2569 wr32(hw
, I40E_QINT_TQCTL(0), val
);
2574 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
2575 * @pf: board private structure
2577 void i40e_irq_dynamic_disable_icr0(struct i40e_pf
*pf
)
2579 struct i40e_hw
*hw
= &pf
->hw
;
2581 wr32(hw
, I40E_PFINT_DYN_CTL0
,
2582 I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
);
2587 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
2588 * @pf: board private structure
2590 void i40e_irq_dynamic_enable_icr0(struct i40e_pf
*pf
)
2592 struct i40e_hw
*hw
= &pf
->hw
;
2595 val
= I40E_PFINT_DYN_CTL0_INTENA_MASK
|
2596 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK
|
2597 (I40E_ITR_NONE
<< I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT
);
2599 wr32(hw
, I40E_PFINT_DYN_CTL0
, val
);
2604 * i40e_irq_dynamic_enable - Enable default interrupt generation settings
2605 * @vsi: pointer to a vsi
2606 * @vector: enable a particular Hw Interrupt vector
2608 void i40e_irq_dynamic_enable(struct i40e_vsi
*vsi
, int vector
)
2610 struct i40e_pf
*pf
= vsi
->back
;
2611 struct i40e_hw
*hw
= &pf
->hw
;
2614 val
= I40E_PFINT_DYN_CTLN_INTENA_MASK
|
2615 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK
|
2616 (I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
);
2617 wr32(hw
, I40E_PFINT_DYN_CTLN(vector
- 1), val
);
2618 /* skip the flush */
2622 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
2623 * @irq: interrupt number
2624 * @data: pointer to a q_vector
2626 static irqreturn_t
i40e_msix_clean_rings(int irq
, void *data
)
2628 struct i40e_q_vector
*q_vector
= data
;
2630 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
2633 napi_schedule(&q_vector
->napi
);
2639 * i40e_fdir_clean_rings - Interrupt Handler for FDIR rings
2640 * @irq: interrupt number
2641 * @data: pointer to a q_vector
2643 static irqreturn_t
i40e_fdir_clean_rings(int irq
, void *data
)
2645 struct i40e_q_vector
*q_vector
= data
;
2647 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
2650 pr_info("fdir ring cleaning needed\n");
2656 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
2657 * @vsi: the VSI being configured
2658 * @basename: name for the vector
2660 * Allocates MSI-X vectors and requests interrupts from the kernel.
2662 static int i40e_vsi_request_irq_msix(struct i40e_vsi
*vsi
, char *basename
)
2664 int q_vectors
= vsi
->num_q_vectors
;
2665 struct i40e_pf
*pf
= vsi
->back
;
2666 int base
= vsi
->base_vector
;
2671 for (vector
= 0; vector
< q_vectors
; vector
++) {
2672 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[vector
];
2674 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
2675 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2676 "%s-%s-%d", basename
, "TxRx", rx_int_idx
++);
2678 } else if (q_vector
->rx
.ring
) {
2679 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2680 "%s-%s-%d", basename
, "rx", rx_int_idx
++);
2681 } else if (q_vector
->tx
.ring
) {
2682 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2683 "%s-%s-%d", basename
, "tx", tx_int_idx
++);
2685 /* skip this unused q_vector */
2688 err
= request_irq(pf
->msix_entries
[base
+ vector
].vector
,
2694 dev_info(&pf
->pdev
->dev
,
2695 "%s: request_irq failed, error: %d\n",
2697 goto free_queue_irqs
;
2699 /* assign the mask for this irq */
2700 irq_set_affinity_hint(pf
->msix_entries
[base
+ vector
].vector
,
2701 &q_vector
->affinity_mask
);
2709 irq_set_affinity_hint(pf
->msix_entries
[base
+ vector
].vector
,
2711 free_irq(pf
->msix_entries
[base
+ vector
].vector
,
2712 &(vsi
->q_vectors
[vector
]));
2718 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
2719 * @vsi: the VSI being un-configured
2721 static void i40e_vsi_disable_irq(struct i40e_vsi
*vsi
)
2723 struct i40e_pf
*pf
= vsi
->back
;
2724 struct i40e_hw
*hw
= &pf
->hw
;
2725 int base
= vsi
->base_vector
;
2728 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
2729 wr32(hw
, I40E_QINT_TQCTL(vsi
->tx_rings
[i
]->reg_idx
), 0);
2730 wr32(hw
, I40E_QINT_RQCTL(vsi
->rx_rings
[i
]->reg_idx
), 0);
2733 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
2734 for (i
= vsi
->base_vector
;
2735 i
< (vsi
->num_q_vectors
+ vsi
->base_vector
); i
++)
2736 wr32(hw
, I40E_PFINT_DYN_CTLN(i
- 1), 0);
2739 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
2740 synchronize_irq(pf
->msix_entries
[i
+ base
].vector
);
2742 /* Legacy and MSI mode - this stops all interrupt handling */
2743 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0);
2744 wr32(hw
, I40E_PFINT_DYN_CTL0
, 0);
2746 synchronize_irq(pf
->pdev
->irq
);
2751 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
2752 * @vsi: the VSI being configured
2754 static int i40e_vsi_enable_irq(struct i40e_vsi
*vsi
)
2756 struct i40e_pf
*pf
= vsi
->back
;
2759 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
2760 for (i
= vsi
->base_vector
;
2761 i
< (vsi
->num_q_vectors
+ vsi
->base_vector
); i
++)
2762 i40e_irq_dynamic_enable(vsi
, i
);
2764 i40e_irq_dynamic_enable_icr0(pf
);
2767 i40e_flush(&pf
->hw
);
2772 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
2773 * @pf: board private structure
2775 static void i40e_stop_misc_vector(struct i40e_pf
*pf
)
2778 wr32(&pf
->hw
, I40E_PFINT_ICR0_ENA
, 0);
2779 i40e_flush(&pf
->hw
);
2783 * i40e_intr - MSI/Legacy and non-queue interrupt handler
2784 * @irq: interrupt number
2785 * @data: pointer to a q_vector
2787 * This is the handler used for all MSI/Legacy interrupts, and deals
2788 * with both queue and non-queue interrupts. This is also used in
2789 * MSIX mode to handle the non-queue interrupts.
2791 static irqreturn_t
i40e_intr(int irq
, void *data
)
2793 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
2794 struct i40e_hw
*hw
= &pf
->hw
;
2795 irqreturn_t ret
= IRQ_NONE
;
2796 u32 icr0
, icr0_remaining
;
2799 icr0
= rd32(hw
, I40E_PFINT_ICR0
);
2800 ena_mask
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
2802 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
2803 if ((icr0
& I40E_PFINT_ICR0_INTEVENT_MASK
) == 0)
2806 /* if interrupt but no bits showing, must be SWINT */
2807 if (((icr0
& ~I40E_PFINT_ICR0_INTEVENT_MASK
) == 0) ||
2808 (icr0
& I40E_PFINT_ICR0_SWINT_MASK
))
2811 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
2812 if (icr0
& I40E_PFINT_ICR0_QUEUE_0_MASK
) {
2814 /* temporarily disable queue cause for NAPI processing */
2815 u32 qval
= rd32(hw
, I40E_QINT_RQCTL(0));
2816 qval
&= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK
;
2817 wr32(hw
, I40E_QINT_RQCTL(0), qval
);
2819 qval
= rd32(hw
, I40E_QINT_TQCTL(0));
2820 qval
&= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK
;
2821 wr32(hw
, I40E_QINT_TQCTL(0), qval
);
2823 if (!test_bit(__I40E_DOWN
, &pf
->state
))
2824 napi_schedule(&pf
->vsi
[pf
->lan_vsi
]->q_vectors
[0]->napi
);
2827 if (icr0
& I40E_PFINT_ICR0_ADMINQ_MASK
) {
2828 ena_mask
&= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
2829 set_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
);
2832 if (icr0
& I40E_PFINT_ICR0_MAL_DETECT_MASK
) {
2833 ena_mask
&= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
2834 set_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
);
2837 if (icr0
& I40E_PFINT_ICR0_VFLR_MASK
) {
2838 ena_mask
&= ~I40E_PFINT_ICR0_ENA_VFLR_MASK
;
2839 set_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
);
2842 if (icr0
& I40E_PFINT_ICR0_GRST_MASK
) {
2843 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
))
2844 set_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
);
2845 ena_mask
&= ~I40E_PFINT_ICR0_ENA_GRST_MASK
;
2846 val
= rd32(hw
, I40E_GLGEN_RSTAT
);
2847 val
= (val
& I40E_GLGEN_RSTAT_RESET_TYPE_MASK
)
2848 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT
;
2849 if (val
== I40E_RESET_CORER
)
2851 else if (val
== I40E_RESET_GLOBR
)
2853 else if (val
== I40E_RESET_EMPR
)
2857 if (icr0
& I40E_PFINT_ICR0_HMC_ERR_MASK
) {
2858 icr0
&= ~I40E_PFINT_ICR0_HMC_ERR_MASK
;
2859 dev_info(&pf
->pdev
->dev
, "HMC error interrupt\n");
2862 if (icr0
& I40E_PFINT_ICR0_TIMESYNC_MASK
) {
2863 u32 prttsyn_stat
= rd32(hw
, I40E_PRTTSYN_STAT_0
);
2865 if (prttsyn_stat
& I40E_PRTTSYN_STAT_0_TXTIME_MASK
) {
2866 ena_mask
&= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
2867 i40e_ptp_tx_hwtstamp(pf
);
2868 prttsyn_stat
&= ~I40E_PRTTSYN_STAT_0_TXTIME_MASK
;
2871 wr32(hw
, I40E_PRTTSYN_STAT_0
, prttsyn_stat
);
2874 /* If a critical error is pending we have no choice but to reset the
2876 * Report and mask out any remaining unexpected interrupts.
2878 icr0_remaining
= icr0
& ena_mask
;
2879 if (icr0_remaining
) {
2880 dev_info(&pf
->pdev
->dev
, "unhandled interrupt icr0=0x%08x\n",
2882 if ((icr0_remaining
& I40E_PFINT_ICR0_PE_CRITERR_MASK
) ||
2883 (icr0_remaining
& I40E_PFINT_ICR0_PCI_EXCEPTION_MASK
) ||
2884 (icr0_remaining
& I40E_PFINT_ICR0_ECC_ERR_MASK
) ||
2885 (icr0_remaining
& I40E_PFINT_ICR0_MAL_DETECT_MASK
)) {
2886 dev_info(&pf
->pdev
->dev
, "device will be reset\n");
2887 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
2888 i40e_service_event_schedule(pf
);
2890 ena_mask
&= ~icr0_remaining
;
2895 /* re-enable interrupt causes */
2896 wr32(hw
, I40E_PFINT_ICR0_ENA
, ena_mask
);
2897 if (!test_bit(__I40E_DOWN
, &pf
->state
)) {
2898 i40e_service_event_schedule(pf
);
2899 i40e_irq_dynamic_enable_icr0(pf
);
2906 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
2907 * @vsi: the VSI being configured
2908 * @v_idx: vector index
2909 * @qp_idx: queue pair index
2911 static void map_vector_to_qp(struct i40e_vsi
*vsi
, int v_idx
, int qp_idx
)
2913 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
2914 struct i40e_ring
*tx_ring
= vsi
->tx_rings
[qp_idx
];
2915 struct i40e_ring
*rx_ring
= vsi
->rx_rings
[qp_idx
];
2917 tx_ring
->q_vector
= q_vector
;
2918 tx_ring
->next
= q_vector
->tx
.ring
;
2919 q_vector
->tx
.ring
= tx_ring
;
2920 q_vector
->tx
.count
++;
2922 rx_ring
->q_vector
= q_vector
;
2923 rx_ring
->next
= q_vector
->rx
.ring
;
2924 q_vector
->rx
.ring
= rx_ring
;
2925 q_vector
->rx
.count
++;
2929 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
2930 * @vsi: the VSI being configured
2932 * This function maps descriptor rings to the queue-specific vectors
2933 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2934 * one vector per queue pair, but on a constrained vector budget, we
2935 * group the queue pairs as "efficiently" as possible.
2937 static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi
*vsi
)
2939 int qp_remaining
= vsi
->num_queue_pairs
;
2940 int q_vectors
= vsi
->num_q_vectors
;
2945 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
2946 * group them so there are multiple queues per vector.
2948 for (; v_start
< q_vectors
&& qp_remaining
; v_start
++) {
2949 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_start
];
2951 num_ringpairs
= DIV_ROUND_UP(qp_remaining
, q_vectors
- v_start
);
2953 q_vector
->num_ringpairs
= num_ringpairs
;
2955 q_vector
->rx
.count
= 0;
2956 q_vector
->tx
.count
= 0;
2957 q_vector
->rx
.ring
= NULL
;
2958 q_vector
->tx
.ring
= NULL
;
2960 while (num_ringpairs
--) {
2961 map_vector_to_qp(vsi
, v_start
, qp_idx
);
2969 * i40e_vsi_request_irq - Request IRQ from the OS
2970 * @vsi: the VSI being configured
2971 * @basename: name for the vector
2973 static int i40e_vsi_request_irq(struct i40e_vsi
*vsi
, char *basename
)
2975 struct i40e_pf
*pf
= vsi
->back
;
2978 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
2979 err
= i40e_vsi_request_irq_msix(vsi
, basename
);
2980 else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
)
2981 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, 0,
2982 pf
->misc_int_name
, pf
);
2984 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, IRQF_SHARED
,
2985 pf
->misc_int_name
, pf
);
2988 dev_info(&pf
->pdev
->dev
, "request_irq failed, Error %d\n", err
);
2993 #ifdef CONFIG_NET_POLL_CONTROLLER
2995 * i40e_netpoll - A Polling 'interrupt'handler
2996 * @netdev: network interface device structure
2998 * This is used by netconsole to send skbs without having to re-enable
2999 * interrupts. It's not called while the normal interrupt routine is executing.
3001 static void i40e_netpoll(struct net_device
*netdev
)
3003 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3004 struct i40e_vsi
*vsi
= np
->vsi
;
3005 struct i40e_pf
*pf
= vsi
->back
;
3008 /* if interface is down do nothing */
3009 if (test_bit(__I40E_DOWN
, &vsi
->state
))
3012 pf
->flags
|= I40E_FLAG_IN_NETPOLL
;
3013 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3014 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3015 i40e_msix_clean_rings(0, vsi
->q_vectors
[i
]);
3017 i40e_intr(pf
->pdev
->irq
, netdev
);
3019 pf
->flags
&= ~I40E_FLAG_IN_NETPOLL
;
3024 * i40e_vsi_control_tx - Start or stop a VSI's rings
3025 * @vsi: the VSI being configured
3026 * @enable: start or stop the rings
3028 static int i40e_vsi_control_tx(struct i40e_vsi
*vsi
, bool enable
)
3030 struct i40e_pf
*pf
= vsi
->back
;
3031 struct i40e_hw
*hw
= &pf
->hw
;
3035 pf_q
= vsi
->base_queue
;
3036 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
3039 usleep_range(1000, 2000);
3040 tx_reg
= rd32(hw
, I40E_QTX_ENA(pf_q
));
3041 } while (j
-- && ((tx_reg
>> I40E_QTX_ENA_QENA_REQ_SHIFT
)
3042 ^ (tx_reg
>> I40E_QTX_ENA_QENA_STAT_SHIFT
)) & 1);
3044 /* Skip if the queue is already in the requested state */
3045 if (enable
&& (tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
3047 if (!enable
&& !(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
3050 /* turn on/off the queue */
3052 wr32(hw
, I40E_QTX_HEAD(pf_q
), 0);
3053 tx_reg
|= I40E_QTX_ENA_QENA_REQ_MASK
|
3054 I40E_QTX_ENA_QENA_STAT_MASK
;
3056 tx_reg
&= ~I40E_QTX_ENA_QENA_REQ_MASK
;
3059 wr32(hw
, I40E_QTX_ENA(pf_q
), tx_reg
);
3061 /* wait for the change to finish */
3062 for (j
= 0; j
< 10; j
++) {
3063 tx_reg
= rd32(hw
, I40E_QTX_ENA(pf_q
));
3065 if ((tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
3068 if (!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
3075 dev_info(&pf
->pdev
->dev
, "Tx ring %d %sable timeout\n",
3076 pf_q
, (enable
? "en" : "dis"));
3081 if (hw
->revision_id
== 0)
3088 * i40e_vsi_control_rx - Start or stop a VSI's rings
3089 * @vsi: the VSI being configured
3090 * @enable: start or stop the rings
3092 static int i40e_vsi_control_rx(struct i40e_vsi
*vsi
, bool enable
)
3094 struct i40e_pf
*pf
= vsi
->back
;
3095 struct i40e_hw
*hw
= &pf
->hw
;
3099 pf_q
= vsi
->base_queue
;
3100 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
3103 usleep_range(1000, 2000);
3104 rx_reg
= rd32(hw
, I40E_QRX_ENA(pf_q
));
3105 } while (j
-- && ((rx_reg
>> I40E_QRX_ENA_QENA_REQ_SHIFT
)
3106 ^ (rx_reg
>> I40E_QRX_ENA_QENA_STAT_SHIFT
)) & 1);
3110 if ((rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
3113 /* is !STAT set ? */
3114 if (!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
3118 /* turn on/off the queue */
3120 rx_reg
|= I40E_QRX_ENA_QENA_REQ_MASK
|
3121 I40E_QRX_ENA_QENA_STAT_MASK
;
3123 rx_reg
&= ~(I40E_QRX_ENA_QENA_REQ_MASK
|
3124 I40E_QRX_ENA_QENA_STAT_MASK
);
3125 wr32(hw
, I40E_QRX_ENA(pf_q
), rx_reg
);
3127 /* wait for the change to finish */
3128 for (j
= 0; j
< 10; j
++) {
3129 rx_reg
= rd32(hw
, I40E_QRX_ENA(pf_q
));
3132 if ((rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
3135 if (!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
3142 dev_info(&pf
->pdev
->dev
, "Rx ring %d %sable timeout\n",
3143 pf_q
, (enable
? "en" : "dis"));
3152 * i40e_vsi_control_rings - Start or stop a VSI's rings
3153 * @vsi: the VSI being configured
3154 * @enable: start or stop the rings
3156 int i40e_vsi_control_rings(struct i40e_vsi
*vsi
, bool request
)
3160 /* do rx first for enable and last for disable */
3162 ret
= i40e_vsi_control_rx(vsi
, request
);
3165 ret
= i40e_vsi_control_tx(vsi
, request
);
3167 /* Ignore return value, we need to shutdown whatever we can */
3168 i40e_vsi_control_tx(vsi
, request
);
3169 i40e_vsi_control_rx(vsi
, request
);
3176 * i40e_vsi_free_irq - Free the irq association with the OS
3177 * @vsi: the VSI being configured
3179 static void i40e_vsi_free_irq(struct i40e_vsi
*vsi
)
3181 struct i40e_pf
*pf
= vsi
->back
;
3182 struct i40e_hw
*hw
= &pf
->hw
;
3183 int base
= vsi
->base_vector
;
3187 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3188 if (!vsi
->q_vectors
)
3191 for (i
= 0; i
< vsi
->num_q_vectors
; i
++) {
3192 u16 vector
= i
+ base
;
3194 /* free only the irqs that were actually requested */
3195 if (!vsi
->q_vectors
[i
] ||
3196 !vsi
->q_vectors
[i
]->num_ringpairs
)
3199 /* clear the affinity_mask in the IRQ descriptor */
3200 irq_set_affinity_hint(pf
->msix_entries
[vector
].vector
,
3202 free_irq(pf
->msix_entries
[vector
].vector
,
3205 /* Tear down the interrupt queue link list
3207 * We know that they come in pairs and always
3208 * the Rx first, then the Tx. To clear the
3209 * link list, stick the EOL value into the
3210 * next_q field of the registers.
3212 val
= rd32(hw
, I40E_PFINT_LNKLSTN(vector
- 1));
3213 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
3214 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
3215 val
|= I40E_QUEUE_END_OF_LIST
3216 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
3217 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), val
);
3219 while (qp
!= I40E_QUEUE_END_OF_LIST
) {
3222 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
3224 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
3225 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
3226 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3227 I40E_QINT_RQCTL_INTEVENT_MASK
);
3229 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
3230 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
3232 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
3234 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
3236 next
= (val
& I40E_QINT_TQCTL_NEXTQ_INDX_MASK
)
3237 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
;
3239 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
3240 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
3241 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3242 I40E_QINT_TQCTL_INTEVENT_MASK
);
3244 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
3245 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
3247 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
3252 free_irq(pf
->pdev
->irq
, pf
);
3254 val
= rd32(hw
, I40E_PFINT_LNKLST0
);
3255 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
3256 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
3257 val
|= I40E_QUEUE_END_OF_LIST
3258 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT
;
3259 wr32(hw
, I40E_PFINT_LNKLST0
, val
);
3261 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
3262 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
3263 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
3264 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3265 I40E_QINT_RQCTL_INTEVENT_MASK
);
3267 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
3268 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
3270 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
3272 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
3274 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
3275 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
3276 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3277 I40E_QINT_TQCTL_INTEVENT_MASK
);
3279 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
3280 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
3282 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
3287 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
3288 * @vsi: the VSI being configured
3289 * @v_idx: Index of vector to be freed
3291 * This function frees the memory allocated to the q_vector. In addition if
3292 * NAPI is enabled it will delete any references to the NAPI struct prior
3293 * to freeing the q_vector.
3295 static void i40e_free_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
3297 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
3298 struct i40e_ring
*ring
;
3303 /* disassociate q_vector from rings */
3304 i40e_for_each_ring(ring
, q_vector
->tx
)
3305 ring
->q_vector
= NULL
;
3307 i40e_for_each_ring(ring
, q_vector
->rx
)
3308 ring
->q_vector
= NULL
;
3310 /* only VSI w/ an associated netdev is set up w/ NAPI */
3312 netif_napi_del(&q_vector
->napi
);
3314 vsi
->q_vectors
[v_idx
] = NULL
;
3316 kfree_rcu(q_vector
, rcu
);
3320 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
3321 * @vsi: the VSI being un-configured
3323 * This frees the memory allocated to the q_vectors and
3324 * deletes references to the NAPI struct.
3326 static void i40e_vsi_free_q_vectors(struct i40e_vsi
*vsi
)
3330 for (v_idx
= 0; v_idx
< vsi
->num_q_vectors
; v_idx
++)
3331 i40e_free_q_vector(vsi
, v_idx
);
3335 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
3336 * @pf: board private structure
3338 static void i40e_reset_interrupt_capability(struct i40e_pf
*pf
)
3340 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
3341 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3342 pci_disable_msix(pf
->pdev
);
3343 kfree(pf
->msix_entries
);
3344 pf
->msix_entries
= NULL
;
3345 } else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
) {
3346 pci_disable_msi(pf
->pdev
);
3348 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
);
3352 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
3353 * @pf: board private structure
3355 * We go through and clear interrupt specific resources and reset the structure
3356 * to pre-load conditions
3358 static void i40e_clear_interrupt_scheme(struct i40e_pf
*pf
)
3362 i40e_put_lump(pf
->irq_pile
, 0, I40E_PILE_VALID_BIT
-1);
3363 for (i
= 0; i
< pf
->hw
.func_caps
.num_vsis
; i
++)
3365 i40e_vsi_free_q_vectors(pf
->vsi
[i
]);
3366 i40e_reset_interrupt_capability(pf
);
3370 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
3371 * @vsi: the VSI being configured
3373 static void i40e_napi_enable_all(struct i40e_vsi
*vsi
)
3380 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++)
3381 napi_enable(&vsi
->q_vectors
[q_idx
]->napi
);
3385 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
3386 * @vsi: the VSI being configured
3388 static void i40e_napi_disable_all(struct i40e_vsi
*vsi
)
3395 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++)
3396 napi_disable(&vsi
->q_vectors
[q_idx
]->napi
);
3400 * i40e_quiesce_vsi - Pause a given VSI
3401 * @vsi: the VSI being paused
3403 static void i40e_quiesce_vsi(struct i40e_vsi
*vsi
)
3405 if (test_bit(__I40E_DOWN
, &vsi
->state
))
3408 set_bit(__I40E_NEEDS_RESTART
, &vsi
->state
);
3409 if (vsi
->netdev
&& netif_running(vsi
->netdev
)) {
3410 vsi
->netdev
->netdev_ops
->ndo_stop(vsi
->netdev
);
3412 set_bit(__I40E_DOWN
, &vsi
->state
);
3418 * i40e_unquiesce_vsi - Resume a given VSI
3419 * @vsi: the VSI being resumed
3421 static void i40e_unquiesce_vsi(struct i40e_vsi
*vsi
)
3423 if (!test_bit(__I40E_NEEDS_RESTART
, &vsi
->state
))
3426 clear_bit(__I40E_NEEDS_RESTART
, &vsi
->state
);
3427 if (vsi
->netdev
&& netif_running(vsi
->netdev
))
3428 vsi
->netdev
->netdev_ops
->ndo_open(vsi
->netdev
);
3430 i40e_up(vsi
); /* this clears the DOWN bit */
3434 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
3437 static void i40e_pf_quiesce_all_vsi(struct i40e_pf
*pf
)
3441 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
; v
++) {
3443 i40e_quiesce_vsi(pf
->vsi
[v
]);
3448 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
3451 static void i40e_pf_unquiesce_all_vsi(struct i40e_pf
*pf
)
3455 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
; v
++) {
3457 i40e_unquiesce_vsi(pf
->vsi
[v
]);
3462 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
3463 * @dcbcfg: the corresponding DCBx configuration structure
3465 * Return the number of TCs from given DCBx configuration
3467 static u8
i40e_dcb_get_num_tc(struct i40e_dcbx_config
*dcbcfg
)
3472 /* Scan the ETS Config Priority Table to find
3473 * traffic class enabled for a given priority
3474 * and use the traffic class index to get the
3475 * number of traffic classes enabled
3477 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
3478 if (dcbcfg
->etscfg
.prioritytable
[i
] > num_tc
)
3479 num_tc
= dcbcfg
->etscfg
.prioritytable
[i
];
3482 /* Traffic class index starts from zero so
3483 * increment to return the actual count
3489 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
3490 * @dcbcfg: the corresponding DCBx configuration structure
3492 * Query the current DCB configuration and return the number of
3493 * traffic classes enabled from the given DCBX config
3495 static u8
i40e_dcb_get_enabled_tc(struct i40e_dcbx_config
*dcbcfg
)
3497 u8 num_tc
= i40e_dcb_get_num_tc(dcbcfg
);
3501 for (i
= 0; i
< num_tc
; i
++)
3502 enabled_tc
|= 1 << i
;
3508 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
3509 * @pf: PF being queried
3511 * Return number of traffic classes enabled for the given PF
3513 static u8
i40e_pf_get_num_tc(struct i40e_pf
*pf
)
3515 struct i40e_hw
*hw
= &pf
->hw
;
3518 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
3520 /* If DCB is not enabled then always in single TC */
3521 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
3524 /* MFP mode return count of enabled TCs for this PF */
3525 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
3526 enabled_tc
= pf
->hw
.func_caps
.enabled_tcmap
;
3527 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
3528 if (enabled_tc
& (1 << i
))
3534 /* SFP mode will be enabled for all TCs on port */
3535 return i40e_dcb_get_num_tc(dcbcfg
);
3539 * i40e_pf_get_default_tc - Get bitmap for first enabled TC
3540 * @pf: PF being queried
3542 * Return a bitmap for first enabled traffic class for this PF.
3544 static u8
i40e_pf_get_default_tc(struct i40e_pf
*pf
)
3546 u8 enabled_tc
= pf
->hw
.func_caps
.enabled_tcmap
;
3550 return 0x1; /* TC0 */
3552 /* Find the first enabled TC */
3553 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
3554 if (enabled_tc
& (1 << i
))
3562 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
3563 * @pf: PF being queried
3565 * Return a bitmap for enabled traffic classes for this PF.
3567 static u8
i40e_pf_get_tc_map(struct i40e_pf
*pf
)
3569 /* If DCB is not enabled for this PF then just return default TC */
3570 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
3571 return i40e_pf_get_default_tc(pf
);
3573 /* MFP mode will have enabled TCs set by FW */
3574 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
)
3575 return pf
->hw
.func_caps
.enabled_tcmap
;
3577 /* SFP mode we want PF to be enabled for all TCs */
3578 return i40e_dcb_get_enabled_tc(&pf
->hw
.local_dcbx_config
);
3582 * i40e_vsi_get_bw_info - Query VSI BW Information
3583 * @vsi: the VSI being queried
3585 * Returns 0 on success, negative value on failure
3587 static int i40e_vsi_get_bw_info(struct i40e_vsi
*vsi
)
3589 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config
= {0};
3590 struct i40e_aqc_query_vsi_bw_config_resp bw_config
= {0};
3591 struct i40e_pf
*pf
= vsi
->back
;
3592 struct i40e_hw
*hw
= &pf
->hw
;
3597 /* Get the VSI level BW configuration */
3598 aq_ret
= i40e_aq_query_vsi_bw_config(hw
, vsi
->seid
, &bw_config
, NULL
);
3600 dev_info(&pf
->pdev
->dev
,
3601 "couldn't get pf vsi bw config, err %d, aq_err %d\n",
3602 aq_ret
, pf
->hw
.aq
.asq_last_status
);
3606 /* Get the VSI level BW configuration per TC */
3607 aq_ret
= i40e_aq_query_vsi_ets_sla_config(hw
, vsi
->seid
, &bw_ets_config
,
3610 dev_info(&pf
->pdev
->dev
,
3611 "couldn't get pf vsi ets bw config, err %d, aq_err %d\n",
3612 aq_ret
, pf
->hw
.aq
.asq_last_status
);
3616 if (bw_config
.tc_valid_bits
!= bw_ets_config
.tc_valid_bits
) {
3617 dev_info(&pf
->pdev
->dev
,
3618 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
3619 bw_config
.tc_valid_bits
,
3620 bw_ets_config
.tc_valid_bits
);
3621 /* Still continuing */
3624 vsi
->bw_limit
= le16_to_cpu(bw_config
.port_bw_limit
);
3625 vsi
->bw_max_quanta
= bw_config
.max_bw
;
3626 tc_bw_max
= le16_to_cpu(bw_ets_config
.tc_bw_max
[0]) |
3627 (le16_to_cpu(bw_ets_config
.tc_bw_max
[1]) << 16);
3628 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
3629 vsi
->bw_ets_share_credits
[i
] = bw_ets_config
.share_credits
[i
];
3630 vsi
->bw_ets_limit_credits
[i
] =
3631 le16_to_cpu(bw_ets_config
.credits
[i
]);
3632 /* 3 bits out of 4 for each TC */
3633 vsi
->bw_ets_max_quanta
[i
] = (u8
)((tc_bw_max
>> (i
*4)) & 0x7);
3640 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
3641 * @vsi: the VSI being configured
3642 * @enabled_tc: TC bitmap
3643 * @bw_credits: BW shared credits per TC
3645 * Returns 0 on success, negative value on failure
3647 static int i40e_vsi_configure_bw_alloc(struct i40e_vsi
*vsi
, u8 enabled_tc
,
3650 struct i40e_aqc_configure_vsi_tc_bw_data bw_data
;
3654 bw_data
.tc_valid_bits
= enabled_tc
;
3655 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
3656 bw_data
.tc_bw_credits
[i
] = bw_share
[i
];
3658 aq_ret
= i40e_aq_config_vsi_tc_bw(&vsi
->back
->hw
, vsi
->seid
, &bw_data
,
3661 dev_info(&vsi
->back
->pdev
->dev
,
3662 "%s: AQ command Config VSI BW allocation per TC failed = %d\n",
3663 __func__
, vsi
->back
->hw
.aq
.asq_last_status
);
3667 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
3668 vsi
->info
.qs_handle
[i
] = bw_data
.qs_handles
[i
];
3674 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
3675 * @vsi: the VSI being configured
3676 * @enabled_tc: TC map to be enabled
3679 static void i40e_vsi_config_netdev_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
3681 struct net_device
*netdev
= vsi
->netdev
;
3682 struct i40e_pf
*pf
= vsi
->back
;
3683 struct i40e_hw
*hw
= &pf
->hw
;
3686 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
3692 netdev_reset_tc(netdev
);
3696 /* Set up actual enabled TCs on the VSI */
3697 if (netdev_set_num_tc(netdev
, vsi
->tc_config
.numtc
))
3700 /* set per TC queues for the VSI */
3701 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
3702 /* Only set TC queues for enabled tcs
3704 * e.g. For a VSI that has TC0 and TC3 enabled the
3705 * enabled_tc bitmap would be 0x00001001; the driver
3706 * will set the numtc for netdev as 2 that will be
3707 * referenced by the netdev layer as TC 0 and 1.
3709 if (vsi
->tc_config
.enabled_tc
& (1 << i
))
3710 netdev_set_tc_queue(netdev
,
3711 vsi
->tc_config
.tc_info
[i
].netdev_tc
,
3712 vsi
->tc_config
.tc_info
[i
].qcount
,
3713 vsi
->tc_config
.tc_info
[i
].qoffset
);
3716 /* Assign UP2TC map for the VSI */
3717 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
3718 /* Get the actual TC# for the UP */
3719 u8 ets_tc
= dcbcfg
->etscfg
.prioritytable
[i
];
3720 /* Get the mapped netdev TC# for the UP */
3721 netdev_tc
= vsi
->tc_config
.tc_info
[ets_tc
].netdev_tc
;
3722 netdev_set_prio_tc_map(netdev
, i
, netdev_tc
);
3727 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
3728 * @vsi: the VSI being configured
3729 * @ctxt: the ctxt buffer returned from AQ VSI update param command
3731 static void i40e_vsi_update_queue_map(struct i40e_vsi
*vsi
,
3732 struct i40e_vsi_context
*ctxt
)
3734 /* copy just the sections touched not the entire info
3735 * since not all sections are valid as returned by
3738 vsi
->info
.mapping_flags
= ctxt
->info
.mapping_flags
;
3739 memcpy(&vsi
->info
.queue_mapping
,
3740 &ctxt
->info
.queue_mapping
, sizeof(vsi
->info
.queue_mapping
));
3741 memcpy(&vsi
->info
.tc_mapping
, ctxt
->info
.tc_mapping
,
3742 sizeof(vsi
->info
.tc_mapping
));
3746 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
3747 * @vsi: VSI to be configured
3748 * @enabled_tc: TC bitmap
3750 * This configures a particular VSI for TCs that are mapped to the
3751 * given TC bitmap. It uses default bandwidth share for TCs across
3752 * VSIs to configure TC for a particular VSI.
3755 * It is expected that the VSI queues have been quisced before calling
3758 static int i40e_vsi_config_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
3760 u8 bw_share
[I40E_MAX_TRAFFIC_CLASS
] = {0};
3761 struct i40e_vsi_context ctxt
;
3765 /* Check if enabled_tc is same as existing or new TCs */
3766 if (vsi
->tc_config
.enabled_tc
== enabled_tc
)
3769 /* Enable ETS TCs with equal BW Share for now across all VSIs */
3770 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
3771 if (enabled_tc
& (1 << i
))
3775 ret
= i40e_vsi_configure_bw_alloc(vsi
, enabled_tc
, bw_share
);
3777 dev_info(&vsi
->back
->pdev
->dev
,
3778 "Failed configuring TC map %d for VSI %d\n",
3779 enabled_tc
, vsi
->seid
);
3783 /* Update Queue Pairs Mapping for currently enabled UPs */
3784 ctxt
.seid
= vsi
->seid
;
3785 ctxt
.pf_num
= vsi
->back
->hw
.pf_id
;
3787 ctxt
.uplink_seid
= vsi
->uplink_seid
;
3788 memcpy(&ctxt
.info
, &vsi
->info
, sizeof(vsi
->info
));
3789 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
3791 /* Update the VSI after updating the VSI queue-mapping information */
3792 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
3794 dev_info(&vsi
->back
->pdev
->dev
,
3795 "update vsi failed, aq_err=%d\n",
3796 vsi
->back
->hw
.aq
.asq_last_status
);
3799 /* update the local VSI info with updated queue map */
3800 i40e_vsi_update_queue_map(vsi
, &ctxt
);
3801 vsi
->info
.valid_sections
= 0;
3803 /* Update current VSI BW information */
3804 ret
= i40e_vsi_get_bw_info(vsi
);
3806 dev_info(&vsi
->back
->pdev
->dev
,
3807 "Failed updating vsi bw info, aq_err=%d\n",
3808 vsi
->back
->hw
.aq
.asq_last_status
);
3812 /* Update the netdev TC setup */
3813 i40e_vsi_config_netdev_tc(vsi
, enabled_tc
);
3819 * i40e_up_complete - Finish the last steps of bringing up a connection
3820 * @vsi: the VSI being configured
3822 static int i40e_up_complete(struct i40e_vsi
*vsi
)
3824 struct i40e_pf
*pf
= vsi
->back
;
3827 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
3828 i40e_vsi_configure_msix(vsi
);
3830 i40e_configure_msi_and_legacy(vsi
);
3833 err
= i40e_vsi_control_rings(vsi
, true);
3837 clear_bit(__I40E_DOWN
, &vsi
->state
);
3838 i40e_napi_enable_all(vsi
);
3839 i40e_vsi_enable_irq(vsi
);
3841 if ((pf
->hw
.phy
.link_info
.link_info
& I40E_AQ_LINK_UP
) &&
3843 netdev_info(vsi
->netdev
, "NIC Link is Up\n");
3844 netif_tx_start_all_queues(vsi
->netdev
);
3845 netif_carrier_on(vsi
->netdev
);
3846 } else if (vsi
->netdev
) {
3847 netdev_info(vsi
->netdev
, "NIC Link is Down\n");
3849 i40e_service_event_schedule(pf
);
3855 * i40e_vsi_reinit_locked - Reset the VSI
3856 * @vsi: the VSI being configured
3858 * Rebuild the ring structs after some configuration
3859 * has changed, e.g. MTU size.
3861 static void i40e_vsi_reinit_locked(struct i40e_vsi
*vsi
)
3863 struct i40e_pf
*pf
= vsi
->back
;
3865 WARN_ON(in_interrupt());
3866 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
3867 usleep_range(1000, 2000);
3870 /* Give a VF some time to respond to the reset. The
3871 * two second wait is based upon the watchdog cycle in
3874 if (vsi
->type
== I40E_VSI_SRIOV
)
3877 clear_bit(__I40E_CONFIG_BUSY
, &pf
->state
);
3881 * i40e_up - Bring the connection back up after being down
3882 * @vsi: the VSI being configured
3884 int i40e_up(struct i40e_vsi
*vsi
)
3888 err
= i40e_vsi_configure(vsi
);
3890 err
= i40e_up_complete(vsi
);
3896 * i40e_down - Shutdown the connection processing
3897 * @vsi: the VSI being stopped
3899 void i40e_down(struct i40e_vsi
*vsi
)
3903 /* It is assumed that the caller of this function
3904 * sets the vsi->state __I40E_DOWN bit.
3907 netif_carrier_off(vsi
->netdev
);
3908 netif_tx_disable(vsi
->netdev
);
3910 i40e_vsi_disable_irq(vsi
);
3911 i40e_vsi_control_rings(vsi
, false);
3912 i40e_napi_disable_all(vsi
);
3914 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
3915 i40e_clean_tx_ring(vsi
->tx_rings
[i
]);
3916 i40e_clean_rx_ring(vsi
->rx_rings
[i
]);
3921 * i40e_setup_tc - configure multiple traffic classes
3922 * @netdev: net device to configure
3923 * @tc: number of traffic classes to enable
3925 static int i40e_setup_tc(struct net_device
*netdev
, u8 tc
)
3927 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3928 struct i40e_vsi
*vsi
= np
->vsi
;
3929 struct i40e_pf
*pf
= vsi
->back
;
3934 /* Check if DCB enabled to continue */
3935 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
)) {
3936 netdev_info(netdev
, "DCB is not enabled for adapter\n");
3940 /* Check if MFP enabled */
3941 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
3942 netdev_info(netdev
, "Configuring TC not supported in MFP mode\n");
3946 /* Check whether tc count is within enabled limit */
3947 if (tc
> i40e_pf_get_num_tc(pf
)) {
3948 netdev_info(netdev
, "TC count greater than enabled on link for adapter\n");
3952 /* Generate TC map for number of tc requested */
3953 for (i
= 0; i
< tc
; i
++)
3954 enabled_tc
|= (1 << i
);
3956 /* Requesting same TC configuration as already enabled */
3957 if (enabled_tc
== vsi
->tc_config
.enabled_tc
)
3960 /* Quiesce VSI queues */
3961 i40e_quiesce_vsi(vsi
);
3963 /* Configure VSI for enabled TCs */
3964 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
3966 netdev_info(netdev
, "Failed configuring TC for VSI seid=%d\n",
3972 i40e_unquiesce_vsi(vsi
);
3979 * i40e_open - Called when a network interface is made active
3980 * @netdev: network interface device structure
3982 * The open entry point is called when a network interface is made
3983 * active by the system (IFF_UP). At this point all resources needed
3984 * for transmit and receive operations are allocated, the interrupt
3985 * handler is registered with the OS, the netdev watchdog subtask is
3986 * enabled, and the stack is notified that the interface is ready.
3988 * Returns 0 on success, negative value on failure
3990 static int i40e_open(struct net_device
*netdev
)
3992 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3993 struct i40e_vsi
*vsi
= np
->vsi
;
3994 struct i40e_pf
*pf
= vsi
->back
;
3995 char int_name
[IFNAMSIZ
];
3998 /* disallow open during test */
3999 if (test_bit(__I40E_TESTING
, &pf
->state
))
4002 netif_carrier_off(netdev
);
4004 /* allocate descriptors */
4005 err
= i40e_vsi_setup_tx_resources(vsi
);
4008 err
= i40e_vsi_setup_rx_resources(vsi
);
4012 err
= i40e_vsi_configure(vsi
);
4016 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s",
4017 dev_driver_string(&pf
->pdev
->dev
), netdev
->name
);
4018 err
= i40e_vsi_request_irq(vsi
, int_name
);
4022 /* Notify the stack of the actual queue counts. */
4023 err
= netif_set_real_num_tx_queues(netdev
, vsi
->num_queue_pairs
);
4025 goto err_set_queues
;
4027 err
= netif_set_real_num_rx_queues(netdev
, vsi
->num_queue_pairs
);
4029 goto err_set_queues
;
4031 err
= i40e_up_complete(vsi
);
4033 goto err_up_complete
;
4035 #ifdef CONFIG_I40E_VXLAN
4036 vxlan_get_rx_port(netdev
);
4044 i40e_vsi_free_irq(vsi
);
4046 i40e_vsi_free_rx_resources(vsi
);
4048 i40e_vsi_free_tx_resources(vsi
);
4049 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
4050 i40e_do_reset(pf
, (1 << __I40E_PF_RESET_REQUESTED
));
4056 * i40e_close - Disables a network interface
4057 * @netdev: network interface device structure
4059 * The close entry point is called when an interface is de-activated
4060 * by the OS. The hardware is still under the driver's control, but
4061 * this netdev interface is disabled.
4063 * Returns 0, this is not allowed to fail
4065 static int i40e_close(struct net_device
*netdev
)
4067 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
4068 struct i40e_vsi
*vsi
= np
->vsi
;
4070 if (test_and_set_bit(__I40E_DOWN
, &vsi
->state
))
4074 i40e_vsi_free_irq(vsi
);
4076 i40e_vsi_free_tx_resources(vsi
);
4077 i40e_vsi_free_rx_resources(vsi
);
4083 * i40e_do_reset - Start a PF or Core Reset sequence
4084 * @pf: board private structure
4085 * @reset_flags: which reset is requested
4087 * The essential difference in resets is that the PF Reset
4088 * doesn't clear the packet buffers, doesn't reset the PE
4089 * firmware, and doesn't bother the other PFs on the chip.
4091 void i40e_do_reset(struct i40e_pf
*pf
, u32 reset_flags
)
4095 WARN_ON(in_interrupt());
4097 /* do the biggest reset indicated */
4098 if (reset_flags
& (1 << __I40E_GLOBAL_RESET_REQUESTED
)) {
4100 /* Request a Global Reset
4102 * This will start the chip's countdown to the actual full
4103 * chip reset event, and a warning interrupt to be sent
4104 * to all PFs, including the requestor. Our handler
4105 * for the warning interrupt will deal with the shutdown
4106 * and recovery of the switch setup.
4108 dev_info(&pf
->pdev
->dev
, "GlobalR requested\n");
4109 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
4110 val
|= I40E_GLGEN_RTRIG_GLOBR_MASK
;
4111 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
4113 } else if (reset_flags
& (1 << __I40E_CORE_RESET_REQUESTED
)) {
4115 /* Request a Core Reset
4117 * Same as Global Reset, except does *not* include the MAC/PHY
4119 dev_info(&pf
->pdev
->dev
, "CoreR requested\n");
4120 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
4121 val
|= I40E_GLGEN_RTRIG_CORER_MASK
;
4122 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
4123 i40e_flush(&pf
->hw
);
4125 } else if (reset_flags
& (1 << __I40E_EMP_RESET_REQUESTED
)) {
4127 /* Request a Firmware Reset
4129 * Same as Global reset, plus restarting the
4130 * embedded firmware engine.
4132 /* enable EMP Reset */
4133 val
= rd32(&pf
->hw
, I40E_GLGEN_RSTENA_EMP
);
4134 val
|= I40E_GLGEN_RSTENA_EMP_EMP_RST_ENA_MASK
;
4135 wr32(&pf
->hw
, I40E_GLGEN_RSTENA_EMP
, val
);
4137 /* force the reset */
4138 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
4139 val
|= I40E_GLGEN_RTRIG_EMPFWR_MASK
;
4140 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
4141 i40e_flush(&pf
->hw
);
4143 } else if (reset_flags
& (1 << __I40E_PF_RESET_REQUESTED
)) {
4145 /* Request a PF Reset
4147 * Resets only the PF-specific registers
4149 * This goes directly to the tear-down and rebuild of
4150 * the switch, since we need to do all the recovery as
4151 * for the Core Reset.
4153 dev_info(&pf
->pdev
->dev
, "PFR requested\n");
4154 i40e_handle_reset_warning(pf
);
4156 } else if (reset_flags
& (1 << __I40E_REINIT_REQUESTED
)) {
4159 /* Find the VSI(s) that requested a re-init */
4160 dev_info(&pf
->pdev
->dev
,
4161 "VSI reinit requested\n");
4162 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
; v
++) {
4163 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
4165 test_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
)) {
4166 i40e_vsi_reinit_locked(pf
->vsi
[v
]);
4167 clear_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
);
4171 /* no further action needed, so return now */
4174 dev_info(&pf
->pdev
->dev
,
4175 "bad reset request 0x%08x\n", reset_flags
);
4181 * i40e_do_reset_safe - Protected reset path for userland calls.
4182 * @pf: board private structure
4183 * @reset_flags: which reset is requested
4186 void i40e_do_reset_safe(struct i40e_pf
*pf
, u32 reset_flags
)
4189 i40e_do_reset(pf
, reset_flags
);
4194 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
4195 * @pf: board private structure
4196 * @e: event info posted on ARQ
4198 * Handler for LAN Queue Overflow Event generated by the firmware for PF
4201 static void i40e_handle_lan_overflow_event(struct i40e_pf
*pf
,
4202 struct i40e_arq_event_info
*e
)
4204 struct i40e_aqc_lan_overflow
*data
=
4205 (struct i40e_aqc_lan_overflow
*)&e
->desc
.params
.raw
;
4206 u32 queue
= le32_to_cpu(data
->prtdcb_rupto
);
4207 u32 qtx_ctl
= le32_to_cpu(data
->otx_ctl
);
4208 struct i40e_hw
*hw
= &pf
->hw
;
4212 dev_info(&pf
->pdev
->dev
, "%s: Rx Queue Number = %d QTX_CTL=0x%08x\n",
4213 __func__
, queue
, qtx_ctl
);
4215 /* Queue belongs to VF, find the VF and issue VF reset */
4216 if (((qtx_ctl
& I40E_QTX_CTL_PFVF_Q_MASK
)
4217 >> I40E_QTX_CTL_PFVF_Q_SHIFT
) == I40E_QTX_CTL_VF_QUEUE
) {
4218 vf_id
= (u16
)((qtx_ctl
& I40E_QTX_CTL_VFVM_INDX_MASK
)
4219 >> I40E_QTX_CTL_VFVM_INDX_SHIFT
);
4220 vf_id
-= hw
->func_caps
.vf_base_id
;
4221 vf
= &pf
->vf
[vf_id
];
4222 i40e_vc_notify_vf_reset(vf
);
4223 /* Allow VF to process pending reset notification */
4225 i40e_reset_vf(vf
, false);
4230 * i40e_service_event_complete - Finish up the service event
4231 * @pf: board private structure
4233 static void i40e_service_event_complete(struct i40e_pf
*pf
)
4235 BUG_ON(!test_bit(__I40E_SERVICE_SCHED
, &pf
->state
));
4237 /* flush memory to make sure state is correct before next watchog */
4238 smp_mb__before_clear_bit();
4239 clear_bit(__I40E_SERVICE_SCHED
, &pf
->state
);
4243 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
4244 * @pf: board private structure
4246 static void i40e_fdir_reinit_subtask(struct i40e_pf
*pf
)
4248 if (!(pf
->flags
& I40E_FLAG_FDIR_REQUIRES_REINIT
))
4251 pf
->flags
&= ~I40E_FLAG_FDIR_REQUIRES_REINIT
;
4253 /* if interface is down do nothing */
4254 if (test_bit(__I40E_DOWN
, &pf
->state
))
4259 * i40e_vsi_link_event - notify VSI of a link event
4260 * @vsi: vsi to be notified
4261 * @link_up: link up or down
4263 static void i40e_vsi_link_event(struct i40e_vsi
*vsi
, bool link_up
)
4268 switch (vsi
->type
) {
4270 if (!vsi
->netdev
|| !vsi
->netdev_registered
)
4274 netif_carrier_on(vsi
->netdev
);
4275 netif_tx_wake_all_queues(vsi
->netdev
);
4277 netif_carrier_off(vsi
->netdev
);
4278 netif_tx_stop_all_queues(vsi
->netdev
);
4282 case I40E_VSI_SRIOV
:
4285 case I40E_VSI_VMDQ2
:
4287 case I40E_VSI_MIRROR
:
4289 /* there is no notification for other VSIs */
4295 * i40e_veb_link_event - notify elements on the veb of a link event
4296 * @veb: veb to be notified
4297 * @link_up: link up or down
4299 static void i40e_veb_link_event(struct i40e_veb
*veb
, bool link_up
)
4304 if (!veb
|| !veb
->pf
)
4308 /* depth first... */
4309 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
4310 if (pf
->veb
[i
] && (pf
->veb
[i
]->uplink_seid
== veb
->seid
))
4311 i40e_veb_link_event(pf
->veb
[i
], link_up
);
4313 /* ... now the local VSIs */
4314 for (i
= 0; i
< pf
->hw
.func_caps
.num_vsis
; i
++)
4315 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->uplink_seid
== veb
->seid
))
4316 i40e_vsi_link_event(pf
->vsi
[i
], link_up
);
4320 * i40e_link_event - Update netif_carrier status
4321 * @pf: board private structure
4323 static void i40e_link_event(struct i40e_pf
*pf
)
4325 bool new_link
, old_link
;
4327 new_link
= (pf
->hw
.phy
.link_info
.link_info
& I40E_AQ_LINK_UP
);
4328 old_link
= (pf
->hw
.phy
.link_info_old
.link_info
& I40E_AQ_LINK_UP
);
4330 if (new_link
== old_link
)
4333 if (!test_bit(__I40E_DOWN
, &pf
->vsi
[pf
->lan_vsi
]->state
))
4334 netdev_info(pf
->vsi
[pf
->lan_vsi
]->netdev
,
4335 "NIC Link is %s\n", (new_link
? "Up" : "Down"));
4337 /* Notify the base of the switch tree connected to
4338 * the link. Floating VEBs are not notified.
4340 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
4341 i40e_veb_link_event(pf
->veb
[pf
->lan_veb
], new_link
);
4343 i40e_vsi_link_event(pf
->vsi
[pf
->lan_vsi
], new_link
);
4346 i40e_vc_notify_link_state(pf
);
4348 if (pf
->flags
& I40E_FLAG_PTP
)
4349 i40e_ptp_set_increment(pf
);
4353 * i40e_check_hang_subtask - Check for hung queues and dropped interrupts
4354 * @pf: board private structure
4356 * Set the per-queue flags to request a check for stuck queues in the irq
4357 * clean functions, then force interrupts to be sure the irq clean is called.
4359 static void i40e_check_hang_subtask(struct i40e_pf
*pf
)
4363 /* If we're down or resetting, just bail */
4364 if (test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
4367 /* for each VSI/netdev
4369 * set the check flag
4371 * force an interrupt
4373 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
; v
++) {
4374 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
4378 test_bit(__I40E_DOWN
, &vsi
->state
) ||
4379 (vsi
->netdev
&& !netif_carrier_ok(vsi
->netdev
)))
4382 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
4383 set_check_for_tx_hang(vsi
->tx_rings
[i
]);
4384 if (test_bit(__I40E_HANG_CHECK_ARMED
,
4385 &vsi
->tx_rings
[i
]->state
))
4390 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
)) {
4391 wr32(&vsi
->back
->hw
, I40E_PFINT_DYN_CTL0
,
4392 (I40E_PFINT_DYN_CTL0_INTENA_MASK
|
4393 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK
));
4395 u16 vec
= vsi
->base_vector
- 1;
4396 u32 val
= (I40E_PFINT_DYN_CTLN_INTENA_MASK
|
4397 I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK
);
4398 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vec
++)
4399 wr32(&vsi
->back
->hw
,
4400 I40E_PFINT_DYN_CTLN(vec
), val
);
4402 i40e_flush(&vsi
->back
->hw
);
4408 * i40e_watchdog_subtask - Check and bring link up
4409 * @pf: board private structure
4411 static void i40e_watchdog_subtask(struct i40e_pf
*pf
)
4415 /* if interface is down do nothing */
4416 if (test_bit(__I40E_DOWN
, &pf
->state
) ||
4417 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
4420 /* Update the stats for active netdevs so the network stack
4421 * can look at updated numbers whenever it cares to
4423 for (i
= 0; i
< pf
->hw
.func_caps
.num_vsis
; i
++)
4424 if (pf
->vsi
[i
] && pf
->vsi
[i
]->netdev
)
4425 i40e_update_stats(pf
->vsi
[i
]);
4427 /* Update the stats for the active switching components */
4428 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
4430 i40e_update_veb_stats(pf
->veb
[i
]);
4432 i40e_ptp_rx_hang(pf
->vsi
[pf
->lan_vsi
]);
4436 * i40e_reset_subtask - Set up for resetting the device and driver
4437 * @pf: board private structure
4439 static void i40e_reset_subtask(struct i40e_pf
*pf
)
4441 u32 reset_flags
= 0;
4444 if (test_bit(__I40E_REINIT_REQUESTED
, &pf
->state
)) {
4445 reset_flags
|= (1 << __I40E_REINIT_REQUESTED
);
4446 clear_bit(__I40E_REINIT_REQUESTED
, &pf
->state
);
4448 if (test_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
)) {
4449 reset_flags
|= (1 << __I40E_PF_RESET_REQUESTED
);
4450 clear_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
4452 if (test_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
)) {
4453 reset_flags
|= (1 << __I40E_CORE_RESET_REQUESTED
);
4454 clear_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
);
4456 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
)) {
4457 reset_flags
|= (1 << __I40E_GLOBAL_RESET_REQUESTED
);
4458 clear_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
);
4461 /* If there's a recovery already waiting, it takes
4462 * precedence before starting a new reset sequence.
4464 if (test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
)) {
4465 i40e_handle_reset_warning(pf
);
4469 /* If we're already down or resetting, just bail */
4471 !test_bit(__I40E_DOWN
, &pf
->state
) &&
4472 !test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
4473 i40e_do_reset(pf
, reset_flags
);
4480 * i40e_handle_link_event - Handle link event
4481 * @pf: board private structure
4482 * @e: event info posted on ARQ
4484 static void i40e_handle_link_event(struct i40e_pf
*pf
,
4485 struct i40e_arq_event_info
*e
)
4487 struct i40e_hw
*hw
= &pf
->hw
;
4488 struct i40e_aqc_get_link_status
*status
=
4489 (struct i40e_aqc_get_link_status
*)&e
->desc
.params
.raw
;
4490 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
4492 /* save off old link status information */
4493 memcpy(&pf
->hw
.phy
.link_info_old
, hw_link_info
,
4494 sizeof(pf
->hw
.phy
.link_info_old
));
4496 /* update link status */
4497 hw_link_info
->phy_type
= (enum i40e_aq_phy_type
)status
->phy_type
;
4498 hw_link_info
->link_speed
= (enum i40e_aq_link_speed
)status
->link_speed
;
4499 hw_link_info
->link_info
= status
->link_info
;
4500 hw_link_info
->an_info
= status
->an_info
;
4501 hw_link_info
->ext_info
= status
->ext_info
;
4502 hw_link_info
->lse_enable
=
4503 le16_to_cpu(status
->command_flags
) &
4506 /* process the event */
4507 i40e_link_event(pf
);
4509 /* Do a new status request to re-enable LSE reporting
4510 * and load new status information into the hw struct,
4511 * then see if the status changed while processing the
4514 i40e_aq_get_link_info(&pf
->hw
, true, NULL
, NULL
);
4515 i40e_link_event(pf
);
4519 * i40e_clean_adminq_subtask - Clean the AdminQ rings
4520 * @pf: board private structure
4522 static void i40e_clean_adminq_subtask(struct i40e_pf
*pf
)
4524 struct i40e_arq_event_info event
;
4525 struct i40e_hw
*hw
= &pf
->hw
;
4531 if (!test_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
))
4534 event
.msg_size
= I40E_MAX_AQ_BUF_SIZE
;
4535 event
.msg_buf
= kzalloc(event
.msg_size
, GFP_KERNEL
);
4540 event
.msg_size
= I40E_MAX_AQ_BUF_SIZE
; /* reinit each time */
4541 ret
= i40e_clean_arq_element(hw
, &event
, &pending
);
4542 if (ret
== I40E_ERR_ADMIN_QUEUE_NO_WORK
) {
4543 dev_info(&pf
->pdev
->dev
, "No ARQ event found\n");
4546 dev_info(&pf
->pdev
->dev
, "ARQ event error %d\n", ret
);
4550 opcode
= le16_to_cpu(event
.desc
.opcode
);
4553 case i40e_aqc_opc_get_link_status
:
4554 i40e_handle_link_event(pf
, &event
);
4556 case i40e_aqc_opc_send_msg_to_pf
:
4557 ret
= i40e_vc_process_vf_msg(pf
,
4558 le16_to_cpu(event
.desc
.retval
),
4559 le32_to_cpu(event
.desc
.cookie_high
),
4560 le32_to_cpu(event
.desc
.cookie_low
),
4564 case i40e_aqc_opc_lldp_update_mib
:
4565 dev_info(&pf
->pdev
->dev
, "ARQ: Update LLDP MIB event received\n");
4567 case i40e_aqc_opc_event_lan_overflow
:
4568 dev_info(&pf
->pdev
->dev
, "ARQ LAN queue overflow event received\n");
4569 i40e_handle_lan_overflow_event(pf
, &event
);
4571 case i40e_aqc_opc_send_msg_to_peer
:
4572 dev_info(&pf
->pdev
->dev
, "ARQ: Msg from other pf\n");
4575 dev_info(&pf
->pdev
->dev
,
4576 "ARQ Error: Unknown event 0x%04x received\n",
4580 } while (pending
&& (i
++ < pf
->adminq_work_limit
));
4582 clear_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
);
4583 /* re-enable Admin queue interrupt cause */
4584 val
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
4585 val
|= I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
4586 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
4589 kfree(event
.msg_buf
);
4593 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
4594 * @veb: pointer to the VEB instance
4596 * This is a recursive function that first builds the attached VSIs then
4597 * recurses in to build the next layer of VEB. We track the connections
4598 * through our own index numbers because the seid's from the HW could
4599 * change across the reset.
4601 static int i40e_reconstitute_veb(struct i40e_veb
*veb
)
4603 struct i40e_vsi
*ctl_vsi
= NULL
;
4604 struct i40e_pf
*pf
= veb
->pf
;
4608 /* build VSI that owns this VEB, temporarily attached to base VEB */
4609 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
&& !ctl_vsi
; v
++) {
4611 pf
->vsi
[v
]->veb_idx
== veb
->idx
&&
4612 pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
4613 ctl_vsi
= pf
->vsi
[v
];
4618 dev_info(&pf
->pdev
->dev
,
4619 "missing owner VSI for veb_idx %d\n", veb
->idx
);
4621 goto end_reconstitute
;
4623 if (ctl_vsi
!= pf
->vsi
[pf
->lan_vsi
])
4624 ctl_vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
4625 ret
= i40e_add_vsi(ctl_vsi
);
4627 dev_info(&pf
->pdev
->dev
,
4628 "rebuild of owner VSI failed: %d\n", ret
);
4629 goto end_reconstitute
;
4631 i40e_vsi_reset_stats(ctl_vsi
);
4633 /* create the VEB in the switch and move the VSI onto the VEB */
4634 ret
= i40e_add_veb(veb
, ctl_vsi
);
4636 goto end_reconstitute
;
4638 /* create the remaining VSIs attached to this VEB */
4639 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
; v
++) {
4640 if (!pf
->vsi
[v
] || pf
->vsi
[v
] == ctl_vsi
)
4643 if (pf
->vsi
[v
]->veb_idx
== veb
->idx
) {
4644 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
4645 vsi
->uplink_seid
= veb
->seid
;
4646 ret
= i40e_add_vsi(vsi
);
4648 dev_info(&pf
->pdev
->dev
,
4649 "rebuild of vsi_idx %d failed: %d\n",
4651 goto end_reconstitute
;
4653 i40e_vsi_reset_stats(vsi
);
4657 /* create any VEBs attached to this VEB - RECURSION */
4658 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
4659 if (pf
->veb
[veb_idx
] && pf
->veb
[veb_idx
]->veb_idx
== veb
->idx
) {
4660 pf
->veb
[veb_idx
]->uplink_seid
= veb
->seid
;
4661 ret
= i40e_reconstitute_veb(pf
->veb
[veb_idx
]);
4672 * i40e_get_capabilities - get info about the HW
4673 * @pf: the PF struct
4675 static int i40e_get_capabilities(struct i40e_pf
*pf
)
4677 struct i40e_aqc_list_capabilities_element_resp
*cap_buf
;
4682 buf_len
= 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp
);
4684 cap_buf
= kzalloc(buf_len
, GFP_KERNEL
);
4688 /* this loads the data into the hw struct for us */
4689 err
= i40e_aq_discover_capabilities(&pf
->hw
, cap_buf
, buf_len
,
4691 i40e_aqc_opc_list_func_capabilities
,
4693 /* data loaded, buffer no longer needed */
4696 if (pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_ENOMEM
) {
4697 /* retry with a larger buffer */
4698 buf_len
= data_size
;
4699 } else if (pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_OK
) {
4700 dev_info(&pf
->pdev
->dev
,
4701 "capability discovery failed: aq=%d\n",
4702 pf
->hw
.aq
.asq_last_status
);
4707 if (pf
->hw
.revision_id
== 0 && (pf
->flags
& I40E_FLAG_MFP_ENABLED
)) {
4708 pf
->hw
.func_caps
.num_msix_vectors
+= 1;
4709 pf
->hw
.func_caps
.num_tx_qp
=
4710 min_t(int, pf
->hw
.func_caps
.num_tx_qp
,
4714 if (pf
->hw
.debug_mask
& I40E_DEBUG_USER
)
4715 dev_info(&pf
->pdev
->dev
,
4716 "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",
4717 pf
->hw
.pf_id
, pf
->hw
.func_caps
.num_vfs
,
4718 pf
->hw
.func_caps
.num_msix_vectors
,
4719 pf
->hw
.func_caps
.num_msix_vectors_vf
,
4720 pf
->hw
.func_caps
.fd_filters_guaranteed
,
4721 pf
->hw
.func_caps
.fd_filters_best_effort
,
4722 pf
->hw
.func_caps
.num_tx_qp
,
4723 pf
->hw
.func_caps
.num_vsis
);
4725 #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
4726 + pf->hw.func_caps.num_vfs)
4727 if (pf
->hw
.revision_id
== 0 && (DEF_NUM_VSI
> pf
->hw
.func_caps
.num_vsis
)) {
4728 dev_info(&pf
->pdev
->dev
,
4729 "got num_vsis %d, setting num_vsis to %d\n",
4730 pf
->hw
.func_caps
.num_vsis
, DEF_NUM_VSI
);
4731 pf
->hw
.func_caps
.num_vsis
= DEF_NUM_VSI
;
4738 * i40e_fdir_setup - initialize the Flow Director resources
4739 * @pf: board private structure
4741 static void i40e_fdir_setup(struct i40e_pf
*pf
)
4743 struct i40e_vsi
*vsi
;
4744 bool new_vsi
= false;
4747 if (!(pf
->flags
& (I40E_FLAG_FDIR_ENABLED
|
4748 I40E_FLAG_FDIR_ATR_ENABLED
)))
4751 pf
->atr_sample_rate
= I40E_DEFAULT_ATR_SAMPLE_RATE
;
4753 /* find existing or make new FDIR VSI */
4755 for (i
= 0; i
< pf
->hw
.func_caps
.num_vsis
; i
++)
4756 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
)
4759 vsi
= i40e_vsi_setup(pf
, I40E_VSI_FDIR
, pf
->mac_seid
, 0);
4761 dev_info(&pf
->pdev
->dev
, "Couldn't create FDir VSI\n");
4762 pf
->flags
&= ~I40E_FLAG_FDIR_ENABLED
;
4767 WARN_ON(vsi
->base_queue
!= I40E_FDIR_RING
);
4768 i40e_vsi_setup_irqhandler(vsi
, i40e_fdir_clean_rings
);
4770 err
= i40e_vsi_setup_tx_resources(vsi
);
4772 err
= i40e_vsi_setup_rx_resources(vsi
);
4774 err
= i40e_vsi_configure(vsi
);
4775 if (!err
&& new_vsi
) {
4776 char int_name
[IFNAMSIZ
+ 9];
4777 snprintf(int_name
, sizeof(int_name
) - 1, "%s-fdir",
4778 dev_driver_string(&pf
->pdev
->dev
));
4779 err
= i40e_vsi_request_irq(vsi
, int_name
);
4782 err
= i40e_up_complete(vsi
);
4784 clear_bit(__I40E_NEEDS_RESTART
, &vsi
->state
);
4788 * i40e_fdir_teardown - release the Flow Director resources
4789 * @pf: board private structure
4791 static void i40e_fdir_teardown(struct i40e_pf
*pf
)
4795 for (i
= 0; i
< pf
->hw
.func_caps
.num_vsis
; i
++) {
4796 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
4797 i40e_vsi_release(pf
->vsi
[i
]);
4804 * i40e_prep_for_reset - prep for the core to reset
4805 * @pf: board private structure
4807 * Close up the VFs and other things in prep for pf Reset.
4809 static int i40e_prep_for_reset(struct i40e_pf
*pf
)
4811 struct i40e_hw
*hw
= &pf
->hw
;
4815 clear_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
);
4816 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
))
4819 dev_info(&pf
->pdev
->dev
, "Tearing down internal switch for reset\n");
4821 if (i40e_check_asq_alive(hw
))
4822 i40e_vc_notify_reset(pf
);
4824 /* quiesce the VSIs and their queues that are not already DOWN */
4825 i40e_pf_quiesce_all_vsi(pf
);
4827 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
; v
++) {
4829 pf
->vsi
[v
]->seid
= 0;
4832 i40e_shutdown_adminq(&pf
->hw
);
4834 /* call shutdown HMC */
4835 ret
= i40e_shutdown_lan_hmc(hw
);
4837 dev_info(&pf
->pdev
->dev
, "shutdown_lan_hmc failed: %d\n", ret
);
4838 clear_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
);
4844 * i40e_reset_and_rebuild - reset and rebuild using a saved config
4845 * @pf: board private structure
4846 * @reinit: if the Main VSI needs to re-initialized.
4848 static void i40e_reset_and_rebuild(struct i40e_pf
*pf
, bool reinit
)
4850 struct i40e_driver_version dv
;
4851 struct i40e_hw
*hw
= &pf
->hw
;
4855 /* Now we wait for GRST to settle out.
4856 * We don't have to delete the VEBs or VSIs from the hw switch
4857 * because the reset will make them disappear.
4859 ret
= i40e_pf_reset(hw
);
4861 dev_info(&pf
->pdev
->dev
, "PF reset failed, %d\n", ret
);
4864 if (test_bit(__I40E_DOWN
, &pf
->state
))
4865 goto end_core_reset
;
4866 dev_info(&pf
->pdev
->dev
, "Rebuilding internal switch\n");
4868 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
4869 ret
= i40e_init_adminq(&pf
->hw
);
4871 dev_info(&pf
->pdev
->dev
, "Rebuild AdminQ failed, %d\n", ret
);
4872 goto end_core_reset
;
4875 ret
= i40e_get_capabilities(pf
);
4877 dev_info(&pf
->pdev
->dev
, "i40e_get_capabilities failed, %d\n",
4879 goto end_core_reset
;
4882 ret
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
4883 hw
->func_caps
.num_rx_qp
,
4884 pf
->fcoe_hmc_cntx_num
, pf
->fcoe_hmc_filt_num
);
4886 dev_info(&pf
->pdev
->dev
, "init_lan_hmc failed: %d\n", ret
);
4887 goto end_core_reset
;
4889 ret
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
4891 dev_info(&pf
->pdev
->dev
, "configure_lan_hmc failed: %d\n", ret
);
4892 goto end_core_reset
;
4895 /* do basic switch setup */
4896 ret
= i40e_setup_pf_switch(pf
, reinit
);
4898 goto end_core_reset
;
4900 /* Rebuild the VSIs and VEBs that existed before reset.
4901 * They are still in our local switch element arrays, so only
4902 * need to rebuild the switch model in the HW.
4904 * If there were VEBs but the reconstitution failed, we'll try
4905 * try to recover minimal use by getting the basic PF VSI working.
4907 if (pf
->vsi
[pf
->lan_vsi
]->uplink_seid
!= pf
->mac_seid
) {
4908 dev_info(&pf
->pdev
->dev
, "attempting to rebuild switch\n");
4909 /* find the one VEB connected to the MAC, and find orphans */
4910 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
4914 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
||
4915 pf
->veb
[v
]->uplink_seid
== 0) {
4916 ret
= i40e_reconstitute_veb(pf
->veb
[v
]);
4921 /* If Main VEB failed, we're in deep doodoo,
4922 * so give up rebuilding the switch and set up
4923 * for minimal rebuild of PF VSI.
4924 * If orphan failed, we'll report the error
4925 * but try to keep going.
4927 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
) {
4928 dev_info(&pf
->pdev
->dev
,
4929 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
4931 pf
->vsi
[pf
->lan_vsi
]->uplink_seid
4934 } else if (pf
->veb
[v
]->uplink_seid
== 0) {
4935 dev_info(&pf
->pdev
->dev
,
4936 "rebuild of orphan VEB failed: %d\n",
4943 if (pf
->vsi
[pf
->lan_vsi
]->uplink_seid
== pf
->mac_seid
) {
4944 dev_info(&pf
->pdev
->dev
, "attempting to rebuild PF VSI\n");
4945 /* no VEB, so rebuild only the Main VSI */
4946 ret
= i40e_add_vsi(pf
->vsi
[pf
->lan_vsi
]);
4948 dev_info(&pf
->pdev
->dev
,
4949 "rebuild of Main VSI failed: %d\n", ret
);
4950 goto end_core_reset
;
4954 /* reinit the misc interrupt */
4955 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
4956 ret
= i40e_setup_misc_vector(pf
);
4958 /* restart the VSIs that were rebuilt and running before the reset */
4959 i40e_pf_unquiesce_all_vsi(pf
);
4961 /* tell the firmware that we're starting */
4962 dv
.major_version
= DRV_VERSION_MAJOR
;
4963 dv
.minor_version
= DRV_VERSION_MINOR
;
4964 dv
.build_version
= DRV_VERSION_BUILD
;
4965 dv
.subbuild_version
= 0;
4966 i40e_aq_send_driver_version(&pf
->hw
, &dv
, NULL
);
4968 dev_info(&pf
->pdev
->dev
, "PF reset done\n");
4971 clear_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
);
4975 * i40e_handle_reset_warning - prep for the pf to reset, reset and rebuild
4976 * @pf: board private structure
4978 * Close up the VFs and other things in prep for a Core Reset,
4979 * then get ready to rebuild the world.
4981 static void i40e_handle_reset_warning(struct i40e_pf
*pf
)
4985 ret
= i40e_prep_for_reset(pf
);
4987 i40e_reset_and_rebuild(pf
, false);
4991 * i40e_handle_mdd_event
4992 * @pf: pointer to the pf structure
4994 * Called from the MDD irq handler to identify possibly malicious vfs
4996 static void i40e_handle_mdd_event(struct i40e_pf
*pf
)
4998 struct i40e_hw
*hw
= &pf
->hw
;
4999 bool mdd_detected
= false;
5004 if (!test_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
))
5007 /* find what triggered the MDD event */
5008 reg
= rd32(hw
, I40E_GL_MDET_TX
);
5009 if (reg
& I40E_GL_MDET_TX_VALID_MASK
) {
5010 u8 func
= (reg
& I40E_GL_MDET_TX_FUNCTION_MASK
)
5011 >> I40E_GL_MDET_TX_FUNCTION_SHIFT
;
5012 u8 event
= (reg
& I40E_GL_MDET_TX_EVENT_SHIFT
)
5013 >> I40E_GL_MDET_TX_EVENT_SHIFT
;
5014 u8 queue
= (reg
& I40E_GL_MDET_TX_QUEUE_MASK
)
5015 >> I40E_GL_MDET_TX_QUEUE_SHIFT
;
5016 dev_info(&pf
->pdev
->dev
,
5017 "Malicious Driver Detection TX event 0x%02x on q %d of function 0x%02x\n",
5018 event
, queue
, func
);
5019 wr32(hw
, I40E_GL_MDET_TX
, 0xffffffff);
5020 mdd_detected
= true;
5022 reg
= rd32(hw
, I40E_GL_MDET_RX
);
5023 if (reg
& I40E_GL_MDET_RX_VALID_MASK
) {
5024 u8 func
= (reg
& I40E_GL_MDET_RX_FUNCTION_MASK
)
5025 >> I40E_GL_MDET_RX_FUNCTION_SHIFT
;
5026 u8 event
= (reg
& I40E_GL_MDET_RX_EVENT_SHIFT
)
5027 >> I40E_GL_MDET_RX_EVENT_SHIFT
;
5028 u8 queue
= (reg
& I40E_GL_MDET_RX_QUEUE_MASK
)
5029 >> I40E_GL_MDET_RX_QUEUE_SHIFT
;
5030 dev_info(&pf
->pdev
->dev
,
5031 "Malicious Driver Detection RX event 0x%02x on q %d of function 0x%02x\n",
5032 event
, queue
, func
);
5033 wr32(hw
, I40E_GL_MDET_RX
, 0xffffffff);
5034 mdd_detected
= true;
5037 /* see if one of the VFs needs its hand slapped */
5038 for (i
= 0; i
< pf
->num_alloc_vfs
&& mdd_detected
; i
++) {
5040 reg
= rd32(hw
, I40E_VP_MDET_TX(i
));
5041 if (reg
& I40E_VP_MDET_TX_VALID_MASK
) {
5042 wr32(hw
, I40E_VP_MDET_TX(i
), 0xFFFF);
5043 vf
->num_mdd_events
++;
5044 dev_info(&pf
->pdev
->dev
, "MDD TX event on VF %d\n", i
);
5047 reg
= rd32(hw
, I40E_VP_MDET_RX(i
));
5048 if (reg
& I40E_VP_MDET_RX_VALID_MASK
) {
5049 wr32(hw
, I40E_VP_MDET_RX(i
), 0xFFFF);
5050 vf
->num_mdd_events
++;
5051 dev_info(&pf
->pdev
->dev
, "MDD RX event on VF %d\n", i
);
5054 if (vf
->num_mdd_events
> I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED
) {
5055 dev_info(&pf
->pdev
->dev
,
5056 "Too many MDD events on VF %d, disabled\n", i
);
5057 dev_info(&pf
->pdev
->dev
,
5058 "Use PF Control I/F to re-enable the VF\n");
5059 set_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
);
5063 /* re-enable mdd interrupt cause */
5064 clear_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
);
5065 reg
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
5066 reg
|= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
5067 wr32(hw
, I40E_PFINT_ICR0_ENA
, reg
);
5071 #ifdef CONFIG_I40E_VXLAN
5073 * i40e_sync_vxlan_filters_subtask - Sync the VSI filter list with HW
5074 * @pf: board private structure
5076 static void i40e_sync_vxlan_filters_subtask(struct i40e_pf
*pf
)
5078 const int vxlan_hdr_qwords
= 4;
5079 struct i40e_hw
*hw
= &pf
->hw
;
5085 if (!(pf
->flags
& I40E_FLAG_VXLAN_FILTER_SYNC
))
5088 pf
->flags
&= ~I40E_FLAG_VXLAN_FILTER_SYNC
;
5090 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
5091 if (pf
->pending_vxlan_bitmap
& (1 << i
)) {
5092 pf
->pending_vxlan_bitmap
&= ~(1 << i
);
5093 port
= pf
->vxlan_ports
[i
];
5095 i40e_aq_add_udp_tunnel(hw
, ntohs(port
),
5097 I40E_AQC_TUNNEL_TYPE_VXLAN
,
5098 &filter_index
, NULL
)
5099 : i40e_aq_del_udp_tunnel(hw
, i
, NULL
);
5102 dev_info(&pf
->pdev
->dev
, "Failed to execute AQ command for %s port %d with index %d\n",
5103 port
? "adding" : "deleting",
5104 ntohs(port
), port
? i
: i
);
5106 pf
->vxlan_ports
[i
] = 0;
5108 dev_info(&pf
->pdev
->dev
, "%s port %d with AQ command with index %d\n",
5109 port
? "Added" : "Deleted",
5110 ntohs(port
), port
? i
: filter_index
);
5118 * i40e_service_task - Run the driver's async subtasks
5119 * @work: pointer to work_struct containing our data
5121 static void i40e_service_task(struct work_struct
*work
)
5123 struct i40e_pf
*pf
= container_of(work
,
5126 unsigned long start_time
= jiffies
;
5128 i40e_reset_subtask(pf
);
5129 i40e_handle_mdd_event(pf
);
5130 i40e_vc_process_vflr_event(pf
);
5131 i40e_watchdog_subtask(pf
);
5132 i40e_fdir_reinit_subtask(pf
);
5133 i40e_check_hang_subtask(pf
);
5134 i40e_sync_filters_subtask(pf
);
5135 #ifdef CONFIG_I40E_VXLAN
5136 i40e_sync_vxlan_filters_subtask(pf
);
5138 i40e_clean_adminq_subtask(pf
);
5140 i40e_service_event_complete(pf
);
5142 /* If the tasks have taken longer than one timer cycle or there
5143 * is more work to be done, reschedule the service task now
5144 * rather than wait for the timer to tick again.
5146 if (time_after(jiffies
, (start_time
+ pf
->service_timer_period
)) ||
5147 test_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
) ||
5148 test_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
) ||
5149 test_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
))
5150 i40e_service_event_schedule(pf
);
5154 * i40e_service_timer - timer callback
5155 * @data: pointer to PF struct
5157 static void i40e_service_timer(unsigned long data
)
5159 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
5161 mod_timer(&pf
->service_timer
,
5162 round_jiffies(jiffies
+ pf
->service_timer_period
));
5163 i40e_service_event_schedule(pf
);
5167 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
5168 * @vsi: the VSI being configured
5170 static int i40e_set_num_rings_in_vsi(struct i40e_vsi
*vsi
)
5172 struct i40e_pf
*pf
= vsi
->back
;
5174 switch (vsi
->type
) {
5176 vsi
->alloc_queue_pairs
= pf
->num_lan_qps
;
5177 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
5178 I40E_REQ_DESCRIPTOR_MULTIPLE
);
5179 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
5180 vsi
->num_q_vectors
= pf
->num_lan_msix
;
5182 vsi
->num_q_vectors
= 1;
5187 vsi
->alloc_queue_pairs
= 1;
5188 vsi
->num_desc
= ALIGN(I40E_FDIR_RING_COUNT
,
5189 I40E_REQ_DESCRIPTOR_MULTIPLE
);
5190 vsi
->num_q_vectors
= 1;
5193 case I40E_VSI_VMDQ2
:
5194 vsi
->alloc_queue_pairs
= pf
->num_vmdq_qps
;
5195 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
5196 I40E_REQ_DESCRIPTOR_MULTIPLE
);
5197 vsi
->num_q_vectors
= pf
->num_vmdq_msix
;
5200 case I40E_VSI_SRIOV
:
5201 vsi
->alloc_queue_pairs
= pf
->num_vf_qps
;
5202 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
5203 I40E_REQ_DESCRIPTOR_MULTIPLE
);
5215 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
5216 * @type: VSI pointer
5217 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
5219 * On error: returns error code (negative)
5220 * On success: returns 0
5222 static int i40e_vsi_alloc_arrays(struct i40e_vsi
*vsi
, bool alloc_qvectors
)
5227 /* allocate memory for both Tx and Rx ring pointers */
5228 size
= sizeof(struct i40e_ring
*) * vsi
->alloc_queue_pairs
* 2;
5229 vsi
->tx_rings
= kzalloc(size
, GFP_KERNEL
);
5232 vsi
->rx_rings
= &vsi
->tx_rings
[vsi
->alloc_queue_pairs
];
5234 if (alloc_qvectors
) {
5235 /* allocate memory for q_vector pointers */
5236 size
= sizeof(struct i40e_q_vectors
*) * vsi
->num_q_vectors
;
5237 vsi
->q_vectors
= kzalloc(size
, GFP_KERNEL
);
5238 if (!vsi
->q_vectors
) {
5246 kfree(vsi
->tx_rings
);
5251 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
5252 * @pf: board private structure
5253 * @type: type of VSI
5255 * On error: returns error code (negative)
5256 * On success: returns vsi index in PF (positive)
5258 static int i40e_vsi_mem_alloc(struct i40e_pf
*pf
, enum i40e_vsi_type type
)
5261 struct i40e_vsi
*vsi
;
5265 /* Need to protect the allocation of the VSIs at the PF level */
5266 mutex_lock(&pf
->switch_mutex
);
5268 /* VSI list may be fragmented if VSI creation/destruction has
5269 * been happening. We can afford to do a quick scan to look
5270 * for any free VSIs in the list.
5272 * find next empty vsi slot, looping back around if necessary
5275 while (i
< pf
->hw
.func_caps
.num_vsis
&& pf
->vsi
[i
])
5277 if (i
>= pf
->hw
.func_caps
.num_vsis
) {
5279 while (i
< pf
->next_vsi
&& pf
->vsi
[i
])
5283 if (i
< pf
->hw
.func_caps
.num_vsis
&& !pf
->vsi
[i
]) {
5284 vsi_idx
= i
; /* Found one! */
5287 goto unlock_pf
; /* out of VSI slots! */
5291 vsi
= kzalloc(sizeof(*vsi
), GFP_KERNEL
);
5298 set_bit(__I40E_DOWN
, &vsi
->state
);
5301 vsi
->rx_itr_setting
= pf
->rx_itr_default
;
5302 vsi
->tx_itr_setting
= pf
->tx_itr_default
;
5303 vsi
->netdev_registered
= false;
5304 vsi
->work_limit
= I40E_DEFAULT_IRQ_WORK
;
5305 INIT_LIST_HEAD(&vsi
->mac_filter_list
);
5307 ret
= i40e_set_num_rings_in_vsi(vsi
);
5311 ret
= i40e_vsi_alloc_arrays(vsi
, true);
5315 /* Setup default MSIX irq handler for VSI */
5316 i40e_vsi_setup_irqhandler(vsi
, i40e_msix_clean_rings
);
5318 pf
->vsi
[vsi_idx
] = vsi
;
5323 pf
->next_vsi
= i
- 1;
5326 mutex_unlock(&pf
->switch_mutex
);
5331 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
5332 * @type: VSI pointer
5333 * @free_qvectors: a bool to specify if q_vectors need to be freed.
5335 * On error: returns error code (negative)
5336 * On success: returns 0
5338 static void i40e_vsi_free_arrays(struct i40e_vsi
*vsi
, bool free_qvectors
)
5340 /* free the ring and vector containers */
5341 if (free_qvectors
) {
5342 kfree(vsi
->q_vectors
);
5343 vsi
->q_vectors
= NULL
;
5345 kfree(vsi
->tx_rings
);
5346 vsi
->tx_rings
= NULL
;
5347 vsi
->rx_rings
= NULL
;
5351 * i40e_vsi_clear - Deallocate the VSI provided
5352 * @vsi: the VSI being un-configured
5354 static int i40e_vsi_clear(struct i40e_vsi
*vsi
)
5365 mutex_lock(&pf
->switch_mutex
);
5366 if (!pf
->vsi
[vsi
->idx
]) {
5367 dev_err(&pf
->pdev
->dev
, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
5368 vsi
->idx
, vsi
->idx
, vsi
, vsi
->type
);
5372 if (pf
->vsi
[vsi
->idx
] != vsi
) {
5373 dev_err(&pf
->pdev
->dev
,
5374 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
5375 pf
->vsi
[vsi
->idx
]->idx
,
5377 pf
->vsi
[vsi
->idx
]->type
,
5378 vsi
->idx
, vsi
, vsi
->type
);
5382 /* updates the pf for this cleared vsi */
5383 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
5384 i40e_put_lump(pf
->irq_pile
, vsi
->base_vector
, vsi
->idx
);
5386 i40e_vsi_free_arrays(vsi
, true);
5388 pf
->vsi
[vsi
->idx
] = NULL
;
5389 if (vsi
->idx
< pf
->next_vsi
)
5390 pf
->next_vsi
= vsi
->idx
;
5393 mutex_unlock(&pf
->switch_mutex
);
5401 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
5402 * @vsi: the VSI being cleaned
5404 static void i40e_vsi_clear_rings(struct i40e_vsi
*vsi
)
5408 if (vsi
->tx_rings
&& vsi
->tx_rings
[0]) {
5409 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
5410 kfree_rcu(vsi
->tx_rings
[i
], rcu
);
5411 vsi
->tx_rings
[i
] = NULL
;
5412 vsi
->rx_rings
[i
] = NULL
;
5418 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
5419 * @vsi: the VSI being configured
5421 static int i40e_alloc_rings(struct i40e_vsi
*vsi
)
5423 struct i40e_pf
*pf
= vsi
->back
;
5426 /* Set basic values in the rings to be used later during open() */
5427 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
5428 struct i40e_ring
*tx_ring
;
5429 struct i40e_ring
*rx_ring
;
5431 /* allocate space for both Tx and Rx in one shot */
5432 tx_ring
= kzalloc(sizeof(struct i40e_ring
) * 2, GFP_KERNEL
);
5436 tx_ring
->queue_index
= i
;
5437 tx_ring
->reg_idx
= vsi
->base_queue
+ i
;
5438 tx_ring
->ring_active
= false;
5440 tx_ring
->netdev
= vsi
->netdev
;
5441 tx_ring
->dev
= &pf
->pdev
->dev
;
5442 tx_ring
->count
= vsi
->num_desc
;
5444 tx_ring
->dcb_tc
= 0;
5445 vsi
->tx_rings
[i
] = tx_ring
;
5447 rx_ring
= &tx_ring
[1];
5448 rx_ring
->queue_index
= i
;
5449 rx_ring
->reg_idx
= vsi
->base_queue
+ i
;
5450 rx_ring
->ring_active
= false;
5452 rx_ring
->netdev
= vsi
->netdev
;
5453 rx_ring
->dev
= &pf
->pdev
->dev
;
5454 rx_ring
->count
= vsi
->num_desc
;
5456 rx_ring
->dcb_tc
= 0;
5457 if (pf
->flags
& I40E_FLAG_16BYTE_RX_DESC_ENABLED
)
5458 set_ring_16byte_desc_enabled(rx_ring
);
5460 clear_ring_16byte_desc_enabled(rx_ring
);
5461 vsi
->rx_rings
[i
] = rx_ring
;
5467 i40e_vsi_clear_rings(vsi
);
5472 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
5473 * @pf: board private structure
5474 * @vectors: the number of MSI-X vectors to request
5476 * Returns the number of vectors reserved, or error
5478 static int i40e_reserve_msix_vectors(struct i40e_pf
*pf
, int vectors
)
5482 pf
->num_msix_entries
= 0;
5483 while (vectors
>= I40E_MIN_MSIX
) {
5484 err
= pci_enable_msix(pf
->pdev
, pf
->msix_entries
, vectors
);
5487 pf
->num_msix_entries
= vectors
;
5489 } else if (err
< 0) {
5491 dev_info(&pf
->pdev
->dev
,
5492 "MSI-X vector reservation failed: %d\n", err
);
5496 /* err > 0 is the hint for retry */
5497 dev_info(&pf
->pdev
->dev
,
5498 "MSI-X vectors wanted %d, retrying with %d\n",
5504 if (vectors
> 0 && vectors
< I40E_MIN_MSIX
) {
5505 dev_info(&pf
->pdev
->dev
,
5506 "Couldn't get enough vectors, only %d available\n",
5515 * i40e_init_msix - Setup the MSIX capability
5516 * @pf: board private structure
5518 * Work with the OS to set up the MSIX vectors needed.
5520 * Returns 0 on success, negative on failure
5522 static int i40e_init_msix(struct i40e_pf
*pf
)
5524 i40e_status err
= 0;
5525 struct i40e_hw
*hw
= &pf
->hw
;
5529 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
5532 /* The number of vectors we'll request will be comprised of:
5533 * - Add 1 for "other" cause for Admin Queue events, etc.
5534 * - The number of LAN queue pairs
5535 * - Queues being used for RSS.
5536 * We don't need as many as max_rss_size vectors.
5537 * use rss_size instead in the calculation since that
5538 * is governed by number of cpus in the system.
5539 * - assumes symmetric Tx/Rx pairing
5540 * - The number of VMDq pairs
5541 * Once we count this up, try the request.
5543 * If we can't get what we want, we'll simplify to nearly nothing
5544 * and try again. If that still fails, we punt.
5546 pf
->num_lan_msix
= pf
->num_lan_qps
- (pf
->rss_size_max
- pf
->rss_size
);
5547 pf
->num_vmdq_msix
= pf
->num_vmdq_qps
;
5548 v_budget
= 1 + pf
->num_lan_msix
;
5549 v_budget
+= (pf
->num_vmdq_vsis
* pf
->num_vmdq_msix
);
5550 if (pf
->flags
& I40E_FLAG_FDIR_ENABLED
)
5553 /* Scale down if necessary, and the rings will share vectors */
5554 v_budget
= min_t(int, v_budget
, hw
->func_caps
.num_msix_vectors
);
5556 pf
->msix_entries
= kcalloc(v_budget
, sizeof(struct msix_entry
),
5558 if (!pf
->msix_entries
)
5561 for (i
= 0; i
< v_budget
; i
++)
5562 pf
->msix_entries
[i
].entry
= i
;
5563 vec
= i40e_reserve_msix_vectors(pf
, v_budget
);
5564 if (vec
< I40E_MIN_MSIX
) {
5565 pf
->flags
&= ~I40E_FLAG_MSIX_ENABLED
;
5566 kfree(pf
->msix_entries
);
5567 pf
->msix_entries
= NULL
;
5570 } else if (vec
== I40E_MIN_MSIX
) {
5571 /* Adjust for minimal MSIX use */
5572 dev_info(&pf
->pdev
->dev
, "Features disabled, not enough MSIX vectors\n");
5573 pf
->flags
&= ~I40E_FLAG_VMDQ_ENABLED
;
5574 pf
->num_vmdq_vsis
= 0;
5575 pf
->num_vmdq_qps
= 0;
5576 pf
->num_vmdq_msix
= 0;
5577 pf
->num_lan_qps
= 1;
5578 pf
->num_lan_msix
= 1;
5580 } else if (vec
!= v_budget
) {
5581 /* Scale vector usage down */
5582 pf
->num_vmdq_msix
= 1; /* force VMDqs to only one vector */
5583 vec
--; /* reserve the misc vector */
5585 /* partition out the remaining vectors */
5588 pf
->num_vmdq_vsis
= 1;
5589 pf
->num_lan_msix
= 1;
5592 pf
->num_vmdq_vsis
= 1;
5593 pf
->num_lan_msix
= 2;
5596 pf
->num_lan_msix
= min_t(int, (vec
/ 2),
5598 pf
->num_vmdq_vsis
= min_t(int, (vec
- pf
->num_lan_msix
),
5599 I40E_DEFAULT_NUM_VMDQ_VSI
);
5608 * i40e_alloc_q_vector - Allocate memory for a single interrupt vector
5609 * @vsi: the VSI being configured
5610 * @v_idx: index of the vector in the vsi struct
5612 * We allocate one q_vector. If allocation fails we return -ENOMEM.
5614 static int i40e_alloc_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
5616 struct i40e_q_vector
*q_vector
;
5618 /* allocate q_vector */
5619 q_vector
= kzalloc(sizeof(struct i40e_q_vector
), GFP_KERNEL
);
5623 q_vector
->vsi
= vsi
;
5624 q_vector
->v_idx
= v_idx
;
5625 cpumask_set_cpu(v_idx
, &q_vector
->affinity_mask
);
5627 netif_napi_add(vsi
->netdev
, &q_vector
->napi
,
5628 i40e_napi_poll
, vsi
->work_limit
);
5630 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
5631 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
5633 /* tie q_vector and vsi together */
5634 vsi
->q_vectors
[v_idx
] = q_vector
;
5640 * i40e_alloc_q_vectors - Allocate memory for interrupt vectors
5641 * @vsi: the VSI being configured
5643 * We allocate one q_vector per queue interrupt. If allocation fails we
5646 static int i40e_alloc_q_vectors(struct i40e_vsi
*vsi
)
5648 struct i40e_pf
*pf
= vsi
->back
;
5649 int v_idx
, num_q_vectors
;
5652 /* if not MSIX, give the one vector only to the LAN VSI */
5653 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
5654 num_q_vectors
= vsi
->num_q_vectors
;
5655 else if (vsi
== pf
->vsi
[pf
->lan_vsi
])
5660 for (v_idx
= 0; v_idx
< num_q_vectors
; v_idx
++) {
5661 err
= i40e_alloc_q_vector(vsi
, v_idx
);
5670 i40e_free_q_vector(vsi
, v_idx
);
5676 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
5677 * @pf: board private structure to initialize
5679 static void i40e_init_interrupt_scheme(struct i40e_pf
*pf
)
5683 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
5684 err
= i40e_init_msix(pf
);
5686 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
|
5687 I40E_FLAG_RSS_ENABLED
|
5688 I40E_FLAG_DCB_ENABLED
|
5689 I40E_FLAG_SRIOV_ENABLED
|
5690 I40E_FLAG_FDIR_ENABLED
|
5691 I40E_FLAG_FDIR_ATR_ENABLED
|
5692 I40E_FLAG_VMDQ_ENABLED
);
5694 /* rework the queue expectations without MSIX */
5695 i40e_determine_queue_usage(pf
);
5699 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
5700 (pf
->flags
& I40E_FLAG_MSI_ENABLED
)) {
5701 dev_info(&pf
->pdev
->dev
, "MSIX not available, trying MSI\n");
5702 err
= pci_enable_msi(pf
->pdev
);
5704 dev_info(&pf
->pdev
->dev
, "MSI init failed - %d\n", err
);
5705 pf
->flags
&= ~I40E_FLAG_MSI_ENABLED
;
5709 if (!(pf
->flags
& (I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
)))
5710 dev_info(&pf
->pdev
->dev
, "MSIX and MSI not available, falling back to Legacy IRQ\n");
5712 /* track first vector for misc interrupts */
5713 err
= i40e_get_lump(pf
, pf
->irq_pile
, 1, I40E_PILE_VALID_BIT
-1);
5717 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
5718 * @pf: board private structure
5720 * This sets up the handler for MSIX 0, which is used to manage the
5721 * non-queue interrupts, e.g. AdminQ and errors. This is not used
5722 * when in MSI or Legacy interrupt mode.
5724 static int i40e_setup_misc_vector(struct i40e_pf
*pf
)
5726 struct i40e_hw
*hw
= &pf
->hw
;
5729 /* Only request the irq if this is the first time through, and
5730 * not when we're rebuilding after a Reset
5732 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
)) {
5733 err
= request_irq(pf
->msix_entries
[0].vector
,
5734 i40e_intr
, 0, pf
->misc_int_name
, pf
);
5736 dev_info(&pf
->pdev
->dev
,
5737 "request_irq for msix_misc failed: %d\n", err
);
5742 i40e_enable_misc_int_causes(hw
);
5744 /* associate no queues to the misc vector */
5745 wr32(hw
, I40E_PFINT_LNKLST0
, I40E_QUEUE_END_OF_LIST
);
5746 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), I40E_ITR_8K
);
5750 i40e_irq_dynamic_enable_icr0(pf
);
5756 * i40e_config_rss - Prepare for RSS if used
5757 * @pf: board private structure
5759 static int i40e_config_rss(struct i40e_pf
*pf
)
5761 /* Set of random keys generated using kernel random number generator */
5762 static const u32 seed
[I40E_PFQF_HKEY_MAX_INDEX
+ 1] = {0x41b01687,
5763 0x183cfd8c, 0xce880440, 0x580cbc3c, 0x35897377,
5764 0x328b25e1, 0x4fa98922, 0xb7d90c14, 0xd5bad70d,
5765 0xcd15a2c1, 0xe8580225, 0x4a1e9d11, 0xfe5731be};
5766 struct i40e_hw
*hw
= &pf
->hw
;
5771 /* Fill out hash function seed */
5772 for (i
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++)
5773 wr32(hw
, I40E_PFQF_HKEY(i
), seed
[i
]);
5775 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
5776 hena
= (u64
)rd32(hw
, I40E_PFQF_HENA(0)) |
5777 ((u64
)rd32(hw
, I40E_PFQF_HENA(1)) << 32);
5778 hena
|= I40E_DEFAULT_RSS_HENA
;
5779 wr32(hw
, I40E_PFQF_HENA(0), (u32
)hena
);
5780 wr32(hw
, I40E_PFQF_HENA(1), (u32
)(hena
>> 32));
5782 /* Populate the LUT with max no. of queues in round robin fashion */
5783 for (i
= 0, j
= 0; i
< pf
->hw
.func_caps
.rss_table_size
; i
++, j
++) {
5785 /* The assumption is that lan qp count will be the highest
5786 * qp count for any PF VSI that needs RSS.
5787 * If multiple VSIs need RSS support, all the qp counts
5788 * for those VSIs should be a power of 2 for RSS to work.
5789 * If LAN VSI is the only consumer for RSS then this requirement
5792 if (j
== pf
->rss_size
)
5794 /* lut = 4-byte sliding window of 4 lut entries */
5795 lut
= (lut
<< 8) | (j
&
5796 ((0x1 << pf
->hw
.func_caps
.rss_table_entry_width
) - 1));
5797 /* On i = 3, we have 4 entries in lut; write to the register */
5799 wr32(hw
, I40E_PFQF_HLUT(i
>> 2), lut
);
5807 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
5808 * @pf: board private structure
5809 * @queue_count: the requested queue count for rss.
5811 * returns 0 if rss is not enabled, if enabled returns the final rss queue
5812 * count which may be different from the requested queue count.
5814 int i40e_reconfig_rss_queues(struct i40e_pf
*pf
, int queue_count
)
5816 if (!(pf
->flags
& I40E_FLAG_RSS_ENABLED
))
5819 queue_count
= min_t(int, queue_count
, pf
->rss_size_max
);
5820 queue_count
= rounddown_pow_of_two(queue_count
);
5822 if (queue_count
!= pf
->rss_size
) {
5823 i40e_prep_for_reset(pf
);
5825 pf
->rss_size
= queue_count
;
5827 i40e_reset_and_rebuild(pf
, true);
5828 i40e_config_rss(pf
);
5830 dev_info(&pf
->pdev
->dev
, "RSS count: %d\n", pf
->rss_size
);
5831 return pf
->rss_size
;
5835 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
5836 * @pf: board private structure to initialize
5838 * i40e_sw_init initializes the Adapter private data structure.
5839 * Fields are initialized based on PCI device information and
5840 * OS network device settings (MTU size).
5842 static int i40e_sw_init(struct i40e_pf
*pf
)
5847 pf
->msg_enable
= netif_msg_init(I40E_DEFAULT_MSG_ENABLE
,
5848 (NETIF_MSG_DRV
|NETIF_MSG_PROBE
|NETIF_MSG_LINK
));
5849 pf
->hw
.debug_mask
= pf
->msg_enable
| I40E_DEBUG_DIAG
;
5850 if (debug
!= -1 && debug
!= I40E_DEFAULT_MSG_ENABLE
) {
5851 if (I40E_DEBUG_USER
& debug
)
5852 pf
->hw
.debug_mask
= debug
;
5853 pf
->msg_enable
= netif_msg_init((debug
& ~I40E_DEBUG_USER
),
5854 I40E_DEFAULT_MSG_ENABLE
);
5857 /* Set default capability flags */
5858 pf
->flags
= I40E_FLAG_RX_CSUM_ENABLED
|
5859 I40E_FLAG_MSI_ENABLED
|
5860 I40E_FLAG_MSIX_ENABLED
|
5861 I40E_FLAG_RX_1BUF_ENABLED
;
5863 /* Depending on PF configurations, it is possible that the RSS
5864 * maximum might end up larger than the available queues
5866 pf
->rss_size_max
= 0x1 << pf
->hw
.func_caps
.rss_table_entry_width
;
5867 pf
->rss_size_max
= min_t(int, pf
->rss_size_max
,
5868 pf
->hw
.func_caps
.num_tx_qp
);
5869 if (pf
->hw
.func_caps
.rss
) {
5870 pf
->flags
|= I40E_FLAG_RSS_ENABLED
;
5871 pf
->rss_size
= min_t(int, pf
->rss_size_max
, num_online_cpus());
5876 /* MFP mode enabled */
5877 if (pf
->hw
.func_caps
.npar_enable
|| pf
->hw
.func_caps
.mfp_mode_1
) {
5878 pf
->flags
|= I40E_FLAG_MFP_ENABLED
;
5879 dev_info(&pf
->pdev
->dev
, "MFP mode Enabled\n");
5882 if (pf
->hw
.func_caps
.dcb
)
5883 pf
->num_tc_qps
= I40E_DEFAULT_QUEUES_PER_TC
;
5887 if (pf
->hw
.func_caps
.fd
) {
5888 /* FW/NVM is not yet fixed in this regard */
5889 if ((pf
->hw
.func_caps
.fd_filters_guaranteed
> 0) ||
5890 (pf
->hw
.func_caps
.fd_filters_best_effort
> 0)) {
5891 pf
->flags
|= I40E_FLAG_FDIR_ATR_ENABLED
;
5892 dev_info(&pf
->pdev
->dev
,
5893 "Flow Director ATR mode Enabled\n");
5894 pf
->flags
|= I40E_FLAG_FDIR_ENABLED
;
5895 dev_info(&pf
->pdev
->dev
,
5896 "Flow Director Side Band mode Enabled\n");
5897 pf
->fdir_pf_filter_count
=
5898 pf
->hw
.func_caps
.fd_filters_guaranteed
;
5901 pf
->fdir_pf_filter_count
= 0;
5904 if (pf
->hw
.func_caps
.vmdq
) {
5905 pf
->flags
|= I40E_FLAG_VMDQ_ENABLED
;
5906 pf
->num_vmdq_vsis
= I40E_DEFAULT_NUM_VMDQ_VSI
;
5907 pf
->num_vmdq_qps
= I40E_DEFAULT_QUEUES_PER_VMDQ
;
5910 #ifdef CONFIG_PCI_IOV
5911 if (pf
->hw
.func_caps
.num_vfs
) {
5912 pf
->num_vf_qps
= I40E_DEFAULT_QUEUES_PER_VF
;
5913 pf
->flags
|= I40E_FLAG_SRIOV_ENABLED
;
5914 pf
->num_req_vfs
= min_t(int,
5915 pf
->hw
.func_caps
.num_vfs
,
5917 dev_info(&pf
->pdev
->dev
,
5918 "Number of VFs being requested for PF[%d] = %d\n",
5919 pf
->hw
.pf_id
, pf
->num_req_vfs
);
5921 #endif /* CONFIG_PCI_IOV */
5922 pf
->eeprom_version
= 0xDEAD;
5923 pf
->lan_veb
= I40E_NO_VEB
;
5924 pf
->lan_vsi
= I40E_NO_VSI
;
5926 /* set up queue assignment tracking */
5927 size
= sizeof(struct i40e_lump_tracking
)
5928 + (sizeof(u16
) * pf
->hw
.func_caps
.num_tx_qp
);
5929 pf
->qp_pile
= kzalloc(size
, GFP_KERNEL
);
5934 pf
->qp_pile
->num_entries
= pf
->hw
.func_caps
.num_tx_qp
;
5935 pf
->qp_pile
->search_hint
= 0;
5937 /* set up vector assignment tracking */
5938 size
= sizeof(struct i40e_lump_tracking
)
5939 + (sizeof(u16
) * pf
->hw
.func_caps
.num_msix_vectors
);
5940 pf
->irq_pile
= kzalloc(size
, GFP_KERNEL
);
5941 if (!pf
->irq_pile
) {
5946 pf
->irq_pile
->num_entries
= pf
->hw
.func_caps
.num_msix_vectors
;
5947 pf
->irq_pile
->search_hint
= 0;
5949 mutex_init(&pf
->switch_mutex
);
5956 * i40e_set_features - set the netdev feature flags
5957 * @netdev: ptr to the netdev being adjusted
5958 * @features: the feature set that the stack is suggesting
5960 static int i40e_set_features(struct net_device
*netdev
,
5961 netdev_features_t features
)
5963 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
5964 struct i40e_vsi
*vsi
= np
->vsi
;
5966 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
5967 i40e_vlan_stripping_enable(vsi
);
5969 i40e_vlan_stripping_disable(vsi
);
5974 #ifdef CONFIG_I40E_VXLAN
5976 * i40e_get_vxlan_port_idx - Lookup a possibly offloaded for Rx UDP port
5977 * @pf: board private structure
5978 * @port: The UDP port to look up
5980 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
5982 static u8
i40e_get_vxlan_port_idx(struct i40e_pf
*pf
, __be16 port
)
5986 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
5987 if (pf
->vxlan_ports
[i
] == port
)
5995 * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up
5996 * @netdev: This physical port's netdev
5997 * @sa_family: Socket Family that VXLAN is notifying us about
5998 * @port: New UDP port number that VXLAN started listening to
6000 static void i40e_add_vxlan_port(struct net_device
*netdev
,
6001 sa_family_t sa_family
, __be16 port
)
6003 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
6004 struct i40e_vsi
*vsi
= np
->vsi
;
6005 struct i40e_pf
*pf
= vsi
->back
;
6009 if (sa_family
== AF_INET6
)
6012 idx
= i40e_get_vxlan_port_idx(pf
, port
);
6014 /* Check if port already exists */
6015 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
6016 netdev_info(netdev
, "Port %d already offloaded\n", ntohs(port
));
6020 /* Now check if there is space to add the new port */
6021 next_idx
= i40e_get_vxlan_port_idx(pf
, 0);
6023 if (next_idx
== I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
6024 netdev_info(netdev
, "Maximum number of UDP ports reached, not adding port %d\n",
6029 /* New port: add it and mark its index in the bitmap */
6030 pf
->vxlan_ports
[next_idx
] = port
;
6031 pf
->pending_vxlan_bitmap
|= (1 << next_idx
);
6033 pf
->flags
|= I40E_FLAG_VXLAN_FILTER_SYNC
;
6037 * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away
6038 * @netdev: This physical port's netdev
6039 * @sa_family: Socket Family that VXLAN is notifying us about
6040 * @port: UDP port number that VXLAN stopped listening to
6042 static void i40e_del_vxlan_port(struct net_device
*netdev
,
6043 sa_family_t sa_family
, __be16 port
)
6045 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
6046 struct i40e_vsi
*vsi
= np
->vsi
;
6047 struct i40e_pf
*pf
= vsi
->back
;
6050 if (sa_family
== AF_INET6
)
6053 idx
= i40e_get_vxlan_port_idx(pf
, port
);
6055 /* Check if port already exists */
6056 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
6057 /* if port exists, set it to 0 (mark for deletion)
6058 * and make it pending
6060 pf
->vxlan_ports
[idx
] = 0;
6062 pf
->pending_vxlan_bitmap
|= (1 << idx
);
6064 pf
->flags
|= I40E_FLAG_VXLAN_FILTER_SYNC
;
6066 netdev_warn(netdev
, "Port %d was not found, not deleting\n",
6072 static const struct net_device_ops i40e_netdev_ops
= {
6073 .ndo_open
= i40e_open
,
6074 .ndo_stop
= i40e_close
,
6075 .ndo_start_xmit
= i40e_lan_xmit_frame
,
6076 .ndo_get_stats64
= i40e_get_netdev_stats_struct
,
6077 .ndo_set_rx_mode
= i40e_set_rx_mode
,
6078 .ndo_validate_addr
= eth_validate_addr
,
6079 .ndo_set_mac_address
= i40e_set_mac
,
6080 .ndo_change_mtu
= i40e_change_mtu
,
6081 .ndo_do_ioctl
= i40e_ioctl
,
6082 .ndo_tx_timeout
= i40e_tx_timeout
,
6083 .ndo_vlan_rx_add_vid
= i40e_vlan_rx_add_vid
,
6084 .ndo_vlan_rx_kill_vid
= i40e_vlan_rx_kill_vid
,
6085 #ifdef CONFIG_NET_POLL_CONTROLLER
6086 .ndo_poll_controller
= i40e_netpoll
,
6088 .ndo_setup_tc
= i40e_setup_tc
,
6089 .ndo_set_features
= i40e_set_features
,
6090 .ndo_set_vf_mac
= i40e_ndo_set_vf_mac
,
6091 .ndo_set_vf_vlan
= i40e_ndo_set_vf_port_vlan
,
6092 .ndo_set_vf_tx_rate
= i40e_ndo_set_vf_bw
,
6093 .ndo_get_vf_config
= i40e_ndo_get_vf_config
,
6094 #ifdef CONFIG_I40E_VXLAN
6095 .ndo_add_vxlan_port
= i40e_add_vxlan_port
,
6096 .ndo_del_vxlan_port
= i40e_del_vxlan_port
,
6101 * i40e_config_netdev - Setup the netdev flags
6102 * @vsi: the VSI being configured
6104 * Returns 0 on success, negative value on failure
6106 static int i40e_config_netdev(struct i40e_vsi
*vsi
)
6108 u8 brdcast
[ETH_ALEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
6109 struct i40e_pf
*pf
= vsi
->back
;
6110 struct i40e_hw
*hw
= &pf
->hw
;
6111 struct i40e_netdev_priv
*np
;
6112 struct net_device
*netdev
;
6113 u8 mac_addr
[ETH_ALEN
];
6116 etherdev_size
= sizeof(struct i40e_netdev_priv
);
6117 netdev
= alloc_etherdev_mq(etherdev_size
, vsi
->alloc_queue_pairs
);
6121 vsi
->netdev
= netdev
;
6122 np
= netdev_priv(netdev
);
6125 netdev
->hw_enc_features
= NETIF_F_IP_CSUM
|
6126 NETIF_F_GSO_UDP_TUNNEL
|
6130 netdev
->features
= NETIF_F_SG
|
6134 NETIF_F_GSO_UDP_TUNNEL
|
6135 NETIF_F_HW_VLAN_CTAG_TX
|
6136 NETIF_F_HW_VLAN_CTAG_RX
|
6137 NETIF_F_HW_VLAN_CTAG_FILTER
|
6145 /* copy netdev features into list of user selectable features */
6146 netdev
->hw_features
|= netdev
->features
;
6148 if (vsi
->type
== I40E_VSI_MAIN
) {
6149 SET_NETDEV_DEV(netdev
, &pf
->pdev
->dev
);
6150 memcpy(mac_addr
, hw
->mac
.perm_addr
, ETH_ALEN
);
6152 /* relate the VSI_VMDQ name to the VSI_MAIN name */
6153 snprintf(netdev
->name
, IFNAMSIZ
, "%sv%%d",
6154 pf
->vsi
[pf
->lan_vsi
]->netdev
->name
);
6155 random_ether_addr(mac_addr
);
6156 i40e_add_filter(vsi
, mac_addr
, I40E_VLAN_ANY
, false, false);
6158 i40e_add_filter(vsi
, brdcast
, I40E_VLAN_ANY
, false, false);
6160 memcpy(netdev
->dev_addr
, mac_addr
, ETH_ALEN
);
6161 memcpy(netdev
->perm_addr
, mac_addr
, ETH_ALEN
);
6162 /* vlan gets same features (except vlan offload)
6163 * after any tweaks for specific VSI types
6165 netdev
->vlan_features
= netdev
->features
& ~(NETIF_F_HW_VLAN_CTAG_TX
|
6166 NETIF_F_HW_VLAN_CTAG_RX
|
6167 NETIF_F_HW_VLAN_CTAG_FILTER
);
6168 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
6169 netdev
->priv_flags
|= IFF_SUPP_NOFCS
;
6170 /* Setup netdev TC information */
6171 i40e_vsi_config_netdev_tc(vsi
, vsi
->tc_config
.enabled_tc
);
6173 netdev
->netdev_ops
= &i40e_netdev_ops
;
6174 netdev
->watchdog_timeo
= 5 * HZ
;
6175 i40e_set_ethtool_ops(netdev
);
6181 * i40e_vsi_delete - Delete a VSI from the switch
6182 * @vsi: the VSI being removed
6184 * Returns 0 on success, negative value on failure
6186 static void i40e_vsi_delete(struct i40e_vsi
*vsi
)
6188 /* remove default VSI is not allowed */
6189 if (vsi
== vsi
->back
->vsi
[vsi
->back
->lan_vsi
])
6192 /* there is no HW VSI for FDIR */
6193 if (vsi
->type
== I40E_VSI_FDIR
)
6196 i40e_aq_delete_element(&vsi
->back
->hw
, vsi
->seid
, NULL
);
6201 * i40e_add_vsi - Add a VSI to the switch
6202 * @vsi: the VSI being configured
6204 * This initializes a VSI context depending on the VSI type to be added and
6205 * passes it down to the add_vsi aq command.
6207 static int i40e_add_vsi(struct i40e_vsi
*vsi
)
6210 struct i40e_mac_filter
*f
, *ftmp
;
6211 struct i40e_pf
*pf
= vsi
->back
;
6212 struct i40e_hw
*hw
= &pf
->hw
;
6213 struct i40e_vsi_context ctxt
;
6214 u8 enabled_tc
= 0x1; /* TC0 enabled */
6217 memset(&ctxt
, 0, sizeof(ctxt
));
6218 switch (vsi
->type
) {
6220 /* The PF's main VSI is already setup as part of the
6221 * device initialization, so we'll not bother with
6222 * the add_vsi call, but we will retrieve the current
6225 ctxt
.seid
= pf
->main_vsi_seid
;
6226 ctxt
.pf_num
= pf
->hw
.pf_id
;
6228 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
6229 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
6231 dev_info(&pf
->pdev
->dev
,
6232 "couldn't get pf vsi config, err %d, aq_err %d\n",
6233 ret
, pf
->hw
.aq
.asq_last_status
);
6236 memcpy(&vsi
->info
, &ctxt
.info
, sizeof(ctxt
.info
));
6237 vsi
->info
.valid_sections
= 0;
6239 vsi
->seid
= ctxt
.seid
;
6240 vsi
->id
= ctxt
.vsi_number
;
6242 enabled_tc
= i40e_pf_get_tc_map(pf
);
6244 /* MFP mode setup queue map and update VSI */
6245 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
6246 memset(&ctxt
, 0, sizeof(ctxt
));
6247 ctxt
.seid
= pf
->main_vsi_seid
;
6248 ctxt
.pf_num
= pf
->hw
.pf_id
;
6250 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
6251 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
6253 dev_info(&pf
->pdev
->dev
,
6254 "update vsi failed, aq_err=%d\n",
6255 pf
->hw
.aq
.asq_last_status
);
6259 /* update the local VSI info queue map */
6260 i40e_vsi_update_queue_map(vsi
, &ctxt
);
6261 vsi
->info
.valid_sections
= 0;
6263 /* Default/Main VSI is only enabled for TC0
6264 * reconfigure it to enable all TCs that are
6265 * available on the port in SFP mode.
6267 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
6269 dev_info(&pf
->pdev
->dev
,
6270 "failed to configure TCs for main VSI tc_map 0x%08x, err %d, aq_err %d\n",
6272 pf
->hw
.aq
.asq_last_status
);
6279 /* no queue mapping or actual HW VSI needed */
6280 vsi
->info
.valid_sections
= 0;
6283 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
6287 case I40E_VSI_VMDQ2
:
6288 ctxt
.pf_num
= hw
->pf_id
;
6290 ctxt
.uplink_seid
= vsi
->uplink_seid
;
6291 ctxt
.connection_type
= 0x1; /* regular data port */
6292 ctxt
.flags
= I40E_AQ_VSI_TYPE_VMDQ2
;
6294 ctxt
.info
.valid_sections
|= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
6296 /* This VSI is connected to VEB so the switch_id
6297 * should be set to zero by default.
6299 ctxt
.info
.switch_id
= 0;
6300 ctxt
.info
.switch_id
|= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB
);
6301 ctxt
.info
.switch_id
|= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
6303 /* Setup the VSI tx/rx queue map for TC0 only for now */
6304 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
6307 case I40E_VSI_SRIOV
:
6308 ctxt
.pf_num
= hw
->pf_id
;
6309 ctxt
.vf_num
= vsi
->vf_id
+ hw
->func_caps
.vf_base_id
;
6310 ctxt
.uplink_seid
= vsi
->uplink_seid
;
6311 ctxt
.connection_type
= 0x1; /* regular data port */
6312 ctxt
.flags
= I40E_AQ_VSI_TYPE_VF
;
6314 ctxt
.info
.valid_sections
|= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
6316 /* This VSI is connected to VEB so the switch_id
6317 * should be set to zero by default.
6319 ctxt
.info
.switch_id
= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
6321 ctxt
.info
.valid_sections
|= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
6322 ctxt
.info
.port_vlan_flags
|= I40E_AQ_VSI_PVLAN_MODE_ALL
;
6323 /* Setup the VSI tx/rx queue map for TC0 only for now */
6324 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
6331 if (vsi
->type
!= I40E_VSI_MAIN
) {
6332 ret
= i40e_aq_add_vsi(hw
, &ctxt
, NULL
);
6334 dev_info(&vsi
->back
->pdev
->dev
,
6335 "add vsi failed, aq_err=%d\n",
6336 vsi
->back
->hw
.aq
.asq_last_status
);
6340 memcpy(&vsi
->info
, &ctxt
.info
, sizeof(ctxt
.info
));
6341 vsi
->info
.valid_sections
= 0;
6342 vsi
->seid
= ctxt
.seid
;
6343 vsi
->id
= ctxt
.vsi_number
;
6346 /* If macvlan filters already exist, force them to get loaded */
6347 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
6352 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
6353 pf
->flags
|= I40E_FLAG_FILTER_SYNC
;
6356 /* Update VSI BW information */
6357 ret
= i40e_vsi_get_bw_info(vsi
);
6359 dev_info(&pf
->pdev
->dev
,
6360 "couldn't get vsi bw info, err %d, aq_err %d\n",
6361 ret
, pf
->hw
.aq
.asq_last_status
);
6362 /* VSI is already added so not tearing that up */
6371 * i40e_vsi_release - Delete a VSI and free its resources
6372 * @vsi: the VSI being removed
6374 * Returns 0 on success or < 0 on error
6376 int i40e_vsi_release(struct i40e_vsi
*vsi
)
6378 struct i40e_mac_filter
*f
, *ftmp
;
6379 struct i40e_veb
*veb
= NULL
;
6386 /* release of a VEB-owner or last VSI is not allowed */
6387 if (vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
6388 dev_info(&pf
->pdev
->dev
, "VSI %d has existing VEB %d\n",
6389 vsi
->seid
, vsi
->uplink_seid
);
6392 if (vsi
== pf
->vsi
[pf
->lan_vsi
] &&
6393 !test_bit(__I40E_DOWN
, &pf
->state
)) {
6394 dev_info(&pf
->pdev
->dev
, "Can't remove PF VSI\n");
6398 uplink_seid
= vsi
->uplink_seid
;
6399 if (vsi
->type
!= I40E_VSI_SRIOV
) {
6400 if (vsi
->netdev_registered
) {
6401 vsi
->netdev_registered
= false;
6403 /* results in a call to i40e_close() */
6404 unregister_netdev(vsi
->netdev
);
6405 free_netdev(vsi
->netdev
);
6409 if (!test_and_set_bit(__I40E_DOWN
, &vsi
->state
))
6411 i40e_vsi_free_irq(vsi
);
6412 i40e_vsi_free_tx_resources(vsi
);
6413 i40e_vsi_free_rx_resources(vsi
);
6415 i40e_vsi_disable_irq(vsi
);
6418 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
)
6419 i40e_del_filter(vsi
, f
->macaddr
, f
->vlan
,
6420 f
->is_vf
, f
->is_netdev
);
6421 i40e_sync_vsi_filters(vsi
);
6423 i40e_vsi_delete(vsi
);
6424 i40e_vsi_free_q_vectors(vsi
);
6425 i40e_vsi_clear_rings(vsi
);
6426 i40e_vsi_clear(vsi
);
6428 /* If this was the last thing on the VEB, except for the
6429 * controlling VSI, remove the VEB, which puts the controlling
6430 * VSI onto the next level down in the switch.
6432 * Well, okay, there's one more exception here: don't remove
6433 * the orphan VEBs yet. We'll wait for an explicit remove request
6434 * from up the network stack.
6436 for (n
= 0, i
= 0; i
< pf
->hw
.func_caps
.num_vsis
; i
++) {
6438 pf
->vsi
[i
]->uplink_seid
== uplink_seid
&&
6439 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
6440 n
++; /* count the VSIs */
6443 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
6446 if (pf
->veb
[i
]->uplink_seid
== uplink_seid
)
6447 n
++; /* count the VEBs */
6448 if (pf
->veb
[i
]->seid
== uplink_seid
)
6451 if (n
== 0 && veb
&& veb
->uplink_seid
!= 0)
6452 i40e_veb_release(veb
);
6458 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
6459 * @vsi: ptr to the VSI
6461 * This should only be called after i40e_vsi_mem_alloc() which allocates the
6462 * corresponding SW VSI structure and initializes num_queue_pairs for the
6463 * newly allocated VSI.
6465 * Returns 0 on success or negative on failure
6467 static int i40e_vsi_setup_vectors(struct i40e_vsi
*vsi
)
6470 struct i40e_pf
*pf
= vsi
->back
;
6472 if (vsi
->q_vectors
[0]) {
6473 dev_info(&pf
->pdev
->dev
, "VSI %d has existing q_vectors\n",
6478 if (vsi
->base_vector
) {
6479 dev_info(&pf
->pdev
->dev
,
6480 "VSI %d has non-zero base vector %d\n",
6481 vsi
->seid
, vsi
->base_vector
);
6485 ret
= i40e_alloc_q_vectors(vsi
);
6487 dev_info(&pf
->pdev
->dev
,
6488 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
6489 vsi
->num_q_vectors
, vsi
->seid
, ret
);
6490 vsi
->num_q_vectors
= 0;
6491 goto vector_setup_out
;
6494 if (vsi
->num_q_vectors
)
6495 vsi
->base_vector
= i40e_get_lump(pf
, pf
->irq_pile
,
6496 vsi
->num_q_vectors
, vsi
->idx
);
6497 if (vsi
->base_vector
< 0) {
6498 dev_info(&pf
->pdev
->dev
,
6499 "failed to get q tracking for VSI %d, err=%d\n",
6500 vsi
->seid
, vsi
->base_vector
);
6501 i40e_vsi_free_q_vectors(vsi
);
6503 goto vector_setup_out
;
6511 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
6512 * @vsi: pointer to the vsi.
6514 * This re-allocates a vsi's queue resources.
6516 * Returns pointer to the successfully allocated and configured VSI sw struct
6517 * on success, otherwise returns NULL on failure.
6519 static struct i40e_vsi
*i40e_vsi_reinit_setup(struct i40e_vsi
*vsi
)
6521 struct i40e_pf
*pf
= vsi
->back
;
6525 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
6526 i40e_vsi_clear_rings(vsi
);
6528 i40e_vsi_free_arrays(vsi
, false);
6529 i40e_set_num_rings_in_vsi(vsi
);
6530 ret
= i40e_vsi_alloc_arrays(vsi
, false);
6534 ret
= i40e_get_lump(pf
, pf
->qp_pile
, vsi
->alloc_queue_pairs
, vsi
->idx
);
6536 dev_info(&pf
->pdev
->dev
, "VSI %d get_lump failed %d\n",
6540 vsi
->base_queue
= ret
;
6542 /* Update the FW view of the VSI. Force a reset of TC and queue
6543 * layout configurations.
6545 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
6546 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
6547 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
6548 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
6550 /* assign it some queues */
6551 ret
= i40e_alloc_rings(vsi
);
6555 /* map all of the rings to the q_vectors */
6556 i40e_vsi_map_rings_to_vectors(vsi
);
6560 i40e_vsi_free_q_vectors(vsi
);
6561 if (vsi
->netdev_registered
) {
6562 vsi
->netdev_registered
= false;
6563 unregister_netdev(vsi
->netdev
);
6564 free_netdev(vsi
->netdev
);
6567 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
6569 i40e_vsi_clear(vsi
);
6574 * i40e_vsi_setup - Set up a VSI by a given type
6575 * @pf: board private structure
6577 * @uplink_seid: the switch element to link to
6578 * @param1: usage depends upon VSI type. For VF types, indicates VF id
6580 * This allocates the sw VSI structure and its queue resources, then add a VSI
6581 * to the identified VEB.
6583 * Returns pointer to the successfully allocated and configure VSI sw struct on
6584 * success, otherwise returns NULL on failure.
6586 struct i40e_vsi
*i40e_vsi_setup(struct i40e_pf
*pf
, u8 type
,
6587 u16 uplink_seid
, u32 param1
)
6589 struct i40e_vsi
*vsi
= NULL
;
6590 struct i40e_veb
*veb
= NULL
;
6594 /* The requested uplink_seid must be either
6595 * - the PF's port seid
6596 * no VEB is needed because this is the PF
6597 * or this is a Flow Director special case VSI
6598 * - seid of an existing VEB
6599 * - seid of a VSI that owns an existing VEB
6600 * - seid of a VSI that doesn't own a VEB
6601 * a new VEB is created and the VSI becomes the owner
6602 * - seid of the PF VSI, which is what creates the first VEB
6603 * this is a special case of the previous
6605 * Find which uplink_seid we were given and create a new VEB if needed
6607 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
6608 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== uplink_seid
) {
6614 if (!veb
&& uplink_seid
!= pf
->mac_seid
) {
6616 for (i
= 0; i
< pf
->hw
.func_caps
.num_vsis
; i
++) {
6617 if (pf
->vsi
[i
] && pf
->vsi
[i
]->seid
== uplink_seid
) {
6623 dev_info(&pf
->pdev
->dev
, "no such uplink_seid %d\n",
6628 if (vsi
->uplink_seid
== pf
->mac_seid
)
6629 veb
= i40e_veb_setup(pf
, 0, pf
->mac_seid
, vsi
->seid
,
6630 vsi
->tc_config
.enabled_tc
);
6631 else if ((vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0)
6632 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
6633 vsi
->tc_config
.enabled_tc
);
6635 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
6636 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
6640 dev_info(&pf
->pdev
->dev
, "couldn't add VEB\n");
6644 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
6645 uplink_seid
= veb
->seid
;
6648 /* get vsi sw struct */
6649 v_idx
= i40e_vsi_mem_alloc(pf
, type
);
6652 vsi
= pf
->vsi
[v_idx
];
6654 vsi
->veb_idx
= (veb
? veb
->idx
: I40E_NO_VEB
);
6656 if (type
== I40E_VSI_MAIN
)
6657 pf
->lan_vsi
= v_idx
;
6658 else if (type
== I40E_VSI_SRIOV
)
6659 vsi
->vf_id
= param1
;
6660 /* assign it some queues */
6661 ret
= i40e_get_lump(pf
, pf
->qp_pile
, vsi
->alloc_queue_pairs
, vsi
->idx
);
6663 dev_info(&pf
->pdev
->dev
, "VSI %d get_lump failed %d\n",
6667 vsi
->base_queue
= ret
;
6669 /* get a VSI from the hardware */
6670 vsi
->uplink_seid
= uplink_seid
;
6671 ret
= i40e_add_vsi(vsi
);
6675 switch (vsi
->type
) {
6676 /* setup the netdev if needed */
6678 case I40E_VSI_VMDQ2
:
6679 ret
= i40e_config_netdev(vsi
);
6682 ret
= register_netdev(vsi
->netdev
);
6685 vsi
->netdev_registered
= true;
6686 netif_carrier_off(vsi
->netdev
);
6690 /* set up vectors and rings if needed */
6691 ret
= i40e_vsi_setup_vectors(vsi
);
6695 ret
= i40e_alloc_rings(vsi
);
6699 /* map all of the rings to the q_vectors */
6700 i40e_vsi_map_rings_to_vectors(vsi
);
6702 i40e_vsi_reset_stats(vsi
);
6706 /* no netdev or rings for the other VSI types */
6713 i40e_vsi_free_q_vectors(vsi
);
6715 if (vsi
->netdev_registered
) {
6716 vsi
->netdev_registered
= false;
6717 unregister_netdev(vsi
->netdev
);
6718 free_netdev(vsi
->netdev
);
6722 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
6724 i40e_vsi_clear(vsi
);
6730 * i40e_veb_get_bw_info - Query VEB BW information
6731 * @veb: the veb to query
6733 * Query the Tx scheduler BW configuration data for given VEB
6735 static int i40e_veb_get_bw_info(struct i40e_veb
*veb
)
6737 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data
;
6738 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data
;
6739 struct i40e_pf
*pf
= veb
->pf
;
6740 struct i40e_hw
*hw
= &pf
->hw
;
6745 ret
= i40e_aq_query_switch_comp_bw_config(hw
, veb
->seid
,
6748 dev_info(&pf
->pdev
->dev
,
6749 "query veb bw config failed, aq_err=%d\n",
6750 hw
->aq
.asq_last_status
);
6754 ret
= i40e_aq_query_switch_comp_ets_config(hw
, veb
->seid
,
6757 dev_info(&pf
->pdev
->dev
,
6758 "query veb bw ets config failed, aq_err=%d\n",
6759 hw
->aq
.asq_last_status
);
6763 veb
->bw_limit
= le16_to_cpu(ets_data
.port_bw_limit
);
6764 veb
->bw_max_quanta
= ets_data
.tc_bw_max
;
6765 veb
->is_abs_credits
= bw_data
.absolute_credits_enable
;
6766 tc_bw_max
= le16_to_cpu(bw_data
.tc_bw_max
[0]) |
6767 (le16_to_cpu(bw_data
.tc_bw_max
[1]) << 16);
6768 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
6769 veb
->bw_tc_share_credits
[i
] = bw_data
.tc_bw_share_credits
[i
];
6770 veb
->bw_tc_limit_credits
[i
] =
6771 le16_to_cpu(bw_data
.tc_bw_limits
[i
]);
6772 veb
->bw_tc_max_quanta
[i
] = ((tc_bw_max
>> (i
*4)) & 0x7);
6780 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
6781 * @pf: board private structure
6783 * On error: returns error code (negative)
6784 * On success: returns vsi index in PF (positive)
6786 static int i40e_veb_mem_alloc(struct i40e_pf
*pf
)
6789 struct i40e_veb
*veb
;
6792 /* Need to protect the allocation of switch elements at the PF level */
6793 mutex_lock(&pf
->switch_mutex
);
6795 /* VEB list may be fragmented if VEB creation/destruction has
6796 * been happening. We can afford to do a quick scan to look
6797 * for any free slots in the list.
6799 * find next empty veb slot, looping back around if necessary
6802 while ((i
< I40E_MAX_VEB
) && (pf
->veb
[i
] != NULL
))
6804 if (i
>= I40E_MAX_VEB
) {
6806 goto err_alloc_veb
; /* out of VEB slots! */
6809 veb
= kzalloc(sizeof(*veb
), GFP_KERNEL
);
6816 veb
->enabled_tc
= 1;
6821 mutex_unlock(&pf
->switch_mutex
);
6826 * i40e_switch_branch_release - Delete a branch of the switch tree
6827 * @branch: where to start deleting
6829 * This uses recursion to find the tips of the branch to be
6830 * removed, deleting until we get back to and can delete this VEB.
6832 static void i40e_switch_branch_release(struct i40e_veb
*branch
)
6834 struct i40e_pf
*pf
= branch
->pf
;
6835 u16 branch_seid
= branch
->seid
;
6836 u16 veb_idx
= branch
->idx
;
6839 /* release any VEBs on this VEB - RECURSION */
6840 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
6843 if (pf
->veb
[i
]->uplink_seid
== branch
->seid
)
6844 i40e_switch_branch_release(pf
->veb
[i
]);
6847 /* Release the VSIs on this VEB, but not the owner VSI.
6849 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
6850 * the VEB itself, so don't use (*branch) after this loop.
6852 for (i
= 0; i
< pf
->hw
.func_caps
.num_vsis
; i
++) {
6855 if (pf
->vsi
[i
]->uplink_seid
== branch_seid
&&
6856 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
6857 i40e_vsi_release(pf
->vsi
[i
]);
6861 /* There's one corner case where the VEB might not have been
6862 * removed, so double check it here and remove it if needed.
6863 * This case happens if the veb was created from the debugfs
6864 * commands and no VSIs were added to it.
6866 if (pf
->veb
[veb_idx
])
6867 i40e_veb_release(pf
->veb
[veb_idx
]);
6871 * i40e_veb_clear - remove veb struct
6872 * @veb: the veb to remove
6874 static void i40e_veb_clear(struct i40e_veb
*veb
)
6880 struct i40e_pf
*pf
= veb
->pf
;
6882 mutex_lock(&pf
->switch_mutex
);
6883 if (pf
->veb
[veb
->idx
] == veb
)
6884 pf
->veb
[veb
->idx
] = NULL
;
6885 mutex_unlock(&pf
->switch_mutex
);
6892 * i40e_veb_release - Delete a VEB and free its resources
6893 * @veb: the VEB being removed
6895 void i40e_veb_release(struct i40e_veb
*veb
)
6897 struct i40e_vsi
*vsi
= NULL
;
6903 /* find the remaining VSI and check for extras */
6904 for (i
= 0; i
< pf
->hw
.func_caps
.num_vsis
; i
++) {
6905 if (pf
->vsi
[i
] && pf
->vsi
[i
]->uplink_seid
== veb
->seid
) {
6911 dev_info(&pf
->pdev
->dev
,
6912 "can't remove VEB %d with %d VSIs left\n",
6917 /* move the remaining VSI to uplink veb */
6918 vsi
->flags
&= ~I40E_VSI_FLAG_VEB_OWNER
;
6919 if (veb
->uplink_seid
) {
6920 vsi
->uplink_seid
= veb
->uplink_seid
;
6921 if (veb
->uplink_seid
== pf
->mac_seid
)
6922 vsi
->veb_idx
= I40E_NO_VEB
;
6924 vsi
->veb_idx
= veb
->veb_idx
;
6927 vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
6928 vsi
->veb_idx
= pf
->vsi
[pf
->lan_vsi
]->veb_idx
;
6931 i40e_aq_delete_element(&pf
->hw
, veb
->seid
, NULL
);
6932 i40e_veb_clear(veb
);
6938 * i40e_add_veb - create the VEB in the switch
6939 * @veb: the VEB to be instantiated
6940 * @vsi: the controlling VSI
6942 static int i40e_add_veb(struct i40e_veb
*veb
, struct i40e_vsi
*vsi
)
6944 bool is_default
= false;
6945 bool is_cloud
= false;
6948 /* get a VEB from the hardware */
6949 ret
= i40e_aq_add_veb(&veb
->pf
->hw
, veb
->uplink_seid
, vsi
->seid
,
6950 veb
->enabled_tc
, is_default
,
6951 is_cloud
, &veb
->seid
, NULL
);
6953 dev_info(&veb
->pf
->pdev
->dev
,
6954 "couldn't add VEB, err %d, aq_err %d\n",
6955 ret
, veb
->pf
->hw
.aq
.asq_last_status
);
6959 /* get statistics counter */
6960 ret
= i40e_aq_get_veb_parameters(&veb
->pf
->hw
, veb
->seid
, NULL
, NULL
,
6961 &veb
->stats_idx
, NULL
, NULL
, NULL
);
6963 dev_info(&veb
->pf
->pdev
->dev
,
6964 "couldn't get VEB statistics idx, err %d, aq_err %d\n",
6965 ret
, veb
->pf
->hw
.aq
.asq_last_status
);
6968 ret
= i40e_veb_get_bw_info(veb
);
6970 dev_info(&veb
->pf
->pdev
->dev
,
6971 "couldn't get VEB bw info, err %d, aq_err %d\n",
6972 ret
, veb
->pf
->hw
.aq
.asq_last_status
);
6973 i40e_aq_delete_element(&veb
->pf
->hw
, veb
->seid
, NULL
);
6977 vsi
->uplink_seid
= veb
->seid
;
6978 vsi
->veb_idx
= veb
->idx
;
6979 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
6985 * i40e_veb_setup - Set up a VEB
6986 * @pf: board private structure
6987 * @flags: VEB setup flags
6988 * @uplink_seid: the switch element to link to
6989 * @vsi_seid: the initial VSI seid
6990 * @enabled_tc: Enabled TC bit-map
6992 * This allocates the sw VEB structure and links it into the switch
6993 * It is possible and legal for this to be a duplicate of an already
6994 * existing VEB. It is also possible for both uplink and vsi seids
6995 * to be zero, in order to create a floating VEB.
6997 * Returns pointer to the successfully allocated VEB sw struct on
6998 * success, otherwise returns NULL on failure.
7000 struct i40e_veb
*i40e_veb_setup(struct i40e_pf
*pf
, u16 flags
,
7001 u16 uplink_seid
, u16 vsi_seid
,
7004 struct i40e_veb
*veb
, *uplink_veb
= NULL
;
7005 int vsi_idx
, veb_idx
;
7008 /* if one seid is 0, the other must be 0 to create a floating relay */
7009 if ((uplink_seid
== 0 || vsi_seid
== 0) &&
7010 (uplink_seid
+ vsi_seid
!= 0)) {
7011 dev_info(&pf
->pdev
->dev
,
7012 "one, not both seid's are 0: uplink=%d vsi=%d\n",
7013 uplink_seid
, vsi_seid
);
7017 /* make sure there is such a vsi and uplink */
7018 for (vsi_idx
= 0; vsi_idx
< pf
->hw
.func_caps
.num_vsis
; vsi_idx
++)
7019 if (pf
->vsi
[vsi_idx
] && pf
->vsi
[vsi_idx
]->seid
== vsi_seid
)
7021 if (vsi_idx
>= pf
->hw
.func_caps
.num_vsis
&& vsi_seid
!= 0) {
7022 dev_info(&pf
->pdev
->dev
, "vsi seid %d not found\n",
7027 if (uplink_seid
&& uplink_seid
!= pf
->mac_seid
) {
7028 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
7029 if (pf
->veb
[veb_idx
] &&
7030 pf
->veb
[veb_idx
]->seid
== uplink_seid
) {
7031 uplink_veb
= pf
->veb
[veb_idx
];
7036 dev_info(&pf
->pdev
->dev
,
7037 "uplink seid %d not found\n", uplink_seid
);
7042 /* get veb sw struct */
7043 veb_idx
= i40e_veb_mem_alloc(pf
);
7046 veb
= pf
->veb
[veb_idx
];
7048 veb
->uplink_seid
= uplink_seid
;
7049 veb
->veb_idx
= (uplink_veb
? uplink_veb
->idx
: I40E_NO_VEB
);
7050 veb
->enabled_tc
= (enabled_tc
? enabled_tc
: 0x1);
7052 /* create the VEB in the switch */
7053 ret
= i40e_add_veb(veb
, pf
->vsi
[vsi_idx
]);
7060 i40e_veb_clear(veb
);
7066 * i40e_setup_pf_switch_element - set pf vars based on switch type
7067 * @pf: board private structure
7068 * @ele: element we are building info from
7069 * @num_reported: total number of elements
7070 * @printconfig: should we print the contents
7072 * helper function to assist in extracting a few useful SEID values.
7074 static void i40e_setup_pf_switch_element(struct i40e_pf
*pf
,
7075 struct i40e_aqc_switch_config_element_resp
*ele
,
7076 u16 num_reported
, bool printconfig
)
7078 u16 downlink_seid
= le16_to_cpu(ele
->downlink_seid
);
7079 u16 uplink_seid
= le16_to_cpu(ele
->uplink_seid
);
7080 u8 element_type
= ele
->element_type
;
7081 u16 seid
= le16_to_cpu(ele
->seid
);
7084 dev_info(&pf
->pdev
->dev
,
7085 "type=%d seid=%d uplink=%d downlink=%d\n",
7086 element_type
, seid
, uplink_seid
, downlink_seid
);
7088 switch (element_type
) {
7089 case I40E_SWITCH_ELEMENT_TYPE_MAC
:
7090 pf
->mac_seid
= seid
;
7092 case I40E_SWITCH_ELEMENT_TYPE_VEB
:
7094 if (uplink_seid
!= pf
->mac_seid
)
7096 if (pf
->lan_veb
== I40E_NO_VEB
) {
7099 /* find existing or else empty VEB */
7100 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
7101 if (pf
->veb
[v
] && (pf
->veb
[v
]->seid
== seid
)) {
7106 if (pf
->lan_veb
== I40E_NO_VEB
) {
7107 v
= i40e_veb_mem_alloc(pf
);
7114 pf
->veb
[pf
->lan_veb
]->seid
= seid
;
7115 pf
->veb
[pf
->lan_veb
]->uplink_seid
= pf
->mac_seid
;
7116 pf
->veb
[pf
->lan_veb
]->pf
= pf
;
7117 pf
->veb
[pf
->lan_veb
]->veb_idx
= I40E_NO_VEB
;
7119 case I40E_SWITCH_ELEMENT_TYPE_VSI
:
7120 if (num_reported
!= 1)
7122 /* This is immediately after a reset so we can assume this is
7125 pf
->mac_seid
= uplink_seid
;
7126 pf
->pf_seid
= downlink_seid
;
7127 pf
->main_vsi_seid
= seid
;
7129 dev_info(&pf
->pdev
->dev
,
7130 "pf_seid=%d main_vsi_seid=%d\n",
7131 pf
->pf_seid
, pf
->main_vsi_seid
);
7133 case I40E_SWITCH_ELEMENT_TYPE_PF
:
7134 case I40E_SWITCH_ELEMENT_TYPE_VF
:
7135 case I40E_SWITCH_ELEMENT_TYPE_EMP
:
7136 case I40E_SWITCH_ELEMENT_TYPE_BMC
:
7137 case I40E_SWITCH_ELEMENT_TYPE_PE
:
7138 case I40E_SWITCH_ELEMENT_TYPE_PA
:
7139 /* ignore these for now */
7142 dev_info(&pf
->pdev
->dev
, "unknown element type=%d seid=%d\n",
7143 element_type
, seid
);
7149 * i40e_fetch_switch_configuration - Get switch config from firmware
7150 * @pf: board private structure
7151 * @printconfig: should we print the contents
7153 * Get the current switch configuration from the device and
7154 * extract a few useful SEID values.
7156 int i40e_fetch_switch_configuration(struct i40e_pf
*pf
, bool printconfig
)
7158 struct i40e_aqc_get_switch_config_resp
*sw_config
;
7164 aq_buf
= kzalloc(I40E_AQ_LARGE_BUF
, GFP_KERNEL
);
7168 sw_config
= (struct i40e_aqc_get_switch_config_resp
*)aq_buf
;
7170 u16 num_reported
, num_total
;
7172 ret
= i40e_aq_get_switch_config(&pf
->hw
, sw_config
,
7176 dev_info(&pf
->pdev
->dev
,
7177 "get switch config failed %d aq_err=%x\n",
7178 ret
, pf
->hw
.aq
.asq_last_status
);
7183 num_reported
= le16_to_cpu(sw_config
->header
.num_reported
);
7184 num_total
= le16_to_cpu(sw_config
->header
.num_total
);
7187 dev_info(&pf
->pdev
->dev
,
7188 "header: %d reported %d total\n",
7189 num_reported
, num_total
);
7192 int sz
= sizeof(*sw_config
) * num_reported
;
7194 kfree(pf
->sw_config
);
7195 pf
->sw_config
= kzalloc(sz
, GFP_KERNEL
);
7197 memcpy(pf
->sw_config
, sw_config
, sz
);
7200 for (i
= 0; i
< num_reported
; i
++) {
7201 struct i40e_aqc_switch_config_element_resp
*ele
=
7202 &sw_config
->element
[i
];
7204 i40e_setup_pf_switch_element(pf
, ele
, num_reported
,
7207 } while (next_seid
!= 0);
7214 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
7215 * @pf: board private structure
7216 * @reinit: if the Main VSI needs to re-initialized.
7218 * Returns 0 on success, negative value on failure
7220 static int i40e_setup_pf_switch(struct i40e_pf
*pf
, bool reinit
)
7222 u32 rxfc
= 0, txfc
= 0, rxfc_reg
;
7225 /* find out what's out there already */
7226 ret
= i40e_fetch_switch_configuration(pf
, false);
7228 dev_info(&pf
->pdev
->dev
,
7229 "couldn't fetch switch config, err %d, aq_err %d\n",
7230 ret
, pf
->hw
.aq
.asq_last_status
);
7233 i40e_pf_reset_stats(pf
);
7235 /* fdir VSI must happen first to be sure it gets queue 0, but only
7236 * if there is enough room for the fdir VSI
7238 if (pf
->num_lan_qps
> 1)
7239 i40e_fdir_setup(pf
);
7241 /* first time setup */
7242 if (pf
->lan_vsi
== I40E_NO_VSI
|| reinit
) {
7243 struct i40e_vsi
*vsi
= NULL
;
7246 /* Set up the PF VSI associated with the PF's main VSI
7247 * that is already in the HW switch
7249 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
7250 uplink_seid
= pf
->veb
[pf
->lan_veb
]->seid
;
7252 uplink_seid
= pf
->mac_seid
;
7253 if (pf
->lan_vsi
== I40E_NO_VSI
)
7254 vsi
= i40e_vsi_setup(pf
, I40E_VSI_MAIN
, uplink_seid
, 0);
7256 vsi
= i40e_vsi_reinit_setup(pf
->vsi
[pf
->lan_vsi
]);
7258 dev_info(&pf
->pdev
->dev
, "setup of MAIN VSI failed\n");
7259 i40e_fdir_teardown(pf
);
7263 /* force a reset of TC and queue layout configurations */
7264 u8 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
7265 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
7266 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
7267 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
7269 i40e_vlan_stripping_disable(pf
->vsi
[pf
->lan_vsi
]);
7271 /* Setup static PF queue filter control settings */
7272 ret
= i40e_setup_pf_filter_control(pf
);
7274 dev_info(&pf
->pdev
->dev
, "setup_pf_filter_control failed: %d\n",
7276 /* Failure here should not stop continuing other steps */
7279 /* enable RSS in the HW, even for only one queue, as the stack can use
7282 if ((pf
->flags
& I40E_FLAG_RSS_ENABLED
))
7283 i40e_config_rss(pf
);
7285 /* fill in link information and enable LSE reporting */
7286 i40e_aq_get_link_info(&pf
->hw
, true, NULL
, NULL
);
7287 i40e_link_event(pf
);
7289 /* Initialize user-specific link properties */
7290 pf
->fc_autoneg_status
= ((pf
->hw
.phy
.link_info
.an_info
&
7291 I40E_AQ_AN_COMPLETED
) ? true : false);
7292 /* requested_mode is set in probe or by ethtool */
7293 if (!pf
->fc_autoneg_status
)
7296 if ((pf
->hw
.phy
.link_info
.an_info
& I40E_AQ_LINK_PAUSE_TX
) &&
7297 (pf
->hw
.phy
.link_info
.an_info
& I40E_AQ_LINK_PAUSE_RX
))
7298 pf
->hw
.fc
.current_mode
= I40E_FC_FULL
;
7299 else if (pf
->hw
.phy
.link_info
.an_info
& I40E_AQ_LINK_PAUSE_TX
)
7300 pf
->hw
.fc
.current_mode
= I40E_FC_TX_PAUSE
;
7301 else if (pf
->hw
.phy
.link_info
.an_info
& I40E_AQ_LINK_PAUSE_RX
)
7302 pf
->hw
.fc
.current_mode
= I40E_FC_RX_PAUSE
;
7304 pf
->hw
.fc
.current_mode
= I40E_FC_NONE
;
7306 /* sync the flow control settings with the auto-neg values */
7307 switch (pf
->hw
.fc
.current_mode
) {
7312 case I40E_FC_TX_PAUSE
:
7316 case I40E_FC_RX_PAUSE
:
7321 case I40E_FC_DEFAULT
:
7328 /* no default case, we have to handle all possibilities here */
7331 wr32(&pf
->hw
, I40E_PRTDCB_FCCFG
, txfc
<< I40E_PRTDCB_FCCFG_TFCE_SHIFT
);
7333 rxfc_reg
= rd32(&pf
->hw
, I40E_PRTDCB_MFLCN
) &
7334 ~I40E_PRTDCB_MFLCN_RFCE_MASK
;
7335 rxfc_reg
|= (rxfc
<< I40E_PRTDCB_MFLCN_RFCE_SHIFT
);
7337 wr32(&pf
->hw
, I40E_PRTDCB_MFLCN
, rxfc_reg
);
7342 /* disable L2 flow control, user can turn it on if they wish */
7343 wr32(&pf
->hw
, I40E_PRTDCB_FCCFG
, 0);
7344 wr32(&pf
->hw
, I40E_PRTDCB_MFLCN
, rd32(&pf
->hw
, I40E_PRTDCB_MFLCN
) &
7345 ~I40E_PRTDCB_MFLCN_RFCE_MASK
);
7354 * i40e_set_rss_size - helper to set rss_size
7355 * @pf: board private structure
7356 * @queues_left: how many queues
7358 static u16
i40e_set_rss_size(struct i40e_pf
*pf
, int queues_left
)
7362 num_tc0
= min_t(int, queues_left
, pf
->rss_size_max
);
7363 num_tc0
= min_t(int, num_tc0
, num_online_cpus());
7364 num_tc0
= rounddown_pow_of_two(num_tc0
);
7370 * i40e_determine_queue_usage - Work out queue distribution
7371 * @pf: board private structure
7373 static void i40e_determine_queue_usage(struct i40e_pf
*pf
)
7378 pf
->num_lan_qps
= 0;
7379 pf
->num_tc_qps
= rounddown_pow_of_two(pf
->num_tc_qps
);
7380 accum_tc_size
= (I40E_MAX_TRAFFIC_CLASS
- 1) * pf
->num_tc_qps
;
7382 /* Find the max queues to be put into basic use. We'll always be
7383 * using TC0, whether or not DCB is running, and TC0 will get the
7386 queues_left
= pf
->hw
.func_caps
.num_tx_qp
;
7388 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
) ||
7389 !(pf
->flags
& (I40E_FLAG_RSS_ENABLED
|
7390 I40E_FLAG_FDIR_ENABLED
| I40E_FLAG_DCB_ENABLED
)) ||
7391 (queues_left
== 1)) {
7393 /* one qp for PF, no queues for anything else */
7395 pf
->rss_size
= pf
->num_lan_qps
= 1;
7397 /* make sure all the fancies are disabled */
7398 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
7399 I40E_FLAG_FDIR_ENABLED
|
7400 I40E_FLAG_FDIR_ATR_ENABLED
|
7401 I40E_FLAG_DCB_ENABLED
|
7402 I40E_FLAG_SRIOV_ENABLED
|
7403 I40E_FLAG_VMDQ_ENABLED
);
7405 } else if (pf
->flags
& I40E_FLAG_RSS_ENABLED
&&
7406 !(pf
->flags
& I40E_FLAG_FDIR_ENABLED
) &&
7407 !(pf
->flags
& I40E_FLAG_DCB_ENABLED
)) {
7409 pf
->rss_size
= i40e_set_rss_size(pf
, queues_left
);
7411 queues_left
-= pf
->rss_size
;
7412 pf
->num_lan_qps
= pf
->rss_size_max
;
7414 } else if (pf
->flags
& I40E_FLAG_RSS_ENABLED
&&
7415 !(pf
->flags
& I40E_FLAG_FDIR_ENABLED
) &&
7416 (pf
->flags
& I40E_FLAG_DCB_ENABLED
)) {
7418 /* save num_tc_qps queues for TCs 1 thru 7 and the rest
7419 * are set up for RSS in TC0
7421 queues_left
-= accum_tc_size
;
7423 pf
->rss_size
= i40e_set_rss_size(pf
, queues_left
);
7425 queues_left
-= pf
->rss_size
;
7426 if (queues_left
< 0) {
7427 dev_info(&pf
->pdev
->dev
, "not enough queues for DCB\n");
7431 pf
->num_lan_qps
= pf
->rss_size_max
+ accum_tc_size
;
7433 } else if (pf
->flags
& I40E_FLAG_RSS_ENABLED
&&
7434 (pf
->flags
& I40E_FLAG_FDIR_ENABLED
) &&
7435 !(pf
->flags
& I40E_FLAG_DCB_ENABLED
)) {
7437 queues_left
-= 1; /* save 1 queue for FD */
7439 pf
->rss_size
= i40e_set_rss_size(pf
, queues_left
);
7441 queues_left
-= pf
->rss_size
;
7442 if (queues_left
< 0) {
7443 dev_info(&pf
->pdev
->dev
, "not enough queues for Flow Director\n");
7447 pf
->num_lan_qps
= pf
->rss_size_max
;
7449 } else if (pf
->flags
& I40E_FLAG_RSS_ENABLED
&&
7450 (pf
->flags
& I40E_FLAG_FDIR_ENABLED
) &&
7451 (pf
->flags
& I40E_FLAG_DCB_ENABLED
)) {
7453 /* save 1 queue for TCs 1 thru 7,
7454 * 1 queue for flow director,
7455 * and the rest are set up for RSS in TC0
7458 queues_left
-= accum_tc_size
;
7460 pf
->rss_size
= i40e_set_rss_size(pf
, queues_left
);
7461 queues_left
-= pf
->rss_size
;
7462 if (queues_left
< 0) {
7463 dev_info(&pf
->pdev
->dev
, "not enough queues for DCB and Flow Director\n");
7467 pf
->num_lan_qps
= pf
->rss_size_max
+ accum_tc_size
;
7470 dev_info(&pf
->pdev
->dev
,
7471 "Invalid configuration, flags=0x%08llx\n", pf
->flags
);
7475 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
7476 pf
->num_vf_qps
&& pf
->num_req_vfs
&& queues_left
) {
7477 pf
->num_req_vfs
= min_t(int, pf
->num_req_vfs
, (queues_left
/
7479 queues_left
-= (pf
->num_req_vfs
* pf
->num_vf_qps
);
7482 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
7483 pf
->num_vmdq_vsis
&& pf
->num_vmdq_qps
&& queues_left
) {
7484 pf
->num_vmdq_vsis
= min_t(int, pf
->num_vmdq_vsis
,
7485 (queues_left
/ pf
->num_vmdq_qps
));
7486 queues_left
-= (pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
);
7489 pf
->queues_left
= queues_left
;
7494 * i40e_setup_pf_filter_control - Setup PF static filter control
7495 * @pf: PF to be setup
7497 * i40e_setup_pf_filter_control sets up a pf's initial filter control
7498 * settings. If PE/FCoE are enabled then it will also set the per PF
7499 * based filter sizes required for them. It also enables Flow director,
7500 * ethertype and macvlan type filter settings for the pf.
7502 * Returns 0 on success, negative on failure
7504 static int i40e_setup_pf_filter_control(struct i40e_pf
*pf
)
7506 struct i40e_filter_control_settings
*settings
= &pf
->filter_settings
;
7508 settings
->hash_lut_size
= I40E_HASH_LUT_SIZE_128
;
7510 /* Flow Director is enabled */
7511 if (pf
->flags
& (I40E_FLAG_FDIR_ENABLED
| I40E_FLAG_FDIR_ATR_ENABLED
))
7512 settings
->enable_fdir
= true;
7514 /* Ethtype and MACVLAN filters enabled for PF */
7515 settings
->enable_ethtype
= true;
7516 settings
->enable_macvlan
= true;
7518 if (i40e_set_filter_control(&pf
->hw
, settings
))
7525 * i40e_probe - Device initialization routine
7526 * @pdev: PCI device information struct
7527 * @ent: entry in i40e_pci_tbl
7529 * i40e_probe initializes a pf identified by a pci_dev structure.
7530 * The OS initialization, configuring of the pf private structure,
7531 * and a hardware reset occur.
7533 * Returns 0 on success, negative on failure
7535 static int i40e_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
7537 struct i40e_driver_version dv
;
7540 static u16 pfs_found
;
7545 err
= pci_enable_device_mem(pdev
);
7549 /* set up for high or low dma */
7550 if (!dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(64))) {
7551 /* coherent mask for the same size will always succeed if
7554 dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(64));
7555 } else if (!dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32))) {
7556 dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(32));
7558 dev_err(&pdev
->dev
, "DMA configuration failed: %d\n", err
);
7563 /* set up pci connections */
7564 err
= pci_request_selected_regions(pdev
, pci_select_bars(pdev
,
7565 IORESOURCE_MEM
), i40e_driver_name
);
7567 dev_info(&pdev
->dev
,
7568 "pci_request_selected_regions failed %d\n", err
);
7572 pci_enable_pcie_error_reporting(pdev
);
7573 pci_set_master(pdev
);
7575 /* Now that we have a PCI connection, we need to do the
7576 * low level device setup. This is primarily setting up
7577 * the Admin Queue structures and then querying for the
7578 * device's current profile information.
7580 pf
= kzalloc(sizeof(*pf
), GFP_KERNEL
);
7587 set_bit(__I40E_DOWN
, &pf
->state
);
7591 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
7592 pci_resource_len(pdev
, 0));
7595 dev_info(&pdev
->dev
, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
7596 (unsigned int)pci_resource_start(pdev
, 0),
7597 (unsigned int)pci_resource_len(pdev
, 0), err
);
7600 hw
->vendor_id
= pdev
->vendor
;
7601 hw
->device_id
= pdev
->device
;
7602 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
7603 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
7604 hw
->subsystem_device_id
= pdev
->subsystem_device
;
7605 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
7606 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
7607 pf
->instance
= pfs_found
;
7609 /* do a special CORER for clearing PXE mode once at init */
7610 if (hw
->revision_id
== 0 &&
7611 (rd32(hw
, I40E_GLLAN_RCTL_0
) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK
)) {
7612 wr32(hw
, I40E_GLGEN_RTRIG
, I40E_GLGEN_RTRIG_CORER_MASK
);
7617 i40e_clear_pxe_mode(hw
);
7620 /* Reset here to make sure all is clean and to define PF 'n' */
7621 err
= i40e_pf_reset(hw
);
7623 dev_info(&pdev
->dev
, "Initial pf_reset failed: %d\n", err
);
7628 hw
->aq
.num_arq_entries
= I40E_AQ_LEN
;
7629 hw
->aq
.num_asq_entries
= I40E_AQ_LEN
;
7630 hw
->aq
.arq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
7631 hw
->aq
.asq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
7632 pf
->adminq_work_limit
= I40E_AQ_WORK_LIMIT
;
7633 snprintf(pf
->misc_int_name
, sizeof(pf
->misc_int_name
) - 1,
7635 dev_driver_string(&pf
->pdev
->dev
), pf
->hw
.pf_id
);
7637 err
= i40e_init_shared_code(hw
);
7639 dev_info(&pdev
->dev
, "init_shared_code failed: %d\n", err
);
7643 /* set up a default setting for link flow control */
7644 pf
->hw
.fc
.requested_mode
= I40E_FC_NONE
;
7646 err
= i40e_init_adminq(hw
);
7647 dev_info(&pdev
->dev
, "%s\n", i40e_fw_version_str(hw
));
7648 if (((hw
->nvm
.version
& I40E_NVM_VERSION_HI_MASK
)
7649 >> I40E_NVM_VERSION_HI_SHIFT
) != I40E_CURRENT_NVM_VERSION_HI
) {
7650 dev_info(&pdev
->dev
,
7651 "warning: NVM version not supported, supported version: %02x.%02x\n",
7652 I40E_CURRENT_NVM_VERSION_HI
,
7653 I40E_CURRENT_NVM_VERSION_LO
);
7656 dev_info(&pdev
->dev
,
7657 "init_adminq failed: %d expecting API %02x.%02x\n",
7659 I40E_FW_API_VERSION_MAJOR
, I40E_FW_API_VERSION_MINOR
);
7663 i40e_clear_pxe_mode(hw
);
7664 err
= i40e_get_capabilities(pf
);
7666 goto err_adminq_setup
;
7668 err
= i40e_sw_init(pf
);
7670 dev_info(&pdev
->dev
, "sw_init failed: %d\n", err
);
7674 err
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
7675 hw
->func_caps
.num_rx_qp
,
7676 pf
->fcoe_hmc_cntx_num
, pf
->fcoe_hmc_filt_num
);
7678 dev_info(&pdev
->dev
, "init_lan_hmc failed: %d\n", err
);
7679 goto err_init_lan_hmc
;
7682 err
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
7684 dev_info(&pdev
->dev
, "configure_lan_hmc failed: %d\n", err
);
7686 goto err_configure_lan_hmc
;
7689 i40e_get_mac_addr(hw
, hw
->mac
.addr
);
7690 if (!is_valid_ether_addr(hw
->mac
.addr
)) {
7691 dev_info(&pdev
->dev
, "invalid MAC address %pM\n", hw
->mac
.addr
);
7695 dev_info(&pdev
->dev
, "MAC address: %pM\n", hw
->mac
.addr
);
7696 memcpy(hw
->mac
.perm_addr
, hw
->mac
.addr
, ETH_ALEN
);
7698 pci_set_drvdata(pdev
, pf
);
7699 pci_save_state(pdev
);
7701 /* set up periodic task facility */
7702 setup_timer(&pf
->service_timer
, i40e_service_timer
, (unsigned long)pf
);
7703 pf
->service_timer_period
= HZ
;
7705 INIT_WORK(&pf
->service_task
, i40e_service_task
);
7706 clear_bit(__I40E_SERVICE_SCHED
, &pf
->state
);
7707 pf
->flags
|= I40E_FLAG_NEED_LINK_UPDATE
;
7708 pf
->link_check_timeout
= jiffies
;
7710 /* WoL defaults to disabled */
7712 device_set_wakeup_enable(&pf
->pdev
->dev
, pf
->wol_en
);
7714 /* set up the main switch operations */
7715 i40e_determine_queue_usage(pf
);
7716 i40e_init_interrupt_scheme(pf
);
7718 /* Set up the *vsi struct based on the number of VSIs in the HW,
7719 * and set up our local tracking of the MAIN PF vsi.
7721 len
= sizeof(struct i40e_vsi
*) * pf
->hw
.func_caps
.num_vsis
;
7722 pf
->vsi
= kzalloc(len
, GFP_KERNEL
);
7725 goto err_switch_setup
;
7728 err
= i40e_setup_pf_switch(pf
, false);
7730 dev_info(&pdev
->dev
, "setup_pf_switch failed: %d\n", err
);
7734 /* The main driver is (mostly) up and happy. We need to set this state
7735 * before setting up the misc vector or we get a race and the vector
7736 * ends up disabled forever.
7738 clear_bit(__I40E_DOWN
, &pf
->state
);
7740 /* In case of MSIX we are going to setup the misc vector right here
7741 * to handle admin queue events etc. In case of legacy and MSI
7742 * the misc functionality and queue processing is combined in
7743 * the same vector and that gets setup at open.
7745 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
7746 err
= i40e_setup_misc_vector(pf
);
7748 dev_info(&pdev
->dev
,
7749 "setup of misc vector failed: %d\n", err
);
7754 /* prep for VF support */
7755 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
7756 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)) {
7759 /* disable link interrupts for VFs */
7760 val
= rd32(hw
, I40E_PFGEN_PORTMDIO_NUM
);
7761 val
&= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK
;
7762 wr32(hw
, I40E_PFGEN_PORTMDIO_NUM
, val
);
7768 i40e_dbg_pf_init(pf
);
7770 /* tell the firmware that we're starting */
7771 dv
.major_version
= DRV_VERSION_MAJOR
;
7772 dv
.minor_version
= DRV_VERSION_MINOR
;
7773 dv
.build_version
= DRV_VERSION_BUILD
;
7774 dv
.subbuild_version
= 0;
7775 i40e_aq_send_driver_version(&pf
->hw
, &dv
, NULL
);
7777 /* since everything's happy, start the service_task timer */
7778 mod_timer(&pf
->service_timer
,
7779 round_jiffies(jiffies
+ pf
->service_timer_period
));
7781 /* Get the negotiated link width and speed from PCI config space */
7782 pcie_capability_read_word(pf
->pdev
, PCI_EXP_LNKSTA
, &link_status
);
7784 i40e_set_pci_config_data(hw
, link_status
);
7786 dev_info(&pdev
->dev
, "PCI Express: %s %s\n",
7787 (hw
->bus
.speed
== i40e_bus_speed_8000
? "Speed 8.0GT/s" :
7788 hw
->bus
.speed
== i40e_bus_speed_5000
? "Speed 5.0GT/s" :
7789 hw
->bus
.speed
== i40e_bus_speed_2500
? "Speed 2.5GT/s" :
7791 (hw
->bus
.width
== i40e_bus_width_pcie_x8
? "Width x8" :
7792 hw
->bus
.width
== i40e_bus_width_pcie_x4
? "Width x4" :
7793 hw
->bus
.width
== i40e_bus_width_pcie_x2
? "Width x2" :
7794 hw
->bus
.width
== i40e_bus_width_pcie_x1
? "Width x1" :
7797 if (hw
->bus
.width
< i40e_bus_width_pcie_x8
||
7798 hw
->bus
.speed
< i40e_bus_speed_8000
) {
7799 dev_warn(&pdev
->dev
, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
7800 dev_warn(&pdev
->dev
, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
7805 /* Unwind what we've done if something failed in the setup */
7807 set_bit(__I40E_DOWN
, &pf
->state
);
7808 i40e_clear_interrupt_scheme(pf
);
7811 i40e_reset_interrupt_capability(pf
);
7812 del_timer_sync(&pf
->service_timer
);
7814 err_configure_lan_hmc
:
7815 (void)i40e_shutdown_lan_hmc(hw
);
7818 kfree(pf
->irq_pile
);
7821 (void)i40e_shutdown_adminq(hw
);
7823 iounmap(hw
->hw_addr
);
7827 pci_disable_pcie_error_reporting(pdev
);
7828 pci_release_selected_regions(pdev
,
7829 pci_select_bars(pdev
, IORESOURCE_MEM
));
7832 pci_disable_device(pdev
);
7837 * i40e_remove - Device removal routine
7838 * @pdev: PCI device information struct
7840 * i40e_remove is called by the PCI subsystem to alert the driver
7841 * that is should release a PCI device. This could be caused by a
7842 * Hot-Plug event, or because the driver is going to be removed from
7845 static void i40e_remove(struct pci_dev
*pdev
)
7847 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
7848 i40e_status ret_code
;
7852 i40e_dbg_pf_exit(pf
);
7856 if (pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) {
7858 pf
->flags
&= ~I40E_FLAG_SRIOV_ENABLED
;
7861 /* no more scheduling of any task */
7862 set_bit(__I40E_DOWN
, &pf
->state
);
7863 del_timer_sync(&pf
->service_timer
);
7864 cancel_work_sync(&pf
->service_task
);
7866 i40e_fdir_teardown(pf
);
7868 /* If there is a switch structure or any orphans, remove them.
7869 * This will leave only the PF's VSI remaining.
7871 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
7875 if (pf
->veb
[i
]->uplink_seid
== pf
->mac_seid
||
7876 pf
->veb
[i
]->uplink_seid
== 0)
7877 i40e_switch_branch_release(pf
->veb
[i
]);
7880 /* Now we can shutdown the PF's VSI, just before we kill
7883 if (pf
->vsi
[pf
->lan_vsi
])
7884 i40e_vsi_release(pf
->vsi
[pf
->lan_vsi
]);
7886 i40e_stop_misc_vector(pf
);
7887 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
7888 synchronize_irq(pf
->msix_entries
[0].vector
);
7889 free_irq(pf
->msix_entries
[0].vector
, pf
);
7892 /* shutdown and destroy the HMC */
7893 ret_code
= i40e_shutdown_lan_hmc(&pf
->hw
);
7895 dev_warn(&pdev
->dev
,
7896 "Failed to destroy the HMC resources: %d\n", ret_code
);
7898 /* shutdown the adminq */
7899 ret_code
= i40e_shutdown_adminq(&pf
->hw
);
7901 dev_warn(&pdev
->dev
,
7902 "Failed to destroy the Admin Queue resources: %d\n",
7905 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
7906 i40e_clear_interrupt_scheme(pf
);
7907 for (i
= 0; i
< pf
->hw
.func_caps
.num_vsis
; i
++) {
7909 i40e_vsi_clear_rings(pf
->vsi
[i
]);
7910 i40e_vsi_clear(pf
->vsi
[i
]);
7915 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
7921 kfree(pf
->irq_pile
);
7922 kfree(pf
->sw_config
);
7925 /* force a PF reset to clean anything leftover */
7926 reg
= rd32(&pf
->hw
, I40E_PFGEN_CTRL
);
7927 wr32(&pf
->hw
, I40E_PFGEN_CTRL
, (reg
| I40E_PFGEN_CTRL_PFSWR_MASK
));
7928 i40e_flush(&pf
->hw
);
7930 iounmap(pf
->hw
.hw_addr
);
7932 pci_release_selected_regions(pdev
,
7933 pci_select_bars(pdev
, IORESOURCE_MEM
));
7935 pci_disable_pcie_error_reporting(pdev
);
7936 pci_disable_device(pdev
);
7940 * i40e_pci_error_detected - warning that something funky happened in PCI land
7941 * @pdev: PCI device information struct
7943 * Called to warn that something happened and the error handling steps
7944 * are in progress. Allows the driver to quiesce things, be ready for
7947 static pci_ers_result_t
i40e_pci_error_detected(struct pci_dev
*pdev
,
7948 enum pci_channel_state error
)
7950 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
7952 dev_info(&pdev
->dev
, "%s: error %d\n", __func__
, error
);
7954 /* shutdown all operations */
7955 if (!test_bit(__I40E_SUSPENDED
, &pf
->state
)) {
7957 i40e_prep_for_reset(pf
);
7961 /* Request a slot reset */
7962 return PCI_ERS_RESULT_NEED_RESET
;
7966 * i40e_pci_error_slot_reset - a PCI slot reset just happened
7967 * @pdev: PCI device information struct
7969 * Called to find if the driver can work with the device now that
7970 * the pci slot has been reset. If a basic connection seems good
7971 * (registers are readable and have sane content) then return a
7972 * happy little PCI_ERS_RESULT_xxx.
7974 static pci_ers_result_t
i40e_pci_error_slot_reset(struct pci_dev
*pdev
)
7976 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
7977 pci_ers_result_t result
;
7981 dev_info(&pdev
->dev
, "%s\n", __func__
);
7982 if (pci_enable_device_mem(pdev
)) {
7983 dev_info(&pdev
->dev
,
7984 "Cannot re-enable PCI device after reset.\n");
7985 result
= PCI_ERS_RESULT_DISCONNECT
;
7987 pci_set_master(pdev
);
7988 pci_restore_state(pdev
);
7989 pci_save_state(pdev
);
7990 pci_wake_from_d3(pdev
, false);
7992 reg
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
7994 result
= PCI_ERS_RESULT_RECOVERED
;
7996 result
= PCI_ERS_RESULT_DISCONNECT
;
7999 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
8001 dev_info(&pdev
->dev
,
8002 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
8004 /* non-fatal, continue */
8011 * i40e_pci_error_resume - restart operations after PCI error recovery
8012 * @pdev: PCI device information struct
8014 * Called to allow the driver to bring things back up after PCI error
8015 * and/or reset recovery has finished.
8017 static void i40e_pci_error_resume(struct pci_dev
*pdev
)
8019 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
8021 dev_info(&pdev
->dev
, "%s\n", __func__
);
8022 if (test_bit(__I40E_SUSPENDED
, &pf
->state
))
8026 i40e_handle_reset_warning(pf
);
8031 * i40e_shutdown - PCI callback for shutting down
8032 * @pdev: PCI device information struct
8034 static void i40e_shutdown(struct pci_dev
*pdev
)
8036 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
8037 struct i40e_hw
*hw
= &pf
->hw
;
8039 set_bit(__I40E_SUSPENDED
, &pf
->state
);
8040 set_bit(__I40E_DOWN
, &pf
->state
);
8042 i40e_prep_for_reset(pf
);
8045 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
8046 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
8048 if (system_state
== SYSTEM_POWER_OFF
) {
8049 pci_wake_from_d3(pdev
, pf
->wol_en
);
8050 pci_set_power_state(pdev
, PCI_D3hot
);
8056 * i40e_suspend - PCI callback for moving to D3
8057 * @pdev: PCI device information struct
8059 static int i40e_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8061 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
8062 struct i40e_hw
*hw
= &pf
->hw
;
8064 set_bit(__I40E_SUSPENDED
, &pf
->state
);
8065 set_bit(__I40E_DOWN
, &pf
->state
);
8067 i40e_prep_for_reset(pf
);
8070 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
8071 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
8073 pci_wake_from_d3(pdev
, pf
->wol_en
);
8074 pci_set_power_state(pdev
, PCI_D3hot
);
8080 * i40e_resume - PCI callback for waking up from D3
8081 * @pdev: PCI device information struct
8083 static int i40e_resume(struct pci_dev
*pdev
)
8085 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
8088 pci_set_power_state(pdev
, PCI_D0
);
8089 pci_restore_state(pdev
);
8090 /* pci_restore_state() clears dev->state_saves, so
8091 * call pci_save_state() again to restore it.
8093 pci_save_state(pdev
);
8095 err
= pci_enable_device_mem(pdev
);
8098 "%s: Cannot enable PCI device from suspend\n",
8102 pci_set_master(pdev
);
8104 /* no wakeup events while running */
8105 pci_wake_from_d3(pdev
, false);
8107 /* handling the reset will rebuild the device state */
8108 if (test_and_clear_bit(__I40E_SUSPENDED
, &pf
->state
)) {
8109 clear_bit(__I40E_DOWN
, &pf
->state
);
8111 i40e_reset_and_rebuild(pf
, false);
8119 static const struct pci_error_handlers i40e_err_handler
= {
8120 .error_detected
= i40e_pci_error_detected
,
8121 .slot_reset
= i40e_pci_error_slot_reset
,
8122 .resume
= i40e_pci_error_resume
,
8125 static struct pci_driver i40e_driver
= {
8126 .name
= i40e_driver_name
,
8127 .id_table
= i40e_pci_tbl
,
8128 .probe
= i40e_probe
,
8129 .remove
= i40e_remove
,
8131 .suspend
= i40e_suspend
,
8132 .resume
= i40e_resume
,
8134 .shutdown
= i40e_shutdown
,
8135 .err_handler
= &i40e_err_handler
,
8136 .sriov_configure
= i40e_pci_sriov_configure
,
8140 * i40e_init_module - Driver registration routine
8142 * i40e_init_module is the first routine called when the driver is
8143 * loaded. All it does is register with the PCI subsystem.
8145 static int __init
i40e_init_module(void)
8147 pr_info("%s: %s - version %s\n", i40e_driver_name
,
8148 i40e_driver_string
, i40e_driver_version_str
);
8149 pr_info("%s: %s\n", i40e_driver_name
, i40e_copyright
);
8151 return pci_register_driver(&i40e_driver
);
8153 module_init(i40e_init_module
);
8156 * i40e_exit_module - Driver exit cleanup routine
8158 * i40e_exit_module is called just before the driver is removed
8161 static void __exit
i40e_exit_module(void)
8163 pci_unregister_driver(&i40e_driver
);
8166 module_exit(i40e_exit_module
);