diff --git a/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h b/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h index f536bceec5ef6badd911c033d66766b16a24e3c1..4e87862cd501f9805407a70f3561ac04d5e3ef2c 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 184912607a2a68543f7b7fc1e1f8a206c4496f64..08b13a41a5807834e1fe1f28feeccab511294dd8 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 288d069530f9d7f936fb7136ae8563b2adc97ec3..2361f19c3b32482500f8dd7a91ad7f7ca8b96d42 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++) {