1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Cavium, Inc
5 #ifndef _CPT_HW_TYPES_H_
6 #define _CPT_HW_TYPES_H_
8 #include <rte_byteorder.h>
11 * This file defines HRM specific structs.
15 #define CPT_VF_INTR_MBOX_MASK (1<<0)
16 #define CPT_VF_INTR_DOVF_MASK (1<<1)
17 #define CPT_VF_INTR_IRDE_MASK (1<<2)
18 #define CPT_VF_INTR_NWRP_MASK (1<<3)
19 #define CPT_VF_INTR_SWERR_MASK (1<<4)
20 #define CPT_VF_INTR_HWERR_MASK (1<<5)
21 #define CPT_VF_INTR_FAULT_MASK (1<<6)
23 #define CPT_INST_SIZE (64)
24 #define CPT_NEXT_CHUNK_PTR_SIZE (8)
27 * CPT_INST_S software command definitions
33 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
50 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
60 typedef struct cpt_vq_command {
68 * Structure cpt_inst_s
70 * CPT Instruction Structure
71 * This structure specifies the instruction layout.
72 * Instructions are stored in memory as little-endian unless
73 * CPT()_PF_Q()_CTL[INST_BE] is set.
75 typedef union cpt_inst_s {
77 struct cpt_inst_s_8s {
78 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 0 - Big Endian */
79 uint64_t reserved_17_63 : 47;
80 /* [ 16: 16] Done interrupt.
81 * 0 = No interrupts related to this instruction.
82 * 1 = When the instruction completes,CPT()_VQ()_DONE[DONE]
83 * will be incremented, and based on the rules described
84 * there an interrupt may occur.
87 uint64_t reserved_0_15 : 16;
88 #else /* Word 0 - Little Endian */
89 uint64_t reserved_0_15 : 16;
91 uint64_t reserved_17_63 : 47;
92 #endif /* Word 0 - End */
93 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 1 - Big Endian */
94 /* [127: 64] Result IOVA.
95 * If nonzero, specifies where to write CPT_RES_S.
96 * If zero, no result structure will be written.
97 * Address must be 16-byte aligned.
99 * Bits <63:49> are ignored by hardware; software should
100 * use a sign-extended bit <48> for forward compatibility.
102 uint64_t res_addr : 64;
103 #else /* Word 1 - Little Endian */
104 uint64_t res_addr : 64;
105 #endif /* Word 1 - End */
106 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 2 - Big Endian */
107 uint64_t reserved_172_191 : 20;
108 /* [171:162] If [WQ_PTR] is nonzero, the SSO guest-group to
109 * use when CPT submits work to SSO.
110 * For the SSO to not discard the add-work request, FPA_PF_MAP()
111 * must map [GRP] and CPT()_PF_Q()_GMCTL[GMID] as valid.
114 /* [161:160] If [WQ_PTR] is nonzero, the SSO tag type to use
115 * when CPT submits work to SSO.
118 /* [159:128] If [WQ_PTR] is nonzero, the SSO tag to use when
119 * CPT submits work to SSO.
122 #else /* Word 2 - Little Endian */
126 uint64_t reserved_172_191 : 20;
127 #endif /* Word 2 - End */
128 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 3 - Big Endian */
129 /** [255:192] If [WQ_PTR] is nonzero, it is a pointer to a
130 * work-queue entry that CPT submits work to SSO after all
131 * context, output data, and result write operations are
132 * visible to other CNXXXX units and the cores.
133 * Bits <2:0> must be zero.
134 * Bits <63:49> are ignored by hardware; software should use a
135 * sign-extended bit <48> for forward compatibility.
136 * Internal:Bits <63:49>, <2:0> are ignored by hardware,
137 * treated as always 0x0.
139 uint64_t wq_ptr : 64;
140 #else /* Word 3 - Little Endian */
141 uint64_t wq_ptr : 64;
142 #endif /* Word 3 - End */
143 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 4 - Big Endian */
145 /** [319:256] Engine instruction word 0. Passed to the
149 vq_cmd_word0_t vq_cmd_w0;
151 #else /* Word 4 - Little Endian */
154 vq_cmd_word0_t vq_cmd_w0;
156 #endif /* Word 4 - End */
157 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 5 - Big Endian */
159 /** [383:320] Engine instruction word 1. Passed to the
165 #else /* Word 5 - Little Endian */
170 #endif /* Word 5 - End */
171 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 6 - Big Endian */
173 /** [447:384] Engine instruction word 2. Passed to the
179 #else /* Word 6 - Little Endian */
184 #endif /* Word 6 - End */
185 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 7 - Big Endian */
187 /** [511:448] Engine instruction word 3. Passed to the
191 vq_cmd_word3_t vq_cmd_w3;
193 #else /* Word 7 - Little Endian */
196 vq_cmd_word3_t vq_cmd_w3;
198 #endif /* Word 7 - End */
203 * Structure cpt_res_s
205 * CPT Result Structure
206 * The CPT coprocessor writes the result structure after it completes a
207 * CPT_INST_S instruction. The result structure is exactly 16 bytes, and each
208 * instruction completion produces exactly one result structure.
210 * This structure is stored in memory as little-endian unless
211 * CPT()_PF_Q()_CTL[INST_BE] is set.
213 typedef union cpt_res_s {
215 struct cpt_res_s_8s {
216 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 0 - Big Endian */
217 uint64_t reserved_17_63 : 47;
218 /** [ 16: 16] Done interrupt. This bit is copied from the
219 * corresponding instruction's CPT_INST_S[DONEINT].
221 uint64_t doneint : 1;
222 uint64_t reserved_8_15 : 8;
223 /** [ 7: 0] Indicates completion/error status of the CPT
224 * coprocessor for the associated instruction, as enumerated by
225 * CPT_COMP_E. Core software may write the memory location
226 * containing [COMPCODE] to 0x0 before ringing the doorbell, and
227 * then poll for completion by checking for a nonzero value.
229 * Once the core observes a nonzero [COMPCODE] value in this
230 * case, the CPT coprocessor will have also completed L2/DRAM
233 uint64_t compcode : 8;
234 #else /* Word 0 - Little Endian */
235 uint64_t compcode : 8;
236 uint64_t reserved_8_15 : 8;
237 uint64_t doneint : 1;
238 uint64_t reserved_17_63 : 47;
239 #endif /* Word 0 - End */
240 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 1 - Big Endian */
241 uint64_t reserved_64_127 : 64;
242 #else /* Word 1 - Little Endian */
243 uint64_t reserved_64_127 : 64;
244 #endif /* Word 1 - End */
249 * Register (NCB) cpt#_vq#_ctl
251 * CPT VF Queue Control Registers
252 * This register configures queues. This register should be changed (other than
253 * clearing [ENA]) only when quiescent (see CPT()_VQ()_INPROG[INFLIGHT]).
257 struct cptx_vqx_ctl_s {
258 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 0 - Big Endian */
259 uint64_t reserved_1_63 : 63;
260 /** [ 0: 0](R/W/H) Enables the logical instruction queue.
261 * See also CPT()_PF_Q()_CTL[CONT_ERR] and
262 * CPT()_VQ()_INPROG[INFLIGHT].
263 * 1 = Queue is enabled.
264 * 0 = Queue is disabled.
267 #else /* Word 0 - Little Endian */
269 uint64_t reserved_1_63 : 63;
270 #endif /* Word 0 - End */
275 * Register (NCB) cpt#_vq#_done
277 * CPT Queue Done Count Registers
278 * These registers contain the per-queue instruction done count.
282 struct cptx_vqx_done_s {
283 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 0 - Big Endian */
284 uint64_t reserved_20_63 : 44;
285 /** [ 19: 0](R/W/H) Done count. When CPT_INST_S[DONEINT] set
286 * and that instruction completes,CPT()_VQ()_DONE[DONE] is
287 * incremented when the instruction finishes. Write to this
288 * field are for diagnostic use only; instead software writes
289 * CPT()_VQ()_DONE_ACK with the number of decrements for this
292 * Interrupts are sent as follows:
294 * When CPT()_VQ()_DONE[DONE] = 0, then no results are pending,
295 * the interrupt coalescing timer is held to zero, and an
296 * interrupt is not sent.
298 * When CPT()_VQ()_DONE[DONE] != 0, then the interrupt
299 * coalescing timer counts. If the counter is >= CPT()_VQ()_DONE
300 * _WAIT[TIME_WAIT]*1024, or CPT()_VQ()_DONE[DONE] >= CPT()_VQ()
301 * _DONE_WAIT[NUM_WAIT], i.e. enough time has passed or enough
302 * results have arrived, then the interrupt is sent. Otherwise,
303 * it is not sent due to coalescing.
305 * When CPT()_VQ()_DONE_ACK is written (or CPT()_VQ()_DONE is
306 * written but this is not typical), the interrupt coalescing
307 * timer restarts. Note after decrementing this interrupt
308 * equation is recomputed, for example if CPT()_VQ()_DONE[DONE]
309 * >= CPT()_VQ()_DONE_WAIT[NUM_WAIT] and because the timer is
310 * zero, the interrupt will be resent immediately. (This covers
311 * the race case between software acknowledging an interrupt and
312 * a result returning.)
314 * When CPT()_VQ()_DONE_ENA_W1S[DONE] = 0, interrupts are not
315 * sent, but the counting described above still occurs.
317 * Since CPT instructions complete out-of-order, if software is
318 * using completion interrupts the suggested scheme is to
319 * request a DONEINT on each request, and when an interrupt
320 * arrives perform a "greedy" scan for completions; even if a
321 * later command is acknowledged first this will not result in
322 * missing a completion.
324 * Software is responsible for making sure [DONE] does not
325 * overflow; for example by insuring there are not more than
326 * 2^20-1 instructions in flight that may request interrupts.
329 #else /* Word 0 - Little Endian */
331 uint64_t reserved_20_63 : 44;
332 #endif /* Word 0 - End */
337 * Register (NCB) cpt#_vq#_done_ack
339 * CPT Queue Done Count Ack Registers
340 * This register is written by software to acknowledge interrupts.
344 struct cptx_vqx_done_ack_s {
345 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 0 - Big Endian */
346 uint64_t reserved_20_63 : 44;
347 /** [ 19: 0](R/W/H) Number of decrements to CPT()_VQ()_DONE
348 * [DONE]. Reads CPT()_VQ()_DONE[DONE].
350 * Written by software to acknowledge interrupts. If CPT()_VQ()_
351 * DONE[DONE] is still nonzero the interrupt will be re-sent if
352 * the conditions described in CPT()_VQ()_DONE[DONE] are
355 uint64_t done_ack : 20;
356 #else /* Word 0 - Little Endian */
357 uint64_t done_ack : 20;
358 uint64_t reserved_20_63 : 44;
359 #endif /* Word 0 - End */
361 } cptx_vqx_done_ack_t;
364 * Register (NCB) cpt#_vq#_done_wait
366 * CPT Queue Done Interrupt Coalescing Wait Registers
367 * Specifies the per queue interrupt coalescing settings.
371 struct cptx_vqx_done_wait_s {
372 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 0 - Big Endian */
373 uint64_t reserved_48_63 : 16;
374 /** [ 47: 32](R/W) Time hold-off. When CPT()_VQ()_DONE[DONE] =
375 * 0, or CPT()_VQ()_DONE_ACK is written a timer is cleared. When
376 * the timer reaches [TIME_WAIT]*1024 then interrupt coalescing
377 * ends; see CPT()_VQ()_DONE[DONE]. If 0x0, time coalescing is
380 uint64_t time_wait : 16;
381 uint64_t reserved_20_31 : 12;
382 /** [ 19: 0](R/W) Number of messages hold-off. When
383 * CPT()_VQ()_DONE[DONE] >= [NUM_WAIT] then interrupt coalescing
384 * ends; see CPT()_VQ()_DONE[DONE]. If 0x0, same behavior as
387 uint64_t num_wait : 20;
388 #else /* Word 0 - Little Endian */
389 uint64_t num_wait : 20;
390 uint64_t reserved_20_31 : 12;
391 uint64_t time_wait : 16;
392 uint64_t reserved_48_63 : 16;
393 #endif /* Word 0 - End */
395 } cptx_vqx_done_wait_t;
398 * Register (NCB) cpt#_vq#_doorbell
400 * CPT Queue Doorbell Registers
401 * Doorbells for the CPT instruction queues.
405 struct cptx_vqx_doorbell_s {
406 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 0 - Big Endian */
407 uint64_t reserved_20_63 : 44;
408 uint64_t dbell_cnt : 20;
409 /** [ 19: 0](R/W/H) Number of instruction queue 64-bit words
410 * to add to the CPT instruction doorbell count. Readback value
411 * is the the current number of pending doorbell requests.
413 * If counter overflows CPT()_VQ()_MISC_INT[DBELL_DOVF] is set.
415 * To reset the count back to zero, write one to clear
416 * CPT()_VQ()_MISC_INT_ENA_W1C[DBELL_DOVF], then write a value
417 * of 2^20 minus the read [DBELL_CNT], then write one to
418 * CPT()_VQ()_MISC_INT_W1C[DBELL_DOVF] and
419 * CPT()_VQ()_MISC_INT_ENA_W1S[DBELL_DOVF].
421 * Must be a multiple of 8. All CPT instructions are 8 words
422 * and require a doorbell count of multiple of 8.
424 #else /* Word 0 - Little Endian */
425 uint64_t dbell_cnt : 20;
426 uint64_t reserved_20_63 : 44;
427 #endif /* Word 0 - End */
429 } cptx_vqx_doorbell_t;
432 * Register (NCB) cpt#_vq#_inprog
434 * CPT Queue In Progress Count Registers
435 * These registers contain the per-queue instruction in flight registers.
439 struct cptx_vqx_inprog_s {
440 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 0 - Big Endian */
441 uint64_t reserved_8_63 : 56;
442 /** [ 7: 0](RO/H) Inflight count. Counts the number of
443 * instructions for the VF for which CPT is fetching, executing
444 * or responding to instructions. However this does not include
445 * any interrupts that are awaiting software handling
446 * (CPT()_VQ()_DONE[DONE] != 0x0).
448 * A queue may not be reconfigured until:
449 * 1. CPT()_VQ()_CTL[ENA] is cleared by software.
450 * 2. [INFLIGHT] is polled until equals to zero.
452 uint64_t inflight : 8;
453 #else /* Word 0 - Little Endian */
454 uint64_t inflight : 8;
455 uint64_t reserved_8_63 : 56;
456 #endif /* Word 0 - End */
461 * Register (NCB) cpt#_vq#_misc_int
463 * CPT Queue Misc Interrupt Register
464 * These registers contain the per-queue miscellaneous interrupts.
468 struct cptx_vqx_misc_int_s {
469 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 0 - Big Endian */
470 uint64_t reserved_7_63 : 57;
471 /** [ 6: 6](R/W1C/H) Translation fault detected. */
473 /** [ 5: 5](R/W1C/H) Hardware error from engines. */
475 /** [ 4: 4](R/W1C/H) Software error from engines. */
477 /** [ 3: 3](R/W1C/H) NCB result write response error. */
479 /** [ 2: 2](R/W1C/H) Instruction NCB read response error. */
481 /** [ 1: 1](R/W1C/H) Doorbell overflow. */
483 /** [ 0: 0](R/W1C/H) PF to VF mailbox interrupt. Set when
484 * CPT()_VF()_PF_MBOX(0) is written.
487 #else /* Word 0 - Little Endian */
495 uint64_t reserved_5_63 : 59;
496 #endif /* Word 0 - End */
498 } cptx_vqx_misc_int_t;
501 * Register (NCB) cpt#_vq#_saddr
503 * CPT Queue Starting Buffer Address Registers
504 * These registers set the instruction buffer starting address.
508 struct cptx_vqx_saddr_s {
509 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 0 - Big Endian */
510 uint64_t reserved_49_63 : 15;
511 /** [ 48: 6](R/W/H) Instruction buffer IOVA <48:6>
512 * (64-byte aligned). When written, it is the initial buffer
513 * starting address; when read, it is the next read pointer to
514 * be requested from L2C. The PTR field is overwritten with the
515 * next pointer each time that the command buffer segment is
516 * exhausted. New commands will then be read from the newly
517 * specified command buffer pointer.
520 uint64_t reserved_0_5 : 6;
521 #else /* Word 0 - Little Endian */
522 uint64_t reserved_0_5 : 6;
524 uint64_t reserved_49_63 : 15;
525 #endif /* Word 0 - End */
529 #endif /*_CPT_HW_TYPES_H_ */