Skip to content

Commit d0ba353

Browse files
committed
crypto: octeontx2 - add LF reset on queue disable
JIRA: https://issues.redhat.com/browse/RHEL-31478 Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git commit cac482f Author: Srujana Challa <schalla@marvell.com> Date: Wed Dec 13 13:00:51 2023 +0530 crypto: octeontx2 - add LF reset on queue disable CPT LF must be reset and follow CPT LF disable sequence suggested by HW team, when driver exits. This patch adds code for the same. 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 bb1548d commit d0ba353

File tree

5 files changed

+86
-29
lines changed

5 files changed

+86
-29
lines changed

drivers/crypto/marvell/octeontx2/otx2_cpt_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,5 +218,6 @@ int otx2_cpt_attach_rscrs_msg(struct otx2_cptlfs_info *lfs);
218218
int otx2_cpt_detach_rsrcs_msg(struct otx2_cptlfs_info *lfs);
219219
int otx2_cpt_msix_offset_msg(struct otx2_cptlfs_info *lfs);
220220
int otx2_cpt_sync_mbox_msg(struct otx2_mbox *mbox);
221+
int otx2_cpt_lf_reset_msg(struct otx2_cptlfs_info *lfs, int slot);
221222

222223
#endif /* __OTX2_CPT_COMMON_H */

drivers/crypto/marvell/octeontx2/otx2_cpt_mbox_common.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,29 @@ int otx2_cpt_sync_mbox_msg(struct otx2_mbox *mbox)
229229
return otx2_mbox_check_rsp_msgs(mbox, 0);
230230
}
231231
EXPORT_SYMBOL_NS_GPL(otx2_cpt_sync_mbox_msg, CRYPTO_DEV_OCTEONTX2_CPT);
232+
233+
int otx2_cpt_lf_reset_msg(struct otx2_cptlfs_info *lfs, int slot)
234+
{
235+
struct otx2_mbox *mbox = lfs->mbox;
236+
struct pci_dev *pdev = lfs->pdev;
237+
struct cpt_lf_rst_req *req;
238+
int ret;
239+
240+
req = (struct cpt_lf_rst_req *)otx2_mbox_alloc_msg_rsp(mbox, 0, sizeof(*req),
241+
sizeof(struct msg_rsp));
242+
if (!req) {
243+
dev_err(&pdev->dev, "RVU MBOX failed to get message.\n");
244+
return -EFAULT;
245+
}
246+
247+
req->hdr.id = MBOX_MSG_CPT_LF_RESET;
248+
req->hdr.sig = OTX2_MBOX_REQ_SIG;
249+
req->hdr.pcifunc = 0;
250+
req->slot = slot;
251+
ret = otx2_cpt_send_mbox_msg(mbox, pdev);
252+
if (ret)
253+
return ret;
254+
255+
return ret;
256+
}
257+
EXPORT_SYMBOL_NS_GPL(otx2_cpt_lf_reset_msg, CRYPTO_DEV_OCTEONTX2_CPT);

drivers/crypto/marvell/octeontx2/otx2_cptlf.h

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define __OTX2_CPTLF_H
66

77
#include <linux/soc/marvell/octeontx2/asm.h>
8+
#include <linux/bitfield.h>
89
#include <mbox.h>
910
#include <rvu.h>
1011
#include "otx2_cpt_common.h"
@@ -119,6 +120,7 @@ struct otx2_cptlfs_info {
119120
u8 kvf_limits; /* Kernel crypto limits */
120121
atomic_t state; /* LF's state. started/reset */
121122
int blkaddr; /* CPT blkaddr: BLKADDR_CPT0/BLKADDR_CPT1 */
123+
int global_slot; /* Global slot across the blocks */
122124
};
123125

124126
static inline void otx2_cpt_free_instruction_queues(
@@ -206,48 +208,71 @@ static inline void otx2_cptlf_set_iqueues_size(struct otx2_cptlfs_info *lfs)
206208
otx2_cptlf_do_set_iqueue_size(&lfs->lf[slot]);
207209
}
208210

211+
#define INFLIGHT GENMASK_ULL(8, 0)
212+
#define GRB_CNT GENMASK_ULL(39, 32)
213+
#define GWB_CNT GENMASK_ULL(47, 40)
214+
#define XQ_XOR GENMASK_ULL(63, 63)
215+
#define DQPTR GENMASK_ULL(19, 0)
216+
#define NQPTR GENMASK_ULL(51, 32)
217+
209218
static inline void otx2_cptlf_do_disable_iqueue(struct otx2_cptlf_info *lf)
210219
{
211-
union otx2_cptx_lf_ctl lf_ctl = { .u = 0x0 };
212-
union otx2_cptx_lf_inprog lf_inprog;
220+
void __iomem *reg_base = lf->lfs->reg_base;
221+
struct pci_dev *pdev = lf->lfs->pdev;
213222
u8 blkaddr = lf->lfs->blkaddr;
214-
int timeout = 20;
223+
int timeout = 1000000;
224+
u64 inprog, inst_ptr;
225+
u64 slot = lf->slot;
226+
u64 qsize, pending;
227+
int i = 0;
215228

216229
/* Disable instructions enqueuing */
217-
otx2_cpt_write64(lf->lfs->reg_base, blkaddr, lf->slot,
218-
OTX2_CPT_LF_CTL, lf_ctl.u);
230+
otx2_cpt_write64(reg_base, blkaddr, slot, OTX2_CPT_LF_CTL, 0x0);
219231

220-
/* Wait for instruction queue to become empty */
232+
inprog = otx2_cpt_read64(reg_base, blkaddr, slot, OTX2_CPT_LF_INPROG);
233+
inprog |= BIT_ULL(16);
234+
otx2_cpt_write64(reg_base, blkaddr, slot, OTX2_CPT_LF_INPROG, inprog);
235+
236+
qsize = otx2_cpt_read64(reg_base, blkaddr, slot, OTX2_CPT_LF_Q_SIZE) & 0x7FFF;
237+
do {
238+
inst_ptr = otx2_cpt_read64(reg_base, blkaddr, slot, OTX2_CPT_LF_Q_INST_PTR);
239+
pending = (FIELD_GET(XQ_XOR, inst_ptr) * qsize * 40) +
240+
FIELD_GET(NQPTR, inst_ptr) - FIELD_GET(DQPTR, inst_ptr);
241+
udelay(1);
242+
timeout--;
243+
} while ((pending != 0) && (timeout != 0));
244+
245+
if (timeout == 0)
246+
dev_warn(&pdev->dev, "TIMEOUT: CPT poll on pending instructions\n");
247+
248+
timeout = 1000000;
249+
/* Wait for CPT queue to become execution-quiescent */
221250
do {
222-
lf_inprog.u = otx2_cpt_read64(lf->lfs->reg_base, blkaddr,
223-
lf->slot, OTX2_CPT_LF_INPROG);
224-
if (!lf_inprog.s.inflight)
225-
break;
226-
227-
usleep_range(10000, 20000);
228-
if (timeout-- < 0) {
229-
dev_err(&lf->lfs->pdev->dev,
230-
"Error LF %d is still busy.\n", lf->slot);
231-
break;
251+
inprog = otx2_cpt_read64(reg_base, blkaddr, slot, OTX2_CPT_LF_INPROG);
252+
253+
if ((FIELD_GET(INFLIGHT, inprog) == 0) &&
254+
(FIELD_GET(GRB_CNT, inprog) == 0)) {
255+
i++;
256+
} else {
257+
i = 0;
258+
timeout--;
232259
}
260+
} while ((timeout != 0) && (i < 10));
233261

234-
} while (1);
235-
236-
/*
237-
* Disable executions in the LF's queue,
238-
* the queue should be empty at this point
239-
*/
240-
lf_inprog.s.eena = 0x0;
241-
otx2_cpt_write64(lf->lfs->reg_base, blkaddr, lf->slot,
242-
OTX2_CPT_LF_INPROG, lf_inprog.u);
262+
if (timeout == 0)
263+
dev_warn(&pdev->dev, "TIMEOUT: CPT poll on inflight count\n");
264+
/* Wait for 2 us to flush all queue writes to memory */
265+
udelay(2);
243266
}
244267

245268
static inline void otx2_cptlf_disable_iqueues(struct otx2_cptlfs_info *lfs)
246269
{
247270
int slot;
248271

249-
for (slot = 0; slot < lfs->lfs_num; slot++)
272+
for (slot = 0; slot < lfs->lfs_num; slot++) {
250273
otx2_cptlf_do_disable_iqueue(&lfs->lf[slot]);
274+
otx2_cpt_lf_reset_msg(lfs, lfs->global_slot + slot);
275+
}
251276
}
252277

253278
static inline void otx2_cptlf_set_iqueue_enq(struct otx2_cptlf_info *lf,

drivers/crypto/marvell/octeontx2/otx2_cptpf_mbox.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ static int handle_msg_rx_inline_ipsec_lf_cfg(struct otx2_cptpf_dev *cptpf,
201201
struct mbox_msghdr *req)
202202
{
203203
struct otx2_cpt_rx_inline_lf_cfg *cfg_req;
204+
int num_lfs = 1, ret;
204205
u8 egrp;
205-
int ret;
206206

207207
cfg_req = (struct otx2_cpt_rx_inline_lf_cfg *)req;
208208
if (cptpf->lfs.lfs_num) {
@@ -223,8 +223,9 @@ static int handle_msg_rx_inline_ipsec_lf_cfg(struct otx2_cptpf_dev *cptpf,
223223

224224
otx2_cptlf_set_dev_info(&cptpf->lfs, cptpf->pdev, cptpf->reg_base,
225225
&cptpf->afpf_mbox, BLKADDR_CPT0);
226+
cptpf->lfs.global_slot = 0;
226227
ret = otx2_cptlf_init(&cptpf->lfs, 1 << egrp, OTX2_CPT_QUEUE_HI_PRIO,
227-
1);
228+
num_lfs);
228229
if (ret) {
229230
dev_err(&cptpf->pdev->dev,
230231
"LF configuration failed for RX inline ipsec.\n");
@@ -236,8 +237,9 @@ static int handle_msg_rx_inline_ipsec_lf_cfg(struct otx2_cptpf_dev *cptpf,
236237
otx2_cptlf_set_dev_info(&cptpf->cpt1_lfs, cptpf->pdev,
237238
cptpf->reg_base, &cptpf->afpf_mbox,
238239
BLKADDR_CPT1);
240+
cptpf->cpt1_lfs.global_slot = num_lfs;
239241
ret = otx2_cptlf_init(&cptpf->cpt1_lfs, 1 << egrp,
240-
OTX2_CPT_QUEUE_HI_PRIO, 1);
242+
OTX2_CPT_QUEUE_HI_PRIO, num_lfs);
241243
if (ret) {
242244
dev_err(&cptpf->pdev->dev,
243245
"LF configuration failed for RX inline ipsec.\n");
@@ -449,6 +451,7 @@ static void process_afpf_mbox_msg(struct otx2_cptpf_dev *cptpf,
449451
break;
450452
case MBOX_MSG_CPT_INLINE_IPSEC_CFG:
451453
case MBOX_MSG_NIX_INLINE_IPSEC_CFG:
454+
case MBOX_MSG_CPT_LF_RESET:
452455
break;
453456

454457
default:

drivers/crypto/marvell/octeontx2/otx2_cptvf_mbox.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ static void process_pfvf_mbox_mbox_msg(struct otx2_cptvf_dev *cptvf,
133133
memcpy(cptvf->eng_caps, eng_caps->eng_caps,
134134
sizeof(cptvf->eng_caps));
135135
break;
136+
case MBOX_MSG_CPT_LF_RESET:
137+
break;
136138
default:
137139
dev_err(&cptvf->pdev->dev, "Unsupported msg %d received.\n",
138140
msg->id);

0 commit comments

Comments
 (0)