Re: [PATCH net-next v2] hinic: add three net_device_ops of vf

2020-05-09 Thread Jakub Kicinski
On Fri, 8 May 2020 20:18:50 + Luo bin wrote:
> 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 

Applied, thank you. Please make sure you fix the time on your system,
this patch arrived with a date set few hours in the past.


[PATCH net-next v2] hinic: add three net_device_ops of vf

2020-05-08 Thread Luo bin
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 
---
 .../net/ethernet/huawei/hinic/hinic_hw_cmdq.c |  29 ++
 .../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_hw_mbox.c |   4 +-
 .../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 +
 11 files changed, 453 insertions(+), 24 deletions(-)

diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c 
b/drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c
index 33c5333657c1..cb5b6e5f787f 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c
@@ -849,6 +849,25 @@ 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(>pf_to_mgmt, HINIC_MOD_COMM,
+HINIC_COMM_CMD_HWCTXT_SET,
+_ioctxt, sizeof(hw_ioctxt), NULL,
+NULL, HINIC_MGMT_MSG_SYNC);
+}
+
 /**
  * hinic_init_cmdqs - init all cmdqs
  * @cmdqs: cmdqs to init
@@ -899,8 +918,18 @@ int hinic_init_cmdqs(struct hinic_cmdqs *cmdqs, struct 
hinic_hwif *hwif,
 
hinic_ceq_register_cb(_to_io->ceqs, HINIC_CEQ_CMDQ, cmdqs,
  cmdq_ceq_handler);
+
+   err = hinic_set_cmdq_depth(hwdev, CMDQ_DEPTH);
+   if (err) {
+   dev_err(>pdev->dev, "Failed to set cmdq depth\n");
+   goto err_set_cmdq_depth;
+   }
+
return 0;
 
+err_set_cmdq_depth:
+   hinic_ceq_unregister_cb(_to_io->ceqs, HINIC_CEQ_CMDQ);
+
 err_cmdq_ctxt:
hinic_wqs_cmdq_free(>cmdq_pages, cmdqs->saved_wqs,
HINIC_MAX_CMDQ_TYPES);
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c 
b/drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c
index e5cab58e4ddd..1ce8b8d572cf 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c
@@ -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(>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(>pf_to_mgmt, HINIC_MOD_COMM,
+   HINIC_COMM_CMD_L2NIC_RESET, _reset,
+   sizeof(l2nic_reset), _reset,
+   _size, HINIC_MGMT_MSG_SYNC);
+   if (err || !out_size || l2nic_reset.status) {
+   dev_err(>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(>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);
 
diff --git