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
))
673 /* Assign FCP prio region since older adapters may not have FLT, or
674 FCP prio region in it's FLT.
676 ha
->flt_region_fcp_prio
= ha
->flags
.port0
?
677 fcp_prio_cfg0
[def
] : fcp_prio_cfg1
[def
];
679 ha
->flt_region_flt
= flt_addr
;
680 wptr
= (uint16_t *)req
->ring
;
681 flt
= (struct qla_flt_header
*)req
->ring
;
682 region
= (struct qla_flt_region
*)&flt
[1];
683 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)req
->ring
,
684 flt_addr
<< 2, OPTROM_BURST_SIZE
);
685 if (*wptr
== __constant_cpu_to_le16(0xffff))
687 if (flt
->version
!= __constant_cpu_to_le16(1)) {
688 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unsupported FLT detected: "
689 "version=0x%x length=0x%x checksum=0x%x.\n",
690 le16_to_cpu(flt
->version
), le16_to_cpu(flt
->length
),
691 le16_to_cpu(flt
->checksum
)));
695 cnt
= (sizeof(struct qla_flt_header
) + le16_to_cpu(flt
->length
)) >> 1;
696 for (chksum
= 0; cnt
; cnt
--)
697 chksum
+= le16_to_cpu(*wptr
++);
699 DEBUG2(qla_printk(KERN_INFO
, ha
, "Inconsistent FLT detected: "
700 "version=0x%x length=0x%x checksum=0x%x.\n",
701 le16_to_cpu(flt
->version
), le16_to_cpu(flt
->length
),
707 cnt
= le16_to_cpu(flt
->length
) / sizeof(struct qla_flt_region
);
708 for ( ; cnt
; cnt
--, region
++) {
709 /* Store addresses as DWORD offsets. */
710 start
= le32_to_cpu(region
->start
) >> 2;
712 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "FLT[%02x]: start=0x%x "
713 "end=0x%x size=0x%x.\n", le32_to_cpu(region
->code
), start
,
714 le32_to_cpu(region
->end
) >> 2, le32_to_cpu(region
->size
)));
716 switch (le32_to_cpu(region
->code
) & 0xff) {
718 ha
->flt_region_fw
= start
;
720 case FLT_REG_BOOT_CODE
:
721 ha
->flt_region_boot
= start
;
724 ha
->flt_region_vpd_nvram
= start
;
728 ha
->flt_region_vpd
= start
;
733 if (!ha
->flags
.port0
)
734 ha
->flt_region_vpd
= start
;
736 case FLT_REG_NVRAM_0
:
738 ha
->flt_region_nvram
= start
;
740 case FLT_REG_NVRAM_1
:
741 if (!ha
->flags
.port0
)
742 ha
->flt_region_nvram
= start
;
745 ha
->flt_region_fdt
= start
;
747 case FLT_REG_NPIV_CONF_0
:
749 ha
->flt_region_npiv_conf
= start
;
751 case FLT_REG_NPIV_CONF_1
:
752 if (!ha
->flags
.port0
)
753 ha
->flt_region_npiv_conf
= start
;
755 case FLT_REG_GOLD_FW
:
756 ha
->flt_region_gold_fw
= start
;
758 case FLT_REG_FCP_PRIO_0
:
760 ha
->flt_region_fcp_prio
= start
;
762 case FLT_REG_FCP_PRIO_1
:
763 if (!ha
->flags
.port0
)
764 ha
->flt_region_fcp_prio
= start
;
766 case FLT_REG_BOOT_CODE_82XX
:
767 ha
->flt_region_boot
= start
;
769 case FLT_REG_FW_82XX
:
770 ha
->flt_region_fw
= start
;
772 case FLT_REG_GOLD_FW_82XX
:
773 ha
->flt_region_gold_fw
= start
;
775 case FLT_REG_BOOTLOAD_82XX
:
776 ha
->flt_region_bootload
= start
;
778 case FLT_REG_VPD_82XX
:
779 ha
->flt_region_vpd
= start
;
786 /* Use hardcoded defaults. */
788 ha
->flt_region_fw
= def_fw
[def
];
789 ha
->flt_region_boot
= def_boot
[def
];
790 ha
->flt_region_vpd_nvram
= def_vpd_nvram
[def
];
791 ha
->flt_region_vpd
= ha
->flags
.port0
?
792 def_vpd0
[def
] : def_vpd1
[def
];
793 ha
->flt_region_nvram
= ha
->flags
.port0
?
794 def_nvram0
[def
] : def_nvram1
[def
];
795 ha
->flt_region_fdt
= def_fdt
[def
];
796 ha
->flt_region_npiv_conf
= ha
->flags
.port0
?
797 def_npiv_conf0
[def
] : def_npiv_conf1
[def
];
799 DEBUG2(qla_printk(KERN_DEBUG
, ha
, "FLT[%s]: boot=0x%x fw=0x%x "
800 "vpd_nvram=0x%x vpd=0x%x nvram=0x%x fdt=0x%x flt=0x%x "
801 "npiv=0x%x. fcp_prio_cfg=0x%x\n", loc
, ha
->flt_region_boot
,
802 ha
->flt_region_fw
, ha
->flt_region_vpd_nvram
, ha
->flt_region_vpd
,
803 ha
->flt_region_nvram
, ha
->flt_region_fdt
, ha
->flt_region_flt
,
804 ha
->flt_region_npiv_conf
, ha
->flt_region_fcp_prio
));
808 qla2xxx_get_fdt_info(scsi_qla_host_t
*vha
)
810 #define FLASH_BLK_SIZE_4K 0x1000
811 #define FLASH_BLK_SIZE_32K 0x8000
812 #define FLASH_BLK_SIZE_64K 0x10000
813 const char *loc
, *locations
[] = { "MID", "FDT" };
814 uint16_t cnt
, chksum
;
816 struct qla_fdt_layout
*fdt
;
817 uint8_t man_id
, flash_id
;
818 uint16_t mid
= 0, fid
= 0;
819 struct qla_hw_data
*ha
= vha
->hw
;
820 struct req_que
*req
= ha
->req_q_map
[0];
822 wptr
= (uint16_t *)req
->ring
;
823 fdt
= (struct qla_fdt_layout
*)req
->ring
;
824 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)req
->ring
,
825 ha
->flt_region_fdt
<< 2, OPTROM_BURST_SIZE
);
826 if (*wptr
== __constant_cpu_to_le16(0xffff))
828 if (fdt
->sig
[0] != 'Q' || fdt
->sig
[1] != 'L' || fdt
->sig
[2] != 'I' ||
832 for (cnt
= 0, chksum
= 0; cnt
< sizeof(struct qla_fdt_layout
) >> 1;
834 chksum
+= le16_to_cpu(*wptr
++);
836 DEBUG2(qla_printk(KERN_INFO
, ha
, "Inconsistent FDT detected: "
837 "checksum=0x%x id=%c version=0x%x.\n", chksum
, fdt
->sig
[0],
838 le16_to_cpu(fdt
->version
)));
839 DEBUG9(qla2x00_dump_buffer((uint8_t *)fdt
, sizeof(*fdt
)));
844 mid
= le16_to_cpu(fdt
->man_id
);
845 fid
= le16_to_cpu(fdt
->id
);
846 ha
->fdt_wrt_disable
= fdt
->wrt_disable_bits
;
847 ha
->fdt_erase_cmd
= flash_conf_addr(ha
, 0x0300 | fdt
->erase_cmd
);
848 ha
->fdt_block_size
= le32_to_cpu(fdt
->block_size
);
849 if (fdt
->unprotect_sec_cmd
) {
850 ha
->fdt_unprotect_sec_cmd
= flash_conf_addr(ha
, 0x0300 |
851 fdt
->unprotect_sec_cmd
);
852 ha
->fdt_protect_sec_cmd
= fdt
->protect_sec_cmd
?
853 flash_conf_addr(ha
, 0x0300 | fdt
->protect_sec_cmd
):
854 flash_conf_addr(ha
, 0x0336);
859 if (IS_QLA82XX(ha
)) {
860 ha
->fdt_block_size
= FLASH_BLK_SIZE_64K
;
863 qla24xx_get_flash_manufacturer(ha
, &man_id
, &flash_id
);
866 ha
->fdt_wrt_disable
= 0x9c;
867 ha
->fdt_erase_cmd
= flash_conf_addr(ha
, 0x03d8);
869 case 0xbf: /* STT flash. */
870 if (flash_id
== 0x8e)
871 ha
->fdt_block_size
= FLASH_BLK_SIZE_64K
;
873 ha
->fdt_block_size
= FLASH_BLK_SIZE_32K
;
875 if (flash_id
== 0x80)
876 ha
->fdt_erase_cmd
= flash_conf_addr(ha
, 0x0352);
878 case 0x13: /* ST M25P80. */
879 ha
->fdt_block_size
= FLASH_BLK_SIZE_64K
;
881 case 0x1f: /* Atmel 26DF081A. */
882 ha
->fdt_block_size
= FLASH_BLK_SIZE_4K
;
883 ha
->fdt_erase_cmd
= flash_conf_addr(ha
, 0x0320);
884 ha
->fdt_unprotect_sec_cmd
= flash_conf_addr(ha
, 0x0339);
885 ha
->fdt_protect_sec_cmd
= flash_conf_addr(ha
, 0x0336);
888 /* Default to 64 kb sector size. */
889 ha
->fdt_block_size
= FLASH_BLK_SIZE_64K
;
893 DEBUG2(qla_printk(KERN_DEBUG
, ha
, "FDT[%s]: (0x%x/0x%x) erase=0x%x "
894 "pro=%x upro=%x wrtd=0x%x blk=0x%x.\n", loc
, mid
, fid
,
895 ha
->fdt_erase_cmd
, ha
->fdt_protect_sec_cmd
,
896 ha
->fdt_unprotect_sec_cmd
, ha
->fdt_wrt_disable
,
897 ha
->fdt_block_size
));
901 qla2xxx_get_idc_param(scsi_qla_host_t
*vha
)
903 #define QLA82XX_IDC_PARAM_ADDR 0x003e885c
905 struct qla_hw_data
*ha
= vha
->hw
;
906 struct req_que
*req
= ha
->req_q_map
[0];
911 wptr
= (uint32_t *)req
->ring
;
912 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)req
->ring
,
913 QLA82XX_IDC_PARAM_ADDR
, 8);
915 if (*wptr
== __constant_cpu_to_le32(0xffffffff)) {
916 ha
->nx_dev_init_timeout
= QLA82XX_ROM_DEV_INIT_TIMEOUT
;
917 ha
->nx_reset_timeout
= QLA82XX_ROM_DRV_RESET_ACK_TIMEOUT
;
919 ha
->nx_dev_init_timeout
= le32_to_cpu(*wptr
++);
920 ha
->nx_reset_timeout
= le32_to_cpu(*wptr
);
926 qla2xxx_get_flash_info(scsi_qla_host_t
*vha
)
930 struct qla_hw_data
*ha
= vha
->hw
;
932 if (!IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) && !IS_QLA8XXX_TYPE(ha
))
935 ret
= qla2xxx_find_flt_start(vha
, &flt_addr
);
936 if (ret
!= QLA_SUCCESS
)
939 qla2xxx_get_flt_info(vha
, flt_addr
);
940 qla2xxx_get_fdt_info(vha
);
941 qla2xxx_get_idc_param(vha
);
947 qla2xxx_flash_npiv_conf(scsi_qla_host_t
*vha
)
949 #define NPIV_CONFIG_SIZE (16*1024)
952 uint16_t cnt
, chksum
;
954 struct qla_npiv_header hdr
;
955 struct qla_npiv_entry
*entry
;
956 struct qla_hw_data
*ha
= vha
->hw
;
958 if (!IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) && !IS_QLA8XXX_TYPE(ha
))
961 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)&hdr
,
962 ha
->flt_region_npiv_conf
<< 2, sizeof(struct qla_npiv_header
));
963 if (hdr
.version
== __constant_cpu_to_le16(0xffff))
965 if (hdr
.version
!= __constant_cpu_to_le16(1)) {
966 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unsupported NPIV-Config "
967 "detected: version=0x%x entries=0x%x checksum=0x%x.\n",
968 le16_to_cpu(hdr
.version
), le16_to_cpu(hdr
.entries
),
969 le16_to_cpu(hdr
.checksum
)));
973 data
= kmalloc(NPIV_CONFIG_SIZE
, GFP_KERNEL
);
975 DEBUG2(qla_printk(KERN_INFO
, ha
, "NPIV-Config: Unable to "
976 "allocate memory.\n"));
980 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)data
,
981 ha
->flt_region_npiv_conf
<< 2, NPIV_CONFIG_SIZE
);
983 cnt
= (sizeof(struct qla_npiv_header
) + le16_to_cpu(hdr
.entries
) *
984 sizeof(struct qla_npiv_entry
)) >> 1;
985 for (wptr
= data
, chksum
= 0; cnt
; cnt
--)
986 chksum
+= le16_to_cpu(*wptr
++);
988 DEBUG2(qla_printk(KERN_INFO
, ha
, "Inconsistent NPIV-Config "
989 "detected: version=0x%x entries=0x%x checksum=0x%x.\n",
990 le16_to_cpu(hdr
.version
), le16_to_cpu(hdr
.entries
),
995 entry
= data
+ sizeof(struct qla_npiv_header
);
996 cnt
= le16_to_cpu(hdr
.entries
);
997 for (i
= 0; cnt
; cnt
--, entry
++, i
++) {
999 struct fc_vport_identifiers vid
;
1000 struct fc_vport
*vport
;
1002 memcpy(&ha
->npiv_info
[i
], entry
, sizeof(struct qla_npiv_entry
));
1004 flags
= le16_to_cpu(entry
->flags
);
1005 if (flags
== 0xffff)
1007 if ((flags
& BIT_0
) == 0)
1010 memset(&vid
, 0, sizeof(vid
));
1011 vid
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
1012 vid
.vport_type
= FC_PORTTYPE_NPIV
;
1013 vid
.disable
= false;
1014 vid
.port_name
= wwn_to_u64(entry
->port_name
);
1015 vid
.node_name
= wwn_to_u64(entry
->node_name
);
1017 DEBUG2(qla_printk(KERN_INFO
, ha
, "NPIV[%02x]: wwpn=%llx "
1018 "wwnn=%llx vf_id=0x%x Q_qos=0x%x F_qos=0x%x.\n", cnt
,
1019 (unsigned long long)vid
.port_name
,
1020 (unsigned long long)vid
.node_name
,
1021 le16_to_cpu(entry
->vf_id
),
1022 entry
->q_qos
, entry
->f_qos
));
1024 if (i
< QLA_PRECONFIG_VPORTS
) {
1025 vport
= fc_vport_create(vha
->host
, 0, &vid
);
1027 qla_printk(KERN_INFO
, ha
,
1028 "NPIV-Config: Failed to create vport [%02x]: "
1029 "wwpn=%llx wwnn=%llx.\n", cnt
,
1030 (unsigned long long)vid
.port_name
,
1031 (unsigned long long)vid
.node_name
);
1039 qla24xx_unprotect_flash(scsi_qla_host_t
*vha
)
1041 struct qla_hw_data
*ha
= vha
->hw
;
1042 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1044 if (ha
->flags
.fac_supported
)
1045 return qla81xx_fac_do_write_enable(vha
, 1);
1047 /* Enable flash write. */
1048 WRT_REG_DWORD(®
->ctrl_status
,
1049 RD_REG_DWORD(®
->ctrl_status
) | CSRX_FLASH_ENABLE
);
1050 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
1052 if (!ha
->fdt_wrt_disable
)
1055 /* Disable flash write-protection, first clear SR protection bit */
1056 qla24xx_write_flash_dword(ha
, flash_conf_addr(ha
, 0x101), 0);
1057 /* Then write zero again to clear remaining SR bits.*/
1058 qla24xx_write_flash_dword(ha
, flash_conf_addr(ha
, 0x101), 0);
1064 qla24xx_protect_flash(scsi_qla_host_t
*vha
)
1067 struct qla_hw_data
*ha
= vha
->hw
;
1068 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1070 if (ha
->flags
.fac_supported
)
1071 return qla81xx_fac_do_write_enable(vha
, 0);
1073 if (!ha
->fdt_wrt_disable
)
1074 goto skip_wrt_protect
;
1076 /* Enable flash write-protection and wait for completion. */
1077 qla24xx_write_flash_dword(ha
, flash_conf_addr(ha
, 0x101),
1078 ha
->fdt_wrt_disable
);
1079 for (cnt
= 300; cnt
&&
1080 qla24xx_read_flash_dword(ha
, flash_conf_addr(ha
, 0x005)) & BIT_0
;
1086 /* Disable flash write. */
1087 WRT_REG_DWORD(®
->ctrl_status
,
1088 RD_REG_DWORD(®
->ctrl_status
) & ~CSRX_FLASH_ENABLE
);
1089 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
1095 qla24xx_erase_sector(scsi_qla_host_t
*vha
, uint32_t fdata
)
1097 struct qla_hw_data
*ha
= vha
->hw
;
1098 uint32_t start
, finish
;
1100 if (ha
->flags
.fac_supported
) {
1102 finish
= start
+ (ha
->fdt_block_size
>> 2) - 1;
1103 return qla81xx_fac_erase_sector(vha
, flash_data_addr(ha
,
1104 start
), flash_data_addr(ha
, finish
));
1107 return qla24xx_write_flash_dword(ha
, ha
->fdt_erase_cmd
,
1108 (fdata
& 0xff00) | ((fdata
<< 16) & 0xff0000) |
1109 ((fdata
>> 16) & 0xff));
1113 qla24xx_write_flash_data(scsi_qla_host_t
*vha
, uint32_t *dwptr
, uint32_t faddr
,
1118 uint32_t sec_mask
, rest_addr
;
1120 dma_addr_t optrom_dma
;
1121 void *optrom
= NULL
;
1122 struct qla_hw_data
*ha
= vha
->hw
;
1124 /* Prepare burst-capable write on supported ISPs. */
1125 if ((IS_QLA25XX(ha
) || IS_QLA81XX(ha
)) && !(faddr
& 0xfff) &&
1126 dwords
> OPTROM_BURST_DWORDS
) {
1127 optrom
= dma_alloc_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
,
1128 &optrom_dma
, GFP_KERNEL
);
1130 qla_printk(KERN_DEBUG
, ha
,
1131 "Unable to allocate memory for optrom burst write "
1132 "(%x KB).\n", OPTROM_BURST_SIZE
/ 1024);
1136 rest_addr
= (ha
->fdt_block_size
>> 2) - 1;
1137 sec_mask
= ~rest_addr
;
1139 ret
= qla24xx_unprotect_flash(vha
);
1140 if (ret
!= QLA_SUCCESS
) {
1141 qla_printk(KERN_WARNING
, ha
,
1142 "Unable to unprotect flash for update.\n");
1146 for (liter
= 0; liter
< dwords
; liter
++, faddr
++, dwptr
++) {
1147 fdata
= (faddr
& sec_mask
) << 2;
1149 /* Are we at the beginning of a sector? */
1150 if ((faddr
& rest_addr
) == 0) {
1151 /* Do sector unprotect. */
1152 if (ha
->fdt_unprotect_sec_cmd
)
1153 qla24xx_write_flash_dword(ha
,
1154 ha
->fdt_unprotect_sec_cmd
,
1155 (fdata
& 0xff00) | ((fdata
<< 16) &
1156 0xff0000) | ((fdata
>> 16) & 0xff));
1157 ret
= qla24xx_erase_sector(vha
, fdata
);
1158 if (ret
!= QLA_SUCCESS
) {
1159 DEBUG9(qla_printk(KERN_WARNING
, ha
,
1160 "Unable to erase sector: address=%x.\n",
1166 /* Go with burst-write. */
1167 if (optrom
&& (liter
+ OPTROM_BURST_DWORDS
) <= dwords
) {
1168 /* Copy data to DMA'ble buffer. */
1169 memcpy(optrom
, dwptr
, OPTROM_BURST_SIZE
);
1171 ret
= qla2x00_load_ram(vha
, optrom_dma
,
1172 flash_data_addr(ha
, faddr
),
1173 OPTROM_BURST_DWORDS
);
1174 if (ret
!= QLA_SUCCESS
) {
1175 qla_printk(KERN_WARNING
, ha
,
1176 "Unable to burst-write optrom segment "
1177 "(%x/%x/%llx).\n", ret
,
1178 flash_data_addr(ha
, faddr
),
1179 (unsigned long long)optrom_dma
);
1180 qla_printk(KERN_WARNING
, ha
,
1181 "Reverting to slow-write.\n");
1183 dma_free_coherent(&ha
->pdev
->dev
,
1184 OPTROM_BURST_SIZE
, optrom
, optrom_dma
);
1187 liter
+= OPTROM_BURST_DWORDS
- 1;
1188 faddr
+= OPTROM_BURST_DWORDS
- 1;
1189 dwptr
+= OPTROM_BURST_DWORDS
- 1;
1194 ret
= qla24xx_write_flash_dword(ha
,
1195 flash_data_addr(ha
, faddr
), cpu_to_le32(*dwptr
));
1196 if (ret
!= QLA_SUCCESS
) {
1197 DEBUG9(printk("%s(%ld) Unable to program flash "
1198 "address=%x data=%x.\n", __func__
,
1199 vha
->host_no
, faddr
, *dwptr
));
1203 /* Do sector protect. */
1204 if (ha
->fdt_unprotect_sec_cmd
&&
1205 ((faddr
& rest_addr
) == rest_addr
))
1206 qla24xx_write_flash_dword(ha
,
1207 ha
->fdt_protect_sec_cmd
,
1208 (fdata
& 0xff00) | ((fdata
<< 16) &
1209 0xff0000) | ((fdata
>> 16) & 0xff));
1212 ret
= qla24xx_protect_flash(vha
);
1213 if (ret
!= QLA_SUCCESS
)
1214 qla_printk(KERN_WARNING
, ha
,
1215 "Unable to protect flash after update.\n");
1218 dma_free_coherent(&ha
->pdev
->dev
,
1219 OPTROM_BURST_SIZE
, optrom
, optrom_dma
);
1225 qla2x00_read_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1230 struct qla_hw_data
*ha
= vha
->hw
;
1232 /* Word reads to NVRAM via registers. */
1233 wptr
= (uint16_t *)buf
;
1234 qla2x00_lock_nvram_access(ha
);
1235 for (i
= 0; i
< bytes
>> 1; i
++, naddr
++)
1236 wptr
[i
] = cpu_to_le16(qla2x00_get_nvram_word(ha
,
1238 qla2x00_unlock_nvram_access(ha
);
1244 qla24xx_read_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1249 struct qla_hw_data
*ha
= vha
->hw
;
1254 /* Dword reads to flash. */
1255 dwptr
= (uint32_t *)buf
;
1256 for (i
= 0; i
< bytes
>> 2; i
++, naddr
++)
1257 dwptr
[i
] = cpu_to_le32(qla24xx_read_flash_dword(ha
,
1258 nvram_data_addr(ha
, naddr
)));
1264 qla2x00_write_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1270 unsigned long flags
;
1271 struct qla_hw_data
*ha
= vha
->hw
;
1275 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1276 qla2x00_lock_nvram_access(ha
);
1278 /* Disable NVRAM write-protection. */
1279 stat
= qla2x00_clear_nvram_protection(ha
);
1281 wptr
= (uint16_t *)buf
;
1282 for (i
= 0; i
< bytes
>> 1; i
++, naddr
++) {
1283 qla2x00_write_nvram_word(ha
, naddr
,
1284 cpu_to_le16(*wptr
));
1288 /* Enable NVRAM write-protection. */
1289 qla2x00_set_nvram_protection(ha
, stat
);
1291 qla2x00_unlock_nvram_access(ha
);
1292 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1298 qla24xx_write_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1304 struct qla_hw_data
*ha
= vha
->hw
;
1305 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1312 /* Enable flash write. */
1313 WRT_REG_DWORD(®
->ctrl_status
,
1314 RD_REG_DWORD(®
->ctrl_status
) | CSRX_FLASH_ENABLE
);
1315 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
1317 /* Disable NVRAM write-protection. */
1318 qla24xx_write_flash_dword(ha
, nvram_conf_addr(ha
, 0x101), 0);
1319 qla24xx_write_flash_dword(ha
, nvram_conf_addr(ha
, 0x101), 0);
1321 /* Dword writes to flash. */
1322 dwptr
= (uint32_t *)buf
;
1323 for (i
= 0; i
< bytes
>> 2; i
++, naddr
++, dwptr
++) {
1324 ret
= qla24xx_write_flash_dword(ha
,
1325 nvram_data_addr(ha
, naddr
), cpu_to_le32(*dwptr
));
1326 if (ret
!= QLA_SUCCESS
) {
1327 DEBUG9(qla_printk(KERN_WARNING
, ha
,
1328 "Unable to program nvram address=%x data=%x.\n",
1334 /* Enable NVRAM write-protection. */
1335 qla24xx_write_flash_dword(ha
, nvram_conf_addr(ha
, 0x101), 0x8c);
1337 /* Disable flash write. */
1338 WRT_REG_DWORD(®
->ctrl_status
,
1339 RD_REG_DWORD(®
->ctrl_status
) & ~CSRX_FLASH_ENABLE
);
1340 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
1346 qla25xx_read_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1351 struct qla_hw_data
*ha
= vha
->hw
;
1353 /* Dword reads to flash. */
1354 dwptr
= (uint32_t *)buf
;
1355 for (i
= 0; i
< bytes
>> 2; i
++, naddr
++)
1356 dwptr
[i
] = cpu_to_le32(qla24xx_read_flash_dword(ha
,
1357 flash_data_addr(ha
, ha
->flt_region_vpd_nvram
| naddr
)));
1363 qla25xx_write_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1366 struct qla_hw_data
*ha
= vha
->hw
;
1367 #define RMW_BUFFER_SIZE (64 * 1024)
1370 dbuf
= vmalloc(RMW_BUFFER_SIZE
);
1372 return QLA_MEMORY_ALLOC_FAILED
;
1373 ha
->isp_ops
->read_optrom(vha
, dbuf
, ha
->flt_region_vpd_nvram
<< 2,
1375 memcpy(dbuf
+ (naddr
<< 2), buf
, bytes
);
1376 ha
->isp_ops
->write_optrom(vha
, dbuf
, ha
->flt_region_vpd_nvram
<< 2,
1384 qla2x00_flip_colors(struct qla_hw_data
*ha
, uint16_t *pflags
)
1386 if (IS_QLA2322(ha
)) {
1387 /* Flip all colors. */
1388 if (ha
->beacon_color_state
== QLA_LED_ALL_ON
) {
1390 ha
->beacon_color_state
= 0;
1391 *pflags
= GPIO_LED_ALL_OFF
;
1394 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1395 *pflags
= GPIO_LED_RGA_ON
;
1398 /* Flip green led only. */
1399 if (ha
->beacon_color_state
== QLA_LED_GRN_ON
) {
1401 ha
->beacon_color_state
= 0;
1402 *pflags
= GPIO_LED_GREEN_OFF_AMBER_OFF
;
1405 ha
->beacon_color_state
= QLA_LED_GRN_ON
;
1406 *pflags
= GPIO_LED_GREEN_ON_AMBER_OFF
;
1411 #define PIO_REG(h, r) ((h)->pio_address + offsetof(struct device_reg_2xxx, r))
1414 qla2x00_beacon_blink(struct scsi_qla_host
*vha
)
1416 uint16_t gpio_enable
;
1418 uint16_t led_color
= 0;
1419 unsigned long flags
;
1420 struct qla_hw_data
*ha
= vha
->hw
;
1421 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1426 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1428 /* Save the Original GPIOE. */
1429 if (ha
->pio_address
) {
1430 gpio_enable
= RD_REG_WORD_PIO(PIO_REG(ha
, gpioe
));
1431 gpio_data
= RD_REG_WORD_PIO(PIO_REG(ha
, gpiod
));
1433 gpio_enable
= RD_REG_WORD(®
->gpioe
);
1434 gpio_data
= RD_REG_WORD(®
->gpiod
);
1437 /* Set the modified gpio_enable values */
1438 gpio_enable
|= GPIO_LED_MASK
;
1440 if (ha
->pio_address
) {
1441 WRT_REG_WORD_PIO(PIO_REG(ha
, gpioe
), gpio_enable
);
1443 WRT_REG_WORD(®
->gpioe
, gpio_enable
);
1444 RD_REG_WORD(®
->gpioe
);
1447 qla2x00_flip_colors(ha
, &led_color
);
1449 /* Clear out any previously set LED color. */
1450 gpio_data
&= ~GPIO_LED_MASK
;
1452 /* Set the new input LED color to GPIOD. */
1453 gpio_data
|= led_color
;
1455 /* Set the modified gpio_data values */
1456 if (ha
->pio_address
) {
1457 WRT_REG_WORD_PIO(PIO_REG(ha
, gpiod
), gpio_data
);
1459 WRT_REG_WORD(®
->gpiod
, gpio_data
);
1460 RD_REG_WORD(®
->gpiod
);
1463 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1467 qla2x00_beacon_on(struct scsi_qla_host
*vha
)
1469 uint16_t gpio_enable
;
1471 unsigned long flags
;
1472 struct qla_hw_data
*ha
= vha
->hw
;
1473 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1475 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1476 ha
->fw_options
[1] |= FO1_DISABLE_GPIO6_7
;
1478 if (qla2x00_set_fw_options(vha
, ha
->fw_options
) != QLA_SUCCESS
) {
1479 qla_printk(KERN_WARNING
, ha
,
1480 "Unable to update fw options (beacon on).\n");
1481 return QLA_FUNCTION_FAILED
;
1484 /* Turn off LEDs. */
1485 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1486 if (ha
->pio_address
) {
1487 gpio_enable
= RD_REG_WORD_PIO(PIO_REG(ha
, gpioe
));
1488 gpio_data
= RD_REG_WORD_PIO(PIO_REG(ha
, gpiod
));
1490 gpio_enable
= RD_REG_WORD(®
->gpioe
);
1491 gpio_data
= RD_REG_WORD(®
->gpiod
);
1493 gpio_enable
|= GPIO_LED_MASK
;
1495 /* Set the modified gpio_enable values. */
1496 if (ha
->pio_address
) {
1497 WRT_REG_WORD_PIO(PIO_REG(ha
, gpioe
), gpio_enable
);
1499 WRT_REG_WORD(®
->gpioe
, gpio_enable
);
1500 RD_REG_WORD(®
->gpioe
);
1503 /* Clear out previously set LED colour. */
1504 gpio_data
&= ~GPIO_LED_MASK
;
1505 if (ha
->pio_address
) {
1506 WRT_REG_WORD_PIO(PIO_REG(ha
, gpiod
), gpio_data
);
1508 WRT_REG_WORD(®
->gpiod
, gpio_data
);
1509 RD_REG_WORD(®
->gpiod
);
1511 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1514 * Let the per HBA timer kick off the blinking process based on
1515 * the following flags. No need to do anything else now.
1517 ha
->beacon_blink_led
= 1;
1518 ha
->beacon_color_state
= 0;
1524 qla2x00_beacon_off(struct scsi_qla_host
*vha
)
1526 int rval
= QLA_SUCCESS
;
1527 struct qla_hw_data
*ha
= vha
->hw
;
1529 ha
->beacon_blink_led
= 0;
1531 /* Set the on flag so when it gets flipped it will be off. */
1533 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1535 ha
->beacon_color_state
= QLA_LED_GRN_ON
;
1537 ha
->isp_ops
->beacon_blink(vha
); /* This turns green LED off */
1539 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1540 ha
->fw_options
[1] &= ~FO1_DISABLE_GPIO6_7
;
1542 rval
= qla2x00_set_fw_options(vha
, ha
->fw_options
);
1543 if (rval
!= QLA_SUCCESS
)
1544 qla_printk(KERN_WARNING
, ha
,
1545 "Unable to update fw options (beacon off).\n");
1551 qla24xx_flip_colors(struct qla_hw_data
*ha
, uint16_t *pflags
)
1553 /* Flip all colors. */
1554 if (ha
->beacon_color_state
== QLA_LED_ALL_ON
) {
1556 ha
->beacon_color_state
= 0;
1560 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1561 *pflags
= GPDX_LED_YELLOW_ON
| GPDX_LED_AMBER_ON
;
1566 qla24xx_beacon_blink(struct scsi_qla_host
*vha
)
1568 uint16_t led_color
= 0;
1570 unsigned long flags
;
1571 struct qla_hw_data
*ha
= vha
->hw
;
1572 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1574 /* Save the Original GPIOD. */
1575 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1576 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1578 /* Enable the gpio_data reg for update. */
1579 gpio_data
|= GPDX_LED_UPDATE_MASK
;
1581 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1582 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1584 /* Set the color bits. */
1585 qla24xx_flip_colors(ha
, &led_color
);
1587 /* Clear out any previously set LED color. */
1588 gpio_data
&= ~GPDX_LED_COLOR_MASK
;
1590 /* Set the new input LED color to GPIOD. */
1591 gpio_data
|= led_color
;
1593 /* Set the modified gpio_data values. */
1594 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1595 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1596 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1600 qla24xx_beacon_on(struct scsi_qla_host
*vha
)
1603 unsigned long flags
;
1604 struct qla_hw_data
*ha
= vha
->hw
;
1605 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1610 if (ha
->beacon_blink_led
== 0) {
1611 /* Enable firmware for update */
1612 ha
->fw_options
[1] |= ADD_FO1_DISABLE_GPIO_LED_CTRL
;
1614 if (qla2x00_set_fw_options(vha
, ha
->fw_options
) != QLA_SUCCESS
)
1615 return QLA_FUNCTION_FAILED
;
1617 if (qla2x00_get_fw_options(vha
, ha
->fw_options
) !=
1619 qla_printk(KERN_WARNING
, ha
,
1620 "Unable to update fw options (beacon on).\n");
1621 return QLA_FUNCTION_FAILED
;
1624 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1625 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1627 /* Enable the gpio_data reg for update. */
1628 gpio_data
|= GPDX_LED_UPDATE_MASK
;
1629 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1630 RD_REG_DWORD(®
->gpiod
);
1632 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1635 /* So all colors blink together. */
1636 ha
->beacon_color_state
= 0;
1638 /* Let the per HBA timer kick off the blinking process. */
1639 ha
->beacon_blink_led
= 1;
1645 qla24xx_beacon_off(struct scsi_qla_host
*vha
)
1648 unsigned long flags
;
1649 struct qla_hw_data
*ha
= vha
->hw
;
1650 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1655 ha
->beacon_blink_led
= 0;
1656 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1658 ha
->isp_ops
->beacon_blink(vha
); /* Will flip to all off. */
1660 /* Give control back to firmware. */
1661 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1662 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1664 /* Disable the gpio_data reg for update. */
1665 gpio_data
&= ~GPDX_LED_UPDATE_MASK
;
1666 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1667 RD_REG_DWORD(®
->gpiod
);
1668 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1670 ha
->fw_options
[1] &= ~ADD_FO1_DISABLE_GPIO_LED_CTRL
;
1672 if (qla2x00_set_fw_options(vha
, ha
->fw_options
) != QLA_SUCCESS
) {
1673 qla_printk(KERN_WARNING
, ha
,
1674 "Unable to update fw options (beacon off).\n");
1675 return QLA_FUNCTION_FAILED
;
1678 if (qla2x00_get_fw_options(vha
, ha
->fw_options
) != QLA_SUCCESS
) {
1679 qla_printk(KERN_WARNING
, ha
,
1680 "Unable to get fw options (beacon off).\n");
1681 return QLA_FUNCTION_FAILED
;
1689 * Flash support routines
1693 * qla2x00_flash_enable() - Setup flash for reading and writing.
1697 qla2x00_flash_enable(struct qla_hw_data
*ha
)
1700 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1702 data
= RD_REG_WORD(®
->ctrl_status
);
1703 data
|= CSR_FLASH_ENABLE
;
1704 WRT_REG_WORD(®
->ctrl_status
, data
);
1705 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1709 * qla2x00_flash_disable() - Disable flash and allow RISC to run.
1713 qla2x00_flash_disable(struct qla_hw_data
*ha
)
1716 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1718 data
= RD_REG_WORD(®
->ctrl_status
);
1719 data
&= ~(CSR_FLASH_ENABLE
);
1720 WRT_REG_WORD(®
->ctrl_status
, data
);
1721 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1725 * qla2x00_read_flash_byte() - Reads a byte from flash
1727 * @addr: Address in flash to read
1729 * A word is read from the chip, but, only the lower byte is valid.
1731 * Returns the byte read from flash @addr.
1734 qla2x00_read_flash_byte(struct qla_hw_data
*ha
, uint32_t addr
)
1737 uint16_t bank_select
;
1738 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1740 bank_select
= RD_REG_WORD(®
->ctrl_status
);
1742 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1743 /* Specify 64K address range: */
1744 /* clear out Module Select and Flash Address bits [19:16]. */
1745 bank_select
&= ~0xf8;
1746 bank_select
|= addr
>> 12 & 0xf0;
1747 bank_select
|= CSR_FLASH_64K_BANK
;
1748 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1749 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1751 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1752 data
= RD_REG_WORD(®
->flash_data
);
1754 return (uint8_t)data
;
1757 /* Setup bit 16 of flash address. */
1758 if ((addr
& BIT_16
) && ((bank_select
& CSR_FLASH_64K_BANK
) == 0)) {
1759 bank_select
|= CSR_FLASH_64K_BANK
;
1760 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1761 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1762 } else if (((addr
& BIT_16
) == 0) &&
1763 (bank_select
& CSR_FLASH_64K_BANK
)) {
1764 bank_select
&= ~(CSR_FLASH_64K_BANK
);
1765 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1766 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1769 /* Always perform IO mapped accesses to the FLASH registers. */
1770 if (ha
->pio_address
) {
1773 WRT_REG_WORD_PIO(PIO_REG(ha
, flash_address
), (uint16_t)addr
);
1775 data
= RD_REG_WORD_PIO(PIO_REG(ha
, flash_data
));
1778 data2
= RD_REG_WORD_PIO(PIO_REG(ha
, flash_data
));
1779 } while (data
!= data2
);
1781 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1782 data
= qla2x00_debounce_register(®
->flash_data
);
1785 return (uint8_t)data
;
1789 * qla2x00_write_flash_byte() - Write a byte to flash
1791 * @addr: Address in flash to write
1792 * @data: Data to write
1795 qla2x00_write_flash_byte(struct qla_hw_data
*ha
, uint32_t addr
, uint8_t data
)
1797 uint16_t bank_select
;
1798 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1800 bank_select
= RD_REG_WORD(®
->ctrl_status
);
1801 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1802 /* Specify 64K address range: */
1803 /* clear out Module Select and Flash Address bits [19:16]. */
1804 bank_select
&= ~0xf8;
1805 bank_select
|= addr
>> 12 & 0xf0;
1806 bank_select
|= CSR_FLASH_64K_BANK
;
1807 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1808 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1810 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1811 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1812 WRT_REG_WORD(®
->flash_data
, (uint16_t)data
);
1813 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1818 /* Setup bit 16 of flash address. */
1819 if ((addr
& BIT_16
) && ((bank_select
& CSR_FLASH_64K_BANK
) == 0)) {
1820 bank_select
|= CSR_FLASH_64K_BANK
;
1821 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1822 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1823 } else if (((addr
& BIT_16
) == 0) &&
1824 (bank_select
& CSR_FLASH_64K_BANK
)) {
1825 bank_select
&= ~(CSR_FLASH_64K_BANK
);
1826 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1827 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1830 /* Always perform IO mapped accesses to the FLASH registers. */
1831 if (ha
->pio_address
) {
1832 WRT_REG_WORD_PIO(PIO_REG(ha
, flash_address
), (uint16_t)addr
);
1833 WRT_REG_WORD_PIO(PIO_REG(ha
, flash_data
), (uint16_t)data
);
1835 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1836 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1837 WRT_REG_WORD(®
->flash_data
, (uint16_t)data
);
1838 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1843 * qla2x00_poll_flash() - Polls flash for completion.
1845 * @addr: Address in flash to poll
1846 * @poll_data: Data to be polled
1847 * @man_id: Flash manufacturer ID
1848 * @flash_id: Flash ID
1850 * This function polls the device until bit 7 of what is read matches data
1851 * bit 7 or until data bit 5 becomes a 1. If that hapens, the flash ROM timed
1852 * out (a fatal error). The flash book recommeds reading bit 7 again after
1853 * reading bit 5 as a 1.
1855 * Returns 0 on success, else non-zero.
1858 qla2x00_poll_flash(struct qla_hw_data
*ha
, uint32_t addr
, uint8_t poll_data
,
1859 uint8_t man_id
, uint8_t flash_id
)
1867 /* Wait for 30 seconds for command to finish. */
1869 for (cnt
= 3000000; cnt
; cnt
--) {
1870 flash_data
= qla2x00_read_flash_byte(ha
, addr
);
1871 if ((flash_data
& BIT_7
) == poll_data
) {
1876 if (man_id
!= 0x40 && man_id
!= 0xda) {
1877 if ((flash_data
& BIT_5
) && cnt
> 2)
1888 * qla2x00_program_flash_address() - Programs a flash address
1890 * @addr: Address in flash to program
1891 * @data: Data to be written in flash
1892 * @man_id: Flash manufacturer ID
1893 * @flash_id: Flash ID
1895 * Returns 0 on success, else non-zero.
1898 qla2x00_program_flash_address(struct qla_hw_data
*ha
, uint32_t addr
,
1899 uint8_t data
, uint8_t man_id
, uint8_t flash_id
)
1901 /* Write Program Command Sequence. */
1902 if (IS_OEM_001(ha
)) {
1903 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1904 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1905 qla2x00_write_flash_byte(ha
, 0xaaa, 0xa0);
1906 qla2x00_write_flash_byte(ha
, addr
, data
);
1908 if (man_id
== 0xda && flash_id
== 0xc1) {
1909 qla2x00_write_flash_byte(ha
, addr
, data
);
1913 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1914 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1915 qla2x00_write_flash_byte(ha
, 0x5555, 0xa0);
1916 qla2x00_write_flash_byte(ha
, addr
, data
);
1922 /* Wait for write to complete. */
1923 return qla2x00_poll_flash(ha
, addr
, data
, man_id
, flash_id
);
1927 * qla2x00_erase_flash() - Erase the flash.
1929 * @man_id: Flash manufacturer ID
1930 * @flash_id: Flash ID
1932 * Returns 0 on success, else non-zero.
1935 qla2x00_erase_flash(struct qla_hw_data
*ha
, uint8_t man_id
, uint8_t flash_id
)
1937 /* Individual Sector Erase Command Sequence */
1938 if (IS_OEM_001(ha
)) {
1939 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1940 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1941 qla2x00_write_flash_byte(ha
, 0xaaa, 0x80);
1942 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1943 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1944 qla2x00_write_flash_byte(ha
, 0xaaa, 0x10);
1946 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1947 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1948 qla2x00_write_flash_byte(ha
, 0x5555, 0x80);
1949 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1950 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1951 qla2x00_write_flash_byte(ha
, 0x5555, 0x10);
1956 /* Wait for erase to complete. */
1957 return qla2x00_poll_flash(ha
, 0x00, 0x80, man_id
, flash_id
);
1961 * qla2x00_erase_flash_sector() - Erase a flash sector.
1963 * @addr: Flash sector to erase
1964 * @sec_mask: Sector address mask
1965 * @man_id: Flash manufacturer ID
1966 * @flash_id: Flash ID
1968 * Returns 0 on success, else non-zero.
1971 qla2x00_erase_flash_sector(struct qla_hw_data
*ha
, uint32_t addr
,
1972 uint32_t sec_mask
, uint8_t man_id
, uint8_t flash_id
)
1974 /* Individual Sector Erase Command Sequence */
1975 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1976 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1977 qla2x00_write_flash_byte(ha
, 0x5555, 0x80);
1978 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1979 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1980 if (man_id
== 0x1f && flash_id
== 0x13)
1981 qla2x00_write_flash_byte(ha
, addr
& sec_mask
, 0x10);
1983 qla2x00_write_flash_byte(ha
, addr
& sec_mask
, 0x30);
1987 /* Wait for erase to complete. */
1988 return qla2x00_poll_flash(ha
, addr
, 0x80, man_id
, flash_id
);
1992 * qla2x00_get_flash_manufacturer() - Read manufacturer ID from flash chip.
1993 * @man_id: Flash manufacturer ID
1994 * @flash_id: Flash ID
1997 qla2x00_get_flash_manufacturer(struct qla_hw_data
*ha
, uint8_t *man_id
,
2000 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
2001 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
2002 qla2x00_write_flash_byte(ha
, 0x5555, 0x90);
2003 *man_id
= qla2x00_read_flash_byte(ha
, 0x0000);
2004 *flash_id
= qla2x00_read_flash_byte(ha
, 0x0001);
2005 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
2006 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
2007 qla2x00_write_flash_byte(ha
, 0x5555, 0xf0);
2011 qla2x00_read_flash_data(struct qla_hw_data
*ha
, uint8_t *tmp_buf
,
2012 uint32_t saddr
, uint32_t length
)
2014 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2015 uint32_t midpoint
, ilength
;
2018 midpoint
= length
/ 2;
2020 WRT_REG_WORD(®
->nvram
, 0);
2021 RD_REG_WORD(®
->nvram
);
2022 for (ilength
= 0; ilength
< length
; saddr
++, ilength
++, tmp_buf
++) {
2023 if (ilength
== midpoint
) {
2024 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
2025 RD_REG_WORD(®
->nvram
);
2027 data
= qla2x00_read_flash_byte(ha
, saddr
);
2036 qla2x00_suspend_hba(struct scsi_qla_host
*vha
)
2039 unsigned long flags
;
2040 struct qla_hw_data
*ha
= vha
->hw
;
2041 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2044 scsi_block_requests(vha
->host
);
2045 ha
->isp_ops
->disable_intrs(ha
);
2046 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
2049 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2050 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
2051 RD_REG_WORD(®
->hccr
);
2052 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2053 for (cnt
= 0; cnt
< 30000; cnt
++) {
2054 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
2061 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2065 qla2x00_resume_hba(struct scsi_qla_host
*vha
)
2067 struct qla_hw_data
*ha
= vha
->hw
;
2070 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
2071 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2072 qla2xxx_wake_dpc(vha
);
2073 qla2x00_wait_for_chip_reset(vha
);
2074 scsi_unblock_requests(vha
->host
);
2078 qla2x00_read_optrom_data(struct scsi_qla_host
*vha
, uint8_t *buf
,
2079 uint32_t offset
, uint32_t length
)
2081 uint32_t addr
, midpoint
;
2083 struct qla_hw_data
*ha
= vha
->hw
;
2084 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2087 qla2x00_suspend_hba(vha
);
2090 midpoint
= ha
->optrom_size
/ 2;
2092 qla2x00_flash_enable(ha
);
2093 WRT_REG_WORD(®
->nvram
, 0);
2094 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
2095 for (addr
= offset
, data
= buf
; addr
< length
; addr
++, data
++) {
2096 if (addr
== midpoint
) {
2097 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
2098 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
2101 *data
= qla2x00_read_flash_byte(ha
, addr
);
2103 qla2x00_flash_disable(ha
);
2106 qla2x00_resume_hba(vha
);
2112 qla2x00_write_optrom_data(struct scsi_qla_host
*vha
, uint8_t *buf
,
2113 uint32_t offset
, uint32_t length
)
2117 uint8_t man_id
, flash_id
, sec_number
, data
;
2119 uint32_t addr
, liter
, sec_mask
, rest_addr
;
2120 struct qla_hw_data
*ha
= vha
->hw
;
2121 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2124 qla2x00_suspend_hba(vha
);
2129 /* Reset ISP chip. */
2130 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2131 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
2133 /* Go with write. */
2134 qla2x00_flash_enable(ha
);
2135 do { /* Loop once to provide quick error exit */
2136 /* Structure of flash memory based on manufacturer */
2137 if (IS_OEM_001(ha
)) {
2138 /* OEM variant with special flash part. */
2139 man_id
= flash_id
= 0;
2144 qla2x00_get_flash_manufacturer(ha
, &man_id
, &flash_id
);
2146 case 0x20: /* ST flash. */
2147 if (flash_id
== 0xd2 || flash_id
== 0xe3) {
2149 * ST m29w008at part - 64kb sector size with
2150 * 32kb,8kb,8kb,16kb sectors at memory address
2158 * ST m29w010b part - 16kb sector size
2159 * Default to 16kb sectors
2164 case 0x40: /* Mostel flash. */
2165 /* Mostel v29c51001 part - 512 byte sector size. */
2169 case 0xbf: /* SST flash. */
2170 /* SST39sf10 part - 4kb sector size. */
2174 case 0xda: /* Winbond flash. */
2175 /* Winbond W29EE011 part - 256 byte sector size. */
2179 case 0xc2: /* Macronix flash. */
2180 /* 64k sector size. */
2181 if (flash_id
== 0x38 || flash_id
== 0x4f) {
2186 /* Fall through... */
2188 case 0x1f: /* Atmel flash. */
2189 /* 512k sector size. */
2190 if (flash_id
== 0x13) {
2191 rest_addr
= 0x7fffffff;
2192 sec_mask
= 0x80000000;
2195 /* Fall through... */
2197 case 0x01: /* AMD flash. */
2198 if (flash_id
== 0x38 || flash_id
== 0x40 ||
2200 /* Am29LV081 part - 64kb sector size. */
2201 /* Am29LV002BT part - 64kb sector size. */
2205 } else if (flash_id
== 0x3e) {
2207 * Am29LV008b part - 64kb sector size with
2208 * 32kb,8kb,8kb,16kb sector at memory address
2214 } else if (flash_id
== 0x20 || flash_id
== 0x6e) {
2216 * Am29LV010 part or AM29f010 - 16kb sector
2222 } else if (flash_id
== 0x6d) {
2223 /* Am29LV001 part - 8kb sector size. */
2229 /* Default to 16 kb sector size. */
2236 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
2237 if (qla2x00_erase_flash(ha
, man_id
, flash_id
)) {
2238 rval
= QLA_FUNCTION_FAILED
;
2243 for (addr
= offset
, liter
= 0; liter
< length
; liter
++,
2246 /* Are we at the beginning of a sector? */
2247 if ((addr
& rest_addr
) == 0) {
2248 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
2249 if (addr
>= 0x10000UL
) {
2250 if (((addr
>> 12) & 0xf0) &&
2252 flash_id
== 0x3e) ||
2254 flash_id
== 0xd2))) {
2256 if (sec_number
== 1) {
2277 } else if (addr
== ha
->optrom_size
/ 2) {
2278 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
2279 RD_REG_WORD(®
->nvram
);
2282 if (flash_id
== 0xda && man_id
== 0xc1) {
2283 qla2x00_write_flash_byte(ha
, 0x5555,
2285 qla2x00_write_flash_byte(ha
, 0x2aaa,
2287 qla2x00_write_flash_byte(ha
, 0x5555,
2289 } else if (!IS_QLA2322(ha
) && !IS_QLA6322(ha
)) {
2291 if (qla2x00_erase_flash_sector(ha
,
2292 addr
, sec_mask
, man_id
,
2294 rval
= QLA_FUNCTION_FAILED
;
2297 if (man_id
== 0x01 && flash_id
== 0x6d)
2302 if (man_id
== 0x01 && flash_id
== 0x6d) {
2303 if (sec_number
== 1 &&
2304 addr
== (rest_addr
- 1)) {
2307 } else if (sec_number
== 3 && (addr
& 0x7ffe)) {
2313 if (qla2x00_program_flash_address(ha
, addr
, data
,
2314 man_id
, flash_id
)) {
2315 rval
= QLA_FUNCTION_FAILED
;
2321 qla2x00_flash_disable(ha
);
2324 qla2x00_resume_hba(vha
);
2330 qla24xx_read_optrom_data(struct scsi_qla_host
*vha
, uint8_t *buf
,
2331 uint32_t offset
, uint32_t length
)
2333 struct qla_hw_data
*ha
= vha
->hw
;
2336 scsi_block_requests(vha
->host
);
2337 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
2340 qla24xx_read_flash_data(vha
, (uint32_t *)buf
, offset
>> 2, length
>> 2);
2343 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
2344 scsi_unblock_requests(vha
->host
);
2350 qla24xx_write_optrom_data(struct scsi_qla_host
*vha
, uint8_t *buf
,
2351 uint32_t offset
, uint32_t length
)
2354 struct qla_hw_data
*ha
= vha
->hw
;
2357 scsi_block_requests(vha
->host
);
2358 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
2360 /* Go with write. */
2361 rval
= qla24xx_write_flash_data(vha
, (uint32_t *)buf
, offset
>> 2,
2364 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
2365 scsi_unblock_requests(vha
->host
);
2371 qla25xx_read_optrom_data(struct scsi_qla_host
*vha
, uint8_t *buf
,
2372 uint32_t offset
, uint32_t length
)
2375 dma_addr_t optrom_dma
;
2378 uint32_t faddr
, left
, burst
;
2379 struct qla_hw_data
*ha
= vha
->hw
;
2381 if (IS_QLA25XX(ha
) || IS_QLA81XX(ha
))
2385 if (length
< OPTROM_BURST_SIZE
)
2389 optrom
= dma_alloc_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
,
2390 &optrom_dma
, GFP_KERNEL
);
2392 qla_printk(KERN_DEBUG
, ha
,
2393 "Unable to allocate memory for optrom burst read "
2394 "(%x KB).\n", OPTROM_BURST_SIZE
/ 1024);
2400 faddr
= offset
>> 2;
2402 burst
= OPTROM_BURST_DWORDS
;
2407 rval
= qla2x00_dump_ram(vha
, optrom_dma
,
2408 flash_data_addr(ha
, faddr
), burst
);
2410 qla_printk(KERN_WARNING
, ha
,
2411 "Unable to burst-read optrom segment "
2412 "(%x/%x/%llx).\n", rval
,
2413 flash_data_addr(ha
, faddr
),
2414 (unsigned long long)optrom_dma
);
2415 qla_printk(KERN_WARNING
, ha
,
2416 "Reverting to slow-read.\n");
2418 dma_free_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
,
2419 optrom
, optrom_dma
);
2423 memcpy(pbuf
, optrom
, burst
* 4);
2430 dma_free_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
, optrom
,
2436 return qla24xx_read_optrom_data(vha
, buf
, offset
, length
);
2440 * qla2x00_get_fcode_version() - Determine an FCODE image's version.
2442 * @pcids: Pointer to the FCODE PCI data structure
2444 * The process of retrieving the FCODE version information is at best
2445 * described as interesting.
2447 * Within the first 100h bytes of the image an ASCII string is present
2448 * which contains several pieces of information including the FCODE
2449 * version. Unfortunately it seems the only reliable way to retrieve
2450 * the version is by scanning for another sentinel within the string,
2451 * the FCODE build date:
2453 * ... 2.00.02 10/17/02 ...
2455 * Returns QLA_SUCCESS on successful retrieval of version.
2458 qla2x00_get_fcode_version(struct qla_hw_data
*ha
, uint32_t pcids
)
2460 int ret
= QLA_FUNCTION_FAILED
;
2461 uint32_t istart
, iend
, iter
, vend
;
2462 uint8_t do_next
, rbyte
, *vbyte
;
2464 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2466 /* Skip the PCI data structure. */
2468 ((qla2x00_read_flash_byte(ha
, pcids
+ 0x0B) << 8) |
2469 qla2x00_read_flash_byte(ha
, pcids
+ 0x0A));
2470 iend
= istart
+ 0x100;
2472 /* Scan for the sentinel date string...eeewww. */
2475 while ((iter
< iend
) && !do_next
) {
2477 if (qla2x00_read_flash_byte(ha
, iter
) == '/') {
2478 if (qla2x00_read_flash_byte(ha
, iter
+ 2) ==
2481 else if (qla2x00_read_flash_byte(ha
,
2489 /* Backtrack to previous ' ' (space). */
2491 while ((iter
> istart
) && !do_next
) {
2493 if (qla2x00_read_flash_byte(ha
, iter
) == ' ')
2500 * Mark end of version tag, and find previous ' ' (space) or
2501 * string length (recent FCODE images -- major hack ahead!!!).
2505 while ((iter
> istart
) && !do_next
) {
2507 rbyte
= qla2x00_read_flash_byte(ha
, iter
);
2508 if (rbyte
== ' ' || rbyte
== 0xd || rbyte
== 0x10)
2514 /* Mark beginning of version tag, and copy data. */
2516 if ((vend
- iter
) &&
2517 ((vend
- iter
) < sizeof(ha
->fcode_revision
))) {
2518 vbyte
= ha
->fcode_revision
;
2519 while (iter
<= vend
) {
2520 *vbyte
++ = qla2x00_read_flash_byte(ha
, iter
);
2527 if (ret
!= QLA_SUCCESS
)
2528 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2532 qla2x00_get_flash_version(scsi_qla_host_t
*vha
, void *mbuf
)
2534 int ret
= QLA_SUCCESS
;
2535 uint8_t code_type
, last_image
;
2536 uint32_t pcihdr
, pcids
;
2539 struct qla_hw_data
*ha
= vha
->hw
;
2541 if (!ha
->pio_address
|| !mbuf
)
2542 return QLA_FUNCTION_FAILED
;
2544 memset(ha
->bios_revision
, 0, sizeof(ha
->bios_revision
));
2545 memset(ha
->efi_revision
, 0, sizeof(ha
->efi_revision
));
2546 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2547 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2549 qla2x00_flash_enable(ha
);
2551 /* Begin with first PCI expansion ROM header. */
2555 /* Verify PCI expansion ROM header. */
2556 if (qla2x00_read_flash_byte(ha
, pcihdr
) != 0x55 ||
2557 qla2x00_read_flash_byte(ha
, pcihdr
+ 0x01) != 0xaa) {
2559 DEBUG2(qla_printk(KERN_DEBUG
, ha
, "No matching ROM "
2561 ret
= QLA_FUNCTION_FAILED
;
2565 /* Locate PCI data structure. */
2567 ((qla2x00_read_flash_byte(ha
, pcihdr
+ 0x19) << 8) |
2568 qla2x00_read_flash_byte(ha
, pcihdr
+ 0x18));
2570 /* Validate signature of PCI data structure. */
2571 if (qla2x00_read_flash_byte(ha
, pcids
) != 'P' ||
2572 qla2x00_read_flash_byte(ha
, pcids
+ 0x1) != 'C' ||
2573 qla2x00_read_flash_byte(ha
, pcids
+ 0x2) != 'I' ||
2574 qla2x00_read_flash_byte(ha
, pcids
+ 0x3) != 'R') {
2575 /* Incorrect header. */
2576 DEBUG2(qla_printk(KERN_INFO
, ha
, "PCI data struct not "
2577 "found pcir_adr=%x.\n", pcids
));
2578 ret
= QLA_FUNCTION_FAILED
;
2583 code_type
= qla2x00_read_flash_byte(ha
, pcids
+ 0x14);
2584 switch (code_type
) {
2585 case ROM_CODE_TYPE_BIOS
:
2586 /* Intel x86, PC-AT compatible. */
2587 ha
->bios_revision
[0] =
2588 qla2x00_read_flash_byte(ha
, pcids
+ 0x12);
2589 ha
->bios_revision
[1] =
2590 qla2x00_read_flash_byte(ha
, pcids
+ 0x13);
2591 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "read BIOS %d.%d.\n",
2592 ha
->bios_revision
[1], ha
->bios_revision
[0]));
2594 case ROM_CODE_TYPE_FCODE
:
2595 /* Open Firmware standard for PCI (FCode). */
2597 qla2x00_get_fcode_version(ha
, pcids
);
2599 case ROM_CODE_TYPE_EFI
:
2600 /* Extensible Firmware Interface (EFI). */
2601 ha
->efi_revision
[0] =
2602 qla2x00_read_flash_byte(ha
, pcids
+ 0x12);
2603 ha
->efi_revision
[1] =
2604 qla2x00_read_flash_byte(ha
, pcids
+ 0x13);
2605 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "read EFI %d.%d.\n",
2606 ha
->efi_revision
[1], ha
->efi_revision
[0]));
2609 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unrecognized code "
2610 "type %x at pcids %x.\n", code_type
, pcids
));
2614 last_image
= qla2x00_read_flash_byte(ha
, pcids
+ 0x15) & BIT_7
;
2616 /* Locate next PCI expansion ROM. */
2617 pcihdr
+= ((qla2x00_read_flash_byte(ha
, pcids
+ 0x11) << 8) |
2618 qla2x00_read_flash_byte(ha
, pcids
+ 0x10)) * 512;
2619 } while (!last_image
);
2621 if (IS_QLA2322(ha
)) {
2622 /* Read firmware image information. */
2623 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2625 memset(dbyte
, 0, 8);
2626 dcode
= (uint16_t *)dbyte
;
2628 qla2x00_read_flash_data(ha
, dbyte
, ha
->flt_region_fw
* 4 + 10,
2630 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "dumping fw ver from "
2632 DEBUG3(qla2x00_dump_buffer((uint8_t *)dbyte
, 8));
2634 if ((dcode
[0] == 0xffff && dcode
[1] == 0xffff &&
2635 dcode
[2] == 0xffff && dcode
[3] == 0xffff) ||
2636 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
2638 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unrecognized fw "
2639 "revision at %x.\n", ha
->flt_region_fw
* 4));
2641 /* values are in big endian */
2642 ha
->fw_revision
[0] = dbyte
[0] << 16 | dbyte
[1];
2643 ha
->fw_revision
[1] = dbyte
[2] << 16 | dbyte
[3];
2644 ha
->fw_revision
[2] = dbyte
[4] << 16 | dbyte
[5];
2648 qla2x00_flash_disable(ha
);
2654 qla24xx_get_flash_version(scsi_qla_host_t
*vha
, void *mbuf
)
2656 int ret
= QLA_SUCCESS
;
2657 uint32_t pcihdr
, pcids
;
2660 uint8_t code_type
, last_image
;
2662 struct qla_hw_data
*ha
= vha
->hw
;
2668 return QLA_FUNCTION_FAILED
;
2670 memset(ha
->bios_revision
, 0, sizeof(ha
->bios_revision
));
2671 memset(ha
->efi_revision
, 0, sizeof(ha
->efi_revision
));
2672 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2673 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2677 /* Begin with first PCI expansion ROM header. */
2678 pcihdr
= ha
->flt_region_boot
<< 2;
2681 /* Verify PCI expansion ROM header. */
2682 qla24xx_read_flash_data(vha
, dcode
, pcihdr
>> 2, 0x20);
2683 bcode
= mbuf
+ (pcihdr
% 4);
2684 if (bcode
[0x0] != 0x55 || bcode
[0x1] != 0xaa) {
2686 DEBUG2(qla_printk(KERN_DEBUG
, ha
, "No matching ROM "
2688 ret
= QLA_FUNCTION_FAILED
;
2692 /* Locate PCI data structure. */
2693 pcids
= pcihdr
+ ((bcode
[0x19] << 8) | bcode
[0x18]);
2695 qla24xx_read_flash_data(vha
, dcode
, pcids
>> 2, 0x20);
2696 bcode
= mbuf
+ (pcihdr
% 4);
2698 /* Validate signature of PCI data structure. */
2699 if (bcode
[0x0] != 'P' || bcode
[0x1] != 'C' ||
2700 bcode
[0x2] != 'I' || bcode
[0x3] != 'R') {
2701 /* Incorrect header. */
2702 DEBUG2(qla_printk(KERN_INFO
, ha
, "PCI data struct not "
2703 "found pcir_adr=%x.\n", pcids
));
2704 ret
= QLA_FUNCTION_FAILED
;
2709 code_type
= bcode
[0x14];
2710 switch (code_type
) {
2711 case ROM_CODE_TYPE_BIOS
:
2712 /* Intel x86, PC-AT compatible. */
2713 ha
->bios_revision
[0] = bcode
[0x12];
2714 ha
->bios_revision
[1] = bcode
[0x13];
2715 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "read BIOS %d.%d.\n",
2716 ha
->bios_revision
[1], ha
->bios_revision
[0]));
2718 case ROM_CODE_TYPE_FCODE
:
2719 /* Open Firmware standard for PCI (FCode). */
2720 ha
->fcode_revision
[0] = bcode
[0x12];
2721 ha
->fcode_revision
[1] = bcode
[0x13];
2722 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "read FCODE %d.%d.\n",
2723 ha
->fcode_revision
[1], ha
->fcode_revision
[0]));
2725 case ROM_CODE_TYPE_EFI
:
2726 /* Extensible Firmware Interface (EFI). */
2727 ha
->efi_revision
[0] = bcode
[0x12];
2728 ha
->efi_revision
[1] = bcode
[0x13];
2729 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "read EFI %d.%d.\n",
2730 ha
->efi_revision
[1], ha
->efi_revision
[0]));
2733 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unrecognized code "
2734 "type %x at pcids %x.\n", code_type
, pcids
));
2738 last_image
= bcode
[0x15] & BIT_7
;
2740 /* Locate next PCI expansion ROM. */
2741 pcihdr
+= ((bcode
[0x11] << 8) | bcode
[0x10]) * 512;
2742 } while (!last_image
);
2744 /* Read firmware image information. */
2745 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2748 qla24xx_read_flash_data(vha
, dcode
, ha
->flt_region_fw
+ 4, 4);
2749 for (i
= 0; i
< 4; i
++)
2750 dcode
[i
] = be32_to_cpu(dcode
[i
]);
2752 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
2753 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
2754 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
2756 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unrecognized fw "
2757 "revision at %x.\n", ha
->flt_region_fw
* 4));
2759 ha
->fw_revision
[0] = dcode
[0];
2760 ha
->fw_revision
[1] = dcode
[1];
2761 ha
->fw_revision
[2] = dcode
[2];
2762 ha
->fw_revision
[3] = dcode
[3];
2765 /* Check for golden firmware and get version if available */
2766 if (!IS_QLA81XX(ha
)) {
2767 /* Golden firmware is not present in non 81XX adapters */
2771 memset(ha
->gold_fw_version
, 0, sizeof(ha
->gold_fw_version
));
2773 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)dcode
,
2774 ha
->flt_region_gold_fw
<< 2, 32);
2776 if (dcode
[4] == 0xFFFFFFFF && dcode
[5] == 0xFFFFFFFF &&
2777 dcode
[6] == 0xFFFFFFFF && dcode
[7] == 0xFFFFFFFF) {
2778 DEBUG2(qla_printk(KERN_INFO
, ha
,
2779 "%s(%ld): Unrecognized golden fw at 0x%x.\n",
2780 __func__
, vha
->host_no
, ha
->flt_region_gold_fw
* 4));
2784 for (i
= 4; i
< 8; i
++)
2785 ha
->gold_fw_version
[i
-4] = be32_to_cpu(dcode
[i
]);
2791 qla2xxx_is_vpd_valid(uint8_t *pos
, uint8_t *end
)
2793 if (pos
>= end
|| *pos
!= 0x82)
2797 if (pos
>= end
|| *pos
!= 0x90)
2801 if (pos
>= end
|| *pos
!= 0x78)
2808 qla2xxx_get_vpd_field(scsi_qla_host_t
*vha
, char *key
, char *str
, size_t size
)
2810 struct qla_hw_data
*ha
= vha
->hw
;
2811 uint8_t *pos
= ha
->vpd
;
2812 uint8_t *end
= pos
+ ha
->vpd_size
;
2815 if (!IS_FWI2_CAPABLE(ha
) || !qla2xxx_is_vpd_valid(pos
, end
))
2818 while (pos
< end
&& *pos
!= 0x78) {
2819 len
= (*pos
== 0x82) ? pos
[1] : pos
[2];
2821 if (!strncmp(pos
, key
, strlen(key
)))
2824 if (*pos
!= 0x90 && *pos
!= 0x91)
2830 if (pos
< end
- len
&& *pos
!= 0x78)
2831 return snprintf(str
, size
, "%.*s", len
, pos
+ 3);
2837 qla24xx_read_fcp_prio_cfg(scsi_qla_host_t
*vha
)
2840 uint32_t fcp_prio_addr
;
2841 struct qla_hw_data
*ha
= vha
->hw
;
2843 if (!ha
->fcp_prio_cfg
) {
2844 ha
->fcp_prio_cfg
= vmalloc(FCP_PRIO_CFG_SIZE
);
2845 if (!ha
->fcp_prio_cfg
) {
2846 qla_printk(KERN_WARNING
, ha
,
2847 "Unable to allocate memory for fcp priority data "
2848 "(%x).\n", FCP_PRIO_CFG_SIZE
);
2849 return QLA_FUNCTION_FAILED
;
2852 memset(ha
->fcp_prio_cfg
, 0, FCP_PRIO_CFG_SIZE
);
2854 fcp_prio_addr
= ha
->flt_region_fcp_prio
;
2856 /* first read the fcp priority data header from flash */
2857 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)ha
->fcp_prio_cfg
,
2858 fcp_prio_addr
<< 2, FCP_PRIO_CFG_HDR_SIZE
);
2860 if (!qla24xx_fcp_prio_cfg_valid(ha
->fcp_prio_cfg
, 0))
2863 /* read remaining FCP CMD config data from flash */
2864 fcp_prio_addr
+= (FCP_PRIO_CFG_HDR_SIZE
>> 2);
2865 len
= ha
->fcp_prio_cfg
->num_entries
* FCP_PRIO_CFG_ENTRY_SIZE
;
2866 max_len
= FCP_PRIO_CFG_SIZE
- FCP_PRIO_CFG_HDR_SIZE
;
2868 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)&ha
->fcp_prio_cfg
->entry
[0],
2869 fcp_prio_addr
<< 2, (len
< max_len
? len
: max_len
));
2871 /* revalidate the entire FCP priority config data, including entries */
2872 if (!qla24xx_fcp_prio_cfg_valid(ha
->fcp_prio_cfg
, 1))
2875 ha
->flags
.fcp_prio_enabled
= 1;
2878 vfree(ha
->fcp_prio_cfg
);
2879 ha
->fcp_prio_cfg
= NULL
;
2880 return QLA_FUNCTION_FAILED
;