1 /* * SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
12 #include <rte_ethdev.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"
29 struct rte_dpaa2_xstats_name_off {
30 char name[RTE_ETH_XSTATS_NAME_SIZE];
31 uint8_t page_id; /* dpni statistics page id */
32 uint8_t stats_id; /* stats id in the given page */
35 static const struct rte_dpaa2_xstats_name_off dpaa2_xstats_strings[] = {
36 {"ingress_multicast_frames", 0, 2},
37 {"ingress_multicast_bytes", 0, 3},
38 {"ingress_broadcast_frames", 0, 4},
39 {"ingress_broadcast_bytes", 0, 5},
40 {"egress_multicast_frames", 1, 2},
41 {"egress_multicast_bytes", 1, 3},
42 {"egress_broadcast_frames", 1, 4},
43 {"egress_broadcast_bytes", 1, 5},
44 {"ingress_filtered_frames", 2, 0},
45 {"ingress_discarded_frames", 2, 1},
46 {"ingress_nobuffer_discards", 2, 2},
47 {"egress_discarded_frames", 2, 3},
48 {"egress_confirmed_frames", 2, 4},
51 static struct rte_dpaa2_driver rte_dpaa2_pmd;
52 static int dpaa2_dev_uninit(struct rte_eth_dev *eth_dev);
53 static int dpaa2_dev_link_update(struct rte_eth_dev *dev,
54 int wait_to_complete);
55 static int dpaa2_dev_set_link_up(struct rte_eth_dev *dev);
56 static int dpaa2_dev_set_link_down(struct rte_eth_dev *dev);
57 static int dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
60 * Atomically reads the link status information from global
61 * structure rte_eth_dev.
64 * - Pointer to the structure rte_eth_dev to read from.
65 * - Pointer to the buffer to be saved with the link status.
69 * - On failure, negative value.
72 dpaa2_dev_atomic_read_link_status(struct rte_eth_dev *dev,
73 struct rte_eth_link *link)
75 struct rte_eth_link *dst = link;
76 struct rte_eth_link *src = &dev->data->dev_link;
78 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
79 *(uint64_t *)src) == 0)
86 * Atomically writes the link status information into global
87 * structure rte_eth_dev.
90 * - Pointer to the structure rte_eth_dev to read from.
91 * - Pointer to the buffer to be saved with the link status.
95 * - On failure, negative value.
98 dpaa2_dev_atomic_write_link_status(struct rte_eth_dev *dev,
99 struct rte_eth_link *link)
101 struct rte_eth_link *dst = &dev->data->dev_link;
102 struct rte_eth_link *src = link;
104 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
105 *(uint64_t *)src) == 0)
112 dpaa2_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
115 struct dpaa2_dev_priv *priv = dev->data->dev_private;
116 struct fsl_mc_io *dpni = priv->hw;
118 PMD_INIT_FUNC_TRACE();
121 RTE_LOG(ERR, PMD, "dpni is NULL\n");
126 ret = dpni_add_vlan_id(dpni, CMD_PRI_LOW,
127 priv->token, vlan_id);
129 ret = dpni_remove_vlan_id(dpni, CMD_PRI_LOW,
130 priv->token, vlan_id);
133 PMD_DRV_LOG(ERR, "ret = %d Unable to add/rem vlan %d hwid =%d",
134 ret, vlan_id, priv->hw_id);
140 dpaa2_vlan_offload_set(struct rte_eth_dev *dev, int mask)
142 struct dpaa2_dev_priv *priv = dev->data->dev_private;
143 struct fsl_mc_io *dpni = priv->hw;
146 PMD_INIT_FUNC_TRACE();
148 if (mask & ETH_VLAN_FILTER_MASK) {
149 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
150 ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
153 ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
156 RTE_LOG(ERR, PMD, "Unable to set vlan filter = %d\n",
160 if (mask & ETH_VLAN_EXTEND_MASK) {
161 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
163 "VLAN extend offload not supported\n");
170 dpaa2_fw_version_get(struct rte_eth_dev *dev,
175 struct dpaa2_dev_priv *priv = dev->data->dev_private;
176 struct fsl_mc_io *dpni = priv->hw;
177 struct mc_soc_version mc_plat_info = {0};
178 struct mc_version mc_ver_info = {0};
180 PMD_INIT_FUNC_TRACE();
182 if (mc_get_soc_version(dpni, CMD_PRI_LOW, &mc_plat_info))
183 RTE_LOG(WARNING, PMD, "\tmc_get_soc_version failed\n");
185 if (mc_get_version(dpni, CMD_PRI_LOW, &mc_ver_info))
186 RTE_LOG(WARNING, PMD, "\tmc_get_version failed\n");
188 ret = snprintf(fw_version, fw_size,
193 mc_ver_info.revision);
195 ret += 1; /* add the size of '\0' */
196 if (fw_size < (uint32_t)ret)
203 dpaa2_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
205 struct dpaa2_dev_priv *priv = dev->data->dev_private;
207 PMD_INIT_FUNC_TRACE();
209 dev_info->if_index = priv->hw_id;
211 dev_info->max_mac_addrs = priv->max_mac_filters;
212 dev_info->max_rx_pktlen = DPAA2_MAX_RX_PKT_LEN;
213 dev_info->min_rx_bufsize = DPAA2_MIN_RX_BUF_SIZE;
214 dev_info->max_rx_queues = (uint16_t)priv->nb_rx_queues;
215 dev_info->max_tx_queues = (uint16_t)priv->nb_tx_queues;
216 dev_info->rx_offload_capa =
217 DEV_RX_OFFLOAD_IPV4_CKSUM |
218 DEV_RX_OFFLOAD_UDP_CKSUM |
219 DEV_RX_OFFLOAD_TCP_CKSUM |
220 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM;
221 dev_info->tx_offload_capa =
222 DEV_TX_OFFLOAD_IPV4_CKSUM |
223 DEV_TX_OFFLOAD_UDP_CKSUM |
224 DEV_TX_OFFLOAD_TCP_CKSUM |
225 DEV_TX_OFFLOAD_SCTP_CKSUM |
226 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
227 dev_info->speed_capa = ETH_LINK_SPEED_1G |
228 ETH_LINK_SPEED_2_5G |
233 dpaa2_alloc_rx_tx_queues(struct rte_eth_dev *dev)
235 struct dpaa2_dev_priv *priv = dev->data->dev_private;
238 struct dpaa2_queue *mc_q, *mcq;
241 struct dpaa2_queue *dpaa2_q;
243 PMD_INIT_FUNC_TRACE();
245 tot_queues = priv->nb_rx_queues + priv->nb_tx_queues;
246 mc_q = rte_malloc(NULL, sizeof(struct dpaa2_queue) * tot_queues,
247 RTE_CACHE_LINE_SIZE);
249 PMD_INIT_LOG(ERR, "malloc failed for rx/tx queues\n");
253 for (i = 0; i < priv->nb_rx_queues; i++) {
255 priv->rx_vq[i] = mc_q++;
256 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
257 dpaa2_q->q_storage = rte_malloc("dq_storage",
258 sizeof(struct queue_storage_info_t),
259 RTE_CACHE_LINE_SIZE);
260 if (!dpaa2_q->q_storage)
263 memset(dpaa2_q->q_storage, 0,
264 sizeof(struct queue_storage_info_t));
265 if (dpaa2_alloc_dq_storage(dpaa2_q->q_storage))
269 for (i = 0; i < priv->nb_tx_queues; i++) {
271 mc_q->flow_id = 0xffff;
272 priv->tx_vq[i] = mc_q++;
273 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
274 dpaa2_q->cscn = rte_malloc(NULL,
275 sizeof(struct qbman_result), 16);
281 for (dist_idx = 0; dist_idx < priv->nb_rx_queues; dist_idx++) {
282 mcq = (struct dpaa2_queue *)priv->rx_vq[vq_id];
283 mcq->tc_index = DPAA2_DEF_TC;
284 mcq->flow_id = dist_idx;
292 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
293 rte_free(dpaa2_q->cscn);
294 priv->tx_vq[i--] = NULL;
296 i = priv->nb_rx_queues;
299 mc_q = priv->rx_vq[0];
301 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
302 dpaa2_free_dq_storage(dpaa2_q->q_storage);
303 rte_free(dpaa2_q->q_storage);
304 priv->rx_vq[i--] = NULL;
311 dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
313 struct dpaa2_dev_priv *priv = dev->data->dev_private;
314 struct fsl_mc_io *dpni = priv->hw;
315 struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
316 int rx_ip_csum_offload = false;
319 PMD_INIT_FUNC_TRACE();
321 if (eth_conf->rxmode.jumbo_frame == 1) {
322 if (eth_conf->rxmode.max_rx_pkt_len <= DPAA2_MAX_RX_PKT_LEN) {
323 ret = dpaa2_dev_mtu_set(dev,
324 eth_conf->rxmode.max_rx_pkt_len);
327 "unable to set mtu. check config\n");
335 if (eth_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) {
336 ret = dpaa2_setup_flow_dist(dev,
337 eth_conf->rx_adv_conf.rss_conf.rss_hf);
339 PMD_INIT_LOG(ERR, "unable to set flow distribution."
340 "please check queue config\n");
345 if (eth_conf->rxmode.hw_ip_checksum)
346 rx_ip_csum_offload = true;
348 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
349 DPNI_OFF_RX_L3_CSUM, rx_ip_csum_offload);
351 PMD_INIT_LOG(ERR, "Error to set RX l3 csum:Error = %d\n", ret);
355 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
356 DPNI_OFF_RX_L4_CSUM, rx_ip_csum_offload);
358 PMD_INIT_LOG(ERR, "Error to get RX l4 csum:Error = %d\n", ret);
362 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
363 DPNI_OFF_TX_L3_CSUM, true);
365 PMD_INIT_LOG(ERR, "Error to set TX l3 csum:Error = %d\n", ret);
369 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
370 DPNI_OFF_TX_L4_CSUM, true);
372 PMD_INIT_LOG(ERR, "Error to get TX l4 csum:Error = %d\n", ret);
376 /* update the current status */
377 dpaa2_dev_link_update(dev, 0);
382 /* Function to setup RX flow information. It contains traffic class ID,
383 * flow ID, destination configuration etc.
386 dpaa2_dev_rx_queue_setup(struct rte_eth_dev *dev,
387 uint16_t rx_queue_id,
388 uint16_t nb_rx_desc __rte_unused,
389 unsigned int socket_id __rte_unused,
390 const struct rte_eth_rxconf *rx_conf __rte_unused,
391 struct rte_mempool *mb_pool)
393 struct dpaa2_dev_priv *priv = dev->data->dev_private;
394 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
395 struct mc_soc_version mc_plat_info = {0};
396 struct dpaa2_queue *dpaa2_q;
397 struct dpni_queue cfg;
403 PMD_INIT_FUNC_TRACE();
405 PMD_DRV_LOG(DEBUG, "dev =%p, queue =%d, pool = %p, conf =%p",
406 dev, rx_queue_id, mb_pool, rx_conf);
408 if (!priv->bp_list || priv->bp_list->mp != mb_pool) {
409 bpid = mempool_to_bpid(mb_pool);
410 ret = dpaa2_attach_bp_list(priv,
411 rte_dpaa2_bpid_info[bpid].bp_list);
415 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
416 dpaa2_q->mb_pool = mb_pool; /**< mbuf pool to populate RX ring. */
418 /*Get the flow id from given VQ id*/
419 flow_id = rx_queue_id % priv->nb_rx_queues;
420 memset(&cfg, 0, sizeof(struct dpni_queue));
422 options = options | DPNI_QUEUE_OPT_USER_CTX;
423 cfg.user_context = (uint64_t)(dpaa2_q);
425 /*if ls2088 or rev2 device, enable the stashing */
427 if (mc_get_soc_version(dpni, CMD_PRI_LOW, &mc_plat_info))
428 PMD_INIT_LOG(ERR, "\tmc_get_soc_version failed\n");
430 if ((mc_plat_info.svr & 0xffff0000) != SVR_LS2080A) {
431 options |= DPNI_QUEUE_OPT_FLC;
432 cfg.flc.stash_control = true;
433 cfg.flc.value &= 0xFFFFFFFFFFFFFFC0;
434 /* 00 00 00 - last 6 bit represent annotation, context stashing,
435 * data stashing setting 01 01 00 (0x14) to enable
436 * 1 line data, 1 line annotation
438 cfg.flc.value |= 0x14;
440 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_RX,
441 dpaa2_q->tc_index, flow_id, options, &cfg);
443 PMD_INIT_LOG(ERR, "Error in setting the rx flow: = %d\n", ret);
447 if (!(priv->flags & DPAA2_RX_TAILDROP_OFF)) {
448 struct dpni_taildrop taildrop;
451 /*enabling per rx queue congestion control */
452 taildrop.threshold = CONG_THRESHOLD_RX_Q;
453 taildrop.units = DPNI_CONGESTION_UNIT_BYTES;
454 taildrop.oal = CONG_RX_OAL;
455 PMD_DRV_LOG(DEBUG, "Enabling Early Drop on queue = %d",
457 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
458 DPNI_CP_QUEUE, DPNI_QUEUE_RX,
459 dpaa2_q->tc_index, flow_id, &taildrop);
461 PMD_INIT_LOG(ERR, "Error in setting the rx flow"
462 " err : = %d\n", ret);
467 dev->data->rx_queues[rx_queue_id] = dpaa2_q;
472 dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
473 uint16_t tx_queue_id,
474 uint16_t nb_tx_desc __rte_unused,
475 unsigned int socket_id __rte_unused,
476 const struct rte_eth_txconf *tx_conf __rte_unused)
478 struct dpaa2_dev_priv *priv = dev->data->dev_private;
479 struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)
480 priv->tx_vq[tx_queue_id];
481 struct fsl_mc_io *dpni = priv->hw;
482 struct dpni_queue tx_conf_cfg;
483 struct dpni_queue tx_flow_cfg;
484 uint8_t options = 0, flow_id;
488 PMD_INIT_FUNC_TRACE();
490 /* Return if queue already configured */
491 if (dpaa2_q->flow_id != 0xffff) {
492 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
496 memset(&tx_conf_cfg, 0, sizeof(struct dpni_queue));
497 memset(&tx_flow_cfg, 0, sizeof(struct dpni_queue));
502 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
503 tc_id, flow_id, options, &tx_flow_cfg);
505 PMD_INIT_LOG(ERR, "Error in setting the tx flow: "
506 "tc_id=%d, flow =%d ErrorCode = %x\n",
507 tc_id, flow_id, -ret);
511 dpaa2_q->flow_id = flow_id;
513 if (tx_queue_id == 0) {
514 /*Set tx-conf and error configuration*/
515 ret = dpni_set_tx_confirmation_mode(dpni, CMD_PRI_LOW,
519 PMD_INIT_LOG(ERR, "Error in set tx conf mode settings"
520 " ErrorCode = %x", ret);
524 dpaa2_q->tc_index = tc_id;
526 if (!(priv->flags & DPAA2_TX_CGR_OFF)) {
527 struct dpni_congestion_notification_cfg cong_notif_cfg;
529 cong_notif_cfg.units = DPNI_CONGESTION_UNIT_FRAMES;
530 cong_notif_cfg.threshold_entry = CONG_ENTER_TX_THRESHOLD;
531 /* Notify that the queue is not congested when the data in
532 * the queue is below this thershold.
534 cong_notif_cfg.threshold_exit = CONG_EXIT_TX_THRESHOLD;
535 cong_notif_cfg.message_ctx = 0;
536 cong_notif_cfg.message_iova = (uint64_t)dpaa2_q->cscn;
537 cong_notif_cfg.dest_cfg.dest_type = DPNI_DEST_NONE;
538 cong_notif_cfg.notification_mode =
539 DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
540 DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
541 DPNI_CONG_OPT_COHERENT_WRITE;
543 ret = dpni_set_congestion_notification(dpni, CMD_PRI_LOW,
550 "Error in setting tx congestion notification: = %d",
555 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
560 dpaa2_dev_rx_queue_release(void *q __rte_unused)
562 PMD_INIT_FUNC_TRACE();
566 dpaa2_dev_tx_queue_release(void *q __rte_unused)
568 PMD_INIT_FUNC_TRACE();
571 static const uint32_t *
572 dpaa2_supported_ptypes_get(struct rte_eth_dev *dev)
574 static const uint32_t ptypes[] = {
575 /*todo -= add more types */
578 RTE_PTYPE_L3_IPV4_EXT,
580 RTE_PTYPE_L3_IPV6_EXT,
588 if (dev->rx_pkt_burst == dpaa2_dev_prefetch_rx)
594 * Dpaa2 link Interrupt handler
597 * The address of parameter (struct rte_eth_dev *) regsitered before.
603 dpaa2_interrupt_handler(void *param)
605 struct rte_eth_dev *dev = param;
606 struct dpaa2_dev_priv *priv = dev->data->dev_private;
607 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
609 int irq_index = DPNI_IRQ_INDEX;
610 unsigned int status = 0, clear = 0;
612 PMD_INIT_FUNC_TRACE();
615 RTE_LOG(ERR, PMD, "dpni is NULL");
619 ret = dpni_get_irq_status(dpni, CMD_PRI_LOW, priv->token,
622 RTE_LOG(ERR, PMD, "Can't get irq status (err %d)", ret);
627 if (status & DPNI_IRQ_EVENT_LINK_CHANGED) {
628 clear = DPNI_IRQ_EVENT_LINK_CHANGED;
629 dpaa2_dev_link_update(dev, 0);
630 /* calling all the apps registered for link status event */
631 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
635 ret = dpni_clear_irq_status(dpni, CMD_PRI_LOW, priv->token,
638 RTE_LOG(ERR, PMD, "Can't clear irq status (err %d)", ret);
642 dpaa2_eth_setup_irqs(struct rte_eth_dev *dev, int enable)
645 struct dpaa2_dev_priv *priv = dev->data->dev_private;
646 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
647 int irq_index = DPNI_IRQ_INDEX;
648 unsigned int mask = DPNI_IRQ_EVENT_LINK_CHANGED;
650 PMD_INIT_FUNC_TRACE();
652 err = dpni_set_irq_mask(dpni, CMD_PRI_LOW, priv->token,
655 PMD_INIT_LOG(ERR, "Error: dpni_set_irq_mask():%d (%s)", err,
660 err = dpni_set_irq_enable(dpni, CMD_PRI_LOW, priv->token,
663 PMD_INIT_LOG(ERR, "Error: dpni_set_irq_enable():%d (%s)", err,
670 dpaa2_dev_start(struct rte_eth_dev *dev)
672 struct rte_device *rdev = dev->device;
673 struct rte_dpaa2_device *dpaa2_dev;
674 struct rte_eth_dev_data *data = dev->data;
675 struct dpaa2_dev_priv *priv = data->dev_private;
676 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
677 struct dpni_queue cfg;
678 struct dpni_error_cfg err_cfg;
680 struct dpni_queue_id qid;
681 struct dpaa2_queue *dpaa2_q;
683 struct rte_intr_handle *intr_handle;
685 dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
686 intr_handle = &dpaa2_dev->intr_handle;
688 PMD_INIT_FUNC_TRACE();
690 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
692 PMD_INIT_LOG(ERR, "Failure %d in enabling dpni %d device\n",
697 /* Power up the phy. Needed to make the link go UP */
698 dpaa2_dev_set_link_up(dev);
700 ret = dpni_get_qdid(dpni, CMD_PRI_LOW, priv->token,
701 DPNI_QUEUE_TX, &qdid);
703 PMD_INIT_LOG(ERR, "Error to get qdid:ErrorCode = %d\n", ret);
708 for (i = 0; i < data->nb_rx_queues; i++) {
709 dpaa2_q = (struct dpaa2_queue *)data->rx_queues[i];
710 ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
711 DPNI_QUEUE_RX, dpaa2_q->tc_index,
712 dpaa2_q->flow_id, &cfg, &qid);
714 PMD_INIT_LOG(ERR, "Error to get flow "
715 "information Error code = %d\n", ret);
718 dpaa2_q->fqid = qid.fqid;
721 /*checksum errors, send them to normal path and set it in annotation */
722 err_cfg.errors = DPNI_ERROR_L3CE | DPNI_ERROR_L4CE;
724 err_cfg.error_action = DPNI_ERROR_ACTION_CONTINUE;
725 err_cfg.set_frame_annotation = true;
727 ret = dpni_set_errors_behavior(dpni, CMD_PRI_LOW,
728 priv->token, &err_cfg);
730 PMD_INIT_LOG(ERR, "Error to dpni_set_errors_behavior:"
734 /* VLAN Offload Settings */
735 if (priv->max_vlan_filters) {
736 ret = dpaa2_vlan_offload_set(dev, ETH_VLAN_FILTER_MASK);
738 PMD_INIT_LOG(ERR, "Error to dpaa2_vlan_offload_set:"
745 /* if the interrupts were configured on this devices*/
746 if (intr_handle && (intr_handle->fd) &&
747 (dev->data->dev_conf.intr_conf.lsc != 0)) {
748 /* Registering LSC interrupt handler */
749 rte_intr_callback_register(intr_handle,
750 dpaa2_interrupt_handler,
753 /* enable vfio intr/eventfd mapping
754 * Interrupt index 0 is required, so we can not use
757 rte_dpaa2_intr_enable(intr_handle, DPNI_IRQ_INDEX);
759 /* enable dpni_irqs */
760 dpaa2_eth_setup_irqs(dev, 1);
767 * This routine disables all traffic on the adapter by issuing a
768 * global reset on the MAC.
771 dpaa2_dev_stop(struct rte_eth_dev *dev)
773 struct dpaa2_dev_priv *priv = dev->data->dev_private;
774 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
776 struct rte_eth_link link;
777 struct rte_intr_handle *intr_handle = dev->intr_handle;
779 PMD_INIT_FUNC_TRACE();
781 /* reset interrupt callback */
782 if (intr_handle && (intr_handle->fd) &&
783 (dev->data->dev_conf.intr_conf.lsc != 0)) {
784 /*disable dpni irqs */
785 dpaa2_eth_setup_irqs(dev, 0);
787 /* disable vfio intr before callback unregister */
788 rte_dpaa2_intr_disable(intr_handle, DPNI_IRQ_INDEX);
790 /* Unregistering LSC interrupt handler */
791 rte_intr_callback_unregister(intr_handle,
792 dpaa2_interrupt_handler,
796 dpaa2_dev_set_link_down(dev);
798 ret = dpni_disable(dpni, CMD_PRI_LOW, priv->token);
800 PMD_INIT_LOG(ERR, "Failure (ret %d) in disabling dpni %d dev\n",
805 /* clear the recorded link status */
806 memset(&link, 0, sizeof(link));
807 dpaa2_dev_atomic_write_link_status(dev, &link);
811 dpaa2_dev_close(struct rte_eth_dev *dev)
813 struct rte_eth_dev_data *data = dev->data;
814 struct dpaa2_dev_priv *priv = dev->data->dev_private;
815 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
817 struct rte_eth_link link;
818 struct dpaa2_queue *dpaa2_q;
820 PMD_INIT_FUNC_TRACE();
822 for (i = 0; i < data->nb_tx_queues; i++) {
823 dpaa2_q = (struct dpaa2_queue *)data->tx_queues[i];
824 if (!dpaa2_q->cscn) {
825 rte_free(dpaa2_q->cscn);
826 dpaa2_q->cscn = NULL;
830 /* Clean the device first */
831 ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
833 PMD_INIT_LOG(ERR, "Failure cleaning dpni device with"
834 " error code %d\n", ret);
838 memset(&link, 0, sizeof(link));
839 dpaa2_dev_atomic_write_link_status(dev, &link);
843 dpaa2_dev_promiscuous_enable(
844 struct rte_eth_dev *dev)
847 struct dpaa2_dev_priv *priv = dev->data->dev_private;
848 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
850 PMD_INIT_FUNC_TRACE();
853 RTE_LOG(ERR, PMD, "dpni is NULL\n");
857 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
859 RTE_LOG(ERR, PMD, "Unable to enable U promisc mode %d\n", ret);
861 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
863 RTE_LOG(ERR, PMD, "Unable to enable M promisc mode %d\n", ret);
867 dpaa2_dev_promiscuous_disable(
868 struct rte_eth_dev *dev)
871 struct dpaa2_dev_priv *priv = dev->data->dev_private;
872 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
874 PMD_INIT_FUNC_TRACE();
877 RTE_LOG(ERR, PMD, "dpni is NULL\n");
881 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
883 RTE_LOG(ERR, PMD, "Unable to disable U promisc mode %d\n", ret);
885 if (dev->data->all_multicast == 0) {
886 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW,
890 "Unable to disable M promisc mode %d\n",
896 dpaa2_dev_allmulticast_enable(
897 struct rte_eth_dev *dev)
900 struct dpaa2_dev_priv *priv = dev->data->dev_private;
901 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
903 PMD_INIT_FUNC_TRACE();
906 RTE_LOG(ERR, PMD, "dpni is NULL\n");
910 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
912 RTE_LOG(ERR, PMD, "Unable to enable multicast mode %d\n", ret);
916 dpaa2_dev_allmulticast_disable(struct rte_eth_dev *dev)
919 struct dpaa2_dev_priv *priv = dev->data->dev_private;
920 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
922 PMD_INIT_FUNC_TRACE();
925 RTE_LOG(ERR, PMD, "dpni is NULL\n");
929 /* must remain on for all promiscuous */
930 if (dev->data->promiscuous == 1)
933 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
935 RTE_LOG(ERR, PMD, "Unable to disable multicast mode %d\n", ret);
939 dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
942 struct dpaa2_dev_priv *priv = dev->data->dev_private;
943 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
944 uint32_t frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
946 PMD_INIT_FUNC_TRACE();
949 RTE_LOG(ERR, PMD, "dpni is NULL\n");
953 /* check that mtu is within the allowed range */
954 if ((mtu < ETHER_MIN_MTU) || (frame_size > DPAA2_MAX_RX_PKT_LEN))
957 if (frame_size > ETHER_MAX_LEN)
958 dev->data->dev_conf.rxmode.jumbo_frame = 1;
960 dev->data->dev_conf.rxmode.jumbo_frame = 0;
962 /* Set the Max Rx frame length as 'mtu' +
963 * Maximum Ethernet header length
965 ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
966 mtu + ETH_VLAN_HLEN);
968 PMD_DRV_LOG(ERR, "setting the max frame length failed");
971 PMD_DRV_LOG(INFO, "MTU is configured %d for the device", mtu);
976 dpaa2_dev_add_mac_addr(struct rte_eth_dev *dev,
977 struct ether_addr *addr,
978 __rte_unused uint32_t index,
979 __rte_unused uint32_t pool)
982 struct dpaa2_dev_priv *priv = dev->data->dev_private;
983 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
985 PMD_INIT_FUNC_TRACE();
988 RTE_LOG(ERR, PMD, "dpni is NULL\n");
992 ret = dpni_add_mac_addr(dpni, CMD_PRI_LOW,
993 priv->token, addr->addr_bytes);
996 "error: Adding the MAC ADDR failed: err = %d\n", ret);
1001 dpaa2_dev_remove_mac_addr(struct rte_eth_dev *dev,
1005 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1006 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1007 struct rte_eth_dev_data *data = dev->data;
1008 struct ether_addr *macaddr;
1010 PMD_INIT_FUNC_TRACE();
1012 macaddr = &data->mac_addrs[index];
1015 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1019 ret = dpni_remove_mac_addr(dpni, CMD_PRI_LOW,
1020 priv->token, macaddr->addr_bytes);
1023 "error: Removing the MAC ADDR failed: err = %d\n", ret);
1027 dpaa2_dev_set_mac_addr(struct rte_eth_dev *dev,
1028 struct ether_addr *addr)
1031 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1032 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1034 PMD_INIT_FUNC_TRACE();
1037 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1041 ret = dpni_set_primary_mac_addr(dpni, CMD_PRI_LOW,
1042 priv->token, addr->addr_bytes);
1046 "error: Setting the MAC ADDR failed %d\n", ret);
1049 int dpaa2_dev_stats_get(struct rte_eth_dev *dev,
1050 struct rte_eth_stats *stats)
1052 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1053 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1055 uint8_t page0 = 0, page1 = 1, page2 = 2;
1056 union dpni_statistics value;
1058 memset(&value, 0, sizeof(union dpni_statistics));
1060 PMD_INIT_FUNC_TRACE();
1063 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1068 RTE_LOG(ERR, PMD, "stats is NULL\n");
1072 /*Get Counters from page_0*/
1073 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1078 stats->ipackets = value.page_0.ingress_all_frames;
1079 stats->ibytes = value.page_0.ingress_all_bytes;
1081 /*Get Counters from page_1*/
1082 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1087 stats->opackets = value.page_1.egress_all_frames;
1088 stats->obytes = value.page_1.egress_all_bytes;
1090 /*Get Counters from page_2*/
1091 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1096 /* Ingress drop frame count due to configured rules */
1097 stats->ierrors = value.page_2.ingress_filtered_frames;
1098 /* Ingress drop frame count due to error */
1099 stats->ierrors += value.page_2.ingress_discarded_frames;
1101 stats->oerrors = value.page_2.egress_discarded_frames;
1102 stats->imissed = value.page_2.ingress_nobuffer_discards;
1107 RTE_LOG(ERR, PMD, "Operation not completed:Error Code = %d\n", retcode);
1112 dpaa2_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1115 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1116 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1118 union dpni_statistics value[3] = {};
1119 unsigned int i = 0, num = RTE_DIM(dpaa2_xstats_strings);
1127 /* Get Counters from page_0*/
1128 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1133 /* Get Counters from page_1*/
1134 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1139 /* Get Counters from page_2*/
1140 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1145 for (i = 0; i < num; i++) {
1147 xstats[i].value = value[dpaa2_xstats_strings[i].page_id].
1148 raw.counter[dpaa2_xstats_strings[i].stats_id];
1152 RTE_LOG(ERR, PMD, "Error in obtaining extended stats (%d)\n", retcode);
1157 dpaa2_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1158 struct rte_eth_xstat_name *xstats_names,
1159 __rte_unused unsigned int limit)
1161 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1163 if (xstats_names != NULL)
1164 for (i = 0; i < stat_cnt; i++)
1165 snprintf(xstats_names[i].name,
1166 sizeof(xstats_names[i].name),
1168 dpaa2_xstats_strings[i].name);
1174 dpaa2_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1175 uint64_t *values, unsigned int n)
1177 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1178 uint64_t values_copy[stat_cnt];
1181 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1182 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1184 union dpni_statistics value[3] = {};
1192 /* Get Counters from page_0*/
1193 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1198 /* Get Counters from page_1*/
1199 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1204 /* Get Counters from page_2*/
1205 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1210 for (i = 0; i < stat_cnt; i++) {
1211 values[i] = value[dpaa2_xstats_strings[i].page_id].
1212 raw.counter[dpaa2_xstats_strings[i].stats_id];
1217 dpaa2_xstats_get_by_id(dev, NULL, values_copy, stat_cnt);
1219 for (i = 0; i < n; i++) {
1220 if (ids[i] >= stat_cnt) {
1221 PMD_INIT_LOG(ERR, "id value isn't valid");
1224 values[i] = values_copy[ids[i]];
1230 dpaa2_xstats_get_names_by_id(
1231 struct rte_eth_dev *dev,
1232 struct rte_eth_xstat_name *xstats_names,
1233 const uint64_t *ids,
1236 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1237 struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
1240 return dpaa2_xstats_get_names(dev, xstats_names, limit);
1242 dpaa2_xstats_get_names(dev, xstats_names_copy, limit);
1244 for (i = 0; i < limit; i++) {
1245 if (ids[i] >= stat_cnt) {
1246 PMD_INIT_LOG(ERR, "id value isn't valid");
1249 strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
1255 dpaa2_dev_stats_reset(struct rte_eth_dev *dev)
1257 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1258 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1261 PMD_INIT_FUNC_TRACE();
1264 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1268 retcode = dpni_reset_statistics(dpni, CMD_PRI_LOW, priv->token);
1275 RTE_LOG(ERR, PMD, "Operation not completed:Error Code = %d\n", retcode);
1279 /* return 0 means link status changed, -1 means not changed */
1281 dpaa2_dev_link_update(struct rte_eth_dev *dev,
1282 int wait_to_complete __rte_unused)
1285 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1286 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1287 struct rte_eth_link link, old;
1288 struct dpni_link_state state = {0};
1291 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1294 memset(&old, 0, sizeof(old));
1295 dpaa2_dev_atomic_read_link_status(dev, &old);
1297 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1299 RTE_LOG(ERR, PMD, "error: dpni_get_link_state %d\n", ret);
1303 if ((old.link_status == state.up) && (old.link_speed == state.rate)) {
1304 RTE_LOG(DEBUG, PMD, "No change in status\n");
1308 memset(&link, 0, sizeof(struct rte_eth_link));
1309 link.link_status = state.up;
1310 link.link_speed = state.rate;
1312 if (state.options & DPNI_LINK_OPT_HALF_DUPLEX)
1313 link.link_duplex = ETH_LINK_HALF_DUPLEX;
1315 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1317 dpaa2_dev_atomic_write_link_status(dev, &link);
1319 if (link.link_status)
1320 PMD_DRV_LOG(INFO, "Port %d Link is Up\n", dev->data->port_id);
1322 PMD_DRV_LOG(INFO, "Port %d Link is Down", dev->data->port_id);
1327 * Toggle the DPNI to enable, if not already enabled.
1328 * This is not strictly PHY up/down - it is more of logical toggling.
1331 dpaa2_dev_set_link_up(struct rte_eth_dev *dev)
1334 struct dpaa2_dev_priv *priv;
1335 struct fsl_mc_io *dpni;
1337 struct dpni_link_state state = {0};
1339 priv = dev->data->dev_private;
1340 dpni = (struct fsl_mc_io *)priv->hw;
1343 RTE_LOG(ERR, PMD, "DPNI is NULL\n");
1347 /* Check if DPNI is currently enabled */
1348 ret = dpni_is_enabled(dpni, CMD_PRI_LOW, priv->token, &en);
1350 /* Unable to obtain dpni status; Not continuing */
1351 PMD_DRV_LOG(ERR, "Interface Link UP failed (%d)", ret);
1355 /* Enable link if not already enabled */
1357 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
1359 PMD_DRV_LOG(ERR, "Interface Link UP failed (%d)", ret);
1363 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1365 RTE_LOG(ERR, PMD, "error: dpni_get_link_state %d\n", ret);
1369 /* changing tx burst function to start enqueues */
1370 dev->tx_pkt_burst = dpaa2_dev_tx;
1371 dev->data->dev_link.link_status = state.up;
1374 PMD_DRV_LOG(INFO, "Port %d Link is set as UP",
1375 dev->data->port_id);
1377 PMD_DRV_LOG(INFO, "Port %d Link is DOWN", dev->data->port_id);
1382 * Toggle the DPNI to disable, if not already disabled.
1383 * This is not strictly PHY up/down - it is more of logical toggling.
1386 dpaa2_dev_set_link_down(struct rte_eth_dev *dev)
1389 struct dpaa2_dev_priv *priv;
1390 struct fsl_mc_io *dpni;
1391 int dpni_enabled = 0;
1394 PMD_INIT_FUNC_TRACE();
1396 priv = dev->data->dev_private;
1397 dpni = (struct fsl_mc_io *)priv->hw;
1400 RTE_LOG(ERR, PMD, "Device has not yet been configured\n");
1404 /*changing tx burst function to avoid any more enqueues */
1405 dev->tx_pkt_burst = dummy_dev_tx;
1407 /* Loop while dpni_disable() attempts to drain the egress FQs
1408 * and confirm them back to us.
1411 ret = dpni_disable(dpni, 0, priv->token);
1413 PMD_DRV_LOG(ERR, "dpni disable failed (%d)", ret);
1416 ret = dpni_is_enabled(dpni, 0, priv->token, &dpni_enabled);
1418 PMD_DRV_LOG(ERR, "dpni_is_enabled failed (%d)", ret);
1422 /* Allow the MC some slack */
1423 rte_delay_us(100 * 1000);
1424 } while (dpni_enabled && --retries);
1427 PMD_DRV_LOG(WARNING, "Retry count exceeded disabling DPNI\n");
1428 /* todo- we may have to manually cleanup queues.
1431 PMD_DRV_LOG(INFO, "Port %d Link DOWN successful",
1432 dev->data->port_id);
1435 dev->data->dev_link.link_status = 0;
1441 dpaa2_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1444 struct dpaa2_dev_priv *priv;
1445 struct fsl_mc_io *dpni;
1446 struct dpni_link_state state = {0};
1448 PMD_INIT_FUNC_TRACE();
1450 priv = dev->data->dev_private;
1451 dpni = (struct fsl_mc_io *)priv->hw;
1453 if (dpni == NULL || fc_conf == NULL) {
1454 RTE_LOG(ERR, PMD, "device not configured\n");
1458 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1460 RTE_LOG(ERR, PMD, "error: dpni_get_link_state %d\n", ret);
1464 memset(fc_conf, 0, sizeof(struct rte_eth_fc_conf));
1465 if (state.options & DPNI_LINK_OPT_PAUSE) {
1466 /* DPNI_LINK_OPT_PAUSE set
1467 * if ASYM_PAUSE not set,
1468 * RX Side flow control (handle received Pause frame)
1469 * TX side flow control (send Pause frame)
1470 * if ASYM_PAUSE set,
1471 * RX Side flow control (handle received Pause frame)
1472 * No TX side flow control (send Pause frame disabled)
1474 if (!(state.options & DPNI_LINK_OPT_ASYM_PAUSE))
1475 fc_conf->mode = RTE_FC_FULL;
1477 fc_conf->mode = RTE_FC_RX_PAUSE;
1479 /* DPNI_LINK_OPT_PAUSE not set
1480 * if ASYM_PAUSE set,
1481 * TX side flow control (send Pause frame)
1482 * No RX side flow control (No action on pause frame rx)
1483 * if ASYM_PAUSE not set,
1484 * Flow control disabled
1486 if (state.options & DPNI_LINK_OPT_ASYM_PAUSE)
1487 fc_conf->mode = RTE_FC_TX_PAUSE;
1489 fc_conf->mode = RTE_FC_NONE;
1496 dpaa2_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1499 struct dpaa2_dev_priv *priv;
1500 struct fsl_mc_io *dpni;
1501 struct dpni_link_state state = {0};
1502 struct dpni_link_cfg cfg = {0};
1504 PMD_INIT_FUNC_TRACE();
1506 priv = dev->data->dev_private;
1507 dpni = (struct fsl_mc_io *)priv->hw;
1510 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1514 /* It is necessary to obtain the current state before setting fc_conf
1515 * as MC would return error in case rate, autoneg or duplex values are
1518 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1520 RTE_LOG(ERR, PMD, "Unable to get link state (err=%d)\n", ret);
1524 /* Disable link before setting configuration */
1525 dpaa2_dev_set_link_down(dev);
1527 /* Based on fc_conf, update cfg */
1528 cfg.rate = state.rate;
1529 cfg.options = state.options;
1531 /* update cfg with fc_conf */
1532 switch (fc_conf->mode) {
1534 /* Full flow control;
1535 * OPT_PAUSE set, ASYM_PAUSE not set
1537 cfg.options |= DPNI_LINK_OPT_PAUSE;
1538 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1540 case RTE_FC_TX_PAUSE:
1541 /* Enable RX flow control
1542 * OPT_PAUSE not set;
1545 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1546 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1548 case RTE_FC_RX_PAUSE:
1549 /* Enable TX Flow control
1553 cfg.options |= DPNI_LINK_OPT_PAUSE;
1554 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1557 /* Disable Flow control
1559 * ASYM_PAUSE not set
1561 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1562 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1565 RTE_LOG(ERR, PMD, "Incorrect Flow control flag (%d)\n",
1570 ret = dpni_set_link_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
1573 "Unable to set Link configuration (err=%d)\n",
1577 dpaa2_dev_set_link_up(dev);
1583 dpaa2_dev_rss_hash_update(struct rte_eth_dev *dev,
1584 struct rte_eth_rss_conf *rss_conf)
1586 struct rte_eth_dev_data *data = dev->data;
1587 struct rte_eth_conf *eth_conf = &data->dev_conf;
1590 PMD_INIT_FUNC_TRACE();
1592 if (rss_conf->rss_hf) {
1593 ret = dpaa2_setup_flow_dist(dev, rss_conf->rss_hf);
1595 PMD_INIT_LOG(ERR, "unable to set flow dist");
1599 ret = dpaa2_remove_flow_dist(dev, 0);
1601 PMD_INIT_LOG(ERR, "unable to remove flow dist");
1605 eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_conf->rss_hf;
1610 dpaa2_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1611 struct rte_eth_rss_conf *rss_conf)
1613 struct rte_eth_dev_data *data = dev->data;
1614 struct rte_eth_conf *eth_conf = &data->dev_conf;
1616 /* dpaa2 does not support rss_key, so length should be 0*/
1617 rss_conf->rss_key_len = 0;
1618 rss_conf->rss_hf = eth_conf->rx_adv_conf.rss_conf.rss_hf;
1622 int dpaa2_eth_eventq_attach(const struct rte_eth_dev *dev,
1623 int eth_rx_queue_id,
1625 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
1627 struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
1628 struct fsl_mc_io *dpni = (struct fsl_mc_io *)eth_priv->hw;
1629 struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
1630 uint8_t flow_id = dpaa2_ethq->flow_id;
1631 struct dpni_queue cfg;
1635 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL)
1636 dpaa2_ethq->cb = dpaa2_dev_process_parallel_event;
1640 memset(&cfg, 0, sizeof(struct dpni_queue));
1641 options = DPNI_QUEUE_OPT_DEST;
1642 cfg.destination.type = DPNI_DEST_DPCON;
1643 cfg.destination.id = dpcon_id;
1644 cfg.destination.priority = queue_conf->ev.priority;
1646 options |= DPNI_QUEUE_OPT_USER_CTX;
1647 cfg.user_context = (uint64_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 .flow_ctrl_get = dpaa2_flow_ctrl_get,
1714 .flow_ctrl_set = dpaa2_flow_ctrl_set,
1715 .mac_addr_add = dpaa2_dev_add_mac_addr,
1716 .mac_addr_remove = dpaa2_dev_remove_mac_addr,
1717 .mac_addr_set = dpaa2_dev_set_mac_addr,
1718 .rss_hash_update = dpaa2_dev_rss_hash_update,
1719 .rss_hash_conf_get = dpaa2_dev_rss_hash_conf_get,
1723 dpaa2_dev_init(struct rte_eth_dev *eth_dev)
1725 struct rte_device *dev = eth_dev->device;
1726 struct rte_dpaa2_device *dpaa2_dev;
1727 struct fsl_mc_io *dpni_dev;
1728 struct dpni_attr attr;
1729 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
1730 struct dpni_buffer_layout layout;
1733 PMD_INIT_FUNC_TRACE();
1735 /* For secondary processes, the primary has done all the work */
1736 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1739 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
1741 hw_id = dpaa2_dev->object_id;
1743 dpni_dev = rte_malloc(NULL, sizeof(struct fsl_mc_io), 0);
1745 PMD_INIT_LOG(ERR, "malloc failed for dpni device\n");
1749 dpni_dev->regs = rte_mcp_ptr_list[0];
1750 ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
1753 "Failure in opening dpni@%d with err code %d\n",
1759 /* Clean the device first */
1760 ret = dpni_reset(dpni_dev, CMD_PRI_LOW, priv->token);
1763 "Failure cleaning dpni@%d with err code %d\n",
1768 ret = dpni_get_attributes(dpni_dev, CMD_PRI_LOW, priv->token, &attr);
1771 "Failure in get dpni@%d attribute, err code %d\n",
1776 priv->num_rx_tc = attr.num_rx_tcs;
1778 /* Resetting the "num_rx_queues" to equal number of queues in first TC
1779 * as only one TC is supported on Rx Side. Once Multiple TCs will be
1780 * in use for Rx processing then this will be changed or removed.
1782 priv->nb_rx_queues = attr.num_queues;
1784 /* Using number of TX queues as number of TX TCs */
1785 priv->nb_tx_queues = attr.num_tx_tcs;
1787 PMD_DRV_LOG(DEBUG, "RX-TC= %d, nb_rx_queues= %d, nb_tx_queues=%d",
1788 priv->num_rx_tc, priv->nb_rx_queues, priv->nb_tx_queues);
1790 priv->hw = dpni_dev;
1791 priv->hw_id = hw_id;
1792 priv->options = attr.options;
1793 priv->max_mac_filters = attr.mac_filter_entries;
1794 priv->max_vlan_filters = attr.vlan_filter_entries;
1797 /* Allocate memory for hardware structure for queues */
1798 ret = dpaa2_alloc_rx_tx_queues(eth_dev);
1800 PMD_INIT_LOG(ERR, "dpaa2_alloc_rx_tx_queuesFailed\n");
1804 /* Allocate memory for storing MAC addresses */
1805 eth_dev->data->mac_addrs = rte_zmalloc("dpni",
1806 ETHER_ADDR_LEN * attr.mac_filter_entries, 0);
1807 if (eth_dev->data->mac_addrs == NULL) {
1809 "Failed to allocate %d bytes needed to store MAC addresses",
1810 ETHER_ADDR_LEN * attr.mac_filter_entries);
1815 ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
1817 (uint8_t *)(eth_dev->data->mac_addrs[0].addr_bytes));
1819 PMD_INIT_LOG(ERR, "DPNI get mac address failed:Err Code = %d\n",
1824 /* ... tx buffer layout ... */
1825 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
1826 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
1827 layout.pass_frame_status = 1;
1828 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
1829 DPNI_QUEUE_TX, &layout);
1831 PMD_INIT_LOG(ERR, "Error (%d) in setting tx buffer layout",
1836 /* ... tx-conf and error buffer layout ... */
1837 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
1838 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
1839 layout.pass_frame_status = 1;
1840 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
1841 DPNI_QUEUE_TX_CONFIRM, &layout);
1843 PMD_INIT_LOG(ERR, "Error (%d) in setting tx-conf buffer layout",
1848 eth_dev->dev_ops = &dpaa2_ethdev_ops;
1849 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
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 /* Invoke PMD device initialization function */
1954 diag = dpaa2_dev_init(eth_dev);
1958 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1959 rte_free(eth_dev->data->dev_private);
1960 rte_eth_dev_release_port(eth_dev);
1965 rte_dpaa2_remove(struct rte_dpaa2_device *dpaa2_dev)
1967 struct rte_eth_dev *eth_dev;
1969 eth_dev = dpaa2_dev->eth_dev;
1970 dpaa2_dev_uninit(eth_dev);
1972 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1973 rte_free(eth_dev->data->dev_private);
1974 rte_eth_dev_release_port(eth_dev);
1979 static struct rte_dpaa2_driver rte_dpaa2_pmd = {
1980 .drv_type = DPAA2_ETH,
1981 .probe = rte_dpaa2_probe,
1982 .remove = rte_dpaa2_remove,
1985 RTE_PMD_REGISTER_DPAA2(net_dpaa2, rte_dpaa2_pmd);