common/cpt: remove redundant bit swaps
[dpdk.git] / drivers / common / cpt / cpt_hw_types.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Cavium, Inc
3  */
4
5 #ifndef _CPT_HW_TYPES_H_
6 #define _CPT_HW_TYPES_H_
7
8 #include <rte_byteorder.h>
9
10 /*
11  * This file defines HRM specific structs.
12  *
13  */
14
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)
22
23 #define CPT_INST_SIZE           (64)
24 #define CPT_NEXT_CHUNK_PTR_SIZE (8)
25
26 /*
27  * CPT_INST_S software command definitions
28  * Words EI (0-3)
29  */
30 typedef union {
31         uint64_t u64;
32         struct {
33 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
34                 uint16_t opcode;
35                 uint16_t param1;
36                 uint16_t param2;
37                 uint16_t dlen;
38 #else
39                 uint16_t dlen;
40                 uint16_t param2;
41                 uint16_t param1;
42                 uint16_t opcode;
43 #endif
44         } s;
45 } vq_cmd_word0_t;
46
47 typedef union {
48         uint64_t u64;
49         struct {
50 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
51                 uint64_t grp    : 3;
52                 uint64_t cptr   : 61;
53 #else
54                 uint64_t cptr   : 61;
55                 uint64_t grp    : 3;
56 #endif
57         } s;
58 } vq_cmd_word3_t;
59
60 typedef struct cpt_vq_command {
61         vq_cmd_word0_t cmd;
62         uint64_t dptr;
63         uint64_t rptr;
64         vq_cmd_word3_t cptr;
65 } cpt_vq_cmd_t;
66
67 /**
68  * Structure cpt_inst_s
69  *
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.
74  */
75 typedef union cpt_inst_s {
76         uint64_t u[8];
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.
85                  */
86                 uint64_t doneint               : 1;
87                 uint64_t reserved_0_15         : 16;
88 #else /* Word 0 - Little Endian */
89                 uint64_t reserved_0_15         : 16;
90                 uint64_t doneint               : 1;
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.
98                  *
99                  * Bits <63:49> are ignored by hardware; software should
100                  * use a sign-extended bit <48> for forward compatibility.
101                  */
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.
112                  */
113                 uint64_t grp                   : 10;
114                 /* [161:160] If [WQ_PTR] is nonzero, the SSO tag type to use
115                  * when CPT submits work to SSO.
116                  */
117                 uint64_t tt                    : 2;
118                 /* [159:128] If [WQ_PTR] is nonzero, the SSO tag to use when
119                  * CPT submits work to SSO.
120                  */
121                 uint64_t tag                   : 32;
122 #else /* Word 2 - Little Endian */
123                 uint64_t tag                   : 32;
124                 uint64_t tt                    : 2;
125                 uint64_t grp                   : 10;
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.
138                  **/
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 */
144                 union {
145                         /** [319:256] Engine instruction word 0. Passed to the
146                          * AE/SE.
147                          **/
148                         uint64_t ei0                   : 64;
149                         vq_cmd_word0_t vq_cmd_w0;
150                 };
151 #else /* Word 4 - Little Endian */
152                 union {
153                         uint64_t ei0                   : 64;
154                         vq_cmd_word0_t vq_cmd_w0;
155                 };
156 #endif /* Word 4 - End */
157 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 5 - Big Endian */
158                 union {
159                         /** [383:320] Engine instruction word 1. Passed to the
160                          * AE/SE.
161                          **/
162                         uint64_t ei1                   : 64;
163                         uint64_t dptr;
164                 };
165 #else /* Word 5 - Little Endian */
166                 union {
167                         uint64_t ei1                   : 64;
168                         uint64_t dptr;
169                 };
170 #endif /* Word 5 - End */
171 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 6 - Big Endian */
172                 union {
173                         /** [447:384] Engine instruction word 2. Passed to the
174                          * AE/SE.
175                          **/
176                         uint64_t ei2                   : 64;
177                         uint64_t rptr;
178                 };
179 #else /* Word 6 - Little Endian */
180                 union {
181                         uint64_t ei2                   : 64;
182                         uint64_t rptr;
183                 };
184 #endif /* Word 6 - End */
185 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) /* Word 7 - Big Endian */
186                 union {
187                         /** [511:448] Engine instruction word 3. Passed to the
188                          * AE/SE.
189                          **/
190                         uint64_t ei3                   : 64;
191                         vq_cmd_word3_t vq_cmd_w3;
192                 };
193 #else /* Word 7 - Little Endian */
194                 union {
195                         uint64_t ei3                   : 64;
196                         vq_cmd_word3_t vq_cmd_w3;
197                 };
198 #endif /* Word 7 - End */
199         } s8x;
200 } cpt_inst_s_t;
201
202 /**
203  * Structure cpt_res_s
204  *
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.
209  *
210  * This structure is stored in memory as little-endian unless
211  * CPT()_PF_Q()_CTL[INST_BE] is set.
212  */
213 typedef union cpt_res_s {
214         uint64_t u[2];
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].
220                  **/
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.
228                  *
229                  * Once the core observes a nonzero [COMPCODE] value in this
230                  * case, the CPT coprocessor will have also completed L2/DRAM
231                  * write operations.
232                  **/
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 */
245         } s8x;
246 } cpt_res_s_t;
247
248 /**
249  * Register (NCB) cpt#_vq#_ctl
250  *
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]).
254  */
255 typedef union {
256         uint64_t u;
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.
265                  **/
266                 uint64_t ena                   : 1;
267 #else /* Word 0 - Little Endian */
268                 uint64_t ena                   : 1;
269                 uint64_t reserved_1_63         : 63;
270 #endif /* Word 0 - End */
271         } s;
272 } cptx_vqx_ctl_t;
273
274 /**
275  * Register (NCB) cpt#_vq#_done
276  *
277  * CPT Queue Done Count Registers
278  * These registers contain the per-queue instruction done count.
279  */
280 typedef union {
281         uint64_t u;
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
290                  * field.
291                  *
292                  * Interrupts are sent as follows:
293                  *
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.
297                  *
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.
304                  *
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.)
313                  *
314                  * When CPT()_VQ()_DONE_ENA_W1S[DONE] = 0, interrupts are not
315                  * sent, but the counting described above still occurs.
316                  *
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.
323                  *
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.
327                  **/
328                 uint64_t done                  : 20;
329 #else /* Word 0 - Little Endian */
330                 uint64_t done                  : 20;
331                 uint64_t reserved_20_63        : 44;
332 #endif /* Word 0 - End */
333         } s;
334 } cptx_vqx_done_t;
335
336 /**
337  * Register (NCB) cpt#_vq#_done_ack
338  *
339  * CPT Queue Done Count Ack Registers
340  * This register is written by software to acknowledge interrupts.
341  */
342 typedef union {
343         uint64_t u;
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].
349                  *
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
353                  * satisfied.
354                  **/
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 */
360         } s;
361 } cptx_vqx_done_ack_t;
362
363 /**
364  * Register (NCB) cpt#_vq#_done_wait
365  *
366  * CPT Queue Done Interrupt Coalescing Wait Registers
367  * Specifies the per queue interrupt coalescing settings.
368  */
369 typedef union {
370         uint64_t u;
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
378                  * disabled.
379                  **/
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
385                  * 0x1.
386                  **/
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 */
394         } s;
395 } cptx_vqx_done_wait_t;
396
397 /**
398  * Register (NCB) cpt#_vq#_doorbell
399  *
400  * CPT Queue Doorbell Registers
401  * Doorbells for the CPT instruction queues.
402  */
403 typedef union {
404         uint64_t u;
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.
412                  *
413                  * If counter overflows CPT()_VQ()_MISC_INT[DBELL_DOVF] is set.
414                  *
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].
420                  *
421                  * Must be a multiple of 8.  All CPT instructions are 8 words
422                  * and require a doorbell count of multiple of 8.
423                  **/
424 #else /* Word 0 - Little Endian */
425                 uint64_t dbell_cnt             : 20;
426                 uint64_t reserved_20_63        : 44;
427 #endif /* Word 0 - End */
428         } s;
429 } cptx_vqx_doorbell_t;
430
431 /**
432  * Register (NCB) cpt#_vq#_inprog
433  *
434  * CPT Queue In Progress Count Registers
435  * These registers contain the per-queue instruction in flight registers.
436  */
437 typedef union {
438         uint64_t u;
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).
447                  *
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.
451                  **/
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 */
457         } s;
458 } cptx_vqx_inprog_t;
459
460 /**
461  * Register (NCB) cpt#_vq#_misc_int
462  *
463  * CPT Queue Misc Interrupt Register
464  * These registers contain the per-queue miscellaneous interrupts.
465  */
466 typedef union {
467         uint64_t u;
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. */
472                 uint64_t fault                 : 1;
473                 /** [  5:  5](R/W1C/H) Hardware error from engines. */
474                 uint64_t hwerr                 : 1;
475                 /** [  4:  4](R/W1C/H) Software error from engines. */
476                 uint64_t swerr                 : 1;
477                 /** [  3:  3](R/W1C/H) NCB result write response error. */
478                 uint64_t nwrp                  : 1;
479                 /** [  2:  2](R/W1C/H) Instruction NCB read response error. */
480                 uint64_t irde                  : 1;
481                 /** [  1:  1](R/W1C/H) Doorbell overflow. */
482                 uint64_t dovf                  : 1;
483                 /** [  0:  0](R/W1C/H) PF to VF mailbox interrupt. Set when
484                  * CPT()_VF()_PF_MBOX(0) is written.
485                  **/
486                 uint64_t mbox                  : 1;
487 #else /* Word 0 - Little Endian */
488                 uint64_t mbox                  : 1;
489                 uint64_t dovf                  : 1;
490                 uint64_t irde                  : 1;
491                 uint64_t nwrp                  : 1;
492                 uint64_t swerr                 : 1;
493                 uint64_t hwerr                 : 1;
494                 uint64_t fault                 : 1;
495                 uint64_t reserved_5_63         : 59;
496 #endif /* Word 0 - End */
497         } s;
498 } cptx_vqx_misc_int_t;
499
500 /**
501  * Register (NCB) cpt#_vq#_saddr
502  *
503  * CPT Queue Starting Buffer Address Registers
504  * These registers set the instruction buffer starting address.
505  */
506 typedef union {
507         uint64_t u;
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.
518                  **/
519                 uint64_t ptr                   : 43;
520                 uint64_t reserved_0_5          : 6;
521 #else /* Word 0 - Little Endian */
522                 uint64_t reserved_0_5          : 6;
523                 uint64_t ptr                   : 43;
524                 uint64_t reserved_49_63        : 15;
525 #endif /* Word 0 - End */
526         } s;
527 } cptx_vqx_saddr_t;
528
529 #endif /*_CPT_HW_TYPES_H_ */