Skip to contentSkip to conversation

hinic: mailbox channel enhancement

PATCH Superseded Luo bin 2 participants 5 messages Aug 1, 2020 – Aug 4, 2020

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Luo bin

author
#0 lore raw

v3 cover 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.

Luo bin (2):
hinic: add generating mailbox random index support
hinic: add check for mailbox msg from VF

 .../net/ethernet/huawei/hinic/hinic_hw_cmdq.h |   8 +
 .../net/ethernet/huawei/hinic/hinic_hw_dev.h  |  13 +
 .../net/ethernet/huawei/hinic/hinic_hw_mbox.c | 308 +++++++++++++++++-
 .../net/ethernet/huawei/hinic/hinic_hw_mbox.h |  22 ++
 .../net/ethernet/huawei/hinic/hinic_hw_mgmt.h |   2 +
 .../net/ethernet/huawei/hinic/hinic_sriov.c   |  69 +++-
 6 files changed, 420 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v3 1/2 hinic: add generating mailbox random index support

add support to generate mailbox random id of VF to ensure that mailbox messages PF received are from the correct VF.

---
V2~V3 fix review opinions pointed out by Jakub

 .../net/ethernet/huawei/hinic/hinic_hw_dev.h  |  13 ++
 .../net/ethernet/huawei/hinic/hinic_hw_mbox.c | 135 ++++++++++++++++++
 .../net/ethernet/huawei/hinic/hinic_hw_mbox.h |   8 ++
 .../net/ethernet/huawei/hinic/hinic_hw_mgmt.h |   2 +
 .../net/ethernet/huawei/hinic/hinic_sriov.c   |   7 +
 5 files changed, 165 insertions(+)
drivers/net/ethernet/huawei/hinic/hinic_hw_dev.h +13 -0
index 2fb5f784f116..dc6e645f2689 100644
@@ -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;
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c +135 -0

150 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.h +8 -0
index 7b18559bfe80..0618fe515d9c 100644
@@ -22,6 +22,8 @@
 #define HINIC_FUNC_CSR_MAILBOX_RESULT_H_OFF		0x0108
 #define HINIC_FUNC_CSR_MAILBOX_RESULT_L_OFF		0x010C
 
+#define MAX_FUNCTION_NUM		512
+
 enum hinic_mbox_ack_type {
 	MBOX_ACK,
 	MBOX_NO_ACK,
@@ -100,6 +102,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 {
@@ -151,4 +157,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
drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.h +2 -0
index f626100b85c1..4ca81cc838db 100644
@@ -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,
 };
 
drivers/net/ethernet/huawei/hinic/hinic_sriov.c +7 -0
index 141206917e4d..1d8a115cb9ec 100644
@@ -1108,6 +1108,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)) {
Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH net-next v3 1/2] hinic: add generating mailbox random index support

Quoted 6 lines · On Sat, 1 Aug 2020 10:49:34 +0800 Luo bin wrote:

add support to generate mailbox random id of VF to ensure that mailbox messages PF received are from the correct VF.

---
V2~V3 fix review opinions pointed out by Jakub

In the future please specify what was changed, e.g.:

- use get_random_u32()
- remove unnecessary parenthesis

etc.

drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c void hinic_func_to_func_free(struct hinic_hwdev *hwdev) · line 1332

Quoted 11 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c +11 -0
+int hinic_vf_mbox_random_id_init(struct hinic_hwdev *hwdev)
+{
+	u8 vf_in_pf;
+	int err = 0;
+
+	if (HINIC_IS_VF(hwdev->hwif))
+		return 0;
+
+	for (vf_in_pf = 1; vf_in_pf <= hwdev->nic_cap.max_vf; vf_in_pf++) {
+		err = set_vf_mbox_random_id(hwdev, hinic_glb_pf_vf_offset
+					    (hwdev->hwif) + vf_in_pf);

I'm sorry but you must put the call to hinic_glb_pf_vf_offset() on a separate line. Perhaps take this call out of the for loop entirely?

The way it's written with the parenthesis on the next line is hard to read.

Quoted 3 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c +3 -0
+		if (err)
+			break;
+	}
author
#3 lore raw

Re: [PATCH net-next v3 1/2] hinic: add generating mailbox random index support

Quoted 8 lines · Jakub Kicinski
Quoted 6 lines · On Sat, 1 Aug 2020 10:49:34 +0800 Luo bin wrote:

add support to generate mailbox random id of VF to ensure that mailbox messages PF received are from the correct VF.

---
V2~V3 fix review opinions pointed out by Jakub

Quoted 7 lines

In the future please specify what was changed, e.g.:

- use get_random_u32()
- remove unnecessary parenthesis

etc.

Okay, I'll pay attention to that next time.

Quoted 15 lines

drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c void hinic_func_to_func_free(struct hinic_hwdev *hwdev) · line 1332

Quoted 11 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c +11 -0
+int hinic_vf_mbox_random_id_init(struct hinic_hwdev *hwdev)
+{
+	u8 vf_in_pf;
+	int err = 0;
+
+	if (HINIC_IS_VF(hwdev->hwif))
+		return 0;
+
+	for (vf_in_pf = 1; vf_in_pf <= hwdev->nic_cap.max_vf; vf_in_pf++) {
+		err = set_vf_mbox_random_id(hwdev, hinic_glb_pf_vf_offset
+					    (hwdev->hwif) + vf_in_pf);

I'm sorry but you must put the call to hinic_glb_pf_vf_offset() on a separate line. Perhaps take this call out of the for loop entirely?

Quoted 2 lines

The way it's written with the parenthesis on the next line is hard to read.

Will fix. Thanks. Taking it out of the loop is a better way to avoid a long line length.

Quoted 6 lines

drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c void hinic_func_to_func_free(struct hinic_hwdev *hwdev) · line 1335

Quoted 4 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c +3 -0
+		if (err)
+			break;
+	}

.

author
#4 lore raw

PATCH v3 2/2 hinic: add check for mailbox msg from VF

In reply to Luo bin

PF should check whether the cmd from VF is supported and its content is right before passing it to hw.

---
V1~V2: fix W=1 C=1 warnings

 .../net/ethernet/huawei/hinic/hinic_hw_cmdq.h |   8 +
 .../net/ethernet/huawei/hinic/hinic_hw_mbox.c | 173 +++++++++++++++++-
 .../net/ethernet/huawei/hinic/hinic_hw_mbox.h |  14 ++
 .../net/ethernet/huawei/hinic/hinic_sriov.c   |  62 ++++++-
 4 files changed, 255 insertions(+), 2 deletions(-)
drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.h +8 -0
index f40c31e1879f..9c413e963a04 100644
@@ -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)))
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c +172 -1

200 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.h +14 -0
index 0618fe515d9c..46953190d29e 100644
@@ -24,6 +24,12 @@
 
 #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,
@@ -122,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);
drivers/net/ethernet/huawei/hinic/hinic_sriov.c +61 -1

86 lines not on this page · raw message

Signature · 1 line
2.17.1