1 /* * SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
12 #include <rte_ethdev_driver.h>
13 #include <rte_malloc.h>
14 #include <rte_memcpy.h>
15 #include <rte_string_fns.h>
16 #include <rte_cycles.h>
17 #include <rte_kvargs.h>
19 #include <rte_fslmc.h>
21 #include <fslmc_logs.h>
22 #include <fslmc_vfio.h>
23 #include <dpaa2_hw_pvt.h>
24 #include <dpaa2_hw_mempool.h>
25 #include <dpaa2_hw_dpio.h>
26 #include <mc/fsl_dpmng.h>
27 #include "dpaa2_ethdev.h"
28 #include <fsl_qbman_debug.h>
30 struct rte_dpaa2_xstats_name_off {
31 char name[RTE_ETH_XSTATS_NAME_SIZE];
32 uint8_t page_id; /* dpni statistics page id */
33 uint8_t stats_id; /* stats id in the given page */
36 static const struct rte_dpaa2_xstats_name_off dpaa2_xstats_strings[] = {
37 {"ingress_multicast_frames", 0, 2},
38 {"ingress_multicast_bytes", 0, 3},
39 {"ingress_broadcast_frames", 0, 4},
40 {"ingress_broadcast_bytes", 0, 5},
41 {"egress_multicast_frames", 1, 2},
42 {"egress_multicast_bytes", 1, 3},
43 {"egress_broadcast_frames", 1, 4},
44 {"egress_broadcast_bytes", 1, 5},
45 {"ingress_filtered_frames", 2, 0},
46 {"ingress_discarded_frames", 2, 1},
47 {"ingress_nobuffer_discards", 2, 2},
48 {"egress_discarded_frames", 2, 3},
49 {"egress_confirmed_frames", 2, 4},
52 static struct rte_dpaa2_driver rte_dpaa2_pmd;
53 static int dpaa2_dev_uninit(struct rte_eth_dev *eth_dev);
54 static int dpaa2_dev_link_update(struct rte_eth_dev *dev,
55 int wait_to_complete);
56 static int dpaa2_dev_set_link_up(struct rte_eth_dev *dev);
57 static int dpaa2_dev_set_link_down(struct rte_eth_dev *dev);
58 static int dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
61 dpaa2_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
64 struct dpaa2_dev_priv *priv = dev->data->dev_private;
65 struct fsl_mc_io *dpni = priv->hw;
67 PMD_INIT_FUNC_TRACE();
70 RTE_LOG(ERR, PMD, "dpni is NULL\n");
75 ret = dpni_add_vlan_id(dpni, CMD_PRI_LOW,
76 priv->token, vlan_id);
78 ret = dpni_remove_vlan_id(dpni, CMD_PRI_LOW,
79 priv->token, vlan_id);
82 PMD_DRV_LOG(ERR, "ret = %d Unable to add/rem vlan %d hwid =%d",
83 ret, vlan_id, priv->hw_id);
89 dpaa2_vlan_offload_set(struct rte_eth_dev *dev, int mask)
91 struct dpaa2_dev_priv *priv = dev->data->dev_private;
92 struct fsl_mc_io *dpni = priv->hw;
95 PMD_INIT_FUNC_TRACE();
97 if (mask & ETH_VLAN_FILTER_MASK) {
98 /* VLAN Filter not avaialble */
99 if (!priv->max_vlan_filters) {
100 RTE_LOG(INFO, PMD, "VLAN filter not available\n");
104 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
105 ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
108 ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
111 RTE_LOG(ERR, PMD, "Unable to set vlan filter = %d\n",
115 if (mask & ETH_VLAN_EXTEND_MASK) {
116 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
118 "VLAN extend offload not supported\n");
125 dpaa2_fw_version_get(struct rte_eth_dev *dev,
130 struct dpaa2_dev_priv *priv = dev->data->dev_private;
131 struct fsl_mc_io *dpni = priv->hw;
132 struct mc_soc_version mc_plat_info = {0};
133 struct mc_version mc_ver_info = {0};
135 PMD_INIT_FUNC_TRACE();
137 if (mc_get_soc_version(dpni, CMD_PRI_LOW, &mc_plat_info))
138 RTE_LOG(WARNING, PMD, "\tmc_get_soc_version failed\n");
140 if (mc_get_version(dpni, CMD_PRI_LOW, &mc_ver_info))
141 RTE_LOG(WARNING, PMD, "\tmc_get_version failed\n");
143 ret = snprintf(fw_version, fw_size,
148 mc_ver_info.revision);
150 ret += 1; /* add the size of '\0' */
151 if (fw_size < (uint32_t)ret)
158 dpaa2_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
160 struct dpaa2_dev_priv *priv = dev->data->dev_private;
162 PMD_INIT_FUNC_TRACE();
164 dev_info->if_index = priv->hw_id;
166 dev_info->max_mac_addrs = priv->max_mac_filters;
167 dev_info->max_rx_pktlen = DPAA2_MAX_RX_PKT_LEN;
168 dev_info->min_rx_bufsize = DPAA2_MIN_RX_BUF_SIZE;
169 dev_info->max_rx_queues = (uint16_t)priv->nb_rx_queues;
170 dev_info->max_tx_queues = (uint16_t)priv->nb_tx_queues;
171 dev_info->rx_offload_capa =
172 DEV_RX_OFFLOAD_IPV4_CKSUM |
173 DEV_RX_OFFLOAD_UDP_CKSUM |
174 DEV_RX_OFFLOAD_TCP_CKSUM |
175 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM;
176 dev_info->tx_offload_capa =
177 DEV_TX_OFFLOAD_IPV4_CKSUM |
178 DEV_TX_OFFLOAD_UDP_CKSUM |
179 DEV_TX_OFFLOAD_TCP_CKSUM |
180 DEV_TX_OFFLOAD_SCTP_CKSUM |
181 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
182 dev_info->speed_capa = ETH_LINK_SPEED_1G |
183 ETH_LINK_SPEED_2_5G |
188 dpaa2_alloc_rx_tx_queues(struct rte_eth_dev *dev)
190 struct dpaa2_dev_priv *priv = dev->data->dev_private;
193 struct dpaa2_queue *mc_q, *mcq;
196 struct dpaa2_queue *dpaa2_q;
198 PMD_INIT_FUNC_TRACE();
200 tot_queues = priv->nb_rx_queues + priv->nb_tx_queues;
201 mc_q = rte_malloc(NULL, sizeof(struct dpaa2_queue) * tot_queues,
202 RTE_CACHE_LINE_SIZE);
204 PMD_INIT_LOG(ERR, "malloc failed for rx/tx queues\n");
208 for (i = 0; i < priv->nb_rx_queues; i++) {
210 priv->rx_vq[i] = mc_q++;
211 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
212 dpaa2_q->q_storage = rte_malloc("dq_storage",
213 sizeof(struct queue_storage_info_t),
214 RTE_CACHE_LINE_SIZE);
215 if (!dpaa2_q->q_storage)
218 memset(dpaa2_q->q_storage, 0,
219 sizeof(struct queue_storage_info_t));
220 if (dpaa2_alloc_dq_storage(dpaa2_q->q_storage))
224 for (i = 0; i < priv->nb_tx_queues; i++) {
226 mc_q->flow_id = 0xffff;
227 priv->tx_vq[i] = mc_q++;
228 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
229 dpaa2_q->cscn = rte_malloc(NULL,
230 sizeof(struct qbman_result), 16);
236 for (dist_idx = 0; dist_idx < priv->nb_rx_queues; dist_idx++) {
237 mcq = (struct dpaa2_queue *)priv->rx_vq[vq_id];
238 mcq->tc_index = DPAA2_DEF_TC;
239 mcq->flow_id = dist_idx;
247 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
248 rte_free(dpaa2_q->cscn);
249 priv->tx_vq[i--] = NULL;
251 i = priv->nb_rx_queues;
254 mc_q = priv->rx_vq[0];
256 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
257 dpaa2_free_dq_storage(dpaa2_q->q_storage);
258 rte_free(dpaa2_q->q_storage);
259 priv->rx_vq[i--] = NULL;
266 dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
268 struct dpaa2_dev_priv *priv = dev->data->dev_private;
269 struct fsl_mc_io *dpni = priv->hw;
270 struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
271 int rx_ip_csum_offload = false;
274 PMD_INIT_FUNC_TRACE();
276 if (eth_conf->rxmode.jumbo_frame == 1) {
277 if (eth_conf->rxmode.max_rx_pkt_len <= DPAA2_MAX_RX_PKT_LEN) {
278 ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW,
279 priv->token, eth_conf->rxmode.max_rx_pkt_len);
282 "unable to set mtu. check config\n");
290 if (eth_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) {
291 ret = dpaa2_setup_flow_dist(dev,
292 eth_conf->rx_adv_conf.rss_conf.rss_hf);
294 PMD_INIT_LOG(ERR, "unable to set flow distribution."
295 "please check queue config\n");
300 if (eth_conf->rxmode.hw_ip_checksum)
301 rx_ip_csum_offload = true;
303 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
304 DPNI_OFF_RX_L3_CSUM, rx_ip_csum_offload);
306 PMD_INIT_LOG(ERR, "Error to set RX l3 csum:Error = %d\n", ret);
310 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
311 DPNI_OFF_RX_L4_CSUM, rx_ip_csum_offload);
313 PMD_INIT_LOG(ERR, "Error to get RX l4 csum:Error = %d\n", ret);
317 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
318 DPNI_OFF_TX_L3_CSUM, true);
320 PMD_INIT_LOG(ERR, "Error to set TX l3 csum:Error = %d\n", ret);
324 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
325 DPNI_OFF_TX_L4_CSUM, true);
327 PMD_INIT_LOG(ERR, "Error to get TX l4 csum:Error = %d\n", ret);
331 /* Enabling hash results in FD requires setting DPNI_FLCTYPE_HASH in
332 * dpni_set_offload API. Setting this FLCTYPE for DPNI sets the FD[SC]
333 * to 0 for LS2 in the hardware thus disabling data/annotation
334 * stashing. For LX2 this is fixed in hardware and thus hash result and
335 * parse results can be received in FD using this option.
337 if (dpaa2_svr_family == SVR_LX2160A) {
338 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
339 DPNI_FLCTYPE_HASH, true);
341 PMD_INIT_LOG(ERR, "Error setting FLCTYPE: Err = %d\n",
347 if (eth_conf->rxmode.hw_vlan_filter)
348 dpaa2_vlan_offload_set(dev, ETH_VLAN_FILTER_MASK);
350 /* update the current status */
351 dpaa2_dev_link_update(dev, 0);
356 /* Function to setup RX flow information. It contains traffic class ID,
357 * flow ID, destination configuration etc.
360 dpaa2_dev_rx_queue_setup(struct rte_eth_dev *dev,
361 uint16_t rx_queue_id,
362 uint16_t nb_rx_desc __rte_unused,
363 unsigned int socket_id __rte_unused,
364 const struct rte_eth_rxconf *rx_conf __rte_unused,
365 struct rte_mempool *mb_pool)
367 struct dpaa2_dev_priv *priv = dev->data->dev_private;
368 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
369 struct dpaa2_queue *dpaa2_q;
370 struct dpni_queue cfg;
376 PMD_INIT_FUNC_TRACE();
378 PMD_DRV_LOG(DEBUG, "dev =%p, queue =%d, pool = %p, conf =%p",
379 dev, rx_queue_id, mb_pool, rx_conf);
381 if (!priv->bp_list || priv->bp_list->mp != mb_pool) {
382 bpid = mempool_to_bpid(mb_pool);
383 ret = dpaa2_attach_bp_list(priv,
384 rte_dpaa2_bpid_info[bpid].bp_list);
388 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
389 dpaa2_q->mb_pool = mb_pool; /**< mbuf pool to populate RX ring. */
391 /*Get the flow id from given VQ id*/
392 flow_id = rx_queue_id % priv->nb_rx_queues;
393 memset(&cfg, 0, sizeof(struct dpni_queue));
395 options = options | DPNI_QUEUE_OPT_USER_CTX;
396 cfg.user_context = (size_t)(dpaa2_q);
398 /*if ls2088 or rev2 device, enable the stashing */
400 if ((dpaa2_svr_family & 0xffff0000) != SVR_LS2080A) {
401 options |= DPNI_QUEUE_OPT_FLC;
402 cfg.flc.stash_control = true;
403 cfg.flc.value &= 0xFFFFFFFFFFFFFFC0;
404 /* 00 00 00 - last 6 bit represent annotation, context stashing,
405 * data stashing setting 01 01 00 (0x14)
406 * (in following order ->DS AS CS)
407 * to enable 1 line data, 1 line annotation.
408 * For LX2, this setting should be 01 00 00 (0x10)
410 if ((dpaa2_svr_family & 0xffff0000) == SVR_LX2160A)
411 cfg.flc.value |= 0x10;
413 cfg.flc.value |= 0x14;
415 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_RX,
416 dpaa2_q->tc_index, flow_id, options, &cfg);
418 PMD_INIT_LOG(ERR, "Error in setting the rx flow: = %d\n", ret);
422 if (!(priv->flags & DPAA2_RX_TAILDROP_OFF)) {
423 struct dpni_taildrop taildrop;
426 /*enabling per rx queue congestion control */
427 taildrop.threshold = CONG_THRESHOLD_RX_Q;
428 taildrop.units = DPNI_CONGESTION_UNIT_BYTES;
429 taildrop.oal = CONG_RX_OAL;
430 PMD_DRV_LOG(DEBUG, "Enabling Early Drop on queue = %d",
432 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
433 DPNI_CP_QUEUE, DPNI_QUEUE_RX,
434 dpaa2_q->tc_index, flow_id, &taildrop);
436 PMD_INIT_LOG(ERR, "Error in setting the rx flow"
437 " err : = %d\n", ret);
442 dev->data->rx_queues[rx_queue_id] = dpaa2_q;
447 dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
448 uint16_t tx_queue_id,
449 uint16_t nb_tx_desc __rte_unused,
450 unsigned int socket_id __rte_unused,
451 const struct rte_eth_txconf *tx_conf __rte_unused)
453 struct dpaa2_dev_priv *priv = dev->data->dev_private;
454 struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)
455 priv->tx_vq[tx_queue_id];
456 struct fsl_mc_io *dpni = priv->hw;
457 struct dpni_queue tx_conf_cfg;
458 struct dpni_queue tx_flow_cfg;
459 uint8_t options = 0, flow_id;
463 PMD_INIT_FUNC_TRACE();
465 /* Return if queue already configured */
466 if (dpaa2_q->flow_id != 0xffff) {
467 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
471 memset(&tx_conf_cfg, 0, sizeof(struct dpni_queue));
472 memset(&tx_flow_cfg, 0, sizeof(struct dpni_queue));
477 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
478 tc_id, flow_id, options, &tx_flow_cfg);
480 PMD_INIT_LOG(ERR, "Error in setting the tx flow: "
481 "tc_id=%d, flow =%d ErrorCode = %x\n",
482 tc_id, flow_id, -ret);
486 dpaa2_q->flow_id = flow_id;
488 if (tx_queue_id == 0) {
489 /*Set tx-conf and error configuration*/
490 ret = dpni_set_tx_confirmation_mode(dpni, CMD_PRI_LOW,
494 PMD_INIT_LOG(ERR, "Error in set tx conf mode settings"
495 " ErrorCode = %x", ret);
499 dpaa2_q->tc_index = tc_id;
501 if (!(priv->flags & DPAA2_TX_CGR_OFF)) {
502 struct dpni_congestion_notification_cfg cong_notif_cfg;
504 cong_notif_cfg.units = DPNI_CONGESTION_UNIT_FRAMES;
505 cong_notif_cfg.threshold_entry = CONG_ENTER_TX_THRESHOLD;
506 /* Notify that the queue is not congested when the data in
507 * the queue is below this thershold.
509 cong_notif_cfg.threshold_exit = CONG_EXIT_TX_THRESHOLD;
510 cong_notif_cfg.message_ctx = 0;
511 cong_notif_cfg.message_iova = (size_t)dpaa2_q->cscn;
512 cong_notif_cfg.dest_cfg.dest_type = DPNI_DEST_NONE;
513 cong_notif_cfg.notification_mode =
514 DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
515 DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
516 DPNI_CONG_OPT_COHERENT_WRITE;
518 ret = dpni_set_congestion_notification(dpni, CMD_PRI_LOW,
525 "Error in setting tx congestion notification: = %d",
530 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
535 dpaa2_dev_rx_queue_release(void *q __rte_unused)
537 PMD_INIT_FUNC_TRACE();
541 dpaa2_dev_tx_queue_release(void *q __rte_unused)
543 PMD_INIT_FUNC_TRACE();
547 dpaa2_dev_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
550 struct dpaa2_dev_priv *priv = dev->data->dev_private;
551 struct dpaa2_queue *dpaa2_q;
552 struct qbman_swp *swp;
553 struct qbman_fq_query_np_rslt state;
554 uint32_t frame_cnt = 0;
556 PMD_INIT_FUNC_TRACE();
558 if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
559 ret = dpaa2_affine_qbman_swp();
561 RTE_LOG(ERR, PMD, "Failure in affining portal\n");
565 swp = DPAA2_PER_LCORE_PORTAL;
567 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
569 if (qbman_fq_query_state(swp, dpaa2_q->fqid, &state) == 0) {
570 frame_cnt = qbman_fq_state_frame_count(&state);
571 RTE_LOG(DEBUG, PMD, "RX frame count for q(%d) is %u\n",
572 rx_queue_id, frame_cnt);
577 static const uint32_t *
578 dpaa2_supported_ptypes_get(struct rte_eth_dev *dev)
580 static const uint32_t ptypes[] = {
581 /*todo -= add more types */
584 RTE_PTYPE_L3_IPV4_EXT,
586 RTE_PTYPE_L3_IPV6_EXT,
594 if (dev->rx_pkt_burst == dpaa2_dev_prefetch_rx)
600 * Dpaa2 link Interrupt handler
603 * The address of parameter (struct rte_eth_dev *) regsitered before.
609 dpaa2_interrupt_handler(void *param)
611 struct rte_eth_dev *dev = param;
612 struct dpaa2_dev_priv *priv = dev->data->dev_private;
613 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
615 int irq_index = DPNI_IRQ_INDEX;
616 unsigned int status = 0, clear = 0;
618 PMD_INIT_FUNC_TRACE();
621 RTE_LOG(ERR, PMD, "dpni is NULL");
625 ret = dpni_get_irq_status(dpni, CMD_PRI_LOW, priv->token,
628 RTE_LOG(ERR, PMD, "Can't get irq status (err %d)", ret);
633 if (status & DPNI_IRQ_EVENT_LINK_CHANGED) {
634 clear = DPNI_IRQ_EVENT_LINK_CHANGED;
635 dpaa2_dev_link_update(dev, 0);
636 /* calling all the apps registered for link status event */
637 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
641 ret = dpni_clear_irq_status(dpni, CMD_PRI_LOW, priv->token,
644 RTE_LOG(ERR, PMD, "Can't clear irq status (err %d)", ret);
648 dpaa2_eth_setup_irqs(struct rte_eth_dev *dev, int enable)
651 struct dpaa2_dev_priv *priv = dev->data->dev_private;
652 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
653 int irq_index = DPNI_IRQ_INDEX;
654 unsigned int mask = DPNI_IRQ_EVENT_LINK_CHANGED;
656 PMD_INIT_FUNC_TRACE();
658 err = dpni_set_irq_mask(dpni, CMD_PRI_LOW, priv->token,
661 PMD_INIT_LOG(ERR, "Error: dpni_set_irq_mask():%d (%s)", err,
666 err = dpni_set_irq_enable(dpni, CMD_PRI_LOW, priv->token,
669 PMD_INIT_LOG(ERR, "Error: dpni_set_irq_enable():%d (%s)", err,
676 dpaa2_dev_start(struct rte_eth_dev *dev)
678 struct rte_device *rdev = dev->device;
679 struct rte_dpaa2_device *dpaa2_dev;
680 struct rte_eth_dev_data *data = dev->data;
681 struct dpaa2_dev_priv *priv = data->dev_private;
682 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
683 struct dpni_queue cfg;
684 struct dpni_error_cfg err_cfg;
686 struct dpni_queue_id qid;
687 struct dpaa2_queue *dpaa2_q;
689 struct rte_intr_handle *intr_handle;
691 dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
692 intr_handle = &dpaa2_dev->intr_handle;
694 PMD_INIT_FUNC_TRACE();
696 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
698 PMD_INIT_LOG(ERR, "Failure %d in enabling dpni %d device\n",
703 /* Power up the phy. Needed to make the link go UP */
704 dpaa2_dev_set_link_up(dev);
706 ret = dpni_get_qdid(dpni, CMD_PRI_LOW, priv->token,
707 DPNI_QUEUE_TX, &qdid);
709 PMD_INIT_LOG(ERR, "Error to get qdid:ErrorCode = %d\n", ret);
714 for (i = 0; i < data->nb_rx_queues; i++) {
715 dpaa2_q = (struct dpaa2_queue *)data->rx_queues[i];
716 ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
717 DPNI_QUEUE_RX, dpaa2_q->tc_index,
718 dpaa2_q->flow_id, &cfg, &qid);
720 PMD_INIT_LOG(ERR, "Error to get flow "
721 "information Error code = %d\n", ret);
724 dpaa2_q->fqid = qid.fqid;
727 /*checksum errors, send them to normal path and set it in annotation */
728 err_cfg.errors = DPNI_ERROR_L3CE | DPNI_ERROR_L4CE;
730 err_cfg.error_action = DPNI_ERROR_ACTION_CONTINUE;
731 err_cfg.set_frame_annotation = true;
733 ret = dpni_set_errors_behavior(dpni, CMD_PRI_LOW,
734 priv->token, &err_cfg);
736 PMD_INIT_LOG(ERR, "Error to dpni_set_errors_behavior:"
741 /* if the interrupts were configured on this devices*/
742 if (intr_handle && (intr_handle->fd) &&
743 (dev->data->dev_conf.intr_conf.lsc != 0)) {
744 /* Registering LSC interrupt handler */
745 rte_intr_callback_register(intr_handle,
746 dpaa2_interrupt_handler,
749 /* enable vfio intr/eventfd mapping
750 * Interrupt index 0 is required, so we can not use
753 rte_dpaa2_intr_enable(intr_handle, DPNI_IRQ_INDEX);
755 /* enable dpni_irqs */
756 dpaa2_eth_setup_irqs(dev, 1);
763 * This routine disables all traffic on the adapter by issuing a
764 * global reset on the MAC.
767 dpaa2_dev_stop(struct rte_eth_dev *dev)
769 struct dpaa2_dev_priv *priv = dev->data->dev_private;
770 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
772 struct rte_eth_link link;
773 struct rte_intr_handle *intr_handle = dev->intr_handle;
775 PMD_INIT_FUNC_TRACE();
777 /* reset interrupt callback */
778 if (intr_handle && (intr_handle->fd) &&
779 (dev->data->dev_conf.intr_conf.lsc != 0)) {
780 /*disable dpni irqs */
781 dpaa2_eth_setup_irqs(dev, 0);
783 /* disable vfio intr before callback unregister */
784 rte_dpaa2_intr_disable(intr_handle, DPNI_IRQ_INDEX);
786 /* Unregistering LSC interrupt handler */
787 rte_intr_callback_unregister(intr_handle,
788 dpaa2_interrupt_handler,
792 dpaa2_dev_set_link_down(dev);
794 ret = dpni_disable(dpni, CMD_PRI_LOW, priv->token);
796 PMD_INIT_LOG(ERR, "Failure (ret %d) in disabling dpni %d dev\n",
801 /* clear the recorded link status */
802 memset(&link, 0, sizeof(link));
803 rte_eth_linkstatus_set(dev, &link);
807 dpaa2_dev_close(struct rte_eth_dev *dev)
809 struct rte_eth_dev_data *data = dev->data;
810 struct dpaa2_dev_priv *priv = dev->data->dev_private;
811 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
813 struct rte_eth_link link;
814 struct dpaa2_queue *dpaa2_q;
816 PMD_INIT_FUNC_TRACE();
818 for (i = 0; i < data->nb_tx_queues; i++) {
819 dpaa2_q = (struct dpaa2_queue *)data->tx_queues[i];
820 if (!dpaa2_q->cscn) {
821 rte_free(dpaa2_q->cscn);
822 dpaa2_q->cscn = NULL;
826 /* Clean the device first */
827 ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
829 PMD_INIT_LOG(ERR, "Failure cleaning dpni device with"
830 " error code %d\n", ret);
834 memset(&link, 0, sizeof(link));
835 rte_eth_linkstatus_set(dev, &link);
839 dpaa2_dev_promiscuous_enable(
840 struct rte_eth_dev *dev)
843 struct dpaa2_dev_priv *priv = dev->data->dev_private;
844 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
846 PMD_INIT_FUNC_TRACE();
849 RTE_LOG(ERR, PMD, "dpni is NULL\n");
853 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
855 RTE_LOG(ERR, PMD, "Unable to enable U promisc mode %d\n", ret);
857 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
859 RTE_LOG(ERR, PMD, "Unable to enable M promisc mode %d\n", ret);
863 dpaa2_dev_promiscuous_disable(
864 struct rte_eth_dev *dev)
867 struct dpaa2_dev_priv *priv = dev->data->dev_private;
868 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
870 PMD_INIT_FUNC_TRACE();
873 RTE_LOG(ERR, PMD, "dpni is NULL\n");
877 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
879 RTE_LOG(ERR, PMD, "Unable to disable U promisc mode %d\n", ret);
881 if (dev->data->all_multicast == 0) {
882 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW,
886 "Unable to disable M promisc mode %d\n",
892 dpaa2_dev_allmulticast_enable(
893 struct rte_eth_dev *dev)
896 struct dpaa2_dev_priv *priv = dev->data->dev_private;
897 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
899 PMD_INIT_FUNC_TRACE();
902 RTE_LOG(ERR, PMD, "dpni is NULL\n");
906 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
908 RTE_LOG(ERR, PMD, "Unable to enable multicast mode %d\n", ret);
912 dpaa2_dev_allmulticast_disable(struct rte_eth_dev *dev)
915 struct dpaa2_dev_priv *priv = dev->data->dev_private;
916 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
918 PMD_INIT_FUNC_TRACE();
921 RTE_LOG(ERR, PMD, "dpni is NULL\n");
925 /* must remain on for all promiscuous */
926 if (dev->data->promiscuous == 1)
929 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
931 RTE_LOG(ERR, PMD, "Unable to disable multicast mode %d\n", ret);
935 dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
938 struct dpaa2_dev_priv *priv = dev->data->dev_private;
939 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
940 uint32_t frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN
943 PMD_INIT_FUNC_TRACE();
946 RTE_LOG(ERR, PMD, "dpni is NULL\n");
950 /* check that mtu is within the allowed range */
951 if ((mtu < ETHER_MIN_MTU) || (frame_size > DPAA2_MAX_RX_PKT_LEN))
954 if (frame_size > ETHER_MAX_LEN)
955 dev->data->dev_conf.rxmode.jumbo_frame = 1;
957 dev->data->dev_conf.rxmode.jumbo_frame = 0;
959 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
961 /* Set the Max Rx frame length as 'mtu' +
962 * Maximum Ethernet header length
964 ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
967 PMD_DRV_LOG(ERR, "setting the max frame length failed");
970 PMD_DRV_LOG(INFO, "MTU is configured %d for the device", mtu);
975 dpaa2_dev_add_mac_addr(struct rte_eth_dev *dev,
976 struct ether_addr *addr,
977 __rte_unused uint32_t index,
978 __rte_unused uint32_t pool)
981 struct dpaa2_dev_priv *priv = dev->data->dev_private;
982 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
984 PMD_INIT_FUNC_TRACE();
987 RTE_LOG(ERR, PMD, "dpni is NULL\n");
991 ret = dpni_add_mac_addr(dpni, CMD_PRI_LOW,
992 priv->token, addr->addr_bytes);
995 "error: Adding the MAC ADDR failed: err = %d\n", ret);
1000 dpaa2_dev_remove_mac_addr(struct rte_eth_dev *dev,
1004 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1005 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1006 struct rte_eth_dev_data *data = dev->data;
1007 struct ether_addr *macaddr;
1009 PMD_INIT_FUNC_TRACE();
1011 macaddr = &data->mac_addrs[index];
1014 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1018 ret = dpni_remove_mac_addr(dpni, CMD_PRI_LOW,
1019 priv->token, macaddr->addr_bytes);
1022 "error: Removing the MAC ADDR failed: err = %d\n", ret);
1026 dpaa2_dev_set_mac_addr(struct rte_eth_dev *dev,
1027 struct ether_addr *addr)
1030 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1031 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1033 PMD_INIT_FUNC_TRACE();
1036 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1040 ret = dpni_set_primary_mac_addr(dpni, CMD_PRI_LOW,
1041 priv->token, addr->addr_bytes);
1045 "error: Setting the MAC ADDR failed %d\n", ret);
1048 int dpaa2_dev_stats_get(struct rte_eth_dev *dev,
1049 struct rte_eth_stats *stats)
1051 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1052 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1054 uint8_t page0 = 0, page1 = 1, page2 = 2;
1055 union dpni_statistics value;
1057 memset(&value, 0, sizeof(union dpni_statistics));
1059 PMD_INIT_FUNC_TRACE();
1062 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1067 RTE_LOG(ERR, PMD, "stats is NULL\n");
1071 /*Get Counters from page_0*/
1072 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1077 stats->ipackets = value.page_0.ingress_all_frames;
1078 stats->ibytes = value.page_0.ingress_all_bytes;
1080 /*Get Counters from page_1*/
1081 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1086 stats->opackets = value.page_1.egress_all_frames;
1087 stats->obytes = value.page_1.egress_all_bytes;
1089 /*Get Counters from page_2*/
1090 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1095 /* Ingress drop frame count due to configured rules */
1096 stats->ierrors = value.page_2.ingress_filtered_frames;
1097 /* Ingress drop frame count due to error */
1098 stats->ierrors += value.page_2.ingress_discarded_frames;
1100 stats->oerrors = value.page_2.egress_discarded_frames;
1101 stats->imissed = value.page_2.ingress_nobuffer_discards;
1106 RTE_LOG(ERR, PMD, "Operation not completed:Error Code = %d\n", retcode);
1111 dpaa2_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1114 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1115 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1117 union dpni_statistics value[3] = {};
1118 unsigned int i = 0, num = RTE_DIM(dpaa2_xstats_strings);
1126 /* Get Counters from page_0*/
1127 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1132 /* Get Counters from page_1*/
1133 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1138 /* Get Counters from page_2*/
1139 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1144 for (i = 0; i < num; i++) {
1146 xstats[i].value = value[dpaa2_xstats_strings[i].page_id].
1147 raw.counter[dpaa2_xstats_strings[i].stats_id];
1151 RTE_LOG(ERR, PMD, "Error in obtaining extended stats (%d)\n", retcode);
1156 dpaa2_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1157 struct rte_eth_xstat_name *xstats_names,
1158 __rte_unused unsigned int limit)
1160 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1162 if (xstats_names != NULL)
1163 for (i = 0; i < stat_cnt; i++)
1164 snprintf(xstats_names[i].name,
1165 sizeof(xstats_names[i].name),
1167 dpaa2_xstats_strings[i].name);
1173 dpaa2_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1174 uint64_t *values, unsigned int n)
1176 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1177 uint64_t values_copy[stat_cnt];
1180 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1181 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1183 union dpni_statistics value[3] = {};
1191 /* Get Counters from page_0*/
1192 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1197 /* Get Counters from page_1*/
1198 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1203 /* Get Counters from page_2*/
1204 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1209 for (i = 0; i < stat_cnt; i++) {
1210 values[i] = value[dpaa2_xstats_strings[i].page_id].
1211 raw.counter[dpaa2_xstats_strings[i].stats_id];
1216 dpaa2_xstats_get_by_id(dev, NULL, values_copy, stat_cnt);
1218 for (i = 0; i < n; i++) {
1219 if (ids[i] >= stat_cnt) {
1220 PMD_INIT_LOG(ERR, "id value isn't valid");
1223 values[i] = values_copy[ids[i]];
1229 dpaa2_xstats_get_names_by_id(
1230 struct rte_eth_dev *dev,
1231 struct rte_eth_xstat_name *xstats_names,
1232 const uint64_t *ids,
1235 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1236 struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
1239 return dpaa2_xstats_get_names(dev, xstats_names, limit);
1241 dpaa2_xstats_get_names(dev, xstats_names_copy, limit);
1243 for (i = 0; i < limit; i++) {
1244 if (ids[i] >= stat_cnt) {
1245 PMD_INIT_LOG(ERR, "id value isn't valid");
1248 strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
1254 dpaa2_dev_stats_reset(struct rte_eth_dev *dev)
1256 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1257 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1260 PMD_INIT_FUNC_TRACE();
1263 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1267 retcode = dpni_reset_statistics(dpni, CMD_PRI_LOW, priv->token);
1274 RTE_LOG(ERR, PMD, "Operation not completed:Error Code = %d\n", retcode);
1278 /* return 0 means link status changed, -1 means not changed */
1280 dpaa2_dev_link_update(struct rte_eth_dev *dev,
1281 int wait_to_complete __rte_unused)
1284 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1285 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1286 struct rte_eth_link link;
1287 struct dpni_link_state state = {0};
1290 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1294 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1296 RTE_LOG(ERR, PMD, "error: dpni_get_link_state %d\n", ret);
1300 memset(&link, 0, sizeof(struct rte_eth_link));
1301 link.link_status = state.up;
1302 link.link_speed = state.rate;
1304 if (state.options & DPNI_LINK_OPT_HALF_DUPLEX)
1305 link.link_duplex = ETH_LINK_HALF_DUPLEX;
1307 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1309 ret = rte_eth_linkstatus_set(dev, &link);
1311 RTE_LOG(DEBUG, PMD, "No change in status\n");
1313 PMD_DRV_LOG(INFO, "Port %d Link is %s\n", dev->data->port_id,
1314 link.link_status ? "Up" : "Down");
1320 * Toggle the DPNI to enable, if not already enabled.
1321 * This is not strictly PHY up/down - it is more of logical toggling.
1324 dpaa2_dev_set_link_up(struct rte_eth_dev *dev)
1327 struct dpaa2_dev_priv *priv;
1328 struct fsl_mc_io *dpni;
1330 struct dpni_link_state state = {0};
1332 priv = dev->data->dev_private;
1333 dpni = (struct fsl_mc_io *)priv->hw;
1336 RTE_LOG(ERR, PMD, "DPNI is NULL\n");
1340 /* Check if DPNI is currently enabled */
1341 ret = dpni_is_enabled(dpni, CMD_PRI_LOW, priv->token, &en);
1343 /* Unable to obtain dpni status; Not continuing */
1344 PMD_DRV_LOG(ERR, "Interface Link UP failed (%d)", ret);
1348 /* Enable link if not already enabled */
1350 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
1352 PMD_DRV_LOG(ERR, "Interface Link UP failed (%d)", ret);
1356 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1358 RTE_LOG(ERR, PMD, "error: dpni_get_link_state %d\n", ret);
1362 /* changing tx burst function to start enqueues */
1363 dev->tx_pkt_burst = dpaa2_dev_tx;
1364 dev->data->dev_link.link_status = state.up;
1367 PMD_DRV_LOG(INFO, "Port %d Link is set as UP",
1368 dev->data->port_id);
1370 PMD_DRV_LOG(INFO, "Port %d Link is DOWN", dev->data->port_id);
1375 * Toggle the DPNI to disable, if not already disabled.
1376 * This is not strictly PHY up/down - it is more of logical toggling.
1379 dpaa2_dev_set_link_down(struct rte_eth_dev *dev)
1382 struct dpaa2_dev_priv *priv;
1383 struct fsl_mc_io *dpni;
1384 int dpni_enabled = 0;
1387 PMD_INIT_FUNC_TRACE();
1389 priv = dev->data->dev_private;
1390 dpni = (struct fsl_mc_io *)priv->hw;
1393 RTE_LOG(ERR, PMD, "Device has not yet been configured\n");
1397 /*changing tx burst function to avoid any more enqueues */
1398 dev->tx_pkt_burst = dummy_dev_tx;
1400 /* Loop while dpni_disable() attempts to drain the egress FQs
1401 * and confirm them back to us.
1404 ret = dpni_disable(dpni, 0, priv->token);
1406 PMD_DRV_LOG(ERR, "dpni disable failed (%d)", ret);
1409 ret = dpni_is_enabled(dpni, 0, priv->token, &dpni_enabled);
1411 PMD_DRV_LOG(ERR, "dpni_is_enabled failed (%d)", ret);
1415 /* Allow the MC some slack */
1416 rte_delay_us(100 * 1000);
1417 } while (dpni_enabled && --retries);
1420 PMD_DRV_LOG(WARNING, "Retry count exceeded disabling DPNI\n");
1421 /* todo- we may have to manually cleanup queues.
1424 PMD_DRV_LOG(INFO, "Port %d Link DOWN successful",
1425 dev->data->port_id);
1428 dev->data->dev_link.link_status = 0;
1434 dpaa2_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1437 struct dpaa2_dev_priv *priv;
1438 struct fsl_mc_io *dpni;
1439 struct dpni_link_state state = {0};
1441 PMD_INIT_FUNC_TRACE();
1443 priv = dev->data->dev_private;
1444 dpni = (struct fsl_mc_io *)priv->hw;
1446 if (dpni == NULL || fc_conf == NULL) {
1447 RTE_LOG(ERR, PMD, "device not configured\n");
1451 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1453 RTE_LOG(ERR, PMD, "error: dpni_get_link_state %d\n", ret);
1457 memset(fc_conf, 0, sizeof(struct rte_eth_fc_conf));
1458 if (state.options & DPNI_LINK_OPT_PAUSE) {
1459 /* DPNI_LINK_OPT_PAUSE set
1460 * if ASYM_PAUSE not set,
1461 * RX Side flow control (handle received Pause frame)
1462 * TX side flow control (send Pause frame)
1463 * if ASYM_PAUSE set,
1464 * RX Side flow control (handle received Pause frame)
1465 * No TX side flow control (send Pause frame disabled)
1467 if (!(state.options & DPNI_LINK_OPT_ASYM_PAUSE))
1468 fc_conf->mode = RTE_FC_FULL;
1470 fc_conf->mode = RTE_FC_RX_PAUSE;
1472 /* DPNI_LINK_OPT_PAUSE not set
1473 * if ASYM_PAUSE set,
1474 * TX side flow control (send Pause frame)
1475 * No RX side flow control (No action on pause frame rx)
1476 * if ASYM_PAUSE not set,
1477 * Flow control disabled
1479 if (state.options & DPNI_LINK_OPT_ASYM_PAUSE)
1480 fc_conf->mode = RTE_FC_TX_PAUSE;
1482 fc_conf->mode = RTE_FC_NONE;
1489 dpaa2_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1492 struct dpaa2_dev_priv *priv;
1493 struct fsl_mc_io *dpni;
1494 struct dpni_link_state state = {0};
1495 struct dpni_link_cfg cfg = {0};
1497 PMD_INIT_FUNC_TRACE();
1499 priv = dev->data->dev_private;
1500 dpni = (struct fsl_mc_io *)priv->hw;
1503 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1507 /* It is necessary to obtain the current state before setting fc_conf
1508 * as MC would return error in case rate, autoneg or duplex values are
1511 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1513 RTE_LOG(ERR, PMD, "Unable to get link state (err=%d)\n", ret);
1517 /* Disable link before setting configuration */
1518 dpaa2_dev_set_link_down(dev);
1520 /* Based on fc_conf, update cfg */
1521 cfg.rate = state.rate;
1522 cfg.options = state.options;
1524 /* update cfg with fc_conf */
1525 switch (fc_conf->mode) {
1527 /* Full flow control;
1528 * OPT_PAUSE set, ASYM_PAUSE not set
1530 cfg.options |= DPNI_LINK_OPT_PAUSE;
1531 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1533 case RTE_FC_TX_PAUSE:
1534 /* Enable RX flow control
1535 * OPT_PAUSE not set;
1538 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1539 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1541 case RTE_FC_RX_PAUSE:
1542 /* Enable TX Flow control
1546 cfg.options |= DPNI_LINK_OPT_PAUSE;
1547 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1550 /* Disable Flow control
1552 * ASYM_PAUSE not set
1554 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1555 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1558 RTE_LOG(ERR, PMD, "Incorrect Flow control flag (%d)\n",
1563 ret = dpni_set_link_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
1566 "Unable to set Link configuration (err=%d)\n",
1570 dpaa2_dev_set_link_up(dev);
1576 dpaa2_dev_rss_hash_update(struct rte_eth_dev *dev,
1577 struct rte_eth_rss_conf *rss_conf)
1579 struct rte_eth_dev_data *data = dev->data;
1580 struct rte_eth_conf *eth_conf = &data->dev_conf;
1583 PMD_INIT_FUNC_TRACE();
1585 if (rss_conf->rss_hf) {
1586 ret = dpaa2_setup_flow_dist(dev, rss_conf->rss_hf);
1588 PMD_INIT_LOG(ERR, "unable to set flow dist");
1592 ret = dpaa2_remove_flow_dist(dev, 0);
1594 PMD_INIT_LOG(ERR, "unable to remove flow dist");
1598 eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_conf->rss_hf;
1603 dpaa2_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1604 struct rte_eth_rss_conf *rss_conf)
1606 struct rte_eth_dev_data *data = dev->data;
1607 struct rte_eth_conf *eth_conf = &data->dev_conf;
1609 /* dpaa2 does not support rss_key, so length should be 0*/
1610 rss_conf->rss_key_len = 0;
1611 rss_conf->rss_hf = eth_conf->rx_adv_conf.rss_conf.rss_hf;
1615 int dpaa2_eth_eventq_attach(const struct rte_eth_dev *dev,
1616 int eth_rx_queue_id,
1618 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
1620 struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
1621 struct fsl_mc_io *dpni = (struct fsl_mc_io *)eth_priv->hw;
1622 struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
1623 uint8_t flow_id = dpaa2_ethq->flow_id;
1624 struct dpni_queue cfg;
1628 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL)
1629 dpaa2_ethq->cb = dpaa2_dev_process_parallel_event;
1630 else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC)
1631 dpaa2_ethq->cb = dpaa2_dev_process_atomic_event;
1635 memset(&cfg, 0, sizeof(struct dpni_queue));
1636 options = DPNI_QUEUE_OPT_DEST;
1637 cfg.destination.type = DPNI_DEST_DPCON;
1638 cfg.destination.id = dpcon_id;
1639 cfg.destination.priority = queue_conf->ev.priority;
1641 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC) {
1642 options |= DPNI_QUEUE_OPT_HOLD_ACTIVE;
1643 cfg.destination.hold_active = 1;
1646 options |= DPNI_QUEUE_OPT_USER_CTX;
1647 cfg.user_context = (size_t)(dpaa2_ethq);
1649 ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
1650 dpaa2_ethq->tc_index, flow_id, options, &cfg);
1652 RTE_LOG(ERR, PMD, "Error in dpni_set_queue: ret: %d\n", ret);
1656 memcpy(&dpaa2_ethq->ev, &queue_conf->ev, sizeof(struct rte_event));
1661 int dpaa2_eth_eventq_detach(const struct rte_eth_dev *dev,
1662 int eth_rx_queue_id)
1664 struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
1665 struct fsl_mc_io *dpni = (struct fsl_mc_io *)eth_priv->hw;
1666 struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
1667 uint8_t flow_id = dpaa2_ethq->flow_id;
1668 struct dpni_queue cfg;
1672 memset(&cfg, 0, sizeof(struct dpni_queue));
1673 options = DPNI_QUEUE_OPT_DEST;
1674 cfg.destination.type = DPNI_DEST_NONE;
1676 ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
1677 dpaa2_ethq->tc_index, flow_id, options, &cfg);
1679 RTE_LOG(ERR, PMD, "Error in dpni_set_queue: ret: %d\n", ret);
1684 static struct eth_dev_ops dpaa2_ethdev_ops = {
1685 .dev_configure = dpaa2_eth_dev_configure,
1686 .dev_start = dpaa2_dev_start,
1687 .dev_stop = dpaa2_dev_stop,
1688 .dev_close = dpaa2_dev_close,
1689 .promiscuous_enable = dpaa2_dev_promiscuous_enable,
1690 .promiscuous_disable = dpaa2_dev_promiscuous_disable,
1691 .allmulticast_enable = dpaa2_dev_allmulticast_enable,
1692 .allmulticast_disable = dpaa2_dev_allmulticast_disable,
1693 .dev_set_link_up = dpaa2_dev_set_link_up,
1694 .dev_set_link_down = dpaa2_dev_set_link_down,
1695 .link_update = dpaa2_dev_link_update,
1696 .stats_get = dpaa2_dev_stats_get,
1697 .xstats_get = dpaa2_dev_xstats_get,
1698 .xstats_get_by_id = dpaa2_xstats_get_by_id,
1699 .xstats_get_names_by_id = dpaa2_xstats_get_names_by_id,
1700 .xstats_get_names = dpaa2_xstats_get_names,
1701 .stats_reset = dpaa2_dev_stats_reset,
1702 .xstats_reset = dpaa2_dev_stats_reset,
1703 .fw_version_get = dpaa2_fw_version_get,
1704 .dev_infos_get = dpaa2_dev_info_get,
1705 .dev_supported_ptypes_get = dpaa2_supported_ptypes_get,
1706 .mtu_set = dpaa2_dev_mtu_set,
1707 .vlan_filter_set = dpaa2_vlan_filter_set,
1708 .vlan_offload_set = dpaa2_vlan_offload_set,
1709 .rx_queue_setup = dpaa2_dev_rx_queue_setup,
1710 .rx_queue_release = dpaa2_dev_rx_queue_release,
1711 .tx_queue_setup = dpaa2_dev_tx_queue_setup,
1712 .tx_queue_release = dpaa2_dev_tx_queue_release,
1713 .rx_queue_count = dpaa2_dev_rx_queue_count,
1714 .flow_ctrl_get = dpaa2_flow_ctrl_get,
1715 .flow_ctrl_set = dpaa2_flow_ctrl_set,
1716 .mac_addr_add = dpaa2_dev_add_mac_addr,
1717 .mac_addr_remove = dpaa2_dev_remove_mac_addr,
1718 .mac_addr_set = dpaa2_dev_set_mac_addr,
1719 .rss_hash_update = dpaa2_dev_rss_hash_update,
1720 .rss_hash_conf_get = dpaa2_dev_rss_hash_conf_get,
1724 dpaa2_dev_init(struct rte_eth_dev *eth_dev)
1726 struct rte_device *dev = eth_dev->device;
1727 struct rte_dpaa2_device *dpaa2_dev;
1728 struct fsl_mc_io *dpni_dev;
1729 struct dpni_attr attr;
1730 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
1731 struct dpni_buffer_layout layout;
1734 PMD_INIT_FUNC_TRACE();
1736 /* For secondary processes, the primary has done all the work */
1737 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1740 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
1742 hw_id = dpaa2_dev->object_id;
1744 dpni_dev = rte_malloc(NULL, sizeof(struct fsl_mc_io), 0);
1746 PMD_INIT_LOG(ERR, "malloc failed for dpni device\n");
1750 dpni_dev->regs = rte_mcp_ptr_list[0];
1751 ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
1754 "Failure in opening dpni@%d with err code %d\n",
1760 /* Clean the device first */
1761 ret = dpni_reset(dpni_dev, CMD_PRI_LOW, priv->token);
1764 "Failure cleaning dpni@%d with err code %d\n",
1769 ret = dpni_get_attributes(dpni_dev, CMD_PRI_LOW, priv->token, &attr);
1772 "Failure in get dpni@%d attribute, err code %d\n",
1777 priv->num_rx_tc = attr.num_rx_tcs;
1779 /* Resetting the "num_rx_queues" to equal number of queues in first TC
1780 * as only one TC is supported on Rx Side. Once Multiple TCs will be
1781 * in use for Rx processing then this will be changed or removed.
1783 priv->nb_rx_queues = attr.num_queues;
1785 /* Using number of TX queues as number of TX TCs */
1786 priv->nb_tx_queues = attr.num_tx_tcs;
1788 PMD_DRV_LOG(DEBUG, "RX-TC= %d, nb_rx_queues= %d, nb_tx_queues=%d",
1789 priv->num_rx_tc, priv->nb_rx_queues, priv->nb_tx_queues);
1791 priv->hw = dpni_dev;
1792 priv->hw_id = hw_id;
1793 priv->options = attr.options;
1794 priv->max_mac_filters = attr.mac_filter_entries;
1795 priv->max_vlan_filters = attr.vlan_filter_entries;
1798 /* Allocate memory for hardware structure for queues */
1799 ret = dpaa2_alloc_rx_tx_queues(eth_dev);
1801 PMD_INIT_LOG(ERR, "dpaa2_alloc_rx_tx_queuesFailed\n");
1805 /* Allocate memory for storing MAC addresses */
1806 eth_dev->data->mac_addrs = rte_zmalloc("dpni",
1807 ETHER_ADDR_LEN * attr.mac_filter_entries, 0);
1808 if (eth_dev->data->mac_addrs == NULL) {
1810 "Failed to allocate %d bytes needed to store MAC addresses",
1811 ETHER_ADDR_LEN * attr.mac_filter_entries);
1816 ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
1818 (uint8_t *)(eth_dev->data->mac_addrs[0].addr_bytes));
1820 PMD_INIT_LOG(ERR, "DPNI get mac address failed:Err Code = %d\n",
1825 /* ... tx buffer layout ... */
1826 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
1827 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
1828 layout.pass_frame_status = 1;
1829 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
1830 DPNI_QUEUE_TX, &layout);
1832 PMD_INIT_LOG(ERR, "Error (%d) in setting tx buffer layout",
1837 /* ... tx-conf and error buffer layout ... */
1838 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
1839 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
1840 layout.pass_frame_status = 1;
1841 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
1842 DPNI_QUEUE_TX_CONFIRM, &layout);
1844 PMD_INIT_LOG(ERR, "Error (%d) in setting tx-conf buffer layout",
1849 eth_dev->dev_ops = &dpaa2_ethdev_ops;
1851 eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
1852 eth_dev->tx_pkt_burst = dpaa2_dev_tx;
1853 rte_fslmc_vfio_dmamap();
1855 RTE_LOG(INFO, PMD, "%s: netdev created\n", eth_dev->data->name);
1858 dpaa2_dev_uninit(eth_dev);
1863 dpaa2_dev_uninit(struct rte_eth_dev *eth_dev)
1865 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
1866 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1868 struct dpaa2_queue *dpaa2_q;
1870 PMD_INIT_FUNC_TRACE();
1872 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1876 PMD_INIT_LOG(WARNING, "Already closed or not started");
1880 dpaa2_dev_close(eth_dev);
1882 if (priv->rx_vq[0]) {
1883 /* cleaning up queue storage */
1884 for (i = 0; i < priv->nb_rx_queues; i++) {
1885 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
1886 if (dpaa2_q->q_storage)
1887 rte_free(dpaa2_q->q_storage);
1889 /*free the all queue memory */
1890 rte_free(priv->rx_vq[0]);
1891 priv->rx_vq[0] = NULL;
1894 /* free memory for storing MAC addresses */
1895 if (eth_dev->data->mac_addrs) {
1896 rte_free(eth_dev->data->mac_addrs);
1897 eth_dev->data->mac_addrs = NULL;
1900 /* Close the device at underlying layer*/
1901 ret = dpni_close(dpni, CMD_PRI_LOW, priv->token);
1904 "Failure closing dpni device with err code %d\n",
1908 /* Free the allocated memory for ethernet private data and dpni*/
1912 eth_dev->dev_ops = NULL;
1913 eth_dev->rx_pkt_burst = NULL;
1914 eth_dev->tx_pkt_burst = NULL;
1916 RTE_LOG(INFO, PMD, "%s: netdev created\n", eth_dev->data->name);
1921 rte_dpaa2_probe(struct rte_dpaa2_driver *dpaa2_drv,
1922 struct rte_dpaa2_device *dpaa2_dev)
1924 struct rte_eth_dev *eth_dev;
1927 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1928 eth_dev = rte_eth_dev_allocate(dpaa2_dev->device.name);
1931 eth_dev->data->dev_private = rte_zmalloc(
1932 "ethdev private structure",
1933 sizeof(struct dpaa2_dev_priv),
1934 RTE_CACHE_LINE_SIZE);
1935 if (eth_dev->data->dev_private == NULL) {
1936 PMD_INIT_LOG(CRIT, "Cannot allocate memzone for"
1937 " private port data\n");
1938 rte_eth_dev_release_port(eth_dev);
1942 eth_dev = rte_eth_dev_attach_secondary(dpaa2_dev->device.name);
1947 eth_dev->device = &dpaa2_dev->device;
1948 eth_dev->device->driver = &dpaa2_drv->driver;
1950 dpaa2_dev->eth_dev = eth_dev;
1951 eth_dev->data->rx_mbuf_alloc_failed = 0;
1953 if (dpaa2_drv->drv_flags & RTE_DPAA2_DRV_INTR_LSC)
1954 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
1956 /* Invoke PMD device initialization function */
1957 diag = dpaa2_dev_init(eth_dev);
1961 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1962 rte_free(eth_dev->data->dev_private);
1963 rte_eth_dev_release_port(eth_dev);
1968 rte_dpaa2_remove(struct rte_dpaa2_device *dpaa2_dev)
1970 struct rte_eth_dev *eth_dev;
1972 eth_dev = dpaa2_dev->eth_dev;
1973 dpaa2_dev_uninit(eth_dev);
1975 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1976 rte_free(eth_dev->data->dev_private);
1977 rte_eth_dev_release_port(eth_dev);
1982 static struct rte_dpaa2_driver rte_dpaa2_pmd = {
1983 .drv_flags = RTE_DPAA2_DRV_INTR_LSC | RTE_DPAA2_DRV_IOVA_AS_VA,
1984 .drv_type = DPAA2_ETH,
1985 .probe = rte_dpaa2_probe,
1986 .remove = rte_dpaa2_remove,
1989 RTE_PMD_REGISTER_DPAA2(net_dpaa2, rte_dpaa2_pmd);