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