ice: preserve NVM capabilities in safe mode
Subsystems (2)
Tony Nguyen
maintainerPATCH 1/6 ice: preserve NVM capabilities in safe mode
From: Jacob Keller <[email protected]>
If the driver initializes in safe mode, it will call ice_set_safe_mode_caps. This results in clearing the capabilities structures, in order to set them up for operating in safe mode, ensuring many features are disabled.
This has a side effect of also clearing the capability bits that relate to NVM update. The result is that the device driver will not indicate support for unified update, even if the firmware is capable.
Fix this by adding the relevant capability fields to the list of values we preserve. To simplify the code, use a common_cap structure instead of a handful of local variables. To reduce some duplication of the capability name, introduce a couple of macros used to restore the capabilities values from the cached copy.
--- drivers/net/ethernet/intel/ice/ice_common.c | 49 ++++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-)
drivers/net/ethernet/intel/ice/ice_common.c +27 -22
@@ -2288,26 +2288,28 @@ void ice_set_safe_mode_caps(struct ice_hw *hw) {struct ice_hw_func_caps *func_caps = &hw->func_caps;struct ice_hw_dev_caps *dev_caps = &hw->dev_caps; -u32 valid_func, rxq_first_id, txq_first_id; -u32 msix_vector_first_id, max_mtu; +struct ice_hw_common_caps cached_caps;u32 num_funcs;/* cache some func_caps values that should be restored after memset */ - valid_func = func_caps->common_cap.valid_functions; - txq_first_id = func_caps->common_cap.txq_first_id; - rxq_first_id = func_caps->common_cap.rxq_first_id; - msix_vector_first_id = func_caps->common_cap.msix_vector_first_id; - max_mtu = func_caps->common_cap.max_mtu; + cached_caps = func_caps->common_cap;/* unset func capabilities */ memset (func_caps,0 ,sizeof (*func_caps)); +#define ICE_RESTORE_FUNC_CAP (name) \ + func_caps->common_cap.name = cached_caps.name +/* restore cached values */ - func_caps->common_cap.valid_functions = valid_func; - func_caps->common_cap.txq_first_id = txq_first_id; - func_caps->common_cap.rxq_first_id = rxq_first_id; - func_caps->common_cap.msix_vector_first_id = msix_vector_first_id; - func_caps->common_cap.max_mtu = max_mtu; +ICE_RESTORE_FUNC_CAP (valid_functions); +ICE_RESTORE_FUNC_CAP (txq_first_id); +ICE_RESTORE_FUNC_CAP (rxq_first_id); +ICE_RESTORE_FUNC_CAP (msix_vector_first_id); +ICE_RESTORE_FUNC_CAP (max_mtu); +ICE_RESTORE_FUNC_CAP (nvm_unified_update); +ICE_RESTORE_FUNC_CAP (nvm_update_pending_nvm); +ICE_RESTORE_FUNC_CAP (nvm_update_pending_orom); +ICE_RESTORE_FUNC_CAP (nvm_update_pending_netlist);/* one Tx and one Rx queue in safe mode */ func_caps->common_cap.num_rxq =1 ;
@@ -2318,22 +2320,25 @@ void ice_set_safe_mode_caps(struct ice_hw *hw) func_caps->guar_num_vsi =1 ;/* cache some dev_caps values that should be restored after memset */ - valid_func = dev_caps->common_cap.valid_functions; - txq_first_id = dev_caps->common_cap.txq_first_id; - rxq_first_id = dev_caps->common_cap.rxq_first_id; - msix_vector_first_id = dev_caps->common_cap.msix_vector_first_id; - max_mtu = dev_caps->common_cap.max_mtu; + cached_caps = dev_caps->common_cap; num_funcs = dev_caps->num_funcs;/* unset dev capabilities */ memset (dev_caps,0 ,sizeof (*dev_caps)); +#define ICE_RESTORE_DEV_CAP (name) \ + dev_caps->common_cap.name = cached_caps.name +/* restore cached values */ - dev_caps->common_cap.valid_functions = valid_func; - dev_caps->common_cap.txq_first_id = txq_first_id; - dev_caps->common_cap.rxq_first_id = rxq_first_id; - dev_caps->common_cap.msix_vector_first_id = msix_vector_first_id; - dev_caps->common_cap.max_mtu = max_mtu; +ICE_RESTORE_DEV_CAP (valid_functions); +ICE_RESTORE_DEV_CAP (txq_first_id); +ICE_RESTORE_DEV_CAP (rxq_first_id); +ICE_RESTORE_DEV_CAP (msix_vector_first_id); +ICE_RESTORE_DEV_CAP (max_mtu); +ICE_RESTORE_DEV_CAP (nvm_unified_update); +ICE_RESTORE_DEV_CAP (nvm_update_pending_nvm); +ICE_RESTORE_DEV_CAP (nvm_update_pending_orom); +ICE_RESTORE_DEV_CAP (nvm_update_pending_netlist); dev_caps->num_funcs = num_funcs;/* one Tx and one Rx queue per function in safe mode */
Signature · 1 line
2.20.1
Tony Nguyen
maintainerPATCH 2/6 ice: fix adding IP4 IP6 Flow Director rules
From: Dan Nowlin <[email protected]>
A subsequent addition of an IP4 or IP6 rule after other rules would overwrite any existing TCAM entries of related L4 protocols(ex: tcp4 or udp6). This was due to the mask including too many TCAM entries. Add new packet type masks with bits properly excluded so rules are not overwritten.
--- drivers/net/ethernet/intel/ice/ice_flow.c | 62 ++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_flow.c +61 -1
@@ -99,6 +99,54 @@ static const u32 ice_ptypes_ipv6_il[] = { 0x00000000, 0x00000000, 0x00000000, 0x00000000, }; +/* Packet types for packets with an Outer/First/Single IPv4 header - no L4 */ +static const u32 ice_ipv4_ofos_no_l4[] = { +0x10C00000 ,0x04000800 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +}; + +/* Packet types for packets with an Innermost/Last IPv4 header - no L4 */ +static const u32 ice_ipv4_il_no_l4[] = { +0x60000000 ,0x18043008 ,0x80000002 ,0x6010c021 , +0x00000008 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +}; + +/* Packet types for packets with an Outer/First/Single IPv6 header - no L4 */ +static const u32 ice_ipv6_ofos_no_l4[] = { +0x00000000 ,0x00000000 ,0x43000000 ,0x10002000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +}; + +/* Packet types for packets with an Innermost/Last IPv6 header - no L4 */ +static const u32 ice_ipv6_il_no_l4[] = { +0x00000000 ,0x02180430 ,0x0000010c ,0x086010c0 , +0x00000430 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 , +}; +/* UDP Packet types for non-tunneled packets or tunneled * packets with inner UDP. */
@@ -250,11 +298,23 @@ ice_flow_proc_seg_hdrs(struct ice_flow_prof_params *params) hdrs = prof->segs[i].hdrs; -if (hdrs &ICE_FLOW_SEG_HDR_IPV4 ) { +if ((hdrs &ICE_FLOW_SEG_HDR_IPV4 ) && + !(hdrs &ICE_FLOW_SEG_HDRS_L4_MASK )) { + src = !i ? (const unsigned long *)ice_ipv4_ofos_no_l4 : + (const unsigned long *)ice_ipv4_il_no_l4; +bitmap_and (params->ptypes, params->ptypes, src, +ICE_FLOW_PTYPE_MAX ); + }else if (hdrs &ICE_FLOW_SEG_HDR_IPV4 ) { src = !i ? (const unsigned long *)ice_ptypes_ipv4_ofos : (const unsigned long *)ice_ptypes_ipv4_il;bitmap_and (params->ptypes, params->ptypes, src,ICE_FLOW_PTYPE_MAX ); + }else if ((hdrs &ICE_FLOW_SEG_HDR_IPV6 ) && + !(hdrs &ICE_FLOW_SEG_HDRS_L4_MASK )) { + src = !i ? (const unsigned long *)ice_ipv6_ofos_no_l4 : + (const unsigned long *)ice_ipv6_il_no_l4; +bitmap_and (params->ptypes, params->ptypes, src, +ICE_FLOW_PTYPE_MAX ); }else if (hdrs &ICE_FLOW_SEG_HDR_IPV6 ) { src = !i ? (const unsigned long *)ice_ptypes_ipv6_ofos : (const unsigned long *)ice_ptypes_ipv6_il;
Signature · 1 line
2.20.1
Tony Nguyen
maintainerPATCH 3/6 ice: report correct max number of TCs
In reply to Tony NguyenFrom: Dave Ertman <[email protected]>
In the driver currently, we are reporting max number of TCs to the DCBNL callback as a kernel define set to 8. This is preventing userspace applications performing DCBx to correctly down map the TCs from requested to actual values.
Report the actual max TC value to userspace from the capability struct.
--- drivers/net/ethernet/intel/ice/ice_dcb_nl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_dcb_nl.c +1 -1
@@ -136,7 +136,7 @@ ice_dcbnl_getnumtcs(struct net_device *dev, int __always_unused tcid, u8 *num)if (!test_bit (ICE_FLAG_DCB_CAPABLE , pf->flags))return -EINVAL ; - *num =IEEE_8021QAZ_MAX_TCS ; + *num = pf->hw.func_caps.common_cap.maxtc;return 0 ; }
Signature · 1 line
2.20.1
Tony Nguyen
maintainerPATCH 4/6 ice: Fix call trace on suspend
In reply to Tony NguyenFrom: Anirudh Venkataramanan <[email protected]>
It appears that the ice_suspend flow is missing a call to pci_save_state and this is triggering the message "State of device not saved by ice_suspend" and a call trace. Fix it.
--- drivers/net/ethernet/intel/ice/ice_main.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/intel/ice/ice_main.c +1 -0
@@ -4531,6 +4531,7 @@ static int __maybe_unused ice_suspend(struct device *dev) }ice_clear_interrupt_scheme (pf); +pci_save_state (pdev);pci_wake_from_d3 (pdev, pf->wol_ena);pci_set_power_state (pdev, PCI_D3hot);return 0 ;
Signature · 1 line
2.20.1
Brown
PATCH 4/6 ice: Fix call trace on suspend
Quoted 12 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Tony Nguyen
Sent: Wednesday, September 2, 2020 8:54 AM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [net 4/6] ice: Fix call trace on suspendFrom: Anirudh Venkataramanan <[email protected]>
It appears that the
ice_suspendflow is missing a call topci_save_stateand this is triggering the message "State of device not saved byice_suspend" and a call trace. Fix it.
Quoted 7 lines
Fixes 769c500dcc1e ("ice: Add advanced power mgmt for WoL")Signed-off-by Anirudh Venkataramanan--- drivers/net/ethernet/intel/ice/ice_main.c | 1 + 1 file changed, 1 insertion(+)
Tony Nguyen
maintainerPATCH 5/6 ice: fix memory leak if register_netdev_fails
In reply to Tony NguyenFrom: Jacob Keller <[email protected]>
The ice_setup_pf_sw function can cause a memory leak if register_netdev fails, due to accidentally failing to free the VSI rings. Fix the memory leak by using ice_vsi_release, ensuring we actually go through the full teardown process.
This should be safe even if the netdevice is not registered because we will have set the netdev pointer to NULL, ensuring ice_vsi_release won't call unregister_netdev.
An alternative fix would be moving management of the PF VSI netdev into the main VSI setup code. This is complicated and likely requires significant refactor in how we manage VSIs
--- drivers/net/ethernet/intel/ice/ice_lib.c | 6 +++--- drivers/net/ethernet/intel/ice/ice_lib.h | 6 ------ drivers/net/ethernet/intel/ice/ice_main.c | 13 +++---------- 3 files changed, 6 insertions(+), 19 deletions(-)
drivers/net/ethernet/intel/ice/ice_lib.c +3 -3
@@ -246,7 +246,7 @@ static int ice_get_free_slot(void *array, int size, int curr)* ice_vsi_delete - delete a VSI from the switch * @vsi: pointer to VSI being removed */ -void ice_vsi_delete (struct ice_vsi *vsi) +static void ice_vsi_delete (struct ice_vsi *vsi) {struct ice_pf *pf = vsi->back;struct ice_vsi_ctx *ctxt;
@@ -313,7 +313,7 @@ static void ice_vsi_free_arrays(struct ice_vsi *vsi)* * Returns 0 on success, negative on failure */ -int ice_vsi_clear (struct ice_vsi *vsi) +static int ice_vsi_clear (struct ice_vsi *vsi) {struct ice_pf *pf =NULL ;struct device *dev;
@@ -563,7 +563,7 @@ static int ice_vsi_get_qs(struct ice_vsi *vsi)* ice_vsi_put_qs - Release queues from VSI to PF * @vsi: the VSI that is going to release queues */ -void ice_vsi_put_qs (struct ice_vsi *vsi) +static void ice_vsi_put_qs (struct ice_vsi *vsi) {struct ice_pf *pf = vsi->back;int i;
drivers/net/ethernet/intel/ice/ice_lib.h +0 -6
@@ -45,10 +45,6 @@ int ice_cfg_vlan_pruning(struct ice_vsi *vsi, bool ena, bool vlan_promisc);void ice_cfg_sw_lldp (struct ice_vsi *vsi,bool tx,bool create); -void ice_vsi_delete (struct ice_vsi *vsi); - -int ice_vsi_clear (struct ice_vsi *vsi); -#ifdef CONFIG_DCB int ice_vsi_cfg_tc (struct ice_vsi *vsi,u8 ena_tc);#endif /* CONFIG_DCB */
@@ -79,8 +75,6 @@ bool ice_is_reset_in_progress(unsigned long *state);void ice_write_qrxflxp_cntxt (struct ice_hw *hw,u16 pf_q,u32 rxdid,u32 prio); -void ice_vsi_put_qs (struct ice_vsi *vsi); -void ice_vsi_dis_irq (struct ice_vsi *vsi);void ice_vsi_free_irq (struct ice_vsi *vsi);
drivers/net/ethernet/intel/ice/ice_main.c +3 -10
@@ -3178,10 +3178,8 @@ static int ice_setup_pf_sw(struct ice_pf *pf)return -EBUSY ; vsi =ice_pf_vsi_setup (pf, pf->hw.port_info); -if (!vsi) { - status = -ENOMEM ; - goto unroll_vsi_setup; - } +if (!vsi) +return -ENOMEM ; status =ice_cfg_netdev (vsi);if (status) {
@@ -3228,12 +3226,7 @@ static int ice_setup_pf_sw(struct ice_pf *pf) } unroll_vsi_setup: -if (vsi) { -ice_vsi_free_q_vectors (vsi); -ice_vsi_delete (vsi); -ice_vsi_put_qs (vsi); -ice_vsi_clear (vsi); - } +ice_vsi_release (vsi);return status; }
Signature · 1 line
2.20.1
Brown
PATCH 5/6 ice: fix memory leak if register_netdev_fails
Quoted 22 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Tony Nguyen
Sent: Wednesday, September 2, 2020 8:54 AM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [net 5/6] ice: fix memory leak ifregister_netdev_failsFrom: Jacob Keller <[email protected]>
The
ice_setup_pf_swfunction can cause a memory leak ifregister_netdevfails, due to accidentally failing to free the VSI rings. Fix the memory leak by usingice_vsi_release, ensuring we actually go through the full teardown process.This should be safe even if the netdevice is not registered because we will have set the netdev pointer to NULL, ensuring
ice_vsi_releasewon't callunregister_netdev.An alternative fix would be moving management of the PF VSI netdev into the main VSI setup code. This is complicated and likely requires significant refactor in how we manage VSIs
Quoted 8 lines
Fixes 3a858ba392c3 ("ice: Add support for VSI allocation and deallocation")Signed-off-by Jacob Keller <[email protected]>--- drivers/net/ethernet/intel/ice/ice_lib.c | 6 +++--- drivers/net/ethernet/intel/ice/ice_lib.h | 6 ------ drivers/net/ethernet/intel/ice/ice_main.c | 13 +++---------- 3 files changed, 6 insertions(+), 19 deletions(-)
Tony Nguyen
maintainerPATCH 6/6 ice: fix memory leak in ice_vsi_setup
In reply to Tony NguyenFrom: Jacob Keller <[email protected]>
During ice_vsi_setup, if ice_cfg_vsi_lan fails, it does not properly release memory associated with the VSI rings. If we had used devres allocations for the rings, this would be ok. However, we use kzalloc and kfree_rcu for these ring structures.
Using the correct label to cleanup the rings during ice_vsi_setup highlights an issue in the ice_vsi_clear_rings function: it can leave behind stale ring pointers in the q_vectors structure.
When releasing rings, we must also ensure that no q_vector associated with the VSI will point to this ring again. To resolve this, loop over all q_vectors and release their ring mapping. Because we are about to free all rings, no q_vector should remain pointing to any of the rings in this VSI.
--- drivers/net/ethernet/intel/ice/ice_lib.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_lib.c +13 -1
@@ -1196,6 +1196,18 @@ static void ice_vsi_clear_rings(struct ice_vsi *vsi) {int i; +/* Avoid stale references by clearing map from vector to ring */ +if (vsi->q_vectors) { +ice_for_each_q_vector (vsi, i) { +struct ice_q_vector *q_vector = vsi->q_vectors[i]; + +if (q_vector) { + q_vector->tx.ring =NULL ; + q_vector->rx.ring =NULL ; + } + } + } +if (vsi->tx_rings) {for (i =0 ; i < vsi->alloc_txq; i++) {if (vsi->tx_rings[i]) {
@@ -2291,7 +2303,7 @@ ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,if (status) {dev_err (dev,"VSI %d failed lan queue config, error %s\n" , vsi->vsi_num,ice_stat_str (status)); - goto unroll_vector_base; + goto unroll_clear_rings; }/* Add switch rule to drop all Tx Flow Control Frames, of look up
Signature · 1 line
2.20.1
Brown
PATCH 6/6 ice: fix memory leak in ice_vsi_setup
Quoted 23 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Tony Nguyen
Sent: Wednesday, September 2, 2020 8:54 AM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [net 6/6] ice: fix memory leak inice_vsi_setupFrom: Jacob Keller <[email protected]>
During
ice_vsi_setup, ifice_cfg_vsi_lanfails, it does not properly release memory associated with the VSI rings. If we had used devres allocations for the rings, this would be ok. However, we use kzalloc andkfree_rcufor these ring structures.Using the correct label to cleanup the rings during
ice_vsi_setuphighlights an issue in theice_vsi_clear_ringsfunction: it can leave behind stale ring pointers in theq_vectorsstructure.When releasing rings, we must also ensure that no
q_vectorassociated with the VSI will point to this ring again. To resolve this, loop over allq_vectorsand release their ring mapping. Because we are about to free all rings, noq_vectorshould remain pointing to any of the rings in this VSI.
Quoted 7 lines
Fixes 5513b920a4f7 ("ice: Update Tx scheduler tree for VSI multi-Tx queuesupport")
Signed-off-by Jacob Keller <[email protected]>--- drivers/net/ethernet/intel/ice/ice_lib.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)