Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Srujana Challa and committed by
Herbert Xu
cac482f2 9d1d5702

+85 -28
+1
drivers/crypto/marvell/octeontx2/otx2_cpt_common.h
··· 218 218 int otx2_cpt_detach_rsrcs_msg(struct otx2_cptlfs_info *lfs); 219 219 int otx2_cpt_msix_offset_msg(struct otx2_cptlfs_info *lfs); 220 220 int otx2_cpt_sync_mbox_msg(struct otx2_mbox *mbox); 221 + int otx2_cpt_lf_reset_msg(struct otx2_cptlfs_info *lfs, int slot); 221 222 222 223 #endif /* __OTX2_CPT_COMMON_H */
+26
drivers/crypto/marvell/octeontx2/otx2_cpt_mbox_common.c
··· 229 229 return otx2_mbox_check_rsp_msgs(mbox, 0); 230 230 } 231 231 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);
+50 -25
drivers/crypto/marvell/octeontx2/otx2_cptlf.h
··· 5 5 #define __OTX2_CPTLF_H 6 6 7 7 #include <linux/soc/marvell/octeontx2/asm.h> 8 + #include <linux/bitfield.h> 8 9 #include <mbox.h> 9 10 #include <rvu.h> 10 11 #include "otx2_cpt_common.h" ··· 120 119 u8 kvf_limits; /* Kernel crypto limits */ 121 120 atomic_t state; /* LF's state. started/reset */ 122 121 int blkaddr; /* CPT blkaddr: BLKADDR_CPT0/BLKADDR_CPT1 */ 122 + int global_slot; /* Global slot across the blocks */ 123 123 }; 124 124 125 125 static inline void otx2_cpt_free_instruction_queues( ··· 208 206 otx2_cptlf_do_set_iqueue_size(&lfs->lf[slot]); 209 207 } 210 208 209 + #define INFLIGHT GENMASK_ULL(8, 0) 210 + #define GRB_CNT GENMASK_ULL(39, 32) 211 + #define GWB_CNT GENMASK_ULL(47, 40) 212 + #define XQ_XOR GENMASK_ULL(63, 63) 213 + #define DQPTR GENMASK_ULL(19, 0) 214 + #define NQPTR GENMASK_ULL(51, 32) 215 + 211 216 static inline void otx2_cptlf_do_disable_iqueue(struct otx2_cptlf_info *lf) 212 217 { 213 - union otx2_cptx_lf_ctl lf_ctl = { .u = 0x0 }; 214 - union otx2_cptx_lf_inprog lf_inprog; 218 + void __iomem *reg_base = lf->lfs->reg_base; 219 + struct pci_dev *pdev = lf->lfs->pdev; 215 220 u8 blkaddr = lf->lfs->blkaddr; 216 - int timeout = 20; 221 + int timeout = 1000000; 222 + u64 inprog, inst_ptr; 223 + u64 slot = lf->slot; 224 + u64 qsize, pending; 225 + int i = 0; 217 226 218 227 /* Disable instructions enqueuing */ 219 - otx2_cpt_write64(lf->lfs->reg_base, blkaddr, lf->slot, 220 - OTX2_CPT_LF_CTL, lf_ctl.u); 228 + otx2_cpt_write64(reg_base, blkaddr, slot, OTX2_CPT_LF_CTL, 0x0); 221 229 222 - /* Wait for instruction queue to become empty */ 230 + inprog = otx2_cpt_read64(reg_base, blkaddr, slot, OTX2_CPT_LF_INPROG); 231 + inprog |= BIT_ULL(16); 232 + otx2_cpt_write64(reg_base, blkaddr, slot, OTX2_CPT_LF_INPROG, inprog); 233 + 234 + qsize = otx2_cpt_read64(reg_base, blkaddr, slot, OTX2_CPT_LF_Q_SIZE) & 0x7FFF; 223 235 do { 224 - lf_inprog.u = otx2_cpt_read64(lf->lfs->reg_base, blkaddr, 225 - lf->slot, OTX2_CPT_LF_INPROG); 226 - if (!lf_inprog.s.inflight) 227 - break; 236 + inst_ptr = otx2_cpt_read64(reg_base, blkaddr, slot, OTX2_CPT_LF_Q_INST_PTR); 237 + pending = (FIELD_GET(XQ_XOR, inst_ptr) * qsize * 40) + 238 + FIELD_GET(NQPTR, inst_ptr) - FIELD_GET(DQPTR, inst_ptr); 239 + udelay(1); 240 + timeout--; 241 + } while ((pending != 0) && (timeout != 0)); 228 242 229 - usleep_range(10000, 20000); 230 - if (timeout-- < 0) { 231 - dev_err(&lf->lfs->pdev->dev, 232 - "Error LF %d is still busy.\n", lf->slot); 233 - break; 243 + if (timeout == 0) 244 + dev_warn(&pdev->dev, "TIMEOUT: CPT poll on pending instructions\n"); 245 + 246 + timeout = 1000000; 247 + /* Wait for CPT queue to become execution-quiescent */ 248 + do { 249 + inprog = otx2_cpt_read64(reg_base, blkaddr, slot, OTX2_CPT_LF_INPROG); 250 + 251 + if ((FIELD_GET(INFLIGHT, inprog) == 0) && 252 + (FIELD_GET(GRB_CNT, inprog) == 0)) { 253 + i++; 254 + } else { 255 + i = 0; 256 + timeout--; 234 257 } 258 + } while ((timeout != 0) && (i < 10)); 235 259 236 - } while (1); 237 - 238 - /* 239 - * Disable executions in the LF's queue, 240 - * the queue should be empty at this point 241 - */ 242 - lf_inprog.s.eena = 0x0; 243 - otx2_cpt_write64(lf->lfs->reg_base, blkaddr, lf->slot, 244 - OTX2_CPT_LF_INPROG, lf_inprog.u); 260 + if (timeout == 0) 261 + dev_warn(&pdev->dev, "TIMEOUT: CPT poll on inflight count\n"); 262 + /* Wait for 2 us to flush all queue writes to memory */ 263 + udelay(2); 245 264 } 246 265 247 266 static inline void otx2_cptlf_disable_iqueues(struct otx2_cptlfs_info *lfs) 248 267 { 249 268 int slot; 250 269 251 - for (slot = 0; slot < lfs->lfs_num; slot++) 270 + for (slot = 0; slot < lfs->lfs_num; slot++) { 252 271 otx2_cptlf_do_disable_iqueue(&lfs->lf[slot]); 272 + otx2_cpt_lf_reset_msg(lfs, lfs->global_slot + slot); 273 + } 253 274 } 254 275 255 276 static inline void otx2_cptlf_set_iqueue_enq(struct otx2_cptlf_info *lf,
+6 -3
drivers/crypto/marvell/octeontx2/otx2_cptpf_mbox.c
··· 201 201 struct mbox_msghdr *req) 202 202 { 203 203 struct otx2_cpt_rx_inline_lf_cfg *cfg_req; 204 + int num_lfs = 1, ret; 204 205 u8 egrp; 205 - int ret; 206 206 207 207 cfg_req = (struct otx2_cpt_rx_inline_lf_cfg *)req; 208 208 if (cptpf->lfs.lfs_num) { ··· 223 223 224 224 otx2_cptlf_set_dev_info(&cptpf->lfs, cptpf->pdev, cptpf->reg_base, 225 225 &cptpf->afpf_mbox, BLKADDR_CPT0); 226 + cptpf->lfs.global_slot = 0; 226 227 ret = otx2_cptlf_init(&cptpf->lfs, 1 << egrp, OTX2_CPT_QUEUE_HI_PRIO, 227 - 1); 228 + num_lfs); 228 229 if (ret) { 229 230 dev_err(&cptpf->pdev->dev, 230 231 "LF configuration failed for RX inline ipsec.\n"); ··· 237 236 otx2_cptlf_set_dev_info(&cptpf->cpt1_lfs, cptpf->pdev, 238 237 cptpf->reg_base, &cptpf->afpf_mbox, 239 238 BLKADDR_CPT1); 239 + cptpf->cpt1_lfs.global_slot = num_lfs; 240 240 ret = otx2_cptlf_init(&cptpf->cpt1_lfs, 1 << egrp, 241 - OTX2_CPT_QUEUE_HI_PRIO, 1); 241 + OTX2_CPT_QUEUE_HI_PRIO, num_lfs); 242 242 if (ret) { 243 243 dev_err(&cptpf->pdev->dev, 244 244 "LF configuration failed for RX inline ipsec.\n"); ··· 451 449 break; 452 450 case MBOX_MSG_CPT_INLINE_IPSEC_CFG: 453 451 case MBOX_MSG_NIX_INLINE_IPSEC_CFG: 452 + case MBOX_MSG_CPT_LF_RESET: 454 453 break; 455 454 456 455 default:
+2
drivers/crypto/marvell/octeontx2/otx2_cptvf_mbox.c
··· 133 133 memcpy(cptvf->eng_caps, eng_caps->eng_caps, 134 134 sizeof(cptvf->eng_caps)); 135 135 break; 136 + case MBOX_MSG_CPT_LF_RESET: 137 + break; 136 138 default: 137 139 dev_err(&cptvf->pdev->dev, "Unsupported msg %d received.\n", 138 140 msg->id);