4 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Freescale Semiconductor, Inc nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <rte_ethdev.h>
39 #include <rte_malloc.h>
40 #include <rte_memcpy.h>
41 #include <rte_string_fns.h>
42 #include <rte_cycles.h>
43 #include <rte_kvargs.h>
45 #include <rte_fslmc.h>
47 #include <fslmc_logs.h>
48 #include <fslmc_vfio.h>
49 #include <dpaa2_hw_pvt.h>
50 #include <dpaa2_hw_mempool.h>
51 #include <dpaa2_hw_dpio.h>
52 #include <mc/fsl_dpmng.h>
53 #include "dpaa2_ethdev.h"
55 static struct rte_dpaa2_driver rte_dpaa2_pmd;
56 static int dpaa2_dev_uninit(struct rte_eth_dev *eth_dev);
57 static int dpaa2_dev_link_update(struct rte_eth_dev *dev,
58 int wait_to_complete);
59 static int dpaa2_dev_set_link_up(struct rte_eth_dev *dev);
60 static int dpaa2_dev_set_link_down(struct rte_eth_dev *dev);
61 static int dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
64 * Atomically reads the link status information from global
65 * structure rte_eth_dev.
68 * - Pointer to the structure rte_eth_dev to read from.
69 * - Pointer to the buffer to be saved with the link status.
73 * - On failure, negative value.
76 dpaa2_dev_atomic_read_link_status(struct rte_eth_dev *dev,
77 struct rte_eth_link *link)
79 struct rte_eth_link *dst = link;
80 struct rte_eth_link *src = &dev->data->dev_link;
82 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
83 *(uint64_t *)src) == 0)
90 * Atomically writes the link status information into global
91 * structure rte_eth_dev.
94 * - Pointer to the structure rte_eth_dev to read from.
95 * - Pointer to the buffer to be saved with the link status.
99 * - On failure, negative value.
102 dpaa2_dev_atomic_write_link_status(struct rte_eth_dev *dev,
103 struct rte_eth_link *link)
105 struct rte_eth_link *dst = &dev->data->dev_link;
106 struct rte_eth_link *src = link;
108 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
109 *(uint64_t *)src) == 0)
116 dpaa2_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
119 struct dpaa2_dev_priv *priv = dev->data->dev_private;
120 struct fsl_mc_io *dpni = priv->hw;
122 PMD_INIT_FUNC_TRACE();
125 RTE_LOG(ERR, PMD, "dpni is NULL\n");
130 ret = dpni_add_vlan_id(dpni, CMD_PRI_LOW,
131 priv->token, vlan_id);
133 ret = dpni_remove_vlan_id(dpni, CMD_PRI_LOW,
134 priv->token, vlan_id);
137 PMD_DRV_LOG(ERR, "ret = %d Unable to add/rem vlan %d hwid =%d",
138 ret, vlan_id, priv->hw_id);
144 dpaa2_vlan_offload_set(struct rte_eth_dev *dev, int mask)
146 struct dpaa2_dev_priv *priv = dev->data->dev_private;
147 struct fsl_mc_io *dpni = priv->hw;
150 PMD_INIT_FUNC_TRACE();
152 if (mask & ETH_VLAN_FILTER_MASK) {
153 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
154 ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
157 ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
160 RTE_LOG(ERR, PMD, "Unable to set vlan filter = %d\n",
166 dpaa2_fw_version_get(struct rte_eth_dev *dev,
171 struct dpaa2_dev_priv *priv = dev->data->dev_private;
172 struct fsl_mc_io *dpni = priv->hw;
173 struct mc_soc_version mc_plat_info = {0};
174 struct mc_version mc_ver_info = {0};
176 PMD_INIT_FUNC_TRACE();
178 if (mc_get_soc_version(dpni, CMD_PRI_LOW, &mc_plat_info))
179 RTE_LOG(WARNING, PMD, "\tmc_get_soc_version failed\n");
181 if (mc_get_version(dpni, CMD_PRI_LOW, &mc_ver_info))
182 RTE_LOG(WARNING, PMD, "\tmc_get_version failed\n");
184 ret = snprintf(fw_version, fw_size,
189 mc_ver_info.revision);
191 ret += 1; /* add the size of '\0' */
192 if (fw_size < (uint32_t)ret)
199 dpaa2_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
201 struct dpaa2_dev_priv *priv = dev->data->dev_private;
203 PMD_INIT_FUNC_TRACE();
205 dev_info->if_index = priv->hw_id;
207 dev_info->max_mac_addrs = priv->max_mac_filters;
208 dev_info->max_rx_pktlen = DPAA2_MAX_RX_PKT_LEN;
209 dev_info->min_rx_bufsize = DPAA2_MIN_RX_BUF_SIZE;
210 dev_info->max_rx_queues = (uint16_t)priv->nb_rx_queues;
211 dev_info->max_tx_queues = (uint16_t)priv->nb_tx_queues;
212 dev_info->rx_offload_capa =
213 DEV_RX_OFFLOAD_IPV4_CKSUM |
214 DEV_RX_OFFLOAD_UDP_CKSUM |
215 DEV_RX_OFFLOAD_TCP_CKSUM |
216 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM;
217 dev_info->tx_offload_capa =
218 DEV_TX_OFFLOAD_IPV4_CKSUM |
219 DEV_TX_OFFLOAD_UDP_CKSUM |
220 DEV_TX_OFFLOAD_TCP_CKSUM |
221 DEV_TX_OFFLOAD_SCTP_CKSUM |
222 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
223 dev_info->speed_capa = ETH_LINK_SPEED_1G |
224 ETH_LINK_SPEED_2_5G |
229 dpaa2_alloc_rx_tx_queues(struct rte_eth_dev *dev)
231 struct dpaa2_dev_priv *priv = dev->data->dev_private;
234 struct dpaa2_queue *mc_q, *mcq;
237 struct dpaa2_queue *dpaa2_q;
239 PMD_INIT_FUNC_TRACE();
241 tot_queues = priv->nb_rx_queues + priv->nb_tx_queues;
242 mc_q = rte_malloc(NULL, sizeof(struct dpaa2_queue) * tot_queues,
243 RTE_CACHE_LINE_SIZE);
245 PMD_INIT_LOG(ERR, "malloc failed for rx/tx queues\n");
249 for (i = 0; i < priv->nb_rx_queues; i++) {
251 priv->rx_vq[i] = mc_q++;
252 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
253 dpaa2_q->q_storage = rte_malloc("dq_storage",
254 sizeof(struct queue_storage_info_t),
255 RTE_CACHE_LINE_SIZE);
256 if (!dpaa2_q->q_storage)
259 memset(dpaa2_q->q_storage, 0,
260 sizeof(struct queue_storage_info_t));
261 if (dpaa2_alloc_dq_storage(dpaa2_q->q_storage))
265 for (i = 0; i < priv->nb_tx_queues; i++) {
267 mc_q->flow_id = 0xffff;
268 priv->tx_vq[i] = mc_q++;
269 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
270 dpaa2_q->cscn = rte_malloc(NULL,
271 sizeof(struct qbman_result), 16);
277 for (dist_idx = 0; dist_idx < priv->nb_rx_queues; dist_idx++) {
278 mcq = (struct dpaa2_queue *)priv->rx_vq[vq_id];
279 mcq->tc_index = DPAA2_DEF_TC;
280 mcq->flow_id = dist_idx;
288 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
289 rte_free(dpaa2_q->cscn);
290 priv->tx_vq[i--] = NULL;
292 i = priv->nb_rx_queues;
295 mc_q = priv->rx_vq[0];
297 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
298 dpaa2_free_dq_storage(dpaa2_q->q_storage);
299 rte_free(dpaa2_q->q_storage);
300 priv->rx_vq[i--] = NULL;
307 dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
309 struct rte_eth_dev_data *data = dev->data;
310 struct rte_eth_conf *eth_conf = &data->dev_conf;
313 PMD_INIT_FUNC_TRACE();
315 if (eth_conf->rxmode.jumbo_frame == 1) {
316 if (eth_conf->rxmode.max_rx_pkt_len <= DPAA2_MAX_RX_PKT_LEN) {
317 ret = dpaa2_dev_mtu_set(dev,
318 eth_conf->rxmode.max_rx_pkt_len);
321 "unable to set mtu. check config\n");
329 if (eth_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) {
330 ret = dpaa2_setup_flow_dist(dev,
331 eth_conf->rx_adv_conf.rss_conf.rss_hf);
333 PMD_INIT_LOG(ERR, "unable to set flow distribution."
334 "please check queue config\n");
339 /* update the current status */
340 dpaa2_dev_link_update(dev, 0);
345 /* Function to setup RX flow information. It contains traffic class ID,
346 * flow ID, destination configuration etc.
349 dpaa2_dev_rx_queue_setup(struct rte_eth_dev *dev,
350 uint16_t rx_queue_id,
351 uint16_t nb_rx_desc __rte_unused,
352 unsigned int socket_id __rte_unused,
353 const struct rte_eth_rxconf *rx_conf __rte_unused,
354 struct rte_mempool *mb_pool)
356 struct dpaa2_dev_priv *priv = dev->data->dev_private;
357 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
358 struct mc_soc_version mc_plat_info = {0};
359 struct dpaa2_queue *dpaa2_q;
360 struct dpni_queue cfg;
366 PMD_INIT_FUNC_TRACE();
368 PMD_INIT_LOG(DEBUG, "dev =%p, queue =%d, pool = %p, conf =%p",
369 dev, rx_queue_id, mb_pool, rx_conf);
371 if (!priv->bp_list || priv->bp_list->mp != mb_pool) {
372 bpid = mempool_to_bpid(mb_pool);
373 ret = dpaa2_attach_bp_list(priv,
374 rte_dpaa2_bpid_info[bpid].bp_list);
378 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
379 dpaa2_q->mb_pool = mb_pool; /**< mbuf pool to populate RX ring. */
381 /*Get the flow id from given VQ id*/
382 flow_id = rx_queue_id % priv->nb_rx_queues;
383 memset(&cfg, 0, sizeof(struct dpni_queue));
385 options = options | DPNI_QUEUE_OPT_USER_CTX;
386 cfg.user_context = (uint64_t)(dpaa2_q);
388 /*if ls2088 or rev2 device, enable the stashing */
390 if (mc_get_soc_version(dpni, CMD_PRI_LOW, &mc_plat_info))
391 PMD_INIT_LOG(ERR, "\tmc_get_soc_version failed\n");
393 if ((mc_plat_info.svr & 0xffff0000) != SVR_LS2080A) {
394 options |= DPNI_QUEUE_OPT_FLC;
395 cfg.flc.stash_control = true;
396 cfg.flc.value &= 0xFFFFFFFFFFFFFFC0;
397 /* 00 00 00 - last 6 bit represent annotation, context stashing,
398 * data stashing setting 01 01 00 (0x14) to enable
399 * 1 line data, 1 line annotation
401 cfg.flc.value |= 0x14;
403 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_RX,
404 dpaa2_q->tc_index, flow_id, options, &cfg);
406 PMD_INIT_LOG(ERR, "Error in setting the rx flow: = %d\n", ret);
410 if (!(priv->flags & DPAA2_RX_TAILDROP_OFF)) {
411 struct dpni_taildrop taildrop;
414 /*enabling per rx queue congestion control */
415 taildrop.threshold = CONG_THRESHOLD_RX_Q;
416 taildrop.units = DPNI_CONGESTION_UNIT_BYTES;
417 taildrop.oal = CONG_RX_OAL;
418 PMD_INIT_LOG(DEBUG, "Enabling Early Drop on queue = %d",
420 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
421 DPNI_CP_QUEUE, DPNI_QUEUE_RX,
422 dpaa2_q->tc_index, flow_id, &taildrop);
424 PMD_INIT_LOG(ERR, "Error in setting the rx flow"
425 " err : = %d\n", ret);
430 dev->data->rx_queues[rx_queue_id] = dpaa2_q;
435 dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
436 uint16_t tx_queue_id,
437 uint16_t nb_tx_desc __rte_unused,
438 unsigned int socket_id __rte_unused,
439 const struct rte_eth_txconf *tx_conf __rte_unused)
441 struct dpaa2_dev_priv *priv = dev->data->dev_private;
442 struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)
443 priv->tx_vq[tx_queue_id];
444 struct fsl_mc_io *dpni = priv->hw;
445 struct dpni_queue tx_conf_cfg;
446 struct dpni_queue tx_flow_cfg;
447 uint8_t options = 0, flow_id;
451 PMD_INIT_FUNC_TRACE();
453 /* Return if queue already configured */
454 if (dpaa2_q->flow_id != 0xffff)
457 memset(&tx_conf_cfg, 0, sizeof(struct dpni_queue));
458 memset(&tx_flow_cfg, 0, sizeof(struct dpni_queue));
463 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
464 tc_id, flow_id, options, &tx_flow_cfg);
466 PMD_INIT_LOG(ERR, "Error in setting the tx flow: "
467 "tc_id=%d, flow =%d ErrorCode = %x\n",
468 tc_id, flow_id, -ret);
472 dpaa2_q->flow_id = flow_id;
474 if (tx_queue_id == 0) {
475 /*Set tx-conf and error configuration*/
476 ret = dpni_set_tx_confirmation_mode(dpni, CMD_PRI_LOW,
480 PMD_INIT_LOG(ERR, "Error in set tx conf mode settings"
481 " ErrorCode = %x", ret);
485 dpaa2_q->tc_index = tc_id;
487 if (!(priv->flags & DPAA2_TX_CGR_OFF)) {
488 struct dpni_congestion_notification_cfg cong_notif_cfg;
490 cong_notif_cfg.units = DPNI_CONGESTION_UNIT_FRAMES;
491 cong_notif_cfg.threshold_entry = CONG_ENTER_TX_THRESHOLD;
492 /* Notify that the queue is not congested when the data in
493 * the queue is below this thershold.
495 cong_notif_cfg.threshold_exit = CONG_EXIT_TX_THRESHOLD;
496 cong_notif_cfg.message_ctx = 0;
497 cong_notif_cfg.message_iova = (uint64_t)dpaa2_q->cscn;
498 cong_notif_cfg.dest_cfg.dest_type = DPNI_DEST_NONE;
499 cong_notif_cfg.notification_mode =
500 DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
501 DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
502 DPNI_CONG_OPT_COHERENT_WRITE;
504 ret = dpni_set_congestion_notification(dpni, CMD_PRI_LOW,
511 "Error in setting tx congestion notification: = %d",
516 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
521 dpaa2_dev_rx_queue_release(void *q __rte_unused)
523 PMD_INIT_FUNC_TRACE();
527 dpaa2_dev_tx_queue_release(void *q __rte_unused)
529 PMD_INIT_FUNC_TRACE();
532 static const uint32_t *
533 dpaa2_supported_ptypes_get(struct rte_eth_dev *dev)
535 static const uint32_t ptypes[] = {
536 /*todo -= add more types */
539 RTE_PTYPE_L3_IPV4_EXT,
541 RTE_PTYPE_L3_IPV6_EXT,
549 if (dev->rx_pkt_burst == dpaa2_dev_prefetch_rx)
555 * Dpaa2 link Interrupt handler
558 * The address of parameter (struct rte_eth_dev *) regsitered before.
564 dpaa2_interrupt_handler(void *param)
566 struct rte_eth_dev *dev = param;
567 struct dpaa2_dev_priv *priv = dev->data->dev_private;
568 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
570 int irq_index = DPNI_IRQ_INDEX;
571 unsigned int status = 0, clear = 0;
573 PMD_INIT_FUNC_TRACE();
576 RTE_LOG(ERR, PMD, "dpni is NULL");
580 ret = dpni_get_irq_status(dpni, CMD_PRI_LOW, priv->token,
583 RTE_LOG(ERR, PMD, "Can't get irq status (err %d)", ret);
588 if (status & DPNI_IRQ_EVENT_LINK_CHANGED) {
589 clear = DPNI_IRQ_EVENT_LINK_CHANGED;
590 dpaa2_dev_link_update(dev, 0);
591 /* calling all the apps registered for link status event */
592 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
596 ret = dpni_clear_irq_status(dpni, CMD_PRI_LOW, priv->token,
599 RTE_LOG(ERR, PMD, "Can't clear irq status (err %d)", ret);
603 dpaa2_eth_setup_irqs(struct rte_eth_dev *dev, int enable)
606 struct dpaa2_dev_priv *priv = dev->data->dev_private;
607 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
608 int irq_index = DPNI_IRQ_INDEX;
609 unsigned int mask = DPNI_IRQ_EVENT_LINK_CHANGED;
611 PMD_INIT_FUNC_TRACE();
613 err = dpni_set_irq_mask(dpni, CMD_PRI_LOW, priv->token,
616 PMD_INIT_LOG(ERR, "Error: dpni_set_irq_mask():%d (%s)", err,
621 err = dpni_set_irq_enable(dpni, CMD_PRI_LOW, priv->token,
624 PMD_INIT_LOG(ERR, "Error: dpni_set_irq_enable():%d (%s)", err,
631 dpaa2_dev_start(struct rte_eth_dev *dev)
633 struct rte_device *rdev = dev->device;
634 struct rte_dpaa2_device *dpaa2_dev;
635 struct rte_eth_dev_data *data = dev->data;
636 struct dpaa2_dev_priv *priv = data->dev_private;
637 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
638 struct dpni_queue cfg;
639 struct dpni_error_cfg err_cfg;
641 struct dpni_queue_id qid;
642 struct dpaa2_queue *dpaa2_q;
644 struct rte_intr_handle *intr_handle;
646 dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
647 intr_handle = &dpaa2_dev->intr_handle;
649 PMD_INIT_FUNC_TRACE();
651 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
653 PMD_INIT_LOG(ERR, "Failure %d in enabling dpni %d device\n",
658 /* Power up the phy. Needed to make the link go UP */
659 dpaa2_dev_set_link_up(dev);
661 ret = dpni_get_qdid(dpni, CMD_PRI_LOW, priv->token,
662 DPNI_QUEUE_TX, &qdid);
664 PMD_INIT_LOG(ERR, "Error to get qdid:ErrorCode = %d\n", ret);
669 for (i = 0; i < data->nb_rx_queues; i++) {
670 dpaa2_q = (struct dpaa2_queue *)data->rx_queues[i];
671 ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
672 DPNI_QUEUE_RX, dpaa2_q->tc_index,
673 dpaa2_q->flow_id, &cfg, &qid);
675 PMD_INIT_LOG(ERR, "Error to get flow "
676 "information Error code = %d\n", ret);
679 dpaa2_q->fqid = qid.fqid;
682 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
683 DPNI_OFF_RX_L3_CSUM, true);
685 PMD_INIT_LOG(ERR, "Error to set RX l3 csum:Error = %d\n", ret);
689 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
690 DPNI_OFF_RX_L4_CSUM, true);
692 PMD_INIT_LOG(ERR, "Error to get RX l4 csum:Error = %d\n", ret);
696 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
697 DPNI_OFF_TX_L3_CSUM, true);
699 PMD_INIT_LOG(ERR, "Error to set TX l3 csum:Error = %d\n", ret);
703 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
704 DPNI_OFF_TX_L4_CSUM, true);
706 PMD_INIT_LOG(ERR, "Error to get TX l4 csum:Error = %d\n", ret);
710 /*checksum errors, send them to normal path and set it in annotation */
711 err_cfg.errors = DPNI_ERROR_L3CE | DPNI_ERROR_L4CE;
713 err_cfg.error_action = DPNI_ERROR_ACTION_CONTINUE;
714 err_cfg.set_frame_annotation = true;
716 ret = dpni_set_errors_behavior(dpni, CMD_PRI_LOW,
717 priv->token, &err_cfg);
719 PMD_INIT_LOG(ERR, "Error to dpni_set_errors_behavior:"
723 /* VLAN Offload Settings */
724 if (priv->max_vlan_filters)
725 dpaa2_vlan_offload_set(dev, ETH_VLAN_FILTER_MASK);
727 /* if the interrupts were configured on this devices*/
728 if (intr_handle && (intr_handle->fd) &&
729 (dev->data->dev_conf.intr_conf.lsc != 0)) {
730 /* Registering LSC interrupt handler */
731 rte_intr_callback_register(intr_handle,
732 dpaa2_interrupt_handler,
735 /* enable vfio intr/eventfd mapping
736 * Interrupt index 0 is required, so we can not use
739 rte_dpaa2_intr_enable(intr_handle, DPNI_IRQ_INDEX);
741 /* enable dpni_irqs */
742 dpaa2_eth_setup_irqs(dev, 1);
749 * This routine disables all traffic on the adapter by issuing a
750 * global reset on the MAC.
753 dpaa2_dev_stop(struct rte_eth_dev *dev)
755 struct dpaa2_dev_priv *priv = dev->data->dev_private;
756 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
758 struct rte_eth_link link;
759 struct rte_intr_handle *intr_handle = dev->intr_handle;
761 PMD_INIT_FUNC_TRACE();
763 /* reset interrupt callback */
764 if (intr_handle && (intr_handle->fd) &&
765 (dev->data->dev_conf.intr_conf.lsc != 0)) {
766 /*disable dpni irqs */
767 dpaa2_eth_setup_irqs(dev, 0);
769 /* disable vfio intr before callback unregister */
770 rte_dpaa2_intr_disable(intr_handle, DPNI_IRQ_INDEX);
772 /* Unregistering LSC interrupt handler */
773 rte_intr_callback_unregister(intr_handle,
774 dpaa2_interrupt_handler,
778 dpaa2_dev_set_link_down(dev);
780 ret = dpni_disable(dpni, CMD_PRI_LOW, priv->token);
782 PMD_INIT_LOG(ERR, "Failure (ret %d) in disabling dpni %d dev\n",
787 /* clear the recorded link status */
788 memset(&link, 0, sizeof(link));
789 dpaa2_dev_atomic_write_link_status(dev, &link);
793 dpaa2_dev_close(struct rte_eth_dev *dev)
795 struct rte_eth_dev_data *data = dev->data;
796 struct dpaa2_dev_priv *priv = dev->data->dev_private;
797 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
799 struct rte_eth_link link;
800 struct dpaa2_queue *dpaa2_q;
802 PMD_INIT_FUNC_TRACE();
804 for (i = 0; i < data->nb_tx_queues; i++) {
805 dpaa2_q = (struct dpaa2_queue *)data->tx_queues[i];
806 if (!dpaa2_q->cscn) {
807 rte_free(dpaa2_q->cscn);
808 dpaa2_q->cscn = NULL;
812 /* Clean the device first */
813 ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
815 PMD_INIT_LOG(ERR, "Failure cleaning dpni device with"
816 " error code %d\n", ret);
820 memset(&link, 0, sizeof(link));
821 dpaa2_dev_atomic_write_link_status(dev, &link);
825 dpaa2_dev_promiscuous_enable(
826 struct rte_eth_dev *dev)
829 struct dpaa2_dev_priv *priv = dev->data->dev_private;
830 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
832 PMD_INIT_FUNC_TRACE();
835 RTE_LOG(ERR, PMD, "dpni is NULL\n");
839 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
841 RTE_LOG(ERR, PMD, "Unable to enable U promisc mode %d\n", ret);
843 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
845 RTE_LOG(ERR, PMD, "Unable to enable M promisc mode %d\n", ret);
849 dpaa2_dev_promiscuous_disable(
850 struct rte_eth_dev *dev)
853 struct dpaa2_dev_priv *priv = dev->data->dev_private;
854 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
856 PMD_INIT_FUNC_TRACE();
859 RTE_LOG(ERR, PMD, "dpni is NULL\n");
863 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
865 RTE_LOG(ERR, PMD, "Unable to disable U promisc mode %d\n", ret);
867 if (dev->data->all_multicast == 0) {
868 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW,
872 "Unable to disable M promisc mode %d\n",
878 dpaa2_dev_allmulticast_enable(
879 struct rte_eth_dev *dev)
882 struct dpaa2_dev_priv *priv = dev->data->dev_private;
883 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
885 PMD_INIT_FUNC_TRACE();
888 RTE_LOG(ERR, PMD, "dpni is NULL\n");
892 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
894 RTE_LOG(ERR, PMD, "Unable to enable multicast mode %d\n", ret);
898 dpaa2_dev_allmulticast_disable(struct rte_eth_dev *dev)
901 struct dpaa2_dev_priv *priv = dev->data->dev_private;
902 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
904 PMD_INIT_FUNC_TRACE();
907 RTE_LOG(ERR, PMD, "dpni is NULL\n");
911 /* must remain on for all promiscuous */
912 if (dev->data->promiscuous == 1)
915 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
917 RTE_LOG(ERR, PMD, "Unable to disable multicast mode %d\n", ret);
921 dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
924 struct dpaa2_dev_priv *priv = dev->data->dev_private;
925 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
926 uint32_t frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
928 PMD_INIT_FUNC_TRACE();
931 RTE_LOG(ERR, PMD, "dpni is NULL\n");
935 /* check that mtu is within the allowed range */
936 if ((mtu < ETHER_MIN_MTU) || (frame_size > DPAA2_MAX_RX_PKT_LEN))
939 if (frame_size > ETHER_MAX_LEN)
940 dev->data->dev_conf.rxmode.jumbo_frame = 1;
942 dev->data->dev_conf.rxmode.jumbo_frame = 0;
944 /* Set the Max Rx frame length as 'mtu' +
945 * Maximum Ethernet header length
947 ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
948 mtu + ETH_VLAN_HLEN);
950 PMD_DRV_LOG(ERR, "setting the max frame length failed");
953 PMD_DRV_LOG(INFO, "MTU is configured %d for the device\n", mtu);
958 dpaa2_dev_add_mac_addr(struct rte_eth_dev *dev,
959 struct ether_addr *addr,
960 __rte_unused uint32_t index,
961 __rte_unused uint32_t pool)
964 struct dpaa2_dev_priv *priv = dev->data->dev_private;
965 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
967 PMD_INIT_FUNC_TRACE();
970 RTE_LOG(ERR, PMD, "dpni is NULL\n");
974 ret = dpni_add_mac_addr(dpni, CMD_PRI_LOW,
975 priv->token, addr->addr_bytes);
978 "error: Adding the MAC ADDR failed: err = %d\n", ret);
983 dpaa2_dev_remove_mac_addr(struct rte_eth_dev *dev,
987 struct dpaa2_dev_priv *priv = dev->data->dev_private;
988 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
989 struct rte_eth_dev_data *data = dev->data;
990 struct ether_addr *macaddr;
992 PMD_INIT_FUNC_TRACE();
994 macaddr = &data->mac_addrs[index];
997 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1001 ret = dpni_remove_mac_addr(dpni, CMD_PRI_LOW,
1002 priv->token, macaddr->addr_bytes);
1005 "error: Removing the MAC ADDR failed: err = %d\n", ret);
1009 dpaa2_dev_set_mac_addr(struct rte_eth_dev *dev,
1010 struct ether_addr *addr)
1013 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1014 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1016 PMD_INIT_FUNC_TRACE();
1019 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1023 ret = dpni_set_primary_mac_addr(dpni, CMD_PRI_LOW,
1024 priv->token, addr->addr_bytes);
1028 "error: Setting the MAC ADDR failed %d\n", ret);
1031 void dpaa2_dev_stats_get(struct rte_eth_dev *dev,
1032 struct rte_eth_stats *stats)
1034 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1035 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1037 uint8_t page0 = 0, page1 = 1, page2 = 2;
1038 union dpni_statistics value;
1040 memset(&value, 0, sizeof(union dpni_statistics));
1042 PMD_INIT_FUNC_TRACE();
1045 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1050 RTE_LOG(ERR, PMD, "stats is NULL\n");
1054 /*Get Counters from page_0*/
1055 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1060 stats->ipackets = value.page_0.ingress_all_frames;
1061 stats->ibytes = value.page_0.ingress_all_bytes;
1063 /*Get Counters from page_1*/
1064 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1069 stats->opackets = value.page_1.egress_all_frames;
1070 stats->obytes = value.page_1.egress_all_bytes;
1072 /*Get Counters from page_2*/
1073 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1078 /* Ingress drop frame count due to configured rules */
1079 stats->ierrors = value.page_2.ingress_filtered_frames;
1080 /* Ingress drop frame count due to error */
1081 stats->ierrors += value.page_2.ingress_discarded_frames;
1083 stats->oerrors = value.page_2.egress_discarded_frames;
1084 stats->imissed = value.page_2.ingress_nobuffer_discards;
1089 RTE_LOG(ERR, PMD, "Operation not completed:Error Code = %d\n", retcode);
1094 void dpaa2_dev_stats_reset(struct rte_eth_dev *dev)
1096 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1097 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1100 PMD_INIT_FUNC_TRACE();
1103 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1107 retcode = dpni_reset_statistics(dpni, CMD_PRI_LOW, priv->token);
1114 RTE_LOG(ERR, PMD, "Operation not completed:Error Code = %d\n", retcode);
1118 /* return 0 means link status changed, -1 means not changed */
1120 dpaa2_dev_link_update(struct rte_eth_dev *dev,
1121 int wait_to_complete __rte_unused)
1124 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1125 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1126 struct rte_eth_link link, old;
1127 struct dpni_link_state state = {0};
1130 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1133 memset(&old, 0, sizeof(old));
1134 dpaa2_dev_atomic_read_link_status(dev, &old);
1136 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1138 RTE_LOG(ERR, PMD, "error: dpni_get_link_state %d\n", ret);
1142 if ((old.link_status == state.up) && (old.link_speed == state.rate)) {
1143 RTE_LOG(DEBUG, PMD, "No change in status\n");
1147 memset(&link, 0, sizeof(struct rte_eth_link));
1148 link.link_status = state.up;
1149 link.link_speed = state.rate;
1151 if (state.options & DPNI_LINK_OPT_HALF_DUPLEX)
1152 link.link_duplex = ETH_LINK_HALF_DUPLEX;
1154 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1156 dpaa2_dev_atomic_write_link_status(dev, &link);
1158 if (link.link_status)
1159 PMD_DRV_LOG(INFO, "Port %d Link is Up\n", dev->data->port_id);
1161 PMD_DRV_LOG(INFO, "Port %d Link is Down", dev->data->port_id);
1166 * Toggle the DPNI to enable, if not already enabled.
1167 * This is not strictly PHY up/down - it is more of logical toggling.
1170 dpaa2_dev_set_link_up(struct rte_eth_dev *dev)
1173 struct dpaa2_dev_priv *priv;
1174 struct fsl_mc_io *dpni;
1176 struct dpni_link_state state = {0};
1178 priv = dev->data->dev_private;
1179 dpni = (struct fsl_mc_io *)priv->hw;
1182 RTE_LOG(ERR, PMD, "DPNI is NULL\n");
1186 /* Check if DPNI is currently enabled */
1187 ret = dpni_is_enabled(dpni, CMD_PRI_LOW, priv->token, &en);
1189 /* Unable to obtain dpni status; Not continuing */
1190 PMD_DRV_LOG(ERR, "Interface Link UP failed (%d)", ret);
1194 /* Enable link if not already enabled */
1196 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
1198 PMD_DRV_LOG(ERR, "Interface Link UP failed (%d)", ret);
1202 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1204 RTE_LOG(ERR, PMD, "error: dpni_get_link_state %d\n", ret);
1208 /* changing tx burst function to start enqueues */
1209 dev->tx_pkt_burst = dpaa2_dev_tx;
1210 dev->data->dev_link.link_status = state.up;
1213 PMD_DRV_LOG(INFO, "Port %d Link is set as UP",
1214 dev->data->port_id);
1216 PMD_DRV_LOG(INFO, "Port %d Link is DOWN", dev->data->port_id);
1221 * Toggle the DPNI to disable, if not already disabled.
1222 * This is not strictly PHY up/down - it is more of logical toggling.
1225 dpaa2_dev_set_link_down(struct rte_eth_dev *dev)
1228 struct dpaa2_dev_priv *priv;
1229 struct fsl_mc_io *dpni;
1230 int dpni_enabled = 0;
1233 PMD_INIT_FUNC_TRACE();
1235 priv = dev->data->dev_private;
1236 dpni = (struct fsl_mc_io *)priv->hw;
1239 RTE_LOG(ERR, PMD, "Device has not yet been configured\n");
1243 /*changing tx burst function to avoid any more enqueues */
1244 dev->tx_pkt_burst = dummy_dev_tx;
1246 /* Loop while dpni_disable() attempts to drain the egress FQs
1247 * and confirm them back to us.
1250 ret = dpni_disable(dpni, 0, priv->token);
1252 PMD_DRV_LOG(ERR, "dpni disable failed (%d)", ret);
1255 ret = dpni_is_enabled(dpni, 0, priv->token, &dpni_enabled);
1257 PMD_DRV_LOG(ERR, "dpni_is_enabled failed (%d)", ret);
1261 /* Allow the MC some slack */
1262 rte_delay_us(100 * 1000);
1263 } while (dpni_enabled && --retries);
1266 PMD_DRV_LOG(WARNING, "Retry count exceeded disabling DPNI\n");
1267 /* todo- we may have to manually cleanup queues.
1270 PMD_DRV_LOG(INFO, "Port %d Link DOWN successful",
1271 dev->data->port_id);
1274 dev->data->dev_link.link_status = 0;
1280 dpaa2_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1283 struct dpaa2_dev_priv *priv;
1284 struct fsl_mc_io *dpni;
1285 struct dpni_link_state state = {0};
1287 PMD_INIT_FUNC_TRACE();
1289 priv = dev->data->dev_private;
1290 dpni = (struct fsl_mc_io *)priv->hw;
1292 if (dpni == NULL || fc_conf == NULL) {
1293 RTE_LOG(ERR, PMD, "device not configured\n");
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 memset(fc_conf, 0, sizeof(struct rte_eth_fc_conf));
1304 if (state.options & DPNI_LINK_OPT_PAUSE) {
1305 /* DPNI_LINK_OPT_PAUSE set
1306 * if ASYM_PAUSE not set,
1307 * RX Side flow control (handle received Pause frame)
1308 * TX side flow control (send Pause frame)
1309 * if ASYM_PAUSE set,
1310 * RX Side flow control (handle received Pause frame)
1311 * No TX side flow control (send Pause frame disabled)
1313 if (!(state.options & DPNI_LINK_OPT_ASYM_PAUSE))
1314 fc_conf->mode = RTE_FC_FULL;
1316 fc_conf->mode = RTE_FC_RX_PAUSE;
1318 /* DPNI_LINK_OPT_PAUSE not set
1319 * if ASYM_PAUSE set,
1320 * TX side flow control (send Pause frame)
1321 * No RX side flow control (No action on pause frame rx)
1322 * if ASYM_PAUSE not set,
1323 * Flow control disabled
1325 if (state.options & DPNI_LINK_OPT_ASYM_PAUSE)
1326 fc_conf->mode = RTE_FC_TX_PAUSE;
1328 fc_conf->mode = RTE_FC_NONE;
1335 dpaa2_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1338 struct dpaa2_dev_priv *priv;
1339 struct fsl_mc_io *dpni;
1340 struct dpni_link_state state = {0};
1341 struct dpni_link_cfg cfg = {0};
1343 PMD_INIT_FUNC_TRACE();
1345 priv = dev->data->dev_private;
1346 dpni = (struct fsl_mc_io *)priv->hw;
1349 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1353 /* It is necessary to obtain the current state before setting fc_conf
1354 * as MC would return error in case rate, autoneg or duplex values are
1357 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1359 RTE_LOG(ERR, PMD, "Unable to get link state (err=%d)\n", ret);
1363 /* Disable link before setting configuration */
1364 dpaa2_dev_set_link_down(dev);
1366 /* Based on fc_conf, update cfg */
1367 cfg.rate = state.rate;
1368 cfg.options = state.options;
1370 /* update cfg with fc_conf */
1371 switch (fc_conf->mode) {
1373 /* Full flow control;
1374 * OPT_PAUSE set, ASYM_PAUSE not set
1376 cfg.options |= DPNI_LINK_OPT_PAUSE;
1377 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1379 case RTE_FC_TX_PAUSE:
1380 /* Enable RX flow control
1381 * OPT_PAUSE not set;
1384 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1385 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1387 case RTE_FC_RX_PAUSE:
1388 /* Enable TX Flow control
1392 cfg.options |= DPNI_LINK_OPT_PAUSE;
1393 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1396 /* Disable Flow control
1398 * ASYM_PAUSE not set
1400 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1401 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1404 RTE_LOG(ERR, PMD, "Incorrect Flow control flag (%d)\n",
1409 ret = dpni_set_link_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
1412 "Unable to set Link configuration (err=%d)\n",
1416 dpaa2_dev_set_link_up(dev);
1421 static struct eth_dev_ops dpaa2_ethdev_ops = {
1422 .dev_configure = dpaa2_eth_dev_configure,
1423 .dev_start = dpaa2_dev_start,
1424 .dev_stop = dpaa2_dev_stop,
1425 .dev_close = dpaa2_dev_close,
1426 .promiscuous_enable = dpaa2_dev_promiscuous_enable,
1427 .promiscuous_disable = dpaa2_dev_promiscuous_disable,
1428 .allmulticast_enable = dpaa2_dev_allmulticast_enable,
1429 .allmulticast_disable = dpaa2_dev_allmulticast_disable,
1430 .dev_set_link_up = dpaa2_dev_set_link_up,
1431 .dev_set_link_down = dpaa2_dev_set_link_down,
1432 .link_update = dpaa2_dev_link_update,
1433 .stats_get = dpaa2_dev_stats_get,
1434 .stats_reset = dpaa2_dev_stats_reset,
1435 .fw_version_get = dpaa2_fw_version_get,
1436 .dev_infos_get = dpaa2_dev_info_get,
1437 .dev_supported_ptypes_get = dpaa2_supported_ptypes_get,
1438 .mtu_set = dpaa2_dev_mtu_set,
1439 .vlan_filter_set = dpaa2_vlan_filter_set,
1440 .vlan_offload_set = dpaa2_vlan_offload_set,
1441 .rx_queue_setup = dpaa2_dev_rx_queue_setup,
1442 .rx_queue_release = dpaa2_dev_rx_queue_release,
1443 .tx_queue_setup = dpaa2_dev_tx_queue_setup,
1444 .tx_queue_release = dpaa2_dev_tx_queue_release,
1445 .flow_ctrl_get = dpaa2_flow_ctrl_get,
1446 .flow_ctrl_set = dpaa2_flow_ctrl_set,
1447 .mac_addr_add = dpaa2_dev_add_mac_addr,
1448 .mac_addr_remove = dpaa2_dev_remove_mac_addr,
1449 .mac_addr_set = dpaa2_dev_set_mac_addr,
1453 dpaa2_dev_init(struct rte_eth_dev *eth_dev)
1455 struct rte_device *dev = eth_dev->device;
1456 struct rte_dpaa2_device *dpaa2_dev;
1457 struct fsl_mc_io *dpni_dev;
1458 struct dpni_attr attr;
1459 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
1460 struct dpni_buffer_layout layout;
1463 PMD_INIT_FUNC_TRACE();
1465 /* For secondary processes, the primary has done all the work */
1466 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1469 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
1471 hw_id = dpaa2_dev->object_id;
1473 dpni_dev = rte_malloc(NULL, sizeof(struct fsl_mc_io), 0);
1475 PMD_INIT_LOG(ERR, "malloc failed for dpni device\n");
1479 dpni_dev->regs = rte_mcp_ptr_list[0];
1480 ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
1483 "Failure in opening dpni@%d with err code %d\n",
1489 /* Clean the device first */
1490 ret = dpni_reset(dpni_dev, CMD_PRI_LOW, priv->token);
1493 "Failure cleaning dpni@%d with err code %d\n",
1498 ret = dpni_get_attributes(dpni_dev, CMD_PRI_LOW, priv->token, &attr);
1501 "Failure in get dpni@%d attribute, err code %d\n",
1506 priv->num_rx_tc = attr.num_rx_tcs;
1508 /* Resetting the "num_rx_queues" to equal number of queues in first TC
1509 * as only one TC is supported on Rx Side. Once Multiple TCs will be
1510 * in use for Rx processing then this will be changed or removed.
1512 priv->nb_rx_queues = attr.num_queues;
1514 /* Using number of TX queues as number of TX TCs */
1515 priv->nb_tx_queues = attr.num_tx_tcs;
1517 PMD_DRV_LOG(DEBUG, "RX-TC= %d, nb_rx_queues= %d, nb_tx_queues=%d",
1518 priv->num_tc, priv->nb_rx_queues, priv->nb_tx_queues);
1520 priv->hw = dpni_dev;
1521 priv->hw_id = hw_id;
1522 priv->options = attr.options;
1523 priv->max_mac_filters = attr.mac_filter_entries;
1524 priv->max_vlan_filters = attr.vlan_filter_entries;
1527 /* Allocate memory for hardware structure for queues */
1528 ret = dpaa2_alloc_rx_tx_queues(eth_dev);
1530 PMD_INIT_LOG(ERR, "dpaa2_alloc_rx_tx_queuesFailed\n");
1534 /* Allocate memory for storing MAC addresses */
1535 eth_dev->data->mac_addrs = rte_zmalloc("dpni",
1536 ETHER_ADDR_LEN * attr.mac_filter_entries, 0);
1537 if (eth_dev->data->mac_addrs == NULL) {
1539 "Failed to allocate %d bytes needed to store MAC addresses",
1540 ETHER_ADDR_LEN * attr.mac_filter_entries);
1545 ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
1547 (uint8_t *)(eth_dev->data->mac_addrs[0].addr_bytes));
1549 PMD_INIT_LOG(ERR, "DPNI get mac address failed:Err Code = %d\n",
1554 /* ... tx buffer layout ... */
1555 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
1556 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
1557 layout.pass_frame_status = 1;
1558 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
1559 DPNI_QUEUE_TX, &layout);
1561 PMD_INIT_LOG(ERR, "Error (%d) in setting tx buffer layout",
1566 /* ... tx-conf and error buffer layout ... */
1567 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
1568 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
1569 layout.pass_frame_status = 1;
1570 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
1571 DPNI_QUEUE_TX_CONFIRM, &layout);
1573 PMD_INIT_LOG(ERR, "Error (%d) in setting tx-conf buffer layout",
1578 eth_dev->dev_ops = &dpaa2_ethdev_ops;
1579 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
1581 eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
1582 eth_dev->tx_pkt_burst = dpaa2_dev_tx;
1583 rte_fslmc_vfio_dmamap();
1587 dpaa2_dev_uninit(eth_dev);
1592 dpaa2_dev_uninit(struct rte_eth_dev *eth_dev)
1594 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
1595 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1597 struct dpaa2_queue *dpaa2_q;
1599 PMD_INIT_FUNC_TRACE();
1601 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1605 PMD_INIT_LOG(WARNING, "Already closed or not started");
1609 dpaa2_dev_close(eth_dev);
1611 if (priv->rx_vq[0]) {
1612 /* cleaning up queue storage */
1613 for (i = 0; i < priv->nb_rx_queues; i++) {
1614 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
1615 if (dpaa2_q->q_storage)
1616 rte_free(dpaa2_q->q_storage);
1618 /*free the all queue memory */
1619 rte_free(priv->rx_vq[0]);
1620 priv->rx_vq[0] = NULL;
1623 /* free memory for storing MAC addresses */
1624 if (eth_dev->data->mac_addrs) {
1625 rte_free(eth_dev->data->mac_addrs);
1626 eth_dev->data->mac_addrs = NULL;
1629 /* Close the device at underlying layer*/
1630 ret = dpni_close(dpni, CMD_PRI_LOW, priv->token);
1633 "Failure closing dpni device with err code %d\n",
1637 /* Free the allocated memory for ethernet private data and dpni*/
1641 eth_dev->dev_ops = NULL;
1642 eth_dev->rx_pkt_burst = NULL;
1643 eth_dev->tx_pkt_burst = NULL;
1649 rte_dpaa2_probe(struct rte_dpaa2_driver *dpaa2_drv,
1650 struct rte_dpaa2_device *dpaa2_dev)
1652 struct rte_eth_dev *eth_dev;
1655 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1656 eth_dev = rte_eth_dev_allocate(dpaa2_dev->device.name);
1659 eth_dev->data->dev_private = rte_zmalloc(
1660 "ethdev private structure",
1661 sizeof(struct dpaa2_dev_priv),
1662 RTE_CACHE_LINE_SIZE);
1663 if (eth_dev->data->dev_private == NULL) {
1664 PMD_INIT_LOG(CRIT, "Cannot allocate memzone for"
1665 " private port data\n");
1666 rte_eth_dev_release_port(eth_dev);
1670 eth_dev = rte_eth_dev_attach_secondary(dpaa2_dev->device.name);
1675 eth_dev->device = &dpaa2_dev->device;
1676 eth_dev->device->driver = &dpaa2_drv->driver;
1678 dpaa2_dev->eth_dev = eth_dev;
1679 eth_dev->data->rx_mbuf_alloc_failed = 0;
1681 /* Invoke PMD device initialization function */
1682 diag = dpaa2_dev_init(eth_dev);
1686 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1687 rte_free(eth_dev->data->dev_private);
1688 rte_eth_dev_release_port(eth_dev);
1693 rte_dpaa2_remove(struct rte_dpaa2_device *dpaa2_dev)
1695 struct rte_eth_dev *eth_dev;
1697 eth_dev = dpaa2_dev->eth_dev;
1698 dpaa2_dev_uninit(eth_dev);
1700 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1701 rte_free(eth_dev->data->dev_private);
1702 rte_eth_dev_release_port(eth_dev);
1707 static struct rte_dpaa2_driver rte_dpaa2_pmd = {
1708 .drv_type = DPAA2_ETH,
1709 .probe = rte_dpaa2_probe,
1710 .remove = rte_dpaa2_remove,
1713 RTE_PMD_REGISTER_DPAA2(net_dpaa2, rte_dpaa2_pmd);