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