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