1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Cavium, Inc
5 #ifndef _OTX_CRYPTODEV_HW_ACCESS_H_
6 #define _OTX_CRYPTODEV_HW_ACCESS_H_
11 #include <rte_memory.h>
13 #include "cpt_common.h"
14 #include "cpt_hw_types.h"
16 #define CPT_INTR_POLL_INTERVAL_MS (50)
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)
24 #define CPT_CSR_REG_BASE(cpt) ((cpt)->reg_base)
26 /* Read hw register */
27 #define CPT_READ_CSR(__hw_addr, __offset) \
28 rte_read64_relaxed((uint8_t *)__hw_addr + __offset)
30 /* Write hw register */
31 #define CPT_WRITE_CSR(__hw_addr, __offset, __val) \
32 rte_write64_relaxed((__val), ((uint8_t *)__hw_addr + __offset))
40 struct command_chunk {
41 /** 128-byte aligned real_vaddr */
43 /** 128-byte aligned real_dma_addr */
48 * Command queue structure
50 struct command_queue {
51 /** Command queue host write idx */
53 /** Command queue chunk */
55 /** Command queue head; instructions are inserted here */
57 /** Command chunk list head */
58 struct command_chunk chead[DEFAULT_CMD_QCHUNKS];
62 * CPT VF device structure
66 struct cpt_instance instance;
67 /** Register start address */
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;
76 /** Below fields are accessed only in control path */
78 /** Env specific pdev representing the pci dev */
80 /** Calculated queue size */
82 /** Device index (0...CPT_MAX_VQ_NUM)*/
84 /** VF type of cpt_vf_type_t (SE_TYPE(2) or AE_TYPE(1) */
86 /** VF group (0 - 8) */
88 /** Operating node: Bits (46:44) in BAR0 address */
91 /** VF-PF mailbox communication */
95 /** Flag if not acked */
100 } __rte_cache_aligned;
103 * CPT Registers map for 81xx
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) + \
141 /* VF HAL functions */
144 otx_cpt_poll_misc(struct cpt_vf *cptvf);
147 otx_cpt_hw_init(struct cpt_vf *cptvf, void *pdev, void *reg_base, char *name);
150 otx_cpt_deinit_device(void *dev);
153 otx_cpt_get_resource(void *dev, uint8_t group, struct cpt_instance **instance);
156 otx_cpt_put_resource(struct cpt_instance *instance);
159 otx_cpt_start_device(void *cptvf);
162 otx_cpt_stop_device(void *cptvf);
164 /* Write to VQX_DOORBELL register
166 static __rte_always_inline void
167 otx_cpt_write_vq_doorbell(struct cpt_vf *cptvf, uint32_t val)
169 cptx_vqx_doorbell_t vqx_dbell;
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);
177 static __rte_always_inline uint32_t
178 otx_cpt_read_vq_doorbell(struct cpt_vf *cptvf)
180 cptx_vqx_doorbell_t vqx_dbell;
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;
187 #endif /* _OTX_CRYPTODEV_HW_ACCESS_H_ */