Commit a79da695 authored by David S. Miller's avatar David S. Miller

Merge branch 'hinic-mailbox-channel-enhancement'

Luo bin says:

====================
hinic: mailbox channel enhancement

add support to generate mailbox random id for VF to ensure that
the mailbox message from VF is valid and PF should check whether
the cmd from VF is supported before passing it to hw.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents da795540 c8c29ec3
......@@ -31,6 +31,10 @@
(((u64)(val) & HINIC_CMDQ_CTXT_##member##_MASK) \
<< HINIC_CMDQ_CTXT_##member##_SHIFT)
#define HINIC_CMDQ_CTXT_PAGE_INFO_GET(val, member) \
(((u64)(val) >> HINIC_CMDQ_CTXT_##member##_SHIFT) \
& HINIC_CMDQ_CTXT_##member##_MASK)
#define HINIC_CMDQ_CTXT_PAGE_INFO_CLEAR(val, member) \
((val) & (~((u64)HINIC_CMDQ_CTXT_##member##_MASK \
<< HINIC_CMDQ_CTXT_##member##_SHIFT)))
......@@ -45,6 +49,10 @@
(((u64)(val) & HINIC_CMDQ_CTXT_##member##_MASK) \
<< HINIC_CMDQ_CTXT_##member##_SHIFT)
#define HINIC_CMDQ_CTXT_BLOCK_INFO_GET(val, member) \
(((u64)(val) >> HINIC_CMDQ_CTXT_##member##_SHIFT) \
& HINIC_CMDQ_CTXT_##member##_MASK)
#define HINIC_CMDQ_CTXT_BLOCK_INFO_CLEAR(val, member) \
((val) & (~((u64)HINIC_CMDQ_CTXT_##member##_MASK \
<< HINIC_CMDQ_CTXT_##member##_SHIFT)))
......
......@@ -28,6 +28,8 @@
#define HINIC_MGMT_STATUS_EXIST 0x6
#define HINIC_MGMT_CMD_UNSUPPORTED 0xFF
#define HINIC_CMD_VER_FUNC_ID 2
struct hinic_cap {
u16 max_qps;
u16 num_qps;
......@@ -313,6 +315,17 @@ struct hinic_msix_config {
u8 rsvd1[3];
};
struct hinic_set_random_id {
u8 status;
u8 version;
u8 rsvd0[6];
u8 vf_in_pf;
u8 rsvd1;
u16 func_idx;
u32 random_id;
};
struct hinic_board_info {
u32 board_type;
u32 port_num;
......
......@@ -22,6 +22,14 @@
#define HINIC_FUNC_CSR_MAILBOX_RESULT_H_OFF 0x0108
#define HINIC_FUNC_CSR_MAILBOX_RESULT_L_OFF 0x010C
#define MAX_FUNCTION_NUM 512
struct vf_cmd_check_handle {
u8 cmd;
bool (*check_cmd)(struct hinic_hwdev *hwdev, u16 src_func_idx,
void *buf_in, u16 in_size);
};
enum hinic_mbox_ack_type {
MBOX_ACK,
MBOX_NO_ACK,
......@@ -100,6 +108,10 @@ struct hinic_mbox_func_to_func {
/* lock for mbox event flag */
spinlock_t mbox_lock;
u32 vf_mbx_old_rand_id[MAX_FUNCTION_NUM];
u32 vf_mbx_rand_id[MAX_FUNCTION_NUM];
bool support_vf_random;
};
struct hinic_mbox_work {
......@@ -116,6 +128,14 @@ struct vf_cmd_msg_handle {
void *buf_out, u16 *out_size);
};
bool hinic_mbox_check_func_id_8B(struct hinic_hwdev *hwdev, u16 func_idx,
void *buf_in, u16 in_size);
bool hinic_mbox_check_cmd_valid(struct hinic_hwdev *hwdev,
struct vf_cmd_check_handle *cmd_handle,
u16 vf_id, u8 cmd, void *buf_in,
u16 in_size, u8 size);
int hinic_register_pf_mbox_cb(struct hinic_hwdev *hwdev,
enum hinic_mod_type mod,
hinic_pf_mbox_cb callback);
......@@ -151,4 +171,6 @@ int hinic_mbox_to_vf(struct hinic_hwdev *hwdev,
enum hinic_mod_type mod, u16 vf_id, u8 cmd, void *buf_in,
u16 in_size, void *buf_out, u16 *out_size, u32 timeout);
int hinic_vf_mbox_random_id_init(struct hinic_hwdev *hwdev);
#endif
......@@ -93,6 +93,8 @@ enum hinic_comm_cmd {
HINIC_COMM_CMD_WATCHDOG_INFO = 0x56,
HINIC_MGMT_CMD_SET_VF_RANDOM_ID = 0x61,
HINIC_COMM_CMD_MAX,
};
......
......@@ -429,6 +429,18 @@ static int hinic_get_vf_link_status_msg_handler(void *hwdev, u16 vf_id,
return 0;
}
static bool check_func_table(struct hinic_hwdev *hwdev, u16 func_idx,
void *buf_in, u16 in_size)
{
struct hinic_cmd_fw_ctxt *function_table = buf_in;
if (!hinic_mbox_check_func_id_8B(hwdev, func_idx, buf_in, in_size) ||
!function_table->rx_buf_sz)
return false;
return true;
}
static struct vf_cmd_msg_handle nic_vf_cmd_msg_handler[] = {
{HINIC_PORT_CMD_VF_REGISTER, hinic_register_vf_msg_handler},
{HINIC_PORT_CMD_VF_UNREGISTER, hinic_unregister_vf_msg_handler},
......@@ -439,6 +451,45 @@ static struct vf_cmd_msg_handle nic_vf_cmd_msg_handler[] = {
{HINIC_PORT_CMD_GET_LINK_STATE, hinic_get_vf_link_status_msg_handler},
};
static struct vf_cmd_check_handle nic_cmd_support_vf[] = {
{HINIC_PORT_CMD_VF_REGISTER, NULL},
{HINIC_PORT_CMD_VF_UNREGISTER, NULL},
{HINIC_PORT_CMD_CHANGE_MTU, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_ADD_VLAN, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_DEL_VLAN, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_SET_MAC, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_GET_MAC, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_DEL_MAC, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_SET_RX_MODE, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_GET_PAUSE_INFO, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_GET_LINK_STATE, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_SET_LRO, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_SET_RX_CSUM, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_SET_RX_VLAN_OFFLOAD, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_GET_VPORT_STAT, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_CLEAN_VPORT_STAT, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_GET_RSS_TEMPLATE_INDIR_TBL,
hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_SET_RSS_TEMPLATE_TBL, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_GET_RSS_TEMPLATE_TBL, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_SET_RSS_HASH_ENGINE, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_GET_RSS_HASH_ENGINE, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_GET_RSS_CTX_TBL, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_SET_RSS_CTX_TBL, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_RSS_TEMP_MGR, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_RSS_CFG, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_FWCTXT_INIT, check_func_table},
{HINIC_PORT_CMD_GET_MGMT_VERSION, NULL},
{HINIC_PORT_CMD_SET_FUNC_STATE, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_GET_GLOBAL_QPN, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_SET_TSO, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_SET_RQ_IQ_MAP, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_LINK_STATUS_REPORT, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_UPDATE_MAC, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_GET_CAP, hinic_mbox_check_func_id_8B},
{HINIC_PORT_CMD_GET_LINK_MODE, hinic_mbox_check_func_id_8B},
};
#define CHECK_IPSU_15BIT 0X8000
static
......@@ -972,6 +1023,7 @@ int hinic_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
static int nic_pf_mbox_handler(void *hwdev, u16 vf_id, u8 cmd, void *buf_in,
u16 in_size, void *buf_out, u16 *out_size)
{
u8 size = ARRAY_SIZE(nic_cmd_support_vf);
struct vf_cmd_msg_handle *vf_msg_handle;
struct hinic_hwdev *dev = hwdev;
struct hinic_func_to_io *nic_io;
......@@ -980,7 +1032,15 @@ static int nic_pf_mbox_handler(void *hwdev, u16 vf_id, u8 cmd, void *buf_in,
u32 i;
if (!hwdev)
return -EFAULT;
return -EINVAL;
if (!hinic_mbox_check_cmd_valid(hwdev, nic_cmd_support_vf, vf_id, cmd,
buf_in, in_size, size)) {
dev_err(&dev->hwif->pdev->dev,
"PF Receive VF nic cmd: 0x%x, mbox len: 0x%x is invalid\n",
cmd, in_size);
return HINIC_MBOX_VF_CMD_ERROR;
}
pfhwdev = container_of(dev, struct hinic_pfhwdev, hwdev);
nic_io = &dev->func_to_io;
......@@ -1108,6 +1168,13 @@ int hinic_vf_func_init(struct hinic_hwdev *hwdev)
int err = 0;
u32 size, i;
err = hinic_vf_mbox_random_id_init(hwdev);
if (err) {
dev_err(&hwdev->hwif->pdev->dev, "Failed to init vf mbox random id, err: %d\n",
err);
return err;
}
nic_io = &hwdev->func_to_io;
if (HINIC_IS_VF(hwdev->hwif)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment