1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2015 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 ******************************************************************************/
29 #include "i40e_diag.h"
30 #ifdef CONFIG_I40E_VXLAN
31 #include <net/vxlan.h>
34 const char i40e_driver_name
[] = "i40e";
35 static const char i40e_driver_string
[] =
36 "Intel(R) Ethernet Connection XL710 Network Driver";
40 #define DRV_VERSION_MAJOR 1
41 #define DRV_VERSION_MINOR 3
42 #define DRV_VERSION_BUILD 4
43 #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
44 __stringify(DRV_VERSION_MINOR) "." \
45 __stringify(DRV_VERSION_BUILD) DRV_KERN
46 const char i40e_driver_version_str
[] = DRV_VERSION
;
47 static const char i40e_copyright
[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
49 /* a bit of forward declarations */
50 static void i40e_vsi_reinit_locked(struct i40e_vsi
*vsi
);
51 static void i40e_handle_reset_warning(struct i40e_pf
*pf
);
52 static int i40e_add_vsi(struct i40e_vsi
*vsi
);
53 static int i40e_add_veb(struct i40e_veb
*veb
, struct i40e_vsi
*vsi
);
54 static int i40e_setup_pf_switch(struct i40e_pf
*pf
, bool reinit
);
55 static int i40e_setup_misc_vector(struct i40e_pf
*pf
);
56 static void i40e_determine_queue_usage(struct i40e_pf
*pf
);
57 static int i40e_setup_pf_filter_control(struct i40e_pf
*pf
);
58 static void i40e_fdir_sb_setup(struct i40e_pf
*pf
);
59 static int i40e_veb_get_bw_info(struct i40e_veb
*veb
);
61 /* i40e_pci_tbl - PCI Device ID Table
63 * Last entry must be all 0s
65 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
66 * Class, Class Mask, private data (not used) }
68 static const struct pci_device_id i40e_pci_tbl
[] = {
69 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_SFP_XL710
), 0},
70 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QEMU
), 0},
71 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_A
), 0},
72 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_B
), 0},
73 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_KX_C
), 0},
74 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_A
), 0},
75 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_B
), 0},
76 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_QSFP_C
), 0},
77 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_10G_BASE_T
), 0},
78 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_20G_KR2
), 0},
79 /* required last entry */
82 MODULE_DEVICE_TABLE(pci
, i40e_pci_tbl
);
84 #define I40E_MAX_VF_COUNT 128
85 static int debug
= -1;
86 module_param(debug
, int, 0);
87 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
89 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
90 MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
91 MODULE_LICENSE("GPL");
92 MODULE_VERSION(DRV_VERSION
);
95 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
96 * @hw: pointer to the HW structure
97 * @mem: ptr to mem struct to fill out
98 * @size: size of memory requested
99 * @alignment: what to align the allocation to
101 int i40e_allocate_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
,
102 u64 size
, u32 alignment
)
104 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
106 mem
->size
= ALIGN(size
, alignment
);
107 mem
->va
= dma_zalloc_coherent(&pf
->pdev
->dev
, mem
->size
,
108 &mem
->pa
, GFP_KERNEL
);
116 * i40e_free_dma_mem_d - OS specific memory free for shared code
117 * @hw: pointer to the HW structure
118 * @mem: ptr to mem struct to free
120 int i40e_free_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
)
122 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
124 dma_free_coherent(&pf
->pdev
->dev
, mem
->size
, mem
->va
, mem
->pa
);
133 * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
134 * @hw: pointer to the HW structure
135 * @mem: ptr to mem struct to fill out
136 * @size: size of memory requested
138 int i40e_allocate_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
,
142 mem
->va
= kzalloc(size
, GFP_KERNEL
);
151 * i40e_free_virt_mem_d - OS specific memory free for shared code
152 * @hw: pointer to the HW structure
153 * @mem: ptr to mem struct to free
155 int i40e_free_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
)
157 /* it's ok to kfree a NULL pointer */
166 * i40e_get_lump - find a lump of free generic resource
167 * @pf: board private structure
168 * @pile: the pile of resource to search
169 * @needed: the number of items needed
170 * @id: an owner id to stick on the items assigned
172 * Returns the base item index of the lump, or negative for error
174 * The search_hint trick and lack of advanced fit-finding only work
175 * because we're highly likely to have all the same size lump requests.
176 * Linear search time and any fragmentation should be minimal.
178 static int i40e_get_lump(struct i40e_pf
*pf
, struct i40e_lump_tracking
*pile
,
184 if (!pile
|| needed
== 0 || id
>= I40E_PILE_VALID_BIT
) {
185 dev_info(&pf
->pdev
->dev
,
186 "param err: pile=%p needed=%d id=0x%04x\n",
191 /* start the linear search with an imperfect hint */
192 i
= pile
->search_hint
;
193 while (i
< pile
->num_entries
) {
194 /* skip already allocated entries */
195 if (pile
->list
[i
] & I40E_PILE_VALID_BIT
) {
200 /* do we have enough in this lump? */
201 for (j
= 0; (j
< needed
) && ((i
+j
) < pile
->num_entries
); j
++) {
202 if (pile
->list
[i
+j
] & I40E_PILE_VALID_BIT
)
207 /* there was enough, so assign it to the requestor */
208 for (j
= 0; j
< needed
; j
++)
209 pile
->list
[i
+j
] = id
| I40E_PILE_VALID_BIT
;
211 pile
->search_hint
= i
+ j
;
214 /* not enough, so skip over it and continue looking */
223 * i40e_put_lump - return a lump of generic resource
224 * @pile: the pile of resource to search
225 * @index: the base item index
226 * @id: the owner id of the items assigned
228 * Returns the count of items in the lump
230 static int i40e_put_lump(struct i40e_lump_tracking
*pile
, u16 index
, u16 id
)
232 int valid_id
= (id
| I40E_PILE_VALID_BIT
);
236 if (!pile
|| index
>= pile
->num_entries
)
240 i
< pile
->num_entries
&& pile
->list
[i
] == valid_id
;
246 if (count
&& index
< pile
->search_hint
)
247 pile
->search_hint
= index
;
253 * i40e_find_vsi_from_id - searches for the vsi with the given id
254 * @pf - the pf structure to search for the vsi
255 * @id - id of the vsi it is searching for
257 struct i40e_vsi
*i40e_find_vsi_from_id(struct i40e_pf
*pf
, u16 id
)
261 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
262 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->id
== id
))
269 * i40e_service_event_schedule - Schedule the service task to wake up
270 * @pf: board private structure
272 * If not already scheduled, this puts the task into the work queue
274 static void i40e_service_event_schedule(struct i40e_pf
*pf
)
276 if (!test_bit(__I40E_DOWN
, &pf
->state
) &&
277 !test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) &&
278 !test_and_set_bit(__I40E_SERVICE_SCHED
, &pf
->state
))
279 schedule_work(&pf
->service_task
);
283 * i40e_tx_timeout - Respond to a Tx Hang
284 * @netdev: network interface device structure
286 * If any port has noticed a Tx timeout, it is likely that the whole
287 * device is munged, not just the one netdev port, so go for the full
291 void i40e_tx_timeout(struct net_device
*netdev
)
293 static void i40e_tx_timeout(struct net_device
*netdev
)
296 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
297 struct i40e_vsi
*vsi
= np
->vsi
;
298 struct i40e_pf
*pf
= vsi
->back
;
300 pf
->tx_timeout_count
++;
302 if (time_after(jiffies
, (pf
->tx_timeout_last_recovery
+ HZ
*20)))
303 pf
->tx_timeout_recovery_level
= 1;
304 pf
->tx_timeout_last_recovery
= jiffies
;
305 netdev_info(netdev
, "tx_timeout recovery level %d\n",
306 pf
->tx_timeout_recovery_level
);
308 switch (pf
->tx_timeout_recovery_level
) {
310 /* disable and re-enable queues for the VSI */
311 if (in_interrupt()) {
312 set_bit(__I40E_REINIT_REQUESTED
, &pf
->state
);
313 set_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
);
315 i40e_vsi_reinit_locked(vsi
);
319 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
322 set_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
);
325 set_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
);
328 netdev_err(netdev
, "tx_timeout recovery unsuccessful\n");
329 set_bit(__I40E_DOWN_REQUESTED
, &pf
->state
);
330 set_bit(__I40E_DOWN_REQUESTED
, &vsi
->state
);
333 i40e_service_event_schedule(pf
);
334 pf
->tx_timeout_recovery_level
++;
338 * i40e_release_rx_desc - Store the new tail and head values
339 * @rx_ring: ring to bump
340 * @val: new head index
342 static inline void i40e_release_rx_desc(struct i40e_ring
*rx_ring
, u32 val
)
344 rx_ring
->next_to_use
= val
;
346 /* Force memory writes to complete before letting h/w
347 * know there are new descriptors to fetch. (Only
348 * applicable for weak-ordered memory model archs,
352 writel(val
, rx_ring
->tail
);
356 * i40e_get_vsi_stats_struct - Get System Network Statistics
357 * @vsi: the VSI we care about
359 * Returns the address of the device statistics structure.
360 * The statistics are actually updated from the service task.
362 struct rtnl_link_stats64
*i40e_get_vsi_stats_struct(struct i40e_vsi
*vsi
)
364 return &vsi
->net_stats
;
368 * i40e_get_netdev_stats_struct - Get statistics for netdev interface
369 * @netdev: network interface device structure
371 * Returns the address of the device statistics structure.
372 * The statistics are actually updated from the service task.
375 struct rtnl_link_stats64
*i40e_get_netdev_stats_struct(
376 struct net_device
*netdev
,
377 struct rtnl_link_stats64
*stats
)
379 static struct rtnl_link_stats64
*i40e_get_netdev_stats_struct(
380 struct net_device
*netdev
,
381 struct rtnl_link_stats64
*stats
)
384 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
385 struct i40e_ring
*tx_ring
, *rx_ring
;
386 struct i40e_vsi
*vsi
= np
->vsi
;
387 struct rtnl_link_stats64
*vsi_stats
= i40e_get_vsi_stats_struct(vsi
);
390 if (test_bit(__I40E_DOWN
, &vsi
->state
))
397 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
401 tx_ring
= ACCESS_ONCE(vsi
->tx_rings
[i
]);
406 start
= u64_stats_fetch_begin_irq(&tx_ring
->syncp
);
407 packets
= tx_ring
->stats
.packets
;
408 bytes
= tx_ring
->stats
.bytes
;
409 } while (u64_stats_fetch_retry_irq(&tx_ring
->syncp
, start
));
411 stats
->tx_packets
+= packets
;
412 stats
->tx_bytes
+= bytes
;
413 rx_ring
= &tx_ring
[1];
416 start
= u64_stats_fetch_begin_irq(&rx_ring
->syncp
);
417 packets
= rx_ring
->stats
.packets
;
418 bytes
= rx_ring
->stats
.bytes
;
419 } while (u64_stats_fetch_retry_irq(&rx_ring
->syncp
, start
));
421 stats
->rx_packets
+= packets
;
422 stats
->rx_bytes
+= bytes
;
426 /* following stats updated by i40e_watchdog_subtask() */
427 stats
->multicast
= vsi_stats
->multicast
;
428 stats
->tx_errors
= vsi_stats
->tx_errors
;
429 stats
->tx_dropped
= vsi_stats
->tx_dropped
;
430 stats
->rx_errors
= vsi_stats
->rx_errors
;
431 stats
->rx_crc_errors
= vsi_stats
->rx_crc_errors
;
432 stats
->rx_length_errors
= vsi_stats
->rx_length_errors
;
438 * i40e_vsi_reset_stats - Resets all stats of the given vsi
439 * @vsi: the VSI to have its stats reset
441 void i40e_vsi_reset_stats(struct i40e_vsi
*vsi
)
443 struct rtnl_link_stats64
*ns
;
449 ns
= i40e_get_vsi_stats_struct(vsi
);
450 memset(ns
, 0, sizeof(*ns
));
451 memset(&vsi
->net_stats_offsets
, 0, sizeof(vsi
->net_stats_offsets
));
452 memset(&vsi
->eth_stats
, 0, sizeof(vsi
->eth_stats
));
453 memset(&vsi
->eth_stats_offsets
, 0, sizeof(vsi
->eth_stats_offsets
));
454 if (vsi
->rx_rings
&& vsi
->rx_rings
[0]) {
455 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
456 memset(&vsi
->rx_rings
[i
]->stats
, 0 ,
457 sizeof(vsi
->rx_rings
[i
]->stats
));
458 memset(&vsi
->rx_rings
[i
]->rx_stats
, 0 ,
459 sizeof(vsi
->rx_rings
[i
]->rx_stats
));
460 memset(&vsi
->tx_rings
[i
]->stats
, 0 ,
461 sizeof(vsi
->tx_rings
[i
]->stats
));
462 memset(&vsi
->tx_rings
[i
]->tx_stats
, 0,
463 sizeof(vsi
->tx_rings
[i
]->tx_stats
));
466 vsi
->stat_offsets_loaded
= false;
470 * i40e_pf_reset_stats - Reset all of the stats for the given PF
471 * @pf: the PF to be reset
473 void i40e_pf_reset_stats(struct i40e_pf
*pf
)
477 memset(&pf
->stats
, 0, sizeof(pf
->stats
));
478 memset(&pf
->stats_offsets
, 0, sizeof(pf
->stats_offsets
));
479 pf
->stat_offsets_loaded
= false;
481 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
483 memset(&pf
->veb
[i
]->stats
, 0,
484 sizeof(pf
->veb
[i
]->stats
));
485 memset(&pf
->veb
[i
]->stats_offsets
, 0,
486 sizeof(pf
->veb
[i
]->stats_offsets
));
487 pf
->veb
[i
]->stat_offsets_loaded
= false;
493 * i40e_stat_update48 - read and update a 48 bit stat from the chip
494 * @hw: ptr to the hardware info
495 * @hireg: the high 32 bit reg to read
496 * @loreg: the low 32 bit reg to read
497 * @offset_loaded: has the initial offset been loaded yet
498 * @offset: ptr to current offset value
499 * @stat: ptr to the stat
501 * Since the device stats are not reset at PFReset, they likely will not
502 * be zeroed when the driver starts. We'll save the first values read
503 * and use them as offsets to be subtracted from the raw values in order
504 * to report stats that count from zero. In the process, we also manage
505 * the potential roll-over.
507 static void i40e_stat_update48(struct i40e_hw
*hw
, u32 hireg
, u32 loreg
,
508 bool offset_loaded
, u64
*offset
, u64
*stat
)
512 if (hw
->device_id
== I40E_DEV_ID_QEMU
) {
513 new_data
= rd32(hw
, loreg
);
514 new_data
|= ((u64
)(rd32(hw
, hireg
) & 0xFFFF)) << 32;
516 new_data
= rd64(hw
, loreg
);
520 if (likely(new_data
>= *offset
))
521 *stat
= new_data
- *offset
;
523 *stat
= (new_data
+ ((u64
)1 << 48)) - *offset
;
524 *stat
&= 0xFFFFFFFFFFFFULL
;
528 * i40e_stat_update32 - read and update a 32 bit stat from the chip
529 * @hw: ptr to the hardware info
530 * @reg: the hw reg to read
531 * @offset_loaded: has the initial offset been loaded yet
532 * @offset: ptr to current offset value
533 * @stat: ptr to the stat
535 static void i40e_stat_update32(struct i40e_hw
*hw
, u32 reg
,
536 bool offset_loaded
, u64
*offset
, u64
*stat
)
540 new_data
= rd32(hw
, reg
);
543 if (likely(new_data
>= *offset
))
544 *stat
= (u32
)(new_data
- *offset
);
546 *stat
= (u32
)((new_data
+ ((u64
)1 << 32)) - *offset
);
550 * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
551 * @vsi: the VSI to be updated
553 void i40e_update_eth_stats(struct i40e_vsi
*vsi
)
555 int stat_idx
= le16_to_cpu(vsi
->info
.stat_counter_idx
);
556 struct i40e_pf
*pf
= vsi
->back
;
557 struct i40e_hw
*hw
= &pf
->hw
;
558 struct i40e_eth_stats
*oes
;
559 struct i40e_eth_stats
*es
; /* device's eth stats */
561 es
= &vsi
->eth_stats
;
562 oes
= &vsi
->eth_stats_offsets
;
564 /* Gather up the stats that the hw collects */
565 i40e_stat_update32(hw
, I40E_GLV_TEPC(stat_idx
),
566 vsi
->stat_offsets_loaded
,
567 &oes
->tx_errors
, &es
->tx_errors
);
568 i40e_stat_update32(hw
, I40E_GLV_RDPC(stat_idx
),
569 vsi
->stat_offsets_loaded
,
570 &oes
->rx_discards
, &es
->rx_discards
);
571 i40e_stat_update32(hw
, I40E_GLV_RUPP(stat_idx
),
572 vsi
->stat_offsets_loaded
,
573 &oes
->rx_unknown_protocol
, &es
->rx_unknown_protocol
);
574 i40e_stat_update32(hw
, I40E_GLV_TEPC(stat_idx
),
575 vsi
->stat_offsets_loaded
,
576 &oes
->tx_errors
, &es
->tx_errors
);
578 i40e_stat_update48(hw
, I40E_GLV_GORCH(stat_idx
),
579 I40E_GLV_GORCL(stat_idx
),
580 vsi
->stat_offsets_loaded
,
581 &oes
->rx_bytes
, &es
->rx_bytes
);
582 i40e_stat_update48(hw
, I40E_GLV_UPRCH(stat_idx
),
583 I40E_GLV_UPRCL(stat_idx
),
584 vsi
->stat_offsets_loaded
,
585 &oes
->rx_unicast
, &es
->rx_unicast
);
586 i40e_stat_update48(hw
, I40E_GLV_MPRCH(stat_idx
),
587 I40E_GLV_MPRCL(stat_idx
),
588 vsi
->stat_offsets_loaded
,
589 &oes
->rx_multicast
, &es
->rx_multicast
);
590 i40e_stat_update48(hw
, I40E_GLV_BPRCH(stat_idx
),
591 I40E_GLV_BPRCL(stat_idx
),
592 vsi
->stat_offsets_loaded
,
593 &oes
->rx_broadcast
, &es
->rx_broadcast
);
595 i40e_stat_update48(hw
, I40E_GLV_GOTCH(stat_idx
),
596 I40E_GLV_GOTCL(stat_idx
),
597 vsi
->stat_offsets_loaded
,
598 &oes
->tx_bytes
, &es
->tx_bytes
);
599 i40e_stat_update48(hw
, I40E_GLV_UPTCH(stat_idx
),
600 I40E_GLV_UPTCL(stat_idx
),
601 vsi
->stat_offsets_loaded
,
602 &oes
->tx_unicast
, &es
->tx_unicast
);
603 i40e_stat_update48(hw
, I40E_GLV_MPTCH(stat_idx
),
604 I40E_GLV_MPTCL(stat_idx
),
605 vsi
->stat_offsets_loaded
,
606 &oes
->tx_multicast
, &es
->tx_multicast
);
607 i40e_stat_update48(hw
, I40E_GLV_BPTCH(stat_idx
),
608 I40E_GLV_BPTCL(stat_idx
),
609 vsi
->stat_offsets_loaded
,
610 &oes
->tx_broadcast
, &es
->tx_broadcast
);
611 vsi
->stat_offsets_loaded
= true;
615 * i40e_update_veb_stats - Update Switch component statistics
616 * @veb: the VEB being updated
618 static void i40e_update_veb_stats(struct i40e_veb
*veb
)
620 struct i40e_pf
*pf
= veb
->pf
;
621 struct i40e_hw
*hw
= &pf
->hw
;
622 struct i40e_eth_stats
*oes
;
623 struct i40e_eth_stats
*es
; /* device's eth stats */
626 idx
= veb
->stats_idx
;
628 oes
= &veb
->stats_offsets
;
630 /* Gather up the stats that the hw collects */
631 i40e_stat_update32(hw
, I40E_GLSW_TDPC(idx
),
632 veb
->stat_offsets_loaded
,
633 &oes
->tx_discards
, &es
->tx_discards
);
634 if (hw
->revision_id
> 0)
635 i40e_stat_update32(hw
, I40E_GLSW_RUPP(idx
),
636 veb
->stat_offsets_loaded
,
637 &oes
->rx_unknown_protocol
,
638 &es
->rx_unknown_protocol
);
639 i40e_stat_update48(hw
, I40E_GLSW_GORCH(idx
), I40E_GLSW_GORCL(idx
),
640 veb
->stat_offsets_loaded
,
641 &oes
->rx_bytes
, &es
->rx_bytes
);
642 i40e_stat_update48(hw
, I40E_GLSW_UPRCH(idx
), I40E_GLSW_UPRCL(idx
),
643 veb
->stat_offsets_loaded
,
644 &oes
->rx_unicast
, &es
->rx_unicast
);
645 i40e_stat_update48(hw
, I40E_GLSW_MPRCH(idx
), I40E_GLSW_MPRCL(idx
),
646 veb
->stat_offsets_loaded
,
647 &oes
->rx_multicast
, &es
->rx_multicast
);
648 i40e_stat_update48(hw
, I40E_GLSW_BPRCH(idx
), I40E_GLSW_BPRCL(idx
),
649 veb
->stat_offsets_loaded
,
650 &oes
->rx_broadcast
, &es
->rx_broadcast
);
652 i40e_stat_update48(hw
, I40E_GLSW_GOTCH(idx
), I40E_GLSW_GOTCL(idx
),
653 veb
->stat_offsets_loaded
,
654 &oes
->tx_bytes
, &es
->tx_bytes
);
655 i40e_stat_update48(hw
, I40E_GLSW_UPTCH(idx
), I40E_GLSW_UPTCL(idx
),
656 veb
->stat_offsets_loaded
,
657 &oes
->tx_unicast
, &es
->tx_unicast
);
658 i40e_stat_update48(hw
, I40E_GLSW_MPTCH(idx
), I40E_GLSW_MPTCL(idx
),
659 veb
->stat_offsets_loaded
,
660 &oes
->tx_multicast
, &es
->tx_multicast
);
661 i40e_stat_update48(hw
, I40E_GLSW_BPTCH(idx
), I40E_GLSW_BPTCL(idx
),
662 veb
->stat_offsets_loaded
,
663 &oes
->tx_broadcast
, &es
->tx_broadcast
);
664 veb
->stat_offsets_loaded
= true;
669 * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters.
670 * @vsi: the VSI that is capable of doing FCoE
672 static void i40e_update_fcoe_stats(struct i40e_vsi
*vsi
)
674 struct i40e_pf
*pf
= vsi
->back
;
675 struct i40e_hw
*hw
= &pf
->hw
;
676 struct i40e_fcoe_stats
*ofs
;
677 struct i40e_fcoe_stats
*fs
; /* device's eth stats */
680 if (vsi
->type
!= I40E_VSI_FCOE
)
683 idx
= (pf
->pf_seid
- I40E_BASE_PF_SEID
) + I40E_FCOE_PF_STAT_OFFSET
;
684 fs
= &vsi
->fcoe_stats
;
685 ofs
= &vsi
->fcoe_stats_offsets
;
687 i40e_stat_update32(hw
, I40E_GL_FCOEPRC(idx
),
688 vsi
->fcoe_stat_offsets_loaded
,
689 &ofs
->rx_fcoe_packets
, &fs
->rx_fcoe_packets
);
690 i40e_stat_update48(hw
, I40E_GL_FCOEDWRCH(idx
), I40E_GL_FCOEDWRCL(idx
),
691 vsi
->fcoe_stat_offsets_loaded
,
692 &ofs
->rx_fcoe_dwords
, &fs
->rx_fcoe_dwords
);
693 i40e_stat_update32(hw
, I40E_GL_FCOERPDC(idx
),
694 vsi
->fcoe_stat_offsets_loaded
,
695 &ofs
->rx_fcoe_dropped
, &fs
->rx_fcoe_dropped
);
696 i40e_stat_update32(hw
, I40E_GL_FCOEPTC(idx
),
697 vsi
->fcoe_stat_offsets_loaded
,
698 &ofs
->tx_fcoe_packets
, &fs
->tx_fcoe_packets
);
699 i40e_stat_update48(hw
, I40E_GL_FCOEDWTCH(idx
), I40E_GL_FCOEDWTCL(idx
),
700 vsi
->fcoe_stat_offsets_loaded
,
701 &ofs
->tx_fcoe_dwords
, &fs
->tx_fcoe_dwords
);
702 i40e_stat_update32(hw
, I40E_GL_FCOECRC(idx
),
703 vsi
->fcoe_stat_offsets_loaded
,
704 &ofs
->fcoe_bad_fccrc
, &fs
->fcoe_bad_fccrc
);
705 i40e_stat_update32(hw
, I40E_GL_FCOELAST(idx
),
706 vsi
->fcoe_stat_offsets_loaded
,
707 &ofs
->fcoe_last_error
, &fs
->fcoe_last_error
);
708 i40e_stat_update32(hw
, I40E_GL_FCOEDDPC(idx
),
709 vsi
->fcoe_stat_offsets_loaded
,
710 &ofs
->fcoe_ddp_count
, &fs
->fcoe_ddp_count
);
712 vsi
->fcoe_stat_offsets_loaded
= true;
717 * i40e_update_link_xoff_rx - Update XOFF received in link flow control mode
718 * @pf: the corresponding PF
720 * Update the Rx XOFF counter (PAUSE frames) in link flow control mode
722 static void i40e_update_link_xoff_rx(struct i40e_pf
*pf
)
724 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
725 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
726 struct i40e_hw
*hw
= &pf
->hw
;
730 if ((hw
->fc
.current_mode
!= I40E_FC_FULL
) &&
731 (hw
->fc
.current_mode
!= I40E_FC_RX_PAUSE
))
734 xoff
= nsd
->link_xoff_rx
;
735 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFRXC(hw
->port
),
736 pf
->stat_offsets_loaded
,
737 &osd
->link_xoff_rx
, &nsd
->link_xoff_rx
);
739 /* No new LFC xoff rx */
740 if (!(nsd
->link_xoff_rx
- xoff
))
743 /* Clear the __I40E_HANG_CHECK_ARMED bit for all Tx rings */
744 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
745 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
747 if (!vsi
|| !vsi
->tx_rings
[0])
750 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
751 struct i40e_ring
*ring
= vsi
->tx_rings
[i
];
752 clear_bit(__I40E_HANG_CHECK_ARMED
, &ring
->state
);
758 * i40e_update_prio_xoff_rx - Update XOFF received in PFC mode
759 * @pf: the corresponding PF
761 * Update the Rx XOFF counter (PAUSE frames) in PFC mode
763 static void i40e_update_prio_xoff_rx(struct i40e_pf
*pf
)
765 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
766 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
767 bool xoff
[I40E_MAX_TRAFFIC_CLASS
] = {false};
768 struct i40e_dcbx_config
*dcb_cfg
;
769 struct i40e_hw
*hw
= &pf
->hw
;
773 dcb_cfg
= &hw
->local_dcbx_config
;
775 /* Collect Link XOFF stats when PFC is disabled */
776 if (!dcb_cfg
->pfc
.pfcenable
) {
777 i40e_update_link_xoff_rx(pf
);
781 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
782 u64 prio_xoff
= nsd
->priority_xoff_rx
[i
];
783 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFRXC(hw
->port
, i
),
784 pf
->stat_offsets_loaded
,
785 &osd
->priority_xoff_rx
[i
],
786 &nsd
->priority_xoff_rx
[i
]);
788 /* No new PFC xoff rx */
789 if (!(nsd
->priority_xoff_rx
[i
] - prio_xoff
))
791 /* Get the TC for given priority */
792 tc
= dcb_cfg
->etscfg
.prioritytable
[i
];
796 /* Clear the __I40E_HANG_CHECK_ARMED bit for Tx rings */
797 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
798 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
800 if (!vsi
|| !vsi
->tx_rings
[0])
803 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
804 struct i40e_ring
*ring
= vsi
->tx_rings
[i
];
808 clear_bit(__I40E_HANG_CHECK_ARMED
,
815 * i40e_update_vsi_stats - Update the vsi statistics counters.
816 * @vsi: the VSI to be updated
818 * There are a few instances where we store the same stat in a
819 * couple of different structs. This is partly because we have
820 * the netdev stats that need to be filled out, which is slightly
821 * different from the "eth_stats" defined by the chip and used in
822 * VF communications. We sort it out here.
824 static void i40e_update_vsi_stats(struct i40e_vsi
*vsi
)
826 struct i40e_pf
*pf
= vsi
->back
;
827 struct rtnl_link_stats64
*ons
;
828 struct rtnl_link_stats64
*ns
; /* netdev stats */
829 struct i40e_eth_stats
*oes
;
830 struct i40e_eth_stats
*es
; /* device's eth stats */
831 u32 tx_restart
, tx_busy
;
840 if (test_bit(__I40E_DOWN
, &vsi
->state
) ||
841 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
844 ns
= i40e_get_vsi_stats_struct(vsi
);
845 ons
= &vsi
->net_stats_offsets
;
846 es
= &vsi
->eth_stats
;
847 oes
= &vsi
->eth_stats_offsets
;
849 /* Gather up the netdev and vsi stats that the driver collects
850 * on the fly during packet processing
854 tx_restart
= tx_busy
= 0;
858 for (q
= 0; q
< vsi
->num_queue_pairs
; q
++) {
860 p
= ACCESS_ONCE(vsi
->tx_rings
[q
]);
863 start
= u64_stats_fetch_begin_irq(&p
->syncp
);
864 packets
= p
->stats
.packets
;
865 bytes
= p
->stats
.bytes
;
866 } while (u64_stats_fetch_retry_irq(&p
->syncp
, start
));
869 tx_restart
+= p
->tx_stats
.restart_queue
;
870 tx_busy
+= p
->tx_stats
.tx_busy
;
872 /* Rx queue is part of the same block as Tx queue */
875 start
= u64_stats_fetch_begin_irq(&p
->syncp
);
876 packets
= p
->stats
.packets
;
877 bytes
= p
->stats
.bytes
;
878 } while (u64_stats_fetch_retry_irq(&p
->syncp
, start
));
881 rx_buf
+= p
->rx_stats
.alloc_buff_failed
;
882 rx_page
+= p
->rx_stats
.alloc_page_failed
;
885 vsi
->tx_restart
= tx_restart
;
886 vsi
->tx_busy
= tx_busy
;
887 vsi
->rx_page_failed
= rx_page
;
888 vsi
->rx_buf_failed
= rx_buf
;
890 ns
->rx_packets
= rx_p
;
892 ns
->tx_packets
= tx_p
;
895 /* update netdev stats from eth stats */
896 i40e_update_eth_stats(vsi
);
897 ons
->tx_errors
= oes
->tx_errors
;
898 ns
->tx_errors
= es
->tx_errors
;
899 ons
->multicast
= oes
->rx_multicast
;
900 ns
->multicast
= es
->rx_multicast
;
901 ons
->rx_dropped
= oes
->rx_discards
;
902 ns
->rx_dropped
= es
->rx_discards
;
903 ons
->tx_dropped
= oes
->tx_discards
;
904 ns
->tx_dropped
= es
->tx_discards
;
906 /* pull in a couple PF stats if this is the main vsi */
907 if (vsi
== pf
->vsi
[pf
->lan_vsi
]) {
908 ns
->rx_crc_errors
= pf
->stats
.crc_errors
;
909 ns
->rx_errors
= pf
->stats
.crc_errors
+ pf
->stats
.illegal_bytes
;
910 ns
->rx_length_errors
= pf
->stats
.rx_length_errors
;
915 * i40e_update_pf_stats - Update the PF statistics counters.
916 * @pf: the PF to be updated
918 static void i40e_update_pf_stats(struct i40e_pf
*pf
)
920 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
921 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
922 struct i40e_hw
*hw
= &pf
->hw
;
926 i40e_stat_update48(hw
, I40E_GLPRT_GORCH(hw
->port
),
927 I40E_GLPRT_GORCL(hw
->port
),
928 pf
->stat_offsets_loaded
,
929 &osd
->eth
.rx_bytes
, &nsd
->eth
.rx_bytes
);
930 i40e_stat_update48(hw
, I40E_GLPRT_GOTCH(hw
->port
),
931 I40E_GLPRT_GOTCL(hw
->port
),
932 pf
->stat_offsets_loaded
,
933 &osd
->eth
.tx_bytes
, &nsd
->eth
.tx_bytes
);
934 i40e_stat_update32(hw
, I40E_GLPRT_RDPC(hw
->port
),
935 pf
->stat_offsets_loaded
,
936 &osd
->eth
.rx_discards
,
937 &nsd
->eth
.rx_discards
);
938 i40e_stat_update48(hw
, I40E_GLPRT_UPRCH(hw
->port
),
939 I40E_GLPRT_UPRCL(hw
->port
),
940 pf
->stat_offsets_loaded
,
941 &osd
->eth
.rx_unicast
,
942 &nsd
->eth
.rx_unicast
);
943 i40e_stat_update48(hw
, I40E_GLPRT_MPRCH(hw
->port
),
944 I40E_GLPRT_MPRCL(hw
->port
),
945 pf
->stat_offsets_loaded
,
946 &osd
->eth
.rx_multicast
,
947 &nsd
->eth
.rx_multicast
);
948 i40e_stat_update48(hw
, I40E_GLPRT_BPRCH(hw
->port
),
949 I40E_GLPRT_BPRCL(hw
->port
),
950 pf
->stat_offsets_loaded
,
951 &osd
->eth
.rx_broadcast
,
952 &nsd
->eth
.rx_broadcast
);
953 i40e_stat_update48(hw
, I40E_GLPRT_UPTCH(hw
->port
),
954 I40E_GLPRT_UPTCL(hw
->port
),
955 pf
->stat_offsets_loaded
,
956 &osd
->eth
.tx_unicast
,
957 &nsd
->eth
.tx_unicast
);
958 i40e_stat_update48(hw
, I40E_GLPRT_MPTCH(hw
->port
),
959 I40E_GLPRT_MPTCL(hw
->port
),
960 pf
->stat_offsets_loaded
,
961 &osd
->eth
.tx_multicast
,
962 &nsd
->eth
.tx_multicast
);
963 i40e_stat_update48(hw
, I40E_GLPRT_BPTCH(hw
->port
),
964 I40E_GLPRT_BPTCL(hw
->port
),
965 pf
->stat_offsets_loaded
,
966 &osd
->eth
.tx_broadcast
,
967 &nsd
->eth
.tx_broadcast
);
969 i40e_stat_update32(hw
, I40E_GLPRT_TDOLD(hw
->port
),
970 pf
->stat_offsets_loaded
,
971 &osd
->tx_dropped_link_down
,
972 &nsd
->tx_dropped_link_down
);
974 i40e_stat_update32(hw
, I40E_GLPRT_CRCERRS(hw
->port
),
975 pf
->stat_offsets_loaded
,
976 &osd
->crc_errors
, &nsd
->crc_errors
);
978 i40e_stat_update32(hw
, I40E_GLPRT_ILLERRC(hw
->port
),
979 pf
->stat_offsets_loaded
,
980 &osd
->illegal_bytes
, &nsd
->illegal_bytes
);
982 i40e_stat_update32(hw
, I40E_GLPRT_MLFC(hw
->port
),
983 pf
->stat_offsets_loaded
,
984 &osd
->mac_local_faults
,
985 &nsd
->mac_local_faults
);
986 i40e_stat_update32(hw
, I40E_GLPRT_MRFC(hw
->port
),
987 pf
->stat_offsets_loaded
,
988 &osd
->mac_remote_faults
,
989 &nsd
->mac_remote_faults
);
991 i40e_stat_update32(hw
, I40E_GLPRT_RLEC(hw
->port
),
992 pf
->stat_offsets_loaded
,
993 &osd
->rx_length_errors
,
994 &nsd
->rx_length_errors
);
996 i40e_stat_update32(hw
, I40E_GLPRT_LXONRXC(hw
->port
),
997 pf
->stat_offsets_loaded
,
998 &osd
->link_xon_rx
, &nsd
->link_xon_rx
);
999 i40e_stat_update32(hw
, I40E_GLPRT_LXONTXC(hw
->port
),
1000 pf
->stat_offsets_loaded
,
1001 &osd
->link_xon_tx
, &nsd
->link_xon_tx
);
1002 i40e_update_prio_xoff_rx(pf
); /* handles I40E_GLPRT_LXOFFRXC */
1003 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFTXC(hw
->port
),
1004 pf
->stat_offsets_loaded
,
1005 &osd
->link_xoff_tx
, &nsd
->link_xoff_tx
);
1007 for (i
= 0; i
< 8; i
++) {
1008 i40e_stat_update32(hw
, I40E_GLPRT_PXONRXC(hw
->port
, i
),
1009 pf
->stat_offsets_loaded
,
1010 &osd
->priority_xon_rx
[i
],
1011 &nsd
->priority_xon_rx
[i
]);
1012 i40e_stat_update32(hw
, I40E_GLPRT_PXONTXC(hw
->port
, i
),
1013 pf
->stat_offsets_loaded
,
1014 &osd
->priority_xon_tx
[i
],
1015 &nsd
->priority_xon_tx
[i
]);
1016 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFTXC(hw
->port
, i
),
1017 pf
->stat_offsets_loaded
,
1018 &osd
->priority_xoff_tx
[i
],
1019 &nsd
->priority_xoff_tx
[i
]);
1020 i40e_stat_update32(hw
,
1021 I40E_GLPRT_RXON2OFFCNT(hw
->port
, i
),
1022 pf
->stat_offsets_loaded
,
1023 &osd
->priority_xon_2_xoff
[i
],
1024 &nsd
->priority_xon_2_xoff
[i
]);
1027 i40e_stat_update48(hw
, I40E_GLPRT_PRC64H(hw
->port
),
1028 I40E_GLPRT_PRC64L(hw
->port
),
1029 pf
->stat_offsets_loaded
,
1030 &osd
->rx_size_64
, &nsd
->rx_size_64
);
1031 i40e_stat_update48(hw
, I40E_GLPRT_PRC127H(hw
->port
),
1032 I40E_GLPRT_PRC127L(hw
->port
),
1033 pf
->stat_offsets_loaded
,
1034 &osd
->rx_size_127
, &nsd
->rx_size_127
);
1035 i40e_stat_update48(hw
, I40E_GLPRT_PRC255H(hw
->port
),
1036 I40E_GLPRT_PRC255L(hw
->port
),
1037 pf
->stat_offsets_loaded
,
1038 &osd
->rx_size_255
, &nsd
->rx_size_255
);
1039 i40e_stat_update48(hw
, I40E_GLPRT_PRC511H(hw
->port
),
1040 I40E_GLPRT_PRC511L(hw
->port
),
1041 pf
->stat_offsets_loaded
,
1042 &osd
->rx_size_511
, &nsd
->rx_size_511
);
1043 i40e_stat_update48(hw
, I40E_GLPRT_PRC1023H(hw
->port
),
1044 I40E_GLPRT_PRC1023L(hw
->port
),
1045 pf
->stat_offsets_loaded
,
1046 &osd
->rx_size_1023
, &nsd
->rx_size_1023
);
1047 i40e_stat_update48(hw
, I40E_GLPRT_PRC1522H(hw
->port
),
1048 I40E_GLPRT_PRC1522L(hw
->port
),
1049 pf
->stat_offsets_loaded
,
1050 &osd
->rx_size_1522
, &nsd
->rx_size_1522
);
1051 i40e_stat_update48(hw
, I40E_GLPRT_PRC9522H(hw
->port
),
1052 I40E_GLPRT_PRC9522L(hw
->port
),
1053 pf
->stat_offsets_loaded
,
1054 &osd
->rx_size_big
, &nsd
->rx_size_big
);
1056 i40e_stat_update48(hw
, I40E_GLPRT_PTC64H(hw
->port
),
1057 I40E_GLPRT_PTC64L(hw
->port
),
1058 pf
->stat_offsets_loaded
,
1059 &osd
->tx_size_64
, &nsd
->tx_size_64
);
1060 i40e_stat_update48(hw
, I40E_GLPRT_PTC127H(hw
->port
),
1061 I40E_GLPRT_PTC127L(hw
->port
),
1062 pf
->stat_offsets_loaded
,
1063 &osd
->tx_size_127
, &nsd
->tx_size_127
);
1064 i40e_stat_update48(hw
, I40E_GLPRT_PTC255H(hw
->port
),
1065 I40E_GLPRT_PTC255L(hw
->port
),
1066 pf
->stat_offsets_loaded
,
1067 &osd
->tx_size_255
, &nsd
->tx_size_255
);
1068 i40e_stat_update48(hw
, I40E_GLPRT_PTC511H(hw
->port
),
1069 I40E_GLPRT_PTC511L(hw
->port
),
1070 pf
->stat_offsets_loaded
,
1071 &osd
->tx_size_511
, &nsd
->tx_size_511
);
1072 i40e_stat_update48(hw
, I40E_GLPRT_PTC1023H(hw
->port
),
1073 I40E_GLPRT_PTC1023L(hw
->port
),
1074 pf
->stat_offsets_loaded
,
1075 &osd
->tx_size_1023
, &nsd
->tx_size_1023
);
1076 i40e_stat_update48(hw
, I40E_GLPRT_PTC1522H(hw
->port
),
1077 I40E_GLPRT_PTC1522L(hw
->port
),
1078 pf
->stat_offsets_loaded
,
1079 &osd
->tx_size_1522
, &nsd
->tx_size_1522
);
1080 i40e_stat_update48(hw
, I40E_GLPRT_PTC9522H(hw
->port
),
1081 I40E_GLPRT_PTC9522L(hw
->port
),
1082 pf
->stat_offsets_loaded
,
1083 &osd
->tx_size_big
, &nsd
->tx_size_big
);
1085 i40e_stat_update32(hw
, I40E_GLPRT_RUC(hw
->port
),
1086 pf
->stat_offsets_loaded
,
1087 &osd
->rx_undersize
, &nsd
->rx_undersize
);
1088 i40e_stat_update32(hw
, I40E_GLPRT_RFC(hw
->port
),
1089 pf
->stat_offsets_loaded
,
1090 &osd
->rx_fragments
, &nsd
->rx_fragments
);
1091 i40e_stat_update32(hw
, I40E_GLPRT_ROC(hw
->port
),
1092 pf
->stat_offsets_loaded
,
1093 &osd
->rx_oversize
, &nsd
->rx_oversize
);
1094 i40e_stat_update32(hw
, I40E_GLPRT_RJC(hw
->port
),
1095 pf
->stat_offsets_loaded
,
1096 &osd
->rx_jabber
, &nsd
->rx_jabber
);
1099 i40e_stat_update32(hw
,
1100 I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf
->hw
.pf_id
)),
1101 pf
->stat_offsets_loaded
,
1102 &osd
->fd_atr_match
, &nsd
->fd_atr_match
);
1103 i40e_stat_update32(hw
,
1104 I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf
->hw
.pf_id
)),
1105 pf
->stat_offsets_loaded
,
1106 &osd
->fd_sb_match
, &nsd
->fd_sb_match
);
1107 i40e_stat_update32(hw
,
1108 I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf
->hw
.pf_id
)),
1109 pf
->stat_offsets_loaded
,
1110 &osd
->fd_atr_tunnel_match
, &nsd
->fd_atr_tunnel_match
);
1112 val
= rd32(hw
, I40E_PRTPM_EEE_STAT
);
1113 nsd
->tx_lpi_status
=
1114 (val
& I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK
) >>
1115 I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT
;
1116 nsd
->rx_lpi_status
=
1117 (val
& I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK
) >>
1118 I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT
;
1119 i40e_stat_update32(hw
, I40E_PRTPM_TLPIC
,
1120 pf
->stat_offsets_loaded
,
1121 &osd
->tx_lpi_count
, &nsd
->tx_lpi_count
);
1122 i40e_stat_update32(hw
, I40E_PRTPM_RLPIC
,
1123 pf
->stat_offsets_loaded
,
1124 &osd
->rx_lpi_count
, &nsd
->rx_lpi_count
);
1126 pf
->stat_offsets_loaded
= true;
1130 * i40e_update_stats - Update the various statistics counters.
1131 * @vsi: the VSI to be updated
1133 * Update the various stats for this VSI and its related entities.
1135 void i40e_update_stats(struct i40e_vsi
*vsi
)
1137 struct i40e_pf
*pf
= vsi
->back
;
1139 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
1140 i40e_update_pf_stats(pf
);
1142 i40e_update_vsi_stats(vsi
);
1144 i40e_update_fcoe_stats(vsi
);
1149 * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
1150 * @vsi: the VSI to be searched
1151 * @macaddr: the MAC address
1153 * @is_vf: make sure its a VF filter, else doesn't matter
1154 * @is_netdev: make sure its a netdev filter, else doesn't matter
1156 * Returns ptr to the filter object or NULL
1158 static struct i40e_mac_filter
*i40e_find_filter(struct i40e_vsi
*vsi
,
1159 u8
*macaddr
, s16 vlan
,
1160 bool is_vf
, bool is_netdev
)
1162 struct i40e_mac_filter
*f
;
1164 if (!vsi
|| !macaddr
)
1167 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1168 if ((ether_addr_equal(macaddr
, f
->macaddr
)) &&
1169 (vlan
== f
->vlan
) &&
1170 (!is_vf
|| f
->is_vf
) &&
1171 (!is_netdev
|| f
->is_netdev
))
1178 * i40e_find_mac - Find a mac addr in the macvlan filters list
1179 * @vsi: the VSI to be searched
1180 * @macaddr: the MAC address we are searching for
1181 * @is_vf: make sure its a VF filter, else doesn't matter
1182 * @is_netdev: make sure its a netdev filter, else doesn't matter
1184 * Returns the first filter with the provided MAC address or NULL if
1185 * MAC address was not found
1187 struct i40e_mac_filter
*i40e_find_mac(struct i40e_vsi
*vsi
, u8
*macaddr
,
1188 bool is_vf
, bool is_netdev
)
1190 struct i40e_mac_filter
*f
;
1192 if (!vsi
|| !macaddr
)
1195 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1196 if ((ether_addr_equal(macaddr
, f
->macaddr
)) &&
1197 (!is_vf
|| f
->is_vf
) &&
1198 (!is_netdev
|| f
->is_netdev
))
1205 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1206 * @vsi: the VSI to be searched
1208 * Returns true if VSI is in vlan mode or false otherwise
1210 bool i40e_is_vsi_in_vlan(struct i40e_vsi
*vsi
)
1212 struct i40e_mac_filter
*f
;
1214 /* Only -1 for all the filters denotes not in vlan mode
1215 * so we have to go through all the list in order to make sure
1217 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1226 * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
1227 * @vsi: the VSI to be searched
1228 * @macaddr: the mac address to be filtered
1229 * @is_vf: true if it is a VF
1230 * @is_netdev: true if it is a netdev
1232 * Goes through all the macvlan filters and adds a
1233 * macvlan filter for each unique vlan that already exists
1235 * Returns first filter found on success, else NULL
1237 struct i40e_mac_filter
*i40e_put_mac_in_vlan(struct i40e_vsi
*vsi
, u8
*macaddr
,
1238 bool is_vf
, bool is_netdev
)
1240 struct i40e_mac_filter
*f
;
1242 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1243 if (!i40e_find_filter(vsi
, macaddr
, f
->vlan
,
1244 is_vf
, is_netdev
)) {
1245 if (!i40e_add_filter(vsi
, macaddr
, f
->vlan
,
1251 return list_first_entry_or_null(&vsi
->mac_filter_list
,
1252 struct i40e_mac_filter
, list
);
1256 * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
1257 * @vsi: the PF Main VSI - inappropriate for any other VSI
1258 * @macaddr: the MAC address
1260 * Some older firmware configurations set up a default promiscuous VLAN
1261 * filter that needs to be removed.
1263 static int i40e_rm_default_mac_filter(struct i40e_vsi
*vsi
, u8
*macaddr
)
1265 struct i40e_aqc_remove_macvlan_element_data element
;
1266 struct i40e_pf
*pf
= vsi
->back
;
1269 /* Only appropriate for the PF main VSI */
1270 if (vsi
->type
!= I40E_VSI_MAIN
)
1273 memset(&element
, 0, sizeof(element
));
1274 ether_addr_copy(element
.mac_addr
, macaddr
);
1275 element
.vlan_tag
= 0;
1276 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
|
1277 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
1278 aq_ret
= i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1286 * i40e_add_filter - Add a mac/vlan filter to the VSI
1287 * @vsi: the VSI to be searched
1288 * @macaddr: the MAC address
1290 * @is_vf: make sure its a VF filter, else doesn't matter
1291 * @is_netdev: make sure its a netdev filter, else doesn't matter
1293 * Returns ptr to the filter object or NULL when no memory available.
1295 struct i40e_mac_filter
*i40e_add_filter(struct i40e_vsi
*vsi
,
1296 u8
*macaddr
, s16 vlan
,
1297 bool is_vf
, bool is_netdev
)
1299 struct i40e_mac_filter
*f
;
1301 if (!vsi
|| !macaddr
)
1304 f
= i40e_find_filter(vsi
, macaddr
, vlan
, is_vf
, is_netdev
);
1306 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
1308 goto add_filter_out
;
1310 ether_addr_copy(f
->macaddr
, macaddr
);
1314 INIT_LIST_HEAD(&f
->list
);
1315 list_add(&f
->list
, &vsi
->mac_filter_list
);
1318 /* increment counter and add a new flag if needed */
1324 } else if (is_netdev
) {
1325 if (!f
->is_netdev
) {
1326 f
->is_netdev
= true;
1333 /* changed tells sync_filters_subtask to
1334 * push the filter down to the firmware
1337 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1338 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1346 * i40e_del_filter - Remove a mac/vlan filter from the VSI
1347 * @vsi: the VSI to be searched
1348 * @macaddr: the MAC address
1350 * @is_vf: make sure it's a VF filter, else doesn't matter
1351 * @is_netdev: make sure it's a netdev filter, else doesn't matter
1353 void i40e_del_filter(struct i40e_vsi
*vsi
,
1354 u8
*macaddr
, s16 vlan
,
1355 bool is_vf
, bool is_netdev
)
1357 struct i40e_mac_filter
*f
;
1359 if (!vsi
|| !macaddr
)
1362 f
= i40e_find_filter(vsi
, macaddr
, vlan
, is_vf
, is_netdev
);
1363 if (!f
|| f
->counter
== 0)
1371 } else if (is_netdev
) {
1373 f
->is_netdev
= false;
1377 /* make sure we don't remove a filter in use by VF or netdev */
1379 min_f
+= (f
->is_vf
? 1 : 0);
1380 min_f
+= (f
->is_netdev
? 1 : 0);
1382 if (f
->counter
> min_f
)
1386 /* counter == 0 tells sync_filters_subtask to
1387 * remove the filter from the firmware's list
1389 if (f
->counter
== 0) {
1391 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1392 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1397 * i40e_set_mac - NDO callback to set mac address
1398 * @netdev: network interface device structure
1399 * @p: pointer to an address structure
1401 * Returns 0 on success, negative on failure
1404 int i40e_set_mac(struct net_device
*netdev
, void *p
)
1406 static int i40e_set_mac(struct net_device
*netdev
, void *p
)
1409 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1410 struct i40e_vsi
*vsi
= np
->vsi
;
1411 struct i40e_pf
*pf
= vsi
->back
;
1412 struct i40e_hw
*hw
= &pf
->hw
;
1413 struct sockaddr
*addr
= p
;
1414 struct i40e_mac_filter
*f
;
1416 if (!is_valid_ether_addr(addr
->sa_data
))
1417 return -EADDRNOTAVAIL
;
1419 if (ether_addr_equal(netdev
->dev_addr
, addr
->sa_data
)) {
1420 netdev_info(netdev
, "already using mac address %pM\n",
1425 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
1426 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
1427 return -EADDRNOTAVAIL
;
1429 if (ether_addr_equal(hw
->mac
.addr
, addr
->sa_data
))
1430 netdev_info(netdev
, "returning to hw mac address %pM\n",
1433 netdev_info(netdev
, "set new mac address %pM\n", addr
->sa_data
);
1435 if (vsi
->type
== I40E_VSI_MAIN
) {
1437 ret
= i40e_aq_mac_address_write(&vsi
->back
->hw
,
1438 I40E_AQC_WRITE_TYPE_LAA_WOL
,
1439 addr
->sa_data
, NULL
);
1442 "Addr change for Main VSI failed: %d\n",
1444 return -EADDRNOTAVAIL
;
1448 if (ether_addr_equal(netdev
->dev_addr
, hw
->mac
.addr
)) {
1449 struct i40e_aqc_remove_macvlan_element_data element
;
1451 memset(&element
, 0, sizeof(element
));
1452 ether_addr_copy(element
.mac_addr
, netdev
->dev_addr
);
1453 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
1454 i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1456 i40e_del_filter(vsi
, netdev
->dev_addr
, I40E_VLAN_ANY
,
1460 if (ether_addr_equal(addr
->sa_data
, hw
->mac
.addr
)) {
1461 struct i40e_aqc_add_macvlan_element_data element
;
1463 memset(&element
, 0, sizeof(element
));
1464 ether_addr_copy(element
.mac_addr
, hw
->mac
.addr
);
1465 element
.flags
= cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
);
1466 i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1468 f
= i40e_add_filter(vsi
, addr
->sa_data
, I40E_VLAN_ANY
,
1474 i40e_sync_vsi_filters(vsi
);
1475 ether_addr_copy(netdev
->dev_addr
, addr
->sa_data
);
1481 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1482 * @vsi: the VSI being setup
1483 * @ctxt: VSI context structure
1484 * @enabled_tc: Enabled TCs bitmap
1485 * @is_add: True if called before Add VSI
1487 * Setup VSI queue mapping for enabled traffic classes.
1490 void i40e_vsi_setup_queue_map(struct i40e_vsi
*vsi
,
1491 struct i40e_vsi_context
*ctxt
,
1495 static void i40e_vsi_setup_queue_map(struct i40e_vsi
*vsi
,
1496 struct i40e_vsi_context
*ctxt
,
1501 struct i40e_pf
*pf
= vsi
->back
;
1511 sections
= I40E_AQ_VSI_PROP_QUEUE_MAP_VALID
;
1514 if (enabled_tc
&& (vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
1515 /* Find numtc from enabled TC bitmap */
1516 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1517 if (enabled_tc
& (1 << i
)) /* TC is enabled */
1521 dev_warn(&pf
->pdev
->dev
, "DCB is enabled but no TC enabled, forcing TC0\n");
1525 /* At least TC0 is enabled in case of non-DCB case */
1529 vsi
->tc_config
.numtc
= numtc
;
1530 vsi
->tc_config
.enabled_tc
= enabled_tc
? enabled_tc
: 1;
1531 /* Number of queues per enabled TC */
1532 /* In MFP case we can have a much lower count of MSIx
1533 * vectors available and so we need to lower the used
1536 qcount
= min_t(int, vsi
->alloc_queue_pairs
, pf
->num_lan_msix
);
1537 num_tc_qps
= qcount
/ numtc
;
1538 num_tc_qps
= min_t(int, num_tc_qps
, I40E_MAX_QUEUES_PER_TC
);
1540 /* Setup queue offset/count for all TCs for given VSI */
1541 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1542 /* See if the given TC is enabled for the given VSI */
1543 if (vsi
->tc_config
.enabled_tc
& (1 << i
)) { /* TC is enabled */
1546 switch (vsi
->type
) {
1548 qcount
= min_t(int, pf
->rss_size
, num_tc_qps
);
1552 qcount
= num_tc_qps
;
1556 case I40E_VSI_SRIOV
:
1557 case I40E_VSI_VMDQ2
:
1559 qcount
= num_tc_qps
;
1563 vsi
->tc_config
.tc_info
[i
].qoffset
= offset
;
1564 vsi
->tc_config
.tc_info
[i
].qcount
= qcount
;
1566 /* find the next higher power-of-2 of num queue pairs */
1569 while (num_qps
&& ((1 << pow
) < qcount
)) {
1574 vsi
->tc_config
.tc_info
[i
].netdev_tc
= netdev_tc
++;
1576 (offset
<< I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT
) |
1577 (pow
<< I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT
);
1581 /* TC is not enabled so set the offset to
1582 * default queue and allocate one queue
1585 vsi
->tc_config
.tc_info
[i
].qoffset
= 0;
1586 vsi
->tc_config
.tc_info
[i
].qcount
= 1;
1587 vsi
->tc_config
.tc_info
[i
].netdev_tc
= 0;
1591 ctxt
->info
.tc_mapping
[i
] = cpu_to_le16(qmap
);
1594 /* Set actual Tx/Rx queue pairs */
1595 vsi
->num_queue_pairs
= offset
;
1596 if ((vsi
->type
== I40E_VSI_MAIN
) && (numtc
== 1)) {
1597 if (vsi
->req_queue_pairs
> 0)
1598 vsi
->num_queue_pairs
= vsi
->req_queue_pairs
;
1600 vsi
->num_queue_pairs
= pf
->num_lan_msix
;
1603 /* Scheduler section valid can only be set for ADD VSI */
1605 sections
|= I40E_AQ_VSI_PROP_SCHED_VALID
;
1607 ctxt
->info
.up_enable_bits
= enabled_tc
;
1609 if (vsi
->type
== I40E_VSI_SRIOV
) {
1610 ctxt
->info
.mapping_flags
|=
1611 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG
);
1612 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
1613 ctxt
->info
.queue_mapping
[i
] =
1614 cpu_to_le16(vsi
->base_queue
+ i
);
1616 ctxt
->info
.mapping_flags
|=
1617 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG
);
1618 ctxt
->info
.queue_mapping
[0] = cpu_to_le16(vsi
->base_queue
);
1620 ctxt
->info
.valid_sections
|= cpu_to_le16(sections
);
1624 * i40e_set_rx_mode - NDO callback to set the netdev filters
1625 * @netdev: network interface device structure
1628 void i40e_set_rx_mode(struct net_device
*netdev
)
1630 static void i40e_set_rx_mode(struct net_device
*netdev
)
1633 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1634 struct i40e_mac_filter
*f
, *ftmp
;
1635 struct i40e_vsi
*vsi
= np
->vsi
;
1636 struct netdev_hw_addr
*uca
;
1637 struct netdev_hw_addr
*mca
;
1638 struct netdev_hw_addr
*ha
;
1640 /* add addr if not already in the filter list */
1641 netdev_for_each_uc_addr(uca
, netdev
) {
1642 if (!i40e_find_mac(vsi
, uca
->addr
, false, true)) {
1643 if (i40e_is_vsi_in_vlan(vsi
))
1644 i40e_put_mac_in_vlan(vsi
, uca
->addr
,
1647 i40e_add_filter(vsi
, uca
->addr
, I40E_VLAN_ANY
,
1652 netdev_for_each_mc_addr(mca
, netdev
) {
1653 if (!i40e_find_mac(vsi
, mca
->addr
, false, true)) {
1654 if (i40e_is_vsi_in_vlan(vsi
))
1655 i40e_put_mac_in_vlan(vsi
, mca
->addr
,
1658 i40e_add_filter(vsi
, mca
->addr
, I40E_VLAN_ANY
,
1663 /* remove filter if not in netdev list */
1664 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1670 if (is_multicast_ether_addr(f
->macaddr
)) {
1671 netdev_for_each_mc_addr(mca
, netdev
) {
1672 if (ether_addr_equal(mca
->addr
, f
->macaddr
)) {
1678 netdev_for_each_uc_addr(uca
, netdev
) {
1679 if (ether_addr_equal(uca
->addr
, f
->macaddr
)) {
1685 for_each_dev_addr(netdev
, ha
) {
1686 if (ether_addr_equal(ha
->addr
, f
->macaddr
)) {
1694 vsi
, f
->macaddr
, I40E_VLAN_ANY
, false, true);
1697 /* check for other flag changes */
1698 if (vsi
->current_netdev_flags
!= vsi
->netdev
->flags
) {
1699 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1700 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1705 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
1706 * @vsi: ptr to the VSI
1708 * Push any outstanding VSI filter changes through the AdminQ.
1710 * Returns 0 or error value
1712 int i40e_sync_vsi_filters(struct i40e_vsi
*vsi
)
1714 struct i40e_mac_filter
*f
, *ftmp
;
1715 bool promisc_forced_on
= false;
1716 bool add_happened
= false;
1717 int filter_list_len
= 0;
1718 u32 changed_flags
= 0;
1719 i40e_status aq_ret
= 0;
1725 /* empty array typed pointers, kcalloc later */
1726 struct i40e_aqc_add_macvlan_element_data
*add_list
;
1727 struct i40e_aqc_remove_macvlan_element_data
*del_list
;
1729 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &vsi
->state
))
1730 usleep_range(1000, 2000);
1734 changed_flags
= vsi
->current_netdev_flags
^ vsi
->netdev
->flags
;
1735 vsi
->current_netdev_flags
= vsi
->netdev
->flags
;
1738 if (vsi
->flags
& I40E_VSI_FLAG_FILTER_CHANGED
) {
1739 vsi
->flags
&= ~I40E_VSI_FLAG_FILTER_CHANGED
;
1741 filter_list_len
= pf
->hw
.aq
.asq_buf_size
/
1742 sizeof(struct i40e_aqc_remove_macvlan_element_data
);
1743 del_list
= kcalloc(filter_list_len
,
1744 sizeof(struct i40e_aqc_remove_macvlan_element_data
),
1749 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1753 if (f
->counter
!= 0)
1758 /* add to delete list */
1759 ether_addr_copy(del_list
[num_del
].mac_addr
, f
->macaddr
);
1760 del_list
[num_del
].vlan_tag
=
1761 cpu_to_le16((u16
)(f
->vlan
==
1762 I40E_VLAN_ANY
? 0 : f
->vlan
));
1764 cmd_flags
|= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
1765 del_list
[num_del
].flags
= cmd_flags
;
1768 /* unlink from filter list */
1772 /* flush a full buffer */
1773 if (num_del
== filter_list_len
) {
1774 aq_ret
= i40e_aq_remove_macvlan(&pf
->hw
,
1775 vsi
->seid
, del_list
, num_del
,
1778 memset(del_list
, 0, sizeof(*del_list
));
1781 pf
->hw
.aq
.asq_last_status
!=
1783 dev_info(&pf
->pdev
->dev
,
1784 "ignoring delete macvlan error, err %d, aq_err %d while flushing a full buffer\n",
1786 pf
->hw
.aq
.asq_last_status
);
1790 aq_ret
= i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
,
1791 del_list
, num_del
, NULL
);
1795 pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_ENOENT
)
1796 dev_info(&pf
->pdev
->dev
,
1797 "ignoring delete macvlan error, err %d, aq_err %d\n",
1798 aq_ret
, pf
->hw
.aq
.asq_last_status
);
1804 /* do all the adds now */
1805 filter_list_len
= pf
->hw
.aq
.asq_buf_size
/
1806 sizeof(struct i40e_aqc_add_macvlan_element_data
),
1807 add_list
= kcalloc(filter_list_len
,
1808 sizeof(struct i40e_aqc_add_macvlan_element_data
),
1813 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1817 if (f
->counter
== 0)
1820 add_happened
= true;
1823 /* add to add array */
1824 ether_addr_copy(add_list
[num_add
].mac_addr
, f
->macaddr
);
1825 add_list
[num_add
].vlan_tag
=
1827 (u16
)(f
->vlan
== I40E_VLAN_ANY
? 0 : f
->vlan
));
1828 add_list
[num_add
].queue_number
= 0;
1830 cmd_flags
|= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
;
1831 add_list
[num_add
].flags
= cpu_to_le16(cmd_flags
);
1834 /* flush a full buffer */
1835 if (num_add
== filter_list_len
) {
1836 aq_ret
= i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
,
1843 memset(add_list
, 0, sizeof(*add_list
));
1847 aq_ret
= i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
,
1848 add_list
, num_add
, NULL
);
1854 if (add_happened
&& aq_ret
&&
1855 pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_EINVAL
) {
1856 dev_info(&pf
->pdev
->dev
,
1857 "add filter failed, err %d, aq_err %d\n",
1858 aq_ret
, pf
->hw
.aq
.asq_last_status
);
1859 if ((pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_ENOSPC
) &&
1860 !test_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
1862 promisc_forced_on
= true;
1863 set_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
1865 dev_info(&pf
->pdev
->dev
, "promiscuous mode forced on\n");
1870 /* check for changes in promiscuous modes */
1871 if (changed_flags
& IFF_ALLMULTI
) {
1872 bool cur_multipromisc
;
1873 cur_multipromisc
= !!(vsi
->current_netdev_flags
& IFF_ALLMULTI
);
1874 aq_ret
= i40e_aq_set_vsi_multicast_promiscuous(&vsi
->back
->hw
,
1879 dev_info(&pf
->pdev
->dev
,
1880 "set multi promisc failed, err %d, aq_err %d\n",
1881 aq_ret
, pf
->hw
.aq
.asq_last_status
);
1883 if ((changed_flags
& IFF_PROMISC
) || promisc_forced_on
) {
1885 cur_promisc
= (!!(vsi
->current_netdev_flags
& IFF_PROMISC
) ||
1886 test_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
1888 aq_ret
= i40e_aq_set_vsi_unicast_promiscuous(&vsi
->back
->hw
,
1892 dev_info(&pf
->pdev
->dev
,
1893 "set uni promisc failed, err %d, aq_err %d\n",
1894 aq_ret
, pf
->hw
.aq
.asq_last_status
);
1895 aq_ret
= i40e_aq_set_vsi_broadcast(&vsi
->back
->hw
,
1899 dev_info(&pf
->pdev
->dev
,
1900 "set brdcast promisc failed, err %d, aq_err %d\n",
1901 aq_ret
, pf
->hw
.aq
.asq_last_status
);
1904 clear_bit(__I40E_CONFIG_BUSY
, &vsi
->state
);
1909 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
1910 * @pf: board private structure
1912 static void i40e_sync_filters_subtask(struct i40e_pf
*pf
)
1916 if (!pf
|| !(pf
->flags
& I40E_FLAG_FILTER_SYNC
))
1918 pf
->flags
&= ~I40E_FLAG_FILTER_SYNC
;
1920 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
1922 (pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_FILTER_CHANGED
))
1923 i40e_sync_vsi_filters(pf
->vsi
[v
]);
1928 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
1929 * @netdev: network interface device structure
1930 * @new_mtu: new value for maximum frame size
1932 * Returns 0 on success, negative on failure
1934 static int i40e_change_mtu(struct net_device
*netdev
, int new_mtu
)
1936 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1937 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
1938 struct i40e_vsi
*vsi
= np
->vsi
;
1940 /* MTU < 68 is an error and causes problems on some kernels */
1941 if ((new_mtu
< 68) || (max_frame
> I40E_MAX_RXBUFFER
))
1944 netdev_info(netdev
, "changing MTU from %d to %d\n",
1945 netdev
->mtu
, new_mtu
);
1946 netdev
->mtu
= new_mtu
;
1947 if (netif_running(netdev
))
1948 i40e_vsi_reinit_locked(vsi
);
1954 * i40e_ioctl - Access the hwtstamp interface
1955 * @netdev: network interface device structure
1956 * @ifr: interface request data
1957 * @cmd: ioctl command
1959 int i40e_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
1961 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1962 struct i40e_pf
*pf
= np
->vsi
->back
;
1966 return i40e_ptp_get_ts_config(pf
, ifr
);
1968 return i40e_ptp_set_ts_config(pf
, ifr
);
1975 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
1976 * @vsi: the vsi being adjusted
1978 void i40e_vlan_stripping_enable(struct i40e_vsi
*vsi
)
1980 struct i40e_vsi_context ctxt
;
1983 if ((vsi
->info
.valid_sections
&
1984 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
1985 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_MODE_MASK
) == 0))
1986 return; /* already enabled */
1988 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
1989 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
1990 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH
;
1992 ctxt
.seid
= vsi
->seid
;
1993 ctxt
.info
= vsi
->info
;
1994 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
1996 dev_info(&vsi
->back
->pdev
->dev
,
1997 "%s: update vsi failed, aq_err=%d\n",
1998 __func__
, vsi
->back
->hw
.aq
.asq_last_status
);
2003 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2004 * @vsi: the vsi being adjusted
2006 void i40e_vlan_stripping_disable(struct i40e_vsi
*vsi
)
2008 struct i40e_vsi_context ctxt
;
2011 if ((vsi
->info
.valid_sections
&
2012 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
2013 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_EMOD_MASK
) ==
2014 I40E_AQ_VSI_PVLAN_EMOD_MASK
))
2015 return; /* already disabled */
2017 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2018 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
2019 I40E_AQ_VSI_PVLAN_EMOD_NOTHING
;
2021 ctxt
.seid
= vsi
->seid
;
2022 ctxt
.info
= vsi
->info
;
2023 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2025 dev_info(&vsi
->back
->pdev
->dev
,
2026 "%s: update vsi failed, aq_err=%d\n",
2027 __func__
, vsi
->back
->hw
.aq
.asq_last_status
);
2032 * i40e_vlan_rx_register - Setup or shutdown vlan offload
2033 * @netdev: network interface to be adjusted
2034 * @features: netdev features to test if VLAN offload is enabled or not
2036 static void i40e_vlan_rx_register(struct net_device
*netdev
, u32 features
)
2038 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2039 struct i40e_vsi
*vsi
= np
->vsi
;
2041 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
2042 i40e_vlan_stripping_enable(vsi
);
2044 i40e_vlan_stripping_disable(vsi
);
2048 * i40e_vsi_add_vlan - Add vsi membership for given vlan
2049 * @vsi: the vsi being configured
2050 * @vid: vlan id to be added (0 = untagged only , -1 = any)
2052 int i40e_vsi_add_vlan(struct i40e_vsi
*vsi
, s16 vid
)
2054 struct i40e_mac_filter
*f
, *add_f
;
2055 bool is_netdev
, is_vf
;
2057 is_vf
= (vsi
->type
== I40E_VSI_SRIOV
);
2058 is_netdev
= !!(vsi
->netdev
);
2061 add_f
= i40e_add_filter(vsi
, vsi
->netdev
->dev_addr
, vid
,
2064 dev_info(&vsi
->back
->pdev
->dev
,
2065 "Could not add vlan filter %d for %pM\n",
2066 vid
, vsi
->netdev
->dev_addr
);
2071 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2072 add_f
= i40e_add_filter(vsi
, f
->macaddr
, vid
, is_vf
, is_netdev
);
2074 dev_info(&vsi
->back
->pdev
->dev
,
2075 "Could not add vlan filter %d for %pM\n",
2081 /* Now if we add a vlan tag, make sure to check if it is the first
2082 * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
2083 * with 0, so we now accept untagged and specified tagged traffic
2084 * (and not any taged and untagged)
2087 if (is_netdev
&& i40e_find_filter(vsi
, vsi
->netdev
->dev_addr
,
2089 is_vf
, is_netdev
)) {
2090 i40e_del_filter(vsi
, vsi
->netdev
->dev_addr
,
2091 I40E_VLAN_ANY
, is_vf
, is_netdev
);
2092 add_f
= i40e_add_filter(vsi
, vsi
->netdev
->dev_addr
, 0,
2095 dev_info(&vsi
->back
->pdev
->dev
,
2096 "Could not add filter 0 for %pM\n",
2097 vsi
->netdev
->dev_addr
);
2103 /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
2104 if (vid
> 0 && !vsi
->info
.pvid
) {
2105 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2106 if (i40e_find_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2107 is_vf
, is_netdev
)) {
2108 i40e_del_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2110 add_f
= i40e_add_filter(vsi
, f
->macaddr
,
2111 0, is_vf
, is_netdev
);
2113 dev_info(&vsi
->back
->pdev
->dev
,
2114 "Could not add filter 0 for %pM\n",
2122 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
2123 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
2126 return i40e_sync_vsi_filters(vsi
);
2130 * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
2131 * @vsi: the vsi being configured
2132 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
2134 * Return: 0 on success or negative otherwise
2136 int i40e_vsi_kill_vlan(struct i40e_vsi
*vsi
, s16 vid
)
2138 struct net_device
*netdev
= vsi
->netdev
;
2139 struct i40e_mac_filter
*f
, *add_f
;
2140 bool is_vf
, is_netdev
;
2141 int filter_count
= 0;
2143 is_vf
= (vsi
->type
== I40E_VSI_SRIOV
);
2144 is_netdev
= !!(netdev
);
2147 i40e_del_filter(vsi
, netdev
->dev_addr
, vid
, is_vf
, is_netdev
);
2149 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
)
2150 i40e_del_filter(vsi
, f
->macaddr
, vid
, is_vf
, is_netdev
);
2152 /* go through all the filters for this VSI and if there is only
2153 * vid == 0 it means there are no other filters, so vid 0 must
2154 * be replaced with -1. This signifies that we should from now
2155 * on accept any traffic (with any tag present, or untagged)
2157 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2160 ether_addr_equal(netdev
->dev_addr
, f
->macaddr
))
2168 if (!filter_count
&& is_netdev
) {
2169 i40e_del_filter(vsi
, netdev
->dev_addr
, 0, is_vf
, is_netdev
);
2170 f
= i40e_add_filter(vsi
, netdev
->dev_addr
, I40E_VLAN_ANY
,
2173 dev_info(&vsi
->back
->pdev
->dev
,
2174 "Could not add filter %d for %pM\n",
2175 I40E_VLAN_ANY
, netdev
->dev_addr
);
2180 if (!filter_count
) {
2181 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2182 i40e_del_filter(vsi
, f
->macaddr
, 0, is_vf
, is_netdev
);
2183 add_f
= i40e_add_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2186 dev_info(&vsi
->back
->pdev
->dev
,
2187 "Could not add filter %d for %pM\n",
2188 I40E_VLAN_ANY
, f
->macaddr
);
2194 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
2195 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
2198 return i40e_sync_vsi_filters(vsi
);
2202 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2203 * @netdev: network interface to be adjusted
2204 * @vid: vlan id to be added
2206 * net_device_ops implementation for adding vlan ids
2209 int i40e_vlan_rx_add_vid(struct net_device
*netdev
,
2210 __always_unused __be16 proto
, u16 vid
)
2212 static int i40e_vlan_rx_add_vid(struct net_device
*netdev
,
2213 __always_unused __be16 proto
, u16 vid
)
2216 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2217 struct i40e_vsi
*vsi
= np
->vsi
;
2223 netdev_info(netdev
, "adding %pM vid=%d\n", netdev
->dev_addr
, vid
);
2225 /* If the network stack called us with vid = 0 then
2226 * it is asking to receive priority tagged packets with
2227 * vlan id 0. Our HW receives them by default when configured
2228 * to receive untagged packets so there is no need to add an
2229 * extra filter for vlan 0 tagged packets.
2232 ret
= i40e_vsi_add_vlan(vsi
, vid
);
2234 if (!ret
&& (vid
< VLAN_N_VID
))
2235 set_bit(vid
, vsi
->active_vlans
);
2241 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2242 * @netdev: network interface to be adjusted
2243 * @vid: vlan id to be removed
2245 * net_device_ops implementation for removing vlan ids
2248 int i40e_vlan_rx_kill_vid(struct net_device
*netdev
,
2249 __always_unused __be16 proto
, u16 vid
)
2251 static int i40e_vlan_rx_kill_vid(struct net_device
*netdev
,
2252 __always_unused __be16 proto
, u16 vid
)
2255 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2256 struct i40e_vsi
*vsi
= np
->vsi
;
2258 netdev_info(netdev
, "removing %pM vid=%d\n", netdev
->dev_addr
, vid
);
2260 /* return code is ignored as there is nothing a user
2261 * can do about failure to remove and a log message was
2262 * already printed from the other function
2264 i40e_vsi_kill_vlan(vsi
, vid
);
2266 clear_bit(vid
, vsi
->active_vlans
);
2272 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2273 * @vsi: the vsi being brought back up
2275 static void i40e_restore_vlan(struct i40e_vsi
*vsi
)
2282 i40e_vlan_rx_register(vsi
->netdev
, vsi
->netdev
->features
);
2284 for_each_set_bit(vid
, vsi
->active_vlans
, VLAN_N_VID
)
2285 i40e_vlan_rx_add_vid(vsi
->netdev
, htons(ETH_P_8021Q
),
2290 * i40e_vsi_add_pvid - Add pvid for the VSI
2291 * @vsi: the vsi being adjusted
2292 * @vid: the vlan id to set as a PVID
2294 int i40e_vsi_add_pvid(struct i40e_vsi
*vsi
, u16 vid
)
2296 struct i40e_vsi_context ctxt
;
2299 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2300 vsi
->info
.pvid
= cpu_to_le16(vid
);
2301 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_TAGGED
|
2302 I40E_AQ_VSI_PVLAN_INSERT_PVID
|
2303 I40E_AQ_VSI_PVLAN_EMOD_STR
;
2305 ctxt
.seid
= vsi
->seid
;
2306 ctxt
.info
= vsi
->info
;
2307 aq_ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2309 dev_info(&vsi
->back
->pdev
->dev
,
2310 "%s: update vsi failed, aq_err=%d\n",
2311 __func__
, vsi
->back
->hw
.aq
.asq_last_status
);
2319 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2320 * @vsi: the vsi being adjusted
2322 * Just use the vlan_rx_register() service to put it back to normal
2324 void i40e_vsi_remove_pvid(struct i40e_vsi
*vsi
)
2326 i40e_vlan_stripping_disable(vsi
);
2332 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2333 * @vsi: ptr to the VSI
2335 * If this function returns with an error, then it's possible one or
2336 * more of the rings is populated (while the rest are not). It is the
2337 * callers duty to clean those orphaned rings.
2339 * Return 0 on success, negative on failure
2341 static int i40e_vsi_setup_tx_resources(struct i40e_vsi
*vsi
)
2345 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2346 err
= i40e_setup_tx_descriptors(vsi
->tx_rings
[i
]);
2352 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2353 * @vsi: ptr to the VSI
2355 * Free VSI's transmit software resources
2357 static void i40e_vsi_free_tx_resources(struct i40e_vsi
*vsi
)
2364 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2365 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
)
2366 i40e_free_tx_resources(vsi
->tx_rings
[i
]);
2370 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2371 * @vsi: ptr to the VSI
2373 * If this function returns with an error, then it's possible one or
2374 * more of the rings is populated (while the rest are not). It is the
2375 * callers duty to clean those orphaned rings.
2377 * Return 0 on success, negative on failure
2379 static int i40e_vsi_setup_rx_resources(struct i40e_vsi
*vsi
)
2383 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2384 err
= i40e_setup_rx_descriptors(vsi
->rx_rings
[i
]);
2386 i40e_fcoe_setup_ddp_resources(vsi
);
2392 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2393 * @vsi: ptr to the VSI
2395 * Free all receive software resources
2397 static void i40e_vsi_free_rx_resources(struct i40e_vsi
*vsi
)
2404 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2405 if (vsi
->rx_rings
[i
] && vsi
->rx_rings
[i
]->desc
)
2406 i40e_free_rx_resources(vsi
->rx_rings
[i
]);
2408 i40e_fcoe_free_ddp_resources(vsi
);
2413 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
2414 * @ring: The Tx ring to configure
2416 * This enables/disables XPS for a given Tx descriptor ring
2417 * based on the TCs enabled for the VSI that ring belongs to.
2419 static void i40e_config_xps_tx_ring(struct i40e_ring
*ring
)
2421 struct i40e_vsi
*vsi
= ring
->vsi
;
2424 if (!ring
->q_vector
|| !ring
->netdev
)
2427 /* Single TC mode enable XPS */
2428 if (vsi
->tc_config
.numtc
<= 1) {
2429 if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE
, &ring
->state
))
2430 netif_set_xps_queue(ring
->netdev
,
2431 &ring
->q_vector
->affinity_mask
,
2433 } else if (alloc_cpumask_var(&mask
, GFP_KERNEL
)) {
2434 /* Disable XPS to allow selection based on TC */
2435 bitmap_zero(cpumask_bits(mask
), nr_cpumask_bits
);
2436 netif_set_xps_queue(ring
->netdev
, mask
, ring
->queue_index
);
2437 free_cpumask_var(mask
);
2442 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2443 * @ring: The Tx ring to configure
2445 * Configure the Tx descriptor ring in the HMC context.
2447 static int i40e_configure_tx_ring(struct i40e_ring
*ring
)
2449 struct i40e_vsi
*vsi
= ring
->vsi
;
2450 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
2451 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2452 struct i40e_hmc_obj_txq tx_ctx
;
2453 i40e_status err
= 0;
2456 /* some ATR related tx ring init */
2457 if (vsi
->back
->flags
& I40E_FLAG_FD_ATR_ENABLED
) {
2458 ring
->atr_sample_rate
= vsi
->back
->atr_sample_rate
;
2459 ring
->atr_count
= 0;
2461 ring
->atr_sample_rate
= 0;
2465 i40e_config_xps_tx_ring(ring
);
2467 /* clear the context structure first */
2468 memset(&tx_ctx
, 0, sizeof(tx_ctx
));
2470 tx_ctx
.new_context
= 1;
2471 tx_ctx
.base
= (ring
->dma
/ 128);
2472 tx_ctx
.qlen
= ring
->count
;
2473 tx_ctx
.fd_ena
= !!(vsi
->back
->flags
& (I40E_FLAG_FD_SB_ENABLED
|
2474 I40E_FLAG_FD_ATR_ENABLED
));
2476 tx_ctx
.fc_ena
= (vsi
->type
== I40E_VSI_FCOE
);
2478 tx_ctx
.timesync_ena
= !!(vsi
->back
->flags
& I40E_FLAG_PTP
);
2479 /* FDIR VSI tx ring can still use RS bit and writebacks */
2480 if (vsi
->type
!= I40E_VSI_FDIR
)
2481 tx_ctx
.head_wb_ena
= 1;
2482 tx_ctx
.head_wb_addr
= ring
->dma
+
2483 (ring
->count
* sizeof(struct i40e_tx_desc
));
2485 /* As part of VSI creation/update, FW allocates certain
2486 * Tx arbitration queue sets for each TC enabled for
2487 * the VSI. The FW returns the handles to these queue
2488 * sets as part of the response buffer to Add VSI,
2489 * Update VSI, etc. AQ commands. It is expected that
2490 * these queue set handles be associated with the Tx
2491 * queues by the driver as part of the TX queue context
2492 * initialization. This has to be done regardless of
2493 * DCB as by default everything is mapped to TC0.
2495 tx_ctx
.rdylist
= le16_to_cpu(vsi
->info
.qs_handle
[ring
->dcb_tc
]);
2496 tx_ctx
.rdylist_act
= 0;
2498 /* clear the context in the HMC */
2499 err
= i40e_clear_lan_tx_queue_context(hw
, pf_q
);
2501 dev_info(&vsi
->back
->pdev
->dev
,
2502 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2503 ring
->queue_index
, pf_q
, err
);
2507 /* set the context in the HMC */
2508 err
= i40e_set_lan_tx_queue_context(hw
, pf_q
, &tx_ctx
);
2510 dev_info(&vsi
->back
->pdev
->dev
,
2511 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
2512 ring
->queue_index
, pf_q
, err
);
2516 /* Now associate this queue with this PCI function */
2517 if (vsi
->type
== I40E_VSI_VMDQ2
) {
2518 qtx_ctl
= I40E_QTX_CTL_VM_QUEUE
;
2519 qtx_ctl
|= ((vsi
->id
) << I40E_QTX_CTL_VFVM_INDX_SHIFT
) &
2520 I40E_QTX_CTL_VFVM_INDX_MASK
;
2522 qtx_ctl
= I40E_QTX_CTL_PF_QUEUE
;
2525 qtx_ctl
|= ((hw
->pf_id
<< I40E_QTX_CTL_PF_INDX_SHIFT
) &
2526 I40E_QTX_CTL_PF_INDX_MASK
);
2527 wr32(hw
, I40E_QTX_CTL(pf_q
), qtx_ctl
);
2530 clear_bit(__I40E_HANG_CHECK_ARMED
, &ring
->state
);
2532 /* cache tail off for easier writes later */
2533 ring
->tail
= hw
->hw_addr
+ I40E_QTX_TAIL(pf_q
);
2539 * i40e_configure_rx_ring - Configure a receive ring context
2540 * @ring: The Rx ring to configure
2542 * Configure the Rx descriptor ring in the HMC context.
2544 static int i40e_configure_rx_ring(struct i40e_ring
*ring
)
2546 struct i40e_vsi
*vsi
= ring
->vsi
;
2547 u32 chain_len
= vsi
->back
->hw
.func_caps
.rx_buf_chain_len
;
2548 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
2549 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2550 struct i40e_hmc_obj_rxq rx_ctx
;
2551 i40e_status err
= 0;
2555 /* clear the context structure first */
2556 memset(&rx_ctx
, 0, sizeof(rx_ctx
));
2558 ring
->rx_buf_len
= vsi
->rx_buf_len
;
2559 ring
->rx_hdr_len
= vsi
->rx_hdr_len
;
2561 rx_ctx
.dbuff
= ring
->rx_buf_len
>> I40E_RXQ_CTX_DBUFF_SHIFT
;
2562 rx_ctx
.hbuff
= ring
->rx_hdr_len
>> I40E_RXQ_CTX_HBUFF_SHIFT
;
2564 rx_ctx
.base
= (ring
->dma
/ 128);
2565 rx_ctx
.qlen
= ring
->count
;
2567 if (vsi
->back
->flags
& I40E_FLAG_16BYTE_RX_DESC_ENABLED
) {
2568 set_ring_16byte_desc_enabled(ring
);
2574 rx_ctx
.dtype
= vsi
->dtype
;
2576 set_ring_ps_enabled(ring
);
2577 rx_ctx
.hsplit_0
= I40E_RX_SPLIT_L2
|
2579 I40E_RX_SPLIT_TCP_UDP
|
2582 rx_ctx
.hsplit_0
= 0;
2585 rx_ctx
.rxmax
= min_t(u16
, vsi
->max_frame
,
2586 (chain_len
* ring
->rx_buf_len
));
2587 if (hw
->revision_id
== 0)
2588 rx_ctx
.lrxqthresh
= 0;
2590 rx_ctx
.lrxqthresh
= 2;
2591 rx_ctx
.crcstrip
= 1;
2595 rx_ctx
.fc_ena
= (vsi
->type
== I40E_VSI_FCOE
);
2597 /* set the prefena field to 1 because the manual says to */
2600 /* clear the context in the HMC */
2601 err
= i40e_clear_lan_rx_queue_context(hw
, pf_q
);
2603 dev_info(&vsi
->back
->pdev
->dev
,
2604 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2605 ring
->queue_index
, pf_q
, err
);
2609 /* set the context in the HMC */
2610 err
= i40e_set_lan_rx_queue_context(hw
, pf_q
, &rx_ctx
);
2612 dev_info(&vsi
->back
->pdev
->dev
,
2613 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2614 ring
->queue_index
, pf_q
, err
);
2618 /* cache tail for quicker writes, and clear the reg before use */
2619 ring
->tail
= hw
->hw_addr
+ I40E_QRX_TAIL(pf_q
);
2620 writel(0, ring
->tail
);
2622 if (ring_is_ps_enabled(ring
)) {
2623 i40e_alloc_rx_headers(ring
);
2624 i40e_alloc_rx_buffers_ps(ring
, I40E_DESC_UNUSED(ring
));
2626 i40e_alloc_rx_buffers_1buf(ring
, I40E_DESC_UNUSED(ring
));
2633 * i40e_vsi_configure_tx - Configure the VSI for Tx
2634 * @vsi: VSI structure describing this set of rings and resources
2636 * Configure the Tx VSI for operation.
2638 static int i40e_vsi_configure_tx(struct i40e_vsi
*vsi
)
2643 for (i
= 0; (i
< vsi
->num_queue_pairs
) && !err
; i
++)
2644 err
= i40e_configure_tx_ring(vsi
->tx_rings
[i
]);
2650 * i40e_vsi_configure_rx - Configure the VSI for Rx
2651 * @vsi: the VSI being configured
2653 * Configure the Rx VSI for operation.
2655 static int i40e_vsi_configure_rx(struct i40e_vsi
*vsi
)
2660 if (vsi
->netdev
&& (vsi
->netdev
->mtu
> ETH_DATA_LEN
))
2661 vsi
->max_frame
= vsi
->netdev
->mtu
+ ETH_HLEN
2662 + ETH_FCS_LEN
+ VLAN_HLEN
;
2664 vsi
->max_frame
= I40E_RXBUFFER_2048
;
2666 /* figure out correct receive buffer length */
2667 switch (vsi
->back
->flags
& (I40E_FLAG_RX_1BUF_ENABLED
|
2668 I40E_FLAG_RX_PS_ENABLED
)) {
2669 case I40E_FLAG_RX_1BUF_ENABLED
:
2670 vsi
->rx_hdr_len
= 0;
2671 vsi
->rx_buf_len
= vsi
->max_frame
;
2672 vsi
->dtype
= I40E_RX_DTYPE_NO_SPLIT
;
2674 case I40E_FLAG_RX_PS_ENABLED
:
2675 vsi
->rx_hdr_len
= I40E_RX_HDR_SIZE
;
2676 vsi
->rx_buf_len
= I40E_RXBUFFER_2048
;
2677 vsi
->dtype
= I40E_RX_DTYPE_HEADER_SPLIT
;
2680 vsi
->rx_hdr_len
= I40E_RX_HDR_SIZE
;
2681 vsi
->rx_buf_len
= I40E_RXBUFFER_2048
;
2682 vsi
->dtype
= I40E_RX_DTYPE_SPLIT_ALWAYS
;
2687 /* setup rx buffer for FCoE */
2688 if ((vsi
->type
== I40E_VSI_FCOE
) &&
2689 (vsi
->back
->flags
& I40E_FLAG_FCOE_ENABLED
)) {
2690 vsi
->rx_hdr_len
= 0;
2691 vsi
->rx_buf_len
= I40E_RXBUFFER_3072
;
2692 vsi
->max_frame
= I40E_RXBUFFER_3072
;
2693 vsi
->dtype
= I40E_RX_DTYPE_NO_SPLIT
;
2696 #endif /* I40E_FCOE */
2697 /* round up for the chip's needs */
2698 vsi
->rx_hdr_len
= ALIGN(vsi
->rx_hdr_len
,
2699 (1 << I40E_RXQ_CTX_HBUFF_SHIFT
));
2700 vsi
->rx_buf_len
= ALIGN(vsi
->rx_buf_len
,
2701 (1 << I40E_RXQ_CTX_DBUFF_SHIFT
));
2703 /* set up individual rings */
2704 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2705 err
= i40e_configure_rx_ring(vsi
->rx_rings
[i
]);
2711 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
2712 * @vsi: ptr to the VSI
2714 static void i40e_vsi_config_dcb_rings(struct i40e_vsi
*vsi
)
2716 struct i40e_ring
*tx_ring
, *rx_ring
;
2717 u16 qoffset
, qcount
;
2720 if (!(vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
2721 /* Reset the TC information */
2722 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
2723 rx_ring
= vsi
->rx_rings
[i
];
2724 tx_ring
= vsi
->tx_rings
[i
];
2725 rx_ring
->dcb_tc
= 0;
2726 tx_ring
->dcb_tc
= 0;
2730 for (n
= 0; n
< I40E_MAX_TRAFFIC_CLASS
; n
++) {
2731 if (!(vsi
->tc_config
.enabled_tc
& (1 << n
)))
2734 qoffset
= vsi
->tc_config
.tc_info
[n
].qoffset
;
2735 qcount
= vsi
->tc_config
.tc_info
[n
].qcount
;
2736 for (i
= qoffset
; i
< (qoffset
+ qcount
); i
++) {
2737 rx_ring
= vsi
->rx_rings
[i
];
2738 tx_ring
= vsi
->tx_rings
[i
];
2739 rx_ring
->dcb_tc
= n
;
2740 tx_ring
->dcb_tc
= n
;
2746 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
2747 * @vsi: ptr to the VSI
2749 static void i40e_set_vsi_rx_mode(struct i40e_vsi
*vsi
)
2752 i40e_set_rx_mode(vsi
->netdev
);
2756 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
2757 * @vsi: Pointer to the targeted VSI
2759 * This function replays the hlist on the hw where all the SB Flow Director
2760 * filters were saved.
2762 static void i40e_fdir_filter_restore(struct i40e_vsi
*vsi
)
2764 struct i40e_fdir_filter
*filter
;
2765 struct i40e_pf
*pf
= vsi
->back
;
2766 struct hlist_node
*node
;
2768 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
2771 hlist_for_each_entry_safe(filter
, node
,
2772 &pf
->fdir_filter_list
, fdir_node
) {
2773 i40e_add_del_fdir(vsi
, filter
, true);
2778 * i40e_vsi_configure - Set up the VSI for action
2779 * @vsi: the VSI being configured
2781 static int i40e_vsi_configure(struct i40e_vsi
*vsi
)
2785 i40e_set_vsi_rx_mode(vsi
);
2786 i40e_restore_vlan(vsi
);
2787 i40e_vsi_config_dcb_rings(vsi
);
2788 err
= i40e_vsi_configure_tx(vsi
);
2790 err
= i40e_vsi_configure_rx(vsi
);
2796 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
2797 * @vsi: the VSI being configured
2799 static void i40e_vsi_configure_msix(struct i40e_vsi
*vsi
)
2801 struct i40e_pf
*pf
= vsi
->back
;
2802 struct i40e_q_vector
*q_vector
;
2803 struct i40e_hw
*hw
= &pf
->hw
;
2809 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
2810 * and PFINT_LNKLSTn registers, e.g.:
2811 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
2813 qp
= vsi
->base_queue
;
2814 vector
= vsi
->base_vector
;
2815 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vector
++) {
2816 q_vector
= vsi
->q_vectors
[i
];
2817 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
2818 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
2819 wr32(hw
, I40E_PFINT_ITRN(I40E_RX_ITR
, vector
- 1),
2821 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
2822 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
2823 wr32(hw
, I40E_PFINT_ITRN(I40E_TX_ITR
, vector
- 1),
2826 /* Linked list for the queuepairs assigned to this vector */
2827 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), qp
);
2828 for (q
= 0; q
< q_vector
->num_ringpairs
; q
++) {
2829 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
2830 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
2831 (vector
<< I40E_QINT_RQCTL_MSIX_INDX_SHIFT
) |
2832 (qp
<< I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT
)|
2834 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT
);
2836 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
2838 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
2839 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
2840 (vector
<< I40E_QINT_TQCTL_MSIX_INDX_SHIFT
) |
2841 ((qp
+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
)|
2843 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
2845 /* Terminate the linked list */
2846 if (q
== (q_vector
->num_ringpairs
- 1))
2847 val
|= (I40E_QUEUE_END_OF_LIST
2848 << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
2850 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
2859 * i40e_enable_misc_int_causes - enable the non-queue interrupts
2860 * @hw: ptr to the hardware info
2862 static void i40e_enable_misc_int_causes(struct i40e_pf
*pf
)
2864 struct i40e_hw
*hw
= &pf
->hw
;
2867 /* clear things first */
2868 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0); /* disable all */
2869 rd32(hw
, I40E_PFINT_ICR0
); /* read to clear */
2871 val
= I40E_PFINT_ICR0_ENA_ECC_ERR_MASK
|
2872 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
|
2873 I40E_PFINT_ICR0_ENA_GRST_MASK
|
2874 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK
|
2875 I40E_PFINT_ICR0_ENA_GPIO_MASK
|
2876 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK
|
2877 I40E_PFINT_ICR0_ENA_VFLR_MASK
|
2878 I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
2880 if (pf
->flags
& I40E_FLAG_PTP
)
2881 val
|= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
2883 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
2885 /* SW_ITR_IDX = 0, but don't change INTENA */
2886 wr32(hw
, I40E_PFINT_DYN_CTL0
, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK
|
2887 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK
);
2889 /* OTHER_ITR_IDX = 0 */
2890 wr32(hw
, I40E_PFINT_STAT_CTL0
, 0);
2894 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
2895 * @vsi: the VSI being configured
2897 static void i40e_configure_msi_and_legacy(struct i40e_vsi
*vsi
)
2899 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[0];
2900 struct i40e_pf
*pf
= vsi
->back
;
2901 struct i40e_hw
*hw
= &pf
->hw
;
2904 /* set the ITR configuration */
2905 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
2906 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
2907 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), q_vector
->rx
.itr
);
2908 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
2909 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
2910 wr32(hw
, I40E_PFINT_ITR0(I40E_TX_ITR
), q_vector
->tx
.itr
);
2912 i40e_enable_misc_int_causes(pf
);
2914 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
2915 wr32(hw
, I40E_PFINT_LNKLST0
, 0);
2917 /* Associate the queue pair to the vector and enable the queue int */
2918 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
2919 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
2920 (I40E_QUEUE_TYPE_TX
<< I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
2922 wr32(hw
, I40E_QINT_RQCTL(0), val
);
2924 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
2925 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
2926 (I40E_QUEUE_END_OF_LIST
<< I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
2928 wr32(hw
, I40E_QINT_TQCTL(0), val
);
2933 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
2934 * @pf: board private structure
2936 void i40e_irq_dynamic_disable_icr0(struct i40e_pf
*pf
)
2938 struct i40e_hw
*hw
= &pf
->hw
;
2940 wr32(hw
, I40E_PFINT_DYN_CTL0
,
2941 I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
);
2946 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
2947 * @pf: board private structure
2949 void i40e_irq_dynamic_enable_icr0(struct i40e_pf
*pf
)
2951 struct i40e_hw
*hw
= &pf
->hw
;
2954 val
= I40E_PFINT_DYN_CTL0_INTENA_MASK
|
2955 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK
|
2956 (I40E_ITR_NONE
<< I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT
);
2958 wr32(hw
, I40E_PFINT_DYN_CTL0
, val
);
2963 * i40e_irq_dynamic_enable - Enable default interrupt generation settings
2964 * @vsi: pointer to a vsi
2965 * @vector: enable a particular Hw Interrupt vector
2967 void i40e_irq_dynamic_enable(struct i40e_vsi
*vsi
, int vector
)
2969 struct i40e_pf
*pf
= vsi
->back
;
2970 struct i40e_hw
*hw
= &pf
->hw
;
2973 val
= I40E_PFINT_DYN_CTLN_INTENA_MASK
|
2974 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK
|
2975 (I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
);
2976 wr32(hw
, I40E_PFINT_DYN_CTLN(vector
- 1), val
);
2977 /* skip the flush */
2981 * i40e_irq_dynamic_disable - Disable default interrupt generation settings
2982 * @vsi: pointer to a vsi
2983 * @vector: disable a particular Hw Interrupt vector
2985 void i40e_irq_dynamic_disable(struct i40e_vsi
*vsi
, int vector
)
2987 struct i40e_pf
*pf
= vsi
->back
;
2988 struct i40e_hw
*hw
= &pf
->hw
;
2991 val
= I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
;
2992 wr32(hw
, I40E_PFINT_DYN_CTLN(vector
- 1), val
);
2997 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
2998 * @irq: interrupt number
2999 * @data: pointer to a q_vector
3001 static irqreturn_t
i40e_msix_clean_rings(int irq
, void *data
)
3003 struct i40e_q_vector
*q_vector
= data
;
3005 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
3008 napi_schedule(&q_vector
->napi
);
3014 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3015 * @vsi: the VSI being configured
3016 * @basename: name for the vector
3018 * Allocates MSI-X vectors and requests interrupts from the kernel.
3020 static int i40e_vsi_request_irq_msix(struct i40e_vsi
*vsi
, char *basename
)
3022 int q_vectors
= vsi
->num_q_vectors
;
3023 struct i40e_pf
*pf
= vsi
->back
;
3024 int base
= vsi
->base_vector
;
3029 for (vector
= 0; vector
< q_vectors
; vector
++) {
3030 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[vector
];
3032 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
3033 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3034 "%s-%s-%d", basename
, "TxRx", rx_int_idx
++);
3036 } else if (q_vector
->rx
.ring
) {
3037 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3038 "%s-%s-%d", basename
, "rx", rx_int_idx
++);
3039 } else if (q_vector
->tx
.ring
) {
3040 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
3041 "%s-%s-%d", basename
, "tx", tx_int_idx
++);
3043 /* skip this unused q_vector */
3046 err
= request_irq(pf
->msix_entries
[base
+ vector
].vector
,
3052 dev_info(&pf
->pdev
->dev
,
3053 "%s: request_irq failed, error: %d\n",
3055 goto free_queue_irqs
;
3057 /* assign the mask for this irq */
3058 irq_set_affinity_hint(pf
->msix_entries
[base
+ vector
].vector
,
3059 &q_vector
->affinity_mask
);
3062 vsi
->irqs_ready
= true;
3068 irq_set_affinity_hint(pf
->msix_entries
[base
+ vector
].vector
,
3070 free_irq(pf
->msix_entries
[base
+ vector
].vector
,
3071 &(vsi
->q_vectors
[vector
]));
3077 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3078 * @vsi: the VSI being un-configured
3080 static void i40e_vsi_disable_irq(struct i40e_vsi
*vsi
)
3082 struct i40e_pf
*pf
= vsi
->back
;
3083 struct i40e_hw
*hw
= &pf
->hw
;
3084 int base
= vsi
->base_vector
;
3087 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
3088 wr32(hw
, I40E_QINT_TQCTL(vsi
->tx_rings
[i
]->reg_idx
), 0);
3089 wr32(hw
, I40E_QINT_RQCTL(vsi
->rx_rings
[i
]->reg_idx
), 0);
3092 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3093 for (i
= vsi
->base_vector
;
3094 i
< (vsi
->num_q_vectors
+ vsi
->base_vector
); i
++)
3095 wr32(hw
, I40E_PFINT_DYN_CTLN(i
- 1), 0);
3098 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3099 synchronize_irq(pf
->msix_entries
[i
+ base
].vector
);
3101 /* Legacy and MSI mode - this stops all interrupt handling */
3102 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0);
3103 wr32(hw
, I40E_PFINT_DYN_CTL0
, 0);
3105 synchronize_irq(pf
->pdev
->irq
);
3110 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3111 * @vsi: the VSI being configured
3113 static int i40e_vsi_enable_irq(struct i40e_vsi
*vsi
)
3115 struct i40e_pf
*pf
= vsi
->back
;
3118 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3119 for (i
= vsi
->base_vector
;
3120 i
< (vsi
->num_q_vectors
+ vsi
->base_vector
); i
++)
3121 i40e_irq_dynamic_enable(vsi
, i
);
3123 i40e_irq_dynamic_enable_icr0(pf
);
3126 i40e_flush(&pf
->hw
);
3131 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
3132 * @pf: board private structure
3134 static void i40e_stop_misc_vector(struct i40e_pf
*pf
)
3137 wr32(&pf
->hw
, I40E_PFINT_ICR0_ENA
, 0);
3138 i40e_flush(&pf
->hw
);
3142 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3143 * @irq: interrupt number
3144 * @data: pointer to a q_vector
3146 * This is the handler used for all MSI/Legacy interrupts, and deals
3147 * with both queue and non-queue interrupts. This is also used in
3148 * MSIX mode to handle the non-queue interrupts.
3150 static irqreturn_t
i40e_intr(int irq
, void *data
)
3152 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
3153 struct i40e_hw
*hw
= &pf
->hw
;
3154 irqreturn_t ret
= IRQ_NONE
;
3155 u32 icr0
, icr0_remaining
;
3158 icr0
= rd32(hw
, I40E_PFINT_ICR0
);
3159 ena_mask
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
3161 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
3162 if ((icr0
& I40E_PFINT_ICR0_INTEVENT_MASK
) == 0)
3165 /* if interrupt but no bits showing, must be SWINT */
3166 if (((icr0
& ~I40E_PFINT_ICR0_INTEVENT_MASK
) == 0) ||
3167 (icr0
& I40E_PFINT_ICR0_SWINT_MASK
))
3170 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
3171 if (icr0
& I40E_PFINT_ICR0_QUEUE_0_MASK
) {
3173 /* temporarily disable queue cause for NAPI processing */
3174 u32 qval
= rd32(hw
, I40E_QINT_RQCTL(0));
3175 qval
&= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK
;
3176 wr32(hw
, I40E_QINT_RQCTL(0), qval
);
3178 qval
= rd32(hw
, I40E_QINT_TQCTL(0));
3179 qval
&= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK
;
3180 wr32(hw
, I40E_QINT_TQCTL(0), qval
);
3182 if (!test_bit(__I40E_DOWN
, &pf
->state
))
3183 napi_schedule(&pf
->vsi
[pf
->lan_vsi
]->q_vectors
[0]->napi
);
3186 if (icr0
& I40E_PFINT_ICR0_ADMINQ_MASK
) {
3187 ena_mask
&= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
3188 set_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
);
3191 if (icr0
& I40E_PFINT_ICR0_MAL_DETECT_MASK
) {
3192 ena_mask
&= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
3193 set_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
);
3196 if (icr0
& I40E_PFINT_ICR0_VFLR_MASK
) {
3197 ena_mask
&= ~I40E_PFINT_ICR0_ENA_VFLR_MASK
;
3198 set_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
);
3201 if (icr0
& I40E_PFINT_ICR0_GRST_MASK
) {
3202 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
))
3203 set_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
);
3204 ena_mask
&= ~I40E_PFINT_ICR0_ENA_GRST_MASK
;
3205 val
= rd32(hw
, I40E_GLGEN_RSTAT
);
3206 val
= (val
& I40E_GLGEN_RSTAT_RESET_TYPE_MASK
)
3207 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT
;
3208 if (val
== I40E_RESET_CORER
) {
3210 } else if (val
== I40E_RESET_GLOBR
) {
3212 } else if (val
== I40E_RESET_EMPR
) {
3214 set_bit(__I40E_EMP_RESET_INTR_RECEIVED
, &pf
->state
);
3218 if (icr0
& I40E_PFINT_ICR0_HMC_ERR_MASK
) {
3219 icr0
&= ~I40E_PFINT_ICR0_HMC_ERR_MASK
;
3220 dev_info(&pf
->pdev
->dev
, "HMC error interrupt\n");
3221 dev_info(&pf
->pdev
->dev
, "HMC error info 0x%x, HMC error data 0x%x\n",
3222 rd32(hw
, I40E_PFHMC_ERRORINFO
),
3223 rd32(hw
, I40E_PFHMC_ERRORDATA
));
3226 if (icr0
& I40E_PFINT_ICR0_TIMESYNC_MASK
) {
3227 u32 prttsyn_stat
= rd32(hw
, I40E_PRTTSYN_STAT_0
);
3229 if (prttsyn_stat
& I40E_PRTTSYN_STAT_0_TXTIME_MASK
) {
3230 icr0
&= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
3231 i40e_ptp_tx_hwtstamp(pf
);
3235 /* If a critical error is pending we have no choice but to reset the
3237 * Report and mask out any remaining unexpected interrupts.
3239 icr0_remaining
= icr0
& ena_mask
;
3240 if (icr0_remaining
) {
3241 dev_info(&pf
->pdev
->dev
, "unhandled interrupt icr0=0x%08x\n",
3243 if ((icr0_remaining
& I40E_PFINT_ICR0_PE_CRITERR_MASK
) ||
3244 (icr0_remaining
& I40E_PFINT_ICR0_PCI_EXCEPTION_MASK
) ||
3245 (icr0_remaining
& I40E_PFINT_ICR0_ECC_ERR_MASK
)) {
3246 dev_info(&pf
->pdev
->dev
, "device will be reset\n");
3247 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
3248 i40e_service_event_schedule(pf
);
3250 ena_mask
&= ~icr0_remaining
;
3255 /* re-enable interrupt causes */
3256 wr32(hw
, I40E_PFINT_ICR0_ENA
, ena_mask
);
3257 if (!test_bit(__I40E_DOWN
, &pf
->state
)) {
3258 i40e_service_event_schedule(pf
);
3259 i40e_irq_dynamic_enable_icr0(pf
);
3266 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3267 * @tx_ring: tx ring to clean
3268 * @budget: how many cleans we're allowed
3270 * Returns true if there's any budget left (e.g. the clean is finished)
3272 static bool i40e_clean_fdir_tx_irq(struct i40e_ring
*tx_ring
, int budget
)
3274 struct i40e_vsi
*vsi
= tx_ring
->vsi
;
3275 u16 i
= tx_ring
->next_to_clean
;
3276 struct i40e_tx_buffer
*tx_buf
;
3277 struct i40e_tx_desc
*tx_desc
;
3279 tx_buf
= &tx_ring
->tx_bi
[i
];
3280 tx_desc
= I40E_TX_DESC(tx_ring
, i
);
3281 i
-= tx_ring
->count
;
3284 struct i40e_tx_desc
*eop_desc
= tx_buf
->next_to_watch
;
3286 /* if next_to_watch is not set then there is no work pending */
3290 /* prevent any other reads prior to eop_desc */
3291 read_barrier_depends();
3293 /* if the descriptor isn't done, no work yet to do */
3294 if (!(eop_desc
->cmd_type_offset_bsz
&
3295 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE
)))
3298 /* clear next_to_watch to prevent false hangs */
3299 tx_buf
->next_to_watch
= NULL
;
3301 tx_desc
->buffer_addr
= 0;
3302 tx_desc
->cmd_type_offset_bsz
= 0;
3303 /* move past filter desc */
3308 i
-= tx_ring
->count
;
3309 tx_buf
= tx_ring
->tx_bi
;
3310 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
3312 /* unmap skb header data */
3313 dma_unmap_single(tx_ring
->dev
,
3314 dma_unmap_addr(tx_buf
, dma
),
3315 dma_unmap_len(tx_buf
, len
),
3317 if (tx_buf
->tx_flags
& I40E_TX_FLAGS_FD_SB
)
3318 kfree(tx_buf
->raw_buf
);
3320 tx_buf
->raw_buf
= NULL
;
3321 tx_buf
->tx_flags
= 0;
3322 tx_buf
->next_to_watch
= NULL
;
3323 dma_unmap_len_set(tx_buf
, len
, 0);
3324 tx_desc
->buffer_addr
= 0;
3325 tx_desc
->cmd_type_offset_bsz
= 0;
3327 /* move us past the eop_desc for start of next FD desc */
3332 i
-= tx_ring
->count
;
3333 tx_buf
= tx_ring
->tx_bi
;
3334 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
3337 /* update budget accounting */
3339 } while (likely(budget
));
3341 i
+= tx_ring
->count
;
3342 tx_ring
->next_to_clean
= i
;
3344 if (vsi
->back
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3345 i40e_irq_dynamic_enable(vsi
,
3346 tx_ring
->q_vector
->v_idx
+ vsi
->base_vector
);
3352 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
3353 * @irq: interrupt number
3354 * @data: pointer to a q_vector
3356 static irqreturn_t
i40e_fdir_clean_ring(int irq
, void *data
)
3358 struct i40e_q_vector
*q_vector
= data
;
3359 struct i40e_vsi
*vsi
;
3361 if (!q_vector
->tx
.ring
)
3364 vsi
= q_vector
->tx
.ring
->vsi
;
3365 i40e_clean_fdir_tx_irq(q_vector
->tx
.ring
, vsi
->work_limit
);
3371 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
3372 * @vsi: the VSI being configured
3373 * @v_idx: vector index
3374 * @qp_idx: queue pair index
3376 static void map_vector_to_qp(struct i40e_vsi
*vsi
, int v_idx
, int qp_idx
)
3378 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
3379 struct i40e_ring
*tx_ring
= vsi
->tx_rings
[qp_idx
];
3380 struct i40e_ring
*rx_ring
= vsi
->rx_rings
[qp_idx
];
3382 tx_ring
->q_vector
= q_vector
;
3383 tx_ring
->next
= q_vector
->tx
.ring
;
3384 q_vector
->tx
.ring
= tx_ring
;
3385 q_vector
->tx
.count
++;
3387 rx_ring
->q_vector
= q_vector
;
3388 rx_ring
->next
= q_vector
->rx
.ring
;
3389 q_vector
->rx
.ring
= rx_ring
;
3390 q_vector
->rx
.count
++;
3394 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
3395 * @vsi: the VSI being configured
3397 * This function maps descriptor rings to the queue-specific vectors
3398 * we were allotted through the MSI-X enabling code. Ideally, we'd have
3399 * one vector per queue pair, but on a constrained vector budget, we
3400 * group the queue pairs as "efficiently" as possible.
3402 static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi
*vsi
)
3404 int qp_remaining
= vsi
->num_queue_pairs
;
3405 int q_vectors
= vsi
->num_q_vectors
;
3410 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
3411 * group them so there are multiple queues per vector.
3412 * It is also important to go through all the vectors available to be
3413 * sure that if we don't use all the vectors, that the remaining vectors
3414 * are cleared. This is especially important when decreasing the
3415 * number of queues in use.
3417 for (; v_start
< q_vectors
; v_start
++) {
3418 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_start
];
3420 num_ringpairs
= DIV_ROUND_UP(qp_remaining
, q_vectors
- v_start
);
3422 q_vector
->num_ringpairs
= num_ringpairs
;
3424 q_vector
->rx
.count
= 0;
3425 q_vector
->tx
.count
= 0;
3426 q_vector
->rx
.ring
= NULL
;
3427 q_vector
->tx
.ring
= NULL
;
3429 while (num_ringpairs
--) {
3430 map_vector_to_qp(vsi
, v_start
, qp_idx
);
3438 * i40e_vsi_request_irq - Request IRQ from the OS
3439 * @vsi: the VSI being configured
3440 * @basename: name for the vector
3442 static int i40e_vsi_request_irq(struct i40e_vsi
*vsi
, char *basename
)
3444 struct i40e_pf
*pf
= vsi
->back
;
3447 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
3448 err
= i40e_vsi_request_irq_msix(vsi
, basename
);
3449 else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
)
3450 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, 0,
3453 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, IRQF_SHARED
,
3457 dev_info(&pf
->pdev
->dev
, "request_irq failed, Error %d\n", err
);
3462 #ifdef CONFIG_NET_POLL_CONTROLLER
3464 * i40e_netpoll - A Polling 'interrupt'handler
3465 * @netdev: network interface device structure
3467 * This is used by netconsole to send skbs without having to re-enable
3468 * interrupts. It's not called while the normal interrupt routine is executing.
3471 void i40e_netpoll(struct net_device
*netdev
)
3473 static void i40e_netpoll(struct net_device
*netdev
)
3476 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3477 struct i40e_vsi
*vsi
= np
->vsi
;
3478 struct i40e_pf
*pf
= vsi
->back
;
3481 /* if interface is down do nothing */
3482 if (test_bit(__I40E_DOWN
, &vsi
->state
))
3485 pf
->flags
|= I40E_FLAG_IN_NETPOLL
;
3486 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3487 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3488 i40e_msix_clean_rings(0, vsi
->q_vectors
[i
]);
3490 i40e_intr(pf
->pdev
->irq
, netdev
);
3492 pf
->flags
&= ~I40E_FLAG_IN_NETPOLL
;
3497 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
3498 * @pf: the PF being configured
3499 * @pf_q: the PF queue
3500 * @enable: enable or disable state of the queue
3502 * This routine will wait for the given Tx queue of the PF to reach the
3503 * enabled or disabled state.
3504 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3505 * multiple retries; else will return 0 in case of success.
3507 static int i40e_pf_txq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
3512 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
3513 tx_reg
= rd32(&pf
->hw
, I40E_QTX_ENA(pf_q
));
3514 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
3517 usleep_range(10, 20);
3519 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
3526 * i40e_vsi_control_tx - Start or stop a VSI's rings
3527 * @vsi: the VSI being configured
3528 * @enable: start or stop the rings
3530 static int i40e_vsi_control_tx(struct i40e_vsi
*vsi
, bool enable
)
3532 struct i40e_pf
*pf
= vsi
->back
;
3533 struct i40e_hw
*hw
= &pf
->hw
;
3534 int i
, j
, pf_q
, ret
= 0;
3537 pf_q
= vsi
->base_queue
;
3538 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
3540 /* warn the TX unit of coming changes */
3541 i40e_pre_tx_queue_cfg(&pf
->hw
, pf_q
, enable
);
3543 usleep_range(10, 20);
3545 for (j
= 0; j
< 50; j
++) {
3546 tx_reg
= rd32(hw
, I40E_QTX_ENA(pf_q
));
3547 if (((tx_reg
>> I40E_QTX_ENA_QENA_REQ_SHIFT
) & 1) ==
3548 ((tx_reg
>> I40E_QTX_ENA_QENA_STAT_SHIFT
) & 1))
3550 usleep_range(1000, 2000);
3552 /* Skip if the queue is already in the requested state */
3553 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
3556 /* turn on/off the queue */
3558 wr32(hw
, I40E_QTX_HEAD(pf_q
), 0);
3559 tx_reg
|= I40E_QTX_ENA_QENA_REQ_MASK
;
3561 tx_reg
&= ~I40E_QTX_ENA_QENA_REQ_MASK
;
3564 wr32(hw
, I40E_QTX_ENA(pf_q
), tx_reg
);
3565 /* No waiting for the Tx queue to disable */
3566 if (!enable
&& test_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
))
3569 /* wait for the change to finish */
3570 ret
= i40e_pf_txq_wait(pf
, pf_q
, enable
);
3572 dev_info(&pf
->pdev
->dev
,
3573 "%s: VSI seid %d Tx ring %d %sable timeout\n",
3574 __func__
, vsi
->seid
, pf_q
,
3575 (enable
? "en" : "dis"));
3580 if (hw
->revision_id
== 0)
3586 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
3587 * @pf: the PF being configured
3588 * @pf_q: the PF queue
3589 * @enable: enable or disable state of the queue
3591 * This routine will wait for the given Rx queue of the PF to reach the
3592 * enabled or disabled state.
3593 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3594 * multiple retries; else will return 0 in case of success.
3596 static int i40e_pf_rxq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
3601 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
3602 rx_reg
= rd32(&pf
->hw
, I40E_QRX_ENA(pf_q
));
3603 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
3606 usleep_range(10, 20);
3608 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
3615 * i40e_vsi_control_rx - Start or stop a VSI's rings
3616 * @vsi: the VSI being configured
3617 * @enable: start or stop the rings
3619 static int i40e_vsi_control_rx(struct i40e_vsi
*vsi
, bool enable
)
3621 struct i40e_pf
*pf
= vsi
->back
;
3622 struct i40e_hw
*hw
= &pf
->hw
;
3623 int i
, j
, pf_q
, ret
= 0;
3626 pf_q
= vsi
->base_queue
;
3627 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
3628 for (j
= 0; j
< 50; j
++) {
3629 rx_reg
= rd32(hw
, I40E_QRX_ENA(pf_q
));
3630 if (((rx_reg
>> I40E_QRX_ENA_QENA_REQ_SHIFT
) & 1) ==
3631 ((rx_reg
>> I40E_QRX_ENA_QENA_STAT_SHIFT
) & 1))
3633 usleep_range(1000, 2000);
3636 /* Skip if the queue is already in the requested state */
3637 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
3640 /* turn on/off the queue */
3642 rx_reg
|= I40E_QRX_ENA_QENA_REQ_MASK
;
3644 rx_reg
&= ~I40E_QRX_ENA_QENA_REQ_MASK
;
3645 wr32(hw
, I40E_QRX_ENA(pf_q
), rx_reg
);
3647 /* wait for the change to finish */
3648 ret
= i40e_pf_rxq_wait(pf
, pf_q
, enable
);
3650 dev_info(&pf
->pdev
->dev
,
3651 "%s: VSI seid %d Rx ring %d %sable timeout\n",
3652 __func__
, vsi
->seid
, pf_q
,
3653 (enable
? "en" : "dis"));
3662 * i40e_vsi_control_rings - Start or stop a VSI's rings
3663 * @vsi: the VSI being configured
3664 * @enable: start or stop the rings
3666 int i40e_vsi_control_rings(struct i40e_vsi
*vsi
, bool request
)
3670 /* do rx first for enable and last for disable */
3672 ret
= i40e_vsi_control_rx(vsi
, request
);
3675 ret
= i40e_vsi_control_tx(vsi
, request
);
3677 /* Ignore return value, we need to shutdown whatever we can */
3678 i40e_vsi_control_tx(vsi
, request
);
3679 i40e_vsi_control_rx(vsi
, request
);
3686 * i40e_vsi_free_irq - Free the irq association with the OS
3687 * @vsi: the VSI being configured
3689 static void i40e_vsi_free_irq(struct i40e_vsi
*vsi
)
3691 struct i40e_pf
*pf
= vsi
->back
;
3692 struct i40e_hw
*hw
= &pf
->hw
;
3693 int base
= vsi
->base_vector
;
3697 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3698 if (!vsi
->q_vectors
)
3701 if (!vsi
->irqs_ready
)
3704 vsi
->irqs_ready
= false;
3705 for (i
= 0; i
< vsi
->num_q_vectors
; i
++) {
3706 u16 vector
= i
+ base
;
3708 /* free only the irqs that were actually requested */
3709 if (!vsi
->q_vectors
[i
] ||
3710 !vsi
->q_vectors
[i
]->num_ringpairs
)
3713 /* clear the affinity_mask in the IRQ descriptor */
3714 irq_set_affinity_hint(pf
->msix_entries
[vector
].vector
,
3716 free_irq(pf
->msix_entries
[vector
].vector
,
3719 /* Tear down the interrupt queue link list
3721 * We know that they come in pairs and always
3722 * the Rx first, then the Tx. To clear the
3723 * link list, stick the EOL value into the
3724 * next_q field of the registers.
3726 val
= rd32(hw
, I40E_PFINT_LNKLSTN(vector
- 1));
3727 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
3728 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
3729 val
|= I40E_QUEUE_END_OF_LIST
3730 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
3731 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), val
);
3733 while (qp
!= I40E_QUEUE_END_OF_LIST
) {
3736 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
3738 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
3739 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
3740 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3741 I40E_QINT_RQCTL_INTEVENT_MASK
);
3743 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
3744 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
3746 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
3748 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
3750 next
= (val
& I40E_QINT_TQCTL_NEXTQ_INDX_MASK
)
3751 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
;
3753 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
3754 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
3755 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3756 I40E_QINT_TQCTL_INTEVENT_MASK
);
3758 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
3759 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
3761 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
3766 free_irq(pf
->pdev
->irq
, pf
);
3768 val
= rd32(hw
, I40E_PFINT_LNKLST0
);
3769 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
3770 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
3771 val
|= I40E_QUEUE_END_OF_LIST
3772 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT
;
3773 wr32(hw
, I40E_PFINT_LNKLST0
, val
);
3775 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
3776 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
3777 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
3778 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3779 I40E_QINT_RQCTL_INTEVENT_MASK
);
3781 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
3782 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
3784 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
3786 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
3788 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
3789 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
3790 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3791 I40E_QINT_TQCTL_INTEVENT_MASK
);
3793 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
3794 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
3796 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
3801 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
3802 * @vsi: the VSI being configured
3803 * @v_idx: Index of vector to be freed
3805 * This function frees the memory allocated to the q_vector. In addition if
3806 * NAPI is enabled it will delete any references to the NAPI struct prior
3807 * to freeing the q_vector.
3809 static void i40e_free_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
3811 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
3812 struct i40e_ring
*ring
;
3817 /* disassociate q_vector from rings */
3818 i40e_for_each_ring(ring
, q_vector
->tx
)
3819 ring
->q_vector
= NULL
;
3821 i40e_for_each_ring(ring
, q_vector
->rx
)
3822 ring
->q_vector
= NULL
;
3824 /* only VSI w/ an associated netdev is set up w/ NAPI */
3826 netif_napi_del(&q_vector
->napi
);
3828 vsi
->q_vectors
[v_idx
] = NULL
;
3830 kfree_rcu(q_vector
, rcu
);
3834 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
3835 * @vsi: the VSI being un-configured
3837 * This frees the memory allocated to the q_vectors and
3838 * deletes references to the NAPI struct.
3840 static void i40e_vsi_free_q_vectors(struct i40e_vsi
*vsi
)
3844 for (v_idx
= 0; v_idx
< vsi
->num_q_vectors
; v_idx
++)
3845 i40e_free_q_vector(vsi
, v_idx
);
3849 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
3850 * @pf: board private structure
3852 static void i40e_reset_interrupt_capability(struct i40e_pf
*pf
)
3854 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
3855 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3856 pci_disable_msix(pf
->pdev
);
3857 kfree(pf
->msix_entries
);
3858 pf
->msix_entries
= NULL
;
3859 kfree(pf
->irq_pile
);
3860 pf
->irq_pile
= NULL
;
3861 } else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
) {
3862 pci_disable_msi(pf
->pdev
);
3864 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
);
3868 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
3869 * @pf: board private structure
3871 * We go through and clear interrupt specific resources and reset the structure
3872 * to pre-load conditions
3874 static void i40e_clear_interrupt_scheme(struct i40e_pf
*pf
)
3878 i40e_stop_misc_vector(pf
);
3879 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3880 synchronize_irq(pf
->msix_entries
[0].vector
);
3881 free_irq(pf
->msix_entries
[0].vector
, pf
);
3884 i40e_put_lump(pf
->irq_pile
, 0, I40E_PILE_VALID_BIT
-1);
3885 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
3887 i40e_vsi_free_q_vectors(pf
->vsi
[i
]);
3888 i40e_reset_interrupt_capability(pf
);
3892 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
3893 * @vsi: the VSI being configured
3895 static void i40e_napi_enable_all(struct i40e_vsi
*vsi
)
3902 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++)
3903 napi_enable(&vsi
->q_vectors
[q_idx
]->napi
);
3907 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
3908 * @vsi: the VSI being configured
3910 static void i40e_napi_disable_all(struct i40e_vsi
*vsi
)
3917 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++)
3918 napi_disable(&vsi
->q_vectors
[q_idx
]->napi
);
3922 * i40e_vsi_close - Shut down a VSI
3923 * @vsi: the vsi to be quelled
3925 static void i40e_vsi_close(struct i40e_vsi
*vsi
)
3927 if (!test_and_set_bit(__I40E_DOWN
, &vsi
->state
))
3929 i40e_vsi_free_irq(vsi
);
3930 i40e_vsi_free_tx_resources(vsi
);
3931 i40e_vsi_free_rx_resources(vsi
);
3935 * i40e_quiesce_vsi - Pause a given VSI
3936 * @vsi: the VSI being paused
3938 static void i40e_quiesce_vsi(struct i40e_vsi
*vsi
)
3940 if (test_bit(__I40E_DOWN
, &vsi
->state
))
3943 /* No need to disable FCoE VSI when Tx suspended */
3944 if ((test_bit(__I40E_PORT_TX_SUSPENDED
, &vsi
->back
->state
)) &&
3945 vsi
->type
== I40E_VSI_FCOE
) {
3946 dev_dbg(&vsi
->back
->pdev
->dev
,
3947 "%s: VSI seid %d skipping FCoE VSI disable\n",
3948 __func__
, vsi
->seid
);
3952 set_bit(__I40E_NEEDS_RESTART
, &vsi
->state
);
3953 if (vsi
->netdev
&& netif_running(vsi
->netdev
)) {
3954 vsi
->netdev
->netdev_ops
->ndo_stop(vsi
->netdev
);
3956 i40e_vsi_close(vsi
);
3961 * i40e_unquiesce_vsi - Resume a given VSI
3962 * @vsi: the VSI being resumed
3964 static void i40e_unquiesce_vsi(struct i40e_vsi
*vsi
)
3966 if (!test_bit(__I40E_NEEDS_RESTART
, &vsi
->state
))
3969 clear_bit(__I40E_NEEDS_RESTART
, &vsi
->state
);
3970 if (vsi
->netdev
&& netif_running(vsi
->netdev
))
3971 vsi
->netdev
->netdev_ops
->ndo_open(vsi
->netdev
);
3973 i40e_vsi_open(vsi
); /* this clears the DOWN bit */
3977 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
3980 static void i40e_pf_quiesce_all_vsi(struct i40e_pf
*pf
)
3984 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
3986 i40e_quiesce_vsi(pf
->vsi
[v
]);
3991 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
3994 static void i40e_pf_unquiesce_all_vsi(struct i40e_pf
*pf
)
3998 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4000 i40e_unquiesce_vsi(pf
->vsi
[v
]);
4004 #ifdef CONFIG_I40E_DCB
4006 * i40e_vsi_wait_txq_disabled - Wait for VSI's queues to be disabled
4007 * @vsi: the VSI being configured
4009 * This function waits for the given VSI's Tx queues to be disabled.
4011 static int i40e_vsi_wait_txq_disabled(struct i40e_vsi
*vsi
)
4013 struct i40e_pf
*pf
= vsi
->back
;
4016 pf_q
= vsi
->base_queue
;
4017 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
4018 /* Check and wait for the disable status of the queue */
4019 ret
= i40e_pf_txq_wait(pf
, pf_q
, false);
4021 dev_info(&pf
->pdev
->dev
,
4022 "%s: VSI seid %d Tx ring %d disable timeout\n",
4023 __func__
, vsi
->seid
, pf_q
);
4032 * i40e_pf_wait_txq_disabled - Wait for all queues of PF VSIs to be disabled
4035 * This function waits for the Tx queues to be in disabled state for all the
4036 * VSIs that are managed by this PF.
4038 static int i40e_pf_wait_txq_disabled(struct i40e_pf
*pf
)
4042 for (v
= 0; v
< pf
->hw
.func_caps
.num_vsis
; v
++) {
4043 /* No need to wait for FCoE VSI queues */
4044 if (pf
->vsi
[v
] && pf
->vsi
[v
]->type
!= I40E_VSI_FCOE
) {
4045 ret
= i40e_vsi_wait_txq_disabled(pf
->vsi
[v
]);
4056 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
4057 * @pf: pointer to PF
4059 * Get TC map for ISCSI PF type that will include iSCSI TC
4062 static u8
i40e_get_iscsi_tc_map(struct i40e_pf
*pf
)
4064 struct i40e_dcb_app_priority_table app
;
4065 struct i40e_hw
*hw
= &pf
->hw
;
4066 u8 enabled_tc
= 1; /* TC0 is always enabled */
4068 /* Get the iSCSI APP TLV */
4069 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4071 for (i
= 0; i
< dcbcfg
->numapps
; i
++) {
4072 app
= dcbcfg
->app
[i
];
4073 if (app
.selector
== I40E_APP_SEL_TCPIP
&&
4074 app
.protocolid
== I40E_APP_PROTOID_ISCSI
) {
4075 tc
= dcbcfg
->etscfg
.prioritytable
[app
.priority
];
4076 enabled_tc
|= (1 << tc
);
4085 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
4086 * @dcbcfg: the corresponding DCBx configuration structure
4088 * Return the number of TCs from given DCBx configuration
4090 static u8
i40e_dcb_get_num_tc(struct i40e_dcbx_config
*dcbcfg
)
4095 /* Scan the ETS Config Priority Table to find
4096 * traffic class enabled for a given priority
4097 * and use the traffic class index to get the
4098 * number of traffic classes enabled
4100 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
4101 if (dcbcfg
->etscfg
.prioritytable
[i
] > num_tc
)
4102 num_tc
= dcbcfg
->etscfg
.prioritytable
[i
];
4105 /* Traffic class index starts from zero so
4106 * increment to return the actual count
4112 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
4113 * @dcbcfg: the corresponding DCBx configuration structure
4115 * Query the current DCB configuration and return the number of
4116 * traffic classes enabled from the given DCBX config
4118 static u8
i40e_dcb_get_enabled_tc(struct i40e_dcbx_config
*dcbcfg
)
4120 u8 num_tc
= i40e_dcb_get_num_tc(dcbcfg
);
4124 for (i
= 0; i
< num_tc
; i
++)
4125 enabled_tc
|= 1 << i
;
4131 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
4132 * @pf: PF being queried
4134 * Return number of traffic classes enabled for the given PF
4136 static u8
i40e_pf_get_num_tc(struct i40e_pf
*pf
)
4138 struct i40e_hw
*hw
= &pf
->hw
;
4141 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4143 /* If DCB is not enabled then always in single TC */
4144 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
4147 /* SFP mode will be enabled for all TCs on port */
4148 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
4149 return i40e_dcb_get_num_tc(dcbcfg
);
4151 /* MFP mode return count of enabled TCs for this PF */
4152 if (pf
->hw
.func_caps
.iscsi
)
4153 enabled_tc
= i40e_get_iscsi_tc_map(pf
);
4155 return 1; /* Only TC0 */
4157 /* At least have TC0 */
4158 enabled_tc
= (enabled_tc
? enabled_tc
: 0x1);
4159 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4160 if (enabled_tc
& (1 << i
))
4167 * i40e_pf_get_default_tc - Get bitmap for first enabled TC
4168 * @pf: PF being queried
4170 * Return a bitmap for first enabled traffic class for this PF.
4172 static u8
i40e_pf_get_default_tc(struct i40e_pf
*pf
)
4174 u8 enabled_tc
= pf
->hw
.func_caps
.enabled_tcmap
;
4178 return 0x1; /* TC0 */
4180 /* Find the first enabled TC */
4181 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4182 if (enabled_tc
& (1 << i
))
4190 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
4191 * @pf: PF being queried
4193 * Return a bitmap for enabled traffic classes for this PF.
4195 static u8
i40e_pf_get_tc_map(struct i40e_pf
*pf
)
4197 /* If DCB is not enabled for this PF then just return default TC */
4198 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
4199 return i40e_pf_get_default_tc(pf
);
4201 /* SFP mode we want PF to be enabled for all TCs */
4202 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
4203 return i40e_dcb_get_enabled_tc(&pf
->hw
.local_dcbx_config
);
4205 /* MFP enabled and iSCSI PF type */
4206 if (pf
->hw
.func_caps
.iscsi
)
4207 return i40e_get_iscsi_tc_map(pf
);
4209 return i40e_pf_get_default_tc(pf
);
4213 * i40e_vsi_get_bw_info - Query VSI BW Information
4214 * @vsi: the VSI being queried
4216 * Returns 0 on success, negative value on failure
4218 static int i40e_vsi_get_bw_info(struct i40e_vsi
*vsi
)
4220 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config
= {0};
4221 struct i40e_aqc_query_vsi_bw_config_resp bw_config
= {0};
4222 struct i40e_pf
*pf
= vsi
->back
;
4223 struct i40e_hw
*hw
= &pf
->hw
;
4228 /* Get the VSI level BW configuration */
4229 aq_ret
= i40e_aq_query_vsi_bw_config(hw
, vsi
->seid
, &bw_config
, NULL
);
4231 dev_info(&pf
->pdev
->dev
,
4232 "couldn't get PF vsi bw config, err %d, aq_err %d\n",
4233 aq_ret
, pf
->hw
.aq
.asq_last_status
);
4237 /* Get the VSI level BW configuration per TC */
4238 aq_ret
= i40e_aq_query_vsi_ets_sla_config(hw
, vsi
->seid
, &bw_ets_config
,
4241 dev_info(&pf
->pdev
->dev
,
4242 "couldn't get PF vsi ets bw config, err %d, aq_err %d\n",
4243 aq_ret
, pf
->hw
.aq
.asq_last_status
);
4247 if (bw_config
.tc_valid_bits
!= bw_ets_config
.tc_valid_bits
) {
4248 dev_info(&pf
->pdev
->dev
,
4249 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
4250 bw_config
.tc_valid_bits
,
4251 bw_ets_config
.tc_valid_bits
);
4252 /* Still continuing */
4255 vsi
->bw_limit
= le16_to_cpu(bw_config
.port_bw_limit
);
4256 vsi
->bw_max_quanta
= bw_config
.max_bw
;
4257 tc_bw_max
= le16_to_cpu(bw_ets_config
.tc_bw_max
[0]) |
4258 (le16_to_cpu(bw_ets_config
.tc_bw_max
[1]) << 16);
4259 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4260 vsi
->bw_ets_share_credits
[i
] = bw_ets_config
.share_credits
[i
];
4261 vsi
->bw_ets_limit_credits
[i
] =
4262 le16_to_cpu(bw_ets_config
.credits
[i
]);
4263 /* 3 bits out of 4 for each TC */
4264 vsi
->bw_ets_max_quanta
[i
] = (u8
)((tc_bw_max
>> (i
*4)) & 0x7);
4271 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
4272 * @vsi: the VSI being configured
4273 * @enabled_tc: TC bitmap
4274 * @bw_credits: BW shared credits per TC
4276 * Returns 0 on success, negative value on failure
4278 static int i40e_vsi_configure_bw_alloc(struct i40e_vsi
*vsi
, u8 enabled_tc
,
4281 struct i40e_aqc_configure_vsi_tc_bw_data bw_data
;
4285 bw_data
.tc_valid_bits
= enabled_tc
;
4286 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
4287 bw_data
.tc_bw_credits
[i
] = bw_share
[i
];
4289 aq_ret
= i40e_aq_config_vsi_tc_bw(&vsi
->back
->hw
, vsi
->seid
, &bw_data
,
4292 dev_info(&vsi
->back
->pdev
->dev
,
4293 "AQ command Config VSI BW allocation per TC failed = %d\n",
4294 vsi
->back
->hw
.aq
.asq_last_status
);
4298 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
4299 vsi
->info
.qs_handle
[i
] = bw_data
.qs_handles
[i
];
4305 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
4306 * @vsi: the VSI being configured
4307 * @enabled_tc: TC map to be enabled
4310 static void i40e_vsi_config_netdev_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
4312 struct net_device
*netdev
= vsi
->netdev
;
4313 struct i40e_pf
*pf
= vsi
->back
;
4314 struct i40e_hw
*hw
= &pf
->hw
;
4317 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4323 netdev_reset_tc(netdev
);
4327 /* Set up actual enabled TCs on the VSI */
4328 if (netdev_set_num_tc(netdev
, vsi
->tc_config
.numtc
))
4331 /* set per TC queues for the VSI */
4332 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4333 /* Only set TC queues for enabled tcs
4335 * e.g. For a VSI that has TC0 and TC3 enabled the
4336 * enabled_tc bitmap would be 0x00001001; the driver
4337 * will set the numtc for netdev as 2 that will be
4338 * referenced by the netdev layer as TC 0 and 1.
4340 if (vsi
->tc_config
.enabled_tc
& (1 << i
))
4341 netdev_set_tc_queue(netdev
,
4342 vsi
->tc_config
.tc_info
[i
].netdev_tc
,
4343 vsi
->tc_config
.tc_info
[i
].qcount
,
4344 vsi
->tc_config
.tc_info
[i
].qoffset
);
4347 /* Assign UP2TC map for the VSI */
4348 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
4349 /* Get the actual TC# for the UP */
4350 u8 ets_tc
= dcbcfg
->etscfg
.prioritytable
[i
];
4351 /* Get the mapped netdev TC# for the UP */
4352 netdev_tc
= vsi
->tc_config
.tc_info
[ets_tc
].netdev_tc
;
4353 netdev_set_prio_tc_map(netdev
, i
, netdev_tc
);
4358 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
4359 * @vsi: the VSI being configured
4360 * @ctxt: the ctxt buffer returned from AQ VSI update param command
4362 static void i40e_vsi_update_queue_map(struct i40e_vsi
*vsi
,
4363 struct i40e_vsi_context
*ctxt
)
4365 /* copy just the sections touched not the entire info
4366 * since not all sections are valid as returned by
4369 vsi
->info
.mapping_flags
= ctxt
->info
.mapping_flags
;
4370 memcpy(&vsi
->info
.queue_mapping
,
4371 &ctxt
->info
.queue_mapping
, sizeof(vsi
->info
.queue_mapping
));
4372 memcpy(&vsi
->info
.tc_mapping
, ctxt
->info
.tc_mapping
,
4373 sizeof(vsi
->info
.tc_mapping
));
4377 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
4378 * @vsi: VSI to be configured
4379 * @enabled_tc: TC bitmap
4381 * This configures a particular VSI for TCs that are mapped to the
4382 * given TC bitmap. It uses default bandwidth share for TCs across
4383 * VSIs to configure TC for a particular VSI.
4386 * It is expected that the VSI queues have been quisced before calling
4389 static int i40e_vsi_config_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
4391 u8 bw_share
[I40E_MAX_TRAFFIC_CLASS
] = {0};
4392 struct i40e_vsi_context ctxt
;
4396 /* Check if enabled_tc is same as existing or new TCs */
4397 if (vsi
->tc_config
.enabled_tc
== enabled_tc
)
4400 /* Enable ETS TCs with equal BW Share for now across all VSIs */
4401 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4402 if (enabled_tc
& (1 << i
))
4406 ret
= i40e_vsi_configure_bw_alloc(vsi
, enabled_tc
, bw_share
);
4408 dev_info(&vsi
->back
->pdev
->dev
,
4409 "Failed configuring TC map %d for VSI %d\n",
4410 enabled_tc
, vsi
->seid
);
4414 /* Update Queue Pairs Mapping for currently enabled UPs */
4415 ctxt
.seid
= vsi
->seid
;
4416 ctxt
.pf_num
= vsi
->back
->hw
.pf_id
;
4418 ctxt
.uplink_seid
= vsi
->uplink_seid
;
4419 ctxt
.info
= vsi
->info
;
4420 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
4422 /* Update the VSI after updating the VSI queue-mapping information */
4423 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
4425 dev_info(&vsi
->back
->pdev
->dev
,
4426 "update vsi failed, aq_err=%d\n",
4427 vsi
->back
->hw
.aq
.asq_last_status
);
4430 /* update the local VSI info with updated queue map */
4431 i40e_vsi_update_queue_map(vsi
, &ctxt
);
4432 vsi
->info
.valid_sections
= 0;
4434 /* Update current VSI BW information */
4435 ret
= i40e_vsi_get_bw_info(vsi
);
4437 dev_info(&vsi
->back
->pdev
->dev
,
4438 "Failed updating vsi bw info, aq_err=%d\n",
4439 vsi
->back
->hw
.aq
.asq_last_status
);
4443 /* Update the netdev TC setup */
4444 i40e_vsi_config_netdev_tc(vsi
, enabled_tc
);
4450 * i40e_veb_config_tc - Configure TCs for given VEB
4452 * @enabled_tc: TC bitmap
4454 * Configures given TC bitmap for VEB (switching) element
4456 int i40e_veb_config_tc(struct i40e_veb
*veb
, u8 enabled_tc
)
4458 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data
= {0};
4459 struct i40e_pf
*pf
= veb
->pf
;
4463 /* No TCs or already enabled TCs just return */
4464 if (!enabled_tc
|| veb
->enabled_tc
== enabled_tc
)
4467 bw_data
.tc_valid_bits
= enabled_tc
;
4468 /* bw_data.absolute_credits is not set (relative) */
4470 /* Enable ETS TCs with equal BW Share for now */
4471 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4472 if (enabled_tc
& (1 << i
))
4473 bw_data
.tc_bw_share_credits
[i
] = 1;
4476 ret
= i40e_aq_config_switch_comp_bw_config(&pf
->hw
, veb
->seid
,
4479 dev_info(&pf
->pdev
->dev
,
4480 "veb bw config failed, aq_err=%d\n",
4481 pf
->hw
.aq
.asq_last_status
);
4485 /* Update the BW information */
4486 ret
= i40e_veb_get_bw_info(veb
);
4488 dev_info(&pf
->pdev
->dev
,
4489 "Failed getting veb bw config, aq_err=%d\n",
4490 pf
->hw
.aq
.asq_last_status
);
4497 #ifdef CONFIG_I40E_DCB
4499 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
4502 * Reconfigure VEB/VSIs on a given PF; it is assumed that
4503 * the caller would've quiesce all the VSIs before calling
4506 static void i40e_dcb_reconfigure(struct i40e_pf
*pf
)
4512 /* Enable the TCs available on PF to all VEBs */
4513 tc_map
= i40e_pf_get_tc_map(pf
);
4514 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
4517 ret
= i40e_veb_config_tc(pf
->veb
[v
], tc_map
);
4519 dev_info(&pf
->pdev
->dev
,
4520 "Failed configuring TC for VEB seid=%d\n",
4522 /* Will try to configure as many components */
4526 /* Update each VSI */
4527 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4531 /* - Enable all TCs for the LAN VSI
4533 * - For FCoE VSI only enable the TC configured
4534 * as per the APP TLV
4536 * - For all others keep them at TC0 for now
4538 if (v
== pf
->lan_vsi
)
4539 tc_map
= i40e_pf_get_tc_map(pf
);
4541 tc_map
= i40e_pf_get_default_tc(pf
);
4543 if (pf
->vsi
[v
]->type
== I40E_VSI_FCOE
)
4544 tc_map
= i40e_get_fcoe_tc_map(pf
);
4545 #endif /* #ifdef I40E_FCOE */
4547 ret
= i40e_vsi_config_tc(pf
->vsi
[v
], tc_map
);
4549 dev_info(&pf
->pdev
->dev
,
4550 "Failed configuring TC for VSI seid=%d\n",
4552 /* Will try to configure as many components */
4554 /* Re-configure VSI vectors based on updated TC map */
4555 i40e_vsi_map_rings_to_vectors(pf
->vsi
[v
]);
4556 if (pf
->vsi
[v
]->netdev
)
4557 i40e_dcbnl_set_all(pf
->vsi
[v
]);
4563 * i40e_resume_port_tx - Resume port Tx
4566 * Resume a port's Tx and issue a PF reset in case of failure to
4569 static int i40e_resume_port_tx(struct i40e_pf
*pf
)
4571 struct i40e_hw
*hw
= &pf
->hw
;
4574 ret
= i40e_aq_resume_port_tx(hw
, NULL
);
4576 dev_info(&pf
->pdev
->dev
,
4577 "AQ command Resume Port Tx failed = %d\n",
4578 pf
->hw
.aq
.asq_last_status
);
4579 /* Schedule PF reset to recover */
4580 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
4581 i40e_service_event_schedule(pf
);
4588 * i40e_init_pf_dcb - Initialize DCB configuration
4589 * @pf: PF being configured
4591 * Query the current DCB configuration and cache it
4592 * in the hardware structure
4594 static int i40e_init_pf_dcb(struct i40e_pf
*pf
)
4596 struct i40e_hw
*hw
= &pf
->hw
;
4599 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
4600 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
4601 (pf
->hw
.aq
.fw_maj_ver
< 4))
4604 /* Get the initial DCB configuration */
4605 err
= i40e_init_dcb(hw
);
4607 /* Device/Function is not DCBX capable */
4608 if ((!hw
->func_caps
.dcb
) ||
4609 (hw
->dcbx_status
== I40E_DCBX_STATUS_DISABLED
)) {
4610 dev_info(&pf
->pdev
->dev
,
4611 "DCBX offload is not supported or is disabled for this PF.\n");
4613 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
)
4617 /* When status is not DISABLED then DCBX in FW */
4618 pf
->dcbx_cap
= DCB_CAP_DCBX_LLD_MANAGED
|
4619 DCB_CAP_DCBX_VER_IEEE
;
4621 pf
->flags
|= I40E_FLAG_DCB_CAPABLE
;
4622 /* Enable DCB tagging only when more than one TC */
4623 if (i40e_dcb_get_num_tc(&hw
->local_dcbx_config
) > 1)
4624 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
4625 dev_dbg(&pf
->pdev
->dev
,
4626 "DCBX offload is supported for this PF.\n");
4629 dev_info(&pf
->pdev
->dev
,
4630 "AQ Querying DCB configuration failed: aq_err %d\n",
4631 pf
->hw
.aq
.asq_last_status
);
4637 #endif /* CONFIG_I40E_DCB */
4638 #define SPEED_SIZE 14
4641 * i40e_print_link_message - print link up or down
4642 * @vsi: the VSI for which link needs a message
4644 static void i40e_print_link_message(struct i40e_vsi
*vsi
, bool isup
)
4646 char speed
[SPEED_SIZE
] = "Unknown";
4647 char fc
[FC_SIZE
] = "RX/TX";
4650 netdev_info(vsi
->netdev
, "NIC Link is Down\n");
4654 /* Warn user if link speed on NPAR enabled partition is not at
4657 if (vsi
->back
->hw
.func_caps
.npar_enable
&&
4658 (vsi
->back
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_1GB
||
4659 vsi
->back
->hw
.phy
.link_info
.link_speed
== I40E_LINK_SPEED_100MB
))
4660 netdev_warn(vsi
->netdev
,
4661 "The partition detected link speed that is less than 10Gbps\n");
4663 switch (vsi
->back
->hw
.phy
.link_info
.link_speed
) {
4664 case I40E_LINK_SPEED_40GB
:
4665 strlcpy(speed
, "40 Gbps", SPEED_SIZE
);
4667 case I40E_LINK_SPEED_20GB
:
4668 strncpy(speed
, "20 Gbps", SPEED_SIZE
);
4670 case I40E_LINK_SPEED_10GB
:
4671 strlcpy(speed
, "10 Gbps", SPEED_SIZE
);
4673 case I40E_LINK_SPEED_1GB
:
4674 strlcpy(speed
, "1000 Mbps", SPEED_SIZE
);
4676 case I40E_LINK_SPEED_100MB
:
4677 strncpy(speed
, "100 Mbps", SPEED_SIZE
);
4683 switch (vsi
->back
->hw
.fc
.current_mode
) {
4685 strlcpy(fc
, "RX/TX", FC_SIZE
);
4687 case I40E_FC_TX_PAUSE
:
4688 strlcpy(fc
, "TX", FC_SIZE
);
4690 case I40E_FC_RX_PAUSE
:
4691 strlcpy(fc
, "RX", FC_SIZE
);
4694 strlcpy(fc
, "None", FC_SIZE
);
4698 netdev_info(vsi
->netdev
, "NIC Link is Up %s Full Duplex, Flow Control: %s\n",
4703 * i40e_up_complete - Finish the last steps of bringing up a connection
4704 * @vsi: the VSI being configured
4706 static int i40e_up_complete(struct i40e_vsi
*vsi
)
4708 struct i40e_pf
*pf
= vsi
->back
;
4711 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
4712 i40e_vsi_configure_msix(vsi
);
4714 i40e_configure_msi_and_legacy(vsi
);
4717 err
= i40e_vsi_control_rings(vsi
, true);
4721 clear_bit(__I40E_DOWN
, &vsi
->state
);
4722 i40e_napi_enable_all(vsi
);
4723 i40e_vsi_enable_irq(vsi
);
4725 if ((pf
->hw
.phy
.link_info
.link_info
& I40E_AQ_LINK_UP
) &&
4727 i40e_print_link_message(vsi
, true);
4728 netif_tx_start_all_queues(vsi
->netdev
);
4729 netif_carrier_on(vsi
->netdev
);
4730 } else if (vsi
->netdev
) {
4731 i40e_print_link_message(vsi
, false);
4732 /* need to check for qualified module here*/
4733 if ((pf
->hw
.phy
.link_info
.link_info
&
4734 I40E_AQ_MEDIA_AVAILABLE
) &&
4735 (!(pf
->hw
.phy
.link_info
.an_info
&
4736 I40E_AQ_QUALIFIED_MODULE
)))
4737 netdev_err(vsi
->netdev
,
4738 "the driver failed to link because an unqualified module was detected.");
4741 /* replay FDIR SB filters */
4742 if (vsi
->type
== I40E_VSI_FDIR
) {
4743 /* reset fd counters */
4744 pf
->fd_add_err
= pf
->fd_atr_cnt
= 0;
4745 if (pf
->fd_tcp_rule
> 0) {
4746 pf
->flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
4747 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
4748 dev_info(&pf
->pdev
->dev
, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
4749 pf
->fd_tcp_rule
= 0;
4751 i40e_fdir_filter_restore(vsi
);
4753 i40e_service_event_schedule(pf
);
4759 * i40e_vsi_reinit_locked - Reset the VSI
4760 * @vsi: the VSI being configured
4762 * Rebuild the ring structs after some configuration
4763 * has changed, e.g. MTU size.
4765 static void i40e_vsi_reinit_locked(struct i40e_vsi
*vsi
)
4767 struct i40e_pf
*pf
= vsi
->back
;
4769 WARN_ON(in_interrupt());
4770 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
4771 usleep_range(1000, 2000);
4774 /* Give a VF some time to respond to the reset. The
4775 * two second wait is based upon the watchdog cycle in
4778 if (vsi
->type
== I40E_VSI_SRIOV
)
4781 clear_bit(__I40E_CONFIG_BUSY
, &pf
->state
);
4785 * i40e_up - Bring the connection back up after being down
4786 * @vsi: the VSI being configured
4788 int i40e_up(struct i40e_vsi
*vsi
)
4792 err
= i40e_vsi_configure(vsi
);
4794 err
= i40e_up_complete(vsi
);
4800 * i40e_down - Shutdown the connection processing
4801 * @vsi: the VSI being stopped
4803 void i40e_down(struct i40e_vsi
*vsi
)
4807 /* It is assumed that the caller of this function
4808 * sets the vsi->state __I40E_DOWN bit.
4811 netif_carrier_off(vsi
->netdev
);
4812 netif_tx_disable(vsi
->netdev
);
4814 i40e_vsi_disable_irq(vsi
);
4815 i40e_vsi_control_rings(vsi
, false);
4816 i40e_napi_disable_all(vsi
);
4818 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
4819 i40e_clean_tx_ring(vsi
->tx_rings
[i
]);
4820 i40e_clean_rx_ring(vsi
->rx_rings
[i
]);
4825 * i40e_setup_tc - configure multiple traffic classes
4826 * @netdev: net device to configure
4827 * @tc: number of traffic classes to enable
4830 int i40e_setup_tc(struct net_device
*netdev
, u8 tc
)
4832 static int i40e_setup_tc(struct net_device
*netdev
, u8 tc
)
4835 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
4836 struct i40e_vsi
*vsi
= np
->vsi
;
4837 struct i40e_pf
*pf
= vsi
->back
;
4842 /* Check if DCB enabled to continue */
4843 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
)) {
4844 netdev_info(netdev
, "DCB is not enabled for adapter\n");
4848 /* Check if MFP enabled */
4849 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
4850 netdev_info(netdev
, "Configuring TC not supported in MFP mode\n");
4854 /* Check whether tc count is within enabled limit */
4855 if (tc
> i40e_pf_get_num_tc(pf
)) {
4856 netdev_info(netdev
, "TC count greater than enabled on link for adapter\n");
4860 /* Generate TC map for number of tc requested */
4861 for (i
= 0; i
< tc
; i
++)
4862 enabled_tc
|= (1 << i
);
4864 /* Requesting same TC configuration as already enabled */
4865 if (enabled_tc
== vsi
->tc_config
.enabled_tc
)
4868 /* Quiesce VSI queues */
4869 i40e_quiesce_vsi(vsi
);
4871 /* Configure VSI for enabled TCs */
4872 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
4874 netdev_info(netdev
, "Failed configuring TC for VSI seid=%d\n",
4880 i40e_unquiesce_vsi(vsi
);
4887 * i40e_open - Called when a network interface is made active
4888 * @netdev: network interface device structure
4890 * The open entry point is called when a network interface is made
4891 * active by the system (IFF_UP). At this point all resources needed
4892 * for transmit and receive operations are allocated, the interrupt
4893 * handler is registered with the OS, the netdev watchdog subtask is
4894 * enabled, and the stack is notified that the interface is ready.
4896 * Returns 0 on success, negative value on failure
4898 int i40e_open(struct net_device
*netdev
)
4900 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
4901 struct i40e_vsi
*vsi
= np
->vsi
;
4902 struct i40e_pf
*pf
= vsi
->back
;
4905 /* disallow open during test or if eeprom is broken */
4906 if (test_bit(__I40E_TESTING
, &pf
->state
) ||
4907 test_bit(__I40E_BAD_EEPROM
, &pf
->state
))
4910 netif_carrier_off(netdev
);
4912 err
= i40e_vsi_open(vsi
);
4916 /* configure global TSO hardware offload settings */
4917 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_F
, be32_to_cpu(TCP_FLAG_PSH
|
4918 TCP_FLAG_FIN
) >> 16);
4919 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_M
, be32_to_cpu(TCP_FLAG_PSH
|
4921 TCP_FLAG_CWR
) >> 16);
4922 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_L
, be32_to_cpu(TCP_FLAG_CWR
) >> 16);
4924 #ifdef CONFIG_I40E_VXLAN
4925 vxlan_get_rx_port(netdev
);
4933 * @vsi: the VSI to open
4935 * Finish initialization of the VSI.
4937 * Returns 0 on success, negative value on failure
4939 int i40e_vsi_open(struct i40e_vsi
*vsi
)
4941 struct i40e_pf
*pf
= vsi
->back
;
4942 char int_name
[I40E_INT_NAME_STR_LEN
];
4945 /* allocate descriptors */
4946 err
= i40e_vsi_setup_tx_resources(vsi
);
4949 err
= i40e_vsi_setup_rx_resources(vsi
);
4953 err
= i40e_vsi_configure(vsi
);
4958 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s",
4959 dev_driver_string(&pf
->pdev
->dev
), vsi
->netdev
->name
);
4960 err
= i40e_vsi_request_irq(vsi
, int_name
);
4964 /* Notify the stack of the actual queue counts. */
4965 err
= netif_set_real_num_tx_queues(vsi
->netdev
,
4966 vsi
->num_queue_pairs
);
4968 goto err_set_queues
;
4970 err
= netif_set_real_num_rx_queues(vsi
->netdev
,
4971 vsi
->num_queue_pairs
);
4973 goto err_set_queues
;
4975 } else if (vsi
->type
== I40E_VSI_FDIR
) {
4976 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s:fdir",
4977 dev_driver_string(&pf
->pdev
->dev
),
4978 dev_name(&pf
->pdev
->dev
));
4979 err
= i40e_vsi_request_irq(vsi
, int_name
);
4986 err
= i40e_up_complete(vsi
);
4988 goto err_up_complete
;
4995 i40e_vsi_free_irq(vsi
);
4997 i40e_vsi_free_rx_resources(vsi
);
4999 i40e_vsi_free_tx_resources(vsi
);
5000 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
5001 i40e_do_reset(pf
, (1 << __I40E_PF_RESET_REQUESTED
));
5007 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
5008 * @pf: Pointer to PF
5010 * This function destroys the hlist where all the Flow Director
5011 * filters were saved.
5013 static void i40e_fdir_filter_exit(struct i40e_pf
*pf
)
5015 struct i40e_fdir_filter
*filter
;
5016 struct hlist_node
*node2
;
5018 hlist_for_each_entry_safe(filter
, node2
,
5019 &pf
->fdir_filter_list
, fdir_node
) {
5020 hlist_del(&filter
->fdir_node
);
5023 pf
->fdir_pf_active_filters
= 0;
5027 * i40e_close - Disables a network interface
5028 * @netdev: network interface device structure
5030 * The close entry point is called when an interface is de-activated
5031 * by the OS. The hardware is still under the driver's control, but
5032 * this netdev interface is disabled.
5034 * Returns 0, this is not allowed to fail
5037 int i40e_close(struct net_device
*netdev
)
5039 static int i40e_close(struct net_device
*netdev
)
5042 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
5043 struct i40e_vsi
*vsi
= np
->vsi
;
5045 i40e_vsi_close(vsi
);
5051 * i40e_do_reset - Start a PF or Core Reset sequence
5052 * @pf: board private structure
5053 * @reset_flags: which reset is requested
5055 * The essential difference in resets is that the PF Reset
5056 * doesn't clear the packet buffers, doesn't reset the PE
5057 * firmware, and doesn't bother the other PFs on the chip.
5059 void i40e_do_reset(struct i40e_pf
*pf
, u32 reset_flags
)
5063 WARN_ON(in_interrupt());
5065 if (i40e_check_asq_alive(&pf
->hw
))
5066 i40e_vc_notify_reset(pf
);
5068 /* do the biggest reset indicated */
5069 if (reset_flags
& (1 << __I40E_GLOBAL_RESET_REQUESTED
)) {
5071 /* Request a Global Reset
5073 * This will start the chip's countdown to the actual full
5074 * chip reset event, and a warning interrupt to be sent
5075 * to all PFs, including the requestor. Our handler
5076 * for the warning interrupt will deal with the shutdown
5077 * and recovery of the switch setup.
5079 dev_dbg(&pf
->pdev
->dev
, "GlobalR requested\n");
5080 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
5081 val
|= I40E_GLGEN_RTRIG_GLOBR_MASK
;
5082 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
5084 } else if (reset_flags
& (1 << __I40E_CORE_RESET_REQUESTED
)) {
5086 /* Request a Core Reset
5088 * Same as Global Reset, except does *not* include the MAC/PHY
5090 dev_dbg(&pf
->pdev
->dev
, "CoreR requested\n");
5091 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
5092 val
|= I40E_GLGEN_RTRIG_CORER_MASK
;
5093 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
5094 i40e_flush(&pf
->hw
);
5096 } else if (reset_flags
& (1 << __I40E_PF_RESET_REQUESTED
)) {
5098 /* Request a PF Reset
5100 * Resets only the PF-specific registers
5102 * This goes directly to the tear-down and rebuild of
5103 * the switch, since we need to do all the recovery as
5104 * for the Core Reset.
5106 dev_dbg(&pf
->pdev
->dev
, "PFR requested\n");
5107 i40e_handle_reset_warning(pf
);
5109 } else if (reset_flags
& (1 << __I40E_REINIT_REQUESTED
)) {
5112 /* Find the VSI(s) that requested a re-init */
5113 dev_info(&pf
->pdev
->dev
,
5114 "VSI reinit requested\n");
5115 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5116 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
5118 test_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
)) {
5119 i40e_vsi_reinit_locked(pf
->vsi
[v
]);
5120 clear_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
);
5124 /* no further action needed, so return now */
5126 } else if (reset_flags
& (1 << __I40E_DOWN_REQUESTED
)) {
5129 /* Find the VSI(s) that needs to be brought down */
5130 dev_info(&pf
->pdev
->dev
, "VSI down requested\n");
5131 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5132 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
5134 test_bit(__I40E_DOWN_REQUESTED
, &vsi
->state
)) {
5135 set_bit(__I40E_DOWN
, &vsi
->state
);
5137 clear_bit(__I40E_DOWN_REQUESTED
, &vsi
->state
);
5141 /* no further action needed, so return now */
5144 dev_info(&pf
->pdev
->dev
,
5145 "bad reset request 0x%08x\n", reset_flags
);
5150 #ifdef CONFIG_I40E_DCB
5152 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
5153 * @pf: board private structure
5154 * @old_cfg: current DCB config
5155 * @new_cfg: new DCB config
5157 bool i40e_dcb_need_reconfig(struct i40e_pf
*pf
,
5158 struct i40e_dcbx_config
*old_cfg
,
5159 struct i40e_dcbx_config
*new_cfg
)
5161 bool need_reconfig
= false;
5163 /* Check if ETS configuration has changed */
5164 if (memcmp(&new_cfg
->etscfg
,
5166 sizeof(new_cfg
->etscfg
))) {
5167 /* If Priority Table has changed reconfig is needed */
5168 if (memcmp(&new_cfg
->etscfg
.prioritytable
,
5169 &old_cfg
->etscfg
.prioritytable
,
5170 sizeof(new_cfg
->etscfg
.prioritytable
))) {
5171 need_reconfig
= true;
5172 dev_dbg(&pf
->pdev
->dev
, "ETS UP2TC changed.\n");
5175 if (memcmp(&new_cfg
->etscfg
.tcbwtable
,
5176 &old_cfg
->etscfg
.tcbwtable
,
5177 sizeof(new_cfg
->etscfg
.tcbwtable
)))
5178 dev_dbg(&pf
->pdev
->dev
, "ETS TC BW Table changed.\n");
5180 if (memcmp(&new_cfg
->etscfg
.tsatable
,
5181 &old_cfg
->etscfg
.tsatable
,
5182 sizeof(new_cfg
->etscfg
.tsatable
)))
5183 dev_dbg(&pf
->pdev
->dev
, "ETS TSA Table changed.\n");
5186 /* Check if PFC configuration has changed */
5187 if (memcmp(&new_cfg
->pfc
,
5189 sizeof(new_cfg
->pfc
))) {
5190 need_reconfig
= true;
5191 dev_dbg(&pf
->pdev
->dev
, "PFC config change detected.\n");
5194 /* Check if APP Table has changed */
5195 if (memcmp(&new_cfg
->app
,
5197 sizeof(new_cfg
->app
))) {
5198 need_reconfig
= true;
5199 dev_dbg(&pf
->pdev
->dev
, "APP Table change detected.\n");
5202 dev_dbg(&pf
->pdev
->dev
, "%s: need_reconfig=%d\n", __func__
,
5204 return need_reconfig
;
5208 * i40e_handle_lldp_event - Handle LLDP Change MIB event
5209 * @pf: board private structure
5210 * @e: event info posted on ARQ
5212 static int i40e_handle_lldp_event(struct i40e_pf
*pf
,
5213 struct i40e_arq_event_info
*e
)
5215 struct i40e_aqc_lldp_get_mib
*mib
=
5216 (struct i40e_aqc_lldp_get_mib
*)&e
->desc
.params
.raw
;
5217 struct i40e_hw
*hw
= &pf
->hw
;
5218 struct i40e_dcbx_config tmp_dcbx_cfg
;
5219 bool need_reconfig
= false;
5223 /* Not DCB capable or capability disabled */
5224 if (!(pf
->flags
& I40E_FLAG_DCB_CAPABLE
))
5227 /* Ignore if event is not for Nearest Bridge */
5228 type
= ((mib
->type
>> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT
)
5229 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK
);
5230 dev_dbg(&pf
->pdev
->dev
,
5231 "%s: LLDP event mib bridge type 0x%x\n", __func__
, type
);
5232 if (type
!= I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
)
5235 /* Check MIB Type and return if event for Remote MIB update */
5236 type
= mib
->type
& I40E_AQ_LLDP_MIB_TYPE_MASK
;
5237 dev_dbg(&pf
->pdev
->dev
,
5238 "%s: LLDP event mib type %s\n", __func__
,
5239 type
? "remote" : "local");
5240 if (type
== I40E_AQ_LLDP_MIB_REMOTE
) {
5241 /* Update the remote cached instance and return */
5242 ret
= i40e_aq_get_dcb_config(hw
, I40E_AQ_LLDP_MIB_REMOTE
,
5243 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
,
5244 &hw
->remote_dcbx_config
);
5248 /* Store the old configuration */
5249 tmp_dcbx_cfg
= hw
->local_dcbx_config
;
5251 /* Reset the old DCBx configuration data */
5252 memset(&hw
->local_dcbx_config
, 0, sizeof(hw
->local_dcbx_config
));
5253 /* Get updated DCBX data from firmware */
5254 ret
= i40e_get_dcb_config(&pf
->hw
);
5256 dev_info(&pf
->pdev
->dev
, "Failed querying DCB configuration data from firmware.\n");
5260 /* No change detected in DCBX configs */
5261 if (!memcmp(&tmp_dcbx_cfg
, &hw
->local_dcbx_config
,
5262 sizeof(tmp_dcbx_cfg
))) {
5263 dev_dbg(&pf
->pdev
->dev
, "No change detected in DCBX configuration.\n");
5267 need_reconfig
= i40e_dcb_need_reconfig(pf
, &tmp_dcbx_cfg
,
5268 &hw
->local_dcbx_config
);
5270 i40e_dcbnl_flush_apps(pf
, &tmp_dcbx_cfg
, &hw
->local_dcbx_config
);
5275 /* Enable DCB tagging only when more than one TC */
5276 if (i40e_dcb_get_num_tc(&hw
->local_dcbx_config
) > 1)
5277 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
5279 pf
->flags
&= ~I40E_FLAG_DCB_ENABLED
;
5281 set_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
);
5282 /* Reconfiguration needed quiesce all VSIs */
5283 i40e_pf_quiesce_all_vsi(pf
);
5285 /* Changes in configuration update VEB/VSI */
5286 i40e_dcb_reconfigure(pf
);
5288 ret
= i40e_resume_port_tx(pf
);
5290 clear_bit(__I40E_PORT_TX_SUSPENDED
, &pf
->state
);
5291 /* In case of error no point in resuming VSIs */
5295 /* Wait for the PF's Tx queues to be disabled */
5296 ret
= i40e_pf_wait_txq_disabled(pf
);
5298 /* Schedule PF reset to recover */
5299 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
5300 i40e_service_event_schedule(pf
);
5302 i40e_pf_unquiesce_all_vsi(pf
);
5308 #endif /* CONFIG_I40E_DCB */
5311 * i40e_do_reset_safe - Protected reset path for userland calls.
5312 * @pf: board private structure
5313 * @reset_flags: which reset is requested
5316 void i40e_do_reset_safe(struct i40e_pf
*pf
, u32 reset_flags
)
5319 i40e_do_reset(pf
, reset_flags
);
5324 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
5325 * @pf: board private structure
5326 * @e: event info posted on ARQ
5328 * Handler for LAN Queue Overflow Event generated by the firmware for PF
5331 static void i40e_handle_lan_overflow_event(struct i40e_pf
*pf
,
5332 struct i40e_arq_event_info
*e
)
5334 struct i40e_aqc_lan_overflow
*data
=
5335 (struct i40e_aqc_lan_overflow
*)&e
->desc
.params
.raw
;
5336 u32 queue
= le32_to_cpu(data
->prtdcb_rupto
);
5337 u32 qtx_ctl
= le32_to_cpu(data
->otx_ctl
);
5338 struct i40e_hw
*hw
= &pf
->hw
;
5342 dev_dbg(&pf
->pdev
->dev
, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
5345 /* Queue belongs to VF, find the VF and issue VF reset */
5346 if (((qtx_ctl
& I40E_QTX_CTL_PFVF_Q_MASK
)
5347 >> I40E_QTX_CTL_PFVF_Q_SHIFT
) == I40E_QTX_CTL_VF_QUEUE
) {
5348 vf_id
= (u16
)((qtx_ctl
& I40E_QTX_CTL_VFVM_INDX_MASK
)
5349 >> I40E_QTX_CTL_VFVM_INDX_SHIFT
);
5350 vf_id
-= hw
->func_caps
.vf_base_id
;
5351 vf
= &pf
->vf
[vf_id
];
5352 i40e_vc_notify_vf_reset(vf
);
5353 /* Allow VF to process pending reset notification */
5355 i40e_reset_vf(vf
, false);
5360 * i40e_service_event_complete - Finish up the service event
5361 * @pf: board private structure
5363 static void i40e_service_event_complete(struct i40e_pf
*pf
)
5365 BUG_ON(!test_bit(__I40E_SERVICE_SCHED
, &pf
->state
));
5367 /* flush memory to make sure state is correct before next watchog */
5368 smp_mb__before_atomic();
5369 clear_bit(__I40E_SERVICE_SCHED
, &pf
->state
);
5373 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
5374 * @pf: board private structure
5376 u32
i40e_get_cur_guaranteed_fd_count(struct i40e_pf
*pf
)
5380 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
5381 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
);
5386 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
5387 * @pf: board private structure
5389 u32
i40e_get_current_fd_count(struct i40e_pf
*pf
)
5393 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
5394 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
) +
5395 ((val
& I40E_PFQF_FDSTAT_BEST_CNT_MASK
) >>
5396 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT
);
5401 * i40e_get_global_fd_count - Get total FD filters programmed on device
5402 * @pf: board private structure
5404 u32
i40e_get_global_fd_count(struct i40e_pf
*pf
)
5408 val
= rd32(&pf
->hw
, I40E_GLQF_FDCNT_0
);
5409 fcnt_prog
= (val
& I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK
) +
5410 ((val
& I40E_GLQF_FDCNT_0_BESTCNT_MASK
) >>
5411 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT
);
5416 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
5417 * @pf: board private structure
5419 void i40e_fdir_check_and_reenable(struct i40e_pf
*pf
)
5421 u32 fcnt_prog
, fcnt_avail
;
5423 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
5426 /* Check if, FD SB or ATR was auto disabled and if there is enough room
5429 fcnt_prog
= i40e_get_global_fd_count(pf
);
5430 fcnt_avail
= pf
->fdir_pf_filter_count
;
5431 if ((fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM
)) ||
5432 (pf
->fd_add_err
== 0) ||
5433 (i40e_get_current_atr_cnt(pf
) < pf
->fd_atr_cnt
)) {
5434 if ((pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) &&
5435 (pf
->auto_disable_flags
& I40E_FLAG_FD_SB_ENABLED
)) {
5436 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
5437 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5438 dev_info(&pf
->pdev
->dev
, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
5441 /* Wait for some more space to be available to turn on ATR */
5442 if (fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM
* 2)) {
5443 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
5444 (pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
)) {
5445 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
5446 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5447 dev_info(&pf
->pdev
->dev
, "ATR is being enabled since we have space in the table now\n");
5452 #define I40E_MIN_FD_FLUSH_INTERVAL 10
5453 #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
5455 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
5456 * @pf: board private structure
5458 static void i40e_fdir_flush_and_replay(struct i40e_pf
*pf
)
5460 unsigned long min_flush_time
;
5461 int flush_wait_retry
= 50;
5462 bool disable_atr
= false;
5466 if (!(pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
)))
5469 if (time_after(jiffies
, pf
->fd_flush_timestamp
+
5470 (I40E_MIN_FD_FLUSH_INTERVAL
* HZ
))) {
5471 /* If the flush is happening too quick and we have mostly
5472 * SB rules we should not re-enable ATR for some time.
5474 min_flush_time
= pf
->fd_flush_timestamp
5475 + (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE
* HZ
);
5476 fd_room
= pf
->fdir_pf_filter_count
- pf
->fdir_pf_active_filters
;
5478 if (!(time_after(jiffies
, min_flush_time
)) &&
5479 (fd_room
< I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR
)) {
5480 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5481 dev_info(&pf
->pdev
->dev
, "ATR disabled, not enough FD filter space.\n");
5485 pf
->fd_flush_timestamp
= jiffies
;
5486 pf
->flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
5487 /* flush all filters */
5488 wr32(&pf
->hw
, I40E_PFQF_CTL_1
,
5489 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
);
5490 i40e_flush(&pf
->hw
);
5494 /* Check FD flush status every 5-6msec */
5495 usleep_range(5000, 6000);
5496 reg
= rd32(&pf
->hw
, I40E_PFQF_CTL_1
);
5497 if (!(reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
))
5499 } while (flush_wait_retry
--);
5500 if (reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
) {
5501 dev_warn(&pf
->pdev
->dev
, "FD table did not flush, needs more time\n");
5503 /* replay sideband filters */
5504 i40e_fdir_filter_restore(pf
->vsi
[pf
->lan_vsi
]);
5506 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
5507 clear_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
);
5508 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
5509 dev_info(&pf
->pdev
->dev
, "FD Filter table flushed and FD-SB replayed.\n");
5515 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
5516 * @pf: board private structure
5518 u32
i40e_get_current_atr_cnt(struct i40e_pf
*pf
)
5520 return i40e_get_current_fd_count(pf
) - pf
->fdir_pf_active_filters
;
5523 /* We can see up to 256 filter programming desc in transit if the filters are
5524 * being applied really fast; before we see the first
5525 * filter miss error on Rx queue 0. Accumulating enough error messages before
5526 * reacting will make sure we don't cause flush too often.
5528 #define I40E_MAX_FD_PROGRAM_ERROR 256
5531 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
5532 * @pf: board private structure
5534 static void i40e_fdir_reinit_subtask(struct i40e_pf
*pf
)
5537 /* if interface is down do nothing */
5538 if (test_bit(__I40E_DOWN
, &pf
->state
))
5541 if (!(pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
)))
5544 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
5545 i40e_fdir_flush_and_replay(pf
);
5547 i40e_fdir_check_and_reenable(pf
);
5552 * i40e_vsi_link_event - notify VSI of a link event
5553 * @vsi: vsi to be notified
5554 * @link_up: link up or down
5556 static void i40e_vsi_link_event(struct i40e_vsi
*vsi
, bool link_up
)
5558 if (!vsi
|| test_bit(__I40E_DOWN
, &vsi
->state
))
5561 switch (vsi
->type
) {
5566 if (!vsi
->netdev
|| !vsi
->netdev_registered
)
5570 netif_carrier_on(vsi
->netdev
);
5571 netif_tx_wake_all_queues(vsi
->netdev
);
5573 netif_carrier_off(vsi
->netdev
);
5574 netif_tx_stop_all_queues(vsi
->netdev
);
5578 case I40E_VSI_SRIOV
:
5579 case I40E_VSI_VMDQ2
:
5581 case I40E_VSI_MIRROR
:
5583 /* there is no notification for other VSIs */
5589 * i40e_veb_link_event - notify elements on the veb of a link event
5590 * @veb: veb to be notified
5591 * @link_up: link up or down
5593 static void i40e_veb_link_event(struct i40e_veb
*veb
, bool link_up
)
5598 if (!veb
|| !veb
->pf
)
5602 /* depth first... */
5603 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
5604 if (pf
->veb
[i
] && (pf
->veb
[i
]->uplink_seid
== veb
->seid
))
5605 i40e_veb_link_event(pf
->veb
[i
], link_up
);
5607 /* ... now the local VSIs */
5608 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
5609 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->uplink_seid
== veb
->seid
))
5610 i40e_vsi_link_event(pf
->vsi
[i
], link_up
);
5614 * i40e_link_event - Update netif_carrier status
5615 * @pf: board private structure
5617 static void i40e_link_event(struct i40e_pf
*pf
)
5619 bool new_link
, old_link
;
5620 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
5621 u8 new_link_speed
, old_link_speed
;
5623 /* set this to force the get_link_status call to refresh state */
5624 pf
->hw
.phy
.get_link_info
= true;
5626 old_link
= (pf
->hw
.phy
.link_info_old
.link_info
& I40E_AQ_LINK_UP
);
5627 new_link
= i40e_get_link_status(&pf
->hw
);
5628 old_link_speed
= pf
->hw
.phy
.link_info_old
.link_speed
;
5629 new_link_speed
= pf
->hw
.phy
.link_info
.link_speed
;
5631 if (new_link
== old_link
&&
5632 new_link_speed
== old_link_speed
&&
5633 (test_bit(__I40E_DOWN
, &vsi
->state
) ||
5634 new_link
== netif_carrier_ok(vsi
->netdev
)))
5637 if (!test_bit(__I40E_DOWN
, &vsi
->state
))
5638 i40e_print_link_message(vsi
, new_link
);
5640 /* Notify the base of the switch tree connected to
5641 * the link. Floating VEBs are not notified.
5643 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
5644 i40e_veb_link_event(pf
->veb
[pf
->lan_veb
], new_link
);
5646 i40e_vsi_link_event(vsi
, new_link
);
5649 i40e_vc_notify_link_state(pf
);
5651 if (pf
->flags
& I40E_FLAG_PTP
)
5652 i40e_ptp_set_increment(pf
);
5656 * i40e_check_hang_subtask - Check for hung queues and dropped interrupts
5657 * @pf: board private structure
5659 * Set the per-queue flags to request a check for stuck queues in the irq
5660 * clean functions, then force interrupts to be sure the irq clean is called.
5662 static void i40e_check_hang_subtask(struct i40e_pf
*pf
)
5666 /* If we're down or resetting, just bail */
5667 if (test_bit(__I40E_DOWN
, &pf
->state
) ||
5668 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
5671 /* for each VSI/netdev
5673 * set the check flag
5675 * force an interrupt
5677 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5678 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
5682 test_bit(__I40E_DOWN
, &vsi
->state
) ||
5683 (vsi
->netdev
&& !netif_carrier_ok(vsi
->netdev
)))
5686 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
5687 set_check_for_tx_hang(vsi
->tx_rings
[i
]);
5688 if (test_bit(__I40E_HANG_CHECK_ARMED
,
5689 &vsi
->tx_rings
[i
]->state
))
5694 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
)) {
5695 wr32(&vsi
->back
->hw
, I40E_PFINT_DYN_CTL0
,
5696 (I40E_PFINT_DYN_CTL0_INTENA_MASK
|
5697 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK
|
5698 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK
|
5699 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK
|
5700 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK
));
5702 u16 vec
= vsi
->base_vector
- 1;
5703 u32 val
= (I40E_PFINT_DYN_CTLN_INTENA_MASK
|
5704 I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK
|
5705 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK
|
5706 I40E_PFINT_DYN_CTLN_SW_ITR_INDX_ENA_MASK
|
5707 I40E_PFINT_DYN_CTLN_SW_ITR_INDX_MASK
);
5708 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vec
++)
5709 wr32(&vsi
->back
->hw
,
5710 I40E_PFINT_DYN_CTLN(vec
), val
);
5712 i40e_flush(&vsi
->back
->hw
);
5718 * i40e_watchdog_subtask - periodic checks not using event driven response
5719 * @pf: board private structure
5721 static void i40e_watchdog_subtask(struct i40e_pf
*pf
)
5725 /* if interface is down do nothing */
5726 if (test_bit(__I40E_DOWN
, &pf
->state
) ||
5727 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
5730 /* make sure we don't do these things too often */
5731 if (time_before(jiffies
, (pf
->service_timer_previous
+
5732 pf
->service_timer_period
)))
5734 pf
->service_timer_previous
= jiffies
;
5736 i40e_check_hang_subtask(pf
);
5737 i40e_link_event(pf
);
5739 /* Update the stats for active netdevs so the network stack
5740 * can look at updated numbers whenever it cares to
5742 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
5743 if (pf
->vsi
[i
] && pf
->vsi
[i
]->netdev
)
5744 i40e_update_stats(pf
->vsi
[i
]);
5746 /* Update the stats for the active switching components */
5747 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
5749 i40e_update_veb_stats(pf
->veb
[i
]);
5751 i40e_ptp_rx_hang(pf
->vsi
[pf
->lan_vsi
]);
5755 * i40e_reset_subtask - Set up for resetting the device and driver
5756 * @pf: board private structure
5758 static void i40e_reset_subtask(struct i40e_pf
*pf
)
5760 u32 reset_flags
= 0;
5763 if (test_bit(__I40E_REINIT_REQUESTED
, &pf
->state
)) {
5764 reset_flags
|= (1 << __I40E_REINIT_REQUESTED
);
5765 clear_bit(__I40E_REINIT_REQUESTED
, &pf
->state
);
5767 if (test_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
)) {
5768 reset_flags
|= (1 << __I40E_PF_RESET_REQUESTED
);
5769 clear_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
5771 if (test_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
)) {
5772 reset_flags
|= (1 << __I40E_CORE_RESET_REQUESTED
);
5773 clear_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
);
5775 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
)) {
5776 reset_flags
|= (1 << __I40E_GLOBAL_RESET_REQUESTED
);
5777 clear_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
);
5779 if (test_bit(__I40E_DOWN_REQUESTED
, &pf
->state
)) {
5780 reset_flags
|= (1 << __I40E_DOWN_REQUESTED
);
5781 clear_bit(__I40E_DOWN_REQUESTED
, &pf
->state
);
5784 /* If there's a recovery already waiting, it takes
5785 * precedence before starting a new reset sequence.
5787 if (test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
)) {
5788 i40e_handle_reset_warning(pf
);
5792 /* If we're already down or resetting, just bail */
5794 !test_bit(__I40E_DOWN
, &pf
->state
) &&
5795 !test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
5796 i40e_do_reset(pf
, reset_flags
);
5803 * i40e_handle_link_event - Handle link event
5804 * @pf: board private structure
5805 * @e: event info posted on ARQ
5807 static void i40e_handle_link_event(struct i40e_pf
*pf
,
5808 struct i40e_arq_event_info
*e
)
5810 struct i40e_hw
*hw
= &pf
->hw
;
5811 struct i40e_aqc_get_link_status
*status
=
5812 (struct i40e_aqc_get_link_status
*)&e
->desc
.params
.raw
;
5814 /* save off old link status information */
5815 hw
->phy
.link_info_old
= hw
->phy
.link_info
;
5817 /* Do a new status request to re-enable LSE reporting
5818 * and load new status information into the hw struct
5819 * This completely ignores any state information
5820 * in the ARQ event info, instead choosing to always
5821 * issue the AQ update link status command.
5823 i40e_link_event(pf
);
5825 /* check for unqualified module, if link is down */
5826 if ((status
->link_info
& I40E_AQ_MEDIA_AVAILABLE
) &&
5827 (!(status
->an_info
& I40E_AQ_QUALIFIED_MODULE
)) &&
5828 (!(status
->link_info
& I40E_AQ_LINK_UP
)))
5829 dev_err(&pf
->pdev
->dev
,
5830 "The driver failed to link because an unqualified module was detected.\n");
5834 * i40e_clean_adminq_subtask - Clean the AdminQ rings
5835 * @pf: board private structure
5837 static void i40e_clean_adminq_subtask(struct i40e_pf
*pf
)
5839 struct i40e_arq_event_info event
;
5840 struct i40e_hw
*hw
= &pf
->hw
;
5847 /* Do not run clean AQ when PF reset fails */
5848 if (test_bit(__I40E_RESET_FAILED
, &pf
->state
))
5851 /* check for error indications */
5852 val
= rd32(&pf
->hw
, pf
->hw
.aq
.arq
.len
);
5854 if (val
& I40E_PF_ARQLEN_ARQVFE_MASK
) {
5855 dev_info(&pf
->pdev
->dev
, "ARQ VF Error detected\n");
5856 val
&= ~I40E_PF_ARQLEN_ARQVFE_MASK
;
5858 if (val
& I40E_PF_ARQLEN_ARQOVFL_MASK
) {
5859 dev_info(&pf
->pdev
->dev
, "ARQ Overflow Error detected\n");
5860 val
&= ~I40E_PF_ARQLEN_ARQOVFL_MASK
;
5862 if (val
& I40E_PF_ARQLEN_ARQCRIT_MASK
) {
5863 dev_info(&pf
->pdev
->dev
, "ARQ Critical Error detected\n");
5864 val
&= ~I40E_PF_ARQLEN_ARQCRIT_MASK
;
5867 wr32(&pf
->hw
, pf
->hw
.aq
.arq
.len
, val
);
5869 val
= rd32(&pf
->hw
, pf
->hw
.aq
.asq
.len
);
5871 if (val
& I40E_PF_ATQLEN_ATQVFE_MASK
) {
5872 dev_info(&pf
->pdev
->dev
, "ASQ VF Error detected\n");
5873 val
&= ~I40E_PF_ATQLEN_ATQVFE_MASK
;
5875 if (val
& I40E_PF_ATQLEN_ATQOVFL_MASK
) {
5876 dev_info(&pf
->pdev
->dev
, "ASQ Overflow Error detected\n");
5877 val
&= ~I40E_PF_ATQLEN_ATQOVFL_MASK
;
5879 if (val
& I40E_PF_ATQLEN_ATQCRIT_MASK
) {
5880 dev_info(&pf
->pdev
->dev
, "ASQ Critical Error detected\n");
5881 val
&= ~I40E_PF_ATQLEN_ATQCRIT_MASK
;
5884 wr32(&pf
->hw
, pf
->hw
.aq
.asq
.len
, val
);
5886 event
.buf_len
= I40E_MAX_AQ_BUF_SIZE
;
5887 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
5892 ret
= i40e_clean_arq_element(hw
, &event
, &pending
);
5893 if (ret
== I40E_ERR_ADMIN_QUEUE_NO_WORK
)
5896 dev_info(&pf
->pdev
->dev
, "ARQ event error %d\n", ret
);
5900 opcode
= le16_to_cpu(event
.desc
.opcode
);
5903 case i40e_aqc_opc_get_link_status
:
5904 i40e_handle_link_event(pf
, &event
);
5906 case i40e_aqc_opc_send_msg_to_pf
:
5907 ret
= i40e_vc_process_vf_msg(pf
,
5908 le16_to_cpu(event
.desc
.retval
),
5909 le32_to_cpu(event
.desc
.cookie_high
),
5910 le32_to_cpu(event
.desc
.cookie_low
),
5914 case i40e_aqc_opc_lldp_update_mib
:
5915 dev_dbg(&pf
->pdev
->dev
, "ARQ: Update LLDP MIB event received\n");
5916 #ifdef CONFIG_I40E_DCB
5918 ret
= i40e_handle_lldp_event(pf
, &event
);
5920 #endif /* CONFIG_I40E_DCB */
5922 case i40e_aqc_opc_event_lan_overflow
:
5923 dev_dbg(&pf
->pdev
->dev
, "ARQ LAN queue overflow event received\n");
5924 i40e_handle_lan_overflow_event(pf
, &event
);
5926 case i40e_aqc_opc_send_msg_to_peer
:
5927 dev_info(&pf
->pdev
->dev
, "ARQ: Msg from other pf\n");
5929 case i40e_aqc_opc_nvm_erase
:
5930 case i40e_aqc_opc_nvm_update
:
5931 i40e_debug(&pf
->hw
, I40E_DEBUG_NVM
, "ARQ NVM operation completed\n");
5934 dev_info(&pf
->pdev
->dev
,
5935 "ARQ Error: Unknown event 0x%04x received\n",
5939 } while (pending
&& (i
++ < pf
->adminq_work_limit
));
5941 clear_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
);
5942 /* re-enable Admin queue interrupt cause */
5943 val
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
5944 val
|= I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
5945 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
5948 kfree(event
.msg_buf
);
5952 * i40e_verify_eeprom - make sure eeprom is good to use
5953 * @pf: board private structure
5955 static void i40e_verify_eeprom(struct i40e_pf
*pf
)
5959 err
= i40e_diag_eeprom_test(&pf
->hw
);
5961 /* retry in case of garbage read */
5962 err
= i40e_diag_eeprom_test(&pf
->hw
);
5964 dev_info(&pf
->pdev
->dev
, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
5966 set_bit(__I40E_BAD_EEPROM
, &pf
->state
);
5970 if (!err
&& test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
5971 dev_info(&pf
->pdev
->dev
, "eeprom check passed, Tx/Rx traffic enabled\n");
5972 clear_bit(__I40E_BAD_EEPROM
, &pf
->state
);
5977 * i40e_enable_pf_switch_lb
5978 * @pf: pointer to the PF structure
5980 * enable switch loop back or die - no point in a return value
5982 static void i40e_enable_pf_switch_lb(struct i40e_pf
*pf
)
5984 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
5985 struct i40e_vsi_context ctxt
;
5988 ctxt
.seid
= pf
->main_vsi_seid
;
5989 ctxt
.pf_num
= pf
->hw
.pf_id
;
5991 aq_ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
5993 dev_info(&pf
->pdev
->dev
,
5994 "%s couldn't get PF vsi config, err %d, aq_err %d\n",
5995 __func__
, aq_ret
, pf
->hw
.aq
.asq_last_status
);
5998 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
5999 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
6000 ctxt
.info
.switch_id
|= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
6002 aq_ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
6004 dev_info(&pf
->pdev
->dev
,
6005 "%s: update vsi switch failed, aq_err=%d\n",
6006 __func__
, vsi
->back
->hw
.aq
.asq_last_status
);
6011 * i40e_disable_pf_switch_lb
6012 * @pf: pointer to the PF structure
6014 * disable switch loop back or die - no point in a return value
6016 static void i40e_disable_pf_switch_lb(struct i40e_pf
*pf
)
6018 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
6019 struct i40e_vsi_context ctxt
;
6022 ctxt
.seid
= pf
->main_vsi_seid
;
6023 ctxt
.pf_num
= pf
->hw
.pf_id
;
6025 aq_ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
6027 dev_info(&pf
->pdev
->dev
,
6028 "%s couldn't get PF vsi config, err %d, aq_err %d\n",
6029 __func__
, aq_ret
, pf
->hw
.aq
.asq_last_status
);
6032 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
6033 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
6034 ctxt
.info
.switch_id
&= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
6036 aq_ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
6038 dev_info(&pf
->pdev
->dev
,
6039 "%s: update vsi switch failed, aq_err=%d\n",
6040 __func__
, vsi
->back
->hw
.aq
.asq_last_status
);
6045 * i40e_config_bridge_mode - Configure the HW bridge mode
6046 * @veb: pointer to the bridge instance
6048 * Configure the loop back mode for the LAN VSI that is downlink to the
6049 * specified HW bridge instance. It is expected this function is called
6050 * when a new HW bridge is instantiated.
6052 static void i40e_config_bridge_mode(struct i40e_veb
*veb
)
6054 struct i40e_pf
*pf
= veb
->pf
;
6056 dev_info(&pf
->pdev
->dev
, "enabling bridge mode: %s\n",
6057 veb
->bridge_mode
== BRIDGE_MODE_VEPA
? "VEPA" : "VEB");
6058 if (veb
->bridge_mode
& BRIDGE_MODE_VEPA
)
6059 i40e_disable_pf_switch_lb(pf
);
6061 i40e_enable_pf_switch_lb(pf
);
6065 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
6066 * @veb: pointer to the VEB instance
6068 * This is a recursive function that first builds the attached VSIs then
6069 * recurses in to build the next layer of VEB. We track the connections
6070 * through our own index numbers because the seid's from the HW could
6071 * change across the reset.
6073 static int i40e_reconstitute_veb(struct i40e_veb
*veb
)
6075 struct i40e_vsi
*ctl_vsi
= NULL
;
6076 struct i40e_pf
*pf
= veb
->pf
;
6080 /* build VSI that owns this VEB, temporarily attached to base VEB */
6081 for (v
= 0; v
< pf
->num_alloc_vsi
&& !ctl_vsi
; v
++) {
6083 pf
->vsi
[v
]->veb_idx
== veb
->idx
&&
6084 pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
6085 ctl_vsi
= pf
->vsi
[v
];
6090 dev_info(&pf
->pdev
->dev
,
6091 "missing owner VSI for veb_idx %d\n", veb
->idx
);
6093 goto end_reconstitute
;
6095 if (ctl_vsi
!= pf
->vsi
[pf
->lan_vsi
])
6096 ctl_vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
6097 ret
= i40e_add_vsi(ctl_vsi
);
6099 dev_info(&pf
->pdev
->dev
,
6100 "rebuild of owner VSI failed: %d\n", ret
);
6101 goto end_reconstitute
;
6103 i40e_vsi_reset_stats(ctl_vsi
);
6105 /* create the VEB in the switch and move the VSI onto the VEB */
6106 ret
= i40e_add_veb(veb
, ctl_vsi
);
6108 goto end_reconstitute
;
6110 if (pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)
6111 veb
->bridge_mode
= BRIDGE_MODE_VEB
;
6113 veb
->bridge_mode
= BRIDGE_MODE_VEPA
;
6114 i40e_config_bridge_mode(veb
);
6116 /* create the remaining VSIs attached to this VEB */
6117 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
6118 if (!pf
->vsi
[v
] || pf
->vsi
[v
] == ctl_vsi
)
6121 if (pf
->vsi
[v
]->veb_idx
== veb
->idx
) {
6122 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
6123 vsi
->uplink_seid
= veb
->seid
;
6124 ret
= i40e_add_vsi(vsi
);
6126 dev_info(&pf
->pdev
->dev
,
6127 "rebuild of vsi_idx %d failed: %d\n",
6129 goto end_reconstitute
;
6131 i40e_vsi_reset_stats(vsi
);
6135 /* create any VEBs attached to this VEB - RECURSION */
6136 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
6137 if (pf
->veb
[veb_idx
] && pf
->veb
[veb_idx
]->veb_idx
== veb
->idx
) {
6138 pf
->veb
[veb_idx
]->uplink_seid
= veb
->seid
;
6139 ret
= i40e_reconstitute_veb(pf
->veb
[veb_idx
]);
6150 * i40e_get_capabilities - get info about the HW
6151 * @pf: the PF struct
6153 static int i40e_get_capabilities(struct i40e_pf
*pf
)
6155 struct i40e_aqc_list_capabilities_element_resp
*cap_buf
;
6160 buf_len
= 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp
);
6162 cap_buf
= kzalloc(buf_len
, GFP_KERNEL
);
6166 /* this loads the data into the hw struct for us */
6167 err
= i40e_aq_discover_capabilities(&pf
->hw
, cap_buf
, buf_len
,
6169 i40e_aqc_opc_list_func_capabilities
,
6171 /* data loaded, buffer no longer needed */
6174 if (pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_ENOMEM
) {
6175 /* retry with a larger buffer */
6176 buf_len
= data_size
;
6177 } else if (pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_OK
) {
6178 dev_info(&pf
->pdev
->dev
,
6179 "capability discovery failed: aq=%d\n",
6180 pf
->hw
.aq
.asq_last_status
);
6185 if (((pf
->hw
.aq
.fw_maj_ver
== 2) && (pf
->hw
.aq
.fw_min_ver
< 22)) ||
6186 (pf
->hw
.aq
.fw_maj_ver
< 2)) {
6187 pf
->hw
.func_caps
.num_msix_vectors
++;
6188 pf
->hw
.func_caps
.num_msix_vectors_vf
++;
6191 if (pf
->hw
.debug_mask
& I40E_DEBUG_USER
)
6192 dev_info(&pf
->pdev
->dev
,
6193 "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",
6194 pf
->hw
.pf_id
, pf
->hw
.func_caps
.num_vfs
,
6195 pf
->hw
.func_caps
.num_msix_vectors
,
6196 pf
->hw
.func_caps
.num_msix_vectors_vf
,
6197 pf
->hw
.func_caps
.fd_filters_guaranteed
,
6198 pf
->hw
.func_caps
.fd_filters_best_effort
,
6199 pf
->hw
.func_caps
.num_tx_qp
,
6200 pf
->hw
.func_caps
.num_vsis
);
6202 #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
6203 + pf->hw.func_caps.num_vfs)
6204 if (pf
->hw
.revision_id
== 0 && (DEF_NUM_VSI
> pf
->hw
.func_caps
.num_vsis
)) {
6205 dev_info(&pf
->pdev
->dev
,
6206 "got num_vsis %d, setting num_vsis to %d\n",
6207 pf
->hw
.func_caps
.num_vsis
, DEF_NUM_VSI
);
6208 pf
->hw
.func_caps
.num_vsis
= DEF_NUM_VSI
;
6214 static int i40e_vsi_clear(struct i40e_vsi
*vsi
);
6217 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
6218 * @pf: board private structure
6220 static void i40e_fdir_sb_setup(struct i40e_pf
*pf
)
6222 struct i40e_vsi
*vsi
;
6225 /* quick workaround for an NVM issue that leaves a critical register
6228 if (!rd32(&pf
->hw
, I40E_GLQF_HKEY(0))) {
6229 static const u32 hkey
[] = {
6230 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
6231 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
6232 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
6235 for (i
= 0; i
<= I40E_GLQF_HKEY_MAX_INDEX
; i
++)
6236 wr32(&pf
->hw
, I40E_GLQF_HKEY(i
), hkey
[i
]);
6239 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
6242 /* find existing VSI and see if it needs configuring */
6244 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
6245 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
6251 /* create a new VSI if none exists */
6253 vsi
= i40e_vsi_setup(pf
, I40E_VSI_FDIR
,
6254 pf
->vsi
[pf
->lan_vsi
]->seid
, 0);
6256 dev_info(&pf
->pdev
->dev
, "Couldn't create FDir VSI\n");
6257 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
6262 i40e_vsi_setup_irqhandler(vsi
, i40e_fdir_clean_ring
);
6266 * i40e_fdir_teardown - release the Flow Director resources
6267 * @pf: board private structure
6269 static void i40e_fdir_teardown(struct i40e_pf
*pf
)
6273 i40e_fdir_filter_exit(pf
);
6274 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
6275 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
6276 i40e_vsi_release(pf
->vsi
[i
]);
6283 * i40e_prep_for_reset - prep for the core to reset
6284 * @pf: board private structure
6286 * Close up the VFs and other things in prep for PF Reset.
6288 static void i40e_prep_for_reset(struct i40e_pf
*pf
)
6290 struct i40e_hw
*hw
= &pf
->hw
;
6291 i40e_status ret
= 0;
6294 clear_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
);
6295 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
))
6298 dev_dbg(&pf
->pdev
->dev
, "Tearing down internal switch for reset\n");
6300 /* quiesce the VSIs and their queues that are not already DOWN */
6301 i40e_pf_quiesce_all_vsi(pf
);
6303 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
6305 pf
->vsi
[v
]->seid
= 0;
6308 i40e_shutdown_adminq(&pf
->hw
);
6310 /* call shutdown HMC */
6311 if (hw
->hmc
.hmc_obj
) {
6312 ret
= i40e_shutdown_lan_hmc(hw
);
6314 dev_warn(&pf
->pdev
->dev
,
6315 "shutdown_lan_hmc failed: %d\n", ret
);
6320 * i40e_send_version - update firmware with driver version
6323 static void i40e_send_version(struct i40e_pf
*pf
)
6325 struct i40e_driver_version dv
;
6327 dv
.major_version
= DRV_VERSION_MAJOR
;
6328 dv
.minor_version
= DRV_VERSION_MINOR
;
6329 dv
.build_version
= DRV_VERSION_BUILD
;
6330 dv
.subbuild_version
= 0;
6331 strlcpy(dv
.driver_string
, DRV_VERSION
, sizeof(dv
.driver_string
));
6332 i40e_aq_send_driver_version(&pf
->hw
, &dv
, NULL
);
6336 * i40e_reset_and_rebuild - reset and rebuild using a saved config
6337 * @pf: board private structure
6338 * @reinit: if the Main VSI needs to re-initialized.
6340 static void i40e_reset_and_rebuild(struct i40e_pf
*pf
, bool reinit
)
6342 struct i40e_hw
*hw
= &pf
->hw
;
6343 u8 set_fc_aq_fail
= 0;
6347 /* Now we wait for GRST to settle out.
6348 * We don't have to delete the VEBs or VSIs from the hw switch
6349 * because the reset will make them disappear.
6351 ret
= i40e_pf_reset(hw
);
6353 dev_info(&pf
->pdev
->dev
, "PF reset failed, %d\n", ret
);
6354 set_bit(__I40E_RESET_FAILED
, &pf
->state
);
6355 goto clear_recovery
;
6359 if (test_bit(__I40E_DOWN
, &pf
->state
))
6360 goto clear_recovery
;
6361 dev_dbg(&pf
->pdev
->dev
, "Rebuilding internal switch\n");
6363 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
6364 ret
= i40e_init_adminq(&pf
->hw
);
6366 dev_info(&pf
->pdev
->dev
, "Rebuild AdminQ failed, %d\n", ret
);
6367 goto clear_recovery
;
6370 /* re-verify the eeprom if we just had an EMP reset */
6371 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED
, &pf
->state
))
6372 i40e_verify_eeprom(pf
);
6374 i40e_clear_pxe_mode(hw
);
6375 ret
= i40e_get_capabilities(pf
);
6377 dev_info(&pf
->pdev
->dev
, "i40e_get_capabilities failed, %d\n",
6379 goto end_core_reset
;
6382 ret
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
6383 hw
->func_caps
.num_rx_qp
,
6384 pf
->fcoe_hmc_cntx_num
, pf
->fcoe_hmc_filt_num
);
6386 dev_info(&pf
->pdev
->dev
, "init_lan_hmc failed: %d\n", ret
);
6387 goto end_core_reset
;
6389 ret
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
6391 dev_info(&pf
->pdev
->dev
, "configure_lan_hmc failed: %d\n", ret
);
6392 goto end_core_reset
;
6395 #ifdef CONFIG_I40E_DCB
6396 ret
= i40e_init_pf_dcb(pf
);
6398 dev_info(&pf
->pdev
->dev
, "DCB init failed %d, disabled\n", ret
);
6399 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
6400 /* Continue without DCB enabled */
6402 #endif /* CONFIG_I40E_DCB */
6404 ret
= i40e_init_pf_fcoe(pf
);
6406 dev_info(&pf
->pdev
->dev
, "init_pf_fcoe failed: %d\n", ret
);
6409 /* do basic switch setup */
6410 ret
= i40e_setup_pf_switch(pf
, reinit
);
6412 goto end_core_reset
;
6414 /* driver is only interested in link up/down and module qualification
6415 * reports from firmware
6417 ret
= i40e_aq_set_phy_int_mask(&pf
->hw
,
6418 I40E_AQ_EVENT_LINK_UPDOWN
|
6419 I40E_AQ_EVENT_MODULE_QUAL_FAIL
, NULL
);
6421 dev_info(&pf
->pdev
->dev
, "set phy mask fail, aq_err %d\n", ret
);
6423 /* make sure our flow control settings are restored */
6424 ret
= i40e_set_fc(&pf
->hw
, &set_fc_aq_fail
, true);
6426 dev_info(&pf
->pdev
->dev
, "set fc fail, aq_err %d\n", ret
);
6428 /* Rebuild the VSIs and VEBs that existed before reset.
6429 * They are still in our local switch element arrays, so only
6430 * need to rebuild the switch model in the HW.
6432 * If there were VEBs but the reconstitution failed, we'll try
6433 * try to recover minimal use by getting the basic PF VSI working.
6435 if (pf
->vsi
[pf
->lan_vsi
]->uplink_seid
!= pf
->mac_seid
) {
6436 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild switch\n");
6437 /* find the one VEB connected to the MAC, and find orphans */
6438 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
6442 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
||
6443 pf
->veb
[v
]->uplink_seid
== 0) {
6444 ret
= i40e_reconstitute_veb(pf
->veb
[v
]);
6449 /* If Main VEB failed, we're in deep doodoo,
6450 * so give up rebuilding the switch and set up
6451 * for minimal rebuild of PF VSI.
6452 * If orphan failed, we'll report the error
6453 * but try to keep going.
6455 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
) {
6456 dev_info(&pf
->pdev
->dev
,
6457 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
6459 pf
->vsi
[pf
->lan_vsi
]->uplink_seid
6462 } else if (pf
->veb
[v
]->uplink_seid
== 0) {
6463 dev_info(&pf
->pdev
->dev
,
6464 "rebuild of orphan VEB failed: %d\n",
6471 if (pf
->vsi
[pf
->lan_vsi
]->uplink_seid
== pf
->mac_seid
) {
6472 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild PF VSI\n");
6473 /* no VEB, so rebuild only the Main VSI */
6474 ret
= i40e_add_vsi(pf
->vsi
[pf
->lan_vsi
]);
6476 dev_info(&pf
->pdev
->dev
,
6477 "rebuild of Main VSI failed: %d\n", ret
);
6478 goto end_core_reset
;
6482 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
6483 (pf
->hw
.aq
.fw_maj_ver
< 4)) {
6485 ret
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
6487 dev_info(&pf
->pdev
->dev
, "link restart failed, aq_err=%d\n",
6488 pf
->hw
.aq
.asq_last_status
);
6490 /* reinit the misc interrupt */
6491 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
6492 ret
= i40e_setup_misc_vector(pf
);
6494 /* restart the VSIs that were rebuilt and running before the reset */
6495 i40e_pf_unquiesce_all_vsi(pf
);
6497 if (pf
->num_alloc_vfs
) {
6498 for (v
= 0; v
< pf
->num_alloc_vfs
; v
++)
6499 i40e_reset_vf(&pf
->vf
[v
], true);
6502 /* tell the firmware that we're starting */
6503 i40e_send_version(pf
);
6506 clear_bit(__I40E_RESET_FAILED
, &pf
->state
);
6508 clear_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
);
6512 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
6513 * @pf: board private structure
6515 * Close up the VFs and other things in prep for a Core Reset,
6516 * then get ready to rebuild the world.
6518 static void i40e_handle_reset_warning(struct i40e_pf
*pf
)
6520 i40e_prep_for_reset(pf
);
6521 i40e_reset_and_rebuild(pf
, false);
6525 * i40e_handle_mdd_event
6526 * @pf: pointer to the PF structure
6528 * Called from the MDD irq handler to identify possibly malicious vfs
6530 static void i40e_handle_mdd_event(struct i40e_pf
*pf
)
6532 struct i40e_hw
*hw
= &pf
->hw
;
6533 bool mdd_detected
= false;
6534 bool pf_mdd_detected
= false;
6539 if (!test_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
))
6542 /* find what triggered the MDD event */
6543 reg
= rd32(hw
, I40E_GL_MDET_TX
);
6544 if (reg
& I40E_GL_MDET_TX_VALID_MASK
) {
6545 u8 pf_num
= (reg
& I40E_GL_MDET_TX_PF_NUM_MASK
) >>
6546 I40E_GL_MDET_TX_PF_NUM_SHIFT
;
6547 u16 vf_num
= (reg
& I40E_GL_MDET_TX_VF_NUM_MASK
) >>
6548 I40E_GL_MDET_TX_VF_NUM_SHIFT
;
6549 u8 event
= (reg
& I40E_GL_MDET_TX_EVENT_MASK
) >>
6550 I40E_GL_MDET_TX_EVENT_SHIFT
;
6551 u16 queue
= ((reg
& I40E_GL_MDET_TX_QUEUE_MASK
) >>
6552 I40E_GL_MDET_TX_QUEUE_SHIFT
) -
6553 pf
->hw
.func_caps
.base_queue
;
6554 if (netif_msg_tx_err(pf
))
6555 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
6556 event
, queue
, pf_num
, vf_num
);
6557 wr32(hw
, I40E_GL_MDET_TX
, 0xffffffff);
6558 mdd_detected
= true;
6560 reg
= rd32(hw
, I40E_GL_MDET_RX
);
6561 if (reg
& I40E_GL_MDET_RX_VALID_MASK
) {
6562 u8 func
= (reg
& I40E_GL_MDET_RX_FUNCTION_MASK
) >>
6563 I40E_GL_MDET_RX_FUNCTION_SHIFT
;
6564 u8 event
= (reg
& I40E_GL_MDET_RX_EVENT_MASK
) >>
6565 I40E_GL_MDET_RX_EVENT_SHIFT
;
6566 u16 queue
= ((reg
& I40E_GL_MDET_RX_QUEUE_MASK
) >>
6567 I40E_GL_MDET_RX_QUEUE_SHIFT
) -
6568 pf
->hw
.func_caps
.base_queue
;
6569 if (netif_msg_rx_err(pf
))
6570 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
6571 event
, queue
, func
);
6572 wr32(hw
, I40E_GL_MDET_RX
, 0xffffffff);
6573 mdd_detected
= true;
6577 reg
= rd32(hw
, I40E_PF_MDET_TX
);
6578 if (reg
& I40E_PF_MDET_TX_VALID_MASK
) {
6579 wr32(hw
, I40E_PF_MDET_TX
, 0xFFFF);
6580 dev_info(&pf
->pdev
->dev
, "TX driver issue detected, PF reset issued\n");
6581 pf_mdd_detected
= true;
6583 reg
= rd32(hw
, I40E_PF_MDET_RX
);
6584 if (reg
& I40E_PF_MDET_RX_VALID_MASK
) {
6585 wr32(hw
, I40E_PF_MDET_RX
, 0xFFFF);
6586 dev_info(&pf
->pdev
->dev
, "RX driver issue detected, PF reset issued\n");
6587 pf_mdd_detected
= true;
6589 /* Queue belongs to the PF, initiate a reset */
6590 if (pf_mdd_detected
) {
6591 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
6592 i40e_service_event_schedule(pf
);
6596 /* see if one of the VFs needs its hand slapped */
6597 for (i
= 0; i
< pf
->num_alloc_vfs
&& mdd_detected
; i
++) {
6599 reg
= rd32(hw
, I40E_VP_MDET_TX(i
));
6600 if (reg
& I40E_VP_MDET_TX_VALID_MASK
) {
6601 wr32(hw
, I40E_VP_MDET_TX(i
), 0xFFFF);
6602 vf
->num_mdd_events
++;
6603 dev_info(&pf
->pdev
->dev
, "TX driver issue detected on VF %d\n",
6607 reg
= rd32(hw
, I40E_VP_MDET_RX(i
));
6608 if (reg
& I40E_VP_MDET_RX_VALID_MASK
) {
6609 wr32(hw
, I40E_VP_MDET_RX(i
), 0xFFFF);
6610 vf
->num_mdd_events
++;
6611 dev_info(&pf
->pdev
->dev
, "RX driver issue detected on VF %d\n",
6615 if (vf
->num_mdd_events
> I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED
) {
6616 dev_info(&pf
->pdev
->dev
,
6617 "Too many MDD events on VF %d, disabled\n", i
);
6618 dev_info(&pf
->pdev
->dev
,
6619 "Use PF Control I/F to re-enable the VF\n");
6620 set_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
);
6624 /* re-enable mdd interrupt cause */
6625 clear_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
);
6626 reg
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
6627 reg
|= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
6628 wr32(hw
, I40E_PFINT_ICR0_ENA
, reg
);
6632 #ifdef CONFIG_I40E_VXLAN
6634 * i40e_sync_vxlan_filters_subtask - Sync the VSI filter list with HW
6635 * @pf: board private structure
6637 static void i40e_sync_vxlan_filters_subtask(struct i40e_pf
*pf
)
6639 struct i40e_hw
*hw
= &pf
->hw
;
6644 if (!(pf
->flags
& I40E_FLAG_VXLAN_FILTER_SYNC
))
6647 pf
->flags
&= ~I40E_FLAG_VXLAN_FILTER_SYNC
;
6649 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
6650 if (pf
->pending_vxlan_bitmap
& (1 << i
)) {
6651 pf
->pending_vxlan_bitmap
&= ~(1 << i
);
6652 port
= pf
->vxlan_ports
[i
];
6654 ret
= i40e_aq_add_udp_tunnel(hw
, ntohs(port
),
6655 I40E_AQC_TUNNEL_TYPE_VXLAN
,
6658 ret
= i40e_aq_del_udp_tunnel(hw
, i
, NULL
);
6661 dev_info(&pf
->pdev
->dev
,
6662 "%s vxlan port %d, index %d failed, err %d, aq_err %d\n",
6663 port
? "add" : "delete",
6664 ntohs(port
), i
, ret
,
6665 pf
->hw
.aq
.asq_last_status
);
6666 pf
->vxlan_ports
[i
] = 0;
6674 * i40e_service_task - Run the driver's async subtasks
6675 * @work: pointer to work_struct containing our data
6677 static void i40e_service_task(struct work_struct
*work
)
6679 struct i40e_pf
*pf
= container_of(work
,
6682 unsigned long start_time
= jiffies
;
6684 /* don't bother with service tasks if a reset is in progress */
6685 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
)) {
6686 i40e_service_event_complete(pf
);
6690 i40e_reset_subtask(pf
);
6691 i40e_handle_mdd_event(pf
);
6692 i40e_vc_process_vflr_event(pf
);
6693 i40e_watchdog_subtask(pf
);
6694 i40e_fdir_reinit_subtask(pf
);
6695 i40e_sync_filters_subtask(pf
);
6696 #ifdef CONFIG_I40E_VXLAN
6697 i40e_sync_vxlan_filters_subtask(pf
);
6699 i40e_clean_adminq_subtask(pf
);
6701 i40e_service_event_complete(pf
);
6703 /* If the tasks have taken longer than one timer cycle or there
6704 * is more work to be done, reschedule the service task now
6705 * rather than wait for the timer to tick again.
6707 if (time_after(jiffies
, (start_time
+ pf
->service_timer_period
)) ||
6708 test_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
) ||
6709 test_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
) ||
6710 test_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
))
6711 i40e_service_event_schedule(pf
);
6715 * i40e_service_timer - timer callback
6716 * @data: pointer to PF struct
6718 static void i40e_service_timer(unsigned long data
)
6720 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
6722 mod_timer(&pf
->service_timer
,
6723 round_jiffies(jiffies
+ pf
->service_timer_period
));
6724 i40e_service_event_schedule(pf
);
6728 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
6729 * @vsi: the VSI being configured
6731 static int i40e_set_num_rings_in_vsi(struct i40e_vsi
*vsi
)
6733 struct i40e_pf
*pf
= vsi
->back
;
6735 switch (vsi
->type
) {
6737 vsi
->alloc_queue_pairs
= pf
->num_lan_qps
;
6738 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
6739 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6740 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
6741 vsi
->num_q_vectors
= pf
->num_lan_msix
;
6743 vsi
->num_q_vectors
= 1;
6748 vsi
->alloc_queue_pairs
= 1;
6749 vsi
->num_desc
= ALIGN(I40E_FDIR_RING_COUNT
,
6750 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6751 vsi
->num_q_vectors
= 1;
6754 case I40E_VSI_VMDQ2
:
6755 vsi
->alloc_queue_pairs
= pf
->num_vmdq_qps
;
6756 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
6757 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6758 vsi
->num_q_vectors
= pf
->num_vmdq_msix
;
6761 case I40E_VSI_SRIOV
:
6762 vsi
->alloc_queue_pairs
= pf
->num_vf_qps
;
6763 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
6764 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6769 vsi
->alloc_queue_pairs
= pf
->num_fcoe_qps
;
6770 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
6771 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6772 vsi
->num_q_vectors
= pf
->num_fcoe_msix
;
6775 #endif /* I40E_FCOE */
6785 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
6786 * @type: VSI pointer
6787 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
6789 * On error: returns error code (negative)
6790 * On success: returns 0
6792 static int i40e_vsi_alloc_arrays(struct i40e_vsi
*vsi
, bool alloc_qvectors
)
6797 /* allocate memory for both Tx and Rx ring pointers */
6798 size
= sizeof(struct i40e_ring
*) * vsi
->alloc_queue_pairs
* 2;
6799 vsi
->tx_rings
= kzalloc(size
, GFP_KERNEL
);
6802 vsi
->rx_rings
= &vsi
->tx_rings
[vsi
->alloc_queue_pairs
];
6804 if (alloc_qvectors
) {
6805 /* allocate memory for q_vector pointers */
6806 size
= sizeof(struct i40e_q_vector
*) * vsi
->num_q_vectors
;
6807 vsi
->q_vectors
= kzalloc(size
, GFP_KERNEL
);
6808 if (!vsi
->q_vectors
) {
6816 kfree(vsi
->tx_rings
);
6821 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
6822 * @pf: board private structure
6823 * @type: type of VSI
6825 * On error: returns error code (negative)
6826 * On success: returns vsi index in PF (positive)
6828 static int i40e_vsi_mem_alloc(struct i40e_pf
*pf
, enum i40e_vsi_type type
)
6831 struct i40e_vsi
*vsi
;
6835 /* Need to protect the allocation of the VSIs at the PF level */
6836 mutex_lock(&pf
->switch_mutex
);
6838 /* VSI list may be fragmented if VSI creation/destruction has
6839 * been happening. We can afford to do a quick scan to look
6840 * for any free VSIs in the list.
6842 * find next empty vsi slot, looping back around if necessary
6845 while (i
< pf
->num_alloc_vsi
&& pf
->vsi
[i
])
6847 if (i
>= pf
->num_alloc_vsi
) {
6849 while (i
< pf
->next_vsi
&& pf
->vsi
[i
])
6853 if (i
< pf
->num_alloc_vsi
&& !pf
->vsi
[i
]) {
6854 vsi_idx
= i
; /* Found one! */
6857 goto unlock_pf
; /* out of VSI slots! */
6861 vsi
= kzalloc(sizeof(*vsi
), GFP_KERNEL
);
6868 set_bit(__I40E_DOWN
, &vsi
->state
);
6871 vsi
->rx_itr_setting
= pf
->rx_itr_default
;
6872 vsi
->tx_itr_setting
= pf
->tx_itr_default
;
6873 vsi
->rss_table_size
= (vsi
->type
== I40E_VSI_MAIN
) ?
6874 pf
->rss_table_size
: 64;
6875 vsi
->netdev_registered
= false;
6876 vsi
->work_limit
= I40E_DEFAULT_IRQ_WORK
;
6877 INIT_LIST_HEAD(&vsi
->mac_filter_list
);
6878 vsi
->irqs_ready
= false;
6880 ret
= i40e_set_num_rings_in_vsi(vsi
);
6884 ret
= i40e_vsi_alloc_arrays(vsi
, true);
6888 /* Setup default MSIX irq handler for VSI */
6889 i40e_vsi_setup_irqhandler(vsi
, i40e_msix_clean_rings
);
6891 pf
->vsi
[vsi_idx
] = vsi
;
6896 pf
->next_vsi
= i
- 1;
6899 mutex_unlock(&pf
->switch_mutex
);
6904 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
6905 * @type: VSI pointer
6906 * @free_qvectors: a bool to specify if q_vectors need to be freed.
6908 * On error: returns error code (negative)
6909 * On success: returns 0
6911 static void i40e_vsi_free_arrays(struct i40e_vsi
*vsi
, bool free_qvectors
)
6913 /* free the ring and vector containers */
6914 if (free_qvectors
) {
6915 kfree(vsi
->q_vectors
);
6916 vsi
->q_vectors
= NULL
;
6918 kfree(vsi
->tx_rings
);
6919 vsi
->tx_rings
= NULL
;
6920 vsi
->rx_rings
= NULL
;
6924 * i40e_vsi_clear - Deallocate the VSI provided
6925 * @vsi: the VSI being un-configured
6927 static int i40e_vsi_clear(struct i40e_vsi
*vsi
)
6938 mutex_lock(&pf
->switch_mutex
);
6939 if (!pf
->vsi
[vsi
->idx
]) {
6940 dev_err(&pf
->pdev
->dev
, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
6941 vsi
->idx
, vsi
->idx
, vsi
, vsi
->type
);
6945 if (pf
->vsi
[vsi
->idx
] != vsi
) {
6946 dev_err(&pf
->pdev
->dev
,
6947 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
6948 pf
->vsi
[vsi
->idx
]->idx
,
6950 pf
->vsi
[vsi
->idx
]->type
,
6951 vsi
->idx
, vsi
, vsi
->type
);
6955 /* updates the PF for this cleared vsi */
6956 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
6957 i40e_put_lump(pf
->irq_pile
, vsi
->base_vector
, vsi
->idx
);
6959 i40e_vsi_free_arrays(vsi
, true);
6961 pf
->vsi
[vsi
->idx
] = NULL
;
6962 if (vsi
->idx
< pf
->next_vsi
)
6963 pf
->next_vsi
= vsi
->idx
;
6966 mutex_unlock(&pf
->switch_mutex
);
6974 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
6975 * @vsi: the VSI being cleaned
6977 static void i40e_vsi_clear_rings(struct i40e_vsi
*vsi
)
6981 if (vsi
->tx_rings
&& vsi
->tx_rings
[0]) {
6982 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
6983 kfree_rcu(vsi
->tx_rings
[i
], rcu
);
6984 vsi
->tx_rings
[i
] = NULL
;
6985 vsi
->rx_rings
[i
] = NULL
;
6991 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
6992 * @vsi: the VSI being configured
6994 static int i40e_alloc_rings(struct i40e_vsi
*vsi
)
6996 struct i40e_ring
*tx_ring
, *rx_ring
;
6997 struct i40e_pf
*pf
= vsi
->back
;
7000 /* Set basic values in the rings to be used later during open() */
7001 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
7002 /* allocate space for both Tx and Rx in one shot */
7003 tx_ring
= kzalloc(sizeof(struct i40e_ring
) * 2, GFP_KERNEL
);
7007 tx_ring
->queue_index
= i
;
7008 tx_ring
->reg_idx
= vsi
->base_queue
+ i
;
7009 tx_ring
->ring_active
= false;
7011 tx_ring
->netdev
= vsi
->netdev
;
7012 tx_ring
->dev
= &pf
->pdev
->dev
;
7013 tx_ring
->count
= vsi
->num_desc
;
7015 tx_ring
->dcb_tc
= 0;
7016 vsi
->tx_rings
[i
] = tx_ring
;
7018 rx_ring
= &tx_ring
[1];
7019 rx_ring
->queue_index
= i
;
7020 rx_ring
->reg_idx
= vsi
->base_queue
+ i
;
7021 rx_ring
->ring_active
= false;
7023 rx_ring
->netdev
= vsi
->netdev
;
7024 rx_ring
->dev
= &pf
->pdev
->dev
;
7025 rx_ring
->count
= vsi
->num_desc
;
7027 rx_ring
->dcb_tc
= 0;
7028 if (pf
->flags
& I40E_FLAG_16BYTE_RX_DESC_ENABLED
)
7029 set_ring_16byte_desc_enabled(rx_ring
);
7031 clear_ring_16byte_desc_enabled(rx_ring
);
7032 vsi
->rx_rings
[i
] = rx_ring
;
7038 i40e_vsi_clear_rings(vsi
);
7043 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
7044 * @pf: board private structure
7045 * @vectors: the number of MSI-X vectors to request
7047 * Returns the number of vectors reserved, or error
7049 static int i40e_reserve_msix_vectors(struct i40e_pf
*pf
, int vectors
)
7051 vectors
= pci_enable_msix_range(pf
->pdev
, pf
->msix_entries
,
7052 I40E_MIN_MSIX
, vectors
);
7054 dev_info(&pf
->pdev
->dev
,
7055 "MSI-X vector reservation failed: %d\n", vectors
);
7063 * i40e_init_msix - Setup the MSIX capability
7064 * @pf: board private structure
7066 * Work with the OS to set up the MSIX vectors needed.
7068 * Returns the number of vectors reserved or negative on failure
7070 static int i40e_init_msix(struct i40e_pf
*pf
)
7072 struct i40e_hw
*hw
= &pf
->hw
;
7077 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
7080 /* The number of vectors we'll request will be comprised of:
7081 * - Add 1 for "other" cause for Admin Queue events, etc.
7082 * - The number of LAN queue pairs
7083 * - Queues being used for RSS.
7084 * We don't need as many as max_rss_size vectors.
7085 * use rss_size instead in the calculation since that
7086 * is governed by number of cpus in the system.
7087 * - assumes symmetric Tx/Rx pairing
7088 * - The number of VMDq pairs
7090 * - The number of FCOE qps.
7092 * Once we count this up, try the request.
7094 * If we can't get what we want, we'll simplify to nearly nothing
7095 * and try again. If that still fails, we punt.
7097 vectors_left
= hw
->func_caps
.num_msix_vectors
;
7100 /* reserve one vector for miscellaneous handler */
7106 /* reserve vectors for the main PF traffic queues */
7107 pf
->num_lan_msix
= min_t(int, num_online_cpus(), vectors_left
);
7108 vectors_left
-= pf
->num_lan_msix
;
7109 v_budget
+= pf
->num_lan_msix
;
7111 /* reserve one vector for sideband flow director */
7112 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
7117 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7122 /* can we reserve enough for FCoE? */
7123 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7125 pf
->num_fcoe_msix
= 0;
7126 else if (vectors_left
>= pf
->num_fcoe_qps
)
7127 pf
->num_fcoe_msix
= pf
->num_fcoe_qps
;
7129 pf
->num_fcoe_msix
= 1;
7130 v_budget
+= pf
->num_fcoe_msix
;
7131 vectors_left
-= pf
->num_fcoe_msix
;
7135 /* any vectors left over go for VMDq support */
7136 if (pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) {
7137 int vmdq_vecs_wanted
= pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
;
7138 int vmdq_vecs
= min_t(int, vectors_left
, vmdq_vecs_wanted
);
7140 /* if we're short on vectors for what's desired, we limit
7141 * the queues per vmdq. If this is still more than are
7142 * available, the user will need to change the number of
7143 * queues/vectors used by the PF later with the ethtool
7146 if (vmdq_vecs
< vmdq_vecs_wanted
)
7147 pf
->num_vmdq_qps
= 1;
7148 pf
->num_vmdq_msix
= pf
->num_vmdq_qps
;
7150 v_budget
+= vmdq_vecs
;
7151 vectors_left
-= vmdq_vecs
;
7154 pf
->msix_entries
= kcalloc(v_budget
, sizeof(struct msix_entry
),
7156 if (!pf
->msix_entries
)
7159 for (i
= 0; i
< v_budget
; i
++)
7160 pf
->msix_entries
[i
].entry
= i
;
7161 v_actual
= i40e_reserve_msix_vectors(pf
, v_budget
);
7163 if (v_actual
!= v_budget
) {
7164 /* If we have limited resources, we will start with no vectors
7165 * for the special features and then allocate vectors to some
7166 * of these features based on the policy and at the end disable
7167 * the features that did not get any vectors.
7170 pf
->num_fcoe_qps
= 0;
7171 pf
->num_fcoe_msix
= 0;
7173 pf
->num_vmdq_msix
= 0;
7176 if (v_actual
< I40E_MIN_MSIX
) {
7177 pf
->flags
&= ~I40E_FLAG_MSIX_ENABLED
;
7178 kfree(pf
->msix_entries
);
7179 pf
->msix_entries
= NULL
;
7182 } else if (v_actual
== I40E_MIN_MSIX
) {
7183 /* Adjust for minimal MSIX use */
7184 pf
->num_vmdq_vsis
= 0;
7185 pf
->num_vmdq_qps
= 0;
7186 pf
->num_lan_qps
= 1;
7187 pf
->num_lan_msix
= 1;
7189 } else if (v_actual
!= v_budget
) {
7192 /* reserve the misc vector */
7195 /* Scale vector usage down */
7196 pf
->num_vmdq_msix
= 1; /* force VMDqs to only one vector */
7197 pf
->num_vmdq_vsis
= 1;
7198 pf
->num_vmdq_qps
= 1;
7199 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7201 /* partition out the remaining vectors */
7204 pf
->num_lan_msix
= 1;
7208 /* give one vector to FCoE */
7209 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7210 pf
->num_lan_msix
= 1;
7211 pf
->num_fcoe_msix
= 1;
7214 pf
->num_lan_msix
= 2;
7219 /* give one vector to FCoE */
7220 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
7221 pf
->num_fcoe_msix
= 1;
7225 /* give the rest to the PF */
7226 pf
->num_lan_msix
= min_t(int, vec
, pf
->num_lan_qps
);
7231 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
7232 (pf
->num_vmdq_msix
== 0)) {
7233 dev_info(&pf
->pdev
->dev
, "VMDq disabled, not enough MSI-X vectors\n");
7234 pf
->flags
&= ~I40E_FLAG_VMDQ_ENABLED
;
7238 if ((pf
->flags
& I40E_FLAG_FCOE_ENABLED
) && (pf
->num_fcoe_msix
== 0)) {
7239 dev_info(&pf
->pdev
->dev
, "FCOE disabled, not enough MSI-X vectors\n");
7240 pf
->flags
&= ~I40E_FLAG_FCOE_ENABLED
;
7247 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
7248 * @vsi: the VSI being configured
7249 * @v_idx: index of the vector in the vsi struct
7251 * We allocate one q_vector. If allocation fails we return -ENOMEM.
7253 static int i40e_vsi_alloc_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
7255 struct i40e_q_vector
*q_vector
;
7257 /* allocate q_vector */
7258 q_vector
= kzalloc(sizeof(struct i40e_q_vector
), GFP_KERNEL
);
7262 q_vector
->vsi
= vsi
;
7263 q_vector
->v_idx
= v_idx
;
7264 cpumask_set_cpu(v_idx
, &q_vector
->affinity_mask
);
7266 netif_napi_add(vsi
->netdev
, &q_vector
->napi
,
7267 i40e_napi_poll
, NAPI_POLL_WEIGHT
);
7269 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
7270 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
7272 /* tie q_vector and vsi together */
7273 vsi
->q_vectors
[v_idx
] = q_vector
;
7279 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
7280 * @vsi: the VSI being configured
7282 * We allocate one q_vector per queue interrupt. If allocation fails we
7285 static int i40e_vsi_alloc_q_vectors(struct i40e_vsi
*vsi
)
7287 struct i40e_pf
*pf
= vsi
->back
;
7288 int v_idx
, num_q_vectors
;
7291 /* if not MSIX, give the one vector only to the LAN VSI */
7292 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
7293 num_q_vectors
= vsi
->num_q_vectors
;
7294 else if (vsi
== pf
->vsi
[pf
->lan_vsi
])
7299 for (v_idx
= 0; v_idx
< num_q_vectors
; v_idx
++) {
7300 err
= i40e_vsi_alloc_q_vector(vsi
, v_idx
);
7309 i40e_free_q_vector(vsi
, v_idx
);
7315 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
7316 * @pf: board private structure to initialize
7318 static int i40e_init_interrupt_scheme(struct i40e_pf
*pf
)
7323 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
7324 vectors
= i40e_init_msix(pf
);
7326 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
|
7328 I40E_FLAG_FCOE_ENABLED
|
7330 I40E_FLAG_RSS_ENABLED
|
7331 I40E_FLAG_DCB_CAPABLE
|
7332 I40E_FLAG_SRIOV_ENABLED
|
7333 I40E_FLAG_FD_SB_ENABLED
|
7334 I40E_FLAG_FD_ATR_ENABLED
|
7335 I40E_FLAG_VMDQ_ENABLED
);
7337 /* rework the queue expectations without MSIX */
7338 i40e_determine_queue_usage(pf
);
7342 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
7343 (pf
->flags
& I40E_FLAG_MSI_ENABLED
)) {
7344 dev_info(&pf
->pdev
->dev
, "MSI-X not available, trying MSI\n");
7345 vectors
= pci_enable_msi(pf
->pdev
);
7347 dev_info(&pf
->pdev
->dev
, "MSI init failed - %d\n",
7349 pf
->flags
&= ~I40E_FLAG_MSI_ENABLED
;
7351 vectors
= 1; /* one MSI or Legacy vector */
7354 if (!(pf
->flags
& (I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
)))
7355 dev_info(&pf
->pdev
->dev
, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
7357 /* set up vector assignment tracking */
7358 size
= sizeof(struct i40e_lump_tracking
) + (sizeof(u16
) * vectors
);
7359 pf
->irq_pile
= kzalloc(size
, GFP_KERNEL
);
7360 if (!pf
->irq_pile
) {
7361 dev_err(&pf
->pdev
->dev
, "error allocating irq_pile memory\n");
7364 pf
->irq_pile
->num_entries
= vectors
;
7365 pf
->irq_pile
->search_hint
= 0;
7367 /* track first vector for misc interrupts, ignore return */
7368 (void)i40e_get_lump(pf
, pf
->irq_pile
, 1, I40E_PILE_VALID_BIT
- 1);
7374 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
7375 * @pf: board private structure
7377 * This sets up the handler for MSIX 0, which is used to manage the
7378 * non-queue interrupts, e.g. AdminQ and errors. This is not used
7379 * when in MSI or Legacy interrupt mode.
7381 static int i40e_setup_misc_vector(struct i40e_pf
*pf
)
7383 struct i40e_hw
*hw
= &pf
->hw
;
7386 /* Only request the irq if this is the first time through, and
7387 * not when we're rebuilding after a Reset
7389 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
)) {
7390 err
= request_irq(pf
->msix_entries
[0].vector
,
7391 i40e_intr
, 0, pf
->int_name
, pf
);
7393 dev_info(&pf
->pdev
->dev
,
7394 "request_irq for %s failed: %d\n",
7400 i40e_enable_misc_int_causes(pf
);
7402 /* associate no queues to the misc vector */
7403 wr32(hw
, I40E_PFINT_LNKLST0
, I40E_QUEUE_END_OF_LIST
);
7404 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), I40E_ITR_8K
);
7408 i40e_irq_dynamic_enable_icr0(pf
);
7414 * i40e_config_rss - Prepare for RSS if used
7415 * @pf: board private structure
7417 static int i40e_config_rss(struct i40e_pf
*pf
)
7419 u32 rss_key
[I40E_PFQF_HKEY_MAX_INDEX
+ 1];
7420 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
7421 struct i40e_hw
*hw
= &pf
->hw
;
7427 netdev_rss_key_fill(rss_key
, sizeof(rss_key
));
7428 for (i
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++)
7429 wr32(hw
, I40E_PFQF_HKEY(i
), rss_key
[i
]);
7431 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
7432 hena
= (u64
)rd32(hw
, I40E_PFQF_HENA(0)) |
7433 ((u64
)rd32(hw
, I40E_PFQF_HENA(1)) << 32);
7434 hena
|= I40E_DEFAULT_RSS_HENA
;
7435 wr32(hw
, I40E_PFQF_HENA(0), (u32
)hena
);
7436 wr32(hw
, I40E_PFQF_HENA(1), (u32
)(hena
>> 32));
7438 vsi
->rss_size
= min_t(int, pf
->rss_size
, vsi
->num_queue_pairs
);
7440 /* Check capability and Set table size and register per hw expectation*/
7441 reg_val
= rd32(hw
, I40E_PFQF_CTL_0
);
7442 if (pf
->rss_table_size
== 512)
7443 reg_val
|= I40E_PFQF_CTL_0_HASHLUTSIZE_512
;
7445 reg_val
&= ~I40E_PFQF_CTL_0_HASHLUTSIZE_512
;
7446 wr32(hw
, I40E_PFQF_CTL_0
, reg_val
);
7448 /* Populate the LUT with max no. of queues in round robin fashion */
7449 for (i
= 0, j
= 0; i
< pf
->rss_table_size
; i
++, j
++) {
7451 /* The assumption is that lan qp count will be the highest
7452 * qp count for any PF VSI that needs RSS.
7453 * If multiple VSIs need RSS support, all the qp counts
7454 * for those VSIs should be a power of 2 for RSS to work.
7455 * If LAN VSI is the only consumer for RSS then this requirement
7458 if (j
== vsi
->rss_size
)
7460 /* lut = 4-byte sliding window of 4 lut entries */
7461 lut
= (lut
<< 8) | (j
&
7462 ((0x1 << pf
->hw
.func_caps
.rss_table_entry_width
) - 1));
7463 /* On i = 3, we have 4 entries in lut; write to the register */
7465 wr32(hw
, I40E_PFQF_HLUT(i
>> 2), lut
);
7473 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
7474 * @pf: board private structure
7475 * @queue_count: the requested queue count for rss.
7477 * returns 0 if rss is not enabled, if enabled returns the final rss queue
7478 * count which may be different from the requested queue count.
7480 int i40e_reconfig_rss_queues(struct i40e_pf
*pf
, int queue_count
)
7482 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
7485 if (!(pf
->flags
& I40E_FLAG_RSS_ENABLED
))
7488 new_rss_size
= min_t(int, queue_count
, pf
->rss_size_max
);
7490 if (queue_count
!= vsi
->num_queue_pairs
) {
7491 vsi
->req_queue_pairs
= queue_count
;
7492 i40e_prep_for_reset(pf
);
7494 pf
->rss_size
= new_rss_size
;
7496 i40e_reset_and_rebuild(pf
, true);
7497 i40e_config_rss(pf
);
7499 dev_info(&pf
->pdev
->dev
, "RSS count: %d\n", pf
->rss_size
);
7500 return pf
->rss_size
;
7504 * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition
7505 * @pf: board private structure
7507 i40e_status
i40e_get_npar_bw_setting(struct i40e_pf
*pf
)
7510 bool min_valid
, max_valid
;
7513 status
= i40e_read_bw_from_alt_ram(&pf
->hw
, &max_bw
, &min_bw
,
7514 &min_valid
, &max_valid
);
7518 pf
->npar_min_bw
= min_bw
;
7520 pf
->npar_max_bw
= max_bw
;
7527 * i40e_set_npar_bw_setting - Set BW settings for this PF partition
7528 * @pf: board private structure
7530 i40e_status
i40e_set_npar_bw_setting(struct i40e_pf
*pf
)
7532 struct i40e_aqc_configure_partition_bw_data bw_data
;
7535 /* Set the valid bit for this PF */
7536 bw_data
.pf_valid_bits
= cpu_to_le16(1 << pf
->hw
.pf_id
);
7537 bw_data
.max_bw
[pf
->hw
.pf_id
] = pf
->npar_max_bw
& I40E_ALT_BW_VALUE_MASK
;
7538 bw_data
.min_bw
[pf
->hw
.pf_id
] = pf
->npar_min_bw
& I40E_ALT_BW_VALUE_MASK
;
7540 /* Set the new bandwidths */
7541 status
= i40e_aq_configure_partition_bw(&pf
->hw
, &bw_data
, NULL
);
7547 * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition
7548 * @pf: board private structure
7550 i40e_status
i40e_commit_npar_bw_setting(struct i40e_pf
*pf
)
7552 /* Commit temporary BW setting to permanent NVM image */
7553 enum i40e_admin_queue_err last_aq_status
;
7557 if (pf
->hw
.partition_id
!= 1) {
7558 dev_info(&pf
->pdev
->dev
,
7559 "Commit BW only works on partition 1! This is partition %d",
7560 pf
->hw
.partition_id
);
7561 ret
= I40E_NOT_SUPPORTED
;
7565 /* Acquire NVM for read access */
7566 ret
= i40e_acquire_nvm(&pf
->hw
, I40E_RESOURCE_READ
);
7567 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
7569 dev_info(&pf
->pdev
->dev
,
7570 "Cannot acquire NVM for read access, err %d: aq_err %d\n",
7571 ret
, last_aq_status
);
7575 /* Read word 0x10 of NVM - SW compatibility word 1 */
7576 ret
= i40e_aq_read_nvm(&pf
->hw
,
7577 I40E_SR_NVM_CONTROL_WORD
,
7578 0x10, sizeof(nvm_word
), &nvm_word
,
7580 /* Save off last admin queue command status before releasing
7583 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
7584 i40e_release_nvm(&pf
->hw
);
7586 dev_info(&pf
->pdev
->dev
, "NVM read error, err %d aq_err %d\n",
7587 ret
, last_aq_status
);
7591 /* Wait a bit for NVM release to complete */
7594 /* Acquire NVM for write access */
7595 ret
= i40e_acquire_nvm(&pf
->hw
, I40E_RESOURCE_WRITE
);
7596 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
7598 dev_info(&pf
->pdev
->dev
,
7599 "Cannot acquire NVM for write access, err %d: aq_err %d\n",
7600 ret
, last_aq_status
);
7603 /* Write it back out unchanged to initiate update NVM,
7604 * which will force a write of the shadow (alt) RAM to
7605 * the NVM - thus storing the bandwidth values permanently.
7607 ret
= i40e_aq_update_nvm(&pf
->hw
,
7608 I40E_SR_NVM_CONTROL_WORD
,
7609 0x10, sizeof(nvm_word
),
7610 &nvm_word
, true, NULL
);
7611 /* Save off last admin queue command status before releasing
7614 last_aq_status
= pf
->hw
.aq
.asq_last_status
;
7615 i40e_release_nvm(&pf
->hw
);
7617 dev_info(&pf
->pdev
->dev
,
7618 "BW settings NOT SAVED, err %d aq_err %d\n",
7619 ret
, last_aq_status
);
7626 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
7627 * @pf: board private structure to initialize
7629 * i40e_sw_init initializes the Adapter private data structure.
7630 * Fields are initialized based on PCI device information and
7631 * OS network device settings (MTU size).
7633 static int i40e_sw_init(struct i40e_pf
*pf
)
7638 pf
->msg_enable
= netif_msg_init(I40E_DEFAULT_MSG_ENABLE
,
7639 (NETIF_MSG_DRV
|NETIF_MSG_PROBE
|NETIF_MSG_LINK
));
7640 pf
->hw
.debug_mask
= pf
->msg_enable
| I40E_DEBUG_DIAG
;
7641 if (debug
!= -1 && debug
!= I40E_DEFAULT_MSG_ENABLE
) {
7642 if (I40E_DEBUG_USER
& debug
)
7643 pf
->hw
.debug_mask
= debug
;
7644 pf
->msg_enable
= netif_msg_init((debug
& ~I40E_DEBUG_USER
),
7645 I40E_DEFAULT_MSG_ENABLE
);
7648 /* Set default capability flags */
7649 pf
->flags
= I40E_FLAG_RX_CSUM_ENABLED
|
7650 I40E_FLAG_MSI_ENABLED
|
7651 I40E_FLAG_MSIX_ENABLED
;
7653 if (iommu_present(&pci_bus_type
))
7654 pf
->flags
|= I40E_FLAG_RX_PS_ENABLED
;
7656 pf
->flags
|= I40E_FLAG_RX_1BUF_ENABLED
;
7658 /* Set default ITR */
7659 pf
->rx_itr_default
= I40E_ITR_DYNAMIC
| I40E_ITR_RX_DEF
;
7660 pf
->tx_itr_default
= I40E_ITR_DYNAMIC
| I40E_ITR_TX_DEF
;
7662 /* Depending on PF configurations, it is possible that the RSS
7663 * maximum might end up larger than the available queues
7665 pf
->rss_size_max
= 0x1 << pf
->hw
.func_caps
.rss_table_entry_width
;
7667 pf
->rss_table_size
= pf
->hw
.func_caps
.rss_table_size
;
7668 pf
->rss_size_max
= min_t(int, pf
->rss_size_max
,
7669 pf
->hw
.func_caps
.num_tx_qp
);
7670 if (pf
->hw
.func_caps
.rss
) {
7671 pf
->flags
|= I40E_FLAG_RSS_ENABLED
;
7672 pf
->rss_size
= min_t(int, pf
->rss_size_max
, num_online_cpus());
7675 /* MFP mode enabled */
7676 if (pf
->hw
.func_caps
.npar_enable
|| pf
->hw
.func_caps
.mfp_mode_1
) {
7677 pf
->flags
|= I40E_FLAG_MFP_ENABLED
;
7678 dev_info(&pf
->pdev
->dev
, "MFP mode Enabled\n");
7679 if (i40e_get_npar_bw_setting(pf
))
7680 dev_warn(&pf
->pdev
->dev
,
7681 "Could not get NPAR bw settings\n");
7683 dev_info(&pf
->pdev
->dev
,
7684 "Min BW = %8.8x, Max BW = %8.8x\n",
7685 pf
->npar_min_bw
, pf
->npar_max_bw
);
7688 /* FW/NVM is not yet fixed in this regard */
7689 if ((pf
->hw
.func_caps
.fd_filters_guaranteed
> 0) ||
7690 (pf
->hw
.func_caps
.fd_filters_best_effort
> 0)) {
7691 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
7692 pf
->atr_sample_rate
= I40E_DEFAULT_ATR_SAMPLE_RATE
;
7693 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
)) {
7694 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
7696 dev_info(&pf
->pdev
->dev
,
7697 "Flow Director Sideband mode Disabled in MFP mode\n");
7699 pf
->fdir_pf_filter_count
=
7700 pf
->hw
.func_caps
.fd_filters_guaranteed
;
7701 pf
->hw
.fdir_shared_filter_count
=
7702 pf
->hw
.func_caps
.fd_filters_best_effort
;
7705 if (pf
->hw
.func_caps
.vmdq
) {
7706 pf
->flags
|= I40E_FLAG_VMDQ_ENABLED
;
7707 pf
->num_vmdq_vsis
= I40E_DEFAULT_NUM_VMDQ_VSI
;
7708 pf
->num_vmdq_qps
= I40E_DEFAULT_QUEUES_PER_VMDQ
;
7712 err
= i40e_init_pf_fcoe(pf
);
7714 dev_info(&pf
->pdev
->dev
, "init_pf_fcoe failed: %d\n", err
);
7716 #endif /* I40E_FCOE */
7717 #ifdef CONFIG_PCI_IOV
7718 if (pf
->hw
.func_caps
.num_vfs
&& pf
->hw
.partition_id
== 1) {
7719 pf
->num_vf_qps
= I40E_DEFAULT_QUEUES_PER_VF
;
7720 pf
->flags
|= I40E_FLAG_SRIOV_ENABLED
;
7721 pf
->num_req_vfs
= min_t(int,
7722 pf
->hw
.func_caps
.num_vfs
,
7725 #endif /* CONFIG_PCI_IOV */
7726 pf
->eeprom_version
= 0xDEAD;
7727 pf
->lan_veb
= I40E_NO_VEB
;
7728 pf
->lan_vsi
= I40E_NO_VSI
;
7730 /* set up queue assignment tracking */
7731 size
= sizeof(struct i40e_lump_tracking
)
7732 + (sizeof(u16
) * pf
->hw
.func_caps
.num_tx_qp
);
7733 pf
->qp_pile
= kzalloc(size
, GFP_KERNEL
);
7738 pf
->qp_pile
->num_entries
= pf
->hw
.func_caps
.num_tx_qp
;
7739 pf
->qp_pile
->search_hint
= 0;
7741 pf
->tx_timeout_recovery_level
= 1;
7743 mutex_init(&pf
->switch_mutex
);
7745 /* If NPAR is enabled nudge the Tx scheduler */
7746 if (pf
->hw
.func_caps
.npar_enable
&& (!i40e_get_npar_bw_setting(pf
)))
7747 i40e_set_npar_bw_setting(pf
);
7754 * i40e_set_ntuple - set the ntuple feature flag and take action
7755 * @pf: board private structure to initialize
7756 * @features: the feature set that the stack is suggesting
7758 * returns a bool to indicate if reset needs to happen
7760 bool i40e_set_ntuple(struct i40e_pf
*pf
, netdev_features_t features
)
7762 bool need_reset
= false;
7764 /* Check if Flow Director n-tuple support was enabled or disabled. If
7765 * the state changed, we need to reset.
7767 if (features
& NETIF_F_NTUPLE
) {
7768 /* Enable filters and mark for reset */
7769 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
7771 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
7773 /* turn off filters, mark for reset and clear SW filter list */
7774 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
7776 i40e_fdir_filter_exit(pf
);
7778 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7779 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7780 /* reset fd counters */
7781 pf
->fd_add_err
= pf
->fd_atr_cnt
= pf
->fd_tcp_rule
= 0;
7782 pf
->fdir_pf_active_filters
= 0;
7783 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
7784 if (I40E_DEBUG_FD
& pf
->hw
.debug_mask
)
7785 dev_info(&pf
->pdev
->dev
, "ATR re-enabled.\n");
7786 /* if ATR was auto disabled it can be re-enabled. */
7787 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
7788 (pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
))
7789 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
7795 * i40e_set_features - set the netdev feature flags
7796 * @netdev: ptr to the netdev being adjusted
7797 * @features: the feature set that the stack is suggesting
7799 static int i40e_set_features(struct net_device
*netdev
,
7800 netdev_features_t features
)
7802 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7803 struct i40e_vsi
*vsi
= np
->vsi
;
7804 struct i40e_pf
*pf
= vsi
->back
;
7807 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
7808 i40e_vlan_stripping_enable(vsi
);
7810 i40e_vlan_stripping_disable(vsi
);
7812 need_reset
= i40e_set_ntuple(pf
, features
);
7815 i40e_do_reset(pf
, (1 << __I40E_PF_RESET_REQUESTED
));
7820 #ifdef CONFIG_I40E_VXLAN
7822 * i40e_get_vxlan_port_idx - Lookup a possibly offloaded for Rx UDP port
7823 * @pf: board private structure
7824 * @port: The UDP port to look up
7826 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
7828 static u8
i40e_get_vxlan_port_idx(struct i40e_pf
*pf
, __be16 port
)
7832 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
7833 if (pf
->vxlan_ports
[i
] == port
)
7841 * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up
7842 * @netdev: This physical port's netdev
7843 * @sa_family: Socket Family that VXLAN is notifying us about
7844 * @port: New UDP port number that VXLAN started listening to
7846 static void i40e_add_vxlan_port(struct net_device
*netdev
,
7847 sa_family_t sa_family
, __be16 port
)
7849 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7850 struct i40e_vsi
*vsi
= np
->vsi
;
7851 struct i40e_pf
*pf
= vsi
->back
;
7855 if (sa_family
== AF_INET6
)
7858 idx
= i40e_get_vxlan_port_idx(pf
, port
);
7860 /* Check if port already exists */
7861 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
7862 netdev_info(netdev
, "vxlan port %d already offloaded\n",
7867 /* Now check if there is space to add the new port */
7868 next_idx
= i40e_get_vxlan_port_idx(pf
, 0);
7870 if (next_idx
== I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
7871 netdev_info(netdev
, "maximum number of vxlan UDP ports reached, not adding port %d\n",
7876 /* New port: add it and mark its index in the bitmap */
7877 pf
->vxlan_ports
[next_idx
] = port
;
7878 pf
->pending_vxlan_bitmap
|= (1 << next_idx
);
7879 pf
->flags
|= I40E_FLAG_VXLAN_FILTER_SYNC
;
7881 dev_info(&pf
->pdev
->dev
, "adding vxlan port %d\n", ntohs(port
));
7885 * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away
7886 * @netdev: This physical port's netdev
7887 * @sa_family: Socket Family that VXLAN is notifying us about
7888 * @port: UDP port number that VXLAN stopped listening to
7890 static void i40e_del_vxlan_port(struct net_device
*netdev
,
7891 sa_family_t sa_family
, __be16 port
)
7893 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7894 struct i40e_vsi
*vsi
= np
->vsi
;
7895 struct i40e_pf
*pf
= vsi
->back
;
7898 if (sa_family
== AF_INET6
)
7901 idx
= i40e_get_vxlan_port_idx(pf
, port
);
7903 /* Check if port already exists */
7904 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
7905 /* if port exists, set it to 0 (mark for deletion)
7906 * and make it pending
7908 pf
->vxlan_ports
[idx
] = 0;
7909 pf
->pending_vxlan_bitmap
|= (1 << idx
);
7910 pf
->flags
|= I40E_FLAG_VXLAN_FILTER_SYNC
;
7912 dev_info(&pf
->pdev
->dev
, "deleting vxlan port %d\n",
7915 netdev_warn(netdev
, "vxlan port %d was not found, not deleting\n",
7921 static int i40e_get_phys_port_id(struct net_device
*netdev
,
7922 struct netdev_phys_item_id
*ppid
)
7924 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7925 struct i40e_pf
*pf
= np
->vsi
->back
;
7926 struct i40e_hw
*hw
= &pf
->hw
;
7928 if (!(pf
->flags
& I40E_FLAG_PORT_ID_VALID
))
7931 ppid
->id_len
= min_t(int, sizeof(hw
->mac
.port_addr
), sizeof(ppid
->id
));
7932 memcpy(ppid
->id
, hw
->mac
.port_addr
, ppid
->id_len
);
7938 * i40e_ndo_fdb_add - add an entry to the hardware database
7939 * @ndm: the input from the stack
7940 * @tb: pointer to array of nladdr (unused)
7941 * @dev: the net device pointer
7942 * @addr: the MAC address entry being added
7943 * @flags: instructions from stack about fdb operation
7945 static int i40e_ndo_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
7946 struct net_device
*dev
,
7947 const unsigned char *addr
, u16 vid
,
7950 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
7951 struct i40e_pf
*pf
= np
->vsi
->back
;
7954 if (!(pf
->flags
& I40E_FLAG_SRIOV_ENABLED
))
7958 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev
->name
);
7962 /* Hardware does not support aging addresses so if a
7963 * ndm_state is given only allow permanent addresses
7965 if (ndm
->ndm_state
&& !(ndm
->ndm_state
& NUD_PERMANENT
)) {
7966 netdev_info(dev
, "FDB only supports static addresses\n");
7970 if (is_unicast_ether_addr(addr
) || is_link_local_ether_addr(addr
))
7971 err
= dev_uc_add_excl(dev
, addr
);
7972 else if (is_multicast_ether_addr(addr
))
7973 err
= dev_mc_add_excl(dev
, addr
);
7977 /* Only return duplicate errors if NLM_F_EXCL is set */
7978 if (err
== -EEXIST
&& !(flags
& NLM_F_EXCL
))
7984 #ifdef HAVE_BRIDGE_ATTRIBS
7986 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
7987 * @dev: the netdev being configured
7988 * @nlh: RTNL message
7990 * Inserts a new hardware bridge if not already created and
7991 * enables the bridging mode requested (VEB or VEPA). If the
7992 * hardware bridge has already been inserted and the request
7993 * is to change the mode then that requires a PF reset to
7994 * allow rebuild of the components with required hardware
7995 * bridge mode enabled.
7997 static int i40e_ndo_bridge_setlink(struct net_device
*dev
,
7998 struct nlmsghdr
*nlh
)
8000 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
8001 struct i40e_vsi
*vsi
= np
->vsi
;
8002 struct i40e_pf
*pf
= vsi
->back
;
8003 struct i40e_veb
*veb
= NULL
;
8004 struct nlattr
*attr
, *br_spec
;
8007 /* Only for PF VSI for now */
8008 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
)
8011 /* Find the HW bridge for PF VSI */
8012 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
8013 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
8017 br_spec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
8019 nla_for_each_nested(attr
, br_spec
, rem
) {
8022 if (nla_type(attr
) != IFLA_BRIDGE_MODE
)
8025 mode
= nla_get_u16(attr
);
8026 if ((mode
!= BRIDGE_MODE_VEPA
) &&
8027 (mode
!= BRIDGE_MODE_VEB
))
8030 /* Insert a new HW bridge */
8032 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
8033 vsi
->tc_config
.enabled_tc
);
8035 veb
->bridge_mode
= mode
;
8036 i40e_config_bridge_mode(veb
);
8038 /* No Bridge HW offload available */
8042 } else if (mode
!= veb
->bridge_mode
) {
8043 /* Existing HW bridge but different mode needs reset */
8044 veb
->bridge_mode
= mode
;
8045 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
8046 if (mode
== BRIDGE_MODE_VEB
)
8047 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
8049 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
8050 i40e_do_reset(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
8059 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
8062 * @seq: RTNL message seq #
8063 * @dev: the netdev being configured
8064 * @filter_mask: unused
8066 * Return the mode in which the hardware bridge is operating in
8069 #ifdef HAVE_BRIDGE_FILTER
8070 static int i40e_ndo_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
8071 struct net_device
*dev
,
8072 u32 filter_mask
, int nlflags
)
8074 static int i40e_ndo_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
8075 struct net_device
*dev
, int nlflags
)
8076 #endif /* HAVE_BRIDGE_FILTER */
8078 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
8079 struct i40e_vsi
*vsi
= np
->vsi
;
8080 struct i40e_pf
*pf
= vsi
->back
;
8081 struct i40e_veb
*veb
= NULL
;
8084 /* Only for PF VSI for now */
8085 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
)
8088 /* Find the HW bridge for the PF VSI */
8089 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
8090 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
8097 return ndo_dflt_bridge_getlink(skb
, pid
, seq
, dev
, veb
->bridge_mode
,
8098 nlflags
, 0, 0, filter_mask
, NULL
);
8100 #endif /* HAVE_BRIDGE_ATTRIBS */
8102 static const struct net_device_ops i40e_netdev_ops
= {
8103 .ndo_open
= i40e_open
,
8104 .ndo_stop
= i40e_close
,
8105 .ndo_start_xmit
= i40e_lan_xmit_frame
,
8106 .ndo_get_stats64
= i40e_get_netdev_stats_struct
,
8107 .ndo_set_rx_mode
= i40e_set_rx_mode
,
8108 .ndo_validate_addr
= eth_validate_addr
,
8109 .ndo_set_mac_address
= i40e_set_mac
,
8110 .ndo_change_mtu
= i40e_change_mtu
,
8111 .ndo_do_ioctl
= i40e_ioctl
,
8112 .ndo_tx_timeout
= i40e_tx_timeout
,
8113 .ndo_vlan_rx_add_vid
= i40e_vlan_rx_add_vid
,
8114 .ndo_vlan_rx_kill_vid
= i40e_vlan_rx_kill_vid
,
8115 #ifdef CONFIG_NET_POLL_CONTROLLER
8116 .ndo_poll_controller
= i40e_netpoll
,
8118 .ndo_setup_tc
= i40e_setup_tc
,
8120 .ndo_fcoe_enable
= i40e_fcoe_enable
,
8121 .ndo_fcoe_disable
= i40e_fcoe_disable
,
8123 .ndo_set_features
= i40e_set_features
,
8124 .ndo_set_vf_mac
= i40e_ndo_set_vf_mac
,
8125 .ndo_set_vf_vlan
= i40e_ndo_set_vf_port_vlan
,
8126 .ndo_set_vf_rate
= i40e_ndo_set_vf_bw
,
8127 .ndo_get_vf_config
= i40e_ndo_get_vf_config
,
8128 .ndo_set_vf_link_state
= i40e_ndo_set_vf_link_state
,
8129 .ndo_set_vf_spoofchk
= i40e_ndo_set_vf_spoofchk
,
8130 #ifdef CONFIG_I40E_VXLAN
8131 .ndo_add_vxlan_port
= i40e_add_vxlan_port
,
8132 .ndo_del_vxlan_port
= i40e_del_vxlan_port
,
8134 .ndo_get_phys_port_id
= i40e_get_phys_port_id
,
8135 .ndo_fdb_add
= i40e_ndo_fdb_add
,
8136 #ifdef HAVE_BRIDGE_ATTRIBS
8137 .ndo_bridge_getlink
= i40e_ndo_bridge_getlink
,
8138 .ndo_bridge_setlink
= i40e_ndo_bridge_setlink
,
8139 #endif /* HAVE_BRIDGE_ATTRIBS */
8143 * i40e_config_netdev - Setup the netdev flags
8144 * @vsi: the VSI being configured
8146 * Returns 0 on success, negative value on failure
8148 static int i40e_config_netdev(struct i40e_vsi
*vsi
)
8150 u8 brdcast
[ETH_ALEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
8151 struct i40e_pf
*pf
= vsi
->back
;
8152 struct i40e_hw
*hw
= &pf
->hw
;
8153 struct i40e_netdev_priv
*np
;
8154 struct net_device
*netdev
;
8155 u8 mac_addr
[ETH_ALEN
];
8158 etherdev_size
= sizeof(struct i40e_netdev_priv
);
8159 netdev
= alloc_etherdev_mq(etherdev_size
, vsi
->alloc_queue_pairs
);
8163 vsi
->netdev
= netdev
;
8164 np
= netdev_priv(netdev
);
8167 netdev
->hw_enc_features
|= NETIF_F_IP_CSUM
|
8168 NETIF_F_GSO_UDP_TUNNEL
|
8171 netdev
->features
= NETIF_F_SG
|
8175 NETIF_F_GSO_UDP_TUNNEL
|
8176 NETIF_F_HW_VLAN_CTAG_TX
|
8177 NETIF_F_HW_VLAN_CTAG_RX
|
8178 NETIF_F_HW_VLAN_CTAG_FILTER
|
8187 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
8188 netdev
->features
|= NETIF_F_NTUPLE
;
8190 /* copy netdev features into list of user selectable features */
8191 netdev
->hw_features
|= netdev
->features
;
8193 if (vsi
->type
== I40E_VSI_MAIN
) {
8194 SET_NETDEV_DEV(netdev
, &pf
->pdev
->dev
);
8195 ether_addr_copy(mac_addr
, hw
->mac
.perm_addr
);
8196 /* The following steps are necessary to prevent reception
8197 * of tagged packets - some older NVM configurations load a
8198 * default a MAC-VLAN filter that accepts any tagged packet
8199 * which must be replaced by a normal filter.
8201 if (!i40e_rm_default_mac_filter(vsi
, mac_addr
))
8202 i40e_add_filter(vsi
, mac_addr
,
8203 I40E_VLAN_ANY
, false, true);
8205 /* relate the VSI_VMDQ name to the VSI_MAIN name */
8206 snprintf(netdev
->name
, IFNAMSIZ
, "%sv%%d",
8207 pf
->vsi
[pf
->lan_vsi
]->netdev
->name
);
8208 random_ether_addr(mac_addr
);
8209 i40e_add_filter(vsi
, mac_addr
, I40E_VLAN_ANY
, false, false);
8211 i40e_add_filter(vsi
, brdcast
, I40E_VLAN_ANY
, false, false);
8213 ether_addr_copy(netdev
->dev_addr
, mac_addr
);
8214 ether_addr_copy(netdev
->perm_addr
, mac_addr
);
8215 /* vlan gets same features (except vlan offload)
8216 * after any tweaks for specific VSI types
8218 netdev
->vlan_features
= netdev
->features
& ~(NETIF_F_HW_VLAN_CTAG_TX
|
8219 NETIF_F_HW_VLAN_CTAG_RX
|
8220 NETIF_F_HW_VLAN_CTAG_FILTER
);
8221 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
8222 netdev
->priv_flags
|= IFF_SUPP_NOFCS
;
8223 /* Setup netdev TC information */
8224 i40e_vsi_config_netdev_tc(vsi
, vsi
->tc_config
.enabled_tc
);
8226 netdev
->netdev_ops
= &i40e_netdev_ops
;
8227 netdev
->watchdog_timeo
= 5 * HZ
;
8228 i40e_set_ethtool_ops(netdev
);
8230 i40e_fcoe_config_netdev(netdev
, vsi
);
8237 * i40e_vsi_delete - Delete a VSI from the switch
8238 * @vsi: the VSI being removed
8240 * Returns 0 on success, negative value on failure
8242 static void i40e_vsi_delete(struct i40e_vsi
*vsi
)
8244 /* remove default VSI is not allowed */
8245 if (vsi
== vsi
->back
->vsi
[vsi
->back
->lan_vsi
])
8248 i40e_aq_delete_element(&vsi
->back
->hw
, vsi
->seid
, NULL
);
8252 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
8253 * @vsi: the VSI being queried
8255 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
8257 int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi
*vsi
)
8259 struct i40e_veb
*veb
;
8260 struct i40e_pf
*pf
= vsi
->back
;
8262 /* Uplink is not a bridge so default to VEB */
8263 if (vsi
->veb_idx
== I40E_NO_VEB
)
8266 veb
= pf
->veb
[vsi
->veb_idx
];
8267 /* Uplink is a bridge in VEPA mode */
8268 if (veb
&& (veb
->bridge_mode
& BRIDGE_MODE_VEPA
))
8271 /* Uplink is a bridge in VEB mode */
8276 * i40e_add_vsi - Add a VSI to the switch
8277 * @vsi: the VSI being configured
8279 * This initializes a VSI context depending on the VSI type to be added and
8280 * passes it down to the add_vsi aq command.
8282 static int i40e_add_vsi(struct i40e_vsi
*vsi
)
8285 struct i40e_mac_filter
*f
, *ftmp
;
8286 struct i40e_pf
*pf
= vsi
->back
;
8287 struct i40e_hw
*hw
= &pf
->hw
;
8288 struct i40e_vsi_context ctxt
;
8289 u8 enabled_tc
= 0x1; /* TC0 enabled */
8292 memset(&ctxt
, 0, sizeof(ctxt
));
8293 switch (vsi
->type
) {
8295 /* The PF's main VSI is already setup as part of the
8296 * device initialization, so we'll not bother with
8297 * the add_vsi call, but we will retrieve the current
8300 ctxt
.seid
= pf
->main_vsi_seid
;
8301 ctxt
.pf_num
= pf
->hw
.pf_id
;
8303 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
8304 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
8306 dev_info(&pf
->pdev
->dev
,
8307 "couldn't get PF vsi config, err %d, aq_err %d\n",
8308 ret
, pf
->hw
.aq
.asq_last_status
);
8311 vsi
->info
= ctxt
.info
;
8312 vsi
->info
.valid_sections
= 0;
8314 vsi
->seid
= ctxt
.seid
;
8315 vsi
->id
= ctxt
.vsi_number
;
8317 enabled_tc
= i40e_pf_get_tc_map(pf
);
8319 /* MFP mode setup queue map and update VSI */
8320 if ((pf
->flags
& I40E_FLAG_MFP_ENABLED
) &&
8321 !(pf
->hw
.func_caps
.iscsi
)) { /* NIC type PF */
8322 memset(&ctxt
, 0, sizeof(ctxt
));
8323 ctxt
.seid
= pf
->main_vsi_seid
;
8324 ctxt
.pf_num
= pf
->hw
.pf_id
;
8326 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
8327 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
8329 dev_info(&pf
->pdev
->dev
,
8330 "update vsi failed, aq_err=%d\n",
8331 pf
->hw
.aq
.asq_last_status
);
8335 /* update the local VSI info queue map */
8336 i40e_vsi_update_queue_map(vsi
, &ctxt
);
8337 vsi
->info
.valid_sections
= 0;
8339 /* Default/Main VSI is only enabled for TC0
8340 * reconfigure it to enable all TCs that are
8341 * available on the port in SFP mode.
8342 * For MFP case the iSCSI PF would use this
8343 * flow to enable LAN+iSCSI TC.
8345 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
8347 dev_info(&pf
->pdev
->dev
,
8348 "failed to configure TCs for main VSI tc_map 0x%08x, err %d, aq_err %d\n",
8350 pf
->hw
.aq
.asq_last_status
);
8357 ctxt
.pf_num
= hw
->pf_id
;
8359 ctxt
.uplink_seid
= vsi
->uplink_seid
;
8360 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
8361 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
8362 if ((pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
) &&
8363 (i40e_is_vsi_uplink_mode_veb(vsi
))) {
8364 ctxt
.info
.valid_sections
|=
8365 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
8366 ctxt
.info
.switch_id
=
8367 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
8369 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
8372 case I40E_VSI_VMDQ2
:
8373 ctxt
.pf_num
= hw
->pf_id
;
8375 ctxt
.uplink_seid
= vsi
->uplink_seid
;
8376 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
8377 ctxt
.flags
= I40E_AQ_VSI_TYPE_VMDQ2
;
8379 /* This VSI is connected to VEB so the switch_id
8380 * should be set to zero by default.
8382 if (i40e_is_vsi_uplink_mode_veb(vsi
)) {
8383 ctxt
.info
.valid_sections
|=
8384 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
8385 ctxt
.info
.switch_id
=
8386 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
8389 /* Setup the VSI tx/rx queue map for TC0 only for now */
8390 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
8393 case I40E_VSI_SRIOV
:
8394 ctxt
.pf_num
= hw
->pf_id
;
8395 ctxt
.vf_num
= vsi
->vf_id
+ hw
->func_caps
.vf_base_id
;
8396 ctxt
.uplink_seid
= vsi
->uplink_seid
;
8397 ctxt
.connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
8398 ctxt
.flags
= I40E_AQ_VSI_TYPE_VF
;
8400 /* This VSI is connected to VEB so the switch_id
8401 * should be set to zero by default.
8403 if (i40e_is_vsi_uplink_mode_veb(vsi
)) {
8404 ctxt
.info
.valid_sections
|=
8405 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
8406 ctxt
.info
.switch_id
=
8407 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
8410 ctxt
.info
.valid_sections
|= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
8411 ctxt
.info
.port_vlan_flags
|= I40E_AQ_VSI_PVLAN_MODE_ALL
;
8412 if (pf
->vf
[vsi
->vf_id
].spoofchk
) {
8413 ctxt
.info
.valid_sections
|=
8414 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID
);
8415 ctxt
.info
.sec_flags
|=
8416 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK
|
8417 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK
);
8419 /* Setup the VSI tx/rx queue map for TC0 only for now */
8420 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
8425 ret
= i40e_fcoe_vsi_init(vsi
, &ctxt
);
8427 dev_info(&pf
->pdev
->dev
, "failed to initialize FCoE VSI\n");
8432 #endif /* I40E_FCOE */
8437 if (vsi
->type
!= I40E_VSI_MAIN
) {
8438 ret
= i40e_aq_add_vsi(hw
, &ctxt
, NULL
);
8440 dev_info(&vsi
->back
->pdev
->dev
,
8441 "add vsi failed, aq_err=%d\n",
8442 vsi
->back
->hw
.aq
.asq_last_status
);
8446 vsi
->info
= ctxt
.info
;
8447 vsi
->info
.valid_sections
= 0;
8448 vsi
->seid
= ctxt
.seid
;
8449 vsi
->id
= ctxt
.vsi_number
;
8452 /* If macvlan filters already exist, force them to get loaded */
8453 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
8457 if (f
->is_laa
&& vsi
->type
== I40E_VSI_MAIN
) {
8458 struct i40e_aqc_remove_macvlan_element_data element
;
8460 memset(&element
, 0, sizeof(element
));
8461 ether_addr_copy(element
.mac_addr
, f
->macaddr
);
8462 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
8463 ret
= i40e_aq_remove_macvlan(hw
, vsi
->seid
,
8466 /* some older FW has a different default */
8468 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
8469 i40e_aq_remove_macvlan(hw
, vsi
->seid
,
8473 i40e_aq_mac_address_write(hw
,
8474 I40E_AQC_WRITE_TYPE_LAA_WOL
,
8479 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
8480 pf
->flags
|= I40E_FLAG_FILTER_SYNC
;
8483 /* Update VSI BW information */
8484 ret
= i40e_vsi_get_bw_info(vsi
);
8486 dev_info(&pf
->pdev
->dev
,
8487 "couldn't get vsi bw info, err %d, aq_err %d\n",
8488 ret
, pf
->hw
.aq
.asq_last_status
);
8489 /* VSI is already added so not tearing that up */
8498 * i40e_vsi_release - Delete a VSI and free its resources
8499 * @vsi: the VSI being removed
8501 * Returns 0 on success or < 0 on error
8503 int i40e_vsi_release(struct i40e_vsi
*vsi
)
8505 struct i40e_mac_filter
*f
, *ftmp
;
8506 struct i40e_veb
*veb
= NULL
;
8513 /* release of a VEB-owner or last VSI is not allowed */
8514 if (vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
8515 dev_info(&pf
->pdev
->dev
, "VSI %d has existing VEB %d\n",
8516 vsi
->seid
, vsi
->uplink_seid
);
8519 if (vsi
== pf
->vsi
[pf
->lan_vsi
] &&
8520 !test_bit(__I40E_DOWN
, &pf
->state
)) {
8521 dev_info(&pf
->pdev
->dev
, "Can't remove PF VSI\n");
8525 uplink_seid
= vsi
->uplink_seid
;
8526 if (vsi
->type
!= I40E_VSI_SRIOV
) {
8527 if (vsi
->netdev_registered
) {
8528 vsi
->netdev_registered
= false;
8530 /* results in a call to i40e_close() */
8531 unregister_netdev(vsi
->netdev
);
8534 i40e_vsi_close(vsi
);
8536 i40e_vsi_disable_irq(vsi
);
8539 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
)
8540 i40e_del_filter(vsi
, f
->macaddr
, f
->vlan
,
8541 f
->is_vf
, f
->is_netdev
);
8542 i40e_sync_vsi_filters(vsi
);
8544 i40e_vsi_delete(vsi
);
8545 i40e_vsi_free_q_vectors(vsi
);
8547 free_netdev(vsi
->netdev
);
8550 i40e_vsi_clear_rings(vsi
);
8551 i40e_vsi_clear(vsi
);
8553 /* If this was the last thing on the VEB, except for the
8554 * controlling VSI, remove the VEB, which puts the controlling
8555 * VSI onto the next level down in the switch.
8557 * Well, okay, there's one more exception here: don't remove
8558 * the orphan VEBs yet. We'll wait for an explicit remove request
8559 * from up the network stack.
8561 for (n
= 0, i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
8563 pf
->vsi
[i
]->uplink_seid
== uplink_seid
&&
8564 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
8565 n
++; /* count the VSIs */
8568 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
8571 if (pf
->veb
[i
]->uplink_seid
== uplink_seid
)
8572 n
++; /* count the VEBs */
8573 if (pf
->veb
[i
]->seid
== uplink_seid
)
8576 if (n
== 0 && veb
&& veb
->uplink_seid
!= 0)
8577 i40e_veb_release(veb
);
8583 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
8584 * @vsi: ptr to the VSI
8586 * This should only be called after i40e_vsi_mem_alloc() which allocates the
8587 * corresponding SW VSI structure and initializes num_queue_pairs for the
8588 * newly allocated VSI.
8590 * Returns 0 on success or negative on failure
8592 static int i40e_vsi_setup_vectors(struct i40e_vsi
*vsi
)
8595 struct i40e_pf
*pf
= vsi
->back
;
8597 if (vsi
->q_vectors
[0]) {
8598 dev_info(&pf
->pdev
->dev
, "VSI %d has existing q_vectors\n",
8603 if (vsi
->base_vector
) {
8604 dev_info(&pf
->pdev
->dev
, "VSI %d has non-zero base vector %d\n",
8605 vsi
->seid
, vsi
->base_vector
);
8609 ret
= i40e_vsi_alloc_q_vectors(vsi
);
8611 dev_info(&pf
->pdev
->dev
,
8612 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
8613 vsi
->num_q_vectors
, vsi
->seid
, ret
);
8614 vsi
->num_q_vectors
= 0;
8615 goto vector_setup_out
;
8618 if (vsi
->num_q_vectors
)
8619 vsi
->base_vector
= i40e_get_lump(pf
, pf
->irq_pile
,
8620 vsi
->num_q_vectors
, vsi
->idx
);
8621 if (vsi
->base_vector
< 0) {
8622 dev_info(&pf
->pdev
->dev
,
8623 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
8624 vsi
->num_q_vectors
, vsi
->seid
, vsi
->base_vector
);
8625 i40e_vsi_free_q_vectors(vsi
);
8627 goto vector_setup_out
;
8635 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
8636 * @vsi: pointer to the vsi.
8638 * This re-allocates a vsi's queue resources.
8640 * Returns pointer to the successfully allocated and configured VSI sw struct
8641 * on success, otherwise returns NULL on failure.
8643 static struct i40e_vsi
*i40e_vsi_reinit_setup(struct i40e_vsi
*vsi
)
8645 struct i40e_pf
*pf
= vsi
->back
;
8649 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
8650 i40e_vsi_clear_rings(vsi
);
8652 i40e_vsi_free_arrays(vsi
, false);
8653 i40e_set_num_rings_in_vsi(vsi
);
8654 ret
= i40e_vsi_alloc_arrays(vsi
, false);
8658 ret
= i40e_get_lump(pf
, pf
->qp_pile
, vsi
->alloc_queue_pairs
, vsi
->idx
);
8660 dev_info(&pf
->pdev
->dev
,
8661 "failed to get tracking for %d queues for VSI %d err=%d\n",
8662 vsi
->alloc_queue_pairs
, vsi
->seid
, ret
);
8665 vsi
->base_queue
= ret
;
8667 /* Update the FW view of the VSI. Force a reset of TC and queue
8668 * layout configurations.
8670 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
8671 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
8672 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
8673 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
8675 /* assign it some queues */
8676 ret
= i40e_alloc_rings(vsi
);
8680 /* map all of the rings to the q_vectors */
8681 i40e_vsi_map_rings_to_vectors(vsi
);
8685 i40e_vsi_free_q_vectors(vsi
);
8686 if (vsi
->netdev_registered
) {
8687 vsi
->netdev_registered
= false;
8688 unregister_netdev(vsi
->netdev
);
8689 free_netdev(vsi
->netdev
);
8692 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
8694 i40e_vsi_clear(vsi
);
8699 * i40e_vsi_setup - Set up a VSI by a given type
8700 * @pf: board private structure
8702 * @uplink_seid: the switch element to link to
8703 * @param1: usage depends upon VSI type. For VF types, indicates VF id
8705 * This allocates the sw VSI structure and its queue resources, then add a VSI
8706 * to the identified VEB.
8708 * Returns pointer to the successfully allocated and configure VSI sw struct on
8709 * success, otherwise returns NULL on failure.
8711 struct i40e_vsi
*i40e_vsi_setup(struct i40e_pf
*pf
, u8 type
,
8712 u16 uplink_seid
, u32 param1
)
8714 struct i40e_vsi
*vsi
= NULL
;
8715 struct i40e_veb
*veb
= NULL
;
8719 /* The requested uplink_seid must be either
8720 * - the PF's port seid
8721 * no VEB is needed because this is the PF
8722 * or this is a Flow Director special case VSI
8723 * - seid of an existing VEB
8724 * - seid of a VSI that owns an existing VEB
8725 * - seid of a VSI that doesn't own a VEB
8726 * a new VEB is created and the VSI becomes the owner
8727 * - seid of the PF VSI, which is what creates the first VEB
8728 * this is a special case of the previous
8730 * Find which uplink_seid we were given and create a new VEB if needed
8732 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
8733 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== uplink_seid
) {
8739 if (!veb
&& uplink_seid
!= pf
->mac_seid
) {
8741 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
8742 if (pf
->vsi
[i
] && pf
->vsi
[i
]->seid
== uplink_seid
) {
8748 dev_info(&pf
->pdev
->dev
, "no such uplink_seid %d\n",
8753 if (vsi
->uplink_seid
== pf
->mac_seid
)
8754 veb
= i40e_veb_setup(pf
, 0, pf
->mac_seid
, vsi
->seid
,
8755 vsi
->tc_config
.enabled_tc
);
8756 else if ((vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0)
8757 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
8758 vsi
->tc_config
.enabled_tc
);
8760 if (vsi
->seid
!= pf
->vsi
[pf
->lan_vsi
]->seid
) {
8761 dev_info(&vsi
->back
->pdev
->dev
,
8762 "%s: New VSI creation error, uplink seid of LAN VSI expected.\n",
8766 /* We come up by default in VEPA mode if SRIOV is not
8767 * already enabled, in which case we can't force VEPA
8770 if (!(pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)) {
8771 veb
->bridge_mode
= BRIDGE_MODE_VEPA
;
8772 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
8774 i40e_config_bridge_mode(veb
);
8776 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
8777 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
8781 dev_info(&pf
->pdev
->dev
, "couldn't add VEB\n");
8785 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
8786 uplink_seid
= veb
->seid
;
8789 /* get vsi sw struct */
8790 v_idx
= i40e_vsi_mem_alloc(pf
, type
);
8793 vsi
= pf
->vsi
[v_idx
];
8797 vsi
->veb_idx
= (veb
? veb
->idx
: I40E_NO_VEB
);
8799 if (type
== I40E_VSI_MAIN
)
8800 pf
->lan_vsi
= v_idx
;
8801 else if (type
== I40E_VSI_SRIOV
)
8802 vsi
->vf_id
= param1
;
8803 /* assign it some queues */
8804 ret
= i40e_get_lump(pf
, pf
->qp_pile
, vsi
->alloc_queue_pairs
,
8807 dev_info(&pf
->pdev
->dev
,
8808 "failed to get tracking for %d queues for VSI %d err=%d\n",
8809 vsi
->alloc_queue_pairs
, vsi
->seid
, ret
);
8812 vsi
->base_queue
= ret
;
8814 /* get a VSI from the hardware */
8815 vsi
->uplink_seid
= uplink_seid
;
8816 ret
= i40e_add_vsi(vsi
);
8820 switch (vsi
->type
) {
8821 /* setup the netdev if needed */
8823 case I40E_VSI_VMDQ2
:
8825 ret
= i40e_config_netdev(vsi
);
8828 ret
= register_netdev(vsi
->netdev
);
8831 vsi
->netdev_registered
= true;
8832 netif_carrier_off(vsi
->netdev
);
8833 #ifdef CONFIG_I40E_DCB
8834 /* Setup DCB netlink interface */
8835 i40e_dcbnl_setup(vsi
);
8836 #endif /* CONFIG_I40E_DCB */
8840 /* set up vectors and rings if needed */
8841 ret
= i40e_vsi_setup_vectors(vsi
);
8845 ret
= i40e_alloc_rings(vsi
);
8849 /* map all of the rings to the q_vectors */
8850 i40e_vsi_map_rings_to_vectors(vsi
);
8852 i40e_vsi_reset_stats(vsi
);
8856 /* no netdev or rings for the other VSI types */
8863 i40e_vsi_free_q_vectors(vsi
);
8865 if (vsi
->netdev_registered
) {
8866 vsi
->netdev_registered
= false;
8867 unregister_netdev(vsi
->netdev
);
8868 free_netdev(vsi
->netdev
);
8872 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
8874 i40e_vsi_clear(vsi
);
8880 * i40e_veb_get_bw_info - Query VEB BW information
8881 * @veb: the veb to query
8883 * Query the Tx scheduler BW configuration data for given VEB
8885 static int i40e_veb_get_bw_info(struct i40e_veb
*veb
)
8887 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data
;
8888 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data
;
8889 struct i40e_pf
*pf
= veb
->pf
;
8890 struct i40e_hw
*hw
= &pf
->hw
;
8895 ret
= i40e_aq_query_switch_comp_bw_config(hw
, veb
->seid
,
8898 dev_info(&pf
->pdev
->dev
,
8899 "query veb bw config failed, aq_err=%d\n",
8900 hw
->aq
.asq_last_status
);
8904 ret
= i40e_aq_query_switch_comp_ets_config(hw
, veb
->seid
,
8907 dev_info(&pf
->pdev
->dev
,
8908 "query veb bw ets config failed, aq_err=%d\n",
8909 hw
->aq
.asq_last_status
);
8913 veb
->bw_limit
= le16_to_cpu(ets_data
.port_bw_limit
);
8914 veb
->bw_max_quanta
= ets_data
.tc_bw_max
;
8915 veb
->is_abs_credits
= bw_data
.absolute_credits_enable
;
8916 veb
->enabled_tc
= ets_data
.tc_valid_bits
;
8917 tc_bw_max
= le16_to_cpu(bw_data
.tc_bw_max
[0]) |
8918 (le16_to_cpu(bw_data
.tc_bw_max
[1]) << 16);
8919 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
8920 veb
->bw_tc_share_credits
[i
] = bw_data
.tc_bw_share_credits
[i
];
8921 veb
->bw_tc_limit_credits
[i
] =
8922 le16_to_cpu(bw_data
.tc_bw_limits
[i
]);
8923 veb
->bw_tc_max_quanta
[i
] = ((tc_bw_max
>> (i
*4)) & 0x7);
8931 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
8932 * @pf: board private structure
8934 * On error: returns error code (negative)
8935 * On success: returns vsi index in PF (positive)
8937 static int i40e_veb_mem_alloc(struct i40e_pf
*pf
)
8940 struct i40e_veb
*veb
;
8943 /* Need to protect the allocation of switch elements at the PF level */
8944 mutex_lock(&pf
->switch_mutex
);
8946 /* VEB list may be fragmented if VEB creation/destruction has
8947 * been happening. We can afford to do a quick scan to look
8948 * for any free slots in the list.
8950 * find next empty veb slot, looping back around if necessary
8953 while ((i
< I40E_MAX_VEB
) && (pf
->veb
[i
] != NULL
))
8955 if (i
>= I40E_MAX_VEB
) {
8957 goto err_alloc_veb
; /* out of VEB slots! */
8960 veb
= kzalloc(sizeof(*veb
), GFP_KERNEL
);
8967 veb
->enabled_tc
= 1;
8972 mutex_unlock(&pf
->switch_mutex
);
8977 * i40e_switch_branch_release - Delete a branch of the switch tree
8978 * @branch: where to start deleting
8980 * This uses recursion to find the tips of the branch to be
8981 * removed, deleting until we get back to and can delete this VEB.
8983 static void i40e_switch_branch_release(struct i40e_veb
*branch
)
8985 struct i40e_pf
*pf
= branch
->pf
;
8986 u16 branch_seid
= branch
->seid
;
8987 u16 veb_idx
= branch
->idx
;
8990 /* release any VEBs on this VEB - RECURSION */
8991 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
8994 if (pf
->veb
[i
]->uplink_seid
== branch
->seid
)
8995 i40e_switch_branch_release(pf
->veb
[i
]);
8998 /* Release the VSIs on this VEB, but not the owner VSI.
9000 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
9001 * the VEB itself, so don't use (*branch) after this loop.
9003 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9006 if (pf
->vsi
[i
]->uplink_seid
== branch_seid
&&
9007 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
9008 i40e_vsi_release(pf
->vsi
[i
]);
9012 /* There's one corner case where the VEB might not have been
9013 * removed, so double check it here and remove it if needed.
9014 * This case happens if the veb was created from the debugfs
9015 * commands and no VSIs were added to it.
9017 if (pf
->veb
[veb_idx
])
9018 i40e_veb_release(pf
->veb
[veb_idx
]);
9022 * i40e_veb_clear - remove veb struct
9023 * @veb: the veb to remove
9025 static void i40e_veb_clear(struct i40e_veb
*veb
)
9031 struct i40e_pf
*pf
= veb
->pf
;
9033 mutex_lock(&pf
->switch_mutex
);
9034 if (pf
->veb
[veb
->idx
] == veb
)
9035 pf
->veb
[veb
->idx
] = NULL
;
9036 mutex_unlock(&pf
->switch_mutex
);
9043 * i40e_veb_release - Delete a VEB and free its resources
9044 * @veb: the VEB being removed
9046 void i40e_veb_release(struct i40e_veb
*veb
)
9048 struct i40e_vsi
*vsi
= NULL
;
9054 /* find the remaining VSI and check for extras */
9055 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9056 if (pf
->vsi
[i
] && pf
->vsi
[i
]->uplink_seid
== veb
->seid
) {
9062 dev_info(&pf
->pdev
->dev
,
9063 "can't remove VEB %d with %d VSIs left\n",
9068 /* move the remaining VSI to uplink veb */
9069 vsi
->flags
&= ~I40E_VSI_FLAG_VEB_OWNER
;
9070 if (veb
->uplink_seid
) {
9071 vsi
->uplink_seid
= veb
->uplink_seid
;
9072 if (veb
->uplink_seid
== pf
->mac_seid
)
9073 vsi
->veb_idx
= I40E_NO_VEB
;
9075 vsi
->veb_idx
= veb
->veb_idx
;
9078 vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
9079 vsi
->veb_idx
= pf
->vsi
[pf
->lan_vsi
]->veb_idx
;
9082 i40e_aq_delete_element(&pf
->hw
, veb
->seid
, NULL
);
9083 i40e_veb_clear(veb
);
9087 * i40e_add_veb - create the VEB in the switch
9088 * @veb: the VEB to be instantiated
9089 * @vsi: the controlling VSI
9091 static int i40e_add_veb(struct i40e_veb
*veb
, struct i40e_vsi
*vsi
)
9093 bool is_default
= false;
9094 bool is_cloud
= false;
9097 /* get a VEB from the hardware */
9098 ret
= i40e_aq_add_veb(&veb
->pf
->hw
, veb
->uplink_seid
, vsi
->seid
,
9099 veb
->enabled_tc
, is_default
,
9100 is_cloud
, &veb
->seid
, NULL
);
9102 dev_info(&veb
->pf
->pdev
->dev
,
9103 "couldn't add VEB, err %d, aq_err %d\n",
9104 ret
, veb
->pf
->hw
.aq
.asq_last_status
);
9108 /* get statistics counter */
9109 ret
= i40e_aq_get_veb_parameters(&veb
->pf
->hw
, veb
->seid
, NULL
, NULL
,
9110 &veb
->stats_idx
, NULL
, NULL
, NULL
);
9112 dev_info(&veb
->pf
->pdev
->dev
,
9113 "couldn't get VEB statistics idx, err %d, aq_err %d\n",
9114 ret
, veb
->pf
->hw
.aq
.asq_last_status
);
9117 ret
= i40e_veb_get_bw_info(veb
);
9119 dev_info(&veb
->pf
->pdev
->dev
,
9120 "couldn't get VEB bw info, err %d, aq_err %d\n",
9121 ret
, veb
->pf
->hw
.aq
.asq_last_status
);
9122 i40e_aq_delete_element(&veb
->pf
->hw
, veb
->seid
, NULL
);
9126 vsi
->uplink_seid
= veb
->seid
;
9127 vsi
->veb_idx
= veb
->idx
;
9128 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
9134 * i40e_veb_setup - Set up a VEB
9135 * @pf: board private structure
9136 * @flags: VEB setup flags
9137 * @uplink_seid: the switch element to link to
9138 * @vsi_seid: the initial VSI seid
9139 * @enabled_tc: Enabled TC bit-map
9141 * This allocates the sw VEB structure and links it into the switch
9142 * It is possible and legal for this to be a duplicate of an already
9143 * existing VEB. It is also possible for both uplink and vsi seids
9144 * to be zero, in order to create a floating VEB.
9146 * Returns pointer to the successfully allocated VEB sw struct on
9147 * success, otherwise returns NULL on failure.
9149 struct i40e_veb
*i40e_veb_setup(struct i40e_pf
*pf
, u16 flags
,
9150 u16 uplink_seid
, u16 vsi_seid
,
9153 struct i40e_veb
*veb
, *uplink_veb
= NULL
;
9154 int vsi_idx
, veb_idx
;
9157 /* if one seid is 0, the other must be 0 to create a floating relay */
9158 if ((uplink_seid
== 0 || vsi_seid
== 0) &&
9159 (uplink_seid
+ vsi_seid
!= 0)) {
9160 dev_info(&pf
->pdev
->dev
,
9161 "one, not both seid's are 0: uplink=%d vsi=%d\n",
9162 uplink_seid
, vsi_seid
);
9166 /* make sure there is such a vsi and uplink */
9167 for (vsi_idx
= 0; vsi_idx
< pf
->num_alloc_vsi
; vsi_idx
++)
9168 if (pf
->vsi
[vsi_idx
] && pf
->vsi
[vsi_idx
]->seid
== vsi_seid
)
9170 if (vsi_idx
>= pf
->num_alloc_vsi
&& vsi_seid
!= 0) {
9171 dev_info(&pf
->pdev
->dev
, "vsi seid %d not found\n",
9176 if (uplink_seid
&& uplink_seid
!= pf
->mac_seid
) {
9177 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
9178 if (pf
->veb
[veb_idx
] &&
9179 pf
->veb
[veb_idx
]->seid
== uplink_seid
) {
9180 uplink_veb
= pf
->veb
[veb_idx
];
9185 dev_info(&pf
->pdev
->dev
,
9186 "uplink seid %d not found\n", uplink_seid
);
9191 /* get veb sw struct */
9192 veb_idx
= i40e_veb_mem_alloc(pf
);
9195 veb
= pf
->veb
[veb_idx
];
9197 veb
->uplink_seid
= uplink_seid
;
9198 veb
->veb_idx
= (uplink_veb
? uplink_veb
->idx
: I40E_NO_VEB
);
9199 veb
->enabled_tc
= (enabled_tc
? enabled_tc
: 0x1);
9201 /* create the VEB in the switch */
9202 ret
= i40e_add_veb(veb
, pf
->vsi
[vsi_idx
]);
9205 if (vsi_idx
== pf
->lan_vsi
)
9206 pf
->lan_veb
= veb
->idx
;
9211 i40e_veb_clear(veb
);
9217 * i40e_setup_pf_switch_element - set PF vars based on switch type
9218 * @pf: board private structure
9219 * @ele: element we are building info from
9220 * @num_reported: total number of elements
9221 * @printconfig: should we print the contents
9223 * helper function to assist in extracting a few useful SEID values.
9225 static void i40e_setup_pf_switch_element(struct i40e_pf
*pf
,
9226 struct i40e_aqc_switch_config_element_resp
*ele
,
9227 u16 num_reported
, bool printconfig
)
9229 u16 downlink_seid
= le16_to_cpu(ele
->downlink_seid
);
9230 u16 uplink_seid
= le16_to_cpu(ele
->uplink_seid
);
9231 u8 element_type
= ele
->element_type
;
9232 u16 seid
= le16_to_cpu(ele
->seid
);
9235 dev_info(&pf
->pdev
->dev
,
9236 "type=%d seid=%d uplink=%d downlink=%d\n",
9237 element_type
, seid
, uplink_seid
, downlink_seid
);
9239 switch (element_type
) {
9240 case I40E_SWITCH_ELEMENT_TYPE_MAC
:
9241 pf
->mac_seid
= seid
;
9243 case I40E_SWITCH_ELEMENT_TYPE_VEB
:
9245 if (uplink_seid
!= pf
->mac_seid
)
9247 if (pf
->lan_veb
== I40E_NO_VEB
) {
9250 /* find existing or else empty VEB */
9251 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
9252 if (pf
->veb
[v
] && (pf
->veb
[v
]->seid
== seid
)) {
9257 if (pf
->lan_veb
== I40E_NO_VEB
) {
9258 v
= i40e_veb_mem_alloc(pf
);
9265 pf
->veb
[pf
->lan_veb
]->seid
= seid
;
9266 pf
->veb
[pf
->lan_veb
]->uplink_seid
= pf
->mac_seid
;
9267 pf
->veb
[pf
->lan_veb
]->pf
= pf
;
9268 pf
->veb
[pf
->lan_veb
]->veb_idx
= I40E_NO_VEB
;
9270 case I40E_SWITCH_ELEMENT_TYPE_VSI
:
9271 if (num_reported
!= 1)
9273 /* This is immediately after a reset so we can assume this is
9276 pf
->mac_seid
= uplink_seid
;
9277 pf
->pf_seid
= downlink_seid
;
9278 pf
->main_vsi_seid
= seid
;
9280 dev_info(&pf
->pdev
->dev
,
9281 "pf_seid=%d main_vsi_seid=%d\n",
9282 pf
->pf_seid
, pf
->main_vsi_seid
);
9284 case I40E_SWITCH_ELEMENT_TYPE_PF
:
9285 case I40E_SWITCH_ELEMENT_TYPE_VF
:
9286 case I40E_SWITCH_ELEMENT_TYPE_EMP
:
9287 case I40E_SWITCH_ELEMENT_TYPE_BMC
:
9288 case I40E_SWITCH_ELEMENT_TYPE_PE
:
9289 case I40E_SWITCH_ELEMENT_TYPE_PA
:
9290 /* ignore these for now */
9293 dev_info(&pf
->pdev
->dev
, "unknown element type=%d seid=%d\n",
9294 element_type
, seid
);
9300 * i40e_fetch_switch_configuration - Get switch config from firmware
9301 * @pf: board private structure
9302 * @printconfig: should we print the contents
9304 * Get the current switch configuration from the device and
9305 * extract a few useful SEID values.
9307 int i40e_fetch_switch_configuration(struct i40e_pf
*pf
, bool printconfig
)
9309 struct i40e_aqc_get_switch_config_resp
*sw_config
;
9315 aq_buf
= kzalloc(I40E_AQ_LARGE_BUF
, GFP_KERNEL
);
9319 sw_config
= (struct i40e_aqc_get_switch_config_resp
*)aq_buf
;
9321 u16 num_reported
, num_total
;
9323 ret
= i40e_aq_get_switch_config(&pf
->hw
, sw_config
,
9327 dev_info(&pf
->pdev
->dev
,
9328 "get switch config failed %d aq_err=%x\n",
9329 ret
, pf
->hw
.aq
.asq_last_status
);
9334 num_reported
= le16_to_cpu(sw_config
->header
.num_reported
);
9335 num_total
= le16_to_cpu(sw_config
->header
.num_total
);
9338 dev_info(&pf
->pdev
->dev
,
9339 "header: %d reported %d total\n",
9340 num_reported
, num_total
);
9342 for (i
= 0; i
< num_reported
; i
++) {
9343 struct i40e_aqc_switch_config_element_resp
*ele
=
9344 &sw_config
->element
[i
];
9346 i40e_setup_pf_switch_element(pf
, ele
, num_reported
,
9349 } while (next_seid
!= 0);
9356 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
9357 * @pf: board private structure
9358 * @reinit: if the Main VSI needs to re-initialized.
9360 * Returns 0 on success, negative value on failure
9362 static int i40e_setup_pf_switch(struct i40e_pf
*pf
, bool reinit
)
9366 /* find out what's out there already */
9367 ret
= i40e_fetch_switch_configuration(pf
, false);
9369 dev_info(&pf
->pdev
->dev
,
9370 "couldn't fetch switch config, err %d, aq_err %d\n",
9371 ret
, pf
->hw
.aq
.asq_last_status
);
9374 i40e_pf_reset_stats(pf
);
9376 /* first time setup */
9377 if (pf
->lan_vsi
== I40E_NO_VSI
|| reinit
) {
9378 struct i40e_vsi
*vsi
= NULL
;
9381 /* Set up the PF VSI associated with the PF's main VSI
9382 * that is already in the HW switch
9384 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
9385 uplink_seid
= pf
->veb
[pf
->lan_veb
]->seid
;
9387 uplink_seid
= pf
->mac_seid
;
9388 if (pf
->lan_vsi
== I40E_NO_VSI
)
9389 vsi
= i40e_vsi_setup(pf
, I40E_VSI_MAIN
, uplink_seid
, 0);
9391 vsi
= i40e_vsi_reinit_setup(pf
->vsi
[pf
->lan_vsi
]);
9393 dev_info(&pf
->pdev
->dev
, "setup of MAIN VSI failed\n");
9394 i40e_fdir_teardown(pf
);
9398 /* force a reset of TC and queue layout configurations */
9399 u8 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
9400 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
9401 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
9402 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
9404 i40e_vlan_stripping_disable(pf
->vsi
[pf
->lan_vsi
]);
9406 i40e_fdir_sb_setup(pf
);
9408 /* Setup static PF queue filter control settings */
9409 ret
= i40e_setup_pf_filter_control(pf
);
9411 dev_info(&pf
->pdev
->dev
, "setup_pf_filter_control failed: %d\n",
9413 /* Failure here should not stop continuing other steps */
9416 /* enable RSS in the HW, even for only one queue, as the stack can use
9419 if ((pf
->flags
& I40E_FLAG_RSS_ENABLED
))
9420 i40e_config_rss(pf
);
9422 /* fill in link information and enable LSE reporting */
9423 i40e_aq_get_link_info(&pf
->hw
, true, NULL
, NULL
);
9424 i40e_link_event(pf
);
9426 /* Initialize user-specific link properties */
9427 pf
->fc_autoneg_status
= ((pf
->hw
.phy
.link_info
.an_info
&
9428 I40E_AQ_AN_COMPLETED
) ? true : false);
9436 * i40e_determine_queue_usage - Work out queue distribution
9437 * @pf: board private structure
9439 static void i40e_determine_queue_usage(struct i40e_pf
*pf
)
9443 pf
->num_lan_qps
= 0;
9445 pf
->num_fcoe_qps
= 0;
9448 /* Find the max queues to be put into basic use. We'll always be
9449 * using TC0, whether or not DCB is running, and TC0 will get the
9452 queues_left
= pf
->hw
.func_caps
.num_tx_qp
;
9454 if ((queues_left
== 1) ||
9455 !(pf
->flags
& I40E_FLAG_MSIX_ENABLED
)) {
9456 /* one qp for PF, no queues for anything else */
9458 pf
->rss_size
= pf
->num_lan_qps
= 1;
9460 /* make sure all the fancies are disabled */
9461 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
9463 I40E_FLAG_FCOE_ENABLED
|
9465 I40E_FLAG_FD_SB_ENABLED
|
9466 I40E_FLAG_FD_ATR_ENABLED
|
9467 I40E_FLAG_DCB_CAPABLE
|
9468 I40E_FLAG_SRIOV_ENABLED
|
9469 I40E_FLAG_VMDQ_ENABLED
);
9470 } else if (!(pf
->flags
& (I40E_FLAG_RSS_ENABLED
|
9471 I40E_FLAG_FD_SB_ENABLED
|
9472 I40E_FLAG_FD_ATR_ENABLED
|
9473 I40E_FLAG_DCB_CAPABLE
))) {
9475 pf
->rss_size
= pf
->num_lan_qps
= 1;
9476 queues_left
-= pf
->num_lan_qps
;
9478 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
9480 I40E_FLAG_FCOE_ENABLED
|
9482 I40E_FLAG_FD_SB_ENABLED
|
9483 I40E_FLAG_FD_ATR_ENABLED
|
9484 I40E_FLAG_DCB_ENABLED
|
9485 I40E_FLAG_VMDQ_ENABLED
);
9487 /* Not enough queues for all TCs */
9488 if ((pf
->flags
& I40E_FLAG_DCB_CAPABLE
) &&
9489 (queues_left
< I40E_MAX_TRAFFIC_CLASS
)) {
9490 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
9491 dev_info(&pf
->pdev
->dev
, "not enough queues for DCB. DCB is disabled.\n");
9493 pf
->num_lan_qps
= max_t(int, pf
->rss_size_max
,
9495 pf
->num_lan_qps
= min_t(int, pf
->num_lan_qps
,
9496 pf
->hw
.func_caps
.num_tx_qp
);
9498 queues_left
-= pf
->num_lan_qps
;
9502 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
9503 if (I40E_DEFAULT_FCOE
<= queues_left
) {
9504 pf
->num_fcoe_qps
= I40E_DEFAULT_FCOE
;
9505 } else if (I40E_MINIMUM_FCOE
<= queues_left
) {
9506 pf
->num_fcoe_qps
= I40E_MINIMUM_FCOE
;
9508 pf
->num_fcoe_qps
= 0;
9509 pf
->flags
&= ~I40E_FLAG_FCOE_ENABLED
;
9510 dev_info(&pf
->pdev
->dev
, "not enough queues for FCoE. FCoE feature will be disabled\n");
9513 queues_left
-= pf
->num_fcoe_qps
;
9517 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
9518 if (queues_left
> 1) {
9519 queues_left
-= 1; /* save 1 queue for FD */
9521 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
9522 dev_info(&pf
->pdev
->dev
, "not enough queues for Flow Director. Flow Director feature is disabled\n");
9526 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
9527 pf
->num_vf_qps
&& pf
->num_req_vfs
&& queues_left
) {
9528 pf
->num_req_vfs
= min_t(int, pf
->num_req_vfs
,
9529 (queues_left
/ pf
->num_vf_qps
));
9530 queues_left
-= (pf
->num_req_vfs
* pf
->num_vf_qps
);
9533 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
9534 pf
->num_vmdq_vsis
&& pf
->num_vmdq_qps
&& queues_left
) {
9535 pf
->num_vmdq_vsis
= min_t(int, pf
->num_vmdq_vsis
,
9536 (queues_left
/ pf
->num_vmdq_qps
));
9537 queues_left
-= (pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
);
9540 pf
->queues_left
= queues_left
;
9542 dev_info(&pf
->pdev
->dev
, "fcoe queues = %d\n", pf
->num_fcoe_qps
);
9547 * i40e_setup_pf_filter_control - Setup PF static filter control
9548 * @pf: PF to be setup
9550 * i40e_setup_pf_filter_control sets up a PF's initial filter control
9551 * settings. If PE/FCoE are enabled then it will also set the per PF
9552 * based filter sizes required for them. It also enables Flow director,
9553 * ethertype and macvlan type filter settings for the pf.
9555 * Returns 0 on success, negative on failure
9557 static int i40e_setup_pf_filter_control(struct i40e_pf
*pf
)
9559 struct i40e_filter_control_settings
*settings
= &pf
->filter_settings
;
9561 settings
->hash_lut_size
= I40E_HASH_LUT_SIZE_128
;
9563 /* Flow Director is enabled */
9564 if (pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
))
9565 settings
->enable_fdir
= true;
9567 /* Ethtype and MACVLAN filters enabled for PF */
9568 settings
->enable_ethtype
= true;
9569 settings
->enable_macvlan
= true;
9571 if (i40e_set_filter_control(&pf
->hw
, settings
))
9577 #define INFO_STRING_LEN 255
9578 static void i40e_print_features(struct i40e_pf
*pf
)
9580 struct i40e_hw
*hw
= &pf
->hw
;
9583 string
= kzalloc(INFO_STRING_LEN
, GFP_KERNEL
);
9585 dev_err(&pf
->pdev
->dev
, "Features string allocation failed\n");
9591 buf
+= sprintf(string
, "Features: PF-id[%d] ", hw
->pf_id
);
9592 #ifdef CONFIG_PCI_IOV
9593 buf
+= sprintf(buf
, "VFs: %d ", pf
->num_req_vfs
);
9595 buf
+= sprintf(buf
, "VSIs: %d QP: %d RX: %s ",
9596 pf
->hw
.func_caps
.num_vsis
,
9597 pf
->vsi
[pf
->lan_vsi
]->num_queue_pairs
,
9598 pf
->flags
& I40E_FLAG_RX_PS_ENABLED
? "PS" : "1BUF");
9600 if (pf
->flags
& I40E_FLAG_RSS_ENABLED
)
9601 buf
+= sprintf(buf
, "RSS ");
9602 if (pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
)
9603 buf
+= sprintf(buf
, "FD_ATR ");
9604 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
9605 buf
+= sprintf(buf
, "FD_SB ");
9606 buf
+= sprintf(buf
, "NTUPLE ");
9608 if (pf
->flags
& I40E_FLAG_DCB_CAPABLE
)
9609 buf
+= sprintf(buf
, "DCB ");
9610 if (pf
->flags
& I40E_FLAG_PTP
)
9611 buf
+= sprintf(buf
, "PTP ");
9613 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
)
9614 buf
+= sprintf(buf
, "FCOE ");
9617 BUG_ON(buf
> (string
+ INFO_STRING_LEN
));
9618 dev_info(&pf
->pdev
->dev
, "%s\n", string
);
9623 * i40e_probe - Device initialization routine
9624 * @pdev: PCI device information struct
9625 * @ent: entry in i40e_pci_tbl
9627 * i40e_probe initializes a PF identified by a pci_dev structure.
9628 * The OS initialization, configuring of the PF private structure,
9629 * and a hardware reset occur.
9631 * Returns 0 on success, negative on failure
9633 static int i40e_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
9635 struct i40e_aq_get_phy_abilities_resp abilities
;
9636 unsigned long ioremap_len
;
9639 static u16 pfs_found
;
9645 err
= pci_enable_device_mem(pdev
);
9649 /* set up for high or low dma */
9650 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
9652 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
9655 "DMA configuration failed: 0x%x\n", err
);
9660 /* set up pci connections */
9661 err
= pci_request_selected_regions(pdev
, pci_select_bars(pdev
,
9662 IORESOURCE_MEM
), i40e_driver_name
);
9664 dev_info(&pdev
->dev
,
9665 "pci_request_selected_regions failed %d\n", err
);
9669 pci_enable_pcie_error_reporting(pdev
);
9670 pci_set_master(pdev
);
9672 /* Now that we have a PCI connection, we need to do the
9673 * low level device setup. This is primarily setting up
9674 * the Admin Queue structures and then querying for the
9675 * device's current profile information.
9677 pf
= kzalloc(sizeof(*pf
), GFP_KERNEL
);
9684 set_bit(__I40E_DOWN
, &pf
->state
);
9689 ioremap_len
= min_t(unsigned long, pci_resource_len(pdev
, 0),
9690 I40E_MAX_CSR_SPACE
);
9692 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0), ioremap_len
);
9695 dev_info(&pdev
->dev
, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
9696 (unsigned int)pci_resource_start(pdev
, 0),
9697 (unsigned int)pci_resource_len(pdev
, 0), err
);
9700 hw
->vendor_id
= pdev
->vendor
;
9701 hw
->device_id
= pdev
->device
;
9702 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
9703 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
9704 hw
->subsystem_device_id
= pdev
->subsystem_device
;
9705 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
9706 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
9707 pf
->instance
= pfs_found
;
9710 pf
->msg_enable
= pf
->hw
.debug_mask
;
9711 pf
->msg_enable
= debug
;
9714 /* do a special CORER for clearing PXE mode once at init */
9715 if (hw
->revision_id
== 0 &&
9716 (rd32(hw
, I40E_GLLAN_RCTL_0
) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK
)) {
9717 wr32(hw
, I40E_GLGEN_RTRIG
, I40E_GLGEN_RTRIG_CORER_MASK
);
9722 i40e_clear_pxe_mode(hw
);
9725 /* Reset here to make sure all is clean and to define PF 'n' */
9727 err
= i40e_pf_reset(hw
);
9729 dev_info(&pdev
->dev
, "Initial pf_reset failed: %d\n", err
);
9734 hw
->aq
.num_arq_entries
= I40E_AQ_LEN
;
9735 hw
->aq
.num_asq_entries
= I40E_AQ_LEN
;
9736 hw
->aq
.arq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
9737 hw
->aq
.asq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
9738 pf
->adminq_work_limit
= I40E_AQ_WORK_LIMIT
;
9740 snprintf(pf
->int_name
, sizeof(pf
->int_name
) - 1,
9742 dev_driver_string(&pf
->pdev
->dev
), dev_name(&pdev
->dev
));
9744 err
= i40e_init_shared_code(hw
);
9746 dev_info(&pdev
->dev
, "init_shared_code failed: %d\n", err
);
9750 /* set up a default setting for link flow control */
9751 pf
->hw
.fc
.requested_mode
= I40E_FC_NONE
;
9753 err
= i40e_init_adminq(hw
);
9754 dev_info(&pdev
->dev
, "%s\n", i40e_fw_version_str(hw
));
9756 dev_info(&pdev
->dev
,
9757 "The driver for the device stopped because the NVM image is newer than expected. You must install the most recent version of the network driver.\n");
9761 if (hw
->aq
.api_maj_ver
== I40E_FW_API_VERSION_MAJOR
&&
9762 hw
->aq
.api_min_ver
> I40E_FW_API_VERSION_MINOR
)
9763 dev_info(&pdev
->dev
,
9764 "The driver for the device detected a newer version of the NVM image than expected. Please install the most recent version of the network driver.\n");
9765 else if (hw
->aq
.api_maj_ver
< I40E_FW_API_VERSION_MAJOR
||
9766 hw
->aq
.api_min_ver
< (I40E_FW_API_VERSION_MINOR
- 1))
9767 dev_info(&pdev
->dev
,
9768 "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
9770 i40e_verify_eeprom(pf
);
9772 /* Rev 0 hardware was never productized */
9773 if (hw
->revision_id
< 1)
9774 dev_warn(&pdev
->dev
, "This device is a pre-production adapter/LOM. Please be aware there may be issues with your hardware. If you are experiencing problems please contact your Intel or hardware representative who provided you with this hardware.\n");
9776 i40e_clear_pxe_mode(hw
);
9777 err
= i40e_get_capabilities(pf
);
9779 goto err_adminq_setup
;
9781 err
= i40e_sw_init(pf
);
9783 dev_info(&pdev
->dev
, "sw_init failed: %d\n", err
);
9787 err
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
9788 hw
->func_caps
.num_rx_qp
,
9789 pf
->fcoe_hmc_cntx_num
, pf
->fcoe_hmc_filt_num
);
9791 dev_info(&pdev
->dev
, "init_lan_hmc failed: %d\n", err
);
9792 goto err_init_lan_hmc
;
9795 err
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
9797 dev_info(&pdev
->dev
, "configure_lan_hmc failed: %d\n", err
);
9799 goto err_configure_lan_hmc
;
9802 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
9803 * Ignore error return codes because if it was already disabled via
9804 * hardware settings this will fail
9806 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 3)) ||
9807 (pf
->hw
.aq
.fw_maj_ver
< 4)) {
9808 dev_info(&pdev
->dev
, "Stopping firmware LLDP agent.\n");
9809 i40e_aq_stop_lldp(hw
, true, NULL
);
9812 i40e_get_mac_addr(hw
, hw
->mac
.addr
);
9813 if (!is_valid_ether_addr(hw
->mac
.addr
)) {
9814 dev_info(&pdev
->dev
, "invalid MAC address %pM\n", hw
->mac
.addr
);
9818 dev_info(&pdev
->dev
, "MAC address: %pM\n", hw
->mac
.addr
);
9819 ether_addr_copy(hw
->mac
.perm_addr
, hw
->mac
.addr
);
9820 i40e_get_port_mac_addr(hw
, hw
->mac
.port_addr
);
9821 if (is_valid_ether_addr(hw
->mac
.port_addr
))
9822 pf
->flags
|= I40E_FLAG_PORT_ID_VALID
;
9824 err
= i40e_get_san_mac_addr(hw
, hw
->mac
.san_addr
);
9826 dev_info(&pdev
->dev
,
9827 "(non-fatal) SAN MAC retrieval failed: %d\n", err
);
9828 if (!is_valid_ether_addr(hw
->mac
.san_addr
)) {
9829 dev_warn(&pdev
->dev
, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
9831 ether_addr_copy(hw
->mac
.san_addr
, hw
->mac
.addr
);
9833 dev_info(&pf
->pdev
->dev
, "SAN MAC: %pM\n", hw
->mac
.san_addr
);
9834 #endif /* I40E_FCOE */
9836 pci_set_drvdata(pdev
, pf
);
9837 pci_save_state(pdev
);
9838 #ifdef CONFIG_I40E_DCB
9839 err
= i40e_init_pf_dcb(pf
);
9841 dev_info(&pdev
->dev
, "DCB init failed %d, disabled\n", err
);
9842 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
9843 /* Continue without DCB enabled */
9845 #endif /* CONFIG_I40E_DCB */
9847 /* set up periodic task facility */
9848 setup_timer(&pf
->service_timer
, i40e_service_timer
, (unsigned long)pf
);
9849 pf
->service_timer_period
= HZ
;
9851 INIT_WORK(&pf
->service_task
, i40e_service_task
);
9852 clear_bit(__I40E_SERVICE_SCHED
, &pf
->state
);
9853 pf
->flags
|= I40E_FLAG_NEED_LINK_UPDATE
;
9854 pf
->link_check_timeout
= jiffies
;
9856 /* WoL defaults to disabled */
9858 device_set_wakeup_enable(&pf
->pdev
->dev
, pf
->wol_en
);
9860 /* set up the main switch operations */
9861 i40e_determine_queue_usage(pf
);
9862 err
= i40e_init_interrupt_scheme(pf
);
9864 goto err_switch_setup
;
9866 /* The number of VSIs reported by the FW is the minimum guaranteed
9867 * to us; HW supports far more and we share the remaining pool with
9868 * the other PFs. We allocate space for more than the guarantee with
9869 * the understanding that we might not get them all later.
9871 if (pf
->hw
.func_caps
.num_vsis
< I40E_MIN_VSI_ALLOC
)
9872 pf
->num_alloc_vsi
= I40E_MIN_VSI_ALLOC
;
9874 pf
->num_alloc_vsi
= pf
->hw
.func_caps
.num_vsis
;
9876 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
9877 len
= sizeof(struct i40e_vsi
*) * pf
->num_alloc_vsi
;
9878 pf
->vsi
= kzalloc(len
, GFP_KERNEL
);
9881 goto err_switch_setup
;
9884 #ifdef CONFIG_PCI_IOV
9885 /* prep for VF support */
9886 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
9887 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
9888 !test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
9889 if (pci_num_vf(pdev
))
9890 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
9893 err
= i40e_setup_pf_switch(pf
, false);
9895 dev_info(&pdev
->dev
, "setup_pf_switch failed: %d\n", err
);
9898 /* if FDIR VSI was set up, start it now */
9899 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9900 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
9901 i40e_vsi_open(pf
->vsi
[i
]);
9906 /* driver is only interested in link up/down and module qualification
9907 * reports from firmware
9909 err
= i40e_aq_set_phy_int_mask(&pf
->hw
,
9910 I40E_AQ_EVENT_LINK_UPDOWN
|
9911 I40E_AQ_EVENT_MODULE_QUAL_FAIL
, NULL
);
9913 dev_info(&pf
->pdev
->dev
, "set phy mask fail, aq_err %d\n", err
);
9915 if (((pf
->hw
.aq
.fw_maj_ver
== 4) && (pf
->hw
.aq
.fw_min_ver
< 33)) ||
9916 (pf
->hw
.aq
.fw_maj_ver
< 4)) {
9918 err
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
9920 dev_info(&pf
->pdev
->dev
, "link restart failed, aq_err=%d\n",
9921 pf
->hw
.aq
.asq_last_status
);
9923 /* The main driver is (mostly) up and happy. We need to set this state
9924 * before setting up the misc vector or we get a race and the vector
9925 * ends up disabled forever.
9927 clear_bit(__I40E_DOWN
, &pf
->state
);
9929 /* In case of MSIX we are going to setup the misc vector right here
9930 * to handle admin queue events etc. In case of legacy and MSI
9931 * the misc functionality and queue processing is combined in
9932 * the same vector and that gets setup at open.
9934 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
9935 err
= i40e_setup_misc_vector(pf
);
9937 dev_info(&pdev
->dev
,
9938 "setup of misc vector failed: %d\n", err
);
9943 #ifdef CONFIG_PCI_IOV
9944 /* prep for VF support */
9945 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
9946 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
9947 !test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
9950 /* disable link interrupts for VFs */
9951 val
= rd32(hw
, I40E_PFGEN_PORTMDIO_NUM
);
9952 val
&= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK
;
9953 wr32(hw
, I40E_PFGEN_PORTMDIO_NUM
, val
);
9956 if (pci_num_vf(pdev
)) {
9957 dev_info(&pdev
->dev
,
9958 "Active VFs found, allocating resources.\n");
9959 err
= i40e_alloc_vfs(pf
, pci_num_vf(pdev
));
9961 dev_info(&pdev
->dev
,
9962 "Error %d allocating resources for existing VFs\n",
9966 #endif /* CONFIG_PCI_IOV */
9970 i40e_dbg_pf_init(pf
);
9972 /* tell the firmware that we're starting */
9973 i40e_send_version(pf
);
9975 /* since everything's happy, start the service_task timer */
9976 mod_timer(&pf
->service_timer
,
9977 round_jiffies(jiffies
+ pf
->service_timer_period
));
9980 /* create FCoE interface */
9981 i40e_fcoe_vsi_setup(pf
);
9984 /* Get the negotiated link width and speed from PCI config space */
9985 pcie_capability_read_word(pf
->pdev
, PCI_EXP_LNKSTA
, &link_status
);
9987 i40e_set_pci_config_data(hw
, link_status
);
9989 dev_info(&pdev
->dev
, "PCI-Express: %s %s\n",
9990 (hw
->bus
.speed
== i40e_bus_speed_8000
? "Speed 8.0GT/s" :
9991 hw
->bus
.speed
== i40e_bus_speed_5000
? "Speed 5.0GT/s" :
9992 hw
->bus
.speed
== i40e_bus_speed_2500
? "Speed 2.5GT/s" :
9994 (hw
->bus
.width
== i40e_bus_width_pcie_x8
? "Width x8" :
9995 hw
->bus
.width
== i40e_bus_width_pcie_x4
? "Width x4" :
9996 hw
->bus
.width
== i40e_bus_width_pcie_x2
? "Width x2" :
9997 hw
->bus
.width
== i40e_bus_width_pcie_x1
? "Width x1" :
10000 if (hw
->bus
.width
< i40e_bus_width_pcie_x8
||
10001 hw
->bus
.speed
< i40e_bus_speed_8000
) {
10002 dev_warn(&pdev
->dev
, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
10003 dev_warn(&pdev
->dev
, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
10006 /* get the requested speeds from the fw */
10007 err
= i40e_aq_get_phy_capabilities(hw
, false, false, &abilities
, NULL
);
10009 dev_info(&pf
->pdev
->dev
, "get phy abilities failed, aq_err %d, advertised speed settings may not be correct\n",
10011 pf
->hw
.phy
.link_info
.requested_speeds
= abilities
.link_speed
;
10013 /* print a string summarizing features */
10014 i40e_print_features(pf
);
10018 /* Unwind what we've done if something failed in the setup */
10020 set_bit(__I40E_DOWN
, &pf
->state
);
10021 i40e_clear_interrupt_scheme(pf
);
10024 i40e_reset_interrupt_capability(pf
);
10025 del_timer_sync(&pf
->service_timer
);
10027 err_configure_lan_hmc
:
10028 (void)i40e_shutdown_lan_hmc(hw
);
10030 kfree(pf
->qp_pile
);
10033 (void)i40e_shutdown_adminq(hw
);
10035 iounmap(hw
->hw_addr
);
10039 pci_disable_pcie_error_reporting(pdev
);
10040 pci_release_selected_regions(pdev
,
10041 pci_select_bars(pdev
, IORESOURCE_MEM
));
10044 pci_disable_device(pdev
);
10049 * i40e_remove - Device removal routine
10050 * @pdev: PCI device information struct
10052 * i40e_remove is called by the PCI subsystem to alert the driver
10053 * that is should release a PCI device. This could be caused by a
10054 * Hot-Plug event, or because the driver is going to be removed from
10057 static void i40e_remove(struct pci_dev
*pdev
)
10059 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10060 i40e_status ret_code
;
10063 i40e_dbg_pf_exit(pf
);
10067 /* no more scheduling of any task */
10068 set_bit(__I40E_DOWN
, &pf
->state
);
10069 del_timer_sync(&pf
->service_timer
);
10070 cancel_work_sync(&pf
->service_task
);
10071 i40e_fdir_teardown(pf
);
10073 if (pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) {
10075 pf
->flags
&= ~I40E_FLAG_SRIOV_ENABLED
;
10078 i40e_fdir_teardown(pf
);
10080 /* If there is a switch structure or any orphans, remove them.
10081 * This will leave only the PF's VSI remaining.
10083 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
10087 if (pf
->veb
[i
]->uplink_seid
== pf
->mac_seid
||
10088 pf
->veb
[i
]->uplink_seid
== 0)
10089 i40e_switch_branch_release(pf
->veb
[i
]);
10092 /* Now we can shutdown the PF's VSI, just before we kill
10095 if (pf
->vsi
[pf
->lan_vsi
])
10096 i40e_vsi_release(pf
->vsi
[pf
->lan_vsi
]);
10098 /* shutdown and destroy the HMC */
10099 if (pf
->hw
.hmc
.hmc_obj
) {
10100 ret_code
= i40e_shutdown_lan_hmc(&pf
->hw
);
10102 dev_warn(&pdev
->dev
,
10103 "Failed to destroy the HMC resources: %d\n",
10107 /* shutdown the adminq */
10108 ret_code
= i40e_shutdown_adminq(&pf
->hw
);
10110 dev_warn(&pdev
->dev
,
10111 "Failed to destroy the Admin Queue resources: %d\n",
10114 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
10115 i40e_clear_interrupt_scheme(pf
);
10116 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
10118 i40e_vsi_clear_rings(pf
->vsi
[i
]);
10119 i40e_vsi_clear(pf
->vsi
[i
]);
10124 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
10129 kfree(pf
->qp_pile
);
10132 iounmap(pf
->hw
.hw_addr
);
10134 pci_release_selected_regions(pdev
,
10135 pci_select_bars(pdev
, IORESOURCE_MEM
));
10137 pci_disable_pcie_error_reporting(pdev
);
10138 pci_disable_device(pdev
);
10142 * i40e_pci_error_detected - warning that something funky happened in PCI land
10143 * @pdev: PCI device information struct
10145 * Called to warn that something happened and the error handling steps
10146 * are in progress. Allows the driver to quiesce things, be ready for
10149 static pci_ers_result_t
i40e_pci_error_detected(struct pci_dev
*pdev
,
10150 enum pci_channel_state error
)
10152 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10154 dev_info(&pdev
->dev
, "%s: error %d\n", __func__
, error
);
10156 /* shutdown all operations */
10157 if (!test_bit(__I40E_SUSPENDED
, &pf
->state
)) {
10159 i40e_prep_for_reset(pf
);
10163 /* Request a slot reset */
10164 return PCI_ERS_RESULT_NEED_RESET
;
10168 * i40e_pci_error_slot_reset - a PCI slot reset just happened
10169 * @pdev: PCI device information struct
10171 * Called to find if the driver can work with the device now that
10172 * the pci slot has been reset. If a basic connection seems good
10173 * (registers are readable and have sane content) then return a
10174 * happy little PCI_ERS_RESULT_xxx.
10176 static pci_ers_result_t
i40e_pci_error_slot_reset(struct pci_dev
*pdev
)
10178 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10179 pci_ers_result_t result
;
10183 dev_info(&pdev
->dev
, "%s\n", __func__
);
10184 if (pci_enable_device_mem(pdev
)) {
10185 dev_info(&pdev
->dev
,
10186 "Cannot re-enable PCI device after reset.\n");
10187 result
= PCI_ERS_RESULT_DISCONNECT
;
10189 pci_set_master(pdev
);
10190 pci_restore_state(pdev
);
10191 pci_save_state(pdev
);
10192 pci_wake_from_d3(pdev
, false);
10194 reg
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
10196 result
= PCI_ERS_RESULT_RECOVERED
;
10198 result
= PCI_ERS_RESULT_DISCONNECT
;
10201 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
10203 dev_info(&pdev
->dev
,
10204 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
10206 /* non-fatal, continue */
10213 * i40e_pci_error_resume - restart operations after PCI error recovery
10214 * @pdev: PCI device information struct
10216 * Called to allow the driver to bring things back up after PCI error
10217 * and/or reset recovery has finished.
10219 static void i40e_pci_error_resume(struct pci_dev
*pdev
)
10221 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10223 dev_info(&pdev
->dev
, "%s\n", __func__
);
10224 if (test_bit(__I40E_SUSPENDED
, &pf
->state
))
10228 i40e_handle_reset_warning(pf
);
10233 * i40e_shutdown - PCI callback for shutting down
10234 * @pdev: PCI device information struct
10236 static void i40e_shutdown(struct pci_dev
*pdev
)
10238 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10239 struct i40e_hw
*hw
= &pf
->hw
;
10241 set_bit(__I40E_SUSPENDED
, &pf
->state
);
10242 set_bit(__I40E_DOWN
, &pf
->state
);
10244 i40e_prep_for_reset(pf
);
10247 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
10248 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
10250 i40e_clear_interrupt_scheme(pf
);
10252 if (system_state
== SYSTEM_POWER_OFF
) {
10253 pci_wake_from_d3(pdev
, pf
->wol_en
);
10254 pci_set_power_state(pdev
, PCI_D3hot
);
10260 * i40e_suspend - PCI callback for moving to D3
10261 * @pdev: PCI device information struct
10263 static int i40e_suspend(struct pci_dev
*pdev
, pm_message_t state
)
10265 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10266 struct i40e_hw
*hw
= &pf
->hw
;
10268 set_bit(__I40E_SUSPENDED
, &pf
->state
);
10269 set_bit(__I40E_DOWN
, &pf
->state
);
10270 del_timer_sync(&pf
->service_timer
);
10271 cancel_work_sync(&pf
->service_task
);
10272 i40e_fdir_teardown(pf
);
10275 i40e_prep_for_reset(pf
);
10278 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
10279 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
10281 pci_wake_from_d3(pdev
, pf
->wol_en
);
10282 pci_set_power_state(pdev
, PCI_D3hot
);
10288 * i40e_resume - PCI callback for waking up from D3
10289 * @pdev: PCI device information struct
10291 static int i40e_resume(struct pci_dev
*pdev
)
10293 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
10296 pci_set_power_state(pdev
, PCI_D0
);
10297 pci_restore_state(pdev
);
10298 /* pci_restore_state() clears dev->state_saves, so
10299 * call pci_save_state() again to restore it.
10301 pci_save_state(pdev
);
10303 err
= pci_enable_device_mem(pdev
);
10305 dev_err(&pdev
->dev
,
10306 "%s: Cannot enable PCI device from suspend\n",
10310 pci_set_master(pdev
);
10312 /* no wakeup events while running */
10313 pci_wake_from_d3(pdev
, false);
10315 /* handling the reset will rebuild the device state */
10316 if (test_and_clear_bit(__I40E_SUSPENDED
, &pf
->state
)) {
10317 clear_bit(__I40E_DOWN
, &pf
->state
);
10319 i40e_reset_and_rebuild(pf
, false);
10327 static const struct pci_error_handlers i40e_err_handler
= {
10328 .error_detected
= i40e_pci_error_detected
,
10329 .slot_reset
= i40e_pci_error_slot_reset
,
10330 .resume
= i40e_pci_error_resume
,
10333 static struct pci_driver i40e_driver
= {
10334 .name
= i40e_driver_name
,
10335 .id_table
= i40e_pci_tbl
,
10336 .probe
= i40e_probe
,
10337 .remove
= i40e_remove
,
10339 .suspend
= i40e_suspend
,
10340 .resume
= i40e_resume
,
10342 .shutdown
= i40e_shutdown
,
10343 .err_handler
= &i40e_err_handler
,
10344 .sriov_configure
= i40e_pci_sriov_configure
,
10348 * i40e_init_module - Driver registration routine
10350 * i40e_init_module is the first routine called when the driver is
10351 * loaded. All it does is register with the PCI subsystem.
10353 static int __init
i40e_init_module(void)
10355 pr_info("%s: %s - version %s\n", i40e_driver_name
,
10356 i40e_driver_string
, i40e_driver_version_str
);
10357 pr_info("%s: %s\n", i40e_driver_name
, i40e_copyright
);
10360 return pci_register_driver(&i40e_driver
);
10362 module_init(i40e_init_module
);
10365 * i40e_exit_module - Driver exit cleanup routine
10367 * i40e_exit_module is called just before the driver is removed
10370 static void __exit
i40e_exit_module(void)
10372 pci_unregister_driver(&i40e_driver
);
10375 module_exit(i40e_exit_module
);