hinic: add three net_device_ops of vf
Subsystems (3)
PATCH 1/1 hinic: add three net_device_ops of vf
adds ndo_set_vf_rate/ndo_set_vf_spoofchk/ndo_set_vf_link_state to configure netdev of virtual function
Signed-off-by Luo bin <[email protected]>
--- .../net/ethernet/huawei/hinic/hinic_hw_cmdq.c | 31 ++ .../net/ethernet/huawei/hinic/hinic_hw_dev.c | 35 ++- .../net/ethernet/huawei/hinic/hinic_hw_dev.h | 21 ++ .../net/ethernet/huawei/hinic/hinic_hw_if.c | 32 +- .../net/ethernet/huawei/hinic/hinic_hw_if.h | 6 +- .../net/ethernet/huawei/hinic/hinic_main.c | 17 +- .../net/ethernet/huawei/hinic/hinic_port.c | 8 +- .../net/ethernet/huawei/hinic/hinic_port.h | 43 +++ .../net/ethernet/huawei/hinic/hinic_sriov.c | 275 ++++++++++++++++++ .../net/ethernet/huawei/hinic/hinic_sriov.h | 7 + 10 files changed, 453 insertions(+), 22 deletions(-)
drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c +31 -0
@@ -849,6 +849,27 @@ static int init_cmdqs_ctxt(struct hinic_hwdev *hwdev,return err; } +static int hinic_set_cmdq_depth (struct hinic_hwdev *hwdev,u16 cmdq_depth) +{ +struct hinic_cmd_hw_ioctxt hw_ioctxt = {0 }; +struct hinic_pfhwdev *pfhwdev; + + pfhwdev = container_of(hwdev, struct hinic_pfhwdev, hwdev); + + hw_ioctxt.func_idx =HINIC_HWIF_FUNC_IDX (hwdev->hwif); + hw_ioctxt.ppf_idx =HINIC_HWIF_PPF_IDX (hwdev->hwif); + + hw_ioctxt.set_cmdq_depth =HW_IOCTXT_SET_CMDQ_DEPTH_ENABLE ; + hw_ioctxt.cmdq_depth = (u8 )ilog2 (cmdq_depth); + +return hinic_msg_to_mgmt (&pfhwdev->pf_to_mgmt,HINIC_MOD_COMM , +HINIC_COMM_CMD_HWCTXT_SET , + &hw_ioctxt,sizeof (hw_ioctxt),NULL , +NULL ,HINIC_MGMT_MSG_SYNC ); + +return 0 ; +} +/** * hinic_init_cmdqs - init all cmdqs * @cmdqs: cmdqs to init
@@ -899,8 +920,18 @@ int hinic_init_cmdqs(struct hinic_cmdqs *cmdqs, struct hinic_hwif *hwif,hinic_ceq_register_cb (&func_to_io->ceqs,HINIC_CEQ_CMDQ , cmdqs, cmdq_ceq_handler); + + err =hinic_set_cmdq_depth (hwdev,CMDQ_DEPTH ); +if (err) { +dev_err (&hwif->pdev->dev,"Failed to set cmdq depth\n" ); + goto err_set_cmdq_depth; + } +return 0 ; +err_set_cmdq_depth: +hinic_ceq_unregister_cb (&func_to_io->ceqs,HINIC_CEQ_CMDQ ); + err_cmdq_ctxt:hinic_wqs_cmdq_free (&cmdqs->cmdq_pages, cmdqs->saved_wqs,HINIC_MAX_CMDQ_TYPES );
drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c +31 -4
@@ -44,10 +44,6 @@ enum io_status { IO_RUNNING = 1, }; -enum hw_ioctxt_set_cmdq_depth { -HW_IOCTXT_SET_CMDQ_DEPTH_DEFAULT , -}; -/** * get_capability - convert device capabilities to NIC capabilities * @hwdev: the HW device to set and convert device capabilities for
@@ -667,6 +663,32 @@ static void free_pfhwdev(struct hinic_pfhwdev *pfhwdev)hinic_pf_to_mgmt_free (&pfhwdev->pf_to_mgmt); } +static int hinic_l2nic_reset (struct hinic_hwdev *hwdev) +{ +struct hinic_cmd_l2nic_reset l2nic_reset = {0 }; +u16 out_size =sizeof (l2nic_reset); +struct hinic_pfhwdev *pfhwdev; +int err; + + pfhwdev = container_of(hwdev, struct hinic_pfhwdev, hwdev); + + l2nic_reset.func_id =HINIC_HWIF_FUNC_IDX (hwdev->hwif); +/* 0 represents standard l2nic reset flow */ + l2nic_reset.reset_flag =0 ; + + err =hinic_msg_to_mgmt (&pfhwdev->pf_to_mgmt,HINIC_MOD_COMM , +HINIC_COMM_CMD_L2NIC_RESET , &l2nic_reset, +sizeof (l2nic_reset), &l2nic_reset, + &out_size,HINIC_MGMT_MSG_SYNC ); +if (err || !out_size || l2nic_reset.status) { +dev_err (&hwdev->hwif->pdev->dev,"Failed to reset L2NIC resources, err: %d, status: 0x%x, out_size: 0x%x\n" , + err, l2nic_reset.status, out_size); +return -EIO ; + } + +return 0 ; +} +/** * hinic_init_hwdev - Initialize the NIC HW * @pdev: the NIC pci device
@@ -729,6 +751,10 @@ struct hinic_hwdev *hinic_init_hwdev(struct pci_dev *pdev) goto err_init_pfhwdev; } + err =hinic_l2nic_reset (hwdev); +if (err) + goto err_l2nic_reset; + err =get_dev_cap (hwdev);if (err) {dev_err (&pdev->dev,"Failed to get device capabilities\n" );
@@ -759,6 +785,7 @@ struct hinic_hwdev *hinic_init_hwdev(struct pci_dev *pdev) err_init_fw_ctxt:hinic_vf_func_free (hwdev); err_vf_func_init: +err_l2nic_reset: err_dev_cap:free_pfhwdev (pfhwdev);
drivers/net/ethernet/huawei/hinic/hinic_hw_dev.h +21 -0
@@ -25,6 +25,7 @@#define HINIC_PF_SET_VF_ALREADY 0x4#define HINIC_MGMT_STATUS_EXIST 0x6 +#define HINIC_MGMT_CMD_UNSUPPORTED 0xFFstruct hinic_cap {u16 max_qps;
@@ -33,6 +34,11 @@ struct hinic_cap {u16 max_vf_qps; }; +enum hw_ioctxt_set_cmdq_depth { +HW_IOCTXT_SET_CMDQ_DEPTH_DEFAULT , +HW_IOCTXT_SET_CMDQ_DEPTH_ENABLE , +}; +enum hinic_port_cmd {HINIC_PORT_CMD_VF_REGISTER =0x0 ,HINIC_PORT_CMD_VF_UNREGISTER =0x1 ,
@@ -86,12 +92,16 @@ enum hinic_port_cmd {HINIC_PORT_CMD_FWCTXT_INIT =69 , +HINIC_PORT_CMD_ENABLE_SPOOFCHK =78 , +HINIC_PORT_CMD_GET_MGMT_VERSION =88 ,HINIC_PORT_CMD_SET_FUNC_STATE =93 ,HINIC_PORT_CMD_GET_GLOBAL_QPN =102 , +HINIC_PORT_CMD_SET_VF_RATE =105 , +HINIC_PORT_CMD_SET_VF_VLAN =106 , HINIC_PORT_CMD_CLR_VF_VLAN,
@@ -107,6 +117,8 @@ enum hinic_port_cmd {HINIC_PORT_CMD_GET_CAP =170 ,HINIC_PORT_CMD_SET_LRO_TIMER =244 , + + HINIC_PORT_CMD_SET_VF_MAX_MIN_RATE = 249, }; enum hinic_ucode_cmd {
@@ -247,6 +259,15 @@ struct hinic_cmd_hw_ci {u64 ci_addr; }; +struct hinic_cmd_l2nic_reset { +u8 status; +u8 version; +u8 rsvd0[6 ]; + +u16 func_id; +u16 reset_flag; +}; +struct hinic_hwdev {struct hinic_hwif *hwif;struct msix_entry *msix_entries;
drivers/net/ethernet/huawei/hinic/hinic_hw_if.c +27 -5
@@ -10,6 +10,7 @@#include <linux/io.h> #include <linux/types.h> #include <linux/bitops.h> +#include <linux/delay.h> #include "hinic_hw_csr.h" #include "hinic_hw_if.h"
@@ -18,6 +19,8 @@#define VALID_MSIX_IDX (attr, msix_index) ((msix_index) < (attr)->num_irqs) +#define WAIT_HWIF_READY_TIMEOUT 10000 +/** * hinic_msix_attr_set - set message attribute for msix entry * @hwif: the HW interface of a pci function device
@@ -187,20 +190,39 @@ void hinic_set_msix_state(struct hinic_hwif *hwif, u16 msix_idx,**/ static int hwif_ready (struct hinic_hwif *hwif) { -struct pci_dev *pdev = hwif->pdev;u32 addr, attr1; addr =HINIC_CSR_FUNC_ATTR1_ADDR ; attr1 =hinic_hwif_read_reg (hwif, addr); -if (!HINIC_FA1_GET (attr1,INIT_STATUS )) { -dev_err (&pdev->dev,"hwif status is not ready\n" ); -return -EFAULT ; +if (!HINIC_FA1_GET (attr1,MGMT_INIT_STATUS )) +return -EBUSY ; + +if (HINIC_IS_VF (hwif)) { +if (!HINIC_FA1_GET (attr1,PF_INIT_STATUS )) +return -EBUSY ; }return 0 ; } +static int wait_hwif_ready (struct hinic_hwif *hwif) +{ +ulong timeout =0 ; + +do { +if (!hwif_ready (hwif)) +return 0 ; + +usleep_range (999 ,1000 ); + timeout++; + }while (timeout <=WAIT_HWIF_READY_TIMEOUT ); + +dev_err (&hwif->pdev->dev,"Wait for hwif timeout\n" ); + +return -EBUSY ; +} +/** * set_hwif_attr - set the attributes in the relevant members in hwif * @hwif: the HW interface of a pci function device
@@ -373,7 +395,7 @@ int hinic_init_hwif(struct hinic_hwif *hwif, struct pci_dev *pdev) goto err_map_intr_bar; } - err =hwif_ready (hwif); + err =wait_hwif_ready (hwif);if (err) {dev_err (&pdev->dev,"HW interface is not ready\n" ); goto err_hwif_ready;
drivers/net/ethernet/huawei/hinic/hinic_hw_if.h +4 -2
@@ -55,13 +55,15 @@#define HINIC_FA1_IRQS_PER_FUNC_SHIFT 20#define HINIC_FA1_DMA_ATTR_PER_FUNC_SHIFT 24/* reserved members - off 27 */ -#define HINIC_FA1_INIT_STATUS_SHIFT 30 +#define HINIC_FA1_MGMT_INIT_STATUS_SHIFT 30 +#define HINIC_FA1_PF_INIT_STATUS_SHIFT 31#define HINIC_FA1_AEQS_PER_FUNC_MASK 0x3#define HINIC_FA1_CEQS_PER_FUNC_MASK 0x7#define HINIC_FA1_IRQS_PER_FUNC_MASK 0xF#define HINIC_FA1_DMA_ATTR_PER_FUNC_MASK 0x7 -#define HINIC_FA1_INIT_STATUS_MASK 0x1 +#define HINIC_FA1_MGMT_INIT_STATUS_MASK 0x1 +#define HINIC_FA1_PF_INIT_STATUS_MASK 0x1#define HINIC_FA1_GET (val, member) \ (((val) >> HINIC_FA1_##member##_SHIFT) & HINIC_FA1_##member##_MASK)
drivers/net/ethernet/huawei/hinic/hinic_main.c +10 -7
@@ -427,10 +427,6 @@ static int hinic_open(struct net_device *netdev) goto err_func_port_state; } -if (!HINIC_IS_VF (nic_dev->hwdev->hwif)) -/* Wait up to 3 sec between port enable to link state */ -msleep (3000 ); -down (&nic_dev->mgmt_lock); err =hinic_port_link_state (nic_dev, &link_state);
@@ -766,10 +762,12 @@ static void hinic_set_rx_mode(struct net_device *netdev)HINIC_RX_MODE_MC |HINIC_RX_MODE_BC ; -if (netdev->flags &IFF_PROMISC ) - rx_mode |=HINIC_RX_MODE_PROMISC ; -else if (netdev->flags &IFF_ALLMULTI ) +if (netdev->flags &IFF_PROMISC ) { +if (!HINIC_IS_VF (nic_dev->hwdev->hwif)) + rx_mode |=HINIC_RX_MODE_PROMISC ; + }else if (netdev->flags &IFF_ALLMULTI ) { rx_mode |=HINIC_RX_MODE_MC_ALL ; + } rx_mode_work->rx_mode = rx_mode;
@@ -868,6 +866,9 @@ static const struct net_device_ops hinic_netdev_ops = { .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, + .ndo_set_vf_rate = hinic_ndo_set_vf_bw, + .ndo_set_vf_spoofchk = hinic_ndo_set_vf_spoofchk, + .ndo_set_vf_link_state = hinic_ndo_set_vf_link_state, };static const struct net_device_ops hinicvf_netdev_ops = {
@@ -1232,6 +1233,8 @@ static void hinic_remove(struct pci_dev *pdev)unregister_netdev (netdev); +hinic_port_del_mac (nic_dev, netdev->dev_addr,0 ); +hinic_hwdev_cb_unregister (nic_dev->hwdev,HINIC_MGMT_MSG_CMD_LINK_STATUS );
drivers/net/ethernet/huawei/hinic/hinic_port.c +4 -4
@@ -66,15 +66,15 @@ static int change_mac(struct hinic_dev *nic_dev, const u8 *addr,return -EFAULT ; } -if (cmd ==HINIC_PORT_CMD_SET_MAC && port_mac_cmd.status == -HINIC_PF_SET_VF_ALREADY ) { -dev_warn (&pdev->dev,"PF has already set VF mac, Ignore set operation\n" ); +if (port_mac_cmd.status ==HINIC_PF_SET_VF_ALREADY ) { +dev_warn (&pdev->dev,"PF has already set VF mac, ignore %s operation\n" , + (op ==MAC_SET ) ?"set" :"del" );return HINIC_PF_SET_VF_ALREADY ; }if (cmd ==HINIC_PORT_CMD_SET_MAC && port_mac_cmd.status ==HINIC_MGMT_STATUS_EXIST ) -dev_warn (&pdev->dev,"MAC is repeated. Ignore set operation\n" ); +dev_warn (&pdev->dev,"MAC is repeated, ignore set operation\n" );return 0 ; }
drivers/net/ethernet/huawei/hinic/hinic_port.h +43 -0
49 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic/hinic_sriov.c +275 -0
305 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic/hinic_sriov.h +7 -0
@@ -86,6 +86,13 @@ int hinic_ndo_get_vf_config(struct net_device *netdev,int hinic_ndo_set_vf_trust (struct net_device *netdev,int vf,bool setting); +int hinic_ndo_set_vf_bw (struct net_device *netdev, +int vf,int min_tx_rate,int max_tx_rate); + +int hinic_ndo_set_vf_spoofchk (struct net_device *netdev,int vf,bool setting); + +int hinic_ndo_set_vf_link_state (struct net_device *netdev,int vf_id,int link); +void hinic_notify_all_vfs_link_changed (struct hinic_hwdev *hwdev,u8 link_status);
Signature · 1 line
2.17.1