Skip to contentSkip to conversation

ethtool: Add link mode maps for forced speeds

PATCH Applied Paul Greenwalt 3 participants 8 messages Oct 15, 2023 – Oct 18, 2023

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v5 cover ethtool: Add link mode maps for forced speeds

The following patch set was initially a part of [1]. As the purpose of the original series was to add the support of the new hardware to the intel ice driver, the refactoring of advertised link modes mapping was extracted to a new set.

The patch set adds a common mechanism for mapping Ethtool forced speeds with Ethtool supported link modes, which can be used in drivers code.

[1] https://lore.kernel.org/netdev/[email protected]

Changelog:
v4->v5:
Separated ethtool and qede changes into two patches, fixed indentation, and moved ethtool_forced_speed_maps_init() from ioctl.c to ethtool.h

v3->v4:
Moved the macro for setting fields into the common header file

v2->v3:
Fixed whitespaces, added missing line at end of file

v1->v2:
Fixed formatting, typo, moved declaration of iterator to loop line.

Paul Greenwalt (2):
ethtool: Add forced speed to supported link modes maps
qede: Refactor qede_forced_speed_maps_init()

Pawel Chmielewski (1):
ice: Refactor finding advertised link speed

 drivers/net/ethernet/intel/ice/ice.h          |   1 +
 drivers/net/ethernet/intel/ice/ice_ethtool.c  | 193 ++++++++++++------
 drivers/net/ethernet/intel/ice/ice_main.c     |   2 +
 .../net/ethernet/qlogic/qede/qede_ethtool.c   |  46 ++---
 include/linux/ethtool.h                       |  37 ++++
 include/linux/linkmode.h                      |  29 +--
 6 files changed, 195 insertions(+), 113 deletions(-)

base-commit: ac4dec3fd63c7da703c244698fc92efb411ff0d4

Signature · 1 line
2.40.0
#1 lore raw

PATCH v5 1/3 ethtool: Add forced speed to supported link modes maps

The need to map Ethtool forced speeds to Ethtool supported link modes is common among drivers. To support this, add a common structure for forced speed maps and a function to init them. This is solution was originally introduced in commit 1d4e4ecccb11 ("qede: populate supported link modes maps on module init") for qede driver.

ethtool_forced_speed_maps_init() should be called during driver init with an array of struct ethtool_forced_speed_map to populate the mapping.

Definitions for maps themselves are left in the driver code, as the sets of supported link modes may vary between the devices.

---
 include/linux/ethtool.h  | 37 +++++++++++++++++++++++++++++++++++++
 include/linux/linkmode.h | 29 +++++++++++++++--------------
 2 files changed, 52 insertions(+), 14 deletions(-)
include/linux/ethtool.h +37 -0
index 62b61527bcc4..8e91e8b8a693 100644
@@ -13,6 +13,7 @@
 #ifndef _LINUX_ETHTOOL_H
 #define _LINUX_ETHTOOL_H
 
+#include <linux/linkmode.h>
 #include <linux/bitmap.h>
 #include <linux/compat.h>
 #include <linux/if_ether.h>
@@ -1052,4 +1053,40 @@ static inline int ethtool_mm_frag_size_min_to_add(u32 val_min, u32 *val_add,
  * next string.
  */
 extern __printf(2, 3) void ethtool_sprintf(u8 **data, const char *fmt, ...);
+
+/* Link mode to forced speed capabilities maps */
+struct ethtool_forced_speed_map {
+	u32		speed;
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(caps);
+
+	const u32	*cap_arr;
+	u32		arr_size;
+};
+
+#define ETHTOOL_FORCED_SPEED_MAP(prefix, value)				\
+{									\
+	.speed		= SPEED_##value,				\
+	.cap_arr	= prefix##_##value,				\
+	.arr_size	= ARRAY_SIZE(prefix##_##value),			\
+}
+
+/**
+ * ethtool_forced_speed_maps_init
+ * @maps: Pointer to an array of Ethtool forced speed map
+ * @size: Array size
+ *
+ * Initialize an array of Ethtool forced speed map to Ethtool link modes. This
+ * should be called during driver module init.
+ */
+static inline void
+ethtool_forced_speed_maps_init(struct ethtool_forced_speed_map *maps, u32 size)
+{
+	for (u32 i = 0; i < size; i++) {
+		struct ethtool_forced_speed_map *map = &maps[i];
+
+		linkmode_set_bit_array(map->cap_arr, map->arr_size, map->caps);
+		map->cap_arr = NULL;
+		map->arr_size = 0;
+	}
+}
 #endif /* _LINUX_ETHTOOL_H */
include/linux/linkmode.h +15 -14
index 15e0e0209da4..cd38f89553e6 100644
@@ -2,6 +2,21 @@
 #define __LINKMODE_H
 
 #include <linux/bitmap.h>
+
+static inline void linkmode_set_bit(int nr, volatile unsigned long *addr)
+{
+	__set_bit(nr, addr);
+}
+
+static inline void linkmode_set_bit_array(const int *array, int array_size,
+					  unsigned long *addr)
+{
+	int i;
+
+	for (i = 0; i < array_size; i++)
+		linkmode_set_bit(array[i], addr);
+}
+
 #include <linux/ethtool.h>
 #include <uapi/linux/ethtool.h>
 
@@ -38,20 +53,6 @@ static inline int linkmode_andnot(unsigned long *dst, const unsigned long *src1,
 	return bitmap_andnot(dst, src1, src2,  __ETHTOOL_LINK_MODE_MASK_NBITS);
 }
 
-static inline void linkmode_set_bit(int nr, volatile unsigned long *addr)
-{
-	__set_bit(nr, addr);
-}
-
-static inline void linkmode_set_bit_array(const int *array, int array_size,
-					  unsigned long *addr)
-{
-	int i;
-
-	for (i = 0; i < array_size; i++)
-		linkmode_set_bit(array[i], addr);
-}
-
 static inline void linkmode_clear_bit(int nr, volatile unsigned long *addr)
 {
 	__clear_bit(nr, addr);
Signature · 1 line
2.40.0
reviewer Reviewed-by on v5 1/3
#2 lore raw

Re: [PATCH net-next v5 1/3] ethtool: Add forced speed to supported link modes maps

Quoted 9 lines · Paul Greenwalt

The need to map Ethtool forced speeds to Ethtool supported link modes is common among drivers. To support this, add a common structure for forced speed maps and a function to init them. This is solution was originally introduced in commit 1d4e4ecccb11 ("qede: populate supported link modes maps on module init") for qede driver.

ethtool_forced_speed_maps_init() should be called during driver init with an array of struct ethtool_forced_speed_map to populate the mapping.

Quoted 8 lines

Definitions for maps themselves are left in the driver code, as the sets of supported link modes may vary between the devices.

Thanks Paul,

I verified that this duplicates infrastructure added by the commit quoted above. And splits adding the new from removing the old into separate patches as suggested by Jiri in his review of v2.

This leads to nice code reuse in patch 3/3
and makes for a nicely constructed patchset.

#3 lore raw

PATCH v5 2/3 qede: Refactor qede_forced_speed_maps_init()

In reply to Paul Greenwalt

Refactor qede_forced_speed_maps_init() to use commen implementation ethtool_forced_speed_maps_init().

The qede driver was compile tested only.

---
 .../net/ethernet/qlogic/qede/qede_ethtool.c   | 46 +++++--------------
 1 file changed, 12 insertions(+), 34 deletions(-)
drivers/net/ethernet/qlogic/qede/qede_ethtool.c +12 -34
index 95820cf1cd6c..b6b849a079ed 100644
@@ -201,21 +201,6 @@ static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
 
 /* Forced speed capabilities maps */
 
-struct qede_forced_speed_map {
-	u32		speed;
-	__ETHTOOL_DECLARE_LINK_MODE_MASK(caps);
-
-	const u32	*cap_arr;
-	u32		arr_size;
-};
-
-#define QEDE_FORCED_SPEED_MAP(value)					\
-{									\
-	.speed		= SPEED_##value,				\
-	.cap_arr	= qede_forced_speed_##value,			\
-	.arr_size	= ARRAY_SIZE(qede_forced_speed_##value),	\
-}
-
 static const u32 qede_forced_speed_1000[] __initconst = {
 	ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
 	ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
@@ -263,28 +248,21 @@ static const u32 qede_forced_speed_100000[] __initconst = {
 	ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT,
 };
 
-static struct qede_forced_speed_map qede_forced_speed_maps[] __ro_after_init = {
-	QEDE_FORCED_SPEED_MAP(1000),
-	QEDE_FORCED_SPEED_MAP(10000),
-	QEDE_FORCED_SPEED_MAP(20000),
-	QEDE_FORCED_SPEED_MAP(25000),
-	QEDE_FORCED_SPEED_MAP(40000),
-	QEDE_FORCED_SPEED_MAP(50000),
-	QEDE_FORCED_SPEED_MAP(100000),
+static struct ethtool_forced_speed_map
+qede_forced_speed_maps[] __ro_after_init = {
+	ETHTOOL_FORCED_SPEED_MAP(qede_forced_speed, 1000),
+	ETHTOOL_FORCED_SPEED_MAP(qede_forced_speed, 10000),
+	ETHTOOL_FORCED_SPEED_MAP(qede_forced_speed, 20000),
+	ETHTOOL_FORCED_SPEED_MAP(qede_forced_speed, 25000),
+	ETHTOOL_FORCED_SPEED_MAP(qede_forced_speed, 40000),
+	ETHTOOL_FORCED_SPEED_MAP(qede_forced_speed, 50000),
+	ETHTOOL_FORCED_SPEED_MAP(qede_forced_speed, 100000),
 };
 
 void __init qede_forced_speed_maps_init(void)
 {
-	struct qede_forced_speed_map *map;
-	u32 i;
-
-	for (i = 0; i < ARRAY_SIZE(qede_forced_speed_maps); i++) {
-		map = qede_forced_speed_maps + i;
-
-		linkmode_set_bit_array(map->cap_arr, map->arr_size, map->caps);
-		map->cap_arr = NULL;
-		map->arr_size = 0;
-	}
+	ethtool_forced_speed_maps_init(qede_forced_speed_maps,
+				       ARRAY_SIZE(qede_forced_speed_maps));
 }
 
 /* Ethtool callbacks */
@@ -564,8 +542,8 @@ static int qede_set_link_ksettings(struct net_device *dev,
 				   const struct ethtool_link_ksettings *cmd)
 {
 	const struct ethtool_link_settings *base = &cmd->base;
+	const struct ethtool_forced_speed_map *map;
 	struct qede_dev *edev = netdev_priv(dev);
-	const struct qede_forced_speed_map *map;
 	struct qed_link_output current_link;
 	struct qed_link_params params;
 	u32 i;
Signature · 1 line
2.40.0
reviewer Reviewed-by on v5 2/3
#4 lore raw

Re: [PATCH net-next v5 2/3] qede: Refactor qede_forced_speed_maps_init()

Quoted 9 lines · Paul Greenwalt

Refactor qede_forced_speed_maps_init() to use commen implementation ethtool_forced_speed_maps_init().

The qede driver was compile tested only.

#5 lore raw

PATCH v5 3/3 ice: Refactor finding advertised link speed

In reply to Paul Greenwalt

From: Pawel Chmielewski <[email protected]>

Refactor ice_get_link_ksettings to using forced speed to link modes mapping.

---
 drivers/net/ethernet/intel/ice/ice.h         |   1 +
 drivers/net/ethernet/intel/ice/ice_ethtool.c | 193 ++++++++++++-------
 drivers/net/ethernet/intel/ice/ice_main.c    |   2 +
 3 files changed, 131 insertions(+), 65 deletions(-)
drivers/net/ethernet/intel/ice/ice.h +1 -0
index ad5614d4449c..64d0af39cb98 100644
@@ -969,6 +969,7 @@ int ice_stop(struct net_device *netdev);
 void ice_service_task_schedule(struct ice_pf *pf);
 int ice_load(struct ice_pf *pf);
 void ice_unload(struct ice_pf *pf);
+void ice_adv_lnk_speed_maps_init(void);
 
 /**
  * ice_set_rdma_cap - enable RDMA support
drivers/net/ethernet/intel/ice/ice_ethtool.c +128 -65

213 lines not on this page · raw message

drivers/net/ethernet/intel/ice/ice_main.c +2 -0
index a58da0024fe5..e5aad584aedb 100644
@@ -5756,6 +5756,8 @@ static int __init ice_module_init(void)
 	pr_info("%s\n", ice_driver_string);
 	pr_info("%s\n", ice_copyright);
 
+	ice_adv_lnk_speed_maps_init();
+
 	ice_wq = alloc_workqueue("%s", 0, 0, KBUILD_MODNAME);
 	if (!ice_wq) {
 		pr_err("Failed to create workqueue\n");
Signature · 1 line
2.40.0
reviewer Reviewed-by on v5 3/3
#6 lore raw

Re: [PATCH net-next v5 3/3] ice: Refactor finding advertised link speed

Quoted 10 lines · Paul Greenwalt

From: Pawel Chmielewski <[email protected]>

Refactor ice_get_link_ksettings to using forced speed to link modes mapping.

#7 lore raw
In reply to Paul Greenwalt
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Quoted 9 lines · On Sun, 15 Oct 2023 19:43:01 -0400 you wrote:

The following patch set was initially a part of [1]. As the purpose of the original series was to add the support of the new hardware to the intel ice driver, the refactoring of advertised link modes mapping was extracted to a new set.

The patch set adds a common mechanism for mapping Ethtool forced speeds with Ethtool supported link modes, which can be used in drivers code.

[...]

Here is the summary with links:
- [net-next,v5,1/3] ethtool: Add forced speed to supported link modes maps

    https://git.kernel.org/netdev/net-next/c/26c5334d344d
  - [net-next,v5,2/3] qede: Refactor qede_forced_speed_maps_init()
    https://git.kernel.org/netdev/net-next/c/a5b65cd2a317
  - [net-next,v5,3/3] ice: Refactor finding advertised link speed
    https://git.kernel.org/netdev/net-next/c/982b0192db45

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html