1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2014 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 ******************************************************************************/
29 #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 0
42 #define DRV_VERSION_BUILD 11
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 /* required last entry */
81 MODULE_DEVICE_TABLE(pci
, i40e_pci_tbl
);
83 #define I40E_MAX_VF_COUNT 128
84 static int debug
= -1;
85 module_param(debug
, int, 0);
86 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
88 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
89 MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
90 MODULE_LICENSE("GPL");
91 MODULE_VERSION(DRV_VERSION
);
94 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
95 * @hw: pointer to the HW structure
96 * @mem: ptr to mem struct to fill out
97 * @size: size of memory requested
98 * @alignment: what to align the allocation to
100 int i40e_allocate_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
,
101 u64 size
, u32 alignment
)
103 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
105 mem
->size
= ALIGN(size
, alignment
);
106 mem
->va
= dma_zalloc_coherent(&pf
->pdev
->dev
, mem
->size
,
107 &mem
->pa
, GFP_KERNEL
);
115 * i40e_free_dma_mem_d - OS specific memory free for shared code
116 * @hw: pointer to the HW structure
117 * @mem: ptr to mem struct to free
119 int i40e_free_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
)
121 struct i40e_pf
*pf
= (struct i40e_pf
*)hw
->back
;
123 dma_free_coherent(&pf
->pdev
->dev
, mem
->size
, mem
->va
, mem
->pa
);
132 * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
133 * @hw: pointer to the HW structure
134 * @mem: ptr to mem struct to fill out
135 * @size: size of memory requested
137 int i40e_allocate_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
,
141 mem
->va
= kzalloc(size
, GFP_KERNEL
);
150 * i40e_free_virt_mem_d - OS specific memory free for shared code
151 * @hw: pointer to the HW structure
152 * @mem: ptr to mem struct to free
154 int i40e_free_virt_mem_d(struct i40e_hw
*hw
, struct i40e_virt_mem
*mem
)
156 /* it's ok to kfree a NULL pointer */
165 * i40e_get_lump - find a lump of free generic resource
166 * @pf: board private structure
167 * @pile: the pile of resource to search
168 * @needed: the number of items needed
169 * @id: an owner id to stick on the items assigned
171 * Returns the base item index of the lump, or negative for error
173 * The search_hint trick and lack of advanced fit-finding only work
174 * because we're highly likely to have all the same size lump requests.
175 * Linear search time and any fragmentation should be minimal.
177 static int i40e_get_lump(struct i40e_pf
*pf
, struct i40e_lump_tracking
*pile
,
183 if (!pile
|| needed
== 0 || id
>= I40E_PILE_VALID_BIT
) {
184 dev_info(&pf
->pdev
->dev
,
185 "param err: pile=%p needed=%d id=0x%04x\n",
190 /* start the linear search with an imperfect hint */
191 i
= pile
->search_hint
;
192 while (i
< pile
->num_entries
) {
193 /* skip already allocated entries */
194 if (pile
->list
[i
] & I40E_PILE_VALID_BIT
) {
199 /* do we have enough in this lump? */
200 for (j
= 0; (j
< needed
) && ((i
+j
) < pile
->num_entries
); j
++) {
201 if (pile
->list
[i
+j
] & I40E_PILE_VALID_BIT
)
206 /* there was enough, so assign it to the requestor */
207 for (j
= 0; j
< needed
; j
++)
208 pile
->list
[i
+j
] = id
| I40E_PILE_VALID_BIT
;
210 pile
->search_hint
= i
+ j
;
213 /* not enough, so skip over it and continue looking */
222 * i40e_put_lump - return a lump of generic resource
223 * @pile: the pile of resource to search
224 * @index: the base item index
225 * @id: the owner id of the items assigned
227 * Returns the count of items in the lump
229 static int i40e_put_lump(struct i40e_lump_tracking
*pile
, u16 index
, u16 id
)
231 int valid_id
= (id
| I40E_PILE_VALID_BIT
);
235 if (!pile
|| index
>= pile
->num_entries
)
239 i
< pile
->num_entries
&& pile
->list
[i
] == valid_id
;
245 if (count
&& index
< pile
->search_hint
)
246 pile
->search_hint
= index
;
252 * i40e_service_event_schedule - Schedule the service task to wake up
253 * @pf: board private structure
255 * If not already scheduled, this puts the task into the work queue
257 static void i40e_service_event_schedule(struct i40e_pf
*pf
)
259 if (!test_bit(__I40E_DOWN
, &pf
->state
) &&
260 !test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) &&
261 !test_and_set_bit(__I40E_SERVICE_SCHED
, &pf
->state
))
262 schedule_work(&pf
->service_task
);
266 * i40e_tx_timeout - Respond to a Tx Hang
267 * @netdev: network interface device structure
269 * If any port has noticed a Tx timeout, it is likely that the whole
270 * device is munged, not just the one netdev port, so go for the full
274 void i40e_tx_timeout(struct net_device
*netdev
)
276 static void i40e_tx_timeout(struct net_device
*netdev
)
279 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
280 struct i40e_vsi
*vsi
= np
->vsi
;
281 struct i40e_pf
*pf
= vsi
->back
;
283 pf
->tx_timeout_count
++;
285 if (time_after(jiffies
, (pf
->tx_timeout_last_recovery
+ HZ
*20)))
286 pf
->tx_timeout_recovery_level
= 1;
287 pf
->tx_timeout_last_recovery
= jiffies
;
288 netdev_info(netdev
, "tx_timeout recovery level %d\n",
289 pf
->tx_timeout_recovery_level
);
291 switch (pf
->tx_timeout_recovery_level
) {
293 /* disable and re-enable queues for the VSI */
294 if (in_interrupt()) {
295 set_bit(__I40E_REINIT_REQUESTED
, &pf
->state
);
296 set_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
);
298 i40e_vsi_reinit_locked(vsi
);
302 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
305 set_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
);
308 set_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
);
311 netdev_err(netdev
, "tx_timeout recovery unsuccessful\n");
312 set_bit(__I40E_DOWN_REQUESTED
, &pf
->state
);
313 set_bit(__I40E_DOWN_REQUESTED
, &vsi
->state
);
316 i40e_service_event_schedule(pf
);
317 pf
->tx_timeout_recovery_level
++;
321 * i40e_release_rx_desc - Store the new tail and head values
322 * @rx_ring: ring to bump
323 * @val: new head index
325 static inline void i40e_release_rx_desc(struct i40e_ring
*rx_ring
, u32 val
)
327 rx_ring
->next_to_use
= val
;
329 /* Force memory writes to complete before letting h/w
330 * know there are new descriptors to fetch. (Only
331 * applicable for weak-ordered memory model archs,
335 writel(val
, rx_ring
->tail
);
339 * i40e_get_vsi_stats_struct - Get System Network Statistics
340 * @vsi: the VSI we care about
342 * Returns the address of the device statistics structure.
343 * The statistics are actually updated from the service task.
345 struct rtnl_link_stats64
*i40e_get_vsi_stats_struct(struct i40e_vsi
*vsi
)
347 return &vsi
->net_stats
;
351 * i40e_get_netdev_stats_struct - Get statistics for netdev interface
352 * @netdev: network interface device structure
354 * Returns the address of the device statistics structure.
355 * The statistics are actually updated from the service task.
358 struct rtnl_link_stats64
*i40e_get_netdev_stats_struct(
359 struct net_device
*netdev
,
360 struct rtnl_link_stats64
*stats
)
362 static struct rtnl_link_stats64
*i40e_get_netdev_stats_struct(
363 struct net_device
*netdev
,
364 struct rtnl_link_stats64
*stats
)
367 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
368 struct i40e_ring
*tx_ring
, *rx_ring
;
369 struct i40e_vsi
*vsi
= np
->vsi
;
370 struct rtnl_link_stats64
*vsi_stats
= i40e_get_vsi_stats_struct(vsi
);
373 if (test_bit(__I40E_DOWN
, &vsi
->state
))
380 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
384 tx_ring
= ACCESS_ONCE(vsi
->tx_rings
[i
]);
389 start
= u64_stats_fetch_begin_irq(&tx_ring
->syncp
);
390 packets
= tx_ring
->stats
.packets
;
391 bytes
= tx_ring
->stats
.bytes
;
392 } while (u64_stats_fetch_retry_irq(&tx_ring
->syncp
, start
));
394 stats
->tx_packets
+= packets
;
395 stats
->tx_bytes
+= bytes
;
396 rx_ring
= &tx_ring
[1];
399 start
= u64_stats_fetch_begin_irq(&rx_ring
->syncp
);
400 packets
= rx_ring
->stats
.packets
;
401 bytes
= rx_ring
->stats
.bytes
;
402 } while (u64_stats_fetch_retry_irq(&rx_ring
->syncp
, start
));
404 stats
->rx_packets
+= packets
;
405 stats
->rx_bytes
+= bytes
;
409 /* following stats updated by i40e_watchdog_subtask() */
410 stats
->multicast
= vsi_stats
->multicast
;
411 stats
->tx_errors
= vsi_stats
->tx_errors
;
412 stats
->tx_dropped
= vsi_stats
->tx_dropped
;
413 stats
->rx_errors
= vsi_stats
->rx_errors
;
414 stats
->rx_crc_errors
= vsi_stats
->rx_crc_errors
;
415 stats
->rx_length_errors
= vsi_stats
->rx_length_errors
;
421 * i40e_vsi_reset_stats - Resets all stats of the given vsi
422 * @vsi: the VSI to have its stats reset
424 void i40e_vsi_reset_stats(struct i40e_vsi
*vsi
)
426 struct rtnl_link_stats64
*ns
;
432 ns
= i40e_get_vsi_stats_struct(vsi
);
433 memset(ns
, 0, sizeof(*ns
));
434 memset(&vsi
->net_stats_offsets
, 0, sizeof(vsi
->net_stats_offsets
));
435 memset(&vsi
->eth_stats
, 0, sizeof(vsi
->eth_stats
));
436 memset(&vsi
->eth_stats_offsets
, 0, sizeof(vsi
->eth_stats_offsets
));
437 if (vsi
->rx_rings
&& vsi
->rx_rings
[0]) {
438 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
439 memset(&vsi
->rx_rings
[i
]->stats
, 0 ,
440 sizeof(vsi
->rx_rings
[i
]->stats
));
441 memset(&vsi
->rx_rings
[i
]->rx_stats
, 0 ,
442 sizeof(vsi
->rx_rings
[i
]->rx_stats
));
443 memset(&vsi
->tx_rings
[i
]->stats
, 0 ,
444 sizeof(vsi
->tx_rings
[i
]->stats
));
445 memset(&vsi
->tx_rings
[i
]->tx_stats
, 0,
446 sizeof(vsi
->tx_rings
[i
]->tx_stats
));
449 vsi
->stat_offsets_loaded
= false;
453 * i40e_pf_reset_stats - Reset all of the stats for the given pf
454 * @pf: the PF to be reset
456 void i40e_pf_reset_stats(struct i40e_pf
*pf
)
460 memset(&pf
->stats
, 0, sizeof(pf
->stats
));
461 memset(&pf
->stats_offsets
, 0, sizeof(pf
->stats_offsets
));
462 pf
->stat_offsets_loaded
= false;
464 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
466 memset(&pf
->veb
[i
]->stats
, 0,
467 sizeof(pf
->veb
[i
]->stats
));
468 memset(&pf
->veb
[i
]->stats_offsets
, 0,
469 sizeof(pf
->veb
[i
]->stats_offsets
));
470 pf
->veb
[i
]->stat_offsets_loaded
= false;
476 * i40e_stat_update48 - read and update a 48 bit stat from the chip
477 * @hw: ptr to the hardware info
478 * @hireg: the high 32 bit reg to read
479 * @loreg: the low 32 bit reg to read
480 * @offset_loaded: has the initial offset been loaded yet
481 * @offset: ptr to current offset value
482 * @stat: ptr to the stat
484 * Since the device stats are not reset at PFReset, they likely will not
485 * be zeroed when the driver starts. We'll save the first values read
486 * and use them as offsets to be subtracted from the raw values in order
487 * to report stats that count from zero. In the process, we also manage
488 * the potential roll-over.
490 static void i40e_stat_update48(struct i40e_hw
*hw
, u32 hireg
, u32 loreg
,
491 bool offset_loaded
, u64
*offset
, u64
*stat
)
495 if (hw
->device_id
== I40E_DEV_ID_QEMU
) {
496 new_data
= rd32(hw
, loreg
);
497 new_data
|= ((u64
)(rd32(hw
, hireg
) & 0xFFFF)) << 32;
499 new_data
= rd64(hw
, loreg
);
503 if (likely(new_data
>= *offset
))
504 *stat
= new_data
- *offset
;
506 *stat
= (new_data
+ ((u64
)1 << 48)) - *offset
;
507 *stat
&= 0xFFFFFFFFFFFFULL
;
511 * i40e_stat_update32 - read and update a 32 bit stat from the chip
512 * @hw: ptr to the hardware info
513 * @reg: the hw reg to read
514 * @offset_loaded: has the initial offset been loaded yet
515 * @offset: ptr to current offset value
516 * @stat: ptr to the stat
518 static void i40e_stat_update32(struct i40e_hw
*hw
, u32 reg
,
519 bool offset_loaded
, u64
*offset
, u64
*stat
)
523 new_data
= rd32(hw
, reg
);
526 if (likely(new_data
>= *offset
))
527 *stat
= (u32
)(new_data
- *offset
);
529 *stat
= (u32
)((new_data
+ ((u64
)1 << 32)) - *offset
);
533 * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
534 * @vsi: the VSI to be updated
536 void i40e_update_eth_stats(struct i40e_vsi
*vsi
)
538 int stat_idx
= le16_to_cpu(vsi
->info
.stat_counter_idx
);
539 struct i40e_pf
*pf
= vsi
->back
;
540 struct i40e_hw
*hw
= &pf
->hw
;
541 struct i40e_eth_stats
*oes
;
542 struct i40e_eth_stats
*es
; /* device's eth stats */
544 es
= &vsi
->eth_stats
;
545 oes
= &vsi
->eth_stats_offsets
;
547 /* Gather up the stats that the hw collects */
548 i40e_stat_update32(hw
, I40E_GLV_TEPC(stat_idx
),
549 vsi
->stat_offsets_loaded
,
550 &oes
->tx_errors
, &es
->tx_errors
);
551 i40e_stat_update32(hw
, I40E_GLV_RDPC(stat_idx
),
552 vsi
->stat_offsets_loaded
,
553 &oes
->rx_discards
, &es
->rx_discards
);
554 i40e_stat_update32(hw
, I40E_GLV_RUPP(stat_idx
),
555 vsi
->stat_offsets_loaded
,
556 &oes
->rx_unknown_protocol
, &es
->rx_unknown_protocol
);
557 i40e_stat_update32(hw
, I40E_GLV_TEPC(stat_idx
),
558 vsi
->stat_offsets_loaded
,
559 &oes
->tx_errors
, &es
->tx_errors
);
561 i40e_stat_update48(hw
, I40E_GLV_GORCH(stat_idx
),
562 I40E_GLV_GORCL(stat_idx
),
563 vsi
->stat_offsets_loaded
,
564 &oes
->rx_bytes
, &es
->rx_bytes
);
565 i40e_stat_update48(hw
, I40E_GLV_UPRCH(stat_idx
),
566 I40E_GLV_UPRCL(stat_idx
),
567 vsi
->stat_offsets_loaded
,
568 &oes
->rx_unicast
, &es
->rx_unicast
);
569 i40e_stat_update48(hw
, I40E_GLV_MPRCH(stat_idx
),
570 I40E_GLV_MPRCL(stat_idx
),
571 vsi
->stat_offsets_loaded
,
572 &oes
->rx_multicast
, &es
->rx_multicast
);
573 i40e_stat_update48(hw
, I40E_GLV_BPRCH(stat_idx
),
574 I40E_GLV_BPRCL(stat_idx
),
575 vsi
->stat_offsets_loaded
,
576 &oes
->rx_broadcast
, &es
->rx_broadcast
);
578 i40e_stat_update48(hw
, I40E_GLV_GOTCH(stat_idx
),
579 I40E_GLV_GOTCL(stat_idx
),
580 vsi
->stat_offsets_loaded
,
581 &oes
->tx_bytes
, &es
->tx_bytes
);
582 i40e_stat_update48(hw
, I40E_GLV_UPTCH(stat_idx
),
583 I40E_GLV_UPTCL(stat_idx
),
584 vsi
->stat_offsets_loaded
,
585 &oes
->tx_unicast
, &es
->tx_unicast
);
586 i40e_stat_update48(hw
, I40E_GLV_MPTCH(stat_idx
),
587 I40E_GLV_MPTCL(stat_idx
),
588 vsi
->stat_offsets_loaded
,
589 &oes
->tx_multicast
, &es
->tx_multicast
);
590 i40e_stat_update48(hw
, I40E_GLV_BPTCH(stat_idx
),
591 I40E_GLV_BPTCL(stat_idx
),
592 vsi
->stat_offsets_loaded
,
593 &oes
->tx_broadcast
, &es
->tx_broadcast
);
594 vsi
->stat_offsets_loaded
= true;
598 * i40e_update_veb_stats - Update Switch component statistics
599 * @veb: the VEB being updated
601 static void i40e_update_veb_stats(struct i40e_veb
*veb
)
603 struct i40e_pf
*pf
= veb
->pf
;
604 struct i40e_hw
*hw
= &pf
->hw
;
605 struct i40e_eth_stats
*oes
;
606 struct i40e_eth_stats
*es
; /* device's eth stats */
609 idx
= veb
->stats_idx
;
611 oes
= &veb
->stats_offsets
;
613 /* Gather up the stats that the hw collects */
614 i40e_stat_update32(hw
, I40E_GLSW_TDPC(idx
),
615 veb
->stat_offsets_loaded
,
616 &oes
->tx_discards
, &es
->tx_discards
);
617 if (hw
->revision_id
> 0)
618 i40e_stat_update32(hw
, I40E_GLSW_RUPP(idx
),
619 veb
->stat_offsets_loaded
,
620 &oes
->rx_unknown_protocol
,
621 &es
->rx_unknown_protocol
);
622 i40e_stat_update48(hw
, I40E_GLSW_GORCH(idx
), I40E_GLSW_GORCL(idx
),
623 veb
->stat_offsets_loaded
,
624 &oes
->rx_bytes
, &es
->rx_bytes
);
625 i40e_stat_update48(hw
, I40E_GLSW_UPRCH(idx
), I40E_GLSW_UPRCL(idx
),
626 veb
->stat_offsets_loaded
,
627 &oes
->rx_unicast
, &es
->rx_unicast
);
628 i40e_stat_update48(hw
, I40E_GLSW_MPRCH(idx
), I40E_GLSW_MPRCL(idx
),
629 veb
->stat_offsets_loaded
,
630 &oes
->rx_multicast
, &es
->rx_multicast
);
631 i40e_stat_update48(hw
, I40E_GLSW_BPRCH(idx
), I40E_GLSW_BPRCL(idx
),
632 veb
->stat_offsets_loaded
,
633 &oes
->rx_broadcast
, &es
->rx_broadcast
);
635 i40e_stat_update48(hw
, I40E_GLSW_GOTCH(idx
), I40E_GLSW_GOTCL(idx
),
636 veb
->stat_offsets_loaded
,
637 &oes
->tx_bytes
, &es
->tx_bytes
);
638 i40e_stat_update48(hw
, I40E_GLSW_UPTCH(idx
), I40E_GLSW_UPTCL(idx
),
639 veb
->stat_offsets_loaded
,
640 &oes
->tx_unicast
, &es
->tx_unicast
);
641 i40e_stat_update48(hw
, I40E_GLSW_MPTCH(idx
), I40E_GLSW_MPTCL(idx
),
642 veb
->stat_offsets_loaded
,
643 &oes
->tx_multicast
, &es
->tx_multicast
);
644 i40e_stat_update48(hw
, I40E_GLSW_BPTCH(idx
), I40E_GLSW_BPTCL(idx
),
645 veb
->stat_offsets_loaded
,
646 &oes
->tx_broadcast
, &es
->tx_broadcast
);
647 veb
->stat_offsets_loaded
= true;
652 * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters.
653 * @vsi: the VSI that is capable of doing FCoE
655 static void i40e_update_fcoe_stats(struct i40e_vsi
*vsi
)
657 struct i40e_pf
*pf
= vsi
->back
;
658 struct i40e_hw
*hw
= &pf
->hw
;
659 struct i40e_fcoe_stats
*ofs
;
660 struct i40e_fcoe_stats
*fs
; /* device's eth stats */
663 if (vsi
->type
!= I40E_VSI_FCOE
)
666 idx
= (pf
->pf_seid
- I40E_BASE_PF_SEID
) + I40E_FCOE_PF_STAT_OFFSET
;
667 fs
= &vsi
->fcoe_stats
;
668 ofs
= &vsi
->fcoe_stats_offsets
;
670 i40e_stat_update32(hw
, I40E_GL_FCOEPRC(idx
),
671 vsi
->fcoe_stat_offsets_loaded
,
672 &ofs
->rx_fcoe_packets
, &fs
->rx_fcoe_packets
);
673 i40e_stat_update48(hw
, I40E_GL_FCOEDWRCH(idx
), I40E_GL_FCOEDWRCL(idx
),
674 vsi
->fcoe_stat_offsets_loaded
,
675 &ofs
->rx_fcoe_dwords
, &fs
->rx_fcoe_dwords
);
676 i40e_stat_update32(hw
, I40E_GL_FCOERPDC(idx
),
677 vsi
->fcoe_stat_offsets_loaded
,
678 &ofs
->rx_fcoe_dropped
, &fs
->rx_fcoe_dropped
);
679 i40e_stat_update32(hw
, I40E_GL_FCOEPTC(idx
),
680 vsi
->fcoe_stat_offsets_loaded
,
681 &ofs
->tx_fcoe_packets
, &fs
->tx_fcoe_packets
);
682 i40e_stat_update48(hw
, I40E_GL_FCOEDWTCH(idx
), I40E_GL_FCOEDWTCL(idx
),
683 vsi
->fcoe_stat_offsets_loaded
,
684 &ofs
->tx_fcoe_dwords
, &fs
->tx_fcoe_dwords
);
685 i40e_stat_update32(hw
, I40E_GL_FCOECRC(idx
),
686 vsi
->fcoe_stat_offsets_loaded
,
687 &ofs
->fcoe_bad_fccrc
, &fs
->fcoe_bad_fccrc
);
688 i40e_stat_update32(hw
, I40E_GL_FCOELAST(idx
),
689 vsi
->fcoe_stat_offsets_loaded
,
690 &ofs
->fcoe_last_error
, &fs
->fcoe_last_error
);
691 i40e_stat_update32(hw
, I40E_GL_FCOEDDPC(idx
),
692 vsi
->fcoe_stat_offsets_loaded
,
693 &ofs
->fcoe_ddp_count
, &fs
->fcoe_ddp_count
);
695 vsi
->fcoe_stat_offsets_loaded
= true;
700 * i40e_update_link_xoff_rx - Update XOFF received in link flow control mode
701 * @pf: the corresponding PF
703 * Update the Rx XOFF counter (PAUSE frames) in link flow control mode
705 static void i40e_update_link_xoff_rx(struct i40e_pf
*pf
)
707 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
708 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
709 struct i40e_hw
*hw
= &pf
->hw
;
713 if ((hw
->fc
.current_mode
!= I40E_FC_FULL
) &&
714 (hw
->fc
.current_mode
!= I40E_FC_RX_PAUSE
))
717 xoff
= nsd
->link_xoff_rx
;
718 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFRXC(hw
->port
),
719 pf
->stat_offsets_loaded
,
720 &osd
->link_xoff_rx
, &nsd
->link_xoff_rx
);
722 /* No new LFC xoff rx */
723 if (!(nsd
->link_xoff_rx
- xoff
))
726 /* Clear the __I40E_HANG_CHECK_ARMED bit for all Tx rings */
727 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
728 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
730 if (!vsi
|| !vsi
->tx_rings
[0])
733 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
734 struct i40e_ring
*ring
= vsi
->tx_rings
[i
];
735 clear_bit(__I40E_HANG_CHECK_ARMED
, &ring
->state
);
741 * i40e_update_prio_xoff_rx - Update XOFF received in PFC mode
742 * @pf: the corresponding PF
744 * Update the Rx XOFF counter (PAUSE frames) in PFC mode
746 static void i40e_update_prio_xoff_rx(struct i40e_pf
*pf
)
748 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
749 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
750 bool xoff
[I40E_MAX_TRAFFIC_CLASS
] = {false};
751 struct i40e_dcbx_config
*dcb_cfg
;
752 struct i40e_hw
*hw
= &pf
->hw
;
756 dcb_cfg
= &hw
->local_dcbx_config
;
758 /* See if DCB enabled with PFC TC */
759 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
) ||
760 !(dcb_cfg
->pfc
.pfcenable
)) {
761 i40e_update_link_xoff_rx(pf
);
765 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
766 u64 prio_xoff
= nsd
->priority_xoff_rx
[i
];
767 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFRXC(hw
->port
, i
),
768 pf
->stat_offsets_loaded
,
769 &osd
->priority_xoff_rx
[i
],
770 &nsd
->priority_xoff_rx
[i
]);
772 /* No new PFC xoff rx */
773 if (!(nsd
->priority_xoff_rx
[i
] - prio_xoff
))
775 /* Get the TC for given priority */
776 tc
= dcb_cfg
->etscfg
.prioritytable
[i
];
780 /* Clear the __I40E_HANG_CHECK_ARMED bit for Tx rings */
781 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
782 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
784 if (!vsi
|| !vsi
->tx_rings
[0])
787 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
788 struct i40e_ring
*ring
= vsi
->tx_rings
[i
];
792 clear_bit(__I40E_HANG_CHECK_ARMED
,
799 * i40e_update_vsi_stats - Update the vsi statistics counters.
800 * @vsi: the VSI to be updated
802 * There are a few instances where we store the same stat in a
803 * couple of different structs. This is partly because we have
804 * the netdev stats that need to be filled out, which is slightly
805 * different from the "eth_stats" defined by the chip and used in
806 * VF communications. We sort it out here.
808 static void i40e_update_vsi_stats(struct i40e_vsi
*vsi
)
810 struct i40e_pf
*pf
= vsi
->back
;
811 struct rtnl_link_stats64
*ons
;
812 struct rtnl_link_stats64
*ns
; /* netdev stats */
813 struct i40e_eth_stats
*oes
;
814 struct i40e_eth_stats
*es
; /* device's eth stats */
815 u32 tx_restart
, tx_busy
;
821 if (test_bit(__I40E_DOWN
, &vsi
->state
) ||
822 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
825 ns
= i40e_get_vsi_stats_struct(vsi
);
826 ons
= &vsi
->net_stats_offsets
;
827 es
= &vsi
->eth_stats
;
828 oes
= &vsi
->eth_stats_offsets
;
830 /* Gather up the netdev and vsi stats that the driver collects
831 * on the fly during packet processing
835 tx_restart
= tx_busy
= 0;
839 for (q
= 0; q
< vsi
->num_queue_pairs
; q
++) {
845 p
= ACCESS_ONCE(vsi
->tx_rings
[q
]);
848 start
= u64_stats_fetch_begin_irq(&p
->syncp
);
849 packets
= p
->stats
.packets
;
850 bytes
= p
->stats
.bytes
;
851 } while (u64_stats_fetch_retry_irq(&p
->syncp
, start
));
854 tx_restart
+= p
->tx_stats
.restart_queue
;
855 tx_busy
+= p
->tx_stats
.tx_busy
;
857 /* Rx queue is part of the same block as Tx queue */
860 start
= u64_stats_fetch_begin_irq(&p
->syncp
);
861 packets
= p
->stats
.packets
;
862 bytes
= p
->stats
.bytes
;
863 } while (u64_stats_fetch_retry_irq(&p
->syncp
, start
));
866 rx_buf
+= p
->rx_stats
.alloc_buff_failed
;
867 rx_page
+= p
->rx_stats
.alloc_page_failed
;
870 vsi
->tx_restart
= tx_restart
;
871 vsi
->tx_busy
= tx_busy
;
872 vsi
->rx_page_failed
= rx_page
;
873 vsi
->rx_buf_failed
= rx_buf
;
875 ns
->rx_packets
= rx_p
;
877 ns
->tx_packets
= tx_p
;
880 /* update netdev stats from eth stats */
881 i40e_update_eth_stats(vsi
);
882 ons
->tx_errors
= oes
->tx_errors
;
883 ns
->tx_errors
= es
->tx_errors
;
884 ons
->multicast
= oes
->rx_multicast
;
885 ns
->multicast
= es
->rx_multicast
;
886 ons
->rx_dropped
= oes
->rx_discards
;
887 ns
->rx_dropped
= es
->rx_discards
;
888 ons
->tx_dropped
= oes
->tx_discards
;
889 ns
->tx_dropped
= es
->tx_discards
;
891 /* pull in a couple PF stats if this is the main vsi */
892 if (vsi
== pf
->vsi
[pf
->lan_vsi
]) {
893 ns
->rx_crc_errors
= pf
->stats
.crc_errors
;
894 ns
->rx_errors
= pf
->stats
.crc_errors
+ pf
->stats
.illegal_bytes
;
895 ns
->rx_length_errors
= pf
->stats
.rx_length_errors
;
900 * i40e_update_pf_stats - Update the pf statistics counters.
901 * @pf: the PF to be updated
903 static void i40e_update_pf_stats(struct i40e_pf
*pf
)
905 struct i40e_hw_port_stats
*osd
= &pf
->stats_offsets
;
906 struct i40e_hw_port_stats
*nsd
= &pf
->stats
;
907 struct i40e_hw
*hw
= &pf
->hw
;
911 i40e_stat_update48(hw
, I40E_GLPRT_GORCH(hw
->port
),
912 I40E_GLPRT_GORCL(hw
->port
),
913 pf
->stat_offsets_loaded
,
914 &osd
->eth
.rx_bytes
, &nsd
->eth
.rx_bytes
);
915 i40e_stat_update48(hw
, I40E_GLPRT_GOTCH(hw
->port
),
916 I40E_GLPRT_GOTCL(hw
->port
),
917 pf
->stat_offsets_loaded
,
918 &osd
->eth
.tx_bytes
, &nsd
->eth
.tx_bytes
);
919 i40e_stat_update32(hw
, I40E_GLPRT_RDPC(hw
->port
),
920 pf
->stat_offsets_loaded
,
921 &osd
->eth
.rx_discards
,
922 &nsd
->eth
.rx_discards
);
923 i40e_stat_update32(hw
, I40E_GLPRT_TDPC(hw
->port
),
924 pf
->stat_offsets_loaded
,
925 &osd
->eth
.tx_discards
,
926 &nsd
->eth
.tx_discards
);
928 i40e_stat_update48(hw
, I40E_GLPRT_UPRCH(hw
->port
),
929 I40E_GLPRT_UPRCL(hw
->port
),
930 pf
->stat_offsets_loaded
,
931 &osd
->eth
.rx_unicast
,
932 &nsd
->eth
.rx_unicast
);
933 i40e_stat_update48(hw
, I40E_GLPRT_MPRCH(hw
->port
),
934 I40E_GLPRT_MPRCL(hw
->port
),
935 pf
->stat_offsets_loaded
,
936 &osd
->eth
.rx_multicast
,
937 &nsd
->eth
.rx_multicast
);
938 i40e_stat_update48(hw
, I40E_GLPRT_BPRCH(hw
->port
),
939 I40E_GLPRT_BPRCL(hw
->port
),
940 pf
->stat_offsets_loaded
,
941 &osd
->eth
.rx_broadcast
,
942 &nsd
->eth
.rx_broadcast
);
943 i40e_stat_update48(hw
, I40E_GLPRT_UPTCH(hw
->port
),
944 I40E_GLPRT_UPTCL(hw
->port
),
945 pf
->stat_offsets_loaded
,
946 &osd
->eth
.tx_unicast
,
947 &nsd
->eth
.tx_unicast
);
948 i40e_stat_update48(hw
, I40E_GLPRT_MPTCH(hw
->port
),
949 I40E_GLPRT_MPTCL(hw
->port
),
950 pf
->stat_offsets_loaded
,
951 &osd
->eth
.tx_multicast
,
952 &nsd
->eth
.tx_multicast
);
953 i40e_stat_update48(hw
, I40E_GLPRT_BPTCH(hw
->port
),
954 I40E_GLPRT_BPTCL(hw
->port
),
955 pf
->stat_offsets_loaded
,
956 &osd
->eth
.tx_broadcast
,
957 &nsd
->eth
.tx_broadcast
);
959 i40e_stat_update32(hw
, I40E_GLPRT_TDOLD(hw
->port
),
960 pf
->stat_offsets_loaded
,
961 &osd
->tx_dropped_link_down
,
962 &nsd
->tx_dropped_link_down
);
964 i40e_stat_update32(hw
, I40E_GLPRT_CRCERRS(hw
->port
),
965 pf
->stat_offsets_loaded
,
966 &osd
->crc_errors
, &nsd
->crc_errors
);
968 i40e_stat_update32(hw
, I40E_GLPRT_ILLERRC(hw
->port
),
969 pf
->stat_offsets_loaded
,
970 &osd
->illegal_bytes
, &nsd
->illegal_bytes
);
972 i40e_stat_update32(hw
, I40E_GLPRT_MLFC(hw
->port
),
973 pf
->stat_offsets_loaded
,
974 &osd
->mac_local_faults
,
975 &nsd
->mac_local_faults
);
976 i40e_stat_update32(hw
, I40E_GLPRT_MRFC(hw
->port
),
977 pf
->stat_offsets_loaded
,
978 &osd
->mac_remote_faults
,
979 &nsd
->mac_remote_faults
);
981 i40e_stat_update32(hw
, I40E_GLPRT_RLEC(hw
->port
),
982 pf
->stat_offsets_loaded
,
983 &osd
->rx_length_errors
,
984 &nsd
->rx_length_errors
);
986 i40e_stat_update32(hw
, I40E_GLPRT_LXONRXC(hw
->port
),
987 pf
->stat_offsets_loaded
,
988 &osd
->link_xon_rx
, &nsd
->link_xon_rx
);
989 i40e_stat_update32(hw
, I40E_GLPRT_LXONTXC(hw
->port
),
990 pf
->stat_offsets_loaded
,
991 &osd
->link_xon_tx
, &nsd
->link_xon_tx
);
992 i40e_update_prio_xoff_rx(pf
); /* handles I40E_GLPRT_LXOFFRXC */
993 i40e_stat_update32(hw
, I40E_GLPRT_LXOFFTXC(hw
->port
),
994 pf
->stat_offsets_loaded
,
995 &osd
->link_xoff_tx
, &nsd
->link_xoff_tx
);
997 for (i
= 0; i
< 8; i
++) {
998 i40e_stat_update32(hw
, I40E_GLPRT_PXONRXC(hw
->port
, i
),
999 pf
->stat_offsets_loaded
,
1000 &osd
->priority_xon_rx
[i
],
1001 &nsd
->priority_xon_rx
[i
]);
1002 i40e_stat_update32(hw
, I40E_GLPRT_PXONTXC(hw
->port
, i
),
1003 pf
->stat_offsets_loaded
,
1004 &osd
->priority_xon_tx
[i
],
1005 &nsd
->priority_xon_tx
[i
]);
1006 i40e_stat_update32(hw
, I40E_GLPRT_PXOFFTXC(hw
->port
, i
),
1007 pf
->stat_offsets_loaded
,
1008 &osd
->priority_xoff_tx
[i
],
1009 &nsd
->priority_xoff_tx
[i
]);
1010 i40e_stat_update32(hw
,
1011 I40E_GLPRT_RXON2OFFCNT(hw
->port
, i
),
1012 pf
->stat_offsets_loaded
,
1013 &osd
->priority_xon_2_xoff
[i
],
1014 &nsd
->priority_xon_2_xoff
[i
]);
1017 i40e_stat_update48(hw
, I40E_GLPRT_PRC64H(hw
->port
),
1018 I40E_GLPRT_PRC64L(hw
->port
),
1019 pf
->stat_offsets_loaded
,
1020 &osd
->rx_size_64
, &nsd
->rx_size_64
);
1021 i40e_stat_update48(hw
, I40E_GLPRT_PRC127H(hw
->port
),
1022 I40E_GLPRT_PRC127L(hw
->port
),
1023 pf
->stat_offsets_loaded
,
1024 &osd
->rx_size_127
, &nsd
->rx_size_127
);
1025 i40e_stat_update48(hw
, I40E_GLPRT_PRC255H(hw
->port
),
1026 I40E_GLPRT_PRC255L(hw
->port
),
1027 pf
->stat_offsets_loaded
,
1028 &osd
->rx_size_255
, &nsd
->rx_size_255
);
1029 i40e_stat_update48(hw
, I40E_GLPRT_PRC511H(hw
->port
),
1030 I40E_GLPRT_PRC511L(hw
->port
),
1031 pf
->stat_offsets_loaded
,
1032 &osd
->rx_size_511
, &nsd
->rx_size_511
);
1033 i40e_stat_update48(hw
, I40E_GLPRT_PRC1023H(hw
->port
),
1034 I40E_GLPRT_PRC1023L(hw
->port
),
1035 pf
->stat_offsets_loaded
,
1036 &osd
->rx_size_1023
, &nsd
->rx_size_1023
);
1037 i40e_stat_update48(hw
, I40E_GLPRT_PRC1522H(hw
->port
),
1038 I40E_GLPRT_PRC1522L(hw
->port
),
1039 pf
->stat_offsets_loaded
,
1040 &osd
->rx_size_1522
, &nsd
->rx_size_1522
);
1041 i40e_stat_update48(hw
, I40E_GLPRT_PRC9522H(hw
->port
),
1042 I40E_GLPRT_PRC9522L(hw
->port
),
1043 pf
->stat_offsets_loaded
,
1044 &osd
->rx_size_big
, &nsd
->rx_size_big
);
1046 i40e_stat_update48(hw
, I40E_GLPRT_PTC64H(hw
->port
),
1047 I40E_GLPRT_PTC64L(hw
->port
),
1048 pf
->stat_offsets_loaded
,
1049 &osd
->tx_size_64
, &nsd
->tx_size_64
);
1050 i40e_stat_update48(hw
, I40E_GLPRT_PTC127H(hw
->port
),
1051 I40E_GLPRT_PTC127L(hw
->port
),
1052 pf
->stat_offsets_loaded
,
1053 &osd
->tx_size_127
, &nsd
->tx_size_127
);
1054 i40e_stat_update48(hw
, I40E_GLPRT_PTC255H(hw
->port
),
1055 I40E_GLPRT_PTC255L(hw
->port
),
1056 pf
->stat_offsets_loaded
,
1057 &osd
->tx_size_255
, &nsd
->tx_size_255
);
1058 i40e_stat_update48(hw
, I40E_GLPRT_PTC511H(hw
->port
),
1059 I40E_GLPRT_PTC511L(hw
->port
),
1060 pf
->stat_offsets_loaded
,
1061 &osd
->tx_size_511
, &nsd
->tx_size_511
);
1062 i40e_stat_update48(hw
, I40E_GLPRT_PTC1023H(hw
->port
),
1063 I40E_GLPRT_PTC1023L(hw
->port
),
1064 pf
->stat_offsets_loaded
,
1065 &osd
->tx_size_1023
, &nsd
->tx_size_1023
);
1066 i40e_stat_update48(hw
, I40E_GLPRT_PTC1522H(hw
->port
),
1067 I40E_GLPRT_PTC1522L(hw
->port
),
1068 pf
->stat_offsets_loaded
,
1069 &osd
->tx_size_1522
, &nsd
->tx_size_1522
);
1070 i40e_stat_update48(hw
, I40E_GLPRT_PTC9522H(hw
->port
),
1071 I40E_GLPRT_PTC9522L(hw
->port
),
1072 pf
->stat_offsets_loaded
,
1073 &osd
->tx_size_big
, &nsd
->tx_size_big
);
1075 i40e_stat_update32(hw
, I40E_GLPRT_RUC(hw
->port
),
1076 pf
->stat_offsets_loaded
,
1077 &osd
->rx_undersize
, &nsd
->rx_undersize
);
1078 i40e_stat_update32(hw
, I40E_GLPRT_RFC(hw
->port
),
1079 pf
->stat_offsets_loaded
,
1080 &osd
->rx_fragments
, &nsd
->rx_fragments
);
1081 i40e_stat_update32(hw
, I40E_GLPRT_ROC(hw
->port
),
1082 pf
->stat_offsets_loaded
,
1083 &osd
->rx_oversize
, &nsd
->rx_oversize
);
1084 i40e_stat_update32(hw
, I40E_GLPRT_RJC(hw
->port
),
1085 pf
->stat_offsets_loaded
,
1086 &osd
->rx_jabber
, &nsd
->rx_jabber
);
1089 i40e_stat_update32(hw
, I40E_GLQF_PCNT(pf
->fd_atr_cnt_idx
),
1090 pf
->stat_offsets_loaded
,
1091 &osd
->fd_atr_match
, &nsd
->fd_atr_match
);
1092 i40e_stat_update32(hw
, I40E_GLQF_PCNT(pf
->fd_sb_cnt_idx
),
1093 pf
->stat_offsets_loaded
,
1094 &osd
->fd_sb_match
, &nsd
->fd_sb_match
);
1096 val
= rd32(hw
, I40E_PRTPM_EEE_STAT
);
1097 nsd
->tx_lpi_status
=
1098 (val
& I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK
) >>
1099 I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT
;
1100 nsd
->rx_lpi_status
=
1101 (val
& I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK
) >>
1102 I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT
;
1103 i40e_stat_update32(hw
, I40E_PRTPM_TLPIC
,
1104 pf
->stat_offsets_loaded
,
1105 &osd
->tx_lpi_count
, &nsd
->tx_lpi_count
);
1106 i40e_stat_update32(hw
, I40E_PRTPM_RLPIC
,
1107 pf
->stat_offsets_loaded
,
1108 &osd
->rx_lpi_count
, &nsd
->rx_lpi_count
);
1110 pf
->stat_offsets_loaded
= true;
1114 * i40e_update_stats - Update the various statistics counters.
1115 * @vsi: the VSI to be updated
1117 * Update the various stats for this VSI and its related entities.
1119 void i40e_update_stats(struct i40e_vsi
*vsi
)
1121 struct i40e_pf
*pf
= vsi
->back
;
1123 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
1124 i40e_update_pf_stats(pf
);
1126 i40e_update_vsi_stats(vsi
);
1128 i40e_update_fcoe_stats(vsi
);
1133 * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
1134 * @vsi: the VSI to be searched
1135 * @macaddr: the MAC address
1137 * @is_vf: make sure its a vf filter, else doesn't matter
1138 * @is_netdev: make sure its a netdev filter, else doesn't matter
1140 * Returns ptr to the filter object or NULL
1142 static struct i40e_mac_filter
*i40e_find_filter(struct i40e_vsi
*vsi
,
1143 u8
*macaddr
, s16 vlan
,
1144 bool is_vf
, bool is_netdev
)
1146 struct i40e_mac_filter
*f
;
1148 if (!vsi
|| !macaddr
)
1151 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1152 if ((ether_addr_equal(macaddr
, f
->macaddr
)) &&
1153 (vlan
== f
->vlan
) &&
1154 (!is_vf
|| f
->is_vf
) &&
1155 (!is_netdev
|| f
->is_netdev
))
1162 * i40e_find_mac - Find a mac addr in the macvlan filters list
1163 * @vsi: the VSI to be searched
1164 * @macaddr: the MAC address we are searching for
1165 * @is_vf: make sure its a vf filter, else doesn't matter
1166 * @is_netdev: make sure its a netdev filter, else doesn't matter
1168 * Returns the first filter with the provided MAC address or NULL if
1169 * MAC address was not found
1171 struct i40e_mac_filter
*i40e_find_mac(struct i40e_vsi
*vsi
, u8
*macaddr
,
1172 bool is_vf
, bool is_netdev
)
1174 struct i40e_mac_filter
*f
;
1176 if (!vsi
|| !macaddr
)
1179 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1180 if ((ether_addr_equal(macaddr
, f
->macaddr
)) &&
1181 (!is_vf
|| f
->is_vf
) &&
1182 (!is_netdev
|| f
->is_netdev
))
1189 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1190 * @vsi: the VSI to be searched
1192 * Returns true if VSI is in vlan mode or false otherwise
1194 bool i40e_is_vsi_in_vlan(struct i40e_vsi
*vsi
)
1196 struct i40e_mac_filter
*f
;
1198 /* Only -1 for all the filters denotes not in vlan mode
1199 * so we have to go through all the list in order to make sure
1201 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1210 * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
1211 * @vsi: the VSI to be searched
1212 * @macaddr: the mac address to be filtered
1213 * @is_vf: true if it is a vf
1214 * @is_netdev: true if it is a netdev
1216 * Goes through all the macvlan filters and adds a
1217 * macvlan filter for each unique vlan that already exists
1219 * Returns first filter found on success, else NULL
1221 struct i40e_mac_filter
*i40e_put_mac_in_vlan(struct i40e_vsi
*vsi
, u8
*macaddr
,
1222 bool is_vf
, bool is_netdev
)
1224 struct i40e_mac_filter
*f
;
1226 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1227 if (!i40e_find_filter(vsi
, macaddr
, f
->vlan
,
1228 is_vf
, is_netdev
)) {
1229 if (!i40e_add_filter(vsi
, macaddr
, f
->vlan
,
1235 return list_first_entry_or_null(&vsi
->mac_filter_list
,
1236 struct i40e_mac_filter
, list
);
1240 * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
1241 * @vsi: the PF Main VSI - inappropriate for any other VSI
1242 * @macaddr: the MAC address
1244 * Some older firmware configurations set up a default promiscuous VLAN
1245 * filter that needs to be removed.
1247 static int i40e_rm_default_mac_filter(struct i40e_vsi
*vsi
, u8
*macaddr
)
1249 struct i40e_aqc_remove_macvlan_element_data element
;
1250 struct i40e_pf
*pf
= vsi
->back
;
1253 /* Only appropriate for the PF main VSI */
1254 if (vsi
->type
!= I40E_VSI_MAIN
)
1257 memset(&element
, 0, sizeof(element
));
1258 ether_addr_copy(element
.mac_addr
, macaddr
);
1259 element
.vlan_tag
= 0;
1260 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
|
1261 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
1262 aq_ret
= i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1270 * i40e_add_filter - Add a mac/vlan filter to the VSI
1271 * @vsi: the VSI to be searched
1272 * @macaddr: the MAC address
1274 * @is_vf: make sure its a vf filter, else doesn't matter
1275 * @is_netdev: make sure its a netdev filter, else doesn't matter
1277 * Returns ptr to the filter object or NULL when no memory available.
1279 struct i40e_mac_filter
*i40e_add_filter(struct i40e_vsi
*vsi
,
1280 u8
*macaddr
, s16 vlan
,
1281 bool is_vf
, bool is_netdev
)
1283 struct i40e_mac_filter
*f
;
1285 if (!vsi
|| !macaddr
)
1288 f
= i40e_find_filter(vsi
, macaddr
, vlan
, is_vf
, is_netdev
);
1290 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
1292 goto add_filter_out
;
1294 ether_addr_copy(f
->macaddr
, macaddr
);
1298 INIT_LIST_HEAD(&f
->list
);
1299 list_add(&f
->list
, &vsi
->mac_filter_list
);
1302 /* increment counter and add a new flag if needed */
1308 } else if (is_netdev
) {
1309 if (!f
->is_netdev
) {
1310 f
->is_netdev
= true;
1317 /* changed tells sync_filters_subtask to
1318 * push the filter down to the firmware
1321 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1322 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1330 * i40e_del_filter - Remove a mac/vlan filter from the VSI
1331 * @vsi: the VSI to be searched
1332 * @macaddr: the MAC address
1334 * @is_vf: make sure it's a vf filter, else doesn't matter
1335 * @is_netdev: make sure it's a netdev filter, else doesn't matter
1337 void i40e_del_filter(struct i40e_vsi
*vsi
,
1338 u8
*macaddr
, s16 vlan
,
1339 bool is_vf
, bool is_netdev
)
1341 struct i40e_mac_filter
*f
;
1343 if (!vsi
|| !macaddr
)
1346 f
= i40e_find_filter(vsi
, macaddr
, vlan
, is_vf
, is_netdev
);
1347 if (!f
|| f
->counter
== 0)
1355 } else if (is_netdev
) {
1357 f
->is_netdev
= false;
1361 /* make sure we don't remove a filter in use by vf or netdev */
1363 min_f
+= (f
->is_vf
? 1 : 0);
1364 min_f
+= (f
->is_netdev
? 1 : 0);
1366 if (f
->counter
> min_f
)
1370 /* counter == 0 tells sync_filters_subtask to
1371 * remove the filter from the firmware's list
1373 if (f
->counter
== 0) {
1375 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1376 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1381 * i40e_set_mac - NDO callback to set mac address
1382 * @netdev: network interface device structure
1383 * @p: pointer to an address structure
1385 * Returns 0 on success, negative on failure
1388 int i40e_set_mac(struct net_device
*netdev
, void *p
)
1390 static int i40e_set_mac(struct net_device
*netdev
, void *p
)
1393 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1394 struct i40e_vsi
*vsi
= np
->vsi
;
1395 struct i40e_pf
*pf
= vsi
->back
;
1396 struct i40e_hw
*hw
= &pf
->hw
;
1397 struct sockaddr
*addr
= p
;
1398 struct i40e_mac_filter
*f
;
1400 if (!is_valid_ether_addr(addr
->sa_data
))
1401 return -EADDRNOTAVAIL
;
1403 if (ether_addr_equal(netdev
->dev_addr
, addr
->sa_data
)) {
1404 netdev_info(netdev
, "already using mac address %pM\n",
1409 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
1410 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
1411 return -EADDRNOTAVAIL
;
1413 if (ether_addr_equal(hw
->mac
.addr
, addr
->sa_data
))
1414 netdev_info(netdev
, "returning to hw mac address %pM\n",
1417 netdev_info(netdev
, "set new mac address %pM\n", addr
->sa_data
);
1419 if (vsi
->type
== I40E_VSI_MAIN
) {
1421 ret
= i40e_aq_mac_address_write(&vsi
->back
->hw
,
1422 I40E_AQC_WRITE_TYPE_LAA_WOL
,
1423 addr
->sa_data
, NULL
);
1426 "Addr change for Main VSI failed: %d\n",
1428 return -EADDRNOTAVAIL
;
1432 if (ether_addr_equal(netdev
->dev_addr
, hw
->mac
.addr
)) {
1433 struct i40e_aqc_remove_macvlan_element_data element
;
1435 memset(&element
, 0, sizeof(element
));
1436 ether_addr_copy(element
.mac_addr
, netdev
->dev_addr
);
1437 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
1438 i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1440 i40e_del_filter(vsi
, netdev
->dev_addr
, I40E_VLAN_ANY
,
1444 if (ether_addr_equal(addr
->sa_data
, hw
->mac
.addr
)) {
1445 struct i40e_aqc_add_macvlan_element_data element
;
1447 memset(&element
, 0, sizeof(element
));
1448 ether_addr_copy(element
.mac_addr
, hw
->mac
.addr
);
1449 element
.flags
= cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
);
1450 i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
, &element
, 1, NULL
);
1452 f
= i40e_add_filter(vsi
, addr
->sa_data
, I40E_VLAN_ANY
,
1458 i40e_sync_vsi_filters(vsi
);
1459 ether_addr_copy(netdev
->dev_addr
, addr
->sa_data
);
1465 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1466 * @vsi: the VSI being setup
1467 * @ctxt: VSI context structure
1468 * @enabled_tc: Enabled TCs bitmap
1469 * @is_add: True if called before Add VSI
1471 * Setup VSI queue mapping for enabled traffic classes.
1474 void i40e_vsi_setup_queue_map(struct i40e_vsi
*vsi
,
1475 struct i40e_vsi_context
*ctxt
,
1479 static void i40e_vsi_setup_queue_map(struct i40e_vsi
*vsi
,
1480 struct i40e_vsi_context
*ctxt
,
1485 struct i40e_pf
*pf
= vsi
->back
;
1495 sections
= I40E_AQ_VSI_PROP_QUEUE_MAP_VALID
;
1498 if (enabled_tc
&& (vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
)) {
1499 /* Find numtc from enabled TC bitmap */
1500 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1501 if (enabled_tc
& (1 << i
)) /* TC is enabled */
1505 dev_warn(&pf
->pdev
->dev
, "DCB is enabled but no TC enabled, forcing TC0\n");
1509 /* At least TC0 is enabled in case of non-DCB case */
1513 vsi
->tc_config
.numtc
= numtc
;
1514 vsi
->tc_config
.enabled_tc
= enabled_tc
? enabled_tc
: 1;
1515 /* Number of queues per enabled TC */
1516 num_tc_qps
= vsi
->alloc_queue_pairs
/numtc
;
1517 num_tc_qps
= min_t(int, num_tc_qps
, I40E_MAX_QUEUES_PER_TC
);
1519 /* Setup queue offset/count for all TCs for given VSI */
1520 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1521 /* See if the given TC is enabled for the given VSI */
1522 if (vsi
->tc_config
.enabled_tc
& (1 << i
)) { /* TC is enabled */
1525 switch (vsi
->type
) {
1527 qcount
= min_t(int, pf
->rss_size
, num_tc_qps
);
1531 qcount
= num_tc_qps
;
1535 case I40E_VSI_SRIOV
:
1536 case I40E_VSI_VMDQ2
:
1538 qcount
= num_tc_qps
;
1542 vsi
->tc_config
.tc_info
[i
].qoffset
= offset
;
1543 vsi
->tc_config
.tc_info
[i
].qcount
= qcount
;
1545 /* find the power-of-2 of the number of queue pairs */
1548 while (num_qps
&& ((1 << pow
) < qcount
)) {
1553 vsi
->tc_config
.tc_info
[i
].netdev_tc
= netdev_tc
++;
1555 (offset
<< I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT
) |
1556 (pow
<< I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT
);
1560 /* TC is not enabled so set the offset to
1561 * default queue and allocate one queue
1564 vsi
->tc_config
.tc_info
[i
].qoffset
= 0;
1565 vsi
->tc_config
.tc_info
[i
].qcount
= 1;
1566 vsi
->tc_config
.tc_info
[i
].netdev_tc
= 0;
1570 ctxt
->info
.tc_mapping
[i
] = cpu_to_le16(qmap
);
1573 /* Set actual Tx/Rx queue pairs */
1574 vsi
->num_queue_pairs
= offset
;
1576 /* Scheduler section valid can only be set for ADD VSI */
1578 sections
|= I40E_AQ_VSI_PROP_SCHED_VALID
;
1580 ctxt
->info
.up_enable_bits
= enabled_tc
;
1582 if (vsi
->type
== I40E_VSI_SRIOV
) {
1583 ctxt
->info
.mapping_flags
|=
1584 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG
);
1585 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
1586 ctxt
->info
.queue_mapping
[i
] =
1587 cpu_to_le16(vsi
->base_queue
+ i
);
1589 ctxt
->info
.mapping_flags
|=
1590 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG
);
1591 ctxt
->info
.queue_mapping
[0] = cpu_to_le16(vsi
->base_queue
);
1593 ctxt
->info
.valid_sections
|= cpu_to_le16(sections
);
1597 * i40e_set_rx_mode - NDO callback to set the netdev filters
1598 * @netdev: network interface device structure
1601 void i40e_set_rx_mode(struct net_device
*netdev
)
1603 static void i40e_set_rx_mode(struct net_device
*netdev
)
1606 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1607 struct i40e_mac_filter
*f
, *ftmp
;
1608 struct i40e_vsi
*vsi
= np
->vsi
;
1609 struct netdev_hw_addr
*uca
;
1610 struct netdev_hw_addr
*mca
;
1611 struct netdev_hw_addr
*ha
;
1613 /* add addr if not already in the filter list */
1614 netdev_for_each_uc_addr(uca
, netdev
) {
1615 if (!i40e_find_mac(vsi
, uca
->addr
, false, true)) {
1616 if (i40e_is_vsi_in_vlan(vsi
))
1617 i40e_put_mac_in_vlan(vsi
, uca
->addr
,
1620 i40e_add_filter(vsi
, uca
->addr
, I40E_VLAN_ANY
,
1625 netdev_for_each_mc_addr(mca
, netdev
) {
1626 if (!i40e_find_mac(vsi
, mca
->addr
, false, true)) {
1627 if (i40e_is_vsi_in_vlan(vsi
))
1628 i40e_put_mac_in_vlan(vsi
, mca
->addr
,
1631 i40e_add_filter(vsi
, mca
->addr
, I40E_VLAN_ANY
,
1636 /* remove filter if not in netdev list */
1637 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1643 if (is_multicast_ether_addr(f
->macaddr
)) {
1644 netdev_for_each_mc_addr(mca
, netdev
) {
1645 if (ether_addr_equal(mca
->addr
, f
->macaddr
)) {
1651 netdev_for_each_uc_addr(uca
, netdev
) {
1652 if (ether_addr_equal(uca
->addr
, f
->macaddr
)) {
1658 for_each_dev_addr(netdev
, ha
) {
1659 if (ether_addr_equal(ha
->addr
, f
->macaddr
)) {
1667 vsi
, f
->macaddr
, I40E_VLAN_ANY
, false, true);
1670 /* check for other flag changes */
1671 if (vsi
->current_netdev_flags
!= vsi
->netdev
->flags
) {
1672 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
1673 vsi
->back
->flags
|= I40E_FLAG_FILTER_SYNC
;
1678 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
1679 * @vsi: ptr to the VSI
1681 * Push any outstanding VSI filter changes through the AdminQ.
1683 * Returns 0 or error value
1685 int i40e_sync_vsi_filters(struct i40e_vsi
*vsi
)
1687 struct i40e_mac_filter
*f
, *ftmp
;
1688 bool promisc_forced_on
= false;
1689 bool add_happened
= false;
1690 int filter_list_len
= 0;
1691 u32 changed_flags
= 0;
1692 i40e_status aq_ret
= 0;
1698 /* empty array typed pointers, kcalloc later */
1699 struct i40e_aqc_add_macvlan_element_data
*add_list
;
1700 struct i40e_aqc_remove_macvlan_element_data
*del_list
;
1702 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &vsi
->state
))
1703 usleep_range(1000, 2000);
1707 changed_flags
= vsi
->current_netdev_flags
^ vsi
->netdev
->flags
;
1708 vsi
->current_netdev_flags
= vsi
->netdev
->flags
;
1711 if (vsi
->flags
& I40E_VSI_FLAG_FILTER_CHANGED
) {
1712 vsi
->flags
&= ~I40E_VSI_FLAG_FILTER_CHANGED
;
1714 filter_list_len
= pf
->hw
.aq
.asq_buf_size
/
1715 sizeof(struct i40e_aqc_remove_macvlan_element_data
);
1716 del_list
= kcalloc(filter_list_len
,
1717 sizeof(struct i40e_aqc_remove_macvlan_element_data
),
1722 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1726 if (f
->counter
!= 0)
1731 /* add to delete list */
1732 ether_addr_copy(del_list
[num_del
].mac_addr
, f
->macaddr
);
1733 del_list
[num_del
].vlan_tag
=
1734 cpu_to_le16((u16
)(f
->vlan
==
1735 I40E_VLAN_ANY
? 0 : f
->vlan
));
1737 cmd_flags
|= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
1738 del_list
[num_del
].flags
= cmd_flags
;
1741 /* unlink from filter list */
1745 /* flush a full buffer */
1746 if (num_del
== filter_list_len
) {
1747 aq_ret
= i40e_aq_remove_macvlan(&pf
->hw
,
1748 vsi
->seid
, del_list
, num_del
,
1751 memset(del_list
, 0, sizeof(*del_list
));
1754 pf
->hw
.aq
.asq_last_status
!=
1756 dev_info(&pf
->pdev
->dev
,
1757 "ignoring delete macvlan error, err %d, aq_err %d while flushing a full buffer\n",
1759 pf
->hw
.aq
.asq_last_status
);
1763 aq_ret
= i40e_aq_remove_macvlan(&pf
->hw
, vsi
->seid
,
1764 del_list
, num_del
, NULL
);
1768 pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_ENOENT
)
1769 dev_info(&pf
->pdev
->dev
,
1770 "ignoring delete macvlan error, err %d, aq_err %d\n",
1771 aq_ret
, pf
->hw
.aq
.asq_last_status
);
1777 /* do all the adds now */
1778 filter_list_len
= pf
->hw
.aq
.asq_buf_size
/
1779 sizeof(struct i40e_aqc_add_macvlan_element_data
),
1780 add_list
= kcalloc(filter_list_len
,
1781 sizeof(struct i40e_aqc_add_macvlan_element_data
),
1786 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
1790 if (f
->counter
== 0)
1793 add_happened
= true;
1796 /* add to add array */
1797 ether_addr_copy(add_list
[num_add
].mac_addr
, f
->macaddr
);
1798 add_list
[num_add
].vlan_tag
=
1800 (u16
)(f
->vlan
== I40E_VLAN_ANY
? 0 : f
->vlan
));
1801 add_list
[num_add
].queue_number
= 0;
1803 cmd_flags
|= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH
;
1804 add_list
[num_add
].flags
= cpu_to_le16(cmd_flags
);
1807 /* flush a full buffer */
1808 if (num_add
== filter_list_len
) {
1809 aq_ret
= i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
,
1816 memset(add_list
, 0, sizeof(*add_list
));
1820 aq_ret
= i40e_aq_add_macvlan(&pf
->hw
, vsi
->seid
,
1821 add_list
, num_add
, NULL
);
1827 if (add_happened
&& aq_ret
&&
1828 pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_EINVAL
) {
1829 dev_info(&pf
->pdev
->dev
,
1830 "add filter failed, err %d, aq_err %d\n",
1831 aq_ret
, pf
->hw
.aq
.asq_last_status
);
1832 if ((pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_ENOSPC
) &&
1833 !test_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
1835 promisc_forced_on
= true;
1836 set_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
1838 dev_info(&pf
->pdev
->dev
, "promiscuous mode forced on\n");
1843 /* check for changes in promiscuous modes */
1844 if (changed_flags
& IFF_ALLMULTI
) {
1845 bool cur_multipromisc
;
1846 cur_multipromisc
= !!(vsi
->current_netdev_flags
& IFF_ALLMULTI
);
1847 aq_ret
= i40e_aq_set_vsi_multicast_promiscuous(&vsi
->back
->hw
,
1852 dev_info(&pf
->pdev
->dev
,
1853 "set multi promisc failed, err %d, aq_err %d\n",
1854 aq_ret
, pf
->hw
.aq
.asq_last_status
);
1856 if ((changed_flags
& IFF_PROMISC
) || promisc_forced_on
) {
1858 cur_promisc
= (!!(vsi
->current_netdev_flags
& IFF_PROMISC
) ||
1859 test_bit(__I40E_FILTER_OVERFLOW_PROMISC
,
1861 aq_ret
= i40e_aq_set_vsi_unicast_promiscuous(&vsi
->back
->hw
,
1865 dev_info(&pf
->pdev
->dev
,
1866 "set uni promisc failed, err %d, aq_err %d\n",
1867 aq_ret
, pf
->hw
.aq
.asq_last_status
);
1868 aq_ret
= i40e_aq_set_vsi_broadcast(&vsi
->back
->hw
,
1872 dev_info(&pf
->pdev
->dev
,
1873 "set brdcast promisc failed, err %d, aq_err %d\n",
1874 aq_ret
, pf
->hw
.aq
.asq_last_status
);
1877 clear_bit(__I40E_CONFIG_BUSY
, &vsi
->state
);
1882 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
1883 * @pf: board private structure
1885 static void i40e_sync_filters_subtask(struct i40e_pf
*pf
)
1889 if (!pf
|| !(pf
->flags
& I40E_FLAG_FILTER_SYNC
))
1891 pf
->flags
&= ~I40E_FLAG_FILTER_SYNC
;
1893 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
1895 (pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_FILTER_CHANGED
))
1896 i40e_sync_vsi_filters(pf
->vsi
[v
]);
1901 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
1902 * @netdev: network interface device structure
1903 * @new_mtu: new value for maximum frame size
1905 * Returns 0 on success, negative on failure
1907 static int i40e_change_mtu(struct net_device
*netdev
, int new_mtu
)
1909 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1910 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
1911 struct i40e_vsi
*vsi
= np
->vsi
;
1913 /* MTU < 68 is an error and causes problems on some kernels */
1914 if ((new_mtu
< 68) || (max_frame
> I40E_MAX_RXBUFFER
))
1917 netdev_info(netdev
, "changing MTU from %d to %d\n",
1918 netdev
->mtu
, new_mtu
);
1919 netdev
->mtu
= new_mtu
;
1920 if (netif_running(netdev
))
1921 i40e_vsi_reinit_locked(vsi
);
1927 * i40e_ioctl - Access the hwtstamp interface
1928 * @netdev: network interface device structure
1929 * @ifr: interface request data
1930 * @cmd: ioctl command
1932 int i40e_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
1934 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1935 struct i40e_pf
*pf
= np
->vsi
->back
;
1939 return i40e_ptp_get_ts_config(pf
, ifr
);
1941 return i40e_ptp_set_ts_config(pf
, ifr
);
1948 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
1949 * @vsi: the vsi being adjusted
1951 void i40e_vlan_stripping_enable(struct i40e_vsi
*vsi
)
1953 struct i40e_vsi_context ctxt
;
1956 if ((vsi
->info
.valid_sections
&
1957 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
1958 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_MODE_MASK
) == 0))
1959 return; /* already enabled */
1961 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
1962 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
1963 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH
;
1965 ctxt
.seid
= vsi
->seid
;
1966 memcpy(&ctxt
.info
, &vsi
->info
, sizeof(vsi
->info
));
1967 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
1969 dev_info(&vsi
->back
->pdev
->dev
,
1970 "%s: update vsi failed, aq_err=%d\n",
1971 __func__
, vsi
->back
->hw
.aq
.asq_last_status
);
1976 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
1977 * @vsi: the vsi being adjusted
1979 void i40e_vlan_stripping_disable(struct i40e_vsi
*vsi
)
1981 struct i40e_vsi_context ctxt
;
1984 if ((vsi
->info
.valid_sections
&
1985 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
)) &&
1986 ((vsi
->info
.port_vlan_flags
& I40E_AQ_VSI_PVLAN_EMOD_MASK
) ==
1987 I40E_AQ_VSI_PVLAN_EMOD_MASK
))
1988 return; /* already disabled */
1990 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
1991 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_ALL
|
1992 I40E_AQ_VSI_PVLAN_EMOD_NOTHING
;
1994 ctxt
.seid
= vsi
->seid
;
1995 memcpy(&ctxt
.info
, &vsi
->info
, sizeof(vsi
->info
));
1996 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
1998 dev_info(&vsi
->back
->pdev
->dev
,
1999 "%s: update vsi failed, aq_err=%d\n",
2000 __func__
, vsi
->back
->hw
.aq
.asq_last_status
);
2005 * i40e_vlan_rx_register - Setup or shutdown vlan offload
2006 * @netdev: network interface to be adjusted
2007 * @features: netdev features to test if VLAN offload is enabled or not
2009 static void i40e_vlan_rx_register(struct net_device
*netdev
, u32 features
)
2011 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2012 struct i40e_vsi
*vsi
= np
->vsi
;
2014 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
2015 i40e_vlan_stripping_enable(vsi
);
2017 i40e_vlan_stripping_disable(vsi
);
2021 * i40e_vsi_add_vlan - Add vsi membership for given vlan
2022 * @vsi: the vsi being configured
2023 * @vid: vlan id to be added (0 = untagged only , -1 = any)
2025 int i40e_vsi_add_vlan(struct i40e_vsi
*vsi
, s16 vid
)
2027 struct i40e_mac_filter
*f
, *add_f
;
2028 bool is_netdev
, is_vf
;
2030 is_vf
= (vsi
->type
== I40E_VSI_SRIOV
);
2031 is_netdev
= !!(vsi
->netdev
);
2034 add_f
= i40e_add_filter(vsi
, vsi
->netdev
->dev_addr
, vid
,
2037 dev_info(&vsi
->back
->pdev
->dev
,
2038 "Could not add vlan filter %d for %pM\n",
2039 vid
, vsi
->netdev
->dev_addr
);
2044 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2045 add_f
= i40e_add_filter(vsi
, f
->macaddr
, vid
, is_vf
, is_netdev
);
2047 dev_info(&vsi
->back
->pdev
->dev
,
2048 "Could not add vlan filter %d for %pM\n",
2054 /* Now if we add a vlan tag, make sure to check if it is the first
2055 * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
2056 * with 0, so we now accept untagged and specified tagged traffic
2057 * (and not any taged and untagged)
2060 if (is_netdev
&& i40e_find_filter(vsi
, vsi
->netdev
->dev_addr
,
2062 is_vf
, is_netdev
)) {
2063 i40e_del_filter(vsi
, vsi
->netdev
->dev_addr
,
2064 I40E_VLAN_ANY
, is_vf
, is_netdev
);
2065 add_f
= i40e_add_filter(vsi
, vsi
->netdev
->dev_addr
, 0,
2068 dev_info(&vsi
->back
->pdev
->dev
,
2069 "Could not add filter 0 for %pM\n",
2070 vsi
->netdev
->dev_addr
);
2076 /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
2077 if (vid
> 0 && !vsi
->info
.pvid
) {
2078 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2079 if (i40e_find_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2080 is_vf
, is_netdev
)) {
2081 i40e_del_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2083 add_f
= i40e_add_filter(vsi
, f
->macaddr
,
2084 0, is_vf
, is_netdev
);
2086 dev_info(&vsi
->back
->pdev
->dev
,
2087 "Could not add filter 0 for %pM\n",
2095 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
2096 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
2099 return i40e_sync_vsi_filters(vsi
);
2103 * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
2104 * @vsi: the vsi being configured
2105 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
2107 * Return: 0 on success or negative otherwise
2109 int i40e_vsi_kill_vlan(struct i40e_vsi
*vsi
, s16 vid
)
2111 struct net_device
*netdev
= vsi
->netdev
;
2112 struct i40e_mac_filter
*f
, *add_f
;
2113 bool is_vf
, is_netdev
;
2114 int filter_count
= 0;
2116 is_vf
= (vsi
->type
== I40E_VSI_SRIOV
);
2117 is_netdev
= !!(netdev
);
2120 i40e_del_filter(vsi
, netdev
->dev_addr
, vid
, is_vf
, is_netdev
);
2122 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
)
2123 i40e_del_filter(vsi
, f
->macaddr
, vid
, is_vf
, is_netdev
);
2125 /* go through all the filters for this VSI and if there is only
2126 * vid == 0 it means there are no other filters, so vid 0 must
2127 * be replaced with -1. This signifies that we should from now
2128 * on accept any traffic (with any tag present, or untagged)
2130 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2133 ether_addr_equal(netdev
->dev_addr
, f
->macaddr
))
2141 if (!filter_count
&& is_netdev
) {
2142 i40e_del_filter(vsi
, netdev
->dev_addr
, 0, is_vf
, is_netdev
);
2143 f
= i40e_add_filter(vsi
, netdev
->dev_addr
, I40E_VLAN_ANY
,
2146 dev_info(&vsi
->back
->pdev
->dev
,
2147 "Could not add filter %d for %pM\n",
2148 I40E_VLAN_ANY
, netdev
->dev_addr
);
2153 if (!filter_count
) {
2154 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
2155 i40e_del_filter(vsi
, f
->macaddr
, 0, is_vf
, is_netdev
);
2156 add_f
= i40e_add_filter(vsi
, f
->macaddr
, I40E_VLAN_ANY
,
2159 dev_info(&vsi
->back
->pdev
->dev
,
2160 "Could not add filter %d for %pM\n",
2161 I40E_VLAN_ANY
, f
->macaddr
);
2167 if (test_bit(__I40E_DOWN
, &vsi
->back
->state
) ||
2168 test_bit(__I40E_RESET_RECOVERY_PENDING
, &vsi
->back
->state
))
2171 return i40e_sync_vsi_filters(vsi
);
2175 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2176 * @netdev: network interface to be adjusted
2177 * @vid: vlan id to be added
2179 * net_device_ops implementation for adding vlan ids
2182 int i40e_vlan_rx_add_vid(struct net_device
*netdev
,
2183 __always_unused __be16 proto
, u16 vid
)
2185 static int i40e_vlan_rx_add_vid(struct net_device
*netdev
,
2186 __always_unused __be16 proto
, u16 vid
)
2189 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2190 struct i40e_vsi
*vsi
= np
->vsi
;
2196 netdev_info(netdev
, "adding %pM vid=%d\n", netdev
->dev_addr
, vid
);
2198 /* If the network stack called us with vid = 0 then
2199 * it is asking to receive priority tagged packets with
2200 * vlan id 0. Our HW receives them by default when configured
2201 * to receive untagged packets so there is no need to add an
2202 * extra filter for vlan 0 tagged packets.
2205 ret
= i40e_vsi_add_vlan(vsi
, vid
);
2207 if (!ret
&& (vid
< VLAN_N_VID
))
2208 set_bit(vid
, vsi
->active_vlans
);
2214 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2215 * @netdev: network interface to be adjusted
2216 * @vid: vlan id to be removed
2218 * net_device_ops implementation for removing vlan ids
2221 int i40e_vlan_rx_kill_vid(struct net_device
*netdev
,
2222 __always_unused __be16 proto
, u16 vid
)
2224 static int i40e_vlan_rx_kill_vid(struct net_device
*netdev
,
2225 __always_unused __be16 proto
, u16 vid
)
2228 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2229 struct i40e_vsi
*vsi
= np
->vsi
;
2231 netdev_info(netdev
, "removing %pM vid=%d\n", netdev
->dev_addr
, vid
);
2233 /* return code is ignored as there is nothing a user
2234 * can do about failure to remove and a log message was
2235 * already printed from the other function
2237 i40e_vsi_kill_vlan(vsi
, vid
);
2239 clear_bit(vid
, vsi
->active_vlans
);
2245 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2246 * @vsi: the vsi being brought back up
2248 static void i40e_restore_vlan(struct i40e_vsi
*vsi
)
2255 i40e_vlan_rx_register(vsi
->netdev
, vsi
->netdev
->features
);
2257 for_each_set_bit(vid
, vsi
->active_vlans
, VLAN_N_VID
)
2258 i40e_vlan_rx_add_vid(vsi
->netdev
, htons(ETH_P_8021Q
),
2263 * i40e_vsi_add_pvid - Add pvid for the VSI
2264 * @vsi: the vsi being adjusted
2265 * @vid: the vlan id to set as a PVID
2267 int i40e_vsi_add_pvid(struct i40e_vsi
*vsi
, u16 vid
)
2269 struct i40e_vsi_context ctxt
;
2272 vsi
->info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
2273 vsi
->info
.pvid
= cpu_to_le16(vid
);
2274 vsi
->info
.port_vlan_flags
= I40E_AQ_VSI_PVLAN_MODE_TAGGED
|
2275 I40E_AQ_VSI_PVLAN_INSERT_PVID
|
2276 I40E_AQ_VSI_PVLAN_EMOD_STR
;
2278 ctxt
.seid
= vsi
->seid
;
2279 memcpy(&ctxt
.info
, &vsi
->info
, sizeof(vsi
->info
));
2280 aq_ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
2282 dev_info(&vsi
->back
->pdev
->dev
,
2283 "%s: update vsi failed, aq_err=%d\n",
2284 __func__
, vsi
->back
->hw
.aq
.asq_last_status
);
2292 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2293 * @vsi: the vsi being adjusted
2295 * Just use the vlan_rx_register() service to put it back to normal
2297 void i40e_vsi_remove_pvid(struct i40e_vsi
*vsi
)
2299 i40e_vlan_stripping_disable(vsi
);
2305 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2306 * @vsi: ptr to the VSI
2308 * If this function returns with an error, then it's possible one or
2309 * more of the rings is populated (while the rest are not). It is the
2310 * callers duty to clean those orphaned rings.
2312 * Return 0 on success, negative on failure
2314 static int i40e_vsi_setup_tx_resources(struct i40e_vsi
*vsi
)
2318 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2319 err
= i40e_setup_tx_descriptors(vsi
->tx_rings
[i
]);
2325 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2326 * @vsi: ptr to the VSI
2328 * Free VSI's transmit software resources
2330 static void i40e_vsi_free_tx_resources(struct i40e_vsi
*vsi
)
2337 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2338 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
)
2339 i40e_free_tx_resources(vsi
->tx_rings
[i
]);
2343 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2344 * @vsi: ptr to the VSI
2346 * If this function returns with an error, then it's possible one or
2347 * more of the rings is populated (while the rest are not). It is the
2348 * callers duty to clean those orphaned rings.
2350 * Return 0 on success, negative on failure
2352 static int i40e_vsi_setup_rx_resources(struct i40e_vsi
*vsi
)
2356 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2357 err
= i40e_setup_rx_descriptors(vsi
->rx_rings
[i
]);
2359 i40e_fcoe_setup_ddp_resources(vsi
);
2365 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2366 * @vsi: ptr to the VSI
2368 * Free all receive software resources
2370 static void i40e_vsi_free_rx_resources(struct i40e_vsi
*vsi
)
2377 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2378 if (vsi
->rx_rings
[i
] && vsi
->rx_rings
[i
]->desc
)
2379 i40e_free_rx_resources(vsi
->rx_rings
[i
]);
2381 i40e_fcoe_free_ddp_resources(vsi
);
2386 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2387 * @ring: The Tx ring to configure
2389 * Configure the Tx descriptor ring in the HMC context.
2391 static int i40e_configure_tx_ring(struct i40e_ring
*ring
)
2393 struct i40e_vsi
*vsi
= ring
->vsi
;
2394 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
2395 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2396 struct i40e_hmc_obj_txq tx_ctx
;
2397 i40e_status err
= 0;
2400 /* some ATR related tx ring init */
2401 if (vsi
->back
->flags
& I40E_FLAG_FD_ATR_ENABLED
) {
2402 ring
->atr_sample_rate
= vsi
->back
->atr_sample_rate
;
2403 ring
->atr_count
= 0;
2405 ring
->atr_sample_rate
= 0;
2408 /* initialize XPS */
2409 if (ring
->q_vector
&& ring
->netdev
&&
2410 vsi
->tc_config
.numtc
<= 1 &&
2411 !test_and_set_bit(__I40E_TX_XPS_INIT_DONE
, &ring
->state
))
2412 netif_set_xps_queue(ring
->netdev
,
2413 &ring
->q_vector
->affinity_mask
,
2416 /* clear the context structure first */
2417 memset(&tx_ctx
, 0, sizeof(tx_ctx
));
2419 tx_ctx
.new_context
= 1;
2420 tx_ctx
.base
= (ring
->dma
/ 128);
2421 tx_ctx
.qlen
= ring
->count
;
2422 tx_ctx
.fd_ena
= !!(vsi
->back
->flags
& (I40E_FLAG_FD_SB_ENABLED
|
2423 I40E_FLAG_FD_ATR_ENABLED
));
2425 tx_ctx
.fc_ena
= (vsi
->type
== I40E_VSI_FCOE
);
2427 tx_ctx
.timesync_ena
= !!(vsi
->back
->flags
& I40E_FLAG_PTP
);
2428 /* FDIR VSI tx ring can still use RS bit and writebacks */
2429 if (vsi
->type
!= I40E_VSI_FDIR
)
2430 tx_ctx
.head_wb_ena
= 1;
2431 tx_ctx
.head_wb_addr
= ring
->dma
+
2432 (ring
->count
* sizeof(struct i40e_tx_desc
));
2434 /* As part of VSI creation/update, FW allocates certain
2435 * Tx arbitration queue sets for each TC enabled for
2436 * the VSI. The FW returns the handles to these queue
2437 * sets as part of the response buffer to Add VSI,
2438 * Update VSI, etc. AQ commands. It is expected that
2439 * these queue set handles be associated with the Tx
2440 * queues by the driver as part of the TX queue context
2441 * initialization. This has to be done regardless of
2442 * DCB as by default everything is mapped to TC0.
2444 tx_ctx
.rdylist
= le16_to_cpu(vsi
->info
.qs_handle
[ring
->dcb_tc
]);
2445 tx_ctx
.rdylist_act
= 0;
2447 /* clear the context in the HMC */
2448 err
= i40e_clear_lan_tx_queue_context(hw
, pf_q
);
2450 dev_info(&vsi
->back
->pdev
->dev
,
2451 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2452 ring
->queue_index
, pf_q
, err
);
2456 /* set the context in the HMC */
2457 err
= i40e_set_lan_tx_queue_context(hw
, pf_q
, &tx_ctx
);
2459 dev_info(&vsi
->back
->pdev
->dev
,
2460 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
2461 ring
->queue_index
, pf_q
, err
);
2465 /* Now associate this queue with this PCI function */
2466 if (vsi
->type
== I40E_VSI_VMDQ2
)
2467 qtx_ctl
= I40E_QTX_CTL_VM_QUEUE
;
2469 qtx_ctl
= I40E_QTX_CTL_PF_QUEUE
;
2470 qtx_ctl
|= ((hw
->pf_id
<< I40E_QTX_CTL_PF_INDX_SHIFT
) &
2471 I40E_QTX_CTL_PF_INDX_MASK
);
2472 wr32(hw
, I40E_QTX_CTL(pf_q
), qtx_ctl
);
2475 clear_bit(__I40E_HANG_CHECK_ARMED
, &ring
->state
);
2477 /* cache tail off for easier writes later */
2478 ring
->tail
= hw
->hw_addr
+ I40E_QTX_TAIL(pf_q
);
2484 * i40e_configure_rx_ring - Configure a receive ring context
2485 * @ring: The Rx ring to configure
2487 * Configure the Rx descriptor ring in the HMC context.
2489 static int i40e_configure_rx_ring(struct i40e_ring
*ring
)
2491 struct i40e_vsi
*vsi
= ring
->vsi
;
2492 u32 chain_len
= vsi
->back
->hw
.func_caps
.rx_buf_chain_len
;
2493 u16 pf_q
= vsi
->base_queue
+ ring
->queue_index
;
2494 struct i40e_hw
*hw
= &vsi
->back
->hw
;
2495 struct i40e_hmc_obj_rxq rx_ctx
;
2496 i40e_status err
= 0;
2500 /* clear the context structure first */
2501 memset(&rx_ctx
, 0, sizeof(rx_ctx
));
2503 ring
->rx_buf_len
= vsi
->rx_buf_len
;
2504 ring
->rx_hdr_len
= vsi
->rx_hdr_len
;
2506 rx_ctx
.dbuff
= ring
->rx_buf_len
>> I40E_RXQ_CTX_DBUFF_SHIFT
;
2507 rx_ctx
.hbuff
= ring
->rx_hdr_len
>> I40E_RXQ_CTX_HBUFF_SHIFT
;
2509 rx_ctx
.base
= (ring
->dma
/ 128);
2510 rx_ctx
.qlen
= ring
->count
;
2512 if (vsi
->back
->flags
& I40E_FLAG_16BYTE_RX_DESC_ENABLED
) {
2513 set_ring_16byte_desc_enabled(ring
);
2519 rx_ctx
.dtype
= vsi
->dtype
;
2521 set_ring_ps_enabled(ring
);
2522 rx_ctx
.hsplit_0
= I40E_RX_SPLIT_L2
|
2524 I40E_RX_SPLIT_TCP_UDP
|
2527 rx_ctx
.hsplit_0
= 0;
2530 rx_ctx
.rxmax
= min_t(u16
, vsi
->max_frame
,
2531 (chain_len
* ring
->rx_buf_len
));
2532 if (hw
->revision_id
== 0)
2533 rx_ctx
.lrxqthresh
= 0;
2535 rx_ctx
.lrxqthresh
= 2;
2536 rx_ctx
.crcstrip
= 1;
2540 rx_ctx
.fc_ena
= (vsi
->type
== I40E_VSI_FCOE
);
2542 /* set the prefena field to 1 because the manual says to */
2545 /* clear the context in the HMC */
2546 err
= i40e_clear_lan_rx_queue_context(hw
, pf_q
);
2548 dev_info(&vsi
->back
->pdev
->dev
,
2549 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2550 ring
->queue_index
, pf_q
, err
);
2554 /* set the context in the HMC */
2555 err
= i40e_set_lan_rx_queue_context(hw
, pf_q
, &rx_ctx
);
2557 dev_info(&vsi
->back
->pdev
->dev
,
2558 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2559 ring
->queue_index
, pf_q
, err
);
2563 /* cache tail for quicker writes, and clear the reg before use */
2564 ring
->tail
= hw
->hw_addr
+ I40E_QRX_TAIL(pf_q
);
2565 writel(0, ring
->tail
);
2567 i40e_alloc_rx_buffers(ring
, I40E_DESC_UNUSED(ring
));
2573 * i40e_vsi_configure_tx - Configure the VSI for Tx
2574 * @vsi: VSI structure describing this set of rings and resources
2576 * Configure the Tx VSI for operation.
2578 static int i40e_vsi_configure_tx(struct i40e_vsi
*vsi
)
2583 for (i
= 0; (i
< vsi
->num_queue_pairs
) && !err
; i
++)
2584 err
= i40e_configure_tx_ring(vsi
->tx_rings
[i
]);
2590 * i40e_vsi_configure_rx - Configure the VSI for Rx
2591 * @vsi: the VSI being configured
2593 * Configure the Rx VSI for operation.
2595 static int i40e_vsi_configure_rx(struct i40e_vsi
*vsi
)
2600 if (vsi
->netdev
&& (vsi
->netdev
->mtu
> ETH_DATA_LEN
))
2601 vsi
->max_frame
= vsi
->netdev
->mtu
+ ETH_HLEN
2602 + ETH_FCS_LEN
+ VLAN_HLEN
;
2604 vsi
->max_frame
= I40E_RXBUFFER_2048
;
2606 /* figure out correct receive buffer length */
2607 switch (vsi
->back
->flags
& (I40E_FLAG_RX_1BUF_ENABLED
|
2608 I40E_FLAG_RX_PS_ENABLED
)) {
2609 case I40E_FLAG_RX_1BUF_ENABLED
:
2610 vsi
->rx_hdr_len
= 0;
2611 vsi
->rx_buf_len
= vsi
->max_frame
;
2612 vsi
->dtype
= I40E_RX_DTYPE_NO_SPLIT
;
2614 case I40E_FLAG_RX_PS_ENABLED
:
2615 vsi
->rx_hdr_len
= I40E_RX_HDR_SIZE
;
2616 vsi
->rx_buf_len
= I40E_RXBUFFER_2048
;
2617 vsi
->dtype
= I40E_RX_DTYPE_HEADER_SPLIT
;
2620 vsi
->rx_hdr_len
= I40E_RX_HDR_SIZE
;
2621 vsi
->rx_buf_len
= I40E_RXBUFFER_2048
;
2622 vsi
->dtype
= I40E_RX_DTYPE_SPLIT_ALWAYS
;
2627 /* setup rx buffer for FCoE */
2628 if ((vsi
->type
== I40E_VSI_FCOE
) &&
2629 (vsi
->back
->flags
& I40E_FLAG_FCOE_ENABLED
)) {
2630 vsi
->rx_hdr_len
= 0;
2631 vsi
->rx_buf_len
= I40E_RXBUFFER_3072
;
2632 vsi
->max_frame
= I40E_RXBUFFER_3072
;
2633 vsi
->dtype
= I40E_RX_DTYPE_NO_SPLIT
;
2636 #endif /* I40E_FCOE */
2637 /* round up for the chip's needs */
2638 vsi
->rx_hdr_len
= ALIGN(vsi
->rx_hdr_len
,
2639 (1 << I40E_RXQ_CTX_HBUFF_SHIFT
));
2640 vsi
->rx_buf_len
= ALIGN(vsi
->rx_buf_len
,
2641 (1 << I40E_RXQ_CTX_DBUFF_SHIFT
));
2643 /* set up individual rings */
2644 for (i
= 0; i
< vsi
->num_queue_pairs
&& !err
; i
++)
2645 err
= i40e_configure_rx_ring(vsi
->rx_rings
[i
]);
2651 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
2652 * @vsi: ptr to the VSI
2654 static void i40e_vsi_config_dcb_rings(struct i40e_vsi
*vsi
)
2656 struct i40e_ring
*tx_ring
, *rx_ring
;
2657 u16 qoffset
, qcount
;
2660 if (!(vsi
->back
->flags
& I40E_FLAG_DCB_ENABLED
))
2663 for (n
= 0; n
< I40E_MAX_TRAFFIC_CLASS
; n
++) {
2664 if (!(vsi
->tc_config
.enabled_tc
& (1 << n
)))
2667 qoffset
= vsi
->tc_config
.tc_info
[n
].qoffset
;
2668 qcount
= vsi
->tc_config
.tc_info
[n
].qcount
;
2669 for (i
= qoffset
; i
< (qoffset
+ qcount
); i
++) {
2670 rx_ring
= vsi
->rx_rings
[i
];
2671 tx_ring
= vsi
->tx_rings
[i
];
2672 rx_ring
->dcb_tc
= n
;
2673 tx_ring
->dcb_tc
= n
;
2679 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
2680 * @vsi: ptr to the VSI
2682 static void i40e_set_vsi_rx_mode(struct i40e_vsi
*vsi
)
2685 i40e_set_rx_mode(vsi
->netdev
);
2689 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
2690 * @vsi: Pointer to the targeted VSI
2692 * This function replays the hlist on the hw where all the SB Flow Director
2693 * filters were saved.
2695 static void i40e_fdir_filter_restore(struct i40e_vsi
*vsi
)
2697 struct i40e_fdir_filter
*filter
;
2698 struct i40e_pf
*pf
= vsi
->back
;
2699 struct hlist_node
*node
;
2701 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
2704 hlist_for_each_entry_safe(filter
, node
,
2705 &pf
->fdir_filter_list
, fdir_node
) {
2706 i40e_add_del_fdir(vsi
, filter
, true);
2711 * i40e_vsi_configure - Set up the VSI for action
2712 * @vsi: the VSI being configured
2714 static int i40e_vsi_configure(struct i40e_vsi
*vsi
)
2718 i40e_set_vsi_rx_mode(vsi
);
2719 i40e_restore_vlan(vsi
);
2720 i40e_vsi_config_dcb_rings(vsi
);
2721 err
= i40e_vsi_configure_tx(vsi
);
2723 err
= i40e_vsi_configure_rx(vsi
);
2729 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
2730 * @vsi: the VSI being configured
2732 static void i40e_vsi_configure_msix(struct i40e_vsi
*vsi
)
2734 struct i40e_pf
*pf
= vsi
->back
;
2735 struct i40e_q_vector
*q_vector
;
2736 struct i40e_hw
*hw
= &pf
->hw
;
2742 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
2743 * and PFINT_LNKLSTn registers, e.g.:
2744 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
2746 qp
= vsi
->base_queue
;
2747 vector
= vsi
->base_vector
;
2748 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vector
++) {
2749 q_vector
= vsi
->q_vectors
[i
];
2750 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
2751 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
2752 wr32(hw
, I40E_PFINT_ITRN(I40E_RX_ITR
, vector
- 1),
2754 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
2755 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
2756 wr32(hw
, I40E_PFINT_ITRN(I40E_TX_ITR
, vector
- 1),
2759 /* Linked list for the queuepairs assigned to this vector */
2760 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), qp
);
2761 for (q
= 0; q
< q_vector
->num_ringpairs
; q
++) {
2762 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
2763 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
2764 (vector
<< I40E_QINT_RQCTL_MSIX_INDX_SHIFT
) |
2765 (qp
<< I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT
)|
2767 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT
);
2769 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
2771 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
2772 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
2773 (vector
<< I40E_QINT_TQCTL_MSIX_INDX_SHIFT
) |
2774 ((qp
+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
)|
2776 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
2778 /* Terminate the linked list */
2779 if (q
== (q_vector
->num_ringpairs
- 1))
2780 val
|= (I40E_QUEUE_END_OF_LIST
2781 << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
2783 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
2792 * i40e_enable_misc_int_causes - enable the non-queue interrupts
2793 * @hw: ptr to the hardware info
2795 static void i40e_enable_misc_int_causes(struct i40e_hw
*hw
)
2799 /* clear things first */
2800 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0); /* disable all */
2801 rd32(hw
, I40E_PFINT_ICR0
); /* read to clear */
2803 val
= I40E_PFINT_ICR0_ENA_ECC_ERR_MASK
|
2804 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
|
2805 I40E_PFINT_ICR0_ENA_GRST_MASK
|
2806 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK
|
2807 I40E_PFINT_ICR0_ENA_GPIO_MASK
|
2808 I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
|
2809 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK
|
2810 I40E_PFINT_ICR0_ENA_VFLR_MASK
|
2811 I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
2813 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
2815 /* SW_ITR_IDX = 0, but don't change INTENA */
2816 wr32(hw
, I40E_PFINT_DYN_CTL0
, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK
|
2817 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK
);
2819 /* OTHER_ITR_IDX = 0 */
2820 wr32(hw
, I40E_PFINT_STAT_CTL0
, 0);
2824 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
2825 * @vsi: the VSI being configured
2827 static void i40e_configure_msi_and_legacy(struct i40e_vsi
*vsi
)
2829 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[0];
2830 struct i40e_pf
*pf
= vsi
->back
;
2831 struct i40e_hw
*hw
= &pf
->hw
;
2834 /* set the ITR configuration */
2835 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
2836 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
2837 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), q_vector
->rx
.itr
);
2838 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
2839 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
2840 wr32(hw
, I40E_PFINT_ITR0(I40E_TX_ITR
), q_vector
->tx
.itr
);
2842 i40e_enable_misc_int_causes(hw
);
2844 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
2845 wr32(hw
, I40E_PFINT_LNKLST0
, 0);
2847 /* Associate the queue pair to the vector and enable the queue int */
2848 val
= I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
2849 (I40E_RX_ITR
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
) |
2850 (I40E_QUEUE_TYPE_TX
<< I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT
);
2852 wr32(hw
, I40E_QINT_RQCTL(0), val
);
2854 val
= I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
2855 (I40E_TX_ITR
<< I40E_QINT_TQCTL_ITR_INDX_SHIFT
) |
2856 (I40E_QUEUE_END_OF_LIST
<< I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
);
2858 wr32(hw
, I40E_QINT_TQCTL(0), val
);
2863 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
2864 * @pf: board private structure
2866 void i40e_irq_dynamic_disable_icr0(struct i40e_pf
*pf
)
2868 struct i40e_hw
*hw
= &pf
->hw
;
2870 wr32(hw
, I40E_PFINT_DYN_CTL0
,
2871 I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
);
2876 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
2877 * @pf: board private structure
2879 void i40e_irq_dynamic_enable_icr0(struct i40e_pf
*pf
)
2881 struct i40e_hw
*hw
= &pf
->hw
;
2884 val
= I40E_PFINT_DYN_CTL0_INTENA_MASK
|
2885 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK
|
2886 (I40E_ITR_NONE
<< I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT
);
2888 wr32(hw
, I40E_PFINT_DYN_CTL0
, val
);
2893 * i40e_irq_dynamic_enable - Enable default interrupt generation settings
2894 * @vsi: pointer to a vsi
2895 * @vector: enable a particular Hw Interrupt vector
2897 void i40e_irq_dynamic_enable(struct i40e_vsi
*vsi
, int vector
)
2899 struct i40e_pf
*pf
= vsi
->back
;
2900 struct i40e_hw
*hw
= &pf
->hw
;
2903 val
= I40E_PFINT_DYN_CTLN_INTENA_MASK
|
2904 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK
|
2905 (I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
);
2906 wr32(hw
, I40E_PFINT_DYN_CTLN(vector
- 1), val
);
2907 /* skip the flush */
2911 * i40e_irq_dynamic_disable - Disable default interrupt generation settings
2912 * @vsi: pointer to a vsi
2913 * @vector: enable a particular Hw Interrupt vector
2915 void i40e_irq_dynamic_disable(struct i40e_vsi
*vsi
, int vector
)
2917 struct i40e_pf
*pf
= vsi
->back
;
2918 struct i40e_hw
*hw
= &pf
->hw
;
2921 val
= I40E_ITR_NONE
<< I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT
;
2922 wr32(hw
, I40E_PFINT_DYN_CTLN(vector
- 1), val
);
2927 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
2928 * @irq: interrupt number
2929 * @data: pointer to a q_vector
2931 static irqreturn_t
i40e_msix_clean_rings(int irq
, void *data
)
2933 struct i40e_q_vector
*q_vector
= data
;
2935 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
2938 napi_schedule(&q_vector
->napi
);
2944 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
2945 * @vsi: the VSI being configured
2946 * @basename: name for the vector
2948 * Allocates MSI-X vectors and requests interrupts from the kernel.
2950 static int i40e_vsi_request_irq_msix(struct i40e_vsi
*vsi
, char *basename
)
2952 int q_vectors
= vsi
->num_q_vectors
;
2953 struct i40e_pf
*pf
= vsi
->back
;
2954 int base
= vsi
->base_vector
;
2959 for (vector
= 0; vector
< q_vectors
; vector
++) {
2960 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[vector
];
2962 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
2963 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2964 "%s-%s-%d", basename
, "TxRx", rx_int_idx
++);
2966 } else if (q_vector
->rx
.ring
) {
2967 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2968 "%s-%s-%d", basename
, "rx", rx_int_idx
++);
2969 } else if (q_vector
->tx
.ring
) {
2970 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2971 "%s-%s-%d", basename
, "tx", tx_int_idx
++);
2973 /* skip this unused q_vector */
2976 err
= request_irq(pf
->msix_entries
[base
+ vector
].vector
,
2982 dev_info(&pf
->pdev
->dev
,
2983 "%s: request_irq failed, error: %d\n",
2985 goto free_queue_irqs
;
2987 /* assign the mask for this irq */
2988 irq_set_affinity_hint(pf
->msix_entries
[base
+ vector
].vector
,
2989 &q_vector
->affinity_mask
);
2992 vsi
->irqs_ready
= true;
2998 irq_set_affinity_hint(pf
->msix_entries
[base
+ vector
].vector
,
3000 free_irq(pf
->msix_entries
[base
+ vector
].vector
,
3001 &(vsi
->q_vectors
[vector
]));
3007 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3008 * @vsi: the VSI being un-configured
3010 static void i40e_vsi_disable_irq(struct i40e_vsi
*vsi
)
3012 struct i40e_pf
*pf
= vsi
->back
;
3013 struct i40e_hw
*hw
= &pf
->hw
;
3014 int base
= vsi
->base_vector
;
3017 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
3018 wr32(hw
, I40E_QINT_TQCTL(vsi
->tx_rings
[i
]->reg_idx
), 0);
3019 wr32(hw
, I40E_QINT_RQCTL(vsi
->rx_rings
[i
]->reg_idx
), 0);
3022 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3023 for (i
= vsi
->base_vector
;
3024 i
< (vsi
->num_q_vectors
+ vsi
->base_vector
); i
++)
3025 wr32(hw
, I40E_PFINT_DYN_CTLN(i
- 1), 0);
3028 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3029 synchronize_irq(pf
->msix_entries
[i
+ base
].vector
);
3031 /* Legacy and MSI mode - this stops all interrupt handling */
3032 wr32(hw
, I40E_PFINT_ICR0_ENA
, 0);
3033 wr32(hw
, I40E_PFINT_DYN_CTL0
, 0);
3035 synchronize_irq(pf
->pdev
->irq
);
3040 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3041 * @vsi: the VSI being configured
3043 static int i40e_vsi_enable_irq(struct i40e_vsi
*vsi
)
3045 struct i40e_pf
*pf
= vsi
->back
;
3048 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3049 for (i
= vsi
->base_vector
;
3050 i
< (vsi
->num_q_vectors
+ vsi
->base_vector
); i
++)
3051 i40e_irq_dynamic_enable(vsi
, i
);
3053 i40e_irq_dynamic_enable_icr0(pf
);
3056 i40e_flush(&pf
->hw
);
3061 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
3062 * @pf: board private structure
3064 static void i40e_stop_misc_vector(struct i40e_pf
*pf
)
3067 wr32(&pf
->hw
, I40E_PFINT_ICR0_ENA
, 0);
3068 i40e_flush(&pf
->hw
);
3072 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3073 * @irq: interrupt number
3074 * @data: pointer to a q_vector
3076 * This is the handler used for all MSI/Legacy interrupts, and deals
3077 * with both queue and non-queue interrupts. This is also used in
3078 * MSIX mode to handle the non-queue interrupts.
3080 static irqreturn_t
i40e_intr(int irq
, void *data
)
3082 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
3083 struct i40e_hw
*hw
= &pf
->hw
;
3084 irqreturn_t ret
= IRQ_NONE
;
3085 u32 icr0
, icr0_remaining
;
3088 icr0
= rd32(hw
, I40E_PFINT_ICR0
);
3089 ena_mask
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
3091 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
3092 if ((icr0
& I40E_PFINT_ICR0_INTEVENT_MASK
) == 0)
3095 /* if interrupt but no bits showing, must be SWINT */
3096 if (((icr0
& ~I40E_PFINT_ICR0_INTEVENT_MASK
) == 0) ||
3097 (icr0
& I40E_PFINT_ICR0_SWINT_MASK
))
3100 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
3101 if (icr0
& I40E_PFINT_ICR0_QUEUE_0_MASK
) {
3103 /* temporarily disable queue cause for NAPI processing */
3104 u32 qval
= rd32(hw
, I40E_QINT_RQCTL(0));
3105 qval
&= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK
;
3106 wr32(hw
, I40E_QINT_RQCTL(0), qval
);
3108 qval
= rd32(hw
, I40E_QINT_TQCTL(0));
3109 qval
&= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK
;
3110 wr32(hw
, I40E_QINT_TQCTL(0), qval
);
3112 if (!test_bit(__I40E_DOWN
, &pf
->state
))
3113 napi_schedule(&pf
->vsi
[pf
->lan_vsi
]->q_vectors
[0]->napi
);
3116 if (icr0
& I40E_PFINT_ICR0_ADMINQ_MASK
) {
3117 ena_mask
&= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
3118 set_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
);
3121 if (icr0
& I40E_PFINT_ICR0_MAL_DETECT_MASK
) {
3122 ena_mask
&= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
3123 set_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
);
3126 if (icr0
& I40E_PFINT_ICR0_VFLR_MASK
) {
3127 ena_mask
&= ~I40E_PFINT_ICR0_ENA_VFLR_MASK
;
3128 set_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
);
3131 if (icr0
& I40E_PFINT_ICR0_GRST_MASK
) {
3132 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
))
3133 set_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
);
3134 ena_mask
&= ~I40E_PFINT_ICR0_ENA_GRST_MASK
;
3135 val
= rd32(hw
, I40E_GLGEN_RSTAT
);
3136 val
= (val
& I40E_GLGEN_RSTAT_RESET_TYPE_MASK
)
3137 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT
;
3138 if (val
== I40E_RESET_CORER
) {
3140 } else if (val
== I40E_RESET_GLOBR
) {
3142 } else if (val
== I40E_RESET_EMPR
) {
3144 set_bit(__I40E_EMP_RESET_REQUESTED
, &pf
->state
);
3148 if (icr0
& I40E_PFINT_ICR0_HMC_ERR_MASK
) {
3149 icr0
&= ~I40E_PFINT_ICR0_HMC_ERR_MASK
;
3150 dev_info(&pf
->pdev
->dev
, "HMC error interrupt\n");
3153 if (icr0
& I40E_PFINT_ICR0_TIMESYNC_MASK
) {
3154 u32 prttsyn_stat
= rd32(hw
, I40E_PRTTSYN_STAT_0
);
3156 if (prttsyn_stat
& I40E_PRTTSYN_STAT_0_TXTIME_MASK
) {
3157 icr0
&= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK
;
3158 i40e_ptp_tx_hwtstamp(pf
);
3162 /* If a critical error is pending we have no choice but to reset the
3164 * Report and mask out any remaining unexpected interrupts.
3166 icr0_remaining
= icr0
& ena_mask
;
3167 if (icr0_remaining
) {
3168 dev_info(&pf
->pdev
->dev
, "unhandled interrupt icr0=0x%08x\n",
3170 if ((icr0_remaining
& I40E_PFINT_ICR0_PE_CRITERR_MASK
) ||
3171 (icr0_remaining
& I40E_PFINT_ICR0_PCI_EXCEPTION_MASK
) ||
3172 (icr0_remaining
& I40E_PFINT_ICR0_ECC_ERR_MASK
)) {
3173 dev_info(&pf
->pdev
->dev
, "device will be reset\n");
3174 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
3175 i40e_service_event_schedule(pf
);
3177 ena_mask
&= ~icr0_remaining
;
3182 /* re-enable interrupt causes */
3183 wr32(hw
, I40E_PFINT_ICR0_ENA
, ena_mask
);
3184 if (!test_bit(__I40E_DOWN
, &pf
->state
)) {
3185 i40e_service_event_schedule(pf
);
3186 i40e_irq_dynamic_enable_icr0(pf
);
3193 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3194 * @tx_ring: tx ring to clean
3195 * @budget: how many cleans we're allowed
3197 * Returns true if there's any budget left (e.g. the clean is finished)
3199 static bool i40e_clean_fdir_tx_irq(struct i40e_ring
*tx_ring
, int budget
)
3201 struct i40e_vsi
*vsi
= tx_ring
->vsi
;
3202 u16 i
= tx_ring
->next_to_clean
;
3203 struct i40e_tx_buffer
*tx_buf
;
3204 struct i40e_tx_desc
*tx_desc
;
3206 tx_buf
= &tx_ring
->tx_bi
[i
];
3207 tx_desc
= I40E_TX_DESC(tx_ring
, i
);
3208 i
-= tx_ring
->count
;
3211 struct i40e_tx_desc
*eop_desc
= tx_buf
->next_to_watch
;
3213 /* if next_to_watch is not set then there is no work pending */
3217 /* prevent any other reads prior to eop_desc */
3218 read_barrier_depends();
3220 /* if the descriptor isn't done, no work yet to do */
3221 if (!(eop_desc
->cmd_type_offset_bsz
&
3222 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE
)))
3225 /* clear next_to_watch to prevent false hangs */
3226 tx_buf
->next_to_watch
= NULL
;
3228 tx_desc
->buffer_addr
= 0;
3229 tx_desc
->cmd_type_offset_bsz
= 0;
3230 /* move past filter desc */
3235 i
-= tx_ring
->count
;
3236 tx_buf
= tx_ring
->tx_bi
;
3237 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
3239 /* unmap skb header data */
3240 dma_unmap_single(tx_ring
->dev
,
3241 dma_unmap_addr(tx_buf
, dma
),
3242 dma_unmap_len(tx_buf
, len
),
3244 if (tx_buf
->tx_flags
& I40E_TX_FLAGS_FD_SB
)
3245 kfree(tx_buf
->raw_buf
);
3247 tx_buf
->raw_buf
= NULL
;
3248 tx_buf
->tx_flags
= 0;
3249 tx_buf
->next_to_watch
= NULL
;
3250 dma_unmap_len_set(tx_buf
, len
, 0);
3251 tx_desc
->buffer_addr
= 0;
3252 tx_desc
->cmd_type_offset_bsz
= 0;
3254 /* move us past the eop_desc for start of next FD desc */
3259 i
-= tx_ring
->count
;
3260 tx_buf
= tx_ring
->tx_bi
;
3261 tx_desc
= I40E_TX_DESC(tx_ring
, 0);
3264 /* update budget accounting */
3266 } while (likely(budget
));
3268 i
+= tx_ring
->count
;
3269 tx_ring
->next_to_clean
= i
;
3271 if (vsi
->back
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3272 i40e_irq_dynamic_enable(vsi
,
3273 tx_ring
->q_vector
->v_idx
+ vsi
->base_vector
);
3279 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
3280 * @irq: interrupt number
3281 * @data: pointer to a q_vector
3283 static irqreturn_t
i40e_fdir_clean_ring(int irq
, void *data
)
3285 struct i40e_q_vector
*q_vector
= data
;
3286 struct i40e_vsi
*vsi
;
3288 if (!q_vector
->tx
.ring
)
3291 vsi
= q_vector
->tx
.ring
->vsi
;
3292 i40e_clean_fdir_tx_irq(q_vector
->tx
.ring
, vsi
->work_limit
);
3298 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
3299 * @vsi: the VSI being configured
3300 * @v_idx: vector index
3301 * @qp_idx: queue pair index
3303 static void map_vector_to_qp(struct i40e_vsi
*vsi
, int v_idx
, int qp_idx
)
3305 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
3306 struct i40e_ring
*tx_ring
= vsi
->tx_rings
[qp_idx
];
3307 struct i40e_ring
*rx_ring
= vsi
->rx_rings
[qp_idx
];
3309 tx_ring
->q_vector
= q_vector
;
3310 tx_ring
->next
= q_vector
->tx
.ring
;
3311 q_vector
->tx
.ring
= tx_ring
;
3312 q_vector
->tx
.count
++;
3314 rx_ring
->q_vector
= q_vector
;
3315 rx_ring
->next
= q_vector
->rx
.ring
;
3316 q_vector
->rx
.ring
= rx_ring
;
3317 q_vector
->rx
.count
++;
3321 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
3322 * @vsi: the VSI being configured
3324 * This function maps descriptor rings to the queue-specific vectors
3325 * we were allotted through the MSI-X enabling code. Ideally, we'd have
3326 * one vector per queue pair, but on a constrained vector budget, we
3327 * group the queue pairs as "efficiently" as possible.
3329 static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi
*vsi
)
3331 int qp_remaining
= vsi
->num_queue_pairs
;
3332 int q_vectors
= vsi
->num_q_vectors
;
3337 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
3338 * group them so there are multiple queues per vector.
3339 * It is also important to go through all the vectors available to be
3340 * sure that if we don't use all the vectors, that the remaining vectors
3341 * are cleared. This is especially important when decreasing the
3342 * number of queues in use.
3344 for (; v_start
< q_vectors
; v_start
++) {
3345 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_start
];
3347 num_ringpairs
= DIV_ROUND_UP(qp_remaining
, q_vectors
- v_start
);
3349 q_vector
->num_ringpairs
= num_ringpairs
;
3351 q_vector
->rx
.count
= 0;
3352 q_vector
->tx
.count
= 0;
3353 q_vector
->rx
.ring
= NULL
;
3354 q_vector
->tx
.ring
= NULL
;
3356 while (num_ringpairs
--) {
3357 map_vector_to_qp(vsi
, v_start
, qp_idx
);
3365 * i40e_vsi_request_irq - Request IRQ from the OS
3366 * @vsi: the VSI being configured
3367 * @basename: name for the vector
3369 static int i40e_vsi_request_irq(struct i40e_vsi
*vsi
, char *basename
)
3371 struct i40e_pf
*pf
= vsi
->back
;
3374 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
3375 err
= i40e_vsi_request_irq_msix(vsi
, basename
);
3376 else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
)
3377 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, 0,
3378 pf
->misc_int_name
, pf
);
3380 err
= request_irq(pf
->pdev
->irq
, i40e_intr
, IRQF_SHARED
,
3381 pf
->misc_int_name
, pf
);
3384 dev_info(&pf
->pdev
->dev
, "request_irq failed, Error %d\n", err
);
3389 #ifdef CONFIG_NET_POLL_CONTROLLER
3391 * i40e_netpoll - A Polling 'interrupt'handler
3392 * @netdev: network interface device structure
3394 * This is used by netconsole to send skbs without having to re-enable
3395 * interrupts. It's not called while the normal interrupt routine is executing.
3398 void i40e_netpoll(struct net_device
*netdev
)
3400 static void i40e_netpoll(struct net_device
*netdev
)
3403 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3404 struct i40e_vsi
*vsi
= np
->vsi
;
3405 struct i40e_pf
*pf
= vsi
->back
;
3408 /* if interface is down do nothing */
3409 if (test_bit(__I40E_DOWN
, &vsi
->state
))
3412 pf
->flags
|= I40E_FLAG_IN_NETPOLL
;
3413 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3414 for (i
= 0; i
< vsi
->num_q_vectors
; i
++)
3415 i40e_msix_clean_rings(0, vsi
->q_vectors
[i
]);
3417 i40e_intr(pf
->pdev
->irq
, netdev
);
3419 pf
->flags
&= ~I40E_FLAG_IN_NETPOLL
;
3424 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
3425 * @pf: the PF being configured
3426 * @pf_q: the PF queue
3427 * @enable: enable or disable state of the queue
3429 * This routine will wait for the given Tx queue of the PF to reach the
3430 * enabled or disabled state.
3431 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3432 * multiple retries; else will return 0 in case of success.
3434 static int i40e_pf_txq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
3439 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
3440 tx_reg
= rd32(&pf
->hw
, I40E_QTX_ENA(pf_q
));
3441 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
3444 usleep_range(10, 20);
3446 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
3453 * i40e_vsi_control_tx - Start or stop a VSI's rings
3454 * @vsi: the VSI being configured
3455 * @enable: start or stop the rings
3457 static int i40e_vsi_control_tx(struct i40e_vsi
*vsi
, bool enable
)
3459 struct i40e_pf
*pf
= vsi
->back
;
3460 struct i40e_hw
*hw
= &pf
->hw
;
3461 int i
, j
, pf_q
, ret
= 0;
3464 pf_q
= vsi
->base_queue
;
3465 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
3467 /* warn the TX unit of coming changes */
3468 i40e_pre_tx_queue_cfg(&pf
->hw
, pf_q
, enable
);
3470 usleep_range(10, 20);
3472 for (j
= 0; j
< 50; j
++) {
3473 tx_reg
= rd32(hw
, I40E_QTX_ENA(pf_q
));
3474 if (((tx_reg
>> I40E_QTX_ENA_QENA_REQ_SHIFT
) & 1) ==
3475 ((tx_reg
>> I40E_QTX_ENA_QENA_STAT_SHIFT
) & 1))
3477 usleep_range(1000, 2000);
3479 /* Skip if the queue is already in the requested state */
3480 if (enable
== !!(tx_reg
& I40E_QTX_ENA_QENA_STAT_MASK
))
3483 /* turn on/off the queue */
3485 wr32(hw
, I40E_QTX_HEAD(pf_q
), 0);
3486 tx_reg
|= I40E_QTX_ENA_QENA_REQ_MASK
;
3488 tx_reg
&= ~I40E_QTX_ENA_QENA_REQ_MASK
;
3491 wr32(hw
, I40E_QTX_ENA(pf_q
), tx_reg
);
3493 /* wait for the change to finish */
3494 ret
= i40e_pf_txq_wait(pf
, pf_q
, enable
);
3496 dev_info(&pf
->pdev
->dev
,
3497 "%s: VSI seid %d Tx ring %d %sable timeout\n",
3498 __func__
, vsi
->seid
, pf_q
,
3499 (enable
? "en" : "dis"));
3504 if (hw
->revision_id
== 0)
3510 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
3511 * @pf: the PF being configured
3512 * @pf_q: the PF queue
3513 * @enable: enable or disable state of the queue
3515 * This routine will wait for the given Rx queue of the PF to reach the
3516 * enabled or disabled state.
3517 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3518 * multiple retries; else will return 0 in case of success.
3520 static int i40e_pf_rxq_wait(struct i40e_pf
*pf
, int pf_q
, bool enable
)
3525 for (i
= 0; i
< I40E_QUEUE_WAIT_RETRY_LIMIT
; i
++) {
3526 rx_reg
= rd32(&pf
->hw
, I40E_QRX_ENA(pf_q
));
3527 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
3530 usleep_range(10, 20);
3532 if (i
>= I40E_QUEUE_WAIT_RETRY_LIMIT
)
3539 * i40e_vsi_control_rx - Start or stop a VSI's rings
3540 * @vsi: the VSI being configured
3541 * @enable: start or stop the rings
3543 static int i40e_vsi_control_rx(struct i40e_vsi
*vsi
, bool enable
)
3545 struct i40e_pf
*pf
= vsi
->back
;
3546 struct i40e_hw
*hw
= &pf
->hw
;
3547 int i
, j
, pf_q
, ret
= 0;
3550 pf_q
= vsi
->base_queue
;
3551 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++, pf_q
++) {
3552 for (j
= 0; j
< 50; j
++) {
3553 rx_reg
= rd32(hw
, I40E_QRX_ENA(pf_q
));
3554 if (((rx_reg
>> I40E_QRX_ENA_QENA_REQ_SHIFT
) & 1) ==
3555 ((rx_reg
>> I40E_QRX_ENA_QENA_STAT_SHIFT
) & 1))
3557 usleep_range(1000, 2000);
3560 /* Skip if the queue is already in the requested state */
3561 if (enable
== !!(rx_reg
& I40E_QRX_ENA_QENA_STAT_MASK
))
3564 /* turn on/off the queue */
3566 rx_reg
|= I40E_QRX_ENA_QENA_REQ_MASK
;
3568 rx_reg
&= ~I40E_QRX_ENA_QENA_REQ_MASK
;
3569 wr32(hw
, I40E_QRX_ENA(pf_q
), rx_reg
);
3571 /* wait for the change to finish */
3572 ret
= i40e_pf_rxq_wait(pf
, pf_q
, enable
);
3574 dev_info(&pf
->pdev
->dev
,
3575 "%s: VSI seid %d Rx ring %d %sable timeout\n",
3576 __func__
, vsi
->seid
, pf_q
,
3577 (enable
? "en" : "dis"));
3586 * i40e_vsi_control_rings - Start or stop a VSI's rings
3587 * @vsi: the VSI being configured
3588 * @enable: start or stop the rings
3590 int i40e_vsi_control_rings(struct i40e_vsi
*vsi
, bool request
)
3594 /* do rx first for enable and last for disable */
3596 ret
= i40e_vsi_control_rx(vsi
, request
);
3599 ret
= i40e_vsi_control_tx(vsi
, request
);
3601 /* Ignore return value, we need to shutdown whatever we can */
3602 i40e_vsi_control_tx(vsi
, request
);
3603 i40e_vsi_control_rx(vsi
, request
);
3610 * i40e_vsi_free_irq - Free the irq association with the OS
3611 * @vsi: the VSI being configured
3613 static void i40e_vsi_free_irq(struct i40e_vsi
*vsi
)
3615 struct i40e_pf
*pf
= vsi
->back
;
3616 struct i40e_hw
*hw
= &pf
->hw
;
3617 int base
= vsi
->base_vector
;
3621 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3622 if (!vsi
->q_vectors
)
3625 if (!vsi
->irqs_ready
)
3628 vsi
->irqs_ready
= false;
3629 for (i
= 0; i
< vsi
->num_q_vectors
; i
++) {
3630 u16 vector
= i
+ base
;
3632 /* free only the irqs that were actually requested */
3633 if (!vsi
->q_vectors
[i
] ||
3634 !vsi
->q_vectors
[i
]->num_ringpairs
)
3637 /* clear the affinity_mask in the IRQ descriptor */
3638 irq_set_affinity_hint(pf
->msix_entries
[vector
].vector
,
3640 free_irq(pf
->msix_entries
[vector
].vector
,
3643 /* Tear down the interrupt queue link list
3645 * We know that they come in pairs and always
3646 * the Rx first, then the Tx. To clear the
3647 * link list, stick the EOL value into the
3648 * next_q field of the registers.
3650 val
= rd32(hw
, I40E_PFINT_LNKLSTN(vector
- 1));
3651 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
3652 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
3653 val
|= I40E_QUEUE_END_OF_LIST
3654 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
3655 wr32(hw
, I40E_PFINT_LNKLSTN(vector
- 1), val
);
3657 while (qp
!= I40E_QUEUE_END_OF_LIST
) {
3660 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
3662 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
3663 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
3664 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3665 I40E_QINT_RQCTL_INTEVENT_MASK
);
3667 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
3668 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
3670 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
3672 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
3674 next
= (val
& I40E_QINT_TQCTL_NEXTQ_INDX_MASK
)
3675 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT
;
3677 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
3678 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
3679 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3680 I40E_QINT_TQCTL_INTEVENT_MASK
);
3682 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
3683 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
3685 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
3690 free_irq(pf
->pdev
->irq
, pf
);
3692 val
= rd32(hw
, I40E_PFINT_LNKLST0
);
3693 qp
= (val
& I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK
)
3694 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT
;
3695 val
|= I40E_QUEUE_END_OF_LIST
3696 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT
;
3697 wr32(hw
, I40E_PFINT_LNKLST0
, val
);
3699 val
= rd32(hw
, I40E_QINT_RQCTL(qp
));
3700 val
&= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK
|
3701 I40E_QINT_RQCTL_MSIX0_INDX_MASK
|
3702 I40E_QINT_RQCTL_CAUSE_ENA_MASK
|
3703 I40E_QINT_RQCTL_INTEVENT_MASK
);
3705 val
|= (I40E_QINT_RQCTL_ITR_INDX_MASK
|
3706 I40E_QINT_RQCTL_NEXTQ_INDX_MASK
);
3708 wr32(hw
, I40E_QINT_RQCTL(qp
), val
);
3710 val
= rd32(hw
, I40E_QINT_TQCTL(qp
));
3712 val
&= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK
|
3713 I40E_QINT_TQCTL_MSIX0_INDX_MASK
|
3714 I40E_QINT_TQCTL_CAUSE_ENA_MASK
|
3715 I40E_QINT_TQCTL_INTEVENT_MASK
);
3717 val
|= (I40E_QINT_TQCTL_ITR_INDX_MASK
|
3718 I40E_QINT_TQCTL_NEXTQ_INDX_MASK
);
3720 wr32(hw
, I40E_QINT_TQCTL(qp
), val
);
3725 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
3726 * @vsi: the VSI being configured
3727 * @v_idx: Index of vector to be freed
3729 * This function frees the memory allocated to the q_vector. In addition if
3730 * NAPI is enabled it will delete any references to the NAPI struct prior
3731 * to freeing the q_vector.
3733 static void i40e_free_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
3735 struct i40e_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
3736 struct i40e_ring
*ring
;
3741 /* disassociate q_vector from rings */
3742 i40e_for_each_ring(ring
, q_vector
->tx
)
3743 ring
->q_vector
= NULL
;
3745 i40e_for_each_ring(ring
, q_vector
->rx
)
3746 ring
->q_vector
= NULL
;
3748 /* only VSI w/ an associated netdev is set up w/ NAPI */
3750 netif_napi_del(&q_vector
->napi
);
3752 vsi
->q_vectors
[v_idx
] = NULL
;
3754 kfree_rcu(q_vector
, rcu
);
3758 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
3759 * @vsi: the VSI being un-configured
3761 * This frees the memory allocated to the q_vectors and
3762 * deletes references to the NAPI struct.
3764 static void i40e_vsi_free_q_vectors(struct i40e_vsi
*vsi
)
3768 for (v_idx
= 0; v_idx
< vsi
->num_q_vectors
; v_idx
++)
3769 i40e_free_q_vector(vsi
, v_idx
);
3773 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
3774 * @pf: board private structure
3776 static void i40e_reset_interrupt_capability(struct i40e_pf
*pf
)
3778 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
3779 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
3780 pci_disable_msix(pf
->pdev
);
3781 kfree(pf
->msix_entries
);
3782 pf
->msix_entries
= NULL
;
3783 } else if (pf
->flags
& I40E_FLAG_MSI_ENABLED
) {
3784 pci_disable_msi(pf
->pdev
);
3786 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
);
3790 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
3791 * @pf: board private structure
3793 * We go through and clear interrupt specific resources and reset the structure
3794 * to pre-load conditions
3796 static void i40e_clear_interrupt_scheme(struct i40e_pf
*pf
)
3800 i40e_put_lump(pf
->irq_pile
, 0, I40E_PILE_VALID_BIT
-1);
3801 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
3803 i40e_vsi_free_q_vectors(pf
->vsi
[i
]);
3804 i40e_reset_interrupt_capability(pf
);
3808 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
3809 * @vsi: the VSI being configured
3811 static void i40e_napi_enable_all(struct i40e_vsi
*vsi
)
3818 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++)
3819 napi_enable(&vsi
->q_vectors
[q_idx
]->napi
);
3823 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
3824 * @vsi: the VSI being configured
3826 static void i40e_napi_disable_all(struct i40e_vsi
*vsi
)
3833 for (q_idx
= 0; q_idx
< vsi
->num_q_vectors
; q_idx
++)
3834 napi_disable(&vsi
->q_vectors
[q_idx
]->napi
);
3838 * i40e_vsi_close - Shut down a VSI
3839 * @vsi: the vsi to be quelled
3841 static void i40e_vsi_close(struct i40e_vsi
*vsi
)
3843 if (!test_and_set_bit(__I40E_DOWN
, &vsi
->state
))
3845 i40e_vsi_free_irq(vsi
);
3846 i40e_vsi_free_tx_resources(vsi
);
3847 i40e_vsi_free_rx_resources(vsi
);
3851 * i40e_quiesce_vsi - Pause a given VSI
3852 * @vsi: the VSI being paused
3854 static void i40e_quiesce_vsi(struct i40e_vsi
*vsi
)
3856 if (test_bit(__I40E_DOWN
, &vsi
->state
))
3859 set_bit(__I40E_NEEDS_RESTART
, &vsi
->state
);
3860 if (vsi
->netdev
&& netif_running(vsi
->netdev
)) {
3861 vsi
->netdev
->netdev_ops
->ndo_stop(vsi
->netdev
);
3863 i40e_vsi_close(vsi
);
3868 * i40e_unquiesce_vsi - Resume a given VSI
3869 * @vsi: the VSI being resumed
3871 static void i40e_unquiesce_vsi(struct i40e_vsi
*vsi
)
3873 if (!test_bit(__I40E_NEEDS_RESTART
, &vsi
->state
))
3876 clear_bit(__I40E_NEEDS_RESTART
, &vsi
->state
);
3877 if (vsi
->netdev
&& netif_running(vsi
->netdev
))
3878 vsi
->netdev
->netdev_ops
->ndo_open(vsi
->netdev
);
3880 i40e_vsi_open(vsi
); /* this clears the DOWN bit */
3884 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
3887 static void i40e_pf_quiesce_all_vsi(struct i40e_pf
*pf
)
3891 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
3893 i40e_quiesce_vsi(pf
->vsi
[v
]);
3898 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
3901 static void i40e_pf_unquiesce_all_vsi(struct i40e_pf
*pf
)
3905 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
3907 i40e_unquiesce_vsi(pf
->vsi
[v
]);
3912 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
3913 * @dcbcfg: the corresponding DCBx configuration structure
3915 * Return the number of TCs from given DCBx configuration
3917 static u8
i40e_dcb_get_num_tc(struct i40e_dcbx_config
*dcbcfg
)
3922 /* Scan the ETS Config Priority Table to find
3923 * traffic class enabled for a given priority
3924 * and use the traffic class index to get the
3925 * number of traffic classes enabled
3927 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
3928 if (dcbcfg
->etscfg
.prioritytable
[i
] > num_tc
)
3929 num_tc
= dcbcfg
->etscfg
.prioritytable
[i
];
3932 /* Traffic class index starts from zero so
3933 * increment to return the actual count
3939 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
3940 * @dcbcfg: the corresponding DCBx configuration structure
3942 * Query the current DCB configuration and return the number of
3943 * traffic classes enabled from the given DCBX config
3945 static u8
i40e_dcb_get_enabled_tc(struct i40e_dcbx_config
*dcbcfg
)
3947 u8 num_tc
= i40e_dcb_get_num_tc(dcbcfg
);
3951 for (i
= 0; i
< num_tc
; i
++)
3952 enabled_tc
|= 1 << i
;
3958 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
3959 * @pf: PF being queried
3961 * Return number of traffic classes enabled for the given PF
3963 static u8
i40e_pf_get_num_tc(struct i40e_pf
*pf
)
3965 struct i40e_hw
*hw
= &pf
->hw
;
3968 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
3970 /* If DCB is not enabled then always in single TC */
3971 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
3974 /* MFP mode return count of enabled TCs for this PF */
3975 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
3976 enabled_tc
= pf
->hw
.func_caps
.enabled_tcmap
;
3977 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
3978 if (enabled_tc
& (1 << i
))
3984 /* SFP mode will be enabled for all TCs on port */
3985 return i40e_dcb_get_num_tc(dcbcfg
);
3989 * i40e_pf_get_default_tc - Get bitmap for first enabled TC
3990 * @pf: PF being queried
3992 * Return a bitmap for first enabled traffic class for this PF.
3994 static u8
i40e_pf_get_default_tc(struct i40e_pf
*pf
)
3996 u8 enabled_tc
= pf
->hw
.func_caps
.enabled_tcmap
;
4000 return 0x1; /* TC0 */
4002 /* Find the first enabled TC */
4003 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4004 if (enabled_tc
& (1 << i
))
4012 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
4013 * @pf: PF being queried
4015 * Return a bitmap for enabled traffic classes for this PF.
4017 static u8
i40e_pf_get_tc_map(struct i40e_pf
*pf
)
4019 /* If DCB is not enabled for this PF then just return default TC */
4020 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
))
4021 return i40e_pf_get_default_tc(pf
);
4023 /* MFP mode will have enabled TCs set by FW */
4024 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
)
4025 return pf
->hw
.func_caps
.enabled_tcmap
;
4027 /* SFP mode we want PF to be enabled for all TCs */
4028 return i40e_dcb_get_enabled_tc(&pf
->hw
.local_dcbx_config
);
4032 * i40e_vsi_get_bw_info - Query VSI BW Information
4033 * @vsi: the VSI being queried
4035 * Returns 0 on success, negative value on failure
4037 static int i40e_vsi_get_bw_info(struct i40e_vsi
*vsi
)
4039 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config
= {0};
4040 struct i40e_aqc_query_vsi_bw_config_resp bw_config
= {0};
4041 struct i40e_pf
*pf
= vsi
->back
;
4042 struct i40e_hw
*hw
= &pf
->hw
;
4047 /* Get the VSI level BW configuration */
4048 aq_ret
= i40e_aq_query_vsi_bw_config(hw
, vsi
->seid
, &bw_config
, NULL
);
4050 dev_info(&pf
->pdev
->dev
,
4051 "couldn't get pf vsi bw config, err %d, aq_err %d\n",
4052 aq_ret
, pf
->hw
.aq
.asq_last_status
);
4056 /* Get the VSI level BW configuration per TC */
4057 aq_ret
= i40e_aq_query_vsi_ets_sla_config(hw
, vsi
->seid
, &bw_ets_config
,
4060 dev_info(&pf
->pdev
->dev
,
4061 "couldn't get pf vsi ets bw config, err %d, aq_err %d\n",
4062 aq_ret
, pf
->hw
.aq
.asq_last_status
);
4066 if (bw_config
.tc_valid_bits
!= bw_ets_config
.tc_valid_bits
) {
4067 dev_info(&pf
->pdev
->dev
,
4068 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
4069 bw_config
.tc_valid_bits
,
4070 bw_ets_config
.tc_valid_bits
);
4071 /* Still continuing */
4074 vsi
->bw_limit
= le16_to_cpu(bw_config
.port_bw_limit
);
4075 vsi
->bw_max_quanta
= bw_config
.max_bw
;
4076 tc_bw_max
= le16_to_cpu(bw_ets_config
.tc_bw_max
[0]) |
4077 (le16_to_cpu(bw_ets_config
.tc_bw_max
[1]) << 16);
4078 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4079 vsi
->bw_ets_share_credits
[i
] = bw_ets_config
.share_credits
[i
];
4080 vsi
->bw_ets_limit_credits
[i
] =
4081 le16_to_cpu(bw_ets_config
.credits
[i
]);
4082 /* 3 bits out of 4 for each TC */
4083 vsi
->bw_ets_max_quanta
[i
] = (u8
)((tc_bw_max
>> (i
*4)) & 0x7);
4090 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
4091 * @vsi: the VSI being configured
4092 * @enabled_tc: TC bitmap
4093 * @bw_credits: BW shared credits per TC
4095 * Returns 0 on success, negative value on failure
4097 static int i40e_vsi_configure_bw_alloc(struct i40e_vsi
*vsi
, u8 enabled_tc
,
4100 struct i40e_aqc_configure_vsi_tc_bw_data bw_data
;
4104 bw_data
.tc_valid_bits
= enabled_tc
;
4105 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
4106 bw_data
.tc_bw_credits
[i
] = bw_share
[i
];
4108 aq_ret
= i40e_aq_config_vsi_tc_bw(&vsi
->back
->hw
, vsi
->seid
, &bw_data
,
4111 dev_info(&vsi
->back
->pdev
->dev
,
4112 "AQ command Config VSI BW allocation per TC failed = %d\n",
4113 vsi
->back
->hw
.aq
.asq_last_status
);
4117 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++)
4118 vsi
->info
.qs_handle
[i
] = bw_data
.qs_handles
[i
];
4124 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
4125 * @vsi: the VSI being configured
4126 * @enabled_tc: TC map to be enabled
4129 static void i40e_vsi_config_netdev_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
4131 struct net_device
*netdev
= vsi
->netdev
;
4132 struct i40e_pf
*pf
= vsi
->back
;
4133 struct i40e_hw
*hw
= &pf
->hw
;
4136 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
4142 netdev_reset_tc(netdev
);
4146 /* Set up actual enabled TCs on the VSI */
4147 if (netdev_set_num_tc(netdev
, vsi
->tc_config
.numtc
))
4150 /* set per TC queues for the VSI */
4151 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4152 /* Only set TC queues for enabled tcs
4154 * e.g. For a VSI that has TC0 and TC3 enabled the
4155 * enabled_tc bitmap would be 0x00001001; the driver
4156 * will set the numtc for netdev as 2 that will be
4157 * referenced by the netdev layer as TC 0 and 1.
4159 if (vsi
->tc_config
.enabled_tc
& (1 << i
))
4160 netdev_set_tc_queue(netdev
,
4161 vsi
->tc_config
.tc_info
[i
].netdev_tc
,
4162 vsi
->tc_config
.tc_info
[i
].qcount
,
4163 vsi
->tc_config
.tc_info
[i
].qoffset
);
4166 /* Assign UP2TC map for the VSI */
4167 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
4168 /* Get the actual TC# for the UP */
4169 u8 ets_tc
= dcbcfg
->etscfg
.prioritytable
[i
];
4170 /* Get the mapped netdev TC# for the UP */
4171 netdev_tc
= vsi
->tc_config
.tc_info
[ets_tc
].netdev_tc
;
4172 netdev_set_prio_tc_map(netdev
, i
, netdev_tc
);
4177 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
4178 * @vsi: the VSI being configured
4179 * @ctxt: the ctxt buffer returned from AQ VSI update param command
4181 static void i40e_vsi_update_queue_map(struct i40e_vsi
*vsi
,
4182 struct i40e_vsi_context
*ctxt
)
4184 /* copy just the sections touched not the entire info
4185 * since not all sections are valid as returned by
4188 vsi
->info
.mapping_flags
= ctxt
->info
.mapping_flags
;
4189 memcpy(&vsi
->info
.queue_mapping
,
4190 &ctxt
->info
.queue_mapping
, sizeof(vsi
->info
.queue_mapping
));
4191 memcpy(&vsi
->info
.tc_mapping
, ctxt
->info
.tc_mapping
,
4192 sizeof(vsi
->info
.tc_mapping
));
4196 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
4197 * @vsi: VSI to be configured
4198 * @enabled_tc: TC bitmap
4200 * This configures a particular VSI for TCs that are mapped to the
4201 * given TC bitmap. It uses default bandwidth share for TCs across
4202 * VSIs to configure TC for a particular VSI.
4205 * It is expected that the VSI queues have been quisced before calling
4208 static int i40e_vsi_config_tc(struct i40e_vsi
*vsi
, u8 enabled_tc
)
4210 u8 bw_share
[I40E_MAX_TRAFFIC_CLASS
] = {0};
4211 struct i40e_vsi_context ctxt
;
4215 /* Check if enabled_tc is same as existing or new TCs */
4216 if (vsi
->tc_config
.enabled_tc
== enabled_tc
)
4219 /* Enable ETS TCs with equal BW Share for now across all VSIs */
4220 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4221 if (enabled_tc
& (1 << i
))
4225 ret
= i40e_vsi_configure_bw_alloc(vsi
, enabled_tc
, bw_share
);
4227 dev_info(&vsi
->back
->pdev
->dev
,
4228 "Failed configuring TC map %d for VSI %d\n",
4229 enabled_tc
, vsi
->seid
);
4233 /* Update Queue Pairs Mapping for currently enabled UPs */
4234 ctxt
.seid
= vsi
->seid
;
4235 ctxt
.pf_num
= vsi
->back
->hw
.pf_id
;
4237 ctxt
.uplink_seid
= vsi
->uplink_seid
;
4238 memcpy(&ctxt
.info
, &vsi
->info
, sizeof(vsi
->info
));
4239 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
4241 /* Update the VSI after updating the VSI queue-mapping information */
4242 ret
= i40e_aq_update_vsi_params(&vsi
->back
->hw
, &ctxt
, NULL
);
4244 dev_info(&vsi
->back
->pdev
->dev
,
4245 "update vsi failed, aq_err=%d\n",
4246 vsi
->back
->hw
.aq
.asq_last_status
);
4249 /* update the local VSI info with updated queue map */
4250 i40e_vsi_update_queue_map(vsi
, &ctxt
);
4251 vsi
->info
.valid_sections
= 0;
4253 /* Update current VSI BW information */
4254 ret
= i40e_vsi_get_bw_info(vsi
);
4256 dev_info(&vsi
->back
->pdev
->dev
,
4257 "Failed updating vsi bw info, aq_err=%d\n",
4258 vsi
->back
->hw
.aq
.asq_last_status
);
4262 /* Update the netdev TC setup */
4263 i40e_vsi_config_netdev_tc(vsi
, enabled_tc
);
4269 * i40e_veb_config_tc - Configure TCs for given VEB
4271 * @enabled_tc: TC bitmap
4273 * Configures given TC bitmap for VEB (switching) element
4275 int i40e_veb_config_tc(struct i40e_veb
*veb
, u8 enabled_tc
)
4277 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data
= {0};
4278 struct i40e_pf
*pf
= veb
->pf
;
4282 /* No TCs or already enabled TCs just return */
4283 if (!enabled_tc
|| veb
->enabled_tc
== enabled_tc
)
4286 bw_data
.tc_valid_bits
= enabled_tc
;
4287 /* bw_data.absolute_credits is not set (relative) */
4289 /* Enable ETS TCs with equal BW Share for now */
4290 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
4291 if (enabled_tc
& (1 << i
))
4292 bw_data
.tc_bw_share_credits
[i
] = 1;
4295 ret
= i40e_aq_config_switch_comp_bw_config(&pf
->hw
, veb
->seid
,
4298 dev_info(&pf
->pdev
->dev
,
4299 "veb bw config failed, aq_err=%d\n",
4300 pf
->hw
.aq
.asq_last_status
);
4304 /* Update the BW information */
4305 ret
= i40e_veb_get_bw_info(veb
);
4307 dev_info(&pf
->pdev
->dev
,
4308 "Failed getting veb bw config, aq_err=%d\n",
4309 pf
->hw
.aq
.asq_last_status
);
4316 #ifdef CONFIG_I40E_DCB
4318 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
4321 * Reconfigure VEB/VSIs on a given PF; it is assumed that
4322 * the caller would've quiesce all the VSIs before calling
4325 static void i40e_dcb_reconfigure(struct i40e_pf
*pf
)
4331 /* Enable the TCs available on PF to all VEBs */
4332 tc_map
= i40e_pf_get_tc_map(pf
);
4333 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
4336 ret
= i40e_veb_config_tc(pf
->veb
[v
], tc_map
);
4338 dev_info(&pf
->pdev
->dev
,
4339 "Failed configuring TC for VEB seid=%d\n",
4341 /* Will try to configure as many components */
4345 /* Update each VSI */
4346 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4350 /* - Enable all TCs for the LAN VSI
4352 * - For FCoE VSI only enable the TC configured
4353 * as per the APP TLV
4355 * - For all others keep them at TC0 for now
4357 if (v
== pf
->lan_vsi
)
4358 tc_map
= i40e_pf_get_tc_map(pf
);
4360 tc_map
= i40e_pf_get_default_tc(pf
);
4362 if (pf
->vsi
[v
]->type
== I40E_VSI_FCOE
)
4363 tc_map
= i40e_get_fcoe_tc_map(pf
);
4364 #endif /* #ifdef I40E_FCOE */
4366 ret
= i40e_vsi_config_tc(pf
->vsi
[v
], tc_map
);
4368 dev_info(&pf
->pdev
->dev
,
4369 "Failed configuring TC for VSI seid=%d\n",
4371 /* Will try to configure as many components */
4373 /* Re-configure VSI vectors based on updated TC map */
4374 i40e_vsi_map_rings_to_vectors(pf
->vsi
[v
]);
4375 if (pf
->vsi
[v
]->netdev
)
4376 i40e_dcbnl_set_all(pf
->vsi
[v
]);
4382 * i40e_init_pf_dcb - Initialize DCB configuration
4383 * @pf: PF being configured
4385 * Query the current DCB configuration and cache it
4386 * in the hardware structure
4388 static int i40e_init_pf_dcb(struct i40e_pf
*pf
)
4390 struct i40e_hw
*hw
= &pf
->hw
;
4393 if (pf
->hw
.func_caps
.npar_enable
)
4396 /* Get the initial DCB configuration */
4397 err
= i40e_init_dcb(hw
);
4399 /* Device/Function is not DCBX capable */
4400 if ((!hw
->func_caps
.dcb
) ||
4401 (hw
->dcbx_status
== I40E_DCBX_STATUS_DISABLED
)) {
4402 dev_info(&pf
->pdev
->dev
,
4403 "DCBX offload is not supported or is disabled for this PF.\n");
4405 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
)
4409 /* When status is not DISABLED then DCBX in FW */
4410 pf
->dcbx_cap
= DCB_CAP_DCBX_LLD_MANAGED
|
4411 DCB_CAP_DCBX_VER_IEEE
;
4413 pf
->flags
|= I40E_FLAG_DCB_CAPABLE
;
4414 /* Enable DCB tagging only when more than one TC */
4415 if (i40e_dcb_get_num_tc(&hw
->local_dcbx_config
) > 1)
4416 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
4419 dev_info(&pf
->pdev
->dev
, "AQ Querying DCB configuration failed: %d\n",
4420 pf
->hw
.aq
.asq_last_status
);
4426 #endif /* CONFIG_I40E_DCB */
4427 #define SPEED_SIZE 14
4430 * i40e_print_link_message - print link up or down
4431 * @vsi: the VSI for which link needs a message
4433 static void i40e_print_link_message(struct i40e_vsi
*vsi
, bool isup
)
4435 char speed
[SPEED_SIZE
] = "Unknown";
4436 char fc
[FC_SIZE
] = "RX/TX";
4439 netdev_info(vsi
->netdev
, "NIC Link is Down\n");
4443 switch (vsi
->back
->hw
.phy
.link_info
.link_speed
) {
4444 case I40E_LINK_SPEED_40GB
:
4445 strlcpy(speed
, "40 Gbps", SPEED_SIZE
);
4447 case I40E_LINK_SPEED_10GB
:
4448 strlcpy(speed
, "10 Gbps", SPEED_SIZE
);
4450 case I40E_LINK_SPEED_1GB
:
4451 strlcpy(speed
, "1000 Mbps", SPEED_SIZE
);
4453 case I40E_LINK_SPEED_100MB
:
4454 strncpy(speed
, "100 Mbps", SPEED_SIZE
);
4460 switch (vsi
->back
->hw
.fc
.current_mode
) {
4462 strlcpy(fc
, "RX/TX", FC_SIZE
);
4464 case I40E_FC_TX_PAUSE
:
4465 strlcpy(fc
, "TX", FC_SIZE
);
4467 case I40E_FC_RX_PAUSE
:
4468 strlcpy(fc
, "RX", FC_SIZE
);
4471 strlcpy(fc
, "None", FC_SIZE
);
4475 netdev_info(vsi
->netdev
, "NIC Link is Up %s Full Duplex, Flow Control: %s\n",
4480 * i40e_up_complete - Finish the last steps of bringing up a connection
4481 * @vsi: the VSI being configured
4483 static int i40e_up_complete(struct i40e_vsi
*vsi
)
4485 struct i40e_pf
*pf
= vsi
->back
;
4488 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
4489 i40e_vsi_configure_msix(vsi
);
4491 i40e_configure_msi_and_legacy(vsi
);
4494 err
= i40e_vsi_control_rings(vsi
, true);
4498 clear_bit(__I40E_DOWN
, &vsi
->state
);
4499 i40e_napi_enable_all(vsi
);
4500 i40e_vsi_enable_irq(vsi
);
4502 if ((pf
->hw
.phy
.link_info
.link_info
& I40E_AQ_LINK_UP
) &&
4504 i40e_print_link_message(vsi
, true);
4505 netif_tx_start_all_queues(vsi
->netdev
);
4506 netif_carrier_on(vsi
->netdev
);
4507 } else if (vsi
->netdev
) {
4508 i40e_print_link_message(vsi
, false);
4509 /* need to check for qualified module here*/
4510 if ((pf
->hw
.phy
.link_info
.link_info
&
4511 I40E_AQ_MEDIA_AVAILABLE
) &&
4512 (!(pf
->hw
.phy
.link_info
.an_info
&
4513 I40E_AQ_QUALIFIED_MODULE
)))
4514 netdev_err(vsi
->netdev
,
4515 "the driver failed to link because an unqualified module was detected.");
4518 /* replay FDIR SB filters */
4519 if (vsi
->type
== I40E_VSI_FDIR
) {
4520 /* reset fd counters */
4521 pf
->fd_add_err
= pf
->fd_atr_cnt
= 0;
4522 if (pf
->fd_tcp_rule
> 0) {
4523 pf
->flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
4524 dev_info(&pf
->pdev
->dev
, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
4525 pf
->fd_tcp_rule
= 0;
4527 i40e_fdir_filter_restore(vsi
);
4529 i40e_service_event_schedule(pf
);
4535 * i40e_vsi_reinit_locked - Reset the VSI
4536 * @vsi: the VSI being configured
4538 * Rebuild the ring structs after some configuration
4539 * has changed, e.g. MTU size.
4541 static void i40e_vsi_reinit_locked(struct i40e_vsi
*vsi
)
4543 struct i40e_pf
*pf
= vsi
->back
;
4545 WARN_ON(in_interrupt());
4546 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
4547 usleep_range(1000, 2000);
4550 /* Give a VF some time to respond to the reset. The
4551 * two second wait is based upon the watchdog cycle in
4554 if (vsi
->type
== I40E_VSI_SRIOV
)
4557 clear_bit(__I40E_CONFIG_BUSY
, &pf
->state
);
4561 * i40e_up - Bring the connection back up after being down
4562 * @vsi: the VSI being configured
4564 int i40e_up(struct i40e_vsi
*vsi
)
4568 err
= i40e_vsi_configure(vsi
);
4570 err
= i40e_up_complete(vsi
);
4576 * i40e_down - Shutdown the connection processing
4577 * @vsi: the VSI being stopped
4579 void i40e_down(struct i40e_vsi
*vsi
)
4583 /* It is assumed that the caller of this function
4584 * sets the vsi->state __I40E_DOWN bit.
4587 netif_carrier_off(vsi
->netdev
);
4588 netif_tx_disable(vsi
->netdev
);
4590 i40e_vsi_disable_irq(vsi
);
4591 i40e_vsi_control_rings(vsi
, false);
4592 i40e_napi_disable_all(vsi
);
4594 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
4595 i40e_clean_tx_ring(vsi
->tx_rings
[i
]);
4596 i40e_clean_rx_ring(vsi
->rx_rings
[i
]);
4601 * i40e_setup_tc - configure multiple traffic classes
4602 * @netdev: net device to configure
4603 * @tc: number of traffic classes to enable
4606 int i40e_setup_tc(struct net_device
*netdev
, u8 tc
)
4608 static int i40e_setup_tc(struct net_device
*netdev
, u8 tc
)
4611 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
4612 struct i40e_vsi
*vsi
= np
->vsi
;
4613 struct i40e_pf
*pf
= vsi
->back
;
4618 /* Check if DCB enabled to continue */
4619 if (!(pf
->flags
& I40E_FLAG_DCB_ENABLED
)) {
4620 netdev_info(netdev
, "DCB is not enabled for adapter\n");
4624 /* Check if MFP enabled */
4625 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
4626 netdev_info(netdev
, "Configuring TC not supported in MFP mode\n");
4630 /* Check whether tc count is within enabled limit */
4631 if (tc
> i40e_pf_get_num_tc(pf
)) {
4632 netdev_info(netdev
, "TC count greater than enabled on link for adapter\n");
4636 /* Generate TC map for number of tc requested */
4637 for (i
= 0; i
< tc
; i
++)
4638 enabled_tc
|= (1 << i
);
4640 /* Requesting same TC configuration as already enabled */
4641 if (enabled_tc
== vsi
->tc_config
.enabled_tc
)
4644 /* Quiesce VSI queues */
4645 i40e_quiesce_vsi(vsi
);
4647 /* Configure VSI for enabled TCs */
4648 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
4650 netdev_info(netdev
, "Failed configuring TC for VSI seid=%d\n",
4656 i40e_unquiesce_vsi(vsi
);
4663 * i40e_open - Called when a network interface is made active
4664 * @netdev: network interface device structure
4666 * The open entry point is called when a network interface is made
4667 * active by the system (IFF_UP). At this point all resources needed
4668 * for transmit and receive operations are allocated, the interrupt
4669 * handler is registered with the OS, the netdev watchdog subtask is
4670 * enabled, and the stack is notified that the interface is ready.
4672 * Returns 0 on success, negative value on failure
4675 int i40e_open(struct net_device
*netdev
)
4677 static int i40e_open(struct net_device
*netdev
)
4680 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
4681 struct i40e_vsi
*vsi
= np
->vsi
;
4682 struct i40e_pf
*pf
= vsi
->back
;
4685 /* disallow open during test or if eeprom is broken */
4686 if (test_bit(__I40E_TESTING
, &pf
->state
) ||
4687 test_bit(__I40E_BAD_EEPROM
, &pf
->state
))
4690 netif_carrier_off(netdev
);
4692 err
= i40e_vsi_open(vsi
);
4696 /* configure global TSO hardware offload settings */
4697 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_F
, be32_to_cpu(TCP_FLAG_PSH
|
4698 TCP_FLAG_FIN
) >> 16);
4699 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_M
, be32_to_cpu(TCP_FLAG_PSH
|
4701 TCP_FLAG_CWR
) >> 16);
4702 wr32(&pf
->hw
, I40E_GLLAN_TSOMSK_L
, be32_to_cpu(TCP_FLAG_CWR
) >> 16);
4704 #ifdef CONFIG_I40E_VXLAN
4705 vxlan_get_rx_port(netdev
);
4713 * @vsi: the VSI to open
4715 * Finish initialization of the VSI.
4717 * Returns 0 on success, negative value on failure
4719 int i40e_vsi_open(struct i40e_vsi
*vsi
)
4721 struct i40e_pf
*pf
= vsi
->back
;
4722 char int_name
[IFNAMSIZ
];
4725 /* allocate descriptors */
4726 err
= i40e_vsi_setup_tx_resources(vsi
);
4729 err
= i40e_vsi_setup_rx_resources(vsi
);
4733 err
= i40e_vsi_configure(vsi
);
4738 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s",
4739 dev_driver_string(&pf
->pdev
->dev
), vsi
->netdev
->name
);
4740 err
= i40e_vsi_request_irq(vsi
, int_name
);
4744 /* Notify the stack of the actual queue counts. */
4745 err
= netif_set_real_num_tx_queues(vsi
->netdev
,
4746 vsi
->num_queue_pairs
);
4748 goto err_set_queues
;
4750 err
= netif_set_real_num_rx_queues(vsi
->netdev
,
4751 vsi
->num_queue_pairs
);
4753 goto err_set_queues
;
4755 } else if (vsi
->type
== I40E_VSI_FDIR
) {
4756 snprintf(int_name
, sizeof(int_name
) - 1, "%s-fdir",
4757 dev_driver_string(&pf
->pdev
->dev
));
4758 err
= i40e_vsi_request_irq(vsi
, int_name
);
4764 err
= i40e_up_complete(vsi
);
4766 goto err_up_complete
;
4773 i40e_vsi_free_irq(vsi
);
4775 i40e_vsi_free_rx_resources(vsi
);
4777 i40e_vsi_free_tx_resources(vsi
);
4778 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
4779 i40e_do_reset(pf
, (1 << __I40E_PF_RESET_REQUESTED
));
4785 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
4786 * @pf: Pointer to pf
4788 * This function destroys the hlist where all the Flow Director
4789 * filters were saved.
4791 static void i40e_fdir_filter_exit(struct i40e_pf
*pf
)
4793 struct i40e_fdir_filter
*filter
;
4794 struct hlist_node
*node2
;
4796 hlist_for_each_entry_safe(filter
, node2
,
4797 &pf
->fdir_filter_list
, fdir_node
) {
4798 hlist_del(&filter
->fdir_node
);
4801 pf
->fdir_pf_active_filters
= 0;
4805 * i40e_close - Disables a network interface
4806 * @netdev: network interface device structure
4808 * The close entry point is called when an interface is de-activated
4809 * by the OS. The hardware is still under the driver's control, but
4810 * this netdev interface is disabled.
4812 * Returns 0, this is not allowed to fail
4815 int i40e_close(struct net_device
*netdev
)
4817 static int i40e_close(struct net_device
*netdev
)
4820 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
4821 struct i40e_vsi
*vsi
= np
->vsi
;
4823 i40e_vsi_close(vsi
);
4829 * i40e_do_reset - Start a PF or Core Reset sequence
4830 * @pf: board private structure
4831 * @reset_flags: which reset is requested
4833 * The essential difference in resets is that the PF Reset
4834 * doesn't clear the packet buffers, doesn't reset the PE
4835 * firmware, and doesn't bother the other PFs on the chip.
4837 void i40e_do_reset(struct i40e_pf
*pf
, u32 reset_flags
)
4841 WARN_ON(in_interrupt());
4843 if (i40e_check_asq_alive(&pf
->hw
))
4844 i40e_vc_notify_reset(pf
);
4846 /* do the biggest reset indicated */
4847 if (reset_flags
& (1 << __I40E_GLOBAL_RESET_REQUESTED
)) {
4849 /* Request a Global Reset
4851 * This will start the chip's countdown to the actual full
4852 * chip reset event, and a warning interrupt to be sent
4853 * to all PFs, including the requestor. Our handler
4854 * for the warning interrupt will deal with the shutdown
4855 * and recovery of the switch setup.
4857 dev_dbg(&pf
->pdev
->dev
, "GlobalR requested\n");
4858 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
4859 val
|= I40E_GLGEN_RTRIG_GLOBR_MASK
;
4860 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
4862 } else if (reset_flags
& (1 << __I40E_CORE_RESET_REQUESTED
)) {
4864 /* Request a Core Reset
4866 * Same as Global Reset, except does *not* include the MAC/PHY
4868 dev_dbg(&pf
->pdev
->dev
, "CoreR requested\n");
4869 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
4870 val
|= I40E_GLGEN_RTRIG_CORER_MASK
;
4871 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
4872 i40e_flush(&pf
->hw
);
4874 } else if (reset_flags
& (1 << __I40E_EMP_RESET_REQUESTED
)) {
4876 /* Request a Firmware Reset
4878 * Same as Global reset, plus restarting the
4879 * embedded firmware engine.
4881 /* enable EMP Reset */
4882 val
= rd32(&pf
->hw
, I40E_GLGEN_RSTENA_EMP
);
4883 val
|= I40E_GLGEN_RSTENA_EMP_EMP_RST_ENA_MASK
;
4884 wr32(&pf
->hw
, I40E_GLGEN_RSTENA_EMP
, val
);
4886 /* force the reset */
4887 val
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
4888 val
|= I40E_GLGEN_RTRIG_EMPFWR_MASK
;
4889 wr32(&pf
->hw
, I40E_GLGEN_RTRIG
, val
);
4890 i40e_flush(&pf
->hw
);
4892 } else if (reset_flags
& (1 << __I40E_PF_RESET_REQUESTED
)) {
4894 /* Request a PF Reset
4896 * Resets only the PF-specific registers
4898 * This goes directly to the tear-down and rebuild of
4899 * the switch, since we need to do all the recovery as
4900 * for the Core Reset.
4902 dev_dbg(&pf
->pdev
->dev
, "PFR requested\n");
4903 i40e_handle_reset_warning(pf
);
4905 } else if (reset_flags
& (1 << __I40E_REINIT_REQUESTED
)) {
4908 /* Find the VSI(s) that requested a re-init */
4909 dev_info(&pf
->pdev
->dev
,
4910 "VSI reinit requested\n");
4911 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4912 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
4914 test_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
)) {
4915 i40e_vsi_reinit_locked(pf
->vsi
[v
]);
4916 clear_bit(__I40E_REINIT_REQUESTED
, &vsi
->state
);
4920 /* no further action needed, so return now */
4922 } else if (reset_flags
& (1 << __I40E_DOWN_REQUESTED
)) {
4925 /* Find the VSI(s) that needs to be brought down */
4926 dev_info(&pf
->pdev
->dev
, "VSI down requested\n");
4927 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
4928 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
4930 test_bit(__I40E_DOWN_REQUESTED
, &vsi
->state
)) {
4931 set_bit(__I40E_DOWN
, &vsi
->state
);
4933 clear_bit(__I40E_DOWN_REQUESTED
, &vsi
->state
);
4937 /* no further action needed, so return now */
4940 dev_info(&pf
->pdev
->dev
,
4941 "bad reset request 0x%08x\n", reset_flags
);
4946 #ifdef CONFIG_I40E_DCB
4948 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
4949 * @pf: board private structure
4950 * @old_cfg: current DCB config
4951 * @new_cfg: new DCB config
4953 bool i40e_dcb_need_reconfig(struct i40e_pf
*pf
,
4954 struct i40e_dcbx_config
*old_cfg
,
4955 struct i40e_dcbx_config
*new_cfg
)
4957 bool need_reconfig
= false;
4959 /* Check if ETS configuration has changed */
4960 if (memcmp(&new_cfg
->etscfg
,
4962 sizeof(new_cfg
->etscfg
))) {
4963 /* If Priority Table has changed reconfig is needed */
4964 if (memcmp(&new_cfg
->etscfg
.prioritytable
,
4965 &old_cfg
->etscfg
.prioritytable
,
4966 sizeof(new_cfg
->etscfg
.prioritytable
))) {
4967 need_reconfig
= true;
4968 dev_dbg(&pf
->pdev
->dev
, "ETS UP2TC changed.\n");
4971 if (memcmp(&new_cfg
->etscfg
.tcbwtable
,
4972 &old_cfg
->etscfg
.tcbwtable
,
4973 sizeof(new_cfg
->etscfg
.tcbwtable
)))
4974 dev_dbg(&pf
->pdev
->dev
, "ETS TC BW Table changed.\n");
4976 if (memcmp(&new_cfg
->etscfg
.tsatable
,
4977 &old_cfg
->etscfg
.tsatable
,
4978 sizeof(new_cfg
->etscfg
.tsatable
)))
4979 dev_dbg(&pf
->pdev
->dev
, "ETS TSA Table changed.\n");
4982 /* Check if PFC configuration has changed */
4983 if (memcmp(&new_cfg
->pfc
,
4985 sizeof(new_cfg
->pfc
))) {
4986 need_reconfig
= true;
4987 dev_dbg(&pf
->pdev
->dev
, "PFC config change detected.\n");
4990 /* Check if APP Table has changed */
4991 if (memcmp(&new_cfg
->app
,
4993 sizeof(new_cfg
->app
))) {
4994 need_reconfig
= true;
4995 dev_dbg(&pf
->pdev
->dev
, "APP Table change detected.\n");
4998 return need_reconfig
;
5002 * i40e_handle_lldp_event - Handle LLDP Change MIB event
5003 * @pf: board private structure
5004 * @e: event info posted on ARQ
5006 static int i40e_handle_lldp_event(struct i40e_pf
*pf
,
5007 struct i40e_arq_event_info
*e
)
5009 struct i40e_aqc_lldp_get_mib
*mib
=
5010 (struct i40e_aqc_lldp_get_mib
*)&e
->desc
.params
.raw
;
5011 struct i40e_hw
*hw
= &pf
->hw
;
5012 struct i40e_dcbx_config
*dcbx_cfg
= &hw
->local_dcbx_config
;
5013 struct i40e_dcbx_config tmp_dcbx_cfg
;
5014 bool need_reconfig
= false;
5018 /* Not DCB capable or capability disabled */
5019 if (!(pf
->flags
& I40E_FLAG_DCB_CAPABLE
))
5022 /* Ignore if event is not for Nearest Bridge */
5023 type
= ((mib
->type
>> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT
)
5024 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK
);
5025 if (type
!= I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
)
5028 /* Check MIB Type and return if event for Remote MIB update */
5029 type
= mib
->type
& I40E_AQ_LLDP_MIB_TYPE_MASK
;
5030 if (type
== I40E_AQ_LLDP_MIB_REMOTE
) {
5031 /* Update the remote cached instance and return */
5032 ret
= i40e_aq_get_dcb_config(hw
, I40E_AQ_LLDP_MIB_REMOTE
,
5033 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE
,
5034 &hw
->remote_dcbx_config
);
5038 /* Convert/store the DCBX data from LLDPDU temporarily */
5039 memset(&tmp_dcbx_cfg
, 0, sizeof(tmp_dcbx_cfg
));
5040 ret
= i40e_lldp_to_dcb_config(e
->msg_buf
, &tmp_dcbx_cfg
);
5042 /* Error in LLDPDU parsing return */
5043 dev_info(&pf
->pdev
->dev
, "Failed parsing LLDPDU from event buffer\n");
5047 /* No change detected in DCBX configs */
5048 if (!memcmp(&tmp_dcbx_cfg
, dcbx_cfg
, sizeof(tmp_dcbx_cfg
))) {
5049 dev_dbg(&pf
->pdev
->dev
, "No change detected in DCBX configuration.\n");
5053 need_reconfig
= i40e_dcb_need_reconfig(pf
, dcbx_cfg
, &tmp_dcbx_cfg
);
5055 i40e_dcbnl_flush_apps(pf
, &tmp_dcbx_cfg
);
5057 /* Overwrite the new configuration */
5058 *dcbx_cfg
= tmp_dcbx_cfg
;
5063 /* Enable DCB tagging only when more than one TC */
5064 if (i40e_dcb_get_num_tc(dcbx_cfg
) > 1)
5065 pf
->flags
|= I40E_FLAG_DCB_ENABLED
;
5067 pf
->flags
&= ~I40E_FLAG_DCB_ENABLED
;
5069 /* Reconfiguration needed quiesce all VSIs */
5070 i40e_pf_quiesce_all_vsi(pf
);
5072 /* Changes in configuration update VEB/VSI */
5073 i40e_dcb_reconfigure(pf
);
5075 i40e_pf_unquiesce_all_vsi(pf
);
5079 #endif /* CONFIG_I40E_DCB */
5082 * i40e_do_reset_safe - Protected reset path for userland calls.
5083 * @pf: board private structure
5084 * @reset_flags: which reset is requested
5087 void i40e_do_reset_safe(struct i40e_pf
*pf
, u32 reset_flags
)
5090 i40e_do_reset(pf
, reset_flags
);
5095 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
5096 * @pf: board private structure
5097 * @e: event info posted on ARQ
5099 * Handler for LAN Queue Overflow Event generated by the firmware for PF
5102 static void i40e_handle_lan_overflow_event(struct i40e_pf
*pf
,
5103 struct i40e_arq_event_info
*e
)
5105 struct i40e_aqc_lan_overflow
*data
=
5106 (struct i40e_aqc_lan_overflow
*)&e
->desc
.params
.raw
;
5107 u32 queue
= le32_to_cpu(data
->prtdcb_rupto
);
5108 u32 qtx_ctl
= le32_to_cpu(data
->otx_ctl
);
5109 struct i40e_hw
*hw
= &pf
->hw
;
5113 dev_dbg(&pf
->pdev
->dev
, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
5116 /* Queue belongs to VF, find the VF and issue VF reset */
5117 if (((qtx_ctl
& I40E_QTX_CTL_PFVF_Q_MASK
)
5118 >> I40E_QTX_CTL_PFVF_Q_SHIFT
) == I40E_QTX_CTL_VF_QUEUE
) {
5119 vf_id
= (u16
)((qtx_ctl
& I40E_QTX_CTL_VFVM_INDX_MASK
)
5120 >> I40E_QTX_CTL_VFVM_INDX_SHIFT
);
5121 vf_id
-= hw
->func_caps
.vf_base_id
;
5122 vf
= &pf
->vf
[vf_id
];
5123 i40e_vc_notify_vf_reset(vf
);
5124 /* Allow VF to process pending reset notification */
5126 i40e_reset_vf(vf
, false);
5131 * i40e_service_event_complete - Finish up the service event
5132 * @pf: board private structure
5134 static void i40e_service_event_complete(struct i40e_pf
*pf
)
5136 BUG_ON(!test_bit(__I40E_SERVICE_SCHED
, &pf
->state
));
5138 /* flush memory to make sure state is correct before next watchog */
5139 smp_mb__before_atomic();
5140 clear_bit(__I40E_SERVICE_SCHED
, &pf
->state
);
5144 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
5145 * @pf: board private structure
5147 int i40e_get_cur_guaranteed_fd_count(struct i40e_pf
*pf
)
5151 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
5152 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
);
5157 * i40e_get_current_fd_count - Get the count of total FD filters programmed
5158 * @pf: board private structure
5160 int i40e_get_current_fd_count(struct i40e_pf
*pf
)
5163 val
= rd32(&pf
->hw
, I40E_PFQF_FDSTAT
);
5164 fcnt_prog
= (val
& I40E_PFQF_FDSTAT_GUARANT_CNT_MASK
) +
5165 ((val
& I40E_PFQF_FDSTAT_BEST_CNT_MASK
) >>
5166 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT
);
5171 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
5172 * @pf: board private structure
5174 void i40e_fdir_check_and_reenable(struct i40e_pf
*pf
)
5176 u32 fcnt_prog
, fcnt_avail
;
5178 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
5181 /* Check if, FD SB or ATR was auto disabled and if there is enough room
5184 fcnt_prog
= i40e_get_cur_guaranteed_fd_count(pf
);
5185 fcnt_avail
= pf
->fdir_pf_filter_count
;
5186 if ((fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM
)) ||
5187 (pf
->fd_add_err
== 0) ||
5188 (i40e_get_current_atr_cnt(pf
) < pf
->fd_atr_cnt
)) {
5189 if ((pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) &&
5190 (pf
->auto_disable_flags
& I40E_FLAG_FD_SB_ENABLED
)) {
5191 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
5192 dev_info(&pf
->pdev
->dev
, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
5195 /* Wait for some more space to be available to turn on ATR */
5196 if (fcnt_prog
< (fcnt_avail
- I40E_FDIR_BUFFER_HEAD_ROOM
* 2)) {
5197 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
5198 (pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
)) {
5199 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
5200 dev_info(&pf
->pdev
->dev
, "ATR is being enabled since we have space in the table now\n");
5205 #define I40E_MIN_FD_FLUSH_INTERVAL 10
5207 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
5208 * @pf: board private structure
5210 static void i40e_fdir_flush_and_replay(struct i40e_pf
*pf
)
5212 int flush_wait_retry
= 50;
5215 if (time_after(jiffies
, pf
->fd_flush_timestamp
+
5216 (I40E_MIN_FD_FLUSH_INTERVAL
* HZ
))) {
5217 set_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
);
5218 pf
->fd_flush_timestamp
= jiffies
;
5219 pf
->auto_disable_flags
|= I40E_FLAG_FD_SB_ENABLED
;
5220 pf
->flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
5221 /* flush all filters */
5222 wr32(&pf
->hw
, I40E_PFQF_CTL_1
,
5223 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
);
5224 i40e_flush(&pf
->hw
);
5228 /* Check FD flush status every 5-6msec */
5229 usleep_range(5000, 6000);
5230 reg
= rd32(&pf
->hw
, I40E_PFQF_CTL_1
);
5231 if (!(reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
))
5233 } while (flush_wait_retry
--);
5234 if (reg
& I40E_PFQF_CTL_1_CLEARFDTABLE_MASK
) {
5235 dev_warn(&pf
->pdev
->dev
, "FD table did not flush, needs more time\n");
5237 /* replay sideband filters */
5238 i40e_fdir_filter_restore(pf
->vsi
[pf
->lan_vsi
]);
5240 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
5241 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
5242 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
5243 clear_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
);
5244 dev_info(&pf
->pdev
->dev
, "FD Filter table flushed and FD-SB replayed.\n");
5250 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
5251 * @pf: board private structure
5253 int i40e_get_current_atr_cnt(struct i40e_pf
*pf
)
5255 return i40e_get_current_fd_count(pf
) - pf
->fdir_pf_active_filters
;
5258 /* We can see up to 256 filter programming desc in transit if the filters are
5259 * being applied really fast; before we see the first
5260 * filter miss error on Rx queue 0. Accumulating enough error messages before
5261 * reacting will make sure we don't cause flush too often.
5263 #define I40E_MAX_FD_PROGRAM_ERROR 256
5266 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
5267 * @pf: board private structure
5269 static void i40e_fdir_reinit_subtask(struct i40e_pf
*pf
)
5272 /* if interface is down do nothing */
5273 if (test_bit(__I40E_DOWN
, &pf
->state
))
5276 if ((pf
->fd_add_err
>= I40E_MAX_FD_PROGRAM_ERROR
) &&
5277 (i40e_get_current_atr_cnt(pf
) >= pf
->fd_atr_cnt
) &&
5278 (i40e_get_current_atr_cnt(pf
) > pf
->fdir_pf_filter_count
))
5279 i40e_fdir_flush_and_replay(pf
);
5281 i40e_fdir_check_and_reenable(pf
);
5286 * i40e_vsi_link_event - notify VSI of a link event
5287 * @vsi: vsi to be notified
5288 * @link_up: link up or down
5290 static void i40e_vsi_link_event(struct i40e_vsi
*vsi
, bool link_up
)
5292 if (!vsi
|| test_bit(__I40E_DOWN
, &vsi
->state
))
5295 switch (vsi
->type
) {
5300 if (!vsi
->netdev
|| !vsi
->netdev_registered
)
5304 netif_carrier_on(vsi
->netdev
);
5305 netif_tx_wake_all_queues(vsi
->netdev
);
5307 netif_carrier_off(vsi
->netdev
);
5308 netif_tx_stop_all_queues(vsi
->netdev
);
5312 case I40E_VSI_SRIOV
:
5315 case I40E_VSI_VMDQ2
:
5317 case I40E_VSI_MIRROR
:
5319 /* there is no notification for other VSIs */
5325 * i40e_veb_link_event - notify elements on the veb of a link event
5326 * @veb: veb to be notified
5327 * @link_up: link up or down
5329 static void i40e_veb_link_event(struct i40e_veb
*veb
, bool link_up
)
5334 if (!veb
|| !veb
->pf
)
5338 /* depth first... */
5339 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
5340 if (pf
->veb
[i
] && (pf
->veb
[i
]->uplink_seid
== veb
->seid
))
5341 i40e_veb_link_event(pf
->veb
[i
], link_up
);
5343 /* ... now the local VSIs */
5344 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
5345 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->uplink_seid
== veb
->seid
))
5346 i40e_vsi_link_event(pf
->vsi
[i
], link_up
);
5350 * i40e_link_event - Update netif_carrier status
5351 * @pf: board private structure
5353 static void i40e_link_event(struct i40e_pf
*pf
)
5355 bool new_link
, old_link
;
5357 /* set this to force the get_link_status call to refresh state */
5358 pf
->hw
.phy
.get_link_info
= true;
5360 old_link
= (pf
->hw
.phy
.link_info_old
.link_info
& I40E_AQ_LINK_UP
);
5361 new_link
= i40e_get_link_status(&pf
->hw
);
5363 if (new_link
== old_link
&&
5364 new_link
== netif_carrier_ok(pf
->vsi
[pf
->lan_vsi
]->netdev
))
5366 if (!test_bit(__I40E_DOWN
, &pf
->vsi
[pf
->lan_vsi
]->state
))
5367 i40e_print_link_message(pf
->vsi
[pf
->lan_vsi
], new_link
);
5369 /* Notify the base of the switch tree connected to
5370 * the link. Floating VEBs are not notified.
5372 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
5373 i40e_veb_link_event(pf
->veb
[pf
->lan_veb
], new_link
);
5375 i40e_vsi_link_event(pf
->vsi
[pf
->lan_vsi
], new_link
);
5378 i40e_vc_notify_link_state(pf
);
5380 if (pf
->flags
& I40E_FLAG_PTP
)
5381 i40e_ptp_set_increment(pf
);
5385 * i40e_check_hang_subtask - Check for hung queues and dropped interrupts
5386 * @pf: board private structure
5388 * Set the per-queue flags to request a check for stuck queues in the irq
5389 * clean functions, then force interrupts to be sure the irq clean is called.
5391 static void i40e_check_hang_subtask(struct i40e_pf
*pf
)
5395 /* If we're down or resetting, just bail */
5396 if (test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
5399 /* for each VSI/netdev
5401 * set the check flag
5403 * force an interrupt
5405 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5406 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
5410 test_bit(__I40E_DOWN
, &vsi
->state
) ||
5411 (vsi
->netdev
&& !netif_carrier_ok(vsi
->netdev
)))
5414 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
5415 set_check_for_tx_hang(vsi
->tx_rings
[i
]);
5416 if (test_bit(__I40E_HANG_CHECK_ARMED
,
5417 &vsi
->tx_rings
[i
]->state
))
5422 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
)) {
5423 wr32(&vsi
->back
->hw
, I40E_PFINT_DYN_CTL0
,
5424 (I40E_PFINT_DYN_CTL0_INTENA_MASK
|
5425 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK
));
5427 u16 vec
= vsi
->base_vector
- 1;
5428 u32 val
= (I40E_PFINT_DYN_CTLN_INTENA_MASK
|
5429 I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK
);
5430 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vec
++)
5431 wr32(&vsi
->back
->hw
,
5432 I40E_PFINT_DYN_CTLN(vec
), val
);
5434 i40e_flush(&vsi
->back
->hw
);
5440 * i40e_watchdog_subtask - Check and bring link up
5441 * @pf: board private structure
5443 static void i40e_watchdog_subtask(struct i40e_pf
*pf
)
5447 /* if interface is down do nothing */
5448 if (test_bit(__I40E_DOWN
, &pf
->state
) ||
5449 test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
5452 /* Update the stats for active netdevs so the network stack
5453 * can look at updated numbers whenever it cares to
5455 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++)
5456 if (pf
->vsi
[i
] && pf
->vsi
[i
]->netdev
)
5457 i40e_update_stats(pf
->vsi
[i
]);
5459 /* Update the stats for the active switching components */
5460 for (i
= 0; i
< I40E_MAX_VEB
; i
++)
5462 i40e_update_veb_stats(pf
->veb
[i
]);
5464 i40e_ptp_rx_hang(pf
->vsi
[pf
->lan_vsi
]);
5468 * i40e_reset_subtask - Set up for resetting the device and driver
5469 * @pf: board private structure
5471 static void i40e_reset_subtask(struct i40e_pf
*pf
)
5473 u32 reset_flags
= 0;
5476 if (test_bit(__I40E_REINIT_REQUESTED
, &pf
->state
)) {
5477 reset_flags
|= (1 << __I40E_REINIT_REQUESTED
);
5478 clear_bit(__I40E_REINIT_REQUESTED
, &pf
->state
);
5480 if (test_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
)) {
5481 reset_flags
|= (1 << __I40E_PF_RESET_REQUESTED
);
5482 clear_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
5484 if (test_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
)) {
5485 reset_flags
|= (1 << __I40E_CORE_RESET_REQUESTED
);
5486 clear_bit(__I40E_CORE_RESET_REQUESTED
, &pf
->state
);
5488 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
)) {
5489 reset_flags
|= (1 << __I40E_GLOBAL_RESET_REQUESTED
);
5490 clear_bit(__I40E_GLOBAL_RESET_REQUESTED
, &pf
->state
);
5492 if (test_bit(__I40E_DOWN_REQUESTED
, &pf
->state
)) {
5493 reset_flags
|= (1 << __I40E_DOWN_REQUESTED
);
5494 clear_bit(__I40E_DOWN_REQUESTED
, &pf
->state
);
5497 /* If there's a recovery already waiting, it takes
5498 * precedence before starting a new reset sequence.
5500 if (test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
)) {
5501 i40e_handle_reset_warning(pf
);
5505 /* If we're already down or resetting, just bail */
5507 !test_bit(__I40E_DOWN
, &pf
->state
) &&
5508 !test_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
5509 i40e_do_reset(pf
, reset_flags
);
5516 * i40e_handle_link_event - Handle link event
5517 * @pf: board private structure
5518 * @e: event info posted on ARQ
5520 static void i40e_handle_link_event(struct i40e_pf
*pf
,
5521 struct i40e_arq_event_info
*e
)
5523 struct i40e_hw
*hw
= &pf
->hw
;
5524 struct i40e_aqc_get_link_status
*status
=
5525 (struct i40e_aqc_get_link_status
*)&e
->desc
.params
.raw
;
5526 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
5528 /* save off old link status information */
5529 memcpy(&pf
->hw
.phy
.link_info_old
, hw_link_info
,
5530 sizeof(pf
->hw
.phy
.link_info_old
));
5532 /* Do a new status request to re-enable LSE reporting
5533 * and load new status information into the hw struct
5534 * This completely ignores any state information
5535 * in the ARQ event info, instead choosing to always
5536 * issue the AQ update link status command.
5538 i40e_link_event(pf
);
5540 /* check for unqualified module, if link is down */
5541 if ((status
->link_info
& I40E_AQ_MEDIA_AVAILABLE
) &&
5542 (!(status
->an_info
& I40E_AQ_QUALIFIED_MODULE
)) &&
5543 (!(status
->link_info
& I40E_AQ_LINK_UP
)))
5544 dev_err(&pf
->pdev
->dev
,
5545 "The driver failed to link because an unqualified module was detected.\n");
5549 * i40e_clean_adminq_subtask - Clean the AdminQ rings
5550 * @pf: board private structure
5552 static void i40e_clean_adminq_subtask(struct i40e_pf
*pf
)
5554 struct i40e_arq_event_info event
;
5555 struct i40e_hw
*hw
= &pf
->hw
;
5562 /* Do not run clean AQ when PF reset fails */
5563 if (test_bit(__I40E_RESET_FAILED
, &pf
->state
))
5566 /* check for error indications */
5567 val
= rd32(&pf
->hw
, pf
->hw
.aq
.arq
.len
);
5569 if (val
& I40E_PF_ARQLEN_ARQVFE_MASK
) {
5570 dev_info(&pf
->pdev
->dev
, "ARQ VF Error detected\n");
5571 val
&= ~I40E_PF_ARQLEN_ARQVFE_MASK
;
5573 if (val
& I40E_PF_ARQLEN_ARQOVFL_MASK
) {
5574 dev_info(&pf
->pdev
->dev
, "ARQ Overflow Error detected\n");
5575 val
&= ~I40E_PF_ARQLEN_ARQOVFL_MASK
;
5577 if (val
& I40E_PF_ARQLEN_ARQCRIT_MASK
) {
5578 dev_info(&pf
->pdev
->dev
, "ARQ Critical Error detected\n");
5579 val
&= ~I40E_PF_ARQLEN_ARQCRIT_MASK
;
5582 wr32(&pf
->hw
, pf
->hw
.aq
.arq
.len
, val
);
5584 val
= rd32(&pf
->hw
, pf
->hw
.aq
.asq
.len
);
5586 if (val
& I40E_PF_ATQLEN_ATQVFE_MASK
) {
5587 dev_info(&pf
->pdev
->dev
, "ASQ VF Error detected\n");
5588 val
&= ~I40E_PF_ATQLEN_ATQVFE_MASK
;
5590 if (val
& I40E_PF_ATQLEN_ATQOVFL_MASK
) {
5591 dev_info(&pf
->pdev
->dev
, "ASQ Overflow Error detected\n");
5592 val
&= ~I40E_PF_ATQLEN_ATQOVFL_MASK
;
5594 if (val
& I40E_PF_ATQLEN_ATQCRIT_MASK
) {
5595 dev_info(&pf
->pdev
->dev
, "ASQ Critical Error detected\n");
5596 val
&= ~I40E_PF_ATQLEN_ATQCRIT_MASK
;
5599 wr32(&pf
->hw
, pf
->hw
.aq
.asq
.len
, val
);
5601 event
.msg_size
= I40E_MAX_AQ_BUF_SIZE
;
5602 event
.msg_buf
= kzalloc(event
.msg_size
, GFP_KERNEL
);
5607 event
.msg_size
= I40E_MAX_AQ_BUF_SIZE
; /* reinit each time */
5608 ret
= i40e_clean_arq_element(hw
, &event
, &pending
);
5609 if (ret
== I40E_ERR_ADMIN_QUEUE_NO_WORK
)
5612 dev_info(&pf
->pdev
->dev
, "ARQ event error %d\n", ret
);
5616 opcode
= le16_to_cpu(event
.desc
.opcode
);
5619 case i40e_aqc_opc_get_link_status
:
5620 i40e_handle_link_event(pf
, &event
);
5622 case i40e_aqc_opc_send_msg_to_pf
:
5623 ret
= i40e_vc_process_vf_msg(pf
,
5624 le16_to_cpu(event
.desc
.retval
),
5625 le32_to_cpu(event
.desc
.cookie_high
),
5626 le32_to_cpu(event
.desc
.cookie_low
),
5630 case i40e_aqc_opc_lldp_update_mib
:
5631 dev_dbg(&pf
->pdev
->dev
, "ARQ: Update LLDP MIB event received\n");
5632 #ifdef CONFIG_I40E_DCB
5634 ret
= i40e_handle_lldp_event(pf
, &event
);
5636 #endif /* CONFIG_I40E_DCB */
5638 case i40e_aqc_opc_event_lan_overflow
:
5639 dev_dbg(&pf
->pdev
->dev
, "ARQ LAN queue overflow event received\n");
5640 i40e_handle_lan_overflow_event(pf
, &event
);
5642 case i40e_aqc_opc_send_msg_to_peer
:
5643 dev_info(&pf
->pdev
->dev
, "ARQ: Msg from other pf\n");
5646 dev_info(&pf
->pdev
->dev
,
5647 "ARQ Error: Unknown event 0x%04x received\n",
5651 } while (pending
&& (i
++ < pf
->adminq_work_limit
));
5653 clear_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
);
5654 /* re-enable Admin queue interrupt cause */
5655 val
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
5656 val
|= I40E_PFINT_ICR0_ENA_ADMINQ_MASK
;
5657 wr32(hw
, I40E_PFINT_ICR0_ENA
, val
);
5660 kfree(event
.msg_buf
);
5664 * i40e_verify_eeprom - make sure eeprom is good to use
5665 * @pf: board private structure
5667 static void i40e_verify_eeprom(struct i40e_pf
*pf
)
5671 err
= i40e_diag_eeprom_test(&pf
->hw
);
5673 /* retry in case of garbage read */
5674 err
= i40e_diag_eeprom_test(&pf
->hw
);
5676 dev_info(&pf
->pdev
->dev
, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
5678 set_bit(__I40E_BAD_EEPROM
, &pf
->state
);
5682 if (!err
&& test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
5683 dev_info(&pf
->pdev
->dev
, "eeprom check passed, Tx/Rx traffic enabled\n");
5684 clear_bit(__I40E_BAD_EEPROM
, &pf
->state
);
5689 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
5690 * @veb: pointer to the VEB instance
5692 * This is a recursive function that first builds the attached VSIs then
5693 * recurses in to build the next layer of VEB. We track the connections
5694 * through our own index numbers because the seid's from the HW could
5695 * change across the reset.
5697 static int i40e_reconstitute_veb(struct i40e_veb
*veb
)
5699 struct i40e_vsi
*ctl_vsi
= NULL
;
5700 struct i40e_pf
*pf
= veb
->pf
;
5704 /* build VSI that owns this VEB, temporarily attached to base VEB */
5705 for (v
= 0; v
< pf
->num_alloc_vsi
&& !ctl_vsi
; v
++) {
5707 pf
->vsi
[v
]->veb_idx
== veb
->idx
&&
5708 pf
->vsi
[v
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
5709 ctl_vsi
= pf
->vsi
[v
];
5714 dev_info(&pf
->pdev
->dev
,
5715 "missing owner VSI for veb_idx %d\n", veb
->idx
);
5717 goto end_reconstitute
;
5719 if (ctl_vsi
!= pf
->vsi
[pf
->lan_vsi
])
5720 ctl_vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
5721 ret
= i40e_add_vsi(ctl_vsi
);
5723 dev_info(&pf
->pdev
->dev
,
5724 "rebuild of owner VSI failed: %d\n", ret
);
5725 goto end_reconstitute
;
5727 i40e_vsi_reset_stats(ctl_vsi
);
5729 /* create the VEB in the switch and move the VSI onto the VEB */
5730 ret
= i40e_add_veb(veb
, ctl_vsi
);
5732 goto end_reconstitute
;
5734 /* create the remaining VSIs attached to this VEB */
5735 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5736 if (!pf
->vsi
[v
] || pf
->vsi
[v
] == ctl_vsi
)
5739 if (pf
->vsi
[v
]->veb_idx
== veb
->idx
) {
5740 struct i40e_vsi
*vsi
= pf
->vsi
[v
];
5741 vsi
->uplink_seid
= veb
->seid
;
5742 ret
= i40e_add_vsi(vsi
);
5744 dev_info(&pf
->pdev
->dev
,
5745 "rebuild of vsi_idx %d failed: %d\n",
5747 goto end_reconstitute
;
5749 i40e_vsi_reset_stats(vsi
);
5753 /* create any VEBs attached to this VEB - RECURSION */
5754 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
5755 if (pf
->veb
[veb_idx
] && pf
->veb
[veb_idx
]->veb_idx
== veb
->idx
) {
5756 pf
->veb
[veb_idx
]->uplink_seid
= veb
->seid
;
5757 ret
= i40e_reconstitute_veb(pf
->veb
[veb_idx
]);
5768 * i40e_get_capabilities - get info about the HW
5769 * @pf: the PF struct
5771 static int i40e_get_capabilities(struct i40e_pf
*pf
)
5773 struct i40e_aqc_list_capabilities_element_resp
*cap_buf
;
5778 buf_len
= 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp
);
5780 cap_buf
= kzalloc(buf_len
, GFP_KERNEL
);
5784 /* this loads the data into the hw struct for us */
5785 err
= i40e_aq_discover_capabilities(&pf
->hw
, cap_buf
, buf_len
,
5787 i40e_aqc_opc_list_func_capabilities
,
5789 /* data loaded, buffer no longer needed */
5792 if (pf
->hw
.aq
.asq_last_status
== I40E_AQ_RC_ENOMEM
) {
5793 /* retry with a larger buffer */
5794 buf_len
= data_size
;
5795 } else if (pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_OK
) {
5796 dev_info(&pf
->pdev
->dev
,
5797 "capability discovery failed: aq=%d\n",
5798 pf
->hw
.aq
.asq_last_status
);
5803 if (((pf
->hw
.aq
.fw_maj_ver
== 2) && (pf
->hw
.aq
.fw_min_ver
< 22)) ||
5804 (pf
->hw
.aq
.fw_maj_ver
< 2)) {
5805 pf
->hw
.func_caps
.num_msix_vectors
++;
5806 pf
->hw
.func_caps
.num_msix_vectors_vf
++;
5809 if (pf
->hw
.debug_mask
& I40E_DEBUG_USER
)
5810 dev_info(&pf
->pdev
->dev
,
5811 "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",
5812 pf
->hw
.pf_id
, pf
->hw
.func_caps
.num_vfs
,
5813 pf
->hw
.func_caps
.num_msix_vectors
,
5814 pf
->hw
.func_caps
.num_msix_vectors_vf
,
5815 pf
->hw
.func_caps
.fd_filters_guaranteed
,
5816 pf
->hw
.func_caps
.fd_filters_best_effort
,
5817 pf
->hw
.func_caps
.num_tx_qp
,
5818 pf
->hw
.func_caps
.num_vsis
);
5820 #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
5821 + pf->hw.func_caps.num_vfs)
5822 if (pf
->hw
.revision_id
== 0 && (DEF_NUM_VSI
> pf
->hw
.func_caps
.num_vsis
)) {
5823 dev_info(&pf
->pdev
->dev
,
5824 "got num_vsis %d, setting num_vsis to %d\n",
5825 pf
->hw
.func_caps
.num_vsis
, DEF_NUM_VSI
);
5826 pf
->hw
.func_caps
.num_vsis
= DEF_NUM_VSI
;
5832 static int i40e_vsi_clear(struct i40e_vsi
*vsi
);
5835 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
5836 * @pf: board private structure
5838 static void i40e_fdir_sb_setup(struct i40e_pf
*pf
)
5840 struct i40e_vsi
*vsi
;
5843 /* quick workaround for an NVM issue that leaves a critical register
5846 if (!rd32(&pf
->hw
, I40E_GLQF_HKEY(0))) {
5847 static const u32 hkey
[] = {
5848 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
5849 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
5850 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
5853 for (i
= 0; i
<= I40E_GLQF_HKEY_MAX_INDEX
; i
++)
5854 wr32(&pf
->hw
, I40E_GLQF_HKEY(i
), hkey
[i
]);
5857 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
5860 /* find existing VSI and see if it needs configuring */
5862 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
5863 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
5869 /* create a new VSI if none exists */
5871 vsi
= i40e_vsi_setup(pf
, I40E_VSI_FDIR
,
5872 pf
->vsi
[pf
->lan_vsi
]->seid
, 0);
5874 dev_info(&pf
->pdev
->dev
, "Couldn't create FDir VSI\n");
5875 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
5880 i40e_vsi_setup_irqhandler(vsi
, i40e_fdir_clean_ring
);
5884 * i40e_fdir_teardown - release the Flow Director resources
5885 * @pf: board private structure
5887 static void i40e_fdir_teardown(struct i40e_pf
*pf
)
5891 i40e_fdir_filter_exit(pf
);
5892 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
5893 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
5894 i40e_vsi_release(pf
->vsi
[i
]);
5901 * i40e_prep_for_reset - prep for the core to reset
5902 * @pf: board private structure
5904 * Close up the VFs and other things in prep for pf Reset.
5906 static void i40e_prep_for_reset(struct i40e_pf
*pf
)
5908 struct i40e_hw
*hw
= &pf
->hw
;
5909 i40e_status ret
= 0;
5912 clear_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
);
5913 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
))
5916 dev_dbg(&pf
->pdev
->dev
, "Tearing down internal switch for reset\n");
5918 /* quiesce the VSIs and their queues that are not already DOWN */
5919 i40e_pf_quiesce_all_vsi(pf
);
5921 for (v
= 0; v
< pf
->num_alloc_vsi
; v
++) {
5923 pf
->vsi
[v
]->seid
= 0;
5926 i40e_shutdown_adminq(&pf
->hw
);
5928 /* call shutdown HMC */
5929 if (hw
->hmc
.hmc_obj
) {
5930 ret
= i40e_shutdown_lan_hmc(hw
);
5932 dev_warn(&pf
->pdev
->dev
,
5933 "shutdown_lan_hmc failed: %d\n", ret
);
5938 * i40e_send_version - update firmware with driver version
5941 static void i40e_send_version(struct i40e_pf
*pf
)
5943 struct i40e_driver_version dv
;
5945 dv
.major_version
= DRV_VERSION_MAJOR
;
5946 dv
.minor_version
= DRV_VERSION_MINOR
;
5947 dv
.build_version
= DRV_VERSION_BUILD
;
5948 dv
.subbuild_version
= 0;
5949 strlcpy(dv
.driver_string
, DRV_VERSION
, sizeof(dv
.driver_string
));
5950 i40e_aq_send_driver_version(&pf
->hw
, &dv
, NULL
);
5954 * i40e_reset_and_rebuild - reset and rebuild using a saved config
5955 * @pf: board private structure
5956 * @reinit: if the Main VSI needs to re-initialized.
5958 static void i40e_reset_and_rebuild(struct i40e_pf
*pf
, bool reinit
)
5960 struct i40e_hw
*hw
= &pf
->hw
;
5961 u8 set_fc_aq_fail
= 0;
5965 /* Now we wait for GRST to settle out.
5966 * We don't have to delete the VEBs or VSIs from the hw switch
5967 * because the reset will make them disappear.
5969 ret
= i40e_pf_reset(hw
);
5971 dev_info(&pf
->pdev
->dev
, "PF reset failed, %d\n", ret
);
5972 set_bit(__I40E_RESET_FAILED
, &pf
->state
);
5973 goto clear_recovery
;
5977 if (test_bit(__I40E_DOWN
, &pf
->state
))
5978 goto clear_recovery
;
5979 dev_dbg(&pf
->pdev
->dev
, "Rebuilding internal switch\n");
5981 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
5982 ret
= i40e_init_adminq(&pf
->hw
);
5984 dev_info(&pf
->pdev
->dev
, "Rebuild AdminQ failed, %d\n", ret
);
5985 goto clear_recovery
;
5988 /* re-verify the eeprom if we just had an EMP reset */
5989 if (test_bit(__I40E_EMP_RESET_REQUESTED
, &pf
->state
)) {
5990 clear_bit(__I40E_EMP_RESET_REQUESTED
, &pf
->state
);
5991 i40e_verify_eeprom(pf
);
5994 i40e_clear_pxe_mode(hw
);
5995 ret
= i40e_get_capabilities(pf
);
5997 dev_info(&pf
->pdev
->dev
, "i40e_get_capabilities failed, %d\n",
5999 goto end_core_reset
;
6002 ret
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
6003 hw
->func_caps
.num_rx_qp
,
6004 pf
->fcoe_hmc_cntx_num
, pf
->fcoe_hmc_filt_num
);
6006 dev_info(&pf
->pdev
->dev
, "init_lan_hmc failed: %d\n", ret
);
6007 goto end_core_reset
;
6009 ret
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
6011 dev_info(&pf
->pdev
->dev
, "configure_lan_hmc failed: %d\n", ret
);
6012 goto end_core_reset
;
6015 #ifdef CONFIG_I40E_DCB
6016 ret
= i40e_init_pf_dcb(pf
);
6018 dev_info(&pf
->pdev
->dev
, "init_pf_dcb failed: %d\n", ret
);
6019 goto end_core_reset
;
6021 #endif /* CONFIG_I40E_DCB */
6023 ret
= i40e_init_pf_fcoe(pf
);
6025 dev_info(&pf
->pdev
->dev
, "init_pf_fcoe failed: %d\n", ret
);
6028 /* do basic switch setup */
6029 ret
= i40e_setup_pf_switch(pf
, reinit
);
6031 goto end_core_reset
;
6033 /* driver is only interested in link up/down and module qualification
6034 * reports from firmware
6036 ret
= i40e_aq_set_phy_int_mask(&pf
->hw
,
6037 I40E_AQ_EVENT_LINK_UPDOWN
|
6038 I40E_AQ_EVENT_MODULE_QUAL_FAIL
, NULL
);
6040 dev_info(&pf
->pdev
->dev
, "set phy mask fail, aq_err %d\n", ret
);
6042 /* make sure our flow control settings are restored */
6043 ret
= i40e_set_fc(&pf
->hw
, &set_fc_aq_fail
, true);
6045 dev_info(&pf
->pdev
->dev
, "set fc fail, aq_err %d\n", ret
);
6047 /* Rebuild the VSIs and VEBs that existed before reset.
6048 * They are still in our local switch element arrays, so only
6049 * need to rebuild the switch model in the HW.
6051 * If there were VEBs but the reconstitution failed, we'll try
6052 * try to recover minimal use by getting the basic PF VSI working.
6054 if (pf
->vsi
[pf
->lan_vsi
]->uplink_seid
!= pf
->mac_seid
) {
6055 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild switch\n");
6056 /* find the one VEB connected to the MAC, and find orphans */
6057 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
6061 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
||
6062 pf
->veb
[v
]->uplink_seid
== 0) {
6063 ret
= i40e_reconstitute_veb(pf
->veb
[v
]);
6068 /* If Main VEB failed, we're in deep doodoo,
6069 * so give up rebuilding the switch and set up
6070 * for minimal rebuild of PF VSI.
6071 * If orphan failed, we'll report the error
6072 * but try to keep going.
6074 if (pf
->veb
[v
]->uplink_seid
== pf
->mac_seid
) {
6075 dev_info(&pf
->pdev
->dev
,
6076 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
6078 pf
->vsi
[pf
->lan_vsi
]->uplink_seid
6081 } else if (pf
->veb
[v
]->uplink_seid
== 0) {
6082 dev_info(&pf
->pdev
->dev
,
6083 "rebuild of orphan VEB failed: %d\n",
6090 if (pf
->vsi
[pf
->lan_vsi
]->uplink_seid
== pf
->mac_seid
) {
6091 dev_dbg(&pf
->pdev
->dev
, "attempting to rebuild PF VSI\n");
6092 /* no VEB, so rebuild only the Main VSI */
6093 ret
= i40e_add_vsi(pf
->vsi
[pf
->lan_vsi
]);
6095 dev_info(&pf
->pdev
->dev
,
6096 "rebuild of Main VSI failed: %d\n", ret
);
6097 goto end_core_reset
;
6102 ret
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
6104 dev_info(&pf
->pdev
->dev
, "link restart failed, aq_err=%d\n",
6105 pf
->hw
.aq
.asq_last_status
);
6108 /* reinit the misc interrupt */
6109 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
6110 ret
= i40e_setup_misc_vector(pf
);
6112 /* restart the VSIs that were rebuilt and running before the reset */
6113 i40e_pf_unquiesce_all_vsi(pf
);
6115 if (pf
->num_alloc_vfs
) {
6116 for (v
= 0; v
< pf
->num_alloc_vfs
; v
++)
6117 i40e_reset_vf(&pf
->vf
[v
], true);
6120 /* tell the firmware that we're starting */
6121 i40e_send_version(pf
);
6124 clear_bit(__I40E_RESET_FAILED
, &pf
->state
);
6126 clear_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
);
6130 * i40e_handle_reset_warning - prep for the pf to reset, reset and rebuild
6131 * @pf: board private structure
6133 * Close up the VFs and other things in prep for a Core Reset,
6134 * then get ready to rebuild the world.
6136 static void i40e_handle_reset_warning(struct i40e_pf
*pf
)
6138 i40e_prep_for_reset(pf
);
6139 i40e_reset_and_rebuild(pf
, false);
6143 * i40e_handle_mdd_event
6144 * @pf: pointer to the pf structure
6146 * Called from the MDD irq handler to identify possibly malicious vfs
6148 static void i40e_handle_mdd_event(struct i40e_pf
*pf
)
6150 struct i40e_hw
*hw
= &pf
->hw
;
6151 bool mdd_detected
= false;
6152 bool pf_mdd_detected
= false;
6157 if (!test_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
))
6160 /* find what triggered the MDD event */
6161 reg
= rd32(hw
, I40E_GL_MDET_TX
);
6162 if (reg
& I40E_GL_MDET_TX_VALID_MASK
) {
6163 u8 pf_num
= (reg
& I40E_GL_MDET_TX_PF_NUM_MASK
) >>
6164 I40E_GL_MDET_TX_PF_NUM_SHIFT
;
6165 u8 vf_num
= (reg
& I40E_GL_MDET_TX_VF_NUM_MASK
) >>
6166 I40E_GL_MDET_TX_VF_NUM_SHIFT
;
6167 u8 event
= (reg
& I40E_GL_MDET_TX_EVENT_SHIFT
) >>
6168 I40E_GL_MDET_TX_EVENT_SHIFT
;
6169 u8 queue
= (reg
& I40E_GL_MDET_TX_QUEUE_MASK
) >>
6170 I40E_GL_MDET_TX_QUEUE_SHIFT
;
6171 if (netif_msg_tx_err(pf
))
6172 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on TX queue %d pf number 0x%02x vf number 0x%02x\n",
6173 event
, queue
, pf_num
, vf_num
);
6174 wr32(hw
, I40E_GL_MDET_TX
, 0xffffffff);
6175 mdd_detected
= true;
6177 reg
= rd32(hw
, I40E_GL_MDET_RX
);
6178 if (reg
& I40E_GL_MDET_RX_VALID_MASK
) {
6179 u8 func
= (reg
& I40E_GL_MDET_RX_FUNCTION_MASK
) >>
6180 I40E_GL_MDET_RX_FUNCTION_SHIFT
;
6181 u8 event
= (reg
& I40E_GL_MDET_RX_EVENT_SHIFT
) >>
6182 I40E_GL_MDET_RX_EVENT_SHIFT
;
6183 u8 queue
= (reg
& I40E_GL_MDET_RX_QUEUE_MASK
) >>
6184 I40E_GL_MDET_RX_QUEUE_SHIFT
;
6185 if (netif_msg_rx_err(pf
))
6186 dev_info(&pf
->pdev
->dev
, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
6187 event
, queue
, func
);
6188 wr32(hw
, I40E_GL_MDET_RX
, 0xffffffff);
6189 mdd_detected
= true;
6193 reg
= rd32(hw
, I40E_PF_MDET_TX
);
6194 if (reg
& I40E_PF_MDET_TX_VALID_MASK
) {
6195 wr32(hw
, I40E_PF_MDET_TX
, 0xFFFF);
6196 dev_info(&pf
->pdev
->dev
, "TX driver issue detected, PF reset issued\n");
6197 pf_mdd_detected
= true;
6199 reg
= rd32(hw
, I40E_PF_MDET_RX
);
6200 if (reg
& I40E_PF_MDET_RX_VALID_MASK
) {
6201 wr32(hw
, I40E_PF_MDET_RX
, 0xFFFF);
6202 dev_info(&pf
->pdev
->dev
, "RX driver issue detected, PF reset issued\n");
6203 pf_mdd_detected
= true;
6205 /* Queue belongs to the PF, initiate a reset */
6206 if (pf_mdd_detected
) {
6207 set_bit(__I40E_PF_RESET_REQUESTED
, &pf
->state
);
6208 i40e_service_event_schedule(pf
);
6212 /* see if one of the VFs needs its hand slapped */
6213 for (i
= 0; i
< pf
->num_alloc_vfs
&& mdd_detected
; i
++) {
6215 reg
= rd32(hw
, I40E_VP_MDET_TX(i
));
6216 if (reg
& I40E_VP_MDET_TX_VALID_MASK
) {
6217 wr32(hw
, I40E_VP_MDET_TX(i
), 0xFFFF);
6218 vf
->num_mdd_events
++;
6219 dev_info(&pf
->pdev
->dev
, "TX driver issue detected on VF %d\n",
6223 reg
= rd32(hw
, I40E_VP_MDET_RX(i
));
6224 if (reg
& I40E_VP_MDET_RX_VALID_MASK
) {
6225 wr32(hw
, I40E_VP_MDET_RX(i
), 0xFFFF);
6226 vf
->num_mdd_events
++;
6227 dev_info(&pf
->pdev
->dev
, "RX driver issue detected on VF %d\n",
6231 if (vf
->num_mdd_events
> I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED
) {
6232 dev_info(&pf
->pdev
->dev
,
6233 "Too many MDD events on VF %d, disabled\n", i
);
6234 dev_info(&pf
->pdev
->dev
,
6235 "Use PF Control I/F to re-enable the VF\n");
6236 set_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
);
6240 /* re-enable mdd interrupt cause */
6241 clear_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
);
6242 reg
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
6243 reg
|= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK
;
6244 wr32(hw
, I40E_PFINT_ICR0_ENA
, reg
);
6248 #ifdef CONFIG_I40E_VXLAN
6250 * i40e_sync_vxlan_filters_subtask - Sync the VSI filter list with HW
6251 * @pf: board private structure
6253 static void i40e_sync_vxlan_filters_subtask(struct i40e_pf
*pf
)
6255 struct i40e_hw
*hw
= &pf
->hw
;
6261 if (!(pf
->flags
& I40E_FLAG_VXLAN_FILTER_SYNC
))
6264 pf
->flags
&= ~I40E_FLAG_VXLAN_FILTER_SYNC
;
6266 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
6267 if (pf
->pending_vxlan_bitmap
& (1 << i
)) {
6268 pf
->pending_vxlan_bitmap
&= ~(1 << i
);
6269 port
= pf
->vxlan_ports
[i
];
6271 i40e_aq_add_udp_tunnel(hw
, ntohs(port
),
6272 I40E_AQC_TUNNEL_TYPE_VXLAN
,
6273 &filter_index
, NULL
)
6274 : i40e_aq_del_udp_tunnel(hw
, i
, NULL
);
6277 dev_info(&pf
->pdev
->dev
, "Failed to execute AQ command for %s port %d with index %d\n",
6278 port
? "adding" : "deleting",
6279 ntohs(port
), port
? i
: i
);
6281 pf
->vxlan_ports
[i
] = 0;
6283 dev_info(&pf
->pdev
->dev
, "%s port %d with AQ command with index %d\n",
6284 port
? "Added" : "Deleted",
6285 ntohs(port
), port
? i
: filter_index
);
6293 * i40e_service_task - Run the driver's async subtasks
6294 * @work: pointer to work_struct containing our data
6296 static void i40e_service_task(struct work_struct
*work
)
6298 struct i40e_pf
*pf
= container_of(work
,
6301 unsigned long start_time
= jiffies
;
6303 /* don't bother with service tasks if a reset is in progress */
6304 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
)) {
6305 i40e_service_event_complete(pf
);
6309 i40e_reset_subtask(pf
);
6310 i40e_handle_mdd_event(pf
);
6311 i40e_vc_process_vflr_event(pf
);
6312 i40e_watchdog_subtask(pf
);
6313 i40e_fdir_reinit_subtask(pf
);
6314 i40e_check_hang_subtask(pf
);
6315 i40e_sync_filters_subtask(pf
);
6316 #ifdef CONFIG_I40E_VXLAN
6317 i40e_sync_vxlan_filters_subtask(pf
);
6319 i40e_clean_adminq_subtask(pf
);
6321 i40e_link_event(pf
);
6323 i40e_service_event_complete(pf
);
6325 /* If the tasks have taken longer than one timer cycle or there
6326 * is more work to be done, reschedule the service task now
6327 * rather than wait for the timer to tick again.
6329 if (time_after(jiffies
, (start_time
+ pf
->service_timer_period
)) ||
6330 test_bit(__I40E_ADMINQ_EVENT_PENDING
, &pf
->state
) ||
6331 test_bit(__I40E_MDD_EVENT_PENDING
, &pf
->state
) ||
6332 test_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
))
6333 i40e_service_event_schedule(pf
);
6337 * i40e_service_timer - timer callback
6338 * @data: pointer to PF struct
6340 static void i40e_service_timer(unsigned long data
)
6342 struct i40e_pf
*pf
= (struct i40e_pf
*)data
;
6344 mod_timer(&pf
->service_timer
,
6345 round_jiffies(jiffies
+ pf
->service_timer_period
));
6346 i40e_service_event_schedule(pf
);
6350 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
6351 * @vsi: the VSI being configured
6353 static int i40e_set_num_rings_in_vsi(struct i40e_vsi
*vsi
)
6355 struct i40e_pf
*pf
= vsi
->back
;
6357 switch (vsi
->type
) {
6359 vsi
->alloc_queue_pairs
= pf
->num_lan_qps
;
6360 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
6361 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6362 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
6363 vsi
->num_q_vectors
= pf
->num_lan_msix
;
6365 vsi
->num_q_vectors
= 1;
6370 vsi
->alloc_queue_pairs
= 1;
6371 vsi
->num_desc
= ALIGN(I40E_FDIR_RING_COUNT
,
6372 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6373 vsi
->num_q_vectors
= 1;
6376 case I40E_VSI_VMDQ2
:
6377 vsi
->alloc_queue_pairs
= pf
->num_vmdq_qps
;
6378 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
6379 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6380 vsi
->num_q_vectors
= pf
->num_vmdq_msix
;
6383 case I40E_VSI_SRIOV
:
6384 vsi
->alloc_queue_pairs
= pf
->num_vf_qps
;
6385 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
6386 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6391 vsi
->alloc_queue_pairs
= pf
->num_fcoe_qps
;
6392 vsi
->num_desc
= ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS
,
6393 I40E_REQ_DESCRIPTOR_MULTIPLE
);
6394 vsi
->num_q_vectors
= pf
->num_fcoe_msix
;
6397 #endif /* I40E_FCOE */
6407 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
6408 * @type: VSI pointer
6409 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
6411 * On error: returns error code (negative)
6412 * On success: returns 0
6414 static int i40e_vsi_alloc_arrays(struct i40e_vsi
*vsi
, bool alloc_qvectors
)
6419 /* allocate memory for both Tx and Rx ring pointers */
6420 size
= sizeof(struct i40e_ring
*) * vsi
->alloc_queue_pairs
* 2;
6421 vsi
->tx_rings
= kzalloc(size
, GFP_KERNEL
);
6424 vsi
->rx_rings
= &vsi
->tx_rings
[vsi
->alloc_queue_pairs
];
6426 if (alloc_qvectors
) {
6427 /* allocate memory for q_vector pointers */
6428 size
= sizeof(struct i40e_q_vector
*) * vsi
->num_q_vectors
;
6429 vsi
->q_vectors
= kzalloc(size
, GFP_KERNEL
);
6430 if (!vsi
->q_vectors
) {
6438 kfree(vsi
->tx_rings
);
6443 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
6444 * @pf: board private structure
6445 * @type: type of VSI
6447 * On error: returns error code (negative)
6448 * On success: returns vsi index in PF (positive)
6450 static int i40e_vsi_mem_alloc(struct i40e_pf
*pf
, enum i40e_vsi_type type
)
6453 struct i40e_vsi
*vsi
;
6457 /* Need to protect the allocation of the VSIs at the PF level */
6458 mutex_lock(&pf
->switch_mutex
);
6460 /* VSI list may be fragmented if VSI creation/destruction has
6461 * been happening. We can afford to do a quick scan to look
6462 * for any free VSIs in the list.
6464 * find next empty vsi slot, looping back around if necessary
6467 while (i
< pf
->num_alloc_vsi
&& pf
->vsi
[i
])
6469 if (i
>= pf
->num_alloc_vsi
) {
6471 while (i
< pf
->next_vsi
&& pf
->vsi
[i
])
6475 if (i
< pf
->num_alloc_vsi
&& !pf
->vsi
[i
]) {
6476 vsi_idx
= i
; /* Found one! */
6479 goto unlock_pf
; /* out of VSI slots! */
6483 vsi
= kzalloc(sizeof(*vsi
), GFP_KERNEL
);
6490 set_bit(__I40E_DOWN
, &vsi
->state
);
6493 vsi
->rx_itr_setting
= pf
->rx_itr_default
;
6494 vsi
->tx_itr_setting
= pf
->tx_itr_default
;
6495 vsi
->netdev_registered
= false;
6496 vsi
->work_limit
= I40E_DEFAULT_IRQ_WORK
;
6497 INIT_LIST_HEAD(&vsi
->mac_filter_list
);
6498 vsi
->irqs_ready
= false;
6500 ret
= i40e_set_num_rings_in_vsi(vsi
);
6504 ret
= i40e_vsi_alloc_arrays(vsi
, true);
6508 /* Setup default MSIX irq handler for VSI */
6509 i40e_vsi_setup_irqhandler(vsi
, i40e_msix_clean_rings
);
6511 pf
->vsi
[vsi_idx
] = vsi
;
6516 pf
->next_vsi
= i
- 1;
6519 mutex_unlock(&pf
->switch_mutex
);
6524 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
6525 * @type: VSI pointer
6526 * @free_qvectors: a bool to specify if q_vectors need to be freed.
6528 * On error: returns error code (negative)
6529 * On success: returns 0
6531 static void i40e_vsi_free_arrays(struct i40e_vsi
*vsi
, bool free_qvectors
)
6533 /* free the ring and vector containers */
6534 if (free_qvectors
) {
6535 kfree(vsi
->q_vectors
);
6536 vsi
->q_vectors
= NULL
;
6538 kfree(vsi
->tx_rings
);
6539 vsi
->tx_rings
= NULL
;
6540 vsi
->rx_rings
= NULL
;
6544 * i40e_vsi_clear - Deallocate the VSI provided
6545 * @vsi: the VSI being un-configured
6547 static int i40e_vsi_clear(struct i40e_vsi
*vsi
)
6558 mutex_lock(&pf
->switch_mutex
);
6559 if (!pf
->vsi
[vsi
->idx
]) {
6560 dev_err(&pf
->pdev
->dev
, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
6561 vsi
->idx
, vsi
->idx
, vsi
, vsi
->type
);
6565 if (pf
->vsi
[vsi
->idx
] != vsi
) {
6566 dev_err(&pf
->pdev
->dev
,
6567 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
6568 pf
->vsi
[vsi
->idx
]->idx
,
6570 pf
->vsi
[vsi
->idx
]->type
,
6571 vsi
->idx
, vsi
, vsi
->type
);
6575 /* updates the pf for this cleared vsi */
6576 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
6577 i40e_put_lump(pf
->irq_pile
, vsi
->base_vector
, vsi
->idx
);
6579 i40e_vsi_free_arrays(vsi
, true);
6581 pf
->vsi
[vsi
->idx
] = NULL
;
6582 if (vsi
->idx
< pf
->next_vsi
)
6583 pf
->next_vsi
= vsi
->idx
;
6586 mutex_unlock(&pf
->switch_mutex
);
6594 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
6595 * @vsi: the VSI being cleaned
6597 static void i40e_vsi_clear_rings(struct i40e_vsi
*vsi
)
6601 if (vsi
->tx_rings
&& vsi
->tx_rings
[0]) {
6602 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
6603 kfree_rcu(vsi
->tx_rings
[i
], rcu
);
6604 vsi
->tx_rings
[i
] = NULL
;
6605 vsi
->rx_rings
[i
] = NULL
;
6611 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
6612 * @vsi: the VSI being configured
6614 static int i40e_alloc_rings(struct i40e_vsi
*vsi
)
6616 struct i40e_ring
*tx_ring
, *rx_ring
;
6617 struct i40e_pf
*pf
= vsi
->back
;
6620 /* Set basic values in the rings to be used later during open() */
6621 for (i
= 0; i
< vsi
->alloc_queue_pairs
; i
++) {
6622 /* allocate space for both Tx and Rx in one shot */
6623 tx_ring
= kzalloc(sizeof(struct i40e_ring
) * 2, GFP_KERNEL
);
6627 tx_ring
->queue_index
= i
;
6628 tx_ring
->reg_idx
= vsi
->base_queue
+ i
;
6629 tx_ring
->ring_active
= false;
6631 tx_ring
->netdev
= vsi
->netdev
;
6632 tx_ring
->dev
= &pf
->pdev
->dev
;
6633 tx_ring
->count
= vsi
->num_desc
;
6635 tx_ring
->dcb_tc
= 0;
6636 vsi
->tx_rings
[i
] = tx_ring
;
6638 rx_ring
= &tx_ring
[1];
6639 rx_ring
->queue_index
= i
;
6640 rx_ring
->reg_idx
= vsi
->base_queue
+ i
;
6641 rx_ring
->ring_active
= false;
6643 rx_ring
->netdev
= vsi
->netdev
;
6644 rx_ring
->dev
= &pf
->pdev
->dev
;
6645 rx_ring
->count
= vsi
->num_desc
;
6647 rx_ring
->dcb_tc
= 0;
6648 if (pf
->flags
& I40E_FLAG_16BYTE_RX_DESC_ENABLED
)
6649 set_ring_16byte_desc_enabled(rx_ring
);
6651 clear_ring_16byte_desc_enabled(rx_ring
);
6652 vsi
->rx_rings
[i
] = rx_ring
;
6658 i40e_vsi_clear_rings(vsi
);
6663 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
6664 * @pf: board private structure
6665 * @vectors: the number of MSI-X vectors to request
6667 * Returns the number of vectors reserved, or error
6669 static int i40e_reserve_msix_vectors(struct i40e_pf
*pf
, int vectors
)
6671 vectors
= pci_enable_msix_range(pf
->pdev
, pf
->msix_entries
,
6672 I40E_MIN_MSIX
, vectors
);
6674 dev_info(&pf
->pdev
->dev
,
6675 "MSI-X vector reservation failed: %d\n", vectors
);
6683 * i40e_init_msix - Setup the MSIX capability
6684 * @pf: board private structure
6686 * Work with the OS to set up the MSIX vectors needed.
6688 * Returns 0 on success, negative on failure
6690 static int i40e_init_msix(struct i40e_pf
*pf
)
6692 i40e_status err
= 0;
6693 struct i40e_hw
*hw
= &pf
->hw
;
6697 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
))
6700 /* The number of vectors we'll request will be comprised of:
6701 * - Add 1 for "other" cause for Admin Queue events, etc.
6702 * - The number of LAN queue pairs
6703 * - Queues being used for RSS.
6704 * We don't need as many as max_rss_size vectors.
6705 * use rss_size instead in the calculation since that
6706 * is governed by number of cpus in the system.
6707 * - assumes symmetric Tx/Rx pairing
6708 * - The number of VMDq pairs
6710 * - The number of FCOE qps.
6712 * Once we count this up, try the request.
6714 * If we can't get what we want, we'll simplify to nearly nothing
6715 * and try again. If that still fails, we punt.
6717 pf
->num_lan_msix
= pf
->num_lan_qps
- (pf
->rss_size_max
- pf
->rss_size
);
6718 pf
->num_vmdq_msix
= pf
->num_vmdq_qps
;
6719 v_budget
= 1 + pf
->num_lan_msix
;
6720 v_budget
+= (pf
->num_vmdq_vsis
* pf
->num_vmdq_msix
);
6721 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
)
6725 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
6726 pf
->num_fcoe_msix
= pf
->num_fcoe_qps
;
6727 v_budget
+= pf
->num_fcoe_msix
;
6731 /* Scale down if necessary, and the rings will share vectors */
6732 v_budget
= min_t(int, v_budget
, hw
->func_caps
.num_msix_vectors
);
6734 pf
->msix_entries
= kcalloc(v_budget
, sizeof(struct msix_entry
),
6736 if (!pf
->msix_entries
)
6739 for (i
= 0; i
< v_budget
; i
++)
6740 pf
->msix_entries
[i
].entry
= i
;
6741 vec
= i40e_reserve_msix_vectors(pf
, v_budget
);
6743 if (vec
!= v_budget
) {
6744 /* If we have limited resources, we will start with no vectors
6745 * for the special features and then allocate vectors to some
6746 * of these features based on the policy and at the end disable
6747 * the features that did not get any vectors.
6750 pf
->num_fcoe_qps
= 0;
6751 pf
->num_fcoe_msix
= 0;
6753 pf
->num_vmdq_msix
= 0;
6756 if (vec
< I40E_MIN_MSIX
) {
6757 pf
->flags
&= ~I40E_FLAG_MSIX_ENABLED
;
6758 kfree(pf
->msix_entries
);
6759 pf
->msix_entries
= NULL
;
6762 } else if (vec
== I40E_MIN_MSIX
) {
6763 /* Adjust for minimal MSIX use */
6764 pf
->num_vmdq_vsis
= 0;
6765 pf
->num_vmdq_qps
= 0;
6766 pf
->num_lan_qps
= 1;
6767 pf
->num_lan_msix
= 1;
6769 } else if (vec
!= v_budget
) {
6770 /* reserve the misc vector */
6773 /* Scale vector usage down */
6774 pf
->num_vmdq_msix
= 1; /* force VMDqs to only one vector */
6775 pf
->num_vmdq_vsis
= 1;
6777 /* partition out the remaining vectors */
6780 pf
->num_lan_msix
= 1;
6784 /* give one vector to FCoE */
6785 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
6786 pf
->num_lan_msix
= 1;
6787 pf
->num_fcoe_msix
= 1;
6790 pf
->num_lan_msix
= 2;
6795 /* give one vector to FCoE */
6796 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
6797 pf
->num_fcoe_msix
= 1;
6801 pf
->num_lan_msix
= min_t(int, (vec
/ 2),
6803 pf
->num_vmdq_vsis
= min_t(int, (vec
- pf
->num_lan_msix
),
6804 I40E_DEFAULT_NUM_VMDQ_VSI
);
6809 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
6810 (pf
->num_vmdq_msix
== 0)) {
6811 dev_info(&pf
->pdev
->dev
, "VMDq disabled, not enough MSI-X vectors\n");
6812 pf
->flags
&= ~I40E_FLAG_VMDQ_ENABLED
;
6816 if ((pf
->flags
& I40E_FLAG_FCOE_ENABLED
) && (pf
->num_fcoe_msix
== 0)) {
6817 dev_info(&pf
->pdev
->dev
, "FCOE disabled, not enough MSI-X vectors\n");
6818 pf
->flags
&= ~I40E_FLAG_FCOE_ENABLED
;
6825 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
6826 * @vsi: the VSI being configured
6827 * @v_idx: index of the vector in the vsi struct
6829 * We allocate one q_vector. If allocation fails we return -ENOMEM.
6831 static int i40e_vsi_alloc_q_vector(struct i40e_vsi
*vsi
, int v_idx
)
6833 struct i40e_q_vector
*q_vector
;
6835 /* allocate q_vector */
6836 q_vector
= kzalloc(sizeof(struct i40e_q_vector
), GFP_KERNEL
);
6840 q_vector
->vsi
= vsi
;
6841 q_vector
->v_idx
= v_idx
;
6842 cpumask_set_cpu(v_idx
, &q_vector
->affinity_mask
);
6844 netif_napi_add(vsi
->netdev
, &q_vector
->napi
,
6845 i40e_napi_poll
, NAPI_POLL_WEIGHT
);
6847 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
6848 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
6850 /* tie q_vector and vsi together */
6851 vsi
->q_vectors
[v_idx
] = q_vector
;
6857 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
6858 * @vsi: the VSI being configured
6860 * We allocate one q_vector per queue interrupt. If allocation fails we
6863 static int i40e_vsi_alloc_q_vectors(struct i40e_vsi
*vsi
)
6865 struct i40e_pf
*pf
= vsi
->back
;
6866 int v_idx
, num_q_vectors
;
6869 /* if not MSIX, give the one vector only to the LAN VSI */
6870 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
)
6871 num_q_vectors
= vsi
->num_q_vectors
;
6872 else if (vsi
== pf
->vsi
[pf
->lan_vsi
])
6877 for (v_idx
= 0; v_idx
< num_q_vectors
; v_idx
++) {
6878 err
= i40e_vsi_alloc_q_vector(vsi
, v_idx
);
6887 i40e_free_q_vector(vsi
, v_idx
);
6893 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
6894 * @pf: board private structure to initialize
6896 static void i40e_init_interrupt_scheme(struct i40e_pf
*pf
)
6900 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
6901 err
= i40e_init_msix(pf
);
6903 pf
->flags
&= ~(I40E_FLAG_MSIX_ENABLED
|
6905 I40E_FLAG_FCOE_ENABLED
|
6907 I40E_FLAG_RSS_ENABLED
|
6908 I40E_FLAG_DCB_CAPABLE
|
6909 I40E_FLAG_SRIOV_ENABLED
|
6910 I40E_FLAG_FD_SB_ENABLED
|
6911 I40E_FLAG_FD_ATR_ENABLED
|
6912 I40E_FLAG_VMDQ_ENABLED
);
6914 /* rework the queue expectations without MSIX */
6915 i40e_determine_queue_usage(pf
);
6919 if (!(pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
6920 (pf
->flags
& I40E_FLAG_MSI_ENABLED
)) {
6921 dev_info(&pf
->pdev
->dev
, "MSI-X not available, trying MSI\n");
6922 err
= pci_enable_msi(pf
->pdev
);
6924 dev_info(&pf
->pdev
->dev
, "MSI init failed - %d\n", err
);
6925 pf
->flags
&= ~I40E_FLAG_MSI_ENABLED
;
6929 if (!(pf
->flags
& (I40E_FLAG_MSIX_ENABLED
| I40E_FLAG_MSI_ENABLED
)))
6930 dev_info(&pf
->pdev
->dev
, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
6932 /* track first vector for misc interrupts */
6933 err
= i40e_get_lump(pf
, pf
->irq_pile
, 1, I40E_PILE_VALID_BIT
-1);
6937 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
6938 * @pf: board private structure
6940 * This sets up the handler for MSIX 0, which is used to manage the
6941 * non-queue interrupts, e.g. AdminQ and errors. This is not used
6942 * when in MSI or Legacy interrupt mode.
6944 static int i40e_setup_misc_vector(struct i40e_pf
*pf
)
6946 struct i40e_hw
*hw
= &pf
->hw
;
6949 /* Only request the irq if this is the first time through, and
6950 * not when we're rebuilding after a Reset
6952 if (!test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
)) {
6953 err
= request_irq(pf
->msix_entries
[0].vector
,
6954 i40e_intr
, 0, pf
->misc_int_name
, pf
);
6956 dev_info(&pf
->pdev
->dev
,
6957 "request_irq for %s failed: %d\n",
6958 pf
->misc_int_name
, err
);
6963 i40e_enable_misc_int_causes(hw
);
6965 /* associate no queues to the misc vector */
6966 wr32(hw
, I40E_PFINT_LNKLST0
, I40E_QUEUE_END_OF_LIST
);
6967 wr32(hw
, I40E_PFINT_ITR0(I40E_RX_ITR
), I40E_ITR_8K
);
6971 i40e_irq_dynamic_enable_icr0(pf
);
6977 * i40e_config_rss - Prepare for RSS if used
6978 * @pf: board private structure
6980 static int i40e_config_rss(struct i40e_pf
*pf
)
6982 /* Set of random keys generated using kernel random number generator */
6983 static const u32 seed
[I40E_PFQF_HKEY_MAX_INDEX
+ 1] = {0x41b01687,
6984 0x183cfd8c, 0xce880440, 0x580cbc3c, 0x35897377,
6985 0x328b25e1, 0x4fa98922, 0xb7d90c14, 0xd5bad70d,
6986 0xcd15a2c1, 0xe8580225, 0x4a1e9d11, 0xfe5731be};
6987 struct i40e_hw
*hw
= &pf
->hw
;
6993 /* Fill out hash function seed */
6994 for (i
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++)
6995 wr32(hw
, I40E_PFQF_HKEY(i
), seed
[i
]);
6997 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
6998 hena
= (u64
)rd32(hw
, I40E_PFQF_HENA(0)) |
6999 ((u64
)rd32(hw
, I40E_PFQF_HENA(1)) << 32);
7000 hena
|= I40E_DEFAULT_RSS_HENA
;
7001 wr32(hw
, I40E_PFQF_HENA(0), (u32
)hena
);
7002 wr32(hw
, I40E_PFQF_HENA(1), (u32
)(hena
>> 32));
7004 /* Check capability and Set table size and register per hw expectation*/
7005 reg_val
= rd32(hw
, I40E_PFQF_CTL_0
);
7006 if (hw
->func_caps
.rss_table_size
== 512) {
7007 reg_val
|= I40E_PFQF_CTL_0_HASHLUTSIZE_512
;
7008 pf
->rss_table_size
= 512;
7010 pf
->rss_table_size
= 128;
7011 reg_val
&= ~I40E_PFQF_CTL_0_HASHLUTSIZE_512
;
7013 wr32(hw
, I40E_PFQF_CTL_0
, reg_val
);
7015 /* Populate the LUT with max no. of queues in round robin fashion */
7016 for (i
= 0, j
= 0; i
< pf
->rss_table_size
; i
++, j
++) {
7018 /* The assumption is that lan qp count will be the highest
7019 * qp count for any PF VSI that needs RSS.
7020 * If multiple VSIs need RSS support, all the qp counts
7021 * for those VSIs should be a power of 2 for RSS to work.
7022 * If LAN VSI is the only consumer for RSS then this requirement
7025 if (j
== pf
->rss_size
)
7027 /* lut = 4-byte sliding window of 4 lut entries */
7028 lut
= (lut
<< 8) | (j
&
7029 ((0x1 << pf
->hw
.func_caps
.rss_table_entry_width
) - 1));
7030 /* On i = 3, we have 4 entries in lut; write to the register */
7032 wr32(hw
, I40E_PFQF_HLUT(i
>> 2), lut
);
7040 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
7041 * @pf: board private structure
7042 * @queue_count: the requested queue count for rss.
7044 * returns 0 if rss is not enabled, if enabled returns the final rss queue
7045 * count which may be different from the requested queue count.
7047 int i40e_reconfig_rss_queues(struct i40e_pf
*pf
, int queue_count
)
7049 if (!(pf
->flags
& I40E_FLAG_RSS_ENABLED
))
7052 queue_count
= min_t(int, queue_count
, pf
->rss_size_max
);
7054 if (queue_count
!= pf
->rss_size
) {
7055 i40e_prep_for_reset(pf
);
7057 pf
->rss_size
= queue_count
;
7059 i40e_reset_and_rebuild(pf
, true);
7060 i40e_config_rss(pf
);
7062 dev_info(&pf
->pdev
->dev
, "RSS count: %d\n", pf
->rss_size
);
7063 return pf
->rss_size
;
7067 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
7068 * @pf: board private structure to initialize
7070 * i40e_sw_init initializes the Adapter private data structure.
7071 * Fields are initialized based on PCI device information and
7072 * OS network device settings (MTU size).
7074 static int i40e_sw_init(struct i40e_pf
*pf
)
7079 pf
->msg_enable
= netif_msg_init(I40E_DEFAULT_MSG_ENABLE
,
7080 (NETIF_MSG_DRV
|NETIF_MSG_PROBE
|NETIF_MSG_LINK
));
7081 pf
->hw
.debug_mask
= pf
->msg_enable
| I40E_DEBUG_DIAG
;
7082 if (debug
!= -1 && debug
!= I40E_DEFAULT_MSG_ENABLE
) {
7083 if (I40E_DEBUG_USER
& debug
)
7084 pf
->hw
.debug_mask
= debug
;
7085 pf
->msg_enable
= netif_msg_init((debug
& ~I40E_DEBUG_USER
),
7086 I40E_DEFAULT_MSG_ENABLE
);
7089 /* Set default capability flags */
7090 pf
->flags
= I40E_FLAG_RX_CSUM_ENABLED
|
7091 I40E_FLAG_MSI_ENABLED
|
7092 I40E_FLAG_MSIX_ENABLED
|
7093 I40E_FLAG_RX_1BUF_ENABLED
;
7095 /* Set default ITR */
7096 pf
->rx_itr_default
= I40E_ITR_DYNAMIC
| I40E_ITR_RX_DEF
;
7097 pf
->tx_itr_default
= I40E_ITR_DYNAMIC
| I40E_ITR_TX_DEF
;
7099 /* Depending on PF configurations, it is possible that the RSS
7100 * maximum might end up larger than the available queues
7102 pf
->rss_size_max
= 0x1 << pf
->hw
.func_caps
.rss_table_entry_width
;
7104 pf
->rss_size_max
= min_t(int, pf
->rss_size_max
,
7105 pf
->hw
.func_caps
.num_tx_qp
);
7106 if (pf
->hw
.func_caps
.rss
) {
7107 pf
->flags
|= I40E_FLAG_RSS_ENABLED
;
7108 pf
->rss_size
= min_t(int, pf
->rss_size_max
, num_online_cpus());
7111 /* MFP mode enabled */
7112 if (pf
->hw
.func_caps
.npar_enable
|| pf
->hw
.func_caps
.mfp_mode_1
) {
7113 pf
->flags
|= I40E_FLAG_MFP_ENABLED
;
7114 dev_info(&pf
->pdev
->dev
, "MFP mode Enabled\n");
7117 /* FW/NVM is not yet fixed in this regard */
7118 if ((pf
->hw
.func_caps
.fd_filters_guaranteed
> 0) ||
7119 (pf
->hw
.func_caps
.fd_filters_best_effort
> 0)) {
7120 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
7121 pf
->atr_sample_rate
= I40E_DEFAULT_ATR_SAMPLE_RATE
;
7122 /* Setup a counter for fd_atr per pf */
7123 pf
->fd_atr_cnt_idx
= I40E_FD_ATR_STAT_IDX(pf
->hw
.pf_id
);
7124 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
)) {
7125 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
7126 /* Setup a counter for fd_sb per pf */
7127 pf
->fd_sb_cnt_idx
= I40E_FD_SB_STAT_IDX(pf
->hw
.pf_id
);
7129 dev_info(&pf
->pdev
->dev
,
7130 "Flow Director Sideband mode Disabled in MFP mode\n");
7132 pf
->fdir_pf_filter_count
=
7133 pf
->hw
.func_caps
.fd_filters_guaranteed
;
7134 pf
->hw
.fdir_shared_filter_count
=
7135 pf
->hw
.func_caps
.fd_filters_best_effort
;
7138 if (pf
->hw
.func_caps
.vmdq
) {
7139 pf
->flags
|= I40E_FLAG_VMDQ_ENABLED
;
7140 pf
->num_vmdq_vsis
= I40E_DEFAULT_NUM_VMDQ_VSI
;
7141 pf
->num_vmdq_qps
= I40E_DEFAULT_QUEUES_PER_VMDQ
;
7145 err
= i40e_init_pf_fcoe(pf
);
7147 dev_info(&pf
->pdev
->dev
, "init_pf_fcoe failed: %d\n", err
);
7149 #endif /* I40E_FCOE */
7150 #ifdef CONFIG_PCI_IOV
7151 if (pf
->hw
.func_caps
.num_vfs
) {
7152 pf
->num_vf_qps
= I40E_DEFAULT_QUEUES_PER_VF
;
7153 pf
->flags
|= I40E_FLAG_SRIOV_ENABLED
;
7154 pf
->num_req_vfs
= min_t(int,
7155 pf
->hw
.func_caps
.num_vfs
,
7158 #endif /* CONFIG_PCI_IOV */
7159 pf
->eeprom_version
= 0xDEAD;
7160 pf
->lan_veb
= I40E_NO_VEB
;
7161 pf
->lan_vsi
= I40E_NO_VSI
;
7163 /* set up queue assignment tracking */
7164 size
= sizeof(struct i40e_lump_tracking
)
7165 + (sizeof(u16
) * pf
->hw
.func_caps
.num_tx_qp
);
7166 pf
->qp_pile
= kzalloc(size
, GFP_KERNEL
);
7171 pf
->qp_pile
->num_entries
= pf
->hw
.func_caps
.num_tx_qp
;
7172 pf
->qp_pile
->search_hint
= 0;
7174 /* set up vector assignment tracking */
7175 size
= sizeof(struct i40e_lump_tracking
)
7176 + (sizeof(u16
) * pf
->hw
.func_caps
.num_msix_vectors
);
7177 pf
->irq_pile
= kzalloc(size
, GFP_KERNEL
);
7178 if (!pf
->irq_pile
) {
7183 pf
->irq_pile
->num_entries
= pf
->hw
.func_caps
.num_msix_vectors
;
7184 pf
->irq_pile
->search_hint
= 0;
7186 pf
->tx_timeout_recovery_level
= 1;
7188 mutex_init(&pf
->switch_mutex
);
7195 * i40e_set_ntuple - set the ntuple feature flag and take action
7196 * @pf: board private structure to initialize
7197 * @features: the feature set that the stack is suggesting
7199 * returns a bool to indicate if reset needs to happen
7201 bool i40e_set_ntuple(struct i40e_pf
*pf
, netdev_features_t features
)
7203 bool need_reset
= false;
7205 /* Check if Flow Director n-tuple support was enabled or disabled. If
7206 * the state changed, we need to reset.
7208 if (features
& NETIF_F_NTUPLE
) {
7209 /* Enable filters and mark for reset */
7210 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
7212 pf
->flags
|= I40E_FLAG_FD_SB_ENABLED
;
7214 /* turn off filters, mark for reset and clear SW filter list */
7215 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
7217 i40e_fdir_filter_exit(pf
);
7219 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7220 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
7221 /* reset fd counters */
7222 pf
->fd_add_err
= pf
->fd_atr_cnt
= pf
->fd_tcp_rule
= 0;
7223 pf
->fdir_pf_active_filters
= 0;
7224 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
7225 dev_info(&pf
->pdev
->dev
, "ATR re-enabled.\n");
7226 /* if ATR was auto disabled it can be re-enabled. */
7227 if ((pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
) &&
7228 (pf
->auto_disable_flags
& I40E_FLAG_FD_ATR_ENABLED
))
7229 pf
->auto_disable_flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
7235 * i40e_set_features - set the netdev feature flags
7236 * @netdev: ptr to the netdev being adjusted
7237 * @features: the feature set that the stack is suggesting
7239 static int i40e_set_features(struct net_device
*netdev
,
7240 netdev_features_t features
)
7242 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7243 struct i40e_vsi
*vsi
= np
->vsi
;
7244 struct i40e_pf
*pf
= vsi
->back
;
7247 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
7248 i40e_vlan_stripping_enable(vsi
);
7250 i40e_vlan_stripping_disable(vsi
);
7252 need_reset
= i40e_set_ntuple(pf
, features
);
7255 i40e_do_reset(pf
, (1 << __I40E_PF_RESET_REQUESTED
));
7260 #ifdef CONFIG_I40E_VXLAN
7262 * i40e_get_vxlan_port_idx - Lookup a possibly offloaded for Rx UDP port
7263 * @pf: board private structure
7264 * @port: The UDP port to look up
7266 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
7268 static u8
i40e_get_vxlan_port_idx(struct i40e_pf
*pf
, __be16 port
)
7272 for (i
= 0; i
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
; i
++) {
7273 if (pf
->vxlan_ports
[i
] == port
)
7281 * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up
7282 * @netdev: This physical port's netdev
7283 * @sa_family: Socket Family that VXLAN is notifying us about
7284 * @port: New UDP port number that VXLAN started listening to
7286 static void i40e_add_vxlan_port(struct net_device
*netdev
,
7287 sa_family_t sa_family
, __be16 port
)
7289 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7290 struct i40e_vsi
*vsi
= np
->vsi
;
7291 struct i40e_pf
*pf
= vsi
->back
;
7295 if (sa_family
== AF_INET6
)
7298 idx
= i40e_get_vxlan_port_idx(pf
, port
);
7300 /* Check if port already exists */
7301 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
7302 netdev_info(netdev
, "Port %d already offloaded\n", ntohs(port
));
7306 /* Now check if there is space to add the new port */
7307 next_idx
= i40e_get_vxlan_port_idx(pf
, 0);
7309 if (next_idx
== I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
7310 netdev_info(netdev
, "Maximum number of UDP ports reached, not adding port %d\n",
7315 /* New port: add it and mark its index in the bitmap */
7316 pf
->vxlan_ports
[next_idx
] = port
;
7317 pf
->pending_vxlan_bitmap
|= (1 << next_idx
);
7319 pf
->flags
|= I40E_FLAG_VXLAN_FILTER_SYNC
;
7323 * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away
7324 * @netdev: This physical port's netdev
7325 * @sa_family: Socket Family that VXLAN is notifying us about
7326 * @port: UDP port number that VXLAN stopped listening to
7328 static void i40e_del_vxlan_port(struct net_device
*netdev
,
7329 sa_family_t sa_family
, __be16 port
)
7331 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7332 struct i40e_vsi
*vsi
= np
->vsi
;
7333 struct i40e_pf
*pf
= vsi
->back
;
7336 if (sa_family
== AF_INET6
)
7339 idx
= i40e_get_vxlan_port_idx(pf
, port
);
7341 /* Check if port already exists */
7342 if (idx
< I40E_MAX_PF_UDP_OFFLOAD_PORTS
) {
7343 /* if port exists, set it to 0 (mark for deletion)
7344 * and make it pending
7346 pf
->vxlan_ports
[idx
] = 0;
7348 pf
->pending_vxlan_bitmap
|= (1 << idx
);
7350 pf
->flags
|= I40E_FLAG_VXLAN_FILTER_SYNC
;
7352 netdev_warn(netdev
, "Port %d was not found, not deleting\n",
7358 static int i40e_get_phys_port_id(struct net_device
*netdev
,
7359 struct netdev_phys_port_id
*ppid
)
7361 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
7362 struct i40e_pf
*pf
= np
->vsi
->back
;
7363 struct i40e_hw
*hw
= &pf
->hw
;
7365 if (!(pf
->flags
& I40E_FLAG_PORT_ID_VALID
))
7368 ppid
->id_len
= min_t(int, sizeof(hw
->mac
.port_addr
), sizeof(ppid
->id
));
7369 memcpy(ppid
->id
, hw
->mac
.port_addr
, ppid
->id_len
);
7375 #ifdef USE_CONST_DEV_UC_CHAR
7376 static int i40e_ndo_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
7377 struct net_device
*dev
,
7378 const unsigned char *addr
,
7381 static int i40e_ndo_fdb_add(struct ndmsg
*ndm
,
7382 struct net_device
*dev
,
7383 unsigned char *addr
,
7387 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
7388 struct i40e_pf
*pf
= np
->vsi
->back
;
7391 if (!(pf
->flags
& I40E_FLAG_SRIOV_ENABLED
))
7394 /* Hardware does not support aging addresses so if a
7395 * ndm_state is given only allow permanent addresses
7397 if (ndm
->ndm_state
&& !(ndm
->ndm_state
& NUD_PERMANENT
)) {
7398 netdev_info(dev
, "FDB only supports static addresses\n");
7402 if (is_unicast_ether_addr(addr
) || is_link_local_ether_addr(addr
))
7403 err
= dev_uc_add_excl(dev
, addr
);
7404 else if (is_multicast_ether_addr(addr
))
7405 err
= dev_mc_add_excl(dev
, addr
);
7409 /* Only return duplicate errors if NLM_F_EXCL is set */
7410 if (err
== -EEXIST
&& !(flags
& NLM_F_EXCL
))
7416 #ifndef USE_DEFAULT_FDB_DEL_DUMP
7417 #ifdef USE_CONST_DEV_UC_CHAR
7418 static int i40e_ndo_fdb_del(struct ndmsg
*ndm
,
7419 struct net_device
*dev
,
7420 const unsigned char *addr
)
7422 static int i40e_ndo_fdb_del(struct ndmsg
*ndm
,
7423 struct net_device
*dev
,
7424 unsigned char *addr
)
7427 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
7428 struct i40e_pf
*pf
= np
->vsi
->back
;
7429 int err
= -EOPNOTSUPP
;
7431 if (ndm
->ndm_state
& NUD_PERMANENT
) {
7432 netdev_info(dev
, "FDB only supports static addresses\n");
7436 if (pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) {
7437 if (is_unicast_ether_addr(addr
))
7438 err
= dev_uc_del(dev
, addr
);
7439 else if (is_multicast_ether_addr(addr
))
7440 err
= dev_mc_del(dev
, addr
);
7448 static int i40e_ndo_fdb_dump(struct sk_buff
*skb
,
7449 struct netlink_callback
*cb
,
7450 struct net_device
*dev
,
7451 struct net_device
*filter_dev
,
7454 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
7455 struct i40e_pf
*pf
= np
->vsi
->back
;
7457 if (pf
->flags
& I40E_FLAG_SRIOV_ENABLED
)
7458 idx
= ndo_dflt_fdb_dump(skb
, cb
, dev
, filter_dev
, idx
);
7463 #endif /* USE_DEFAULT_FDB_DEL_DUMP */
7464 #endif /* HAVE_FDB_OPS */
7465 static const struct net_device_ops i40e_netdev_ops
= {
7466 .ndo_open
= i40e_open
,
7467 .ndo_stop
= i40e_close
,
7468 .ndo_start_xmit
= i40e_lan_xmit_frame
,
7469 .ndo_get_stats64
= i40e_get_netdev_stats_struct
,
7470 .ndo_set_rx_mode
= i40e_set_rx_mode
,
7471 .ndo_validate_addr
= eth_validate_addr
,
7472 .ndo_set_mac_address
= i40e_set_mac
,
7473 .ndo_change_mtu
= i40e_change_mtu
,
7474 .ndo_do_ioctl
= i40e_ioctl
,
7475 .ndo_tx_timeout
= i40e_tx_timeout
,
7476 .ndo_vlan_rx_add_vid
= i40e_vlan_rx_add_vid
,
7477 .ndo_vlan_rx_kill_vid
= i40e_vlan_rx_kill_vid
,
7478 #ifdef CONFIG_NET_POLL_CONTROLLER
7479 .ndo_poll_controller
= i40e_netpoll
,
7481 .ndo_setup_tc
= i40e_setup_tc
,
7483 .ndo_fcoe_enable
= i40e_fcoe_enable
,
7484 .ndo_fcoe_disable
= i40e_fcoe_disable
,
7486 .ndo_set_features
= i40e_set_features
,
7487 .ndo_set_vf_mac
= i40e_ndo_set_vf_mac
,
7488 .ndo_set_vf_vlan
= i40e_ndo_set_vf_port_vlan
,
7489 .ndo_set_vf_rate
= i40e_ndo_set_vf_bw
,
7490 .ndo_get_vf_config
= i40e_ndo_get_vf_config
,
7491 .ndo_set_vf_link_state
= i40e_ndo_set_vf_link_state
,
7492 .ndo_set_vf_spoofchk
= i40e_ndo_set_vf_spoofchk
,
7493 #ifdef CONFIG_I40E_VXLAN
7494 .ndo_add_vxlan_port
= i40e_add_vxlan_port
,
7495 .ndo_del_vxlan_port
= i40e_del_vxlan_port
,
7497 .ndo_get_phys_port_id
= i40e_get_phys_port_id
,
7499 .ndo_fdb_add
= i40e_ndo_fdb_add
,
7500 #ifndef USE_DEFAULT_FDB_DEL_DUMP
7501 .ndo_fdb_del
= i40e_ndo_fdb_del
,
7502 .ndo_fdb_dump
= i40e_ndo_fdb_dump
,
7508 * i40e_config_netdev - Setup the netdev flags
7509 * @vsi: the VSI being configured
7511 * Returns 0 on success, negative value on failure
7513 static int i40e_config_netdev(struct i40e_vsi
*vsi
)
7515 u8 brdcast
[ETH_ALEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7516 struct i40e_pf
*pf
= vsi
->back
;
7517 struct i40e_hw
*hw
= &pf
->hw
;
7518 struct i40e_netdev_priv
*np
;
7519 struct net_device
*netdev
;
7520 u8 mac_addr
[ETH_ALEN
];
7523 etherdev_size
= sizeof(struct i40e_netdev_priv
);
7524 netdev
= alloc_etherdev_mq(etherdev_size
, vsi
->alloc_queue_pairs
);
7528 vsi
->netdev
= netdev
;
7529 np
= netdev_priv(netdev
);
7532 netdev
->hw_enc_features
|= NETIF_F_IP_CSUM
|
7533 NETIF_F_GSO_UDP_TUNNEL
|
7536 netdev
->features
= NETIF_F_SG
|
7540 NETIF_F_GSO_UDP_TUNNEL
|
7541 NETIF_F_HW_VLAN_CTAG_TX
|
7542 NETIF_F_HW_VLAN_CTAG_RX
|
7543 NETIF_F_HW_VLAN_CTAG_FILTER
|
7552 if (!(pf
->flags
& I40E_FLAG_MFP_ENABLED
))
7553 netdev
->features
|= NETIF_F_NTUPLE
;
7555 /* copy netdev features into list of user selectable features */
7556 netdev
->hw_features
|= netdev
->features
;
7558 if (vsi
->type
== I40E_VSI_MAIN
) {
7559 SET_NETDEV_DEV(netdev
, &pf
->pdev
->dev
);
7560 ether_addr_copy(mac_addr
, hw
->mac
.perm_addr
);
7561 /* The following steps are necessary to prevent reception
7562 * of tagged packets - some older NVM configurations load a
7563 * default a MAC-VLAN filter that accepts any tagged packet
7564 * which must be replaced by a normal filter.
7566 if (!i40e_rm_default_mac_filter(vsi
, mac_addr
))
7567 i40e_add_filter(vsi
, mac_addr
,
7568 I40E_VLAN_ANY
, false, true);
7570 /* relate the VSI_VMDQ name to the VSI_MAIN name */
7571 snprintf(netdev
->name
, IFNAMSIZ
, "%sv%%d",
7572 pf
->vsi
[pf
->lan_vsi
]->netdev
->name
);
7573 random_ether_addr(mac_addr
);
7574 i40e_add_filter(vsi
, mac_addr
, I40E_VLAN_ANY
, false, false);
7576 i40e_add_filter(vsi
, brdcast
, I40E_VLAN_ANY
, false, false);
7578 ether_addr_copy(netdev
->dev_addr
, mac_addr
);
7579 ether_addr_copy(netdev
->perm_addr
, mac_addr
);
7580 /* vlan gets same features (except vlan offload)
7581 * after any tweaks for specific VSI types
7583 netdev
->vlan_features
= netdev
->features
& ~(NETIF_F_HW_VLAN_CTAG_TX
|
7584 NETIF_F_HW_VLAN_CTAG_RX
|
7585 NETIF_F_HW_VLAN_CTAG_FILTER
);
7586 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
7587 netdev
->priv_flags
|= IFF_SUPP_NOFCS
;
7588 /* Setup netdev TC information */
7589 i40e_vsi_config_netdev_tc(vsi
, vsi
->tc_config
.enabled_tc
);
7591 netdev
->netdev_ops
= &i40e_netdev_ops
;
7592 netdev
->watchdog_timeo
= 5 * HZ
;
7593 i40e_set_ethtool_ops(netdev
);
7595 i40e_fcoe_config_netdev(netdev
, vsi
);
7602 * i40e_vsi_delete - Delete a VSI from the switch
7603 * @vsi: the VSI being removed
7605 * Returns 0 on success, negative value on failure
7607 static void i40e_vsi_delete(struct i40e_vsi
*vsi
)
7609 /* remove default VSI is not allowed */
7610 if (vsi
== vsi
->back
->vsi
[vsi
->back
->lan_vsi
])
7613 i40e_aq_delete_element(&vsi
->back
->hw
, vsi
->seid
, NULL
);
7617 * i40e_add_vsi - Add a VSI to the switch
7618 * @vsi: the VSI being configured
7620 * This initializes a VSI context depending on the VSI type to be added and
7621 * passes it down to the add_vsi aq command.
7623 static int i40e_add_vsi(struct i40e_vsi
*vsi
)
7626 struct i40e_mac_filter
*f
, *ftmp
;
7627 struct i40e_pf
*pf
= vsi
->back
;
7628 struct i40e_hw
*hw
= &pf
->hw
;
7629 struct i40e_vsi_context ctxt
;
7630 u8 enabled_tc
= 0x1; /* TC0 enabled */
7633 memset(&ctxt
, 0, sizeof(ctxt
));
7634 switch (vsi
->type
) {
7636 /* The PF's main VSI is already setup as part of the
7637 * device initialization, so we'll not bother with
7638 * the add_vsi call, but we will retrieve the current
7641 ctxt
.seid
= pf
->main_vsi_seid
;
7642 ctxt
.pf_num
= pf
->hw
.pf_id
;
7644 ret
= i40e_aq_get_vsi_params(&pf
->hw
, &ctxt
, NULL
);
7645 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
7647 dev_info(&pf
->pdev
->dev
,
7648 "couldn't get pf vsi config, err %d, aq_err %d\n",
7649 ret
, pf
->hw
.aq
.asq_last_status
);
7652 memcpy(&vsi
->info
, &ctxt
.info
, sizeof(ctxt
.info
));
7653 vsi
->info
.valid_sections
= 0;
7655 vsi
->seid
= ctxt
.seid
;
7656 vsi
->id
= ctxt
.vsi_number
;
7658 enabled_tc
= i40e_pf_get_tc_map(pf
);
7660 /* MFP mode setup queue map and update VSI */
7661 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
7662 memset(&ctxt
, 0, sizeof(ctxt
));
7663 ctxt
.seid
= pf
->main_vsi_seid
;
7664 ctxt
.pf_num
= pf
->hw
.pf_id
;
7666 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, false);
7667 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
7669 dev_info(&pf
->pdev
->dev
,
7670 "update vsi failed, aq_err=%d\n",
7671 pf
->hw
.aq
.asq_last_status
);
7675 /* update the local VSI info queue map */
7676 i40e_vsi_update_queue_map(vsi
, &ctxt
);
7677 vsi
->info
.valid_sections
= 0;
7679 /* Default/Main VSI is only enabled for TC0
7680 * reconfigure it to enable all TCs that are
7681 * available on the port in SFP mode.
7683 ret
= i40e_vsi_config_tc(vsi
, enabled_tc
);
7685 dev_info(&pf
->pdev
->dev
,
7686 "failed to configure TCs for main VSI tc_map 0x%08x, err %d, aq_err %d\n",
7688 pf
->hw
.aq
.asq_last_status
);
7695 ctxt
.pf_num
= hw
->pf_id
;
7697 ctxt
.uplink_seid
= vsi
->uplink_seid
;
7698 ctxt
.connection_type
= 0x1; /* regular data port */
7699 ctxt
.flags
= I40E_AQ_VSI_TYPE_PF
;
7700 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
7703 case I40E_VSI_VMDQ2
:
7704 ctxt
.pf_num
= hw
->pf_id
;
7706 ctxt
.uplink_seid
= vsi
->uplink_seid
;
7707 ctxt
.connection_type
= 0x1; /* regular data port */
7708 ctxt
.flags
= I40E_AQ_VSI_TYPE_VMDQ2
;
7710 ctxt
.info
.valid_sections
|= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
7712 /* This VSI is connected to VEB so the switch_id
7713 * should be set to zero by default.
7715 ctxt
.info
.switch_id
= 0;
7716 ctxt
.info
.switch_id
|= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
7718 /* Setup the VSI tx/rx queue map for TC0 only for now */
7719 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
7722 case I40E_VSI_SRIOV
:
7723 ctxt
.pf_num
= hw
->pf_id
;
7724 ctxt
.vf_num
= vsi
->vf_id
+ hw
->func_caps
.vf_base_id
;
7725 ctxt
.uplink_seid
= vsi
->uplink_seid
;
7726 ctxt
.connection_type
= 0x1; /* regular data port */
7727 ctxt
.flags
= I40E_AQ_VSI_TYPE_VF
;
7729 ctxt
.info
.valid_sections
|= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
7731 /* This VSI is connected to VEB so the switch_id
7732 * should be set to zero by default.
7734 ctxt
.info
.switch_id
= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
7736 ctxt
.info
.valid_sections
|= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID
);
7737 ctxt
.info
.port_vlan_flags
|= I40E_AQ_VSI_PVLAN_MODE_ALL
;
7738 if (pf
->vf
[vsi
->vf_id
].spoofchk
) {
7739 ctxt
.info
.valid_sections
|=
7740 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID
);
7741 ctxt
.info
.sec_flags
|=
7742 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK
|
7743 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK
);
7745 /* Setup the VSI tx/rx queue map for TC0 only for now */
7746 i40e_vsi_setup_queue_map(vsi
, &ctxt
, enabled_tc
, true);
7751 ret
= i40e_fcoe_vsi_init(vsi
, &ctxt
);
7753 dev_info(&pf
->pdev
->dev
, "failed to initialize FCoE VSI\n");
7758 #endif /* I40E_FCOE */
7763 if (vsi
->type
!= I40E_VSI_MAIN
) {
7764 ret
= i40e_aq_add_vsi(hw
, &ctxt
, NULL
);
7766 dev_info(&vsi
->back
->pdev
->dev
,
7767 "add vsi failed, aq_err=%d\n",
7768 vsi
->back
->hw
.aq
.asq_last_status
);
7772 memcpy(&vsi
->info
, &ctxt
.info
, sizeof(ctxt
.info
));
7773 vsi
->info
.valid_sections
= 0;
7774 vsi
->seid
= ctxt
.seid
;
7775 vsi
->id
= ctxt
.vsi_number
;
7778 /* If macvlan filters already exist, force them to get loaded */
7779 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
) {
7783 if (f
->is_laa
&& vsi
->type
== I40E_VSI_MAIN
) {
7784 struct i40e_aqc_remove_macvlan_element_data element
;
7786 memset(&element
, 0, sizeof(element
));
7787 ether_addr_copy(element
.mac_addr
, f
->macaddr
);
7788 element
.flags
= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH
;
7789 ret
= i40e_aq_remove_macvlan(hw
, vsi
->seid
,
7792 /* some older FW has a different default */
7794 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN
;
7795 i40e_aq_remove_macvlan(hw
, vsi
->seid
,
7799 i40e_aq_mac_address_write(hw
,
7800 I40E_AQC_WRITE_TYPE_LAA_WOL
,
7805 vsi
->flags
|= I40E_VSI_FLAG_FILTER_CHANGED
;
7806 pf
->flags
|= I40E_FLAG_FILTER_SYNC
;
7809 /* Update VSI BW information */
7810 ret
= i40e_vsi_get_bw_info(vsi
);
7812 dev_info(&pf
->pdev
->dev
,
7813 "couldn't get vsi bw info, err %d, aq_err %d\n",
7814 ret
, pf
->hw
.aq
.asq_last_status
);
7815 /* VSI is already added so not tearing that up */
7824 * i40e_vsi_release - Delete a VSI and free its resources
7825 * @vsi: the VSI being removed
7827 * Returns 0 on success or < 0 on error
7829 int i40e_vsi_release(struct i40e_vsi
*vsi
)
7831 struct i40e_mac_filter
*f
, *ftmp
;
7832 struct i40e_veb
*veb
= NULL
;
7839 /* release of a VEB-owner or last VSI is not allowed */
7840 if (vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) {
7841 dev_info(&pf
->pdev
->dev
, "VSI %d has existing VEB %d\n",
7842 vsi
->seid
, vsi
->uplink_seid
);
7845 if (vsi
== pf
->vsi
[pf
->lan_vsi
] &&
7846 !test_bit(__I40E_DOWN
, &pf
->state
)) {
7847 dev_info(&pf
->pdev
->dev
, "Can't remove PF VSI\n");
7851 uplink_seid
= vsi
->uplink_seid
;
7852 if (vsi
->type
!= I40E_VSI_SRIOV
) {
7853 if (vsi
->netdev_registered
) {
7854 vsi
->netdev_registered
= false;
7856 /* results in a call to i40e_close() */
7857 unregister_netdev(vsi
->netdev
);
7860 i40e_vsi_close(vsi
);
7862 i40e_vsi_disable_irq(vsi
);
7865 list_for_each_entry_safe(f
, ftmp
, &vsi
->mac_filter_list
, list
)
7866 i40e_del_filter(vsi
, f
->macaddr
, f
->vlan
,
7867 f
->is_vf
, f
->is_netdev
);
7868 i40e_sync_vsi_filters(vsi
);
7870 i40e_vsi_delete(vsi
);
7871 i40e_vsi_free_q_vectors(vsi
);
7873 free_netdev(vsi
->netdev
);
7876 i40e_vsi_clear_rings(vsi
);
7877 i40e_vsi_clear(vsi
);
7879 /* If this was the last thing on the VEB, except for the
7880 * controlling VSI, remove the VEB, which puts the controlling
7881 * VSI onto the next level down in the switch.
7883 * Well, okay, there's one more exception here: don't remove
7884 * the orphan VEBs yet. We'll wait for an explicit remove request
7885 * from up the network stack.
7887 for (n
= 0, i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
7889 pf
->vsi
[i
]->uplink_seid
== uplink_seid
&&
7890 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
7891 n
++; /* count the VSIs */
7894 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
7897 if (pf
->veb
[i
]->uplink_seid
== uplink_seid
)
7898 n
++; /* count the VEBs */
7899 if (pf
->veb
[i
]->seid
== uplink_seid
)
7902 if (n
== 0 && veb
&& veb
->uplink_seid
!= 0)
7903 i40e_veb_release(veb
);
7909 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
7910 * @vsi: ptr to the VSI
7912 * This should only be called after i40e_vsi_mem_alloc() which allocates the
7913 * corresponding SW VSI structure and initializes num_queue_pairs for the
7914 * newly allocated VSI.
7916 * Returns 0 on success or negative on failure
7918 static int i40e_vsi_setup_vectors(struct i40e_vsi
*vsi
)
7921 struct i40e_pf
*pf
= vsi
->back
;
7923 if (vsi
->q_vectors
[0]) {
7924 dev_info(&pf
->pdev
->dev
, "VSI %d has existing q_vectors\n",
7929 if (vsi
->base_vector
) {
7930 dev_info(&pf
->pdev
->dev
, "VSI %d has non-zero base vector %d\n",
7931 vsi
->seid
, vsi
->base_vector
);
7935 ret
= i40e_vsi_alloc_q_vectors(vsi
);
7937 dev_info(&pf
->pdev
->dev
,
7938 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
7939 vsi
->num_q_vectors
, vsi
->seid
, ret
);
7940 vsi
->num_q_vectors
= 0;
7941 goto vector_setup_out
;
7944 if (vsi
->num_q_vectors
)
7945 vsi
->base_vector
= i40e_get_lump(pf
, pf
->irq_pile
,
7946 vsi
->num_q_vectors
, vsi
->idx
);
7947 if (vsi
->base_vector
< 0) {
7948 dev_info(&pf
->pdev
->dev
,
7949 "failed to get queue tracking for VSI %d, err=%d\n",
7950 vsi
->seid
, vsi
->base_vector
);
7951 i40e_vsi_free_q_vectors(vsi
);
7953 goto vector_setup_out
;
7961 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
7962 * @vsi: pointer to the vsi.
7964 * This re-allocates a vsi's queue resources.
7966 * Returns pointer to the successfully allocated and configured VSI sw struct
7967 * on success, otherwise returns NULL on failure.
7969 static struct i40e_vsi
*i40e_vsi_reinit_setup(struct i40e_vsi
*vsi
)
7971 struct i40e_pf
*pf
= vsi
->back
;
7975 i40e_put_lump(pf
->qp_pile
, vsi
->base_queue
, vsi
->idx
);
7976 i40e_vsi_clear_rings(vsi
);
7978 i40e_vsi_free_arrays(vsi
, false);
7979 i40e_set_num_rings_in_vsi(vsi
);
7980 ret
= i40e_vsi_alloc_arrays(vsi
, false);
7984 ret
= i40e_get_lump(pf
, pf
->qp_pile
, vsi
->alloc_queue_pairs
, vsi
->idx
);
7986 dev_info(&pf
->pdev
->dev
, "VSI %d get_lump failed %d\n",
7990 vsi
->base_queue
= ret
;
7992 /* Update the FW view of the VSI. Force a reset of TC and queue
7993 * layout configurations.
7995 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
7996 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
7997 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
7998 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
8000 /* assign it some queues */
8001 ret
= i40e_alloc_rings(vsi
);
8005 /* map all of the rings to the q_vectors */
8006 i40e_vsi_map_rings_to_vectors(vsi
);
8010 i40e_vsi_free_q_vectors(vsi
);
8011 if (vsi
->netdev_registered
) {
8012 vsi
->netdev_registered
= false;
8013 unregister_netdev(vsi
->netdev
);
8014 free_netdev(vsi
->netdev
);
8017 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
8019 i40e_vsi_clear(vsi
);
8024 * i40e_vsi_setup - Set up a VSI by a given type
8025 * @pf: board private structure
8027 * @uplink_seid: the switch element to link to
8028 * @param1: usage depends upon VSI type. For VF types, indicates VF id
8030 * This allocates the sw VSI structure and its queue resources, then add a VSI
8031 * to the identified VEB.
8033 * Returns pointer to the successfully allocated and configure VSI sw struct on
8034 * success, otherwise returns NULL on failure.
8036 struct i40e_vsi
*i40e_vsi_setup(struct i40e_pf
*pf
, u8 type
,
8037 u16 uplink_seid
, u32 param1
)
8039 struct i40e_vsi
*vsi
= NULL
;
8040 struct i40e_veb
*veb
= NULL
;
8044 /* The requested uplink_seid must be either
8045 * - the PF's port seid
8046 * no VEB is needed because this is the PF
8047 * or this is a Flow Director special case VSI
8048 * - seid of an existing VEB
8049 * - seid of a VSI that owns an existing VEB
8050 * - seid of a VSI that doesn't own a VEB
8051 * a new VEB is created and the VSI becomes the owner
8052 * - seid of the PF VSI, which is what creates the first VEB
8053 * this is a special case of the previous
8055 * Find which uplink_seid we were given and create a new VEB if needed
8057 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
8058 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== uplink_seid
) {
8064 if (!veb
&& uplink_seid
!= pf
->mac_seid
) {
8066 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
8067 if (pf
->vsi
[i
] && pf
->vsi
[i
]->seid
== uplink_seid
) {
8073 dev_info(&pf
->pdev
->dev
, "no such uplink_seid %d\n",
8078 if (vsi
->uplink_seid
== pf
->mac_seid
)
8079 veb
= i40e_veb_setup(pf
, 0, pf
->mac_seid
, vsi
->seid
,
8080 vsi
->tc_config
.enabled_tc
);
8081 else if ((vsi
->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0)
8082 veb
= i40e_veb_setup(pf
, 0, vsi
->uplink_seid
, vsi
->seid
,
8083 vsi
->tc_config
.enabled_tc
);
8085 for (i
= 0; i
< I40E_MAX_VEB
&& !veb
; i
++) {
8086 if (pf
->veb
[i
] && pf
->veb
[i
]->seid
== vsi
->uplink_seid
)
8090 dev_info(&pf
->pdev
->dev
, "couldn't add VEB\n");
8094 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
8095 uplink_seid
= veb
->seid
;
8098 /* get vsi sw struct */
8099 v_idx
= i40e_vsi_mem_alloc(pf
, type
);
8102 vsi
= pf
->vsi
[v_idx
];
8106 vsi
->veb_idx
= (veb
? veb
->idx
: I40E_NO_VEB
);
8108 if (type
== I40E_VSI_MAIN
)
8109 pf
->lan_vsi
= v_idx
;
8110 else if (type
== I40E_VSI_SRIOV
)
8111 vsi
->vf_id
= param1
;
8112 /* assign it some queues */
8113 ret
= i40e_get_lump(pf
, pf
->qp_pile
, vsi
->alloc_queue_pairs
,
8116 dev_info(&pf
->pdev
->dev
, "VSI %d get_lump failed %d\n",
8120 vsi
->base_queue
= ret
;
8122 /* get a VSI from the hardware */
8123 vsi
->uplink_seid
= uplink_seid
;
8124 ret
= i40e_add_vsi(vsi
);
8128 switch (vsi
->type
) {
8129 /* setup the netdev if needed */
8131 case I40E_VSI_VMDQ2
:
8133 ret
= i40e_config_netdev(vsi
);
8136 ret
= register_netdev(vsi
->netdev
);
8139 vsi
->netdev_registered
= true;
8140 netif_carrier_off(vsi
->netdev
);
8141 #ifdef CONFIG_I40E_DCB
8142 /* Setup DCB netlink interface */
8143 i40e_dcbnl_setup(vsi
);
8144 #endif /* CONFIG_I40E_DCB */
8148 /* set up vectors and rings if needed */
8149 ret
= i40e_vsi_setup_vectors(vsi
);
8153 ret
= i40e_alloc_rings(vsi
);
8157 /* map all of the rings to the q_vectors */
8158 i40e_vsi_map_rings_to_vectors(vsi
);
8160 i40e_vsi_reset_stats(vsi
);
8164 /* no netdev or rings for the other VSI types */
8171 i40e_vsi_free_q_vectors(vsi
);
8173 if (vsi
->netdev_registered
) {
8174 vsi
->netdev_registered
= false;
8175 unregister_netdev(vsi
->netdev
);
8176 free_netdev(vsi
->netdev
);
8180 i40e_aq_delete_element(&pf
->hw
, vsi
->seid
, NULL
);
8182 i40e_vsi_clear(vsi
);
8188 * i40e_veb_get_bw_info - Query VEB BW information
8189 * @veb: the veb to query
8191 * Query the Tx scheduler BW configuration data for given VEB
8193 static int i40e_veb_get_bw_info(struct i40e_veb
*veb
)
8195 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data
;
8196 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data
;
8197 struct i40e_pf
*pf
= veb
->pf
;
8198 struct i40e_hw
*hw
= &pf
->hw
;
8203 ret
= i40e_aq_query_switch_comp_bw_config(hw
, veb
->seid
,
8206 dev_info(&pf
->pdev
->dev
,
8207 "query veb bw config failed, aq_err=%d\n",
8208 hw
->aq
.asq_last_status
);
8212 ret
= i40e_aq_query_switch_comp_ets_config(hw
, veb
->seid
,
8215 dev_info(&pf
->pdev
->dev
,
8216 "query veb bw ets config failed, aq_err=%d\n",
8217 hw
->aq
.asq_last_status
);
8221 veb
->bw_limit
= le16_to_cpu(ets_data
.port_bw_limit
);
8222 veb
->bw_max_quanta
= ets_data
.tc_bw_max
;
8223 veb
->is_abs_credits
= bw_data
.absolute_credits_enable
;
8224 tc_bw_max
= le16_to_cpu(bw_data
.tc_bw_max
[0]) |
8225 (le16_to_cpu(bw_data
.tc_bw_max
[1]) << 16);
8226 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
8227 veb
->bw_tc_share_credits
[i
] = bw_data
.tc_bw_share_credits
[i
];
8228 veb
->bw_tc_limit_credits
[i
] =
8229 le16_to_cpu(bw_data
.tc_bw_limits
[i
]);
8230 veb
->bw_tc_max_quanta
[i
] = ((tc_bw_max
>> (i
*4)) & 0x7);
8238 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
8239 * @pf: board private structure
8241 * On error: returns error code (negative)
8242 * On success: returns vsi index in PF (positive)
8244 static int i40e_veb_mem_alloc(struct i40e_pf
*pf
)
8247 struct i40e_veb
*veb
;
8250 /* Need to protect the allocation of switch elements at the PF level */
8251 mutex_lock(&pf
->switch_mutex
);
8253 /* VEB list may be fragmented if VEB creation/destruction has
8254 * been happening. We can afford to do a quick scan to look
8255 * for any free slots in the list.
8257 * find next empty veb slot, looping back around if necessary
8260 while ((i
< I40E_MAX_VEB
) && (pf
->veb
[i
] != NULL
))
8262 if (i
>= I40E_MAX_VEB
) {
8264 goto err_alloc_veb
; /* out of VEB slots! */
8267 veb
= kzalloc(sizeof(*veb
), GFP_KERNEL
);
8274 veb
->enabled_tc
= 1;
8279 mutex_unlock(&pf
->switch_mutex
);
8284 * i40e_switch_branch_release - Delete a branch of the switch tree
8285 * @branch: where to start deleting
8287 * This uses recursion to find the tips of the branch to be
8288 * removed, deleting until we get back to and can delete this VEB.
8290 static void i40e_switch_branch_release(struct i40e_veb
*branch
)
8292 struct i40e_pf
*pf
= branch
->pf
;
8293 u16 branch_seid
= branch
->seid
;
8294 u16 veb_idx
= branch
->idx
;
8297 /* release any VEBs on this VEB - RECURSION */
8298 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
8301 if (pf
->veb
[i
]->uplink_seid
== branch
->seid
)
8302 i40e_switch_branch_release(pf
->veb
[i
]);
8305 /* Release the VSIs on this VEB, but not the owner VSI.
8307 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
8308 * the VEB itself, so don't use (*branch) after this loop.
8310 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
8313 if (pf
->vsi
[i
]->uplink_seid
== branch_seid
&&
8314 (pf
->vsi
[i
]->flags
& I40E_VSI_FLAG_VEB_OWNER
) == 0) {
8315 i40e_vsi_release(pf
->vsi
[i
]);
8319 /* There's one corner case where the VEB might not have been
8320 * removed, so double check it here and remove it if needed.
8321 * This case happens if the veb was created from the debugfs
8322 * commands and no VSIs were added to it.
8324 if (pf
->veb
[veb_idx
])
8325 i40e_veb_release(pf
->veb
[veb_idx
]);
8329 * i40e_veb_clear - remove veb struct
8330 * @veb: the veb to remove
8332 static void i40e_veb_clear(struct i40e_veb
*veb
)
8338 struct i40e_pf
*pf
= veb
->pf
;
8340 mutex_lock(&pf
->switch_mutex
);
8341 if (pf
->veb
[veb
->idx
] == veb
)
8342 pf
->veb
[veb
->idx
] = NULL
;
8343 mutex_unlock(&pf
->switch_mutex
);
8350 * i40e_veb_release - Delete a VEB and free its resources
8351 * @veb: the VEB being removed
8353 void i40e_veb_release(struct i40e_veb
*veb
)
8355 struct i40e_vsi
*vsi
= NULL
;
8361 /* find the remaining VSI and check for extras */
8362 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
8363 if (pf
->vsi
[i
] && pf
->vsi
[i
]->uplink_seid
== veb
->seid
) {
8369 dev_info(&pf
->pdev
->dev
,
8370 "can't remove VEB %d with %d VSIs left\n",
8375 /* move the remaining VSI to uplink veb */
8376 vsi
->flags
&= ~I40E_VSI_FLAG_VEB_OWNER
;
8377 if (veb
->uplink_seid
) {
8378 vsi
->uplink_seid
= veb
->uplink_seid
;
8379 if (veb
->uplink_seid
== pf
->mac_seid
)
8380 vsi
->veb_idx
= I40E_NO_VEB
;
8382 vsi
->veb_idx
= veb
->veb_idx
;
8385 vsi
->uplink_seid
= pf
->vsi
[pf
->lan_vsi
]->uplink_seid
;
8386 vsi
->veb_idx
= pf
->vsi
[pf
->lan_vsi
]->veb_idx
;
8389 i40e_aq_delete_element(&pf
->hw
, veb
->seid
, NULL
);
8390 i40e_veb_clear(veb
);
8394 * i40e_add_veb - create the VEB in the switch
8395 * @veb: the VEB to be instantiated
8396 * @vsi: the controlling VSI
8398 static int i40e_add_veb(struct i40e_veb
*veb
, struct i40e_vsi
*vsi
)
8400 bool is_default
= false;
8401 bool is_cloud
= false;
8404 /* get a VEB from the hardware */
8405 ret
= i40e_aq_add_veb(&veb
->pf
->hw
, veb
->uplink_seid
, vsi
->seid
,
8406 veb
->enabled_tc
, is_default
,
8407 is_cloud
, &veb
->seid
, NULL
);
8409 dev_info(&veb
->pf
->pdev
->dev
,
8410 "couldn't add VEB, err %d, aq_err %d\n",
8411 ret
, veb
->pf
->hw
.aq
.asq_last_status
);
8415 /* get statistics counter */
8416 ret
= i40e_aq_get_veb_parameters(&veb
->pf
->hw
, veb
->seid
, NULL
, NULL
,
8417 &veb
->stats_idx
, NULL
, NULL
, NULL
);
8419 dev_info(&veb
->pf
->pdev
->dev
,
8420 "couldn't get VEB statistics idx, err %d, aq_err %d\n",
8421 ret
, veb
->pf
->hw
.aq
.asq_last_status
);
8424 ret
= i40e_veb_get_bw_info(veb
);
8426 dev_info(&veb
->pf
->pdev
->dev
,
8427 "couldn't get VEB bw info, err %d, aq_err %d\n",
8428 ret
, veb
->pf
->hw
.aq
.asq_last_status
);
8429 i40e_aq_delete_element(&veb
->pf
->hw
, veb
->seid
, NULL
);
8433 vsi
->uplink_seid
= veb
->seid
;
8434 vsi
->veb_idx
= veb
->idx
;
8435 vsi
->flags
|= I40E_VSI_FLAG_VEB_OWNER
;
8441 * i40e_veb_setup - Set up a VEB
8442 * @pf: board private structure
8443 * @flags: VEB setup flags
8444 * @uplink_seid: the switch element to link to
8445 * @vsi_seid: the initial VSI seid
8446 * @enabled_tc: Enabled TC bit-map
8448 * This allocates the sw VEB structure and links it into the switch
8449 * It is possible and legal for this to be a duplicate of an already
8450 * existing VEB. It is also possible for both uplink and vsi seids
8451 * to be zero, in order to create a floating VEB.
8453 * Returns pointer to the successfully allocated VEB sw struct on
8454 * success, otherwise returns NULL on failure.
8456 struct i40e_veb
*i40e_veb_setup(struct i40e_pf
*pf
, u16 flags
,
8457 u16 uplink_seid
, u16 vsi_seid
,
8460 struct i40e_veb
*veb
, *uplink_veb
= NULL
;
8461 int vsi_idx
, veb_idx
;
8464 /* if one seid is 0, the other must be 0 to create a floating relay */
8465 if ((uplink_seid
== 0 || vsi_seid
== 0) &&
8466 (uplink_seid
+ vsi_seid
!= 0)) {
8467 dev_info(&pf
->pdev
->dev
,
8468 "one, not both seid's are 0: uplink=%d vsi=%d\n",
8469 uplink_seid
, vsi_seid
);
8473 /* make sure there is such a vsi and uplink */
8474 for (vsi_idx
= 0; vsi_idx
< pf
->num_alloc_vsi
; vsi_idx
++)
8475 if (pf
->vsi
[vsi_idx
] && pf
->vsi
[vsi_idx
]->seid
== vsi_seid
)
8477 if (vsi_idx
>= pf
->num_alloc_vsi
&& vsi_seid
!= 0) {
8478 dev_info(&pf
->pdev
->dev
, "vsi seid %d not found\n",
8483 if (uplink_seid
&& uplink_seid
!= pf
->mac_seid
) {
8484 for (veb_idx
= 0; veb_idx
< I40E_MAX_VEB
; veb_idx
++) {
8485 if (pf
->veb
[veb_idx
] &&
8486 pf
->veb
[veb_idx
]->seid
== uplink_seid
) {
8487 uplink_veb
= pf
->veb
[veb_idx
];
8492 dev_info(&pf
->pdev
->dev
,
8493 "uplink seid %d not found\n", uplink_seid
);
8498 /* get veb sw struct */
8499 veb_idx
= i40e_veb_mem_alloc(pf
);
8502 veb
= pf
->veb
[veb_idx
];
8504 veb
->uplink_seid
= uplink_seid
;
8505 veb
->veb_idx
= (uplink_veb
? uplink_veb
->idx
: I40E_NO_VEB
);
8506 veb
->enabled_tc
= (enabled_tc
? enabled_tc
: 0x1);
8508 /* create the VEB in the switch */
8509 ret
= i40e_add_veb(veb
, pf
->vsi
[vsi_idx
]);
8512 if (vsi_idx
== pf
->lan_vsi
)
8513 pf
->lan_veb
= veb
->idx
;
8518 i40e_veb_clear(veb
);
8524 * i40e_setup_pf_switch_element - set pf vars based on switch type
8525 * @pf: board private structure
8526 * @ele: element we are building info from
8527 * @num_reported: total number of elements
8528 * @printconfig: should we print the contents
8530 * helper function to assist in extracting a few useful SEID values.
8532 static void i40e_setup_pf_switch_element(struct i40e_pf
*pf
,
8533 struct i40e_aqc_switch_config_element_resp
*ele
,
8534 u16 num_reported
, bool printconfig
)
8536 u16 downlink_seid
= le16_to_cpu(ele
->downlink_seid
);
8537 u16 uplink_seid
= le16_to_cpu(ele
->uplink_seid
);
8538 u8 element_type
= ele
->element_type
;
8539 u16 seid
= le16_to_cpu(ele
->seid
);
8542 dev_info(&pf
->pdev
->dev
,
8543 "type=%d seid=%d uplink=%d downlink=%d\n",
8544 element_type
, seid
, uplink_seid
, downlink_seid
);
8546 switch (element_type
) {
8547 case I40E_SWITCH_ELEMENT_TYPE_MAC
:
8548 pf
->mac_seid
= seid
;
8550 case I40E_SWITCH_ELEMENT_TYPE_VEB
:
8552 if (uplink_seid
!= pf
->mac_seid
)
8554 if (pf
->lan_veb
== I40E_NO_VEB
) {
8557 /* find existing or else empty VEB */
8558 for (v
= 0; v
< I40E_MAX_VEB
; v
++) {
8559 if (pf
->veb
[v
] && (pf
->veb
[v
]->seid
== seid
)) {
8564 if (pf
->lan_veb
== I40E_NO_VEB
) {
8565 v
= i40e_veb_mem_alloc(pf
);
8572 pf
->veb
[pf
->lan_veb
]->seid
= seid
;
8573 pf
->veb
[pf
->lan_veb
]->uplink_seid
= pf
->mac_seid
;
8574 pf
->veb
[pf
->lan_veb
]->pf
= pf
;
8575 pf
->veb
[pf
->lan_veb
]->veb_idx
= I40E_NO_VEB
;
8577 case I40E_SWITCH_ELEMENT_TYPE_VSI
:
8578 if (num_reported
!= 1)
8580 /* This is immediately after a reset so we can assume this is
8583 pf
->mac_seid
= uplink_seid
;
8584 pf
->pf_seid
= downlink_seid
;
8585 pf
->main_vsi_seid
= seid
;
8587 dev_info(&pf
->pdev
->dev
,
8588 "pf_seid=%d main_vsi_seid=%d\n",
8589 pf
->pf_seid
, pf
->main_vsi_seid
);
8591 case I40E_SWITCH_ELEMENT_TYPE_PF
:
8592 case I40E_SWITCH_ELEMENT_TYPE_VF
:
8593 case I40E_SWITCH_ELEMENT_TYPE_EMP
:
8594 case I40E_SWITCH_ELEMENT_TYPE_BMC
:
8595 case I40E_SWITCH_ELEMENT_TYPE_PE
:
8596 case I40E_SWITCH_ELEMENT_TYPE_PA
:
8597 /* ignore these for now */
8600 dev_info(&pf
->pdev
->dev
, "unknown element type=%d seid=%d\n",
8601 element_type
, seid
);
8607 * i40e_fetch_switch_configuration - Get switch config from firmware
8608 * @pf: board private structure
8609 * @printconfig: should we print the contents
8611 * Get the current switch configuration from the device and
8612 * extract a few useful SEID values.
8614 int i40e_fetch_switch_configuration(struct i40e_pf
*pf
, bool printconfig
)
8616 struct i40e_aqc_get_switch_config_resp
*sw_config
;
8622 aq_buf
= kzalloc(I40E_AQ_LARGE_BUF
, GFP_KERNEL
);
8626 sw_config
= (struct i40e_aqc_get_switch_config_resp
*)aq_buf
;
8628 u16 num_reported
, num_total
;
8630 ret
= i40e_aq_get_switch_config(&pf
->hw
, sw_config
,
8634 dev_info(&pf
->pdev
->dev
,
8635 "get switch config failed %d aq_err=%x\n",
8636 ret
, pf
->hw
.aq
.asq_last_status
);
8641 num_reported
= le16_to_cpu(sw_config
->header
.num_reported
);
8642 num_total
= le16_to_cpu(sw_config
->header
.num_total
);
8645 dev_info(&pf
->pdev
->dev
,
8646 "header: %d reported %d total\n",
8647 num_reported
, num_total
);
8649 for (i
= 0; i
< num_reported
; i
++) {
8650 struct i40e_aqc_switch_config_element_resp
*ele
=
8651 &sw_config
->element
[i
];
8653 i40e_setup_pf_switch_element(pf
, ele
, num_reported
,
8656 } while (next_seid
!= 0);
8663 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
8664 * @pf: board private structure
8665 * @reinit: if the Main VSI needs to re-initialized.
8667 * Returns 0 on success, negative value on failure
8669 static int i40e_setup_pf_switch(struct i40e_pf
*pf
, bool reinit
)
8673 /* find out what's out there already */
8674 ret
= i40e_fetch_switch_configuration(pf
, false);
8676 dev_info(&pf
->pdev
->dev
,
8677 "couldn't fetch switch config, err %d, aq_err %d\n",
8678 ret
, pf
->hw
.aq
.asq_last_status
);
8681 i40e_pf_reset_stats(pf
);
8683 /* first time setup */
8684 if (pf
->lan_vsi
== I40E_NO_VSI
|| reinit
) {
8685 struct i40e_vsi
*vsi
= NULL
;
8688 /* Set up the PF VSI associated with the PF's main VSI
8689 * that is already in the HW switch
8691 if (pf
->lan_veb
!= I40E_NO_VEB
&& pf
->veb
[pf
->lan_veb
])
8692 uplink_seid
= pf
->veb
[pf
->lan_veb
]->seid
;
8694 uplink_seid
= pf
->mac_seid
;
8695 if (pf
->lan_vsi
== I40E_NO_VSI
)
8696 vsi
= i40e_vsi_setup(pf
, I40E_VSI_MAIN
, uplink_seid
, 0);
8698 vsi
= i40e_vsi_reinit_setup(pf
->vsi
[pf
->lan_vsi
]);
8700 dev_info(&pf
->pdev
->dev
, "setup of MAIN VSI failed\n");
8701 i40e_fdir_teardown(pf
);
8705 /* force a reset of TC and queue layout configurations */
8706 u8 enabled_tc
= pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
;
8707 pf
->vsi
[pf
->lan_vsi
]->tc_config
.enabled_tc
= 0;
8708 pf
->vsi
[pf
->lan_vsi
]->seid
= pf
->main_vsi_seid
;
8709 i40e_vsi_config_tc(pf
->vsi
[pf
->lan_vsi
], enabled_tc
);
8711 i40e_vlan_stripping_disable(pf
->vsi
[pf
->lan_vsi
]);
8713 i40e_fdir_sb_setup(pf
);
8715 /* Setup static PF queue filter control settings */
8716 ret
= i40e_setup_pf_filter_control(pf
);
8718 dev_info(&pf
->pdev
->dev
, "setup_pf_filter_control failed: %d\n",
8720 /* Failure here should not stop continuing other steps */
8723 /* enable RSS in the HW, even for only one queue, as the stack can use
8726 if ((pf
->flags
& I40E_FLAG_RSS_ENABLED
))
8727 i40e_config_rss(pf
);
8729 /* fill in link information and enable LSE reporting */
8730 i40e_update_link_info(&pf
->hw
, true);
8731 i40e_link_event(pf
);
8733 /* Initialize user-specific link properties */
8734 pf
->fc_autoneg_status
= ((pf
->hw
.phy
.link_info
.an_info
&
8735 I40E_AQ_AN_COMPLETED
) ? true : false);
8737 /* fill in link information and enable LSE reporting */
8738 i40e_update_link_info(&pf
->hw
, true);
8739 i40e_link_event(pf
);
8741 /* Initialize user-specific link properties */
8742 pf
->fc_autoneg_status
= ((pf
->hw
.phy
.link_info
.an_info
&
8743 I40E_AQ_AN_COMPLETED
) ? true : false);
8751 * i40e_determine_queue_usage - Work out queue distribution
8752 * @pf: board private structure
8754 static void i40e_determine_queue_usage(struct i40e_pf
*pf
)
8758 pf
->num_lan_qps
= 0;
8760 pf
->num_fcoe_qps
= 0;
8763 /* Find the max queues to be put into basic use. We'll always be
8764 * using TC0, whether or not DCB is running, and TC0 will get the
8767 queues_left
= pf
->hw
.func_caps
.num_tx_qp
;
8769 if ((queues_left
== 1) ||
8770 !(pf
->flags
& I40E_FLAG_MSIX_ENABLED
)) {
8771 /* one qp for PF, no queues for anything else */
8773 pf
->rss_size
= pf
->num_lan_qps
= 1;
8775 /* make sure all the fancies are disabled */
8776 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
8778 I40E_FLAG_FCOE_ENABLED
|
8780 I40E_FLAG_FD_SB_ENABLED
|
8781 I40E_FLAG_FD_ATR_ENABLED
|
8782 I40E_FLAG_DCB_CAPABLE
|
8783 I40E_FLAG_SRIOV_ENABLED
|
8784 I40E_FLAG_VMDQ_ENABLED
);
8785 } else if (!(pf
->flags
& (I40E_FLAG_RSS_ENABLED
|
8786 I40E_FLAG_FD_SB_ENABLED
|
8787 I40E_FLAG_FD_ATR_ENABLED
|
8788 I40E_FLAG_DCB_CAPABLE
))) {
8790 pf
->rss_size
= pf
->num_lan_qps
= 1;
8791 queues_left
-= pf
->num_lan_qps
;
8793 pf
->flags
&= ~(I40E_FLAG_RSS_ENABLED
|
8795 I40E_FLAG_FCOE_ENABLED
|
8797 I40E_FLAG_FD_SB_ENABLED
|
8798 I40E_FLAG_FD_ATR_ENABLED
|
8799 I40E_FLAG_DCB_ENABLED
|
8800 I40E_FLAG_VMDQ_ENABLED
);
8802 /* Not enough queues for all TCs */
8803 if ((pf
->flags
& I40E_FLAG_DCB_CAPABLE
) &&
8804 (queues_left
< I40E_MAX_TRAFFIC_CLASS
)) {
8805 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
8806 dev_info(&pf
->pdev
->dev
, "not enough queues for DCB. DCB is disabled.\n");
8808 pf
->num_lan_qps
= pf
->rss_size_max
;
8809 queues_left
-= pf
->num_lan_qps
;
8813 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
) {
8814 if (I40E_DEFAULT_FCOE
<= queues_left
) {
8815 pf
->num_fcoe_qps
= I40E_DEFAULT_FCOE
;
8816 } else if (I40E_MINIMUM_FCOE
<= queues_left
) {
8817 pf
->num_fcoe_qps
= I40E_MINIMUM_FCOE
;
8819 pf
->num_fcoe_qps
= 0;
8820 pf
->flags
&= ~I40E_FLAG_FCOE_ENABLED
;
8821 dev_info(&pf
->pdev
->dev
, "not enough queues for FCoE. FCoE feature will be disabled\n");
8824 queues_left
-= pf
->num_fcoe_qps
;
8828 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
8829 if (queues_left
> 1) {
8830 queues_left
-= 1; /* save 1 queue for FD */
8832 pf
->flags
&= ~I40E_FLAG_FD_SB_ENABLED
;
8833 dev_info(&pf
->pdev
->dev
, "not enough queues for Flow Director. Flow Director feature is disabled\n");
8837 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
8838 pf
->num_vf_qps
&& pf
->num_req_vfs
&& queues_left
) {
8839 pf
->num_req_vfs
= min_t(int, pf
->num_req_vfs
,
8840 (queues_left
/ pf
->num_vf_qps
));
8841 queues_left
-= (pf
->num_req_vfs
* pf
->num_vf_qps
);
8844 if ((pf
->flags
& I40E_FLAG_VMDQ_ENABLED
) &&
8845 pf
->num_vmdq_vsis
&& pf
->num_vmdq_qps
&& queues_left
) {
8846 pf
->num_vmdq_vsis
= min_t(int, pf
->num_vmdq_vsis
,
8847 (queues_left
/ pf
->num_vmdq_qps
));
8848 queues_left
-= (pf
->num_vmdq_vsis
* pf
->num_vmdq_qps
);
8851 pf
->queues_left
= queues_left
;
8853 dev_info(&pf
->pdev
->dev
, "fcoe queues = %d\n", pf
->num_fcoe_qps
);
8858 * i40e_setup_pf_filter_control - Setup PF static filter control
8859 * @pf: PF to be setup
8861 * i40e_setup_pf_filter_control sets up a pf's initial filter control
8862 * settings. If PE/FCoE are enabled then it will also set the per PF
8863 * based filter sizes required for them. It also enables Flow director,
8864 * ethertype and macvlan type filter settings for the pf.
8866 * Returns 0 on success, negative on failure
8868 static int i40e_setup_pf_filter_control(struct i40e_pf
*pf
)
8870 struct i40e_filter_control_settings
*settings
= &pf
->filter_settings
;
8872 settings
->hash_lut_size
= I40E_HASH_LUT_SIZE_128
;
8874 /* Flow Director is enabled */
8875 if (pf
->flags
& (I40E_FLAG_FD_SB_ENABLED
| I40E_FLAG_FD_ATR_ENABLED
))
8876 settings
->enable_fdir
= true;
8878 /* Ethtype and MACVLAN filters enabled for PF */
8879 settings
->enable_ethtype
= true;
8880 settings
->enable_macvlan
= true;
8882 if (i40e_set_filter_control(&pf
->hw
, settings
))
8888 #define INFO_STRING_LEN 255
8889 static void i40e_print_features(struct i40e_pf
*pf
)
8891 struct i40e_hw
*hw
= &pf
->hw
;
8894 string
= kzalloc(INFO_STRING_LEN
, GFP_KERNEL
);
8896 dev_err(&pf
->pdev
->dev
, "Features string allocation failed\n");
8902 buf
+= sprintf(string
, "Features: PF-id[%d] ", hw
->pf_id
);
8903 #ifdef CONFIG_PCI_IOV
8904 buf
+= sprintf(buf
, "VFs: %d ", pf
->num_req_vfs
);
8906 buf
+= sprintf(buf
, "VSIs: %d QP: %d ", pf
->hw
.func_caps
.num_vsis
,
8907 pf
->vsi
[pf
->lan_vsi
]->num_queue_pairs
);
8909 if (pf
->flags
& I40E_FLAG_RSS_ENABLED
)
8910 buf
+= sprintf(buf
, "RSS ");
8911 if (pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
)
8912 buf
+= sprintf(buf
, "FD_ATR ");
8913 if (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) {
8914 buf
+= sprintf(buf
, "FD_SB ");
8915 buf
+= sprintf(buf
, "NTUPLE ");
8917 if (pf
->flags
& I40E_FLAG_DCB_CAPABLE
)
8918 buf
+= sprintf(buf
, "DCB ");
8919 if (pf
->flags
& I40E_FLAG_PTP
)
8920 buf
+= sprintf(buf
, "PTP ");
8922 if (pf
->flags
& I40E_FLAG_FCOE_ENABLED
)
8923 buf
+= sprintf(buf
, "FCOE ");
8926 BUG_ON(buf
> (string
+ INFO_STRING_LEN
));
8927 dev_info(&pf
->pdev
->dev
, "%s\n", string
);
8932 * i40e_probe - Device initialization routine
8933 * @pdev: PCI device information struct
8934 * @ent: entry in i40e_pci_tbl
8936 * i40e_probe initializes a pf identified by a pci_dev structure.
8937 * The OS initialization, configuring of the pf private structure,
8938 * and a hardware reset occur.
8940 * Returns 0 on success, negative on failure
8942 static int i40e_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
8946 static u16 pfs_found
;
8952 err
= pci_enable_device_mem(pdev
);
8956 /* set up for high or low dma */
8957 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
8959 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
8962 "DMA configuration failed: 0x%x\n", err
);
8967 /* set up pci connections */
8968 err
= pci_request_selected_regions(pdev
, pci_select_bars(pdev
,
8969 IORESOURCE_MEM
), i40e_driver_name
);
8971 dev_info(&pdev
->dev
,
8972 "pci_request_selected_regions failed %d\n", err
);
8976 pci_enable_pcie_error_reporting(pdev
);
8977 pci_set_master(pdev
);
8979 /* Now that we have a PCI connection, we need to do the
8980 * low level device setup. This is primarily setting up
8981 * the Admin Queue structures and then querying for the
8982 * device's current profile information.
8984 pf
= kzalloc(sizeof(*pf
), GFP_KERNEL
);
8991 set_bit(__I40E_DOWN
, &pf
->state
);
8995 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
8996 pci_resource_len(pdev
, 0));
8999 dev_info(&pdev
->dev
, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
9000 (unsigned int)pci_resource_start(pdev
, 0),
9001 (unsigned int)pci_resource_len(pdev
, 0), err
);
9004 hw
->vendor_id
= pdev
->vendor
;
9005 hw
->device_id
= pdev
->device
;
9006 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
9007 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
9008 hw
->subsystem_device_id
= pdev
->subsystem_device
;
9009 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
9010 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
9011 pf
->instance
= pfs_found
;
9013 /* do a special CORER for clearing PXE mode once at init */
9014 if (hw
->revision_id
== 0 &&
9015 (rd32(hw
, I40E_GLLAN_RCTL_0
) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK
)) {
9016 wr32(hw
, I40E_GLGEN_RTRIG
, I40E_GLGEN_RTRIG_CORER_MASK
);
9021 i40e_clear_pxe_mode(hw
);
9024 /* Reset here to make sure all is clean and to define PF 'n' */
9026 err
= i40e_pf_reset(hw
);
9028 dev_info(&pdev
->dev
, "Initial pf_reset failed: %d\n", err
);
9033 hw
->aq
.num_arq_entries
= I40E_AQ_LEN
;
9034 hw
->aq
.num_asq_entries
= I40E_AQ_LEN
;
9035 hw
->aq
.arq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
9036 hw
->aq
.asq_buf_size
= I40E_MAX_AQ_BUF_SIZE
;
9037 pf
->adminq_work_limit
= I40E_AQ_WORK_LIMIT
;
9038 snprintf(pf
->misc_int_name
, sizeof(pf
->misc_int_name
) - 1,
9040 dev_driver_string(&pf
->pdev
->dev
), pf
->hw
.pf_id
);
9042 err
= i40e_init_shared_code(hw
);
9044 dev_info(&pdev
->dev
, "init_shared_code failed: %d\n", err
);
9048 /* set up a default setting for link flow control */
9049 pf
->hw
.fc
.requested_mode
= I40E_FC_NONE
;
9051 err
= i40e_init_adminq(hw
);
9052 dev_info(&pdev
->dev
, "%s\n", i40e_fw_version_str(hw
));
9054 dev_info(&pdev
->dev
,
9055 "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");
9059 if (hw
->aq
.api_maj_ver
== I40E_FW_API_VERSION_MAJOR
&&
9060 hw
->aq
.api_min_ver
> I40E_FW_API_VERSION_MINOR
)
9061 dev_info(&pdev
->dev
,
9062 "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");
9063 else if (hw
->aq
.api_maj_ver
< I40E_FW_API_VERSION_MAJOR
||
9064 hw
->aq
.api_min_ver
< (I40E_FW_API_VERSION_MINOR
- 1))
9065 dev_info(&pdev
->dev
,
9066 "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
9069 i40e_verify_eeprom(pf
);
9071 /* Rev 0 hardware was never productized */
9072 if (hw
->revision_id
< 1)
9073 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");
9075 i40e_clear_pxe_mode(hw
);
9076 err
= i40e_get_capabilities(pf
);
9078 goto err_adminq_setup
;
9080 err
= i40e_sw_init(pf
);
9082 dev_info(&pdev
->dev
, "sw_init failed: %d\n", err
);
9086 err
= i40e_init_lan_hmc(hw
, hw
->func_caps
.num_tx_qp
,
9087 hw
->func_caps
.num_rx_qp
,
9088 pf
->fcoe_hmc_cntx_num
, pf
->fcoe_hmc_filt_num
);
9090 dev_info(&pdev
->dev
, "init_lan_hmc failed: %d\n", err
);
9091 goto err_init_lan_hmc
;
9094 err
= i40e_configure_lan_hmc(hw
, I40E_HMC_MODEL_DIRECT_ONLY
);
9096 dev_info(&pdev
->dev
, "configure_lan_hmc failed: %d\n", err
);
9098 goto err_configure_lan_hmc
;
9101 i40e_get_mac_addr(hw
, hw
->mac
.addr
);
9102 if (!is_valid_ether_addr(hw
->mac
.addr
)) {
9103 dev_info(&pdev
->dev
, "invalid MAC address %pM\n", hw
->mac
.addr
);
9107 dev_info(&pdev
->dev
, "MAC address: %pM\n", hw
->mac
.addr
);
9108 ether_addr_copy(hw
->mac
.perm_addr
, hw
->mac
.addr
);
9109 i40e_get_port_mac_addr(hw
, hw
->mac
.port_addr
);
9110 if (is_valid_ether_addr(hw
->mac
.port_addr
))
9111 pf
->flags
|= I40E_FLAG_PORT_ID_VALID
;
9113 err
= i40e_get_san_mac_addr(hw
, hw
->mac
.san_addr
);
9115 dev_info(&pdev
->dev
,
9116 "(non-fatal) SAN MAC retrieval failed: %d\n", err
);
9117 if (!is_valid_ether_addr(hw
->mac
.san_addr
)) {
9118 dev_warn(&pdev
->dev
, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
9120 ether_addr_copy(hw
->mac
.san_addr
, hw
->mac
.addr
);
9122 dev_info(&pf
->pdev
->dev
, "SAN MAC: %pM\n", hw
->mac
.san_addr
);
9123 #endif /* I40E_FCOE */
9125 pci_set_drvdata(pdev
, pf
);
9126 pci_save_state(pdev
);
9127 #ifdef CONFIG_I40E_DCB
9128 err
= i40e_init_pf_dcb(pf
);
9130 dev_info(&pdev
->dev
, "init_pf_dcb failed: %d\n", err
);
9131 pf
->flags
&= ~I40E_FLAG_DCB_CAPABLE
;
9132 /* Continue without DCB enabled */
9134 #endif /* CONFIG_I40E_DCB */
9136 /* set up periodic task facility */
9137 setup_timer(&pf
->service_timer
, i40e_service_timer
, (unsigned long)pf
);
9138 pf
->service_timer_period
= HZ
;
9140 INIT_WORK(&pf
->service_task
, i40e_service_task
);
9141 clear_bit(__I40E_SERVICE_SCHED
, &pf
->state
);
9142 pf
->flags
|= I40E_FLAG_NEED_LINK_UPDATE
;
9143 pf
->link_check_timeout
= jiffies
;
9145 /* WoL defaults to disabled */
9147 device_set_wakeup_enable(&pf
->pdev
->dev
, pf
->wol_en
);
9149 /* set up the main switch operations */
9150 i40e_determine_queue_usage(pf
);
9151 i40e_init_interrupt_scheme(pf
);
9153 /* The number of VSIs reported by the FW is the minimum guaranteed
9154 * to us; HW supports far more and we share the remaining pool with
9155 * the other PFs. We allocate space for more than the guarantee with
9156 * the understanding that we might not get them all later.
9158 if (pf
->hw
.func_caps
.num_vsis
< I40E_MIN_VSI_ALLOC
)
9159 pf
->num_alloc_vsi
= I40E_MIN_VSI_ALLOC
;
9161 pf
->num_alloc_vsi
= pf
->hw
.func_caps
.num_vsis
;
9163 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
9164 len
= sizeof(struct i40e_vsi
*) * pf
->num_alloc_vsi
;
9165 pf
->vsi
= kzalloc(len
, GFP_KERNEL
);
9168 goto err_switch_setup
;
9171 err
= i40e_setup_pf_switch(pf
, false);
9173 dev_info(&pdev
->dev
, "setup_pf_switch failed: %d\n", err
);
9176 /* if FDIR VSI was set up, start it now */
9177 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9178 if (pf
->vsi
[i
] && pf
->vsi
[i
]->type
== I40E_VSI_FDIR
) {
9179 i40e_vsi_open(pf
->vsi
[i
]);
9184 /* driver is only interested in link up/down and module qualification
9185 * reports from firmware
9187 err
= i40e_aq_set_phy_int_mask(&pf
->hw
,
9188 I40E_AQ_EVENT_LINK_UPDOWN
|
9189 I40E_AQ_EVENT_MODULE_QUAL_FAIL
, NULL
);
9191 dev_info(&pf
->pdev
->dev
, "set phy mask fail, aq_err %d\n", err
);
9194 err
= i40e_aq_set_link_restart_an(&pf
->hw
, true, NULL
);
9196 dev_info(&pf
->pdev
->dev
, "link restart failed, aq_err=%d\n",
9197 pf
->hw
.aq
.asq_last_status
);
9200 /* The main driver is (mostly) up and happy. We need to set this state
9201 * before setting up the misc vector or we get a race and the vector
9202 * ends up disabled forever.
9204 clear_bit(__I40E_DOWN
, &pf
->state
);
9206 /* In case of MSIX we are going to setup the misc vector right here
9207 * to handle admin queue events etc. In case of legacy and MSI
9208 * the misc functionality and queue processing is combined in
9209 * the same vector and that gets setup at open.
9211 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
9212 err
= i40e_setup_misc_vector(pf
);
9214 dev_info(&pdev
->dev
,
9215 "setup of misc vector failed: %d\n", err
);
9220 #ifdef CONFIG_PCI_IOV
9221 /* prep for VF support */
9222 if ((pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) &&
9223 (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) &&
9224 !test_bit(__I40E_BAD_EEPROM
, &pf
->state
)) {
9227 /* disable link interrupts for VFs */
9228 val
= rd32(hw
, I40E_PFGEN_PORTMDIO_NUM
);
9229 val
&= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK
;
9230 wr32(hw
, I40E_PFGEN_PORTMDIO_NUM
, val
);
9233 if (pci_num_vf(pdev
)) {
9234 dev_info(&pdev
->dev
,
9235 "Active VFs found, allocating resources.\n");
9236 err
= i40e_alloc_vfs(pf
, pci_num_vf(pdev
));
9238 dev_info(&pdev
->dev
,
9239 "Error %d allocating resources for existing VFs\n",
9243 #endif /* CONFIG_PCI_IOV */
9247 i40e_dbg_pf_init(pf
);
9249 /* tell the firmware that we're starting */
9250 i40e_send_version(pf
);
9252 /* since everything's happy, start the service_task timer */
9253 mod_timer(&pf
->service_timer
,
9254 round_jiffies(jiffies
+ pf
->service_timer_period
));
9257 /* create FCoE interface */
9258 i40e_fcoe_vsi_setup(pf
);
9261 /* Get the negotiated link width and speed from PCI config space */
9262 pcie_capability_read_word(pf
->pdev
, PCI_EXP_LNKSTA
, &link_status
);
9264 i40e_set_pci_config_data(hw
, link_status
);
9266 dev_info(&pdev
->dev
, "PCI-Express: %s %s\n",
9267 (hw
->bus
.speed
== i40e_bus_speed_8000
? "Speed 8.0GT/s" :
9268 hw
->bus
.speed
== i40e_bus_speed_5000
? "Speed 5.0GT/s" :
9269 hw
->bus
.speed
== i40e_bus_speed_2500
? "Speed 2.5GT/s" :
9271 (hw
->bus
.width
== i40e_bus_width_pcie_x8
? "Width x8" :
9272 hw
->bus
.width
== i40e_bus_width_pcie_x4
? "Width x4" :
9273 hw
->bus
.width
== i40e_bus_width_pcie_x2
? "Width x2" :
9274 hw
->bus
.width
== i40e_bus_width_pcie_x1
? "Width x1" :
9277 if (hw
->bus
.width
< i40e_bus_width_pcie_x8
||
9278 hw
->bus
.speed
< i40e_bus_speed_8000
) {
9279 dev_warn(&pdev
->dev
, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
9280 dev_warn(&pdev
->dev
, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
9283 /* print a string summarizing features */
9284 i40e_print_features(pf
);
9288 /* Unwind what we've done if something failed in the setup */
9290 set_bit(__I40E_DOWN
, &pf
->state
);
9291 i40e_clear_interrupt_scheme(pf
);
9294 i40e_reset_interrupt_capability(pf
);
9295 del_timer_sync(&pf
->service_timer
);
9297 err_configure_lan_hmc
:
9298 (void)i40e_shutdown_lan_hmc(hw
);
9301 kfree(pf
->irq_pile
);
9304 (void)i40e_shutdown_adminq(hw
);
9306 iounmap(hw
->hw_addr
);
9310 pci_disable_pcie_error_reporting(pdev
);
9311 pci_release_selected_regions(pdev
,
9312 pci_select_bars(pdev
, IORESOURCE_MEM
));
9315 pci_disable_device(pdev
);
9320 * i40e_remove - Device removal routine
9321 * @pdev: PCI device information struct
9323 * i40e_remove is called by the PCI subsystem to alert the driver
9324 * that is should release a PCI device. This could be caused by a
9325 * Hot-Plug event, or because the driver is going to be removed from
9328 static void i40e_remove(struct pci_dev
*pdev
)
9330 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
9331 i40e_status ret_code
;
9334 i40e_dbg_pf_exit(pf
);
9338 /* no more scheduling of any task */
9339 set_bit(__I40E_DOWN
, &pf
->state
);
9340 del_timer_sync(&pf
->service_timer
);
9341 cancel_work_sync(&pf
->service_task
);
9343 if (pf
->flags
& I40E_FLAG_SRIOV_ENABLED
) {
9345 pf
->flags
&= ~I40E_FLAG_SRIOV_ENABLED
;
9348 i40e_fdir_teardown(pf
);
9350 /* If there is a switch structure or any orphans, remove them.
9351 * This will leave only the PF's VSI remaining.
9353 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
9357 if (pf
->veb
[i
]->uplink_seid
== pf
->mac_seid
||
9358 pf
->veb
[i
]->uplink_seid
== 0)
9359 i40e_switch_branch_release(pf
->veb
[i
]);
9362 /* Now we can shutdown the PF's VSI, just before we kill
9365 if (pf
->vsi
[pf
->lan_vsi
])
9366 i40e_vsi_release(pf
->vsi
[pf
->lan_vsi
]);
9368 i40e_stop_misc_vector(pf
);
9369 if (pf
->flags
& I40E_FLAG_MSIX_ENABLED
) {
9370 synchronize_irq(pf
->msix_entries
[0].vector
);
9371 free_irq(pf
->msix_entries
[0].vector
, pf
);
9374 /* shutdown and destroy the HMC */
9375 if (pf
->hw
.hmc
.hmc_obj
) {
9376 ret_code
= i40e_shutdown_lan_hmc(&pf
->hw
);
9378 dev_warn(&pdev
->dev
,
9379 "Failed to destroy the HMC resources: %d\n",
9383 /* shutdown the adminq */
9384 ret_code
= i40e_shutdown_adminq(&pf
->hw
);
9386 dev_warn(&pdev
->dev
,
9387 "Failed to destroy the Admin Queue resources: %d\n",
9390 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
9391 i40e_clear_interrupt_scheme(pf
);
9392 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
9394 i40e_vsi_clear_rings(pf
->vsi
[i
]);
9395 i40e_vsi_clear(pf
->vsi
[i
]);
9400 for (i
= 0; i
< I40E_MAX_VEB
; i
++) {
9406 kfree(pf
->irq_pile
);
9409 iounmap(pf
->hw
.hw_addr
);
9411 pci_release_selected_regions(pdev
,
9412 pci_select_bars(pdev
, IORESOURCE_MEM
));
9414 pci_disable_pcie_error_reporting(pdev
);
9415 pci_disable_device(pdev
);
9419 * i40e_pci_error_detected - warning that something funky happened in PCI land
9420 * @pdev: PCI device information struct
9422 * Called to warn that something happened and the error handling steps
9423 * are in progress. Allows the driver to quiesce things, be ready for
9426 static pci_ers_result_t
i40e_pci_error_detected(struct pci_dev
*pdev
,
9427 enum pci_channel_state error
)
9429 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
9431 dev_info(&pdev
->dev
, "%s: error %d\n", __func__
, error
);
9433 /* shutdown all operations */
9434 if (!test_bit(__I40E_SUSPENDED
, &pf
->state
)) {
9436 i40e_prep_for_reset(pf
);
9440 /* Request a slot reset */
9441 return PCI_ERS_RESULT_NEED_RESET
;
9445 * i40e_pci_error_slot_reset - a PCI slot reset just happened
9446 * @pdev: PCI device information struct
9448 * Called to find if the driver can work with the device now that
9449 * the pci slot has been reset. If a basic connection seems good
9450 * (registers are readable and have sane content) then return a
9451 * happy little PCI_ERS_RESULT_xxx.
9453 static pci_ers_result_t
i40e_pci_error_slot_reset(struct pci_dev
*pdev
)
9455 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
9456 pci_ers_result_t result
;
9460 dev_info(&pdev
->dev
, "%s\n", __func__
);
9461 if (pci_enable_device_mem(pdev
)) {
9462 dev_info(&pdev
->dev
,
9463 "Cannot re-enable PCI device after reset.\n");
9464 result
= PCI_ERS_RESULT_DISCONNECT
;
9466 pci_set_master(pdev
);
9467 pci_restore_state(pdev
);
9468 pci_save_state(pdev
);
9469 pci_wake_from_d3(pdev
, false);
9471 reg
= rd32(&pf
->hw
, I40E_GLGEN_RTRIG
);
9473 result
= PCI_ERS_RESULT_RECOVERED
;
9475 result
= PCI_ERS_RESULT_DISCONNECT
;
9478 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
9480 dev_info(&pdev
->dev
,
9481 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
9483 /* non-fatal, continue */
9490 * i40e_pci_error_resume - restart operations after PCI error recovery
9491 * @pdev: PCI device information struct
9493 * Called to allow the driver to bring things back up after PCI error
9494 * and/or reset recovery has finished.
9496 static void i40e_pci_error_resume(struct pci_dev
*pdev
)
9498 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
9500 dev_info(&pdev
->dev
, "%s\n", __func__
);
9501 if (test_bit(__I40E_SUSPENDED
, &pf
->state
))
9505 i40e_handle_reset_warning(pf
);
9510 * i40e_shutdown - PCI callback for shutting down
9511 * @pdev: PCI device information struct
9513 static void i40e_shutdown(struct pci_dev
*pdev
)
9515 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
9516 struct i40e_hw
*hw
= &pf
->hw
;
9518 set_bit(__I40E_SUSPENDED
, &pf
->state
);
9519 set_bit(__I40E_DOWN
, &pf
->state
);
9521 i40e_prep_for_reset(pf
);
9524 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
9525 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
9527 if (system_state
== SYSTEM_POWER_OFF
) {
9528 pci_wake_from_d3(pdev
, pf
->wol_en
);
9529 pci_set_power_state(pdev
, PCI_D3hot
);
9535 * i40e_suspend - PCI callback for moving to D3
9536 * @pdev: PCI device information struct
9538 static int i40e_suspend(struct pci_dev
*pdev
, pm_message_t state
)
9540 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
9541 struct i40e_hw
*hw
= &pf
->hw
;
9543 set_bit(__I40E_SUSPENDED
, &pf
->state
);
9544 set_bit(__I40E_DOWN
, &pf
->state
);
9546 i40e_prep_for_reset(pf
);
9549 wr32(hw
, I40E_PFPM_APM
, (pf
->wol_en
? I40E_PFPM_APM_APME_MASK
: 0));
9550 wr32(hw
, I40E_PFPM_WUFC
, (pf
->wol_en
? I40E_PFPM_WUFC_MAG_MASK
: 0));
9552 pci_wake_from_d3(pdev
, pf
->wol_en
);
9553 pci_set_power_state(pdev
, PCI_D3hot
);
9559 * i40e_resume - PCI callback for waking up from D3
9560 * @pdev: PCI device information struct
9562 static int i40e_resume(struct pci_dev
*pdev
)
9564 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
9567 pci_set_power_state(pdev
, PCI_D0
);
9568 pci_restore_state(pdev
);
9569 /* pci_restore_state() clears dev->state_saves, so
9570 * call pci_save_state() again to restore it.
9572 pci_save_state(pdev
);
9574 err
= pci_enable_device_mem(pdev
);
9577 "%s: Cannot enable PCI device from suspend\n",
9581 pci_set_master(pdev
);
9583 /* no wakeup events while running */
9584 pci_wake_from_d3(pdev
, false);
9586 /* handling the reset will rebuild the device state */
9587 if (test_and_clear_bit(__I40E_SUSPENDED
, &pf
->state
)) {
9588 clear_bit(__I40E_DOWN
, &pf
->state
);
9590 i40e_reset_and_rebuild(pf
, false);
9598 static const struct pci_error_handlers i40e_err_handler
= {
9599 .error_detected
= i40e_pci_error_detected
,
9600 .slot_reset
= i40e_pci_error_slot_reset
,
9601 .resume
= i40e_pci_error_resume
,
9604 static struct pci_driver i40e_driver
= {
9605 .name
= i40e_driver_name
,
9606 .id_table
= i40e_pci_tbl
,
9607 .probe
= i40e_probe
,
9608 .remove
= i40e_remove
,
9610 .suspend
= i40e_suspend
,
9611 .resume
= i40e_resume
,
9613 .shutdown
= i40e_shutdown
,
9614 .err_handler
= &i40e_err_handler
,
9615 .sriov_configure
= i40e_pci_sriov_configure
,
9619 * i40e_init_module - Driver registration routine
9621 * i40e_init_module is the first routine called when the driver is
9622 * loaded. All it does is register with the PCI subsystem.
9624 static int __init
i40e_init_module(void)
9626 pr_info("%s: %s - version %s\n", i40e_driver_name
,
9627 i40e_driver_string
, i40e_driver_version_str
);
9628 pr_info("%s: %s\n", i40e_driver_name
, i40e_copyright
);
9630 return pci_register_driver(&i40e_driver
);
9632 module_init(i40e_init_module
);
9635 * i40e_exit_module - Driver exit cleanup routine
9637 * i40e_exit_module is called just before the driver is removed
9640 static void __exit
i40e_exit_module(void)
9642 pci_unregister_driver(&i40e_driver
);
9645 module_exit(i40e_exit_module
);