summaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/qlogic/qed/qed_int.h
blob: 84c17e97f5692cffd11c7890cf7a4bbcddabdf70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
/* QLogic qed NIC Driver
 * Copyright (c) 2015-2017  QLogic Corporation
 * Copyright (c) 2019-2020 Marvell International Ltd.
 */

#ifndef _QED_INT_H
#define _QED_INT_H

#include <linux/types.h>
#include <linux/slab.h>
#include "qed.h"

/* Fields of IGU PF CONFIGURATION REGISTER */
#define IGU_PF_CONF_FUNC_EN       (0x1 << 0)    /* function enable        */
#define IGU_PF_CONF_MSI_MSIX_EN   (0x1 << 1)    /* MSI/MSIX enable        */
#define IGU_PF_CONF_INT_LINE_EN   (0x1 << 2)    /* INT enable             */
#define IGU_PF_CONF_ATTN_BIT_EN   (0x1 << 3)    /* attention enable       */
#define IGU_PF_CONF_SINGLE_ISR_EN (0x1 << 4)    /* single ISR mode enable */
#define IGU_PF_CONF_SIMD_MODE     (0x1 << 5)    /* simd all ones mode     */
/* Fields of IGU VF CONFIGURATION REGISTER */
#define IGU_VF_CONF_FUNC_EN        (0x1 << 0)	/* function enable        */
#define IGU_VF_CONF_MSI_MSIX_EN    (0x1 << 1)	/* MSI/MSIX enable        */
#define IGU_VF_CONF_SINGLE_ISR_EN  (0x1 << 4)	/* single ISR mode enable */
#define IGU_VF_CONF_PARENT_MASK    (0xF)	/* Parent PF              */
#define IGU_VF_CONF_PARENT_SHIFT   5		/* Parent PF              */

/* Igu control commands
 */
enum igu_ctrl_cmd {
	IGU_CTRL_CMD_TYPE_RD,
	IGU_CTRL_CMD_TYPE_WR,
	MAX_IGU_CTRL_CMD
};

/* Control register for the IGU command register
 */
struct igu_ctrl_reg {
	u32 ctrl_data;
#define IGU_CTRL_REG_FID_MASK           0xFFFF  /* Opaque_FID	 */
#define IGU_CTRL_REG_FID_SHIFT          0
#define IGU_CTRL_REG_PXP_ADDR_MASK      0xFFF   /* Command address */
#define IGU_CTRL_REG_PXP_ADDR_SHIFT     16
#define IGU_CTRL_REG_RESERVED_MASK      0x1
#define IGU_CTRL_REG_RESERVED_SHIFT     28
#define IGU_CTRL_REG_TYPE_MASK          0x1 /* use enum igu_ctrl_cmd */
#define IGU_CTRL_REG_TYPE_SHIFT         31
};

enum qed_coalescing_fsm {
	QED_COAL_RX_STATE_MACHINE,
	QED_COAL_TX_STATE_MACHINE
};

/**
 * qed_int_igu_enable_int(): Enable device interrupts.
 *
 * @p_hwfn: HW device data.
 * @p_ptt: P_ptt.
 * @int_mode: Interrupt mode to use.
 *
 * Return: Void.
 */
void qed_int_igu_enable_int(struct qed_hwfn *p_hwfn,
			    struct qed_ptt *p_ptt,
			    enum qed_int_mode int_mode);

/**
 * qed_int_igu_disable_int():  Disable device interrupts.
 *
 * @p_hwfn: HW device data.
 * @p_ptt: P_ptt.
 *
 * Return: Void.
 */
void qed_int_igu_disable_int(struct qed_hwfn *p_hwfn,
			     struct qed_ptt *p_ptt);

/**
 * qed_int_igu_read_sisr_reg(): Reads the single isr multiple dpc
 *                             register from igu.
 *
 * @p_hwfn: HW device data.
 *
 * Return: u64.
 */
u64 qed_int_igu_read_sisr_reg(struct qed_hwfn *p_hwfn);

#define QED_SP_SB_ID 0xffff
/**
 * qed_int_sb_init(): Initializes the sb_info structure.
 *
 * @p_hwfn: HW device data.
 * @p_ptt: P_ptt.
 * @sb_info: points to an uninitialized (but allocated) sb_info structure
 * @sb_virt_addr: SB Virtual address.
 * @sb_phy_addr: SB Physial address.
 * @sb_id: the sb_id to be used (zero based in driver)
 *           should use QED_SP_SB_ID for SP Status block
 *
 * Return: int.
 *
 * Once the structure is initialized it can be passed to sb related functions.
 */
int qed_int_sb_init(struct qed_hwfn *p_hwfn,
		    struct qed_ptt *p_ptt,
		    struct qed_sb_info *sb_info,
		    void *sb_virt_addr,
		    dma_addr_t sb_phy_addr,
		    u16 sb_id);
/**
 * qed_int_sb_setup(): Setup the sb.
 *
 * @p_hwfn: HW device data.
 * @p_ptt: P_ptt.
 * @sb_info: Initialized sb_info structure.
 *
 * Return: Void.
 */
void qed_int_sb_setup(struct qed_hwfn *p_hwfn,
		      struct qed_ptt *p_ptt,
		      struct qed_sb_info *sb_info);

/**
 * qed_int_sb_release(): Releases the sb_info structure.
 *
 * @p_hwfn: HW device data.
 * @sb_info: Points to an allocated sb_info structure.
 * @sb_id: The sb_id to be used (zero based in driver)
 *         should never be equal to QED_SP_SB_ID
 *         (SP Status block).
 *
 * Return: int.
 *
 * Once the structure is released, it's memory can be freed.
 */
int qed_int_sb_release(struct qed_hwfn *p_hwfn,
		       struct qed_sb_info *sb_info,
		       u16 sb_id);

/**
 * qed_int_sp_dpc(): To be called when an interrupt is received on the
 *                   default status block.
 *
 * @t: Tasklet.
 *
 * Return: Void.
 *
 */
void qed_int_sp_dpc(struct tasklet_struct *t);

/**
 * qed_int_get_num_sbs(): Get the number of status blocks configured
 *                        for this funciton in the igu.
 *
 * @p_hwfn: HW device data.
 * @p_sb_cnt_info: Pointer to SB count info.
 *
 * Return: Void.
 */
void qed_int_get_num_sbs(struct qed_hwfn	*p_hwfn,
			 struct qed_sb_cnt_info *p_sb_cnt_info);

/**
 * qed_int_disable_post_isr_release(): Performs the cleanup post ISR
 *        release. The API need to be called after releasing all slowpath IRQs
 *        of the device.
 *
 * @cdev: Qed dev pointer.
 *
 * Return: Void.
 */
void qed_int_disable_post_isr_release(struct qed_dev *cdev);

/**
 * qed_int_attn_clr_enable: Sets whether the general behavior is
 *        preventing attentions from being reasserted, or following the
 *        attributes of the specific attention.
 *
 * @cdev: Qed dev pointer.
 * @clr_enable: Clear enable
 *
 * Return: Void.
 *
 */
void qed_int_attn_clr_enable(struct qed_dev *cdev, bool clr_enable);

/**
 * qed_db_rec_handler(): Doorbell Recovery handler.
 *          Run doorbell recovery in case of PF overflow (and flush DORQ if
 *          needed).
 *
 * @p_hwfn: HW device data.
 * @p_ptt: P_ptt.
 *
 * Return: Int.
 */
int qed_db_rec_handler(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);

#define QED_CAU_DEF_RX_TIMER_RES 0
#define QED_CAU_DEF_TX_TIMER_RES 0

#define QED_SB_ATT_IDX  0x0001
#define QED_SB_EVENT_MASK       0x0003

#define SB_ALIGNED_SIZE(p_hwfn)	\
	ALIGNED_TYPE_SIZE(struct status_block, p_hwfn)

#define QED_SB_INVALID_IDX      0xffff

struct qed_igu_block {
	u8 status;
#define QED_IGU_STATUS_FREE     0x01
#define QED_IGU_STATUS_VALID    0x02
#define QED_IGU_STATUS_PF       0x04
#define QED_IGU_STATUS_DSB      0x08

	u8 vector_number;
	u8 function_id;
	u8 is_pf;

	/* Index inside IGU [meant for back reference] */
	u16 igu_sb_id;

	struct qed_sb_info *sb_info;
};

struct qed_igu_info {
	struct qed_igu_block entry[MAX_TOT_SB_PER_PATH];
	u16 igu_dsb_id;

	struct qed_sb_cnt_info usage;

	bool b_allow_pf_vf_change;
};

/**
 * qed_int_igu_reset_cam(): Make sure the IGU CAM reflects the resources
 *                          provided by MFW.
 *
 * @p_hwfn: HW device data.
 * @p_ptt: P_ptt.
 *
 * Return: Void.
 */
int qed_int_igu_reset_cam(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);

/**
 * qed_get_igu_sb_id(): Translate the weakly-defined client sb-id into
 *                      an IGU sb-id
 *
 * @p_hwfn: HW device data.
 * @sb_id: user provided sb_id.
 *
 * Return: An index inside IGU CAM where the SB resides.
 */
u16 qed_get_igu_sb_id(struct qed_hwfn *p_hwfn, u16 sb_id);

/**
 * qed_get_igu_free_sb(): Return a pointer to an unused valid SB
 *
 * @p_hwfn: HW device data.
 * @b_is_pf: True iff we want a SB belonging to a PF.
 *
 * Return: Point to an igu_block, NULL if none is available.
 */
struct qed_igu_block *qed_get_igu_free_sb(struct qed_hwfn *p_hwfn,
					  bool b_is_pf);

void qed_int_igu_init_pure_rt(struct qed_hwfn *p_hwfn,
			      struct qed_ptt *p_ptt,
			      bool b_set,
			      bool b_slowpath);

void qed_int_igu_init_rt(struct qed_hwfn *p_hwfn);

/**
 * qed_int_igu_read_cam():  Reads the IGU CAM.
 *	This function needs to be called during hardware
 *	prepare. It reads the info from igu cam to know which
 *	status block is the default / base status block etc.
 *
 * @p_hwfn: HW device data.
 * @p_ptt: P_ptt.
 *
 * Return: Int.
 */
int qed_int_igu_read_cam(struct qed_hwfn *p_hwfn,
			 struct qed_ptt *p_ptt);

typedef int (*qed_int_comp_cb_t)(struct qed_hwfn *p_hwfn,
				 void *cookie);
/**
 * qed_int_register_cb(): Register callback func for slowhwfn statusblock.
 *
 * @p_hwfn: HW device data.
 * @comp_cb: Function to be called when there is an
 *           interrupt on the sp sb
 * @cookie: Passed to the callback function
 * @sb_idx: (OUT) parameter which gives the chosen index
 *           for this protocol.
 * @p_fw_cons: Pointer to the actual address of the
 *             consumer for this protocol.
 *
 * Return: Int.
 *
 * Every protocol that uses the slowhwfn status block
 * should register a callback function that will be called
 * once there is an update of the sp status block.
 */
int qed_int_register_cb(struct qed_hwfn *p_hwfn,
			qed_int_comp_cb_t comp_cb,
			void *cookie,
			u8 *sb_idx,
			__le16 **p_fw_cons);

/**
 * qed_int_unregister_cb(): Unregisters callback function from sp sb.
 *
 * @p_hwfn: HW device data.
 * @pi: Producer Index.
 *
 * Return: Int.
 *
 * Partner of qed_int_register_cb -> should be called
 * when no longer required.
 */
int qed_int_unregister_cb(struct qed_hwfn *p_hwfn,
			  u8 pi);

/**
 * qed_int_get_sp_sb_id(): Get the slowhwfn sb id.
 *
 * @p_hwfn: HW device data.
 *
 * Return: u16.
 */
u16 qed_int_get_sp_sb_id(struct qed_hwfn *p_hwfn);

/**
 * qed_int_igu_init_pure_rt_single(): Status block cleanup.
 *                                    Should be called for each status
 *                                    block that will be used -> both PF / VF.
 *
 * @p_hwfn: HW device data.
 * @p_ptt: P_ptt.
 * @igu_sb_id: IGU status block id.
 * @opaque: Opaque fid of the sb owner.
 * @b_set: Set(1) / Clear(0).
 *
 * Return: Void.
 */
void qed_int_igu_init_pure_rt_single(struct qed_hwfn *p_hwfn,
				     struct qed_ptt *p_ptt,
				     u16 igu_sb_id,
				     u16 opaque,
				     bool b_set);

/**
 * qed_int_cau_conf_sb(): Configure cau for a given status block.
 *
 * @p_hwfn: HW device data.
 * @p_ptt: P_ptt.
 * @sb_phys: SB Physical.
 * @igu_sb_id: IGU status block id.
 * @vf_number: VF number
 * @vf_valid: VF valid or not.
 *
 * Return: Void.
 */
void qed_int_cau_conf_sb(struct qed_hwfn *p_hwfn,
			 struct qed_ptt *p_ptt,
			 dma_addr_t sb_phys,
			 u16 igu_sb_id,
			 u16 vf_number,
			 u8 vf_valid);

/**
 * qed_int_alloc(): QED interrupt alloc.
 *
 * @p_hwfn: HW device data.
 * @p_ptt: P_ptt.
 *
 * Return: Int.
 */
int qed_int_alloc(struct qed_hwfn *p_hwfn,
		  struct qed_ptt *p_ptt);

/**
 * qed_int_free(): QED interrupt free.
 *
 * @p_hwfn: HW device data.
 *
 * Return: Void.
 */
void qed_int_free(struct qed_hwfn *p_hwfn);

/**
 * qed_int_setup(): QED interrupt setup.
 *
 * @p_hwfn: HW device data.
 * @p_ptt: P_ptt.
 *
 * Return: Void.
 */
void qed_int_setup(struct qed_hwfn *p_hwfn,
		   struct qed_ptt *p_ptt);

/**
 * qed_int_igu_enable(): Enable Interrupt & Attention for hw function.
 *
 * @p_hwfn: HW device data.
 * @p_ptt: P_ptt.
 * @int_mode: Interrut mode
 *
 * Return: Int.
 */
int qed_int_igu_enable(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
		       enum qed_int_mode int_mode);

/**
 * qed_init_cau_sb_entry(): Initialize CAU status block entry.
 *
 * @p_hwfn: HW device data.
 * @p_sb_entry: Pointer SB entry.
 * @pf_id: PF number
 * @vf_number: VF number
 * @vf_valid: VF valid or not.
 *
 * Return: Void.
 */
void qed_init_cau_sb_entry(struct qed_hwfn *p_hwfn,
			   struct cau_sb_entry *p_sb_entry,
			   u8 pf_id,
			   u16 vf_number,
			   u8 vf_valid);

int qed_int_set_timer_res(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
			  u8 timer_res, u16 sb_id, bool tx);

#define QED_MAPPING_MEMORY_SIZE(dev)	(NUM_OF_SBS(dev))

int qed_pglueb_rbc_attn_handler(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
				bool hw_init);

#endif