1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018-2019 Hisilicon Limited.
12 #include <rte_bus_pci.h>
13 #include <rte_common.h>
14 #include <rte_cycles.h>
17 #include <rte_ether.h>
18 #include <rte_ethdev_driver.h>
19 #include <rte_ethdev_pci.h>
24 #include "hns3_ethdev.h"
25 #include "hns3_logs.h"
26 #include "hns3_regs.h"
28 int hns3_logtype_init;
29 int hns3_logtype_driver;
32 hns3_dev_close(struct rte_eth_dev *eth_dev)
34 struct hns3_adapter *hns = eth_dev->data->dev_private;
35 struct hns3_hw *hw = &hns->hw;
37 hw->adapter_state = HNS3_NIC_CLOSED;
40 static const struct eth_dev_ops hns3_eth_dev_ops = {
41 .dev_close = hns3_dev_close,
45 hns3_dev_init(struct rte_eth_dev *eth_dev)
47 struct hns3_adapter *hns = eth_dev->data->dev_private;
48 struct hns3_hw *hw = &hns->hw;
50 PMD_INIT_FUNC_TRACE();
52 eth_dev->dev_ops = &hns3_eth_dev_ops;
53 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
57 hw->data = eth_dev->data;
58 hw->adapter_state = HNS3_NIC_INITIALIZED;
60 * Pass the information to the rte_eth_dev_close() that it should also
61 * release the private port resources.
63 eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
69 hns3_dev_uninit(struct rte_eth_dev *eth_dev)
71 struct hns3_adapter *hns = eth_dev->data->dev_private;
72 struct hns3_hw *hw = &hns->hw;
74 PMD_INIT_FUNC_TRACE();
76 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
79 eth_dev->dev_ops = NULL;
80 eth_dev->rx_pkt_burst = NULL;
81 eth_dev->tx_pkt_burst = NULL;
82 eth_dev->tx_pkt_prepare = NULL;
83 if (hw->adapter_state < HNS3_NIC_CLOSING)
84 hns3_dev_close(eth_dev);
86 hw->adapter_state = HNS3_NIC_REMOVED;
91 eth_hns3_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
92 struct rte_pci_device *pci_dev)
94 return rte_eth_dev_pci_generic_probe(pci_dev,
95 sizeof(struct hns3_adapter),
100 eth_hns3_pci_remove(struct rte_pci_device *pci_dev)
102 return rte_eth_dev_pci_generic_remove(pci_dev, hns3_dev_uninit);
105 static const struct rte_pci_id pci_id_hns3_map[] = {
106 { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_GE) },
107 { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_25GE) },
108 { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_25GE_RDMA) },
109 { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_50GE_RDMA) },
110 { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_100G_RDMA_MACSEC) },
111 { .vendor_id = 0, /* sentinel */ },
114 static struct rte_pci_driver rte_hns3_pmd = {
115 .id_table = pci_id_hns3_map,
116 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
117 .probe = eth_hns3_pci_probe,
118 .remove = eth_hns3_pci_remove,
121 RTE_PMD_REGISTER_PCI(net_hns3, rte_hns3_pmd);
122 RTE_PMD_REGISTER_PCI_TABLE(net_hns3, pci_id_hns3_map);
123 RTE_PMD_REGISTER_KMOD_DEP(net_hns3, "* igb_uio | vfio-pci");
125 RTE_INIT(hns3_init_log)
127 hns3_logtype_init = rte_log_register("pmd.net.hns3.init");
128 if (hns3_logtype_init >= 0)
129 rte_log_set_level(hns3_logtype_init, RTE_LOG_NOTICE);
130 hns3_logtype_driver = rte_log_register("pmd.net.hns3.driver");
131 if (hns3_logtype_driver >= 0)
132 rte_log_set_level(hns3_logtype_driver, RTE_LOG_NOTICE);