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