1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
12 #include <linux/types.h>
13 #include <linux/slab.h>
16 /* Fields of IGU PF CONFIGRATION REGISTER */
17 #define IGU_PF_CONF_FUNC_EN (0x1 << 0) /* function enable */
18 #define IGU_PF_CONF_MSI_MSIX_EN (0x1 << 1) /* MSI/MSIX enable */
19 #define IGU_PF_CONF_INT_LINE_EN (0x1 << 2) /* INT enable */
20 #define IGU_PF_CONF_ATTN_BIT_EN (0x1 << 3) /* attention enable */
21 #define IGU_PF_CONF_SINGLE_ISR_EN (0x1 << 4) /* single ISR mode enable */
22 #define IGU_PF_CONF_SIMD_MODE (0x1 << 5) /* simd all ones mode */
24 /* Igu control commands
32 /* Control register for the IGU command register
36 #define IGU_CTRL_REG_FID_MASK 0xFFFF /* Opaque_FID */
37 #define IGU_CTRL_REG_FID_SHIFT 0
38 #define IGU_CTRL_REG_PXP_ADDR_MASK 0xFFF /* Command address */
39 #define IGU_CTRL_REG_PXP_ADDR_SHIFT 16
40 #define IGU_CTRL_REG_RESERVED_MASK 0x1
41 #define IGU_CTRL_REG_RESERVED_SHIFT 28
42 #define IGU_CTRL_REG_TYPE_MASK 0x1 /* use enum igu_ctrl_cmd */
43 #define IGU_CTRL_REG_TYPE_SHIFT 31
46 enum qed_coalescing_fsm
{
47 QED_COAL_RX_STATE_MACHINE
,
48 QED_COAL_TX_STATE_MACHINE
52 * @brief qed_int_cau_conf_pi - configure cau for a given
62 void qed_int_cau_conf_pi(struct qed_hwfn
*p_hwfn
,
63 struct qed_ptt
*p_ptt
,
66 enum qed_coalescing_fsm coalescing_fsm
,
70 * @brief qed_int_igu_enable_int - enable device interrupts
74 * @param int_mode - interrupt mode to use
76 void qed_int_igu_enable_int(struct qed_hwfn
*p_hwfn
,
77 struct qed_ptt
*p_ptt
,
78 enum qed_int_mode int_mode
);
81 * @brief qed_int_igu_disable_int - disable device interrupts
86 void qed_int_igu_disable_int(struct qed_hwfn
*p_hwfn
,
87 struct qed_ptt
*p_ptt
);
90 * @brief qed_int_igu_read_sisr_reg - Reads the single isr multiple dpc
97 u64
qed_int_igu_read_sisr_reg(struct qed_hwfn
*p_hwfn
);
99 #define QED_SP_SB_ID 0xffff
101 * @brief qed_int_sb_init - Initializes the sb_info structure.
103 * once the structure is initialized it can be passed to sb related functions.
107 * @param sb_info points to an uninitialized (but
108 * allocated) sb_info structure
109 * @param sb_virt_addr
111 * @param sb_id the sb_id to be used (zero based in driver)
112 * should use QED_SP_SB_ID for SP Status block
116 int qed_int_sb_init(struct qed_hwfn
*p_hwfn
,
117 struct qed_ptt
*p_ptt
,
118 struct qed_sb_info
*sb_info
,
120 dma_addr_t sb_phy_addr
,
123 * @brief qed_int_sb_setup - Setup the sb.
127 * @param sb_info initialized sb_info structure
129 void qed_int_sb_setup(struct qed_hwfn
*p_hwfn
,
130 struct qed_ptt
*p_ptt
,
131 struct qed_sb_info
*sb_info
);
134 * @brief qed_int_sb_release - releases the sb_info structure.
136 * once the structure is released, it's memory can be freed
139 * @param sb_info points to an allocated sb_info structure
140 * @param sb_id the sb_id to be used (zero based in driver)
141 * should never be equal to QED_SP_SB_ID
146 int qed_int_sb_release(struct qed_hwfn
*p_hwfn
,
147 struct qed_sb_info
*sb_info
,
151 * @brief qed_int_sp_dpc - To be called when an interrupt is received on the
152 * default status block.
154 * @param p_hwfn - pointer to hwfn
157 void qed_int_sp_dpc(unsigned long hwfn_cookie
);
160 * @brief qed_int_get_num_sbs - get the number of status
161 * blocks configured for this funciton in the igu.
164 * @param p_iov_blks - configured free blks for vfs
166 * @return int - number of status blocks configured
168 int qed_int_get_num_sbs(struct qed_hwfn
*p_hwfn
,
174 * @brief Interrupt handler
177 #define QED_CAU_DEF_RX_TIMER_RES 0
178 #define QED_CAU_DEF_TX_TIMER_RES 0
180 #define QED_SB_ATT_IDX 0x0001
181 #define QED_SB_EVENT_MASK 0x0003
183 #define SB_ALIGNED_SIZE(p_hwfn) \
184 ALIGNED_TYPE_SIZE(struct status_block, p_hwfn)
186 struct qed_igu_block
{
188 #define QED_IGU_STATUS_FREE 0x01
189 #define QED_IGU_STATUS_VALID 0x02
190 #define QED_IGU_STATUS_PF 0x04
198 struct qed_igu_block igu_blocks
[MAX_TOT_SB_PER_PATH
];
201 struct qed_igu_info
{
202 struct qed_igu_map igu_map
;
211 /* TODO Names of function may change... */
212 void qed_int_igu_init_pure_rt(struct qed_hwfn
*p_hwfn
,
213 struct qed_ptt
*p_ptt
,
217 void qed_int_igu_init_rt(struct qed_hwfn
*p_hwfn
);
220 * @brief qed_int_igu_read_cam - Reads the IGU CAM.
221 * This function needs to be called during hardware
222 * prepare. It reads the info from igu cam to know which
223 * status block is the default / base status block etc.
230 int qed_int_igu_read_cam(struct qed_hwfn
*p_hwfn
,
231 struct qed_ptt
*p_ptt
);
233 typedef int (*qed_int_comp_cb_t
)(struct qed_hwfn
*p_hwfn
,
236 * @brief qed_int_register_cb - Register callback func for
237 * slowhwfn statusblock.
239 * Every protocol that uses the slowhwfn status block
240 * should register a callback function that will be called
241 * once there is an update of the sp status block.
244 * @param comp_cb - function to be called when there is an
245 * interrupt on the sp sb
247 * @param cookie - passed to the callback function
248 * @param sb_idx - OUT parameter which gives the chosen index
250 * @param p_fw_cons - pointer to the actual address of the
251 * consumer for this protocol.
255 int qed_int_register_cb(struct qed_hwfn
*p_hwfn
,
256 qed_int_comp_cb_t comp_cb
,
262 * @brief qed_int_unregister_cb - Unregisters callback
263 * function from sp sb.
264 * Partner of qed_int_register_cb -> should be called
265 * when no longer required.
272 int qed_int_unregister_cb(struct qed_hwfn
*p_hwfn
,
276 * @brief qed_int_get_sp_sb_id - Get the slowhwfn sb id.
282 u16
qed_int_get_sp_sb_id(struct qed_hwfn
*p_hwfn
);
285 * @brief Status block cleanup. Should be called for each status
286 * block that will be used -> both PF / VF
290 * @param sb_id - igu status block id
291 * @param cleanup_set - set(1) / clear(0)
292 * @param opaque_fid - the function for which to perform
293 * cleanup, for example a PF on behalf of
296 void qed_int_igu_cleanup_sb(struct qed_hwfn
*p_hwfn
,
297 struct qed_ptt
*p_ptt
,
303 * @brief Status block cleanup. Should be called for each status
304 * block that will be used -> both PF / VF
308 * @param sb_id - igu status block id
309 * @param opaque - opaque fid of the sb owner.
310 * @param cleanup_set - set(1) / clear(0)
312 void qed_int_igu_init_pure_rt_single(struct qed_hwfn
*p_hwfn
,
313 struct qed_ptt
*p_ptt
,
319 * @brief qed_int_cau_conf - configure cau for a given status
329 void qed_int_cau_conf_sb(struct qed_hwfn
*p_hwfn
,
330 struct qed_ptt
*p_ptt
,
337 * @brief qed_int_alloc
344 int qed_int_alloc(struct qed_hwfn
*p_hwfn
,
345 struct qed_ptt
*p_ptt
);
348 * @brief qed_int_free
352 void qed_int_free(struct qed_hwfn
*p_hwfn
);
355 * @brief qed_int_setup
360 void qed_int_setup(struct qed_hwfn
*p_hwfn
,
361 struct qed_ptt
*p_ptt
);
364 * @brief - Enable Interrupt & Attention for hw function
370 void qed_int_igu_enable(struct qed_hwfn
*p_hwfn
,
371 struct qed_ptt
*p_ptt
,
372 enum qed_int_mode int_mode
);
375 * @brief - Initialize CAU status block entry
383 void qed_init_cau_sb_entry(struct qed_hwfn
*p_hwfn
,
384 struct cau_sb_entry
*p_sb_entry
,
389 #define QED_MAPPING_MEMORY_SIZE(dev) (NUM_OF_SBS(dev))