Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1 | /* |
| 2 | * QLogic iSCSI HBA Driver |
| 3 | * Copyright (c) 2003-2009 QLogic Corporation |
| 4 | * |
| 5 | * See LICENSE.qla4xxx for copyright and licensing details. |
| 6 | */ |
| 7 | #include <linux/delay.h> |
Jiri Slaby | a6751cc | 2010-09-14 14:12:54 +0200 | [diff] [blame] | 8 | #include <linux/io.h> |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9 | #include <linux/pci.h> |
| 10 | #include "ql4_def.h" |
| 11 | #include "ql4_glbl.h" |
| 12 | |
| 13 | #define MASK(n) DMA_BIT_MASK(n) |
| 14 | #define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff)) |
| 15 | #define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff)) |
| 16 | #define MS_WIN(addr) (addr & 0x0ffc0000) |
| 17 | #define QLA82XX_PCI_MN_2M (0) |
| 18 | #define QLA82XX_PCI_MS_2M (0x80000) |
| 19 | #define QLA82XX_PCI_OCM0_2M (0xc0000) |
| 20 | #define VALID_OCM_ADDR(addr) (((addr) & 0x3f800) != 0x3f800) |
| 21 | #define GET_MEM_OFFS_2M(addr) (addr & MASK(18)) |
| 22 | |
| 23 | /* CRB window related */ |
| 24 | #define CRB_BLK(off) ((off >> 20) & 0x3f) |
| 25 | #define CRB_SUBBLK(off) ((off >> 16) & 0xf) |
| 26 | #define CRB_WINDOW_2M (0x130060) |
| 27 | #define CRB_HI(off) ((qla4_8xxx_crb_hub_agt[CRB_BLK(off)] << 20) | \ |
| 28 | ((off) & 0xf0000)) |
| 29 | #define QLA82XX_PCI_CAMQM_2M_END (0x04800800UL) |
| 30 | #define QLA82XX_PCI_CAMQM_2M_BASE (0x000ff800UL) |
| 31 | #define CRB_INDIRECT_2M (0x1e0000UL) |
| 32 | |
| 33 | static inline void __iomem * |
| 34 | qla4_8xxx_pci_base_offsetfset(struct scsi_qla_host *ha, unsigned long off) |
| 35 | { |
| 36 | if ((off < ha->first_page_group_end) && |
| 37 | (off >= ha->first_page_group_start)) |
| 38 | return (void __iomem *)(ha->nx_pcibase + off); |
| 39 | |
| 40 | return NULL; |
| 41 | } |
| 42 | |
| 43 | #define MAX_CRB_XFORM 60 |
| 44 | static unsigned long crb_addr_xform[MAX_CRB_XFORM]; |
| 45 | static int qla4_8xxx_crb_table_initialized; |
| 46 | |
| 47 | #define qla4_8xxx_crb_addr_transform(name) \ |
| 48 | (crb_addr_xform[QLA82XX_HW_PX_MAP_CRB_##name] = \ |
| 49 | QLA82XX_HW_CRB_HUB_AGT_ADR_##name << 20) |
| 50 | static void |
| 51 | qla4_8xxx_crb_addr_transform_setup(void) |
| 52 | { |
| 53 | qla4_8xxx_crb_addr_transform(XDMA); |
| 54 | qla4_8xxx_crb_addr_transform(TIMR); |
| 55 | qla4_8xxx_crb_addr_transform(SRE); |
| 56 | qla4_8xxx_crb_addr_transform(SQN3); |
| 57 | qla4_8xxx_crb_addr_transform(SQN2); |
| 58 | qla4_8xxx_crb_addr_transform(SQN1); |
| 59 | qla4_8xxx_crb_addr_transform(SQN0); |
| 60 | qla4_8xxx_crb_addr_transform(SQS3); |
| 61 | qla4_8xxx_crb_addr_transform(SQS2); |
| 62 | qla4_8xxx_crb_addr_transform(SQS1); |
| 63 | qla4_8xxx_crb_addr_transform(SQS0); |
| 64 | qla4_8xxx_crb_addr_transform(RPMX7); |
| 65 | qla4_8xxx_crb_addr_transform(RPMX6); |
| 66 | qla4_8xxx_crb_addr_transform(RPMX5); |
| 67 | qla4_8xxx_crb_addr_transform(RPMX4); |
| 68 | qla4_8xxx_crb_addr_transform(RPMX3); |
| 69 | qla4_8xxx_crb_addr_transform(RPMX2); |
| 70 | qla4_8xxx_crb_addr_transform(RPMX1); |
| 71 | qla4_8xxx_crb_addr_transform(RPMX0); |
| 72 | qla4_8xxx_crb_addr_transform(ROMUSB); |
| 73 | qla4_8xxx_crb_addr_transform(SN); |
| 74 | qla4_8xxx_crb_addr_transform(QMN); |
| 75 | qla4_8xxx_crb_addr_transform(QMS); |
| 76 | qla4_8xxx_crb_addr_transform(PGNI); |
| 77 | qla4_8xxx_crb_addr_transform(PGND); |
| 78 | qla4_8xxx_crb_addr_transform(PGN3); |
| 79 | qla4_8xxx_crb_addr_transform(PGN2); |
| 80 | qla4_8xxx_crb_addr_transform(PGN1); |
| 81 | qla4_8xxx_crb_addr_transform(PGN0); |
| 82 | qla4_8xxx_crb_addr_transform(PGSI); |
| 83 | qla4_8xxx_crb_addr_transform(PGSD); |
| 84 | qla4_8xxx_crb_addr_transform(PGS3); |
| 85 | qla4_8xxx_crb_addr_transform(PGS2); |
| 86 | qla4_8xxx_crb_addr_transform(PGS1); |
| 87 | qla4_8xxx_crb_addr_transform(PGS0); |
| 88 | qla4_8xxx_crb_addr_transform(PS); |
| 89 | qla4_8xxx_crb_addr_transform(PH); |
| 90 | qla4_8xxx_crb_addr_transform(NIU); |
| 91 | qla4_8xxx_crb_addr_transform(I2Q); |
| 92 | qla4_8xxx_crb_addr_transform(EG); |
| 93 | qla4_8xxx_crb_addr_transform(MN); |
| 94 | qla4_8xxx_crb_addr_transform(MS); |
| 95 | qla4_8xxx_crb_addr_transform(CAS2); |
| 96 | qla4_8xxx_crb_addr_transform(CAS1); |
| 97 | qla4_8xxx_crb_addr_transform(CAS0); |
| 98 | qla4_8xxx_crb_addr_transform(CAM); |
| 99 | qla4_8xxx_crb_addr_transform(C2C1); |
| 100 | qla4_8xxx_crb_addr_transform(C2C0); |
| 101 | qla4_8xxx_crb_addr_transform(SMB); |
| 102 | qla4_8xxx_crb_addr_transform(OCM0); |
| 103 | qla4_8xxx_crb_addr_transform(I2C0); |
| 104 | |
| 105 | qla4_8xxx_crb_table_initialized = 1; |
| 106 | } |
| 107 | |
| 108 | static struct crb_128M_2M_block_map crb_128M_2M_map[64] = { |
| 109 | {{{0, 0, 0, 0} } }, /* 0: PCI */ |
| 110 | {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */ |
| 111 | {1, 0x0110000, 0x0120000, 0x130000}, |
| 112 | {1, 0x0120000, 0x0122000, 0x124000}, |
| 113 | {1, 0x0130000, 0x0132000, 0x126000}, |
| 114 | {1, 0x0140000, 0x0142000, 0x128000}, |
| 115 | {1, 0x0150000, 0x0152000, 0x12a000}, |
| 116 | {1, 0x0160000, 0x0170000, 0x110000}, |
| 117 | {1, 0x0170000, 0x0172000, 0x12e000}, |
| 118 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 119 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 120 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 121 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 122 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 123 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 124 | {1, 0x01e0000, 0x01e0800, 0x122000}, |
| 125 | {0, 0x0000000, 0x0000000, 0x000000} } }, |
| 126 | {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */ |
| 127 | {{{0, 0, 0, 0} } }, /* 3: */ |
| 128 | {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */ |
| 129 | {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */ |
| 130 | {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */ |
| 131 | {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */ |
| 132 | {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */ |
| 133 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 134 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 135 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 136 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 137 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 138 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 139 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 140 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 141 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 142 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 143 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 144 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 145 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 146 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 147 | {1, 0x08f0000, 0x08f2000, 0x172000} } }, |
| 148 | {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/ |
| 149 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 150 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 151 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 152 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 153 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 154 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 155 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 156 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 157 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 158 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 159 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 160 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 161 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 162 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 163 | {1, 0x09f0000, 0x09f2000, 0x176000} } }, |
| 164 | {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/ |
| 165 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 166 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 167 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 168 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 169 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 170 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 171 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 172 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 173 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 174 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 175 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 176 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 177 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 178 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 179 | {1, 0x0af0000, 0x0af2000, 0x17a000} } }, |
| 180 | {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/ |
| 181 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 182 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 183 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 184 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 185 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 186 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 187 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 188 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 189 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 190 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 191 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 192 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 193 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 194 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 195 | {1, 0x0bf0000, 0x0bf2000, 0x17e000} } }, |
| 196 | {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */ |
| 197 | {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */ |
| 198 | {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */ |
| 199 | {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */ |
| 200 | {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */ |
| 201 | {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */ |
| 202 | {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */ |
| 203 | {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */ |
| 204 | {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */ |
| 205 | {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */ |
| 206 | {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */ |
| 207 | {{{0, 0, 0, 0} } }, /* 23: */ |
| 208 | {{{0, 0, 0, 0} } }, /* 24: */ |
| 209 | {{{0, 0, 0, 0} } }, /* 25: */ |
| 210 | {{{0, 0, 0, 0} } }, /* 26: */ |
| 211 | {{{0, 0, 0, 0} } }, /* 27: */ |
| 212 | {{{0, 0, 0, 0} } }, /* 28: */ |
| 213 | {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */ |
| 214 | {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */ |
| 215 | {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */ |
| 216 | {{{0} } }, /* 32: PCI */ |
| 217 | {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */ |
| 218 | {1, 0x2110000, 0x2120000, 0x130000}, |
| 219 | {1, 0x2120000, 0x2122000, 0x124000}, |
| 220 | {1, 0x2130000, 0x2132000, 0x126000}, |
| 221 | {1, 0x2140000, 0x2142000, 0x128000}, |
| 222 | {1, 0x2150000, 0x2152000, 0x12a000}, |
| 223 | {1, 0x2160000, 0x2170000, 0x110000}, |
| 224 | {1, 0x2170000, 0x2172000, 0x12e000}, |
| 225 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 226 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 227 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 228 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 229 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 230 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 231 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 232 | {0, 0x0000000, 0x0000000, 0x000000} } }, |
| 233 | {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */ |
| 234 | {{{0} } }, /* 35: */ |
| 235 | {{{0} } }, /* 36: */ |
| 236 | {{{0} } }, /* 37: */ |
| 237 | {{{0} } }, /* 38: */ |
| 238 | {{{0} } }, /* 39: */ |
| 239 | {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */ |
| 240 | {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */ |
| 241 | {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */ |
| 242 | {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */ |
| 243 | {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */ |
| 244 | {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */ |
| 245 | {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */ |
| 246 | {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */ |
| 247 | {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */ |
| 248 | {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */ |
| 249 | {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */ |
| 250 | {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */ |
| 251 | {{{0} } }, /* 52: */ |
| 252 | {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */ |
| 253 | {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */ |
| 254 | {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */ |
| 255 | {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */ |
| 256 | {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */ |
| 257 | {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */ |
| 258 | {{{0} } }, /* 59: I2C0 */ |
| 259 | {{{0} } }, /* 60: I2C1 */ |
| 260 | {{{1, 0x3d00000, 0x3d04000, 0x1dc000} } },/* 61: LPC */ |
| 261 | {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */ |
| 262 | {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */ |
| 263 | }; |
| 264 | |
| 265 | /* |
| 266 | * top 12 bits of crb internal address (hub, agent) |
| 267 | */ |
| 268 | static unsigned qla4_8xxx_crb_hub_agt[64] = { |
| 269 | 0, |
| 270 | QLA82XX_HW_CRB_HUB_AGT_ADR_PS, |
| 271 | QLA82XX_HW_CRB_HUB_AGT_ADR_MN, |
| 272 | QLA82XX_HW_CRB_HUB_AGT_ADR_MS, |
| 273 | 0, |
| 274 | QLA82XX_HW_CRB_HUB_AGT_ADR_SRE, |
| 275 | QLA82XX_HW_CRB_HUB_AGT_ADR_NIU, |
| 276 | QLA82XX_HW_CRB_HUB_AGT_ADR_QMN, |
| 277 | QLA82XX_HW_CRB_HUB_AGT_ADR_SQN0, |
| 278 | QLA82XX_HW_CRB_HUB_AGT_ADR_SQN1, |
| 279 | QLA82XX_HW_CRB_HUB_AGT_ADR_SQN2, |
| 280 | QLA82XX_HW_CRB_HUB_AGT_ADR_SQN3, |
| 281 | QLA82XX_HW_CRB_HUB_AGT_ADR_I2Q, |
| 282 | QLA82XX_HW_CRB_HUB_AGT_ADR_TIMR, |
| 283 | QLA82XX_HW_CRB_HUB_AGT_ADR_ROMUSB, |
| 284 | QLA82XX_HW_CRB_HUB_AGT_ADR_PGN4, |
| 285 | QLA82XX_HW_CRB_HUB_AGT_ADR_XDMA, |
| 286 | QLA82XX_HW_CRB_HUB_AGT_ADR_PGN0, |
| 287 | QLA82XX_HW_CRB_HUB_AGT_ADR_PGN1, |
| 288 | QLA82XX_HW_CRB_HUB_AGT_ADR_PGN2, |
| 289 | QLA82XX_HW_CRB_HUB_AGT_ADR_PGN3, |
| 290 | QLA82XX_HW_CRB_HUB_AGT_ADR_PGND, |
| 291 | QLA82XX_HW_CRB_HUB_AGT_ADR_PGNI, |
| 292 | QLA82XX_HW_CRB_HUB_AGT_ADR_PGS0, |
| 293 | QLA82XX_HW_CRB_HUB_AGT_ADR_PGS1, |
| 294 | QLA82XX_HW_CRB_HUB_AGT_ADR_PGS2, |
| 295 | QLA82XX_HW_CRB_HUB_AGT_ADR_PGS3, |
| 296 | 0, |
| 297 | QLA82XX_HW_CRB_HUB_AGT_ADR_PGSI, |
| 298 | QLA82XX_HW_CRB_HUB_AGT_ADR_SN, |
| 299 | 0, |
| 300 | QLA82XX_HW_CRB_HUB_AGT_ADR_EG, |
| 301 | 0, |
| 302 | QLA82XX_HW_CRB_HUB_AGT_ADR_PS, |
| 303 | QLA82XX_HW_CRB_HUB_AGT_ADR_CAM, |
| 304 | 0, |
| 305 | 0, |
| 306 | 0, |
| 307 | 0, |
| 308 | 0, |
| 309 | QLA82XX_HW_CRB_HUB_AGT_ADR_TIMR, |
| 310 | 0, |
| 311 | QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX1, |
| 312 | QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX2, |
| 313 | QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX3, |
| 314 | QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX4, |
| 315 | QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX5, |
| 316 | QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX6, |
| 317 | QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX7, |
| 318 | QLA82XX_HW_CRB_HUB_AGT_ADR_XDMA, |
| 319 | QLA82XX_HW_CRB_HUB_AGT_ADR_I2Q, |
| 320 | QLA82XX_HW_CRB_HUB_AGT_ADR_ROMUSB, |
| 321 | 0, |
| 322 | QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX0, |
| 323 | QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX8, |
| 324 | QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX9, |
| 325 | QLA82XX_HW_CRB_HUB_AGT_ADR_OCM0, |
| 326 | 0, |
| 327 | QLA82XX_HW_CRB_HUB_AGT_ADR_SMB, |
| 328 | QLA82XX_HW_CRB_HUB_AGT_ADR_I2C0, |
| 329 | QLA82XX_HW_CRB_HUB_AGT_ADR_I2C1, |
| 330 | 0, |
| 331 | QLA82XX_HW_CRB_HUB_AGT_ADR_PGNC, |
| 332 | 0, |
| 333 | }; |
| 334 | |
| 335 | /* Device states */ |
| 336 | static char *qdev_state[] = { |
| 337 | "Unknown", |
| 338 | "Cold", |
| 339 | "Initializing", |
| 340 | "Ready", |
| 341 | "Need Reset", |
| 342 | "Need Quiescent", |
| 343 | "Failed", |
| 344 | "Quiescent", |
| 345 | }; |
| 346 | |
| 347 | /* |
| 348 | * In: 'off' is offset from CRB space in 128M pci map |
| 349 | * Out: 'off' is 2M pci map addr |
| 350 | * side effect: lock crb window |
| 351 | */ |
| 352 | static void |
| 353 | qla4_8xxx_pci_set_crbwindow_2M(struct scsi_qla_host *ha, ulong *off) |
| 354 | { |
| 355 | u32 win_read; |
| 356 | |
| 357 | ha->crb_win = CRB_HI(*off); |
| 358 | writel(ha->crb_win, |
| 359 | (void __iomem *)(CRB_WINDOW_2M + ha->nx_pcibase)); |
| 360 | |
| 361 | /* Read back value to make sure write has gone through before trying |
| 362 | * to use it. */ |
| 363 | win_read = readl((void __iomem *)(CRB_WINDOW_2M + ha->nx_pcibase)); |
| 364 | if (win_read != ha->crb_win) { |
| 365 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 366 | "%s: Written crbwin (0x%x) != Read crbwin (0x%x)," |
| 367 | " off=0x%lx\n", __func__, ha->crb_win, win_read, *off)); |
| 368 | } |
| 369 | *off = (*off & MASK(16)) + CRB_INDIRECT_2M + ha->nx_pcibase; |
| 370 | } |
| 371 | |
| 372 | void |
| 373 | qla4_8xxx_wr_32(struct scsi_qla_host *ha, ulong off, u32 data) |
| 374 | { |
| 375 | unsigned long flags = 0; |
| 376 | int rv; |
| 377 | |
| 378 | rv = qla4_8xxx_pci_get_crb_addr_2M(ha, &off); |
| 379 | |
| 380 | BUG_ON(rv == -1); |
| 381 | |
| 382 | if (rv == 1) { |
| 383 | write_lock_irqsave(&ha->hw_lock, flags); |
| 384 | qla4_8xxx_crb_win_lock(ha); |
| 385 | qla4_8xxx_pci_set_crbwindow_2M(ha, &off); |
| 386 | } |
| 387 | |
| 388 | writel(data, (void __iomem *)off); |
| 389 | |
| 390 | if (rv == 1) { |
| 391 | qla4_8xxx_crb_win_unlock(ha); |
| 392 | write_unlock_irqrestore(&ha->hw_lock, flags); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | int |
| 397 | qla4_8xxx_rd_32(struct scsi_qla_host *ha, ulong off) |
| 398 | { |
| 399 | unsigned long flags = 0; |
| 400 | int rv; |
| 401 | u32 data; |
| 402 | |
| 403 | rv = qla4_8xxx_pci_get_crb_addr_2M(ha, &off); |
| 404 | |
| 405 | BUG_ON(rv == -1); |
| 406 | |
| 407 | if (rv == 1) { |
| 408 | write_lock_irqsave(&ha->hw_lock, flags); |
| 409 | qla4_8xxx_crb_win_lock(ha); |
| 410 | qla4_8xxx_pci_set_crbwindow_2M(ha, &off); |
| 411 | } |
| 412 | data = readl((void __iomem *)off); |
| 413 | |
| 414 | if (rv == 1) { |
| 415 | qla4_8xxx_crb_win_unlock(ha); |
| 416 | write_unlock_irqrestore(&ha->hw_lock, flags); |
| 417 | } |
| 418 | return data; |
| 419 | } |
| 420 | |
| 421 | #define CRB_WIN_LOCK_TIMEOUT 100000000 |
| 422 | |
| 423 | int qla4_8xxx_crb_win_lock(struct scsi_qla_host *ha) |
| 424 | { |
| 425 | int i; |
| 426 | int done = 0, timeout = 0; |
| 427 | |
| 428 | while (!done) { |
| 429 | /* acquire semaphore3 from PCI HW block */ |
| 430 | done = qla4_8xxx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM7_LOCK)); |
| 431 | if (done == 1) |
| 432 | break; |
| 433 | if (timeout >= CRB_WIN_LOCK_TIMEOUT) |
| 434 | return -1; |
| 435 | |
| 436 | timeout++; |
| 437 | |
| 438 | /* Yield CPU */ |
| 439 | if (!in_interrupt()) |
| 440 | schedule(); |
| 441 | else { |
| 442 | for (i = 0; i < 20; i++) |
| 443 | cpu_relax(); /*This a nop instr on i386*/ |
| 444 | } |
| 445 | } |
| 446 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_WIN_LOCK_ID, ha->func_num); |
| 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | void qla4_8xxx_crb_win_unlock(struct scsi_qla_host *ha) |
| 451 | { |
| 452 | qla4_8xxx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM7_UNLOCK)); |
| 453 | } |
| 454 | |
| 455 | #define IDC_LOCK_TIMEOUT 100000000 |
| 456 | |
| 457 | /** |
| 458 | * qla4_8xxx_idc_lock - hw_lock |
| 459 | * @ha: pointer to adapter structure |
| 460 | * |
| 461 | * General purpose lock used to synchronize access to |
| 462 | * CRB_DEV_STATE, CRB_DEV_REF_COUNT, etc. |
| 463 | **/ |
| 464 | int qla4_8xxx_idc_lock(struct scsi_qla_host *ha) |
| 465 | { |
| 466 | int i; |
| 467 | int done = 0, timeout = 0; |
| 468 | |
| 469 | while (!done) { |
| 470 | /* acquire semaphore5 from PCI HW block */ |
| 471 | done = qla4_8xxx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM5_LOCK)); |
| 472 | if (done == 1) |
| 473 | break; |
| 474 | if (timeout >= IDC_LOCK_TIMEOUT) |
| 475 | return -1; |
| 476 | |
| 477 | timeout++; |
| 478 | |
| 479 | /* Yield CPU */ |
| 480 | if (!in_interrupt()) |
| 481 | schedule(); |
| 482 | else { |
| 483 | for (i = 0; i < 20; i++) |
| 484 | cpu_relax(); /*This a nop instr on i386*/ |
| 485 | } |
| 486 | } |
| 487 | return 0; |
| 488 | } |
| 489 | |
| 490 | void qla4_8xxx_idc_unlock(struct scsi_qla_host *ha) |
| 491 | { |
| 492 | qla4_8xxx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM5_UNLOCK)); |
| 493 | } |
| 494 | |
| 495 | int |
| 496 | qla4_8xxx_pci_get_crb_addr_2M(struct scsi_qla_host *ha, ulong *off) |
| 497 | { |
| 498 | struct crb_128M_2M_sub_block_map *m; |
| 499 | |
| 500 | if (*off >= QLA82XX_CRB_MAX) |
| 501 | return -1; |
| 502 | |
| 503 | if (*off >= QLA82XX_PCI_CAMQM && (*off < QLA82XX_PCI_CAMQM_2M_END)) { |
| 504 | *off = (*off - QLA82XX_PCI_CAMQM) + |
| 505 | QLA82XX_PCI_CAMQM_2M_BASE + ha->nx_pcibase; |
| 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | if (*off < QLA82XX_PCI_CRBSPACE) |
| 510 | return -1; |
| 511 | |
| 512 | *off -= QLA82XX_PCI_CRBSPACE; |
| 513 | /* |
| 514 | * Try direct map |
| 515 | */ |
| 516 | |
| 517 | m = &crb_128M_2M_map[CRB_BLK(*off)].sub_block[CRB_SUBBLK(*off)]; |
| 518 | |
| 519 | if (m->valid && (m->start_128M <= *off) && (m->end_128M > *off)) { |
| 520 | *off = *off + m->start_2M - m->start_128M + ha->nx_pcibase; |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | /* |
| 525 | * Not in direct map, use crb window |
| 526 | */ |
| 527 | return 1; |
| 528 | } |
| 529 | |
| 530 | /* PCI Windowing for DDR regions. */ |
| 531 | #define QLA82XX_ADDR_IN_RANGE(addr, low, high) \ |
| 532 | (((addr) <= (high)) && ((addr) >= (low))) |
| 533 | |
| 534 | /* |
| 535 | * check memory access boundary. |
| 536 | * used by test agent. support ddr access only for now |
| 537 | */ |
| 538 | static unsigned long |
| 539 | qla4_8xxx_pci_mem_bound_check(struct scsi_qla_host *ha, |
| 540 | unsigned long long addr, int size) |
| 541 | { |
| 542 | if (!QLA82XX_ADDR_IN_RANGE(addr, QLA82XX_ADDR_DDR_NET, |
| 543 | QLA82XX_ADDR_DDR_NET_MAX) || |
| 544 | !QLA82XX_ADDR_IN_RANGE(addr + size - 1, |
| 545 | QLA82XX_ADDR_DDR_NET, QLA82XX_ADDR_DDR_NET_MAX) || |
| 546 | ((size != 1) && (size != 2) && (size != 4) && (size != 8))) { |
| 547 | return 0; |
| 548 | } |
| 549 | return 1; |
| 550 | } |
| 551 | |
| 552 | static int qla4_8xxx_pci_set_window_warning_count; |
| 553 | |
| 554 | static unsigned long |
| 555 | qla4_8xxx_pci_set_window(struct scsi_qla_host *ha, unsigned long long addr) |
| 556 | { |
| 557 | int window; |
| 558 | u32 win_read; |
| 559 | |
| 560 | if (QLA82XX_ADDR_IN_RANGE(addr, QLA82XX_ADDR_DDR_NET, |
| 561 | QLA82XX_ADDR_DDR_NET_MAX)) { |
| 562 | /* DDR network side */ |
| 563 | window = MN_WIN(addr); |
| 564 | ha->ddr_mn_window = window; |
| 565 | qla4_8xxx_wr_32(ha, ha->mn_win_crb | |
| 566 | QLA82XX_PCI_CRBSPACE, window); |
| 567 | win_read = qla4_8xxx_rd_32(ha, ha->mn_win_crb | |
| 568 | QLA82XX_PCI_CRBSPACE); |
| 569 | if ((win_read << 17) != window) { |
| 570 | ql4_printk(KERN_WARNING, ha, |
| 571 | "%s: Written MNwin (0x%x) != Read MNwin (0x%x)\n", |
| 572 | __func__, window, win_read); |
| 573 | } |
| 574 | addr = GET_MEM_OFFS_2M(addr) + QLA82XX_PCI_DDR_NET; |
| 575 | } else if (QLA82XX_ADDR_IN_RANGE(addr, QLA82XX_ADDR_OCM0, |
| 576 | QLA82XX_ADDR_OCM0_MAX)) { |
| 577 | unsigned int temp1; |
| 578 | /* if bits 19:18&17:11 are on */ |
| 579 | if ((addr & 0x00ff800) == 0xff800) { |
| 580 | printk("%s: QM access not handled.\n", __func__); |
| 581 | addr = -1UL; |
| 582 | } |
| 583 | |
| 584 | window = OCM_WIN(addr); |
| 585 | ha->ddr_mn_window = window; |
| 586 | qla4_8xxx_wr_32(ha, ha->mn_win_crb | |
| 587 | QLA82XX_PCI_CRBSPACE, window); |
| 588 | win_read = qla4_8xxx_rd_32(ha, ha->mn_win_crb | |
| 589 | QLA82XX_PCI_CRBSPACE); |
| 590 | temp1 = ((window & 0x1FF) << 7) | |
| 591 | ((window & 0x0FFFE0000) >> 17); |
| 592 | if (win_read != temp1) { |
| 593 | printk("%s: Written OCMwin (0x%x) != Read" |
| 594 | " OCMwin (0x%x)\n", __func__, temp1, win_read); |
| 595 | } |
| 596 | addr = GET_MEM_OFFS_2M(addr) + QLA82XX_PCI_OCM0_2M; |
| 597 | |
| 598 | } else if (QLA82XX_ADDR_IN_RANGE(addr, QLA82XX_ADDR_QDR_NET, |
| 599 | QLA82XX_P3_ADDR_QDR_NET_MAX)) { |
| 600 | /* QDR network side */ |
| 601 | window = MS_WIN(addr); |
| 602 | ha->qdr_sn_window = window; |
| 603 | qla4_8xxx_wr_32(ha, ha->ms_win_crb | |
| 604 | QLA82XX_PCI_CRBSPACE, window); |
| 605 | win_read = qla4_8xxx_rd_32(ha, |
| 606 | ha->ms_win_crb | QLA82XX_PCI_CRBSPACE); |
| 607 | if (win_read != window) { |
| 608 | printk("%s: Written MSwin (0x%x) != Read " |
| 609 | "MSwin (0x%x)\n", __func__, window, win_read); |
| 610 | } |
| 611 | addr = GET_MEM_OFFS_2M(addr) + QLA82XX_PCI_QDR_NET; |
| 612 | |
| 613 | } else { |
| 614 | /* |
| 615 | * peg gdb frequently accesses memory that doesn't exist, |
| 616 | * this limits the chit chat so debugging isn't slowed down. |
| 617 | */ |
| 618 | if ((qla4_8xxx_pci_set_window_warning_count++ < 8) || |
| 619 | (qla4_8xxx_pci_set_window_warning_count%64 == 0)) { |
| 620 | printk("%s: Warning:%s Unknown address range!\n", |
| 621 | __func__, DRIVER_NAME); |
| 622 | } |
| 623 | addr = -1UL; |
| 624 | } |
| 625 | return addr; |
| 626 | } |
| 627 | |
| 628 | /* check if address is in the same windows as the previous access */ |
| 629 | static int qla4_8xxx_pci_is_same_window(struct scsi_qla_host *ha, |
| 630 | unsigned long long addr) |
| 631 | { |
| 632 | int window; |
| 633 | unsigned long long qdr_max; |
| 634 | |
| 635 | qdr_max = QLA82XX_P3_ADDR_QDR_NET_MAX; |
| 636 | |
| 637 | if (QLA82XX_ADDR_IN_RANGE(addr, QLA82XX_ADDR_DDR_NET, |
| 638 | QLA82XX_ADDR_DDR_NET_MAX)) { |
| 639 | /* DDR network side */ |
| 640 | BUG(); /* MN access can not come here */ |
| 641 | } else if (QLA82XX_ADDR_IN_RANGE(addr, QLA82XX_ADDR_OCM0, |
| 642 | QLA82XX_ADDR_OCM0_MAX)) { |
| 643 | return 1; |
| 644 | } else if (QLA82XX_ADDR_IN_RANGE(addr, QLA82XX_ADDR_OCM1, |
| 645 | QLA82XX_ADDR_OCM1_MAX)) { |
| 646 | return 1; |
| 647 | } else if (QLA82XX_ADDR_IN_RANGE(addr, QLA82XX_ADDR_QDR_NET, |
| 648 | qdr_max)) { |
| 649 | /* QDR network side */ |
| 650 | window = ((addr - QLA82XX_ADDR_QDR_NET) >> 22) & 0x3f; |
| 651 | if (ha->qdr_sn_window == window) |
| 652 | return 1; |
| 653 | } |
| 654 | |
| 655 | return 0; |
| 656 | } |
| 657 | |
| 658 | static int qla4_8xxx_pci_mem_read_direct(struct scsi_qla_host *ha, |
| 659 | u64 off, void *data, int size) |
| 660 | { |
| 661 | unsigned long flags; |
| 662 | void __iomem *addr; |
| 663 | int ret = 0; |
| 664 | u64 start; |
| 665 | void __iomem *mem_ptr = NULL; |
| 666 | unsigned long mem_base; |
| 667 | unsigned long mem_page; |
| 668 | |
| 669 | write_lock_irqsave(&ha->hw_lock, flags); |
| 670 | |
| 671 | /* |
| 672 | * If attempting to access unknown address or straddle hw windows, |
| 673 | * do not access. |
| 674 | */ |
| 675 | start = qla4_8xxx_pci_set_window(ha, off); |
| 676 | if ((start == -1UL) || |
| 677 | (qla4_8xxx_pci_is_same_window(ha, off + size - 1) == 0)) { |
| 678 | write_unlock_irqrestore(&ha->hw_lock, flags); |
| 679 | printk(KERN_ERR"%s out of bound pci memory access. " |
| 680 | "offset is 0x%llx\n", DRIVER_NAME, off); |
| 681 | return -1; |
| 682 | } |
| 683 | |
| 684 | addr = qla4_8xxx_pci_base_offsetfset(ha, start); |
| 685 | if (!addr) { |
| 686 | write_unlock_irqrestore(&ha->hw_lock, flags); |
| 687 | mem_base = pci_resource_start(ha->pdev, 0); |
| 688 | mem_page = start & PAGE_MASK; |
| 689 | /* Map two pages whenever user tries to access addresses in two |
| 690 | consecutive pages. |
| 691 | */ |
| 692 | if (mem_page != ((start + size - 1) & PAGE_MASK)) |
| 693 | mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE * 2); |
| 694 | else |
| 695 | mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE); |
| 696 | |
| 697 | if (mem_ptr == NULL) { |
| 698 | *(u8 *)data = 0; |
| 699 | return -1; |
| 700 | } |
| 701 | addr = mem_ptr; |
| 702 | addr += start & (PAGE_SIZE - 1); |
| 703 | write_lock_irqsave(&ha->hw_lock, flags); |
| 704 | } |
| 705 | |
| 706 | switch (size) { |
| 707 | case 1: |
| 708 | *(u8 *)data = readb(addr); |
| 709 | break; |
| 710 | case 2: |
| 711 | *(u16 *)data = readw(addr); |
| 712 | break; |
| 713 | case 4: |
| 714 | *(u32 *)data = readl(addr); |
| 715 | break; |
| 716 | case 8: |
| 717 | *(u64 *)data = readq(addr); |
| 718 | break; |
| 719 | default: |
| 720 | ret = -1; |
| 721 | break; |
| 722 | } |
| 723 | write_unlock_irqrestore(&ha->hw_lock, flags); |
| 724 | |
| 725 | if (mem_ptr) |
| 726 | iounmap(mem_ptr); |
| 727 | return ret; |
| 728 | } |
| 729 | |
| 730 | static int |
| 731 | qla4_8xxx_pci_mem_write_direct(struct scsi_qla_host *ha, u64 off, |
| 732 | void *data, int size) |
| 733 | { |
| 734 | unsigned long flags; |
| 735 | void __iomem *addr; |
| 736 | int ret = 0; |
| 737 | u64 start; |
| 738 | void __iomem *mem_ptr = NULL; |
| 739 | unsigned long mem_base; |
| 740 | unsigned long mem_page; |
| 741 | |
| 742 | write_lock_irqsave(&ha->hw_lock, flags); |
| 743 | |
| 744 | /* |
| 745 | * If attempting to access unknown address or straddle hw windows, |
| 746 | * do not access. |
| 747 | */ |
| 748 | start = qla4_8xxx_pci_set_window(ha, off); |
| 749 | if ((start == -1UL) || |
| 750 | (qla4_8xxx_pci_is_same_window(ha, off + size - 1) == 0)) { |
| 751 | write_unlock_irqrestore(&ha->hw_lock, flags); |
| 752 | printk(KERN_ERR"%s out of bound pci memory access. " |
| 753 | "offset is 0x%llx\n", DRIVER_NAME, off); |
| 754 | return -1; |
| 755 | } |
| 756 | |
| 757 | addr = qla4_8xxx_pci_base_offsetfset(ha, start); |
| 758 | if (!addr) { |
| 759 | write_unlock_irqrestore(&ha->hw_lock, flags); |
| 760 | mem_base = pci_resource_start(ha->pdev, 0); |
| 761 | mem_page = start & PAGE_MASK; |
| 762 | /* Map two pages whenever user tries to access addresses in two |
| 763 | consecutive pages. |
| 764 | */ |
| 765 | if (mem_page != ((start + size - 1) & PAGE_MASK)) |
| 766 | mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE*2); |
| 767 | else |
| 768 | mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE); |
| 769 | if (mem_ptr == NULL) |
| 770 | return -1; |
| 771 | |
| 772 | addr = mem_ptr; |
| 773 | addr += start & (PAGE_SIZE - 1); |
| 774 | write_lock_irqsave(&ha->hw_lock, flags); |
| 775 | } |
| 776 | |
| 777 | switch (size) { |
| 778 | case 1: |
| 779 | writeb(*(u8 *)data, addr); |
| 780 | break; |
| 781 | case 2: |
| 782 | writew(*(u16 *)data, addr); |
| 783 | break; |
| 784 | case 4: |
| 785 | writel(*(u32 *)data, addr); |
| 786 | break; |
| 787 | case 8: |
| 788 | writeq(*(u64 *)data, addr); |
| 789 | break; |
| 790 | default: |
| 791 | ret = -1; |
| 792 | break; |
| 793 | } |
| 794 | write_unlock_irqrestore(&ha->hw_lock, flags); |
| 795 | if (mem_ptr) |
| 796 | iounmap(mem_ptr); |
| 797 | return ret; |
| 798 | } |
| 799 | |
| 800 | #define MTU_FUDGE_FACTOR 100 |
| 801 | |
| 802 | static unsigned long |
| 803 | qla4_8xxx_decode_crb_addr(unsigned long addr) |
| 804 | { |
| 805 | int i; |
| 806 | unsigned long base_addr, offset, pci_base; |
| 807 | |
| 808 | if (!qla4_8xxx_crb_table_initialized) |
| 809 | qla4_8xxx_crb_addr_transform_setup(); |
| 810 | |
| 811 | pci_base = ADDR_ERROR; |
| 812 | base_addr = addr & 0xfff00000; |
| 813 | offset = addr & 0x000fffff; |
| 814 | |
| 815 | for (i = 0; i < MAX_CRB_XFORM; i++) { |
| 816 | if (crb_addr_xform[i] == base_addr) { |
| 817 | pci_base = i << 20; |
| 818 | break; |
| 819 | } |
| 820 | } |
| 821 | if (pci_base == ADDR_ERROR) |
| 822 | return pci_base; |
| 823 | else |
| 824 | return pci_base + offset; |
| 825 | } |
| 826 | |
| 827 | static long rom_max_timeout = 100; |
| 828 | static long qla4_8xxx_rom_lock_timeout = 100; |
| 829 | |
| 830 | static int |
| 831 | qla4_8xxx_rom_lock(struct scsi_qla_host *ha) |
| 832 | { |
| 833 | int i; |
| 834 | int done = 0, timeout = 0; |
| 835 | |
| 836 | while (!done) { |
| 837 | /* acquire semaphore2 from PCI HW block */ |
| 838 | |
| 839 | done = qla4_8xxx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM2_LOCK)); |
| 840 | if (done == 1) |
| 841 | break; |
Shyam Sundar | b25ee66 | 2010-10-06 22:50:51 -0700 | [diff] [blame] | 842 | if (timeout >= qla4_8xxx_rom_lock_timeout) { |
| 843 | ql4_printk(KERN_WARNING, ha, |
| 844 | "%s: Failed to acquire rom lock", __func__); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 845 | return -1; |
Shyam Sundar | b25ee66 | 2010-10-06 22:50:51 -0700 | [diff] [blame] | 846 | } |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 847 | |
| 848 | timeout++; |
| 849 | |
| 850 | /* Yield CPU */ |
| 851 | if (!in_interrupt()) |
| 852 | schedule(); |
| 853 | else { |
| 854 | for (i = 0; i < 20; i++) |
| 855 | cpu_relax(); /*This a nop instr on i386*/ |
| 856 | } |
| 857 | } |
| 858 | qla4_8xxx_wr_32(ha, QLA82XX_ROM_LOCK_ID, ROM_LOCK_DRIVER); |
| 859 | return 0; |
| 860 | } |
| 861 | |
| 862 | static void |
| 863 | qla4_8xxx_rom_unlock(struct scsi_qla_host *ha) |
| 864 | { |
| 865 | qla4_8xxx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM2_UNLOCK)); |
| 866 | } |
| 867 | |
| 868 | static int |
| 869 | qla4_8xxx_wait_rom_done(struct scsi_qla_host *ha) |
| 870 | { |
| 871 | long timeout = 0; |
| 872 | long done = 0 ; |
| 873 | |
| 874 | while (done == 0) { |
| 875 | done = qla4_8xxx_rd_32(ha, QLA82XX_ROMUSB_GLB_STATUS); |
| 876 | done &= 2; |
| 877 | timeout++; |
| 878 | if (timeout >= rom_max_timeout) { |
| 879 | printk("%s: Timeout reached waiting for rom done", |
| 880 | DRIVER_NAME); |
| 881 | return -1; |
| 882 | } |
| 883 | } |
| 884 | return 0; |
| 885 | } |
| 886 | |
| 887 | static int |
| 888 | qla4_8xxx_do_rom_fast_read(struct scsi_qla_host *ha, int addr, int *valp) |
| 889 | { |
| 890 | qla4_8xxx_wr_32(ha, QLA82XX_ROMUSB_ROM_ADDRESS, addr); |
| 891 | qla4_8xxx_wr_32(ha, QLA82XX_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); |
| 892 | qla4_8xxx_wr_32(ha, QLA82XX_ROMUSB_ROM_ABYTE_CNT, 3); |
| 893 | qla4_8xxx_wr_32(ha, QLA82XX_ROMUSB_ROM_INSTR_OPCODE, 0xb); |
| 894 | if (qla4_8xxx_wait_rom_done(ha)) { |
| 895 | printk("%s: Error waiting for rom done\n", DRIVER_NAME); |
| 896 | return -1; |
| 897 | } |
| 898 | /* reset abyte_cnt and dummy_byte_cnt */ |
| 899 | qla4_8xxx_wr_32(ha, QLA82XX_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); |
| 900 | udelay(10); |
| 901 | qla4_8xxx_wr_32(ha, QLA82XX_ROMUSB_ROM_ABYTE_CNT, 0); |
| 902 | |
| 903 | *valp = qla4_8xxx_rd_32(ha, QLA82XX_ROMUSB_ROM_RDATA); |
| 904 | return 0; |
| 905 | } |
| 906 | |
| 907 | static int |
| 908 | qla4_8xxx_rom_fast_read(struct scsi_qla_host *ha, int addr, int *valp) |
| 909 | { |
| 910 | int ret, loops = 0; |
| 911 | |
| 912 | while ((qla4_8xxx_rom_lock(ha) != 0) && (loops < 50000)) { |
| 913 | udelay(100); |
| 914 | loops++; |
| 915 | } |
| 916 | if (loops >= 50000) { |
| 917 | printk("%s: qla4_8xxx_rom_lock failed\n", DRIVER_NAME); |
| 918 | return -1; |
| 919 | } |
| 920 | ret = qla4_8xxx_do_rom_fast_read(ha, addr, valp); |
| 921 | qla4_8xxx_rom_unlock(ha); |
| 922 | return ret; |
| 923 | } |
| 924 | |
| 925 | /** |
| 926 | * This routine does CRB initialize sequence |
| 927 | * to put the ISP into operational state |
| 928 | **/ |
| 929 | static int |
| 930 | qla4_8xxx_pinit_from_rom(struct scsi_qla_host *ha, int verbose) |
| 931 | { |
| 932 | int addr, val; |
| 933 | int i ; |
| 934 | struct crb_addr_pair *buf; |
| 935 | unsigned long off; |
| 936 | unsigned offset, n; |
| 937 | |
| 938 | struct crb_addr_pair { |
| 939 | long addr; |
| 940 | long data; |
| 941 | }; |
| 942 | |
| 943 | /* Halt all the indiviual PEGs and other blocks of the ISP */ |
| 944 | qla4_8xxx_rom_lock(ha); |
Swapnil Nagle | a1fc26b | 2010-12-02 22:12:15 -0800 | [diff] [blame] | 945 | |
| 946 | /* mask all niu interrupts */ |
| 947 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_NIU + 0x40, 0xff); |
| 948 | /* disable xge rx/tx */ |
| 949 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_NIU + 0x70000, 0x00); |
| 950 | /* disable xg1 rx/tx */ |
| 951 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_NIU + 0x80000, 0x00); |
| 952 | |
| 953 | /* halt sre */ |
| 954 | val = qla4_8xxx_rd_32(ha, QLA82XX_CRB_SRE + 0x1000); |
| 955 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_SRE + 0x1000, val & (~(0x1))); |
| 956 | |
| 957 | /* halt epg */ |
| 958 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_EPG + 0x1300, 0x1); |
| 959 | |
| 960 | /* halt timers */ |
| 961 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_TIMER + 0x0, 0x0); |
| 962 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_TIMER + 0x8, 0x0); |
| 963 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_TIMER + 0x10, 0x0); |
| 964 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_TIMER + 0x18, 0x0); |
| 965 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_TIMER + 0x100, 0x0); |
| 966 | |
| 967 | /* halt pegs */ |
| 968 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_PEG_NET_0 + 0x3c, 1); |
| 969 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_PEG_NET_1 + 0x3c, 1); |
| 970 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_PEG_NET_2 + 0x3c, 1); |
| 971 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_PEG_NET_3 + 0x3c, 1); |
| 972 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_PEG_NET_4 + 0x3c, 1); |
| 973 | |
| 974 | /* big hammer */ |
| 975 | msleep(1000); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 976 | if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 977 | /* don't reset CAM block on reset */ |
| 978 | qla4_8xxx_wr_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET, 0xfeffffff); |
| 979 | else |
| 980 | qla4_8xxx_wr_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET, 0xffffffff); |
| 981 | |
Swapnil Nagle | a1fc26b | 2010-12-02 22:12:15 -0800 | [diff] [blame] | 982 | /* reset ms */ |
| 983 | val = qla4_8xxx_rd_32(ha, QLA82XX_CRB_QDR_NET + 0xe4); |
| 984 | val |= (1 << 1); |
| 985 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_QDR_NET + 0xe4, val); |
| 986 | |
| 987 | msleep(20); |
| 988 | /* unreset ms */ |
| 989 | val = qla4_8xxx_rd_32(ha, QLA82XX_CRB_QDR_NET + 0xe4); |
| 990 | val &= ~(1 << 1); |
| 991 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_QDR_NET + 0xe4, val); |
| 992 | msleep(20); |
| 993 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 994 | qla4_8xxx_rom_unlock(ha); |
| 995 | |
| 996 | /* Read the signature value from the flash. |
| 997 | * Offset 0: Contain signature (0xcafecafe) |
| 998 | * Offset 4: Offset and number of addr/value pairs |
| 999 | * that present in CRB initialize sequence |
| 1000 | */ |
| 1001 | if (qla4_8xxx_rom_fast_read(ha, 0, &n) != 0 || n != 0xcafecafeUL || |
| 1002 | qla4_8xxx_rom_fast_read(ha, 4, &n) != 0) { |
| 1003 | ql4_printk(KERN_WARNING, ha, |
| 1004 | "[ERROR] Reading crb_init area: n: %08x\n", n); |
| 1005 | return -1; |
| 1006 | } |
| 1007 | |
| 1008 | /* Offset in flash = lower 16 bits |
| 1009 | * Number of enteries = upper 16 bits |
| 1010 | */ |
| 1011 | offset = n & 0xffffU; |
| 1012 | n = (n >> 16) & 0xffffU; |
| 1013 | |
| 1014 | /* number of addr/value pair should not exceed 1024 enteries */ |
| 1015 | if (n >= 1024) { |
| 1016 | ql4_printk(KERN_WARNING, ha, |
| 1017 | "%s: %s:n=0x%x [ERROR] Card flash not initialized.\n", |
| 1018 | DRIVER_NAME, __func__, n); |
| 1019 | return -1; |
| 1020 | } |
| 1021 | |
| 1022 | ql4_printk(KERN_INFO, ha, |
| 1023 | "%s: %d CRB init values found in ROM.\n", DRIVER_NAME, n); |
| 1024 | |
| 1025 | buf = kmalloc(n * sizeof(struct crb_addr_pair), GFP_KERNEL); |
| 1026 | if (buf == NULL) { |
| 1027 | ql4_printk(KERN_WARNING, ha, |
| 1028 | "%s: [ERROR] Unable to malloc memory.\n", DRIVER_NAME); |
| 1029 | return -1; |
| 1030 | } |
| 1031 | |
| 1032 | for (i = 0; i < n; i++) { |
| 1033 | if (qla4_8xxx_rom_fast_read(ha, 8*i + 4*offset, &val) != 0 || |
| 1034 | qla4_8xxx_rom_fast_read(ha, 8*i + 4*offset + 4, &addr) != |
| 1035 | 0) { |
| 1036 | kfree(buf); |
| 1037 | return -1; |
| 1038 | } |
| 1039 | |
| 1040 | buf[i].addr = addr; |
| 1041 | buf[i].data = val; |
| 1042 | } |
| 1043 | |
| 1044 | for (i = 0; i < n; i++) { |
| 1045 | /* Translate internal CRB initialization |
| 1046 | * address to PCI bus address |
| 1047 | */ |
| 1048 | off = qla4_8xxx_decode_crb_addr((unsigned long)buf[i].addr) + |
| 1049 | QLA82XX_PCI_CRBSPACE; |
| 1050 | /* Not all CRB addr/value pair to be written, |
| 1051 | * some of them are skipped |
| 1052 | */ |
| 1053 | |
| 1054 | /* skip if LS bit is set*/ |
| 1055 | if (off & 0x1) { |
| 1056 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 1057 | "Skip CRB init replay for offset = 0x%lx\n", off)); |
| 1058 | continue; |
| 1059 | } |
| 1060 | |
| 1061 | /* skipping cold reboot MAGIC */ |
| 1062 | if (off == QLA82XX_CAM_RAM(0x1fc)) |
| 1063 | continue; |
| 1064 | |
| 1065 | /* do not reset PCI */ |
| 1066 | if (off == (ROMUSB_GLB + 0xbc)) |
| 1067 | continue; |
| 1068 | |
| 1069 | /* skip core clock, so that firmware can increase the clock */ |
| 1070 | if (off == (ROMUSB_GLB + 0xc8)) |
| 1071 | continue; |
| 1072 | |
| 1073 | /* skip the function enable register */ |
| 1074 | if (off == QLA82XX_PCIE_REG(PCIE_SETUP_FUNCTION)) |
| 1075 | continue; |
| 1076 | |
| 1077 | if (off == QLA82XX_PCIE_REG(PCIE_SETUP_FUNCTION2)) |
| 1078 | continue; |
| 1079 | |
| 1080 | if ((off & 0x0ff00000) == QLA82XX_CRB_SMB) |
| 1081 | continue; |
| 1082 | |
| 1083 | if ((off & 0x0ff00000) == QLA82XX_CRB_DDR_NET) |
| 1084 | continue; |
| 1085 | |
| 1086 | if (off == ADDR_ERROR) { |
| 1087 | ql4_printk(KERN_WARNING, ha, |
| 1088 | "%s: [ERROR] Unknown addr: 0x%08lx\n", |
| 1089 | DRIVER_NAME, buf[i].addr); |
| 1090 | continue; |
| 1091 | } |
| 1092 | |
| 1093 | qla4_8xxx_wr_32(ha, off, buf[i].data); |
| 1094 | |
| 1095 | /* ISP requires much bigger delay to settle down, |
| 1096 | * else crb_window returns 0xffffffff |
| 1097 | */ |
| 1098 | if (off == QLA82XX_ROMUSB_GLB_SW_RESET) |
| 1099 | msleep(1000); |
| 1100 | |
| 1101 | /* ISP requires millisec delay between |
| 1102 | * successive CRB register updation |
| 1103 | */ |
| 1104 | msleep(1); |
| 1105 | } |
| 1106 | |
| 1107 | kfree(buf); |
| 1108 | |
| 1109 | /* Resetting the data and instruction cache */ |
| 1110 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_PEG_NET_D+0xec, 0x1e); |
| 1111 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_PEG_NET_D+0x4c, 8); |
| 1112 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_PEG_NET_I+0x4c, 8); |
| 1113 | |
| 1114 | /* Clear all protocol processing engines */ |
| 1115 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_PEG_NET_0+0x8, 0); |
| 1116 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_PEG_NET_0+0xc, 0); |
| 1117 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_PEG_NET_1+0x8, 0); |
| 1118 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_PEG_NET_1+0xc, 0); |
| 1119 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_PEG_NET_2+0x8, 0); |
| 1120 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_PEG_NET_2+0xc, 0); |
| 1121 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_PEG_NET_3+0x8, 0); |
| 1122 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_PEG_NET_3+0xc, 0); |
| 1123 | |
| 1124 | return 0; |
| 1125 | } |
| 1126 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1127 | static int |
| 1128 | qla4_8xxx_load_from_flash(struct scsi_qla_host *ha, uint32_t image_start) |
| 1129 | { |
| 1130 | int i; |
| 1131 | long size = 0; |
| 1132 | long flashaddr, memaddr; |
| 1133 | u64 data; |
| 1134 | u32 high, low; |
| 1135 | |
| 1136 | flashaddr = memaddr = ha->hw.flt_region_bootload; |
| 1137 | size = (image_start - flashaddr)/8; |
| 1138 | |
| 1139 | DEBUG2(printk("scsi%ld: %s: bootldr=0x%lx, fw_image=0x%x\n", |
| 1140 | ha->host_no, __func__, flashaddr, image_start)); |
| 1141 | |
| 1142 | for (i = 0; i < size; i++) { |
| 1143 | if ((qla4_8xxx_rom_fast_read(ha, flashaddr, (int *)&low)) || |
| 1144 | (qla4_8xxx_rom_fast_read(ha, flashaddr + 4, |
| 1145 | (int *)&high))) { |
| 1146 | return -1; |
| 1147 | } |
| 1148 | data = ((u64)high << 32) | low ; |
| 1149 | qla4_8xxx_pci_mem_write_2M(ha, memaddr, &data, 8); |
| 1150 | flashaddr += 8; |
| 1151 | memaddr += 8; |
| 1152 | |
| 1153 | if (i%0x1000 == 0) |
| 1154 | msleep(1); |
| 1155 | |
| 1156 | } |
| 1157 | |
| 1158 | udelay(100); |
| 1159 | |
| 1160 | read_lock(&ha->hw_lock); |
| 1161 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_PEG_NET_0 + 0x18, 0x1020); |
| 1162 | qla4_8xxx_wr_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET, 0x80001e); |
| 1163 | read_unlock(&ha->hw_lock); |
| 1164 | |
| 1165 | return 0; |
| 1166 | } |
| 1167 | |
| 1168 | static int qla4_8xxx_load_fw(struct scsi_qla_host *ha, uint32_t image_start) |
| 1169 | { |
| 1170 | u32 rst; |
| 1171 | |
| 1172 | qla4_8xxx_wr_32(ha, CRB_CMDPEG_STATE, 0); |
| 1173 | if (qla4_8xxx_pinit_from_rom(ha, 0) != QLA_SUCCESS) { |
| 1174 | printk(KERN_WARNING "%s: Error during CRB Initialization\n", |
| 1175 | __func__); |
| 1176 | return QLA_ERROR; |
| 1177 | } |
| 1178 | |
| 1179 | udelay(500); |
| 1180 | |
| 1181 | /* at this point, QM is in reset. This could be a problem if there are |
| 1182 | * incoming d* transition queue messages. QM/PCIE could wedge. |
| 1183 | * To get around this, QM is brought out of reset. |
| 1184 | */ |
| 1185 | |
| 1186 | rst = qla4_8xxx_rd_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET); |
| 1187 | /* unreset qm */ |
| 1188 | rst &= ~(1 << 28); |
| 1189 | qla4_8xxx_wr_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET, rst); |
| 1190 | |
| 1191 | if (qla4_8xxx_load_from_flash(ha, image_start)) { |
| 1192 | printk("%s: Error trying to load fw from flash!\n", __func__); |
| 1193 | return QLA_ERROR; |
| 1194 | } |
| 1195 | |
| 1196 | return QLA_SUCCESS; |
| 1197 | } |
| 1198 | |
| 1199 | int |
| 1200 | qla4_8xxx_pci_mem_read_2M(struct scsi_qla_host *ha, |
| 1201 | u64 off, void *data, int size) |
| 1202 | { |
| 1203 | int i, j = 0, k, start, end, loop, sz[2], off0[2]; |
| 1204 | int shift_amount; |
| 1205 | uint32_t temp; |
| 1206 | uint64_t off8, val, mem_crb, word[2] = {0, 0}; |
| 1207 | |
| 1208 | /* |
| 1209 | * If not MN, go check for MS or invalid. |
| 1210 | */ |
| 1211 | |
| 1212 | if (off >= QLA82XX_ADDR_QDR_NET && off <= QLA82XX_P3_ADDR_QDR_NET_MAX) |
| 1213 | mem_crb = QLA82XX_CRB_QDR_NET; |
| 1214 | else { |
| 1215 | mem_crb = QLA82XX_CRB_DDR_NET; |
| 1216 | if (qla4_8xxx_pci_mem_bound_check(ha, off, size) == 0) |
| 1217 | return qla4_8xxx_pci_mem_read_direct(ha, |
| 1218 | off, data, size); |
| 1219 | } |
| 1220 | |
| 1221 | |
| 1222 | off8 = off & 0xfffffff0; |
| 1223 | off0[0] = off & 0xf; |
| 1224 | sz[0] = (size < (16 - off0[0])) ? size : (16 - off0[0]); |
| 1225 | shift_amount = 4; |
| 1226 | |
| 1227 | loop = ((off0[0] + size - 1) >> shift_amount) + 1; |
| 1228 | off0[1] = 0; |
| 1229 | sz[1] = size - sz[0]; |
| 1230 | |
| 1231 | for (i = 0; i < loop; i++) { |
| 1232 | temp = off8 + (i << shift_amount); |
| 1233 | qla4_8xxx_wr_32(ha, mem_crb + MIU_TEST_AGT_ADDR_LO, temp); |
| 1234 | temp = 0; |
| 1235 | qla4_8xxx_wr_32(ha, mem_crb + MIU_TEST_AGT_ADDR_HI, temp); |
| 1236 | temp = MIU_TA_CTL_ENABLE; |
| 1237 | qla4_8xxx_wr_32(ha, mem_crb + MIU_TEST_AGT_CTRL, temp); |
| 1238 | temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE; |
| 1239 | qla4_8xxx_wr_32(ha, mem_crb + MIU_TEST_AGT_CTRL, temp); |
| 1240 | |
| 1241 | for (j = 0; j < MAX_CTL_CHECK; j++) { |
| 1242 | temp = qla4_8xxx_rd_32(ha, mem_crb + MIU_TEST_AGT_CTRL); |
| 1243 | if ((temp & MIU_TA_CTL_BUSY) == 0) |
| 1244 | break; |
| 1245 | } |
| 1246 | |
| 1247 | if (j >= MAX_CTL_CHECK) { |
| 1248 | if (printk_ratelimit()) |
| 1249 | ql4_printk(KERN_ERR, ha, |
| 1250 | "failed to read through agent\n"); |
| 1251 | break; |
| 1252 | } |
| 1253 | |
| 1254 | start = off0[i] >> 2; |
| 1255 | end = (off0[i] + sz[i] - 1) >> 2; |
| 1256 | for (k = start; k <= end; k++) { |
| 1257 | temp = qla4_8xxx_rd_32(ha, |
| 1258 | mem_crb + MIU_TEST_AGT_RDDATA(k)); |
| 1259 | word[i] |= ((uint64_t)temp << (32 * (k & 1))); |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | if (j >= MAX_CTL_CHECK) |
| 1264 | return -1; |
| 1265 | |
| 1266 | if ((off0[0] & 7) == 0) { |
| 1267 | val = word[0]; |
| 1268 | } else { |
| 1269 | val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) | |
| 1270 | ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8)); |
| 1271 | } |
| 1272 | |
| 1273 | switch (size) { |
| 1274 | case 1: |
| 1275 | *(uint8_t *)data = val; |
| 1276 | break; |
| 1277 | case 2: |
| 1278 | *(uint16_t *)data = val; |
| 1279 | break; |
| 1280 | case 4: |
| 1281 | *(uint32_t *)data = val; |
| 1282 | break; |
| 1283 | case 8: |
| 1284 | *(uint64_t *)data = val; |
| 1285 | break; |
| 1286 | } |
| 1287 | return 0; |
| 1288 | } |
| 1289 | |
| 1290 | int |
| 1291 | qla4_8xxx_pci_mem_write_2M(struct scsi_qla_host *ha, |
| 1292 | u64 off, void *data, int size) |
| 1293 | { |
| 1294 | int i, j, ret = 0, loop, sz[2], off0; |
| 1295 | int scale, shift_amount, startword; |
| 1296 | uint32_t temp; |
| 1297 | uint64_t off8, mem_crb, tmpw, word[2] = {0, 0}; |
| 1298 | |
| 1299 | /* |
| 1300 | * If not MN, go check for MS or invalid. |
| 1301 | */ |
| 1302 | if (off >= QLA82XX_ADDR_QDR_NET && off <= QLA82XX_P3_ADDR_QDR_NET_MAX) |
| 1303 | mem_crb = QLA82XX_CRB_QDR_NET; |
| 1304 | else { |
| 1305 | mem_crb = QLA82XX_CRB_DDR_NET; |
| 1306 | if (qla4_8xxx_pci_mem_bound_check(ha, off, size) == 0) |
| 1307 | return qla4_8xxx_pci_mem_write_direct(ha, |
| 1308 | off, data, size); |
| 1309 | } |
| 1310 | |
| 1311 | off0 = off & 0x7; |
| 1312 | sz[0] = (size < (8 - off0)) ? size : (8 - off0); |
| 1313 | sz[1] = size - sz[0]; |
| 1314 | |
| 1315 | off8 = off & 0xfffffff0; |
| 1316 | loop = (((off & 0xf) + size - 1) >> 4) + 1; |
| 1317 | shift_amount = 4; |
| 1318 | scale = 2; |
| 1319 | startword = (off & 0xf)/8; |
| 1320 | |
| 1321 | for (i = 0; i < loop; i++) { |
| 1322 | if (qla4_8xxx_pci_mem_read_2M(ha, off8 + |
| 1323 | (i << shift_amount), &word[i * scale], 8)) |
| 1324 | return -1; |
| 1325 | } |
| 1326 | |
| 1327 | switch (size) { |
| 1328 | case 1: |
| 1329 | tmpw = *((uint8_t *)data); |
| 1330 | break; |
| 1331 | case 2: |
| 1332 | tmpw = *((uint16_t *)data); |
| 1333 | break; |
| 1334 | case 4: |
| 1335 | tmpw = *((uint32_t *)data); |
| 1336 | break; |
| 1337 | case 8: |
| 1338 | default: |
| 1339 | tmpw = *((uint64_t *)data); |
| 1340 | break; |
| 1341 | } |
| 1342 | |
| 1343 | if (sz[0] == 8) |
| 1344 | word[startword] = tmpw; |
| 1345 | else { |
| 1346 | word[startword] &= |
| 1347 | ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8)); |
| 1348 | word[startword] |= tmpw << (off0 * 8); |
| 1349 | } |
| 1350 | |
| 1351 | if (sz[1] != 0) { |
| 1352 | word[startword+1] &= ~(~0ULL << (sz[1] * 8)); |
| 1353 | word[startword+1] |= tmpw >> (sz[0] * 8); |
| 1354 | } |
| 1355 | |
| 1356 | for (i = 0; i < loop; i++) { |
| 1357 | temp = off8 + (i << shift_amount); |
| 1358 | qla4_8xxx_wr_32(ha, mem_crb+MIU_TEST_AGT_ADDR_LO, temp); |
| 1359 | temp = 0; |
| 1360 | qla4_8xxx_wr_32(ha, mem_crb+MIU_TEST_AGT_ADDR_HI, temp); |
| 1361 | temp = word[i * scale] & 0xffffffff; |
| 1362 | qla4_8xxx_wr_32(ha, mem_crb+MIU_TEST_AGT_WRDATA_LO, temp); |
| 1363 | temp = (word[i * scale] >> 32) & 0xffffffff; |
| 1364 | qla4_8xxx_wr_32(ha, mem_crb+MIU_TEST_AGT_WRDATA_HI, temp); |
| 1365 | temp = word[i*scale + 1] & 0xffffffff; |
| 1366 | qla4_8xxx_wr_32(ha, mem_crb + MIU_TEST_AGT_WRDATA_UPPER_LO, |
| 1367 | temp); |
| 1368 | temp = (word[i*scale + 1] >> 32) & 0xffffffff; |
| 1369 | qla4_8xxx_wr_32(ha, mem_crb + MIU_TEST_AGT_WRDATA_UPPER_HI, |
| 1370 | temp); |
| 1371 | |
| 1372 | temp = MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE; |
| 1373 | qla4_8xxx_wr_32(ha, mem_crb+MIU_TEST_AGT_CTRL, temp); |
| 1374 | temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE; |
| 1375 | qla4_8xxx_wr_32(ha, mem_crb+MIU_TEST_AGT_CTRL, temp); |
| 1376 | |
| 1377 | for (j = 0; j < MAX_CTL_CHECK; j++) { |
| 1378 | temp = qla4_8xxx_rd_32(ha, mem_crb + MIU_TEST_AGT_CTRL); |
| 1379 | if ((temp & MIU_TA_CTL_BUSY) == 0) |
| 1380 | break; |
| 1381 | } |
| 1382 | |
| 1383 | if (j >= MAX_CTL_CHECK) { |
| 1384 | if (printk_ratelimit()) |
| 1385 | ql4_printk(KERN_ERR, ha, |
| 1386 | "failed to write through agent\n"); |
| 1387 | ret = -1; |
| 1388 | break; |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | return ret; |
| 1393 | } |
| 1394 | |
| 1395 | static int qla4_8xxx_cmdpeg_ready(struct scsi_qla_host *ha, int pegtune_val) |
| 1396 | { |
| 1397 | u32 val = 0; |
| 1398 | int retries = 60; |
| 1399 | |
| 1400 | if (!pegtune_val) { |
| 1401 | do { |
| 1402 | val = qla4_8xxx_rd_32(ha, CRB_CMDPEG_STATE); |
| 1403 | if ((val == PHAN_INITIALIZE_COMPLETE) || |
| 1404 | (val == PHAN_INITIALIZE_ACK)) |
| 1405 | return 0; |
| 1406 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 1407 | schedule_timeout(500); |
| 1408 | |
| 1409 | } while (--retries); |
| 1410 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1411 | if (!retries) { |
| 1412 | pegtune_val = qla4_8xxx_rd_32(ha, |
| 1413 | QLA82XX_ROMUSB_GLB_PEGTUNE_DONE); |
| 1414 | printk(KERN_WARNING "%s: init failed, " |
| 1415 | "pegtune_val = %x\n", __func__, pegtune_val); |
| 1416 | return -1; |
| 1417 | } |
| 1418 | } |
| 1419 | return 0; |
| 1420 | } |
| 1421 | |
| 1422 | static int qla4_8xxx_rcvpeg_ready(struct scsi_qla_host *ha) |
| 1423 | { |
| 1424 | uint32_t state = 0; |
| 1425 | int loops = 0; |
| 1426 | |
| 1427 | /* Window 1 call */ |
| 1428 | read_lock(&ha->hw_lock); |
| 1429 | state = qla4_8xxx_rd_32(ha, CRB_RCVPEG_STATE); |
| 1430 | read_unlock(&ha->hw_lock); |
| 1431 | |
| 1432 | while ((state != PHAN_PEG_RCV_INITIALIZED) && (loops < 30000)) { |
| 1433 | udelay(100); |
| 1434 | /* Window 1 call */ |
| 1435 | read_lock(&ha->hw_lock); |
| 1436 | state = qla4_8xxx_rd_32(ha, CRB_RCVPEG_STATE); |
| 1437 | read_unlock(&ha->hw_lock); |
| 1438 | |
| 1439 | loops++; |
| 1440 | } |
| 1441 | |
| 1442 | if (loops >= 30000) { |
| 1443 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1444 | "Receive Peg initialization not complete: 0x%x.\n", state)); |
| 1445 | return QLA_ERROR; |
| 1446 | } |
| 1447 | |
| 1448 | return QLA_SUCCESS; |
| 1449 | } |
| 1450 | |
Andrew Morton | 626115c | 2010-08-19 14:13:42 -0700 | [diff] [blame] | 1451 | void |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1452 | qla4_8xxx_set_drv_active(struct scsi_qla_host *ha) |
| 1453 | { |
| 1454 | uint32_t drv_active; |
| 1455 | |
| 1456 | drv_active = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE); |
| 1457 | drv_active |= (1 << (ha->func_num * 4)); |
| 1458 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_ACTIVE, drv_active); |
| 1459 | } |
| 1460 | |
| 1461 | void |
| 1462 | qla4_8xxx_clear_drv_active(struct scsi_qla_host *ha) |
| 1463 | { |
| 1464 | uint32_t drv_active; |
| 1465 | |
| 1466 | drv_active = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE); |
| 1467 | drv_active &= ~(1 << (ha->func_num * 4)); |
| 1468 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_ACTIVE, drv_active); |
| 1469 | } |
| 1470 | |
| 1471 | static inline int |
| 1472 | qla4_8xxx_need_reset(struct scsi_qla_host *ha) |
| 1473 | { |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 1474 | uint32_t drv_state, drv_active; |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1475 | int rval; |
| 1476 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 1477 | drv_active = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1478 | drv_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DRV_STATE); |
| 1479 | rval = drv_state & (1 << (ha->func_num * 4)); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 1480 | if ((test_bit(AF_EEH_BUSY, &ha->flags)) && drv_active) |
| 1481 | rval = 1; |
| 1482 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1483 | return rval; |
| 1484 | } |
| 1485 | |
| 1486 | static inline void |
| 1487 | qla4_8xxx_set_rst_ready(struct scsi_qla_host *ha) |
| 1488 | { |
| 1489 | uint32_t drv_state; |
| 1490 | |
| 1491 | drv_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DRV_STATE); |
| 1492 | drv_state |= (1 << (ha->func_num * 4)); |
| 1493 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, drv_state); |
| 1494 | } |
| 1495 | |
| 1496 | static inline void |
| 1497 | qla4_8xxx_clear_rst_ready(struct scsi_qla_host *ha) |
| 1498 | { |
| 1499 | uint32_t drv_state; |
| 1500 | |
| 1501 | drv_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DRV_STATE); |
| 1502 | drv_state &= ~(1 << (ha->func_num * 4)); |
| 1503 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, drv_state); |
| 1504 | } |
| 1505 | |
| 1506 | static inline void |
| 1507 | qla4_8xxx_set_qsnt_ready(struct scsi_qla_host *ha) |
| 1508 | { |
| 1509 | uint32_t qsnt_state; |
| 1510 | |
| 1511 | qsnt_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DRV_STATE); |
| 1512 | qsnt_state |= (2 << (ha->func_num * 4)); |
| 1513 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, qsnt_state); |
| 1514 | } |
| 1515 | |
| 1516 | |
| 1517 | static int |
| 1518 | qla4_8xxx_start_firmware(struct scsi_qla_host *ha, uint32_t image_start) |
| 1519 | { |
| 1520 | int pcie_cap; |
| 1521 | uint16_t lnk; |
| 1522 | |
| 1523 | /* scrub dma mask expansion register */ |
| 1524 | qla4_8xxx_wr_32(ha, CRB_DMA_SHIFT, 0x55555555); |
| 1525 | |
| 1526 | /* Overwrite stale initialization register values */ |
| 1527 | qla4_8xxx_wr_32(ha, CRB_CMDPEG_STATE, 0); |
| 1528 | qla4_8xxx_wr_32(ha, CRB_RCVPEG_STATE, 0); |
| 1529 | qla4_8xxx_wr_32(ha, QLA82XX_PEG_HALT_STATUS1, 0); |
| 1530 | qla4_8xxx_wr_32(ha, QLA82XX_PEG_HALT_STATUS2, 0); |
| 1531 | |
| 1532 | if (qla4_8xxx_load_fw(ha, image_start) != QLA_SUCCESS) { |
| 1533 | printk("%s: Error trying to start fw!\n", __func__); |
| 1534 | return QLA_ERROR; |
| 1535 | } |
| 1536 | |
| 1537 | /* Handshake with the card before we register the devices. */ |
| 1538 | if (qla4_8xxx_cmdpeg_ready(ha, 0) != QLA_SUCCESS) { |
| 1539 | printk("%s: Error during card handshake!\n", __func__); |
| 1540 | return QLA_ERROR; |
| 1541 | } |
| 1542 | |
| 1543 | /* Negotiated Link width */ |
| 1544 | pcie_cap = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP); |
| 1545 | pci_read_config_word(ha->pdev, pcie_cap + PCI_EXP_LNKSTA, &lnk); |
| 1546 | ha->link_width = (lnk >> 4) & 0x3f; |
| 1547 | |
| 1548 | /* Synchronize with Receive peg */ |
| 1549 | return qla4_8xxx_rcvpeg_ready(ha); |
| 1550 | } |
| 1551 | |
| 1552 | static int |
| 1553 | qla4_8xxx_try_start_fw(struct scsi_qla_host *ha) |
| 1554 | { |
| 1555 | int rval = QLA_ERROR; |
| 1556 | |
| 1557 | /* |
| 1558 | * FW Load priority: |
| 1559 | * 1) Operational firmware residing in flash. |
| 1560 | * 2) Fail |
| 1561 | */ |
| 1562 | |
| 1563 | ql4_printk(KERN_INFO, ha, |
| 1564 | "FW: Retrieving flash offsets from FLT/FDT ...\n"); |
| 1565 | rval = qla4_8xxx_get_flash_info(ha); |
| 1566 | if (rval != QLA_SUCCESS) |
| 1567 | return rval; |
| 1568 | |
| 1569 | ql4_printk(KERN_INFO, ha, |
| 1570 | "FW: Attempting to load firmware from flash...\n"); |
| 1571 | rval = qla4_8xxx_start_firmware(ha, ha->hw.flt_region_fw); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1572 | |
Vikas Chaudhary | f581a3f | 2010-10-06 22:47:48 -0700 | [diff] [blame] | 1573 | if (rval != QLA_SUCCESS) { |
| 1574 | ql4_printk(KERN_ERR, ha, "FW: Load firmware from flash" |
| 1575 | " FAILED...\n"); |
| 1576 | return rval; |
| 1577 | } |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1578 | |
| 1579 | return rval; |
| 1580 | } |
| 1581 | |
Shyam Sundar | b25ee66 | 2010-10-06 22:50:51 -0700 | [diff] [blame] | 1582 | static void qla4_8xxx_rom_lock_recovery(struct scsi_qla_host *ha) |
| 1583 | { |
| 1584 | if (qla4_8xxx_rom_lock(ha)) { |
| 1585 | /* Someone else is holding the lock. */ |
| 1586 | dev_info(&ha->pdev->dev, "Resetting rom_lock\n"); |
| 1587 | } |
| 1588 | |
| 1589 | /* |
| 1590 | * Either we got the lock, or someone |
| 1591 | * else died while holding it. |
| 1592 | * In either case, unlock. |
| 1593 | */ |
| 1594 | qla4_8xxx_rom_unlock(ha); |
| 1595 | } |
| 1596 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1597 | /** |
| 1598 | * qla4_8xxx_device_bootstrap - Initialize device, set DEV_READY, start fw |
| 1599 | * @ha: pointer to adapter structure |
| 1600 | * |
| 1601 | * Note: IDC lock must be held upon entry |
| 1602 | **/ |
| 1603 | static int |
| 1604 | qla4_8xxx_device_bootstrap(struct scsi_qla_host *ha) |
| 1605 | { |
Shyam Sundar | b25ee66 | 2010-10-06 22:50:51 -0700 | [diff] [blame] | 1606 | int rval = QLA_ERROR; |
| 1607 | int i, timeout; |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1608 | uint32_t old_count, count; |
Shyam Sundar | b25ee66 | 2010-10-06 22:50:51 -0700 | [diff] [blame] | 1609 | int need_reset = 0, peg_stuck = 1; |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1610 | |
Shyam Sundar | b25ee66 | 2010-10-06 22:50:51 -0700 | [diff] [blame] | 1611 | need_reset = qla4_8xxx_need_reset(ha); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1612 | |
| 1613 | old_count = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER); |
| 1614 | |
| 1615 | for (i = 0; i < 10; i++) { |
| 1616 | timeout = msleep_interruptible(200); |
| 1617 | if (timeout) { |
| 1618 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 1619 | QLA82XX_DEV_FAILED); |
Shyam Sundar | b25ee66 | 2010-10-06 22:50:51 -0700 | [diff] [blame] | 1620 | return rval; |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | count = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER); |
| 1624 | if (count != old_count) |
Shyam Sundar | b25ee66 | 2010-10-06 22:50:51 -0700 | [diff] [blame] | 1625 | peg_stuck = 0; |
| 1626 | } |
| 1627 | |
| 1628 | if (need_reset) { |
| 1629 | /* We are trying to perform a recovery here. */ |
| 1630 | if (peg_stuck) |
| 1631 | qla4_8xxx_rom_lock_recovery(ha); |
| 1632 | goto dev_initialize; |
| 1633 | } else { |
| 1634 | /* Start of day for this ha context. */ |
| 1635 | if (peg_stuck) { |
| 1636 | /* Either we are the first or recovery in progress. */ |
| 1637 | qla4_8xxx_rom_lock_recovery(ha); |
| 1638 | goto dev_initialize; |
| 1639 | } else { |
| 1640 | /* Firmware already running. */ |
| 1641 | rval = QLA_SUCCESS; |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1642 | goto dev_ready; |
Shyam Sundar | b25ee66 | 2010-10-06 22:50:51 -0700 | [diff] [blame] | 1643 | } |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | dev_initialize: |
| 1647 | /* set to DEV_INITIALIZING */ |
| 1648 | ql4_printk(KERN_INFO, ha, "HW State: INITIALIZING\n"); |
| 1649 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, QLA82XX_DEV_INITIALIZING); |
| 1650 | |
| 1651 | /* Driver that sets device state to initializating sets IDC version */ |
| 1652 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION, QLA82XX_IDC_VERSION); |
| 1653 | |
| 1654 | qla4_8xxx_idc_unlock(ha); |
| 1655 | rval = qla4_8xxx_try_start_fw(ha); |
| 1656 | qla4_8xxx_idc_lock(ha); |
| 1657 | |
| 1658 | if (rval != QLA_SUCCESS) { |
| 1659 | ql4_printk(KERN_INFO, ha, "HW State: FAILED\n"); |
| 1660 | qla4_8xxx_clear_drv_active(ha); |
| 1661 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, QLA82XX_DEV_FAILED); |
| 1662 | return rval; |
| 1663 | } |
| 1664 | |
| 1665 | dev_ready: |
| 1666 | ql4_printk(KERN_INFO, ha, "HW State: READY\n"); |
| 1667 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, QLA82XX_DEV_READY); |
| 1668 | |
Shyam Sundar | b25ee66 | 2010-10-06 22:50:51 -0700 | [diff] [blame] | 1669 | return rval; |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | /** |
| 1673 | * qla4_8xxx_need_reset_handler - Code to start reset sequence |
| 1674 | * @ha: pointer to adapter structure |
| 1675 | * |
| 1676 | * Note: IDC lock must be held upon entry |
| 1677 | **/ |
| 1678 | static void |
| 1679 | qla4_8xxx_need_reset_handler(struct scsi_qla_host *ha) |
| 1680 | { |
| 1681 | uint32_t dev_state, drv_state, drv_active; |
| 1682 | unsigned long reset_timeout; |
| 1683 | |
| 1684 | ql4_printk(KERN_INFO, ha, |
| 1685 | "Performing ISP error recovery\n"); |
| 1686 | |
| 1687 | if (test_and_clear_bit(AF_ONLINE, &ha->flags)) { |
| 1688 | qla4_8xxx_idc_unlock(ha); |
| 1689 | ha->isp_ops->disable_intrs(ha); |
| 1690 | qla4_8xxx_idc_lock(ha); |
| 1691 | } |
| 1692 | |
| 1693 | qla4_8xxx_set_rst_ready(ha); |
| 1694 | |
| 1695 | /* wait for 10 seconds for reset ack from all functions */ |
| 1696 | reset_timeout = jiffies + (ha->nx_reset_timeout * HZ); |
| 1697 | |
| 1698 | drv_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DRV_STATE); |
| 1699 | drv_active = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE); |
| 1700 | |
| 1701 | ql4_printk(KERN_INFO, ha, |
| 1702 | "%s(%ld): drv_state = 0x%x, drv_active = 0x%x\n", |
| 1703 | __func__, ha->host_no, drv_state, drv_active); |
| 1704 | |
| 1705 | while (drv_state != drv_active) { |
| 1706 | if (time_after_eq(jiffies, reset_timeout)) { |
| 1707 | printk("%s: RESET TIMEOUT!\n", DRIVER_NAME); |
| 1708 | break; |
| 1709 | } |
| 1710 | |
| 1711 | qla4_8xxx_idc_unlock(ha); |
| 1712 | msleep(1000); |
| 1713 | qla4_8xxx_idc_lock(ha); |
| 1714 | |
| 1715 | drv_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DRV_STATE); |
| 1716 | drv_active = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE); |
| 1717 | } |
| 1718 | |
| 1719 | dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE); |
| 1720 | ql4_printk(KERN_INFO, ha, "3:Device state is 0x%x = %s\n", dev_state, |
| 1721 | dev_state < MAX_STATES ? qdev_state[dev_state] : "Unknown"); |
| 1722 | |
| 1723 | /* Force to DEV_COLD unless someone else is starting a reset */ |
| 1724 | if (dev_state != QLA82XX_DEV_INITIALIZING) { |
| 1725 | ql4_printk(KERN_INFO, ha, "HW State: COLD/RE-INIT\n"); |
| 1726 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, QLA82XX_DEV_COLD); |
| 1727 | } |
| 1728 | } |
| 1729 | |
| 1730 | /** |
| 1731 | * qla4_8xxx_need_qsnt_handler - Code to start qsnt |
| 1732 | * @ha: pointer to adapter structure |
| 1733 | **/ |
| 1734 | void |
| 1735 | qla4_8xxx_need_qsnt_handler(struct scsi_qla_host *ha) |
| 1736 | { |
| 1737 | qla4_8xxx_idc_lock(ha); |
| 1738 | qla4_8xxx_set_qsnt_ready(ha); |
| 1739 | qla4_8xxx_idc_unlock(ha); |
| 1740 | } |
| 1741 | |
| 1742 | /** |
| 1743 | * qla4_8xxx_device_state_handler - Adapter state machine |
| 1744 | * @ha: pointer to host adapter structure. |
| 1745 | * |
| 1746 | * Note: IDC lock must be UNLOCKED upon entry |
| 1747 | **/ |
| 1748 | int qla4_8xxx_device_state_handler(struct scsi_qla_host *ha) |
| 1749 | { |
| 1750 | uint32_t dev_state; |
| 1751 | int rval = QLA_SUCCESS; |
| 1752 | unsigned long dev_init_timeout; |
| 1753 | |
| 1754 | if (!test_bit(AF_INIT_DONE, &ha->flags)) |
| 1755 | qla4_8xxx_set_drv_active(ha); |
| 1756 | |
| 1757 | dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE); |
| 1758 | ql4_printk(KERN_INFO, ha, "1:Device state is 0x%x = %s\n", dev_state, |
| 1759 | dev_state < MAX_STATES ? qdev_state[dev_state] : "Unknown"); |
| 1760 | |
| 1761 | /* wait for 30 seconds for device to go ready */ |
| 1762 | dev_init_timeout = jiffies + (ha->nx_dev_init_timeout * HZ); |
| 1763 | |
| 1764 | while (1) { |
| 1765 | qla4_8xxx_idc_lock(ha); |
| 1766 | |
| 1767 | if (time_after_eq(jiffies, dev_init_timeout)) { |
| 1768 | ql4_printk(KERN_WARNING, ha, "Device init failed!\n"); |
| 1769 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 1770 | QLA82XX_DEV_FAILED); |
| 1771 | } |
| 1772 | |
| 1773 | dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE); |
| 1774 | ql4_printk(KERN_INFO, ha, |
| 1775 | "2:Device state is 0x%x = %s\n", dev_state, |
| 1776 | dev_state < MAX_STATES ? qdev_state[dev_state] : "Unknown"); |
| 1777 | |
| 1778 | /* NOTE: Make sure idc unlocked upon exit of switch statement */ |
| 1779 | switch (dev_state) { |
| 1780 | case QLA82XX_DEV_READY: |
| 1781 | qla4_8xxx_idc_unlock(ha); |
| 1782 | goto exit; |
| 1783 | case QLA82XX_DEV_COLD: |
| 1784 | rval = qla4_8xxx_device_bootstrap(ha); |
| 1785 | qla4_8xxx_idc_unlock(ha); |
| 1786 | goto exit; |
| 1787 | case QLA82XX_DEV_INITIALIZING: |
| 1788 | qla4_8xxx_idc_unlock(ha); |
| 1789 | msleep(1000); |
| 1790 | break; |
| 1791 | case QLA82XX_DEV_NEED_RESET: |
| 1792 | if (!ql4xdontresethba) { |
| 1793 | qla4_8xxx_need_reset_handler(ha); |
| 1794 | /* Update timeout value after need |
| 1795 | * reset handler */ |
| 1796 | dev_init_timeout = jiffies + |
| 1797 | (ha->nx_dev_init_timeout * HZ); |
| 1798 | } |
| 1799 | qla4_8xxx_idc_unlock(ha); |
| 1800 | break; |
| 1801 | case QLA82XX_DEV_NEED_QUIESCENT: |
| 1802 | qla4_8xxx_idc_unlock(ha); |
| 1803 | /* idc locked/unlocked in handler */ |
| 1804 | qla4_8xxx_need_qsnt_handler(ha); |
| 1805 | qla4_8xxx_idc_lock(ha); |
| 1806 | /* fall thru needs idc_locked */ |
| 1807 | case QLA82XX_DEV_QUIESCENT: |
| 1808 | qla4_8xxx_idc_unlock(ha); |
| 1809 | msleep(1000); |
| 1810 | break; |
| 1811 | case QLA82XX_DEV_FAILED: |
| 1812 | qla4_8xxx_idc_unlock(ha); |
| 1813 | qla4xxx_dead_adapter_cleanup(ha); |
| 1814 | rval = QLA_ERROR; |
| 1815 | goto exit; |
| 1816 | default: |
| 1817 | qla4_8xxx_idc_unlock(ha); |
| 1818 | qla4xxx_dead_adapter_cleanup(ha); |
| 1819 | rval = QLA_ERROR; |
| 1820 | goto exit; |
| 1821 | } |
| 1822 | } |
| 1823 | exit: |
| 1824 | return rval; |
| 1825 | } |
| 1826 | |
| 1827 | int qla4_8xxx_load_risc(struct scsi_qla_host *ha) |
| 1828 | { |
| 1829 | int retval; |
| 1830 | retval = qla4_8xxx_device_state_handler(ha); |
| 1831 | |
Vikas Chaudhary | f581a3f | 2010-10-06 22:47:48 -0700 | [diff] [blame] | 1832 | if (retval == QLA_SUCCESS && !test_bit(AF_INIT_DONE, &ha->flags)) |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1833 | retval = qla4xxx_request_irqs(ha); |
Vikas Chaudhary | f581a3f | 2010-10-06 22:47:48 -0700 | [diff] [blame] | 1834 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1835 | return retval; |
| 1836 | } |
| 1837 | |
| 1838 | /*****************************************************************************/ |
| 1839 | /* Flash Manipulation Routines */ |
| 1840 | /*****************************************************************************/ |
| 1841 | |
| 1842 | #define OPTROM_BURST_SIZE 0x1000 |
| 1843 | #define OPTROM_BURST_DWORDS (OPTROM_BURST_SIZE / 4) |
| 1844 | |
| 1845 | #define FARX_DATA_FLAG BIT_31 |
| 1846 | #define FARX_ACCESS_FLASH_CONF 0x7FFD0000 |
| 1847 | #define FARX_ACCESS_FLASH_DATA 0x7FF00000 |
| 1848 | |
| 1849 | static inline uint32_t |
| 1850 | flash_conf_addr(struct ql82xx_hw_data *hw, uint32_t faddr) |
| 1851 | { |
| 1852 | return hw->flash_conf_off | faddr; |
| 1853 | } |
| 1854 | |
| 1855 | static inline uint32_t |
| 1856 | flash_data_addr(struct ql82xx_hw_data *hw, uint32_t faddr) |
| 1857 | { |
| 1858 | return hw->flash_data_off | faddr; |
| 1859 | } |
| 1860 | |
| 1861 | static uint32_t * |
| 1862 | qla4_8xxx_read_flash_data(struct scsi_qla_host *ha, uint32_t *dwptr, |
| 1863 | uint32_t faddr, uint32_t length) |
| 1864 | { |
| 1865 | uint32_t i; |
| 1866 | uint32_t val; |
| 1867 | int loops = 0; |
| 1868 | while ((qla4_8xxx_rom_lock(ha) != 0) && (loops < 50000)) { |
| 1869 | udelay(100); |
| 1870 | cond_resched(); |
| 1871 | loops++; |
| 1872 | } |
| 1873 | if (loops >= 50000) { |
| 1874 | ql4_printk(KERN_WARNING, ha, "ROM lock failed\n"); |
| 1875 | return dwptr; |
| 1876 | } |
| 1877 | |
| 1878 | /* Dword reads to flash. */ |
| 1879 | for (i = 0; i < length/4; i++, faddr += 4) { |
| 1880 | if (qla4_8xxx_do_rom_fast_read(ha, faddr, &val)) { |
| 1881 | ql4_printk(KERN_WARNING, ha, |
| 1882 | "Do ROM fast read failed\n"); |
| 1883 | goto done_read; |
| 1884 | } |
| 1885 | dwptr[i] = __constant_cpu_to_le32(val); |
| 1886 | } |
| 1887 | |
| 1888 | done_read: |
| 1889 | qla4_8xxx_rom_unlock(ha); |
| 1890 | return dwptr; |
| 1891 | } |
| 1892 | |
| 1893 | /** |
| 1894 | * Address and length are byte address |
| 1895 | **/ |
| 1896 | static uint8_t * |
| 1897 | qla4_8xxx_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf, |
| 1898 | uint32_t offset, uint32_t length) |
| 1899 | { |
| 1900 | qla4_8xxx_read_flash_data(ha, (uint32_t *)buf, offset, length); |
| 1901 | return buf; |
| 1902 | } |
| 1903 | |
| 1904 | static int |
| 1905 | qla4_8xxx_find_flt_start(struct scsi_qla_host *ha, uint32_t *start) |
| 1906 | { |
| 1907 | const char *loc, *locations[] = { "DEF", "PCI" }; |
| 1908 | |
| 1909 | /* |
| 1910 | * FLT-location structure resides after the last PCI region. |
| 1911 | */ |
| 1912 | |
| 1913 | /* Begin with sane defaults. */ |
| 1914 | loc = locations[0]; |
| 1915 | *start = FA_FLASH_LAYOUT_ADDR_82; |
| 1916 | |
| 1917 | DEBUG2(ql4_printk(KERN_INFO, ha, "FLTL[%s] = 0x%x.\n", loc, *start)); |
| 1918 | return QLA_SUCCESS; |
| 1919 | } |
| 1920 | |
| 1921 | static void |
| 1922 | qla4_8xxx_get_flt_info(struct scsi_qla_host *ha, uint32_t flt_addr) |
| 1923 | { |
| 1924 | const char *loc, *locations[] = { "DEF", "FLT" }; |
| 1925 | uint16_t *wptr; |
| 1926 | uint16_t cnt, chksum; |
| 1927 | uint32_t start; |
| 1928 | struct qla_flt_header *flt; |
| 1929 | struct qla_flt_region *region; |
| 1930 | struct ql82xx_hw_data *hw = &ha->hw; |
| 1931 | |
| 1932 | hw->flt_region_flt = flt_addr; |
| 1933 | wptr = (uint16_t *)ha->request_ring; |
| 1934 | flt = (struct qla_flt_header *)ha->request_ring; |
| 1935 | region = (struct qla_flt_region *)&flt[1]; |
| 1936 | qla4_8xxx_read_optrom_data(ha, (uint8_t *)ha->request_ring, |
| 1937 | flt_addr << 2, OPTROM_BURST_SIZE); |
| 1938 | if (*wptr == __constant_cpu_to_le16(0xffff)) |
| 1939 | goto no_flash_data; |
| 1940 | if (flt->version != __constant_cpu_to_le16(1)) { |
| 1941 | DEBUG2(ql4_printk(KERN_INFO, ha, "Unsupported FLT detected: " |
| 1942 | "version=0x%x length=0x%x checksum=0x%x.\n", |
| 1943 | le16_to_cpu(flt->version), le16_to_cpu(flt->length), |
| 1944 | le16_to_cpu(flt->checksum))); |
| 1945 | goto no_flash_data; |
| 1946 | } |
| 1947 | |
| 1948 | cnt = (sizeof(struct qla_flt_header) + le16_to_cpu(flt->length)) >> 1; |
| 1949 | for (chksum = 0; cnt; cnt--) |
| 1950 | chksum += le16_to_cpu(*wptr++); |
| 1951 | if (chksum) { |
| 1952 | DEBUG2(ql4_printk(KERN_INFO, ha, "Inconsistent FLT detected: " |
| 1953 | "version=0x%x length=0x%x checksum=0x%x.\n", |
| 1954 | le16_to_cpu(flt->version), le16_to_cpu(flt->length), |
| 1955 | chksum)); |
| 1956 | goto no_flash_data; |
| 1957 | } |
| 1958 | |
| 1959 | loc = locations[1]; |
| 1960 | cnt = le16_to_cpu(flt->length) / sizeof(struct qla_flt_region); |
| 1961 | for ( ; cnt; cnt--, region++) { |
| 1962 | /* Store addresses as DWORD offsets. */ |
| 1963 | start = le32_to_cpu(region->start) >> 2; |
| 1964 | |
| 1965 | DEBUG3(ql4_printk(KERN_DEBUG, ha, "FLT[%02x]: start=0x%x " |
| 1966 | "end=0x%x size=0x%x.\n", le32_to_cpu(region->code), start, |
| 1967 | le32_to_cpu(region->end) >> 2, le32_to_cpu(region->size))); |
| 1968 | |
| 1969 | switch (le32_to_cpu(region->code) & 0xff) { |
| 1970 | case FLT_REG_FDT: |
| 1971 | hw->flt_region_fdt = start; |
| 1972 | break; |
| 1973 | case FLT_REG_BOOT_CODE_82: |
| 1974 | hw->flt_region_boot = start; |
| 1975 | break; |
| 1976 | case FLT_REG_FW_82: |
| 1977 | hw->flt_region_fw = start; |
| 1978 | break; |
| 1979 | case FLT_REG_BOOTLOAD_82: |
| 1980 | hw->flt_region_bootload = start; |
| 1981 | break; |
| 1982 | } |
| 1983 | } |
| 1984 | goto done; |
| 1985 | |
| 1986 | no_flash_data: |
| 1987 | /* Use hardcoded defaults. */ |
| 1988 | loc = locations[0]; |
| 1989 | |
| 1990 | hw->flt_region_fdt = FA_FLASH_DESCR_ADDR_82; |
| 1991 | hw->flt_region_boot = FA_BOOT_CODE_ADDR_82; |
| 1992 | hw->flt_region_bootload = FA_BOOT_LOAD_ADDR_82; |
| 1993 | hw->flt_region_fw = FA_RISC_CODE_ADDR_82; |
| 1994 | done: |
| 1995 | DEBUG2(ql4_printk(KERN_INFO, ha, "FLT[%s]: flt=0x%x fdt=0x%x " |
| 1996 | "boot=0x%x bootload=0x%x fw=0x%x\n", loc, hw->flt_region_flt, |
| 1997 | hw->flt_region_fdt, hw->flt_region_boot, hw->flt_region_bootload, |
| 1998 | hw->flt_region_fw)); |
| 1999 | } |
| 2000 | |
| 2001 | static void |
| 2002 | qla4_8xxx_get_fdt_info(struct scsi_qla_host *ha) |
| 2003 | { |
| 2004 | #define FLASH_BLK_SIZE_4K 0x1000 |
| 2005 | #define FLASH_BLK_SIZE_32K 0x8000 |
| 2006 | #define FLASH_BLK_SIZE_64K 0x10000 |
| 2007 | const char *loc, *locations[] = { "MID", "FDT" }; |
| 2008 | uint16_t cnt, chksum; |
| 2009 | uint16_t *wptr; |
| 2010 | struct qla_fdt_layout *fdt; |
Vikas Chaudhary | 3c3e210 | 2010-08-09 05:14:07 -0700 | [diff] [blame] | 2011 | uint16_t mid = 0; |
| 2012 | uint16_t fid = 0; |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2013 | struct ql82xx_hw_data *hw = &ha->hw; |
| 2014 | |
| 2015 | hw->flash_conf_off = FARX_ACCESS_FLASH_CONF; |
| 2016 | hw->flash_data_off = FARX_ACCESS_FLASH_DATA; |
| 2017 | |
| 2018 | wptr = (uint16_t *)ha->request_ring; |
| 2019 | fdt = (struct qla_fdt_layout *)ha->request_ring; |
| 2020 | qla4_8xxx_read_optrom_data(ha, (uint8_t *)ha->request_ring, |
| 2021 | hw->flt_region_fdt << 2, OPTROM_BURST_SIZE); |
| 2022 | |
| 2023 | if (*wptr == __constant_cpu_to_le16(0xffff)) |
| 2024 | goto no_flash_data; |
| 2025 | |
| 2026 | if (fdt->sig[0] != 'Q' || fdt->sig[1] != 'L' || fdt->sig[2] != 'I' || |
| 2027 | fdt->sig[3] != 'D') |
| 2028 | goto no_flash_data; |
| 2029 | |
| 2030 | for (cnt = 0, chksum = 0; cnt < sizeof(struct qla_fdt_layout) >> 1; |
| 2031 | cnt++) |
| 2032 | chksum += le16_to_cpu(*wptr++); |
| 2033 | |
| 2034 | if (chksum) { |
| 2035 | DEBUG2(ql4_printk(KERN_INFO, ha, "Inconsistent FDT detected: " |
| 2036 | "checksum=0x%x id=%c version=0x%x.\n", chksum, fdt->sig[0], |
| 2037 | le16_to_cpu(fdt->version))); |
| 2038 | goto no_flash_data; |
| 2039 | } |
| 2040 | |
| 2041 | loc = locations[1]; |
| 2042 | mid = le16_to_cpu(fdt->man_id); |
| 2043 | fid = le16_to_cpu(fdt->id); |
| 2044 | hw->fdt_wrt_disable = fdt->wrt_disable_bits; |
| 2045 | hw->fdt_erase_cmd = flash_conf_addr(hw, 0x0300 | fdt->erase_cmd); |
| 2046 | hw->fdt_block_size = le32_to_cpu(fdt->block_size); |
| 2047 | |
| 2048 | if (fdt->unprotect_sec_cmd) { |
| 2049 | hw->fdt_unprotect_sec_cmd = flash_conf_addr(hw, 0x0300 | |
| 2050 | fdt->unprotect_sec_cmd); |
| 2051 | hw->fdt_protect_sec_cmd = fdt->protect_sec_cmd ? |
| 2052 | flash_conf_addr(hw, 0x0300 | fdt->protect_sec_cmd) : |
| 2053 | flash_conf_addr(hw, 0x0336); |
| 2054 | } |
| 2055 | goto done; |
| 2056 | |
| 2057 | no_flash_data: |
| 2058 | loc = locations[0]; |
| 2059 | hw->fdt_block_size = FLASH_BLK_SIZE_64K; |
| 2060 | done: |
| 2061 | DEBUG2(ql4_printk(KERN_INFO, ha, "FDT[%s]: (0x%x/0x%x) erase=0x%x " |
| 2062 | "pro=%x upro=%x wrtd=0x%x blk=0x%x.\n", loc, mid, fid, |
| 2063 | hw->fdt_erase_cmd, hw->fdt_protect_sec_cmd, |
| 2064 | hw->fdt_unprotect_sec_cmd, hw->fdt_wrt_disable, |
| 2065 | hw->fdt_block_size)); |
| 2066 | } |
| 2067 | |
| 2068 | static void |
| 2069 | qla4_8xxx_get_idc_param(struct scsi_qla_host *ha) |
| 2070 | { |
| 2071 | #define QLA82XX_IDC_PARAM_ADDR 0x003e885c |
| 2072 | uint32_t *wptr; |
| 2073 | |
| 2074 | if (!is_qla8022(ha)) |
| 2075 | return; |
| 2076 | wptr = (uint32_t *)ha->request_ring; |
| 2077 | qla4_8xxx_read_optrom_data(ha, (uint8_t *)ha->request_ring, |
| 2078 | QLA82XX_IDC_PARAM_ADDR , 8); |
| 2079 | |
| 2080 | if (*wptr == __constant_cpu_to_le32(0xffffffff)) { |
| 2081 | ha->nx_dev_init_timeout = ROM_DEV_INIT_TIMEOUT; |
| 2082 | ha->nx_reset_timeout = ROM_DRV_RESET_ACK_TIMEOUT; |
| 2083 | } else { |
| 2084 | ha->nx_dev_init_timeout = le32_to_cpu(*wptr++); |
| 2085 | ha->nx_reset_timeout = le32_to_cpu(*wptr); |
| 2086 | } |
| 2087 | |
| 2088 | DEBUG2(ql4_printk(KERN_DEBUG, ha, |
| 2089 | "ha->nx_dev_init_timeout = %d\n", ha->nx_dev_init_timeout)); |
| 2090 | DEBUG2(ql4_printk(KERN_DEBUG, ha, |
| 2091 | "ha->nx_reset_timeout = %d\n", ha->nx_reset_timeout)); |
| 2092 | return; |
| 2093 | } |
| 2094 | |
| 2095 | int |
| 2096 | qla4_8xxx_get_flash_info(struct scsi_qla_host *ha) |
| 2097 | { |
| 2098 | int ret; |
| 2099 | uint32_t flt_addr; |
| 2100 | |
| 2101 | ret = qla4_8xxx_find_flt_start(ha, &flt_addr); |
| 2102 | if (ret != QLA_SUCCESS) |
| 2103 | return ret; |
| 2104 | |
| 2105 | qla4_8xxx_get_flt_info(ha, flt_addr); |
| 2106 | qla4_8xxx_get_fdt_info(ha); |
| 2107 | qla4_8xxx_get_idc_param(ha); |
| 2108 | |
| 2109 | return QLA_SUCCESS; |
| 2110 | } |
| 2111 | |
| 2112 | /** |
| 2113 | * qla4_8xxx_stop_firmware - stops firmware on specified adapter instance |
| 2114 | * @ha: pointer to host adapter structure. |
| 2115 | * |
| 2116 | * Remarks: |
| 2117 | * For iSCSI, throws away all I/O and AENs into bit bucket, so they will |
| 2118 | * not be available after successful return. Driver must cleanup potential |
| 2119 | * outstanding I/O's after calling this funcion. |
| 2120 | **/ |
| 2121 | int |
| 2122 | qla4_8xxx_stop_firmware(struct scsi_qla_host *ha) |
| 2123 | { |
| 2124 | int status; |
| 2125 | uint32_t mbox_cmd[MBOX_REG_COUNT]; |
| 2126 | uint32_t mbox_sts[MBOX_REG_COUNT]; |
| 2127 | |
| 2128 | memset(&mbox_cmd, 0, sizeof(mbox_cmd)); |
| 2129 | memset(&mbox_sts, 0, sizeof(mbox_sts)); |
| 2130 | |
| 2131 | mbox_cmd[0] = MBOX_CMD_STOP_FW; |
| 2132 | status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, |
| 2133 | &mbox_cmd[0], &mbox_sts[0]); |
| 2134 | |
| 2135 | DEBUG2(printk("scsi%ld: %s: status = %d\n", ha->host_no, |
| 2136 | __func__, status)); |
| 2137 | return status; |
| 2138 | } |
| 2139 | |
| 2140 | /** |
| 2141 | * qla4_8xxx_isp_reset - Resets ISP and aborts all outstanding commands. |
| 2142 | * @ha: pointer to host adapter structure. |
| 2143 | **/ |
| 2144 | int |
| 2145 | qla4_8xxx_isp_reset(struct scsi_qla_host *ha) |
| 2146 | { |
| 2147 | int rval; |
| 2148 | uint32_t dev_state; |
| 2149 | |
| 2150 | qla4_8xxx_idc_lock(ha); |
| 2151 | dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE); |
| 2152 | |
| 2153 | if (dev_state == QLA82XX_DEV_READY) { |
| 2154 | ql4_printk(KERN_INFO, ha, "HW State: NEED RESET\n"); |
| 2155 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 2156 | QLA82XX_DEV_NEED_RESET); |
| 2157 | } else |
| 2158 | ql4_printk(KERN_INFO, ha, "HW State: DEVICE INITIALIZING\n"); |
| 2159 | |
| 2160 | qla4_8xxx_idc_unlock(ha); |
| 2161 | |
| 2162 | rval = qla4_8xxx_device_state_handler(ha); |
| 2163 | |
| 2164 | qla4_8xxx_idc_lock(ha); |
| 2165 | qla4_8xxx_clear_rst_ready(ha); |
| 2166 | qla4_8xxx_idc_unlock(ha); |
| 2167 | |
Nilesh Javali | 2103363 | 2010-07-30 14:28:07 +0530 | [diff] [blame] | 2168 | if (rval == QLA_SUCCESS) |
| 2169 | clear_bit(AF_FW_RECOVERY, &ha->flags); |
| 2170 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2171 | return rval; |
| 2172 | } |
| 2173 | |
| 2174 | /** |
| 2175 | * qla4_8xxx_get_sys_info - get adapter MAC address(es) and serial number |
| 2176 | * @ha: pointer to host adapter structure. |
| 2177 | * |
| 2178 | **/ |
| 2179 | int qla4_8xxx_get_sys_info(struct scsi_qla_host *ha) |
| 2180 | { |
| 2181 | uint32_t mbox_cmd[MBOX_REG_COUNT]; |
| 2182 | uint32_t mbox_sts[MBOX_REG_COUNT]; |
| 2183 | struct mbx_sys_info *sys_info; |
| 2184 | dma_addr_t sys_info_dma; |
| 2185 | int status = QLA_ERROR; |
| 2186 | |
| 2187 | sys_info = dma_alloc_coherent(&ha->pdev->dev, sizeof(*sys_info), |
| 2188 | &sys_info_dma, GFP_KERNEL); |
| 2189 | if (sys_info == NULL) { |
| 2190 | DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n", |
| 2191 | ha->host_no, __func__)); |
| 2192 | return status; |
| 2193 | } |
| 2194 | |
| 2195 | memset(sys_info, 0, sizeof(*sys_info)); |
| 2196 | memset(&mbox_cmd, 0, sizeof(mbox_cmd)); |
| 2197 | memset(&mbox_sts, 0, sizeof(mbox_sts)); |
| 2198 | |
| 2199 | mbox_cmd[0] = MBOX_CMD_GET_SYS_INFO; |
| 2200 | mbox_cmd[1] = LSDW(sys_info_dma); |
| 2201 | mbox_cmd[2] = MSDW(sys_info_dma); |
| 2202 | mbox_cmd[4] = sizeof(*sys_info); |
| 2203 | |
| 2204 | if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 6, &mbox_cmd[0], |
| 2205 | &mbox_sts[0]) != QLA_SUCCESS) { |
| 2206 | DEBUG2(printk("scsi%ld: %s: GET_SYS_INFO failed\n", |
| 2207 | ha->host_no, __func__)); |
| 2208 | goto exit_validate_mac82; |
| 2209 | } |
| 2210 | |
Vikas Chaudhary | 2ccdf0d | 2010-07-30 14:27:45 +0530 | [diff] [blame] | 2211 | /* Make sure we receive the minimum required data to cache internally */ |
| 2212 | if (mbox_sts[4] < offsetof(struct mbx_sys_info, reserved)) { |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2213 | DEBUG2(printk("scsi%ld: %s: GET_SYS_INFO data receive" |
| 2214 | " error (%x)\n", ha->host_no, __func__, mbox_sts[4])); |
| 2215 | goto exit_validate_mac82; |
| 2216 | |
| 2217 | } |
| 2218 | |
| 2219 | /* Save M.A.C. address & serial_number */ |
| 2220 | memcpy(ha->my_mac, &sys_info->mac_addr[0], |
| 2221 | min(sizeof(ha->my_mac), sizeof(sys_info->mac_addr))); |
| 2222 | memcpy(ha->serial_number, &sys_info->serial_number, |
| 2223 | min(sizeof(ha->serial_number), sizeof(sys_info->serial_number))); |
| 2224 | |
| 2225 | DEBUG2(printk("scsi%ld: %s: " |
| 2226 | "mac %02x:%02x:%02x:%02x:%02x:%02x " |
| 2227 | "serial %s\n", ha->host_no, __func__, |
| 2228 | ha->my_mac[0], ha->my_mac[1], ha->my_mac[2], |
| 2229 | ha->my_mac[3], ha->my_mac[4], ha->my_mac[5], |
| 2230 | ha->serial_number)); |
| 2231 | |
| 2232 | status = QLA_SUCCESS; |
| 2233 | |
| 2234 | exit_validate_mac82: |
| 2235 | dma_free_coherent(&ha->pdev->dev, sizeof(*sys_info), sys_info, |
| 2236 | sys_info_dma); |
| 2237 | return status; |
| 2238 | } |
| 2239 | |
| 2240 | /* Interrupt handling helpers. */ |
| 2241 | |
| 2242 | static int |
| 2243 | qla4_8xxx_mbx_intr_enable(struct scsi_qla_host *ha) |
| 2244 | { |
| 2245 | uint32_t mbox_cmd[MBOX_REG_COUNT]; |
| 2246 | uint32_t mbox_sts[MBOX_REG_COUNT]; |
| 2247 | |
| 2248 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s\n", __func__)); |
| 2249 | |
| 2250 | memset(&mbox_cmd, 0, sizeof(mbox_cmd)); |
| 2251 | memset(&mbox_sts, 0, sizeof(mbox_sts)); |
| 2252 | mbox_cmd[0] = MBOX_CMD_ENABLE_INTRS; |
| 2253 | mbox_cmd[1] = INTR_ENABLE; |
| 2254 | if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], |
| 2255 | &mbox_sts[0]) != QLA_SUCCESS) { |
| 2256 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2257 | "%s: MBOX_CMD_ENABLE_INTRS failed (0x%04x)\n", |
| 2258 | __func__, mbox_sts[0])); |
| 2259 | return QLA_ERROR; |
| 2260 | } |
| 2261 | return QLA_SUCCESS; |
| 2262 | } |
| 2263 | |
| 2264 | static int |
| 2265 | qla4_8xxx_mbx_intr_disable(struct scsi_qla_host *ha) |
| 2266 | { |
| 2267 | uint32_t mbox_cmd[MBOX_REG_COUNT]; |
| 2268 | uint32_t mbox_sts[MBOX_REG_COUNT]; |
| 2269 | |
| 2270 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s\n", __func__)); |
| 2271 | |
| 2272 | memset(&mbox_cmd, 0, sizeof(mbox_cmd)); |
| 2273 | memset(&mbox_sts, 0, sizeof(mbox_sts)); |
| 2274 | mbox_cmd[0] = MBOX_CMD_ENABLE_INTRS; |
| 2275 | mbox_cmd[1] = INTR_DISABLE; |
| 2276 | if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], |
| 2277 | &mbox_sts[0]) != QLA_SUCCESS) { |
| 2278 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2279 | "%s: MBOX_CMD_ENABLE_INTRS failed (0x%04x)\n", |
| 2280 | __func__, mbox_sts[0])); |
| 2281 | return QLA_ERROR; |
| 2282 | } |
| 2283 | |
| 2284 | return QLA_SUCCESS; |
| 2285 | } |
| 2286 | |
| 2287 | void |
| 2288 | qla4_8xxx_enable_intrs(struct scsi_qla_host *ha) |
| 2289 | { |
| 2290 | qla4_8xxx_mbx_intr_enable(ha); |
| 2291 | |
| 2292 | spin_lock_irq(&ha->hardware_lock); |
| 2293 | /* BIT 10 - reset */ |
| 2294 | qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0xfbff); |
| 2295 | spin_unlock_irq(&ha->hardware_lock); |
| 2296 | set_bit(AF_INTERRUPTS_ON, &ha->flags); |
| 2297 | } |
| 2298 | |
| 2299 | void |
| 2300 | qla4_8xxx_disable_intrs(struct scsi_qla_host *ha) |
| 2301 | { |
| 2302 | if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) |
| 2303 | qla4_8xxx_mbx_intr_disable(ha); |
| 2304 | |
| 2305 | spin_lock_irq(&ha->hardware_lock); |
| 2306 | /* BIT 10 - set */ |
| 2307 | qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0x0400); |
| 2308 | spin_unlock_irq(&ha->hardware_lock); |
| 2309 | clear_bit(AF_INTERRUPTS_ON, &ha->flags); |
| 2310 | } |
| 2311 | |
| 2312 | struct ql4_init_msix_entry { |
| 2313 | uint16_t entry; |
| 2314 | uint16_t index; |
| 2315 | const char *name; |
| 2316 | irq_handler_t handler; |
| 2317 | }; |
| 2318 | |
| 2319 | static struct ql4_init_msix_entry qla4_8xxx_msix_entries[QLA_MSIX_ENTRIES] = { |
| 2320 | { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT, |
| 2321 | "qla4xxx (default)", |
| 2322 | (irq_handler_t)qla4_8xxx_default_intr_handler }, |
| 2323 | { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q, |
| 2324 | "qla4xxx (rsp_q)", (irq_handler_t)qla4_8xxx_msix_rsp_q }, |
| 2325 | }; |
| 2326 | |
| 2327 | void |
| 2328 | qla4_8xxx_disable_msix(struct scsi_qla_host *ha) |
| 2329 | { |
| 2330 | int i; |
| 2331 | struct ql4_msix_entry *qentry; |
| 2332 | |
| 2333 | for (i = 0; i < QLA_MSIX_ENTRIES; i++) { |
| 2334 | qentry = &ha->msix_entries[qla4_8xxx_msix_entries[i].index]; |
| 2335 | if (qentry->have_irq) { |
| 2336 | free_irq(qentry->msix_vector, ha); |
| 2337 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %s\n", |
| 2338 | __func__, qla4_8xxx_msix_entries[i].name)); |
| 2339 | } |
| 2340 | } |
| 2341 | pci_disable_msix(ha->pdev); |
| 2342 | clear_bit(AF_MSIX_ENABLED, &ha->flags); |
| 2343 | } |
| 2344 | |
| 2345 | int |
| 2346 | qla4_8xxx_enable_msix(struct scsi_qla_host *ha) |
| 2347 | { |
| 2348 | int i, ret; |
| 2349 | struct msix_entry entries[QLA_MSIX_ENTRIES]; |
| 2350 | struct ql4_msix_entry *qentry; |
| 2351 | |
| 2352 | for (i = 0; i < QLA_MSIX_ENTRIES; i++) |
| 2353 | entries[i].entry = qla4_8xxx_msix_entries[i].entry; |
| 2354 | |
| 2355 | ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries)); |
| 2356 | if (ret) { |
| 2357 | ql4_printk(KERN_WARNING, ha, |
| 2358 | "MSI-X: Failed to enable support -- %d/%d\n", |
| 2359 | QLA_MSIX_ENTRIES, ret); |
| 2360 | goto msix_out; |
| 2361 | } |
| 2362 | set_bit(AF_MSIX_ENABLED, &ha->flags); |
| 2363 | |
| 2364 | for (i = 0; i < QLA_MSIX_ENTRIES; i++) { |
| 2365 | qentry = &ha->msix_entries[qla4_8xxx_msix_entries[i].index]; |
| 2366 | qentry->msix_vector = entries[i].vector; |
| 2367 | qentry->msix_entry = entries[i].entry; |
| 2368 | qentry->have_irq = 0; |
| 2369 | ret = request_irq(qentry->msix_vector, |
| 2370 | qla4_8xxx_msix_entries[i].handler, 0, |
| 2371 | qla4_8xxx_msix_entries[i].name, ha); |
| 2372 | if (ret) { |
| 2373 | ql4_printk(KERN_WARNING, ha, |
| 2374 | "MSI-X: Unable to register handler -- %x/%d.\n", |
| 2375 | qla4_8xxx_msix_entries[i].index, ret); |
| 2376 | qla4_8xxx_disable_msix(ha); |
| 2377 | goto msix_out; |
| 2378 | } |
| 2379 | qentry->have_irq = 1; |
| 2380 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %s\n", |
| 2381 | __func__, qla4_8xxx_msix_entries[i].name)); |
| 2382 | } |
| 2383 | msix_out: |
| 2384 | return ret; |
| 2385 | } |