1*52fa7bf9SThomas 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_CB);
170a20de44SKrishna Gudipati
18c679b599SVijaya Mohan Guvva #define bfa_ioc_cb_join_pos(__ioc) ((u32) (1 << BFA_IOC_CB_JOIN_SH))
19c679b599SVijaya Mohan Guvva
200a20de44SKrishna Gudipati /*
210a20de44SKrishna Gudipati * forward declarations
220a20de44SKrishna Gudipati */
230a20de44SKrishna Gudipati static bfa_boolean_t bfa_ioc_cb_firmware_lock(struct bfa_ioc_s *ioc);
240a20de44SKrishna Gudipati static void bfa_ioc_cb_firmware_unlock(struct bfa_ioc_s *ioc);
250a20de44SKrishna Gudipati static void bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc);
260a20de44SKrishna Gudipati static void bfa_ioc_cb_map_port(struct bfa_ioc_s *ioc);
270a20de44SKrishna Gudipati static void bfa_ioc_cb_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix);
28f1d584d7SKrishna Gudipati static void bfa_ioc_cb_notify_fail(struct bfa_ioc_s *ioc);
290a20de44SKrishna Gudipati static void bfa_ioc_cb_ownership_reset(struct bfa_ioc_s *ioc);
3045d7f0ccSJing Huang static bfa_boolean_t bfa_ioc_cb_sync_start(struct bfa_ioc_s *ioc);
31f1d584d7SKrishna Gudipati static void bfa_ioc_cb_sync_join(struct bfa_ioc_s *ioc);
32f1d584d7SKrishna Gudipati static void bfa_ioc_cb_sync_leave(struct bfa_ioc_s *ioc);
33f1d584d7SKrishna Gudipati static void bfa_ioc_cb_sync_ack(struct bfa_ioc_s *ioc);
34f1d584d7SKrishna Gudipati static bfa_boolean_t bfa_ioc_cb_sync_complete(struct bfa_ioc_s *ioc);
35c679b599SVijaya Mohan Guvva static void bfa_ioc_cb_set_cur_ioc_fwstate(
36c679b599SVijaya Mohan Guvva struct bfa_ioc_s *ioc, enum bfi_ioc_state fwstate);
37c679b599SVijaya Mohan Guvva static enum bfi_ioc_state bfa_ioc_cb_get_cur_ioc_fwstate(struct bfa_ioc_s *ioc);
38c679b599SVijaya Mohan Guvva static void bfa_ioc_cb_set_alt_ioc_fwstate(
39c679b599SVijaya Mohan Guvva struct bfa_ioc_s *ioc, enum bfi_ioc_state fwstate);
40c679b599SVijaya Mohan Guvva static enum bfi_ioc_state bfa_ioc_cb_get_alt_ioc_fwstate(struct bfa_ioc_s *ioc);
410a20de44SKrishna Gudipati
4252f94b6fSMaggie static struct bfa_ioc_hwif_s hwif_cb;
430a20de44SKrishna Gudipati
445fbe25c7SJing Huang /*
450a20de44SKrishna Gudipati * Called from bfa_ioc_attach() to map asic specific calls.
460a20de44SKrishna Gudipati */
470a20de44SKrishna Gudipati void
bfa_ioc_set_cb_hwif(struct bfa_ioc_s * ioc)480a20de44SKrishna Gudipati bfa_ioc_set_cb_hwif(struct bfa_ioc_s *ioc)
490a20de44SKrishna Gudipati {
50293f82d5SJing Huang hwif_cb.ioc_pll_init = bfa_ioc_cb_pll_init;
51293f82d5SJing Huang hwif_cb.ioc_firmware_lock = bfa_ioc_cb_firmware_lock;
52293f82d5SJing Huang hwif_cb.ioc_firmware_unlock = bfa_ioc_cb_firmware_unlock;
53293f82d5SJing Huang hwif_cb.ioc_reg_init = bfa_ioc_cb_reg_init;
54293f82d5SJing Huang hwif_cb.ioc_map_port = bfa_ioc_cb_map_port;
55293f82d5SJing Huang hwif_cb.ioc_isr_mode_set = bfa_ioc_cb_isr_mode_set;
56f1d584d7SKrishna Gudipati hwif_cb.ioc_notify_fail = bfa_ioc_cb_notify_fail;
57293f82d5SJing Huang hwif_cb.ioc_ownership_reset = bfa_ioc_cb_ownership_reset;
5845d7f0ccSJing Huang hwif_cb.ioc_sync_start = bfa_ioc_cb_sync_start;
59f1d584d7SKrishna Gudipati hwif_cb.ioc_sync_join = bfa_ioc_cb_sync_join;
60f1d584d7SKrishna Gudipati hwif_cb.ioc_sync_leave = bfa_ioc_cb_sync_leave;
61f1d584d7SKrishna Gudipati hwif_cb.ioc_sync_ack = bfa_ioc_cb_sync_ack;
62f1d584d7SKrishna Gudipati hwif_cb.ioc_sync_complete = bfa_ioc_cb_sync_complete;
63c679b599SVijaya Mohan Guvva hwif_cb.ioc_set_fwstate = bfa_ioc_cb_set_cur_ioc_fwstate;
64c679b599SVijaya Mohan Guvva hwif_cb.ioc_get_fwstate = bfa_ioc_cb_get_cur_ioc_fwstate;
65c679b599SVijaya Mohan Guvva hwif_cb.ioc_set_alt_fwstate = bfa_ioc_cb_set_alt_ioc_fwstate;
66c679b599SVijaya Mohan Guvva hwif_cb.ioc_get_alt_fwstate = bfa_ioc_cb_get_alt_ioc_fwstate;
67293f82d5SJing Huang
680a20de44SKrishna Gudipati ioc->ioc_hwif = &hwif_cb;
690a20de44SKrishna Gudipati }
700a20de44SKrishna Gudipati
718f4bfaddSJing Huang /*
720a20de44SKrishna Gudipati * Return true if firmware of current driver matches the running firmware.
730a20de44SKrishna Gudipati */
740a20de44SKrishna Gudipati static bfa_boolean_t
bfa_ioc_cb_firmware_lock(struct bfa_ioc_s * ioc)750a20de44SKrishna Gudipati bfa_ioc_cb_firmware_lock(struct bfa_ioc_s *ioc)
760a20de44SKrishna Gudipati {
7728d358d0SVijaya Mohan Guvva enum bfi_ioc_state alt_fwstate, cur_fwstate;
7828d358d0SVijaya Mohan Guvva struct bfi_ioc_image_hdr_s fwhdr;
7928d358d0SVijaya Mohan Guvva
8028d358d0SVijaya Mohan Guvva cur_fwstate = bfa_ioc_cb_get_cur_ioc_fwstate(ioc);
8128d358d0SVijaya Mohan Guvva bfa_trc(ioc, cur_fwstate);
8228d358d0SVijaya Mohan Guvva alt_fwstate = bfa_ioc_cb_get_alt_ioc_fwstate(ioc);
8328d358d0SVijaya Mohan Guvva bfa_trc(ioc, alt_fwstate);
8428d358d0SVijaya Mohan Guvva
8528d358d0SVijaya Mohan Guvva /*
8628d358d0SVijaya Mohan Guvva * Uninit implies this is the only driver as of now.
8728d358d0SVijaya Mohan Guvva */
8828d358d0SVijaya Mohan Guvva if (cur_fwstate == BFI_IOC_UNINIT)
8928d358d0SVijaya Mohan Guvva return BFA_TRUE;
9028d358d0SVijaya Mohan Guvva /*
9128d358d0SVijaya Mohan Guvva * Check if another driver with a different firmware is active
9228d358d0SVijaya Mohan Guvva */
9328d358d0SVijaya Mohan Guvva bfa_ioc_fwver_get(ioc, &fwhdr);
9428d358d0SVijaya Mohan Guvva if (!bfa_ioc_fwver_cmp(ioc, &fwhdr) &&
9528d358d0SVijaya Mohan Guvva alt_fwstate != BFI_IOC_DISABLED) {
9628d358d0SVijaya Mohan Guvva bfa_trc(ioc, alt_fwstate);
9728d358d0SVijaya Mohan Guvva return BFA_FALSE;
9828d358d0SVijaya Mohan Guvva }
9928d358d0SVijaya Mohan Guvva
1000a20de44SKrishna Gudipati return BFA_TRUE;
1010a20de44SKrishna Gudipati }
1020a20de44SKrishna Gudipati
1030a20de44SKrishna Gudipati static void
bfa_ioc_cb_firmware_unlock(struct bfa_ioc_s * ioc)1040a20de44SKrishna Gudipati bfa_ioc_cb_firmware_unlock(struct bfa_ioc_s *ioc)
1050a20de44SKrishna Gudipati {
1060a20de44SKrishna Gudipati }
1070a20de44SKrishna Gudipati
1085fbe25c7SJing Huang /*
1090a20de44SKrishna Gudipati * Notify other functions on HB failure.
1100a20de44SKrishna Gudipati */
1110a20de44SKrishna Gudipati static void
bfa_ioc_cb_notify_fail(struct bfa_ioc_s * ioc)112f1d584d7SKrishna Gudipati bfa_ioc_cb_notify_fail(struct bfa_ioc_s *ioc)
1130a20de44SKrishna Gudipati {
11411189208SKrishna Gudipati writel(~0U, ioc->ioc_regs.err_set);
11553440260SJing Huang readl(ioc->ioc_regs.err_set);
1160a20de44SKrishna Gudipati }
1170a20de44SKrishna Gudipati
1185fbe25c7SJing Huang /*
1190a20de44SKrishna Gudipati * Host to LPU mailbox message addresses
1200a20de44SKrishna Gudipati */
121d1c61f8eSKrishna Gudipati static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } iocreg_fnreg[] = {
1220a20de44SKrishna Gudipati { HOSTFN0_LPU_MBOX0_0, LPU_HOSTFN0_MBOX0_0, HOST_PAGE_NUM_FN0 },
1230a20de44SKrishna Gudipati { HOSTFN1_LPU_MBOX0_8, LPU_HOSTFN1_MBOX0_8, HOST_PAGE_NUM_FN1 }
1240a20de44SKrishna Gudipati };
1250a20de44SKrishna Gudipati
1265fbe25c7SJing Huang /*
1270a20de44SKrishna Gudipati * Host <-> LPU mailbox command/status registers
1280a20de44SKrishna Gudipati */
129d1c61f8eSKrishna Gudipati static struct { u32 hfn, lpu; } iocreg_mbcmd[] = {
130a36c61f9SKrishna Gudipati
1310a20de44SKrishna Gudipati { HOSTFN0_LPU0_CMD_STAT, LPU0_HOSTFN0_CMD_STAT },
1320a20de44SKrishna Gudipati { HOSTFN1_LPU1_CMD_STAT, LPU1_HOSTFN1_CMD_STAT }
1330a20de44SKrishna Gudipati };
1340a20de44SKrishna Gudipati
1350a20de44SKrishna Gudipati static void
bfa_ioc_cb_reg_init(struct bfa_ioc_s * ioc)1360a20de44SKrishna Gudipati bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc)
1370a20de44SKrishna Gudipati {
13853440260SJing Huang void __iomem *rb;
1390a20de44SKrishna Gudipati int pcifn = bfa_ioc_pcifn(ioc);
1400a20de44SKrishna Gudipati
1410a20de44SKrishna Gudipati rb = bfa_ioc_bar0(ioc);
1420a20de44SKrishna Gudipati
1430a20de44SKrishna Gudipati ioc->ioc_regs.hfn_mbox = rb + iocreg_fnreg[pcifn].hfn_mbox;
1440a20de44SKrishna Gudipati ioc->ioc_regs.lpu_mbox = rb + iocreg_fnreg[pcifn].lpu_mbox;
1450a20de44SKrishna Gudipati ioc->ioc_regs.host_page_num_fn = rb + iocreg_fnreg[pcifn].hfn_pgn;
1460a20de44SKrishna Gudipati
1470a20de44SKrishna Gudipati if (ioc->port_id == 0) {
1480a20de44SKrishna Gudipati ioc->ioc_regs.heartbeat = rb + BFA_IOC0_HBEAT_REG;
1490a20de44SKrishna Gudipati ioc->ioc_regs.ioc_fwstate = rb + BFA_IOC0_STATE_REG;
150f1d584d7SKrishna Gudipati ioc->ioc_regs.alt_ioc_fwstate = rb + BFA_IOC1_STATE_REG;
1510a20de44SKrishna Gudipati } else {
1520a20de44SKrishna Gudipati ioc->ioc_regs.heartbeat = (rb + BFA_IOC1_HBEAT_REG);
1530a20de44SKrishna Gudipati ioc->ioc_regs.ioc_fwstate = (rb + BFA_IOC1_STATE_REG);
154f1d584d7SKrishna Gudipati ioc->ioc_regs.alt_ioc_fwstate = (rb + BFA_IOC0_STATE_REG);
1550a20de44SKrishna Gudipati }
1560a20de44SKrishna Gudipati
1575fbe25c7SJing Huang /*
1580a20de44SKrishna Gudipati * Host <-> LPU mailbox command/status registers
1590a20de44SKrishna Gudipati */
1600a20de44SKrishna Gudipati ioc->ioc_regs.hfn_mbox_cmd = rb + iocreg_mbcmd[pcifn].hfn;
1610a20de44SKrishna Gudipati ioc->ioc_regs.lpu_mbox_cmd = rb + iocreg_mbcmd[pcifn].lpu;
1620a20de44SKrishna Gudipati
1630a20de44SKrishna Gudipati /*
1640a20de44SKrishna Gudipati * PSS control registers
1650a20de44SKrishna Gudipati */
1660a20de44SKrishna Gudipati ioc->ioc_regs.pss_ctl_reg = (rb + PSS_CTL_REG);
1678b651b42SKrishna Gudipati ioc->ioc_regs.pss_err_status_reg = (rb + PSS_ERR_STATUS_REG);
16811189208SKrishna Gudipati ioc->ioc_regs.app_pll_fast_ctl_reg = (rb + APP_PLL_LCLK_CTL_REG);
16911189208SKrishna Gudipati ioc->ioc_regs.app_pll_slow_ctl_reg = (rb + APP_PLL_SCLK_CTL_REG);
1700a20de44SKrishna Gudipati
1710a20de44SKrishna Gudipati /*
1720a20de44SKrishna Gudipati * IOC semaphore registers and serialization
1730a20de44SKrishna Gudipati */
1740a20de44SKrishna Gudipati ioc->ioc_regs.ioc_sem_reg = (rb + HOST_SEM0_REG);
1750a20de44SKrishna Gudipati ioc->ioc_regs.ioc_init_sem_reg = (rb + HOST_SEM2_REG);
1760a20de44SKrishna Gudipati
1775fbe25c7SJing Huang /*
1780a20de44SKrishna Gudipati * sram memory access
1790a20de44SKrishna Gudipati */
1800a20de44SKrishna Gudipati ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START);
1810a20de44SKrishna Gudipati ioc->ioc_regs.smem_pg0 = BFI_IOC_SMEM_PG0_CB;
1820a20de44SKrishna Gudipati
1830a20de44SKrishna Gudipati /*
1840a20de44SKrishna Gudipati * err set reg : for notification of hb failure
1850a20de44SKrishna Gudipati */
1860a20de44SKrishna Gudipati ioc->ioc_regs.err_set = (rb + ERR_SET_REG);
1870a20de44SKrishna Gudipati }
1880a20de44SKrishna Gudipati
1895fbe25c7SJing Huang /*
1900a20de44SKrishna Gudipati * Initialize IOC to port mapping.
1910a20de44SKrishna Gudipati */
192a36c61f9SKrishna Gudipati
1930a20de44SKrishna Gudipati static void
bfa_ioc_cb_map_port(struct bfa_ioc_s * ioc)1940a20de44SKrishna Gudipati bfa_ioc_cb_map_port(struct bfa_ioc_s *ioc)
1950a20de44SKrishna Gudipati {
1965fbe25c7SJing Huang /*
1970a20de44SKrishna Gudipati * For crossbow, port id is same as pci function.
1980a20de44SKrishna Gudipati */
1990a20de44SKrishna Gudipati ioc->port_id = bfa_ioc_pcifn(ioc);
200a36c61f9SKrishna Gudipati
2010a20de44SKrishna Gudipati bfa_trc(ioc, ioc->port_id);
2020a20de44SKrishna Gudipati }
2030a20de44SKrishna Gudipati
2045fbe25c7SJing Huang /*
2050a20de44SKrishna Gudipati * Set interrupt mode for a function: INTX or MSIX
2060a20de44SKrishna Gudipati */
2070a20de44SKrishna Gudipati static void
bfa_ioc_cb_isr_mode_set(struct bfa_ioc_s * ioc,bfa_boolean_t msix)2080a20de44SKrishna Gudipati bfa_ioc_cb_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix)
2090a20de44SKrishna Gudipati {
2100a20de44SKrishna Gudipati }
2110a20de44SKrishna Gudipati
2125fbe25c7SJing Huang /*
21345d7f0ccSJing Huang * Synchronized IOC failure processing routines
21445d7f0ccSJing Huang */
21545d7f0ccSJing Huang static bfa_boolean_t
bfa_ioc_cb_sync_start(struct bfa_ioc_s * ioc)21645d7f0ccSJing Huang bfa_ioc_cb_sync_start(struct bfa_ioc_s *ioc)
21745d7f0ccSJing Huang {
218c679b599SVijaya Mohan Guvva u32 ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
219c679b599SVijaya Mohan Guvva
220c679b599SVijaya Mohan Guvva /**
221c679b599SVijaya Mohan Guvva * Driver load time. If the join bit is set,
222c679b599SVijaya Mohan Guvva * it is due to an unclean exit by the driver for this
223c679b599SVijaya Mohan Guvva * PCI fn in the previous incarnation. Whoever comes here first
224c679b599SVijaya Mohan Guvva * should clean it up, no matter which PCI fn.
225c679b599SVijaya Mohan Guvva */
226c679b599SVijaya Mohan Guvva if (ioc_fwstate & BFA_IOC_CB_JOIN_MASK) {
227c679b599SVijaya Mohan Guvva writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
228c679b599SVijaya Mohan Guvva writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate);
229c679b599SVijaya Mohan Guvva return BFA_TRUE;
230c679b599SVijaya Mohan Guvva }
231c679b599SVijaya Mohan Guvva
23245d7f0ccSJing Huang return bfa_ioc_cb_sync_complete(ioc);
23345d7f0ccSJing Huang }
23445d7f0ccSJing Huang
23545d7f0ccSJing Huang /*
2360a20de44SKrishna Gudipati * Cleanup hw semaphore and usecnt registers
2370a20de44SKrishna Gudipati */
2380a20de44SKrishna Gudipati static void
bfa_ioc_cb_ownership_reset(struct bfa_ioc_s * ioc)2390a20de44SKrishna Gudipati bfa_ioc_cb_ownership_reset(struct bfa_ioc_s *ioc)
2400a20de44SKrishna Gudipati {
2410a20de44SKrishna Gudipati
2420a20de44SKrishna Gudipati /*
2430a20de44SKrishna Gudipati * Read the hw sem reg to make sure that it is locked
2440a20de44SKrishna Gudipati * before we clear it. If it is not locked, writing 1
2450a20de44SKrishna Gudipati * will lock it instead of clearing it.
2460a20de44SKrishna Gudipati */
24753440260SJing Huang readl(ioc->ioc_regs.ioc_sem_reg);
248f7f73812SMaggie Zhang writel(1, ioc->ioc_regs.ioc_sem_reg);
2490a20de44SKrishna Gudipati }
250a36c61f9SKrishna Gudipati
2518f4bfaddSJing Huang /*
252f1d584d7SKrishna Gudipati * Synchronized IOC failure processing routines
253f1d584d7SKrishna Gudipati */
254f1d584d7SKrishna Gudipati static void
bfa_ioc_cb_sync_join(struct bfa_ioc_s * ioc)255f1d584d7SKrishna Gudipati bfa_ioc_cb_sync_join(struct bfa_ioc_s *ioc)
256f1d584d7SKrishna Gudipati {
257c679b599SVijaya Mohan Guvva u32 r32 = readl(ioc->ioc_regs.ioc_fwstate);
258c679b599SVijaya Mohan Guvva u32 join_pos = bfa_ioc_cb_join_pos(ioc);
259c679b599SVijaya Mohan Guvva
260c679b599SVijaya Mohan Guvva writel((r32 | join_pos), ioc->ioc_regs.ioc_fwstate);
261f1d584d7SKrishna Gudipati }
262a36c61f9SKrishna Gudipati
263f1d584d7SKrishna Gudipati static void
bfa_ioc_cb_sync_leave(struct bfa_ioc_s * ioc)264f1d584d7SKrishna Gudipati bfa_ioc_cb_sync_leave(struct bfa_ioc_s *ioc)
265f1d584d7SKrishna Gudipati {
266c679b599SVijaya Mohan Guvva u32 r32 = readl(ioc->ioc_regs.ioc_fwstate);
267c679b599SVijaya Mohan Guvva u32 join_pos = bfa_ioc_cb_join_pos(ioc);
268c679b599SVijaya Mohan Guvva
269c679b599SVijaya Mohan Guvva writel((r32 & ~join_pos), ioc->ioc_regs.ioc_fwstate);
270c679b599SVijaya Mohan Guvva }
271c679b599SVijaya Mohan Guvva
272c679b599SVijaya Mohan Guvva static void
bfa_ioc_cb_set_cur_ioc_fwstate(struct bfa_ioc_s * ioc,enum bfi_ioc_state fwstate)273c679b599SVijaya Mohan Guvva bfa_ioc_cb_set_cur_ioc_fwstate(struct bfa_ioc_s *ioc,
274c679b599SVijaya Mohan Guvva enum bfi_ioc_state fwstate)
275c679b599SVijaya Mohan Guvva {
276c679b599SVijaya Mohan Guvva u32 r32 = readl(ioc->ioc_regs.ioc_fwstate);
277c679b599SVijaya Mohan Guvva
278c679b599SVijaya Mohan Guvva writel((fwstate | (r32 & BFA_IOC_CB_JOIN_MASK)),
279c679b599SVijaya Mohan Guvva ioc->ioc_regs.ioc_fwstate);
280c679b599SVijaya Mohan Guvva }
281c679b599SVijaya Mohan Guvva
282c679b599SVijaya Mohan Guvva static enum bfi_ioc_state
bfa_ioc_cb_get_cur_ioc_fwstate(struct bfa_ioc_s * ioc)283c679b599SVijaya Mohan Guvva bfa_ioc_cb_get_cur_ioc_fwstate(struct bfa_ioc_s *ioc)
284c679b599SVijaya Mohan Guvva {
285c679b599SVijaya Mohan Guvva return (enum bfi_ioc_state)(readl(ioc->ioc_regs.ioc_fwstate) &
286c679b599SVijaya Mohan Guvva BFA_IOC_CB_FWSTATE_MASK);
287c679b599SVijaya Mohan Guvva }
288c679b599SVijaya Mohan Guvva
289c679b599SVijaya Mohan Guvva static void
bfa_ioc_cb_set_alt_ioc_fwstate(struct bfa_ioc_s * ioc,enum bfi_ioc_state fwstate)290c679b599SVijaya Mohan Guvva bfa_ioc_cb_set_alt_ioc_fwstate(struct bfa_ioc_s *ioc,
291c679b599SVijaya Mohan Guvva enum bfi_ioc_state fwstate)
292c679b599SVijaya Mohan Guvva {
293c679b599SVijaya Mohan Guvva u32 r32 = readl(ioc->ioc_regs.alt_ioc_fwstate);
294c679b599SVijaya Mohan Guvva
295c679b599SVijaya Mohan Guvva writel((fwstate | (r32 & BFA_IOC_CB_JOIN_MASK)),
296c679b599SVijaya Mohan Guvva ioc->ioc_regs.alt_ioc_fwstate);
297c679b599SVijaya Mohan Guvva }
298c679b599SVijaya Mohan Guvva
299c679b599SVijaya Mohan Guvva static enum bfi_ioc_state
bfa_ioc_cb_get_alt_ioc_fwstate(struct bfa_ioc_s * ioc)300c679b599SVijaya Mohan Guvva bfa_ioc_cb_get_alt_ioc_fwstate(struct bfa_ioc_s *ioc)
301c679b599SVijaya Mohan Guvva {
302c679b599SVijaya Mohan Guvva return (enum bfi_ioc_state)(readl(ioc->ioc_regs.alt_ioc_fwstate) &
303c679b599SVijaya Mohan Guvva BFA_IOC_CB_FWSTATE_MASK);
304f1d584d7SKrishna Gudipati }
305f1d584d7SKrishna Gudipati
306f1d584d7SKrishna Gudipati static void
bfa_ioc_cb_sync_ack(struct bfa_ioc_s * ioc)307f1d584d7SKrishna Gudipati bfa_ioc_cb_sync_ack(struct bfa_ioc_s *ioc)
308f1d584d7SKrishna Gudipati {
309c679b599SVijaya Mohan Guvva bfa_ioc_cb_set_cur_ioc_fwstate(ioc, BFI_IOC_FAIL);
310f1d584d7SKrishna Gudipati }
311f1d584d7SKrishna Gudipati
312f1d584d7SKrishna Gudipati static bfa_boolean_t
bfa_ioc_cb_sync_complete(struct bfa_ioc_s * ioc)313f1d584d7SKrishna Gudipati bfa_ioc_cb_sync_complete(struct bfa_ioc_s *ioc)
314f1d584d7SKrishna Gudipati {
315c679b599SVijaya Mohan Guvva u32 fwstate, alt_fwstate;
316c679b599SVijaya Mohan Guvva fwstate = bfa_ioc_cb_get_cur_ioc_fwstate(ioc);
317f1d584d7SKrishna Gudipati
3188f4bfaddSJing Huang /*
319f1d584d7SKrishna Gudipati * At this point, this IOC is hoding the hw sem in the
320f1d584d7SKrishna Gudipati * start path (fwcheck) OR in the disable/enable path
321f1d584d7SKrishna Gudipati * OR to check if the other IOC has acknowledged failure.
322f1d584d7SKrishna Gudipati *
323f1d584d7SKrishna Gudipati * So, this IOC can be in UNINIT, INITING, DISABLED, FAIL
324f1d584d7SKrishna Gudipati * or in MEMTEST states. In a normal scenario, this IOC
325f1d584d7SKrishna Gudipati * can not be in OP state when this function is called.
326f1d584d7SKrishna Gudipati *
327f1d584d7SKrishna Gudipati * However, this IOC could still be in OP state when
328f1d584d7SKrishna Gudipati * the OS driver is starting up, if the OptROM code has
329f1d584d7SKrishna Gudipati * left it in that state.
330f1d584d7SKrishna Gudipati *
331f1d584d7SKrishna Gudipati * If we had marked this IOC's fwstate as BFI_IOC_FAIL
332f1d584d7SKrishna Gudipati * in the failure case and now, if the fwstate is not
333f1d584d7SKrishna Gudipati * BFI_IOC_FAIL it implies that the other PCI fn have
334f1d584d7SKrishna Gudipati * reinitialized the ASIC or this IOC got disabled, so
335f1d584d7SKrishna Gudipati * return TRUE.
336f1d584d7SKrishna Gudipati */
337f1d584d7SKrishna Gudipati if (fwstate == BFI_IOC_UNINIT ||
338f1d584d7SKrishna Gudipati fwstate == BFI_IOC_INITING ||
339f1d584d7SKrishna Gudipati fwstate == BFI_IOC_DISABLED ||
340f1d584d7SKrishna Gudipati fwstate == BFI_IOC_MEMTEST ||
341f1d584d7SKrishna Gudipati fwstate == BFI_IOC_OP)
342f1d584d7SKrishna Gudipati return BFA_TRUE;
343f1d584d7SKrishna Gudipati else {
344c679b599SVijaya Mohan Guvva alt_fwstate = bfa_ioc_cb_get_alt_ioc_fwstate(ioc);
345f1d584d7SKrishna Gudipati if (alt_fwstate == BFI_IOC_FAIL ||
346f1d584d7SKrishna Gudipati alt_fwstate == BFI_IOC_DISABLED ||
347f1d584d7SKrishna Gudipati alt_fwstate == BFI_IOC_UNINIT ||
348f1d584d7SKrishna Gudipati alt_fwstate == BFI_IOC_INITING ||
349f1d584d7SKrishna Gudipati alt_fwstate == BFI_IOC_MEMTEST)
350f1d584d7SKrishna Gudipati return BFA_TRUE;
351f1d584d7SKrishna Gudipati else
352f1d584d7SKrishna Gudipati return BFA_FALSE;
353f1d584d7SKrishna Gudipati }
354f1d584d7SKrishna Gudipati }
355a36c61f9SKrishna Gudipati
356a36c61f9SKrishna Gudipati bfa_status_t
bfa_ioc_cb_pll_init(void __iomem * rb,enum bfi_asic_mode fcmode)35711189208SKrishna Gudipati bfa_ioc_cb_pll_init(void __iomem *rb, enum bfi_asic_mode fcmode)
358a36c61f9SKrishna Gudipati {
359c679b599SVijaya Mohan Guvva u32 pll_sclk, pll_fclk, join_bits;
360a36c61f9SKrishna Gudipati
36111189208SKrishna Gudipati pll_sclk = __APP_PLL_SCLK_ENABLE | __APP_PLL_SCLK_LRESETN |
36211189208SKrishna Gudipati __APP_PLL_SCLK_P0_1(3U) |
36311189208SKrishna Gudipati __APP_PLL_SCLK_JITLMT0_1(3U) |
36411189208SKrishna Gudipati __APP_PLL_SCLK_CNTLMT0_1(3U);
36511189208SKrishna Gudipati pll_fclk = __APP_PLL_LCLK_ENABLE | __APP_PLL_LCLK_LRESETN |
36611189208SKrishna Gudipati __APP_PLL_LCLK_RSEL200500 | __APP_PLL_LCLK_P0_1(3U) |
36711189208SKrishna Gudipati __APP_PLL_LCLK_JITLMT0_1(3U) |
36811189208SKrishna Gudipati __APP_PLL_LCLK_CNTLMT0_1(3U);
369c679b599SVijaya Mohan Guvva join_bits = readl(rb + BFA_IOC0_STATE_REG) &
370c679b599SVijaya Mohan Guvva BFA_IOC_CB_JOIN_MASK;
371c679b599SVijaya Mohan Guvva writel((BFI_IOC_UNINIT | join_bits), (rb + BFA_IOC0_STATE_REG));
372c679b599SVijaya Mohan Guvva join_bits = readl(rb + BFA_IOC1_STATE_REG) &
373c679b599SVijaya Mohan Guvva BFA_IOC_CB_JOIN_MASK;
374c679b599SVijaya Mohan Guvva writel((BFI_IOC_UNINIT | join_bits), (rb + BFA_IOC1_STATE_REG));
37553440260SJing Huang writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
37653440260SJing Huang writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
37753440260SJing Huang writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
37853440260SJing Huang writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
37953440260SJing Huang writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
38053440260SJing Huang writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
38111189208SKrishna Gudipati writel(__APP_PLL_SCLK_LOGIC_SOFT_RESET, rb + APP_PLL_SCLK_CTL_REG);
38211189208SKrishna Gudipati writel(__APP_PLL_SCLK_BYPASS | __APP_PLL_SCLK_LOGIC_SOFT_RESET,
38311189208SKrishna Gudipati rb + APP_PLL_SCLK_CTL_REG);
38411189208SKrishna Gudipati writel(__APP_PLL_LCLK_LOGIC_SOFT_RESET, rb + APP_PLL_LCLK_CTL_REG);
38511189208SKrishna Gudipati writel(__APP_PLL_LCLK_BYPASS | __APP_PLL_LCLK_LOGIC_SOFT_RESET,
38611189208SKrishna Gudipati rb + APP_PLL_LCLK_CTL_REG);
3876a18b167SJing Huang udelay(2);
38811189208SKrishna Gudipati writel(__APP_PLL_SCLK_LOGIC_SOFT_RESET, rb + APP_PLL_SCLK_CTL_REG);
38911189208SKrishna Gudipati writel(__APP_PLL_LCLK_LOGIC_SOFT_RESET, rb + APP_PLL_LCLK_CTL_REG);
39011189208SKrishna Gudipati writel(pll_sclk | __APP_PLL_SCLK_LOGIC_SOFT_RESET,
39111189208SKrishna Gudipati rb + APP_PLL_SCLK_CTL_REG);
39211189208SKrishna Gudipati writel(pll_fclk | __APP_PLL_LCLK_LOGIC_SOFT_RESET,
39311189208SKrishna Gudipati rb + APP_PLL_LCLK_CTL_REG);
3946a18b167SJing Huang udelay(2000);
39553440260SJing Huang writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
39653440260SJing Huang writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
39711189208SKrishna Gudipati writel(pll_sclk, (rb + APP_PLL_SCLK_CTL_REG));
39811189208SKrishna Gudipati writel(pll_fclk, (rb + APP_PLL_LCLK_CTL_REG));
399a36c61f9SKrishna Gudipati
400a36c61f9SKrishna Gudipati return BFA_STATUS_OK;
401a36c61f9SKrishna Gudipati }
402