xref: /openbmc/linux/drivers/scsi/bfa/bfa_ioc_ct.c (revision 775c7742adfd7726f05914198bf33eaa3b9f64bb)
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"
2011189208SKrishna 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;
4811189208SKrishna 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 	 */
6311189208SKrishna 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 	 */
6911189208SKrishna 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 	 */
12311189208SKrishna 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 	 */
12911189208SKrishna 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 {
15311189208SKrishna 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 {
16011189208SKrishna 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  */
16811189208SKrishna 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  */
17811189208SKrishna Gudipati static struct { u32 hfn, lpu; } ct_p0reg[] = {
17911189208SKrishna Gudipati 	{ HOSTFN0_LPU0_CMD_STAT, LPU0_HOSTFN0_CMD_STAT },
18011189208SKrishna Gudipati 	{ HOSTFN1_LPU0_CMD_STAT, LPU0_HOSTFN1_CMD_STAT },
18111189208SKrishna Gudipati 	{ HOSTFN2_LPU0_CMD_STAT, LPU0_HOSTFN2_CMD_STAT },
18211189208SKrishna 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  */
18811189208SKrishna Gudipati static struct { u32 hfn, lpu; } ct_p1reg[] = {
18911189208SKrishna Gudipati 	{ HOSTFN0_LPU1_CMD_STAT, LPU1_HOSTFN0_CMD_STAT },
19011189208SKrishna Gudipati 	{ HOSTFN1_LPU1_CMD_STAT, LPU1_HOSTFN1_CMD_STAT },
19111189208SKrishna Gudipati 	{ HOSTFN2_LPU1_CMD_STAT, LPU1_HOSTFN2_CMD_STAT },
19211189208SKrishna Gudipati 	{ HOSTFN3_LPU1_CMD_STAT, LPU1_HOSTFN3_CMD_STAT }
19311189208SKrishna Gudipati };
19411189208SKrishna Gudipati 
19511189208SKrishna Gudipati static struct { uint32_t hfn_mbox, lpu_mbox, hfn_pgn, hfn, lpu; } ct2_reg[] = {
19611189208SKrishna Gudipati 	{ CT2_HOSTFN_LPU0_MBOX0, CT2_LPU0_HOSTFN_MBOX0, CT2_HOSTFN_PAGE_NUM,
19711189208SKrishna Gudipati 	  CT2_HOSTFN_LPU0_CMD_STAT, CT2_LPU0_HOSTFN_CMD_STAT },
19811189208SKrishna Gudipati 	{ CT2_HOSTFN_LPU1_MBOX0, CT2_LPU1_HOSTFN_MBOX0, CT2_HOSTFN_PAGE_NUM,
19911189208SKrishna 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 
21011189208SKrishna Gudipati 	ioc->ioc_regs.hfn_mbox = rb + ct_fnreg[pcifn].hfn_mbox;
21111189208SKrishna Gudipati 	ioc->ioc_regs.lpu_mbox = rb + ct_fnreg[pcifn].lpu_mbox;
21211189208SKrishna 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;
21811189208SKrishna Gudipati 		ioc->ioc_regs.hfn_mbox_cmd = rb + ct_p0reg[pcifn].hfn;
21911189208SKrishna 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;
22611189208SKrishna Gudipati 		ioc->ioc_regs.hfn_mbox_cmd = rb + ct_p1reg[pcifn].hfn;
22711189208SKrishna 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);
23711189208SKrishna Gudipati 	ioc->ioc_regs.app_pll_fast_ctl_reg = (rb + APP_PLL_LCLK_CTL_REG);
23811189208SKrishna 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 
26111189208SKrishna Gudipati static void
26211189208SKrishna Gudipati bfa_ioc_ct2_reg_init(struct bfa_ioc_s *ioc)
26311189208SKrishna Gudipati {
26411189208SKrishna Gudipati 	void __iomem *rb;
26511189208SKrishna Gudipati 	int	port = bfa_ioc_portid(ioc);
26611189208SKrishna Gudipati 
26711189208SKrishna Gudipati 	rb = bfa_ioc_bar0(ioc);
26811189208SKrishna Gudipati 
26911189208SKrishna Gudipati 	ioc->ioc_regs.hfn_mbox = rb + ct2_reg[port].hfn_mbox;
27011189208SKrishna Gudipati 	ioc->ioc_regs.lpu_mbox = rb + ct2_reg[port].lpu_mbox;
27111189208SKrishna Gudipati 	ioc->ioc_regs.host_page_num_fn = rb + ct2_reg[port].hfn_pgn;
27211189208SKrishna Gudipati 	ioc->ioc_regs.hfn_mbox_cmd = rb + ct2_reg[port].hfn;
27311189208SKrishna Gudipati 	ioc->ioc_regs.lpu_mbox_cmd = rb + ct2_reg[port].lpu;
27411189208SKrishna Gudipati 
27511189208SKrishna Gudipati 	if (port == 0) {
27611189208SKrishna Gudipati 		ioc->ioc_regs.heartbeat = rb + CT2_BFA_IOC0_HBEAT_REG;
27711189208SKrishna Gudipati 		ioc->ioc_regs.ioc_fwstate = rb + CT2_BFA_IOC0_STATE_REG;
27811189208SKrishna Gudipati 		ioc->ioc_regs.alt_ioc_fwstate = rb + CT2_BFA_IOC1_STATE_REG;
27911189208SKrishna Gudipati 		ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P0;
28011189208SKrishna Gudipati 		ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P1;
28111189208SKrishna Gudipati 	} else {
28211189208SKrishna Gudipati 		ioc->ioc_regs.heartbeat = (rb + CT2_BFA_IOC1_HBEAT_REG);
28311189208SKrishna Gudipati 		ioc->ioc_regs.ioc_fwstate = (rb + CT2_BFA_IOC1_STATE_REG);
28411189208SKrishna Gudipati 		ioc->ioc_regs.alt_ioc_fwstate = rb + CT2_BFA_IOC0_STATE_REG;
28511189208SKrishna Gudipati 		ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P1;
28611189208SKrishna Gudipati 		ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P0;
28711189208SKrishna Gudipati 	}
28811189208SKrishna Gudipati 
28911189208SKrishna Gudipati 	/*
29011189208SKrishna Gudipati 	 * PSS control registers
29111189208SKrishna Gudipati 	 */
29211189208SKrishna Gudipati 	ioc->ioc_regs.pss_ctl_reg = (rb + PSS_CTL_REG);
29311189208SKrishna Gudipati 	ioc->ioc_regs.pss_err_status_reg = (rb + PSS_ERR_STATUS_REG);
29411189208SKrishna Gudipati 	ioc->ioc_regs.app_pll_fast_ctl_reg = (rb + CT2_APP_PLL_LCLK_CTL_REG);
29511189208SKrishna Gudipati 	ioc->ioc_regs.app_pll_slow_ctl_reg = (rb + CT2_APP_PLL_SCLK_CTL_REG);
29611189208SKrishna Gudipati 
29711189208SKrishna Gudipati 	/*
29811189208SKrishna Gudipati 	 * IOC semaphore registers and serialization
29911189208SKrishna Gudipati 	 */
30011189208SKrishna Gudipati 	ioc->ioc_regs.ioc_sem_reg = (rb + CT2_HOST_SEM0_REG);
30111189208SKrishna Gudipati 	ioc->ioc_regs.ioc_usage_sem_reg = (rb + CT2_HOST_SEM1_REG);
30211189208SKrishna Gudipati 	ioc->ioc_regs.ioc_init_sem_reg = (rb + CT2_HOST_SEM2_REG);
303*775c7742SKrishna Gudipati 	ioc->ioc_regs.ioc_usage_reg = (rb + CT2_BFA_FW_USE_COUNT);
304*775c7742SKrishna Gudipati 	ioc->ioc_regs.ioc_fail_sync = (rb + CT2_BFA_IOC_FAIL_SYNC);
30511189208SKrishna Gudipati 
30611189208SKrishna Gudipati 	/*
30711189208SKrishna Gudipati 	 * sram memory access
30811189208SKrishna Gudipati 	 */
30911189208SKrishna Gudipati 	ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START);
31011189208SKrishna Gudipati 	ioc->ioc_regs.smem_pg0 = BFI_IOC_SMEM_PG0_CT;
31111189208SKrishna Gudipati 
31211189208SKrishna Gudipati 	/*
31311189208SKrishna Gudipati 	 * err set reg : for notification of hb failure in fcmode
31411189208SKrishna Gudipati 	 */
31511189208SKrishna Gudipati 	ioc->ioc_regs.err_set = (rb + ERR_SET_REG);
31611189208SKrishna Gudipati }
31711189208SKrishna 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 
34011189208SKrishna Gudipati static void
34111189208SKrishna Gudipati bfa_ioc_ct2_map_port(struct bfa_ioc_s *ioc)
34211189208SKrishna Gudipati {
34311189208SKrishna Gudipati 	ioc->port_id = bfa_ioc_pcifn(ioc) % 2;
34411189208SKrishna Gudipati 
34511189208SKrishna Gudipati 	bfa_trc(ioc, bfa_ioc_pcifn(ioc));
34611189208SKrishna Gudipati 	bfa_trc(ioc, ioc->port_id);
34711189208SKrishna Gudipati }
34811189208SKrishna 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 	 */
36711189208SKrishna 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 
38911189208SKrishna 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 
50011189208SKrishna Gudipati /**
50111189208SKrishna Gudipati  * Called from bfa_ioc_attach() to map asic specific calls.
502a36c61f9SKrishna Gudipati  */
50311189208SKrishna Gudipati static void
50411189208SKrishna Gudipati bfa_ioc_set_ctx_hwif(struct bfa_ioc_s *ioc, struct bfa_ioc_hwif_s *hwif)
505a36c61f9SKrishna Gudipati {
50611189208SKrishna Gudipati 	hwif->ioc_firmware_lock = bfa_ioc_ct_firmware_lock;
50711189208SKrishna Gudipati 	hwif->ioc_firmware_unlock = bfa_ioc_ct_firmware_unlock;
50811189208SKrishna Gudipati 	hwif->ioc_notify_fail = bfa_ioc_ct_notify_fail;
50911189208SKrishna Gudipati 	hwif->ioc_ownership_reset = bfa_ioc_ct_ownership_reset;
51011189208SKrishna Gudipati 	hwif->ioc_sync_start = bfa_ioc_ct_sync_start;
51111189208SKrishna Gudipati 	hwif->ioc_sync_join = bfa_ioc_ct_sync_join;
51211189208SKrishna Gudipati 	hwif->ioc_sync_leave = bfa_ioc_ct_sync_leave;
51311189208SKrishna Gudipati 	hwif->ioc_sync_ack = bfa_ioc_ct_sync_ack;
51411189208SKrishna Gudipati 	hwif->ioc_sync_complete = bfa_ioc_ct_sync_complete;
51511189208SKrishna Gudipati }
516a36c61f9SKrishna Gudipati 
51711189208SKrishna Gudipati /**
51811189208SKrishna Gudipati  * Called from bfa_ioc_attach() to map asic specific calls.
51911189208SKrishna Gudipati  */
52011189208SKrishna Gudipati void
52111189208SKrishna Gudipati bfa_ioc_set_ct_hwif(struct bfa_ioc_s *ioc)
52211189208SKrishna Gudipati {
52311189208SKrishna Gudipati 	bfa_ioc_set_ctx_hwif(ioc, &hwif_ct);
52411189208SKrishna Gudipati 
52511189208SKrishna Gudipati 	hwif_ct.ioc_pll_init = bfa_ioc_ct_pll_init;
52611189208SKrishna Gudipati 	hwif_ct.ioc_reg_init = bfa_ioc_ct_reg_init;
52711189208SKrishna Gudipati 	hwif_ct.ioc_map_port = bfa_ioc_ct_map_port;
52811189208SKrishna Gudipati 	hwif_ct.ioc_isr_mode_set = bfa_ioc_ct_isr_mode_set;
52911189208SKrishna Gudipati 	ioc->ioc_hwif = &hwif_ct;
53011189208SKrishna Gudipati }
53111189208SKrishna Gudipati 
53211189208SKrishna Gudipati /**
53311189208SKrishna Gudipati  * Called from bfa_ioc_attach() to map asic specific calls.
53411189208SKrishna Gudipati  */
53511189208SKrishna Gudipati void
53611189208SKrishna Gudipati bfa_ioc_set_ct2_hwif(struct bfa_ioc_s *ioc)
53711189208SKrishna Gudipati {
53811189208SKrishna Gudipati 	bfa_ioc_set_ctx_hwif(ioc, &hwif_ct2);
53911189208SKrishna Gudipati 
54011189208SKrishna Gudipati 	hwif_ct2.ioc_pll_init = bfa_ioc_ct2_pll_init;
54111189208SKrishna Gudipati 	hwif_ct2.ioc_reg_init = bfa_ioc_ct2_reg_init;
54211189208SKrishna Gudipati 	hwif_ct2.ioc_map_port = bfa_ioc_ct2_map_port;
54311189208SKrishna Gudipati 	hwif_ct2.ioc_isr_mode_set = NULL;
54411189208SKrishna Gudipati 	ioc->ioc_hwif = &hwif_ct2;
54511189208SKrishna Gudipati }
54611189208SKrishna Gudipati 
54711189208SKrishna Gudipati /*
54811189208SKrishna Gudipati  * Temporary workaround for MSI-X resource allocation for catapult-2.
54911189208SKrishna Gudipati  */
55011189208SKrishna Gudipati #define HOSTFN_MSIX_DEFAULT		16
55111189208SKrishna Gudipati #define HOSTFN_MSIX_VT_OFST_NUMVT	0x3013c
55211189208SKrishna Gudipati #define __MSIX_VT_NUMVT__MK		0x003ff800
55311189208SKrishna Gudipati #define __MSIX_VT_NUMVT__SH		11
55411189208SKrishna Gudipati #define __MSIX_VT_NUMVT_(_v)		((_v) << __MSIX_VT_NUMVT__SH)
55511189208SKrishna Gudipati void
55611189208SKrishna Gudipati bfa_ioc_ct2_poweron(struct bfa_ioc_s *ioc)
55711189208SKrishna Gudipati {
55811189208SKrishna Gudipati 	void __iomem *rb = ioc->pcidev.pci_bar_kva;
55911189208SKrishna Gudipati 	u32	r32;
56011189208SKrishna Gudipati 
56111189208SKrishna Gudipati 	r32 = readl(rb + HOSTFN_MSIX_VT_OFST_NUMVT);
56211189208SKrishna Gudipati 	if (r32 & __MSIX_VT_NUMVT__MK)
56311189208SKrishna Gudipati 		return;
56411189208SKrishna Gudipati 
56511189208SKrishna Gudipati 	writel(__MSIX_VT_NUMVT_(HOSTFN_MSIX_DEFAULT - 1) |
56611189208SKrishna Gudipati 		HOSTFN_MSIX_DEFAULT * bfa_ioc_pcifn(ioc),
56711189208SKrishna Gudipati 		rb + HOSTFN_MSIX_VT_OFST_NUMVT);
568a36c61f9SKrishna Gudipati }
569a36c61f9SKrishna Gudipati 
570a36c61f9SKrishna Gudipati bfa_status_t
57111189208SKrishna Gudipati bfa_ioc_ct_pll_init(void __iomem *rb, enum bfi_asic_mode mode)
572a36c61f9SKrishna Gudipati {
573a36c61f9SKrishna Gudipati 	u32	pll_sclk, pll_fclk, r32;
57411189208SKrishna Gudipati 	bfa_boolean_t fcmode = (mode == BFI_ASIC_MODE_FC);
575a36c61f9SKrishna Gudipati 
57611189208SKrishna Gudipati 	pll_sclk = __APP_PLL_SCLK_LRESETN | __APP_PLL_SCLK_ENARST |
57711189208SKrishna Gudipati 		__APP_PLL_SCLK_RSEL200500 | __APP_PLL_SCLK_P0_1(3U) |
57811189208SKrishna Gudipati 		__APP_PLL_SCLK_JITLMT0_1(3U) |
57911189208SKrishna Gudipati 		__APP_PLL_SCLK_CNTLMT0_1(1U);
58011189208SKrishna Gudipati 	pll_fclk = __APP_PLL_LCLK_LRESETN | __APP_PLL_LCLK_ENARST |
58111189208SKrishna Gudipati 		__APP_PLL_LCLK_RSEL200500 | __APP_PLL_LCLK_P0_1(3U) |
58211189208SKrishna Gudipati 		__APP_PLL_LCLK_JITLMT0_1(3U) |
58311189208SKrishna Gudipati 		__APP_PLL_LCLK_CNTLMT0_1(1U);
58411189208SKrishna 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));
60111189208SKrishna Gudipati 	writel(pll_sclk | __APP_PLL_SCLK_LOGIC_SOFT_RESET,
60211189208SKrishna Gudipati 			rb + APP_PLL_SCLK_CTL_REG);
60311189208SKrishna Gudipati 	writel(pll_fclk | __APP_PLL_LCLK_LOGIC_SOFT_RESET,
60411189208SKrishna Gudipati 			rb + APP_PLL_LCLK_CTL_REG);
60511189208SKrishna Gudipati 	writel(pll_sclk | __APP_PLL_SCLK_LOGIC_SOFT_RESET |
60611189208SKrishna Gudipati 		__APP_PLL_SCLK_ENABLE, rb + APP_PLL_SCLK_CTL_REG);
60711189208SKrishna Gudipati 	writel(pll_fclk | __APP_PLL_LCLK_LOGIC_SOFT_RESET |
60811189208SKrishna 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));
61311189208SKrishna Gudipati 	writel(pll_sclk | __APP_PLL_SCLK_ENABLE, rb + APP_PLL_SCLK_CTL_REG);
61411189208SKrishna Gudipati 	writel(pll_fclk | __APP_PLL_LCLK_ENABLE, rb + APP_PLL_LCLK_CTL_REG);
61511189208SKrishna 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 }
63511189208SKrishna Gudipati 
63611189208SKrishna Gudipati static struct { u32 sclk, speed, half_speed; } ct2_pll[] = {
63711189208SKrishna Gudipati 	{0},							/* unused */
63811189208SKrishna Gudipati 	{__APP_PLL_SCLK_CLK_DIV2, 0, 0},			/* FC 8G  */
639*775c7742SKrishna Gudipati 	{0, 0, 0},						/* FC 16G */
64011189208SKrishna Gudipati 	{__APP_PLL_SCLK_REFCLK_SEL | __APP_PLL_SCLK_CLK_DIV2, 0, /* ETH   */
64111189208SKrishna Gudipati 	__APP_LPUCLK_HALFSPEED},
642*775c7742SKrishna Gudipati 	{0, 0, 0},						/* COMBO  */
64311189208SKrishna Gudipati };
64411189208SKrishna Gudipati 
64511189208SKrishna Gudipati static void
64611189208SKrishna Gudipati bfa_ioc_ct2_sclk_init(void __iomem *rb, enum bfi_asic_mode mode)
64711189208SKrishna Gudipati {
64811189208SKrishna Gudipati 	u32 r32;
64911189208SKrishna Gudipati 
65011189208SKrishna Gudipati 	/*
65111189208SKrishna Gudipati 	 * put s_clk PLL and PLL FSM in reset
65211189208SKrishna Gudipati 	 */
65311189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG));
65411189208SKrishna Gudipati 	r32 &= ~(__APP_PLL_SCLK_ENABLE | __APP_PLL_SCLK_LRESETN);
65511189208SKrishna Gudipati 	r32 |= (__APP_PLL_SCLK_ENARST | __APP_PLL_SCLK_BYPASS |
65611189208SKrishna Gudipati 		__APP_PLL_SCLK_LOGIC_SOFT_RESET);
65711189208SKrishna Gudipati 	writel(r32, (rb + CT2_APP_PLL_SCLK_CTL_REG));
65811189208SKrishna Gudipati 
65911189208SKrishna Gudipati 	/*
66011189208SKrishna Gudipati 	 * select clock speed based on mode
66111189208SKrishna Gudipati 	 */
66211189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG));
66311189208SKrishna Gudipati 	r32 &= ~(__APP_PLL_SCLK_REFCLK_SEL | __APP_PLL_SCLK_CLK_DIV2);
66411189208SKrishna Gudipati 	writel(r32 | ct2_pll[mode].sclk, (rb + CT2_APP_PLL_SCLK_CTL_REG));
66511189208SKrishna Gudipati 
66611189208SKrishna Gudipati 	/*
667*775c7742SKrishna Gudipati 	 * while doing PLL init dont clock gate ethernet subsystem
66811189208SKrishna Gudipati 	 */
66911189208SKrishna Gudipati 	r32 = readl((rb + CT2_CHIP_MISC_PRG));
67011189208SKrishna Gudipati 	writel(r32 | __ETH_CLK_ENABLE_PORT0, (rb + CT2_CHIP_MISC_PRG));
67111189208SKrishna Gudipati 
67211189208SKrishna Gudipati 	r32 = readl((rb + CT2_PCIE_MISC_REG));
67311189208SKrishna Gudipati 	writel(r32 | __ETH_CLK_ENABLE_PORT1, (rb + CT2_PCIE_MISC_REG));
67411189208SKrishna Gudipati 
67511189208SKrishna Gudipati 	/*
67611189208SKrishna Gudipati 	 * set sclk value
67711189208SKrishna Gudipati 	 */
67811189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG));
67911189208SKrishna Gudipati 	r32 &= (__P_SCLK_PLL_LOCK | __APP_PLL_SCLK_REFCLK_SEL |
68011189208SKrishna Gudipati 		__APP_PLL_SCLK_CLK_DIV2);
68111189208SKrishna Gudipati 	writel(r32 | 0x1061731b, (rb + CT2_APP_PLL_SCLK_CTL_REG));
68211189208SKrishna Gudipati 
68311189208SKrishna Gudipati 	/*
68411189208SKrishna Gudipati 	 * poll for s_clk lock or delay 1ms
68511189208SKrishna Gudipati 	 */
68611189208SKrishna Gudipati 	udelay(1000);
68711189208SKrishna Gudipati 
68811189208SKrishna Gudipati 	/*
68911189208SKrishna Gudipati 	 * release soft reset on s_clk & l_clk
69011189208SKrishna Gudipati 	 */
69111189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG));
69211189208SKrishna Gudipati 	writel(r32 & ~__APP_PLL_SCLK_LOGIC_SOFT_RESET,
69311189208SKrishna Gudipati 		(rb + CT2_APP_PLL_SCLK_CTL_REG));
694*775c7742SKrishna Gudipati 
695*775c7742SKrishna Gudipati 	/*
696*775c7742SKrishna Gudipati 	 * clock gating for ethernet subsystem if not in ethernet mode
697*775c7742SKrishna Gudipati 	 */
698*775c7742SKrishna Gudipati 	if (mode != BFI_ASIC_MODE_ETH) {
699*775c7742SKrishna Gudipati 		r32 = readl((rb + CT2_CHIP_MISC_PRG));
700*775c7742SKrishna Gudipati 		writel(r32 & ~__ETH_CLK_ENABLE_PORT0,
701*775c7742SKrishna Gudipati 			(rb + CT2_CHIP_MISC_PRG));
702*775c7742SKrishna Gudipati 
703*775c7742SKrishna Gudipati 		r32 = readl((rb + CT2_PCIE_MISC_REG));
704*775c7742SKrishna Gudipati 		writel(r32 & ~__ETH_CLK_ENABLE_PORT1,
705*775c7742SKrishna Gudipati 			(rb + CT2_PCIE_MISC_REG));
706*775c7742SKrishna Gudipati 	}
70711189208SKrishna Gudipati }
70811189208SKrishna Gudipati 
70911189208SKrishna Gudipati static void
71011189208SKrishna Gudipati bfa_ioc_ct2_lclk_init(void __iomem *rb, enum bfi_asic_mode mode)
71111189208SKrishna Gudipati {
71211189208SKrishna Gudipati 	u32 r32;
71311189208SKrishna Gudipati 
71411189208SKrishna Gudipati 	/*
71511189208SKrishna Gudipati 	 * put l_clk PLL and PLL FSM in reset
71611189208SKrishna Gudipati 	 */
71711189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG));
71811189208SKrishna Gudipati 	r32 &= ~(__APP_PLL_LCLK_ENABLE | __APP_PLL_LCLK_LRESETN);
71911189208SKrishna Gudipati 	r32 |= (__APP_PLL_LCLK_ENARST | __APP_PLL_LCLK_BYPASS |
72011189208SKrishna Gudipati 		__APP_PLL_LCLK_LOGIC_SOFT_RESET);
72111189208SKrishna Gudipati 	writel(r32, (rb + CT2_APP_PLL_LCLK_CTL_REG));
72211189208SKrishna Gudipati 
72311189208SKrishna Gudipati 	/*
72411189208SKrishna Gudipati 	 * set LPU speed
72511189208SKrishna Gudipati 	 */
72611189208SKrishna Gudipati 	r32 = readl((rb + CT2_CHIP_MISC_PRG));
72711189208SKrishna Gudipati 	writel(r32 | ct2_pll[mode].speed,
72811189208SKrishna Gudipati 		(rb + CT2_CHIP_MISC_PRG));
72911189208SKrishna Gudipati 
73011189208SKrishna Gudipati 	/*
73111189208SKrishna Gudipati 	 * set LPU half speed
73211189208SKrishna Gudipati 	 */
73311189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG));
73411189208SKrishna Gudipati 	writel(r32 | ct2_pll[mode].half_speed,
73511189208SKrishna Gudipati 		(rb + CT2_APP_PLL_LCLK_CTL_REG));
73611189208SKrishna Gudipati 
73711189208SKrishna Gudipati 	/*
73811189208SKrishna Gudipati 	 * set lclk for mode
73911189208SKrishna Gudipati 	 */
74011189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG));
74111189208SKrishna Gudipati 	r32 &= (__P_LCLK_PLL_LOCK | __APP_LPUCLK_HALFSPEED);
742*775c7742SKrishna Gudipati 	 if (mode == BFI_ASIC_MODE_FC || mode == BFI_ASIC_MODE_FC16 ||
743*775c7742SKrishna Gudipati 	     mode == BFI_ASIC_MODE_ETH)
74411189208SKrishna Gudipati 		r32 |= 0x20c1731b;
74511189208SKrishna Gudipati 	else
74611189208SKrishna Gudipati 		r32 |= 0x2081731b;
74711189208SKrishna Gudipati 	writel(r32, (rb + CT2_APP_PLL_LCLK_CTL_REG));
74811189208SKrishna Gudipati 
74911189208SKrishna Gudipati 	/*
75011189208SKrishna Gudipati 	 * poll for s_clk lock or delay 1ms
75111189208SKrishna Gudipati 	 */
75211189208SKrishna Gudipati 	udelay(1000);
75311189208SKrishna Gudipati 
75411189208SKrishna Gudipati 	/*
75511189208SKrishna Gudipati 	 * release soft reset on s_clk & l_clk
75611189208SKrishna Gudipati 	 */
75711189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG));
75811189208SKrishna Gudipati 	writel(r32 & ~__APP_PLL_LCLK_LOGIC_SOFT_RESET,
75911189208SKrishna Gudipati 		(rb + CT2_APP_PLL_LCLK_CTL_REG));
76011189208SKrishna Gudipati }
76111189208SKrishna Gudipati 
76211189208SKrishna Gudipati static void
76311189208SKrishna Gudipati bfa_ioc_ct2_mem_init(void __iomem *rb, enum bfi_asic_mode mode)
76411189208SKrishna Gudipati {
76511189208SKrishna Gudipati 	bfa_boolean_t fcmode;
76611189208SKrishna Gudipati 	u32	r32;
76711189208SKrishna Gudipati 
76811189208SKrishna Gudipati 	fcmode = (mode == BFI_ASIC_MODE_FC) || (mode == BFI_ASIC_MODE_FC16);
76911189208SKrishna Gudipati 	if (!fcmode) {
770*775c7742SKrishna Gudipati 		writel(__PMM_1T_PNDB_P | __PMM_1T_RESET_P,
771*775c7742SKrishna Gudipati 			(rb + CT2_PMM_1T_CONTROL_REG_P0));
772*775c7742SKrishna Gudipati 		writel(__PMM_1T_PNDB_P | __PMM_1T_RESET_P,
773*775c7742SKrishna Gudipati 			(rb + CT2_PMM_1T_CONTROL_REG_P1));
77411189208SKrishna Gudipati 	}
77511189208SKrishna Gudipati 
77611189208SKrishna Gudipati 	r32 = readl((rb + PSS_CTL_REG));
77711189208SKrishna Gudipati 	r32 &= ~__PSS_LMEM_RESET;
77811189208SKrishna Gudipati 	writel(r32, (rb + PSS_CTL_REG));
77911189208SKrishna Gudipati 	udelay(1000);
78011189208SKrishna Gudipati 
781*775c7742SKrishna Gudipati 	if (!fcmode) {
782*775c7742SKrishna Gudipati 		writel(__PMM_1T_PNDB_P, (rb + CT2_PMM_1T_CONTROL_REG_P0));
783*775c7742SKrishna Gudipati 		writel(__PMM_1T_PNDB_P, (rb + CT2_PMM_1T_CONTROL_REG_P1));
784*775c7742SKrishna Gudipati 	}
785*775c7742SKrishna Gudipati 
78611189208SKrishna Gudipati 	writel(__EDRAM_BISTR_START, (rb + CT2_MBIST_CTL_REG));
78711189208SKrishna Gudipati 	udelay(1000);
78811189208SKrishna Gudipati 	writel(0, (rb + CT2_MBIST_CTL_REG));
78911189208SKrishna Gudipati }
79011189208SKrishna Gudipati 
79111189208SKrishna Gudipati bfa_status_t
79211189208SKrishna Gudipati bfa_ioc_ct2_pll_init(void __iomem *rb, enum bfi_asic_mode mode)
79311189208SKrishna Gudipati {
79411189208SKrishna Gudipati 	bfa_ioc_ct2_sclk_init(rb, mode);
79511189208SKrishna Gudipati 	bfa_ioc_ct2_lclk_init(rb, mode);
79611189208SKrishna Gudipati 	bfa_ioc_ct2_mem_init(rb, mode);
79711189208SKrishna Gudipati 
798*775c7742SKrishna Gudipati 	/*
799*775c7742SKrishna Gudipati 	 * Disable flash presence to NFC by clearing GPIO 0
800*775c7742SKrishna Gudipati 	 */
801*775c7742SKrishna Gudipati 	writel(0, (rb + PSS_GPIO_OUT_REG));
802*775c7742SKrishna Gudipati 	writel(1, (rb + PSS_GPIO_OE_REG));
803*775c7742SKrishna Gudipati 
80411189208SKrishna Gudipati 	writel(BFI_IOC_UNINIT, (rb + CT2_BFA_IOC0_STATE_REG));
80511189208SKrishna Gudipati 	writel(BFI_IOC_UNINIT, (rb + CT2_BFA_IOC1_STATE_REG));
80611189208SKrishna Gudipati 	return BFA_STATUS_OK;
80711189208SKrishna Gudipati }
808