xref: /openbmc/linux/drivers/scsi/bfa/bfa_ioc_ct.c (revision 111892082ed7a3214bc7a7ec6b8b20e8f847501a)
10a20de44SKrishna Gudipati /*
2a36c61f9SKrishna Gudipati  * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
30a20de44SKrishna Gudipati  * All rights reserved
40a20de44SKrishna Gudipati  * www.brocade.com
50a20de44SKrishna Gudipati  *
60a20de44SKrishna Gudipati  * Linux driver for Brocade Fibre Channel Host Bus Adapter.
70a20de44SKrishna Gudipati  *
80a20de44SKrishna Gudipati  * This program is free software; you can redistribute it and/or modify it
90a20de44SKrishna Gudipati  * under the terms of the GNU General Public License (GPL) Version 2 as
100a20de44SKrishna Gudipati  * published by the Free Software Foundation
110a20de44SKrishna Gudipati  *
120a20de44SKrishna Gudipati  * This program is distributed in the hope that it will be useful, but
130a20de44SKrishna Gudipati  * WITHOUT ANY WARRANTY; without even the implied warranty of
140a20de44SKrishna Gudipati  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
150a20de44SKrishna Gudipati  * General Public License for more details.
160a20de44SKrishna Gudipati  */
170a20de44SKrishna Gudipati 
18f16a1750SMaggie Zhang #include "bfad_drv.h"
19a36c61f9SKrishna Gudipati #include "bfa_ioc.h"
20*11189208SKrishna Gudipati #include "bfi_reg.h"
21a36c61f9SKrishna Gudipati #include "bfa_defs.h"
220a20de44SKrishna Gudipati 
230a20de44SKrishna Gudipati BFA_TRC_FILE(CNA, IOC_CT);
240a20de44SKrishna Gudipati 
25f1d584d7SKrishna Gudipati #define bfa_ioc_ct_sync_pos(__ioc)      \
26f1d584d7SKrishna Gudipati 		((uint32_t) (1 << bfa_ioc_pcifn(__ioc)))
27f1d584d7SKrishna Gudipati #define BFA_IOC_SYNC_REQD_SH    16
28f1d584d7SKrishna Gudipati #define bfa_ioc_ct_get_sync_ackd(__val) (__val & 0x0000ffff)
29f1d584d7SKrishna Gudipati #define bfa_ioc_ct_clear_sync_ackd(__val)       (__val & 0xffff0000)
30f1d584d7SKrishna Gudipati #define bfa_ioc_ct_get_sync_reqd(__val) (__val >> BFA_IOC_SYNC_REQD_SH)
31f1d584d7SKrishna Gudipati #define bfa_ioc_ct_sync_reqd_pos(__ioc) \
32f1d584d7SKrishna Gudipati 			(bfa_ioc_ct_sync_pos(__ioc) << BFA_IOC_SYNC_REQD_SH)
33f1d584d7SKrishna Gudipati 
340a20de44SKrishna Gudipati /*
350a20de44SKrishna Gudipati  * forward declarations
360a20de44SKrishna Gudipati  */
370a20de44SKrishna Gudipati static bfa_boolean_t bfa_ioc_ct_firmware_lock(struct bfa_ioc_s *ioc);
380a20de44SKrishna Gudipati static void bfa_ioc_ct_firmware_unlock(struct bfa_ioc_s *ioc);
39f1d584d7SKrishna Gudipati static void bfa_ioc_ct_notify_fail(struct bfa_ioc_s *ioc);
400a20de44SKrishna Gudipati static void bfa_ioc_ct_ownership_reset(struct bfa_ioc_s *ioc);
4145d7f0ccSJing Huang static bfa_boolean_t bfa_ioc_ct_sync_start(struct bfa_ioc_s *ioc);
42f1d584d7SKrishna Gudipati static void bfa_ioc_ct_sync_join(struct bfa_ioc_s *ioc);
43f1d584d7SKrishna Gudipati static void bfa_ioc_ct_sync_leave(struct bfa_ioc_s *ioc);
44f1d584d7SKrishna Gudipati static void bfa_ioc_ct_sync_ack(struct bfa_ioc_s *ioc);
45f1d584d7SKrishna Gudipati static bfa_boolean_t bfa_ioc_ct_sync_complete(struct bfa_ioc_s *ioc);
460a20de44SKrishna Gudipati 
4752f94b6fSMaggie static struct bfa_ioc_hwif_s hwif_ct;
48*11189208SKrishna Gudipati static struct bfa_ioc_hwif_s hwif_ct2;
490a20de44SKrishna Gudipati 
505fbe25c7SJing Huang /*
510a20de44SKrishna Gudipati  * Return true if firmware of current driver matches the running firmware.
520a20de44SKrishna Gudipati  */
530a20de44SKrishna Gudipati static bfa_boolean_t
540a20de44SKrishna Gudipati bfa_ioc_ct_firmware_lock(struct bfa_ioc_s *ioc)
550a20de44SKrishna Gudipati {
560a20de44SKrishna Gudipati 	enum bfi_ioc_state ioc_fwstate;
57d1c61f8eSKrishna Gudipati 	u32 usecnt;
580a20de44SKrishna Gudipati 	struct bfi_ioc_image_hdr_s fwhdr;
590a20de44SKrishna Gudipati 
605fbe25c7SJing Huang 	/*
610a20de44SKrishna Gudipati 	 * Firmware match check is relevant only for CNA.
620a20de44SKrishna Gudipati 	 */
63*11189208SKrishna Gudipati 	if (!bfa_ioc_is_cna(ioc))
640a20de44SKrishna Gudipati 		return BFA_TRUE;
650a20de44SKrishna Gudipati 
665fbe25c7SJing Huang 	/*
670a20de44SKrishna Gudipati 	 * If bios boot (flash based) -- do not increment usage count
680a20de44SKrishna Gudipati 	 */
69*11189208SKrishna Gudipati 	if (bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)) <
70a36c61f9SKrishna Gudipati 						BFA_IOC_FWIMG_MINSZ)
710a20de44SKrishna Gudipati 		return BFA_TRUE;
720a20de44SKrishna Gudipati 
730a20de44SKrishna Gudipati 	bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg);
7453440260SJing Huang 	usecnt = readl(ioc->ioc_regs.ioc_usage_reg);
750a20de44SKrishna Gudipati 
765fbe25c7SJing Huang 	/*
770a20de44SKrishna Gudipati 	 * If usage count is 0, always return TRUE.
780a20de44SKrishna Gudipati 	 */
790a20de44SKrishna Gudipati 	if (usecnt == 0) {
8053440260SJing Huang 		writel(1, ioc->ioc_regs.ioc_usage_reg);
81f7f73812SMaggie Zhang 		writel(1, ioc->ioc_regs.ioc_usage_sem_reg);
82f1d584d7SKrishna Gudipati 		writel(0, ioc->ioc_regs.ioc_fail_sync);
830a20de44SKrishna Gudipati 		bfa_trc(ioc, usecnt);
840a20de44SKrishna Gudipati 		return BFA_TRUE;
850a20de44SKrishna Gudipati 	}
860a20de44SKrishna Gudipati 
8753440260SJing Huang 	ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
880a20de44SKrishna Gudipati 	bfa_trc(ioc, ioc_fwstate);
890a20de44SKrishna Gudipati 
905fbe25c7SJing Huang 	/*
910a20de44SKrishna Gudipati 	 * Use count cannot be non-zero and chip in uninitialized state.
920a20de44SKrishna Gudipati 	 */
93d4b671c5SJing Huang 	WARN_ON(ioc_fwstate == BFI_IOC_UNINIT);
940a20de44SKrishna Gudipati 
955fbe25c7SJing Huang 	/*
960a20de44SKrishna Gudipati 	 * Check if another driver with a different firmware is active
970a20de44SKrishna Gudipati 	 */
980a20de44SKrishna Gudipati 	bfa_ioc_fwver_get(ioc, &fwhdr);
990a20de44SKrishna Gudipati 	if (!bfa_ioc_fwver_cmp(ioc, &fwhdr)) {
100f7f73812SMaggie Zhang 		writel(1, ioc->ioc_regs.ioc_usage_sem_reg);
1010a20de44SKrishna Gudipati 		bfa_trc(ioc, usecnt);
1020a20de44SKrishna Gudipati 		return BFA_FALSE;
1030a20de44SKrishna Gudipati 	}
1040a20de44SKrishna Gudipati 
1055fbe25c7SJing Huang 	/*
1060a20de44SKrishna Gudipati 	 * Same firmware version. Increment the reference count.
1070a20de44SKrishna Gudipati 	 */
1080a20de44SKrishna Gudipati 	usecnt++;
10953440260SJing Huang 	writel(usecnt, ioc->ioc_regs.ioc_usage_reg);
110f7f73812SMaggie Zhang 	writel(1, ioc->ioc_regs.ioc_usage_sem_reg);
1110a20de44SKrishna Gudipati 	bfa_trc(ioc, usecnt);
1120a20de44SKrishna Gudipati 	return BFA_TRUE;
1130a20de44SKrishna Gudipati }
1140a20de44SKrishna Gudipati 
1150a20de44SKrishna Gudipati static void
1160a20de44SKrishna Gudipati bfa_ioc_ct_firmware_unlock(struct bfa_ioc_s *ioc)
1170a20de44SKrishna Gudipati {
118d1c61f8eSKrishna Gudipati 	u32 usecnt;
1190a20de44SKrishna Gudipati 
1205fbe25c7SJing Huang 	/*
1210a20de44SKrishna Gudipati 	 * Firmware lock is relevant only for CNA.
122293f82d5SJing Huang 	 */
123*11189208SKrishna Gudipati 	if (!bfa_ioc_is_cna(ioc))
124293f82d5SJing Huang 		return;
125293f82d5SJing Huang 
1265fbe25c7SJing Huang 	/*
1270a20de44SKrishna Gudipati 	 * If bios boot (flash based) -- do not decrement usage count
1280a20de44SKrishna Gudipati 	 */
129*11189208SKrishna Gudipati 	if (bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)) <
130a36c61f9SKrishna Gudipati 						BFA_IOC_FWIMG_MINSZ)
1310a20de44SKrishna Gudipati 		return;
1320a20de44SKrishna Gudipati 
1335fbe25c7SJing Huang 	/*
1340a20de44SKrishna Gudipati 	 * decrement usage count
1350a20de44SKrishna Gudipati 	 */
1360a20de44SKrishna Gudipati 	bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg);
13753440260SJing Huang 	usecnt = readl(ioc->ioc_regs.ioc_usage_reg);
138d4b671c5SJing Huang 	WARN_ON(usecnt <= 0);
1390a20de44SKrishna Gudipati 
1400a20de44SKrishna Gudipati 	usecnt--;
14153440260SJing Huang 	writel(usecnt, ioc->ioc_regs.ioc_usage_reg);
1420a20de44SKrishna Gudipati 	bfa_trc(ioc, usecnt);
1430a20de44SKrishna Gudipati 
144f7f73812SMaggie Zhang 	writel(1, ioc->ioc_regs.ioc_usage_sem_reg);
1450a20de44SKrishna Gudipati }
1460a20de44SKrishna Gudipati 
1475fbe25c7SJing Huang /*
1480a20de44SKrishna Gudipati  * Notify other functions on HB failure.
1490a20de44SKrishna Gudipati  */
1500a20de44SKrishna Gudipati static void
151f1d584d7SKrishna Gudipati bfa_ioc_ct_notify_fail(struct bfa_ioc_s *ioc)
1520a20de44SKrishna Gudipati {
153*11189208SKrishna Gudipati 	if (bfa_ioc_is_cna(ioc)) {
15453440260SJing Huang 		writel(__FW_INIT_HALT_P, ioc->ioc_regs.ll_halt);
155f1d584d7SKrishna Gudipati 		writel(__FW_INIT_HALT_P, ioc->ioc_regs.alt_ll_halt);
1560a20de44SKrishna Gudipati 		/* Wait for halt to take effect */
15753440260SJing Huang 		readl(ioc->ioc_regs.ll_halt);
158f1d584d7SKrishna Gudipati 		readl(ioc->ioc_regs.alt_ll_halt);
159816e49b8SKrishna Gudipati 	} else {
160*11189208SKrishna Gudipati 		writel(~0U, ioc->ioc_regs.err_set);
16153440260SJing Huang 		readl(ioc->ioc_regs.err_set);
162816e49b8SKrishna Gudipati 	}
1630a20de44SKrishna Gudipati }
1640a20de44SKrishna Gudipati 
1655fbe25c7SJing Huang /*
1660a20de44SKrishna Gudipati  * Host to LPU mailbox message addresses
1670a20de44SKrishna Gudipati  */
168*11189208SKrishna Gudipati static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } ct_fnreg[] = {
1690a20de44SKrishna Gudipati 	{ HOSTFN0_LPU_MBOX0_0, LPU_HOSTFN0_MBOX0_0, HOST_PAGE_NUM_FN0 },
1700a20de44SKrishna Gudipati 	{ HOSTFN1_LPU_MBOX0_8, LPU_HOSTFN1_MBOX0_8, HOST_PAGE_NUM_FN1 },
1710a20de44SKrishna Gudipati 	{ HOSTFN2_LPU_MBOX0_0, LPU_HOSTFN2_MBOX0_0, HOST_PAGE_NUM_FN2 },
1720a20de44SKrishna Gudipati 	{ HOSTFN3_LPU_MBOX0_8, LPU_HOSTFN3_MBOX0_8, HOST_PAGE_NUM_FN3 }
1730a20de44SKrishna Gudipati };
1740a20de44SKrishna Gudipati 
1755fbe25c7SJing Huang /*
1760a20de44SKrishna Gudipati  * Host <-> LPU mailbox command/status registers - port 0
1770a20de44SKrishna Gudipati  */
178*11189208SKrishna Gudipati static struct { u32 hfn, lpu; } ct_p0reg[] = {
179*11189208SKrishna Gudipati 	{ HOSTFN0_LPU0_CMD_STAT, LPU0_HOSTFN0_CMD_STAT },
180*11189208SKrishna Gudipati 	{ HOSTFN1_LPU0_CMD_STAT, LPU0_HOSTFN1_CMD_STAT },
181*11189208SKrishna Gudipati 	{ HOSTFN2_LPU0_CMD_STAT, LPU0_HOSTFN2_CMD_STAT },
182*11189208SKrishna Gudipati 	{ HOSTFN3_LPU0_CMD_STAT, LPU0_HOSTFN3_CMD_STAT }
1830a20de44SKrishna Gudipati };
1840a20de44SKrishna Gudipati 
1855fbe25c7SJing Huang /*
1860a20de44SKrishna Gudipati  * Host <-> LPU mailbox command/status registers - port 1
1870a20de44SKrishna Gudipati  */
188*11189208SKrishna Gudipati static struct { u32 hfn, lpu; } ct_p1reg[] = {
189*11189208SKrishna Gudipati 	{ HOSTFN0_LPU1_CMD_STAT, LPU1_HOSTFN0_CMD_STAT },
190*11189208SKrishna Gudipati 	{ HOSTFN1_LPU1_CMD_STAT, LPU1_HOSTFN1_CMD_STAT },
191*11189208SKrishna Gudipati 	{ HOSTFN2_LPU1_CMD_STAT, LPU1_HOSTFN2_CMD_STAT },
192*11189208SKrishna Gudipati 	{ HOSTFN3_LPU1_CMD_STAT, LPU1_HOSTFN3_CMD_STAT }
193*11189208SKrishna Gudipati };
194*11189208SKrishna Gudipati 
195*11189208SKrishna Gudipati static struct { uint32_t hfn_mbox, lpu_mbox, hfn_pgn, hfn, lpu; } ct2_reg[] = {
196*11189208SKrishna Gudipati 	{ CT2_HOSTFN_LPU0_MBOX0, CT2_LPU0_HOSTFN_MBOX0, CT2_HOSTFN_PAGE_NUM,
197*11189208SKrishna Gudipati 	  CT2_HOSTFN_LPU0_CMD_STAT, CT2_LPU0_HOSTFN_CMD_STAT },
198*11189208SKrishna Gudipati 	{ CT2_HOSTFN_LPU1_MBOX0, CT2_LPU1_HOSTFN_MBOX0, CT2_HOSTFN_PAGE_NUM,
199*11189208SKrishna Gudipati 	  CT2_HOSTFN_LPU1_CMD_STAT, CT2_LPU1_HOSTFN_CMD_STAT },
2000a20de44SKrishna Gudipati };
2010a20de44SKrishna Gudipati 
2020a20de44SKrishna Gudipati static void
2030a20de44SKrishna Gudipati bfa_ioc_ct_reg_init(struct bfa_ioc_s *ioc)
2040a20de44SKrishna Gudipati {
20553440260SJing Huang 	void __iomem *rb;
2060a20de44SKrishna Gudipati 	int		pcifn = bfa_ioc_pcifn(ioc);
2070a20de44SKrishna Gudipati 
2080a20de44SKrishna Gudipati 	rb = bfa_ioc_bar0(ioc);
2090a20de44SKrishna Gudipati 
210*11189208SKrishna Gudipati 	ioc->ioc_regs.hfn_mbox = rb + ct_fnreg[pcifn].hfn_mbox;
211*11189208SKrishna Gudipati 	ioc->ioc_regs.lpu_mbox = rb + ct_fnreg[pcifn].lpu_mbox;
212*11189208SKrishna Gudipati 	ioc->ioc_regs.host_page_num_fn = rb + ct_fnreg[pcifn].hfn_pgn;
2130a20de44SKrishna Gudipati 
2140a20de44SKrishna Gudipati 	if (ioc->port_id == 0) {
2150a20de44SKrishna Gudipati 		ioc->ioc_regs.heartbeat = rb + BFA_IOC0_HBEAT_REG;
2160a20de44SKrishna Gudipati 		ioc->ioc_regs.ioc_fwstate = rb + BFA_IOC0_STATE_REG;
217f1d584d7SKrishna Gudipati 		ioc->ioc_regs.alt_ioc_fwstate = rb + BFA_IOC1_STATE_REG;
218*11189208SKrishna Gudipati 		ioc->ioc_regs.hfn_mbox_cmd = rb + ct_p0reg[pcifn].hfn;
219*11189208SKrishna Gudipati 		ioc->ioc_regs.lpu_mbox_cmd = rb + ct_p0reg[pcifn].lpu;
2200a20de44SKrishna Gudipati 		ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P0;
221f1d584d7SKrishna Gudipati 		ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P1;
2220a20de44SKrishna Gudipati 	} else {
2230a20de44SKrishna Gudipati 		ioc->ioc_regs.heartbeat = (rb + BFA_IOC1_HBEAT_REG);
2240a20de44SKrishna Gudipati 		ioc->ioc_regs.ioc_fwstate = (rb + BFA_IOC1_STATE_REG);
225f1d584d7SKrishna Gudipati 		ioc->ioc_regs.alt_ioc_fwstate = rb + BFA_IOC0_STATE_REG;
226*11189208SKrishna Gudipati 		ioc->ioc_regs.hfn_mbox_cmd = rb + ct_p1reg[pcifn].hfn;
227*11189208SKrishna Gudipati 		ioc->ioc_regs.lpu_mbox_cmd = rb + ct_p1reg[pcifn].lpu;
2280a20de44SKrishna Gudipati 		ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P1;
229f1d584d7SKrishna Gudipati 		ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P0;
2300a20de44SKrishna Gudipati 	}
2310a20de44SKrishna Gudipati 
2320a20de44SKrishna Gudipati 	/*
2330a20de44SKrishna Gudipati 	 * PSS control registers
2340a20de44SKrishna Gudipati 	 */
2350a20de44SKrishna Gudipati 	ioc->ioc_regs.pss_ctl_reg = (rb + PSS_CTL_REG);
2368b651b42SKrishna Gudipati 	ioc->ioc_regs.pss_err_status_reg = (rb + PSS_ERR_STATUS_REG);
237*11189208SKrishna Gudipati 	ioc->ioc_regs.app_pll_fast_ctl_reg = (rb + APP_PLL_LCLK_CTL_REG);
238*11189208SKrishna Gudipati 	ioc->ioc_regs.app_pll_slow_ctl_reg = (rb + APP_PLL_SCLK_CTL_REG);
2390a20de44SKrishna Gudipati 
2400a20de44SKrishna Gudipati 	/*
2410a20de44SKrishna Gudipati 	 * IOC semaphore registers and serialization
2420a20de44SKrishna Gudipati 	 */
2430a20de44SKrishna Gudipati 	ioc->ioc_regs.ioc_sem_reg = (rb + HOST_SEM0_REG);
2440a20de44SKrishna Gudipati 	ioc->ioc_regs.ioc_usage_sem_reg = (rb + HOST_SEM1_REG);
2450a20de44SKrishna Gudipati 	ioc->ioc_regs.ioc_init_sem_reg = (rb + HOST_SEM2_REG);
2460a20de44SKrishna Gudipati 	ioc->ioc_regs.ioc_usage_reg = (rb + BFA_FW_USE_COUNT);
247f1d584d7SKrishna Gudipati 	ioc->ioc_regs.ioc_fail_sync = (rb + BFA_IOC_FAIL_SYNC);
2480a20de44SKrishna Gudipati 
2495fbe25c7SJing Huang 	/*
2500a20de44SKrishna Gudipati 	 * sram memory access
2510a20de44SKrishna Gudipati 	 */
2520a20de44SKrishna Gudipati 	ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START);
2530a20de44SKrishna Gudipati 	ioc->ioc_regs.smem_pg0 = BFI_IOC_SMEM_PG0_CT;
254816e49b8SKrishna Gudipati 
255816e49b8SKrishna Gudipati 	/*
256816e49b8SKrishna Gudipati 	 * err set reg : for notification of hb failure in fcmode
257816e49b8SKrishna Gudipati 	 */
258816e49b8SKrishna Gudipati 	ioc->ioc_regs.err_set = (rb + ERR_SET_REG);
2590a20de44SKrishna Gudipati }
2600a20de44SKrishna Gudipati 
261*11189208SKrishna Gudipati static void
262*11189208SKrishna Gudipati bfa_ioc_ct2_reg_init(struct bfa_ioc_s *ioc)
263*11189208SKrishna Gudipati {
264*11189208SKrishna Gudipati 	void __iomem *rb;
265*11189208SKrishna Gudipati 	int	port = bfa_ioc_portid(ioc);
266*11189208SKrishna Gudipati 
267*11189208SKrishna Gudipati 	rb = bfa_ioc_bar0(ioc);
268*11189208SKrishna Gudipati 
269*11189208SKrishna Gudipati 	ioc->ioc_regs.hfn_mbox = rb + ct2_reg[port].hfn_mbox;
270*11189208SKrishna Gudipati 	ioc->ioc_regs.lpu_mbox = rb + ct2_reg[port].lpu_mbox;
271*11189208SKrishna Gudipati 	ioc->ioc_regs.host_page_num_fn = rb + ct2_reg[port].hfn_pgn;
272*11189208SKrishna Gudipati 	ioc->ioc_regs.hfn_mbox_cmd = rb + ct2_reg[port].hfn;
273*11189208SKrishna Gudipati 	ioc->ioc_regs.lpu_mbox_cmd = rb + ct2_reg[port].lpu;
274*11189208SKrishna Gudipati 
275*11189208SKrishna Gudipati 	if (port == 0) {
276*11189208SKrishna Gudipati 		ioc->ioc_regs.heartbeat = rb + CT2_BFA_IOC0_HBEAT_REG;
277*11189208SKrishna Gudipati 		ioc->ioc_regs.ioc_fwstate = rb + CT2_BFA_IOC0_STATE_REG;
278*11189208SKrishna Gudipati 		ioc->ioc_regs.alt_ioc_fwstate = rb + CT2_BFA_IOC1_STATE_REG;
279*11189208SKrishna Gudipati 		ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P0;
280*11189208SKrishna Gudipati 		ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P1;
281*11189208SKrishna Gudipati 	} else {
282*11189208SKrishna Gudipati 		ioc->ioc_regs.heartbeat = (rb + CT2_BFA_IOC1_HBEAT_REG);
283*11189208SKrishna Gudipati 		ioc->ioc_regs.ioc_fwstate = (rb + CT2_BFA_IOC1_STATE_REG);
284*11189208SKrishna Gudipati 		ioc->ioc_regs.alt_ioc_fwstate = rb + CT2_BFA_IOC0_STATE_REG;
285*11189208SKrishna Gudipati 		ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P1;
286*11189208SKrishna Gudipati 		ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P0;
287*11189208SKrishna Gudipati 	}
288*11189208SKrishna Gudipati 
289*11189208SKrishna Gudipati 	/*
290*11189208SKrishna Gudipati 	 * PSS control registers
291*11189208SKrishna Gudipati 	 */
292*11189208SKrishna Gudipati 	ioc->ioc_regs.pss_ctl_reg = (rb + PSS_CTL_REG);
293*11189208SKrishna Gudipati 	ioc->ioc_regs.pss_err_status_reg = (rb + PSS_ERR_STATUS_REG);
294*11189208SKrishna Gudipati 	ioc->ioc_regs.app_pll_fast_ctl_reg = (rb + CT2_APP_PLL_LCLK_CTL_REG);
295*11189208SKrishna Gudipati 	ioc->ioc_regs.app_pll_slow_ctl_reg = (rb + CT2_APP_PLL_SCLK_CTL_REG);
296*11189208SKrishna Gudipati 
297*11189208SKrishna Gudipati 	/*
298*11189208SKrishna Gudipati 	 * IOC semaphore registers and serialization
299*11189208SKrishna Gudipati 	 */
300*11189208SKrishna Gudipati 	ioc->ioc_regs.ioc_sem_reg = (rb + CT2_HOST_SEM0_REG);
301*11189208SKrishna Gudipati 	ioc->ioc_regs.ioc_usage_sem_reg = (rb + CT2_HOST_SEM1_REG);
302*11189208SKrishna Gudipati 	ioc->ioc_regs.ioc_init_sem_reg = (rb + CT2_HOST_SEM2_REG);
303*11189208SKrishna Gudipati 	ioc->ioc_regs.ioc_usage_reg = (rb + BFA_FW_USE_COUNT);
304*11189208SKrishna Gudipati 	ioc->ioc_regs.ioc_fail_sync = (rb + BFA_IOC_FAIL_SYNC);
305*11189208SKrishna Gudipati 
306*11189208SKrishna Gudipati 	/*
307*11189208SKrishna Gudipati 	 * sram memory access
308*11189208SKrishna Gudipati 	 */
309*11189208SKrishna Gudipati 	ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START);
310*11189208SKrishna Gudipati 	ioc->ioc_regs.smem_pg0 = BFI_IOC_SMEM_PG0_CT;
311*11189208SKrishna Gudipati 
312*11189208SKrishna Gudipati 	/*
313*11189208SKrishna Gudipati 	 * err set reg : for notification of hb failure in fcmode
314*11189208SKrishna Gudipati 	 */
315*11189208SKrishna Gudipati 	ioc->ioc_regs.err_set = (rb + ERR_SET_REG);
316*11189208SKrishna Gudipati }
317*11189208SKrishna Gudipati 
3185fbe25c7SJing Huang /*
3190a20de44SKrishna Gudipati  * Initialize IOC to port mapping.
3200a20de44SKrishna Gudipati  */
3210a20de44SKrishna Gudipati 
3220a20de44SKrishna Gudipati #define FNC_PERS_FN_SHIFT(__fn)	((__fn) * 8)
3230a20de44SKrishna Gudipati static void
3240a20de44SKrishna Gudipati bfa_ioc_ct_map_port(struct bfa_ioc_s *ioc)
3250a20de44SKrishna Gudipati {
32653440260SJing Huang 	void __iomem *rb = ioc->pcidev.pci_bar_kva;
327d1c61f8eSKrishna Gudipati 	u32	r32;
3280a20de44SKrishna Gudipati 
3295fbe25c7SJing Huang 	/*
3300a20de44SKrishna Gudipati 	 * For catapult, base port id on personality register and IOC type
3310a20de44SKrishna Gudipati 	 */
33253440260SJing Huang 	r32 = readl(rb + FNC_PERS_REG);
3330a20de44SKrishna Gudipati 	r32 >>= FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc));
3340a20de44SKrishna Gudipati 	ioc->port_id = (r32 & __F0_PORT_MAP_MK) >> __F0_PORT_MAP_SH;
3350a20de44SKrishna Gudipati 
3360a20de44SKrishna Gudipati 	bfa_trc(ioc, bfa_ioc_pcifn(ioc));
3370a20de44SKrishna Gudipati 	bfa_trc(ioc, ioc->port_id);
3380a20de44SKrishna Gudipati }
3390a20de44SKrishna Gudipati 
340*11189208SKrishna Gudipati static void
341*11189208SKrishna Gudipati bfa_ioc_ct2_map_port(struct bfa_ioc_s *ioc)
342*11189208SKrishna Gudipati {
343*11189208SKrishna Gudipati 	ioc->port_id = bfa_ioc_pcifn(ioc) % 2;
344*11189208SKrishna Gudipati 
345*11189208SKrishna Gudipati 	bfa_trc(ioc, bfa_ioc_pcifn(ioc));
346*11189208SKrishna Gudipati 	bfa_trc(ioc, ioc->port_id);
347*11189208SKrishna Gudipati }
348*11189208SKrishna Gudipati 
3495fbe25c7SJing Huang /*
3500a20de44SKrishna Gudipati  * Set interrupt mode for a function: INTX or MSIX
3510a20de44SKrishna Gudipati  */
3520a20de44SKrishna Gudipati static void
3530a20de44SKrishna Gudipati bfa_ioc_ct_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix)
3540a20de44SKrishna Gudipati {
35553440260SJing Huang 	void __iomem *rb = ioc->pcidev.pci_bar_kva;
356d1c61f8eSKrishna Gudipati 	u32	r32, mode;
3570a20de44SKrishna Gudipati 
35853440260SJing Huang 	r32 = readl(rb + FNC_PERS_REG);
3590a20de44SKrishna Gudipati 	bfa_trc(ioc, r32);
3600a20de44SKrishna Gudipati 
3610a20de44SKrishna Gudipati 	mode = (r32 >> FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc))) &
3620a20de44SKrishna Gudipati 		__F0_INTX_STATUS;
3630a20de44SKrishna Gudipati 
3645fbe25c7SJing Huang 	/*
3650a20de44SKrishna Gudipati 	 * If already in desired mode, do not change anything
3660a20de44SKrishna Gudipati 	 */
367*11189208SKrishna Gudipati 	if ((!msix && mode) || (msix && !mode))
3680a20de44SKrishna Gudipati 		return;
3690a20de44SKrishna Gudipati 
3700a20de44SKrishna Gudipati 	if (msix)
3710a20de44SKrishna Gudipati 		mode = __F0_INTX_STATUS_MSIX;
3720a20de44SKrishna Gudipati 	else
3730a20de44SKrishna Gudipati 		mode = __F0_INTX_STATUS_INTA;
3740a20de44SKrishna Gudipati 
3750a20de44SKrishna Gudipati 	r32 &= ~(__F0_INTX_STATUS << FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc)));
3760a20de44SKrishna Gudipati 	r32 |= (mode << FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc)));
3770a20de44SKrishna Gudipati 	bfa_trc(ioc, r32);
3780a20de44SKrishna Gudipati 
37953440260SJing Huang 	writel(r32, rb + FNC_PERS_REG);
3800a20de44SKrishna Gudipati }
3810a20de44SKrishna Gudipati 
3825fbe25c7SJing Huang /*
3830a20de44SKrishna Gudipati  * Cleanup hw semaphore and usecnt registers
3840a20de44SKrishna Gudipati  */
3850a20de44SKrishna Gudipati static void
3860a20de44SKrishna Gudipati bfa_ioc_ct_ownership_reset(struct bfa_ioc_s *ioc)
3870a20de44SKrishna Gudipati {
3880a20de44SKrishna Gudipati 
389*11189208SKrishna Gudipati 	if (bfa_ioc_is_cna(ioc)) {
3900a20de44SKrishna Gudipati 		bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg);
39153440260SJing Huang 		writel(0, ioc->ioc_regs.ioc_usage_reg);
392f7f73812SMaggie Zhang 		writel(1, ioc->ioc_regs.ioc_usage_sem_reg);
3930a20de44SKrishna Gudipati 	}
3940a20de44SKrishna Gudipati 
3950a20de44SKrishna Gudipati 	/*
3960a20de44SKrishna Gudipati 	 * Read the hw sem reg to make sure that it is locked
3970a20de44SKrishna Gudipati 	 * before we clear it. If it is not locked, writing 1
3980a20de44SKrishna Gudipati 	 * will lock it instead of clearing it.
3990a20de44SKrishna Gudipati 	 */
40053440260SJing Huang 	readl(ioc->ioc_regs.ioc_sem_reg);
401f7f73812SMaggie Zhang 	writel(1, ioc->ioc_regs.ioc_sem_reg);
4020a20de44SKrishna Gudipati }
403a36c61f9SKrishna Gudipati 
40445d7f0ccSJing Huang static bfa_boolean_t
40545d7f0ccSJing Huang bfa_ioc_ct_sync_start(struct bfa_ioc_s *ioc)
40645d7f0ccSJing Huang {
40745d7f0ccSJing Huang 	uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync);
40845d7f0ccSJing Huang 	uint32_t sync_reqd = bfa_ioc_ct_get_sync_reqd(r32);
40945d7f0ccSJing Huang 
41045d7f0ccSJing Huang 	/*
41145d7f0ccSJing Huang 	 * Driver load time.  If the sync required bit for this PCI fn
41245d7f0ccSJing Huang 	 * is set, it is due to an unclean exit by the driver for this
41345d7f0ccSJing Huang 	 * PCI fn in the previous incarnation. Whoever comes here first
41445d7f0ccSJing Huang 	 * should clean it up, no matter which PCI fn.
41545d7f0ccSJing Huang 	 */
41645d7f0ccSJing Huang 
41745d7f0ccSJing Huang 	if (sync_reqd & bfa_ioc_ct_sync_pos(ioc)) {
41845d7f0ccSJing Huang 		writel(0, ioc->ioc_regs.ioc_fail_sync);
41945d7f0ccSJing Huang 		writel(1, ioc->ioc_regs.ioc_usage_reg);
42045d7f0ccSJing Huang 		writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
42145d7f0ccSJing Huang 		writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate);
42245d7f0ccSJing Huang 		return BFA_TRUE;
42345d7f0ccSJing Huang 	}
42445d7f0ccSJing Huang 
42545d7f0ccSJing Huang 	return bfa_ioc_ct_sync_complete(ioc);
42645d7f0ccSJing Huang }
42745d7f0ccSJing Huang 
4288f4bfaddSJing Huang /*
429f1d584d7SKrishna Gudipati  * Synchronized IOC failure processing routines
430f1d584d7SKrishna Gudipati  */
431f1d584d7SKrishna Gudipati static void
432f1d584d7SKrishna Gudipati bfa_ioc_ct_sync_join(struct bfa_ioc_s *ioc)
433f1d584d7SKrishna Gudipati {
434f1d584d7SKrishna Gudipati 	uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync);
435f1d584d7SKrishna Gudipati 	uint32_t sync_pos = bfa_ioc_ct_sync_reqd_pos(ioc);
436a36c61f9SKrishna Gudipati 
437f1d584d7SKrishna Gudipati 	writel((r32 | sync_pos), ioc->ioc_regs.ioc_fail_sync);
438f1d584d7SKrishna Gudipati }
439f1d584d7SKrishna Gudipati 
440f1d584d7SKrishna Gudipati static void
441f1d584d7SKrishna Gudipati bfa_ioc_ct_sync_leave(struct bfa_ioc_s *ioc)
442f1d584d7SKrishna Gudipati {
443f1d584d7SKrishna Gudipati 	uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync);
444f1d584d7SKrishna Gudipati 	uint32_t sync_msk = bfa_ioc_ct_sync_reqd_pos(ioc) |
445f1d584d7SKrishna Gudipati 					bfa_ioc_ct_sync_pos(ioc);
446f1d584d7SKrishna Gudipati 
447f1d584d7SKrishna Gudipati 	writel((r32 & ~sync_msk), ioc->ioc_regs.ioc_fail_sync);
448f1d584d7SKrishna Gudipati }
449f1d584d7SKrishna Gudipati 
450f1d584d7SKrishna Gudipati static void
451f1d584d7SKrishna Gudipati bfa_ioc_ct_sync_ack(struct bfa_ioc_s *ioc)
452f1d584d7SKrishna Gudipati {
453f1d584d7SKrishna Gudipati 	uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync);
454f1d584d7SKrishna Gudipati 
455f1d584d7SKrishna Gudipati 	writel((r32 | bfa_ioc_ct_sync_pos(ioc)),
456f1d584d7SKrishna Gudipati 		ioc->ioc_regs.ioc_fail_sync);
457f1d584d7SKrishna Gudipati }
458f1d584d7SKrishna Gudipati 
459f1d584d7SKrishna Gudipati static bfa_boolean_t
460f1d584d7SKrishna Gudipati bfa_ioc_ct_sync_complete(struct bfa_ioc_s *ioc)
461f1d584d7SKrishna Gudipati {
462f1d584d7SKrishna Gudipati 	uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync);
463f1d584d7SKrishna Gudipati 	uint32_t sync_reqd = bfa_ioc_ct_get_sync_reqd(r32);
464f1d584d7SKrishna Gudipati 	uint32_t sync_ackd = bfa_ioc_ct_get_sync_ackd(r32);
465f1d584d7SKrishna Gudipati 	uint32_t tmp_ackd;
466f1d584d7SKrishna Gudipati 
467f1d584d7SKrishna Gudipati 	if (sync_ackd == 0)
468f1d584d7SKrishna Gudipati 		return BFA_TRUE;
469f1d584d7SKrishna Gudipati 
4708f4bfaddSJing Huang 	/*
471f1d584d7SKrishna Gudipati 	 * The check below is to see whether any other PCI fn
472f1d584d7SKrishna Gudipati 	 * has reinitialized the ASIC (reset sync_ackd bits)
473f1d584d7SKrishna Gudipati 	 * and failed again while this IOC was waiting for hw
474f1d584d7SKrishna Gudipati 	 * semaphore (in bfa_iocpf_sm_semwait()).
475f1d584d7SKrishna Gudipati 	 */
476f1d584d7SKrishna Gudipati 	tmp_ackd = sync_ackd;
477f1d584d7SKrishna Gudipati 	if ((sync_reqd &  bfa_ioc_ct_sync_pos(ioc)) &&
478f1d584d7SKrishna Gudipati 		!(sync_ackd & bfa_ioc_ct_sync_pos(ioc)))
479f1d584d7SKrishna Gudipati 		sync_ackd |= bfa_ioc_ct_sync_pos(ioc);
480f1d584d7SKrishna Gudipati 
481f1d584d7SKrishna Gudipati 	if (sync_reqd == sync_ackd) {
482f1d584d7SKrishna Gudipati 		writel(bfa_ioc_ct_clear_sync_ackd(r32),
483f1d584d7SKrishna Gudipati 			ioc->ioc_regs.ioc_fail_sync);
484f1d584d7SKrishna Gudipati 		writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
485f1d584d7SKrishna Gudipati 		writel(BFI_IOC_FAIL, ioc->ioc_regs.alt_ioc_fwstate);
486f1d584d7SKrishna Gudipati 		return BFA_TRUE;
487f1d584d7SKrishna Gudipati 	}
488f1d584d7SKrishna Gudipati 
4898f4bfaddSJing Huang 	/*
490f1d584d7SKrishna Gudipati 	 * If another PCI fn reinitialized and failed again while
491f1d584d7SKrishna Gudipati 	 * this IOC was waiting for hw sem, the sync_ackd bit for
492f1d584d7SKrishna Gudipati 	 * this IOC need to be set again to allow reinitialization.
493f1d584d7SKrishna Gudipati 	 */
494f1d584d7SKrishna Gudipati 	if (tmp_ackd != sync_ackd)
495f1d584d7SKrishna Gudipati 		writel((r32 | sync_ackd), ioc->ioc_regs.ioc_fail_sync);
496f1d584d7SKrishna Gudipati 
497f1d584d7SKrishna Gudipati 	return BFA_FALSE;
498f1d584d7SKrishna Gudipati }
499a36c61f9SKrishna Gudipati 
500*11189208SKrishna Gudipati /**
501*11189208SKrishna Gudipati  * Called from bfa_ioc_attach() to map asic specific calls.
502a36c61f9SKrishna Gudipati  */
503*11189208SKrishna Gudipati static void
504*11189208SKrishna Gudipati bfa_ioc_set_ctx_hwif(struct bfa_ioc_s *ioc, struct bfa_ioc_hwif_s *hwif)
505a36c61f9SKrishna Gudipati {
506*11189208SKrishna Gudipati 	hwif->ioc_firmware_lock = bfa_ioc_ct_firmware_lock;
507*11189208SKrishna Gudipati 	hwif->ioc_firmware_unlock = bfa_ioc_ct_firmware_unlock;
508*11189208SKrishna Gudipati 	hwif->ioc_notify_fail = bfa_ioc_ct_notify_fail;
509*11189208SKrishna Gudipati 	hwif->ioc_ownership_reset = bfa_ioc_ct_ownership_reset;
510*11189208SKrishna Gudipati 	hwif->ioc_sync_start = bfa_ioc_ct_sync_start;
511*11189208SKrishna Gudipati 	hwif->ioc_sync_join = bfa_ioc_ct_sync_join;
512*11189208SKrishna Gudipati 	hwif->ioc_sync_leave = bfa_ioc_ct_sync_leave;
513*11189208SKrishna Gudipati 	hwif->ioc_sync_ack = bfa_ioc_ct_sync_ack;
514*11189208SKrishna Gudipati 	hwif->ioc_sync_complete = bfa_ioc_ct_sync_complete;
515*11189208SKrishna Gudipati }
516a36c61f9SKrishna Gudipati 
517*11189208SKrishna Gudipati /**
518*11189208SKrishna Gudipati  * Called from bfa_ioc_attach() to map asic specific calls.
519*11189208SKrishna Gudipati  */
520*11189208SKrishna Gudipati void
521*11189208SKrishna Gudipati bfa_ioc_set_ct_hwif(struct bfa_ioc_s *ioc)
522*11189208SKrishna Gudipati {
523*11189208SKrishna Gudipati 	bfa_ioc_set_ctx_hwif(ioc, &hwif_ct);
524*11189208SKrishna Gudipati 
525*11189208SKrishna Gudipati 	hwif_ct.ioc_pll_init = bfa_ioc_ct_pll_init;
526*11189208SKrishna Gudipati 	hwif_ct.ioc_reg_init = bfa_ioc_ct_reg_init;
527*11189208SKrishna Gudipati 	hwif_ct.ioc_map_port = bfa_ioc_ct_map_port;
528*11189208SKrishna Gudipati 	hwif_ct.ioc_isr_mode_set = bfa_ioc_ct_isr_mode_set;
529*11189208SKrishna Gudipati 	ioc->ioc_hwif = &hwif_ct;
530*11189208SKrishna Gudipati }
531*11189208SKrishna Gudipati 
532*11189208SKrishna Gudipati /**
533*11189208SKrishna Gudipati  * Called from bfa_ioc_attach() to map asic specific calls.
534*11189208SKrishna Gudipati  */
535*11189208SKrishna Gudipati void
536*11189208SKrishna Gudipati bfa_ioc_set_ct2_hwif(struct bfa_ioc_s *ioc)
537*11189208SKrishna Gudipati {
538*11189208SKrishna Gudipati 	bfa_ioc_set_ctx_hwif(ioc, &hwif_ct2);
539*11189208SKrishna Gudipati 
540*11189208SKrishna Gudipati 	hwif_ct2.ioc_pll_init = bfa_ioc_ct2_pll_init;
541*11189208SKrishna Gudipati 	hwif_ct2.ioc_reg_init = bfa_ioc_ct2_reg_init;
542*11189208SKrishna Gudipati 	hwif_ct2.ioc_map_port = bfa_ioc_ct2_map_port;
543*11189208SKrishna Gudipati 	hwif_ct2.ioc_isr_mode_set = NULL;
544*11189208SKrishna Gudipati 	ioc->ioc_hwif = &hwif_ct2;
545*11189208SKrishna Gudipati }
546*11189208SKrishna Gudipati 
547*11189208SKrishna Gudipati /*
548*11189208SKrishna Gudipati  * Temporary workaround for MSI-X resource allocation for catapult-2.
549*11189208SKrishna Gudipati  */
550*11189208SKrishna Gudipati #define HOSTFN_MSIX_DEFAULT		16
551*11189208SKrishna Gudipati #define HOSTFN_MSIX_VT_OFST_NUMVT	0x3013c
552*11189208SKrishna Gudipati #define __MSIX_VT_NUMVT__MK		0x003ff800
553*11189208SKrishna Gudipati #define __MSIX_VT_NUMVT__SH		11
554*11189208SKrishna Gudipati #define __MSIX_VT_NUMVT_(_v)		((_v) << __MSIX_VT_NUMVT__SH)
555*11189208SKrishna Gudipati void
556*11189208SKrishna Gudipati bfa_ioc_ct2_poweron(struct bfa_ioc_s *ioc)
557*11189208SKrishna Gudipati {
558*11189208SKrishna Gudipati 	void __iomem *rb = ioc->pcidev.pci_bar_kva;
559*11189208SKrishna Gudipati 	u32	r32;
560*11189208SKrishna Gudipati 
561*11189208SKrishna Gudipati 	r32 = readl(rb + HOSTFN_MSIX_VT_OFST_NUMVT);
562*11189208SKrishna Gudipati 	if (r32 & __MSIX_VT_NUMVT__MK)
563*11189208SKrishna Gudipati 		return;
564*11189208SKrishna Gudipati 
565*11189208SKrishna Gudipati 	writel(__MSIX_VT_NUMVT_(HOSTFN_MSIX_DEFAULT - 1) |
566*11189208SKrishna Gudipati 		HOSTFN_MSIX_DEFAULT * bfa_ioc_pcifn(ioc),
567*11189208SKrishna Gudipati 		rb + HOSTFN_MSIX_VT_OFST_NUMVT);
568a36c61f9SKrishna Gudipati }
569a36c61f9SKrishna Gudipati 
570a36c61f9SKrishna Gudipati bfa_status_t
571*11189208SKrishna Gudipati bfa_ioc_ct_pll_init(void __iomem *rb, enum bfi_asic_mode mode)
572a36c61f9SKrishna Gudipati {
573a36c61f9SKrishna Gudipati 	u32	pll_sclk, pll_fclk, r32;
574*11189208SKrishna Gudipati 	bfa_boolean_t fcmode = (mode == BFI_ASIC_MODE_FC);
575a36c61f9SKrishna Gudipati 
576*11189208SKrishna Gudipati 	pll_sclk = __APP_PLL_SCLK_LRESETN | __APP_PLL_SCLK_ENARST |
577*11189208SKrishna Gudipati 		__APP_PLL_SCLK_RSEL200500 | __APP_PLL_SCLK_P0_1(3U) |
578*11189208SKrishna Gudipati 		__APP_PLL_SCLK_JITLMT0_1(3U) |
579*11189208SKrishna Gudipati 		__APP_PLL_SCLK_CNTLMT0_1(1U);
580*11189208SKrishna Gudipati 	pll_fclk = __APP_PLL_LCLK_LRESETN | __APP_PLL_LCLK_ENARST |
581*11189208SKrishna Gudipati 		__APP_PLL_LCLK_RSEL200500 | __APP_PLL_LCLK_P0_1(3U) |
582*11189208SKrishna Gudipati 		__APP_PLL_LCLK_JITLMT0_1(3U) |
583*11189208SKrishna Gudipati 		__APP_PLL_LCLK_CNTLMT0_1(1U);
584*11189208SKrishna Gudipati 
585a36c61f9SKrishna Gudipati 	if (fcmode) {
58653440260SJing Huang 		writel(0, (rb + OP_MODE));
58753440260SJing Huang 		writel(__APP_EMS_CMLCKSEL | __APP_EMS_REFCKBUFEN2 |
58853440260SJing Huang 			 __APP_EMS_CHANNEL_SEL, (rb + ETH_MAC_SER_REG));
589a36c61f9SKrishna Gudipati 	} else {
59053440260SJing Huang 		writel(__GLOBAL_FCOE_MODE, (rb + OP_MODE));
59153440260SJing Huang 		writel(__APP_EMS_REFCKBUFEN1, (rb + ETH_MAC_SER_REG));
592a36c61f9SKrishna Gudipati 	}
59353440260SJing Huang 	writel(BFI_IOC_UNINIT, (rb + BFA_IOC0_STATE_REG));
59453440260SJing Huang 	writel(BFI_IOC_UNINIT, (rb + BFA_IOC1_STATE_REG));
59553440260SJing Huang 	writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
59653440260SJing Huang 	writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
59753440260SJing Huang 	writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
59853440260SJing Huang 	writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
59953440260SJing Huang 	writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
60053440260SJing Huang 	writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
601*11189208SKrishna Gudipati 	writel(pll_sclk | __APP_PLL_SCLK_LOGIC_SOFT_RESET,
602*11189208SKrishna Gudipati 			rb + APP_PLL_SCLK_CTL_REG);
603*11189208SKrishna Gudipati 	writel(pll_fclk | __APP_PLL_LCLK_LOGIC_SOFT_RESET,
604*11189208SKrishna Gudipati 			rb + APP_PLL_LCLK_CTL_REG);
605*11189208SKrishna Gudipati 	writel(pll_sclk | __APP_PLL_SCLK_LOGIC_SOFT_RESET |
606*11189208SKrishna Gudipati 		__APP_PLL_SCLK_ENABLE, rb + APP_PLL_SCLK_CTL_REG);
607*11189208SKrishna Gudipati 	writel(pll_fclk | __APP_PLL_LCLK_LOGIC_SOFT_RESET |
608*11189208SKrishna Gudipati 		__APP_PLL_LCLK_ENABLE, rb + APP_PLL_LCLK_CTL_REG);
60953440260SJing Huang 	readl(rb + HOSTFN0_INT_MSK);
6106a18b167SJing Huang 	udelay(2000);
61153440260SJing Huang 	writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
61253440260SJing Huang 	writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
613*11189208SKrishna Gudipati 	writel(pll_sclk | __APP_PLL_SCLK_ENABLE, rb + APP_PLL_SCLK_CTL_REG);
614*11189208SKrishna Gudipati 	writel(pll_fclk | __APP_PLL_LCLK_ENABLE, rb + APP_PLL_LCLK_CTL_REG);
615*11189208SKrishna Gudipati 
616a36c61f9SKrishna Gudipati 	if (!fcmode) {
61753440260SJing Huang 		writel(__PMM_1T_RESET_P, (rb + PMM_1T_RESET_REG_P0));
61853440260SJing Huang 		writel(__PMM_1T_RESET_P, (rb + PMM_1T_RESET_REG_P1));
619a36c61f9SKrishna Gudipati 	}
62053440260SJing Huang 	r32 = readl((rb + PSS_CTL_REG));
621a36c61f9SKrishna Gudipati 	r32 &= ~__PSS_LMEM_RESET;
62253440260SJing Huang 	writel(r32, (rb + PSS_CTL_REG));
6236a18b167SJing Huang 	udelay(1000);
624a36c61f9SKrishna Gudipati 	if (!fcmode) {
62553440260SJing Huang 		writel(0, (rb + PMM_1T_RESET_REG_P0));
62653440260SJing Huang 		writel(0, (rb + PMM_1T_RESET_REG_P1));
627a36c61f9SKrishna Gudipati 	}
628a36c61f9SKrishna Gudipati 
62953440260SJing Huang 	writel(__EDRAM_BISTR_START, (rb + MBIST_CTL_REG));
6306a18b167SJing Huang 	udelay(1000);
63153440260SJing Huang 	r32 = readl((rb + MBIST_STAT_REG));
63253440260SJing Huang 	writel(0, (rb + MBIST_CTL_REG));
633a36c61f9SKrishna Gudipati 	return BFA_STATUS_OK;
634a36c61f9SKrishna Gudipati }
635*11189208SKrishna Gudipati 
636*11189208SKrishna Gudipati static struct { u32 sclk, speed, half_speed; } ct2_pll[] = {
637*11189208SKrishna Gudipati 	{0},							/* unused */
638*11189208SKrishna Gudipati 	{__APP_PLL_SCLK_CLK_DIV2, 0, 0},			/* FC 8G  */
639*11189208SKrishna Gudipati 	{0, __APP_LPU_SPEED, 0},				/* FC 16G */
640*11189208SKrishna Gudipati 	{__APP_PLL_SCLK_REFCLK_SEL | __APP_PLL_SCLK_CLK_DIV2, 0, /* ETH   */
641*11189208SKrishna Gudipati 	__APP_LPUCLK_HALFSPEED},
642*11189208SKrishna Gudipati 	{0, __APP_LPU_SPEED, 0},				/* COMBO  */
643*11189208SKrishna Gudipati };
644*11189208SKrishna Gudipati 
645*11189208SKrishna Gudipati static void
646*11189208SKrishna Gudipati bfa_ioc_ct2_sclk_init(void __iomem *rb, enum bfi_asic_mode mode)
647*11189208SKrishna Gudipati {
648*11189208SKrishna Gudipati 	u32 r32;
649*11189208SKrishna Gudipati 
650*11189208SKrishna Gudipati 	/*
651*11189208SKrishna Gudipati 	 * put s_clk PLL and PLL FSM in reset
652*11189208SKrishna Gudipati 	 */
653*11189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG));
654*11189208SKrishna Gudipati 	r32 &= ~(__APP_PLL_SCLK_ENABLE | __APP_PLL_SCLK_LRESETN);
655*11189208SKrishna Gudipati 	r32 |= (__APP_PLL_SCLK_ENARST | __APP_PLL_SCLK_BYPASS |
656*11189208SKrishna Gudipati 		__APP_PLL_SCLK_LOGIC_SOFT_RESET);
657*11189208SKrishna Gudipati 	writel(r32, (rb + CT2_APP_PLL_SCLK_CTL_REG));
658*11189208SKrishna Gudipati 
659*11189208SKrishna Gudipati 	/*
660*11189208SKrishna Gudipati 	 * select clock speed based on mode
661*11189208SKrishna Gudipati 	 */
662*11189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG));
663*11189208SKrishna Gudipati 	r32 &= ~(__APP_PLL_SCLK_REFCLK_SEL | __APP_PLL_SCLK_CLK_DIV2);
664*11189208SKrishna Gudipati 	writel(r32 | ct2_pll[mode].sclk, (rb + CT2_APP_PLL_SCLK_CTL_REG));
665*11189208SKrishna Gudipati 
666*11189208SKrishna Gudipati 	/*
667*11189208SKrishna Gudipati 	 * remove clock gating for ethernet subsystem for ethernet mode
668*11189208SKrishna Gudipati 	 */
669*11189208SKrishna Gudipati 	if (mode == BFI_ASIC_MODE_ETH) {
670*11189208SKrishna Gudipati 		r32 = readl((rb + CT2_CHIP_MISC_PRG));
671*11189208SKrishna Gudipati 		writel(r32 | __ETH_CLK_ENABLE_PORT0, (rb + CT2_CHIP_MISC_PRG));
672*11189208SKrishna Gudipati 
673*11189208SKrishna Gudipati 		r32 = readl((rb + CT2_PCIE_MISC_REG));
674*11189208SKrishna Gudipati 		writel(r32 | __ETH_CLK_ENABLE_PORT1, (rb + CT2_PCIE_MISC_REG));
675*11189208SKrishna Gudipati 	}
676*11189208SKrishna Gudipati 
677*11189208SKrishna Gudipati 	/*
678*11189208SKrishna Gudipati 	 * set sclk value
679*11189208SKrishna Gudipati 	 */
680*11189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG));
681*11189208SKrishna Gudipati 	r32 &= (__P_SCLK_PLL_LOCK | __APP_PLL_SCLK_REFCLK_SEL |
682*11189208SKrishna Gudipati 		__APP_PLL_SCLK_CLK_DIV2);
683*11189208SKrishna Gudipati 	writel(r32 | 0x1061731b, (rb + CT2_APP_PLL_SCLK_CTL_REG));
684*11189208SKrishna Gudipati 
685*11189208SKrishna Gudipati 	/*
686*11189208SKrishna Gudipati 	 * poll for s_clk lock or delay 1ms
687*11189208SKrishna Gudipati 	 */
688*11189208SKrishna Gudipati 	udelay(1000);
689*11189208SKrishna Gudipati 
690*11189208SKrishna Gudipati 	/*
691*11189208SKrishna Gudipati 	 * release soft reset on s_clk & l_clk
692*11189208SKrishna Gudipati 	 */
693*11189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG));
694*11189208SKrishna Gudipati 	writel(r32 & ~__APP_PLL_SCLK_LOGIC_SOFT_RESET,
695*11189208SKrishna Gudipati 		(rb + CT2_APP_PLL_SCLK_CTL_REG));
696*11189208SKrishna Gudipati }
697*11189208SKrishna Gudipati 
698*11189208SKrishna Gudipati static void
699*11189208SKrishna Gudipati bfa_ioc_ct2_lclk_init(void __iomem *rb, enum bfi_asic_mode mode)
700*11189208SKrishna Gudipati {
701*11189208SKrishna Gudipati 	u32 r32;
702*11189208SKrishna Gudipati 
703*11189208SKrishna Gudipati 	/*
704*11189208SKrishna Gudipati 	 * put l_clk PLL and PLL FSM in reset
705*11189208SKrishna Gudipati 	 */
706*11189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG));
707*11189208SKrishna Gudipati 	r32 &= ~(__APP_PLL_LCLK_ENABLE | __APP_PLL_LCLK_LRESETN);
708*11189208SKrishna Gudipati 	r32 |= (__APP_PLL_LCLK_ENARST | __APP_PLL_LCLK_BYPASS |
709*11189208SKrishna Gudipati 		__APP_PLL_LCLK_LOGIC_SOFT_RESET);
710*11189208SKrishna Gudipati 	writel(r32, (rb + CT2_APP_PLL_LCLK_CTL_REG));
711*11189208SKrishna Gudipati 
712*11189208SKrishna Gudipati 	/*
713*11189208SKrishna Gudipati 	 * set LPU speed
714*11189208SKrishna Gudipati 	 */
715*11189208SKrishna Gudipati 	r32 = readl((rb + CT2_CHIP_MISC_PRG));
716*11189208SKrishna Gudipati 	writel(r32 | ct2_pll[mode].speed,
717*11189208SKrishna Gudipati 		(rb + CT2_CHIP_MISC_PRG));
718*11189208SKrishna Gudipati 
719*11189208SKrishna Gudipati 	/*
720*11189208SKrishna Gudipati 	 * set LPU half speed
721*11189208SKrishna Gudipati 	 */
722*11189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG));
723*11189208SKrishna Gudipati 	writel(r32 | ct2_pll[mode].half_speed,
724*11189208SKrishna Gudipati 		(rb + CT2_APP_PLL_LCLK_CTL_REG));
725*11189208SKrishna Gudipati 
726*11189208SKrishna Gudipati 	/*
727*11189208SKrishna Gudipati 	 * set lclk for mode
728*11189208SKrishna Gudipati 	 */
729*11189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG));
730*11189208SKrishna Gudipati 	r32 &= (__P_LCLK_PLL_LOCK | __APP_LPUCLK_HALFSPEED);
731*11189208SKrishna Gudipati 	if (mode == BFI_ASIC_MODE_FC || mode == BFI_ASIC_MODE_ETH)
732*11189208SKrishna Gudipati 		r32 |= 0x20c1731b;
733*11189208SKrishna Gudipati 	else
734*11189208SKrishna Gudipati 		r32 |= 0x2081731b;
735*11189208SKrishna Gudipati 	writel(r32, (rb + CT2_APP_PLL_LCLK_CTL_REG));
736*11189208SKrishna Gudipati 
737*11189208SKrishna Gudipati 	/*
738*11189208SKrishna Gudipati 	 * poll for s_clk lock or delay 1ms
739*11189208SKrishna Gudipati 	 */
740*11189208SKrishna Gudipati 	udelay(1000);
741*11189208SKrishna Gudipati 
742*11189208SKrishna Gudipati 	/*
743*11189208SKrishna Gudipati 	 * release soft reset on s_clk & l_clk
744*11189208SKrishna Gudipati 	 */
745*11189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG));
746*11189208SKrishna Gudipati 	writel(r32 & ~__APP_PLL_LCLK_LOGIC_SOFT_RESET,
747*11189208SKrishna Gudipati 		(rb + CT2_APP_PLL_LCLK_CTL_REG));
748*11189208SKrishna Gudipati }
749*11189208SKrishna Gudipati 
750*11189208SKrishna Gudipati static void
751*11189208SKrishna Gudipati bfa_ioc_ct2_mem_init(void __iomem *rb, enum bfi_asic_mode mode)
752*11189208SKrishna Gudipati {
753*11189208SKrishna Gudipati 	bfa_boolean_t fcmode;
754*11189208SKrishna Gudipati 	u32	r32;
755*11189208SKrishna Gudipati 
756*11189208SKrishna Gudipati 	fcmode = (mode == BFI_ASIC_MODE_FC) || (mode == BFI_ASIC_MODE_FC16);
757*11189208SKrishna Gudipati 	if (!fcmode) {
758*11189208SKrishna Gudipati 		writel(__PMM_1T_RESET_P, (rb + CT2_PMM_1T_CONTROL_REG_P0));
759*11189208SKrishna Gudipati 		writel(__PMM_1T_RESET_P, (rb + CT2_PMM_1T_CONTROL_REG_P1));
760*11189208SKrishna Gudipati 	}
761*11189208SKrishna Gudipati 
762*11189208SKrishna Gudipati 	r32 = readl((rb + PSS_CTL_REG));
763*11189208SKrishna Gudipati 	r32 &= ~__PSS_LMEM_RESET;
764*11189208SKrishna Gudipati 	writel(r32, (rb + PSS_CTL_REG));
765*11189208SKrishna Gudipati 	udelay(1000);
766*11189208SKrishna Gudipati 
767*11189208SKrishna Gudipati 	writel(__EDRAM_BISTR_START, (rb + CT2_MBIST_CTL_REG));
768*11189208SKrishna Gudipati 	udelay(1000);
769*11189208SKrishna Gudipati 	writel(0, (rb + CT2_MBIST_CTL_REG));
770*11189208SKrishna Gudipati }
771*11189208SKrishna Gudipati 
772*11189208SKrishna Gudipati bfa_status_t
773*11189208SKrishna Gudipati bfa_ioc_ct2_pll_init(void __iomem *rb, enum bfi_asic_mode mode)
774*11189208SKrishna Gudipati {
775*11189208SKrishna Gudipati 	bfa_ioc_ct2_sclk_init(rb, mode);
776*11189208SKrishna Gudipati 	bfa_ioc_ct2_lclk_init(rb, mode);
777*11189208SKrishna Gudipati 	bfa_ioc_ct2_mem_init(rb, mode);
778*11189208SKrishna Gudipati 
779*11189208SKrishna Gudipati 	writel(BFI_IOC_UNINIT, (rb + CT2_BFA_IOC0_STATE_REG));
780*11189208SKrishna Gudipati 	writel(BFI_IOC_UNINIT, (rb + CT2_BFA_IOC1_STATE_REG));
781*11189208SKrishna Gudipati 	return BFA_STATUS_OK;
782*11189208SKrishna Gudipati }
783