Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QLogic Fibre Channel HBA Driver |
Saurav Kashyap | 1e63395 | 2013-02-08 01:57:54 -0500 | [diff] [blame] | 3 | * Copyright (c) 2003-2013 QLogic Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
| 6 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include "qla_def.h" |
| 8 | |
| 9 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Andrew Vasquez | 2c96d8d | 2007-10-19 15:59:15 -0700 | [diff] [blame] | 11 | #include <linux/vmalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <asm/uaccess.h> |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | /* |
| 15 | * NVRAM support routines |
| 16 | */ |
| 17 | |
| 18 | /** |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 19 | * qla2x00_lock_nvram_access() - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | * @ha: HA context |
| 21 | */ |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 22 | static void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 23 | qla2x00_lock_nvram_access(struct qla_hw_data *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | { |
| 25 | uint16_t data; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 26 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) { |
| 29 | data = RD_REG_WORD(®->nvram); |
| 30 | while (data & NVR_BUSY) { |
| 31 | udelay(100); |
| 32 | data = RD_REG_WORD(®->nvram); |
| 33 | } |
| 34 | |
| 35 | /* Lock resource */ |
| 36 | WRT_REG_WORD(®->u.isp2300.host_semaphore, 0x1); |
| 37 | RD_REG_WORD(®->u.isp2300.host_semaphore); |
| 38 | udelay(5); |
| 39 | data = RD_REG_WORD(®->u.isp2300.host_semaphore); |
| 40 | while ((data & BIT_0) == 0) { |
| 41 | /* Lock failed */ |
| 42 | udelay(100); |
| 43 | WRT_REG_WORD(®->u.isp2300.host_semaphore, 0x1); |
| 44 | RD_REG_WORD(®->u.isp2300.host_semaphore); |
| 45 | udelay(5); |
| 46 | data = RD_REG_WORD(®->u.isp2300.host_semaphore); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /** |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 52 | * qla2x00_unlock_nvram_access() - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | * @ha: HA context |
| 54 | */ |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 55 | static void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 56 | qla2x00_unlock_nvram_access(struct qla_hw_data *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 58 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) { |
| 61 | WRT_REG_WORD(®->u.isp2300.host_semaphore, 0); |
| 62 | RD_REG_WORD(®->u.isp2300.host_semaphore); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /** |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 67 | * qla2x00_nv_write() - Prepare for NVRAM read/write operation. |
| 68 | * @ha: HA context |
| 69 | * @data: Serial interface selector |
| 70 | */ |
| 71 | static void |
| 72 | qla2x00_nv_write(struct qla_hw_data *ha, uint16_t data) |
| 73 | { |
| 74 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 75 | |
| 76 | WRT_REG_WORD(®->nvram, data | NVR_SELECT | NVR_WRT_ENABLE); |
| 77 | RD_REG_WORD(®->nvram); /* PCI Posting. */ |
| 78 | NVRAM_DELAY(); |
| 79 | WRT_REG_WORD(®->nvram, data | NVR_SELECT | NVR_CLOCK | |
| 80 | NVR_WRT_ENABLE); |
| 81 | RD_REG_WORD(®->nvram); /* PCI Posting. */ |
| 82 | NVRAM_DELAY(); |
| 83 | WRT_REG_WORD(®->nvram, data | NVR_SELECT | NVR_WRT_ENABLE); |
| 84 | RD_REG_WORD(®->nvram); /* PCI Posting. */ |
| 85 | NVRAM_DELAY(); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * qla2x00_nvram_request() - Sends read command to NVRAM and gets data from |
| 90 | * NVRAM. |
| 91 | * @ha: HA context |
| 92 | * @nv_cmd: NVRAM command |
| 93 | * |
| 94 | * Bit definitions for NVRAM command: |
| 95 | * |
| 96 | * Bit 26 = start bit |
| 97 | * Bit 25, 24 = opcode |
| 98 | * Bit 23-16 = address |
| 99 | * Bit 15-0 = write data |
| 100 | * |
| 101 | * Returns the word read from nvram @addr. |
| 102 | */ |
| 103 | static uint16_t |
| 104 | qla2x00_nvram_request(struct qla_hw_data *ha, uint32_t nv_cmd) |
| 105 | { |
| 106 | uint8_t cnt; |
| 107 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 108 | uint16_t data = 0; |
| 109 | uint16_t reg_data; |
| 110 | |
| 111 | /* Send command to NVRAM. */ |
| 112 | nv_cmd <<= 5; |
| 113 | for (cnt = 0; cnt < 11; cnt++) { |
| 114 | if (nv_cmd & BIT_31) |
| 115 | qla2x00_nv_write(ha, NVR_DATA_OUT); |
| 116 | else |
| 117 | qla2x00_nv_write(ha, 0); |
| 118 | nv_cmd <<= 1; |
| 119 | } |
| 120 | |
| 121 | /* Read data from NVRAM. */ |
| 122 | for (cnt = 0; cnt < 16; cnt++) { |
| 123 | WRT_REG_WORD(®->nvram, NVR_SELECT | NVR_CLOCK); |
| 124 | RD_REG_WORD(®->nvram); /* PCI Posting. */ |
| 125 | NVRAM_DELAY(); |
| 126 | data <<= 1; |
| 127 | reg_data = RD_REG_WORD(®->nvram); |
| 128 | if (reg_data & NVR_DATA_IN) |
| 129 | data |= BIT_0; |
| 130 | WRT_REG_WORD(®->nvram, NVR_SELECT); |
| 131 | RD_REG_WORD(®->nvram); /* PCI Posting. */ |
| 132 | NVRAM_DELAY(); |
| 133 | } |
| 134 | |
| 135 | /* Deselect chip. */ |
| 136 | WRT_REG_WORD(®->nvram, NVR_DESELECT); |
| 137 | RD_REG_WORD(®->nvram); /* PCI Posting. */ |
| 138 | NVRAM_DELAY(); |
| 139 | |
| 140 | return data; |
| 141 | } |
| 142 | |
| 143 | |
| 144 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | * qla2x00_get_nvram_word() - Calculates word position in NVRAM and calls the |
| 146 | * request routine to get the word from NVRAM. |
| 147 | * @ha: HA context |
| 148 | * @addr: Address in NVRAM to read |
| 149 | * |
| 150 | * Returns the word read from nvram @addr. |
| 151 | */ |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 152 | static uint16_t |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 153 | qla2x00_get_nvram_word(struct qla_hw_data *ha, uint32_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
| 155 | uint16_t data; |
| 156 | uint32_t nv_cmd; |
| 157 | |
| 158 | nv_cmd = addr << 16; |
| 159 | nv_cmd |= NV_READ_OP; |
| 160 | data = qla2x00_nvram_request(ha, nv_cmd); |
| 161 | |
| 162 | return (data); |
| 163 | } |
| 164 | |
| 165 | /** |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 166 | * qla2x00_nv_deselect() - Deselect NVRAM operations. |
| 167 | * @ha: HA context |
| 168 | */ |
| 169 | static void |
| 170 | qla2x00_nv_deselect(struct qla_hw_data *ha) |
| 171 | { |
| 172 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 173 | |
| 174 | WRT_REG_WORD(®->nvram, NVR_DESELECT); |
| 175 | RD_REG_WORD(®->nvram); /* PCI Posting. */ |
| 176 | NVRAM_DELAY(); |
| 177 | } |
| 178 | |
| 179 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | * qla2x00_write_nvram_word() - Write NVRAM data. |
| 181 | * @ha: HA context |
| 182 | * @addr: Address in NVRAM to write |
| 183 | * @data: word to program |
| 184 | */ |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 185 | static void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 186 | qla2x00_write_nvram_word(struct qla_hw_data *ha, uint32_t addr, uint16_t data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { |
| 188 | int count; |
| 189 | uint16_t word; |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 190 | uint32_t nv_cmd, wait_cnt; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 191 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 192 | scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | qla2x00_nv_write(ha, NVR_DATA_OUT); |
| 195 | qla2x00_nv_write(ha, 0); |
| 196 | qla2x00_nv_write(ha, 0); |
| 197 | |
| 198 | for (word = 0; word < 8; word++) |
| 199 | qla2x00_nv_write(ha, NVR_DATA_OUT); |
| 200 | |
| 201 | qla2x00_nv_deselect(ha); |
| 202 | |
| 203 | /* Write data */ |
| 204 | nv_cmd = (addr << 16) | NV_WRITE_OP; |
| 205 | nv_cmd |= data; |
| 206 | nv_cmd <<= 5; |
| 207 | for (count = 0; count < 27; count++) { |
| 208 | if (nv_cmd & BIT_31) |
| 209 | qla2x00_nv_write(ha, NVR_DATA_OUT); |
| 210 | else |
| 211 | qla2x00_nv_write(ha, 0); |
| 212 | |
| 213 | nv_cmd <<= 1; |
| 214 | } |
| 215 | |
| 216 | qla2x00_nv_deselect(ha); |
| 217 | |
| 218 | /* Wait for NVRAM to become ready */ |
| 219 | WRT_REG_WORD(®->nvram, NVR_SELECT); |
Andrew Vasquez | dcb36ce | 2005-11-08 14:37:06 -0800 | [diff] [blame] | 220 | RD_REG_WORD(®->nvram); /* PCI Posting. */ |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 221 | wait_cnt = NVR_WAIT_CNT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | do { |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 223 | if (!--wait_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 224 | ql_dbg(ql_dbg_user, vha, 0x708d, |
| 225 | "NVRAM didn't go ready...\n"); |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 226 | break; |
| 227 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | NVRAM_DELAY(); |
| 229 | word = RD_REG_WORD(®->nvram); |
| 230 | } while ((word & NVR_DATA_IN) == 0); |
| 231 | |
| 232 | qla2x00_nv_deselect(ha); |
| 233 | |
| 234 | /* Disable writes */ |
| 235 | qla2x00_nv_write(ha, NVR_DATA_OUT); |
| 236 | for (count = 0; count < 10; count++) |
| 237 | qla2x00_nv_write(ha, 0); |
| 238 | |
| 239 | qla2x00_nv_deselect(ha); |
| 240 | } |
| 241 | |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 242 | static int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 243 | qla2x00_write_nvram_word_tmo(struct qla_hw_data *ha, uint32_t addr, |
| 244 | uint16_t data, uint32_t tmo) |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 245 | { |
| 246 | int ret, count; |
| 247 | uint16_t word; |
| 248 | uint32_t nv_cmd; |
| 249 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 250 | |
| 251 | ret = QLA_SUCCESS; |
| 252 | |
| 253 | qla2x00_nv_write(ha, NVR_DATA_OUT); |
| 254 | qla2x00_nv_write(ha, 0); |
| 255 | qla2x00_nv_write(ha, 0); |
| 256 | |
| 257 | for (word = 0; word < 8; word++) |
| 258 | qla2x00_nv_write(ha, NVR_DATA_OUT); |
| 259 | |
| 260 | qla2x00_nv_deselect(ha); |
| 261 | |
| 262 | /* Write data */ |
| 263 | nv_cmd = (addr << 16) | NV_WRITE_OP; |
| 264 | nv_cmd |= data; |
| 265 | nv_cmd <<= 5; |
| 266 | for (count = 0; count < 27; count++) { |
| 267 | if (nv_cmd & BIT_31) |
| 268 | qla2x00_nv_write(ha, NVR_DATA_OUT); |
| 269 | else |
| 270 | qla2x00_nv_write(ha, 0); |
| 271 | |
| 272 | nv_cmd <<= 1; |
| 273 | } |
| 274 | |
| 275 | qla2x00_nv_deselect(ha); |
| 276 | |
| 277 | /* Wait for NVRAM to become ready */ |
| 278 | WRT_REG_WORD(®->nvram, NVR_SELECT); |
Andrew Vasquez | dcb36ce | 2005-11-08 14:37:06 -0800 | [diff] [blame] | 279 | RD_REG_WORD(®->nvram); /* PCI Posting. */ |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 280 | do { |
| 281 | NVRAM_DELAY(); |
| 282 | word = RD_REG_WORD(®->nvram); |
| 283 | if (!--tmo) { |
| 284 | ret = QLA_FUNCTION_FAILED; |
| 285 | break; |
| 286 | } |
| 287 | } while ((word & NVR_DATA_IN) == 0); |
| 288 | |
| 289 | qla2x00_nv_deselect(ha); |
| 290 | |
| 291 | /* Disable writes */ |
| 292 | qla2x00_nv_write(ha, NVR_DATA_OUT); |
| 293 | for (count = 0; count < 10; count++) |
| 294 | qla2x00_nv_write(ha, 0); |
| 295 | |
| 296 | qla2x00_nv_deselect(ha); |
| 297 | |
| 298 | return ret; |
| 299 | } |
| 300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | /** |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 302 | * qla2x00_clear_nvram_protection() - |
| 303 | * @ha: HA context |
| 304 | */ |
| 305 | static int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 306 | qla2x00_clear_nvram_protection(struct qla_hw_data *ha) |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 307 | { |
| 308 | int ret, stat; |
| 309 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 310 | uint32_t word, wait_cnt; |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 311 | uint16_t wprot, wprot_old; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 312 | scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 313 | |
| 314 | /* Clear NVRAM write protection. */ |
| 315 | ret = QLA_FUNCTION_FAILED; |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 316 | |
| 317 | wprot_old = cpu_to_le16(qla2x00_get_nvram_word(ha, ha->nvram_base)); |
| 318 | stat = qla2x00_write_nvram_word_tmo(ha, ha->nvram_base, |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 319 | __constant_cpu_to_le16(0x1234), 100000); |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 320 | wprot = cpu_to_le16(qla2x00_get_nvram_word(ha, ha->nvram_base)); |
| 321 | if (stat != QLA_SUCCESS || wprot != 0x1234) { |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 322 | /* Write enable. */ |
| 323 | qla2x00_nv_write(ha, NVR_DATA_OUT); |
| 324 | qla2x00_nv_write(ha, 0); |
| 325 | qla2x00_nv_write(ha, 0); |
| 326 | for (word = 0; word < 8; word++) |
| 327 | qla2x00_nv_write(ha, NVR_DATA_OUT); |
| 328 | |
| 329 | qla2x00_nv_deselect(ha); |
| 330 | |
| 331 | /* Enable protection register. */ |
| 332 | qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT); |
| 333 | qla2x00_nv_write(ha, NVR_PR_ENABLE); |
| 334 | qla2x00_nv_write(ha, NVR_PR_ENABLE); |
| 335 | for (word = 0; word < 8; word++) |
| 336 | qla2x00_nv_write(ha, NVR_DATA_OUT | NVR_PR_ENABLE); |
| 337 | |
| 338 | qla2x00_nv_deselect(ha); |
| 339 | |
| 340 | /* Clear protection register (ffff is cleared). */ |
| 341 | qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT); |
| 342 | qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT); |
| 343 | qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT); |
| 344 | for (word = 0; word < 8; word++) |
| 345 | qla2x00_nv_write(ha, NVR_DATA_OUT | NVR_PR_ENABLE); |
| 346 | |
| 347 | qla2x00_nv_deselect(ha); |
| 348 | |
| 349 | /* Wait for NVRAM to become ready. */ |
| 350 | WRT_REG_WORD(®->nvram, NVR_SELECT); |
Andrew Vasquez | dcb36ce | 2005-11-08 14:37:06 -0800 | [diff] [blame] | 351 | RD_REG_WORD(®->nvram); /* PCI Posting. */ |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 352 | wait_cnt = NVR_WAIT_CNT; |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 353 | do { |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 354 | if (!--wait_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 355 | ql_dbg(ql_dbg_user, vha, 0x708e, |
| 356 | "NVRAM didn't go ready...\n"); |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 357 | break; |
| 358 | } |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 359 | NVRAM_DELAY(); |
| 360 | word = RD_REG_WORD(®->nvram); |
| 361 | } while ((word & NVR_DATA_IN) == 0); |
| 362 | |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 363 | if (wait_cnt) |
| 364 | ret = QLA_SUCCESS; |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 365 | } else |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 366 | qla2x00_write_nvram_word(ha, ha->nvram_base, wprot_old); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 367 | |
| 368 | return ret; |
| 369 | } |
| 370 | |
| 371 | static void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 372 | qla2x00_set_nvram_protection(struct qla_hw_data *ha, int stat) |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 373 | { |
| 374 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 375 | uint32_t word, wait_cnt; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 376 | scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 377 | |
| 378 | if (stat != QLA_SUCCESS) |
| 379 | return; |
| 380 | |
| 381 | /* Set NVRAM write protection. */ |
| 382 | /* Write enable. */ |
| 383 | qla2x00_nv_write(ha, NVR_DATA_OUT); |
| 384 | qla2x00_nv_write(ha, 0); |
| 385 | qla2x00_nv_write(ha, 0); |
| 386 | for (word = 0; word < 8; word++) |
| 387 | qla2x00_nv_write(ha, NVR_DATA_OUT); |
| 388 | |
| 389 | qla2x00_nv_deselect(ha); |
| 390 | |
| 391 | /* Enable protection register. */ |
| 392 | qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT); |
| 393 | qla2x00_nv_write(ha, NVR_PR_ENABLE); |
| 394 | qla2x00_nv_write(ha, NVR_PR_ENABLE); |
| 395 | for (word = 0; word < 8; word++) |
| 396 | qla2x00_nv_write(ha, NVR_DATA_OUT | NVR_PR_ENABLE); |
| 397 | |
| 398 | qla2x00_nv_deselect(ha); |
| 399 | |
| 400 | /* Enable protection register. */ |
| 401 | qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT); |
| 402 | qla2x00_nv_write(ha, NVR_PR_ENABLE); |
| 403 | qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT); |
| 404 | for (word = 0; word < 8; word++) |
| 405 | qla2x00_nv_write(ha, NVR_PR_ENABLE); |
| 406 | |
| 407 | qla2x00_nv_deselect(ha); |
| 408 | |
| 409 | /* Wait for NVRAM to become ready. */ |
| 410 | WRT_REG_WORD(®->nvram, NVR_SELECT); |
Andrew Vasquez | dcb36ce | 2005-11-08 14:37:06 -0800 | [diff] [blame] | 411 | RD_REG_WORD(®->nvram); /* PCI Posting. */ |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 412 | wait_cnt = NVR_WAIT_CNT; |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 413 | do { |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 414 | if (!--wait_cnt) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 415 | ql_dbg(ql_dbg_user, vha, 0x708f, |
| 416 | "NVRAM didn't go ready...\n"); |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 417 | break; |
| 418 | } |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 419 | NVRAM_DELAY(); |
| 420 | word = RD_REG_WORD(®->nvram); |
| 421 | } while ((word & NVR_DATA_IN) == 0); |
| 422 | } |
| 423 | |
| 424 | |
| 425 | /*****************************************************************************/ |
| 426 | /* Flash Manipulation Routines */ |
| 427 | /*****************************************************************************/ |
| 428 | |
| 429 | static inline uint32_t |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 430 | flash_conf_addr(struct qla_hw_data *ha, uint32_t faddr) |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 431 | { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 432 | return ha->flash_conf_off | faddr; |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | static inline uint32_t |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 436 | flash_data_addr(struct qla_hw_data *ha, uint32_t faddr) |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 437 | { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 438 | return ha->flash_data_off | faddr; |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | static inline uint32_t |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 442 | nvram_conf_addr(struct qla_hw_data *ha, uint32_t naddr) |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 443 | { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 444 | return ha->nvram_conf_off | naddr; |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | static inline uint32_t |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 448 | nvram_data_addr(struct qla_hw_data *ha, uint32_t naddr) |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 449 | { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 450 | return ha->nvram_data_off | naddr; |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 453 | static uint32_t |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 454 | qla24xx_read_flash_dword(struct qla_hw_data *ha, uint32_t addr) |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 455 | { |
| 456 | int rval; |
| 457 | uint32_t cnt, data; |
| 458 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 459 | |
| 460 | WRT_REG_DWORD(®->flash_addr, addr & ~FARX_DATA_FLAG); |
| 461 | /* Wait for READ cycle to complete. */ |
| 462 | rval = QLA_SUCCESS; |
| 463 | for (cnt = 3000; |
| 464 | (RD_REG_DWORD(®->flash_addr) & FARX_DATA_FLAG) == 0 && |
| 465 | rval == QLA_SUCCESS; cnt--) { |
| 466 | if (cnt) |
| 467 | udelay(10); |
| 468 | else |
| 469 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 40a2e34 | 2007-03-12 10:41:28 -0700 | [diff] [blame] | 470 | cond_resched(); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | /* TODO: What happens if we time out? */ |
| 474 | data = 0xDEADDEAD; |
| 475 | if (rval == QLA_SUCCESS) |
| 476 | data = RD_REG_DWORD(®->flash_data); |
| 477 | |
| 478 | return data; |
| 479 | } |
| 480 | |
| 481 | uint32_t * |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 482 | qla24xx_read_flash_data(scsi_qla_host_t *vha, uint32_t *dwptr, uint32_t faddr, |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 483 | uint32_t dwords) |
| 484 | { |
| 485 | uint32_t i; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 486 | struct qla_hw_data *ha = vha->hw; |
| 487 | |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 488 | /* Dword reads to flash. */ |
| 489 | for (i = 0; i < dwords; i++, faddr++) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 490 | dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha, |
| 491 | flash_data_addr(ha, faddr))); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 492 | |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 493 | return dwptr; |
| 494 | } |
| 495 | |
Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 496 | static int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 497 | qla24xx_write_flash_dword(struct qla_hw_data *ha, uint32_t addr, uint32_t data) |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 498 | { |
| 499 | int rval; |
| 500 | uint32_t cnt; |
| 501 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 502 | |
| 503 | WRT_REG_DWORD(®->flash_data, data); |
| 504 | RD_REG_DWORD(®->flash_data); /* PCI Posting. */ |
| 505 | WRT_REG_DWORD(®->flash_addr, addr | FARX_DATA_FLAG); |
| 506 | /* Wait for Write cycle to complete. */ |
| 507 | rval = QLA_SUCCESS; |
| 508 | for (cnt = 500000; (RD_REG_DWORD(®->flash_addr) & FARX_DATA_FLAG) && |
| 509 | rval == QLA_SUCCESS; cnt--) { |
| 510 | if (cnt) |
| 511 | udelay(10); |
| 512 | else |
| 513 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 40a2e34 | 2007-03-12 10:41:28 -0700 | [diff] [blame] | 514 | cond_resched(); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 515 | } |
| 516 | return rval; |
| 517 | } |
| 518 | |
Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 519 | static void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 520 | qla24xx_get_flash_manufacturer(struct qla_hw_data *ha, uint8_t *man_id, |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 521 | uint8_t *flash_id) |
| 522 | { |
| 523 | uint32_t ids; |
| 524 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 525 | ids = qla24xx_read_flash_dword(ha, flash_conf_addr(ha, 0x03ab)); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 526 | *man_id = LSB(ids); |
| 527 | *flash_id = MSB(ids); |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 528 | |
| 529 | /* Check if man_id and flash_id are valid. */ |
| 530 | if (ids != 0xDEADDEAD && (*man_id == 0 || *flash_id == 0)) { |
| 531 | /* Read information using 0x9f opcode |
| 532 | * Device ID, Mfg ID would be read in the format: |
| 533 | * <Ext Dev Info><Device ID Part2><Device ID Part 1><Mfg ID> |
| 534 | * Example: ATMEL 0x00 01 45 1F |
| 535 | * Extract MFG and Dev ID from last two bytes. |
| 536 | */ |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 537 | ids = qla24xx_read_flash_dword(ha, flash_conf_addr(ha, 0x009f)); |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 538 | *man_id = LSB(ids); |
| 539 | *flash_id = MSB(ids); |
| 540 | } |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 541 | } |
| 542 | |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 543 | static int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 544 | qla2xxx_find_flt_start(scsi_qla_host_t *vha, uint32_t *start) |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 545 | { |
| 546 | const char *loc, *locations[] = { "DEF", "PCI" }; |
| 547 | uint32_t pcihdr, pcids; |
| 548 | uint32_t *dcode; |
| 549 | uint8_t *buf, *bcode, last_image; |
| 550 | uint16_t cnt, chksum, *wptr; |
| 551 | struct qla_flt_location *fltl; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 552 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 553 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 554 | |
| 555 | /* |
| 556 | * FLT-location structure resides after the last PCI region. |
| 557 | */ |
| 558 | |
| 559 | /* Begin with sane defaults. */ |
| 560 | loc = locations[0]; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 561 | *start = 0; |
| 562 | if (IS_QLA24XX_TYPE(ha)) |
| 563 | *start = FA_FLASH_LAYOUT_ADDR_24; |
| 564 | else if (IS_QLA25XX(ha)) |
| 565 | *start = FA_FLASH_LAYOUT_ADDR; |
| 566 | else if (IS_QLA81XX(ha)) |
| 567 | *start = FA_FLASH_LAYOUT_ADDR_81; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 568 | else if (IS_QLA82XX(ha)) { |
| 569 | *start = FA_FLASH_LAYOUT_ADDR_82; |
| 570 | goto end; |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 571 | } else if (IS_QLA83XX(ha)) { |
| 572 | *start = FA_FLASH_LAYOUT_ADDR_83; |
| 573 | goto end; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 574 | } |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 575 | /* Begin with first PCI expansion ROM header. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 576 | buf = (uint8_t *)req->ring; |
| 577 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 578 | pcihdr = 0; |
| 579 | last_image = 1; |
| 580 | do { |
| 581 | /* Verify PCI expansion ROM header. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 582 | qla24xx_read_flash_data(vha, dcode, pcihdr >> 2, 0x20); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 583 | bcode = buf + (pcihdr % 4); |
| 584 | if (bcode[0x0] != 0x55 || bcode[0x1] != 0xaa) |
| 585 | goto end; |
| 586 | |
| 587 | /* Locate PCI data structure. */ |
| 588 | pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 589 | qla24xx_read_flash_data(vha, dcode, pcids >> 2, 0x20); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 590 | bcode = buf + (pcihdr % 4); |
| 591 | |
| 592 | /* Validate signature of PCI data structure. */ |
| 593 | if (bcode[0x0] != 'P' || bcode[0x1] != 'C' || |
| 594 | bcode[0x2] != 'I' || bcode[0x3] != 'R') |
| 595 | goto end; |
| 596 | |
| 597 | last_image = bcode[0x15] & BIT_7; |
| 598 | |
| 599 | /* Locate next PCI expansion ROM. */ |
| 600 | pcihdr += ((bcode[0x11] << 8) | bcode[0x10]) * 512; |
| 601 | } while (!last_image); |
| 602 | |
| 603 | /* Now verify FLT-location structure. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 604 | fltl = (struct qla_flt_location *)req->ring; |
| 605 | qla24xx_read_flash_data(vha, dcode, pcihdr >> 2, |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 606 | sizeof(struct qla_flt_location) >> 2); |
| 607 | if (fltl->sig[0] != 'Q' || fltl->sig[1] != 'F' || |
| 608 | fltl->sig[2] != 'L' || fltl->sig[3] != 'T') |
| 609 | goto end; |
| 610 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 611 | wptr = (uint16_t *)req->ring; |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 612 | cnt = sizeof(struct qla_flt_location) >> 1; |
| 613 | for (chksum = 0; cnt; cnt--) |
| 614 | chksum += le16_to_cpu(*wptr++); |
| 615 | if (chksum) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 616 | ql_log(ql_log_fatal, vha, 0x0045, |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 617 | "Inconsistent FLTL detected: checksum=0x%x.\n", chksum); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 618 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010e, |
| 619 | buf, sizeof(struct qla_flt_location)); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 620 | return QLA_FUNCTION_FAILED; |
| 621 | } |
| 622 | |
| 623 | /* Good data. Use specified location. */ |
| 624 | loc = locations[1]; |
Harish Zunjarrao | 79c13a7 | 2009-03-24 09:08:19 -0700 | [diff] [blame] | 625 | *start = (le16_to_cpu(fltl->start_hi) << 16 | |
| 626 | le16_to_cpu(fltl->start_lo)) >> 2; |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 627 | end: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 628 | ql_dbg(ql_dbg_init, vha, 0x0046, |
| 629 | "FLTL[%s] = 0x%x.\n", |
| 630 | loc, *start); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 631 | return QLA_SUCCESS; |
| 632 | } |
| 633 | |
| 634 | static void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 635 | qla2xxx_get_flt_info(scsi_qla_host_t *vha, uint32_t flt_addr) |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 636 | { |
| 637 | const char *loc, *locations[] = { "DEF", "FLT" }; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 638 | const uint32_t def_fw[] = |
| 639 | { FA_RISC_CODE_ADDR, FA_RISC_CODE_ADDR, FA_RISC_CODE_ADDR_81 }; |
| 640 | const uint32_t def_boot[] = |
| 641 | { FA_BOOT_CODE_ADDR, FA_BOOT_CODE_ADDR, FA_BOOT_CODE_ADDR_81 }; |
| 642 | const uint32_t def_vpd_nvram[] = |
| 643 | { FA_VPD_NVRAM_ADDR, FA_VPD_NVRAM_ADDR, FA_VPD_NVRAM_ADDR_81 }; |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 644 | const uint32_t def_vpd0[] = |
| 645 | { 0, 0, FA_VPD0_ADDR_81 }; |
| 646 | const uint32_t def_vpd1[] = |
| 647 | { 0, 0, FA_VPD1_ADDR_81 }; |
| 648 | const uint32_t def_nvram0[] = |
| 649 | { 0, 0, FA_NVRAM0_ADDR_81 }; |
| 650 | const uint32_t def_nvram1[] = |
| 651 | { 0, 0, FA_NVRAM1_ADDR_81 }; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 652 | const uint32_t def_fdt[] = |
| 653 | { FA_FLASH_DESCR_ADDR_24, FA_FLASH_DESCR_ADDR, |
| 654 | FA_FLASH_DESCR_ADDR_81 }; |
| 655 | const uint32_t def_npiv_conf0[] = |
| 656 | { FA_NPIV_CONF0_ADDR_24, FA_NPIV_CONF0_ADDR, |
| 657 | FA_NPIV_CONF0_ADDR_81 }; |
| 658 | const uint32_t def_npiv_conf1[] = |
| 659 | { FA_NPIV_CONF1_ADDR_24, FA_NPIV_CONF1_ADDR, |
| 660 | FA_NPIV_CONF1_ADDR_81 }; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 661 | const uint32_t fcp_prio_cfg0[] = |
| 662 | { FA_FCP_PRIO0_ADDR, FA_FCP_PRIO0_ADDR_25, |
| 663 | 0 }; |
| 664 | const uint32_t fcp_prio_cfg1[] = |
| 665 | { FA_FCP_PRIO1_ADDR, FA_FCP_PRIO1_ADDR_25, |
| 666 | 0 }; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 667 | uint32_t def; |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 668 | uint16_t *wptr; |
| 669 | uint16_t cnt, chksum; |
| 670 | uint32_t start; |
| 671 | struct qla_flt_header *flt; |
| 672 | struct qla_flt_region *region; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 673 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 674 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 675 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 676 | def = 0; |
| 677 | if (IS_QLA25XX(ha)) |
| 678 | def = 1; |
| 679 | else if (IS_QLA81XX(ha)) |
| 680 | def = 2; |
Andrew Vasquez | ff8073f | 2010-12-21 16:00:16 -0800 | [diff] [blame] | 681 | |
| 682 | /* Assign FCP prio region since older adapters may not have FLT, or |
| 683 | FCP prio region in it's FLT. |
| 684 | */ |
| 685 | ha->flt_region_fcp_prio = ha->flags.port0 ? |
| 686 | fcp_prio_cfg0[def] : fcp_prio_cfg1[def]; |
| 687 | |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 688 | ha->flt_region_flt = flt_addr; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 689 | wptr = (uint16_t *)req->ring; |
| 690 | flt = (struct qla_flt_header *)req->ring; |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 691 | region = (struct qla_flt_region *)&flt[1]; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 692 | ha->isp_ops->read_optrom(vha, (uint8_t *)req->ring, |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 693 | flt_addr << 2, OPTROM_BURST_SIZE); |
| 694 | if (*wptr == __constant_cpu_to_le16(0xffff)) |
| 695 | goto no_flash_data; |
| 696 | if (flt->version != __constant_cpu_to_le16(1)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 697 | ql_log(ql_log_warn, vha, 0x0047, |
| 698 | "Unsupported FLT detected: version=0x%x length=0x%x checksum=0x%x.\n", |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 699 | le16_to_cpu(flt->version), le16_to_cpu(flt->length), |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 700 | le16_to_cpu(flt->checksum)); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 701 | goto no_flash_data; |
| 702 | } |
| 703 | |
| 704 | cnt = (sizeof(struct qla_flt_header) + le16_to_cpu(flt->length)) >> 1; |
| 705 | for (chksum = 0; cnt; cnt--) |
| 706 | chksum += le16_to_cpu(*wptr++); |
| 707 | if (chksum) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 708 | ql_log(ql_log_fatal, vha, 0x0048, |
| 709 | "Inconsistent FLT detected: version=0x%x length=0x%x checksum=0x%x.\n", |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 710 | le16_to_cpu(flt->version), le16_to_cpu(flt->length), |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 711 | le16_to_cpu(flt->checksum)); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 712 | goto no_flash_data; |
| 713 | } |
| 714 | |
| 715 | loc = locations[1]; |
| 716 | cnt = le16_to_cpu(flt->length) / sizeof(struct qla_flt_region); |
| 717 | for ( ; cnt; cnt--, region++) { |
| 718 | /* Store addresses as DWORD offsets. */ |
| 719 | start = le32_to_cpu(region->start) >> 2; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 720 | ql_dbg(ql_dbg_init, vha, 0x0049, |
| 721 | "FLT[%02x]: start=0x%x " |
| 722 | "end=0x%x size=0x%x.\n", le32_to_cpu(region->code), |
| 723 | start, le32_to_cpu(region->end) >> 2, |
| 724 | le32_to_cpu(region->size)); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 725 | |
Andrew Vasquez | 9088608 | 2009-02-08 20:50:14 -0800 | [diff] [blame] | 726 | switch (le32_to_cpu(region->code) & 0xff) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 727 | case FLT_REG_FCOE_FW: |
| 728 | if (!IS_QLA8031(ha)) |
| 729 | break; |
| 730 | ha->flt_region_fw = start; |
| 731 | break; |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 732 | case FLT_REG_FW: |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 733 | if (IS_QLA8031(ha)) |
| 734 | break; |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 735 | ha->flt_region_fw = start; |
| 736 | break; |
| 737 | case FLT_REG_BOOT_CODE: |
| 738 | ha->flt_region_boot = start; |
| 739 | break; |
| 740 | case FLT_REG_VPD_0: |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 741 | if (IS_QLA8031(ha)) |
| 742 | break; |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 743 | ha->flt_region_vpd_nvram = start; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 744 | if (IS_QLA82XX(ha)) |
| 745 | break; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 746 | if (ha->flags.port0) |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 747 | ha->flt_region_vpd = start; |
| 748 | break; |
| 749 | case FLT_REG_VPD_1: |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 750 | if (IS_QLA82XX(ha) || IS_QLA8031(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 751 | break; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 752 | if (!ha->flags.port0) |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 753 | ha->flt_region_vpd = start; |
| 754 | break; |
| 755 | case FLT_REG_NVRAM_0: |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 756 | if (IS_QLA8031(ha)) |
| 757 | break; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 758 | if (ha->flags.port0) |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 759 | ha->flt_region_nvram = start; |
| 760 | break; |
| 761 | case FLT_REG_NVRAM_1: |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 762 | if (IS_QLA8031(ha)) |
| 763 | break; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 764 | if (!ha->flags.port0) |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 765 | ha->flt_region_nvram = start; |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 766 | break; |
| 767 | case FLT_REG_FDT: |
| 768 | ha->flt_region_fdt = start; |
| 769 | break; |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 770 | case FLT_REG_NPIV_CONF_0: |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 771 | if (ha->flags.port0) |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 772 | ha->flt_region_npiv_conf = start; |
| 773 | break; |
| 774 | case FLT_REG_NPIV_CONF_1: |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 775 | if (!ha->flags.port0) |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 776 | ha->flt_region_npiv_conf = start; |
| 777 | break; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 778 | case FLT_REG_GOLD_FW: |
| 779 | ha->flt_region_gold_fw = start; |
| 780 | break; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 781 | case FLT_REG_FCP_PRIO_0: |
Sarang Radke | bfdaa76 | 2010-03-19 17:04:01 -0700 | [diff] [blame] | 782 | if (ha->flags.port0) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 783 | ha->flt_region_fcp_prio = start; |
| 784 | break; |
| 785 | case FLT_REG_FCP_PRIO_1: |
Sarang Radke | bfdaa76 | 2010-03-19 17:04:01 -0700 | [diff] [blame] | 786 | if (!ha->flags.port0) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 787 | ha->flt_region_fcp_prio = start; |
| 788 | break; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 789 | case FLT_REG_BOOT_CODE_82XX: |
| 790 | ha->flt_region_boot = start; |
| 791 | break; |
| 792 | case FLT_REG_FW_82XX: |
| 793 | ha->flt_region_fw = start; |
| 794 | break; |
| 795 | case FLT_REG_GOLD_FW_82XX: |
| 796 | ha->flt_region_gold_fw = start; |
| 797 | break; |
| 798 | case FLT_REG_BOOTLOAD_82XX: |
| 799 | ha->flt_region_bootload = start; |
| 800 | break; |
Saurav Kashyap | a865c50 | 2013-02-08 01:57:43 -0500 | [diff] [blame] | 801 | case FLT_REG_VPD_8XXX: |
| 802 | if (IS_CNA_CAPABLE(ha)) |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 803 | ha->flt_region_vpd = start; |
| 804 | break; |
| 805 | case FLT_REG_FCOE_NVRAM_0: |
| 806 | if (!IS_QLA8031(ha)) |
| 807 | break; |
| 808 | if (ha->flags.port0) |
| 809 | ha->flt_region_nvram = start; |
| 810 | break; |
| 811 | case FLT_REG_FCOE_NVRAM_1: |
| 812 | if (!IS_QLA8031(ha)) |
| 813 | break; |
| 814 | if (!ha->flags.port0) |
| 815 | ha->flt_region_nvram = start; |
| 816 | break; |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 817 | } |
| 818 | } |
| 819 | goto done; |
| 820 | |
| 821 | no_flash_data: |
| 822 | /* Use hardcoded defaults. */ |
| 823 | loc = locations[0]; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 824 | ha->flt_region_fw = def_fw[def]; |
| 825 | ha->flt_region_boot = def_boot[def]; |
| 826 | ha->flt_region_vpd_nvram = def_vpd_nvram[def]; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 827 | ha->flt_region_vpd = ha->flags.port0 ? |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 828 | def_vpd0[def] : def_vpd1[def]; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 829 | ha->flt_region_nvram = ha->flags.port0 ? |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 830 | def_nvram0[def] : def_nvram1[def]; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 831 | ha->flt_region_fdt = def_fdt[def]; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 832 | ha->flt_region_npiv_conf = ha->flags.port0 ? |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 833 | def_npiv_conf0[def] : def_npiv_conf1[def]; |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 834 | done: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 835 | ql_dbg(ql_dbg_init, vha, 0x004a, |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 836 | "FLT[%s]: boot=0x%x fw=0x%x vpd_nvram=0x%x vpd=0x%x nvram=0x%x " |
| 837 | "fdt=0x%x flt=0x%x npiv=0x%x fcp_prif_cfg=0x%x.\n", |
| 838 | loc, ha->flt_region_boot, ha->flt_region_fw, |
| 839 | ha->flt_region_vpd_nvram, ha->flt_region_vpd, ha->flt_region_nvram, |
| 840 | ha->flt_region_fdt, ha->flt_region_flt, ha->flt_region_npiv_conf, |
| 841 | ha->flt_region_fcp_prio); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | static void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 845 | qla2xxx_get_fdt_info(scsi_qla_host_t *vha) |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 846 | { |
Lalit Chandivade | 821b399 | 2008-10-24 15:13:44 -0700 | [diff] [blame] | 847 | #define FLASH_BLK_SIZE_4K 0x1000 |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 848 | #define FLASH_BLK_SIZE_32K 0x8000 |
| 849 | #define FLASH_BLK_SIZE_64K 0x10000 |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 850 | const char *loc, *locations[] = { "MID", "FDT" }; |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 851 | uint16_t cnt, chksum; |
| 852 | uint16_t *wptr; |
| 853 | struct qla_fdt_layout *fdt; |
| 854 | uint8_t man_id, flash_id; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 855 | uint16_t mid = 0, fid = 0; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 856 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 857 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 858 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 859 | wptr = (uint16_t *)req->ring; |
| 860 | fdt = (struct qla_fdt_layout *)req->ring; |
| 861 | ha->isp_ops->read_optrom(vha, (uint8_t *)req->ring, |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 862 | ha->flt_region_fdt << 2, OPTROM_BURST_SIZE); |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 863 | if (*wptr == __constant_cpu_to_le16(0xffff)) |
| 864 | goto no_flash_data; |
| 865 | if (fdt->sig[0] != 'Q' || fdt->sig[1] != 'L' || fdt->sig[2] != 'I' || |
| 866 | fdt->sig[3] != 'D') |
| 867 | goto no_flash_data; |
| 868 | |
| 869 | for (cnt = 0, chksum = 0; cnt < sizeof(struct qla_fdt_layout) >> 1; |
| 870 | cnt++) |
| 871 | chksum += le16_to_cpu(*wptr++); |
| 872 | if (chksum) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 873 | ql_dbg(ql_dbg_init, vha, 0x004c, |
| 874 | "Inconsistent FDT detected:" |
| 875 | " checksum=0x%x id=%c version0x%x.\n", chksum, |
| 876 | fdt->sig[0], le16_to_cpu(fdt->version)); |
| 877 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0113, |
| 878 | (uint8_t *)fdt, sizeof(*fdt)); |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 879 | goto no_flash_data; |
| 880 | } |
| 881 | |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 882 | loc = locations[1]; |
| 883 | mid = le16_to_cpu(fdt->man_id); |
| 884 | fid = le16_to_cpu(fdt->id); |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 885 | ha->fdt_wrt_disable = fdt->wrt_disable_bits; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 886 | ha->fdt_erase_cmd = flash_conf_addr(ha, 0x0300 | fdt->erase_cmd); |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 887 | ha->fdt_block_size = le32_to_cpu(fdt->block_size); |
| 888 | if (fdt->unprotect_sec_cmd) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 889 | ha->fdt_unprotect_sec_cmd = flash_conf_addr(ha, 0x0300 | |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 890 | fdt->unprotect_sec_cmd); |
| 891 | ha->fdt_protect_sec_cmd = fdt->protect_sec_cmd ? |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 892 | flash_conf_addr(ha, 0x0300 | fdt->protect_sec_cmd): |
| 893 | flash_conf_addr(ha, 0x0336); |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 894 | } |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 895 | goto done; |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 896 | no_flash_data: |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 897 | loc = locations[0]; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 898 | if (IS_QLA82XX(ha)) { |
| 899 | ha->fdt_block_size = FLASH_BLK_SIZE_64K; |
| 900 | goto done; |
| 901 | } |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 902 | qla24xx_get_flash_manufacturer(ha, &man_id, &flash_id); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 903 | mid = man_id; |
| 904 | fid = flash_id; |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 905 | ha->fdt_wrt_disable = 0x9c; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 906 | ha->fdt_erase_cmd = flash_conf_addr(ha, 0x03d8); |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 907 | switch (man_id) { |
| 908 | case 0xbf: /* STT flash. */ |
| 909 | if (flash_id == 0x8e) |
| 910 | ha->fdt_block_size = FLASH_BLK_SIZE_64K; |
| 911 | else |
| 912 | ha->fdt_block_size = FLASH_BLK_SIZE_32K; |
| 913 | |
| 914 | if (flash_id == 0x80) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 915 | ha->fdt_erase_cmd = flash_conf_addr(ha, 0x0352); |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 916 | break; |
| 917 | case 0x13: /* ST M25P80. */ |
| 918 | ha->fdt_block_size = FLASH_BLK_SIZE_64K; |
| 919 | break; |
| 920 | case 0x1f: /* Atmel 26DF081A. */ |
Lalit Chandivade | 821b399 | 2008-10-24 15:13:44 -0700 | [diff] [blame] | 921 | ha->fdt_block_size = FLASH_BLK_SIZE_4K; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 922 | ha->fdt_erase_cmd = flash_conf_addr(ha, 0x0320); |
| 923 | ha->fdt_unprotect_sec_cmd = flash_conf_addr(ha, 0x0339); |
| 924 | ha->fdt_protect_sec_cmd = flash_conf_addr(ha, 0x0336); |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 925 | break; |
| 926 | default: |
| 927 | /* Default to 64 kb sector size. */ |
| 928 | ha->fdt_block_size = FLASH_BLK_SIZE_64K; |
| 929 | break; |
| 930 | } |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 931 | done: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 932 | ql_dbg(ql_dbg_init, vha, 0x004d, |
Joe Perches | d8424f6 | 2011-11-18 09:03:06 -0800 | [diff] [blame] | 933 | "FDT[%s]: (0x%x/0x%x) erase=0x%x " |
| 934 | "pr=%x wrtd=0x%x blk=0x%x.\n", |
| 935 | loc, mid, fid, |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 936 | ha->fdt_erase_cmd, ha->fdt_protect_sec_cmd, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 937 | ha->fdt_wrt_disable, ha->fdt_block_size); |
| 938 | |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 939 | } |
| 940 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 941 | static void |
| 942 | qla2xxx_get_idc_param(scsi_qla_host_t *vha) |
| 943 | { |
| 944 | #define QLA82XX_IDC_PARAM_ADDR 0x003e885c |
| 945 | uint32_t *wptr; |
| 946 | struct qla_hw_data *ha = vha->hw; |
| 947 | struct req_que *req = ha->req_q_map[0]; |
| 948 | |
| 949 | if (!IS_QLA82XX(ha)) |
| 950 | return; |
| 951 | |
| 952 | wptr = (uint32_t *)req->ring; |
| 953 | ha->isp_ops->read_optrom(vha, (uint8_t *)req->ring, |
| 954 | QLA82XX_IDC_PARAM_ADDR , 8); |
| 955 | |
| 956 | if (*wptr == __constant_cpu_to_le32(0xffffffff)) { |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 957 | ha->fcoe_dev_init_timeout = QLA82XX_ROM_DEV_INIT_TIMEOUT; |
| 958 | ha->fcoe_reset_timeout = QLA82XX_ROM_DRV_RESET_ACK_TIMEOUT; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 959 | } else { |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 960 | ha->fcoe_dev_init_timeout = le32_to_cpu(*wptr++); |
| 961 | ha->fcoe_reset_timeout = le32_to_cpu(*wptr); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 962 | } |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 963 | ql_dbg(ql_dbg_init, vha, 0x004e, |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 964 | "fcoe_dev_init_timeout=%d " |
| 965 | "fcoe_reset_timeout=%d.\n", ha->fcoe_dev_init_timeout, |
| 966 | ha->fcoe_reset_timeout); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 967 | return; |
| 968 | } |
| 969 | |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 970 | int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 971 | qla2xxx_get_flash_info(scsi_qla_host_t *vha) |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 972 | { |
| 973 | int ret; |
| 974 | uint32_t flt_addr; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 975 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 976 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 977 | if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && |
| 978 | !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha)) |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 979 | return QLA_SUCCESS; |
| 980 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 981 | ret = qla2xxx_find_flt_start(vha, &flt_addr); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 982 | if (ret != QLA_SUCCESS) |
| 983 | return ret; |
| 984 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 985 | qla2xxx_get_flt_info(vha, flt_addr); |
| 986 | qla2xxx_get_fdt_info(vha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 987 | qla2xxx_get_idc_param(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 988 | |
| 989 | return QLA_SUCCESS; |
| 990 | } |
| 991 | |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 992 | void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 993 | qla2xxx_flash_npiv_conf(scsi_qla_host_t *vha) |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 994 | { |
| 995 | #define NPIV_CONFIG_SIZE (16*1024) |
| 996 | void *data; |
| 997 | uint16_t *wptr; |
| 998 | uint16_t cnt, chksum; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 999 | int i; |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 1000 | struct qla_npiv_header hdr; |
| 1001 | struct qla_npiv_entry *entry; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1002 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 1003 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1004 | if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && |
| 1005 | !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha)) |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 1006 | return; |
| 1007 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1008 | if (ha->flags.nic_core_reset_hdlr_active) |
Giridhar Malavali | a49393f | 2012-04-25 07:26:14 -0700 | [diff] [blame] | 1009 | return; |
| 1010 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1011 | ha->isp_ops->read_optrom(vha, (uint8_t *)&hdr, |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 1012 | ha->flt_region_npiv_conf << 2, sizeof(struct qla_npiv_header)); |
| 1013 | if (hdr.version == __constant_cpu_to_le16(0xffff)) |
| 1014 | return; |
| 1015 | if (hdr.version != __constant_cpu_to_le16(1)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1016 | ql_dbg(ql_dbg_user, vha, 0x7090, |
| 1017 | "Unsupported NPIV-Config " |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 1018 | "detected: version=0x%x entries=0x%x checksum=0x%x.\n", |
| 1019 | le16_to_cpu(hdr.version), le16_to_cpu(hdr.entries), |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1020 | le16_to_cpu(hdr.checksum)); |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 1021 | return; |
| 1022 | } |
| 1023 | |
| 1024 | data = kmalloc(NPIV_CONFIG_SIZE, GFP_KERNEL); |
| 1025 | if (!data) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1026 | ql_log(ql_log_warn, vha, 0x7091, |
| 1027 | "Unable to allocate memory for data.\n"); |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 1028 | return; |
| 1029 | } |
| 1030 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1031 | ha->isp_ops->read_optrom(vha, (uint8_t *)data, |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 1032 | ha->flt_region_npiv_conf << 2, NPIV_CONFIG_SIZE); |
| 1033 | |
| 1034 | cnt = (sizeof(struct qla_npiv_header) + le16_to_cpu(hdr.entries) * |
| 1035 | sizeof(struct qla_npiv_entry)) >> 1; |
| 1036 | for (wptr = data, chksum = 0; cnt; cnt--) |
| 1037 | chksum += le16_to_cpu(*wptr++); |
| 1038 | if (chksum) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1039 | ql_dbg(ql_dbg_user, vha, 0x7092, |
| 1040 | "Inconsistent NPIV-Config " |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 1041 | "detected: version=0x%x entries=0x%x checksum=0x%x.\n", |
| 1042 | le16_to_cpu(hdr.version), le16_to_cpu(hdr.entries), |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1043 | le16_to_cpu(hdr.checksum)); |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 1044 | goto done; |
| 1045 | } |
| 1046 | |
| 1047 | entry = data + sizeof(struct qla_npiv_header); |
| 1048 | cnt = le16_to_cpu(hdr.entries); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1049 | for (i = 0; cnt; cnt--, entry++, i++) { |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 1050 | uint16_t flags; |
| 1051 | struct fc_vport_identifiers vid; |
| 1052 | struct fc_vport *vport; |
| 1053 | |
Anirban Chakraborty | 40859ae | 2009-06-03 09:55:16 -0700 | [diff] [blame] | 1054 | memcpy(&ha->npiv_info[i], entry, sizeof(struct qla_npiv_entry)); |
| 1055 | |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 1056 | flags = le16_to_cpu(entry->flags); |
| 1057 | if (flags == 0xffff) |
| 1058 | continue; |
| 1059 | if ((flags & BIT_0) == 0) |
| 1060 | continue; |
| 1061 | |
| 1062 | memset(&vid, 0, sizeof(vid)); |
| 1063 | vid.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 1064 | vid.vport_type = FC_PORTTYPE_NPIV; |
| 1065 | vid.disable = false; |
| 1066 | vid.port_name = wwn_to_u64(entry->port_name); |
| 1067 | vid.node_name = wwn_to_u64(entry->node_name); |
| 1068 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1069 | ql_dbg(ql_dbg_user, vha, 0x7093, |
| 1070 | "NPIV[%02x]: wwpn=%llx " |
| 1071 | "wwnn=%llx vf_id=0x%x Q_qos=0x%x F_qos=0x%x.\n", cnt, |
| 1072 | (unsigned long long)vid.port_name, |
| 1073 | (unsigned long long)vid.node_name, |
| 1074 | le16_to_cpu(entry->vf_id), |
| 1075 | entry->q_qos, entry->f_qos); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1076 | |
| 1077 | if (i < QLA_PRECONFIG_VPORTS) { |
| 1078 | vport = fc_vport_create(vha->host, 0, &vid); |
| 1079 | if (!vport) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1080 | ql_log(ql_log_warn, vha, 0x7094, |
| 1081 | "NPIV-Config Failed to create vport [%02x]: " |
| 1082 | "wwpn=%llx wwnn=%llx.\n", cnt, |
| 1083 | (unsigned long long)vid.port_name, |
| 1084 | (unsigned long long)vid.node_name); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1085 | } |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 1086 | } |
| 1087 | done: |
| 1088 | kfree(data); |
| 1089 | } |
| 1090 | |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1091 | static int |
| 1092 | qla24xx_unprotect_flash(scsi_qla_host_t *vha) |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 1093 | { |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1094 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 1095 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1096 | |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1097 | if (ha->flags.fac_supported) |
| 1098 | return qla81xx_fac_do_write_enable(vha, 1); |
| 1099 | |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 1100 | /* Enable flash write. */ |
| 1101 | WRT_REG_DWORD(®->ctrl_status, |
| 1102 | RD_REG_DWORD(®->ctrl_status) | CSRX_FLASH_ENABLE); |
| 1103 | RD_REG_DWORD(®->ctrl_status); /* PCI Posting. */ |
| 1104 | |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 1105 | if (!ha->fdt_wrt_disable) |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1106 | goto done; |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 1107 | |
Joe Carnuccio | b872ca4 | 2009-01-22 09:45:36 -0800 | [diff] [blame] | 1108 | /* Disable flash write-protection, first clear SR protection bit */ |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1109 | qla24xx_write_flash_dword(ha, flash_conf_addr(ha, 0x101), 0); |
Joe Carnuccio | b872ca4 | 2009-01-22 09:45:36 -0800 | [diff] [blame] | 1110 | /* Then write zero again to clear remaining SR bits.*/ |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1111 | qla24xx_write_flash_dword(ha, flash_conf_addr(ha, 0x101), 0); |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1112 | done: |
| 1113 | return QLA_SUCCESS; |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1116 | static int |
| 1117 | qla24xx_protect_flash(scsi_qla_host_t *vha) |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 1118 | { |
| 1119 | uint32_t cnt; |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1120 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 1121 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1122 | |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1123 | if (ha->flags.fac_supported) |
| 1124 | return qla81xx_fac_do_write_enable(vha, 0); |
| 1125 | |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 1126 | if (!ha->fdt_wrt_disable) |
| 1127 | goto skip_wrt_protect; |
| 1128 | |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 1129 | /* Enable flash write-protection and wait for completion. */ |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1130 | qla24xx_write_flash_dword(ha, flash_conf_addr(ha, 0x101), |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 1131 | ha->fdt_wrt_disable); |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 1132 | for (cnt = 300; cnt && |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1133 | qla24xx_read_flash_dword(ha, flash_conf_addr(ha, 0x005)) & BIT_0; |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 1134 | cnt--) { |
| 1135 | udelay(10); |
| 1136 | } |
| 1137 | |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 1138 | skip_wrt_protect: |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 1139 | /* Disable flash write. */ |
| 1140 | WRT_REG_DWORD(®->ctrl_status, |
| 1141 | RD_REG_DWORD(®->ctrl_status) & ~CSRX_FLASH_ENABLE); |
| 1142 | RD_REG_DWORD(®->ctrl_status); /* PCI Posting. */ |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1143 | |
| 1144 | return QLA_SUCCESS; |
| 1145 | } |
| 1146 | |
| 1147 | static int |
| 1148 | qla24xx_erase_sector(scsi_qla_host_t *vha, uint32_t fdata) |
| 1149 | { |
| 1150 | struct qla_hw_data *ha = vha->hw; |
| 1151 | uint32_t start, finish; |
| 1152 | |
| 1153 | if (ha->flags.fac_supported) { |
| 1154 | start = fdata >> 2; |
| 1155 | finish = start + (ha->fdt_block_size >> 2) - 1; |
| 1156 | return qla81xx_fac_erase_sector(vha, flash_data_addr(ha, |
| 1157 | start), flash_data_addr(ha, finish)); |
| 1158 | } |
| 1159 | |
| 1160 | return qla24xx_write_flash_dword(ha, ha->fdt_erase_cmd, |
| 1161 | (fdata & 0xff00) | ((fdata << 16) & 0xff0000) | |
| 1162 | ((fdata >> 16) & 0xff)); |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 1163 | } |
| 1164 | |
Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 1165 | static int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1166 | qla24xx_write_flash_data(scsi_qla_host_t *vha, uint32_t *dwptr, uint32_t faddr, |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1167 | uint32_t dwords) |
| 1168 | { |
| 1169 | int ret; |
Andrew Vasquez | 7c28317 | 2009-01-22 09:45:34 -0800 | [diff] [blame] | 1170 | uint32_t liter; |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 1171 | uint32_t sec_mask, rest_addr; |
Andrew Vasquez | 85d0acb | 2009-01-22 09:45:29 -0800 | [diff] [blame] | 1172 | uint32_t fdata; |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1173 | dma_addr_t optrom_dma; |
| 1174 | void *optrom = NULL; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1175 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1176 | |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1177 | /* Prepare burst-capable write on supported ISPs. */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1178 | if ((IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha)) && |
| 1179 | !(faddr & 0xfff) && dwords > OPTROM_BURST_DWORDS) { |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1180 | optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE, |
| 1181 | &optrom_dma, GFP_KERNEL); |
| 1182 | if (!optrom) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1183 | ql_log(ql_log_warn, vha, 0x7095, |
| 1184 | "Unable to allocate " |
| 1185 | "memory for optrom burst write (%x KB).\n", |
| 1186 | OPTROM_BURST_SIZE / 1024); |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1187 | } |
| 1188 | } |
| 1189 | |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 1190 | rest_addr = (ha->fdt_block_size >> 2) - 1; |
Andrew Vasquez | 85d0acb | 2009-01-22 09:45:29 -0800 | [diff] [blame] | 1191 | sec_mask = ~rest_addr; |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1192 | |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1193 | ret = qla24xx_unprotect_flash(vha); |
| 1194 | if (ret != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1195 | ql_log(ql_log_warn, vha, 0x7096, |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1196 | "Unable to unprotect flash for update.\n"); |
| 1197 | goto done; |
| 1198 | } |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1199 | |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1200 | for (liter = 0; liter < dwords; liter++, faddr++, dwptr++) { |
Andrew Vasquez | 85d0acb | 2009-01-22 09:45:29 -0800 | [diff] [blame] | 1201 | fdata = (faddr & sec_mask) << 2; |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 1202 | |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1203 | /* Are we at the beginning of a sector? */ |
Andrew Vasquez | 85d0acb | 2009-01-22 09:45:29 -0800 | [diff] [blame] | 1204 | if ((faddr & rest_addr) == 0) { |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 1205 | /* Do sector unprotect. */ |
| 1206 | if (ha->fdt_unprotect_sec_cmd) |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 1207 | qla24xx_write_flash_dword(ha, |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 1208 | ha->fdt_unprotect_sec_cmd, |
Ravi Anand | 45aeaf1 | 2006-05-17 15:08:49 -0700 | [diff] [blame] | 1209 | (fdata & 0xff00) | ((fdata << 16) & |
| 1210 | 0xff0000) | ((fdata >> 16) & 0xff)); |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1211 | ret = qla24xx_erase_sector(vha, fdata); |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1212 | if (ret != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1213 | ql_dbg(ql_dbg_user, vha, 0x7007, |
| 1214 | "Unable to erase erase sector: address=%x.\n", |
| 1215 | faddr); |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1216 | break; |
| 1217 | } |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1218 | } |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1219 | |
| 1220 | /* Go with burst-write. */ |
Andrew Vasquez | 94d6a2b | 2007-10-19 15:59:16 -0700 | [diff] [blame] | 1221 | if (optrom && (liter + OPTROM_BURST_DWORDS) <= dwords) { |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1222 | /* Copy data to DMA'ble buffer. */ |
Andrew Vasquez | 7c28317 | 2009-01-22 09:45:34 -0800 | [diff] [blame] | 1223 | memcpy(optrom, dwptr, OPTROM_BURST_SIZE); |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1224 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1225 | ret = qla2x00_load_ram(vha, optrom_dma, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1226 | flash_data_addr(ha, faddr), |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1227 | OPTROM_BURST_DWORDS); |
| 1228 | if (ret != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1229 | ql_log(ql_log_warn, vha, 0x7097, |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1230 | "Unable to burst-write optrom segment " |
| 1231 | "(%x/%x/%llx).\n", ret, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1232 | flash_data_addr(ha, faddr), |
Andrew Morton | 875baf3 | 2007-10-16 14:28:20 -0700 | [diff] [blame] | 1233 | (unsigned long long)optrom_dma); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1234 | ql_log(ql_log_warn, vha, 0x7098, |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1235 | "Reverting to slow-write.\n"); |
| 1236 | |
| 1237 | dma_free_coherent(&ha->pdev->dev, |
| 1238 | OPTROM_BURST_SIZE, optrom, optrom_dma); |
| 1239 | optrom = NULL; |
| 1240 | } else { |
| 1241 | liter += OPTROM_BURST_DWORDS - 1; |
| 1242 | faddr += OPTROM_BURST_DWORDS - 1; |
| 1243 | dwptr += OPTROM_BURST_DWORDS - 1; |
| 1244 | continue; |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | ret = qla24xx_write_flash_dword(ha, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1249 | flash_data_addr(ha, faddr), cpu_to_le32(*dwptr)); |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1250 | if (ret != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1251 | ql_dbg(ql_dbg_user, vha, 0x7006, |
| 1252 | "Unable to program flash address=%x data=%x.\n", |
| 1253 | faddr, *dwptr); |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1254 | break; |
| 1255 | } |
| 1256 | |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 1257 | /* Do sector protect. */ |
| 1258 | if (ha->fdt_unprotect_sec_cmd && |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1259 | ((faddr & rest_addr) == rest_addr)) |
| 1260 | qla24xx_write_flash_dword(ha, |
Andrew Vasquez | 7d232c7 | 2008-04-03 13:13:22 -0700 | [diff] [blame] | 1261 | ha->fdt_protect_sec_cmd, |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1262 | (fdata & 0xff00) | ((fdata << 16) & |
| 1263 | 0xff0000) | ((fdata >> 16) & 0xff)); |
| 1264 | } |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1265 | |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1266 | ret = qla24xx_protect_flash(vha); |
| 1267 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1268 | ql_log(ql_log_warn, vha, 0x7099, |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1269 | "Unable to protect flash after update.\n"); |
| 1270 | done: |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1271 | if (optrom) |
| 1272 | dma_free_coherent(&ha->pdev->dev, |
| 1273 | OPTROM_BURST_SIZE, optrom, optrom_dma); |
| 1274 | |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1275 | return ret; |
| 1276 | } |
| 1277 | |
| 1278 | uint8_t * |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1279 | qla2x00_read_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr, |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1280 | uint32_t bytes) |
| 1281 | { |
| 1282 | uint32_t i; |
| 1283 | uint16_t *wptr; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1284 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1285 | |
| 1286 | /* Word reads to NVRAM via registers. */ |
| 1287 | wptr = (uint16_t *)buf; |
| 1288 | qla2x00_lock_nvram_access(ha); |
| 1289 | for (i = 0; i < bytes >> 1; i++, naddr++) |
| 1290 | wptr[i] = cpu_to_le16(qla2x00_get_nvram_word(ha, |
| 1291 | naddr)); |
| 1292 | qla2x00_unlock_nvram_access(ha); |
| 1293 | |
| 1294 | return buf; |
| 1295 | } |
| 1296 | |
| 1297 | uint8_t * |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1298 | qla24xx_read_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr, |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1299 | uint32_t bytes) |
| 1300 | { |
| 1301 | uint32_t i; |
| 1302 | uint32_t *dwptr; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1303 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1304 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1305 | if (IS_QLA82XX(ha)) |
| 1306 | return buf; |
| 1307 | |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1308 | /* Dword reads to flash. */ |
| 1309 | dwptr = (uint32_t *)buf; |
| 1310 | for (i = 0; i < bytes >> 2; i++, naddr++) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1311 | dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha, |
| 1312 | nvram_data_addr(ha, naddr))); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1313 | |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1314 | return buf; |
| 1315 | } |
| 1316 | |
| 1317 | int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1318 | qla2x00_write_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr, |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1319 | uint32_t bytes) |
| 1320 | { |
| 1321 | int ret, stat; |
| 1322 | uint32_t i; |
| 1323 | uint16_t *wptr; |
Andrew Vasquez | 2c96d8d | 2007-10-19 15:59:15 -0700 | [diff] [blame] | 1324 | unsigned long flags; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1325 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1326 | |
| 1327 | ret = QLA_SUCCESS; |
| 1328 | |
Andrew Vasquez | 2c96d8d | 2007-10-19 15:59:15 -0700 | [diff] [blame] | 1329 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1330 | qla2x00_lock_nvram_access(ha); |
| 1331 | |
| 1332 | /* Disable NVRAM write-protection. */ |
| 1333 | stat = qla2x00_clear_nvram_protection(ha); |
| 1334 | |
| 1335 | wptr = (uint16_t *)buf; |
| 1336 | for (i = 0; i < bytes >> 1; i++, naddr++) { |
| 1337 | qla2x00_write_nvram_word(ha, naddr, |
| 1338 | cpu_to_le16(*wptr)); |
| 1339 | wptr++; |
| 1340 | } |
| 1341 | |
| 1342 | /* Enable NVRAM write-protection. */ |
| 1343 | qla2x00_set_nvram_protection(ha, stat); |
| 1344 | |
| 1345 | qla2x00_unlock_nvram_access(ha); |
Andrew Vasquez | 2c96d8d | 2007-10-19 15:59:15 -0700 | [diff] [blame] | 1346 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1347 | |
| 1348 | return ret; |
| 1349 | } |
| 1350 | |
| 1351 | int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1352 | qla24xx_write_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr, |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1353 | uint32_t bytes) |
| 1354 | { |
| 1355 | int ret; |
| 1356 | uint32_t i; |
| 1357 | uint32_t *dwptr; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1358 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1359 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1360 | |
| 1361 | ret = QLA_SUCCESS; |
| 1362 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1363 | if (IS_QLA82XX(ha)) |
| 1364 | return ret; |
| 1365 | |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1366 | /* Enable flash write. */ |
| 1367 | WRT_REG_DWORD(®->ctrl_status, |
| 1368 | RD_REG_DWORD(®->ctrl_status) | CSRX_FLASH_ENABLE); |
| 1369 | RD_REG_DWORD(®->ctrl_status); /* PCI Posting. */ |
| 1370 | |
| 1371 | /* Disable NVRAM write-protection. */ |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1372 | qla24xx_write_flash_dword(ha, nvram_conf_addr(ha, 0x101), 0); |
| 1373 | qla24xx_write_flash_dword(ha, nvram_conf_addr(ha, 0x101), 0); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1374 | |
| 1375 | /* Dword writes to flash. */ |
| 1376 | dwptr = (uint32_t *)buf; |
| 1377 | for (i = 0; i < bytes >> 2; i++, naddr++, dwptr++) { |
| 1378 | ret = qla24xx_write_flash_dword(ha, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1379 | nvram_data_addr(ha, naddr), cpu_to_le32(*dwptr)); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1380 | if (ret != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1381 | ql_dbg(ql_dbg_user, vha, 0x709a, |
Andrew Vasquez | 7640335 | 2009-04-06 22:33:39 -0700 | [diff] [blame] | 1382 | "Unable to program nvram address=%x data=%x.\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1383 | naddr, *dwptr); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1384 | break; |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | /* Enable NVRAM write-protection. */ |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1389 | qla24xx_write_flash_dword(ha, nvram_conf_addr(ha, 0x101), 0x8c); |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1390 | |
| 1391 | /* Disable flash write. */ |
| 1392 | WRT_REG_DWORD(®->ctrl_status, |
| 1393 | RD_REG_DWORD(®->ctrl_status) & ~CSRX_FLASH_ENABLE); |
| 1394 | RD_REG_DWORD(®->ctrl_status); /* PCI Posting. */ |
| 1395 | |
Andrew Vasquez | 459c537 | 2005-07-06 10:31:07 -0700 | [diff] [blame] | 1396 | return ret; |
| 1397 | } |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1398 | |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1399 | uint8_t * |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1400 | qla25xx_read_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr, |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1401 | uint32_t bytes) |
| 1402 | { |
| 1403 | uint32_t i; |
| 1404 | uint32_t *dwptr; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1405 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1406 | |
| 1407 | /* Dword reads to flash. */ |
| 1408 | dwptr = (uint32_t *)buf; |
| 1409 | for (i = 0; i < bytes >> 2; i++, naddr++) |
| 1410 | dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1411 | flash_data_addr(ha, ha->flt_region_vpd_nvram | naddr))); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1412 | |
| 1413 | return buf; |
| 1414 | } |
| 1415 | |
| 1416 | int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1417 | qla25xx_write_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr, |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1418 | uint32_t bytes) |
| 1419 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1420 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 2c96d8d | 2007-10-19 15:59:15 -0700 | [diff] [blame] | 1421 | #define RMW_BUFFER_SIZE (64 * 1024) |
| 1422 | uint8_t *dbuf; |
| 1423 | |
| 1424 | dbuf = vmalloc(RMW_BUFFER_SIZE); |
| 1425 | if (!dbuf) |
| 1426 | return QLA_MEMORY_ALLOC_FAILED; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1427 | ha->isp_ops->read_optrom(vha, dbuf, ha->flt_region_vpd_nvram << 2, |
Andrew Vasquez | 2c96d8d | 2007-10-19 15:59:15 -0700 | [diff] [blame] | 1428 | RMW_BUFFER_SIZE); |
| 1429 | memcpy(dbuf + (naddr << 2), buf, bytes); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1430 | ha->isp_ops->write_optrom(vha, dbuf, ha->flt_region_vpd_nvram << 2, |
Andrew Vasquez | 2c96d8d | 2007-10-19 15:59:15 -0700 | [diff] [blame] | 1431 | RMW_BUFFER_SIZE); |
| 1432 | vfree(dbuf); |
| 1433 | |
| 1434 | return QLA_SUCCESS; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1435 | } |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1436 | |
| 1437 | static inline void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1438 | qla2x00_flip_colors(struct qla_hw_data *ha, uint16_t *pflags) |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1439 | { |
| 1440 | if (IS_QLA2322(ha)) { |
| 1441 | /* Flip all colors. */ |
| 1442 | if (ha->beacon_color_state == QLA_LED_ALL_ON) { |
| 1443 | /* Turn off. */ |
| 1444 | ha->beacon_color_state = 0; |
| 1445 | *pflags = GPIO_LED_ALL_OFF; |
| 1446 | } else { |
| 1447 | /* Turn on. */ |
| 1448 | ha->beacon_color_state = QLA_LED_ALL_ON; |
| 1449 | *pflags = GPIO_LED_RGA_ON; |
| 1450 | } |
| 1451 | } else { |
| 1452 | /* Flip green led only. */ |
| 1453 | if (ha->beacon_color_state == QLA_LED_GRN_ON) { |
| 1454 | /* Turn off. */ |
| 1455 | ha->beacon_color_state = 0; |
| 1456 | *pflags = GPIO_LED_GREEN_OFF_AMBER_OFF; |
| 1457 | } else { |
| 1458 | /* Turn on. */ |
| 1459 | ha->beacon_color_state = QLA_LED_GRN_ON; |
| 1460 | *pflags = GPIO_LED_GREEN_ON_AMBER_OFF; |
| 1461 | } |
| 1462 | } |
| 1463 | } |
| 1464 | |
Andrew Vasquez | 948882f | 2008-01-31 12:33:44 -0800 | [diff] [blame] | 1465 | #define PIO_REG(h, r) ((h)->pio_address + offsetof(struct device_reg_2xxx, r)) |
| 1466 | |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1467 | void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1468 | qla2x00_beacon_blink(struct scsi_qla_host *vha) |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1469 | { |
| 1470 | uint16_t gpio_enable; |
| 1471 | uint16_t gpio_data; |
| 1472 | uint16_t led_color = 0; |
| 1473 | unsigned long flags; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1474 | struct qla_hw_data *ha = vha->hw; |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1475 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 1476 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1477 | if (IS_QLA82XX(ha)) |
| 1478 | return; |
| 1479 | |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1480 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1481 | |
| 1482 | /* Save the Original GPIOE. */ |
| 1483 | if (ha->pio_address) { |
Andrew Vasquez | 948882f | 2008-01-31 12:33:44 -0800 | [diff] [blame] | 1484 | gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe)); |
| 1485 | gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod)); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1486 | } else { |
| 1487 | gpio_enable = RD_REG_WORD(®->gpioe); |
| 1488 | gpio_data = RD_REG_WORD(®->gpiod); |
| 1489 | } |
| 1490 | |
| 1491 | /* Set the modified gpio_enable values */ |
| 1492 | gpio_enable |= GPIO_LED_MASK; |
| 1493 | |
| 1494 | if (ha->pio_address) { |
Andrew Vasquez | 948882f | 2008-01-31 12:33:44 -0800 | [diff] [blame] | 1495 | WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1496 | } else { |
| 1497 | WRT_REG_WORD(®->gpioe, gpio_enable); |
| 1498 | RD_REG_WORD(®->gpioe); |
| 1499 | } |
| 1500 | |
| 1501 | qla2x00_flip_colors(ha, &led_color); |
| 1502 | |
| 1503 | /* Clear out any previously set LED color. */ |
| 1504 | gpio_data &= ~GPIO_LED_MASK; |
| 1505 | |
| 1506 | /* Set the new input LED color to GPIOD. */ |
| 1507 | gpio_data |= led_color; |
| 1508 | |
| 1509 | /* Set the modified gpio_data values */ |
| 1510 | if (ha->pio_address) { |
Andrew Vasquez | 948882f | 2008-01-31 12:33:44 -0800 | [diff] [blame] | 1511 | WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1512 | } else { |
| 1513 | WRT_REG_WORD(®->gpiod, gpio_data); |
| 1514 | RD_REG_WORD(®->gpiod); |
| 1515 | } |
| 1516 | |
| 1517 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1518 | } |
| 1519 | |
| 1520 | int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1521 | qla2x00_beacon_on(struct scsi_qla_host *vha) |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1522 | { |
| 1523 | uint16_t gpio_enable; |
| 1524 | uint16_t gpio_data; |
| 1525 | unsigned long flags; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1526 | struct qla_hw_data *ha = vha->hw; |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1527 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 1528 | |
| 1529 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 1530 | ha->fw_options[1] |= FO1_DISABLE_GPIO6_7; |
| 1531 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1532 | if (qla2x00_set_fw_options(vha, ha->fw_options) != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1533 | ql_log(ql_log_warn, vha, 0x709b, |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1534 | "Unable to update fw options (beacon on).\n"); |
| 1535 | return QLA_FUNCTION_FAILED; |
| 1536 | } |
| 1537 | |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1538 | /* Turn off LEDs. */ |
| 1539 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1540 | if (ha->pio_address) { |
Andrew Vasquez | 948882f | 2008-01-31 12:33:44 -0800 | [diff] [blame] | 1541 | gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe)); |
| 1542 | gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod)); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1543 | } else { |
| 1544 | gpio_enable = RD_REG_WORD(®->gpioe); |
| 1545 | gpio_data = RD_REG_WORD(®->gpiod); |
| 1546 | } |
| 1547 | gpio_enable |= GPIO_LED_MASK; |
| 1548 | |
| 1549 | /* Set the modified gpio_enable values. */ |
| 1550 | if (ha->pio_address) { |
Andrew Vasquez | 948882f | 2008-01-31 12:33:44 -0800 | [diff] [blame] | 1551 | WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1552 | } else { |
| 1553 | WRT_REG_WORD(®->gpioe, gpio_enable); |
| 1554 | RD_REG_WORD(®->gpioe); |
| 1555 | } |
| 1556 | |
| 1557 | /* Clear out previously set LED colour. */ |
| 1558 | gpio_data &= ~GPIO_LED_MASK; |
| 1559 | if (ha->pio_address) { |
Andrew Vasquez | 948882f | 2008-01-31 12:33:44 -0800 | [diff] [blame] | 1560 | WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1561 | } else { |
| 1562 | WRT_REG_WORD(®->gpiod, gpio_data); |
| 1563 | RD_REG_WORD(®->gpiod); |
| 1564 | } |
| 1565 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1566 | |
| 1567 | /* |
| 1568 | * Let the per HBA timer kick off the blinking process based on |
| 1569 | * the following flags. No need to do anything else now. |
| 1570 | */ |
| 1571 | ha->beacon_blink_led = 1; |
| 1572 | ha->beacon_color_state = 0; |
| 1573 | |
| 1574 | return QLA_SUCCESS; |
| 1575 | } |
| 1576 | |
| 1577 | int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1578 | qla2x00_beacon_off(struct scsi_qla_host *vha) |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1579 | { |
| 1580 | int rval = QLA_SUCCESS; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1581 | struct qla_hw_data *ha = vha->hw; |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1582 | |
| 1583 | ha->beacon_blink_led = 0; |
| 1584 | |
| 1585 | /* Set the on flag so when it gets flipped it will be off. */ |
| 1586 | if (IS_QLA2322(ha)) |
| 1587 | ha->beacon_color_state = QLA_LED_ALL_ON; |
| 1588 | else |
| 1589 | ha->beacon_color_state = QLA_LED_GRN_ON; |
| 1590 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1591 | ha->isp_ops->beacon_blink(vha); /* This turns green LED off */ |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1592 | |
| 1593 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 1594 | ha->fw_options[1] &= ~FO1_DISABLE_GPIO6_7; |
| 1595 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1596 | rval = qla2x00_set_fw_options(vha, ha->fw_options); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1597 | if (rval != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1598 | ql_log(ql_log_warn, vha, 0x709c, |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1599 | "Unable to update fw options (beacon off).\n"); |
| 1600 | return rval; |
| 1601 | } |
| 1602 | |
| 1603 | |
| 1604 | static inline void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1605 | qla24xx_flip_colors(struct qla_hw_data *ha, uint16_t *pflags) |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1606 | { |
| 1607 | /* Flip all colors. */ |
| 1608 | if (ha->beacon_color_state == QLA_LED_ALL_ON) { |
| 1609 | /* Turn off. */ |
| 1610 | ha->beacon_color_state = 0; |
| 1611 | *pflags = 0; |
| 1612 | } else { |
| 1613 | /* Turn on. */ |
| 1614 | ha->beacon_color_state = QLA_LED_ALL_ON; |
| 1615 | *pflags = GPDX_LED_YELLOW_ON | GPDX_LED_AMBER_ON; |
| 1616 | } |
| 1617 | } |
| 1618 | |
| 1619 | void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1620 | qla24xx_beacon_blink(struct scsi_qla_host *vha) |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1621 | { |
| 1622 | uint16_t led_color = 0; |
| 1623 | uint32_t gpio_data; |
| 1624 | unsigned long flags; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1625 | struct qla_hw_data *ha = vha->hw; |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1626 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1627 | |
| 1628 | /* Save the Original GPIOD. */ |
| 1629 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1630 | gpio_data = RD_REG_DWORD(®->gpiod); |
| 1631 | |
| 1632 | /* Enable the gpio_data reg for update. */ |
| 1633 | gpio_data |= GPDX_LED_UPDATE_MASK; |
| 1634 | |
| 1635 | WRT_REG_DWORD(®->gpiod, gpio_data); |
| 1636 | gpio_data = RD_REG_DWORD(®->gpiod); |
| 1637 | |
| 1638 | /* Set the color bits. */ |
| 1639 | qla24xx_flip_colors(ha, &led_color); |
| 1640 | |
| 1641 | /* Clear out any previously set LED color. */ |
| 1642 | gpio_data &= ~GPDX_LED_COLOR_MASK; |
| 1643 | |
| 1644 | /* Set the new input LED color to GPIOD. */ |
| 1645 | gpio_data |= led_color; |
| 1646 | |
| 1647 | /* Set the modified gpio_data values. */ |
| 1648 | WRT_REG_DWORD(®->gpiod, gpio_data); |
| 1649 | gpio_data = RD_REG_DWORD(®->gpiod); |
| 1650 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1651 | } |
| 1652 | |
Chad Dupuis | 0143d8b7 | 2012-08-22 14:21:11 -0400 | [diff] [blame] | 1653 | static uint32_t |
| 1654 | qla83xx_select_led_port(struct qla_hw_data *ha) |
| 1655 | { |
| 1656 | uint32_t led_select_value = 0; |
| 1657 | |
| 1658 | if (!IS_QLA83XX(ha)) |
| 1659 | goto out; |
| 1660 | |
| 1661 | if (ha->flags.port0) |
| 1662 | led_select_value = QLA83XX_LED_PORT0; |
| 1663 | else |
| 1664 | led_select_value = QLA83XX_LED_PORT1; |
| 1665 | |
| 1666 | out: |
| 1667 | return led_select_value; |
| 1668 | } |
| 1669 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1670 | void |
| 1671 | qla83xx_beacon_blink(struct scsi_qla_host *vha) |
| 1672 | { |
| 1673 | uint32_t led_select_value; |
| 1674 | struct qla_hw_data *ha = vha->hw; |
| 1675 | uint16_t led_cfg[6]; |
| 1676 | uint16_t orig_led_cfg[6]; |
Chad Dupuis | 0143d8b7 | 2012-08-22 14:21:11 -0400 | [diff] [blame] | 1677 | uint32_t led_10_value, led_43_value; |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1678 | |
| 1679 | if (!IS_QLA83XX(ha) && !IS_QLA81XX(ha)) |
| 1680 | return; |
| 1681 | |
Chad Dupuis | 0143d8b7 | 2012-08-22 14:21:11 -0400 | [diff] [blame] | 1682 | if (!ha->beacon_blink_led) |
| 1683 | return; |
| 1684 | |
| 1685 | if (IS_QLA2031(ha)) { |
| 1686 | led_select_value = qla83xx_select_led_port(ha); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1687 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1688 | qla83xx_wr_reg(vha, led_select_value, 0x40002000); |
| 1689 | qla83xx_wr_reg(vha, led_select_value + 4, 0x40002000); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1690 | msleep(1000); |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1691 | qla83xx_wr_reg(vha, led_select_value, 0x40004000); |
| 1692 | qla83xx_wr_reg(vha, led_select_value + 4, 0x40004000); |
Chad Dupuis | 0143d8b7 | 2012-08-22 14:21:11 -0400 | [diff] [blame] | 1693 | } else if (IS_QLA8031(ha)) { |
| 1694 | led_select_value = qla83xx_select_led_port(ha); |
| 1695 | |
| 1696 | qla83xx_rd_reg(vha, led_select_value, &led_10_value); |
| 1697 | qla83xx_rd_reg(vha, led_select_value + 0x10, &led_43_value); |
| 1698 | qla83xx_wr_reg(vha, led_select_value, 0x01f44000); |
| 1699 | msleep(500); |
| 1700 | qla83xx_wr_reg(vha, led_select_value, 0x400001f4); |
| 1701 | msleep(1000); |
| 1702 | qla83xx_wr_reg(vha, led_select_value, led_10_value); |
| 1703 | qla83xx_wr_reg(vha, led_select_value + 0x10, led_43_value); |
| 1704 | } else if (IS_QLA81XX(ha)) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1705 | int rval; |
| 1706 | |
| 1707 | /* Save Current */ |
| 1708 | rval = qla81xx_get_led_config(vha, orig_led_cfg); |
| 1709 | /* Do the blink */ |
| 1710 | if (rval == QLA_SUCCESS) { |
| 1711 | if (IS_QLA81XX(ha)) { |
| 1712 | led_cfg[0] = 0x4000; |
| 1713 | led_cfg[1] = 0x2000; |
| 1714 | led_cfg[2] = 0; |
| 1715 | led_cfg[3] = 0; |
| 1716 | led_cfg[4] = 0; |
| 1717 | led_cfg[5] = 0; |
| 1718 | } else { |
| 1719 | led_cfg[0] = 0x4000; |
| 1720 | led_cfg[1] = 0x4000; |
| 1721 | led_cfg[2] = 0x4000; |
| 1722 | led_cfg[3] = 0x2000; |
| 1723 | led_cfg[4] = 0; |
| 1724 | led_cfg[5] = 0x2000; |
| 1725 | } |
| 1726 | rval = qla81xx_set_led_config(vha, led_cfg); |
| 1727 | msleep(1000); |
| 1728 | if (IS_QLA81XX(ha)) { |
| 1729 | led_cfg[0] = 0x4000; |
| 1730 | led_cfg[1] = 0x2000; |
| 1731 | led_cfg[2] = 0; |
| 1732 | } else { |
| 1733 | led_cfg[0] = 0x4000; |
| 1734 | led_cfg[1] = 0x2000; |
| 1735 | led_cfg[2] = 0x4000; |
| 1736 | led_cfg[3] = 0x4000; |
| 1737 | led_cfg[4] = 0; |
| 1738 | led_cfg[5] = 0x2000; |
| 1739 | } |
| 1740 | rval = qla81xx_set_led_config(vha, led_cfg); |
| 1741 | } |
| 1742 | /* On exit, restore original (presumes no status change) */ |
| 1743 | qla81xx_set_led_config(vha, orig_led_cfg); |
| 1744 | } |
| 1745 | } |
| 1746 | |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1747 | int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1748 | qla24xx_beacon_on(struct scsi_qla_host *vha) |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1749 | { |
| 1750 | uint32_t gpio_data; |
| 1751 | unsigned long flags; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1752 | struct qla_hw_data *ha = vha->hw; |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1753 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1754 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1755 | if (IS_QLA82XX(ha)) |
| 1756 | return QLA_SUCCESS; |
| 1757 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1758 | if (IS_QLA8031(ha) || IS_QLA81XX(ha)) |
| 1759 | goto skip_gpio; /* let blink handle it */ |
| 1760 | |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1761 | if (ha->beacon_blink_led == 0) { |
| 1762 | /* Enable firmware for update */ |
| 1763 | ha->fw_options[1] |= ADD_FO1_DISABLE_GPIO_LED_CTRL; |
| 1764 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1765 | if (qla2x00_set_fw_options(vha, ha->fw_options) != QLA_SUCCESS) |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1766 | return QLA_FUNCTION_FAILED; |
| 1767 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1768 | if (qla2x00_get_fw_options(vha, ha->fw_options) != |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1769 | QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1770 | ql_log(ql_log_warn, vha, 0x7009, |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1771 | "Unable to update fw options (beacon on).\n"); |
| 1772 | return QLA_FUNCTION_FAILED; |
| 1773 | } |
| 1774 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1775 | if (IS_QLA2031(ha)) |
| 1776 | goto skip_gpio; |
| 1777 | |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1778 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1779 | gpio_data = RD_REG_DWORD(®->gpiod); |
| 1780 | |
| 1781 | /* Enable the gpio_data reg for update. */ |
| 1782 | gpio_data |= GPDX_LED_UPDATE_MASK; |
| 1783 | WRT_REG_DWORD(®->gpiod, gpio_data); |
| 1784 | RD_REG_DWORD(®->gpiod); |
| 1785 | |
| 1786 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1787 | } |
| 1788 | |
| 1789 | /* So all colors blink together. */ |
| 1790 | ha->beacon_color_state = 0; |
| 1791 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1792 | skip_gpio: |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1793 | /* Let the per HBA timer kick off the blinking process. */ |
| 1794 | ha->beacon_blink_led = 1; |
| 1795 | |
| 1796 | return QLA_SUCCESS; |
| 1797 | } |
| 1798 | |
| 1799 | int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1800 | qla24xx_beacon_off(struct scsi_qla_host *vha) |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1801 | { |
| 1802 | uint32_t gpio_data; |
| 1803 | unsigned long flags; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1804 | struct qla_hw_data *ha = vha->hw; |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1805 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1806 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1807 | if (IS_QLA82XX(ha)) |
| 1808 | return QLA_SUCCESS; |
| 1809 | |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1810 | ha->beacon_blink_led = 0; |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1811 | |
| 1812 | if (IS_QLA2031(ha)) |
| 1813 | goto set_fw_options; |
| 1814 | |
| 1815 | if (IS_QLA8031(ha) || IS_QLA81XX(ha)) |
| 1816 | return QLA_SUCCESS; |
| 1817 | |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1818 | ha->beacon_color_state = QLA_LED_ALL_ON; |
| 1819 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1820 | ha->isp_ops->beacon_blink(vha); /* Will flip to all off. */ |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1821 | |
| 1822 | /* Give control back to firmware. */ |
| 1823 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1824 | gpio_data = RD_REG_DWORD(®->gpiod); |
| 1825 | |
| 1826 | /* Disable the gpio_data reg for update. */ |
| 1827 | gpio_data &= ~GPDX_LED_UPDATE_MASK; |
| 1828 | WRT_REG_DWORD(®->gpiod, gpio_data); |
| 1829 | RD_REG_DWORD(®->gpiod); |
| 1830 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1831 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1832 | set_fw_options: |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1833 | ha->fw_options[1] &= ~ADD_FO1_DISABLE_GPIO_LED_CTRL; |
| 1834 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1835 | if (qla2x00_set_fw_options(vha, ha->fw_options) != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1836 | ql_log(ql_log_warn, vha, 0x704d, |
| 1837 | "Unable to update fw options (beacon on).\n"); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1838 | return QLA_FUNCTION_FAILED; |
| 1839 | } |
| 1840 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1841 | if (qla2x00_get_fw_options(vha, ha->fw_options) != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1842 | ql_log(ql_log_warn, vha, 0x704e, |
| 1843 | "Unable to update fw options (beacon on).\n"); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 1844 | return QLA_FUNCTION_FAILED; |
| 1845 | } |
| 1846 | |
| 1847 | return QLA_SUCCESS; |
| 1848 | } |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 1849 | |
| 1850 | |
| 1851 | /* |
| 1852 | * Flash support routines |
| 1853 | */ |
| 1854 | |
| 1855 | /** |
| 1856 | * qla2x00_flash_enable() - Setup flash for reading and writing. |
| 1857 | * @ha: HA context |
| 1858 | */ |
| 1859 | static void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1860 | qla2x00_flash_enable(struct qla_hw_data *ha) |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 1861 | { |
| 1862 | uint16_t data; |
| 1863 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 1864 | |
| 1865 | data = RD_REG_WORD(®->ctrl_status); |
| 1866 | data |= CSR_FLASH_ENABLE; |
| 1867 | WRT_REG_WORD(®->ctrl_status, data); |
| 1868 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1869 | } |
| 1870 | |
| 1871 | /** |
| 1872 | * qla2x00_flash_disable() - Disable flash and allow RISC to run. |
| 1873 | * @ha: HA context |
| 1874 | */ |
| 1875 | static void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1876 | qla2x00_flash_disable(struct qla_hw_data *ha) |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 1877 | { |
| 1878 | uint16_t data; |
| 1879 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 1880 | |
| 1881 | data = RD_REG_WORD(®->ctrl_status); |
| 1882 | data &= ~(CSR_FLASH_ENABLE); |
| 1883 | WRT_REG_WORD(®->ctrl_status, data); |
| 1884 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1885 | } |
| 1886 | |
| 1887 | /** |
| 1888 | * qla2x00_read_flash_byte() - Reads a byte from flash |
| 1889 | * @ha: HA context |
| 1890 | * @addr: Address in flash to read |
| 1891 | * |
| 1892 | * A word is read from the chip, but, only the lower byte is valid. |
| 1893 | * |
| 1894 | * Returns the byte read from flash @addr. |
| 1895 | */ |
| 1896 | static uint8_t |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1897 | qla2x00_read_flash_byte(struct qla_hw_data *ha, uint32_t addr) |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 1898 | { |
| 1899 | uint16_t data; |
| 1900 | uint16_t bank_select; |
| 1901 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 1902 | |
| 1903 | bank_select = RD_REG_WORD(®->ctrl_status); |
| 1904 | |
| 1905 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) { |
| 1906 | /* Specify 64K address range: */ |
| 1907 | /* clear out Module Select and Flash Address bits [19:16]. */ |
| 1908 | bank_select &= ~0xf8; |
| 1909 | bank_select |= addr >> 12 & 0xf0; |
| 1910 | bank_select |= CSR_FLASH_64K_BANK; |
| 1911 | WRT_REG_WORD(®->ctrl_status, bank_select); |
| 1912 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1913 | |
| 1914 | WRT_REG_WORD(®->flash_address, (uint16_t)addr); |
| 1915 | data = RD_REG_WORD(®->flash_data); |
| 1916 | |
| 1917 | return (uint8_t)data; |
| 1918 | } |
| 1919 | |
| 1920 | /* Setup bit 16 of flash address. */ |
| 1921 | if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) { |
| 1922 | bank_select |= CSR_FLASH_64K_BANK; |
| 1923 | WRT_REG_WORD(®->ctrl_status, bank_select); |
| 1924 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1925 | } else if (((addr & BIT_16) == 0) && |
| 1926 | (bank_select & CSR_FLASH_64K_BANK)) { |
| 1927 | bank_select &= ~(CSR_FLASH_64K_BANK); |
| 1928 | WRT_REG_WORD(®->ctrl_status, bank_select); |
| 1929 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1930 | } |
| 1931 | |
| 1932 | /* Always perform IO mapped accesses to the FLASH registers. */ |
| 1933 | if (ha->pio_address) { |
| 1934 | uint16_t data2; |
| 1935 | |
Andrew Vasquez | 948882f | 2008-01-31 12:33:44 -0800 | [diff] [blame] | 1936 | WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 1937 | do { |
Andrew Vasquez | 948882f | 2008-01-31 12:33:44 -0800 | [diff] [blame] | 1938 | data = RD_REG_WORD_PIO(PIO_REG(ha, flash_data)); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 1939 | barrier(); |
| 1940 | cpu_relax(); |
Andrew Vasquez | 948882f | 2008-01-31 12:33:44 -0800 | [diff] [blame] | 1941 | data2 = RD_REG_WORD_PIO(PIO_REG(ha, flash_data)); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 1942 | } while (data != data2); |
| 1943 | } else { |
| 1944 | WRT_REG_WORD(®->flash_address, (uint16_t)addr); |
| 1945 | data = qla2x00_debounce_register(®->flash_data); |
| 1946 | } |
| 1947 | |
| 1948 | return (uint8_t)data; |
| 1949 | } |
| 1950 | |
| 1951 | /** |
| 1952 | * qla2x00_write_flash_byte() - Write a byte to flash |
| 1953 | * @ha: HA context |
| 1954 | * @addr: Address in flash to write |
| 1955 | * @data: Data to write |
| 1956 | */ |
| 1957 | static void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 1958 | qla2x00_write_flash_byte(struct qla_hw_data *ha, uint32_t addr, uint8_t data) |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 1959 | { |
| 1960 | uint16_t bank_select; |
| 1961 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 1962 | |
| 1963 | bank_select = RD_REG_WORD(®->ctrl_status); |
| 1964 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) { |
| 1965 | /* Specify 64K address range: */ |
| 1966 | /* clear out Module Select and Flash Address bits [19:16]. */ |
| 1967 | bank_select &= ~0xf8; |
| 1968 | bank_select |= addr >> 12 & 0xf0; |
| 1969 | bank_select |= CSR_FLASH_64K_BANK; |
| 1970 | WRT_REG_WORD(®->ctrl_status, bank_select); |
| 1971 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1972 | |
| 1973 | WRT_REG_WORD(®->flash_address, (uint16_t)addr); |
| 1974 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1975 | WRT_REG_WORD(®->flash_data, (uint16_t)data); |
| 1976 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1977 | |
| 1978 | return; |
| 1979 | } |
| 1980 | |
| 1981 | /* Setup bit 16 of flash address. */ |
| 1982 | if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) { |
| 1983 | bank_select |= CSR_FLASH_64K_BANK; |
| 1984 | WRT_REG_WORD(®->ctrl_status, bank_select); |
| 1985 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1986 | } else if (((addr & BIT_16) == 0) && |
| 1987 | (bank_select & CSR_FLASH_64K_BANK)) { |
| 1988 | bank_select &= ~(CSR_FLASH_64K_BANK); |
| 1989 | WRT_REG_WORD(®->ctrl_status, bank_select); |
| 1990 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1991 | } |
| 1992 | |
| 1993 | /* Always perform IO mapped accesses to the FLASH registers. */ |
| 1994 | if (ha->pio_address) { |
Andrew Vasquez | 948882f | 2008-01-31 12:33:44 -0800 | [diff] [blame] | 1995 | WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr); |
| 1996 | WRT_REG_WORD_PIO(PIO_REG(ha, flash_data), (uint16_t)data); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 1997 | } else { |
| 1998 | WRT_REG_WORD(®->flash_address, (uint16_t)addr); |
| 1999 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 2000 | WRT_REG_WORD(®->flash_data, (uint16_t)data); |
| 2001 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 2002 | } |
| 2003 | } |
| 2004 | |
| 2005 | /** |
| 2006 | * qla2x00_poll_flash() - Polls flash for completion. |
| 2007 | * @ha: HA context |
| 2008 | * @addr: Address in flash to poll |
| 2009 | * @poll_data: Data to be polled |
| 2010 | * @man_id: Flash manufacturer ID |
| 2011 | * @flash_id: Flash ID |
| 2012 | * |
| 2013 | * This function polls the device until bit 7 of what is read matches data |
| 2014 | * bit 7 or until data bit 5 becomes a 1. If that hapens, the flash ROM timed |
| 2015 | * out (a fatal error). The flash book recommeds reading bit 7 again after |
| 2016 | * reading bit 5 as a 1. |
| 2017 | * |
| 2018 | * Returns 0 on success, else non-zero. |
| 2019 | */ |
| 2020 | static int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2021 | qla2x00_poll_flash(struct qla_hw_data *ha, uint32_t addr, uint8_t poll_data, |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2022 | uint8_t man_id, uint8_t flash_id) |
| 2023 | { |
| 2024 | int status; |
| 2025 | uint8_t flash_data; |
| 2026 | uint32_t cnt; |
| 2027 | |
| 2028 | status = 1; |
| 2029 | |
| 2030 | /* Wait for 30 seconds for command to finish. */ |
| 2031 | poll_data &= BIT_7; |
| 2032 | for (cnt = 3000000; cnt; cnt--) { |
| 2033 | flash_data = qla2x00_read_flash_byte(ha, addr); |
| 2034 | if ((flash_data & BIT_7) == poll_data) { |
| 2035 | status = 0; |
| 2036 | break; |
| 2037 | } |
| 2038 | |
| 2039 | if (man_id != 0x40 && man_id != 0xda) { |
| 2040 | if ((flash_data & BIT_5) && cnt > 2) |
| 2041 | cnt = 2; |
| 2042 | } |
| 2043 | udelay(10); |
| 2044 | barrier(); |
Andrew Vasquez | 40a2e34 | 2007-03-12 10:41:28 -0700 | [diff] [blame] | 2045 | cond_resched(); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2046 | } |
| 2047 | return status; |
| 2048 | } |
| 2049 | |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2050 | /** |
| 2051 | * qla2x00_program_flash_address() - Programs a flash address |
| 2052 | * @ha: HA context |
| 2053 | * @addr: Address in flash to program |
| 2054 | * @data: Data to be written in flash |
| 2055 | * @man_id: Flash manufacturer ID |
| 2056 | * @flash_id: Flash ID |
| 2057 | * |
| 2058 | * Returns 0 on success, else non-zero. |
| 2059 | */ |
| 2060 | static int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2061 | qla2x00_program_flash_address(struct qla_hw_data *ha, uint32_t addr, |
| 2062 | uint8_t data, uint8_t man_id, uint8_t flash_id) |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2063 | { |
| 2064 | /* Write Program Command Sequence. */ |
| 2065 | if (IS_OEM_001(ha)) { |
| 2066 | qla2x00_write_flash_byte(ha, 0xaaa, 0xaa); |
| 2067 | qla2x00_write_flash_byte(ha, 0x555, 0x55); |
| 2068 | qla2x00_write_flash_byte(ha, 0xaaa, 0xa0); |
| 2069 | qla2x00_write_flash_byte(ha, addr, data); |
| 2070 | } else { |
| 2071 | if (man_id == 0xda && flash_id == 0xc1) { |
| 2072 | qla2x00_write_flash_byte(ha, addr, data); |
| 2073 | if (addr & 0x7e) |
| 2074 | return 0; |
| 2075 | } else { |
| 2076 | qla2x00_write_flash_byte(ha, 0x5555, 0xaa); |
| 2077 | qla2x00_write_flash_byte(ha, 0x2aaa, 0x55); |
| 2078 | qla2x00_write_flash_byte(ha, 0x5555, 0xa0); |
| 2079 | qla2x00_write_flash_byte(ha, addr, data); |
| 2080 | } |
| 2081 | } |
| 2082 | |
| 2083 | udelay(150); |
| 2084 | |
| 2085 | /* Wait for write to complete. */ |
| 2086 | return qla2x00_poll_flash(ha, addr, data, man_id, flash_id); |
| 2087 | } |
| 2088 | |
| 2089 | /** |
| 2090 | * qla2x00_erase_flash() - Erase the flash. |
| 2091 | * @ha: HA context |
| 2092 | * @man_id: Flash manufacturer ID |
| 2093 | * @flash_id: Flash ID |
| 2094 | * |
| 2095 | * Returns 0 on success, else non-zero. |
| 2096 | */ |
| 2097 | static int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2098 | qla2x00_erase_flash(struct qla_hw_data *ha, uint8_t man_id, uint8_t flash_id) |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2099 | { |
| 2100 | /* Individual Sector Erase Command Sequence */ |
| 2101 | if (IS_OEM_001(ha)) { |
| 2102 | qla2x00_write_flash_byte(ha, 0xaaa, 0xaa); |
| 2103 | qla2x00_write_flash_byte(ha, 0x555, 0x55); |
| 2104 | qla2x00_write_flash_byte(ha, 0xaaa, 0x80); |
| 2105 | qla2x00_write_flash_byte(ha, 0xaaa, 0xaa); |
| 2106 | qla2x00_write_flash_byte(ha, 0x555, 0x55); |
| 2107 | qla2x00_write_flash_byte(ha, 0xaaa, 0x10); |
| 2108 | } else { |
| 2109 | qla2x00_write_flash_byte(ha, 0x5555, 0xaa); |
| 2110 | qla2x00_write_flash_byte(ha, 0x2aaa, 0x55); |
| 2111 | qla2x00_write_flash_byte(ha, 0x5555, 0x80); |
| 2112 | qla2x00_write_flash_byte(ha, 0x5555, 0xaa); |
| 2113 | qla2x00_write_flash_byte(ha, 0x2aaa, 0x55); |
| 2114 | qla2x00_write_flash_byte(ha, 0x5555, 0x10); |
| 2115 | } |
| 2116 | |
| 2117 | udelay(150); |
| 2118 | |
| 2119 | /* Wait for erase to complete. */ |
| 2120 | return qla2x00_poll_flash(ha, 0x00, 0x80, man_id, flash_id); |
| 2121 | } |
| 2122 | |
| 2123 | /** |
| 2124 | * qla2x00_erase_flash_sector() - Erase a flash sector. |
| 2125 | * @ha: HA context |
| 2126 | * @addr: Flash sector to erase |
| 2127 | * @sec_mask: Sector address mask |
| 2128 | * @man_id: Flash manufacturer ID |
| 2129 | * @flash_id: Flash ID |
| 2130 | * |
| 2131 | * Returns 0 on success, else non-zero. |
| 2132 | */ |
| 2133 | static int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2134 | qla2x00_erase_flash_sector(struct qla_hw_data *ha, uint32_t addr, |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2135 | uint32_t sec_mask, uint8_t man_id, uint8_t flash_id) |
| 2136 | { |
| 2137 | /* Individual Sector Erase Command Sequence */ |
| 2138 | qla2x00_write_flash_byte(ha, 0x5555, 0xaa); |
| 2139 | qla2x00_write_flash_byte(ha, 0x2aaa, 0x55); |
| 2140 | qla2x00_write_flash_byte(ha, 0x5555, 0x80); |
| 2141 | qla2x00_write_flash_byte(ha, 0x5555, 0xaa); |
| 2142 | qla2x00_write_flash_byte(ha, 0x2aaa, 0x55); |
| 2143 | if (man_id == 0x1f && flash_id == 0x13) |
| 2144 | qla2x00_write_flash_byte(ha, addr & sec_mask, 0x10); |
| 2145 | else |
| 2146 | qla2x00_write_flash_byte(ha, addr & sec_mask, 0x30); |
| 2147 | |
| 2148 | udelay(150); |
| 2149 | |
| 2150 | /* Wait for erase to complete. */ |
| 2151 | return qla2x00_poll_flash(ha, addr, 0x80, man_id, flash_id); |
| 2152 | } |
| 2153 | |
| 2154 | /** |
| 2155 | * qla2x00_get_flash_manufacturer() - Read manufacturer ID from flash chip. |
| 2156 | * @man_id: Flash manufacturer ID |
| 2157 | * @flash_id: Flash ID |
| 2158 | */ |
| 2159 | static void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2160 | qla2x00_get_flash_manufacturer(struct qla_hw_data *ha, uint8_t *man_id, |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2161 | uint8_t *flash_id) |
| 2162 | { |
| 2163 | qla2x00_write_flash_byte(ha, 0x5555, 0xaa); |
| 2164 | qla2x00_write_flash_byte(ha, 0x2aaa, 0x55); |
| 2165 | qla2x00_write_flash_byte(ha, 0x5555, 0x90); |
| 2166 | *man_id = qla2x00_read_flash_byte(ha, 0x0000); |
| 2167 | *flash_id = qla2x00_read_flash_byte(ha, 0x0001); |
| 2168 | qla2x00_write_flash_byte(ha, 0x5555, 0xaa); |
| 2169 | qla2x00_write_flash_byte(ha, 0x2aaa, 0x55); |
| 2170 | qla2x00_write_flash_byte(ha, 0x5555, 0xf0); |
| 2171 | } |
| 2172 | |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2173 | static void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2174 | qla2x00_read_flash_data(struct qla_hw_data *ha, uint8_t *tmp_buf, |
| 2175 | uint32_t saddr, uint32_t length) |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2176 | { |
| 2177 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 2178 | uint32_t midpoint, ilength; |
| 2179 | uint8_t data; |
| 2180 | |
| 2181 | midpoint = length / 2; |
| 2182 | |
| 2183 | WRT_REG_WORD(®->nvram, 0); |
| 2184 | RD_REG_WORD(®->nvram); |
| 2185 | for (ilength = 0; ilength < length; saddr++, ilength++, tmp_buf++) { |
| 2186 | if (ilength == midpoint) { |
| 2187 | WRT_REG_WORD(®->nvram, NVR_SELECT); |
| 2188 | RD_REG_WORD(®->nvram); |
| 2189 | } |
| 2190 | data = qla2x00_read_flash_byte(ha, saddr); |
| 2191 | if (saddr % 100) |
| 2192 | udelay(10); |
| 2193 | *tmp_buf = data; |
Andrew Vasquez | 40a2e34 | 2007-03-12 10:41:28 -0700 | [diff] [blame] | 2194 | cond_resched(); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2195 | } |
| 2196 | } |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2197 | |
| 2198 | static inline void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2199 | qla2x00_suspend_hba(struct scsi_qla_host *vha) |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2200 | { |
| 2201 | int cnt; |
| 2202 | unsigned long flags; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2203 | struct qla_hw_data *ha = vha->hw; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2204 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 2205 | |
| 2206 | /* Suspend HBA. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2207 | scsi_block_requests(vha->host); |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2208 | ha->isp_ops->disable_intrs(ha); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2209 | set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags); |
| 2210 | |
| 2211 | /* Pause RISC. */ |
| 2212 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2213 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 2214 | RD_REG_WORD(®->hccr); |
| 2215 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2216 | for (cnt = 0; cnt < 30000; cnt++) { |
| 2217 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
| 2218 | break; |
| 2219 | udelay(100); |
| 2220 | } |
| 2221 | } else { |
| 2222 | udelay(10); |
| 2223 | } |
| 2224 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2225 | } |
| 2226 | |
| 2227 | static inline void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2228 | qla2x00_resume_hba(struct scsi_qla_host *vha) |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2229 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2230 | struct qla_hw_data *ha = vha->hw; |
| 2231 | |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2232 | /* Resume HBA. */ |
| 2233 | clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2234 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 2235 | qla2xxx_wake_dpc(vha); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 2236 | qla2x00_wait_for_chip_reset(vha); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2237 | scsi_unblock_requests(vha->host); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | uint8_t * |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2241 | qla2x00_read_optrom_data(struct scsi_qla_host *vha, uint8_t *buf, |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2242 | uint32_t offset, uint32_t length) |
| 2243 | { |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2244 | uint32_t addr, midpoint; |
| 2245 | uint8_t *data; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2246 | struct qla_hw_data *ha = vha->hw; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2247 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 2248 | |
| 2249 | /* Suspend HBA. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2250 | qla2x00_suspend_hba(vha); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2251 | |
| 2252 | /* Go with read. */ |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2253 | midpoint = ha->optrom_size / 2; |
| 2254 | |
| 2255 | qla2x00_flash_enable(ha); |
| 2256 | WRT_REG_WORD(®->nvram, 0); |
| 2257 | RD_REG_WORD(®->nvram); /* PCI Posting. */ |
| 2258 | for (addr = offset, data = buf; addr < length; addr++, data++) { |
| 2259 | if (addr == midpoint) { |
| 2260 | WRT_REG_WORD(®->nvram, NVR_SELECT); |
| 2261 | RD_REG_WORD(®->nvram); /* PCI Posting. */ |
| 2262 | } |
| 2263 | |
| 2264 | *data = qla2x00_read_flash_byte(ha, addr); |
| 2265 | } |
| 2266 | qla2x00_flash_disable(ha); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2267 | |
| 2268 | /* Resume HBA. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2269 | qla2x00_resume_hba(vha); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2270 | |
| 2271 | return buf; |
| 2272 | } |
| 2273 | |
| 2274 | int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2275 | qla2x00_write_optrom_data(struct scsi_qla_host *vha, uint8_t *buf, |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2276 | uint32_t offset, uint32_t length) |
| 2277 | { |
| 2278 | |
| 2279 | int rval; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2280 | uint8_t man_id, flash_id, sec_number, data; |
| 2281 | uint16_t wd; |
| 2282 | uint32_t addr, liter, sec_mask, rest_addr; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2283 | struct qla_hw_data *ha = vha->hw; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2284 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 2285 | |
| 2286 | /* Suspend HBA. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2287 | qla2x00_suspend_hba(vha); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2288 | |
| 2289 | rval = QLA_SUCCESS; |
| 2290 | sec_number = 0; |
| 2291 | |
| 2292 | /* Reset ISP chip. */ |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2293 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 2294 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
| 2295 | |
| 2296 | /* Go with write. */ |
| 2297 | qla2x00_flash_enable(ha); |
| 2298 | do { /* Loop once to provide quick error exit */ |
| 2299 | /* Structure of flash memory based on manufacturer */ |
| 2300 | if (IS_OEM_001(ha)) { |
| 2301 | /* OEM variant with special flash part. */ |
| 2302 | man_id = flash_id = 0; |
| 2303 | rest_addr = 0xffff; |
| 2304 | sec_mask = 0x10000; |
| 2305 | goto update_flash; |
| 2306 | } |
| 2307 | qla2x00_get_flash_manufacturer(ha, &man_id, &flash_id); |
| 2308 | switch (man_id) { |
| 2309 | case 0x20: /* ST flash. */ |
| 2310 | if (flash_id == 0xd2 || flash_id == 0xe3) { |
| 2311 | /* |
| 2312 | * ST m29w008at part - 64kb sector size with |
| 2313 | * 32kb,8kb,8kb,16kb sectors at memory address |
| 2314 | * 0xf0000. |
| 2315 | */ |
| 2316 | rest_addr = 0xffff; |
| 2317 | sec_mask = 0x10000; |
| 2318 | break; |
| 2319 | } |
| 2320 | /* |
| 2321 | * ST m29w010b part - 16kb sector size |
| 2322 | * Default to 16kb sectors |
| 2323 | */ |
| 2324 | rest_addr = 0x3fff; |
| 2325 | sec_mask = 0x1c000; |
| 2326 | break; |
| 2327 | case 0x40: /* Mostel flash. */ |
| 2328 | /* Mostel v29c51001 part - 512 byte sector size. */ |
| 2329 | rest_addr = 0x1ff; |
| 2330 | sec_mask = 0x1fe00; |
| 2331 | break; |
| 2332 | case 0xbf: /* SST flash. */ |
| 2333 | /* SST39sf10 part - 4kb sector size. */ |
| 2334 | rest_addr = 0xfff; |
| 2335 | sec_mask = 0x1f000; |
| 2336 | break; |
| 2337 | case 0xda: /* Winbond flash. */ |
| 2338 | /* Winbond W29EE011 part - 256 byte sector size. */ |
| 2339 | rest_addr = 0x7f; |
| 2340 | sec_mask = 0x1ff80; |
| 2341 | break; |
| 2342 | case 0xc2: /* Macronix flash. */ |
| 2343 | /* 64k sector size. */ |
| 2344 | if (flash_id == 0x38 || flash_id == 0x4f) { |
| 2345 | rest_addr = 0xffff; |
| 2346 | sec_mask = 0x10000; |
| 2347 | break; |
| 2348 | } |
| 2349 | /* Fall through... */ |
| 2350 | |
| 2351 | case 0x1f: /* Atmel flash. */ |
| 2352 | /* 512k sector size. */ |
| 2353 | if (flash_id == 0x13) { |
| 2354 | rest_addr = 0x7fffffff; |
| 2355 | sec_mask = 0x80000000; |
| 2356 | break; |
| 2357 | } |
| 2358 | /* Fall through... */ |
| 2359 | |
| 2360 | case 0x01: /* AMD flash. */ |
| 2361 | if (flash_id == 0x38 || flash_id == 0x40 || |
| 2362 | flash_id == 0x4f) { |
| 2363 | /* Am29LV081 part - 64kb sector size. */ |
| 2364 | /* Am29LV002BT part - 64kb sector size. */ |
| 2365 | rest_addr = 0xffff; |
| 2366 | sec_mask = 0x10000; |
| 2367 | break; |
| 2368 | } else if (flash_id == 0x3e) { |
| 2369 | /* |
| 2370 | * Am29LV008b part - 64kb sector size with |
| 2371 | * 32kb,8kb,8kb,16kb sector at memory address |
| 2372 | * h0xf0000. |
| 2373 | */ |
| 2374 | rest_addr = 0xffff; |
| 2375 | sec_mask = 0x10000; |
| 2376 | break; |
| 2377 | } else if (flash_id == 0x20 || flash_id == 0x6e) { |
| 2378 | /* |
| 2379 | * Am29LV010 part or AM29f010 - 16kb sector |
| 2380 | * size. |
| 2381 | */ |
| 2382 | rest_addr = 0x3fff; |
| 2383 | sec_mask = 0x1c000; |
| 2384 | break; |
| 2385 | } else if (flash_id == 0x6d) { |
| 2386 | /* Am29LV001 part - 8kb sector size. */ |
| 2387 | rest_addr = 0x1fff; |
| 2388 | sec_mask = 0x1e000; |
| 2389 | break; |
| 2390 | } |
| 2391 | default: |
| 2392 | /* Default to 16 kb sector size. */ |
| 2393 | rest_addr = 0x3fff; |
| 2394 | sec_mask = 0x1c000; |
| 2395 | break; |
| 2396 | } |
| 2397 | |
| 2398 | update_flash: |
| 2399 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) { |
| 2400 | if (qla2x00_erase_flash(ha, man_id, flash_id)) { |
| 2401 | rval = QLA_FUNCTION_FAILED; |
| 2402 | break; |
| 2403 | } |
| 2404 | } |
| 2405 | |
| 2406 | for (addr = offset, liter = 0; liter < length; liter++, |
| 2407 | addr++) { |
| 2408 | data = buf[liter]; |
| 2409 | /* Are we at the beginning of a sector? */ |
| 2410 | if ((addr & rest_addr) == 0) { |
| 2411 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) { |
| 2412 | if (addr >= 0x10000UL) { |
| 2413 | if (((addr >> 12) & 0xf0) && |
| 2414 | ((man_id == 0x01 && |
| 2415 | flash_id == 0x3e) || |
| 2416 | (man_id == 0x20 && |
| 2417 | flash_id == 0xd2))) { |
| 2418 | sec_number++; |
| 2419 | if (sec_number == 1) { |
| 2420 | rest_addr = |
| 2421 | 0x7fff; |
| 2422 | sec_mask = |
| 2423 | 0x18000; |
| 2424 | } else if ( |
| 2425 | sec_number == 2 || |
| 2426 | sec_number == 3) { |
| 2427 | rest_addr = |
| 2428 | 0x1fff; |
| 2429 | sec_mask = |
| 2430 | 0x1e000; |
| 2431 | } else if ( |
| 2432 | sec_number == 4) { |
| 2433 | rest_addr = |
| 2434 | 0x3fff; |
| 2435 | sec_mask = |
| 2436 | 0x1c000; |
| 2437 | } |
| 2438 | } |
| 2439 | } |
| 2440 | } else if (addr == ha->optrom_size / 2) { |
| 2441 | WRT_REG_WORD(®->nvram, NVR_SELECT); |
| 2442 | RD_REG_WORD(®->nvram); |
| 2443 | } |
| 2444 | |
| 2445 | if (flash_id == 0xda && man_id == 0xc1) { |
| 2446 | qla2x00_write_flash_byte(ha, 0x5555, |
| 2447 | 0xaa); |
| 2448 | qla2x00_write_flash_byte(ha, 0x2aaa, |
| 2449 | 0x55); |
| 2450 | qla2x00_write_flash_byte(ha, 0x5555, |
| 2451 | 0xa0); |
| 2452 | } else if (!IS_QLA2322(ha) && !IS_QLA6322(ha)) { |
| 2453 | /* Then erase it */ |
| 2454 | if (qla2x00_erase_flash_sector(ha, |
| 2455 | addr, sec_mask, man_id, |
| 2456 | flash_id)) { |
| 2457 | rval = QLA_FUNCTION_FAILED; |
| 2458 | break; |
| 2459 | } |
| 2460 | if (man_id == 0x01 && flash_id == 0x6d) |
| 2461 | sec_number++; |
| 2462 | } |
| 2463 | } |
| 2464 | |
| 2465 | if (man_id == 0x01 && flash_id == 0x6d) { |
| 2466 | if (sec_number == 1 && |
| 2467 | addr == (rest_addr - 1)) { |
| 2468 | rest_addr = 0x0fff; |
| 2469 | sec_mask = 0x1f000; |
| 2470 | } else if (sec_number == 3 && (addr & 0x7ffe)) { |
| 2471 | rest_addr = 0x3fff; |
| 2472 | sec_mask = 0x1c000; |
| 2473 | } |
| 2474 | } |
| 2475 | |
| 2476 | if (qla2x00_program_flash_address(ha, addr, data, |
| 2477 | man_id, flash_id)) { |
| 2478 | rval = QLA_FUNCTION_FAILED; |
| 2479 | break; |
| 2480 | } |
Andrew Vasquez | 40a2e34 | 2007-03-12 10:41:28 -0700 | [diff] [blame] | 2481 | cond_resched(); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2482 | } |
| 2483 | } while (0); |
| 2484 | qla2x00_flash_disable(ha); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2485 | |
| 2486 | /* Resume HBA. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2487 | qla2x00_resume_hba(vha); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2488 | |
| 2489 | return rval; |
| 2490 | } |
| 2491 | |
| 2492 | uint8_t * |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2493 | qla24xx_read_optrom_data(struct scsi_qla_host *vha, uint8_t *buf, |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2494 | uint32_t offset, uint32_t length) |
| 2495 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2496 | struct qla_hw_data *ha = vha->hw; |
| 2497 | |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2498 | /* Suspend HBA. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2499 | scsi_block_requests(vha->host); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2500 | set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags); |
| 2501 | |
| 2502 | /* Go with read. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2503 | qla24xx_read_flash_data(vha, (uint32_t *)buf, offset >> 2, length >> 2); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2504 | |
| 2505 | /* Resume HBA. */ |
| 2506 | clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2507 | scsi_unblock_requests(vha->host); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2508 | |
| 2509 | return buf; |
| 2510 | } |
| 2511 | |
| 2512 | int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2513 | qla24xx_write_optrom_data(struct scsi_qla_host *vha, uint8_t *buf, |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2514 | uint32_t offset, uint32_t length) |
| 2515 | { |
| 2516 | int rval; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2517 | struct qla_hw_data *ha = vha->hw; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2518 | |
| 2519 | /* Suspend HBA. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2520 | scsi_block_requests(vha->host); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2521 | set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags); |
| 2522 | |
| 2523 | /* Go with write. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2524 | rval = qla24xx_write_flash_data(vha, (uint32_t *)buf, offset >> 2, |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2525 | length >> 2); |
| 2526 | |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2527 | clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2528 | scsi_unblock_requests(vha->host); |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2529 | |
| 2530 | return rval; |
| 2531 | } |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2532 | |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 2533 | uint8_t * |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2534 | qla25xx_read_optrom_data(struct scsi_qla_host *vha, uint8_t *buf, |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 2535 | uint32_t offset, uint32_t length) |
| 2536 | { |
| 2537 | int rval; |
| 2538 | dma_addr_t optrom_dma; |
| 2539 | void *optrom; |
| 2540 | uint8_t *pbuf; |
| 2541 | uint32_t faddr, left, burst; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2542 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 2543 | |
Andrew Vasquez | 368bbe0 | 2010-01-12 12:59:49 -0800 | [diff] [blame] | 2544 | if (IS_QLA25XX(ha) || IS_QLA81XX(ha)) |
| 2545 | goto try_fast; |
Joe Carnuccio | b7cc176 | 2007-09-20 14:07:35 -0700 | [diff] [blame] | 2546 | if (offset & 0xfff) |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 2547 | goto slow_read; |
| 2548 | if (length < OPTROM_BURST_SIZE) |
| 2549 | goto slow_read; |
| 2550 | |
Andrew Vasquez | 368bbe0 | 2010-01-12 12:59:49 -0800 | [diff] [blame] | 2551 | try_fast: |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 2552 | optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE, |
| 2553 | &optrom_dma, GFP_KERNEL); |
| 2554 | if (!optrom) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2555 | ql_log(ql_log_warn, vha, 0x00cc, |
| 2556 | "Unable to allocate memory for optrom burst read (%x KB).\n", |
| 2557 | OPTROM_BURST_SIZE / 1024); |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 2558 | goto slow_read; |
| 2559 | } |
| 2560 | |
| 2561 | pbuf = buf; |
| 2562 | faddr = offset >> 2; |
| 2563 | left = length >> 2; |
| 2564 | burst = OPTROM_BURST_DWORDS; |
| 2565 | while (left != 0) { |
| 2566 | if (burst > left) |
| 2567 | burst = left; |
| 2568 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2569 | rval = qla2x00_dump_ram(vha, optrom_dma, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 2570 | flash_data_addr(ha, faddr), burst); |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 2571 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2572 | ql_log(ql_log_warn, vha, 0x00f5, |
| 2573 | "Unable to burst-read optrom segment (%x/%x/%llx).\n", |
| 2574 | rval, flash_data_addr(ha, faddr), |
Andrew Morton | 875baf3 | 2007-10-16 14:28:20 -0700 | [diff] [blame] | 2575 | (unsigned long long)optrom_dma); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2576 | ql_log(ql_log_warn, vha, 0x00f6, |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 2577 | "Reverting to slow-read.\n"); |
| 2578 | |
| 2579 | dma_free_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE, |
| 2580 | optrom, optrom_dma); |
| 2581 | goto slow_read; |
| 2582 | } |
| 2583 | |
| 2584 | memcpy(pbuf, optrom, burst * 4); |
| 2585 | |
| 2586 | left -= burst; |
| 2587 | faddr += burst; |
| 2588 | pbuf += burst * 4; |
| 2589 | } |
| 2590 | |
| 2591 | dma_free_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE, optrom, |
| 2592 | optrom_dma); |
| 2593 | |
| 2594 | return buf; |
| 2595 | |
| 2596 | slow_read: |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2597 | return qla24xx_read_optrom_data(vha, buf, offset, length); |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 2598 | } |
| 2599 | |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2600 | /** |
| 2601 | * qla2x00_get_fcode_version() - Determine an FCODE image's version. |
| 2602 | * @ha: HA context |
| 2603 | * @pcids: Pointer to the FCODE PCI data structure |
| 2604 | * |
| 2605 | * The process of retrieving the FCODE version information is at best |
| 2606 | * described as interesting. |
| 2607 | * |
| 2608 | * Within the first 100h bytes of the image an ASCII string is present |
| 2609 | * which contains several pieces of information including the FCODE |
| 2610 | * version. Unfortunately it seems the only reliable way to retrieve |
| 2611 | * the version is by scanning for another sentinel within the string, |
| 2612 | * the FCODE build date: |
| 2613 | * |
| 2614 | * ... 2.00.02 10/17/02 ... |
| 2615 | * |
| 2616 | * Returns QLA_SUCCESS on successful retrieval of version. |
| 2617 | */ |
| 2618 | static void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2619 | qla2x00_get_fcode_version(struct qla_hw_data *ha, uint32_t pcids) |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2620 | { |
| 2621 | int ret = QLA_FUNCTION_FAILED; |
| 2622 | uint32_t istart, iend, iter, vend; |
| 2623 | uint8_t do_next, rbyte, *vbyte; |
| 2624 | |
| 2625 | memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision)); |
| 2626 | |
| 2627 | /* Skip the PCI data structure. */ |
| 2628 | istart = pcids + |
| 2629 | ((qla2x00_read_flash_byte(ha, pcids + 0x0B) << 8) | |
| 2630 | qla2x00_read_flash_byte(ha, pcids + 0x0A)); |
| 2631 | iend = istart + 0x100; |
| 2632 | do { |
| 2633 | /* Scan for the sentinel date string...eeewww. */ |
| 2634 | do_next = 0; |
| 2635 | iter = istart; |
| 2636 | while ((iter < iend) && !do_next) { |
| 2637 | iter++; |
| 2638 | if (qla2x00_read_flash_byte(ha, iter) == '/') { |
| 2639 | if (qla2x00_read_flash_byte(ha, iter + 2) == |
| 2640 | '/') |
| 2641 | do_next++; |
| 2642 | else if (qla2x00_read_flash_byte(ha, |
| 2643 | iter + 3) == '/') |
| 2644 | do_next++; |
| 2645 | } |
| 2646 | } |
| 2647 | if (!do_next) |
| 2648 | break; |
| 2649 | |
| 2650 | /* Backtrack to previous ' ' (space). */ |
| 2651 | do_next = 0; |
| 2652 | while ((iter > istart) && !do_next) { |
| 2653 | iter--; |
| 2654 | if (qla2x00_read_flash_byte(ha, iter) == ' ') |
| 2655 | do_next++; |
| 2656 | } |
| 2657 | if (!do_next) |
| 2658 | break; |
| 2659 | |
| 2660 | /* |
| 2661 | * Mark end of version tag, and find previous ' ' (space) or |
| 2662 | * string length (recent FCODE images -- major hack ahead!!!). |
| 2663 | */ |
| 2664 | vend = iter - 1; |
| 2665 | do_next = 0; |
| 2666 | while ((iter > istart) && !do_next) { |
| 2667 | iter--; |
| 2668 | rbyte = qla2x00_read_flash_byte(ha, iter); |
| 2669 | if (rbyte == ' ' || rbyte == 0xd || rbyte == 0x10) |
| 2670 | do_next++; |
| 2671 | } |
| 2672 | if (!do_next) |
| 2673 | break; |
| 2674 | |
| 2675 | /* Mark beginning of version tag, and copy data. */ |
| 2676 | iter++; |
| 2677 | if ((vend - iter) && |
| 2678 | ((vend - iter) < sizeof(ha->fcode_revision))) { |
| 2679 | vbyte = ha->fcode_revision; |
| 2680 | while (iter <= vend) { |
| 2681 | *vbyte++ = qla2x00_read_flash_byte(ha, iter); |
| 2682 | iter++; |
| 2683 | } |
| 2684 | ret = QLA_SUCCESS; |
| 2685 | } |
| 2686 | } while (0); |
| 2687 | |
| 2688 | if (ret != QLA_SUCCESS) |
| 2689 | memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision)); |
| 2690 | } |
| 2691 | |
| 2692 | int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2693 | qla2x00_get_flash_version(scsi_qla_host_t *vha, void *mbuf) |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2694 | { |
| 2695 | int ret = QLA_SUCCESS; |
| 2696 | uint8_t code_type, last_image; |
| 2697 | uint32_t pcihdr, pcids; |
| 2698 | uint8_t *dbyte; |
| 2699 | uint16_t *dcode; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2700 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2701 | |
| 2702 | if (!ha->pio_address || !mbuf) |
| 2703 | return QLA_FUNCTION_FAILED; |
| 2704 | |
| 2705 | memset(ha->bios_revision, 0, sizeof(ha->bios_revision)); |
| 2706 | memset(ha->efi_revision, 0, sizeof(ha->efi_revision)); |
| 2707 | memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision)); |
| 2708 | memset(ha->fw_revision, 0, sizeof(ha->fw_revision)); |
| 2709 | |
| 2710 | qla2x00_flash_enable(ha); |
| 2711 | |
| 2712 | /* Begin with first PCI expansion ROM header. */ |
| 2713 | pcihdr = 0; |
| 2714 | last_image = 1; |
| 2715 | do { |
| 2716 | /* Verify PCI expansion ROM header. */ |
| 2717 | if (qla2x00_read_flash_byte(ha, pcihdr) != 0x55 || |
| 2718 | qla2x00_read_flash_byte(ha, pcihdr + 0x01) != 0xaa) { |
| 2719 | /* No signature */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2720 | ql_log(ql_log_fatal, vha, 0x0050, |
| 2721 | "No matching ROM signature.\n"); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2722 | ret = QLA_FUNCTION_FAILED; |
| 2723 | break; |
| 2724 | } |
| 2725 | |
| 2726 | /* Locate PCI data structure. */ |
| 2727 | pcids = pcihdr + |
| 2728 | ((qla2x00_read_flash_byte(ha, pcihdr + 0x19) << 8) | |
| 2729 | qla2x00_read_flash_byte(ha, pcihdr + 0x18)); |
| 2730 | |
| 2731 | /* Validate signature of PCI data structure. */ |
| 2732 | if (qla2x00_read_flash_byte(ha, pcids) != 'P' || |
| 2733 | qla2x00_read_flash_byte(ha, pcids + 0x1) != 'C' || |
| 2734 | qla2x00_read_flash_byte(ha, pcids + 0x2) != 'I' || |
| 2735 | qla2x00_read_flash_byte(ha, pcids + 0x3) != 'R') { |
| 2736 | /* Incorrect header. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2737 | ql_log(ql_log_fatal, vha, 0x0051, |
| 2738 | "PCI data struct not found pcir_adr=%x.\n", pcids); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2739 | ret = QLA_FUNCTION_FAILED; |
| 2740 | break; |
| 2741 | } |
| 2742 | |
| 2743 | /* Read version */ |
| 2744 | code_type = qla2x00_read_flash_byte(ha, pcids + 0x14); |
| 2745 | switch (code_type) { |
| 2746 | case ROM_CODE_TYPE_BIOS: |
| 2747 | /* Intel x86, PC-AT compatible. */ |
| 2748 | ha->bios_revision[0] = |
| 2749 | qla2x00_read_flash_byte(ha, pcids + 0x12); |
| 2750 | ha->bios_revision[1] = |
| 2751 | qla2x00_read_flash_byte(ha, pcids + 0x13); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2752 | ql_dbg(ql_dbg_init, vha, 0x0052, |
| 2753 | "Read BIOS %d.%d.\n", |
| 2754 | ha->bios_revision[1], ha->bios_revision[0]); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2755 | break; |
| 2756 | case ROM_CODE_TYPE_FCODE: |
| 2757 | /* Open Firmware standard for PCI (FCode). */ |
| 2758 | /* Eeeewww... */ |
| 2759 | qla2x00_get_fcode_version(ha, pcids); |
| 2760 | break; |
| 2761 | case ROM_CODE_TYPE_EFI: |
| 2762 | /* Extensible Firmware Interface (EFI). */ |
| 2763 | ha->efi_revision[0] = |
| 2764 | qla2x00_read_flash_byte(ha, pcids + 0x12); |
| 2765 | ha->efi_revision[1] = |
| 2766 | qla2x00_read_flash_byte(ha, pcids + 0x13); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2767 | ql_dbg(ql_dbg_init, vha, 0x0053, |
| 2768 | "Read EFI %d.%d.\n", |
| 2769 | ha->efi_revision[1], ha->efi_revision[0]); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2770 | break; |
| 2771 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2772 | ql_log(ql_log_warn, vha, 0x0054, |
| 2773 | "Unrecognized code type %x at pcids %x.\n", |
| 2774 | code_type, pcids); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2775 | break; |
| 2776 | } |
| 2777 | |
| 2778 | last_image = qla2x00_read_flash_byte(ha, pcids + 0x15) & BIT_7; |
| 2779 | |
| 2780 | /* Locate next PCI expansion ROM. */ |
| 2781 | pcihdr += ((qla2x00_read_flash_byte(ha, pcids + 0x11) << 8) | |
| 2782 | qla2x00_read_flash_byte(ha, pcids + 0x10)) * 512; |
| 2783 | } while (!last_image); |
| 2784 | |
| 2785 | if (IS_QLA2322(ha)) { |
| 2786 | /* Read firmware image information. */ |
| 2787 | memset(ha->fw_revision, 0, sizeof(ha->fw_revision)); |
| 2788 | dbyte = mbuf; |
| 2789 | memset(dbyte, 0, 8); |
| 2790 | dcode = (uint16_t *)dbyte; |
| 2791 | |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 2792 | qla2x00_read_flash_data(ha, dbyte, ha->flt_region_fw * 4 + 10, |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2793 | 8); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2794 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010a, |
| 2795 | "Dumping fw " |
| 2796 | "ver from flash:.\n"); |
| 2797 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010b, |
| 2798 | (uint8_t *)dbyte, 8); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2799 | |
| 2800 | if ((dcode[0] == 0xffff && dcode[1] == 0xffff && |
| 2801 | dcode[2] == 0xffff && dcode[3] == 0xffff) || |
| 2802 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 2803 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2804 | ql_log(ql_log_warn, vha, 0x0057, |
| 2805 | "Unrecognized fw revision at %x.\n", |
| 2806 | ha->flt_region_fw * 4); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2807 | } else { |
| 2808 | /* values are in big endian */ |
| 2809 | ha->fw_revision[0] = dbyte[0] << 16 | dbyte[1]; |
| 2810 | ha->fw_revision[1] = dbyte[2] << 16 | dbyte[3]; |
| 2811 | ha->fw_revision[2] = dbyte[4] << 16 | dbyte[5]; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2812 | ql_dbg(ql_dbg_init, vha, 0x0058, |
| 2813 | "FW Version: " |
| 2814 | "%d.%d.%d.\n", ha->fw_revision[0], |
| 2815 | ha->fw_revision[1], ha->fw_revision[2]); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2816 | } |
| 2817 | } |
| 2818 | |
| 2819 | qla2x00_flash_disable(ha); |
| 2820 | |
| 2821 | return ret; |
| 2822 | } |
| 2823 | |
| 2824 | int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2825 | qla24xx_get_flash_version(scsi_qla_host_t *vha, void *mbuf) |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2826 | { |
| 2827 | int ret = QLA_SUCCESS; |
| 2828 | uint32_t pcihdr, pcids; |
| 2829 | uint32_t *dcode; |
| 2830 | uint8_t *bcode; |
| 2831 | uint8_t code_type, last_image; |
| 2832 | int i; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2833 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2834 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2835 | if (IS_QLA82XX(ha)) |
| 2836 | return ret; |
| 2837 | |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2838 | if (!mbuf) |
| 2839 | return QLA_FUNCTION_FAILED; |
| 2840 | |
| 2841 | memset(ha->bios_revision, 0, sizeof(ha->bios_revision)); |
| 2842 | memset(ha->efi_revision, 0, sizeof(ha->efi_revision)); |
| 2843 | memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision)); |
| 2844 | memset(ha->fw_revision, 0, sizeof(ha->fw_revision)); |
| 2845 | |
| 2846 | dcode = mbuf; |
| 2847 | |
| 2848 | /* Begin with first PCI expansion ROM header. */ |
Harish Zunjarrao | 6315a5f | 2009-03-24 09:07:59 -0700 | [diff] [blame] | 2849 | pcihdr = ha->flt_region_boot << 2; |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2850 | last_image = 1; |
| 2851 | do { |
| 2852 | /* Verify PCI expansion ROM header. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2853 | qla24xx_read_flash_data(vha, dcode, pcihdr >> 2, 0x20); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2854 | bcode = mbuf + (pcihdr % 4); |
| 2855 | if (bcode[0x0] != 0x55 || bcode[0x1] != 0xaa) { |
| 2856 | /* No signature */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2857 | ql_log(ql_log_fatal, vha, 0x0059, |
| 2858 | "No matching ROM signature.\n"); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2859 | ret = QLA_FUNCTION_FAILED; |
| 2860 | break; |
| 2861 | } |
| 2862 | |
| 2863 | /* Locate PCI data structure. */ |
| 2864 | pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]); |
| 2865 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2866 | qla24xx_read_flash_data(vha, dcode, pcids >> 2, 0x20); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2867 | bcode = mbuf + (pcihdr % 4); |
| 2868 | |
| 2869 | /* Validate signature of PCI data structure. */ |
| 2870 | if (bcode[0x0] != 'P' || bcode[0x1] != 'C' || |
| 2871 | bcode[0x2] != 'I' || bcode[0x3] != 'R') { |
| 2872 | /* Incorrect header. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2873 | ql_log(ql_log_fatal, vha, 0x005a, |
| 2874 | "PCI data struct not found pcir_adr=%x.\n", pcids); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2875 | ret = QLA_FUNCTION_FAILED; |
| 2876 | break; |
| 2877 | } |
| 2878 | |
| 2879 | /* Read version */ |
| 2880 | code_type = bcode[0x14]; |
| 2881 | switch (code_type) { |
| 2882 | case ROM_CODE_TYPE_BIOS: |
| 2883 | /* Intel x86, PC-AT compatible. */ |
| 2884 | ha->bios_revision[0] = bcode[0x12]; |
| 2885 | ha->bios_revision[1] = bcode[0x13]; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2886 | ql_dbg(ql_dbg_init, vha, 0x005b, |
| 2887 | "Read BIOS %d.%d.\n", |
| 2888 | ha->bios_revision[1], ha->bios_revision[0]); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2889 | break; |
| 2890 | case ROM_CODE_TYPE_FCODE: |
| 2891 | /* Open Firmware standard for PCI (FCode). */ |
| 2892 | ha->fcode_revision[0] = bcode[0x12]; |
| 2893 | ha->fcode_revision[1] = bcode[0x13]; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2894 | ql_dbg(ql_dbg_init, vha, 0x005c, |
| 2895 | "Read FCODE %d.%d.\n", |
| 2896 | ha->fcode_revision[1], ha->fcode_revision[0]); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2897 | break; |
| 2898 | case ROM_CODE_TYPE_EFI: |
| 2899 | /* Extensible Firmware Interface (EFI). */ |
| 2900 | ha->efi_revision[0] = bcode[0x12]; |
| 2901 | ha->efi_revision[1] = bcode[0x13]; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2902 | ql_dbg(ql_dbg_init, vha, 0x005d, |
| 2903 | "Read EFI %d.%d.\n", |
| 2904 | ha->efi_revision[1], ha->efi_revision[0]); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2905 | break; |
| 2906 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2907 | ql_log(ql_log_warn, vha, 0x005e, |
| 2908 | "Unrecognized code type %x at pcids %x.\n", |
| 2909 | code_type, pcids); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2910 | break; |
| 2911 | } |
| 2912 | |
| 2913 | last_image = bcode[0x15] & BIT_7; |
| 2914 | |
| 2915 | /* Locate next PCI expansion ROM. */ |
| 2916 | pcihdr += ((bcode[0x11] << 8) | bcode[0x10]) * 512; |
| 2917 | } while (!last_image); |
| 2918 | |
| 2919 | /* Read firmware image information. */ |
| 2920 | memset(ha->fw_revision, 0, sizeof(ha->fw_revision)); |
| 2921 | dcode = mbuf; |
| 2922 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2923 | qla24xx_read_flash_data(vha, dcode, ha->flt_region_fw + 4, 4); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2924 | for (i = 0; i < 4; i++) |
| 2925 | dcode[i] = be32_to_cpu(dcode[i]); |
| 2926 | |
| 2927 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 2928 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 2929 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 2930 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2931 | ql_log(ql_log_warn, vha, 0x005f, |
| 2932 | "Unrecognized fw revision at %x.\n", |
| 2933 | ha->flt_region_fw * 4); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2934 | } else { |
| 2935 | ha->fw_revision[0] = dcode[0]; |
| 2936 | ha->fw_revision[1] = dcode[1]; |
| 2937 | ha->fw_revision[2] = dcode[2]; |
| 2938 | ha->fw_revision[3] = dcode[3]; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2939 | ql_dbg(ql_dbg_init, vha, 0x0060, |
| 2940 | "Firmware revision %d.%d.%d.%d.\n", |
| 2941 | ha->fw_revision[0], ha->fw_revision[1], |
| 2942 | ha->fw_revision[2], ha->fw_revision[3]); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2943 | } |
| 2944 | |
Madhuranath Iyengar | 0f2d962 | 2010-07-23 15:28:26 +0500 | [diff] [blame] | 2945 | /* Check for golden firmware and get version if available */ |
| 2946 | if (!IS_QLA81XX(ha)) { |
| 2947 | /* Golden firmware is not present in non 81XX adapters */ |
| 2948 | return ret; |
| 2949 | } |
| 2950 | |
| 2951 | memset(ha->gold_fw_version, 0, sizeof(ha->gold_fw_version)); |
| 2952 | dcode = mbuf; |
| 2953 | ha->isp_ops->read_optrom(vha, (uint8_t *)dcode, |
| 2954 | ha->flt_region_gold_fw << 2, 32); |
| 2955 | |
| 2956 | if (dcode[4] == 0xFFFFFFFF && dcode[5] == 0xFFFFFFFF && |
| 2957 | dcode[6] == 0xFFFFFFFF && dcode[7] == 0xFFFFFFFF) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2958 | ql_log(ql_log_warn, vha, 0x0056, |
| 2959 | "Unrecognized golden fw at 0x%x.\n", |
| 2960 | ha->flt_region_gold_fw * 4); |
Madhuranath Iyengar | 0f2d962 | 2010-07-23 15:28:26 +0500 | [diff] [blame] | 2961 | return ret; |
| 2962 | } |
| 2963 | |
| 2964 | for (i = 4; i < 8; i++) |
| 2965 | ha->gold_fw_version[i-4] = be32_to_cpu(dcode[i]); |
| 2966 | |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 2967 | return ret; |
| 2968 | } |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 2969 | |
| 2970 | static int |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2971 | qla2xxx_is_vpd_valid(uint8_t *pos, uint8_t *end) |
| 2972 | { |
| 2973 | if (pos >= end || *pos != 0x82) |
| 2974 | return 0; |
| 2975 | |
| 2976 | pos += 3 + pos[1]; |
| 2977 | if (pos >= end || *pos != 0x90) |
| 2978 | return 0; |
| 2979 | |
| 2980 | pos += 3 + pos[1]; |
| 2981 | if (pos >= end || *pos != 0x78) |
| 2982 | return 0; |
| 2983 | |
| 2984 | return 1; |
| 2985 | } |
| 2986 | |
| 2987 | int |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2988 | qla2xxx_get_vpd_field(scsi_qla_host_t *vha, char *key, char *str, size_t size) |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2989 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 2990 | struct qla_hw_data *ha = vha->hw; |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2991 | uint8_t *pos = ha->vpd; |
| 2992 | uint8_t *end = pos + ha->vpd_size; |
| 2993 | int len = 0; |
| 2994 | |
| 2995 | if (!IS_FWI2_CAPABLE(ha) || !qla2xxx_is_vpd_valid(pos, end)) |
| 2996 | return 0; |
| 2997 | |
| 2998 | while (pos < end && *pos != 0x78) { |
| 2999 | len = (*pos == 0x82) ? pos[1] : pos[2]; |
| 3000 | |
| 3001 | if (!strncmp(pos, key, strlen(key))) |
| 3002 | break; |
| 3003 | |
| 3004 | if (*pos != 0x90 && *pos != 0x91) |
| 3005 | pos += len; |
| 3006 | |
| 3007 | pos += 3; |
| 3008 | } |
| 3009 | |
| 3010 | if (pos < end - len && *pos != 0x78) |
| 3011 | return snprintf(str, size, "%.*s", len, pos + 3); |
| 3012 | |
| 3013 | return 0; |
| 3014 | } |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 3015 | |
| 3016 | int |
| 3017 | qla24xx_read_fcp_prio_cfg(scsi_qla_host_t *vha) |
| 3018 | { |
| 3019 | int len, max_len; |
| 3020 | uint32_t fcp_prio_addr; |
| 3021 | struct qla_hw_data *ha = vha->hw; |
| 3022 | |
| 3023 | if (!ha->fcp_prio_cfg) { |
| 3024 | ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE); |
| 3025 | if (!ha->fcp_prio_cfg) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3026 | ql_log(ql_log_warn, vha, 0x00d5, |
| 3027 | "Unable to allocate memory for fcp priorty data (%x).\n", |
| 3028 | FCP_PRIO_CFG_SIZE); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 3029 | return QLA_FUNCTION_FAILED; |
| 3030 | } |
| 3031 | } |
| 3032 | memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE); |
| 3033 | |
| 3034 | fcp_prio_addr = ha->flt_region_fcp_prio; |
| 3035 | |
| 3036 | /* first read the fcp priority data header from flash */ |
| 3037 | ha->isp_ops->read_optrom(vha, (uint8_t *)ha->fcp_prio_cfg, |
| 3038 | fcp_prio_addr << 2, FCP_PRIO_CFG_HDR_SIZE); |
| 3039 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3040 | if (!qla24xx_fcp_prio_cfg_valid(vha, ha->fcp_prio_cfg, 0)) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 3041 | goto fail; |
| 3042 | |
| 3043 | /* read remaining FCP CMD config data from flash */ |
| 3044 | fcp_prio_addr += (FCP_PRIO_CFG_HDR_SIZE >> 2); |
| 3045 | len = ha->fcp_prio_cfg->num_entries * FCP_PRIO_CFG_ENTRY_SIZE; |
| 3046 | max_len = FCP_PRIO_CFG_SIZE - FCP_PRIO_CFG_HDR_SIZE; |
| 3047 | |
| 3048 | ha->isp_ops->read_optrom(vha, (uint8_t *)&ha->fcp_prio_cfg->entry[0], |
| 3049 | fcp_prio_addr << 2, (len < max_len ? len : max_len)); |
| 3050 | |
| 3051 | /* revalidate the entire FCP priority config data, including entries */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3052 | if (!qla24xx_fcp_prio_cfg_valid(vha, ha->fcp_prio_cfg, 1)) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 3053 | goto fail; |
| 3054 | |
| 3055 | ha->flags.fcp_prio_enabled = 1; |
| 3056 | return QLA_SUCCESS; |
| 3057 | fail: |
| 3058 | vfree(ha->fcp_prio_cfg); |
| 3059 | ha->fcp_prio_cfg = NULL; |
| 3060 | return QLA_FUNCTION_FAILED; |
| 3061 | } |