1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2 /* QLogic qed NIC Driver
3 * Copyright (c) 2015-2017 QLogic Corporation
4 * Copyright (c) 2019-2020 Marvell International Ltd.
10 #include <linux/types.h>
11 #include <linux/slab.h>
14 /* Fields of IGU PF CONFIGURATION REGISTER */
15 #define IGU_PF_CONF_FUNC_EN (0x1 << 0) /* function enable */
16 #define IGU_PF_CONF_MSI_MSIX_EN (0x1 << 1) /* MSI/MSIX enable */
17 #define IGU_PF_CONF_INT_LINE_EN (0x1 << 2) /* INT enable */
18 #define IGU_PF_CONF_ATTN_BIT_EN (0x1 << 3) /* attention enable */
19 #define IGU_PF_CONF_SINGLE_ISR_EN (0x1 << 4) /* single ISR mode enable */
20 #define IGU_PF_CONF_SIMD_MODE (0x1 << 5) /* simd all ones mode */
21 /* Fields of IGU VF CONFIGURATION REGISTER */
22 #define IGU_VF_CONF_FUNC_EN (0x1 << 0) /* function enable */
23 #define IGU_VF_CONF_MSI_MSIX_EN (0x1 << 1) /* MSI/MSIX enable */
24 #define IGU_VF_CONF_SINGLE_ISR_EN (0x1 << 4) /* single ISR mode enable */
25 #define IGU_VF_CONF_PARENT_MASK (0xF) /* Parent PF */
26 #define IGU_VF_CONF_PARENT_SHIFT 5 /* Parent PF */
28 /* Igu control commands
36 /* Control register for the IGU command register
40 #define IGU_CTRL_REG_FID_MASK 0xFFFF /* Opaque_FID */
41 #define IGU_CTRL_REG_FID_SHIFT 0
42 #define IGU_CTRL_REG_PXP_ADDR_MASK 0xFFF /* Command address */
43 #define IGU_CTRL_REG_PXP_ADDR_SHIFT 16
44 #define IGU_CTRL_REG_RESERVED_MASK 0x1
45 #define IGU_CTRL_REG_RESERVED_SHIFT 28
46 #define IGU_CTRL_REG_TYPE_MASK 0x1 /* use enum igu_ctrl_cmd */
47 #define IGU_CTRL_REG_TYPE_SHIFT 31
50 enum qed_coalescing_fsm
{
51 QED_COAL_RX_STATE_MACHINE
,
52 QED_COAL_TX_STATE_MACHINE
56 * @brief qed_int_igu_enable_int - enable device interrupts
60 * @param int_mode - interrupt mode to use
62 void qed_int_igu_enable_int(struct qed_hwfn
*p_hwfn
,
63 struct qed_ptt
*p_ptt
,
64 enum qed_int_mode int_mode
);
67 * @brief qed_int_igu_disable_int - disable device interrupts
72 void qed_int_igu_disable_int(struct qed_hwfn
*p_hwfn
,
73 struct qed_ptt
*p_ptt
);
76 * @brief qed_int_igu_read_sisr_reg - Reads the single isr multiple dpc
83 u64
qed_int_igu_read_sisr_reg(struct qed_hwfn
*p_hwfn
);
85 #define QED_SP_SB_ID 0xffff
87 * @brief qed_int_sb_init - Initializes the sb_info structure.
89 * once the structure is initialized it can be passed to sb related functions.
93 * @param sb_info points to an uninitialized (but
94 * allocated) sb_info structure
97 * @param sb_id the sb_id to be used (zero based in driver)
98 * should use QED_SP_SB_ID for SP Status block
102 int qed_int_sb_init(struct qed_hwfn
*p_hwfn
,
103 struct qed_ptt
*p_ptt
,
104 struct qed_sb_info
*sb_info
,
106 dma_addr_t sb_phy_addr
,
109 * @brief qed_int_sb_setup - Setup the sb.
113 * @param sb_info initialized sb_info structure
115 void qed_int_sb_setup(struct qed_hwfn
*p_hwfn
,
116 struct qed_ptt
*p_ptt
,
117 struct qed_sb_info
*sb_info
);
120 * @brief qed_int_sb_release - releases the sb_info structure.
122 * once the structure is released, it's memory can be freed
125 * @param sb_info points to an allocated sb_info structure
126 * @param sb_id the sb_id to be used (zero based in driver)
127 * should never be equal to QED_SP_SB_ID
132 int qed_int_sb_release(struct qed_hwfn
*p_hwfn
,
133 struct qed_sb_info
*sb_info
,
137 * @brief qed_int_sp_dpc - To be called when an interrupt is received on the
138 * default status block.
140 * @param p_hwfn - pointer to hwfn
143 void qed_int_sp_dpc(struct tasklet_struct
*t
);
146 * @brief qed_int_get_num_sbs - get the number of status
147 * blocks configured for this funciton in the igu.
150 * @param p_sb_cnt_info
152 * @return int - number of status blocks configured
154 void qed_int_get_num_sbs(struct qed_hwfn
*p_hwfn
,
155 struct qed_sb_cnt_info
*p_sb_cnt_info
);
158 * @brief qed_int_disable_post_isr_release - performs the cleanup post ISR
159 * release. The API need to be called after releasing all slowpath IRQs
165 void qed_int_disable_post_isr_release(struct qed_dev
*cdev
);
168 * @brief qed_int_attn_clr_enable - sets whether the general behavior is
169 * preventing attentions from being reasserted, or following the
170 * attributes of the specific attention.
176 void qed_int_attn_clr_enable(struct qed_dev
*cdev
, bool clr_enable
);
179 * @brief - Doorbell Recovery handler.
180 * Run doorbell recovery in case of PF overflow (and flush DORQ if
186 int qed_db_rec_handler(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
);
188 #define QED_CAU_DEF_RX_TIMER_RES 0
189 #define QED_CAU_DEF_TX_TIMER_RES 0
191 #define QED_SB_ATT_IDX 0x0001
192 #define QED_SB_EVENT_MASK 0x0003
194 #define SB_ALIGNED_SIZE(p_hwfn) \
195 ALIGNED_TYPE_SIZE(struct status_block_e4, p_hwfn)
197 #define QED_SB_INVALID_IDX 0xffff
199 struct qed_igu_block
{
201 #define QED_IGU_STATUS_FREE 0x01
202 #define QED_IGU_STATUS_VALID 0x02
203 #define QED_IGU_STATUS_PF 0x04
204 #define QED_IGU_STATUS_DSB 0x08
210 /* Index inside IGU [meant for back reference] */
213 struct qed_sb_info
*sb_info
;
216 struct qed_igu_info
{
217 struct qed_igu_block entry
[MAX_TOT_SB_PER_PATH
];
220 struct qed_sb_cnt_info usage
;
222 bool b_allow_pf_vf_change
;
226 * @brief - Make sure the IGU CAM reflects the resources provided by MFW
231 int qed_int_igu_reset_cam(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
);
234 * @brief Translate the weakly-defined client sb-id into an IGU sb-id
237 * @param sb_id - user provided sb_id
239 * @return an index inside IGU CAM where the SB resides
241 u16
qed_get_igu_sb_id(struct qed_hwfn
*p_hwfn
, u16 sb_id
);
244 * @brief return a pointer to an unused valid SB
247 * @param b_is_pf - true iff we want a SB belonging to a PF
249 * @return point to an igu_block, NULL if none is available
251 struct qed_igu_block
*qed_get_igu_free_sb(struct qed_hwfn
*p_hwfn
,
254 void qed_int_igu_init_pure_rt(struct qed_hwfn
*p_hwfn
,
255 struct qed_ptt
*p_ptt
,
259 void qed_int_igu_init_rt(struct qed_hwfn
*p_hwfn
);
262 * @brief qed_int_igu_read_cam - Reads the IGU CAM.
263 * This function needs to be called during hardware
264 * prepare. It reads the info from igu cam to know which
265 * status block is the default / base status block etc.
272 int qed_int_igu_read_cam(struct qed_hwfn
*p_hwfn
,
273 struct qed_ptt
*p_ptt
);
275 typedef int (*qed_int_comp_cb_t
)(struct qed_hwfn
*p_hwfn
,
278 * @brief qed_int_register_cb - Register callback func for
279 * slowhwfn statusblock.
281 * Every protocol that uses the slowhwfn status block
282 * should register a callback function that will be called
283 * once there is an update of the sp status block.
286 * @param comp_cb - function to be called when there is an
287 * interrupt on the sp sb
289 * @param cookie - passed to the callback function
290 * @param sb_idx - OUT parameter which gives the chosen index
292 * @param p_fw_cons - pointer to the actual address of the
293 * consumer for this protocol.
297 int qed_int_register_cb(struct qed_hwfn
*p_hwfn
,
298 qed_int_comp_cb_t comp_cb
,
304 * @brief qed_int_unregister_cb - Unregisters callback
305 * function from sp sb.
306 * Partner of qed_int_register_cb -> should be called
307 * when no longer required.
314 int qed_int_unregister_cb(struct qed_hwfn
*p_hwfn
,
318 * @brief qed_int_get_sp_sb_id - Get the slowhwfn sb id.
324 u16
qed_int_get_sp_sb_id(struct qed_hwfn
*p_hwfn
);
327 * @brief Status block cleanup. Should be called for each status
328 * block that will be used -> both PF / VF
332 * @param igu_sb_id - igu status block id
333 * @param opaque - opaque fid of the sb owner.
334 * @param b_set - set(1) / clear(0)
336 void qed_int_igu_init_pure_rt_single(struct qed_hwfn
*p_hwfn
,
337 struct qed_ptt
*p_ptt
,
343 * @brief qed_int_cau_conf - configure cau for a given status
353 void qed_int_cau_conf_sb(struct qed_hwfn
*p_hwfn
,
354 struct qed_ptt
*p_ptt
,
361 * @brief qed_int_alloc
368 int qed_int_alloc(struct qed_hwfn
*p_hwfn
,
369 struct qed_ptt
*p_ptt
);
372 * @brief qed_int_free
376 void qed_int_free(struct qed_hwfn
*p_hwfn
);
379 * @brief qed_int_setup
384 void qed_int_setup(struct qed_hwfn
*p_hwfn
,
385 struct qed_ptt
*p_ptt
);
388 * @brief - Enable Interrupt & Attention for hw function
396 int qed_int_igu_enable(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
,
397 enum qed_int_mode int_mode
);
400 * @brief - Initialize CAU status block entry
408 void qed_init_cau_sb_entry(struct qed_hwfn
*p_hwfn
,
409 struct cau_sb_entry
*p_sb_entry
,
414 int qed_int_set_timer_res(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
,
415 u8 timer_res
, u16 sb_id
, bool tx
);
417 #define QED_MAPPING_MEMORY_SIZE(dev) (NUM_OF_SBS(dev))
419 int qed_pglueb_rbc_attn_handler(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
,