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