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