提交 b390b26f 编写于 作者: S shenjian 提交者: Xie XiuQi

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: Nshenjian (K) <shenjian15@huawei.com>
Reviewed-by: Nlipeng <lipeng321@huawei.com>
Reviewed-by: NXie XiuQi <xiexiuqi@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 9a272e60
...@@ -81,6 +81,11 @@ struct hclgevf_mbx_resp_status { ...@@ -81,6 +81,11 @@ struct hclgevf_mbx_resp_status {
u8 additional_info[HCLGE_MBX_MAX_RESP_DATA_SIZE]; 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 { struct hclge_mbx_vf_to_pf_cmd {
u8 rsv; u8 rsv;
u8 mbx_src_vfid; /* Auto filled by IMP */ u8 mbx_src_vfid; /* Auto filled by IMP */
......
...@@ -5,6 +5,35 @@ ...@@ -5,6 +5,35 @@
#include "hclge_mbx.h" #include "hclge_mbx.h"
#include "hnae3.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 /* hclge_gen_resp_to_vf: used to generate a synchronous response to VF when PF
* receives a mailbox message from VF. * receives a mailbox message from VF.
* @vport: pointer to struct hclge_vport * @vport: pointer to struct hclge_vport
...@@ -35,11 +64,10 @@ static int hclge_gen_resp_to_vf(struct hclge_vport *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->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_len = vf_to_pf_req->msg_len;
resp_pf_to_vf->msg[0] = HCLGE_MBX_PF_VF_RESP; 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[1] = vf_to_pf_req->msg[0];
resp_pf_to_vf->msg[2] = vf_to_pf_req->msg[1]; 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) if (resp_data && resp_data_len > 0)
memcpy(&resp_pf_to_vf->msg[4], resp_data, resp_data_len); memcpy(&resp_pf_to_vf->msg[4], resp_data, resp_data_len);
......
...@@ -5,6 +5,33 @@ ...@@ -5,6 +5,33 @@
#include "hclgevf_main.h" #include "hclgevf_main.h"
#include "hnae3.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) static void hclgevf_reset_mbx_resp_status(struct hclgevf_dev *hdev)
{ {
/* this function should be called with mbx_resp.mbx_mutex held /* this function should be called with mbx_resp.mbx_mutex held
...@@ -192,7 +219,7 @@ void hclgevf_mbx_handler(struct hclgevf_dev *hdev) ...@@ -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[1] << 16);
resp->origin_mbx_msg |= req->msg[2]; 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]; temp = (u8 *)&req->msg[4];
for (i = 0; i < HCLGE_MBX_MAX_RESP_DATA_SIZE; i++) { for (i = 0; i < HCLGE_MBX_MAX_RESP_DATA_SIZE; i++) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册