1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Aquantia Corporation
5 #include <rte_ethdev_pci.h>
7 #include "atl_ethdev.h"
8 #include "atl_common.h"
9 #include "atl_hw_regs.h"
11 #include "hw_atl/hw_atl_llh.h"
12 #include "hw_atl/hw_atl_b0.h"
13 #include "hw_atl/hw_atl_b0_internal.h"
15 static int eth_atl_dev_init(struct rte_eth_dev *eth_dev);
16 static int eth_atl_dev_uninit(struct rte_eth_dev *eth_dev);
18 static int atl_dev_configure(struct rte_eth_dev *dev);
19 static int atl_dev_start(struct rte_eth_dev *dev);
20 static void atl_dev_stop(struct rte_eth_dev *dev);
21 static void atl_dev_close(struct rte_eth_dev *dev);
22 static int atl_dev_reset(struct rte_eth_dev *dev);
24 static int atl_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
27 static void atl_dev_info_get(struct rte_eth_dev *dev,
28 struct rte_eth_dev_info *dev_info);
31 static int eth_atl_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
32 struct rte_pci_device *pci_dev);
33 static int eth_atl_pci_remove(struct rte_pci_device *pci_dev);
35 static void atl_dev_info_get(struct rte_eth_dev *dev,
36 struct rte_eth_dev_info *dev_info);
39 int atl_logtype_driver;
42 * The set of PCI devices this driver supports
44 static const struct rte_pci_id pci_id_atl_map[] = {
45 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_0001) },
46 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_D100) },
47 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_D107) },
48 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_D108) },
49 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_D109) },
51 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC100) },
52 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC107) },
53 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC108) },
54 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC109) },
55 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC111) },
56 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC112) },
58 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC100S) },
59 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC107S) },
60 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC108S) },
61 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC109S) },
62 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC111S) },
63 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC112S) },
65 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC111E) },
66 { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC112E) },
67 { .vendor_id = 0, /* sentinel */ },
70 static struct rte_pci_driver rte_atl_pmd = {
71 .id_table = pci_id_atl_map,
72 .drv_flags = RTE_PCI_DRV_NEED_MAPPING |
73 RTE_PCI_DRV_IOVA_AS_VA,
74 .probe = eth_atl_pci_probe,
75 .remove = eth_atl_pci_remove,
78 static const struct eth_dev_ops atl_eth_dev_ops = {
79 .dev_configure = atl_dev_configure,
80 .dev_start = atl_dev_start,
81 .dev_stop = atl_dev_stop,
82 .dev_close = atl_dev_close,
83 .dev_reset = atl_dev_reset,
85 .fw_version_get = atl_fw_version_get,
86 .dev_infos_get = atl_dev_info_get,
90 atl_reset_hw(struct aq_hw_s *hw)
92 return hw_atl_b0_hw_reset(hw);
96 eth_atl_dev_init(struct rte_eth_dev *eth_dev)
98 struct atl_adapter *adapter =
99 (struct atl_adapter *)eth_dev->data->dev_private;
100 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
101 struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
104 PMD_INIT_FUNC_TRACE();
106 eth_dev->dev_ops = &atl_eth_dev_ops;
108 /* For secondary processes, the primary process has done all the work */
109 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
112 /* Vendor and Device ID need to be set before init of shared code */
113 hw->device_id = pci_dev->id.device_id;
114 hw->vendor_id = pci_dev->id.vendor_id;
115 hw->mmio = (void *)pci_dev->mem_resource[0].addr;
117 /* Hardware configuration - hardcode */
118 adapter->hw_cfg.is_lro = false;
119 adapter->hw_cfg.wol = false;
121 hw->aq_nic_cfg = &adapter->hw_cfg;
123 /* Allocate memory for storing MAC addresses */
124 eth_dev->data->mac_addrs = rte_zmalloc("atlantic", ETHER_ADDR_LEN, 0);
125 if (eth_dev->data->mac_addrs == NULL) {
126 PMD_INIT_LOG(ERR, "MAC Malloc failed");
130 err = hw_atl_utils_initfw(hw, &hw->aq_fw_ops);
134 /* Copy the permanent MAC address */
135 if (hw->aq_fw_ops->get_mac_permanent(hw,
136 eth_dev->data->mac_addrs->addr_bytes) != 0)
143 eth_atl_dev_uninit(struct rte_eth_dev *eth_dev)
147 PMD_INIT_FUNC_TRACE();
149 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
152 hw = ATL_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
154 if (hw->adapter_stopped == 0)
155 atl_dev_close(eth_dev);
157 eth_dev->dev_ops = NULL;
159 rte_free(eth_dev->data->mac_addrs);
160 eth_dev->data->mac_addrs = NULL;
166 eth_atl_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
167 struct rte_pci_device *pci_dev)
169 return rte_eth_dev_pci_generic_probe(pci_dev,
170 sizeof(struct atl_adapter), eth_atl_dev_init);
174 eth_atl_pci_remove(struct rte_pci_device *pci_dev)
176 return rte_eth_dev_pci_generic_remove(pci_dev, eth_atl_dev_uninit);
180 atl_dev_configure(struct rte_eth_dev *dev __rte_unused)
186 * Configure device link speed and setup link.
187 * It returns 0 on success.
190 atl_dev_start(struct rte_eth_dev *dev)
192 struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
196 PMD_INIT_FUNC_TRACE();
198 /* set adapter started */
199 hw->adapter_stopped = 0;
201 /* reinitialize adapter
202 * this calls reset and start
204 status = atl_reset_hw(hw);
208 err = hw_atl_b0_hw_init(hw, dev->data->mac_addrs->addr_bytes);
210 hw_atl_b0_hw_start(hw);
212 PMD_INIT_LOG(DEBUG, "FW version: %u.%u.%u",
213 hw->fw_ver_actual >> 24,
214 (hw->fw_ver_actual >> 16) & 0xFF,
215 hw->fw_ver_actual & 0xFFFF);
216 PMD_INIT_LOG(DEBUG, "Driver version: %s", ATL_PMD_DRIVER_VERSION);
222 * Stop device: disable rx and tx functions to allow for reconfiguring.
225 atl_dev_stop(struct rte_eth_dev *dev)
228 ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
232 hw->adapter_stopped = 1;
236 * Reset and stop device.
239 atl_dev_close(struct rte_eth_dev *dev)
241 PMD_INIT_FUNC_TRACE();
247 atl_dev_reset(struct rte_eth_dev *dev)
251 ret = eth_atl_dev_uninit(dev);
255 ret = eth_atl_dev_init(dev);
261 atl_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
263 struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
265 unsigned int ret = 0;
267 ret = hw_atl_utils_get_fw_version(hw, &fw_ver);
271 ret = snprintf(fw_version, fw_size, "%u.%u.%u", fw_ver >> 24,
272 (fw_ver >> 16) & 0xFFU, fw_ver & 0xFFFFU);
274 ret += 1; /* add string null-terminator */
283 atl_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
285 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
287 dev_info->max_rx_queues = 0;
288 dev_info->max_rx_queues = 0;
290 dev_info->max_vfs = pci_dev->max_vfs;
292 dev_info->max_hash_mac_addrs = 0;
293 dev_info->max_vmdq_pools = 0;
294 dev_info->vmdq_queue_num = 0;
297 RTE_PMD_REGISTER_PCI(net_atlantic, rte_atl_pmd);
298 RTE_PMD_REGISTER_PCI_TABLE(net_atlantic, pci_id_atl_map);
299 RTE_PMD_REGISTER_KMOD_DEP(net_atlantic, "* igb_uio | uio_pci_generic");
301 RTE_INIT(atl_init_log)
303 atl_logtype_init = rte_log_register("pmd.net.atlantic.init");
304 if (atl_logtype_init >= 0)
305 rte_log_set_level(atl_logtype_init, RTE_LOG_NOTICE);
306 atl_logtype_driver = rte_log_register("pmd.net.atlantic.driver");
307 if (atl_logtype_driver >= 0)
308 rte_log_set_level(atl_logtype_driver, RTE_LOG_NOTICE);