blob: 5b5579401d43de52baf9421aab14347bed90534d [file] [log] [blame]
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
Krishna Gudipati0a20de42010-03-05 19:34:20 -08003 * 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
Maggie Zhangf16a1752010-12-09 19:12:32 -080018#include "bfad_drv.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070019#include "bfa_ioc.h"
Krishna Gudipati11189202011-06-13 15:50:35 -070020#include "bfi_reg.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070021#include "bfa_defs.h"
Krishna Gudipati0a20de42010-03-05 19:34:20 -080022
23BFA_TRC_FILE(CNA, IOC_CT);
24
Krishna Gudipatif1d584d2010-12-13 16:17:11 -080025#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)
33
Krishna Gudipati0a20de42010-03-05 19:34:20 -080034/*
35 * forward declarations
36 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -080037static bfa_boolean_t bfa_ioc_ct_firmware_lock(struct bfa_ioc_s *ioc);
38static void bfa_ioc_ct_firmware_unlock(struct bfa_ioc_s *ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -080039static void bfa_ioc_ct_notify_fail(struct bfa_ioc_s *ioc);
Krishna Gudipati0a20de42010-03-05 19:34:20 -080040static void bfa_ioc_ct_ownership_reset(struct bfa_ioc_s *ioc);
Jing Huang45d7f0c2011-04-13 11:45:53 -070041static bfa_boolean_t bfa_ioc_ct_sync_start(struct bfa_ioc_s *ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -080042static void bfa_ioc_ct_sync_join(struct bfa_ioc_s *ioc);
43static void bfa_ioc_ct_sync_leave(struct bfa_ioc_s *ioc);
44static void bfa_ioc_ct_sync_ack(struct bfa_ioc_s *ioc);
45static bfa_boolean_t bfa_ioc_ct_sync_complete(struct bfa_ioc_s *ioc);
Krishna Gudipati0a20de42010-03-05 19:34:20 -080046
Maggie52f94b62010-11-29 18:21:32 -080047static struct bfa_ioc_hwif_s hwif_ct;
Krishna Gudipati11189202011-06-13 15:50:35 -070048static struct bfa_ioc_hwif_s hwif_ct2;
Krishna Gudipati0a20de42010-03-05 19:34:20 -080049
Jing Huang5fbe25c2010-10-18 17:17:23 -070050/*
Krishna Gudipati0a20de42010-03-05 19:34:20 -080051 * Return true if firmware of current driver matches the running firmware.
52 */
53static bfa_boolean_t
54bfa_ioc_ct_firmware_lock(struct bfa_ioc_s *ioc)
55{
56 enum bfi_ioc_state ioc_fwstate;
Krishna Gudipatid1c61f82010-03-05 19:38:44 -080057 u32 usecnt;
Krishna Gudipati0a20de42010-03-05 19:34:20 -080058 struct bfi_ioc_image_hdr_s fwhdr;
59
Jing Huang5fbe25c2010-10-18 17:17:23 -070060 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -080061 * Firmware match check is relevant only for CNA.
62 */
Krishna Gudipati11189202011-06-13 15:50:35 -070063 if (!bfa_ioc_is_cna(ioc))
Krishna Gudipati0a20de42010-03-05 19:34:20 -080064 return BFA_TRUE;
65
Jing Huang5fbe25c2010-10-18 17:17:23 -070066 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -080067 * If bios boot (flash based) -- do not increment usage count
68 */
Krishna Gudipati11189202011-06-13 15:50:35 -070069 if (bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)) <
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070070 BFA_IOC_FWIMG_MINSZ)
Krishna Gudipati0a20de42010-03-05 19:34:20 -080071 return BFA_TRUE;
72
73 bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg);
Jing Huang53440262010-10-18 17:12:29 -070074 usecnt = readl(ioc->ioc_regs.ioc_usage_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -080075
Jing Huang5fbe25c2010-10-18 17:17:23 -070076 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -080077 * If usage count is 0, always return TRUE.
78 */
79 if (usecnt == 0) {
Jing Huang53440262010-10-18 17:12:29 -070080 writel(1, ioc->ioc_regs.ioc_usage_reg);
Maggie Zhangf7f738122010-12-09 19:08:43 -080081 writel(1, ioc->ioc_regs.ioc_usage_sem_reg);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -080082 writel(0, ioc->ioc_regs.ioc_fail_sync);
Krishna Gudipati0a20de42010-03-05 19:34:20 -080083 bfa_trc(ioc, usecnt);
84 return BFA_TRUE;
85 }
86
Jing Huang53440262010-10-18 17:12:29 -070087 ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
Krishna Gudipati0a20de42010-03-05 19:34:20 -080088 bfa_trc(ioc, ioc_fwstate);
89
Jing Huang5fbe25c2010-10-18 17:17:23 -070090 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -080091 * Use count cannot be non-zero and chip in uninitialized state.
92 */
Jing Huangd4b671c2010-12-26 21:46:35 -080093 WARN_ON(ioc_fwstate == BFI_IOC_UNINIT);
Krishna Gudipati0a20de42010-03-05 19:34:20 -080094
Jing Huang5fbe25c2010-10-18 17:17:23 -070095 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -080096 * Check if another driver with a different firmware is active
97 */
98 bfa_ioc_fwver_get(ioc, &fwhdr);
99 if (!bfa_ioc_fwver_cmp(ioc, &fwhdr)) {
Maggie Zhangf7f738122010-12-09 19:08:43 -0800100 writel(1, ioc->ioc_regs.ioc_usage_sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800101 bfa_trc(ioc, usecnt);
102 return BFA_FALSE;
103 }
104
Jing Huang5fbe25c2010-10-18 17:17:23 -0700105 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800106 * Same firmware version. Increment the reference count.
107 */
108 usecnt++;
Jing Huang53440262010-10-18 17:12:29 -0700109 writel(usecnt, ioc->ioc_regs.ioc_usage_reg);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800110 writel(1, ioc->ioc_regs.ioc_usage_sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800111 bfa_trc(ioc, usecnt);
112 return BFA_TRUE;
113}
114
115static void
116bfa_ioc_ct_firmware_unlock(struct bfa_ioc_s *ioc)
117{
Krishna Gudipatid1c61f82010-03-05 19:38:44 -0800118 u32 usecnt;
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800119
Jing Huang5fbe25c2010-10-18 17:17:23 -0700120 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800121 * Firmware lock is relevant only for CNA.
Jing Huang293f82d2010-07-08 19:45:20 -0700122 */
Krishna Gudipati11189202011-06-13 15:50:35 -0700123 if (!bfa_ioc_is_cna(ioc))
Jing Huang293f82d2010-07-08 19:45:20 -0700124 return;
125
Jing Huang5fbe25c2010-10-18 17:17:23 -0700126 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800127 * If bios boot (flash based) -- do not decrement usage count
128 */
Krishna Gudipati11189202011-06-13 15:50:35 -0700129 if (bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)) <
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700130 BFA_IOC_FWIMG_MINSZ)
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800131 return;
132
Jing Huang5fbe25c2010-10-18 17:17:23 -0700133 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800134 * decrement usage count
135 */
136 bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg);
Jing Huang53440262010-10-18 17:12:29 -0700137 usecnt = readl(ioc->ioc_regs.ioc_usage_reg);
Jing Huangd4b671c2010-12-26 21:46:35 -0800138 WARN_ON(usecnt <= 0);
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800139
140 usecnt--;
Jing Huang53440262010-10-18 17:12:29 -0700141 writel(usecnt, ioc->ioc_regs.ioc_usage_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800142 bfa_trc(ioc, usecnt);
143
Maggie Zhangf7f738122010-12-09 19:08:43 -0800144 writel(1, ioc->ioc_regs.ioc_usage_sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800145}
146
Jing Huang5fbe25c2010-10-18 17:17:23 -0700147/*
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800148 * Notify other functions on HB failure.
149 */
150static void
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800151bfa_ioc_ct_notify_fail(struct bfa_ioc_s *ioc)
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800152{
Krishna Gudipati11189202011-06-13 15:50:35 -0700153 if (bfa_ioc_is_cna(ioc)) {
Jing Huang53440262010-10-18 17:12:29 -0700154 writel(__FW_INIT_HALT_P, ioc->ioc_regs.ll_halt);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800155 writel(__FW_INIT_HALT_P, ioc->ioc_regs.alt_ll_halt);
Krishna Gudipati816e49b2010-03-05 19:36:56 -0800156 /* Wait for halt to take effect */
Jing Huang53440262010-10-18 17:12:29 -0700157 readl(ioc->ioc_regs.ll_halt);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800158 readl(ioc->ioc_regs.alt_ll_halt);
Krishna Gudipati816e49b2010-03-05 19:36:56 -0800159 } else {
Krishna Gudipati11189202011-06-13 15:50:35 -0700160 writel(~0U, ioc->ioc_regs.err_set);
Jing Huang53440262010-10-18 17:12:29 -0700161 readl(ioc->ioc_regs.err_set);
Krishna Gudipati816e49b2010-03-05 19:36:56 -0800162 }
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800163}
164
Jing Huang5fbe25c2010-10-18 17:17:23 -0700165/*
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800166 * Host to LPU mailbox message addresses
167 */
Krishna Gudipati11189202011-06-13 15:50:35 -0700168static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } ct_fnreg[] = {
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800169 { HOSTFN0_LPU_MBOX0_0, LPU_HOSTFN0_MBOX0_0, HOST_PAGE_NUM_FN0 },
170 { HOSTFN1_LPU_MBOX0_8, LPU_HOSTFN1_MBOX0_8, HOST_PAGE_NUM_FN1 },
171 { HOSTFN2_LPU_MBOX0_0, LPU_HOSTFN2_MBOX0_0, HOST_PAGE_NUM_FN2 },
172 { HOSTFN3_LPU_MBOX0_8, LPU_HOSTFN3_MBOX0_8, HOST_PAGE_NUM_FN3 }
173};
174
Jing Huang5fbe25c2010-10-18 17:17:23 -0700175/*
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800176 * Host <-> LPU mailbox command/status registers - port 0
177 */
Krishna Gudipati11189202011-06-13 15:50:35 -0700178static struct { u32 hfn, lpu; } ct_p0reg[] = {
179 { HOSTFN0_LPU0_CMD_STAT, LPU0_HOSTFN0_CMD_STAT },
180 { HOSTFN1_LPU0_CMD_STAT, LPU0_HOSTFN1_CMD_STAT },
181 { HOSTFN2_LPU0_CMD_STAT, LPU0_HOSTFN2_CMD_STAT },
182 { HOSTFN3_LPU0_CMD_STAT, LPU0_HOSTFN3_CMD_STAT }
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800183};
184
Jing Huang5fbe25c2010-10-18 17:17:23 -0700185/*
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800186 * Host <-> LPU mailbox command/status registers - port 1
187 */
Krishna Gudipati11189202011-06-13 15:50:35 -0700188static struct { u32 hfn, lpu; } ct_p1reg[] = {
189 { HOSTFN0_LPU1_CMD_STAT, LPU1_HOSTFN0_CMD_STAT },
190 { HOSTFN1_LPU1_CMD_STAT, LPU1_HOSTFN1_CMD_STAT },
191 { HOSTFN2_LPU1_CMD_STAT, LPU1_HOSTFN2_CMD_STAT },
192 { HOSTFN3_LPU1_CMD_STAT, LPU1_HOSTFN3_CMD_STAT }
193};
194
Krishna Gudipati8b070b42011-06-13 15:52:40 -0700195static struct { uint32_t hfn_mbox, lpu_mbox, hfn_pgn, hfn, lpu, lpu_read; }
196 ct2_reg[] = {
Krishna Gudipati11189202011-06-13 15:50:35 -0700197 { CT2_HOSTFN_LPU0_MBOX0, CT2_LPU0_HOSTFN_MBOX0, CT2_HOSTFN_PAGE_NUM,
Krishna Gudipati8b070b42011-06-13 15:52:40 -0700198 CT2_HOSTFN_LPU0_CMD_STAT, CT2_LPU0_HOSTFN_CMD_STAT,
199 CT2_HOSTFN_LPU0_READ_STAT},
Krishna Gudipati11189202011-06-13 15:50:35 -0700200 { CT2_HOSTFN_LPU1_MBOX0, CT2_LPU1_HOSTFN_MBOX0, CT2_HOSTFN_PAGE_NUM,
Krishna Gudipati8b070b42011-06-13 15:52:40 -0700201 CT2_HOSTFN_LPU1_CMD_STAT, CT2_LPU1_HOSTFN_CMD_STAT,
202 CT2_HOSTFN_LPU1_READ_STAT},
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800203};
204
205static void
206bfa_ioc_ct_reg_init(struct bfa_ioc_s *ioc)
207{
Jing Huang53440262010-10-18 17:12:29 -0700208 void __iomem *rb;
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800209 int pcifn = bfa_ioc_pcifn(ioc);
210
211 rb = bfa_ioc_bar0(ioc);
212
Krishna Gudipati11189202011-06-13 15:50:35 -0700213 ioc->ioc_regs.hfn_mbox = rb + ct_fnreg[pcifn].hfn_mbox;
214 ioc->ioc_regs.lpu_mbox = rb + ct_fnreg[pcifn].lpu_mbox;
215 ioc->ioc_regs.host_page_num_fn = rb + ct_fnreg[pcifn].hfn_pgn;
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800216
217 if (ioc->port_id == 0) {
218 ioc->ioc_regs.heartbeat = rb + BFA_IOC0_HBEAT_REG;
219 ioc->ioc_regs.ioc_fwstate = rb + BFA_IOC0_STATE_REG;
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800220 ioc->ioc_regs.alt_ioc_fwstate = rb + BFA_IOC1_STATE_REG;
Krishna Gudipati11189202011-06-13 15:50:35 -0700221 ioc->ioc_regs.hfn_mbox_cmd = rb + ct_p0reg[pcifn].hfn;
222 ioc->ioc_regs.lpu_mbox_cmd = rb + ct_p0reg[pcifn].lpu;
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800223 ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P0;
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800224 ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P1;
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800225 } else {
226 ioc->ioc_regs.heartbeat = (rb + BFA_IOC1_HBEAT_REG);
227 ioc->ioc_regs.ioc_fwstate = (rb + BFA_IOC1_STATE_REG);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800228 ioc->ioc_regs.alt_ioc_fwstate = rb + BFA_IOC0_STATE_REG;
Krishna Gudipati11189202011-06-13 15:50:35 -0700229 ioc->ioc_regs.hfn_mbox_cmd = rb + ct_p1reg[pcifn].hfn;
230 ioc->ioc_regs.lpu_mbox_cmd = rb + ct_p1reg[pcifn].lpu;
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800231 ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P1;
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800232 ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P0;
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800233 }
234
235 /*
236 * PSS control registers
237 */
238 ioc->ioc_regs.pss_ctl_reg = (rb + PSS_CTL_REG);
Krishna Gudipati8b651b42010-03-05 19:34:44 -0800239 ioc->ioc_regs.pss_err_status_reg = (rb + PSS_ERR_STATUS_REG);
Krishna Gudipati11189202011-06-13 15:50:35 -0700240 ioc->ioc_regs.app_pll_fast_ctl_reg = (rb + APP_PLL_LCLK_CTL_REG);
241 ioc->ioc_regs.app_pll_slow_ctl_reg = (rb + APP_PLL_SCLK_CTL_REG);
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800242
243 /*
244 * IOC semaphore registers and serialization
245 */
246 ioc->ioc_regs.ioc_sem_reg = (rb + HOST_SEM0_REG);
247 ioc->ioc_regs.ioc_usage_sem_reg = (rb + HOST_SEM1_REG);
248 ioc->ioc_regs.ioc_init_sem_reg = (rb + HOST_SEM2_REG);
249 ioc->ioc_regs.ioc_usage_reg = (rb + BFA_FW_USE_COUNT);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800250 ioc->ioc_regs.ioc_fail_sync = (rb + BFA_IOC_FAIL_SYNC);
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800251
Jing Huang5fbe25c2010-10-18 17:17:23 -0700252 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800253 * sram memory access
254 */
255 ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START);
256 ioc->ioc_regs.smem_pg0 = BFI_IOC_SMEM_PG0_CT;
Krishna Gudipati816e49b2010-03-05 19:36:56 -0800257
258 /*
259 * err set reg : for notification of hb failure in fcmode
260 */
261 ioc->ioc_regs.err_set = (rb + ERR_SET_REG);
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800262}
263
Krishna Gudipati11189202011-06-13 15:50:35 -0700264static void
265bfa_ioc_ct2_reg_init(struct bfa_ioc_s *ioc)
266{
267 void __iomem *rb;
268 int port = bfa_ioc_portid(ioc);
269
270 rb = bfa_ioc_bar0(ioc);
271
272 ioc->ioc_regs.hfn_mbox = rb + ct2_reg[port].hfn_mbox;
273 ioc->ioc_regs.lpu_mbox = rb + ct2_reg[port].lpu_mbox;
274 ioc->ioc_regs.host_page_num_fn = rb + ct2_reg[port].hfn_pgn;
275 ioc->ioc_regs.hfn_mbox_cmd = rb + ct2_reg[port].hfn;
276 ioc->ioc_regs.lpu_mbox_cmd = rb + ct2_reg[port].lpu;
Krishna Gudipati8b070b42011-06-13 15:52:40 -0700277 ioc->ioc_regs.lpu_read_stat = rb + ct2_reg[port].lpu_read;
Krishna Gudipati11189202011-06-13 15:50:35 -0700278
279 if (port == 0) {
280 ioc->ioc_regs.heartbeat = rb + CT2_BFA_IOC0_HBEAT_REG;
281 ioc->ioc_regs.ioc_fwstate = rb + CT2_BFA_IOC0_STATE_REG;
282 ioc->ioc_regs.alt_ioc_fwstate = rb + CT2_BFA_IOC1_STATE_REG;
283 ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P0;
284 ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P1;
285 } else {
286 ioc->ioc_regs.heartbeat = (rb + CT2_BFA_IOC1_HBEAT_REG);
287 ioc->ioc_regs.ioc_fwstate = (rb + CT2_BFA_IOC1_STATE_REG);
288 ioc->ioc_regs.alt_ioc_fwstate = rb + CT2_BFA_IOC0_STATE_REG;
289 ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P1;
290 ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P0;
291 }
292
293 /*
294 * PSS control registers
295 */
296 ioc->ioc_regs.pss_ctl_reg = (rb + PSS_CTL_REG);
297 ioc->ioc_regs.pss_err_status_reg = (rb + PSS_ERR_STATUS_REG);
298 ioc->ioc_regs.app_pll_fast_ctl_reg = (rb + CT2_APP_PLL_LCLK_CTL_REG);
299 ioc->ioc_regs.app_pll_slow_ctl_reg = (rb + CT2_APP_PLL_SCLK_CTL_REG);
300
301 /*
302 * IOC semaphore registers and serialization
303 */
304 ioc->ioc_regs.ioc_sem_reg = (rb + CT2_HOST_SEM0_REG);
305 ioc->ioc_regs.ioc_usage_sem_reg = (rb + CT2_HOST_SEM1_REG);
306 ioc->ioc_regs.ioc_init_sem_reg = (rb + CT2_HOST_SEM2_REG);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700307 ioc->ioc_regs.ioc_usage_reg = (rb + CT2_BFA_FW_USE_COUNT);
308 ioc->ioc_regs.ioc_fail_sync = (rb + CT2_BFA_IOC_FAIL_SYNC);
Krishna Gudipati11189202011-06-13 15:50:35 -0700309
310 /*
311 * sram memory access
312 */
313 ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START);
314 ioc->ioc_regs.smem_pg0 = BFI_IOC_SMEM_PG0_CT;
315
316 /*
317 * err set reg : for notification of hb failure in fcmode
318 */
319 ioc->ioc_regs.err_set = (rb + ERR_SET_REG);
320}
321
Jing Huang5fbe25c2010-10-18 17:17:23 -0700322/*
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800323 * Initialize IOC to port mapping.
324 */
325
326#define FNC_PERS_FN_SHIFT(__fn) ((__fn) * 8)
327static void
328bfa_ioc_ct_map_port(struct bfa_ioc_s *ioc)
329{
Jing Huang53440262010-10-18 17:12:29 -0700330 void __iomem *rb = ioc->pcidev.pci_bar_kva;
Krishna Gudipatid1c61f82010-03-05 19:38:44 -0800331 u32 r32;
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800332
Jing Huang5fbe25c2010-10-18 17:17:23 -0700333 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800334 * For catapult, base port id on personality register and IOC type
335 */
Jing Huang53440262010-10-18 17:12:29 -0700336 r32 = readl(rb + FNC_PERS_REG);
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800337 r32 >>= FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc));
338 ioc->port_id = (r32 & __F0_PORT_MAP_MK) >> __F0_PORT_MAP_SH;
339
340 bfa_trc(ioc, bfa_ioc_pcifn(ioc));
341 bfa_trc(ioc, ioc->port_id);
342}
343
Krishna Gudipati11189202011-06-13 15:50:35 -0700344static void
345bfa_ioc_ct2_map_port(struct bfa_ioc_s *ioc)
346{
347 ioc->port_id = bfa_ioc_pcifn(ioc) % 2;
348
349 bfa_trc(ioc, bfa_ioc_pcifn(ioc));
350 bfa_trc(ioc, ioc->port_id);
351}
352
Jing Huang5fbe25c2010-10-18 17:17:23 -0700353/*
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800354 * Set interrupt mode for a function: INTX or MSIX
355 */
356static void
357bfa_ioc_ct_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix)
358{
Jing Huang53440262010-10-18 17:12:29 -0700359 void __iomem *rb = ioc->pcidev.pci_bar_kva;
Krishna Gudipatid1c61f82010-03-05 19:38:44 -0800360 u32 r32, mode;
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800361
Jing Huang53440262010-10-18 17:12:29 -0700362 r32 = readl(rb + FNC_PERS_REG);
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800363 bfa_trc(ioc, r32);
364
365 mode = (r32 >> FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc))) &
366 __F0_INTX_STATUS;
367
Jing Huang5fbe25c2010-10-18 17:17:23 -0700368 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800369 * If already in desired mode, do not change anything
370 */
Krishna Gudipati11189202011-06-13 15:50:35 -0700371 if ((!msix && mode) || (msix && !mode))
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800372 return;
373
374 if (msix)
375 mode = __F0_INTX_STATUS_MSIX;
376 else
377 mode = __F0_INTX_STATUS_INTA;
378
379 r32 &= ~(__F0_INTX_STATUS << FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc)));
380 r32 |= (mode << FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc)));
381 bfa_trc(ioc, r32);
382
Jing Huang53440262010-10-18 17:12:29 -0700383 writel(r32, rb + FNC_PERS_REG);
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800384}
385
Krishna Gudipati8b070b42011-06-13 15:52:40 -0700386bfa_boolean_t
387bfa_ioc_ct2_lpu_read_stat(struct bfa_ioc_s *ioc)
388{
389 u32 r32;
390
391 r32 = readl(ioc->ioc_regs.lpu_read_stat);
392 if (r32) {
393 writel(1, ioc->ioc_regs.lpu_read_stat);
394 return BFA_TRUE;
395 }
396
397 return BFA_FALSE;
398}
399
Jing Huang5fbe25c2010-10-18 17:17:23 -0700400/*
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800401 * Cleanup hw semaphore and usecnt registers
402 */
403static void
404bfa_ioc_ct_ownership_reset(struct bfa_ioc_s *ioc)
405{
406
Krishna Gudipati11189202011-06-13 15:50:35 -0700407 if (bfa_ioc_is_cna(ioc)) {
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800408 bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg);
Jing Huang53440262010-10-18 17:12:29 -0700409 writel(0, ioc->ioc_regs.ioc_usage_reg);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800410 writel(1, ioc->ioc_regs.ioc_usage_sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800411 }
412
413 /*
414 * Read the hw sem reg to make sure that it is locked
415 * before we clear it. If it is not locked, writing 1
416 * will lock it instead of clearing it.
417 */
Jing Huang53440262010-10-18 17:12:29 -0700418 readl(ioc->ioc_regs.ioc_sem_reg);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800419 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800420}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700421
Jing Huang45d7f0c2011-04-13 11:45:53 -0700422static bfa_boolean_t
423bfa_ioc_ct_sync_start(struct bfa_ioc_s *ioc)
424{
425 uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync);
426 uint32_t sync_reqd = bfa_ioc_ct_get_sync_reqd(r32);
427
428 /*
429 * Driver load time. If the sync required bit for this PCI fn
430 * is set, it is due to an unclean exit by the driver for this
431 * PCI fn in the previous incarnation. Whoever comes here first
432 * should clean it up, no matter which PCI fn.
433 */
434
435 if (sync_reqd & bfa_ioc_ct_sync_pos(ioc)) {
436 writel(0, ioc->ioc_regs.ioc_fail_sync);
437 writel(1, ioc->ioc_regs.ioc_usage_reg);
438 writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
439 writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate);
440 return BFA_TRUE;
441 }
442
443 return bfa_ioc_ct_sync_complete(ioc);
444}
445
Jing Huang8f4bfad2010-12-26 21:50:10 -0800446/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800447 * Synchronized IOC failure processing routines
448 */
449static void
450bfa_ioc_ct_sync_join(struct bfa_ioc_s *ioc)
451{
452 uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync);
453 uint32_t sync_pos = bfa_ioc_ct_sync_reqd_pos(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700454
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800455 writel((r32 | sync_pos), ioc->ioc_regs.ioc_fail_sync);
456}
457
458static void
459bfa_ioc_ct_sync_leave(struct bfa_ioc_s *ioc)
460{
461 uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync);
462 uint32_t sync_msk = bfa_ioc_ct_sync_reqd_pos(ioc) |
463 bfa_ioc_ct_sync_pos(ioc);
464
465 writel((r32 & ~sync_msk), ioc->ioc_regs.ioc_fail_sync);
466}
467
468static void
469bfa_ioc_ct_sync_ack(struct bfa_ioc_s *ioc)
470{
471 uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync);
472
473 writel((r32 | bfa_ioc_ct_sync_pos(ioc)),
474 ioc->ioc_regs.ioc_fail_sync);
475}
476
477static bfa_boolean_t
478bfa_ioc_ct_sync_complete(struct bfa_ioc_s *ioc)
479{
480 uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync);
481 uint32_t sync_reqd = bfa_ioc_ct_get_sync_reqd(r32);
482 uint32_t sync_ackd = bfa_ioc_ct_get_sync_ackd(r32);
483 uint32_t tmp_ackd;
484
485 if (sync_ackd == 0)
486 return BFA_TRUE;
487
Jing Huang8f4bfad2010-12-26 21:50:10 -0800488 /*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800489 * The check below is to see whether any other PCI fn
490 * has reinitialized the ASIC (reset sync_ackd bits)
491 * and failed again while this IOC was waiting for hw
492 * semaphore (in bfa_iocpf_sm_semwait()).
493 */
494 tmp_ackd = sync_ackd;
495 if ((sync_reqd & bfa_ioc_ct_sync_pos(ioc)) &&
496 !(sync_ackd & bfa_ioc_ct_sync_pos(ioc)))
497 sync_ackd |= bfa_ioc_ct_sync_pos(ioc);
498
499 if (sync_reqd == sync_ackd) {
500 writel(bfa_ioc_ct_clear_sync_ackd(r32),
501 ioc->ioc_regs.ioc_fail_sync);
502 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
503 writel(BFI_IOC_FAIL, ioc->ioc_regs.alt_ioc_fwstate);
504 return BFA_TRUE;
505 }
506
Jing Huang8f4bfad2010-12-26 21:50:10 -0800507 /*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800508 * If another PCI fn reinitialized and failed again while
509 * this IOC was waiting for hw sem, the sync_ackd bit for
510 * this IOC need to be set again to allow reinitialization.
511 */
512 if (tmp_ackd != sync_ackd)
513 writel((r32 | sync_ackd), ioc->ioc_regs.ioc_fail_sync);
514
515 return BFA_FALSE;
516}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700517
Krishna Gudipati11189202011-06-13 15:50:35 -0700518/**
519 * Called from bfa_ioc_attach() to map asic specific calls.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700520 */
Krishna Gudipati11189202011-06-13 15:50:35 -0700521static void
522bfa_ioc_set_ctx_hwif(struct bfa_ioc_s *ioc, struct bfa_ioc_hwif_s *hwif)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700523{
Krishna Gudipati11189202011-06-13 15:50:35 -0700524 hwif->ioc_firmware_lock = bfa_ioc_ct_firmware_lock;
525 hwif->ioc_firmware_unlock = bfa_ioc_ct_firmware_unlock;
526 hwif->ioc_notify_fail = bfa_ioc_ct_notify_fail;
527 hwif->ioc_ownership_reset = bfa_ioc_ct_ownership_reset;
528 hwif->ioc_sync_start = bfa_ioc_ct_sync_start;
529 hwif->ioc_sync_join = bfa_ioc_ct_sync_join;
530 hwif->ioc_sync_leave = bfa_ioc_ct_sync_leave;
531 hwif->ioc_sync_ack = bfa_ioc_ct_sync_ack;
532 hwif->ioc_sync_complete = bfa_ioc_ct_sync_complete;
533}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700534
Krishna Gudipati11189202011-06-13 15:50:35 -0700535/**
536 * Called from bfa_ioc_attach() to map asic specific calls.
537 */
538void
539bfa_ioc_set_ct_hwif(struct bfa_ioc_s *ioc)
540{
541 bfa_ioc_set_ctx_hwif(ioc, &hwif_ct);
542
543 hwif_ct.ioc_pll_init = bfa_ioc_ct_pll_init;
544 hwif_ct.ioc_reg_init = bfa_ioc_ct_reg_init;
545 hwif_ct.ioc_map_port = bfa_ioc_ct_map_port;
546 hwif_ct.ioc_isr_mode_set = bfa_ioc_ct_isr_mode_set;
547 ioc->ioc_hwif = &hwif_ct;
548}
549
550/**
551 * Called from bfa_ioc_attach() to map asic specific calls.
552 */
553void
554bfa_ioc_set_ct2_hwif(struct bfa_ioc_s *ioc)
555{
556 bfa_ioc_set_ctx_hwif(ioc, &hwif_ct2);
557
558 hwif_ct2.ioc_pll_init = bfa_ioc_ct2_pll_init;
559 hwif_ct2.ioc_reg_init = bfa_ioc_ct2_reg_init;
560 hwif_ct2.ioc_map_port = bfa_ioc_ct2_map_port;
Krishna Gudipati8b070b42011-06-13 15:52:40 -0700561 hwif_ct2.ioc_lpu_read_stat = bfa_ioc_ct2_lpu_read_stat;
Krishna Gudipati11189202011-06-13 15:50:35 -0700562 hwif_ct2.ioc_isr_mode_set = NULL;
563 ioc->ioc_hwif = &hwif_ct2;
564}
565
566/*
567 * Temporary workaround for MSI-X resource allocation for catapult-2.
568 */
569#define HOSTFN_MSIX_DEFAULT 16
570#define HOSTFN_MSIX_VT_OFST_NUMVT 0x3013c
571#define __MSIX_VT_NUMVT__MK 0x003ff800
572#define __MSIX_VT_NUMVT__SH 11
573#define __MSIX_VT_NUMVT_(_v) ((_v) << __MSIX_VT_NUMVT__SH)
574void
575bfa_ioc_ct2_poweron(struct bfa_ioc_s *ioc)
576{
577 void __iomem *rb = ioc->pcidev.pci_bar_kva;
578 u32 r32;
579
580 r32 = readl(rb + HOSTFN_MSIX_VT_OFST_NUMVT);
581 if (r32 & __MSIX_VT_NUMVT__MK)
582 return;
583
584 writel(__MSIX_VT_NUMVT_(HOSTFN_MSIX_DEFAULT - 1) |
585 HOSTFN_MSIX_DEFAULT * bfa_ioc_pcifn(ioc),
586 rb + HOSTFN_MSIX_VT_OFST_NUMVT);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700587}
588
589bfa_status_t
Krishna Gudipati11189202011-06-13 15:50:35 -0700590bfa_ioc_ct_pll_init(void __iomem *rb, enum bfi_asic_mode mode)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700591{
592 u32 pll_sclk, pll_fclk, r32;
Krishna Gudipati11189202011-06-13 15:50:35 -0700593 bfa_boolean_t fcmode = (mode == BFI_ASIC_MODE_FC);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700594
Krishna Gudipati11189202011-06-13 15:50:35 -0700595 pll_sclk = __APP_PLL_SCLK_LRESETN | __APP_PLL_SCLK_ENARST |
596 __APP_PLL_SCLK_RSEL200500 | __APP_PLL_SCLK_P0_1(3U) |
597 __APP_PLL_SCLK_JITLMT0_1(3U) |
598 __APP_PLL_SCLK_CNTLMT0_1(1U);
599 pll_fclk = __APP_PLL_LCLK_LRESETN | __APP_PLL_LCLK_ENARST |
600 __APP_PLL_LCLK_RSEL200500 | __APP_PLL_LCLK_P0_1(3U) |
601 __APP_PLL_LCLK_JITLMT0_1(3U) |
602 __APP_PLL_LCLK_CNTLMT0_1(1U);
603
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700604 if (fcmode) {
Jing Huang53440262010-10-18 17:12:29 -0700605 writel(0, (rb + OP_MODE));
606 writel(__APP_EMS_CMLCKSEL | __APP_EMS_REFCKBUFEN2 |
607 __APP_EMS_CHANNEL_SEL, (rb + ETH_MAC_SER_REG));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700608 } else {
Jing Huang53440262010-10-18 17:12:29 -0700609 writel(__GLOBAL_FCOE_MODE, (rb + OP_MODE));
610 writel(__APP_EMS_REFCKBUFEN1, (rb + ETH_MAC_SER_REG));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700611 }
Jing Huang53440262010-10-18 17:12:29 -0700612 writel(BFI_IOC_UNINIT, (rb + BFA_IOC0_STATE_REG));
613 writel(BFI_IOC_UNINIT, (rb + BFA_IOC1_STATE_REG));
614 writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
615 writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
616 writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
617 writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
618 writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
619 writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
Krishna Gudipati11189202011-06-13 15:50:35 -0700620 writel(pll_sclk | __APP_PLL_SCLK_LOGIC_SOFT_RESET,
621 rb + APP_PLL_SCLK_CTL_REG);
622 writel(pll_fclk | __APP_PLL_LCLK_LOGIC_SOFT_RESET,
623 rb + APP_PLL_LCLK_CTL_REG);
624 writel(pll_sclk | __APP_PLL_SCLK_LOGIC_SOFT_RESET |
625 __APP_PLL_SCLK_ENABLE, rb + APP_PLL_SCLK_CTL_REG);
626 writel(pll_fclk | __APP_PLL_LCLK_LOGIC_SOFT_RESET |
627 __APP_PLL_LCLK_ENABLE, rb + APP_PLL_LCLK_CTL_REG);
Jing Huang53440262010-10-18 17:12:29 -0700628 readl(rb + HOSTFN0_INT_MSK);
Jing Huang6a18b162010-10-18 17:08:54 -0700629 udelay(2000);
Jing Huang53440262010-10-18 17:12:29 -0700630 writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
631 writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
Krishna Gudipati11189202011-06-13 15:50:35 -0700632 writel(pll_sclk | __APP_PLL_SCLK_ENABLE, rb + APP_PLL_SCLK_CTL_REG);
633 writel(pll_fclk | __APP_PLL_LCLK_ENABLE, rb + APP_PLL_LCLK_CTL_REG);
634
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700635 if (!fcmode) {
Jing Huang53440262010-10-18 17:12:29 -0700636 writel(__PMM_1T_RESET_P, (rb + PMM_1T_RESET_REG_P0));
637 writel(__PMM_1T_RESET_P, (rb + PMM_1T_RESET_REG_P1));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700638 }
Jing Huang53440262010-10-18 17:12:29 -0700639 r32 = readl((rb + PSS_CTL_REG));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700640 r32 &= ~__PSS_LMEM_RESET;
Jing Huang53440262010-10-18 17:12:29 -0700641 writel(r32, (rb + PSS_CTL_REG));
Jing Huang6a18b162010-10-18 17:08:54 -0700642 udelay(1000);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700643 if (!fcmode) {
Jing Huang53440262010-10-18 17:12:29 -0700644 writel(0, (rb + PMM_1T_RESET_REG_P0));
645 writel(0, (rb + PMM_1T_RESET_REG_P1));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700646 }
647
Jing Huang53440262010-10-18 17:12:29 -0700648 writel(__EDRAM_BISTR_START, (rb + MBIST_CTL_REG));
Jing Huang6a18b162010-10-18 17:08:54 -0700649 udelay(1000);
Jing Huang53440262010-10-18 17:12:29 -0700650 r32 = readl((rb + MBIST_STAT_REG));
651 writel(0, (rb + MBIST_CTL_REG));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700652 return BFA_STATUS_OK;
653}
Krishna Gudipati11189202011-06-13 15:50:35 -0700654
655static struct { u32 sclk, speed, half_speed; } ct2_pll[] = {
656 {0}, /* unused */
657 {__APP_PLL_SCLK_CLK_DIV2, 0, 0}, /* FC 8G */
Krishna Gudipati775c7742011-06-13 15:52:12 -0700658 {0, 0, 0}, /* FC 16G */
Krishna Gudipati11189202011-06-13 15:50:35 -0700659 {__APP_PLL_SCLK_REFCLK_SEL | __APP_PLL_SCLK_CLK_DIV2, 0, /* ETH */
660 __APP_LPUCLK_HALFSPEED},
Krishna Gudipati775c7742011-06-13 15:52:12 -0700661 {0, 0, 0}, /* COMBO */
Krishna Gudipati11189202011-06-13 15:50:35 -0700662};
663
664static void
665bfa_ioc_ct2_sclk_init(void __iomem *rb, enum bfi_asic_mode mode)
666{
667 u32 r32;
668
669 /*
670 * put s_clk PLL and PLL FSM in reset
671 */
672 r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG));
673 r32 &= ~(__APP_PLL_SCLK_ENABLE | __APP_PLL_SCLK_LRESETN);
674 r32 |= (__APP_PLL_SCLK_ENARST | __APP_PLL_SCLK_BYPASS |
675 __APP_PLL_SCLK_LOGIC_SOFT_RESET);
676 writel(r32, (rb + CT2_APP_PLL_SCLK_CTL_REG));
677
678 /*
679 * select clock speed based on mode
680 */
681 r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG));
682 r32 &= ~(__APP_PLL_SCLK_REFCLK_SEL | __APP_PLL_SCLK_CLK_DIV2);
683 writel(r32 | ct2_pll[mode].sclk, (rb + CT2_APP_PLL_SCLK_CTL_REG));
684
685 /*
Krishna Gudipati775c7742011-06-13 15:52:12 -0700686 * while doing PLL init dont clock gate ethernet subsystem
Krishna Gudipati11189202011-06-13 15:50:35 -0700687 */
Krishna Gudipati775c7742011-06-13 15:52:12 -0700688 r32 = readl((rb + CT2_CHIP_MISC_PRG));
689 writel(r32 | __ETH_CLK_ENABLE_PORT0, (rb + CT2_CHIP_MISC_PRG));
Krishna Gudipati11189202011-06-13 15:50:35 -0700690
Krishna Gudipati775c7742011-06-13 15:52:12 -0700691 r32 = readl((rb + CT2_PCIE_MISC_REG));
692 writel(r32 | __ETH_CLK_ENABLE_PORT1, (rb + CT2_PCIE_MISC_REG));
Krishna Gudipati11189202011-06-13 15:50:35 -0700693
694 /*
695 * set sclk value
696 */
697 r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG));
698 r32 &= (__P_SCLK_PLL_LOCK | __APP_PLL_SCLK_REFCLK_SEL |
699 __APP_PLL_SCLK_CLK_DIV2);
700 writel(r32 | 0x1061731b, (rb + CT2_APP_PLL_SCLK_CTL_REG));
701
702 /*
703 * poll for s_clk lock or delay 1ms
704 */
705 udelay(1000);
706
707 /*
708 * release soft reset on s_clk & l_clk
709 */
710 r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG));
711 writel(r32 & ~__APP_PLL_SCLK_LOGIC_SOFT_RESET,
712 (rb + CT2_APP_PLL_SCLK_CTL_REG));
Krishna Gudipati775c7742011-06-13 15:52:12 -0700713
714 /*
715 * clock gating for ethernet subsystem if not in ethernet mode
716 */
717 if (mode != BFI_ASIC_MODE_ETH) {
718 r32 = readl((rb + CT2_CHIP_MISC_PRG));
719 writel(r32 & ~__ETH_CLK_ENABLE_PORT0,
720 (rb + CT2_CHIP_MISC_PRG));
721
722 r32 = readl((rb + CT2_PCIE_MISC_REG));
723 writel(r32 & ~__ETH_CLK_ENABLE_PORT1,
724 (rb + CT2_PCIE_MISC_REG));
725 }
Krishna Gudipati11189202011-06-13 15:50:35 -0700726}
727
728static void
729bfa_ioc_ct2_lclk_init(void __iomem *rb, enum bfi_asic_mode mode)
730{
731 u32 r32;
732
733 /*
734 * put l_clk PLL and PLL FSM in reset
735 */
736 r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG));
737 r32 &= ~(__APP_PLL_LCLK_ENABLE | __APP_PLL_LCLK_LRESETN);
738 r32 |= (__APP_PLL_LCLK_ENARST | __APP_PLL_LCLK_BYPASS |
739 __APP_PLL_LCLK_LOGIC_SOFT_RESET);
740 writel(r32, (rb + CT2_APP_PLL_LCLK_CTL_REG));
741
742 /*
743 * set LPU speed
744 */
745 r32 = readl((rb + CT2_CHIP_MISC_PRG));
746 writel(r32 | ct2_pll[mode].speed,
747 (rb + CT2_CHIP_MISC_PRG));
748
749 /*
750 * set LPU half speed
751 */
752 r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG));
753 writel(r32 | ct2_pll[mode].half_speed,
754 (rb + CT2_APP_PLL_LCLK_CTL_REG));
755
756 /*
757 * set lclk for mode
758 */
759 r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG));
760 r32 &= (__P_LCLK_PLL_LOCK | __APP_LPUCLK_HALFSPEED);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700761 if (mode == BFI_ASIC_MODE_FC || mode == BFI_ASIC_MODE_FC16 ||
762 mode == BFI_ASIC_MODE_ETH)
Krishna Gudipati11189202011-06-13 15:50:35 -0700763 r32 |= 0x20c1731b;
764 else
765 r32 |= 0x2081731b;
766 writel(r32, (rb + CT2_APP_PLL_LCLK_CTL_REG));
767
768 /*
769 * poll for s_clk lock or delay 1ms
770 */
771 udelay(1000);
772
773 /*
774 * release soft reset on s_clk & l_clk
775 */
776 r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG));
777 writel(r32 & ~__APP_PLL_LCLK_LOGIC_SOFT_RESET,
778 (rb + CT2_APP_PLL_LCLK_CTL_REG));
779}
780
781static void
782bfa_ioc_ct2_mem_init(void __iomem *rb, enum bfi_asic_mode mode)
783{
784 bfa_boolean_t fcmode;
785 u32 r32;
786
787 fcmode = (mode == BFI_ASIC_MODE_FC) || (mode == BFI_ASIC_MODE_FC16);
788 if (!fcmode) {
Krishna Gudipati775c7742011-06-13 15:52:12 -0700789 writel(__PMM_1T_PNDB_P | __PMM_1T_RESET_P,
790 (rb + CT2_PMM_1T_CONTROL_REG_P0));
791 writel(__PMM_1T_PNDB_P | __PMM_1T_RESET_P,
792 (rb + CT2_PMM_1T_CONTROL_REG_P1));
Krishna Gudipati11189202011-06-13 15:50:35 -0700793 }
794
795 r32 = readl((rb + PSS_CTL_REG));
796 r32 &= ~__PSS_LMEM_RESET;
797 writel(r32, (rb + PSS_CTL_REG));
798 udelay(1000);
799
Krishna Gudipati775c7742011-06-13 15:52:12 -0700800 if (!fcmode) {
801 writel(__PMM_1T_PNDB_P, (rb + CT2_PMM_1T_CONTROL_REG_P0));
802 writel(__PMM_1T_PNDB_P, (rb + CT2_PMM_1T_CONTROL_REG_P1));
803 }
804
Krishna Gudipati11189202011-06-13 15:50:35 -0700805 writel(__EDRAM_BISTR_START, (rb + CT2_MBIST_CTL_REG));
806 udelay(1000);
807 writel(0, (rb + CT2_MBIST_CTL_REG));
808}
809
810bfa_status_t
811bfa_ioc_ct2_pll_init(void __iomem *rb, enum bfi_asic_mode mode)
812{
Krishna Gudipati8b070b42011-06-13 15:52:40 -0700813 u32 r32;
814
815 /*
816 * Initialize PLL if not already done by NFC
817 */
818 r32 = readl((rb + CT2_WGN_STATUS));
819
820 writel(__HALT_NFC_CONTROLLER, (rb + CT2_NFC_CSR_SET_REG));
821
Krishna Gudipati11189202011-06-13 15:50:35 -0700822 bfa_ioc_ct2_sclk_init(rb, mode);
823 bfa_ioc_ct2_lclk_init(rb, mode);
824 bfa_ioc_ct2_mem_init(rb, mode);
825
Krishna Gudipati775c7742011-06-13 15:52:12 -0700826 /*
Krishna Gudipati8b070b42011-06-13 15:52:40 -0700827 * Announce flash device presence, if flash was corrupted.
Krishna Gudipati775c7742011-06-13 15:52:12 -0700828 */
Krishna Gudipati8b070b42011-06-13 15:52:40 -0700829 if (r32 == (__WGN_READY | __GLBL_PF_VF_CFG_RDY)) {
830 writel(0, (rb + PSS_GPIO_OUT_REG));
831 writel(1, (rb + PSS_GPIO_OE_REG));
832 }
Krishna Gudipati775c7742011-06-13 15:52:12 -0700833
Krishna Gudipati11189202011-06-13 15:50:35 -0700834 writel(BFI_IOC_UNINIT, (rb + CT2_BFA_IOC0_STATE_REG));
835 writel(BFI_IOC_UNINIT, (rb + CT2_BFA_IOC1_STATE_REG));
836 return BFA_STATUS_OK;
837}