blob: 7fd1be61de5c29a8022f34fcc163612d8b1443ff [file] [log] [blame]
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001/* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
3 *
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
6 * this source tree.
7 */
8
9#include <linux/types.h>
10#include <asm/byteorder.h>
11#include <linux/io.h>
12#include <linux/bitops.h>
13#include <linux/delay.h>
14#include <linux/dma-mapping.h>
15#include <linux/errno.h>
16#include <linux/interrupt.h>
17#include <linux/kernel.h>
18#include <linux/pci.h>
19#include <linux/slab.h>
20#include <linux/string.h>
21#include "qed.h"
22#include "qed_hsi.h"
23#include "qed_hw.h"
24#include "qed_init_ops.h"
25#include "qed_int.h"
26#include "qed_mcp.h"
27#include "qed_reg_addr.h"
28#include "qed_sp.h"
29
30struct qed_pi_info {
31 qed_int_comp_cb_t comp_cb;
32 void *cookie;
33};
34
35struct qed_sb_sp_info {
36 struct qed_sb_info sb_info;
37
38 /* per protocol index data */
39 struct qed_pi_info pi_info_arr[PIS_PER_SB];
40};
41
Yuval Mintzcc875c22015-10-26 11:02:31 +020042#define SB_ATTN_ALIGNED_SIZE(p_hwfn) \
43 ALIGNED_TYPE_SIZE(struct atten_status_block, p_hwfn)
44
45#define ATTN_STATE_BITS (0xfff)
46#define ATTN_BITS_MASKABLE (0x3ff)
47struct qed_sb_attn_info {
48 /* Virtual & Physical address of the SB */
49 struct atten_status_block *sb_attn;
50 dma_addr_t sb_phys;
51
52 /* Last seen running index */
53 u16 index;
54
55 /* Previously asserted attentions, which are still unasserted */
56 u16 known_attn;
57
58 /* Cleanup address for the link's general hw attention */
59 u32 mfw_attn_addr;
60};
61
62static inline u16 qed_attn_update_idx(struct qed_hwfn *p_hwfn,
63 struct qed_sb_attn_info *p_sb_desc)
64{
65 u16 rc = 0;
66 u16 index;
67
68 /* Make certain HW write took affect */
69 mmiowb();
70
71 index = le16_to_cpu(p_sb_desc->sb_attn->sb_index);
72 if (p_sb_desc->index != index) {
73 p_sb_desc->index = index;
74 rc = QED_SB_ATT_IDX;
75 }
76
77 /* Make certain we got a consistent view with HW */
78 mmiowb();
79
80 return rc;
81}
82
83/**
84 * @brief qed_int_assertion - handles asserted attention bits
85 *
86 * @param p_hwfn
87 * @param asserted_bits newly asserted bits
88 * @return int
89 */
90static int qed_int_assertion(struct qed_hwfn *p_hwfn,
91 u16 asserted_bits)
92{
93 struct qed_sb_attn_info *sb_attn_sw = p_hwfn->p_sb_attn;
94 u32 igu_mask;
95
96 /* Mask the source of the attention in the IGU */
97 igu_mask = qed_rd(p_hwfn, p_hwfn->p_dpc_ptt,
98 IGU_REG_ATTENTION_ENABLE);
99 DP_VERBOSE(p_hwfn, NETIF_MSG_INTR, "IGU mask: 0x%08x --> 0x%08x\n",
100 igu_mask, igu_mask & ~(asserted_bits & ATTN_BITS_MASKABLE));
101 igu_mask &= ~(asserted_bits & ATTN_BITS_MASKABLE);
102 qed_wr(p_hwfn, p_hwfn->p_dpc_ptt, IGU_REG_ATTENTION_ENABLE, igu_mask);
103
104 DP_VERBOSE(p_hwfn, NETIF_MSG_INTR,
105 "inner known ATTN state: 0x%04x --> 0x%04x\n",
106 sb_attn_sw->known_attn,
107 sb_attn_sw->known_attn | asserted_bits);
108 sb_attn_sw->known_attn |= asserted_bits;
109
110 /* Handle MCP events */
111 if (asserted_bits & 0x100) {
112 qed_mcp_handle_events(p_hwfn, p_hwfn->p_dpc_ptt);
113 /* Clean the MCP attention */
114 qed_wr(p_hwfn, p_hwfn->p_dpc_ptt,
115 sb_attn_sw->mfw_attn_addr, 0);
116 }
117
118 DIRECT_REG_WR((u8 __iomem *)p_hwfn->regview +
119 GTT_BAR0_MAP_REG_IGU_CMD +
120 ((IGU_CMD_ATTN_BIT_SET_UPPER -
121 IGU_CMD_INT_ACK_BASE) << 3),
122 (u32)asserted_bits);
123
124 DP_VERBOSE(p_hwfn, NETIF_MSG_INTR, "set cmd IGU: 0x%04x\n",
125 asserted_bits);
126
127 return 0;
128}
129
130/**
131 * @brief - handles deassertion of previously asserted attentions.
132 *
133 * @param p_hwfn
134 * @param deasserted_bits - newly deasserted bits
135 * @return int
136 *
137 */
138static int qed_int_deassertion(struct qed_hwfn *p_hwfn,
139 u16 deasserted_bits)
140{
141 struct qed_sb_attn_info *sb_attn_sw = p_hwfn->p_sb_attn;
142 u32 aeu_mask;
143
144 if (deasserted_bits != 0x100)
145 DP_ERR(p_hwfn, "Unexpected - non-link deassertion\n");
146
147 /* Clear IGU indication for the deasserted bits */
148 DIRECT_REG_WR((u8 __iomem *)p_hwfn->regview +
149 GTT_BAR0_MAP_REG_IGU_CMD +
150 ((IGU_CMD_ATTN_BIT_CLR_UPPER -
151 IGU_CMD_INT_ACK_BASE) << 3),
152 ~((u32)deasserted_bits));
153
154 /* Unmask deasserted attentions in IGU */
155 aeu_mask = qed_rd(p_hwfn, p_hwfn->p_dpc_ptt,
156 IGU_REG_ATTENTION_ENABLE);
157 aeu_mask |= (deasserted_bits & ATTN_BITS_MASKABLE);
158 qed_wr(p_hwfn, p_hwfn->p_dpc_ptt, IGU_REG_ATTENTION_ENABLE, aeu_mask);
159
160 /* Clear deassertion from inner state */
161 sb_attn_sw->known_attn &= ~deasserted_bits;
162
163 return 0;
164}
165
166static int qed_int_attentions(struct qed_hwfn *p_hwfn)
167{
168 struct qed_sb_attn_info *p_sb_attn_sw = p_hwfn->p_sb_attn;
169 struct atten_status_block *p_sb_attn = p_sb_attn_sw->sb_attn;
170 u32 attn_bits = 0, attn_acks = 0;
171 u16 asserted_bits, deasserted_bits;
172 __le16 index;
173 int rc = 0;
174
175 /* Read current attention bits/acks - safeguard against attentions
176 * by guaranting work on a synchronized timeframe
177 */
178 do {
179 index = p_sb_attn->sb_index;
180 attn_bits = le32_to_cpu(p_sb_attn->atten_bits);
181 attn_acks = le32_to_cpu(p_sb_attn->atten_ack);
182 } while (index != p_sb_attn->sb_index);
183 p_sb_attn->sb_index = index;
184
185 /* Attention / Deassertion are meaningful (and in correct state)
186 * only when they differ and consistent with known state - deassertion
187 * when previous attention & current ack, and assertion when current
188 * attention with no previous attention
189 */
190 asserted_bits = (attn_bits & ~attn_acks & ATTN_STATE_BITS) &
191 ~p_sb_attn_sw->known_attn;
192 deasserted_bits = (~attn_bits & attn_acks & ATTN_STATE_BITS) &
193 p_sb_attn_sw->known_attn;
194
195 if ((asserted_bits & ~0x100) || (deasserted_bits & ~0x100)) {
196 DP_INFO(p_hwfn,
197 "Attention: Index: 0x%04x, Bits: 0x%08x, Acks: 0x%08x, asserted: 0x%04x, De-asserted 0x%04x [Prev. known: 0x%04x]\n",
198 index, attn_bits, attn_acks, asserted_bits,
199 deasserted_bits, p_sb_attn_sw->known_attn);
200 } else if (asserted_bits == 0x100) {
201 DP_INFO(p_hwfn,
202 "MFW indication via attention\n");
203 } else {
204 DP_VERBOSE(p_hwfn, NETIF_MSG_INTR,
205 "MFW indication [deassertion]\n");
206 }
207
208 if (asserted_bits) {
209 rc = qed_int_assertion(p_hwfn, asserted_bits);
210 if (rc)
211 return rc;
212 }
213
214 if (deasserted_bits) {
215 rc = qed_int_deassertion(p_hwfn, deasserted_bits);
216 if (rc)
217 return rc;
218 }
219
220 return rc;
221}
222
223static void qed_sb_ack_attn(struct qed_hwfn *p_hwfn,
224 void __iomem *igu_addr,
225 u32 ack_cons)
226{
227 struct igu_prod_cons_update igu_ack = { 0 };
228
229 igu_ack.sb_id_and_flags =
230 ((ack_cons << IGU_PROD_CONS_UPDATE_SB_INDEX_SHIFT) |
231 (1 << IGU_PROD_CONS_UPDATE_UPDATE_FLAG_SHIFT) |
232 (IGU_INT_NOP << IGU_PROD_CONS_UPDATE_ENABLE_INT_SHIFT) |
233 (IGU_SEG_ACCESS_ATTN <<
234 IGU_PROD_CONS_UPDATE_SEGMENT_ACCESS_SHIFT));
235
236 DIRECT_REG_WR(igu_addr, igu_ack.sb_id_and_flags);
237
238 /* Both segments (interrupts & acks) are written to same place address;
239 * Need to guarantee all commands will be received (in-order) by HW.
240 */
241 mmiowb();
242 barrier();
243}
244
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200245void qed_int_sp_dpc(unsigned long hwfn_cookie)
246{
247 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)hwfn_cookie;
248 struct qed_pi_info *pi_info = NULL;
Yuval Mintzcc875c22015-10-26 11:02:31 +0200249 struct qed_sb_attn_info *sb_attn;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200250 struct qed_sb_info *sb_info;
251 int arr_size;
252 u16 rc = 0;
253
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200254 if (!p_hwfn->p_sp_sb) {
255 DP_ERR(p_hwfn->cdev, "DPC called - no p_sp_sb\n");
256 return;
257 }
258
259 sb_info = &p_hwfn->p_sp_sb->sb_info;
260 arr_size = ARRAY_SIZE(p_hwfn->p_sp_sb->pi_info_arr);
261 if (!sb_info) {
262 DP_ERR(p_hwfn->cdev,
263 "Status block is NULL - cannot ack interrupts\n");
264 return;
265 }
266
Yuval Mintzcc875c22015-10-26 11:02:31 +0200267 if (!p_hwfn->p_sb_attn) {
268 DP_ERR(p_hwfn->cdev, "DPC called - no p_sb_attn");
269 return;
270 }
271 sb_attn = p_hwfn->p_sb_attn;
272
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200273 DP_VERBOSE(p_hwfn, NETIF_MSG_INTR, "DPC Called! (hwfn %p %d)\n",
274 p_hwfn, p_hwfn->my_id);
275
276 /* Disable ack for def status block. Required both for msix +
277 * inta in non-mask mode, in inta does no harm.
278 */
279 qed_sb_ack(sb_info, IGU_INT_DISABLE, 0);
280
281 /* Gather Interrupts/Attentions information */
282 if (!sb_info->sb_virt) {
283 DP_ERR(
284 p_hwfn->cdev,
285 "Interrupt Status block is NULL - cannot check for new interrupts!\n");
286 } else {
287 u32 tmp_index = sb_info->sb_ack;
288
289 rc = qed_sb_update_sb_idx(sb_info);
290 DP_VERBOSE(p_hwfn->cdev, NETIF_MSG_INTR,
291 "Interrupt indices: 0x%08x --> 0x%08x\n",
292 tmp_index, sb_info->sb_ack);
293 }
294
Yuval Mintzcc875c22015-10-26 11:02:31 +0200295 if (!sb_attn || !sb_attn->sb_attn) {
296 DP_ERR(
297 p_hwfn->cdev,
298 "Attentions Status block is NULL - cannot check for new attentions!\n");
299 } else {
300 u16 tmp_index = sb_attn->index;
301
302 rc |= qed_attn_update_idx(p_hwfn, sb_attn);
303 DP_VERBOSE(p_hwfn->cdev, NETIF_MSG_INTR,
304 "Attention indices: 0x%08x --> 0x%08x\n",
305 tmp_index, sb_attn->index);
306 }
307
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200308 /* Check if we expect interrupts at this time. if not just ack them */
309 if (!(rc & QED_SB_EVENT_MASK)) {
310 qed_sb_ack(sb_info, IGU_INT_ENABLE, 1);
311 return;
312 }
313
314 /* Check the validity of the DPC ptt. If not ack interrupts and fail */
315 if (!p_hwfn->p_dpc_ptt) {
316 DP_NOTICE(p_hwfn->cdev, "Failed to allocate PTT\n");
317 qed_sb_ack(sb_info, IGU_INT_ENABLE, 1);
318 return;
319 }
320
Yuval Mintzcc875c22015-10-26 11:02:31 +0200321 if (rc & QED_SB_ATT_IDX)
322 qed_int_attentions(p_hwfn);
323
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200324 if (rc & QED_SB_IDX) {
325 int pi;
326
327 /* Look for a free index */
328 for (pi = 0; pi < arr_size; pi++) {
329 pi_info = &p_hwfn->p_sp_sb->pi_info_arr[pi];
330 if (pi_info->comp_cb)
331 pi_info->comp_cb(p_hwfn, pi_info->cookie);
332 }
333 }
334
Yuval Mintzcc875c22015-10-26 11:02:31 +0200335 if (sb_attn && (rc & QED_SB_ATT_IDX))
336 /* This should be done before the interrupts are enabled,
337 * since otherwise a new attention will be generated.
338 */
339 qed_sb_ack_attn(p_hwfn, sb_info->igu_addr, sb_attn->index);
340
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200341 qed_sb_ack(sb_info, IGU_INT_ENABLE, 1);
342}
343
Yuval Mintzcc875c22015-10-26 11:02:31 +0200344static void qed_int_sb_attn_free(struct qed_hwfn *p_hwfn)
345{
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200346 struct qed_sb_attn_info *p_sb = p_hwfn->p_sb_attn;
Yuval Mintzcc875c22015-10-26 11:02:31 +0200347
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200348 if (!p_sb)
349 return;
350
351 if (p_sb->sb_attn)
352 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
353 SB_ATTN_ALIGNED_SIZE(p_hwfn),
354 p_sb->sb_attn,
355 p_sb->sb_phys);
356 kfree(p_sb);
Yuval Mintzcc875c22015-10-26 11:02:31 +0200357}
358
359static void qed_int_sb_attn_setup(struct qed_hwfn *p_hwfn,
360 struct qed_ptt *p_ptt)
361{
362 struct qed_sb_attn_info *sb_info = p_hwfn->p_sb_attn;
363
364 memset(sb_info->sb_attn, 0, sizeof(*sb_info->sb_attn));
365
366 sb_info->index = 0;
367 sb_info->known_attn = 0;
368
369 /* Configure Attention Status Block in IGU */
370 qed_wr(p_hwfn, p_ptt, IGU_REG_ATTN_MSG_ADDR_L,
371 lower_32_bits(p_hwfn->p_sb_attn->sb_phys));
372 qed_wr(p_hwfn, p_ptt, IGU_REG_ATTN_MSG_ADDR_H,
373 upper_32_bits(p_hwfn->p_sb_attn->sb_phys));
374}
375
376static void qed_int_sb_attn_init(struct qed_hwfn *p_hwfn,
377 struct qed_ptt *p_ptt,
378 void *sb_virt_addr,
379 dma_addr_t sb_phy_addr)
380{
381 struct qed_sb_attn_info *sb_info = p_hwfn->p_sb_attn;
382
383 sb_info->sb_attn = sb_virt_addr;
384 sb_info->sb_phys = sb_phy_addr;
385
386 /* Set the address of cleanup for the mcp attention */
387 sb_info->mfw_attn_addr = (p_hwfn->rel_pf_id << 3) +
388 MISC_REG_AEU_GENERAL_ATTN_0;
389
390 qed_int_sb_attn_setup(p_hwfn, p_ptt);
391}
392
393static int qed_int_sb_attn_alloc(struct qed_hwfn *p_hwfn,
394 struct qed_ptt *p_ptt)
395{
396 struct qed_dev *cdev = p_hwfn->cdev;
397 struct qed_sb_attn_info *p_sb;
398 void *p_virt;
399 dma_addr_t p_phys = 0;
400
401 /* SB struct */
Yuval Mintz60fffb32016-02-21 11:40:07 +0200402 p_sb = kmalloc(sizeof(*p_sb), GFP_KERNEL);
Yuval Mintzcc875c22015-10-26 11:02:31 +0200403 if (!p_sb) {
404 DP_NOTICE(cdev, "Failed to allocate `struct qed_sb_attn_info'\n");
405 return -ENOMEM;
406 }
407
408 /* SB ring */
409 p_virt = dma_alloc_coherent(&cdev->pdev->dev,
410 SB_ATTN_ALIGNED_SIZE(p_hwfn),
411 &p_phys, GFP_KERNEL);
412
413 if (!p_virt) {
414 DP_NOTICE(cdev, "Failed to allocate status block (attentions)\n");
415 kfree(p_sb);
416 return -ENOMEM;
417 }
418
419 /* Attention setup */
420 p_hwfn->p_sb_attn = p_sb;
421 qed_int_sb_attn_init(p_hwfn, p_ptt, p_virt, p_phys);
422
423 return 0;
424}
425
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200426/* coalescing timeout = timeset << (timer_res + 1) */
427#define QED_CAU_DEF_RX_USECS 24
428#define QED_CAU_DEF_TX_USECS 48
429
430void qed_init_cau_sb_entry(struct qed_hwfn *p_hwfn,
431 struct cau_sb_entry *p_sb_entry,
432 u8 pf_id,
433 u16 vf_number,
434 u8 vf_valid)
435{
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200436 struct qed_dev *cdev = p_hwfn->cdev;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200437 u32 cau_state;
438
439 memset(p_sb_entry, 0, sizeof(*p_sb_entry));
440
441 SET_FIELD(p_sb_entry->params, CAU_SB_ENTRY_PF_NUMBER, pf_id);
442 SET_FIELD(p_sb_entry->params, CAU_SB_ENTRY_VF_NUMBER, vf_number);
443 SET_FIELD(p_sb_entry->params, CAU_SB_ENTRY_VF_VALID, vf_valid);
444 SET_FIELD(p_sb_entry->params, CAU_SB_ENTRY_SB_TIMESET0, 0x7F);
445 SET_FIELD(p_sb_entry->params, CAU_SB_ENTRY_SB_TIMESET1, 0x7F);
446
447 /* setting the time resultion to a fixed value ( = 1) */
448 SET_FIELD(p_sb_entry->params, CAU_SB_ENTRY_TIMER_RES0,
449 QED_CAU_DEF_RX_TIMER_RES);
450 SET_FIELD(p_sb_entry->params, CAU_SB_ENTRY_TIMER_RES1,
451 QED_CAU_DEF_TX_TIMER_RES);
452
453 cau_state = CAU_HC_DISABLE_STATE;
454
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200455 if (cdev->int_coalescing_mode == QED_COAL_MODE_ENABLE) {
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200456 cau_state = CAU_HC_ENABLE_STATE;
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200457 if (!cdev->rx_coalesce_usecs)
458 cdev->rx_coalesce_usecs = QED_CAU_DEF_RX_USECS;
459 if (!cdev->tx_coalesce_usecs)
460 cdev->tx_coalesce_usecs = QED_CAU_DEF_TX_USECS;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200461 }
462
463 SET_FIELD(p_sb_entry->data, CAU_SB_ENTRY_STATE0, cau_state);
464 SET_FIELD(p_sb_entry->data, CAU_SB_ENTRY_STATE1, cau_state);
465}
466
467void qed_int_cau_conf_sb(struct qed_hwfn *p_hwfn,
468 struct qed_ptt *p_ptt,
469 dma_addr_t sb_phys,
470 u16 igu_sb_id,
471 u16 vf_number,
472 u8 vf_valid)
473{
474 struct cau_sb_entry sb_entry;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200475
476 qed_init_cau_sb_entry(p_hwfn, &sb_entry, p_hwfn->rel_pf_id,
477 vf_number, vf_valid);
478
479 if (p_hwfn->hw_init_done) {
Yuval Mintz0a0c5d32016-02-21 11:40:08 +0200480 /* Wide-bus, initialize via DMAE */
481 u64 phys_addr = (u64)sb_phys;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200482
Yuval Mintz0a0c5d32016-02-21 11:40:08 +0200483 qed_dmae_host2grc(p_hwfn, p_ptt, (u64)(uintptr_t)&phys_addr,
484 CAU_REG_SB_ADDR_MEMORY +
485 igu_sb_id * sizeof(u64), 2, 0);
486 qed_dmae_host2grc(p_hwfn, p_ptt, (u64)(uintptr_t)&sb_entry,
487 CAU_REG_SB_VAR_MEMORY +
488 igu_sb_id * sizeof(u64), 2, 0);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200489 } else {
490 /* Initialize Status Block Address */
491 STORE_RT_REG_AGG(p_hwfn,
492 CAU_REG_SB_ADDR_MEMORY_RT_OFFSET +
493 igu_sb_id * 2,
494 sb_phys);
495
496 STORE_RT_REG_AGG(p_hwfn,
497 CAU_REG_SB_VAR_MEMORY_RT_OFFSET +
498 igu_sb_id * 2,
499 sb_entry);
500 }
501
502 /* Configure pi coalescing if set */
503 if (p_hwfn->cdev->int_coalescing_mode == QED_COAL_MODE_ENABLE) {
504 u8 timeset = p_hwfn->cdev->rx_coalesce_usecs >>
505 (QED_CAU_DEF_RX_TIMER_RES + 1);
506 u8 num_tc = 1, i;
507
508 qed_int_cau_conf_pi(p_hwfn, p_ptt, igu_sb_id, RX_PI,
509 QED_COAL_RX_STATE_MACHINE,
510 timeset);
511
512 timeset = p_hwfn->cdev->tx_coalesce_usecs >>
513 (QED_CAU_DEF_TX_TIMER_RES + 1);
514
515 for (i = 0; i < num_tc; i++) {
516 qed_int_cau_conf_pi(p_hwfn, p_ptt,
517 igu_sb_id, TX_PI(i),
518 QED_COAL_TX_STATE_MACHINE,
519 timeset);
520 }
521 }
522}
523
524void qed_int_cau_conf_pi(struct qed_hwfn *p_hwfn,
525 struct qed_ptt *p_ptt,
526 u16 igu_sb_id,
527 u32 pi_index,
528 enum qed_coalescing_fsm coalescing_fsm,
529 u8 timeset)
530{
531 struct cau_pi_entry pi_entry;
532 u32 sb_offset;
533 u32 pi_offset;
534
535 sb_offset = igu_sb_id * PIS_PER_SB;
536 memset(&pi_entry, 0, sizeof(struct cau_pi_entry));
537
538 SET_FIELD(pi_entry.prod, CAU_PI_ENTRY_PI_TIMESET, timeset);
539 if (coalescing_fsm == QED_COAL_RX_STATE_MACHINE)
540 SET_FIELD(pi_entry.prod, CAU_PI_ENTRY_FSM_SEL, 0);
541 else
542 SET_FIELD(pi_entry.prod, CAU_PI_ENTRY_FSM_SEL, 1);
543
544 pi_offset = sb_offset + pi_index;
545 if (p_hwfn->hw_init_done) {
546 qed_wr(p_hwfn, p_ptt,
547 CAU_REG_PI_MEMORY + pi_offset * sizeof(u32),
548 *((u32 *)&(pi_entry)));
549 } else {
550 STORE_RT_REG(p_hwfn,
551 CAU_REG_PI_MEMORY_RT_OFFSET + pi_offset,
552 *((u32 *)&(pi_entry)));
553 }
554}
555
556void qed_int_sb_setup(struct qed_hwfn *p_hwfn,
557 struct qed_ptt *p_ptt,
558 struct qed_sb_info *sb_info)
559{
560 /* zero status block and ack counter */
561 sb_info->sb_ack = 0;
562 memset(sb_info->sb_virt, 0, sizeof(*sb_info->sb_virt));
563
564 qed_int_cau_conf_sb(p_hwfn, p_ptt, sb_info->sb_phys,
565 sb_info->igu_sb_id, 0, 0);
566}
567
568/**
569 * @brief qed_get_igu_sb_id - given a sw sb_id return the
570 * igu_sb_id
571 *
572 * @param p_hwfn
573 * @param sb_id
574 *
575 * @return u16
576 */
577static u16 qed_get_igu_sb_id(struct qed_hwfn *p_hwfn,
578 u16 sb_id)
579{
580 u16 igu_sb_id;
581
582 /* Assuming continuous set of IGU SBs dedicated for given PF */
583 if (sb_id == QED_SP_SB_ID)
584 igu_sb_id = p_hwfn->hw_info.p_igu_info->igu_dsb_id;
585 else
586 igu_sb_id = sb_id + p_hwfn->hw_info.p_igu_info->igu_base_sb;
587
588 DP_VERBOSE(p_hwfn, NETIF_MSG_INTR, "SB [%s] index is 0x%04x\n",
589 (sb_id == QED_SP_SB_ID) ? "DSB" : "non-DSB", igu_sb_id);
590
591 return igu_sb_id;
592}
593
594int qed_int_sb_init(struct qed_hwfn *p_hwfn,
595 struct qed_ptt *p_ptt,
596 struct qed_sb_info *sb_info,
597 void *sb_virt_addr,
598 dma_addr_t sb_phy_addr,
599 u16 sb_id)
600{
601 sb_info->sb_virt = sb_virt_addr;
602 sb_info->sb_phys = sb_phy_addr;
603
604 sb_info->igu_sb_id = qed_get_igu_sb_id(p_hwfn, sb_id);
605
606 if (sb_id != QED_SP_SB_ID) {
607 p_hwfn->sbs_info[sb_id] = sb_info;
608 p_hwfn->num_sbs++;
609 }
610
611 sb_info->cdev = p_hwfn->cdev;
612
613 /* The igu address will hold the absolute address that needs to be
614 * written to for a specific status block
615 */
616 sb_info->igu_addr = (u8 __iomem *)p_hwfn->regview +
617 GTT_BAR0_MAP_REG_IGU_CMD +
618 (sb_info->igu_sb_id << 3);
619
620 sb_info->flags |= QED_SB_INFO_INIT;
621
622 qed_int_sb_setup(p_hwfn, p_ptt, sb_info);
623
624 return 0;
625}
626
627int qed_int_sb_release(struct qed_hwfn *p_hwfn,
628 struct qed_sb_info *sb_info,
629 u16 sb_id)
630{
631 if (sb_id == QED_SP_SB_ID) {
632 DP_ERR(p_hwfn, "Do Not free sp sb using this function");
633 return -EINVAL;
634 }
635
636 /* zero status block and ack counter */
637 sb_info->sb_ack = 0;
638 memset(sb_info->sb_virt, 0, sizeof(*sb_info->sb_virt));
639
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200640 if (p_hwfn->sbs_info[sb_id] != NULL) {
641 p_hwfn->sbs_info[sb_id] = NULL;
642 p_hwfn->num_sbs--;
643 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200644
645 return 0;
646}
647
648static void qed_int_sp_sb_free(struct qed_hwfn *p_hwfn)
649{
650 struct qed_sb_sp_info *p_sb = p_hwfn->p_sp_sb;
651
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200652 if (!p_sb)
653 return;
654
655 if (p_sb->sb_info.sb_virt)
656 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
657 SB_ALIGNED_SIZE(p_hwfn),
658 p_sb->sb_info.sb_virt,
659 p_sb->sb_info.sb_phys);
660 kfree(p_sb);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200661}
662
663static int qed_int_sp_sb_alloc(struct qed_hwfn *p_hwfn,
664 struct qed_ptt *p_ptt)
665{
666 struct qed_sb_sp_info *p_sb;
667 dma_addr_t p_phys = 0;
668 void *p_virt;
669
670 /* SB struct */
Yuval Mintz60fffb32016-02-21 11:40:07 +0200671 p_sb = kmalloc(sizeof(*p_sb), GFP_KERNEL);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200672 if (!p_sb) {
673 DP_NOTICE(p_hwfn, "Failed to allocate `struct qed_sb_info'\n");
674 return -ENOMEM;
675 }
676
677 /* SB ring */
678 p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
679 SB_ALIGNED_SIZE(p_hwfn),
680 &p_phys, GFP_KERNEL);
681 if (!p_virt) {
682 DP_NOTICE(p_hwfn, "Failed to allocate status block\n");
683 kfree(p_sb);
684 return -ENOMEM;
685 }
686
687 /* Status Block setup */
688 p_hwfn->p_sp_sb = p_sb;
689 qed_int_sb_init(p_hwfn, p_ptt, &p_sb->sb_info, p_virt,
690 p_phys, QED_SP_SB_ID);
691
692 memset(p_sb->pi_info_arr, 0, sizeof(p_sb->pi_info_arr));
693
694 return 0;
695}
696
697static void qed_int_sp_sb_setup(struct qed_hwfn *p_hwfn,
698 struct qed_ptt *p_ptt)
699{
700 if (!p_hwfn)
701 return;
702
703 if (p_hwfn->p_sp_sb)
704 qed_int_sb_setup(p_hwfn, p_ptt, &p_hwfn->p_sp_sb->sb_info);
705 else
706 DP_NOTICE(p_hwfn->cdev,
707 "Failed to setup Slow path status block - NULL pointer\n");
Yuval Mintzcc875c22015-10-26 11:02:31 +0200708
709 if (p_hwfn->p_sb_attn)
710 qed_int_sb_attn_setup(p_hwfn, p_ptt);
711 else
712 DP_NOTICE(p_hwfn->cdev,
713 "Failed to setup attentions status block - NULL pointer\n");
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200714}
715
716int qed_int_register_cb(struct qed_hwfn *p_hwfn,
717 qed_int_comp_cb_t comp_cb,
718 void *cookie,
719 u8 *sb_idx,
720 __le16 **p_fw_cons)
721{
722 struct qed_sb_sp_info *p_sp_sb = p_hwfn->p_sp_sb;
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200723 int rc = -ENOMEM;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200724 u8 pi;
725
726 /* Look for a free index */
727 for (pi = 0; pi < ARRAY_SIZE(p_sp_sb->pi_info_arr); pi++) {
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200728 if (p_sp_sb->pi_info_arr[pi].comp_cb)
729 continue;
730
731 p_sp_sb->pi_info_arr[pi].comp_cb = comp_cb;
732 p_sp_sb->pi_info_arr[pi].cookie = cookie;
733 *sb_idx = pi;
734 *p_fw_cons = &p_sp_sb->sb_info.sb_virt->pi_array[pi];
735 rc = 0;
736 break;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200737 }
738
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200739 return rc;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200740}
741
742int qed_int_unregister_cb(struct qed_hwfn *p_hwfn, u8 pi)
743{
744 struct qed_sb_sp_info *p_sp_sb = p_hwfn->p_sp_sb;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200745
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200746 if (p_sp_sb->pi_info_arr[pi].comp_cb == NULL)
747 return -ENOMEM;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200748
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200749 p_sp_sb->pi_info_arr[pi].comp_cb = NULL;
750 p_sp_sb->pi_info_arr[pi].cookie = NULL;
751
752 return 0;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200753}
754
755u16 qed_int_get_sp_sb_id(struct qed_hwfn *p_hwfn)
756{
757 return p_hwfn->p_sp_sb->sb_info.igu_sb_id;
758}
759
760void qed_int_igu_enable_int(struct qed_hwfn *p_hwfn,
761 struct qed_ptt *p_ptt,
762 enum qed_int_mode int_mode)
763{
Yuval Mintzcc875c22015-10-26 11:02:31 +0200764 u32 igu_pf_conf = IGU_PF_CONF_FUNC_EN | IGU_PF_CONF_ATTN_BIT_EN;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200765
766 p_hwfn->cdev->int_mode = int_mode;
767 switch (p_hwfn->cdev->int_mode) {
768 case QED_INT_MODE_INTA:
769 igu_pf_conf |= IGU_PF_CONF_INT_LINE_EN;
770 igu_pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
771 break;
772
773 case QED_INT_MODE_MSI:
774 igu_pf_conf |= IGU_PF_CONF_MSI_MSIX_EN;
775 igu_pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
776 break;
777
778 case QED_INT_MODE_MSIX:
779 igu_pf_conf |= IGU_PF_CONF_MSI_MSIX_EN;
780 break;
781 case QED_INT_MODE_POLL:
782 break;
783 }
784
785 qed_wr(p_hwfn, p_ptt, IGU_REG_PF_CONFIGURATION, igu_pf_conf);
786}
787
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500788int qed_int_igu_enable(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
789 enum qed_int_mode int_mode)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200790{
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500791 int rc, i;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200792
793 /* Mask non-link attentions */
794 for (i = 0; i < 9; i++)
795 qed_wr(p_hwfn, p_ptt,
796 MISC_REG_AEU_ENABLE1_IGU_OUT_0 + (i << 2), 0);
797
Yuval Mintzcc875c22015-10-26 11:02:31 +0200798 /* Configure AEU signal change to produce attentions for link */
799 qed_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0xfff);
800 qed_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0xfff);
801
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200802 /* Flush the writes to IGU */
803 mmiowb();
Yuval Mintzcc875c22015-10-26 11:02:31 +0200804
805 /* Unmask AEU signals toward IGU */
806 qed_wr(p_hwfn, p_ptt, MISC_REG_AEU_MASK_ATTN_IGU, 0xff);
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500807 if ((int_mode != QED_INT_MODE_INTA) || IS_LEAD_HWFN(p_hwfn)) {
808 rc = qed_slowpath_irq_req(p_hwfn);
809 if (rc != 0) {
810 DP_NOTICE(p_hwfn, "Slowpath IRQ request failed\n");
811 return -EINVAL;
812 }
813 p_hwfn->b_int_requested = true;
814 }
815 /* Enable interrupt Generation */
816 qed_int_igu_enable_int(p_hwfn, p_ptt, int_mode);
817 p_hwfn->b_int_enabled = 1;
818
819 return rc;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200820}
821
822void qed_int_igu_disable_int(struct qed_hwfn *p_hwfn,
823 struct qed_ptt *p_ptt)
824{
825 p_hwfn->b_int_enabled = 0;
826
827 qed_wr(p_hwfn, p_ptt, IGU_REG_PF_CONFIGURATION, 0);
828}
829
830#define IGU_CLEANUP_SLEEP_LENGTH (1000)
831void qed_int_igu_cleanup_sb(struct qed_hwfn *p_hwfn,
832 struct qed_ptt *p_ptt,
833 u32 sb_id,
834 bool cleanup_set,
835 u16 opaque_fid
836 )
837{
838 u32 pxp_addr = IGU_CMD_INT_ACK_BASE + sb_id;
839 u32 sleep_cnt = IGU_CLEANUP_SLEEP_LENGTH;
840 u32 data = 0;
841 u32 cmd_ctrl = 0;
842 u32 val = 0;
843 u32 sb_bit = 0;
844 u32 sb_bit_addr = 0;
845
846 /* Set the data field */
847 SET_FIELD(data, IGU_CLEANUP_CLEANUP_SET, cleanup_set ? 1 : 0);
848 SET_FIELD(data, IGU_CLEANUP_CLEANUP_TYPE, 0);
849 SET_FIELD(data, IGU_CLEANUP_COMMAND_TYPE, IGU_COMMAND_TYPE_SET);
850
851 /* Set the control register */
852 SET_FIELD(cmd_ctrl, IGU_CTRL_REG_PXP_ADDR, pxp_addr);
853 SET_FIELD(cmd_ctrl, IGU_CTRL_REG_FID, opaque_fid);
854 SET_FIELD(cmd_ctrl, IGU_CTRL_REG_TYPE, IGU_CTRL_CMD_TYPE_WR);
855
856 qed_wr(p_hwfn, p_ptt, IGU_REG_COMMAND_REG_32LSB_DATA, data);
857
858 barrier();
859
860 qed_wr(p_hwfn, p_ptt, IGU_REG_COMMAND_REG_CTRL, cmd_ctrl);
861
862 /* Flush the write to IGU */
863 mmiowb();
864
865 /* calculate where to read the status bit from */
866 sb_bit = 1 << (sb_id % 32);
867 sb_bit_addr = sb_id / 32 * sizeof(u32);
868
869 sb_bit_addr += IGU_REG_CLEANUP_STATUS_0;
870
871 /* Now wait for the command to complete */
872 do {
873 val = qed_rd(p_hwfn, p_ptt, sb_bit_addr);
874
875 if ((val & sb_bit) == (cleanup_set ? sb_bit : 0))
876 break;
877
878 usleep_range(5000, 10000);
879 } while (--sleep_cnt);
880
881 if (!sleep_cnt)
882 DP_NOTICE(p_hwfn,
883 "Timeout waiting for clear status 0x%08x [for sb %d]\n",
884 val, sb_id);
885}
886
887void qed_int_igu_init_pure_rt_single(struct qed_hwfn *p_hwfn,
888 struct qed_ptt *p_ptt,
889 u32 sb_id,
890 u16 opaque,
891 bool b_set)
892{
893 int pi;
894
895 /* Set */
896 if (b_set)
897 qed_int_igu_cleanup_sb(p_hwfn, p_ptt, sb_id, 1, opaque);
898
899 /* Clear */
900 qed_int_igu_cleanup_sb(p_hwfn, p_ptt, sb_id, 0, opaque);
901
902 /* Clear the CAU for the SB */
903 for (pi = 0; pi < 12; pi++)
904 qed_wr(p_hwfn, p_ptt,
905 CAU_REG_PI_MEMORY + (sb_id * 12 + pi) * 4, 0);
906}
907
908void qed_int_igu_init_pure_rt(struct qed_hwfn *p_hwfn,
909 struct qed_ptt *p_ptt,
910 bool b_set,
911 bool b_slowpath)
912{
913 u32 igu_base_sb = p_hwfn->hw_info.p_igu_info->igu_base_sb;
914 u32 igu_sb_cnt = p_hwfn->hw_info.p_igu_info->igu_sb_cnt;
915 u32 sb_id = 0;
916 u32 val = 0;
917
918 val = qed_rd(p_hwfn, p_ptt, IGU_REG_BLOCK_CONFIGURATION);
919 val |= IGU_REG_BLOCK_CONFIGURATION_VF_CLEANUP_EN;
920 val &= ~IGU_REG_BLOCK_CONFIGURATION_PXP_TPH_INTERFACE_EN;
921 qed_wr(p_hwfn, p_ptt, IGU_REG_BLOCK_CONFIGURATION, val);
922
923 DP_VERBOSE(p_hwfn, NETIF_MSG_INTR,
924 "IGU cleaning SBs [%d,...,%d]\n",
925 igu_base_sb, igu_base_sb + igu_sb_cnt - 1);
926
927 for (sb_id = igu_base_sb; sb_id < igu_base_sb + igu_sb_cnt; sb_id++)
928 qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt, sb_id,
929 p_hwfn->hw_info.opaque_fid,
930 b_set);
931
932 if (b_slowpath) {
933 sb_id = p_hwfn->hw_info.p_igu_info->igu_dsb_id;
934 DP_VERBOSE(p_hwfn, NETIF_MSG_INTR,
935 "IGU cleaning slowpath SB [%d]\n", sb_id);
936 qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt, sb_id,
937 p_hwfn->hw_info.opaque_fid,
938 b_set);
939 }
940}
941
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200942static u32 qed_int_igu_read_cam_block(struct qed_hwfn *p_hwfn,
943 struct qed_ptt *p_ptt,
944 u16 sb_id)
945{
946 u32 val = qed_rd(p_hwfn, p_ptt,
947 IGU_REG_MAPPING_MEMORY +
948 sizeof(u32) * sb_id);
949 struct qed_igu_block *p_block;
950
951 p_block = &p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks[sb_id];
952
953 /* stop scanning when hit first invalid PF entry */
954 if (!GET_FIELD(val, IGU_MAPPING_LINE_VALID) &&
955 GET_FIELD(val, IGU_MAPPING_LINE_PF_VALID))
956 goto out;
957
958 /* Fill the block information */
959 p_block->status = QED_IGU_STATUS_VALID;
960 p_block->function_id = GET_FIELD(val,
961 IGU_MAPPING_LINE_FUNCTION_NUMBER);
962 p_block->is_pf = GET_FIELD(val, IGU_MAPPING_LINE_PF_VALID);
963 p_block->vector_number = GET_FIELD(val,
964 IGU_MAPPING_LINE_VECTOR_NUMBER);
965
966 DP_VERBOSE(p_hwfn, NETIF_MSG_INTR,
967 "IGU_BLOCK: [SB 0x%04x, Value in CAM 0x%08x] func_id = %d is_pf = %d vector_num = 0x%x\n",
968 sb_id, val, p_block->function_id,
969 p_block->is_pf, p_block->vector_number);
970
971out:
972 return val;
973}
974
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200975int qed_int_igu_read_cam(struct qed_hwfn *p_hwfn,
976 struct qed_ptt *p_ptt)
977{
978 struct qed_igu_info *p_igu_info;
979 struct qed_igu_block *blk;
980 u32 val;
981 u16 sb_id;
982 u16 prev_sb_id = 0xFF;
983
Yuval Mintz60fffb32016-02-21 11:40:07 +0200984 p_hwfn->hw_info.p_igu_info = kzalloc(sizeof(*p_igu_info), GFP_KERNEL);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200985
986 if (!p_hwfn->hw_info.p_igu_info)
987 return -ENOMEM;
988
989 p_igu_info = p_hwfn->hw_info.p_igu_info;
990
991 /* Initialize base sb / sb cnt for PFs */
992 p_igu_info->igu_base_sb = 0xffff;
993 p_igu_info->igu_sb_cnt = 0;
994 p_igu_info->igu_dsb_id = 0xffff;
995 p_igu_info->igu_base_sb_iov = 0xffff;
996
997 for (sb_id = 0; sb_id < QED_MAPPING_MEMORY_SIZE(p_hwfn->cdev);
998 sb_id++) {
999 blk = &p_igu_info->igu_map.igu_blocks[sb_id];
1000
Yuval Mintz4ac801b2016-02-28 12:26:52 +02001001 val = qed_int_igu_read_cam_block(p_hwfn, p_ptt, sb_id);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001002
1003 /* stop scanning when hit first invalid PF entry */
1004 if (!GET_FIELD(val, IGU_MAPPING_LINE_VALID) &&
1005 GET_FIELD(val, IGU_MAPPING_LINE_PF_VALID))
1006 break;
1007
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001008 if (blk->is_pf) {
1009 if (blk->function_id == p_hwfn->rel_pf_id) {
1010 blk->status |= QED_IGU_STATUS_PF;
1011
1012 if (blk->vector_number == 0) {
1013 if (p_igu_info->igu_dsb_id == 0xffff)
1014 p_igu_info->igu_dsb_id = sb_id;
1015 } else {
1016 if (p_igu_info->igu_base_sb ==
1017 0xffff) {
1018 p_igu_info->igu_base_sb = sb_id;
1019 } else if (prev_sb_id != sb_id - 1) {
1020 DP_NOTICE(p_hwfn->cdev,
1021 "consecutive igu vectors for HWFN %x broken",
1022 p_hwfn->rel_pf_id);
1023 break;
1024 }
1025 prev_sb_id = sb_id;
1026 /* we don't count the default */
1027 (p_igu_info->igu_sb_cnt)++;
1028 }
1029 }
1030 }
1031 }
1032
1033 DP_VERBOSE(p_hwfn, NETIF_MSG_INTR,
1034 "IGU igu_base_sb=0x%x igu_sb_cnt=%d igu_dsb_id=0x%x\n",
1035 p_igu_info->igu_base_sb,
1036 p_igu_info->igu_sb_cnt,
1037 p_igu_info->igu_dsb_id);
1038
1039 if (p_igu_info->igu_base_sb == 0xffff ||
1040 p_igu_info->igu_dsb_id == 0xffff ||
1041 p_igu_info->igu_sb_cnt == 0) {
1042 DP_NOTICE(p_hwfn,
1043 "IGU CAM returned invalid values igu_base_sb=0x%x igu_sb_cnt=%d igu_dsb_id=0x%x\n",
1044 p_igu_info->igu_base_sb,
1045 p_igu_info->igu_sb_cnt,
1046 p_igu_info->igu_dsb_id);
1047 return -EINVAL;
1048 }
1049
1050 return 0;
1051}
1052
1053/**
1054 * @brief Initialize igu runtime registers
1055 *
1056 * @param p_hwfn
1057 */
1058void qed_int_igu_init_rt(struct qed_hwfn *p_hwfn)
1059{
1060 u32 igu_pf_conf = 0;
1061
1062 igu_pf_conf |= IGU_PF_CONF_FUNC_EN;
1063
1064 STORE_RT_REG(p_hwfn, IGU_REG_PF_CONFIGURATION_RT_OFFSET, igu_pf_conf);
1065}
1066
1067u64 qed_int_igu_read_sisr_reg(struct qed_hwfn *p_hwfn)
1068{
1069 u64 intr_status = 0;
1070 u32 intr_status_lo = 0;
1071 u32 intr_status_hi = 0;
1072 u32 lsb_igu_cmd_addr = IGU_REG_SISR_MDPC_WMASK_LSB_UPPER -
1073 IGU_CMD_INT_ACK_BASE;
1074 u32 msb_igu_cmd_addr = IGU_REG_SISR_MDPC_WMASK_MSB_UPPER -
1075 IGU_CMD_INT_ACK_BASE;
1076
1077 intr_status_lo = REG_RD(p_hwfn,
1078 GTT_BAR0_MAP_REG_IGU_CMD +
1079 lsb_igu_cmd_addr * 8);
1080 intr_status_hi = REG_RD(p_hwfn,
1081 GTT_BAR0_MAP_REG_IGU_CMD +
1082 msb_igu_cmd_addr * 8);
1083 intr_status = ((u64)intr_status_hi << 32) + (u64)intr_status_lo;
1084
1085 return intr_status;
1086}
1087
1088static void qed_int_sp_dpc_setup(struct qed_hwfn *p_hwfn)
1089{
1090 tasklet_init(p_hwfn->sp_dpc,
1091 qed_int_sp_dpc, (unsigned long)p_hwfn);
1092 p_hwfn->b_sp_dpc_enabled = true;
1093}
1094
1095static int qed_int_sp_dpc_alloc(struct qed_hwfn *p_hwfn)
1096{
Yuval Mintz60fffb32016-02-21 11:40:07 +02001097 p_hwfn->sp_dpc = kmalloc(sizeof(*p_hwfn->sp_dpc), GFP_KERNEL);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001098 if (!p_hwfn->sp_dpc)
1099 return -ENOMEM;
1100
1101 return 0;
1102}
1103
1104static void qed_int_sp_dpc_free(struct qed_hwfn *p_hwfn)
1105{
1106 kfree(p_hwfn->sp_dpc);
1107}
1108
1109int qed_int_alloc(struct qed_hwfn *p_hwfn,
1110 struct qed_ptt *p_ptt)
1111{
1112 int rc = 0;
1113
1114 rc = qed_int_sp_dpc_alloc(p_hwfn);
1115 if (rc) {
1116 DP_ERR(p_hwfn->cdev, "Failed to allocate sp dpc mem\n");
1117 return rc;
1118 }
1119 rc = qed_int_sp_sb_alloc(p_hwfn, p_ptt);
1120 if (rc) {
1121 DP_ERR(p_hwfn->cdev, "Failed to allocate sp sb mem\n");
1122 return rc;
1123 }
Yuval Mintzcc875c22015-10-26 11:02:31 +02001124 rc = qed_int_sb_attn_alloc(p_hwfn, p_ptt);
1125 if (rc) {
1126 DP_ERR(p_hwfn->cdev, "Failed to allocate sb attn mem\n");
1127 return rc;
1128 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001129 return rc;
1130}
1131
1132void qed_int_free(struct qed_hwfn *p_hwfn)
1133{
1134 qed_int_sp_sb_free(p_hwfn);
Yuval Mintzcc875c22015-10-26 11:02:31 +02001135 qed_int_sb_attn_free(p_hwfn);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001136 qed_int_sp_dpc_free(p_hwfn);
1137}
1138
1139void qed_int_setup(struct qed_hwfn *p_hwfn,
1140 struct qed_ptt *p_ptt)
1141{
1142 qed_int_sp_sb_setup(p_hwfn, p_ptt);
1143 qed_int_sp_dpc_setup(p_hwfn);
1144}
1145
Yuval Mintz4ac801b2016-02-28 12:26:52 +02001146void qed_int_get_num_sbs(struct qed_hwfn *p_hwfn,
1147 struct qed_sb_cnt_info *p_sb_cnt_info)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001148{
1149 struct qed_igu_info *info = p_hwfn->hw_info.p_igu_info;
1150
Yuval Mintz4ac801b2016-02-28 12:26:52 +02001151 if (!info || !p_sb_cnt_info)
1152 return;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001153
Yuval Mintz4ac801b2016-02-28 12:26:52 +02001154 p_sb_cnt_info->sb_cnt = info->igu_sb_cnt;
1155 p_sb_cnt_info->sb_iov_cnt = info->igu_sb_cnt_iov;
1156 p_sb_cnt_info->sb_free_blk = info->free_blks;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001157}
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -05001158
1159void qed_int_disable_post_isr_release(struct qed_dev *cdev)
1160{
1161 int i;
1162
1163 for_each_hwfn(cdev, i)
1164 cdev->hwfns[i].b_int_requested = false;
1165}