Skip to content

Commit 2a5a880

Browse files
Edwin Peerdavem330
authored andcommitted
bnxt_en: fix firmware message length endianness
The explicit mask and shift is not the appropriate way to parse fields out of a little endian struct. The length field is internally __le16 and the strategy employed only happens to work on little endian machines because the offset used is actually incorrect (length is at offset 6). Also remove the related and no longer used definitions from bnxt.h. Fixes: 845adfe ("bnxt_en: Improve valid bit checking in firmware response message.") Signed-off-by: Edwin Peer <[email protected]> Signed-off-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 95ec1f4 commit 2a5a880

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4176,14 +4176,12 @@ static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len,
41764176
int i, intr_process, rc, tmo_count;
41774177
struct input *req = msg;
41784178
u32 *data = msg;
4179-
__le32 *resp_len;
41804179
u8 *valid;
41814180
u16 cp_ring_id, len = 0;
41824181
struct hwrm_err_output *resp = bp->hwrm_cmd_resp_addr;
41834182
u16 max_req_len = BNXT_HWRM_MAX_REQ_LEN;
41844183
struct hwrm_short_input short_input = {0};
41854184
u32 doorbell_offset = BNXT_GRCPF_REG_CHIMP_COMM_TRIGGER;
4186-
u8 *resp_addr = (u8 *)bp->hwrm_cmd_resp_addr;
41874185
u32 bar_offset = BNXT_GRCPF_REG_CHIMP_COMM;
41884186
u16 dst = BNXT_HWRM_CHNL_CHIMP;
41894187

@@ -4201,7 +4199,6 @@ static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len,
42014199
bar_offset = BNXT_GRCPF_REG_KONG_COMM;
42024200
doorbell_offset = BNXT_GRCPF_REG_KONG_COMM_TRIGGER;
42034201
resp = bp->hwrm_cmd_kong_resp_addr;
4204-
resp_addr = (u8 *)bp->hwrm_cmd_kong_resp_addr;
42054202
}
42064203

42074204
memset(resp, 0, PAGE_SIZE);
@@ -4270,7 +4267,6 @@ static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len,
42704267
tmo_count = HWRM_SHORT_TIMEOUT_COUNTER;
42714268
timeout = timeout - HWRM_SHORT_MIN_TIMEOUT * HWRM_SHORT_TIMEOUT_COUNTER;
42724269
tmo_count += DIV_ROUND_UP(timeout, HWRM_MIN_TIMEOUT);
4273-
resp_len = (__le32 *)(resp_addr + HWRM_RESP_LEN_OFFSET);
42744270

42754271
if (intr_process) {
42764272
u16 seq_id = bp->hwrm_intr_seq_id;
@@ -4298,9 +4294,8 @@ static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len,
42984294
le16_to_cpu(req->req_type));
42994295
return -EBUSY;
43004296
}
4301-
len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >>
4302-
HWRM_RESP_LEN_SFT;
4303-
valid = resp_addr + len - 1;
4297+
len = le16_to_cpu(resp->resp_len);
4298+
valid = ((u8 *)resp) + len - 1;
43044299
} else {
43054300
int j;
43064301

@@ -4311,8 +4306,7 @@ static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len,
43114306
*/
43124307
if (test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state))
43134308
return -EBUSY;
4314-
len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >>
4315-
HWRM_RESP_LEN_SFT;
4309+
len = le16_to_cpu(resp->resp_len);
43164310
if (len)
43174311
break;
43184312
/* on first few passes, just barely sleep */
@@ -4334,7 +4328,7 @@ static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len,
43344328
}
43354329

43364330
/* Last byte of resp contains valid bit */
4337-
valid = resp_addr + len - 1;
4331+
valid = ((u8 *)resp) + len - 1;
43384332
for (j = 0; j < HWRM_VALID_BIT_DELAY_USEC; j++) {
43394333
/* make sure we read from updated DMA memory */
43404334
dma_rmb();

drivers/net/ethernet/broadcom/bnxt/bnxt.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -656,11 +656,6 @@ struct nqe_cn {
656656
#define HWRM_CMD_TIMEOUT (bp->hwrm_cmd_timeout)
657657
#define HWRM_RESET_TIMEOUT ((HWRM_CMD_TIMEOUT) * 4)
658658
#define HWRM_COREDUMP_TIMEOUT ((HWRM_CMD_TIMEOUT) * 12)
659-
#define HWRM_RESP_ERR_CODE_MASK 0xffff
660-
#define HWRM_RESP_LEN_OFFSET 4
661-
#define HWRM_RESP_LEN_MASK 0xffff0000
662-
#define HWRM_RESP_LEN_SFT 16
663-
#define HWRM_RESP_VALID_MASK 0xff000000
664659
#define BNXT_HWRM_REQ_MAX_SIZE 128
665660
#define BNXT_HWRM_REQS_PER_PAGE (BNXT_PAGE_SIZE / \
666661
BNXT_HWRM_REQ_MAX_SIZE)

0 commit comments

Comments
 (0)