Skip to content

Commit 2fc8a34

Browse files
haiyangzPaolo Abeni
authored andcommitted
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: [email protected] Fixes: ca9c54d ("net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)") Signed-off-by: Haiyang Zhang <[email protected]> Reviewed-by: Long Li <[email protected]> Reviewed-by: Shradha Gupta <[email protected]> Reviewed-by: Michal Swiatkowski <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 5f07929 commit 2fc8a34

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

drivers/net/ethernet/microsoft/mana/gdma_main.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ static int mana_gd_detect_devices(struct pci_dev *pdev)
134134
struct gdma_list_devices_resp resp = {};
135135
struct gdma_general_req req = {};
136136
struct gdma_dev_id dev;
137-
u32 i, max_num_devs;
137+
int found_dev = 0;
138138
u16 dev_type;
139139
int err;
140+
u32 i;
140141

141142
mana_gd_init_req_hdr(&req.hdr, GDMA_LIST_DEVICES, sizeof(req),
142143
sizeof(resp));
@@ -148,12 +149,17 @@ static int mana_gd_detect_devices(struct pci_dev *pdev)
148149
return err ? err : -EPROTO;
149150
}
150151

151-
max_num_devs = min_t(u32, MAX_NUM_GDMA_DEVICES, resp.num_of_devs);
152-
153-
for (i = 0; i < max_num_devs; i++) {
152+
for (i = 0; i < GDMA_DEV_LIST_SIZE &&
153+
found_dev < resp.num_of_devs; i++) {
154154
dev = resp.devs[i];
155155
dev_type = dev.type;
156156

157+
/* Skip empty devices */
158+
if (dev.as_uint32 == 0)
159+
continue;
160+
161+
found_dev++;
162+
157163
/* HWC is already detected in mana_hwc_create_channel(). */
158164
if (dev_type == GDMA_DEVICE_HWC)
159165
continue;

include/net/mana/gdma.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,6 @@ struct gdma_context {
408408
struct gdma_dev mana_ib;
409409
};
410410

411-
#define MAX_NUM_GDMA_DEVICES 4
412-
413411
static inline bool mana_gd_is_mana(struct gdma_dev *gd)
414412
{
415413
return gd->dev_id.type == GDMA_DEVICE_MANA;
@@ -556,11 +554,15 @@ enum {
556554
#define GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECONFIG BIT(3)
557555
#define GDMA_DRV_CAP_FLAG_1_VARIABLE_INDIRECTION_TABLE_SUPPORT BIT(5)
558556

557+
/* Driver can handle holes (zeros) in the device list */
558+
#define GDMA_DRV_CAP_FLAG_1_DEV_LIST_HOLES_SUP BIT(11)
559+
559560
#define GDMA_DRV_CAP_FLAGS1 \
560561
(GDMA_DRV_CAP_FLAG_1_EQ_SHARING_MULTI_VPORT | \
561562
GDMA_DRV_CAP_FLAG_1_NAPI_WKDONE_FIX | \
562563
GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECONFIG | \
563-
GDMA_DRV_CAP_FLAG_1_VARIABLE_INDIRECTION_TABLE_SUPPORT)
564+
GDMA_DRV_CAP_FLAG_1_VARIABLE_INDIRECTION_TABLE_SUPPORT | \
565+
GDMA_DRV_CAP_FLAG_1_DEV_LIST_HOLES_SUP)
564566

565567
#define GDMA_DRV_CAP_FLAGS2 0
566568

@@ -621,11 +623,12 @@ struct gdma_query_max_resources_resp {
621623
}; /* HW DATA */
622624

623625
/* GDMA_LIST_DEVICES */
626+
#define GDMA_DEV_LIST_SIZE 64
624627
struct gdma_list_devices_resp {
625628
struct gdma_resp_hdr hdr;
626629
u32 num_of_devs;
627630
u32 reserved;
628-
struct gdma_dev_id devs[64];
631+
struct gdma_dev_id devs[GDMA_DEV_LIST_SIZE];
629632
}; /* HW DATA */
630633

631634
/* GDMA_REGISTER_DEVICE */

0 commit comments

Comments
 (0)