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