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/vmalloc.h>
11 #include <asm/uaccess.h>
13 static uint16_t qla2x00_nvram_request(scsi_qla_host_t
*, uint32_t);
14 static void qla2x00_nv_deselect(scsi_qla_host_t
*);
15 static void qla2x00_nv_write(scsi_qla_host_t
*, uint16_t);
18 * NVRAM support routines
22 * qla2x00_lock_nvram_access() -
26 qla2x00_lock_nvram_access(scsi_qla_host_t
*ha
)
29 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
31 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
)) {
32 data
= RD_REG_WORD(®
->nvram
);
33 while (data
& NVR_BUSY
) {
35 data
= RD_REG_WORD(®
->nvram
);
39 WRT_REG_WORD(®
->u
.isp2300
.host_semaphore
, 0x1);
40 RD_REG_WORD(®
->u
.isp2300
.host_semaphore
);
42 data
= RD_REG_WORD(®
->u
.isp2300
.host_semaphore
);
43 while ((data
& BIT_0
) == 0) {
46 WRT_REG_WORD(®
->u
.isp2300
.host_semaphore
, 0x1);
47 RD_REG_WORD(®
->u
.isp2300
.host_semaphore
);
49 data
= RD_REG_WORD(®
->u
.isp2300
.host_semaphore
);
55 * qla2x00_unlock_nvram_access() -
59 qla2x00_unlock_nvram_access(scsi_qla_host_t
*ha
)
61 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
63 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
)) {
64 WRT_REG_WORD(®
->u
.isp2300
.host_semaphore
, 0);
65 RD_REG_WORD(®
->u
.isp2300
.host_semaphore
);
70 * qla2x00_get_nvram_word() - Calculates word position in NVRAM and calls the
71 * request routine to get the word from NVRAM.
73 * @addr: Address in NVRAM to read
75 * Returns the word read from nvram @addr.
78 qla2x00_get_nvram_word(scsi_qla_host_t
*ha
, uint32_t addr
)
85 data
= qla2x00_nvram_request(ha
, nv_cmd
);
91 * qla2x00_write_nvram_word() - Write NVRAM data.
93 * @addr: Address in NVRAM to write
94 * @data: word to program
97 qla2x00_write_nvram_word(scsi_qla_host_t
*ha
, uint32_t addr
, uint16_t data
)
101 uint32_t nv_cmd
, wait_cnt
;
102 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
104 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
105 qla2x00_nv_write(ha
, 0);
106 qla2x00_nv_write(ha
, 0);
108 for (word
= 0; word
< 8; word
++)
109 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
111 qla2x00_nv_deselect(ha
);
114 nv_cmd
= (addr
<< 16) | NV_WRITE_OP
;
117 for (count
= 0; count
< 27; count
++) {
119 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
121 qla2x00_nv_write(ha
, 0);
126 qla2x00_nv_deselect(ha
);
128 /* Wait for NVRAM to become ready */
129 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
130 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
131 wait_cnt
= NVR_WAIT_CNT
;
134 DEBUG9_10(printk("%s(%ld): NVRAM didn't go ready...\n",
135 __func__
, ha
->host_no
));
139 word
= RD_REG_WORD(®
->nvram
);
140 } while ((word
& NVR_DATA_IN
) == 0);
142 qla2x00_nv_deselect(ha
);
145 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
146 for (count
= 0; count
< 10; count
++)
147 qla2x00_nv_write(ha
, 0);
149 qla2x00_nv_deselect(ha
);
153 qla2x00_write_nvram_word_tmo(scsi_qla_host_t
*ha
, uint32_t addr
, uint16_t data
,
159 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
163 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
164 qla2x00_nv_write(ha
, 0);
165 qla2x00_nv_write(ha
, 0);
167 for (word
= 0; word
< 8; word
++)
168 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
170 qla2x00_nv_deselect(ha
);
173 nv_cmd
= (addr
<< 16) | NV_WRITE_OP
;
176 for (count
= 0; count
< 27; count
++) {
178 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
180 qla2x00_nv_write(ha
, 0);
185 qla2x00_nv_deselect(ha
);
187 /* Wait for NVRAM to become ready */
188 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
189 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
192 word
= RD_REG_WORD(®
->nvram
);
194 ret
= QLA_FUNCTION_FAILED
;
197 } while ((word
& NVR_DATA_IN
) == 0);
199 qla2x00_nv_deselect(ha
);
202 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
203 for (count
= 0; count
< 10; count
++)
204 qla2x00_nv_write(ha
, 0);
206 qla2x00_nv_deselect(ha
);
212 * qla2x00_nvram_request() - Sends read command to NVRAM and gets data from
215 * @nv_cmd: NVRAM command
217 * Bit definitions for NVRAM command:
220 * Bit 25, 24 = opcode
221 * Bit 23-16 = address
222 * Bit 15-0 = write data
224 * Returns the word read from nvram @addr.
227 qla2x00_nvram_request(scsi_qla_host_t
*ha
, uint32_t nv_cmd
)
230 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
234 /* Send command to NVRAM. */
236 for (cnt
= 0; cnt
< 11; cnt
++) {
238 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
240 qla2x00_nv_write(ha
, 0);
244 /* Read data from NVRAM. */
245 for (cnt
= 0; cnt
< 16; cnt
++) {
246 WRT_REG_WORD(®
->nvram
, NVR_SELECT
| NVR_CLOCK
);
247 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
250 reg_data
= RD_REG_WORD(®
->nvram
);
251 if (reg_data
& NVR_DATA_IN
)
253 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
254 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
259 WRT_REG_WORD(®
->nvram
, NVR_DESELECT
);
260 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
267 * qla2x00_nv_write() - Clean NVRAM operations.
271 qla2x00_nv_deselect(scsi_qla_host_t
*ha
)
273 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
275 WRT_REG_WORD(®
->nvram
, NVR_DESELECT
);
276 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
281 * qla2x00_nv_write() - Prepare for NVRAM read/write operation.
283 * @data: Serial interface selector
286 qla2x00_nv_write(scsi_qla_host_t
*ha
, uint16_t data
)
288 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
290 WRT_REG_WORD(®
->nvram
, data
| NVR_SELECT
| NVR_WRT_ENABLE
);
291 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
293 WRT_REG_WORD(®
->nvram
, data
| NVR_SELECT
| NVR_CLOCK
|
295 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
297 WRT_REG_WORD(®
->nvram
, data
| NVR_SELECT
| NVR_WRT_ENABLE
);
298 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
303 * qla2x00_clear_nvram_protection() -
307 qla2x00_clear_nvram_protection(scsi_qla_host_t
*ha
)
310 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
311 uint32_t word
, wait_cnt
;
312 uint16_t wprot
, wprot_old
;
314 /* Clear NVRAM write protection. */
315 ret
= QLA_FUNCTION_FAILED
;
317 wprot_old
= cpu_to_le16(qla2x00_get_nvram_word(ha
, ha
->nvram_base
));
318 stat
= qla2x00_write_nvram_word_tmo(ha
, ha
->nvram_base
,
319 __constant_cpu_to_le16(0x1234), 100000);
320 wprot
= cpu_to_le16(qla2x00_get_nvram_word(ha
, ha
->nvram_base
));
321 if (stat
!= QLA_SUCCESS
|| wprot
!= 0x1234) {
323 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
324 qla2x00_nv_write(ha
, 0);
325 qla2x00_nv_write(ha
, 0);
326 for (word
= 0; word
< 8; word
++)
327 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
329 qla2x00_nv_deselect(ha
);
331 /* Enable protection register. */
332 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
333 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
334 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
335 for (word
= 0; word
< 8; word
++)
336 qla2x00_nv_write(ha
, NVR_DATA_OUT
| NVR_PR_ENABLE
);
338 qla2x00_nv_deselect(ha
);
340 /* Clear protection register (ffff is cleared). */
341 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
342 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
343 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
344 for (word
= 0; word
< 8; word
++)
345 qla2x00_nv_write(ha
, NVR_DATA_OUT
| NVR_PR_ENABLE
);
347 qla2x00_nv_deselect(ha
);
349 /* Wait for NVRAM to become ready. */
350 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
351 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
352 wait_cnt
= NVR_WAIT_CNT
;
355 DEBUG9_10(printk("%s(%ld): NVRAM didn't go "
356 "ready...\n", __func__
,
361 word
= RD_REG_WORD(®
->nvram
);
362 } while ((word
& NVR_DATA_IN
) == 0);
367 qla2x00_write_nvram_word(ha
, ha
->nvram_base
, wprot_old
);
373 qla2x00_set_nvram_protection(scsi_qla_host_t
*ha
, int stat
)
375 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
376 uint32_t word
, wait_cnt
;
378 if (stat
!= QLA_SUCCESS
)
381 /* Set NVRAM write protection. */
383 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
384 qla2x00_nv_write(ha
, 0);
385 qla2x00_nv_write(ha
, 0);
386 for (word
= 0; word
< 8; word
++)
387 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
389 qla2x00_nv_deselect(ha
);
391 /* Enable protection register. */
392 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
393 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
394 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
395 for (word
= 0; word
< 8; word
++)
396 qla2x00_nv_write(ha
, NVR_DATA_OUT
| NVR_PR_ENABLE
);
398 qla2x00_nv_deselect(ha
);
400 /* Enable protection register. */
401 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
402 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
403 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
404 for (word
= 0; word
< 8; word
++)
405 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
407 qla2x00_nv_deselect(ha
);
409 /* Wait for NVRAM to become ready. */
410 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
411 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
412 wait_cnt
= NVR_WAIT_CNT
;
415 DEBUG9_10(printk("%s(%ld): NVRAM didn't go ready...\n",
416 __func__
, ha
->host_no
));
420 word
= RD_REG_WORD(®
->nvram
);
421 } while ((word
& NVR_DATA_IN
) == 0);
425 /*****************************************************************************/
426 /* Flash Manipulation Routines */
427 /*****************************************************************************/
429 #define OPTROM_BURST_SIZE 0x1000
430 #define OPTROM_BURST_DWORDS (OPTROM_BURST_SIZE / 4)
432 static inline uint32_t
433 flash_conf_to_access_addr(uint32_t faddr
)
435 return FARX_ACCESS_FLASH_CONF
| faddr
;
438 static inline uint32_t
439 flash_data_to_access_addr(uint32_t faddr
)
441 return FARX_ACCESS_FLASH_DATA
| faddr
;
444 static inline uint32_t
445 nvram_conf_to_access_addr(uint32_t naddr
)
447 return FARX_ACCESS_NVRAM_CONF
| naddr
;
450 static inline uint32_t
451 nvram_data_to_access_addr(uint32_t naddr
)
453 return FARX_ACCESS_NVRAM_DATA
| naddr
;
457 qla24xx_read_flash_dword(scsi_qla_host_t
*ha
, uint32_t addr
)
461 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
463 WRT_REG_DWORD(®
->flash_addr
, addr
& ~FARX_DATA_FLAG
);
464 /* Wait for READ cycle to complete. */
467 (RD_REG_DWORD(®
->flash_addr
) & FARX_DATA_FLAG
) == 0 &&
468 rval
== QLA_SUCCESS
; cnt
--) {
472 rval
= QLA_FUNCTION_TIMEOUT
;
476 /* TODO: What happens if we time out? */
478 if (rval
== QLA_SUCCESS
)
479 data
= RD_REG_DWORD(®
->flash_data
);
485 qla24xx_read_flash_data(scsi_qla_host_t
*ha
, uint32_t *dwptr
, uint32_t faddr
,
490 /* Dword reads to flash. */
491 for (i
= 0; i
< dwords
; i
++, faddr
++)
492 dwptr
[i
] = cpu_to_le32(qla24xx_read_flash_dword(ha
,
493 flash_data_to_access_addr(faddr
)));
499 qla24xx_write_flash_dword(scsi_qla_host_t
*ha
, uint32_t addr
, uint32_t data
)
503 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
505 WRT_REG_DWORD(®
->flash_data
, data
);
506 RD_REG_DWORD(®
->flash_data
); /* PCI Posting. */
507 WRT_REG_DWORD(®
->flash_addr
, addr
| FARX_DATA_FLAG
);
508 /* Wait for Write cycle to complete. */
510 for (cnt
= 500000; (RD_REG_DWORD(®
->flash_addr
) & FARX_DATA_FLAG
) &&
511 rval
== QLA_SUCCESS
; cnt
--) {
515 rval
= QLA_FUNCTION_TIMEOUT
;
522 qla24xx_get_flash_manufacturer(scsi_qla_host_t
*ha
, uint8_t *man_id
,
527 ids
= qla24xx_read_flash_dword(ha
, flash_data_to_access_addr(0xd03ab));
529 *flash_id
= MSB(ids
);
531 /* Check if man_id and flash_id are valid. */
532 if (ids
!= 0xDEADDEAD && (*man_id
== 0 || *flash_id
== 0)) {
533 /* Read information using 0x9f opcode
534 * Device ID, Mfg ID would be read in the format:
535 * <Ext Dev Info><Device ID Part2><Device ID Part 1><Mfg ID>
536 * Example: ATMEL 0x00 01 45 1F
537 * Extract MFG and Dev ID from last two bytes.
539 ids
= qla24xx_read_flash_dword(ha
,
540 flash_data_to_access_addr(0xd009f));
542 *flash_id
= MSB(ids
);
547 qla2xxx_get_flash_info(scsi_qla_host_t
*ha
)
549 #define FLASH_BLK_SIZE_32K 0x8000
550 #define FLASH_BLK_SIZE_64K 0x10000
551 uint16_t cnt
, chksum
;
553 struct qla_fdt_layout
*fdt
;
554 uint8_t man_id
, flash_id
;
556 if (!IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
))
559 wptr
= (uint16_t *)ha
->request_ring
;
560 fdt
= (struct qla_fdt_layout
*)ha
->request_ring
;
561 ha
->isp_ops
->read_optrom(ha
, (uint8_t *)ha
->request_ring
,
562 FA_FLASH_DESCR_ADDR
<< 2, OPTROM_BURST_SIZE
);
563 if (*wptr
== __constant_cpu_to_le16(0xffff))
565 if (fdt
->sig
[0] != 'Q' || fdt
->sig
[1] != 'L' || fdt
->sig
[2] != 'I' ||
569 for (cnt
= 0, chksum
= 0; cnt
< sizeof(struct qla_fdt_layout
) >> 1;
571 chksum
+= le16_to_cpu(*wptr
++);
573 DEBUG2(qla_printk(KERN_INFO
, ha
, "Inconsistent FDT detected: "
574 "checksum=0x%x id=%c version=0x%x.\n", chksum
, fdt
->sig
[0],
575 le16_to_cpu(fdt
->version
)));
576 DEBUG9(qla2x00_dump_buffer((uint8_t *)fdt
, sizeof(*fdt
)));
580 ha
->fdt_odd_index
= le16_to_cpu(fdt
->man_id
) == 0x1f;
581 ha
->fdt_wrt_disable
= fdt
->wrt_disable_bits
;
582 ha
->fdt_erase_cmd
= flash_conf_to_access_addr(0x0300 | fdt
->erase_cmd
);
583 ha
->fdt_block_size
= le32_to_cpu(fdt
->block_size
);
584 if (fdt
->unprotect_sec_cmd
) {
585 ha
->fdt_unprotect_sec_cmd
= flash_conf_to_access_addr(0x0300 |
586 fdt
->unprotect_sec_cmd
);
587 ha
->fdt_protect_sec_cmd
= fdt
->protect_sec_cmd
?
588 flash_conf_to_access_addr(0x0300 | fdt
->protect_sec_cmd
):
589 flash_conf_to_access_addr(0x0336);
592 DEBUG2(qla_printk(KERN_DEBUG
, ha
, "Flash[FDT]: (0x%x/0x%x) erase=0x%x "
593 "pro=%x upro=%x idx=%d wrtd=0x%x blk=0x%x.\n",
594 le16_to_cpu(fdt
->man_id
), le16_to_cpu(fdt
->id
), ha
->fdt_erase_cmd
,
595 ha
->fdt_protect_sec_cmd
, ha
->fdt_unprotect_sec_cmd
,
596 ha
->fdt_odd_index
, ha
->fdt_wrt_disable
, ha
->fdt_block_size
));
600 qla24xx_get_flash_manufacturer(ha
, &man_id
, &flash_id
);
601 ha
->fdt_wrt_disable
= 0x9c;
602 ha
->fdt_erase_cmd
= flash_conf_to_access_addr(0x03d8);
604 case 0xbf: /* STT flash. */
605 if (flash_id
== 0x8e)
606 ha
->fdt_block_size
= FLASH_BLK_SIZE_64K
;
608 ha
->fdt_block_size
= FLASH_BLK_SIZE_32K
;
610 if (flash_id
== 0x80)
611 ha
->fdt_erase_cmd
= flash_conf_to_access_addr(0x0352);
613 case 0x13: /* ST M25P80. */
614 ha
->fdt_block_size
= FLASH_BLK_SIZE_64K
;
616 case 0x1f: /* Atmel 26DF081A. */
617 ha
->fdt_odd_index
= 1;
618 ha
->fdt_block_size
= FLASH_BLK_SIZE_64K
;
619 ha
->fdt_erase_cmd
= flash_conf_to_access_addr(0x0320);
620 ha
->fdt_unprotect_sec_cmd
= flash_conf_to_access_addr(0x0339);
621 ha
->fdt_protect_sec_cmd
= flash_conf_to_access_addr(0x0336);
624 /* Default to 64 kb sector size. */
625 ha
->fdt_block_size
= FLASH_BLK_SIZE_64K
;
629 DEBUG2(qla_printk(KERN_DEBUG
, ha
, "Flash[MID]: (0x%x/0x%x) erase=0x%x "
630 "pro=%x upro=%x idx=%d wrtd=0x%x blk=0x%x.\n", man_id
, flash_id
,
631 ha
->fdt_erase_cmd
, ha
->fdt_protect_sec_cmd
,
632 ha
->fdt_unprotect_sec_cmd
, ha
->fdt_odd_index
, ha
->fdt_wrt_disable
,
633 ha
->fdt_block_size
));
637 qla24xx_unprotect_flash(scsi_qla_host_t
*ha
)
639 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
641 /* Enable flash write. */
642 WRT_REG_DWORD(®
->ctrl_status
,
643 RD_REG_DWORD(®
->ctrl_status
) | CSRX_FLASH_ENABLE
);
644 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
646 if (!ha
->fdt_wrt_disable
)
649 /* Disable flash write-protection. */
650 qla24xx_write_flash_dword(ha
, flash_conf_to_access_addr(0x101), 0);
651 /* Some flash parts need an additional zero-write to clear bits.*/
652 qla24xx_write_flash_dword(ha
, flash_conf_to_access_addr(0x101), 0);
656 qla24xx_protect_flash(scsi_qla_host_t
*ha
)
659 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
661 if (!ha
->fdt_wrt_disable
)
662 goto skip_wrt_protect
;
664 /* Enable flash write-protection and wait for completion. */
665 qla24xx_write_flash_dword(ha
, flash_conf_to_access_addr(0x101),
666 ha
->fdt_wrt_disable
);
667 for (cnt
= 300; cnt
&&
668 qla24xx_read_flash_dword(ha
,
669 flash_conf_to_access_addr(0x005)) & BIT_0
;
675 /* Disable flash write. */
676 WRT_REG_DWORD(®
->ctrl_status
,
677 RD_REG_DWORD(®
->ctrl_status
) & ~CSRX_FLASH_ENABLE
);
678 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
682 qla24xx_write_flash_data(scsi_qla_host_t
*ha
, uint32_t *dwptr
, uint32_t faddr
,
686 uint32_t liter
, miter
;
687 uint32_t sec_mask
, rest_addr
;
688 uint32_t fdata
, findex
;
689 dma_addr_t optrom_dma
;
695 /* Prepare burst-capable write on supported ISPs. */
696 if (IS_QLA25XX(ha
) && !(faddr
& 0xfff) &&
697 dwords
> OPTROM_BURST_DWORDS
) {
698 optrom
= dma_alloc_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
,
699 &optrom_dma
, GFP_KERNEL
);
701 qla_printk(KERN_DEBUG
, ha
,
702 "Unable to allocate memory for optrom burst write "
703 "(%x KB).\n", OPTROM_BURST_SIZE
/ 1024);
707 rest_addr
= (ha
->fdt_block_size
>> 2) - 1;
708 sec_mask
= 0x80000 - (ha
->fdt_block_size
>> 2);
710 qla24xx_unprotect_flash(ha
);
712 for (liter
= 0; liter
< dwords
; liter
++, faddr
++, dwptr
++) {
713 if (ha
->fdt_odd_index
) {
715 fdata
= findex
& sec_mask
;
718 fdata
= (findex
& sec_mask
) << 2;
721 /* Are we at the beginning of a sector? */
722 if ((findex
& rest_addr
) == 0) {
723 /* Do sector unprotect. */
724 if (ha
->fdt_unprotect_sec_cmd
)
725 qla24xx_write_flash_dword(ha
,
726 ha
->fdt_unprotect_sec_cmd
,
727 (fdata
& 0xff00) | ((fdata
<< 16) &
728 0xff0000) | ((fdata
>> 16) & 0xff));
729 ret
= qla24xx_write_flash_dword(ha
, ha
->fdt_erase_cmd
,
730 (fdata
& 0xff00) |((fdata
<< 16) &
731 0xff0000) | ((fdata
>> 16) & 0xff));
732 if (ret
!= QLA_SUCCESS
) {
733 DEBUG9(printk("%s(%ld) Unable to flash "
734 "sector: address=%x.\n", __func__
,
735 ha
->host_no
, faddr
));
740 /* Go with burst-write. */
741 if (optrom
&& (liter
+ OPTROM_BURST_DWORDS
) <= dwords
) {
742 /* Copy data to DMA'ble buffer. */
743 for (miter
= 0, s
= optrom
, d
= dwptr
;
744 miter
< OPTROM_BURST_DWORDS
; miter
++, s
++, d
++)
745 *s
= cpu_to_le32(*d
);
747 ret
= qla2x00_load_ram(ha
, optrom_dma
,
748 flash_data_to_access_addr(faddr
),
749 OPTROM_BURST_DWORDS
);
750 if (ret
!= QLA_SUCCESS
) {
751 qla_printk(KERN_WARNING
, ha
,
752 "Unable to burst-write optrom segment "
753 "(%x/%x/%llx).\n", ret
,
754 flash_data_to_access_addr(faddr
),
755 (unsigned long long)optrom_dma
);
756 qla_printk(KERN_WARNING
, ha
,
757 "Reverting to slow-write.\n");
759 dma_free_coherent(&ha
->pdev
->dev
,
760 OPTROM_BURST_SIZE
, optrom
, optrom_dma
);
763 liter
+= OPTROM_BURST_DWORDS
- 1;
764 faddr
+= OPTROM_BURST_DWORDS
- 1;
765 dwptr
+= OPTROM_BURST_DWORDS
- 1;
770 ret
= qla24xx_write_flash_dword(ha
,
771 flash_data_to_access_addr(faddr
), cpu_to_le32(*dwptr
));
772 if (ret
!= QLA_SUCCESS
) {
773 DEBUG9(printk("%s(%ld) Unable to program flash "
774 "address=%x data=%x.\n", __func__
,
775 ha
->host_no
, faddr
, *dwptr
));
779 /* Do sector protect. */
780 if (ha
->fdt_unprotect_sec_cmd
&&
781 ((faddr
& rest_addr
) == rest_addr
))
782 qla24xx_write_flash_dword(ha
,
783 ha
->fdt_protect_sec_cmd
,
784 (fdata
& 0xff00) | ((fdata
<< 16) &
785 0xff0000) | ((fdata
>> 16) & 0xff));
788 qla24xx_protect_flash(ha
);
791 dma_free_coherent(&ha
->pdev
->dev
,
792 OPTROM_BURST_SIZE
, optrom
, optrom_dma
);
798 qla2x00_read_nvram_data(scsi_qla_host_t
*ha
, uint8_t *buf
, uint32_t naddr
,
804 /* Word reads to NVRAM via registers. */
805 wptr
= (uint16_t *)buf
;
806 qla2x00_lock_nvram_access(ha
);
807 for (i
= 0; i
< bytes
>> 1; i
++, naddr
++)
808 wptr
[i
] = cpu_to_le16(qla2x00_get_nvram_word(ha
,
810 qla2x00_unlock_nvram_access(ha
);
816 qla24xx_read_nvram_data(scsi_qla_host_t
*ha
, uint8_t *buf
, uint32_t naddr
,
822 /* Dword reads to flash. */
823 dwptr
= (uint32_t *)buf
;
824 for (i
= 0; i
< bytes
>> 2; i
++, naddr
++)
825 dwptr
[i
] = cpu_to_le32(qla24xx_read_flash_dword(ha
,
826 nvram_data_to_access_addr(naddr
)));
832 qla2x00_write_nvram_data(scsi_qla_host_t
*ha
, uint8_t *buf
, uint32_t naddr
,
842 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
843 qla2x00_lock_nvram_access(ha
);
845 /* Disable NVRAM write-protection. */
846 stat
= qla2x00_clear_nvram_protection(ha
);
848 wptr
= (uint16_t *)buf
;
849 for (i
= 0; i
< bytes
>> 1; i
++, naddr
++) {
850 qla2x00_write_nvram_word(ha
, naddr
,
855 /* Enable NVRAM write-protection. */
856 qla2x00_set_nvram_protection(ha
, stat
);
858 qla2x00_unlock_nvram_access(ha
);
859 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
865 qla24xx_write_nvram_data(scsi_qla_host_t
*ha
, uint8_t *buf
, uint32_t naddr
,
871 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
875 /* Enable flash write. */
876 WRT_REG_DWORD(®
->ctrl_status
,
877 RD_REG_DWORD(®
->ctrl_status
) | CSRX_FLASH_ENABLE
);
878 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
880 /* Disable NVRAM write-protection. */
881 qla24xx_write_flash_dword(ha
, nvram_conf_to_access_addr(0x101),
883 qla24xx_write_flash_dword(ha
, nvram_conf_to_access_addr(0x101),
886 /* Dword writes to flash. */
887 dwptr
= (uint32_t *)buf
;
888 for (i
= 0; i
< bytes
>> 2; i
++, naddr
++, dwptr
++) {
889 ret
= qla24xx_write_flash_dword(ha
,
890 nvram_data_to_access_addr(naddr
),
891 cpu_to_le32(*dwptr
));
892 if (ret
!= QLA_SUCCESS
) {
893 DEBUG9(printk("%s(%ld) Unable to program "
894 "nvram address=%x data=%x.\n", __func__
,
895 ha
->host_no
, naddr
, *dwptr
));
900 /* Enable NVRAM write-protection. */
901 qla24xx_write_flash_dword(ha
, nvram_conf_to_access_addr(0x101),
904 /* Disable flash write. */
905 WRT_REG_DWORD(®
->ctrl_status
,
906 RD_REG_DWORD(®
->ctrl_status
) & ~CSRX_FLASH_ENABLE
);
907 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
913 qla25xx_read_nvram_data(scsi_qla_host_t
*ha
, uint8_t *buf
, uint32_t naddr
,
919 /* Dword reads to flash. */
920 dwptr
= (uint32_t *)buf
;
921 for (i
= 0; i
< bytes
>> 2; i
++, naddr
++)
922 dwptr
[i
] = cpu_to_le32(qla24xx_read_flash_dword(ha
,
923 flash_data_to_access_addr(FA_VPD_NVRAM_ADDR
| naddr
)));
929 qla25xx_write_nvram_data(scsi_qla_host_t
*ha
, uint8_t *buf
, uint32_t naddr
,
932 #define RMW_BUFFER_SIZE (64 * 1024)
935 dbuf
= vmalloc(RMW_BUFFER_SIZE
);
937 return QLA_MEMORY_ALLOC_FAILED
;
938 ha
->isp_ops
->read_optrom(ha
, dbuf
, FA_VPD_NVRAM_ADDR
<< 2,
940 memcpy(dbuf
+ (naddr
<< 2), buf
, bytes
);
941 ha
->isp_ops
->write_optrom(ha
, dbuf
, FA_VPD_NVRAM_ADDR
<< 2,
949 qla2x00_flip_colors(scsi_qla_host_t
*ha
, uint16_t *pflags
)
951 if (IS_QLA2322(ha
)) {
952 /* Flip all colors. */
953 if (ha
->beacon_color_state
== QLA_LED_ALL_ON
) {
955 ha
->beacon_color_state
= 0;
956 *pflags
= GPIO_LED_ALL_OFF
;
959 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
960 *pflags
= GPIO_LED_RGA_ON
;
963 /* Flip green led only. */
964 if (ha
->beacon_color_state
== QLA_LED_GRN_ON
) {
966 ha
->beacon_color_state
= 0;
967 *pflags
= GPIO_LED_GREEN_OFF_AMBER_OFF
;
970 ha
->beacon_color_state
= QLA_LED_GRN_ON
;
971 *pflags
= GPIO_LED_GREEN_ON_AMBER_OFF
;
976 #define PIO_REG(h, r) ((h)->pio_address + offsetof(struct device_reg_2xxx, r))
979 qla2x00_beacon_blink(struct scsi_qla_host
*ha
)
981 uint16_t gpio_enable
;
983 uint16_t led_color
= 0;
985 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
987 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
989 /* Save the Original GPIOE. */
990 if (ha
->pio_address
) {
991 gpio_enable
= RD_REG_WORD_PIO(PIO_REG(ha
, gpioe
));
992 gpio_data
= RD_REG_WORD_PIO(PIO_REG(ha
, gpiod
));
994 gpio_enable
= RD_REG_WORD(®
->gpioe
);
995 gpio_data
= RD_REG_WORD(®
->gpiod
);
998 /* Set the modified gpio_enable values */
999 gpio_enable
|= GPIO_LED_MASK
;
1001 if (ha
->pio_address
) {
1002 WRT_REG_WORD_PIO(PIO_REG(ha
, gpioe
), gpio_enable
);
1004 WRT_REG_WORD(®
->gpioe
, gpio_enable
);
1005 RD_REG_WORD(®
->gpioe
);
1008 qla2x00_flip_colors(ha
, &led_color
);
1010 /* Clear out any previously set LED color. */
1011 gpio_data
&= ~GPIO_LED_MASK
;
1013 /* Set the new input LED color to GPIOD. */
1014 gpio_data
|= led_color
;
1016 /* Set the modified gpio_data values */
1017 if (ha
->pio_address
) {
1018 WRT_REG_WORD_PIO(PIO_REG(ha
, gpiod
), gpio_data
);
1020 WRT_REG_WORD(®
->gpiod
, gpio_data
);
1021 RD_REG_WORD(®
->gpiod
);
1024 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1028 qla2x00_beacon_on(struct scsi_qla_host
*ha
)
1030 uint16_t gpio_enable
;
1032 unsigned long flags
;
1033 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1035 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1036 ha
->fw_options
[1] |= FO1_DISABLE_GPIO6_7
;
1038 if (qla2x00_set_fw_options(ha
, ha
->fw_options
) != QLA_SUCCESS
) {
1039 qla_printk(KERN_WARNING
, ha
,
1040 "Unable to update fw options (beacon on).\n");
1041 return QLA_FUNCTION_FAILED
;
1044 /* Turn off LEDs. */
1045 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1046 if (ha
->pio_address
) {
1047 gpio_enable
= RD_REG_WORD_PIO(PIO_REG(ha
, gpioe
));
1048 gpio_data
= RD_REG_WORD_PIO(PIO_REG(ha
, gpiod
));
1050 gpio_enable
= RD_REG_WORD(®
->gpioe
);
1051 gpio_data
= RD_REG_WORD(®
->gpiod
);
1053 gpio_enable
|= GPIO_LED_MASK
;
1055 /* Set the modified gpio_enable values. */
1056 if (ha
->pio_address
) {
1057 WRT_REG_WORD_PIO(PIO_REG(ha
, gpioe
), gpio_enable
);
1059 WRT_REG_WORD(®
->gpioe
, gpio_enable
);
1060 RD_REG_WORD(®
->gpioe
);
1063 /* Clear out previously set LED colour. */
1064 gpio_data
&= ~GPIO_LED_MASK
;
1065 if (ha
->pio_address
) {
1066 WRT_REG_WORD_PIO(PIO_REG(ha
, gpiod
), gpio_data
);
1068 WRT_REG_WORD(®
->gpiod
, gpio_data
);
1069 RD_REG_WORD(®
->gpiod
);
1071 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1074 * Let the per HBA timer kick off the blinking process based on
1075 * the following flags. No need to do anything else now.
1077 ha
->beacon_blink_led
= 1;
1078 ha
->beacon_color_state
= 0;
1084 qla2x00_beacon_off(struct scsi_qla_host
*ha
)
1086 int rval
= QLA_SUCCESS
;
1088 ha
->beacon_blink_led
= 0;
1090 /* Set the on flag so when it gets flipped it will be off. */
1092 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1094 ha
->beacon_color_state
= QLA_LED_GRN_ON
;
1096 ha
->isp_ops
->beacon_blink(ha
); /* This turns green LED off */
1098 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1099 ha
->fw_options
[1] &= ~FO1_DISABLE_GPIO6_7
;
1101 rval
= qla2x00_set_fw_options(ha
, ha
->fw_options
);
1102 if (rval
!= QLA_SUCCESS
)
1103 qla_printk(KERN_WARNING
, ha
,
1104 "Unable to update fw options (beacon off).\n");
1110 qla24xx_flip_colors(scsi_qla_host_t
*ha
, uint16_t *pflags
)
1112 /* Flip all colors. */
1113 if (ha
->beacon_color_state
== QLA_LED_ALL_ON
) {
1115 ha
->beacon_color_state
= 0;
1119 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1120 *pflags
= GPDX_LED_YELLOW_ON
| GPDX_LED_AMBER_ON
;
1125 qla24xx_beacon_blink(struct scsi_qla_host
*ha
)
1127 uint16_t led_color
= 0;
1129 unsigned long flags
;
1130 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1132 /* Save the Original GPIOD. */
1133 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1134 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1136 /* Enable the gpio_data reg for update. */
1137 gpio_data
|= GPDX_LED_UPDATE_MASK
;
1139 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1140 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1142 /* Set the color bits. */
1143 qla24xx_flip_colors(ha
, &led_color
);
1145 /* Clear out any previously set LED color. */
1146 gpio_data
&= ~GPDX_LED_COLOR_MASK
;
1148 /* Set the new input LED color to GPIOD. */
1149 gpio_data
|= led_color
;
1151 /* Set the modified gpio_data values. */
1152 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1153 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1154 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1158 qla24xx_beacon_on(struct scsi_qla_host
*ha
)
1161 unsigned long flags
;
1162 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1164 if (ha
->beacon_blink_led
== 0) {
1165 /* Enable firmware for update */
1166 ha
->fw_options
[1] |= ADD_FO1_DISABLE_GPIO_LED_CTRL
;
1168 if (qla2x00_set_fw_options(ha
, ha
->fw_options
) != QLA_SUCCESS
)
1169 return QLA_FUNCTION_FAILED
;
1171 if (qla2x00_get_fw_options(ha
, ha
->fw_options
) !=
1173 qla_printk(KERN_WARNING
, ha
,
1174 "Unable to update fw options (beacon on).\n");
1175 return QLA_FUNCTION_FAILED
;
1178 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1179 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1181 /* Enable the gpio_data reg for update. */
1182 gpio_data
|= GPDX_LED_UPDATE_MASK
;
1183 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1184 RD_REG_DWORD(®
->gpiod
);
1186 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1189 /* So all colors blink together. */
1190 ha
->beacon_color_state
= 0;
1192 /* Let the per HBA timer kick off the blinking process. */
1193 ha
->beacon_blink_led
= 1;
1199 qla24xx_beacon_off(struct scsi_qla_host
*ha
)
1202 unsigned long flags
;
1203 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1205 ha
->beacon_blink_led
= 0;
1206 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1208 ha
->isp_ops
->beacon_blink(ha
); /* Will flip to all off. */
1210 /* Give control back to firmware. */
1211 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1212 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1214 /* Disable the gpio_data reg for update. */
1215 gpio_data
&= ~GPDX_LED_UPDATE_MASK
;
1216 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1217 RD_REG_DWORD(®
->gpiod
);
1218 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1220 ha
->fw_options
[1] &= ~ADD_FO1_DISABLE_GPIO_LED_CTRL
;
1222 if (qla2x00_set_fw_options(ha
, ha
->fw_options
) != QLA_SUCCESS
) {
1223 qla_printk(KERN_WARNING
, ha
,
1224 "Unable to update fw options (beacon off).\n");
1225 return QLA_FUNCTION_FAILED
;
1228 if (qla2x00_get_fw_options(ha
, ha
->fw_options
) != QLA_SUCCESS
) {
1229 qla_printk(KERN_WARNING
, ha
,
1230 "Unable to get fw options (beacon off).\n");
1231 return QLA_FUNCTION_FAILED
;
1239 * Flash support routines
1243 * qla2x00_flash_enable() - Setup flash for reading and writing.
1247 qla2x00_flash_enable(scsi_qla_host_t
*ha
)
1250 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1252 data
= RD_REG_WORD(®
->ctrl_status
);
1253 data
|= CSR_FLASH_ENABLE
;
1254 WRT_REG_WORD(®
->ctrl_status
, data
);
1255 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1259 * qla2x00_flash_disable() - Disable flash and allow RISC to run.
1263 qla2x00_flash_disable(scsi_qla_host_t
*ha
)
1266 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1268 data
= RD_REG_WORD(®
->ctrl_status
);
1269 data
&= ~(CSR_FLASH_ENABLE
);
1270 WRT_REG_WORD(®
->ctrl_status
, data
);
1271 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1275 * qla2x00_read_flash_byte() - Reads a byte from flash
1277 * @addr: Address in flash to read
1279 * A word is read from the chip, but, only the lower byte is valid.
1281 * Returns the byte read from flash @addr.
1284 qla2x00_read_flash_byte(scsi_qla_host_t
*ha
, uint32_t addr
)
1287 uint16_t bank_select
;
1288 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1290 bank_select
= RD_REG_WORD(®
->ctrl_status
);
1292 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1293 /* Specify 64K address range: */
1294 /* clear out Module Select and Flash Address bits [19:16]. */
1295 bank_select
&= ~0xf8;
1296 bank_select
|= addr
>> 12 & 0xf0;
1297 bank_select
|= CSR_FLASH_64K_BANK
;
1298 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1299 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1301 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1302 data
= RD_REG_WORD(®
->flash_data
);
1304 return (uint8_t)data
;
1307 /* Setup bit 16 of flash address. */
1308 if ((addr
& BIT_16
) && ((bank_select
& CSR_FLASH_64K_BANK
) == 0)) {
1309 bank_select
|= CSR_FLASH_64K_BANK
;
1310 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1311 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1312 } else if (((addr
& BIT_16
) == 0) &&
1313 (bank_select
& CSR_FLASH_64K_BANK
)) {
1314 bank_select
&= ~(CSR_FLASH_64K_BANK
);
1315 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1316 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1319 /* Always perform IO mapped accesses to the FLASH registers. */
1320 if (ha
->pio_address
) {
1323 WRT_REG_WORD_PIO(PIO_REG(ha
, flash_address
), (uint16_t)addr
);
1325 data
= RD_REG_WORD_PIO(PIO_REG(ha
, flash_data
));
1328 data2
= RD_REG_WORD_PIO(PIO_REG(ha
, flash_data
));
1329 } while (data
!= data2
);
1331 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1332 data
= qla2x00_debounce_register(®
->flash_data
);
1335 return (uint8_t)data
;
1339 * qla2x00_write_flash_byte() - Write a byte to flash
1341 * @addr: Address in flash to write
1342 * @data: Data to write
1345 qla2x00_write_flash_byte(scsi_qla_host_t
*ha
, uint32_t addr
, uint8_t data
)
1347 uint16_t bank_select
;
1348 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1350 bank_select
= RD_REG_WORD(®
->ctrl_status
);
1351 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1352 /* Specify 64K address range: */
1353 /* clear out Module Select and Flash Address bits [19:16]. */
1354 bank_select
&= ~0xf8;
1355 bank_select
|= addr
>> 12 & 0xf0;
1356 bank_select
|= CSR_FLASH_64K_BANK
;
1357 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1358 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1360 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1361 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1362 WRT_REG_WORD(®
->flash_data
, (uint16_t)data
);
1363 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1368 /* Setup bit 16 of flash address. */
1369 if ((addr
& BIT_16
) && ((bank_select
& CSR_FLASH_64K_BANK
) == 0)) {
1370 bank_select
|= CSR_FLASH_64K_BANK
;
1371 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1372 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1373 } else if (((addr
& BIT_16
) == 0) &&
1374 (bank_select
& CSR_FLASH_64K_BANK
)) {
1375 bank_select
&= ~(CSR_FLASH_64K_BANK
);
1376 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1377 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1380 /* Always perform IO mapped accesses to the FLASH registers. */
1381 if (ha
->pio_address
) {
1382 WRT_REG_WORD_PIO(PIO_REG(ha
, flash_address
), (uint16_t)addr
);
1383 WRT_REG_WORD_PIO(PIO_REG(ha
, flash_data
), (uint16_t)data
);
1385 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1386 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1387 WRT_REG_WORD(®
->flash_data
, (uint16_t)data
);
1388 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1393 * qla2x00_poll_flash() - Polls flash for completion.
1395 * @addr: Address in flash to poll
1396 * @poll_data: Data to be polled
1397 * @man_id: Flash manufacturer ID
1398 * @flash_id: Flash ID
1400 * This function polls the device until bit 7 of what is read matches data
1401 * bit 7 or until data bit 5 becomes a 1. If that hapens, the flash ROM timed
1402 * out (a fatal error). The flash book recommeds reading bit 7 again after
1403 * reading bit 5 as a 1.
1405 * Returns 0 on success, else non-zero.
1408 qla2x00_poll_flash(scsi_qla_host_t
*ha
, uint32_t addr
, uint8_t poll_data
,
1409 uint8_t man_id
, uint8_t flash_id
)
1417 /* Wait for 30 seconds for command to finish. */
1419 for (cnt
= 3000000; cnt
; cnt
--) {
1420 flash_data
= qla2x00_read_flash_byte(ha
, addr
);
1421 if ((flash_data
& BIT_7
) == poll_data
) {
1426 if (man_id
!= 0x40 && man_id
!= 0xda) {
1427 if ((flash_data
& BIT_5
) && cnt
> 2)
1438 * qla2x00_program_flash_address() - Programs a flash address
1440 * @addr: Address in flash to program
1441 * @data: Data to be written in flash
1442 * @man_id: Flash manufacturer ID
1443 * @flash_id: Flash ID
1445 * Returns 0 on success, else non-zero.
1448 qla2x00_program_flash_address(scsi_qla_host_t
*ha
, uint32_t addr
, uint8_t data
,
1449 uint8_t man_id
, uint8_t flash_id
)
1451 /* Write Program Command Sequence. */
1452 if (IS_OEM_001(ha
)) {
1453 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1454 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1455 qla2x00_write_flash_byte(ha
, 0xaaa, 0xa0);
1456 qla2x00_write_flash_byte(ha
, addr
, data
);
1458 if (man_id
== 0xda && flash_id
== 0xc1) {
1459 qla2x00_write_flash_byte(ha
, addr
, data
);
1463 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1464 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1465 qla2x00_write_flash_byte(ha
, 0x5555, 0xa0);
1466 qla2x00_write_flash_byte(ha
, addr
, data
);
1472 /* Wait for write to complete. */
1473 return qla2x00_poll_flash(ha
, addr
, data
, man_id
, flash_id
);
1477 * qla2x00_erase_flash() - Erase the flash.
1479 * @man_id: Flash manufacturer ID
1480 * @flash_id: Flash ID
1482 * Returns 0 on success, else non-zero.
1485 qla2x00_erase_flash(scsi_qla_host_t
*ha
, uint8_t man_id
, uint8_t flash_id
)
1487 /* Individual Sector Erase Command Sequence */
1488 if (IS_OEM_001(ha
)) {
1489 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1490 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1491 qla2x00_write_flash_byte(ha
, 0xaaa, 0x80);
1492 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1493 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1494 qla2x00_write_flash_byte(ha
, 0xaaa, 0x10);
1496 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1497 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1498 qla2x00_write_flash_byte(ha
, 0x5555, 0x80);
1499 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1500 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1501 qla2x00_write_flash_byte(ha
, 0x5555, 0x10);
1506 /* Wait for erase to complete. */
1507 return qla2x00_poll_flash(ha
, 0x00, 0x80, man_id
, flash_id
);
1511 * qla2x00_erase_flash_sector() - Erase a flash sector.
1513 * @addr: Flash sector to erase
1514 * @sec_mask: Sector address mask
1515 * @man_id: Flash manufacturer ID
1516 * @flash_id: Flash ID
1518 * Returns 0 on success, else non-zero.
1521 qla2x00_erase_flash_sector(scsi_qla_host_t
*ha
, uint32_t addr
,
1522 uint32_t sec_mask
, uint8_t man_id
, uint8_t flash_id
)
1524 /* Individual Sector Erase Command Sequence */
1525 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1526 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1527 qla2x00_write_flash_byte(ha
, 0x5555, 0x80);
1528 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1529 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1530 if (man_id
== 0x1f && flash_id
== 0x13)
1531 qla2x00_write_flash_byte(ha
, addr
& sec_mask
, 0x10);
1533 qla2x00_write_flash_byte(ha
, addr
& sec_mask
, 0x30);
1537 /* Wait for erase to complete. */
1538 return qla2x00_poll_flash(ha
, addr
, 0x80, man_id
, flash_id
);
1542 * qla2x00_get_flash_manufacturer() - Read manufacturer ID from flash chip.
1543 * @man_id: Flash manufacturer ID
1544 * @flash_id: Flash ID
1547 qla2x00_get_flash_manufacturer(scsi_qla_host_t
*ha
, uint8_t *man_id
,
1550 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1551 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1552 qla2x00_write_flash_byte(ha
, 0x5555, 0x90);
1553 *man_id
= qla2x00_read_flash_byte(ha
, 0x0000);
1554 *flash_id
= qla2x00_read_flash_byte(ha
, 0x0001);
1555 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1556 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1557 qla2x00_write_flash_byte(ha
, 0x5555, 0xf0);
1561 qla2x00_read_flash_data(scsi_qla_host_t
*ha
, uint8_t *tmp_buf
, uint32_t saddr
,
1564 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1565 uint32_t midpoint
, ilength
;
1568 midpoint
= length
/ 2;
1570 WRT_REG_WORD(®
->nvram
, 0);
1571 RD_REG_WORD(®
->nvram
);
1572 for (ilength
= 0; ilength
< length
; saddr
++, ilength
++, tmp_buf
++) {
1573 if (ilength
== midpoint
) {
1574 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
1575 RD_REG_WORD(®
->nvram
);
1577 data
= qla2x00_read_flash_byte(ha
, saddr
);
1586 qla2x00_suspend_hba(struct scsi_qla_host
*ha
)
1589 unsigned long flags
;
1590 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1593 scsi_block_requests(ha
->host
);
1594 ha
->isp_ops
->disable_intrs(ha
);
1595 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1598 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1599 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
1600 RD_REG_WORD(®
->hccr
);
1601 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
1602 for (cnt
= 0; cnt
< 30000; cnt
++) {
1603 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
1610 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1614 qla2x00_resume_hba(struct scsi_qla_host
*ha
)
1617 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1618 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1619 qla2xxx_wake_dpc(ha
);
1620 qla2x00_wait_for_hba_online(ha
);
1621 scsi_unblock_requests(ha
->host
);
1625 qla2x00_read_optrom_data(struct scsi_qla_host
*ha
, uint8_t *buf
,
1626 uint32_t offset
, uint32_t length
)
1628 uint32_t addr
, midpoint
;
1630 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1633 qla2x00_suspend_hba(ha
);
1636 midpoint
= ha
->optrom_size
/ 2;
1638 qla2x00_flash_enable(ha
);
1639 WRT_REG_WORD(®
->nvram
, 0);
1640 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
1641 for (addr
= offset
, data
= buf
; addr
< length
; addr
++, data
++) {
1642 if (addr
== midpoint
) {
1643 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
1644 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
1647 *data
= qla2x00_read_flash_byte(ha
, addr
);
1649 qla2x00_flash_disable(ha
);
1652 qla2x00_resume_hba(ha
);
1658 qla2x00_write_optrom_data(struct scsi_qla_host
*ha
, uint8_t *buf
,
1659 uint32_t offset
, uint32_t length
)
1663 uint8_t man_id
, flash_id
, sec_number
, data
;
1665 uint32_t addr
, liter
, sec_mask
, rest_addr
;
1666 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1669 qla2x00_suspend_hba(ha
);
1674 /* Reset ISP chip. */
1675 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
1676 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
1678 /* Go with write. */
1679 qla2x00_flash_enable(ha
);
1680 do { /* Loop once to provide quick error exit */
1681 /* Structure of flash memory based on manufacturer */
1682 if (IS_OEM_001(ha
)) {
1683 /* OEM variant with special flash part. */
1684 man_id
= flash_id
= 0;
1689 qla2x00_get_flash_manufacturer(ha
, &man_id
, &flash_id
);
1691 case 0x20: /* ST flash. */
1692 if (flash_id
== 0xd2 || flash_id
== 0xe3) {
1694 * ST m29w008at part - 64kb sector size with
1695 * 32kb,8kb,8kb,16kb sectors at memory address
1703 * ST m29w010b part - 16kb sector size
1704 * Default to 16kb sectors
1709 case 0x40: /* Mostel flash. */
1710 /* Mostel v29c51001 part - 512 byte sector size. */
1714 case 0xbf: /* SST flash. */
1715 /* SST39sf10 part - 4kb sector size. */
1719 case 0xda: /* Winbond flash. */
1720 /* Winbond W29EE011 part - 256 byte sector size. */
1724 case 0xc2: /* Macronix flash. */
1725 /* 64k sector size. */
1726 if (flash_id
== 0x38 || flash_id
== 0x4f) {
1731 /* Fall through... */
1733 case 0x1f: /* Atmel flash. */
1734 /* 512k sector size. */
1735 if (flash_id
== 0x13) {
1736 rest_addr
= 0x7fffffff;
1737 sec_mask
= 0x80000000;
1740 /* Fall through... */
1742 case 0x01: /* AMD flash. */
1743 if (flash_id
== 0x38 || flash_id
== 0x40 ||
1745 /* Am29LV081 part - 64kb sector size. */
1746 /* Am29LV002BT part - 64kb sector size. */
1750 } else if (flash_id
== 0x3e) {
1752 * Am29LV008b part - 64kb sector size with
1753 * 32kb,8kb,8kb,16kb sector at memory address
1759 } else if (flash_id
== 0x20 || flash_id
== 0x6e) {
1761 * Am29LV010 part or AM29f010 - 16kb sector
1767 } else if (flash_id
== 0x6d) {
1768 /* Am29LV001 part - 8kb sector size. */
1774 /* Default to 16 kb sector size. */
1781 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1782 if (qla2x00_erase_flash(ha
, man_id
, flash_id
)) {
1783 rval
= QLA_FUNCTION_FAILED
;
1788 for (addr
= offset
, liter
= 0; liter
< length
; liter
++,
1791 /* Are we at the beginning of a sector? */
1792 if ((addr
& rest_addr
) == 0) {
1793 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1794 if (addr
>= 0x10000UL
) {
1795 if (((addr
>> 12) & 0xf0) &&
1797 flash_id
== 0x3e) ||
1799 flash_id
== 0xd2))) {
1801 if (sec_number
== 1) {
1822 } else if (addr
== ha
->optrom_size
/ 2) {
1823 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
1824 RD_REG_WORD(®
->nvram
);
1827 if (flash_id
== 0xda && man_id
== 0xc1) {
1828 qla2x00_write_flash_byte(ha
, 0x5555,
1830 qla2x00_write_flash_byte(ha
, 0x2aaa,
1832 qla2x00_write_flash_byte(ha
, 0x5555,
1834 } else if (!IS_QLA2322(ha
) && !IS_QLA6322(ha
)) {
1836 if (qla2x00_erase_flash_sector(ha
,
1837 addr
, sec_mask
, man_id
,
1839 rval
= QLA_FUNCTION_FAILED
;
1842 if (man_id
== 0x01 && flash_id
== 0x6d)
1847 if (man_id
== 0x01 && flash_id
== 0x6d) {
1848 if (sec_number
== 1 &&
1849 addr
== (rest_addr
- 1)) {
1852 } else if (sec_number
== 3 && (addr
& 0x7ffe)) {
1858 if (qla2x00_program_flash_address(ha
, addr
, data
,
1859 man_id
, flash_id
)) {
1860 rval
= QLA_FUNCTION_FAILED
;
1866 qla2x00_flash_disable(ha
);
1869 qla2x00_resume_hba(ha
);
1875 qla24xx_read_optrom_data(struct scsi_qla_host
*ha
, uint8_t *buf
,
1876 uint32_t offset
, uint32_t length
)
1879 scsi_block_requests(ha
->host
);
1880 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1883 qla24xx_read_flash_data(ha
, (uint32_t *)buf
, offset
>> 2, length
>> 2);
1886 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1887 scsi_unblock_requests(ha
->host
);
1893 qla24xx_write_optrom_data(struct scsi_qla_host
*ha
, uint8_t *buf
,
1894 uint32_t offset
, uint32_t length
)
1899 scsi_block_requests(ha
->host
);
1900 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1902 /* Go with write. */
1903 rval
= qla24xx_write_flash_data(ha
, (uint32_t *)buf
, offset
>> 2,
1906 /* Resume HBA -- RISC reset needed. */
1907 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1908 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1909 qla2xxx_wake_dpc(ha
);
1910 qla2x00_wait_for_hba_online(ha
);
1911 scsi_unblock_requests(ha
->host
);
1917 qla25xx_read_optrom_data(struct scsi_qla_host
*ha
, uint8_t *buf
,
1918 uint32_t offset
, uint32_t length
)
1921 dma_addr_t optrom_dma
;
1924 uint32_t faddr
, left
, burst
;
1928 if (length
< OPTROM_BURST_SIZE
)
1931 optrom
= dma_alloc_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
,
1932 &optrom_dma
, GFP_KERNEL
);
1934 qla_printk(KERN_DEBUG
, ha
,
1935 "Unable to allocate memory for optrom burst read "
1936 "(%x KB).\n", OPTROM_BURST_SIZE
/ 1024);
1942 faddr
= offset
>> 2;
1944 burst
= OPTROM_BURST_DWORDS
;
1949 rval
= qla2x00_dump_ram(ha
, optrom_dma
,
1950 flash_data_to_access_addr(faddr
), burst
);
1952 qla_printk(KERN_WARNING
, ha
,
1953 "Unable to burst-read optrom segment "
1954 "(%x/%x/%llx).\n", rval
,
1955 flash_data_to_access_addr(faddr
),
1956 (unsigned long long)optrom_dma
);
1957 qla_printk(KERN_WARNING
, ha
,
1958 "Reverting to slow-read.\n");
1960 dma_free_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
,
1961 optrom
, optrom_dma
);
1965 memcpy(pbuf
, optrom
, burst
* 4);
1972 dma_free_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
, optrom
,
1978 return qla24xx_read_optrom_data(ha
, buf
, offset
, length
);
1982 * qla2x00_get_fcode_version() - Determine an FCODE image's version.
1984 * @pcids: Pointer to the FCODE PCI data structure
1986 * The process of retrieving the FCODE version information is at best
1987 * described as interesting.
1989 * Within the first 100h bytes of the image an ASCII string is present
1990 * which contains several pieces of information including the FCODE
1991 * version. Unfortunately it seems the only reliable way to retrieve
1992 * the version is by scanning for another sentinel within the string,
1993 * the FCODE build date:
1995 * ... 2.00.02 10/17/02 ...
1997 * Returns QLA_SUCCESS on successful retrieval of version.
2000 qla2x00_get_fcode_version(scsi_qla_host_t
*ha
, uint32_t pcids
)
2002 int ret
= QLA_FUNCTION_FAILED
;
2003 uint32_t istart
, iend
, iter
, vend
;
2004 uint8_t do_next
, rbyte
, *vbyte
;
2006 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2008 /* Skip the PCI data structure. */
2010 ((qla2x00_read_flash_byte(ha
, pcids
+ 0x0B) << 8) |
2011 qla2x00_read_flash_byte(ha
, pcids
+ 0x0A));
2012 iend
= istart
+ 0x100;
2014 /* Scan for the sentinel date string...eeewww. */
2017 while ((iter
< iend
) && !do_next
) {
2019 if (qla2x00_read_flash_byte(ha
, iter
) == '/') {
2020 if (qla2x00_read_flash_byte(ha
, iter
+ 2) ==
2023 else if (qla2x00_read_flash_byte(ha
,
2031 /* Backtrack to previous ' ' (space). */
2033 while ((iter
> istart
) && !do_next
) {
2035 if (qla2x00_read_flash_byte(ha
, iter
) == ' ')
2042 * Mark end of version tag, and find previous ' ' (space) or
2043 * string length (recent FCODE images -- major hack ahead!!!).
2047 while ((iter
> istart
) && !do_next
) {
2049 rbyte
= qla2x00_read_flash_byte(ha
, iter
);
2050 if (rbyte
== ' ' || rbyte
== 0xd || rbyte
== 0x10)
2056 /* Mark beginning of version tag, and copy data. */
2058 if ((vend
- iter
) &&
2059 ((vend
- iter
) < sizeof(ha
->fcode_revision
))) {
2060 vbyte
= ha
->fcode_revision
;
2061 while (iter
<= vend
) {
2062 *vbyte
++ = qla2x00_read_flash_byte(ha
, iter
);
2069 if (ret
!= QLA_SUCCESS
)
2070 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2074 qla2x00_get_flash_version(scsi_qla_host_t
*ha
, void *mbuf
)
2076 int ret
= QLA_SUCCESS
;
2077 uint8_t code_type
, last_image
;
2078 uint32_t pcihdr
, pcids
;
2082 if (!ha
->pio_address
|| !mbuf
)
2083 return QLA_FUNCTION_FAILED
;
2085 memset(ha
->bios_revision
, 0, sizeof(ha
->bios_revision
));
2086 memset(ha
->efi_revision
, 0, sizeof(ha
->efi_revision
));
2087 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2088 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2090 qla2x00_flash_enable(ha
);
2092 /* Begin with first PCI expansion ROM header. */
2096 /* Verify PCI expansion ROM header. */
2097 if (qla2x00_read_flash_byte(ha
, pcihdr
) != 0x55 ||
2098 qla2x00_read_flash_byte(ha
, pcihdr
+ 0x01) != 0xaa) {
2100 DEBUG2(printk("scsi(%ld): No matching ROM "
2101 "signature.\n", ha
->host_no
));
2102 ret
= QLA_FUNCTION_FAILED
;
2106 /* Locate PCI data structure. */
2108 ((qla2x00_read_flash_byte(ha
, pcihdr
+ 0x19) << 8) |
2109 qla2x00_read_flash_byte(ha
, pcihdr
+ 0x18));
2111 /* Validate signature of PCI data structure. */
2112 if (qla2x00_read_flash_byte(ha
, pcids
) != 'P' ||
2113 qla2x00_read_flash_byte(ha
, pcids
+ 0x1) != 'C' ||
2114 qla2x00_read_flash_byte(ha
, pcids
+ 0x2) != 'I' ||
2115 qla2x00_read_flash_byte(ha
, pcids
+ 0x3) != 'R') {
2116 /* Incorrect header. */
2117 DEBUG2(printk("%s(): PCI data struct not found "
2118 "pcir_adr=%x.\n", __func__
, pcids
));
2119 ret
= QLA_FUNCTION_FAILED
;
2124 code_type
= qla2x00_read_flash_byte(ha
, pcids
+ 0x14);
2125 switch (code_type
) {
2126 case ROM_CODE_TYPE_BIOS
:
2127 /* Intel x86, PC-AT compatible. */
2128 ha
->bios_revision
[0] =
2129 qla2x00_read_flash_byte(ha
, pcids
+ 0x12);
2130 ha
->bios_revision
[1] =
2131 qla2x00_read_flash_byte(ha
, pcids
+ 0x13);
2132 DEBUG3(printk("%s(): read BIOS %d.%d.\n", __func__
,
2133 ha
->bios_revision
[1], ha
->bios_revision
[0]));
2135 case ROM_CODE_TYPE_FCODE
:
2136 /* Open Firmware standard for PCI (FCode). */
2138 qla2x00_get_fcode_version(ha
, pcids
);
2140 case ROM_CODE_TYPE_EFI
:
2141 /* Extensible Firmware Interface (EFI). */
2142 ha
->efi_revision
[0] =
2143 qla2x00_read_flash_byte(ha
, pcids
+ 0x12);
2144 ha
->efi_revision
[1] =
2145 qla2x00_read_flash_byte(ha
, pcids
+ 0x13);
2146 DEBUG3(printk("%s(): read EFI %d.%d.\n", __func__
,
2147 ha
->efi_revision
[1], ha
->efi_revision
[0]));
2150 DEBUG2(printk("%s(): Unrecognized code type %x at "
2151 "pcids %x.\n", __func__
, code_type
, pcids
));
2155 last_image
= qla2x00_read_flash_byte(ha
, pcids
+ 0x15) & BIT_7
;
2157 /* Locate next PCI expansion ROM. */
2158 pcihdr
+= ((qla2x00_read_flash_byte(ha
, pcids
+ 0x11) << 8) |
2159 qla2x00_read_flash_byte(ha
, pcids
+ 0x10)) * 512;
2160 } while (!last_image
);
2162 if (IS_QLA2322(ha
)) {
2163 /* Read firmware image information. */
2164 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2166 memset(dbyte
, 0, 8);
2167 dcode
= (uint16_t *)dbyte
;
2169 qla2x00_read_flash_data(ha
, dbyte
, FA_RISC_CODE_ADDR
* 4 + 10,
2171 DEBUG3(printk("%s(%ld): dumping fw ver from flash:\n",
2172 __func__
, ha
->host_no
));
2173 DEBUG3(qla2x00_dump_buffer((uint8_t *)dbyte
, 8));
2175 if ((dcode
[0] == 0xffff && dcode
[1] == 0xffff &&
2176 dcode
[2] == 0xffff && dcode
[3] == 0xffff) ||
2177 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
2179 DEBUG2(printk("%s(): Unrecognized fw revision at "
2180 "%x.\n", __func__
, FA_RISC_CODE_ADDR
* 4));
2182 /* values are in big endian */
2183 ha
->fw_revision
[0] = dbyte
[0] << 16 | dbyte
[1];
2184 ha
->fw_revision
[1] = dbyte
[2] << 16 | dbyte
[3];
2185 ha
->fw_revision
[2] = dbyte
[4] << 16 | dbyte
[5];
2189 qla2x00_flash_disable(ha
);
2195 qla24xx_get_flash_version(scsi_qla_host_t
*ha
, void *mbuf
)
2197 int ret
= QLA_SUCCESS
;
2198 uint32_t pcihdr
, pcids
;
2201 uint8_t code_type
, last_image
;
2205 return QLA_FUNCTION_FAILED
;
2207 memset(ha
->bios_revision
, 0, sizeof(ha
->bios_revision
));
2208 memset(ha
->efi_revision
, 0, sizeof(ha
->efi_revision
));
2209 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2210 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2214 /* Begin with first PCI expansion ROM header. */
2218 /* Verify PCI expansion ROM header. */
2219 qla24xx_read_flash_data(ha
, dcode
, pcihdr
>> 2, 0x20);
2220 bcode
= mbuf
+ (pcihdr
% 4);
2221 if (bcode
[0x0] != 0x55 || bcode
[0x1] != 0xaa) {
2223 DEBUG2(printk("scsi(%ld): No matching ROM "
2224 "signature.\n", ha
->host_no
));
2225 ret
= QLA_FUNCTION_FAILED
;
2229 /* Locate PCI data structure. */
2230 pcids
= pcihdr
+ ((bcode
[0x19] << 8) | bcode
[0x18]);
2232 qla24xx_read_flash_data(ha
, dcode
, pcids
>> 2, 0x20);
2233 bcode
= mbuf
+ (pcihdr
% 4);
2235 /* Validate signature of PCI data structure. */
2236 if (bcode
[0x0] != 'P' || bcode
[0x1] != 'C' ||
2237 bcode
[0x2] != 'I' || bcode
[0x3] != 'R') {
2238 /* Incorrect header. */
2239 DEBUG2(printk("%s(): PCI data struct not found "
2240 "pcir_adr=%x.\n", __func__
, pcids
));
2241 ret
= QLA_FUNCTION_FAILED
;
2246 code_type
= bcode
[0x14];
2247 switch (code_type
) {
2248 case ROM_CODE_TYPE_BIOS
:
2249 /* Intel x86, PC-AT compatible. */
2250 ha
->bios_revision
[0] = bcode
[0x12];
2251 ha
->bios_revision
[1] = bcode
[0x13];
2252 DEBUG3(printk("%s(): read BIOS %d.%d.\n", __func__
,
2253 ha
->bios_revision
[1], ha
->bios_revision
[0]));
2255 case ROM_CODE_TYPE_FCODE
:
2256 /* Open Firmware standard for PCI (FCode). */
2257 ha
->fcode_revision
[0] = bcode
[0x12];
2258 ha
->fcode_revision
[1] = bcode
[0x13];
2259 DEBUG3(printk("%s(): read FCODE %d.%d.\n", __func__
,
2260 ha
->fcode_revision
[1], ha
->fcode_revision
[0]));
2262 case ROM_CODE_TYPE_EFI
:
2263 /* Extensible Firmware Interface (EFI). */
2264 ha
->efi_revision
[0] = bcode
[0x12];
2265 ha
->efi_revision
[1] = bcode
[0x13];
2266 DEBUG3(printk("%s(): read EFI %d.%d.\n", __func__
,
2267 ha
->efi_revision
[1], ha
->efi_revision
[0]));
2270 DEBUG2(printk("%s(): Unrecognized code type %x at "
2271 "pcids %x.\n", __func__
, code_type
, pcids
));
2275 last_image
= bcode
[0x15] & BIT_7
;
2277 /* Locate next PCI expansion ROM. */
2278 pcihdr
+= ((bcode
[0x11] << 8) | bcode
[0x10]) * 512;
2279 } while (!last_image
);
2281 /* Read firmware image information. */
2282 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2285 qla24xx_read_flash_data(ha
, dcode
, FA_RISC_CODE_ADDR
+ 4, 4);
2286 for (i
= 0; i
< 4; i
++)
2287 dcode
[i
] = be32_to_cpu(dcode
[i
]);
2289 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
2290 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
2291 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
2293 DEBUG2(printk("%s(): Unrecognized fw version at %x.\n",
2294 __func__
, FA_RISC_CODE_ADDR
));
2296 ha
->fw_revision
[0] = dcode
[0];
2297 ha
->fw_revision
[1] = dcode
[1];
2298 ha
->fw_revision
[2] = dcode
[2];
2299 ha
->fw_revision
[3] = dcode
[3];
2306 qla2xxx_is_vpd_valid(uint8_t *pos
, uint8_t *end
)
2308 if (pos
>= end
|| *pos
!= 0x82)
2312 if (pos
>= end
|| *pos
!= 0x90)
2316 if (pos
>= end
|| *pos
!= 0x78)
2323 qla2xxx_get_vpd_field(scsi_qla_host_t
*ha
, char *key
, char *str
, size_t size
)
2325 uint8_t *pos
= ha
->vpd
;
2326 uint8_t *end
= pos
+ ha
->vpd_size
;
2329 if (!IS_FWI2_CAPABLE(ha
) || !qla2xxx_is_vpd_valid(pos
, end
))
2332 while (pos
< end
&& *pos
!= 0x78) {
2333 len
= (*pos
== 0x82) ? pos
[1] : pos
[2];
2335 if (!strncmp(pos
, key
, strlen(key
)))
2338 if (*pos
!= 0x90 && *pos
!= 0x91)
2344 if (pos
< end
- len
&& *pos
!= 0x78)
2345 return snprintf(str
, size
, "%.*s", len
, pos
+ 3);
2351 qla2xxx_hw_event_store(scsi_qla_host_t
*ha
, uint32_t *fdata
)
2353 uint32_t d
[2], faddr
;
2355 /* Locate first empty entry. */
2357 if (ha
->hw_event_ptr
>=
2358 ha
->hw_event_start
+ FA_HW_EVENT_SIZE
) {
2359 DEBUG2(qla_printk(KERN_WARNING
, ha
,
2360 "HW event -- Log Full!\n"));
2361 return QLA_MEMORY_ALLOC_FAILED
;
2364 qla24xx_read_flash_data(ha
, d
, ha
->hw_event_ptr
, 2);
2365 faddr
= flash_data_to_access_addr(ha
->hw_event_ptr
);
2366 ha
->hw_event_ptr
+= FA_HW_EVENT_ENTRY_SIZE
;
2367 if (d
[0] == __constant_cpu_to_le32(0xffffffff) &&
2368 d
[1] == __constant_cpu_to_le32(0xffffffff)) {
2369 qla24xx_unprotect_flash(ha
);
2371 qla24xx_write_flash_dword(ha
, faddr
++,
2372 cpu_to_le32(jiffies
));
2373 qla24xx_write_flash_dword(ha
, faddr
++, 0);
2374 qla24xx_write_flash_dword(ha
, faddr
++, *fdata
++);
2375 qla24xx_write_flash_dword(ha
, faddr
++, *fdata
);
2377 qla24xx_protect_flash(ha
);
2385 qla2xxx_hw_event_log(scsi_qla_host_t
*ha
, uint16_t code
, uint16_t d1
,
2386 uint16_t d2
, uint16_t d3
)
2388 #define QMARK(a, b, c, d) \
2389 cpu_to_le32(LSB(a) << 24 | LSB(b) << 16 | LSB(c) << 8 | LSB(d))
2392 uint32_t marker
[2], fdata
[4];
2394 if (ha
->hw_event_start
== 0)
2395 return QLA_FUNCTION_FAILED
;
2397 DEBUG2(qla_printk(KERN_WARNING
, ha
,
2398 "HW event -- code=%x, d1=%x, d2=%x, d3=%x.\n", code
, d1
, d2
, d3
));
2400 /* If marker not already found, locate or write. */
2401 if (!ha
->flags
.hw_event_marker_found
) {
2402 /* Create marker. */
2403 marker
[0] = QMARK('L', ha
->fw_major_version
,
2404 ha
->fw_minor_version
, ha
->fw_subminor_version
);
2405 marker
[1] = QMARK(QLA_DRIVER_MAJOR_VER
, QLA_DRIVER_MINOR_VER
,
2406 QLA_DRIVER_PATCH_VER
, QLA_DRIVER_BETA_VER
);
2408 /* Locate marker. */
2409 ha
->hw_event_ptr
= ha
->hw_event_start
;
2411 qla24xx_read_flash_data(ha
, fdata
, ha
->hw_event_ptr
,
2413 if (fdata
[0] == __constant_cpu_to_le32(0xffffffff) &&
2414 fdata
[1] == __constant_cpu_to_le32(0xffffffff))
2416 ha
->hw_event_ptr
+= FA_HW_EVENT_ENTRY_SIZE
;
2417 if (ha
->hw_event_ptr
>=
2418 ha
->hw_event_start
+ FA_HW_EVENT_SIZE
) {
2419 DEBUG2(qla_printk(KERN_WARNING
, ha
,
2420 "HW event -- Log Full!\n"));
2421 return QLA_MEMORY_ALLOC_FAILED
;
2423 if (fdata
[2] == marker
[0] && fdata
[3] == marker
[1]) {
2424 ha
->flags
.hw_event_marker_found
= 1;
2428 /* No marker, write it. */
2429 if (!ha
->flags
.hw_event_marker_found
) {
2430 rval
= qla2xxx_hw_event_store(ha
, marker
);
2431 if (rval
!= QLA_SUCCESS
) {
2432 DEBUG2(qla_printk(KERN_WARNING
, ha
,
2433 "HW event -- Failed marker write=%x.!\n",
2437 ha
->flags
.hw_event_marker_found
= 1;
2442 fdata
[0] = cpu_to_le32(code
<< 16 | d1
);
2443 fdata
[1] = cpu_to_le32(d2
<< 16 | d3
);
2444 rval
= qla2xxx_hw_event_store(ha
, fdata
);
2445 if (rval
!= QLA_SUCCESS
) {
2446 DEBUG2(qla_printk(KERN_WARNING
, ha
,
2447 "HW event -- Failed error write=%x.!\n",