Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2023 Intel Corporation
3 : : */
4 : :
5 : : #include <rte_atomic.h>
6 : : #include <rte_eal.h>
7 : : #include <rte_ether.h>
8 : : #include <rte_malloc.h>
9 : : #include <rte_memzone.h>
10 : : #include <rte_dev.h>
11 : : #include <errno.h>
12 : : #include <rte_alarm.h>
13 : : #include <rte_hash_crc.h>
14 : :
15 : : #include "cpfl_ethdev.h"
16 : : #include <ethdev_private.h>
17 : : #include "cpfl_rxtx.h"
18 : : #include "cpfl_flow.h"
19 : : #include "cpfl_rules.h"
20 : :
21 : : #define CPFL_REPRESENTOR "representor"
22 : : #define CPFL_TX_SINGLE_Q "tx_single"
23 : : #define CPFL_RX_SINGLE_Q "rx_single"
24 : : #define CPFL_VPORT "vport"
25 : :
26 : : #ifdef RTE_HAS_JANSSON
27 : : #define CPFL_FLOW_PARSER "flow_parser"
28 : : #endif
29 : :
30 : : rte_spinlock_t cpfl_adapter_lock;
31 : : /* A list for all adapters, one adapter matches one PCI device */
32 : : struct cpfl_adapter_list cpfl_adapter_list;
33 : : bool cpfl_adapter_list_init;
34 : :
35 : : static const char * const cpfl_valid_args_first[] = {
36 : : CPFL_REPRESENTOR,
37 : : CPFL_TX_SINGLE_Q,
38 : : CPFL_RX_SINGLE_Q,
39 : : CPFL_VPORT,
40 : : #ifdef RTE_HAS_JANSSON
41 : : CPFL_FLOW_PARSER,
42 : : #endif
43 : : NULL
44 : : };
45 : :
46 : : static const char * const cpfl_valid_args_again[] = {
47 : : CPFL_REPRESENTOR,
48 : : NULL
49 : : };
50 : :
51 : : uint32_t cpfl_supported_speeds[] = {
52 : : RTE_ETH_SPEED_NUM_NONE,
53 : : RTE_ETH_SPEED_NUM_10M,
54 : : RTE_ETH_SPEED_NUM_100M,
55 : : RTE_ETH_SPEED_NUM_1G,
56 : : RTE_ETH_SPEED_NUM_2_5G,
57 : : RTE_ETH_SPEED_NUM_5G,
58 : : RTE_ETH_SPEED_NUM_10G,
59 : : RTE_ETH_SPEED_NUM_20G,
60 : : RTE_ETH_SPEED_NUM_25G,
61 : : RTE_ETH_SPEED_NUM_40G,
62 : : RTE_ETH_SPEED_NUM_50G,
63 : : RTE_ETH_SPEED_NUM_56G,
64 : : RTE_ETH_SPEED_NUM_100G,
65 : : RTE_ETH_SPEED_NUM_200G
66 : : };
67 : :
68 : : static const uint64_t cpfl_map_hena_rss[] = {
69 : : [IDPF_HASH_NONF_UNICAST_IPV4_UDP] =
70 : : RTE_ETH_RSS_NONFRAG_IPV4_UDP,
71 : : [IDPF_HASH_NONF_MULTICAST_IPV4_UDP] =
72 : : RTE_ETH_RSS_NONFRAG_IPV4_UDP,
73 : : [IDPF_HASH_NONF_IPV4_UDP] =
74 : : RTE_ETH_RSS_NONFRAG_IPV4_UDP,
75 : : [IDPF_HASH_NONF_IPV4_TCP_SYN_NO_ACK] =
76 : : RTE_ETH_RSS_NONFRAG_IPV4_TCP,
77 : : [IDPF_HASH_NONF_IPV4_TCP] =
78 : : RTE_ETH_RSS_NONFRAG_IPV4_TCP,
79 : : [IDPF_HASH_NONF_IPV4_SCTP] =
80 : : RTE_ETH_RSS_NONFRAG_IPV4_SCTP,
81 : : [IDPF_HASH_NONF_IPV4_OTHER] =
82 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER,
83 : : [IDPF_HASH_FRAG_IPV4] = RTE_ETH_RSS_FRAG_IPV4,
84 : :
85 : : /* IPv6 */
86 : : [IDPF_HASH_NONF_UNICAST_IPV6_UDP] =
87 : : RTE_ETH_RSS_NONFRAG_IPV6_UDP,
88 : : [IDPF_HASH_NONF_MULTICAST_IPV6_UDP] =
89 : : RTE_ETH_RSS_NONFRAG_IPV6_UDP,
90 : : [IDPF_HASH_NONF_IPV6_UDP] =
91 : : RTE_ETH_RSS_NONFRAG_IPV6_UDP,
92 : : [IDPF_HASH_NONF_IPV6_TCP_SYN_NO_ACK] =
93 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP,
94 : : [IDPF_HASH_NONF_IPV6_TCP] =
95 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP,
96 : : [IDPF_HASH_NONF_IPV6_SCTP] =
97 : : RTE_ETH_RSS_NONFRAG_IPV6_SCTP,
98 : : [IDPF_HASH_NONF_IPV6_OTHER] =
99 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER,
100 : : [IDPF_HASH_FRAG_IPV6] = RTE_ETH_RSS_FRAG_IPV6,
101 : :
102 : : /* L2 Payload */
103 : : [IDPF_HASH_L2_PAYLOAD] = RTE_ETH_RSS_L2_PAYLOAD
104 : : };
105 : :
106 : : static const uint64_t cpfl_ipv4_rss = RTE_ETH_RSS_NONFRAG_IPV4_UDP |
107 : : RTE_ETH_RSS_NONFRAG_IPV4_TCP |
108 : : RTE_ETH_RSS_NONFRAG_IPV4_SCTP |
109 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER |
110 : : RTE_ETH_RSS_FRAG_IPV4;
111 : :
112 : : static const uint64_t cpfl_ipv6_rss = RTE_ETH_RSS_NONFRAG_IPV6_UDP |
113 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP |
114 : : RTE_ETH_RSS_NONFRAG_IPV6_SCTP |
115 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER |
116 : : RTE_ETH_RSS_FRAG_IPV6;
117 : :
118 : : struct rte_cpfl_xstats_name_off {
119 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
120 : : unsigned int offset;
121 : : };
122 : :
123 : : static const struct rte_cpfl_xstats_name_off rte_cpfl_stats_strings[] = {
124 : : {"rx_bytes", offsetof(struct virtchnl2_vport_stats, rx_bytes)},
125 : : {"rx_unicast_packets", offsetof(struct virtchnl2_vport_stats, rx_unicast)},
126 : : {"rx_multicast_packets", offsetof(struct virtchnl2_vport_stats, rx_multicast)},
127 : : {"rx_broadcast_packets", offsetof(struct virtchnl2_vport_stats, rx_broadcast)},
128 : : {"rx_dropped_packets", offsetof(struct virtchnl2_vport_stats, rx_discards)},
129 : : {"rx_errors", offsetof(struct virtchnl2_vport_stats, rx_errors)},
130 : : {"rx_unknown_protocol_packets", offsetof(struct virtchnl2_vport_stats,
131 : : rx_unknown_protocol)},
132 : : {"tx_bytes", offsetof(struct virtchnl2_vport_stats, tx_bytes)},
133 : : {"tx_unicast_packets", offsetof(struct virtchnl2_vport_stats, tx_unicast)},
134 : : {"tx_multicast_packets", offsetof(struct virtchnl2_vport_stats, tx_multicast)},
135 : : {"tx_broadcast_packets", offsetof(struct virtchnl2_vport_stats, tx_broadcast)},
136 : : {"tx_dropped_packets", offsetof(struct virtchnl2_vport_stats, tx_discards)},
137 : : {"tx_error_packets", offsetof(struct virtchnl2_vport_stats, tx_errors)}};
138 : :
139 : : #define CPFL_NB_XSTATS RTE_DIM(rte_cpfl_stats_strings)
140 : :
141 : : static int
142 : 0 : cpfl_dev_link_update(struct rte_eth_dev *dev,
143 : : __rte_unused int wait_to_complete)
144 : : {
145 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
146 : : struct idpf_vport *vport = &cpfl_vport->base;
147 : : struct rte_eth_link new_link;
148 : : unsigned int i;
149 : :
150 : : memset(&new_link, 0, sizeof(new_link));
151 : :
152 [ # # ]: 0 : for (i = 0; i < RTE_DIM(cpfl_supported_speeds); i++) {
153 [ # # ]: 0 : if (vport->link_speed == cpfl_supported_speeds[i]) {
154 : 0 : new_link.link_speed = vport->link_speed;
155 : 0 : break;
156 : : }
157 : : }
158 : :
159 [ # # ]: 0 : if (i == RTE_DIM(cpfl_supported_speeds)) {
160 [ # # ]: 0 : if (vport->link_up)
161 : 0 : new_link.link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
162 : : else
163 : 0 : new_link.link_speed = RTE_ETH_SPEED_NUM_NONE;
164 : : }
165 : :
166 : 0 : new_link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
167 : 0 : new_link.link_status = vport->link_up ? RTE_ETH_LINK_UP :
168 : : RTE_ETH_LINK_DOWN;
169 : 0 : new_link.link_autoneg = (dev->data->dev_conf.link_speeds & RTE_ETH_LINK_SPEED_FIXED) ?
170 [ # # ]: 0 : RTE_ETH_LINK_FIXED : RTE_ETH_LINK_AUTONEG;
171 : :
172 : 0 : return rte_eth_linkstatus_set(dev, &new_link);
173 : : }
174 : :
175 : : static int
176 : 0 : cpfl_hairpin_cap_get(struct rte_eth_dev *dev,
177 : : struct rte_eth_hairpin_cap *cap)
178 : : {
179 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
180 : :
181 [ # # ]: 0 : if (cpfl_vport->p2p_q_chunks_info == NULL)
182 : : return -ENOTSUP;
183 : :
184 : 0 : cap->max_nb_queues = CPFL_MAX_P2P_NB_QUEUES;
185 : 0 : cap->max_rx_2_tx = CPFL_MAX_HAIRPINQ_RX_2_TX;
186 : 0 : cap->max_tx_2_rx = CPFL_MAX_HAIRPINQ_TX_2_RX;
187 : 0 : cap->max_nb_desc = CPFL_MAX_HAIRPINQ_NB_DESC;
188 : :
189 : 0 : return 0;
190 : : }
191 : :
192 : : static int
193 : 0 : cpfl_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
194 : : {
195 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
196 : : struct idpf_vport *vport = &cpfl_vport->base;
197 : 0 : struct idpf_adapter *base = vport->adapter;
198 : :
199 : 0 : dev_info->max_rx_queues = base->caps.max_rx_q;
200 : 0 : dev_info->max_tx_queues = base->caps.max_tx_q;
201 : 0 : dev_info->min_rx_bufsize = CPFL_MIN_BUF_SIZE;
202 : 0 : dev_info->max_rx_pktlen = vport->max_mtu + CPFL_ETH_OVERHEAD;
203 : :
204 : 0 : dev_info->max_mtu = vport->max_mtu;
205 : 0 : dev_info->min_mtu = RTE_ETHER_MIN_MTU;
206 : :
207 : 0 : dev_info->hash_key_size = vport->rss_key_size;
208 : 0 : dev_info->reta_size = vport->rss_lut_size;
209 : :
210 : 0 : dev_info->flow_type_rss_offloads = CPFL_RSS_OFFLOAD_ALL;
211 : :
212 : 0 : dev_info->rx_offload_capa =
213 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
214 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
215 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
216 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
217 : : RTE_ETH_RX_OFFLOAD_TIMESTAMP |
218 : : RTE_ETH_RX_OFFLOAD_SCATTER;
219 : :
220 : 0 : dev_info->tx_offload_capa =
221 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
222 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
223 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
224 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
225 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
226 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
227 : : RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
228 : :
229 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
230 : : .tx_free_thresh = CPFL_DEFAULT_TX_FREE_THRESH,
231 : : .tx_rs_thresh = CPFL_DEFAULT_TX_RS_THRESH,
232 : : };
233 : :
234 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
235 : : .rx_free_thresh = CPFL_DEFAULT_RX_FREE_THRESH,
236 : : };
237 : :
238 : 0 : dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
239 : : .nb_max = CPFL_MAX_RING_DESC,
240 : : .nb_min = CPFL_MIN_RING_DESC,
241 : : .nb_align = CPFL_ALIGN_RING_DESC,
242 : : };
243 : :
244 : 0 : dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
245 : : .nb_max = CPFL_MAX_RING_DESC,
246 : : .nb_min = CPFL_MIN_RING_DESC,
247 : : .nb_align = CPFL_ALIGN_RING_DESC,
248 : : };
249 : :
250 : 0 : return 0;
251 : : }
252 : :
253 : : static int
254 : 0 : cpfl_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
255 : : {
256 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
257 : : struct idpf_vport *vport = &cpfl_vport->base;
258 : :
259 : : /* mtu setting is forbidden if port is start */
260 [ # # ]: 0 : if (dev->data->dev_started) {
261 : 0 : PMD_DRV_LOG(ERR, "port must be stopped before configuration");
262 : 0 : return -EBUSY;
263 : : }
264 : :
265 [ # # ]: 0 : if (mtu > vport->max_mtu) {
266 : 0 : PMD_DRV_LOG(ERR, "MTU should be less than %d", vport->max_mtu);
267 : 0 : return -EINVAL;
268 : : }
269 : :
270 : 0 : vport->max_pkt_len = mtu + CPFL_ETH_OVERHEAD;
271 : :
272 : 0 : return 0;
273 : : }
274 : :
275 : : static const uint32_t *
276 : 0 : cpfl_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused,
277 : : size_t *no_of_elements)
278 : : {
279 : : static const uint32_t ptypes[] = {
280 : : RTE_PTYPE_L2_ETHER,
281 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
282 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
283 : : RTE_PTYPE_L4_FRAG,
284 : : RTE_PTYPE_L4_UDP,
285 : : RTE_PTYPE_L4_TCP,
286 : : RTE_PTYPE_L4_SCTP,
287 : : RTE_PTYPE_L4_ICMP,
288 : : };
289 : :
290 : 0 : *no_of_elements = RTE_DIM(ptypes);
291 : 0 : return ptypes;
292 : : }
293 : :
294 : : static uint64_t
295 : 0 : cpfl_get_mbuf_alloc_failed_stats(struct rte_eth_dev *dev)
296 : : {
297 : : uint64_t mbuf_alloc_failed = 0;
298 : : struct cpfl_rx_queue *cpfl_rxq;
299 : : int i = 0;
300 : :
301 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
302 : 0 : cpfl_rxq = dev->data->rx_queues[i];
303 : 0 : mbuf_alloc_failed += __atomic_load_n(&cpfl_rxq->base.rx_stats.mbuf_alloc_failed,
304 : : __ATOMIC_RELAXED);
305 : : }
306 : :
307 : 0 : return mbuf_alloc_failed;
308 : : }
309 : :
310 : : static int
311 : 0 : cpfl_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
312 : : {
313 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
314 : 0 : struct idpf_vport *vport = &cpfl_vport->base;
315 : 0 : struct virtchnl2_vport_stats *pstats = NULL;
316 : : int ret;
317 : :
318 : 0 : ret = idpf_vc_stats_query(vport, &pstats);
319 [ # # ]: 0 : if (ret == 0) {
320 [ # # ]: 0 : uint8_t crc_stats_len = (dev->data->dev_conf.rxmode.offloads &
321 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC) ? 0 :
322 : : RTE_ETHER_CRC_LEN;
323 : :
324 : 0 : idpf_vport_stats_update(&vport->eth_stats_offset, pstats);
325 : 0 : stats->ipackets = pstats->rx_unicast + pstats->rx_multicast +
326 : 0 : pstats->rx_broadcast;
327 : 0 : stats->opackets = pstats->tx_broadcast + pstats->tx_multicast +
328 : 0 : pstats->tx_unicast;
329 : 0 : stats->imissed = pstats->rx_discards;
330 : 0 : stats->ierrors = pstats->rx_errors;
331 : 0 : stats->oerrors = pstats->tx_errors + pstats->tx_discards;
332 : 0 : stats->ibytes = pstats->rx_bytes;
333 : 0 : stats->ibytes -= stats->ipackets * crc_stats_len;
334 : 0 : stats->obytes = pstats->tx_bytes;
335 : :
336 : 0 : dev->data->rx_mbuf_alloc_failed = cpfl_get_mbuf_alloc_failed_stats(dev);
337 : 0 : stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
338 : : } else {
339 : 0 : PMD_DRV_LOG(ERR, "Get statistics failed");
340 : : }
341 : 0 : return ret;
342 : : }
343 : :
344 : : static void
345 : 0 : cpfl_reset_mbuf_alloc_failed_stats(struct rte_eth_dev *dev)
346 : : {
347 : : struct cpfl_rx_queue *cpfl_rxq;
348 : : int i;
349 : :
350 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
351 : 0 : cpfl_rxq = dev->data->rx_queues[i];
352 : 0 : __atomic_store_n(&cpfl_rxq->base.rx_stats.mbuf_alloc_failed, 0, __ATOMIC_RELAXED);
353 : : }
354 : 0 : }
355 : :
356 : : static int
357 : 0 : cpfl_dev_stats_reset(struct rte_eth_dev *dev)
358 : : {
359 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
360 : 0 : struct idpf_vport *vport = &cpfl_vport->base;
361 : 0 : struct virtchnl2_vport_stats *pstats = NULL;
362 : : int ret;
363 : :
364 : 0 : ret = idpf_vc_stats_query(vport, &pstats);
365 [ # # ]: 0 : if (ret != 0)
366 : : return ret;
367 : :
368 : : /* set stats offset base on current values */
369 : 0 : vport->eth_stats_offset = *pstats;
370 : :
371 : 0 : cpfl_reset_mbuf_alloc_failed_stats(dev);
372 : :
373 : 0 : return 0;
374 : : }
375 : :
376 : 0 : static int cpfl_dev_xstats_reset(struct rte_eth_dev *dev)
377 : : {
378 : 0 : cpfl_dev_stats_reset(dev);
379 : 0 : return 0;
380 : : }
381 : :
382 : 0 : static int cpfl_dev_xstats_get(struct rte_eth_dev *dev,
383 : : struct rte_eth_xstat *xstats, unsigned int n)
384 : : {
385 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
386 : 0 : struct idpf_vport *vport = &cpfl_vport->base;
387 : 0 : struct virtchnl2_vport_stats *pstats = NULL;
388 : : unsigned int i;
389 : : int ret;
390 : :
391 [ # # ]: 0 : if (n < CPFL_NB_XSTATS)
392 : : return CPFL_NB_XSTATS;
393 : :
394 [ # # ]: 0 : if (!xstats)
395 : : return CPFL_NB_XSTATS;
396 : :
397 : 0 : ret = idpf_vc_stats_query(vport, &pstats);
398 [ # # ]: 0 : if (ret) {
399 : 0 : PMD_DRV_LOG(ERR, "Get statistics failed");
400 : 0 : return 0;
401 : : }
402 : :
403 : 0 : idpf_vport_stats_update(&vport->eth_stats_offset, pstats);
404 : :
405 : : /* loop over xstats array and values from pstats */
406 [ # # ]: 0 : for (i = 0; i < CPFL_NB_XSTATS; i++) {
407 : 0 : xstats[i].id = i;
408 : 0 : xstats[i].value = *(uint64_t *)(((char *)pstats) +
409 : 0 : rte_cpfl_stats_strings[i].offset);
410 : : }
411 : : return CPFL_NB_XSTATS;
412 : : }
413 : :
414 : 0 : static int cpfl_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
415 : : struct rte_eth_xstat_name *xstats_names,
416 : : __rte_unused unsigned int limit)
417 : : {
418 : : unsigned int i;
419 : :
420 [ # # ]: 0 : if (xstats_names) {
421 [ # # ]: 0 : for (i = 0; i < CPFL_NB_XSTATS; i++) {
422 : 0 : snprintf(xstats_names[i].name,
423 : : sizeof(xstats_names[i].name),
424 : 0 : "%s", rte_cpfl_stats_strings[i].name);
425 : : }
426 : : }
427 : 0 : return CPFL_NB_XSTATS;
428 : : }
429 : :
430 : 0 : static int cpfl_config_rss_hf(struct idpf_vport *vport, uint64_t rss_hf)
431 : : {
432 : : uint64_t hena = 0;
433 : : uint16_t i;
434 : :
435 : : /**
436 : : * RTE_ETH_RSS_IPV4 and RTE_ETH_RSS_IPV6 can be considered as 2
437 : : * generalizations of all other IPv4 and IPv6 RSS types.
438 : : */
439 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV4)
440 : 0 : rss_hf |= cpfl_ipv4_rss;
441 : :
442 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6)
443 : 0 : rss_hf |= cpfl_ipv6_rss;
444 : :
445 [ # # ]: 0 : for (i = 0; i < RTE_DIM(cpfl_map_hena_rss); i++) {
446 [ # # ]: 0 : if (cpfl_map_hena_rss[i] & rss_hf)
447 : 0 : hena |= BIT_ULL(i);
448 : : }
449 : :
450 : : /**
451 : : * At present, cp doesn't process the virtual channel msg of rss_hf configuration,
452 : : * tips are given below.
453 : : */
454 [ # # ]: 0 : if (hena != vport->rss_hf)
455 : 0 : PMD_DRV_LOG(WARNING, "Updating RSS Hash Function is not supported at present.");
456 : :
457 : 0 : return 0;
458 : : }
459 : :
460 : : static int
461 : 0 : cpfl_init_rss(struct idpf_vport *vport)
462 : : {
463 : : struct rte_eth_rss_conf *rss_conf;
464 : : struct rte_eth_dev_data *dev_data;
465 : : uint16_t i, nb_q;
466 : : int ret = 0;
467 : :
468 : 0 : dev_data = vport->dev_data;
469 : : rss_conf = &dev_data->dev_conf.rx_adv_conf.rss_conf;
470 : 0 : nb_q = dev_data->nb_rx_queues;
471 : :
472 [ # # ]: 0 : if (rss_conf->rss_key == NULL) {
473 [ # # ]: 0 : for (i = 0; i < vport->rss_key_size; i++)
474 : 0 : vport->rss_key[i] = (uint8_t)rte_rand();
475 [ # # ]: 0 : } else if (rss_conf->rss_key_len != vport->rss_key_size) {
476 : 0 : PMD_INIT_LOG(ERR, "Invalid RSS key length in RSS configuration, should be %d",
477 : : vport->rss_key_size);
478 : 0 : return -EINVAL;
479 : : } else {
480 : 0 : memcpy(vport->rss_key, rss_conf->rss_key,
481 : : vport->rss_key_size);
482 : : }
483 : :
484 [ # # ]: 0 : for (i = 0; i < vport->rss_lut_size; i++)
485 : 0 : vport->rss_lut[i] = i % nb_q;
486 : :
487 : 0 : vport->rss_hf = IDPF_DEFAULT_RSS_HASH_EXPANDED;
488 : :
489 : 0 : ret = idpf_vport_rss_config(vport);
490 [ # # ]: 0 : if (ret != 0)
491 : 0 : PMD_INIT_LOG(ERR, "Failed to configure RSS");
492 : :
493 : : return ret;
494 : : }
495 : :
496 : : static int
497 : 0 : cpfl_rss_reta_update(struct rte_eth_dev *dev,
498 : : struct rte_eth_rss_reta_entry64 *reta_conf,
499 : : uint16_t reta_size)
500 : : {
501 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
502 : 0 : struct idpf_vport *vport = &cpfl_vport->base;
503 : 0 : struct idpf_adapter *base = vport->adapter;
504 : : uint16_t idx, shift;
505 : : int ret = 0;
506 : : uint16_t i;
507 : :
508 [ # # # # ]: 0 : if (base->caps.rss_caps == 0 || dev->data->nb_rx_queues == 0) {
509 : 0 : PMD_DRV_LOG(DEBUG, "RSS is not supported");
510 : 0 : return -ENOTSUP;
511 : : }
512 : :
513 [ # # ]: 0 : if (reta_size != vport->rss_lut_size) {
514 : 0 : PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
515 : : "(%d) doesn't match the number of hardware can "
516 : : "support (%d)",
517 : : reta_size, vport->rss_lut_size);
518 : 0 : return -EINVAL;
519 : : }
520 : :
521 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
522 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
523 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
524 [ # # ]: 0 : if (reta_conf[idx].mask & (1ULL << shift))
525 : 0 : vport->rss_lut[i] = reta_conf[idx].reta[shift];
526 : : }
527 : :
528 : : /* send virtchnl ops to configure RSS */
529 : 0 : ret = idpf_vc_rss_lut_set(vport);
530 [ # # ]: 0 : if (ret)
531 : 0 : PMD_INIT_LOG(ERR, "Failed to configure RSS lut");
532 : :
533 : : return ret;
534 : : }
535 : :
536 : : static int
537 : 0 : cpfl_rss_reta_query(struct rte_eth_dev *dev,
538 : : struct rte_eth_rss_reta_entry64 *reta_conf,
539 : : uint16_t reta_size)
540 : : {
541 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
542 : 0 : struct idpf_vport *vport = &cpfl_vport->base;
543 : 0 : struct idpf_adapter *base = vport->adapter;
544 : : uint16_t idx, shift;
545 : : int ret = 0;
546 : : uint16_t i;
547 : :
548 [ # # # # ]: 0 : if (base->caps.rss_caps == 0 || dev->data->nb_rx_queues == 0) {
549 : 0 : PMD_DRV_LOG(DEBUG, "RSS is not supported");
550 : 0 : return -ENOTSUP;
551 : : }
552 : :
553 [ # # ]: 0 : if (reta_size != vport->rss_lut_size) {
554 : 0 : PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
555 : : "(%d) doesn't match the number of hardware can "
556 : : "support (%d)", reta_size, vport->rss_lut_size);
557 : 0 : return -EINVAL;
558 : : }
559 : :
560 : 0 : ret = idpf_vc_rss_lut_get(vport);
561 [ # # ]: 0 : if (ret) {
562 : 0 : PMD_DRV_LOG(ERR, "Failed to get RSS LUT");
563 : 0 : return ret;
564 : : }
565 : :
566 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
567 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
568 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
569 [ # # ]: 0 : if (reta_conf[idx].mask & (1ULL << shift))
570 : 0 : reta_conf[idx].reta[shift] = vport->rss_lut[i];
571 : : }
572 : :
573 : : return 0;
574 : : }
575 : :
576 : : static int
577 : 0 : cpfl_rss_hash_update(struct rte_eth_dev *dev,
578 : : struct rte_eth_rss_conf *rss_conf)
579 : : {
580 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
581 : 0 : struct idpf_vport *vport = &cpfl_vport->base;
582 : 0 : struct idpf_adapter *base = vport->adapter;
583 : : int ret = 0;
584 : :
585 [ # # # # ]: 0 : if (base->caps.rss_caps == 0 || dev->data->nb_rx_queues == 0) {
586 : 0 : PMD_DRV_LOG(DEBUG, "RSS is not supported");
587 : 0 : return -ENOTSUP;
588 : : }
589 : :
590 [ # # # # ]: 0 : if (!rss_conf->rss_key || rss_conf->rss_key_len == 0) {
591 : 0 : PMD_DRV_LOG(DEBUG, "No key to be configured");
592 : 0 : goto skip_rss_key;
593 [ # # ]: 0 : } else if (rss_conf->rss_key_len != vport->rss_key_size) {
594 : 0 : PMD_DRV_LOG(ERR, "The size of hash key configured "
595 : : "(%d) doesn't match the size of hardware can "
596 : : "support (%d)",
597 : : rss_conf->rss_key_len,
598 : : vport->rss_key_size);
599 : 0 : return -EINVAL;
600 : : }
601 : :
602 : 0 : memcpy(vport->rss_key, rss_conf->rss_key,
603 : : vport->rss_key_size);
604 : 0 : ret = idpf_vc_rss_key_set(vport);
605 [ # # ]: 0 : if (ret != 0) {
606 : 0 : PMD_INIT_LOG(ERR, "Failed to configure RSS key");
607 : 0 : return ret;
608 : : }
609 : :
610 : 0 : skip_rss_key:
611 : 0 : ret = cpfl_config_rss_hf(vport, rss_conf->rss_hf);
612 [ # # ]: 0 : if (ret != 0) {
613 : 0 : PMD_INIT_LOG(ERR, "Failed to configure RSS hash");
614 : 0 : return ret;
615 : : }
616 : :
617 : : return 0;
618 : : }
619 : :
620 : : static uint64_t
621 : 0 : cpfl_map_general_rss_hf(uint64_t config_rss_hf, uint64_t last_general_rss_hf)
622 : : {
623 : : uint64_t valid_rss_hf = 0;
624 : : uint16_t i;
625 : :
626 [ # # ]: 0 : for (i = 0; i < RTE_DIM(cpfl_map_hena_rss); i++) {
627 : 0 : uint64_t bit = BIT_ULL(i);
628 : :
629 [ # # ]: 0 : if (bit & config_rss_hf)
630 : 0 : valid_rss_hf |= cpfl_map_hena_rss[i];
631 : : }
632 : :
633 [ # # ]: 0 : if (valid_rss_hf & cpfl_ipv4_rss)
634 : 0 : valid_rss_hf |= last_general_rss_hf & RTE_ETH_RSS_IPV4;
635 : :
636 [ # # ]: 0 : if (valid_rss_hf & cpfl_ipv6_rss)
637 : 0 : valid_rss_hf |= last_general_rss_hf & RTE_ETH_RSS_IPV6;
638 : :
639 : 0 : return valid_rss_hf;
640 : : }
641 : :
642 : : static int
643 : 0 : cpfl_rss_hash_conf_get(struct rte_eth_dev *dev,
644 : : struct rte_eth_rss_conf *rss_conf)
645 : : {
646 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
647 : 0 : struct idpf_vport *vport = &cpfl_vport->base;
648 : 0 : struct idpf_adapter *base = vport->adapter;
649 : : int ret = 0;
650 : :
651 [ # # # # ]: 0 : if (base->caps.rss_caps == 0 || dev->data->nb_rx_queues == 0) {
652 : 0 : PMD_DRV_LOG(DEBUG, "RSS is not supported");
653 : 0 : return -ENOTSUP;
654 : : }
655 : :
656 : 0 : ret = idpf_vc_rss_hash_get(vport);
657 [ # # ]: 0 : if (ret) {
658 : 0 : PMD_DRV_LOG(ERR, "Failed to get RSS hf");
659 : 0 : return ret;
660 : : }
661 : :
662 : 0 : rss_conf->rss_hf = cpfl_map_general_rss_hf(vport->rss_hf, vport->last_general_rss_hf);
663 : :
664 [ # # ]: 0 : if (!rss_conf->rss_key)
665 : : return 0;
666 : :
667 : 0 : ret = idpf_vc_rss_key_get(vport);
668 [ # # ]: 0 : if (ret) {
669 : 0 : PMD_DRV_LOG(ERR, "Failed to get RSS key");
670 : 0 : return ret;
671 : : }
672 : :
673 [ # # ]: 0 : if (rss_conf->rss_key_len > vport->rss_key_size)
674 : 0 : rss_conf->rss_key_len = vport->rss_key_size;
675 : :
676 : 0 : memcpy(rss_conf->rss_key, vport->rss_key, rss_conf->rss_key_len);
677 : :
678 : 0 : return 0;
679 : : }
680 : :
681 : : static int
682 : 0 : cpfl_dev_configure(struct rte_eth_dev *dev)
683 : : {
684 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
685 : 0 : struct idpf_vport *vport = &cpfl_vport->base;
686 : : struct rte_eth_conf *conf = &dev->data->dev_conf;
687 : 0 : struct idpf_adapter *base = vport->adapter;
688 : : int ret;
689 : :
690 [ # # ]: 0 : if (conf->link_speeds & RTE_ETH_LINK_SPEED_FIXED) {
691 : 0 : PMD_INIT_LOG(ERR, "Setting link speed is not supported");
692 : 0 : return -ENOTSUP;
693 : : }
694 : :
695 [ # # ]: 0 : if (conf->txmode.mq_mode != RTE_ETH_MQ_TX_NONE) {
696 : 0 : PMD_INIT_LOG(ERR, "Multi-queue TX mode %d is not supported",
697 : : conf->txmode.mq_mode);
698 : 0 : return -ENOTSUP;
699 : : }
700 : :
701 [ # # ]: 0 : if (conf->lpbk_mode != 0) {
702 : 0 : PMD_INIT_LOG(ERR, "Loopback operation mode %d is not supported",
703 : : conf->lpbk_mode);
704 : 0 : return -ENOTSUP;
705 : : }
706 : :
707 [ # # ]: 0 : if (conf->dcb_capability_en != 0) {
708 : 0 : PMD_INIT_LOG(ERR, "Priority Flow Control(PFC) if not supported");
709 : 0 : return -ENOTSUP;
710 : : }
711 : :
712 [ # # ]: 0 : if (conf->intr_conf.lsc != 0) {
713 : 0 : PMD_INIT_LOG(ERR, "LSC interrupt is not supported");
714 : 0 : return -ENOTSUP;
715 : : }
716 : :
717 [ # # ]: 0 : if (conf->intr_conf.rxq != 0) {
718 : 0 : PMD_INIT_LOG(ERR, "RXQ interrupt is not supported");
719 : 0 : return -ENOTSUP;
720 : : }
721 : :
722 [ # # ]: 0 : if (conf->intr_conf.rmv != 0) {
723 : 0 : PMD_INIT_LOG(ERR, "RMV interrupt is not supported");
724 : 0 : return -ENOTSUP;
725 : : }
726 : :
727 [ # # ]: 0 : if (conf->rxmode.mq_mode != RTE_ETH_MQ_RX_RSS &&
728 : : conf->rxmode.mq_mode != RTE_ETH_MQ_RX_NONE) {
729 : 0 : PMD_INIT_LOG(ERR, "RX mode %d is not supported.",
730 : : conf->rxmode.mq_mode);
731 : 0 : return -EINVAL;
732 : : }
733 : :
734 [ # # # # ]: 0 : if (base->caps.rss_caps != 0 && dev->data->nb_rx_queues != 0) {
735 : 0 : ret = cpfl_init_rss(vport);
736 [ # # ]: 0 : if (ret != 0) {
737 : 0 : PMD_INIT_LOG(ERR, "Failed to init rss");
738 : 0 : return ret;
739 : : }
740 [ # # ]: 0 : } else if (conf->rxmode.mq_mode == RTE_ETH_MQ_RX_RSS) {
741 : 0 : PMD_INIT_LOG(ERR, "RSS is not supported.");
742 : 0 : return -ENOTSUP;
743 : : }
744 : :
745 : 0 : vport->max_pkt_len =
746 [ # # ]: 0 : (dev->data->mtu == 0) ? CPFL_DEFAULT_MTU : dev->data->mtu +
747 : : CPFL_ETH_OVERHEAD;
748 : :
749 : 0 : return 0;
750 : : }
751 : :
752 : : static int
753 : 0 : cpfl_config_rx_queues_irqs(struct rte_eth_dev *dev)
754 : : {
755 : 0 : uint32_t qids[CPFL_MAX_P2P_NB_QUEUES + IDPF_DEFAULT_RXQ_NUM] = {0};
756 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
757 : 0 : struct idpf_vport *vport = &cpfl_vport->base;
758 : 0 : uint16_t nb_rx_queues = dev->data->nb_rx_queues;
759 : : struct cpfl_rx_queue *cpfl_rxq;
760 : : int i;
761 : :
762 [ # # ]: 0 : for (i = 0; i < nb_rx_queues; i++) {
763 : 0 : cpfl_rxq = dev->data->rx_queues[i];
764 [ # # ]: 0 : if (cpfl_rxq->hairpin_info.hairpin_q)
765 : 0 : qids[i] = cpfl_hw_qid_get(cpfl_vport->p2p_q_chunks_info->rx_start_qid,
766 : 0 : (i - cpfl_vport->nb_data_rxq));
767 : : else
768 : 0 : qids[i] = cpfl_hw_qid_get(vport->chunks_info.rx_start_qid, i);
769 : : }
770 : 0 : return idpf_vport_irq_map_config_by_qids(vport, qids, nb_rx_queues);
771 : : }
772 : :
773 : : /* Update hairpin_info for dev's tx hairpin queue */
774 : : static int
775 : 0 : cpfl_txq_hairpin_info_update(struct rte_eth_dev *dev, uint16_t rx_port)
776 : : {
777 : 0 : struct cpfl_vport *cpfl_tx_vport = dev->data->dev_private;
778 : 0 : struct rte_eth_dev *peer_dev = &rte_eth_devices[rx_port];
779 : 0 : struct cpfl_vport *cpfl_rx_vport = peer_dev->data->dev_private;
780 : : struct cpfl_txq_hairpin_info *hairpin_info;
781 : : struct cpfl_tx_queue *cpfl_txq;
782 : : int i;
783 : :
784 [ # # ]: 0 : for (i = cpfl_tx_vport->nb_data_txq; i < dev->data->nb_tx_queues; i++) {
785 : 0 : cpfl_txq = dev->data->tx_queues[i];
786 : : hairpin_info = &cpfl_txq->hairpin_info;
787 [ # # ]: 0 : if (hairpin_info->peer_rxp != rx_port) {
788 : 0 : PMD_DRV_LOG(ERR, "port %d is not the peer port", rx_port);
789 : 0 : return -EINVAL;
790 : : }
791 : 0 : hairpin_info->peer_rxq_id =
792 : 0 : cpfl_hw_qid_get(cpfl_rx_vport->p2p_q_chunks_info->rx_start_qid,
793 : 0 : hairpin_info->peer_rxq_id - cpfl_rx_vport->nb_data_rxq);
794 : : }
795 : :
796 : : return 0;
797 : : }
798 : :
799 : : /* Bind Rx hairpin queue's memory zone to peer Tx hairpin queue's memory zone */
800 : : static void
801 : 0 : cpfl_rxq_hairpin_mz_bind(struct rte_eth_dev *dev)
802 : : {
803 : 0 : struct cpfl_vport *cpfl_rx_vport = dev->data->dev_private;
804 : : struct idpf_vport *vport = &cpfl_rx_vport->base;
805 : 0 : struct idpf_adapter *adapter = vport->adapter;
806 : : struct idpf_hw *hw = &adapter->hw;
807 : : struct cpfl_rx_queue *cpfl_rxq;
808 : : struct cpfl_tx_queue *cpfl_txq;
809 : : struct rte_eth_dev *peer_dev;
810 : : const struct rte_memzone *mz;
811 : : uint16_t peer_tx_port;
812 : : uint16_t peer_tx_qid;
813 : : int i;
814 : :
815 [ # # ]: 0 : for (i = cpfl_rx_vport->nb_data_rxq; i < dev->data->nb_rx_queues; i++) {
816 : 0 : cpfl_rxq = dev->data->rx_queues[i];
817 : 0 : peer_tx_port = cpfl_rxq->hairpin_info.peer_txp;
818 : 0 : peer_tx_qid = cpfl_rxq->hairpin_info.peer_txq_id;
819 : 0 : peer_dev = &rte_eth_devices[peer_tx_port];
820 : 0 : cpfl_txq = peer_dev->data->tx_queues[peer_tx_qid];
821 : :
822 : : /* bind rx queue */
823 : 0 : mz = cpfl_txq->base.mz;
824 : 0 : cpfl_rxq->base.rx_ring_phys_addr = mz->iova;
825 : 0 : cpfl_rxq->base.rx_ring = mz->addr;
826 : 0 : cpfl_rxq->base.mz = mz;
827 : :
828 : : /* bind rx buffer queue */
829 : 0 : mz = cpfl_txq->base.complq->mz;
830 : 0 : cpfl_rxq->base.bufq1->rx_ring_phys_addr = mz->iova;
831 : 0 : cpfl_rxq->base.bufq1->rx_ring = mz->addr;
832 : 0 : cpfl_rxq->base.bufq1->mz = mz;
833 : 0 : cpfl_rxq->base.bufq1->qrx_tail = hw->hw_addr +
834 : 0 : cpfl_hw_qtail_get(cpfl_rx_vport->p2p_q_chunks_info->rx_buf_qtail_start,
835 : 0 : 0, cpfl_rx_vport->p2p_q_chunks_info->rx_buf_qtail_spacing);
836 : : }
837 : 0 : }
838 : :
839 : : static int
840 : 0 : cpfl_rss_lut_config(struct cpfl_vport *cpfl_vport, uint16_t nb_q)
841 : : {
842 : 0 : struct idpf_vport *vport = &cpfl_vport->base;
843 : 0 : uint16_t lut_size = vport->rss_lut_size;
844 : : uint16_t i;
845 : : int ret;
846 : :
847 [ # # ]: 0 : for (i = 0; i < lut_size; i++)
848 : 0 : vport->rss_lut[i] = i % nb_q;
849 : :
850 : 0 : ret = idpf_vc_rss_lut_set(vport);
851 [ # # ]: 0 : if (ret)
852 : 0 : PMD_INIT_LOG(ERR, "Failed to configure RSS lut");
853 : :
854 : 0 : return ret;
855 : : }
856 : :
857 : : static int
858 : 0 : cpfl_start_queues(struct rte_eth_dev *dev)
859 : : {
860 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
861 : 0 : struct idpf_vport *vport = &cpfl_vport->base;
862 : : struct cpfl_rx_queue *cpfl_rxq;
863 : : struct cpfl_tx_queue *cpfl_txq;
864 : : int update_flag = 0;
865 : : int err = 0;
866 : : int i;
867 : :
868 : : /* For normal data queues, configure, init and enale Txq.
869 : : * For non-manual bind hairpin queues, configure Txq.
870 : : */
871 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
872 : 0 : cpfl_txq = dev->data->tx_queues[i];
873 [ # # # # ]: 0 : if (cpfl_txq == NULL || cpfl_txq->base.tx_deferred_start)
874 : 0 : continue;
875 [ # # ]: 0 : if (!cpfl_txq->hairpin_info.hairpin_q) {
876 : 0 : err = cpfl_tx_queue_start(dev, i);
877 [ # # ]: 0 : if (err != 0) {
878 : 0 : PMD_DRV_LOG(ERR, "Fail to start Tx queue %u", i);
879 : 0 : return err;
880 : : }
881 [ # # ]: 0 : } else if (!cpfl_vport->p2p_manual_bind) {
882 [ # # ]: 0 : if (update_flag == 0) {
883 : 0 : err = cpfl_txq_hairpin_info_update(dev,
884 : 0 : cpfl_txq->hairpin_info.peer_rxp);
885 [ # # ]: 0 : if (err != 0) {
886 : 0 : PMD_DRV_LOG(ERR, "Fail to update Tx hairpin queue info");
887 : 0 : return err;
888 : : }
889 : : update_flag = 1;
890 : : }
891 : 0 : err = cpfl_hairpin_txq_config(vport, cpfl_txq);
892 [ # # ]: 0 : if (err != 0) {
893 : 0 : PMD_DRV_LOG(ERR, "Fail to configure hairpin Tx queue %u", i);
894 : 0 : return err;
895 : : }
896 : : }
897 : : }
898 : :
899 : : /* For non-manual bind hairpin queues, configure Tx completion queue first.*/
900 [ # # # # ]: 0 : if (!cpfl_vport->p2p_manual_bind && cpfl_vport->p2p_tx_complq != NULL) {
901 : 0 : err = cpfl_hairpin_tx_complq_config(cpfl_vport);
902 [ # # ]: 0 : if (err != 0) {
903 : 0 : PMD_DRV_LOG(ERR, "Fail to config Tx completion queue");
904 : 0 : return err;
905 : : }
906 : : }
907 : :
908 : : /* For non-manual bind hairpin queues, configure Rx buffer queue.*/
909 [ # # # # ]: 0 : if (!cpfl_vport->p2p_manual_bind && cpfl_vport->p2p_rx_bufq != NULL) {
910 : 0 : cpfl_rxq_hairpin_mz_bind(dev);
911 : 0 : err = cpfl_hairpin_rx_bufq_config(cpfl_vport);
912 [ # # ]: 0 : if (err != 0) {
913 : 0 : PMD_DRV_LOG(ERR, "Fail to config Rx buffer queue");
914 : 0 : return err;
915 : : }
916 : : }
917 : :
918 : : /* For normal data queues, configure, init and enale Rxq.
919 : : * For non-manual bind hairpin queues, configure Rxq, and then init Rxq.
920 : : */
921 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
922 : 0 : cpfl_rxq = dev->data->rx_queues[i];
923 [ # # # # ]: 0 : if (cpfl_rxq == NULL || cpfl_rxq->base.rx_deferred_start)
924 : 0 : continue;
925 [ # # ]: 0 : if (!cpfl_rxq->hairpin_info.hairpin_q) {
926 : 0 : err = cpfl_rx_queue_start(dev, i);
927 [ # # ]: 0 : if (err != 0) {
928 : 0 : PMD_DRV_LOG(ERR, "Fail to start Rx queue %u", i);
929 : 0 : return err;
930 : : }
931 [ # # ]: 0 : } else if (!cpfl_vport->p2p_manual_bind) {
932 : 0 : err = cpfl_hairpin_rxq_config(vport, cpfl_rxq);
933 [ # # ]: 0 : if (err != 0) {
934 : 0 : PMD_DRV_LOG(ERR, "Fail to configure hairpin Rx queue %u", i);
935 : 0 : return err;
936 : : }
937 : 0 : err = cpfl_rx_queue_init(dev, i);
938 [ # # ]: 0 : if (err != 0) {
939 : 0 : PMD_DRV_LOG(ERR, "Fail to init hairpin Rx queue %u", i);
940 : 0 : return err;
941 : : }
942 : : }
943 : : }
944 : :
945 : : /* For non-manual bind hairpin queues, enable Tx queue and Rx queue,
946 : : * then enable Tx completion queue and Rx buffer queue.
947 : : */
948 [ # # ]: 0 : for (i = cpfl_vport->nb_data_txq; i < dev->data->nb_tx_queues; i++) {
949 : 0 : cpfl_txq = dev->data->tx_queues[i];
950 [ # # # # ]: 0 : if (cpfl_txq->hairpin_info.hairpin_q && !cpfl_vport->p2p_manual_bind) {
951 : 0 : err = cpfl_switch_hairpin_rxtx_queue(cpfl_vport,
952 : 0 : i - cpfl_vport->nb_data_txq,
953 : : false, true);
954 [ # # ]: 0 : if (err)
955 : 0 : PMD_DRV_LOG(ERR, "Failed to switch hairpin TX queue %u on",
956 : : i);
957 : : else
958 : 0 : cpfl_txq->base.q_started = true;
959 : : }
960 : : }
961 : :
962 [ # # ]: 0 : for (i = cpfl_vport->nb_data_rxq; i < dev->data->nb_rx_queues; i++) {
963 : 0 : cpfl_rxq = dev->data->rx_queues[i];
964 [ # # # # ]: 0 : if (cpfl_rxq->hairpin_info.hairpin_q && !cpfl_vport->p2p_manual_bind) {
965 : 0 : err = cpfl_switch_hairpin_rxtx_queue(cpfl_vport,
966 : 0 : i - cpfl_vport->nb_data_rxq,
967 : : true, true);
968 [ # # ]: 0 : if (err)
969 : 0 : PMD_DRV_LOG(ERR, "Failed to switch hairpin RX queue %u on",
970 : : i);
971 : : else
972 : 0 : cpfl_rxq->base.q_started = true;
973 : : }
974 : : }
975 : :
976 [ # # ]: 0 : if (!cpfl_vport->p2p_manual_bind &&
977 [ # # ]: 0 : cpfl_vport->p2p_tx_complq != NULL &&
978 [ # # ]: 0 : cpfl_vport->p2p_rx_bufq != NULL) {
979 : 0 : err = cpfl_switch_hairpin_complq(cpfl_vport, true);
980 [ # # ]: 0 : if (err != 0) {
981 : 0 : PMD_DRV_LOG(ERR, "Failed to switch hairpin Tx complq");
982 : 0 : return err;
983 : : }
984 : 0 : err = cpfl_switch_hairpin_bufq(cpfl_vport, true);
985 [ # # ]: 0 : if (err != 0) {
986 : 0 : PMD_DRV_LOG(ERR, "Failed to switch hairpin Rx bufq");
987 : 0 : return err;
988 : : }
989 : : }
990 : :
991 : : /* re-configure RSS lut if there's hairpin queue */
992 [ # # ]: 0 : if (cpfl_vport->nb_p2p_rxq > 0)
993 : 0 : err = cpfl_rss_lut_config(cpfl_vport, cpfl_vport->nb_data_rxq);
994 : :
995 : : return err;
996 : : }
997 : :
998 : : static int
999 : 0 : cpfl_dev_start(struct rte_eth_dev *dev)
1000 : : {
1001 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
1002 : 0 : struct idpf_vport *vport = &cpfl_vport->base;
1003 : 0 : struct idpf_adapter *base = vport->adapter;
1004 : 0 : struct cpfl_adapter_ext *adapter = CPFL_ADAPTER_TO_EXT(base);
1005 : 0 : uint16_t num_allocated_vectors = base->caps.num_allocated_vectors;
1006 : : uint16_t req_vecs_num;
1007 : : int ret;
1008 : :
1009 : : req_vecs_num = CPFL_DFLT_Q_VEC_NUM;
1010 [ # # ]: 0 : if (req_vecs_num + adapter->used_vecs_num > num_allocated_vectors) {
1011 : 0 : PMD_DRV_LOG(ERR, "The accumulated request vectors' number should be less than %d",
1012 : : num_allocated_vectors);
1013 : : ret = -EINVAL;
1014 : 0 : goto err_vec;
1015 : : }
1016 : :
1017 : 0 : ret = idpf_vc_vectors_alloc(vport, req_vecs_num);
1018 [ # # ]: 0 : if (ret != 0) {
1019 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate interrupt vectors");
1020 : 0 : goto err_vec;
1021 : : }
1022 : 0 : adapter->used_vecs_num += req_vecs_num;
1023 : :
1024 : 0 : ret = cpfl_config_rx_queues_irqs(dev);
1025 [ # # ]: 0 : if (ret != 0) {
1026 : 0 : PMD_DRV_LOG(ERR, "Failed to configure irqs");
1027 : 0 : goto err_irq;
1028 : : }
1029 : :
1030 : 0 : ret = cpfl_start_queues(dev);
1031 [ # # ]: 0 : if (ret != 0) {
1032 : 0 : PMD_DRV_LOG(ERR, "Failed to start queues");
1033 : 0 : goto err_startq;
1034 : : }
1035 : :
1036 : 0 : cpfl_set_rx_function(dev);
1037 : 0 : cpfl_set_tx_function(dev);
1038 : :
1039 : 0 : ret = idpf_vc_vport_ena_dis(vport, true);
1040 [ # # ]: 0 : if (ret != 0) {
1041 : 0 : PMD_DRV_LOG(ERR, "Failed to enable vport");
1042 : 0 : goto err_vport;
1043 : : }
1044 : :
1045 [ # # ]: 0 : if (cpfl_dev_stats_reset(dev))
1046 : 0 : PMD_DRV_LOG(ERR, "Failed to reset stats");
1047 : :
1048 : : return 0;
1049 : :
1050 : : err_vport:
1051 : 0 : cpfl_stop_queues(dev);
1052 : 0 : err_startq:
1053 : 0 : idpf_vport_irq_unmap_config(vport, dev->data->nb_rx_queues);
1054 : 0 : err_irq:
1055 : 0 : idpf_vc_vectors_dealloc(vport);
1056 : : err_vec:
1057 : : return ret;
1058 : : }
1059 : :
1060 : : static int
1061 : 0 : cpfl_dev_stop(struct rte_eth_dev *dev)
1062 : : {
1063 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
1064 : 0 : struct idpf_vport *vport = &cpfl_vport->base;
1065 : :
1066 [ # # ]: 0 : if (dev->data->dev_started == 0)
1067 : : return 0;
1068 : :
1069 : 0 : idpf_vc_vport_ena_dis(vport, false);
1070 : :
1071 : 0 : cpfl_stop_queues(dev);
1072 : :
1073 : 0 : idpf_vport_irq_unmap_config(vport, dev->data->nb_rx_queues);
1074 : :
1075 : 0 : idpf_vc_vectors_dealloc(vport);
1076 : :
1077 : 0 : return 0;
1078 : : }
1079 : :
1080 : : static void
1081 : 0 : cpfl_flow_free(struct cpfl_vport *vport)
1082 : : {
1083 : : struct rte_flow *p_flow;
1084 : :
1085 [ # # ]: 0 : while ((p_flow = TAILQ_FIRST(&vport->itf.flow_list))) {
1086 [ # # ]: 0 : TAILQ_REMOVE(&vport->itf.flow_list, p_flow, next);
1087 [ # # ]: 0 : if (p_flow->engine->free)
1088 : 0 : p_flow->engine->free(p_flow);
1089 : 0 : rte_free(p_flow);
1090 : : }
1091 : 0 : }
1092 : :
1093 : : static int
1094 : 0 : cpfl_p2p_queue_grps_del(struct idpf_vport *vport)
1095 : : {
1096 : : struct virtchnl2_queue_group_id qg_ids;
1097 : : int ret = 0;
1098 : :
1099 : : memset(&qg_ids, 0, sizeof(qg_ids));
1100 : 0 : qg_ids.queue_group_id = CPFL_P2P_QUEUE_GRP_ID;
1101 : 0 : qg_ids.queue_group_type = VIRTCHNL2_QUEUE_GROUP_P2P;
1102 : 0 : ret = idpf_vc_queue_grps_del(vport, CPFL_P2P_NB_QUEUE_GRPS, &qg_ids);
1103 [ # # ]: 0 : if (ret)
1104 : 0 : PMD_DRV_LOG(ERR, "Failed to delete p2p queue groups");
1105 : 0 : return ret;
1106 : : }
1107 : :
1108 : : static int
1109 : 0 : cpfl_dev_close(struct rte_eth_dev *dev)
1110 : : {
1111 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
1112 : 0 : struct idpf_vport *vport = &cpfl_vport->base;
1113 : 0 : struct cpfl_adapter_ext *adapter = CPFL_ADAPTER_TO_EXT(vport->adapter);
1114 : :
1115 : 0 : cpfl_dev_stop(dev);
1116 [ # # ]: 0 : if (cpfl_vport->p2p_mp) {
1117 : 0 : rte_mempool_free(cpfl_vport->p2p_mp);
1118 : 0 : cpfl_vport->p2p_mp = NULL;
1119 : : }
1120 : :
1121 [ # # # # ]: 0 : if (!adapter->base.is_rx_singleq && !adapter->base.is_tx_singleq)
1122 : 0 : cpfl_p2p_queue_grps_del(vport);
1123 : :
1124 : 0 : cpfl_flow_free(cpfl_vport);
1125 : 0 : idpf_vport_deinit(vport);
1126 : 0 : rte_free(cpfl_vport->p2p_q_chunks_info);
1127 : :
1128 : 0 : adapter->cur_vports &= ~RTE_BIT32(vport->devarg_id);
1129 : 0 : adapter->cur_vport_nb--;
1130 : 0 : dev->data->dev_private = NULL;
1131 : 0 : adapter->vports[vport->sw_idx] = NULL;
1132 : : idpf_free_dma_mem(NULL, &cpfl_vport->itf.flow_dma);
1133 : 0 : rte_free(cpfl_vport);
1134 : :
1135 : 0 : return 0;
1136 : : }
1137 : :
1138 : : static int
1139 : 0 : cpfl_dev_flow_ops_get(struct rte_eth_dev *dev,
1140 : : const struct rte_flow_ops **ops)
1141 : : {
1142 : : struct cpfl_itf *itf;
1143 : :
1144 [ # # ]: 0 : if (!dev)
1145 : : return -EINVAL;
1146 : :
1147 : 0 : itf = CPFL_DEV_TO_ITF(dev);
1148 : :
1149 : : /* only vport support rte_flow */
1150 [ # # ]: 0 : if (itf->type != CPFL_ITF_TYPE_VPORT)
1151 : : return -ENOTSUP;
1152 : : #ifdef RTE_HAS_JANSSON
1153 : 0 : *ops = &cpfl_flow_ops;
1154 : : #else
1155 : : *ops = NULL;
1156 : : PMD_DRV_LOG(NOTICE, "not support rte_flow, please install json-c library.");
1157 : : #endif
1158 : 0 : return 0;
1159 : : }
1160 : :
1161 : : static int
1162 : 0 : cpfl_hairpin_get_peer_ports(struct rte_eth_dev *dev, uint16_t *peer_ports,
1163 : : size_t len, uint32_t tx)
1164 : : {
1165 : 0 : struct cpfl_vport *cpfl_vport =
1166 : 0 : (struct cpfl_vport *)dev->data->dev_private;
1167 : : struct idpf_tx_queue *txq;
1168 : : struct idpf_rx_queue *rxq;
1169 : : struct cpfl_tx_queue *cpfl_txq;
1170 : : struct cpfl_rx_queue *cpfl_rxq;
1171 : : uint16_t i;
1172 : : uint16_t j = 0;
1173 : :
1174 [ # # ]: 0 : if (len <= 0)
1175 : : return -EINVAL;
1176 : :
1177 [ # # ]: 0 : if (cpfl_vport->p2p_q_chunks_info == NULL)
1178 : : return -ENOTSUP;
1179 : :
1180 [ # # ]: 0 : if (tx > 0) {
1181 [ # # ]: 0 : for (i = cpfl_vport->nb_data_txq, j = 0; i < dev->data->nb_tx_queues; i++, j++) {
1182 : 0 : txq = dev->data->tx_queues[i];
1183 [ # # # # ]: 0 : if (txq == NULL || j >= len)
1184 : : return -EINVAL;
1185 : : cpfl_txq = (struct cpfl_tx_queue *)txq;
1186 : 0 : peer_ports[j] = cpfl_txq->hairpin_info.peer_rxp;
1187 : : }
1188 : : } else if (tx == 0) {
1189 [ # # ]: 0 : for (i = cpfl_vport->nb_data_rxq, j = 0; i < dev->data->nb_rx_queues; i++, j++) {
1190 : 0 : rxq = dev->data->rx_queues[i];
1191 [ # # # # ]: 0 : if (rxq == NULL || j >= len)
1192 : : return -EINVAL;
1193 : : cpfl_rxq = (struct cpfl_rx_queue *)rxq;
1194 : 0 : peer_ports[j] = cpfl_rxq->hairpin_info.peer_txp;
1195 : : }
1196 : : }
1197 : :
1198 : 0 : return j;
1199 : : }
1200 : :
1201 : : static int
1202 : 0 : cpfl_hairpin_bind(struct rte_eth_dev *dev, uint16_t rx_port)
1203 : : {
1204 : 0 : struct cpfl_vport *cpfl_tx_vport = dev->data->dev_private;
1205 : 0 : struct idpf_vport *tx_vport = &cpfl_tx_vport->base;
1206 : : struct cpfl_vport *cpfl_rx_vport;
1207 : : struct cpfl_tx_queue *cpfl_txq;
1208 : : struct cpfl_rx_queue *cpfl_rxq;
1209 : : struct rte_eth_dev *peer_dev;
1210 : : struct idpf_vport *rx_vport;
1211 : : int err = 0;
1212 : : int i;
1213 : :
1214 : 0 : err = cpfl_txq_hairpin_info_update(dev, rx_port);
1215 [ # # ]: 0 : if (err != 0) {
1216 : 0 : PMD_DRV_LOG(ERR, "Fail to update Tx hairpin queue info.");
1217 : 0 : return err;
1218 : : }
1219 : :
1220 : : /* configure hairpin queues */
1221 [ # # ]: 0 : for (i = cpfl_tx_vport->nb_data_txq; i < dev->data->nb_tx_queues; i++) {
1222 : 0 : cpfl_txq = dev->data->tx_queues[i];
1223 : 0 : err = cpfl_hairpin_txq_config(tx_vport, cpfl_txq);
1224 [ # # ]: 0 : if (err != 0) {
1225 : 0 : PMD_DRV_LOG(ERR, "Fail to configure hairpin Tx queue %u", i);
1226 : 0 : return err;
1227 : : }
1228 : : }
1229 : :
1230 : 0 : err = cpfl_hairpin_tx_complq_config(cpfl_tx_vport);
1231 [ # # ]: 0 : if (err != 0) {
1232 : 0 : PMD_DRV_LOG(ERR, "Fail to config Tx completion queue");
1233 : 0 : return err;
1234 : : }
1235 : :
1236 : 0 : peer_dev = &rte_eth_devices[rx_port];
1237 : 0 : cpfl_rx_vport = (struct cpfl_vport *)peer_dev->data->dev_private;
1238 : 0 : rx_vport = &cpfl_rx_vport->base;
1239 : 0 : cpfl_rxq_hairpin_mz_bind(peer_dev);
1240 : :
1241 : 0 : err = cpfl_hairpin_rx_bufq_config(cpfl_rx_vport);
1242 [ # # ]: 0 : if (err != 0) {
1243 : 0 : PMD_DRV_LOG(ERR, "Fail to config Rx buffer queue");
1244 : 0 : return err;
1245 : : }
1246 : :
1247 [ # # ]: 0 : for (i = cpfl_rx_vport->nb_data_rxq; i < peer_dev->data->nb_rx_queues; i++) {
1248 : 0 : cpfl_rxq = peer_dev->data->rx_queues[i];
1249 : 0 : err = cpfl_hairpin_rxq_config(rx_vport, cpfl_rxq);
1250 [ # # ]: 0 : if (err != 0) {
1251 : 0 : PMD_DRV_LOG(ERR, "Fail to configure hairpin Rx queue %u", i);
1252 : 0 : return err;
1253 : : }
1254 : 0 : err = cpfl_rx_queue_init(peer_dev, i);
1255 [ # # ]: 0 : if (err != 0) {
1256 : 0 : PMD_DRV_LOG(ERR, "Fail to init hairpin Rx queue %u", i);
1257 : 0 : return err;
1258 : : }
1259 : : }
1260 : :
1261 : : /* enable hairpin queues */
1262 [ # # ]: 0 : for (i = cpfl_tx_vport->nb_data_txq; i < dev->data->nb_tx_queues; i++) {
1263 : 0 : cpfl_txq = dev->data->tx_queues[i];
1264 : 0 : err = cpfl_switch_hairpin_rxtx_queue(cpfl_tx_vport,
1265 : 0 : i - cpfl_tx_vport->nb_data_txq,
1266 : : false, true);
1267 [ # # ]: 0 : if (err != 0) {
1268 : 0 : PMD_DRV_LOG(ERR, "Failed to switch hairpin TX queue %u on",
1269 : : i);
1270 : 0 : return err;
1271 : : }
1272 : 0 : cpfl_txq->base.q_started = true;
1273 : : }
1274 : :
1275 : 0 : err = cpfl_switch_hairpin_complq(cpfl_tx_vport, true);
1276 [ # # ]: 0 : if (err != 0) {
1277 : 0 : PMD_DRV_LOG(ERR, "Failed to switch hairpin Tx complq");
1278 : 0 : return err;
1279 : : }
1280 : :
1281 [ # # ]: 0 : for (i = cpfl_rx_vport->nb_data_rxq; i < peer_dev->data->nb_rx_queues; i++) {
1282 : 0 : cpfl_rxq = peer_dev->data->rx_queues[i];
1283 : 0 : err = cpfl_switch_hairpin_rxtx_queue(cpfl_rx_vport,
1284 : 0 : i - cpfl_rx_vport->nb_data_rxq,
1285 : : true, true);
1286 [ # # ]: 0 : if (err != 0) {
1287 : 0 : PMD_DRV_LOG(ERR, "Failed to switch hairpin RX queue %u on",
1288 : : i);
1289 : : }
1290 : 0 : cpfl_rxq->base.q_started = true;
1291 : : }
1292 : :
1293 : 0 : err = cpfl_switch_hairpin_bufq(cpfl_rx_vport, true);
1294 [ # # ]: 0 : if (err != 0) {
1295 : 0 : PMD_DRV_LOG(ERR, "Failed to switch hairpin Rx buffer queue");
1296 : 0 : return err;
1297 : : }
1298 : :
1299 : : return 0;
1300 : : }
1301 : :
1302 : : static int
1303 : 0 : cpfl_hairpin_unbind(struct rte_eth_dev *dev, uint16_t rx_port)
1304 : : {
1305 : 0 : struct cpfl_vport *cpfl_tx_vport = dev->data->dev_private;
1306 : 0 : struct rte_eth_dev *peer_dev = &rte_eth_devices[rx_port];
1307 : 0 : struct cpfl_vport *cpfl_rx_vport = peer_dev->data->dev_private;
1308 : : struct cpfl_tx_queue *cpfl_txq;
1309 : : struct cpfl_rx_queue *cpfl_rxq;
1310 : : int i;
1311 : :
1312 : : /* disable hairpin queues */
1313 [ # # ]: 0 : for (i = cpfl_tx_vport->nb_data_txq; i < dev->data->nb_tx_queues; i++) {
1314 : 0 : cpfl_txq = dev->data->tx_queues[i];
1315 : 0 : cpfl_switch_hairpin_rxtx_queue(cpfl_tx_vport,
1316 : 0 : i - cpfl_tx_vport->nb_data_txq,
1317 : : false, false);
1318 : 0 : cpfl_txq->base.q_started = false;
1319 : : }
1320 : :
1321 : 0 : cpfl_switch_hairpin_complq(cpfl_tx_vport, false);
1322 : :
1323 [ # # ]: 0 : for (i = cpfl_rx_vport->nb_data_rxq; i < peer_dev->data->nb_rx_queues; i++) {
1324 : 0 : cpfl_rxq = peer_dev->data->rx_queues[i];
1325 : 0 : cpfl_switch_hairpin_rxtx_queue(cpfl_rx_vport,
1326 : 0 : i - cpfl_rx_vport->nb_data_rxq,
1327 : : true, false);
1328 : 0 : cpfl_rxq->base.q_started = false;
1329 : : }
1330 : :
1331 : 0 : cpfl_switch_hairpin_bufq(cpfl_rx_vport, false);
1332 : :
1333 : 0 : return 0;
1334 : : }
1335 : :
1336 : : static const struct eth_dev_ops cpfl_eth_dev_ops = {
1337 : : .dev_configure = cpfl_dev_configure,
1338 : : .dev_close = cpfl_dev_close,
1339 : : .rx_queue_setup = cpfl_rx_queue_setup,
1340 : : .tx_queue_setup = cpfl_tx_queue_setup,
1341 : : .dev_infos_get = cpfl_dev_info_get,
1342 : : .dev_start = cpfl_dev_start,
1343 : : .dev_stop = cpfl_dev_stop,
1344 : : .link_update = cpfl_dev_link_update,
1345 : : .rx_queue_start = cpfl_rx_queue_start,
1346 : : .tx_queue_start = cpfl_tx_queue_start,
1347 : : .rx_queue_stop = cpfl_rx_queue_stop,
1348 : : .tx_queue_stop = cpfl_tx_queue_stop,
1349 : : .rx_queue_release = cpfl_dev_rx_queue_release,
1350 : : .tx_queue_release = cpfl_dev_tx_queue_release,
1351 : : .mtu_set = cpfl_dev_mtu_set,
1352 : : .dev_supported_ptypes_get = cpfl_dev_supported_ptypes_get,
1353 : : .stats_get = cpfl_dev_stats_get,
1354 : : .stats_reset = cpfl_dev_stats_reset,
1355 : : .reta_update = cpfl_rss_reta_update,
1356 : : .reta_query = cpfl_rss_reta_query,
1357 : : .rss_hash_update = cpfl_rss_hash_update,
1358 : : .rss_hash_conf_get = cpfl_rss_hash_conf_get,
1359 : : .xstats_get = cpfl_dev_xstats_get,
1360 : : .xstats_get_names = cpfl_dev_xstats_get_names,
1361 : : .xstats_reset = cpfl_dev_xstats_reset,
1362 : : .flow_ops_get = cpfl_dev_flow_ops_get,
1363 : : .hairpin_cap_get = cpfl_hairpin_cap_get,
1364 : : .rx_hairpin_queue_setup = cpfl_rx_hairpin_queue_setup,
1365 : : .tx_hairpin_queue_setup = cpfl_tx_hairpin_queue_setup,
1366 : : .hairpin_get_peer_ports = cpfl_hairpin_get_peer_ports,
1367 : : .hairpin_bind = cpfl_hairpin_bind,
1368 : : .hairpin_unbind = cpfl_hairpin_unbind,
1369 : : };
1370 : :
1371 : : static int
1372 : : insert_value(struct cpfl_devargs *devargs, uint16_t id)
1373 : : {
1374 : : uint16_t i;
1375 : :
1376 : : /* ignore duplicate */
1377 [ # # # # ]: 0 : for (i = 0; i < devargs->req_vport_nb; i++) {
1378 [ # # # # ]: 0 : if (devargs->req_vports[i] == id)
1379 : : return 0;
1380 : : }
1381 : :
1382 : 0 : devargs->req_vports[devargs->req_vport_nb] = id;
1383 : 0 : devargs->req_vport_nb++;
1384 : :
1385 : 0 : return 0;
1386 : : }
1387 : :
1388 : : static const char *
1389 : 0 : parse_range(const char *value, struct cpfl_devargs *devargs)
1390 : : {
1391 : : uint16_t lo, hi, i;
1392 : 0 : int n = 0;
1393 : : int result;
1394 : : const char *pos = value;
1395 : :
1396 : 0 : result = sscanf(value, "%hu%n-%hu%n", &lo, &n, &hi, &n);
1397 [ # # ]: 0 : if (result == 1) {
1398 : 0 : if (insert_value(devargs, lo) != 0)
1399 : : return NULL;
1400 [ # # ]: 0 : } else if (result == 2) {
1401 [ # # ]: 0 : if (lo > hi)
1402 : : return NULL;
1403 [ # # ]: 0 : for (i = lo; i <= hi; i++) {
1404 : : if (insert_value(devargs, i) != 0)
1405 : : return NULL;
1406 : : }
1407 : : } else {
1408 : : return NULL;
1409 : : }
1410 : :
1411 : 0 : return pos + n;
1412 : : }
1413 : :
1414 : : static int
1415 : 0 : parse_vport(const char *key, const char *value, void *args)
1416 : : {
1417 : : struct cpfl_devargs *devargs = args;
1418 : : const char *pos = value;
1419 : :
1420 : 0 : devargs->req_vport_nb = 0;
1421 : :
1422 [ # # ]: 0 : if (*pos == '[')
1423 : 0 : pos++;
1424 : :
1425 : : while (1) {
1426 : 0 : pos = parse_range(pos, devargs);
1427 [ # # ]: 0 : if (pos == NULL) {
1428 : 0 : PMD_INIT_LOG(ERR, "invalid value:\"%s\" for key:\"%s\", ",
1429 : : value, key);
1430 : 0 : return -EINVAL;
1431 : : }
1432 [ # # ]: 0 : if (*pos != ',')
1433 : : break;
1434 : 0 : pos++;
1435 : : }
1436 : :
1437 [ # # # # ]: 0 : if (*value == '[' && *pos != ']') {
1438 : 0 : PMD_INIT_LOG(ERR, "invalid value:\"%s\" for key:\"%s\", ",
1439 : : value, key);
1440 : 0 : return -EINVAL;
1441 : : }
1442 : :
1443 : : return 0;
1444 : : }
1445 : :
1446 : : static int
1447 : 0 : parse_bool(const char *key, const char *value, void *args)
1448 : : {
1449 : : int *i = args;
1450 : : char *end;
1451 : : int num;
1452 : :
1453 : 0 : errno = 0;
1454 : :
1455 : 0 : num = strtoul(value, &end, 10);
1456 : :
1457 [ # # # # ]: 0 : if (errno == ERANGE || (num != 0 && num != 1)) {
1458 : 0 : PMD_INIT_LOG(ERR, "invalid value:\"%s\" for key:\"%s\", value must be 0 or 1",
1459 : : value, key);
1460 : 0 : return -EINVAL;
1461 : : }
1462 : :
1463 : 0 : *i = num;
1464 : 0 : return 0;
1465 : : }
1466 : :
1467 : : static int
1468 : : enlist(uint16_t *list, uint16_t *len_list, const uint16_t max_list, uint16_t val)
1469 : : {
1470 : : uint16_t i;
1471 : :
1472 [ # # # # ]: 0 : for (i = 0; i < *len_list; i++) {
1473 [ # # # # ]: 0 : if (list[i] == val)
1474 : : return 0;
1475 : : }
1476 [ # # # # ]: 0 : if (*len_list >= max_list)
1477 : : return -1;
1478 : 0 : list[(*len_list)++] = val;
1479 : : return 0;
1480 : : }
1481 : :
1482 : : static const char *
1483 : 0 : process_range(const char *str, uint16_t *list, uint16_t *len_list,
1484 : : const uint16_t max_list)
1485 : : {
1486 : : uint16_t lo, hi, val;
1487 : 0 : int result, n = 0;
1488 : : const char *pos = str;
1489 : :
1490 : 0 : result = sscanf(str, "%hu%n-%hu%n", &lo, &n, &hi, &n);
1491 [ # # ]: 0 : if (result == 1) {
1492 : 0 : if (enlist(list, len_list, max_list, lo) != 0)
1493 : : return NULL;
1494 [ # # ]: 0 : } else if (result == 2) {
1495 [ # # ]: 0 : if (lo > hi)
1496 : : return NULL;
1497 [ # # ]: 0 : for (val = lo; val <= hi; val++) {
1498 : : if (enlist(list, len_list, max_list, val) != 0)
1499 : : return NULL;
1500 : : }
1501 : : } else {
1502 : : return NULL;
1503 : : }
1504 : 0 : return pos + n;
1505 : : }
1506 : :
1507 : : static const char *
1508 : 0 : process_list(const char *str, uint16_t *list, uint16_t *len_list, const uint16_t max_list)
1509 : : {
1510 : : const char *pos = str;
1511 : :
1512 [ # # ]: 0 : if (*pos == '[')
1513 : 0 : pos++;
1514 : : while (1) {
1515 : 0 : pos = process_range(pos, list, len_list, max_list);
1516 [ # # ]: 0 : if (pos == NULL)
1517 : : return NULL;
1518 [ # # ]: 0 : if (*pos != ',') /* end of list */
1519 : : break;
1520 : 0 : pos++;
1521 : : }
1522 [ # # # # ]: 0 : if (*str == '[' && *pos != ']')
1523 : : return NULL;
1524 [ # # ]: 0 : if (*pos == ']')
1525 : 0 : pos++;
1526 : : return pos;
1527 : : }
1528 : :
1529 : : static int
1530 : 0 : parse_repr(const char *key __rte_unused, const char *value, void *args)
1531 : : {
1532 : : struct cpfl_devargs *devargs = args;
1533 : : struct rte_eth_devargs *eth_da;
1534 : : const char *str = value;
1535 : :
1536 [ # # ]: 0 : if (devargs->repr_args_num == CPFL_REPR_ARG_NUM_MAX)
1537 : : return -EINVAL;
1538 : :
1539 : 0 : eth_da = &devargs->repr_args[devargs->repr_args_num];
1540 : :
1541 [ # # ]: 0 : if (str[0] == 'c') {
1542 : 0 : str += 1;
1543 : 0 : str = process_list(str, eth_da->mh_controllers,
1544 : : ð_da->nb_mh_controllers,
1545 : : RTE_DIM(eth_da->mh_controllers));
1546 [ # # ]: 0 : if (str == NULL)
1547 : 0 : goto done;
1548 : : }
1549 [ # # # # ]: 0 : if (str[0] == 'p' && str[1] == 'f') {
1550 : 0 : eth_da->type = RTE_ETH_REPRESENTOR_PF;
1551 : 0 : str += 2;
1552 : 0 : str = process_list(str, eth_da->ports,
1553 : : ð_da->nb_ports, RTE_DIM(eth_da->ports));
1554 [ # # # # ]: 0 : if (str == NULL || str[0] == '\0')
1555 : 0 : goto done;
1556 [ # # ]: 0 : } else if (eth_da->nb_mh_controllers > 0) {
1557 : : /* 'c' must followed by 'pf'. */
1558 : : str = NULL;
1559 : 0 : goto done;
1560 : : }
1561 [ # # # # ]: 0 : if (str[0] == 'v' && str[1] == 'f') {
1562 : 0 : eth_da->type = RTE_ETH_REPRESENTOR_VF;
1563 : 0 : str += 2;
1564 [ # # # # ]: 0 : } else if (str[0] == 's' && str[1] == 'f') {
1565 : 0 : eth_da->type = RTE_ETH_REPRESENTOR_SF;
1566 : 0 : str += 2;
1567 : : } else {
1568 : : /* 'pf' must followed by 'vf' or 'sf'. */
1569 [ # # ]: 0 : if (eth_da->type == RTE_ETH_REPRESENTOR_PF) {
1570 : : str = NULL;
1571 : 0 : goto done;
1572 : : }
1573 : 0 : eth_da->type = RTE_ETH_REPRESENTOR_VF;
1574 : : }
1575 : 0 : str = process_list(str, eth_da->representor_ports,
1576 : : ð_da->nb_representor_ports,
1577 : : RTE_DIM(eth_da->representor_ports));
1578 : 0 : done:
1579 [ # # ]: 0 : if (str == NULL) {
1580 : 0 : RTE_LOG(ERR, EAL, "wrong representor format: %s\n", str);
1581 : 0 : return -1;
1582 : : }
1583 : :
1584 : 0 : devargs->repr_args_num++;
1585 : :
1586 : 0 : return 0;
1587 : : }
1588 : :
1589 : : #ifdef RTE_HAS_JANSSON
1590 : : static int
1591 : 0 : parse_file(const char *key, const char *value, void *args)
1592 : : {
1593 : : char *name = args;
1594 : :
1595 [ # # ]: 0 : if (strlen(value) > CPFL_FLOW_FILE_LEN - 1) {
1596 : 0 : PMD_DRV_LOG(ERR, "file path(%s) is too long.", value);
1597 : 0 : return -1;
1598 : : }
1599 : :
1600 : 0 : PMD_DRV_LOG(DEBUG, "value:\"%s\" for key:\"%s\"", value, key);
1601 : : strlcpy(name, value, CPFL_FLOW_FILE_LEN);
1602 : :
1603 : 0 : return 0;
1604 : : }
1605 : : #endif
1606 : :
1607 : : static int
1608 : 0 : cpfl_parse_devargs(struct rte_pci_device *pci_dev, struct cpfl_adapter_ext *adapter,
1609 : : bool first, struct cpfl_devargs *cpfl_args)
1610 : : {
1611 : 0 : struct rte_devargs *devargs = pci_dev->device.devargs;
1612 : : struct rte_kvargs *kvlist;
1613 : : int ret;
1614 : :
1615 [ # # ]: 0 : if (devargs == NULL)
1616 : : return 0;
1617 : :
1618 [ # # ]: 0 : kvlist = rte_kvargs_parse(devargs->args,
1619 : : first ? cpfl_valid_args_first : cpfl_valid_args_again);
1620 [ # # ]: 0 : if (kvlist == NULL) {
1621 : 0 : PMD_INIT_LOG(ERR, "invalid kvargs key");
1622 : 0 : return -EINVAL;
1623 : : }
1624 : :
1625 [ # # ]: 0 : if (rte_kvargs_count(kvlist, CPFL_VPORT) > 1) {
1626 : 0 : PMD_INIT_LOG(ERR, "devarg vport is duplicated.");
1627 : : ret = -EINVAL;
1628 : 0 : goto fail;
1629 : : }
1630 : :
1631 : 0 : ret = rte_kvargs_process(kvlist, CPFL_REPRESENTOR, &parse_repr, cpfl_args);
1632 : :
1633 [ # # ]: 0 : if (ret != 0)
1634 : 0 : goto fail;
1635 : :
1636 [ # # ]: 0 : if (!first)
1637 : 0 : goto finish;
1638 : :
1639 : 0 : ret = rte_kvargs_process(kvlist, CPFL_VPORT, &parse_vport,
1640 : : cpfl_args);
1641 [ # # ]: 0 : if (ret != 0)
1642 : 0 : goto fail;
1643 : :
1644 : 0 : ret = rte_kvargs_process(kvlist, CPFL_TX_SINGLE_Q, &parse_bool,
1645 : 0 : &adapter->base.is_tx_singleq);
1646 [ # # ]: 0 : if (ret != 0)
1647 : 0 : goto fail;
1648 : :
1649 : 0 : ret = rte_kvargs_process(kvlist, CPFL_RX_SINGLE_Q, &parse_bool,
1650 : 0 : &adapter->base.is_rx_singleq);
1651 [ # # ]: 0 : if (ret != 0)
1652 : 0 : goto fail;
1653 : : #ifdef RTE_HAS_JANSSON
1654 [ # # ]: 0 : if (rte_kvargs_get(kvlist, CPFL_FLOW_PARSER)) {
1655 : 0 : ret = rte_kvargs_process(kvlist, CPFL_FLOW_PARSER,
1656 : 0 : &parse_file, cpfl_args->flow_parser);
1657 [ # # ]: 0 : if (ret) {
1658 : 0 : PMD_DRV_LOG(ERR, "Failed to parser flow_parser, ret: %d", ret);
1659 : 0 : goto fail;
1660 : : }
1661 : : } else {
1662 : 0 : cpfl_args->flow_parser[0] = '\0';
1663 : : }
1664 : : #endif
1665 : 0 : finish:
1666 : 0 : fail:
1667 : 0 : rte_kvargs_free(kvlist);
1668 : 0 : return ret;
1669 : : }
1670 : :
1671 : : static struct cpfl_vport *
1672 : : cpfl_find_vport(struct cpfl_adapter_ext *adapter, uint32_t vport_id)
1673 : : {
1674 : : struct cpfl_vport *vport = NULL;
1675 : : int i;
1676 : :
1677 [ # # ]: 0 : for (i = 0; i < adapter->cur_vport_nb; i++) {
1678 : 0 : vport = adapter->vports[i];
1679 [ # # ]: 0 : if (vport == NULL)
1680 : 0 : continue;
1681 [ # # ]: 0 : if (vport->base.vport_id != vport_id)
1682 : 0 : continue;
1683 : : else
1684 : : return vport;
1685 : : }
1686 : :
1687 : : return NULL;
1688 : : }
1689 : :
1690 : : static void
1691 : 0 : cpfl_handle_vchnl_event_msg(struct cpfl_adapter_ext *adapter, uint8_t *msg, uint16_t msglen)
1692 : : {
1693 : : struct virtchnl2_event *vc_event = (struct virtchnl2_event *)msg;
1694 : : struct cpfl_vport *vport;
1695 : : struct rte_eth_dev_data *data;
1696 : : struct rte_eth_dev *dev;
1697 : :
1698 [ # # ]: 0 : if (msglen < sizeof(struct virtchnl2_event)) {
1699 : 0 : PMD_DRV_LOG(ERR, "Error event");
1700 : 0 : return;
1701 : : }
1702 : :
1703 : : /* ignore if it is ctrl vport */
1704 [ # # ]: 0 : if (adapter->ctrl_vport.base.vport_id == vc_event->vport_id)
1705 : : return;
1706 : :
1707 : : vport = cpfl_find_vport(adapter, vc_event->vport_id);
1708 [ # # ]: 0 : if (!vport) {
1709 : 0 : PMD_DRV_LOG(ERR, "Can't find vport.");
1710 : 0 : return;
1711 : : }
1712 : :
1713 : 0 : data = vport->itf.data;
1714 : 0 : dev = &rte_eth_devices[data->port_id];
1715 : :
1716 [ # # ]: 0 : switch (vc_event->event) {
1717 : 0 : case VIRTCHNL2_EVENT_LINK_CHANGE:
1718 : 0 : PMD_DRV_LOG(DEBUG, "VIRTCHNL2_EVENT_LINK_CHANGE");
1719 : 0 : vport->base.link_up = !!(vc_event->link_status);
1720 : 0 : vport->base.link_speed = vc_event->link_speed;
1721 : 0 : cpfl_dev_link_update(dev, 0);
1722 : 0 : break;
1723 : 0 : default:
1724 : 0 : PMD_DRV_LOG(ERR, " unknown event received %u", vc_event->event);
1725 : 0 : break;
1726 : : }
1727 : : }
1728 : :
1729 : : int
1730 : 0 : cpfl_vport_info_create(struct cpfl_adapter_ext *adapter,
1731 : : struct cpfl_vport_id *vport_identity,
1732 : : struct cpchnl2_event_vport_created *vport_created)
1733 : : {
1734 : 0 : struct cpfl_vport_info *info = NULL;
1735 : : int ret;
1736 : :
1737 : 0 : rte_spinlock_lock(&adapter->vport_map_lock);
1738 : 0 : ret = rte_hash_lookup_data(adapter->vport_map_hash, vport_identity, (void **)&info);
1739 [ # # ]: 0 : if (ret >= 0) {
1740 : 0 : PMD_DRV_LOG(WARNING, "vport already exist, overwrite info anyway");
1741 : : /* overwrite info */
1742 [ # # ]: 0 : if (info)
1743 : 0 : info->vport = *vport_created;
1744 : 0 : goto fini;
1745 : : }
1746 : :
1747 : 0 : info = rte_zmalloc(NULL, sizeof(*info), 0);
1748 [ # # ]: 0 : if (info == NULL) {
1749 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory for vport map info");
1750 : : ret = -ENOMEM;
1751 : 0 : goto err;
1752 : : }
1753 : :
1754 : 0 : info->vport = *vport_created;
1755 : :
1756 : 0 : ret = rte_hash_add_key_data(adapter->vport_map_hash, vport_identity, info);
1757 [ # # ]: 0 : if (ret < 0) {
1758 : 0 : PMD_DRV_LOG(ERR, "Failed to add vport map into hash");
1759 : 0 : rte_free(info);
1760 : 0 : goto err;
1761 : : }
1762 : :
1763 : 0 : fini:
1764 : : rte_spinlock_unlock(&adapter->vport_map_lock);
1765 : 0 : return 0;
1766 : 0 : err:
1767 : : rte_spinlock_unlock(&adapter->vport_map_lock);
1768 : 0 : return ret;
1769 : : }
1770 : :
1771 : : static int
1772 : 0 : cpfl_vport_info_destroy(struct cpfl_adapter_ext *adapter, struct cpfl_vport_id *vport_identity)
1773 : : {
1774 : : struct cpfl_vport_info *info;
1775 : : int ret;
1776 : :
1777 : 0 : rte_spinlock_lock(&adapter->vport_map_lock);
1778 : 0 : ret = rte_hash_lookup_data(adapter->vport_map_hash, vport_identity, (void **)&info);
1779 [ # # ]: 0 : if (ret < 0) {
1780 : 0 : PMD_DRV_LOG(ERR, "vport id doesn't exist");
1781 : 0 : goto err;
1782 : : }
1783 : :
1784 : 0 : rte_hash_del_key(adapter->vport_map_hash, vport_identity);
1785 : : rte_spinlock_unlock(&adapter->vport_map_lock);
1786 : 0 : rte_free(info);
1787 : :
1788 : 0 : return 0;
1789 : :
1790 : : err:
1791 : : rte_spinlock_unlock(&adapter->vport_map_lock);
1792 : 0 : return ret;
1793 : : }
1794 : :
1795 : : static void
1796 : 0 : cpfl_handle_cpchnl_event_msg(struct cpfl_adapter_ext *adapter, uint8_t *msg, uint16_t msglen)
1797 : : {
1798 : : struct cpchnl2_event_info *cpchnl2_event = (struct cpchnl2_event_info *)msg;
1799 : : struct cpchnl2_event_vport_created *vport_created;
1800 : 0 : struct cpfl_vport_id vport_identity = { 0 };
1801 : :
1802 [ # # ]: 0 : if (msglen < sizeof(struct cpchnl2_event_info)) {
1803 : 0 : PMD_DRV_LOG(ERR, "Error event");
1804 : 0 : return;
1805 : : }
1806 : :
1807 [ # # # ]: 0 : switch (cpchnl2_event->header.type) {
1808 : 0 : case CPCHNL2_EVENT_VPORT_CREATED:
1809 : 0 : vport_identity.vport_id = cpchnl2_event->data.vport_created.vport.vport_id;
1810 : 0 : vport_created = &cpchnl2_event->data.vport_created;
1811 : 0 : vport_identity.func_type = vport_created->info.func_type;
1812 : 0 : vport_identity.pf_id = vport_created->info.pf_id;
1813 : 0 : vport_identity.vf_id = vport_created->info.vf_id;
1814 [ # # ]: 0 : if (cpfl_vport_info_create(adapter, &vport_identity, vport_created))
1815 : 0 : PMD_DRV_LOG(WARNING, "Failed to handle CPCHNL2_EVENT_VPORT_CREATED");
1816 : : break;
1817 : 0 : case CPCHNL2_EVENT_VPORT_DESTROYED:
1818 : 0 : vport_identity.vport_id = cpchnl2_event->data.vport_destroyed.vport.vport_id;
1819 : 0 : vport_identity.func_type = cpchnl2_event->data.vport_destroyed.func.func_type;
1820 : 0 : vport_identity.pf_id = cpchnl2_event->data.vport_destroyed.func.pf_id;
1821 : 0 : vport_identity.vf_id = cpchnl2_event->data.vport_destroyed.func.vf_id;
1822 [ # # ]: 0 : if (cpfl_vport_info_destroy(adapter, &vport_identity))
1823 : 0 : PMD_DRV_LOG(WARNING, "Failed to handle CPCHNL2_EVENT_VPORT_DESTROY");
1824 : : break;
1825 : 0 : default:
1826 : 0 : PMD_DRV_LOG(ERR, " unknown event received %u", cpchnl2_event->header.type);
1827 : 0 : break;
1828 : : }
1829 : : }
1830 : :
1831 : : static void
1832 : 0 : cpfl_handle_virtchnl_msg(struct cpfl_adapter_ext *adapter)
1833 : : {
1834 : : struct idpf_adapter *base = &adapter->base;
1835 : 0 : struct idpf_dma_mem *dma_mem = NULL;
1836 : 0 : struct idpf_hw *hw = &base->hw;
1837 : : struct idpf_ctlq_msg ctlq_msg;
1838 : : enum idpf_mbx_opc mbx_op;
1839 : 0 : uint16_t pending = 1;
1840 : : uint32_t vc_op;
1841 : : int ret;
1842 : :
1843 [ # # ]: 0 : while (pending) {
1844 : 0 : ret = idpf_vc_ctlq_recv(hw->arq, &pending, &ctlq_msg);
1845 [ # # ]: 0 : if (ret) {
1846 : 0 : PMD_DRV_LOG(INFO, "Failed to read msg from virtual channel, ret: %d", ret);
1847 : 0 : return;
1848 : : }
1849 : :
1850 [ # # ]: 0 : memcpy(base->mbx_resp, ctlq_msg.ctx.indirect.payload->va,
1851 : : IDPF_DFLT_MBX_BUF_SIZE);
1852 : :
1853 : 0 : mbx_op = rte_le_to_cpu_16(ctlq_msg.opcode);
1854 : 0 : vc_op = rte_le_to_cpu_32(ctlq_msg.cookie.mbx.chnl_opcode);
1855 : 0 : base->cmd_retval = rte_le_to_cpu_32(ctlq_msg.cookie.mbx.chnl_retval);
1856 : :
1857 [ # # ]: 0 : switch (mbx_op) {
1858 : 0 : case idpf_mbq_opc_send_msg_to_peer_pf:
1859 [ # # ]: 0 : if (vc_op == VIRTCHNL2_OP_EVENT) {
1860 : 0 : cpfl_handle_vchnl_event_msg(adapter, adapter->base.mbx_resp,
1861 : 0 : ctlq_msg.data_len);
1862 [ # # ]: 0 : } else if (vc_op == CPCHNL2_OP_EVENT) {
1863 : 0 : cpfl_handle_cpchnl_event_msg(adapter, adapter->base.mbx_resp,
1864 : 0 : ctlq_msg.data_len);
1865 : : } else {
1866 [ # # ]: 0 : if (vc_op == base->pend_cmd)
1867 : : notify_cmd(base, base->cmd_retval);
1868 : : else
1869 : 0 : PMD_DRV_LOG(ERR, "command mismatch, expect %u, get %u",
1870 : : base->pend_cmd, vc_op);
1871 : :
1872 : 0 : PMD_DRV_LOG(DEBUG, " Virtual channel response is received,"
1873 : : "opcode = %d", vc_op);
1874 : : }
1875 : 0 : goto post_buf;
1876 : 0 : default:
1877 : 0 : PMD_DRV_LOG(DEBUG, "Request %u is not supported yet", mbx_op);
1878 : : }
1879 : : }
1880 : :
1881 : 0 : post_buf:
1882 [ # # ]: 0 : if (ctlq_msg.data_len)
1883 : 0 : dma_mem = ctlq_msg.ctx.indirect.payload;
1884 : : else
1885 : 0 : pending = 0;
1886 : :
1887 : 0 : ret = idpf_vc_ctlq_post_rx_buffs(hw, hw->arq, &pending, &dma_mem);
1888 [ # # # # ]: 0 : if (ret && dma_mem)
1889 : : idpf_free_dma_mem(hw, dma_mem);
1890 : : }
1891 : :
1892 : : static void
1893 : 0 : cpfl_dev_alarm_handler(void *param)
1894 : : {
1895 : : struct cpfl_adapter_ext *adapter = param;
1896 : :
1897 : 0 : cpfl_handle_virtchnl_msg(adapter);
1898 : :
1899 : 0 : rte_eal_alarm_set(CPFL_ALARM_INTERVAL, cpfl_dev_alarm_handler, adapter);
1900 : 0 : }
1901 : :
1902 : : static int
1903 : 0 : cpfl_stop_cfgqs(struct cpfl_adapter_ext *adapter)
1904 : : {
1905 : : int i, ret;
1906 : :
1907 [ # # ]: 0 : for (i = 0; i < CPFL_TX_CFGQ_NUM; i++) {
1908 : 0 : ret = idpf_vc_queue_switch(&adapter->ctrl_vport.base, i, false, false);
1909 [ # # ]: 0 : if (ret) {
1910 : 0 : PMD_DRV_LOG(ERR, "Fail to disable Tx config queue.");
1911 : 0 : return ret;
1912 : : }
1913 : : }
1914 : :
1915 [ # # ]: 0 : for (i = 0; i < CPFL_RX_CFGQ_NUM; i++) {
1916 : 0 : ret = idpf_vc_queue_switch(&adapter->ctrl_vport.base, i, true, false);
1917 [ # # ]: 0 : if (ret) {
1918 : 0 : PMD_DRV_LOG(ERR, "Fail to disable Rx config queue.");
1919 : 0 : return ret;
1920 : : }
1921 : : }
1922 : :
1923 : : return 0;
1924 : : }
1925 : :
1926 : : static int
1927 : 0 : cpfl_start_cfgqs(struct cpfl_adapter_ext *adapter)
1928 : : {
1929 : : int i, ret;
1930 : :
1931 : 0 : ret = cpfl_config_ctlq_tx(adapter);
1932 [ # # ]: 0 : if (ret) {
1933 : 0 : PMD_DRV_LOG(ERR, "Fail to configure Tx config queue.");
1934 : 0 : return ret;
1935 : : }
1936 : :
1937 : 0 : ret = cpfl_config_ctlq_rx(adapter);
1938 [ # # ]: 0 : if (ret) {
1939 : 0 : PMD_DRV_LOG(ERR, "Fail to configure Rx config queue.");
1940 : 0 : return ret;
1941 : : }
1942 : :
1943 [ # # ]: 0 : for (i = 0; i < CPFL_TX_CFGQ_NUM; i++) {
1944 : 0 : ret = idpf_vc_queue_switch(&adapter->ctrl_vport.base, i, false, true);
1945 [ # # ]: 0 : if (ret) {
1946 : 0 : PMD_DRV_LOG(ERR, "Fail to enable Tx config queue.");
1947 : 0 : return ret;
1948 : : }
1949 : : }
1950 : :
1951 [ # # ]: 0 : for (i = 0; i < CPFL_RX_CFGQ_NUM; i++) {
1952 : 0 : ret = idpf_vc_queue_switch(&adapter->ctrl_vport.base, i, true, true);
1953 [ # # ]: 0 : if (ret) {
1954 : 0 : PMD_DRV_LOG(ERR, "Fail to enable Rx config queue.");
1955 : 0 : return ret;
1956 : : }
1957 : : }
1958 : :
1959 : : return 0;
1960 : : }
1961 : :
1962 : : static void
1963 : 0 : cpfl_remove_cfgqs(struct cpfl_adapter_ext *adapter)
1964 : : {
1965 : 0 : struct idpf_hw *hw = (struct idpf_hw *)(&adapter->base.hw);
1966 : : struct cpfl_ctlq_create_info *create_cfgq_info;
1967 : : int i;
1968 : :
1969 : 0 : create_cfgq_info = adapter->cfgq_info;
1970 : :
1971 [ # # ]: 0 : for (i = 0; i < CPFL_CFGQ_NUM; i++) {
1972 [ # # ]: 0 : if (adapter->ctlqp[i])
1973 : 0 : cpfl_vport_ctlq_remove(hw, adapter->ctlqp[i]);
1974 [ # # ]: 0 : if (create_cfgq_info[i].ring_mem.va)
1975 : : idpf_free_dma_mem(&adapter->base.hw, &create_cfgq_info[i].ring_mem);
1976 [ # # ]: 0 : if (create_cfgq_info[i].buf_mem.va)
1977 : : idpf_free_dma_mem(&adapter->base.hw, &create_cfgq_info[i].buf_mem);
1978 : : }
1979 : 0 : }
1980 : :
1981 : : static int
1982 : 0 : cpfl_add_cfgqs(struct cpfl_adapter_ext *adapter)
1983 : : {
1984 : : struct idpf_ctlq_info *cfg_cq;
1985 : : int ret = 0;
1986 : : int i = 0;
1987 : :
1988 [ # # ]: 0 : for (i = 0; i < CPFL_CFGQ_NUM; i++) {
1989 : 0 : cfg_cq = NULL;
1990 : 0 : ret = cpfl_vport_ctlq_add((struct idpf_hw *)(&adapter->base.hw),
1991 : : &adapter->cfgq_info[i],
1992 : : &cfg_cq);
1993 [ # # # # ]: 0 : if (ret || !cfg_cq) {
1994 : 0 : PMD_DRV_LOG(ERR, "ctlq add failed for queue id: %d",
1995 : : adapter->cfgq_info[i].id);
1996 : 0 : cpfl_remove_cfgqs(adapter);
1997 : 0 : return ret;
1998 : : }
1999 : 0 : PMD_DRV_LOG(INFO, "added cfgq to hw. queue id: %d",
2000 : : adapter->cfgq_info[i].id);
2001 : 0 : adapter->ctlqp[i] = cfg_cq;
2002 : : }
2003 : :
2004 : : return ret;
2005 : : }
2006 : :
2007 : : #define CPFL_CFGQ_RING_LEN 512
2008 : : #define CPFL_CFGQ_DESCRIPTOR_SIZE 32
2009 : : #define CPFL_CFGQ_BUFFER_SIZE 256
2010 : : #define CPFL_CFGQ_RING_SIZE 512
2011 : :
2012 : : static int
2013 : 0 : cpfl_cfgq_setup(struct cpfl_adapter_ext *adapter)
2014 : : {
2015 : : struct cpfl_ctlq_create_info *create_cfgq_info;
2016 : : struct cpfl_vport *vport;
2017 : : int i, err;
2018 : : uint32_t ring_size = CPFL_CFGQ_RING_SIZE * sizeof(struct idpf_ctlq_desc);
2019 : : uint32_t buf_size = CPFL_CFGQ_RING_SIZE * CPFL_CFGQ_BUFFER_SIZE;
2020 : :
2021 : : vport = &adapter->ctrl_vport;
2022 : 0 : create_cfgq_info = adapter->cfgq_info;
2023 : :
2024 [ # # ]: 0 : for (i = 0; i < CPFL_CFGQ_NUM; i++) {
2025 [ # # ]: 0 : if (i % 2 == 0) {
2026 : : /* Setup Tx config queue */
2027 : 0 : create_cfgq_info[i].id = vport->base.chunks_info.tx_start_qid + i / 2;
2028 : 0 : create_cfgq_info[i].type = IDPF_CTLQ_TYPE_CONFIG_TX;
2029 : 0 : create_cfgq_info[i].len = CPFL_CFGQ_RING_SIZE;
2030 : 0 : create_cfgq_info[i].buf_size = CPFL_CFGQ_BUFFER_SIZE;
2031 : 0 : memset(&create_cfgq_info[i].reg, 0, sizeof(struct idpf_ctlq_reg));
2032 : 0 : create_cfgq_info[i].reg.tail = vport->base.chunks_info.tx_qtail_start +
2033 : 0 : i / 2 * vport->base.chunks_info.tx_qtail_spacing;
2034 : : } else {
2035 : : /* Setup Rx config queue */
2036 : 0 : create_cfgq_info[i].id = vport->base.chunks_info.rx_start_qid + i / 2;
2037 : 0 : create_cfgq_info[i].type = IDPF_CTLQ_TYPE_CONFIG_RX;
2038 : 0 : create_cfgq_info[i].len = CPFL_CFGQ_RING_SIZE;
2039 : 0 : create_cfgq_info[i].buf_size = CPFL_CFGQ_BUFFER_SIZE;
2040 : 0 : memset(&create_cfgq_info[i].reg, 0, sizeof(struct idpf_ctlq_reg));
2041 : 0 : create_cfgq_info[i].reg.tail = vport->base.chunks_info.rx_qtail_start +
2042 : 0 : i / 2 * vport->base.chunks_info.rx_qtail_spacing;
2043 [ # # ]: 0 : if (!idpf_alloc_dma_mem(&adapter->base.hw, &create_cfgq_info[i].buf_mem,
2044 : : buf_size)) {
2045 : : err = -ENOMEM;
2046 : 0 : goto free_mem;
2047 : : }
2048 : : }
2049 [ # # ]: 0 : if (!idpf_alloc_dma_mem(&adapter->base.hw, &create_cfgq_info[i].ring_mem,
2050 : : ring_size)) {
2051 : : err = -ENOMEM;
2052 : 0 : goto free_mem;
2053 : : }
2054 : : }
2055 : : return 0;
2056 : : free_mem:
2057 [ # # ]: 0 : for (i = 0; i < CPFL_CFGQ_NUM; i++) {
2058 [ # # ]: 0 : if (create_cfgq_info[i].ring_mem.va)
2059 : : idpf_free_dma_mem(&adapter->base.hw, &create_cfgq_info[i].ring_mem);
2060 [ # # ]: 0 : if (create_cfgq_info[i].buf_mem.va)
2061 : : idpf_free_dma_mem(&adapter->base.hw, &create_cfgq_info[i].buf_mem);
2062 : : }
2063 : : return err;
2064 : : }
2065 : :
2066 : : static int
2067 : 0 : cpfl_init_ctrl_vport(struct cpfl_adapter_ext *adapter)
2068 : : {
2069 : : struct cpfl_vport *vport = &adapter->ctrl_vport;
2070 : : struct virtchnl2_create_vport *vport_info =
2071 : : (struct virtchnl2_create_vport *)adapter->ctrl_vport_recv_info;
2072 : : int i;
2073 : :
2074 : 0 : vport->itf.adapter = adapter;
2075 : 0 : vport->base.adapter = &adapter->base;
2076 : 0 : vport->base.vport_id = vport_info->vport_id;
2077 : :
2078 [ # # ]: 0 : for (i = 0; i < vport_info->chunks.num_chunks; i++) {
2079 [ # # ]: 0 : if (vport_info->chunks.chunks[i].type == VIRTCHNL2_QUEUE_TYPE_TX) {
2080 : 0 : vport->base.chunks_info.tx_start_qid =
2081 : 0 : vport_info->chunks.chunks[i].start_queue_id;
2082 : 0 : vport->base.chunks_info.tx_qtail_start =
2083 : 0 : vport_info->chunks.chunks[i].qtail_reg_start;
2084 : 0 : vport->base.chunks_info.tx_qtail_spacing =
2085 : 0 : vport_info->chunks.chunks[i].qtail_reg_spacing;
2086 [ # # ]: 0 : } else if (vport_info->chunks.chunks[i].type == VIRTCHNL2_QUEUE_TYPE_RX) {
2087 : 0 : vport->base.chunks_info.rx_start_qid =
2088 : 0 : vport_info->chunks.chunks[i].start_queue_id;
2089 : 0 : vport->base.chunks_info.rx_qtail_start =
2090 : 0 : vport_info->chunks.chunks[i].qtail_reg_start;
2091 : 0 : vport->base.chunks_info.rx_qtail_spacing =
2092 : 0 : vport_info->chunks.chunks[i].qtail_reg_spacing;
2093 : : } else {
2094 : 0 : PMD_INIT_LOG(ERR, "Unsupported chunk type");
2095 : 0 : return -EINVAL;
2096 : : }
2097 : : }
2098 : :
2099 : : return 0;
2100 : : }
2101 : :
2102 : : static void
2103 : 0 : cpfl_ctrl_path_close(struct cpfl_adapter_ext *adapter)
2104 : : {
2105 : 0 : cpfl_stop_cfgqs(adapter);
2106 : 0 : cpfl_remove_cfgqs(adapter);
2107 : 0 : idpf_vc_vport_destroy(&adapter->ctrl_vport.base);
2108 : 0 : }
2109 : :
2110 : : static int
2111 : 0 : cpfl_ctrl_path_open(struct cpfl_adapter_ext *adapter)
2112 : : {
2113 : : int ret;
2114 : :
2115 : 0 : ret = cpfl_vc_create_ctrl_vport(adapter);
2116 [ # # ]: 0 : if (ret) {
2117 : 0 : PMD_INIT_LOG(ERR, "Failed to create control vport");
2118 : 0 : return ret;
2119 : : }
2120 : :
2121 : 0 : ret = cpfl_init_ctrl_vport(adapter);
2122 [ # # ]: 0 : if (ret) {
2123 : 0 : PMD_INIT_LOG(ERR, "Failed to init control vport");
2124 : 0 : goto err_init_ctrl_vport;
2125 : : }
2126 : :
2127 : 0 : ret = cpfl_cfgq_setup(adapter);
2128 [ # # ]: 0 : if (ret) {
2129 : 0 : PMD_INIT_LOG(ERR, "Failed to setup control queues");
2130 : 0 : goto err_cfgq_setup;
2131 : : }
2132 : :
2133 : 0 : ret = cpfl_add_cfgqs(adapter);
2134 [ # # ]: 0 : if (ret) {
2135 : 0 : PMD_INIT_LOG(ERR, "Failed to add control queues");
2136 : 0 : goto err_add_cfgq;
2137 : : }
2138 : :
2139 : 0 : ret = cpfl_start_cfgqs(adapter);
2140 [ # # ]: 0 : if (ret) {
2141 : 0 : PMD_INIT_LOG(ERR, "Failed to start control queues");
2142 : 0 : goto err_start_cfgqs;
2143 : : }
2144 : :
2145 : : return 0;
2146 : :
2147 : : err_start_cfgqs:
2148 : 0 : cpfl_stop_cfgqs(adapter);
2149 : 0 : err_add_cfgq:
2150 : 0 : cpfl_remove_cfgqs(adapter);
2151 : 0 : err_cfgq_setup:
2152 : 0 : err_init_ctrl_vport:
2153 : 0 : idpf_vc_vport_destroy(&adapter->ctrl_vport.base);
2154 : :
2155 : 0 : return ret;
2156 : : }
2157 : :
2158 : : static struct virtchnl2_get_capabilities req_caps = {
2159 : : .csum_caps =
2160 : : VIRTCHNL2_CAP_TX_CSUM_L3_IPV4 |
2161 : : VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_TCP |
2162 : : VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_UDP |
2163 : : VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_SCTP |
2164 : : VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_TCP |
2165 : : VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_UDP |
2166 : : VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_SCTP |
2167 : : VIRTCHNL2_CAP_TX_CSUM_GENERIC |
2168 : : VIRTCHNL2_CAP_RX_CSUM_L3_IPV4 |
2169 : : VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_TCP |
2170 : : VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_UDP |
2171 : : VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_SCTP |
2172 : : VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_TCP |
2173 : : VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_UDP |
2174 : : VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_SCTP |
2175 : : VIRTCHNL2_CAP_RX_CSUM_GENERIC,
2176 : :
2177 : : .rss_caps =
2178 : : VIRTCHNL2_CAP_RSS_IPV4_TCP |
2179 : : VIRTCHNL2_CAP_RSS_IPV4_UDP |
2180 : : VIRTCHNL2_CAP_RSS_IPV4_SCTP |
2181 : : VIRTCHNL2_CAP_RSS_IPV4_OTHER |
2182 : : VIRTCHNL2_CAP_RSS_IPV6_TCP |
2183 : : VIRTCHNL2_CAP_RSS_IPV6_UDP |
2184 : : VIRTCHNL2_CAP_RSS_IPV6_SCTP |
2185 : : VIRTCHNL2_CAP_RSS_IPV6_OTHER |
2186 : : VIRTCHNL2_CAP_RSS_IPV4_AH |
2187 : : VIRTCHNL2_CAP_RSS_IPV4_ESP |
2188 : : VIRTCHNL2_CAP_RSS_IPV4_AH_ESP |
2189 : : VIRTCHNL2_CAP_RSS_IPV6_AH |
2190 : : VIRTCHNL2_CAP_RSS_IPV6_ESP |
2191 : : VIRTCHNL2_CAP_RSS_IPV6_AH_ESP,
2192 : :
2193 : : .other_caps = VIRTCHNL2_CAP_WB_ON_ITR
2194 : : };
2195 : :
2196 : : static int
2197 : 0 : cpfl_vport_map_init(struct cpfl_adapter_ext *adapter)
2198 : : {
2199 : : char hname[32];
2200 : :
2201 : 0 : snprintf(hname, 32, "%s-vport", adapter->name);
2202 : :
2203 : : rte_spinlock_init(&adapter->vport_map_lock);
2204 : :
2205 : : #define CPFL_VPORT_MAP_HASH_ENTRY_NUM 2048
2206 : :
2207 : 0 : struct rte_hash_parameters params = {
2208 : : .name = adapter->name,
2209 : : .entries = CPFL_VPORT_MAP_HASH_ENTRY_NUM,
2210 : : .key_len = sizeof(struct cpfl_vport_id),
2211 : : .hash_func = rte_hash_crc,
2212 : : .socket_id = SOCKET_ID_ANY,
2213 : : };
2214 : :
2215 : 0 : adapter->vport_map_hash = rte_hash_create(¶ms);
2216 : :
2217 [ # # ]: 0 : if (adapter->vport_map_hash == NULL) {
2218 : 0 : PMD_INIT_LOG(ERR, "Failed to create vport map hash");
2219 : 0 : return -EINVAL;
2220 : : }
2221 : :
2222 : : return 0;
2223 : : }
2224 : :
2225 : : static void
2226 : 0 : cpfl_vport_map_uninit(struct cpfl_adapter_ext *adapter)
2227 : : {
2228 : 0 : const void *key = NULL;
2229 : : struct cpfl_vport_map_info *info;
2230 : 0 : uint32_t iter = 0;
2231 : :
2232 [ # # ]: 0 : while (rte_hash_iterate(adapter->vport_map_hash, &key, (void **)&info, &iter) >= 0)
2233 : 0 : rte_free(info);
2234 : :
2235 : 0 : rte_hash_free(adapter->vport_map_hash);
2236 : 0 : }
2237 : :
2238 : : static int
2239 : 0 : cpfl_repr_allowlist_init(struct cpfl_adapter_ext *adapter)
2240 : : {
2241 : : char hname[32];
2242 : :
2243 : 0 : snprintf(hname, 32, "%s-repr_al", adapter->name);
2244 : :
2245 : : rte_spinlock_init(&adapter->repr_lock);
2246 : :
2247 : : #define CPFL_REPR_HASH_ENTRY_NUM 2048
2248 : :
2249 : 0 : struct rte_hash_parameters params = {
2250 : : .name = hname,
2251 : : .entries = CPFL_REPR_HASH_ENTRY_NUM,
2252 : : .key_len = sizeof(struct cpfl_repr_id),
2253 : : .hash_func = rte_hash_crc,
2254 : : .socket_id = SOCKET_ID_ANY,
2255 : : };
2256 : :
2257 : 0 : adapter->repr_allowlist_hash = rte_hash_create(¶ms);
2258 : :
2259 [ # # ]: 0 : if (adapter->repr_allowlist_hash == NULL) {
2260 : 0 : PMD_INIT_LOG(ERR, "Failed to create repr allowlist hash");
2261 : 0 : return -EINVAL;
2262 : : }
2263 : :
2264 : : return 0;
2265 : : }
2266 : :
2267 : : static void
2268 : : cpfl_repr_allowlist_uninit(struct cpfl_adapter_ext *adapter)
2269 : : {
2270 : 0 : rte_hash_free(adapter->repr_allowlist_hash);
2271 : 0 : }
2272 : :
2273 : :
2274 : : static int
2275 : 0 : cpfl_adapter_ext_init(struct rte_pci_device *pci_dev, struct cpfl_adapter_ext *adapter,
2276 : : struct cpfl_devargs *devargs)
2277 : : {
2278 : 0 : struct idpf_adapter *base = &adapter->base;
2279 : : struct idpf_hw *hw = &base->hw;
2280 : : int ret = 0;
2281 : :
2282 : : #ifndef RTE_HAS_JANSSON
2283 : : RTE_SET_USED(devargs);
2284 : : #endif
2285 : :
2286 : 0 : hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
2287 : 0 : hw->hw_addr_len = pci_dev->mem_resource[0].len;
2288 : 0 : hw->back = base;
2289 : 0 : hw->vendor_id = pci_dev->id.vendor_id;
2290 : 0 : hw->device_id = pci_dev->id.device_id;
2291 : 0 : hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
2292 : :
2293 [ # # ]: 0 : strncpy(adapter->name, pci_dev->device.name, PCI_PRI_STR_SIZE);
2294 : :
2295 [ # # ]: 0 : rte_memcpy(&base->caps, &req_caps, sizeof(struct virtchnl2_get_capabilities));
2296 : :
2297 : 0 : ret = idpf_adapter_init(base);
2298 [ # # ]: 0 : if (ret != 0) {
2299 : 0 : PMD_INIT_LOG(ERR, "Failed to init adapter");
2300 : 0 : goto err_adapter_init;
2301 : : }
2302 : :
2303 : 0 : ret = cpfl_vport_map_init(adapter);
2304 [ # # ]: 0 : if (ret) {
2305 : 0 : PMD_INIT_LOG(ERR, "Failed to init vport map");
2306 : 0 : goto err_vport_map_init;
2307 : : }
2308 : :
2309 : 0 : ret = cpfl_repr_allowlist_init(adapter);
2310 [ # # ]: 0 : if (ret) {
2311 : 0 : PMD_INIT_LOG(ERR, "Failed to init representor allowlist");
2312 : 0 : goto err_repr_allowlist_init;
2313 : : }
2314 : :
2315 : 0 : rte_eal_alarm_set(CPFL_ALARM_INTERVAL, cpfl_dev_alarm_handler, adapter);
2316 : :
2317 : 0 : adapter->max_vport_nb = adapter->base.caps.max_vports > CPFL_MAX_VPORT_NUM ?
2318 : 0 : CPFL_MAX_VPORT_NUM : adapter->base.caps.max_vports;
2319 : :
2320 : 0 : adapter->vports = rte_zmalloc("vports",
2321 : 0 : adapter->max_vport_nb *
2322 : : sizeof(*adapter->vports),
2323 : : 0);
2324 [ # # ]: 0 : if (adapter->vports == NULL) {
2325 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate vports memory");
2326 : : ret = -ENOMEM;
2327 : 0 : goto err_vports_alloc;
2328 : : }
2329 : :
2330 : 0 : ret = cpfl_ctrl_path_open(adapter);
2331 [ # # ]: 0 : if (ret) {
2332 : 0 : PMD_INIT_LOG(ERR, "Failed to setup control path");
2333 : 0 : goto err_create_ctrl_vport;
2334 : : }
2335 : :
2336 : : #ifdef RTE_HAS_JANSSON
2337 : 0 : ret = cpfl_flow_init(adapter, devargs);
2338 [ # # ]: 0 : if (ret) {
2339 : 0 : PMD_INIT_LOG(ERR, "Failed to init flow module");
2340 : 0 : goto err_flow_init;
2341 : : }
2342 : : #endif
2343 : 0 : adapter->cur_vports = 0;
2344 : 0 : adapter->cur_vport_nb = 0;
2345 : :
2346 : 0 : adapter->used_vecs_num = 0;
2347 : :
2348 : 0 : return ret;
2349 : :
2350 : : #ifdef RTE_HAS_JANSSON
2351 : : err_flow_init:
2352 : 0 : cpfl_ctrl_path_close(adapter);
2353 : : #endif
2354 : 0 : err_create_ctrl_vport:
2355 : 0 : rte_free(adapter->vports);
2356 : 0 : err_vports_alloc:
2357 : 0 : rte_eal_alarm_cancel(cpfl_dev_alarm_handler, adapter);
2358 : : cpfl_repr_allowlist_uninit(adapter);
2359 : 0 : err_repr_allowlist_init:
2360 : 0 : cpfl_vport_map_uninit(adapter);
2361 : 0 : err_vport_map_init:
2362 : 0 : idpf_adapter_deinit(base);
2363 : : err_adapter_init:
2364 : : return ret;
2365 : : }
2366 : :
2367 : : static uint16_t
2368 : : cpfl_vport_idx_alloc(struct cpfl_adapter_ext *adapter)
2369 : : {
2370 : : uint16_t vport_idx;
2371 : : uint16_t i;
2372 : :
2373 [ # # ]: 0 : for (i = 0; i < adapter->max_vport_nb; i++) {
2374 [ # # ]: 0 : if (adapter->vports[i] == NULL)
2375 : : break;
2376 : : }
2377 : :
2378 [ # # ]: 0 : if (i == adapter->max_vport_nb)
2379 : : vport_idx = CPFL_INVALID_VPORT_IDX;
2380 : : else
2381 : : vport_idx = i;
2382 : :
2383 : : return vport_idx;
2384 : : }
2385 : :
2386 : : static int
2387 : 0 : cpfl_p2p_q_grps_add(struct idpf_vport *vport,
2388 : : struct virtchnl2_add_queue_groups *p2p_queue_grps_info,
2389 : : uint8_t *p2p_q_vc_out_info)
2390 : : {
2391 : : int ret;
2392 : :
2393 : 0 : p2p_queue_grps_info->vport_id = vport->vport_id;
2394 : 0 : p2p_queue_grps_info->qg_info.num_queue_groups = CPFL_P2P_NB_QUEUE_GRPS;
2395 : 0 : p2p_queue_grps_info->qg_info.groups[0].num_rx_q = CPFL_MAX_P2P_NB_QUEUES;
2396 : 0 : p2p_queue_grps_info->qg_info.groups[0].num_rx_bufq = CPFL_P2P_NB_RX_BUFQ;
2397 : 0 : p2p_queue_grps_info->qg_info.groups[0].num_tx_q = CPFL_MAX_P2P_NB_QUEUES;
2398 : 0 : p2p_queue_grps_info->qg_info.groups[0].num_tx_complq = CPFL_P2P_NB_TX_COMPLQ;
2399 : 0 : p2p_queue_grps_info->qg_info.groups[0].qg_id.queue_group_id = CPFL_P2P_QUEUE_GRP_ID;
2400 : 0 : p2p_queue_grps_info->qg_info.groups[0].qg_id.queue_group_type = VIRTCHNL2_QUEUE_GROUP_P2P;
2401 : 0 : p2p_queue_grps_info->qg_info.groups[0].rx_q_grp_info.rss_lut_size = 0;
2402 : 0 : p2p_queue_grps_info->qg_info.groups[0].tx_q_grp_info.tx_tc = 0;
2403 : 0 : p2p_queue_grps_info->qg_info.groups[0].tx_q_grp_info.priority = 0;
2404 : 0 : p2p_queue_grps_info->qg_info.groups[0].tx_q_grp_info.is_sp = 0;
2405 : 0 : p2p_queue_grps_info->qg_info.groups[0].tx_q_grp_info.pir_weight = 0;
2406 : :
2407 : 0 : ret = idpf_vc_queue_grps_add(vport, p2p_queue_grps_info, p2p_q_vc_out_info);
2408 [ # # ]: 0 : if (ret != 0) {
2409 : 0 : PMD_DRV_LOG(ERR, "Failed to add p2p queue groups.");
2410 : 0 : return ret;
2411 : : }
2412 : :
2413 : : return ret;
2414 : : }
2415 : :
2416 : : static int
2417 : 0 : cpfl_p2p_queue_info_init(struct cpfl_vport *cpfl_vport,
2418 : : struct virtchnl2_add_queue_groups *p2p_q_vc_out_info)
2419 : : {
2420 : 0 : struct p2p_queue_chunks_info *p2p_q_chunks_info = cpfl_vport->p2p_q_chunks_info;
2421 : : struct virtchnl2_queue_reg_chunks *vc_chunks_out;
2422 : : int i, type;
2423 : :
2424 [ # # ]: 0 : if (p2p_q_vc_out_info->qg_info.groups[0].qg_id.queue_group_type !=
2425 : : VIRTCHNL2_QUEUE_GROUP_P2P) {
2426 : 0 : PMD_DRV_LOG(ERR, "Add queue group response mismatch.");
2427 : 0 : return -EINVAL;
2428 : : }
2429 : :
2430 : : vc_chunks_out = &p2p_q_vc_out_info->qg_info.groups[0].chunks;
2431 : :
2432 [ # # ]: 0 : for (i = 0; i < vc_chunks_out->num_chunks; i++) {
2433 : 0 : type = vc_chunks_out->chunks[i].type;
2434 [ # # # # : 0 : switch (type) {
# ]
2435 : 0 : case VIRTCHNL2_QUEUE_TYPE_TX:
2436 : 0 : p2p_q_chunks_info->tx_start_qid =
2437 : 0 : vc_chunks_out->chunks[i].start_queue_id;
2438 : 0 : p2p_q_chunks_info->tx_qtail_start =
2439 : 0 : vc_chunks_out->chunks[i].qtail_reg_start;
2440 : 0 : p2p_q_chunks_info->tx_qtail_spacing =
2441 : 0 : vc_chunks_out->chunks[i].qtail_reg_spacing;
2442 : 0 : break;
2443 : 0 : case VIRTCHNL2_QUEUE_TYPE_RX:
2444 : 0 : p2p_q_chunks_info->rx_start_qid =
2445 : 0 : vc_chunks_out->chunks[i].start_queue_id;
2446 : 0 : p2p_q_chunks_info->rx_qtail_start =
2447 : 0 : vc_chunks_out->chunks[i].qtail_reg_start;
2448 : 0 : p2p_q_chunks_info->rx_qtail_spacing =
2449 : 0 : vc_chunks_out->chunks[i].qtail_reg_spacing;
2450 : 0 : break;
2451 : 0 : case VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION:
2452 : 0 : p2p_q_chunks_info->tx_compl_start_qid =
2453 : 0 : vc_chunks_out->chunks[i].start_queue_id;
2454 : 0 : p2p_q_chunks_info->tx_compl_qtail_start =
2455 : 0 : vc_chunks_out->chunks[i].qtail_reg_start;
2456 : 0 : p2p_q_chunks_info->tx_compl_qtail_spacing =
2457 : 0 : vc_chunks_out->chunks[i].qtail_reg_spacing;
2458 : 0 : break;
2459 : 0 : case VIRTCHNL2_QUEUE_TYPE_RX_BUFFER:
2460 : 0 : p2p_q_chunks_info->rx_buf_start_qid =
2461 : 0 : vc_chunks_out->chunks[i].start_queue_id;
2462 : 0 : p2p_q_chunks_info->rx_buf_qtail_start =
2463 : 0 : vc_chunks_out->chunks[i].qtail_reg_start;
2464 : 0 : p2p_q_chunks_info->rx_buf_qtail_spacing =
2465 : 0 : vc_chunks_out->chunks[i].qtail_reg_spacing;
2466 : 0 : break;
2467 : 0 : default:
2468 : 0 : PMD_DRV_LOG(ERR, "Unsupported queue type");
2469 : 0 : break;
2470 : : }
2471 : : }
2472 : :
2473 : : return 0;
2474 : : }
2475 : :
2476 : : int
2477 : 0 : cpfl_alloc_dma_mem_batch(struct idpf_dma_mem *orig_dma, struct idpf_dma_mem *dma, uint32_t size,
2478 : : int batch_size)
2479 : : {
2480 : : int i;
2481 : :
2482 [ # # ]: 0 : if (!idpf_alloc_dma_mem(NULL, orig_dma, (uint64_t)size * (1 + batch_size))) {
2483 : 0 : PMD_INIT_LOG(ERR, "Could not alloc dma memory");
2484 : 0 : return -ENOMEM;
2485 : : }
2486 : :
2487 [ # # ]: 0 : for (i = 0; i < batch_size; i++) {
2488 : 0 : dma[i].va = (void *)((char *)orig_dma->va + size * (i + 1));
2489 : 0 : dma[i].pa = orig_dma->pa + size * (i + 1);
2490 : 0 : dma[i].size = size;
2491 : 0 : dma[i].zone = NULL;
2492 : : }
2493 : : return 0;
2494 : : }
2495 : :
2496 : : static int
2497 : 0 : cpfl_dev_vport_init(struct rte_eth_dev *dev, void *init_params)
2498 : : {
2499 : 0 : struct cpfl_vport *cpfl_vport = dev->data->dev_private;
2500 : 0 : struct idpf_vport *vport = &cpfl_vport->base;
2501 : : struct cpfl_vport_param *param = init_params;
2502 : 0 : struct cpfl_adapter_ext *adapter = param->adapter;
2503 : : /* for sending create vport virtchnl msg prepare */
2504 : : struct virtchnl2_create_vport create_vport_info;
2505 : : struct virtchnl2_add_queue_groups p2p_queue_grps_info;
2506 : 0 : uint8_t p2p_q_vc_out_info[IDPF_DFLT_MBX_BUF_SIZE] = {0};
2507 : : int ret = 0;
2508 : :
2509 : 0 : dev->dev_ops = &cpfl_eth_dev_ops;
2510 : 0 : vport->adapter = &adapter->base;
2511 : 0 : vport->sw_idx = param->idx;
2512 : 0 : vport->devarg_id = param->devarg_id;
2513 : :
2514 : : memset(&create_vport_info, 0, sizeof(create_vport_info));
2515 : 0 : ret = idpf_vport_info_init(vport, &create_vport_info);
2516 [ # # ]: 0 : if (ret != 0) {
2517 : 0 : PMD_INIT_LOG(ERR, "Failed to init vport req_info.");
2518 : 0 : goto err;
2519 : : }
2520 : :
2521 : 0 : ret = idpf_vport_init(vport, &create_vport_info, dev->data);
2522 [ # # ]: 0 : if (ret != 0) {
2523 : 0 : PMD_INIT_LOG(ERR, "Failed to init vports.");
2524 : 0 : goto err;
2525 : : }
2526 : :
2527 : 0 : cpfl_vport->itf.type = CPFL_ITF_TYPE_VPORT;
2528 : 0 : cpfl_vport->itf.adapter = adapter;
2529 : 0 : cpfl_vport->itf.data = dev->data;
2530 : 0 : TAILQ_INIT(&cpfl_vport->itf.flow_list);
2531 : 0 : adapter->vports[param->idx] = cpfl_vport;
2532 : 0 : adapter->cur_vports |= RTE_BIT32(param->devarg_id);
2533 : 0 : adapter->cur_vport_nb++;
2534 : :
2535 : 0 : dev->data->mac_addrs = rte_zmalloc(NULL, RTE_ETHER_ADDR_LEN, 0);
2536 [ # # ]: 0 : if (dev->data->mac_addrs == NULL) {
2537 : 0 : PMD_INIT_LOG(ERR, "Cannot allocate mac_addr memory.");
2538 : : ret = -ENOMEM;
2539 : 0 : goto err_mac_addrs;
2540 : : }
2541 : :
2542 : : rte_ether_addr_copy((struct rte_ether_addr *)vport->default_mac_addr,
2543 : : &dev->data->mac_addrs[0]);
2544 : :
2545 : 0 : memset(cpfl_vport->itf.dma, 0, sizeof(cpfl_vport->itf.dma));
2546 : 0 : memset(cpfl_vport->itf.msg, 0, sizeof(cpfl_vport->itf.msg));
2547 : 0 : ret = cpfl_alloc_dma_mem_batch(&cpfl_vport->itf.flow_dma,
2548 : : cpfl_vport->itf.dma,
2549 : : sizeof(union cpfl_rule_cfg_pkt_record),
2550 : : CPFL_FLOW_BATCH_SIZE);
2551 [ # # ]: 0 : if (ret < 0)
2552 : 0 : goto err_mac_addrs;
2553 : :
2554 [ # # # # ]: 0 : if (!adapter->base.is_rx_singleq && !adapter->base.is_tx_singleq) {
2555 : : memset(&p2p_queue_grps_info, 0, sizeof(p2p_queue_grps_info));
2556 : 0 : ret = cpfl_p2p_q_grps_add(vport, &p2p_queue_grps_info, p2p_q_vc_out_info);
2557 [ # # ]: 0 : if (ret != 0) {
2558 : 0 : PMD_INIT_LOG(WARNING, "Failed to add p2p queue group.");
2559 : 0 : return 0;
2560 : : }
2561 : 0 : cpfl_vport->p2p_q_chunks_info = rte_zmalloc(NULL,
2562 : : sizeof(struct p2p_queue_chunks_info), 0);
2563 [ # # ]: 0 : if (cpfl_vport->p2p_q_chunks_info == NULL) {
2564 : 0 : PMD_INIT_LOG(WARNING, "Failed to allocate p2p queue info.");
2565 : 0 : cpfl_p2p_queue_grps_del(vport);
2566 : 0 : return 0;
2567 : : }
2568 : 0 : ret = cpfl_p2p_queue_info_init(cpfl_vport,
2569 : : (struct virtchnl2_add_queue_groups *)p2p_q_vc_out_info);
2570 [ # # ]: 0 : if (ret != 0) {
2571 : 0 : PMD_INIT_LOG(WARNING, "Failed to init p2p queue info.");
2572 : 0 : rte_free(cpfl_vport->p2p_q_chunks_info);
2573 : 0 : cpfl_p2p_queue_grps_del(vport);
2574 : : }
2575 : : }
2576 : :
2577 : : return 0;
2578 : :
2579 : 0 : err_mac_addrs:
2580 : 0 : adapter->vports[param->idx] = NULL; /* reset */
2581 : 0 : idpf_vport_deinit(vport);
2582 : 0 : adapter->cur_vports &= ~RTE_BIT32(param->devarg_id);
2583 : 0 : adapter->cur_vport_nb--;
2584 : : err:
2585 : : return ret;
2586 : : }
2587 : :
2588 : : static const struct rte_pci_id pci_id_cpfl_map[] = {
2589 : : { RTE_PCI_DEVICE(IDPF_INTEL_VENDOR_ID, IDPF_DEV_ID_CPF) },
2590 : : { .vendor_id = 0, /* sentinel */ },
2591 : : };
2592 : :
2593 : : static struct cpfl_adapter_ext *
2594 : 0 : cpfl_find_adapter_ext(struct rte_pci_device *pci_dev)
2595 : : {
2596 : : struct cpfl_adapter_ext *adapter;
2597 : : int found = 0;
2598 : :
2599 [ # # ]: 0 : if (pci_dev == NULL)
2600 : : return NULL;
2601 : :
2602 : : rte_spinlock_lock(&cpfl_adapter_lock);
2603 [ # # ]: 0 : TAILQ_FOREACH(adapter, &cpfl_adapter_list, next) {
2604 [ # # ]: 0 : if (strncmp(adapter->name, pci_dev->device.name, PCI_PRI_STR_SIZE) == 0) {
2605 : : found = 1;
2606 : : break;
2607 : : }
2608 : : }
2609 : : rte_spinlock_unlock(&cpfl_adapter_lock);
2610 : :
2611 [ # # ]: 0 : if (found == 0)
2612 : 0 : return NULL;
2613 : :
2614 : : return adapter;
2615 : : }
2616 : :
2617 : : static void
2618 : 0 : cpfl_adapter_ext_deinit(struct cpfl_adapter_ext *adapter)
2619 : : {
2620 : : #ifdef RTE_HAS_JANSSON
2621 : 0 : cpfl_flow_uninit(adapter);
2622 : : #endif
2623 : 0 : cpfl_ctrl_path_close(adapter);
2624 : 0 : rte_eal_alarm_cancel(cpfl_dev_alarm_handler, adapter);
2625 : 0 : cpfl_vport_map_uninit(adapter);
2626 : 0 : idpf_adapter_deinit(&adapter->base);
2627 : :
2628 : 0 : rte_free(adapter->vports);
2629 : 0 : adapter->vports = NULL;
2630 : 0 : }
2631 : :
2632 : : static int
2633 : 0 : cpfl_vport_devargs_process(struct cpfl_adapter_ext *adapter, struct cpfl_devargs *devargs)
2634 : : {
2635 : : int i;
2636 : :
2637 : : /* refine vport number, at least 1 vport */
2638 [ # # ]: 0 : if (devargs->req_vport_nb == 0) {
2639 : 0 : devargs->req_vport_nb = 1;
2640 : 0 : devargs->req_vports[0] = 0;
2641 : : }
2642 : :
2643 : : /* check parsed devargs */
2644 : 0 : if (adapter->cur_vport_nb + devargs->req_vport_nb >
2645 [ # # ]: 0 : adapter->max_vport_nb) {
2646 : 0 : PMD_INIT_LOG(ERR, "Total vport number can't be > %d",
2647 : : adapter->max_vport_nb);
2648 : 0 : return -EINVAL;
2649 : : }
2650 : :
2651 [ # # ]: 0 : for (i = 0; i < devargs->req_vport_nb; i++) {
2652 [ # # ]: 0 : if (devargs->req_vports[i] > adapter->max_vport_nb - 1) {
2653 : 0 : PMD_INIT_LOG(ERR, "Invalid vport id %d, it should be 0 ~ %d",
2654 : : devargs->req_vports[i], adapter->max_vport_nb - 1);
2655 : 0 : return -EINVAL;
2656 : : }
2657 : :
2658 [ # # ]: 0 : if (adapter->cur_vports & RTE_BIT32(devargs->req_vports[i])) {
2659 : 0 : PMD_INIT_LOG(ERR, "Vport %d has been requested",
2660 : : devargs->req_vports[i]);
2661 : 0 : return -EINVAL;
2662 : : }
2663 : : }
2664 : :
2665 : : return 0;
2666 : : }
2667 : :
2668 : : static int
2669 : 0 : cpfl_vport_create(struct rte_pci_device *pci_dev, struct cpfl_adapter_ext *adapter,
2670 : : struct cpfl_devargs *devargs)
2671 : : {
2672 : : struct cpfl_vport_param vport_param;
2673 : : char name[RTE_ETH_NAME_MAX_LEN];
2674 : : int ret, i;
2675 : :
2676 [ # # ]: 0 : for (i = 0; i < devargs->req_vport_nb; i++) {
2677 : 0 : vport_param.adapter = adapter;
2678 : 0 : vport_param.devarg_id = devargs->req_vports[i];
2679 : 0 : vport_param.idx = cpfl_vport_idx_alloc(adapter);
2680 [ # # ]: 0 : if (vport_param.idx == CPFL_INVALID_VPORT_IDX) {
2681 : 0 : PMD_INIT_LOG(ERR, "No space for vport %u", vport_param.devarg_id);
2682 : 0 : break;
2683 : : }
2684 : 0 : snprintf(name, sizeof(name), "net_%s_vport_%d",
2685 : : pci_dev->device.name,
2686 : : devargs->req_vports[i]);
2687 : 0 : ret = rte_eth_dev_create(&pci_dev->device, name,
2688 : : sizeof(struct cpfl_vport),
2689 : : NULL, NULL, cpfl_dev_vport_init,
2690 : : &vport_param);
2691 [ # # ]: 0 : if (ret != 0)
2692 : 0 : PMD_DRV_LOG(ERR, "Failed to create vport %d",
2693 : : vport_param.devarg_id);
2694 : : }
2695 : :
2696 : 0 : return 0;
2697 : : }
2698 : :
2699 : : static int
2700 : 0 : cpfl_pci_probe_first(struct rte_pci_device *pci_dev)
2701 : : {
2702 : : struct cpfl_adapter_ext *adapter;
2703 : : struct cpfl_devargs devargs;
2704 : : int retval;
2705 : : uint16_t port_id;
2706 : :
2707 : 0 : adapter = rte_zmalloc("cpfl_adapter_ext",
2708 : : sizeof(struct cpfl_adapter_ext), 0);
2709 [ # # ]: 0 : if (adapter == NULL) {
2710 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate adapter.");
2711 : 0 : return -ENOMEM;
2712 : : }
2713 : :
2714 : : memset(&devargs, 0, sizeof(devargs));
2715 : :
2716 : 0 : retval = cpfl_parse_devargs(pci_dev, adapter, true, &devargs);
2717 [ # # ]: 0 : if (retval != 0) {
2718 : 0 : PMD_INIT_LOG(ERR, "Failed to parse private devargs");
2719 : 0 : return retval;
2720 : : }
2721 : :
2722 : 0 : retval = cpfl_adapter_ext_init(pci_dev, adapter, &devargs);
2723 [ # # ]: 0 : if (retval != 0) {
2724 : 0 : PMD_INIT_LOG(ERR, "Failed to init adapter.");
2725 : 0 : return retval;
2726 : : }
2727 : :
2728 : : rte_spinlock_lock(&cpfl_adapter_lock);
2729 : 0 : TAILQ_INSERT_TAIL(&cpfl_adapter_list, adapter, next);
2730 : : rte_spinlock_unlock(&cpfl_adapter_lock);
2731 : :
2732 : 0 : retval = cpfl_vport_devargs_process(adapter, &devargs);
2733 [ # # ]: 0 : if (retval != 0) {
2734 : 0 : PMD_INIT_LOG(ERR, "Failed to process vport devargs");
2735 : 0 : goto err;
2736 : : }
2737 : :
2738 : 0 : retval = cpfl_vport_create(pci_dev, adapter, &devargs);
2739 [ # # ]: 0 : if (retval != 0) {
2740 : 0 : PMD_INIT_LOG(ERR, "Failed to create vports.");
2741 : 0 : goto err;
2742 : : }
2743 : :
2744 : 0 : retval = cpfl_repr_devargs_process(adapter, &devargs);
2745 [ # # ]: 0 : if (retval != 0) {
2746 : 0 : PMD_INIT_LOG(ERR, "Failed to process repr devargs");
2747 : 0 : goto close_ethdev;
2748 : : }
2749 : :
2750 : 0 : retval = cpfl_repr_create(pci_dev, adapter);
2751 [ # # ]: 0 : if (retval != 0) {
2752 : 0 : PMD_INIT_LOG(ERR, "Failed to create representors ");
2753 : 0 : goto close_ethdev;
2754 : : }
2755 : :
2756 : :
2757 : : return 0;
2758 : :
2759 : 0 : close_ethdev:
2760 : : /* Ethdev created can be found RTE_ETH_FOREACH_DEV_OF through rte_device */
2761 [ # # ]: 0 : RTE_ETH_FOREACH_DEV_OF(port_id, &pci_dev->device) {
2762 : 0 : rte_eth_dev_close(port_id);
2763 : : }
2764 : 0 : err:
2765 : : rte_spinlock_lock(&cpfl_adapter_lock);
2766 [ # # ]: 0 : TAILQ_REMOVE(&cpfl_adapter_list, adapter, next);
2767 : : rte_spinlock_unlock(&cpfl_adapter_lock);
2768 : 0 : cpfl_adapter_ext_deinit(adapter);
2769 : 0 : rte_free(adapter);
2770 : 0 : return retval;
2771 : : }
2772 : :
2773 : : static int
2774 : 0 : cpfl_pci_probe_again(struct rte_pci_device *pci_dev, struct cpfl_adapter_ext *adapter)
2775 : : {
2776 : : struct cpfl_devargs devargs;
2777 : : int ret;
2778 : :
2779 : : memset(&devargs, 0, sizeof(devargs));
2780 : 0 : ret = cpfl_parse_devargs(pci_dev, adapter, false, &devargs);
2781 [ # # ]: 0 : if (ret != 0) {
2782 : 0 : PMD_INIT_LOG(ERR, "Failed to parse private devargs");
2783 : 0 : return ret;
2784 : : }
2785 : :
2786 : 0 : ret = cpfl_repr_devargs_process(adapter, &devargs);
2787 [ # # ]: 0 : if (ret != 0) {
2788 : 0 : PMD_INIT_LOG(ERR, "Failed to process reprenstor devargs");
2789 : 0 : return ret;
2790 : : }
2791 : :
2792 : 0 : ret = cpfl_repr_create(pci_dev, adapter);
2793 [ # # ]: 0 : if (ret != 0) {
2794 : 0 : PMD_INIT_LOG(ERR, "Failed to create representors ");
2795 : 0 : return ret;
2796 : : }
2797 : :
2798 : : return 0;
2799 : : }
2800 : :
2801 : : static int
2802 : 0 : cpfl_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2803 : : struct rte_pci_device *pci_dev)
2804 : : {
2805 : : struct cpfl_adapter_ext *adapter;
2806 : :
2807 [ # # ]: 0 : if (!cpfl_adapter_list_init) {
2808 : : rte_spinlock_init(&cpfl_adapter_lock);
2809 : 0 : TAILQ_INIT(&cpfl_adapter_list);
2810 : 0 : cpfl_adapter_list_init = true;
2811 : : }
2812 : :
2813 : 0 : adapter = cpfl_find_adapter_ext(pci_dev);
2814 : :
2815 [ # # ]: 0 : if (adapter == NULL)
2816 : 0 : return cpfl_pci_probe_first(pci_dev);
2817 : : else
2818 : 0 : return cpfl_pci_probe_again(pci_dev, adapter);
2819 : : }
2820 : :
2821 : : static int
2822 : 0 : cpfl_pci_remove(struct rte_pci_device *pci_dev)
2823 : : {
2824 : 0 : struct cpfl_adapter_ext *adapter = cpfl_find_adapter_ext(pci_dev);
2825 : : uint16_t port_id;
2826 : :
2827 : : /* Ethdev created can be found RTE_ETH_FOREACH_DEV_OF through rte_device */
2828 [ # # ]: 0 : RTE_ETH_FOREACH_DEV_OF(port_id, &pci_dev->device) {
2829 : 0 : rte_eth_dev_close(port_id);
2830 : : }
2831 : :
2832 : : rte_spinlock_lock(&cpfl_adapter_lock);
2833 [ # # ]: 0 : TAILQ_REMOVE(&cpfl_adapter_list, adapter, next);
2834 : : rte_spinlock_unlock(&cpfl_adapter_lock);
2835 : 0 : cpfl_adapter_ext_deinit(adapter);
2836 : 0 : rte_free(adapter);
2837 : :
2838 : 0 : return 0;
2839 : : }
2840 : :
2841 : : static struct rte_pci_driver rte_cpfl_pmd = {
2842 : : .id_table = pci_id_cpfl_map,
2843 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING |
2844 : : RTE_PCI_DRV_PROBE_AGAIN,
2845 : : .probe = cpfl_pci_probe,
2846 : : .remove = cpfl_pci_remove,
2847 : : };
2848 : :
2849 : : /**
2850 : : * Driver initialization routine.
2851 : : * Invoked once at EAL init time.
2852 : : * Register itself as the [Poll Mode] Driver of PCI devices.
2853 : : */
2854 : 238 : RTE_PMD_REGISTER_PCI(net_cpfl, rte_cpfl_pmd);
2855 : : RTE_PMD_REGISTER_PCI_TABLE(net_cpfl, pci_id_cpfl_map);
2856 : : RTE_PMD_REGISTER_KMOD_DEP(net_cpfl, "* igb_uio | vfio-pci");
2857 : : RTE_PMD_REGISTER_PARAM_STRING(net_cpfl,
2858 : : CPFL_TX_SINGLE_Q "=<0|1> "
2859 : : CPFL_RX_SINGLE_Q "=<0|1> "
2860 : : CPFL_VPORT "=[vport0_begin[-vport0_end][,vport1_begin[-vport1_end]][,..]]");
2861 : :
2862 [ - + ]: 238 : RTE_LOG_REGISTER_SUFFIX(cpfl_logtype_init, init, NOTICE);
2863 [ - + ]: 238 : RTE_LOG_REGISTER_SUFFIX(cpfl_logtype_driver, driver, NOTICE);
|