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