Skip to content

Commit 07b9383

Browse files
committed
crypto: octeontx2 - add support for AF to CPT PF uplink mbox
JIRA: https://issues.redhat.com/browse/RHEL-31478 Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git commit 5c55311 Author: Srujana Challa <schalla@marvell.com> Date: Tue Apr 25 19:36:19 2023 +0530 crypto: octeontx2 - add support for AF to CPT PF uplink mbox This patch adds support for AF -> CPT PF uplink mailbox messages and adds a mailbox handler to submit a CPT instruction from AF as current architecture doesn't allow AF to submit CPT instruction directly to HW. Signed-off-by: Srujana Challa <schalla@marvell.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Štěpán Horáček <shoracek@redhat.com>
1 parent 3a54db0 commit 07b9383

File tree

3 files changed

+98
-2
lines changed

3 files changed

+98
-2
lines changed

drivers/crypto/marvell/octeontx2/otx2_cptpf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ struct otx2_cptpf_dev {
4040
struct work_struct afpf_mbox_work;
4141
struct workqueue_struct *afpf_mbox_wq;
4242

43+
struct otx2_mbox afpf_mbox_up;
44+
struct work_struct afpf_mbox_up_work;
45+
4346
/* VF <=> PF mbox */
4447
struct otx2_mbox vfpf_mbox;
4548
struct workqueue_struct *vfpf_mbox_wq;
@@ -61,6 +64,7 @@ struct otx2_cptpf_dev {
6164

6265
irqreturn_t otx2_cptpf_afpf_mbox_intr(int irq, void *arg);
6366
void otx2_cptpf_afpf_mbox_handler(struct work_struct *work);
67+
void otx2_cptpf_afpf_mbox_up_handler(struct work_struct *work);
6468
irqreturn_t otx2_cptpf_vfpf_mbox_intr(int irq, void *arg);
6569
void otx2_cptpf_vfpf_mbox_handler(struct work_struct *work);
6670

drivers/crypto/marvell/octeontx2/otx2_cptpf_main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,19 @@ static int cptpf_afpf_mbox_init(struct otx2_cptpf_dev *cptpf)
473473
if (err)
474474
goto error;
475475

476+
err = otx2_mbox_init(&cptpf->afpf_mbox_up, cptpf->afpf_mbox_base,
477+
pdev, cptpf->reg_base, MBOX_DIR_PFAF_UP, 1);
478+
if (err)
479+
goto mbox_cleanup;
480+
476481
INIT_WORK(&cptpf->afpf_mbox_work, otx2_cptpf_afpf_mbox_handler);
482+
INIT_WORK(&cptpf->afpf_mbox_up_work, otx2_cptpf_afpf_mbox_up_handler);
477483
mutex_init(&cptpf->lock);
484+
478485
return 0;
479486

487+
mbox_cleanup:
488+
otx2_mbox_destroy(&cptpf->afpf_mbox);
480489
error:
481490
destroy_workqueue(cptpf->afpf_mbox_wq);
482491
return err;
@@ -486,6 +495,7 @@ static void cptpf_afpf_mbox_destroy(struct otx2_cptpf_dev *cptpf)
486495
{
487496
destroy_workqueue(cptpf->afpf_mbox_wq);
488497
otx2_mbox_destroy(&cptpf->afpf_mbox);
498+
otx2_mbox_destroy(&cptpf->afpf_mbox_up);
489499
}
490500

491501
static ssize_t kvf_limits_show(struct device *dev,

drivers/crypto/marvell/octeontx2/otx2_cptpf_mbox.c

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,28 @@ void otx2_cptpf_vfpf_mbox_handler(struct work_struct *work)
224224
irqreturn_t otx2_cptpf_afpf_mbox_intr(int __always_unused irq, void *arg)
225225
{
226226
struct otx2_cptpf_dev *cptpf = arg;
227+
struct otx2_mbox_dev *mdev;
228+
struct otx2_mbox *mbox;
229+
struct mbox_hdr *hdr;
227230
u64 intr;
228231

229232
/* Read the interrupt bits */
230233
intr = otx2_cpt_read64(cptpf->reg_base, BLKADDR_RVUM, 0, RVU_PF_INT);
231234

232235
if (intr & 0x1ULL) {
233-
/* Schedule work queue function to process the MBOX request */
234-
queue_work(cptpf->afpf_mbox_wq, &cptpf->afpf_mbox_work);
236+
mbox = &cptpf->afpf_mbox;
237+
mdev = &mbox->dev[0];
238+
hdr = mdev->mbase + mbox->rx_start;
239+
if (hdr->num_msgs)
240+
/* Schedule work queue function to process the MBOX request */
241+
queue_work(cptpf->afpf_mbox_wq, &cptpf->afpf_mbox_work);
242+
243+
mbox = &cptpf->afpf_mbox_up;
244+
mdev = &mbox->dev[0];
245+
hdr = mdev->mbase + mbox->rx_start;
246+
if (hdr->num_msgs)
247+
/* Schedule work queue function to process the MBOX request */
248+
queue_work(cptpf->afpf_mbox_wq, &cptpf->afpf_mbox_up_work);
235249
/* Clear and ack the interrupt */
236250
otx2_cpt_write64(cptpf->reg_base, BLKADDR_RVUM, 0, RVU_PF_INT,
237251
0x1ULL);
@@ -367,3 +381,71 @@ void otx2_cptpf_afpf_mbox_handler(struct work_struct *work)
367381
}
368382
otx2_mbox_reset(afpf_mbox, 0);
369383
}
384+
385+
static void handle_msg_cpt_inst_lmtst(struct otx2_cptpf_dev *cptpf,
386+
struct mbox_msghdr *msg)
387+
{
388+
struct cpt_inst_lmtst_req *req = (struct cpt_inst_lmtst_req *)msg;
389+
struct otx2_cptlfs_info *lfs = &cptpf->lfs;
390+
struct msg_rsp *rsp;
391+
392+
if (cptpf->lfs.lfs_num)
393+
lfs->ops->send_cmd((union otx2_cpt_inst_s *)req->inst, 1,
394+
&lfs->lf[0]);
395+
396+
rsp = (struct msg_rsp *)otx2_mbox_alloc_msg(&cptpf->afpf_mbox_up, 0,
397+
sizeof(*rsp));
398+
if (!rsp)
399+
return;
400+
401+
rsp->hdr.id = msg->id;
402+
rsp->hdr.sig = OTX2_MBOX_RSP_SIG;
403+
rsp->hdr.pcifunc = 0;
404+
rsp->hdr.rc = 0;
405+
}
406+
407+
static void process_afpf_mbox_up_msg(struct otx2_cptpf_dev *cptpf,
408+
struct mbox_msghdr *msg)
409+
{
410+
if (msg->id >= MBOX_MSG_MAX) {
411+
dev_err(&cptpf->pdev->dev,
412+
"MBOX msg with unknown ID %d\n", msg->id);
413+
return;
414+
}
415+
416+
switch (msg->id) {
417+
case MBOX_MSG_CPT_INST_LMTST:
418+
handle_msg_cpt_inst_lmtst(cptpf, msg);
419+
break;
420+
default:
421+
otx2_reply_invalid_msg(&cptpf->afpf_mbox_up, 0, 0, msg->id);
422+
}
423+
}
424+
425+
void otx2_cptpf_afpf_mbox_up_handler(struct work_struct *work)
426+
{
427+
struct otx2_cptpf_dev *cptpf;
428+
struct otx2_mbox_dev *mdev;
429+
struct mbox_hdr *rsp_hdr;
430+
struct mbox_msghdr *msg;
431+
struct otx2_mbox *mbox;
432+
int offset, i;
433+
434+
cptpf = container_of(work, struct otx2_cptpf_dev, afpf_mbox_up_work);
435+
mbox = &cptpf->afpf_mbox_up;
436+
mdev = &mbox->dev[0];
437+
/* Sync mbox data into memory */
438+
smp_wmb();
439+
440+
rsp_hdr = (struct mbox_hdr *)(mdev->mbase + mbox->rx_start);
441+
offset = mbox->rx_start + ALIGN(sizeof(*rsp_hdr), MBOX_MSG_ALIGN);
442+
443+
for (i = 0; i < rsp_hdr->num_msgs; i++) {
444+
msg = (struct mbox_msghdr *)(mdev->mbase + offset);
445+
446+
process_afpf_mbox_up_msg(cptpf, msg);
447+
448+
offset = mbox->rx_start + msg->next_msgoff;
449+
}
450+
otx2_mbox_msg_send(mbox, 0);
451+
}

0 commit comments

Comments
 (0)