[PATCH v4 075/103] net/ice/base: switch speed conversions to static lookups
Anatoly Burakov
anatoly.burakov at intel.com
Wed Jun 26 13:42:03 CEST 2024
From: Jesse Brandeburg <jesse.brandeburg at intel.com>
Refactor to use a constant time lookup in a table for speed conversions
from ICE_AQ_LINK_SPEED values to speeds defined in firmware.
Also, make sure 200000MBPS is defined when needed.
Signed-off-by: Jesse Brandeburg <jesse.brandeburg at intel.com>
Signed-off-by: Anatoly Burakov <anatoly.burakov at intel.com>
---
drivers/net/ice/base/ice_common.c | 40 ++++++++++++++++++++++++++--
drivers/net/ice/base/ice_common.h | 1 +
drivers/net/ice/base/ice_lan_tx_rx.h | 2 +-
3 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ice/base/ice_common.c b/drivers/net/ice/base/ice_common.c
index 9560187a85..de1079b3ae 100644
--- a/drivers/net/ice/base/ice_common.c
+++ b/drivers/net/ice/base/ice_common.c
@@ -3308,8 +3308,8 @@ bool ice_is_100m_speed_supported(struct ice_hw *hw)
* Note: In the structure of [phy_type_low, phy_type_high], there should
* be one bit set, as this function will convert one PHY type to its
* speed.
- * If no bit gets set, ICE_LINK_SPEED_UNKNOWN will be returned
- * If more than one bit gets set, ICE_LINK_SPEED_UNKNOWN will be returned
+ * If no bit gets set, ICE_AQ_LINK_SPEED_UNKNOWN will be returned
+ * If more than one bit gets set, ICE_AQ_LINK_SPEED_UNKNOWN will be returned
*/
static u16
ice_get_link_speed_based_on_phy_type(u64 phy_type_low, u64 phy_type_high)
@@ -6322,6 +6322,42 @@ bool ice_fw_supports_report_dflt_cfg(struct ice_hw *hw)
ICE_FW_API_REPORT_DFLT_CFG_PATCH);
}
+/* each of the indexes into the following array match the speed of a return
+ * value from the list of AQ returned speeds like the range:
+ * ICE_AQ_LINK_SPEED_10MB .. ICE_AQ_LINK_SPEED_100GB excluding
+ * ICE_AQ_LINK_SPEED_UNKNOWN which is BIT(15) The array is defined as 15
+ * elements long because the link_speed returned by the firmware is a 16 bit
+ * value, but is indexed by [fls(speed) - 1]
+ */
+static const u32 ice_aq_to_link_speed[] = {
+ ICE_LINK_SPEED_10MBPS, /* BIT(0) */
+ ICE_LINK_SPEED_100MBPS,
+ ICE_LINK_SPEED_1000MBPS,
+ ICE_LINK_SPEED_2500MBPS,
+ ICE_LINK_SPEED_5000MBPS,
+ ICE_LINK_SPEED_10000MBPS,
+ ICE_LINK_SPEED_20000MBPS,
+ ICE_LINK_SPEED_25000MBPS,
+ ICE_LINK_SPEED_40000MBPS,
+ ICE_LINK_SPEED_50000MBPS,
+ ICE_LINK_SPEED_100000MBPS, /* BIT(10) */
+ ICE_LINK_SPEED_200000MBPS,
+};
+
+/**
+ * ice_get_link_speed - get integer speed from table
+ * @index: array index from fls(aq speed) - 1
+ *
+ * Returns: u32 value containing integer speed
+ */
+u32 ice_get_link_speed(u16 index)
+{
+ if (index >= ARRAY_SIZE(ice_aq_to_link_speed))
+ return ICE_LINK_SPEED_UNKNOWN;
+
+ return ice_aq_to_link_speed[index];
+}
+
/**
* ice_fw_supports_fec_dis_auto
* @hw: pointer to the hardware structure
diff --git a/drivers/net/ice/base/ice_common.h b/drivers/net/ice/base/ice_common.h
index df0a247263..894d650b1a 100644
--- a/drivers/net/ice/base/ice_common.h
+++ b/drivers/net/ice/base/ice_common.h
@@ -224,6 +224,7 @@ int
ice_aq_sff_eeprom(struct ice_hw *hw, u16 lport, u8 bus_addr,
u16 mem_addr, u8 page, u8 set_page, u8 *data, u8 length,
bool write, struct ice_sq_cd *cd);
+u32 ice_get_link_speed(u16 index);
int
ice_aq_prog_topo_dev_nvm(struct ice_hw *hw,
diff --git a/drivers/net/ice/base/ice_lan_tx_rx.h b/drivers/net/ice/base/ice_lan_tx_rx.h
index 39673e36f7..a28345c2c4 100644
--- a/drivers/net/ice/base/ice_lan_tx_rx.h
+++ b/drivers/net/ice/base/ice_lan_tx_rx.h
@@ -2469,5 +2469,5 @@ static inline struct ice_rx_ptype_decoded ice_decode_rx_desc_ptype(u16 ptype)
#define ICE_LINK_SPEED_40000MBPS 40000
#define ICE_LINK_SPEED_50000MBPS 50000
#define ICE_LINK_SPEED_100000MBPS 100000
-
+#define ICE_LINK_SPEED_200000MBPS 200000
#endif /* _ICE_LAN_TX_RX_H_ */
--
2.43.0
More information about the dev
mailing list