net/igc: add skeleton
[dpdk.git] / drivers / net / igc / igc_ethdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Intel Corporation
3  */
4
5 #include <stdint.h>
6
7 #include <rte_pci.h>
8 #include <rte_bus_pci.h>
9 #include <rte_ethdev_driver.h>
10 #include <rte_ethdev_pci.h>
11 #include <rte_malloc.h>
12
13 #include "igc_logs.h"
14 #include "igc_ethdev.h"
15
16 #define IGC_INTEL_VENDOR_ID             0x8086
17 #define IGC_DEV_ID_I225_LM              0x15F2
18 #define IGC_DEV_ID_I225_V               0x15F3
19 #define IGC_DEV_ID_I225_K               0x3100
20 #define IGC_DEV_ID_I225_I               0x15F8
21 #define IGC_DEV_ID_I220_V               0x15F7
22
23 static const struct rte_pci_id pci_id_igc_map[] = {
24         { RTE_PCI_DEVICE(IGC_INTEL_VENDOR_ID, IGC_DEV_ID_I225_LM) },
25         { RTE_PCI_DEVICE(IGC_INTEL_VENDOR_ID, IGC_DEV_ID_I225_V)  },
26         { RTE_PCI_DEVICE(IGC_INTEL_VENDOR_ID, IGC_DEV_ID_I225_I)  },
27         { RTE_PCI_DEVICE(IGC_INTEL_VENDOR_ID, IGC_DEV_ID_I225_K)  },
28         { .vendor_id = 0, /* sentinel */ },
29 };
30
31 static int eth_igc_configure(struct rte_eth_dev *dev);
32 static int eth_igc_link_update(struct rte_eth_dev *dev, int wait_to_complete);
33 static void eth_igc_stop(struct rte_eth_dev *dev);
34 static int eth_igc_start(struct rte_eth_dev *dev);
35 static void eth_igc_close(struct rte_eth_dev *dev);
36 static int eth_igc_reset(struct rte_eth_dev *dev);
37 static int eth_igc_promiscuous_enable(struct rte_eth_dev *dev);
38 static int eth_igc_promiscuous_disable(struct rte_eth_dev *dev);
39 static int eth_igc_infos_get(struct rte_eth_dev *dev,
40                         struct rte_eth_dev_info *dev_info);
41 static int
42 eth_igc_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
43                 uint16_t nb_rx_desc, unsigned int socket_id,
44                 const struct rte_eth_rxconf *rx_conf,
45                 struct rte_mempool *mb_pool);
46 static int
47 eth_igc_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
48                 uint16_t nb_desc, unsigned int socket_id,
49                 const struct rte_eth_txconf *tx_conf);
50
51 static const struct eth_dev_ops eth_igc_ops = {
52         .dev_configure          = eth_igc_configure,
53         .link_update            = eth_igc_link_update,
54         .dev_stop               = eth_igc_stop,
55         .dev_start              = eth_igc_start,
56         .dev_close              = eth_igc_close,
57         .dev_reset              = eth_igc_reset,
58         .promiscuous_enable     = eth_igc_promiscuous_enable,
59         .promiscuous_disable    = eth_igc_promiscuous_disable,
60         .dev_infos_get          = eth_igc_infos_get,
61         .rx_queue_setup         = eth_igc_rx_queue_setup,
62         .tx_queue_setup         = eth_igc_tx_queue_setup,
63 };
64
65 static int
66 eth_igc_configure(struct rte_eth_dev *dev)
67 {
68         PMD_INIT_FUNC_TRACE();
69         RTE_SET_USED(dev);
70         return 0;
71 }
72
73 static int
74 eth_igc_link_update(struct rte_eth_dev *dev, int wait_to_complete)
75 {
76         PMD_INIT_FUNC_TRACE();
77         RTE_SET_USED(dev);
78         RTE_SET_USED(wait_to_complete);
79         return 0;
80 }
81
82 static void
83 eth_igc_stop(struct rte_eth_dev *dev)
84 {
85         PMD_INIT_FUNC_TRACE();
86         RTE_SET_USED(dev);
87 }
88
89 static int
90 eth_igc_start(struct rte_eth_dev *dev)
91 {
92         PMD_INIT_FUNC_TRACE();
93         RTE_SET_USED(dev);
94         return 0;
95 }
96
97 static void
98 eth_igc_close(struct rte_eth_dev *dev)
99 {
100         PMD_INIT_FUNC_TRACE();
101          RTE_SET_USED(dev);
102 }
103
104 static int
105 eth_igc_dev_init(struct rte_eth_dev *dev)
106 {
107         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
108
109         PMD_INIT_FUNC_TRACE();
110         dev->dev_ops = &eth_igc_ops;
111
112         /*
113          * for secondary processes, we don't initialize any further as primary
114          * has already done this work. Only check we don't need a different
115          * RX function.
116          */
117         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
118                 return 0;
119
120         dev->data->mac_addrs = rte_zmalloc("igc",
121                 RTE_ETHER_ADDR_LEN, 0);
122         if (dev->data->mac_addrs == NULL) {
123                 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes for storing MAC",
124                                 RTE_ETHER_ADDR_LEN);
125                 return -ENOMEM;
126         }
127
128         /* Pass the information to the rte_eth_dev_close() that it should also
129          * release the private port resources.
130          */
131         dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
132
133         PMD_INIT_LOG(DEBUG, "port_id %d vendorID=0x%x deviceID=0x%x",
134                         dev->data->port_id, pci_dev->id.vendor_id,
135                         pci_dev->id.device_id);
136
137         return 0;
138 }
139
140 static int
141 eth_igc_dev_uninit(__rte_unused struct rte_eth_dev *eth_dev)
142 {
143         PMD_INIT_FUNC_TRACE();
144
145         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
146                 return 0;
147
148         eth_igc_close(eth_dev);
149         return 0;
150 }
151
152 static int
153 eth_igc_reset(struct rte_eth_dev *dev)
154 {
155         int ret;
156
157         PMD_INIT_FUNC_TRACE();
158
159         ret = eth_igc_dev_uninit(dev);
160         if (ret)
161                 return ret;
162
163         return eth_igc_dev_init(dev);
164 }
165
166 static int
167 eth_igc_promiscuous_enable(struct rte_eth_dev *dev)
168 {
169         PMD_INIT_FUNC_TRACE();
170         RTE_SET_USED(dev);
171         return 0;
172 }
173
174 static int
175 eth_igc_promiscuous_disable(struct rte_eth_dev *dev)
176 {
177         PMD_INIT_FUNC_TRACE();
178         RTE_SET_USED(dev);
179         return 0;
180 }
181
182 static int
183 eth_igc_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
184 {
185         PMD_INIT_FUNC_TRACE();
186         RTE_SET_USED(dev);
187         dev_info->max_rx_queues = IGC_QUEUE_PAIRS_NUM;
188         dev_info->max_tx_queues = IGC_QUEUE_PAIRS_NUM;
189         return 0;
190 }
191
192 static int
193 eth_igc_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
194                 uint16_t nb_rx_desc, unsigned int socket_id,
195                 const struct rte_eth_rxconf *rx_conf,
196                 struct rte_mempool *mb_pool)
197 {
198         PMD_INIT_FUNC_TRACE();
199         RTE_SET_USED(dev);
200         RTE_SET_USED(rx_queue_id);
201         RTE_SET_USED(nb_rx_desc);
202         RTE_SET_USED(socket_id);
203         RTE_SET_USED(rx_conf);
204         RTE_SET_USED(mb_pool);
205         return 0;
206 }
207
208 static int
209 eth_igc_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
210                 uint16_t nb_desc, unsigned int socket_id,
211                 const struct rte_eth_txconf *tx_conf)
212 {
213         PMD_INIT_FUNC_TRACE();
214         RTE_SET_USED(dev);
215         RTE_SET_USED(queue_idx);
216         RTE_SET_USED(nb_desc);
217         RTE_SET_USED(socket_id);
218         RTE_SET_USED(tx_conf);
219         return 0;
220 }
221
222 static int
223 eth_igc_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
224         struct rte_pci_device *pci_dev)
225 {
226         PMD_INIT_FUNC_TRACE();
227         return rte_eth_dev_pci_generic_probe(pci_dev, 0, eth_igc_dev_init);
228 }
229
230 static int
231 eth_igc_pci_remove(struct rte_pci_device *pci_dev)
232 {
233         PMD_INIT_FUNC_TRACE();
234         return rte_eth_dev_pci_generic_remove(pci_dev, eth_igc_dev_uninit);
235 }
236
237 static struct rte_pci_driver rte_igc_pmd = {
238         .id_table = pci_id_igc_map,
239         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
240         .probe = eth_igc_pci_probe,
241         .remove = eth_igc_pci_remove,
242 };
243
244 RTE_PMD_REGISTER_PCI(net_igc, rte_igc_pmd);
245 RTE_PMD_REGISTER_PCI_TABLE(net_igc, pci_id_igc_map);
246 RTE_PMD_REGISTER_KMOD_DEP(net_igc, "* igb_uio | uio_pci_generic | vfio-pci");