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 /* Check for correct configuration */
330 if (eth_conf->rxmode.mq_mode != ETH_MQ_RX_RSS &&
331 data->nb_rx_queues > 1) {
332 PMD_INIT_LOG(ERR, "Distribution is not enabled, "
333 "but Rx queues more than 1\n");
337 if (eth_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) {
338 /* Return in case number of Rx queues is 1 */
339 if (data->nb_rx_queues == 1)
341 ret = dpaa2_setup_flow_dist(dev,
342 eth_conf->rx_adv_conf.rss_conf.rss_hf);
344 PMD_INIT_LOG(ERR, "unable to set flow distribution."
345 "please check queue config\n");
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 mc_soc_version mc_plat_info = {0};
370 struct dpaa2_queue *dpaa2_q;
371 struct dpni_queue cfg;
377 PMD_INIT_FUNC_TRACE();
379 PMD_INIT_LOG(DEBUG, "dev =%p, queue =%d, pool = %p, conf =%p",
380 dev, rx_queue_id, mb_pool, rx_conf);
382 if (!priv->bp_list || priv->bp_list->mp != mb_pool) {
383 bpid = mempool_to_bpid(mb_pool);
384 ret = dpaa2_attach_bp_list(priv,
385 rte_dpaa2_bpid_info[bpid].bp_list);
389 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
390 dpaa2_q->mb_pool = mb_pool; /**< mbuf pool to populate RX ring. */
392 /*Get the flow id from given VQ id*/
393 flow_id = rx_queue_id % priv->nb_rx_queues;
394 memset(&cfg, 0, sizeof(struct dpni_queue));
396 options = options | DPNI_QUEUE_OPT_USER_CTX;
397 cfg.user_context = (uint64_t)(dpaa2_q);
399 /*if ls2088 or rev2 device, enable the stashing */
401 if (mc_get_soc_version(dpni, CMD_PRI_LOW, &mc_plat_info))
402 PMD_INIT_LOG(ERR, "\tmc_get_soc_version failed\n");
404 if ((mc_plat_info.svr & 0xffff0000) != SVR_LS2080A) {
405 options |= DPNI_QUEUE_OPT_FLC;
406 cfg.flc.stash_control = true;
407 cfg.flc.value &= 0xFFFFFFFFFFFFFFC0;
408 /* 00 00 00 - last 6 bit represent annotation, context stashing,
409 * data stashing setting 01 01 00 (0x14) to enable
410 * 1 line data, 1 line annotation
412 cfg.flc.value |= 0x14;
414 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_RX,
415 dpaa2_q->tc_index, flow_id, options, &cfg);
417 PMD_INIT_LOG(ERR, "Error in setting the rx flow: = %d\n", ret);
421 if (!(priv->flags & DPAA2_RX_TAILDROP_OFF)) {
422 struct dpni_taildrop taildrop;
425 /*enabling per rx queue congestion control */
426 taildrop.threshold = CONG_THRESHOLD_RX_Q;
427 taildrop.units = DPNI_CONGESTION_UNIT_BYTES;
428 taildrop.oal = CONG_RX_OAL;
429 PMD_INIT_LOG(DEBUG, "Enabling Early Drop on queue = %d",
431 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
432 DPNI_CP_QUEUE, DPNI_QUEUE_RX,
433 dpaa2_q->tc_index, flow_id, &taildrop);
435 PMD_INIT_LOG(ERR, "Error in setting the rx flow"
436 " err : = %d\n", ret);
441 dev->data->rx_queues[rx_queue_id] = dpaa2_q;
446 dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
447 uint16_t tx_queue_id,
448 uint16_t nb_tx_desc __rte_unused,
449 unsigned int socket_id __rte_unused,
450 const struct rte_eth_txconf *tx_conf __rte_unused)
452 struct dpaa2_dev_priv *priv = dev->data->dev_private;
453 struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)
454 priv->tx_vq[tx_queue_id];
455 struct fsl_mc_io *dpni = priv->hw;
456 struct dpni_queue tx_conf_cfg;
457 struct dpni_queue tx_flow_cfg;
458 uint8_t options = 0, flow_id;
462 PMD_INIT_FUNC_TRACE();
464 /* Return if queue already configured */
465 if (dpaa2_q->flow_id != 0xffff)
468 memset(&tx_conf_cfg, 0, sizeof(struct dpni_queue));
469 memset(&tx_flow_cfg, 0, sizeof(struct dpni_queue));
474 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
475 tc_id, flow_id, options, &tx_flow_cfg);
477 PMD_INIT_LOG(ERR, "Error in setting the tx flow: "
478 "tc_id=%d, flow =%d ErrorCode = %x\n",
479 tc_id, flow_id, -ret);
483 dpaa2_q->flow_id = flow_id;
485 if (tx_queue_id == 0) {
486 /*Set tx-conf and error configuration*/
487 ret = dpni_set_tx_confirmation_mode(dpni, CMD_PRI_LOW,
491 PMD_INIT_LOG(ERR, "Error in set tx conf mode settings"
492 " ErrorCode = %x", ret);
496 dpaa2_q->tc_index = tc_id;
498 if (!(priv->flags & DPAA2_TX_CGR_OFF)) {
499 struct dpni_congestion_notification_cfg cong_notif_cfg;
501 cong_notif_cfg.units = DPNI_CONGESTION_UNIT_FRAMES;
502 cong_notif_cfg.threshold_entry = CONG_ENTER_TX_THRESHOLD;
503 /* Notify that the queue is not congested when the data in
504 * the queue is below this thershold.
506 cong_notif_cfg.threshold_exit = CONG_EXIT_TX_THRESHOLD;
507 cong_notif_cfg.message_ctx = 0;
508 cong_notif_cfg.message_iova = (uint64_t)dpaa2_q->cscn;
509 cong_notif_cfg.dest_cfg.dest_type = DPNI_DEST_NONE;
510 cong_notif_cfg.notification_mode =
511 DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
512 DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
513 DPNI_CONG_OPT_COHERENT_WRITE;
515 ret = dpni_set_congestion_notification(dpni, CMD_PRI_LOW,
522 "Error in setting tx congestion notification: = %d",
527 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
532 dpaa2_dev_rx_queue_release(void *q __rte_unused)
534 PMD_INIT_FUNC_TRACE();
538 dpaa2_dev_tx_queue_release(void *q __rte_unused)
540 PMD_INIT_FUNC_TRACE();
543 static const uint32_t *
544 dpaa2_supported_ptypes_get(struct rte_eth_dev *dev)
546 static const uint32_t ptypes[] = {
547 /*todo -= add more types */
550 RTE_PTYPE_L3_IPV4_EXT,
552 RTE_PTYPE_L3_IPV6_EXT,
560 if (dev->rx_pkt_burst == dpaa2_dev_prefetch_rx)
566 * Dpaa2 link Interrupt handler
569 * The address of parameter (struct rte_eth_dev *) regsitered before.
575 dpaa2_interrupt_handler(void *param)
577 struct rte_eth_dev *dev = param;
578 struct dpaa2_dev_priv *priv = dev->data->dev_private;
579 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
581 int irq_index = DPNI_IRQ_INDEX;
582 unsigned int status = 0, clear = 0;
584 PMD_INIT_FUNC_TRACE();
587 RTE_LOG(ERR, PMD, "dpni is NULL");
591 ret = dpni_get_irq_status(dpni, CMD_PRI_LOW, priv->token,
594 RTE_LOG(ERR, PMD, "Can't get irq status (err %d)", ret);
599 if (status & DPNI_IRQ_EVENT_LINK_CHANGED) {
600 clear = DPNI_IRQ_EVENT_LINK_CHANGED;
601 dpaa2_dev_link_update(dev, 0);
602 /* calling all the apps registered for link status event */
603 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
607 ret = dpni_clear_irq_status(dpni, CMD_PRI_LOW, priv->token,
610 RTE_LOG(ERR, PMD, "Can't clear irq status (err %d)", ret);
614 dpaa2_eth_setup_irqs(struct rte_eth_dev *dev, int enable)
617 struct dpaa2_dev_priv *priv = dev->data->dev_private;
618 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
619 int irq_index = DPNI_IRQ_INDEX;
620 unsigned int mask = DPNI_IRQ_EVENT_LINK_CHANGED;
622 PMD_INIT_FUNC_TRACE();
624 err = dpni_set_irq_mask(dpni, CMD_PRI_LOW, priv->token,
627 PMD_INIT_LOG(ERR, "Error: dpni_set_irq_mask():%d (%s)", err,
632 err = dpni_set_irq_enable(dpni, CMD_PRI_LOW, priv->token,
635 PMD_INIT_LOG(ERR, "Error: dpni_set_irq_enable():%d (%s)", err,
642 dpaa2_dev_start(struct rte_eth_dev *dev)
644 struct rte_device *rdev = dev->device;
645 struct rte_dpaa2_device *dpaa2_dev;
646 struct rte_eth_dev_data *data = dev->data;
647 struct dpaa2_dev_priv *priv = data->dev_private;
648 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
649 struct dpni_queue cfg;
650 struct dpni_error_cfg err_cfg;
652 struct dpni_queue_id qid;
653 struct dpaa2_queue *dpaa2_q;
655 struct rte_intr_handle *intr_handle;
657 dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
658 intr_handle = &dpaa2_dev->intr_handle;
660 PMD_INIT_FUNC_TRACE();
662 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
664 PMD_INIT_LOG(ERR, "Failure %d in enabling dpni %d device\n",
669 /* Power up the phy. Needed to make the link go Up */
670 dpaa2_dev_set_link_up(dev);
672 ret = dpni_get_qdid(dpni, CMD_PRI_LOW, priv->token,
673 DPNI_QUEUE_TX, &qdid);
675 PMD_INIT_LOG(ERR, "Error to get qdid:ErrorCode = %d\n", ret);
680 for (i = 0; i < data->nb_rx_queues; i++) {
681 dpaa2_q = (struct dpaa2_queue *)data->rx_queues[i];
682 ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
683 DPNI_QUEUE_RX, dpaa2_q->tc_index,
684 dpaa2_q->flow_id, &cfg, &qid);
686 PMD_INIT_LOG(ERR, "Error to get flow "
687 "information Error code = %d\n", ret);
690 dpaa2_q->fqid = qid.fqid;
693 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
694 DPNI_OFF_RX_L3_CSUM, true);
696 PMD_INIT_LOG(ERR, "Error to set RX l3 csum:Error = %d\n", ret);
700 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
701 DPNI_OFF_RX_L4_CSUM, true);
703 PMD_INIT_LOG(ERR, "Error to get RX l4 csum:Error = %d\n", ret);
707 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
708 DPNI_OFF_TX_L3_CSUM, true);
710 PMD_INIT_LOG(ERR, "Error to set TX l3 csum:Error = %d\n", ret);
714 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
715 DPNI_OFF_TX_L4_CSUM, true);
717 PMD_INIT_LOG(ERR, "Error to get TX l4 csum:Error = %d\n", ret);
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 dpaa2_vlan_offload_set(dev, ETH_VLAN_FILTER_MASK);
738 /* if the interrupts were configured on this devices*/
739 if (intr_handle && (intr_handle->fd) &&
740 (dev->data->dev_conf.intr_conf.lsc != 0)) {
741 /* Registering LSC interrupt handler */
742 rte_intr_callback_register(intr_handle,
743 dpaa2_interrupt_handler,
746 /* enable vfio intr/eventfd mapping
747 * Interrupt index 0 is required, so we can not use
750 rte_dpaa2_intr_enable(intr_handle, DPNI_IRQ_INDEX);
752 /* enable dpni_irqs */
753 dpaa2_eth_setup_irqs(dev, 1);
760 * This routine disables all traffic on the adapter by issuing a
761 * global reset on the MAC.
764 dpaa2_dev_stop(struct rte_eth_dev *dev)
766 struct dpaa2_dev_priv *priv = dev->data->dev_private;
767 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
769 struct rte_eth_link link;
770 struct rte_intr_handle *intr_handle = dev->intr_handle;
772 PMD_INIT_FUNC_TRACE();
774 /* reset interrupt callback */
775 if (intr_handle && (intr_handle->fd) &&
776 (dev->data->dev_conf.intr_conf.lsc != 0)) {
777 /*disable dpni irqs */
778 dpaa2_eth_setup_irqs(dev, 0);
780 /* disable vfio intr before callback unregister */
781 rte_dpaa2_intr_disable(intr_handle, DPNI_IRQ_INDEX);
783 /* Unregistering LSC interrupt handler */
784 rte_intr_callback_unregister(intr_handle,
785 dpaa2_interrupt_handler,
789 dpaa2_dev_set_link_down(dev);
791 ret = dpni_disable(dpni, CMD_PRI_LOW, priv->token);
793 PMD_INIT_LOG(ERR, "Failure (ret %d) in disabling dpni %d dev\n",
798 /* clear the recorded link status */
799 memset(&link, 0, sizeof(link));
800 dpaa2_dev_atomic_write_link_status(dev, &link);
804 dpaa2_dev_close(struct rte_eth_dev *dev)
806 struct rte_eth_dev_data *data = dev->data;
807 struct dpaa2_dev_priv *priv = dev->data->dev_private;
808 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
810 struct rte_eth_link link;
811 struct dpaa2_queue *dpaa2_q;
813 PMD_INIT_FUNC_TRACE();
815 for (i = 0; i < data->nb_tx_queues; i++) {
816 dpaa2_q = (struct dpaa2_queue *)data->tx_queues[i];
817 if (!dpaa2_q->cscn) {
818 rte_free(dpaa2_q->cscn);
819 dpaa2_q->cscn = NULL;
823 /* Clean the device first */
824 ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
826 PMD_INIT_LOG(ERR, "Failure cleaning dpni device with"
827 " error code %d\n", ret);
831 memset(&link, 0, sizeof(link));
832 dpaa2_dev_atomic_write_link_status(dev, &link);
836 dpaa2_dev_promiscuous_enable(
837 struct rte_eth_dev *dev)
840 struct dpaa2_dev_priv *priv = dev->data->dev_private;
841 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
843 PMD_INIT_FUNC_TRACE();
846 RTE_LOG(ERR, PMD, "dpni is NULL\n");
850 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
852 RTE_LOG(ERR, PMD, "Unable to enable U promisc mode %d\n", ret);
854 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
856 RTE_LOG(ERR, PMD, "Unable to enable M promisc mode %d\n", ret);
860 dpaa2_dev_promiscuous_disable(
861 struct rte_eth_dev *dev)
864 struct dpaa2_dev_priv *priv = dev->data->dev_private;
865 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
867 PMD_INIT_FUNC_TRACE();
870 RTE_LOG(ERR, PMD, "dpni is NULL\n");
874 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
876 RTE_LOG(ERR, PMD, "Unable to disable U promisc mode %d\n", ret);
878 if (dev->data->all_multicast == 0) {
879 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW,
883 "Unable to disable M promisc mode %d\n",
889 dpaa2_dev_allmulticast_enable(
890 struct rte_eth_dev *dev)
893 struct dpaa2_dev_priv *priv = dev->data->dev_private;
894 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
896 PMD_INIT_FUNC_TRACE();
899 RTE_LOG(ERR, PMD, "dpni is NULL\n");
903 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
905 RTE_LOG(ERR, PMD, "Unable to enable multicast mode %d\n", ret);
909 dpaa2_dev_allmulticast_disable(struct rte_eth_dev *dev)
912 struct dpaa2_dev_priv *priv = dev->data->dev_private;
913 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
915 PMD_INIT_FUNC_TRACE();
918 RTE_LOG(ERR, PMD, "dpni is NULL\n");
922 /* must remain on for all promiscuous */
923 if (dev->data->promiscuous == 1)
926 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
928 RTE_LOG(ERR, PMD, "Unable to disable multicast mode %d\n", ret);
932 dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
935 struct dpaa2_dev_priv *priv = dev->data->dev_private;
936 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
937 uint32_t frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
939 PMD_INIT_FUNC_TRACE();
942 RTE_LOG(ERR, PMD, "dpni is NULL\n");
946 /* check that mtu is within the allowed range */
947 if ((mtu < ETHER_MIN_MTU) || (frame_size > DPAA2_MAX_RX_PKT_LEN))
950 if (frame_size > ETHER_MAX_LEN)
951 dev->data->dev_conf.rxmode.jumbo_frame = 1;
953 dev->data->dev_conf.rxmode.jumbo_frame = 0;
955 /* Set the Max Rx frame length as 'mtu' +
956 * Maximum Ethernet header length
958 ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
959 mtu + ETH_VLAN_HLEN);
961 PMD_DRV_LOG(ERR, "setting the max frame length failed");
964 PMD_DRV_LOG(INFO, "MTU is configured %d for the device\n", mtu);
969 dpaa2_dev_add_mac_addr(struct rte_eth_dev *dev,
970 struct ether_addr *addr,
971 __rte_unused uint32_t index,
972 __rte_unused uint32_t pool)
975 struct dpaa2_dev_priv *priv = dev->data->dev_private;
976 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
978 PMD_INIT_FUNC_TRACE();
981 RTE_LOG(ERR, PMD, "dpni is NULL\n");
985 ret = dpni_add_mac_addr(dpni, CMD_PRI_LOW,
986 priv->token, addr->addr_bytes);
989 "error: Adding the MAC ADDR failed: err = %d\n", ret);
994 dpaa2_dev_remove_mac_addr(struct rte_eth_dev *dev,
998 struct dpaa2_dev_priv *priv = dev->data->dev_private;
999 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1000 struct rte_eth_dev_data *data = dev->data;
1001 struct ether_addr *macaddr;
1003 PMD_INIT_FUNC_TRACE();
1005 macaddr = &data->mac_addrs[index];
1008 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1012 ret = dpni_remove_mac_addr(dpni, CMD_PRI_LOW,
1013 priv->token, macaddr->addr_bytes);
1016 "error: Removing the MAC ADDR failed: err = %d\n", ret);
1020 dpaa2_dev_set_mac_addr(struct rte_eth_dev *dev,
1021 struct ether_addr *addr)
1024 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1025 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1027 PMD_INIT_FUNC_TRACE();
1030 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1034 ret = dpni_set_primary_mac_addr(dpni, CMD_PRI_LOW,
1035 priv->token, addr->addr_bytes);
1039 "error: Setting the MAC ADDR failed %d\n", ret);
1042 void dpaa2_dev_stats_get(struct rte_eth_dev *dev,
1043 struct rte_eth_stats *stats)
1045 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1046 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1048 uint8_t page0 = 0, page1 = 1, page2 = 2;
1049 union dpni_statistics value;
1051 memset(&value, 0, sizeof(union dpni_statistics));
1053 PMD_INIT_FUNC_TRACE();
1056 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1061 RTE_LOG(ERR, PMD, "stats is NULL\n");
1065 /*Get Counters from page_0*/
1066 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1071 stats->ipackets = value.page_0.ingress_all_frames;
1072 stats->ibytes = value.page_0.ingress_all_bytes;
1074 /*Get Counters from page_1*/
1075 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1080 stats->opackets = value.page_1.egress_all_frames;
1081 stats->obytes = value.page_1.egress_all_bytes;
1083 /*Get Counters from page_2*/
1084 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1089 /* Ingress drop frame count due to configured rules */
1090 stats->ierrors = value.page_2.ingress_filtered_frames;
1091 /* Ingress drop frame count due to error */
1092 stats->ierrors += value.page_2.ingress_discarded_frames;
1094 stats->oerrors = value.page_2.egress_discarded_frames;
1095 stats->imissed = value.page_2.ingress_nobuffer_discards;
1100 RTE_LOG(ERR, PMD, "Operation not completed:Error Code = %d\n", retcode);
1105 void dpaa2_dev_stats_reset(struct rte_eth_dev *dev)
1107 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1108 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1111 PMD_INIT_FUNC_TRACE();
1114 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1118 retcode = dpni_reset_statistics(dpni, CMD_PRI_LOW, priv->token);
1125 RTE_LOG(ERR, PMD, "Operation not completed:Error Code = %d\n", retcode);
1129 /* return 0 means link status changed, -1 means not changed */
1131 dpaa2_dev_link_update(struct rte_eth_dev *dev,
1132 int wait_to_complete __rte_unused)
1135 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1136 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1137 struct rte_eth_link link, old;
1138 struct dpni_link_state state = {0};
1140 PMD_INIT_FUNC_TRACE();
1143 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1146 memset(&old, 0, sizeof(old));
1147 dpaa2_dev_atomic_read_link_status(dev, &old);
1149 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1151 RTE_LOG(ERR, PMD, "error: dpni_get_link_state %d\n", ret);
1155 if ((old.link_status == state.up) && (old.link_speed == state.rate)) {
1156 RTE_LOG(DEBUG, PMD, "No change in status\n");
1160 memset(&link, 0, sizeof(struct rte_eth_link));
1161 link.link_status = state.up;
1162 link.link_speed = state.rate;
1164 if (state.options & DPNI_LINK_OPT_HALF_DUPLEX)
1165 link.link_duplex = ETH_LINK_HALF_DUPLEX;
1167 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1169 dpaa2_dev_atomic_write_link_status(dev, &link);
1171 if (link.link_status)
1172 PMD_DRV_LOG(INFO, "Port %d Link is Up\n", dev->data->port_id);
1174 PMD_DRV_LOG(INFO, "Port %d Link is Down\n", dev->data->port_id);
1179 * Toggle the DPNI to enable, if not already enabled.
1180 * This is not strictly PHY up/down - it is more of logical toggling.
1183 dpaa2_dev_set_link_up(struct rte_eth_dev *dev)
1186 struct dpaa2_dev_priv *priv;
1187 struct fsl_mc_io *dpni;
1190 PMD_INIT_FUNC_TRACE();
1192 priv = dev->data->dev_private;
1193 dpni = (struct fsl_mc_io *)priv->hw;
1196 RTE_LOG(ERR, PMD, "DPNI is NULL\n");
1200 /* Check if DPNI is currently enabled */
1201 ret = dpni_is_enabled(dpni, CMD_PRI_LOW, priv->token, &en);
1203 /* Unable to obtain dpni status; Not continuing */
1204 PMD_DRV_LOG(ERR, "Interface Link UP failed (%d)", ret);
1208 /* Enable link if not already enabled */
1210 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
1212 PMD_DRV_LOG(ERR, "Interface Link UP failed (%d)", ret);
1216 /* changing tx burst function to start enqueues */
1217 dev->tx_pkt_burst = dpaa2_dev_tx;
1218 dev->data->dev_link.link_status = 1;
1220 PMD_DRV_LOG(INFO, "Port %d Link UP successful", dev->data->port_id);
1225 * Toggle the DPNI to disable, if not already disabled.
1226 * This is not strictly PHY up/down - it is more of logical toggling.
1229 dpaa2_dev_set_link_down(struct rte_eth_dev *dev)
1232 struct dpaa2_dev_priv *priv;
1233 struct fsl_mc_io *dpni;
1234 int dpni_enabled = 0;
1237 PMD_INIT_FUNC_TRACE();
1239 priv = dev->data->dev_private;
1240 dpni = (struct fsl_mc_io *)priv->hw;
1243 RTE_LOG(ERR, PMD, "Device has not yet been configured\n");
1247 /*changing tx burst function to avoid any more enqueues */
1248 dev->tx_pkt_burst = dummy_dev_tx;
1250 /* Loop while dpni_disable() attempts to drain the egress FQs
1251 * and confirm them back to us.
1254 ret = dpni_disable(dpni, 0, priv->token);
1256 PMD_DRV_LOG(ERR, "dpni disable failed (%d)", ret);
1259 ret = dpni_is_enabled(dpni, 0, priv->token, &dpni_enabled);
1261 PMD_DRV_LOG(ERR, "dpni_is_enabled failed (%d)", ret);
1265 /* Allow the MC some slack */
1266 rte_delay_us(100 * 1000);
1267 } while (dpni_enabled && --retries);
1270 PMD_DRV_LOG(WARNING, "Retry count exceeded disabling DPNI\n");
1271 /* todo- we may have to manually cleanup queues.
1274 PMD_DRV_LOG(INFO, "Port %d Link DOWN successful",
1275 dev->data->port_id);
1278 dev->data->dev_link.link_status = 0;
1284 dpaa2_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1287 struct dpaa2_dev_priv *priv;
1288 struct fsl_mc_io *dpni;
1289 struct dpni_link_state state = {0};
1291 PMD_INIT_FUNC_TRACE();
1293 priv = dev->data->dev_private;
1294 dpni = (struct fsl_mc_io *)priv->hw;
1296 if (dpni == NULL || fc_conf == NULL) {
1297 RTE_LOG(ERR, PMD, "device not configured\n");
1301 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1303 RTE_LOG(ERR, PMD, "error: dpni_get_link_state %d\n", ret);
1307 memset(fc_conf, 0, sizeof(struct rte_eth_fc_conf));
1308 if (state.options & DPNI_LINK_OPT_PAUSE) {
1309 /* DPNI_LINK_OPT_PAUSE set
1310 * if ASYM_PAUSE not set,
1311 * RX Side flow control (handle received Pause frame)
1312 * TX side flow control (send Pause frame)
1313 * if ASYM_PAUSE set,
1314 * RX Side flow control (handle received Pause frame)
1315 * No TX side flow control (send Pause frame disabled)
1317 if (!(state.options & DPNI_LINK_OPT_ASYM_PAUSE))
1318 fc_conf->mode = RTE_FC_FULL;
1320 fc_conf->mode = RTE_FC_RX_PAUSE;
1322 /* DPNI_LINK_OPT_PAUSE not set
1323 * if ASYM_PAUSE set,
1324 * TX side flow control (send Pause frame)
1325 * No RX side flow control (No action on pause frame rx)
1326 * if ASYM_PAUSE not set,
1327 * Flow control disabled
1329 if (state.options & DPNI_LINK_OPT_ASYM_PAUSE)
1330 fc_conf->mode = RTE_FC_TX_PAUSE;
1332 fc_conf->mode = RTE_FC_NONE;
1339 dpaa2_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1342 struct dpaa2_dev_priv *priv;
1343 struct fsl_mc_io *dpni;
1344 struct dpni_link_state state = {0};
1345 struct dpni_link_cfg cfg = {0};
1347 PMD_INIT_FUNC_TRACE();
1349 priv = dev->data->dev_private;
1350 dpni = (struct fsl_mc_io *)priv->hw;
1353 RTE_LOG(ERR, PMD, "dpni is NULL\n");
1357 /* It is necessary to obtain the current state before setting fc_conf
1358 * as MC would return error in case rate, autoneg or duplex values are
1361 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1363 RTE_LOG(ERR, PMD, "Unable to get link state (err=%d)\n", ret);
1367 /* Disable link before setting configuration */
1368 dpaa2_dev_set_link_down(dev);
1370 /* Based on fc_conf, update cfg */
1371 cfg.rate = state.rate;
1372 cfg.options = state.options;
1374 /* update cfg with fc_conf */
1375 switch (fc_conf->mode) {
1377 /* Full flow control;
1378 * OPT_PAUSE set, ASYM_PAUSE not set
1380 cfg.options |= DPNI_LINK_OPT_PAUSE;
1381 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1383 case RTE_FC_TX_PAUSE:
1384 /* Enable RX flow control
1385 * OPT_PAUSE not set;
1388 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1389 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1391 case RTE_FC_RX_PAUSE:
1392 /* Enable TX Flow control
1396 cfg.options |= DPNI_LINK_OPT_PAUSE;
1397 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1400 /* Disable Flow control
1402 * ASYM_PAUSE not set
1404 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1405 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1408 RTE_LOG(ERR, PMD, "Incorrect Flow control flag (%d)\n",
1413 ret = dpni_set_link_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
1416 "Unable to set Link configuration (err=%d)\n",
1420 dpaa2_dev_set_link_up(dev);
1425 static struct eth_dev_ops dpaa2_ethdev_ops = {
1426 .dev_configure = dpaa2_eth_dev_configure,
1427 .dev_start = dpaa2_dev_start,
1428 .dev_stop = dpaa2_dev_stop,
1429 .dev_close = dpaa2_dev_close,
1430 .promiscuous_enable = dpaa2_dev_promiscuous_enable,
1431 .promiscuous_disable = dpaa2_dev_promiscuous_disable,
1432 .allmulticast_enable = dpaa2_dev_allmulticast_enable,
1433 .allmulticast_disable = dpaa2_dev_allmulticast_disable,
1434 .dev_set_link_up = dpaa2_dev_set_link_up,
1435 .dev_set_link_down = dpaa2_dev_set_link_down,
1436 .link_update = dpaa2_dev_link_update,
1437 .stats_get = dpaa2_dev_stats_get,
1438 .stats_reset = dpaa2_dev_stats_reset,
1439 .fw_version_get = dpaa2_fw_version_get,
1440 .dev_infos_get = dpaa2_dev_info_get,
1441 .dev_supported_ptypes_get = dpaa2_supported_ptypes_get,
1442 .mtu_set = dpaa2_dev_mtu_set,
1443 .vlan_filter_set = dpaa2_vlan_filter_set,
1444 .vlan_offload_set = dpaa2_vlan_offload_set,
1445 .rx_queue_setup = dpaa2_dev_rx_queue_setup,
1446 .rx_queue_release = dpaa2_dev_rx_queue_release,
1447 .tx_queue_setup = dpaa2_dev_tx_queue_setup,
1448 .tx_queue_release = dpaa2_dev_tx_queue_release,
1449 .flow_ctrl_get = dpaa2_flow_ctrl_get,
1450 .flow_ctrl_set = dpaa2_flow_ctrl_set,
1451 .mac_addr_add = dpaa2_dev_add_mac_addr,
1452 .mac_addr_remove = dpaa2_dev_remove_mac_addr,
1453 .mac_addr_set = dpaa2_dev_set_mac_addr,
1457 dpaa2_dev_init(struct rte_eth_dev *eth_dev)
1459 struct rte_device *dev = eth_dev->device;
1460 struct rte_dpaa2_device *dpaa2_dev;
1461 struct fsl_mc_io *dpni_dev;
1462 struct dpni_attr attr;
1463 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
1464 struct dpni_buffer_layout layout;
1467 PMD_INIT_FUNC_TRACE();
1469 /* For secondary processes, the primary has done all the work */
1470 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1473 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
1475 hw_id = dpaa2_dev->object_id;
1477 dpni_dev = rte_malloc(NULL, sizeof(struct fsl_mc_io), 0);
1479 PMD_INIT_LOG(ERR, "malloc failed for dpni device\n");
1483 dpni_dev->regs = rte_mcp_ptr_list[0];
1484 ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
1487 "Failure in opening dpni@%d with err code %d\n",
1493 /* Clean the device first */
1494 ret = dpni_reset(dpni_dev, CMD_PRI_LOW, priv->token);
1497 "Failure cleaning dpni@%d with err code %d\n",
1502 ret = dpni_get_attributes(dpni_dev, CMD_PRI_LOW, priv->token, &attr);
1505 "Failure in get dpni@%d attribute, err code %d\n",
1510 priv->num_rx_tc = attr.num_rx_tcs;
1512 /* Resetting the "num_rx_queues" to equal number of queues in first TC
1513 * as only one TC is supported on Rx Side. Once Multiple TCs will be
1514 * in use for Rx processing then this will be changed or removed.
1516 priv->nb_rx_queues = attr.num_queues;
1518 /* Using number of TX queues as number of TX TCs */
1519 priv->nb_tx_queues = attr.num_tx_tcs;
1521 PMD_DRV_LOG(DEBUG, "RX-TC= %d, nb_rx_queues= %d, nb_tx_queues=%d",
1522 priv->num_tc, priv->nb_rx_queues, priv->nb_tx_queues);
1524 priv->hw = dpni_dev;
1525 priv->hw_id = hw_id;
1526 priv->options = attr.options;
1527 priv->max_mac_filters = attr.mac_filter_entries;
1528 priv->max_vlan_filters = attr.vlan_filter_entries;
1531 /* Allocate memory for hardware structure for queues */
1532 ret = dpaa2_alloc_rx_tx_queues(eth_dev);
1534 PMD_INIT_LOG(ERR, "dpaa2_alloc_rx_tx_queuesFailed\n");
1538 /* Allocate memory for storing MAC addresses */
1539 eth_dev->data->mac_addrs = rte_zmalloc("dpni",
1540 ETHER_ADDR_LEN * attr.mac_filter_entries, 0);
1541 if (eth_dev->data->mac_addrs == NULL) {
1543 "Failed to allocate %d bytes needed to store MAC addresses",
1544 ETHER_ADDR_LEN * attr.mac_filter_entries);
1549 ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
1551 (uint8_t *)(eth_dev->data->mac_addrs[0].addr_bytes));
1553 PMD_INIT_LOG(ERR, "DPNI get mac address failed:Err Code = %d\n",
1558 /* ... tx buffer layout ... */
1559 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
1560 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
1561 layout.pass_frame_status = 1;
1562 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
1563 DPNI_QUEUE_TX, &layout);
1565 PMD_INIT_LOG(ERR, "Error (%d) in setting tx buffer layout",
1570 /* ... tx-conf and error buffer layout ... */
1571 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
1572 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
1573 layout.pass_frame_status = 1;
1574 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
1575 DPNI_QUEUE_TX_CONFIRM, &layout);
1577 PMD_INIT_LOG(ERR, "Error (%d) in setting tx-conf buffer layout",
1582 eth_dev->dev_ops = &dpaa2_ethdev_ops;
1583 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
1585 eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
1586 eth_dev->tx_pkt_burst = dpaa2_dev_tx;
1587 rte_fslmc_vfio_dmamap();
1591 dpaa2_dev_uninit(eth_dev);
1596 dpaa2_dev_uninit(struct rte_eth_dev *eth_dev)
1598 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
1599 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1601 struct dpaa2_queue *dpaa2_q;
1603 PMD_INIT_FUNC_TRACE();
1605 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1609 PMD_INIT_LOG(WARNING, "Already closed or not started");
1613 dpaa2_dev_close(eth_dev);
1615 if (priv->rx_vq[0]) {
1616 /* cleaning up queue storage */
1617 for (i = 0; i < priv->nb_rx_queues; i++) {
1618 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
1619 if (dpaa2_q->q_storage)
1620 rte_free(dpaa2_q->q_storage);
1622 /*free the all queue memory */
1623 rte_free(priv->rx_vq[0]);
1624 priv->rx_vq[0] = NULL;
1627 /* free memory for storing MAC addresses */
1628 if (eth_dev->data->mac_addrs) {
1629 rte_free(eth_dev->data->mac_addrs);
1630 eth_dev->data->mac_addrs = NULL;
1633 /* Close the device at underlying layer*/
1634 ret = dpni_close(dpni, CMD_PRI_LOW, priv->token);
1637 "Failure closing dpni device with err code %d\n",
1641 /* Free the allocated memory for ethernet private data and dpni*/
1645 eth_dev->dev_ops = NULL;
1646 eth_dev->rx_pkt_burst = NULL;
1647 eth_dev->tx_pkt_burst = NULL;
1653 rte_dpaa2_probe(struct rte_dpaa2_driver *dpaa2_drv,
1654 struct rte_dpaa2_device *dpaa2_dev)
1656 struct rte_eth_dev *eth_dev;
1659 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1660 eth_dev = rte_eth_dev_allocate(dpaa2_dev->device.name);
1663 eth_dev->data->dev_private = rte_zmalloc(
1664 "ethdev private structure",
1665 sizeof(struct dpaa2_dev_priv),
1666 RTE_CACHE_LINE_SIZE);
1667 if (eth_dev->data->dev_private == NULL) {
1668 PMD_INIT_LOG(CRIT, "Cannot allocate memzone for"
1669 " private port data\n");
1670 rte_eth_dev_release_port(eth_dev);
1674 eth_dev = rte_eth_dev_attach_secondary(dpaa2_dev->device.name);
1679 eth_dev->device = &dpaa2_dev->device;
1680 eth_dev->device->driver = &dpaa2_drv->driver;
1682 dpaa2_dev->eth_dev = eth_dev;
1683 eth_dev->data->rx_mbuf_alloc_failed = 0;
1685 /* Invoke PMD device initialization function */
1686 diag = dpaa2_dev_init(eth_dev);
1690 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1691 rte_free(eth_dev->data->dev_private);
1692 rte_eth_dev_release_port(eth_dev);
1697 rte_dpaa2_remove(struct rte_dpaa2_device *dpaa2_dev)
1699 struct rte_eth_dev *eth_dev;
1701 eth_dev = dpaa2_dev->eth_dev;
1702 dpaa2_dev_uninit(eth_dev);
1704 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1705 rte_free(eth_dev->data->dev_private);
1706 rte_eth_dev_release_port(eth_dev);
1711 static struct rte_dpaa2_driver rte_dpaa2_pmd = {
1712 .drv_type = DPAA2_ETH,
1713 .probe = rte_dpaa2_probe,
1714 .remove = rte_dpaa2_remove,
1717 RTE_PMD_REGISTER_DPAA2(net_dpaa2, rte_dpaa2_pmd);