2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2010 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
10 #include <linux/slab.h>
11 #include <linux/vmalloc.h>
12 #include <asm/uaccess.h>
15 * NVRAM support routines
19 * qla2x00_lock_nvram_access() -
23 qla2x00_lock_nvram_access(struct qla_hw_data
*ha
)
26 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
28 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
)) {
29 data
= RD_REG_WORD(®
->nvram
);
30 while (data
& NVR_BUSY
) {
32 data
= RD_REG_WORD(®
->nvram
);
36 WRT_REG_WORD(®
->u
.isp2300
.host_semaphore
, 0x1);
37 RD_REG_WORD(®
->u
.isp2300
.host_semaphore
);
39 data
= RD_REG_WORD(®
->u
.isp2300
.host_semaphore
);
40 while ((data
& BIT_0
) == 0) {
43 WRT_REG_WORD(®
->u
.isp2300
.host_semaphore
, 0x1);
44 RD_REG_WORD(®
->u
.isp2300
.host_semaphore
);
46 data
= RD_REG_WORD(®
->u
.isp2300
.host_semaphore
);
52 * qla2x00_unlock_nvram_access() -
56 qla2x00_unlock_nvram_access(struct qla_hw_data
*ha
)
58 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
60 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
)) {
61 WRT_REG_WORD(®
->u
.isp2300
.host_semaphore
, 0);
62 RD_REG_WORD(®
->u
.isp2300
.host_semaphore
);
67 * qla2x00_nv_write() - Prepare for NVRAM read/write operation.
69 * @data: Serial interface selector
72 qla2x00_nv_write(struct qla_hw_data
*ha
, uint16_t data
)
74 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
76 WRT_REG_WORD(®
->nvram
, data
| NVR_SELECT
| NVR_WRT_ENABLE
);
77 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
79 WRT_REG_WORD(®
->nvram
, data
| NVR_SELECT
| NVR_CLOCK
|
81 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
83 WRT_REG_WORD(®
->nvram
, data
| NVR_SELECT
| NVR_WRT_ENABLE
);
84 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
89 * qla2x00_nvram_request() - Sends read command to NVRAM and gets data from
92 * @nv_cmd: NVRAM command
94 * Bit definitions for NVRAM command:
99 * Bit 15-0 = write data
101 * Returns the word read from nvram @addr.
104 qla2x00_nvram_request(struct qla_hw_data
*ha
, uint32_t nv_cmd
)
107 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
111 /* Send command to NVRAM. */
113 for (cnt
= 0; cnt
< 11; cnt
++) {
115 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
117 qla2x00_nv_write(ha
, 0);
121 /* Read data from NVRAM. */
122 for (cnt
= 0; cnt
< 16; cnt
++) {
123 WRT_REG_WORD(®
->nvram
, NVR_SELECT
| NVR_CLOCK
);
124 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
127 reg_data
= RD_REG_WORD(®
->nvram
);
128 if (reg_data
& NVR_DATA_IN
)
130 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
131 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
136 WRT_REG_WORD(®
->nvram
, NVR_DESELECT
);
137 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
145 * qla2x00_get_nvram_word() - Calculates word position in NVRAM and calls the
146 * request routine to get the word from NVRAM.
148 * @addr: Address in NVRAM to read
150 * Returns the word read from nvram @addr.
153 qla2x00_get_nvram_word(struct qla_hw_data
*ha
, uint32_t addr
)
159 nv_cmd
|= NV_READ_OP
;
160 data
= qla2x00_nvram_request(ha
, nv_cmd
);
166 * qla2x00_nv_deselect() - Deselect NVRAM operations.
170 qla2x00_nv_deselect(struct qla_hw_data
*ha
)
172 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
174 WRT_REG_WORD(®
->nvram
, NVR_DESELECT
);
175 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
180 * qla2x00_write_nvram_word() - Write NVRAM data.
182 * @addr: Address in NVRAM to write
183 * @data: word to program
186 qla2x00_write_nvram_word(struct qla_hw_data
*ha
, uint32_t addr
, uint16_t data
)
190 uint32_t nv_cmd
, wait_cnt
;
191 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
193 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
194 qla2x00_nv_write(ha
, 0);
195 qla2x00_nv_write(ha
, 0);
197 for (word
= 0; word
< 8; word
++)
198 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
200 qla2x00_nv_deselect(ha
);
203 nv_cmd
= (addr
<< 16) | NV_WRITE_OP
;
206 for (count
= 0; count
< 27; count
++) {
208 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
210 qla2x00_nv_write(ha
, 0);
215 qla2x00_nv_deselect(ha
);
217 /* Wait for NVRAM to become ready */
218 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
219 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
220 wait_cnt
= NVR_WAIT_CNT
;
223 DEBUG9_10(qla_printk(KERN_WARNING
, ha
,
224 "NVRAM didn't go ready...\n"));
228 word
= RD_REG_WORD(®
->nvram
);
229 } while ((word
& NVR_DATA_IN
) == 0);
231 qla2x00_nv_deselect(ha
);
234 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
235 for (count
= 0; count
< 10; count
++)
236 qla2x00_nv_write(ha
, 0);
238 qla2x00_nv_deselect(ha
);
242 qla2x00_write_nvram_word_tmo(struct qla_hw_data
*ha
, uint32_t addr
,
243 uint16_t data
, uint32_t tmo
)
248 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
252 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
253 qla2x00_nv_write(ha
, 0);
254 qla2x00_nv_write(ha
, 0);
256 for (word
= 0; word
< 8; word
++)
257 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
259 qla2x00_nv_deselect(ha
);
262 nv_cmd
= (addr
<< 16) | NV_WRITE_OP
;
265 for (count
= 0; count
< 27; count
++) {
267 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
269 qla2x00_nv_write(ha
, 0);
274 qla2x00_nv_deselect(ha
);
276 /* Wait for NVRAM to become ready */
277 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
278 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
281 word
= RD_REG_WORD(®
->nvram
);
283 ret
= QLA_FUNCTION_FAILED
;
286 } while ((word
& NVR_DATA_IN
) == 0);
288 qla2x00_nv_deselect(ha
);
291 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
292 for (count
= 0; count
< 10; count
++)
293 qla2x00_nv_write(ha
, 0);
295 qla2x00_nv_deselect(ha
);
301 * qla2x00_clear_nvram_protection() -
305 qla2x00_clear_nvram_protection(struct qla_hw_data
*ha
)
308 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
309 uint32_t word
, wait_cnt
;
310 uint16_t wprot
, wprot_old
;
312 /* Clear NVRAM write protection. */
313 ret
= QLA_FUNCTION_FAILED
;
315 wprot_old
= cpu_to_le16(qla2x00_get_nvram_word(ha
, ha
->nvram_base
));
316 stat
= qla2x00_write_nvram_word_tmo(ha
, ha
->nvram_base
,
317 __constant_cpu_to_le16(0x1234), 100000);
318 wprot
= cpu_to_le16(qla2x00_get_nvram_word(ha
, ha
->nvram_base
));
319 if (stat
!= QLA_SUCCESS
|| wprot
!= 0x1234) {
321 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
322 qla2x00_nv_write(ha
, 0);
323 qla2x00_nv_write(ha
, 0);
324 for (word
= 0; word
< 8; word
++)
325 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
327 qla2x00_nv_deselect(ha
);
329 /* Enable protection register. */
330 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
331 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
332 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
333 for (word
= 0; word
< 8; word
++)
334 qla2x00_nv_write(ha
, NVR_DATA_OUT
| NVR_PR_ENABLE
);
336 qla2x00_nv_deselect(ha
);
338 /* Clear protection register (ffff is cleared). */
339 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
340 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
341 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
342 for (word
= 0; word
< 8; word
++)
343 qla2x00_nv_write(ha
, NVR_DATA_OUT
| NVR_PR_ENABLE
);
345 qla2x00_nv_deselect(ha
);
347 /* Wait for NVRAM to become ready. */
348 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
349 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
350 wait_cnt
= NVR_WAIT_CNT
;
353 DEBUG9_10(qla_printk(KERN_WARNING
, ha
,
354 "NVRAM didn't go ready...\n"));
358 word
= RD_REG_WORD(®
->nvram
);
359 } while ((word
& NVR_DATA_IN
) == 0);
364 qla2x00_write_nvram_word(ha
, ha
->nvram_base
, wprot_old
);
370 qla2x00_set_nvram_protection(struct qla_hw_data
*ha
, int stat
)
372 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
373 uint32_t word
, wait_cnt
;
375 if (stat
!= QLA_SUCCESS
)
378 /* Set NVRAM write protection. */
380 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
381 qla2x00_nv_write(ha
, 0);
382 qla2x00_nv_write(ha
, 0);
383 for (word
= 0; word
< 8; word
++)
384 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
386 qla2x00_nv_deselect(ha
);
388 /* Enable protection register. */
389 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
390 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
391 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
392 for (word
= 0; word
< 8; word
++)
393 qla2x00_nv_write(ha
, NVR_DATA_OUT
| NVR_PR_ENABLE
);
395 qla2x00_nv_deselect(ha
);
397 /* Enable protection register. */
398 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
399 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
400 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
401 for (word
= 0; word
< 8; word
++)
402 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
404 qla2x00_nv_deselect(ha
);
406 /* Wait for NVRAM to become ready. */
407 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
408 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
409 wait_cnt
= NVR_WAIT_CNT
;
412 DEBUG9_10(qla_printk(KERN_WARNING
, ha
,
413 "NVRAM didn't go ready...\n"));
417 word
= RD_REG_WORD(®
->nvram
);
418 } while ((word
& NVR_DATA_IN
) == 0);
422 /*****************************************************************************/
423 /* Flash Manipulation Routines */
424 /*****************************************************************************/
426 static inline uint32_t
427 flash_conf_addr(struct qla_hw_data
*ha
, uint32_t faddr
)
429 return ha
->flash_conf_off
| faddr
;
432 static inline uint32_t
433 flash_data_addr(struct qla_hw_data
*ha
, uint32_t faddr
)
435 return ha
->flash_data_off
| faddr
;
438 static inline uint32_t
439 nvram_conf_addr(struct qla_hw_data
*ha
, uint32_t naddr
)
441 return ha
->nvram_conf_off
| naddr
;
444 static inline uint32_t
445 nvram_data_addr(struct qla_hw_data
*ha
, uint32_t naddr
)
447 return ha
->nvram_data_off
| naddr
;
451 qla24xx_read_flash_dword(struct qla_hw_data
*ha
, uint32_t addr
)
455 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
457 WRT_REG_DWORD(®
->flash_addr
, addr
& ~FARX_DATA_FLAG
);
458 /* Wait for READ cycle to complete. */
461 (RD_REG_DWORD(®
->flash_addr
) & FARX_DATA_FLAG
) == 0 &&
462 rval
== QLA_SUCCESS
; cnt
--) {
466 rval
= QLA_FUNCTION_TIMEOUT
;
470 /* TODO: What happens if we time out? */
472 if (rval
== QLA_SUCCESS
)
473 data
= RD_REG_DWORD(®
->flash_data
);
479 qla24xx_read_flash_data(scsi_qla_host_t
*vha
, uint32_t *dwptr
, uint32_t faddr
,
483 struct qla_hw_data
*ha
= vha
->hw
;
485 /* Dword reads to flash. */
486 for (i
= 0; i
< dwords
; i
++, faddr
++)
487 dwptr
[i
] = cpu_to_le32(qla24xx_read_flash_dword(ha
,
488 flash_data_addr(ha
, faddr
)));
494 qla24xx_write_flash_dword(struct qla_hw_data
*ha
, uint32_t addr
, uint32_t data
)
498 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
500 WRT_REG_DWORD(®
->flash_data
, data
);
501 RD_REG_DWORD(®
->flash_data
); /* PCI Posting. */
502 WRT_REG_DWORD(®
->flash_addr
, addr
| FARX_DATA_FLAG
);
503 /* Wait for Write cycle to complete. */
505 for (cnt
= 500000; (RD_REG_DWORD(®
->flash_addr
) & FARX_DATA_FLAG
) &&
506 rval
== QLA_SUCCESS
; cnt
--) {
510 rval
= QLA_FUNCTION_TIMEOUT
;
517 qla24xx_get_flash_manufacturer(struct qla_hw_data
*ha
, uint8_t *man_id
,
522 ids
= qla24xx_read_flash_dword(ha
, flash_conf_addr(ha
, 0x03ab));
524 *flash_id
= MSB(ids
);
526 /* Check if man_id and flash_id are valid. */
527 if (ids
!= 0xDEADDEAD && (*man_id
== 0 || *flash_id
== 0)) {
528 /* Read information using 0x9f opcode
529 * Device ID, Mfg ID would be read in the format:
530 * <Ext Dev Info><Device ID Part2><Device ID Part 1><Mfg ID>
531 * Example: ATMEL 0x00 01 45 1F
532 * Extract MFG and Dev ID from last two bytes.
534 ids
= qla24xx_read_flash_dword(ha
, flash_conf_addr(ha
, 0x009f));
536 *flash_id
= MSB(ids
);
541 qla2xxx_find_flt_start(scsi_qla_host_t
*vha
, uint32_t *start
)
543 const char *loc
, *locations
[] = { "DEF", "PCI" };
544 uint32_t pcihdr
, pcids
;
546 uint8_t *buf
, *bcode
, last_image
;
547 uint16_t cnt
, chksum
, *wptr
;
548 struct qla_flt_location
*fltl
;
549 struct qla_hw_data
*ha
= vha
->hw
;
550 struct req_que
*req
= ha
->req_q_map
[0];
553 * FLT-location structure resides after the last PCI region.
556 /* Begin with sane defaults. */
559 if (IS_QLA24XX_TYPE(ha
))
560 *start
= FA_FLASH_LAYOUT_ADDR_24
;
561 else if (IS_QLA25XX(ha
))
562 *start
= FA_FLASH_LAYOUT_ADDR
;
563 else if (IS_QLA81XX(ha
))
564 *start
= FA_FLASH_LAYOUT_ADDR_81
;
565 else if (IS_QLA82XX(ha
)) {
566 *start
= FA_FLASH_LAYOUT_ADDR_82
;
569 /* Begin with first PCI expansion ROM header. */
570 buf
= (uint8_t *)req
->ring
;
571 dcode
= (uint32_t *)req
->ring
;
575 /* Verify PCI expansion ROM header. */
576 qla24xx_read_flash_data(vha
, dcode
, pcihdr
>> 2, 0x20);
577 bcode
= buf
+ (pcihdr
% 4);
578 if (bcode
[0x0] != 0x55 || bcode
[0x1] != 0xaa)
581 /* Locate PCI data structure. */
582 pcids
= pcihdr
+ ((bcode
[0x19] << 8) | bcode
[0x18]);
583 qla24xx_read_flash_data(vha
, dcode
, pcids
>> 2, 0x20);
584 bcode
= buf
+ (pcihdr
% 4);
586 /* Validate signature of PCI data structure. */
587 if (bcode
[0x0] != 'P' || bcode
[0x1] != 'C' ||
588 bcode
[0x2] != 'I' || bcode
[0x3] != 'R')
591 last_image
= bcode
[0x15] & BIT_7
;
593 /* Locate next PCI expansion ROM. */
594 pcihdr
+= ((bcode
[0x11] << 8) | bcode
[0x10]) * 512;
595 } while (!last_image
);
597 /* Now verify FLT-location structure. */
598 fltl
= (struct qla_flt_location
*)req
->ring
;
599 qla24xx_read_flash_data(vha
, dcode
, pcihdr
>> 2,
600 sizeof(struct qla_flt_location
) >> 2);
601 if (fltl
->sig
[0] != 'Q' || fltl
->sig
[1] != 'F' ||
602 fltl
->sig
[2] != 'L' || fltl
->sig
[3] != 'T')
605 wptr
= (uint16_t *)req
->ring
;
606 cnt
= sizeof(struct qla_flt_location
) >> 1;
607 for (chksum
= 0; cnt
; cnt
--)
608 chksum
+= le16_to_cpu(*wptr
++);
610 qla_printk(KERN_ERR
, ha
,
611 "Inconsistent FLTL detected: checksum=0x%x.\n", chksum
);
612 qla2x00_dump_buffer(buf
, sizeof(struct qla_flt_location
));
613 return QLA_FUNCTION_FAILED
;
616 /* Good data. Use specified location. */
618 *start
= (le16_to_cpu(fltl
->start_hi
) << 16 |
619 le16_to_cpu(fltl
->start_lo
)) >> 2;
621 DEBUG2(qla_printk(KERN_DEBUG
, ha
, "FLTL[%s] = 0x%x.\n", loc
, *start
));
626 qla2xxx_get_flt_info(scsi_qla_host_t
*vha
, uint32_t flt_addr
)
628 const char *loc
, *locations
[] = { "DEF", "FLT" };
629 const uint32_t def_fw
[] =
630 { FA_RISC_CODE_ADDR
, FA_RISC_CODE_ADDR
, FA_RISC_CODE_ADDR_81
};
631 const uint32_t def_boot
[] =
632 { FA_BOOT_CODE_ADDR
, FA_BOOT_CODE_ADDR
, FA_BOOT_CODE_ADDR_81
};
633 const uint32_t def_vpd_nvram
[] =
634 { FA_VPD_NVRAM_ADDR
, FA_VPD_NVRAM_ADDR
, FA_VPD_NVRAM_ADDR_81
};
635 const uint32_t def_vpd0
[] =
636 { 0, 0, FA_VPD0_ADDR_81
};
637 const uint32_t def_vpd1
[] =
638 { 0, 0, FA_VPD1_ADDR_81
};
639 const uint32_t def_nvram0
[] =
640 { 0, 0, FA_NVRAM0_ADDR_81
};
641 const uint32_t def_nvram1
[] =
642 { 0, 0, FA_NVRAM1_ADDR_81
};
643 const uint32_t def_fdt
[] =
644 { FA_FLASH_DESCR_ADDR_24
, FA_FLASH_DESCR_ADDR
,
645 FA_FLASH_DESCR_ADDR_81
};
646 const uint32_t def_npiv_conf0
[] =
647 { FA_NPIV_CONF0_ADDR_24
, FA_NPIV_CONF0_ADDR
,
648 FA_NPIV_CONF0_ADDR_81
};
649 const uint32_t def_npiv_conf1
[] =
650 { FA_NPIV_CONF1_ADDR_24
, FA_NPIV_CONF1_ADDR
,
651 FA_NPIV_CONF1_ADDR_81
};
652 const uint32_t fcp_prio_cfg0
[] =
653 { FA_FCP_PRIO0_ADDR
, FA_FCP_PRIO0_ADDR_25
,
655 const uint32_t fcp_prio_cfg1
[] =
656 { FA_FCP_PRIO1_ADDR
, FA_FCP_PRIO1_ADDR_25
,
660 uint16_t cnt
, chksum
;
662 struct qla_flt_header
*flt
;
663 struct qla_flt_region
*region
;
664 struct qla_hw_data
*ha
= vha
->hw
;
665 struct req_que
*req
= ha
->req_q_map
[0];
670 else if (IS_QLA81XX(ha
))
672 ha
->flt_region_flt
= flt_addr
;
673 wptr
= (uint16_t *)req
->ring
;
674 flt
= (struct qla_flt_header
*)req
->ring
;
675 region
= (struct qla_flt_region
*)&flt
[1];
676 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)req
->ring
,
677 flt_addr
<< 2, OPTROM_BURST_SIZE
);
678 if (*wptr
== __constant_cpu_to_le16(0xffff))
680 if (flt
->version
!= __constant_cpu_to_le16(1)) {
681 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unsupported FLT detected: "
682 "version=0x%x length=0x%x checksum=0x%x.\n",
683 le16_to_cpu(flt
->version
), le16_to_cpu(flt
->length
),
684 le16_to_cpu(flt
->checksum
)));
688 cnt
= (sizeof(struct qla_flt_header
) + le16_to_cpu(flt
->length
)) >> 1;
689 for (chksum
= 0; cnt
; cnt
--)
690 chksum
+= le16_to_cpu(*wptr
++);
692 DEBUG2(qla_printk(KERN_INFO
, ha
, "Inconsistent FLT detected: "
693 "version=0x%x length=0x%x checksum=0x%x.\n",
694 le16_to_cpu(flt
->version
), le16_to_cpu(flt
->length
),
699 /* Assign FCP prio region since older FLT's may not have it */
700 ha
->flt_region_fcp_prio
= ha
->flags
.port0
?
701 fcp_prio_cfg0
[def
] : fcp_prio_cfg1
[def
];
704 cnt
= le16_to_cpu(flt
->length
) / sizeof(struct qla_flt_region
);
705 for ( ; cnt
; cnt
--, region
++) {
706 /* Store addresses as DWORD offsets. */
707 start
= le32_to_cpu(region
->start
) >> 2;
709 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "FLT[%02x]: start=0x%x "
710 "end=0x%x size=0x%x.\n", le32_to_cpu(region
->code
), start
,
711 le32_to_cpu(region
->end
) >> 2, le32_to_cpu(region
->size
)));
713 switch (le32_to_cpu(region
->code
) & 0xff) {
715 ha
->flt_region_fw
= start
;
717 case FLT_REG_BOOT_CODE
:
718 ha
->flt_region_boot
= start
;
721 ha
->flt_region_vpd_nvram
= start
;
725 ha
->flt_region_vpd
= start
;
730 if (!ha
->flags
.port0
)
731 ha
->flt_region_vpd
= start
;
733 case FLT_REG_NVRAM_0
:
735 ha
->flt_region_nvram
= start
;
737 case FLT_REG_NVRAM_1
:
738 if (!ha
->flags
.port0
)
739 ha
->flt_region_nvram
= start
;
742 ha
->flt_region_fdt
= start
;
744 case FLT_REG_NPIV_CONF_0
:
746 ha
->flt_region_npiv_conf
= start
;
748 case FLT_REG_NPIV_CONF_1
:
749 if (!ha
->flags
.port0
)
750 ha
->flt_region_npiv_conf
= start
;
752 case FLT_REG_GOLD_FW
:
753 ha
->flt_region_gold_fw
= start
;
755 case FLT_REG_FCP_PRIO_0
:
757 ha
->flt_region_fcp_prio
= start
;
759 case FLT_REG_FCP_PRIO_1
:
760 if (!ha
->flags
.port0
)
761 ha
->flt_region_fcp_prio
= start
;
763 case FLT_REG_BOOT_CODE_82XX
:
764 ha
->flt_region_boot
= start
;
766 case FLT_REG_FW_82XX
:
767 ha
->flt_region_fw
= start
;
769 case FLT_REG_GOLD_FW_82XX
:
770 ha
->flt_region_gold_fw
= start
;
772 case FLT_REG_BOOTLOAD_82XX
:
773 ha
->flt_region_bootload
= start
;
775 case FLT_REG_VPD_82XX
:
776 ha
->flt_region_vpd
= start
;
783 /* Use hardcoded defaults. */
785 ha
->flt_region_fw
= def_fw
[def
];
786 ha
->flt_region_boot
= def_boot
[def
];
787 ha
->flt_region_vpd_nvram
= def_vpd_nvram
[def
];
788 ha
->flt_region_vpd
= ha
->flags
.port0
?
789 def_vpd0
[def
] : def_vpd1
[def
];
790 ha
->flt_region_nvram
= ha
->flags
.port0
?
791 def_nvram0
[def
] : def_nvram1
[def
];
792 ha
->flt_region_fdt
= def_fdt
[def
];
793 ha
->flt_region_npiv_conf
= ha
->flags
.port0
?
794 def_npiv_conf0
[def
] : def_npiv_conf1
[def
];
796 DEBUG2(qla_printk(KERN_DEBUG
, ha
, "FLT[%s]: boot=0x%x fw=0x%x "
797 "vpd_nvram=0x%x vpd=0x%x nvram=0x%x fdt=0x%x flt=0x%x "
798 "npiv=0x%x. fcp_prio_cfg=0x%x\n", loc
, ha
->flt_region_boot
,
799 ha
->flt_region_fw
, ha
->flt_region_vpd_nvram
, ha
->flt_region_vpd
,
800 ha
->flt_region_nvram
, ha
->flt_region_fdt
, ha
->flt_region_flt
,
801 ha
->flt_region_npiv_conf
, ha
->flt_region_fcp_prio
));
805 qla2xxx_get_fdt_info(scsi_qla_host_t
*vha
)
807 #define FLASH_BLK_SIZE_4K 0x1000
808 #define FLASH_BLK_SIZE_32K 0x8000
809 #define FLASH_BLK_SIZE_64K 0x10000
810 const char *loc
, *locations
[] = { "MID", "FDT" };
811 uint16_t cnt
, chksum
;
813 struct qla_fdt_layout
*fdt
;
814 uint8_t man_id
, flash_id
;
815 uint16_t mid
= 0, fid
= 0;
816 struct qla_hw_data
*ha
= vha
->hw
;
817 struct req_que
*req
= ha
->req_q_map
[0];
819 wptr
= (uint16_t *)req
->ring
;
820 fdt
= (struct qla_fdt_layout
*)req
->ring
;
821 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)req
->ring
,
822 ha
->flt_region_fdt
<< 2, OPTROM_BURST_SIZE
);
823 if (*wptr
== __constant_cpu_to_le16(0xffff))
825 if (fdt
->sig
[0] != 'Q' || fdt
->sig
[1] != 'L' || fdt
->sig
[2] != 'I' ||
829 for (cnt
= 0, chksum
= 0; cnt
< sizeof(struct qla_fdt_layout
) >> 1;
831 chksum
+= le16_to_cpu(*wptr
++);
833 DEBUG2(qla_printk(KERN_INFO
, ha
, "Inconsistent FDT detected: "
834 "checksum=0x%x id=%c version=0x%x.\n", chksum
, fdt
->sig
[0],
835 le16_to_cpu(fdt
->version
)));
836 DEBUG9(qla2x00_dump_buffer((uint8_t *)fdt
, sizeof(*fdt
)));
841 mid
= le16_to_cpu(fdt
->man_id
);
842 fid
= le16_to_cpu(fdt
->id
);
843 ha
->fdt_wrt_disable
= fdt
->wrt_disable_bits
;
844 ha
->fdt_erase_cmd
= flash_conf_addr(ha
, 0x0300 | fdt
->erase_cmd
);
845 ha
->fdt_block_size
= le32_to_cpu(fdt
->block_size
);
846 if (fdt
->unprotect_sec_cmd
) {
847 ha
->fdt_unprotect_sec_cmd
= flash_conf_addr(ha
, 0x0300 |
848 fdt
->unprotect_sec_cmd
);
849 ha
->fdt_protect_sec_cmd
= fdt
->protect_sec_cmd
?
850 flash_conf_addr(ha
, 0x0300 | fdt
->protect_sec_cmd
):
851 flash_conf_addr(ha
, 0x0336);
856 if (IS_QLA82XX(ha
)) {
857 ha
->fdt_block_size
= FLASH_BLK_SIZE_64K
;
860 qla24xx_get_flash_manufacturer(ha
, &man_id
, &flash_id
);
863 ha
->fdt_wrt_disable
= 0x9c;
864 ha
->fdt_erase_cmd
= flash_conf_addr(ha
, 0x03d8);
866 case 0xbf: /* STT flash. */
867 if (flash_id
== 0x8e)
868 ha
->fdt_block_size
= FLASH_BLK_SIZE_64K
;
870 ha
->fdt_block_size
= FLASH_BLK_SIZE_32K
;
872 if (flash_id
== 0x80)
873 ha
->fdt_erase_cmd
= flash_conf_addr(ha
, 0x0352);
875 case 0x13: /* ST M25P80. */
876 ha
->fdt_block_size
= FLASH_BLK_SIZE_64K
;
878 case 0x1f: /* Atmel 26DF081A. */
879 ha
->fdt_block_size
= FLASH_BLK_SIZE_4K
;
880 ha
->fdt_erase_cmd
= flash_conf_addr(ha
, 0x0320);
881 ha
->fdt_unprotect_sec_cmd
= flash_conf_addr(ha
, 0x0339);
882 ha
->fdt_protect_sec_cmd
= flash_conf_addr(ha
, 0x0336);
885 /* Default to 64 kb sector size. */
886 ha
->fdt_block_size
= FLASH_BLK_SIZE_64K
;
890 DEBUG2(qla_printk(KERN_DEBUG
, ha
, "FDT[%s]: (0x%x/0x%x) erase=0x%x "
891 "pro=%x upro=%x wrtd=0x%x blk=0x%x.\n", loc
, mid
, fid
,
892 ha
->fdt_erase_cmd
, ha
->fdt_protect_sec_cmd
,
893 ha
->fdt_unprotect_sec_cmd
, ha
->fdt_wrt_disable
,
894 ha
->fdt_block_size
));
898 qla2xxx_get_idc_param(scsi_qla_host_t
*vha
)
900 #define QLA82XX_IDC_PARAM_ADDR 0x003e885c
902 struct qla_hw_data
*ha
= vha
->hw
;
903 struct req_que
*req
= ha
->req_q_map
[0];
908 wptr
= (uint32_t *)req
->ring
;
909 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)req
->ring
,
910 QLA82XX_IDC_PARAM_ADDR
, 8);
912 if (*wptr
== __constant_cpu_to_le32(0xffffffff)) {
913 ha
->nx_dev_init_timeout
= QLA82XX_ROM_DEV_INIT_TIMEOUT
;
914 ha
->nx_reset_timeout
= QLA82XX_ROM_DRV_RESET_ACK_TIMEOUT
;
916 ha
->nx_dev_init_timeout
= le32_to_cpu(*wptr
++);
917 ha
->nx_reset_timeout
= le32_to_cpu(*wptr
);
923 qla2xxx_get_flash_info(scsi_qla_host_t
*vha
)
927 struct qla_hw_data
*ha
= vha
->hw
;
929 if (!IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) && !IS_QLA8XXX_TYPE(ha
))
932 ret
= qla2xxx_find_flt_start(vha
, &flt_addr
);
933 if (ret
!= QLA_SUCCESS
)
936 qla2xxx_get_flt_info(vha
, flt_addr
);
937 qla2xxx_get_fdt_info(vha
);
938 qla2xxx_get_idc_param(vha
);
944 qla2xxx_flash_npiv_conf(scsi_qla_host_t
*vha
)
946 #define NPIV_CONFIG_SIZE (16*1024)
949 uint16_t cnt
, chksum
;
951 struct qla_npiv_header hdr
;
952 struct qla_npiv_entry
*entry
;
953 struct qla_hw_data
*ha
= vha
->hw
;
955 if (!IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) && !IS_QLA8XXX_TYPE(ha
))
958 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)&hdr
,
959 ha
->flt_region_npiv_conf
<< 2, sizeof(struct qla_npiv_header
));
960 if (hdr
.version
== __constant_cpu_to_le16(0xffff))
962 if (hdr
.version
!= __constant_cpu_to_le16(1)) {
963 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unsupported NPIV-Config "
964 "detected: version=0x%x entries=0x%x checksum=0x%x.\n",
965 le16_to_cpu(hdr
.version
), le16_to_cpu(hdr
.entries
),
966 le16_to_cpu(hdr
.checksum
)));
970 data
= kmalloc(NPIV_CONFIG_SIZE
, GFP_KERNEL
);
972 DEBUG2(qla_printk(KERN_INFO
, ha
, "NPIV-Config: Unable to "
973 "allocate memory.\n"));
977 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)data
,
978 ha
->flt_region_npiv_conf
<< 2, NPIV_CONFIG_SIZE
);
980 cnt
= (sizeof(struct qla_npiv_header
) + le16_to_cpu(hdr
.entries
) *
981 sizeof(struct qla_npiv_entry
)) >> 1;
982 for (wptr
= data
, chksum
= 0; cnt
; cnt
--)
983 chksum
+= le16_to_cpu(*wptr
++);
985 DEBUG2(qla_printk(KERN_INFO
, ha
, "Inconsistent NPIV-Config "
986 "detected: version=0x%x entries=0x%x checksum=0x%x.\n",
987 le16_to_cpu(hdr
.version
), le16_to_cpu(hdr
.entries
),
992 entry
= data
+ sizeof(struct qla_npiv_header
);
993 cnt
= le16_to_cpu(hdr
.entries
);
994 for (i
= 0; cnt
; cnt
--, entry
++, i
++) {
996 struct fc_vport_identifiers vid
;
997 struct fc_vport
*vport
;
999 memcpy(&ha
->npiv_info
[i
], entry
, sizeof(struct qla_npiv_entry
));
1001 flags
= le16_to_cpu(entry
->flags
);
1002 if (flags
== 0xffff)
1004 if ((flags
& BIT_0
) == 0)
1007 memset(&vid
, 0, sizeof(vid
));
1008 vid
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
1009 vid
.vport_type
= FC_PORTTYPE_NPIV
;
1010 vid
.disable
= false;
1011 vid
.port_name
= wwn_to_u64(entry
->port_name
);
1012 vid
.node_name
= wwn_to_u64(entry
->node_name
);
1014 DEBUG2(qla_printk(KERN_INFO
, ha
, "NPIV[%02x]: wwpn=%llx "
1015 "wwnn=%llx vf_id=0x%x Q_qos=0x%x F_qos=0x%x.\n", cnt
,
1016 (unsigned long long)vid
.port_name
,
1017 (unsigned long long)vid
.node_name
,
1018 le16_to_cpu(entry
->vf_id
),
1019 entry
->q_qos
, entry
->f_qos
));
1021 if (i
< QLA_PRECONFIG_VPORTS
) {
1022 vport
= fc_vport_create(vha
->host
, 0, &vid
);
1024 qla_printk(KERN_INFO
, ha
,
1025 "NPIV-Config: Failed to create vport [%02x]: "
1026 "wwpn=%llx wwnn=%llx.\n", cnt
,
1027 (unsigned long long)vid
.port_name
,
1028 (unsigned long long)vid
.node_name
);
1036 qla24xx_unprotect_flash(scsi_qla_host_t
*vha
)
1038 struct qla_hw_data
*ha
= vha
->hw
;
1039 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1041 if (ha
->flags
.fac_supported
)
1042 return qla81xx_fac_do_write_enable(vha
, 1);
1044 /* Enable flash write. */
1045 WRT_REG_DWORD(®
->ctrl_status
,
1046 RD_REG_DWORD(®
->ctrl_status
) | CSRX_FLASH_ENABLE
);
1047 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
1049 if (!ha
->fdt_wrt_disable
)
1052 /* Disable flash write-protection, first clear SR protection bit */
1053 qla24xx_write_flash_dword(ha
, flash_conf_addr(ha
, 0x101), 0);
1054 /* Then write zero again to clear remaining SR bits.*/
1055 qla24xx_write_flash_dword(ha
, flash_conf_addr(ha
, 0x101), 0);
1061 qla24xx_protect_flash(scsi_qla_host_t
*vha
)
1064 struct qla_hw_data
*ha
= vha
->hw
;
1065 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1067 if (ha
->flags
.fac_supported
)
1068 return qla81xx_fac_do_write_enable(vha
, 0);
1070 if (!ha
->fdt_wrt_disable
)
1071 goto skip_wrt_protect
;
1073 /* Enable flash write-protection and wait for completion. */
1074 qla24xx_write_flash_dword(ha
, flash_conf_addr(ha
, 0x101),
1075 ha
->fdt_wrt_disable
);
1076 for (cnt
= 300; cnt
&&
1077 qla24xx_read_flash_dword(ha
, flash_conf_addr(ha
, 0x005)) & BIT_0
;
1083 /* Disable flash write. */
1084 WRT_REG_DWORD(®
->ctrl_status
,
1085 RD_REG_DWORD(®
->ctrl_status
) & ~CSRX_FLASH_ENABLE
);
1086 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
1092 qla24xx_erase_sector(scsi_qla_host_t
*vha
, uint32_t fdata
)
1094 struct qla_hw_data
*ha
= vha
->hw
;
1095 uint32_t start
, finish
;
1097 if (ha
->flags
.fac_supported
) {
1099 finish
= start
+ (ha
->fdt_block_size
>> 2) - 1;
1100 return qla81xx_fac_erase_sector(vha
, flash_data_addr(ha
,
1101 start
), flash_data_addr(ha
, finish
));
1104 return qla24xx_write_flash_dword(ha
, ha
->fdt_erase_cmd
,
1105 (fdata
& 0xff00) | ((fdata
<< 16) & 0xff0000) |
1106 ((fdata
>> 16) & 0xff));
1110 qla24xx_write_flash_data(scsi_qla_host_t
*vha
, uint32_t *dwptr
, uint32_t faddr
,
1115 uint32_t sec_mask
, rest_addr
;
1117 dma_addr_t optrom_dma
;
1118 void *optrom
= NULL
;
1119 struct qla_hw_data
*ha
= vha
->hw
;
1121 /* Prepare burst-capable write on supported ISPs. */
1122 if ((IS_QLA25XX(ha
) || IS_QLA81XX(ha
)) && !(faddr
& 0xfff) &&
1123 dwords
> OPTROM_BURST_DWORDS
) {
1124 optrom
= dma_alloc_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
,
1125 &optrom_dma
, GFP_KERNEL
);
1127 qla_printk(KERN_DEBUG
, ha
,
1128 "Unable to allocate memory for optrom burst write "
1129 "(%x KB).\n", OPTROM_BURST_SIZE
/ 1024);
1133 rest_addr
= (ha
->fdt_block_size
>> 2) - 1;
1134 sec_mask
= ~rest_addr
;
1136 ret
= qla24xx_unprotect_flash(vha
);
1137 if (ret
!= QLA_SUCCESS
) {
1138 qla_printk(KERN_WARNING
, ha
,
1139 "Unable to unprotect flash for update.\n");
1143 for (liter
= 0; liter
< dwords
; liter
++, faddr
++, dwptr
++) {
1144 fdata
= (faddr
& sec_mask
) << 2;
1146 /* Are we at the beginning of a sector? */
1147 if ((faddr
& rest_addr
) == 0) {
1148 /* Do sector unprotect. */
1149 if (ha
->fdt_unprotect_sec_cmd
)
1150 qla24xx_write_flash_dword(ha
,
1151 ha
->fdt_unprotect_sec_cmd
,
1152 (fdata
& 0xff00) | ((fdata
<< 16) &
1153 0xff0000) | ((fdata
>> 16) & 0xff));
1154 ret
= qla24xx_erase_sector(vha
, fdata
);
1155 if (ret
!= QLA_SUCCESS
) {
1156 DEBUG9(qla_printk(KERN_WARNING
, ha
,
1157 "Unable to erase sector: address=%x.\n",
1163 /* Go with burst-write. */
1164 if (optrom
&& (liter
+ OPTROM_BURST_DWORDS
) <= dwords
) {
1165 /* Copy data to DMA'ble buffer. */
1166 memcpy(optrom
, dwptr
, OPTROM_BURST_SIZE
);
1168 ret
= qla2x00_load_ram(vha
, optrom_dma
,
1169 flash_data_addr(ha
, faddr
),
1170 OPTROM_BURST_DWORDS
);
1171 if (ret
!= QLA_SUCCESS
) {
1172 qla_printk(KERN_WARNING
, ha
,
1173 "Unable to burst-write optrom segment "
1174 "(%x/%x/%llx).\n", ret
,
1175 flash_data_addr(ha
, faddr
),
1176 (unsigned long long)optrom_dma
);
1177 qla_printk(KERN_WARNING
, ha
,
1178 "Reverting to slow-write.\n");
1180 dma_free_coherent(&ha
->pdev
->dev
,
1181 OPTROM_BURST_SIZE
, optrom
, optrom_dma
);
1184 liter
+= OPTROM_BURST_DWORDS
- 1;
1185 faddr
+= OPTROM_BURST_DWORDS
- 1;
1186 dwptr
+= OPTROM_BURST_DWORDS
- 1;
1191 ret
= qla24xx_write_flash_dword(ha
,
1192 flash_data_addr(ha
, faddr
), cpu_to_le32(*dwptr
));
1193 if (ret
!= QLA_SUCCESS
) {
1194 DEBUG9(printk("%s(%ld) Unable to program flash "
1195 "address=%x data=%x.\n", __func__
,
1196 vha
->host_no
, faddr
, *dwptr
));
1200 /* Do sector protect. */
1201 if (ha
->fdt_unprotect_sec_cmd
&&
1202 ((faddr
& rest_addr
) == rest_addr
))
1203 qla24xx_write_flash_dword(ha
,
1204 ha
->fdt_protect_sec_cmd
,
1205 (fdata
& 0xff00) | ((fdata
<< 16) &
1206 0xff0000) | ((fdata
>> 16) & 0xff));
1209 ret
= qla24xx_protect_flash(vha
);
1210 if (ret
!= QLA_SUCCESS
)
1211 qla_printk(KERN_WARNING
, ha
,
1212 "Unable to protect flash after update.\n");
1215 dma_free_coherent(&ha
->pdev
->dev
,
1216 OPTROM_BURST_SIZE
, optrom
, optrom_dma
);
1222 qla2x00_read_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1227 struct qla_hw_data
*ha
= vha
->hw
;
1229 /* Word reads to NVRAM via registers. */
1230 wptr
= (uint16_t *)buf
;
1231 qla2x00_lock_nvram_access(ha
);
1232 for (i
= 0; i
< bytes
>> 1; i
++, naddr
++)
1233 wptr
[i
] = cpu_to_le16(qla2x00_get_nvram_word(ha
,
1235 qla2x00_unlock_nvram_access(ha
);
1241 qla24xx_read_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1246 struct qla_hw_data
*ha
= vha
->hw
;
1251 /* Dword reads to flash. */
1252 dwptr
= (uint32_t *)buf
;
1253 for (i
= 0; i
< bytes
>> 2; i
++, naddr
++)
1254 dwptr
[i
] = cpu_to_le32(qla24xx_read_flash_dword(ha
,
1255 nvram_data_addr(ha
, naddr
)));
1261 qla2x00_write_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1267 unsigned long flags
;
1268 struct qla_hw_data
*ha
= vha
->hw
;
1272 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1273 qla2x00_lock_nvram_access(ha
);
1275 /* Disable NVRAM write-protection. */
1276 stat
= qla2x00_clear_nvram_protection(ha
);
1278 wptr
= (uint16_t *)buf
;
1279 for (i
= 0; i
< bytes
>> 1; i
++, naddr
++) {
1280 qla2x00_write_nvram_word(ha
, naddr
,
1281 cpu_to_le16(*wptr
));
1285 /* Enable NVRAM write-protection. */
1286 qla2x00_set_nvram_protection(ha
, stat
);
1288 qla2x00_unlock_nvram_access(ha
);
1289 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1295 qla24xx_write_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1301 struct qla_hw_data
*ha
= vha
->hw
;
1302 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1309 /* Enable flash write. */
1310 WRT_REG_DWORD(®
->ctrl_status
,
1311 RD_REG_DWORD(®
->ctrl_status
) | CSRX_FLASH_ENABLE
);
1312 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
1314 /* Disable NVRAM write-protection. */
1315 qla24xx_write_flash_dword(ha
, nvram_conf_addr(ha
, 0x101), 0);
1316 qla24xx_write_flash_dword(ha
, nvram_conf_addr(ha
, 0x101), 0);
1318 /* Dword writes to flash. */
1319 dwptr
= (uint32_t *)buf
;
1320 for (i
= 0; i
< bytes
>> 2; i
++, naddr
++, dwptr
++) {
1321 ret
= qla24xx_write_flash_dword(ha
,
1322 nvram_data_addr(ha
, naddr
), cpu_to_le32(*dwptr
));
1323 if (ret
!= QLA_SUCCESS
) {
1324 DEBUG9(qla_printk(KERN_WARNING
, ha
,
1325 "Unable to program nvram address=%x data=%x.\n",
1331 /* Enable NVRAM write-protection. */
1332 qla24xx_write_flash_dword(ha
, nvram_conf_addr(ha
, 0x101), 0x8c);
1334 /* Disable flash write. */
1335 WRT_REG_DWORD(®
->ctrl_status
,
1336 RD_REG_DWORD(®
->ctrl_status
) & ~CSRX_FLASH_ENABLE
);
1337 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
1343 qla25xx_read_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1348 struct qla_hw_data
*ha
= vha
->hw
;
1350 /* Dword reads to flash. */
1351 dwptr
= (uint32_t *)buf
;
1352 for (i
= 0; i
< bytes
>> 2; i
++, naddr
++)
1353 dwptr
[i
] = cpu_to_le32(qla24xx_read_flash_dword(ha
,
1354 flash_data_addr(ha
, ha
->flt_region_vpd_nvram
| naddr
)));
1360 qla25xx_write_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1363 struct qla_hw_data
*ha
= vha
->hw
;
1364 #define RMW_BUFFER_SIZE (64 * 1024)
1367 dbuf
= vmalloc(RMW_BUFFER_SIZE
);
1369 return QLA_MEMORY_ALLOC_FAILED
;
1370 ha
->isp_ops
->read_optrom(vha
, dbuf
, ha
->flt_region_vpd_nvram
<< 2,
1372 memcpy(dbuf
+ (naddr
<< 2), buf
, bytes
);
1373 ha
->isp_ops
->write_optrom(vha
, dbuf
, ha
->flt_region_vpd_nvram
<< 2,
1381 qla2x00_flip_colors(struct qla_hw_data
*ha
, uint16_t *pflags
)
1383 if (IS_QLA2322(ha
)) {
1384 /* Flip all colors. */
1385 if (ha
->beacon_color_state
== QLA_LED_ALL_ON
) {
1387 ha
->beacon_color_state
= 0;
1388 *pflags
= GPIO_LED_ALL_OFF
;
1391 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1392 *pflags
= GPIO_LED_RGA_ON
;
1395 /* Flip green led only. */
1396 if (ha
->beacon_color_state
== QLA_LED_GRN_ON
) {
1398 ha
->beacon_color_state
= 0;
1399 *pflags
= GPIO_LED_GREEN_OFF_AMBER_OFF
;
1402 ha
->beacon_color_state
= QLA_LED_GRN_ON
;
1403 *pflags
= GPIO_LED_GREEN_ON_AMBER_OFF
;
1408 #define PIO_REG(h, r) ((h)->pio_address + offsetof(struct device_reg_2xxx, r))
1411 qla2x00_beacon_blink(struct scsi_qla_host
*vha
)
1413 uint16_t gpio_enable
;
1415 uint16_t led_color
= 0;
1416 unsigned long flags
;
1417 struct qla_hw_data
*ha
= vha
->hw
;
1418 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1423 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1425 /* Save the Original GPIOE. */
1426 if (ha
->pio_address
) {
1427 gpio_enable
= RD_REG_WORD_PIO(PIO_REG(ha
, gpioe
));
1428 gpio_data
= RD_REG_WORD_PIO(PIO_REG(ha
, gpiod
));
1430 gpio_enable
= RD_REG_WORD(®
->gpioe
);
1431 gpio_data
= RD_REG_WORD(®
->gpiod
);
1434 /* Set the modified gpio_enable values */
1435 gpio_enable
|= GPIO_LED_MASK
;
1437 if (ha
->pio_address
) {
1438 WRT_REG_WORD_PIO(PIO_REG(ha
, gpioe
), gpio_enable
);
1440 WRT_REG_WORD(®
->gpioe
, gpio_enable
);
1441 RD_REG_WORD(®
->gpioe
);
1444 qla2x00_flip_colors(ha
, &led_color
);
1446 /* Clear out any previously set LED color. */
1447 gpio_data
&= ~GPIO_LED_MASK
;
1449 /* Set the new input LED color to GPIOD. */
1450 gpio_data
|= led_color
;
1452 /* Set the modified gpio_data values */
1453 if (ha
->pio_address
) {
1454 WRT_REG_WORD_PIO(PIO_REG(ha
, gpiod
), gpio_data
);
1456 WRT_REG_WORD(®
->gpiod
, gpio_data
);
1457 RD_REG_WORD(®
->gpiod
);
1460 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1464 qla2x00_beacon_on(struct scsi_qla_host
*vha
)
1466 uint16_t gpio_enable
;
1468 unsigned long flags
;
1469 struct qla_hw_data
*ha
= vha
->hw
;
1470 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1472 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1473 ha
->fw_options
[1] |= FO1_DISABLE_GPIO6_7
;
1475 if (qla2x00_set_fw_options(vha
, ha
->fw_options
) != QLA_SUCCESS
) {
1476 qla_printk(KERN_WARNING
, ha
,
1477 "Unable to update fw options (beacon on).\n");
1478 return QLA_FUNCTION_FAILED
;
1481 /* Turn off LEDs. */
1482 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1483 if (ha
->pio_address
) {
1484 gpio_enable
= RD_REG_WORD_PIO(PIO_REG(ha
, gpioe
));
1485 gpio_data
= RD_REG_WORD_PIO(PIO_REG(ha
, gpiod
));
1487 gpio_enable
= RD_REG_WORD(®
->gpioe
);
1488 gpio_data
= RD_REG_WORD(®
->gpiod
);
1490 gpio_enable
|= GPIO_LED_MASK
;
1492 /* Set the modified gpio_enable values. */
1493 if (ha
->pio_address
) {
1494 WRT_REG_WORD_PIO(PIO_REG(ha
, gpioe
), gpio_enable
);
1496 WRT_REG_WORD(®
->gpioe
, gpio_enable
);
1497 RD_REG_WORD(®
->gpioe
);
1500 /* Clear out previously set LED colour. */
1501 gpio_data
&= ~GPIO_LED_MASK
;
1502 if (ha
->pio_address
) {
1503 WRT_REG_WORD_PIO(PIO_REG(ha
, gpiod
), gpio_data
);
1505 WRT_REG_WORD(®
->gpiod
, gpio_data
);
1506 RD_REG_WORD(®
->gpiod
);
1508 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1511 * Let the per HBA timer kick off the blinking process based on
1512 * the following flags. No need to do anything else now.
1514 ha
->beacon_blink_led
= 1;
1515 ha
->beacon_color_state
= 0;
1521 qla2x00_beacon_off(struct scsi_qla_host
*vha
)
1523 int rval
= QLA_SUCCESS
;
1524 struct qla_hw_data
*ha
= vha
->hw
;
1526 ha
->beacon_blink_led
= 0;
1528 /* Set the on flag so when it gets flipped it will be off. */
1530 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1532 ha
->beacon_color_state
= QLA_LED_GRN_ON
;
1534 ha
->isp_ops
->beacon_blink(vha
); /* This turns green LED off */
1536 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1537 ha
->fw_options
[1] &= ~FO1_DISABLE_GPIO6_7
;
1539 rval
= qla2x00_set_fw_options(vha
, ha
->fw_options
);
1540 if (rval
!= QLA_SUCCESS
)
1541 qla_printk(KERN_WARNING
, ha
,
1542 "Unable to update fw options (beacon off).\n");
1548 qla24xx_flip_colors(struct qla_hw_data
*ha
, uint16_t *pflags
)
1550 /* Flip all colors. */
1551 if (ha
->beacon_color_state
== QLA_LED_ALL_ON
) {
1553 ha
->beacon_color_state
= 0;
1557 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1558 *pflags
= GPDX_LED_YELLOW_ON
| GPDX_LED_AMBER_ON
;
1563 qla24xx_beacon_blink(struct scsi_qla_host
*vha
)
1565 uint16_t led_color
= 0;
1567 unsigned long flags
;
1568 struct qla_hw_data
*ha
= vha
->hw
;
1569 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1571 /* Save the Original GPIOD. */
1572 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1573 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1575 /* Enable the gpio_data reg for update. */
1576 gpio_data
|= GPDX_LED_UPDATE_MASK
;
1578 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1579 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1581 /* Set the color bits. */
1582 qla24xx_flip_colors(ha
, &led_color
);
1584 /* Clear out any previously set LED color. */
1585 gpio_data
&= ~GPDX_LED_COLOR_MASK
;
1587 /* Set the new input LED color to GPIOD. */
1588 gpio_data
|= led_color
;
1590 /* Set the modified gpio_data values. */
1591 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1592 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1593 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1597 qla24xx_beacon_on(struct scsi_qla_host
*vha
)
1600 unsigned long flags
;
1601 struct qla_hw_data
*ha
= vha
->hw
;
1602 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1607 if (ha
->beacon_blink_led
== 0) {
1608 /* Enable firmware for update */
1609 ha
->fw_options
[1] |= ADD_FO1_DISABLE_GPIO_LED_CTRL
;
1611 if (qla2x00_set_fw_options(vha
, ha
->fw_options
) != QLA_SUCCESS
)
1612 return QLA_FUNCTION_FAILED
;
1614 if (qla2x00_get_fw_options(vha
, ha
->fw_options
) !=
1616 qla_printk(KERN_WARNING
, ha
,
1617 "Unable to update fw options (beacon on).\n");
1618 return QLA_FUNCTION_FAILED
;
1621 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1622 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1624 /* Enable the gpio_data reg for update. */
1625 gpio_data
|= GPDX_LED_UPDATE_MASK
;
1626 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1627 RD_REG_DWORD(®
->gpiod
);
1629 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1632 /* So all colors blink together. */
1633 ha
->beacon_color_state
= 0;
1635 /* Let the per HBA timer kick off the blinking process. */
1636 ha
->beacon_blink_led
= 1;
1642 qla24xx_beacon_off(struct scsi_qla_host
*vha
)
1645 unsigned long flags
;
1646 struct qla_hw_data
*ha
= vha
->hw
;
1647 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1652 ha
->beacon_blink_led
= 0;
1653 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1655 ha
->isp_ops
->beacon_blink(vha
); /* Will flip to all off. */
1657 /* Give control back to firmware. */
1658 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1659 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1661 /* Disable the gpio_data reg for update. */
1662 gpio_data
&= ~GPDX_LED_UPDATE_MASK
;
1663 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1664 RD_REG_DWORD(®
->gpiod
);
1665 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1667 ha
->fw_options
[1] &= ~ADD_FO1_DISABLE_GPIO_LED_CTRL
;
1669 if (qla2x00_set_fw_options(vha
, ha
->fw_options
) != QLA_SUCCESS
) {
1670 qla_printk(KERN_WARNING
, ha
,
1671 "Unable to update fw options (beacon off).\n");
1672 return QLA_FUNCTION_FAILED
;
1675 if (qla2x00_get_fw_options(vha
, ha
->fw_options
) != QLA_SUCCESS
) {
1676 qla_printk(KERN_WARNING
, ha
,
1677 "Unable to get fw options (beacon off).\n");
1678 return QLA_FUNCTION_FAILED
;
1686 * Flash support routines
1690 * qla2x00_flash_enable() - Setup flash for reading and writing.
1694 qla2x00_flash_enable(struct qla_hw_data
*ha
)
1697 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1699 data
= RD_REG_WORD(®
->ctrl_status
);
1700 data
|= CSR_FLASH_ENABLE
;
1701 WRT_REG_WORD(®
->ctrl_status
, data
);
1702 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1706 * qla2x00_flash_disable() - Disable flash and allow RISC to run.
1710 qla2x00_flash_disable(struct qla_hw_data
*ha
)
1713 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1715 data
= RD_REG_WORD(®
->ctrl_status
);
1716 data
&= ~(CSR_FLASH_ENABLE
);
1717 WRT_REG_WORD(®
->ctrl_status
, data
);
1718 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1722 * qla2x00_read_flash_byte() - Reads a byte from flash
1724 * @addr: Address in flash to read
1726 * A word is read from the chip, but, only the lower byte is valid.
1728 * Returns the byte read from flash @addr.
1731 qla2x00_read_flash_byte(struct qla_hw_data
*ha
, uint32_t addr
)
1734 uint16_t bank_select
;
1735 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1737 bank_select
= RD_REG_WORD(®
->ctrl_status
);
1739 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1740 /* Specify 64K address range: */
1741 /* clear out Module Select and Flash Address bits [19:16]. */
1742 bank_select
&= ~0xf8;
1743 bank_select
|= addr
>> 12 & 0xf0;
1744 bank_select
|= CSR_FLASH_64K_BANK
;
1745 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1746 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1748 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1749 data
= RD_REG_WORD(®
->flash_data
);
1751 return (uint8_t)data
;
1754 /* Setup bit 16 of flash address. */
1755 if ((addr
& BIT_16
) && ((bank_select
& CSR_FLASH_64K_BANK
) == 0)) {
1756 bank_select
|= CSR_FLASH_64K_BANK
;
1757 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1758 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1759 } else if (((addr
& BIT_16
) == 0) &&
1760 (bank_select
& CSR_FLASH_64K_BANK
)) {
1761 bank_select
&= ~(CSR_FLASH_64K_BANK
);
1762 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1763 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1766 /* Always perform IO mapped accesses to the FLASH registers. */
1767 if (ha
->pio_address
) {
1770 WRT_REG_WORD_PIO(PIO_REG(ha
, flash_address
), (uint16_t)addr
);
1772 data
= RD_REG_WORD_PIO(PIO_REG(ha
, flash_data
));
1775 data2
= RD_REG_WORD_PIO(PIO_REG(ha
, flash_data
));
1776 } while (data
!= data2
);
1778 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1779 data
= qla2x00_debounce_register(®
->flash_data
);
1782 return (uint8_t)data
;
1786 * qla2x00_write_flash_byte() - Write a byte to flash
1788 * @addr: Address in flash to write
1789 * @data: Data to write
1792 qla2x00_write_flash_byte(struct qla_hw_data
*ha
, uint32_t addr
, uint8_t data
)
1794 uint16_t bank_select
;
1795 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1797 bank_select
= RD_REG_WORD(®
->ctrl_status
);
1798 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1799 /* Specify 64K address range: */
1800 /* clear out Module Select and Flash Address bits [19:16]. */
1801 bank_select
&= ~0xf8;
1802 bank_select
|= addr
>> 12 & 0xf0;
1803 bank_select
|= CSR_FLASH_64K_BANK
;
1804 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1805 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1807 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1808 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1809 WRT_REG_WORD(®
->flash_data
, (uint16_t)data
);
1810 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1815 /* Setup bit 16 of flash address. */
1816 if ((addr
& BIT_16
) && ((bank_select
& CSR_FLASH_64K_BANK
) == 0)) {
1817 bank_select
|= CSR_FLASH_64K_BANK
;
1818 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1819 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1820 } else if (((addr
& BIT_16
) == 0) &&
1821 (bank_select
& CSR_FLASH_64K_BANK
)) {
1822 bank_select
&= ~(CSR_FLASH_64K_BANK
);
1823 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1824 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1827 /* Always perform IO mapped accesses to the FLASH registers. */
1828 if (ha
->pio_address
) {
1829 WRT_REG_WORD_PIO(PIO_REG(ha
, flash_address
), (uint16_t)addr
);
1830 WRT_REG_WORD_PIO(PIO_REG(ha
, flash_data
), (uint16_t)data
);
1832 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1833 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1834 WRT_REG_WORD(®
->flash_data
, (uint16_t)data
);
1835 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1840 * qla2x00_poll_flash() - Polls flash for completion.
1842 * @addr: Address in flash to poll
1843 * @poll_data: Data to be polled
1844 * @man_id: Flash manufacturer ID
1845 * @flash_id: Flash ID
1847 * This function polls the device until bit 7 of what is read matches data
1848 * bit 7 or until data bit 5 becomes a 1. If that hapens, the flash ROM timed
1849 * out (a fatal error). The flash book recommeds reading bit 7 again after
1850 * reading bit 5 as a 1.
1852 * Returns 0 on success, else non-zero.
1855 qla2x00_poll_flash(struct qla_hw_data
*ha
, uint32_t addr
, uint8_t poll_data
,
1856 uint8_t man_id
, uint8_t flash_id
)
1864 /* Wait for 30 seconds for command to finish. */
1866 for (cnt
= 3000000; cnt
; cnt
--) {
1867 flash_data
= qla2x00_read_flash_byte(ha
, addr
);
1868 if ((flash_data
& BIT_7
) == poll_data
) {
1873 if (man_id
!= 0x40 && man_id
!= 0xda) {
1874 if ((flash_data
& BIT_5
) && cnt
> 2)
1885 * qla2x00_program_flash_address() - Programs a flash address
1887 * @addr: Address in flash to program
1888 * @data: Data to be written in flash
1889 * @man_id: Flash manufacturer ID
1890 * @flash_id: Flash ID
1892 * Returns 0 on success, else non-zero.
1895 qla2x00_program_flash_address(struct qla_hw_data
*ha
, uint32_t addr
,
1896 uint8_t data
, uint8_t man_id
, uint8_t flash_id
)
1898 /* Write Program Command Sequence. */
1899 if (IS_OEM_001(ha
)) {
1900 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1901 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1902 qla2x00_write_flash_byte(ha
, 0xaaa, 0xa0);
1903 qla2x00_write_flash_byte(ha
, addr
, data
);
1905 if (man_id
== 0xda && flash_id
== 0xc1) {
1906 qla2x00_write_flash_byte(ha
, addr
, data
);
1910 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1911 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1912 qla2x00_write_flash_byte(ha
, 0x5555, 0xa0);
1913 qla2x00_write_flash_byte(ha
, addr
, data
);
1919 /* Wait for write to complete. */
1920 return qla2x00_poll_flash(ha
, addr
, data
, man_id
, flash_id
);
1924 * qla2x00_erase_flash() - Erase the flash.
1926 * @man_id: Flash manufacturer ID
1927 * @flash_id: Flash ID
1929 * Returns 0 on success, else non-zero.
1932 qla2x00_erase_flash(struct qla_hw_data
*ha
, uint8_t man_id
, uint8_t flash_id
)
1934 /* Individual Sector Erase Command Sequence */
1935 if (IS_OEM_001(ha
)) {
1936 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1937 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1938 qla2x00_write_flash_byte(ha
, 0xaaa, 0x80);
1939 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1940 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1941 qla2x00_write_flash_byte(ha
, 0xaaa, 0x10);
1943 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1944 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1945 qla2x00_write_flash_byte(ha
, 0x5555, 0x80);
1946 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1947 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1948 qla2x00_write_flash_byte(ha
, 0x5555, 0x10);
1953 /* Wait for erase to complete. */
1954 return qla2x00_poll_flash(ha
, 0x00, 0x80, man_id
, flash_id
);
1958 * qla2x00_erase_flash_sector() - Erase a flash sector.
1960 * @addr: Flash sector to erase
1961 * @sec_mask: Sector address mask
1962 * @man_id: Flash manufacturer ID
1963 * @flash_id: Flash ID
1965 * Returns 0 on success, else non-zero.
1968 qla2x00_erase_flash_sector(struct qla_hw_data
*ha
, uint32_t addr
,
1969 uint32_t sec_mask
, uint8_t man_id
, uint8_t flash_id
)
1971 /* Individual Sector Erase Command Sequence */
1972 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1973 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1974 qla2x00_write_flash_byte(ha
, 0x5555, 0x80);
1975 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1976 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1977 if (man_id
== 0x1f && flash_id
== 0x13)
1978 qla2x00_write_flash_byte(ha
, addr
& sec_mask
, 0x10);
1980 qla2x00_write_flash_byte(ha
, addr
& sec_mask
, 0x30);
1984 /* Wait for erase to complete. */
1985 return qla2x00_poll_flash(ha
, addr
, 0x80, man_id
, flash_id
);
1989 * qla2x00_get_flash_manufacturer() - Read manufacturer ID from flash chip.
1990 * @man_id: Flash manufacturer ID
1991 * @flash_id: Flash ID
1994 qla2x00_get_flash_manufacturer(struct qla_hw_data
*ha
, uint8_t *man_id
,
1997 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1998 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1999 qla2x00_write_flash_byte(ha
, 0x5555, 0x90);
2000 *man_id
= qla2x00_read_flash_byte(ha
, 0x0000);
2001 *flash_id
= qla2x00_read_flash_byte(ha
, 0x0001);
2002 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
2003 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
2004 qla2x00_write_flash_byte(ha
, 0x5555, 0xf0);
2008 qla2x00_read_flash_data(struct qla_hw_data
*ha
, uint8_t *tmp_buf
,
2009 uint32_t saddr
, uint32_t length
)
2011 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2012 uint32_t midpoint
, ilength
;
2015 midpoint
= length
/ 2;
2017 WRT_REG_WORD(®
->nvram
, 0);
2018 RD_REG_WORD(®
->nvram
);
2019 for (ilength
= 0; ilength
< length
; saddr
++, ilength
++, tmp_buf
++) {
2020 if (ilength
== midpoint
) {
2021 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
2022 RD_REG_WORD(®
->nvram
);
2024 data
= qla2x00_read_flash_byte(ha
, saddr
);
2033 qla2x00_suspend_hba(struct scsi_qla_host
*vha
)
2036 unsigned long flags
;
2037 struct qla_hw_data
*ha
= vha
->hw
;
2038 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2041 scsi_block_requests(vha
->host
);
2042 ha
->isp_ops
->disable_intrs(ha
);
2043 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
2046 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2047 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
2048 RD_REG_WORD(®
->hccr
);
2049 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2050 for (cnt
= 0; cnt
< 30000; cnt
++) {
2051 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
2058 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2062 qla2x00_resume_hba(struct scsi_qla_host
*vha
)
2064 struct qla_hw_data
*ha
= vha
->hw
;
2067 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
2068 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2069 qla2xxx_wake_dpc(vha
);
2070 qla2x00_wait_for_chip_reset(vha
);
2071 scsi_unblock_requests(vha
->host
);
2075 qla2x00_read_optrom_data(struct scsi_qla_host
*vha
, uint8_t *buf
,
2076 uint32_t offset
, uint32_t length
)
2078 uint32_t addr
, midpoint
;
2080 struct qla_hw_data
*ha
= vha
->hw
;
2081 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2084 qla2x00_suspend_hba(vha
);
2087 midpoint
= ha
->optrom_size
/ 2;
2089 qla2x00_flash_enable(ha
);
2090 WRT_REG_WORD(®
->nvram
, 0);
2091 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
2092 for (addr
= offset
, data
= buf
; addr
< length
; addr
++, data
++) {
2093 if (addr
== midpoint
) {
2094 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
2095 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
2098 *data
= qla2x00_read_flash_byte(ha
, addr
);
2100 qla2x00_flash_disable(ha
);
2103 qla2x00_resume_hba(vha
);
2109 qla2x00_write_optrom_data(struct scsi_qla_host
*vha
, uint8_t *buf
,
2110 uint32_t offset
, uint32_t length
)
2114 uint8_t man_id
, flash_id
, sec_number
, data
;
2116 uint32_t addr
, liter
, sec_mask
, rest_addr
;
2117 struct qla_hw_data
*ha
= vha
->hw
;
2118 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2121 qla2x00_suspend_hba(vha
);
2126 /* Reset ISP chip. */
2127 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2128 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
2130 /* Go with write. */
2131 qla2x00_flash_enable(ha
);
2132 do { /* Loop once to provide quick error exit */
2133 /* Structure of flash memory based on manufacturer */
2134 if (IS_OEM_001(ha
)) {
2135 /* OEM variant with special flash part. */
2136 man_id
= flash_id
= 0;
2141 qla2x00_get_flash_manufacturer(ha
, &man_id
, &flash_id
);
2143 case 0x20: /* ST flash. */
2144 if (flash_id
== 0xd2 || flash_id
== 0xe3) {
2146 * ST m29w008at part - 64kb sector size with
2147 * 32kb,8kb,8kb,16kb sectors at memory address
2155 * ST m29w010b part - 16kb sector size
2156 * Default to 16kb sectors
2161 case 0x40: /* Mostel flash. */
2162 /* Mostel v29c51001 part - 512 byte sector size. */
2166 case 0xbf: /* SST flash. */
2167 /* SST39sf10 part - 4kb sector size. */
2171 case 0xda: /* Winbond flash. */
2172 /* Winbond W29EE011 part - 256 byte sector size. */
2176 case 0xc2: /* Macronix flash. */
2177 /* 64k sector size. */
2178 if (flash_id
== 0x38 || flash_id
== 0x4f) {
2183 /* Fall through... */
2185 case 0x1f: /* Atmel flash. */
2186 /* 512k sector size. */
2187 if (flash_id
== 0x13) {
2188 rest_addr
= 0x7fffffff;
2189 sec_mask
= 0x80000000;
2192 /* Fall through... */
2194 case 0x01: /* AMD flash. */
2195 if (flash_id
== 0x38 || flash_id
== 0x40 ||
2197 /* Am29LV081 part - 64kb sector size. */
2198 /* Am29LV002BT part - 64kb sector size. */
2202 } else if (flash_id
== 0x3e) {
2204 * Am29LV008b part - 64kb sector size with
2205 * 32kb,8kb,8kb,16kb sector at memory address
2211 } else if (flash_id
== 0x20 || flash_id
== 0x6e) {
2213 * Am29LV010 part or AM29f010 - 16kb sector
2219 } else if (flash_id
== 0x6d) {
2220 /* Am29LV001 part - 8kb sector size. */
2226 /* Default to 16 kb sector size. */
2233 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
2234 if (qla2x00_erase_flash(ha
, man_id
, flash_id
)) {
2235 rval
= QLA_FUNCTION_FAILED
;
2240 for (addr
= offset
, liter
= 0; liter
< length
; liter
++,
2243 /* Are we at the beginning of a sector? */
2244 if ((addr
& rest_addr
) == 0) {
2245 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
2246 if (addr
>= 0x10000UL
) {
2247 if (((addr
>> 12) & 0xf0) &&
2249 flash_id
== 0x3e) ||
2251 flash_id
== 0xd2))) {
2253 if (sec_number
== 1) {
2274 } else if (addr
== ha
->optrom_size
/ 2) {
2275 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
2276 RD_REG_WORD(®
->nvram
);
2279 if (flash_id
== 0xda && man_id
== 0xc1) {
2280 qla2x00_write_flash_byte(ha
, 0x5555,
2282 qla2x00_write_flash_byte(ha
, 0x2aaa,
2284 qla2x00_write_flash_byte(ha
, 0x5555,
2286 } else if (!IS_QLA2322(ha
) && !IS_QLA6322(ha
)) {
2288 if (qla2x00_erase_flash_sector(ha
,
2289 addr
, sec_mask
, man_id
,
2291 rval
= QLA_FUNCTION_FAILED
;
2294 if (man_id
== 0x01 && flash_id
== 0x6d)
2299 if (man_id
== 0x01 && flash_id
== 0x6d) {
2300 if (sec_number
== 1 &&
2301 addr
== (rest_addr
- 1)) {
2304 } else if (sec_number
== 3 && (addr
& 0x7ffe)) {
2310 if (qla2x00_program_flash_address(ha
, addr
, data
,
2311 man_id
, flash_id
)) {
2312 rval
= QLA_FUNCTION_FAILED
;
2318 qla2x00_flash_disable(ha
);
2321 qla2x00_resume_hba(vha
);
2327 qla24xx_read_optrom_data(struct scsi_qla_host
*vha
, uint8_t *buf
,
2328 uint32_t offset
, uint32_t length
)
2330 struct qla_hw_data
*ha
= vha
->hw
;
2333 scsi_block_requests(vha
->host
);
2334 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
2337 qla24xx_read_flash_data(vha
, (uint32_t *)buf
, offset
>> 2, length
>> 2);
2340 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
2341 scsi_unblock_requests(vha
->host
);
2347 qla24xx_write_optrom_data(struct scsi_qla_host
*vha
, uint8_t *buf
,
2348 uint32_t offset
, uint32_t length
)
2351 struct qla_hw_data
*ha
= vha
->hw
;
2354 scsi_block_requests(vha
->host
);
2355 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
2357 /* Go with write. */
2358 rval
= qla24xx_write_flash_data(vha
, (uint32_t *)buf
, offset
>> 2,
2361 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
2362 scsi_unblock_requests(vha
->host
);
2368 qla25xx_read_optrom_data(struct scsi_qla_host
*vha
, uint8_t *buf
,
2369 uint32_t offset
, uint32_t length
)
2372 dma_addr_t optrom_dma
;
2375 uint32_t faddr
, left
, burst
;
2376 struct qla_hw_data
*ha
= vha
->hw
;
2378 if (IS_QLA25XX(ha
) || IS_QLA81XX(ha
))
2382 if (length
< OPTROM_BURST_SIZE
)
2386 optrom
= dma_alloc_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
,
2387 &optrom_dma
, GFP_KERNEL
);
2389 qla_printk(KERN_DEBUG
, ha
,
2390 "Unable to allocate memory for optrom burst read "
2391 "(%x KB).\n", OPTROM_BURST_SIZE
/ 1024);
2397 faddr
= offset
>> 2;
2399 burst
= OPTROM_BURST_DWORDS
;
2404 rval
= qla2x00_dump_ram(vha
, optrom_dma
,
2405 flash_data_addr(ha
, faddr
), burst
);
2407 qla_printk(KERN_WARNING
, ha
,
2408 "Unable to burst-read optrom segment "
2409 "(%x/%x/%llx).\n", rval
,
2410 flash_data_addr(ha
, faddr
),
2411 (unsigned long long)optrom_dma
);
2412 qla_printk(KERN_WARNING
, ha
,
2413 "Reverting to slow-read.\n");
2415 dma_free_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
,
2416 optrom
, optrom_dma
);
2420 memcpy(pbuf
, optrom
, burst
* 4);
2427 dma_free_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
, optrom
,
2433 return qla24xx_read_optrom_data(vha
, buf
, offset
, length
);
2437 * qla2x00_get_fcode_version() - Determine an FCODE image's version.
2439 * @pcids: Pointer to the FCODE PCI data structure
2441 * The process of retrieving the FCODE version information is at best
2442 * described as interesting.
2444 * Within the first 100h bytes of the image an ASCII string is present
2445 * which contains several pieces of information including the FCODE
2446 * version. Unfortunately it seems the only reliable way to retrieve
2447 * the version is by scanning for another sentinel within the string,
2448 * the FCODE build date:
2450 * ... 2.00.02 10/17/02 ...
2452 * Returns QLA_SUCCESS on successful retrieval of version.
2455 qla2x00_get_fcode_version(struct qla_hw_data
*ha
, uint32_t pcids
)
2457 int ret
= QLA_FUNCTION_FAILED
;
2458 uint32_t istart
, iend
, iter
, vend
;
2459 uint8_t do_next
, rbyte
, *vbyte
;
2461 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2463 /* Skip the PCI data structure. */
2465 ((qla2x00_read_flash_byte(ha
, pcids
+ 0x0B) << 8) |
2466 qla2x00_read_flash_byte(ha
, pcids
+ 0x0A));
2467 iend
= istart
+ 0x100;
2469 /* Scan for the sentinel date string...eeewww. */
2472 while ((iter
< iend
) && !do_next
) {
2474 if (qla2x00_read_flash_byte(ha
, iter
) == '/') {
2475 if (qla2x00_read_flash_byte(ha
, iter
+ 2) ==
2478 else if (qla2x00_read_flash_byte(ha
,
2486 /* Backtrack to previous ' ' (space). */
2488 while ((iter
> istart
) && !do_next
) {
2490 if (qla2x00_read_flash_byte(ha
, iter
) == ' ')
2497 * Mark end of version tag, and find previous ' ' (space) or
2498 * string length (recent FCODE images -- major hack ahead!!!).
2502 while ((iter
> istart
) && !do_next
) {
2504 rbyte
= qla2x00_read_flash_byte(ha
, iter
);
2505 if (rbyte
== ' ' || rbyte
== 0xd || rbyte
== 0x10)
2511 /* Mark beginning of version tag, and copy data. */
2513 if ((vend
- iter
) &&
2514 ((vend
- iter
) < sizeof(ha
->fcode_revision
))) {
2515 vbyte
= ha
->fcode_revision
;
2516 while (iter
<= vend
) {
2517 *vbyte
++ = qla2x00_read_flash_byte(ha
, iter
);
2524 if (ret
!= QLA_SUCCESS
)
2525 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2529 qla2x00_get_flash_version(scsi_qla_host_t
*vha
, void *mbuf
)
2531 int ret
= QLA_SUCCESS
;
2532 uint8_t code_type
, last_image
;
2533 uint32_t pcihdr
, pcids
;
2536 struct qla_hw_data
*ha
= vha
->hw
;
2538 if (!ha
->pio_address
|| !mbuf
)
2539 return QLA_FUNCTION_FAILED
;
2541 memset(ha
->bios_revision
, 0, sizeof(ha
->bios_revision
));
2542 memset(ha
->efi_revision
, 0, sizeof(ha
->efi_revision
));
2543 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2544 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2546 qla2x00_flash_enable(ha
);
2548 /* Begin with first PCI expansion ROM header. */
2552 /* Verify PCI expansion ROM header. */
2553 if (qla2x00_read_flash_byte(ha
, pcihdr
) != 0x55 ||
2554 qla2x00_read_flash_byte(ha
, pcihdr
+ 0x01) != 0xaa) {
2556 DEBUG2(qla_printk(KERN_DEBUG
, ha
, "No matching ROM "
2558 ret
= QLA_FUNCTION_FAILED
;
2562 /* Locate PCI data structure. */
2564 ((qla2x00_read_flash_byte(ha
, pcihdr
+ 0x19) << 8) |
2565 qla2x00_read_flash_byte(ha
, pcihdr
+ 0x18));
2567 /* Validate signature of PCI data structure. */
2568 if (qla2x00_read_flash_byte(ha
, pcids
) != 'P' ||
2569 qla2x00_read_flash_byte(ha
, pcids
+ 0x1) != 'C' ||
2570 qla2x00_read_flash_byte(ha
, pcids
+ 0x2) != 'I' ||
2571 qla2x00_read_flash_byte(ha
, pcids
+ 0x3) != 'R') {
2572 /* Incorrect header. */
2573 DEBUG2(qla_printk(KERN_INFO
, ha
, "PCI data struct not "
2574 "found pcir_adr=%x.\n", pcids
));
2575 ret
= QLA_FUNCTION_FAILED
;
2580 code_type
= qla2x00_read_flash_byte(ha
, pcids
+ 0x14);
2581 switch (code_type
) {
2582 case ROM_CODE_TYPE_BIOS
:
2583 /* Intel x86, PC-AT compatible. */
2584 ha
->bios_revision
[0] =
2585 qla2x00_read_flash_byte(ha
, pcids
+ 0x12);
2586 ha
->bios_revision
[1] =
2587 qla2x00_read_flash_byte(ha
, pcids
+ 0x13);
2588 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "read BIOS %d.%d.\n",
2589 ha
->bios_revision
[1], ha
->bios_revision
[0]));
2591 case ROM_CODE_TYPE_FCODE
:
2592 /* Open Firmware standard for PCI (FCode). */
2594 qla2x00_get_fcode_version(ha
, pcids
);
2596 case ROM_CODE_TYPE_EFI
:
2597 /* Extensible Firmware Interface (EFI). */
2598 ha
->efi_revision
[0] =
2599 qla2x00_read_flash_byte(ha
, pcids
+ 0x12);
2600 ha
->efi_revision
[1] =
2601 qla2x00_read_flash_byte(ha
, pcids
+ 0x13);
2602 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "read EFI %d.%d.\n",
2603 ha
->efi_revision
[1], ha
->efi_revision
[0]));
2606 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unrecognized code "
2607 "type %x at pcids %x.\n", code_type
, pcids
));
2611 last_image
= qla2x00_read_flash_byte(ha
, pcids
+ 0x15) & BIT_7
;
2613 /* Locate next PCI expansion ROM. */
2614 pcihdr
+= ((qla2x00_read_flash_byte(ha
, pcids
+ 0x11) << 8) |
2615 qla2x00_read_flash_byte(ha
, pcids
+ 0x10)) * 512;
2616 } while (!last_image
);
2618 if (IS_QLA2322(ha
)) {
2619 /* Read firmware image information. */
2620 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2622 memset(dbyte
, 0, 8);
2623 dcode
= (uint16_t *)dbyte
;
2625 qla2x00_read_flash_data(ha
, dbyte
, ha
->flt_region_fw
* 4 + 10,
2627 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "dumping fw ver from "
2629 DEBUG3(qla2x00_dump_buffer((uint8_t *)dbyte
, 8));
2631 if ((dcode
[0] == 0xffff && dcode
[1] == 0xffff &&
2632 dcode
[2] == 0xffff && dcode
[3] == 0xffff) ||
2633 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
2635 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unrecognized fw "
2636 "revision at %x.\n", ha
->flt_region_fw
* 4));
2638 /* values are in big endian */
2639 ha
->fw_revision
[0] = dbyte
[0] << 16 | dbyte
[1];
2640 ha
->fw_revision
[1] = dbyte
[2] << 16 | dbyte
[3];
2641 ha
->fw_revision
[2] = dbyte
[4] << 16 | dbyte
[5];
2645 qla2x00_flash_disable(ha
);
2651 qla24xx_get_flash_version(scsi_qla_host_t
*vha
, void *mbuf
)
2653 int ret
= QLA_SUCCESS
;
2654 uint32_t pcihdr
, pcids
;
2657 uint8_t code_type
, last_image
;
2659 struct qla_hw_data
*ha
= vha
->hw
;
2665 return QLA_FUNCTION_FAILED
;
2667 memset(ha
->bios_revision
, 0, sizeof(ha
->bios_revision
));
2668 memset(ha
->efi_revision
, 0, sizeof(ha
->efi_revision
));
2669 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2670 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2674 /* Begin with first PCI expansion ROM header. */
2675 pcihdr
= ha
->flt_region_boot
<< 2;
2678 /* Verify PCI expansion ROM header. */
2679 qla24xx_read_flash_data(vha
, dcode
, pcihdr
>> 2, 0x20);
2680 bcode
= mbuf
+ (pcihdr
% 4);
2681 if (bcode
[0x0] != 0x55 || bcode
[0x1] != 0xaa) {
2683 DEBUG2(qla_printk(KERN_DEBUG
, ha
, "No matching ROM "
2685 ret
= QLA_FUNCTION_FAILED
;
2689 /* Locate PCI data structure. */
2690 pcids
= pcihdr
+ ((bcode
[0x19] << 8) | bcode
[0x18]);
2692 qla24xx_read_flash_data(vha
, dcode
, pcids
>> 2, 0x20);
2693 bcode
= mbuf
+ (pcihdr
% 4);
2695 /* Validate signature of PCI data structure. */
2696 if (bcode
[0x0] != 'P' || bcode
[0x1] != 'C' ||
2697 bcode
[0x2] != 'I' || bcode
[0x3] != 'R') {
2698 /* Incorrect header. */
2699 DEBUG2(qla_printk(KERN_INFO
, ha
, "PCI data struct not "
2700 "found pcir_adr=%x.\n", pcids
));
2701 ret
= QLA_FUNCTION_FAILED
;
2706 code_type
= bcode
[0x14];
2707 switch (code_type
) {
2708 case ROM_CODE_TYPE_BIOS
:
2709 /* Intel x86, PC-AT compatible. */
2710 ha
->bios_revision
[0] = bcode
[0x12];
2711 ha
->bios_revision
[1] = bcode
[0x13];
2712 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "read BIOS %d.%d.\n",
2713 ha
->bios_revision
[1], ha
->bios_revision
[0]));
2715 case ROM_CODE_TYPE_FCODE
:
2716 /* Open Firmware standard for PCI (FCode). */
2717 ha
->fcode_revision
[0] = bcode
[0x12];
2718 ha
->fcode_revision
[1] = bcode
[0x13];
2719 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "read FCODE %d.%d.\n",
2720 ha
->fcode_revision
[1], ha
->fcode_revision
[0]));
2722 case ROM_CODE_TYPE_EFI
:
2723 /* Extensible Firmware Interface (EFI). */
2724 ha
->efi_revision
[0] = bcode
[0x12];
2725 ha
->efi_revision
[1] = bcode
[0x13];
2726 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "read EFI %d.%d.\n",
2727 ha
->efi_revision
[1], ha
->efi_revision
[0]));
2730 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unrecognized code "
2731 "type %x at pcids %x.\n", code_type
, pcids
));
2735 last_image
= bcode
[0x15] & BIT_7
;
2737 /* Locate next PCI expansion ROM. */
2738 pcihdr
+= ((bcode
[0x11] << 8) | bcode
[0x10]) * 512;
2739 } while (!last_image
);
2741 /* Read firmware image information. */
2742 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2745 qla24xx_read_flash_data(vha
, dcode
, ha
->flt_region_fw
+ 4, 4);
2746 for (i
= 0; i
< 4; i
++)
2747 dcode
[i
] = be32_to_cpu(dcode
[i
]);
2749 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
2750 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
2751 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
2753 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unrecognized fw "
2754 "revision at %x.\n", ha
->flt_region_fw
* 4));
2756 ha
->fw_revision
[0] = dcode
[0];
2757 ha
->fw_revision
[1] = dcode
[1];
2758 ha
->fw_revision
[2] = dcode
[2];
2759 ha
->fw_revision
[3] = dcode
[3];
2762 /* Check for golden firmware and get version if available */
2763 if (!IS_QLA81XX(ha
)) {
2764 /* Golden firmware is not present in non 81XX adapters */
2768 memset(ha
->gold_fw_version
, 0, sizeof(ha
->gold_fw_version
));
2770 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)dcode
,
2771 ha
->flt_region_gold_fw
<< 2, 32);
2773 if (dcode
[4] == 0xFFFFFFFF && dcode
[5] == 0xFFFFFFFF &&
2774 dcode
[6] == 0xFFFFFFFF && dcode
[7] == 0xFFFFFFFF) {
2775 DEBUG2(qla_printk(KERN_INFO
, ha
,
2776 "%s(%ld): Unrecognized golden fw at 0x%x.\n",
2777 __func__
, vha
->host_no
, ha
->flt_region_gold_fw
* 4));
2781 for (i
= 4; i
< 8; i
++)
2782 ha
->gold_fw_version
[i
-4] = be32_to_cpu(dcode
[i
]);
2788 qla2xxx_is_vpd_valid(uint8_t *pos
, uint8_t *end
)
2790 if (pos
>= end
|| *pos
!= 0x82)
2794 if (pos
>= end
|| *pos
!= 0x90)
2798 if (pos
>= end
|| *pos
!= 0x78)
2805 qla2xxx_get_vpd_field(scsi_qla_host_t
*vha
, char *key
, char *str
, size_t size
)
2807 struct qla_hw_data
*ha
= vha
->hw
;
2808 uint8_t *pos
= ha
->vpd
;
2809 uint8_t *end
= pos
+ ha
->vpd_size
;
2812 if (!IS_FWI2_CAPABLE(ha
) || !qla2xxx_is_vpd_valid(pos
, end
))
2815 while (pos
< end
&& *pos
!= 0x78) {
2816 len
= (*pos
== 0x82) ? pos
[1] : pos
[2];
2818 if (!strncmp(pos
, key
, strlen(key
)))
2821 if (*pos
!= 0x90 && *pos
!= 0x91)
2827 if (pos
< end
- len
&& *pos
!= 0x78)
2828 return snprintf(str
, size
, "%.*s", len
, pos
+ 3);
2834 qla24xx_read_fcp_prio_cfg(scsi_qla_host_t
*vha
)
2837 uint32_t fcp_prio_addr
;
2838 struct qla_hw_data
*ha
= vha
->hw
;
2840 if (!ha
->fcp_prio_cfg
) {
2841 ha
->fcp_prio_cfg
= vmalloc(FCP_PRIO_CFG_SIZE
);
2842 if (!ha
->fcp_prio_cfg
) {
2843 qla_printk(KERN_WARNING
, ha
,
2844 "Unable to allocate memory for fcp priority data "
2845 "(%x).\n", FCP_PRIO_CFG_SIZE
);
2846 return QLA_FUNCTION_FAILED
;
2849 memset(ha
->fcp_prio_cfg
, 0, FCP_PRIO_CFG_SIZE
);
2851 fcp_prio_addr
= ha
->flt_region_fcp_prio
;
2853 /* first read the fcp priority data header from flash */
2854 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)ha
->fcp_prio_cfg
,
2855 fcp_prio_addr
<< 2, FCP_PRIO_CFG_HDR_SIZE
);
2857 if (!qla24xx_fcp_prio_cfg_valid(ha
->fcp_prio_cfg
, 0))
2860 /* read remaining FCP CMD config data from flash */
2861 fcp_prio_addr
+= (FCP_PRIO_CFG_HDR_SIZE
>> 2);
2862 len
= ha
->fcp_prio_cfg
->num_entries
* FCP_PRIO_CFG_ENTRY_SIZE
;
2863 max_len
= FCP_PRIO_CFG_SIZE
- FCP_PRIO_CFG_HDR_SIZE
;
2865 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)&ha
->fcp_prio_cfg
->entry
[0],
2866 fcp_prio_addr
<< 2, (len
< max_len
? len
: max_len
));
2868 /* revalidate the entire FCP priority config data, including entries */
2869 if (!qla24xx_fcp_prio_cfg_valid(ha
->fcp_prio_cfg
, 1))
2872 ha
->flags
.fcp_prio_enabled
= 1;
2875 vfree(ha
->fcp_prio_cfg
);
2876 ha
->fcp_prio_cfg
= NULL
;
2877 return QLA_FUNCTION_FAILED
;