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>
43 #include <rte_ethdev.h>
45 #include <fslmc_logs.h>
46 #include <fslmc_vfio.h>
47 #include <dpaa2_hw_pvt.h>
48 #include <dpaa2_hw_dpio.h>
49 #include <dpaa2_hw_mempool.h>
51 #include "dpaa2_ethdev.h"
53 static inline struct rte_mbuf *__attribute__((hot))
54 eth_fd_to_mbuf(const struct qbman_fd *fd)
56 struct rte_mbuf *mbuf = DPAA2_INLINE_MBUF_FROM_BUF(
57 DPAA2_GET_FD_ADDR(fd),
58 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size);
60 /* need to repopulated some of the fields,
61 * as they may have changed in last transmission
65 mbuf->data_off = DPAA2_GET_FD_OFFSET(fd);
66 mbuf->data_len = DPAA2_GET_FD_LEN(fd);
67 mbuf->pkt_len = mbuf->data_len;
69 mbuf->packet_type = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4;
72 rte_mbuf_refcnt_set(mbuf, 1);
74 PMD_RX_LOG(DEBUG, "to mbuf - mbuf =%p, mbuf->buf_addr =%p, off = %d,"
75 "fd_off=%d fd =%lx, meta = %d bpid =%d, len=%d\n",
76 mbuf, mbuf->buf_addr, mbuf->data_off,
77 DPAA2_GET_FD_OFFSET(fd), DPAA2_GET_FD_ADDR(fd),
78 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size,
79 DPAA2_GET_FD_BPID(fd), DPAA2_GET_FD_LEN(fd));
84 static void __attribute__ ((noinline)) __attribute__((hot))
85 eth_mbuf_to_fd(struct rte_mbuf *mbuf,
86 struct qbman_fd *fd, uint16_t bpid)
88 /*Resetting the buffer pool id and offset field*/
89 fd->simple.bpid_offset = 0;
91 DPAA2_SET_FD_ADDR(fd, (mbuf->buf_addr));
92 DPAA2_SET_FD_LEN(fd, mbuf->data_len);
93 DPAA2_SET_FD_BPID(fd, bpid);
94 DPAA2_SET_FD_OFFSET(fd, mbuf->data_off);
95 DPAA2_SET_FD_ASAL(fd, DPAA2_ASAL_VAL);
97 PMD_TX_LOG(DEBUG, "mbuf =%p, mbuf->buf_addr =%p, off = %d,"
98 "fd_off=%d fd =%lx, meta = %d bpid =%d, len=%d\n",
99 mbuf, mbuf->buf_addr, mbuf->data_off,
100 DPAA2_GET_FD_OFFSET(fd), DPAA2_GET_FD_ADDR(fd),
101 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size,
102 DPAA2_GET_FD_BPID(fd), DPAA2_GET_FD_LEN(fd));
106 dpaa2_dev_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
108 /* Function is responsible to receive frames for a given device and VQ*/
109 struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)queue;
110 struct qbman_result *dq_storage;
111 uint32_t fqid = dpaa2_q->fqid;
113 uint8_t is_last = 0, status;
114 struct qbman_swp *swp;
115 const struct qbman_fd *fd;
116 struct qbman_pull_desc pulldesc;
117 struct rte_eth_dev *dev = dpaa2_q->dev;
119 if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
120 ret = dpaa2_affine_qbman_swp();
122 RTE_LOG(ERR, PMD, "Failure in affining portal\n");
126 swp = DPAA2_PER_LCORE_PORTAL;
127 dq_storage = dpaa2_q->q_storage->dq_storage[0];
129 qbman_pull_desc_clear(&pulldesc);
130 qbman_pull_desc_set_numframes(&pulldesc,
131 (nb_pkts > DPAA2_DQRR_RING_SIZE) ?
132 DPAA2_DQRR_RING_SIZE : nb_pkts);
133 qbman_pull_desc_set_fq(&pulldesc, fqid);
134 /* todo optimization - we can have dq_storage_phys available*/
135 qbman_pull_desc_set_storage(&pulldesc, dq_storage,
136 (dma_addr_t)(dq_storage), 1);
138 /*Issue a volatile dequeue command. */
140 if (qbman_swp_pull(swp, &pulldesc)) {
141 PMD_RX_LOG(ERR, "VDQ command is not issued."
143 /* Portal was busy, try again */
149 /* Receive the packets till Last Dequeue entry is found with
150 * respect to the above issues PULL command.
153 struct rte_mbuf *mbuf;
154 /*Check if the previous issued command is completed.
155 * Also seems like the SWP is shared between the
156 * Ethernet Driver and the SEC driver.
158 while (!qbman_check_command_complete(swp, dq_storage))
160 /* Loop until the dq_storage is updated with
163 while (!qbman_result_has_new_result(swp, dq_storage))
165 /* Check whether Last Pull command is Expired and
166 * setting Condition for Loop termination
168 if (qbman_result_DQ_is_pull_complete(dq_storage)) {
170 /* Check for valid frame. */
171 status = (uint8_t)qbman_result_DQ_flags(dq_storage);
172 if (unlikely((status & QBMAN_DQ_STAT_VALIDFRAME) == 0))
176 fd = qbman_result_DQ_fd(dq_storage);
177 mbuf = (struct rte_mbuf *)(DPAA2_GET_FD_ADDR(fd)
178 - rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size);
181 /* Prefetch Annotation address for the parse results */
182 rte_prefetch0((void *)((uint64_t)DPAA2_GET_FD_ADDR(fd)
183 + DPAA2_FD_PTA_SIZE + 16));
185 bufs[num_rx] = eth_fd_to_mbuf(fd);
186 bufs[num_rx]->port = dev->data->port_id;
190 } /* End of Packet Rx loop */
192 dpaa2_q->rx_pkts += num_rx;
194 /*Return the total number of packets received to DPAA2 app*/
199 * Callback to handle sending packets through WRIOP based interface
202 dpaa2_dev_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
204 /* Function to transmit the frames to given device and VQ*/
207 struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
208 uint32_t frames_to_send;
209 struct rte_mempool *mp;
210 struct qbman_eq_desc eqdesc;
211 struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)queue;
212 struct qbman_swp *swp;
215 struct rte_eth_dev *dev = dpaa2_q->dev;
216 struct dpaa2_dev_priv *priv = dev->data->dev_private;
218 if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
219 ret = dpaa2_affine_qbman_swp();
221 RTE_LOG(ERR, PMD, "Failure in affining portal\n");
225 swp = DPAA2_PER_LCORE_PORTAL;
227 PMD_TX_LOG(DEBUG, "===> dev =%p, fqid =%d", dev, dpaa2_q->fqid);
229 /*Prepare enqueue descriptor*/
230 qbman_eq_desc_clear(&eqdesc);
231 qbman_eq_desc_set_no_orp(&eqdesc, DPAA2_EQ_RESP_ERR_FQ);
232 qbman_eq_desc_set_response(&eqdesc, 0, 0);
233 qbman_eq_desc_set_qd(&eqdesc, priv->qdid,
234 dpaa2_q->flow_id, dpaa2_q->tc_index);
236 /*Clear the unused FD fields before sending*/
238 frames_to_send = (nb_pkts >> 3) ? MAX_TX_RING_SLOTS : nb_pkts;
240 for (loop = 0; loop < frames_to_send; loop++) {
241 fd_arr[loop].simple.frc = 0;
242 DPAA2_RESET_FD_CTRL((&fd_arr[loop]));
243 DPAA2_SET_FD_FLC((&fd_arr[loop]), NULL);
245 bpid = mempool_to_bpid(mp);
246 eth_mbuf_to_fd(*bufs, &fd_arr[loop], bpid);
250 while (loop < frames_to_send) {
251 loop += qbman_swp_send_multiple(swp, &eqdesc,
252 &fd_arr[loop], frames_to_send - loop);
255 num_tx += frames_to_send;
256 dpaa2_q->tx_pkts += frames_to_send;
257 nb_pkts -= frames_to_send;