Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : *
3 : : * Copyright 2016 Freescale Semiconductor, Inc. All rights reserved.
4 : : * Copyright 2017-2020,2022-2025 NXP
5 : : *
6 : : */
7 : : /* System headers */
8 : : #include <stdio.h>
9 : : #include <inttypes.h>
10 : : #include <unistd.h>
11 : : #include <limits.h>
12 : : #include <sched.h>
13 : : #include <signal.h>
14 : : #include <pthread.h>
15 : : #include <sys/types.h>
16 : : #include <sys/syscall.h>
17 : : #include <sys/ioctl.h>
18 : :
19 : : #include <eal_export.h>
20 : : #include <rte_string_fns.h>
21 : : #include <rte_byteorder.h>
22 : : #include <rte_common.h>
23 : : #include <rte_interrupts.h>
24 : : #include <rte_log.h>
25 : : #include <rte_debug.h>
26 : : #include <rte_pci.h>
27 : : #include <rte_atomic.h>
28 : : #include <rte_branch_prediction.h>
29 : : #include <rte_memory.h>
30 : : #include <rte_tailq.h>
31 : : #include <rte_eal.h>
32 : : #include <rte_alarm.h>
33 : : #include <rte_ether.h>
34 : : #include <rte_kvargs.h>
35 : : #include <ethdev_driver.h>
36 : : #include <rte_malloc.h>
37 : : #include <rte_ring.h>
38 : :
39 : : #include <bus_dpaa_driver.h>
40 : : #include <rte_dpaa_logs.h>
41 : : #include <dpaa_mempool.h>
42 : :
43 : : #include <dpaa_ethdev.h>
44 : : #include <dpaa_rxtx.h>
45 : : #include <dpaa_flow.h>
46 : : #include <rte_pmd_dpaa.h>
47 : :
48 : : #include <fsl_usd.h>
49 : : #include <fsl_qman.h>
50 : : #include <fsl_bman.h>
51 : : #include <fsl_fman.h>
52 : : #include <process.h>
53 : : #include <fmlib/fm_ext.h>
54 : :
55 : : #define CHECK_INTERVAL 100 /* 100ms */
56 : : #define MAX_REPEAT_TIME 90 /* 9s (90 * 100ms) in total */
57 : : #define DRIVER_RECV_ERR_PKTS "recv_err_pkts"
58 : : #define RTE_PRIORITY_103 103
59 : :
60 : : /* Supported Rx offloads */
61 : : static uint64_t dev_rx_offloads_sup =
62 : : RTE_ETH_RX_OFFLOAD_SCATTER;
63 : :
64 : : /* Rx offloads which cannot be disabled */
65 : : static uint64_t dev_rx_offloads_nodis =
66 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
67 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
68 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
69 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
70 : : RTE_ETH_RX_OFFLOAD_RSS_HASH;
71 : :
72 : : /* Supported Tx offloads */
73 : : static uint64_t dev_tx_offloads_sup =
74 : : RTE_ETH_TX_OFFLOAD_MT_LOCKFREE |
75 : : RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
76 : :
77 : : /* Tx offloads which cannot be disabled */
78 : : static uint64_t dev_tx_offloads_nodis =
79 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
80 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
81 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
82 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
83 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
84 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
85 : :
86 : : /* Keep track of whether QMAN and BMAN have been globally initialized */
87 : : static int is_global_init;
88 : : static int fmc_q = 1; /* Indicates the use of static fmc for distribution */
89 : : static int default_q; /* use default queue - FMC is not executed*/
90 : : bool dpaa_enable_recv_err_pkts; /* Enable main queue to receive error packets */
91 : :
92 : : /* Per RX FQ Taildrop in frame count */
93 : : static unsigned int td_threshold = CGR_RX_PERFQ_THRESH;
94 : :
95 : : /* Per TX FQ Taildrop in frame count, disabled by default */
96 : : static unsigned int td_tx_threshold;
97 : :
98 : : struct rte_dpaa_xstats_name_off {
99 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
100 : : uint32_t offset;
101 : : };
102 : :
103 : : static const struct rte_dpaa_xstats_name_off dpaa_xstats_strings[] = {
104 : : {"rx_align_err",
105 : : offsetof(struct dpaa_if_stats, raln)},
106 : : {"rx_valid_pause",
107 : : offsetof(struct dpaa_if_stats, rxpf)},
108 : : {"rx_fcs_err",
109 : : offsetof(struct dpaa_if_stats, rfcs)},
110 : : {"rx_vlan_frame",
111 : : offsetof(struct dpaa_if_stats, rvlan)},
112 : : {"rx_frame_err",
113 : : offsetof(struct dpaa_if_stats, rerr)},
114 : : {"rx_drop_err",
115 : : offsetof(struct dpaa_if_stats, rdrp)},
116 : : {"rx_undersized",
117 : : offsetof(struct dpaa_if_stats, rund)},
118 : : {"rx_oversize_err",
119 : : offsetof(struct dpaa_if_stats, rovr)},
120 : : {"rx_fragment_pkt",
121 : : offsetof(struct dpaa_if_stats, rfrg)},
122 : : {"tx_valid_pause",
123 : : offsetof(struct dpaa_if_stats, txpf)},
124 : : {"tx_fcs_err",
125 : : offsetof(struct dpaa_if_stats, terr)},
126 : : {"tx_vlan_frame",
127 : : offsetof(struct dpaa_if_stats, tvlan)},
128 : : {"rx_undersized",
129 : : offsetof(struct dpaa_if_stats, tund)},
130 : : {"rx_frame_counter",
131 : : offsetof(struct dpaa_if_rx_bmi_stats, fmbm_rfrc)},
132 : : {"rx_bad_frames_count",
133 : : offsetof(struct dpaa_if_rx_bmi_stats, fmbm_rfbc)},
134 : : {"rx_large_frames_count",
135 : : offsetof(struct dpaa_if_rx_bmi_stats, fmbm_rlfc)},
136 : : {"rx_filter_frames_count",
137 : : offsetof(struct dpaa_if_rx_bmi_stats, fmbm_rffc)},
138 : : {"rx_frame_discrad_count",
139 : : offsetof(struct dpaa_if_rx_bmi_stats, fmbm_rfdc)},
140 : : {"rx_frame_list_dma_err_count",
141 : : offsetof(struct dpaa_if_rx_bmi_stats, fmbm_rfldec)},
142 : : {"rx_out_of_buffer_discard ",
143 : : offsetof(struct dpaa_if_rx_bmi_stats, fmbm_rodc)},
144 : : {"rx_buf_diallocate",
145 : : offsetof(struct dpaa_if_rx_bmi_stats, fmbm_rbdc)},
146 : : };
147 : :
148 : : static struct rte_dpaa_driver rte_dpaa_pmd;
149 : : int dpaa_valid_dev;
150 : : struct rte_mempool *dpaa_tx_sg_pool;
151 : :
152 : : static int
153 : : dpaa_eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info);
154 : :
155 : : static int dpaa_eth_link_update(struct rte_eth_dev *dev,
156 : : int wait_to_complete __rte_unused);
157 : :
158 : : static void dpaa_interrupt_handler(void *param);
159 : :
160 : : static inline void
161 : 0 : dpaa_poll_queue_default_config(struct qm_mcc_initfq *opts)
162 : : {
163 : : memset(opts, 0, sizeof(struct qm_mcc_initfq));
164 : 0 : opts->we_mask = QM_INITFQ_WE_FQCTRL | QM_INITFQ_WE_CONTEXTA;
165 : 0 : opts->fqd.fq_ctrl = QM_FQCTRL_AVOIDBLOCK | QM_FQCTRL_CTXASTASHING |
166 : : QM_FQCTRL_PREFERINCACHE;
167 : : opts->fqd.context_a.stashing.exclusive = 0;
168 [ # # ]: 0 : if (dpaa_soc_ver() != SVR_LS1046A_FAMILY)
169 : 0 : opts->fqd.context_a.stashing.annotation_cl =
170 : : DPAA_IF_RX_ANNOTATION_STASH;
171 : 0 : opts->fqd.context_a.stashing.data_cl = DPAA_IF_RX_DATA_STASH;
172 : 0 : opts->fqd.context_a.stashing.context_cl = DPAA_IF_RX_CONTEXT_STASH;
173 : 0 : }
174 : :
175 : : static int
176 : 0 : dpaa_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
177 : : {
178 : 0 : uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN
179 : 0 : + VLAN_TAG_SIZE;
180 : 0 : uint32_t buffsz = dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
181 : 0 : struct fman_if *fif = dev->process_private;
182 : :
183 : 0 : PMD_INIT_FUNC_TRACE();
184 : :
185 [ # # ]: 0 : if (fif->is_shared_mac) {
186 : 0 : DPAA_PMD_ERR("Cannot configure mtu from DPDK in VSP mode.");
187 : 0 : return -ENOTSUP;
188 : : }
189 : :
190 : : /*
191 : : * Refuse mtu that requires the support of scattered packets
192 : : * when this feature has not been enabled before.
193 : : */
194 [ # # ]: 0 : if (dev->data->min_rx_buf_size &&
195 [ # # # # ]: 0 : !dev->data->scattered_rx && frame_size > buffsz) {
196 : 0 : DPAA_PMD_ERR("SG not enabled, will not fit in one buffer");
197 : 0 : return -EINVAL;
198 : : }
199 : :
200 : : /* check <seg size> * <max_seg> >= max_frame */
201 [ # # # # ]: 0 : if (dev->data->min_rx_buf_size && dev->data->scattered_rx &&
202 [ # # ]: 0 : (frame_size > buffsz * DPAA_SGT_MAX_ENTRIES)) {
203 : 0 : DPAA_PMD_ERR("Too big to fit for Max SG list %d",
204 : : buffsz * DPAA_SGT_MAX_ENTRIES);
205 : 0 : return -EINVAL;
206 : : }
207 : :
208 : 0 : fman_if_set_maxfrm(dev->process_private, frame_size);
209 : :
210 : 0 : return 0;
211 : : }
212 : :
213 : : static int
214 : 0 : dpaa_eth_dev_configure(struct rte_eth_dev *dev)
215 : : {
216 : 0 : struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
217 : 0 : uint64_t rx_offloads = eth_conf->rxmode.offloads;
218 : 0 : uint64_t tx_offloads = eth_conf->txmode.offloads;
219 : 0 : struct dpaa_if *dpaa_intf = dev->data->dev_private;
220 : : struct rte_eth_link *link = &dev->data->dev_link;
221 : : struct rte_dpaa_device *dpaa_dev;
222 : 0 : struct fman_if *fif = dev->process_private;
223 : : struct __fman_if *__fif;
224 : : struct rte_intr_handle *intr_handle;
225 : : uint32_t max_rx_pktlen;
226 : : int speed, duplex;
227 : : int ret, rx_status, socket_fd;
228 : : struct ifreq ifr;
229 : :
230 : 0 : PMD_INIT_FUNC_TRACE();
231 : :
232 : 0 : dpaa_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *dpaa_dev);
233 : 0 : intr_handle = dpaa_dev->intr_handle;
234 : : __fif = container_of(fif, struct __fman_if, __if);
235 : :
236 : : /* Check if interface is enabled in case of shared MAC */
237 [ # # ]: 0 : if (fif->is_shared_mac) {
238 : 0 : rx_status = fman_if_get_rx_status(fif);
239 [ # # ]: 0 : if (!rx_status) {
240 : 0 : DPAA_PMD_ERR("%s Interface not enabled in kernel!",
241 : : dpaa_intf->name);
242 : 0 : return -EHOSTDOWN;
243 : : }
244 : :
245 : 0 : socket_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
246 [ # # ]: 0 : if (socket_fd == -1) {
247 : 0 : DPAA_PMD_ERR("Cannot open IF socket");
248 : 0 : return -errno;
249 : : }
250 : 0 : strncpy(ifr.ifr_name, dpaa_intf->name, IFNAMSIZ - 1);
251 : :
252 [ # # ]: 0 : if (ioctl(socket_fd, SIOCGIFMTU, &ifr) < 0) {
253 : 0 : DPAA_PMD_ERR("Cannot get interface mtu");
254 : 0 : close(socket_fd);
255 : 0 : return -errno;
256 : : }
257 : :
258 : 0 : close(socket_fd);
259 : 0 : DPAA_PMD_INFO("Using kernel configured mtu size(%u)",
260 : : ifr.ifr_mtu);
261 : :
262 : 0 : eth_conf->rxmode.mtu = ifr.ifr_mtu;
263 : : }
264 : :
265 : : /* Rx offloads which are enabled by default */
266 [ # # ]: 0 : if (dev_rx_offloads_nodis & ~rx_offloads) {
267 : 0 : DPAA_PMD_INFO(
268 : : "Some of rx offloads enabled by default - requested 0x%" PRIx64
269 : : " fixed are 0x%" PRIx64,
270 : : rx_offloads, dev_rx_offloads_nodis);
271 : : }
272 : :
273 : : /* Tx offloads which are enabled by default */
274 [ # # ]: 0 : if (dev_tx_offloads_nodis & ~tx_offloads) {
275 : 0 : DPAA_PMD_INFO(
276 : : "Some of tx offloads enabled by default - requested 0x%" PRIx64
277 : : " fixed are 0x%" PRIx64,
278 : : tx_offloads, dev_tx_offloads_nodis);
279 : : }
280 : :
281 : 0 : max_rx_pktlen = eth_conf->rxmode.mtu + RTE_ETHER_HDR_LEN +
282 : : RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE;
283 [ # # ]: 0 : if (max_rx_pktlen > DPAA_MAX_RX_PKT_LEN) {
284 : 0 : DPAA_PMD_INFO("enabling jumbo override conf max len=%d "
285 : : "supported is %d",
286 : : max_rx_pktlen, DPAA_MAX_RX_PKT_LEN);
287 : : max_rx_pktlen = DPAA_MAX_RX_PKT_LEN;
288 : : }
289 : :
290 [ # # # # : 0 : if (!fif->is_shared_mac && fif->mac_type != fman_offline_internal &&
# # ]
291 : : fif->mac_type != fman_onic)
292 : 0 : fman_if_set_maxfrm(dev->process_private, max_rx_pktlen);
293 : :
294 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
295 : 0 : DPAA_PMD_DEBUG("enabling scatter mode");
296 : 0 : fman_if_set_sg(dev->process_private, 1);
297 : 0 : dev->data->scattered_rx = 1;
298 : : }
299 : :
300 [ # # # # ]: 0 : if (!(default_q || fmc_q)) {
301 : 0 : ret = dpaa_fm_config(dev,
302 : : eth_conf->rx_adv_conf.rss_conf.rss_hf);
303 [ # # ]: 0 : if (ret) {
304 : 0 : dpaa_write_fm_config_to_file();
305 : 0 : DPAA_PMD_ERR("FM port configuration: Failed(%d)", ret);
306 : 0 : return ret;
307 : : }
308 : 0 : dpaa_write_fm_config_to_file();
309 : : }
310 : :
311 : : /* Disable interrupt support on offline port*/
312 [ # # ]: 0 : if (fif->mac_type == fman_offline_internal ||
313 : : fif->mac_type == fman_onic)
314 : : return 0;
315 : :
316 : : /* if the interrupts were configured on this devices*/
317 [ # # # # ]: 0 : if (intr_handle && rte_intr_fd_get(intr_handle)) {
318 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0)
319 : 0 : rte_intr_callback_register(intr_handle,
320 : : dpaa_interrupt_handler,
321 : : (void *)dev);
322 : :
323 : 0 : ret = dpaa_intr_enable(__fif->node_name,
324 : : rte_intr_fd_get(intr_handle));
325 [ # # ]: 0 : if (ret) {
326 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0) {
327 : 0 : rte_intr_callback_unregister(intr_handle,
328 : : dpaa_interrupt_handler,
329 : : (void *)dev);
330 [ # # ]: 0 : if (ret == EINVAL)
331 : 0 : DPAA_PMD_ERR("Failed to enable interrupt: Not Supported");
332 : : else
333 : 0 : DPAA_PMD_ERR("Failed to enable interrupt");
334 : : }
335 : 0 : dev->data->dev_conf.intr_conf.lsc = 0;
336 : 0 : dev->data->dev_flags &= ~RTE_ETH_DEV_INTR_LSC;
337 : : }
338 : : }
339 : :
340 : : /* Wait for link status to get updated */
341 [ # # ]: 0 : if (!link->link_status)
342 : 0 : sleep(1);
343 : :
344 : : /* Configure link only if link is UP*/
345 [ # # ]: 0 : if (link->link_status) {
346 [ # # ]: 0 : if (eth_conf->link_speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
347 : : /* Start autoneg only if link is not in autoneg mode */
348 [ # # ]: 0 : if (!link->link_autoneg)
349 : 0 : dpaa_restart_link_autoneg(__fif->node_name);
350 [ # # ]: 0 : } else if (eth_conf->link_speeds & RTE_ETH_LINK_SPEED_FIXED) {
351 : : switch (eth_conf->link_speeds & RTE_ETH_LINK_SPEED_FIXED) {
352 : : case RTE_ETH_LINK_SPEED_10M_HD:
353 : : speed = RTE_ETH_SPEED_NUM_10M;
354 : : duplex = RTE_ETH_LINK_HALF_DUPLEX;
355 : : break;
356 : : case RTE_ETH_LINK_SPEED_10M:
357 : : speed = RTE_ETH_SPEED_NUM_10M;
358 : : duplex = RTE_ETH_LINK_FULL_DUPLEX;
359 : : break;
360 : : case RTE_ETH_LINK_SPEED_100M_HD:
361 : : speed = RTE_ETH_SPEED_NUM_100M;
362 : : duplex = RTE_ETH_LINK_HALF_DUPLEX;
363 : : break;
364 : : case RTE_ETH_LINK_SPEED_100M:
365 : : speed = RTE_ETH_SPEED_NUM_100M;
366 : : duplex = RTE_ETH_LINK_FULL_DUPLEX;
367 : : break;
368 : : case RTE_ETH_LINK_SPEED_1G:
369 : : speed = RTE_ETH_SPEED_NUM_1G;
370 : : duplex = RTE_ETH_LINK_FULL_DUPLEX;
371 : : break;
372 : : case RTE_ETH_LINK_SPEED_2_5G:
373 : : speed = RTE_ETH_SPEED_NUM_2_5G;
374 : : duplex = RTE_ETH_LINK_FULL_DUPLEX;
375 : : break;
376 : : case RTE_ETH_LINK_SPEED_10G:
377 : : speed = RTE_ETH_SPEED_NUM_10G;
378 : : duplex = RTE_ETH_LINK_FULL_DUPLEX;
379 : : break;
380 : : default:
381 : : speed = RTE_ETH_SPEED_NUM_NONE;
382 : : duplex = RTE_ETH_LINK_FULL_DUPLEX;
383 : : break;
384 : : }
385 : : /* Set link speed */
386 : 0 : dpaa_update_link_speed(__fif->node_name, speed, duplex);
387 : : } else {
388 : : /* Manual autoneg - custom advertisement speed. */
389 : 0 : DPAA_PMD_ERR("Custom Advertisement speeds not supported");
390 : : }
391 : : }
392 : :
393 : : return 0;
394 : : }
395 : :
396 : : static const uint32_t *
397 : 0 : dpaa_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
398 : : {
399 : : static const uint32_t ptypes[] = {
400 : : RTE_PTYPE_L2_ETHER,
401 : : RTE_PTYPE_L2_ETHER_VLAN,
402 : : RTE_PTYPE_L2_ETHER_ARP,
403 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
404 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
405 : : RTE_PTYPE_L4_ICMP,
406 : : RTE_PTYPE_L4_TCP,
407 : : RTE_PTYPE_L4_UDP,
408 : : RTE_PTYPE_L4_FRAG,
409 : : RTE_PTYPE_L4_TCP,
410 : : RTE_PTYPE_L4_UDP,
411 : : RTE_PTYPE_L4_SCTP,
412 : : RTE_PTYPE_TUNNEL_ESP,
413 : : RTE_PTYPE_TUNNEL_GRE,
414 : : };
415 : :
416 : 0 : PMD_INIT_FUNC_TRACE();
417 : :
418 [ # # ]: 0 : if (dev->rx_pkt_burst == dpaa_eth_queue_rx) {
419 : 0 : *no_of_elements = RTE_DIM(ptypes);
420 : 0 : return ptypes;
421 : : }
422 : : return NULL;
423 : : }
424 : :
425 : 0 : static void dpaa_interrupt_handler(void *param)
426 : : {
427 : : struct rte_eth_dev *dev = param;
428 : : struct rte_dpaa_device *dpaa_dev;
429 : : struct rte_intr_handle *intr_handle;
430 : : uint64_t buf;
431 : : int bytes_read;
432 : :
433 : 0 : dpaa_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *dpaa_dev);
434 : 0 : intr_handle = dpaa_dev->intr_handle;
435 : :
436 [ # # ]: 0 : if (rte_intr_fd_get(intr_handle) < 0)
437 : 0 : return;
438 : :
439 : 0 : bytes_read = read(rte_intr_fd_get(intr_handle), &buf,
440 : : sizeof(uint64_t));
441 [ # # ]: 0 : if (bytes_read < 0)
442 : 0 : DPAA_PMD_ERR("Error reading eventfd");
443 : 0 : dpaa_eth_link_update(dev, 0);
444 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
445 : : }
446 : :
447 : 0 : static int dpaa_eth_dev_start(struct rte_eth_dev *dev)
448 : : {
449 : 0 : struct dpaa_if *dpaa_intf = dev->data->dev_private;
450 : 0 : struct fman_if *fif = dev->process_private;
451 : : uint16_t i;
452 : :
453 : 0 : PMD_INIT_FUNC_TRACE();
454 : :
455 [ # # # # ]: 0 : if (!(default_q || fmc_q))
456 : 0 : dpaa_write_fm_config_to_file();
457 : :
458 : : /* Change tx callback to the real one */
459 [ # # ]: 0 : if (dpaa_intf->cgr_tx)
460 : 0 : dev->tx_pkt_burst = dpaa_eth_queue_tx_slow;
461 : : else
462 : 0 : dev->tx_pkt_burst = dpaa_eth_queue_tx;
463 : :
464 [ # # ]: 0 : if (fif->mac_type != fman_onic) {
465 : 0 : fman_if_bmi_stats_enable(fif);
466 : 0 : fman_if_bmi_stats_reset(fif);
467 : 0 : fman_if_enable_rx(fif);
468 : : }
469 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
470 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
471 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
472 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
473 : :
474 : 0 : return 0;
475 : : }
476 : :
477 : 0 : static int dpaa_eth_dev_stop(struct rte_eth_dev *dev)
478 : : {
479 : 0 : struct fman_if *fif = dev->process_private;
480 : : uint16_t i;
481 : :
482 : 0 : PMD_INIT_FUNC_TRACE();
483 : 0 : dev->data->dev_started = 0;
484 : :
485 [ # # ]: 0 : if (!fif->is_shared_mac) {
486 : 0 : fman_if_bmi_stats_disable(fif);
487 : 0 : fman_if_disable_rx(fif);
488 : : }
489 : 0 : dev->tx_pkt_burst = dpaa_eth_tx_drop_all;
490 : :
491 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
492 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
493 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
494 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
495 : :
496 : 0 : return 0;
497 : : }
498 : :
499 : 0 : static int dpaa_eth_dev_close(struct rte_eth_dev *dev)
500 : : {
501 : 0 : struct fman_if *fif = dev->process_private;
502 : : struct __fman_if *__fif;
503 : : struct rte_dpaa_device *dpaa_dev;
504 : : struct rte_intr_handle *intr_handle;
505 : 0 : struct rte_eth_link *link = &dev->data->dev_link;
506 : 0 : struct dpaa_if *dpaa_intf = dev->data->dev_private;
507 : : struct qman_fq *fq;
508 : : int loop;
509 : : int ret;
510 : :
511 : 0 : PMD_INIT_FUNC_TRACE();
512 : :
513 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
514 : : return 0;
515 : :
516 [ # # ]: 0 : if (!dpaa_intf) {
517 : 0 : DPAA_PMD_DEBUG("Already closed or not started");
518 : 0 : return -ENOENT;
519 : : }
520 : :
521 : : /* DPAA FM deconfig */
522 [ # # # # ]: 0 : if (!(default_q || fmc_q)) {
523 : 0 : ret = dpaa_fm_deconfig(dpaa_intf, dev->process_private);
524 [ # # ]: 0 : if (ret) {
525 : 0 : DPAA_PMD_WARN("%s: FM deconfig failed(%d)",
526 : : dev->data->name, ret);
527 : : }
528 : : }
529 : :
530 : 0 : dpaa_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *dpaa_dev);
531 : 0 : intr_handle = dpaa_dev->intr_handle;
532 : : __fif = container_of(fif, struct __fman_if, __if);
533 : :
534 : 0 : ret = dpaa_eth_dev_stop(dev);
535 [ # # ]: 0 : if (ret) {
536 : 0 : DPAA_PMD_WARN("%s: stop device failed(%d)",
537 : : dev->data->name, ret);
538 : : }
539 : :
540 [ # # ]: 0 : if (fif->mac_type == fman_offline_internal ||
541 : : fif->mac_type == fman_onic)
542 : : return 0;
543 : :
544 : : /* Reset link to autoneg */
545 [ # # ]: 0 : if (link->link_status && !link->link_autoneg) {
546 : 0 : ret = dpaa_restart_link_autoneg(__fif->node_name);
547 [ # # ]: 0 : if (ret) {
548 : 0 : DPAA_PMD_WARN("%s: restart link failed(%d)",
549 : : dev->data->name, ret);
550 : : }
551 : : }
552 : :
553 [ # # # # ]: 0 : if (intr_handle && rte_intr_fd_get(intr_handle) &&
554 [ # # ]: 0 : dev->data->dev_conf.intr_conf.lsc != 0) {
555 : 0 : ret = dpaa_intr_disable(__fif->node_name);
556 [ # # ]: 0 : if (ret) {
557 : 0 : DPAA_PMD_WARN("%s: disable interrupt failed(%d)",
558 : : dev->data->name, ret);
559 : : }
560 : 0 : ret = rte_intr_callback_unregister(intr_handle,
561 : : dpaa_interrupt_handler, (void *)dev);
562 [ # # ]: 0 : if (ret) {
563 : 0 : DPAA_PMD_WARN("%s: unregister interrupt failed(%d)",
564 : : dev->data->name, ret);
565 : : }
566 : : }
567 : :
568 : : /* release configuration memory */
569 : 0 : rte_free(dpaa_intf->fc_conf);
570 : :
571 : : /* Release RX congestion Groups */
572 [ # # ]: 0 : if (dpaa_intf->cgr_rx) {
573 [ # # ]: 0 : for (loop = 0; loop < dpaa_intf->nb_rx_queues; loop++) {
574 : 0 : ret = qman_delete_cgr(&dpaa_intf->cgr_rx[loop]);
575 [ # # ]: 0 : if (ret) {
576 : 0 : DPAA_PMD_WARN("%s: delete rxq%d's cgr err(%d)",
577 : : dev->data->name, loop, ret);
578 : : }
579 : : }
580 : 0 : rte_free(dpaa_intf->cgr_rx);
581 : 0 : dpaa_intf->cgr_rx = NULL;
582 : : }
583 : :
584 : : /* Release TX congestion Groups */
585 [ # # ]: 0 : if (dpaa_intf->cgr_tx) {
586 [ # # ]: 0 : for (loop = 0; loop < MAX_DPAA_CORES; loop++) {
587 : 0 : ret = qman_delete_cgr(&dpaa_intf->cgr_tx[loop]);
588 [ # # ]: 0 : if (ret) {
589 : 0 : DPAA_PMD_WARN("%s: delete txq%d's cgr err(%d)",
590 : : dev->data->name, loop, ret);
591 : : }
592 : : }
593 : 0 : rte_free(dpaa_intf->cgr_tx);
594 : 0 : dpaa_intf->cgr_tx = NULL;
595 : : }
596 : :
597 : : /* Freeing queue specific portals */
598 [ # # ]: 0 : for (loop = 0; loop < dpaa_intf->nb_rx_queues; loop++) {
599 [ # # ]: 0 : if (!dpaa_intf->rx_queues)
600 : : break;
601 : :
602 : 0 : fq = &dpaa_intf->rx_queues[loop];
603 [ # # ]: 0 : if (fq->qp_initialized) {
604 : 0 : rte_dpaa_portal_fq_close(fq);
605 : 0 : fq->qp_initialized = 0;
606 : : }
607 : : }
608 : :
609 : 0 : rte_free(dpaa_intf->rx_queues);
610 : 0 : dpaa_intf->rx_queues = NULL;
611 : :
612 : 0 : rte_free(dpaa_intf->tx_queues);
613 : 0 : dpaa_intf->tx_queues = NULL;
614 [ # # ]: 0 : if (dpaa_intf->port_handle) {
615 : 0 : ret = dpaa_fm_deconfig(dpaa_intf, fif);
616 [ # # ]: 0 : if (ret) {
617 : 0 : DPAA_PMD_WARN("%s: FM deconfig failed(%d)",
618 : : dev->data->name, ret);
619 : : }
620 : : }
621 [ # # ]: 0 : if (fif->num_profiles) {
622 : 0 : ret = dpaa_port_vsp_cleanup(dpaa_intf, fif);
623 [ # # ]: 0 : if (ret) {
624 : 0 : DPAA_PMD_WARN("%s: cleanup VSP failed(%d)",
625 : : dev->data->name, ret);
626 : : }
627 : : }
628 : :
629 : : return ret;
630 : : }
631 : :
632 : : static int
633 : 0 : dpaa_fw_version_get(struct rte_eth_dev *dev,
634 : : char *fw_version, size_t fw_size)
635 : : {
636 : 0 : struct fman_if *fif = dev->process_private;
637 : : int ret;
638 : :
639 : 0 : PMD_INIT_FUNC_TRACE();
640 : :
641 : 0 : ret = snprintf(fw_version, fw_size, "SVR:%x-fman-v%x",
642 : 0 : dpaa_soc_ver(), fif->fman->ip_rev);
643 [ # # ]: 0 : if (ret < 0)
644 : : return -EINVAL;
645 : :
646 : 0 : ret += 1; /* add the size of '\0' */
647 [ # # ]: 0 : if (fw_size < (size_t)ret)
648 : : return ret;
649 : : else
650 : 0 : return 0;
651 : : }
652 : :
653 : 0 : static int dpaa_eth_dev_info(struct rte_eth_dev *dev,
654 : : struct rte_eth_dev_info *dev_info)
655 : : {
656 : 0 : struct dpaa_if *dpaa_intf = dev->data->dev_private;
657 : 0 : struct fman_if *fif = dev->process_private;
658 : :
659 : 0 : DPAA_PMD_DEBUG(": %s", dpaa_intf->name);
660 : :
661 : 0 : dev_info->max_rx_queues = dpaa_intf->nb_rx_queues;
662 : 0 : dev_info->max_tx_queues = dpaa_intf->nb_tx_queues;
663 : 0 : dev_info->max_rx_pktlen = DPAA_MAX_RX_PKT_LEN;
664 : 0 : dev_info->max_mac_addrs = DPAA_MAX_MAC_FILTER;
665 : 0 : dev_info->max_hash_mac_addrs = 0;
666 : 0 : dev_info->max_vfs = 0;
667 : 0 : dev_info->max_vmdq_pools = RTE_ETH_16_POOLS;
668 : 0 : dev_info->flow_type_rss_offloads = DPAA_RSS_OFFLOAD_ALL;
669 : :
670 [ # # ]: 0 : if (fif->mac_type == fman_mac_1g) {
671 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M_HD
672 : : | RTE_ETH_LINK_SPEED_10M
673 : : | RTE_ETH_LINK_SPEED_100M_HD
674 : : | RTE_ETH_LINK_SPEED_100M
675 : : | RTE_ETH_LINK_SPEED_1G;
676 [ # # ]: 0 : } else if (fif->mac_type == fman_mac_2_5g) {
677 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M_HD
678 : : | RTE_ETH_LINK_SPEED_10M
679 : : | RTE_ETH_LINK_SPEED_100M_HD
680 : : | RTE_ETH_LINK_SPEED_100M
681 : : | RTE_ETH_LINK_SPEED_1G
682 : : | RTE_ETH_LINK_SPEED_2_5G;
683 [ # # ]: 0 : } else if (fif->mac_type == fman_mac_10g) {
684 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M_HD
685 : : | RTE_ETH_LINK_SPEED_10M
686 : : | RTE_ETH_LINK_SPEED_100M_HD
687 : : | RTE_ETH_LINK_SPEED_100M
688 : : | RTE_ETH_LINK_SPEED_1G
689 : : | RTE_ETH_LINK_SPEED_2_5G
690 : : | RTE_ETH_LINK_SPEED_10G;
691 [ # # ]: 0 : } else if (fif->mac_type == fman_offline_internal ||
692 : : fif->mac_type == fman_onic) {
693 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M_HD
694 : : | RTE_ETH_LINK_SPEED_10M
695 : : | RTE_ETH_LINK_SPEED_100M_HD
696 : : | RTE_ETH_LINK_SPEED_100M
697 : : | RTE_ETH_LINK_SPEED_1G
698 : : | RTE_ETH_LINK_SPEED_2_5G;
699 : : } else {
700 : 0 : DPAA_PMD_ERR("invalid link_speed: %s, %d",
701 : : dpaa_intf->name, fif->mac_type);
702 : 0 : return -EINVAL;
703 : : }
704 : :
705 : 0 : dev_info->rx_offload_capa = dev_rx_offloads_sup |
706 : : dev_rx_offloads_nodis;
707 : 0 : dev_info->tx_offload_capa = dev_tx_offloads_sup |
708 : : dev_tx_offloads_nodis;
709 : 0 : dev_info->default_rxportconf.burst_size = DPAA_DEF_RX_BURST_SIZE;
710 : 0 : dev_info->default_txportconf.burst_size = DPAA_DEF_TX_BURST_SIZE;
711 : 0 : dev_info->default_rxportconf.nb_queues = 1;
712 : 0 : dev_info->default_txportconf.nb_queues = 1;
713 : 0 : dev_info->default_txportconf.ring_size = CGR_TX_CGR_THRESH;
714 : 0 : dev_info->default_rxportconf.ring_size = CGR_RX_PERFQ_THRESH;
715 : :
716 : 0 : return 0;
717 : : }
718 : :
719 : : static int
720 : 0 : dpaa_dev_rx_burst_mode_get(struct rte_eth_dev *dev,
721 : : __rte_unused uint16_t queue_id,
722 : : struct rte_eth_burst_mode *mode)
723 : : {
724 : 0 : struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
725 : : int ret = -EINVAL;
726 : : unsigned int i;
727 : : const struct burst_info {
728 : : uint64_t flags;
729 : : const char *output;
730 : 0 : } rx_offload_map[] = {
731 : : {RTE_ETH_RX_OFFLOAD_SCATTER, " Scattered,"},
732 : : {RTE_ETH_RX_OFFLOAD_IPV4_CKSUM, " IPV4 csum,"},
733 : : {RTE_ETH_RX_OFFLOAD_UDP_CKSUM, " UDP csum,"},
734 : : {RTE_ETH_RX_OFFLOAD_TCP_CKSUM, " TCP csum,"},
735 : : {RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM, " Outer IPV4 csum,"},
736 : : {RTE_ETH_RX_OFFLOAD_RSS_HASH, " RSS,"}
737 : : };
738 : :
739 : : /* Update Rx offload info */
740 [ # # ]: 0 : for (i = 0; i < RTE_DIM(rx_offload_map); i++) {
741 [ # # ]: 0 : if (eth_conf->rxmode.offloads & rx_offload_map[i].flags) {
742 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
743 : 0 : rx_offload_map[i].output);
744 : : ret = 0;
745 : 0 : break;
746 : : }
747 : : }
748 : 0 : return ret;
749 : : }
750 : :
751 : : static int
752 : 0 : dpaa_dev_tx_burst_mode_get(struct rte_eth_dev *dev,
753 : : __rte_unused uint16_t queue_id,
754 : : struct rte_eth_burst_mode *mode)
755 : : {
756 : 0 : struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
757 : : int ret = -EINVAL;
758 : : unsigned int i;
759 : : const struct burst_info {
760 : : uint64_t flags;
761 : : const char *output;
762 : 0 : } tx_offload_map[] = {
763 : : {RTE_ETH_TX_OFFLOAD_MT_LOCKFREE, " MT lockfree,"},
764 : : {RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE, " MBUF free disable,"},
765 : : {RTE_ETH_TX_OFFLOAD_IPV4_CKSUM, " IPV4 csum,"},
766 : : {RTE_ETH_TX_OFFLOAD_UDP_CKSUM, " UDP csum,"},
767 : : {RTE_ETH_TX_OFFLOAD_TCP_CKSUM, " TCP csum,"},
768 : : {RTE_ETH_TX_OFFLOAD_SCTP_CKSUM, " SCTP csum,"},
769 : : {RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM, " Outer IPV4 csum,"},
770 : : {RTE_ETH_TX_OFFLOAD_MULTI_SEGS, " Scattered,"}
771 : : };
772 : :
773 : : /* Update Tx offload info */
774 [ # # ]: 0 : for (i = 0; i < RTE_DIM(tx_offload_map); i++) {
775 [ # # ]: 0 : if (eth_conf->txmode.offloads & tx_offload_map[i].flags) {
776 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
777 : 0 : tx_offload_map[i].output);
778 : : ret = 0;
779 : 0 : break;
780 : : }
781 : : }
782 : 0 : return ret;
783 : : }
784 : :
785 : 0 : static int dpaa_eth_link_update(struct rte_eth_dev *dev,
786 : : int wait_to_complete)
787 : : {
788 : 0 : struct dpaa_if *dpaa_intf = dev->data->dev_private;
789 : 0 : struct rte_eth_link *link = &dev->data->dev_link;
790 : 0 : struct fman_if *fif = dev->process_private;
791 : : struct __fman_if *__fif = container_of(fif, struct __fman_if, __if);
792 : : int ret, ioctl_version;
793 : : uint8_t count;
794 : :
795 : 0 : PMD_INIT_FUNC_TRACE();
796 : :
797 : 0 : ioctl_version = dpaa_get_ioctl_version_number();
798 : :
799 [ # # ]: 0 : if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC &&
800 [ # # # # ]: 0 : fif->mac_type != fman_offline_internal &&
801 : : fif->mac_type != fman_onic) {
802 [ # # ]: 0 : for (count = 0; count <= MAX_REPEAT_TIME; count++) {
803 : 0 : ret = dpaa_get_link_status(__fif->node_name, link);
804 [ # # ]: 0 : if (ret)
805 : 0 : return ret;
806 [ # # # # ]: 0 : if (link->link_status == RTE_ETH_LINK_DOWN &&
807 : : wait_to_complete)
808 : : rte_delay_ms(CHECK_INTERVAL);
809 : : else
810 : : break;
811 : : }
812 : : } else {
813 : 0 : link->link_status = dpaa_intf->valid;
814 [ # # ]: 0 : if (fif->mac_type == fman_offline_internal ||
815 : : fif->mac_type == fman_onic) {
816 : : /*Max supported rate for O/H port is 3.75Mpps*/
817 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_2_5G;
818 : 0 : link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
819 : : }
820 : : }
821 : :
822 [ # # ]: 0 : if (ioctl_version < 2) {
823 : 0 : link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
824 : 0 : link->link_autoneg = RTE_ETH_LINK_AUTONEG;
825 : :
826 [ # # ]: 0 : if (fif->mac_type == fman_mac_1g)
827 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_1G;
828 [ # # ]: 0 : else if (fif->mac_type == fman_mac_2_5g)
829 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_2_5G;
830 [ # # ]: 0 : else if (fif->mac_type == fman_mac_10g)
831 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
832 : : else
833 : 0 : DPAA_PMD_ERR("invalid link_speed: %s, %d",
834 : : dpaa_intf->name, fif->mac_type);
835 : : }
836 : :
837 [ # # ]: 0 : DPAA_PMD_INFO("Port %d Link is %s", dev->data->port_id,
838 : : link->link_status ? "Up" : "Down");
839 : 0 : return 0;
840 : : }
841 : :
842 : 0 : static int dpaa_eth_stats_get(struct rte_eth_dev *dev,
843 : : struct rte_eth_stats *stats,
844 : : struct eth_queue_stats *qstats __rte_unused)
845 : : {
846 : 0 : PMD_INIT_FUNC_TRACE();
847 : :
848 : 0 : fman_if_stats_get(dev->process_private, stats);
849 : 0 : return 0;
850 : : }
851 : :
852 : 0 : static int dpaa_eth_stats_reset(struct rte_eth_dev *dev)
853 : : {
854 : 0 : PMD_INIT_FUNC_TRACE();
855 : :
856 : 0 : fman_if_stats_reset(dev->process_private);
857 : 0 : fman_if_bmi_stats_reset(dev->process_private);
858 : :
859 : 0 : return 0;
860 : : }
861 : :
862 : : static int
863 : 0 : dpaa_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
864 : : unsigned int n)
865 : : {
866 : : unsigned int i = 0, j, num = RTE_DIM(dpaa_xstats_strings);
867 : : uint64_t values[sizeof(struct dpaa_if_stats) / 8];
868 : : unsigned int bmi_count = sizeof(struct dpaa_if_rx_bmi_stats) / 4;
869 : :
870 [ # # ]: 0 : if (n < num)
871 : : return num;
872 : :
873 [ # # ]: 0 : if (xstats == NULL)
874 : : return 0;
875 : :
876 : 0 : fman_if_stats_get_all(dev->process_private, values,
877 : : sizeof(struct dpaa_if_stats) / 8);
878 : :
879 [ # # ]: 0 : for (i = 0; i < num - (bmi_count - 1); i++) {
880 : 0 : xstats[i].id = i;
881 : 0 : xstats[i].value = values[dpaa_xstats_strings[i].offset / 8];
882 : : }
883 : 0 : fman_if_bmi_stats_get_all(dev->process_private, values);
884 [ # # ]: 0 : for (j = 0; i < num; i++, j++) {
885 : 0 : xstats[i].id = i;
886 : 0 : xstats[i].value = values[j];
887 : : }
888 : :
889 : : return i;
890 : : }
891 : :
892 : : static int
893 : 0 : dpaa_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
894 : : struct rte_eth_xstat_name *xstats_names,
895 : : unsigned int limit)
896 : : {
897 : : unsigned int i, stat_cnt = RTE_DIM(dpaa_xstats_strings);
898 : :
899 [ # # ]: 0 : if (limit < stat_cnt)
900 : : return stat_cnt;
901 : :
902 [ # # ]: 0 : if (xstats_names != NULL)
903 [ # # ]: 0 : for (i = 0; i < stat_cnt; i++)
904 : 0 : strlcpy(xstats_names[i].name,
905 : : dpaa_xstats_strings[i].name,
906 : : sizeof(xstats_names[i].name));
907 : :
908 : : return stat_cnt;
909 : : }
910 : :
911 : : static int
912 : 0 : dpaa_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
913 : : uint64_t *values, unsigned int n)
914 : : {
915 : : unsigned int i, j, stat_cnt = RTE_DIM(dpaa_xstats_strings);
916 : : uint64_t values_copy[sizeof(struct dpaa_if_stats) / 8];
917 : : unsigned int bmi_count = sizeof(struct dpaa_if_rx_bmi_stats) / 4;
918 : :
919 [ # # ]: 0 : if (!ids) {
920 [ # # ]: 0 : if (n < stat_cnt)
921 : : return stat_cnt;
922 : :
923 [ # # ]: 0 : if (!values)
924 : : return 0;
925 : :
926 : 0 : fman_if_stats_get_all(dev->process_private, values_copy,
927 : : sizeof(struct dpaa_if_stats) / 8);
928 : :
929 [ # # ]: 0 : for (i = 0; i < stat_cnt - (bmi_count - 1); i++)
930 : 0 : values[i] =
931 : 0 : values_copy[dpaa_xstats_strings[i].offset / 8];
932 : :
933 : 0 : fman_if_bmi_stats_get_all(dev->process_private, values);
934 [ # # ]: 0 : for (j = 0; i < stat_cnt; i++, j++)
935 : 0 : values[i] = values_copy[j];
936 : :
937 : : return stat_cnt;
938 : : }
939 : :
940 : 0 : dpaa_xstats_get_by_id(dev, NULL, values_copy, stat_cnt);
941 : :
942 [ # # ]: 0 : for (i = 0; i < n; i++) {
943 [ # # ]: 0 : if (ids[i] >= stat_cnt) {
944 : 0 : DPAA_PMD_ERR("id value isn't valid");
945 : 0 : return -1;
946 : : }
947 : 0 : values[i] = values_copy[ids[i]];
948 : : }
949 : 0 : return n;
950 : : }
951 : :
952 : : static int
953 : 0 : dpaa_xstats_get_names_by_id(
954 : : struct rte_eth_dev *dev,
955 : : const uint64_t *ids,
956 : : struct rte_eth_xstat_name *xstats_names,
957 : : unsigned int limit)
958 : 0 : {
959 : : unsigned int i, stat_cnt = RTE_DIM(dpaa_xstats_strings);
960 : 0 : struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
961 : :
962 [ # # ]: 0 : if (!ids)
963 : 0 : return dpaa_xstats_get_names(dev, xstats_names, limit);
964 : :
965 : 0 : dpaa_xstats_get_names(dev, xstats_names_copy, limit);
966 : :
967 [ # # ]: 0 : for (i = 0; i < limit; i++) {
968 [ # # ]: 0 : if (ids[i] >= stat_cnt) {
969 : 0 : DPAA_PMD_ERR("id value isn't valid");
970 : 0 : return -1;
971 : : }
972 : 0 : strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
973 : : }
974 : 0 : return limit;
975 : : }
976 : :
977 : 0 : static int dpaa_eth_promiscuous_enable(struct rte_eth_dev *dev)
978 : : {
979 : 0 : struct fman_if *fif = dev->process_private;
980 : :
981 : 0 : PMD_INIT_FUNC_TRACE();
982 : :
983 [ # # ]: 0 : if (fif->mac_type == fman_onic) {
984 : 0 : DPAA_PMD_INFO("Enable promiscuous mode not supported on ONIC "
985 : : "port");
986 : 0 : return 0;
987 : : }
988 : :
989 : 0 : fman_if_promiscuous_enable(dev->process_private);
990 : :
991 : 0 : return 0;
992 : : }
993 : :
994 : 0 : static int dpaa_eth_promiscuous_disable(struct rte_eth_dev *dev)
995 : : {
996 : 0 : struct fman_if *fif = dev->process_private;
997 : :
998 : 0 : PMD_INIT_FUNC_TRACE();
999 : :
1000 [ # # ]: 0 : if (fif->mac_type == fman_onic) {
1001 : 0 : DPAA_PMD_INFO("Disable promiscuous mode not supported on ONIC "
1002 : : "port");
1003 : 0 : return 0;
1004 : : }
1005 : :
1006 : 0 : fman_if_promiscuous_disable(dev->process_private);
1007 : :
1008 : 0 : return 0;
1009 : : }
1010 : :
1011 : 0 : static int dpaa_eth_multicast_enable(struct rte_eth_dev *dev)
1012 : : {
1013 : 0 : struct fman_if *fif = dev->process_private;
1014 : :
1015 : 0 : PMD_INIT_FUNC_TRACE();
1016 : :
1017 [ # # ]: 0 : if (fif->mac_type == fman_onic) {
1018 : 0 : DPAA_PMD_INFO("Enable Multicast not supported on ONIC port");
1019 : 0 : return 0;
1020 : : }
1021 : :
1022 : 0 : fman_if_set_mcast_filter_table(dev->process_private);
1023 : :
1024 : 0 : return 0;
1025 : : }
1026 : :
1027 : 0 : static int dpaa_eth_multicast_disable(struct rte_eth_dev *dev)
1028 : : {
1029 : 0 : struct fman_if *fif = dev->process_private;
1030 : :
1031 : 0 : PMD_INIT_FUNC_TRACE();
1032 : :
1033 [ # # ]: 0 : if (fif->mac_type == fman_onic) {
1034 : 0 : DPAA_PMD_INFO("Disable Multicast not supported on ONIC port");
1035 : 0 : return 0;
1036 : : }
1037 : :
1038 : 0 : fman_if_reset_mcast_filter_table(dev->process_private);
1039 : :
1040 : 0 : return 0;
1041 : : }
1042 : :
1043 : 0 : static void dpaa_fman_if_pool_setup(struct rte_eth_dev *dev)
1044 : : {
1045 : 0 : struct dpaa_if *dpaa_intf = dev->data->dev_private;
1046 : : struct fman_if_ic_params icp;
1047 : : uint32_t fd_offset;
1048 : : uint32_t bp_size;
1049 : :
1050 : : memset(&icp, 0, sizeof(icp));
1051 : : /* set ICEOF for to the default value , which is 0*/
1052 : 0 : icp.iciof = DEFAULT_ICIOF;
1053 : 0 : icp.iceof = DEFAULT_RX_ICEOF;
1054 : 0 : icp.icsz = DEFAULT_ICSZ;
1055 : 0 : fman_if_set_ic_params(dev->process_private, &icp);
1056 : :
1057 : : fd_offset = RTE_PKTMBUF_HEADROOM + DPAA_HW_BUF_RESERVE;
1058 : 0 : fman_if_set_fdoff(dev->process_private, fd_offset);
1059 : :
1060 : : /* Buffer pool size should be equal to Dataroom Size*/
1061 [ # # ]: 0 : bp_size = rte_pktmbuf_data_room_size(dpaa_intf->bp_info->mp);
1062 : :
1063 : 0 : fman_if_set_bp(dev->process_private,
1064 : : dpaa_intf->bp_info->mp->size,
1065 : 0 : dpaa_intf->bp_info->bpid, bp_size);
1066 : 0 : }
1067 : :
1068 : 0 : static inline int dpaa_eth_rx_queue_bp_check(struct rte_eth_dev *dev,
1069 : : int8_t vsp_id, uint32_t bpid)
1070 : : {
1071 : 0 : struct dpaa_if *dpaa_intf = dev->data->dev_private;
1072 : 0 : struct fman_if *fif = dev->process_private;
1073 : :
1074 [ # # ]: 0 : if (fif->num_profiles) {
1075 [ # # ]: 0 : if (vsp_id < 0)
1076 : 0 : vsp_id = fif->base_profile_id;
1077 : : } else {
1078 : : if (vsp_id < 0)
1079 : : vsp_id = 0;
1080 : : }
1081 : :
1082 [ # # # # ]: 0 : if (dpaa_intf->vsp_bpid[vsp_id] &&
1083 : : bpid != dpaa_intf->vsp_bpid[vsp_id]) {
1084 : 0 : DPAA_PMD_ERR("Various MPs are assigned to RXQs with same VSP");
1085 : :
1086 : 0 : return -1;
1087 : : }
1088 : :
1089 : : return 0;
1090 : : }
1091 : :
1092 : : static
1093 : 0 : int dpaa_eth_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
1094 : : uint16_t nb_desc,
1095 : : unsigned int socket_id __rte_unused,
1096 : : const struct rte_eth_rxconf *rx_conf,
1097 : : struct rte_mempool *mp)
1098 : : {
1099 : 0 : struct dpaa_if *dpaa_intf = dev->data->dev_private;
1100 : 0 : struct fman_if *fif = dev->process_private;
1101 : 0 : struct qman_fq *rxq = &dpaa_intf->rx_queues[queue_idx];
1102 [ # # ]: 0 : struct qm_mcc_initfq opts = {0};
1103 : : u32 ch_id, flags = 0;
1104 : : int ret, set_push_rxq = false;
1105 : 0 : u32 buffsz = rte_pktmbuf_data_room_size(mp) - RTE_PKTMBUF_HEADROOM;
1106 : : uint32_t max_rx_pktlen;
1107 : :
1108 : 0 : PMD_INIT_FUNC_TRACE();
1109 : :
1110 [ # # ]: 0 : if (queue_idx >= dev->data->nb_rx_queues) {
1111 : 0 : rte_errno = EOVERFLOW;
1112 : 0 : DPAA_PMD_ERR("%p: queue index out of range (%u >= %u)",
1113 : : (void *)dev, queue_idx, dev->data->nb_rx_queues);
1114 : 0 : return -rte_errno;
1115 : : }
1116 : :
1117 : 0 : rxq->nb_desc = UINT16_MAX;
1118 : 0 : rxq->offloads = rx_conf->offloads;
1119 : :
1120 : 0 : DPAA_PMD_INFO("Rx queue setup for queue index: %d fq_id (0x%x)",
1121 : : queue_idx, rxq->fqid);
1122 : :
1123 : : /* Shutdown FQ before configure */
1124 : 0 : qman_shutdown_fq(rxq->fqid);
1125 : :
1126 [ # # ]: 0 : if (!fif->num_profiles) {
1127 [ # # # # ]: 0 : if (dpaa_intf->bp_info && dpaa_intf->bp_info->bp &&
1128 [ # # ]: 0 : dpaa_intf->bp_info->mp != mp) {
1129 : 0 : DPAA_PMD_WARN("Multiple pools on same interface not"
1130 : : " supported");
1131 : 0 : return -EINVAL;
1132 : : }
1133 : : } else {
1134 [ # # ]: 0 : if (dpaa_eth_rx_queue_bp_check(dev, rxq->vsp_id,
1135 : 0 : DPAA_MEMPOOL_TO_POOL_INFO(mp)->bpid)) {
1136 : : return -EINVAL;
1137 : : }
1138 : : }
1139 : :
1140 [ # # # # ]: 0 : if (dpaa_intf->bp_info && dpaa_intf->bp_info->bp &&
1141 [ # # ]: 0 : dpaa_intf->bp_info->mp != mp) {
1142 : 0 : DPAA_PMD_WARN("Multiple pools on same interface not supported");
1143 : 0 : return -EINVAL;
1144 : : }
1145 : :
1146 : 0 : max_rx_pktlen = dev->data->mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN +
1147 : : VLAN_TAG_SIZE;
1148 : : /* Max packet can fit in single buffer */
1149 [ # # ]: 0 : if (max_rx_pktlen <= buffsz) {
1150 : : ;
1151 [ # # ]: 0 : } else if (dev->data->dev_conf.rxmode.offloads &
1152 : : RTE_ETH_RX_OFFLOAD_SCATTER) {
1153 [ # # ]: 0 : if (max_rx_pktlen > buffsz * DPAA_SGT_MAX_ENTRIES) {
1154 : 0 : DPAA_PMD_ERR("Maximum Rx packet size %d too big to fit "
1155 : : "MaxSGlist %d",
1156 : : max_rx_pktlen, buffsz * DPAA_SGT_MAX_ENTRIES);
1157 : 0 : rte_errno = EOVERFLOW;
1158 : 0 : return -rte_errno;
1159 : : }
1160 : : } else {
1161 : 0 : DPAA_PMD_WARN("The requested maximum Rx packet size (%u) is"
1162 : : " larger than a single mbuf (%u) and scattered"
1163 : : " mode has not been requested", max_rx_pktlen, buffsz);
1164 : : }
1165 : :
1166 : 0 : dpaa_intf->bp_info = DPAA_MEMPOOL_TO_POOL_INFO(mp);
1167 : :
1168 : : /* For shared interface, it's done in kernel, skip.*/
1169 [ # # # # : 0 : if (!fif->is_shared_mac && fif->mac_type != fman_offline_internal &&
# # ]
1170 : : fif->mac_type != fman_onic)
1171 : 0 : dpaa_fman_if_pool_setup(dev);
1172 : :
1173 [ # # ]: 0 : if (fif->num_profiles) {
1174 : 0 : int8_t vsp_id = rxq->vsp_id;
1175 : :
1176 [ # # ]: 0 : if (vsp_id >= 0) {
1177 : 0 : ret = dpaa_port_vsp_update(dpaa_intf, fmc_q, vsp_id,
1178 : 0 : DPAA_MEMPOOL_TO_POOL_INFO(mp)->bpid,
1179 : : fif, buffsz + RTE_PKTMBUF_HEADROOM);
1180 [ # # ]: 0 : if (ret) {
1181 : 0 : DPAA_PMD_ERR("dpaa_port_vsp_update failed");
1182 : 0 : return ret;
1183 : : }
1184 : : } else {
1185 : 0 : DPAA_PMD_INFO("Base profile is associated to"
1186 : : " RXQ fqid:%d", rxq->fqid);
1187 [ # # ]: 0 : if (fif->is_shared_mac) {
1188 : 0 : DPAA_PMD_ERR("Fatal: Base profile is associated"
1189 : : " to shared interface on DPDK.");
1190 : 0 : return -EINVAL;
1191 : : }
1192 : 0 : dpaa_intf->vsp_bpid[fif->base_profile_id] =
1193 : 0 : DPAA_MEMPOOL_TO_POOL_INFO(mp)->bpid;
1194 : : }
1195 : : } else {
1196 : 0 : dpaa_intf->vsp_bpid[0] =
1197 : 0 : DPAA_MEMPOOL_TO_POOL_INFO(mp)->bpid;
1198 : : }
1199 : :
1200 : 0 : dpaa_intf->valid = 1;
1201 [ # # ]: 0 : if (fif->mac_type != fman_onic)
1202 : 0 : DPAA_PMD_DEBUG("if:%s sg_on = %d, max_frm =%d", dpaa_intf->name,
1203 : : fman_if_get_sg_enable(fif), max_rx_pktlen);
1204 : : /* checking if push mode only, no error check for now */
1205 [ # # ]: 0 : if (!rxq->is_static)
1206 : 0 : set_push_rxq = dpaa_push_queue_num_update();
1207 [ # # ]: 0 : if (set_push_rxq) {
1208 : : struct qman_portal *qp;
1209 : : int q_fd;
1210 : :
1211 : 0 : opts.we_mask = QM_INITFQ_WE_FQCTRL | QM_INITFQ_WE_CONTEXTA;
1212 : 0 : opts.fqd.fq_ctrl = QM_FQCTRL_AVOIDBLOCK |
1213 : : QM_FQCTRL_CTXASTASHING |
1214 : : QM_FQCTRL_PREFERINCACHE;
1215 : 0 : opts.fqd.context_a.stashing.exclusive = 0;
1216 : : /* In multicore scenario stashing becomes a bottleneck on LS1046.
1217 : : * So do not enable stashing in this case
1218 : : */
1219 [ # # ]: 0 : if (dpaa_soc_ver() != SVR_LS1046A_FAMILY)
1220 : 0 : opts.fqd.context_a.stashing.annotation_cl =
1221 : : DPAA_IF_RX_ANNOTATION_STASH;
1222 : 0 : opts.fqd.context_a.stashing.data_cl = DPAA_IF_RX_DATA_STASH;
1223 : 0 : opts.fqd.context_a.stashing.context_cl =
1224 : : DPAA_IF_RX_CONTEXT_STASH;
1225 : :
1226 : : /*Create a channel and associate given queue with the channel*/
1227 : 0 : qman_alloc_pool_range(&ch_id, 1, 1, 0);
1228 : 0 : rxq->ch_id = (u16)ch_id;
1229 : :
1230 : 0 : opts.we_mask = opts.we_mask | QM_INITFQ_WE_DESTWQ;
1231 : 0 : opts.fqd.dest.channel = rxq->ch_id;
1232 : 0 : opts.fqd.dest.wq = DPAA_IF_RX_PRIORITY;
1233 : : flags = QMAN_INITFQ_FLAG_SCHED;
1234 : :
1235 : : /* Configure tail drop */
1236 [ # # ]: 0 : if (dpaa_intf->cgr_rx) {
1237 : 0 : opts.we_mask |= QM_INITFQ_WE_CGID;
1238 : 0 : opts.fqd.cgid = dpaa_intf->cgr_rx[queue_idx].cgrid;
1239 : 0 : opts.fqd.fq_ctrl |= QM_FQCTRL_CGE;
1240 : : }
1241 : 0 : ret = qman_init_fq(rxq, flags, &opts);
1242 [ # # ]: 0 : if (ret) {
1243 : 0 : DPAA_PMD_ERR("Channel/Q association failed. fqid 0x%x "
1244 : : "ret:%d(%s)", rxq->fqid, ret, strerror(ret));
1245 : 0 : return ret;
1246 : : }
1247 [ # # ]: 0 : if (dpaa_soc_ver() == SVR_LS1043A_FAMILY) {
1248 : 0 : rxq->cb.dqrr_dpdk_pull_cb = dpaa_rx_cb_no_prefetch;
1249 : : } else {
1250 : 0 : rxq->cb.dqrr_dpdk_pull_cb = dpaa_rx_cb;
1251 : 0 : rxq->cb.dqrr_prepare = dpaa_rx_cb_prepare;
1252 : : }
1253 : :
1254 : 0 : rxq->is_static = true;
1255 : :
1256 : : /* Allocate qman specific portals */
1257 : 0 : qp = fsl_qman_fq_portal_create(&q_fd);
1258 [ # # ]: 0 : if (!qp) {
1259 : 0 : DPAA_PMD_ERR("Unable to alloc fq portal");
1260 : 0 : return -EIO;
1261 : : }
1262 : 0 : rxq->qp = qp;
1263 : :
1264 : : /* Set up the device interrupt handler */
1265 [ # # ]: 0 : if (dev->intr_handle == NULL) {
1266 : : struct rte_dpaa_device *dpaa_dev;
1267 : :
1268 : 0 : dpaa_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *dpaa_dev);
1269 : 0 : dev->intr_handle = dpaa_dev->intr_handle;
1270 [ # # ]: 0 : if (rte_intr_vec_list_alloc(dev->intr_handle,
1271 : 0 : NULL, dpaa_push_queue_max_num())) {
1272 : 0 : DPAA_PMD_ERR("intr_vec alloc failed");
1273 : 0 : return -ENOMEM;
1274 : : }
1275 [ # # ]: 0 : if (rte_intr_nb_efd_set(dev->intr_handle,
1276 : 0 : dpaa_push_queue_max_num()))
1277 : 0 : return -rte_errno;
1278 : :
1279 [ # # ]: 0 : if (rte_intr_max_intr_set(dev->intr_handle,
1280 : 0 : dpaa_push_queue_max_num()))
1281 : 0 : return -rte_errno;
1282 : : }
1283 : :
1284 [ # # ]: 0 : if (rte_intr_type_set(dev->intr_handle, RTE_INTR_HANDLE_EXT))
1285 : 0 : return -rte_errno;
1286 : :
1287 [ # # ]: 0 : if (rte_intr_vec_list_index_set(dev->intr_handle,
1288 : : queue_idx, queue_idx + 1))
1289 : 0 : return -rte_errno;
1290 : :
1291 [ # # ]: 0 : if (rte_intr_efds_index_set(dev->intr_handle, queue_idx,
1292 : : q_fd))
1293 : 0 : return -rte_errno;
1294 : :
1295 : 0 : rxq->q_fd = q_fd;
1296 : : }
1297 : 0 : rxq->bp_array = rte_dpaa_bpid_info;
1298 : 0 : dev->data->rx_queues[queue_idx] = rxq;
1299 : :
1300 : : /* configure the CGR size as per the desc size */
1301 [ # # ]: 0 : if (dpaa_intf->cgr_rx) {
1302 : 0 : struct qm_mcc_initcgr cgr_opts = {0};
1303 : :
1304 : 0 : rxq->nb_desc = nb_desc;
1305 : : /* Enable tail drop with cgr on this queue */
1306 : 0 : qm_cgr_cs_thres_set64(&cgr_opts.cgr.cs_thres, nb_desc, 0);
1307 : 0 : ret = qman_modify_cgr(dpaa_intf->cgr_rx, 0, &cgr_opts);
1308 [ # # ]: 0 : if (ret) {
1309 : 0 : DPAA_PMD_WARN(
1310 : : "rx taildrop modify fail on fqid %d (ret=%d)",
1311 : : rxq->fqid, ret);
1312 : : }
1313 : : }
1314 : :
1315 : : /* Enable main queue to receive error packets */
1316 [ # # ]: 0 : if (fif->mac_type != fman_offline_internal &&
1317 [ # # ]: 0 : fif->mac_type != fman_onic &&
1318 [ # # ]: 0 : dpaa_enable_recv_err_pkts && !fif->is_shared_mac) {
1319 : 0 : fman_if_set_err_fqid(fif, rxq->fqid);
1320 : : }
1321 : :
1322 : : return 0;
1323 : : }
1324 : :
1325 : : RTE_EXPORT_INTERNAL_SYMBOL(dpaa_eth_eventq_attach)
1326 : : int
1327 : 0 : dpaa_eth_eventq_attach(const struct rte_eth_dev *dev,
1328 : : int eth_rx_queue_id, u16 ch_id,
1329 : : const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
1330 : : {
1331 : : int ret;
1332 : : u32 flags = 0;
1333 : 0 : struct dpaa_if *dpaa_intf = dev->data->dev_private;
1334 : 0 : struct qman_fq *rxq = &dpaa_intf->rx_queues[eth_rx_queue_id];
1335 : 0 : struct qm_mcc_initfq opts = {0};
1336 : :
1337 [ # # ]: 0 : if (dpaa_push_queue_max_num() > 0) {
1338 : 0 : DPAA_PMD_WARN("PUSH mode q and EVENTDEV are not compatible");
1339 : 0 : DPAA_PMD_WARN("PUSH mode already enabled for first %d queues.",
1340 : : dpaa_push_queue_max_num());
1341 : 0 : DPAA_PMD_WARN("To disable set DPAA_PUSH_QUEUES_NUMBER to 0");
1342 : : }
1343 : :
1344 : 0 : dpaa_poll_queue_default_config(&opts);
1345 : :
1346 [ # # # ]: 0 : switch (queue_conf->ev.sched_type) {
1347 : 0 : case RTE_SCHED_TYPE_ATOMIC:
1348 : 0 : opts.fqd.fq_ctrl |= QM_FQCTRL_HOLDACTIVE;
1349 : : /* Reset FQCTRL_AVOIDBLOCK bit as it is unnecessary
1350 : : * configuration with HOLD_ACTIVE setting
1351 : : */
1352 : 0 : opts.fqd.fq_ctrl &= (~QM_FQCTRL_AVOIDBLOCK);
1353 : 0 : rxq->cb.dqrr_dpdk_cb = dpaa_rx_cb_atomic;
1354 : 0 : break;
1355 : 0 : case RTE_SCHED_TYPE_ORDERED:
1356 : 0 : DPAA_PMD_ERR("Ordered queue schedule type is not supported");
1357 : 0 : return -1;
1358 : 0 : default:
1359 : 0 : opts.fqd.fq_ctrl |= QM_FQCTRL_AVOIDBLOCK;
1360 : 0 : rxq->cb.dqrr_dpdk_cb = dpaa_rx_cb_parallel;
1361 : 0 : break;
1362 : : }
1363 : :
1364 : 0 : opts.we_mask = opts.we_mask | QM_INITFQ_WE_DESTWQ;
1365 : 0 : opts.fqd.dest.channel = ch_id;
1366 : 0 : opts.fqd.dest.wq = queue_conf->ev.priority;
1367 : :
1368 [ # # ]: 0 : if (dpaa_intf->cgr_rx) {
1369 : 0 : opts.we_mask |= QM_INITFQ_WE_CGID;
1370 : 0 : opts.fqd.cgid = dpaa_intf->cgr_rx[eth_rx_queue_id].cgrid;
1371 : 0 : opts.fqd.fq_ctrl |= QM_FQCTRL_CGE;
1372 : : }
1373 : :
1374 : : flags = QMAN_INITFQ_FLAG_SCHED;
1375 : :
1376 : 0 : ret = qman_init_fq(rxq, flags, &opts);
1377 [ # # ]: 0 : if (ret) {
1378 : 0 : DPAA_PMD_ERR("Ev-Channel/Q association failed. fqid 0x%x "
1379 : : "ret:%d(%s)", rxq->fqid, ret, strerror(ret));
1380 : 0 : return ret;
1381 : : }
1382 : :
1383 : : /* copy configuration which needs to be filled during dequeue */
1384 : 0 : memcpy(&rxq->ev, &queue_conf->ev, sizeof(struct rte_event));
1385 : 0 : dev->data->rx_queues[eth_rx_queue_id] = rxq;
1386 : :
1387 : 0 : return ret;
1388 : : }
1389 : :
1390 : : RTE_EXPORT_INTERNAL_SYMBOL(dpaa_eth_eventq_detach)
1391 : : int
1392 : 0 : dpaa_eth_eventq_detach(const struct rte_eth_dev *dev,
1393 : : int eth_rx_queue_id)
1394 : : {
1395 : 0 : struct qm_mcc_initfq opts = {0};
1396 : : int ret;
1397 : : u32 flags = 0;
1398 : 0 : struct dpaa_if *dpaa_intf = dev->data->dev_private;
1399 : 0 : struct qman_fq *rxq = &dpaa_intf->rx_queues[eth_rx_queue_id];
1400 : :
1401 : 0 : qman_retire_fq(rxq, NULL);
1402 : 0 : qman_oos_fq(rxq);
1403 : 0 : ret = qman_init_fq(rxq, flags, &opts);
1404 [ # # ]: 0 : if (ret) {
1405 : 0 : DPAA_PMD_ERR("detach rx fqid %d failed with ret: %d",
1406 : : rxq->fqid, ret);
1407 : : }
1408 : :
1409 : 0 : rxq->cb.dqrr_dpdk_cb = NULL;
1410 : 0 : dev->data->rx_queues[eth_rx_queue_id] = NULL;
1411 : :
1412 : 0 : return 0;
1413 : : }
1414 : :
1415 : : static
1416 : 0 : int dpaa_eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
1417 : : uint16_t nb_desc __rte_unused,
1418 : : unsigned int socket_id __rte_unused,
1419 : : const struct rte_eth_txconf *tx_conf)
1420 : : {
1421 : 0 : struct dpaa_if *dpaa_intf = dev->data->dev_private;
1422 : 0 : struct qman_fq *txq = &dpaa_intf->tx_queues[queue_idx];
1423 : :
1424 : 0 : PMD_INIT_FUNC_TRACE();
1425 : :
1426 : 0 : txq->nb_desc = UINT16_MAX;
1427 : 0 : txq->offloads = tx_conf->offloads;
1428 : :
1429 [ # # ]: 0 : if (queue_idx >= dev->data->nb_tx_queues) {
1430 : 0 : rte_errno = EOVERFLOW;
1431 : 0 : DPAA_PMD_ERR("%p: queue index out of range (%u >= %u)",
1432 : : (void *)dev, queue_idx, dev->data->nb_tx_queues);
1433 : 0 : return -rte_errno;
1434 : : }
1435 : :
1436 : 0 : DPAA_PMD_INFO("Tx queue setup for queue index: %d fq_id (0x%x)",
1437 : : queue_idx, txq->fqid);
1438 : 0 : dev->data->tx_queues[queue_idx] = txq;
1439 : :
1440 : 0 : return 0;
1441 : : }
1442 : :
1443 : : static int
1444 : 0 : dpaa_dev_rx_queue_count(void *rx_queue)
1445 : : {
1446 : : struct qman_fq *rxq = rx_queue;
1447 : 0 : u32 frm_cnt = 0;
1448 : :
1449 : 0 : PMD_INIT_FUNC_TRACE();
1450 : :
1451 [ # # ]: 0 : if (qman_query_fq_frm_cnt(rxq, &frm_cnt) == 0) {
1452 : 0 : DPAA_PMD_DEBUG("RX frame count for q(%p) is %u",
1453 : : rx_queue, frm_cnt);
1454 : : }
1455 : 0 : return frm_cnt;
1456 : : }
1457 : :
1458 : 0 : static int dpaa_link_down(struct rte_eth_dev *dev)
1459 : : {
1460 : 0 : struct fman_if *fif = dev->process_private;
1461 : : struct __fman_if *__fif;
1462 : :
1463 : 0 : PMD_INIT_FUNC_TRACE();
1464 : :
1465 : : __fif = container_of(fif, struct __fman_if, __if);
1466 : :
1467 [ # # ]: 0 : if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC &&
1468 [ # # # # ]: 0 : fif->mac_type != fman_offline_internal &&
1469 : : fif->mac_type != fman_onic)
1470 : 0 : dpaa_update_link_status(__fif->node_name, RTE_ETH_LINK_DOWN);
1471 : : else
1472 : 0 : return dpaa_eth_dev_stop(dev);
1473 : 0 : return 0;
1474 : : }
1475 : :
1476 : 0 : static int dpaa_link_up(struct rte_eth_dev *dev)
1477 : : {
1478 : 0 : struct fman_if *fif = dev->process_private;
1479 : : struct __fman_if *__fif;
1480 : :
1481 : 0 : PMD_INIT_FUNC_TRACE();
1482 : :
1483 : : __fif = container_of(fif, struct __fman_if, __if);
1484 : :
1485 [ # # ]: 0 : if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC &&
1486 [ # # # # ]: 0 : fif->mac_type != fman_offline_internal &&
1487 : : fif->mac_type != fman_onic)
1488 : 0 : dpaa_update_link_status(__fif->node_name, RTE_ETH_LINK_UP);
1489 : : else
1490 : 0 : dpaa_eth_dev_start(dev);
1491 : 0 : return 0;
1492 : : }
1493 : :
1494 : : static int
1495 : 0 : dpaa_flow_ctrl_set(struct rte_eth_dev *dev,
1496 : : struct rte_eth_fc_conf *fc_conf)
1497 : : {
1498 : 0 : struct dpaa_if *dpaa_intf = dev->data->dev_private;
1499 : : struct rte_eth_fc_conf *net_fc;
1500 : 0 : struct fman_if *fm_if = dev->process_private;
1501 : : int ret;
1502 : :
1503 : 0 : PMD_INIT_FUNC_TRACE();
1504 : :
1505 [ # # ]: 0 : if (!(dpaa_intf->fc_conf)) {
1506 : 0 : dpaa_intf->fc_conf = rte_zmalloc(NULL,
1507 : : sizeof(struct rte_eth_fc_conf), MAX_CACHELINE);
1508 [ # # ]: 0 : if (!dpaa_intf->fc_conf) {
1509 : 0 : DPAA_PMD_ERR("unable to save flow control info");
1510 : 0 : return -ENOMEM;
1511 : : }
1512 : : }
1513 : 0 : net_fc = dpaa_intf->fc_conf;
1514 : :
1515 [ # # ]: 0 : if (fc_conf->high_water < fc_conf->low_water) {
1516 : 0 : DPAA_PMD_ERR("Incorrect Flow Control Configuration");
1517 : 0 : return -EINVAL;
1518 : : }
1519 : :
1520 [ # # ]: 0 : if (fc_conf->mode == RTE_ETH_FC_NONE)
1521 : : return 0;
1522 : :
1523 [ # # ]: 0 : if (fc_conf->mode != RTE_ETH_FC_TX_PAUSE &&
1524 : : fc_conf->mode != RTE_ETH_FC_FULL)
1525 : 0 : goto save_fc;
1526 : :
1527 : 0 : ret = fman_if_set_fc_threshold(fm_if,
1528 : : fc_conf->high_water,
1529 : : fc_conf->low_water,
1530 : 0 : dpaa_intf->bp_info->bpid);
1531 [ # # ]: 0 : if (ret) {
1532 : 0 : DPAA_PMD_ERR("Set %s's fc on bpid(%d) err(%d)",
1533 : : dev->data->name, dpaa_intf->bp_info->bpid,
1534 : : ret);
1535 : : }
1536 [ # # ]: 0 : if (fc_conf->pause_time) {
1537 : 0 : ret = fman_if_set_fc_quanta(fm_if, fc_conf->pause_time);
1538 [ # # ]: 0 : if (ret) {
1539 : 0 : DPAA_PMD_ERR("Set %s's fc pause time err(%d)",
1540 : : dev->data->name, ret);
1541 : : }
1542 : : }
1543 : :
1544 : 0 : save_fc:
1545 : : /* Save the information in dpaa device */
1546 : 0 : net_fc->pause_time = fc_conf->pause_time;
1547 : 0 : net_fc->high_water = fc_conf->high_water;
1548 : 0 : net_fc->low_water = fc_conf->low_water;
1549 : 0 : net_fc->send_xon = fc_conf->send_xon;
1550 : 0 : net_fc->mac_ctrl_frame_fwd = fc_conf->mac_ctrl_frame_fwd;
1551 : 0 : net_fc->mode = fc_conf->mode;
1552 : 0 : net_fc->autoneg = fc_conf->autoneg;
1553 : :
1554 : 0 : return 0;
1555 : : }
1556 : :
1557 : : static int
1558 : 0 : dpaa_flow_ctrl_get(struct rte_eth_dev *dev,
1559 : : struct rte_eth_fc_conf *fc_conf)
1560 : : {
1561 : 0 : struct dpaa_if *dpaa_intf = dev->data->dev_private;
1562 : 0 : struct rte_eth_fc_conf *net_fc = dpaa_intf->fc_conf;
1563 : : int ret;
1564 : :
1565 : 0 : PMD_INIT_FUNC_TRACE();
1566 : :
1567 [ # # ]: 0 : if (net_fc) {
1568 : 0 : fc_conf->pause_time = net_fc->pause_time;
1569 : 0 : fc_conf->high_water = net_fc->high_water;
1570 : 0 : fc_conf->low_water = net_fc->low_water;
1571 : 0 : fc_conf->send_xon = net_fc->send_xon;
1572 : 0 : fc_conf->mac_ctrl_frame_fwd = net_fc->mac_ctrl_frame_fwd;
1573 : 0 : fc_conf->mode = net_fc->mode;
1574 : 0 : fc_conf->autoneg = net_fc->autoneg;
1575 : 0 : return 0;
1576 : : }
1577 : 0 : ret = fman_if_get_fc_threshold(dev->process_private);
1578 [ # # ]: 0 : if (ret) {
1579 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
1580 : 0 : fc_conf->pause_time =
1581 : 0 : fman_if_get_fc_quanta(dev->process_private);
1582 : : } else {
1583 : 0 : fc_conf->mode = RTE_ETH_FC_NONE;
1584 : : }
1585 : :
1586 : : return 0;
1587 : : }
1588 : :
1589 : : static int
1590 : 0 : dpaa_dev_add_mac_addr(struct rte_eth_dev *dev,
1591 : : struct rte_ether_addr *addr,
1592 : : uint32_t index,
1593 : : __rte_unused uint32_t pool)
1594 : : {
1595 : : int ret;
1596 : 0 : struct fman_if *fif = dev->process_private;
1597 : :
1598 : 0 : PMD_INIT_FUNC_TRACE();
1599 : :
1600 [ # # ]: 0 : if (fif->mac_type == fman_offline_internal) {
1601 : 0 : DPAA_PMD_DEBUG("Add MAC Address not supported on O/H port");
1602 : 0 : return 0;
1603 : : }
1604 : :
1605 [ # # ]: 0 : if (fif->mac_type == fman_onic) {
1606 : 0 : DPAA_PMD_INFO("Add MAC Address not supported on ONIC port");
1607 : 0 : return 0;
1608 : : }
1609 : :
1610 : 0 : ret = fman_if_add_mac_addr(dev->process_private,
1611 : 0 : addr->addr_bytes, index);
1612 : :
1613 [ # # ]: 0 : if (ret)
1614 : 0 : DPAA_PMD_ERR("Adding the MAC ADDR failed: err = %d", ret);
1615 : : return 0;
1616 : : }
1617 : :
1618 : : static void
1619 : 0 : dpaa_dev_remove_mac_addr(struct rte_eth_dev *dev,
1620 : : uint32_t index)
1621 : : {
1622 : 0 : struct fman_if *fif = dev->process_private;
1623 : :
1624 : 0 : PMD_INIT_FUNC_TRACE();
1625 : :
1626 [ # # ]: 0 : if (fif->mac_type == fman_offline_internal) {
1627 : 0 : DPAA_PMD_DEBUG("Remove MAC Address not supported on O/H port");
1628 : 0 : return;
1629 : : }
1630 : :
1631 [ # # ]: 0 : if (fif->mac_type == fman_onic) {
1632 : 0 : DPAA_PMD_INFO("Remove MAC Address not supported on ONIC port");
1633 : 0 : return;
1634 : : }
1635 : :
1636 : 0 : fman_if_clear_mac_addr(dev->process_private, index);
1637 : : }
1638 : :
1639 : : static int
1640 : 0 : dpaa_dev_set_mac_addr(struct rte_eth_dev *dev,
1641 : : struct rte_ether_addr *addr)
1642 : : {
1643 : : int ret;
1644 : 0 : struct fman_if *fif = dev->process_private;
1645 : :
1646 : 0 : PMD_INIT_FUNC_TRACE();
1647 : :
1648 [ # # ]: 0 : if (fif->mac_type == fman_offline_internal) {
1649 : 0 : DPAA_PMD_DEBUG("Set MAC Address not supported on O/H port");
1650 : 0 : return 0;
1651 : : }
1652 : :
1653 [ # # ]: 0 : if (fif->mac_type == fman_onic) {
1654 : 0 : DPAA_PMD_INFO("Set MAC Address not supported on ONIC port");
1655 : 0 : return 0;
1656 : : }
1657 : :
1658 : 0 : ret = fman_if_add_mac_addr(dev->process_private, addr->addr_bytes, 0);
1659 [ # # ]: 0 : if (ret)
1660 : 0 : DPAA_PMD_ERR("Setting the MAC ADDR failed %d", ret);
1661 : :
1662 : : return ret;
1663 : : }
1664 : :
1665 : : static int
1666 : 0 : dpaa_dev_rss_hash_update(struct rte_eth_dev *dev,
1667 : : struct rte_eth_rss_conf *rss_conf)
1668 : : {
1669 : 0 : struct rte_eth_dev_data *data = dev->data;
1670 : : struct rte_eth_conf *eth_conf = &data->dev_conf;
1671 : : int ret;
1672 : :
1673 : 0 : PMD_INIT_FUNC_TRACE();
1674 : :
1675 [ # # # # ]: 0 : if (!(default_q || fmc_q)) {
1676 : 0 : ret = dpaa_fm_config(dev, rss_conf->rss_hf);
1677 [ # # ]: 0 : if (ret) {
1678 : 0 : DPAA_PMD_ERR("FM port configuration: Failed(%d)", ret);
1679 : 0 : return ret;
1680 : : }
1681 : 0 : eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_conf->rss_hf;
1682 : : } else {
1683 : 0 : DPAA_PMD_ERR("Function not supported");
1684 : 0 : return -ENOTSUP;
1685 : : }
1686 : 0 : return 0;
1687 : : }
1688 : :
1689 : : static int
1690 : 0 : dpaa_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1691 : : struct rte_eth_rss_conf *rss_conf)
1692 : : {
1693 : 0 : struct rte_eth_dev_data *data = dev->data;
1694 : : struct rte_eth_conf *eth_conf = &data->dev_conf;
1695 : :
1696 : : /* dpaa does not support rss_key, so length should be 0*/
1697 : 0 : rss_conf->rss_key_len = 0;
1698 : 0 : rss_conf->rss_hf = eth_conf->rx_adv_conf.rss_conf.rss_hf;
1699 : 0 : return 0;
1700 : : }
1701 : :
1702 : 0 : static int dpaa_dev_queue_intr_enable(struct rte_eth_dev *dev,
1703 : : uint16_t queue_id)
1704 : : {
1705 : 0 : struct dpaa_if *dpaa_intf = dev->data->dev_private;
1706 : 0 : struct qman_fq *rxq = &dpaa_intf->rx_queues[queue_id];
1707 : :
1708 [ # # ]: 0 : if (!rxq->is_static)
1709 : : return -EINVAL;
1710 : :
1711 : 0 : return qman_fq_portal_irqsource_add(rxq->qp, QM_PIRQ_DQRI);
1712 : : }
1713 : :
1714 : 0 : static int dpaa_dev_queue_intr_disable(struct rte_eth_dev *dev,
1715 : : uint16_t queue_id)
1716 : : {
1717 : 0 : struct dpaa_if *dpaa_intf = dev->data->dev_private;
1718 : 0 : struct qman_fq *rxq = &dpaa_intf->rx_queues[queue_id];
1719 : : uint32_t temp;
1720 : : ssize_t temp1;
1721 : :
1722 [ # # ]: 0 : if (!rxq->is_static)
1723 : : return -EINVAL;
1724 : :
1725 : 0 : qman_fq_portal_irqsource_remove(rxq->qp, ~0);
1726 : :
1727 : 0 : temp1 = read(rxq->q_fd, &temp, sizeof(temp));
1728 [ # # ]: 0 : if (temp1 != sizeof(temp))
1729 : 0 : DPAA_PMD_DEBUG("read did not return anything");
1730 : :
1731 : 0 : qman_fq_portal_thread_irq(rxq->qp);
1732 : :
1733 : 0 : return 0;
1734 : : }
1735 : :
1736 : : static void
1737 : 0 : dpaa_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
1738 : : struct rte_eth_rxq_info *qinfo)
1739 : : {
1740 : 0 : struct dpaa_if *dpaa_intf = dev->data->dev_private;
1741 : : struct qman_fq *rxq;
1742 : : int ret;
1743 : :
1744 : 0 : rxq = dev->data->rx_queues[queue_id];
1745 : :
1746 : 0 : qinfo->mp = dpaa_intf->bp_info->mp;
1747 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
1748 : 0 : qinfo->nb_desc = rxq->nb_desc;
1749 : :
1750 : : /* Report the HW Rx buffer length to user */
1751 : 0 : ret = fman_if_get_maxfrm(dev->process_private);
1752 [ # # ]: 0 : if (ret > 0)
1753 : 0 : qinfo->rx_buf_size = ret;
1754 : :
1755 : 0 : qinfo->conf.rx_free_thresh = 1;
1756 : 0 : qinfo->conf.rx_drop_en = 1;
1757 : 0 : qinfo->conf.rx_deferred_start = 0;
1758 : 0 : qinfo->conf.offloads = rxq->offloads;
1759 : 0 : }
1760 : :
1761 : : static void
1762 : 0 : dpaa_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
1763 : : struct rte_eth_txq_info *qinfo)
1764 : : {
1765 : : struct qman_fq *txq;
1766 : :
1767 : 0 : txq = dev->data->tx_queues[queue_id];
1768 : :
1769 : 0 : qinfo->nb_desc = txq->nb_desc;
1770 : 0 : qinfo->conf.tx_thresh.pthresh = 0;
1771 : 0 : qinfo->conf.tx_thresh.hthresh = 0;
1772 : 0 : qinfo->conf.tx_thresh.wthresh = 0;
1773 : :
1774 : 0 : qinfo->conf.tx_free_thresh = 0;
1775 : 0 : qinfo->conf.tx_rs_thresh = 0;
1776 : 0 : qinfo->conf.offloads = txq->offloads;
1777 : 0 : qinfo->conf.tx_deferred_start = 0;
1778 : 0 : }
1779 : :
1780 : : static struct eth_dev_ops dpaa_devops = {
1781 : : .dev_configure = dpaa_eth_dev_configure,
1782 : : .dev_start = dpaa_eth_dev_start,
1783 : : .dev_stop = dpaa_eth_dev_stop,
1784 : : .dev_close = dpaa_eth_dev_close,
1785 : : .dev_infos_get = dpaa_eth_dev_info,
1786 : : .dev_supported_ptypes_get = dpaa_supported_ptypes_get,
1787 : :
1788 : : .rx_queue_setup = dpaa_eth_rx_queue_setup,
1789 : : .tx_queue_setup = dpaa_eth_tx_queue_setup,
1790 : : .rx_burst_mode_get = dpaa_dev_rx_burst_mode_get,
1791 : : .tx_burst_mode_get = dpaa_dev_tx_burst_mode_get,
1792 : : .rxq_info_get = dpaa_rxq_info_get,
1793 : : .txq_info_get = dpaa_txq_info_get,
1794 : :
1795 : : .flow_ctrl_get = dpaa_flow_ctrl_get,
1796 : : .flow_ctrl_set = dpaa_flow_ctrl_set,
1797 : :
1798 : : .link_update = dpaa_eth_link_update,
1799 : : .stats_get = dpaa_eth_stats_get,
1800 : : .xstats_get = dpaa_dev_xstats_get,
1801 : : .xstats_get_by_id = dpaa_xstats_get_by_id,
1802 : : .xstats_get_names_by_id = dpaa_xstats_get_names_by_id,
1803 : : .xstats_get_names = dpaa_xstats_get_names,
1804 : : .xstats_reset = dpaa_eth_stats_reset,
1805 : : .stats_reset = dpaa_eth_stats_reset,
1806 : : .promiscuous_enable = dpaa_eth_promiscuous_enable,
1807 : : .promiscuous_disable = dpaa_eth_promiscuous_disable,
1808 : : .allmulticast_enable = dpaa_eth_multicast_enable,
1809 : : .allmulticast_disable = dpaa_eth_multicast_disable,
1810 : : .mtu_set = dpaa_mtu_set,
1811 : : .dev_set_link_down = dpaa_link_down,
1812 : : .dev_set_link_up = dpaa_link_up,
1813 : : .mac_addr_add = dpaa_dev_add_mac_addr,
1814 : : .mac_addr_remove = dpaa_dev_remove_mac_addr,
1815 : : .mac_addr_set = dpaa_dev_set_mac_addr,
1816 : :
1817 : : .fw_version_get = dpaa_fw_version_get,
1818 : :
1819 : : .rx_queue_intr_enable = dpaa_dev_queue_intr_enable,
1820 : : .rx_queue_intr_disable = dpaa_dev_queue_intr_disable,
1821 : : .rss_hash_update = dpaa_dev_rss_hash_update,
1822 : : .rss_hash_conf_get = dpaa_dev_rss_hash_conf_get,
1823 : : .timesync_enable = dpaa_timesync_enable,
1824 : : .timesync_disable = dpaa_timesync_disable,
1825 : : .timesync_read_time = dpaa_timesync_read_time,
1826 : : .timesync_write_time = dpaa_timesync_write_time,
1827 : : .timesync_adjust_time = dpaa_timesync_adjust_time,
1828 : : .timesync_read_rx_timestamp = dpaa_timesync_read_rx_timestamp,
1829 : : .timesync_read_tx_timestamp = dpaa_timesync_read_tx_timestamp,
1830 : : };
1831 : :
1832 : : static bool
1833 : : is_device_supported(struct rte_eth_dev *dev, struct rte_dpaa_driver *drv)
1834 : : {
1835 [ # # ]: 0 : if (strcmp(dev->device->driver->name,
1836 : : drv->driver.name))
1837 : : return false;
1838 : :
1839 : : return true;
1840 : : }
1841 : :
1842 : : static bool
1843 : : is_dpaa_supported(struct rte_eth_dev *dev)
1844 : : {
1845 : : return is_device_supported(dev, &rte_dpaa_pmd);
1846 : : }
1847 : :
1848 : : RTE_EXPORT_SYMBOL(rte_pmd_dpaa_set_tx_loopback)
1849 : : int
1850 : 0 : rte_pmd_dpaa_set_tx_loopback(uint16_t port, uint8_t on)
1851 : : {
1852 : : struct rte_eth_dev *dev;
1853 : :
1854 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1855 : :
1856 : : dev = &rte_eth_devices[port];
1857 : :
1858 : : if (!is_dpaa_supported(dev))
1859 : : return -ENOTSUP;
1860 : :
1861 [ # # ]: 0 : if (on)
1862 : 0 : fman_if_loopback_enable(dev->process_private);
1863 : : else
1864 : 0 : fman_if_loopback_disable(dev->process_private);
1865 : :
1866 : : return 0;
1867 : : }
1868 : :
1869 : 0 : static int dpaa_fc_set_default(struct dpaa_if *dpaa_intf,
1870 : : struct fman_if *fman_intf)
1871 : : {
1872 : : struct rte_eth_fc_conf *fc_conf;
1873 : : int ret;
1874 : :
1875 : 0 : PMD_INIT_FUNC_TRACE();
1876 : :
1877 [ # # ]: 0 : if (!(dpaa_intf->fc_conf)) {
1878 : 0 : dpaa_intf->fc_conf = rte_zmalloc(NULL,
1879 : : sizeof(struct rte_eth_fc_conf), MAX_CACHELINE);
1880 [ # # ]: 0 : if (!dpaa_intf->fc_conf) {
1881 : 0 : DPAA_PMD_ERR("unable to save flow control info");
1882 : 0 : return -ENOMEM;
1883 : : }
1884 : : }
1885 : 0 : fc_conf = dpaa_intf->fc_conf;
1886 : 0 : ret = fman_if_get_fc_threshold(fman_intf);
1887 [ # # ]: 0 : if (ret) {
1888 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
1889 : 0 : fc_conf->pause_time = fman_if_get_fc_quanta(fman_intf);
1890 : : } else {
1891 : 0 : fc_conf->mode = RTE_ETH_FC_NONE;
1892 : : }
1893 : :
1894 : : return 0;
1895 : : }
1896 : :
1897 : : /* Initialise an Rx FQ */
1898 : 0 : static int dpaa_rx_queue_init(struct qman_fq *fq, struct qman_cgr *cgr_rx,
1899 : : uint32_t fqid)
1900 : : {
1901 : 0 : struct qm_mcc_initfq opts = {0};
1902 : : int ret;
1903 : : u32 flags = QMAN_FQ_FLAG_NO_ENQUEUE;
1904 : 0 : struct qm_mcc_initcgr cgr_opts = {
1905 : : .we_mask = QM_CGR_WE_CS_THRES |
1906 : : QM_CGR_WE_CSTD_EN |
1907 : : QM_CGR_WE_MODE,
1908 : : .cgr = {
1909 : : .cstd_en = QM_CGR_EN,
1910 : : .mode = QMAN_CGR_MODE_FRAME
1911 : : }
1912 : : };
1913 : :
1914 [ # # # # ]: 0 : if (fmc_q || default_q) {
1915 : : ret = qman_reserve_fqid(fqid);
1916 [ # # ]: 0 : if (ret) {
1917 : 0 : DPAA_PMD_ERR("reserve rx fqid 0x%x failed, ret: %d",
1918 : : fqid, ret);
1919 : 0 : return -EINVAL;
1920 : : }
1921 : : }
1922 : :
1923 : 0 : DPAA_PMD_DEBUG("creating rx fq %p, fqid 0x%x", fq, fqid);
1924 : 0 : ret = qman_create_fq(fqid, flags, fq);
1925 [ # # ]: 0 : if (ret) {
1926 : 0 : DPAA_PMD_ERR("create rx fqid 0x%x failed with ret: %d",
1927 : : fqid, ret);
1928 : 0 : return ret;
1929 : : }
1930 : 0 : fq->is_static = false;
1931 : :
1932 : 0 : dpaa_poll_queue_default_config(&opts);
1933 : :
1934 [ # # ]: 0 : if (cgr_rx) {
1935 : : /* Enable tail drop with cgr on this queue */
1936 : 0 : qm_cgr_cs_thres_set64(&cgr_opts.cgr.cs_thres, td_threshold, 0);
1937 : 0 : cgr_rx->cb = NULL;
1938 : 0 : ret = qman_create_cgr(cgr_rx, QMAN_CGR_FLAG_USE_INIT,
1939 : : &cgr_opts);
1940 [ # # ]: 0 : if (ret) {
1941 : 0 : DPAA_PMD_WARN(
1942 : : "rx taildrop init fail on rx fqid 0x%x(ret=%d)",
1943 : : fq->fqid, ret);
1944 : 0 : goto without_cgr;
1945 : : }
1946 : 0 : opts.we_mask |= QM_INITFQ_WE_CGID;
1947 : 0 : opts.fqd.cgid = cgr_rx->cgrid;
1948 : 0 : opts.fqd.fq_ctrl |= QM_FQCTRL_CGE;
1949 : : }
1950 : 0 : without_cgr:
1951 : 0 : ret = qman_init_fq(fq, 0, &opts);
1952 [ # # ]: 0 : if (ret)
1953 : 0 : DPAA_PMD_ERR("init rx fqid 0x%x failed with ret:%d", fqid, ret);
1954 : : return ret;
1955 : : }
1956 : :
1957 : 0 : uint8_t fm_default_vsp_id(struct fman_if *fif)
1958 : : {
1959 : : /* Avoid being same as base profile which could be used
1960 : : * for kernel interface of shared mac.
1961 : : */
1962 [ # # ]: 0 : if (fif->base_profile_id)
1963 : : return 0;
1964 : : else
1965 : 0 : return DPAA_DEFAULT_RXQ_VSP_ID;
1966 : : }
1967 : :
1968 : : /* Initialise a Tx FQ */
1969 : 0 : static int dpaa_tx_queue_init(struct qman_fq *fq,
1970 : : struct fman_if *fman_intf,
1971 : : struct qman_cgr *cgr_tx)
1972 : : {
1973 : 0 : struct qm_mcc_initfq opts = {0};
1974 : 0 : struct qm_mcc_initcgr cgr_opts = {
1975 : : .we_mask = QM_CGR_WE_CS_THRES |
1976 : : QM_CGR_WE_CSTD_EN |
1977 : : QM_CGR_WE_MODE,
1978 : : .cgr = {
1979 : : .cstd_en = QM_CGR_EN,
1980 : : .mode = QMAN_CGR_MODE_FRAME
1981 : : }
1982 : : };
1983 : : int ret;
1984 : 0 : struct dpaa_if *dpaa_intf = fq->dpaa_intf;
1985 : :
1986 : 0 : ret = qman_create_fq(0, QMAN_FQ_FLAG_DYNAMIC_FQID |
1987 : : QMAN_FQ_FLAG_TO_DCPORTAL, fq);
1988 [ # # ]: 0 : if (ret) {
1989 : 0 : DPAA_PMD_ERR("create tx fq failed with ret: %d", ret);
1990 : 0 : return ret;
1991 : : }
1992 : 0 : opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL |
1993 : : QM_INITFQ_WE_CONTEXTB | QM_INITFQ_WE_CONTEXTA;
1994 : 0 : opts.fqd.dest.channel = fman_intf->tx_channel_id;
1995 : 0 : opts.fqd.dest.wq = DPAA_IF_TX_PRIORITY;
1996 : 0 : opts.fqd.fq_ctrl = QM_FQCTRL_PREFERINCACHE;
1997 : 0 : opts.fqd.context_b = 0;
1998 [ # # ]: 0 : if (dpaa_intf->ts_enable) {
1999 : 0 : opts.fqd.context_a.lo = 0;
2000 : 0 : opts.fqd.context_a.hi =
2001 : 0 : fman_intf->fman->dealloc_bufs_mask_hi;
2002 : : } else {
2003 : : /* no tx-confirmation */
2004 : 0 : opts.fqd.context_a.lo =
2005 : 0 : fman_intf->fman->dealloc_bufs_mask_lo;
2006 : 0 : opts.fqd.context_a.hi =
2007 : 0 : DPAA_FQD_CTX_A_OVERRIDE_FQ |
2008 : 0 : fman_intf->fman->dealloc_bufs_mask_hi;
2009 : : }
2010 : :
2011 [ # # ]: 0 : if (fman_intf->fman->ip_rev >= FMAN_V3)
2012 : : /* Set B0V bit in contextA to set ASPID to 0 */
2013 : 0 : opts.fqd.context_a.hi |= DPAA_FQD_CTX_A_B0_FIELD_VALID;
2014 : :
2015 [ # # ]: 0 : if (fman_intf->mac_type == fman_offline_internal ||
2016 : : fman_intf->mac_type == fman_onic) {
2017 : 0 : opts.fqd.context_a.lo |= DPAA_FQD_CTX_A2_VSPE_BIT;
2018 : 0 : opts.fqd.context_b = fm_default_vsp_id(fman_intf) <<
2019 : : DPAA_FQD_CTX_B_SHIFT_BITS;
2020 : : }
2021 : :
2022 : 0 : DPAA_PMD_DEBUG("init tx fq %p, fqid 0x%x", fq, fq->fqid);
2023 : :
2024 [ # # ]: 0 : if (cgr_tx) {
2025 : : /* Enable tail drop with cgr on this queue */
2026 : 0 : qm_cgr_cs_thres_set64(&cgr_opts.cgr.cs_thres,
2027 : : td_tx_threshold, 0);
2028 : 0 : cgr_tx->cb = NULL;
2029 : 0 : ret = qman_create_cgr(cgr_tx, QMAN_CGR_FLAG_USE_INIT,
2030 : : &cgr_opts);
2031 [ # # ]: 0 : if (ret) {
2032 : 0 : DPAA_PMD_WARN(
2033 : : "rx taildrop init fail on rx fqid 0x%x(ret=%d)",
2034 : : fq->fqid, ret);
2035 : 0 : goto without_cgr;
2036 : : }
2037 : 0 : opts.we_mask |= QM_INITFQ_WE_CGID;
2038 : 0 : opts.fqd.cgid = cgr_tx->cgrid;
2039 : 0 : opts.fqd.fq_ctrl |= QM_FQCTRL_CGE;
2040 : 0 : DPAA_PMD_DEBUG("Tx FQ tail drop enabled, threshold = %d",
2041 : : td_tx_threshold);
2042 : : }
2043 : 0 : without_cgr:
2044 : 0 : ret = qman_init_fq(fq, QMAN_INITFQ_FLAG_SCHED, &opts);
2045 [ # # ]: 0 : if (ret)
2046 : 0 : DPAA_PMD_ERR("init tx fqid 0x%x failed %d", fq->fqid, ret);
2047 : : return ret;
2048 : : }
2049 : :
2050 : : int
2051 : 0 : dpaa_tx_conf_queue_init(struct qman_fq *fq)
2052 : : {
2053 : 0 : struct qm_mcc_initfq opts = {0};
2054 : : int ret;
2055 : :
2056 : 0 : PMD_INIT_FUNC_TRACE();
2057 : :
2058 : 0 : ret = qman_create_fq(0, QMAN_FQ_FLAG_DYNAMIC_FQID, fq);
2059 [ # # ]: 0 : if (ret) {
2060 : 0 : DPAA_PMD_ERR("create Tx_conf failed with ret: %d", ret);
2061 : 0 : return ret;
2062 : : }
2063 : :
2064 : 0 : opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL;
2065 : 0 : opts.fqd.dest.wq = DPAA_IF_DEBUG_PRIORITY;
2066 : 0 : ret = qman_init_fq(fq, 0, &opts);
2067 [ # # ]: 0 : if (ret)
2068 : 0 : DPAA_PMD_ERR("init Tx_conf fqid %d failed with ret: %d",
2069 : : fq->fqid, ret);
2070 : : return ret;
2071 : : }
2072 : :
2073 : : #if defined(RTE_LIBRTE_DPAA_DEBUG_DRIVER)
2074 : : /* Initialise a DEBUG FQ ([rt]x_error, rx_default) */
2075 : : static int dpaa_def_queue_init(struct qman_fq *fq, uint32_t fqid)
2076 : : {
2077 : : struct qm_mcc_initfq opts = {0};
2078 : : int ret;
2079 : :
2080 : : PMD_INIT_FUNC_TRACE();
2081 : :
2082 : : ret = qman_reserve_fqid(fqid);
2083 : : if (ret) {
2084 : : DPAA_PMD_ERR("Reserve fqid %d failed with ret: %d",
2085 : : fqid, ret);
2086 : : return -EINVAL;
2087 : : }
2088 : : /* "map" this Rx FQ to one of the interfaces Tx FQID */
2089 : : DPAA_PMD_DEBUG("Creating fq %p, fqid %d", fq, fqid);
2090 : : ret = qman_create_fq(fqid, QMAN_FQ_FLAG_NO_ENQUEUE, fq);
2091 : : if (ret) {
2092 : : DPAA_PMD_ERR("create fqid %d failed with ret: %d",
2093 : : fqid, ret);
2094 : : return ret;
2095 : : }
2096 : : opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL;
2097 : : opts.fqd.dest.wq = DPAA_IF_DEBUG_PRIORITY;
2098 : : ret = qman_init_fq(fq, 0, &opts);
2099 : : if (ret)
2100 : : DPAA_PMD_ERR("init fqid %d failed with ret: %d",
2101 : : fqid, ret);
2102 : : return ret;
2103 : : }
2104 : : #endif
2105 : :
2106 : : /* Initialise a network interface */
2107 : : static int
2108 : 0 : dpaa_dev_init_secondary(struct rte_eth_dev *eth_dev)
2109 : : {
2110 : : struct rte_dpaa_device *dpaa_device;
2111 : : struct fm_eth_port_cfg *cfg;
2112 : : struct dpaa_if *dpaa_intf;
2113 : : struct fman_if *fman_intf;
2114 : : int dev_id;
2115 : :
2116 : 0 : PMD_INIT_FUNC_TRACE();
2117 : :
2118 : 0 : dpaa_device = RTE_CLASS_TO_BUS_DEVICE(eth_dev, *dpaa_device);
2119 : 0 : dev_id = dpaa_device->id.dev_id;
2120 : 0 : cfg = dpaa_get_eth_port_cfg(dev_id);
2121 : 0 : fman_intf = cfg->fman_if;
2122 : 0 : eth_dev->process_private = fman_intf;
2123 : :
2124 : : /* Plugging of UCODE burst API not supported in Secondary */
2125 : 0 : dpaa_intf = eth_dev->data->dev_private;
2126 : 0 : eth_dev->rx_pkt_burst = dpaa_eth_queue_rx;
2127 [ # # ]: 0 : if (dpaa_intf->cgr_tx)
2128 : 0 : eth_dev->tx_pkt_burst = dpaa_eth_queue_tx_slow;
2129 : : else
2130 : 0 : eth_dev->tx_pkt_burst = dpaa_eth_queue_tx;
2131 : : #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
2132 : 0 : qman_set_fq_lookup_table(
2133 : 0 : dpaa_intf->rx_queues->qman_fq_lookup_table);
2134 : : #endif
2135 : :
2136 : 0 : return 0;
2137 : : }
2138 : :
2139 : : #ifdef RTE_LIBRTE_DPAA_DEBUG_DRIVER
2140 : : static int
2141 : : dpaa_error_queue_init(struct dpaa_if *dpaa_intf,
2142 : : struct fman_if *fman_intf)
2143 : : {
2144 : : int i, ret;
2145 : : struct qman_fq *err_queues = dpaa_intf->debug_queues;
2146 : : uint32_t err_fqid = 0;
2147 : :
2148 : : if (fman_intf->is_shared_mac) {
2149 : : DPAA_PMD_DEBUG("Shared MAC's err queues are handled in kernel");
2150 : : return 0;
2151 : : }
2152 : :
2153 : : for (i = 0; i < DPAA_DEBUG_FQ_MAX_NUM; i++) {
2154 : : if (i == DPAA_DEBUG_FQ_RX_ERROR)
2155 : : err_fqid = fman_intf->fqid_rx_err;
2156 : : else if (i == DPAA_DEBUG_FQ_TX_ERROR)
2157 : : err_fqid = fman_intf->fqid_tx_err;
2158 : : else
2159 : : continue;
2160 : : ret = dpaa_def_queue_init(&err_queues[i], err_fqid);
2161 : : if (ret) {
2162 : : DPAA_PMD_ERR("DPAA %s ERROR queue init failed!",
2163 : : i == DPAA_DEBUG_FQ_RX_ERROR ?
2164 : : "RX" : "TX");
2165 : : return ret;
2166 : : }
2167 : : err_queues[i].dpaa_intf = dpaa_intf;
2168 : : }
2169 : :
2170 : : return 0;
2171 : : }
2172 : : #endif
2173 : :
2174 : : static int
2175 : 0 : check_devargs_handler(__rte_unused const char *key, const char *value,
2176 : : __rte_unused void *opaque)
2177 : : {
2178 [ # # ]: 0 : if (strcmp(value, "1"))
2179 : 0 : return -1;
2180 : :
2181 : : return 0;
2182 : : }
2183 : :
2184 : : static int
2185 : 0 : dpaa_get_devargs(struct rte_devargs *devargs, const char *key)
2186 : : {
2187 : : struct rte_kvargs *kvlist;
2188 : :
2189 [ # # ]: 0 : if (!devargs)
2190 : : return 0;
2191 : :
2192 : 0 : kvlist = rte_kvargs_parse(devargs->args, NULL);
2193 [ # # ]: 0 : if (!kvlist)
2194 : : return 0;
2195 : :
2196 [ # # ]: 0 : if (!rte_kvargs_count(kvlist, key)) {
2197 : 0 : rte_kvargs_free(kvlist);
2198 : 0 : return 0;
2199 : : }
2200 : :
2201 [ # # ]: 0 : if (rte_kvargs_process(kvlist, key,
2202 : : check_devargs_handler, NULL) < 0) {
2203 : 0 : rte_kvargs_free(kvlist);
2204 : 0 : return 0;
2205 : : }
2206 : 0 : rte_kvargs_free(kvlist);
2207 : :
2208 : 0 : return 1;
2209 : : }
2210 : :
2211 : : /* Initialise a network interface */
2212 : : static int
2213 : 0 : dpaa_dev_init(struct rte_eth_dev *eth_dev)
2214 : : {
2215 : : int num_rx_fqs, fqid;
2216 : : int loop, ret = 0;
2217 : : int dev_id;
2218 : : struct rte_dpaa_device *dpaa_device;
2219 : : struct dpaa_if *dpaa_intf;
2220 : : struct fm_eth_port_cfg *cfg;
2221 : : struct fman_if *fman_intf;
2222 : : struct fman_if_bpool *bp, *tmp_bp;
2223 : : uint32_t cgrid[DPAA_MAX_NUM_PCD_QUEUES];
2224 : : uint32_t cgrid_tx[MAX_DPAA_CORES];
2225 : : uint32_t dev_rx_fqids[DPAA_MAX_NUM_PCD_QUEUES];
2226 : : int8_t dev_vspids[DPAA_MAX_NUM_PCD_QUEUES];
2227 : : int8_t vsp_id = -1;
2228 : 0 : struct rte_device *dev = eth_dev->device;
2229 : : #ifdef RTE_LIBRTE_DPAA_DEBUG_DRIVER
2230 : : char *penv;
2231 : : #endif
2232 : :
2233 : 0 : PMD_INIT_FUNC_TRACE();
2234 : :
2235 : 0 : dpaa_device = RTE_CLASS_TO_BUS_DEVICE(eth_dev, *dpaa_device);
2236 : 0 : dev_id = dpaa_device->id.dev_id;
2237 : 0 : dpaa_intf = eth_dev->data->dev_private;
2238 : 0 : cfg = dpaa_get_eth_port_cfg(dev_id);
2239 : 0 : fman_intf = cfg->fman_if;
2240 : :
2241 : 0 : dpaa_intf->name = dpaa_device->name;
2242 : :
2243 : : /* save fman_if & cfg in the interface structure */
2244 : 0 : eth_dev->process_private = fman_intf;
2245 : 0 : dpaa_intf->ifid = dev_id;
2246 : 0 : dpaa_intf->cfg = cfg;
2247 : :
2248 [ # # ]: 0 : if (dpaa_get_devargs(dev->devargs, DRIVER_RECV_ERR_PKTS))
2249 : 0 : dpaa_enable_recv_err_pkts = 1;
2250 : :
2251 : : memset((char *)dev_rx_fqids, 0,
2252 : : sizeof(uint32_t) * DPAA_MAX_NUM_PCD_QUEUES);
2253 : :
2254 : : memset(dev_vspids, -1, DPAA_MAX_NUM_PCD_QUEUES);
2255 : :
2256 : : /* Initialize Rx FQ's */
2257 [ # # ]: 0 : if (default_q) {
2258 : : num_rx_fqs = DPAA_DEFAULT_NUM_PCD_QUEUES;
2259 [ # # ]: 0 : } else if (fmc_q) {
2260 : 0 : num_rx_fqs = dpaa_port_fmc_init(fman_intf, dev_rx_fqids,
2261 : : dev_vspids,
2262 : : DPAA_MAX_NUM_PCD_QUEUES);
2263 [ # # ]: 0 : if (num_rx_fqs < 0) {
2264 : 0 : DPAA_PMD_ERR("%s FMC initializes failed!",
2265 : : dpaa_intf->name);
2266 : 0 : goto free_rx;
2267 : : }
2268 [ # # ]: 0 : if (!num_rx_fqs) {
2269 [ # # ]: 0 : if (fman_intf->mac_type == fman_offline_internal ||
2270 : : fman_intf->mac_type == fman_onic) {
2271 : : ret = -ENODEV;
2272 : 0 : goto free_rx;
2273 : : }
2274 : 0 : DPAA_PMD_WARN("%s is not configured by FMC.",
2275 : : dpaa_intf->name);
2276 : : }
2277 : : } else {
2278 : : /* FMCLESS mode, load balance to multiple cores.*/
2279 : 0 : num_rx_fqs = rte_lcore_count();
2280 : : }
2281 : :
2282 : : /* Each device can not have more than DPAA_MAX_NUM_PCD_QUEUES RX
2283 : : * queues.
2284 : : */
2285 [ # # ]: 0 : if (num_rx_fqs > DPAA_MAX_NUM_PCD_QUEUES) {
2286 : 0 : DPAA_PMD_ERR("Invalid number of RX queues(%d)", num_rx_fqs);
2287 : 0 : return -EINVAL;
2288 : : }
2289 : :
2290 [ # # ]: 0 : if (num_rx_fqs > 0) {
2291 : 0 : dpaa_intf->rx_queues = rte_zmalloc(NULL,
2292 : : sizeof(struct qman_fq) * num_rx_fqs, MAX_CACHELINE);
2293 [ # # ]: 0 : if (!dpaa_intf->rx_queues) {
2294 : 0 : DPAA_PMD_ERR("Failed to alloc mem for RX queues");
2295 : 0 : return -ENOMEM;
2296 : : }
2297 : : } else {
2298 : 0 : dpaa_intf->rx_queues = NULL;
2299 : : }
2300 : :
2301 : : memset(cgrid, 0, sizeof(cgrid));
2302 : : memset(cgrid_tx, 0, sizeof(cgrid_tx));
2303 : :
2304 : : /* if DPAA_TX_TAILDROP_THRESHOLD is set, use that value; if 0, it means
2305 : : * Tx tail drop is disabled.
2306 : : */
2307 [ # # ]: 0 : if (getenv("DPAA_TX_TAILDROP_THRESHOLD")) {
2308 : 0 : td_tx_threshold = atoi(getenv("DPAA_TX_TAILDROP_THRESHOLD"));
2309 : 0 : DPAA_PMD_DEBUG("Tail drop threshold env configured: %u",
2310 : : td_tx_threshold);
2311 : : /* if a very large value is being configured */
2312 [ # # ]: 0 : if (td_tx_threshold > UINT16_MAX)
2313 : 0 : td_tx_threshold = CGR_RX_PERFQ_THRESH;
2314 : : }
2315 : :
2316 : : #ifdef RTE_LIBRTE_DPAA_DEBUG_DRIVER
2317 : : penv = getenv("DPAA_DISPLAY_FRAME_AND_PARSER_RESULT");
2318 : : if (penv)
2319 : : dpaa_force_display_frame_set(atoi(penv));
2320 : : #endif
2321 : :
2322 : : /* If congestion control is enabled globally*/
2323 [ # # # # ]: 0 : if (num_rx_fqs > 0 && td_threshold) {
2324 : 0 : dpaa_intf->cgr_rx = rte_zmalloc(NULL,
2325 : : sizeof(struct qman_cgr) * num_rx_fqs, MAX_CACHELINE);
2326 [ # # ]: 0 : if (!dpaa_intf->cgr_rx) {
2327 : 0 : DPAA_PMD_ERR("Failed to alloc mem for cgr_rx");
2328 : : ret = -ENOMEM;
2329 : 0 : goto free_rx;
2330 : : }
2331 : :
2332 : 0 : ret = qman_alloc_cgrid_range(&cgrid[0], num_rx_fqs, 1, 0);
2333 [ # # ]: 0 : if (ret != num_rx_fqs) {
2334 : 0 : DPAA_PMD_WARN("insufficient CGRIDs available");
2335 : : ret = -EINVAL;
2336 : 0 : goto free_rx;
2337 : : }
2338 : : } else {
2339 : 0 : dpaa_intf->cgr_rx = NULL;
2340 : : }
2341 : :
2342 [ # # # # ]: 0 : if (!fmc_q && !default_q) {
2343 : 0 : ret = qman_alloc_fqid_range(dev_rx_fqids, num_rx_fqs,
2344 : : num_rx_fqs, 0);
2345 [ # # ]: 0 : if (ret < 0) {
2346 : 0 : DPAA_PMD_ERR("Failed to alloc rx fqid's");
2347 : 0 : goto free_rx;
2348 : : }
2349 : : }
2350 : :
2351 [ # # ]: 0 : for (loop = 0; loop < num_rx_fqs; loop++) {
2352 [ # # ]: 0 : if (default_q)
2353 : 0 : fqid = cfg->rx_def;
2354 : : else
2355 : 0 : fqid = dev_rx_fqids[loop];
2356 : :
2357 : 0 : vsp_id = dev_vspids[loop];
2358 : :
2359 [ # # ]: 0 : if (dpaa_intf->cgr_rx)
2360 : 0 : dpaa_intf->cgr_rx[loop].cgrid = cgrid[loop];
2361 : :
2362 [ # # ]: 0 : ret = dpaa_rx_queue_init(&dpaa_intf->rx_queues[loop],
2363 : 0 : dpaa_intf->cgr_rx ? &dpaa_intf->cgr_rx[loop] : NULL,
2364 : : fqid);
2365 [ # # ]: 0 : if (ret)
2366 : 0 : goto free_rx;
2367 : 0 : dpaa_intf->rx_queues[loop].vsp_id = vsp_id;
2368 : 0 : dpaa_intf->rx_queues[loop].dpaa_intf = dpaa_intf;
2369 : : }
2370 : 0 : dpaa_intf->nb_rx_queues = num_rx_fqs;
2371 : :
2372 : : /* Initialise Tx FQs.free_rx Have as many Tx FQ's as number of cores */
2373 : 0 : dpaa_intf->tx_queues = rte_zmalloc(NULL, sizeof(struct qman_fq) *
2374 : : MAX_DPAA_CORES, MAX_CACHELINE);
2375 [ # # ]: 0 : if (!dpaa_intf->tx_queues) {
2376 : 0 : DPAA_PMD_ERR("Failed to alloc mem for TX queues");
2377 : : ret = -ENOMEM;
2378 : 0 : goto free_rx;
2379 : : }
2380 : :
2381 : 0 : dpaa_intf->tx_conf_queues = rte_zmalloc(NULL, sizeof(struct qman_fq) *
2382 : : MAX_DPAA_CORES, MAX_CACHELINE);
2383 [ # # ]: 0 : if (!dpaa_intf->tx_conf_queues) {
2384 : 0 : DPAA_PMD_ERR("Failed to alloc mem for TX conf queues");
2385 : : ret = -ENOMEM;
2386 : 0 : goto free_rx;
2387 : : }
2388 : :
2389 : : /* If congestion control is enabled globally*/
2390 [ # # ]: 0 : if (td_tx_threshold) {
2391 : 0 : dpaa_intf->cgr_tx = rte_zmalloc(NULL,
2392 : : sizeof(struct qman_cgr) * MAX_DPAA_CORES,
2393 : : MAX_CACHELINE);
2394 [ # # ]: 0 : if (!dpaa_intf->cgr_tx) {
2395 : 0 : DPAA_PMD_ERR("Failed to alloc mem for cgr_tx");
2396 : : ret = -ENOMEM;
2397 : 0 : goto free_rx;
2398 : : }
2399 : :
2400 : 0 : ret = qman_alloc_cgrid_range(&cgrid_tx[0], MAX_DPAA_CORES,
2401 : : 1, 0);
2402 [ # # ]: 0 : if (ret != MAX_DPAA_CORES) {
2403 : 0 : DPAA_PMD_WARN("insufficient CGRIDs available");
2404 : : ret = -EINVAL;
2405 : 0 : goto free_rx;
2406 : : }
2407 : : } else {
2408 : 0 : dpaa_intf->cgr_tx = NULL;
2409 : : }
2410 : :
2411 : :
2412 [ # # ]: 0 : for (loop = 0; loop < MAX_DPAA_CORES; loop++) {
2413 [ # # ]: 0 : if (dpaa_intf->cgr_tx)
2414 : 0 : dpaa_intf->cgr_tx[loop].cgrid = cgrid_tx[loop];
2415 : :
2416 : 0 : dpaa_intf->tx_queues[loop].dpaa_intf = dpaa_intf;
2417 [ # # ]: 0 : ret = dpaa_tx_queue_init(&dpaa_intf->tx_queues[loop],
2418 : : fman_intf,
2419 : 0 : dpaa_intf->cgr_tx ? &dpaa_intf->cgr_tx[loop] : NULL);
2420 [ # # ]: 0 : if (ret)
2421 : 0 : goto free_tx;
2422 : :
2423 [ # # ]: 0 : if (dpaa_intf->ts_enable) {
2424 : 0 : ret = dpaa_tx_conf_queue_init(&dpaa_intf->tx_conf_queues[loop]);
2425 [ # # ]: 0 : if (ret)
2426 : 0 : goto free_tx;
2427 : :
2428 : 0 : dpaa_intf->tx_conf_queues[loop].dpaa_intf = dpaa_intf;
2429 : 0 : dpaa_intf->tx_queues[loop].tx_conf_queue = &dpaa_intf->tx_conf_queues[loop];
2430 : : }
2431 : : }
2432 : 0 : dpaa_intf->nb_tx_queues = MAX_DPAA_CORES;
2433 : : #if defined(RTE_LIBRTE_DPAA_DEBUG_DRIVER)
2434 : : ret = dpaa_error_queue_init(dpaa_intf, fman_intf);
2435 : : if (ret)
2436 : : goto free_tx;
2437 : : #endif
2438 : 0 : DPAA_PMD_DEBUG("All frame queues created");
2439 : :
2440 : : /* Get the initial configuration for flow control */
2441 [ # # ]: 0 : if (fman_intf->mac_type != fman_offline_internal &&
2442 : : fman_intf->mac_type != fman_onic)
2443 : 0 : dpaa_fc_set_default(dpaa_intf, fman_intf);
2444 : :
2445 : : /* reset bpool list, initialize bpool dynamically */
2446 [ # # ]: 0 : list_for_each_entry_safe(bp, tmp_bp, &cfg->fman_if->bpool_list, node) {
2447 : 0 : list_del(&bp->node);
2448 : 0 : rte_free(bp);
2449 : : }
2450 : :
2451 : : /* Populate ethdev structure */
2452 : 0 : eth_dev->dev_ops = &dpaa_devops;
2453 : 0 : eth_dev->rx_queue_count = dpaa_dev_rx_queue_count;
2454 : 0 : eth_dev->rx_pkt_burst = dpaa_eth_queue_rx;
2455 : 0 : eth_dev->tx_pkt_burst = dpaa_eth_tx_drop_all;
2456 : :
2457 : : /* Allocate memory for storing MAC addresses */
2458 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("mac_addr",
2459 : : RTE_ETHER_ADDR_LEN * DPAA_MAX_MAC_FILTER, 0);
2460 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
2461 : 0 : DPAA_PMD_ERR("Failed to allocate %d bytes needed to "
2462 : : "store MAC addresses",
2463 : : RTE_ETHER_ADDR_LEN * DPAA_MAX_MAC_FILTER);
2464 : : ret = -ENOMEM;
2465 : 0 : goto free_tx;
2466 : : }
2467 : :
2468 : : /* copy the primary mac address */
2469 : : rte_ether_addr_copy(&fman_intf->mac_addr, ð_dev->data->mac_addrs[0]);
2470 : :
2471 : 0 : DPAA_PMD_INFO("net: dpaa: %s: " RTE_ETHER_ADDR_PRT_FMT,
2472 : : dpaa_device->name, RTE_ETHER_ADDR_BYTES(&fman_intf->mac_addr));
2473 : :
2474 [ # # ]: 0 : if (!fman_intf->is_shared_mac &&
2475 [ # # # # ]: 0 : fman_intf->mac_type != fman_offline_internal &&
2476 : : fman_intf->mac_type != fman_onic) {
2477 : : /* Configure error packet handling */
2478 : : #ifndef RTE_LIBRTE_DPAA_DEBUG_DRIVER
2479 [ # # ]: 0 : if (dpaa_enable_recv_err_pkts)
2480 : : #endif
2481 : 0 : fman_if_receive_rx_errors(fman_intf,
2482 : : FM_FD_RX_STATUS_ERR_MASK);
2483 : :
2484 : : /* Disable RX mode */
2485 : 0 : fman_if_disable_rx(fman_intf);
2486 : : /* Disable promiscuous mode */
2487 : 0 : fman_if_promiscuous_disable(fman_intf);
2488 : : /* Disable multicast */
2489 : 0 : fman_if_reset_mcast_filter_table(fman_intf);
2490 : : /* Reset interface statistics */
2491 : 0 : fman_if_stats_reset(fman_intf);
2492 : : /* Disable SG by default */
2493 : 0 : fman_if_set_sg(fman_intf, 0);
2494 : 0 : fman_if_set_maxfrm(fman_intf,
2495 : : RTE_ETHER_MAX_LEN + VLAN_TAG_SIZE);
2496 : : }
2497 : :
2498 : : return 0;
2499 : :
2500 : 0 : free_tx:
2501 : 0 : rte_free(dpaa_intf->tx_queues);
2502 : 0 : dpaa_intf->tx_queues = NULL;
2503 : 0 : dpaa_intf->nb_tx_queues = 0;
2504 : :
2505 : 0 : free_rx:
2506 : 0 : rte_free(dpaa_intf->cgr_rx);
2507 : 0 : rte_free(dpaa_intf->cgr_tx);
2508 : 0 : rte_free(dpaa_intf->rx_queues);
2509 : 0 : dpaa_intf->rx_queues = NULL;
2510 : 0 : dpaa_intf->nb_rx_queues = 0;
2511 : 0 : return ret;
2512 : : }
2513 : :
2514 : : static int
2515 : 0 : rte_dpaa_probe(struct rte_dpaa_driver *dpaa_drv,
2516 : : struct rte_dpaa_device *dpaa_dev)
2517 : : {
2518 : : int diag;
2519 : : int ret;
2520 : : struct rte_eth_dev *eth_dev;
2521 : :
2522 : 0 : PMD_INIT_FUNC_TRACE();
2523 : :
2524 : : if ((DPAA_MBUF_HW_ANNOTATION + DPAA_FD_PTA_SIZE) >
2525 : : RTE_PKTMBUF_HEADROOM) {
2526 : : DPAA_PMD_ERR(
2527 : : "RTE_PKTMBUF_HEADROOM(%d) shall be > DPAA Annotation req(%d)",
2528 : : RTE_PKTMBUF_HEADROOM,
2529 : : DPAA_MBUF_HW_ANNOTATION + DPAA_FD_PTA_SIZE);
2530 : :
2531 : : return -1;
2532 : : }
2533 : :
2534 : : /* In case of secondary process, the device is already configured
2535 : : * and no further action is required, except portal initialization
2536 : : * and verifying secondary attachment to port name.
2537 : : */
2538 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2539 : 0 : eth_dev = rte_eth_dev_attach_secondary(dpaa_dev->name);
2540 [ # # ]: 0 : if (!eth_dev)
2541 : : return -ENOMEM;
2542 : 0 : eth_dev->device = &dpaa_dev->device;
2543 : 0 : eth_dev->dev_ops = &dpaa_devops;
2544 : :
2545 : 0 : ret = dpaa_dev_init_secondary(eth_dev);
2546 [ # # ]: 0 : if (ret) {
2547 : 0 : DPAA_PMD_ERR("secondary dev init failed(%d)", ret);
2548 : 0 : return ret;
2549 : : }
2550 : :
2551 : 0 : rte_eth_dev_probing_finish(eth_dev);
2552 : 0 : return 0;
2553 : : }
2554 : :
2555 [ # # # # ]: 0 : if (!is_global_init && (rte_eal_process_type() == RTE_PROC_PRIMARY)) {
2556 [ # # ]: 0 : if (access("/tmp/fmc.bin", F_OK) == -1) {
2557 : 0 : DPAA_PMD_INFO("* FMC not configured.Enabling default mode");
2558 : 0 : default_q = 1;
2559 : : }
2560 : :
2561 [ # # # # ]: 0 : if (!(default_q || fmc_q)) {
2562 : 0 : ret = dpaa_fm_init();
2563 [ # # ]: 0 : if (ret) {
2564 : 0 : DPAA_PMD_ERR("FM init failed(%d)", ret);
2565 : 0 : return ret;
2566 : : }
2567 : : }
2568 : :
2569 : 0 : is_global_init = 1;
2570 : : }
2571 : :
2572 [ # # ]: 0 : if (unlikely(!DPAA_PER_LCORE_PORTAL)) {
2573 : 0 : ret = rte_dpaa_portal_init((void *)1);
2574 [ # # ]: 0 : if (ret) {
2575 : 0 : DPAA_PMD_ERR("Unable to initialize portal");
2576 : 0 : return ret;
2577 : : }
2578 : : }
2579 : :
2580 : 0 : eth_dev = rte_eth_dev_allocate(dpaa_dev->name);
2581 [ # # ]: 0 : if (!eth_dev)
2582 : : return -ENOMEM;
2583 : :
2584 : 0 : eth_dev->data->dev_private =
2585 : 0 : rte_zmalloc("ethdev private structure",
2586 : : sizeof(struct dpaa_if),
2587 : : RTE_CACHE_LINE_SIZE);
2588 [ # # ]: 0 : if (!eth_dev->data->dev_private) {
2589 : 0 : DPAA_PMD_ERR("Cannot allocate memzone for port data");
2590 : 0 : rte_eth_dev_release_port(eth_dev);
2591 : 0 : return -ENOMEM;
2592 : : }
2593 : :
2594 : 0 : eth_dev->device = &dpaa_dev->device;
2595 : :
2596 : 0 : qman_ern_register_cb(dpaa_free_mbuf);
2597 : :
2598 [ # # ]: 0 : if (dpaa_drv->drv_flags & RTE_DPAA_DRV_INTR_LSC)
2599 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
2600 : :
2601 : : /* Invoke PMD device initialization function */
2602 : 0 : diag = dpaa_dev_init(eth_dev);
2603 [ # # ]: 0 : if (diag == 0) {
2604 [ # # ]: 0 : if (!dpaa_tx_sg_pool) {
2605 : 0 : dpaa_tx_sg_pool =
2606 : 0 : rte_pktmbuf_pool_create("dpaa_mbuf_tx_sg_pool",
2607 : : DPAA_POOL_SIZE,
2608 : : DPAA_POOL_CACHE_SIZE, 0,
2609 : : DPAA_MAX_SGS * sizeof(struct qm_sg_entry),
2610 : 0 : rte_socket_id());
2611 [ # # ]: 0 : if (dpaa_tx_sg_pool == NULL) {
2612 : 0 : DPAA_PMD_ERR("SG pool creation failed");
2613 : 0 : return -ENOMEM;
2614 : : }
2615 : : }
2616 : 0 : rte_eth_dev_probing_finish(eth_dev);
2617 : 0 : dpaa_valid_dev++;
2618 : 0 : return 0;
2619 : : }
2620 : :
2621 : 0 : rte_eth_dev_release_port(eth_dev);
2622 : 0 : return diag;
2623 : : }
2624 : :
2625 : : /* Adding destructor for double check in case non-gracefully
2626 : : * exit.
2627 : : */
2628 : 301 : RTE_FINI_PRIO(dpaa_finish, 103)
2629 : : {
2630 : : struct dpaa_if *dpaa_intf;
2631 : : int loop;
2632 : : struct qman_fq *fq;
2633 : : uint16_t portid;
2634 : : struct rte_eth_dev *dev;
2635 : :
2636 : 301 : PMD_INIT_FUNC_TRACE();
2637 : : /* For secondary, primary will do all the cleanup */
2638 [ + + ]: 301 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2639 : : return;
2640 : :
2641 [ - + ]: 268 : if (!is_global_init)
2642 : : return;
2643 : :
2644 [ # # # # ]: 0 : if (!(default_q || fmc_q)) {
2645 [ # # ]: 0 : if (dpaa_fm_term())
2646 : 0 : DPAA_PMD_WARN("DPAA FM term failed");
2647 : :
2648 : 0 : DPAA_PMD_INFO("DPAA fman cleaned up");
2649 : : }
2650 : :
2651 [ # # ]: 0 : RTE_ETH_FOREACH_DEV(portid) {
2652 : 0 : dev = &rte_eth_devices[portid];
2653 [ # # ]: 0 : if (strcmp(dev->device->driver->name,
2654 : : rte_dpaa_pmd.driver.name))
2655 : 0 : continue;
2656 : 0 : dpaa_intf = dev->data->dev_private;
2657 : : /* Freeing queue specific portals */
2658 [ # # ]: 0 : for (loop = 0; loop < dpaa_intf->nb_rx_queues; loop++) {
2659 [ # # ]: 0 : if (!dpaa_intf->rx_queues)
2660 : : break;
2661 : :
2662 : 0 : fq = &dpaa_intf->rx_queues[loop];
2663 [ # # ]: 0 : if (fq->qp_initialized) {
2664 : 0 : rte_dpaa_portal_fq_close(fq);
2665 : 0 : fq->qp_initialized = 0;
2666 : : }
2667 : : }
2668 : : }
2669 : 0 : is_global_init = 0;
2670 : : }
2671 : :
2672 : : static int
2673 : 0 : rte_dpaa_remove(struct rte_dpaa_device *dpaa_dev)
2674 : : {
2675 : : struct rte_eth_dev *eth_dev;
2676 : : int ret;
2677 : :
2678 : 0 : PMD_INIT_FUNC_TRACE();
2679 : :
2680 : 0 : eth_dev = rte_eth_dev_allocated(dpaa_dev->device.name);
2681 : 0 : dpaa_eth_dev_close(eth_dev);
2682 : 0 : ret = rte_eth_dev_release_port(eth_dev);
2683 : 0 : dpaa_valid_dev--;
2684 [ # # ]: 0 : if (!dpaa_valid_dev) {
2685 : 0 : rte_mempool_free(dpaa_tx_sg_pool);
2686 : 0 : dpaa_finish();
2687 : : }
2688 : 0 : return ret;
2689 : : }
2690 : :
2691 : : static struct rte_dpaa_driver rte_dpaa_pmd = {
2692 : : .drv_flags = RTE_DPAA_DRV_INTR_LSC,
2693 : : .drv_type = FSL_DPAA_ETH,
2694 : : .probe = rte_dpaa_probe,
2695 : : .remove = rte_dpaa_remove,
2696 : : };
2697 : :
2698 : 301 : RTE_PMD_REGISTER_DPAA(net_dpaa, rte_dpaa_pmd);
2699 : : RTE_PMD_REGISTER_PARAM_STRING(net_dpaa,
2700 : : DRIVER_RECV_ERR_PKTS "=<int>");
2701 [ - + ]: 301 : RTE_LOG_REGISTER_DEFAULT(dpaa_logtype_pmd, NOTICE);
|