2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 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 #define OPTROM_BURST_SIZE 0x1000
427 #define OPTROM_BURST_DWORDS (OPTROM_BURST_SIZE / 4)
429 static inline uint32_t
430 flash_conf_addr(struct qla_hw_data
*ha
, uint32_t faddr
)
432 return ha
->flash_conf_off
| faddr
;
435 static inline uint32_t
436 flash_data_addr(struct qla_hw_data
*ha
, uint32_t faddr
)
438 return ha
->flash_data_off
| faddr
;
441 static inline uint32_t
442 nvram_conf_addr(struct qla_hw_data
*ha
, uint32_t naddr
)
444 return ha
->nvram_conf_off
| naddr
;
447 static inline uint32_t
448 nvram_data_addr(struct qla_hw_data
*ha
, uint32_t naddr
)
450 return ha
->nvram_data_off
| naddr
;
454 qla24xx_read_flash_dword(struct qla_hw_data
*ha
, uint32_t addr
)
458 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
460 WRT_REG_DWORD(®
->flash_addr
, addr
& ~FARX_DATA_FLAG
);
461 /* Wait for READ cycle to complete. */
464 (RD_REG_DWORD(®
->flash_addr
) & FARX_DATA_FLAG
) == 0 &&
465 rval
== QLA_SUCCESS
; cnt
--) {
469 rval
= QLA_FUNCTION_TIMEOUT
;
473 /* TODO: What happens if we time out? */
475 if (rval
== QLA_SUCCESS
)
476 data
= RD_REG_DWORD(®
->flash_data
);
482 qla24xx_read_flash_data(scsi_qla_host_t
*vha
, uint32_t *dwptr
, uint32_t faddr
,
486 struct qla_hw_data
*ha
= vha
->hw
;
488 /* Dword reads to flash. */
489 for (i
= 0; i
< dwords
; i
++, faddr
++)
490 dwptr
[i
] = cpu_to_le32(qla24xx_read_flash_dword(ha
,
491 flash_data_addr(ha
, faddr
)));
497 qla24xx_write_flash_dword(struct qla_hw_data
*ha
, uint32_t addr
, uint32_t data
)
501 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
503 WRT_REG_DWORD(®
->flash_data
, data
);
504 RD_REG_DWORD(®
->flash_data
); /* PCI Posting. */
505 WRT_REG_DWORD(®
->flash_addr
, addr
| FARX_DATA_FLAG
);
506 /* Wait for Write cycle to complete. */
508 for (cnt
= 500000; (RD_REG_DWORD(®
->flash_addr
) & FARX_DATA_FLAG
) &&
509 rval
== QLA_SUCCESS
; cnt
--) {
513 rval
= QLA_FUNCTION_TIMEOUT
;
520 qla24xx_get_flash_manufacturer(struct qla_hw_data
*ha
, uint8_t *man_id
,
525 ids
= qla24xx_read_flash_dword(ha
, flash_conf_addr(ha
, 0x03ab));
527 *flash_id
= MSB(ids
);
529 /* Check if man_id and flash_id are valid. */
530 if (ids
!= 0xDEADDEAD && (*man_id
== 0 || *flash_id
== 0)) {
531 /* Read information using 0x9f opcode
532 * Device ID, Mfg ID would be read in the format:
533 * <Ext Dev Info><Device ID Part2><Device ID Part 1><Mfg ID>
534 * Example: ATMEL 0x00 01 45 1F
535 * Extract MFG and Dev ID from last two bytes.
537 ids
= qla24xx_read_flash_dword(ha
, flash_conf_addr(ha
, 0x009f));
539 *flash_id
= MSB(ids
);
544 qla2xxx_find_flt_start(scsi_qla_host_t
*vha
, uint32_t *start
)
546 const char *loc
, *locations
[] = { "DEF", "PCI" };
547 uint32_t pcihdr
, pcids
;
549 uint8_t *buf
, *bcode
, last_image
;
550 uint16_t cnt
, chksum
, *wptr
;
551 struct qla_flt_location
*fltl
;
552 struct qla_hw_data
*ha
= vha
->hw
;
553 struct req_que
*req
= ha
->req_q_map
[0];
556 * FLT-location structure resides after the last PCI region.
559 /* Begin with sane defaults. */
562 if (IS_QLA24XX_TYPE(ha
))
563 *start
= FA_FLASH_LAYOUT_ADDR_24
;
564 else if (IS_QLA25XX(ha
))
565 *start
= FA_FLASH_LAYOUT_ADDR
;
566 else if (IS_QLA81XX(ha
))
567 *start
= FA_FLASH_LAYOUT_ADDR_81
;
568 /* Begin with first PCI expansion ROM header. */
569 buf
= (uint8_t *)req
->ring
;
570 dcode
= (uint32_t *)req
->ring
;
574 /* Verify PCI expansion ROM header. */
575 qla24xx_read_flash_data(vha
, dcode
, pcihdr
>> 2, 0x20);
576 bcode
= buf
+ (pcihdr
% 4);
577 if (bcode
[0x0] != 0x55 || bcode
[0x1] != 0xaa)
580 /* Locate PCI data structure. */
581 pcids
= pcihdr
+ ((bcode
[0x19] << 8) | bcode
[0x18]);
582 qla24xx_read_flash_data(vha
, dcode
, pcids
>> 2, 0x20);
583 bcode
= buf
+ (pcihdr
% 4);
585 /* Validate signature of PCI data structure. */
586 if (bcode
[0x0] != 'P' || bcode
[0x1] != 'C' ||
587 bcode
[0x2] != 'I' || bcode
[0x3] != 'R')
590 last_image
= bcode
[0x15] & BIT_7
;
592 /* Locate next PCI expansion ROM. */
593 pcihdr
+= ((bcode
[0x11] << 8) | bcode
[0x10]) * 512;
594 } while (!last_image
);
596 /* Now verify FLT-location structure. */
597 fltl
= (struct qla_flt_location
*)req
->ring
;
598 qla24xx_read_flash_data(vha
, dcode
, pcihdr
>> 2,
599 sizeof(struct qla_flt_location
) >> 2);
600 if (fltl
->sig
[0] != 'Q' || fltl
->sig
[1] != 'F' ||
601 fltl
->sig
[2] != 'L' || fltl
->sig
[3] != 'T')
604 wptr
= (uint16_t *)req
->ring
;
605 cnt
= sizeof(struct qla_flt_location
) >> 1;
606 for (chksum
= 0; cnt
; cnt
--)
607 chksum
+= le16_to_cpu(*wptr
++);
609 qla_printk(KERN_ERR
, ha
,
610 "Inconsistent FLTL detected: checksum=0x%x.\n", chksum
);
611 qla2x00_dump_buffer(buf
, sizeof(struct qla_flt_location
));
612 return QLA_FUNCTION_FAILED
;
615 /* Good data. Use specified location. */
617 *start
= (le16_to_cpu(fltl
->start_hi
) << 16 |
618 le16_to_cpu(fltl
->start_lo
)) >> 2;
620 DEBUG2(qla_printk(KERN_DEBUG
, ha
, "FLTL[%s] = 0x%x.\n", loc
, *start
));
625 qla2xxx_get_flt_info(scsi_qla_host_t
*vha
, uint32_t flt_addr
)
627 const char *loc
, *locations
[] = { "DEF", "FLT" };
628 const uint32_t def_fw
[] =
629 { FA_RISC_CODE_ADDR
, FA_RISC_CODE_ADDR
, FA_RISC_CODE_ADDR_81
};
630 const uint32_t def_boot
[] =
631 { FA_BOOT_CODE_ADDR
, FA_BOOT_CODE_ADDR
, FA_BOOT_CODE_ADDR_81
};
632 const uint32_t def_vpd_nvram
[] =
633 { FA_VPD_NVRAM_ADDR
, FA_VPD_NVRAM_ADDR
, FA_VPD_NVRAM_ADDR_81
};
634 const uint32_t def_vpd0
[] =
635 { 0, 0, FA_VPD0_ADDR_81
};
636 const uint32_t def_vpd1
[] =
637 { 0, 0, FA_VPD1_ADDR_81
};
638 const uint32_t def_nvram0
[] =
639 { 0, 0, FA_NVRAM0_ADDR_81
};
640 const uint32_t def_nvram1
[] =
641 { 0, 0, FA_NVRAM1_ADDR_81
};
642 const uint32_t def_fdt
[] =
643 { FA_FLASH_DESCR_ADDR_24
, FA_FLASH_DESCR_ADDR
,
644 FA_FLASH_DESCR_ADDR_81
};
645 const uint32_t def_npiv_conf0
[] =
646 { FA_NPIV_CONF0_ADDR_24
, FA_NPIV_CONF0_ADDR
,
647 FA_NPIV_CONF0_ADDR_81
};
648 const uint32_t def_npiv_conf1
[] =
649 { FA_NPIV_CONF1_ADDR_24
, FA_NPIV_CONF1_ADDR
,
650 FA_NPIV_CONF1_ADDR_81
};
653 uint16_t cnt
, chksum
;
655 struct qla_flt_header
*flt
;
656 struct qla_flt_region
*region
;
657 struct qla_hw_data
*ha
= vha
->hw
;
658 struct req_que
*req
= ha
->req_q_map
[0];
660 ha
->flt_region_flt
= flt_addr
;
661 wptr
= (uint16_t *)req
->ring
;
662 flt
= (struct qla_flt_header
*)req
->ring
;
663 region
= (struct qla_flt_region
*)&flt
[1];
664 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)req
->ring
,
665 flt_addr
<< 2, OPTROM_BURST_SIZE
);
666 if (*wptr
== __constant_cpu_to_le16(0xffff))
668 if (flt
->version
!= __constant_cpu_to_le16(1)) {
669 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unsupported FLT detected: "
670 "version=0x%x length=0x%x checksum=0x%x.\n",
671 le16_to_cpu(flt
->version
), le16_to_cpu(flt
->length
),
672 le16_to_cpu(flt
->checksum
)));
676 cnt
= (sizeof(struct qla_flt_header
) + le16_to_cpu(flt
->length
)) >> 1;
677 for (chksum
= 0; cnt
; cnt
--)
678 chksum
+= le16_to_cpu(*wptr
++);
680 DEBUG2(qla_printk(KERN_INFO
, ha
, "Inconsistent FLT detected: "
681 "version=0x%x length=0x%x checksum=0x%x.\n",
682 le16_to_cpu(flt
->version
), le16_to_cpu(flt
->length
),
688 cnt
= le16_to_cpu(flt
->length
) / sizeof(struct qla_flt_region
);
689 for ( ; cnt
; cnt
--, region
++) {
690 /* Store addresses as DWORD offsets. */
691 start
= le32_to_cpu(region
->start
) >> 2;
693 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "FLT[%02x]: start=0x%x "
694 "end=0x%x size=0x%x.\n", le32_to_cpu(region
->code
), start
,
695 le32_to_cpu(region
->end
) >> 2, le32_to_cpu(region
->size
)));
697 switch (le32_to_cpu(region
->code
) & 0xff) {
699 ha
->flt_region_fw
= start
;
701 case FLT_REG_BOOT_CODE
:
702 ha
->flt_region_boot
= start
;
705 ha
->flt_region_vpd_nvram
= start
;
707 ha
->flt_region_vpd
= start
;
710 if (!ha
->flags
.port0
)
711 ha
->flt_region_vpd
= start
;
713 case FLT_REG_NVRAM_0
:
715 ha
->flt_region_nvram
= start
;
717 case FLT_REG_NVRAM_1
:
718 if (!ha
->flags
.port0
)
719 ha
->flt_region_nvram
= start
;
722 ha
->flt_region_fdt
= start
;
724 case FLT_REG_NPIV_CONF_0
:
726 ha
->flt_region_npiv_conf
= start
;
728 case FLT_REG_NPIV_CONF_1
:
729 if (!ha
->flags
.port0
)
730 ha
->flt_region_npiv_conf
= start
;
732 case FLT_REG_GOLD_FW
:
733 ha
->flt_region_gold_fw
= start
;
740 /* Use hardcoded defaults. */
743 if (IS_QLA24XX_TYPE(ha
))
745 else if (IS_QLA25XX(ha
))
747 else if (IS_QLA81XX(ha
))
749 ha
->flt_region_fw
= def_fw
[def
];
750 ha
->flt_region_boot
= def_boot
[def
];
751 ha
->flt_region_vpd_nvram
= def_vpd_nvram
[def
];
752 ha
->flt_region_vpd
= ha
->flags
.port0
?
753 def_vpd0
[def
]: def_vpd1
[def
];
754 ha
->flt_region_nvram
= ha
->flags
.port0
?
755 def_nvram0
[def
]: def_nvram1
[def
];
756 ha
->flt_region_fdt
= def_fdt
[def
];
757 ha
->flt_region_npiv_conf
= ha
->flags
.port0
?
758 def_npiv_conf0
[def
]: def_npiv_conf1
[def
];
760 DEBUG2(qla_printk(KERN_DEBUG
, ha
, "FLT[%s]: boot=0x%x fw=0x%x "
761 "vpd_nvram=0x%x vpd=0x%x nvram=0x%x fdt=0x%x flt=0x%x "
762 "npiv=0x%x.\n", loc
, ha
->flt_region_boot
, ha
->flt_region_fw
,
763 ha
->flt_region_vpd_nvram
, ha
->flt_region_vpd
, ha
->flt_region_nvram
,
764 ha
->flt_region_fdt
, ha
->flt_region_flt
, ha
->flt_region_npiv_conf
));
768 qla2xxx_get_fdt_info(scsi_qla_host_t
*vha
)
770 #define FLASH_BLK_SIZE_4K 0x1000
771 #define FLASH_BLK_SIZE_32K 0x8000
772 #define FLASH_BLK_SIZE_64K 0x10000
773 const char *loc
, *locations
[] = { "MID", "FDT" };
774 uint16_t cnt
, chksum
;
776 struct qla_fdt_layout
*fdt
;
777 uint8_t man_id
, flash_id
;
779 struct qla_hw_data
*ha
= vha
->hw
;
780 struct req_que
*req
= ha
->req_q_map
[0];
782 wptr
= (uint16_t *)req
->ring
;
783 fdt
= (struct qla_fdt_layout
*)req
->ring
;
784 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)req
->ring
,
785 ha
->flt_region_fdt
<< 2, OPTROM_BURST_SIZE
);
786 if (*wptr
== __constant_cpu_to_le16(0xffff))
788 if (fdt
->sig
[0] != 'Q' || fdt
->sig
[1] != 'L' || fdt
->sig
[2] != 'I' ||
792 for (cnt
= 0, chksum
= 0; cnt
< sizeof(struct qla_fdt_layout
) >> 1;
794 chksum
+= le16_to_cpu(*wptr
++);
796 DEBUG2(qla_printk(KERN_INFO
, ha
, "Inconsistent FDT detected: "
797 "checksum=0x%x id=%c version=0x%x.\n", chksum
, fdt
->sig
[0],
798 le16_to_cpu(fdt
->version
)));
799 DEBUG9(qla2x00_dump_buffer((uint8_t *)fdt
, sizeof(*fdt
)));
804 mid
= le16_to_cpu(fdt
->man_id
);
805 fid
= le16_to_cpu(fdt
->id
);
806 ha
->fdt_wrt_disable
= fdt
->wrt_disable_bits
;
807 ha
->fdt_erase_cmd
= flash_conf_addr(ha
, 0x0300 | fdt
->erase_cmd
);
808 ha
->fdt_block_size
= le32_to_cpu(fdt
->block_size
);
809 if (fdt
->unprotect_sec_cmd
) {
810 ha
->fdt_unprotect_sec_cmd
= flash_conf_addr(ha
, 0x0300 |
811 fdt
->unprotect_sec_cmd
);
812 ha
->fdt_protect_sec_cmd
= fdt
->protect_sec_cmd
?
813 flash_conf_addr(ha
, 0x0300 | fdt
->protect_sec_cmd
):
814 flash_conf_addr(ha
, 0x0336);
819 qla24xx_get_flash_manufacturer(ha
, &man_id
, &flash_id
);
822 ha
->fdt_wrt_disable
= 0x9c;
823 ha
->fdt_erase_cmd
= flash_conf_addr(ha
, 0x03d8);
825 case 0xbf: /* STT flash. */
826 if (flash_id
== 0x8e)
827 ha
->fdt_block_size
= FLASH_BLK_SIZE_64K
;
829 ha
->fdt_block_size
= FLASH_BLK_SIZE_32K
;
831 if (flash_id
== 0x80)
832 ha
->fdt_erase_cmd
= flash_conf_addr(ha
, 0x0352);
834 case 0x13: /* ST M25P80. */
835 ha
->fdt_block_size
= FLASH_BLK_SIZE_64K
;
837 case 0x1f: /* Atmel 26DF081A. */
838 ha
->fdt_block_size
= FLASH_BLK_SIZE_4K
;
839 ha
->fdt_erase_cmd
= flash_conf_addr(ha
, 0x0320);
840 ha
->fdt_unprotect_sec_cmd
= flash_conf_addr(ha
, 0x0339);
841 ha
->fdt_protect_sec_cmd
= flash_conf_addr(ha
, 0x0336);
844 /* Default to 64 kb sector size. */
845 ha
->fdt_block_size
= FLASH_BLK_SIZE_64K
;
849 DEBUG2(qla_printk(KERN_DEBUG
, ha
, "FDT[%s]: (0x%x/0x%x) erase=0x%x "
850 "pro=%x upro=%x wrtd=0x%x blk=0x%x.\n", loc
, mid
, fid
,
851 ha
->fdt_erase_cmd
, ha
->fdt_protect_sec_cmd
,
852 ha
->fdt_unprotect_sec_cmd
, ha
->fdt_wrt_disable
,
853 ha
->fdt_block_size
));
857 qla2xxx_get_flash_info(scsi_qla_host_t
*vha
)
861 struct qla_hw_data
*ha
= vha
->hw
;
863 if (!IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) && !IS_QLA81XX(ha
))
866 ret
= qla2xxx_find_flt_start(vha
, &flt_addr
);
867 if (ret
!= QLA_SUCCESS
)
870 qla2xxx_get_flt_info(vha
, flt_addr
);
871 qla2xxx_get_fdt_info(vha
);
877 qla2xxx_flash_npiv_conf(scsi_qla_host_t
*vha
)
879 #define NPIV_CONFIG_SIZE (16*1024)
882 uint16_t cnt
, chksum
;
884 struct qla_npiv_header hdr
;
885 struct qla_npiv_entry
*entry
;
886 struct qla_hw_data
*ha
= vha
->hw
;
888 if (!IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) && !IS_QLA81XX(ha
))
891 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)&hdr
,
892 ha
->flt_region_npiv_conf
<< 2, sizeof(struct qla_npiv_header
));
893 if (hdr
.version
== __constant_cpu_to_le16(0xffff))
895 if (hdr
.version
!= __constant_cpu_to_le16(1)) {
896 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unsupported NPIV-Config "
897 "detected: version=0x%x entries=0x%x checksum=0x%x.\n",
898 le16_to_cpu(hdr
.version
), le16_to_cpu(hdr
.entries
),
899 le16_to_cpu(hdr
.checksum
)));
903 data
= kmalloc(NPIV_CONFIG_SIZE
, GFP_KERNEL
);
905 DEBUG2(qla_printk(KERN_INFO
, ha
, "NPIV-Config: Unable to "
906 "allocate memory.\n"));
910 ha
->isp_ops
->read_optrom(vha
, (uint8_t *)data
,
911 ha
->flt_region_npiv_conf
<< 2, NPIV_CONFIG_SIZE
);
913 cnt
= (sizeof(struct qla_npiv_header
) + le16_to_cpu(hdr
.entries
) *
914 sizeof(struct qla_npiv_entry
)) >> 1;
915 for (wptr
= data
, chksum
= 0; cnt
; cnt
--)
916 chksum
+= le16_to_cpu(*wptr
++);
918 DEBUG2(qla_printk(KERN_INFO
, ha
, "Inconsistent NPIV-Config "
919 "detected: version=0x%x entries=0x%x checksum=0x%x.\n",
920 le16_to_cpu(hdr
.version
), le16_to_cpu(hdr
.entries
),
925 entry
= data
+ sizeof(struct qla_npiv_header
);
926 cnt
= le16_to_cpu(hdr
.entries
);
927 for (i
= 0; cnt
; cnt
--, entry
++, i
++) {
929 struct fc_vport_identifiers vid
;
930 struct fc_vport
*vport
;
932 memcpy(&ha
->npiv_info
[i
], entry
, sizeof(struct qla_npiv_entry
));
934 flags
= le16_to_cpu(entry
->flags
);
937 if ((flags
& BIT_0
) == 0)
940 memset(&vid
, 0, sizeof(vid
));
941 vid
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
942 vid
.vport_type
= FC_PORTTYPE_NPIV
;
944 vid
.port_name
= wwn_to_u64(entry
->port_name
);
945 vid
.node_name
= wwn_to_u64(entry
->node_name
);
947 DEBUG2(qla_printk(KERN_INFO
, ha
, "NPIV[%02x]: wwpn=%llx "
948 "wwnn=%llx vf_id=0x%x Q_qos=0x%x F_qos=0x%x.\n", cnt
,
949 (unsigned long long)vid
.port_name
,
950 (unsigned long long)vid
.node_name
,
951 le16_to_cpu(entry
->vf_id
),
952 entry
->q_qos
, entry
->f_qos
));
954 if (i
< QLA_PRECONFIG_VPORTS
) {
955 vport
= fc_vport_create(vha
->host
, 0, &vid
);
957 qla_printk(KERN_INFO
, ha
,
958 "NPIV-Config: Failed to create vport [%02x]: "
959 "wwpn=%llx wwnn=%llx.\n", cnt
,
960 (unsigned long long)vid
.port_name
,
961 (unsigned long long)vid
.node_name
);
969 qla24xx_unprotect_flash(scsi_qla_host_t
*vha
)
971 struct qla_hw_data
*ha
= vha
->hw
;
972 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
974 if (ha
->flags
.fac_supported
)
975 return qla81xx_fac_do_write_enable(vha
, 1);
977 /* Enable flash write. */
978 WRT_REG_DWORD(®
->ctrl_status
,
979 RD_REG_DWORD(®
->ctrl_status
) | CSRX_FLASH_ENABLE
);
980 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
982 if (!ha
->fdt_wrt_disable
)
985 /* Disable flash write-protection, first clear SR protection bit */
986 qla24xx_write_flash_dword(ha
, flash_conf_addr(ha
, 0x101), 0);
987 /* Then write zero again to clear remaining SR bits.*/
988 qla24xx_write_flash_dword(ha
, flash_conf_addr(ha
, 0x101), 0);
994 qla24xx_protect_flash(scsi_qla_host_t
*vha
)
997 struct qla_hw_data
*ha
= vha
->hw
;
998 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1000 if (ha
->flags
.fac_supported
)
1001 return qla81xx_fac_do_write_enable(vha
, 0);
1003 if (!ha
->fdt_wrt_disable
)
1004 goto skip_wrt_protect
;
1006 /* Enable flash write-protection and wait for completion. */
1007 qla24xx_write_flash_dword(ha
, flash_conf_addr(ha
, 0x101),
1008 ha
->fdt_wrt_disable
);
1009 for (cnt
= 300; cnt
&&
1010 qla24xx_read_flash_dword(ha
, flash_conf_addr(ha
, 0x005)) & BIT_0
;
1016 /* Disable flash write. */
1017 WRT_REG_DWORD(®
->ctrl_status
,
1018 RD_REG_DWORD(®
->ctrl_status
) & ~CSRX_FLASH_ENABLE
);
1019 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
1025 qla24xx_erase_sector(scsi_qla_host_t
*vha
, uint32_t fdata
)
1027 struct qla_hw_data
*ha
= vha
->hw
;
1028 uint32_t start
, finish
;
1030 if (ha
->flags
.fac_supported
) {
1032 finish
= start
+ (ha
->fdt_block_size
>> 2) - 1;
1033 return qla81xx_fac_erase_sector(vha
, flash_data_addr(ha
,
1034 start
), flash_data_addr(ha
, finish
));
1037 return qla24xx_write_flash_dword(ha
, ha
->fdt_erase_cmd
,
1038 (fdata
& 0xff00) | ((fdata
<< 16) & 0xff0000) |
1039 ((fdata
>> 16) & 0xff));
1043 qla24xx_write_flash_data(scsi_qla_host_t
*vha
, uint32_t *dwptr
, uint32_t faddr
,
1048 uint32_t sec_mask
, rest_addr
;
1050 dma_addr_t optrom_dma
;
1051 void *optrom
= NULL
;
1052 struct qla_hw_data
*ha
= vha
->hw
;
1054 /* Prepare burst-capable write on supported ISPs. */
1055 if ((IS_QLA25XX(ha
) || IS_QLA81XX(ha
)) && !(faddr
& 0xfff) &&
1056 dwords
> OPTROM_BURST_DWORDS
) {
1057 optrom
= dma_alloc_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
,
1058 &optrom_dma
, GFP_KERNEL
);
1060 qla_printk(KERN_DEBUG
, ha
,
1061 "Unable to allocate memory for optrom burst write "
1062 "(%x KB).\n", OPTROM_BURST_SIZE
/ 1024);
1066 rest_addr
= (ha
->fdt_block_size
>> 2) - 1;
1067 sec_mask
= ~rest_addr
;
1069 ret
= qla24xx_unprotect_flash(vha
);
1070 if (ret
!= QLA_SUCCESS
) {
1071 qla_printk(KERN_WARNING
, ha
,
1072 "Unable to unprotect flash for update.\n");
1076 for (liter
= 0; liter
< dwords
; liter
++, faddr
++, dwptr
++) {
1077 fdata
= (faddr
& sec_mask
) << 2;
1079 /* Are we at the beginning of a sector? */
1080 if ((faddr
& rest_addr
) == 0) {
1081 /* Do sector unprotect. */
1082 if (ha
->fdt_unprotect_sec_cmd
)
1083 qla24xx_write_flash_dword(ha
,
1084 ha
->fdt_unprotect_sec_cmd
,
1085 (fdata
& 0xff00) | ((fdata
<< 16) &
1086 0xff0000) | ((fdata
>> 16) & 0xff));
1087 ret
= qla24xx_erase_sector(vha
, fdata
);
1088 if (ret
!= QLA_SUCCESS
) {
1089 DEBUG9(qla_printk(KERN_WARNING
, ha
,
1090 "Unable to erase sector: address=%x.\n",
1096 /* Go with burst-write. */
1097 if (optrom
&& (liter
+ OPTROM_BURST_DWORDS
) <= dwords
) {
1098 /* Copy data to DMA'ble buffer. */
1099 memcpy(optrom
, dwptr
, OPTROM_BURST_SIZE
);
1101 ret
= qla2x00_load_ram(vha
, optrom_dma
,
1102 flash_data_addr(ha
, faddr
),
1103 OPTROM_BURST_DWORDS
);
1104 if (ret
!= QLA_SUCCESS
) {
1105 qla_printk(KERN_WARNING
, ha
,
1106 "Unable to burst-write optrom segment "
1107 "(%x/%x/%llx).\n", ret
,
1108 flash_data_addr(ha
, faddr
),
1109 (unsigned long long)optrom_dma
);
1110 qla_printk(KERN_WARNING
, ha
,
1111 "Reverting to slow-write.\n");
1113 dma_free_coherent(&ha
->pdev
->dev
,
1114 OPTROM_BURST_SIZE
, optrom
, optrom_dma
);
1117 liter
+= OPTROM_BURST_DWORDS
- 1;
1118 faddr
+= OPTROM_BURST_DWORDS
- 1;
1119 dwptr
+= OPTROM_BURST_DWORDS
- 1;
1124 ret
= qla24xx_write_flash_dword(ha
,
1125 flash_data_addr(ha
, faddr
), cpu_to_le32(*dwptr
));
1126 if (ret
!= QLA_SUCCESS
) {
1127 DEBUG9(printk("%s(%ld) Unable to program flash "
1128 "address=%x data=%x.\n", __func__
,
1129 vha
->host_no
, faddr
, *dwptr
));
1133 /* Do sector protect. */
1134 if (ha
->fdt_unprotect_sec_cmd
&&
1135 ((faddr
& rest_addr
) == rest_addr
))
1136 qla24xx_write_flash_dword(ha
,
1137 ha
->fdt_protect_sec_cmd
,
1138 (fdata
& 0xff00) | ((fdata
<< 16) &
1139 0xff0000) | ((fdata
>> 16) & 0xff));
1142 ret
= qla24xx_protect_flash(vha
);
1143 if (ret
!= QLA_SUCCESS
)
1144 qla_printk(KERN_WARNING
, ha
,
1145 "Unable to protect flash after update.\n");
1148 dma_free_coherent(&ha
->pdev
->dev
,
1149 OPTROM_BURST_SIZE
, optrom
, optrom_dma
);
1155 qla2x00_read_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1160 struct qla_hw_data
*ha
= vha
->hw
;
1162 /* Word reads to NVRAM via registers. */
1163 wptr
= (uint16_t *)buf
;
1164 qla2x00_lock_nvram_access(ha
);
1165 for (i
= 0; i
< bytes
>> 1; i
++, naddr
++)
1166 wptr
[i
] = cpu_to_le16(qla2x00_get_nvram_word(ha
,
1168 qla2x00_unlock_nvram_access(ha
);
1174 qla24xx_read_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1179 struct qla_hw_data
*ha
= vha
->hw
;
1181 /* Dword reads to flash. */
1182 dwptr
= (uint32_t *)buf
;
1183 for (i
= 0; i
< bytes
>> 2; i
++, naddr
++)
1184 dwptr
[i
] = cpu_to_le32(qla24xx_read_flash_dword(ha
,
1185 nvram_data_addr(ha
, naddr
)));
1191 qla2x00_write_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1197 unsigned long flags
;
1198 struct qla_hw_data
*ha
= vha
->hw
;
1202 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1203 qla2x00_lock_nvram_access(ha
);
1205 /* Disable NVRAM write-protection. */
1206 stat
= qla2x00_clear_nvram_protection(ha
);
1208 wptr
= (uint16_t *)buf
;
1209 for (i
= 0; i
< bytes
>> 1; i
++, naddr
++) {
1210 qla2x00_write_nvram_word(ha
, naddr
,
1211 cpu_to_le16(*wptr
));
1215 /* Enable NVRAM write-protection. */
1216 qla2x00_set_nvram_protection(ha
, stat
);
1218 qla2x00_unlock_nvram_access(ha
);
1219 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1225 qla24xx_write_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1231 struct qla_hw_data
*ha
= vha
->hw
;
1232 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1236 /* Enable flash write. */
1237 WRT_REG_DWORD(®
->ctrl_status
,
1238 RD_REG_DWORD(®
->ctrl_status
) | CSRX_FLASH_ENABLE
);
1239 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
1241 /* Disable NVRAM write-protection. */
1242 qla24xx_write_flash_dword(ha
, nvram_conf_addr(ha
, 0x101), 0);
1243 qla24xx_write_flash_dword(ha
, nvram_conf_addr(ha
, 0x101), 0);
1245 /* Dword writes to flash. */
1246 dwptr
= (uint32_t *)buf
;
1247 for (i
= 0; i
< bytes
>> 2; i
++, naddr
++, dwptr
++) {
1248 ret
= qla24xx_write_flash_dword(ha
,
1249 nvram_data_addr(ha
, naddr
), cpu_to_le32(*dwptr
));
1250 if (ret
!= QLA_SUCCESS
) {
1251 DEBUG9(qla_printk(KERN_WARNING
, ha
,
1252 "Unable to program nvram address=%x data=%x.\n",
1258 /* Enable NVRAM write-protection. */
1259 qla24xx_write_flash_dword(ha
, nvram_conf_addr(ha
, 0x101), 0x8c);
1261 /* Disable flash write. */
1262 WRT_REG_DWORD(®
->ctrl_status
,
1263 RD_REG_DWORD(®
->ctrl_status
) & ~CSRX_FLASH_ENABLE
);
1264 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
1270 qla25xx_read_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1275 struct qla_hw_data
*ha
= vha
->hw
;
1277 /* Dword reads to flash. */
1278 dwptr
= (uint32_t *)buf
;
1279 for (i
= 0; i
< bytes
>> 2; i
++, naddr
++)
1280 dwptr
[i
] = cpu_to_le32(qla24xx_read_flash_dword(ha
,
1281 flash_data_addr(ha
, ha
->flt_region_vpd_nvram
| naddr
)));
1287 qla25xx_write_nvram_data(scsi_qla_host_t
*vha
, uint8_t *buf
, uint32_t naddr
,
1290 struct qla_hw_data
*ha
= vha
->hw
;
1291 #define RMW_BUFFER_SIZE (64 * 1024)
1294 dbuf
= vmalloc(RMW_BUFFER_SIZE
);
1296 return QLA_MEMORY_ALLOC_FAILED
;
1297 ha
->isp_ops
->read_optrom(vha
, dbuf
, ha
->flt_region_vpd_nvram
<< 2,
1299 memcpy(dbuf
+ (naddr
<< 2), buf
, bytes
);
1300 ha
->isp_ops
->write_optrom(vha
, dbuf
, ha
->flt_region_vpd_nvram
<< 2,
1308 qla2x00_flip_colors(struct qla_hw_data
*ha
, uint16_t *pflags
)
1310 if (IS_QLA2322(ha
)) {
1311 /* Flip all colors. */
1312 if (ha
->beacon_color_state
== QLA_LED_ALL_ON
) {
1314 ha
->beacon_color_state
= 0;
1315 *pflags
= GPIO_LED_ALL_OFF
;
1318 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1319 *pflags
= GPIO_LED_RGA_ON
;
1322 /* Flip green led only. */
1323 if (ha
->beacon_color_state
== QLA_LED_GRN_ON
) {
1325 ha
->beacon_color_state
= 0;
1326 *pflags
= GPIO_LED_GREEN_OFF_AMBER_OFF
;
1329 ha
->beacon_color_state
= QLA_LED_GRN_ON
;
1330 *pflags
= GPIO_LED_GREEN_ON_AMBER_OFF
;
1335 #define PIO_REG(h, r) ((h)->pio_address + offsetof(struct device_reg_2xxx, r))
1338 qla2x00_beacon_blink(struct scsi_qla_host
*vha
)
1340 uint16_t gpio_enable
;
1342 uint16_t led_color
= 0;
1343 unsigned long flags
;
1344 struct qla_hw_data
*ha
= vha
->hw
;
1345 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1347 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1349 /* Save the Original GPIOE. */
1350 if (ha
->pio_address
) {
1351 gpio_enable
= RD_REG_WORD_PIO(PIO_REG(ha
, gpioe
));
1352 gpio_data
= RD_REG_WORD_PIO(PIO_REG(ha
, gpiod
));
1354 gpio_enable
= RD_REG_WORD(®
->gpioe
);
1355 gpio_data
= RD_REG_WORD(®
->gpiod
);
1358 /* Set the modified gpio_enable values */
1359 gpio_enable
|= GPIO_LED_MASK
;
1361 if (ha
->pio_address
) {
1362 WRT_REG_WORD_PIO(PIO_REG(ha
, gpioe
), gpio_enable
);
1364 WRT_REG_WORD(®
->gpioe
, gpio_enable
);
1365 RD_REG_WORD(®
->gpioe
);
1368 qla2x00_flip_colors(ha
, &led_color
);
1370 /* Clear out any previously set LED color. */
1371 gpio_data
&= ~GPIO_LED_MASK
;
1373 /* Set the new input LED color to GPIOD. */
1374 gpio_data
|= led_color
;
1376 /* Set the modified gpio_data values */
1377 if (ha
->pio_address
) {
1378 WRT_REG_WORD_PIO(PIO_REG(ha
, gpiod
), gpio_data
);
1380 WRT_REG_WORD(®
->gpiod
, gpio_data
);
1381 RD_REG_WORD(®
->gpiod
);
1384 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1388 qla2x00_beacon_on(struct scsi_qla_host
*vha
)
1390 uint16_t gpio_enable
;
1392 unsigned long flags
;
1393 struct qla_hw_data
*ha
= vha
->hw
;
1394 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1396 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1397 ha
->fw_options
[1] |= FO1_DISABLE_GPIO6_7
;
1399 if (qla2x00_set_fw_options(vha
, ha
->fw_options
) != QLA_SUCCESS
) {
1400 qla_printk(KERN_WARNING
, ha
,
1401 "Unable to update fw options (beacon on).\n");
1402 return QLA_FUNCTION_FAILED
;
1405 /* Turn off LEDs. */
1406 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1407 if (ha
->pio_address
) {
1408 gpio_enable
= RD_REG_WORD_PIO(PIO_REG(ha
, gpioe
));
1409 gpio_data
= RD_REG_WORD_PIO(PIO_REG(ha
, gpiod
));
1411 gpio_enable
= RD_REG_WORD(®
->gpioe
);
1412 gpio_data
= RD_REG_WORD(®
->gpiod
);
1414 gpio_enable
|= GPIO_LED_MASK
;
1416 /* Set the modified gpio_enable values. */
1417 if (ha
->pio_address
) {
1418 WRT_REG_WORD_PIO(PIO_REG(ha
, gpioe
), gpio_enable
);
1420 WRT_REG_WORD(®
->gpioe
, gpio_enable
);
1421 RD_REG_WORD(®
->gpioe
);
1424 /* Clear out previously set LED colour. */
1425 gpio_data
&= ~GPIO_LED_MASK
;
1426 if (ha
->pio_address
) {
1427 WRT_REG_WORD_PIO(PIO_REG(ha
, gpiod
), gpio_data
);
1429 WRT_REG_WORD(®
->gpiod
, gpio_data
);
1430 RD_REG_WORD(®
->gpiod
);
1432 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1435 * Let the per HBA timer kick off the blinking process based on
1436 * the following flags. No need to do anything else now.
1438 ha
->beacon_blink_led
= 1;
1439 ha
->beacon_color_state
= 0;
1445 qla2x00_beacon_off(struct scsi_qla_host
*vha
)
1447 int rval
= QLA_SUCCESS
;
1448 struct qla_hw_data
*ha
= vha
->hw
;
1450 ha
->beacon_blink_led
= 0;
1452 /* Set the on flag so when it gets flipped it will be off. */
1454 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1456 ha
->beacon_color_state
= QLA_LED_GRN_ON
;
1458 ha
->isp_ops
->beacon_blink(vha
); /* This turns green LED off */
1460 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1461 ha
->fw_options
[1] &= ~FO1_DISABLE_GPIO6_7
;
1463 rval
= qla2x00_set_fw_options(vha
, ha
->fw_options
);
1464 if (rval
!= QLA_SUCCESS
)
1465 qla_printk(KERN_WARNING
, ha
,
1466 "Unable to update fw options (beacon off).\n");
1472 qla24xx_flip_colors(struct qla_hw_data
*ha
, uint16_t *pflags
)
1474 /* Flip all colors. */
1475 if (ha
->beacon_color_state
== QLA_LED_ALL_ON
) {
1477 ha
->beacon_color_state
= 0;
1481 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1482 *pflags
= GPDX_LED_YELLOW_ON
| GPDX_LED_AMBER_ON
;
1487 qla24xx_beacon_blink(struct scsi_qla_host
*vha
)
1489 uint16_t led_color
= 0;
1491 unsigned long flags
;
1492 struct qla_hw_data
*ha
= vha
->hw
;
1493 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1495 /* Save the Original GPIOD. */
1496 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1497 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1499 /* Enable the gpio_data reg for update. */
1500 gpio_data
|= GPDX_LED_UPDATE_MASK
;
1502 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1503 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1505 /* Set the color bits. */
1506 qla24xx_flip_colors(ha
, &led_color
);
1508 /* Clear out any previously set LED color. */
1509 gpio_data
&= ~GPDX_LED_COLOR_MASK
;
1511 /* Set the new input LED color to GPIOD. */
1512 gpio_data
|= led_color
;
1514 /* Set the modified gpio_data values. */
1515 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1516 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1517 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1521 qla24xx_beacon_on(struct scsi_qla_host
*vha
)
1524 unsigned long flags
;
1525 struct qla_hw_data
*ha
= vha
->hw
;
1526 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1528 if (ha
->beacon_blink_led
== 0) {
1529 /* Enable firmware for update */
1530 ha
->fw_options
[1] |= ADD_FO1_DISABLE_GPIO_LED_CTRL
;
1532 if (qla2x00_set_fw_options(vha
, ha
->fw_options
) != QLA_SUCCESS
)
1533 return QLA_FUNCTION_FAILED
;
1535 if (qla2x00_get_fw_options(vha
, ha
->fw_options
) !=
1537 qla_printk(KERN_WARNING
, ha
,
1538 "Unable to update fw options (beacon on).\n");
1539 return QLA_FUNCTION_FAILED
;
1542 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1543 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1545 /* Enable the gpio_data reg for update. */
1546 gpio_data
|= GPDX_LED_UPDATE_MASK
;
1547 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1548 RD_REG_DWORD(®
->gpiod
);
1550 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1553 /* So all colors blink together. */
1554 ha
->beacon_color_state
= 0;
1556 /* Let the per HBA timer kick off the blinking process. */
1557 ha
->beacon_blink_led
= 1;
1563 qla24xx_beacon_off(struct scsi_qla_host
*vha
)
1566 unsigned long flags
;
1567 struct qla_hw_data
*ha
= vha
->hw
;
1568 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1570 ha
->beacon_blink_led
= 0;
1571 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1573 ha
->isp_ops
->beacon_blink(vha
); /* Will flip to all off. */
1575 /* Give control back to firmware. */
1576 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1577 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1579 /* Disable the gpio_data reg for update. */
1580 gpio_data
&= ~GPDX_LED_UPDATE_MASK
;
1581 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1582 RD_REG_DWORD(®
->gpiod
);
1583 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1585 ha
->fw_options
[1] &= ~ADD_FO1_DISABLE_GPIO_LED_CTRL
;
1587 if (qla2x00_set_fw_options(vha
, ha
->fw_options
) != QLA_SUCCESS
) {
1588 qla_printk(KERN_WARNING
, ha
,
1589 "Unable to update fw options (beacon off).\n");
1590 return QLA_FUNCTION_FAILED
;
1593 if (qla2x00_get_fw_options(vha
, ha
->fw_options
) != QLA_SUCCESS
) {
1594 qla_printk(KERN_WARNING
, ha
,
1595 "Unable to get fw options (beacon off).\n");
1596 return QLA_FUNCTION_FAILED
;
1604 * Flash support routines
1608 * qla2x00_flash_enable() - Setup flash for reading and writing.
1612 qla2x00_flash_enable(struct qla_hw_data
*ha
)
1615 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1617 data
= RD_REG_WORD(®
->ctrl_status
);
1618 data
|= CSR_FLASH_ENABLE
;
1619 WRT_REG_WORD(®
->ctrl_status
, data
);
1620 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1624 * qla2x00_flash_disable() - Disable flash and allow RISC to run.
1628 qla2x00_flash_disable(struct qla_hw_data
*ha
)
1631 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1633 data
= RD_REG_WORD(®
->ctrl_status
);
1634 data
&= ~(CSR_FLASH_ENABLE
);
1635 WRT_REG_WORD(®
->ctrl_status
, data
);
1636 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1640 * qla2x00_read_flash_byte() - Reads a byte from flash
1642 * @addr: Address in flash to read
1644 * A word is read from the chip, but, only the lower byte is valid.
1646 * Returns the byte read from flash @addr.
1649 qla2x00_read_flash_byte(struct qla_hw_data
*ha
, uint32_t addr
)
1652 uint16_t bank_select
;
1653 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1655 bank_select
= RD_REG_WORD(®
->ctrl_status
);
1657 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1658 /* Specify 64K address range: */
1659 /* clear out Module Select and Flash Address bits [19:16]. */
1660 bank_select
&= ~0xf8;
1661 bank_select
|= addr
>> 12 & 0xf0;
1662 bank_select
|= CSR_FLASH_64K_BANK
;
1663 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1664 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1666 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1667 data
= RD_REG_WORD(®
->flash_data
);
1669 return (uint8_t)data
;
1672 /* Setup bit 16 of flash address. */
1673 if ((addr
& BIT_16
) && ((bank_select
& CSR_FLASH_64K_BANK
) == 0)) {
1674 bank_select
|= CSR_FLASH_64K_BANK
;
1675 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1676 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1677 } else if (((addr
& BIT_16
) == 0) &&
1678 (bank_select
& CSR_FLASH_64K_BANK
)) {
1679 bank_select
&= ~(CSR_FLASH_64K_BANK
);
1680 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1681 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1684 /* Always perform IO mapped accesses to the FLASH registers. */
1685 if (ha
->pio_address
) {
1688 WRT_REG_WORD_PIO(PIO_REG(ha
, flash_address
), (uint16_t)addr
);
1690 data
= RD_REG_WORD_PIO(PIO_REG(ha
, flash_data
));
1693 data2
= RD_REG_WORD_PIO(PIO_REG(ha
, flash_data
));
1694 } while (data
!= data2
);
1696 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1697 data
= qla2x00_debounce_register(®
->flash_data
);
1700 return (uint8_t)data
;
1704 * qla2x00_write_flash_byte() - Write a byte to flash
1706 * @addr: Address in flash to write
1707 * @data: Data to write
1710 qla2x00_write_flash_byte(struct qla_hw_data
*ha
, uint32_t addr
, uint8_t data
)
1712 uint16_t bank_select
;
1713 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1715 bank_select
= RD_REG_WORD(®
->ctrl_status
);
1716 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1717 /* Specify 64K address range: */
1718 /* clear out Module Select and Flash Address bits [19:16]. */
1719 bank_select
&= ~0xf8;
1720 bank_select
|= addr
>> 12 & 0xf0;
1721 bank_select
|= CSR_FLASH_64K_BANK
;
1722 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1723 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1725 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1726 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1727 WRT_REG_WORD(®
->flash_data
, (uint16_t)data
);
1728 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1733 /* Setup bit 16 of flash address. */
1734 if ((addr
& BIT_16
) && ((bank_select
& CSR_FLASH_64K_BANK
) == 0)) {
1735 bank_select
|= CSR_FLASH_64K_BANK
;
1736 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1737 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1738 } else if (((addr
& BIT_16
) == 0) &&
1739 (bank_select
& CSR_FLASH_64K_BANK
)) {
1740 bank_select
&= ~(CSR_FLASH_64K_BANK
);
1741 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1742 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1745 /* Always perform IO mapped accesses to the FLASH registers. */
1746 if (ha
->pio_address
) {
1747 WRT_REG_WORD_PIO(PIO_REG(ha
, flash_address
), (uint16_t)addr
);
1748 WRT_REG_WORD_PIO(PIO_REG(ha
, flash_data
), (uint16_t)data
);
1750 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1751 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1752 WRT_REG_WORD(®
->flash_data
, (uint16_t)data
);
1753 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1758 * qla2x00_poll_flash() - Polls flash for completion.
1760 * @addr: Address in flash to poll
1761 * @poll_data: Data to be polled
1762 * @man_id: Flash manufacturer ID
1763 * @flash_id: Flash ID
1765 * This function polls the device until bit 7 of what is read matches data
1766 * bit 7 or until data bit 5 becomes a 1. If that hapens, the flash ROM timed
1767 * out (a fatal error). The flash book recommeds reading bit 7 again after
1768 * reading bit 5 as a 1.
1770 * Returns 0 on success, else non-zero.
1773 qla2x00_poll_flash(struct qla_hw_data
*ha
, uint32_t addr
, uint8_t poll_data
,
1774 uint8_t man_id
, uint8_t flash_id
)
1782 /* Wait for 30 seconds for command to finish. */
1784 for (cnt
= 3000000; cnt
; cnt
--) {
1785 flash_data
= qla2x00_read_flash_byte(ha
, addr
);
1786 if ((flash_data
& BIT_7
) == poll_data
) {
1791 if (man_id
!= 0x40 && man_id
!= 0xda) {
1792 if ((flash_data
& BIT_5
) && cnt
> 2)
1803 * qla2x00_program_flash_address() - Programs a flash address
1805 * @addr: Address in flash to program
1806 * @data: Data to be written in flash
1807 * @man_id: Flash manufacturer ID
1808 * @flash_id: Flash ID
1810 * Returns 0 on success, else non-zero.
1813 qla2x00_program_flash_address(struct qla_hw_data
*ha
, uint32_t addr
,
1814 uint8_t data
, uint8_t man_id
, uint8_t flash_id
)
1816 /* Write Program Command Sequence. */
1817 if (IS_OEM_001(ha
)) {
1818 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1819 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1820 qla2x00_write_flash_byte(ha
, 0xaaa, 0xa0);
1821 qla2x00_write_flash_byte(ha
, addr
, data
);
1823 if (man_id
== 0xda && flash_id
== 0xc1) {
1824 qla2x00_write_flash_byte(ha
, addr
, data
);
1828 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1829 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1830 qla2x00_write_flash_byte(ha
, 0x5555, 0xa0);
1831 qla2x00_write_flash_byte(ha
, addr
, data
);
1837 /* Wait for write to complete. */
1838 return qla2x00_poll_flash(ha
, addr
, data
, man_id
, flash_id
);
1842 * qla2x00_erase_flash() - Erase the flash.
1844 * @man_id: Flash manufacturer ID
1845 * @flash_id: Flash ID
1847 * Returns 0 on success, else non-zero.
1850 qla2x00_erase_flash(struct qla_hw_data
*ha
, uint8_t man_id
, uint8_t flash_id
)
1852 /* Individual Sector Erase Command Sequence */
1853 if (IS_OEM_001(ha
)) {
1854 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1855 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1856 qla2x00_write_flash_byte(ha
, 0xaaa, 0x80);
1857 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1858 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1859 qla2x00_write_flash_byte(ha
, 0xaaa, 0x10);
1861 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1862 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1863 qla2x00_write_flash_byte(ha
, 0x5555, 0x80);
1864 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1865 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1866 qla2x00_write_flash_byte(ha
, 0x5555, 0x10);
1871 /* Wait for erase to complete. */
1872 return qla2x00_poll_flash(ha
, 0x00, 0x80, man_id
, flash_id
);
1876 * qla2x00_erase_flash_sector() - Erase a flash sector.
1878 * @addr: Flash sector to erase
1879 * @sec_mask: Sector address mask
1880 * @man_id: Flash manufacturer ID
1881 * @flash_id: Flash ID
1883 * Returns 0 on success, else non-zero.
1886 qla2x00_erase_flash_sector(struct qla_hw_data
*ha
, uint32_t addr
,
1887 uint32_t sec_mask
, uint8_t man_id
, uint8_t flash_id
)
1889 /* Individual Sector Erase Command Sequence */
1890 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1891 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1892 qla2x00_write_flash_byte(ha
, 0x5555, 0x80);
1893 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1894 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1895 if (man_id
== 0x1f && flash_id
== 0x13)
1896 qla2x00_write_flash_byte(ha
, addr
& sec_mask
, 0x10);
1898 qla2x00_write_flash_byte(ha
, addr
& sec_mask
, 0x30);
1902 /* Wait for erase to complete. */
1903 return qla2x00_poll_flash(ha
, addr
, 0x80, man_id
, flash_id
);
1907 * qla2x00_get_flash_manufacturer() - Read manufacturer ID from flash chip.
1908 * @man_id: Flash manufacturer ID
1909 * @flash_id: Flash ID
1912 qla2x00_get_flash_manufacturer(struct qla_hw_data
*ha
, uint8_t *man_id
,
1915 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1916 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1917 qla2x00_write_flash_byte(ha
, 0x5555, 0x90);
1918 *man_id
= qla2x00_read_flash_byte(ha
, 0x0000);
1919 *flash_id
= qla2x00_read_flash_byte(ha
, 0x0001);
1920 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1921 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1922 qla2x00_write_flash_byte(ha
, 0x5555, 0xf0);
1926 qla2x00_read_flash_data(struct qla_hw_data
*ha
, uint8_t *tmp_buf
,
1927 uint32_t saddr
, uint32_t length
)
1929 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1930 uint32_t midpoint
, ilength
;
1933 midpoint
= length
/ 2;
1935 WRT_REG_WORD(®
->nvram
, 0);
1936 RD_REG_WORD(®
->nvram
);
1937 for (ilength
= 0; ilength
< length
; saddr
++, ilength
++, tmp_buf
++) {
1938 if (ilength
== midpoint
) {
1939 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
1940 RD_REG_WORD(®
->nvram
);
1942 data
= qla2x00_read_flash_byte(ha
, saddr
);
1951 qla2x00_suspend_hba(struct scsi_qla_host
*vha
)
1954 unsigned long flags
;
1955 struct qla_hw_data
*ha
= vha
->hw
;
1956 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1959 scsi_block_requests(vha
->host
);
1960 ha
->isp_ops
->disable_intrs(ha
);
1961 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1964 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1965 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
1966 RD_REG_WORD(®
->hccr
);
1967 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
1968 for (cnt
= 0; cnt
< 30000; cnt
++) {
1969 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
1976 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1980 qla2x00_resume_hba(struct scsi_qla_host
*vha
)
1982 struct qla_hw_data
*ha
= vha
->hw
;
1985 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1986 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1987 qla2xxx_wake_dpc(vha
);
1988 qla2x00_wait_for_chip_reset(vha
);
1989 scsi_unblock_requests(vha
->host
);
1993 qla2x00_read_optrom_data(struct scsi_qla_host
*vha
, uint8_t *buf
,
1994 uint32_t offset
, uint32_t length
)
1996 uint32_t addr
, midpoint
;
1998 struct qla_hw_data
*ha
= vha
->hw
;
1999 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2002 qla2x00_suspend_hba(vha
);
2005 midpoint
= ha
->optrom_size
/ 2;
2007 qla2x00_flash_enable(ha
);
2008 WRT_REG_WORD(®
->nvram
, 0);
2009 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
2010 for (addr
= offset
, data
= buf
; addr
< length
; addr
++, data
++) {
2011 if (addr
== midpoint
) {
2012 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
2013 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
2016 *data
= qla2x00_read_flash_byte(ha
, addr
);
2018 qla2x00_flash_disable(ha
);
2021 qla2x00_resume_hba(vha
);
2027 qla2x00_write_optrom_data(struct scsi_qla_host
*vha
, uint8_t *buf
,
2028 uint32_t offset
, uint32_t length
)
2032 uint8_t man_id
, flash_id
, sec_number
, data
;
2034 uint32_t addr
, liter
, sec_mask
, rest_addr
;
2035 struct qla_hw_data
*ha
= vha
->hw
;
2036 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2039 qla2x00_suspend_hba(vha
);
2044 /* Reset ISP chip. */
2045 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2046 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
2048 /* Go with write. */
2049 qla2x00_flash_enable(ha
);
2050 do { /* Loop once to provide quick error exit */
2051 /* Structure of flash memory based on manufacturer */
2052 if (IS_OEM_001(ha
)) {
2053 /* OEM variant with special flash part. */
2054 man_id
= flash_id
= 0;
2059 qla2x00_get_flash_manufacturer(ha
, &man_id
, &flash_id
);
2061 case 0x20: /* ST flash. */
2062 if (flash_id
== 0xd2 || flash_id
== 0xe3) {
2064 * ST m29w008at part - 64kb sector size with
2065 * 32kb,8kb,8kb,16kb sectors at memory address
2073 * ST m29w010b part - 16kb sector size
2074 * Default to 16kb sectors
2079 case 0x40: /* Mostel flash. */
2080 /* Mostel v29c51001 part - 512 byte sector size. */
2084 case 0xbf: /* SST flash. */
2085 /* SST39sf10 part - 4kb sector size. */
2089 case 0xda: /* Winbond flash. */
2090 /* Winbond W29EE011 part - 256 byte sector size. */
2094 case 0xc2: /* Macronix flash. */
2095 /* 64k sector size. */
2096 if (flash_id
== 0x38 || flash_id
== 0x4f) {
2101 /* Fall through... */
2103 case 0x1f: /* Atmel flash. */
2104 /* 512k sector size. */
2105 if (flash_id
== 0x13) {
2106 rest_addr
= 0x7fffffff;
2107 sec_mask
= 0x80000000;
2110 /* Fall through... */
2112 case 0x01: /* AMD flash. */
2113 if (flash_id
== 0x38 || flash_id
== 0x40 ||
2115 /* Am29LV081 part - 64kb sector size. */
2116 /* Am29LV002BT part - 64kb sector size. */
2120 } else if (flash_id
== 0x3e) {
2122 * Am29LV008b part - 64kb sector size with
2123 * 32kb,8kb,8kb,16kb sector at memory address
2129 } else if (flash_id
== 0x20 || flash_id
== 0x6e) {
2131 * Am29LV010 part or AM29f010 - 16kb sector
2137 } else if (flash_id
== 0x6d) {
2138 /* Am29LV001 part - 8kb sector size. */
2144 /* Default to 16 kb sector size. */
2151 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
2152 if (qla2x00_erase_flash(ha
, man_id
, flash_id
)) {
2153 rval
= QLA_FUNCTION_FAILED
;
2158 for (addr
= offset
, liter
= 0; liter
< length
; liter
++,
2161 /* Are we at the beginning of a sector? */
2162 if ((addr
& rest_addr
) == 0) {
2163 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
2164 if (addr
>= 0x10000UL
) {
2165 if (((addr
>> 12) & 0xf0) &&
2167 flash_id
== 0x3e) ||
2169 flash_id
== 0xd2))) {
2171 if (sec_number
== 1) {
2192 } else if (addr
== ha
->optrom_size
/ 2) {
2193 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
2194 RD_REG_WORD(®
->nvram
);
2197 if (flash_id
== 0xda && man_id
== 0xc1) {
2198 qla2x00_write_flash_byte(ha
, 0x5555,
2200 qla2x00_write_flash_byte(ha
, 0x2aaa,
2202 qla2x00_write_flash_byte(ha
, 0x5555,
2204 } else if (!IS_QLA2322(ha
) && !IS_QLA6322(ha
)) {
2206 if (qla2x00_erase_flash_sector(ha
,
2207 addr
, sec_mask
, man_id
,
2209 rval
= QLA_FUNCTION_FAILED
;
2212 if (man_id
== 0x01 && flash_id
== 0x6d)
2217 if (man_id
== 0x01 && flash_id
== 0x6d) {
2218 if (sec_number
== 1 &&
2219 addr
== (rest_addr
- 1)) {
2222 } else if (sec_number
== 3 && (addr
& 0x7ffe)) {
2228 if (qla2x00_program_flash_address(ha
, addr
, data
,
2229 man_id
, flash_id
)) {
2230 rval
= QLA_FUNCTION_FAILED
;
2236 qla2x00_flash_disable(ha
);
2239 qla2x00_resume_hba(vha
);
2245 qla24xx_read_optrom_data(struct scsi_qla_host
*vha
, uint8_t *buf
,
2246 uint32_t offset
, uint32_t length
)
2248 struct qla_hw_data
*ha
= vha
->hw
;
2251 scsi_block_requests(vha
->host
);
2252 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
2255 qla24xx_read_flash_data(vha
, (uint32_t *)buf
, offset
>> 2, length
>> 2);
2258 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
2259 scsi_unblock_requests(vha
->host
);
2265 qla24xx_write_optrom_data(struct scsi_qla_host
*vha
, uint8_t *buf
,
2266 uint32_t offset
, uint32_t length
)
2269 struct qla_hw_data
*ha
= vha
->hw
;
2272 scsi_block_requests(vha
->host
);
2273 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
2275 /* Go with write. */
2276 rval
= qla24xx_write_flash_data(vha
, (uint32_t *)buf
, offset
>> 2,
2279 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
2280 scsi_unblock_requests(vha
->host
);
2286 qla25xx_read_optrom_data(struct scsi_qla_host
*vha
, uint8_t *buf
,
2287 uint32_t offset
, uint32_t length
)
2290 dma_addr_t optrom_dma
;
2293 uint32_t faddr
, left
, burst
;
2294 struct qla_hw_data
*ha
= vha
->hw
;
2296 if (IS_QLA25XX(ha
) || IS_QLA81XX(ha
))
2300 if (length
< OPTROM_BURST_SIZE
)
2304 optrom
= dma_alloc_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
,
2305 &optrom_dma
, GFP_KERNEL
);
2307 qla_printk(KERN_DEBUG
, ha
,
2308 "Unable to allocate memory for optrom burst read "
2309 "(%x KB).\n", OPTROM_BURST_SIZE
/ 1024);
2315 faddr
= offset
>> 2;
2317 burst
= OPTROM_BURST_DWORDS
;
2322 rval
= qla2x00_dump_ram(vha
, optrom_dma
,
2323 flash_data_addr(ha
, faddr
), burst
);
2325 qla_printk(KERN_WARNING
, ha
,
2326 "Unable to burst-read optrom segment "
2327 "(%x/%x/%llx).\n", rval
,
2328 flash_data_addr(ha
, faddr
),
2329 (unsigned long long)optrom_dma
);
2330 qla_printk(KERN_WARNING
, ha
,
2331 "Reverting to slow-read.\n");
2333 dma_free_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
,
2334 optrom
, optrom_dma
);
2338 memcpy(pbuf
, optrom
, burst
* 4);
2345 dma_free_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
, optrom
,
2351 return qla24xx_read_optrom_data(vha
, buf
, offset
, length
);
2355 * qla2x00_get_fcode_version() - Determine an FCODE image's version.
2357 * @pcids: Pointer to the FCODE PCI data structure
2359 * The process of retrieving the FCODE version information is at best
2360 * described as interesting.
2362 * Within the first 100h bytes of the image an ASCII string is present
2363 * which contains several pieces of information including the FCODE
2364 * version. Unfortunately it seems the only reliable way to retrieve
2365 * the version is by scanning for another sentinel within the string,
2366 * the FCODE build date:
2368 * ... 2.00.02 10/17/02 ...
2370 * Returns QLA_SUCCESS on successful retrieval of version.
2373 qla2x00_get_fcode_version(struct qla_hw_data
*ha
, uint32_t pcids
)
2375 int ret
= QLA_FUNCTION_FAILED
;
2376 uint32_t istart
, iend
, iter
, vend
;
2377 uint8_t do_next
, rbyte
, *vbyte
;
2379 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2381 /* Skip the PCI data structure. */
2383 ((qla2x00_read_flash_byte(ha
, pcids
+ 0x0B) << 8) |
2384 qla2x00_read_flash_byte(ha
, pcids
+ 0x0A));
2385 iend
= istart
+ 0x100;
2387 /* Scan for the sentinel date string...eeewww. */
2390 while ((iter
< iend
) && !do_next
) {
2392 if (qla2x00_read_flash_byte(ha
, iter
) == '/') {
2393 if (qla2x00_read_flash_byte(ha
, iter
+ 2) ==
2396 else if (qla2x00_read_flash_byte(ha
,
2404 /* Backtrack to previous ' ' (space). */
2406 while ((iter
> istart
) && !do_next
) {
2408 if (qla2x00_read_flash_byte(ha
, iter
) == ' ')
2415 * Mark end of version tag, and find previous ' ' (space) or
2416 * string length (recent FCODE images -- major hack ahead!!!).
2420 while ((iter
> istart
) && !do_next
) {
2422 rbyte
= qla2x00_read_flash_byte(ha
, iter
);
2423 if (rbyte
== ' ' || rbyte
== 0xd || rbyte
== 0x10)
2429 /* Mark beginning of version tag, and copy data. */
2431 if ((vend
- iter
) &&
2432 ((vend
- iter
) < sizeof(ha
->fcode_revision
))) {
2433 vbyte
= ha
->fcode_revision
;
2434 while (iter
<= vend
) {
2435 *vbyte
++ = qla2x00_read_flash_byte(ha
, iter
);
2442 if (ret
!= QLA_SUCCESS
)
2443 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2447 qla2x00_get_flash_version(scsi_qla_host_t
*vha
, void *mbuf
)
2449 int ret
= QLA_SUCCESS
;
2450 uint8_t code_type
, last_image
;
2451 uint32_t pcihdr
, pcids
;
2454 struct qla_hw_data
*ha
= vha
->hw
;
2456 if (!ha
->pio_address
|| !mbuf
)
2457 return QLA_FUNCTION_FAILED
;
2459 memset(ha
->bios_revision
, 0, sizeof(ha
->bios_revision
));
2460 memset(ha
->efi_revision
, 0, sizeof(ha
->efi_revision
));
2461 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2462 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2464 qla2x00_flash_enable(ha
);
2466 /* Begin with first PCI expansion ROM header. */
2470 /* Verify PCI expansion ROM header. */
2471 if (qla2x00_read_flash_byte(ha
, pcihdr
) != 0x55 ||
2472 qla2x00_read_flash_byte(ha
, pcihdr
+ 0x01) != 0xaa) {
2474 DEBUG2(qla_printk(KERN_DEBUG
, ha
, "No matching ROM "
2476 ret
= QLA_FUNCTION_FAILED
;
2480 /* Locate PCI data structure. */
2482 ((qla2x00_read_flash_byte(ha
, pcihdr
+ 0x19) << 8) |
2483 qla2x00_read_flash_byte(ha
, pcihdr
+ 0x18));
2485 /* Validate signature of PCI data structure. */
2486 if (qla2x00_read_flash_byte(ha
, pcids
) != 'P' ||
2487 qla2x00_read_flash_byte(ha
, pcids
+ 0x1) != 'C' ||
2488 qla2x00_read_flash_byte(ha
, pcids
+ 0x2) != 'I' ||
2489 qla2x00_read_flash_byte(ha
, pcids
+ 0x3) != 'R') {
2490 /* Incorrect header. */
2491 DEBUG2(qla_printk(KERN_INFO
, ha
, "PCI data struct not "
2492 "found pcir_adr=%x.\n", pcids
));
2493 ret
= QLA_FUNCTION_FAILED
;
2498 code_type
= qla2x00_read_flash_byte(ha
, pcids
+ 0x14);
2499 switch (code_type
) {
2500 case ROM_CODE_TYPE_BIOS
:
2501 /* Intel x86, PC-AT compatible. */
2502 ha
->bios_revision
[0] =
2503 qla2x00_read_flash_byte(ha
, pcids
+ 0x12);
2504 ha
->bios_revision
[1] =
2505 qla2x00_read_flash_byte(ha
, pcids
+ 0x13);
2506 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "read BIOS %d.%d.\n",
2507 ha
->bios_revision
[1], ha
->bios_revision
[0]));
2509 case ROM_CODE_TYPE_FCODE
:
2510 /* Open Firmware standard for PCI (FCode). */
2512 qla2x00_get_fcode_version(ha
, pcids
);
2514 case ROM_CODE_TYPE_EFI
:
2515 /* Extensible Firmware Interface (EFI). */
2516 ha
->efi_revision
[0] =
2517 qla2x00_read_flash_byte(ha
, pcids
+ 0x12);
2518 ha
->efi_revision
[1] =
2519 qla2x00_read_flash_byte(ha
, pcids
+ 0x13);
2520 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "read EFI %d.%d.\n",
2521 ha
->efi_revision
[1], ha
->efi_revision
[0]));
2524 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unrecognized code "
2525 "type %x at pcids %x.\n", code_type
, pcids
));
2529 last_image
= qla2x00_read_flash_byte(ha
, pcids
+ 0x15) & BIT_7
;
2531 /* Locate next PCI expansion ROM. */
2532 pcihdr
+= ((qla2x00_read_flash_byte(ha
, pcids
+ 0x11) << 8) |
2533 qla2x00_read_flash_byte(ha
, pcids
+ 0x10)) * 512;
2534 } while (!last_image
);
2536 if (IS_QLA2322(ha
)) {
2537 /* Read firmware image information. */
2538 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2540 memset(dbyte
, 0, 8);
2541 dcode
= (uint16_t *)dbyte
;
2543 qla2x00_read_flash_data(ha
, dbyte
, ha
->flt_region_fw
* 4 + 10,
2545 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "dumping fw ver from "
2547 DEBUG3(qla2x00_dump_buffer((uint8_t *)dbyte
, 8));
2549 if ((dcode
[0] == 0xffff && dcode
[1] == 0xffff &&
2550 dcode
[2] == 0xffff && dcode
[3] == 0xffff) ||
2551 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
2553 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unrecognized fw "
2554 "revision at %x.\n", ha
->flt_region_fw
* 4));
2556 /* values are in big endian */
2557 ha
->fw_revision
[0] = dbyte
[0] << 16 | dbyte
[1];
2558 ha
->fw_revision
[1] = dbyte
[2] << 16 | dbyte
[3];
2559 ha
->fw_revision
[2] = dbyte
[4] << 16 | dbyte
[5];
2563 qla2x00_flash_disable(ha
);
2569 qla24xx_get_flash_version(scsi_qla_host_t
*vha
, void *mbuf
)
2571 int ret
= QLA_SUCCESS
;
2572 uint32_t pcihdr
, pcids
;
2575 uint8_t code_type
, last_image
;
2577 struct qla_hw_data
*ha
= vha
->hw
;
2580 return QLA_FUNCTION_FAILED
;
2582 memset(ha
->bios_revision
, 0, sizeof(ha
->bios_revision
));
2583 memset(ha
->efi_revision
, 0, sizeof(ha
->efi_revision
));
2584 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2585 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2589 /* Begin with first PCI expansion ROM header. */
2590 pcihdr
= ha
->flt_region_boot
<< 2;
2593 /* Verify PCI expansion ROM header. */
2594 qla24xx_read_flash_data(vha
, dcode
, pcihdr
>> 2, 0x20);
2595 bcode
= mbuf
+ (pcihdr
% 4);
2596 if (bcode
[0x0] != 0x55 || bcode
[0x1] != 0xaa) {
2598 DEBUG2(qla_printk(KERN_DEBUG
, ha
, "No matching ROM "
2600 ret
= QLA_FUNCTION_FAILED
;
2604 /* Locate PCI data structure. */
2605 pcids
= pcihdr
+ ((bcode
[0x19] << 8) | bcode
[0x18]);
2607 qla24xx_read_flash_data(vha
, dcode
, pcids
>> 2, 0x20);
2608 bcode
= mbuf
+ (pcihdr
% 4);
2610 /* Validate signature of PCI data structure. */
2611 if (bcode
[0x0] != 'P' || bcode
[0x1] != 'C' ||
2612 bcode
[0x2] != 'I' || bcode
[0x3] != 'R') {
2613 /* Incorrect header. */
2614 DEBUG2(qla_printk(KERN_INFO
, ha
, "PCI data struct not "
2615 "found pcir_adr=%x.\n", pcids
));
2616 ret
= QLA_FUNCTION_FAILED
;
2621 code_type
= bcode
[0x14];
2622 switch (code_type
) {
2623 case ROM_CODE_TYPE_BIOS
:
2624 /* Intel x86, PC-AT compatible. */
2625 ha
->bios_revision
[0] = bcode
[0x12];
2626 ha
->bios_revision
[1] = bcode
[0x13];
2627 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "read BIOS %d.%d.\n",
2628 ha
->bios_revision
[1], ha
->bios_revision
[0]));
2630 case ROM_CODE_TYPE_FCODE
:
2631 /* Open Firmware standard for PCI (FCode). */
2632 ha
->fcode_revision
[0] = bcode
[0x12];
2633 ha
->fcode_revision
[1] = bcode
[0x13];
2634 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "read FCODE %d.%d.\n",
2635 ha
->fcode_revision
[1], ha
->fcode_revision
[0]));
2637 case ROM_CODE_TYPE_EFI
:
2638 /* Extensible Firmware Interface (EFI). */
2639 ha
->efi_revision
[0] = bcode
[0x12];
2640 ha
->efi_revision
[1] = bcode
[0x13];
2641 DEBUG3(qla_printk(KERN_DEBUG
, ha
, "read EFI %d.%d.\n",
2642 ha
->efi_revision
[1], ha
->efi_revision
[0]));
2645 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unrecognized code "
2646 "type %x at pcids %x.\n", code_type
, pcids
));
2650 last_image
= bcode
[0x15] & BIT_7
;
2652 /* Locate next PCI expansion ROM. */
2653 pcihdr
+= ((bcode
[0x11] << 8) | bcode
[0x10]) * 512;
2654 } while (!last_image
);
2656 /* Read firmware image information. */
2657 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2660 qla24xx_read_flash_data(vha
, dcode
, ha
->flt_region_fw
+ 4, 4);
2661 for (i
= 0; i
< 4; i
++)
2662 dcode
[i
] = be32_to_cpu(dcode
[i
]);
2664 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
2665 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
2666 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
2668 DEBUG2(qla_printk(KERN_INFO
, ha
, "Unrecognized fw "
2669 "revision at %x.\n", ha
->flt_region_fw
* 4));
2671 ha
->fw_revision
[0] = dcode
[0];
2672 ha
->fw_revision
[1] = dcode
[1];
2673 ha
->fw_revision
[2] = dcode
[2];
2674 ha
->fw_revision
[3] = dcode
[3];
2681 qla2xxx_is_vpd_valid(uint8_t *pos
, uint8_t *end
)
2683 if (pos
>= end
|| *pos
!= 0x82)
2687 if (pos
>= end
|| *pos
!= 0x90)
2691 if (pos
>= end
|| *pos
!= 0x78)
2698 qla2xxx_get_vpd_field(scsi_qla_host_t
*vha
, char *key
, char *str
, size_t size
)
2700 struct qla_hw_data
*ha
= vha
->hw
;
2701 uint8_t *pos
= ha
->vpd
;
2702 uint8_t *end
= pos
+ ha
->vpd_size
;
2705 if (!IS_FWI2_CAPABLE(ha
) || !qla2xxx_is_vpd_valid(pos
, end
))
2708 while (pos
< end
&& *pos
!= 0x78) {
2709 len
= (*pos
== 0x82) ? pos
[1] : pos
[2];
2711 if (!strncmp(pos
, key
, strlen(key
)))
2714 if (*pos
!= 0x90 && *pos
!= 0x91)
2720 if (pos
< end
- len
&& *pos
!= 0x78)
2721 return snprintf(str
, size
, "%.*s", len
, pos
+ 3);