Skip to content

Commit b27d023

Browse files
Hao Landavem330
authored andcommitted
net: hns3: fix the imp capability bit cannot exceed 32 bits issue
Current only the first 32 bits of the capability flag bit are considered. When the matching capability flag bit is greater than 31 bits, it will get an error bit.This patch use bitmap to solve this issue. It can handle each capability bit whitout bit width limit. Fixes: da77aef ("net: hns3: create common cmdq resource allocate/free/query APIs") Signed-off-by: Hao Lan <[email protected]> Signed-off-by: Jijie Shao <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c7b75be commit b27d023

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

drivers/net/ethernet/hisilicon/hns3/hnae3.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/pci.h>
3232
#include <linux/pkt_sched.h>
3333
#include <linux/types.h>
34+
#include <linux/bitmap.h>
3435
#include <net/pkt_cls.h>
3536
#include <net/pkt_sched.h>
3637

@@ -407,7 +408,7 @@ struct hnae3_ae_dev {
407408
unsigned long hw_err_reset_req;
408409
struct hnae3_dev_specs dev_specs;
409410
u32 dev_version;
410-
unsigned long caps[BITS_TO_LONGS(HNAE3_DEV_CAPS_MAX_NUM)];
411+
DECLARE_BITMAP(caps, HNAE3_DEV_CAPS_MAX_NUM);
411412
void *priv;
412413
};
413414

drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_cmd.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ static const struct hclge_comm_caps_bit_map hclge_vf_cmd_caps[] = {
171171
{HCLGE_COMM_CAP_GRO_B, HNAE3_DEV_SUPPORT_GRO_B},
172172
};
173173

174+
static void
175+
hclge_comm_capability_to_bitmap(unsigned long *bitmap, __le32 *caps)
176+
{
177+
const unsigned int words = HCLGE_COMM_QUERY_CAP_LENGTH;
178+
u32 val[HCLGE_COMM_QUERY_CAP_LENGTH];
179+
unsigned int i;
180+
181+
for (i = 0; i < words; i++)
182+
val[i] = __le32_to_cpu(caps[i]);
183+
184+
bitmap_from_arr32(bitmap, val,
185+
HCLGE_COMM_QUERY_CAP_LENGTH * BITS_PER_TYPE(u32));
186+
}
187+
174188
static void
175189
hclge_comm_parse_capability(struct hnae3_ae_dev *ae_dev, bool is_pf,
176190
struct hclge_comm_query_version_cmd *cmd)
@@ -179,11 +193,12 @@ hclge_comm_parse_capability(struct hnae3_ae_dev *ae_dev, bool is_pf,
179193
is_pf ? hclge_pf_cmd_caps : hclge_vf_cmd_caps;
180194
u32 size = is_pf ? ARRAY_SIZE(hclge_pf_cmd_caps) :
181195
ARRAY_SIZE(hclge_vf_cmd_caps);
182-
u32 caps, i;
196+
DECLARE_BITMAP(caps, HCLGE_COMM_QUERY_CAP_LENGTH * BITS_PER_TYPE(u32));
197+
u32 i;
183198

184-
caps = __le32_to_cpu(cmd->caps[0]);
199+
hclge_comm_capability_to_bitmap(caps, cmd->caps);
185200
for (i = 0; i < size; i++)
186-
if (hnae3_get_bit(caps, caps_map[i].imp_bit))
201+
if (test_bit(caps_map[i].imp_bit, caps))
187202
set_bit(caps_map[i].local_bit, ae_dev->caps);
188203
}
189204

0 commit comments

Comments
 (0)