baseband/acc100: add HW register definitions
[dpdk.git] / drivers / baseband / acc100 / rte_acc100_pmd.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Intel Corporation
3  */
4
5 #ifndef _RTE_ACC100_PMD_H_
6 #define _RTE_ACC100_PMD_H_
7
8 #include "acc100_pf_enum.h"
9 #include "acc100_vf_enum.h"
10
11 /* Helper macro for logging */
12 #define rte_bbdev_log(level, fmt, ...) \
13         rte_log(RTE_LOG_ ## level, acc100_logtype, fmt "\n", \
14                 ##__VA_ARGS__)
15
16 #ifdef RTE_LIBRTE_BBDEV_DEBUG
17 #define rte_bbdev_log_debug(fmt, ...) \
18                 rte_bbdev_log(DEBUG, "acc100_pmd: " fmt, \
19                 ##__VA_ARGS__)
20 #else
21 #define rte_bbdev_log_debug(fmt, ...)
22 #endif
23
24 /* ACC100 PF and VF driver names */
25 #define ACC100PF_DRIVER_NAME           intel_acc100_pf
26 #define ACC100VF_DRIVER_NAME           intel_acc100_vf
27
28 /* ACC100 PCI vendor & device IDs */
29 #define RTE_ACC100_VENDOR_ID           (0x8086)
30 #define RTE_ACC100_PF_DEVICE_ID        (0x0d5c)
31 #define RTE_ACC100_VF_DEVICE_ID        (0x0d5d)
32
33 /* Define as 1 to use only a single FEC engine */
34 #ifndef RTE_ACC100_SINGLE_FEC
35 #define RTE_ACC100_SINGLE_FEC 0
36 #endif
37
38 /* Values used in filling in descriptors */
39 #define ACC100_DMA_DESC_TYPE           2
40 #define ACC100_DMA_CODE_BLK_MODE       0
41 #define ACC100_DMA_BLKID_FCW           1
42 #define ACC100_DMA_BLKID_IN            2
43 #define ACC100_DMA_BLKID_OUT_ENC       1
44 #define ACC100_DMA_BLKID_OUT_HARD      1
45 #define ACC100_DMA_BLKID_OUT_SOFT      2
46 #define ACC100_DMA_BLKID_OUT_HARQ      3
47 #define ACC100_DMA_BLKID_IN_HARQ       3
48
49 /* Values used in filling in decode FCWs */
50 #define ACC100_FCW_TD_VER              1
51 #define ACC100_FCW_TD_EXT_COLD_REG_EN  1
52 #define ACC100_FCW_TD_AUTOMAP          0x0f
53 #define ACC100_FCW_TD_RVIDX_0          2
54 #define ACC100_FCW_TD_RVIDX_1          26
55 #define ACC100_FCW_TD_RVIDX_2          50
56 #define ACC100_FCW_TD_RVIDX_3          74
57
58 /* Values used in writing to the registers */
59 #define ACC100_REG_IRQ_EN_ALL          0x1FF83FF  /* Enable all interrupts */
60
61 /* ACC100 Specific Dimensioning */
62 #define ACC100_SIZE_64MBYTE            (64*1024*1024)
63 /* Number of elements in an Info Ring */
64 #define ACC100_INFO_RING_NUM_ENTRIES   1024
65 /* Number of elements in HARQ layout memory */
66 #define ACC100_HARQ_LAYOUT             (64*1024*1024)
67 /* Assume offset for HARQ in memory */
68 #define ACC100_HARQ_OFFSET             (32*1024)
69 /* Mask used to calculate an index in an Info Ring array (not a byte offset) */
70 #define ACC100_INFO_RING_MASK          (ACC100_INFO_RING_NUM_ENTRIES-1)
71 /* Number of Virtual Functions ACC100 supports */
72 #define ACC100_NUM_VFS                  16
73 #define ACC100_NUM_QGRPS                8
74 #define ACC100_NUM_QGRPS_PER_WORD       8
75 #define ACC100_NUM_AQS                  16
76 #define MAX_ENQ_BATCH_SIZE              255
77 /* All ACC100 Registers alignment are 32bits = 4B */
78 #define ACC100_BYTES_IN_WORD                 4
79 #define ACC100_MAX_E_MBUF                64000
80
81 #define ACC100_GRP_ID_SHIFT    10 /* Queue Index Hierarchy */
82 #define ACC100_VF_ID_SHIFT     4  /* Queue Index Hierarchy */
83 #define ACC100_VF_OFFSET_QOS   16 /* offset in Memory specific to QoS Mon */
84 #define ACC100_TMPL_PRI_0      0x03020100
85 #define ACC100_TMPL_PRI_1      0x07060504
86 #define ACC100_TMPL_PRI_2      0x0b0a0908
87 #define ACC100_TMPL_PRI_3      0x0f0e0d0c
88 #define ACC100_QUEUE_ENABLE    0x80000000  /* Bit to mark Queue as Enabled */
89 #define ACC100_WORDS_IN_ARAM_SIZE (128 * 1024 / 4)
90
91 #define ACC100_NUM_TMPL       32
92 /* Mapping of signals for the available engines */
93 #define ACC100_SIG_UL_5G      0
94 #define ACC100_SIG_UL_5G_LAST 7
95 #define ACC100_SIG_DL_5G      13
96 #define ACC100_SIG_DL_5G_LAST 15
97 #define ACC100_SIG_UL_4G      16
98 #define ACC100_SIG_UL_4G_LAST 21
99 #define ACC100_SIG_DL_4G      27
100 #define ACC100_SIG_DL_4G_LAST 31
101
102 /* max number of iterations to allocate memory block for all rings */
103 #define ACC100_SW_RING_MEM_ALLOC_ATTEMPTS 5
104 #define ACC100_MAX_QUEUE_DEPTH            1024
105 #define ACC100_DMA_MAX_NUM_POINTERS       14
106 #define ACC100_DMA_DESC_PADDING           8
107 #define ACC100_FCW_PADDING                12
108 #define ACC100_DESC_FCW_OFFSET            192
109 #define ACC100_DESC_SIZE                  256
110 #define ACC100_DESC_OFFSET                (ACC100_DESC_SIZE / 64)
111 #define ACC100_FCW_TE_BLEN                32
112 #define ACC100_FCW_TD_BLEN                24
113 #define ACC100_FCW_LE_BLEN                32
114 #define ACC100_FCW_LD_BLEN                36
115
116 #define ACC100_FCW_VER         2
117 #define ACC100_MUX_5GDL_DESC   6
118 #define ACC100_CMP_ENC_SIZE    20
119 #define ACC100_CMP_DEC_SIZE    24
120 #define ACC100_ENC_OFFSET     (32)
121 #define ACC100_DEC_OFFSET     (80)
122 #define ACC100_EXT_MEM /* Default option with memory external to CPU */
123 #define ACC100_HARQ_OFFSET_THRESHOLD 1024
124
125 /* Constants from K0 computation from 3GPP 38.212 Table 5.4.2.1-2 */
126 #define ACC100_N_ZC_1 66 /* N = 66 Zc for BG 1 */
127 #define ACC100_N_ZC_2 50 /* N = 50 Zc for BG 2 */
128 #define ACC100_K0_1_1 17 /* K0 fraction numerator for rv 1 and BG 1 */
129 #define ACC100_K0_1_2 13 /* K0 fraction numerator for rv 1 and BG 2 */
130 #define ACC100_K0_2_1 33 /* K0 fraction numerator for rv 2 and BG 1 */
131 #define ACC100_K0_2_2 25 /* K0 fraction numerator for rv 2 and BG 2 */
132 #define ACC100_K0_3_1 56 /* K0 fraction numerator for rv 3 and BG 1 */
133 #define ACC100_K0_3_2 43 /* K0 fraction numerator for rv 3 and BG 2 */
134
135 /* ACC100 Configuration */
136 #define ACC100_DDR_ECC_ENABLE
137 #define ACC100_CFG_DMA_ERROR    0x3D7
138 #define ACC100_CFG_AXI_CACHE    0x11
139 #define ACC100_CFG_QMGR_HI_P    0x0F0F
140 #define ACC100_CFG_PCI_AXI      0xC003
141 #define ACC100_CFG_PCI_BRIDGE   0x40006033
142 #define ACC100_ENGINE_OFFSET    0x1000
143 #define ACC100_RESET_HI         0x20100
144 #define ACC100_RESET_LO         0x20000
145 #define ACC100_RESET_HARD       0x1FF
146 #define ACC100_ENGINES_MAX      9
147 #define ACC100_LONG_WAIT        1000
148
149 /* ACC100 DMA Descriptor triplet */
150 struct acc100_dma_triplet {
151         uint64_t address;
152         uint32_t blen:20,
153                 res0:4,
154                 last:1,
155                 dma_ext:1,
156                 res1:2,
157                 blkid:4;
158 } __rte_packed;
159
160 /* ACC100 DMA Response Descriptor */
161 union acc100_dma_rsp_desc {
162         uint32_t val;
163         struct {
164                 uint32_t crc_status:1,
165                         synd_ok:1,
166                         dma_err:1,
167                         neg_stop:1,
168                         fcw_err:1,
169                         output_err:1,
170                         input_err:1,
171                         timestampEn:1,
172                         iterCountFrac:8,
173                         iter_cnt:8,
174                         rsrvd3:6,
175                         sdone:1,
176                         fdone:1;
177                 uint32_t add_info_0;
178                 uint32_t add_info_1;
179         };
180 };
181
182
183 /* ACC100 Queue Manager Enqueue PCI Register */
184 union acc100_enqueue_reg_fmt {
185         uint32_t val;
186         struct {
187                 uint32_t num_elem:8,
188                         addr_offset:3,
189                         rsrvd:1,
190                         req_elem_addr:20;
191         };
192 };
193
194 /* FEC 4G Uplink Frame Control Word */
195 struct __rte_packed acc100_fcw_td {
196         uint8_t fcw_ver:4,
197                 num_maps:4; /* Unused */
198         uint8_t filler:6, /* Unused */
199                 rsrvd0:1,
200                 bypass_sb_deint:1;
201         uint16_t k_pos;
202         uint16_t k_neg; /* Unused */
203         uint8_t c_neg; /* Unused */
204         uint8_t c; /* Unused */
205         uint32_t ea; /* Unused */
206         uint32_t eb; /* Unused */
207         uint8_t cab; /* Unused */
208         uint8_t k0_start_col; /* Unused */
209         uint8_t rsrvd1;
210         uint8_t code_block_mode:1, /* Unused */
211                 turbo_crc_type:1,
212                 rsrvd2:3,
213                 bypass_teq:1, /* Unused */
214                 soft_output_en:1, /* Unused */
215                 ext_td_cold_reg_en:1;
216         union { /* External Cold register */
217                 uint32_t ext_td_cold_reg;
218                 struct {
219                         uint32_t min_iter:4, /* Unused */
220                                 max_iter:4,
221                                 ext_scale:5, /* Unused */
222                                 rsrvd3:3,
223                                 early_stop_en:1, /* Unused */
224                                 sw_soft_out_dis:1, /* Unused */
225                                 sw_et_cont:1, /* Unused */
226                                 sw_soft_out_saturation:1, /* Unused */
227                                 half_iter_on:1, /* Unused */
228                                 raw_decoder_input_on:1, /* Unused */
229                                 rsrvd4:10;
230                 };
231         };
232 };
233
234 /* FEC 5GNR Uplink Frame Control Word */
235 struct __rte_packed acc100_fcw_ld {
236         uint32_t FCWversion:4,
237                 qm:4,
238                 nfiller:11,
239                 BG:1,
240                 Zc:9,
241                 res0:1,
242                 synd_precoder:1,
243                 synd_post:1;
244         uint32_t ncb:16,
245                 k0:16;
246         uint32_t rm_e:24,
247                 hcin_en:1,
248                 hcout_en:1,
249                 crc_select:1,
250                 bypass_dec:1,
251                 bypass_intlv:1,
252                 so_en:1,
253                 so_bypass_rm:1,
254                 so_bypass_intlv:1;
255         uint32_t hcin_offset:16,
256                 hcin_size0:16;
257         uint32_t hcin_size1:16,
258                 hcin_decomp_mode:3,
259                 llr_pack_mode:1,
260                 hcout_comp_mode:3,
261                 res2:1,
262                 dec_convllr:4,
263                 hcout_convllr:4;
264         uint32_t itmax:7,
265                 itstop:1,
266                 so_it:7,
267                 res3:1,
268                 hcout_offset:16;
269         uint32_t hcout_size0:16,
270                 hcout_size1:16;
271         uint32_t gain_i:8,
272                 gain_h:8,
273                 negstop_th:16;
274         uint32_t negstop_it:7,
275                 negstop_en:1,
276                 res4:24;
277 };
278
279 /* FEC 4G Downlink Frame Control Word */
280 struct __rte_packed acc100_fcw_te {
281         uint16_t k_neg;
282         uint16_t k_pos;
283         uint8_t c_neg;
284         uint8_t c;
285         uint8_t filler;
286         uint8_t cab;
287         uint32_t ea:17,
288                 rsrvd0:15;
289         uint32_t eb:17,
290                 rsrvd1:15;
291         uint16_t ncb_neg;
292         uint16_t ncb_pos;
293         uint8_t rv_idx0:2,
294                 rsrvd2:2,
295                 rv_idx1:2,
296                 rsrvd3:2;
297         uint8_t bypass_rv_idx0:1,
298                 bypass_rv_idx1:1,
299                 bypass_rm:1,
300                 rsrvd4:5;
301         uint8_t rsrvd5:1,
302                 rsrvd6:3,
303                 code_block_crc:1,
304                 rsrvd7:3;
305         uint8_t code_block_mode:1,
306                 rsrvd8:7;
307         uint64_t rsrvd9;
308 };
309
310 /* FEC 5GNR Downlink Frame Control Word */
311 struct __rte_packed acc100_fcw_le {
312         uint32_t FCWversion:4,
313                 qm:4,
314                 nfiller:11,
315                 BG:1,
316                 Zc:9,
317                 res0:3;
318         uint32_t ncb:16,
319                 k0:16;
320         uint32_t rm_e:24,
321                 res1:2,
322                 crc_select:1,
323                 res2:1,
324                 bypass_intlv:1,
325                 res3:3;
326         uint32_t res4_a:12,
327                 mcb_count:3,
328                 res4_b:17;
329         uint32_t res5;
330         uint32_t res6;
331         uint32_t res7;
332         uint32_t res8;
333 };
334
335 /* ACC100 DMA Request Descriptor */
336 struct __rte_packed acc100_dma_req_desc {
337         union {
338                 struct{
339                         uint32_t type:4,
340                                 rsrvd0:26,
341                                 sdone:1,
342                                 fdone:1;
343                         uint32_t rsrvd1;
344                         uint32_t rsrvd2;
345                         uint32_t pass_param:8,
346                                 sdone_enable:1,
347                                 irq_enable:1,
348                                 timeStampEn:1,
349                                 res0:5,
350                                 numCBs:4,
351                                 res1:4,
352                                 m2dlen:4,
353                                 d2mlen:4;
354                 };
355                 struct{
356                         uint32_t word0;
357                         uint32_t word1;
358                         uint32_t word2;
359                         uint32_t word3;
360                 };
361         };
362         struct acc100_dma_triplet data_ptrs[ACC100_DMA_MAX_NUM_POINTERS];
363
364         /* Virtual addresses used to retrieve SW context info */
365         union {
366                 void *op_addr;
367                 uint64_t pad1;  /* pad to 64 bits */
368         };
369         /*
370          * Stores additional information needed for driver processing:
371          * - last_desc_in_batch - flag used to mark last descriptor (CB)
372          *                        in batch
373          * - cbs_in_tb - stores information about total number of Code Blocks
374          *               in currently processed Transport Block
375          */
376         union {
377                 struct {
378                         union {
379                                 struct acc100_fcw_ld fcw_ld;
380                                 struct acc100_fcw_td fcw_td;
381                                 struct acc100_fcw_le fcw_le;
382                                 struct acc100_fcw_te fcw_te;
383                                 uint32_t pad2[ACC100_FCW_PADDING];
384                         };
385                         uint32_t last_desc_in_batch :8,
386                                 cbs_in_tb:8,
387                                 pad4 : 16;
388                 };
389                 uint64_t pad3[ACC100_DMA_DESC_PADDING]; /* pad to 64 bits */
390         };
391 };
392
393 /* ACC100 DMA Descriptor */
394 union acc100_dma_desc {
395         struct acc100_dma_req_desc req;
396         union acc100_dma_rsp_desc rsp;
397 };
398
399
400 /* Union describing Info Ring entry */
401 union acc100_harq_layout_data {
402         uint32_t val;
403         struct {
404                 uint16_t offset;
405                 uint16_t size0;
406         };
407 } __rte_packed;
408
409
410 /* Union describing Info Ring entry */
411 union acc100_info_ring_data {
412         uint32_t val;
413         struct {
414                 union {
415                         uint16_t detailed_info;
416                         struct {
417                                 uint16_t aq_id: 4;
418                                 uint16_t qg_id: 4;
419                                 uint16_t vf_id: 6;
420                                 uint16_t reserved: 2;
421                         };
422                 };
423                 uint16_t int_nb: 7;
424                 uint16_t msi_0: 1;
425                 uint16_t vf2pf: 6;
426                 uint16_t loop: 1;
427                 uint16_t valid: 1;
428         };
429 } __rte_packed;
430
431 struct acc100_registry_addr {
432         unsigned int dma_ring_dl5g_hi;
433         unsigned int dma_ring_dl5g_lo;
434         unsigned int dma_ring_ul5g_hi;
435         unsigned int dma_ring_ul5g_lo;
436         unsigned int dma_ring_dl4g_hi;
437         unsigned int dma_ring_dl4g_lo;
438         unsigned int dma_ring_ul4g_hi;
439         unsigned int dma_ring_ul4g_lo;
440         unsigned int ring_size;
441         unsigned int info_ring_hi;
442         unsigned int info_ring_lo;
443         unsigned int info_ring_en;
444         unsigned int info_ring_ptr;
445         unsigned int tail_ptrs_dl5g_hi;
446         unsigned int tail_ptrs_dl5g_lo;
447         unsigned int tail_ptrs_ul5g_hi;
448         unsigned int tail_ptrs_ul5g_lo;
449         unsigned int tail_ptrs_dl4g_hi;
450         unsigned int tail_ptrs_dl4g_lo;
451         unsigned int tail_ptrs_ul4g_hi;
452         unsigned int tail_ptrs_ul4g_lo;
453         unsigned int depth_log0_offset;
454         unsigned int depth_log1_offset;
455         unsigned int qman_group_func;
456         unsigned int ddr_range;
457 };
458
459 /* Structure holding registry addresses for PF */
460 static const struct acc100_registry_addr pf_reg_addr = {
461         .dma_ring_dl5g_hi = HWPfDmaFec5GdlDescBaseHiRegVf,
462         .dma_ring_dl5g_lo = HWPfDmaFec5GdlDescBaseLoRegVf,
463         .dma_ring_ul5g_hi = HWPfDmaFec5GulDescBaseHiRegVf,
464         .dma_ring_ul5g_lo = HWPfDmaFec5GulDescBaseLoRegVf,
465         .dma_ring_dl4g_hi = HWPfDmaFec4GdlDescBaseHiRegVf,
466         .dma_ring_dl4g_lo = HWPfDmaFec4GdlDescBaseLoRegVf,
467         .dma_ring_ul4g_hi = HWPfDmaFec4GulDescBaseHiRegVf,
468         .dma_ring_ul4g_lo = HWPfDmaFec4GulDescBaseLoRegVf,
469         .ring_size = HWPfQmgrRingSizeVf,
470         .info_ring_hi = HWPfHiInfoRingBaseHiRegPf,
471         .info_ring_lo = HWPfHiInfoRingBaseLoRegPf,
472         .info_ring_en = HWPfHiInfoRingIntWrEnRegPf,
473         .info_ring_ptr = HWPfHiInfoRingPointerRegPf,
474         .tail_ptrs_dl5g_hi = HWPfDmaFec5GdlRespPtrHiRegVf,
475         .tail_ptrs_dl5g_lo = HWPfDmaFec5GdlRespPtrLoRegVf,
476         .tail_ptrs_ul5g_hi = HWPfDmaFec5GulRespPtrHiRegVf,
477         .tail_ptrs_ul5g_lo = HWPfDmaFec5GulRespPtrLoRegVf,
478         .tail_ptrs_dl4g_hi = HWPfDmaFec4GdlRespPtrHiRegVf,
479         .tail_ptrs_dl4g_lo = HWPfDmaFec4GdlRespPtrLoRegVf,
480         .tail_ptrs_ul4g_hi = HWPfDmaFec4GulRespPtrHiRegVf,
481         .tail_ptrs_ul4g_lo = HWPfDmaFec4GulRespPtrLoRegVf,
482         .depth_log0_offset = HWPfQmgrGrpDepthLog20Vf,
483         .depth_log1_offset = HWPfQmgrGrpDepthLog21Vf,
484         .qman_group_func = HWPfQmgrGrpFunction0,
485         .ddr_range = HWPfDmaVfDdrBaseRw,
486 };
487
488 /* Structure holding registry addresses for VF */
489 static const struct acc100_registry_addr vf_reg_addr = {
490         .dma_ring_dl5g_hi = HWVfDmaFec5GdlDescBaseHiRegVf,
491         .dma_ring_dl5g_lo = HWVfDmaFec5GdlDescBaseLoRegVf,
492         .dma_ring_ul5g_hi = HWVfDmaFec5GulDescBaseHiRegVf,
493         .dma_ring_ul5g_lo = HWVfDmaFec5GulDescBaseLoRegVf,
494         .dma_ring_dl4g_hi = HWVfDmaFec4GdlDescBaseHiRegVf,
495         .dma_ring_dl4g_lo = HWVfDmaFec4GdlDescBaseLoRegVf,
496         .dma_ring_ul4g_hi = HWVfDmaFec4GulDescBaseHiRegVf,
497         .dma_ring_ul4g_lo = HWVfDmaFec4GulDescBaseLoRegVf,
498         .ring_size = HWVfQmgrRingSizeVf,
499         .info_ring_hi = HWVfHiInfoRingBaseHiVf,
500         .info_ring_lo = HWVfHiInfoRingBaseLoVf,
501         .info_ring_en = HWVfHiInfoRingIntWrEnVf,
502         .info_ring_ptr = HWVfHiInfoRingPointerVf,
503         .tail_ptrs_dl5g_hi = HWVfDmaFec5GdlRespPtrHiRegVf,
504         .tail_ptrs_dl5g_lo = HWVfDmaFec5GdlRespPtrLoRegVf,
505         .tail_ptrs_ul5g_hi = HWVfDmaFec5GulRespPtrHiRegVf,
506         .tail_ptrs_ul5g_lo = HWVfDmaFec5GulRespPtrLoRegVf,
507         .tail_ptrs_dl4g_hi = HWVfDmaFec4GdlRespPtrHiRegVf,
508         .tail_ptrs_dl4g_lo = HWVfDmaFec4GdlRespPtrLoRegVf,
509         .tail_ptrs_ul4g_hi = HWVfDmaFec4GulRespPtrHiRegVf,
510         .tail_ptrs_ul4g_lo = HWVfDmaFec4GulRespPtrLoRegVf,
511         .depth_log0_offset = HWVfQmgrGrpDepthLog20Vf,
512         .depth_log1_offset = HWVfQmgrGrpDepthLog21Vf,
513         .qman_group_func = HWVfQmgrGrpFunction0Vf,
514         .ddr_range = HWVfDmaDdrBaseRangeRoVf,
515 };
516
517 /* Private data structure for each ACC100 device */
518 struct acc100_device {
519         void *mmio_base;  /**< Base address of MMIO registers (BAR0) */
520         bool pf_device; /**< True if this is a PF ACC100 device */
521         bool configured; /**< True if this ACC100 device is configured */
522 };
523
524 #endif /* _RTE_ACC100_PMD_H_ */