baseband/la12xx: add queue and modem config
[dpdk.git] / drivers / baseband / la12xx / bbdev_la12xx_ipc.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2020-2021 NXP
3  */
4 #ifndef __BBDEV_LA12XX_IPC_H__
5 #define __BBDEV_LA12XX_IPC_H__
6
7 #define LA12XX_MAX_QUEUES 20
8 #define HOST_RX_QUEUEID_OFFSET LA12XX_MAX_QUEUES
9
10 /** No. of max channel per instance */
11 #define IPC_MAX_CHANNEL_COUNT   (64)
12
13 /** No. of max channel per instance */
14 #define IPC_MAX_DEPTH   (16)
15
16 /** No. of max IPC instance per modem */
17 #define IPC_MAX_INSTANCE_COUNT  (1)
18
19 /** Error codes */
20 #define IPC_SUCCESS             (0) /** IPC operation success */
21 #define IPC_INPUT_INVALID       (-1) /** Invalid input to API */
22 #define IPC_CH_INVALID          (-2) /** Channel no is invalid */
23 #define IPC_INSTANCE_INVALID    (-3) /** Instance no is invalid */
24 #define IPC_MEM_INVALID         (-4) /** Insufficient memory */
25 #define IPC_CH_FULL             (-5) /** Channel is full */
26 #define IPC_CH_EMPTY            (-6) /** Channel is empty */
27 #define IPC_BL_EMPTY            (-7) /** Free buffer list is empty */
28 #define IPC_BL_FULL             (-8) /** Free buffer list is full */
29 #define IPC_HOST_BUF_ALLOC_FAIL (-9) /** DPDK malloc fail */
30 #define IPC_MD_SZ_MISS_MATCH    (-10) /** META DATA size in mhif miss matched*/
31 #define IPC_MALLOC_FAIL         (-11) /** system malloc fail */
32 #define IPC_IOCTL_FAIL          (-12) /** IOCTL call failed */
33 #define IPC_MMAP_FAIL           (-14) /** MMAP fail */
34 #define IPC_OPEN_FAIL           (-15) /** OPEN fail */
35 #define IPC_EVENTFD_FAIL        (-16) /** eventfd initialization failed */
36 #define IPC_NOT_IMPLEMENTED     (-17) /** IPC feature is not implemented yet*/
37
38 #define SET_HIF_HOST_RDY(hif, RDY_MASK) (hif->host_ready |= RDY_MASK)
39 #define CHK_HIF_MOD_RDY(hif, RDY_MASK) (hif->mod_ready & RDY_MASK)
40
41 /* Host Ready bits */
42 #define HIF_HOST_READY_HOST_REGIONS     (1 << 0)
43 #define HIF_HOST_READY_IPC_LIB          (1 << 12)
44 #define HIF_HOST_READY_IPC_APP          (1 << 13)
45 #define HIF_HOST_READY_FECA             (1 << 14)
46
47 /* Modem Ready bits */
48 #define HIF_MOD_READY_IPC_LIB           (1 << 5)
49 #define HIF_MOD_READY_IPC_APP           (1 << 6)
50 #define HIF_MOD_READY_FECA              (1 << 7)
51
52 typedef void *ipc_t;
53
54 struct ipc_msg {
55         int chid;
56         void *addr;
57         uint32_t len;
58         uint8_t flags;
59 };
60
61 typedef struct {
62         uint64_t host_phys;
63         uint32_t modem_phys;
64         void    *host_vaddr;
65         uint32_t size;
66 } mem_range_t;
67
68 #define GUL_IPC_MAGIC   'R'
69
70 #define IOCTL_GUL_IPC_GET_SYS_MAP _IOW(GUL_IPC_MAGIC, 1, struct ipc_msg *)
71 #define IOCTL_GUL_IPC_CHANNEL_REGISTER _IOWR(GUL_IPC_MAGIC, 4, struct ipc_msg *)
72 #define IOCTL_GUL_IPC_CHANNEL_DEREGISTER \
73         _IOWR(GUL_IPC_MAGIC, 5, struct ipc_msg *)
74 #define IOCTL_GUL_IPC_CHANNEL_RAISE_INTERRUPT _IOW(GUL_IPC_MAGIC, 6, int *)
75
76 /** buffer ring common metadata */
77 typedef struct ipc_bd_ring_md {
78         volatile uint32_t pi;           /**< Producer index and flag (MSB)
79                                           *  which flip for each Ring wrapping
80                                           */
81         volatile uint32_t ci;           /**< Consumer index and flag (MSB)
82                                           *  which flip for each Ring wrapping
83                                           */
84         uint32_t ring_size;     /**< depth (Used to roll-over pi/ci) */
85         uint32_t msg_size;      /**< Size of the each buffer */
86 } __rte_packed ipc_br_md_t;
87
88 /** IPC buffer descriptor */
89 typedef struct ipc_buffer_desc {
90         union {
91                 uint64_t host_virt;     /**< msg's host virtual address */
92                 struct {
93                         uint32_t host_virt_l;
94                         uint32_t host_virt_h;
95                 };
96         };
97         uint32_t modem_ptr;     /**< msg's modem physical address */
98         uint32_t len;           /**< msg len */
99 } __rte_packed ipc_bd_t;
100
101 typedef struct ipc_channel {
102         uint32_t ch_id;         /**< Channel id */
103         ipc_br_md_t md;                 /**< Metadata for BD ring */
104         ipc_bd_t bd_h[IPC_MAX_DEPTH];   /**< Buffer Descriptor on Host */
105         ipc_bd_t bd_m[IPC_MAX_DEPTH];   /**< Buffer Descriptor on Modem */
106         uint32_t op_type;               /**< Type of the BBDEV operation
107                                           * supported on this channel
108                                           */
109         uint32_t depth;                 /**< Channel depth */
110         uint32_t feca_blk_id;   /**< FECA Transport Block ID for processing */
111         uint32_t la12xx_core_id;/**< LA12xx core ID on which this will be
112                                   * scheduled
113                                   */
114         uint32_t feca_input_circ_size;  /**< FECA transport block input
115                                           * circular buffer size
116                                           */
117         uint32_t host_ipc_params;       /**< Address for host IPC parameters */
118 } __rte_packed ipc_ch_t;
119
120 typedef struct ipc_instance {
121         uint32_t instance_id;           /**< instance id, use to init this
122                                           * instance by ipc_init API
123                                           */
124         uint32_t initialized;           /**< Set in ipc_init */
125         ipc_ch_t ch_list[IPC_MAX_CHANNEL_COUNT];
126                 /**< Channel descriptors in this instance */
127 } __rte_packed ipc_instance_t;
128
129 typedef struct ipc_metadata {
130         uint32_t ipc_host_signature; /**< IPC host signature, Set by host/L2 */
131         uint32_t ipc_geul_signature; /**< IPC geul signature, Set by modem */
132         ipc_instance_t instance_list[IPC_MAX_INSTANCE_COUNT];
133 } __rte_packed ipc_metadata_t;
134
135 typedef struct ipc_channel_us_priv {
136         int32_t         eventfd;
137         uint32_t        channel_id;
138         /* In flight packets status for buffer list. */
139         uint8_t         bufs_inflight[IPC_MAX_DEPTH];
140 } ipc_channel_us_t;
141
142 typedef struct {
143         uint64_t host_phys;
144         uint32_t modem_phys;
145         uint32_t size;
146 } mem_strt_addr_t;
147
148 typedef struct {
149         mem_strt_addr_t modem_ccsrbar;
150         mem_strt_addr_t peb_start; /* PEB meta data */
151         mem_strt_addr_t mhif_start; /* MHIF meta daat */
152         mem_strt_addr_t hugepg_start; /* Modem to access hugepage */
153 } sys_map_t;
154
155 typedef struct ipc_priv_t {
156         int instance_id;
157         int dev_ipc;
158         int dev_mem;
159         sys_map_t sys_map;
160         mem_range_t modem_ccsrbar;
161         mem_range_t peb_start;
162         mem_range_t mhif_start;
163         mem_range_t hugepg_start;
164         ipc_channel_us_t *channels[IPC_MAX_CHANNEL_COUNT];
165         ipc_instance_t  *instance;
166         ipc_instance_t  *instance_bk;
167 } ipc_userspace_t;
168
169 /** Structure specifying enqueue operation (enqueue at LA1224) */
170 struct bbdev_ipc_enqueue_op {
171         /** Status of operation that was performed */
172         int32_t status;
173         /** CRC Status of SD operation that was performed */
174         int32_t crc_stat_addr;
175         /** HARQ Output buffer memory length for Shared Decode.
176          * Filled by LA12xx.
177          */
178         uint32_t out_len;
179         /** Reserved (for 8 byte alignment) */
180         uint32_t rsvd;
181 };
182
183 /* This shared memory would be on the host side which have copy of some
184  * of the parameters which are also part of Shared BD ring. Read access
185  * of these parameters from the host side would not be over PCI.
186  */
187 typedef struct host_ipc_params {
188         volatile uint32_t pi;
189         volatile uint32_t ci;
190         volatile uint32_t bd_m_modem_ptr[IPC_MAX_DEPTH];
191 } __rte_packed host_ipc_params_t;
192
193 struct hif_ipc_regs {
194         uint32_t ipc_mdata_offset;
195         uint32_t ipc_mdata_size;
196 } __rte_packed;
197
198 struct gul_hif {
199         uint32_t ver;
200         uint32_t hif_ver;
201         uint32_t status;
202         volatile uint32_t host_ready;
203         volatile uint32_t mod_ready;
204         struct hif_ipc_regs ipc_regs;
205 } __rte_packed;
206
207 #endif