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