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