Skip to content

Commit 424eb83

Browse files
Salil Mehtadavem330
authored andcommitted
net: hns3: Unified HNS3 {VF|PF} Ethernet Driver for hip08 SoC
Most of the NAPI handling interface, skb buffer management, management of the RX/TX descriptors, ethool interface etc. has quite a bit of code which is common to VF and PF driver. This patch makes the exisitng PF's HNS3 ENET driver as the common ENET driver for both Virtual & Physical Function. This will help in reduction of redundancy and better management of code. Signed-off-by: Salil Mehta <salil.mehta@huawei.com> Signed-off-by: lipeng <lipeng321@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e963cb7 commit 424eb83

File tree

9 files changed

+46
-12
lines changed

9 files changed

+46
-12
lines changed

drivers/net/ethernet/hisilicon/hns3/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ obj-$(CONFIG_HNS3) += hns3pf/
77
obj-$(CONFIG_HNS3) += hns3vf/
88

99
obj-$(CONFIG_HNS3) += hnae3.o
10+
11+
obj-$(CONFIG_HNS3_ENET) += hns3.o
12+
hns3-objs = hns3_enet.o hns3_ethtool.o
13+
14+
hns3-$(CONFIG_HNS3_DCB) += hns3_dcbnl.o

drivers/net/ethernet/hisilicon/hns3/hnae3.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,18 @@ int hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev)
196196
const struct pci_device_id *id;
197197
struct hnae3_ae_algo *ae_algo;
198198
struct hnae3_client *client;
199-
int ret = 0;
199+
int ret = 0, lock_acquired;
200+
201+
/* we can get deadlocked if SRIOV is being enabled in context to probe
202+
* and probe gets called again in same context. This can happen when
203+
* pci_enable_sriov() is called to create VFs from PF probes context.
204+
* Therefore, for simplicity uniformly defering further probing in all
205+
* cases where we detect contention.
206+
*/
207+
lock_acquired = mutex_trylock(&hnae3_common_lock);
208+
if (!lock_acquired)
209+
return -EPROBE_DEFER;
200210

201-
mutex_lock(&hnae3_common_lock);
202211
list_add_tail(&ae_dev->node, &hnae3_ae_dev_list);
203212

204213
/* Check if there are matched ae_algo */
@@ -211,6 +220,7 @@ int hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev)
211220

212221
if (!ae_dev->ops) {
213222
dev_err(&ae_dev->pdev->dev, "ae_dev ops are null\n");
223+
ret = -EOPNOTSUPP;
214224
goto out_err;
215225
}
216226

drivers/net/ethernet/hisilicon/hns3/hnae3.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,10 @@ struct hnae3_unic_private_info {
452452
struct hnae3_queue **tqp; /* array base of all TQPs of this instance */
453453
};
454454

455-
#define HNAE3_SUPPORT_MAC_LOOPBACK 1
456-
#define HNAE3_SUPPORT_PHY_LOOPBACK 2
457-
#define HNAE3_SUPPORT_SERDES_LOOPBACK 4
455+
#define HNAE3_SUPPORT_MAC_LOOPBACK BIT(0)
456+
#define HNAE3_SUPPORT_PHY_LOOPBACK BIT(1)
457+
#define HNAE3_SUPPORT_SERDES_LOOPBACK BIT(2)
458+
#define HNAE3_SUPPORT_VF BIT(3)
458459

459460
struct hnae3_handle {
460461
struct hnae3_client *client;

drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_dcbnl.c renamed to drivers/net/ethernet/hisilicon/hns3/hns3_dcbnl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void hns3_dcbnl_setup(struct hnae3_handle *handle)
9393
{
9494
struct net_device *dev = handle->kinfo.netdev;
9595

96-
if (!handle->kinfo.dcb_ops)
96+
if ((!handle->kinfo.dcb_ops) || (handle->flags & HNAE3_SUPPORT_VF))
9797
return;
9898

9999
dev->dcbnl_ops = &hns3_dcbnl_ops;

drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c renamed to drivers/net/ethernet/hisilicon/hns3/hns3_enet.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ static const struct pci_device_id hns3_pci_tbl[] = {
5252
HNAE3_DEV_SUPPORT_ROCE_DCB_BITS},
5353
{PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_100G_RDMA_MACSEC),
5454
HNAE3_DEV_SUPPORT_ROCE_DCB_BITS},
55+
{PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_100G_VF), 0},
56+
{PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_100G_RDMA_DCB_PFC_VF), 0},
5557
/* required last entry */
5658
{0, }
5759
};

drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c renamed to drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,21 @@ static int hns3_nway_reset(struct net_device *netdev)
849849
return genphy_restart_aneg(phy);
850850
}
851851

852+
static const struct ethtool_ops hns3vf_ethtool_ops = {
853+
.get_drvinfo = hns3_get_drvinfo,
854+
.get_ringparam = hns3_get_ringparam,
855+
.set_ringparam = hns3_set_ringparam,
856+
.get_strings = hns3_get_strings,
857+
.get_ethtool_stats = hns3_get_stats,
858+
.get_sset_count = hns3_get_sset_count,
859+
.get_rxnfc = hns3_get_rxnfc,
860+
.get_rxfh_key_size = hns3_get_rss_key_size,
861+
.get_rxfh_indir_size = hns3_get_rss_indir_size,
862+
.get_rxfh = hns3_get_rss,
863+
.set_rxfh = hns3_set_rss,
864+
.get_link_ksettings = hns3_get_link_ksettings,
865+
};
866+
852867
static const struct ethtool_ops hns3_ethtool_ops = {
853868
.self_test = hns3_self_test,
854869
.get_drvinfo = hns3_get_drvinfo,
@@ -872,5 +887,10 @@ static const struct ethtool_ops hns3_ethtool_ops = {
872887

873888
void hns3_ethtool_set_ops(struct net_device *netdev)
874889
{
875-
netdev->ethtool_ops = &hns3_ethtool_ops;
890+
struct hnae3_handle *h = hns3_get_handle(netdev);
891+
892+
if (h->flags & HNAE3_SUPPORT_VF)
893+
netdev->ethtool_ops = &hns3vf_ethtool_ops;
894+
else
895+
netdev->ethtool_ops = &hns3_ethtool_ops;
876896
}

drivers/net/ethernet/hisilicon/hns3/hns3pf/Makefile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,3 @@ obj-$(CONFIG_HNS3_HCLGE) += hclge.o
88
hclge-objs = hclge_main.o hclge_cmd.o hclge_mdio.o hclge_tm.o
99

1010
hclge-$(CONFIG_HNS3_DCB) += hclge_dcb.o
11-
12-
obj-$(CONFIG_HNS3_ENET) += hns3.o
13-
hns3-objs = hns3_enet.o hns3_ethtool.o
14-
15-
hns3-$(CONFIG_HNS3_DCB) += hns3_dcbnl.o

drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ static int hclgevf_set_handle_info(struct hclgevf_dev *hdev)
310310
nic->ae_algo = &ae_algovf;
311311
nic->pdev = hdev->pdev;
312312
nic->numa_node_mask = hdev->numa_node_mask;
313+
nic->flags |= HNAE3_SUPPORT_VF;
313314

314315
if (hdev->ae_dev->dev_type != HNAE3_DEV_KNIC) {
315316
dev_err(&hdev->pdev->dev, "unsupported device type %d\n",

0 commit comments

Comments
 (0)