blob: 91424cf79f6732e245613c114b78be3f9c158416 [file] [log] [blame]
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001/* QLogic qed NIC Driver
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02002 * Copyright (c) 2015-2017 QLogic Corporation
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02003 *
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02004 * 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:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
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.
22 *
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
30 * SOFTWARE.
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020031 */
32
33#ifndef _QED_INT_H
34#define _QED_INT_H
35
36#include <linux/types.h>
37#include <linux/slab.h>
38#include "qed.h"
39
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 */
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030047/* 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 */
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020053
54/* Igu control commands
55 */
56enum igu_ctrl_cmd {
57 IGU_CTRL_CMD_TYPE_RD,
58 IGU_CTRL_CMD_TYPE_WR,
59 MAX_IGU_CTRL_CMD
60};
61
62/* Control register for the IGU command register
63 */
64struct igu_ctrl_reg {
65 u32 ctrl_data;
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
74};
75
76enum qed_coalescing_fsm {
77 QED_COAL_RX_STATE_MACHINE,
78 QED_COAL_TX_STATE_MACHINE
79};
80
81/**
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020082 * @brief qed_int_igu_enable_int - enable device interrupts
83 *
84 * @param p_hwfn
85 * @param p_ptt
86 * @param int_mode - interrupt mode to use
87 */
88void qed_int_igu_enable_int(struct qed_hwfn *p_hwfn,
89 struct qed_ptt *p_ptt,
90 enum qed_int_mode int_mode);
91
92/**
93 * @brief qed_int_igu_disable_int - disable device interrupts
94 *
95 * @param p_hwfn
96 * @param p_ptt
97 */
98void qed_int_igu_disable_int(struct qed_hwfn *p_hwfn,
99 struct qed_ptt *p_ptt);
100
101/**
102 * @brief qed_int_igu_read_sisr_reg - Reads the single isr multiple dpc
103 * register from igu.
104 *
105 * @param p_hwfn
106 *
107 * @return u64
108 */
109u64 qed_int_igu_read_sisr_reg(struct qed_hwfn *p_hwfn);
110
111#define QED_SP_SB_ID 0xffff
112/**
113 * @brief qed_int_sb_init - Initializes the sb_info structure.
114 *
115 * once the structure is initialized it can be passed to sb related functions.
116 *
117 * @param p_hwfn
118 * @param p_ptt
119 * @param sb_info points to an uninitialized (but
120 * allocated) sb_info structure
121 * @param sb_virt_addr
122 * @param sb_phy_addr
123 * @param sb_id the sb_id to be used (zero based in driver)
124 * should use QED_SP_SB_ID for SP Status block
125 *
126 * @return int
127 */
128int qed_int_sb_init(struct qed_hwfn *p_hwfn,
129 struct qed_ptt *p_ptt,
130 struct qed_sb_info *sb_info,
131 void *sb_virt_addr,
132 dma_addr_t sb_phy_addr,
133 u16 sb_id);
134/**
135 * @brief qed_int_sb_setup - Setup the sb.
136 *
137 * @param p_hwfn
138 * @param p_ptt
139 * @param sb_info initialized sb_info structure
140 */
141void qed_int_sb_setup(struct qed_hwfn *p_hwfn,
142 struct qed_ptt *p_ptt,
143 struct qed_sb_info *sb_info);
144
145/**
146 * @brief qed_int_sb_release - releases the sb_info structure.
147 *
148 * once the structure is released, it's memory can be freed
149 *
150 * @param p_hwfn
151 * @param sb_info points to an allocated sb_info structure
152 * @param sb_id the sb_id to be used (zero based in driver)
153 * should never be equal to QED_SP_SB_ID
154 * (SP Status block)
155 *
156 * @return int
157 */
158int qed_int_sb_release(struct qed_hwfn *p_hwfn,
159 struct qed_sb_info *sb_info,
160 u16 sb_id);
161
162/**
163 * @brief qed_int_sp_dpc - To be called when an interrupt is received on the
164 * default status block.
165 *
166 * @param p_hwfn - pointer to hwfn
167 *
168 */
169void qed_int_sp_dpc(unsigned long hwfn_cookie);
170
171/**
172 * @brief qed_int_get_num_sbs - get the number of status
173 * blocks configured for this funciton in the igu.
174 *
175 * @param p_hwfn
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200176 * @param p_sb_cnt_info
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200177 *
178 * @return int - number of status blocks configured
179 */
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200180void qed_int_get_num_sbs(struct qed_hwfn *p_hwfn,
181 struct qed_sb_cnt_info *p_sb_cnt_info);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200182
183/**
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500184 * @brief qed_int_disable_post_isr_release - performs the cleanup post ISR
185 * release. The API need to be called after releasing all slowpath IRQs
186 * of the device.
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200187 *
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500188 * @param cdev
189 *
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200190 */
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500191void qed_int_disable_post_isr_release(struct qed_dev *cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200192
193#define QED_CAU_DEF_RX_TIMER_RES 0
194#define QED_CAU_DEF_TX_TIMER_RES 0
195
196#define QED_SB_ATT_IDX 0x0001
197#define QED_SB_EVENT_MASK 0x0003
198
199#define SB_ALIGNED_SIZE(p_hwfn) \
200 ALIGNED_TYPE_SIZE(struct status_block, p_hwfn)
201
Mintz, Yuvald749dd02017-06-01 15:29:03 +0300202#define QED_SB_INVALID_IDX 0xffff
203
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200204struct qed_igu_block {
205 u8 status;
206#define QED_IGU_STATUS_FREE 0x01
207#define QED_IGU_STATUS_VALID 0x02
208#define QED_IGU_STATUS_PF 0x04
Mintz, Yuvald749dd02017-06-01 15:29:03 +0300209#define QED_IGU_STATUS_DSB 0x08
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200210
211 u8 vector_number;
212 u8 function_id;
213 u8 is_pf;
214};
215
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200216struct qed_igu_info {
Mintz, Yuvald749dd02017-06-01 15:29:03 +0300217 struct qed_igu_block entry[MAX_TOT_SB_PER_PATH];
218 u16 igu_dsb_id;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200219 u16 igu_base_sb;
220 u16 igu_base_sb_iov;
221 u16 igu_sb_cnt;
222 u16 igu_sb_cnt_iov;
223 u16 free_blks;
224};
225
226/* TODO Names of function may change... */
227void qed_int_igu_init_pure_rt(struct qed_hwfn *p_hwfn,
228 struct qed_ptt *p_ptt,
229 bool b_set,
230 bool b_slowpath);
231
232void qed_int_igu_init_rt(struct qed_hwfn *p_hwfn);
233
234/**
235 * @brief qed_int_igu_read_cam - Reads the IGU CAM.
236 * This function needs to be called during hardware
237 * prepare. It reads the info from igu cam to know which
238 * status block is the default / base status block etc.
239 *
240 * @param p_hwfn
241 * @param p_ptt
242 *
243 * @return int
244 */
245int qed_int_igu_read_cam(struct qed_hwfn *p_hwfn,
246 struct qed_ptt *p_ptt);
247
248typedef int (*qed_int_comp_cb_t)(struct qed_hwfn *p_hwfn,
249 void *cookie);
250/**
251 * @brief qed_int_register_cb - Register callback func for
252 * slowhwfn statusblock.
253 *
254 * Every protocol that uses the slowhwfn status block
255 * should register a callback function that will be called
256 * once there is an update of the sp status block.
257 *
258 * @param p_hwfn
259 * @param comp_cb - function to be called when there is an
260 * interrupt on the sp sb
261 *
262 * @param cookie - passed to the callback function
263 * @param sb_idx - OUT parameter which gives the chosen index
264 * for this protocol.
265 * @param p_fw_cons - pointer to the actual address of the
266 * consumer for this protocol.
267 *
268 * @return int
269 */
270int qed_int_register_cb(struct qed_hwfn *p_hwfn,
271 qed_int_comp_cb_t comp_cb,
272 void *cookie,
273 u8 *sb_idx,
274 __le16 **p_fw_cons);
275
276/**
277 * @brief qed_int_unregister_cb - Unregisters callback
278 * function from sp sb.
279 * Partner of qed_int_register_cb -> should be called
280 * when no longer required.
281 *
282 * @param p_hwfn
283 * @param pi
284 *
285 * @return int
286 */
287int qed_int_unregister_cb(struct qed_hwfn *p_hwfn,
288 u8 pi);
289
290/**
291 * @brief qed_int_get_sp_sb_id - Get the slowhwfn sb id.
292 *
293 * @param p_hwfn
294 *
295 * @return u16
296 */
297u16 qed_int_get_sp_sb_id(struct qed_hwfn *p_hwfn);
298
299/**
300 * @brief Status block cleanup. Should be called for each status
301 * block that will be used -> both PF / VF
302 *
303 * @param p_hwfn
304 * @param p_ptt
305 * @param sb_id - igu status block id
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200306 * @param opaque - opaque fid of the sb owner.
Yuval Mintzb2b897e2016-05-15 14:48:06 +0300307 * @param b_set - set(1) / clear(0)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200308 */
309void qed_int_igu_init_pure_rt_single(struct qed_hwfn *p_hwfn,
310 struct qed_ptt *p_ptt,
311 u32 sb_id,
312 u16 opaque,
313 bool b_set);
314
315/**
316 * @brief qed_int_cau_conf - configure cau for a given status
317 * block
318 *
319 * @param p_hwfn
320 * @param ptt
321 * @param sb_phys
322 * @param igu_sb_id
323 * @param vf_number
324 * @param vf_valid
325 */
326void qed_int_cau_conf_sb(struct qed_hwfn *p_hwfn,
327 struct qed_ptt *p_ptt,
328 dma_addr_t sb_phys,
329 u16 igu_sb_id,
330 u16 vf_number,
331 u8 vf_valid);
332
333/**
334 * @brief qed_int_alloc
335 *
336 * @param p_hwfn
337 * @param p_ptt
338 *
339 * @return int
340 */
341int qed_int_alloc(struct qed_hwfn *p_hwfn,
342 struct qed_ptt *p_ptt);
343
344/**
345 * @brief qed_int_free
346 *
347 * @param p_hwfn
348 */
349void qed_int_free(struct qed_hwfn *p_hwfn);
350
351/**
352 * @brief qed_int_setup
353 *
354 * @param p_hwfn
355 * @param p_ptt
356 */
357void qed_int_setup(struct qed_hwfn *p_hwfn,
358 struct qed_ptt *p_ptt);
359
360/**
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300361 * @brief - Returns an Rx queue index appropriate for usage with given SB.
362 *
363 * @param p_hwfn
364 * @param sb_id - absolute index of SB
365 *
366 * @return index of Rx queue
367 */
368u16 qed_int_queue_id_from_sb_id(struct qed_hwfn *p_hwfn, u16 sb_id);
369
370/**
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200371 * @brief - Enable Interrupt & Attention for hw function
372 *
373 * @param p_hwfn
374 * @param p_ptt
375 * @param int_mode
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500376 *
377 * @return int
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200378 */
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500379int qed_int_igu_enable(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
380 enum qed_int_mode int_mode);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200381
382/**
383 * @brief - Initialize CAU status block entry
384 *
385 * @param p_hwfn
386 * @param p_sb_entry
387 * @param pf_id
388 * @param vf_number
389 * @param vf_valid
390 */
391void qed_init_cau_sb_entry(struct qed_hwfn *p_hwfn,
392 struct cau_sb_entry *p_sb_entry,
393 u8 pf_id,
394 u16 vf_number,
395 u8 vf_valid);
396
Sudarsana Reddy Kalluru722003a2016-06-21 09:36:21 -0400397int qed_int_set_timer_res(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
398 u8 timer_res, u16 sb_id, bool tx);
399
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200400#define QED_MAPPING_MEMORY_SIZE(dev) (NUM_OF_SBS(dev))
401
402#endif