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