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