1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 #include <linux/types.h>
37 #include <linux/slab.h>
40 /* Fields of IGU PF CONFIGRATION REGISTER */
41 #define IGU_PF_CONF_FUNC_EN (0x1 << 0) /* function enable */
42 #define IGU_PF_CONF_MSI_MSIX_EN (0x1 << 1) /* MSI/MSIX enable */
43 #define IGU_PF_CONF_INT_LINE_EN (0x1 << 2) /* INT enable */
44 #define IGU_PF_CONF_ATTN_BIT_EN (0x1 << 3) /* attention enable */
45 #define IGU_PF_CONF_SINGLE_ISR_EN (0x1 << 4) /* single ISR mode enable */
46 #define IGU_PF_CONF_SIMD_MODE (0x1 << 5) /* simd all ones mode */
47 /* Fields of IGU VF CONFIGRATION REGISTER */
48 #define IGU_VF_CONF_FUNC_EN (0x1 << 0) /* function enable */
49 #define IGU_VF_CONF_MSI_MSIX_EN (0x1 << 1) /* MSI/MSIX enable */
50 #define IGU_VF_CONF_SINGLE_ISR_EN (0x1 << 4) /* single ISR mode enable */
51 #define IGU_VF_CONF_PARENT_MASK (0xF) /* Parent PF */
52 #define IGU_VF_CONF_PARENT_SHIFT 5 /* Parent PF */
54 /* Igu control commands
62 /* Control register for the IGU command register
66 #define IGU_CTRL_REG_FID_MASK 0xFFFF /* Opaque_FID */
67 #define IGU_CTRL_REG_FID_SHIFT 0
68 #define IGU_CTRL_REG_PXP_ADDR_MASK 0xFFF /* Command address */
69 #define IGU_CTRL_REG_PXP_ADDR_SHIFT 16
70 #define IGU_CTRL_REG_RESERVED_MASK 0x1
71 #define IGU_CTRL_REG_RESERVED_SHIFT 28
72 #define IGU_CTRL_REG_TYPE_MASK 0x1 /* use enum igu_ctrl_cmd */
73 #define IGU_CTRL_REG_TYPE_SHIFT 31
76 enum qed_coalescing_fsm
{
77 QED_COAL_RX_STATE_MACHINE
,
78 QED_COAL_TX_STATE_MACHINE
82 * @brief qed_int_cau_conf_pi - configure cau for a given
92 void qed_int_cau_conf_pi(struct qed_hwfn
*p_hwfn
,
93 struct qed_ptt
*p_ptt
,
96 enum qed_coalescing_fsm coalescing_fsm
,
100 * @brief qed_int_igu_enable_int - enable device interrupts
104 * @param int_mode - interrupt mode to use
106 void qed_int_igu_enable_int(struct qed_hwfn
*p_hwfn
,
107 struct qed_ptt
*p_ptt
,
108 enum qed_int_mode int_mode
);
111 * @brief qed_int_igu_disable_int - disable device interrupts
116 void qed_int_igu_disable_int(struct qed_hwfn
*p_hwfn
,
117 struct qed_ptt
*p_ptt
);
120 * @brief qed_int_igu_read_sisr_reg - Reads the single isr multiple dpc
127 u64
qed_int_igu_read_sisr_reg(struct qed_hwfn
*p_hwfn
);
129 #define QED_SP_SB_ID 0xffff
131 * @brief qed_int_sb_init - Initializes the sb_info structure.
133 * once the structure is initialized it can be passed to sb related functions.
137 * @param sb_info points to an uninitialized (but
138 * allocated) sb_info structure
139 * @param sb_virt_addr
141 * @param sb_id the sb_id to be used (zero based in driver)
142 * should use QED_SP_SB_ID for SP Status block
146 int qed_int_sb_init(struct qed_hwfn
*p_hwfn
,
147 struct qed_ptt
*p_ptt
,
148 struct qed_sb_info
*sb_info
,
150 dma_addr_t sb_phy_addr
,
153 * @brief qed_int_sb_setup - Setup the sb.
157 * @param sb_info initialized sb_info structure
159 void qed_int_sb_setup(struct qed_hwfn
*p_hwfn
,
160 struct qed_ptt
*p_ptt
,
161 struct qed_sb_info
*sb_info
);
164 * @brief qed_int_sb_release - releases the sb_info structure.
166 * once the structure is released, it's memory can be freed
169 * @param sb_info points to an allocated sb_info structure
170 * @param sb_id the sb_id to be used (zero based in driver)
171 * should never be equal to QED_SP_SB_ID
176 int qed_int_sb_release(struct qed_hwfn
*p_hwfn
,
177 struct qed_sb_info
*sb_info
,
181 * @brief qed_int_sp_dpc - To be called when an interrupt is received on the
182 * default status block.
184 * @param p_hwfn - pointer to hwfn
187 void qed_int_sp_dpc(unsigned long hwfn_cookie
);
190 * @brief qed_int_get_num_sbs - get the number of status
191 * blocks configured for this funciton in the igu.
194 * @param p_sb_cnt_info
196 * @return int - number of status blocks configured
198 void qed_int_get_num_sbs(struct qed_hwfn
*p_hwfn
,
199 struct qed_sb_cnt_info
*p_sb_cnt_info
);
202 * @brief qed_int_disable_post_isr_release - performs the cleanup post ISR
203 * release. The API need to be called after releasing all slowpath IRQs
209 void qed_int_disable_post_isr_release(struct qed_dev
*cdev
);
211 #define QED_CAU_DEF_RX_TIMER_RES 0
212 #define QED_CAU_DEF_TX_TIMER_RES 0
214 #define QED_SB_ATT_IDX 0x0001
215 #define QED_SB_EVENT_MASK 0x0003
217 #define SB_ALIGNED_SIZE(p_hwfn) \
218 ALIGNED_TYPE_SIZE(struct status_block, p_hwfn)
220 struct qed_igu_block
{
222 #define QED_IGU_STATUS_FREE 0x01
223 #define QED_IGU_STATUS_VALID 0x02
224 #define QED_IGU_STATUS_PF 0x04
232 struct qed_igu_block igu_blocks
[MAX_TOT_SB_PER_PATH
];
235 struct qed_igu_info
{
236 struct qed_igu_map igu_map
;
245 /* TODO Names of function may change... */
246 void qed_int_igu_init_pure_rt(struct qed_hwfn
*p_hwfn
,
247 struct qed_ptt
*p_ptt
,
251 void qed_int_igu_init_rt(struct qed_hwfn
*p_hwfn
);
254 * @brief qed_int_igu_read_cam - Reads the IGU CAM.
255 * This function needs to be called during hardware
256 * prepare. It reads the info from igu cam to know which
257 * status block is the default / base status block etc.
264 int qed_int_igu_read_cam(struct qed_hwfn
*p_hwfn
,
265 struct qed_ptt
*p_ptt
);
267 typedef int (*qed_int_comp_cb_t
)(struct qed_hwfn
*p_hwfn
,
270 * @brief qed_int_register_cb - Register callback func for
271 * slowhwfn statusblock.
273 * Every protocol that uses the slowhwfn status block
274 * should register a callback function that will be called
275 * once there is an update of the sp status block.
278 * @param comp_cb - function to be called when there is an
279 * interrupt on the sp sb
281 * @param cookie - passed to the callback function
282 * @param sb_idx - OUT parameter which gives the chosen index
284 * @param p_fw_cons - pointer to the actual address of the
285 * consumer for this protocol.
289 int qed_int_register_cb(struct qed_hwfn
*p_hwfn
,
290 qed_int_comp_cb_t comp_cb
,
296 * @brief qed_int_unregister_cb - Unregisters callback
297 * function from sp sb.
298 * Partner of qed_int_register_cb -> should be called
299 * when no longer required.
306 int qed_int_unregister_cb(struct qed_hwfn
*p_hwfn
,
310 * @brief qed_int_get_sp_sb_id - Get the slowhwfn sb id.
316 u16
qed_int_get_sp_sb_id(struct qed_hwfn
*p_hwfn
);
319 * @brief Status block cleanup. Should be called for each status
320 * block that will be used -> both PF / VF
324 * @param sb_id - igu status block id
325 * @param opaque - opaque fid of the sb owner.
326 * @param b_set - set(1) / clear(0)
328 void qed_int_igu_init_pure_rt_single(struct qed_hwfn
*p_hwfn
,
329 struct qed_ptt
*p_ptt
,
335 * @brief qed_int_cau_conf - configure cau for a given status
345 void qed_int_cau_conf_sb(struct qed_hwfn
*p_hwfn
,
346 struct qed_ptt
*p_ptt
,
353 * @brief qed_int_alloc
360 int qed_int_alloc(struct qed_hwfn
*p_hwfn
,
361 struct qed_ptt
*p_ptt
);
364 * @brief qed_int_free
368 void qed_int_free(struct qed_hwfn
*p_hwfn
);
371 * @brief qed_int_setup
376 void qed_int_setup(struct qed_hwfn
*p_hwfn
,
377 struct qed_ptt
*p_ptt
);
380 * @brief - Returns an Rx queue index appropriate for usage with given SB.
383 * @param sb_id - absolute index of SB
385 * @return index of Rx queue
387 u16
qed_int_queue_id_from_sb_id(struct qed_hwfn
*p_hwfn
, u16 sb_id
);
390 * @brief - Enable Interrupt & Attention for hw function
398 int qed_int_igu_enable(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
,
399 enum qed_int_mode int_mode
);
402 * @brief - Initialize CAU status block entry
410 void qed_init_cau_sb_entry(struct qed_hwfn
*p_hwfn
,
411 struct cau_sb_entry
*p_sb_entry
,
416 int qed_int_set_timer_res(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
,
417 u8 timer_res
, u16 sb_id
, bool tx
);
419 #define QED_MAPPING_MEMORY_SIZE(dev) (NUM_OF_SBS(dev))