Skip to content

Commit 72ef908

Browse files
Luo binkuba-moo
authored andcommitted
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 <luobin9@huawei.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 0d5c56a commit 72ef908

11 files changed

Lines changed: 453 additions & 24 deletions

File tree

‎drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,25 @@ static int init_cmdqs_ctxt(struct hinic_hwdev *hwdev,
849849
return err;
850850
}
851851

852+
static int hinic_set_cmdq_depth(struct hinic_hwdev *hwdev, u16 cmdq_depth)
853+
{
854+
struct hinic_cmd_hw_ioctxt hw_ioctxt = { 0 };
855+
struct hinic_pfhwdev *pfhwdev;
856+
857+
pfhwdev = container_of(hwdev, struct hinic_pfhwdev, hwdev);
858+
859+
hw_ioctxt.func_idx = HINIC_HWIF_FUNC_IDX(hwdev->hwif);
860+
hw_ioctxt.ppf_idx = HINIC_HWIF_PPF_IDX(hwdev->hwif);
861+
862+
hw_ioctxt.set_cmdq_depth = HW_IOCTXT_SET_CMDQ_DEPTH_ENABLE;
863+
hw_ioctxt.cmdq_depth = (u8)ilog2(cmdq_depth);
864+
865+
return hinic_msg_to_mgmt(&pfhwdev->pf_to_mgmt, HINIC_MOD_COMM,
866+
HINIC_COMM_CMD_HWCTXT_SET,
867+
&hw_ioctxt, sizeof(hw_ioctxt), NULL,
868+
NULL, HINIC_MGMT_MSG_SYNC);
869+
}
870+
852871
/**
853872
* hinic_init_cmdqs - init all cmdqs
854873
* @cmdqs: cmdqs to init
@@ -899,8 +918,18 @@ int hinic_init_cmdqs(struct hinic_cmdqs *cmdqs, struct hinic_hwif *hwif,
899918

900919
hinic_ceq_register_cb(&func_to_io->ceqs, HINIC_CEQ_CMDQ, cmdqs,
901920
cmdq_ceq_handler);
921+
922+
err = hinic_set_cmdq_depth(hwdev, CMDQ_DEPTH);
923+
if (err) {
924+
dev_err(&hwif->pdev->dev, "Failed to set cmdq depth\n");
925+
goto err_set_cmdq_depth;
926+
}
927+
902928
return 0;
903929

930+
err_set_cmdq_depth:
931+
hinic_ceq_unregister_cb(&func_to_io->ceqs, HINIC_CEQ_CMDQ);
932+
904933
err_cmdq_ctxt:
905934
hinic_wqs_cmdq_free(&cmdqs->cmdq_pages, cmdqs->saved_wqs,
906935
HINIC_MAX_CMDQ_TYPES);

‎drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c‎

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ enum io_status {
4444
IO_RUNNING = 1,
4545
};
4646

47-
enum hw_ioctxt_set_cmdq_depth {
48-
HW_IOCTXT_SET_CMDQ_DEPTH_DEFAULT,
49-
};
50-
5147
/**
5248
* get_capability - convert device capabilities to NIC capabilities
5349
* @hwdev: the HW device to set and convert device capabilities for
@@ -667,6 +663,32 @@ static void free_pfhwdev(struct hinic_pfhwdev *pfhwdev)
667663
hinic_pf_to_mgmt_free(&pfhwdev->pf_to_mgmt);
668664
}
669665

666+
static int hinic_l2nic_reset(struct hinic_hwdev *hwdev)
667+
{
668+
struct hinic_cmd_l2nic_reset l2nic_reset = {0};
669+
u16 out_size = sizeof(l2nic_reset);
670+
struct hinic_pfhwdev *pfhwdev;
671+
int err;
672+
673+
pfhwdev = container_of(hwdev, struct hinic_pfhwdev, hwdev);
674+
675+
l2nic_reset.func_id = HINIC_HWIF_FUNC_IDX(hwdev->hwif);
676+
/* 0 represents standard l2nic reset flow */
677+
l2nic_reset.reset_flag = 0;
678+
679+
err = hinic_msg_to_mgmt(&pfhwdev->pf_to_mgmt, HINIC_MOD_COMM,
680+
HINIC_COMM_CMD_L2NIC_RESET, &l2nic_reset,
681+
sizeof(l2nic_reset), &l2nic_reset,
682+
&out_size, HINIC_MGMT_MSG_SYNC);
683+
if (err || !out_size || l2nic_reset.status) {
684+
dev_err(&hwdev->hwif->pdev->dev, "Failed to reset L2NIC resources, err: %d, status: 0x%x, out_size: 0x%x\n",
685+
err, l2nic_reset.status, out_size);
686+
return -EIO;
687+
}
688+
689+
return 0;
690+
}
691+
670692
/**
671693
* hinic_init_hwdev - Initialize the NIC HW
672694
* @pdev: the NIC pci device
@@ -729,6 +751,10 @@ struct hinic_hwdev *hinic_init_hwdev(struct pci_dev *pdev)
729751
goto err_init_pfhwdev;
730752
}
731753

754+
err = hinic_l2nic_reset(hwdev);
755+
if (err)
756+
goto err_l2nic_reset;
757+
732758
err = get_dev_cap(hwdev);
733759
if (err) {
734760
dev_err(&pdev->dev, "Failed to get device capabilities\n");
@@ -759,6 +785,7 @@ struct hinic_hwdev *hinic_init_hwdev(struct pci_dev *pdev)
759785
err_init_fw_ctxt:
760786
hinic_vf_func_free(hwdev);
761787
err_vf_func_init:
788+
err_l2nic_reset:
762789
err_dev_cap:
763790
free_pfhwdev(pfhwdev);
764791

‎drivers/net/ethernet/huawei/hinic/hinic_hw_dev.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#define HINIC_PF_SET_VF_ALREADY 0x4
2727
#define HINIC_MGMT_STATUS_EXIST 0x6
28+
#define HINIC_MGMT_CMD_UNSUPPORTED 0xFF
2829

2930
struct hinic_cap {
3031
u16 max_qps;
@@ -33,6 +34,11 @@ struct hinic_cap {
3334
u16 max_vf_qps;
3435
};
3536

37+
enum hw_ioctxt_set_cmdq_depth {
38+
HW_IOCTXT_SET_CMDQ_DEPTH_DEFAULT,
39+
HW_IOCTXT_SET_CMDQ_DEPTH_ENABLE,
40+
};
41+
3642
enum hinic_port_cmd {
3743
HINIC_PORT_CMD_VF_REGISTER = 0x0,
3844
HINIC_PORT_CMD_VF_UNREGISTER = 0x1,
@@ -86,12 +92,16 @@ enum hinic_port_cmd {
8692

8793
HINIC_PORT_CMD_FWCTXT_INIT = 69,
8894

95+
HINIC_PORT_CMD_ENABLE_SPOOFCHK = 78,
96+
8997
HINIC_PORT_CMD_GET_MGMT_VERSION = 88,
9098

9199
HINIC_PORT_CMD_SET_FUNC_STATE = 93,
92100

93101
HINIC_PORT_CMD_GET_GLOBAL_QPN = 102,
94102

103+
HINIC_PORT_CMD_SET_VF_RATE = 105,
104+
95105
HINIC_PORT_CMD_SET_VF_VLAN = 106,
96106

97107
HINIC_PORT_CMD_CLR_VF_VLAN,
@@ -107,6 +117,8 @@ enum hinic_port_cmd {
107117
HINIC_PORT_CMD_GET_CAP = 170,
108118

109119
HINIC_PORT_CMD_SET_LRO_TIMER = 244,
120+
121+
HINIC_PORT_CMD_SET_VF_MAX_MIN_RATE = 249,
110122
};
111123

112124
enum hinic_ucode_cmd {
@@ -247,6 +259,15 @@ struct hinic_cmd_hw_ci {
247259
u64 ci_addr;
248260
};
249261

262+
struct hinic_cmd_l2nic_reset {
263+
u8 status;
264+
u8 version;
265+
u8 rsvd0[6];
266+
267+
u16 func_id;
268+
u16 reset_flag;
269+
};
270+
250271
struct hinic_hwdev {
251272
struct hinic_hwif *hwif;
252273
struct msix_entry *msix_entries;

‎drivers/net/ethernet/huawei/hinic/hinic_hw_if.c‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/io.h>
1111
#include <linux/types.h>
1212
#include <linux/bitops.h>
13+
#include <linux/delay.h>
1314

1415
#include "hinic_hw_csr.h"
1516
#include "hinic_hw_if.h"
@@ -18,6 +19,8 @@
1819

1920
#define VALID_MSIX_IDX(attr, msix_index) ((msix_index) < (attr)->num_irqs)
2021

22+
#define WAIT_HWIF_READY_TIMEOUT 10000
23+
2124
/**
2225
* hinic_msix_attr_set - set message attribute for msix entry
2326
* @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,
187190
**/
188191
static int hwif_ready(struct hinic_hwif *hwif)
189192
{
190-
struct pci_dev *pdev = hwif->pdev;
191193
u32 addr, attr1;
192194

193195
addr = HINIC_CSR_FUNC_ATTR1_ADDR;
194196
attr1 = hinic_hwif_read_reg(hwif, addr);
195197

196-
if (!HINIC_FA1_GET(attr1, INIT_STATUS)) {
197-
dev_err(&pdev->dev, "hwif status is not ready\n");
198-
return -EFAULT;
198+
if (!HINIC_FA1_GET(attr1, MGMT_INIT_STATUS))
199+
return -EBUSY;
200+
201+
if (HINIC_IS_VF(hwif)) {
202+
if (!HINIC_FA1_GET(attr1, PF_INIT_STATUS))
203+
return -EBUSY;
199204
}
200205

201206
return 0;
202207
}
203208

209+
static int wait_hwif_ready(struct hinic_hwif *hwif)
210+
{
211+
unsigned long timeout = 0;
212+
213+
do {
214+
if (!hwif_ready(hwif))
215+
return 0;
216+
217+
usleep_range(999, 1000);
218+
timeout++;
219+
} while (timeout <= WAIT_HWIF_READY_TIMEOUT);
220+
221+
dev_err(&hwif->pdev->dev, "Wait for hwif timeout\n");
222+
223+
return -EBUSY;
224+
}
225+
204226
/**
205227
* set_hwif_attr - set the attributes in the relevant members in hwif
206228
* @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)
373395
goto err_map_intr_bar;
374396
}
375397

376-
err = hwif_ready(hwif);
398+
err = wait_hwif_ready(hwif);
377399
if (err) {
378400
dev_err(&pdev->dev, "HW interface is not ready\n");
379401
goto err_hwif_ready;

‎drivers/net/ethernet/huawei/hinic/hinic_hw_if.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@
5555
#define HINIC_FA1_IRQS_PER_FUNC_SHIFT 20
5656
#define HINIC_FA1_DMA_ATTR_PER_FUNC_SHIFT 24
5757
/* reserved members - off 27 */
58-
#define HINIC_FA1_INIT_STATUS_SHIFT 30
58+
#define HINIC_FA1_MGMT_INIT_STATUS_SHIFT 30
59+
#define HINIC_FA1_PF_INIT_STATUS_SHIFT 31
5960

6061
#define HINIC_FA1_AEQS_PER_FUNC_MASK 0x3
6162
#define HINIC_FA1_CEQS_PER_FUNC_MASK 0x7
6263
#define HINIC_FA1_IRQS_PER_FUNC_MASK 0xF
6364
#define HINIC_FA1_DMA_ATTR_PER_FUNC_MASK 0x7
64-
#define HINIC_FA1_INIT_STATUS_MASK 0x1
65+
#define HINIC_FA1_MGMT_INIT_STATUS_MASK 0x1
66+
#define HINIC_FA1_PF_INIT_STATUS_MASK 0x1
6567

6668
#define HINIC_FA1_GET(val, member) \
6769
(((val) >> HINIC_FA1_##member##_SHIFT) & HINIC_FA1_##member##_MASK)

‎drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ wait_for_mbox_seg_completion(struct hinic_mbox_func_to_func *func_to_func,
627627
struct hinic_hwdev *hwdev = func_to_func->hwdev;
628628
struct completion *done = &send_mbox->send_done;
629629
u32 cnt = 0;
630-
ulong jif;
630+
unsigned long jif;
631631

632632
if (poll) {
633633
while (cnt < MBOX_MSG_POLLING_TIMEOUT) {
@@ -869,7 +869,7 @@ int hinic_mbox_to_func(struct hinic_mbox_func_to_func *func_to_func,
869869
{
870870
struct hinic_recv_mbox *mbox_for_resp;
871871
struct mbox_msg_info msg_info = {0};
872-
ulong timeo;
872+
unsigned long timeo;
873873
int err;
874874

875875
mbox_for_resp = &func_to_func->mbox_resp[dst_func];

‎drivers/net/ethernet/huawei/hinic/hinic_main.c‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,6 @@ static int hinic_open(struct net_device *netdev)
427427
goto err_func_port_state;
428428
}
429429

430-
if (!HINIC_IS_VF(nic_dev->hwdev->hwif))
431-
/* Wait up to 3 sec between port enable to link state */
432-
msleep(3000);
433-
434430
down(&nic_dev->mgmt_lock);
435431

436432
err = hinic_port_link_state(nic_dev, &link_state);
@@ -766,10 +762,12 @@ static void hinic_set_rx_mode(struct net_device *netdev)
766762
HINIC_RX_MODE_MC |
767763
HINIC_RX_MODE_BC;
768764

769-
if (netdev->flags & IFF_PROMISC)
770-
rx_mode |= HINIC_RX_MODE_PROMISC;
771-
else if (netdev->flags & IFF_ALLMULTI)
765+
if (netdev->flags & IFF_PROMISC) {
766+
if (!HINIC_IS_VF(nic_dev->hwdev->hwif))
767+
rx_mode |= HINIC_RX_MODE_PROMISC;
768+
} else if (netdev->flags & IFF_ALLMULTI) {
772769
rx_mode |= HINIC_RX_MODE_MC_ALL;
770+
}
773771

774772
rx_mode_work->rx_mode = rx_mode;
775773

@@ -868,6 +866,9 @@ static const struct net_device_ops hinic_netdev_ops = {
868866
.ndo_set_vf_vlan = hinic_ndo_set_vf_vlan,
869867
.ndo_get_vf_config = hinic_ndo_get_vf_config,
870868
.ndo_set_vf_trust = hinic_ndo_set_vf_trust,
869+
.ndo_set_vf_rate = hinic_ndo_set_vf_bw,
870+
.ndo_set_vf_spoofchk = hinic_ndo_set_vf_spoofchk,
871+
.ndo_set_vf_link_state = hinic_ndo_set_vf_link_state,
871872
};
872873

873874
static const struct net_device_ops hinicvf_netdev_ops = {
@@ -1232,6 +1233,8 @@ static void hinic_remove(struct pci_dev *pdev)
12321233

12331234
unregister_netdev(netdev);
12341235

1236+
hinic_port_del_mac(nic_dev, netdev->dev_addr, 0);
1237+
12351238
hinic_hwdev_cb_unregister(nic_dev->hwdev,
12361239
HINIC_MGMT_MSG_CMD_LINK_STATUS);
12371240

‎drivers/net/ethernet/huawei/hinic/hinic_port.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ static int change_mac(struct hinic_dev *nic_dev, const u8 *addr,
6666
return -EFAULT;
6767
}
6868

69-
if (cmd == HINIC_PORT_CMD_SET_MAC && port_mac_cmd.status ==
70-
HINIC_PF_SET_VF_ALREADY) {
71-
dev_warn(&pdev->dev, "PF has already set VF mac, Ignore set operation\n");
69+
if (port_mac_cmd.status == HINIC_PF_SET_VF_ALREADY) {
70+
dev_warn(&pdev->dev, "PF has already set VF mac, ignore %s operation\n",
71+
(op == MAC_SET) ? "set" : "del");
7272
return HINIC_PF_SET_VF_ALREADY;
7373
}
7474

7575
if (cmd == HINIC_PORT_CMD_SET_MAC && port_mac_cmd.status ==
7676
HINIC_MGMT_STATUS_EXIST)
77-
dev_warn(&pdev->dev, "MAC is repeated. Ignore set operation\n");
77+
dev_warn(&pdev->dev, "MAC is repeated, ignore set operation\n");
7878

7979
return 0;
8080
}

‎drivers/net/ethernet/huawei/hinic/hinic_port.h‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,49 @@ struct hinic_cmd_vport_stats {
506506
struct hinic_vport_stats stats;
507507
};
508508

509+
struct hinic_tx_rate_cfg_max_min {
510+
u8 status;
511+
u8 version;
512+
u8 rsvd0[6];
513+
514+
u16 func_id;
515+
u16 rsvd1;
516+
u32 min_rate;
517+
u32 max_rate;
518+
u8 rsvd2[8];
519+
};
520+
521+
struct hinic_tx_rate_cfg {
522+
u8 status;
523+
u8 version;
524+
u8 rsvd0[6];
525+
526+
u16 func_id;
527+
u16 rsvd1;
528+
u32 tx_rate;
529+
};
530+
531+
enum nic_speed_level {
532+
LINK_SPEED_10MB = 0,
533+
LINK_SPEED_100MB,
534+
LINK_SPEED_1GB,
535+
LINK_SPEED_10GB,
536+
LINK_SPEED_25GB,
537+
LINK_SPEED_40GB,
538+
LINK_SPEED_100GB,
539+
LINK_SPEED_LEVELS,
540+
};
541+
542+
struct hinic_spoofchk_set {
543+
u8 status;
544+
u8 version;
545+
u8 rsvd0[6];
546+
547+
u8 state;
548+
u8 rsvd1;
549+
u16 func_id;
550+
};
551+
509552
int hinic_port_add_mac(struct hinic_dev *nic_dev, const u8 *addr,
510553
u16 vlan_id);
511554

0 commit comments

Comments
 (0)