GNU Linux-libre 6.7.9-gnu
[releases.git] / drivers / crypto / marvell / octeontx2 / otx2_cpt_hw_types.h
1 /* SPDX-License-Identifier: GPL-2.0-only
2  * Copyright (C) 2020 Marvell.
3  */
4
5 #ifndef __OTX2_CPT_HW_TYPES_H
6 #define __OTX2_CPT_HW_TYPES_H
7
8 #include <linux/types.h>
9
10 /* Device IDs */
11 #define OTX2_CPT_PCI_PF_DEVICE_ID 0xA0FD
12 #define OTX2_CPT_PCI_VF_DEVICE_ID 0xA0FE
13 #define CN10K_CPT_PCI_PF_DEVICE_ID 0xA0F2
14 #define CN10K_CPT_PCI_VF_DEVICE_ID 0xA0F3
15
16 /* Mailbox interrupts offset */
17 #define OTX2_CPT_PF_MBOX_INT    6
18 #define OTX2_CPT_PF_INT_VEC_E_MBOXX(x, a) ((x) + (a))
19
20 /* Maximum supported microcode groups */
21 #define OTX2_CPT_MAX_ENGINE_GROUPS 8
22
23 /* CPT instruction size in bytes */
24 #define OTX2_CPT_INST_SIZE      64
25 /*
26  * CPT VF MSIX vectors and their offsets
27  */
28 #define OTX2_CPT_VF_MSIX_VECTORS 1
29 #define OTX2_CPT_VF_INTR_MBOX_MASK BIT(0)
30 #define CN10K_CPT_VF_MBOX_REGION  (0xC0000)
31
32 /* CPT LF MSIX vectors */
33 #define OTX2_CPT_LF_MSIX_VECTORS 2
34
35 /* OcteonTX2 CPT PF registers */
36 #define OTX2_CPT_PF_CONSTANTS           (0x0)
37 #define OTX2_CPT_PF_RESET               (0x100)
38 #define OTX2_CPT_PF_DIAG                (0x120)
39 #define OTX2_CPT_PF_BIST_STATUS         (0x160)
40 #define OTX2_CPT_PF_ECC0_CTL            (0x200)
41 #define OTX2_CPT_PF_ECC0_FLIP           (0x210)
42 #define OTX2_CPT_PF_ECC0_INT            (0x220)
43 #define OTX2_CPT_PF_ECC0_INT_W1S        (0x230)
44 #define OTX2_CPT_PF_ECC0_ENA_W1S        (0x240)
45 #define OTX2_CPT_PF_ECC0_ENA_W1C        (0x250)
46 #define OTX2_CPT_PF_MBOX_INTX(b)        (0x400 | (b) << 3)
47 #define OTX2_CPT_PF_MBOX_INT_W1SX(b)    (0x420 | (b) << 3)
48 #define OTX2_CPT_PF_MBOX_ENA_W1CX(b)    (0x440 | (b) << 3)
49 #define OTX2_CPT_PF_MBOX_ENA_W1SX(b)    (0x460 | (b) << 3)
50 #define OTX2_CPT_PF_EXEC_INT            (0x500)
51 #define OTX2_CPT_PF_EXEC_INT_W1S        (0x520)
52 #define OTX2_CPT_PF_EXEC_ENA_W1C        (0x540)
53 #define OTX2_CPT_PF_EXEC_ENA_W1S        (0x560)
54 #define OTX2_CPT_PF_GX_EN(b)            (0x600 | (b) << 3)
55 #define OTX2_CPT_PF_EXEC_INFO           (0x700)
56 #define OTX2_CPT_PF_EXEC_BUSY           (0x800)
57 #define OTX2_CPT_PF_EXEC_INFO0          (0x900)
58 #define OTX2_CPT_PF_EXEC_INFO1          (0x910)
59 #define OTX2_CPT_PF_INST_REQ_PC         (0x10000)
60 #define OTX2_CPT_PF_INST_LATENCY_PC     (0x10020)
61 #define OTX2_CPT_PF_RD_REQ_PC           (0x10040)
62 #define OTX2_CPT_PF_RD_LATENCY_PC       (0x10060)
63 #define OTX2_CPT_PF_RD_UC_PC            (0x10080)
64 #define OTX2_CPT_PF_ACTIVE_CYCLES_PC    (0x10100)
65 #define OTX2_CPT_PF_EXE_CTL             (0x4000000)
66 #define OTX2_CPT_PF_EXE_STATUS          (0x4000008)
67 #define OTX2_CPT_PF_EXE_CLK             (0x4000010)
68 #define OTX2_CPT_PF_EXE_DBG_CTL         (0x4000018)
69 #define OTX2_CPT_PF_EXE_DBG_DATA        (0x4000020)
70 #define OTX2_CPT_PF_EXE_BIST_STATUS     (0x4000028)
71 #define OTX2_CPT_PF_EXE_REQ_TIMER       (0x4000030)
72 #define OTX2_CPT_PF_EXE_MEM_CTL         (0x4000038)
73 #define OTX2_CPT_PF_EXE_PERF_CTL        (0x4001000)
74 #define OTX2_CPT_PF_EXE_DBG_CNTX(b)     (0x4001100 | (b) << 3)
75 #define OTX2_CPT_PF_EXE_PERF_EVENT_CNT  (0x4001180)
76 #define OTX2_CPT_PF_EXE_EPCI_INBX_CNT(b)  (0x4001200 | (b) << 3)
77 #define OTX2_CPT_PF_EXE_EPCI_OUTBX_CNT(b) (0x4001240 | (b) << 3)
78 #define OTX2_CPT_PF_ENGX_UCODE_BASE(b)  (0x4002000 | (b) << 3)
79 #define OTX2_CPT_PF_QX_CTL(b)           (0x8000000 | (b) << 20)
80 #define OTX2_CPT_PF_QX_GMCTL(b)         (0x8000020 | (b) << 20)
81 #define OTX2_CPT_PF_QX_CTL2(b)          (0x8000100 | (b) << 20)
82 #define OTX2_CPT_PF_VFX_MBOXX(b, c)     (0x8001000 | (b) << 20 | \
83                                          (c) << 8)
84
85 /* OcteonTX2 CPT LF registers */
86 #define OTX2_CPT_LF_CTL                 (0x10)
87 #define OTX2_CPT_LF_DONE_WAIT           (0x30)
88 #define OTX2_CPT_LF_INPROG              (0x40)
89 #define OTX2_CPT_LF_DONE                (0x50)
90 #define OTX2_CPT_LF_DONE_ACK            (0x60)
91 #define OTX2_CPT_LF_DONE_INT_ENA_W1S    (0x90)
92 #define OTX2_CPT_LF_DONE_INT_ENA_W1C    (0xa0)
93 #define OTX2_CPT_LF_MISC_INT            (0xb0)
94 #define OTX2_CPT_LF_MISC_INT_W1S        (0xc0)
95 #define OTX2_CPT_LF_MISC_INT_ENA_W1S    (0xd0)
96 #define OTX2_CPT_LF_MISC_INT_ENA_W1C    (0xe0)
97 #define OTX2_CPT_LF_Q_BASE              (0xf0)
98 #define OTX2_CPT_LF_Q_SIZE              (0x100)
99 #define OTX2_CPT_LF_Q_INST_PTR          (0x110)
100 #define OTX2_CPT_LF_Q_GRP_PTR           (0x120)
101 #define OTX2_CPT_LF_NQX(a)              (0x400 | (a) << 3)
102 #define OTX2_CPT_RVU_FUNC_BLKADDR_SHIFT 20
103 /* LMT LF registers */
104 #define OTX2_CPT_LMT_LFBASE             BIT_ULL(OTX2_CPT_RVU_FUNC_BLKADDR_SHIFT)
105 #define OTX2_CPT_LMT_LF_LMTLINEX(a)     (OTX2_CPT_LMT_LFBASE | 0x000 | \
106                                          (a) << 12)
107 /* RVU VF registers */
108 #define OTX2_RVU_VF_INT                 (0x20)
109 #define OTX2_RVU_VF_INT_W1S             (0x28)
110 #define OTX2_RVU_VF_INT_ENA_W1S         (0x30)
111 #define OTX2_RVU_VF_INT_ENA_W1C         (0x38)
112
113 /*
114  * Enumeration otx2_cpt_ucode_error_code_e
115  *
116  * Enumerates ucode errors
117  */
118 enum otx2_cpt_ucode_comp_code_e {
119         OTX2_CPT_UCC_SUCCESS = 0x00,
120         OTX2_CPT_UCC_INVALID_OPCODE = 0x01,
121
122         /* Scatter gather */
123         OTX2_CPT_UCC_SG_WRITE_LENGTH = 0x02,
124         OTX2_CPT_UCC_SG_LIST = 0x03,
125         OTX2_CPT_UCC_SG_NOT_SUPPORTED = 0x04,
126
127 };
128
129 /*
130  * Enumeration otx2_cpt_comp_e
131  *
132  * OcteonTX2 CPT Completion Enumeration
133  * Enumerates the values of CPT_RES_S[COMPCODE].
134  */
135 enum otx2_cpt_comp_e {
136         OTX2_CPT_COMP_E_NOTDONE = 0x00,
137         OTX2_CPT_COMP_E_GOOD = 0x01,
138         OTX2_CPT_COMP_E_FAULT = 0x02,
139         OTX2_CPT_COMP_E_HWERR = 0x04,
140         OTX2_CPT_COMP_E_INSTERR = 0x05,
141         OTX2_CPT_COMP_E_WARN = 0x06
142 };
143
144 /*
145  * Enumeration otx2_cpt_vf_int_vec_e
146  *
147  * OcteonTX2 CPT VF MSI-X Vector Enumeration
148  * Enumerates the MSI-X interrupt vectors.
149  */
150 enum otx2_cpt_vf_int_vec_e {
151         OTX2_CPT_VF_INT_VEC_E_MBOX = 0x00
152 };
153
154 /*
155  * Enumeration otx2_cpt_lf_int_vec_e
156  *
157  * OcteonTX2 CPT LF MSI-X Vector Enumeration
158  * Enumerates the MSI-X interrupt vectors.
159  */
160 enum otx2_cpt_lf_int_vec_e {
161         OTX2_CPT_LF_INT_VEC_E_MISC = 0x00,
162         OTX2_CPT_LF_INT_VEC_E_DONE = 0x01
163 };
164
165 /*
166  * Structure otx2_cpt_inst_s
167  *
168  * CPT Instruction Structure
169  * This structure specifies the instruction layout. Instructions are
170  * stored in memory as little-endian unless CPT()_PF_Q()_CTL[INST_BE] is set.
171  * cpt_inst_s_s
172  * Word 0
173  * doneint:1 Done interrupt.
174  *      0 = No interrupts related to this instruction.
175  *      1 = When the instruction completes, CPT()_VQ()_DONE[DONE] will be
176  *      incremented,and based on the rules described there an interrupt may
177  *      occur.
178  * Word 1
179  * res_addr [127: 64] Result IOVA.
180  *      If nonzero, specifies where to write CPT_RES_S.
181  *      If zero, no result structure will be written.
182  *      Address must be 16-byte aligned.
183  *      Bits <63:49> are ignored by hardware; software should use a
184  *      sign-extended bit <48> for forward compatibility.
185  * Word 2
186  *  grp:10 [171:162] If [WQ_PTR] is nonzero, the SSO guest-group to use when
187  *      CPT submits work SSO.
188  *      For the SSO to not discard the add-work request, FPA_PF_MAP() must map
189  *      [GRP] and CPT()_PF_Q()_GMCTL[GMID] as valid.
190  *  tt:2 [161:160] If [WQ_PTR] is nonzero, the SSO tag type to use when CPT
191  *      submits work to SSO
192  *  tag:32 [159:128] If [WQ_PTR] is nonzero, the SSO tag to use when CPT
193  *      submits work to SSO.
194  * Word 3
195  *  wq_ptr [255:192] If [WQ_PTR] is nonzero, it is a pointer to a
196  *      work-queue entry that CPT submits work to SSO after all context,
197  *      output data, and result write operations are visible to other
198  *      CNXXXX units and the cores. Bits <2:0> must be zero.
199  *      Bits <63:49> are ignored by hardware; software should
200  *      use a sign-extended bit <48> for forward compatibility.
201  *      Internal:
202  *      Bits <63:49>, <2:0> are ignored by hardware, treated as always 0x0.
203  * Word 4
204  *  ei0; [319:256] Engine instruction word 0. Passed to the AE/SE.
205  * Word 5
206  *  ei1; [383:320] Engine instruction word 1. Passed to the AE/SE.
207  * Word 6
208  *  ei2; [447:384] Engine instruction word 1. Passed to the AE/SE.
209  * Word 7
210  *  ei3; [511:448] Engine instruction word 1. Passed to the AE/SE.
211  *
212  */
213 union otx2_cpt_inst_s {
214         u64 u[8];
215
216         struct {
217                 /* Word 0 */
218                 u64 nixtxl:3;
219                 u64 doneint:1;
220                 u64 nixtx_addr:60;
221                 /* Word 1 */
222                 u64 res_addr;
223                 /* Word 2 */
224                 u64 tag:32;
225                 u64 tt:2;
226                 u64 grp:10;
227                 u64 reserved_172_175:4;
228                 u64 rvu_pf_func:16;
229                 /* Word 3 */
230                 u64 qord:1;
231                 u64 reserved_194_193:2;
232                 u64 wq_ptr:61;
233                 /* Word 4 */
234                 u64 ei0;
235                 /* Word 5 */
236                 u64 ei1;
237                 /* Word 6 */
238                 u64 ei2;
239                 /* Word 7 */
240                 u64 ei3;
241         } s;
242 };
243
244 /*
245  * Structure otx2_cpt_res_s
246  *
247  * CPT Result Structure
248  * The CPT coprocessor writes the result structure after it completes a
249  * CPT_INST_S instruction. The result structure is exactly 16 bytes, and
250  * each instruction completion produces exactly one result structure.
251  *
252  * This structure is stored in memory as little-endian unless
253  * CPT()_PF_Q()_CTL[INST_BE] is set.
254  * cpt_res_s_s
255  * Word 0
256  *  doneint:1 [16:16] Done interrupt. This bit is copied from the
257  *      corresponding instruction's CPT_INST_S[DONEINT].
258  *  compcode:8 [7:0] Indicates completion/error status of the CPT coprocessor
259  *      for the associated instruction, as enumerated by CPT_COMP_E.
260  *      Core software may write the memory location containing [COMPCODE] to
261  *      0x0 before ringing the doorbell, and then poll for completion by
262  *      checking for a nonzero value.
263  *      Once the core observes a nonzero [COMPCODE] value in this case,the CPT
264  *      coprocessor will have also completed L2/DRAM write operations.
265  * Word 1
266  *  reserved
267  *
268  */
269 union otx2_cpt_res_s {
270         u64 u[2];
271
272         struct cn9k_cpt_res_s {
273                 u64 compcode:8;
274                 u64 uc_compcode:8;
275                 u64 doneint:1;
276                 u64 reserved_17_63:47;
277                 u64 reserved_64_127;
278         } s;
279
280         struct cn10k_cpt_res_s {
281                 u64 compcode:7;
282                 u64 doneint:1;
283                 u64 uc_compcode:8;
284                 u64 rlen:16;
285                 u64 spi:32;
286                 u64 esn;
287         } cn10k;
288 };
289
290 /*
291  * Register (RVU_PF_BAR0) cpt#_af_constants1
292  *
293  * CPT AF Constants Register
294  * This register contains implementation-related parameters of CPT.
295  */
296 union otx2_cptx_af_constants1 {
297         u64 u;
298         struct otx2_cptx_af_constants1_s {
299                 u64 se:16;
300                 u64 ie:16;
301                 u64 ae:16;
302                 u64 reserved_48_63:16;
303         } s;
304 };
305
306 /*
307  * RVU_PFVF_BAR2 - cpt_lf_misc_int
308  *
309  * This register contain the per-queue miscellaneous interrupts.
310  *
311  */
312 union otx2_cptx_lf_misc_int {
313         u64 u;
314         struct otx2_cptx_lf_misc_int_s {
315                 u64 reserved_0:1;
316                 u64 nqerr:1;
317                 u64 irde:1;
318                 u64 nwrp:1;
319                 u64 reserved_4:1;
320                 u64 hwerr:1;
321                 u64 fault:1;
322                 u64 reserved_7_63:57;
323         } s;
324 };
325
326 /*
327  * RVU_PFVF_BAR2 - cpt_lf_misc_int_ena_w1s
328  *
329  * This register sets interrupt enable bits.
330  *
331  */
332 union otx2_cptx_lf_misc_int_ena_w1s {
333         u64 u;
334         struct otx2_cptx_lf_misc_int_ena_w1s_s {
335                 u64 reserved_0:1;
336                 u64 nqerr:1;
337                 u64 irde:1;
338                 u64 nwrp:1;
339                 u64 reserved_4:1;
340                 u64 hwerr:1;
341                 u64 fault:1;
342                 u64 reserved_7_63:57;
343         } s;
344 };
345
346 /*
347  * RVU_PFVF_BAR2 - cpt_lf_ctl
348  *
349  * This register configures the queue.
350  *
351  * When the queue is not execution-quiescent (see CPT_LF_INPROG[EENA,INFLIGHT]),
352  * software must only write this register with [ENA]=0.
353  */
354 union otx2_cptx_lf_ctl {
355         u64 u;
356         struct otx2_cptx_lf_ctl_s {
357                 u64 ena:1;
358                 u64 fc_ena:1;
359                 u64 fc_up_crossing:1;
360                 u64 reserved_3:1;
361                 u64 fc_hyst_bits:4;
362                 u64 reserved_8_63:56;
363         } s;
364 };
365
366 /*
367  * RVU_PFVF_BAR2 - cpt_lf_done_wait
368  *
369  * This register specifies the per-queue interrupt coalescing settings.
370  */
371 union otx2_cptx_lf_done_wait {
372         u64 u;
373         struct otx2_cptx_lf_done_wait_s {
374                 u64 num_wait:20;
375                 u64 reserved_20_31:12;
376                 u64 time_wait:16;
377                 u64 reserved_48_63:16;
378         } s;
379 };
380
381 /*
382  * RVU_PFVF_BAR2 - cpt_lf_done
383  *
384  * This register contain the per-queue instruction done count.
385  */
386 union otx2_cptx_lf_done {
387         u64 u;
388         struct otx2_cptx_lf_done_s {
389                 u64 done:20;
390                 u64 reserved_20_63:44;
391         } s;
392 };
393
394 /*
395  * RVU_PFVF_BAR2 - cpt_lf_inprog
396  *
397  * These registers contain the per-queue instruction in flight registers.
398  *
399  */
400 union otx2_cptx_lf_inprog {
401         u64 u;
402         struct otx2_cptx_lf_inprog_s {
403                 u64 inflight:9;
404                 u64 reserved_9_15:7;
405                 u64 eena:1;
406                 u64 grp_drp:1;
407                 u64 reserved_18_30:13;
408                 u64 grb_partial:1;
409                 u64 grb_cnt:8;
410                 u64 gwb_cnt:8;
411                 u64 reserved_48_63:16;
412         } s;
413 };
414
415 /*
416  * RVU_PFVF_BAR2 - cpt_lf_q_base
417  *
418  * CPT initializes these CSR fields to these values on any CPT_LF_Q_BASE write:
419  * _ CPT_LF_Q_INST_PTR[XQ_XOR]=0.
420  * _ CPT_LF_Q_INST_PTR[NQ_PTR]=2.
421  * _ CPT_LF_Q_INST_PTR[DQ_PTR]=2.
422  * _ CPT_LF_Q_GRP_PTR[XQ_XOR]=0.
423  * _ CPT_LF_Q_GRP_PTR[NQ_PTR]=1.
424  * _ CPT_LF_Q_GRP_PTR[DQ_PTR]=1.
425  */
426 union otx2_cptx_lf_q_base {
427         u64 u;
428         struct otx2_cptx_lf_q_base_s {
429                 u64 fault:1;
430                 u64 reserved_1_6:6;
431                 u64 addr:46;
432                 u64 reserved_53_63:11;
433         } s;
434 };
435
436 /*
437  * RVU_PFVF_BAR2 - cpt_lf_q_size
438  *
439  * CPT initializes these CSR fields to these values on any CPT_LF_Q_SIZE write:
440  * _ CPT_LF_Q_INST_PTR[XQ_XOR]=0.
441  * _ CPT_LF_Q_INST_PTR[NQ_PTR]=2.
442  * _ CPT_LF_Q_INST_PTR[DQ_PTR]=2.
443  * _ CPT_LF_Q_GRP_PTR[XQ_XOR]=0.
444  * _ CPT_LF_Q_GRP_PTR[NQ_PTR]=1.
445  * _ CPT_LF_Q_GRP_PTR[DQ_PTR]=1.
446  */
447 union otx2_cptx_lf_q_size {
448         u64 u;
449         struct otx2_cptx_lf_q_size_s {
450                 u64 size_div40:15;
451                 u64 reserved_15_63:49;
452         } s;
453 };
454
455 /*
456  * RVU_PF_BAR0 - cpt_af_lf_ctl
457  *
458  * This register configures queues. This register should be written only
459  * when the queue is execution-quiescent (see CPT_LF_INPROG[INFLIGHT]).
460  */
461 union otx2_cptx_af_lf_ctrl {
462         u64 u;
463         struct otx2_cptx_af_lf_ctrl_s {
464                 u64 pri:1;
465                 u64 reserved_1_8:8;
466                 u64 pf_func_inst:1;
467                 u64 cont_err:1;
468                 u64 reserved_11_15:5;
469                 u64 nixtx_en:1;
470                 u64 reserved_17_47:31;
471                 u64 grp:8;
472                 u64 reserved_56_63:8;
473         } s;
474 };
475
476 #endif /* __OTX2_CPT_HW_TYPES_H */