net/atlantic: add PMD driver skeleton
[dpdk.git] / drivers / net / atlantic / atl_ethdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Aquantia Corporation
3  */
4
5 #include <rte_ethdev_pci.h>
6
7 #include "atl_ethdev.h"
8 #include "atl_common.h"
9
10 static int eth_atl_dev_init(struct rte_eth_dev *eth_dev);
11 static int eth_atl_dev_uninit(struct rte_eth_dev *eth_dev);
12
13 static int  atl_dev_configure(struct rte_eth_dev *dev);
14 static int  atl_dev_start(struct rte_eth_dev *dev);
15 static void atl_dev_stop(struct rte_eth_dev *dev);
16 static void atl_dev_close(struct rte_eth_dev *dev);
17 static int  atl_dev_reset(struct rte_eth_dev *dev);
18
19 static int eth_atl_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
20         struct rte_pci_device *pci_dev);
21 static int eth_atl_pci_remove(struct rte_pci_device *pci_dev);
22
23 static void atl_dev_info_get(struct rte_eth_dev *dev,
24                                 struct rte_eth_dev_info *dev_info);
25
26 /*
27  * The set of PCI devices this driver supports
28  */
29 static const struct rte_pci_id pci_id_atl_map[] = {
30         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_0001) },
31         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_D100) },
32         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_D107) },
33         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_D108) },
34         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_D109) },
35
36         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC100) },
37         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC107) },
38         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC108) },
39         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC109) },
40         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC111) },
41         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC112) },
42
43         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC100S) },
44         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC107S) },
45         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC108S) },
46         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC109S) },
47         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC111S) },
48         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC112S) },
49
50         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC111E) },
51         { RTE_PCI_DEVICE(PCI_VENDOR_ID_AQUANTIA, AQ_DEVICE_ID_AQC112E) },
52         { .vendor_id = 0, /* sentinel */ },
53 };
54
55 static struct rte_pci_driver rte_atl_pmd = {
56         .id_table = pci_id_atl_map,
57         .drv_flags = RTE_PCI_DRV_NEED_MAPPING |
58                      RTE_PCI_DRV_IOVA_AS_VA,
59         .probe = eth_atl_pci_probe,
60         .remove = eth_atl_pci_remove,
61 };
62
63 static const struct eth_dev_ops atl_eth_dev_ops = {
64         .dev_configure        = atl_dev_configure,
65         .dev_start            = atl_dev_start,
66         .dev_stop             = atl_dev_stop,
67         .dev_close            = atl_dev_close,
68         .dev_reset            = atl_dev_reset,
69         .dev_infos_get        = atl_dev_info_get,
70 };
71
72 static int
73 eth_atl_dev_init(struct rte_eth_dev *eth_dev)
74 {
75         eth_dev->dev_ops = &atl_eth_dev_ops;
76
77         /* Allocate memory for storing MAC addresses */
78         eth_dev->data->mac_addrs = rte_zmalloc("atlantic", ETHER_ADDR_LEN, 0);
79         if (eth_dev->data->mac_addrs == NULL)
80                 return -ENOMEM;
81
82         return 0;
83 }
84
85 static int
86 eth_atl_dev_uninit(struct rte_eth_dev *eth_dev)
87 {
88         rte_free(eth_dev->data->mac_addrs);
89
90         return 0;
91 }
92
93 static int
94 eth_atl_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
95         struct rte_pci_device *pci_dev)
96 {
97         return rte_eth_dev_pci_generic_probe(pci_dev,
98                 sizeof(struct atl_adapter), eth_atl_dev_init);
99 }
100
101 static int
102 eth_atl_pci_remove(struct rte_pci_device *pci_dev)
103 {
104         return rte_eth_dev_pci_generic_remove(pci_dev, eth_atl_dev_uninit);
105 }
106
107 static int
108 atl_dev_configure(struct rte_eth_dev *dev __rte_unused)
109 {
110         return 0;
111 }
112
113 /*
114  * Configure device link speed and setup link.
115  * It returns 0 on success.
116  */
117 static int
118 atl_dev_start(struct rte_eth_dev *dev __rte_unused)
119 {
120         return 0;
121 }
122
123 /*
124  * Stop device: disable rx and tx functions to allow for reconfiguring.
125  */
126 static void
127 atl_dev_stop(struct rte_eth_dev *dev __rte_unused)
128 {
129 }
130
131 /*
132  * Reset and stop device.
133  */
134 static void
135 atl_dev_close(struct rte_eth_dev *dev __rte_unused)
136 {
137 }
138
139 static int
140 atl_dev_reset(struct rte_eth_dev *dev)
141 {
142         int ret;
143
144         ret = eth_atl_dev_uninit(dev);
145         if (ret)
146                 return ret;
147
148         ret = eth_atl_dev_init(dev);
149
150         return ret;
151 }
152
153 static void
154 atl_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
155 {
156         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
157
158         dev_info->max_rx_queues = 0;
159         dev_info->max_rx_queues = 0;
160
161         dev_info->max_vfs = pci_dev->max_vfs;
162
163         dev_info->max_hash_mac_addrs = 0;
164         dev_info->max_vmdq_pools = 0;
165         dev_info->vmdq_queue_num = 0;
166 }
167
168 RTE_PMD_REGISTER_PCI(net_atlantic, rte_atl_pmd);
169 RTE_PMD_REGISTER_PCI_TABLE(net_atlantic, pci_id_atl_map);
170 RTE_PMD_REGISTER_KMOD_DEP(net_atlantic, "* igb_uio | uio_pci_generic");