Branch data Line data Source code
1 : : /* * SPDX-License-Identifier: BSD-3-Clause
2 : : *
3 : : * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
4 : : * Copyright 2016-2024 NXP
5 : : *
6 : : */
7 : :
8 : : #include <time.h>
9 : : #include <net/if.h>
10 : :
11 : : #include <rte_mbuf.h>
12 : : #include <ethdev_driver.h>
13 : : #include <rte_malloc.h>
14 : : #include <rte_memcpy.h>
15 : : #include <rte_string_fns.h>
16 : : #include <rte_cycles.h>
17 : : #include <rte_kvargs.h>
18 : : #include <dev_driver.h>
19 : : #include <bus_fslmc_driver.h>
20 : : #include <rte_flow_driver.h>
21 : : #include "rte_dpaa2_mempool.h"
22 : :
23 : : #include "dpaa2_pmd_logs.h"
24 : : #include <fslmc_vfio.h>
25 : : #include <dpaa2_hw_pvt.h>
26 : : #include <dpaa2_hw_mempool.h>
27 : : #include <dpaa2_hw_dpio.h>
28 : : #include <mc/fsl_dpmng.h>
29 : : #include "dpaa2_ethdev.h"
30 : : #include "dpaa2_sparser.h"
31 : : #include <fsl_qbman_debug.h>
32 : :
33 : : #define DRIVER_LOOPBACK_MODE "drv_loopback"
34 : : #define DRIVER_NO_PREFETCH_MODE "drv_no_prefetch"
35 : : #define DRIVER_TX_CONF "drv_tx_conf"
36 : : #define DRIVER_ERROR_QUEUE "drv_err_queue"
37 : : #define CHECK_INTERVAL 100 /* 100ms */
38 : : #define MAX_REPEAT_TIME 90 /* 9s (90 * 100ms) in total */
39 : :
40 : : /* Supported Rx offloads */
41 : : static uint64_t dev_rx_offloads_sup =
42 : : RTE_ETH_RX_OFFLOAD_CHECKSUM |
43 : : RTE_ETH_RX_OFFLOAD_SCTP_CKSUM |
44 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
45 : : RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM |
46 : : RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
47 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
48 : : RTE_ETH_RX_OFFLOAD_TIMESTAMP;
49 : :
50 : : /* Rx offloads which cannot be disabled */
51 : : static uint64_t dev_rx_offloads_nodis =
52 : : RTE_ETH_RX_OFFLOAD_RSS_HASH |
53 : : RTE_ETH_RX_OFFLOAD_SCATTER;
54 : :
55 : : /* Supported Tx offloads */
56 : : static uint64_t dev_tx_offloads_sup =
57 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
58 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
59 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
60 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
61 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
62 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
63 : : RTE_ETH_TX_OFFLOAD_MT_LOCKFREE |
64 : : RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
65 : :
66 : : /* Tx offloads which cannot be disabled */
67 : : static uint64_t dev_tx_offloads_nodis =
68 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
69 : :
70 : : /* enable timestamp in mbuf */
71 : : bool dpaa2_enable_ts[RTE_MAX_ETHPORTS];
72 : : uint64_t dpaa2_timestamp_rx_dynflag;
73 : : int dpaa2_timestamp_dynfield_offset = -1;
74 : :
75 : : /* Enable error queue */
76 : : bool dpaa2_enable_err_queue;
77 : :
78 : : bool dpaa2_print_parser_result;
79 : :
80 : : #define MAX_NB_RX_DESC 11264
81 : : int total_nb_rx_desc;
82 : :
83 : : int dpaa2_valid_dev;
84 : : struct rte_mempool *dpaa2_tx_sg_pool;
85 : :
86 : : struct rte_dpaa2_xstats_name_off {
87 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
88 : : uint8_t page_id; /* dpni statistics page id */
89 : : uint8_t stats_id; /* stats id in the given page */
90 : : };
91 : :
92 : : static const struct rte_dpaa2_xstats_name_off dpaa2_xstats_strings[] = {
93 : : {"ingress_multicast_frames", 0, 2},
94 : : {"ingress_multicast_bytes", 0, 3},
95 : : {"ingress_broadcast_frames", 0, 4},
96 : : {"ingress_broadcast_bytes", 0, 5},
97 : : {"egress_multicast_frames", 1, 2},
98 : : {"egress_multicast_bytes", 1, 3},
99 : : {"egress_broadcast_frames", 1, 4},
100 : : {"egress_broadcast_bytes", 1, 5},
101 : : {"ingress_filtered_frames", 2, 0},
102 : : {"ingress_discarded_frames", 2, 1},
103 : : {"ingress_nobuffer_discards", 2, 2},
104 : : {"egress_discarded_frames", 2, 3},
105 : : {"egress_confirmed_frames", 2, 4},
106 : : {"cgr_reject_frames", 4, 0},
107 : : {"cgr_reject_bytes", 4, 1},
108 : : };
109 : :
110 : : static struct rte_dpaa2_driver rte_dpaa2_pmd;
111 : : static int dpaa2_dev_link_update(struct rte_eth_dev *dev,
112 : : int wait_to_complete);
113 : : static int dpaa2_dev_set_link_up(struct rte_eth_dev *dev);
114 : : static int dpaa2_dev_set_link_down(struct rte_eth_dev *dev);
115 : : static int dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
116 : :
117 : : static int
118 : 0 : dpaa2_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
119 : : {
120 : : int ret;
121 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
122 : 0 : struct fsl_mc_io *dpni = dev->process_private;
123 : :
124 : 0 : PMD_INIT_FUNC_TRACE();
125 : :
126 [ # # ]: 0 : if (!dpni) {
127 : 0 : DPAA2_PMD_ERR("dpni is NULL");
128 : 0 : return -EINVAL;
129 : : }
130 : :
131 [ # # ]: 0 : if (on)
132 : 0 : ret = dpni_add_vlan_id(dpni, CMD_PRI_LOW, priv->token,
133 : : vlan_id, 0, 0, 0);
134 : : else
135 : 0 : ret = dpni_remove_vlan_id(dpni, CMD_PRI_LOW,
136 : 0 : priv->token, vlan_id);
137 : :
138 [ # # ]: 0 : if (ret < 0)
139 : 0 : DPAA2_PMD_ERR("ret = %d Unable to add/rem vlan %d hwid =%d",
140 : : ret, vlan_id, priv->hw_id);
141 : :
142 : : return ret;
143 : : }
144 : :
145 : : static int
146 : 0 : dpaa2_vlan_offload_set(struct rte_eth_dev *dev, int mask)
147 : : {
148 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
149 : 0 : struct fsl_mc_io *dpni = dev->process_private;
150 : : int ret = 0;
151 : :
152 : 0 : PMD_INIT_FUNC_TRACE();
153 : :
154 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
155 : : /* VLAN Filter not available */
156 [ # # ]: 0 : if (!priv->max_vlan_filters) {
157 : 0 : DPAA2_PMD_INFO("VLAN filter not available");
158 : 0 : return -ENOTSUP;
159 : : }
160 : :
161 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads &
162 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
163 : 0 : ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
164 : 0 : priv->token, true);
165 : : else
166 : 0 : ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
167 : 0 : priv->token, false);
168 [ # # ]: 0 : if (ret < 0)
169 : 0 : DPAA2_PMD_INFO("Unable to set vlan filter = %d", ret);
170 : : }
171 : :
172 : : return ret;
173 : : }
174 : :
175 : : static int
176 : 0 : dpaa2_vlan_tpid_set(struct rte_eth_dev *dev,
177 : : enum rte_vlan_type vlan_type __rte_unused,
178 : : uint16_t tpid)
179 : : {
180 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
181 : 0 : struct fsl_mc_io *dpni = dev->process_private;
182 : : int ret = -ENOTSUP;
183 : :
184 : 0 : PMD_INIT_FUNC_TRACE();
185 : :
186 : : /* nothing to be done for standard vlan tpids */
187 [ # # ]: 0 : if (tpid == 0x8100 || tpid == 0x88A8)
188 : : return 0;
189 : :
190 : 0 : ret = dpni_add_custom_tpid(dpni, CMD_PRI_LOW,
191 : 0 : priv->token, tpid);
192 [ # # ]: 0 : if (ret < 0)
193 : 0 : DPAA2_PMD_INFO("Unable to set vlan tpid = %d", ret);
194 : : /* if already configured tpids, remove them first */
195 [ # # ]: 0 : if (ret == -EBUSY) {
196 : 0 : struct dpni_custom_tpid_cfg tpid_list = {0};
197 : :
198 : 0 : ret = dpni_get_custom_tpid(dpni, CMD_PRI_LOW,
199 : 0 : priv->token, &tpid_list);
200 [ # # ]: 0 : if (ret < 0)
201 : 0 : goto fail;
202 : 0 : ret = dpni_remove_custom_tpid(dpni, CMD_PRI_LOW,
203 : 0 : priv->token, tpid_list.tpid1);
204 [ # # ]: 0 : if (ret < 0)
205 : 0 : goto fail;
206 : 0 : ret = dpni_add_custom_tpid(dpni, CMD_PRI_LOW,
207 : 0 : priv->token, tpid);
208 : : }
209 : 0 : fail:
210 : : return ret;
211 : : }
212 : :
213 : : static int
214 : 0 : dpaa2_fw_version_get(struct rte_eth_dev *dev,
215 : : char *fw_version, size_t fw_size)
216 : : {
217 : : int ret;
218 : 0 : struct fsl_mc_io *dpni = dev->process_private;
219 : 0 : struct mc_soc_version mc_plat_info = {0};
220 : 0 : struct mc_version mc_ver_info = {0};
221 : :
222 : 0 : PMD_INIT_FUNC_TRACE();
223 : :
224 [ # # ]: 0 : if (mc_get_soc_version(dpni, CMD_PRI_LOW, &mc_plat_info))
225 : 0 : DPAA2_PMD_WARN("\tmc_get_soc_version failed");
226 : :
227 [ # # ]: 0 : if (mc_get_version(dpni, CMD_PRI_LOW, &mc_ver_info))
228 : 0 : DPAA2_PMD_WARN("\tmc_get_version failed");
229 : :
230 [ # # ]: 0 : ret = snprintf(fw_version, fw_size,
231 : : "%x-%d.%d.%d",
232 : : mc_plat_info.svr,
233 : : mc_ver_info.major,
234 : : mc_ver_info.minor,
235 : : mc_ver_info.revision);
236 [ # # ]: 0 : if (ret < 0)
237 : : return -EINVAL;
238 : :
239 : 0 : ret += 1; /* add the size of '\0' */
240 [ # # ]: 0 : if (fw_size < (size_t)ret)
241 : : return ret;
242 : : else
243 : 0 : return 0;
244 : : }
245 : :
246 : : static int
247 : 0 : dpaa2_dev_info_get(struct rte_eth_dev *dev,
248 : : struct rte_eth_dev_info *dev_info)
249 : : {
250 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
251 : :
252 : 0 : PMD_INIT_FUNC_TRACE();
253 : :
254 : 0 : dev_info->max_mac_addrs = priv->max_mac_filters;
255 : 0 : dev_info->max_rx_pktlen = DPAA2_MAX_RX_PKT_LEN;
256 : 0 : dev_info->min_rx_bufsize = DPAA2_MIN_RX_BUF_SIZE;
257 : 0 : dev_info->max_rx_queues = (uint16_t)priv->nb_rx_queues;
258 : 0 : dev_info->max_tx_queues = (uint16_t)priv->nb_tx_queues;
259 : 0 : dev_info->rx_offload_capa = dev_rx_offloads_sup |
260 : : dev_rx_offloads_nodis;
261 : 0 : dev_info->tx_offload_capa = dev_tx_offloads_sup |
262 : : dev_tx_offloads_nodis;
263 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_1G |
264 : : RTE_ETH_LINK_SPEED_2_5G |
265 : : RTE_ETH_LINK_SPEED_10G;
266 : 0 : dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
267 : :
268 : 0 : dev_info->max_hash_mac_addrs = 0;
269 : 0 : dev_info->max_vfs = 0;
270 : 0 : dev_info->max_vmdq_pools = RTE_ETH_16_POOLS;
271 : 0 : dev_info->flow_type_rss_offloads = DPAA2_RSS_OFFLOAD_ALL;
272 : :
273 : 0 : dev_info->default_rxportconf.burst_size = dpaa2_dqrr_size;
274 : : /* same is rx size for best perf */
275 : 0 : dev_info->default_txportconf.burst_size = dpaa2_dqrr_size;
276 : :
277 : 0 : dev_info->default_rxportconf.nb_queues = 1;
278 : 0 : dev_info->default_txportconf.nb_queues = 1;
279 : 0 : dev_info->default_txportconf.ring_size = CONG_ENTER_TX_THRESHOLD;
280 : 0 : dev_info->default_rxportconf.ring_size = DPAA2_RX_DEFAULT_NBDESC;
281 : :
282 [ # # ]: 0 : if (dpaa2_svr_family == SVR_LX2160A) {
283 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_25G |
284 : : RTE_ETH_LINK_SPEED_40G |
285 : : RTE_ETH_LINK_SPEED_50G |
286 : : RTE_ETH_LINK_SPEED_100G;
287 : : }
288 : :
289 : 0 : return 0;
290 : : }
291 : :
292 : : static int
293 : 0 : dpaa2_dev_rx_burst_mode_get(struct rte_eth_dev *dev,
294 : : __rte_unused uint16_t queue_id,
295 : : struct rte_eth_burst_mode *mode)
296 : : {
297 : 0 : struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
298 : : int ret = -EINVAL;
299 : : unsigned int i;
300 : : const struct burst_info {
301 : : uint64_t flags;
302 : : const char *output;
303 : 0 : } rx_offload_map[] = {
304 : : {RTE_ETH_RX_OFFLOAD_CHECKSUM, " Checksum,"},
305 : : {RTE_ETH_RX_OFFLOAD_SCTP_CKSUM, " SCTP csum,"},
306 : : {RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM, " Outer IPV4 csum,"},
307 : : {RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM, " Outer UDP csum,"},
308 : : {RTE_ETH_RX_OFFLOAD_VLAN_STRIP, " VLAN strip,"},
309 : : {RTE_ETH_RX_OFFLOAD_VLAN_FILTER, " VLAN filter,"},
310 : : {RTE_ETH_RX_OFFLOAD_TIMESTAMP, " Timestamp,"},
311 : : {RTE_ETH_RX_OFFLOAD_RSS_HASH, " RSS,"},
312 : : {RTE_ETH_RX_OFFLOAD_SCATTER, " Scattered,"}
313 : : };
314 : :
315 : : /* Update Rx offload info */
316 [ # # ]: 0 : for (i = 0; i < RTE_DIM(rx_offload_map); i++) {
317 [ # # ]: 0 : if (eth_conf->rxmode.offloads & rx_offload_map[i].flags) {
318 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
319 : 0 : rx_offload_map[i].output);
320 : : ret = 0;
321 : 0 : break;
322 : : }
323 : : }
324 : 0 : return ret;
325 : : }
326 : :
327 : : static int
328 : 0 : dpaa2_dev_tx_burst_mode_get(struct rte_eth_dev *dev,
329 : : __rte_unused uint16_t queue_id,
330 : : struct rte_eth_burst_mode *mode)
331 : : {
332 : 0 : struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
333 : : int ret = -EINVAL;
334 : : unsigned int i;
335 : : const struct burst_info {
336 : : uint64_t flags;
337 : : const char *output;
338 : 0 : } tx_offload_map[] = {
339 : : {RTE_ETH_TX_OFFLOAD_VLAN_INSERT, " VLAN Insert,"},
340 : : {RTE_ETH_TX_OFFLOAD_IPV4_CKSUM, " IPV4 csum,"},
341 : : {RTE_ETH_TX_OFFLOAD_UDP_CKSUM, " UDP csum,"},
342 : : {RTE_ETH_TX_OFFLOAD_TCP_CKSUM, " TCP csum,"},
343 : : {RTE_ETH_TX_OFFLOAD_SCTP_CKSUM, " SCTP csum,"},
344 : : {RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM, " Outer IPV4 csum,"},
345 : : {RTE_ETH_TX_OFFLOAD_MT_LOCKFREE, " MT lockfree,"},
346 : : {RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE, " MBUF free disable,"},
347 : : {RTE_ETH_TX_OFFLOAD_MULTI_SEGS, " Scattered,"}
348 : : };
349 : :
350 : : /* Update Tx offload info */
351 [ # # ]: 0 : for (i = 0; i < RTE_DIM(tx_offload_map); i++) {
352 [ # # ]: 0 : if (eth_conf->txmode.offloads & tx_offload_map[i].flags) {
353 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
354 : 0 : tx_offload_map[i].output);
355 : : ret = 0;
356 : 0 : break;
357 : : }
358 : : }
359 : 0 : return ret;
360 : : }
361 : :
362 : : static int
363 : 0 : dpaa2_alloc_rx_tx_queues(struct rte_eth_dev *dev)
364 : : {
365 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
366 : : uint16_t dist_idx;
367 : : uint32_t vq_id;
368 : : uint8_t num_rxqueue_per_tc;
369 : : struct dpaa2_queue *mc_q, *mcq;
370 : : uint32_t tot_queues;
371 : : int i, ret = 0;
372 : : struct dpaa2_queue *dpaa2_q;
373 : :
374 : 0 : PMD_INIT_FUNC_TRACE();
375 : :
376 : 0 : num_rxqueue_per_tc = (priv->nb_rx_queues / priv->num_rx_tc);
377 [ # # ]: 0 : if (priv->flags & DPAA2_TX_CONF_ENABLE)
378 : 0 : tot_queues = priv->nb_rx_queues + 2 * priv->nb_tx_queues;
379 : : else
380 : 0 : tot_queues = priv->nb_rx_queues + priv->nb_tx_queues;
381 : 0 : mc_q = rte_malloc(NULL, sizeof(struct dpaa2_queue) * tot_queues,
382 : : RTE_CACHE_LINE_SIZE);
383 [ # # ]: 0 : if (!mc_q) {
384 : 0 : DPAA2_PMD_ERR("Memory allocation failed for rx/tx queues");
385 : 0 : return -ENOBUFS;
386 : : }
387 : :
388 [ # # ]: 0 : for (i = 0; i < priv->nb_rx_queues; i++) {
389 : 0 : mc_q->eth_data = dev->data;
390 : 0 : priv->rx_vq[i] = mc_q++;
391 : : dpaa2_q = priv->rx_vq[i];
392 [ # # # # : 0 : ret = dpaa2_queue_storage_alloc(dpaa2_q,
# # ]
393 : : RTE_MAX_LCORE);
394 [ # # ]: 0 : if (ret)
395 : 0 : goto fail;
396 : : }
397 : :
398 [ # # ]: 0 : if (dpaa2_enable_err_queue) {
399 : 0 : priv->rx_err_vq = rte_zmalloc("dpni_rx_err",
400 : : sizeof(struct dpaa2_queue), 0);
401 [ # # ]: 0 : if (!priv->rx_err_vq) {
402 : : ret = -ENOBUFS;
403 : 0 : goto fail;
404 : : }
405 : :
406 : : dpaa2_q = priv->rx_err_vq;
407 [ # # # # : 0 : ret = dpaa2_queue_storage_alloc(dpaa2_q,
# # ]
408 : : RTE_MAX_LCORE);
409 [ # # ]: 0 : if (ret)
410 : 0 : goto fail;
411 : : }
412 : :
413 [ # # ]: 0 : for (i = 0; i < priv->nb_tx_queues; i++) {
414 : 0 : mc_q->eth_data = dev->data;
415 : 0 : mc_q->flow_id = DPAA2_INVALID_FLOW_ID;
416 : 0 : priv->tx_vq[i] = mc_q++;
417 : : dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
418 : 0 : dpaa2_q->cscn = rte_malloc(NULL,
419 : : sizeof(struct qbman_result), 16);
420 [ # # ]: 0 : if (!dpaa2_q->cscn) {
421 : : ret = -ENOBUFS;
422 : 0 : goto fail_tx;
423 : : }
424 : : }
425 : :
426 [ # # ]: 0 : if (priv->flags & DPAA2_TX_CONF_ENABLE) {
427 : : /*Setup tx confirmation queues*/
428 [ # # ]: 0 : for (i = 0; i < priv->nb_tx_queues; i++) {
429 : 0 : mc_q->eth_data = dev->data;
430 : 0 : mc_q->tc_index = i;
431 : 0 : mc_q->flow_id = 0;
432 : 0 : priv->tx_conf_vq[i] = mc_q++;
433 : : dpaa2_q = priv->tx_conf_vq[i];
434 [ # # # # : 0 : ret = dpaa2_queue_storage_alloc(dpaa2_q,
# # ]
435 : : RTE_MAX_LCORE);
436 [ # # ]: 0 : if (ret)
437 : 0 : goto fail_tx_conf;
438 : : }
439 : : }
440 : :
441 : : vq_id = 0;
442 [ # # ]: 0 : for (dist_idx = 0; dist_idx < priv->nb_rx_queues; dist_idx++) {
443 : 0 : mcq = priv->rx_vq[vq_id];
444 : 0 : mcq->tc_index = dist_idx / num_rxqueue_per_tc;
445 : 0 : mcq->flow_id = dist_idx % num_rxqueue_per_tc;
446 : 0 : vq_id++;
447 : : }
448 : :
449 : : return 0;
450 : : fail_tx_conf:
451 : 0 : i -= 1;
452 [ # # ]: 0 : while (i >= 0) {
453 : 0 : dpaa2_q = priv->tx_conf_vq[i];
454 [ # # # # ]: 0 : dpaa2_queue_storage_free(dpaa2_q, RTE_MAX_LCORE);
455 : 0 : priv->tx_conf_vq[i--] = NULL;
456 : : }
457 : 0 : i = priv->nb_tx_queues;
458 : 0 : fail_tx:
459 : 0 : i -= 1;
460 [ # # ]: 0 : while (i >= 0) {
461 : 0 : dpaa2_q = priv->tx_vq[i];
462 : 0 : rte_free(dpaa2_q->cscn);
463 : 0 : priv->tx_vq[i--] = NULL;
464 : : }
465 : 0 : i = priv->nb_rx_queues;
466 : 0 : fail:
467 : 0 : i -= 1;
468 : 0 : mc_q = priv->rx_vq[0];
469 [ # # ]: 0 : while (i >= 0) {
470 : 0 : dpaa2_q = priv->rx_vq[i];
471 [ # # # # ]: 0 : dpaa2_queue_storage_free(dpaa2_q, RTE_MAX_LCORE);
472 : 0 : priv->rx_vq[i--] = NULL;
473 : : }
474 : :
475 [ # # ]: 0 : if (dpaa2_enable_err_queue) {
476 : 0 : dpaa2_q = priv->rx_err_vq;
477 [ # # # # ]: 0 : dpaa2_queue_storage_free(dpaa2_q, RTE_MAX_LCORE);
478 : : }
479 : :
480 : 0 : rte_free(mc_q);
481 : 0 : return ret;
482 : : }
483 : :
484 : : static void
485 : 0 : dpaa2_free_rx_tx_queues(struct rte_eth_dev *dev)
486 : : {
487 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
488 : : struct dpaa2_queue *dpaa2_q;
489 : : int i;
490 : :
491 : 0 : PMD_INIT_FUNC_TRACE();
492 : :
493 : : /* Queue allocation base */
494 [ # # ]: 0 : if (priv->rx_vq[0]) {
495 : : /* cleaning up queue storage */
496 [ # # ]: 0 : for (i = 0; i < priv->nb_rx_queues; i++) {
497 : 0 : dpaa2_q = priv->rx_vq[i];
498 [ # # # # ]: 0 : dpaa2_queue_storage_free(dpaa2_q,
499 : : RTE_MAX_LCORE);
500 : : }
501 : : /* cleanup tx queue cscn */
502 [ # # ]: 0 : for (i = 0; i < priv->nb_tx_queues; i++) {
503 : 0 : dpaa2_q = priv->tx_vq[i];
504 : 0 : rte_free(dpaa2_q->cscn);
505 : : }
506 [ # # ]: 0 : if (priv->flags & DPAA2_TX_CONF_ENABLE) {
507 : : /* cleanup tx conf queue storage */
508 [ # # ]: 0 : for (i = 0; i < priv->nb_tx_queues; i++) {
509 : 0 : dpaa2_q = priv->tx_conf_vq[i];
510 [ # # # # ]: 0 : dpaa2_queue_storage_free(dpaa2_q,
511 : : RTE_MAX_LCORE);
512 : : }
513 : : }
514 : : /*free memory for all queues (RX+TX) */
515 : 0 : rte_free(priv->rx_vq[0]);
516 : 0 : priv->rx_vq[0] = NULL;
517 : : }
518 : 0 : }
519 : :
520 : : static int
521 : 0 : dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
522 : : {
523 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
524 : 0 : struct fsl_mc_io *dpni = dev->process_private;
525 : : struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
526 : 0 : uint64_t rx_offloads = eth_conf->rxmode.offloads;
527 : 0 : uint64_t tx_offloads = eth_conf->txmode.offloads;
528 : : int rx_l3_csum_offload = false;
529 : : int rx_l4_csum_offload = false;
530 : : int tx_l3_csum_offload = false;
531 : : int tx_l4_csum_offload = false;
532 : : int ret, tc_index;
533 : : uint32_t max_rx_pktlen;
534 : : #if defined(RTE_LIBRTE_IEEE1588)
535 : : uint16_t ptp_correction_offset;
536 : : #endif
537 : :
538 : 0 : PMD_INIT_FUNC_TRACE();
539 : :
540 : : /* Rx offloads which are enabled by default */
541 [ # # ]: 0 : if (dev_rx_offloads_nodis & ~rx_offloads) {
542 : 0 : DPAA2_PMD_INFO(
543 : : "Some of rx offloads enabled by default - requested 0x%" PRIx64
544 : : " fixed are 0x%" PRIx64,
545 : : rx_offloads, dev_rx_offloads_nodis);
546 : : }
547 : :
548 : : /* Tx offloads which are enabled by default */
549 [ # # ]: 0 : if (dev_tx_offloads_nodis & ~tx_offloads) {
550 : 0 : DPAA2_PMD_INFO(
551 : : "Some of tx offloads enabled by default - requested 0x%" PRIx64
552 : : " fixed are 0x%" PRIx64,
553 : : tx_offloads, dev_tx_offloads_nodis);
554 : : }
555 : :
556 : 0 : max_rx_pktlen = eth_conf->rxmode.mtu + RTE_ETHER_HDR_LEN +
557 : : RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE;
558 [ # # ]: 0 : if (max_rx_pktlen <= DPAA2_MAX_RX_PKT_LEN) {
559 : 0 : ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW,
560 : 0 : priv->token, max_rx_pktlen - RTE_ETHER_CRC_LEN);
561 [ # # ]: 0 : if (ret != 0) {
562 : 0 : DPAA2_PMD_ERR("Unable to set mtu. check config");
563 : 0 : return ret;
564 : : }
565 : 0 : DPAA2_PMD_DEBUG("MTU configured for the device: %d",
566 : : dev->data->mtu);
567 : : } else {
568 : 0 : DPAA2_PMD_ERR("Configured mtu %d and calculated max-pkt-len is %d which should be <= %d",
569 : : eth_conf->rxmode.mtu, max_rx_pktlen, DPAA2_MAX_RX_PKT_LEN);
570 : 0 : return -1;
571 : : }
572 : :
573 [ # # ]: 0 : if (eth_conf->rxmode.mq_mode == RTE_ETH_MQ_RX_RSS) {
574 [ # # ]: 0 : for (tc_index = 0; tc_index < priv->num_rx_tc; tc_index++) {
575 : 0 : ret = dpaa2_setup_flow_dist(dev,
576 : : eth_conf->rx_adv_conf.rss_conf.rss_hf,
577 : : tc_index);
578 [ # # ]: 0 : if (ret) {
579 : 0 : DPAA2_PMD_ERR(
580 : : "Unable to set flow distribution on tc%d."
581 : : "Check queue config", tc_index);
582 : 0 : return ret;
583 : : }
584 : : }
585 : : }
586 : :
587 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM)
588 : : rx_l3_csum_offload = true;
589 : :
590 : 0 : if ((rx_offloads & RTE_ETH_RX_OFFLOAD_UDP_CKSUM) ||
591 [ # # ]: 0 : (rx_offloads & RTE_ETH_RX_OFFLOAD_TCP_CKSUM) ||
592 : : (rx_offloads & RTE_ETH_RX_OFFLOAD_SCTP_CKSUM))
593 : : rx_l4_csum_offload = true;
594 : :
595 : 0 : ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
596 : : DPNI_OFF_RX_L3_CSUM, rx_l3_csum_offload);
597 [ # # ]: 0 : if (ret) {
598 : 0 : DPAA2_PMD_ERR("Error to set RX l3 csum:Error = %d", ret);
599 : 0 : return ret;
600 : : }
601 : :
602 : 0 : ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
603 : : DPNI_OFF_RX_L4_CSUM, rx_l4_csum_offload);
604 [ # # ]: 0 : if (ret) {
605 : 0 : DPAA2_PMD_ERR("Error to get RX l4 csum:Error = %d", ret);
606 : 0 : return ret;
607 : : }
608 : :
609 : : #if !defined(RTE_LIBRTE_IEEE1588)
610 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
611 : : #endif
612 : : {
613 : 0 : ret = rte_mbuf_dyn_rx_timestamp_register(
614 : : &dpaa2_timestamp_dynfield_offset,
615 : : &dpaa2_timestamp_rx_dynflag);
616 [ # # ]: 0 : if (ret != 0) {
617 : 0 : DPAA2_PMD_ERR("Error to register timestamp field/flag");
618 : 0 : return -rte_errno;
619 : : }
620 : 0 : dpaa2_enable_ts[dev->data->port_id] = true;
621 : : }
622 : :
623 : : #if defined(RTE_LIBRTE_IEEE1588)
624 : : /* By default setting ptp correction offset for Ethernet SYNC packets */
625 : : ptp_correction_offset = RTE_ETHER_HDR_LEN + 8;
626 : : rte_pmd_dpaa2_set_one_step_ts(dev->data->port_id, ptp_correction_offset, 0);
627 : : #endif
628 [ # # ]: 0 : if (tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)
629 : : tx_l3_csum_offload = true;
630 : :
631 : 0 : if ((tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) ||
632 [ # # ]: 0 : (tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) ||
633 : : (tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM))
634 : : tx_l4_csum_offload = true;
635 : :
636 : 0 : ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
637 : : DPNI_OFF_TX_L3_CSUM, tx_l3_csum_offload);
638 [ # # ]: 0 : if (ret) {
639 : 0 : DPAA2_PMD_ERR("Error to set TX l3 csum:Error = %d", ret);
640 : 0 : return ret;
641 : : }
642 : :
643 : 0 : ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
644 : : DPNI_OFF_TX_L4_CSUM, tx_l4_csum_offload);
645 [ # # ]: 0 : if (ret) {
646 : 0 : DPAA2_PMD_ERR("Error to get TX l4 csum:Error = %d", ret);
647 : 0 : return ret;
648 : : }
649 : :
650 : : /* Enabling hash results in FD requires setting DPNI_FLCTYPE_HASH in
651 : : * dpni_set_offload API. Setting this FLCTYPE for DPNI sets the FD[SC]
652 : : * to 0 for LS2 in the hardware thus disabling data/annotation
653 : : * stashing. For LX2 this is fixed in hardware and thus hash result and
654 : : * parse results can be received in FD using this option.
655 : : */
656 [ # # ]: 0 : if (dpaa2_svr_family == SVR_LX2160A) {
657 : 0 : ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
658 : : DPNI_FLCTYPE_HASH, true);
659 [ # # ]: 0 : if (ret) {
660 : 0 : DPAA2_PMD_ERR("Error setting FLCTYPE: Err = %d", ret);
661 : 0 : return ret;
662 : : }
663 : : }
664 : :
665 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
666 : 0 : dpaa2_vlan_offload_set(dev, RTE_ETH_VLAN_FILTER_MASK);
667 : :
668 [ # # ]: 0 : if (eth_conf->lpbk_mode) {
669 : 0 : ret = dpaa2_dev_recycle_config(dev);
670 [ # # ]: 0 : if (ret) {
671 : 0 : DPAA2_PMD_ERR("Error to configure %s to recycle port.",
672 : : dev->data->name);
673 : :
674 : 0 : return ret;
675 : : }
676 : : } else {
677 : : /** User may disable loopback mode by calling
678 : : * "dev_configure" with lpbk_mode cleared.
679 : : * No matter the port was configured recycle or not,
680 : : * recycle de-configure is called here.
681 : : * If port is not recycled, the de-configure will return directly.
682 : : */
683 : 0 : ret = dpaa2_dev_recycle_deconfig(dev);
684 [ # # ]: 0 : if (ret) {
685 : 0 : DPAA2_PMD_ERR("Error to de-configure recycle port %s.",
686 : : dev->data->name);
687 : :
688 : 0 : return ret;
689 : : }
690 : : }
691 : :
692 : 0 : dpaa2_tm_init(dev);
693 : :
694 : 0 : return 0;
695 : : }
696 : :
697 : : /* Function to setup RX flow information. It contains traffic class ID,
698 : : * flow ID, destination configuration etc.
699 : : */
700 : : static int
701 : 0 : dpaa2_dev_rx_queue_setup(struct rte_eth_dev *dev,
702 : : uint16_t rx_queue_id,
703 : : uint16_t nb_rx_desc,
704 : : unsigned int socket_id __rte_unused,
705 : : const struct rte_eth_rxconf *rx_conf,
706 : : struct rte_mempool *mb_pool)
707 : : {
708 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
709 : 0 : struct fsl_mc_io *dpni = dev->process_private;
710 : : struct dpaa2_queue *dpaa2_q;
711 : : struct dpni_queue cfg;
712 : : uint8_t options = 0;
713 : : uint8_t flow_id;
714 : : uint32_t bpid;
715 : : int i, ret;
716 : :
717 : 0 : PMD_INIT_FUNC_TRACE();
718 : :
719 : 0 : DPAA2_PMD_DEBUG("dev =%p, queue =%d, pool = %p, conf =%p",
720 : : dev, rx_queue_id, mb_pool, rx_conf);
721 : :
722 : 0 : total_nb_rx_desc += nb_rx_desc;
723 [ # # ]: 0 : if (total_nb_rx_desc > MAX_NB_RX_DESC) {
724 : 0 : DPAA2_PMD_WARN("Total nb_rx_desc exceeds %d limit. Please use Normal buffers",
725 : : MAX_NB_RX_DESC);
726 : 0 : DPAA2_PMD_WARN("To use Normal buffers, run 'export DPNI_NORMAL_BUF=1' before running dynamic_dpl.sh script");
727 : : }
728 : :
729 [ # # # # ]: 0 : if (!priv->bp_list || priv->bp_list->mp != mb_pool) {
730 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
731 : 0 : ret = rte_dpaa2_bpid_info_init(mb_pool);
732 [ # # ]: 0 : if (ret)
733 : : return ret;
734 : : }
735 : 0 : bpid = mempool_to_bpid(mb_pool);
736 : 0 : ret = dpaa2_attach_bp_list(priv, dpni,
737 : 0 : rte_dpaa2_bpid_info[bpid].bp_list);
738 [ # # ]: 0 : if (ret)
739 : : return ret;
740 : : }
741 : 0 : dpaa2_q = priv->rx_vq[rx_queue_id];
742 : 0 : dpaa2_q->mb_pool = mb_pool; /**< mbuf pool to populate RX ring. */
743 : 0 : dpaa2_q->bp_array = rte_dpaa2_bpid_info;
744 : 0 : dpaa2_q->nb_desc = UINT16_MAX;
745 : 0 : dpaa2_q->offloads = rx_conf->offloads;
746 : :
747 : : /*Get the flow id from given VQ id*/
748 : 0 : flow_id = dpaa2_q->flow_id;
749 : : memset(&cfg, 0, sizeof(struct dpni_queue));
750 : :
751 : : options = options | DPNI_QUEUE_OPT_USER_CTX;
752 : 0 : cfg.user_context = (size_t)(dpaa2_q);
753 : :
754 : : /* check if a private cgr available. */
755 [ # # ]: 0 : for (i = 0; i < priv->max_cgs; i++) {
756 [ # # ]: 0 : if (!priv->cgid_in_use[i]) {
757 : 0 : priv->cgid_in_use[i] = 1;
758 : 0 : break;
759 : : }
760 : : }
761 : :
762 [ # # ]: 0 : if (i < priv->max_cgs) {
763 : : options |= DPNI_QUEUE_OPT_SET_CGID;
764 : 0 : cfg.cgid = i;
765 : 0 : dpaa2_q->cgid = cfg.cgid;
766 : : } else {
767 : 0 : dpaa2_q->cgid = DPAA2_INVALID_CGID;
768 : : }
769 : :
770 : : /*if ls2088 or rev2 device, enable the stashing */
771 : :
772 [ # # ]: 0 : if ((dpaa2_svr_family & 0xffff0000) != SVR_LS2080A) {
773 : 0 : options |= DPNI_QUEUE_OPT_FLC;
774 : 0 : cfg.flc.stash_control = true;
775 : : dpaa2_flc_stashing_clear_all(&cfg.flc.value);
776 [ # # ]: 0 : if (getenv("DPAA2_DATA_STASHING_OFF")) {
777 : : dpaa2_flc_stashing_set(DPAA2_FLC_DATA_STASHING, 0,
778 : : &cfg.flc.value);
779 : 0 : dpaa2_q->data_stashing_off = 1;
780 : : } else {
781 : : dpaa2_flc_stashing_set(DPAA2_FLC_DATA_STASHING, 1,
782 : : &cfg.flc.value);
783 : 0 : dpaa2_q->data_stashing_off = 0;
784 : : }
785 [ # # ]: 0 : if ((dpaa2_svr_family & 0xffff0000) != SVR_LX2160A) {
786 : : dpaa2_flc_stashing_set(DPAA2_FLC_ANNO_STASHING, 1,
787 : : &cfg.flc.value);
788 : : }
789 : : }
790 : 0 : ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_RX,
791 : 0 : dpaa2_q->tc_index, flow_id, options, &cfg);
792 [ # # ]: 0 : if (ret) {
793 : 0 : DPAA2_PMD_ERR("Error in setting the rx flow: = %d", ret);
794 : 0 : return ret;
795 : : }
796 : :
797 [ # # ]: 0 : if (!(priv->flags & DPAA2_RX_TAILDROP_OFF)) {
798 : : struct dpni_taildrop taildrop;
799 : :
800 : 0 : taildrop.enable = 1;
801 : 0 : dpaa2_q->nb_desc = nb_rx_desc;
802 : : /* Private CGR will use tail drop length as nb_rx_desc.
803 : : * for rest cases we can use standard byte based tail drop.
804 : : * There is no HW restriction, but number of CGRs are limited,
805 : : * hence this restriction is placed.
806 : : */
807 [ # # ]: 0 : if (dpaa2_q->cgid != DPAA2_INVALID_CGID) {
808 : : /*enabling per rx queue congestion control */
809 : 0 : taildrop.threshold = nb_rx_desc;
810 : 0 : taildrop.units = DPNI_CONGESTION_UNIT_FRAMES;
811 : 0 : taildrop.oal = 0;
812 : 0 : DPAA2_PMD_DEBUG("Enabling CG Tail Drop on queue = %d",
813 : : rx_queue_id);
814 : 0 : ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
815 : : DPNI_CP_CONGESTION_GROUP,
816 : : DPNI_QUEUE_RX,
817 : 0 : dpaa2_q->tc_index,
818 : 0 : dpaa2_q->cgid, &taildrop);
819 : : } else {
820 : : /*enabling per rx queue congestion control */
821 : 0 : taildrop.threshold = CONG_THRESHOLD_RX_BYTES_Q;
822 : 0 : taildrop.units = DPNI_CONGESTION_UNIT_BYTES;
823 : 0 : taildrop.oal = CONG_RX_OAL;
824 : 0 : DPAA2_PMD_DEBUG("Enabling Byte based Drop on queue= %d",
825 : : rx_queue_id);
826 : 0 : ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
827 : : DPNI_CP_QUEUE, DPNI_QUEUE_RX,
828 : 0 : dpaa2_q->tc_index, flow_id,
829 : : &taildrop);
830 : : }
831 [ # # ]: 0 : if (ret) {
832 : 0 : DPAA2_PMD_ERR("Error in setting taildrop. err=(%d)",
833 : : ret);
834 : 0 : return ret;
835 : : }
836 : : } else { /* Disable tail Drop */
837 : 0 : struct dpni_taildrop taildrop = {0};
838 : 0 : DPAA2_PMD_INFO("Tail drop is disabled on queue");
839 : :
840 : 0 : taildrop.enable = 0;
841 [ # # ]: 0 : if (dpaa2_q->cgid != DPAA2_INVALID_CGID) {
842 : 0 : ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
843 : : DPNI_CP_CONGESTION_GROUP, DPNI_QUEUE_RX,
844 : 0 : dpaa2_q->tc_index,
845 : : dpaa2_q->cgid, &taildrop);
846 : : } else {
847 : 0 : ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
848 : : DPNI_CP_QUEUE, DPNI_QUEUE_RX,
849 : 0 : dpaa2_q->tc_index, flow_id, &taildrop);
850 : : }
851 [ # # ]: 0 : if (ret) {
852 : 0 : DPAA2_PMD_ERR("Error in setting taildrop. err=(%d)",
853 : : ret);
854 : 0 : return ret;
855 : : }
856 : : }
857 : :
858 : 0 : dev->data->rx_queues[rx_queue_id] = dpaa2_q;
859 : 0 : return 0;
860 : : }
861 : :
862 : : static int
863 : 0 : dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
864 : : uint16_t tx_queue_id,
865 : : uint16_t nb_tx_desc,
866 : : unsigned int socket_id __rte_unused,
867 : : const struct rte_eth_txconf *tx_conf)
868 : : {
869 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
870 : 0 : struct dpaa2_queue *dpaa2_q = priv->tx_vq[tx_queue_id];
871 : 0 : struct dpaa2_queue *dpaa2_tx_conf_q = priv->tx_conf_vq[tx_queue_id];
872 : 0 : struct fsl_mc_io *dpni = dev->process_private;
873 : : struct dpni_queue tx_conf_cfg;
874 : : struct dpni_queue tx_flow_cfg;
875 : : uint8_t options = 0, flow_id;
876 : : uint8_t ceetm_ch_idx;
877 : : uint16_t channel_id;
878 : : struct dpni_queue_id qid;
879 : : uint32_t tc_id;
880 : : int ret;
881 : : uint64_t iova;
882 : :
883 : 0 : PMD_INIT_FUNC_TRACE();
884 : :
885 : 0 : dpaa2_q->nb_desc = UINT16_MAX;
886 : 0 : dpaa2_q->offloads = tx_conf->offloads;
887 : :
888 : : /* Return if queue already configured */
889 [ # # ]: 0 : if (dpaa2_q->flow_id != DPAA2_INVALID_FLOW_ID) {
890 : 0 : dev->data->tx_queues[tx_queue_id] = dpaa2_q;
891 : 0 : return 0;
892 : : }
893 : :
894 : : memset(&tx_conf_cfg, 0, sizeof(struct dpni_queue));
895 : : memset(&tx_flow_cfg, 0, sizeof(struct dpni_queue));
896 : :
897 [ # # ]: 0 : if (!tx_queue_id) {
898 : : for (ceetm_ch_idx = 0;
899 [ # # ]: 0 : ceetm_ch_idx <= (priv->num_channels - 1);
900 : 0 : ceetm_ch_idx++) {
901 : : /*Set tx-conf and error configuration*/
902 [ # # ]: 0 : if (priv->flags & DPAA2_TX_CONF_ENABLE) {
903 : 0 : ret = dpni_set_tx_confirmation_mode(dpni,
904 : 0 : CMD_PRI_LOW, priv->token,
905 : : ceetm_ch_idx,
906 : : DPNI_CONF_AFFINE);
907 : : } else {
908 : 0 : ret = dpni_set_tx_confirmation_mode(dpni,
909 : 0 : CMD_PRI_LOW, priv->token,
910 : : ceetm_ch_idx,
911 : : DPNI_CONF_DISABLE);
912 : : }
913 [ # # ]: 0 : if (ret) {
914 : 0 : DPAA2_PMD_ERR("Error(%d) in tx conf setting",
915 : : ret);
916 : 0 : return ret;
917 : : }
918 : : }
919 : : }
920 : :
921 : 0 : tc_id = tx_queue_id % priv->num_tx_tc;
922 : 0 : channel_id = (uint8_t)(tx_queue_id / priv->num_tx_tc) % priv->num_channels;
923 : : flow_id = 0;
924 : :
925 : 0 : ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
926 : 0 : ((channel_id << 8) | tc_id), flow_id, options, &tx_flow_cfg);
927 [ # # ]: 0 : if (ret) {
928 : 0 : DPAA2_PMD_ERR("Error in setting the tx flow: "
929 : : "tc_id=%d, flow=%d err=%d",
930 : : tc_id, flow_id, ret);
931 : 0 : return ret;
932 : : }
933 : :
934 : 0 : dpaa2_q->flow_id = flow_id;
935 : :
936 : 0 : dpaa2_q->tc_index = tc_id;
937 : :
938 : 0 : ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
939 : 0 : DPNI_QUEUE_TX, ((channel_id << 8) | dpaa2_q->tc_index),
940 : : dpaa2_q->flow_id, &tx_flow_cfg, &qid);
941 [ # # ]: 0 : if (ret) {
942 : 0 : DPAA2_PMD_ERR("Error in getting LFQID err=%d", ret);
943 : 0 : return ret;
944 : : }
945 : 0 : dpaa2_q->fqid = qid.fqid;
946 : :
947 [ # # ]: 0 : if (!(priv->flags & DPAA2_TX_CGR_OFF)) {
948 : 0 : struct dpni_congestion_notification_cfg cong_notif_cfg = {0};
949 : :
950 : 0 : dpaa2_q->nb_desc = nb_tx_desc;
951 : :
952 : 0 : cong_notif_cfg.units = DPNI_CONGESTION_UNIT_FRAMES;
953 : 0 : cong_notif_cfg.threshold_entry = nb_tx_desc;
954 : : /* Notify that the queue is not congested when the data in
955 : : * the queue is below this threshold.(90% of value)
956 : : */
957 : 0 : cong_notif_cfg.threshold_exit = (nb_tx_desc * 9) / 10;
958 : : cong_notif_cfg.message_ctx = 0;
959 : :
960 : 0 : iova = DPAA2_VADDR_TO_IOVA_AND_CHECK(dpaa2_q->cscn,
961 : : sizeof(struct qbman_result));
962 [ # # ]: 0 : if (iova == RTE_BAD_IOVA) {
963 : 0 : DPAA2_PMD_ERR("No IOMMU map for cscn(%p)(size=%x)",
964 : : dpaa2_q->cscn, (uint32_t)sizeof(struct qbman_result));
965 : :
966 : 0 : return -ENOBUFS;
967 : : }
968 : :
969 : 0 : cong_notif_cfg.message_iova = iova;
970 : 0 : cong_notif_cfg.dest_cfg.dest_type = DPNI_DEST_NONE;
971 : 0 : cong_notif_cfg.notification_mode =
972 : : DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
973 : : DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
974 : : DPNI_CONG_OPT_COHERENT_WRITE;
975 : 0 : cong_notif_cfg.cg_point = DPNI_CP_QUEUE;
976 : :
977 : 0 : ret = dpni_set_congestion_notification(dpni,
978 : 0 : CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
979 : : ((channel_id << 8) | tc_id), &cong_notif_cfg);
980 [ # # ]: 0 : if (ret) {
981 : 0 : DPAA2_PMD_ERR("Set TX congestion notification err=%d",
982 : : ret);
983 : 0 : return ret;
984 : : }
985 : : }
986 : 0 : dpaa2_q->cb_eqresp_free = dpaa2_dev_free_eqresp_buf;
987 : 0 : dev->data->tx_queues[tx_queue_id] = dpaa2_q;
988 : :
989 [ # # ]: 0 : if (priv->flags & DPAA2_TX_CONF_ENABLE) {
990 : 0 : dpaa2_q->tx_conf_queue = dpaa2_tx_conf_q;
991 : : options = options | DPNI_QUEUE_OPT_USER_CTX;
992 : 0 : tx_conf_cfg.user_context = (size_t)(dpaa2_q);
993 : 0 : ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token,
994 : : DPNI_QUEUE_TX_CONFIRM,
995 : 0 : ((channel_id << 8) | dpaa2_tx_conf_q->tc_index),
996 : 0 : dpaa2_tx_conf_q->flow_id,
997 : : options, &tx_conf_cfg);
998 [ # # ]: 0 : if (ret) {
999 : 0 : DPAA2_PMD_ERR("Set TC[%d].TX[%d] conf flow err=%d",
1000 : : dpaa2_tx_conf_q->tc_index,
1001 : : dpaa2_tx_conf_q->flow_id, ret);
1002 : 0 : return ret;
1003 : : }
1004 : :
1005 : 0 : ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
1006 : : DPNI_QUEUE_TX_CONFIRM,
1007 : 0 : ((channel_id << 8) | dpaa2_tx_conf_q->tc_index),
1008 : 0 : dpaa2_tx_conf_q->flow_id, &tx_conf_cfg, &qid);
1009 [ # # ]: 0 : if (ret) {
1010 : 0 : DPAA2_PMD_ERR("Error in getting LFQID err=%d", ret);
1011 : 0 : return ret;
1012 : : }
1013 : 0 : dpaa2_tx_conf_q->fqid = qid.fqid;
1014 : : }
1015 : : return 0;
1016 : : }
1017 : :
1018 : : static void
1019 : 0 : dpaa2_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1020 : : {
1021 : 0 : struct dpaa2_queue *dpaa2_q = dev->data->rx_queues[rx_queue_id];
1022 : 0 : struct dpaa2_dev_priv *priv = dpaa2_q->eth_data->dev_private;
1023 : 0 : struct fsl_mc_io *dpni = priv->eth_dev->process_private;
1024 : : uint8_t options = 0;
1025 : : int ret;
1026 : : struct dpni_queue cfg;
1027 : :
1028 : : memset(&cfg, 0, sizeof(struct dpni_queue));
1029 : 0 : PMD_INIT_FUNC_TRACE();
1030 : :
1031 : 0 : total_nb_rx_desc -= dpaa2_q->nb_desc;
1032 : :
1033 [ # # ]: 0 : if (dpaa2_q->cgid != DPAA2_INVALID_CGID) {
1034 : : options = DPNI_QUEUE_OPT_CLEAR_CGID;
1035 : 0 : cfg.cgid = dpaa2_q->cgid;
1036 : :
1037 : 0 : ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token,
1038 : : DPNI_QUEUE_RX,
1039 : 0 : dpaa2_q->tc_index, dpaa2_q->flow_id,
1040 : : options, &cfg);
1041 [ # # ]: 0 : if (ret)
1042 : 0 : DPAA2_PMD_ERR("Unable to clear CGR from q=%u err=%d",
1043 : : dpaa2_q->fqid, ret);
1044 : 0 : priv->cgid_in_use[dpaa2_q->cgid] = 0;
1045 : 0 : dpaa2_q->cgid = DPAA2_INVALID_CGID;
1046 : : }
1047 : 0 : }
1048 : :
1049 : : static uint32_t
1050 : 0 : dpaa2_dev_rx_queue_count(void *rx_queue)
1051 : : {
1052 : : int32_t ret;
1053 : : struct dpaa2_queue *dpaa2_q;
1054 : : struct qbman_swp *swp;
1055 : : struct qbman_fq_query_np_rslt state;
1056 : : uint32_t frame_cnt = 0;
1057 : :
1058 [ # # ]: 0 : if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
1059 : 0 : ret = dpaa2_affine_qbman_swp();
1060 [ # # ]: 0 : if (ret) {
1061 : 0 : DPAA2_PMD_ERR(
1062 : : "Failed to allocate IO portal, tid: %d",
1063 : : rte_gettid());
1064 : 0 : return -EINVAL;
1065 : : }
1066 : : }
1067 : 0 : swp = DPAA2_PER_LCORE_PORTAL;
1068 : :
1069 : : dpaa2_q = rx_queue;
1070 : :
1071 [ # # ]: 0 : if (qbman_fq_query_state(swp, dpaa2_q->fqid, &state) == 0) {
1072 : 0 : frame_cnt = qbman_fq_state_frame_count(&state);
1073 : : DPAA2_PMD_DP_DEBUG("RX frame count for q(%p) is %u",
1074 : : rx_queue, frame_cnt);
1075 : : }
1076 : : return frame_cnt;
1077 : : }
1078 : :
1079 : : static const uint32_t *
1080 : 0 : dpaa2_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
1081 : : {
1082 : : static const uint32_t ptypes[] = {
1083 : : /*todo -= add more types */
1084 : : RTE_PTYPE_L2_ETHER,
1085 : : RTE_PTYPE_L3_IPV4,
1086 : : RTE_PTYPE_L3_IPV4_EXT,
1087 : : RTE_PTYPE_L3_IPV6,
1088 : : RTE_PTYPE_L3_IPV6_EXT,
1089 : : RTE_PTYPE_L4_TCP,
1090 : : RTE_PTYPE_L4_UDP,
1091 : : RTE_PTYPE_L4_SCTP,
1092 : : RTE_PTYPE_L4_ICMP,
1093 : : };
1094 : :
1095 [ # # # # ]: 0 : if (dev->rx_pkt_burst == dpaa2_dev_prefetch_rx ||
1096 [ # # ]: 0 : dev->rx_pkt_burst == dpaa2_dev_rx ||
1097 : : dev->rx_pkt_burst == dpaa2_dev_loopback_rx) {
1098 : 0 : *no_of_elements = RTE_DIM(ptypes);
1099 : 0 : return ptypes;
1100 : : }
1101 : : return NULL;
1102 : : }
1103 : :
1104 : : /**
1105 : : * Dpaa2 link Interrupt handler
1106 : : *
1107 : : * @param param
1108 : : * The address of parameter (struct rte_eth_dev *) registered before.
1109 : : *
1110 : : * @return
1111 : : * void
1112 : : */
1113 : : static void
1114 : 0 : dpaa2_interrupt_handler(void *param)
1115 : : {
1116 : : struct rte_eth_dev *dev = param;
1117 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
1118 : 0 : struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1119 : : int ret;
1120 : : int irq_index = DPNI_IRQ_INDEX;
1121 : 0 : unsigned int status = 0, clear = 0;
1122 : :
1123 : 0 : PMD_INIT_FUNC_TRACE();
1124 : :
1125 [ # # ]: 0 : if (dpni == NULL) {
1126 : 0 : DPAA2_PMD_ERR("dpni is NULL");
1127 : 0 : return;
1128 : : }
1129 : :
1130 : 0 : ret = dpni_get_irq_status(dpni, CMD_PRI_LOW, priv->token,
1131 : : irq_index, &status);
1132 [ # # ]: 0 : if (unlikely(ret)) {
1133 : 0 : DPAA2_PMD_ERR("Can't get irq status (err %d)", ret);
1134 : : clear = 0xffffffff;
1135 : 0 : goto out;
1136 : : }
1137 : :
1138 [ # # ]: 0 : if (status & DPNI_IRQ_EVENT_LINK_CHANGED) {
1139 : : clear = DPNI_IRQ_EVENT_LINK_CHANGED;
1140 : 0 : dpaa2_dev_link_update(dev, 0);
1141 : : /* calling all the apps registered for link status event */
1142 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
1143 : : }
1144 : 0 : out:
1145 : 0 : ret = dpni_clear_irq_status(dpni, CMD_PRI_LOW, priv->token,
1146 : : irq_index, clear);
1147 [ # # ]: 0 : if (unlikely(ret))
1148 : 0 : DPAA2_PMD_ERR("Can't clear irq status (err %d)", ret);
1149 : : }
1150 : :
1151 : : static int
1152 : 0 : dpaa2_eth_setup_irqs(struct rte_eth_dev *dev, int enable)
1153 : : {
1154 : : int err = 0;
1155 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
1156 : 0 : struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1157 : : int irq_index = DPNI_IRQ_INDEX;
1158 : : unsigned int mask = DPNI_IRQ_EVENT_LINK_CHANGED;
1159 : :
1160 : 0 : PMD_INIT_FUNC_TRACE();
1161 : :
1162 : 0 : err = dpni_set_irq_mask(dpni, CMD_PRI_LOW, priv->token,
1163 : : irq_index, mask);
1164 [ # # ]: 0 : if (err < 0) {
1165 : 0 : DPAA2_PMD_ERR("Error: dpni_set_irq_mask():%d (%s)", err,
1166 : : strerror(-err));
1167 : 0 : return err;
1168 : : }
1169 : :
1170 : 0 : err = dpni_set_irq_enable(dpni, CMD_PRI_LOW, priv->token,
1171 : : irq_index, enable);
1172 [ # # ]: 0 : if (err < 0)
1173 : 0 : DPAA2_PMD_ERR("Error: dpni_set_irq_enable():%d (%s)", err,
1174 : : strerror(-err));
1175 : :
1176 : : return err;
1177 : : }
1178 : :
1179 : : static int
1180 : 0 : dpaa2_dev_start(struct rte_eth_dev *dev)
1181 : : {
1182 : 0 : struct rte_device *rdev = dev->device;
1183 : : struct rte_dpaa2_device *dpaa2_dev;
1184 : 0 : struct rte_eth_dev_data *data = dev->data;
1185 : 0 : struct dpaa2_dev_priv *priv = data->dev_private;
1186 : 0 : struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1187 : : struct dpni_queue cfg;
1188 : : struct dpni_error_cfg err_cfg;
1189 : : struct dpni_queue_id qid;
1190 : : struct dpaa2_queue *dpaa2_q;
1191 : : int ret, i;
1192 : : struct rte_intr_handle *intr_handle;
1193 : :
1194 : 0 : dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
1195 : 0 : intr_handle = dpaa2_dev->intr_handle;
1196 : :
1197 : 0 : PMD_INIT_FUNC_TRACE();
1198 : 0 : ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
1199 [ # # ]: 0 : if (ret) {
1200 : 0 : DPAA2_PMD_ERR("Failure in enabling dpni %d device: err=%d",
1201 : : priv->hw_id, ret);
1202 : 0 : return ret;
1203 : : }
1204 : :
1205 : : /* Power up the phy. Needed to make the link go UP */
1206 : 0 : dpaa2_dev_set_link_up(dev);
1207 : :
1208 [ # # ]: 0 : for (i = 0; i < data->nb_rx_queues; i++) {
1209 : 0 : dpaa2_q = data->rx_queues[i];
1210 : 0 : ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
1211 : 0 : DPNI_QUEUE_RX, dpaa2_q->tc_index,
1212 : 0 : dpaa2_q->flow_id, &cfg, &qid);
1213 [ # # ]: 0 : if (ret) {
1214 : 0 : DPAA2_PMD_ERR("Error in getting flow information: "
1215 : : "err=%d", ret);
1216 : 0 : return ret;
1217 : : }
1218 : 0 : dpaa2_q->fqid = qid.fqid;
1219 : : }
1220 : :
1221 [ # # ]: 0 : if (dpaa2_enable_err_queue) {
1222 : 0 : ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
1223 : : DPNI_QUEUE_RX_ERR, 0, 0, &cfg, &qid);
1224 [ # # ]: 0 : if (ret) {
1225 : 0 : DPAA2_PMD_ERR("Error getting rx err flow information: err=%d",
1226 : : ret);
1227 : 0 : return ret;
1228 : : }
1229 : 0 : dpaa2_q = priv->rx_err_vq;
1230 : 0 : dpaa2_q->fqid = qid.fqid;
1231 : 0 : dpaa2_q->eth_data = dev->data;
1232 : :
1233 : 0 : err_cfg.errors = DPNI_ERROR_DISC;
1234 : 0 : err_cfg.error_action = DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE;
1235 : : } else {
1236 : : /* checksum errors, send them to normal path
1237 : : * and set it in annotation
1238 : : */
1239 : : err_cfg.errors = DPNI_ERROR_L3CE | DPNI_ERROR_L4CE;
1240 : :
1241 : : /* if packet with parse error are not to be dropped */
1242 : 0 : err_cfg.errors |= DPNI_ERROR_PHE;
1243 : :
1244 : 0 : err_cfg.error_action = DPNI_ERROR_ACTION_CONTINUE;
1245 : : }
1246 : 0 : err_cfg.set_frame_annotation = true;
1247 : :
1248 : 0 : ret = dpni_set_errors_behavior(dpni, CMD_PRI_LOW,
1249 : 0 : priv->token, &err_cfg);
1250 [ # # ]: 0 : if (ret) {
1251 : 0 : DPAA2_PMD_ERR("Error to dpni_set_errors_behavior: code = %d",
1252 : : ret);
1253 : 0 : return ret;
1254 : : }
1255 : :
1256 : : /* if the interrupts were configured on this devices*/
1257 [ # # # # ]: 0 : if (intr_handle && rte_intr_fd_get(intr_handle) &&
1258 [ # # ]: 0 : dev->data->dev_conf.intr_conf.lsc != 0) {
1259 : : /* Registering LSC interrupt handler */
1260 : 0 : rte_intr_callback_register(intr_handle,
1261 : : dpaa2_interrupt_handler,
1262 : : (void *)dev);
1263 : :
1264 : : /* enable vfio intr/eventfd mapping
1265 : : * Interrupt index 0 is required, so we can not use
1266 : : * rte_intr_enable.
1267 : : */
1268 : 0 : rte_dpaa2_intr_enable(intr_handle, DPNI_IRQ_INDEX);
1269 : :
1270 : : /* enable dpni_irqs */
1271 : 0 : dpaa2_eth_setup_irqs(dev, 1);
1272 : : }
1273 : :
1274 : : /* Change the tx burst function if ordered queues are used */
1275 [ # # ]: 0 : if (priv->en_ordered)
1276 : 0 : dev->tx_pkt_burst = dpaa2_dev_tx_ordered;
1277 : :
1278 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
1279 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
1280 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
1281 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
1282 : :
1283 : : return 0;
1284 : : }
1285 : :
1286 : : /**
1287 : : * This routine disables all traffic on the adapter by issuing a
1288 : : * global reset on the MAC.
1289 : : */
1290 : : static int
1291 : 0 : dpaa2_dev_stop(struct rte_eth_dev *dev)
1292 : : {
1293 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
1294 : 0 : struct fsl_mc_io *dpni = dev->process_private;
1295 : : int ret;
1296 : : struct rte_eth_link link;
1297 : 0 : struct rte_device *rdev = dev->device;
1298 : : struct rte_intr_handle *intr_handle;
1299 : : struct rte_dpaa2_device *dpaa2_dev;
1300 : : uint16_t i;
1301 : :
1302 : 0 : dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
1303 : 0 : intr_handle = dpaa2_dev->intr_handle;
1304 : :
1305 : 0 : PMD_INIT_FUNC_TRACE();
1306 : :
1307 : : /* reset interrupt callback */
1308 [ # # # # ]: 0 : if (intr_handle && rte_intr_fd_get(intr_handle) &&
1309 [ # # ]: 0 : dev->data->dev_conf.intr_conf.lsc != 0) {
1310 : : /*disable dpni irqs */
1311 : 0 : dpaa2_eth_setup_irqs(dev, 0);
1312 : :
1313 : : /* disable vfio intr before callback unregister */
1314 : 0 : rte_dpaa2_intr_disable(intr_handle, DPNI_IRQ_INDEX);
1315 : :
1316 : : /* Unregistering LSC interrupt handler */
1317 : 0 : rte_intr_callback_unregister(intr_handle,
1318 : : dpaa2_interrupt_handler,
1319 : : (void *)dev);
1320 : : }
1321 : :
1322 : 0 : dpaa2_dev_set_link_down(dev);
1323 : :
1324 : 0 : ret = dpni_disable(dpni, CMD_PRI_LOW, priv->token);
1325 [ # # ]: 0 : if (ret) {
1326 : 0 : DPAA2_PMD_ERR("Failure (ret %d) in disabling dpni %d dev",
1327 : : ret, priv->hw_id);
1328 : 0 : return ret;
1329 : : }
1330 : :
1331 : : /* clear the recorded link status */
1332 : : memset(&link, 0, sizeof(link));
1333 : 0 : rte_eth_linkstatus_set(dev, &link);
1334 : :
1335 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
1336 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1337 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
1338 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1339 : :
1340 : : return 0;
1341 : : }
1342 : :
1343 : : static int
1344 : 0 : dpaa2_dev_close(struct rte_eth_dev *dev)
1345 : : {
1346 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
1347 : 0 : struct fsl_mc_io *dpni = dev->process_private;
1348 : : int i, ret;
1349 : : struct rte_eth_link link;
1350 : :
1351 : 0 : PMD_INIT_FUNC_TRACE();
1352 : :
1353 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1354 : : return 0;
1355 : :
1356 [ # # ]: 0 : if (!dpni) {
1357 : 0 : DPAA2_PMD_WARN("Already closed or not started");
1358 : 0 : return -EINVAL;
1359 : : }
1360 : :
1361 : 0 : dpaa2_tm_deinit(dev);
1362 : 0 : dpaa2_flow_clean(dev);
1363 : : /* Clean the device first */
1364 : 0 : ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
1365 [ # # ]: 0 : if (ret) {
1366 : 0 : DPAA2_PMD_ERR("Failure cleaning dpni device: err=%d", ret);
1367 : 0 : return ret;
1368 : : }
1369 : :
1370 : : memset(&link, 0, sizeof(link));
1371 : 0 : rte_eth_linkstatus_set(dev, &link);
1372 : :
1373 : : /* Free private queues memory */
1374 : 0 : dpaa2_free_rx_tx_queues(dev);
1375 : : /* Close the device at underlying layer*/
1376 : 0 : ret = dpni_close(dpni, CMD_PRI_LOW, priv->token);
1377 [ # # ]: 0 : if (ret) {
1378 : 0 : DPAA2_PMD_ERR("Failure closing dpni device with err code %d",
1379 : : ret);
1380 : : }
1381 : :
1382 : : /* Free the allocated memory for ethernet private data and dpni*/
1383 : 0 : priv->hw = NULL;
1384 : 0 : dev->process_private = NULL;
1385 : 0 : rte_free(dpni);
1386 : :
1387 [ # # ]: 0 : for (i = 0; i < MAX_TCS; i++)
1388 : 0 : rte_free(priv->extract.tc_extract_param[i]);
1389 : :
1390 : 0 : rte_free(priv->extract.qos_extract_param);
1391 : :
1392 : 0 : DPAA2_PMD_INFO("%s: netdev deleted", dev->data->name);
1393 : 0 : return 0;
1394 : : }
1395 : :
1396 : : static int
1397 : 0 : dpaa2_dev_promiscuous_enable(struct rte_eth_dev *dev)
1398 : : {
1399 : : int ret;
1400 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
1401 : 0 : struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1402 : :
1403 : 0 : PMD_INIT_FUNC_TRACE();
1404 : :
1405 [ # # ]: 0 : if (dpni == NULL) {
1406 : 0 : DPAA2_PMD_ERR("dpni is NULL");
1407 : 0 : return -ENODEV;
1408 : : }
1409 : :
1410 : 0 : ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1411 [ # # ]: 0 : if (ret < 0)
1412 : 0 : DPAA2_PMD_ERR("Unable to enable U promisc mode %d", ret);
1413 : :
1414 : 0 : ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1415 [ # # ]: 0 : if (ret < 0)
1416 : 0 : DPAA2_PMD_ERR("Unable to enable M promisc mode %d", ret);
1417 : :
1418 : : return ret;
1419 : : }
1420 : :
1421 : : static int
1422 : 0 : dpaa2_dev_promiscuous_disable(
1423 : : struct rte_eth_dev *dev)
1424 : : {
1425 : : int ret;
1426 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
1427 : 0 : struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1428 : :
1429 : 0 : PMD_INIT_FUNC_TRACE();
1430 : :
1431 [ # # ]: 0 : if (dpni == NULL) {
1432 : 0 : DPAA2_PMD_ERR("dpni is NULL");
1433 : 0 : return -ENODEV;
1434 : : }
1435 : :
1436 : 0 : ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
1437 [ # # ]: 0 : if (ret < 0)
1438 : 0 : DPAA2_PMD_ERR("Unable to disable U promisc mode %d", ret);
1439 : :
1440 [ # # ]: 0 : if (dev->data->all_multicast == 0) {
1441 : 0 : ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW,
1442 : 0 : priv->token, false);
1443 [ # # ]: 0 : if (ret < 0)
1444 : 0 : DPAA2_PMD_ERR("Unable to disable M promisc mode %d",
1445 : : ret);
1446 : : }
1447 : :
1448 : : return ret;
1449 : : }
1450 : :
1451 : : static int
1452 : 0 : dpaa2_dev_allmulticast_enable(
1453 : : struct rte_eth_dev *dev)
1454 : : {
1455 : : int ret;
1456 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
1457 : 0 : struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1458 : :
1459 : 0 : PMD_INIT_FUNC_TRACE();
1460 : :
1461 [ # # ]: 0 : if (dpni == NULL) {
1462 : 0 : DPAA2_PMD_ERR("dpni is NULL");
1463 : 0 : return -ENODEV;
1464 : : }
1465 : :
1466 : 0 : ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1467 [ # # ]: 0 : if (ret < 0)
1468 : 0 : DPAA2_PMD_ERR("Unable to enable multicast mode %d", ret);
1469 : :
1470 : : return ret;
1471 : : }
1472 : :
1473 : : static int
1474 : 0 : dpaa2_dev_allmulticast_disable(struct rte_eth_dev *dev)
1475 : : {
1476 : : int ret;
1477 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
1478 : 0 : struct fsl_mc_io *dpni = dev->process_private;
1479 : :
1480 : 0 : PMD_INIT_FUNC_TRACE();
1481 : :
1482 [ # # ]: 0 : if (dpni == NULL) {
1483 : 0 : DPAA2_PMD_ERR("dpni is NULL");
1484 : 0 : return -ENODEV;
1485 : : }
1486 : :
1487 : : /* must remain on for all promiscuous */
1488 [ # # ]: 0 : if (dev->data->promiscuous == 1)
1489 : : return 0;
1490 : :
1491 : 0 : ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
1492 [ # # ]: 0 : if (ret < 0)
1493 : 0 : DPAA2_PMD_ERR("Unable to disable multicast mode %d", ret);
1494 : :
1495 : : return ret;
1496 : : }
1497 : :
1498 : : static int
1499 : 0 : dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1500 : : {
1501 : : int ret;
1502 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
1503 : 0 : struct fsl_mc_io *dpni = dev->process_private;
1504 : : uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN
1505 : 0 : + VLAN_TAG_SIZE;
1506 : :
1507 : 0 : PMD_INIT_FUNC_TRACE();
1508 : :
1509 [ # # ]: 0 : if (!dpni) {
1510 : 0 : DPAA2_PMD_ERR("dpni is NULL");
1511 : 0 : return -EINVAL;
1512 : : }
1513 : :
1514 : : /* Set the Max Rx frame length as 'mtu' +
1515 : : * Maximum Ethernet header length
1516 : : */
1517 : 0 : ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
1518 : 0 : frame_size - RTE_ETHER_CRC_LEN);
1519 [ # # ]: 0 : if (ret) {
1520 : 0 : DPAA2_PMD_ERR("Setting the max frame length failed");
1521 : 0 : return ret;
1522 : : }
1523 : 0 : dev->data->mtu = mtu;
1524 : 0 : DPAA2_PMD_INFO("MTU configured for the device: %d", mtu);
1525 : 0 : return 0;
1526 : : }
1527 : :
1528 : : static int
1529 : 0 : dpaa2_dev_add_mac_addr(struct rte_eth_dev *dev,
1530 : : struct rte_ether_addr *addr,
1531 : : __rte_unused uint32_t index,
1532 : : __rte_unused uint32_t pool)
1533 : : {
1534 : : int ret;
1535 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
1536 : 0 : struct fsl_mc_io *dpni = dev->process_private;
1537 : :
1538 : 0 : PMD_INIT_FUNC_TRACE();
1539 : :
1540 [ # # ]: 0 : if (dpni == NULL) {
1541 : 0 : DPAA2_PMD_ERR("dpni is NULL");
1542 : 0 : return -EINVAL;
1543 : : }
1544 : :
1545 : 0 : ret = dpni_add_mac_addr(dpni, CMD_PRI_LOW, priv->token,
1546 : 0 : addr->addr_bytes, 0, 0, 0);
1547 [ # # ]: 0 : if (ret)
1548 : 0 : DPAA2_PMD_ERR("ERR(%d) Adding the MAC ADDR failed", ret);
1549 : : return ret;
1550 : : }
1551 : :
1552 : : static void
1553 : 0 : dpaa2_dev_remove_mac_addr(struct rte_eth_dev *dev,
1554 : : uint32_t index)
1555 : : {
1556 : : int ret;
1557 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
1558 : 0 : struct fsl_mc_io *dpni = dev->process_private;
1559 : : struct rte_eth_dev_data *data = dev->data;
1560 : : struct rte_ether_addr *macaddr;
1561 : :
1562 : 0 : PMD_INIT_FUNC_TRACE();
1563 : :
1564 : 0 : macaddr = &data->mac_addrs[index];
1565 : :
1566 [ # # ]: 0 : if (!dpni) {
1567 : 0 : DPAA2_PMD_ERR("dpni is NULL");
1568 : 0 : return;
1569 : : }
1570 : :
1571 : 0 : ret = dpni_remove_mac_addr(dpni, CMD_PRI_LOW,
1572 : 0 : priv->token, macaddr->addr_bytes);
1573 [ # # ]: 0 : if (ret)
1574 : 0 : DPAA2_PMD_ERR(
1575 : : "error: Removing the MAC ADDR failed: err = %d", ret);
1576 : : }
1577 : :
1578 : : static int
1579 : 0 : dpaa2_dev_set_mac_addr(struct rte_eth_dev *dev,
1580 : : struct rte_ether_addr *addr)
1581 : : {
1582 : : int ret;
1583 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
1584 : 0 : struct fsl_mc_io *dpni = dev->process_private;
1585 : :
1586 : 0 : PMD_INIT_FUNC_TRACE();
1587 : :
1588 [ # # ]: 0 : if (!dpni) {
1589 : 0 : DPAA2_PMD_ERR("dpni is NULL");
1590 : 0 : return -EINVAL;
1591 : : }
1592 : :
1593 : 0 : ret = dpni_set_primary_mac_addr(dpni, CMD_PRI_LOW,
1594 : 0 : priv->token, addr->addr_bytes);
1595 : :
1596 [ # # ]: 0 : if (ret)
1597 : 0 : DPAA2_PMD_ERR("ERR(%d) Setting the MAC ADDR failed", ret);
1598 : :
1599 : : return ret;
1600 : : }
1601 : :
1602 : : static int
1603 : 0 : dpaa2_dev_stats_get(struct rte_eth_dev *dev,
1604 : : struct rte_eth_stats *stats)
1605 : : {
1606 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
1607 : 0 : struct fsl_mc_io *dpni = dev->process_private;
1608 : : int32_t retcode;
1609 : : uint8_t page0 = 0, page1 = 1, page2 = 2;
1610 : : union dpni_statistics value;
1611 : : int i;
1612 : : struct dpaa2_queue *dpaa2_rxq, *dpaa2_txq;
1613 : :
1614 : : memset(&value, 0, sizeof(union dpni_statistics));
1615 : :
1616 : 0 : PMD_INIT_FUNC_TRACE();
1617 : :
1618 [ # # ]: 0 : if (!dpni) {
1619 : 0 : DPAA2_PMD_ERR("dpni is NULL");
1620 : 0 : return -EINVAL;
1621 : : }
1622 : :
1623 [ # # ]: 0 : if (!stats) {
1624 : 0 : DPAA2_PMD_ERR("stats is NULL");
1625 : 0 : return -EINVAL;
1626 : : }
1627 : :
1628 : : /*Get Counters from page_0*/
1629 : 0 : retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1630 : : page0, 0, &value);
1631 [ # # ]: 0 : if (retcode)
1632 : 0 : goto err;
1633 : :
1634 : 0 : stats->ipackets = value.page_0.ingress_all_frames;
1635 : 0 : stats->ibytes = value.page_0.ingress_all_bytes;
1636 : :
1637 : : /*Get Counters from page_1*/
1638 : 0 : retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1639 : : page1, 0, &value);
1640 [ # # ]: 0 : if (retcode)
1641 : 0 : goto err;
1642 : :
1643 : 0 : stats->opackets = value.page_1.egress_all_frames;
1644 : 0 : stats->obytes = value.page_1.egress_all_bytes;
1645 : :
1646 : : /*Get Counters from page_2*/
1647 : 0 : retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1648 : : page2, 0, &value);
1649 [ # # ]: 0 : if (retcode)
1650 : 0 : goto err;
1651 : :
1652 : : /* Ingress drop frame count due to configured rules */
1653 : 0 : stats->ierrors = value.page_2.ingress_filtered_frames;
1654 : : /* Ingress drop frame count due to error */
1655 : 0 : stats->ierrors += value.page_2.ingress_discarded_frames;
1656 : :
1657 : 0 : stats->oerrors = value.page_2.egress_discarded_frames;
1658 : 0 : stats->imissed = value.page_2.ingress_nobuffer_discards;
1659 : :
1660 : : /* Fill in per queue stats */
1661 [ # # ]: 0 : for (i = 0; (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) &&
1662 [ # # # # ]: 0 : (i < priv->nb_rx_queues || i < priv->nb_tx_queues); ++i) {
1663 : 0 : dpaa2_rxq = priv->rx_vq[i];
1664 : 0 : dpaa2_txq = priv->tx_vq[i];
1665 [ # # ]: 0 : if (dpaa2_rxq)
1666 : 0 : stats->q_ipackets[i] = dpaa2_rxq->rx_pkts;
1667 [ # # ]: 0 : if (dpaa2_txq)
1668 : 0 : stats->q_opackets[i] = dpaa2_txq->tx_pkts;
1669 : :
1670 : : /* Byte counting is not implemented */
1671 : 0 : stats->q_ibytes[i] = 0;
1672 : 0 : stats->q_obytes[i] = 0;
1673 : : }
1674 : :
1675 : : return 0;
1676 : :
1677 : 0 : err:
1678 : 0 : DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
1679 : 0 : return retcode;
1680 : : };
1681 : :
1682 : : static int
1683 : 0 : dpaa2_dev_xstats_get(struct rte_eth_dev *dev,
1684 : : struct rte_eth_xstat *xstats, unsigned int n)
1685 : : {
1686 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
1687 : 0 : struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1688 : : int32_t retcode;
1689 : 0 : union dpni_statistics value[5] = {};
1690 : : unsigned int i = 0, num = RTE_DIM(dpaa2_xstats_strings);
1691 : : uint8_t page_id, stats_id;
1692 : :
1693 [ # # ]: 0 : if (n < num)
1694 : : return num;
1695 : :
1696 [ # # ]: 0 : if (!xstats)
1697 : : return 0;
1698 : :
1699 : : /* Get Counters from page_0*/
1700 : 0 : retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1701 : : 0, 0, &value[0]);
1702 [ # # ]: 0 : if (retcode)
1703 : 0 : goto err;
1704 : :
1705 : : /* Get Counters from page_1*/
1706 : 0 : retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1707 : : 1, 0, &value[1]);
1708 [ # # ]: 0 : if (retcode)
1709 : 0 : goto err;
1710 : :
1711 : : /* Get Counters from page_2*/
1712 : 0 : retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1713 : : 2, 0, &value[2]);
1714 [ # # ]: 0 : if (retcode)
1715 : 0 : goto err;
1716 : :
1717 [ # # ]: 0 : for (i = 0; i < priv->max_cgs; i++) {
1718 [ # # ]: 0 : if (!priv->cgid_in_use[i]) {
1719 : : /* Get Counters from page_4*/
1720 : 0 : retcode = dpni_get_statistics(dpni, CMD_PRI_LOW,
1721 : 0 : priv->token,
1722 : : 4, 0, &value[4]);
1723 [ # # ]: 0 : if (retcode)
1724 : 0 : goto err;
1725 : : break;
1726 : : }
1727 : : }
1728 : :
1729 [ # # ]: 0 : for (i = 0; i < num; i++) {
1730 : 0 : xstats[i].id = i;
1731 : 0 : page_id = dpaa2_xstats_strings[i].page_id;
1732 : 0 : stats_id = dpaa2_xstats_strings[i].stats_id;
1733 : 0 : xstats[i].value = value[page_id].raw.counter[stats_id];
1734 : : }
1735 : : return i;
1736 : 0 : err:
1737 : 0 : DPAA2_PMD_ERR("Error in obtaining extended stats (%d)", retcode);
1738 : 0 : return retcode;
1739 : : }
1740 : :
1741 : : static int
1742 : 0 : dpaa2_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1743 : : struct rte_eth_xstat_name *xstats_names,
1744 : : unsigned int limit)
1745 : : {
1746 : : unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1747 : :
1748 [ # # ]: 0 : if (limit < stat_cnt)
1749 : : return stat_cnt;
1750 : :
1751 [ # # ]: 0 : if (xstats_names != NULL)
1752 [ # # ]: 0 : for (i = 0; i < stat_cnt; i++)
1753 : 0 : strlcpy(xstats_names[i].name,
1754 : : dpaa2_xstats_strings[i].name,
1755 : : sizeof(xstats_names[i].name));
1756 : :
1757 : : return stat_cnt;
1758 : : }
1759 : :
1760 : : static int
1761 : 0 : dpaa2_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1762 : : uint64_t *values, unsigned int n)
1763 : 0 : {
1764 : : unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1765 : 0 : uint64_t values_copy[stat_cnt];
1766 : : uint8_t page_id, stats_id;
1767 : :
1768 [ # # ]: 0 : if (!ids) {
1769 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
1770 : 0 : struct fsl_mc_io *dpni = dev->process_private;
1771 : : int32_t retcode;
1772 : 0 : union dpni_statistics value[5] = {};
1773 : :
1774 [ # # ]: 0 : if (n < stat_cnt)
1775 : : return stat_cnt;
1776 : :
1777 [ # # ]: 0 : if (!values)
1778 : : return 0;
1779 : :
1780 : : /* Get Counters from page_0*/
1781 : 0 : retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1782 : : 0, 0, &value[0]);
1783 [ # # ]: 0 : if (retcode)
1784 : : return 0;
1785 : :
1786 : : /* Get Counters from page_1*/
1787 : 0 : retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1788 : : 1, 0, &value[1]);
1789 [ # # ]: 0 : if (retcode)
1790 : : return 0;
1791 : :
1792 : : /* Get Counters from page_2*/
1793 : 0 : retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1794 : : 2, 0, &value[2]);
1795 [ # # ]: 0 : if (retcode)
1796 : : return 0;
1797 : :
1798 : : /* Get Counters from page_4*/
1799 : 0 : retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1800 : : 4, 0, &value[4]);
1801 [ # # ]: 0 : if (retcode)
1802 : : return 0;
1803 : :
1804 [ # # ]: 0 : for (i = 0; i < stat_cnt; i++) {
1805 : 0 : page_id = dpaa2_xstats_strings[i].page_id;
1806 : 0 : stats_id = dpaa2_xstats_strings[i].stats_id;
1807 : 0 : values[i] = value[page_id].raw.counter[stats_id];
1808 : : }
1809 : : return stat_cnt;
1810 : : }
1811 : :
1812 : 0 : dpaa2_xstats_get_by_id(dev, NULL, values_copy, stat_cnt);
1813 : :
1814 [ # # ]: 0 : for (i = 0; i < n; i++) {
1815 [ # # ]: 0 : if (ids[i] >= stat_cnt) {
1816 : 0 : DPAA2_PMD_ERR("xstats id value isn't valid");
1817 : 0 : return -EINVAL;
1818 : : }
1819 : 0 : values[i] = values_copy[ids[i]];
1820 : : }
1821 : 0 : return n;
1822 : : }
1823 : :
1824 : : static int
1825 : 0 : dpaa2_xstats_get_names_by_id(struct rte_eth_dev *dev,
1826 : : const uint64_t *ids,
1827 : : struct rte_eth_xstat_name *xstats_names,
1828 : : unsigned int limit)
1829 : 0 : {
1830 : : unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1831 : 0 : struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
1832 : :
1833 [ # # ]: 0 : if (!ids)
1834 : 0 : return dpaa2_xstats_get_names(dev, xstats_names, limit);
1835 : :
1836 : 0 : dpaa2_xstats_get_names(dev, xstats_names_copy, limit);
1837 : :
1838 [ # # ]: 0 : for (i = 0; i < limit; i++) {
1839 [ # # ]: 0 : if (ids[i] >= stat_cnt) {
1840 : 0 : DPAA2_PMD_ERR("xstats id value isn't valid");
1841 : 0 : return -1;
1842 : : }
1843 : 0 : strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
1844 : : }
1845 : 0 : return limit;
1846 : : }
1847 : :
1848 : : static int
1849 : 0 : dpaa2_dev_stats_reset(struct rte_eth_dev *dev)
1850 : : {
1851 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
1852 : 0 : struct fsl_mc_io *dpni = dev->process_private;
1853 : : int retcode;
1854 : : int i;
1855 : : struct dpaa2_queue *dpaa2_q;
1856 : :
1857 : 0 : PMD_INIT_FUNC_TRACE();
1858 : :
1859 [ # # ]: 0 : if (!dpni) {
1860 : 0 : DPAA2_PMD_ERR("dpni is NULL");
1861 : 0 : return -EINVAL;
1862 : : }
1863 : :
1864 : 0 : retcode = dpni_reset_statistics(dpni, CMD_PRI_LOW, priv->token);
1865 [ # # ]: 0 : if (retcode)
1866 : 0 : goto error;
1867 : :
1868 : : /* Reset the per queue stats in dpaa2_queue structure */
1869 [ # # ]: 0 : for (i = 0; i < priv->nb_rx_queues; i++) {
1870 : 0 : dpaa2_q = priv->rx_vq[i];
1871 [ # # ]: 0 : if (dpaa2_q)
1872 : 0 : dpaa2_q->rx_pkts = 0;
1873 : : }
1874 : :
1875 [ # # ]: 0 : for (i = 0; i < priv->nb_tx_queues; i++) {
1876 : 0 : dpaa2_q = priv->tx_vq[i];
1877 [ # # ]: 0 : if (dpaa2_q)
1878 : 0 : dpaa2_q->tx_pkts = 0;
1879 : : }
1880 : :
1881 : : return 0;
1882 : :
1883 : : error:
1884 : 0 : DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
1885 : 0 : return retcode;
1886 : : };
1887 : :
1888 : : /* return 0 means link status changed, -1 means not changed */
1889 : : static int
1890 : 0 : dpaa2_dev_link_update(struct rte_eth_dev *dev,
1891 : : int wait_to_complete)
1892 : : {
1893 : : int ret;
1894 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
1895 : 0 : struct fsl_mc_io *dpni = dev->process_private;
1896 : : struct rte_eth_link link;
1897 : 0 : struct dpni_link_state state = {0};
1898 : : uint8_t count;
1899 : :
1900 [ # # ]: 0 : if (!dpni) {
1901 : 0 : DPAA2_PMD_ERR("dpni is NULL");
1902 : 0 : return 0;
1903 : : }
1904 : :
1905 [ # # ]: 0 : for (count = 0; count <= MAX_REPEAT_TIME; count++) {
1906 : 0 : ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token,
1907 : : &state);
1908 [ # # ]: 0 : if (ret < 0) {
1909 : 0 : DPAA2_PMD_DEBUG("error: dpni_get_link_state %d", ret);
1910 : 0 : return ret;
1911 : : }
1912 [ # # # # ]: 0 : if (state.up == RTE_ETH_LINK_DOWN &&
1913 : : wait_to_complete)
1914 : : rte_delay_ms(CHECK_INTERVAL);
1915 : : else
1916 : : break;
1917 : : }
1918 : :
1919 : : memset(&link, 0, sizeof(struct rte_eth_link));
1920 : 0 : link.link_status = state.up;
1921 : 0 : link.link_speed = state.rate;
1922 : :
1923 [ # # ]: 0 : if (state.options & DPNI_LINK_OPT_HALF_DUPLEX)
1924 : : link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
1925 : : else
1926 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
1927 : :
1928 : : ret = rte_eth_linkstatus_set(dev, &link);
1929 : : if (ret < 0)
1930 : 0 : DPAA2_PMD_DEBUG("No change in status");
1931 : : else
1932 [ # # ]: 0 : DPAA2_PMD_INFO("Port %d Link is %s", dev->data->port_id,
1933 : : link.link_status ? "Up" : "Down");
1934 : :
1935 : : return ret;
1936 : : }
1937 : :
1938 : : /**
1939 : : * Toggle the DPNI to enable, if not already enabled.
1940 : : * This is not strictly PHY up/down - it is more of logical toggling.
1941 : : */
1942 : : static int
1943 : 0 : dpaa2_dev_set_link_up(struct rte_eth_dev *dev)
1944 : : {
1945 : : int ret = -EINVAL;
1946 : : struct dpaa2_dev_priv *priv;
1947 : : struct fsl_mc_io *dpni;
1948 : 0 : int en = 0;
1949 : 0 : struct dpni_link_state state = {0};
1950 : :
1951 : 0 : priv = dev->data->dev_private;
1952 : 0 : dpni = dev->process_private;
1953 : :
1954 [ # # ]: 0 : if (!dpni) {
1955 : 0 : DPAA2_PMD_ERR("dpni is NULL");
1956 : 0 : return ret;
1957 : : }
1958 : :
1959 : : /* Check if DPNI is currently enabled */
1960 : 0 : ret = dpni_is_enabled(dpni, CMD_PRI_LOW, priv->token, &en);
1961 [ # # ]: 0 : if (ret) {
1962 : : /* Unable to obtain dpni status; Not continuing */
1963 : 0 : DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
1964 : 0 : return ret;
1965 : : }
1966 : :
1967 : : /* Enable link if not already enabled */
1968 [ # # ]: 0 : if (!en) {
1969 : 0 : ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
1970 [ # # ]: 0 : if (ret) {
1971 : 0 : DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
1972 : 0 : return ret;
1973 : : }
1974 : : }
1975 : 0 : ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1976 [ # # ]: 0 : if (ret < 0) {
1977 : 0 : DPAA2_PMD_DEBUG("Unable to get link state (%d)", ret);
1978 : 0 : return ret;
1979 : : }
1980 : :
1981 : : /* changing tx burst function to start enqueues */
1982 : 0 : dev->tx_pkt_burst = dpaa2_dev_tx;
1983 : 0 : dev->data->dev_link.link_status = state.up;
1984 : 0 : dev->data->dev_link.link_speed = state.rate;
1985 : :
1986 [ # # ]: 0 : if (state.options & DPNI_LINK_OPT_HALF_DUPLEX)
1987 : 0 : dev->data->dev_link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
1988 : : else
1989 : 0 : dev->data->dev_link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
1990 : :
1991 [ # # ]: 0 : if (state.up)
1992 : 0 : DPAA2_PMD_DEBUG("Port %d Link is Up", dev->data->port_id);
1993 : : else
1994 : 0 : DPAA2_PMD_DEBUG("Port %d Link is Down", dev->data->port_id);
1995 : : return ret;
1996 : : }
1997 : :
1998 : : /**
1999 : : * Toggle the DPNI to disable, if not already disabled.
2000 : : * This is not strictly PHY up/down - it is more of logical toggling.
2001 : : */
2002 : : static int
2003 : 0 : dpaa2_dev_set_link_down(struct rte_eth_dev *dev)
2004 : : {
2005 : : int ret = -EINVAL;
2006 : : struct dpaa2_dev_priv *priv;
2007 : : struct fsl_mc_io *dpni;
2008 : 0 : int dpni_enabled = 0;
2009 : : int retries = 10;
2010 : :
2011 : 0 : PMD_INIT_FUNC_TRACE();
2012 : :
2013 : 0 : priv = dev->data->dev_private;
2014 : 0 : dpni = dev->process_private;
2015 : :
2016 [ # # ]: 0 : if (!dpni) {
2017 : 0 : DPAA2_PMD_ERR("Device has not yet been configured");
2018 : 0 : return ret;
2019 : : }
2020 : :
2021 : : /*changing tx burst function to avoid any more enqueues */
2022 : 0 : dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
2023 : :
2024 : : /* Loop while dpni_disable() attempts to drain the egress FQs
2025 : : * and confirm them back to us.
2026 : : */
2027 : : do {
2028 : 0 : ret = dpni_disable(dpni, 0, priv->token);
2029 [ # # ]: 0 : if (ret) {
2030 : 0 : DPAA2_PMD_ERR("dpni disable failed (%d)", ret);
2031 : 0 : return ret;
2032 : : }
2033 : 0 : ret = dpni_is_enabled(dpni, 0, priv->token, &dpni_enabled);
2034 [ # # ]: 0 : if (ret) {
2035 : 0 : DPAA2_PMD_ERR("dpni enable check failed (%d)", ret);
2036 : 0 : return ret;
2037 : : }
2038 [ # # ]: 0 : if (dpni_enabled)
2039 : : /* Allow the MC some slack */
2040 : 0 : rte_delay_us(100 * 1000);
2041 [ # # # # ]: 0 : } while (dpni_enabled && --retries);
2042 : :
2043 [ # # ]: 0 : if (!retries) {
2044 : 0 : DPAA2_PMD_WARN("Retry count exceeded disabling dpni");
2045 : : /* todo- we may have to manually cleanup queues.
2046 : : */
2047 : : } else {
2048 : 0 : DPAA2_PMD_INFO("Port %d Link DOWN successful",
2049 : : dev->data->port_id);
2050 : : }
2051 : :
2052 : 0 : dev->data->dev_link.link_status = 0;
2053 : :
2054 : 0 : return ret;
2055 : : }
2056 : :
2057 : : static int
2058 : 0 : dpaa2_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2059 : : {
2060 : : int ret = -EINVAL;
2061 : : struct dpaa2_dev_priv *priv;
2062 : : struct fsl_mc_io *dpni;
2063 : 0 : struct dpni_link_cfg cfg = {0};
2064 : :
2065 : 0 : PMD_INIT_FUNC_TRACE();
2066 : :
2067 : 0 : priv = dev->data->dev_private;
2068 : 0 : dpni = dev->process_private;
2069 : :
2070 [ # # ]: 0 : if (!dpni || !fc_conf) {
2071 : 0 : DPAA2_PMD_ERR("device not configured");
2072 : 0 : return ret;
2073 : : }
2074 : :
2075 : 0 : ret = dpni_get_link_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
2076 [ # # ]: 0 : if (ret) {
2077 : 0 : DPAA2_PMD_ERR("error: dpni_get_link_cfg %d", ret);
2078 : 0 : return ret;
2079 : : }
2080 : :
2081 : : memset(fc_conf, 0, sizeof(struct rte_eth_fc_conf));
2082 [ # # ]: 0 : if (cfg.options & DPNI_LINK_OPT_PAUSE) {
2083 : : /* DPNI_LINK_OPT_PAUSE set
2084 : : * if ASYM_PAUSE not set,
2085 : : * RX Side flow control (handle received Pause frame)
2086 : : * TX side flow control (send Pause frame)
2087 : : * if ASYM_PAUSE set,
2088 : : * RX Side flow control (handle received Pause frame)
2089 : : * No TX side flow control (send Pause frame disabled)
2090 : : */
2091 [ # # ]: 0 : if (!(cfg.options & DPNI_LINK_OPT_ASYM_PAUSE))
2092 : 0 : fc_conf->mode = RTE_ETH_FC_FULL;
2093 : : else
2094 : 0 : fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
2095 : : } else {
2096 : : /* DPNI_LINK_OPT_PAUSE not set
2097 : : * if ASYM_PAUSE set,
2098 : : * TX side flow control (send Pause frame)
2099 : : * No RX side flow control (No action on pause frame rx)
2100 : : * if ASYM_PAUSE not set,
2101 : : * Flow control disabled
2102 : : */
2103 [ # # ]: 0 : if (cfg.options & DPNI_LINK_OPT_ASYM_PAUSE)
2104 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
2105 : : else
2106 : : fc_conf->mode = RTE_ETH_FC_NONE;
2107 : : }
2108 : :
2109 : : return ret;
2110 : : }
2111 : :
2112 : : static int
2113 : 0 : dpaa2_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2114 : : {
2115 : : int ret = -EINVAL;
2116 : : struct dpaa2_dev_priv *priv;
2117 : : struct fsl_mc_io *dpni;
2118 : 0 : struct dpni_link_cfg cfg = {0};
2119 : :
2120 : 0 : PMD_INIT_FUNC_TRACE();
2121 : :
2122 : 0 : priv = dev->data->dev_private;
2123 : 0 : dpni = dev->process_private;
2124 : :
2125 [ # # ]: 0 : if (!dpni) {
2126 : 0 : DPAA2_PMD_ERR("dpni is NULL");
2127 : 0 : return ret;
2128 : : }
2129 : :
2130 : : /* It is necessary to obtain the current cfg before setting fc_conf
2131 : : * as MC would return error in case rate, autoneg or duplex values are
2132 : : * different.
2133 : : */
2134 : 0 : ret = dpni_get_link_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
2135 [ # # ]: 0 : if (ret) {
2136 : 0 : DPAA2_PMD_ERR("Unable to get link cfg (err=%d)", ret);
2137 : 0 : return ret;
2138 : : }
2139 : :
2140 : : /* Disable link before setting configuration */
2141 : 0 : dpaa2_dev_set_link_down(dev);
2142 : :
2143 : : /* update cfg with fc_conf */
2144 [ # # # # : 0 : switch (fc_conf->mode) {
# ]
2145 : 0 : case RTE_ETH_FC_FULL:
2146 : : /* Full flow control;
2147 : : * OPT_PAUSE set, ASYM_PAUSE not set
2148 : : */
2149 : 0 : cfg.options |= DPNI_LINK_OPT_PAUSE;
2150 : 0 : cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
2151 : 0 : break;
2152 : 0 : case RTE_ETH_FC_TX_PAUSE:
2153 : : /* Enable RX flow control
2154 : : * OPT_PAUSE not set;
2155 : : * ASYM_PAUSE set;
2156 : : */
2157 : 0 : cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
2158 : 0 : cfg.options &= ~DPNI_LINK_OPT_PAUSE;
2159 : 0 : break;
2160 : 0 : case RTE_ETH_FC_RX_PAUSE:
2161 : : /* Enable TX Flow control
2162 : : * OPT_PAUSE set
2163 : : * ASYM_PAUSE set
2164 : : */
2165 : 0 : cfg.options |= DPNI_LINK_OPT_PAUSE;
2166 : 0 : cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
2167 : 0 : break;
2168 : 0 : case RTE_ETH_FC_NONE:
2169 : : /* Disable Flow control
2170 : : * OPT_PAUSE not set
2171 : : * ASYM_PAUSE not set
2172 : : */
2173 : 0 : cfg.options &= ~DPNI_LINK_OPT_PAUSE;
2174 : 0 : cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
2175 : 0 : break;
2176 : 0 : default:
2177 : 0 : DPAA2_PMD_ERR("Incorrect Flow control flag (%d)",
2178 : : fc_conf->mode);
2179 : 0 : return -EINVAL;
2180 : : }
2181 : :
2182 : 0 : ret = dpni_set_link_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
2183 [ # # ]: 0 : if (ret)
2184 : 0 : DPAA2_PMD_ERR("Unable to set Link configuration (err=%d)",
2185 : : ret);
2186 : :
2187 : : /* Enable link */
2188 : 0 : dpaa2_dev_set_link_up(dev);
2189 : :
2190 : 0 : return ret;
2191 : : }
2192 : :
2193 : : static int
2194 : 0 : dpaa2_dev_rss_hash_update(struct rte_eth_dev *dev,
2195 : : struct rte_eth_rss_conf *rss_conf)
2196 : : {
2197 : 0 : struct rte_eth_dev_data *data = dev->data;
2198 : 0 : struct dpaa2_dev_priv *priv = data->dev_private;
2199 : : struct rte_eth_conf *eth_conf = &data->dev_conf;
2200 : : int ret, tc_index;
2201 : :
2202 : 0 : PMD_INIT_FUNC_TRACE();
2203 : :
2204 [ # # ]: 0 : if (rss_conf->rss_hf) {
2205 [ # # ]: 0 : for (tc_index = 0; tc_index < priv->num_rx_tc; tc_index++) {
2206 : 0 : ret = dpaa2_setup_flow_dist(dev, rss_conf->rss_hf,
2207 : : tc_index);
2208 [ # # ]: 0 : if (ret) {
2209 : 0 : DPAA2_PMD_ERR("Unable to set flow dist on tc%d",
2210 : : tc_index);
2211 : 0 : return ret;
2212 : : }
2213 : : }
2214 : : } else {
2215 [ # # ]: 0 : for (tc_index = 0; tc_index < priv->num_rx_tc; tc_index++) {
2216 : 0 : ret = dpaa2_remove_flow_dist(dev, tc_index);
2217 [ # # ]: 0 : if (ret) {
2218 : 0 : DPAA2_PMD_ERR(
2219 : : "Unable to remove flow dist on tc%d",
2220 : : tc_index);
2221 : 0 : return ret;
2222 : : }
2223 : : }
2224 : : }
2225 : 0 : eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_conf->rss_hf;
2226 : 0 : return 0;
2227 : : }
2228 : :
2229 : : static int
2230 : 0 : dpaa2_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
2231 : : struct rte_eth_rss_conf *rss_conf)
2232 : : {
2233 : 0 : struct rte_eth_dev_data *data = dev->data;
2234 : : struct rte_eth_conf *eth_conf = &data->dev_conf;
2235 : :
2236 : : /* dpaa2 does not support rss_key, so length should be 0*/
2237 : 0 : rss_conf->rss_key_len = 0;
2238 : 0 : rss_conf->rss_hf = eth_conf->rx_adv_conf.rss_conf.rss_hf;
2239 : 0 : return 0;
2240 : : }
2241 : :
2242 : 0 : int dpaa2_eth_eventq_attach(const struct rte_eth_dev *dev,
2243 : : int eth_rx_queue_id,
2244 : : struct dpaa2_dpcon_dev *dpcon,
2245 : : const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
2246 : : {
2247 : 0 : struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
2248 : 0 : struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
2249 : 0 : struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
2250 : 0 : uint8_t flow_id = dpaa2_ethq->flow_id;
2251 : : struct dpni_queue cfg;
2252 : : uint8_t options, priority;
2253 : : int ret;
2254 : :
2255 [ # # ]: 0 : if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL)
2256 : 0 : dpaa2_ethq->cb = dpaa2_dev_process_parallel_event;
2257 [ # # ]: 0 : else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC)
2258 : 0 : dpaa2_ethq->cb = dpaa2_dev_process_atomic_event;
2259 [ # # ]: 0 : else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED)
2260 : 0 : dpaa2_ethq->cb = dpaa2_dev_process_ordered_event;
2261 : : else
2262 : : return -EINVAL;
2263 : :
2264 : 0 : priority = (RTE_EVENT_DEV_PRIORITY_LOWEST / queue_conf->ev.priority) *
2265 [ # # ]: 0 : (dpcon->num_priorities - 1);
2266 : :
2267 : : memset(&cfg, 0, sizeof(struct dpni_queue));
2268 : : options = DPNI_QUEUE_OPT_DEST;
2269 : 0 : cfg.destination.type = DPNI_DEST_DPCON;
2270 : 0 : cfg.destination.id = dpcon->dpcon_id;
2271 : 0 : cfg.destination.priority = priority;
2272 : :
2273 [ # # ]: 0 : if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC) {
2274 : : options |= DPNI_QUEUE_OPT_HOLD_ACTIVE;
2275 : 0 : cfg.destination.hold_active = 1;
2276 : : }
2277 : :
2278 [ # # ]: 0 : if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED &&
2279 [ # # ]: 0 : !eth_priv->en_ordered) {
2280 : : struct opr_cfg ocfg;
2281 : :
2282 : : /* Restoration window size = 256 frames */
2283 : 0 : ocfg.oprrws = 3;
2284 : : /* Restoration window size = 512 frames for LX2 */
2285 [ # # ]: 0 : if (dpaa2_svr_family == SVR_LX2160A)
2286 : 0 : ocfg.oprrws = 4;
2287 : : /* Auto advance NESN window enabled */
2288 : 0 : ocfg.oa = 1;
2289 : : /* Late arrival window size disabled */
2290 : 0 : ocfg.olws = 0;
2291 : : /* ORL resource exhaustion advance NESN disabled */
2292 : 0 : ocfg.oeane = 0;
2293 : : /* Loose ordering enabled */
2294 : 0 : ocfg.oloe = 1;
2295 : 0 : eth_priv->en_loose_ordered = 1;
2296 : : /* Strict ordering enabled if explicitly set */
2297 [ # # ]: 0 : if (getenv("DPAA2_STRICT_ORDERING_ENABLE")) {
2298 : 0 : ocfg.oloe = 0;
2299 : 0 : eth_priv->en_loose_ordered = 0;
2300 : : }
2301 : :
2302 : 0 : ret = dpni_set_opr(dpni, CMD_PRI_LOW, eth_priv->token,
2303 : 0 : dpaa2_ethq->tc_index, flow_id,
2304 : : OPR_OPT_CREATE, &ocfg, 0);
2305 [ # # ]: 0 : if (ret) {
2306 : 0 : DPAA2_PMD_ERR("Error setting opr: ret: %d", ret);
2307 : 0 : return ret;
2308 : : }
2309 : :
2310 : 0 : eth_priv->en_ordered = 1;
2311 : : }
2312 : :
2313 : 0 : options |= DPNI_QUEUE_OPT_USER_CTX;
2314 : 0 : cfg.user_context = (size_t)(dpaa2_ethq);
2315 : :
2316 : 0 : ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
2317 : 0 : dpaa2_ethq->tc_index, flow_id, options, &cfg);
2318 [ # # ]: 0 : if (ret) {
2319 : 0 : DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
2320 : 0 : return ret;
2321 : : }
2322 : :
2323 : 0 : memcpy(&dpaa2_ethq->ev, &queue_conf->ev, sizeof(struct rte_event));
2324 : :
2325 : 0 : return 0;
2326 : : }
2327 : :
2328 : 0 : int dpaa2_eth_eventq_detach(const struct rte_eth_dev *dev,
2329 : : int eth_rx_queue_id)
2330 : : {
2331 : 0 : struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
2332 : 0 : struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
2333 : 0 : struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
2334 : 0 : uint8_t flow_id = dpaa2_ethq->flow_id;
2335 : : struct dpni_queue cfg;
2336 : : uint8_t options;
2337 : : int ret;
2338 : :
2339 : : memset(&cfg, 0, sizeof(struct dpni_queue));
2340 : : options = DPNI_QUEUE_OPT_DEST;
2341 : : cfg.destination.type = DPNI_DEST_NONE;
2342 : :
2343 : 0 : ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
2344 : 0 : dpaa2_ethq->tc_index, flow_id, options, &cfg);
2345 [ # # ]: 0 : if (ret)
2346 : 0 : DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
2347 : :
2348 : 0 : return ret;
2349 : : }
2350 : :
2351 : : static int
2352 : 0 : dpaa2_dev_flow_ops_get(struct rte_eth_dev *dev,
2353 : : const struct rte_flow_ops **ops)
2354 : : {
2355 [ # # ]: 0 : if (!dev)
2356 : : return -ENODEV;
2357 : :
2358 : 0 : *ops = &dpaa2_flow_ops;
2359 : 0 : return 0;
2360 : : }
2361 : :
2362 : : static void
2363 : 0 : dpaa2_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
2364 : : struct rte_eth_rxq_info *qinfo)
2365 : : {
2366 : : struct dpaa2_queue *rxq;
2367 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
2368 : 0 : struct fsl_mc_io *dpni = dev->process_private;
2369 : : uint16_t max_frame_length;
2370 : :
2371 : 0 : rxq = dev->data->rx_queues[queue_id];
2372 : :
2373 : 0 : qinfo->mp = rxq->mb_pool;
2374 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
2375 : 0 : qinfo->nb_desc = rxq->nb_desc;
2376 [ # # ]: 0 : if (dpni_get_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
2377 : : &max_frame_length) == 0)
2378 : 0 : qinfo->rx_buf_size = max_frame_length;
2379 : :
2380 : 0 : qinfo->conf.rx_free_thresh = 1;
2381 : 0 : qinfo->conf.rx_drop_en = 1;
2382 : 0 : qinfo->conf.rx_deferred_start = 0;
2383 : 0 : qinfo->conf.offloads = rxq->offloads;
2384 : 0 : }
2385 : :
2386 : : static void
2387 : 0 : dpaa2_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
2388 : : struct rte_eth_txq_info *qinfo)
2389 : : {
2390 : : struct dpaa2_queue *txq;
2391 : :
2392 : 0 : txq = dev->data->tx_queues[queue_id];
2393 : :
2394 : 0 : qinfo->nb_desc = txq->nb_desc;
2395 : 0 : qinfo->conf.tx_thresh.pthresh = 0;
2396 : 0 : qinfo->conf.tx_thresh.hthresh = 0;
2397 : 0 : qinfo->conf.tx_thresh.wthresh = 0;
2398 : :
2399 : 0 : qinfo->conf.tx_free_thresh = 0;
2400 : 0 : qinfo->conf.tx_rs_thresh = 0;
2401 : 0 : qinfo->conf.offloads = txq->offloads;
2402 : 0 : qinfo->conf.tx_deferred_start = 0;
2403 : 0 : }
2404 : :
2405 : : static int
2406 : 0 : dpaa2_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *ops)
2407 : : {
2408 : 0 : *(const void **)ops = &dpaa2_tm_ops;
2409 : :
2410 : 0 : return 0;
2411 : : }
2412 : :
2413 : : void
2414 : 0 : rte_pmd_dpaa2_thread_init(void)
2415 : : {
2416 : : int ret;
2417 : :
2418 [ # # ]: 0 : if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
2419 : 0 : ret = dpaa2_affine_qbman_swp();
2420 [ # # ]: 0 : if (ret) {
2421 : 0 : DPAA2_PMD_ERR(
2422 : : "Failed to allocate IO portal, tid: %d",
2423 : : rte_gettid());
2424 : 0 : return;
2425 : : }
2426 : : }
2427 : : }
2428 : :
2429 : : static struct eth_dev_ops dpaa2_ethdev_ops = {
2430 : : .dev_configure = dpaa2_eth_dev_configure,
2431 : : .dev_start = dpaa2_dev_start,
2432 : : .dev_stop = dpaa2_dev_stop,
2433 : : .dev_close = dpaa2_dev_close,
2434 : : .promiscuous_enable = dpaa2_dev_promiscuous_enable,
2435 : : .promiscuous_disable = dpaa2_dev_promiscuous_disable,
2436 : : .allmulticast_enable = dpaa2_dev_allmulticast_enable,
2437 : : .allmulticast_disable = dpaa2_dev_allmulticast_disable,
2438 : : .dev_set_link_up = dpaa2_dev_set_link_up,
2439 : : .dev_set_link_down = dpaa2_dev_set_link_down,
2440 : : .link_update = dpaa2_dev_link_update,
2441 : : .stats_get = dpaa2_dev_stats_get,
2442 : : .xstats_get = dpaa2_dev_xstats_get,
2443 : : .xstats_get_by_id = dpaa2_xstats_get_by_id,
2444 : : .xstats_get_names_by_id = dpaa2_xstats_get_names_by_id,
2445 : : .xstats_get_names = dpaa2_xstats_get_names,
2446 : : .stats_reset = dpaa2_dev_stats_reset,
2447 : : .xstats_reset = dpaa2_dev_stats_reset,
2448 : : .fw_version_get = dpaa2_fw_version_get,
2449 : : .dev_infos_get = dpaa2_dev_info_get,
2450 : : .dev_supported_ptypes_get = dpaa2_supported_ptypes_get,
2451 : : .mtu_set = dpaa2_dev_mtu_set,
2452 : : .vlan_filter_set = dpaa2_vlan_filter_set,
2453 : : .vlan_offload_set = dpaa2_vlan_offload_set,
2454 : : .vlan_tpid_set = dpaa2_vlan_tpid_set,
2455 : : .rx_queue_setup = dpaa2_dev_rx_queue_setup,
2456 : : .rx_queue_release = dpaa2_dev_rx_queue_release,
2457 : : .tx_queue_setup = dpaa2_dev_tx_queue_setup,
2458 : : .rx_burst_mode_get = dpaa2_dev_rx_burst_mode_get,
2459 : : .tx_burst_mode_get = dpaa2_dev_tx_burst_mode_get,
2460 : : .flow_ctrl_get = dpaa2_flow_ctrl_get,
2461 : : .flow_ctrl_set = dpaa2_flow_ctrl_set,
2462 : : .mac_addr_add = dpaa2_dev_add_mac_addr,
2463 : : .mac_addr_remove = dpaa2_dev_remove_mac_addr,
2464 : : .mac_addr_set = dpaa2_dev_set_mac_addr,
2465 : : .rss_hash_update = dpaa2_dev_rss_hash_update,
2466 : : .rss_hash_conf_get = dpaa2_dev_rss_hash_conf_get,
2467 : : .flow_ops_get = dpaa2_dev_flow_ops_get,
2468 : : .rxq_info_get = dpaa2_rxq_info_get,
2469 : : .txq_info_get = dpaa2_txq_info_get,
2470 : : .tm_ops_get = dpaa2_tm_ops_get,
2471 : : #if defined(RTE_LIBRTE_IEEE1588)
2472 : : .timesync_enable = dpaa2_timesync_enable,
2473 : : .timesync_disable = dpaa2_timesync_disable,
2474 : : .timesync_read_time = dpaa2_timesync_read_time,
2475 : : .timesync_write_time = dpaa2_timesync_write_time,
2476 : : .timesync_adjust_time = dpaa2_timesync_adjust_time,
2477 : : .timesync_read_rx_timestamp = dpaa2_timesync_read_rx_timestamp,
2478 : : .timesync_read_tx_timestamp = dpaa2_timesync_read_tx_timestamp,
2479 : : #endif
2480 : : };
2481 : :
2482 : : /* Populate the mac address from physically available (u-boot/firmware) and/or
2483 : : * one set by higher layers like MC (restool) etc.
2484 : : * Returns the table of MAC entries (multiple entries)
2485 : : */
2486 : : static int
2487 : 0 : populate_mac_addr(struct fsl_mc_io *dpni_dev,
2488 : : struct dpaa2_dev_priv *priv, struct rte_ether_addr *mac_entry)
2489 : : {
2490 : : int ret = 0;
2491 : : struct rte_ether_addr phy_mac, prime_mac;
2492 : :
2493 : : memset(&phy_mac, 0, sizeof(struct rte_ether_addr));
2494 : : memset(&prime_mac, 0, sizeof(struct rte_ether_addr));
2495 : :
2496 : : /* Get the physical device MAC address */
2497 : 0 : ret = dpni_get_port_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
2498 : : phy_mac.addr_bytes);
2499 [ # # ]: 0 : if (ret) {
2500 : 0 : DPAA2_PMD_ERR("DPNI get physical port MAC failed: %d", ret);
2501 : 0 : goto cleanup;
2502 : : }
2503 : :
2504 : 0 : ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
2505 : : prime_mac.addr_bytes);
2506 [ # # ]: 0 : if (ret) {
2507 : 0 : DPAA2_PMD_ERR("DPNI get Prime port MAC failed: %d", ret);
2508 : 0 : goto cleanup;
2509 : : }
2510 : :
2511 : : /* Now that both MAC have been obtained, do:
2512 : : * if not_empty_mac(phy) && phy != Prime, overwrite prime with Phy
2513 : : * and return phy
2514 : : * If empty_mac(phy), return prime.
2515 : : * if both are empty, create random MAC, set as prime and return
2516 : : */
2517 [ # # ]: 0 : if (!rte_is_zero_ether_addr(&phy_mac)) {
2518 : : /* If the addresses are not same, overwrite prime */
2519 [ # # ]: 0 : if (!rte_is_same_ether_addr(&phy_mac, &prime_mac)) {
2520 : 0 : ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
2521 : 0 : priv->token,
2522 : : phy_mac.addr_bytes);
2523 [ # # ]: 0 : if (ret) {
2524 : 0 : DPAA2_PMD_ERR("Unable to set MAC Address: %d",
2525 : : ret);
2526 : 0 : goto cleanup;
2527 : : }
2528 : : memcpy(&prime_mac, &phy_mac,
2529 : : sizeof(struct rte_ether_addr));
2530 : : }
2531 [ # # ]: 0 : } else if (rte_is_zero_ether_addr(&prime_mac)) {
2532 : : /* In case phys and prime, both are zero, create random MAC */
2533 : 0 : rte_eth_random_addr(prime_mac.addr_bytes);
2534 : 0 : ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
2535 : 0 : priv->token,
2536 : : prime_mac.addr_bytes);
2537 [ # # ]: 0 : if (ret) {
2538 : 0 : DPAA2_PMD_ERR("Unable to set MAC Address: %d", ret);
2539 : 0 : goto cleanup;
2540 : : }
2541 : : }
2542 : :
2543 : : /* prime_mac the final MAC address */
2544 : : memcpy(mac_entry, &prime_mac, sizeof(struct rte_ether_addr));
2545 : 0 : return 0;
2546 : :
2547 : : cleanup:
2548 : : return ret;
2549 : : }
2550 : :
2551 : : static int
2552 : 0 : check_devargs_handler(__rte_unused const char *key, const char *value,
2553 : : __rte_unused void *opaque)
2554 : : {
2555 [ # # ]: 0 : if (strcmp(value, "1"))
2556 : 0 : return -1;
2557 : :
2558 : : return 0;
2559 : : }
2560 : :
2561 : : static int
2562 : 0 : dpaa2_get_devargs(struct rte_devargs *devargs, const char *key)
2563 : : {
2564 : : struct rte_kvargs *kvlist;
2565 : :
2566 [ # # ]: 0 : if (!devargs)
2567 : : return 0;
2568 : :
2569 : 0 : kvlist = rte_kvargs_parse(devargs->args, NULL);
2570 [ # # ]: 0 : if (!kvlist)
2571 : : return 0;
2572 : :
2573 [ # # ]: 0 : if (!rte_kvargs_count(kvlist, key)) {
2574 : 0 : rte_kvargs_free(kvlist);
2575 : 0 : return 0;
2576 : : }
2577 : :
2578 [ # # ]: 0 : if (rte_kvargs_process(kvlist, key,
2579 : : check_devargs_handler, NULL) < 0) {
2580 : 0 : rte_kvargs_free(kvlist);
2581 : 0 : return 0;
2582 : : }
2583 : 0 : rte_kvargs_free(kvlist);
2584 : :
2585 : 0 : return 1;
2586 : : }
2587 : :
2588 : : static int
2589 : 0 : dpaa2_dev_init(struct rte_eth_dev *eth_dev)
2590 : : {
2591 : 0 : struct rte_device *dev = eth_dev->device;
2592 : : struct rte_dpaa2_device *dpaa2_dev;
2593 : : struct fsl_mc_io *dpni_dev;
2594 : : struct dpni_attr attr;
2595 : 0 : struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
2596 : : struct dpni_buffer_layout layout;
2597 : : int ret, hw_id, i;
2598 : :
2599 : 0 : PMD_INIT_FUNC_TRACE();
2600 : :
2601 : 0 : dpni_dev = rte_malloc(NULL, sizeof(struct fsl_mc_io), 0);
2602 [ # # ]: 0 : if (!dpni_dev) {
2603 : 0 : DPAA2_PMD_ERR("Memory allocation failed for dpni device");
2604 : 0 : return -1;
2605 : : }
2606 : 0 : dpni_dev->regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
2607 : 0 : eth_dev->process_private = dpni_dev;
2608 : :
2609 : : /* For secondary processes, the primary has done all the work */
2610 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2611 : : /* In case of secondary, only burst and ops API need to be
2612 : : * plugged.
2613 : : */
2614 : 0 : eth_dev->dev_ops = &dpaa2_ethdev_ops;
2615 : 0 : eth_dev->rx_queue_count = dpaa2_dev_rx_queue_count;
2616 [ # # ]: 0 : if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE))
2617 : 0 : eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
2618 [ # # ]: 0 : else if (dpaa2_get_devargs(dev->devargs,
2619 : : DRIVER_NO_PREFETCH_MODE))
2620 : 0 : eth_dev->rx_pkt_burst = dpaa2_dev_rx;
2621 : : else
2622 : 0 : eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
2623 : 0 : eth_dev->tx_pkt_burst = dpaa2_dev_tx;
2624 : 0 : return 0;
2625 : : }
2626 : :
2627 : 0 : dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
2628 : :
2629 : 0 : hw_id = dpaa2_dev->object_id;
2630 : 0 : ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
2631 [ # # ]: 0 : if (ret) {
2632 : 0 : DPAA2_PMD_ERR(
2633 : : "Failure in opening dpni@%d with err code %d",
2634 : : hw_id, ret);
2635 : 0 : rte_free(dpni_dev);
2636 : 0 : return ret;
2637 : : }
2638 : :
2639 [ # # ]: 0 : if (eth_dev->data->dev_conf.lpbk_mode)
2640 : 0 : dpaa2_dev_recycle_deconfig(eth_dev);
2641 : :
2642 : : /* Clean the device first */
2643 : 0 : ret = dpni_reset(dpni_dev, CMD_PRI_LOW, priv->token);
2644 [ # # ]: 0 : if (ret) {
2645 : 0 : DPAA2_PMD_ERR("Failure cleaning dpni@%d with err code %d",
2646 : : hw_id, ret);
2647 : 0 : goto init_err;
2648 : : }
2649 : :
2650 : 0 : ret = dpni_get_attributes(dpni_dev, CMD_PRI_LOW, priv->token, &attr);
2651 [ # # ]: 0 : if (ret) {
2652 : 0 : DPAA2_PMD_ERR(
2653 : : "Failure in get dpni@%d attribute, err code %d",
2654 : : hw_id, ret);
2655 : 0 : goto init_err;
2656 : : }
2657 : :
2658 : 0 : priv->num_rx_tc = attr.num_rx_tcs;
2659 : 0 : priv->num_tx_tc = attr.num_tx_tcs;
2660 : 0 : priv->qos_entries = attr.qos_entries;
2661 : 0 : priv->fs_entries = attr.fs_entries;
2662 : 0 : priv->dist_queues = attr.num_queues;
2663 : 0 : priv->num_channels = attr.num_channels;
2664 [ # # ]: 0 : priv->channel_inuse = 0;
2665 : : rte_spinlock_init(&priv->lpbk_qp_lock);
2666 : :
2667 : : /* only if the custom CG is enabled */
2668 [ # # ]: 0 : if (attr.options & DPNI_OPT_CUSTOM_CG)
2669 : 0 : priv->max_cgs = attr.num_cgs;
2670 : : else
2671 : 0 : priv->max_cgs = 0;
2672 : :
2673 [ # # ]: 0 : for (i = 0; i < priv->max_cgs; i++)
2674 : 0 : priv->cgid_in_use[i] = 0;
2675 : :
2676 [ # # ]: 0 : for (i = 0; i < attr.num_rx_tcs; i++)
2677 : 0 : priv->nb_rx_queues += attr.num_queues;
2678 : :
2679 : 0 : priv->nb_tx_queues = attr.num_tx_tcs * attr.num_channels;
2680 : :
2681 : 0 : DPAA2_PMD_DEBUG("RX-TC= %d, rx_queues= %d, tx_queues=%d, max_cgs=%d",
2682 : : priv->num_rx_tc, priv->nb_rx_queues,
2683 : : priv->nb_tx_queues, priv->max_cgs);
2684 : :
2685 : 0 : priv->hw = dpni_dev;
2686 : 0 : priv->hw_id = hw_id;
2687 : 0 : priv->options = attr.options;
2688 : 0 : priv->max_mac_filters = attr.mac_filter_entries;
2689 : 0 : priv->max_vlan_filters = attr.vlan_filter_entries;
2690 : 0 : priv->flags = 0;
2691 : : #if defined(RTE_LIBRTE_IEEE1588)
2692 : : DPAA2_PMD_INFO("DPDK IEEE1588 is enabled");
2693 : : priv->flags |= DPAA2_TX_CONF_ENABLE;
2694 : : #endif
2695 : : /* Used with ``fslmc:dpni.1,drv_tx_conf=1`` */
2696 [ # # ]: 0 : if (dpaa2_get_devargs(dev->devargs, DRIVER_TX_CONF)) {
2697 : 0 : priv->flags |= DPAA2_TX_CONF_ENABLE;
2698 : 0 : DPAA2_PMD_INFO("TX_CONF Enabled");
2699 : : }
2700 : :
2701 [ # # ]: 0 : if (dpaa2_get_devargs(dev->devargs, DRIVER_ERROR_QUEUE)) {
2702 : 0 : dpaa2_enable_err_queue = 1;
2703 : 0 : DPAA2_PMD_INFO("Enable DMA error checks");
2704 : : }
2705 : :
2706 [ # # ]: 0 : if (getenv("DPAA2_PRINT_RX_PARSER_RESULT"))
2707 : 0 : dpaa2_print_parser_result = 1;
2708 : :
2709 : : /* Allocate memory for hardware structure for queues */
2710 : 0 : ret = dpaa2_alloc_rx_tx_queues(eth_dev);
2711 [ # # ]: 0 : if (ret) {
2712 : 0 : DPAA2_PMD_ERR("Queue allocation Failed");
2713 : 0 : goto init_err;
2714 : : }
2715 : :
2716 : : /* Allocate memory for storing MAC addresses.
2717 : : * Table of mac_filter_entries size is allocated so that RTE ether lib
2718 : : * can add MAC entries when rte_eth_dev_mac_addr_add is called.
2719 : : */
2720 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("dpni",
2721 : 0 : RTE_ETHER_ADDR_LEN * attr.mac_filter_entries, 0);
2722 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
2723 : 0 : DPAA2_PMD_ERR(
2724 : : "Failed to allocate %d bytes needed to store MAC addresses",
2725 : : RTE_ETHER_ADDR_LEN * attr.mac_filter_entries);
2726 : : ret = -ENOMEM;
2727 : 0 : goto init_err;
2728 : : }
2729 : :
2730 : 0 : ret = populate_mac_addr(dpni_dev, priv, ð_dev->data->mac_addrs[0]);
2731 [ # # ]: 0 : if (ret) {
2732 : 0 : DPAA2_PMD_ERR("Unable to fetch MAC Address for device");
2733 : 0 : rte_free(eth_dev->data->mac_addrs);
2734 : 0 : eth_dev->data->mac_addrs = NULL;
2735 : 0 : goto init_err;
2736 : : }
2737 : :
2738 : : /* ... tx buffer layout ... */
2739 : : memset(&layout, 0, sizeof(struct dpni_buffer_layout));
2740 [ # # ]: 0 : if (priv->flags & DPAA2_TX_CONF_ENABLE) {
2741 : 0 : layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
2742 : : DPNI_BUF_LAYOUT_OPT_TIMESTAMP;
2743 : 0 : layout.pass_timestamp = true;
2744 : : } else {
2745 : 0 : layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
2746 : : }
2747 : 0 : layout.pass_frame_status = 1;
2748 : 0 : ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
2749 : : DPNI_QUEUE_TX, &layout);
2750 [ # # ]: 0 : if (ret) {
2751 : 0 : DPAA2_PMD_ERR("Error (%d) in setting tx buffer layout", ret);
2752 : 0 : goto init_err;
2753 : : }
2754 : :
2755 : : /* ... tx-conf and error buffer layout ... */
2756 : : memset(&layout, 0, sizeof(struct dpni_buffer_layout));
2757 [ # # ]: 0 : if (priv->flags & DPAA2_TX_CONF_ENABLE) {
2758 : 0 : layout.options = DPNI_BUF_LAYOUT_OPT_TIMESTAMP;
2759 : 0 : layout.pass_timestamp = true;
2760 : : }
2761 : 0 : layout.options |= DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
2762 : 0 : layout.pass_frame_status = 1;
2763 : 0 : ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
2764 : : DPNI_QUEUE_TX_CONFIRM, &layout);
2765 [ # # ]: 0 : if (ret) {
2766 : 0 : DPAA2_PMD_ERR("Error (%d) in setting tx-conf buffer layout",
2767 : : ret);
2768 : 0 : goto init_err;
2769 : : }
2770 : :
2771 : 0 : eth_dev->dev_ops = &dpaa2_ethdev_ops;
2772 : :
2773 [ # # ]: 0 : if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE)) {
2774 : 0 : eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
2775 : 0 : DPAA2_PMD_INFO("Loopback mode");
2776 [ # # ]: 0 : } else if (dpaa2_get_devargs(dev->devargs, DRIVER_NO_PREFETCH_MODE)) {
2777 : 0 : eth_dev->rx_pkt_burst = dpaa2_dev_rx;
2778 : 0 : DPAA2_PMD_INFO("No Prefetch mode");
2779 : : } else {
2780 : 0 : eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
2781 : : }
2782 : 0 : eth_dev->tx_pkt_burst = dpaa2_dev_tx;
2783 : :
2784 : : /* Init fields w.r.t. classification */
2785 : 0 : memset(&priv->extract.qos_key_extract, 0,
2786 : : sizeof(struct dpaa2_key_extract));
2787 : 0 : priv->extract.qos_extract_param = rte_malloc(NULL,
2788 : : DPAA2_EXTRACT_PARAM_MAX_SIZE,
2789 : : RTE_CACHE_LINE_SIZE);
2790 [ # # ]: 0 : if (!priv->extract.qos_extract_param) {
2791 : 0 : DPAA2_PMD_ERR("Memory alloc failed");
2792 : 0 : goto init_err;
2793 : : }
2794 : :
2795 [ # # ]: 0 : for (i = 0; i < MAX_TCS; i++) {
2796 : 0 : memset(&priv->extract.tc_key_extract[i], 0,
2797 : : sizeof(struct dpaa2_key_extract));
2798 : 0 : priv->extract.tc_extract_param[i] = rte_malloc(NULL,
2799 : : DPAA2_EXTRACT_PARAM_MAX_SIZE,
2800 : : RTE_CACHE_LINE_SIZE);
2801 [ # # ]: 0 : if (!priv->extract.tc_extract_param[i]) {
2802 : 0 : DPAA2_PMD_ERR("Memory alloc failed");
2803 : 0 : goto init_err;
2804 : : }
2805 : : }
2806 : :
2807 : 0 : ret = dpni_set_max_frame_length(dpni_dev, CMD_PRI_LOW, priv->token,
2808 : : RTE_ETHER_MAX_LEN - RTE_ETHER_CRC_LEN
2809 : : + VLAN_TAG_SIZE);
2810 [ # # ]: 0 : if (ret) {
2811 : 0 : DPAA2_PMD_ERR("Unable to set mtu. check config");
2812 : 0 : goto init_err;
2813 : : }
2814 : 0 : eth_dev->data->mtu = RTE_ETHER_MTU;
2815 : :
2816 : : /*TODO To enable soft parser support DPAA2 driver needs to integrate
2817 : : * with external entity to receive byte code for software sequence
2818 : : * and same will be offload to the H/W using MC interface.
2819 : : * Currently it is assumed that DPAA2 driver has byte code by some
2820 : : * mean and same if offloaded to H/W.
2821 : : */
2822 [ # # ]: 0 : if (getenv("DPAA2_ENABLE_SOFT_PARSER")) {
2823 : 0 : WRIOP_SS_INITIALIZER(priv);
2824 : 0 : ret = dpaa2_eth_load_wriop_soft_parser(priv, DPNI_SS_INGRESS);
2825 [ # # ]: 0 : if (ret < 0) {
2826 : 0 : DPAA2_PMD_ERR(" Error(%d) in loading softparser",
2827 : : ret);
2828 : 0 : return ret;
2829 : : }
2830 : :
2831 : 0 : ret = dpaa2_eth_enable_wriop_soft_parser(priv,
2832 : : DPNI_SS_INGRESS);
2833 [ # # ]: 0 : if (ret < 0) {
2834 : 0 : DPAA2_PMD_ERR(" Error(%d) in enabling softparser",
2835 : : ret);
2836 : 0 : return ret;
2837 : : }
2838 : : }
2839 : :
2840 : 0 : ret = dpaa2_soft_parser_loaded();
2841 [ # # ]: 0 : if (ret > 0)
2842 : 0 : DPAA2_PMD_INFO("soft parser is loaded");
2843 : 0 : DPAA2_PMD_INFO("%s: netdev created, connected to %s",
2844 : : eth_dev->data->name, dpaa2_dev->ep_name);
2845 : :
2846 : 0 : return 0;
2847 : 0 : init_err:
2848 : 0 : dpaa2_dev_close(eth_dev);
2849 : :
2850 : 0 : return ret;
2851 : : }
2852 : :
2853 : : int
2854 : 0 : rte_pmd_dpaa2_dev_is_dpaa2(uint32_t eth_id)
2855 : : {
2856 : : struct rte_eth_dev *dev;
2857 : :
2858 [ # # ]: 0 : if (eth_id >= RTE_MAX_ETHPORTS)
2859 : : return false;
2860 : :
2861 : : dev = &rte_eth_devices[eth_id];
2862 [ # # ]: 0 : if (!dev->device)
2863 : : return false;
2864 : :
2865 : 0 : return dev->device->driver == &rte_dpaa2_pmd.driver;
2866 : : }
2867 : :
2868 : : const char *
2869 : 0 : rte_pmd_dpaa2_ep_name(uint32_t eth_id)
2870 : : {
2871 : : struct rte_eth_dev *dev;
2872 : : struct dpaa2_dev_priv *priv;
2873 : :
2874 [ # # ]: 0 : if (eth_id >= RTE_MAX_ETHPORTS)
2875 : : return NULL;
2876 : :
2877 [ # # ]: 0 : if (!rte_pmd_dpaa2_dev_is_dpaa2(eth_id))
2878 : : return NULL;
2879 : :
2880 : : dev = &rte_eth_devices[eth_id];
2881 [ # # ]: 0 : if (!dev->data)
2882 : : return NULL;
2883 : :
2884 [ # # ]: 0 : if (!dev->data->dev_private)
2885 : : return NULL;
2886 : :
2887 : : priv = dev->data->dev_private;
2888 : :
2889 : 0 : return priv->ep_name;
2890 : : }
2891 : :
2892 : : #if defined(RTE_LIBRTE_IEEE1588)
2893 : : int
2894 : : rte_pmd_dpaa2_get_one_step_ts(uint16_t port_id, bool mc_query)
2895 : : {
2896 : : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2897 : : struct dpaa2_dev_priv *priv = dev->data->dev_private;
2898 : : struct fsl_mc_io *dpni = priv->eth_dev->process_private;
2899 : : struct dpni_single_step_cfg ptp_cfg;
2900 : : int err;
2901 : :
2902 : : if (!mc_query)
2903 : : return priv->ptp_correction_offset;
2904 : :
2905 : : err = dpni_get_single_step_cfg(dpni, CMD_PRI_LOW, priv->token, &ptp_cfg);
2906 : : if (err) {
2907 : : DPAA2_PMD_ERR("Failed to retrieve onestep configuration");
2908 : : return err;
2909 : : }
2910 : :
2911 : : if (!ptp_cfg.ptp_onestep_reg_base) {
2912 : : DPAA2_PMD_ERR("1588 onestep reg not available");
2913 : : return -1;
2914 : : }
2915 : :
2916 : : priv->ptp_correction_offset = ptp_cfg.offset;
2917 : :
2918 : : return priv->ptp_correction_offset;
2919 : : }
2920 : :
2921 : : int
2922 : : rte_pmd_dpaa2_set_one_step_ts(uint16_t port_id, uint16_t offset, uint8_t ch_update)
2923 : : {
2924 : : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2925 : : struct dpaa2_dev_priv *priv = dev->data->dev_private;
2926 : : struct fsl_mc_io *dpni = dev->process_private;
2927 : : struct dpni_single_step_cfg cfg;
2928 : : int err;
2929 : :
2930 : : cfg.en = 1;
2931 : : cfg.ch_update = ch_update;
2932 : : cfg.offset = offset;
2933 : : cfg.peer_delay = 0;
2934 : :
2935 : : err = dpni_set_single_step_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
2936 : : if (err)
2937 : : return err;
2938 : :
2939 : : priv->ptp_correction_offset = offset;
2940 : :
2941 : : return 0;
2942 : : }
2943 : : #endif
2944 : :
2945 : 0 : static int dpaa2_tx_sg_pool_init(void)
2946 : : {
2947 : : char name[RTE_MEMZONE_NAMESIZE];
2948 : :
2949 [ # # ]: 0 : if (dpaa2_tx_sg_pool)
2950 : : return 0;
2951 : :
2952 : : sprintf(name, "dpaa2_mbuf_tx_sg_pool");
2953 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
2954 : 0 : dpaa2_tx_sg_pool = rte_pktmbuf_pool_create(name,
2955 : : DPAA2_POOL_SIZE,
2956 : : DPAA2_POOL_CACHE_SIZE, 0,
2957 : : DPAA2_MAX_SGS * sizeof(struct qbman_sge),
2958 : 0 : rte_socket_id());
2959 [ # # ]: 0 : if (!dpaa2_tx_sg_pool) {
2960 : 0 : DPAA2_PMD_ERR("SG pool creation failed");
2961 : 0 : return -ENOMEM;
2962 : : }
2963 : : } else {
2964 : 0 : dpaa2_tx_sg_pool = rte_mempool_lookup(name);
2965 [ # # ]: 0 : if (!dpaa2_tx_sg_pool) {
2966 : 0 : DPAA2_PMD_ERR("SG pool lookup failed");
2967 : 0 : return -ENOMEM;
2968 : : }
2969 : : }
2970 : :
2971 : : return 0;
2972 : : }
2973 : :
2974 : : static int
2975 : 0 : rte_dpaa2_probe(struct rte_dpaa2_driver *dpaa2_drv,
2976 : : struct rte_dpaa2_device *dpaa2_dev)
2977 : : {
2978 : : struct rte_eth_dev *eth_dev;
2979 : : struct dpaa2_dev_priv *dev_priv;
2980 : : int diag;
2981 : :
2982 : : if ((DPAA2_MBUF_HW_ANNOTATION + DPAA2_FD_PTA_SIZE) >
2983 : : RTE_PKTMBUF_HEADROOM) {
2984 : : DPAA2_PMD_ERR("RTE_PKTMBUF_HEADROOM(%d) < DPAA2 Annotation(%d)",
2985 : : RTE_PKTMBUF_HEADROOM,
2986 : : DPAA2_MBUF_HW_ANNOTATION + DPAA2_FD_PTA_SIZE);
2987 : :
2988 : : return -EINVAL;
2989 : : }
2990 : :
2991 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
2992 : 0 : eth_dev = rte_eth_dev_allocate(dpaa2_dev->device.name);
2993 [ # # ]: 0 : if (!eth_dev)
2994 : : return -ENODEV;
2995 : 0 : dev_priv = rte_zmalloc("ethdev private structure",
2996 : : sizeof(struct dpaa2_dev_priv),
2997 : : RTE_CACHE_LINE_SIZE);
2998 [ # # ]: 0 : if (dev_priv == NULL) {
2999 : 0 : DPAA2_PMD_CRIT(
3000 : : "Unable to allocate memory for private data");
3001 : 0 : rte_eth_dev_release_port(eth_dev);
3002 : 0 : return -ENOMEM;
3003 : : }
3004 : 0 : eth_dev->data->dev_private = (void *)dev_priv;
3005 : : /* Store a pointer to eth_dev in dev_private */
3006 : 0 : dev_priv->eth_dev = eth_dev;
3007 : : } else {
3008 : 0 : eth_dev = rte_eth_dev_attach_secondary(dpaa2_dev->device.name);
3009 [ # # ]: 0 : if (!eth_dev) {
3010 : 0 : DPAA2_PMD_DEBUG("returning enodev");
3011 : 0 : return -ENODEV;
3012 : : }
3013 : : }
3014 : :
3015 : 0 : eth_dev->device = &dpaa2_dev->device;
3016 : :
3017 : 0 : dpaa2_dev->eth_dev = eth_dev;
3018 : 0 : eth_dev->data->rx_mbuf_alloc_failed = 0;
3019 : :
3020 [ # # ]: 0 : if (dpaa2_drv->drv_flags & RTE_DPAA2_DRV_INTR_LSC)
3021 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
3022 : :
3023 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
3024 : :
3025 : : /* Invoke PMD device initialization function */
3026 : 0 : diag = dpaa2_dev_init(eth_dev);
3027 [ # # ]: 0 : if (!diag) {
3028 : 0 : diag = dpaa2_tx_sg_pool_init();
3029 [ # # ]: 0 : if (diag)
3030 : : return diag;
3031 : 0 : rte_eth_dev_probing_finish(eth_dev);
3032 : 0 : dpaa2_valid_dev++;
3033 : 0 : return 0;
3034 : : }
3035 : :
3036 : 0 : rte_eth_dev_release_port(eth_dev);
3037 : 0 : return diag;
3038 : : }
3039 : :
3040 : : static int
3041 : 0 : rte_dpaa2_remove(struct rte_dpaa2_device *dpaa2_dev)
3042 : : {
3043 : : struct rte_eth_dev *eth_dev;
3044 : : int ret;
3045 : :
3046 : 0 : eth_dev = dpaa2_dev->eth_dev;
3047 : 0 : dpaa2_dev_close(eth_dev);
3048 : 0 : dpaa2_valid_dev--;
3049 [ # # ]: 0 : if (!dpaa2_valid_dev)
3050 : 0 : rte_mempool_free(dpaa2_tx_sg_pool);
3051 : 0 : ret = rte_eth_dev_release_port(eth_dev);
3052 : :
3053 : 0 : return ret;
3054 : : }
3055 : :
3056 : : static struct rte_dpaa2_driver rte_dpaa2_pmd = {
3057 : : .drv_flags = RTE_DPAA2_DRV_INTR_LSC | RTE_DPAA2_DRV_IOVA_AS_VA,
3058 : : .drv_type = DPAA2_ETH,
3059 : : .probe = rte_dpaa2_probe,
3060 : : .remove = rte_dpaa2_remove,
3061 : : };
3062 : :
3063 : 252 : RTE_PMD_REGISTER_DPAA2(NET_DPAA2_PMD_DRIVER_NAME, rte_dpaa2_pmd);
3064 : : RTE_PMD_REGISTER_PARAM_STRING(NET_DPAA2_PMD_DRIVER_NAME,
3065 : : DRIVER_LOOPBACK_MODE "=<int> "
3066 : : DRIVER_NO_PREFETCH_MODE "=<int>"
3067 : : DRIVER_TX_CONF "=<int>"
3068 : : DRIVER_ERROR_QUEUE "=<int>");
3069 [ - + ]: 252 : RTE_LOG_REGISTER_DEFAULT(dpaa2_logtype_pmd, NOTICE);
|