net/ice: complete device configure in DCF
[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 #include "ice_rxtx.h"
28
29 static uint16_t
30 ice_dcf_recv_pkts(__rte_unused void *rx_queue,
31                   __rte_unused struct rte_mbuf **bufs,
32                   __rte_unused uint16_t nb_pkts)
33 {
34         return 0;
35 }
36
37 static uint16_t
38 ice_dcf_xmit_pkts(__rte_unused void *tx_queue,
39                   __rte_unused struct rte_mbuf **bufs,
40                   __rte_unused uint16_t nb_pkts)
41 {
42         return 0;
43 }
44
45 static int
46 ice_dcf_dev_start(struct rte_eth_dev *dev)
47 {
48         dev->data->dev_link.link_status = ETH_LINK_UP;
49
50         return 0;
51 }
52
53 static void
54 ice_dcf_dev_stop(struct rte_eth_dev *dev)
55 {
56         dev->data->dev_link.link_status = ETH_LINK_DOWN;
57 }
58
59 static int
60 ice_dcf_dev_configure(struct rte_eth_dev *dev)
61 {
62         struct ice_dcf_adapter *dcf_ad = dev->data->dev_private;
63         struct ice_adapter *ad = &dcf_ad->parent;
64
65         ad->rx_bulk_alloc_allowed = true;
66         ad->tx_simple_allowed = true;
67
68         if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
69                 dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
70
71         return 0;
72 }
73
74 static int
75 ice_dcf_dev_info_get(struct rte_eth_dev *dev,
76                      struct rte_eth_dev_info *dev_info)
77 {
78         struct ice_dcf_adapter *adapter = dev->data->dev_private;
79         struct ice_dcf_hw *hw = &adapter->real_hw;
80
81         dev_info->max_mac_addrs = 1;
82         dev_info->max_rx_queues = hw->vsi_res->num_queue_pairs;
83         dev_info->max_tx_queues = hw->vsi_res->num_queue_pairs;
84         dev_info->min_rx_bufsize = ICE_BUF_SIZE_MIN;
85         dev_info->max_rx_pktlen = ICE_FRAME_SIZE_MAX;
86         dev_info->hash_key_size = hw->vf_res->rss_key_size;
87         dev_info->reta_size = hw->vf_res->rss_lut_size;
88         dev_info->flow_type_rss_offloads = ICE_RSS_OFFLOAD_ALL;
89
90         dev_info->rx_offload_capa =
91                 DEV_RX_OFFLOAD_VLAN_STRIP |
92                 DEV_RX_OFFLOAD_IPV4_CKSUM |
93                 DEV_RX_OFFLOAD_UDP_CKSUM |
94                 DEV_RX_OFFLOAD_TCP_CKSUM |
95                 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
96                 DEV_RX_OFFLOAD_SCATTER |
97                 DEV_RX_OFFLOAD_JUMBO_FRAME |
98                 DEV_RX_OFFLOAD_VLAN_FILTER |
99                 DEV_RX_OFFLOAD_RSS_HASH;
100         dev_info->tx_offload_capa =
101                 DEV_TX_OFFLOAD_VLAN_INSERT |
102                 DEV_TX_OFFLOAD_IPV4_CKSUM |
103                 DEV_TX_OFFLOAD_UDP_CKSUM |
104                 DEV_TX_OFFLOAD_TCP_CKSUM |
105                 DEV_TX_OFFLOAD_SCTP_CKSUM |
106                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
107                 DEV_TX_OFFLOAD_TCP_TSO |
108                 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
109                 DEV_TX_OFFLOAD_GRE_TNL_TSO |
110                 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
111                 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
112                 DEV_TX_OFFLOAD_MULTI_SEGS;
113
114         dev_info->default_rxconf = (struct rte_eth_rxconf) {
115                 .rx_thresh = {
116                         .pthresh = ICE_DEFAULT_RX_PTHRESH,
117                         .hthresh = ICE_DEFAULT_RX_HTHRESH,
118                         .wthresh = ICE_DEFAULT_RX_WTHRESH,
119                 },
120                 .rx_free_thresh = ICE_DEFAULT_RX_FREE_THRESH,
121                 .rx_drop_en = 0,
122                 .offloads = 0,
123         };
124
125         dev_info->default_txconf = (struct rte_eth_txconf) {
126                 .tx_thresh = {
127                         .pthresh = ICE_DEFAULT_TX_PTHRESH,
128                         .hthresh = ICE_DEFAULT_TX_HTHRESH,
129                         .wthresh = ICE_DEFAULT_TX_WTHRESH,
130                 },
131                 .tx_free_thresh = ICE_DEFAULT_TX_FREE_THRESH,
132                 .tx_rs_thresh = ICE_DEFAULT_TX_RSBIT_THRESH,
133                 .offloads = 0,
134         };
135
136         dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
137                 .nb_max = ICE_MAX_RING_DESC,
138                 .nb_min = ICE_MIN_RING_DESC,
139                 .nb_align = ICE_ALIGN_RING_DESC,
140         };
141
142         dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
143                 .nb_max = ICE_MAX_RING_DESC,
144                 .nb_min = ICE_MIN_RING_DESC,
145                 .nb_align = ICE_ALIGN_RING_DESC,
146         };
147
148         return 0;
149 }
150
151 static int
152 ice_dcf_stats_get(__rte_unused struct rte_eth_dev *dev,
153                   __rte_unused struct rte_eth_stats *igb_stats)
154 {
155         return 0;
156 }
157
158 static int
159 ice_dcf_stats_reset(__rte_unused struct rte_eth_dev *dev)
160 {
161         return 0;
162 }
163
164 static int
165 ice_dcf_dev_promiscuous_enable(__rte_unused struct rte_eth_dev *dev)
166 {
167         return 0;
168 }
169
170 static int
171 ice_dcf_dev_promiscuous_disable(__rte_unused struct rte_eth_dev *dev)
172 {
173         return 0;
174 }
175
176 static int
177 ice_dcf_dev_allmulticast_enable(__rte_unused struct rte_eth_dev *dev)
178 {
179         return 0;
180 }
181
182 static int
183 ice_dcf_dev_allmulticast_disable(__rte_unused struct rte_eth_dev *dev)
184 {
185         return 0;
186 }
187
188 static int
189 ice_dcf_dev_filter_ctrl(struct rte_eth_dev *dev,
190                         enum rte_filter_type filter_type,
191                         enum rte_filter_op filter_op,
192                         void *arg)
193 {
194         int ret = 0;
195
196         if (!dev)
197                 return -EINVAL;
198
199         switch (filter_type) {
200         case RTE_ETH_FILTER_GENERIC:
201                 if (filter_op != RTE_ETH_FILTER_GET)
202                         return -EINVAL;
203                 *(const void **)arg = &ice_flow_ops;
204                 break;
205
206         default:
207                 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
208                             filter_type);
209                 ret = -EINVAL;
210                 break;
211         }
212
213         return ret;
214 }
215
216 static void
217 ice_dcf_dev_close(struct rte_eth_dev *dev)
218 {
219         struct ice_dcf_adapter *adapter = dev->data->dev_private;
220
221         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
222                 return;
223
224         dev->dev_ops = NULL;
225         dev->rx_pkt_burst = NULL;
226         dev->tx_pkt_burst = NULL;
227
228         ice_dcf_uninit_parent_adapter(dev);
229         ice_dcf_uninit_hw(dev, &adapter->real_hw);
230 }
231
232 static void
233 ice_dcf_queue_release(__rte_unused void *q)
234 {
235 }
236
237 static int
238 ice_dcf_link_update(__rte_unused struct rte_eth_dev *dev,
239                     __rte_unused int wait_to_complete)
240 {
241         return 0;
242 }
243
244 static int
245 ice_dcf_rx_queue_setup(struct rte_eth_dev *dev,
246                        uint16_t rx_queue_id,
247                        __rte_unused uint16_t nb_rx_desc,
248                        __rte_unused unsigned int socket_id,
249                        __rte_unused const struct rte_eth_rxconf *rx_conf,
250                        __rte_unused struct rte_mempool *mb_pool)
251 {
252         struct ice_dcf_adapter *adapter = dev->data->dev_private;
253
254         dev->data->rx_queues[rx_queue_id] = &adapter->rxqs[rx_queue_id];
255
256         return 0;
257 }
258
259 static int
260 ice_dcf_tx_queue_setup(struct rte_eth_dev *dev,
261                        uint16_t tx_queue_id,
262                        __rte_unused uint16_t nb_tx_desc,
263                        __rte_unused unsigned int socket_id,
264                        __rte_unused const struct rte_eth_txconf *tx_conf)
265 {
266         struct ice_dcf_adapter *adapter = dev->data->dev_private;
267
268         dev->data->tx_queues[tx_queue_id] = &adapter->txqs[tx_queue_id];
269
270         return 0;
271 }
272
273 static const struct eth_dev_ops ice_dcf_eth_dev_ops = {
274         .dev_start               = ice_dcf_dev_start,
275         .dev_stop                = ice_dcf_dev_stop,
276         .dev_close               = ice_dcf_dev_close,
277         .dev_configure           = ice_dcf_dev_configure,
278         .dev_infos_get           = ice_dcf_dev_info_get,
279         .rx_queue_setup          = ice_dcf_rx_queue_setup,
280         .tx_queue_setup          = ice_dcf_tx_queue_setup,
281         .rx_queue_release        = ice_dcf_queue_release,
282         .tx_queue_release        = ice_dcf_queue_release,
283         .link_update             = ice_dcf_link_update,
284         .stats_get               = ice_dcf_stats_get,
285         .stats_reset             = ice_dcf_stats_reset,
286         .promiscuous_enable      = ice_dcf_dev_promiscuous_enable,
287         .promiscuous_disable     = ice_dcf_dev_promiscuous_disable,
288         .allmulticast_enable     = ice_dcf_dev_allmulticast_enable,
289         .allmulticast_disable    = ice_dcf_dev_allmulticast_disable,
290         .filter_ctrl             = ice_dcf_dev_filter_ctrl,
291 };
292
293 static int
294 ice_dcf_dev_init(struct rte_eth_dev *eth_dev)
295 {
296         struct ice_dcf_adapter *adapter = eth_dev->data->dev_private;
297
298         eth_dev->dev_ops = &ice_dcf_eth_dev_ops;
299         eth_dev->rx_pkt_burst = ice_dcf_recv_pkts;
300         eth_dev->tx_pkt_burst = ice_dcf_xmit_pkts;
301
302         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
303                 return 0;
304
305         eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
306
307         adapter->real_hw.vc_event_msg_cb = ice_dcf_handle_pf_event_msg;
308         if (ice_dcf_init_hw(eth_dev, &adapter->real_hw) != 0) {
309                 PMD_INIT_LOG(ERR, "Failed to init DCF hardware");
310                 return -1;
311         }
312
313         if (ice_dcf_init_parent_adapter(eth_dev) != 0) {
314                 PMD_INIT_LOG(ERR, "Failed to init DCF parent adapter");
315                 ice_dcf_uninit_hw(eth_dev, &adapter->real_hw);
316                 return -1;
317         }
318
319         return 0;
320 }
321
322 static int
323 ice_dcf_dev_uninit(struct rte_eth_dev *eth_dev)
324 {
325         ice_dcf_dev_close(eth_dev);
326
327         return 0;
328 }
329
330 static int
331 ice_dcf_cap_check_handler(__rte_unused const char *key,
332                           const char *value, __rte_unused void *opaque)
333 {
334         if (strcmp(value, "dcf"))
335                 return -1;
336
337         return 0;
338 }
339
340 static int
341 ice_dcf_cap_selected(struct rte_devargs *devargs)
342 {
343         struct rte_kvargs *kvlist;
344         const char *key = "cap";
345         int ret = 0;
346
347         if (devargs == NULL)
348                 return 0;
349
350         kvlist = rte_kvargs_parse(devargs->args, NULL);
351         if (kvlist == NULL)
352                 return 0;
353
354         if (!rte_kvargs_count(kvlist, key))
355                 goto exit;
356
357         /* dcf capability selected when there's a key-value pair: cap=dcf */
358         if (rte_kvargs_process(kvlist, key,
359                                ice_dcf_cap_check_handler, NULL) < 0)
360                 goto exit;
361
362         ret = 1;
363
364 exit:
365         rte_kvargs_free(kvlist);
366         return ret;
367 }
368
369 static int eth_ice_dcf_pci_probe(__rte_unused struct rte_pci_driver *pci_drv,
370                              struct rte_pci_device *pci_dev)
371 {
372         if (!ice_dcf_cap_selected(pci_dev->device.devargs))
373                 return 1;
374
375         return rte_eth_dev_pci_generic_probe(pci_dev,
376                                              sizeof(struct ice_dcf_adapter),
377                                              ice_dcf_dev_init);
378 }
379
380 static int eth_ice_dcf_pci_remove(struct rte_pci_device *pci_dev)
381 {
382         return rte_eth_dev_pci_generic_remove(pci_dev, ice_dcf_dev_uninit);
383 }
384
385 static const struct rte_pci_id pci_id_ice_dcf_map[] = {
386         { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_ADAPTIVE_VF) },
387         { .vendor_id = 0, /* sentinel */ },
388 };
389
390 static struct rte_pci_driver rte_ice_dcf_pmd = {
391         .id_table = pci_id_ice_dcf_map,
392         .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
393         .probe = eth_ice_dcf_pci_probe,
394         .remove = eth_ice_dcf_pci_remove,
395 };
396
397 RTE_PMD_REGISTER_PCI(net_ice_dcf, rte_ice_dcf_pmd);
398 RTE_PMD_REGISTER_PCI_TABLE(net_ice_dcf, pci_id_ice_dcf_map);
399 RTE_PMD_REGISTER_KMOD_DEP(net_ice_dcf, "* igb_uio | vfio-pci");
400 RTE_PMD_REGISTER_PARAM_STRING(net_ice_dcf, "cap=dcf");