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 600a20de44SKrishna Gudipati bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg); 6153440260SJing Huang usecnt = readl(ioc->ioc_regs.ioc_usage_reg); 620a20de44SKrishna Gudipati 635fbe25c7SJing Huang /* 640a20de44SKrishna Gudipati * If usage count is 0, always return TRUE. 650a20de44SKrishna Gudipati */ 660a20de44SKrishna Gudipati if (usecnt == 0) { 6753440260SJing Huang writel(1, ioc->ioc_regs.ioc_usage_reg); 685a0adaedSKrishna Gudipati readl(ioc->ioc_regs.ioc_usage_sem_reg); 69f7f73812SMaggie Zhang writel(1, ioc->ioc_regs.ioc_usage_sem_reg); 70f1d584d7SKrishna Gudipati writel(0, ioc->ioc_regs.ioc_fail_sync); 710a20de44SKrishna Gudipati bfa_trc(ioc, usecnt); 720a20de44SKrishna Gudipati return BFA_TRUE; 730a20de44SKrishna Gudipati } 740a20de44SKrishna Gudipati 7553440260SJing Huang ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate); 760a20de44SKrishna Gudipati bfa_trc(ioc, ioc_fwstate); 770a20de44SKrishna Gudipati 785fbe25c7SJing Huang /* 790a20de44SKrishna Gudipati * Use count cannot be non-zero and chip in uninitialized state. 800a20de44SKrishna Gudipati */ 81d4b671c5SJing Huang WARN_ON(ioc_fwstate == BFI_IOC_UNINIT); 820a20de44SKrishna Gudipati 835fbe25c7SJing Huang /* 840a20de44SKrishna Gudipati * Check if another driver with a different firmware is active 850a20de44SKrishna Gudipati */ 860a20de44SKrishna Gudipati bfa_ioc_fwver_get(ioc, &fwhdr); 870a20de44SKrishna Gudipati if (!bfa_ioc_fwver_cmp(ioc, &fwhdr)) { 885a0adaedSKrishna Gudipati readl(ioc->ioc_regs.ioc_usage_sem_reg); 89f7f73812SMaggie Zhang writel(1, ioc->ioc_regs.ioc_usage_sem_reg); 900a20de44SKrishna Gudipati bfa_trc(ioc, usecnt); 910a20de44SKrishna Gudipati return BFA_FALSE; 920a20de44SKrishna Gudipati } 930a20de44SKrishna Gudipati 945fbe25c7SJing Huang /* 950a20de44SKrishna Gudipati * Same firmware version. Increment the reference count. 960a20de44SKrishna Gudipati */ 970a20de44SKrishna Gudipati usecnt++; 9853440260SJing Huang writel(usecnt, ioc->ioc_regs.ioc_usage_reg); 995a0adaedSKrishna Gudipati readl(ioc->ioc_regs.ioc_usage_sem_reg); 100f7f73812SMaggie Zhang writel(1, ioc->ioc_regs.ioc_usage_sem_reg); 1010a20de44SKrishna Gudipati bfa_trc(ioc, usecnt); 1020a20de44SKrishna Gudipati return BFA_TRUE; 1030a20de44SKrishna Gudipati } 1040a20de44SKrishna Gudipati 1050a20de44SKrishna Gudipati static void 1060a20de44SKrishna Gudipati bfa_ioc_ct_firmware_unlock(struct bfa_ioc_s *ioc) 1070a20de44SKrishna Gudipati { 108d1c61f8eSKrishna Gudipati u32 usecnt; 1090a20de44SKrishna Gudipati 1105fbe25c7SJing Huang /* 1110a20de44SKrishna Gudipati * decrement usage count 1120a20de44SKrishna Gudipati */ 1130a20de44SKrishna Gudipati bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg); 11453440260SJing Huang usecnt = readl(ioc->ioc_regs.ioc_usage_reg); 115d4b671c5SJing Huang WARN_ON(usecnt <= 0); 1160a20de44SKrishna Gudipati 1170a20de44SKrishna Gudipati usecnt--; 11853440260SJing Huang writel(usecnt, ioc->ioc_regs.ioc_usage_reg); 1190a20de44SKrishna Gudipati bfa_trc(ioc, usecnt); 1200a20de44SKrishna Gudipati 1215a0adaedSKrishna Gudipati readl(ioc->ioc_regs.ioc_usage_sem_reg); 122f7f73812SMaggie Zhang writel(1, ioc->ioc_regs.ioc_usage_sem_reg); 1230a20de44SKrishna Gudipati } 1240a20de44SKrishna Gudipati 1255fbe25c7SJing Huang /* 1260a20de44SKrishna Gudipati * Notify other functions on HB failure. 1270a20de44SKrishna Gudipati */ 1280a20de44SKrishna Gudipati static void 129f1d584d7SKrishna Gudipati bfa_ioc_ct_notify_fail(struct bfa_ioc_s *ioc) 1300a20de44SKrishna Gudipati { 13111189208SKrishna Gudipati if (bfa_ioc_is_cna(ioc)) { 13253440260SJing Huang writel(__FW_INIT_HALT_P, ioc->ioc_regs.ll_halt); 133f1d584d7SKrishna Gudipati writel(__FW_INIT_HALT_P, ioc->ioc_regs.alt_ll_halt); 1340a20de44SKrishna Gudipati /* Wait for halt to take effect */ 13553440260SJing Huang readl(ioc->ioc_regs.ll_halt); 136f1d584d7SKrishna Gudipati readl(ioc->ioc_regs.alt_ll_halt); 137816e49b8SKrishna Gudipati } else { 13811189208SKrishna Gudipati writel(~0U, ioc->ioc_regs.err_set); 13953440260SJing Huang readl(ioc->ioc_regs.err_set); 140816e49b8SKrishna Gudipati } 1410a20de44SKrishna Gudipati } 1420a20de44SKrishna Gudipati 1435fbe25c7SJing Huang /* 1440a20de44SKrishna Gudipati * Host to LPU mailbox message addresses 1450a20de44SKrishna Gudipati */ 14611189208SKrishna Gudipati static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } ct_fnreg[] = { 1470a20de44SKrishna Gudipati { HOSTFN0_LPU_MBOX0_0, LPU_HOSTFN0_MBOX0_0, HOST_PAGE_NUM_FN0 }, 1480a20de44SKrishna Gudipati { HOSTFN1_LPU_MBOX0_8, LPU_HOSTFN1_MBOX0_8, HOST_PAGE_NUM_FN1 }, 1490a20de44SKrishna Gudipati { HOSTFN2_LPU_MBOX0_0, LPU_HOSTFN2_MBOX0_0, HOST_PAGE_NUM_FN2 }, 1500a20de44SKrishna Gudipati { HOSTFN3_LPU_MBOX0_8, LPU_HOSTFN3_MBOX0_8, HOST_PAGE_NUM_FN3 } 1510a20de44SKrishna Gudipati }; 1520a20de44SKrishna Gudipati 1535fbe25c7SJing Huang /* 1540a20de44SKrishna Gudipati * Host <-> LPU mailbox command/status registers - port 0 1550a20de44SKrishna Gudipati */ 15611189208SKrishna Gudipati static struct { u32 hfn, lpu; } ct_p0reg[] = { 15711189208SKrishna Gudipati { HOSTFN0_LPU0_CMD_STAT, LPU0_HOSTFN0_CMD_STAT }, 15811189208SKrishna Gudipati { HOSTFN1_LPU0_CMD_STAT, LPU0_HOSTFN1_CMD_STAT }, 15911189208SKrishna Gudipati { HOSTFN2_LPU0_CMD_STAT, LPU0_HOSTFN2_CMD_STAT }, 16011189208SKrishna Gudipati { HOSTFN3_LPU0_CMD_STAT, LPU0_HOSTFN3_CMD_STAT } 1610a20de44SKrishna Gudipati }; 1620a20de44SKrishna Gudipati 1635fbe25c7SJing Huang /* 1640a20de44SKrishna Gudipati * Host <-> LPU mailbox command/status registers - port 1 1650a20de44SKrishna Gudipati */ 16611189208SKrishna Gudipati static struct { u32 hfn, lpu; } ct_p1reg[] = { 16711189208SKrishna Gudipati { HOSTFN0_LPU1_CMD_STAT, LPU1_HOSTFN0_CMD_STAT }, 16811189208SKrishna Gudipati { HOSTFN1_LPU1_CMD_STAT, LPU1_HOSTFN1_CMD_STAT }, 16911189208SKrishna Gudipati { HOSTFN2_LPU1_CMD_STAT, LPU1_HOSTFN2_CMD_STAT }, 17011189208SKrishna Gudipati { HOSTFN3_LPU1_CMD_STAT, LPU1_HOSTFN3_CMD_STAT } 17111189208SKrishna Gudipati }; 17211189208SKrishna Gudipati 1738b070b4aSKrishna Gudipati static struct { uint32_t hfn_mbox, lpu_mbox, hfn_pgn, hfn, lpu, lpu_read; } 1748b070b4aSKrishna Gudipati ct2_reg[] = { 17511189208SKrishna Gudipati { CT2_HOSTFN_LPU0_MBOX0, CT2_LPU0_HOSTFN_MBOX0, CT2_HOSTFN_PAGE_NUM, 1768b070b4aSKrishna Gudipati CT2_HOSTFN_LPU0_CMD_STAT, CT2_LPU0_HOSTFN_CMD_STAT, 1778b070b4aSKrishna Gudipati CT2_HOSTFN_LPU0_READ_STAT}, 17811189208SKrishna Gudipati { CT2_HOSTFN_LPU1_MBOX0, CT2_LPU1_HOSTFN_MBOX0, CT2_HOSTFN_PAGE_NUM, 1798b070b4aSKrishna Gudipati CT2_HOSTFN_LPU1_CMD_STAT, CT2_LPU1_HOSTFN_CMD_STAT, 1808b070b4aSKrishna Gudipati CT2_HOSTFN_LPU1_READ_STAT}, 1810a20de44SKrishna Gudipati }; 1820a20de44SKrishna Gudipati 1830a20de44SKrishna Gudipati static void 1840a20de44SKrishna Gudipati bfa_ioc_ct_reg_init(struct bfa_ioc_s *ioc) 1850a20de44SKrishna Gudipati { 18653440260SJing Huang void __iomem *rb; 1870a20de44SKrishna Gudipati int pcifn = bfa_ioc_pcifn(ioc); 1880a20de44SKrishna Gudipati 1890a20de44SKrishna Gudipati rb = bfa_ioc_bar0(ioc); 1900a20de44SKrishna Gudipati 19111189208SKrishna Gudipati ioc->ioc_regs.hfn_mbox = rb + ct_fnreg[pcifn].hfn_mbox; 19211189208SKrishna Gudipati ioc->ioc_regs.lpu_mbox = rb + ct_fnreg[pcifn].lpu_mbox; 19311189208SKrishna Gudipati ioc->ioc_regs.host_page_num_fn = rb + ct_fnreg[pcifn].hfn_pgn; 1940a20de44SKrishna Gudipati 1950a20de44SKrishna Gudipati if (ioc->port_id == 0) { 1960a20de44SKrishna Gudipati ioc->ioc_regs.heartbeat = rb + BFA_IOC0_HBEAT_REG; 1970a20de44SKrishna Gudipati ioc->ioc_regs.ioc_fwstate = rb + BFA_IOC0_STATE_REG; 198f1d584d7SKrishna Gudipati ioc->ioc_regs.alt_ioc_fwstate = rb + BFA_IOC1_STATE_REG; 19911189208SKrishna Gudipati ioc->ioc_regs.hfn_mbox_cmd = rb + ct_p0reg[pcifn].hfn; 20011189208SKrishna Gudipati ioc->ioc_regs.lpu_mbox_cmd = rb + ct_p0reg[pcifn].lpu; 2010a20de44SKrishna Gudipati ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P0; 202f1d584d7SKrishna Gudipati ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P1; 2030a20de44SKrishna Gudipati } else { 2040a20de44SKrishna Gudipati ioc->ioc_regs.heartbeat = (rb + BFA_IOC1_HBEAT_REG); 2050a20de44SKrishna Gudipati ioc->ioc_regs.ioc_fwstate = (rb + BFA_IOC1_STATE_REG); 206f1d584d7SKrishna Gudipati ioc->ioc_regs.alt_ioc_fwstate = rb + BFA_IOC0_STATE_REG; 20711189208SKrishna Gudipati ioc->ioc_regs.hfn_mbox_cmd = rb + ct_p1reg[pcifn].hfn; 20811189208SKrishna Gudipati ioc->ioc_regs.lpu_mbox_cmd = rb + ct_p1reg[pcifn].lpu; 2090a20de44SKrishna Gudipati ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P1; 210f1d584d7SKrishna Gudipati ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P0; 2110a20de44SKrishna Gudipati } 2120a20de44SKrishna Gudipati 2130a20de44SKrishna Gudipati /* 2140a20de44SKrishna Gudipati * PSS control registers 2150a20de44SKrishna Gudipati */ 2160a20de44SKrishna Gudipati ioc->ioc_regs.pss_ctl_reg = (rb + PSS_CTL_REG); 2178b651b42SKrishna Gudipati ioc->ioc_regs.pss_err_status_reg = (rb + PSS_ERR_STATUS_REG); 21811189208SKrishna Gudipati ioc->ioc_regs.app_pll_fast_ctl_reg = (rb + APP_PLL_LCLK_CTL_REG); 21911189208SKrishna Gudipati ioc->ioc_regs.app_pll_slow_ctl_reg = (rb + APP_PLL_SCLK_CTL_REG); 2200a20de44SKrishna Gudipati 2210a20de44SKrishna Gudipati /* 2220a20de44SKrishna Gudipati * IOC semaphore registers and serialization 2230a20de44SKrishna Gudipati */ 2240a20de44SKrishna Gudipati ioc->ioc_regs.ioc_sem_reg = (rb + HOST_SEM0_REG); 2250a20de44SKrishna Gudipati ioc->ioc_regs.ioc_usage_sem_reg = (rb + HOST_SEM1_REG); 2260a20de44SKrishna Gudipati ioc->ioc_regs.ioc_init_sem_reg = (rb + HOST_SEM2_REG); 2270a20de44SKrishna Gudipati ioc->ioc_regs.ioc_usage_reg = (rb + BFA_FW_USE_COUNT); 228f1d584d7SKrishna Gudipati ioc->ioc_regs.ioc_fail_sync = (rb + BFA_IOC_FAIL_SYNC); 2290a20de44SKrishna Gudipati 2305fbe25c7SJing Huang /* 2310a20de44SKrishna Gudipati * sram memory access 2320a20de44SKrishna Gudipati */ 2330a20de44SKrishna Gudipati ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START); 2340a20de44SKrishna Gudipati ioc->ioc_regs.smem_pg0 = BFI_IOC_SMEM_PG0_CT; 235816e49b8SKrishna Gudipati 236816e49b8SKrishna Gudipati /* 237816e49b8SKrishna Gudipati * err set reg : for notification of hb failure in fcmode 238816e49b8SKrishna Gudipati */ 239816e49b8SKrishna Gudipati ioc->ioc_regs.err_set = (rb + ERR_SET_REG); 2400a20de44SKrishna Gudipati } 2410a20de44SKrishna Gudipati 24211189208SKrishna Gudipati static void 24311189208SKrishna Gudipati bfa_ioc_ct2_reg_init(struct bfa_ioc_s *ioc) 24411189208SKrishna Gudipati { 24511189208SKrishna Gudipati void __iomem *rb; 24611189208SKrishna Gudipati int port = bfa_ioc_portid(ioc); 24711189208SKrishna Gudipati 24811189208SKrishna Gudipati rb = bfa_ioc_bar0(ioc); 24911189208SKrishna Gudipati 25011189208SKrishna Gudipati ioc->ioc_regs.hfn_mbox = rb + ct2_reg[port].hfn_mbox; 25111189208SKrishna Gudipati ioc->ioc_regs.lpu_mbox = rb + ct2_reg[port].lpu_mbox; 25211189208SKrishna Gudipati ioc->ioc_regs.host_page_num_fn = rb + ct2_reg[port].hfn_pgn; 25311189208SKrishna Gudipati ioc->ioc_regs.hfn_mbox_cmd = rb + ct2_reg[port].hfn; 25411189208SKrishna Gudipati ioc->ioc_regs.lpu_mbox_cmd = rb + ct2_reg[port].lpu; 2558b070b4aSKrishna Gudipati ioc->ioc_regs.lpu_read_stat = rb + ct2_reg[port].lpu_read; 25611189208SKrishna Gudipati 25711189208SKrishna Gudipati if (port == 0) { 25811189208SKrishna Gudipati ioc->ioc_regs.heartbeat = rb + CT2_BFA_IOC0_HBEAT_REG; 25911189208SKrishna Gudipati ioc->ioc_regs.ioc_fwstate = rb + CT2_BFA_IOC0_STATE_REG; 26011189208SKrishna Gudipati ioc->ioc_regs.alt_ioc_fwstate = rb + CT2_BFA_IOC1_STATE_REG; 26111189208SKrishna Gudipati ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P0; 26211189208SKrishna Gudipati ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P1; 26311189208SKrishna Gudipati } else { 26411189208SKrishna Gudipati ioc->ioc_regs.heartbeat = (rb + CT2_BFA_IOC1_HBEAT_REG); 26511189208SKrishna Gudipati ioc->ioc_regs.ioc_fwstate = (rb + CT2_BFA_IOC1_STATE_REG); 26611189208SKrishna Gudipati ioc->ioc_regs.alt_ioc_fwstate = rb + CT2_BFA_IOC0_STATE_REG; 26711189208SKrishna Gudipati ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P1; 26811189208SKrishna Gudipati ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P0; 26911189208SKrishna Gudipati } 27011189208SKrishna Gudipati 27111189208SKrishna Gudipati /* 27211189208SKrishna Gudipati * PSS control registers 27311189208SKrishna Gudipati */ 27411189208SKrishna Gudipati ioc->ioc_regs.pss_ctl_reg = (rb + PSS_CTL_REG); 27511189208SKrishna Gudipati ioc->ioc_regs.pss_err_status_reg = (rb + PSS_ERR_STATUS_REG); 27611189208SKrishna Gudipati ioc->ioc_regs.app_pll_fast_ctl_reg = (rb + CT2_APP_PLL_LCLK_CTL_REG); 27711189208SKrishna Gudipati ioc->ioc_regs.app_pll_slow_ctl_reg = (rb + CT2_APP_PLL_SCLK_CTL_REG); 27811189208SKrishna Gudipati 27911189208SKrishna Gudipati /* 28011189208SKrishna Gudipati * IOC semaphore registers and serialization 28111189208SKrishna Gudipati */ 28211189208SKrishna Gudipati ioc->ioc_regs.ioc_sem_reg = (rb + CT2_HOST_SEM0_REG); 28311189208SKrishna Gudipati ioc->ioc_regs.ioc_usage_sem_reg = (rb + CT2_HOST_SEM1_REG); 28411189208SKrishna Gudipati ioc->ioc_regs.ioc_init_sem_reg = (rb + CT2_HOST_SEM2_REG); 285775c7742SKrishna Gudipati ioc->ioc_regs.ioc_usage_reg = (rb + CT2_BFA_FW_USE_COUNT); 286775c7742SKrishna Gudipati ioc->ioc_regs.ioc_fail_sync = (rb + CT2_BFA_IOC_FAIL_SYNC); 28711189208SKrishna Gudipati 28811189208SKrishna Gudipati /* 28911189208SKrishna Gudipati * sram memory access 29011189208SKrishna Gudipati */ 29111189208SKrishna Gudipati ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START); 29211189208SKrishna Gudipati ioc->ioc_regs.smem_pg0 = BFI_IOC_SMEM_PG0_CT; 29311189208SKrishna Gudipati 29411189208SKrishna Gudipati /* 29511189208SKrishna Gudipati * err set reg : for notification of hb failure in fcmode 29611189208SKrishna Gudipati */ 29711189208SKrishna Gudipati ioc->ioc_regs.err_set = (rb + ERR_SET_REG); 29811189208SKrishna Gudipati } 29911189208SKrishna Gudipati 3005fbe25c7SJing Huang /* 3010a20de44SKrishna Gudipati * Initialize IOC to port mapping. 3020a20de44SKrishna Gudipati */ 3030a20de44SKrishna Gudipati 3040a20de44SKrishna Gudipati #define FNC_PERS_FN_SHIFT(__fn) ((__fn) * 8) 3050a20de44SKrishna Gudipati static void 3060a20de44SKrishna Gudipati bfa_ioc_ct_map_port(struct bfa_ioc_s *ioc) 3070a20de44SKrishna Gudipati { 30853440260SJing Huang void __iomem *rb = ioc->pcidev.pci_bar_kva; 309d1c61f8eSKrishna Gudipati u32 r32; 3100a20de44SKrishna Gudipati 3115fbe25c7SJing Huang /* 3120a20de44SKrishna Gudipati * For catapult, base port id on personality register and IOC type 3130a20de44SKrishna Gudipati */ 31453440260SJing Huang r32 = readl(rb + FNC_PERS_REG); 3150a20de44SKrishna Gudipati r32 >>= FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc)); 3160a20de44SKrishna Gudipati ioc->port_id = (r32 & __F0_PORT_MAP_MK) >> __F0_PORT_MAP_SH; 3170a20de44SKrishna Gudipati 3180a20de44SKrishna Gudipati bfa_trc(ioc, bfa_ioc_pcifn(ioc)); 3190a20de44SKrishna Gudipati bfa_trc(ioc, ioc->port_id); 3200a20de44SKrishna Gudipati } 3210a20de44SKrishna Gudipati 32211189208SKrishna Gudipati static void 32311189208SKrishna Gudipati bfa_ioc_ct2_map_port(struct bfa_ioc_s *ioc) 32411189208SKrishna Gudipati { 3255a0adaedSKrishna Gudipati void __iomem *rb = ioc->pcidev.pci_bar_kva; 3265a0adaedSKrishna Gudipati u32 r32; 3275a0adaedSKrishna Gudipati 3285a0adaedSKrishna Gudipati r32 = readl(rb + CT2_HOSTFN_PERSONALITY0); 3295a0adaedSKrishna Gudipati ioc->port_id = ((r32 & __FC_LL_PORT_MAP__MK) >> __FC_LL_PORT_MAP__SH); 33011189208SKrishna Gudipati 33111189208SKrishna Gudipati bfa_trc(ioc, bfa_ioc_pcifn(ioc)); 33211189208SKrishna Gudipati bfa_trc(ioc, ioc->port_id); 33311189208SKrishna Gudipati } 33411189208SKrishna Gudipati 3355fbe25c7SJing Huang /* 3360a20de44SKrishna Gudipati * Set interrupt mode for a function: INTX or MSIX 3370a20de44SKrishna Gudipati */ 3380a20de44SKrishna Gudipati static void 3390a20de44SKrishna Gudipati bfa_ioc_ct_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix) 3400a20de44SKrishna Gudipati { 34153440260SJing Huang void __iomem *rb = ioc->pcidev.pci_bar_kva; 342d1c61f8eSKrishna Gudipati u32 r32, mode; 3430a20de44SKrishna Gudipati 34453440260SJing Huang r32 = readl(rb + FNC_PERS_REG); 3450a20de44SKrishna Gudipati bfa_trc(ioc, r32); 3460a20de44SKrishna Gudipati 3470a20de44SKrishna Gudipati mode = (r32 >> FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc))) & 3480a20de44SKrishna Gudipati __F0_INTX_STATUS; 3490a20de44SKrishna Gudipati 3505fbe25c7SJing Huang /* 3510a20de44SKrishna Gudipati * If already in desired mode, do not change anything 3520a20de44SKrishna Gudipati */ 35311189208SKrishna Gudipati if ((!msix && mode) || (msix && !mode)) 3540a20de44SKrishna Gudipati return; 3550a20de44SKrishna Gudipati 3560a20de44SKrishna Gudipati if (msix) 3570a20de44SKrishna Gudipati mode = __F0_INTX_STATUS_MSIX; 3580a20de44SKrishna Gudipati else 3590a20de44SKrishna Gudipati mode = __F0_INTX_STATUS_INTA; 3600a20de44SKrishna Gudipati 3610a20de44SKrishna Gudipati r32 &= ~(__F0_INTX_STATUS << FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc))); 3620a20de44SKrishna Gudipati r32 |= (mode << FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc))); 3630a20de44SKrishna Gudipati bfa_trc(ioc, r32); 3640a20de44SKrishna Gudipati 36553440260SJing Huang writel(r32, rb + FNC_PERS_REG); 3660a20de44SKrishna Gudipati } 3670a20de44SKrishna Gudipati 3688b070b4aSKrishna Gudipati bfa_boolean_t 3698b070b4aSKrishna Gudipati bfa_ioc_ct2_lpu_read_stat(struct bfa_ioc_s *ioc) 3708b070b4aSKrishna Gudipati { 3718b070b4aSKrishna Gudipati u32 r32; 3728b070b4aSKrishna Gudipati 3738b070b4aSKrishna Gudipati r32 = readl(ioc->ioc_regs.lpu_read_stat); 3748b070b4aSKrishna Gudipati if (r32) { 3758b070b4aSKrishna Gudipati writel(1, ioc->ioc_regs.lpu_read_stat); 3768b070b4aSKrishna Gudipati return BFA_TRUE; 3778b070b4aSKrishna Gudipati } 3788b070b4aSKrishna Gudipati 3798b070b4aSKrishna Gudipati return BFA_FALSE; 3808b070b4aSKrishna Gudipati } 3818b070b4aSKrishna 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 3890a20de44SKrishna Gudipati bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg); 39053440260SJing Huang writel(0, ioc->ioc_regs.ioc_usage_reg); 3915a0adaedSKrishna Gudipati readl(ioc->ioc_regs.ioc_usage_sem_reg); 392f7f73812SMaggie Zhang writel(1, ioc->ioc_regs.ioc_usage_sem_reg); 3930a20de44SKrishna Gudipati 3947ac83b1fSKrishna Gudipati writel(0, ioc->ioc_regs.ioc_fail_sync); 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; 5438b070b4aSKrishna Gudipati hwif_ct2.ioc_lpu_read_stat = bfa_ioc_ct2_lpu_read_stat; 54411189208SKrishna Gudipati hwif_ct2.ioc_isr_mode_set = NULL; 54511189208SKrishna Gudipati ioc->ioc_hwif = &hwif_ct2; 54611189208SKrishna Gudipati } 54711189208SKrishna Gudipati 54811189208SKrishna Gudipati /* 5493fd45980SKrishna Gudipati * Workaround for MSI-X resource allocation for catapult-2 with no asic block 55011189208SKrishna Gudipati */ 5513fd45980SKrishna Gudipati #define HOSTFN_MSIX_DEFAULT 64 55210a07379SKrishna Gudipati #define HOSTFN_MSIX_VT_INDEX_MBOX_ERR 0x30138 55311189208SKrishna Gudipati #define HOSTFN_MSIX_VT_OFST_NUMVT 0x3013c 55411189208SKrishna Gudipati #define __MSIX_VT_NUMVT__MK 0x003ff800 55511189208SKrishna Gudipati #define __MSIX_VT_NUMVT__SH 11 55611189208SKrishna Gudipati #define __MSIX_VT_NUMVT_(_v) ((_v) << __MSIX_VT_NUMVT__SH) 55710a07379SKrishna Gudipati #define __MSIX_VT_OFST_ 0x000007ff 55811189208SKrishna Gudipati void 55911189208SKrishna Gudipati bfa_ioc_ct2_poweron(struct bfa_ioc_s *ioc) 56011189208SKrishna Gudipati { 56111189208SKrishna Gudipati void __iomem *rb = ioc->pcidev.pci_bar_kva; 56211189208SKrishna Gudipati u32 r32; 56311189208SKrishna Gudipati 56411189208SKrishna Gudipati r32 = readl(rb + HOSTFN_MSIX_VT_OFST_NUMVT); 56510a07379SKrishna Gudipati if (r32 & __MSIX_VT_NUMVT__MK) { 56610a07379SKrishna Gudipati writel(r32 & __MSIX_VT_OFST_, 56710a07379SKrishna Gudipati rb + HOSTFN_MSIX_VT_INDEX_MBOX_ERR); 56811189208SKrishna Gudipati return; 56910a07379SKrishna Gudipati } 57011189208SKrishna Gudipati 57111189208SKrishna Gudipati writel(__MSIX_VT_NUMVT_(HOSTFN_MSIX_DEFAULT - 1) | 57211189208SKrishna Gudipati HOSTFN_MSIX_DEFAULT * bfa_ioc_pcifn(ioc), 57311189208SKrishna Gudipati rb + HOSTFN_MSIX_VT_OFST_NUMVT); 57410a07379SKrishna Gudipati writel(HOSTFN_MSIX_DEFAULT * bfa_ioc_pcifn(ioc), 57510a07379SKrishna Gudipati rb + HOSTFN_MSIX_VT_INDEX_MBOX_ERR); 576a36c61f9SKrishna Gudipati } 577a36c61f9SKrishna Gudipati 578a36c61f9SKrishna Gudipati bfa_status_t 57911189208SKrishna Gudipati bfa_ioc_ct_pll_init(void __iomem *rb, enum bfi_asic_mode mode) 580a36c61f9SKrishna Gudipati { 581a36c61f9SKrishna Gudipati u32 pll_sclk, pll_fclk, r32; 58211189208SKrishna Gudipati bfa_boolean_t fcmode = (mode == BFI_ASIC_MODE_FC); 583a36c61f9SKrishna Gudipati 58411189208SKrishna Gudipati pll_sclk = __APP_PLL_SCLK_LRESETN | __APP_PLL_SCLK_ENARST | 58511189208SKrishna Gudipati __APP_PLL_SCLK_RSEL200500 | __APP_PLL_SCLK_P0_1(3U) | 58611189208SKrishna Gudipati __APP_PLL_SCLK_JITLMT0_1(3U) | 58711189208SKrishna Gudipati __APP_PLL_SCLK_CNTLMT0_1(1U); 58811189208SKrishna Gudipati pll_fclk = __APP_PLL_LCLK_LRESETN | __APP_PLL_LCLK_ENARST | 58911189208SKrishna Gudipati __APP_PLL_LCLK_RSEL200500 | __APP_PLL_LCLK_P0_1(3U) | 59011189208SKrishna Gudipati __APP_PLL_LCLK_JITLMT0_1(3U) | 59111189208SKrishna Gudipati __APP_PLL_LCLK_CNTLMT0_1(1U); 59211189208SKrishna Gudipati 593a36c61f9SKrishna Gudipati if (fcmode) { 59453440260SJing Huang writel(0, (rb + OP_MODE)); 59553440260SJing Huang writel(__APP_EMS_CMLCKSEL | __APP_EMS_REFCKBUFEN2 | 59653440260SJing Huang __APP_EMS_CHANNEL_SEL, (rb + ETH_MAC_SER_REG)); 597a36c61f9SKrishna Gudipati } else { 59853440260SJing Huang writel(__GLOBAL_FCOE_MODE, (rb + OP_MODE)); 59953440260SJing Huang writel(__APP_EMS_REFCKBUFEN1, (rb + ETH_MAC_SER_REG)); 600a36c61f9SKrishna Gudipati } 60153440260SJing Huang writel(BFI_IOC_UNINIT, (rb + BFA_IOC0_STATE_REG)); 60253440260SJing Huang writel(BFI_IOC_UNINIT, (rb + BFA_IOC1_STATE_REG)); 60353440260SJing Huang writel(0xffffffffU, (rb + HOSTFN0_INT_MSK)); 60453440260SJing Huang writel(0xffffffffU, (rb + HOSTFN1_INT_MSK)); 60553440260SJing Huang writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS)); 60653440260SJing Huang writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS)); 60753440260SJing Huang writel(0xffffffffU, (rb + HOSTFN0_INT_MSK)); 60853440260SJing Huang writel(0xffffffffU, (rb + HOSTFN1_INT_MSK)); 60911189208SKrishna Gudipati writel(pll_sclk | __APP_PLL_SCLK_LOGIC_SOFT_RESET, 61011189208SKrishna Gudipati rb + APP_PLL_SCLK_CTL_REG); 61111189208SKrishna Gudipati writel(pll_fclk | __APP_PLL_LCLK_LOGIC_SOFT_RESET, 61211189208SKrishna Gudipati rb + APP_PLL_LCLK_CTL_REG); 61311189208SKrishna Gudipati writel(pll_sclk | __APP_PLL_SCLK_LOGIC_SOFT_RESET | 61411189208SKrishna Gudipati __APP_PLL_SCLK_ENABLE, rb + APP_PLL_SCLK_CTL_REG); 61511189208SKrishna Gudipati writel(pll_fclk | __APP_PLL_LCLK_LOGIC_SOFT_RESET | 61611189208SKrishna Gudipati __APP_PLL_LCLK_ENABLE, rb + APP_PLL_LCLK_CTL_REG); 61753440260SJing Huang readl(rb + HOSTFN0_INT_MSK); 6186a18b167SJing Huang udelay(2000); 61953440260SJing Huang writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS)); 62053440260SJing Huang writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS)); 62111189208SKrishna Gudipati writel(pll_sclk | __APP_PLL_SCLK_ENABLE, rb + APP_PLL_SCLK_CTL_REG); 62211189208SKrishna Gudipati writel(pll_fclk | __APP_PLL_LCLK_ENABLE, rb + APP_PLL_LCLK_CTL_REG); 62311189208SKrishna Gudipati 624a36c61f9SKrishna Gudipati if (!fcmode) { 62553440260SJing Huang writel(__PMM_1T_RESET_P, (rb + PMM_1T_RESET_REG_P0)); 62653440260SJing Huang writel(__PMM_1T_RESET_P, (rb + PMM_1T_RESET_REG_P1)); 627a36c61f9SKrishna Gudipati } 62853440260SJing Huang r32 = readl((rb + PSS_CTL_REG)); 629a36c61f9SKrishna Gudipati r32 &= ~__PSS_LMEM_RESET; 63053440260SJing Huang writel(r32, (rb + PSS_CTL_REG)); 6316a18b167SJing Huang udelay(1000); 632a36c61f9SKrishna Gudipati if (!fcmode) { 63353440260SJing Huang writel(0, (rb + PMM_1T_RESET_REG_P0)); 63453440260SJing Huang writel(0, (rb + PMM_1T_RESET_REG_P1)); 635a36c61f9SKrishna Gudipati } 636a36c61f9SKrishna Gudipati 63753440260SJing Huang writel(__EDRAM_BISTR_START, (rb + MBIST_CTL_REG)); 6386a18b167SJing Huang udelay(1000); 63953440260SJing Huang r32 = readl((rb + MBIST_STAT_REG)); 64053440260SJing Huang writel(0, (rb + MBIST_CTL_REG)); 641a36c61f9SKrishna Gudipati return BFA_STATUS_OK; 642a36c61f9SKrishna Gudipati } 64311189208SKrishna Gudipati 64411189208SKrishna Gudipati static void 64510a07379SKrishna Gudipati bfa_ioc_ct2_sclk_init(void __iomem *rb) 64611189208SKrishna Gudipati { 64711189208SKrishna Gudipati u32 r32; 64811189208SKrishna Gudipati 64911189208SKrishna Gudipati /* 65011189208SKrishna Gudipati * put s_clk PLL and PLL FSM in reset 65111189208SKrishna Gudipati */ 65211189208SKrishna Gudipati r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG)); 65311189208SKrishna Gudipati r32 &= ~(__APP_PLL_SCLK_ENABLE | __APP_PLL_SCLK_LRESETN); 65411189208SKrishna Gudipati r32 |= (__APP_PLL_SCLK_ENARST | __APP_PLL_SCLK_BYPASS | 65511189208SKrishna Gudipati __APP_PLL_SCLK_LOGIC_SOFT_RESET); 65611189208SKrishna Gudipati writel(r32, (rb + CT2_APP_PLL_SCLK_CTL_REG)); 65711189208SKrishna Gudipati 65811189208SKrishna Gudipati /* 65910a07379SKrishna Gudipati * Ignore mode and program for the max clock (which is FC16) 66010a07379SKrishna Gudipati * Firmware/NFC will do the PLL init appropiately 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); 66410a07379SKrishna Gudipati writel(r32, (rb + CT2_APP_PLL_SCLK_CTL_REG)); 66511189208SKrishna Gudipati 66611189208SKrishna Gudipati /* 667775c7742SKrishna 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 static void 69010a07379SKrishna Gudipati bfa_ioc_ct2_lclk_init(void __iomem *rb) 69111189208SKrishna Gudipati { 69211189208SKrishna Gudipati u32 r32; 69311189208SKrishna Gudipati 69411189208SKrishna Gudipati /* 69511189208SKrishna Gudipati * put l_clk PLL and PLL FSM in reset 69611189208SKrishna Gudipati */ 69711189208SKrishna Gudipati r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG)); 69811189208SKrishna Gudipati r32 &= ~(__APP_PLL_LCLK_ENABLE | __APP_PLL_LCLK_LRESETN); 69911189208SKrishna Gudipati r32 |= (__APP_PLL_LCLK_ENARST | __APP_PLL_LCLK_BYPASS | 70011189208SKrishna Gudipati __APP_PLL_LCLK_LOGIC_SOFT_RESET); 70111189208SKrishna Gudipati writel(r32, (rb + CT2_APP_PLL_LCLK_CTL_REG)); 70211189208SKrishna Gudipati 70311189208SKrishna Gudipati /* 70410a07379SKrishna Gudipati * set LPU speed (set for FC16 which will work for other modes) 70511189208SKrishna Gudipati */ 70611189208SKrishna Gudipati r32 = readl((rb + CT2_CHIP_MISC_PRG)); 70710a07379SKrishna Gudipati writel(r32, (rb + CT2_CHIP_MISC_PRG)); 70811189208SKrishna Gudipati 70911189208SKrishna Gudipati /* 71010a07379SKrishna Gudipati * set LPU half speed (set for FC16 which will work for other modes) 71111189208SKrishna Gudipati */ 71211189208SKrishna Gudipati r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG)); 71310a07379SKrishna Gudipati writel(r32, (rb + CT2_APP_PLL_LCLK_CTL_REG)); 71411189208SKrishna Gudipati 71511189208SKrishna Gudipati /* 71610a07379SKrishna Gudipati * set lclk for mode (set for FC16) 71711189208SKrishna Gudipati */ 71811189208SKrishna Gudipati r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG)); 71911189208SKrishna Gudipati r32 &= (__P_LCLK_PLL_LOCK | __APP_LPUCLK_HALFSPEED); 72011189208SKrishna Gudipati r32 |= 0x20c1731b; 72111189208SKrishna Gudipati writel(r32, (rb + CT2_APP_PLL_LCLK_CTL_REG)); 72211189208SKrishna Gudipati 72311189208SKrishna Gudipati /* 72411189208SKrishna Gudipati * poll for s_clk lock or delay 1ms 72511189208SKrishna Gudipati */ 72611189208SKrishna Gudipati udelay(1000); 72710a07379SKrishna Gudipati } 72810a07379SKrishna Gudipati 72910a07379SKrishna Gudipati static void 73010a07379SKrishna Gudipati bfa_ioc_ct2_mem_init(void __iomem *rb) 73110a07379SKrishna Gudipati { 73210a07379SKrishna Gudipati u32 r32; 73310a07379SKrishna Gudipati 73410a07379SKrishna Gudipati r32 = readl((rb + PSS_CTL_REG)); 73510a07379SKrishna Gudipati r32 &= ~__PSS_LMEM_RESET; 73610a07379SKrishna Gudipati writel(r32, (rb + PSS_CTL_REG)); 73710a07379SKrishna Gudipati udelay(1000); 73810a07379SKrishna Gudipati 73910a07379SKrishna Gudipati writel(__EDRAM_BISTR_START, (rb + CT2_MBIST_CTL_REG)); 74010a07379SKrishna Gudipati udelay(1000); 74110a07379SKrishna Gudipati writel(0, (rb + CT2_MBIST_CTL_REG)); 74210a07379SKrishna Gudipati } 74310a07379SKrishna Gudipati 74410a07379SKrishna Gudipati void 74510a07379SKrishna Gudipati bfa_ioc_ct2_mac_reset(void __iomem *rb) 74610a07379SKrishna Gudipati { 74710a07379SKrishna Gudipati /* put port0, port1 MAC & AHB in reset */ 74810a07379SKrishna Gudipati writel((__CSI_MAC_RESET | __CSI_MAC_AHB_RESET), 74910a07379SKrishna Gudipati rb + CT2_CSI_MAC_CONTROL_REG(0)); 75010a07379SKrishna Gudipati writel((__CSI_MAC_RESET | __CSI_MAC_AHB_RESET), 75110a07379SKrishna Gudipati rb + CT2_CSI_MAC_CONTROL_REG(1)); 75211189208SKrishna Gudipati } 75311189208SKrishna Gudipati 754227fab90SKrishna Gudipati static void 755227fab90SKrishna Gudipati bfa_ioc_ct2_enable_flash(void __iomem *rb) 756227fab90SKrishna Gudipati { 757227fab90SKrishna Gudipati u32 r32; 758227fab90SKrishna Gudipati 759227fab90SKrishna Gudipati r32 = readl((rb + PSS_GPIO_OUT_REG)); 760227fab90SKrishna Gudipati writel(r32 & ~1, (rb + PSS_GPIO_OUT_REG)); 761227fab90SKrishna Gudipati r32 = readl((rb + PSS_GPIO_OE_REG)); 762227fab90SKrishna Gudipati writel(r32 | 1, (rb + PSS_GPIO_OE_REG)); 763227fab90SKrishna Gudipati } 764227fab90SKrishna Gudipati 76510a07379SKrishna Gudipati #define CT2_NFC_MAX_DELAY 1000 766227fab90SKrishna Gudipati #define CT2_NFC_PAUSE_MAX_DELAY 4000 767227fab90SKrishna Gudipati #define CT2_NFC_VER_VALID 0x147 768227fab90SKrishna Gudipati #define CT2_NFC_STATE_RUNNING 0x20000001 769a6b963dbSKrishna Gudipati #define BFA_IOC_PLL_POLL 1000000 770a6b963dbSKrishna Gudipati 771a6b963dbSKrishna Gudipati static bfa_boolean_t 772a6b963dbSKrishna Gudipati bfa_ioc_ct2_nfc_halted(void __iomem *rb) 773a6b963dbSKrishna Gudipati { 774a6b963dbSKrishna Gudipati u32 r32; 775a6b963dbSKrishna Gudipati 776a6b963dbSKrishna Gudipati r32 = readl(rb + CT2_NFC_CSR_SET_REG); 777a6b963dbSKrishna Gudipati if (r32 & __NFC_CONTROLLER_HALTED) 778a6b963dbSKrishna Gudipati return BFA_TRUE; 779a6b963dbSKrishna Gudipati 780a6b963dbSKrishna Gudipati return BFA_FALSE; 781a6b963dbSKrishna Gudipati } 782a6b963dbSKrishna Gudipati 783a6b963dbSKrishna Gudipati static void 784227fab90SKrishna Gudipati bfa_ioc_ct2_nfc_halt(void __iomem *rb) 785227fab90SKrishna Gudipati { 786227fab90SKrishna Gudipati int i; 787227fab90SKrishna Gudipati 788227fab90SKrishna Gudipati writel(__HALT_NFC_CONTROLLER, rb + CT2_NFC_CSR_SET_REG); 789227fab90SKrishna Gudipati for (i = 0; i < CT2_NFC_MAX_DELAY; i++) { 790227fab90SKrishna Gudipati if (bfa_ioc_ct2_nfc_halted(rb)) 791227fab90SKrishna Gudipati break; 792227fab90SKrishna Gudipati udelay(1000); 793227fab90SKrishna Gudipati } 794227fab90SKrishna Gudipati WARN_ON(!bfa_ioc_ct2_nfc_halted(rb)); 795227fab90SKrishna Gudipati } 796227fab90SKrishna Gudipati 797227fab90SKrishna Gudipati static void 798a6b963dbSKrishna Gudipati bfa_ioc_ct2_nfc_resume(void __iomem *rb) 799a6b963dbSKrishna Gudipati { 800a6b963dbSKrishna Gudipati u32 r32; 801a6b963dbSKrishna Gudipati int i; 802a6b963dbSKrishna Gudipati 803a6b963dbSKrishna Gudipati writel(__HALT_NFC_CONTROLLER, rb + CT2_NFC_CSR_CLR_REG); 804a6b963dbSKrishna Gudipati for (i = 0; i < CT2_NFC_MAX_DELAY; i++) { 805a6b963dbSKrishna Gudipati r32 = readl(rb + CT2_NFC_CSR_SET_REG); 806a6b963dbSKrishna Gudipati if (!(r32 & __NFC_CONTROLLER_HALTED)) 807a6b963dbSKrishna Gudipati return; 808a6b963dbSKrishna Gudipati udelay(1000); 809a6b963dbSKrishna Gudipati } 810a6b963dbSKrishna Gudipati WARN_ON(1); 811a6b963dbSKrishna Gudipati } 812a6b963dbSKrishna Gudipati 813227fab90SKrishna Gudipati static void 814227fab90SKrishna Gudipati bfa_ioc_ct2_clk_reset(void __iomem *rb) 81511189208SKrishna Gudipati { 816227fab90SKrishna Gudipati u32 r32; 8178b070b4aSKrishna Gudipati 81810a07379SKrishna Gudipati bfa_ioc_ct2_sclk_init(rb); 81910a07379SKrishna Gudipati bfa_ioc_ct2_lclk_init(rb); 82010a07379SKrishna Gudipati 82110a07379SKrishna Gudipati /* 82210a07379SKrishna Gudipati * release soft reset on s_clk & l_clk 82310a07379SKrishna Gudipati */ 824227fab90SKrishna Gudipati r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG)); 82510a07379SKrishna Gudipati writel(r32 & ~__APP_PLL_SCLK_LOGIC_SOFT_RESET, 82610a07379SKrishna Gudipati (rb + CT2_APP_PLL_SCLK_CTL_REG)); 82710a07379SKrishna Gudipati 828227fab90SKrishna Gudipati r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG)); 82910a07379SKrishna Gudipati writel(r32 & ~__APP_PLL_LCLK_LOGIC_SOFT_RESET, 83010a07379SKrishna Gudipati (rb + CT2_APP_PLL_LCLK_CTL_REG)); 831227fab90SKrishna Gudipati 832a6b963dbSKrishna Gudipati } 83311189208SKrishna Gudipati 834227fab90SKrishna Gudipati static void 835227fab90SKrishna Gudipati bfa_ioc_ct2_nfc_clk_reset(void __iomem *rb) 836227fab90SKrishna Gudipati { 837227fab90SKrishna Gudipati u32 r32, i; 838227fab90SKrishna Gudipati 839227fab90SKrishna Gudipati r32 = readl((rb + PSS_CTL_REG)); 840227fab90SKrishna Gudipati r32 |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET); 841227fab90SKrishna Gudipati writel(r32, (rb + PSS_CTL_REG)); 842227fab90SKrishna Gudipati 843227fab90SKrishna Gudipati writel(__RESET_AND_START_SCLK_LCLK_PLLS, rb + CT2_CSI_FW_CTL_SET_REG); 844227fab90SKrishna Gudipati 845227fab90SKrishna Gudipati for (i = 0; i < BFA_IOC_PLL_POLL; i++) { 846227fab90SKrishna Gudipati r32 = readl(rb + CT2_NFC_FLASH_STS_REG); 847227fab90SKrishna Gudipati 848227fab90SKrishna Gudipati if ((r32 & __FLASH_PLL_INIT_AND_RESET_IN_PROGRESS)) 849227fab90SKrishna Gudipati break; 850227fab90SKrishna Gudipati } 851227fab90SKrishna Gudipati WARN_ON(!(r32 & __FLASH_PLL_INIT_AND_RESET_IN_PROGRESS)); 852227fab90SKrishna Gudipati 853227fab90SKrishna Gudipati for (i = 0; i < BFA_IOC_PLL_POLL; i++) { 854227fab90SKrishna Gudipati r32 = readl(rb + CT2_NFC_FLASH_STS_REG); 855227fab90SKrishna Gudipati 856227fab90SKrishna Gudipati if (!(r32 & __FLASH_PLL_INIT_AND_RESET_IN_PROGRESS)) 857227fab90SKrishna Gudipati break; 858227fab90SKrishna Gudipati } 859227fab90SKrishna Gudipati WARN_ON((r32 & __FLASH_PLL_INIT_AND_RESET_IN_PROGRESS)); 860227fab90SKrishna Gudipati 861227fab90SKrishna Gudipati r32 = readl(rb + CT2_CSI_FW_CTL_REG); 862227fab90SKrishna Gudipati WARN_ON((r32 & __RESET_AND_START_SCLK_LCLK_PLLS)); 863227fab90SKrishna Gudipati } 864227fab90SKrishna Gudipati 865227fab90SKrishna Gudipati static void 866227fab90SKrishna Gudipati bfa_ioc_ct2_wait_till_nfc_running(void __iomem *rb) 867227fab90SKrishna Gudipati { 868227fab90SKrishna Gudipati u32 r32; 869227fab90SKrishna Gudipati int i; 870227fab90SKrishna Gudipati 871227fab90SKrishna Gudipati if (bfa_ioc_ct2_nfc_halted(rb)) 872227fab90SKrishna Gudipati bfa_ioc_ct2_nfc_resume(rb); 873227fab90SKrishna Gudipati for (i = 0; i < CT2_NFC_PAUSE_MAX_DELAY; i++) { 874227fab90SKrishna Gudipati r32 = readl(rb + CT2_NFC_STS_REG); 875227fab90SKrishna Gudipati if (r32 == CT2_NFC_STATE_RUNNING) 876227fab90SKrishna Gudipati return; 877227fab90SKrishna Gudipati udelay(1000); 878227fab90SKrishna Gudipati } 879227fab90SKrishna Gudipati 880227fab90SKrishna Gudipati r32 = readl(rb + CT2_NFC_STS_REG); 881227fab90SKrishna Gudipati WARN_ON(!(r32 == CT2_NFC_STATE_RUNNING)); 882227fab90SKrishna Gudipati } 883227fab90SKrishna Gudipati 884227fab90SKrishna Gudipati bfa_status_t 885227fab90SKrishna Gudipati bfa_ioc_ct2_pll_init(void __iomem *rb, enum bfi_asic_mode mode) 886227fab90SKrishna Gudipati { 887227fab90SKrishna Gudipati u32 wgn, r32, nfc_ver; 888227fab90SKrishna Gudipati 889227fab90SKrishna Gudipati wgn = readl(rb + CT2_WGN_STATUS); 890227fab90SKrishna Gudipati 89110a07379SKrishna Gudipati if (wgn == (__WGN_READY | __GLBL_PF_VF_CFG_RDY)) { 892227fab90SKrishna Gudipati /* 893227fab90SKrishna Gudipati * If flash is corrupted, enable flash explicitly 894227fab90SKrishna Gudipati */ 895227fab90SKrishna Gudipati bfa_ioc_ct2_clk_reset(rb); 896227fab90SKrishna Gudipati bfa_ioc_ct2_enable_flash(rb); 897227fab90SKrishna Gudipati 898227fab90SKrishna Gudipati bfa_ioc_ct2_mac_reset(rb); 899227fab90SKrishna Gudipati 900227fab90SKrishna Gudipati bfa_ioc_ct2_clk_reset(rb); 901227fab90SKrishna Gudipati bfa_ioc_ct2_enable_flash(rb); 902227fab90SKrishna Gudipati 903227fab90SKrishna Gudipati } else { 904227fab90SKrishna Gudipati nfc_ver = readl(rb + CT2_RSC_GPR15_REG); 905227fab90SKrishna Gudipati 906227fab90SKrishna Gudipati if ((nfc_ver >= CT2_NFC_VER_VALID) && 907227fab90SKrishna Gudipati (wgn == (__A2T_AHB_LOAD | __WGN_READY))) { 908227fab90SKrishna Gudipati 909227fab90SKrishna Gudipati bfa_ioc_ct2_wait_till_nfc_running(rb); 910227fab90SKrishna Gudipati 911227fab90SKrishna Gudipati bfa_ioc_ct2_nfc_clk_reset(rb); 912227fab90SKrishna Gudipati } else { 913227fab90SKrishna Gudipati bfa_ioc_ct2_nfc_halt(rb); 914227fab90SKrishna Gudipati 915227fab90SKrishna Gudipati bfa_ioc_ct2_clk_reset(rb); 916227fab90SKrishna Gudipati bfa_ioc_ct2_mac_reset(rb); 917227fab90SKrishna Gudipati bfa_ioc_ct2_clk_reset(rb); 918227fab90SKrishna Gudipati 919227fab90SKrishna Gudipati } 9208b070b4aSKrishna Gudipati } 921*e1aaab89SVijaya Mohan Guvva /* 922*e1aaab89SVijaya Mohan Guvva * The very first PCIe DMA Read done by LPU fails with a fatal error, 923*e1aaab89SVijaya Mohan Guvva * when Address Translation Cache (ATC) has been enabled by system BIOS. 924*e1aaab89SVijaya Mohan Guvva * 925*e1aaab89SVijaya Mohan Guvva * Workaround: 926*e1aaab89SVijaya Mohan Guvva * Disable Invalidated Tag Match Enable capability by setting the bit 26 927*e1aaab89SVijaya Mohan Guvva * of CHIP_MISC_PRG to 0, by default it is set to 1. 928*e1aaab89SVijaya Mohan Guvva */ 929*e1aaab89SVijaya Mohan Guvva r32 = readl(rb + CT2_CHIP_MISC_PRG); 930*e1aaab89SVijaya Mohan Guvva writel((r32 & 0xfbffffff), (rb + CT2_CHIP_MISC_PRG)); 931775c7742SKrishna Gudipati 932a6b963dbSKrishna Gudipati /* 933a6b963dbSKrishna Gudipati * Mask the interrupts and clear any 934227fab90SKrishna Gudipati * pending interrupts left by BIOS/EFI 935a6b963dbSKrishna Gudipati */ 936227fab90SKrishna Gudipati 937a6b963dbSKrishna Gudipati writel(1, (rb + CT2_LPU0_HOSTFN_MBOX0_MSK)); 938a6b963dbSKrishna Gudipati writel(1, (rb + CT2_LPU1_HOSTFN_MBOX0_MSK)); 939a6b963dbSKrishna Gudipati 940a6b963dbSKrishna Gudipati /* For first time initialization, no need to clear interrupts */ 941a6b963dbSKrishna Gudipati r32 = readl(rb + HOST_SEM5_REG); 942a6b963dbSKrishna Gudipati if (r32 & 0x1) { 943227fab90SKrishna Gudipati r32 = readl((rb + CT2_LPU0_HOSTFN_CMD_STAT)); 944a6b963dbSKrishna Gudipati if (r32 == 1) { 945227fab90SKrishna Gudipati writel(1, (rb + CT2_LPU0_HOSTFN_CMD_STAT)); 946a6b963dbSKrishna Gudipati readl((rb + CT2_LPU0_HOSTFN_CMD_STAT)); 947a6b963dbSKrishna Gudipati } 948227fab90SKrishna Gudipati r32 = readl((rb + CT2_LPU1_HOSTFN_CMD_STAT)); 949a6b963dbSKrishna Gudipati if (r32 == 1) { 950227fab90SKrishna Gudipati writel(1, (rb + CT2_LPU1_HOSTFN_CMD_STAT)); 951227fab90SKrishna Gudipati readl((rb + CT2_LPU1_HOSTFN_CMD_STAT)); 952a6b963dbSKrishna Gudipati } 953a6b963dbSKrishna Gudipati } 954a6b963dbSKrishna Gudipati 95510a07379SKrishna Gudipati bfa_ioc_ct2_mem_init(rb); 95610a07379SKrishna Gudipati 957227fab90SKrishna Gudipati writel(BFI_IOC_UNINIT, (rb + CT2_BFA_IOC0_STATE_REG)); 958227fab90SKrishna Gudipati writel(BFI_IOC_UNINIT, (rb + CT2_BFA_IOC1_STATE_REG)); 959a6b963dbSKrishna Gudipati 96011189208SKrishna Gudipati return BFA_STATUS_OK; 96111189208SKrishna Gudipati } 962