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