From b390b26f23864ef0684c91c06af0a2d520433834 Mon Sep 17 00:00:00 2001 From: shenjian Date: Mon, 29 Apr 2019 08:56:39 +0800 Subject: [PATCH] net: hns3: fix response value issue for mailbox message driver inclusion category: bugfix bugzilla: NA CVE: NA Previously, sometimes VF may send configure messages to PF, and ask PF return response. There is an issue when PF building the response message, the error code is always converted to 1 when resp_status is negative. This patch fixes it. Feature or Bugfix:Bugfix Signed-off-by: shenjian (K) Reviewed-by: lipeng Reviewed-by: Xie XiuQi Signed-off-by: Yang Yingliang --- .../net/ethernet/hisilicon/hns3/hclge_mbx.h | 5 +++ .../hisilicon/hns3/hns3pf/hclge_mbx.c | 32 +++++++++++++++++-- .../hisilicon/hns3/hns3vf/hclgevf_mbx.c | 29 ++++++++++++++++- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h b/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h index f536bceec5ef..4e87862cd501 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h +++ b/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h @@ -81,6 +81,11 @@ struct hclgevf_mbx_resp_status { u8 additional_info[HCLGE_MBX_MAX_RESP_DATA_SIZE]; }; +struct errno_respcode_map { + u16 resp_code; + int errno; +}; + struct hclge_mbx_vf_to_pf_cmd { u8 rsv; u8 mbx_src_vfid; /* Auto filled by IMP */ diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c index 184912607a2a..08b13a41a580 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c @@ -5,6 +5,35 @@ #include "hclge_mbx.h" #include "hnae3.h" +static const struct errno_respcode_map err_code_map[] = { + {0, 0}, + {1, -EPERM}, + {2, -ENOENT}, + {5, -EIO}, + {11, -EAGAIN}, + {12, -ENOMEM}, + {16, -EBUSY}, + {22, -EINVAL}, + {28, -ENOSPC}, + {95, -EOPNOTSUPP}, +}; + +static u16 hclge_errno_to_resp(int errno) +{ +#define UNKNOWN_ERR 0xFFFF + + u32 i; + + for (i = 0; + i < sizeof(err_code_map) / sizeof(struct errno_respcode_map); + i++) { + if (err_code_map[i].errno == errno) + return err_code_map[i].resp_code; + } + + return UNKNOWN_ERR; +} + /* hclge_gen_resp_to_vf: used to generate a synchronous response to VF when PF * receives a mailbox message from VF. * @vport: pointer to struct hclge_vport @@ -35,11 +64,10 @@ static int hclge_gen_resp_to_vf(struct hclge_vport *vport, resp_pf_to_vf->dest_vfid = vf_to_pf_req->mbx_src_vfid; resp_pf_to_vf->msg_len = vf_to_pf_req->msg_len; - resp_pf_to_vf->msg[0] = HCLGE_MBX_PF_VF_RESP; resp_pf_to_vf->msg[1] = vf_to_pf_req->msg[0]; resp_pf_to_vf->msg[2] = vf_to_pf_req->msg[1]; - resp_pf_to_vf->msg[3] = (resp_status == 0) ? 0 : 1; + resp_pf_to_vf->msg[3] = hclge_errno_to_resp(resp_status); if (resp_data && resp_data_len > 0) memcpy(&resp_pf_to_vf->msg[4], resp_data, resp_data_len); diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c index 288d069530f9..2361f19c3b32 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c @@ -5,6 +5,33 @@ #include "hclgevf_main.h" #include "hnae3.h" +static const struct errno_respcode_map err_code_map[] = { + {0, 0}, + {1, -EPERM}, + {2, -ENOENT}, + {5, -EIO}, + {11, -EAGAIN}, + {12, -ENOMEM}, + {16, -EBUSY}, + {22, -EINVAL}, + {28, -ENOSPC}, + {95, -EOPNOTSUPP}, +}; + +static int hclgevf_resp_to_errno(u16 resp_code) +{ + u32 i; + + for (i = 0; + i < sizeof(err_code_map) / sizeof(struct errno_respcode_map); + i++) { + if (err_code_map[i].resp_code == resp_code) + return err_code_map[i].errno; + } + + return -EIO; +} + static void hclgevf_reset_mbx_resp_status(struct hclgevf_dev *hdev) { /* this function should be called with mbx_resp.mbx_mutex held @@ -192,7 +219,7 @@ void hclgevf_mbx_handler(struct hclgevf_dev *hdev) resp->origin_mbx_msg = (req->msg[1] << 16); resp->origin_mbx_msg |= req->msg[2]; - resp->resp_status = req->msg[3]; + resp->resp_status = hclgevf_resp_to_errno(req->msg[3]); temp = (u8 *)&req->msg[4]; for (i = 0; i < HCLGE_MBX_MAX_RESP_DATA_SIZE; i++) { -- GitLab