hinic: add SR-IOV support
Subsystems (3)
cover hinic: add SR-IOV support
patch #1 adds mailbox channel support and vf can communicate with pf or hw through it.
patch #2 adds support for enabling vf and tx/rx capabilities based on vf.
patch #3 adds support for vf's basic configurations.
Luo bin (3):
hinic: add mailbox function support
hinic: add sriov feature support
hinic: add net_device_ops associated with vf
drivers/net/ethernet/huawei/hinic/Makefile | 2 +- drivers/net/ethernet/huawei/hinic/hinic_dev.h | 3 + .../net/ethernet/huawei/hinic/hinic_hw_cmdq.c | 5 - .../net/ethernet/huawei/hinic/hinic_hw_csr.h | 2 +- .../net/ethernet/huawei/hinic/hinic_hw_dev.c | 141 +- .../net/ethernet/huawei/hinic/hinic_hw_dev.h | 48 + .../net/ethernet/huawei/hinic/hinic_hw_eqs.c | 98 +- .../net/ethernet/huawei/hinic/hinic_hw_eqs.h | 7 +- .../net/ethernet/huawei/hinic/hinic_hw_if.c | 46 +- .../net/ethernet/huawei/hinic/hinic_hw_if.h | 18 + .../net/ethernet/huawei/hinic/hinic_hw_io.c | 1 + .../net/ethernet/huawei/hinic/hinic_hw_io.h | 6 +- .../net/ethernet/huawei/hinic/hinic_hw_mbox.c | 1217 +++++++++++++++++ .../net/ethernet/huawei/hinic/hinic_hw_mbox.h | 154 +++ .../net/ethernet/huawei/hinic/hinic_hw_mgmt.c | 13 +- .../net/ethernet/huawei/hinic/hinic_hw_mgmt.h | 10 +- .../net/ethernet/huawei/hinic/hinic_main.c | 100 +- .../net/ethernet/huawei/hinic/hinic_port.c | 75 +- .../net/ethernet/huawei/hinic/hinic_port.h | 4 +- drivers/net/ethernet/huawei/hinic/hinic_rx.c | 15 +- .../net/ethernet/huawei/hinic/hinic_sriov.c | 1007 ++++++++++++++ .../net/ethernet/huawei/hinic/hinic_sriov.h | 102 ++ drivers/net/ethernet/huawei/hinic/hinic_tx.c | 17 +- 23 files changed, 2909 insertions(+), 182 deletions(-) create mode 100644 drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c create mode 100644 drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.h create mode 100644 drivers/net/ethernet/huawei/hinic/hinic_sriov.c create mode 100644 drivers/net/ethernet/huawei/hinic/hinic_sriov.h
Signature · 1 line
2.17.1
PATCH 1/3 hinic: add mailbox function support
virtual function and physical function can communicate with each other through mailbox channel supported by hw
--- drivers/net/ethernet/huawei/hinic/Makefile | 2 +- .../net/ethernet/huawei/hinic/hinic_hw_csr.h | 2 +- .../net/ethernet/huawei/hinic/hinic_hw_dev.c | 25 +- .../net/ethernet/huawei/hinic/hinic_hw_dev.h | 2 + .../net/ethernet/huawei/hinic/hinic_hw_eqs.h | 3 +- .../net/ethernet/huawei/hinic/hinic_hw_if.c | 46 +- .../net/ethernet/huawei/hinic/hinic_hw_if.h | 18 + .../net/ethernet/huawei/hinic/hinic_hw_mbox.c | 1217 +++++++++++++++++ .../net/ethernet/huawei/hinic/hinic_hw_mbox.h | 154 +++ .../net/ethernet/huawei/hinic/hinic_hw_mgmt.h | 1 + 10 files changed, 1460 insertions(+), 10 deletions(-) create mode 100644 drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c create mode 100644 drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.h
drivers/net/ethernet/huawei/hinic/Makefile +1 -1
@@ -4,4 +4,4 @@ obj-$(CONFIG_HINIC) += hinic.o hinic-y := hinic_main.o hinic_tx.o hinic_rx.o hinic_port.o hinic_hw_dev.o \ hinic_hw_io.o hinic_hw_qp.o hinic_hw_cmdq.o hinic_hw_wq.o \ hinic_hw_mgmt.o hinic_hw_api_cmd.o hinic_hw_eqs.o hinic_hw_if.o \ - hinic_common.o hinic_ethtool.o + hinic_common.o hinic_ethtool.o hinic_hw_mbox.o
drivers/net/ethernet/huawei/hinic/hinic_hw_csr.h +1 -1
@@ -10,7 +10,7 @@/* HW interface registers */ #define HINIC_CSR_FUNC_ATTR0_ADDR 0x0#define HINIC_CSR_FUNC_ATTR1_ADDR 0x4 - +#define HINIC_CSR_FUNC_ATTR2_ADDR 0x8#define HINIC_CSR_FUNC_ATTR4_ADDR 0x10#define HINIC_CSR_FUNC_ATTR5_ADDR 0x14
drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c +22 -3
@@ -676,10 +676,23 @@ static int init_pfhwdev(struct hinic_pfhwdev *pfhwdev)return err; } -hinic_register_mgmt_msg_cb (&pfhwdev->pf_to_mgmt,HINIC_MOD_L2NIC , - pfhwdev, nic_mgmt_msg_handler); + err =hinic_func_to_func_init (hwdev); +if (err) { +dev_err (&hwif->pdev->dev,"Failed to init mailbox\n" ); +hinic_pf_to_mgmt_free (&pfhwdev->pf_to_mgmt); +return err; + } + +if (!HINIC_IS_VF (hwif)) +hinic_register_mgmt_msg_cb (&pfhwdev->pf_to_mgmt, +HINIC_MOD_L2NIC , pfhwdev, + nic_mgmt_msg_handler); +else +hinic_register_vf_mbox_cb (hwdev,HINIC_MOD_L2NIC , + nic_mgmt_msg_handler);hinic_set_pf_action (hwif,HINIC_PF_MGMT_ACTIVE ); +return 0 ; }
@@ -693,7 +706,13 @@ static void free_pfhwdev(struct hinic_pfhwdev *pfhwdev)hinic_set_pf_action (hwdev->hwif,HINIC_PF_MGMT_INIT ); -hinic_unregister_mgmt_msg_cb (&pfhwdev->pf_to_mgmt,HINIC_MOD_L2NIC ); +if (!HINIC_IS_VF (hwdev->hwif)) +hinic_unregister_mgmt_msg_cb (&pfhwdev->pf_to_mgmt, +HINIC_MOD_L2NIC ); +else +hinic_unregister_vf_mbox_cb (hwdev,HINIC_MOD_L2NIC ); + +hinic_func_to_func_free (hwdev);hinic_pf_to_mgmt_free (&pfhwdev->pf_to_mgmt); }
drivers/net/ethernet/huawei/hinic/hinic_hw_dev.h +2 -0
@@ -16,6 +16,7 @@#include "hinic_hw_mgmt.h" #include "hinic_hw_qp.h" #include "hinic_hw_io.h" +#include "hinic_hw_mbox.h" #define HINIC_MAX_QPS 32
@@ -225,6 +226,7 @@ struct hinic_hwdev {struct hinic_aeqs aeqs;struct hinic_func_to_io func_to_io; +struct hinic_mbox_func_to_func *func_to_func;struct hinic_cap nic_cap; };
drivers/net/ethernet/huawei/hinic/hinic_hw_eqs.h +2 -1
@@ -143,8 +143,9 @@ enum hinic_eq_type { };enum hinic_aeq_type { +HINIC_MBX_FROM_FUNC =1 ,HINIC_MSG_FROM_MGMT_CPU =2 , - +HINIC_MBX_SEND_RSLT =5 ,HINIC_MAX_AEQ_EVENTS , };
drivers/net/ethernet/huawei/hinic/hinic_hw_if.c +42 -4
83 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic/hinic_hw_if.h +18 -0
@@ -35,6 +35,7 @@#define HINIC_FA0_FUNC_IDX_SHIFT 0#define HINIC_FA0_PF_IDX_SHIFT 10#define HINIC_FA0_PCI_INTF_IDX_SHIFT 14 +#define HINIC_FA0_VF_IN_PF_SHIFT 16/* reserved members - off 16 */ #define HINIC_FA0_FUNC_TYPE_SHIFT 24
@@ -42,6 +43,7 @@#define HINIC_FA0_PF_IDX_MASK 0xF#define HINIC_FA0_PCI_INTF_IDX_MASK 0x3#define HINIC_FA0_FUNC_TYPE_MASK 0x1 +#define HINIC_FA0_VF_IN_PF_MASK 0xFF#define HINIC_FA0_GET (val, member) \ (((val) >> HINIC_FA0_##member##_SHIFT) & HINIC_FA0_##member##_MASK)
@@ -64,6 +66,12 @@#define HINIC_FA1_GET (val, member) \ (((val) >> HINIC_FA1_##member##_SHIFT) & HINIC_FA1_##member##_MASK) +#define HINIC_FA2_GLOBAL_VF_ID_OF_PF_SHIFT 16 +#define HINIC_FA2_GLOBAL_VF_ID_OF_PF_MASK 0x3FF + +#define HINIC_FA2_GET (val, member) \ + (((val) >> HINIC_FA2_##member##_SHIFT) & HINIC_FA2_##member##_MASK) +#define HINIC_FA4_OUTBOUND_STATE_SHIFT 0#define HINIC_FA4_DB_STATE_SHIFT 1
@@ -140,6 +148,7 @@#define HINIC_HWIF_PPF_IDX (hwif) ((hwif)->attr.ppf_idx)#define HINIC_FUNC_TYPE (hwif) ((hwif)->attr.func_type) +#define HINIC_IS_VF (hwif) (HINIC_FUNC_TYPE(hwif) == HINIC_VF)#define HINIC_IS_PF (hwif) (HINIC_FUNC_TYPE(hwif) == HINIC_PF)#define HINIC_IS_PPF (hwif) (HINIC_FUNC_TYPE(hwif) == HINIC_PPF)
@@ -173,6 +182,7 @@ enum hinic_pcie_tph {enum hinic_func_type {HINIC_PF =0 , +HINIC_VF =1 ,HINIC_PPF =2 , };
@@ -223,6 +233,8 @@ struct hinic_func_attr {u8 num_ceqs;u8 num_dma_attr; + +u16 global_vf_id_of_pf; };struct hinic_hwif {
@@ -271,6 +283,12 @@ enum hinic_db_state hinic_db_state_get(struct hinic_hwif *hwif);void hinic_db_state_set (struct hinic_hwif *hwif,enum hinic_db_state db_state); +u16 hinic_glb_pf_vf_offset (struct hinic_hwif *hwif); + +u16 hinic_global_func_id_hw (struct hinic_hwif *hwif); + +u16 hinic_pf_id_of_vf_hw (struct hinic_hwif *hwif); +int hinic_init_hwif (struct hinic_hwif *hwif,struct pci_dev *pdev);void hinic_free_hwif (struct hinic_hwif *hwif);
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c new file +1217 -0
1,217 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.h new file +154 -0
154 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.h +1 -0
@@ -60,6 +60,7 @@ enum hinic_cfg_cmd { };enum hinic_comm_cmd { +HINIC_COMM_CMD_START_FLR =0x1 ,HINIC_COMM_CMD_IO_STATUS_GET =0x3 ,HINIC_COMM_CMD_CMDQ_CTXT_SET =0x10 ,
Signature · 1 line
2.17.1
Jakub Kicinski
maintainerRe: [PATCH net-next 1/3] hinic: add mailbox function support
Quoted 5 lines · On Tue, 21 Apr 2020 04:56:33 +0000 Luo bin wrote:
virtual function and physical function can communicate with each other through mailbox channel supported by hw
Signed-off-by Luo bin <[email protected]>
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c line 285
Quoted 10 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c new file +10
-0+static int recv_vf_mbox_handler (struct hinic_mbox_func_to_func *func_to_func, +struct hinic_recv_mbox *recv_mbox, +void *buf_out,u16 *out_size) +{ +hinic_vf_mbox_cb cb; +int ret =0 ; + +if (recv_mbox->mod >=HINIC_MOD_MAX ) { +dev_err (&func_to_func->hwif->pdev->dev,"Receive illegal mbox message, mod = %d\n" , + recv_mbox->mod);
You may want to rate limit these, otherwise VF may spam PFs logs.
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c line 922
Quoted 8 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c new file +7
-0+return -EINVAL ; + } +static int mbox_func_params_valid (struct hinic_mbox_func_to_func *func_to_func, +void *buf_in,u16 in_size) +{ +if (!buf_in || !in_size) +return -EINVAL ;
This is defensive programming, we don't do that in the kernel, callers should not pass NULL buffer and 0 size.
Also you probably want the size to be size_t, otherwise it may get truncated before the check below.
Quoted 20 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c new file +20
-0+if (in_size >HINIC_MBOX_DATA_SIZE ) { +dev_err (&func_to_func->hwif->pdev->dev, +"Mbox msg len(%d) exceed limit(%d)\n" , + in_size,HINIC_MBOX_DATA_SIZE ); +return -EINVAL ; + } + +return 0 ; +} + +int hinic_mbox_to_pf (struct hinic_hwdev *hwdev, +enum hinic_mod_type mod,u8 cmd,void *buf_in, +u16 in_size,void *buf_out,u16 *out_size,u32 timeout) +{ +struct hinic_mbox_func_to_func *func_to_func = hwdev->func_to_func; +int err =mbox_func_params_valid (func_to_func, buf_in, in_size); + +if (err) +return err; +
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c line 953
Quoted 10 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c new file +10
-0+if (!HINIC_IS_VF (hwdev->hwif)) { +dev_err (&hwdev->hwif->pdev->dev,"Params error, func_type: %d\n" , +HINIC_FUNC_TYPE (hwdev->hwif)); +return -EINVAL ; + } + + err =hinic_mbox_to_func (func_to_func, mod, cmd, +hinic_pf_id_of_vf_hw (hwdev->hwif), buf_in, + in_size, buf_out, out_size, timeout); +return err;
return hinic_mbox_to...
directly
Quoted 8 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c new file +7
-0+} +static int comm_pf_mbox_handler (void *handle,u16 vf_id,u8 cmd,void *buf_in, +u16 in_size,void *buf_out,u16 *out_size) +{ +struct hinic_hwdev *hwdev = handle; +struct hinic_pfhwdev *pfhwdev; +int err =0 ;
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c line 1120
Quoted 10 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c new file +10
-0+ + pfhwdev = container_of(hwdev, struct hinic_pfhwdev, hwdev); + +if (cmd ==HINIC_COMM_CMD_START_FLR ) { + *out_size =0 ; + }else { + err =hinic_msg_to_mgmt (&pfhwdev->pf_to_mgmt,HINIC_MOD_COMM , + cmd, buf_in, in_size, buf_out, out_size, +HINIC_MGMT_MSG_SYNC ); +if (err && err !=HINIC_MBOX_PF_BUSY_ACTIVE_FW )
Double space, please run checkpatch --strict on the patches
Quoted 7 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c new file +7
-0+dev_err (&hwdev->hwif->pdev->dev, +"PF mbox common callback handler err: %d\n" , + err); + } + +return err; +}
Re: [PATCH net-next 1/3] hinic: add mailbox function support
Thank you for your review. Will fix.
Quoted 91 lines · Jakub Kicinski
Quoted 4 lines · On Tue, 21 Apr 2020 04:56:33 +0000 Luo bin wrote:
virtual function and physical function can communicate with each other through mailbox channel supported by hw
Signed-off-by Luo bin <[email protected]>drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c line 285
Quoted 10 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c new file +10
-0+static int recv_vf_mbox_handler (struct hinic_mbox_func_to_func *func_to_func, +struct hinic_recv_mbox *recv_mbox, +void *buf_out,u16 *out_size) +{ +hinic_vf_mbox_cb cb; +int ret =0 ; + +if (recv_mbox->mod >=HINIC_MOD_MAX ) { +dev_err (&func_to_func->hwif->pdev->dev,"Receive illegal mbox message, mod = %d\n" , + recv_mbox->mod);You may want to rate limit these, otherwise VF may spam PFs logs.
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c line 922
Quoted 7 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c new file +7
-0+return -EINVAL ; + } +static int mbox_func_params_valid (struct hinic_mbox_func_to_func *func_to_func, +void *buf_in,u16 in_size) +{ +if (!buf_in || !in_size) +return -EINVAL ;This is defensive programming, we don't do that in the kernel, callers should not pass NULL buffer and 0 size.
Also you probably want the size to be
size_t, otherwise it may get truncated before the check below.Quoted 20 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c new file +20
-0+if (in_size >HINIC_MBOX_DATA_SIZE ) { +dev_err (&func_to_func->hwif->pdev->dev, +"Mbox msg len(%d) exceed limit(%d)\n" , + in_size,HINIC_MBOX_DATA_SIZE ); +return -EINVAL ; + } + +return 0 ; +} + +int hinic_mbox_to_pf (struct hinic_hwdev *hwdev, +enum hinic_mod_type mod,u8 cmd,void *buf_in, +u16 in_size,void *buf_out,u16 *out_size,u32 timeout) +{ +struct hinic_mbox_func_to_func *func_to_func = hwdev->func_to_func; +int err =mbox_func_params_valid (func_to_func, buf_in, in_size); + +if (err) +return err; +drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c line 953
Quoted 10 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c new file +10
-0+if (!HINIC_IS_VF (hwdev->hwif)) { +dev_err (&hwdev->hwif->pdev->dev,"Params error, func_type: %d\n" , +HINIC_FUNC_TYPE (hwdev->hwif)); +return -EINVAL ; + } + + err =hinic_mbox_to_func (func_to_func, mod, cmd, +hinic_pf_id_of_vf_hw (hwdev->hwif), buf_in, + in_size, buf_out, out_size, timeout); +return err;return
hinic_mbox_to...directly
Quoted 7 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c new file +7
-0+} +static int comm_pf_mbox_handler (void *handle,u16 vf_id,u8 cmd,void *buf_in, +u16 in_size,void *buf_out,u16 *out_size) +{ +struct hinic_hwdev *hwdev = handle; +struct hinic_pfhwdev *pfhwdev; +int err =0 ;drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c line 1120
Quoted 10 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c new file +10
-0+ + pfhwdev = container_of(hwdev, struct hinic_pfhwdev, hwdev); + +if (cmd ==HINIC_COMM_CMD_START_FLR ) { + *out_size =0 ; + }else { + err =hinic_msg_to_mgmt (&pfhwdev->pf_to_mgmt,HINIC_MOD_COMM , + cmd, buf_in, in_size, buf_out, out_size, +HINIC_MGMT_MSG_SYNC ); +if (err && err !=HINIC_MBOX_PF_BUSY_ACTIVE_FW )Double space, please run checkpatch --strict on the patches
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c line 1127
Quoted 7 lines
drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c new file +7
-0+dev_err (&hwdev->hwif->pdev->dev, +"PF mbox common callback handler err: %d\n" , + err); + } + +return err; +}.
PATCH 2/3 hinic: add sriov feature support
In reply to Luo binadds support of basic sriov feature including initialization and tx/rx capabilities of virtual function
--- drivers/net/ethernet/huawei/hinic/Makefile | 2 +- drivers/net/ethernet/huawei/hinic/hinic_dev.h | 3 + .../net/ethernet/huawei/hinic/hinic_hw_cmdq.c | 5 - .../net/ethernet/huawei/hinic/hinic_hw_dev.c | 116 +-- .../net/ethernet/huawei/hinic/hinic_hw_dev.h | 46 ++ .../net/ethernet/huawei/hinic/hinic_hw_eqs.c | 98 ++- .../net/ethernet/huawei/hinic/hinic_hw_eqs.h | 4 +- .../net/ethernet/huawei/hinic/hinic_hw_io.c | 1 + .../net/ethernet/huawei/hinic/hinic_hw_io.h | 6 +- .../net/ethernet/huawei/hinic/hinic_hw_mgmt.c | 13 +- .../net/ethernet/huawei/hinic/hinic_hw_mgmt.h | 9 +- .../net/ethernet/huawei/hinic/hinic_main.c | 72 +- .../net/ethernet/huawei/hinic/hinic_port.c | 75 +- .../net/ethernet/huawei/hinic/hinic_port.h | 4 +- drivers/net/ethernet/huawei/hinic/hinic_rx.c | 15 +- .../net/ethernet/huawei/hinic/hinic_sriov.c | 689 ++++++++++++++++++ .../net/ethernet/huawei/hinic/hinic_sriov.h | 79 ++ drivers/net/ethernet/huawei/hinic/hinic_tx.c | 17 +- 18 files changed, 1082 insertions(+), 172 deletions(-) create mode 100644 drivers/net/ethernet/huawei/hinic/hinic_sriov.c create mode 100644 drivers/net/ethernet/huawei/hinic/hinic_sriov.h
drivers/net/ethernet/huawei/hinic/Makefile +1 -1
@@ -4,4 +4,4 @@ obj-$(CONFIG_HINIC) += hinic.o hinic-y := hinic_main.o hinic_tx.o hinic_rx.o hinic_port.o hinic_hw_dev.o \ hinic_hw_io.o hinic_hw_qp.o hinic_hw_cmdq.o hinic_hw_wq.o \ hinic_hw_mgmt.o hinic_hw_api_cmd.o hinic_hw_eqs.o hinic_hw_if.o \ - hinic_common.o hinic_ethtool.o hinic_hw_mbox.o + hinic_common.o hinic_ethtool.o hinic_hw_mbox.o hinic_sriov.o
drivers/net/ethernet/huawei/hinic/hinic_dev.h +3 -0
@@ -16,6 +16,7 @@#include "hinic_hw_dev.h" #include "hinic_tx.h" #include "hinic_rx.h" +#include "hinic_sriov.h" #define HINIC_DRV_NAME "hinic"
@@ -23,6 +24,7 @@ enum hinic_flags {HINIC_LINK_UP =BIT (0 ),HINIC_INTF_UP =BIT (1 ),HINIC_RSS_ENABLE =BIT (2 ), + HINIC_LINK_DOWN = BIT(3), }; struct hinic_rx_mode_work {
@@ -78,6 +80,7 @@ struct hinic_dev {struct hinic_rss_type rss_type;u8 *rss_hkey_user;s32 *rss_indir_user; + struct hinic_sriov_info sriov_info; };#endif
drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c +0 -5
@@ -795,11 +795,6 @@ static int init_cmdqs_ctxt(struct hinic_hwdev *hwdev,size_t cmdq_ctxts_size;int err; -if (!HINIC_IS_PF (hwif) && !HINIC_IS_PPF (hwif)) { -dev_err (&pdev->dev,"Unsupported PCI function type\n" ); -return -EINVAL ; - } - cmdq_ctxts_size =HINIC_MAX_CMDQ_TYPES *sizeof (*cmdq_ctxts); cmdq_ctxts =devm_kzalloc (&pdev->dev, cmdq_ctxts_size,GFP_KERNEL );if (!cmdq_ctxts)
drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c +30 -86
282 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic/hinic_hw_dev.h +46 -0
80 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic/hinic_hw_eqs.c +82 -16
165 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic/hinic_hw_eqs.h +2 -2
@@ -172,7 +172,7 @@ struct hinic_eq_work {struct hinic_eq {struct hinic_hwif *hwif; - +struct hinic_hwdev *hwdev;enum hinic_eq_type type;int q_id;u32 q_len;
@@ -220,7 +220,7 @@ struct hinic_ceq_cb {struct hinic_ceqs {struct hinic_hwif *hwif; - +struct hinic_hwdev *hwdev;struct hinic_eq ceq[HINIC_MAX_CEQS ];int num_ceqs;
drivers/net/ethernet/huawei/hinic/hinic_hw_io.c +1 -0
@@ -506,6 +506,7 @@ int hinic_io_init(struct hinic_func_to_io *func_to_io, func_to_io->hwif = hwif; func_to_io->qps =NULL ; func_to_io->max_qps = max_qps; + func_to_io->ceqs.hwdev = func_to_io->hwdev; err = hinic_ceqs_init(&func_to_io->ceqs, hwif, num_ceqs, HINIC_DEFAULT_CEQ_LEN, HINIC_EQ_PAGE_SIZE,
drivers/net/ethernet/huawei/hinic/hinic_hw_io.h +5 -1
@@ -47,7 +47,7 @@ struct hinic_free_db_area {struct hinic_func_to_io {struct hinic_hwif *hwif; - +struct hinic_hwdev *hwdev;struct hinic_ceqs ceqs;struct hinic_wqs wqs;
@@ -69,6 +69,10 @@ struct hinic_func_to_io {void __iomem *cmdq_db_area[HINIC_MAX_CMDQ_TYPES ];struct hinic_cmdqs cmdqs; + +u16 max_vfs; +struct vf_data_storage *vf_infos; +u8 link_status; }; int hinic_io_create_qps(struct hinic_func_to_io *func_to_io,
drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.c +12 -1
@@ -353,7 +353,11 @@ int hinic_msg_to_mgmt(struct hinic_pf_to_mgmt *pf_to_mgmt,return -EINVAL ; } -return msg_to_mgmt_sync (pf_to_mgmt, mod, cmd, buf_in, in_size, +if (HINIC_IS_VF (hwif)) +return hinic_mbox_to_pf (pf_to_mgmt->hwdev, mod, cmd, buf_in, + in_size, buf_out, out_size,0 ); +else +return msg_to_mgmt_sync (pf_to_mgmt, mod, cmd, buf_in, in_size, buf_out, out_size,MGMT_DIRECT_SEND ,MSG_NOT_RESP ); }
@@ -553,6 +557,10 @@ int hinic_pf_to_mgmt_init(struct hinic_pf_to_mgmt *pf_to_mgmt,int err; pf_to_mgmt->hwif = hwif; + pf_to_mgmt->hwdev = hwdev; + +if (HINIC_IS_VF (hwif)) +return 0 ;sema_init (&pf_to_mgmt->sync_msg_lock,1 ); pf_to_mgmt->sync_msg_id =0 ;
@@ -584,6 +592,9 @@ void hinic_pf_to_mgmt_free(struct hinic_pf_to_mgmt *pf_to_mgmt)struct hinic_pfhwdev *pfhwdev =mgmt_to_pfhwdev (pf_to_mgmt);struct hinic_hwdev *hwdev = &pfhwdev->hwdev; +if (HINIC_IS_VF (hwdev->hwif)) +return ; +hinic_aeq_unregister_hw_cb (&hwdev->aeqs,HINIC_MSG_FROM_MGMT_CPU );hinic_api_cmd_free (pf_to_mgmt->cmd_chain); }
drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.h +7 -2
@@ -62,6 +62,7 @@ enum hinic_cfg_cmd {enum hinic_comm_cmd {HINIC_COMM_CMD_START_FLR =0x1 ,HINIC_COMM_CMD_IO_STATUS_GET =0x3 , +HINIC_COMM_CMD_DMA_ATTR_SET =0x4 ,HINIC_COMM_CMD_CMDQ_CTXT_SET =0x10 ,HINIC_COMM_CMD_CMDQ_CTXT_GET =0x11 ,
@@ -75,7 +76,11 @@ enum hinic_comm_cmd {HINIC_COMM_CMD_IO_RES_CLEAR =0x29 , - HINIC_COMM_CMD_MAX = 0x32, +HINIC_COMM_CMD_CEQ_CTRL_REG_WR_BY_UP =0x33 , + +HINIC_COMM_CMD_L2NIC_RESET =0x4b , + + HINIC_COMM_CMD_MAX = 0x4c, }; enum hinic_mgmt_cb_state {
@@ -108,7 +113,7 @@ struct hinic_mgmt_cb {struct hinic_pf_to_mgmt {struct hinic_hwif *hwif; - +struct hinic_hwdev *hwdev;struct semaphore sync_msg_lock;u16 sync_msg_id;u8 *sync_msg_buf;
drivers/net/ethernet/huawei/hinic/hinic_main.c +66 -6
177 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic/hinic_port.c +38 -37
246 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic/hinic_port.h +2 -2
@@ -148,9 +148,9 @@ struct hinic_port_link_status {u8 version;u8 rsvd0[6 ]; -u16 rsvd1; +u16 func_id;u8 link; -u8 rsvd2; +u8 port_id; };struct hinic_port_func_state_cmd {
drivers/net/ethernet/huawei/hinic/hinic_rx.c +9 -6
@@ -432,9 +432,11 @@ static int rx_poll(struct napi_struct *napi, int budget)return budget;napi_complete (napi); -hinic_hwdev_set_msix_state (nic_dev->hwdev, - rq->msix_entry, -HINIC_MSIX_ENABLE ); + +if (!HINIC_IS_VF (nic_dev->hwdev->hwif)) +hinic_hwdev_set_msix_state (nic_dev->hwdev, + rq->msix_entry, +HINIC_MSIX_ENABLE );return pkts; }
@@ -461,9 +463,10 @@ static irqreturn_t rx_irq(int irq, void *data)/* Disable the interrupt until napi will be completed */ nic_dev =netdev_priv (rxq->netdev); -hinic_hwdev_set_msix_state (nic_dev->hwdev, - rq->msix_entry, -HINIC_MSIX_DISABLE ); +if (!HINIC_IS_VF (nic_dev->hwdev->hwif)) +hinic_hwdev_set_msix_state (nic_dev->hwdev, + rq->msix_entry, +HINIC_MSIX_DISABLE ); nic_dev =netdev_priv (rxq->netdev);hinic_hwdev_msix_cnt_set (nic_dev->hwdev, rq->msix_entry);
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +689 -0
689 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic/hinic_sriov.h new file +79 -0
79 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic/hinic_tx.c +10 -7
@@ -673,9 +673,11 @@ static int free_tx_poll(struct napi_struct *napi, int budget)if (pkts < budget) {napi_complete (napi); -hinic_hwdev_set_msix_state (nic_dev->hwdev, - sq->msix_entry, -HINIC_MSIX_ENABLE ); +if (!HINIC_IS_VF (nic_dev->hwdev->hwif)) +hinic_hwdev_set_msix_state (nic_dev->hwdev, + sq->msix_entry, +HINIC_MSIX_ENABLE ); +return pkts; }
@@ -701,10 +703,11 @@ static irqreturn_t tx_irq(int irq, void *data) nic_dev =netdev_priv (txq->netdev); -/* Disable the interrupt until napi will be completed */ -hinic_hwdev_set_msix_state (nic_dev->hwdev, - txq->sq->msix_entry, -HINIC_MSIX_DISABLE ); +if (!HINIC_IS_VF (nic_dev->hwdev->hwif)) +/* Disable the interrupt until napi will be completed */ +hinic_hwdev_set_msix_state (nic_dev->hwdev, + txq->sq->msix_entry, +HINIC_MSIX_DISABLE );hinic_hwdev_msix_cnt_set (nic_dev->hwdev, txq->sq->msix_entry);
Signature · 1 line
2.17.1
Jakub Kicinski
maintainerRe: [PATCH net-next 2/3] hinic: add sriov feature support
drivers/net/ethernet/huawei/hinic/hinic_sriov.c line 597
Quoted 9 lines · On Tue, 21 Apr 2020 04:56:34 +0000 Luo bin wrote:
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +9
-0+int hinic_pci_sriov_disable (struct pci_dev *pdev) +{ +struct hinic_sriov_info *sriov_info; +u16 tmp_vfs; + + sriov_info =hinic_get_sriov_info_by_pcidev (pdev); +/* if SR-IOV is already disabled then nothing will be done */ +if (!sriov_info->sriov_enabled) +return 0 ;
Can't happen see below.
drivers/net/ethernet/huawei/hinic/hinic_sriov.c line 603
Quoted 5 lines
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +5
-0+if (test_and_set_bit (HINIC_SRIOV_DISABLE , &sriov_info->state)) { +dev_err (&pdev->dev, +"SR-IOV disable in process, please wait" ); +return -EPERM ; + }
Hm. I don't understand why you need these bit locks.
Quoted 28 lines
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +28
-0+/* If our VFs are assigned we cannot shut down SR-IOV +* without causing issues, so just leave the hardware +* available but disabled +*/ +if (pci_vfs_assigned (sriov_info->pdev)) { +clear_bit (HINIC_SRIOV_DISABLE , &sriov_info->state); +dev_warn (&pdev->dev,"Unloading driver while VFs are assigned - VFs will not be deallocated\n" ); +return -EPERM ; + } + sriov_info->sriov_enabled = false; + +/* disable iov and allow time for transactions to clear */ +pci_disable_sriov (sriov_info->pdev); + + tmp_vfs = (u16 )sriov_info->num_vfs; + sriov_info->num_vfs =0 ; +hinic_deinit_vf_hw (sriov_info,OS_VF_ID_TO_HW (0 ), +OS_VF_ID_TO_HW (tmp_vfs -1 )); + +clear_bit (HINIC_SRIOV_DISABLE , &sriov_info->state); + +return 0 ; +} + +int hinic_pci_sriov_enable (struct pci_dev *pdev,int num_vfs) +{ +struct hinic_sriov_info *sriov_info; +int pre_existing_vfs =0 ;
drivers/net/ethernet/huawei/hinic/hinic_sriov.c line 642
Quoted 10 lines
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +10
-0+int err =0 ; + + sriov_info =hinic_get_sriov_info_by_pcidev (pdev); + +if (test_and_set_bit (HINIC_SRIOV_ENABLE , &sriov_info->state)) { +dev_err (&pdev->dev, +"SR-IOV enable in process, please wait, num_vfs %d\n" , + num_vfs); +return -EPERM ; + }
This should never happen, PCI core code will prevent SR-IOV from being enabled twice in a row, and concurrently. See sriov_numvfs_store().
drivers/net/ethernet/huawei/hinic/hinic_sriov.c line 649
Quoted 6 lines
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +6
-0+ pre_existing_vfs =pci_num_vf (sriov_info->pdev); + +if (num_vfs >pci_sriov_get_totalvfs (sriov_info->pdev)) { +clear_bit (HINIC_SRIOV_ENABLE , &sriov_info->state); +return -ERANGE ; + }
Again, can't happen.
drivers/net/ethernet/huawei/hinic/hinic_sriov.c line 655
Quoted 6 lines
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +6
-0+if (pre_existing_vfs && pre_existing_vfs != num_vfs) { + err =hinic_pci_sriov_disable (sriov_info->pdev); +if (err) { +clear_bit (HINIC_SRIOV_ENABLE , &sriov_info->state); +return err; + }
And this.
drivers/net/ethernet/huawei/hinic/hinic_sriov.c line 656
Quoted 1 line
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +1
-0+ }else if (pre_existing_vfs == num_vfs) {
Or this.
Quoted 17 lines
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +17
-0+clear_bit (HINIC_SRIOV_ENABLE , &sriov_info->state); +return num_vfs; + } + + err =pci_enable_sriov (sriov_info->pdev, num_vfs); +if (err) { +dev_err (&pdev->dev, +"Failed to enable SR-IOV, error %d\n" , err); +clear_bit (HINIC_SRIOV_ENABLE , &sriov_info->state); +return err; + } + + sriov_info->sriov_enabled = true; + sriov_info->num_vfs = num_vfs; +clear_bit (HINIC_SRIOV_ENABLE , &sriov_info->state); + +return num_vfs;
drivers/net/ethernet/huawei/hinic/hinic_sriov.c line 683
Quoted 10 lines
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +10
-0+} + +int hinic_pci_sriov_configure (struct pci_dev *dev,int num_vfs) +{ +struct hinic_sriov_info *sriov_info; + + sriov_info =hinic_get_sriov_info_by_pcidev (dev); + +if (test_bit (HINIC_FUNC_REMOVE , &sriov_info->state)) +return -EFAULT ;
I don't think EFAULT is not a correct error code here. Use EBUSY, or ENODEV?
Quoted 5 lines
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +5
-0+if (!num_vfs) +return hinic_pci_sriov_disable (dev); +else +return hinic_pci_sriov_enable (dev, num_vfs); +}
Re: [PATCH net-next 2/3] hinic: add sriov feature support
These bit locks are mainly used for extendibility, and other opinions are accepted.Thanks for your review.
Quoted 115 lines · Jakub Kicinski
drivers/net/ethernet/huawei/hinic/hinic_sriov.c line 597
Quoted 9 lines · On Tue, 21 Apr 2020 04:56:34 +0000 Luo bin wrote:
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +9
-0+int hinic_pci_sriov_disable (struct pci_dev *pdev) +{ +struct hinic_sriov_info *sriov_info; +u16 tmp_vfs; + + sriov_info =hinic_get_sriov_info_by_pcidev (pdev); +/* if SR-IOV is already disabled then nothing will be done */ +if (!sriov_info->sriov_enabled) +return 0 ;Can't happen see below.
drivers/net/ethernet/huawei/hinic/hinic_sriov.c line 603
Quoted 5 lines
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +5
-0+if (test_and_set_bit (HINIC_SRIOV_DISABLE , &sriov_info->state)) { +dev_err (&pdev->dev, +"SR-IOV disable in process, please wait" ); +return -EPERM ; + }Hm. I don't understand why you need these bit locks.
Quoted 28 lines
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +28
-0+/* If our VFs are assigned we cannot shut down SR-IOV +* without causing issues, so just leave the hardware +* available but disabled +*/ +if (pci_vfs_assigned (sriov_info->pdev)) { +clear_bit (HINIC_SRIOV_DISABLE , &sriov_info->state); +dev_warn (&pdev->dev,"Unloading driver while VFs are assigned - VFs will not be deallocated\n" ); +return -EPERM ; + } + sriov_info->sriov_enabled = false; + +/* disable iov and allow time for transactions to clear */ +pci_disable_sriov (sriov_info->pdev); + + tmp_vfs = (u16 )sriov_info->num_vfs; + sriov_info->num_vfs =0 ; +hinic_deinit_vf_hw (sriov_info,OS_VF_ID_TO_HW (0 ), +OS_VF_ID_TO_HW (tmp_vfs -1 )); + +clear_bit (HINIC_SRIOV_DISABLE , &sriov_info->state); + +return 0 ; +} + +int hinic_pci_sriov_enable (struct pci_dev *pdev,int num_vfs) +{ +struct hinic_sriov_info *sriov_info; +int pre_existing_vfs =0 ;drivers/net/ethernet/huawei/hinic/hinic_sriov.c line 642
Quoted 10 lines
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +10
-0+int err =0 ; + + sriov_info =hinic_get_sriov_info_by_pcidev (pdev); + +if (test_and_set_bit (HINIC_SRIOV_ENABLE , &sriov_info->state)) { +dev_err (&pdev->dev, +"SR-IOV enable in process, please wait, num_vfs %d\n" , + num_vfs); +return -EPERM ; + }This should never happen, PCI core code will prevent SR-IOV from being enabled twice in a row, and concurrently. See
sriov_numvfs_store().drivers/net/ethernet/huawei/hinic/hinic_sriov.c line 649
Quoted 6 lines
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +6
-0+ pre_existing_vfs =pci_num_vf (sriov_info->pdev); + +if (num_vfs >pci_sriov_get_totalvfs (sriov_info->pdev)) { +clear_bit (HINIC_SRIOV_ENABLE , &sriov_info->state); +return -ERANGE ; + }Again, can't happen.
drivers/net/ethernet/huawei/hinic/hinic_sriov.c line 655
Quoted 6 lines
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +6
-0+if (pre_existing_vfs && pre_existing_vfs != num_vfs) { + err =hinic_pci_sriov_disable (sriov_info->pdev); +if (err) { +clear_bit (HINIC_SRIOV_ENABLE , &sriov_info->state); +return err; + }And this.
drivers/net/ethernet/huawei/hinic/hinic_sriov.c line 656
Quoted 1 line
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +1
-0+ }else if (pre_existing_vfs == num_vfs) {Or this.
Quoted 17 lines
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +17
-0+clear_bit (HINIC_SRIOV_ENABLE , &sriov_info->state); +return num_vfs; + } + + err =pci_enable_sriov (sriov_info->pdev, num_vfs); +if (err) { +dev_err (&pdev->dev, +"Failed to enable SR-IOV, error %d\n" , err); +clear_bit (HINIC_SRIOV_ENABLE , &sriov_info->state); +return err; + } + + sriov_info->sriov_enabled = true; + sriov_info->num_vfs = num_vfs; +clear_bit (HINIC_SRIOV_ENABLE , &sriov_info->state); + +return num_vfs;drivers/net/ethernet/huawei/hinic/hinic_sriov.c line 683
Quoted 10 lines
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +10
-0+} + +int hinic_pci_sriov_configure (struct pci_dev *dev,int num_vfs) +{ +struct hinic_sriov_info *sriov_info; + + sriov_info =hinic_get_sriov_info_by_pcidev (dev); + +if (test_bit (HINIC_FUNC_REMOVE , &sriov_info->state)) +return -EFAULT ;I don't think EFAULT is not a correct error code here. Use EBUSY, or ENODEV?
drivers/net/ethernet/huawei/hinic/hinic_sriov.c line 689
Quoted 5 lines
drivers/net/ethernet/huawei/hinic/hinic_sriov.c new file +5
-0+if (!num_vfs) +return hinic_pci_sriov_disable (dev); +else +return hinic_pci_sriov_enable (dev, num_vfs); +}.
PATCH 3/3 hinic: add net_device_ops associated with vf
In reply to Luo binadds ndo_set_vf_mac/ndo_set_vf_vlan/ndo_get_vf_config and ndo_set_vf_trust to configure netdev of virtual function
--- .../net/ethernet/huawei/hinic/hinic_main.c | 28 +- .../net/ethernet/huawei/hinic/hinic_sriov.c | 318 ++++++++++++++++++ .../net/ethernet/huawei/hinic/hinic_sriov.h | 23 ++ 3 files changed, 368 insertions(+), 1 deletion(-)
drivers/net/ethernet/huawei/hinic/hinic_main.c +27 -1
@@ -845,6 +845,29 @@ static const struct net_device_ops hinic_netdev_ops = { .ndo_get_stats64 = hinic_get_stats64, .ndo_fix_features = hinic_fix_features, .ndo_set_features = hinic_set_features, +#ifdef IFLA_VF_MAX + .ndo_set_vf_mac = hinic_ndo_set_vf_mac, + .ndo_set_vf_vlan = hinic_ndo_set_vf_vlan, + .ndo_get_vf_config = hinic_ndo_get_vf_config, + .ndo_set_vf_trust = hinic_ndo_set_vf_trust, +#endif + +}; + +static const struct net_device_ops hinicvf_netdev_ops = { + .ndo_open = hinic_open, + .ndo_stop = hinic_close, + .ndo_change_mtu = hinic_change_mtu, + .ndo_set_mac_address = hinic_set_mac_addr, + .ndo_validate_addr = eth_validate_addr, + .ndo_vlan_rx_add_vid = hinic_vlan_rx_add_vid, + .ndo_vlan_rx_kill_vid = hinic_vlan_rx_kill_vid, + .ndo_set_rx_mode = hinic_set_rx_mode, + .ndo_start_xmit = hinic_xmit_frame, + .ndo_tx_timeout = hinic_tx_timeout, + .ndo_get_stats64 = hinic_get_stats64, + .ndo_fix_features = hinic_fix_features, + .ndo_set_features = hinic_set_features, };static void netdev_features_init (struct net_device *netdev)
@@ -982,7 +1005,10 @@ static int nic_dev_init(struct pci_dev *pdev)hinic_set_ethtool_ops (netdev); - netdev->netdev_ops = &hinic_netdev_ops; +if (!HINIC_IS_VF (hwdev->hwif)) + netdev->netdev_ops = &hinic_netdev_ops; +else + netdev->netdev_ops = &hinicvf_netdev_ops; netdev->max_mtu =ETH_MAX_MTU ;
drivers/net/ethernet/huawei/hinic/hinic_sriov.c +318 -0
336 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic/hinic_sriov.h +23 -0
@@ -52,6 +52,19 @@ struct hinic_register_vf {u8 rsvd0[6 ]; }; +struct hinic_port_mac_update { +u8 status; +u8 version; +u8 rsvd0[6 ]; + +u16 func_id; +u16 vlan_id; +u16 rsvd1; +u8 old_mac[ETH_ALEN ]; +u16 rsvd2; +u8 new_mac[ETH_ALEN ]; +}; +struct hinic_vf_vlan_config {u8 status;u8 version;
@@ -63,6 +76,16 @@ struct hinic_vf_vlan_config {u8 rsvd1[7 ]; }; +int hinic_ndo_set_vf_mac (struct net_device *netdev,int vf,u8 *mac); + +int hinic_ndo_set_vf_vlan (struct net_device *netdev,int vf,u16 vlan,u8 qos, +__be16 vlan_proto); + +int hinic_ndo_get_vf_config (struct net_device *netdev, +int vf,struct ifla_vf_info *ivi); + +int hinic_ndo_set_vf_trust (struct net_device *netdev,int vf,bool setting); +void hinic_notify_all_vfs_link_changed (struct hinic_hwdev *hwdev,u8 link_status);
Signature · 1 line
2.17.1