Skip to content

Commit 78506c2

Browse files
SruChallaherbertx
authored andcommitted
crypto: octeontx2 - add support to get engine capabilities
Adds support to get engine capabilities and adds a new mailbox to share capabilities with VF driver. Signed-off-by: Suheil Chandran <schandran@marvell.com> Signed-off-by: Srujana Challa <schalla@marvell.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 6450601 commit 78506c2

File tree

8 files changed

+350
-0
lines changed

8 files changed

+350
-0
lines changed

drivers/crypto/marvell/octeontx2/otx2_cpt_common.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#define OTX2_CPT_INVALID_CRYPTO_ENG_GRP 0xFF
2222
#define OTX2_CPT_NAME_LENGTH 64
23+
#define OTX2_CPT_DMA_MINALIGN 128
2324

2425
#define BAD_OTX2_CPT_ENG_TYPE OTX2_CPT_MAX_ENG_TYPES
2526

@@ -32,6 +33,7 @@ enum otx2_cpt_eng_type {
3233

3334
/* Take mbox id from end of CPT mbox range in AF (range 0xA00 - 0xBFF) */
3435
#define MBOX_MSG_GET_ENG_GRP_NUM 0xBFF
36+
#define MBOX_MSG_GET_CAPS 0xBFD
3537

3638
/*
3739
* Message request and response to get engine group number
@@ -49,6 +51,40 @@ struct otx2_cpt_egrp_num_rsp {
4951
u8 eng_grp_num;
5052
};
5153

54+
/* CPT HW capabilities */
55+
union otx2_cpt_eng_caps {
56+
u64 u;
57+
struct {
58+
u64 reserved_0_4:5;
59+
u64 mul:1;
60+
u64 sha1_sha2:1;
61+
u64 chacha20:1;
62+
u64 zuc_snow3g:1;
63+
u64 sha3:1;
64+
u64 aes:1;
65+
u64 kasumi:1;
66+
u64 des:1;
67+
u64 crc:1;
68+
u64 reserved_14_63:50;
69+
};
70+
};
71+
72+
/*
73+
* Message request and response to get HW capabilities for each
74+
* engine type (SE, IE, AE).
75+
* This messages are only used between CPT PF <=> CPT VF
76+
*/
77+
struct otx2_cpt_caps_msg {
78+
struct mbox_msghdr hdr;
79+
};
80+
81+
struct otx2_cpt_caps_rsp {
82+
struct mbox_msghdr hdr;
83+
u16 cpt_pf_drv_version;
84+
u8 cpt_revision;
85+
union otx2_cpt_eng_caps eng_caps[OTX2_CPT_MAX_ENG_TYPES];
86+
};
87+
5288
static inline void otx2_cpt_write64(void __iomem *reg_base, u64 blk, u64 slot,
5389
u64 offs, u64 val)
5490
{
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only
2+
* Copyright (C) 2020 Marvell.
3+
*/
4+
5+
#ifndef __OTX2_CPT_REQMGR_H
6+
#define __OTX2_CPT_REQMGR_H
7+
8+
#include "otx2_cpt_common.h"
9+
10+
/* Completion code size and initial value */
11+
#define OTX2_CPT_COMPLETION_CODE_SIZE 8
12+
#define OTX2_CPT_COMPLETION_CODE_INIT OTX2_CPT_COMP_E_NOTDONE
13+
14+
union otx2_cpt_opcode {
15+
u16 flags;
16+
struct {
17+
u8 major;
18+
u8 minor;
19+
} s;
20+
};
21+
22+
/*
23+
* CPT_INST_S software command definitions
24+
* Words EI (0-3)
25+
*/
26+
union otx2_cpt_iq_cmd_word0 {
27+
u64 u;
28+
struct {
29+
__be16 opcode;
30+
__be16 param1;
31+
__be16 param2;
32+
__be16 dlen;
33+
} s;
34+
};
35+
36+
union otx2_cpt_iq_cmd_word3 {
37+
u64 u;
38+
struct {
39+
u64 cptr:61;
40+
u64 grp:3;
41+
} s;
42+
};
43+
44+
struct otx2_cpt_iq_command {
45+
union otx2_cpt_iq_cmd_word0 cmd;
46+
u64 dptr;
47+
u64 rptr;
48+
union otx2_cpt_iq_cmd_word3 cptr;
49+
};
50+
51+
#endif /* __OTX2_CPT_REQMGR_H */

drivers/crypto/marvell/octeontx2/otx2_cptlf.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
#ifndef __OTX2_CPTLF_H
55
#define __OTX2_CPTLF_H
66

7+
#include <linux/soc/marvell/octeontx2/asm.h>
78
#include <mbox.h>
89
#include <rvu.h>
910
#include "otx2_cpt_common.h"
11+
#include "otx2_cpt_reqmgr.h"
1012

1113
/*
1214
* CPT instruction and pending queues user requested length in CPT_INST_S msgs
@@ -272,6 +274,66 @@ static inline void otx2_cptlf_enable_iqueues(struct otx2_cptlfs_info *lfs)
272274
}
273275
}
274276

277+
static inline void otx2_cpt_fill_inst(union otx2_cpt_inst_s *cptinst,
278+
struct otx2_cpt_iq_command *iq_cmd,
279+
u64 comp_baddr)
280+
{
281+
cptinst->u[0] = 0x0;
282+
cptinst->s.doneint = true;
283+
cptinst->s.res_addr = comp_baddr;
284+
cptinst->u[2] = 0x0;
285+
cptinst->u[3] = 0x0;
286+
cptinst->s.ei0 = iq_cmd->cmd.u;
287+
cptinst->s.ei1 = iq_cmd->dptr;
288+
cptinst->s.ei2 = iq_cmd->rptr;
289+
cptinst->s.ei3 = iq_cmd->cptr.u;
290+
}
291+
292+
/*
293+
* On OcteonTX2 platform the parameter insts_num is used as a count of
294+
* instructions to be enqueued. The valid values for insts_num are:
295+
* 1 - 1 CPT instruction will be enqueued during LMTST operation
296+
* 2 - 2 CPT instructions will be enqueued during LMTST operation
297+
*/
298+
static inline void otx2_cpt_send_cmd(union otx2_cpt_inst_s *cptinst,
299+
u32 insts_num, struct otx2_cptlf_info *lf)
300+
{
301+
void __iomem *lmtline = lf->lmtline;
302+
long ret;
303+
304+
/*
305+
* Make sure memory areas pointed in CPT_INST_S
306+
* are flushed before the instruction is sent to CPT
307+
*/
308+
dma_wmb();
309+
310+
do {
311+
/* Copy CPT command to LMTLINE */
312+
memcpy_toio(lmtline, cptinst, insts_num * OTX2_CPT_INST_SIZE);
313+
314+
/*
315+
* LDEOR initiates atomic transfer to I/O device
316+
* The following will cause the LMTST to fail (the LDEOR
317+
* returns zero):
318+
* - No stores have been performed to the LMTLINE since it was
319+
* last invalidated.
320+
* - The bytes which have been stored to LMTLINE since it was
321+
* last invalidated form a pattern that is non-contiguous, does
322+
* not start at byte 0, or does not end on a 8-byte boundary.
323+
* (i.e.comprises a formation of other than 1–16 8-byte
324+
* words.)
325+
*
326+
* These rules are designed such that an operating system
327+
* context switch or hypervisor guest switch need have no
328+
* knowledge of the LMTST operations; the switch code does not
329+
* need to store to LMTCANCEL. Also note as LMTLINE data cannot
330+
* be read, there is no information leakage between processes.
331+
*/
332+
ret = otx2_lmt_flush(lf->ioreg);
333+
334+
} while (!ret);
335+
}
336+
275337
int otx2_cptlf_init(struct otx2_cptlfs_info *lfs, u8 eng_grp_msk, int pri,
276338
int lfs_num);
277339
void otx2_cptlf_shutdown(struct otx2_cptlfs_info *lfs);

drivers/crypto/marvell/octeontx2/otx2_cptpf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ struct otx2_cptpf_dev {
3131
struct otx2_cptvf_info vf[OTX2_CPT_MAX_VFS_NUM];
3232
struct otx2_cpt_eng_grps eng_grps;/* Engine groups information */
3333
struct otx2_cptlfs_info lfs; /* CPT LFs attached to this PF */
34+
/* HW capabilities for each engine type */
35+
union otx2_cpt_eng_caps eng_caps[OTX2_CPT_MAX_ENG_TYPES];
36+
bool is_eng_caps_discovered;
3437

3538
/* AF <=> PF mbox */
3639
struct otx2_mbox afpf_mbox;

drivers/crypto/marvell/octeontx2/otx2_cptpf_main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,11 @@ static int cptpf_sriov_enable(struct pci_dev *pdev, int num_vfs)
500500
if (ret)
501501
goto destroy_flr;
502502

503+
/* Get CPT HW capabilities using LOAD_FVC operation. */
504+
ret = otx2_cpt_discover_eng_capabilities(cptpf);
505+
if (ret)
506+
goto disable_intr;
507+
503508
ret = otx2_cpt_create_eng_grps(cptpf->pdev, &cptpf->eng_grps);
504509
if (ret)
505510
goto disable_intr;

drivers/crypto/marvell/octeontx2/otx2_cptpf_mbox.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
#include "otx2_cptpf.h"
66
#include "rvu_reg.h"
77

8+
/*
9+
* CPT PF driver version, It will be incremented by 1 for every feature
10+
* addition in CPT mailbox messages.
11+
*/
12+
#define OTX2_CPT_PF_DRV_VERSION 0x1
13+
814
static int forward_to_af(struct otx2_cptpf_dev *cptpf,
915
struct otx2_cptvf_info *vf,
1016
struct mbox_msghdr *req, int size)
@@ -35,6 +41,28 @@ static int forward_to_af(struct otx2_cptpf_dev *cptpf,
3541
return 0;
3642
}
3743

44+
static int handle_msg_get_caps(struct otx2_cptpf_dev *cptpf,
45+
struct otx2_cptvf_info *vf,
46+
struct mbox_msghdr *req)
47+
{
48+
struct otx2_cpt_caps_rsp *rsp;
49+
50+
rsp = (struct otx2_cpt_caps_rsp *)
51+
otx2_mbox_alloc_msg(&cptpf->vfpf_mbox, vf->vf_id,
52+
sizeof(*rsp));
53+
if (!rsp)
54+
return -ENOMEM;
55+
56+
rsp->hdr.id = MBOX_MSG_GET_CAPS;
57+
rsp->hdr.sig = OTX2_MBOX_RSP_SIG;
58+
rsp->hdr.pcifunc = req->pcifunc;
59+
rsp->cpt_pf_drv_version = OTX2_CPT_PF_DRV_VERSION;
60+
rsp->cpt_revision = cptpf->pdev->revision;
61+
memcpy(&rsp->eng_caps, &cptpf->eng_caps, sizeof(rsp->eng_caps));
62+
63+
return 0;
64+
}
65+
3866
static int handle_msg_get_eng_grp_num(struct otx2_cptpf_dev *cptpf,
3967
struct otx2_cptvf_info *vf,
4068
struct mbox_msghdr *req)
@@ -72,6 +100,9 @@ static int cptpf_handle_vf_req(struct otx2_cptpf_dev *cptpf,
72100
case MBOX_MSG_GET_ENG_GRP_NUM:
73101
err = handle_msg_get_eng_grp_num(cptpf, vf, req);
74102
break;
103+
case MBOX_MSG_GET_CAPS:
104+
err = handle_msg_get_caps(cptpf, vf, req);
105+
break;
75106
default:
76107
err = forward_to_af(cptpf, vf, req, size);
77108
break;

0 commit comments

Comments
 (0)