[SCSI] bfa: Brocade-1860 Fabric Adapter vHBA support.
[pandora-kernel.git] / drivers / scsi / bfa / bfa_hw_cb.c
1 /*
2  * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
3  * All rights reserved
4  * www.brocade.com
5  *
6  * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License (GPL) Version 2 as
10  * published by the Free Software Foundation
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  */
17
18 #include "bfad_drv.h"
19 #include "bfa_modules.h"
20 #include "bfi_reg.h"
21
22 void
23 bfa_hwcb_reginit(struct bfa_s *bfa)
24 {
25         struct bfa_iocfc_regs_s *bfa_regs = &bfa->iocfc.bfa_regs;
26         void __iomem *kva = bfa_ioc_bar0(&bfa->ioc);
27         int     fn = bfa_ioc_pcifn(&bfa->ioc);
28
29         if (fn == 0) {
30                 bfa_regs->intr_status = (kva + HOSTFN0_INT_STATUS);
31                 bfa_regs->intr_mask   = (kva + HOSTFN0_INT_MSK);
32         } else {
33                 bfa_regs->intr_status = (kva + HOSTFN1_INT_STATUS);
34                 bfa_regs->intr_mask   = (kva + HOSTFN1_INT_MSK);
35         }
36 }
37
38 static void
39 bfa_hwcb_reqq_ack_msix(struct bfa_s *bfa, int reqq)
40 {
41         writel(__HFN_INT_CPE_Q0 << CPE_Q_NUM(bfa_ioc_pcifn(&bfa->ioc), reqq),
42                         bfa->iocfc.bfa_regs.intr_status);
43 }
44
45 static void
46 bfa_hwcb_rspq_ack_msix(struct bfa_s *bfa, int rspq)
47 {
48         writel(__HFN_INT_RME_Q0 << RME_Q_NUM(bfa_ioc_pcifn(&bfa->ioc), rspq),
49                         bfa->iocfc.bfa_regs.intr_status);
50 }
51
52 void
53 bfa_hwcb_msix_getvecs(struct bfa_s *bfa, u32 *msix_vecs_bmap,
54                  u32 *num_vecs, u32 *max_vec_bit)
55 {
56 #define __HFN_NUMINTS   13
57         if (bfa_ioc_pcifn(&bfa->ioc) == 0) {
58                 *msix_vecs_bmap = (__HFN_INT_CPE_Q0 | __HFN_INT_CPE_Q1 |
59                                    __HFN_INT_CPE_Q2 | __HFN_INT_CPE_Q3 |
60                                    __HFN_INT_RME_Q0 | __HFN_INT_RME_Q1 |
61                                    __HFN_INT_RME_Q2 | __HFN_INT_RME_Q3 |
62                                    __HFN_INT_MBOX_LPU0);
63                 *max_vec_bit = __HFN_INT_MBOX_LPU0;
64         } else {
65                 *msix_vecs_bmap = (__HFN_INT_CPE_Q4 | __HFN_INT_CPE_Q5 |
66                                    __HFN_INT_CPE_Q6 | __HFN_INT_CPE_Q7 |
67                                    __HFN_INT_RME_Q4 | __HFN_INT_RME_Q5 |
68                                    __HFN_INT_RME_Q6 | __HFN_INT_RME_Q7 |
69                                    __HFN_INT_MBOX_LPU1);
70                 *max_vec_bit = __HFN_INT_MBOX_LPU1;
71         }
72
73         *msix_vecs_bmap |= (__HFN_INT_ERR_EMC | __HFN_INT_ERR_LPU0 |
74                             __HFN_INT_ERR_LPU1 | __HFN_INT_ERR_PSS);
75         *num_vecs = __HFN_NUMINTS;
76 }
77
78 /*
79  * Dummy interrupt handler for handling spurious interrupts.
80  */
81 static void
82 bfa_hwcb_msix_dummy(struct bfa_s *bfa, int vec)
83 {
84 }
85
86 /*
87  * No special setup required for crossbow -- vector assignments are implicit.
88  */
89 void
90 bfa_hwcb_msix_init(struct bfa_s *bfa, int nvecs)
91 {
92         WARN_ON((nvecs != 1) && (nvecs != __HFN_NUMINTS));
93
94         bfa->msix.nvecs = nvecs;
95         bfa_hwcb_msix_uninstall(bfa);
96 }
97
98 void
99 bfa_hwcb_msix_ctrl_install(struct bfa_s *bfa)
100 {
101         int i;
102
103         if (bfa->msix.nvecs == 0)
104                 return;
105
106         if (bfa->msix.nvecs == 1) {
107                 for (i = BFI_MSIX_CPE_QMIN_CB; i < BFI_MSIX_CB_MAX; i++)
108                         bfa->msix.handler[i] = bfa_msix_all;
109                 return;
110         }
111
112         for (i = BFI_MSIX_RME_QMAX_CB+1; i < BFI_MSIX_CB_MAX; i++)
113                 bfa->msix.handler[i] = bfa_msix_lpu_err;
114 }
115
116 void
117 bfa_hwcb_msix_queue_install(struct bfa_s *bfa)
118 {
119         int i;
120
121         if (bfa->msix.nvecs == 0)
122                 return;
123
124         if (bfa->msix.nvecs == 1) {
125                 for (i = BFI_MSIX_CPE_QMIN_CB; i <= BFI_MSIX_RME_QMAX_CB; i++)
126                         bfa->msix.handler[i] = bfa_msix_all;
127                 return;
128         }
129
130         for (i = BFI_MSIX_CPE_QMIN_CB; i <= BFI_MSIX_CPE_QMAX_CB; i++)
131                 bfa->msix.handler[i] = bfa_msix_reqq;
132
133         for (i = BFI_MSIX_RME_QMIN_CB; i <= BFI_MSIX_RME_QMAX_CB; i++)
134                 bfa->msix.handler[i] = bfa_msix_rspq;
135 }
136
137 void
138 bfa_hwcb_msix_uninstall(struct bfa_s *bfa)
139 {
140         int i;
141
142         for (i = 0; i < BFI_MSIX_CB_MAX; i++)
143                 bfa->msix.handler[i] = bfa_hwcb_msix_dummy;
144 }
145
146 /*
147  * No special enable/disable -- vector assignments are implicit.
148  */
149 void
150 bfa_hwcb_isr_mode_set(struct bfa_s *bfa, bfa_boolean_t msix)
151 {
152         bfa->iocfc.hwif.hw_reqq_ack = bfa_hwcb_reqq_ack_msix;
153         bfa->iocfc.hwif.hw_rspq_ack = bfa_hwcb_rspq_ack_msix;
154 }
155
156 void
157 bfa_hwcb_msix_get_rme_range(struct bfa_s *bfa, u32 *start, u32 *end)
158 {
159         *start = BFI_MSIX_RME_QMIN_CB;
160         *end = BFI_MSIX_RME_QMAX_CB;
161 }