af94caeff752fdddd59f7dae385d6b697431b648
[dpdk.git] / drivers / net / ice / ice_dcf_ethdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Intel Corporation
3  */
4
5 #include <errno.h>
6 #include <stdbool.h>
7 #include <sys/types.h>
8 #include <sys/ioctl.h>
9 #include <unistd.h>
10
11 #include <rte_interrupts.h>
12 #include <rte_debug.h>
13 #include <rte_pci.h>
14 #include <rte_atomic.h>
15 #include <rte_eal.h>
16 #include <rte_ether.h>
17 #include <rte_ethdev_pci.h>
18 #include <rte_kvargs.h>
19 #include <rte_malloc.h>
20 #include <rte_memzone.h>
21 #include <rte_dev.h>
22
23 #include <iavf_devids.h>
24
25 #include "ice_generic_flow.h"
26 #include "ice_dcf_ethdev.h"
27
28 static uint16_t
29 ice_dcf_recv_pkts(__rte_unused void *rx_queue,
30                   __rte_unused struct rte_mbuf **bufs,
31                   __rte_unused uint16_t nb_pkts)
32 {
33         return 0;
34 }
35
36 static uint16_t
37 ice_dcf_xmit_pkts(__rte_unused void *tx_queue,
38                   __rte_unused struct rte_mbuf **bufs,
39                   __rte_unused uint16_t nb_pkts)
40 {
41         return 0;
42 }
43
44 static int
45 ice_dcf_dev_start(struct rte_eth_dev *dev)
46 {
47         dev->data->dev_link.link_status = ETH_LINK_UP;
48
49         return 0;
50 }
51
52 static void
53 ice_dcf_dev_stop(struct rte_eth_dev *dev)
54 {
55         dev->data->dev_link.link_status = ETH_LINK_DOWN;
56 }
57
58 static int
59 ice_dcf_dev_configure(__rte_unused struct rte_eth_dev *dev)
60 {
61         return 0;
62 }
63
64 static int
65 ice_dcf_dev_info_get(struct rte_eth_dev *dev,
66                      struct rte_eth_dev_info *dev_info)
67 {
68         struct ice_dcf_adapter *adapter = dev->data->dev_private;
69
70         dev_info->max_mac_addrs = 1;
71         dev_info->max_rx_pktlen = (uint32_t)-1;
72         dev_info->max_rx_queues = RTE_DIM(adapter->rxqs);
73         dev_info->max_tx_queues = RTE_DIM(adapter->txqs);
74
75         return 0;
76 }
77
78 static int
79 ice_dcf_stats_get(__rte_unused struct rte_eth_dev *dev,
80                   __rte_unused struct rte_eth_stats *igb_stats)
81 {
82         return 0;
83 }
84
85 static int
86 ice_dcf_stats_reset(__rte_unused struct rte_eth_dev *dev)
87 {
88         return 0;
89 }
90
91 static int
92 ice_dcf_dev_promiscuous_enable(__rte_unused struct rte_eth_dev *dev)
93 {
94         return 0;
95 }
96
97 static int
98 ice_dcf_dev_promiscuous_disable(__rte_unused struct rte_eth_dev *dev)
99 {
100         return 0;
101 }
102
103 static int
104 ice_dcf_dev_allmulticast_enable(__rte_unused struct rte_eth_dev *dev)
105 {
106         return 0;
107 }
108
109 static int
110 ice_dcf_dev_allmulticast_disable(__rte_unused struct rte_eth_dev *dev)
111 {
112         return 0;
113 }
114
115 static int
116 ice_dcf_dev_filter_ctrl(struct rte_eth_dev *dev,
117                         enum rte_filter_type filter_type,
118                         __rte_unused enum rte_filter_op filter_op,
119                         __rte_unused void *arg)
120 {
121         int ret = 0;
122
123         if (!dev)
124                 return -EINVAL;
125
126         switch (filter_type) {
127         default:
128                 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
129                             filter_type);
130                 ret = -EINVAL;
131                 break;
132         }
133
134         return ret;
135 }
136
137 static void
138 ice_dcf_dev_close(struct rte_eth_dev *dev)
139 {
140         struct ice_dcf_adapter *adapter = dev->data->dev_private;
141
142         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
143                 return;
144
145         dev->dev_ops = NULL;
146         dev->rx_pkt_burst = NULL;
147         dev->tx_pkt_burst = NULL;
148
149         ice_dcf_uninit_parent_adapter(dev);
150         ice_dcf_uninit_hw(dev, &adapter->real_hw);
151 }
152
153 static void
154 ice_dcf_queue_release(__rte_unused void *q)
155 {
156 }
157
158 static int
159 ice_dcf_link_update(__rte_unused struct rte_eth_dev *dev,
160                     __rte_unused int wait_to_complete)
161 {
162         return 0;
163 }
164
165 static int
166 ice_dcf_rx_queue_setup(struct rte_eth_dev *dev,
167                        uint16_t rx_queue_id,
168                        __rte_unused uint16_t nb_rx_desc,
169                        __rte_unused unsigned int socket_id,
170                        __rte_unused const struct rte_eth_rxconf *rx_conf,
171                        __rte_unused struct rte_mempool *mb_pool)
172 {
173         struct ice_dcf_adapter *adapter = dev->data->dev_private;
174
175         dev->data->rx_queues[rx_queue_id] = &adapter->rxqs[rx_queue_id];
176
177         return 0;
178 }
179
180 static int
181 ice_dcf_tx_queue_setup(struct rte_eth_dev *dev,
182                        uint16_t tx_queue_id,
183                        __rte_unused uint16_t nb_tx_desc,
184                        __rte_unused unsigned int socket_id,
185                        __rte_unused const struct rte_eth_txconf *tx_conf)
186 {
187         struct ice_dcf_adapter *adapter = dev->data->dev_private;
188
189         dev->data->tx_queues[tx_queue_id] = &adapter->txqs[tx_queue_id];
190
191         return 0;
192 }
193
194 static const struct eth_dev_ops ice_dcf_eth_dev_ops = {
195         .dev_start               = ice_dcf_dev_start,
196         .dev_stop                = ice_dcf_dev_stop,
197         .dev_close               = ice_dcf_dev_close,
198         .dev_configure           = ice_dcf_dev_configure,
199         .dev_infos_get           = ice_dcf_dev_info_get,
200         .rx_queue_setup          = ice_dcf_rx_queue_setup,
201         .tx_queue_setup          = ice_dcf_tx_queue_setup,
202         .rx_queue_release        = ice_dcf_queue_release,
203         .tx_queue_release        = ice_dcf_queue_release,
204         .link_update             = ice_dcf_link_update,
205         .stats_get               = ice_dcf_stats_get,
206         .stats_reset             = ice_dcf_stats_reset,
207         .promiscuous_enable      = ice_dcf_dev_promiscuous_enable,
208         .promiscuous_disable     = ice_dcf_dev_promiscuous_disable,
209         .allmulticast_enable     = ice_dcf_dev_allmulticast_enable,
210         .allmulticast_disable    = ice_dcf_dev_allmulticast_disable,
211         .filter_ctrl             = ice_dcf_dev_filter_ctrl,
212 };
213
214 static int
215 ice_dcf_dev_init(struct rte_eth_dev *eth_dev)
216 {
217         struct ice_dcf_adapter *adapter = eth_dev->data->dev_private;
218
219         eth_dev->dev_ops = &ice_dcf_eth_dev_ops;
220         eth_dev->rx_pkt_burst = ice_dcf_recv_pkts;
221         eth_dev->tx_pkt_burst = ice_dcf_xmit_pkts;
222
223         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
224                 return 0;
225
226         eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
227
228         adapter->real_hw.vc_event_msg_cb = ice_dcf_handle_pf_event_msg;
229         if (ice_dcf_init_hw(eth_dev, &adapter->real_hw) != 0) {
230                 PMD_INIT_LOG(ERR, "Failed to init DCF hardware");
231                 return -1;
232         }
233
234         if (ice_dcf_init_parent_adapter(eth_dev) != 0) {
235                 PMD_INIT_LOG(ERR, "Failed to init DCF parent adapter");
236                 ice_dcf_uninit_hw(eth_dev, &adapter->real_hw);
237                 return -1;
238         }
239
240         return 0;
241 }
242
243 static int
244 ice_dcf_dev_uninit(struct rte_eth_dev *eth_dev)
245 {
246         ice_dcf_dev_close(eth_dev);
247
248         return 0;
249 }
250
251 static int
252 ice_dcf_cap_check_handler(__rte_unused const char *key,
253                           const char *value, __rte_unused void *opaque)
254 {
255         if (strcmp(value, "dcf"))
256                 return -1;
257
258         return 0;
259 }
260
261 static int
262 ice_dcf_cap_selected(struct rte_devargs *devargs)
263 {
264         struct rte_kvargs *kvlist;
265         const char *key = "cap";
266         int ret = 0;
267
268         if (devargs == NULL)
269                 return 0;
270
271         kvlist = rte_kvargs_parse(devargs->args, NULL);
272         if (kvlist == NULL)
273                 return 0;
274
275         if (!rte_kvargs_count(kvlist, key))
276                 goto exit;
277
278         /* dcf capability selected when there's a key-value pair: cap=dcf */
279         if (rte_kvargs_process(kvlist, key,
280                                ice_dcf_cap_check_handler, NULL) < 0)
281                 goto exit;
282
283         ret = 1;
284
285 exit:
286         rte_kvargs_free(kvlist);
287         return ret;
288 }
289
290 static int eth_ice_dcf_pci_probe(__rte_unused struct rte_pci_driver *pci_drv,
291                              struct rte_pci_device *pci_dev)
292 {
293         if (!ice_dcf_cap_selected(pci_dev->device.devargs))
294                 return 1;
295
296         return rte_eth_dev_pci_generic_probe(pci_dev,
297                                              sizeof(struct ice_dcf_adapter),
298                                              ice_dcf_dev_init);
299 }
300
301 static int eth_ice_dcf_pci_remove(struct rte_pci_device *pci_dev)
302 {
303         return rte_eth_dev_pci_generic_remove(pci_dev, ice_dcf_dev_uninit);
304 }
305
306 static const struct rte_pci_id pci_id_ice_dcf_map[] = {
307         { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_ADAPTIVE_VF) },
308         { .vendor_id = 0, /* sentinel */ },
309 };
310
311 static struct rte_pci_driver rte_ice_dcf_pmd = {
312         .id_table = pci_id_ice_dcf_map,
313         .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
314         .probe = eth_ice_dcf_pci_probe,
315         .remove = eth_ice_dcf_pci_remove,
316 };
317
318 RTE_PMD_REGISTER_PCI(net_ice_dcf, rte_ice_dcf_pmd);
319 RTE_PMD_REGISTER_PCI_TABLE(net_ice_dcf, pci_id_ice_dcf_map);
320 RTE_PMD_REGISTER_KMOD_DEP(net_ice_dcf, "* igb_uio | vfio-pci");
321 RTE_PMD_REGISTER_PARAM_STRING(net_ice_dcf, "cap=dcf");