1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2016 - 2018 Cavium Inc.
7 #ifndef __ECORE_INT_API_H__
8 #define __ECORE_INT_API_H__
10 #ifndef __EXTRACT__LINUX__
11 #define ECORE_SB_IDX 0x0002
14 #define TX_PI(tc) (RX_PI + 1 + tc)
16 #ifndef ECORE_INT_MODE
17 #define ECORE_INT_MODE
26 struct ecore_sb_info {
27 struct status_block_e4 *sb_virt;
29 u32 sb_ack; /* Last given ack */
31 void OSAL_IOMEM *igu_addr;
33 #define ECORE_SB_INFO_INIT 0x1
34 #define ECORE_SB_INFO_SETUP 0x2
36 #ifdef ECORE_CONFIG_DIRECT_HWFN
37 struct ecore_hwfn *p_hwfn;
39 struct ecore_dev *p_dev;
42 struct ecore_sb_info_dbg {
45 u16 pi[PIS_PER_SB_E4];
48 struct ecore_sb_cnt_info {
49 /* Original, current, and free SBs for PF */
54 /* Original, current and free SBS for child VFs */
60 static OSAL_INLINE u16 ecore_sb_update_sb_idx(struct ecore_sb_info *sb_info)
65 /* barrier(); status block is written to by the chip */
66 /* FIXME: need some sort of barrier. */
67 prod = OSAL_LE32_TO_CPU(sb_info->sb_virt->prod_index) &
68 STATUS_BLOCK_E4_PROD_INDEX_MASK;
69 if (sb_info->sb_ack != prod) {
70 sb_info->sb_ack = prod;
74 OSAL_MMIOWB(sb_info->p_dev);
80 * @brief This function creates an update command for interrupts that is
83 * @param sb_info - This is the structure allocated and
84 * initialized per status block. Assumption is
85 * that it was initialized using ecore_sb_init
86 * @param int_cmd - Enable/Disable/Nop
87 * @param upd_flg - whether igu consumer should be
90 * @return OSAL_INLINE void
92 static OSAL_INLINE void ecore_sb_ack(struct ecore_sb_info *sb_info,
93 enum igu_int_cmd int_cmd, u8 upd_flg)
95 struct igu_prod_cons_update igu_ack = { 0 };
97 igu_ack.sb_id_and_flags =
98 ((sb_info->sb_ack << IGU_PROD_CONS_UPDATE_SB_INDEX_SHIFT) |
99 (upd_flg << IGU_PROD_CONS_UPDATE_UPDATE_FLAG_SHIFT) |
100 (int_cmd << IGU_PROD_CONS_UPDATE_ENABLE_INT_SHIFT) |
101 (IGU_SEG_ACCESS_REG << IGU_PROD_CONS_UPDATE_SEGMENT_ACCESS_SHIFT));
103 #ifdef ECORE_CONFIG_DIRECT_HWFN
104 DIRECT_REG_WR(sb_info->p_hwfn, sb_info->igu_addr,
105 igu_ack.sb_id_and_flags);
107 DIRECT_REG_WR(OSAL_NULL, sb_info->igu_addr, igu_ack.sb_id_and_flags);
109 /* Both segments (interrupts & acks) are written to same place address;
110 * Need to guarantee all commands will be received (in-order) by HW.
112 OSAL_MMIOWB(sb_info->p_dev);
113 OSAL_BARRIER(sb_info->p_dev);
116 #ifdef ECORE_CONFIG_DIRECT_HWFN
117 static OSAL_INLINE void __internal_ram_wr(struct ecore_hwfn *p_hwfn,
118 void OSAL_IOMEM *addr,
121 static OSAL_INLINE void __internal_ram_wr(__rte_unused void *p_hwfn,
122 void OSAL_IOMEM *addr,
128 for (i = 0; i < size / sizeof(*data); i++)
129 DIRECT_REG_WR(p_hwfn, &((u32 OSAL_IOMEM *)addr)[i], data[i]);
132 #ifdef ECORE_CONFIG_DIRECT_HWFN
133 static OSAL_INLINE void __internal_ram_wr_relaxed(struct ecore_hwfn *p_hwfn,
134 void OSAL_IOMEM * addr,
137 static OSAL_INLINE void __internal_ram_wr_relaxed(__rte_unused void *p_hwfn,
138 void OSAL_IOMEM * addr,
144 for (i = 0; i < size / sizeof(*data); i++)
145 DIRECT_REG_WR_RELAXED(p_hwfn, &((u32 OSAL_IOMEM *)addr)[i],
149 #ifdef ECORE_CONFIG_DIRECT_HWFN
150 static OSAL_INLINE void internal_ram_wr(struct ecore_hwfn *p_hwfn,
151 void OSAL_IOMEM * addr,
154 __internal_ram_wr_relaxed(p_hwfn, addr, size, data);
157 static OSAL_INLINE void internal_ram_wr(void OSAL_IOMEM *addr,
160 __internal_ram_wr_relaxed(OSAL_NULL, addr, size, data);
169 enum ecore_coalescing_fsm {
170 ECORE_COAL_RX_STATE_MACHINE,
171 ECORE_COAL_TX_STATE_MACHINE
175 * @brief ecore_int_cau_conf_pi - configure cau for a given
185 void ecore_int_cau_conf_pi(struct ecore_hwfn *p_hwfn,
186 struct ecore_ptt *p_ptt,
187 struct ecore_sb_info *p_sb,
189 enum ecore_coalescing_fsm coalescing_fsm,
194 * @brief ecore_int_igu_enable_int - enable device interrupts
198 * @param int_mode - interrupt mode to use
200 void ecore_int_igu_enable_int(struct ecore_hwfn *p_hwfn,
201 struct ecore_ptt *p_ptt,
202 enum ecore_int_mode int_mode);
206 * @brief ecore_int_igu_disable_int - disable device interrupts
211 void ecore_int_igu_disable_int(struct ecore_hwfn *p_hwfn,
212 struct ecore_ptt *p_ptt);
216 * @brief ecore_int_igu_read_sisr_reg - Reads the single isr multiple dpc
223 u64 ecore_int_igu_read_sisr_reg(struct ecore_hwfn *p_hwfn);
225 #define ECORE_SP_SB_ID 0xffff
228 * @brief ecore_int_sb_init - Initializes the sb_info structure.
230 * once the structure is initialized it can be passed to sb related functions.
234 * @param sb_info points to an uninitialized (but
235 * allocated) sb_info structure
236 * @param sb_virt_addr
238 * @param sb_id the sb_id to be used (zero based in driver)
239 * should use ECORE_SP_SB_ID for SP Status block
241 * @return enum _ecore_status_t
243 enum _ecore_status_t ecore_int_sb_init(struct ecore_hwfn *p_hwfn,
244 struct ecore_ptt *p_ptt,
245 struct ecore_sb_info *sb_info,
247 dma_addr_t sb_phy_addr, u16 sb_id);
249 * @brief ecore_int_sb_setup - Setup the sb.
253 * @param sb_info initialized sb_info structure
255 void ecore_int_sb_setup(struct ecore_hwfn *p_hwfn,
256 struct ecore_ptt *p_ptt, struct ecore_sb_info *sb_info);
259 * @brief ecore_int_sb_release - releases the sb_info structure.
261 * once the structure is released, it's memory can be freed
264 * @param sb_info points to an allocated sb_info structure
265 * @param sb_id the sb_id to be used (zero based in driver)
266 * should never be equal to ECORE_SP_SB_ID
269 * @return enum _ecore_status_t
271 enum _ecore_status_t ecore_int_sb_release(struct ecore_hwfn *p_hwfn,
272 struct ecore_sb_info *sb_info,
276 * @brief ecore_int_sp_dpc - To be called when an interrupt is received on the
277 * default status block.
279 * @param p_hwfn - pointer to hwfn
282 void ecore_int_sp_dpc(osal_int_ptr_t hwfn_cookie);
285 * @brief ecore_int_get_num_sbs - get the number of status
286 * blocks configured for this funciton in the igu.
289 * @param p_sb_cnt_info
293 void ecore_int_get_num_sbs(struct ecore_hwfn *p_hwfn,
294 struct ecore_sb_cnt_info *p_sb_cnt_info);
297 * @brief ecore_int_disable_post_isr_release - performs the cleanup post ISR
298 * release. The API need to be called after releasing all slowpath IRQs
304 void ecore_int_disable_post_isr_release(struct ecore_dev *p_dev);
307 * @brief ecore_int_attn_clr_enable - sets whether the general behavior is
308 * preventing attentions from being reasserted, or following the
309 * attributes of the specific attention.
315 void ecore_int_attn_clr_enable(struct ecore_dev *p_dev, bool clr_enable);
318 * @brief Read debug information regarding a given SB.
322 * @param p_sb - point to Status block for which we want to get info.
323 * @param p_info - pointer to struct to fill with information regarding SB.
325 * @return ECORE_SUCCESS if pointer is filled; failure otherwise.
327 enum _ecore_status_t ecore_int_get_sb_dbg(struct ecore_hwfn *p_hwfn,
328 struct ecore_ptt *p_ptt,
329 struct ecore_sb_info *p_sb,
330 struct ecore_sb_info_dbg *p_info);
333 * @brief - Move a free Status block between PF and child VF
337 * @param sb_id - The PF fastpath vector to be moved [re-assigned if claiming
338 * from VF, given-up if moving to VF]
339 * @param b_to_vf - PF->VF == true, VF->PF == false
341 * @return ECORE_SUCCESS if SB successfully moved.
344 ecore_int_igu_relocate_sb(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
345 u16 sb_id, bool b_to_vf);
348 * @brief - Doorbell Recovery handler.
349 * Run DB_REAL_DEAL doorbell recovery in case of PF overflow
350 * (and flush DORQ if needed), otherwise run DB_REC_ONCE.
355 enum _ecore_status_t ecore_db_rec_handler(struct ecore_hwfn *p_hwfn,
356 struct ecore_ptt *p_ptt);