1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
10 #include <rte_common.h>
12 #include <rte_lcore.h>
13 #include <rte_mempool.h>
15 #include <rte_rawdev.h>
16 #include <rte_rawdev_pmd.h>
18 #include "otx2_common.h"
19 #include "otx2_ep_rawdev.h"
21 #define SDP_IOQ_NUM_BUFS (4 * 1024)
22 #define SDP_IOQ_BUF_SIZE (2 * 1024)
24 #define SDP_TEST_PKT_FSZ (0)
25 #define SDP_TEST_PKT_SIZE (1024)
28 sdp_validate_data(struct sdp_droq_pkt *oq_pkt, uint8_t *iq_pkt,
34 if (pkt_len != oq_pkt->len) {
35 otx2_err("Invalid packet length");
39 if (memcmp(oq_pkt->data, iq_pkt, pkt_len) != 0) {
40 otx2_err("Data validation failed");
43 otx2_sdp_dbg("Data validation successful");
49 sdp_ioq_buffer_fill(uint8_t *addr, uint32_t len)
55 for (idx = 0; idx < len; idx++)
59 static struct rte_mempool*
60 sdp_ioq_mempool_create(void)
62 struct rte_mempool *mpool;
64 mpool = rte_mempool_create("ioqbuf_pool",
65 SDP_IOQ_NUM_BUFS /*num elt*/,
66 SDP_IOQ_BUF_SIZE /*elt size*/,
68 0 /*private_data_size*/,
72 NULL /*obj_init arg*/,
73 rte_socket_id() /*socket id*/,
74 (MEMPOOL_F_SP_PUT | MEMPOOL_F_SC_GET));
81 sdp_rawdev_selftest(uint16_t dev_id)
83 struct sdp_rawdev_info app_info = {0};
84 struct rte_rawdev_info dev_info = {0};
86 struct rte_rawdev_buf *d_buf[1];
87 struct sdp_droq_pkt oq_pkt;
88 struct sdp_soft_instr si;
89 struct sdp_device sdpvf;
95 otx2_info("SDP RAWDEV Self Test: Started");
97 memset(&oq_pkt, 0x00, sizeof(oq_pkt));
98 d_buf[0] = (struct rte_rawdev_buf *)&oq_pkt;
100 struct rte_mempool *ioq_mpool = sdp_ioq_mempool_create();
102 otx2_err("IOQ mpool creation failed");
106 app_info.enqdeq_mpool = ioq_mpool;
107 app_info.app_conf = NULL; /* Use default conf */
109 dev_info.dev_private = &app_info;
111 ret = rte_rawdev_configure(dev_id, &dev_info);
113 otx2_err("Unable to configure SDP_VF %d", dev_id);
114 rte_mempool_free(ioq_mpool);
117 otx2_info("SDP VF rawdev[%d] configured successfully", dev_id);
119 memset(&si, 0x00, sizeof(si));
120 memset(&sdpvf, 0x00, sizeof(sdpvf));
122 buf_size = SDP_TEST_PKT_SIZE;
125 si.reqtype = SDP_REQTYPE_NORESP;
128 si.ih.fsz = SDP_TEST_PKT_FSZ;
129 si.ih.tlen = buf_size;
132 /* Enqueue raw pkt data */
133 rte_mempool_get(ioq_mpool, &buf);
135 otx2_err("Buffer allocation failed");
136 rte_mempool_free(ioq_mpool);
137 rte_rawdev_close(dev_id);
141 sdp_ioq_buffer_fill(buf, buf_size);
142 si.dptr = (uint8_t *)buf;
144 rte_rawdev_enqueue_buffers(dev_id, NULL, 1, &si);
147 /* Dequeue raw pkt data */
150 ret = rte_rawdev_dequeue_buffers(dev_id, &d_buf[0], 1, &si);
154 /* Validate the dequeued raw pkt data */
155 if (sdp_validate_data((struct sdp_droq_pkt *)d_buf[0],
156 buf, buf_size) != 0) {
157 otx2_err("Data invalid");
158 rte_mempool_put(ioq_mpool,
159 ((struct sdp_droq_pkt *)d_buf[0])->data);
160 rte_mempool_free(ioq_mpool);
161 rte_rawdev_close(dev_id);
165 rte_mempool_put(ioq_mpool, ((struct sdp_droq_pkt *)d_buf[0])->data);
166 rte_mempool_free(ioq_mpool);
167 rte_rawdev_close(dev_id);
169 otx2_info("SDP RAWDEV Self Test: Successful");