4 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
5 * Copyright (c) 2016 NXP. 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_ethdev.h>
46 #include <rte_fslmc.h>
48 #include <fslmc_logs.h>
49 #include <fslmc_vfio.h>
50 #include <dpaa2_hw_pvt.h>
51 #include <dpaa2_hw_mempool.h>
52 #include <dpaa2_hw_dpio.h>
54 #include "dpaa2_ethdev.h"
56 static struct rte_dpaa2_driver rte_dpaa2_pmd;
57 static int dpaa2_dev_uninit(struct rte_eth_dev *eth_dev);
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_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
114 struct dpaa2_dev_priv *priv = dev->data->dev_private;
116 PMD_INIT_FUNC_TRACE();
118 dev_info->if_index = priv->hw_id;
120 dev_info->max_mac_addrs = priv->max_mac_filters;
121 dev_info->max_rx_pktlen = DPAA2_MAX_RX_PKT_LEN;
122 dev_info->min_rx_bufsize = DPAA2_MIN_RX_BUF_SIZE;
123 dev_info->max_rx_queues = (uint16_t)priv->nb_rx_queues;
124 dev_info->max_tx_queues = (uint16_t)priv->nb_tx_queues;
125 dev_info->rx_offload_capa =
126 DEV_RX_OFFLOAD_IPV4_CKSUM |
127 DEV_RX_OFFLOAD_UDP_CKSUM |
128 DEV_RX_OFFLOAD_TCP_CKSUM |
129 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM;
130 dev_info->tx_offload_capa =
131 DEV_TX_OFFLOAD_IPV4_CKSUM |
132 DEV_TX_OFFLOAD_UDP_CKSUM |
133 DEV_TX_OFFLOAD_TCP_CKSUM |
134 DEV_TX_OFFLOAD_SCTP_CKSUM |
135 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
136 dev_info->speed_capa = ETH_LINK_SPEED_1G |
137 ETH_LINK_SPEED_2_5G |
142 dpaa2_alloc_rx_tx_queues(struct rte_eth_dev *dev)
144 struct dpaa2_dev_priv *priv = dev->data->dev_private;
147 struct dpaa2_queue *mc_q, *mcq;
150 struct dpaa2_queue *dpaa2_q;
152 PMD_INIT_FUNC_TRACE();
154 tot_queues = priv->nb_rx_queues + priv->nb_tx_queues;
155 mc_q = rte_malloc(NULL, sizeof(struct dpaa2_queue) * tot_queues,
156 RTE_CACHE_LINE_SIZE);
158 PMD_INIT_LOG(ERR, "malloc failed for rx/tx queues\n");
162 for (i = 0; i < priv->nb_rx_queues; i++) {
164 priv->rx_vq[i] = mc_q++;
165 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
166 dpaa2_q->q_storage = rte_malloc("dq_storage",
167 sizeof(struct queue_storage_info_t),
168 RTE_CACHE_LINE_SIZE);
169 if (!dpaa2_q->q_storage)
172 memset(dpaa2_q->q_storage, 0,
173 sizeof(struct queue_storage_info_t));
174 if (dpaa2_alloc_dq_storage(dpaa2_q->q_storage))
178 for (i = 0; i < priv->nb_tx_queues; i++) {
180 mc_q->flow_id = 0xffff;
181 priv->tx_vq[i] = mc_q++;
182 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
183 dpaa2_q->cscn = rte_malloc(NULL,
184 sizeof(struct qbman_result), 16);
190 for (dist_idx = 0; dist_idx < priv->num_dist_per_tc[DPAA2_DEF_TC];
192 mcq = (struct dpaa2_queue *)priv->rx_vq[vq_id];
193 mcq->tc_index = DPAA2_DEF_TC;
194 mcq->flow_id = dist_idx;
202 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
203 rte_free(dpaa2_q->cscn);
204 priv->tx_vq[i--] = NULL;
206 i = priv->nb_rx_queues;
209 mc_q = priv->rx_vq[0];
211 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
212 dpaa2_free_dq_storage(dpaa2_q->q_storage);
213 rte_free(dpaa2_q->q_storage);
214 priv->rx_vq[i--] = NULL;
221 dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
223 struct rte_eth_dev_data *data = dev->data;
224 struct rte_eth_conf *eth_conf = &data->dev_conf;
227 PMD_INIT_FUNC_TRACE();
229 /* Check for correct configuration */
230 if (eth_conf->rxmode.mq_mode != ETH_MQ_RX_RSS &&
231 data->nb_rx_queues > 1) {
232 PMD_INIT_LOG(ERR, "Distribution is not enabled, "
233 "but Rx queues more than 1\n");
237 if (eth_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) {
238 /* Return in case number of Rx queues is 1 */
239 if (data->nb_rx_queues == 1)
241 ret = dpaa2_setup_flow_dist(dev,
242 eth_conf->rx_adv_conf.rss_conf.rss_hf);
244 PMD_INIT_LOG(ERR, "unable to set flow distribution."
245 "please check queue config\n");
252 /* Function to setup RX flow information. It contains traffic class ID,
253 * flow ID, destination configuration etc.
256 dpaa2_dev_rx_queue_setup(struct rte_eth_dev *dev,
257 uint16_t rx_queue_id,
258 uint16_t nb_rx_desc __rte_unused,
259 unsigned int socket_id __rte_unused,
260 const struct rte_eth_rxconf *rx_conf __rte_unused,
261 struct rte_mempool *mb_pool)
263 struct dpaa2_dev_priv *priv = dev->data->dev_private;
264 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
265 struct dpaa2_queue *dpaa2_q;
266 struct dpni_queue cfg;
272 PMD_INIT_FUNC_TRACE();
274 PMD_INIT_LOG(DEBUG, "dev =%p, queue =%d, pool = %p, conf =%p",
275 dev, rx_queue_id, mb_pool, rx_conf);
277 if (!priv->bp_list || priv->bp_list->mp != mb_pool) {
278 bpid = mempool_to_bpid(mb_pool);
279 ret = dpaa2_attach_bp_list(priv,
280 rte_dpaa2_bpid_info[bpid].bp_list);
284 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
285 dpaa2_q->mb_pool = mb_pool; /**< mbuf pool to populate RX ring. */
287 /*Get the tc id and flow id from given VQ id*/
288 flow_id = rx_queue_id % priv->num_dist_per_tc[dpaa2_q->tc_index];
289 memset(&cfg, 0, sizeof(struct dpni_queue));
291 options = options | DPNI_QUEUE_OPT_USER_CTX;
292 cfg.user_context = (uint64_t)(dpaa2_q);
294 /*if ls2088 or rev2 device, enable the stashing */
295 if ((qbman_get_version() & 0xFFFF0000) > QMAN_REV_4000) {
296 options |= DPNI_QUEUE_OPT_FLC;
297 cfg.flc.stash_control = true;
298 cfg.flc.value &= 0xFFFFFFFFFFFFFFC0;
299 /* 00 00 00 - last 6 bit represent annotation, context stashing,
300 * data stashing setting 01 01 00 (0x14) to enable
301 * 1 line data, 1 line annotation
303 cfg.flc.value |= 0x14;
305 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_RX,
306 dpaa2_q->tc_index, flow_id, options, &cfg);
308 PMD_INIT_LOG(ERR, "Error in setting the rx flow: = %d\n", ret);
312 if (!(priv->flags & DPAA2_RX_TAILDROP_OFF)) {
313 struct dpni_taildrop taildrop;
316 /*enabling per rx queue congestion control */
317 taildrop.threshold = CONG_THRESHOLD_RX_Q;
318 taildrop.units = DPNI_CONGESTION_UNIT_BYTES;
319 PMD_INIT_LOG(DEBUG, "Enabling Early Drop on queue = %d",
321 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
322 DPNI_CP_QUEUE, DPNI_QUEUE_RX,
323 dpaa2_q->tc_index, flow_id, &taildrop);
325 PMD_INIT_LOG(ERR, "Error in setting the rx flow"
326 " err : = %d\n", ret);
331 dev->data->rx_queues[rx_queue_id] = dpaa2_q;
336 dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
337 uint16_t tx_queue_id,
338 uint16_t nb_tx_desc __rte_unused,
339 unsigned int socket_id __rte_unused,
340 const struct rte_eth_txconf *tx_conf __rte_unused)
342 struct dpaa2_dev_priv *priv = dev->data->dev_private;
343 struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)
344 priv->tx_vq[tx_queue_id];
345 struct fsl_mc_io *dpni = priv->hw;
346 struct dpni_queue tx_conf_cfg;
347 struct dpni_queue tx_flow_cfg;
348 uint8_t options = 0, flow_id;
352 PMD_INIT_FUNC_TRACE();
354 /* Return if queue already configured */
355 if (dpaa2_q->flow_id != 0xffff)
358 memset(&tx_conf_cfg, 0, sizeof(struct dpni_queue));
359 memset(&tx_flow_cfg, 0, sizeof(struct dpni_queue));
361 if (priv->num_tc == 1) {
363 flow_id = tx_queue_id % priv->num_dist_per_tc[tc_id];
369 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
370 tc_id, flow_id, options, &tx_flow_cfg);
372 PMD_INIT_LOG(ERR, "Error in setting the tx flow: "
373 "tc_id=%d, flow =%d ErrorCode = %x\n",
374 tc_id, flow_id, -ret);
378 dpaa2_q->flow_id = flow_id;
380 if (tx_queue_id == 0) {
381 /*Set tx-conf and error configuration*/
382 ret = dpni_set_tx_confirmation_mode(dpni, CMD_PRI_LOW,
386 PMD_INIT_LOG(ERR, "Error in set tx conf mode settings"
387 " ErrorCode = %x", ret);
391 dpaa2_q->tc_index = tc_id;
393 if (priv->flags & DPAA2_TX_CGR_SUPPORT) {
394 struct dpni_congestion_notification_cfg cong_notif_cfg;
396 cong_notif_cfg.units = DPNI_CONGESTION_UNIT_BYTES;
397 /* Notify about congestion when the queue size is 32 KB */
398 cong_notif_cfg.threshold_entry = CONG_ENTER_TX_THRESHOLD;
399 /* Notify that the queue is not congested when the data in
400 * the queue is below this thershold.
402 cong_notif_cfg.threshold_exit = CONG_EXIT_TX_THRESHOLD;
403 cong_notif_cfg.message_ctx = 0;
404 cong_notif_cfg.message_iova = (uint64_t)dpaa2_q->cscn;
405 cong_notif_cfg.dest_cfg.dest_type = DPNI_DEST_NONE;
406 cong_notif_cfg.notification_mode =
407 DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
408 DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
409 DPNI_CONG_OPT_COHERENT_WRITE;
411 ret = dpni_set_congestion_notification(dpni, CMD_PRI_LOW,
418 "Error in setting tx congestion notification: = %d",
423 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
428 dpaa2_dev_rx_queue_release(void *q __rte_unused)
430 PMD_INIT_FUNC_TRACE();
434 dpaa2_dev_tx_queue_release(void *q __rte_unused)
436 PMD_INIT_FUNC_TRACE();
439 static const uint32_t *
440 dpaa2_supported_ptypes_get(struct rte_eth_dev *dev)
442 static const uint32_t ptypes[] = {
443 /*todo -= add more types */
446 RTE_PTYPE_L3_IPV4_EXT,
448 RTE_PTYPE_L3_IPV6_EXT,
456 if (dev->rx_pkt_burst == dpaa2_dev_prefetch_rx)
462 dpaa2_dev_start(struct rte_eth_dev *dev)
464 struct rte_eth_dev_data *data = dev->data;
465 struct dpaa2_dev_priv *priv = data->dev_private;
466 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
467 struct dpni_queue cfg;
468 struct dpni_error_cfg err_cfg;
470 struct dpni_queue_id qid;
471 struct dpaa2_queue *dpaa2_q;
474 PMD_INIT_FUNC_TRACE();
476 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
478 PMD_INIT_LOG(ERR, "Failure %d in enabling dpni %d device\n",
483 ret = dpni_get_qdid(dpni, CMD_PRI_LOW, priv->token,
484 DPNI_QUEUE_TX, &qdid);
486 PMD_INIT_LOG(ERR, "Error to get qdid:ErrorCode = %d\n", ret);
491 for (i = 0; i < data->nb_rx_queues; i++) {
492 dpaa2_q = (struct dpaa2_queue *)data->rx_queues[i];
493 ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
494 DPNI_QUEUE_RX, dpaa2_q->tc_index,
495 dpaa2_q->flow_id, &cfg, &qid);
497 PMD_INIT_LOG(ERR, "Error to get flow "
498 "information Error code = %d\n", ret);
501 dpaa2_q->fqid = qid.fqid;
504 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
505 DPNI_OFF_RX_L3_CSUM, true);
507 PMD_INIT_LOG(ERR, "Error to set RX l3 csum:Error = %d\n", ret);
511 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
512 DPNI_OFF_RX_L4_CSUM, true);
514 PMD_INIT_LOG(ERR, "Error to get RX l4 csum:Error = %d\n", ret);
518 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
519 DPNI_OFF_TX_L3_CSUM, true);
521 PMD_INIT_LOG(ERR, "Error to set TX l3 csum:Error = %d\n", ret);
525 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
526 DPNI_OFF_TX_L4_CSUM, true);
528 PMD_INIT_LOG(ERR, "Error to get TX l4 csum:Error = %d\n", ret);
532 /*checksum errors, send them to normal path and set it in annotation */
533 err_cfg.errors = DPNI_ERROR_L3CE | DPNI_ERROR_L4CE;
535 err_cfg.error_action = DPNI_ERROR_ACTION_CONTINUE;
536 err_cfg.set_frame_annotation = true;
538 ret = dpni_set_errors_behavior(dpni, CMD_PRI_LOW,
539 priv->token, &err_cfg);
541 PMD_INIT_LOG(ERR, "Error to dpni_set_errors_behavior:"
550 * This routine disables all traffic on the adapter by issuing a
551 * global reset on the MAC.
554 dpaa2_dev_stop(struct rte_eth_dev *dev)
556 struct dpaa2_dev_priv *priv = dev->data->dev_private;
557 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
559 struct rte_eth_link link;
561 PMD_INIT_FUNC_TRACE();
563 ret = dpni_disable(dpni, CMD_PRI_LOW, priv->token);
565 PMD_INIT_LOG(ERR, "Failure (ret %d) in disabling dpni %d dev\n",
570 /* clear the recorded link status */
571 memset(&link, 0, sizeof(link));
572 dpaa2_dev_atomic_write_link_status(dev, &link);
576 dpaa2_dev_close(struct rte_eth_dev *dev)
578 struct rte_eth_dev_data *data = dev->data;
579 struct dpaa2_dev_priv *priv = dev->data->dev_private;
580 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
582 struct dpaa2_queue *dpaa2_q;
584 PMD_INIT_FUNC_TRACE();
586 for (i = 0; i < data->nb_tx_queues; i++) {
587 dpaa2_q = (struct dpaa2_queue *)data->tx_queues[i];
588 if (!dpaa2_q->cscn) {
589 rte_free(dpaa2_q->cscn);
590 dpaa2_q->cscn = NULL;
594 /* Clean the device first */
595 ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
597 PMD_INIT_LOG(ERR, "Failure cleaning dpni device with"
598 " error code %d\n", ret);
604 dpaa2_dev_promiscuous_enable(
605 struct rte_eth_dev *dev)
608 struct dpaa2_dev_priv *priv = dev->data->dev_private;
609 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
611 PMD_INIT_FUNC_TRACE();
614 RTE_LOG(ERR, PMD, "dpni is NULL");
618 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
620 RTE_LOG(ERR, PMD, "Unable to enable U promisc mode %d", ret);
622 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
624 RTE_LOG(ERR, PMD, "Unable to enable M promisc mode %d", ret);
628 dpaa2_dev_promiscuous_disable(
629 struct rte_eth_dev *dev)
632 struct dpaa2_dev_priv *priv = dev->data->dev_private;
633 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
635 PMD_INIT_FUNC_TRACE();
638 RTE_LOG(ERR, PMD, "dpni is NULL");
642 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
644 RTE_LOG(ERR, PMD, "Unable to disable U promisc mode %d", ret);
646 if (dev->data->all_multicast == 0) {
647 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW,
650 RTE_LOG(ERR, PMD, "Unable to disable M promisc mode %d",
656 dpaa2_dev_allmulticast_enable(
657 struct rte_eth_dev *dev)
660 struct dpaa2_dev_priv *priv = dev->data->dev_private;
661 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
663 PMD_INIT_FUNC_TRACE();
666 RTE_LOG(ERR, PMD, "dpni is NULL");
670 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
672 RTE_LOG(ERR, PMD, "Unable to enable multicast mode %d", ret);
676 dpaa2_dev_allmulticast_disable(struct rte_eth_dev *dev)
679 struct dpaa2_dev_priv *priv = dev->data->dev_private;
680 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
682 PMD_INIT_FUNC_TRACE();
685 RTE_LOG(ERR, PMD, "dpni is NULL");
689 /* must remain on for all promiscuous */
690 if (dev->data->promiscuous == 1)
693 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
695 RTE_LOG(ERR, PMD, "Unable to disable multicast mode %d", ret);
699 dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
702 struct dpaa2_dev_priv *priv = dev->data->dev_private;
703 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
704 uint32_t frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
706 PMD_INIT_FUNC_TRACE();
709 RTE_LOG(ERR, PMD, "dpni is NULL");
713 /* check that mtu is within the allowed range */
714 if ((mtu < ETHER_MIN_MTU) || (frame_size > DPAA2_MAX_RX_PKT_LEN))
717 /* Set the Max Rx frame length as 'mtu' +
718 * Maximum Ethernet header length
720 ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
721 mtu + ETH_VLAN_HLEN);
723 PMD_DRV_LOG(ERR, "setting the max frame length failed");
726 PMD_DRV_LOG(INFO, "MTU is configured %d for the device\n", mtu);
731 dpaa2_dev_add_mac_addr(struct rte_eth_dev *dev,
732 struct ether_addr *addr,
733 __rte_unused uint32_t index,
734 __rte_unused uint32_t pool)
737 struct dpaa2_dev_priv *priv = dev->data->dev_private;
738 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
740 PMD_INIT_FUNC_TRACE();
743 RTE_LOG(ERR, PMD, "dpni is NULL");
747 ret = dpni_add_mac_addr(dpni, CMD_PRI_LOW,
748 priv->token, addr->addr_bytes);
750 RTE_LOG(ERR, PMD, "error: Adding the MAC ADDR failed:"
756 dpaa2_dev_remove_mac_addr(struct rte_eth_dev *dev,
760 struct dpaa2_dev_priv *priv = dev->data->dev_private;
761 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
762 struct rte_eth_dev_data *data = dev->data;
763 struct ether_addr *macaddr;
765 PMD_INIT_FUNC_TRACE();
767 macaddr = &data->mac_addrs[index];
770 RTE_LOG(ERR, PMD, "dpni is NULL");
774 ret = dpni_remove_mac_addr(dpni, CMD_PRI_LOW,
775 priv->token, macaddr->addr_bytes);
777 RTE_LOG(ERR, PMD, "error: Removing the MAC ADDR failed:"
782 dpaa2_dev_set_mac_addr(struct rte_eth_dev *dev,
783 struct ether_addr *addr)
786 struct dpaa2_dev_priv *priv = dev->data->dev_private;
787 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
789 PMD_INIT_FUNC_TRACE();
792 RTE_LOG(ERR, PMD, "dpni is NULL");
796 ret = dpni_set_primary_mac_addr(dpni, CMD_PRI_LOW,
797 priv->token, addr->addr_bytes);
800 RTE_LOG(ERR, PMD, "error: Setting the MAC ADDR failed %d", ret);
803 void dpaa2_dev_stats_get(struct rte_eth_dev *dev,
804 struct rte_eth_stats *stats)
806 struct dpaa2_dev_priv *priv = dev->data->dev_private;
807 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
809 uint8_t page0 = 0, page1 = 1, page2 = 2;
810 union dpni_statistics value;
812 memset(&value, 0, sizeof(union dpni_statistics));
814 PMD_INIT_FUNC_TRACE();
817 RTE_LOG(ERR, PMD, "dpni is NULL");
822 RTE_LOG(ERR, PMD, "stats is NULL");
826 /*Get Counters from page_0*/
827 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
832 stats->ipackets = value.page_0.ingress_all_frames;
833 stats->ibytes = value.page_0.ingress_all_bytes;
835 /*Get Counters from page_1*/
836 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
841 stats->opackets = value.page_1.egress_all_frames;
842 stats->obytes = value.page_1.egress_all_bytes;
844 /*Get Counters from page_2*/
845 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
850 /* Ingress drop frame count due to configured rules */
851 stats->ierrors = value.page_2.ingress_filtered_frames;
852 /* Ingress drop frame count due to error */
853 stats->ierrors += value.page_2.ingress_discarded_frames;
855 stats->oerrors = value.page_2.egress_discarded_frames;
856 stats->imissed = value.page_2.ingress_nobuffer_discards;
861 RTE_LOG(ERR, PMD, "Operation not completed:Error Code = %d\n", retcode);
866 void dpaa2_dev_stats_reset(struct rte_eth_dev *dev)
868 struct dpaa2_dev_priv *priv = dev->data->dev_private;
869 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
872 PMD_INIT_FUNC_TRACE();
875 RTE_LOG(ERR, PMD, "dpni is NULL");
879 retcode = dpni_reset_statistics(dpni, CMD_PRI_LOW, priv->token);
886 RTE_LOG(ERR, PMD, "Operation not completed:Error Code = %d\n", retcode);
890 /* return 0 means link status changed, -1 means not changed */
892 dpaa2_dev_link_update(struct rte_eth_dev *dev,
893 int wait_to_complete __rte_unused)
896 struct dpaa2_dev_priv *priv = dev->data->dev_private;
897 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
898 struct rte_eth_link link, old;
899 struct dpni_link_state state = {0};
901 PMD_INIT_FUNC_TRACE();
904 RTE_LOG(ERR, PMD, "error : dpni is NULL");
907 memset(&old, 0, sizeof(old));
908 dpaa2_dev_atomic_read_link_status(dev, &old);
910 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
912 RTE_LOG(ERR, PMD, "error: dpni_get_link_state %d", ret);
916 if ((old.link_status == state.up) && (old.link_speed == state.rate)) {
917 RTE_LOG(DEBUG, PMD, "No change in status\n");
921 memset(&link, 0, sizeof(struct rte_eth_link));
922 link.link_status = state.up;
923 link.link_speed = state.rate;
925 if (state.options & DPNI_LINK_OPT_HALF_DUPLEX)
926 link.link_duplex = ETH_LINK_HALF_DUPLEX;
928 link.link_duplex = ETH_LINK_FULL_DUPLEX;
930 dpaa2_dev_atomic_write_link_status(dev, &link);
932 if (link.link_status)
933 PMD_DRV_LOG(INFO, "Port %d Link is Up\n", dev->data->port_id);
935 PMD_DRV_LOG(INFO, "Port %d Link is Down\n", dev->data->port_id);
939 static struct eth_dev_ops dpaa2_ethdev_ops = {
940 .dev_configure = dpaa2_eth_dev_configure,
941 .dev_start = dpaa2_dev_start,
942 .dev_stop = dpaa2_dev_stop,
943 .dev_close = dpaa2_dev_close,
944 .promiscuous_enable = dpaa2_dev_promiscuous_enable,
945 .promiscuous_disable = dpaa2_dev_promiscuous_disable,
946 .allmulticast_enable = dpaa2_dev_allmulticast_enable,
947 .allmulticast_disable = dpaa2_dev_allmulticast_disable,
948 .link_update = dpaa2_dev_link_update,
949 .stats_get = dpaa2_dev_stats_get,
950 .stats_reset = dpaa2_dev_stats_reset,
951 .dev_infos_get = dpaa2_dev_info_get,
952 .dev_supported_ptypes_get = dpaa2_supported_ptypes_get,
953 .mtu_set = dpaa2_dev_mtu_set,
954 .rx_queue_setup = dpaa2_dev_rx_queue_setup,
955 .rx_queue_release = dpaa2_dev_rx_queue_release,
956 .tx_queue_setup = dpaa2_dev_tx_queue_setup,
957 .tx_queue_release = dpaa2_dev_tx_queue_release,
958 .mac_addr_add = dpaa2_dev_add_mac_addr,
959 .mac_addr_remove = dpaa2_dev_remove_mac_addr,
960 .mac_addr_set = dpaa2_dev_set_mac_addr,
964 dpaa2_dev_init(struct rte_eth_dev *eth_dev)
966 struct rte_device *dev = eth_dev->device;
967 struct rte_dpaa2_device *dpaa2_dev;
968 struct fsl_mc_io *dpni_dev;
969 struct dpni_attr attr;
970 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
971 struct dpni_buffer_layout layout;
974 PMD_INIT_FUNC_TRACE();
976 /* For secondary processes, the primary has done all the work */
977 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
980 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
982 hw_id = dpaa2_dev->object_id;
984 dpni_dev = rte_malloc(NULL, sizeof(struct fsl_mc_io), 0);
986 PMD_INIT_LOG(ERR, "malloc failed for dpni device\n");
990 dpni_dev->regs = rte_mcp_ptr_list[0];
991 ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
994 "Failure in opening dpni@%d with err code %d\n",
1000 /* Clean the device first */
1001 ret = dpni_reset(dpni_dev, CMD_PRI_LOW, priv->token);
1004 "Failure cleaning dpni@%d with err code %d\n",
1009 ret = dpni_get_attributes(dpni_dev, CMD_PRI_LOW, priv->token, &attr);
1012 "Failure in get dpni@%d attribute, err code %d\n",
1017 priv->num_tc = attr.num_tcs;
1018 for (i = 0; i < attr.num_tcs; i++) {
1019 priv->num_dist_per_tc[i] = attr.num_queues;
1023 /* Distribution is per Tc only,
1024 * so choosing RX queues from default TC only
1026 priv->nb_rx_queues = priv->num_dist_per_tc[DPAA2_DEF_TC];
1028 if (attr.num_tcs == 1)
1029 priv->nb_tx_queues = attr.num_queues;
1031 priv->nb_tx_queues = attr.num_tcs;
1033 PMD_INIT_LOG(DEBUG, "num_tc %d", priv->num_tc);
1034 PMD_INIT_LOG(DEBUG, "nb_rx_queues %d", priv->nb_rx_queues);
1036 priv->hw = dpni_dev;
1037 priv->hw_id = hw_id;
1038 priv->options = attr.options;
1039 priv->max_mac_filters = attr.mac_filter_entries;
1040 priv->max_vlan_filters = attr.vlan_filter_entries;
1043 priv->flags |= DPAA2_TX_CGR_SUPPORT;
1044 PMD_INIT_LOG(INFO, "Enable the tx congestion control support");
1046 /* Allocate memory for hardware structure for queues */
1047 ret = dpaa2_alloc_rx_tx_queues(eth_dev);
1049 PMD_INIT_LOG(ERR, "dpaa2_alloc_rx_tx_queuesFailed\n");
1053 /* Allocate memory for storing MAC addresses */
1054 eth_dev->data->mac_addrs = rte_zmalloc("dpni",
1055 ETHER_ADDR_LEN * attr.mac_filter_entries, 0);
1056 if (eth_dev->data->mac_addrs == NULL) {
1058 "Failed to allocate %d bytes needed to store MAC addresses",
1059 ETHER_ADDR_LEN * attr.mac_filter_entries);
1064 ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
1066 (uint8_t *)(eth_dev->data->mac_addrs[0].addr_bytes));
1068 PMD_INIT_LOG(ERR, "DPNI get mac address failed:Err Code = %d\n",
1073 /* ... tx buffer layout ... */
1074 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
1075 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
1076 layout.pass_frame_status = 1;
1077 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
1078 DPNI_QUEUE_TX, &layout);
1080 PMD_INIT_LOG(ERR, "Error (%d) in setting tx buffer layout",
1085 /* ... tx-conf and error buffer layout ... */
1086 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
1087 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
1088 layout.pass_frame_status = 1;
1089 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
1090 DPNI_QUEUE_TX_CONFIRM, &layout);
1092 PMD_INIT_LOG(ERR, "Error (%d) in setting tx-conf buffer layout",
1097 eth_dev->dev_ops = &dpaa2_ethdev_ops;
1098 eth_dev->data->drv_name = rte_dpaa2_pmd.driver.name;
1100 eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
1101 eth_dev->tx_pkt_burst = dpaa2_dev_tx;
1102 rte_fslmc_vfio_dmamap();
1106 dpaa2_dev_uninit(eth_dev);
1111 dpaa2_dev_uninit(struct rte_eth_dev *eth_dev)
1113 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
1114 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1116 struct dpaa2_queue *dpaa2_q;
1118 PMD_INIT_FUNC_TRACE();
1120 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1124 PMD_INIT_LOG(WARNING, "Already closed or not started");
1128 dpaa2_dev_close(eth_dev);
1130 if (priv->rx_vq[0]) {
1131 /* cleaning up queue storage */
1132 for (i = 0; i < priv->nb_rx_queues; i++) {
1133 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
1134 if (dpaa2_q->q_storage)
1135 rte_free(dpaa2_q->q_storage);
1137 /*free the all queue memory */
1138 rte_free(priv->rx_vq[0]);
1139 priv->rx_vq[0] = NULL;
1142 /* free memory for storing MAC addresses */
1143 if (eth_dev->data->mac_addrs) {
1144 rte_free(eth_dev->data->mac_addrs);
1145 eth_dev->data->mac_addrs = NULL;
1148 /* Close the device at underlying layer*/
1149 ret = dpni_close(dpni, CMD_PRI_LOW, priv->token);
1152 "Failure closing dpni device with err code %d\n",
1156 /* Free the allocated memory for ethernet private data and dpni*/
1160 eth_dev->dev_ops = NULL;
1161 eth_dev->rx_pkt_burst = NULL;
1162 eth_dev->tx_pkt_burst = NULL;
1168 rte_dpaa2_probe(struct rte_dpaa2_driver *dpaa2_drv __rte_unused,
1169 struct rte_dpaa2_device *dpaa2_dev)
1171 struct rte_eth_dev *eth_dev;
1172 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
1176 sprintf(ethdev_name, "dpni-%d", dpaa2_dev->object_id);
1178 eth_dev = rte_eth_dev_allocate(ethdev_name);
1179 if (eth_dev == NULL)
1182 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1183 eth_dev->data->dev_private = rte_zmalloc(
1184 "ethdev private structure",
1185 sizeof(struct dpaa2_dev_priv),
1186 RTE_CACHE_LINE_SIZE);
1187 if (eth_dev->data->dev_private == NULL) {
1188 PMD_INIT_LOG(CRIT, "Cannot allocate memzone for"
1189 " private port data\n");
1190 rte_eth_dev_release_port(eth_dev);
1194 eth_dev->device = &dpaa2_dev->device;
1195 dpaa2_dev->eth_dev = eth_dev;
1196 eth_dev->data->rx_mbuf_alloc_failed = 0;
1198 /* Invoke PMD device initialization function */
1199 diag = dpaa2_dev_init(eth_dev);
1203 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1204 rte_free(eth_dev->data->dev_private);
1205 rte_eth_dev_release_port(eth_dev);
1210 rte_dpaa2_remove(struct rte_dpaa2_device *dpaa2_dev)
1212 struct rte_eth_dev *eth_dev;
1214 eth_dev = dpaa2_dev->eth_dev;
1215 dpaa2_dev_uninit(eth_dev);
1217 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1218 rte_free(eth_dev->data->dev_private);
1219 rte_eth_dev_release_port(eth_dev);
1224 static struct rte_dpaa2_driver rte_dpaa2_pmd = {
1225 .drv_type = DPAA2_MC_DPNI_DEVID,
1226 .probe = rte_dpaa2_probe,
1227 .remove = rte_dpaa2_remove,
1230 RTE_PMD_REGISTER_DPAA2(net_dpaa2, rte_dpaa2_pmd);