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