2698df6451d5ad7f7b5319eb715330c518f300ab
[dpdk.git] / drivers / crypto / octeontx / otx_cryptodev_hw_access.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Cavium, Inc
3  */
4
5 #ifndef _OTX_CRYPTODEV_HW_ACCESS_H_
6 #define _OTX_CRYPTODEV_HW_ACCESS_H_
7
8 #include <stdbool.h>
9
10 #include <rte_io.h>
11 #include <rte_memory.h>
12
13 #include "cpt_common.h"
14 #include "cpt_hw_types.h"
15
16 #define CPT_INTR_POLL_INTERVAL_MS       (50)
17
18 /* Default command queue length */
19 #define DEFAULT_CMD_QCHUNKS             2
20 #define DEFAULT_CMD_QCHUNK_SIZE         1023
21 #define DEFAULT_CMD_QLEN \
22                 (DEFAULT_CMD_QCHUNK_SIZE * DEFAULT_CMD_QCHUNKS)
23
24 #define CPT_CSR_REG_BASE(cpt)           ((cpt)->reg_base)
25
26 /* Read hw register */
27 #define CPT_READ_CSR(__hw_addr, __offset) \
28         rte_read64_relaxed((uint8_t *)__hw_addr + __offset)
29
30 /* Write hw register */
31 #define CPT_WRITE_CSR(__hw_addr, __offset, __val) \
32         rte_write64_relaxed((__val), ((uint8_t *)__hw_addr + __offset))
33
34 /* cpt instance */
35 struct cpt_instance {
36         uint32_t queue_id;
37         uintptr_t rsvd;
38 };
39
40 struct command_chunk {
41         /** 128-byte aligned real_vaddr */
42         uint8_t *head;
43         /** 128-byte aligned real_dma_addr */
44         phys_addr_t dma_addr;
45 };
46
47 /**
48  * Command queue structure
49  */
50 struct command_queue {
51         /** Command queue host write idx */
52         uint32_t idx;
53         /** Command queue chunk */
54         uint32_t cchunk;
55         /** Command queue head; instructions are inserted here */
56         uint8_t *qhead;
57         /** Command chunk list head */
58         struct command_chunk chead[DEFAULT_CMD_QCHUNKS];
59 };
60
61 /**
62  * CPT VF device structure
63  */
64 struct cpt_vf {
65         /** CPT instance */
66         struct cpt_instance instance;
67         /** Register start address */
68         uint8_t *reg_base;
69         /** Command queue information */
70         struct command_queue cqueue;
71         /** Pending queue information */
72         struct pending_queue pqueue;
73         /** Meta information per vf */
74         struct cptvf_meta_info meta_info;
75
76         /** Below fields are accessed only in control path */
77
78         /** Env specific pdev representing the pci dev */
79         void *pdev;
80         /** Calculated queue size */
81         uint32_t qsize;
82         /** Device index (0...CPT_MAX_VQ_NUM)*/
83         uint8_t  vfid;
84         /** VF type of cpt_vf_type_t (SE_TYPE(2) or AE_TYPE(1) */
85         uint8_t  vftype;
86         /** VF group (0 - 8) */
87         uint8_t  vfgrp;
88         /** Operating node: Bits (46:44) in BAR0 address */
89         uint8_t  node;
90
91         /** VF-PF mailbox communication */
92
93         /** Flag if acked */
94         bool pf_acked;
95         /** Flag if not acked */
96         bool pf_nacked;
97
98         /** Device name */
99         char dev_name[32];
100 } __rte_cache_aligned;
101
102 /*
103  * CPT Registers map for 81xx
104  */
105
106 /* VF registers */
107 #define CPTX_VQX_CTL(a, b)              (0x0000100ll + 0x1000000000ll * \
108                                          ((a) & 0x0) + 0x100000ll * (b))
109 #define CPTX_VQX_SADDR(a, b)            (0x0000200ll + 0x1000000000ll * \
110                                          ((a) & 0x0) + 0x100000ll * (b))
111 #define CPTX_VQX_DONE_WAIT(a, b)        (0x0000400ll + 0x1000000000ll * \
112                                          ((a) & 0x0) + 0x100000ll * (b))
113 #define CPTX_VQX_INPROG(a, b)           (0x0000410ll + 0x1000000000ll * \
114                                          ((a) & 0x0) + 0x100000ll * (b))
115 #define CPTX_VQX_DONE(a, b)             (0x0000420ll + 0x1000000000ll * \
116                                          ((a) & 0x1) + 0x100000ll * (b))
117 #define CPTX_VQX_DONE_ACK(a, b)         (0x0000440ll + 0x1000000000ll * \
118                                          ((a) & 0x1) + 0x100000ll * (b))
119 #define CPTX_VQX_DONE_INT_W1S(a, b)     (0x0000460ll + 0x1000000000ll * \
120                                          ((a) & 0x1) + 0x100000ll * (b))
121 #define CPTX_VQX_DONE_INT_W1C(a, b)     (0x0000468ll + 0x1000000000ll * \
122                                          ((a) & 0x1) + 0x100000ll * (b))
123 #define CPTX_VQX_DONE_ENA_W1S(a, b)     (0x0000470ll + 0x1000000000ll * \
124                                          ((a) & 0x1) + 0x100000ll * (b))
125 #define CPTX_VQX_DONE_ENA_W1C(a, b)     (0x0000478ll + 0x1000000000ll * \
126                                          ((a) & 0x1) + 0x100000ll * (b))
127 #define CPTX_VQX_MISC_INT(a, b)         (0x0000500ll + 0x1000000000ll * \
128                                          ((a) & 0x1) + 0x100000ll * (b))
129 #define CPTX_VQX_MISC_INT_W1S(a, b)     (0x0000508ll + 0x1000000000ll * \
130                                          ((a) & 0x1) + 0x100000ll * (b))
131 #define CPTX_VQX_MISC_ENA_W1S(a, b)     (0x0000510ll + 0x1000000000ll * \
132                                          ((a) & 0x1) + 0x100000ll * (b))
133 #define CPTX_VQX_MISC_ENA_W1C(a, b)     (0x0000518ll + 0x1000000000ll * \
134                                          ((a) & 0x1) + 0x100000ll * (b))
135 #define CPTX_VQX_DOORBELL(a, b)         (0x0000600ll + 0x1000000000ll * \
136                                          ((a) & 0x1) + 0x100000ll * (b))
137 #define CPTX_VFX_PF_MBOXX(a, b, c)      (0x0001000ll + 0x1000000000ll * \
138                                          ((a) & 0x1) + 0x100000ll * (b) + \
139                                          8ll * ((c) & 0x1))
140
141 /* VF HAL functions */
142
143 void
144 otx_cpt_poll_misc(struct cpt_vf *cptvf);
145
146 int
147 otx_cpt_hw_init(struct cpt_vf *cptvf, void *pdev, void *reg_base, char *name);
148
149 int
150 otx_cpt_deinit_device(void *dev);
151
152 int
153 otx_cpt_get_resource(void *dev, uint8_t group, struct cpt_instance **instance);
154
155 int
156 otx_cpt_put_resource(struct cpt_instance *instance);
157
158 int
159 otx_cpt_start_device(void *cptvf);
160
161 void
162 otx_cpt_stop_device(void *cptvf);
163
164 /* Write to VQX_DOORBELL register
165  */
166 static __rte_always_inline void
167 otx_cpt_write_vq_doorbell(struct cpt_vf *cptvf, uint32_t val)
168 {
169         cptx_vqx_doorbell_t vqx_dbell;
170
171         vqx_dbell.u = 0;
172         vqx_dbell.s.dbell_cnt = val * 8; /* Num of Instructions * 8 words */
173         CPT_WRITE_CSR(CPT_CSR_REG_BASE(cptvf),
174                       CPTX_VQX_DOORBELL(0, 0), vqx_dbell.u);
175 }
176
177 static __rte_always_inline uint32_t
178 otx_cpt_read_vq_doorbell(struct cpt_vf *cptvf)
179 {
180         cptx_vqx_doorbell_t vqx_dbell;
181
182         vqx_dbell.u = CPT_READ_CSR(CPT_CSR_REG_BASE(cptvf),
183                                    CPTX_VQX_DOORBELL(0, 0));
184         return vqx_dbell.s.dbell_cnt;
185 }
186
187 #endif /* _OTX_CRYPTODEV_HW_ACCESS_H_ */