aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/bfa/bfa_ioc_cb.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/bfa/bfa_ioc_cb.c')
-rw-r--r--drivers/scsi/bfa/bfa_ioc_cb.c264
1 files changed, 167 insertions, 97 deletions
diff --git a/drivers/scsi/bfa/bfa_ioc_cb.c b/drivers/scsi/bfa/bfa_ioc_cb.c
index 324bdde7ea2e..89ae4c8f95a2 100644
--- a/drivers/scsi/bfa/bfa_ioc_cb.c
+++ b/drivers/scsi/bfa/bfa_ioc_cb.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2005-2009 Brocade Communications Systems, Inc. 2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
3 * All rights reserved 3 * All rights reserved
4 * www.brocade.com 4 * www.brocade.com
5 * 5 *
@@ -15,33 +15,32 @@
15 * General Public License for more details. 15 * General Public License for more details.
16 */ 16 */
17 17
18#include <bfa.h> 18#include "bfad_drv.h"
19#include <bfa_ioc.h> 19#include "bfa_ioc.h"
20#include <bfa_fwimg_priv.h> 20#include "bfi_cbreg.h"
21#include <cna/bfa_cna_trcmod.h> 21#include "bfa_defs.h"
22#include <cs/bfa_debug.h>
23#include <bfi/bfi_ioc.h>
24#include <bfi/bfi_cbreg.h>
25#include <log/bfa_log_hal.h>
26#include <defs/bfa_defs_pci.h>
27 22
28BFA_TRC_FILE(CNA, IOC_CB); 23BFA_TRC_FILE(CNA, IOC_CB);
29 24
30/* 25/*
31 * forward declarations 26 * forward declarations
32 */ 27 */
33static bfa_status_t bfa_ioc_cb_pll_init(struct bfa_ioc_s *ioc);
34static bfa_boolean_t bfa_ioc_cb_firmware_lock(struct bfa_ioc_s *ioc); 28static bfa_boolean_t bfa_ioc_cb_firmware_lock(struct bfa_ioc_s *ioc);
35static void bfa_ioc_cb_firmware_unlock(struct bfa_ioc_s *ioc); 29static void bfa_ioc_cb_firmware_unlock(struct bfa_ioc_s *ioc);
36static void bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc); 30static void bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc);
37static void bfa_ioc_cb_map_port(struct bfa_ioc_s *ioc); 31static void bfa_ioc_cb_map_port(struct bfa_ioc_s *ioc);
38static void bfa_ioc_cb_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix); 32static void bfa_ioc_cb_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix);
39static void bfa_ioc_cb_notify_hbfail(struct bfa_ioc_s *ioc); 33static void bfa_ioc_cb_notify_fail(struct bfa_ioc_s *ioc);
40static void bfa_ioc_cb_ownership_reset(struct bfa_ioc_s *ioc); 34static void bfa_ioc_cb_ownership_reset(struct bfa_ioc_s *ioc);
35static bfa_boolean_t bfa_ioc_cb_sync_start(struct bfa_ioc_s *ioc);
36static void bfa_ioc_cb_sync_join(struct bfa_ioc_s *ioc);
37static void bfa_ioc_cb_sync_leave(struct bfa_ioc_s *ioc);
38static void bfa_ioc_cb_sync_ack(struct bfa_ioc_s *ioc);
39static bfa_boolean_t bfa_ioc_cb_sync_complete(struct bfa_ioc_s *ioc);
41 40
42struct bfa_ioc_hwif_s hwif_cb; 41static struct bfa_ioc_hwif_s hwif_cb;
43 42
44/** 43/*
45 * Called from bfa_ioc_attach() to map asic specific calls. 44 * Called from bfa_ioc_attach() to map asic specific calls.
46 */ 45 */
47void 46void
@@ -53,18 +52,38 @@ bfa_ioc_set_cb_hwif(struct bfa_ioc_s *ioc)
53 hwif_cb.ioc_reg_init = bfa_ioc_cb_reg_init; 52 hwif_cb.ioc_reg_init = bfa_ioc_cb_reg_init;
54 hwif_cb.ioc_map_port = bfa_ioc_cb_map_port; 53 hwif_cb.ioc_map_port = bfa_ioc_cb_map_port;
55 hwif_cb.ioc_isr_mode_set = bfa_ioc_cb_isr_mode_set; 54 hwif_cb.ioc_isr_mode_set = bfa_ioc_cb_isr_mode_set;
56 hwif_cb.ioc_notify_hbfail = bfa_ioc_cb_notify_hbfail; 55 hwif_cb.ioc_notify_fail = bfa_ioc_cb_notify_fail;
57 hwif_cb.ioc_ownership_reset = bfa_ioc_cb_ownership_reset; 56 hwif_cb.ioc_ownership_reset = bfa_ioc_cb_ownership_reset;
57 hwif_cb.ioc_sync_start = bfa_ioc_cb_sync_start;
58 hwif_cb.ioc_sync_join = bfa_ioc_cb_sync_join;
59 hwif_cb.ioc_sync_leave = bfa_ioc_cb_sync_leave;
60 hwif_cb.ioc_sync_ack = bfa_ioc_cb_sync_ack;
61 hwif_cb.ioc_sync_complete = bfa_ioc_cb_sync_complete;
58 62
59 ioc->ioc_hwif = &hwif_cb; 63 ioc->ioc_hwif = &hwif_cb;
60} 64}
61 65
62/** 66/*
63 * Return true if firmware of current driver matches the running firmware. 67 * Return true if firmware of current driver matches the running firmware.
64 */ 68 */
65static bfa_boolean_t 69static bfa_boolean_t
66bfa_ioc_cb_firmware_lock(struct bfa_ioc_s *ioc) 70bfa_ioc_cb_firmware_lock(struct bfa_ioc_s *ioc)
67{ 71{
72 struct bfi_ioc_image_hdr_s fwhdr;
73 uint32_t fwstate = readl(ioc->ioc_regs.ioc_fwstate);
74
75 if (fwstate == BFI_IOC_UNINIT)
76 return BFA_TRUE;
77
78 bfa_ioc_fwver_get(ioc, &fwhdr);
79
80 if (swab32(fwhdr.exec) == BFI_BOOT_TYPE_NORMAL)
81 return BFA_TRUE;
82
83 bfa_trc(ioc, fwstate);
84 bfa_trc(ioc, fwhdr.exec);
85 writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
86
68 return BFA_TRUE; 87 return BFA_TRUE;
69} 88}
70 89
@@ -73,17 +92,17 @@ bfa_ioc_cb_firmware_unlock(struct bfa_ioc_s *ioc)
73{ 92{
74} 93}
75 94
76/** 95/*
77 * Notify other functions on HB failure. 96 * Notify other functions on HB failure.
78 */ 97 */
79static void 98static void
80bfa_ioc_cb_notify_hbfail(struct bfa_ioc_s *ioc) 99bfa_ioc_cb_notify_fail(struct bfa_ioc_s *ioc)
81{ 100{
82 bfa_reg_write(ioc->ioc_regs.err_set, __PSS_ERR_STATUS_SET); 101 writel(__PSS_ERR_STATUS_SET, ioc->ioc_regs.err_set);
83 bfa_reg_read(ioc->ioc_regs.err_set); 102 readl(ioc->ioc_regs.err_set);
84} 103}
85 104
86/** 105/*
87 * Host to LPU mailbox message addresses 106 * Host to LPU mailbox message addresses
88 */ 107 */
89static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } iocreg_fnreg[] = { 108static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } iocreg_fnreg[] = {
@@ -91,10 +110,11 @@ static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } iocreg_fnreg[] = {
91 { HOSTFN1_LPU_MBOX0_8, LPU_HOSTFN1_MBOX0_8, HOST_PAGE_NUM_FN1 } 110 { HOSTFN1_LPU_MBOX0_8, LPU_HOSTFN1_MBOX0_8, HOST_PAGE_NUM_FN1 }
92}; 111};
93 112
94/** 113/*
95 * Host <-> LPU mailbox command/status registers 114 * Host <-> LPU mailbox command/status registers
96 */ 115 */
97static struct { u32 hfn, lpu; } iocreg_mbcmd[] = { 116static struct { u32 hfn, lpu; } iocreg_mbcmd[] = {
117
98 { HOSTFN0_LPU0_CMD_STAT, LPU0_HOSTFN0_CMD_STAT }, 118 { HOSTFN0_LPU0_CMD_STAT, LPU0_HOSTFN0_CMD_STAT },
99 { HOSTFN1_LPU1_CMD_STAT, LPU1_HOSTFN1_CMD_STAT } 119 { HOSTFN1_LPU1_CMD_STAT, LPU1_HOSTFN1_CMD_STAT }
100}; 120};
@@ -102,7 +122,7 @@ static struct { u32 hfn, lpu; } iocreg_mbcmd[] = {
102static void 122static void
103bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc) 123bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc)
104{ 124{
105 bfa_os_addr_t rb; 125 void __iomem *rb;
106 int pcifn = bfa_ioc_pcifn(ioc); 126 int pcifn = bfa_ioc_pcifn(ioc);
107 127
108 rb = bfa_ioc_bar0(ioc); 128 rb = bfa_ioc_bar0(ioc);
@@ -114,12 +134,14 @@ bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc)
114 if (ioc->port_id == 0) { 134 if (ioc->port_id == 0) {
115 ioc->ioc_regs.heartbeat = rb + BFA_IOC0_HBEAT_REG; 135 ioc->ioc_regs.heartbeat = rb + BFA_IOC0_HBEAT_REG;
116 ioc->ioc_regs.ioc_fwstate = rb + BFA_IOC0_STATE_REG; 136 ioc->ioc_regs.ioc_fwstate = rb + BFA_IOC0_STATE_REG;
137 ioc->ioc_regs.alt_ioc_fwstate = rb + BFA_IOC1_STATE_REG;
117 } else { 138 } else {
118 ioc->ioc_regs.heartbeat = (rb + BFA_IOC1_HBEAT_REG); 139 ioc->ioc_regs.heartbeat = (rb + BFA_IOC1_HBEAT_REG);
119 ioc->ioc_regs.ioc_fwstate = (rb + BFA_IOC1_STATE_REG); 140 ioc->ioc_regs.ioc_fwstate = (rb + BFA_IOC1_STATE_REG);
141 ioc->ioc_regs.alt_ioc_fwstate = (rb + BFA_IOC0_STATE_REG);
120 } 142 }
121 143
122 /** 144 /*
123 * Host <-> LPU mailbox command/status registers 145 * Host <-> LPU mailbox command/status registers
124 */ 146 */
125 ioc->ioc_regs.hfn_mbox_cmd = rb + iocreg_mbcmd[pcifn].hfn; 147 ioc->ioc_regs.hfn_mbox_cmd = rb + iocreg_mbcmd[pcifn].hfn;
@@ -139,7 +161,7 @@ bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc)
139 ioc->ioc_regs.ioc_sem_reg = (rb + HOST_SEM0_REG); 161 ioc->ioc_regs.ioc_sem_reg = (rb + HOST_SEM0_REG);
140 ioc->ioc_regs.ioc_init_sem_reg = (rb + HOST_SEM2_REG); 162 ioc->ioc_regs.ioc_init_sem_reg = (rb + HOST_SEM2_REG);
141 163
142 /** 164 /*
143 * sram memory access 165 * sram memory access
144 */ 166 */
145 ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START); 167 ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START);
@@ -151,20 +173,22 @@ bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc)
151 ioc->ioc_regs.err_set = (rb + ERR_SET_REG); 173 ioc->ioc_regs.err_set = (rb + ERR_SET_REG);
152} 174}
153 175
154/** 176/*
155 * Initialize IOC to port mapping. 177 * Initialize IOC to port mapping.
156 */ 178 */
179
157static void 180static void
158bfa_ioc_cb_map_port(struct bfa_ioc_s *ioc) 181bfa_ioc_cb_map_port(struct bfa_ioc_s *ioc)
159{ 182{
160 /** 183 /*
161 * For crossbow, port id is same as pci function. 184 * For crossbow, port id is same as pci function.
162 */ 185 */
163 ioc->port_id = bfa_ioc_pcifn(ioc); 186 ioc->port_id = bfa_ioc_pcifn(ioc);
187
164 bfa_trc(ioc, ioc->port_id); 188 bfa_trc(ioc, ioc->port_id);
165} 189}
166 190
167/** 191/*
168 * Set interrupt mode for a function: INTX or MSIX 192 * Set interrupt mode for a function: INTX or MSIX
169 */ 193 */
170static void 194static void
@@ -172,76 +196,16 @@ bfa_ioc_cb_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix)
172{ 196{
173} 197}
174 198
175static bfa_status_t 199/*
176bfa_ioc_cb_pll_init(struct bfa_ioc_s *ioc) 200 * Synchronized IOC failure processing routines
201 */
202static bfa_boolean_t
203bfa_ioc_cb_sync_start(struct bfa_ioc_s *ioc)
177{ 204{
178 bfa_os_addr_t rb = ioc->pcidev.pci_bar_kva; 205 return bfa_ioc_cb_sync_complete(ioc);
179 u32 pll_sclk, pll_fclk;
180
181 /*
182 * Hold semaphore so that nobody can access the chip during init.
183 */
184 bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
185
186 pll_sclk = __APP_PLL_212_ENABLE | __APP_PLL_212_LRESETN |
187 __APP_PLL_212_P0_1(3U) |
188 __APP_PLL_212_JITLMT0_1(3U) |
189 __APP_PLL_212_CNTLMT0_1(3U);
190 pll_fclk = __APP_PLL_400_ENABLE | __APP_PLL_400_LRESETN |
191 __APP_PLL_400_RSEL200500 | __APP_PLL_400_P0_1(3U) |
192 __APP_PLL_400_JITLMT0_1(3U) |
193 __APP_PLL_400_CNTLMT0_1(3U);
194
195 bfa_reg_write((rb + BFA_IOC0_STATE_REG), BFI_IOC_UNINIT);
196 bfa_reg_write((rb + BFA_IOC1_STATE_REG), BFI_IOC_UNINIT);
197
198 bfa_reg_write((rb + HOSTFN0_INT_MSK), 0xffffffffU);
199 bfa_reg_write((rb + HOSTFN1_INT_MSK), 0xffffffffU);
200 bfa_reg_write((rb + HOSTFN0_INT_STATUS), 0xffffffffU);
201 bfa_reg_write((rb + HOSTFN1_INT_STATUS), 0xffffffffU);
202 bfa_reg_write((rb + HOSTFN0_INT_MSK), 0xffffffffU);
203 bfa_reg_write((rb + HOSTFN1_INT_MSK), 0xffffffffU);
204
205 bfa_reg_write(ioc->ioc_regs.app_pll_slow_ctl_reg,
206 __APP_PLL_212_LOGIC_SOFT_RESET);
207 bfa_reg_write(ioc->ioc_regs.app_pll_slow_ctl_reg,
208 __APP_PLL_212_BYPASS |
209 __APP_PLL_212_LOGIC_SOFT_RESET);
210 bfa_reg_write(ioc->ioc_regs.app_pll_fast_ctl_reg,
211 __APP_PLL_400_LOGIC_SOFT_RESET);
212 bfa_reg_write(ioc->ioc_regs.app_pll_fast_ctl_reg,
213 __APP_PLL_400_BYPASS |
214 __APP_PLL_400_LOGIC_SOFT_RESET);
215 bfa_os_udelay(2);
216 bfa_reg_write(ioc->ioc_regs.app_pll_slow_ctl_reg,
217 __APP_PLL_212_LOGIC_SOFT_RESET);
218 bfa_reg_write(ioc->ioc_regs.app_pll_fast_ctl_reg,
219 __APP_PLL_400_LOGIC_SOFT_RESET);
220
221 bfa_reg_write(ioc->ioc_regs.app_pll_slow_ctl_reg,
222 pll_sclk | __APP_PLL_212_LOGIC_SOFT_RESET);
223 bfa_reg_write(ioc->ioc_regs.app_pll_fast_ctl_reg,
224 pll_fclk | __APP_PLL_400_LOGIC_SOFT_RESET);
225
226 /**
227 * Wait for PLLs to lock.
228 */
229 bfa_os_udelay(2000);
230 bfa_reg_write((rb + HOSTFN0_INT_STATUS), 0xffffffffU);
231 bfa_reg_write((rb + HOSTFN1_INT_STATUS), 0xffffffffU);
232
233 bfa_reg_write(ioc->ioc_regs.app_pll_slow_ctl_reg, pll_sclk);
234 bfa_reg_write(ioc->ioc_regs.app_pll_fast_ctl_reg, pll_fclk);
235
236 /*
237 * release semaphore.
238 */
239 bfa_ioc_sem_release(ioc->ioc_regs.ioc_init_sem_reg);
240
241 return BFA_STATUS_OK;
242} 206}
243 207
244/** 208/*
245 * Cleanup hw semaphore and usecnt registers 209 * Cleanup hw semaphore and usecnt registers
246 */ 210 */
247static void 211static void
@@ -253,6 +217,112 @@ bfa_ioc_cb_ownership_reset(struct bfa_ioc_s *ioc)
253 * before we clear it. If it is not locked, writing 1 217 * before we clear it. If it is not locked, writing 1
254 * will lock it instead of clearing it. 218 * will lock it instead of clearing it.
255 */ 219 */
256 bfa_reg_read(ioc->ioc_regs.ioc_sem_reg); 220 readl(ioc->ioc_regs.ioc_sem_reg);
257 bfa_ioc_hw_sem_release(ioc); 221 writel(1, ioc->ioc_regs.ioc_sem_reg);
222}
223
224/*
225 * Synchronized IOC failure processing routines
226 */
227static void
228bfa_ioc_cb_sync_join(struct bfa_ioc_s *ioc)
229{
230}
231
232static void
233bfa_ioc_cb_sync_leave(struct bfa_ioc_s *ioc)
234{
235}
236
237static void
238bfa_ioc_cb_sync_ack(struct bfa_ioc_s *ioc)
239{
240 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
241}
242
243static bfa_boolean_t
244bfa_ioc_cb_sync_complete(struct bfa_ioc_s *ioc)
245{
246 uint32_t fwstate, alt_fwstate;
247 fwstate = readl(ioc->ioc_regs.ioc_fwstate);
248
249 /*
250 * At this point, this IOC is hoding the hw sem in the
251 * start path (fwcheck) OR in the disable/enable path
252 * OR to check if the other IOC has acknowledged failure.
253 *
254 * So, this IOC can be in UNINIT, INITING, DISABLED, FAIL
255 * or in MEMTEST states. In a normal scenario, this IOC
256 * can not be in OP state when this function is called.
257 *
258 * However, this IOC could still be in OP state when
259 * the OS driver is starting up, if the OptROM code has
260 * left it in that state.
261 *
262 * If we had marked this IOC's fwstate as BFI_IOC_FAIL
263 * in the failure case and now, if the fwstate is not
264 * BFI_IOC_FAIL it implies that the other PCI fn have
265 * reinitialized the ASIC or this IOC got disabled, so
266 * return TRUE.
267 */
268 if (fwstate == BFI_IOC_UNINIT ||
269 fwstate == BFI_IOC_INITING ||
270 fwstate == BFI_IOC_DISABLED ||
271 fwstate == BFI_IOC_MEMTEST ||
272 fwstate == BFI_IOC_OP)
273 return BFA_TRUE;
274 else {
275 alt_fwstate = readl(ioc->ioc_regs.alt_ioc_fwstate);
276 if (alt_fwstate == BFI_IOC_FAIL ||
277 alt_fwstate == BFI_IOC_DISABLED ||
278 alt_fwstate == BFI_IOC_UNINIT ||
279 alt_fwstate == BFI_IOC_INITING ||
280 alt_fwstate == BFI_IOC_MEMTEST)
281 return BFA_TRUE;
282 else
283 return BFA_FALSE;
284 }
285}
286
287bfa_status_t
288bfa_ioc_cb_pll_init(void __iomem *rb, bfa_boolean_t fcmode)
289{
290 u32 pll_sclk, pll_fclk;
291
292 pll_sclk = __APP_PLL_212_ENABLE | __APP_PLL_212_LRESETN |
293 __APP_PLL_212_P0_1(3U) |
294 __APP_PLL_212_JITLMT0_1(3U) |
295 __APP_PLL_212_CNTLMT0_1(3U);
296 pll_fclk = __APP_PLL_400_ENABLE | __APP_PLL_400_LRESETN |
297 __APP_PLL_400_RSEL200500 | __APP_PLL_400_P0_1(3U) |
298 __APP_PLL_400_JITLMT0_1(3U) |
299 __APP_PLL_400_CNTLMT0_1(3U);
300 writel(BFI_IOC_UNINIT, (rb + BFA_IOC0_STATE_REG));
301 writel(BFI_IOC_UNINIT, (rb + BFA_IOC1_STATE_REG));
302 writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
303 writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
304 writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
305 writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
306 writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
307 writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
308 writel(__APP_PLL_212_LOGIC_SOFT_RESET, rb + APP_PLL_212_CTL_REG);
309 writel(__APP_PLL_212_BYPASS | __APP_PLL_212_LOGIC_SOFT_RESET,
310 rb + APP_PLL_212_CTL_REG);
311 writel(__APP_PLL_400_LOGIC_SOFT_RESET, rb + APP_PLL_400_CTL_REG);
312 writel(__APP_PLL_400_BYPASS | __APP_PLL_400_LOGIC_SOFT_RESET,
313 rb + APP_PLL_400_CTL_REG);
314 udelay(2);
315 writel(__APP_PLL_212_LOGIC_SOFT_RESET, rb + APP_PLL_212_CTL_REG);
316 writel(__APP_PLL_400_LOGIC_SOFT_RESET, rb + APP_PLL_400_CTL_REG);
317 writel(pll_sclk | __APP_PLL_212_LOGIC_SOFT_RESET,
318 rb + APP_PLL_212_CTL_REG);
319 writel(pll_fclk | __APP_PLL_400_LOGIC_SOFT_RESET,
320 rb + APP_PLL_400_CTL_REG);
321 udelay(2000);
322 writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
323 writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
324 writel(pll_sclk, (rb + APP_PLL_212_CTL_REG));
325 writel(pll_fclk, (rb + APP_PLL_400_CTL_REG));
326
327 return BFA_STATUS_OK;
258} 328}