2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
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
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.
20 #include "bfi_ctreg.h"
23 BFA_TRC_FILE(CNA
, IOC_CT
);
25 #define bfa_ioc_ct_sync_pos(__ioc) \
26 ((uint32_t) (1 << bfa_ioc_pcifn(__ioc)))
27 #define BFA_IOC_SYNC_REQD_SH 16
28 #define bfa_ioc_ct_get_sync_ackd(__val) (__val & 0x0000ffff)
29 #define bfa_ioc_ct_clear_sync_ackd(__val) (__val & 0xffff0000)
30 #define bfa_ioc_ct_get_sync_reqd(__val) (__val >> BFA_IOC_SYNC_REQD_SH)
31 #define bfa_ioc_ct_sync_reqd_pos(__ioc) \
32 (bfa_ioc_ct_sync_pos(__ioc) << BFA_IOC_SYNC_REQD_SH)
35 * forward declarations
37 static bfa_boolean_t
bfa_ioc_ct_firmware_lock(struct bfa_ioc_s
*ioc
);
38 static void bfa_ioc_ct_firmware_unlock(struct bfa_ioc_s
*ioc
);
39 static void bfa_ioc_ct_reg_init(struct bfa_ioc_s
*ioc
);
40 static void bfa_ioc_ct_map_port(struct bfa_ioc_s
*ioc
);
41 static void bfa_ioc_ct_isr_mode_set(struct bfa_ioc_s
*ioc
, bfa_boolean_t msix
);
42 static void bfa_ioc_ct_notify_fail(struct bfa_ioc_s
*ioc
);
43 static void bfa_ioc_ct_ownership_reset(struct bfa_ioc_s
*ioc
);
44 static bfa_boolean_t
bfa_ioc_ct_sync_start(struct bfa_ioc_s
*ioc
);
45 static void bfa_ioc_ct_sync_join(struct bfa_ioc_s
*ioc
);
46 static void bfa_ioc_ct_sync_leave(struct bfa_ioc_s
*ioc
);
47 static void bfa_ioc_ct_sync_ack(struct bfa_ioc_s
*ioc
);
48 static bfa_boolean_t
bfa_ioc_ct_sync_complete(struct bfa_ioc_s
*ioc
);
50 static struct bfa_ioc_hwif_s hwif_ct
;
53 * Called from bfa_ioc_attach() to map asic specific calls.
56 bfa_ioc_set_ct_hwif(struct bfa_ioc_s
*ioc
)
58 hwif_ct
.ioc_pll_init
= bfa_ioc_ct_pll_init
;
59 hwif_ct
.ioc_firmware_lock
= bfa_ioc_ct_firmware_lock
;
60 hwif_ct
.ioc_firmware_unlock
= bfa_ioc_ct_firmware_unlock
;
61 hwif_ct
.ioc_reg_init
= bfa_ioc_ct_reg_init
;
62 hwif_ct
.ioc_map_port
= bfa_ioc_ct_map_port
;
63 hwif_ct
.ioc_isr_mode_set
= bfa_ioc_ct_isr_mode_set
;
64 hwif_ct
.ioc_notify_fail
= bfa_ioc_ct_notify_fail
;
65 hwif_ct
.ioc_ownership_reset
= bfa_ioc_ct_ownership_reset
;
66 hwif_ct
.ioc_sync_start
= bfa_ioc_ct_sync_start
;
67 hwif_ct
.ioc_sync_join
= bfa_ioc_ct_sync_join
;
68 hwif_ct
.ioc_sync_leave
= bfa_ioc_ct_sync_leave
;
69 hwif_ct
.ioc_sync_ack
= bfa_ioc_ct_sync_ack
;
70 hwif_ct
.ioc_sync_complete
= bfa_ioc_ct_sync_complete
;
72 ioc
->ioc_hwif
= &hwif_ct
;
76 * Return true if firmware of current driver matches the running firmware.
79 bfa_ioc_ct_firmware_lock(struct bfa_ioc_s
*ioc
)
81 enum bfi_ioc_state ioc_fwstate
;
83 struct bfi_ioc_image_hdr_s fwhdr
;
86 * Firmware match check is relevant only for CNA.
92 * If bios boot (flash based) -- do not increment usage count
94 if (bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc
)) <
98 bfa_ioc_sem_get(ioc
->ioc_regs
.ioc_usage_sem_reg
);
99 usecnt
= readl(ioc
->ioc_regs
.ioc_usage_reg
);
102 * If usage count is 0, always return TRUE.
105 writel(1, ioc
->ioc_regs
.ioc_usage_reg
);
106 writel(1, ioc
->ioc_regs
.ioc_usage_sem_reg
);
107 writel(0, ioc
->ioc_regs
.ioc_fail_sync
);
108 bfa_trc(ioc
, usecnt
);
112 ioc_fwstate
= readl(ioc
->ioc_regs
.ioc_fwstate
);
113 bfa_trc(ioc
, ioc_fwstate
);
116 * Use count cannot be non-zero and chip in uninitialized state.
118 WARN_ON(ioc_fwstate
== BFI_IOC_UNINIT
);
121 * Check if another driver with a different firmware is active
123 bfa_ioc_fwver_get(ioc
, &fwhdr
);
124 if (!bfa_ioc_fwver_cmp(ioc
, &fwhdr
)) {
125 writel(1, ioc
->ioc_regs
.ioc_usage_sem_reg
);
126 bfa_trc(ioc
, usecnt
);
131 * Same firmware version. Increment the reference count.
134 writel(usecnt
, ioc
->ioc_regs
.ioc_usage_reg
);
135 writel(1, ioc
->ioc_regs
.ioc_usage_sem_reg
);
136 bfa_trc(ioc
, usecnt
);
141 bfa_ioc_ct_firmware_unlock(struct bfa_ioc_s
*ioc
)
146 * Firmware lock is relevant only for CNA.
152 * If bios boot (flash based) -- do not decrement usage count
154 if (bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc
)) <
159 * decrement usage count
161 bfa_ioc_sem_get(ioc
->ioc_regs
.ioc_usage_sem_reg
);
162 usecnt
= readl(ioc
->ioc_regs
.ioc_usage_reg
);
163 WARN_ON(usecnt
<= 0);
166 writel(usecnt
, ioc
->ioc_regs
.ioc_usage_reg
);
167 bfa_trc(ioc
, usecnt
);
169 writel(1, ioc
->ioc_regs
.ioc_usage_sem_reg
);
173 * Notify other functions on HB failure.
176 bfa_ioc_ct_notify_fail(struct bfa_ioc_s
*ioc
)
179 writel(__FW_INIT_HALT_P
, ioc
->ioc_regs
.ll_halt
);
180 writel(__FW_INIT_HALT_P
, ioc
->ioc_regs
.alt_ll_halt
);
181 /* Wait for halt to take effect */
182 readl(ioc
->ioc_regs
.ll_halt
);
183 readl(ioc
->ioc_regs
.alt_ll_halt
);
185 writel(__PSS_ERR_STATUS_SET
, ioc
->ioc_regs
.err_set
);
186 readl(ioc
->ioc_regs
.err_set
);
191 * Host to LPU mailbox message addresses
193 static struct { u32 hfn_mbox
, lpu_mbox
, hfn_pgn
; } iocreg_fnreg
[] = {
194 { HOSTFN0_LPU_MBOX0_0
, LPU_HOSTFN0_MBOX0_0
, HOST_PAGE_NUM_FN0
},
195 { HOSTFN1_LPU_MBOX0_8
, LPU_HOSTFN1_MBOX0_8
, HOST_PAGE_NUM_FN1
},
196 { HOSTFN2_LPU_MBOX0_0
, LPU_HOSTFN2_MBOX0_0
, HOST_PAGE_NUM_FN2
},
197 { HOSTFN3_LPU_MBOX0_8
, LPU_HOSTFN3_MBOX0_8
, HOST_PAGE_NUM_FN3
}
201 * Host <-> LPU mailbox command/status registers - port 0
203 static struct { u32 hfn
, lpu
; } iocreg_mbcmd_p0
[] = {
204 { HOSTFN0_LPU0_MBOX0_CMD_STAT
, LPU0_HOSTFN0_MBOX0_CMD_STAT
},
205 { HOSTFN1_LPU0_MBOX0_CMD_STAT
, LPU0_HOSTFN1_MBOX0_CMD_STAT
},
206 { HOSTFN2_LPU0_MBOX0_CMD_STAT
, LPU0_HOSTFN2_MBOX0_CMD_STAT
},
207 { HOSTFN3_LPU0_MBOX0_CMD_STAT
, LPU0_HOSTFN3_MBOX0_CMD_STAT
}
211 * Host <-> LPU mailbox command/status registers - port 1
213 static struct { u32 hfn
, lpu
; } iocreg_mbcmd_p1
[] = {
214 { HOSTFN0_LPU1_MBOX0_CMD_STAT
, LPU1_HOSTFN0_MBOX0_CMD_STAT
},
215 { HOSTFN1_LPU1_MBOX0_CMD_STAT
, LPU1_HOSTFN1_MBOX0_CMD_STAT
},
216 { HOSTFN2_LPU1_MBOX0_CMD_STAT
, LPU1_HOSTFN2_MBOX0_CMD_STAT
},
217 { HOSTFN3_LPU1_MBOX0_CMD_STAT
, LPU1_HOSTFN3_MBOX0_CMD_STAT
}
221 bfa_ioc_ct_reg_init(struct bfa_ioc_s
*ioc
)
224 int pcifn
= bfa_ioc_pcifn(ioc
);
226 rb
= bfa_ioc_bar0(ioc
);
228 ioc
->ioc_regs
.hfn_mbox
= rb
+ iocreg_fnreg
[pcifn
].hfn_mbox
;
229 ioc
->ioc_regs
.lpu_mbox
= rb
+ iocreg_fnreg
[pcifn
].lpu_mbox
;
230 ioc
->ioc_regs
.host_page_num_fn
= rb
+ iocreg_fnreg
[pcifn
].hfn_pgn
;
232 if (ioc
->port_id
== 0) {
233 ioc
->ioc_regs
.heartbeat
= rb
+ BFA_IOC0_HBEAT_REG
;
234 ioc
->ioc_regs
.ioc_fwstate
= rb
+ BFA_IOC0_STATE_REG
;
235 ioc
->ioc_regs
.alt_ioc_fwstate
= rb
+ BFA_IOC1_STATE_REG
;
236 ioc
->ioc_regs
.hfn_mbox_cmd
= rb
+ iocreg_mbcmd_p0
[pcifn
].hfn
;
237 ioc
->ioc_regs
.lpu_mbox_cmd
= rb
+ iocreg_mbcmd_p0
[pcifn
].lpu
;
238 ioc
->ioc_regs
.ll_halt
= rb
+ FW_INIT_HALT_P0
;
239 ioc
->ioc_regs
.alt_ll_halt
= rb
+ FW_INIT_HALT_P1
;
241 ioc
->ioc_regs
.heartbeat
= (rb
+ BFA_IOC1_HBEAT_REG
);
242 ioc
->ioc_regs
.ioc_fwstate
= (rb
+ BFA_IOC1_STATE_REG
);
243 ioc
->ioc_regs
.alt_ioc_fwstate
= rb
+ BFA_IOC0_STATE_REG
;
244 ioc
->ioc_regs
.hfn_mbox_cmd
= rb
+ iocreg_mbcmd_p1
[pcifn
].hfn
;
245 ioc
->ioc_regs
.lpu_mbox_cmd
= rb
+ iocreg_mbcmd_p1
[pcifn
].lpu
;
246 ioc
->ioc_regs
.ll_halt
= rb
+ FW_INIT_HALT_P1
;
247 ioc
->ioc_regs
.alt_ll_halt
= rb
+ FW_INIT_HALT_P0
;
251 * PSS control registers
253 ioc
->ioc_regs
.pss_ctl_reg
= (rb
+ PSS_CTL_REG
);
254 ioc
->ioc_regs
.pss_err_status_reg
= (rb
+ PSS_ERR_STATUS_REG
);
255 ioc
->ioc_regs
.app_pll_fast_ctl_reg
= (rb
+ APP_PLL_425_CTL_REG
);
256 ioc
->ioc_regs
.app_pll_slow_ctl_reg
= (rb
+ APP_PLL_312_CTL_REG
);
259 * IOC semaphore registers and serialization
261 ioc
->ioc_regs
.ioc_sem_reg
= (rb
+ HOST_SEM0_REG
);
262 ioc
->ioc_regs
.ioc_usage_sem_reg
= (rb
+ HOST_SEM1_REG
);
263 ioc
->ioc_regs
.ioc_init_sem_reg
= (rb
+ HOST_SEM2_REG
);
264 ioc
->ioc_regs
.ioc_usage_reg
= (rb
+ BFA_FW_USE_COUNT
);
265 ioc
->ioc_regs
.ioc_fail_sync
= (rb
+ BFA_IOC_FAIL_SYNC
);
270 ioc
->ioc_regs
.smem_page_start
= (rb
+ PSS_SMEM_PAGE_START
);
271 ioc
->ioc_regs
.smem_pg0
= BFI_IOC_SMEM_PG0_CT
;
274 * err set reg : for notification of hb failure in fcmode
276 ioc
->ioc_regs
.err_set
= (rb
+ ERR_SET_REG
);
280 * Initialize IOC to port mapping.
283 #define FNC_PERS_FN_SHIFT(__fn) ((__fn) * 8)
285 bfa_ioc_ct_map_port(struct bfa_ioc_s
*ioc
)
287 void __iomem
*rb
= ioc
->pcidev
.pci_bar_kva
;
291 * For catapult, base port id on personality register and IOC type
293 r32
= readl(rb
+ FNC_PERS_REG
);
294 r32
>>= FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc
));
295 ioc
->port_id
= (r32
& __F0_PORT_MAP_MK
) >> __F0_PORT_MAP_SH
;
297 bfa_trc(ioc
, bfa_ioc_pcifn(ioc
));
298 bfa_trc(ioc
, ioc
->port_id
);
302 * Set interrupt mode for a function: INTX or MSIX
305 bfa_ioc_ct_isr_mode_set(struct bfa_ioc_s
*ioc
, bfa_boolean_t msix
)
307 void __iomem
*rb
= ioc
->pcidev
.pci_bar_kva
;
310 r32
= readl(rb
+ FNC_PERS_REG
);
313 mode
= (r32
>> FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc
))) &
317 * If already in desired mode, do not change anything
323 mode
= __F0_INTX_STATUS_MSIX
;
325 mode
= __F0_INTX_STATUS_INTA
;
327 r32
&= ~(__F0_INTX_STATUS
<< FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc
)));
328 r32
|= (mode
<< FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc
)));
331 writel(r32
, rb
+ FNC_PERS_REG
);
335 * Cleanup hw semaphore and usecnt registers
338 bfa_ioc_ct_ownership_reset(struct bfa_ioc_s
*ioc
)
342 bfa_ioc_sem_get(ioc
->ioc_regs
.ioc_usage_sem_reg
);
343 writel(0, ioc
->ioc_regs
.ioc_usage_reg
);
344 writel(1, ioc
->ioc_regs
.ioc_usage_sem_reg
);
348 * Read the hw sem reg to make sure that it is locked
349 * before we clear it. If it is not locked, writing 1
350 * will lock it instead of clearing it.
352 readl(ioc
->ioc_regs
.ioc_sem_reg
);
353 writel(1, ioc
->ioc_regs
.ioc_sem_reg
);
357 bfa_ioc_ct_sync_start(struct bfa_ioc_s
*ioc
)
359 uint32_t r32
= readl(ioc
->ioc_regs
.ioc_fail_sync
);
360 uint32_t sync_reqd
= bfa_ioc_ct_get_sync_reqd(r32
);
363 * Driver load time. If the sync required bit for this PCI fn
364 * is set, it is due to an unclean exit by the driver for this
365 * PCI fn in the previous incarnation. Whoever comes here first
366 * should clean it up, no matter which PCI fn.
369 if (sync_reqd
& bfa_ioc_ct_sync_pos(ioc
)) {
370 writel(0, ioc
->ioc_regs
.ioc_fail_sync
);
371 writel(1, ioc
->ioc_regs
.ioc_usage_reg
);
372 writel(BFI_IOC_UNINIT
, ioc
->ioc_regs
.ioc_fwstate
);
373 writel(BFI_IOC_UNINIT
, ioc
->ioc_regs
.alt_ioc_fwstate
);
377 return bfa_ioc_ct_sync_complete(ioc
);
381 * Synchronized IOC failure processing routines
384 bfa_ioc_ct_sync_join(struct bfa_ioc_s
*ioc
)
386 uint32_t r32
= readl(ioc
->ioc_regs
.ioc_fail_sync
);
387 uint32_t sync_pos
= bfa_ioc_ct_sync_reqd_pos(ioc
);
389 writel((r32
| sync_pos
), ioc
->ioc_regs
.ioc_fail_sync
);
393 bfa_ioc_ct_sync_leave(struct bfa_ioc_s
*ioc
)
395 uint32_t r32
= readl(ioc
->ioc_regs
.ioc_fail_sync
);
396 uint32_t sync_msk
= bfa_ioc_ct_sync_reqd_pos(ioc
) |
397 bfa_ioc_ct_sync_pos(ioc
);
399 writel((r32
& ~sync_msk
), ioc
->ioc_regs
.ioc_fail_sync
);
403 bfa_ioc_ct_sync_ack(struct bfa_ioc_s
*ioc
)
405 uint32_t r32
= readl(ioc
->ioc_regs
.ioc_fail_sync
);
407 writel((r32
| bfa_ioc_ct_sync_pos(ioc
)),
408 ioc
->ioc_regs
.ioc_fail_sync
);
412 bfa_ioc_ct_sync_complete(struct bfa_ioc_s
*ioc
)
414 uint32_t r32
= readl(ioc
->ioc_regs
.ioc_fail_sync
);
415 uint32_t sync_reqd
= bfa_ioc_ct_get_sync_reqd(r32
);
416 uint32_t sync_ackd
= bfa_ioc_ct_get_sync_ackd(r32
);
423 * The check below is to see whether any other PCI fn
424 * has reinitialized the ASIC (reset sync_ackd bits)
425 * and failed again while this IOC was waiting for hw
426 * semaphore (in bfa_iocpf_sm_semwait()).
428 tmp_ackd
= sync_ackd
;
429 if ((sync_reqd
& bfa_ioc_ct_sync_pos(ioc
)) &&
430 !(sync_ackd
& bfa_ioc_ct_sync_pos(ioc
)))
431 sync_ackd
|= bfa_ioc_ct_sync_pos(ioc
);
433 if (sync_reqd
== sync_ackd
) {
434 writel(bfa_ioc_ct_clear_sync_ackd(r32
),
435 ioc
->ioc_regs
.ioc_fail_sync
);
436 writel(BFI_IOC_FAIL
, ioc
->ioc_regs
.ioc_fwstate
);
437 writel(BFI_IOC_FAIL
, ioc
->ioc_regs
.alt_ioc_fwstate
);
442 * If another PCI fn reinitialized and failed again while
443 * this IOC was waiting for hw sem, the sync_ackd bit for
444 * this IOC need to be set again to allow reinitialization.
446 if (tmp_ackd
!= sync_ackd
)
447 writel((r32
| sync_ackd
), ioc
->ioc_regs
.ioc_fail_sync
);
453 * Check the firmware state to know if pll_init has been completed already
456 bfa_ioc_ct_pll_init_complete(void __iomem
*rb
)
458 if ((readl(rb
+ BFA_IOC0_STATE_REG
) == BFI_IOC_OP
) ||
459 (readl(rb
+ BFA_IOC1_STATE_REG
) == BFI_IOC_OP
))
466 bfa_ioc_ct_pll_init(void __iomem
*rb
, bfa_boolean_t fcmode
)
468 u32 pll_sclk
, pll_fclk
, r32
;
470 pll_sclk
= __APP_PLL_312_LRESETN
| __APP_PLL_312_ENARST
|
471 __APP_PLL_312_RSEL200500
| __APP_PLL_312_P0_1(3U) |
472 __APP_PLL_312_JITLMT0_1(3U) |
473 __APP_PLL_312_CNTLMT0_1(1U);
474 pll_fclk
= __APP_PLL_425_LRESETN
| __APP_PLL_425_ENARST
|
475 __APP_PLL_425_RSEL200500
| __APP_PLL_425_P0_1(3U) |
476 __APP_PLL_425_JITLMT0_1(3U) |
477 __APP_PLL_425_CNTLMT0_1(1U);
479 writel(0, (rb
+ OP_MODE
));
480 writel(__APP_EMS_CMLCKSEL
| __APP_EMS_REFCKBUFEN2
|
481 __APP_EMS_CHANNEL_SEL
, (rb
+ ETH_MAC_SER_REG
));
483 writel(__GLOBAL_FCOE_MODE
, (rb
+ OP_MODE
));
484 writel(__APP_EMS_REFCKBUFEN1
, (rb
+ ETH_MAC_SER_REG
));
486 writel(BFI_IOC_UNINIT
, (rb
+ BFA_IOC0_STATE_REG
));
487 writel(BFI_IOC_UNINIT
, (rb
+ BFA_IOC1_STATE_REG
));
488 writel(0xffffffffU
, (rb
+ HOSTFN0_INT_MSK
));
489 writel(0xffffffffU
, (rb
+ HOSTFN1_INT_MSK
));
490 writel(0xffffffffU
, (rb
+ HOSTFN0_INT_STATUS
));
491 writel(0xffffffffU
, (rb
+ HOSTFN1_INT_STATUS
));
492 writel(0xffffffffU
, (rb
+ HOSTFN0_INT_MSK
));
493 writel(0xffffffffU
, (rb
+ HOSTFN1_INT_MSK
));
494 writel(pll_sclk
| __APP_PLL_312_LOGIC_SOFT_RESET
,
495 rb
+ APP_PLL_312_CTL_REG
);
496 writel(pll_fclk
| __APP_PLL_425_LOGIC_SOFT_RESET
,
497 rb
+ APP_PLL_425_CTL_REG
);
498 writel(pll_sclk
| __APP_PLL_312_LOGIC_SOFT_RESET
| __APP_PLL_312_ENABLE
,
499 rb
+ APP_PLL_312_CTL_REG
);
500 writel(pll_fclk
| __APP_PLL_425_LOGIC_SOFT_RESET
| __APP_PLL_425_ENABLE
,
501 rb
+ APP_PLL_425_CTL_REG
);
502 readl(rb
+ HOSTFN0_INT_MSK
);
504 writel(0xffffffffU
, (rb
+ HOSTFN0_INT_STATUS
));
505 writel(0xffffffffU
, (rb
+ HOSTFN1_INT_STATUS
));
506 writel(pll_sclk
| __APP_PLL_312_ENABLE
, rb
+ APP_PLL_312_CTL_REG
);
507 writel(pll_fclk
| __APP_PLL_425_ENABLE
, rb
+ APP_PLL_425_CTL_REG
);
509 writel(__PMM_1T_RESET_P
, (rb
+ PMM_1T_RESET_REG_P0
));
510 writel(__PMM_1T_RESET_P
, (rb
+ PMM_1T_RESET_REG_P1
));
512 r32
= readl((rb
+ PSS_CTL_REG
));
513 r32
&= ~__PSS_LMEM_RESET
;
514 writel(r32
, (rb
+ PSS_CTL_REG
));
517 writel(0, (rb
+ PMM_1T_RESET_REG_P0
));
518 writel(0, (rb
+ PMM_1T_RESET_REG_P1
));
521 writel(__EDRAM_BISTR_START
, (rb
+ MBIST_CTL_REG
));
523 r32
= readl((rb
+ MBIST_STAT_REG
));
524 writel(0, (rb
+ MBIST_CTL_REG
));
525 return BFA_STATUS_OK
;