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