blob: c4a0c0eb88a576ac7105ad5789403f62d7d03a59 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05002 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
Jing Huang7725ccf2009-09-23 17:46:15 -07004 * All rights reserved
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05005 * www.qlogic.com
Jing Huang7725ccf2009-09-23 17:46:15 -07006 *
Anil Gurumurthy31e1d562015-11-26 03:54:46 -05007 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
Jing Huang7725ccf2009-09-23 17:46:15 -07008 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License (GPL) Version 2 as
11 * published by the Free Software Foundation
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 */
18
Maggie Zhangf16a1752010-12-09 19:12:32 -080019#include "bfad_drv.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070020#include "bfa_modules.h"
Krishna Gudipati11189202011-06-13 15:50:35 -070021#include "bfi_reg.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070022
23void
24bfa_hwcb_reginit(struct bfa_s *bfa)
25{
26 struct bfa_iocfc_regs_s *bfa_regs = &bfa->iocfc.bfa_regs;
Jing Huang53440262010-10-18 17:12:29 -070027 void __iomem *kva = bfa_ioc_bar0(&bfa->ioc);
Krishna Gudipati11189202011-06-13 15:50:35 -070028 int fn = bfa_ioc_pcifn(&bfa->ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -070029
30 if (fn == 0) {
31 bfa_regs->intr_status = (kva + HOSTFN0_INT_STATUS);
32 bfa_regs->intr_mask = (kva + HOSTFN0_INT_MSK);
33 } else {
34 bfa_regs->intr_status = (kva + HOSTFN1_INT_STATUS);
35 bfa_regs->intr_mask = (kva + HOSTFN1_INT_MSK);
36 }
Jing Huang7725ccf2009-09-23 17:46:15 -070037}
38
Krishna Gudipatif5713c52010-03-05 19:37:09 -080039static void
40bfa_hwcb_reqq_ack_msix(struct bfa_s *bfa, int reqq)
41{
Jing Huang53440262010-10-18 17:12:29 -070042 writel(__HFN_INT_CPE_Q0 << CPE_Q_NUM(bfa_ioc_pcifn(&bfa->ioc), reqq),
43 bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatif5713c52010-03-05 19:37:09 -080044}
45
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -070046/*
47 * Actions to respond RME Interrupt for Crossbow ASIC:
48 * - Write 1 to Interrupt Status register
49 * INTX - done in bfa_intx()
50 * MSIX - done in bfa_hwcb_rspq_ack_msix()
51 * - Update CI (only if new CI)
52 */
Jing Huang7725ccf2009-09-23 17:46:15 -070053static void
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -070054bfa_hwcb_rspq_ack_msix(struct bfa_s *bfa, int rspq, u32 ci)
Jing Huang7725ccf2009-09-23 17:46:15 -070055{
Jing Huang53440262010-10-18 17:12:29 -070056 writel(__HFN_INT_RME_Q0 << RME_Q_NUM(bfa_ioc_pcifn(&bfa->ioc), rspq),
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -070057 bfa->iocfc.bfa_regs.intr_status);
58
59 if (bfa_rspq_ci(bfa, rspq) == ci)
60 return;
61
62 bfa_rspq_ci(bfa, rspq) = ci;
63 writel(ci, bfa->iocfc.bfa_regs.rme_q_ci[rspq]);
64 mmiowb();
65}
66
67void
68bfa_hwcb_rspq_ack(struct bfa_s *bfa, int rspq, u32 ci)
69{
70 if (bfa_rspq_ci(bfa, rspq) == ci)
71 return;
72
73 bfa_rspq_ci(bfa, rspq) = ci;
74 writel(ci, bfa->iocfc.bfa_regs.rme_q_ci[rspq]);
75 mmiowb();
Jing Huang7725ccf2009-09-23 17:46:15 -070076}
77
78void
79bfa_hwcb_msix_getvecs(struct bfa_s *bfa, u32 *msix_vecs_bmap,
80 u32 *num_vecs, u32 *max_vec_bit)
81{
82#define __HFN_NUMINTS 13
83 if (bfa_ioc_pcifn(&bfa->ioc) == 0) {
84 *msix_vecs_bmap = (__HFN_INT_CPE_Q0 | __HFN_INT_CPE_Q1 |
85 __HFN_INT_CPE_Q2 | __HFN_INT_CPE_Q3 |
86 __HFN_INT_RME_Q0 | __HFN_INT_RME_Q1 |
87 __HFN_INT_RME_Q2 | __HFN_INT_RME_Q3 |
88 __HFN_INT_MBOX_LPU0);
89 *max_vec_bit = __HFN_INT_MBOX_LPU0;
90 } else {
91 *msix_vecs_bmap = (__HFN_INT_CPE_Q4 | __HFN_INT_CPE_Q5 |
92 __HFN_INT_CPE_Q6 | __HFN_INT_CPE_Q7 |
93 __HFN_INT_RME_Q4 | __HFN_INT_RME_Q5 |
94 __HFN_INT_RME_Q6 | __HFN_INT_RME_Q7 |
95 __HFN_INT_MBOX_LPU1);
96 *max_vec_bit = __HFN_INT_MBOX_LPU1;
97 }
98
99 *msix_vecs_bmap |= (__HFN_INT_ERR_EMC | __HFN_INT_ERR_LPU0 |
100 __HFN_INT_ERR_LPU1 | __HFN_INT_ERR_PSS);
101 *num_vecs = __HFN_NUMINTS;
102}
103
Jing Huang5fbe25c2010-10-18 17:17:23 -0700104/*
Krishna Gudipati775c7742011-06-13 15:52:12 -0700105 * Dummy interrupt handler for handling spurious interrupts.
106 */
107static void
108bfa_hwcb_msix_dummy(struct bfa_s *bfa, int vec)
109{
110}
111
112/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700113 * No special setup required for crossbow -- vector assignments are implicit.
114 */
115void
116bfa_hwcb_msix_init(struct bfa_s *bfa, int nvecs)
117{
Jing Huangd4b671c2010-12-26 21:46:35 -0800118 WARN_ON((nvecs != 1) && (nvecs != __HFN_NUMINTS));
Jing Huang7725ccf2009-09-23 17:46:15 -0700119
120 bfa->msix.nvecs = nvecs;
Krishna Gudipati775c7742011-06-13 15:52:12 -0700121 bfa_hwcb_msix_uninstall(bfa);
122}
123
124void
125bfa_hwcb_msix_ctrl_install(struct bfa_s *bfa)
126{
127 int i;
128
129 if (bfa->msix.nvecs == 0)
130 return;
131
132 if (bfa->msix.nvecs == 1) {
Krishna Gudipati10a07372011-06-24 20:23:38 -0700133 for (i = BFI_MSIX_CPE_QMIN_CB; i < BFI_MSIX_CB_MAX; i++)
Krishna Gudipati775c7742011-06-13 15:52:12 -0700134 bfa->msix.handler[i] = bfa_msix_all;
135 return;
136 }
137
138 for (i = BFI_MSIX_RME_QMAX_CB+1; i < BFI_MSIX_CB_MAX; i++)
139 bfa->msix.handler[i] = bfa_msix_lpu_err;
140}
141
142void
143bfa_hwcb_msix_queue_install(struct bfa_s *bfa)
144{
145 int i;
146
147 if (bfa->msix.nvecs == 0)
148 return;
149
150 if (bfa->msix.nvecs == 1) {
151 for (i = BFI_MSIX_CPE_QMIN_CB; i <= BFI_MSIX_RME_QMAX_CB; i++)
Jing Huang7725ccf2009-09-23 17:46:15 -0700152 bfa->msix.handler[i] = bfa_msix_all;
153 return;
154 }
155
Krishna Gudipati11189202011-06-13 15:50:35 -0700156 for (i = BFI_MSIX_CPE_QMIN_CB; i <= BFI_MSIX_CPE_QMAX_CB; i++)
Jing Huang7725ccf2009-09-23 17:46:15 -0700157 bfa->msix.handler[i] = bfa_msix_reqq;
158
Krishna Gudipati11189202011-06-13 15:50:35 -0700159 for (i = BFI_MSIX_RME_QMIN_CB; i <= BFI_MSIX_RME_QMAX_CB; i++)
Jing Huang7725ccf2009-09-23 17:46:15 -0700160 bfa->msix.handler[i] = bfa_msix_rspq;
Jing Huang7725ccf2009-09-23 17:46:15 -0700161}
162
163void
164bfa_hwcb_msix_uninstall(struct bfa_s *bfa)
165{
Krishna Gudipati775c7742011-06-13 15:52:12 -0700166 int i;
167
168 for (i = 0; i < BFI_MSIX_CB_MAX; i++)
169 bfa->msix.handler[i] = bfa_hwcb_msix_dummy;
Jing Huang7725ccf2009-09-23 17:46:15 -0700170}
171
Jing Huang5fbe25c2010-10-18 17:17:23 -0700172/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700173 * No special enable/disable -- vector assignments are implicit.
174 */
175void
176bfa_hwcb_isr_mode_set(struct bfa_s *bfa, bfa_boolean_t msix)
177{
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -0700178 if (msix) {
179 bfa->iocfc.hwif.hw_reqq_ack = bfa_hwcb_reqq_ack_msix;
180 bfa->iocfc.hwif.hw_rspq_ack = bfa_hwcb_rspq_ack_msix;
181 } else {
182 bfa->iocfc.hwif.hw_reqq_ack = NULL;
183 bfa->iocfc.hwif.hw_rspq_ack = bfa_hwcb_rspq_ack;
184 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700185}
186
Jing Huang36d345a2010-07-08 19:57:33 -0700187void
188bfa_hwcb_msix_get_rme_range(struct bfa_s *bfa, u32 *start, u32 *end)
189{
Krishna Gudipati11189202011-06-13 15:50:35 -0700190 *start = BFI_MSIX_RME_QMIN_CB;
191 *end = BFI_MSIX_RME_QMAX_CB;
Jing Huang36d345a2010-07-08 19:57:33 -0700192}