Skip to content

Commit d9110b0

Browse files
SruChallaherbertx
authored andcommitted
crypto: marvell - add support for OCTEON TX CPT engine
Add support for the cryptographic acceleration unit (CPT) on OcteonTX CN83XX SoC. Co-developed-by: Lukasz Bartosik <[email protected]> Signed-off-by: Lukasz Bartosik <[email protected]> Signed-off-by: SrujanaChalla <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 655ff1a commit d9110b0

File tree

9 files changed

+2765
-0
lines changed

9 files changed

+2765
-0
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10018,6 +10018,7 @@ F: Documentation/devicetree/bindings/phy/phy-mvebu-utmi.txt
1001810018
MARVELL CRYPTO DRIVER
1001910019
M: Boris Brezillon <[email protected]>
1002010020
M: Arnaud Ebalard <[email protected]>
10021+
M: Srujana Challa <[email protected]>
1002110022
F: drivers/crypto/marvell/
1002210023
S: Maintained
1002310024
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
obj-$(CONFIG_CRYPTO_DEV_OCTEONTX_CPT) += octeontx-cpt.o
3+
4+
octeontx-cpt-objs := otx_cptpf_main.o otx_cptpf_mbox.o otx_cptpf_ucode.o
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
2+
* Marvell OcteonTX CPT driver
3+
*
4+
* Copyright (C) 2019 Marvell International Ltd.
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 as
8+
* published by the Free Software Foundation.
9+
*/
10+
11+
#ifndef __OTX_CPT_COMMON_H
12+
#define __OTX_CPT_COMMON_H
13+
14+
#include <linux/types.h>
15+
#include <linux/delay.h>
16+
#include <linux/device.h>
17+
18+
#define OTX_CPT_MAX_MBOX_DATA_STR_SIZE 64
19+
20+
enum otx_cptpf_type {
21+
OTX_CPT_AE = 2,
22+
OTX_CPT_SE = 3,
23+
BAD_OTX_CPTPF_TYPE,
24+
};
25+
26+
enum otx_cptvf_type {
27+
OTX_CPT_AE_TYPES = 1,
28+
OTX_CPT_SE_TYPES = 2,
29+
BAD_OTX_CPTVF_TYPE,
30+
};
31+
32+
/* VF-PF message opcodes */
33+
enum otx_cpt_mbox_opcode {
34+
OTX_CPT_MSG_VF_UP = 1,
35+
OTX_CPT_MSG_VF_DOWN,
36+
OTX_CPT_MSG_READY,
37+
OTX_CPT_MSG_QLEN,
38+
OTX_CPT_MSG_QBIND_GRP,
39+
OTX_CPT_MSG_VQ_PRIORITY,
40+
OTX_CPT_MSG_PF_TYPE,
41+
OTX_CPT_MSG_ACK,
42+
OTX_CPT_MSG_NACK
43+
};
44+
45+
/* OcteonTX CPT mailbox structure */
46+
struct otx_cpt_mbox {
47+
u64 msg; /* Message type MBOX[0] */
48+
u64 data;/* Data MBOX[1] */
49+
};
50+
51+
#endif /* __OTX_CPT_COMMON_H */
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
/* SPDX-License-Identifier: GPL-2.0
2+
* Marvell OcteonTX CPT driver
3+
*
4+
* Copyright (C) 2019 Marvell International Ltd.
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 as
8+
* published by the Free Software Foundation.
9+
*/
10+
11+
#ifndef __OTX_CPT_HW_TYPES_H
12+
#define __OTX_CPT_HW_TYPES_H
13+
14+
#include <linux/types.h>
15+
16+
/* Device IDs */
17+
#define OTX_CPT_PCI_PF_DEVICE_ID 0xa040
18+
19+
#define OTX_CPT_PCI_PF_SUBSYS_ID 0xa340
20+
21+
/* Configuration and status registers are in BAR0 on OcteonTX platform */
22+
#define OTX_CPT_PF_PCI_CFG_BAR 0
23+
/* Mailbox interrupts offset */
24+
#define OTX_CPT_PF_MBOX_INT 3
25+
#define OTX_CPT_PF_INT_VEC_E_MBOXX(x, a) ((x) + (a))
26+
/* Number of MSIX supported in PF */
27+
#define OTX_CPT_PF_MSIX_VECTORS 4
28+
/* Maximum supported microcode groups */
29+
#define OTX_CPT_MAX_ENGINE_GROUPS 8
30+
31+
/* OcteonTX CPT PF registers */
32+
#define OTX_CPT_PF_CONSTANTS (0x0ll)
33+
#define OTX_CPT_PF_RESET (0x100ll)
34+
#define OTX_CPT_PF_DIAG (0x120ll)
35+
#define OTX_CPT_PF_BIST_STATUS (0x160ll)
36+
#define OTX_CPT_PF_ECC0_CTL (0x200ll)
37+
#define OTX_CPT_PF_ECC0_FLIP (0x210ll)
38+
#define OTX_CPT_PF_ECC0_INT (0x220ll)
39+
#define OTX_CPT_PF_ECC0_INT_W1S (0x230ll)
40+
#define OTX_CPT_PF_ECC0_ENA_W1S (0x240ll)
41+
#define OTX_CPT_PF_ECC0_ENA_W1C (0x250ll)
42+
#define OTX_CPT_PF_MBOX_INTX(b) (0x400ll | (u64)(b) << 3)
43+
#define OTX_CPT_PF_MBOX_INT_W1SX(b) (0x420ll | (u64)(b) << 3)
44+
#define OTX_CPT_PF_MBOX_ENA_W1CX(b) (0x440ll | (u64)(b) << 3)
45+
#define OTX_CPT_PF_MBOX_ENA_W1SX(b) (0x460ll | (u64)(b) << 3)
46+
#define OTX_CPT_PF_EXEC_INT (0x500ll)
47+
#define OTX_CPT_PF_EXEC_INT_W1S (0x520ll)
48+
#define OTX_CPT_PF_EXEC_ENA_W1C (0x540ll)
49+
#define OTX_CPT_PF_EXEC_ENA_W1S (0x560ll)
50+
#define OTX_CPT_PF_GX_EN(b) (0x600ll | (u64)(b) << 3)
51+
#define OTX_CPT_PF_EXEC_INFO (0x700ll)
52+
#define OTX_CPT_PF_EXEC_BUSY (0x800ll)
53+
#define OTX_CPT_PF_EXEC_INFO0 (0x900ll)
54+
#define OTX_CPT_PF_EXEC_INFO1 (0x910ll)
55+
#define OTX_CPT_PF_INST_REQ_PC (0x10000ll)
56+
#define OTX_CPT_PF_INST_LATENCY_PC (0x10020ll)
57+
#define OTX_CPT_PF_RD_REQ_PC (0x10040ll)
58+
#define OTX_CPT_PF_RD_LATENCY_PC (0x10060ll)
59+
#define OTX_CPT_PF_RD_UC_PC (0x10080ll)
60+
#define OTX_CPT_PF_ACTIVE_CYCLES_PC (0x10100ll)
61+
#define OTX_CPT_PF_EXE_CTL (0x4000000ll)
62+
#define OTX_CPT_PF_EXE_STATUS (0x4000008ll)
63+
#define OTX_CPT_PF_EXE_CLK (0x4000010ll)
64+
#define OTX_CPT_PF_EXE_DBG_CTL (0x4000018ll)
65+
#define OTX_CPT_PF_EXE_DBG_DATA (0x4000020ll)
66+
#define OTX_CPT_PF_EXE_BIST_STATUS (0x4000028ll)
67+
#define OTX_CPT_PF_EXE_REQ_TIMER (0x4000030ll)
68+
#define OTX_CPT_PF_EXE_MEM_CTL (0x4000038ll)
69+
#define OTX_CPT_PF_EXE_PERF_CTL (0x4001000ll)
70+
#define OTX_CPT_PF_EXE_DBG_CNTX(b) (0x4001100ll | (u64)(b) << 3)
71+
#define OTX_CPT_PF_EXE_PERF_EVENT_CNT (0x4001180ll)
72+
#define OTX_CPT_PF_EXE_EPCI_INBX_CNT(b) (0x4001200ll | (u64)(b) << 3)
73+
#define OTX_CPT_PF_EXE_EPCI_OUTBX_CNT(b) (0x4001240ll | (u64)(b) << 3)
74+
#define OTX_CPT_PF_ENGX_UCODE_BASE(b) (0x4002000ll | (u64)(b) << 3)
75+
#define OTX_CPT_PF_QX_CTL(b) (0x8000000ll | (u64)(b) << 20)
76+
#define OTX_CPT_PF_QX_GMCTL(b) (0x8000020ll | (u64)(b) << 20)
77+
#define OTX_CPT_PF_QX_CTL2(b) (0x8000100ll | (u64)(b) << 20)
78+
#define OTX_CPT_PF_VFX_MBOXX(b, c) (0x8001000ll | (u64)(b) << 20 | \
79+
(u64)(c) << 8)
80+
81+
/*
82+
* Register (NCB) otx_cpt#_pf_bist_status
83+
*
84+
* CPT PF Control Bist Status Register
85+
* This register has the BIST status of memories. Each bit is the BIST result
86+
* of an individual memory (per bit, 0 = pass and 1 = fail).
87+
* otx_cptx_pf_bist_status_s
88+
* Word0
89+
* bstatus [29:0](RO/H) BIST status. One bit per memory, enumerated by
90+
* CPT_RAMS_E.
91+
*/
92+
union otx_cptx_pf_bist_status {
93+
u64 u;
94+
struct otx_cptx_pf_bist_status_s {
95+
#if defined(__BIG_ENDIAN_BITFIELD) /* Word 0 - Big Endian */
96+
u64 reserved_30_63:34;
97+
u64 bstatus:30;
98+
#else /* Word 0 - Little Endian */
99+
u64 bstatus:30;
100+
u64 reserved_30_63:34;
101+
#endif /* Word 0 - End */
102+
} s;
103+
};
104+
105+
/*
106+
* Register (NCB) otx_cpt#_pf_constants
107+
*
108+
* CPT PF Constants Register
109+
* This register contains implementation-related parameters of CPT in CNXXXX.
110+
* otx_cptx_pf_constants_s
111+
* Word 0
112+
* reserved_40_63:24 [63:40] Reserved.
113+
* epcis:8 [39:32](RO) Number of EPCI busses.
114+
* grps:8 [31:24](RO) Number of engine groups implemented.
115+
* ae:8 [23:16](RO/H) Number of AEs. In CNXXXX, for CPT0 returns 0x0,
116+
* for CPT1 returns 0x18, or less if there are fuse-disables.
117+
* se:8 [15:8](RO/H) Number of SEs. In CNXXXX, for CPT0 returns 0x30,
118+
* or less if there are fuse-disables, for CPT1 returns 0x0.
119+
* vq:8 [7:0](RO) Number of VQs.
120+
*/
121+
union otx_cptx_pf_constants {
122+
u64 u;
123+
struct otx_cptx_pf_constants_s {
124+
#if defined(__BIG_ENDIAN_BITFIELD) /* Word 0 - Big Endian */
125+
u64 reserved_40_63:24;
126+
u64 epcis:8;
127+
u64 grps:8;
128+
u64 ae:8;
129+
u64 se:8;
130+
u64 vq:8;
131+
#else /* Word 0 - Little Endian */
132+
u64 vq:8;
133+
u64 se:8;
134+
u64 ae:8;
135+
u64 grps:8;
136+
u64 epcis:8;
137+
u64 reserved_40_63:24;
138+
#endif /* Word 0 - End */
139+
} s;
140+
};
141+
142+
/*
143+
* Register (NCB) otx_cpt#_pf_exe_bist_status
144+
*
145+
* CPT PF Engine Bist Status Register
146+
* This register has the BIST status of each engine. Each bit is the
147+
* BIST result of an individual engine (per bit, 0 = pass and 1 = fail).
148+
* otx_cptx_pf_exe_bist_status_s
149+
* Word0
150+
* reserved_48_63:16 [63:48] reserved
151+
* bstatus:48 [47:0](RO/H) BIST status. One bit per engine.
152+
*
153+
*/
154+
union otx_cptx_pf_exe_bist_status {
155+
u64 u;
156+
struct otx_cptx_pf_exe_bist_status_s {
157+
#if defined(__BIG_ENDIAN_BITFIELD) /* Word 0 - Big Endian */
158+
u64 reserved_48_63:16;
159+
u64 bstatus:48;
160+
#else /* Word 0 - Little Endian */
161+
u64 bstatus:48;
162+
u64 reserved_48_63:16;
163+
#endif /* Word 0 - End */
164+
} s;
165+
};
166+
167+
/*
168+
* Register (NCB) otx_cpt#_pf_q#_ctl
169+
*
170+
* CPT Queue Control Register
171+
* This register configures queues. This register should be changed only
172+
* when quiescent (see CPT()_VQ()_INPROG[INFLIGHT]).
173+
* otx_cptx_pf_qx_ctl_s
174+
* Word0
175+
* reserved_60_63:4 [63:60] reserved.
176+
* aura:12; [59:48](R/W) Guest-aura for returning this queue's
177+
* instruction-chunk buffers to FPA. Only used when [INST_FREE] is set.
178+
* For the FPA to not discard the request, FPA_PF_MAP() must map
179+
* [AURA] and CPT()_PF_Q()_GMCTL[GMID] as valid.
180+
* reserved_45_47:3 [47:45] reserved.
181+
* size:13 [44:32](R/W) Command-buffer size, in number of 64-bit words per
182+
* command buffer segment. Must be 8*n + 1, where n is the number of
183+
* instructions per buffer segment.
184+
* reserved_11_31:21 [31:11] Reserved.
185+
* cont_err:1 [10:10](R/W) Continue on error.
186+
* 0 = When CPT()_VQ()_MISC_INT[NWRP], CPT()_VQ()_MISC_INT[IRDE] or
187+
* CPT()_VQ()_MISC_INT[DOVF] are set by hardware or software via
188+
* CPT()_VQ()_MISC_INT_W1S, then CPT()_VQ()_CTL[ENA] is cleared. Due to
189+
* pipelining, additional instructions may have been processed between the
190+
* instruction causing the error and the next instruction in the disabled
191+
* queue (the instruction at CPT()_VQ()_SADDR).
192+
* 1 = Ignore errors and continue processing instructions.
193+
* For diagnostic use only.
194+
* inst_free:1 [9:9](R/W) Instruction FPA free. When set, when CPT reaches the
195+
* end of an instruction chunk, that chunk will be freed to the FPA.
196+
* inst_be:1 [8:8](R/W) Instruction big-endian control. When set, instructions,
197+
* instruction next chunk pointers, and result structures are stored in
198+
* big-endian format in memory.
199+
* iqb_ldwb:1 [7:7](R/W) Instruction load don't write back.
200+
* 0 = The hardware issues NCB transient load (LDT) towards the cache,
201+
* which if the line hits and is is dirty will cause the line to be
202+
* written back before being replaced.
203+
* 1 = The hardware issues NCB LDWB read-and-invalidate command towards
204+
* the cache when fetching the last word of instructions; as a result the
205+
* line will not be written back when replaced. This improves
206+
* performance, but software must not read the instructions after they are
207+
* posted to the hardware. Reads that do not consume the last word of a
208+
* cache line always use LDI.
209+
* reserved_4_6:3 [6:4] Reserved.
210+
* grp:3; [3:1](R/W) Engine group.
211+
* pri:1; [0:0](R/W) Queue priority.
212+
* 1 = This queue has higher priority. Round-robin between higher
213+
* priority queues.
214+
* 0 = This queue has lower priority. Round-robin between lower
215+
* priority queues.
216+
*/
217+
union otx_cptx_pf_qx_ctl {
218+
u64 u;
219+
struct otx_cptx_pf_qx_ctl_s {
220+
#if defined(__BIG_ENDIAN_BITFIELD) /* Word 0 - Big Endian */
221+
u64 reserved_60_63:4;
222+
u64 aura:12;
223+
u64 reserved_45_47:3;
224+
u64 size:13;
225+
u64 reserved_11_31:21;
226+
u64 cont_err:1;
227+
u64 inst_free:1;
228+
u64 inst_be:1;
229+
u64 iqb_ldwb:1;
230+
u64 reserved_4_6:3;
231+
u64 grp:3;
232+
u64 pri:1;
233+
#else /* Word 0 - Little Endian */
234+
u64 pri:1;
235+
u64 grp:3;
236+
u64 reserved_4_6:3;
237+
u64 iqb_ldwb:1;
238+
u64 inst_be:1;
239+
u64 inst_free:1;
240+
u64 cont_err:1;
241+
u64 reserved_11_31:21;
242+
u64 size:13;
243+
u64 reserved_45_47:3;
244+
u64 aura:12;
245+
u64 reserved_60_63:4;
246+
#endif /* Word 0 - End */
247+
} s;
248+
};
249+
#endif /* __OTX_CPT_HW_TYPES_H */
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* SPDX-License-Identifier: GPL-2.0
2+
* Marvell OcteonTX CPT driver
3+
*
4+
* Copyright (C) 2019 Marvell International Ltd.
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 as
8+
* published by the Free Software Foundation.
9+
*/
10+
11+
#ifndef __OTX_CPTPF_H
12+
#define __OTX_CPTPF_H
13+
14+
#include <linux/types.h>
15+
#include <linux/device.h>
16+
#include "otx_cptpf_ucode.h"
17+
18+
/*
19+
* OcteonTX CPT device structure
20+
*/
21+
struct otx_cpt_device {
22+
void __iomem *reg_base; /* Register start address */
23+
struct pci_dev *pdev; /* Pci device handle */
24+
struct otx_cpt_eng_grps eng_grps;/* Engine groups information */
25+
struct list_head list;
26+
u8 pf_type; /* PF type SE or AE */
27+
u8 max_vfs; /* Maximum number of VFs supported by the CPT */
28+
u8 vfs_enabled; /* Number of enabled VFs */
29+
};
30+
31+
void otx_cpt_mbox_intr_handler(struct otx_cpt_device *cpt, int mbx);
32+
void otx_cpt_disable_all_cores(struct otx_cpt_device *cpt);
33+
34+
#endif /* __OTX_CPTPF_H */

0 commit comments

Comments
 (0)