1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2018 Cavium, Inc
*/
#ifndef _RTE_OCTEONTX_ZIP_VF_H_
#define _RTE_OCTEONTX_ZIP_VF_H_
#include <unistd.h>
#include <rte_bus_pci.h>
#include <rte_comp.h>
#include <rte_compressdev.h>
#include <rte_compressdev_pmd.h>
#include <rte_malloc.h>
#include <rte_memory.h>
#include <rte_spinlock.h>
#include <zip_regs.h>
int octtx_zip_logtype_driver;
/* ZIP VF Control/Status registers (CSRs): */
/* VF_BAR0: */
#define ZIP_VQ_ENA (0x10)
#define ZIP_VQ_SBUF_ADDR (0x20)
#define ZIP_VF_PF_MBOXX(x) (0x400 | (x)<<3)
#define ZIP_VQ_DOORBELL (0x1000)
/**< Vendor ID */
#define PCI_VENDOR_ID_CAVIUM 0x177D
/**< PCI device id of ZIP VF */
#define PCI_DEVICE_ID_OCTEONTX_ZIPVF 0xA037
/* maxmum number of zip vf devices */
#define ZIP_MAX_VFS 8
/* max size of one chunk */
#define ZIP_MAX_CHUNK_SIZE 8192
/* each instruction is fixed 128 bytes */
#define ZIP_CMD_SIZE 128
#define ZIP_CMD_SIZE_WORDS (ZIP_CMD_SIZE >> 3) /* 16 64_bit words */
/* size of next chunk buffer pointer */
#define ZIP_MAX_NCBP_SIZE 8
/* size of instruction queue in units of instruction size */
#define ZIP_MAX_NUM_CMDS ((ZIP_MAX_CHUNK_SIZE - ZIP_MAX_NCBP_SIZE) / \
ZIP_CMD_SIZE) /* 63 */
/* size of instruct queue in bytes */
#define ZIP_MAX_CMDQ_SIZE ((ZIP_MAX_NUM_CMDS * ZIP_CMD_SIZE) + \
ZIP_MAX_NCBP_SIZE)/* ~8072ull */
#define ZIP_BUF_SIZE 256
#define ZIP_SGPTR_ALIGN 16
#define ZIP_CMDQ_ALIGN 128
#define MAX_SG_LEN ((ZIP_BUF_SIZE - ZIP_SGPTR_ALIGN) / sizeof(void *))
/**< ZIP PMD specified queue pairs */
#define ZIP_MAX_VF_QUEUE 1
#define ZIP_ALIGN_ROUNDUP(x, _align) \
((_align) * (((x) + (_align) - 1) / (_align)))
/**< ZIP PMD device name */
#define COMPRESSDEV_NAME_ZIP_PMD compress_octeonx
#define ZIP_PMD_LOG(level, fmt, args...) \
rte_log(RTE_LOG_ ## level, \
octtx_zip_logtype_driver, "%s(): "fmt "\n", \
__func__, ##args)
#define ZIP_PMD_INFO(fmt, args...) \
ZIP_PMD_LOG(INFO, fmt, ## args)
#define ZIP_PMD_ERR(fmt, args...) \
ZIP_PMD_LOG(ERR, fmt, ## args)
/* resources required to process stream */
enum NUM_BUFS_PER_STREAM {
RES_BUF = 0,
CMD_BUF,
HASH_CTX_BUF,
DECOMP_CTX_BUF,
IN_DATA_BUF,
OUT_DATA_BUF,
HISTORY_DATA_BUF,
MAX_BUFS_PER_STREAM
};
struct zip_stream;
struct zipvf_qp;
/* Algorithm handler function prototype */
typedef int (*comp_func_t)(struct rte_comp_op *op,
struct zipvf_qp *qp, struct zip_stream *zstrm);
/**
* ZIP private stream structure
*/
struct zip_stream {
union zip_inst_s *inst;
/* zip instruction pointer */
comp_func_t func;
/* function to process comp operation */
void *bufs[MAX_BUFS_PER_STREAM];
} __rte_cache_aligned;
/**
* ZIP instruction Queue
*/
struct zipvf_cmdq {
rte_spinlock_t qlock;
/* queue lock */
uint64_t *sw_head;
/* pointer to start of 8-byte word length queue-head */
uint8_t *va;
/* pointer to instruction queue virtual address */
rte_iova_t iova;
/* iova addr of cmdq head*/
};
/**
* ZIP device queue structure
*/
struct zipvf_qp {
struct zipvf_cmdq cmdq;
/* Hardware instruction queue structure */
struct rte_ring *processed_pkts;
/* Ring for placing processed packets */
struct rte_compressdev_stats qp_stats;
/* Queue pair statistics */
uint16_t id;
/* Queue Pair Identifier */
const char *name;
/* Unique Queue Pair Name */
struct zip_vf *vf;
/* pointer to device, queue belongs to */
} __rte_cache_aligned;
/**
* ZIP VF device structure.
*/
struct zip_vf {
int vfid;
/* vf index */
struct rte_pci_device *pdev;
/* pci device */
void *vbar0;
/* CSR base address for underlying BAR0 VF.*/
uint64_t dom_sdom;
/* Storing mbox domain and subdomain id for app rerun*/
uint32_t max_nb_queue_pairs;
/* pointer to device qps */
struct rte_mempool *zip_mp;
/* pointer to pools */
} __rte_cache_aligned;
static inline void
zipvf_prepare_in_buf(struct zip_stream *zstrm, struct rte_comp_op *op)
{
uint32_t offset, inlen;
struct rte_mbuf *m_src;
union zip_inst_s *inst = zstrm->inst;
inlen = op->src.length;
offset = op->src.offset;
m_src = op->m_src;
/* Prepare direct input data pointer */
inst->s.dg = 0;
inst->s.inp_ptr_addr.s.addr =
rte_pktmbuf_iova_offset(m_src, offset);
inst->s.inp_ptr_ctl.s.length = inlen;
}
static inline void
zipvf_prepare_out_buf(struct zip_stream *zstrm, struct rte_comp_op *op)
{
uint32_t offset;
struct rte_mbuf *m_dst;
union zip_inst_s *inst = zstrm->inst;
offset = op->dst.offset;
m_dst = op->m_dst;
/* Prepare direct input data pointer */
inst->s.ds = 0;
inst->s.out_ptr_addr.s.addr =
rte_pktmbuf_iova_offset(m_dst, offset);
inst->s.totaloutputlength = rte_pktmbuf_pkt_len(m_dst) -
op->dst.offset;
inst->s.out_ptr_ctl.s.length = inst->s.totaloutputlength;
}
static inline void
zipvf_prepare_cmd_stateless(struct rte_comp_op *op, struct zip_stream *zstrm)
{
union zip_inst_s *inst = zstrm->inst;
/* set flush flag to always 1*/
inst->s.ef = 1;
if (inst->s.op == ZIP_OP_E_DECOMP)
inst->s.sf = 1;
else
inst->s.sf = 0;
/* Set input checksum */
inst->s.adlercrc32 = op->input_chksum;
/* Prepare gather buffers */
zipvf_prepare_in_buf(zstrm, op);
zipvf_prepare_out_buf(zstrm, op);
}
#ifdef ZIP_DBG
static inline void
zip_dump_instruction(void *inst)
{
union zip_inst_s *cmd83 = (union zip_inst_s *)inst;
printf("####### START ########\n");
printf("doneint:%d totaloutputlength:%d\n", cmd83->s.doneint,
cmd83->s.totaloutputlength);
printf("exnum:%d iv:%d exbits:%d hmif:%d halg:%d\n", cmd83->s.exn,
cmd83->s.iv, cmd83->s.exbits, cmd83->s.hmif, cmd83->s.halg);
printf("flush:%d speed:%d cc:%d\n", cmd83->s.sf,
cmd83->s.ss, cmd83->s.cc);
printf("eof:%d bof:%d op:%d dscatter:%d dgather:%d hgather:%d\n",
cmd83->s.ef, cmd83->s.bf, cmd83->s.op, cmd83->s.ds,
cmd83->s.dg, cmd83->s.hg);
printf("historylength:%d adler32:%d\n", cmd83->s.historylength,
cmd83->s.adlercrc32);
printf("ctx_ptr.addr:0x%"PRIx64"\n", cmd83->s.ctx_ptr_addr.s.addr);
printf("ctx_ptr.len:%d\n", cmd83->s.ctx_ptr_ctl.s.length);
printf("history_ptr.addr:0x%"PRIx64"\n", cmd83->s.his_ptr_addr.s.addr);
printf("history_ptr.len:%d\n", cmd83->s.his_ptr_ctl.s.length);
printf("inp_ptr.addr:0x%"PRIx64"\n", cmd83->s.inp_ptr_addr.s.addr);
printf("inp_ptr.len:%d\n", cmd83->s.inp_ptr_ctl.s.length);
printf("out_ptr.addr:0x%"PRIx64"\n", cmd83->s.out_ptr_addr.s.addr);
printf("out_ptr.len:%d\n", cmd83->s.out_ptr_ctl.s.length);
printf("result_ptr.len:%d\n", cmd83->s.res_ptr_ctl.s.length);
printf("####### END ########\n");
}
#endif
int
zipvf_create(struct rte_compressdev *compressdev);
int
zipvf_destroy(struct rte_compressdev *compressdev);
int
zipvf_q_init(struct zipvf_qp *qp);
int
zipvf_q_term(struct zipvf_qp *qp);
void
zipvf_push_command(struct zipvf_qp *qp, union zip_inst_s *zcmd);
int
zip_process_op(struct rte_comp_op *op,
struct zipvf_qp *qp,
struct zip_stream *zstrm);
uint64_t
zip_reg_read64(uint8_t *hw_addr, uint64_t offset);
void
zip_reg_write64(uint8_t *hw_addr, uint64_t offset, uint64_t val);
#endif /* _RTE_ZIP_VF_H_ */
|