drivers/octeontx2: fix Coverity warnings
[dpdk.git] / drivers / common / octeontx2 / otx2_mbox.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2019 Marvell International Ltd.
3  */
4
5 #ifndef __OTX2_MBOX_H__
6 #define __OTX2_MBOX_H__
7
8 #include <errno.h>
9 #include <stdbool.h>
10
11 #include <rte_ether.h>
12 #include <rte_spinlock.h>
13
14 #include <otx2_common.h>
15
16 #define SZ_64K                  (64ULL * 1024ULL)
17 #define SZ_1K                   (1ULL * 1024ULL)
18 #define MBOX_SIZE               SZ_64K
19
20 /* AF/PF: PF initiated, PF/VF VF initiated */
21 #define MBOX_DOWN_RX_START      0
22 #define MBOX_DOWN_RX_SIZE       (46 * SZ_1K)
23 #define MBOX_DOWN_TX_START      (MBOX_DOWN_RX_START + MBOX_DOWN_RX_SIZE)
24 #define MBOX_DOWN_TX_SIZE       (16 * SZ_1K)
25 /* AF/PF: AF initiated, PF/VF PF initiated */
26 #define MBOX_UP_RX_START        (MBOX_DOWN_TX_START + MBOX_DOWN_TX_SIZE)
27 #define MBOX_UP_RX_SIZE         SZ_1K
28 #define MBOX_UP_TX_START        (MBOX_UP_RX_START + MBOX_UP_RX_SIZE)
29 #define MBOX_UP_TX_SIZE         SZ_1K
30
31 #if MBOX_UP_TX_SIZE + MBOX_UP_TX_START != MBOX_SIZE
32 # error "Incorrect mailbox area sizes"
33 #endif
34
35 #define INTR_MASK(pfvfs) ((pfvfs < 64) ? (BIT_ULL(pfvfs) - 1) : (~0ull))
36
37 #define MBOX_RSP_TIMEOUT        3000 /* Time to wait for mbox response in ms */
38
39 #define MBOX_MSG_ALIGN          16  /* Align mbox msg start to 16bytes */
40
41 /* Mailbox directions */
42 #define MBOX_DIR_AFPF           0  /* AF replies to PF */
43 #define MBOX_DIR_PFAF           1  /* PF sends messages to AF */
44 #define MBOX_DIR_PFVF           2  /* PF replies to VF */
45 #define MBOX_DIR_VFPF           3  /* VF sends messages to PF */
46 #define MBOX_DIR_AFPF_UP        4  /* AF sends messages to PF */
47 #define MBOX_DIR_PFAF_UP        5  /* PF replies to AF */
48 #define MBOX_DIR_PFVF_UP        6  /* PF sends messages to VF */
49 #define MBOX_DIR_VFPF_UP        7  /* VF replies to PF */
50
51 /* Device memory does not support unaligned access, instruct compiler to
52  * not optimize the memory access when working with mailbox memory.
53  */
54 #define __otx2_io volatile
55
56 struct otx2_mbox_dev {
57         void        *mbase;   /* This dev's mbox region */
58         rte_spinlock_t  mbox_lock;
59         uint16_t     msg_size; /* Total msg size to be sent */
60         uint16_t     rsp_size; /* Total rsp size to be sure the reply is ok */
61         uint16_t     num_msgs; /* No of msgs sent or waiting for response */
62         uint16_t     msgs_acked; /* No of msgs for which response is received */
63 };
64
65 struct otx2_mbox {
66         uintptr_t hwbase;  /* Mbox region advertised by HW */
67         uintptr_t reg_base;/* CSR base for this dev */
68         uint64_t trigger;  /* Trigger mbox notification */
69         uint16_t tr_shift; /* Mbox trigger shift */
70         uint64_t rx_start; /* Offset of Rx region in mbox memory */
71         uint64_t tx_start; /* Offset of Tx region in mbox memory */
72         uint16_t rx_size;  /* Size of Rx region */
73         uint16_t tx_size;  /* Size of Tx region */
74         uint16_t ndevs;    /* The number of peers */
75         struct otx2_mbox_dev *dev;
76 };
77
78 /* Header which precedes all mbox messages */
79 struct mbox_hdr {
80         uint64_t __otx2_io msg_size;   /* Total msgs size embedded */
81         uint16_t __otx2_io num_msgs;   /* No of msgs embedded */
82 };
83
84 /* Header which precedes every msg and is also part of it */
85 struct mbox_msghdr {
86         uint16_t __otx2_io pcifunc; /* Who's sending this msg */
87         uint16_t __otx2_io id;      /* Mbox message ID */
88 #define OTX2_MBOX_REQ_SIG (0xdead)
89 #define OTX2_MBOX_RSP_SIG (0xbeef)
90         /* Signature, for validating corrupted msgs */
91         uint16_t __otx2_io sig;
92 #define OTX2_MBOX_VERSION (0x0001)
93         /* Version of msg's structure for this ID */
94         uint16_t __otx2_io ver;
95         /* Offset of next msg within mailbox region */
96         uint16_t __otx2_io next_msgoff;
97         int __otx2_io rc; /* Msg processed response code */
98 };
99
100 /* Mailbox message types */
101 #define MBOX_MSG_MASK                           0xFFFF
102 #define MBOX_MSG_INVALID                        0xFFFE
103 #define MBOX_MSG_MAX                            0xFFFF
104
105 #define MBOX_MESSAGES                                                   \
106 /* Generic mbox IDs (range 0x000 - 0x1FF) */                            \
107 M(READY,                0x001, ready, msg_req, ready_msg_rsp)           \
108 M(ATTACH_RESOURCES,     0x002, attach_resources, rsrc_attach_req, msg_rsp)\
109 M(DETACH_RESOURCES,     0x003, detach_resources, rsrc_detach_req, msg_rsp)\
110 M(FREE_RSRC_CNT,        0x004, free_rsrc_cnt, msg_req, free_rsrcs_rsp)  \
111 M(MSIX_OFFSET,          0x005, msix_offset, msg_req, msix_offset_rsp)   \
112 M(VF_FLR,               0x006, vf_flr, msg_req, msg_rsp)                \
113 M(PTP_OP,               0x007, ptp_op, ptp_req, ptp_rsp)                \
114 M(GET_HW_CAP,           0x008, get_hw_cap, msg_req, get_hw_cap_rsp)     \
115 M(NDC_SYNC_OP,          0x009, ndc_sync_op, ndc_sync_op, msg_rsp)       \
116 /* CGX mbox IDs (range 0x200 - 0x3FF) */                                \
117 M(CGX_START_RXTX,       0x200, cgx_start_rxtx, msg_req, msg_rsp)        \
118 M(CGX_STOP_RXTX,        0x201, cgx_stop_rxtx, msg_req, msg_rsp)         \
119 M(CGX_STATS,            0x202, cgx_stats, msg_req, cgx_stats_rsp)       \
120 M(CGX_MAC_ADDR_SET,     0x203, cgx_mac_addr_set, cgx_mac_addr_set_or_get,\
121                                 cgx_mac_addr_set_or_get)                \
122 M(CGX_MAC_ADDR_GET,     0x204, cgx_mac_addr_get, cgx_mac_addr_set_or_get,\
123                                 cgx_mac_addr_set_or_get)                \
124 M(CGX_PROMISC_ENABLE,   0x205, cgx_promisc_enable, msg_req, msg_rsp)    \
125 M(CGX_PROMISC_DISABLE,  0x206, cgx_promisc_disable, msg_req, msg_rsp)   \
126 M(CGX_START_LINKEVENTS, 0x207, cgx_start_linkevents, msg_req, msg_rsp)  \
127 M(CGX_STOP_LINKEVENTS,  0x208, cgx_stop_linkevents, msg_req, msg_rsp)   \
128 M(CGX_GET_LINKINFO,     0x209, cgx_get_linkinfo, msg_req, cgx_link_info_msg)\
129 M(CGX_INTLBK_ENABLE,    0x20A, cgx_intlbk_enable, msg_req, msg_rsp)     \
130 M(CGX_INTLBK_DISABLE,   0x20B, cgx_intlbk_disable, msg_req, msg_rsp)    \
131 M(CGX_PTP_RX_ENABLE,    0x20C, cgx_ptp_rx_enable, msg_req, msg_rsp)     \
132 M(CGX_PTP_RX_DISABLE,   0x20D, cgx_ptp_rx_disable, msg_req, msg_rsp)    \
133 M(CGX_CFG_PAUSE_FRM,    0x20E, cgx_cfg_pause_frm, cgx_pause_frm_cfg,    \
134                                 cgx_pause_frm_cfg)                      \
135 M(CGX_FW_DATA_GET,      0x20F, cgx_get_aux_link_info, msg_req, cgx_fw_data) \
136 M(CGX_MAC_ADDR_ADD,     0x211, cgx_mac_addr_add, cgx_mac_addr_add_req,  \
137                                 cgx_mac_addr_add_rsp)                   \
138 M(CGX_MAC_ADDR_DEL,     0x212, cgx_mac_addr_del, cgx_mac_addr_del_req,  \
139                                 msg_rsp)                                \
140 M(CGX_MAC_MAX_ENTRIES_GET, 0x213, cgx_mac_max_entries_get, msg_req,     \
141                                  cgx_max_dmac_entries_get_rsp)          \
142 M(CGX_SET_LINK_STATE,   0x214, cgx_set_link_state,              \
143                         cgx_set_link_state_msg, msg_rsp)                \
144 /* NPA mbox IDs (range 0x400 - 0x5FF) */                                \
145 M(NPA_LF_ALLOC,         0x400, npa_lf_alloc, npa_lf_alloc_req,          \
146                                 npa_lf_alloc_rsp)                       \
147 M(NPA_LF_FREE,          0x401, npa_lf_free, msg_req, msg_rsp)           \
148 M(NPA_AQ_ENQ,           0x402, npa_aq_enq, npa_aq_enq_req, npa_aq_enq_rsp)\
149 M(NPA_HWCTX_DISABLE,    0x403, npa_hwctx_disable, hwctx_disable_req, msg_rsp)\
150 /* SSO/SSOW mbox IDs (range 0x600 - 0x7FF) */                           \
151 M(SSO_LF_ALLOC,         0x600, sso_lf_alloc, sso_lf_alloc_req,          \
152                                 sso_lf_alloc_rsp)                       \
153 M(SSO_LF_FREE,          0x601, sso_lf_free, sso_lf_free_req, msg_rsp)   \
154 M(SSOW_LF_ALLOC,        0x602, ssow_lf_alloc, ssow_lf_alloc_req, msg_rsp)\
155 M(SSOW_LF_FREE,         0x603, ssow_lf_free, ssow_lf_free_req, msg_rsp) \
156 M(SSO_HW_SETCONFIG,     0x604, sso_hw_setconfig, sso_hw_setconfig,      \
157                                 msg_rsp)                                \
158 M(SSO_GRP_SET_PRIORITY, 0x605, sso_grp_set_priority, sso_grp_priority,  \
159                                 msg_rsp)                                \
160 M(SSO_GRP_GET_PRIORITY, 0x606, sso_grp_get_priority, sso_info_req,      \
161                                 sso_grp_priority)                       \
162 M(SSO_WS_CACHE_INV,     0x607, sso_ws_cache_inv, msg_req, msg_rsp)      \
163 M(SSO_GRP_QOS_CONFIG,   0x608, sso_grp_qos_config, sso_grp_qos_cfg,     \
164                                 msg_rsp)                                \
165 M(SSO_GRP_GET_STATS,    0x609, sso_grp_get_stats, sso_info_req,         \
166                                 sso_grp_stats)                          \
167 M(SSO_HWS_GET_STATS,    0x610, sso_hws_get_stats, sso_info_req,         \
168                                 sso_hws_stats)                          \
169 /* TIM mbox IDs (range 0x800 - 0x9FF) */                                \
170 M(TIM_LF_ALLOC,         0x800, tim_lf_alloc, tim_lf_alloc_req,          \
171                                 tim_lf_alloc_rsp)                       \
172 M(TIM_LF_FREE,          0x801, tim_lf_free, tim_ring_req, msg_rsp)      \
173 M(TIM_CONFIG_RING,      0x802, tim_config_ring, tim_config_req, msg_rsp)\
174 M(TIM_ENABLE_RING,      0x803, tim_enable_ring, tim_ring_req,           \
175                                 tim_enable_rsp)                         \
176 M(TIM_DISABLE_RING,     0x804, tim_disable_ring, tim_ring_req, msg_rsp) \
177 /* CPT mbox IDs (range 0xA00 - 0xBFF) */                                \
178 M(CPT_RD_WR_REGISTER,   0xA02, cpt_rd_wr_register, cpt_rd_wr_reg_msg,   \
179                                cpt_rd_wr_reg_msg)                       \
180 M(CPT_INLINE_IPSEC_CFG, 0xA04, cpt_inline_ipsec_cfg,                    \
181                                cpt_inline_ipsec_cfg_msg, msg_rsp)       \
182 /* NPC mbox IDs (range 0x6000 - 0x7FFF) */                              \
183 M(NPC_MCAM_ALLOC_ENTRY, 0x6000, npc_mcam_alloc_entry,                   \
184                                 npc_mcam_alloc_entry_req,               \
185                                 npc_mcam_alloc_entry_rsp)               \
186 M(NPC_MCAM_FREE_ENTRY,  0x6001, npc_mcam_free_entry,                    \
187                                 npc_mcam_free_entry_req, msg_rsp)       \
188 M(NPC_MCAM_WRITE_ENTRY, 0x6002, npc_mcam_write_entry,                   \
189                                 npc_mcam_write_entry_req, msg_rsp)      \
190 M(NPC_MCAM_ENA_ENTRY,   0x6003, npc_mcam_ena_entry,                     \
191                                 npc_mcam_ena_dis_entry_req, msg_rsp)    \
192 M(NPC_MCAM_DIS_ENTRY,   0x6004, npc_mcam_dis_entry,                     \
193                                 npc_mcam_ena_dis_entry_req, msg_rsp)    \
194 M(NPC_MCAM_SHIFT_ENTRY, 0x6005, npc_mcam_shift_entry,                   \
195                                 npc_mcam_shift_entry_req,               \
196                                 npc_mcam_shift_entry_rsp)               \
197 M(NPC_MCAM_ALLOC_COUNTER,       0x6006, npc_mcam_alloc_counter,         \
198                                 npc_mcam_alloc_counter_req,             \
199                                 npc_mcam_alloc_counter_rsp)             \
200 M(NPC_MCAM_FREE_COUNTER,        0x6007, npc_mcam_free_counter,          \
201                                 npc_mcam_oper_counter_req,              \
202                                 msg_rsp)                                \
203 M(NPC_MCAM_UNMAP_COUNTER,       0x6008, npc_mcam_unmap_counter,         \
204                                 npc_mcam_unmap_counter_req,             \
205                                 msg_rsp)                                \
206 M(NPC_MCAM_CLEAR_COUNTER,       0x6009, npc_mcam_clear_counter,         \
207                                 npc_mcam_oper_counter_req,              \
208                                 msg_rsp)                                \
209 M(NPC_MCAM_COUNTER_STATS,       0x600a, npc_mcam_counter_stats,         \
210                                 npc_mcam_oper_counter_req,              \
211                                 npc_mcam_oper_counter_rsp)              \
212 M(NPC_MCAM_ALLOC_AND_WRITE_ENTRY, 0x600b, npc_mcam_alloc_and_write_entry,\
213                                 npc_mcam_alloc_and_write_entry_req,     \
214                                 npc_mcam_alloc_and_write_entry_rsp)     \
215 M(NPC_GET_KEX_CFG,        0x600c, npc_get_kex_cfg, msg_req,             \
216                                 npc_get_kex_cfg_rsp)                    \
217 M(NPC_INSTALL_FLOW,       0x600d, npc_install_flow,                     \
218                                   npc_install_flow_req,                 \
219                                   npc_install_flow_rsp)                 \
220 M(NPC_DELETE_FLOW,        0x600e, npc_delete_flow,                      \
221                                   npc_delete_flow_req, msg_rsp)         \
222 M(NPC_MCAM_READ_ENTRY,    0x600f, npc_mcam_read_entry,                  \
223                                   npc_mcam_read_entry_req,              \
224                                   npc_mcam_read_entry_rsp)              \
225 /* NIX mbox IDs (range 0x8000 - 0xFFFF) */                              \
226 M(NIX_LF_ALLOC,         0x8000, nix_lf_alloc, nix_lf_alloc_req,         \
227                                 nix_lf_alloc_rsp)                       \
228 M(NIX_LF_FREE,          0x8001, nix_lf_free, nix_lf_free_req, msg_rsp)  \
229 M(NIX_AQ_ENQ,           0x8002, nix_aq_enq, nix_aq_enq_req,             \
230                                 nix_aq_enq_rsp)                         \
231 M(NIX_HWCTX_DISABLE,    0x8003, nix_hwctx_disable, hwctx_disable_req,   \
232                                 msg_rsp)                                \
233 M(NIX_TXSCH_ALLOC,      0x8004, nix_txsch_alloc, nix_txsch_alloc_req,   \
234                                 nix_txsch_alloc_rsp)                    \
235 M(NIX_TXSCH_FREE,       0x8005, nix_txsch_free, nix_txsch_free_req,     \
236                                 msg_rsp)                                \
237 M(NIX_TXSCHQ_CFG,       0x8006, nix_txschq_cfg, nix_txschq_config,      \
238                                 msg_rsp)                                \
239 M(NIX_STATS_RST,        0x8007, nix_stats_rst, msg_req, msg_rsp)        \
240 M(NIX_VTAG_CFG,         0x8008, nix_vtag_cfg, nix_vtag_config, msg_rsp) \
241 M(NIX_RSS_FLOWKEY_CFG,  0x8009, nix_rss_flowkey_cfg,                    \
242                                 nix_rss_flowkey_cfg,                    \
243                                 nix_rss_flowkey_cfg_rsp)                \
244 M(NIX_SET_MAC_ADDR,     0x800a, nix_set_mac_addr, nix_set_mac_addr,     \
245                                 msg_rsp)                                \
246 M(NIX_SET_RX_MODE,      0x800b, nix_set_rx_mode, nix_rx_mode, msg_rsp)  \
247 M(NIX_SET_HW_FRS,       0x800c, nix_set_hw_frs, nix_frs_cfg, msg_rsp)   \
248 M(NIX_LF_START_RX,      0x800d, nix_lf_start_rx, msg_req, msg_rsp)      \
249 M(NIX_LF_STOP_RX,       0x800e, nix_lf_stop_rx, msg_req, msg_rsp)       \
250 M(NIX_MARK_FORMAT_CFG,  0x800f, nix_mark_format_cfg,                    \
251                                 nix_mark_format_cfg,                    \
252                                 nix_mark_format_cfg_rsp)                \
253 M(NIX_LSO_FORMAT_CFG,   0x8011, nix_lso_format_cfg, nix_lso_format_cfg, \
254                                 nix_lso_format_cfg_rsp)                 \
255 M(NIX_LF_PTP_TX_ENABLE, 0x8013, nix_lf_ptp_tx_enable, msg_req,          \
256                                 msg_rsp)                                \
257 M(NIX_LF_PTP_TX_DISABLE,        0x8014, nix_lf_ptp_tx_disable, msg_req, \
258                                 msg_rsp)                                \
259 M(NIX_SET_VLAN_TPID,    0x8015, nix_set_vlan_tpid, nix_set_vlan_tpid,   \
260                                 msg_rsp)                                \
261 M(NIX_BP_ENABLE,        0x8016, nix_bp_enable, nix_bp_cfg_req,          \
262                                 nix_bp_cfg_rsp)                         \
263 M(NIX_BP_DISABLE,       0x8017, nix_bp_disable, nix_bp_cfg_req, msg_rsp)\
264 M(NIX_GET_MAC_ADDR,     0x8018, nix_get_mac_addr, msg_req,              \
265                                 nix_get_mac_addr_rsp)                   \
266 M(NIX_INLINE_IPSEC_CFG, 0x8019, nix_inline_ipsec_cfg,                   \
267                                 nix_inline_ipsec_cfg, msg_rsp)          \
268 M(NIX_INLINE_IPSEC_LF_CFG,                                              \
269                         0x801a, nix_inline_ipsec_lf_cfg,                \
270                                 nix_inline_ipsec_lf_cfg, msg_rsp)
271
272 /* Messages initiated by AF (range 0xC00 - 0xDFF) */
273 #define MBOX_UP_CGX_MESSAGES                                            \
274 M(CGX_LINK_EVENT,       0xC00, cgx_link_event, cgx_link_info_msg,       \
275                                 msg_rsp)                                \
276 M(CGX_PTP_RX_INFO,      0xC01, cgx_ptp_rx_info, cgx_ptp_rx_info_msg,    \
277                                 msg_rsp)
278
279 enum {
280 #define M(_name, _id, _1, _2, _3) MBOX_MSG_ ## _name = _id,
281 MBOX_MESSAGES
282 MBOX_UP_CGX_MESSAGES
283 #undef M
284 };
285
286 /* Mailbox message formats */
287
288 #define RVU_DEFAULT_PF_FUNC     0xFFFF
289
290 /* Generic request msg used for those mbox messages which
291  * don't send any data in the request.
292  */
293 struct msg_req {
294         struct mbox_msghdr hdr;
295 };
296
297 /* Generic response msg used a ack or response for those mbox
298  * messages which doesn't have a specific rsp msg format.
299  */
300 struct msg_rsp {
301         struct mbox_msghdr hdr;
302 };
303
304 /* RVU mailbox error codes
305  * Range 256 - 300.
306  */
307 enum rvu_af_status {
308         RVU_INVALID_VF_ID           = -256,
309 };
310
311 struct ready_msg_rsp {
312         struct mbox_msghdr hdr;
313         uint16_t __otx2_io sclk_feq; /* SCLK frequency */
314         uint16_t __otx2_io rclk_freq; /* RCLK frequency */
315 };
316
317 /* Structure for requesting resource provisioning.
318  * 'modify' flag to be used when either requesting more
319  * or detach partial of a certain resource type.
320  * Rest of the fields specify how many of what type to
321  * be attached.
322  */
323 struct rsrc_attach_req {
324         struct mbox_msghdr hdr;
325         uint8_t __otx2_io modify:1;
326         uint8_t __otx2_io npalf:1;
327         uint8_t __otx2_io nixlf:1;
328         uint16_t __otx2_io sso;
329         uint16_t __otx2_io ssow;
330         uint16_t __otx2_io timlfs;
331         uint16_t __otx2_io cptlfs;
332 };
333
334 /* Structure for relinquishing resources.
335  * 'partial' flag to be used when relinquishing all resources
336  * but only of a certain type. If not set, all resources of all
337  * types provisioned to the RVU function will be detached.
338  */
339 struct rsrc_detach_req {
340         struct mbox_msghdr hdr;
341         uint8_t __otx2_io partial:1;
342         uint8_t __otx2_io npalf:1;
343         uint8_t __otx2_io nixlf:1;
344         uint8_t __otx2_io sso:1;
345         uint8_t __otx2_io ssow:1;
346         uint8_t __otx2_io timlfs:1;
347         uint8_t __otx2_io cptlfs:1;
348 };
349
350 /* NIX Transmit schedulers */
351 #define NIX_TXSCH_LVL_SMQ 0x0
352 #define NIX_TXSCH_LVL_MDQ 0x0
353 #define NIX_TXSCH_LVL_TL4 0x1
354 #define NIX_TXSCH_LVL_TL3 0x2
355 #define NIX_TXSCH_LVL_TL2 0x3
356 #define NIX_TXSCH_LVL_TL1 0x4
357 #define NIX_TXSCH_LVL_CNT 0x5
358
359 /*
360  * Number of resources available to the caller.
361  * In reply to MBOX_MSG_FREE_RSRC_CNT.
362  */
363 struct free_rsrcs_rsp {
364         struct mbox_msghdr hdr;
365         uint16_t __otx2_io schq[NIX_TXSCH_LVL_CNT];
366         uint16_t __otx2_io sso;
367         uint16_t __otx2_io tim;
368         uint16_t __otx2_io ssow;
369         uint16_t __otx2_io cpt;
370         uint8_t __otx2_io npa;
371         uint8_t __otx2_io nix;
372 };
373
374 #define MSIX_VECTOR_INVALID     0xFFFF
375 #define MAX_RVU_BLKLF_CNT       256
376
377 struct msix_offset_rsp {
378         struct mbox_msghdr hdr;
379         uint16_t __otx2_io npa_msixoff;
380         uint16_t __otx2_io nix_msixoff;
381         uint8_t __otx2_io sso;
382         uint8_t __otx2_io ssow;
383         uint8_t __otx2_io timlfs;
384         uint8_t __otx2_io cptlfs;
385         uint16_t __otx2_io sso_msixoff[MAX_RVU_BLKLF_CNT];
386         uint16_t __otx2_io ssow_msixoff[MAX_RVU_BLKLF_CNT];
387         uint16_t __otx2_io timlf_msixoff[MAX_RVU_BLKLF_CNT];
388         uint16_t __otx2_io cptlf_msixoff[MAX_RVU_BLKLF_CNT];
389 };
390
391 /* CGX mbox message formats */
392 struct cgx_stats_rsp {
393         struct mbox_msghdr hdr;
394 #define CGX_RX_STATS_COUNT      13
395 #define CGX_TX_STATS_COUNT      18
396         uint64_t __otx2_io rx_stats[CGX_RX_STATS_COUNT];
397         uint64_t __otx2_io tx_stats[CGX_TX_STATS_COUNT];
398 };
399
400 /* Structure for requesting the operation for
401  * setting/getting mac address in the CGX interface
402  */
403 struct cgx_mac_addr_set_or_get {
404         struct mbox_msghdr hdr;
405         uint8_t __otx2_io mac_addr[RTE_ETHER_ADDR_LEN];
406 };
407
408 /* Structure for requesting the operation to
409  * add DMAC filter entry into CGX interface
410  */
411 struct cgx_mac_addr_add_req {
412         struct mbox_msghdr hdr;
413         uint8_t __otx2_io mac_addr[RTE_ETHER_ADDR_LEN];
414 };
415
416 /* Structure for response against the operation to
417  * add DMAC filter entry into CGX interface
418  */
419 struct cgx_mac_addr_add_rsp {
420         struct mbox_msghdr hdr;
421         uint8_t __otx2_io index;
422 };
423
424 /* Structure for requesting the operation to
425  * delete DMAC filter entry from CGX interface
426  */
427 struct cgx_mac_addr_del_req {
428         struct mbox_msghdr hdr;
429         uint8_t __otx2_io index;
430 };
431
432 /* Structure for response against the operation to
433  * get maximum supported DMAC filter entries
434  */
435 struct cgx_max_dmac_entries_get_rsp {
436         struct mbox_msghdr hdr;
437         uint8_t __otx2_io max_dmac_filters;
438 };
439
440 struct cgx_link_user_info {
441         uint64_t __otx2_io link_up:1;
442         uint64_t __otx2_io full_duplex:1;
443         uint64_t __otx2_io lmac_type_id:4;
444         uint64_t __otx2_io speed:20; /* speed in Mbps */
445 #define LMACTYPE_STR_LEN 16
446         char lmac_type[LMACTYPE_STR_LEN];
447 };
448
449 struct cgx_link_info_msg {
450         struct mbox_msghdr hdr;
451         struct cgx_link_user_info link_info;
452 };
453
454 struct cgx_pause_frm_cfg {
455         struct mbox_msghdr hdr;
456         uint8_t __otx2_io set;
457         /* set = 1 if the request is to config pause frames */
458         /* set = 0 if the request is to fetch pause frames config */
459         uint8_t __otx2_io rx_pause;
460         uint8_t __otx2_io tx_pause;
461 };
462
463 struct cgx_ptp_rx_info_msg {
464         struct mbox_msghdr hdr;
465         uint8_t __otx2_io ptp_en;
466         uint8_t __otx2_io ptp_offset;
467 };
468
469 struct sfp_eeprom_s {
470 #define SFP_EEPROM_SIZE 256
471         uint16_t __otx2_io sff_id;
472         uint8_t __otx2_io buf[SFP_EEPROM_SIZE];
473 };
474
475 struct cgx_lmac_fwdata_s {
476         uint16_t __otx2_io rw_valid;
477         uint64_t __otx2_io supported_fec;
478         uint64_t __otx2_io supported_an;
479         uint64_t __otx2_io supported_link_modes;
480         /* Only applicable if AN is supported */
481         uint64_t __otx2_io advertised_fec;
482         uint64_t __otx2_io advertised_link_modes;
483         /* Only applicable if SFP/QSFP slot is present */
484         struct sfp_eeprom_s sfp_eeprom;
485 };
486
487 struct cgx_fw_data {
488         struct mbox_msghdr hdr;
489         struct cgx_lmac_fwdata_s fwdata;
490 };
491
492 struct cgx_set_link_state_msg {
493         struct mbox_msghdr hdr;
494         uint8_t __otx2_io enable;
495 };
496
497 /* NPA mbox message formats */
498
499 /* NPA mailbox error codes
500  * Range 301 - 400.
501  */
502 enum npa_af_status {
503         NPA_AF_ERR_PARAM            = -301,
504         NPA_AF_ERR_AQ_FULL          = -302,
505         NPA_AF_ERR_AQ_ENQUEUE       = -303,
506         NPA_AF_ERR_AF_LF_INVALID    = -304,
507         NPA_AF_ERR_AF_LF_ALLOC      = -305,
508         NIX_AF_ERR_X2P_CALIBRATE    = -398,
509         NIX_AF_ERR_RAN_OUT_BPID     = -399,
510 };
511
512 #define NPA_AURA_SZ_0           0
513 #define NPA_AURA_SZ_128         1
514 #define NPA_AURA_SZ_256         2
515 #define NPA_AURA_SZ_512         3
516 #define NPA_AURA_SZ_1K          4
517 #define NPA_AURA_SZ_2K          5
518 #define NPA_AURA_SZ_4K          6
519 #define NPA_AURA_SZ_8K          7
520 #define NPA_AURA_SZ_16K         8
521 #define NPA_AURA_SZ_32K         9
522 #define NPA_AURA_SZ_64K         10
523 #define NPA_AURA_SZ_128K        11
524 #define NPA_AURA_SZ_256K        12
525 #define NPA_AURA_SZ_512K        13
526 #define NPA_AURA_SZ_1M          14
527 #define NPA_AURA_SZ_MAX         15
528
529 /* For NPA LF context alloc and init */
530 struct npa_lf_alloc_req {
531         struct mbox_msghdr hdr;
532         int __otx2_io node;
533         int __otx2_io aura_sz; /* No of auras. See NPA_AURA_SZ_* */
534         uint32_t __otx2_io nr_pools; /* No of pools */
535         uint64_t __otx2_io way_mask;
536 };
537
538 struct npa_lf_alloc_rsp {
539         struct mbox_msghdr hdr;
540         uint32_t __otx2_io stack_pg_ptrs;  /* No of ptrs per stack page */
541         uint32_t __otx2_io stack_pg_bytes; /* Size of stack page */
542         uint16_t __otx2_io qints; /* NPA_AF_CONST::QINTS */
543 };
544
545 /* NPA AQ enqueue msg */
546 struct npa_aq_enq_req {
547         struct mbox_msghdr hdr;
548         uint32_t __otx2_io aura_id;
549         uint8_t __otx2_io ctype;
550         uint8_t __otx2_io op;
551         union {
552                 /* Valid when op == WRITE/INIT and ctype == AURA.
553                  * LF fills the pool_id in aura.pool_addr. AF will translate
554                  * the pool_id to pool context pointer.
555                  */
556                 struct npa_aura_s aura;
557                 /* Valid when op == WRITE/INIT and ctype == POOL */
558                 struct npa_pool_s pool;
559         };
560         /* Mask data when op == WRITE (1=write, 0=don't write) */
561         union {
562                 /* Valid when op == WRITE and ctype == AURA */
563                 struct npa_aura_s aura_mask;
564                 /* Valid when op == WRITE and ctype == POOL */
565                 struct npa_pool_s pool_mask;
566         };
567 };
568
569 struct npa_aq_enq_rsp {
570         struct mbox_msghdr hdr;
571         union {
572                 /* Valid when op == READ and ctype == AURA */
573                 struct npa_aura_s aura;
574                 /* Valid when op == READ and ctype == POOL */
575                 struct npa_pool_s pool;
576         };
577 };
578
579 /* Disable all contexts of type 'ctype' */
580 struct hwctx_disable_req {
581         struct mbox_msghdr hdr;
582         uint8_t __otx2_io ctype;
583 };
584
585 /* NIX mbox message formats */
586 /* NIX mailbox error codes
587  * Range 401 - 500.
588  */
589 enum nix_af_status {
590         NIX_AF_ERR_PARAM            = -401,
591         NIX_AF_ERR_AQ_FULL          = -402,
592         NIX_AF_ERR_AQ_ENQUEUE       = -403,
593         NIX_AF_ERR_AF_LF_INVALID    = -404,
594         NIX_AF_ERR_AF_LF_ALLOC      = -405,
595         NIX_AF_ERR_TLX_ALLOC_FAIL   = -406,
596         NIX_AF_ERR_TLX_INVALID      = -407,
597         NIX_AF_ERR_RSS_SIZE_INVALID = -408,
598         NIX_AF_ERR_RSS_GRPS_INVALID = -409,
599         NIX_AF_ERR_FRS_INVALID      = -410,
600         NIX_AF_ERR_RX_LINK_INVALID  = -411,
601         NIX_AF_INVAL_TXSCHQ_CFG     = -412,
602         NIX_AF_SMQ_FLUSH_FAILED     = -413,
603         NIX_AF_MACADDR_SET_FAILED   = -414,
604         NIX_AF_RX_MODE_SET_FAILED   = -415,
605         NIX_AF_ERR_RSS_NOSPC_ALGO   = -416,
606         NIX_AF_ERR_RSS_NOSPC_FIELD  = -417,
607         NIX_AF_ERR_MARK_ALLOC_FAIL  = -418,
608         NIX_AF_ERR_LSOFMT_CFG_FAIL  = -419,
609 };
610
611 /* For NIX LF context alloc and init */
612 struct nix_lf_alloc_req {
613         struct mbox_msghdr hdr;
614         int __otx2_io node;
615         uint32_t __otx2_io rq_cnt;   /* No of receive queues */
616         uint32_t __otx2_io sq_cnt;   /* No of send queues */
617         uint32_t __otx2_io cq_cnt;   /* No of completion queues */
618         uint8_t __otx2_io xqe_sz;
619         uint16_t __otx2_io rss_sz;
620         uint8_t __otx2_io rss_grps;
621         uint16_t __otx2_io npa_func;
622         /* RVU_DEFAULT_PF_FUNC == default pf_func associated with lf */
623         uint16_t __otx2_io sso_func;
624         uint64_t __otx2_io rx_cfg;   /* See NIX_AF_LF(0..127)_RX_CFG */
625         uint64_t __otx2_io way_mask;
626 };
627
628 struct nix_lf_alloc_rsp {
629         struct mbox_msghdr hdr;
630         uint16_t __otx2_io sqb_size;
631         uint16_t __otx2_io rx_chan_base;
632         uint16_t __otx2_io tx_chan_base;
633         uint8_t __otx2_io rx_chan_cnt; /* Total number of RX channels */
634         uint8_t __otx2_io tx_chan_cnt; /* Total number of TX channels */
635         uint8_t __otx2_io lso_tsov4_idx;
636         uint8_t __otx2_io lso_tsov6_idx;
637         uint8_t __otx2_io mac_addr[RTE_ETHER_ADDR_LEN];
638         uint8_t __otx2_io lf_rx_stats; /* NIX_AF_CONST1::LF_RX_STATS */
639         uint8_t __otx2_io lf_tx_stats; /* NIX_AF_CONST1::LF_TX_STATS */
640         uint16_t __otx2_io cints; /* NIX_AF_CONST2::CINTS */
641         uint16_t __otx2_io qints; /* NIX_AF_CONST2::QINTS */
642         uint8_t __otx2_io ptp; /* boolean; true iff PTP block is supported */
643 };
644
645 struct nix_lf_free_req {
646         struct mbox_msghdr hdr;
647 #define NIX_LF_DISABLE_FLOWS   0x1
648         uint64_t __otx2_io flags;
649 };
650
651 /* NIX AQ enqueue msg */
652 struct nix_aq_enq_req {
653         struct mbox_msghdr hdr;
654         uint32_t __otx2_io qidx;
655         uint8_t __otx2_io ctype;
656         uint8_t __otx2_io op;
657         union {
658                 /* Valid when op == WRITE/INIT and ctype == NIX_AQ_CTYPE_RQ */
659                 struct nix_rq_ctx_s rq;
660                 /* Valid when op == WRITE/INIT and ctype == NIX_AQ_CTYPE_SQ */
661                 struct nix_sq_ctx_s sq;
662                 /* Valid when op == WRITE/INIT and ctype == NIX_AQ_CTYPE_CQ */
663                 struct nix_cq_ctx_s cq;
664                 /* Valid when op == WRITE/INIT and ctype == NIX_AQ_CTYPE_RSS */
665                 struct nix_rsse_s rss;
666                 /* Valid when op == WRITE/INIT and ctype == NIX_AQ_CTYPE_MCE */
667                 struct nix_rx_mce_s mce;
668         };
669         /* Mask data when op == WRITE (1=write, 0=don't write) */
670         union {
671                 /* Valid when op == WRITE and ctype == NIX_AQ_CTYPE_RQ */
672                 struct nix_rq_ctx_s rq_mask;
673                 /* Valid when op == WRITE and ctype == NIX_AQ_CTYPE_SQ */
674                 struct nix_sq_ctx_s sq_mask;
675                 /* Valid when op == WRITE and ctype == NIX_AQ_CTYPE_CQ */
676                 struct nix_cq_ctx_s cq_mask;
677                 /* Valid when op == WRITE and ctype == NIX_AQ_CTYPE_RSS */
678                 struct nix_rsse_s rss_mask;
679                 /* Valid when op == WRITE and ctype == NIX_AQ_CTYPE_MCE */
680                 struct nix_rx_mce_s mce_mask;
681         };
682 };
683
684 struct nix_aq_enq_rsp {
685         struct mbox_msghdr hdr;
686         union {
687                 struct nix_rq_ctx_s rq;
688                 struct nix_sq_ctx_s sq;
689                 struct nix_cq_ctx_s cq;
690                 struct nix_rsse_s   rss;
691                 struct nix_rx_mce_s mce;
692         };
693 };
694
695 /* Tx scheduler/shaper mailbox messages */
696
697 #define MAX_TXSCHQ_PER_FUNC     128
698
699 struct nix_txsch_alloc_req {
700         struct mbox_msghdr hdr;
701         /* Scheduler queue count request at each level */
702         uint16_t __otx2_io schq_contig[NIX_TXSCH_LVL_CNT]; /* Contig. queues */
703         uint16_t __otx2_io schq[NIX_TXSCH_LVL_CNT]; /* Non-Contig. queues */
704 };
705
706 struct nix_txsch_alloc_rsp {
707         struct mbox_msghdr hdr;
708         /* Scheduler queue count allocated at each level */
709         uint16_t __otx2_io schq_contig[NIX_TXSCH_LVL_CNT]; /* Contig. queues */
710         uint16_t __otx2_io schq[NIX_TXSCH_LVL_CNT]; /* Non-Contig. queues */
711         /* Scheduler queue list allocated at each level */
712         uint16_t __otx2_io
713                 schq_contig_list[NIX_TXSCH_LVL_CNT][MAX_TXSCHQ_PER_FUNC];
714         uint16_t __otx2_io schq_list[NIX_TXSCH_LVL_CNT][MAX_TXSCHQ_PER_FUNC];
715         /* Traffic aggregation scheduler level */
716         uint8_t  __otx2_io aggr_level;
717         /* Aggregation lvl's RR_PRIO config */
718         uint8_t  __otx2_io aggr_lvl_rr_prio;
719         /* LINKX_CFG CSRs mapped to TL3 or TL2's index ? */
720         uint8_t  __otx2_io link_cfg_lvl;
721 };
722
723 struct nix_txsch_free_req {
724         struct mbox_msghdr hdr;
725 #define TXSCHQ_FREE_ALL BIT_ULL(0)
726         uint16_t __otx2_io flags;
727         /* Scheduler queue level to be freed */
728         uint16_t __otx2_io schq_lvl;
729         /* List of scheduler queues to be freed */
730         uint16_t __otx2_io schq;
731 };
732
733 struct nix_txschq_config {
734         struct mbox_msghdr hdr;
735         uint8_t __otx2_io lvl; /* SMQ/MDQ/TL4/TL3/TL2/TL1 */
736 #define TXSCHQ_IDX_SHIFT 16
737 #define TXSCHQ_IDX_MASK (BIT_ULL(10) - 1)
738 #define TXSCHQ_IDX(reg, shift) (((reg) >> (shift)) & TXSCHQ_IDX_MASK)
739         uint8_t __otx2_io num_regs;
740 #define MAX_REGS_PER_MBOX_MSG 20
741         uint64_t __otx2_io reg[MAX_REGS_PER_MBOX_MSG];
742         uint64_t __otx2_io regval[MAX_REGS_PER_MBOX_MSG];
743 };
744
745 struct nix_vtag_config {
746         struct mbox_msghdr hdr;
747         /* '0' for 4 octet VTAG, '1' for 8 octet VTAG */
748         uint8_t __otx2_io vtag_size;
749         /* cfg_type is '0' for tx vlan cfg
750          * cfg_type is '1' for rx vlan cfg
751          */
752         uint8_t __otx2_io cfg_type;
753         union {
754                 /* Valid when cfg_type is '0' */
755                 struct {
756                         uint64_t __otx2_io vtag0;
757                         uint64_t __otx2_io vtag1;
758
759                         /* cfg_vtag0 & cfg_vtag1 fields are valid
760                          * when free_vtag0 & free_vtag1 are '0's.
761                          */
762                         /* cfg_vtag0 = 1 to configure vtag0 */
763                         uint8_t __otx2_io cfg_vtag0 :1;
764                         /* cfg_vtag1 = 1 to configure vtag1 */
765                         uint8_t __otx2_io cfg_vtag1 :1;
766
767                         /* vtag0_idx & vtag1_idx are only valid when
768                          * both cfg_vtag0 & cfg_vtag1 are '0's,
769                          * these fields are used along with free_vtag0
770                          * & free_vtag1 to free the nix lf's tx_vlan
771                          * configuration.
772                          *
773                          * Denotes the indices of tx_vtag def registers
774                          * that needs to be cleared and freed.
775                          */
776                         int __otx2_io vtag0_idx;
777                         int __otx2_io vtag1_idx;
778
779                         /* Free_vtag0 & free_vtag1 fields are valid
780                          * when cfg_vtag0 & cfg_vtag1 are '0's.
781                          */
782                         /* Free_vtag0 = 1 clears vtag0 configuration
783                          * vtag0_idx denotes the index to be cleared.
784                          */
785                         uint8_t __otx2_io free_vtag0 :1;
786                         /* Free_vtag1 = 1 clears vtag1 configuration
787                          * vtag1_idx denotes the index to be cleared.
788                          */
789                         uint8_t __otx2_io free_vtag1 :1;
790                 } tx;
791
792                 /* Valid when cfg_type is '1' */
793                 struct {
794                         /* Rx vtag type index, valid values are in 0..7 range */
795                         uint8_t __otx2_io vtag_type;
796                         /* Rx vtag strip */
797                         uint8_t __otx2_io strip_vtag :1;
798                         /* Rx vtag capture */
799                         uint8_t __otx2_io capture_vtag :1;
800                 } rx;
801         };
802 };
803
804 struct nix_vtag_config_rsp {
805         struct mbox_msghdr hdr;
806         /* Indices of tx_vtag def registers used to configure
807          * tx vtag0 & vtag1 headers, these indices are valid
808          * when nix_vtag_config mbox requested for vtag0 and/
809          * or vtag1 configuration.
810          */
811         int __otx2_io vtag0_idx;
812         int __otx2_io vtag1_idx;
813 };
814
815 struct nix_rss_flowkey_cfg {
816         struct mbox_msghdr hdr;
817         int __otx2_io mcam_index;  /* MCAM entry index to modify */
818         uint32_t __otx2_io flowkey_cfg; /* Flowkey types selected */
819 #define FLOW_KEY_TYPE_PORT     BIT(0)
820 #define FLOW_KEY_TYPE_IPV4     BIT(1)
821 #define FLOW_KEY_TYPE_IPV6     BIT(2)
822 #define FLOW_KEY_TYPE_TCP      BIT(3)
823 #define FLOW_KEY_TYPE_UDP      BIT(4)
824 #define FLOW_KEY_TYPE_SCTP     BIT(5)
825 #define FLOW_KEY_TYPE_NVGRE    BIT(6)
826 #define FLOW_KEY_TYPE_VXLAN    BIT(7)
827 #define FLOW_KEY_TYPE_GENEVE   BIT(8)
828 #define FLOW_KEY_TYPE_ETH_DMAC BIT(9)
829 #define FLOW_KEY_TYPE_IPV6_EXT BIT(10)
830 #define FLOW_KEY_TYPE_GTPU       BIT(11)
831 #define FLOW_KEY_TYPE_INNR_IPV4     BIT(12)
832 #define FLOW_KEY_TYPE_INNR_IPV6     BIT(13)
833 #define FLOW_KEY_TYPE_INNR_TCP      BIT(14)
834 #define FLOW_KEY_TYPE_INNR_UDP      BIT(15)
835 #define FLOW_KEY_TYPE_INNR_SCTP     BIT(16)
836 #define FLOW_KEY_TYPE_INNR_ETH_DMAC BIT(17)
837         uint8_t group;       /* RSS context or group */
838 };
839
840 struct nix_rss_flowkey_cfg_rsp {
841         struct mbox_msghdr hdr;
842         uint8_t __otx2_io alg_idx; /* Selected algo index */
843 };
844
845 struct nix_set_mac_addr {
846         struct mbox_msghdr hdr;
847         uint8_t __otx2_io mac_addr[RTE_ETHER_ADDR_LEN];
848 };
849
850 struct nix_get_mac_addr_rsp {
851         struct mbox_msghdr hdr;
852         uint8_t __otx2_io mac_addr[RTE_ETHER_ADDR_LEN];
853 };
854
855 struct nix_mark_format_cfg {
856         struct mbox_msghdr hdr;
857         uint8_t __otx2_io offset;
858         uint8_t __otx2_io y_mask;
859         uint8_t __otx2_io y_val;
860         uint8_t __otx2_io r_mask;
861         uint8_t __otx2_io r_val;
862 };
863
864 struct nix_mark_format_cfg_rsp {
865         struct mbox_msghdr hdr;
866         uint8_t __otx2_io mark_format_idx;
867 };
868
869 struct nix_lso_format_cfg {
870         struct mbox_msghdr hdr;
871         uint64_t __otx2_io field_mask;
872 #define NIX_LSO_FIELD_MAX       (8)
873         uint64_t __otx2_io fields[NIX_LSO_FIELD_MAX];
874 };
875
876 struct nix_lso_format_cfg_rsp {
877         struct mbox_msghdr hdr;
878         uint8_t __otx2_io lso_format_idx;
879 };
880
881 struct nix_rx_mode {
882         struct mbox_msghdr hdr;
883 #define NIX_RX_MODE_UCAST    BIT(0)
884 #define NIX_RX_MODE_PROMISC  BIT(1)
885 #define NIX_RX_MODE_ALLMULTI BIT(2)
886         uint16_t __otx2_io mode;
887 };
888
889 struct nix_frs_cfg {
890         struct mbox_msghdr hdr;
891         uint8_t __otx2_io update_smq;    /* Update SMQ's min/max lens */
892         uint8_t __otx2_io update_minlen; /* Set minlen also */
893         uint8_t __otx2_io sdp_link;      /* Set SDP RX link */
894         uint16_t __otx2_io maxlen;
895         uint16_t __otx2_io minlen;
896 };
897
898 struct nix_set_vlan_tpid {
899         struct mbox_msghdr hdr;
900 #define NIX_VLAN_TYPE_INNER 0
901 #define NIX_VLAN_TYPE_OUTER 1
902         uint8_t __otx2_io vlan_type;
903         uint16_t __otx2_io tpid;
904 };
905
906 struct nix_bp_cfg_req {
907         struct mbox_msghdr hdr;
908         uint16_t __otx2_io chan_base; /* Starting channel number */
909         uint8_t __otx2_io chan_cnt; /* Number of channels */
910         uint8_t __otx2_io bpid_per_chan;
911         /* bpid_per_chan = 0  assigns single bp id for range of channels */
912         /* bpid_per_chan = 1 assigns separate bp id for each channel */
913 };
914
915 /* Global NIX inline IPSec configuration */
916 struct nix_inline_ipsec_cfg {
917         struct mbox_msghdr hdr;
918         uint32_t __otx2_io cpt_credit;
919         struct {
920                 uint8_t __otx2_io egrp;
921                 uint8_t __otx2_io opcode;
922         } gen_cfg;
923         struct {
924                 uint16_t __otx2_io cpt_pf_func;
925                 uint8_t __otx2_io cpt_slot;
926         } inst_qsel;
927         uint8_t __otx2_io enable;
928 };
929
930 /* Per NIX LF inline IPSec configuration */
931 struct nix_inline_ipsec_lf_cfg {
932         struct mbox_msghdr hdr;
933         uint64_t __otx2_io sa_base_addr;
934         struct {
935                 uint32_t __otx2_io tag_const;
936                 uint16_t __otx2_io lenm1_max;
937                 uint8_t __otx2_io sa_pow2_size;
938                 uint8_t __otx2_io tt;
939         } ipsec_cfg0;
940         struct {
941                 uint32_t __otx2_io sa_idx_max;
942                 uint8_t __otx2_io sa_idx_w;
943         } ipsec_cfg1;
944         uint8_t __otx2_io enable;
945 };
946
947 /* PF can be mapped to either CGX or LBK interface,
948  * so maximum 64 channels are possible.
949  */
950 #define NIX_MAX_CHAN    64
951 struct nix_bp_cfg_rsp {
952         struct mbox_msghdr hdr;
953         /* Channel and bpid mapping */
954         uint16_t __otx2_io chan_bpid[NIX_MAX_CHAN];
955         /* Number of channel for which bpids are assigned */
956         uint8_t __otx2_io chan_cnt;
957 };
958
959 /* SSO mailbox error codes
960  * Range 501 - 600.
961  */
962 enum sso_af_status {
963         SSO_AF_ERR_PARAM        = -501,
964         SSO_AF_ERR_LF_INVALID   = -502,
965         SSO_AF_ERR_AF_LF_ALLOC  = -503,
966         SSO_AF_ERR_GRP_EBUSY    = -504,
967         SSO_AF_ERR_AF_LF_INVALID = -599,
968 };
969
970 struct sso_lf_alloc_req {
971         struct mbox_msghdr hdr;
972         int __otx2_io node;
973         uint16_t __otx2_io hwgrps;
974 };
975
976 struct sso_lf_alloc_rsp {
977         struct mbox_msghdr hdr;
978         uint32_t __otx2_io xaq_buf_size;
979         uint32_t __otx2_io xaq_wq_entries;
980         uint32_t __otx2_io in_unit_entries;
981         uint16_t __otx2_io hwgrps;
982 };
983
984 struct sso_lf_free_req {
985         struct mbox_msghdr hdr;
986         int __otx2_io node;
987         uint16_t __otx2_io hwgrps;
988 };
989
990 /* SSOW mailbox error codes
991  * Range 601 - 700.
992  */
993 enum ssow_af_status {
994         SSOW_AF_ERR_PARAM       = -601,
995         SSOW_AF_ERR_LF_INVALID  = -602,
996         SSOW_AF_ERR_AF_LF_ALLOC = -603,
997 };
998
999 struct ssow_lf_alloc_req {
1000         struct mbox_msghdr hdr;
1001         int __otx2_io node;
1002         uint16_t __otx2_io hws;
1003 };
1004
1005 struct ssow_lf_free_req {
1006         struct mbox_msghdr hdr;
1007         int __otx2_io node;
1008         uint16_t __otx2_io hws;
1009 };
1010
1011 struct sso_hw_setconfig {
1012         struct mbox_msghdr hdr;
1013         uint32_t __otx2_io npa_aura_id;
1014         uint16_t __otx2_io npa_pf_func;
1015         uint16_t __otx2_io hwgrps;
1016 };
1017
1018 struct sso_info_req {
1019         struct mbox_msghdr hdr;
1020         union {
1021                 uint16_t __otx2_io grp;
1022                 uint16_t __otx2_io hws;
1023         };
1024 };
1025
1026 struct sso_grp_priority {
1027         struct mbox_msghdr hdr;
1028         uint16_t __otx2_io grp;
1029         uint8_t __otx2_io priority;
1030         uint8_t __otx2_io affinity;
1031         uint8_t __otx2_io weight;
1032 };
1033
1034 struct sso_grp_qos_cfg {
1035         struct mbox_msghdr hdr;
1036         uint16_t __otx2_io grp;
1037         uint32_t __otx2_io xaq_limit;
1038         uint16_t __otx2_io taq_thr;
1039         uint16_t __otx2_io iaq_thr;
1040 };
1041
1042 struct sso_grp_stats {
1043         struct mbox_msghdr hdr;
1044         uint16_t __otx2_io grp;
1045         uint64_t __otx2_io ws_pc;
1046         uint64_t __otx2_io ext_pc;
1047         uint64_t __otx2_io wa_pc;
1048         uint64_t __otx2_io ts_pc;
1049         uint64_t __otx2_io ds_pc;
1050         uint64_t __otx2_io dq_pc;
1051         uint64_t __otx2_io aw_status;
1052         uint64_t __otx2_io page_cnt;
1053 };
1054
1055 struct sso_hws_stats {
1056         struct mbox_msghdr hdr;
1057         uint16_t __otx2_io hws;
1058         uint64_t __otx2_io arbitration;
1059 };
1060
1061 /* CPT mbox message formats */
1062
1063 struct cpt_rd_wr_reg_msg {
1064         struct mbox_msghdr hdr;
1065         uint64_t __otx2_io reg_offset;
1066         uint64_t __otx2_io *ret_val;
1067         uint64_t __otx2_io val;
1068         uint8_t __otx2_io is_write;
1069 };
1070
1071 #define CPT_INLINE_INBOUND      0
1072 #define CPT_INLINE_OUTBOUND     1
1073
1074 struct cpt_inline_ipsec_cfg_msg {
1075         struct mbox_msghdr hdr;
1076         uint8_t __otx2_io enable;
1077         uint8_t __otx2_io slot;
1078         uint8_t __otx2_io dir;
1079         uint16_t __otx2_io sso_pf_func; /* Inbound path SSO_PF_FUNC */
1080         uint16_t __otx2_io nix_pf_func; /* Outbound path NIX_PF_FUNC */
1081 };
1082
1083 /* NPC mbox message structs */
1084
1085 #define NPC_MCAM_ENTRY_INVALID  0xFFFF
1086 #define NPC_MCAM_INVALID_MAP    0xFFFF
1087
1088 /* NPC mailbox error codes
1089  * Range 701 - 800.
1090  */
1091 enum npc_af_status {
1092         NPC_MCAM_INVALID_REQ    = -701,
1093         NPC_MCAM_ALLOC_DENIED   = -702,
1094         NPC_MCAM_ALLOC_FAILED   = -703,
1095         NPC_MCAM_PERM_DENIED    = -704,
1096 };
1097
1098 struct npc_mcam_alloc_entry_req {
1099         struct mbox_msghdr hdr;
1100 #define NPC_MAX_NONCONTIG_ENTRIES       256
1101         uint8_t __otx2_io contig;   /* Contiguous entries ? */
1102 #define NPC_MCAM_ANY_PRIO               0
1103 #define NPC_MCAM_LOWER_PRIO             1
1104 #define NPC_MCAM_HIGHER_PRIO            2
1105         uint8_t __otx2_io priority; /* Lower or higher w.r.t ref_entry */
1106         uint16_t __otx2_io ref_entry;
1107         uint16_t __otx2_io count;    /* Number of entries requested */
1108 };
1109
1110 struct npc_mcam_alloc_entry_rsp {
1111         struct mbox_msghdr hdr;
1112         /* Entry alloc'ed or start index if contiguous.
1113          * Invalid in case of non-contiguous.
1114          */
1115         uint16_t __otx2_io entry;
1116         uint16_t __otx2_io count; /* Number of entries allocated */
1117         uint16_t __otx2_io free_count; /* Number of entries available */
1118         uint16_t __otx2_io entry_list[NPC_MAX_NONCONTIG_ENTRIES];
1119 };
1120
1121 struct npc_mcam_free_entry_req {
1122         struct mbox_msghdr hdr;
1123         uint16_t __otx2_io entry; /* Entry index to be freed */
1124         uint8_t __otx2_io all;   /* Free all entries alloc'ed to this PFVF */
1125 };
1126
1127 struct mcam_entry {
1128 #define NPC_MAX_KWS_IN_KEY      7 /* Number of keywords in max key width */
1129         uint64_t __otx2_io kw[NPC_MAX_KWS_IN_KEY];
1130         uint64_t __otx2_io kw_mask[NPC_MAX_KWS_IN_KEY];
1131         uint64_t __otx2_io action;
1132         uint64_t __otx2_io vtag_action;
1133 };
1134
1135 struct npc_mcam_write_entry_req {
1136         struct mbox_msghdr hdr;
1137         struct mcam_entry entry_data;
1138         uint16_t __otx2_io entry; /* MCAM entry to write this match key */
1139         uint16_t __otx2_io cntr;         /* Counter for this MCAM entry */
1140         uint8_t __otx2_io intf;  /* Rx or Tx interface */
1141         uint8_t __otx2_io enable_entry;/* Enable this MCAM entry ? */
1142         uint8_t __otx2_io set_cntr;    /* Set counter for this entry ? */
1143 };
1144
1145 /* Enable/Disable a given entry */
1146 struct npc_mcam_ena_dis_entry_req {
1147         struct mbox_msghdr hdr;
1148         uint16_t __otx2_io entry;
1149 };
1150
1151 struct npc_mcam_shift_entry_req {
1152         struct mbox_msghdr hdr;
1153 #define NPC_MCAM_MAX_SHIFTS     64
1154         uint16_t __otx2_io curr_entry[NPC_MCAM_MAX_SHIFTS];
1155         uint16_t __otx2_io new_entry[NPC_MCAM_MAX_SHIFTS];
1156         uint16_t __otx2_io shift_count; /* Number of entries to shift */
1157 };
1158
1159 struct npc_mcam_shift_entry_rsp {
1160         struct mbox_msghdr hdr;
1161         /* Index in 'curr_entry', not entry itself */
1162         uint16_t __otx2_io failed_entry_idx;
1163 };
1164
1165 struct npc_mcam_alloc_counter_req {
1166         struct mbox_msghdr hdr;
1167         uint8_t __otx2_io contig;       /* Contiguous counters ? */
1168 #define NPC_MAX_NONCONTIG_COUNTERS 64
1169         uint16_t __otx2_io count;       /* Number of counters requested */
1170 };
1171
1172 struct npc_mcam_alloc_counter_rsp {
1173         struct mbox_msghdr hdr;
1174         /* Counter alloc'ed or start idx if contiguous.
1175          * Invalid incase of non-contiguous.
1176          */
1177         uint16_t __otx2_io cntr;
1178         uint16_t __otx2_io count; /* Number of counters allocated */
1179         uint16_t __otx2_io cntr_list[NPC_MAX_NONCONTIG_COUNTERS];
1180 };
1181
1182 struct npc_mcam_oper_counter_req {
1183         struct mbox_msghdr hdr;
1184         uint16_t __otx2_io cntr; /* Free a counter or clear/fetch it's stats */
1185 };
1186
1187 struct npc_mcam_oper_counter_rsp {
1188         struct mbox_msghdr hdr;
1189         /* valid only while fetching counter's stats */
1190         uint64_t __otx2_io stat;
1191 };
1192
1193 struct npc_mcam_unmap_counter_req {
1194         struct mbox_msghdr hdr;
1195         uint16_t __otx2_io cntr;
1196         uint16_t __otx2_io entry; /* Entry and counter to be unmapped */
1197         uint8_t __otx2_io all;   /* Unmap all entries using this counter ? */
1198 };
1199
1200 struct npc_mcam_alloc_and_write_entry_req {
1201         struct mbox_msghdr hdr;
1202         struct mcam_entry entry_data;
1203         uint16_t __otx2_io ref_entry;
1204         uint8_t __otx2_io priority;    /* Lower or higher w.r.t ref_entry */
1205         uint8_t __otx2_io intf;  /* Rx or Tx interface */
1206         uint8_t __otx2_io enable_entry;/* Enable this MCAM entry ? */
1207         uint8_t __otx2_io alloc_cntr;  /* Allocate counter and map ? */
1208 };
1209
1210 struct npc_mcam_alloc_and_write_entry_rsp {
1211         struct mbox_msghdr hdr;
1212         uint16_t __otx2_io entry;
1213         uint16_t __otx2_io cntr;
1214 };
1215
1216 struct npc_get_kex_cfg_rsp {
1217         struct mbox_msghdr hdr;
1218         uint64_t __otx2_io rx_keyx_cfg;   /* NPC_AF_INTF(0)_KEX_CFG */
1219         uint64_t __otx2_io tx_keyx_cfg;   /* NPC_AF_INTF(1)_KEX_CFG */
1220 #define NPC_MAX_INTF    2
1221 #define NPC_MAX_LID     8
1222 #define NPC_MAX_LT      16
1223 #define NPC_MAX_LD      2
1224 #define NPC_MAX_LFL     16
1225         /* NPC_AF_KEX_LDATA(0..1)_FLAGS_CFG */
1226         uint64_t __otx2_io kex_ld_flags[NPC_MAX_LD];
1227         /* NPC_AF_INTF(0..1)_LID(0..7)_LT(0..15)_LD(0..1)_CFG */
1228         uint64_t __otx2_io
1229         intf_lid_lt_ld[NPC_MAX_INTF][NPC_MAX_LID][NPC_MAX_LT][NPC_MAX_LD];
1230         /* NPC_AF_INTF(0..1)_LDATA(0..1)_FLAGS(0..15)_CFG */
1231         uint64_t __otx2_io
1232         intf_ld_flags[NPC_MAX_INTF][NPC_MAX_LD][NPC_MAX_LFL];
1233 #define MKEX_NAME_LEN 128
1234         uint8_t __otx2_io mkex_pfl_name[MKEX_NAME_LEN];
1235 };
1236
1237 struct flow_msg {
1238         unsigned char __otx2_io dmac[6];
1239         unsigned char __otx2_io smac[6];
1240         uint16_t __otx2_io etype;
1241         uint16_t __otx2_io vlan_etype;
1242         uint16_t __otx2_io vlan_tci;
1243         union {
1244                 uint32_t __otx2_io ip4src;
1245                 uint32_t __otx2_io ip6src[4];
1246         };
1247         union {
1248                 uint32_t __otx2_io ip4dst;
1249                 uint32_t __otx2_io ip6dst[4];
1250         };
1251         uint8_t __otx2_io tos;
1252         uint8_t __otx2_io ip_ver;
1253         uint8_t __otx2_io ip_proto;
1254         uint8_t __otx2_io tc;
1255         uint16_t __otx2_io sport;
1256         uint16_t __otx2_io dport;
1257 };
1258
1259 struct npc_install_flow_req {
1260         struct mbox_msghdr hdr;
1261         struct flow_msg packet;
1262         struct flow_msg mask;
1263         uint64_t __otx2_io features;
1264         uint16_t __otx2_io entry;
1265         uint16_t __otx2_io channel;
1266         uint8_t __otx2_io intf;
1267         uint8_t __otx2_io set_cntr;
1268         uint8_t __otx2_io default_rule;
1269         /* Overwrite(0) or append(1) flow to default rule? */
1270         uint8_t __otx2_io append;
1271         uint16_t __otx2_io vf;
1272         /* action */
1273         uint32_t __otx2_io index;
1274         uint16_t __otx2_io match_id;
1275         uint8_t __otx2_io flow_key_alg;
1276         uint8_t __otx2_io op;
1277         /* vtag action */
1278         uint8_t __otx2_io vtag0_type;
1279         uint8_t __otx2_io vtag0_valid;
1280         uint8_t __otx2_io vtag1_type;
1281         uint8_t __otx2_io vtag1_valid;
1282 };
1283
1284 struct npc_install_flow_rsp {
1285         struct mbox_msghdr hdr;
1286         /* Negative if no counter else counter number */
1287         int __otx2_io counter;
1288 };
1289
1290 struct npc_delete_flow_req {
1291         struct mbox_msghdr hdr;
1292         uint16_t __otx2_io entry;
1293         /* PF + VFs */
1294         uint8_t __otx2_io all;
1295 };
1296
1297 struct npc_mcam_read_entry_req {
1298         struct mbox_msghdr hdr;
1299         /* MCAM entry to read */
1300         uint16_t __otx2_io entry;
1301 };
1302
1303 struct npc_mcam_read_entry_rsp {
1304         struct mbox_msghdr hdr;
1305         struct mcam_entry entry_data;
1306         uint8_t __otx2_io intf;
1307         uint8_t __otx2_io enable;
1308 };
1309
1310 /* TIM mailbox error codes
1311  * Range 801 - 900.
1312  */
1313 enum tim_af_status {
1314         TIM_AF_NO_RINGS_LEFT                    = -801,
1315         TIM_AF_INVALID_NPA_PF_FUNC              = -802,
1316         TIM_AF_INVALID_SSO_PF_FUNC              = -803,
1317         TIM_AF_RING_STILL_RUNNING               = -804,
1318         TIM_AF_LF_INVALID                       = -805,
1319         TIM_AF_CSIZE_NOT_ALIGNED                = -806,
1320         TIM_AF_CSIZE_TOO_SMALL                  = -807,
1321         TIM_AF_CSIZE_TOO_BIG                    = -808,
1322         TIM_AF_INTERVAL_TOO_SMALL               = -809,
1323         TIM_AF_INVALID_BIG_ENDIAN_VALUE         = -810,
1324         TIM_AF_INVALID_CLOCK_SOURCE             = -811,
1325         TIM_AF_GPIO_CLK_SRC_NOT_ENABLED         = -812,
1326         TIM_AF_INVALID_BSIZE                    = -813,
1327         TIM_AF_INVALID_ENABLE_PERIODIC          = -814,
1328         TIM_AF_INVALID_ENABLE_DONTFREE          = -815,
1329         TIM_AF_ENA_DONTFRE_NSET_PERIODIC        = -816,
1330         TIM_AF_RING_ALREADY_DISABLED            = -817,
1331 };
1332
1333 enum tim_clk_srcs {
1334         TIM_CLK_SRCS_TENNS      = 0,
1335         TIM_CLK_SRCS_GPIO       = 1,
1336         TIM_CLK_SRCS_GTI        = 2,
1337         TIM_CLK_SRCS_PTP        = 3,
1338         TIM_CLK_SRSC_INVALID,
1339 };
1340
1341 enum tim_gpio_edge {
1342         TIM_GPIO_NO_EDGE                = 0,
1343         TIM_GPIO_LTOH_TRANS             = 1,
1344         TIM_GPIO_HTOL_TRANS             = 2,
1345         TIM_GPIO_BOTH_TRANS             = 3,
1346         TIM_GPIO_INVALID,
1347 };
1348
1349 enum ptp_op {
1350         PTP_OP_ADJFINE = 0, /* adjfine(req.scaled_ppm); */
1351         PTP_OP_GET_CLOCK = 1, /* rsp.clk = get_clock() */
1352 };
1353
1354 struct ptp_req {
1355         struct mbox_msghdr hdr;
1356         uint8_t __otx2_io op;
1357         int64_t __otx2_io scaled_ppm;
1358         uint8_t __otx2_io is_pmu;
1359 };
1360
1361 struct ptp_rsp {
1362         struct mbox_msghdr hdr;
1363         uint64_t __otx2_io clk;
1364         uint64_t __otx2_io tsc;
1365 };
1366
1367 struct get_hw_cap_rsp {
1368         struct mbox_msghdr hdr;
1369         /* Schq mapping fixed or flexible */
1370         uint8_t __otx2_io nix_fixed_txschq_mapping;
1371         uint8_t __otx2_io nix_express_traffic; /* Are express links supported */
1372         uint8_t __otx2_io nix_shaping; /* Is shaping and coloring supported */
1373 };
1374
1375 struct ndc_sync_op {
1376         struct mbox_msghdr hdr;
1377         uint8_t __otx2_io nix_lf_tx_sync;
1378         uint8_t __otx2_io nix_lf_rx_sync;
1379         uint8_t __otx2_io npa_lf_sync;
1380 };
1381
1382 struct tim_lf_alloc_req {
1383         struct mbox_msghdr hdr;
1384         uint16_t __otx2_io ring;
1385         uint16_t __otx2_io npa_pf_func;
1386         uint16_t __otx2_io sso_pf_func;
1387 };
1388
1389 struct tim_ring_req {
1390         struct mbox_msghdr hdr;
1391         uint16_t __otx2_io ring;
1392 };
1393
1394 struct tim_config_req {
1395         struct mbox_msghdr hdr;
1396         uint16_t __otx2_io ring;
1397         uint8_t __otx2_io bigendian;
1398         uint8_t __otx2_io clocksource;
1399         uint8_t __otx2_io enableperiodic;
1400         uint8_t __otx2_io enabledontfreebuffer;
1401         uint32_t __otx2_io bucketsize;
1402         uint32_t __otx2_io chunksize;
1403         uint32_t __otx2_io interval;
1404 };
1405
1406 struct tim_lf_alloc_rsp {
1407         struct mbox_msghdr hdr;
1408         uint64_t __otx2_io tenns_clk;
1409 };
1410
1411 struct tim_enable_rsp {
1412         struct mbox_msghdr hdr;
1413         uint64_t __otx2_io timestarted;
1414         uint32_t __otx2_io currentbucket;
1415 };
1416
1417 const char *otx2_mbox_id2name(uint16_t id);
1418 int otx2_mbox_id2size(uint16_t id);
1419 void otx2_mbox_reset(struct otx2_mbox *mbox, int devid);
1420 int otx2_mbox_init(struct otx2_mbox *mbox, uintptr_t hwbase,
1421                    uintptr_t reg_base, int direction, int ndevs);
1422 void otx2_mbox_fini(struct otx2_mbox *mbox);
1423 void otx2_mbox_msg_send(struct otx2_mbox *mbox, int devid);
1424 int otx2_mbox_wait_for_rsp(struct otx2_mbox *mbox, int devid);
1425 int otx2_mbox_wait_for_rsp_tmo(struct otx2_mbox *mbox, int devid, uint32_t tmo);
1426 int otx2_mbox_get_rsp(struct otx2_mbox *mbox, int devid, void **msg);
1427 int otx2_mbox_get_rsp_tmo(struct otx2_mbox *mbox, int devid, void **msg,
1428                           uint32_t tmo);
1429 int otx2_mbox_get_availmem(struct otx2_mbox *mbox, int devid);
1430 struct mbox_msghdr *otx2_mbox_alloc_msg_rsp(struct otx2_mbox *mbox, int devid,
1431                                             int size, int size_rsp);
1432
1433 static inline struct mbox_msghdr *
1434 otx2_mbox_alloc_msg(struct otx2_mbox *mbox, int devid, int size)
1435 {
1436         return otx2_mbox_alloc_msg_rsp(mbox, devid, size, 0);
1437 }
1438
1439 static inline void
1440 otx2_mbox_req_init(uint16_t mbox_id, void *msghdr)
1441 {
1442         struct mbox_msghdr *hdr = msghdr;
1443
1444         hdr->sig = OTX2_MBOX_REQ_SIG;
1445         hdr->ver = OTX2_MBOX_VERSION;
1446         hdr->id = mbox_id;
1447         hdr->pcifunc = 0;
1448 }
1449
1450 static inline void
1451 otx2_mbox_rsp_init(uint16_t mbox_id, void *msghdr)
1452 {
1453         struct mbox_msghdr *hdr = msghdr;
1454
1455         hdr->sig = OTX2_MBOX_RSP_SIG;
1456         hdr->rc = -ETIMEDOUT;
1457         hdr->id = mbox_id;
1458 }
1459
1460 static inline bool
1461 otx2_mbox_nonempty(struct otx2_mbox *mbox, int devid)
1462 {
1463         struct otx2_mbox_dev *mdev = &mbox->dev[devid];
1464         bool ret;
1465
1466         rte_spinlock_lock(&mdev->mbox_lock);
1467         ret = mdev->num_msgs != 0;
1468         rte_spinlock_unlock(&mdev->mbox_lock);
1469
1470         return ret;
1471 }
1472
1473 static inline int
1474 otx2_mbox_process(struct otx2_mbox *mbox)
1475 {
1476         otx2_mbox_msg_send(mbox, 0);
1477         return otx2_mbox_get_rsp(mbox, 0, NULL);
1478 }
1479
1480 static inline int
1481 otx2_mbox_process_msg(struct otx2_mbox *mbox, void **msg)
1482 {
1483         otx2_mbox_msg_send(mbox, 0);
1484         return otx2_mbox_get_rsp(mbox, 0, msg);
1485 }
1486
1487 static inline int
1488 otx2_mbox_process_tmo(struct otx2_mbox *mbox, uint32_t tmo)
1489 {
1490         otx2_mbox_msg_send(mbox, 0);
1491         return otx2_mbox_get_rsp_tmo(mbox, 0, NULL, tmo);
1492 }
1493
1494 static inline int
1495 otx2_mbox_process_msg_tmo(struct otx2_mbox *mbox, void **msg, uint32_t tmo)
1496 {
1497         otx2_mbox_msg_send(mbox, 0);
1498         return otx2_mbox_get_rsp_tmo(mbox, 0, msg, tmo);
1499 }
1500
1501 int otx2_send_ready_msg(struct otx2_mbox *mbox, uint16_t *pf_func /* out */);
1502 int otx2_reply_invalid_msg(struct otx2_mbox *mbox, int devid, uint16_t pf_func,
1503                         uint16_t id);
1504
1505 #define M(_name, _id, _fn_name, _req_type, _rsp_type)                   \
1506 static inline struct _req_type                                          \
1507 *otx2_mbox_alloc_msg_ ## _fn_name(struct otx2_mbox *mbox)               \
1508 {                                                                       \
1509         struct _req_type *req;                                          \
1510                                                                         \
1511         req = (struct _req_type *)otx2_mbox_alloc_msg_rsp(              \
1512                 mbox, 0, sizeof(struct _req_type),                      \
1513                 sizeof(struct _rsp_type));                              \
1514         if (!req)                                                       \
1515                 return NULL;                                            \
1516                                                                         \
1517         req->hdr.sig = OTX2_MBOX_REQ_SIG;                               \
1518         req->hdr.id = _id;                                              \
1519         otx2_mbox_dbg("id=0x%x (%s)",                                   \
1520                         req->hdr.id, otx2_mbox_id2name(req->hdr.id));   \
1521         return req;                                                     \
1522 }
1523
1524 MBOX_MESSAGES
1525 #undef M
1526
1527 /* This is required for copy operations from device memory which do not work on
1528  * addresses which are unaligned to 16B. This is because of specific
1529  * optimizations to libc memcpy.
1530  */
1531 static inline volatile void *
1532 otx2_mbox_memcpy(volatile void *d, const volatile void *s, size_t l)
1533 {
1534         const volatile uint8_t *sb;
1535         volatile uint8_t *db;
1536         size_t i;
1537
1538         if (!d || !s)
1539                 return NULL;
1540         db = (volatile uint8_t *)d;
1541         sb = (const volatile uint8_t *)s;
1542         for (i = 0; i < l; i++)
1543                 db[i] = sb[i];
1544         return d;
1545 }
1546
1547 /* This is required for memory operations from device memory which do not
1548  * work on addresses which are unaligned to 16B. This is because of specific
1549  * optimizations to libc memset.
1550  */
1551 static inline void
1552 otx2_mbox_memset(volatile void *d, uint8_t val, size_t l)
1553 {
1554         volatile uint8_t *db;
1555         size_t i = 0;
1556
1557         if (!d || !l)
1558                 return;
1559         db = (volatile uint8_t *)d;
1560         for (i = 0; i < l; i++)
1561                 db[i] = val;
1562 }
1563
1564 #endif /* __OTX2_MBOX_H__ */