Skip to content

Commit 764430c

Browse files
jbrandebJeff Kirsher
authored andcommitted
i40e/virtchnl: refactor code for validate checks
This change updates the arguments passed to the validate function and fixes the caller, as well as uses the new return values added to virtchnl.h One other minor tweak, remove a duplicate set to zero of valid_len. This is in preparation for moving the function to virtchnl.h. Signed-off-by: Jesse Brandeburg <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent eedcfef commit 764430c

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,15 +2536,16 @@ static int i40e_vc_set_rss_hena(struct i40e_vf *vf, u8 *msg, u16 msglen)
25362536

25372537
/**
25382538
* i40e_vc_validate_vf_msg
2539-
* @vf: pointer to the VF info
2539+
* @ver: Virtchnl version info
2540+
* @v_opcode: Opcode for the message
25402541
* @msg: pointer to the msg buffer
25412542
* @msglen: msg length
2542-
* @msghndl: msg handle
25432543
*
2544-
* validate msg
2544+
* validate msg format against struct for each opcode
25452545
**/
2546-
static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
2547-
u32 v_retval, u8 *msg, u16 msglen)
2546+
static int
2547+
i40e_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
2548+
u8 *msg, u16 msglen)
25482549
{
25492550
bool err_msg_format = false;
25502551
int valid_len = 0;
@@ -2557,7 +2558,7 @@ static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
25572558
case VIRTCHNL_OP_RESET_VF:
25582559
break;
25592560
case VIRTCHNL_OP_GET_VF_RESOURCES:
2560-
if (VF_IS_V11(&vf->vf_ver))
2561+
if (VF_IS_V11(ver))
25612562
valid_len = sizeof(u32);
25622563
break;
25632564
case VIRTCHNL_OP_CONFIG_TX_QUEUE:
@@ -2633,7 +2634,6 @@ static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
26332634
err_msg_format = true;
26342635
break;
26352636
case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
2636-
valid_len = 0;
26372637
break;
26382638
case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
26392639
valid_len = sizeof(struct virtchnl_iwarp_qvlist_info);
@@ -2673,15 +2673,13 @@ static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
26732673
case VIRTCHNL_OP_EVENT:
26742674
case VIRTCHNL_OP_UNKNOWN:
26752675
default:
2676-
return -EPERM;
2676+
return VIRTCHNL_ERR_PARAM;
26772677
}
26782678
/* few more checks */
2679-
if ((valid_len != msglen) || (err_msg_format)) {
2680-
i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
2681-
return -EINVAL;
2682-
} else {
2683-
return 0;
2684-
}
2679+
if ((valid_len != msglen) || (err_msg_format))
2680+
return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH;
2681+
2682+
return 0;
26852683
}
26862684

26872685
/**
@@ -2713,7 +2711,7 @@ int i40e_vc_process_vf_msg(struct i40e_pf *pf, s16 vf_id, u32 v_opcode,
27132711
return I40E_ERR_PARAM;
27142712

27152713
/* perform basic checks on the msg */
2716-
ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen);
2714+
ret = i40e_vc_validate_vf_msg(&vf->vf_ver, v_opcode, msg, msglen);
27172715

27182716
/* perform additional checks specific to this driver */
27192717
if (v_opcode == VIRTCHNL_OP_CONFIG_RSS_KEY) {
@@ -2729,9 +2727,15 @@ int i40e_vc_process_vf_msg(struct i40e_pf *pf, s16 vf_id, u32 v_opcode,
27292727
}
27302728

27312729
if (ret) {
2730+
i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
27322731
dev_err(&pf->pdev->dev, "Invalid message from VF %d, opcode %d, len %d\n",
27332732
local_vf_id, v_opcode, msglen);
2734-
return ret;
2733+
switch (ret) {
2734+
case VIRTCHNL_ERR_PARAM:
2735+
return -EPERM;
2736+
default:
2737+
return -EINVAL;
2738+
}
27352739
}
27362740

27372741
switch (v_opcode) {

include/linux/avf/virtchnl.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@
5353
* its queues, optionally add MAC and VLAN filters, and process traffic.
5454
*/
5555

56+
/* START GENERIC DEFINES
57+
* Need to ensure the following enums and defines hold the same meaning and
58+
* value in current and future projects
59+
*/
60+
61+
/* Error Codes */
62+
enum virtchnl_status_code {
63+
VIRTCHNL_STATUS_SUCCESS = 0,
64+
VIRTCHNL_ERR_PARAM = -5,
65+
VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH = -38,
66+
VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR = -39,
67+
VIRTCHNL_STATUS_ERR_INVALID_VF_ID = -40,
68+
VIRTCHNL_STATUS_NOT_SUPPORTED = -64,
69+
};
70+
71+
/* END GENERIC DEFINES */
72+
5673
/* Opcodes for VF-PF communication. These are placed in the v_opcode field
5774
* of the virtchnl_msg structure.
5875
*/

0 commit comments

Comments
 (0)