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