Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1 | /* |
Anil Gurumurthy | 889d0d4 | 2015-11-26 03:54:45 -0500 | [diff] [blame] | 2 | * Copyright (c) 2005-2014 Brocade Communications Systems, Inc. |
| 3 | * Copyright (c) 2014- QLogic Corporation. |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 4 | * All rights reserved |
Anil Gurumurthy | 889d0d4 | 2015-11-26 03:54:45 -0500 | [diff] [blame] | 5 | * www.qlogic.com |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 6 | * |
Anil Gurumurthy | 31e1d56 | 2015-11-26 03:54:46 -0500 | [diff] [blame] | 7 | * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter. |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License (GPL) Version 2 as |
| 11 | * published by the Free Software Foundation |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | */ |
| 18 | |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 19 | #include "bfad_drv.h" |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 20 | #include "bfa_ioc.h" |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 21 | #include "bfi_reg.h" |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 22 | #include "bfa_defs.h" |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 23 | |
| 24 | BFA_TRC_FILE(CNA, IOC_CT); |
| 25 | |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 26 | #define bfa_ioc_ct_sync_pos(__ioc) \ |
| 27 | ((uint32_t) (1 << bfa_ioc_pcifn(__ioc))) |
| 28 | #define BFA_IOC_SYNC_REQD_SH 16 |
| 29 | #define bfa_ioc_ct_get_sync_ackd(__val) (__val & 0x0000ffff) |
| 30 | #define bfa_ioc_ct_clear_sync_ackd(__val) (__val & 0xffff0000) |
| 31 | #define bfa_ioc_ct_get_sync_reqd(__val) (__val >> BFA_IOC_SYNC_REQD_SH) |
| 32 | #define bfa_ioc_ct_sync_reqd_pos(__ioc) \ |
| 33 | (bfa_ioc_ct_sync_pos(__ioc) << BFA_IOC_SYNC_REQD_SH) |
| 34 | |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 35 | /* |
| 36 | * forward declarations |
| 37 | */ |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 38 | static bfa_boolean_t bfa_ioc_ct_firmware_lock(struct bfa_ioc_s *ioc); |
| 39 | static void bfa_ioc_ct_firmware_unlock(struct bfa_ioc_s *ioc); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 40 | static void bfa_ioc_ct_notify_fail(struct bfa_ioc_s *ioc); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 41 | static void bfa_ioc_ct_ownership_reset(struct bfa_ioc_s *ioc); |
Jing Huang | 45d7f0c | 2011-04-13 11:45:53 -0700 | [diff] [blame] | 42 | static bfa_boolean_t bfa_ioc_ct_sync_start(struct bfa_ioc_s *ioc); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 43 | static void bfa_ioc_ct_sync_join(struct bfa_ioc_s *ioc); |
| 44 | static void bfa_ioc_ct_sync_leave(struct bfa_ioc_s *ioc); |
| 45 | static void bfa_ioc_ct_sync_ack(struct bfa_ioc_s *ioc); |
| 46 | static bfa_boolean_t bfa_ioc_ct_sync_complete(struct bfa_ioc_s *ioc); |
Vijaya Mohan Guvva | c679b59 | 2013-05-13 02:33:26 -0700 | [diff] [blame] | 47 | static void bfa_ioc_ct_set_cur_ioc_fwstate( |
| 48 | struct bfa_ioc_s *ioc, enum bfi_ioc_state fwstate); |
| 49 | static enum bfi_ioc_state bfa_ioc_ct_get_cur_ioc_fwstate(struct bfa_ioc_s *ioc); |
| 50 | static void bfa_ioc_ct_set_alt_ioc_fwstate( |
| 51 | struct bfa_ioc_s *ioc, enum bfi_ioc_state fwstate); |
| 52 | static enum bfi_ioc_state bfa_ioc_ct_get_alt_ioc_fwstate(struct bfa_ioc_s *ioc); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 53 | |
Maggie | 52f94b6 | 2010-11-29 18:21:32 -0800 | [diff] [blame] | 54 | static struct bfa_ioc_hwif_s hwif_ct; |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 55 | static struct bfa_ioc_hwif_s hwif_ct2; |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 56 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 57 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 58 | * Return true if firmware of current driver matches the running firmware. |
| 59 | */ |
| 60 | static bfa_boolean_t |
| 61 | bfa_ioc_ct_firmware_lock(struct bfa_ioc_s *ioc) |
| 62 | { |
| 63 | enum bfi_ioc_state ioc_fwstate; |
Krishna Gudipati | d1c61f8 | 2010-03-05 19:38:44 -0800 | [diff] [blame] | 64 | u32 usecnt; |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 65 | struct bfi_ioc_image_hdr_s fwhdr; |
| 66 | |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 67 | bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg); |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 68 | usecnt = readl(ioc->ioc_regs.ioc_usage_reg); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 69 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 70 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 71 | * If usage count is 0, always return TRUE. |
| 72 | */ |
| 73 | if (usecnt == 0) { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 74 | writel(1, ioc->ioc_regs.ioc_usage_reg); |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 75 | readl(ioc->ioc_regs.ioc_usage_sem_reg); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 76 | writel(1, ioc->ioc_regs.ioc_usage_sem_reg); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 77 | writel(0, ioc->ioc_regs.ioc_fail_sync); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 78 | bfa_trc(ioc, usecnt); |
| 79 | return BFA_TRUE; |
| 80 | } |
| 81 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 82 | ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 83 | bfa_trc(ioc, ioc_fwstate); |
| 84 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 85 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 86 | * Use count cannot be non-zero and chip in uninitialized state. |
| 87 | */ |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 88 | WARN_ON(ioc_fwstate == BFI_IOC_UNINIT); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 89 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 90 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 91 | * Check if another driver with a different firmware is active |
| 92 | */ |
| 93 | bfa_ioc_fwver_get(ioc, &fwhdr); |
| 94 | if (!bfa_ioc_fwver_cmp(ioc, &fwhdr)) { |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 95 | readl(ioc->ioc_regs.ioc_usage_sem_reg); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 96 | writel(1, ioc->ioc_regs.ioc_usage_sem_reg); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 97 | bfa_trc(ioc, usecnt); |
| 98 | return BFA_FALSE; |
| 99 | } |
| 100 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 101 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 102 | * Same firmware version. Increment the reference count. |
| 103 | */ |
| 104 | usecnt++; |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 105 | writel(usecnt, ioc->ioc_regs.ioc_usage_reg); |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 106 | readl(ioc->ioc_regs.ioc_usage_sem_reg); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 107 | writel(1, ioc->ioc_regs.ioc_usage_sem_reg); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 108 | bfa_trc(ioc, usecnt); |
| 109 | return BFA_TRUE; |
| 110 | } |
| 111 | |
| 112 | static void |
| 113 | bfa_ioc_ct_firmware_unlock(struct bfa_ioc_s *ioc) |
| 114 | { |
Krishna Gudipati | d1c61f8 | 2010-03-05 19:38:44 -0800 | [diff] [blame] | 115 | u32 usecnt; |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 116 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 117 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 118 | * decrement usage count |
| 119 | */ |
| 120 | bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg); |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 121 | usecnt = readl(ioc->ioc_regs.ioc_usage_reg); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 122 | WARN_ON(usecnt <= 0); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 123 | |
| 124 | usecnt--; |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 125 | writel(usecnt, ioc->ioc_regs.ioc_usage_reg); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 126 | bfa_trc(ioc, usecnt); |
| 127 | |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 128 | readl(ioc->ioc_regs.ioc_usage_sem_reg); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 129 | writel(1, ioc->ioc_regs.ioc_usage_sem_reg); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 130 | } |
| 131 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 132 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 133 | * Notify other functions on HB failure. |
| 134 | */ |
| 135 | static void |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 136 | bfa_ioc_ct_notify_fail(struct bfa_ioc_s *ioc) |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 137 | { |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 138 | if (bfa_ioc_is_cna(ioc)) { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 139 | writel(__FW_INIT_HALT_P, ioc->ioc_regs.ll_halt); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 140 | writel(__FW_INIT_HALT_P, ioc->ioc_regs.alt_ll_halt); |
Krishna Gudipati | 816e49b | 2010-03-05 19:36:56 -0800 | [diff] [blame] | 141 | /* Wait for halt to take effect */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 142 | readl(ioc->ioc_regs.ll_halt); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 143 | readl(ioc->ioc_regs.alt_ll_halt); |
Krishna Gudipati | 816e49b | 2010-03-05 19:36:56 -0800 | [diff] [blame] | 144 | } else { |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 145 | writel(~0U, ioc->ioc_regs.err_set); |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 146 | readl(ioc->ioc_regs.err_set); |
Krishna Gudipati | 816e49b | 2010-03-05 19:36:56 -0800 | [diff] [blame] | 147 | } |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 148 | } |
| 149 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 150 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 151 | * Host to LPU mailbox message addresses |
| 152 | */ |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 153 | static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } ct_fnreg[] = { |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 154 | { HOSTFN0_LPU_MBOX0_0, LPU_HOSTFN0_MBOX0_0, HOST_PAGE_NUM_FN0 }, |
| 155 | { HOSTFN1_LPU_MBOX0_8, LPU_HOSTFN1_MBOX0_8, HOST_PAGE_NUM_FN1 }, |
| 156 | { HOSTFN2_LPU_MBOX0_0, LPU_HOSTFN2_MBOX0_0, HOST_PAGE_NUM_FN2 }, |
| 157 | { HOSTFN3_LPU_MBOX0_8, LPU_HOSTFN3_MBOX0_8, HOST_PAGE_NUM_FN3 } |
| 158 | }; |
| 159 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 160 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 161 | * Host <-> LPU mailbox command/status registers - port 0 |
| 162 | */ |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 163 | static struct { u32 hfn, lpu; } ct_p0reg[] = { |
| 164 | { HOSTFN0_LPU0_CMD_STAT, LPU0_HOSTFN0_CMD_STAT }, |
| 165 | { HOSTFN1_LPU0_CMD_STAT, LPU0_HOSTFN1_CMD_STAT }, |
| 166 | { HOSTFN2_LPU0_CMD_STAT, LPU0_HOSTFN2_CMD_STAT }, |
| 167 | { HOSTFN3_LPU0_CMD_STAT, LPU0_HOSTFN3_CMD_STAT } |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 168 | }; |
| 169 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 170 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 171 | * Host <-> LPU mailbox command/status registers - port 1 |
| 172 | */ |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 173 | static struct { u32 hfn, lpu; } ct_p1reg[] = { |
| 174 | { HOSTFN0_LPU1_CMD_STAT, LPU1_HOSTFN0_CMD_STAT }, |
| 175 | { HOSTFN1_LPU1_CMD_STAT, LPU1_HOSTFN1_CMD_STAT }, |
| 176 | { HOSTFN2_LPU1_CMD_STAT, LPU1_HOSTFN2_CMD_STAT }, |
| 177 | { HOSTFN3_LPU1_CMD_STAT, LPU1_HOSTFN3_CMD_STAT } |
| 178 | }; |
| 179 | |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 180 | static struct { uint32_t hfn_mbox, lpu_mbox, hfn_pgn, hfn, lpu, lpu_read; } |
| 181 | ct2_reg[] = { |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 182 | { CT2_HOSTFN_LPU0_MBOX0, CT2_LPU0_HOSTFN_MBOX0, CT2_HOSTFN_PAGE_NUM, |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 183 | CT2_HOSTFN_LPU0_CMD_STAT, CT2_LPU0_HOSTFN_CMD_STAT, |
| 184 | CT2_HOSTFN_LPU0_READ_STAT}, |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 185 | { CT2_HOSTFN_LPU1_MBOX0, CT2_LPU1_HOSTFN_MBOX0, CT2_HOSTFN_PAGE_NUM, |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 186 | CT2_HOSTFN_LPU1_CMD_STAT, CT2_LPU1_HOSTFN_CMD_STAT, |
| 187 | CT2_HOSTFN_LPU1_READ_STAT}, |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | static void |
| 191 | bfa_ioc_ct_reg_init(struct bfa_ioc_s *ioc) |
| 192 | { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 193 | void __iomem *rb; |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 194 | int pcifn = bfa_ioc_pcifn(ioc); |
| 195 | |
| 196 | rb = bfa_ioc_bar0(ioc); |
| 197 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 198 | ioc->ioc_regs.hfn_mbox = rb + ct_fnreg[pcifn].hfn_mbox; |
| 199 | ioc->ioc_regs.lpu_mbox = rb + ct_fnreg[pcifn].lpu_mbox; |
| 200 | ioc->ioc_regs.host_page_num_fn = rb + ct_fnreg[pcifn].hfn_pgn; |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 201 | |
| 202 | if (ioc->port_id == 0) { |
| 203 | ioc->ioc_regs.heartbeat = rb + BFA_IOC0_HBEAT_REG; |
| 204 | ioc->ioc_regs.ioc_fwstate = rb + BFA_IOC0_STATE_REG; |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 205 | ioc->ioc_regs.alt_ioc_fwstate = rb + BFA_IOC1_STATE_REG; |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 206 | ioc->ioc_regs.hfn_mbox_cmd = rb + ct_p0reg[pcifn].hfn; |
| 207 | ioc->ioc_regs.lpu_mbox_cmd = rb + ct_p0reg[pcifn].lpu; |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 208 | ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P0; |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 209 | ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P1; |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 210 | } else { |
| 211 | ioc->ioc_regs.heartbeat = (rb + BFA_IOC1_HBEAT_REG); |
| 212 | ioc->ioc_regs.ioc_fwstate = (rb + BFA_IOC1_STATE_REG); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 213 | ioc->ioc_regs.alt_ioc_fwstate = rb + BFA_IOC0_STATE_REG; |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 214 | ioc->ioc_regs.hfn_mbox_cmd = rb + ct_p1reg[pcifn].hfn; |
| 215 | ioc->ioc_regs.lpu_mbox_cmd = rb + ct_p1reg[pcifn].lpu; |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 216 | ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P1; |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 217 | ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P0; |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /* |
| 221 | * PSS control registers |
| 222 | */ |
| 223 | ioc->ioc_regs.pss_ctl_reg = (rb + PSS_CTL_REG); |
Krishna Gudipati | 8b651b4 | 2010-03-05 19:34:44 -0800 | [diff] [blame] | 224 | ioc->ioc_regs.pss_err_status_reg = (rb + PSS_ERR_STATUS_REG); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 225 | ioc->ioc_regs.app_pll_fast_ctl_reg = (rb + APP_PLL_LCLK_CTL_REG); |
| 226 | ioc->ioc_regs.app_pll_slow_ctl_reg = (rb + APP_PLL_SCLK_CTL_REG); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 227 | |
| 228 | /* |
| 229 | * IOC semaphore registers and serialization |
| 230 | */ |
| 231 | ioc->ioc_regs.ioc_sem_reg = (rb + HOST_SEM0_REG); |
| 232 | ioc->ioc_regs.ioc_usage_sem_reg = (rb + HOST_SEM1_REG); |
| 233 | ioc->ioc_regs.ioc_init_sem_reg = (rb + HOST_SEM2_REG); |
| 234 | ioc->ioc_regs.ioc_usage_reg = (rb + BFA_FW_USE_COUNT); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 235 | ioc->ioc_regs.ioc_fail_sync = (rb + BFA_IOC_FAIL_SYNC); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 236 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 237 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 238 | * sram memory access |
| 239 | */ |
| 240 | ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START); |
| 241 | ioc->ioc_regs.smem_pg0 = BFI_IOC_SMEM_PG0_CT; |
Krishna Gudipati | 816e49b | 2010-03-05 19:36:56 -0800 | [diff] [blame] | 242 | |
| 243 | /* |
| 244 | * err set reg : for notification of hb failure in fcmode |
| 245 | */ |
| 246 | ioc->ioc_regs.err_set = (rb + ERR_SET_REG); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 247 | } |
| 248 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 249 | static void |
| 250 | bfa_ioc_ct2_reg_init(struct bfa_ioc_s *ioc) |
| 251 | { |
| 252 | void __iomem *rb; |
| 253 | int port = bfa_ioc_portid(ioc); |
| 254 | |
| 255 | rb = bfa_ioc_bar0(ioc); |
| 256 | |
| 257 | ioc->ioc_regs.hfn_mbox = rb + ct2_reg[port].hfn_mbox; |
| 258 | ioc->ioc_regs.lpu_mbox = rb + ct2_reg[port].lpu_mbox; |
| 259 | ioc->ioc_regs.host_page_num_fn = rb + ct2_reg[port].hfn_pgn; |
| 260 | ioc->ioc_regs.hfn_mbox_cmd = rb + ct2_reg[port].hfn; |
| 261 | ioc->ioc_regs.lpu_mbox_cmd = rb + ct2_reg[port].lpu; |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 262 | ioc->ioc_regs.lpu_read_stat = rb + ct2_reg[port].lpu_read; |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 263 | |
| 264 | if (port == 0) { |
| 265 | ioc->ioc_regs.heartbeat = rb + CT2_BFA_IOC0_HBEAT_REG; |
| 266 | ioc->ioc_regs.ioc_fwstate = rb + CT2_BFA_IOC0_STATE_REG; |
| 267 | ioc->ioc_regs.alt_ioc_fwstate = rb + CT2_BFA_IOC1_STATE_REG; |
| 268 | ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P0; |
| 269 | ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P1; |
| 270 | } else { |
| 271 | ioc->ioc_regs.heartbeat = (rb + CT2_BFA_IOC1_HBEAT_REG); |
| 272 | ioc->ioc_regs.ioc_fwstate = (rb + CT2_BFA_IOC1_STATE_REG); |
| 273 | ioc->ioc_regs.alt_ioc_fwstate = rb + CT2_BFA_IOC0_STATE_REG; |
| 274 | ioc->ioc_regs.ll_halt = rb + FW_INIT_HALT_P1; |
| 275 | ioc->ioc_regs.alt_ll_halt = rb + FW_INIT_HALT_P0; |
| 276 | } |
| 277 | |
| 278 | /* |
| 279 | * PSS control registers |
| 280 | */ |
| 281 | ioc->ioc_regs.pss_ctl_reg = (rb + PSS_CTL_REG); |
| 282 | ioc->ioc_regs.pss_err_status_reg = (rb + PSS_ERR_STATUS_REG); |
| 283 | ioc->ioc_regs.app_pll_fast_ctl_reg = (rb + CT2_APP_PLL_LCLK_CTL_REG); |
| 284 | ioc->ioc_regs.app_pll_slow_ctl_reg = (rb + CT2_APP_PLL_SCLK_CTL_REG); |
| 285 | |
| 286 | /* |
| 287 | * IOC semaphore registers and serialization |
| 288 | */ |
| 289 | ioc->ioc_regs.ioc_sem_reg = (rb + CT2_HOST_SEM0_REG); |
| 290 | ioc->ioc_regs.ioc_usage_sem_reg = (rb + CT2_HOST_SEM1_REG); |
| 291 | ioc->ioc_regs.ioc_init_sem_reg = (rb + CT2_HOST_SEM2_REG); |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 292 | ioc->ioc_regs.ioc_usage_reg = (rb + CT2_BFA_FW_USE_COUNT); |
| 293 | ioc->ioc_regs.ioc_fail_sync = (rb + CT2_BFA_IOC_FAIL_SYNC); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 294 | |
| 295 | /* |
| 296 | * sram memory access |
| 297 | */ |
| 298 | ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START); |
| 299 | ioc->ioc_regs.smem_pg0 = BFI_IOC_SMEM_PG0_CT; |
| 300 | |
| 301 | /* |
| 302 | * err set reg : for notification of hb failure in fcmode |
| 303 | */ |
| 304 | ioc->ioc_regs.err_set = (rb + ERR_SET_REG); |
| 305 | } |
| 306 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 307 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 308 | * Initialize IOC to port mapping. |
| 309 | */ |
| 310 | |
| 311 | #define FNC_PERS_FN_SHIFT(__fn) ((__fn) * 8) |
| 312 | static void |
| 313 | bfa_ioc_ct_map_port(struct bfa_ioc_s *ioc) |
| 314 | { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 315 | void __iomem *rb = ioc->pcidev.pci_bar_kva; |
Krishna Gudipati | d1c61f8 | 2010-03-05 19:38:44 -0800 | [diff] [blame] | 316 | u32 r32; |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 317 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 318 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 319 | * For catapult, base port id on personality register and IOC type |
| 320 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 321 | r32 = readl(rb + FNC_PERS_REG); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 322 | r32 >>= FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc)); |
| 323 | ioc->port_id = (r32 & __F0_PORT_MAP_MK) >> __F0_PORT_MAP_SH; |
| 324 | |
| 325 | bfa_trc(ioc, bfa_ioc_pcifn(ioc)); |
| 326 | bfa_trc(ioc, ioc->port_id); |
| 327 | } |
| 328 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 329 | static void |
| 330 | bfa_ioc_ct2_map_port(struct bfa_ioc_s *ioc) |
| 331 | { |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 332 | void __iomem *rb = ioc->pcidev.pci_bar_kva; |
| 333 | u32 r32; |
| 334 | |
| 335 | r32 = readl(rb + CT2_HOSTFN_PERSONALITY0); |
| 336 | ioc->port_id = ((r32 & __FC_LL_PORT_MAP__MK) >> __FC_LL_PORT_MAP__SH); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 337 | |
| 338 | bfa_trc(ioc, bfa_ioc_pcifn(ioc)); |
| 339 | bfa_trc(ioc, ioc->port_id); |
| 340 | } |
| 341 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 342 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 343 | * Set interrupt mode for a function: INTX or MSIX |
| 344 | */ |
| 345 | static void |
| 346 | bfa_ioc_ct_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix) |
| 347 | { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 348 | void __iomem *rb = ioc->pcidev.pci_bar_kva; |
Krishna Gudipati | d1c61f8 | 2010-03-05 19:38:44 -0800 | [diff] [blame] | 349 | u32 r32, mode; |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 350 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 351 | r32 = readl(rb + FNC_PERS_REG); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 352 | bfa_trc(ioc, r32); |
| 353 | |
| 354 | mode = (r32 >> FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc))) & |
| 355 | __F0_INTX_STATUS; |
| 356 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 357 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 358 | * If already in desired mode, do not change anything |
| 359 | */ |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 360 | if ((!msix && mode) || (msix && !mode)) |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 361 | return; |
| 362 | |
| 363 | if (msix) |
| 364 | mode = __F0_INTX_STATUS_MSIX; |
| 365 | else |
| 366 | mode = __F0_INTX_STATUS_INTA; |
| 367 | |
| 368 | r32 &= ~(__F0_INTX_STATUS << FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc))); |
| 369 | r32 |= (mode << FNC_PERS_FN_SHIFT(bfa_ioc_pcifn(ioc))); |
| 370 | bfa_trc(ioc, r32); |
| 371 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 372 | writel(r32, rb + FNC_PERS_REG); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 373 | } |
| 374 | |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 375 | bfa_boolean_t |
| 376 | bfa_ioc_ct2_lpu_read_stat(struct bfa_ioc_s *ioc) |
| 377 | { |
| 378 | u32 r32; |
| 379 | |
| 380 | r32 = readl(ioc->ioc_regs.lpu_read_stat); |
| 381 | if (r32) { |
| 382 | writel(1, ioc->ioc_regs.lpu_read_stat); |
| 383 | return BFA_TRUE; |
| 384 | } |
| 385 | |
| 386 | return BFA_FALSE; |
| 387 | } |
| 388 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 389 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 390 | * Cleanup hw semaphore and usecnt registers |
| 391 | */ |
| 392 | static void |
| 393 | bfa_ioc_ct_ownership_reset(struct bfa_ioc_s *ioc) |
| 394 | { |
| 395 | |
Krishna Gudipati | 7ac83b1 | 2012-09-21 17:24:21 -0700 | [diff] [blame] | 396 | bfa_ioc_sem_get(ioc->ioc_regs.ioc_usage_sem_reg); |
| 397 | writel(0, ioc->ioc_regs.ioc_usage_reg); |
| 398 | readl(ioc->ioc_regs.ioc_usage_sem_reg); |
| 399 | writel(1, ioc->ioc_regs.ioc_usage_sem_reg); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 400 | |
Krishna Gudipati | 7ac83b1 | 2012-09-21 17:24:21 -0700 | [diff] [blame] | 401 | writel(0, ioc->ioc_regs.ioc_fail_sync); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 402 | /* |
| 403 | * Read the hw sem reg to make sure that it is locked |
| 404 | * before we clear it. If it is not locked, writing 1 |
| 405 | * will lock it instead of clearing it. |
| 406 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 407 | readl(ioc->ioc_regs.ioc_sem_reg); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 408 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 409 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 410 | |
Jing Huang | 45d7f0c | 2011-04-13 11:45:53 -0700 | [diff] [blame] | 411 | static bfa_boolean_t |
| 412 | bfa_ioc_ct_sync_start(struct bfa_ioc_s *ioc) |
| 413 | { |
| 414 | uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync); |
| 415 | uint32_t sync_reqd = bfa_ioc_ct_get_sync_reqd(r32); |
| 416 | |
| 417 | /* |
| 418 | * Driver load time. If the sync required bit for this PCI fn |
| 419 | * is set, it is due to an unclean exit by the driver for this |
| 420 | * PCI fn in the previous incarnation. Whoever comes here first |
| 421 | * should clean it up, no matter which PCI fn. |
| 422 | */ |
| 423 | |
| 424 | if (sync_reqd & bfa_ioc_ct_sync_pos(ioc)) { |
| 425 | writel(0, ioc->ioc_regs.ioc_fail_sync); |
| 426 | writel(1, ioc->ioc_regs.ioc_usage_reg); |
| 427 | writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate); |
| 428 | writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate); |
| 429 | return BFA_TRUE; |
| 430 | } |
| 431 | |
| 432 | return bfa_ioc_ct_sync_complete(ioc); |
| 433 | } |
| 434 | |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 435 | /* |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 436 | * Synchronized IOC failure processing routines |
| 437 | */ |
| 438 | static void |
| 439 | bfa_ioc_ct_sync_join(struct bfa_ioc_s *ioc) |
| 440 | { |
| 441 | uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync); |
| 442 | uint32_t sync_pos = bfa_ioc_ct_sync_reqd_pos(ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 443 | |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 444 | writel((r32 | sync_pos), ioc->ioc_regs.ioc_fail_sync); |
| 445 | } |
| 446 | |
| 447 | static void |
| 448 | bfa_ioc_ct_sync_leave(struct bfa_ioc_s *ioc) |
| 449 | { |
| 450 | uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync); |
| 451 | uint32_t sync_msk = bfa_ioc_ct_sync_reqd_pos(ioc) | |
| 452 | bfa_ioc_ct_sync_pos(ioc); |
| 453 | |
| 454 | writel((r32 & ~sync_msk), ioc->ioc_regs.ioc_fail_sync); |
| 455 | } |
| 456 | |
| 457 | static void |
| 458 | bfa_ioc_ct_sync_ack(struct bfa_ioc_s *ioc) |
| 459 | { |
| 460 | uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync); |
| 461 | |
| 462 | writel((r32 | bfa_ioc_ct_sync_pos(ioc)), |
| 463 | ioc->ioc_regs.ioc_fail_sync); |
| 464 | } |
| 465 | |
| 466 | static bfa_boolean_t |
| 467 | bfa_ioc_ct_sync_complete(struct bfa_ioc_s *ioc) |
| 468 | { |
| 469 | uint32_t r32 = readl(ioc->ioc_regs.ioc_fail_sync); |
| 470 | uint32_t sync_reqd = bfa_ioc_ct_get_sync_reqd(r32); |
| 471 | uint32_t sync_ackd = bfa_ioc_ct_get_sync_ackd(r32); |
| 472 | uint32_t tmp_ackd; |
| 473 | |
| 474 | if (sync_ackd == 0) |
| 475 | return BFA_TRUE; |
| 476 | |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 477 | /* |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 478 | * The check below is to see whether any other PCI fn |
| 479 | * has reinitialized the ASIC (reset sync_ackd bits) |
| 480 | * and failed again while this IOC was waiting for hw |
| 481 | * semaphore (in bfa_iocpf_sm_semwait()). |
| 482 | */ |
| 483 | tmp_ackd = sync_ackd; |
| 484 | if ((sync_reqd & bfa_ioc_ct_sync_pos(ioc)) && |
| 485 | !(sync_ackd & bfa_ioc_ct_sync_pos(ioc))) |
| 486 | sync_ackd |= bfa_ioc_ct_sync_pos(ioc); |
| 487 | |
| 488 | if (sync_reqd == sync_ackd) { |
| 489 | writel(bfa_ioc_ct_clear_sync_ackd(r32), |
| 490 | ioc->ioc_regs.ioc_fail_sync); |
| 491 | writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate); |
| 492 | writel(BFI_IOC_FAIL, ioc->ioc_regs.alt_ioc_fwstate); |
| 493 | return BFA_TRUE; |
| 494 | } |
| 495 | |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 496 | /* |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 497 | * If another PCI fn reinitialized and failed again while |
| 498 | * this IOC was waiting for hw sem, the sync_ackd bit for |
| 499 | * this IOC need to be set again to allow reinitialization. |
| 500 | */ |
| 501 | if (tmp_ackd != sync_ackd) |
| 502 | writel((r32 | sync_ackd), ioc->ioc_regs.ioc_fail_sync); |
| 503 | |
| 504 | return BFA_FALSE; |
| 505 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 506 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 507 | /** |
| 508 | * Called from bfa_ioc_attach() to map asic specific calls. |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 509 | */ |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 510 | static void |
| 511 | bfa_ioc_set_ctx_hwif(struct bfa_ioc_s *ioc, struct bfa_ioc_hwif_s *hwif) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 512 | { |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 513 | hwif->ioc_firmware_lock = bfa_ioc_ct_firmware_lock; |
| 514 | hwif->ioc_firmware_unlock = bfa_ioc_ct_firmware_unlock; |
| 515 | hwif->ioc_notify_fail = bfa_ioc_ct_notify_fail; |
| 516 | hwif->ioc_ownership_reset = bfa_ioc_ct_ownership_reset; |
| 517 | hwif->ioc_sync_start = bfa_ioc_ct_sync_start; |
| 518 | hwif->ioc_sync_join = bfa_ioc_ct_sync_join; |
| 519 | hwif->ioc_sync_leave = bfa_ioc_ct_sync_leave; |
| 520 | hwif->ioc_sync_ack = bfa_ioc_ct_sync_ack; |
| 521 | hwif->ioc_sync_complete = bfa_ioc_ct_sync_complete; |
Vijaya Mohan Guvva | c679b59 | 2013-05-13 02:33:26 -0700 | [diff] [blame] | 522 | hwif->ioc_set_fwstate = bfa_ioc_ct_set_cur_ioc_fwstate; |
| 523 | hwif->ioc_get_fwstate = bfa_ioc_ct_get_cur_ioc_fwstate; |
| 524 | hwif->ioc_set_alt_fwstate = bfa_ioc_ct_set_alt_ioc_fwstate; |
| 525 | hwif->ioc_get_alt_fwstate = bfa_ioc_ct_get_alt_ioc_fwstate; |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 526 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 527 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 528 | /** |
| 529 | * Called from bfa_ioc_attach() to map asic specific calls. |
| 530 | */ |
| 531 | void |
| 532 | bfa_ioc_set_ct_hwif(struct bfa_ioc_s *ioc) |
| 533 | { |
| 534 | bfa_ioc_set_ctx_hwif(ioc, &hwif_ct); |
| 535 | |
| 536 | hwif_ct.ioc_pll_init = bfa_ioc_ct_pll_init; |
| 537 | hwif_ct.ioc_reg_init = bfa_ioc_ct_reg_init; |
| 538 | hwif_ct.ioc_map_port = bfa_ioc_ct_map_port; |
| 539 | hwif_ct.ioc_isr_mode_set = bfa_ioc_ct_isr_mode_set; |
| 540 | ioc->ioc_hwif = &hwif_ct; |
| 541 | } |
| 542 | |
| 543 | /** |
| 544 | * Called from bfa_ioc_attach() to map asic specific calls. |
| 545 | */ |
| 546 | void |
| 547 | bfa_ioc_set_ct2_hwif(struct bfa_ioc_s *ioc) |
| 548 | { |
| 549 | bfa_ioc_set_ctx_hwif(ioc, &hwif_ct2); |
| 550 | |
| 551 | hwif_ct2.ioc_pll_init = bfa_ioc_ct2_pll_init; |
| 552 | hwif_ct2.ioc_reg_init = bfa_ioc_ct2_reg_init; |
| 553 | hwif_ct2.ioc_map_port = bfa_ioc_ct2_map_port; |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 554 | hwif_ct2.ioc_lpu_read_stat = bfa_ioc_ct2_lpu_read_stat; |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 555 | hwif_ct2.ioc_isr_mode_set = NULL; |
| 556 | ioc->ioc_hwif = &hwif_ct2; |
| 557 | } |
| 558 | |
| 559 | /* |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 560 | * Workaround for MSI-X resource allocation for catapult-2 with no asic block |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 561 | */ |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 562 | #define HOSTFN_MSIX_DEFAULT 64 |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 563 | #define HOSTFN_MSIX_VT_INDEX_MBOX_ERR 0x30138 |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 564 | #define HOSTFN_MSIX_VT_OFST_NUMVT 0x3013c |
| 565 | #define __MSIX_VT_NUMVT__MK 0x003ff800 |
| 566 | #define __MSIX_VT_NUMVT__SH 11 |
| 567 | #define __MSIX_VT_NUMVT_(_v) ((_v) << __MSIX_VT_NUMVT__SH) |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 568 | #define __MSIX_VT_OFST_ 0x000007ff |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 569 | void |
| 570 | bfa_ioc_ct2_poweron(struct bfa_ioc_s *ioc) |
| 571 | { |
| 572 | void __iomem *rb = ioc->pcidev.pci_bar_kva; |
| 573 | u32 r32; |
| 574 | |
| 575 | r32 = readl(rb + HOSTFN_MSIX_VT_OFST_NUMVT); |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 576 | if (r32 & __MSIX_VT_NUMVT__MK) { |
| 577 | writel(r32 & __MSIX_VT_OFST_, |
| 578 | rb + HOSTFN_MSIX_VT_INDEX_MBOX_ERR); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 579 | return; |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 580 | } |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 581 | |
| 582 | writel(__MSIX_VT_NUMVT_(HOSTFN_MSIX_DEFAULT - 1) | |
| 583 | HOSTFN_MSIX_DEFAULT * bfa_ioc_pcifn(ioc), |
| 584 | rb + HOSTFN_MSIX_VT_OFST_NUMVT); |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 585 | writel(HOSTFN_MSIX_DEFAULT * bfa_ioc_pcifn(ioc), |
| 586 | rb + HOSTFN_MSIX_VT_INDEX_MBOX_ERR); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | bfa_status_t |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 590 | bfa_ioc_ct_pll_init(void __iomem *rb, enum bfi_asic_mode mode) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 591 | { |
| 592 | u32 pll_sclk, pll_fclk, r32; |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 593 | bfa_boolean_t fcmode = (mode == BFI_ASIC_MODE_FC); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 594 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 595 | pll_sclk = __APP_PLL_SCLK_LRESETN | __APP_PLL_SCLK_ENARST | |
| 596 | __APP_PLL_SCLK_RSEL200500 | __APP_PLL_SCLK_P0_1(3U) | |
| 597 | __APP_PLL_SCLK_JITLMT0_1(3U) | |
| 598 | __APP_PLL_SCLK_CNTLMT0_1(1U); |
| 599 | pll_fclk = __APP_PLL_LCLK_LRESETN | __APP_PLL_LCLK_ENARST | |
| 600 | __APP_PLL_LCLK_RSEL200500 | __APP_PLL_LCLK_P0_1(3U) | |
| 601 | __APP_PLL_LCLK_JITLMT0_1(3U) | |
| 602 | __APP_PLL_LCLK_CNTLMT0_1(1U); |
| 603 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 604 | if (fcmode) { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 605 | writel(0, (rb + OP_MODE)); |
| 606 | writel(__APP_EMS_CMLCKSEL | __APP_EMS_REFCKBUFEN2 | |
| 607 | __APP_EMS_CHANNEL_SEL, (rb + ETH_MAC_SER_REG)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 608 | } else { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 609 | writel(__GLOBAL_FCOE_MODE, (rb + OP_MODE)); |
| 610 | writel(__APP_EMS_REFCKBUFEN1, (rb + ETH_MAC_SER_REG)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 611 | } |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 612 | writel(BFI_IOC_UNINIT, (rb + BFA_IOC0_STATE_REG)); |
| 613 | writel(BFI_IOC_UNINIT, (rb + BFA_IOC1_STATE_REG)); |
| 614 | writel(0xffffffffU, (rb + HOSTFN0_INT_MSK)); |
| 615 | writel(0xffffffffU, (rb + HOSTFN1_INT_MSK)); |
| 616 | writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS)); |
| 617 | writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS)); |
| 618 | writel(0xffffffffU, (rb + HOSTFN0_INT_MSK)); |
| 619 | writel(0xffffffffU, (rb + HOSTFN1_INT_MSK)); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 620 | writel(pll_sclk | __APP_PLL_SCLK_LOGIC_SOFT_RESET, |
| 621 | rb + APP_PLL_SCLK_CTL_REG); |
| 622 | writel(pll_fclk | __APP_PLL_LCLK_LOGIC_SOFT_RESET, |
| 623 | rb + APP_PLL_LCLK_CTL_REG); |
| 624 | writel(pll_sclk | __APP_PLL_SCLK_LOGIC_SOFT_RESET | |
| 625 | __APP_PLL_SCLK_ENABLE, rb + APP_PLL_SCLK_CTL_REG); |
| 626 | writel(pll_fclk | __APP_PLL_LCLK_LOGIC_SOFT_RESET | |
| 627 | __APP_PLL_LCLK_ENABLE, rb + APP_PLL_LCLK_CTL_REG); |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 628 | readl(rb + HOSTFN0_INT_MSK); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 629 | udelay(2000); |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 630 | writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS)); |
| 631 | writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS)); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 632 | writel(pll_sclk | __APP_PLL_SCLK_ENABLE, rb + APP_PLL_SCLK_CTL_REG); |
| 633 | writel(pll_fclk | __APP_PLL_LCLK_ENABLE, rb + APP_PLL_LCLK_CTL_REG); |
| 634 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 635 | if (!fcmode) { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 636 | writel(__PMM_1T_RESET_P, (rb + PMM_1T_RESET_REG_P0)); |
| 637 | writel(__PMM_1T_RESET_P, (rb + PMM_1T_RESET_REG_P1)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 638 | } |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 639 | r32 = readl((rb + PSS_CTL_REG)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 640 | r32 &= ~__PSS_LMEM_RESET; |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 641 | writel(r32, (rb + PSS_CTL_REG)); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 642 | udelay(1000); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 643 | if (!fcmode) { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 644 | writel(0, (rb + PMM_1T_RESET_REG_P0)); |
| 645 | writel(0, (rb + PMM_1T_RESET_REG_P1)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 648 | writel(__EDRAM_BISTR_START, (rb + MBIST_CTL_REG)); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 649 | udelay(1000); |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 650 | r32 = readl((rb + MBIST_STAT_REG)); |
| 651 | writel(0, (rb + MBIST_CTL_REG)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 652 | return BFA_STATUS_OK; |
| 653 | } |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 654 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 655 | static void |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 656 | bfa_ioc_ct2_sclk_init(void __iomem *rb) |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 657 | { |
| 658 | u32 r32; |
| 659 | |
| 660 | /* |
| 661 | * put s_clk PLL and PLL FSM in reset |
| 662 | */ |
| 663 | r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG)); |
| 664 | r32 &= ~(__APP_PLL_SCLK_ENABLE | __APP_PLL_SCLK_LRESETN); |
| 665 | r32 |= (__APP_PLL_SCLK_ENARST | __APP_PLL_SCLK_BYPASS | |
| 666 | __APP_PLL_SCLK_LOGIC_SOFT_RESET); |
| 667 | writel(r32, (rb + CT2_APP_PLL_SCLK_CTL_REG)); |
| 668 | |
| 669 | /* |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 670 | * Ignore mode and program for the max clock (which is FC16) |
| 671 | * Firmware/NFC will do the PLL init appropiately |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 672 | */ |
| 673 | r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG)); |
| 674 | r32 &= ~(__APP_PLL_SCLK_REFCLK_SEL | __APP_PLL_SCLK_CLK_DIV2); |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 675 | writel(r32, (rb + CT2_APP_PLL_SCLK_CTL_REG)); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 676 | |
| 677 | /* |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 678 | * while doing PLL init dont clock gate ethernet subsystem |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 679 | */ |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 680 | r32 = readl((rb + CT2_CHIP_MISC_PRG)); |
| 681 | writel(r32 | __ETH_CLK_ENABLE_PORT0, (rb + CT2_CHIP_MISC_PRG)); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 682 | |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 683 | r32 = readl((rb + CT2_PCIE_MISC_REG)); |
| 684 | writel(r32 | __ETH_CLK_ENABLE_PORT1, (rb + CT2_PCIE_MISC_REG)); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 685 | |
| 686 | /* |
| 687 | * set sclk value |
| 688 | */ |
| 689 | r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG)); |
| 690 | r32 &= (__P_SCLK_PLL_LOCK | __APP_PLL_SCLK_REFCLK_SEL | |
| 691 | __APP_PLL_SCLK_CLK_DIV2); |
| 692 | writel(r32 | 0x1061731b, (rb + CT2_APP_PLL_SCLK_CTL_REG)); |
| 693 | |
| 694 | /* |
| 695 | * poll for s_clk lock or delay 1ms |
| 696 | */ |
| 697 | udelay(1000); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | static void |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 701 | bfa_ioc_ct2_lclk_init(void __iomem *rb) |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 702 | { |
| 703 | u32 r32; |
| 704 | |
| 705 | /* |
| 706 | * put l_clk PLL and PLL FSM in reset |
| 707 | */ |
| 708 | r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG)); |
| 709 | r32 &= ~(__APP_PLL_LCLK_ENABLE | __APP_PLL_LCLK_LRESETN); |
| 710 | r32 |= (__APP_PLL_LCLK_ENARST | __APP_PLL_LCLK_BYPASS | |
| 711 | __APP_PLL_LCLK_LOGIC_SOFT_RESET); |
| 712 | writel(r32, (rb + CT2_APP_PLL_LCLK_CTL_REG)); |
| 713 | |
| 714 | /* |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 715 | * set LPU speed (set for FC16 which will work for other modes) |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 716 | */ |
| 717 | r32 = readl((rb + CT2_CHIP_MISC_PRG)); |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 718 | writel(r32, (rb + CT2_CHIP_MISC_PRG)); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 719 | |
| 720 | /* |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 721 | * set LPU half speed (set for FC16 which will work for other modes) |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 722 | */ |
| 723 | r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG)); |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 724 | writel(r32, (rb + CT2_APP_PLL_LCLK_CTL_REG)); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 725 | |
| 726 | /* |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 727 | * set lclk for mode (set for FC16) |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 728 | */ |
| 729 | r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG)); |
| 730 | r32 &= (__P_LCLK_PLL_LOCK | __APP_LPUCLK_HALFSPEED); |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 731 | r32 |= 0x20c1731b; |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 732 | writel(r32, (rb + CT2_APP_PLL_LCLK_CTL_REG)); |
| 733 | |
| 734 | /* |
| 735 | * poll for s_clk lock or delay 1ms |
| 736 | */ |
| 737 | udelay(1000); |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | static void |
| 741 | bfa_ioc_ct2_mem_init(void __iomem *rb) |
| 742 | { |
| 743 | u32 r32; |
| 744 | |
| 745 | r32 = readl((rb + PSS_CTL_REG)); |
| 746 | r32 &= ~__PSS_LMEM_RESET; |
| 747 | writel(r32, (rb + PSS_CTL_REG)); |
| 748 | udelay(1000); |
| 749 | |
| 750 | writel(__EDRAM_BISTR_START, (rb + CT2_MBIST_CTL_REG)); |
| 751 | udelay(1000); |
| 752 | writel(0, (rb + CT2_MBIST_CTL_REG)); |
| 753 | } |
| 754 | |
| 755 | void |
| 756 | bfa_ioc_ct2_mac_reset(void __iomem *rb) |
| 757 | { |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 758 | /* put port0, port1 MAC & AHB in reset */ |
| 759 | writel((__CSI_MAC_RESET | __CSI_MAC_AHB_RESET), |
| 760 | rb + CT2_CSI_MAC_CONTROL_REG(0)); |
| 761 | writel((__CSI_MAC_RESET | __CSI_MAC_AHB_RESET), |
| 762 | rb + CT2_CSI_MAC_CONTROL_REG(1)); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Krishna Gudipati | 227fab9 | 2012-09-21 17:24:52 -0700 | [diff] [blame] | 765 | static void |
| 766 | bfa_ioc_ct2_enable_flash(void __iomem *rb) |
| 767 | { |
| 768 | u32 r32; |
| 769 | |
| 770 | r32 = readl((rb + PSS_GPIO_OUT_REG)); |
| 771 | writel(r32 & ~1, (rb + PSS_GPIO_OUT_REG)); |
| 772 | r32 = readl((rb + PSS_GPIO_OE_REG)); |
| 773 | writel(r32 | 1, (rb + PSS_GPIO_OE_REG)); |
| 774 | } |
| 775 | |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 776 | #define CT2_NFC_MAX_DELAY 1000 |
Krishna Gudipati | 227fab9 | 2012-09-21 17:24:52 -0700 | [diff] [blame] | 777 | #define CT2_NFC_PAUSE_MAX_DELAY 4000 |
| 778 | #define CT2_NFC_VER_VALID 0x147 |
| 779 | #define CT2_NFC_STATE_RUNNING 0x20000001 |
Krishna Gudipati | a6b963d | 2012-03-13 17:39:22 -0700 | [diff] [blame] | 780 | #define BFA_IOC_PLL_POLL 1000000 |
| 781 | |
| 782 | static bfa_boolean_t |
| 783 | bfa_ioc_ct2_nfc_halted(void __iomem *rb) |
| 784 | { |
| 785 | u32 r32; |
| 786 | |
| 787 | r32 = readl(rb + CT2_NFC_CSR_SET_REG); |
| 788 | if (r32 & __NFC_CONTROLLER_HALTED) |
| 789 | return BFA_TRUE; |
| 790 | |
| 791 | return BFA_FALSE; |
| 792 | } |
| 793 | |
| 794 | static void |
Krishna Gudipati | 227fab9 | 2012-09-21 17:24:52 -0700 | [diff] [blame] | 795 | bfa_ioc_ct2_nfc_halt(void __iomem *rb) |
| 796 | { |
| 797 | int i; |
| 798 | |
| 799 | writel(__HALT_NFC_CONTROLLER, rb + CT2_NFC_CSR_SET_REG); |
| 800 | for (i = 0; i < CT2_NFC_MAX_DELAY; i++) { |
| 801 | if (bfa_ioc_ct2_nfc_halted(rb)) |
| 802 | break; |
| 803 | udelay(1000); |
| 804 | } |
| 805 | WARN_ON(!bfa_ioc_ct2_nfc_halted(rb)); |
| 806 | } |
| 807 | |
| 808 | static void |
Krishna Gudipati | a6b963d | 2012-03-13 17:39:22 -0700 | [diff] [blame] | 809 | bfa_ioc_ct2_nfc_resume(void __iomem *rb) |
| 810 | { |
| 811 | u32 r32; |
| 812 | int i; |
| 813 | |
| 814 | writel(__HALT_NFC_CONTROLLER, rb + CT2_NFC_CSR_CLR_REG); |
| 815 | for (i = 0; i < CT2_NFC_MAX_DELAY; i++) { |
| 816 | r32 = readl(rb + CT2_NFC_CSR_SET_REG); |
| 817 | if (!(r32 & __NFC_CONTROLLER_HALTED)) |
| 818 | return; |
| 819 | udelay(1000); |
| 820 | } |
| 821 | WARN_ON(1); |
| 822 | } |
| 823 | |
Krishna Gudipati | 227fab9 | 2012-09-21 17:24:52 -0700 | [diff] [blame] | 824 | static void |
| 825 | bfa_ioc_ct2_clk_reset(void __iomem *rb) |
| 826 | { |
| 827 | u32 r32; |
| 828 | |
| 829 | bfa_ioc_ct2_sclk_init(rb); |
| 830 | bfa_ioc_ct2_lclk_init(rb); |
| 831 | |
| 832 | /* |
| 833 | * release soft reset on s_clk & l_clk |
| 834 | */ |
| 835 | r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG)); |
| 836 | writel(r32 & ~__APP_PLL_SCLK_LOGIC_SOFT_RESET, |
| 837 | (rb + CT2_APP_PLL_SCLK_CTL_REG)); |
| 838 | |
| 839 | r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG)); |
| 840 | writel(r32 & ~__APP_PLL_LCLK_LOGIC_SOFT_RESET, |
| 841 | (rb + CT2_APP_PLL_LCLK_CTL_REG)); |
| 842 | |
| 843 | } |
| 844 | |
| 845 | static void |
| 846 | bfa_ioc_ct2_nfc_clk_reset(void __iomem *rb) |
| 847 | { |
| 848 | u32 r32, i; |
| 849 | |
| 850 | r32 = readl((rb + PSS_CTL_REG)); |
| 851 | r32 |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET); |
| 852 | writel(r32, (rb + PSS_CTL_REG)); |
| 853 | |
| 854 | writel(__RESET_AND_START_SCLK_LCLK_PLLS, rb + CT2_CSI_FW_CTL_SET_REG); |
| 855 | |
| 856 | for (i = 0; i < BFA_IOC_PLL_POLL; i++) { |
| 857 | r32 = readl(rb + CT2_NFC_FLASH_STS_REG); |
| 858 | |
| 859 | if ((r32 & __FLASH_PLL_INIT_AND_RESET_IN_PROGRESS)) |
| 860 | break; |
| 861 | } |
| 862 | WARN_ON(!(r32 & __FLASH_PLL_INIT_AND_RESET_IN_PROGRESS)); |
| 863 | |
| 864 | for (i = 0; i < BFA_IOC_PLL_POLL; i++) { |
| 865 | r32 = readl(rb + CT2_NFC_FLASH_STS_REG); |
| 866 | |
| 867 | if (!(r32 & __FLASH_PLL_INIT_AND_RESET_IN_PROGRESS)) |
| 868 | break; |
| 869 | } |
| 870 | WARN_ON((r32 & __FLASH_PLL_INIT_AND_RESET_IN_PROGRESS)); |
| 871 | |
| 872 | r32 = readl(rb + CT2_CSI_FW_CTL_REG); |
| 873 | WARN_ON((r32 & __RESET_AND_START_SCLK_LCLK_PLLS)); |
| 874 | } |
| 875 | |
| 876 | static void |
| 877 | bfa_ioc_ct2_wait_till_nfc_running(void __iomem *rb) |
| 878 | { |
| 879 | u32 r32; |
| 880 | int i; |
| 881 | |
| 882 | if (bfa_ioc_ct2_nfc_halted(rb)) |
| 883 | bfa_ioc_ct2_nfc_resume(rb); |
| 884 | for (i = 0; i < CT2_NFC_PAUSE_MAX_DELAY; i++) { |
| 885 | r32 = readl(rb + CT2_NFC_STS_REG); |
| 886 | if (r32 == CT2_NFC_STATE_RUNNING) |
| 887 | return; |
| 888 | udelay(1000); |
| 889 | } |
| 890 | |
| 891 | r32 = readl(rb + CT2_NFC_STS_REG); |
| 892 | WARN_ON(!(r32 == CT2_NFC_STATE_RUNNING)); |
| 893 | } |
| 894 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 895 | bfa_status_t |
| 896 | bfa_ioc_ct2_pll_init(void __iomem *rb, enum bfi_asic_mode mode) |
| 897 | { |
Krishna Gudipati | 227fab9 | 2012-09-21 17:24:52 -0700 | [diff] [blame] | 898 | u32 wgn, r32, nfc_ver; |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 899 | |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 900 | wgn = readl(rb + CT2_WGN_STATUS); |
Krishna Gudipati | a6b963d | 2012-03-13 17:39:22 -0700 | [diff] [blame] | 901 | |
Krishna Gudipati | 227fab9 | 2012-09-21 17:24:52 -0700 | [diff] [blame] | 902 | if (wgn == (__WGN_READY | __GLBL_PF_VF_CFG_RDY)) { |
| 903 | /* |
| 904 | * If flash is corrupted, enable flash explicitly |
| 905 | */ |
| 906 | bfa_ioc_ct2_clk_reset(rb); |
| 907 | bfa_ioc_ct2_enable_flash(rb); |
Krishna Gudipati | a6b963d | 2012-03-13 17:39:22 -0700 | [diff] [blame] | 908 | |
| 909 | bfa_ioc_ct2_mac_reset(rb); |
Krishna Gudipati | a6b963d | 2012-03-13 17:39:22 -0700 | [diff] [blame] | 910 | |
Krishna Gudipati | 227fab9 | 2012-09-21 17:24:52 -0700 | [diff] [blame] | 911 | bfa_ioc_ct2_clk_reset(rb); |
| 912 | bfa_ioc_ct2_enable_flash(rb); |
Krishna Gudipati | a6b963d | 2012-03-13 17:39:22 -0700 | [diff] [blame] | 913 | |
Krishna Gudipati | 227fab9 | 2012-09-21 17:24:52 -0700 | [diff] [blame] | 914 | } else { |
| 915 | nfc_ver = readl(rb + CT2_RSC_GPR15_REG); |
Krishna Gudipati | a6b963d | 2012-03-13 17:39:22 -0700 | [diff] [blame] | 916 | |
Krishna Gudipati | 227fab9 | 2012-09-21 17:24:52 -0700 | [diff] [blame] | 917 | if ((nfc_ver >= CT2_NFC_VER_VALID) && |
| 918 | (wgn == (__A2T_AHB_LOAD | __WGN_READY))) { |
| 919 | |
| 920 | bfa_ioc_ct2_wait_till_nfc_running(rb); |
| 921 | |
| 922 | bfa_ioc_ct2_nfc_clk_reset(rb); |
| 923 | } else { |
| 924 | bfa_ioc_ct2_nfc_halt(rb); |
| 925 | |
| 926 | bfa_ioc_ct2_clk_reset(rb); |
| 927 | bfa_ioc_ct2_mac_reset(rb); |
| 928 | bfa_ioc_ct2_clk_reset(rb); |
| 929 | |
| 930 | } |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 931 | } |
Vijaya Mohan Guvva | e1aaab8 | 2013-05-13 02:33:24 -0700 | [diff] [blame] | 932 | /* |
| 933 | * The very first PCIe DMA Read done by LPU fails with a fatal error, |
| 934 | * when Address Translation Cache (ATC) has been enabled by system BIOS. |
| 935 | * |
| 936 | * Workaround: |
| 937 | * Disable Invalidated Tag Match Enable capability by setting the bit 26 |
| 938 | * of CHIP_MISC_PRG to 0, by default it is set to 1. |
| 939 | */ |
| 940 | r32 = readl(rb + CT2_CHIP_MISC_PRG); |
| 941 | writel((r32 & 0xfbffffff), (rb + CT2_CHIP_MISC_PRG)); |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 942 | |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 943 | /* |
| 944 | * Mask the interrupts and clear any |
Krishna Gudipati | 227fab9 | 2012-09-21 17:24:52 -0700 | [diff] [blame] | 945 | * pending interrupts left by BIOS/EFI |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 946 | */ |
Krishna Gudipati | 227fab9 | 2012-09-21 17:24:52 -0700 | [diff] [blame] | 947 | |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 948 | writel(1, (rb + CT2_LPU0_HOSTFN_MBOX0_MSK)); |
| 949 | writel(1, (rb + CT2_LPU1_HOSTFN_MBOX0_MSK)); |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 950 | |
Krishna Gudipati | a6b963d | 2012-03-13 17:39:22 -0700 | [diff] [blame] | 951 | /* For first time initialization, no need to clear interrupts */ |
| 952 | r32 = readl(rb + HOST_SEM5_REG); |
| 953 | if (r32 & 0x1) { |
Krishna Gudipati | 227fab9 | 2012-09-21 17:24:52 -0700 | [diff] [blame] | 954 | r32 = readl((rb + CT2_LPU0_HOSTFN_CMD_STAT)); |
Krishna Gudipati | a6b963d | 2012-03-13 17:39:22 -0700 | [diff] [blame] | 955 | if (r32 == 1) { |
Krishna Gudipati | 227fab9 | 2012-09-21 17:24:52 -0700 | [diff] [blame] | 956 | writel(1, (rb + CT2_LPU0_HOSTFN_CMD_STAT)); |
Krishna Gudipati | a6b963d | 2012-03-13 17:39:22 -0700 | [diff] [blame] | 957 | readl((rb + CT2_LPU0_HOSTFN_CMD_STAT)); |
| 958 | } |
Krishna Gudipati | 227fab9 | 2012-09-21 17:24:52 -0700 | [diff] [blame] | 959 | r32 = readl((rb + CT2_LPU1_HOSTFN_CMD_STAT)); |
Krishna Gudipati | a6b963d | 2012-03-13 17:39:22 -0700 | [diff] [blame] | 960 | if (r32 == 1) { |
Krishna Gudipati | 227fab9 | 2012-09-21 17:24:52 -0700 | [diff] [blame] | 961 | writel(1, (rb + CT2_LPU1_HOSTFN_CMD_STAT)); |
| 962 | readl((rb + CT2_LPU1_HOSTFN_CMD_STAT)); |
Krishna Gudipati | a6b963d | 2012-03-13 17:39:22 -0700 | [diff] [blame] | 963 | } |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 964 | } |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 965 | |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 966 | bfa_ioc_ct2_mem_init(rb); |
| 967 | |
Krishna Gudipati | 227fab9 | 2012-09-21 17:24:52 -0700 | [diff] [blame] | 968 | writel(BFI_IOC_UNINIT, (rb + CT2_BFA_IOC0_STATE_REG)); |
| 969 | writel(BFI_IOC_UNINIT, (rb + CT2_BFA_IOC1_STATE_REG)); |
Krishna Gudipati | a6b963d | 2012-03-13 17:39:22 -0700 | [diff] [blame] | 970 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 971 | return BFA_STATUS_OK; |
| 972 | } |
Vijaya Mohan Guvva | c679b59 | 2013-05-13 02:33:26 -0700 | [diff] [blame] | 973 | |
| 974 | static void |
| 975 | bfa_ioc_ct_set_cur_ioc_fwstate(struct bfa_ioc_s *ioc, |
| 976 | enum bfi_ioc_state fwstate) |
| 977 | { |
| 978 | writel(fwstate, ioc->ioc_regs.ioc_fwstate); |
| 979 | } |
| 980 | |
| 981 | static enum bfi_ioc_state |
| 982 | bfa_ioc_ct_get_cur_ioc_fwstate(struct bfa_ioc_s *ioc) |
| 983 | { |
| 984 | return (enum bfi_ioc_state)readl(ioc->ioc_regs.ioc_fwstate); |
| 985 | } |
| 986 | |
| 987 | static void |
| 988 | bfa_ioc_ct_set_alt_ioc_fwstate(struct bfa_ioc_s *ioc, |
| 989 | enum bfi_ioc_state fwstate) |
| 990 | { |
| 991 | writel(fwstate, ioc->ioc_regs.alt_ioc_fwstate); |
| 992 | } |
| 993 | |
| 994 | static enum bfi_ioc_state |
| 995 | bfa_ioc_ct_get_alt_ioc_fwstate(struct bfa_ioc_s *ioc) |
| 996 | { |
| 997 | return (enum bfi_ioc_state) readl(ioc->ioc_regs.alt_ioc_fwstate); |
| 998 | } |