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