xref: /dpdk/drivers/baseband/fpga_5gnr_fec/fpga_5gnr_fec.h (revision e77506397fc8005c5129e22e9e2d15d5876790fd)
10b5927cbSNicolas Chautru /* SPDX-License-Identifier: BSD-3-Clause
20b5927cbSNicolas Chautru  * Copyright(c) 2020 Intel Corporation
30b5927cbSNicolas Chautru  */
40b5927cbSNicolas Chautru 
50b5927cbSNicolas Chautru #ifndef _FPGA_5GNR_FEC_H_
60b5927cbSNicolas Chautru #define _FPGA_5GNR_FEC_H_
70b5927cbSNicolas Chautru 
80b5927cbSNicolas Chautru #include <stdint.h>
90b5927cbSNicolas Chautru #include <stdbool.h>
100b5927cbSNicolas Chautru 
119e3ffd38SHernan Vargas #include "agx100_pmd.h"
12c750d277SHernan Vargas #include "vc_5gnr_pmd.h"
13c750d277SHernan Vargas 
142b843cacSDavid Marchand extern int fpga_5gnr_fec_logtype;
152b843cacSDavid Marchand #define RTE_LOGTYPE_FPGA_5GNR_FEC fpga_5gnr_fec_logtype
162b843cacSDavid Marchand 
170b5927cbSNicolas Chautru /* Helper macro for logging */
182b843cacSDavid Marchand #define rte_bbdev_log(level, ...) \
192b843cacSDavid Marchand 	RTE_LOG_LINE(level, FPGA_5GNR_FEC, __VA_ARGS__)
200b5927cbSNicolas Chautru 
210b5927cbSNicolas Chautru #ifdef RTE_LIBRTE_BBDEV_DEBUG
222b843cacSDavid Marchand #define rte_bbdev_log_debug(...) \
232b843cacSDavid Marchand 	rte_bbdev_log(DEBUG, __VA_ARGS__)
240b5927cbSNicolas Chautru #else
252b843cacSDavid Marchand #define rte_bbdev_log_debug(...)
260b5927cbSNicolas Chautru #endif
270b5927cbSNicolas Chautru 
280b5927cbSNicolas Chautru /* FPGA 5GNR FEC driver names */
290b5927cbSNicolas Chautru #define FPGA_5GNR_FEC_PF_DRIVER_NAME intel_fpga_5gnr_fec_pf
300b5927cbSNicolas Chautru #define FPGA_5GNR_FEC_VF_DRIVER_NAME intel_fpga_5gnr_fec_vf
310b5927cbSNicolas Chautru 
3210829ff2SHernan Vargas #define FPGA_5GNR_INVALID_HW_QUEUE_ID (0xFFFFFFFF)
3310829ff2SHernan Vargas #define FPGA_5GNR_QUEUE_FLUSH_TIMEOUT_US (1000)
3410829ff2SHernan Vargas #define FPGA_5GNR_HARQ_RDY_TIMEOUT (10)
3510829ff2SHernan Vargas #define FPGA_5GNR_TIMEOUT_CHECK_INTERVAL (5)
3610829ff2SHernan Vargas #define FPGA_5GNR_DDR_OVERFLOW (0x10)
3710829ff2SHernan Vargas #define FPGA_5GNR_DDR_WR_DATA_LEN_IN_BYTES 8
3810829ff2SHernan Vargas #define FPGA_5GNR_DDR_RD_DATA_LEN_IN_BYTES 8
39c750d277SHernan Vargas /* Align DMA descriptors to 256 bytes - cache-aligned. */
40c750d277SHernan Vargas #define FPGA_5GNR_RING_DESC_ENTRY_LENGTH (8)
41c750d277SHernan Vargas /* Maximum size of queue. */
42c750d277SHernan Vargas #define FPGA_5GNR_RING_MAX_SIZE (1024)
43c750d277SHernan Vargas 
44c750d277SHernan Vargas #define VC_5GNR_FPGA_VARIANT	0
45c750d277SHernan Vargas #define AGX100_FPGA_VARIANT	1
46cfea95f4SNicolas Chautru 
4744dc6faaSNicolas Chautru /* Constants from K0 computation from 3GPP 38.212 Table 5.4.2.1-2 */
4844dc6faaSNicolas Chautru #define N_ZC_1 66 /* N = 66 Zc for BG 1 */
4944dc6faaSNicolas Chautru #define N_ZC_2 50 /* N = 50 Zc for BG 2 */
5044dc6faaSNicolas Chautru #define K0_1_1 17 /* K0 fraction numerator for rv 1 and BG 1 */
5144dc6faaSNicolas Chautru #define K0_1_2 13 /* K0 fraction numerator for rv 1 and BG 2 */
5244dc6faaSNicolas Chautru #define K0_2_1 33 /* K0 fraction numerator for rv 2 and BG 1 */
5344dc6faaSNicolas Chautru #define K0_2_2 25 /* K0 fraction numerator for rv 2 and BG 2 */
5444dc6faaSNicolas Chautru #define K0_3_1 56 /* K0 fraction numerator for rv 3 and BG 1 */
5544dc6faaSNicolas Chautru #define K0_3_2 43 /* K0 fraction numerator for rv 3 and BG 2 */
56cfea95f4SNicolas Chautru 
57c750d277SHernan Vargas /* FPGA 5GNR Ring Control Registers. */
58cfea95f4SNicolas Chautru enum {
59cfea95f4SNicolas Chautru 	FPGA_5GNR_FEC_RING_HEAD_ADDR = 0x00000008,
60cfea95f4SNicolas Chautru 	FPGA_5GNR_FEC_RING_SIZE = 0x00000010,
61cfea95f4SNicolas Chautru 	FPGA_5GNR_FEC_RING_MISC = 0x00000014,
62cfea95f4SNicolas Chautru 	FPGA_5GNR_FEC_RING_ENABLE = 0x00000015,
63cfea95f4SNicolas Chautru 	FPGA_5GNR_FEC_RING_FLUSH_QUEUE_EN = 0x00000016,
64cfea95f4SNicolas Chautru 	FPGA_5GNR_FEC_RING_SHADOW_TAIL = 0x00000018,
65cfea95f4SNicolas Chautru 	FPGA_5GNR_FEC_RING_HEAD_POINT = 0x0000001C
66cfea95f4SNicolas Chautru };
67cfea95f4SNicolas Chautru 
68c750d277SHernan Vargas /* VC 5GNR and AGX100 common register mapping on BAR0. */
69cfea95f4SNicolas Chautru enum {
70c750d277SHernan Vargas 	FPGA_5GNR_FEC_VERSION_ID = 0x00000000, /**< len: 4B. */
71c750d277SHernan Vargas 	FPGA_5GNR_FEC_QUEUE_PF_VF_MAP_DONE = 0x00000008, /**< len: 1B. */
72c750d277SHernan Vargas 	FPGA_5GNR_FEC_LOAD_BALANCE_FACTOR = 0x0000000A, /**< len: 2B. */
73c750d277SHernan Vargas 	FPGA_5GNR_FEC_RING_DESC_LEN = 0x0000000C, /**< len: 2B. */
74c750d277SHernan Vargas 	FPGA_5GNR_FEC_VFQ_FLUSH_STATUS_LW = 0x00000018, /**< len: 4B. */
75c750d277SHernan Vargas 	FPGA_5GNR_FEC_VFQ_FLUSH_STATUS_HI = 0x0000001C, /**< len: 4B. */
76c750d277SHernan Vargas 	FPGA_5GNR_FEC_RING_CTRL_REGS = 0x00000200, /**< len: 2048B. */
77c750d277SHernan Vargas 	FPGA_5GNR_FEC_DDR4_WR_ADDR_REGS = 0x00000A00, /**< len: 4B. */
78c750d277SHernan Vargas 	FPGA_5GNR_FEC_DDR4_WR_DATA_REGS = 0x00000A08, /**< len: 8B. */
79c750d277SHernan Vargas 	FPGA_5GNR_FEC_DDR4_WR_DONE_REGS = 0x00000A10, /**< len: 1B. */
80c750d277SHernan Vargas 	FPGA_5GNR_FEC_DDR4_RD_ADDR_REGS = 0x00000A18, /**< len: 4B. */
81c750d277SHernan Vargas 	FPGA_5GNR_FEC_DDR4_RD_DONE_REGS = 0x00000A20, /**< len: 1B. */
82c750d277SHernan Vargas 	FPGA_5GNR_FEC_DDR4_RD_RDY_REGS = 0x00000A28, /**< len: 1B. */
83c750d277SHernan Vargas 	FPGA_5GNR_FEC_DDR4_RD_DATA_REGS = 0x00000A30, /**< len: 8B. */
84c750d277SHernan Vargas 	FPGA_5GNR_FEC_DDR4_ADDR_RDY_REGS = 0x00000A38, /**< len: 1B. */
85c750d277SHernan Vargas 	FPGA_5GNR_FEC_HARQ_BUF_SIZE_RDY_REGS = 0x00000A40, /**< len: 1B. */
86c750d277SHernan Vargas 	FPGA_5GNR_FEC_HARQ_BUF_SIZE_REGS = 0x00000A48, /**< len: 4B. */
87c750d277SHernan Vargas 	FPGA_5GNR_FEC_MUTEX = 0x00000A60, /**< len: 4B. */
88c750d277SHernan Vargas 	FPGA_5GNR_FEC_MUTEX_RESET = 0x00000A68  /**< len: 4B. */
89cfea95f4SNicolas Chautru };
90cfea95f4SNicolas Chautru 
9110829ff2SHernan Vargas /* FPGA 5GNR Ring Control Register. */
92*e7750639SAndre Muezerie struct __rte_packed_begin fpga_5gnr_ring_ctrl_reg {
93cfea95f4SNicolas Chautru 	uint64_t ring_base_addr;
94cfea95f4SNicolas Chautru 	uint64_t ring_head_addr;
95cfea95f4SNicolas Chautru 	uint16_t ring_size:11;
96cfea95f4SNicolas Chautru 	uint16_t rsrvd0;
97cfea95f4SNicolas Chautru 	union { /* Miscellaneous register */
98cfea95f4SNicolas Chautru 		uint8_t misc;
99cfea95f4SNicolas Chautru 		uint8_t max_ul_dec:5,
100cfea95f4SNicolas Chautru 			max_ul_dec_en:1,
101cfea95f4SNicolas Chautru 			rsrvd1:2;
102cfea95f4SNicolas Chautru 	};
103cfea95f4SNicolas Chautru 	uint8_t enable;
104cfea95f4SNicolas Chautru 	uint8_t flush_queue_en;
105cfea95f4SNicolas Chautru 	uint8_t rsrvd2;
106cfea95f4SNicolas Chautru 	uint16_t shadow_tail;
107cfea95f4SNicolas Chautru 	uint16_t rsrvd3;
108cfea95f4SNicolas Chautru 	uint16_t head_point;
109cfea95f4SNicolas Chautru 	uint16_t rsrvd4;
110*e7750639SAndre Muezerie } __rte_packed_end;
111cfea95f4SNicolas Chautru 
11210829ff2SHernan Vargas /* Private data structure for each FPGA 5GNR device. */
1130b5927cbSNicolas Chautru struct fpga_5gnr_fec_device {
11410829ff2SHernan Vargas 	/** Base address of MMIO registers (BAR0). */
1150b5927cbSNicolas Chautru 	void *mmio_base;
11610829ff2SHernan Vargas 	/** Base address of memory for sw rings. */
117c58109a8SNicolas Chautru 	void *sw_rings;
11810829ff2SHernan Vargas 	/** Physical address of sw_rings. */
119c58109a8SNicolas Chautru 	rte_iova_t sw_rings_phys;
120c58109a8SNicolas Chautru 	/** Number of bytes available for each queue in device. */
121c58109a8SNicolas Chautru 	uint32_t sw_ring_size;
12210829ff2SHernan Vargas 	/** Max number of entries available for each queue in device. */
123c58109a8SNicolas Chautru 	uint32_t sw_ring_max_depth;
12410829ff2SHernan Vargas 	/** Base address of response tail pointer buffer. */
125c58109a8SNicolas Chautru 	uint32_t *tail_ptrs;
12610829ff2SHernan Vargas 	/** Physical address of tail pointers. */
127c58109a8SNicolas Chautru 	rte_iova_t tail_ptr_phys;
12810829ff2SHernan Vargas 	/** Queues flush completion flag. */
129c58109a8SNicolas Chautru 	uint64_t *flush_queue_status;
13010829ff2SHernan Vargas 	/** Bitmap capturing which Queues are bound to the PF/VF. */
131c58109a8SNicolas Chautru 	uint64_t q_bound_bit_map;
13210829ff2SHernan Vargas 	/** Bitmap capturing which Queues have already been assigned. */
133c58109a8SNicolas Chautru 	uint64_t q_assigned_bit_map;
13410829ff2SHernan Vargas 	/** True if this is a PF FPGA 5GNR device. */
1350b5927cbSNicolas Chautru 	bool pf_device;
13699f09224SHernan Vargas 	/** Maximum number of possible queues for this device. */
13799f09224SHernan Vargas 	uint8_t total_num_queues;
1389e3ffd38SHernan Vargas 	/** FPGA Variant. VC_5GNR_FPGA_VARIANT = 0; AGX100_FPGA_VARIANT = 1. */
1399e3ffd38SHernan Vargas 	uint8_t fpga_variant;
1400b5927cbSNicolas Chautru };
1410b5927cbSNicolas Chautru 
14210829ff2SHernan Vargas /** Structure associated with each queue. */
14310829ff2SHernan Vargas struct __rte_cache_aligned fpga_5gnr_queue {
14410829ff2SHernan Vargas 	struct fpga_5gnr_ring_ctrl_reg ring_ctrl_reg;  /**< Ring Control Register */
1459e3ffd38SHernan Vargas 	union {
1469e3ffd38SHernan Vargas 		/** Virtual address of VC 5GNR software ring. */
1479e3ffd38SHernan Vargas 		union vc_5gnr_dma_desc *vc_5gnr_ring_addr;
1489e3ffd38SHernan Vargas 		/** Virtual address of AGX100 software ring. */
1499e3ffd38SHernan Vargas 		union agx100_dma_desc *agx100_ring_addr;
1509e3ffd38SHernan Vargas 	};
151c58109a8SNicolas Chautru 	uint64_t *ring_head_addr;  /* Virtual address of completion_head */
152c58109a8SNicolas Chautru 	uint64_t shadow_completion_head; /* Shadow completion head value */
153c58109a8SNicolas Chautru 	uint16_t head_free_desc;  /* Ring head */
154c58109a8SNicolas Chautru 	uint16_t tail;  /* Ring tail */
155c58109a8SNicolas Chautru 	/* Mask used to wrap enqueued descriptors on the sw ring */
156c58109a8SNicolas Chautru 	uint32_t sw_ring_wrap_mask;
157c58109a8SNicolas Chautru 	uint32_t irq_enable;  /* Enable ops dequeue interrupts if set to 1 */
158c58109a8SNicolas Chautru 	uint8_t q_idx;  /* Queue index */
159b3d326e4SHernan Vargas 	/** uuid used for MUTEX acquision for DDR */
160b3d326e4SHernan Vargas 	uint16_t ddr_mutex_uuid;
161c58109a8SNicolas Chautru 	struct fpga_5gnr_fec_device *d;
162c58109a8SNicolas Chautru 	/* MMIO register of shadow_tail used to enqueue descriptors */
163c58109a8SNicolas Chautru 	void *shadow_tail_addr;
164c58109a8SNicolas Chautru };
165c58109a8SNicolas Chautru 
16610829ff2SHernan Vargas /* Write to 16 bit MMIO register address. */
167c58109a8SNicolas Chautru static inline void
168c58109a8SNicolas Chautru mmio_write_16(void *addr, uint16_t value)
169c58109a8SNicolas Chautru {
170c58109a8SNicolas Chautru 	*((volatile uint16_t *)(addr)) = rte_cpu_to_le_16(value);
171c58109a8SNicolas Chautru }
172c58109a8SNicolas Chautru 
17310829ff2SHernan Vargas /* Write to 32 bit MMIO register address. */
174c58109a8SNicolas Chautru static inline void
175c58109a8SNicolas Chautru mmio_write_32(void *addr, uint32_t value)
176c58109a8SNicolas Chautru {
177c58109a8SNicolas Chautru 	*((volatile uint32_t *)(addr)) = rte_cpu_to_le_32(value);
178c58109a8SNicolas Chautru }
179c58109a8SNicolas Chautru 
18010829ff2SHernan Vargas /* Write to 64 bit MMIO register address. */
181c58109a8SNicolas Chautru static inline void
182c58109a8SNicolas Chautru mmio_write_64(void *addr, uint64_t value)
183c58109a8SNicolas Chautru {
184c58109a8SNicolas Chautru 	*((volatile uint64_t *)(addr)) = rte_cpu_to_le_64(value);
185c58109a8SNicolas Chautru }
186c58109a8SNicolas Chautru 
18710829ff2SHernan Vargas /* Write a 8 bit register of a FPGA 5GNR device. */
188c58109a8SNicolas Chautru static inline void
18910829ff2SHernan Vargas fpga_5gnr_reg_write_8(void *mmio_base, uint32_t offset, uint8_t payload)
190c58109a8SNicolas Chautru {
191c58109a8SNicolas Chautru 	void *reg_addr = RTE_PTR_ADD(mmio_base, offset);
192c58109a8SNicolas Chautru 	*((volatile uint8_t *)(reg_addr)) = payload;
193c58109a8SNicolas Chautru }
194c58109a8SNicolas Chautru 
19510829ff2SHernan Vargas /* Write a 16 bit register of a FPGA 5GNR device. */
196c58109a8SNicolas Chautru static inline void
19710829ff2SHernan Vargas fpga_5gnr_reg_write_16(void *mmio_base, uint32_t offset, uint16_t payload)
198c58109a8SNicolas Chautru {
199c58109a8SNicolas Chautru 	void *reg_addr = RTE_PTR_ADD(mmio_base, offset);
200c58109a8SNicolas Chautru 	mmio_write_16(reg_addr, payload);
201c58109a8SNicolas Chautru }
202c58109a8SNicolas Chautru 
20310829ff2SHernan Vargas /* Write a 32 bit register of a FPGA 5GNR device. */
204c58109a8SNicolas Chautru static inline void
20510829ff2SHernan Vargas fpga_5gnr_reg_write_32(void *mmio_base, uint32_t offset, uint32_t payload)
206c58109a8SNicolas Chautru {
207c58109a8SNicolas Chautru 	void *reg_addr = RTE_PTR_ADD(mmio_base, offset);
208c58109a8SNicolas Chautru 	mmio_write_32(reg_addr, payload);
209c58109a8SNicolas Chautru }
210c58109a8SNicolas Chautru 
21110829ff2SHernan Vargas /* Write a 64 bit register of a FPGA 5GNR device. */
212c58109a8SNicolas Chautru static inline void
21310829ff2SHernan Vargas fpga_5gnr_reg_write_64(void *mmio_base, uint32_t offset, uint64_t payload)
214c58109a8SNicolas Chautru {
215c58109a8SNicolas Chautru 	void *reg_addr = RTE_PTR_ADD(mmio_base, offset);
216c58109a8SNicolas Chautru 	mmio_write_64(reg_addr, payload);
217c58109a8SNicolas Chautru }
218c58109a8SNicolas Chautru 
21910829ff2SHernan Vargas /* Write a ring control register of a FPGA 5GNR device. */
220c58109a8SNicolas Chautru static inline void
22110829ff2SHernan Vargas fpga_ring_reg_write(void *mmio_base, uint32_t offset, struct fpga_5gnr_ring_ctrl_reg payload)
222c58109a8SNicolas Chautru {
22310829ff2SHernan Vargas 	fpga_5gnr_reg_write_64(mmio_base, offset, payload.ring_base_addr);
22410829ff2SHernan Vargas 	fpga_5gnr_reg_write_64(mmio_base, offset + FPGA_5GNR_FEC_RING_HEAD_ADDR,
225c58109a8SNicolas Chautru 			payload.ring_head_addr);
22610829ff2SHernan Vargas 	fpga_5gnr_reg_write_16(mmio_base, offset + FPGA_5GNR_FEC_RING_SIZE, payload.ring_size);
22710829ff2SHernan Vargas 	fpga_5gnr_reg_write_16(mmio_base, offset + FPGA_5GNR_FEC_RING_HEAD_POINT,
228c58109a8SNicolas Chautru 			payload.head_point);
22910829ff2SHernan Vargas 	fpga_5gnr_reg_write_8(mmio_base, offset + FPGA_5GNR_FEC_RING_FLUSH_QUEUE_EN,
230c58109a8SNicolas Chautru 			payload.flush_queue_en);
23110829ff2SHernan Vargas 	fpga_5gnr_reg_write_16(mmio_base, offset + FPGA_5GNR_FEC_RING_SHADOW_TAIL,
232c58109a8SNicolas Chautru 			payload.shadow_tail);
23310829ff2SHernan Vargas 	fpga_5gnr_reg_write_8(mmio_base, offset + FPGA_5GNR_FEC_RING_MISC, payload.misc);
23410829ff2SHernan Vargas 	fpga_5gnr_reg_write_8(mmio_base, offset + FPGA_5GNR_FEC_RING_ENABLE, payload.enable);
235c58109a8SNicolas Chautru }
236c58109a8SNicolas Chautru 
23710829ff2SHernan Vargas /* Read a register of FPGA 5GNR device. */
23857936c36SNicolas Chautru static inline uint32_t
23910829ff2SHernan Vargas fpga_5gnr_reg_read_32(void *mmio_base, uint32_t offset)
24057936c36SNicolas Chautru {
24157936c36SNicolas Chautru 	void *reg_addr = RTE_PTR_ADD(mmio_base, offset);
24257936c36SNicolas Chautru 	uint32_t ret = *((volatile uint32_t *)(reg_addr));
24357936c36SNicolas Chautru 	return rte_le_to_cpu_32(ret);
24457936c36SNicolas Chautru }
24557936c36SNicolas Chautru 
24611b0a112SNicolas Chautru #ifdef RTE_LIBRTE_BBDEV_DEBUG
24711b0a112SNicolas Chautru 
24810829ff2SHernan Vargas /* Read a register of FPGA 5GNR device. */
24911b0a112SNicolas Chautru static inline uint16_t
25010829ff2SHernan Vargas fpga_5gnr_reg_read_16(void *mmio_base, uint32_t offset)
25111b0a112SNicolas Chautru {
25211b0a112SNicolas Chautru 	void *reg_addr = RTE_PTR_ADD(mmio_base, offset);
25311b0a112SNicolas Chautru 	uint16_t ret = *((volatile uint16_t *)(reg_addr));
25411b0a112SNicolas Chautru 	return rte_le_to_cpu_16(ret);
25511b0a112SNicolas Chautru }
25611b0a112SNicolas Chautru 
2574d9199e3SNicolas Chautru #endif
2584d9199e3SNicolas Chautru 
25910829ff2SHernan Vargas /* Read a register of FPGA 5GNR device. */
26011b0a112SNicolas Chautru static inline uint8_t
26110829ff2SHernan Vargas fpga_5gnr_reg_read_8(void *mmio_base, uint32_t offset)
26211b0a112SNicolas Chautru {
26311b0a112SNicolas Chautru 	void *reg_addr = RTE_PTR_ADD(mmio_base, offset);
26411b0a112SNicolas Chautru 	return *((volatile uint8_t *)(reg_addr));
26511b0a112SNicolas Chautru }
26611b0a112SNicolas Chautru 
26710829ff2SHernan Vargas /* Read a register of FPGA 5GNR device. */
26811b0a112SNicolas Chautru static inline uint64_t
26910829ff2SHernan Vargas fpga_5gnr_reg_read_64(void *mmio_base, uint32_t offset)
27011b0a112SNicolas Chautru {
27111b0a112SNicolas Chautru 	void *reg_addr = RTE_PTR_ADD(mmio_base, offset);
27211b0a112SNicolas Chautru 	uint64_t ret = *((volatile uint64_t *)(reg_addr));
27311b0a112SNicolas Chautru 	return rte_le_to_cpu_64(ret);
27411b0a112SNicolas Chautru }
27511b0a112SNicolas Chautru 
2760b5927cbSNicolas Chautru #endif /* _FPGA_5GNR_FEC_H_ */
277