1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (C) 2020 Marvell International Ltd.
5 #include "otx2_common.h"
7 #include "otx2_regexdev_mbox.h"
8 #include "otx2_regexdev.h"
11 otx2_ree_available_queues_get(const struct rte_regexdev *dev,
14 struct otx2_ree_data *data = dev->data->dev_private;
15 struct otx2_ree_vf *vf = &data->vf;
16 struct free_rsrcs_rsp *rsp;
17 struct otx2_dev *otx2_dev;
20 otx2_dev = &vf->otx2_dev;
21 otx2_mbox_alloc_msg_free_rsrc_cnt(otx2_dev->mbox);
23 ret = otx2_mbox_process_msg(otx2_dev->mbox, (void *)&rsp);
27 if (vf->block_address == RVU_BLOCK_ADDR_REE0)
28 *nb_queues = rsp->ree0;
30 *nb_queues = rsp->ree1;
35 otx2_ree_queues_attach(const struct rte_regexdev *dev, uint8_t nb_queues)
37 struct otx2_ree_data *data = dev->data->dev_private;
38 struct otx2_ree_vf *vf = &data->vf;
39 struct rsrc_attach_req *req;
40 struct otx2_mbox *mbox;
42 /* Ask AF to attach required LFs */
43 mbox = vf->otx2_dev.mbox;
44 req = otx2_mbox_alloc_msg_attach_resources(mbox);
47 req->reelfs = nb_queues;
48 req->ree_blkaddr = vf->block_address;
50 if (otx2_mbox_process(mbox) < 0)
53 /* Update number of attached queues */
54 vf->nb_queues = nb_queues;
60 otx2_ree_queues_detach(const struct rte_regexdev *dev)
62 struct otx2_ree_data *data = dev->data->dev_private;
63 struct otx2_ree_vf *vf = &data->vf;
64 struct rsrc_detach_req *req;
65 struct otx2_mbox *mbox;
67 mbox = vf->otx2_dev.mbox;
68 req = otx2_mbox_alloc_msg_detach_resources(mbox);
71 if (otx2_mbox_process(mbox) < 0)
74 /* Queues have been detached */
81 otx2_ree_msix_offsets_get(const struct rte_regexdev *dev)
83 struct otx2_ree_data *data = dev->data->dev_private;
84 struct otx2_ree_vf *vf = &data->vf;
85 struct msix_offset_rsp *rsp;
86 struct otx2_mbox *mbox;
89 /* Get REE MSI-X vector offsets */
90 mbox = vf->otx2_dev.mbox;
91 otx2_mbox_alloc_msg_msix_offset(mbox);
93 ret = otx2_mbox_process_msg(mbox, (void *)&rsp);
97 for (i = 0; i < vf->nb_queues; i++) {
98 if (vf->block_address == RVU_BLOCK_ADDR_REE0)
99 vf->lf_msixoff[i] = rsp->ree0_lf_msixoff[i];
101 vf->lf_msixoff[i] = rsp->ree1_lf_msixoff[i];
102 otx2_ree_dbg("lf_msixoff[%d] 0x%x", i, vf->lf_msixoff[i]);
109 ree_send_mbox_msg(struct otx2_ree_vf *vf)
111 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
114 otx2_mbox_msg_send(mbox, 0);
116 ret = otx2_mbox_wait_for_rsp(mbox, 0);
118 otx2_err("Could not get mailbox response");
126 otx2_ree_config_lf(const struct rte_regexdev *dev, uint8_t lf, uint8_t pri,
129 struct otx2_ree_data *data = dev->data->dev_private;
130 struct otx2_ree_vf *vf = &data->vf;
131 struct ree_lf_req_msg *req;
132 struct otx2_mbox *mbox;
135 mbox = vf->otx2_dev.mbox;
136 req = otx2_mbox_alloc_msg_ree_config_lf(mbox);
139 req->pri = pri ? 1 : 0;
141 req->blkaddr = vf->block_address;
143 ret = otx2_mbox_process(mbox);
145 otx2_err("Could not get mailbox response");
152 otx2_ree_af_reg_read(const struct rte_regexdev *dev, uint64_t reg,
155 struct otx2_ree_data *data = dev->data->dev_private;
156 struct otx2_ree_vf *vf = &data->vf;
157 struct ree_rd_wr_reg_msg *msg;
158 struct otx2_mbox_dev *mdev;
159 struct otx2_mbox *mbox;
162 mbox = vf->otx2_dev.mbox;
163 mdev = &mbox->dev[0];
164 msg = (struct ree_rd_wr_reg_msg *)otx2_mbox_alloc_msg_rsp(mbox, 0,
165 sizeof(*msg), sizeof(*msg));
167 otx2_err("Could not allocate mailbox message");
171 msg->hdr.id = MBOX_MSG_REE_RD_WR_REGISTER;
172 msg->hdr.sig = OTX2_MBOX_REQ_SIG;
173 msg->hdr.pcifunc = vf->otx2_dev.pf_func;
175 msg->reg_offset = reg;
177 msg->blkaddr = vf->block_address;
179 ret = ree_send_mbox_msg(vf);
183 off = mbox->rx_start +
184 RTE_ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
185 msg = (struct ree_rd_wr_reg_msg *) ((uintptr_t)mdev->mbase + off);
193 otx2_ree_af_reg_write(const struct rte_regexdev *dev, uint64_t reg,
196 struct otx2_ree_data *data = dev->data->dev_private;
197 struct otx2_ree_vf *vf = &data->vf;
198 struct ree_rd_wr_reg_msg *msg;
199 struct otx2_mbox *mbox;
201 mbox = vf->otx2_dev.mbox;
202 msg = (struct ree_rd_wr_reg_msg *)otx2_mbox_alloc_msg_rsp(mbox, 0,
203 sizeof(*msg), sizeof(*msg));
205 otx2_err("Could not allocate mailbox message");
209 msg->hdr.id = MBOX_MSG_REE_RD_WR_REGISTER;
210 msg->hdr.sig = OTX2_MBOX_REQ_SIG;
211 msg->hdr.pcifunc = vf->otx2_dev.pf_func;
213 msg->reg_offset = reg;
215 msg->blkaddr = vf->block_address;
217 return ree_send_mbox_msg(vf);
221 otx2_ree_rule_db_get(const struct rte_regexdev *dev, char *rule_db,
222 uint32_t rule_db_len, char *rule_dbi, uint32_t rule_dbi_len)
224 struct otx2_ree_data *data = dev->data->dev_private;
225 struct ree_rule_db_get_req_msg *req;
226 struct ree_rule_db_get_rsp_msg *rsp;
227 char *rule_db_ptr = (char *)rule_db;
228 struct otx2_ree_vf *vf = &data->vf;
229 struct otx2_mbox *mbox;
233 mbox = vf->otx2_dev.mbox;
235 otx2_err("Couldn't return rule db due to NULL pointer");
240 req = (struct ree_rule_db_get_req_msg *)
241 otx2_mbox_alloc_msg_rsp(mbox, 0, sizeof(*req),
244 otx2_err("Could not allocate mailbox message");
248 req->hdr.id = MBOX_MSG_REE_RULE_DB_GET;
249 req->hdr.sig = OTX2_MBOX_REQ_SIG;
250 req->hdr.pcifunc = vf->otx2_dev.pf_func;
251 req->blkaddr = vf->block_address;
254 ret = otx2_mbox_process_msg(mbox, (void *)&rsp);
257 if (rule_db_len < len + rsp->len) {
258 otx2_err("Rule db size is too small");
261 otx2_mbox_memcpy(rule_db_ptr, rsp->rule_db, rsp->len);
263 rule_db_ptr = rule_db_ptr + rsp->len;
268 req = (struct ree_rule_db_get_req_msg *)
269 otx2_mbox_alloc_msg_rsp(mbox, 0, sizeof(*req),
272 otx2_err("Could not allocate mailbox message");
276 req->hdr.id = MBOX_MSG_REE_RULE_DB_GET;
277 req->hdr.sig = OTX2_MBOX_REQ_SIG;
278 req->hdr.pcifunc = vf->otx2_dev.pf_func;
279 req->blkaddr = vf->block_address;
283 ret = otx2_mbox_process_msg(mbox, (void *)&rsp);
286 if (rule_dbi_len < rsp->len) {
287 otx2_err("Rule dbi size is too small");
290 otx2_mbox_memcpy(rule_dbi, rsp->rule_db, rsp->len);
296 otx2_ree_rule_db_len_get(const struct rte_regexdev *dev,
297 uint32_t *rule_db_len,
298 uint32_t *rule_dbi_len)
300 struct otx2_ree_data *data = dev->data->dev_private;
301 struct ree_rule_db_len_rsp_msg *rsp;
302 struct otx2_ree_vf *vf = &data->vf;
303 struct ree_req_msg *req;
304 struct otx2_mbox *mbox;
307 mbox = vf->otx2_dev.mbox;
308 req = (struct ree_req_msg *)
309 otx2_mbox_alloc_msg_rsp(mbox, 0, sizeof(*req), sizeof(*rsp));
311 otx2_err("Could not allocate mailbox message");
315 req->hdr.id = MBOX_MSG_REE_RULE_DB_LEN_GET;
316 req->hdr.sig = OTX2_MBOX_REQ_SIG;
317 req->hdr.pcifunc = vf->otx2_dev.pf_func;
318 req->blkaddr = vf->block_address;
319 ret = otx2_mbox_process_msg(mbox, (void *)&rsp);
322 if (rule_db_len != NULL)
323 *rule_db_len = rsp->len;
324 if (rule_dbi_len != NULL)
325 *rule_dbi_len = rsp->inc_len;
331 ree_db_msg(const struct rte_regexdev *dev, const char *db, uint32_t db_len,
334 struct otx2_ree_data *data = dev->data->dev_private;
335 uint32_t len_left = db_len, offset = 0;
336 struct ree_rule_db_prog_req_msg *req;
337 struct otx2_ree_vf *vf = &data->vf;
338 const char *rule_db_ptr = db;
339 struct otx2_mbox *mbox;
343 mbox = vf->otx2_dev.mbox;
345 req = (struct ree_rule_db_prog_req_msg *)
346 otx2_mbox_alloc_msg_rsp(mbox, 0, sizeof(*req),
349 otx2_err("Could not allocate mailbox message");
352 req->hdr.id = MBOX_MSG_REE_RULE_DB_PROG;
353 req->hdr.sig = OTX2_MBOX_REQ_SIG;
354 req->hdr.pcifunc = vf->otx2_dev.pf_func;
355 req->offset = offset;
356 req->total_len = db_len;
357 req->len = REE_RULE_DB_REQ_BLOCK_SIZE;
358 req->is_incremental = inc;
360 req->blkaddr = vf->block_address;
362 if (len_left < REE_RULE_DB_REQ_BLOCK_SIZE) {
366 otx2_mbox_memcpy(req->rule_db, rule_db_ptr, req->len);
367 ret = otx2_mbox_process_msg(mbox, (void *)&rsp);
369 otx2_err("Programming mailbox processing failed");
372 len_left -= req->len;
374 rule_db_ptr = rule_db_ptr + req->len;
380 otx2_ree_rule_db_prog(const struct rte_regexdev *dev, const char *rule_db,
381 uint32_t rule_db_len, const char *rule_dbi,
382 uint32_t rule_dbi_len)
386 if (rule_db_len == 0) {
387 otx2_err("Couldn't program empty rule db");
390 inc = (rule_dbi_len != 0);
391 if ((rule_db == NULL) || (inc && (rule_dbi == NULL))) {
392 otx2_err("Couldn't program NULL rule db");
396 ret = ree_db_msg(dev, rule_dbi, rule_dbi_len, inc, 1);
400 return ree_db_msg(dev, rule_db, rule_db_len, inc, 0);