blob: 3c13c0a6be63cfa2f00ae5b7022031828c79143d [file] [log] [blame]
Andrew Vasquezfa90c542005-10-27 11:10:08 -07001/*
2 * QLogic Fibre Channel HBA Driver
Andrew Vasquez07e264b2011-03-30 11:46:23 -07003 * Copyright (c) 2003-2011 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
6 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include "qla_def.h"
8
9#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Andrew Vasquez2c96d8d2007-10-19 15:59:15 -070011#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <asm/uaccess.h>
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014/*
15 * NVRAM support routines
16 */
17
18/**
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -070019 * qla2x00_lock_nvram_access() -
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 * @ha: HA context
21 */
Adrian Bunka824ebb2008-01-17 09:02:15 -080022static void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080023qla2x00_lock_nvram_access(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024{
25 uint16_t data;
Andrew Vasquez3d716442005-07-06 10:30:26 -070026 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) {
29 data = RD_REG_WORD(&reg->nvram);
30 while (data & NVR_BUSY) {
31 udelay(100);
32 data = RD_REG_WORD(&reg->nvram);
33 }
34
35 /* Lock resource */
36 WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0x1);
37 RD_REG_WORD(&reg->u.isp2300.host_semaphore);
38 udelay(5);
39 data = RD_REG_WORD(&reg->u.isp2300.host_semaphore);
40 while ((data & BIT_0) == 0) {
41 /* Lock failed */
42 udelay(100);
43 WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0x1);
44 RD_REG_WORD(&reg->u.isp2300.host_semaphore);
45 udelay(5);
46 data = RD_REG_WORD(&reg->u.isp2300.host_semaphore);
47 }
48 }
49}
50
51/**
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -070052 * qla2x00_unlock_nvram_access() -
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 * @ha: HA context
54 */
Adrian Bunka824ebb2008-01-17 09:02:15 -080055static void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080056qla2x00_unlock_nvram_access(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Andrew Vasquez3d716442005-07-06 10:30:26 -070058 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) {
61 WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0);
62 RD_REG_WORD(&reg->u.isp2300.host_semaphore);
63 }
64}
65
66/**
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080067 * qla2x00_nv_write() - Prepare for NVRAM read/write operation.
68 * @ha: HA context
69 * @data: Serial interface selector
70 */
71static void
72qla2x00_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(&reg->nvram, data | NVR_SELECT | NVR_WRT_ENABLE);
77 RD_REG_WORD(&reg->nvram); /* PCI Posting. */
78 NVRAM_DELAY();
79 WRT_REG_WORD(&reg->nvram, data | NVR_SELECT | NVR_CLOCK |
80 NVR_WRT_ENABLE);
81 RD_REG_WORD(&reg->nvram); /* PCI Posting. */
82 NVRAM_DELAY();
83 WRT_REG_WORD(&reg->nvram, data | NVR_SELECT | NVR_WRT_ENABLE);
84 RD_REG_WORD(&reg->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 */
103static uint16_t
104qla2x00_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(&reg->nvram, NVR_SELECT | NVR_CLOCK);
124 RD_REG_WORD(&reg->nvram); /* PCI Posting. */
125 NVRAM_DELAY();
126 data <<= 1;
127 reg_data = RD_REG_WORD(&reg->nvram);
128 if (reg_data & NVR_DATA_IN)
129 data |= BIT_0;
130 WRT_REG_WORD(&reg->nvram, NVR_SELECT);
131 RD_REG_WORD(&reg->nvram); /* PCI Posting. */
132 NVRAM_DELAY();
133 }
134
135 /* Deselect chip. */
136 WRT_REG_WORD(&reg->nvram, NVR_DESELECT);
137 RD_REG_WORD(&reg->nvram); /* PCI Posting. */
138 NVRAM_DELAY();
139
140 return data;
141}
142
143
144/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 * 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 Bunka824ebb2008-01-17 09:02:15 -0800152static uint16_t
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800153qla2x00_get_nvram_word(struct qla_hw_data *ha, uint32_t addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
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 Chakraborty7b867cf2008-11-06 10:40:19 -0800166 * qla2x00_nv_deselect() - Deselect NVRAM operations.
167 * @ha: HA context
168 */
169static void
170qla2x00_nv_deselect(struct qla_hw_data *ha)
171{
172 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
173
174 WRT_REG_WORD(&reg->nvram, NVR_DESELECT);
175 RD_REG_WORD(&reg->nvram); /* PCI Posting. */
176 NVRAM_DELAY();
177}
178
179/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 * 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 Bunka824ebb2008-01-17 09:02:15 -0800185static void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800186qla2x00_write_nvram_word(struct qla_hw_data *ha, uint32_t addr, uint16_t data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
188 int count;
189 uint16_t word;
Ravi Anand45aeaf12006-05-17 15:08:49 -0700190 uint32_t nv_cmd, wait_cnt;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700191 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700192 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
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(&reg->nvram, NVR_SELECT);
Andrew Vasquezdcb36ce2005-11-08 14:37:06 -0800220 RD_REG_WORD(&reg->nvram); /* PCI Posting. */
Ravi Anand45aeaf12006-05-17 15:08:49 -0700221 wait_cnt = NVR_WAIT_CNT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 do {
Ravi Anand45aeaf12006-05-17 15:08:49 -0700223 if (!--wait_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700224 ql_dbg(ql_dbg_user, vha, 0x708d,
225 "NVRAM didn't go ready...\n");
Ravi Anand45aeaf12006-05-17 15:08:49 -0700226 break;
227 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 NVRAM_DELAY();
229 word = RD_REG_WORD(&reg->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 Vasquez459c5372005-07-06 10:31:07 -0700242static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800243qla2x00_write_nvram_word_tmo(struct qla_hw_data *ha, uint32_t addr,
244 uint16_t data, uint32_t tmo)
Andrew Vasquez459c5372005-07-06 10:31:07 -0700245{
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(&reg->nvram, NVR_SELECT);
Andrew Vasquezdcb36ce2005-11-08 14:37:06 -0800279 RD_REG_WORD(&reg->nvram); /* PCI Posting. */
Andrew Vasquez459c5372005-07-06 10:31:07 -0700280 do {
281 NVRAM_DELAY();
282 word = RD_REG_WORD(&reg->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 Torvalds1da177e2005-04-16 15:20:36 -0700301/**
Andrew Vasquez459c5372005-07-06 10:31:07 -0700302 * qla2x00_clear_nvram_protection() -
303 * @ha: HA context
304 */
305static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800306qla2x00_clear_nvram_protection(struct qla_hw_data *ha)
Andrew Vasquez459c5372005-07-06 10:31:07 -0700307{
308 int ret, stat;
309 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Ravi Anand45aeaf12006-05-17 15:08:49 -0700310 uint32_t word, wait_cnt;
Andrew Vasquez459c5372005-07-06 10:31:07 -0700311 uint16_t wprot, wprot_old;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700312 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez459c5372005-07-06 10:31:07 -0700313
314 /* Clear NVRAM write protection. */
315 ret = QLA_FUNCTION_FAILED;
Ravi Anand45aeaf12006-05-17 15:08:49 -0700316
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 Vasquez459c5372005-07-06 10:31:07 -0700319 __constant_cpu_to_le16(0x1234), 100000);
Ravi Anand45aeaf12006-05-17 15:08:49 -0700320 wprot = cpu_to_le16(qla2x00_get_nvram_word(ha, ha->nvram_base));
321 if (stat != QLA_SUCCESS || wprot != 0x1234) {
Andrew Vasquez459c5372005-07-06 10:31:07 -0700322 /* 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(&reg->nvram, NVR_SELECT);
Andrew Vasquezdcb36ce2005-11-08 14:37:06 -0800351 RD_REG_WORD(&reg->nvram); /* PCI Posting. */
Ravi Anand45aeaf12006-05-17 15:08:49 -0700352 wait_cnt = NVR_WAIT_CNT;
Andrew Vasquez459c5372005-07-06 10:31:07 -0700353 do {
Ravi Anand45aeaf12006-05-17 15:08:49 -0700354 if (!--wait_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700355 ql_dbg(ql_dbg_user, vha, 0x708e,
356 "NVRAM didn't go ready...\n");
Ravi Anand45aeaf12006-05-17 15:08:49 -0700357 break;
358 }
Andrew Vasquez459c5372005-07-06 10:31:07 -0700359 NVRAM_DELAY();
360 word = RD_REG_WORD(&reg->nvram);
361 } while ((word & NVR_DATA_IN) == 0);
362
Ravi Anand45aeaf12006-05-17 15:08:49 -0700363 if (wait_cnt)
364 ret = QLA_SUCCESS;
Andrew Vasquez459c5372005-07-06 10:31:07 -0700365 } else
Ravi Anand45aeaf12006-05-17 15:08:49 -0700366 qla2x00_write_nvram_word(ha, ha->nvram_base, wprot_old);
Andrew Vasquez459c5372005-07-06 10:31:07 -0700367
368 return ret;
369}
370
371static void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800372qla2x00_set_nvram_protection(struct qla_hw_data *ha, int stat)
Andrew Vasquez459c5372005-07-06 10:31:07 -0700373{
374 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Ravi Anand45aeaf12006-05-17 15:08:49 -0700375 uint32_t word, wait_cnt;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700376 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez459c5372005-07-06 10:31:07 -0700377
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(&reg->nvram, NVR_SELECT);
Andrew Vasquezdcb36ce2005-11-08 14:37:06 -0800411 RD_REG_WORD(&reg->nvram); /* PCI Posting. */
Ravi Anand45aeaf12006-05-17 15:08:49 -0700412 wait_cnt = NVR_WAIT_CNT;
Andrew Vasquez459c5372005-07-06 10:31:07 -0700413 do {
Ravi Anand45aeaf12006-05-17 15:08:49 -0700414 if (!--wait_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700415 ql_dbg(ql_dbg_user, vha, 0x708f,
416 "NVRAM didn't go ready...\n");
Ravi Anand45aeaf12006-05-17 15:08:49 -0700417 break;
418 }
Andrew Vasquez459c5372005-07-06 10:31:07 -0700419 NVRAM_DELAY();
420 word = RD_REG_WORD(&reg->nvram);
421 } while ((word & NVR_DATA_IN) == 0);
422}
423
424
425/*****************************************************************************/
426/* Flash Manipulation Routines */
427/*****************************************************************************/
428
429static inline uint32_t
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800430flash_conf_addr(struct qla_hw_data *ha, uint32_t faddr)
Andrew Vasquez459c5372005-07-06 10:31:07 -0700431{
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800432 return ha->flash_conf_off | faddr;
Andrew Vasquez459c5372005-07-06 10:31:07 -0700433}
434
435static inline uint32_t
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800436flash_data_addr(struct qla_hw_data *ha, uint32_t faddr)
Andrew Vasquez459c5372005-07-06 10:31:07 -0700437{
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800438 return ha->flash_data_off | faddr;
Andrew Vasquez459c5372005-07-06 10:31:07 -0700439}
440
441static inline uint32_t
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800442nvram_conf_addr(struct qla_hw_data *ha, uint32_t naddr)
Andrew Vasquez459c5372005-07-06 10:31:07 -0700443{
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800444 return ha->nvram_conf_off | naddr;
Andrew Vasquez459c5372005-07-06 10:31:07 -0700445}
446
447static inline uint32_t
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800448nvram_data_addr(struct qla_hw_data *ha, uint32_t naddr)
Andrew Vasquez459c5372005-07-06 10:31:07 -0700449{
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800450 return ha->nvram_data_off | naddr;
Andrew Vasquez459c5372005-07-06 10:31:07 -0700451}
452
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800453static uint32_t
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800454qla24xx_read_flash_dword(struct qla_hw_data *ha, uint32_t addr)
Andrew Vasquez459c5372005-07-06 10:31:07 -0700455{
456 int rval;
457 uint32_t cnt, data;
458 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
459
460 WRT_REG_DWORD(&reg->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(&reg->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 Vasquez40a2e342007-03-12 10:41:28 -0700470 cond_resched();
Andrew Vasquez459c5372005-07-06 10:31:07 -0700471 }
472
473 /* TODO: What happens if we time out? */
474 data = 0xDEADDEAD;
475 if (rval == QLA_SUCCESS)
476 data = RD_REG_DWORD(&reg->flash_data);
477
478 return data;
479}
480
481uint32_t *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800482qla24xx_read_flash_data(scsi_qla_host_t *vha, uint32_t *dwptr, uint32_t faddr,
Andrew Vasquez459c5372005-07-06 10:31:07 -0700483 uint32_t dwords)
484{
485 uint32_t i;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800486 struct qla_hw_data *ha = vha->hw;
487
Andrew Vasquez459c5372005-07-06 10:31:07 -0700488 /* Dword reads to flash. */
489 for (i = 0; i < dwords; i++, faddr++)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800490 dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
491 flash_data_addr(ha, faddr)));
Andrew Vasquez459c5372005-07-06 10:31:07 -0700492
Andrew Vasquez459c5372005-07-06 10:31:07 -0700493 return dwptr;
494}
495
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800496static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800497qla24xx_write_flash_dword(struct qla_hw_data *ha, uint32_t addr, uint32_t data)
Andrew Vasquez459c5372005-07-06 10:31:07 -0700498{
499 int rval;
500 uint32_t cnt;
501 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
502
503 WRT_REG_DWORD(&reg->flash_data, data);
504 RD_REG_DWORD(&reg->flash_data); /* PCI Posting. */
505 WRT_REG_DWORD(&reg->flash_addr, addr | FARX_DATA_FLAG);
506 /* Wait for Write cycle to complete. */
507 rval = QLA_SUCCESS;
508 for (cnt = 500000; (RD_REG_DWORD(&reg->flash_addr) & FARX_DATA_FLAG) &&
509 rval == QLA_SUCCESS; cnt--) {
510 if (cnt)
511 udelay(10);
512 else
513 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez40a2e342007-03-12 10:41:28 -0700514 cond_resched();
Andrew Vasquez459c5372005-07-06 10:31:07 -0700515 }
516 return rval;
517}
518
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800519static void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800520qla24xx_get_flash_manufacturer(struct qla_hw_data *ha, uint8_t *man_id,
Andrew Vasquez459c5372005-07-06 10:31:07 -0700521 uint8_t *flash_id)
522{
523 uint32_t ids;
524
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800525 ids = qla24xx_read_flash_dword(ha, flash_conf_addr(ha, 0x03ab));
Andrew Vasquez459c5372005-07-06 10:31:07 -0700526 *man_id = LSB(ids);
527 *flash_id = MSB(ids);
Ravi Anand45aeaf12006-05-17 15:08:49 -0700528
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 Vasquez3a03eb72009-01-05 11:18:11 -0800537 ids = qla24xx_read_flash_dword(ha, flash_conf_addr(ha, 0x009f));
Ravi Anand45aeaf12006-05-17 15:08:49 -0700538 *man_id = LSB(ids);
539 *flash_id = MSB(ids);
540 }
Andrew Vasquez459c5372005-07-06 10:31:07 -0700541}
542
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700543static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800544qla2xxx_find_flt_start(scsi_qla_host_t *vha, uint32_t *start)
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700545{
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 Chakraborty7b867cf2008-11-06 10:40:19 -0800552 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800553 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700554
555 /*
556 * FLT-location structure resides after the last PCI region.
557 */
558
559 /* Begin with sane defaults. */
560 loc = locations[0];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800561 *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 Malavalia9083012010-04-12 17:59:55 -0700568 else if (IS_QLA82XX(ha)) {
569 *start = FA_FLASH_LAYOUT_ADDR_82;
570 goto end;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800571 } else if (IS_QLA83XX(ha)) {
572 *start = FA_FLASH_LAYOUT_ADDR_83;
573 goto end;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700574 }
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700575 /* Begin with first PCI expansion ROM header. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800576 buf = (uint8_t *)req->ring;
577 dcode = (uint32_t *)req->ring;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700578 pcihdr = 0;
579 last_image = 1;
580 do {
581 /* Verify PCI expansion ROM header. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800582 qla24xx_read_flash_data(vha, dcode, pcihdr >> 2, 0x20);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700583 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 Chakraborty7b867cf2008-11-06 10:40:19 -0800589 qla24xx_read_flash_data(vha, dcode, pcids >> 2, 0x20);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700590 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 Chakraborty7b867cf2008-11-06 10:40:19 -0800604 fltl = (struct qla_flt_location *)req->ring;
605 qla24xx_read_flash_data(vha, dcode, pcihdr >> 2,
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700606 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 Chakraborty7b867cf2008-11-06 10:40:19 -0800611 wptr = (uint16_t *)req->ring;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700612 cnt = sizeof(struct qla_flt_location) >> 1;
613 for (chksum = 0; cnt; cnt--)
614 chksum += le16_to_cpu(*wptr++);
615 if (chksum) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700616 ql_log(ql_log_fatal, vha, 0x0045,
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700617 "Inconsistent FLTL detected: checksum=0x%x.\n", chksum);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700618 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010e,
619 buf, sizeof(struct qla_flt_location));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700620 return QLA_FUNCTION_FAILED;
621 }
622
623 /* Good data. Use specified location. */
624 loc = locations[1];
Harish Zunjarrao79c13a72009-03-24 09:08:19 -0700625 *start = (le16_to_cpu(fltl->start_hi) << 16 |
626 le16_to_cpu(fltl->start_lo)) >> 2;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700627end:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700628 ql_dbg(ql_dbg_init, vha, 0x0046,
629 "FLTL[%s] = 0x%x.\n",
630 loc, *start);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700631 return QLA_SUCCESS;
632}
633
634static void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800635qla2xxx_get_flt_info(scsi_qla_host_t *vha, uint32_t flt_addr)
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700636{
637 const char *loc, *locations[] = { "DEF", "FLT" };
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800638 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 Vasquez3d79038f2009-03-24 09:08:14 -0700644 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 Vasquez3a03eb72009-01-05 11:18:11 -0800652 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 Radke09ff7012010-03-19 17:03:59 -0700661 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 Vasquez3a03eb72009-01-05 11:18:11 -0800667 uint32_t def;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700668 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 Chakraborty7b867cf2008-11-06 10:40:19 -0800673 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800674 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700675
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500676 def = 0;
677 if (IS_QLA25XX(ha))
678 def = 1;
679 else if (IS_QLA81XX(ha))
680 def = 2;
Andrew Vasquezff8073f2010-12-21 16:00:16 -0800681
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 Vasquezc00d8992008-09-11 21:22:49 -0700688 ha->flt_region_flt = flt_addr;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800689 wptr = (uint16_t *)req->ring;
690 flt = (struct qla_flt_header *)req->ring;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700691 region = (struct qla_flt_region *)&flt[1];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800692 ha->isp_ops->read_optrom(vha, (uint8_t *)req->ring,
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700693 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 Kashyap7c3df132011-07-14 12:00:13 -0700697 ql_log(ql_log_warn, vha, 0x0047,
698 "Unsupported FLT detected: version=0x%x length=0x%x checksum=0x%x.\n",
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700699 le16_to_cpu(flt->version), le16_to_cpu(flt->length),
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700700 le16_to_cpu(flt->checksum));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700701 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 Kashyap7c3df132011-07-14 12:00:13 -0700708 ql_log(ql_log_fatal, vha, 0x0048,
709 "Inconsistent FLT detected: version=0x%x length=0x%x checksum=0x%x.\n",
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700710 le16_to_cpu(flt->version), le16_to_cpu(flt->length),
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700711 le16_to_cpu(flt->checksum));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700712 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 Kashyap7c3df132011-07-14 12:00:13 -0700720 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 Vasquezc00d8992008-09-11 21:22:49 -0700725
Andrew Vasquez90886082009-02-08 20:50:14 -0800726 switch (le32_to_cpu(region->code) & 0xff) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800727 case FLT_REG_FCOE_FW:
728 if (!IS_QLA8031(ha))
729 break;
730 ha->flt_region_fw = start;
731 break;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700732 case FLT_REG_FW:
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800733 if (IS_QLA8031(ha))
734 break;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700735 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 Malavali6246b8a2012-02-09 11:15:34 -0800741 if (IS_QLA8031(ha))
742 break;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700743 ha->flt_region_vpd_nvram = start;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700744 if (IS_QLA82XX(ha))
745 break;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -0700746 if (ha->flags.port0)
Andrew Vasquez3d79038f2009-03-24 09:08:14 -0700747 ha->flt_region_vpd = start;
748 break;
749 case FLT_REG_VPD_1:
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800750 if (IS_QLA82XX(ha) || IS_QLA8031(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -0700751 break;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -0700752 if (!ha->flags.port0)
Andrew Vasquez3d79038f2009-03-24 09:08:14 -0700753 ha->flt_region_vpd = start;
754 break;
755 case FLT_REG_NVRAM_0:
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800756 if (IS_QLA8031(ha))
757 break;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -0700758 if (ha->flags.port0)
Andrew Vasquez3d79038f2009-03-24 09:08:14 -0700759 ha->flt_region_nvram = start;
760 break;
761 case FLT_REG_NVRAM_1:
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800762 if (IS_QLA8031(ha))
763 break;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -0700764 if (!ha->flags.port0)
Andrew Vasquez3d79038f2009-03-24 09:08:14 -0700765 ha->flt_region_nvram = start;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700766 break;
767 case FLT_REG_FDT:
768 ha->flt_region_fdt = start;
769 break;
Andrew Vasquez272976c2008-09-11 21:22:50 -0700770 case FLT_REG_NPIV_CONF_0:
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -0700771 if (ha->flags.port0)
Andrew Vasquez272976c2008-09-11 21:22:50 -0700772 ha->flt_region_npiv_conf = start;
773 break;
774 case FLT_REG_NPIV_CONF_1:
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -0700775 if (!ha->flags.port0)
Andrew Vasquez272976c2008-09-11 21:22:50 -0700776 ha->flt_region_npiv_conf = start;
777 break;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -0700778 case FLT_REG_GOLD_FW:
779 ha->flt_region_gold_fw = start;
780 break;
Sarang Radke09ff7012010-03-19 17:03:59 -0700781 case FLT_REG_FCP_PRIO_0:
Sarang Radkebfdaa762010-03-19 17:04:01 -0700782 if (ha->flags.port0)
Sarang Radke09ff7012010-03-19 17:03:59 -0700783 ha->flt_region_fcp_prio = start;
784 break;
785 case FLT_REG_FCP_PRIO_1:
Sarang Radkebfdaa762010-03-19 17:04:01 -0700786 if (!ha->flags.port0)
Sarang Radke09ff7012010-03-19 17:03:59 -0700787 ha->flt_region_fcp_prio = start;
788 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700789 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;
801 case FLT_REG_VPD_82XX:
802 ha->flt_region_vpd = start;
803 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800804 case FLT_REG_FCOE_VPD_0:
805 if (!IS_QLA8031(ha))
806 break;
807 ha->flt_region_vpd_nvram = start;
808 if (ha->flags.port0)
809 ha->flt_region_vpd = start;
810 break;
811 case FLT_REG_FCOE_VPD_1:
812 if (!IS_QLA8031(ha))
813 break;
814 if (!ha->flags.port0)
815 ha->flt_region_vpd = start;
816 break;
817 case FLT_REG_FCOE_NVRAM_0:
818 if (!IS_QLA8031(ha))
819 break;
820 if (ha->flags.port0)
821 ha->flt_region_nvram = start;
822 break;
823 case FLT_REG_FCOE_NVRAM_1:
824 if (!IS_QLA8031(ha))
825 break;
826 if (!ha->flags.port0)
827 ha->flt_region_nvram = start;
828 break;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700829 }
830 }
831 goto done;
832
833no_flash_data:
834 /* Use hardcoded defaults. */
835 loc = locations[0];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800836 ha->flt_region_fw = def_fw[def];
837 ha->flt_region_boot = def_boot[def];
838 ha->flt_region_vpd_nvram = def_vpd_nvram[def];
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -0700839 ha->flt_region_vpd = ha->flags.port0 ?
Sarang Radke09ff7012010-03-19 17:03:59 -0700840 def_vpd0[def] : def_vpd1[def];
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -0700841 ha->flt_region_nvram = ha->flags.port0 ?
Sarang Radke09ff7012010-03-19 17:03:59 -0700842 def_nvram0[def] : def_nvram1[def];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800843 ha->flt_region_fdt = def_fdt[def];
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -0700844 ha->flt_region_npiv_conf = ha->flags.port0 ?
Sarang Radke09ff7012010-03-19 17:03:59 -0700845 def_npiv_conf0[def] : def_npiv_conf1[def];
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700846done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700847 ql_dbg(ql_dbg_init, vha, 0x004a,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800848 "FLT[%s]: boot=0x%x fw=0x%x vpd_nvram=0x%x vpd=0x%x nvram=0x%x "
849 "fdt=0x%x flt=0x%x npiv=0x%x fcp_prif_cfg=0x%x.\n",
850 loc, ha->flt_region_boot, ha->flt_region_fw,
851 ha->flt_region_vpd_nvram, ha->flt_region_vpd, ha->flt_region_nvram,
852 ha->flt_region_fdt, ha->flt_region_flt, ha->flt_region_npiv_conf,
853 ha->flt_region_fcp_prio);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700854}
855
856static void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800857qla2xxx_get_fdt_info(scsi_qla_host_t *vha)
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700858{
Lalit Chandivade821b3992008-10-24 15:13:44 -0700859#define FLASH_BLK_SIZE_4K 0x1000
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700860#define FLASH_BLK_SIZE_32K 0x8000
861#define FLASH_BLK_SIZE_64K 0x10000
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700862 const char *loc, *locations[] = { "MID", "FDT" };
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700863 uint16_t cnt, chksum;
864 uint16_t *wptr;
865 struct qla_fdt_layout *fdt;
866 uint8_t man_id, flash_id;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700867 uint16_t mid = 0, fid = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800868 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800869 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700870
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800871 wptr = (uint16_t *)req->ring;
872 fdt = (struct qla_fdt_layout *)req->ring;
873 ha->isp_ops->read_optrom(vha, (uint8_t *)req->ring,
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700874 ha->flt_region_fdt << 2, OPTROM_BURST_SIZE);
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700875 if (*wptr == __constant_cpu_to_le16(0xffff))
876 goto no_flash_data;
877 if (fdt->sig[0] != 'Q' || fdt->sig[1] != 'L' || fdt->sig[2] != 'I' ||
878 fdt->sig[3] != 'D')
879 goto no_flash_data;
880
881 for (cnt = 0, chksum = 0; cnt < sizeof(struct qla_fdt_layout) >> 1;
882 cnt++)
883 chksum += le16_to_cpu(*wptr++);
884 if (chksum) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700885 ql_dbg(ql_dbg_init, vha, 0x004c,
886 "Inconsistent FDT detected:"
887 " checksum=0x%x id=%c version0x%x.\n", chksum,
888 fdt->sig[0], le16_to_cpu(fdt->version));
889 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0113,
890 (uint8_t *)fdt, sizeof(*fdt));
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700891 goto no_flash_data;
892 }
893
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700894 loc = locations[1];
895 mid = le16_to_cpu(fdt->man_id);
896 fid = le16_to_cpu(fdt->id);
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700897 ha->fdt_wrt_disable = fdt->wrt_disable_bits;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800898 ha->fdt_erase_cmd = flash_conf_addr(ha, 0x0300 | fdt->erase_cmd);
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700899 ha->fdt_block_size = le32_to_cpu(fdt->block_size);
900 if (fdt->unprotect_sec_cmd) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800901 ha->fdt_unprotect_sec_cmd = flash_conf_addr(ha, 0x0300 |
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700902 fdt->unprotect_sec_cmd);
903 ha->fdt_protect_sec_cmd = fdt->protect_sec_cmd ?
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800904 flash_conf_addr(ha, 0x0300 | fdt->protect_sec_cmd):
905 flash_conf_addr(ha, 0x0336);
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700906 }
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700907 goto done;
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700908no_flash_data:
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700909 loc = locations[0];
Giridhar Malavalia9083012010-04-12 17:59:55 -0700910 if (IS_QLA82XX(ha)) {
911 ha->fdt_block_size = FLASH_BLK_SIZE_64K;
912 goto done;
913 }
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700914 qla24xx_get_flash_manufacturer(ha, &man_id, &flash_id);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700915 mid = man_id;
916 fid = flash_id;
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700917 ha->fdt_wrt_disable = 0x9c;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800918 ha->fdt_erase_cmd = flash_conf_addr(ha, 0x03d8);
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700919 switch (man_id) {
920 case 0xbf: /* STT flash. */
921 if (flash_id == 0x8e)
922 ha->fdt_block_size = FLASH_BLK_SIZE_64K;
923 else
924 ha->fdt_block_size = FLASH_BLK_SIZE_32K;
925
926 if (flash_id == 0x80)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800927 ha->fdt_erase_cmd = flash_conf_addr(ha, 0x0352);
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700928 break;
929 case 0x13: /* ST M25P80. */
930 ha->fdt_block_size = FLASH_BLK_SIZE_64K;
931 break;
932 case 0x1f: /* Atmel 26DF081A. */
Lalit Chandivade821b3992008-10-24 15:13:44 -0700933 ha->fdt_block_size = FLASH_BLK_SIZE_4K;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800934 ha->fdt_erase_cmd = flash_conf_addr(ha, 0x0320);
935 ha->fdt_unprotect_sec_cmd = flash_conf_addr(ha, 0x0339);
936 ha->fdt_protect_sec_cmd = flash_conf_addr(ha, 0x0336);
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700937 break;
938 default:
939 /* Default to 64 kb sector size. */
940 ha->fdt_block_size = FLASH_BLK_SIZE_64K;
941 break;
942 }
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700943done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700944 ql_dbg(ql_dbg_init, vha, 0x004d,
Joe Perchesd8424f62011-11-18 09:03:06 -0800945 "FDT[%s]: (0x%x/0x%x) erase=0x%x "
946 "pr=%x wrtd=0x%x blk=0x%x.\n",
947 loc, mid, fid,
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700948 ha->fdt_erase_cmd, ha->fdt_protect_sec_cmd,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700949 ha->fdt_wrt_disable, ha->fdt_block_size);
950
Andrew Vasquez7d232c72008-04-03 13:13:22 -0700951}
952
Giridhar Malavalia9083012010-04-12 17:59:55 -0700953static void
954qla2xxx_get_idc_param(scsi_qla_host_t *vha)
955{
956#define QLA82XX_IDC_PARAM_ADDR 0x003e885c
957 uint32_t *wptr;
958 struct qla_hw_data *ha = vha->hw;
959 struct req_que *req = ha->req_q_map[0];
960
961 if (!IS_QLA82XX(ha))
962 return;
963
964 wptr = (uint32_t *)req->ring;
965 ha->isp_ops->read_optrom(vha, (uint8_t *)req->ring,
966 QLA82XX_IDC_PARAM_ADDR , 8);
967
968 if (*wptr == __constant_cpu_to_le32(0xffffffff)) {
969 ha->nx_dev_init_timeout = QLA82XX_ROM_DEV_INIT_TIMEOUT;
970 ha->nx_reset_timeout = QLA82XX_ROM_DRV_RESET_ACK_TIMEOUT;
971 } else {
972 ha->nx_dev_init_timeout = le32_to_cpu(*wptr++);
973 ha->nx_reset_timeout = le32_to_cpu(*wptr);
974 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700975 ql_dbg(ql_dbg_init, vha, 0x004e,
976 "nx_dev_init_timeout=%d "
977 "nx_reset_timeout=%d.\n", ha->nx_dev_init_timeout,
978 ha->nx_reset_timeout);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700979 return;
980}
981
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700982int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800983qla2xxx_get_flash_info(scsi_qla_host_t *vha)
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700984{
985 int ret;
986 uint32_t flt_addr;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800987 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700988
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800989 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
990 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha))
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700991 return QLA_SUCCESS;
992
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800993 ret = qla2xxx_find_flt_start(vha, &flt_addr);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700994 if (ret != QLA_SUCCESS)
995 return ret;
996
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800997 qla2xxx_get_flt_info(vha, flt_addr);
998 qla2xxx_get_fdt_info(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700999 qla2xxx_get_idc_param(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001000
1001 return QLA_SUCCESS;
1002}
1003
Andrew Vasquez272976c2008-09-11 21:22:50 -07001004void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001005qla2xxx_flash_npiv_conf(scsi_qla_host_t *vha)
Andrew Vasquez272976c2008-09-11 21:22:50 -07001006{
1007#define NPIV_CONFIG_SIZE (16*1024)
1008 void *data;
1009 uint16_t *wptr;
1010 uint16_t cnt, chksum;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001011 int i;
Andrew Vasquez272976c2008-09-11 21:22:50 -07001012 struct qla_npiv_header hdr;
1013 struct qla_npiv_entry *entry;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001014 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez272976c2008-09-11 21:22:50 -07001015
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001016 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
1017 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha))
Andrew Vasquez272976c2008-09-11 21:22:50 -07001018 return;
1019
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001020 ha->isp_ops->read_optrom(vha, (uint8_t *)&hdr,
Andrew Vasquez272976c2008-09-11 21:22:50 -07001021 ha->flt_region_npiv_conf << 2, sizeof(struct qla_npiv_header));
1022 if (hdr.version == __constant_cpu_to_le16(0xffff))
1023 return;
1024 if (hdr.version != __constant_cpu_to_le16(1)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001025 ql_dbg(ql_dbg_user, vha, 0x7090,
1026 "Unsupported NPIV-Config "
Andrew Vasquez272976c2008-09-11 21:22:50 -07001027 "detected: version=0x%x entries=0x%x checksum=0x%x.\n",
1028 le16_to_cpu(hdr.version), le16_to_cpu(hdr.entries),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001029 le16_to_cpu(hdr.checksum));
Andrew Vasquez272976c2008-09-11 21:22:50 -07001030 return;
1031 }
1032
1033 data = kmalloc(NPIV_CONFIG_SIZE, GFP_KERNEL);
1034 if (!data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001035 ql_log(ql_log_warn, vha, 0x7091,
1036 "Unable to allocate memory for data.\n");
Andrew Vasquez272976c2008-09-11 21:22:50 -07001037 return;
1038 }
1039
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001040 ha->isp_ops->read_optrom(vha, (uint8_t *)data,
Andrew Vasquez272976c2008-09-11 21:22:50 -07001041 ha->flt_region_npiv_conf << 2, NPIV_CONFIG_SIZE);
1042
1043 cnt = (sizeof(struct qla_npiv_header) + le16_to_cpu(hdr.entries) *
1044 sizeof(struct qla_npiv_entry)) >> 1;
1045 for (wptr = data, chksum = 0; cnt; cnt--)
1046 chksum += le16_to_cpu(*wptr++);
1047 if (chksum) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001048 ql_dbg(ql_dbg_user, vha, 0x7092,
1049 "Inconsistent NPIV-Config "
Andrew Vasquez272976c2008-09-11 21:22:50 -07001050 "detected: version=0x%x entries=0x%x checksum=0x%x.\n",
1051 le16_to_cpu(hdr.version), le16_to_cpu(hdr.entries),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001052 le16_to_cpu(hdr.checksum));
Andrew Vasquez272976c2008-09-11 21:22:50 -07001053 goto done;
1054 }
1055
1056 entry = data + sizeof(struct qla_npiv_header);
1057 cnt = le16_to_cpu(hdr.entries);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001058 for (i = 0; cnt; cnt--, entry++, i++) {
Andrew Vasquez272976c2008-09-11 21:22:50 -07001059 uint16_t flags;
1060 struct fc_vport_identifiers vid;
1061 struct fc_vport *vport;
1062
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001063 memcpy(&ha->npiv_info[i], entry, sizeof(struct qla_npiv_entry));
1064
Andrew Vasquez272976c2008-09-11 21:22:50 -07001065 flags = le16_to_cpu(entry->flags);
1066 if (flags == 0xffff)
1067 continue;
1068 if ((flags & BIT_0) == 0)
1069 continue;
1070
1071 memset(&vid, 0, sizeof(vid));
1072 vid.roles = FC_PORT_ROLE_FCP_INITIATOR;
1073 vid.vport_type = FC_PORTTYPE_NPIV;
1074 vid.disable = false;
1075 vid.port_name = wwn_to_u64(entry->port_name);
1076 vid.node_name = wwn_to_u64(entry->node_name);
1077
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001078 ql_dbg(ql_dbg_user, vha, 0x7093,
1079 "NPIV[%02x]: wwpn=%llx "
1080 "wwnn=%llx vf_id=0x%x Q_qos=0x%x F_qos=0x%x.\n", cnt,
1081 (unsigned long long)vid.port_name,
1082 (unsigned long long)vid.node_name,
1083 le16_to_cpu(entry->vf_id),
1084 entry->q_qos, entry->f_qos);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001085
1086 if (i < QLA_PRECONFIG_VPORTS) {
1087 vport = fc_vport_create(vha->host, 0, &vid);
1088 if (!vport)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001089 ql_log(ql_log_warn, vha, 0x7094,
1090 "NPIV-Config Failed to create vport [%02x]: "
1091 "wwpn=%llx wwnn=%llx.\n", cnt,
1092 (unsigned long long)vid.port_name,
1093 (unsigned long long)vid.node_name);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001094 }
Andrew Vasquez272976c2008-09-11 21:22:50 -07001095 }
1096done:
1097 kfree(data);
1098}
1099
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001100static int
1101qla24xx_unprotect_flash(scsi_qla_host_t *vha)
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001102{
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001103 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001104 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1105
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001106 if (ha->flags.fac_supported)
1107 return qla81xx_fac_do_write_enable(vha, 1);
1108
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001109 /* Enable flash write. */
1110 WRT_REG_DWORD(&reg->ctrl_status,
1111 RD_REG_DWORD(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
1112 RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
1113
Andrew Vasquez7d232c72008-04-03 13:13:22 -07001114 if (!ha->fdt_wrt_disable)
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001115 goto done;
Andrew Vasquez7d232c72008-04-03 13:13:22 -07001116
Joe Carnucciob872ca42009-01-22 09:45:36 -08001117 /* Disable flash write-protection, first clear SR protection bit */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001118 qla24xx_write_flash_dword(ha, flash_conf_addr(ha, 0x101), 0);
Joe Carnucciob872ca42009-01-22 09:45:36 -08001119 /* Then write zero again to clear remaining SR bits.*/
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001120 qla24xx_write_flash_dword(ha, flash_conf_addr(ha, 0x101), 0);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001121done:
1122 return QLA_SUCCESS;
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001123}
1124
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001125static int
1126qla24xx_protect_flash(scsi_qla_host_t *vha)
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001127{
1128 uint32_t cnt;
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001129 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001130 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1131
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001132 if (ha->flags.fac_supported)
1133 return qla81xx_fac_do_write_enable(vha, 0);
1134
Andrew Vasquez7d232c72008-04-03 13:13:22 -07001135 if (!ha->fdt_wrt_disable)
1136 goto skip_wrt_protect;
1137
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001138 /* Enable flash write-protection and wait for completion. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001139 qla24xx_write_flash_dword(ha, flash_conf_addr(ha, 0x101),
Andrew Vasquez7d232c72008-04-03 13:13:22 -07001140 ha->fdt_wrt_disable);
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001141 for (cnt = 300; cnt &&
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001142 qla24xx_read_flash_dword(ha, flash_conf_addr(ha, 0x005)) & BIT_0;
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001143 cnt--) {
1144 udelay(10);
1145 }
1146
Andrew Vasquez7d232c72008-04-03 13:13:22 -07001147skip_wrt_protect:
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001148 /* Disable flash write. */
1149 WRT_REG_DWORD(&reg->ctrl_status,
1150 RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
1151 RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001152
1153 return QLA_SUCCESS;
1154}
1155
1156static int
1157qla24xx_erase_sector(scsi_qla_host_t *vha, uint32_t fdata)
1158{
1159 struct qla_hw_data *ha = vha->hw;
1160 uint32_t start, finish;
1161
1162 if (ha->flags.fac_supported) {
1163 start = fdata >> 2;
1164 finish = start + (ha->fdt_block_size >> 2) - 1;
1165 return qla81xx_fac_erase_sector(vha, flash_data_addr(ha,
1166 start), flash_data_addr(ha, finish));
1167 }
1168
1169 return qla24xx_write_flash_dword(ha, ha->fdt_erase_cmd,
1170 (fdata & 0xff00) | ((fdata << 16) & 0xff0000) |
1171 ((fdata >> 16) & 0xff));
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001172}
1173
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001174static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001175qla24xx_write_flash_data(scsi_qla_host_t *vha, uint32_t *dwptr, uint32_t faddr,
Andrew Vasquez459c5372005-07-06 10:31:07 -07001176 uint32_t dwords)
1177{
1178 int ret;
Andrew Vasquez7c283172009-01-22 09:45:34 -08001179 uint32_t liter;
Andrew Vasquez7d232c72008-04-03 13:13:22 -07001180 uint32_t sec_mask, rest_addr;
Andrew Vasquez85d0acb2009-01-22 09:45:29 -08001181 uint32_t fdata;
Andrew Vasquez338c9162007-09-20 14:07:33 -07001182 dma_addr_t optrom_dma;
1183 void *optrom = NULL;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001184 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez459c5372005-07-06 10:31:07 -07001185
Andrew Vasquez338c9162007-09-20 14:07:33 -07001186 /* Prepare burst-capable write on supported ISPs. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001187 if ((IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha)) &&
1188 !(faddr & 0xfff) && dwords > OPTROM_BURST_DWORDS) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07001189 optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
1190 &optrom_dma, GFP_KERNEL);
1191 if (!optrom) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001192 ql_log(ql_log_warn, vha, 0x7095,
1193 "Unable to allocate "
1194 "memory for optrom burst write (%x KB).\n",
1195 OPTROM_BURST_SIZE / 1024);
Andrew Vasquez338c9162007-09-20 14:07:33 -07001196 }
1197 }
1198
Andrew Vasquez7d232c72008-04-03 13:13:22 -07001199 rest_addr = (ha->fdt_block_size >> 2) - 1;
Andrew Vasquez85d0acb2009-01-22 09:45:29 -08001200 sec_mask = ~rest_addr;
Andrew Vasquez459c5372005-07-06 10:31:07 -07001201
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001202 ret = qla24xx_unprotect_flash(vha);
1203 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001204 ql_log(ql_log_warn, vha, 0x7096,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001205 "Unable to unprotect flash for update.\n");
1206 goto done;
1207 }
Andrew Vasquez459c5372005-07-06 10:31:07 -07001208
Andrew Vasquez338c9162007-09-20 14:07:33 -07001209 for (liter = 0; liter < dwords; liter++, faddr++, dwptr++) {
Andrew Vasquez85d0acb2009-01-22 09:45:29 -08001210 fdata = (faddr & sec_mask) << 2;
Ravi Anand45aeaf12006-05-17 15:08:49 -07001211
Andrew Vasquez338c9162007-09-20 14:07:33 -07001212 /* Are we at the beginning of a sector? */
Andrew Vasquez85d0acb2009-01-22 09:45:29 -08001213 if ((faddr & rest_addr) == 0) {
Andrew Vasquez7d232c72008-04-03 13:13:22 -07001214 /* Do sector unprotect. */
1215 if (ha->fdt_unprotect_sec_cmd)
Ravi Anand45aeaf12006-05-17 15:08:49 -07001216 qla24xx_write_flash_dword(ha,
Andrew Vasquez7d232c72008-04-03 13:13:22 -07001217 ha->fdt_unprotect_sec_cmd,
Ravi Anand45aeaf12006-05-17 15:08:49 -07001218 (fdata & 0xff00) | ((fdata << 16) &
1219 0xff0000) | ((fdata >> 16) & 0xff));
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001220 ret = qla24xx_erase_sector(vha, fdata);
Andrew Vasquez338c9162007-09-20 14:07:33 -07001221 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001222 ql_dbg(ql_dbg_user, vha, 0x7007,
1223 "Unable to erase erase sector: address=%x.\n",
1224 faddr);
Andrew Vasquez338c9162007-09-20 14:07:33 -07001225 break;
1226 }
Andrew Vasquez459c5372005-07-06 10:31:07 -07001227 }
Andrew Vasquez338c9162007-09-20 14:07:33 -07001228
1229 /* Go with burst-write. */
Andrew Vasquez94d6a2b2007-10-19 15:59:16 -07001230 if (optrom && (liter + OPTROM_BURST_DWORDS) <= dwords) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07001231 /* Copy data to DMA'ble buffer. */
Andrew Vasquez7c283172009-01-22 09:45:34 -08001232 memcpy(optrom, dwptr, OPTROM_BURST_SIZE);
Andrew Vasquez338c9162007-09-20 14:07:33 -07001233
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001234 ret = qla2x00_load_ram(vha, optrom_dma,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001235 flash_data_addr(ha, faddr),
Andrew Vasquez338c9162007-09-20 14:07:33 -07001236 OPTROM_BURST_DWORDS);
1237 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001238 ql_log(ql_log_warn, vha, 0x7097,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001239 "Unable to burst-write optrom segment "
1240 "(%x/%x/%llx).\n", ret,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001241 flash_data_addr(ha, faddr),
Andrew Morton875baf32007-10-16 14:28:20 -07001242 (unsigned long long)optrom_dma);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001243 ql_log(ql_log_warn, vha, 0x7098,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001244 "Reverting to slow-write.\n");
1245
1246 dma_free_coherent(&ha->pdev->dev,
1247 OPTROM_BURST_SIZE, optrom, optrom_dma);
1248 optrom = NULL;
1249 } else {
1250 liter += OPTROM_BURST_DWORDS - 1;
1251 faddr += OPTROM_BURST_DWORDS - 1;
1252 dwptr += OPTROM_BURST_DWORDS - 1;
1253 continue;
1254 }
1255 }
1256
1257 ret = qla24xx_write_flash_dword(ha,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001258 flash_data_addr(ha, faddr), cpu_to_le32(*dwptr));
Andrew Vasquez338c9162007-09-20 14:07:33 -07001259 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001260 ql_dbg(ql_dbg_user, vha, 0x7006,
1261 "Unable to program flash address=%x data=%x.\n",
1262 faddr, *dwptr);
Andrew Vasquez338c9162007-09-20 14:07:33 -07001263 break;
1264 }
1265
Andrew Vasquez7d232c72008-04-03 13:13:22 -07001266 /* Do sector protect. */
1267 if (ha->fdt_unprotect_sec_cmd &&
Andrew Vasquez338c9162007-09-20 14:07:33 -07001268 ((faddr & rest_addr) == rest_addr))
1269 qla24xx_write_flash_dword(ha,
Andrew Vasquez7d232c72008-04-03 13:13:22 -07001270 ha->fdt_protect_sec_cmd,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001271 (fdata & 0xff00) | ((fdata << 16) &
1272 0xff0000) | ((fdata >> 16) & 0xff));
1273 }
Andrew Vasquez459c5372005-07-06 10:31:07 -07001274
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001275 ret = qla24xx_protect_flash(vha);
1276 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001277 ql_log(ql_log_warn, vha, 0x7099,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001278 "Unable to protect flash after update.\n");
1279done:
Andrew Vasquez338c9162007-09-20 14:07:33 -07001280 if (optrom)
1281 dma_free_coherent(&ha->pdev->dev,
1282 OPTROM_BURST_SIZE, optrom, optrom_dma);
1283
Andrew Vasquez459c5372005-07-06 10:31:07 -07001284 return ret;
1285}
1286
1287uint8_t *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001288qla2x00_read_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
Andrew Vasquez459c5372005-07-06 10:31:07 -07001289 uint32_t bytes)
1290{
1291 uint32_t i;
1292 uint16_t *wptr;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001293 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez459c5372005-07-06 10:31:07 -07001294
1295 /* Word reads to NVRAM via registers. */
1296 wptr = (uint16_t *)buf;
1297 qla2x00_lock_nvram_access(ha);
1298 for (i = 0; i < bytes >> 1; i++, naddr++)
1299 wptr[i] = cpu_to_le16(qla2x00_get_nvram_word(ha,
1300 naddr));
1301 qla2x00_unlock_nvram_access(ha);
1302
1303 return buf;
1304}
1305
1306uint8_t *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001307qla24xx_read_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
Andrew Vasquez459c5372005-07-06 10:31:07 -07001308 uint32_t bytes)
1309{
1310 uint32_t i;
1311 uint32_t *dwptr;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001312 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez459c5372005-07-06 10:31:07 -07001313
Giridhar Malavalia9083012010-04-12 17:59:55 -07001314 if (IS_QLA82XX(ha))
1315 return buf;
1316
Andrew Vasquez459c5372005-07-06 10:31:07 -07001317 /* Dword reads to flash. */
1318 dwptr = (uint32_t *)buf;
1319 for (i = 0; i < bytes >> 2; i++, naddr++)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001320 dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
1321 nvram_data_addr(ha, naddr)));
Andrew Vasquez459c5372005-07-06 10:31:07 -07001322
Andrew Vasquez459c5372005-07-06 10:31:07 -07001323 return buf;
1324}
1325
1326int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001327qla2x00_write_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
Andrew Vasquez459c5372005-07-06 10:31:07 -07001328 uint32_t bytes)
1329{
1330 int ret, stat;
1331 uint32_t i;
1332 uint16_t *wptr;
Andrew Vasquez2c96d8d2007-10-19 15:59:15 -07001333 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001334 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez459c5372005-07-06 10:31:07 -07001335
1336 ret = QLA_SUCCESS;
1337
Andrew Vasquez2c96d8d2007-10-19 15:59:15 -07001338 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez459c5372005-07-06 10:31:07 -07001339 qla2x00_lock_nvram_access(ha);
1340
1341 /* Disable NVRAM write-protection. */
1342 stat = qla2x00_clear_nvram_protection(ha);
1343
1344 wptr = (uint16_t *)buf;
1345 for (i = 0; i < bytes >> 1; i++, naddr++) {
1346 qla2x00_write_nvram_word(ha, naddr,
1347 cpu_to_le16(*wptr));
1348 wptr++;
1349 }
1350
1351 /* Enable NVRAM write-protection. */
1352 qla2x00_set_nvram_protection(ha, stat);
1353
1354 qla2x00_unlock_nvram_access(ha);
Andrew Vasquez2c96d8d2007-10-19 15:59:15 -07001355 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez459c5372005-07-06 10:31:07 -07001356
1357 return ret;
1358}
1359
1360int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001361qla24xx_write_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
Andrew Vasquez459c5372005-07-06 10:31:07 -07001362 uint32_t bytes)
1363{
1364 int ret;
1365 uint32_t i;
1366 uint32_t *dwptr;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001367 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez459c5372005-07-06 10:31:07 -07001368 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1369
1370 ret = QLA_SUCCESS;
1371
Giridhar Malavalia9083012010-04-12 17:59:55 -07001372 if (IS_QLA82XX(ha))
1373 return ret;
1374
Andrew Vasquez459c5372005-07-06 10:31:07 -07001375 /* Enable flash write. */
1376 WRT_REG_DWORD(&reg->ctrl_status,
1377 RD_REG_DWORD(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
1378 RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
1379
1380 /* Disable NVRAM write-protection. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001381 qla24xx_write_flash_dword(ha, nvram_conf_addr(ha, 0x101), 0);
1382 qla24xx_write_flash_dword(ha, nvram_conf_addr(ha, 0x101), 0);
Andrew Vasquez459c5372005-07-06 10:31:07 -07001383
1384 /* Dword writes to flash. */
1385 dwptr = (uint32_t *)buf;
1386 for (i = 0; i < bytes >> 2; i++, naddr++, dwptr++) {
1387 ret = qla24xx_write_flash_dword(ha,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001388 nvram_data_addr(ha, naddr), cpu_to_le32(*dwptr));
Andrew Vasquez459c5372005-07-06 10:31:07 -07001389 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001390 ql_dbg(ql_dbg_user, vha, 0x709a,
Andrew Vasquez76403352009-04-06 22:33:39 -07001391 "Unable to program nvram address=%x data=%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001392 naddr, *dwptr);
Andrew Vasquez459c5372005-07-06 10:31:07 -07001393 break;
1394 }
1395 }
1396
1397 /* Enable NVRAM write-protection. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001398 qla24xx_write_flash_dword(ha, nvram_conf_addr(ha, 0x101), 0x8c);
Andrew Vasquez459c5372005-07-06 10:31:07 -07001399
1400 /* Disable flash write. */
1401 WRT_REG_DWORD(&reg->ctrl_status,
1402 RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
1403 RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
1404
Andrew Vasquez459c5372005-07-06 10:31:07 -07001405 return ret;
1406}
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001407
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001408uint8_t *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001409qla25xx_read_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001410 uint32_t bytes)
1411{
1412 uint32_t i;
1413 uint32_t *dwptr;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001414 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001415
1416 /* Dword reads to flash. */
1417 dwptr = (uint32_t *)buf;
1418 for (i = 0; i < bytes >> 2; i++, naddr++)
1419 dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001420 flash_data_addr(ha, ha->flt_region_vpd_nvram | naddr)));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001421
1422 return buf;
1423}
1424
1425int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001426qla25xx_write_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001427 uint32_t bytes)
1428{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001429 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez2c96d8d2007-10-19 15:59:15 -07001430#define RMW_BUFFER_SIZE (64 * 1024)
1431 uint8_t *dbuf;
1432
1433 dbuf = vmalloc(RMW_BUFFER_SIZE);
1434 if (!dbuf)
1435 return QLA_MEMORY_ALLOC_FAILED;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001436 ha->isp_ops->read_optrom(vha, dbuf, ha->flt_region_vpd_nvram << 2,
Andrew Vasquez2c96d8d2007-10-19 15:59:15 -07001437 RMW_BUFFER_SIZE);
1438 memcpy(dbuf + (naddr << 2), buf, bytes);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001439 ha->isp_ops->write_optrom(vha, dbuf, ha->flt_region_vpd_nvram << 2,
Andrew Vasquez2c96d8d2007-10-19 15:59:15 -07001440 RMW_BUFFER_SIZE);
1441 vfree(dbuf);
1442
1443 return QLA_SUCCESS;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001444}
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001445
1446static inline void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001447qla2x00_flip_colors(struct qla_hw_data *ha, uint16_t *pflags)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001448{
1449 if (IS_QLA2322(ha)) {
1450 /* Flip all colors. */
1451 if (ha->beacon_color_state == QLA_LED_ALL_ON) {
1452 /* Turn off. */
1453 ha->beacon_color_state = 0;
1454 *pflags = GPIO_LED_ALL_OFF;
1455 } else {
1456 /* Turn on. */
1457 ha->beacon_color_state = QLA_LED_ALL_ON;
1458 *pflags = GPIO_LED_RGA_ON;
1459 }
1460 } else {
1461 /* Flip green led only. */
1462 if (ha->beacon_color_state == QLA_LED_GRN_ON) {
1463 /* Turn off. */
1464 ha->beacon_color_state = 0;
1465 *pflags = GPIO_LED_GREEN_OFF_AMBER_OFF;
1466 } else {
1467 /* Turn on. */
1468 ha->beacon_color_state = QLA_LED_GRN_ON;
1469 *pflags = GPIO_LED_GREEN_ON_AMBER_OFF;
1470 }
1471 }
1472}
1473
Andrew Vasquez948882f2008-01-31 12:33:44 -08001474#define PIO_REG(h, r) ((h)->pio_address + offsetof(struct device_reg_2xxx, r))
1475
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001476void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001477qla2x00_beacon_blink(struct scsi_qla_host *vha)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001478{
1479 uint16_t gpio_enable;
1480 uint16_t gpio_data;
1481 uint16_t led_color = 0;
1482 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001483 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001484 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1485
Giridhar Malavalia9083012010-04-12 17:59:55 -07001486 if (IS_QLA82XX(ha))
1487 return;
1488
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001489 spin_lock_irqsave(&ha->hardware_lock, flags);
1490
1491 /* Save the Original GPIOE. */
1492 if (ha->pio_address) {
Andrew Vasquez948882f2008-01-31 12:33:44 -08001493 gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
1494 gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001495 } else {
1496 gpio_enable = RD_REG_WORD(&reg->gpioe);
1497 gpio_data = RD_REG_WORD(&reg->gpiod);
1498 }
1499
1500 /* Set the modified gpio_enable values */
1501 gpio_enable |= GPIO_LED_MASK;
1502
1503 if (ha->pio_address) {
Andrew Vasquez948882f2008-01-31 12:33:44 -08001504 WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001505 } else {
1506 WRT_REG_WORD(&reg->gpioe, gpio_enable);
1507 RD_REG_WORD(&reg->gpioe);
1508 }
1509
1510 qla2x00_flip_colors(ha, &led_color);
1511
1512 /* Clear out any previously set LED color. */
1513 gpio_data &= ~GPIO_LED_MASK;
1514
1515 /* Set the new input LED color to GPIOD. */
1516 gpio_data |= led_color;
1517
1518 /* Set the modified gpio_data values */
1519 if (ha->pio_address) {
Andrew Vasquez948882f2008-01-31 12:33:44 -08001520 WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001521 } else {
1522 WRT_REG_WORD(&reg->gpiod, gpio_data);
1523 RD_REG_WORD(&reg->gpiod);
1524 }
1525
1526 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1527}
1528
1529int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001530qla2x00_beacon_on(struct scsi_qla_host *vha)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001531{
1532 uint16_t gpio_enable;
1533 uint16_t gpio_data;
1534 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001535 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001536 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1537
1538 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1539 ha->fw_options[1] |= FO1_DISABLE_GPIO6_7;
1540
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001541 if (qla2x00_set_fw_options(vha, ha->fw_options) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001542 ql_log(ql_log_warn, vha, 0x709b,
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001543 "Unable to update fw options (beacon on).\n");
1544 return QLA_FUNCTION_FAILED;
1545 }
1546
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001547 /* Turn off LEDs. */
1548 spin_lock_irqsave(&ha->hardware_lock, flags);
1549 if (ha->pio_address) {
Andrew Vasquez948882f2008-01-31 12:33:44 -08001550 gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
1551 gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001552 } else {
1553 gpio_enable = RD_REG_WORD(&reg->gpioe);
1554 gpio_data = RD_REG_WORD(&reg->gpiod);
1555 }
1556 gpio_enable |= GPIO_LED_MASK;
1557
1558 /* Set the modified gpio_enable values. */
1559 if (ha->pio_address) {
Andrew Vasquez948882f2008-01-31 12:33:44 -08001560 WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001561 } else {
1562 WRT_REG_WORD(&reg->gpioe, gpio_enable);
1563 RD_REG_WORD(&reg->gpioe);
1564 }
1565
1566 /* Clear out previously set LED colour. */
1567 gpio_data &= ~GPIO_LED_MASK;
1568 if (ha->pio_address) {
Andrew Vasquez948882f2008-01-31 12:33:44 -08001569 WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001570 } else {
1571 WRT_REG_WORD(&reg->gpiod, gpio_data);
1572 RD_REG_WORD(&reg->gpiod);
1573 }
1574 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1575
1576 /*
1577 * Let the per HBA timer kick off the blinking process based on
1578 * the following flags. No need to do anything else now.
1579 */
1580 ha->beacon_blink_led = 1;
1581 ha->beacon_color_state = 0;
1582
1583 return QLA_SUCCESS;
1584}
1585
1586int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001587qla2x00_beacon_off(struct scsi_qla_host *vha)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001588{
1589 int rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001590 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001591
1592 ha->beacon_blink_led = 0;
1593
1594 /* Set the on flag so when it gets flipped it will be off. */
1595 if (IS_QLA2322(ha))
1596 ha->beacon_color_state = QLA_LED_ALL_ON;
1597 else
1598 ha->beacon_color_state = QLA_LED_GRN_ON;
1599
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001600 ha->isp_ops->beacon_blink(vha); /* This turns green LED off */
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001601
1602 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1603 ha->fw_options[1] &= ~FO1_DISABLE_GPIO6_7;
1604
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001605 rval = qla2x00_set_fw_options(vha, ha->fw_options);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001606 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001607 ql_log(ql_log_warn, vha, 0x709c,
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001608 "Unable to update fw options (beacon off).\n");
1609 return rval;
1610}
1611
1612
1613static inline void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001614qla24xx_flip_colors(struct qla_hw_data *ha, uint16_t *pflags)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001615{
1616 /* Flip all colors. */
1617 if (ha->beacon_color_state == QLA_LED_ALL_ON) {
1618 /* Turn off. */
1619 ha->beacon_color_state = 0;
1620 *pflags = 0;
1621 } else {
1622 /* Turn on. */
1623 ha->beacon_color_state = QLA_LED_ALL_ON;
1624 *pflags = GPDX_LED_YELLOW_ON | GPDX_LED_AMBER_ON;
1625 }
1626}
1627
1628void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001629qla24xx_beacon_blink(struct scsi_qla_host *vha)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001630{
1631 uint16_t led_color = 0;
1632 uint32_t gpio_data;
1633 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001634 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001635 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1636
1637 /* Save the Original GPIOD. */
1638 spin_lock_irqsave(&ha->hardware_lock, flags);
1639 gpio_data = RD_REG_DWORD(&reg->gpiod);
1640
1641 /* Enable the gpio_data reg for update. */
1642 gpio_data |= GPDX_LED_UPDATE_MASK;
1643
1644 WRT_REG_DWORD(&reg->gpiod, gpio_data);
1645 gpio_data = RD_REG_DWORD(&reg->gpiod);
1646
1647 /* Set the color bits. */
1648 qla24xx_flip_colors(ha, &led_color);
1649
1650 /* Clear out any previously set LED color. */
1651 gpio_data &= ~GPDX_LED_COLOR_MASK;
1652
1653 /* Set the new input LED color to GPIOD. */
1654 gpio_data |= led_color;
1655
1656 /* Set the modified gpio_data values. */
1657 WRT_REG_DWORD(&reg->gpiod, gpio_data);
1658 gpio_data = RD_REG_DWORD(&reg->gpiod);
1659 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1660}
1661
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001662void
1663qla83xx_beacon_blink(struct scsi_qla_host *vha)
1664{
1665 uint32_t led_select_value;
1666 struct qla_hw_data *ha = vha->hw;
1667 uint16_t led_cfg[6];
1668 uint16_t orig_led_cfg[6];
1669
1670 if (!IS_QLA83XX(ha) && !IS_QLA81XX(ha))
1671 return;
1672
1673 if (IS_QLA2031(ha) && ha->beacon_blink_led) {
1674 if (ha->flags.port0)
1675 led_select_value = 0x00201320;
1676 else
1677 led_select_value = 0x00201328;
1678
1679 qla83xx_write_remote_reg(vha, led_select_value, 0x40002000);
1680 qla83xx_write_remote_reg(vha, led_select_value + 4, 0x40002000);
1681 msleep(1000);
1682 qla83xx_write_remote_reg(vha, led_select_value, 0x40004000);
1683 qla83xx_write_remote_reg(vha, led_select_value + 4, 0x40004000);
1684 } else if ((IS_QLA8031(ha) || IS_QLA81XX(ha)) && ha->beacon_blink_led) {
1685 int rval;
1686
1687 /* Save Current */
1688 rval = qla81xx_get_led_config(vha, orig_led_cfg);
1689 /* Do the blink */
1690 if (rval == QLA_SUCCESS) {
1691 if (IS_QLA81XX(ha)) {
1692 led_cfg[0] = 0x4000;
1693 led_cfg[1] = 0x2000;
1694 led_cfg[2] = 0;
1695 led_cfg[3] = 0;
1696 led_cfg[4] = 0;
1697 led_cfg[5] = 0;
1698 } else {
1699 led_cfg[0] = 0x4000;
1700 led_cfg[1] = 0x4000;
1701 led_cfg[2] = 0x4000;
1702 led_cfg[3] = 0x2000;
1703 led_cfg[4] = 0;
1704 led_cfg[5] = 0x2000;
1705 }
1706 rval = qla81xx_set_led_config(vha, led_cfg);
1707 msleep(1000);
1708 if (IS_QLA81XX(ha)) {
1709 led_cfg[0] = 0x4000;
1710 led_cfg[1] = 0x2000;
1711 led_cfg[2] = 0;
1712 } else {
1713 led_cfg[0] = 0x4000;
1714 led_cfg[1] = 0x2000;
1715 led_cfg[2] = 0x4000;
1716 led_cfg[3] = 0x4000;
1717 led_cfg[4] = 0;
1718 led_cfg[5] = 0x2000;
1719 }
1720 rval = qla81xx_set_led_config(vha, led_cfg);
1721 }
1722 /* On exit, restore original (presumes no status change) */
1723 qla81xx_set_led_config(vha, orig_led_cfg);
1724 }
1725}
1726
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001727int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001728qla24xx_beacon_on(struct scsi_qla_host *vha)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001729{
1730 uint32_t gpio_data;
1731 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001732 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001733 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1734
Giridhar Malavalia9083012010-04-12 17:59:55 -07001735 if (IS_QLA82XX(ha))
1736 return QLA_SUCCESS;
1737
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001738 if (IS_QLA8031(ha) || IS_QLA81XX(ha))
1739 goto skip_gpio; /* let blink handle it */
1740
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001741 if (ha->beacon_blink_led == 0) {
1742 /* Enable firmware for update */
1743 ha->fw_options[1] |= ADD_FO1_DISABLE_GPIO_LED_CTRL;
1744
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001745 if (qla2x00_set_fw_options(vha, ha->fw_options) != QLA_SUCCESS)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001746 return QLA_FUNCTION_FAILED;
1747
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001748 if (qla2x00_get_fw_options(vha, ha->fw_options) !=
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001749 QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001750 ql_log(ql_log_warn, vha, 0x7009,
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001751 "Unable to update fw options (beacon on).\n");
1752 return QLA_FUNCTION_FAILED;
1753 }
1754
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001755 if (IS_QLA2031(ha))
1756 goto skip_gpio;
1757
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001758 spin_lock_irqsave(&ha->hardware_lock, flags);
1759 gpio_data = RD_REG_DWORD(&reg->gpiod);
1760
1761 /* Enable the gpio_data reg for update. */
1762 gpio_data |= GPDX_LED_UPDATE_MASK;
1763 WRT_REG_DWORD(&reg->gpiod, gpio_data);
1764 RD_REG_DWORD(&reg->gpiod);
1765
1766 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1767 }
1768
1769 /* So all colors blink together. */
1770 ha->beacon_color_state = 0;
1771
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001772skip_gpio:
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001773 /* Let the per HBA timer kick off the blinking process. */
1774 ha->beacon_blink_led = 1;
1775
1776 return QLA_SUCCESS;
1777}
1778
1779int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001780qla24xx_beacon_off(struct scsi_qla_host *vha)
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001781{
1782 uint32_t gpio_data;
1783 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001784 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001785 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1786
Giridhar Malavalia9083012010-04-12 17:59:55 -07001787 if (IS_QLA82XX(ha))
1788 return QLA_SUCCESS;
1789
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001790 ha->beacon_blink_led = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001791
1792 if (IS_QLA2031(ha))
1793 goto set_fw_options;
1794
1795 if (IS_QLA8031(ha) || IS_QLA81XX(ha))
1796 return QLA_SUCCESS;
1797
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001798 ha->beacon_color_state = QLA_LED_ALL_ON;
1799
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001800 ha->isp_ops->beacon_blink(vha); /* Will flip to all off. */
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001801
1802 /* Give control back to firmware. */
1803 spin_lock_irqsave(&ha->hardware_lock, flags);
1804 gpio_data = RD_REG_DWORD(&reg->gpiod);
1805
1806 /* Disable the gpio_data reg for update. */
1807 gpio_data &= ~GPDX_LED_UPDATE_MASK;
1808 WRT_REG_DWORD(&reg->gpiod, gpio_data);
1809 RD_REG_DWORD(&reg->gpiod);
1810 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1811
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001812set_fw_options:
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001813 ha->fw_options[1] &= ~ADD_FO1_DISABLE_GPIO_LED_CTRL;
1814
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001815 if (qla2x00_set_fw_options(vha, ha->fw_options) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001816 ql_log(ql_log_warn, vha, 0x704d,
1817 "Unable to update fw options (beacon on).\n");
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001818 return QLA_FUNCTION_FAILED;
1819 }
1820
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001821 if (qla2x00_get_fw_options(vha, ha->fw_options) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001822 ql_log(ql_log_warn, vha, 0x704e,
1823 "Unable to update fw options (beacon on).\n");
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08001824 return QLA_FUNCTION_FAILED;
1825 }
1826
1827 return QLA_SUCCESS;
1828}
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001829
1830
1831/*
1832 * Flash support routines
1833 */
1834
1835/**
1836 * qla2x00_flash_enable() - Setup flash for reading and writing.
1837 * @ha: HA context
1838 */
1839static void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001840qla2x00_flash_enable(struct qla_hw_data *ha)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001841{
1842 uint16_t data;
1843 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1844
1845 data = RD_REG_WORD(&reg->ctrl_status);
1846 data |= CSR_FLASH_ENABLE;
1847 WRT_REG_WORD(&reg->ctrl_status, data);
1848 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1849}
1850
1851/**
1852 * qla2x00_flash_disable() - Disable flash and allow RISC to run.
1853 * @ha: HA context
1854 */
1855static void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001856qla2x00_flash_disable(struct qla_hw_data *ha)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001857{
1858 uint16_t data;
1859 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1860
1861 data = RD_REG_WORD(&reg->ctrl_status);
1862 data &= ~(CSR_FLASH_ENABLE);
1863 WRT_REG_WORD(&reg->ctrl_status, data);
1864 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1865}
1866
1867/**
1868 * qla2x00_read_flash_byte() - Reads a byte from flash
1869 * @ha: HA context
1870 * @addr: Address in flash to read
1871 *
1872 * A word is read from the chip, but, only the lower byte is valid.
1873 *
1874 * Returns the byte read from flash @addr.
1875 */
1876static uint8_t
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001877qla2x00_read_flash_byte(struct qla_hw_data *ha, uint32_t addr)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001878{
1879 uint16_t data;
1880 uint16_t bank_select;
1881 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1882
1883 bank_select = RD_REG_WORD(&reg->ctrl_status);
1884
1885 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
1886 /* Specify 64K address range: */
1887 /* clear out Module Select and Flash Address bits [19:16]. */
1888 bank_select &= ~0xf8;
1889 bank_select |= addr >> 12 & 0xf0;
1890 bank_select |= CSR_FLASH_64K_BANK;
1891 WRT_REG_WORD(&reg->ctrl_status, bank_select);
1892 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1893
1894 WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
1895 data = RD_REG_WORD(&reg->flash_data);
1896
1897 return (uint8_t)data;
1898 }
1899
1900 /* Setup bit 16 of flash address. */
1901 if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
1902 bank_select |= CSR_FLASH_64K_BANK;
1903 WRT_REG_WORD(&reg->ctrl_status, bank_select);
1904 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1905 } else if (((addr & BIT_16) == 0) &&
1906 (bank_select & CSR_FLASH_64K_BANK)) {
1907 bank_select &= ~(CSR_FLASH_64K_BANK);
1908 WRT_REG_WORD(&reg->ctrl_status, bank_select);
1909 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1910 }
1911
1912 /* Always perform IO mapped accesses to the FLASH registers. */
1913 if (ha->pio_address) {
1914 uint16_t data2;
1915
Andrew Vasquez948882f2008-01-31 12:33:44 -08001916 WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001917 do {
Andrew Vasquez948882f2008-01-31 12:33:44 -08001918 data = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001919 barrier();
1920 cpu_relax();
Andrew Vasquez948882f2008-01-31 12:33:44 -08001921 data2 = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001922 } while (data != data2);
1923 } else {
1924 WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
1925 data = qla2x00_debounce_register(&reg->flash_data);
1926 }
1927
1928 return (uint8_t)data;
1929}
1930
1931/**
1932 * qla2x00_write_flash_byte() - Write a byte to flash
1933 * @ha: HA context
1934 * @addr: Address in flash to write
1935 * @data: Data to write
1936 */
1937static void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001938qla2x00_write_flash_byte(struct qla_hw_data *ha, uint32_t addr, uint8_t data)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001939{
1940 uint16_t bank_select;
1941 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1942
1943 bank_select = RD_REG_WORD(&reg->ctrl_status);
1944 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
1945 /* Specify 64K address range: */
1946 /* clear out Module Select and Flash Address bits [19:16]. */
1947 bank_select &= ~0xf8;
1948 bank_select |= addr >> 12 & 0xf0;
1949 bank_select |= CSR_FLASH_64K_BANK;
1950 WRT_REG_WORD(&reg->ctrl_status, bank_select);
1951 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1952
1953 WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
1954 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1955 WRT_REG_WORD(&reg->flash_data, (uint16_t)data);
1956 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1957
1958 return;
1959 }
1960
1961 /* Setup bit 16 of flash address. */
1962 if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
1963 bank_select |= CSR_FLASH_64K_BANK;
1964 WRT_REG_WORD(&reg->ctrl_status, bank_select);
1965 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1966 } else if (((addr & BIT_16) == 0) &&
1967 (bank_select & CSR_FLASH_64K_BANK)) {
1968 bank_select &= ~(CSR_FLASH_64K_BANK);
1969 WRT_REG_WORD(&reg->ctrl_status, bank_select);
1970 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1971 }
1972
1973 /* Always perform IO mapped accesses to the FLASH registers. */
1974 if (ha->pio_address) {
Andrew Vasquez948882f2008-01-31 12:33:44 -08001975 WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
1976 WRT_REG_WORD_PIO(PIO_REG(ha, flash_data), (uint16_t)data);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001977 } else {
1978 WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
1979 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1980 WRT_REG_WORD(&reg->flash_data, (uint16_t)data);
1981 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1982 }
1983}
1984
1985/**
1986 * qla2x00_poll_flash() - Polls flash for completion.
1987 * @ha: HA context
1988 * @addr: Address in flash to poll
1989 * @poll_data: Data to be polled
1990 * @man_id: Flash manufacturer ID
1991 * @flash_id: Flash ID
1992 *
1993 * This function polls the device until bit 7 of what is read matches data
1994 * bit 7 or until data bit 5 becomes a 1. If that hapens, the flash ROM timed
1995 * out (a fatal error). The flash book recommeds reading bit 7 again after
1996 * reading bit 5 as a 1.
1997 *
1998 * Returns 0 on success, else non-zero.
1999 */
2000static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002001qla2x00_poll_flash(struct qla_hw_data *ha, uint32_t addr, uint8_t poll_data,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002002 uint8_t man_id, uint8_t flash_id)
2003{
2004 int status;
2005 uint8_t flash_data;
2006 uint32_t cnt;
2007
2008 status = 1;
2009
2010 /* Wait for 30 seconds for command to finish. */
2011 poll_data &= BIT_7;
2012 for (cnt = 3000000; cnt; cnt--) {
2013 flash_data = qla2x00_read_flash_byte(ha, addr);
2014 if ((flash_data & BIT_7) == poll_data) {
2015 status = 0;
2016 break;
2017 }
2018
2019 if (man_id != 0x40 && man_id != 0xda) {
2020 if ((flash_data & BIT_5) && cnt > 2)
2021 cnt = 2;
2022 }
2023 udelay(10);
2024 barrier();
Andrew Vasquez40a2e342007-03-12 10:41:28 -07002025 cond_resched();
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002026 }
2027 return status;
2028}
2029
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002030/**
2031 * qla2x00_program_flash_address() - Programs a flash address
2032 * @ha: HA context
2033 * @addr: Address in flash to program
2034 * @data: Data to be written in flash
2035 * @man_id: Flash manufacturer ID
2036 * @flash_id: Flash ID
2037 *
2038 * Returns 0 on success, else non-zero.
2039 */
2040static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002041qla2x00_program_flash_address(struct qla_hw_data *ha, uint32_t addr,
2042 uint8_t data, uint8_t man_id, uint8_t flash_id)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002043{
2044 /* Write Program Command Sequence. */
2045 if (IS_OEM_001(ha)) {
2046 qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
2047 qla2x00_write_flash_byte(ha, 0x555, 0x55);
2048 qla2x00_write_flash_byte(ha, 0xaaa, 0xa0);
2049 qla2x00_write_flash_byte(ha, addr, data);
2050 } else {
2051 if (man_id == 0xda && flash_id == 0xc1) {
2052 qla2x00_write_flash_byte(ha, addr, data);
2053 if (addr & 0x7e)
2054 return 0;
2055 } else {
2056 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
2057 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
2058 qla2x00_write_flash_byte(ha, 0x5555, 0xa0);
2059 qla2x00_write_flash_byte(ha, addr, data);
2060 }
2061 }
2062
2063 udelay(150);
2064
2065 /* Wait for write to complete. */
2066 return qla2x00_poll_flash(ha, addr, data, man_id, flash_id);
2067}
2068
2069/**
2070 * qla2x00_erase_flash() - Erase the flash.
2071 * @ha: HA context
2072 * @man_id: Flash manufacturer ID
2073 * @flash_id: Flash ID
2074 *
2075 * Returns 0 on success, else non-zero.
2076 */
2077static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002078qla2x00_erase_flash(struct qla_hw_data *ha, uint8_t man_id, uint8_t flash_id)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002079{
2080 /* Individual Sector Erase Command Sequence */
2081 if (IS_OEM_001(ha)) {
2082 qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
2083 qla2x00_write_flash_byte(ha, 0x555, 0x55);
2084 qla2x00_write_flash_byte(ha, 0xaaa, 0x80);
2085 qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
2086 qla2x00_write_flash_byte(ha, 0x555, 0x55);
2087 qla2x00_write_flash_byte(ha, 0xaaa, 0x10);
2088 } else {
2089 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
2090 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
2091 qla2x00_write_flash_byte(ha, 0x5555, 0x80);
2092 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
2093 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
2094 qla2x00_write_flash_byte(ha, 0x5555, 0x10);
2095 }
2096
2097 udelay(150);
2098
2099 /* Wait for erase to complete. */
2100 return qla2x00_poll_flash(ha, 0x00, 0x80, man_id, flash_id);
2101}
2102
2103/**
2104 * qla2x00_erase_flash_sector() - Erase a flash sector.
2105 * @ha: HA context
2106 * @addr: Flash sector to erase
2107 * @sec_mask: Sector address mask
2108 * @man_id: Flash manufacturer ID
2109 * @flash_id: Flash ID
2110 *
2111 * Returns 0 on success, else non-zero.
2112 */
2113static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002114qla2x00_erase_flash_sector(struct qla_hw_data *ha, uint32_t addr,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002115 uint32_t sec_mask, uint8_t man_id, uint8_t flash_id)
2116{
2117 /* Individual Sector Erase Command Sequence */
2118 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
2119 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
2120 qla2x00_write_flash_byte(ha, 0x5555, 0x80);
2121 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
2122 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
2123 if (man_id == 0x1f && flash_id == 0x13)
2124 qla2x00_write_flash_byte(ha, addr & sec_mask, 0x10);
2125 else
2126 qla2x00_write_flash_byte(ha, addr & sec_mask, 0x30);
2127
2128 udelay(150);
2129
2130 /* Wait for erase to complete. */
2131 return qla2x00_poll_flash(ha, addr, 0x80, man_id, flash_id);
2132}
2133
2134/**
2135 * qla2x00_get_flash_manufacturer() - Read manufacturer ID from flash chip.
2136 * @man_id: Flash manufacturer ID
2137 * @flash_id: Flash ID
2138 */
2139static void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002140qla2x00_get_flash_manufacturer(struct qla_hw_data *ha, uint8_t *man_id,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002141 uint8_t *flash_id)
2142{
2143 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
2144 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
2145 qla2x00_write_flash_byte(ha, 0x5555, 0x90);
2146 *man_id = qla2x00_read_flash_byte(ha, 0x0000);
2147 *flash_id = qla2x00_read_flash_byte(ha, 0x0001);
2148 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
2149 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
2150 qla2x00_write_flash_byte(ha, 0x5555, 0xf0);
2151}
2152
Andrew Vasquez30c47662007-01-29 10:22:21 -08002153static void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002154qla2x00_read_flash_data(struct qla_hw_data *ha, uint8_t *tmp_buf,
2155 uint32_t saddr, uint32_t length)
Andrew Vasquez30c47662007-01-29 10:22:21 -08002156{
2157 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2158 uint32_t midpoint, ilength;
2159 uint8_t data;
2160
2161 midpoint = length / 2;
2162
2163 WRT_REG_WORD(&reg->nvram, 0);
2164 RD_REG_WORD(&reg->nvram);
2165 for (ilength = 0; ilength < length; saddr++, ilength++, tmp_buf++) {
2166 if (ilength == midpoint) {
2167 WRT_REG_WORD(&reg->nvram, NVR_SELECT);
2168 RD_REG_WORD(&reg->nvram);
2169 }
2170 data = qla2x00_read_flash_byte(ha, saddr);
2171 if (saddr % 100)
2172 udelay(10);
2173 *tmp_buf = data;
Andrew Vasquez40a2e342007-03-12 10:41:28 -07002174 cond_resched();
Andrew Vasquez30c47662007-01-29 10:22:21 -08002175 }
2176}
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002177
2178static inline void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002179qla2x00_suspend_hba(struct scsi_qla_host *vha)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002180{
2181 int cnt;
2182 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002183 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002184 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2185
2186 /* Suspend HBA. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002187 scsi_block_requests(vha->host);
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002188 ha->isp_ops->disable_intrs(ha);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002189 set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
2190
2191 /* Pause RISC. */
2192 spin_lock_irqsave(&ha->hardware_lock, flags);
2193 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
2194 RD_REG_WORD(&reg->hccr);
2195 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2196 for (cnt = 0; cnt < 30000; cnt++) {
2197 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
2198 break;
2199 udelay(100);
2200 }
2201 } else {
2202 udelay(10);
2203 }
2204 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2205}
2206
2207static inline void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002208qla2x00_resume_hba(struct scsi_qla_host *vha)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002209{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002210 struct qla_hw_data *ha = vha->hw;
2211
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002212 /* Resume HBA. */
2213 clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002214 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2215 qla2xxx_wake_dpc(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07002216 qla2x00_wait_for_chip_reset(vha);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002217 scsi_unblock_requests(vha->host);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002218}
2219
2220uint8_t *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002221qla2x00_read_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002222 uint32_t offset, uint32_t length)
2223{
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002224 uint32_t addr, midpoint;
2225 uint8_t *data;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002226 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002227 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2228
2229 /* Suspend HBA. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002230 qla2x00_suspend_hba(vha);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002231
2232 /* Go with read. */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002233 midpoint = ha->optrom_size / 2;
2234
2235 qla2x00_flash_enable(ha);
2236 WRT_REG_WORD(&reg->nvram, 0);
2237 RD_REG_WORD(&reg->nvram); /* PCI Posting. */
2238 for (addr = offset, data = buf; addr < length; addr++, data++) {
2239 if (addr == midpoint) {
2240 WRT_REG_WORD(&reg->nvram, NVR_SELECT);
2241 RD_REG_WORD(&reg->nvram); /* PCI Posting. */
2242 }
2243
2244 *data = qla2x00_read_flash_byte(ha, addr);
2245 }
2246 qla2x00_flash_disable(ha);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002247
2248 /* Resume HBA. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002249 qla2x00_resume_hba(vha);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002250
2251 return buf;
2252}
2253
2254int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002255qla2x00_write_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002256 uint32_t offset, uint32_t length)
2257{
2258
2259 int rval;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002260 uint8_t man_id, flash_id, sec_number, data;
2261 uint16_t wd;
2262 uint32_t addr, liter, sec_mask, rest_addr;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002263 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002264 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2265
2266 /* Suspend HBA. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002267 qla2x00_suspend_hba(vha);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002268
2269 rval = QLA_SUCCESS;
2270 sec_number = 0;
2271
2272 /* Reset ISP chip. */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002273 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
2274 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2275
2276 /* Go with write. */
2277 qla2x00_flash_enable(ha);
2278 do { /* Loop once to provide quick error exit */
2279 /* Structure of flash memory based on manufacturer */
2280 if (IS_OEM_001(ha)) {
2281 /* OEM variant with special flash part. */
2282 man_id = flash_id = 0;
2283 rest_addr = 0xffff;
2284 sec_mask = 0x10000;
2285 goto update_flash;
2286 }
2287 qla2x00_get_flash_manufacturer(ha, &man_id, &flash_id);
2288 switch (man_id) {
2289 case 0x20: /* ST flash. */
2290 if (flash_id == 0xd2 || flash_id == 0xe3) {
2291 /*
2292 * ST m29w008at part - 64kb sector size with
2293 * 32kb,8kb,8kb,16kb sectors at memory address
2294 * 0xf0000.
2295 */
2296 rest_addr = 0xffff;
2297 sec_mask = 0x10000;
2298 break;
2299 }
2300 /*
2301 * ST m29w010b part - 16kb sector size
2302 * Default to 16kb sectors
2303 */
2304 rest_addr = 0x3fff;
2305 sec_mask = 0x1c000;
2306 break;
2307 case 0x40: /* Mostel flash. */
2308 /* Mostel v29c51001 part - 512 byte sector size. */
2309 rest_addr = 0x1ff;
2310 sec_mask = 0x1fe00;
2311 break;
2312 case 0xbf: /* SST flash. */
2313 /* SST39sf10 part - 4kb sector size. */
2314 rest_addr = 0xfff;
2315 sec_mask = 0x1f000;
2316 break;
2317 case 0xda: /* Winbond flash. */
2318 /* Winbond W29EE011 part - 256 byte sector size. */
2319 rest_addr = 0x7f;
2320 sec_mask = 0x1ff80;
2321 break;
2322 case 0xc2: /* Macronix flash. */
2323 /* 64k sector size. */
2324 if (flash_id == 0x38 || flash_id == 0x4f) {
2325 rest_addr = 0xffff;
2326 sec_mask = 0x10000;
2327 break;
2328 }
2329 /* Fall through... */
2330
2331 case 0x1f: /* Atmel flash. */
2332 /* 512k sector size. */
2333 if (flash_id == 0x13) {
2334 rest_addr = 0x7fffffff;
2335 sec_mask = 0x80000000;
2336 break;
2337 }
2338 /* Fall through... */
2339
2340 case 0x01: /* AMD flash. */
2341 if (flash_id == 0x38 || flash_id == 0x40 ||
2342 flash_id == 0x4f) {
2343 /* Am29LV081 part - 64kb sector size. */
2344 /* Am29LV002BT part - 64kb sector size. */
2345 rest_addr = 0xffff;
2346 sec_mask = 0x10000;
2347 break;
2348 } else if (flash_id == 0x3e) {
2349 /*
2350 * Am29LV008b part - 64kb sector size with
2351 * 32kb,8kb,8kb,16kb sector at memory address
2352 * h0xf0000.
2353 */
2354 rest_addr = 0xffff;
2355 sec_mask = 0x10000;
2356 break;
2357 } else if (flash_id == 0x20 || flash_id == 0x6e) {
2358 /*
2359 * Am29LV010 part or AM29f010 - 16kb sector
2360 * size.
2361 */
2362 rest_addr = 0x3fff;
2363 sec_mask = 0x1c000;
2364 break;
2365 } else if (flash_id == 0x6d) {
2366 /* Am29LV001 part - 8kb sector size. */
2367 rest_addr = 0x1fff;
2368 sec_mask = 0x1e000;
2369 break;
2370 }
2371 default:
2372 /* Default to 16 kb sector size. */
2373 rest_addr = 0x3fff;
2374 sec_mask = 0x1c000;
2375 break;
2376 }
2377
2378update_flash:
2379 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
2380 if (qla2x00_erase_flash(ha, man_id, flash_id)) {
2381 rval = QLA_FUNCTION_FAILED;
2382 break;
2383 }
2384 }
2385
2386 for (addr = offset, liter = 0; liter < length; liter++,
2387 addr++) {
2388 data = buf[liter];
2389 /* Are we at the beginning of a sector? */
2390 if ((addr & rest_addr) == 0) {
2391 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
2392 if (addr >= 0x10000UL) {
2393 if (((addr >> 12) & 0xf0) &&
2394 ((man_id == 0x01 &&
2395 flash_id == 0x3e) ||
2396 (man_id == 0x20 &&
2397 flash_id == 0xd2))) {
2398 sec_number++;
2399 if (sec_number == 1) {
2400 rest_addr =
2401 0x7fff;
2402 sec_mask =
2403 0x18000;
2404 } else if (
2405 sec_number == 2 ||
2406 sec_number == 3) {
2407 rest_addr =
2408 0x1fff;
2409 sec_mask =
2410 0x1e000;
2411 } else if (
2412 sec_number == 4) {
2413 rest_addr =
2414 0x3fff;
2415 sec_mask =
2416 0x1c000;
2417 }
2418 }
2419 }
2420 } else if (addr == ha->optrom_size / 2) {
2421 WRT_REG_WORD(&reg->nvram, NVR_SELECT);
2422 RD_REG_WORD(&reg->nvram);
2423 }
2424
2425 if (flash_id == 0xda && man_id == 0xc1) {
2426 qla2x00_write_flash_byte(ha, 0x5555,
2427 0xaa);
2428 qla2x00_write_flash_byte(ha, 0x2aaa,
2429 0x55);
2430 qla2x00_write_flash_byte(ha, 0x5555,
2431 0xa0);
2432 } else if (!IS_QLA2322(ha) && !IS_QLA6322(ha)) {
2433 /* Then erase it */
2434 if (qla2x00_erase_flash_sector(ha,
2435 addr, sec_mask, man_id,
2436 flash_id)) {
2437 rval = QLA_FUNCTION_FAILED;
2438 break;
2439 }
2440 if (man_id == 0x01 && flash_id == 0x6d)
2441 sec_number++;
2442 }
2443 }
2444
2445 if (man_id == 0x01 && flash_id == 0x6d) {
2446 if (sec_number == 1 &&
2447 addr == (rest_addr - 1)) {
2448 rest_addr = 0x0fff;
2449 sec_mask = 0x1f000;
2450 } else if (sec_number == 3 && (addr & 0x7ffe)) {
2451 rest_addr = 0x3fff;
2452 sec_mask = 0x1c000;
2453 }
2454 }
2455
2456 if (qla2x00_program_flash_address(ha, addr, data,
2457 man_id, flash_id)) {
2458 rval = QLA_FUNCTION_FAILED;
2459 break;
2460 }
Andrew Vasquez40a2e342007-03-12 10:41:28 -07002461 cond_resched();
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002462 }
2463 } while (0);
2464 qla2x00_flash_disable(ha);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002465
2466 /* Resume HBA. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002467 qla2x00_resume_hba(vha);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002468
2469 return rval;
2470}
2471
2472uint8_t *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002473qla24xx_read_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002474 uint32_t offset, uint32_t length)
2475{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002476 struct qla_hw_data *ha = vha->hw;
2477
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002478 /* Suspend HBA. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002479 scsi_block_requests(vha->host);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002480 set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
2481
2482 /* Go with read. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002483 qla24xx_read_flash_data(vha, (uint32_t *)buf, offset >> 2, length >> 2);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002484
2485 /* Resume HBA. */
2486 clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002487 scsi_unblock_requests(vha->host);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002488
2489 return buf;
2490}
2491
2492int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002493qla24xx_write_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002494 uint32_t offset, uint32_t length)
2495{
2496 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002497 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002498
2499 /* Suspend HBA. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002500 scsi_block_requests(vha->host);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002501 set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
2502
2503 /* Go with write. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002504 rval = qla24xx_write_flash_data(vha, (uint32_t *)buf, offset >> 2,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002505 length >> 2);
2506
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002507 clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002508 scsi_unblock_requests(vha->host);
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002509
2510 return rval;
2511}
Andrew Vasquez30c47662007-01-29 10:22:21 -08002512
Andrew Vasquez338c9162007-09-20 14:07:33 -07002513uint8_t *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002514qla25xx_read_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
Andrew Vasquez338c9162007-09-20 14:07:33 -07002515 uint32_t offset, uint32_t length)
2516{
2517 int rval;
2518 dma_addr_t optrom_dma;
2519 void *optrom;
2520 uint8_t *pbuf;
2521 uint32_t faddr, left, burst;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002522 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez338c9162007-09-20 14:07:33 -07002523
Andrew Vasquez368bbe02010-01-12 12:59:49 -08002524 if (IS_QLA25XX(ha) || IS_QLA81XX(ha))
2525 goto try_fast;
Joe Carnucciob7cc1762007-09-20 14:07:35 -07002526 if (offset & 0xfff)
Andrew Vasquez338c9162007-09-20 14:07:33 -07002527 goto slow_read;
2528 if (length < OPTROM_BURST_SIZE)
2529 goto slow_read;
2530
Andrew Vasquez368bbe02010-01-12 12:59:49 -08002531try_fast:
Andrew Vasquez338c9162007-09-20 14:07:33 -07002532 optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
2533 &optrom_dma, GFP_KERNEL);
2534 if (!optrom) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002535 ql_log(ql_log_warn, vha, 0x00cc,
2536 "Unable to allocate memory for optrom burst read (%x KB).\n",
2537 OPTROM_BURST_SIZE / 1024);
Andrew Vasquez338c9162007-09-20 14:07:33 -07002538 goto slow_read;
2539 }
2540
2541 pbuf = buf;
2542 faddr = offset >> 2;
2543 left = length >> 2;
2544 burst = OPTROM_BURST_DWORDS;
2545 while (left != 0) {
2546 if (burst > left)
2547 burst = left;
2548
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002549 rval = qla2x00_dump_ram(vha, optrom_dma,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002550 flash_data_addr(ha, faddr), burst);
Andrew Vasquez338c9162007-09-20 14:07:33 -07002551 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002552 ql_log(ql_log_warn, vha, 0x00f5,
2553 "Unable to burst-read optrom segment (%x/%x/%llx).\n",
2554 rval, flash_data_addr(ha, faddr),
Andrew Morton875baf32007-10-16 14:28:20 -07002555 (unsigned long long)optrom_dma);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002556 ql_log(ql_log_warn, vha, 0x00f6,
Andrew Vasquez338c9162007-09-20 14:07:33 -07002557 "Reverting to slow-read.\n");
2558
2559 dma_free_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
2560 optrom, optrom_dma);
2561 goto slow_read;
2562 }
2563
2564 memcpy(pbuf, optrom, burst * 4);
2565
2566 left -= burst;
2567 faddr += burst;
2568 pbuf += burst * 4;
2569 }
2570
2571 dma_free_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE, optrom,
2572 optrom_dma);
2573
2574 return buf;
2575
2576slow_read:
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002577 return qla24xx_read_optrom_data(vha, buf, offset, length);
Andrew Vasquez338c9162007-09-20 14:07:33 -07002578}
2579
Andrew Vasquez30c47662007-01-29 10:22:21 -08002580/**
2581 * qla2x00_get_fcode_version() - Determine an FCODE image's version.
2582 * @ha: HA context
2583 * @pcids: Pointer to the FCODE PCI data structure
2584 *
2585 * The process of retrieving the FCODE version information is at best
2586 * described as interesting.
2587 *
2588 * Within the first 100h bytes of the image an ASCII string is present
2589 * which contains several pieces of information including the FCODE
2590 * version. Unfortunately it seems the only reliable way to retrieve
2591 * the version is by scanning for another sentinel within the string,
2592 * the FCODE build date:
2593 *
2594 * ... 2.00.02 10/17/02 ...
2595 *
2596 * Returns QLA_SUCCESS on successful retrieval of version.
2597 */
2598static void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002599qla2x00_get_fcode_version(struct qla_hw_data *ha, uint32_t pcids)
Andrew Vasquez30c47662007-01-29 10:22:21 -08002600{
2601 int ret = QLA_FUNCTION_FAILED;
2602 uint32_t istart, iend, iter, vend;
2603 uint8_t do_next, rbyte, *vbyte;
2604
2605 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
2606
2607 /* Skip the PCI data structure. */
2608 istart = pcids +
2609 ((qla2x00_read_flash_byte(ha, pcids + 0x0B) << 8) |
2610 qla2x00_read_flash_byte(ha, pcids + 0x0A));
2611 iend = istart + 0x100;
2612 do {
2613 /* Scan for the sentinel date string...eeewww. */
2614 do_next = 0;
2615 iter = istart;
2616 while ((iter < iend) && !do_next) {
2617 iter++;
2618 if (qla2x00_read_flash_byte(ha, iter) == '/') {
2619 if (qla2x00_read_flash_byte(ha, iter + 2) ==
2620 '/')
2621 do_next++;
2622 else if (qla2x00_read_flash_byte(ha,
2623 iter + 3) == '/')
2624 do_next++;
2625 }
2626 }
2627 if (!do_next)
2628 break;
2629
2630 /* Backtrack to previous ' ' (space). */
2631 do_next = 0;
2632 while ((iter > istart) && !do_next) {
2633 iter--;
2634 if (qla2x00_read_flash_byte(ha, iter) == ' ')
2635 do_next++;
2636 }
2637 if (!do_next)
2638 break;
2639
2640 /*
2641 * Mark end of version tag, and find previous ' ' (space) or
2642 * string length (recent FCODE images -- major hack ahead!!!).
2643 */
2644 vend = iter - 1;
2645 do_next = 0;
2646 while ((iter > istart) && !do_next) {
2647 iter--;
2648 rbyte = qla2x00_read_flash_byte(ha, iter);
2649 if (rbyte == ' ' || rbyte == 0xd || rbyte == 0x10)
2650 do_next++;
2651 }
2652 if (!do_next)
2653 break;
2654
2655 /* Mark beginning of version tag, and copy data. */
2656 iter++;
2657 if ((vend - iter) &&
2658 ((vend - iter) < sizeof(ha->fcode_revision))) {
2659 vbyte = ha->fcode_revision;
2660 while (iter <= vend) {
2661 *vbyte++ = qla2x00_read_flash_byte(ha, iter);
2662 iter++;
2663 }
2664 ret = QLA_SUCCESS;
2665 }
2666 } while (0);
2667
2668 if (ret != QLA_SUCCESS)
2669 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
2670}
2671
2672int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002673qla2x00_get_flash_version(scsi_qla_host_t *vha, void *mbuf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08002674{
2675 int ret = QLA_SUCCESS;
2676 uint8_t code_type, last_image;
2677 uint32_t pcihdr, pcids;
2678 uint8_t *dbyte;
2679 uint16_t *dcode;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002680 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08002681
2682 if (!ha->pio_address || !mbuf)
2683 return QLA_FUNCTION_FAILED;
2684
2685 memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
2686 memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
2687 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
2688 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
2689
2690 qla2x00_flash_enable(ha);
2691
2692 /* Begin with first PCI expansion ROM header. */
2693 pcihdr = 0;
2694 last_image = 1;
2695 do {
2696 /* Verify PCI expansion ROM header. */
2697 if (qla2x00_read_flash_byte(ha, pcihdr) != 0x55 ||
2698 qla2x00_read_flash_byte(ha, pcihdr + 0x01) != 0xaa) {
2699 /* No signature */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002700 ql_log(ql_log_fatal, vha, 0x0050,
2701 "No matching ROM signature.\n");
Andrew Vasquez30c47662007-01-29 10:22:21 -08002702 ret = QLA_FUNCTION_FAILED;
2703 break;
2704 }
2705
2706 /* Locate PCI data structure. */
2707 pcids = pcihdr +
2708 ((qla2x00_read_flash_byte(ha, pcihdr + 0x19) << 8) |
2709 qla2x00_read_flash_byte(ha, pcihdr + 0x18));
2710
2711 /* Validate signature of PCI data structure. */
2712 if (qla2x00_read_flash_byte(ha, pcids) != 'P' ||
2713 qla2x00_read_flash_byte(ha, pcids + 0x1) != 'C' ||
2714 qla2x00_read_flash_byte(ha, pcids + 0x2) != 'I' ||
2715 qla2x00_read_flash_byte(ha, pcids + 0x3) != 'R') {
2716 /* Incorrect header. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002717 ql_log(ql_log_fatal, vha, 0x0051,
2718 "PCI data struct not found pcir_adr=%x.\n", pcids);
Andrew Vasquez30c47662007-01-29 10:22:21 -08002719 ret = QLA_FUNCTION_FAILED;
2720 break;
2721 }
2722
2723 /* Read version */
2724 code_type = qla2x00_read_flash_byte(ha, pcids + 0x14);
2725 switch (code_type) {
2726 case ROM_CODE_TYPE_BIOS:
2727 /* Intel x86, PC-AT compatible. */
2728 ha->bios_revision[0] =
2729 qla2x00_read_flash_byte(ha, pcids + 0x12);
2730 ha->bios_revision[1] =
2731 qla2x00_read_flash_byte(ha, pcids + 0x13);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002732 ql_dbg(ql_dbg_init, vha, 0x0052,
2733 "Read BIOS %d.%d.\n",
2734 ha->bios_revision[1], ha->bios_revision[0]);
Andrew Vasquez30c47662007-01-29 10:22:21 -08002735 break;
2736 case ROM_CODE_TYPE_FCODE:
2737 /* Open Firmware standard for PCI (FCode). */
2738 /* Eeeewww... */
2739 qla2x00_get_fcode_version(ha, pcids);
2740 break;
2741 case ROM_CODE_TYPE_EFI:
2742 /* Extensible Firmware Interface (EFI). */
2743 ha->efi_revision[0] =
2744 qla2x00_read_flash_byte(ha, pcids + 0x12);
2745 ha->efi_revision[1] =
2746 qla2x00_read_flash_byte(ha, pcids + 0x13);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002747 ql_dbg(ql_dbg_init, vha, 0x0053,
2748 "Read EFI %d.%d.\n",
2749 ha->efi_revision[1], ha->efi_revision[0]);
Andrew Vasquez30c47662007-01-29 10:22:21 -08002750 break;
2751 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002752 ql_log(ql_log_warn, vha, 0x0054,
2753 "Unrecognized code type %x at pcids %x.\n",
2754 code_type, pcids);
Andrew Vasquez30c47662007-01-29 10:22:21 -08002755 break;
2756 }
2757
2758 last_image = qla2x00_read_flash_byte(ha, pcids + 0x15) & BIT_7;
2759
2760 /* Locate next PCI expansion ROM. */
2761 pcihdr += ((qla2x00_read_flash_byte(ha, pcids + 0x11) << 8) |
2762 qla2x00_read_flash_byte(ha, pcids + 0x10)) * 512;
2763 } while (!last_image);
2764
2765 if (IS_QLA2322(ha)) {
2766 /* Read firmware image information. */
2767 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
2768 dbyte = mbuf;
2769 memset(dbyte, 0, 8);
2770 dcode = (uint16_t *)dbyte;
2771
Andrew Vasquezc00d8992008-09-11 21:22:49 -07002772 qla2x00_read_flash_data(ha, dbyte, ha->flt_region_fw * 4 + 10,
Andrew Vasquez30c47662007-01-29 10:22:21 -08002773 8);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002774 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010a,
2775 "Dumping fw "
2776 "ver from flash:.\n");
2777 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010b,
2778 (uint8_t *)dbyte, 8);
Andrew Vasquez30c47662007-01-29 10:22:21 -08002779
2780 if ((dcode[0] == 0xffff && dcode[1] == 0xffff &&
2781 dcode[2] == 0xffff && dcode[3] == 0xffff) ||
2782 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
2783 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002784 ql_log(ql_log_warn, vha, 0x0057,
2785 "Unrecognized fw revision at %x.\n",
2786 ha->flt_region_fw * 4);
Andrew Vasquez30c47662007-01-29 10:22:21 -08002787 } else {
2788 /* values are in big endian */
2789 ha->fw_revision[0] = dbyte[0] << 16 | dbyte[1];
2790 ha->fw_revision[1] = dbyte[2] << 16 | dbyte[3];
2791 ha->fw_revision[2] = dbyte[4] << 16 | dbyte[5];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002792 ql_dbg(ql_dbg_init, vha, 0x0058,
2793 "FW Version: "
2794 "%d.%d.%d.\n", ha->fw_revision[0],
2795 ha->fw_revision[1], ha->fw_revision[2]);
Andrew Vasquez30c47662007-01-29 10:22:21 -08002796 }
2797 }
2798
2799 qla2x00_flash_disable(ha);
2800
2801 return ret;
2802}
2803
2804int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002805qla24xx_get_flash_version(scsi_qla_host_t *vha, void *mbuf)
Andrew Vasquez30c47662007-01-29 10:22:21 -08002806{
2807 int ret = QLA_SUCCESS;
2808 uint32_t pcihdr, pcids;
2809 uint32_t *dcode;
2810 uint8_t *bcode;
2811 uint8_t code_type, last_image;
2812 int i;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002813 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez30c47662007-01-29 10:22:21 -08002814
Giridhar Malavalia9083012010-04-12 17:59:55 -07002815 if (IS_QLA82XX(ha))
2816 return ret;
2817
Andrew Vasquez30c47662007-01-29 10:22:21 -08002818 if (!mbuf)
2819 return QLA_FUNCTION_FAILED;
2820
2821 memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
2822 memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
2823 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
2824 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
2825
2826 dcode = mbuf;
2827
2828 /* Begin with first PCI expansion ROM header. */
Harish Zunjarrao6315a5f2009-03-24 09:07:59 -07002829 pcihdr = ha->flt_region_boot << 2;
Andrew Vasquez30c47662007-01-29 10:22:21 -08002830 last_image = 1;
2831 do {
2832 /* Verify PCI expansion ROM header. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002833 qla24xx_read_flash_data(vha, dcode, pcihdr >> 2, 0x20);
Andrew Vasquez30c47662007-01-29 10:22:21 -08002834 bcode = mbuf + (pcihdr % 4);
2835 if (bcode[0x0] != 0x55 || bcode[0x1] != 0xaa) {
2836 /* No signature */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002837 ql_log(ql_log_fatal, vha, 0x0059,
2838 "No matching ROM signature.\n");
Andrew Vasquez30c47662007-01-29 10:22:21 -08002839 ret = QLA_FUNCTION_FAILED;
2840 break;
2841 }
2842
2843 /* Locate PCI data structure. */
2844 pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]);
2845
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002846 qla24xx_read_flash_data(vha, dcode, pcids >> 2, 0x20);
Andrew Vasquez30c47662007-01-29 10:22:21 -08002847 bcode = mbuf + (pcihdr % 4);
2848
2849 /* Validate signature of PCI data structure. */
2850 if (bcode[0x0] != 'P' || bcode[0x1] != 'C' ||
2851 bcode[0x2] != 'I' || bcode[0x3] != 'R') {
2852 /* Incorrect header. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002853 ql_log(ql_log_fatal, vha, 0x005a,
2854 "PCI data struct not found pcir_adr=%x.\n", pcids);
Andrew Vasquez30c47662007-01-29 10:22:21 -08002855 ret = QLA_FUNCTION_FAILED;
2856 break;
2857 }
2858
2859 /* Read version */
2860 code_type = bcode[0x14];
2861 switch (code_type) {
2862 case ROM_CODE_TYPE_BIOS:
2863 /* Intel x86, PC-AT compatible. */
2864 ha->bios_revision[0] = bcode[0x12];
2865 ha->bios_revision[1] = bcode[0x13];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002866 ql_dbg(ql_dbg_init, vha, 0x005b,
2867 "Read BIOS %d.%d.\n",
2868 ha->bios_revision[1], ha->bios_revision[0]);
Andrew Vasquez30c47662007-01-29 10:22:21 -08002869 break;
2870 case ROM_CODE_TYPE_FCODE:
2871 /* Open Firmware standard for PCI (FCode). */
2872 ha->fcode_revision[0] = bcode[0x12];
2873 ha->fcode_revision[1] = bcode[0x13];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002874 ql_dbg(ql_dbg_init, vha, 0x005c,
2875 "Read FCODE %d.%d.\n",
2876 ha->fcode_revision[1], ha->fcode_revision[0]);
Andrew Vasquez30c47662007-01-29 10:22:21 -08002877 break;
2878 case ROM_CODE_TYPE_EFI:
2879 /* Extensible Firmware Interface (EFI). */
2880 ha->efi_revision[0] = bcode[0x12];
2881 ha->efi_revision[1] = bcode[0x13];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002882 ql_dbg(ql_dbg_init, vha, 0x005d,
2883 "Read EFI %d.%d.\n",
2884 ha->efi_revision[1], ha->efi_revision[0]);
Andrew Vasquez30c47662007-01-29 10:22:21 -08002885 break;
2886 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002887 ql_log(ql_log_warn, vha, 0x005e,
2888 "Unrecognized code type %x at pcids %x.\n",
2889 code_type, pcids);
Andrew Vasquez30c47662007-01-29 10:22:21 -08002890 break;
2891 }
2892
2893 last_image = bcode[0x15] & BIT_7;
2894
2895 /* Locate next PCI expansion ROM. */
2896 pcihdr += ((bcode[0x11] << 8) | bcode[0x10]) * 512;
2897 } while (!last_image);
2898
2899 /* Read firmware image information. */
2900 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
2901 dcode = mbuf;
2902
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002903 qla24xx_read_flash_data(vha, dcode, ha->flt_region_fw + 4, 4);
Andrew Vasquez30c47662007-01-29 10:22:21 -08002904 for (i = 0; i < 4; i++)
2905 dcode[i] = be32_to_cpu(dcode[i]);
2906
2907 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
2908 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
2909 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
2910 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002911 ql_log(ql_log_warn, vha, 0x005f,
2912 "Unrecognized fw revision at %x.\n",
2913 ha->flt_region_fw * 4);
Andrew Vasquez30c47662007-01-29 10:22:21 -08002914 } else {
2915 ha->fw_revision[0] = dcode[0];
2916 ha->fw_revision[1] = dcode[1];
2917 ha->fw_revision[2] = dcode[2];
2918 ha->fw_revision[3] = dcode[3];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002919 ql_dbg(ql_dbg_init, vha, 0x0060,
2920 "Firmware revision %d.%d.%d.%d.\n",
2921 ha->fw_revision[0], ha->fw_revision[1],
2922 ha->fw_revision[2], ha->fw_revision[3]);
Andrew Vasquez30c47662007-01-29 10:22:21 -08002923 }
2924
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05002925 /* Check for golden firmware and get version if available */
2926 if (!IS_QLA81XX(ha)) {
2927 /* Golden firmware is not present in non 81XX adapters */
2928 return ret;
2929 }
2930
2931 memset(ha->gold_fw_version, 0, sizeof(ha->gold_fw_version));
2932 dcode = mbuf;
2933 ha->isp_ops->read_optrom(vha, (uint8_t *)dcode,
2934 ha->flt_region_gold_fw << 2, 32);
2935
2936 if (dcode[4] == 0xFFFFFFFF && dcode[5] == 0xFFFFFFFF &&
2937 dcode[6] == 0xFFFFFFFF && dcode[7] == 0xFFFFFFFF) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002938 ql_log(ql_log_warn, vha, 0x0056,
2939 "Unrecognized golden fw at 0x%x.\n",
2940 ha->flt_region_gold_fw * 4);
Madhuranath Iyengar0f2d9622010-07-23 15:28:26 +05002941 return ret;
2942 }
2943
2944 for (i = 4; i < 8; i++)
2945 ha->gold_fw_version[i-4] = be32_to_cpu(dcode[i]);
2946
Andrew Vasquez30c47662007-01-29 10:22:21 -08002947 return ret;
2948}
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002949
2950static int
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002951qla2xxx_is_vpd_valid(uint8_t *pos, uint8_t *end)
2952{
2953 if (pos >= end || *pos != 0x82)
2954 return 0;
2955
2956 pos += 3 + pos[1];
2957 if (pos >= end || *pos != 0x90)
2958 return 0;
2959
2960 pos += 3 + pos[1];
2961 if (pos >= end || *pos != 0x78)
2962 return 0;
2963
2964 return 1;
2965}
2966
2967int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002968qla2xxx_get_vpd_field(scsi_qla_host_t *vha, char *key, char *str, size_t size)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002969{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002970 struct qla_hw_data *ha = vha->hw;
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002971 uint8_t *pos = ha->vpd;
2972 uint8_t *end = pos + ha->vpd_size;
2973 int len = 0;
2974
2975 if (!IS_FWI2_CAPABLE(ha) || !qla2xxx_is_vpd_valid(pos, end))
2976 return 0;
2977
2978 while (pos < end && *pos != 0x78) {
2979 len = (*pos == 0x82) ? pos[1] : pos[2];
2980
2981 if (!strncmp(pos, key, strlen(key)))
2982 break;
2983
2984 if (*pos != 0x90 && *pos != 0x91)
2985 pos += len;
2986
2987 pos += 3;
2988 }
2989
2990 if (pos < end - len && *pos != 0x78)
2991 return snprintf(str, size, "%.*s", len, pos + 3);
2992
2993 return 0;
2994}
Sarang Radke09ff7012010-03-19 17:03:59 -07002995
2996int
2997qla24xx_read_fcp_prio_cfg(scsi_qla_host_t *vha)
2998{
2999 int len, max_len;
3000 uint32_t fcp_prio_addr;
3001 struct qla_hw_data *ha = vha->hw;
3002
3003 if (!ha->fcp_prio_cfg) {
3004 ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE);
3005 if (!ha->fcp_prio_cfg) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003006 ql_log(ql_log_warn, vha, 0x00d5,
3007 "Unable to allocate memory for fcp priorty data (%x).\n",
3008 FCP_PRIO_CFG_SIZE);
Sarang Radke09ff7012010-03-19 17:03:59 -07003009 return QLA_FUNCTION_FAILED;
3010 }
3011 }
3012 memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE);
3013
3014 fcp_prio_addr = ha->flt_region_fcp_prio;
3015
3016 /* first read the fcp priority data header from flash */
3017 ha->isp_ops->read_optrom(vha, (uint8_t *)ha->fcp_prio_cfg,
3018 fcp_prio_addr << 2, FCP_PRIO_CFG_HDR_SIZE);
3019
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003020 if (!qla24xx_fcp_prio_cfg_valid(vha, ha->fcp_prio_cfg, 0))
Sarang Radke09ff7012010-03-19 17:03:59 -07003021 goto fail;
3022
3023 /* read remaining FCP CMD config data from flash */
3024 fcp_prio_addr += (FCP_PRIO_CFG_HDR_SIZE >> 2);
3025 len = ha->fcp_prio_cfg->num_entries * FCP_PRIO_CFG_ENTRY_SIZE;
3026 max_len = FCP_PRIO_CFG_SIZE - FCP_PRIO_CFG_HDR_SIZE;
3027
3028 ha->isp_ops->read_optrom(vha, (uint8_t *)&ha->fcp_prio_cfg->entry[0],
3029 fcp_prio_addr << 2, (len < max_len ? len : max_len));
3030
3031 /* revalidate the entire FCP priority config data, including entries */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003032 if (!qla24xx_fcp_prio_cfg_valid(vha, ha->fcp_prio_cfg, 1))
Sarang Radke09ff7012010-03-19 17:03:59 -07003033 goto fail;
3034
3035 ha->flags.fcp_prio_enabled = 1;
3036 return QLA_SUCCESS;
3037fail:
3038 vfree(ha->fcp_prio_cfg);
3039 ha->fcp_prio_cfg = NULL;
3040 return QLA_FUNCTION_FAILED;
3041}