xref: /openbmc/linux/drivers/scsi/bfa/bfa_ioc_ct.c (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
152fa7bf9SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
20a20de44SKrishna Gudipati /*
3889d0d42SAnil Gurumurthy  * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
4889d0d42SAnil Gurumurthy  * Copyright (c) 2014- QLogic Corporation.
50a20de44SKrishna Gudipati  * All rights reserved
6889d0d42SAnil Gurumurthy  * www.qlogic.com
70a20de44SKrishna Gudipati  *
831e1d569SAnil Gurumurthy  * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
90a20de44SKrishna Gudipati  */
100a20de44SKrishna Gudipati 
11f16a1750SMaggie Zhang #include "bfad_drv.h"
12a36c61f9SKrishna Gudipati #include "bfa_ioc.h"
1311189208SKrishna Gudipati #include "bfi_reg.h"
14a36c61f9SKrishna Gudipati #include "bfa_defs.h"
150a20de44SKrishna Gudipati 
160a20de44SKrishna Gudipati BFA_TRC_FILE(CNA, IOC_CT);
170a20de44SKrishna Gudipati 
18f1d584d7SKrishna Gudipati #define bfa_ioc_ct_sync_pos(__ioc)      \
19f1d584d7SKrishna Gudipati 		((uint32_t) (1 << bfa_ioc_pcifn(__ioc)))
20f1d584d7SKrishna Gudipati #define BFA_IOC_SYNC_REQD_SH    16
21f1d584d7SKrishna Gudipati #define bfa_ioc_ct_get_sync_ackd(__val) (__val & 0x0000ffff)
22f1d584d7SKrishna Gudipati #define bfa_ioc_ct_clear_sync_ackd(__val)       (__val & 0xffff0000)
23f1d584d7SKrishna Gudipati #define bfa_ioc_ct_get_sync_reqd(__val) (__val >> BFA_IOC_SYNC_REQD_SH)
24f1d584d7SKrishna Gudipati #define bfa_ioc_ct_sync_reqd_pos(__ioc) \
25f1d584d7SKrishna Gudipati 			(bfa_ioc_ct_sync_pos(__ioc) << BFA_IOC_SYNC_REQD_SH)
26f1d584d7SKrishna Gudipati 
270a20de44SKrishna Gudipati /*
280a20de44SKrishna Gudipati  * forward declarations
290a20de44SKrishna Gudipati  */
300a20de44SKrishna Gudipati static bfa_boolean_t bfa_ioc_ct_firmware_lock(struct bfa_ioc_s *ioc);
310a20de44SKrishna Gudipati static void bfa_ioc_ct_firmware_unlock(struct bfa_ioc_s *ioc);
32f1d584d7SKrishna Gudipati static void bfa_ioc_ct_notify_fail(struct bfa_ioc_s *ioc);
330a20de44SKrishna Gudipati static void bfa_ioc_ct_ownership_reset(struct bfa_ioc_s *ioc);
3445d7f0ccSJing Huang static bfa_boolean_t bfa_ioc_ct_sync_start(struct bfa_ioc_s *ioc);
35f1d584d7SKrishna Gudipati static void bfa_ioc_ct_sync_join(struct bfa_ioc_s *ioc);
36f1d584d7SKrishna Gudipati static void bfa_ioc_ct_sync_leave(struct bfa_ioc_s *ioc);
37f1d584d7SKrishna Gudipati static void bfa_ioc_ct_sync_ack(struct bfa_ioc_s *ioc);
38f1d584d7SKrishna Gudipati static bfa_boolean_t bfa_ioc_ct_sync_complete(struct bfa_ioc_s *ioc);
39c679b599SVijaya Mohan Guvva static void bfa_ioc_ct_set_cur_ioc_fwstate(
40c679b599SVijaya Mohan Guvva 			struct bfa_ioc_s *ioc, enum bfi_ioc_state fwstate);
41c679b599SVijaya Mohan Guvva static enum bfi_ioc_state bfa_ioc_ct_get_cur_ioc_fwstate(struct bfa_ioc_s *ioc);
42c679b599SVijaya Mohan Guvva static void bfa_ioc_ct_set_alt_ioc_fwstate(
43c679b599SVijaya Mohan Guvva 			struct bfa_ioc_s *ioc, enum bfi_ioc_state fwstate);
44c679b599SVijaya Mohan Guvva static enum bfi_ioc_state bfa_ioc_ct_get_alt_ioc_fwstate(struct bfa_ioc_s *ioc);
450a20de44SKrishna Gudipati 
4652f94b6fSMaggie static struct bfa_ioc_hwif_s hwif_ct;
4711189208SKrishna Gudipati static struct bfa_ioc_hwif_s hwif_ct2;
480a20de44SKrishna Gudipati 
495fbe25c7SJing Huang /*
500a20de44SKrishna Gudipati  * Return true if firmware of current driver matches the running firmware.
510a20de44SKrishna Gudipati  */
520a20de44SKrishna Gudipati static bfa_boolean_t
bfa_ioc_ct_firmware_lock(struct bfa_ioc_s * ioc)530a20de44SKrishna Gudipati bfa_ioc_ct_firmware_lock(struct bfa_ioc_s *ioc)
540a20de44SKrishna Gudipati {
550a20de44SKrishna Gudipati 	enum bfi_ioc_state ioc_fwstate;
56d1c61f8eSKrishna Gudipati 	u32 usecnt;
570a20de44SKrishna Gudipati 	struct bfi_ioc_image_hdr_s fwhdr;
580a20de44SKrishna Gudipati 
590a20de44SKrishna Gudipati 	bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg);
6053440260SJing Huang 	usecnt = readl(ioc->ioc_regs.ioc_usage_reg);
610a20de44SKrishna Gudipati 
625fbe25c7SJing Huang 	/*
630a20de44SKrishna Gudipati 	 * If usage count is 0, always return TRUE.
640a20de44SKrishna Gudipati 	 */
650a20de44SKrishna Gudipati 	if (usecnt == 0) {
6653440260SJing Huang 		writel(1, ioc->ioc_regs.ioc_usage_reg);
675a0adaedSKrishna Gudipati 		readl(ioc->ioc_regs.ioc_usage_sem_reg);
68f7f73812SMaggie Zhang 		writel(1, ioc->ioc_regs.ioc_usage_sem_reg);
69f1d584d7SKrishna Gudipati 		writel(0, ioc->ioc_regs.ioc_fail_sync);
700a20de44SKrishna Gudipati 		bfa_trc(ioc, usecnt);
710a20de44SKrishna Gudipati 		return BFA_TRUE;
720a20de44SKrishna Gudipati 	}
730a20de44SKrishna Gudipati 
7453440260SJing Huang 	ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
750a20de44SKrishna Gudipati 	bfa_trc(ioc, ioc_fwstate);
760a20de44SKrishna Gudipati 
775fbe25c7SJing Huang 	/*
780a20de44SKrishna Gudipati 	 * Use count cannot be non-zero and chip in uninitialized state.
790a20de44SKrishna Gudipati 	 */
80d4b671c5SJing Huang 	WARN_ON(ioc_fwstate == BFI_IOC_UNINIT);
810a20de44SKrishna Gudipati 
825fbe25c7SJing Huang 	/*
830a20de44SKrishna Gudipati 	 * Check if another driver with a different firmware is active
840a20de44SKrishna Gudipati 	 */
850a20de44SKrishna Gudipati 	bfa_ioc_fwver_get(ioc, &fwhdr);
860a20de44SKrishna Gudipati 	if (!bfa_ioc_fwver_cmp(ioc, &fwhdr)) {
875a0adaedSKrishna Gudipati 		readl(ioc->ioc_regs.ioc_usage_sem_reg);
88f7f73812SMaggie Zhang 		writel(1, ioc->ioc_regs.ioc_usage_sem_reg);
890a20de44SKrishna Gudipati 		bfa_trc(ioc, usecnt);
900a20de44SKrishna Gudipati 		return BFA_FALSE;
910a20de44SKrishna Gudipati 	}
920a20de44SKrishna Gudipati 
935fbe25c7SJing Huang 	/*
940a20de44SKrishna Gudipati 	 * Same firmware version. Increment the reference count.
950a20de44SKrishna Gudipati 	 */
960a20de44SKrishna Gudipati 	usecnt++;
9753440260SJing Huang 	writel(usecnt, ioc->ioc_regs.ioc_usage_reg);
985a0adaedSKrishna Gudipati 	readl(ioc->ioc_regs.ioc_usage_sem_reg);
99f7f73812SMaggie Zhang 	writel(1, ioc->ioc_regs.ioc_usage_sem_reg);
1000a20de44SKrishna Gudipati 	bfa_trc(ioc, usecnt);
1010a20de44SKrishna Gudipati 	return BFA_TRUE;
1020a20de44SKrishna Gudipati }
1030a20de44SKrishna Gudipati 
1040a20de44SKrishna Gudipati static void
bfa_ioc_ct_firmware_unlock(struct bfa_ioc_s * ioc)1050a20de44SKrishna Gudipati bfa_ioc_ct_firmware_unlock(struct bfa_ioc_s *ioc)
1060a20de44SKrishna Gudipati {
107d1c61f8eSKrishna Gudipati 	u32 usecnt;
1080a20de44SKrishna Gudipati 
1095fbe25c7SJing Huang 	/*
1100a20de44SKrishna Gudipati 	 * decrement usage count
1110a20de44SKrishna Gudipati 	 */
1120a20de44SKrishna Gudipati 	bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg);
11353440260SJing Huang 	usecnt = readl(ioc->ioc_regs.ioc_usage_reg);
114d4b671c5SJing Huang 	WARN_ON(usecnt <= 0);
1150a20de44SKrishna Gudipati 
1160a20de44SKrishna Gudipati 	usecnt--;
11753440260SJing Huang 	writel(usecnt, ioc->ioc_regs.ioc_usage_reg);
1180a20de44SKrishna Gudipati 	bfa_trc(ioc, usecnt);
1190a20de44SKrishna Gudipati 
1205a0adaedSKrishna Gudipati 	readl(ioc->ioc_regs.ioc_usage_sem_reg);
121f7f73812SMaggie Zhang 	writel(1, ioc->ioc_regs.ioc_usage_sem_reg);
1220a20de44SKrishna Gudipati }
1230a20de44SKrishna Gudipati 
1245fbe25c7SJing Huang /*
1250a20de44SKrishna Gudipati  * Notify other functions on HB failure.
1260a20de44SKrishna Gudipati  */
1270a20de44SKrishna Gudipati static void
bfa_ioc_ct_notify_fail(struct bfa_ioc_s * ioc)128f1d584d7SKrishna Gudipati bfa_ioc_ct_notify_fail(struct bfa_ioc_s *ioc)
1290a20de44SKrishna Gudipati {
13011189208SKrishna Gudipati 	if (bfa_ioc_is_cna(ioc)) {
13153440260SJing Huang 		writel(__FW_INIT_HALT_P, ioc->ioc_regs.ll_halt);
132f1d584d7SKrishna Gudipati 		writel(__FW_INIT_HALT_P, ioc->ioc_regs.alt_ll_halt);
1330a20de44SKrishna Gudipati 		/* Wait for halt to take effect */
13453440260SJing Huang 		readl(ioc->ioc_regs.ll_halt);
135f1d584d7SKrishna Gudipati 		readl(ioc->ioc_regs.alt_ll_halt);
136816e49b8SKrishna Gudipati 	} else {
13711189208SKrishna Gudipati 		writel(~0U, ioc->ioc_regs.err_set);
13853440260SJing Huang 		readl(ioc->ioc_regs.err_set);
139816e49b8SKrishna Gudipati 	}
1400a20de44SKrishna Gudipati }
1410a20de44SKrishna Gudipati 
1425fbe25c7SJing Huang /*
1430a20de44SKrishna Gudipati  * Host to LPU mailbox message addresses
1440a20de44SKrishna Gudipati  */
14511189208SKrishna Gudipati static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } ct_fnreg[] = {
1460a20de44SKrishna Gudipati 	{ HOSTFN0_LPU_MBOX0_0, LPU_HOSTFN0_MBOX0_0, HOST_PAGE_NUM_FN0 },
1470a20de44SKrishna Gudipati 	{ HOSTFN1_LPU_MBOX0_8, LPU_HOSTFN1_MBOX0_8, HOST_PAGE_NUM_FN1 },
1480a20de44SKrishna Gudipati 	{ HOSTFN2_LPU_MBOX0_0, LPU_HOSTFN2_MBOX0_0, HOST_PAGE_NUM_FN2 },
1490a20de44SKrishna Gudipati 	{ HOSTFN3_LPU_MBOX0_8, LPU_HOSTFN3_MBOX0_8, HOST_PAGE_NUM_FN3 }
1500a20de44SKrishna Gudipati };
1510a20de44SKrishna Gudipati 
1525fbe25c7SJing Huang /*
1530a20de44SKrishna Gudipati  * Host <-> LPU mailbox command/status registers - port 0
1540a20de44SKrishna Gudipati  */
15511189208SKrishna Gudipati static struct { u32 hfn, lpu; } ct_p0reg[] = {
15611189208SKrishna Gudipati 	{ HOSTFN0_LPU0_CMD_STAT, LPU0_HOSTFN0_CMD_STAT },
15711189208SKrishna Gudipati 	{ HOSTFN1_LPU0_CMD_STAT, LPU0_HOSTFN1_CMD_STAT },
15811189208SKrishna Gudipati 	{ HOSTFN2_LPU0_CMD_STAT, LPU0_HOSTFN2_CMD_STAT },
15911189208SKrishna Gudipati 	{ HOSTFN3_LPU0_CMD_STAT, LPU0_HOSTFN3_CMD_STAT }
1600a20de44SKrishna Gudipati };
1610a20de44SKrishna Gudipati 
1625fbe25c7SJing Huang /*
1630a20de44SKrishna Gudipati  * Host <-> LPU mailbox command/status registers - port 1
1640a20de44SKrishna Gudipati  */
16511189208SKrishna Gudipati static struct { u32 hfn, lpu; } ct_p1reg[] = {
16611189208SKrishna Gudipati 	{ HOSTFN0_LPU1_CMD_STAT, LPU1_HOSTFN0_CMD_STAT },
16711189208SKrishna Gudipati 	{ HOSTFN1_LPU1_CMD_STAT, LPU1_HOSTFN1_CMD_STAT },
16811189208SKrishna Gudipati 	{ HOSTFN2_LPU1_CMD_STAT, LPU1_HOSTFN2_CMD_STAT },
16911189208SKrishna Gudipati 	{ HOSTFN3_LPU1_CMD_STAT, LPU1_HOSTFN3_CMD_STAT }
17011189208SKrishna Gudipati };
17111189208SKrishna Gudipati 
1728b070b4aSKrishna Gudipati static struct { uint32_t hfn_mbox, lpu_mbox, hfn_pgn, hfn, lpu, lpu_read; }
1738b070b4aSKrishna Gudipati 	ct2_reg[] = {
17411189208SKrishna Gudipati 	{ CT2_HOSTFN_LPU0_MBOX0, CT2_LPU0_HOSTFN_MBOX0, CT2_HOSTFN_PAGE_NUM,
1758b070b4aSKrishna Gudipati 	  CT2_HOSTFN_LPU0_CMD_STAT, CT2_LPU0_HOSTFN_CMD_STAT,
1768b070b4aSKrishna Gudipati 	  CT2_HOSTFN_LPU0_READ_STAT},
17711189208SKrishna Gudipati 	{ CT2_HOSTFN_LPU1_MBOX0, CT2_LPU1_HOSTFN_MBOX0, CT2_HOSTFN_PAGE_NUM,
1788b070b4aSKrishna Gudipati 	  CT2_HOSTFN_LPU1_CMD_STAT, CT2_LPU1_HOSTFN_CMD_STAT,
1798b070b4aSKrishna Gudipati 	  CT2_HOSTFN_LPU1_READ_STAT},
1800a20de44SKrishna Gudipati };
1810a20de44SKrishna Gudipati 
1820a20de44SKrishna Gudipati static void
bfa_ioc_ct_reg_init(struct bfa_ioc_s * ioc)1830a20de44SKrishna Gudipati bfa_ioc_ct_reg_init(struct bfa_ioc_s *ioc)
1840a20de44SKrishna Gudipati {
18553440260SJing Huang 	void __iomem *rb;
1860a20de44SKrishna Gudipati 	int		pcifn = bfa_ioc_pcifn(ioc);
1870a20de44SKrishna Gudipati 
1880a20de44SKrishna Gudipati 	rb = bfa_ioc_bar0(ioc);
1890a20de44SKrishna Gudipati 
19011189208SKrishna Gudipati 	ioc->ioc_regs.hfn_mbox = rb + ct_fnreg[pcifn].hfn_mbox;
19111189208SKrishna Gudipati 	ioc->ioc_regs.lpu_mbox = rb + ct_fnreg[pcifn].lpu_mbox;
19211189208SKrishna Gudipati 	ioc->ioc_regs.host_page_num_fn = rb + ct_fnreg[pcifn].hfn_pgn;
1930a20de44SKrishna Gudipati 
1940a20de44SKrishna Gudipati 	if (ioc->port_id == 0) {
1950a20de44SKrishna Gudipati 		ioc->ioc_regs.heartbeat = rb + BFA_IOC0_HBEAT_REG;
1960a20de44SKrishna Gudipati 		ioc->ioc_regs.ioc_fwstate = rb + BFA_IOC0_STATE_REG;
197f1d584d7SKrishna Gudipati 		ioc->ioc_regs.alt_ioc_fwstate = rb + BFA_IOC1_STATE_REG;
19811189208SKrishna Gudipati 		ioc->ioc_regs.hfn_mbox_cmd = rb + ct_p0reg[pcifn].hfn;
19911189208SKrishna Gudipati 		ioc->ioc_regs.lpu_mbox_cmd = rb + ct_p0reg[pcifn].lpu;
2000a20de44SKrishna Gudipati 		ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P0;
201f1d584d7SKrishna Gudipati 		ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P1;
2020a20de44SKrishna Gudipati 	} else {
2030a20de44SKrishna Gudipati 		ioc->ioc_regs.heartbeat = (rb + BFA_IOC1_HBEAT_REG);
2040a20de44SKrishna Gudipati 		ioc->ioc_regs.ioc_fwstate = (rb + BFA_IOC1_STATE_REG);
205f1d584d7SKrishna Gudipati 		ioc->ioc_regs.alt_ioc_fwstate = rb + BFA_IOC0_STATE_REG;
20611189208SKrishna Gudipati 		ioc->ioc_regs.hfn_mbox_cmd = rb + ct_p1reg[pcifn].hfn;
20711189208SKrishna Gudipati 		ioc->ioc_regs.lpu_mbox_cmd = rb + ct_p1reg[pcifn].lpu;
2080a20de44SKrishna Gudipati 		ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P1;
209f1d584d7SKrishna Gudipati 		ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P0;
2100a20de44SKrishna Gudipati 	}
2110a20de44SKrishna Gudipati 
2120a20de44SKrishna Gudipati 	/*
2130a20de44SKrishna Gudipati 	 * PSS control registers
2140a20de44SKrishna Gudipati 	 */
2150a20de44SKrishna Gudipati 	ioc->ioc_regs.pss_ctl_reg = (rb + PSS_CTL_REG);
2168b651b42SKrishna Gudipati 	ioc->ioc_regs.pss_err_status_reg = (rb + PSS_ERR_STATUS_REG);
21711189208SKrishna Gudipati 	ioc->ioc_regs.app_pll_fast_ctl_reg = (rb + APP_PLL_LCLK_CTL_REG);
21811189208SKrishna Gudipati 	ioc->ioc_regs.app_pll_slow_ctl_reg = (rb + APP_PLL_SCLK_CTL_REG);
2190a20de44SKrishna Gudipati 
2200a20de44SKrishna Gudipati 	/*
2210a20de44SKrishna Gudipati 	 * IOC semaphore registers and serialization
2220a20de44SKrishna Gudipati 	 */
2230a20de44SKrishna Gudipati 	ioc->ioc_regs.ioc_sem_reg = (rb + HOST_SEM0_REG);
2240a20de44SKrishna Gudipati 	ioc->ioc_regs.ioc_usage_sem_reg = (rb + HOST_SEM1_REG);
2250a20de44SKrishna Gudipati 	ioc->ioc_regs.ioc_init_sem_reg = (rb + HOST_SEM2_REG);
2260a20de44SKrishna Gudipati 	ioc->ioc_regs.ioc_usage_reg = (rb + BFA_FW_USE_COUNT);
227f1d584d7SKrishna Gudipati 	ioc->ioc_regs.ioc_fail_sync = (rb + BFA_IOC_FAIL_SYNC);
2280a20de44SKrishna Gudipati 
2295fbe25c7SJing Huang 	/*
2300a20de44SKrishna Gudipati 	 * sram memory access
2310a20de44SKrishna Gudipati 	 */
2320a20de44SKrishna Gudipati 	ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START);
2330a20de44SKrishna Gudipati 	ioc->ioc_regs.smem_pg0 = BFI_IOC_SMEM_PG0_CT;
234816e49b8SKrishna Gudipati 
235816e49b8SKrishna Gudipati 	/*
236816e49b8SKrishna Gudipati 	 * err set reg : for notification of hb failure in fcmode
237816e49b8SKrishna Gudipati 	 */
238816e49b8SKrishna Gudipati 	ioc->ioc_regs.err_set = (rb + ERR_SET_REG);
2390a20de44SKrishna Gudipati }
2400a20de44SKrishna Gudipati 
24111189208SKrishna Gudipati static void
bfa_ioc_ct2_reg_init(struct bfa_ioc_s * ioc)24211189208SKrishna Gudipati bfa_ioc_ct2_reg_init(struct bfa_ioc_s *ioc)
24311189208SKrishna Gudipati {
24411189208SKrishna Gudipati 	void __iomem *rb;
24511189208SKrishna Gudipati 	int	port = bfa_ioc_portid(ioc);
24611189208SKrishna Gudipati 
24711189208SKrishna Gudipati 	rb = bfa_ioc_bar0(ioc);
24811189208SKrishna Gudipati 
24911189208SKrishna Gudipati 	ioc->ioc_regs.hfn_mbox = rb + ct2_reg[port].hfn_mbox;
25011189208SKrishna Gudipati 	ioc->ioc_regs.lpu_mbox = rb + ct2_reg[port].lpu_mbox;
25111189208SKrishna Gudipati 	ioc->ioc_regs.host_page_num_fn = rb + ct2_reg[port].hfn_pgn;
25211189208SKrishna Gudipati 	ioc->ioc_regs.hfn_mbox_cmd = rb + ct2_reg[port].hfn;
25311189208SKrishna Gudipati 	ioc->ioc_regs.lpu_mbox_cmd = rb + ct2_reg[port].lpu;
2548b070b4aSKrishna Gudipati 	ioc->ioc_regs.lpu_read_stat = rb + ct2_reg[port].lpu_read;
25511189208SKrishna Gudipati 
25611189208SKrishna Gudipati 	if (port == 0) {
25711189208SKrishna Gudipati 		ioc->ioc_regs.heartbeat = rb + CT2_BFA_IOC0_HBEAT_REG;
25811189208SKrishna Gudipati 		ioc->ioc_regs.ioc_fwstate = rb + CT2_BFA_IOC0_STATE_REG;
25911189208SKrishna Gudipati 		ioc->ioc_regs.alt_ioc_fwstate = rb + CT2_BFA_IOC1_STATE_REG;
26011189208SKrishna Gudipati 		ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P0;
26111189208SKrishna Gudipati 		ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P1;
26211189208SKrishna Gudipati 	} else {
26311189208SKrishna Gudipati 		ioc->ioc_regs.heartbeat = (rb + CT2_BFA_IOC1_HBEAT_REG);
26411189208SKrishna Gudipati 		ioc->ioc_regs.ioc_fwstate = (rb + CT2_BFA_IOC1_STATE_REG);
26511189208SKrishna Gudipati 		ioc->ioc_regs.alt_ioc_fwstate = rb + CT2_BFA_IOC0_STATE_REG;
26611189208SKrishna Gudipati 		ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P1;
26711189208SKrishna Gudipati 		ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P0;
26811189208SKrishna Gudipati 	}
26911189208SKrishna Gudipati 
27011189208SKrishna Gudipati 	/*
27111189208SKrishna Gudipati 	 * PSS control registers
27211189208SKrishna Gudipati 	 */
27311189208SKrishna Gudipati 	ioc->ioc_regs.pss_ctl_reg = (rb + PSS_CTL_REG);
27411189208SKrishna Gudipati 	ioc->ioc_regs.pss_err_status_reg = (rb + PSS_ERR_STATUS_REG);
27511189208SKrishna Gudipati 	ioc->ioc_regs.app_pll_fast_ctl_reg = (rb + CT2_APP_PLL_LCLK_CTL_REG);
27611189208SKrishna Gudipati 	ioc->ioc_regs.app_pll_slow_ctl_reg = (rb + CT2_APP_PLL_SCLK_CTL_REG);
27711189208SKrishna Gudipati 
27811189208SKrishna Gudipati 	/*
27911189208SKrishna Gudipati 	 * IOC semaphore registers and serialization
28011189208SKrishna Gudipati 	 */
28111189208SKrishna Gudipati 	ioc->ioc_regs.ioc_sem_reg = (rb + CT2_HOST_SEM0_REG);
28211189208SKrishna Gudipati 	ioc->ioc_regs.ioc_usage_sem_reg = (rb + CT2_HOST_SEM1_REG);
28311189208SKrishna Gudipati 	ioc->ioc_regs.ioc_init_sem_reg = (rb + CT2_HOST_SEM2_REG);
284775c7742SKrishna Gudipati 	ioc->ioc_regs.ioc_usage_reg = (rb + CT2_BFA_FW_USE_COUNT);
285775c7742SKrishna Gudipati 	ioc->ioc_regs.ioc_fail_sync = (rb + CT2_BFA_IOC_FAIL_SYNC);
28611189208SKrishna Gudipati 
28711189208SKrishna Gudipati 	/*
28811189208SKrishna Gudipati 	 * sram memory access
28911189208SKrishna Gudipati 	 */
29011189208SKrishna Gudipati 	ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START);
29111189208SKrishna Gudipati 	ioc->ioc_regs.smem_pg0 = BFI_IOC_SMEM_PG0_CT;
29211189208SKrishna Gudipati 
29311189208SKrishna Gudipati 	/*
29411189208SKrishna Gudipati 	 * err set reg : for notification of hb failure in fcmode
29511189208SKrishna Gudipati 	 */
29611189208SKrishna Gudipati 	ioc->ioc_regs.err_set = (rb + ERR_SET_REG);
29711189208SKrishna Gudipati }
29811189208SKrishna Gudipati 
2995fbe25c7SJing Huang /*
3000a20de44SKrishna Gudipati  * Initialize IOC to port mapping.
3010a20de44SKrishna Gudipati  */
3020a20de44SKrishna Gudipati 
3030a20de44SKrishna Gudipati #define FNC_PERS_FN_SHIFT(__fn)	((__fn) * 8)
3040a20de44SKrishna Gudipati static void
bfa_ioc_ct_map_port(struct bfa_ioc_s * ioc)3050a20de44SKrishna Gudipati bfa_ioc_ct_map_port(struct bfa_ioc_s *ioc)
3060a20de44SKrishna Gudipati {
30753440260SJing Huang 	void __iomem *rb = ioc->pcidev.pci_bar_kva;
308d1c61f8eSKrishna Gudipati 	u32	r32;
3090a20de44SKrishna Gudipati 
3105fbe25c7SJing Huang 	/*
3110a20de44SKrishna Gudipati 	 * For catapult, base port id on personality register and IOC type
3120a20de44SKrishna Gudipati 	 */
31353440260SJing Huang 	r32 = readl(rb + FNC_PERS_REG);
3140a20de44SKrishna Gudipati 	r32 >>= FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc));
3150a20de44SKrishna Gudipati 	ioc->port_id = (r32 & __F0_PORT_MAP_MK) >> __F0_PORT_MAP_SH;
3160a20de44SKrishna Gudipati 
3170a20de44SKrishna Gudipati 	bfa_trc(ioc, bfa_ioc_pcifn(ioc));
3180a20de44SKrishna Gudipati 	bfa_trc(ioc, ioc->port_id);
3190a20de44SKrishna Gudipati }
3200a20de44SKrishna Gudipati 
32111189208SKrishna Gudipati static void
bfa_ioc_ct2_map_port(struct bfa_ioc_s * ioc)32211189208SKrishna Gudipati bfa_ioc_ct2_map_port(struct bfa_ioc_s *ioc)
32311189208SKrishna Gudipati {
3245a0adaedSKrishna Gudipati 	void __iomem	*rb = ioc->pcidev.pci_bar_kva;
3255a0adaedSKrishna Gudipati 	u32	r32;
3265a0adaedSKrishna Gudipati 
3275a0adaedSKrishna Gudipati 	r32 = readl(rb + CT2_HOSTFN_PERSONALITY0);
3285a0adaedSKrishna Gudipati 	ioc->port_id = ((r32 & __FC_LL_PORT_MAP__MK) >> __FC_LL_PORT_MAP__SH);
32911189208SKrishna Gudipati 
33011189208SKrishna Gudipati 	bfa_trc(ioc, bfa_ioc_pcifn(ioc));
33111189208SKrishna Gudipati 	bfa_trc(ioc, ioc->port_id);
33211189208SKrishna Gudipati }
33311189208SKrishna Gudipati 
3345fbe25c7SJing Huang /*
3350a20de44SKrishna Gudipati  * Set interrupt mode for a function: INTX or MSIX
3360a20de44SKrishna Gudipati  */
3370a20de44SKrishna Gudipati static void
bfa_ioc_ct_isr_mode_set(struct bfa_ioc_s * ioc,bfa_boolean_t msix)3380a20de44SKrishna Gudipati bfa_ioc_ct_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix)
3390a20de44SKrishna Gudipati {
34053440260SJing Huang 	void __iomem *rb = ioc->pcidev.pci_bar_kva;
341d1c61f8eSKrishna Gudipati 	u32	r32, mode;
3420a20de44SKrishna Gudipati 
34353440260SJing Huang 	r32 = readl(rb + FNC_PERS_REG);
3440a20de44SKrishna Gudipati 	bfa_trc(ioc, r32);
3450a20de44SKrishna Gudipati 
3460a20de44SKrishna Gudipati 	mode = (r32 >> FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc))) &
3470a20de44SKrishna Gudipati 		__F0_INTX_STATUS;
3480a20de44SKrishna Gudipati 
3495fbe25c7SJing Huang 	/*
3500a20de44SKrishna Gudipati 	 * If already in desired mode, do not change anything
3510a20de44SKrishna Gudipati 	 */
35211189208SKrishna Gudipati 	if ((!msix && mode) || (msix && !mode))
3530a20de44SKrishna Gudipati 		return;
3540a20de44SKrishna Gudipati 
3550a20de44SKrishna Gudipati 	if (msix)
3560a20de44SKrishna Gudipati 		mode = __F0_INTX_STATUS_MSIX;
3570a20de44SKrishna Gudipati 	else
3580a20de44SKrishna Gudipati 		mode = __F0_INTX_STATUS_INTA;
3590a20de44SKrishna Gudipati 
3600a20de44SKrishna Gudipati 	r32 &= ~(__F0_INTX_STATUS << FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc)));
3610a20de44SKrishna Gudipati 	r32 |= (mode << FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc)));
3620a20de44SKrishna Gudipati 	bfa_trc(ioc, r32);
3630a20de44SKrishna Gudipati 
36453440260SJing Huang 	writel(r32, rb + FNC_PERS_REG);
3650a20de44SKrishna Gudipati }
3660a20de44SKrishna Gudipati 
367eae9b178SJason Yan static bfa_boolean_t
bfa_ioc_ct2_lpu_read_stat(struct bfa_ioc_s * ioc)3688b070b4aSKrishna Gudipati bfa_ioc_ct2_lpu_read_stat(struct bfa_ioc_s *ioc)
3698b070b4aSKrishna Gudipati {
3708b070b4aSKrishna Gudipati 	u32	r32;
3718b070b4aSKrishna Gudipati 
3728b070b4aSKrishna Gudipati 	r32 = readl(ioc->ioc_regs.lpu_read_stat);
3738b070b4aSKrishna Gudipati 	if (r32) {
3748b070b4aSKrishna Gudipati 		writel(1, ioc->ioc_regs.lpu_read_stat);
3758b070b4aSKrishna Gudipati 		return BFA_TRUE;
3768b070b4aSKrishna Gudipati 	}
3778b070b4aSKrishna Gudipati 
3788b070b4aSKrishna Gudipati 	return BFA_FALSE;
3798b070b4aSKrishna Gudipati }
3808b070b4aSKrishna Gudipati 
3815fbe25c7SJing Huang /*
3820a20de44SKrishna Gudipati  * Cleanup hw semaphore and usecnt registers
3830a20de44SKrishna Gudipati  */
3840a20de44SKrishna Gudipati static void
bfa_ioc_ct_ownership_reset(struct bfa_ioc_s * ioc)3850a20de44SKrishna Gudipati bfa_ioc_ct_ownership_reset(struct bfa_ioc_s *ioc)
3860a20de44SKrishna Gudipati {
3870a20de44SKrishna Gudipati 
3880a20de44SKrishna Gudipati 	bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg);
38953440260SJing Huang 	writel(0, ioc->ioc_regs.ioc_usage_reg);
3905a0adaedSKrishna Gudipati 	readl(ioc->ioc_regs.ioc_usage_sem_reg);
391f7f73812SMaggie Zhang 	writel(1, ioc->ioc_regs.ioc_usage_sem_reg);
3920a20de44SKrishna Gudipati 
3937ac83b1fSKrishna Gudipati 	writel(0, ioc->ioc_regs.ioc_fail_sync);
3940a20de44SKrishna Gudipati 	/*
3950a20de44SKrishna Gudipati 	 * Read the hw sem reg to make sure that it is locked
3960a20de44SKrishna Gudipati 	 * before we clear it. If it is not locked, writing 1
3970a20de44SKrishna Gudipati 	 * will lock it instead of clearing it.
3980a20de44SKrishna Gudipati 	 */
39953440260SJing Huang 	readl(ioc->ioc_regs.ioc_sem_reg);
400f7f73812SMaggie Zhang 	writel(1, ioc->ioc_regs.ioc_sem_reg);
4010a20de44SKrishna Gudipati }
402a36c61f9SKrishna Gudipati 
40345d7f0ccSJing Huang static bfa_boolean_t
bfa_ioc_ct_sync_start(struct bfa_ioc_s * ioc)40445d7f0ccSJing Huang bfa_ioc_ct_sync_start(struct bfa_ioc_s *ioc)
40545d7f0ccSJing Huang {
40645d7f0ccSJing Huang 	uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync);
40745d7f0ccSJing Huang 	uint32_t sync_reqd = bfa_ioc_ct_get_sync_reqd(r32);
40845d7f0ccSJing Huang 
40945d7f0ccSJing Huang 	/*
41045d7f0ccSJing Huang 	 * Driver load time.  If the sync required bit for this PCI fn
41145d7f0ccSJing Huang 	 * is set, it is due to an unclean exit by the driver for this
41245d7f0ccSJing Huang 	 * PCI fn in the previous incarnation. Whoever comes here first
41345d7f0ccSJing Huang 	 * should clean it up, no matter which PCI fn.
41445d7f0ccSJing Huang 	 */
41545d7f0ccSJing Huang 
41645d7f0ccSJing Huang 	if (sync_reqd & bfa_ioc_ct_sync_pos(ioc)) {
41745d7f0ccSJing Huang 		writel(0, ioc->ioc_regs.ioc_fail_sync);
41845d7f0ccSJing Huang 		writel(1, ioc->ioc_regs.ioc_usage_reg);
41945d7f0ccSJing Huang 		writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
42045d7f0ccSJing Huang 		writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate);
42145d7f0ccSJing Huang 		return BFA_TRUE;
42245d7f0ccSJing Huang 	}
42345d7f0ccSJing Huang 
42445d7f0ccSJing Huang 	return bfa_ioc_ct_sync_complete(ioc);
42545d7f0ccSJing Huang }
42645d7f0ccSJing Huang 
4278f4bfaddSJing Huang /*
428f1d584d7SKrishna Gudipati  * Synchronized IOC failure processing routines
429f1d584d7SKrishna Gudipati  */
430f1d584d7SKrishna Gudipati static void
bfa_ioc_ct_sync_join(struct bfa_ioc_s * ioc)431f1d584d7SKrishna Gudipati bfa_ioc_ct_sync_join(struct bfa_ioc_s *ioc)
432f1d584d7SKrishna Gudipati {
433f1d584d7SKrishna Gudipati 	uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync);
434f1d584d7SKrishna Gudipati 	uint32_t sync_pos = bfa_ioc_ct_sync_reqd_pos(ioc);
435a36c61f9SKrishna Gudipati 
436f1d584d7SKrishna Gudipati 	writel((r32 | sync_pos), ioc->ioc_regs.ioc_fail_sync);
437f1d584d7SKrishna Gudipati }
438f1d584d7SKrishna Gudipati 
439f1d584d7SKrishna Gudipati static void
bfa_ioc_ct_sync_leave(struct bfa_ioc_s * ioc)440f1d584d7SKrishna Gudipati bfa_ioc_ct_sync_leave(struct bfa_ioc_s *ioc)
441f1d584d7SKrishna Gudipati {
442f1d584d7SKrishna Gudipati 	uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync);
443f1d584d7SKrishna Gudipati 	uint32_t sync_msk = bfa_ioc_ct_sync_reqd_pos(ioc) |
444f1d584d7SKrishna Gudipati 					bfa_ioc_ct_sync_pos(ioc);
445f1d584d7SKrishna Gudipati 
446f1d584d7SKrishna Gudipati 	writel((r32 & ~sync_msk), ioc->ioc_regs.ioc_fail_sync);
447f1d584d7SKrishna Gudipati }
448f1d584d7SKrishna Gudipati 
449f1d584d7SKrishna Gudipati static void
bfa_ioc_ct_sync_ack(struct bfa_ioc_s * ioc)450f1d584d7SKrishna Gudipati bfa_ioc_ct_sync_ack(struct bfa_ioc_s *ioc)
451f1d584d7SKrishna Gudipati {
452f1d584d7SKrishna Gudipati 	uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync);
453f1d584d7SKrishna Gudipati 
454f1d584d7SKrishna Gudipati 	writel((r32 | bfa_ioc_ct_sync_pos(ioc)),
455f1d584d7SKrishna Gudipati 		ioc->ioc_regs.ioc_fail_sync);
456f1d584d7SKrishna Gudipati }
457f1d584d7SKrishna Gudipati 
458f1d584d7SKrishna Gudipati static bfa_boolean_t
bfa_ioc_ct_sync_complete(struct bfa_ioc_s * ioc)459f1d584d7SKrishna Gudipati bfa_ioc_ct_sync_complete(struct bfa_ioc_s *ioc)
460f1d584d7SKrishna Gudipati {
461f1d584d7SKrishna Gudipati 	uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync);
462f1d584d7SKrishna Gudipati 	uint32_t sync_reqd = bfa_ioc_ct_get_sync_reqd(r32);
463f1d584d7SKrishna Gudipati 	uint32_t sync_ackd = bfa_ioc_ct_get_sync_ackd(r32);
464f1d584d7SKrishna Gudipati 	uint32_t tmp_ackd;
465f1d584d7SKrishna Gudipati 
466f1d584d7SKrishna Gudipati 	if (sync_ackd == 0)
467f1d584d7SKrishna Gudipati 		return BFA_TRUE;
468f1d584d7SKrishna Gudipati 
4698f4bfaddSJing Huang 	/*
470f1d584d7SKrishna Gudipati 	 * The check below is to see whether any other PCI fn
471f1d584d7SKrishna Gudipati 	 * has reinitialized the ASIC (reset sync_ackd bits)
472f1d584d7SKrishna Gudipati 	 * and failed again while this IOC was waiting for hw
473f1d584d7SKrishna Gudipati 	 * semaphore (in bfa_iocpf_sm_semwait()).
474f1d584d7SKrishna Gudipati 	 */
475f1d584d7SKrishna Gudipati 	tmp_ackd = sync_ackd;
476f1d584d7SKrishna Gudipati 	if ((sync_reqd &  bfa_ioc_ct_sync_pos(ioc)) &&
477f1d584d7SKrishna Gudipati 		!(sync_ackd & bfa_ioc_ct_sync_pos(ioc)))
478f1d584d7SKrishna Gudipati 		sync_ackd |= bfa_ioc_ct_sync_pos(ioc);
479f1d584d7SKrishna Gudipati 
480f1d584d7SKrishna Gudipati 	if (sync_reqd == sync_ackd) {
481f1d584d7SKrishna Gudipati 		writel(bfa_ioc_ct_clear_sync_ackd(r32),
482f1d584d7SKrishna Gudipati 			ioc->ioc_regs.ioc_fail_sync);
483f1d584d7SKrishna Gudipati 		writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
484f1d584d7SKrishna Gudipati 		writel(BFI_IOC_FAIL, ioc->ioc_regs.alt_ioc_fwstate);
485f1d584d7SKrishna Gudipati 		return BFA_TRUE;
486f1d584d7SKrishna Gudipati 	}
487f1d584d7SKrishna Gudipati 
4888f4bfaddSJing Huang 	/*
489f1d584d7SKrishna Gudipati 	 * If another PCI fn reinitialized and failed again while
490f1d584d7SKrishna Gudipati 	 * this IOC was waiting for hw sem, the sync_ackd bit for
491f1d584d7SKrishna Gudipati 	 * this IOC need to be set again to allow reinitialization.
492f1d584d7SKrishna Gudipati 	 */
493f1d584d7SKrishna Gudipati 	if (tmp_ackd != sync_ackd)
494f1d584d7SKrishna Gudipati 		writel((r32 | sync_ackd), ioc->ioc_regs.ioc_fail_sync);
495f1d584d7SKrishna Gudipati 
496f1d584d7SKrishna Gudipati 	return BFA_FALSE;
497f1d584d7SKrishna Gudipati }
498a36c61f9SKrishna Gudipati 
499*eaefa330SLee Jones /*
50011189208SKrishna Gudipati  * Called from bfa_ioc_attach() to map asic specific calls.
501a36c61f9SKrishna Gudipati  */
50211189208SKrishna Gudipati static void
bfa_ioc_set_ctx_hwif(struct bfa_ioc_s * ioc,struct bfa_ioc_hwif_s * hwif)50311189208SKrishna Gudipati bfa_ioc_set_ctx_hwif(struct bfa_ioc_s *ioc, struct bfa_ioc_hwif_s *hwif)
504a36c61f9SKrishna Gudipati {
50511189208SKrishna Gudipati 	hwif->ioc_firmware_lock = bfa_ioc_ct_firmware_lock;
50611189208SKrishna Gudipati 	hwif->ioc_firmware_unlock = bfa_ioc_ct_firmware_unlock;
50711189208SKrishna Gudipati 	hwif->ioc_notify_fail = bfa_ioc_ct_notify_fail;
50811189208SKrishna Gudipati 	hwif->ioc_ownership_reset = bfa_ioc_ct_ownership_reset;
50911189208SKrishna Gudipati 	hwif->ioc_sync_start = bfa_ioc_ct_sync_start;
51011189208SKrishna Gudipati 	hwif->ioc_sync_join = bfa_ioc_ct_sync_join;
51111189208SKrishna Gudipati 	hwif->ioc_sync_leave = bfa_ioc_ct_sync_leave;
51211189208SKrishna Gudipati 	hwif->ioc_sync_ack = bfa_ioc_ct_sync_ack;
51311189208SKrishna Gudipati 	hwif->ioc_sync_complete = bfa_ioc_ct_sync_complete;
514c679b599SVijaya Mohan Guvva 	hwif->ioc_set_fwstate = bfa_ioc_ct_set_cur_ioc_fwstate;
515c679b599SVijaya Mohan Guvva 	hwif->ioc_get_fwstate = bfa_ioc_ct_get_cur_ioc_fwstate;
516c679b599SVijaya Mohan Guvva 	hwif->ioc_set_alt_fwstate = bfa_ioc_ct_set_alt_ioc_fwstate;
517c679b599SVijaya Mohan Guvva 	hwif->ioc_get_alt_fwstate = bfa_ioc_ct_get_alt_ioc_fwstate;
51811189208SKrishna Gudipati }
519a36c61f9SKrishna Gudipati 
520*eaefa330SLee Jones /*
52111189208SKrishna Gudipati  * Called from bfa_ioc_attach() to map asic specific calls.
52211189208SKrishna Gudipati  */
52311189208SKrishna Gudipati void
bfa_ioc_set_ct_hwif(struct bfa_ioc_s * ioc)52411189208SKrishna Gudipati bfa_ioc_set_ct_hwif(struct bfa_ioc_s *ioc)
52511189208SKrishna Gudipati {
52611189208SKrishna Gudipati 	bfa_ioc_set_ctx_hwif(ioc, &hwif_ct);
52711189208SKrishna Gudipati 
52811189208SKrishna Gudipati 	hwif_ct.ioc_pll_init = bfa_ioc_ct_pll_init;
52911189208SKrishna Gudipati 	hwif_ct.ioc_reg_init = bfa_ioc_ct_reg_init;
53011189208SKrishna Gudipati 	hwif_ct.ioc_map_port = bfa_ioc_ct_map_port;
53111189208SKrishna Gudipati 	hwif_ct.ioc_isr_mode_set = bfa_ioc_ct_isr_mode_set;
53211189208SKrishna Gudipati 	ioc->ioc_hwif = &hwif_ct;
53311189208SKrishna Gudipati }
53411189208SKrishna Gudipati 
535*eaefa330SLee Jones /*
53611189208SKrishna Gudipati  * Called from bfa_ioc_attach() to map asic specific calls.
53711189208SKrishna Gudipati  */
53811189208SKrishna Gudipati void
bfa_ioc_set_ct2_hwif(struct bfa_ioc_s * ioc)53911189208SKrishna Gudipati bfa_ioc_set_ct2_hwif(struct bfa_ioc_s *ioc)
54011189208SKrishna Gudipati {
54111189208SKrishna Gudipati 	bfa_ioc_set_ctx_hwif(ioc, &hwif_ct2);
54211189208SKrishna Gudipati 
54311189208SKrishna Gudipati 	hwif_ct2.ioc_pll_init = bfa_ioc_ct2_pll_init;
54411189208SKrishna Gudipati 	hwif_ct2.ioc_reg_init = bfa_ioc_ct2_reg_init;
54511189208SKrishna Gudipati 	hwif_ct2.ioc_map_port = bfa_ioc_ct2_map_port;
5468b070b4aSKrishna Gudipati 	hwif_ct2.ioc_lpu_read_stat = bfa_ioc_ct2_lpu_read_stat;
54711189208SKrishna Gudipati 	hwif_ct2.ioc_isr_mode_set = NULL;
54811189208SKrishna Gudipati 	ioc->ioc_hwif = &hwif_ct2;
54911189208SKrishna Gudipati }
55011189208SKrishna Gudipati 
55111189208SKrishna Gudipati /*
5523fd45980SKrishna Gudipati  * Workaround for MSI-X resource allocation for catapult-2 with no asic block
55311189208SKrishna Gudipati  */
5543fd45980SKrishna Gudipati #define HOSTFN_MSIX_DEFAULT		64
55510a07379SKrishna Gudipati #define HOSTFN_MSIX_VT_INDEX_MBOX_ERR	0x30138
55611189208SKrishna Gudipati #define HOSTFN_MSIX_VT_OFST_NUMVT	0x3013c
55711189208SKrishna Gudipati #define __MSIX_VT_NUMVT__MK		0x003ff800
55811189208SKrishna Gudipati #define __MSIX_VT_NUMVT__SH		11
55911189208SKrishna Gudipati #define __MSIX_VT_NUMVT_(_v)		((_v) << __MSIX_VT_NUMVT__SH)
56010a07379SKrishna Gudipati #define __MSIX_VT_OFST_			0x000007ff
56111189208SKrishna Gudipati void
bfa_ioc_ct2_poweron(struct bfa_ioc_s * ioc)56211189208SKrishna Gudipati bfa_ioc_ct2_poweron(struct bfa_ioc_s *ioc)
56311189208SKrishna Gudipati {
56411189208SKrishna Gudipati 	void __iomem *rb = ioc->pcidev.pci_bar_kva;
56511189208SKrishna Gudipati 	u32	r32;
56611189208SKrishna Gudipati 
56711189208SKrishna Gudipati 	r32 = readl(rb + HOSTFN_MSIX_VT_OFST_NUMVT);
56810a07379SKrishna Gudipati 	if (r32 & __MSIX_VT_NUMVT__MK) {
56910a07379SKrishna Gudipati 		writel(r32 & __MSIX_VT_OFST_,
57010a07379SKrishna Gudipati 			rb + HOSTFN_MSIX_VT_INDEX_MBOX_ERR);
57111189208SKrishna Gudipati 		return;
57210a07379SKrishna Gudipati 	}
57311189208SKrishna Gudipati 
57411189208SKrishna Gudipati 	writel(__MSIX_VT_NUMVT_(HOSTFN_MSIX_DEFAULT - 1) |
57511189208SKrishna Gudipati 		HOSTFN_MSIX_DEFAULT * bfa_ioc_pcifn(ioc),
57611189208SKrishna Gudipati 		rb + HOSTFN_MSIX_VT_OFST_NUMVT);
57710a07379SKrishna Gudipati 	writel(HOSTFN_MSIX_DEFAULT * bfa_ioc_pcifn(ioc),
57810a07379SKrishna Gudipati 		rb + HOSTFN_MSIX_VT_INDEX_MBOX_ERR);
579a36c61f9SKrishna Gudipati }
580a36c61f9SKrishna Gudipati 
581a36c61f9SKrishna Gudipati bfa_status_t
bfa_ioc_ct_pll_init(void __iomem * rb,enum bfi_asic_mode mode)58211189208SKrishna Gudipati bfa_ioc_ct_pll_init(void __iomem *rb, enum bfi_asic_mode mode)
583a36c61f9SKrishna Gudipati {
584a36c61f9SKrishna Gudipati 	u32	pll_sclk, pll_fclk, r32;
58511189208SKrishna Gudipati 	bfa_boolean_t fcmode = (mode == BFI_ASIC_MODE_FC);
586a36c61f9SKrishna Gudipati 
58711189208SKrishna Gudipati 	pll_sclk = __APP_PLL_SCLK_LRESETN | __APP_PLL_SCLK_ENARST |
58811189208SKrishna Gudipati 		__APP_PLL_SCLK_RSEL200500 | __APP_PLL_SCLK_P0_1(3U) |
58911189208SKrishna Gudipati 		__APP_PLL_SCLK_JITLMT0_1(3U) |
59011189208SKrishna Gudipati 		__APP_PLL_SCLK_CNTLMT0_1(1U);
59111189208SKrishna Gudipati 	pll_fclk = __APP_PLL_LCLK_LRESETN | __APP_PLL_LCLK_ENARST |
59211189208SKrishna Gudipati 		__APP_PLL_LCLK_RSEL200500 | __APP_PLL_LCLK_P0_1(3U) |
59311189208SKrishna Gudipati 		__APP_PLL_LCLK_JITLMT0_1(3U) |
59411189208SKrishna Gudipati 		__APP_PLL_LCLK_CNTLMT0_1(1U);
59511189208SKrishna Gudipati 
596a36c61f9SKrishna Gudipati 	if (fcmode) {
59753440260SJing Huang 		writel(0, (rb + OP_MODE));
59853440260SJing Huang 		writel(__APP_EMS_CMLCKSEL | __APP_EMS_REFCKBUFEN2 |
59953440260SJing Huang 			 __APP_EMS_CHANNEL_SEL, (rb + ETH_MAC_SER_REG));
600a36c61f9SKrishna Gudipati 	} else {
60153440260SJing Huang 		writel(__GLOBAL_FCOE_MODE, (rb + OP_MODE));
60253440260SJing Huang 		writel(__APP_EMS_REFCKBUFEN1, (rb + ETH_MAC_SER_REG));
603a36c61f9SKrishna Gudipati 	}
60453440260SJing Huang 	writel(BFI_IOC_UNINIT, (rb + BFA_IOC0_STATE_REG));
60553440260SJing Huang 	writel(BFI_IOC_UNINIT, (rb + BFA_IOC1_STATE_REG));
60653440260SJing Huang 	writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
60753440260SJing Huang 	writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
60853440260SJing Huang 	writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
60953440260SJing Huang 	writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
61053440260SJing Huang 	writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
61153440260SJing Huang 	writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
61211189208SKrishna Gudipati 	writel(pll_sclk | __APP_PLL_SCLK_LOGIC_SOFT_RESET,
61311189208SKrishna Gudipati 			rb + APP_PLL_SCLK_CTL_REG);
61411189208SKrishna Gudipati 	writel(pll_fclk | __APP_PLL_LCLK_LOGIC_SOFT_RESET,
61511189208SKrishna Gudipati 			rb + APP_PLL_LCLK_CTL_REG);
61611189208SKrishna Gudipati 	writel(pll_sclk | __APP_PLL_SCLK_LOGIC_SOFT_RESET |
61711189208SKrishna Gudipati 		__APP_PLL_SCLK_ENABLE, rb + APP_PLL_SCLK_CTL_REG);
61811189208SKrishna Gudipati 	writel(pll_fclk | __APP_PLL_LCLK_LOGIC_SOFT_RESET |
61911189208SKrishna Gudipati 		__APP_PLL_LCLK_ENABLE, rb + APP_PLL_LCLK_CTL_REG);
62053440260SJing Huang 	readl(rb + HOSTFN0_INT_MSK);
6216a18b167SJing Huang 	udelay(2000);
62253440260SJing Huang 	writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
62353440260SJing Huang 	writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
62411189208SKrishna Gudipati 	writel(pll_sclk | __APP_PLL_SCLK_ENABLE, rb + APP_PLL_SCLK_CTL_REG);
62511189208SKrishna Gudipati 	writel(pll_fclk | __APP_PLL_LCLK_ENABLE, rb + APP_PLL_LCLK_CTL_REG);
62611189208SKrishna Gudipati 
627a36c61f9SKrishna Gudipati 	if (!fcmode) {
62853440260SJing Huang 		writel(__PMM_1T_RESET_P, (rb + PMM_1T_RESET_REG_P0));
62953440260SJing Huang 		writel(__PMM_1T_RESET_P, (rb + PMM_1T_RESET_REG_P1));
630a36c61f9SKrishna Gudipati 	}
63153440260SJing Huang 	r32 = readl((rb + PSS_CTL_REG));
632a36c61f9SKrishna Gudipati 	r32 &= ~__PSS_LMEM_RESET;
63353440260SJing Huang 	writel(r32, (rb + PSS_CTL_REG));
6346a18b167SJing Huang 	udelay(1000);
635a36c61f9SKrishna Gudipati 	if (!fcmode) {
63653440260SJing Huang 		writel(0, (rb + PMM_1T_RESET_REG_P0));
63753440260SJing Huang 		writel(0, (rb + PMM_1T_RESET_REG_P1));
638a36c61f9SKrishna Gudipati 	}
639a36c61f9SKrishna Gudipati 
64053440260SJing Huang 	writel(__EDRAM_BISTR_START, (rb + MBIST_CTL_REG));
6416a18b167SJing Huang 	udelay(1000);
64253440260SJing Huang 	r32 = readl((rb + MBIST_STAT_REG));
64353440260SJing Huang 	writel(0, (rb + MBIST_CTL_REG));
644a36c61f9SKrishna Gudipati 	return BFA_STATUS_OK;
645a36c61f9SKrishna Gudipati }
64611189208SKrishna Gudipati 
64711189208SKrishna Gudipati static void
bfa_ioc_ct2_sclk_init(void __iomem * rb)64810a07379SKrishna Gudipati bfa_ioc_ct2_sclk_init(void __iomem *rb)
64911189208SKrishna Gudipati {
65011189208SKrishna Gudipati 	u32 r32;
65111189208SKrishna Gudipati 
65211189208SKrishna Gudipati 	/*
65311189208SKrishna Gudipati 	 * put s_clk PLL and PLL FSM in reset
65411189208SKrishna Gudipati 	 */
65511189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG));
65611189208SKrishna Gudipati 	r32 &= ~(__APP_PLL_SCLK_ENABLE | __APP_PLL_SCLK_LRESETN);
65711189208SKrishna Gudipati 	r32 |= (__APP_PLL_SCLK_ENARST | __APP_PLL_SCLK_BYPASS |
65811189208SKrishna Gudipati 		__APP_PLL_SCLK_LOGIC_SOFT_RESET);
65911189208SKrishna Gudipati 	writel(r32, (rb + CT2_APP_PLL_SCLK_CTL_REG));
66011189208SKrishna Gudipati 
66111189208SKrishna Gudipati 	/*
66210a07379SKrishna Gudipati 	 * Ignore mode and program for the max clock (which is FC16)
66310a07379SKrishna Gudipati 	 * Firmware/NFC will do the PLL init appropiately
66411189208SKrishna Gudipati 	 */
66511189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG));
66611189208SKrishna Gudipati 	r32 &= ~(__APP_PLL_SCLK_REFCLK_SEL | __APP_PLL_SCLK_CLK_DIV2);
66710a07379SKrishna Gudipati 	writel(r32, (rb + CT2_APP_PLL_SCLK_CTL_REG));
66811189208SKrishna Gudipati 
66911189208SKrishna Gudipati 	/*
670775c7742SKrishna Gudipati 	 * while doing PLL init dont clock gate ethernet subsystem
67111189208SKrishna Gudipati 	 */
67211189208SKrishna Gudipati 	r32 = readl((rb + CT2_CHIP_MISC_PRG));
67311189208SKrishna Gudipati 	writel(r32 | __ETH_CLK_ENABLE_PORT0, (rb + CT2_CHIP_MISC_PRG));
67411189208SKrishna Gudipati 
67511189208SKrishna Gudipati 	r32 = readl((rb + CT2_PCIE_MISC_REG));
67611189208SKrishna Gudipati 	writel(r32 | __ETH_CLK_ENABLE_PORT1, (rb + CT2_PCIE_MISC_REG));
67711189208SKrishna Gudipati 
67811189208SKrishna Gudipati 	/*
67911189208SKrishna Gudipati 	 * set sclk value
68011189208SKrishna Gudipati 	 */
68111189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG));
68211189208SKrishna Gudipati 	r32 &= (__P_SCLK_PLL_LOCK | __APP_PLL_SCLK_REFCLK_SEL |
68311189208SKrishna Gudipati 		__APP_PLL_SCLK_CLK_DIV2);
68411189208SKrishna Gudipati 	writel(r32 | 0x1061731b, (rb + CT2_APP_PLL_SCLK_CTL_REG));
68511189208SKrishna Gudipati 
68611189208SKrishna Gudipati 	/*
68711189208SKrishna Gudipati 	 * poll for s_clk lock or delay 1ms
68811189208SKrishna Gudipati 	 */
68911189208SKrishna Gudipati 	udelay(1000);
69011189208SKrishna Gudipati }
69111189208SKrishna Gudipati 
69211189208SKrishna Gudipati static void
bfa_ioc_ct2_lclk_init(void __iomem * rb)69310a07379SKrishna Gudipati bfa_ioc_ct2_lclk_init(void __iomem *rb)
69411189208SKrishna Gudipati {
69511189208SKrishna Gudipati 	u32 r32;
69611189208SKrishna Gudipati 
69711189208SKrishna Gudipati 	/*
69811189208SKrishna Gudipati 	 * put l_clk PLL and PLL FSM in reset
69911189208SKrishna Gudipati 	 */
70011189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG));
70111189208SKrishna Gudipati 	r32 &= ~(__APP_PLL_LCLK_ENABLE | __APP_PLL_LCLK_LRESETN);
70211189208SKrishna Gudipati 	r32 |= (__APP_PLL_LCLK_ENARST | __APP_PLL_LCLK_BYPASS |
70311189208SKrishna Gudipati 		__APP_PLL_LCLK_LOGIC_SOFT_RESET);
70411189208SKrishna Gudipati 	writel(r32, (rb + CT2_APP_PLL_LCLK_CTL_REG));
70511189208SKrishna Gudipati 
70611189208SKrishna Gudipati 	/*
70710a07379SKrishna Gudipati 	 * set LPU speed (set for FC16 which will work for other modes)
70811189208SKrishna Gudipati 	 */
70911189208SKrishna Gudipati 	r32 = readl((rb + CT2_CHIP_MISC_PRG));
71010a07379SKrishna Gudipati 	writel(r32, (rb + CT2_CHIP_MISC_PRG));
71111189208SKrishna Gudipati 
71211189208SKrishna Gudipati 	/*
71310a07379SKrishna Gudipati 	 * set LPU half speed (set for FC16 which will work for other modes)
71411189208SKrishna Gudipati 	 */
71511189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG));
71610a07379SKrishna Gudipati 	writel(r32, (rb + CT2_APP_PLL_LCLK_CTL_REG));
71711189208SKrishna Gudipati 
71811189208SKrishna Gudipati 	/*
71910a07379SKrishna Gudipati 	 * set lclk for mode (set for FC16)
72011189208SKrishna Gudipati 	 */
72111189208SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG));
72211189208SKrishna Gudipati 	r32 &= (__P_LCLK_PLL_LOCK | __APP_LPUCLK_HALFSPEED);
72311189208SKrishna Gudipati 	r32 |= 0x20c1731b;
72411189208SKrishna Gudipati 	writel(r32, (rb + CT2_APP_PLL_LCLK_CTL_REG));
72511189208SKrishna Gudipati 
72611189208SKrishna Gudipati 	/*
72711189208SKrishna Gudipati 	 * poll for s_clk lock or delay 1ms
72811189208SKrishna Gudipati 	 */
72911189208SKrishna Gudipati 	udelay(1000);
73010a07379SKrishna Gudipati }
73110a07379SKrishna Gudipati 
73210a07379SKrishna Gudipati static void
bfa_ioc_ct2_mem_init(void __iomem * rb)73310a07379SKrishna Gudipati bfa_ioc_ct2_mem_init(void __iomem *rb)
73410a07379SKrishna Gudipati {
73510a07379SKrishna Gudipati 	u32	r32;
73610a07379SKrishna Gudipati 
73710a07379SKrishna Gudipati 	r32 = readl((rb + PSS_CTL_REG));
73810a07379SKrishna Gudipati 	r32 &= ~__PSS_LMEM_RESET;
73910a07379SKrishna Gudipati 	writel(r32, (rb + PSS_CTL_REG));
74010a07379SKrishna Gudipati 	udelay(1000);
74110a07379SKrishna Gudipati 
74210a07379SKrishna Gudipati 	writel(__EDRAM_BISTR_START, (rb + CT2_MBIST_CTL_REG));
74310a07379SKrishna Gudipati 	udelay(1000);
74410a07379SKrishna Gudipati 	writel(0, (rb + CT2_MBIST_CTL_REG));
74510a07379SKrishna Gudipati }
74610a07379SKrishna Gudipati 
747eae9b178SJason Yan static void
bfa_ioc_ct2_mac_reset(void __iomem * rb)74810a07379SKrishna Gudipati bfa_ioc_ct2_mac_reset(void __iomem *rb)
74910a07379SKrishna Gudipati {
75010a07379SKrishna Gudipati 	/* put port0, port1 MAC & AHB in reset */
75110a07379SKrishna Gudipati 	writel((__CSI_MAC_RESET | __CSI_MAC_AHB_RESET),
75210a07379SKrishna Gudipati 		rb + CT2_CSI_MAC_CONTROL_REG(0));
75310a07379SKrishna Gudipati 	writel((__CSI_MAC_RESET | __CSI_MAC_AHB_RESET),
75410a07379SKrishna Gudipati 		rb + CT2_CSI_MAC_CONTROL_REG(1));
75511189208SKrishna Gudipati }
75611189208SKrishna Gudipati 
757227fab90SKrishna Gudipati static void
bfa_ioc_ct2_enable_flash(void __iomem * rb)758227fab90SKrishna Gudipati bfa_ioc_ct2_enable_flash(void __iomem *rb)
759227fab90SKrishna Gudipati {
760227fab90SKrishna Gudipati 	u32 r32;
761227fab90SKrishna Gudipati 
762227fab90SKrishna Gudipati 	r32 = readl((rb + PSS_GPIO_OUT_REG));
763227fab90SKrishna Gudipati 	writel(r32 & ~1, (rb + PSS_GPIO_OUT_REG));
764227fab90SKrishna Gudipati 	r32 = readl((rb + PSS_GPIO_OE_REG));
765227fab90SKrishna Gudipati 	writel(r32 | 1, (rb + PSS_GPIO_OE_REG));
766227fab90SKrishna Gudipati }
767227fab90SKrishna Gudipati 
76810a07379SKrishna Gudipati #define CT2_NFC_MAX_DELAY	1000
769227fab90SKrishna Gudipati #define CT2_NFC_PAUSE_MAX_DELAY 4000
770227fab90SKrishna Gudipati #define CT2_NFC_VER_VALID	0x147
771227fab90SKrishna Gudipati #define CT2_NFC_STATE_RUNNING   0x20000001
772a6b963dbSKrishna Gudipati #define BFA_IOC_PLL_POLL	1000000
773a6b963dbSKrishna Gudipati 
774a6b963dbSKrishna Gudipati static bfa_boolean_t
bfa_ioc_ct2_nfc_halted(void __iomem * rb)775a6b963dbSKrishna Gudipati bfa_ioc_ct2_nfc_halted(void __iomem *rb)
776a6b963dbSKrishna Gudipati {
777a6b963dbSKrishna Gudipati 	u32	r32;
778a6b963dbSKrishna Gudipati 
779a6b963dbSKrishna Gudipati 	r32 = readl(rb + CT2_NFC_CSR_SET_REG);
780a6b963dbSKrishna Gudipati 	if (r32 & __NFC_CONTROLLER_HALTED)
781a6b963dbSKrishna Gudipati 		return BFA_TRUE;
782a6b963dbSKrishna Gudipati 
783a6b963dbSKrishna Gudipati 	return BFA_FALSE;
784a6b963dbSKrishna Gudipati }
785a6b963dbSKrishna Gudipati 
786a6b963dbSKrishna Gudipati static void
bfa_ioc_ct2_nfc_halt(void __iomem * rb)787227fab90SKrishna Gudipati bfa_ioc_ct2_nfc_halt(void __iomem *rb)
788227fab90SKrishna Gudipati {
789227fab90SKrishna Gudipati 	int	i;
790227fab90SKrishna Gudipati 
791227fab90SKrishna Gudipati 	writel(__HALT_NFC_CONTROLLER, rb + CT2_NFC_CSR_SET_REG);
792227fab90SKrishna Gudipati 	for (i = 0; i < CT2_NFC_MAX_DELAY; i++) {
793227fab90SKrishna Gudipati 		if (bfa_ioc_ct2_nfc_halted(rb))
794227fab90SKrishna Gudipati 			break;
795227fab90SKrishna Gudipati 		udelay(1000);
796227fab90SKrishna Gudipati 	}
797227fab90SKrishna Gudipati 	WARN_ON(!bfa_ioc_ct2_nfc_halted(rb));
798227fab90SKrishna Gudipati }
799227fab90SKrishna Gudipati 
800227fab90SKrishna Gudipati static void
bfa_ioc_ct2_nfc_resume(void __iomem * rb)801a6b963dbSKrishna Gudipati bfa_ioc_ct2_nfc_resume(void __iomem *rb)
802a6b963dbSKrishna Gudipati {
803a6b963dbSKrishna Gudipati 	u32	r32;
804a6b963dbSKrishna Gudipati 	int i;
805a6b963dbSKrishna Gudipati 
806a6b963dbSKrishna Gudipati 	writel(__HALT_NFC_CONTROLLER, rb + CT2_NFC_CSR_CLR_REG);
807a6b963dbSKrishna Gudipati 	for (i = 0; i < CT2_NFC_MAX_DELAY; i++) {
808a6b963dbSKrishna Gudipati 		r32 = readl(rb + CT2_NFC_CSR_SET_REG);
809a6b963dbSKrishna Gudipati 		if (!(r32 & __NFC_CONTROLLER_HALTED))
810a6b963dbSKrishna Gudipati 			return;
811a6b963dbSKrishna Gudipati 		udelay(1000);
812a6b963dbSKrishna Gudipati 	}
813a6b963dbSKrishna Gudipati 	WARN_ON(1);
814a6b963dbSKrishna Gudipati }
815a6b963dbSKrishna Gudipati 
816227fab90SKrishna Gudipati static void
bfa_ioc_ct2_clk_reset(void __iomem * rb)817227fab90SKrishna Gudipati bfa_ioc_ct2_clk_reset(void __iomem *rb)
81811189208SKrishna Gudipati {
819227fab90SKrishna Gudipati 	u32 r32;
8208b070b4aSKrishna Gudipati 
82110a07379SKrishna Gudipati 	bfa_ioc_ct2_sclk_init(rb);
82210a07379SKrishna Gudipati 	bfa_ioc_ct2_lclk_init(rb);
82310a07379SKrishna Gudipati 
82410a07379SKrishna Gudipati 	/*
82510a07379SKrishna Gudipati 	 * release soft reset on s_clk & l_clk
82610a07379SKrishna Gudipati 	 */
827227fab90SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG));
82810a07379SKrishna Gudipati 	writel(r32 & ~__APP_PLL_SCLK_LOGIC_SOFT_RESET,
82910a07379SKrishna Gudipati 			(rb + CT2_APP_PLL_SCLK_CTL_REG));
83010a07379SKrishna Gudipati 
831227fab90SKrishna Gudipati 	r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG));
83210a07379SKrishna Gudipati 	writel(r32 & ~__APP_PLL_LCLK_LOGIC_SOFT_RESET,
83310a07379SKrishna Gudipati 			(rb + CT2_APP_PLL_LCLK_CTL_REG));
834227fab90SKrishna Gudipati 
835a6b963dbSKrishna Gudipati }
83611189208SKrishna Gudipati 
837227fab90SKrishna Gudipati static void
bfa_ioc_ct2_nfc_clk_reset(void __iomem * rb)838227fab90SKrishna Gudipati bfa_ioc_ct2_nfc_clk_reset(void __iomem *rb)
839227fab90SKrishna Gudipati {
840227fab90SKrishna Gudipati 	u32 r32, i;
841227fab90SKrishna Gudipati 
842227fab90SKrishna Gudipati 	r32 = readl((rb + PSS_CTL_REG));
843227fab90SKrishna Gudipati 	r32 |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
844227fab90SKrishna Gudipati 	writel(r32, (rb + PSS_CTL_REG));
845227fab90SKrishna Gudipati 
846227fab90SKrishna Gudipati 	writel(__RESET_AND_START_SCLK_LCLK_PLLS, rb + CT2_CSI_FW_CTL_SET_REG);
847227fab90SKrishna Gudipati 
848227fab90SKrishna Gudipati 	for (i = 0; i < BFA_IOC_PLL_POLL; i++) {
849227fab90SKrishna Gudipati 		r32 = readl(rb + CT2_NFC_FLASH_STS_REG);
850227fab90SKrishna Gudipati 
851227fab90SKrishna Gudipati 		if ((r32 & __FLASH_PLL_INIT_AND_RESET_IN_PROGRESS))
852227fab90SKrishna Gudipati 			break;
853227fab90SKrishna Gudipati 	}
854227fab90SKrishna Gudipati 	WARN_ON(!(r32 & __FLASH_PLL_INIT_AND_RESET_IN_PROGRESS));
855227fab90SKrishna Gudipati 
856227fab90SKrishna Gudipati 	for (i = 0; i < BFA_IOC_PLL_POLL; i++) {
857227fab90SKrishna Gudipati 		r32 = readl(rb + CT2_NFC_FLASH_STS_REG);
858227fab90SKrishna Gudipati 
859227fab90SKrishna Gudipati 		if (!(r32 & __FLASH_PLL_INIT_AND_RESET_IN_PROGRESS))
860227fab90SKrishna Gudipati 			break;
861227fab90SKrishna Gudipati 	}
862227fab90SKrishna Gudipati 	WARN_ON((r32 & __FLASH_PLL_INIT_AND_RESET_IN_PROGRESS));
863227fab90SKrishna Gudipati 
864227fab90SKrishna Gudipati 	r32 = readl(rb + CT2_CSI_FW_CTL_REG);
865227fab90SKrishna Gudipati 	WARN_ON((r32 & __RESET_AND_START_SCLK_LCLK_PLLS));
866227fab90SKrishna Gudipati }
867227fab90SKrishna Gudipati 
868227fab90SKrishna Gudipati static void
bfa_ioc_ct2_wait_till_nfc_running(void __iomem * rb)869227fab90SKrishna Gudipati bfa_ioc_ct2_wait_till_nfc_running(void __iomem *rb)
870227fab90SKrishna Gudipati {
871227fab90SKrishna Gudipati 	u32 r32;
872227fab90SKrishna Gudipati 	int i;
873227fab90SKrishna Gudipati 
874227fab90SKrishna Gudipati 	if (bfa_ioc_ct2_nfc_halted(rb))
875227fab90SKrishna Gudipati 		bfa_ioc_ct2_nfc_resume(rb);
876227fab90SKrishna Gudipati 	for (i = 0; i < CT2_NFC_PAUSE_MAX_DELAY; i++) {
877227fab90SKrishna Gudipati 		r32 = readl(rb + CT2_NFC_STS_REG);
878227fab90SKrishna Gudipati 		if (r32 == CT2_NFC_STATE_RUNNING)
879227fab90SKrishna Gudipati 			return;
880227fab90SKrishna Gudipati 		udelay(1000);
881227fab90SKrishna Gudipati 	}
882227fab90SKrishna Gudipati 
883227fab90SKrishna Gudipati 	r32 = readl(rb + CT2_NFC_STS_REG);
884227fab90SKrishna Gudipati 	WARN_ON(!(r32 == CT2_NFC_STATE_RUNNING));
885227fab90SKrishna Gudipati }
886227fab90SKrishna Gudipati 
887227fab90SKrishna Gudipati bfa_status_t
bfa_ioc_ct2_pll_init(void __iomem * rb,enum bfi_asic_mode mode)888227fab90SKrishna Gudipati bfa_ioc_ct2_pll_init(void __iomem *rb, enum bfi_asic_mode mode)
889227fab90SKrishna Gudipati {
890227fab90SKrishna Gudipati 	u32 wgn, r32, nfc_ver;
891227fab90SKrishna Gudipati 
892227fab90SKrishna Gudipati 	wgn = readl(rb + CT2_WGN_STATUS);
893227fab90SKrishna Gudipati 
89410a07379SKrishna Gudipati 	if (wgn == (__WGN_READY | __GLBL_PF_VF_CFG_RDY)) {
895227fab90SKrishna Gudipati 		/*
896227fab90SKrishna Gudipati 		 * If flash is corrupted, enable flash explicitly
897227fab90SKrishna Gudipati 		 */
898227fab90SKrishna Gudipati 		bfa_ioc_ct2_clk_reset(rb);
899227fab90SKrishna Gudipati 		bfa_ioc_ct2_enable_flash(rb);
900227fab90SKrishna Gudipati 
901227fab90SKrishna Gudipati 		bfa_ioc_ct2_mac_reset(rb);
902227fab90SKrishna Gudipati 
903227fab90SKrishna Gudipati 		bfa_ioc_ct2_clk_reset(rb);
904227fab90SKrishna Gudipati 		bfa_ioc_ct2_enable_flash(rb);
905227fab90SKrishna Gudipati 
906227fab90SKrishna Gudipati 	} else {
907227fab90SKrishna Gudipati 		nfc_ver = readl(rb + CT2_RSC_GPR15_REG);
908227fab90SKrishna Gudipati 
909227fab90SKrishna Gudipati 		if ((nfc_ver >= CT2_NFC_VER_VALID) &&
910227fab90SKrishna Gudipati 		    (wgn == (__A2T_AHB_LOAD | __WGN_READY))) {
911227fab90SKrishna Gudipati 
912227fab90SKrishna Gudipati 			bfa_ioc_ct2_wait_till_nfc_running(rb);
913227fab90SKrishna Gudipati 
914227fab90SKrishna Gudipati 			bfa_ioc_ct2_nfc_clk_reset(rb);
915227fab90SKrishna Gudipati 		} else {
916227fab90SKrishna Gudipati 			bfa_ioc_ct2_nfc_halt(rb);
917227fab90SKrishna Gudipati 
918227fab90SKrishna Gudipati 			bfa_ioc_ct2_clk_reset(rb);
919227fab90SKrishna Gudipati 			bfa_ioc_ct2_mac_reset(rb);
920227fab90SKrishna Gudipati 			bfa_ioc_ct2_clk_reset(rb);
921227fab90SKrishna Gudipati 
922227fab90SKrishna Gudipati 		}
9238b070b4aSKrishna Gudipati 	}
924e1aaab89SVijaya Mohan Guvva 	/*
925e1aaab89SVijaya Mohan Guvva 	* The very first PCIe DMA Read done by LPU fails with a fatal error,
926e1aaab89SVijaya Mohan Guvva 	* when Address Translation Cache (ATC) has been enabled by system BIOS.
927e1aaab89SVijaya Mohan Guvva 	*
928e1aaab89SVijaya Mohan Guvva 	* Workaround:
929e1aaab89SVijaya Mohan Guvva 	* Disable Invalidated Tag Match Enable capability by setting the bit 26
930e1aaab89SVijaya Mohan Guvva 	* of CHIP_MISC_PRG to 0, by default it is set to 1.
931e1aaab89SVijaya Mohan Guvva 	*/
932e1aaab89SVijaya Mohan Guvva 	r32 = readl(rb + CT2_CHIP_MISC_PRG);
933e1aaab89SVijaya Mohan Guvva 	writel((r32 & 0xfbffffff), (rb + CT2_CHIP_MISC_PRG));
934775c7742SKrishna Gudipati 
935a6b963dbSKrishna Gudipati 	/*
936a6b963dbSKrishna Gudipati 	 * Mask the interrupts and clear any
937227fab90SKrishna Gudipati 	 * pending interrupts left by BIOS/EFI
938a6b963dbSKrishna Gudipati 	 */
939227fab90SKrishna Gudipati 
940a6b963dbSKrishna Gudipati 	writel(1, (rb + CT2_LPU0_HOSTFN_MBOX0_MSK));
941a6b963dbSKrishna Gudipati 	writel(1, (rb + CT2_LPU1_HOSTFN_MBOX0_MSK));
942a6b963dbSKrishna Gudipati 
943a6b963dbSKrishna Gudipati 	/* For first time initialization, no need to clear interrupts */
944a6b963dbSKrishna Gudipati 	r32 = readl(rb + HOST_SEM5_REG);
945a6b963dbSKrishna Gudipati 	if (r32 & 0x1) {
946227fab90SKrishna Gudipati 		r32 = readl((rb + CT2_LPU0_HOSTFN_CMD_STAT));
947a6b963dbSKrishna Gudipati 		if (r32 == 1) {
948227fab90SKrishna Gudipati 			writel(1, (rb + CT2_LPU0_HOSTFN_CMD_STAT));
949a6b963dbSKrishna Gudipati 			readl((rb + CT2_LPU0_HOSTFN_CMD_STAT));
950a6b963dbSKrishna Gudipati 		}
951227fab90SKrishna Gudipati 		r32 = readl((rb + CT2_LPU1_HOSTFN_CMD_STAT));
952a6b963dbSKrishna Gudipati 		if (r32 == 1) {
953227fab90SKrishna Gudipati 			writel(1, (rb + CT2_LPU1_HOSTFN_CMD_STAT));
954227fab90SKrishna Gudipati 			readl((rb + CT2_LPU1_HOSTFN_CMD_STAT));
955a6b963dbSKrishna Gudipati 		}
956a6b963dbSKrishna Gudipati 	}
957a6b963dbSKrishna Gudipati 
95810a07379SKrishna Gudipati 	bfa_ioc_ct2_mem_init(rb);
95910a07379SKrishna Gudipati 
960227fab90SKrishna Gudipati 	writel(BFI_IOC_UNINIT, (rb + CT2_BFA_IOC0_STATE_REG));
961227fab90SKrishna Gudipati 	writel(BFI_IOC_UNINIT, (rb + CT2_BFA_IOC1_STATE_REG));
962a6b963dbSKrishna Gudipati 
96311189208SKrishna Gudipati 	return BFA_STATUS_OK;
96411189208SKrishna Gudipati }
965c679b599SVijaya Mohan Guvva 
966c679b599SVijaya Mohan Guvva static void
bfa_ioc_ct_set_cur_ioc_fwstate(struct bfa_ioc_s * ioc,enum bfi_ioc_state fwstate)967c679b599SVijaya Mohan Guvva bfa_ioc_ct_set_cur_ioc_fwstate(struct bfa_ioc_s *ioc,
968c679b599SVijaya Mohan Guvva 		enum bfi_ioc_state fwstate)
969c679b599SVijaya Mohan Guvva {
970c679b599SVijaya Mohan Guvva 	writel(fwstate, ioc->ioc_regs.ioc_fwstate);
971c679b599SVijaya Mohan Guvva }
972c679b599SVijaya Mohan Guvva 
973c679b599SVijaya Mohan Guvva static enum bfi_ioc_state
bfa_ioc_ct_get_cur_ioc_fwstate(struct bfa_ioc_s * ioc)974c679b599SVijaya Mohan Guvva bfa_ioc_ct_get_cur_ioc_fwstate(struct bfa_ioc_s *ioc)
975c679b599SVijaya Mohan Guvva {
976c679b599SVijaya Mohan Guvva 	return (enum bfi_ioc_state)readl(ioc->ioc_regs.ioc_fwstate);
977c679b599SVijaya Mohan Guvva }
978c679b599SVijaya Mohan Guvva 
979c679b599SVijaya Mohan Guvva static void
bfa_ioc_ct_set_alt_ioc_fwstate(struct bfa_ioc_s * ioc,enum bfi_ioc_state fwstate)980c679b599SVijaya Mohan Guvva bfa_ioc_ct_set_alt_ioc_fwstate(struct bfa_ioc_s *ioc,
981c679b599SVijaya Mohan Guvva 		enum bfi_ioc_state fwstate)
982c679b599SVijaya Mohan Guvva {
983c679b599SVijaya Mohan Guvva 	writel(fwstate, ioc->ioc_regs.alt_ioc_fwstate);
984c679b599SVijaya Mohan Guvva }
985c679b599SVijaya Mohan Guvva 
986c679b599SVijaya Mohan Guvva static enum bfi_ioc_state
bfa_ioc_ct_get_alt_ioc_fwstate(struct bfa_ioc_s * ioc)987c679b599SVijaya Mohan Guvva bfa_ioc_ct_get_alt_ioc_fwstate(struct bfa_ioc_s *ioc)
988c679b599SVijaya Mohan Guvva {
989c679b599SVijaya Mohan Guvva 	return (enum bfi_ioc_state) readl(ioc->ioc_regs.alt_ioc_fwstate);
990c679b599SVijaya Mohan Guvva }
991