1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Cavium, Inc
5 #ifndef _RTE_OCTEONTX_ZIP_VF_H_
6 #define _RTE_OCTEONTX_ZIP_VF_H_
10 #include <rte_bus_pci.h>
12 #include <rte_compressdev.h>
13 #include <rte_compressdev_pmd.h>
14 #include <rte_malloc.h>
15 #include <rte_memory.h>
16 #include <rte_spinlock.h>
20 extern int octtx_zip_logtype_driver;
22 /* ZIP VF Control/Status registers (CSRs): */
24 #define ZIP_VQ_ENA (0x10)
25 #define ZIP_VQ_SBUF_ADDR (0x20)
26 #define ZIP_VF_PF_MBOXX(x) (0x400 | (x)<<3)
27 #define ZIP_VQ_DOORBELL (0x1000)
30 #define PCI_VENDOR_ID_CAVIUM 0x177D
31 /**< PCI device id of ZIP VF */
32 #define PCI_DEVICE_ID_OCTEONTX_ZIPVF 0xA037
33 #define PCI_DEVICE_ID_OCTEONTX2_ZIPVF 0xA083
35 /* maximum number of zip vf devices */
38 /* max size of one chunk */
39 #define ZIP_MAX_CHUNK_SIZE 8192
41 /* each instruction is fixed 128 bytes */
42 #define ZIP_CMD_SIZE 128
44 #define ZIP_CMD_SIZE_WORDS (ZIP_CMD_SIZE >> 3) /* 16 64_bit words */
46 /* size of next chunk buffer pointer */
47 #define ZIP_MAX_NCBP_SIZE 8
49 /* size of instruction queue in units of instruction size */
50 #define ZIP_MAX_NUM_CMDS ((ZIP_MAX_CHUNK_SIZE - ZIP_MAX_NCBP_SIZE) / \
51 ZIP_CMD_SIZE) /* 63 */
53 /* size of instruct queue in bytes */
54 #define ZIP_MAX_CMDQ_SIZE ((ZIP_MAX_NUM_CMDS * ZIP_CMD_SIZE) + \
55 ZIP_MAX_NCBP_SIZE)/* ~8072ull */
57 #define ZIP_BUF_SIZE 256
59 #define ZIP_SGPTR_ALIGN 16
60 #define ZIP_CMDQ_ALIGN 128
61 #define MAX_SG_LEN ((ZIP_BUF_SIZE - ZIP_SGPTR_ALIGN) / sizeof(void *))
63 /**< ZIP PMD specified queue pairs */
64 #define ZIP_MAX_VF_QUEUE 1
66 #define ZIP_ALIGN_ROUNDUP(x, _align) \
67 ((_align) * (((x) + (_align) - 1) / (_align)))
69 /**< ZIP PMD device name */
70 #define COMPRESSDEV_NAME_ZIP_PMD compress_octeonx
72 #define ZIP_PMD_LOG(level, fmt, args...) \
73 rte_log(RTE_LOG_ ## level, \
74 octtx_zip_logtype_driver, "%s(): "fmt "\n", \
77 #define ZIP_PMD_INFO(fmt, args...) \
78 ZIP_PMD_LOG(INFO, fmt, ## args)
79 #define ZIP_PMD_ERR(fmt, args...) \
80 ZIP_PMD_LOG(ERR, fmt, ## args)
82 /* resources required to process stream */
83 enum NUM_BUFS_PER_STREAM {
97 /* Algorithm handler function prototype */
98 typedef int (*comp_func_t)(struct rte_comp_op *op,
99 struct zipvf_qp *qp, struct zip_stream *zstrm);
102 * ZIP private stream structure
105 union zip_inst_s *inst;
106 /* zip instruction pointer */
108 /* function to process comp operation */
109 void *bufs[MAX_BUFS_PER_STREAM];
110 } __rte_cache_aligned;
114 * ZIP instruction Queue
117 rte_spinlock_t qlock;
120 /* pointer to start of 8-byte word length queue-head */
122 /* pointer to instruction queue virtual address */
124 /* iova addr of cmdq head*/
128 * ZIP device queue structure
131 struct zipvf_cmdq cmdq;
132 /* Hardware instruction queue structure */
133 struct rte_ring *processed_pkts;
134 /* Ring for placing processed packets */
135 struct rte_compressdev_stats qp_stats;
136 /* Queue pair statistics */
138 /* Queue Pair Identifier */
140 /* Unique Queue Pair Name */
142 /* pointer to device, queue belongs to */
143 } __rte_cache_aligned;
146 * ZIP VF device structure.
151 struct rte_pci_device *pdev;
154 /* CSR base address for underlying BAR0 VF.*/
156 /* Storing mbox domain and subdomain id for app rerun*/
157 uint32_t max_nb_queue_pairs;
158 /* pointer to device qps */
159 struct rte_mempool *zip_mp;
160 /* pointer to pools */
161 } __rte_cache_aligned;
165 zipvf_prepare_in_buf(struct zip_stream *zstrm, struct rte_comp_op *op)
167 uint32_t offset, inlen;
168 struct rte_mbuf *m_src;
169 union zip_inst_s *inst = zstrm->inst;
171 inlen = op->src.length;
172 offset = op->src.offset;
175 /* Prepare direct input data pointer */
177 inst->s.inp_ptr_addr.s.addr =
178 rte_pktmbuf_iova_offset(m_src, offset);
179 inst->s.inp_ptr_ctl.s.length = inlen;
183 zipvf_prepare_out_buf(struct zip_stream *zstrm, struct rte_comp_op *op)
186 struct rte_mbuf *m_dst;
187 union zip_inst_s *inst = zstrm->inst;
189 offset = op->dst.offset;
192 /* Prepare direct input data pointer */
194 inst->s.out_ptr_addr.s.addr =
195 rte_pktmbuf_iova_offset(m_dst, offset);
196 inst->s.totaloutputlength = rte_pktmbuf_pkt_len(m_dst) -
198 inst->s.out_ptr_ctl.s.length = inst->s.totaloutputlength;
202 zipvf_prepare_cmd_stateless(struct rte_comp_op *op, struct zip_stream *zstrm)
204 union zip_inst_s *inst = zstrm->inst;
206 /* set flush flag to always 1*/
209 if (inst->s.op == ZIP_OP_E_DECOMP)
214 /* Set input checksum */
215 inst->s.adlercrc32 = op->input_chksum;
217 /* Prepare gather buffers */
218 zipvf_prepare_in_buf(zstrm, op);
219 zipvf_prepare_out_buf(zstrm, op);
224 zip_dump_instruction(void *inst)
226 union zip_inst_s *cmd83 = (union zip_inst_s *)inst;
227 printf("####### START ########\n");
228 printf("doneint:%d totaloutputlength:%d\n", cmd83->s.doneint,
229 cmd83->s.totaloutputlength);
230 printf("exnum:%d iv:%d exbits:%d hmif:%d halg:%d\n", cmd83->s.exn,
231 cmd83->s.iv, cmd83->s.exbits, cmd83->s.hmif, cmd83->s.halg);
232 printf("flush:%d speed:%d cc:%d\n", cmd83->s.sf,
233 cmd83->s.ss, cmd83->s.cc);
234 printf("eof:%d bof:%d op:%d dscatter:%d dgather:%d hgather:%d\n",
235 cmd83->s.ef, cmd83->s.bf, cmd83->s.op, cmd83->s.ds,
236 cmd83->s.dg, cmd83->s.hg);
237 printf("historylength:%d adler32:%d\n", cmd83->s.historylength,
238 cmd83->s.adlercrc32);
239 printf("ctx_ptr.addr:0x%"PRIx64"\n", cmd83->s.ctx_ptr_addr.s.addr);
240 printf("ctx_ptr.len:%d\n", cmd83->s.ctx_ptr_ctl.s.length);
241 printf("history_ptr.addr:0x%"PRIx64"\n", cmd83->s.his_ptr_addr.s.addr);
242 printf("history_ptr.len:%d\n", cmd83->s.his_ptr_ctl.s.length);
243 printf("inp_ptr.addr:0x%"PRIx64"\n", cmd83->s.inp_ptr_addr.s.addr);
244 printf("inp_ptr.len:%d\n", cmd83->s.inp_ptr_ctl.s.length);
245 printf("out_ptr.addr:0x%"PRIx64"\n", cmd83->s.out_ptr_addr.s.addr);
246 printf("out_ptr.len:%d\n", cmd83->s.out_ptr_ctl.s.length);
247 printf("result_ptr.len:%d\n", cmd83->s.res_ptr_ctl.s.length);
248 printf("####### END ########\n");
253 zipvf_create(struct rte_compressdev *compressdev);
256 zipvf_destroy(struct rte_compressdev *compressdev);
259 zipvf_q_init(struct zipvf_qp *qp);
262 zipvf_q_term(struct zipvf_qp *qp);
265 zipvf_push_command(struct zipvf_qp *qp, union zip_inst_s *zcmd);
268 zip_process_op(struct rte_comp_op *op,
270 struct zip_stream *zstrm);
273 zip_reg_read64(uint8_t *hw_addr, uint64_t offset);
276 zip_reg_write64(uint8_t *hw_addr, uint64_t offset, uint64_t val);
278 #endif /* _RTE_ZIP_VF_H_ */