diff mbox series

[net] net: mana: Support holes in device list reply msg

Message ID 1741211181-6990-1-git-send-email-haiyangz@microsoft.com (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series [net] net: mana: Support holes in device list reply msg | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success Errors and warnings before: 26 (+0) this patch: 26 (+0)
netdev/cc_maintainers warning 3 maintainers not CCed: kotaranov@microsoft.com andrew+netdev@lunn.ch horms@kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning CHECK: Alignment should match open parenthesis
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-03-06--03-00 (tests: 894)

Commit Message

Haiyang Zhang March 5, 2025, 9:46 p.m. UTC
According to GDMA protocol, holes (zeros) are allowed at the beginning
or middle of the gdma_list_devices_resp message. The existing code
cannot properly handle this, and may miss some devices in the list.

To fix, scan the entire list until the num_of_devs are found, or until
the end of the list.

Cc: stable@vger.kernel.org
Fixes: ca9c54d2d6a5 ("net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)")
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>

---
 drivers/net/ethernet/microsoft/mana/gdma_main.c | 16 ++++++++++++----
 include/net/mana/gdma.h                         | 11 +++++++----
 2 files changed, 19 insertions(+), 8 deletions(-)

Comments

Long Li March 5, 2025, 11:25 p.m. UTC | #1
> Subject: [PATCH net] net: mana: Support holes in device list reply msg
> 
> According to GDMA protocol, holes (zeros) are allowed at the beginning or middle
> of the gdma_list_devices_resp message. The existing code cannot properly
> handle this, and may miss some devices in the list.
> 
> To fix, scan the entire list until the num_of_devs are found, or until the end of the
> list.
> 
> Cc: stable@vger.kernel.org
> Fixes: ca9c54d2d6a5 ("net: mana: Add a driver for Microsoft Azure Network
> Adapter (MANA)")
> Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>

Reviewed-by: Long Li <longli@microsoft.com>

> 
> ---
>  drivers/net/ethernet/microsoft/mana/gdma_main.c | 16 ++++++++++++----
>  include/net/mana/gdma.h                         | 11 +++++++----
>  2 files changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c
> b/drivers/net/ethernet/microsoft/mana/gdma_main.c
> index c15a5ef4674e..df3ab31974b1 100644
> --- a/drivers/net/ethernet/microsoft/mana/gdma_main.c
> +++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c
> @@ -134,9 +134,10 @@ static int mana_gd_detect_devices(struct pci_dev
> *pdev)
>  	struct gdma_list_devices_resp resp = {};
>  	struct gdma_general_req req = {};
>  	struct gdma_dev_id dev;
> -	u32 i, max_num_devs;
> +	int found_dev = 0;
>  	u16 dev_type;
>  	int err;
> +	u32 i;
> 
>  	mana_gd_init_req_hdr(&req.hdr, GDMA_LIST_DEVICES, sizeof(req),
>  			     sizeof(resp));
> @@ -148,12 +149,19 @@ static int mana_gd_detect_devices(struct pci_dev
> *pdev)
>  		return err ? err : -EPROTO;
>  	}
> 
> -	max_num_devs = min_t(u32, MAX_NUM_GDMA_DEVICES,
> resp.num_of_devs);
> -
> -	for (i = 0; i < max_num_devs; i++) {
> +	for (i = 0; i < GDMA_DEV_LIST_SIZE &&
> +		found_dev < resp.num_of_devs; i++) {
>  		dev = resp.devs[i];
>  		dev_type = dev.type;
> 
> +		/* Skip empty devices */
> +		if (dev.as_uint32 == 0)
> +			continue;
> +
> +		found_dev++;
> +		dev_info(gc->dev, "Got devidx:%u, type:%u, instance:%u\n", i,
> +			 dev.type, dev.instance);
> +
>  		/* HWC is already detected in mana_hwc_create_channel(). */
>  		if (dev_type == GDMA_DEVICE_HWC)
>  			continue;
> diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h index
> 90f56656b572..62e9d7673862 100644
> --- a/include/net/mana/gdma.h
> +++ b/include/net/mana/gdma.h
> @@ -408,8 +408,6 @@ struct gdma_context {
>  	struct gdma_dev		mana_ib;
>  };
> 
> -#define MAX_NUM_GDMA_DEVICES	4
> -
>  static inline bool mana_gd_is_mana(struct gdma_dev *gd)  {
>  	return gd->dev_id.type == GDMA_DEVICE_MANA; @@ -556,11 +554,15
> @@ enum {  #define GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECONFIG
> BIT(3)  #define
> GDMA_DRV_CAP_FLAG_1_VARIABLE_INDIRECTION_TABLE_SUPPORT BIT(5)
> 
> +/* Driver can handle holes (zeros) in the device list */ #define
> +GDMA_DRV_CAP_FLAG_1_DEV_LIST_HOLES_SUP BIT(11)
> +
>  #define GDMA_DRV_CAP_FLAGS1 \
>  	(GDMA_DRV_CAP_FLAG_1_EQ_SHARING_MULTI_VPORT | \
>  	 GDMA_DRV_CAP_FLAG_1_NAPI_WKDONE_FIX | \
>  	 GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECONFIG | \
> -	 GDMA_DRV_CAP_FLAG_1_VARIABLE_INDIRECTION_TABLE_SUPPORT)
> +	 GDMA_DRV_CAP_FLAG_1_VARIABLE_INDIRECTION_TABLE_SUPPORT |
> \
> +	 GDMA_DRV_CAP_FLAG_1_DEV_LIST_HOLES_SUP)
> 
>  #define GDMA_DRV_CAP_FLAGS2 0
> 
> @@ -621,11 +623,12 @@ struct gdma_query_max_resources_resp {  }; /* HW
> DATA */
> 
>  /* GDMA_LIST_DEVICES */
> +#define GDMA_DEV_LIST_SIZE 64
>  struct gdma_list_devices_resp {
>  	struct gdma_resp_hdr hdr;
>  	u32 num_of_devs;
>  	u32 reserved;
> -	struct gdma_dev_id devs[64];
> +	struct gdma_dev_id devs[GDMA_DEV_LIST_SIZE];
>  }; /* HW DATA */
> 
>  /* GDMA_REGISTER_DEVICE */
> --
> 2.34.1
diff mbox series

Patch

diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c
index c15a5ef4674e..df3ab31974b1 100644
--- a/drivers/net/ethernet/microsoft/mana/gdma_main.c
+++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c
@@ -134,9 +134,10 @@  static int mana_gd_detect_devices(struct pci_dev *pdev)
 	struct gdma_list_devices_resp resp = {};
 	struct gdma_general_req req = {};
 	struct gdma_dev_id dev;
-	u32 i, max_num_devs;
+	int found_dev = 0;
 	u16 dev_type;
 	int err;
+	u32 i;
 
 	mana_gd_init_req_hdr(&req.hdr, GDMA_LIST_DEVICES, sizeof(req),
 			     sizeof(resp));
@@ -148,12 +149,19 @@  static int mana_gd_detect_devices(struct pci_dev *pdev)
 		return err ? err : -EPROTO;
 	}
 
-	max_num_devs = min_t(u32, MAX_NUM_GDMA_DEVICES, resp.num_of_devs);
-
-	for (i = 0; i < max_num_devs; i++) {
+	for (i = 0; i < GDMA_DEV_LIST_SIZE &&
+		found_dev < resp.num_of_devs; i++) {
 		dev = resp.devs[i];
 		dev_type = dev.type;
 
+		/* Skip empty devices */
+		if (dev.as_uint32 == 0)
+			continue;
+
+		found_dev++;
+		dev_info(gc->dev, "Got devidx:%u, type:%u, instance:%u\n", i,
+			 dev.type, dev.instance);
+
 		/* HWC is already detected in mana_hwc_create_channel(). */
 		if (dev_type == GDMA_DEVICE_HWC)
 			continue;
diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h
index 90f56656b572..62e9d7673862 100644
--- a/include/net/mana/gdma.h
+++ b/include/net/mana/gdma.h
@@ -408,8 +408,6 @@  struct gdma_context {
 	struct gdma_dev		mana_ib;
 };
 
-#define MAX_NUM_GDMA_DEVICES	4
-
 static inline bool mana_gd_is_mana(struct gdma_dev *gd)
 {
 	return gd->dev_id.type == GDMA_DEVICE_MANA;
@@ -556,11 +554,15 @@  enum {
 #define GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECONFIG BIT(3)
 #define GDMA_DRV_CAP_FLAG_1_VARIABLE_INDIRECTION_TABLE_SUPPORT BIT(5)
 
+/* Driver can handle holes (zeros) in the device list */
+#define GDMA_DRV_CAP_FLAG_1_DEV_LIST_HOLES_SUP BIT(11)
+
 #define GDMA_DRV_CAP_FLAGS1 \
 	(GDMA_DRV_CAP_FLAG_1_EQ_SHARING_MULTI_VPORT | \
 	 GDMA_DRV_CAP_FLAG_1_NAPI_WKDONE_FIX | \
 	 GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECONFIG | \
-	 GDMA_DRV_CAP_FLAG_1_VARIABLE_INDIRECTION_TABLE_SUPPORT)
+	 GDMA_DRV_CAP_FLAG_1_VARIABLE_INDIRECTION_TABLE_SUPPORT | \
+	 GDMA_DRV_CAP_FLAG_1_DEV_LIST_HOLES_SUP)
 
 #define GDMA_DRV_CAP_FLAGS2 0
 
@@ -621,11 +623,12 @@  struct gdma_query_max_resources_resp {
 }; /* HW DATA */
 
 /* GDMA_LIST_DEVICES */
+#define GDMA_DEV_LIST_SIZE 64
 struct gdma_list_devices_resp {
 	struct gdma_resp_hdr hdr;
 	u32 num_of_devs;
 	u32 reserved;
-	struct gdma_dev_id devs[64];
+	struct gdma_dev_id devs[GDMA_DEV_LIST_SIZE];
 }; /* HW DATA */
 
 /* GDMA_REGISTER_DEVICE */