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
;
876 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
877 /* Enable flash write. */
878 WRT_REG_DWORD(®
->ctrl_status
,
879 RD_REG_DWORD(®
->ctrl_status
) | CSRX_FLASH_ENABLE
);
880 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
882 /* Disable NVRAM write-protection. */
883 qla24xx_write_flash_dword(ha
, nvram_conf_to_access_addr(0x101),
885 qla24xx_write_flash_dword(ha
, nvram_conf_to_access_addr(0x101),
888 /* Dword writes to flash. */
889 dwptr
= (uint32_t *)buf
;
890 for (i
= 0; i
< bytes
>> 2; i
++, naddr
++, dwptr
++) {
891 ret
= qla24xx_write_flash_dword(ha
,
892 nvram_data_to_access_addr(naddr
),
893 cpu_to_le32(*dwptr
));
894 if (ret
!= QLA_SUCCESS
) {
895 DEBUG9(printk("%s(%ld) Unable to program "
896 "nvram address=%x data=%x.\n", __func__
,
897 ha
->host_no
, naddr
, *dwptr
));
902 /* Enable NVRAM write-protection. */
903 qla24xx_write_flash_dword(ha
, nvram_conf_to_access_addr(0x101),
906 /* Disable flash write. */
907 WRT_REG_DWORD(®
->ctrl_status
,
908 RD_REG_DWORD(®
->ctrl_status
) & ~CSRX_FLASH_ENABLE
);
909 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
910 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
916 qla25xx_read_nvram_data(scsi_qla_host_t
*ha
, uint8_t *buf
, uint32_t naddr
,
922 /* Dword reads to flash. */
923 dwptr
= (uint32_t *)buf
;
924 for (i
= 0; i
< bytes
>> 2; i
++, naddr
++)
925 dwptr
[i
] = cpu_to_le32(qla24xx_read_flash_dword(ha
,
926 flash_data_to_access_addr(FA_VPD_NVRAM_ADDR
| naddr
)));
932 qla25xx_write_nvram_data(scsi_qla_host_t
*ha
, uint8_t *buf
, uint32_t naddr
,
935 #define RMW_BUFFER_SIZE (64 * 1024)
938 dbuf
= vmalloc(RMW_BUFFER_SIZE
);
940 return QLA_MEMORY_ALLOC_FAILED
;
941 ha
->isp_ops
->read_optrom(ha
, dbuf
, FA_VPD_NVRAM_ADDR
<< 2,
943 memcpy(dbuf
+ (naddr
<< 2), buf
, bytes
);
944 ha
->isp_ops
->write_optrom(ha
, dbuf
, FA_VPD_NVRAM_ADDR
<< 2,
952 qla2x00_flip_colors(scsi_qla_host_t
*ha
, uint16_t *pflags
)
954 if (IS_QLA2322(ha
)) {
955 /* Flip all colors. */
956 if (ha
->beacon_color_state
== QLA_LED_ALL_ON
) {
958 ha
->beacon_color_state
= 0;
959 *pflags
= GPIO_LED_ALL_OFF
;
962 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
963 *pflags
= GPIO_LED_RGA_ON
;
966 /* Flip green led only. */
967 if (ha
->beacon_color_state
== QLA_LED_GRN_ON
) {
969 ha
->beacon_color_state
= 0;
970 *pflags
= GPIO_LED_GREEN_OFF_AMBER_OFF
;
973 ha
->beacon_color_state
= QLA_LED_GRN_ON
;
974 *pflags
= GPIO_LED_GREEN_ON_AMBER_OFF
;
979 #define PIO_REG(h, r) ((h)->pio_address + offsetof(struct device_reg_2xxx, r))
982 qla2x00_beacon_blink(struct scsi_qla_host
*ha
)
984 uint16_t gpio_enable
;
986 uint16_t led_color
= 0;
988 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
990 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
992 /* Save the Original GPIOE. */
993 if (ha
->pio_address
) {
994 gpio_enable
= RD_REG_WORD_PIO(PIO_REG(ha
, gpioe
));
995 gpio_data
= RD_REG_WORD_PIO(PIO_REG(ha
, gpiod
));
997 gpio_enable
= RD_REG_WORD(®
->gpioe
);
998 gpio_data
= RD_REG_WORD(®
->gpiod
);
1001 /* Set the modified gpio_enable values */
1002 gpio_enable
|= GPIO_LED_MASK
;
1004 if (ha
->pio_address
) {
1005 WRT_REG_WORD_PIO(PIO_REG(ha
, gpioe
), gpio_enable
);
1007 WRT_REG_WORD(®
->gpioe
, gpio_enable
);
1008 RD_REG_WORD(®
->gpioe
);
1011 qla2x00_flip_colors(ha
, &led_color
);
1013 /* Clear out any previously set LED color. */
1014 gpio_data
&= ~GPIO_LED_MASK
;
1016 /* Set the new input LED color to GPIOD. */
1017 gpio_data
|= led_color
;
1019 /* Set the modified gpio_data values */
1020 if (ha
->pio_address
) {
1021 WRT_REG_WORD_PIO(PIO_REG(ha
, gpiod
), gpio_data
);
1023 WRT_REG_WORD(®
->gpiod
, gpio_data
);
1024 RD_REG_WORD(®
->gpiod
);
1027 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1031 qla2x00_beacon_on(struct scsi_qla_host
*ha
)
1033 uint16_t gpio_enable
;
1035 unsigned long flags
;
1036 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1038 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1039 ha
->fw_options
[1] |= FO1_DISABLE_GPIO6_7
;
1041 if (qla2x00_set_fw_options(ha
, ha
->fw_options
) != QLA_SUCCESS
) {
1042 qla_printk(KERN_WARNING
, ha
,
1043 "Unable to update fw options (beacon on).\n");
1044 return QLA_FUNCTION_FAILED
;
1047 /* Turn off LEDs. */
1048 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1049 if (ha
->pio_address
) {
1050 gpio_enable
= RD_REG_WORD_PIO(PIO_REG(ha
, gpioe
));
1051 gpio_data
= RD_REG_WORD_PIO(PIO_REG(ha
, gpiod
));
1053 gpio_enable
= RD_REG_WORD(®
->gpioe
);
1054 gpio_data
= RD_REG_WORD(®
->gpiod
);
1056 gpio_enable
|= GPIO_LED_MASK
;
1058 /* Set the modified gpio_enable values. */
1059 if (ha
->pio_address
) {
1060 WRT_REG_WORD_PIO(PIO_REG(ha
, gpioe
), gpio_enable
);
1062 WRT_REG_WORD(®
->gpioe
, gpio_enable
);
1063 RD_REG_WORD(®
->gpioe
);
1066 /* Clear out previously set LED colour. */
1067 gpio_data
&= ~GPIO_LED_MASK
;
1068 if (ha
->pio_address
) {
1069 WRT_REG_WORD_PIO(PIO_REG(ha
, gpiod
), gpio_data
);
1071 WRT_REG_WORD(®
->gpiod
, gpio_data
);
1072 RD_REG_WORD(®
->gpiod
);
1074 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1077 * Let the per HBA timer kick off the blinking process based on
1078 * the following flags. No need to do anything else now.
1080 ha
->beacon_blink_led
= 1;
1081 ha
->beacon_color_state
= 0;
1087 qla2x00_beacon_off(struct scsi_qla_host
*ha
)
1089 int rval
= QLA_SUCCESS
;
1091 ha
->beacon_blink_led
= 0;
1093 /* Set the on flag so when it gets flipped it will be off. */
1095 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1097 ha
->beacon_color_state
= QLA_LED_GRN_ON
;
1099 ha
->isp_ops
->beacon_blink(ha
); /* This turns green LED off */
1101 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1102 ha
->fw_options
[1] &= ~FO1_DISABLE_GPIO6_7
;
1104 rval
= qla2x00_set_fw_options(ha
, ha
->fw_options
);
1105 if (rval
!= QLA_SUCCESS
)
1106 qla_printk(KERN_WARNING
, ha
,
1107 "Unable to update fw options (beacon off).\n");
1113 qla24xx_flip_colors(scsi_qla_host_t
*ha
, uint16_t *pflags
)
1115 /* Flip all colors. */
1116 if (ha
->beacon_color_state
== QLA_LED_ALL_ON
) {
1118 ha
->beacon_color_state
= 0;
1122 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1123 *pflags
= GPDX_LED_YELLOW_ON
| GPDX_LED_AMBER_ON
;
1128 qla24xx_beacon_blink(struct scsi_qla_host
*ha
)
1130 uint16_t led_color
= 0;
1132 unsigned long flags
;
1133 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1135 /* Save the Original GPIOD. */
1136 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1137 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1139 /* Enable the gpio_data reg for update. */
1140 gpio_data
|= GPDX_LED_UPDATE_MASK
;
1142 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1143 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1145 /* Set the color bits. */
1146 qla24xx_flip_colors(ha
, &led_color
);
1148 /* Clear out any previously set LED color. */
1149 gpio_data
&= ~GPDX_LED_COLOR_MASK
;
1151 /* Set the new input LED color to GPIOD. */
1152 gpio_data
|= led_color
;
1154 /* Set the modified gpio_data values. */
1155 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1156 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1157 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1161 qla24xx_beacon_on(struct scsi_qla_host
*ha
)
1164 unsigned long flags
;
1165 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1167 if (ha
->beacon_blink_led
== 0) {
1168 /* Enable firmware for update */
1169 ha
->fw_options
[1] |= ADD_FO1_DISABLE_GPIO_LED_CTRL
;
1171 if (qla2x00_set_fw_options(ha
, ha
->fw_options
) != QLA_SUCCESS
)
1172 return QLA_FUNCTION_FAILED
;
1174 if (qla2x00_get_fw_options(ha
, ha
->fw_options
) !=
1176 qla_printk(KERN_WARNING
, ha
,
1177 "Unable to update fw options (beacon on).\n");
1178 return QLA_FUNCTION_FAILED
;
1181 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1182 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1184 /* Enable the gpio_data reg for update. */
1185 gpio_data
|= GPDX_LED_UPDATE_MASK
;
1186 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1187 RD_REG_DWORD(®
->gpiod
);
1189 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1192 /* So all colors blink together. */
1193 ha
->beacon_color_state
= 0;
1195 /* Let the per HBA timer kick off the blinking process. */
1196 ha
->beacon_blink_led
= 1;
1202 qla24xx_beacon_off(struct scsi_qla_host
*ha
)
1205 unsigned long flags
;
1206 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1208 ha
->beacon_blink_led
= 0;
1209 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1211 ha
->isp_ops
->beacon_blink(ha
); /* Will flip to all off. */
1213 /* Give control back to firmware. */
1214 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1215 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1217 /* Disable the gpio_data reg for update. */
1218 gpio_data
&= ~GPDX_LED_UPDATE_MASK
;
1219 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1220 RD_REG_DWORD(®
->gpiod
);
1221 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1223 ha
->fw_options
[1] &= ~ADD_FO1_DISABLE_GPIO_LED_CTRL
;
1225 if (qla2x00_set_fw_options(ha
, ha
->fw_options
) != QLA_SUCCESS
) {
1226 qla_printk(KERN_WARNING
, ha
,
1227 "Unable to update fw options (beacon off).\n");
1228 return QLA_FUNCTION_FAILED
;
1231 if (qla2x00_get_fw_options(ha
, ha
->fw_options
) != QLA_SUCCESS
) {
1232 qla_printk(KERN_WARNING
, ha
,
1233 "Unable to get fw options (beacon off).\n");
1234 return QLA_FUNCTION_FAILED
;
1242 * Flash support routines
1246 * qla2x00_flash_enable() - Setup flash for reading and writing.
1250 qla2x00_flash_enable(scsi_qla_host_t
*ha
)
1253 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1255 data
= RD_REG_WORD(®
->ctrl_status
);
1256 data
|= CSR_FLASH_ENABLE
;
1257 WRT_REG_WORD(®
->ctrl_status
, data
);
1258 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1262 * qla2x00_flash_disable() - Disable flash and allow RISC to run.
1266 qla2x00_flash_disable(scsi_qla_host_t
*ha
)
1269 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1271 data
= RD_REG_WORD(®
->ctrl_status
);
1272 data
&= ~(CSR_FLASH_ENABLE
);
1273 WRT_REG_WORD(®
->ctrl_status
, data
);
1274 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1278 * qla2x00_read_flash_byte() - Reads a byte from flash
1280 * @addr: Address in flash to read
1282 * A word is read from the chip, but, only the lower byte is valid.
1284 * Returns the byte read from flash @addr.
1287 qla2x00_read_flash_byte(scsi_qla_host_t
*ha
, uint32_t addr
)
1290 uint16_t bank_select
;
1291 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1293 bank_select
= RD_REG_WORD(®
->ctrl_status
);
1295 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1296 /* Specify 64K address range: */
1297 /* clear out Module Select and Flash Address bits [19:16]. */
1298 bank_select
&= ~0xf8;
1299 bank_select
|= addr
>> 12 & 0xf0;
1300 bank_select
|= CSR_FLASH_64K_BANK
;
1301 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1302 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1304 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1305 data
= RD_REG_WORD(®
->flash_data
);
1307 return (uint8_t)data
;
1310 /* Setup bit 16 of flash address. */
1311 if ((addr
& BIT_16
) && ((bank_select
& CSR_FLASH_64K_BANK
) == 0)) {
1312 bank_select
|= CSR_FLASH_64K_BANK
;
1313 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1314 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1315 } else if (((addr
& BIT_16
) == 0) &&
1316 (bank_select
& CSR_FLASH_64K_BANK
)) {
1317 bank_select
&= ~(CSR_FLASH_64K_BANK
);
1318 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1319 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1322 /* Always perform IO mapped accesses to the FLASH registers. */
1323 if (ha
->pio_address
) {
1326 WRT_REG_WORD_PIO(PIO_REG(ha
, flash_address
), (uint16_t)addr
);
1328 data
= RD_REG_WORD_PIO(PIO_REG(ha
, flash_data
));
1331 data2
= RD_REG_WORD_PIO(PIO_REG(ha
, flash_data
));
1332 } while (data
!= data2
);
1334 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1335 data
= qla2x00_debounce_register(®
->flash_data
);
1338 return (uint8_t)data
;
1342 * qla2x00_write_flash_byte() - Write a byte to flash
1344 * @addr: Address in flash to write
1345 * @data: Data to write
1348 qla2x00_write_flash_byte(scsi_qla_host_t
*ha
, uint32_t addr
, uint8_t data
)
1350 uint16_t bank_select
;
1351 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1353 bank_select
= RD_REG_WORD(®
->ctrl_status
);
1354 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1355 /* Specify 64K address range: */
1356 /* clear out Module Select and Flash Address bits [19:16]. */
1357 bank_select
&= ~0xf8;
1358 bank_select
|= addr
>> 12 & 0xf0;
1359 bank_select
|= CSR_FLASH_64K_BANK
;
1360 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1361 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1363 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1364 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1365 WRT_REG_WORD(®
->flash_data
, (uint16_t)data
);
1366 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1371 /* Setup bit 16 of flash address. */
1372 if ((addr
& BIT_16
) && ((bank_select
& CSR_FLASH_64K_BANK
) == 0)) {
1373 bank_select
|= CSR_FLASH_64K_BANK
;
1374 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1375 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1376 } else if (((addr
& BIT_16
) == 0) &&
1377 (bank_select
& CSR_FLASH_64K_BANK
)) {
1378 bank_select
&= ~(CSR_FLASH_64K_BANK
);
1379 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1380 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1383 /* Always perform IO mapped accesses to the FLASH registers. */
1384 if (ha
->pio_address
) {
1385 WRT_REG_WORD_PIO(PIO_REG(ha
, flash_address
), (uint16_t)addr
);
1386 WRT_REG_WORD_PIO(PIO_REG(ha
, flash_data
), (uint16_t)data
);
1388 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1389 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1390 WRT_REG_WORD(®
->flash_data
, (uint16_t)data
);
1391 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1396 * qla2x00_poll_flash() - Polls flash for completion.
1398 * @addr: Address in flash to poll
1399 * @poll_data: Data to be polled
1400 * @man_id: Flash manufacturer ID
1401 * @flash_id: Flash ID
1403 * This function polls the device until bit 7 of what is read matches data
1404 * bit 7 or until data bit 5 becomes a 1. If that hapens, the flash ROM timed
1405 * out (a fatal error). The flash book recommeds reading bit 7 again after
1406 * reading bit 5 as a 1.
1408 * Returns 0 on success, else non-zero.
1411 qla2x00_poll_flash(scsi_qla_host_t
*ha
, uint32_t addr
, uint8_t poll_data
,
1412 uint8_t man_id
, uint8_t flash_id
)
1420 /* Wait for 30 seconds for command to finish. */
1422 for (cnt
= 3000000; cnt
; cnt
--) {
1423 flash_data
= qla2x00_read_flash_byte(ha
, addr
);
1424 if ((flash_data
& BIT_7
) == poll_data
) {
1429 if (man_id
!= 0x40 && man_id
!= 0xda) {
1430 if ((flash_data
& BIT_5
) && cnt
> 2)
1441 * qla2x00_program_flash_address() - Programs a flash address
1443 * @addr: Address in flash to program
1444 * @data: Data to be written in flash
1445 * @man_id: Flash manufacturer ID
1446 * @flash_id: Flash ID
1448 * Returns 0 on success, else non-zero.
1451 qla2x00_program_flash_address(scsi_qla_host_t
*ha
, uint32_t addr
, uint8_t data
,
1452 uint8_t man_id
, uint8_t flash_id
)
1454 /* Write Program Command Sequence. */
1455 if (IS_OEM_001(ha
)) {
1456 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1457 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1458 qla2x00_write_flash_byte(ha
, 0xaaa, 0xa0);
1459 qla2x00_write_flash_byte(ha
, addr
, data
);
1461 if (man_id
== 0xda && flash_id
== 0xc1) {
1462 qla2x00_write_flash_byte(ha
, addr
, data
);
1466 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1467 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1468 qla2x00_write_flash_byte(ha
, 0x5555, 0xa0);
1469 qla2x00_write_flash_byte(ha
, addr
, data
);
1475 /* Wait for write to complete. */
1476 return qla2x00_poll_flash(ha
, addr
, data
, man_id
, flash_id
);
1480 * qla2x00_erase_flash() - Erase the flash.
1482 * @man_id: Flash manufacturer ID
1483 * @flash_id: Flash ID
1485 * Returns 0 on success, else non-zero.
1488 qla2x00_erase_flash(scsi_qla_host_t
*ha
, uint8_t man_id
, uint8_t flash_id
)
1490 /* Individual Sector Erase Command Sequence */
1491 if (IS_OEM_001(ha
)) {
1492 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1493 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1494 qla2x00_write_flash_byte(ha
, 0xaaa, 0x80);
1495 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1496 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1497 qla2x00_write_flash_byte(ha
, 0xaaa, 0x10);
1499 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1500 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1501 qla2x00_write_flash_byte(ha
, 0x5555, 0x80);
1502 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1503 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1504 qla2x00_write_flash_byte(ha
, 0x5555, 0x10);
1509 /* Wait for erase to complete. */
1510 return qla2x00_poll_flash(ha
, 0x00, 0x80, man_id
, flash_id
);
1514 * qla2x00_erase_flash_sector() - Erase a flash sector.
1516 * @addr: Flash sector to erase
1517 * @sec_mask: Sector address mask
1518 * @man_id: Flash manufacturer ID
1519 * @flash_id: Flash ID
1521 * Returns 0 on success, else non-zero.
1524 qla2x00_erase_flash_sector(scsi_qla_host_t
*ha
, uint32_t addr
,
1525 uint32_t sec_mask
, uint8_t man_id
, uint8_t flash_id
)
1527 /* Individual Sector Erase Command Sequence */
1528 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1529 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1530 qla2x00_write_flash_byte(ha
, 0x5555, 0x80);
1531 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1532 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1533 if (man_id
== 0x1f && flash_id
== 0x13)
1534 qla2x00_write_flash_byte(ha
, addr
& sec_mask
, 0x10);
1536 qla2x00_write_flash_byte(ha
, addr
& sec_mask
, 0x30);
1540 /* Wait for erase to complete. */
1541 return qla2x00_poll_flash(ha
, addr
, 0x80, man_id
, flash_id
);
1545 * qla2x00_get_flash_manufacturer() - Read manufacturer ID from flash chip.
1546 * @man_id: Flash manufacturer ID
1547 * @flash_id: Flash ID
1550 qla2x00_get_flash_manufacturer(scsi_qla_host_t
*ha
, uint8_t *man_id
,
1553 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1554 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1555 qla2x00_write_flash_byte(ha
, 0x5555, 0x90);
1556 *man_id
= qla2x00_read_flash_byte(ha
, 0x0000);
1557 *flash_id
= qla2x00_read_flash_byte(ha
, 0x0001);
1558 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1559 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1560 qla2x00_write_flash_byte(ha
, 0x5555, 0xf0);
1564 qla2x00_read_flash_data(scsi_qla_host_t
*ha
, uint8_t *tmp_buf
, uint32_t saddr
,
1567 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1568 uint32_t midpoint
, ilength
;
1571 midpoint
= length
/ 2;
1573 WRT_REG_WORD(®
->nvram
, 0);
1574 RD_REG_WORD(®
->nvram
);
1575 for (ilength
= 0; ilength
< length
; saddr
++, ilength
++, tmp_buf
++) {
1576 if (ilength
== midpoint
) {
1577 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
1578 RD_REG_WORD(®
->nvram
);
1580 data
= qla2x00_read_flash_byte(ha
, saddr
);
1589 qla2x00_suspend_hba(struct scsi_qla_host
*ha
)
1592 unsigned long flags
;
1593 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1596 scsi_block_requests(ha
->host
);
1597 ha
->isp_ops
->disable_intrs(ha
);
1598 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1601 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1602 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
1603 RD_REG_WORD(®
->hccr
);
1604 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
1605 for (cnt
= 0; cnt
< 30000; cnt
++) {
1606 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
1613 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1617 qla2x00_resume_hba(struct scsi_qla_host
*ha
)
1620 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1621 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1622 qla2xxx_wake_dpc(ha
);
1623 qla2x00_wait_for_hba_online(ha
);
1624 scsi_unblock_requests(ha
->host
);
1628 qla2x00_read_optrom_data(struct scsi_qla_host
*ha
, uint8_t *buf
,
1629 uint32_t offset
, uint32_t length
)
1631 uint32_t addr
, midpoint
;
1633 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1636 qla2x00_suspend_hba(ha
);
1639 midpoint
= ha
->optrom_size
/ 2;
1641 qla2x00_flash_enable(ha
);
1642 WRT_REG_WORD(®
->nvram
, 0);
1643 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
1644 for (addr
= offset
, data
= buf
; addr
< length
; addr
++, data
++) {
1645 if (addr
== midpoint
) {
1646 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
1647 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
1650 *data
= qla2x00_read_flash_byte(ha
, addr
);
1652 qla2x00_flash_disable(ha
);
1655 qla2x00_resume_hba(ha
);
1661 qla2x00_write_optrom_data(struct scsi_qla_host
*ha
, uint8_t *buf
,
1662 uint32_t offset
, uint32_t length
)
1666 uint8_t man_id
, flash_id
, sec_number
, data
;
1668 uint32_t addr
, liter
, sec_mask
, rest_addr
;
1669 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1672 qla2x00_suspend_hba(ha
);
1677 /* Reset ISP chip. */
1678 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
1679 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
1681 /* Go with write. */
1682 qla2x00_flash_enable(ha
);
1683 do { /* Loop once to provide quick error exit */
1684 /* Structure of flash memory based on manufacturer */
1685 if (IS_OEM_001(ha
)) {
1686 /* OEM variant with special flash part. */
1687 man_id
= flash_id
= 0;
1692 qla2x00_get_flash_manufacturer(ha
, &man_id
, &flash_id
);
1694 case 0x20: /* ST flash. */
1695 if (flash_id
== 0xd2 || flash_id
== 0xe3) {
1697 * ST m29w008at part - 64kb sector size with
1698 * 32kb,8kb,8kb,16kb sectors at memory address
1706 * ST m29w010b part - 16kb sector size
1707 * Default to 16kb sectors
1712 case 0x40: /* Mostel flash. */
1713 /* Mostel v29c51001 part - 512 byte sector size. */
1717 case 0xbf: /* SST flash. */
1718 /* SST39sf10 part - 4kb sector size. */
1722 case 0xda: /* Winbond flash. */
1723 /* Winbond W29EE011 part - 256 byte sector size. */
1727 case 0xc2: /* Macronix flash. */
1728 /* 64k sector size. */
1729 if (flash_id
== 0x38 || flash_id
== 0x4f) {
1734 /* Fall through... */
1736 case 0x1f: /* Atmel flash. */
1737 /* 512k sector size. */
1738 if (flash_id
== 0x13) {
1739 rest_addr
= 0x7fffffff;
1740 sec_mask
= 0x80000000;
1743 /* Fall through... */
1745 case 0x01: /* AMD flash. */
1746 if (flash_id
== 0x38 || flash_id
== 0x40 ||
1748 /* Am29LV081 part - 64kb sector size. */
1749 /* Am29LV002BT part - 64kb sector size. */
1753 } else if (flash_id
== 0x3e) {
1755 * Am29LV008b part - 64kb sector size with
1756 * 32kb,8kb,8kb,16kb sector at memory address
1762 } else if (flash_id
== 0x20 || flash_id
== 0x6e) {
1764 * Am29LV010 part or AM29f010 - 16kb sector
1770 } else if (flash_id
== 0x6d) {
1771 /* Am29LV001 part - 8kb sector size. */
1777 /* Default to 16 kb sector size. */
1784 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1785 if (qla2x00_erase_flash(ha
, man_id
, flash_id
)) {
1786 rval
= QLA_FUNCTION_FAILED
;
1791 for (addr
= offset
, liter
= 0; liter
< length
; liter
++,
1794 /* Are we at the beginning of a sector? */
1795 if ((addr
& rest_addr
) == 0) {
1796 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1797 if (addr
>= 0x10000UL
) {
1798 if (((addr
>> 12) & 0xf0) &&
1800 flash_id
== 0x3e) ||
1802 flash_id
== 0xd2))) {
1804 if (sec_number
== 1) {
1825 } else if (addr
== ha
->optrom_size
/ 2) {
1826 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
1827 RD_REG_WORD(®
->nvram
);
1830 if (flash_id
== 0xda && man_id
== 0xc1) {
1831 qla2x00_write_flash_byte(ha
, 0x5555,
1833 qla2x00_write_flash_byte(ha
, 0x2aaa,
1835 qla2x00_write_flash_byte(ha
, 0x5555,
1837 } else if (!IS_QLA2322(ha
) && !IS_QLA6322(ha
)) {
1839 if (qla2x00_erase_flash_sector(ha
,
1840 addr
, sec_mask
, man_id
,
1842 rval
= QLA_FUNCTION_FAILED
;
1845 if (man_id
== 0x01 && flash_id
== 0x6d)
1850 if (man_id
== 0x01 && flash_id
== 0x6d) {
1851 if (sec_number
== 1 &&
1852 addr
== (rest_addr
- 1)) {
1855 } else if (sec_number
== 3 && (addr
& 0x7ffe)) {
1861 if (qla2x00_program_flash_address(ha
, addr
, data
,
1862 man_id
, flash_id
)) {
1863 rval
= QLA_FUNCTION_FAILED
;
1869 qla2x00_flash_disable(ha
);
1872 qla2x00_resume_hba(ha
);
1878 qla24xx_read_optrom_data(struct scsi_qla_host
*ha
, uint8_t *buf
,
1879 uint32_t offset
, uint32_t length
)
1882 scsi_block_requests(ha
->host
);
1883 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1886 qla24xx_read_flash_data(ha
, (uint32_t *)buf
, offset
>> 2, length
>> 2);
1889 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1890 scsi_unblock_requests(ha
->host
);
1896 qla24xx_write_optrom_data(struct scsi_qla_host
*ha
, uint8_t *buf
,
1897 uint32_t offset
, uint32_t length
)
1902 scsi_block_requests(ha
->host
);
1903 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1905 /* Go with write. */
1906 rval
= qla24xx_write_flash_data(ha
, (uint32_t *)buf
, offset
>> 2,
1909 /* Resume HBA -- RISC reset needed. */
1910 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1911 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1912 qla2xxx_wake_dpc(ha
);
1913 qla2x00_wait_for_hba_online(ha
);
1914 scsi_unblock_requests(ha
->host
);
1920 qla25xx_read_optrom_data(struct scsi_qla_host
*ha
, uint8_t *buf
,
1921 uint32_t offset
, uint32_t length
)
1924 dma_addr_t optrom_dma
;
1927 uint32_t faddr
, left
, burst
;
1931 if (length
< OPTROM_BURST_SIZE
)
1934 optrom
= dma_alloc_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
,
1935 &optrom_dma
, GFP_KERNEL
);
1937 qla_printk(KERN_DEBUG
, ha
,
1938 "Unable to allocate memory for optrom burst read "
1939 "(%x KB).\n", OPTROM_BURST_SIZE
/ 1024);
1945 faddr
= offset
>> 2;
1947 burst
= OPTROM_BURST_DWORDS
;
1952 rval
= qla2x00_dump_ram(ha
, optrom_dma
,
1953 flash_data_to_access_addr(faddr
), burst
);
1955 qla_printk(KERN_WARNING
, ha
,
1956 "Unable to burst-read optrom segment "
1957 "(%x/%x/%llx).\n", rval
,
1958 flash_data_to_access_addr(faddr
),
1959 (unsigned long long)optrom_dma
);
1960 qla_printk(KERN_WARNING
, ha
,
1961 "Reverting to slow-read.\n");
1963 dma_free_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
,
1964 optrom
, optrom_dma
);
1968 memcpy(pbuf
, optrom
, burst
* 4);
1975 dma_free_coherent(&ha
->pdev
->dev
, OPTROM_BURST_SIZE
, optrom
,
1981 return qla24xx_read_optrom_data(ha
, buf
, offset
, length
);
1985 * qla2x00_get_fcode_version() - Determine an FCODE image's version.
1987 * @pcids: Pointer to the FCODE PCI data structure
1989 * The process of retrieving the FCODE version information is at best
1990 * described as interesting.
1992 * Within the first 100h bytes of the image an ASCII string is present
1993 * which contains several pieces of information including the FCODE
1994 * version. Unfortunately it seems the only reliable way to retrieve
1995 * the version is by scanning for another sentinel within the string,
1996 * the FCODE build date:
1998 * ... 2.00.02 10/17/02 ...
2000 * Returns QLA_SUCCESS on successful retrieval of version.
2003 qla2x00_get_fcode_version(scsi_qla_host_t
*ha
, uint32_t pcids
)
2005 int ret
= QLA_FUNCTION_FAILED
;
2006 uint32_t istart
, iend
, iter
, vend
;
2007 uint8_t do_next
, rbyte
, *vbyte
;
2009 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2011 /* Skip the PCI data structure. */
2013 ((qla2x00_read_flash_byte(ha
, pcids
+ 0x0B) << 8) |
2014 qla2x00_read_flash_byte(ha
, pcids
+ 0x0A));
2015 iend
= istart
+ 0x100;
2017 /* Scan for the sentinel date string...eeewww. */
2020 while ((iter
< iend
) && !do_next
) {
2022 if (qla2x00_read_flash_byte(ha
, iter
) == '/') {
2023 if (qla2x00_read_flash_byte(ha
, iter
+ 2) ==
2026 else if (qla2x00_read_flash_byte(ha
,
2034 /* Backtrack to previous ' ' (space). */
2036 while ((iter
> istart
) && !do_next
) {
2038 if (qla2x00_read_flash_byte(ha
, iter
) == ' ')
2045 * Mark end of version tag, and find previous ' ' (space) or
2046 * string length (recent FCODE images -- major hack ahead!!!).
2050 while ((iter
> istart
) && !do_next
) {
2052 rbyte
= qla2x00_read_flash_byte(ha
, iter
);
2053 if (rbyte
== ' ' || rbyte
== 0xd || rbyte
== 0x10)
2059 /* Mark beginning of version tag, and copy data. */
2061 if ((vend
- iter
) &&
2062 ((vend
- iter
) < sizeof(ha
->fcode_revision
))) {
2063 vbyte
= ha
->fcode_revision
;
2064 while (iter
<= vend
) {
2065 *vbyte
++ = qla2x00_read_flash_byte(ha
, iter
);
2072 if (ret
!= QLA_SUCCESS
)
2073 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2077 qla2x00_get_flash_version(scsi_qla_host_t
*ha
, void *mbuf
)
2079 int ret
= QLA_SUCCESS
;
2080 uint8_t code_type
, last_image
;
2081 uint32_t pcihdr
, pcids
;
2085 if (!ha
->pio_address
|| !mbuf
)
2086 return QLA_FUNCTION_FAILED
;
2088 memset(ha
->bios_revision
, 0, sizeof(ha
->bios_revision
));
2089 memset(ha
->efi_revision
, 0, sizeof(ha
->efi_revision
));
2090 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2091 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2093 qla2x00_flash_enable(ha
);
2095 /* Begin with first PCI expansion ROM header. */
2099 /* Verify PCI expansion ROM header. */
2100 if (qla2x00_read_flash_byte(ha
, pcihdr
) != 0x55 ||
2101 qla2x00_read_flash_byte(ha
, pcihdr
+ 0x01) != 0xaa) {
2103 DEBUG2(printk("scsi(%ld): No matching ROM "
2104 "signature.\n", ha
->host_no
));
2105 ret
= QLA_FUNCTION_FAILED
;
2109 /* Locate PCI data structure. */
2111 ((qla2x00_read_flash_byte(ha
, pcihdr
+ 0x19) << 8) |
2112 qla2x00_read_flash_byte(ha
, pcihdr
+ 0x18));
2114 /* Validate signature of PCI data structure. */
2115 if (qla2x00_read_flash_byte(ha
, pcids
) != 'P' ||
2116 qla2x00_read_flash_byte(ha
, pcids
+ 0x1) != 'C' ||
2117 qla2x00_read_flash_byte(ha
, pcids
+ 0x2) != 'I' ||
2118 qla2x00_read_flash_byte(ha
, pcids
+ 0x3) != 'R') {
2119 /* Incorrect header. */
2120 DEBUG2(printk("%s(): PCI data struct not found "
2121 "pcir_adr=%x.\n", __func__
, pcids
));
2122 ret
= QLA_FUNCTION_FAILED
;
2127 code_type
= qla2x00_read_flash_byte(ha
, pcids
+ 0x14);
2128 switch (code_type
) {
2129 case ROM_CODE_TYPE_BIOS
:
2130 /* Intel x86, PC-AT compatible. */
2131 ha
->bios_revision
[0] =
2132 qla2x00_read_flash_byte(ha
, pcids
+ 0x12);
2133 ha
->bios_revision
[1] =
2134 qla2x00_read_flash_byte(ha
, pcids
+ 0x13);
2135 DEBUG3(printk("%s(): read BIOS %d.%d.\n", __func__
,
2136 ha
->bios_revision
[1], ha
->bios_revision
[0]));
2138 case ROM_CODE_TYPE_FCODE
:
2139 /* Open Firmware standard for PCI (FCode). */
2141 qla2x00_get_fcode_version(ha
, pcids
);
2143 case ROM_CODE_TYPE_EFI
:
2144 /* Extensible Firmware Interface (EFI). */
2145 ha
->efi_revision
[0] =
2146 qla2x00_read_flash_byte(ha
, pcids
+ 0x12);
2147 ha
->efi_revision
[1] =
2148 qla2x00_read_flash_byte(ha
, pcids
+ 0x13);
2149 DEBUG3(printk("%s(): read EFI %d.%d.\n", __func__
,
2150 ha
->efi_revision
[1], ha
->efi_revision
[0]));
2153 DEBUG2(printk("%s(): Unrecognized code type %x at "
2154 "pcids %x.\n", __func__
, code_type
, pcids
));
2158 last_image
= qla2x00_read_flash_byte(ha
, pcids
+ 0x15) & BIT_7
;
2160 /* Locate next PCI expansion ROM. */
2161 pcihdr
+= ((qla2x00_read_flash_byte(ha
, pcids
+ 0x11) << 8) |
2162 qla2x00_read_flash_byte(ha
, pcids
+ 0x10)) * 512;
2163 } while (!last_image
);
2165 if (IS_QLA2322(ha
)) {
2166 /* Read firmware image information. */
2167 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2169 memset(dbyte
, 0, 8);
2170 dcode
= (uint16_t *)dbyte
;
2172 qla2x00_read_flash_data(ha
, dbyte
, FA_RISC_CODE_ADDR
* 4 + 10,
2174 DEBUG3(printk("%s(%ld): dumping fw ver from flash:\n",
2175 __func__
, ha
->host_no
));
2176 DEBUG3(qla2x00_dump_buffer((uint8_t *)dbyte
, 8));
2178 if ((dcode
[0] == 0xffff && dcode
[1] == 0xffff &&
2179 dcode
[2] == 0xffff && dcode
[3] == 0xffff) ||
2180 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
2182 DEBUG2(printk("%s(): Unrecognized fw revision at "
2183 "%x.\n", __func__
, FA_RISC_CODE_ADDR
* 4));
2185 /* values are in big endian */
2186 ha
->fw_revision
[0] = dbyte
[0] << 16 | dbyte
[1];
2187 ha
->fw_revision
[1] = dbyte
[2] << 16 | dbyte
[3];
2188 ha
->fw_revision
[2] = dbyte
[4] << 16 | dbyte
[5];
2192 qla2x00_flash_disable(ha
);
2198 qla24xx_get_flash_version(scsi_qla_host_t
*ha
, void *mbuf
)
2200 int ret
= QLA_SUCCESS
;
2201 uint32_t pcihdr
, pcids
;
2204 uint8_t code_type
, last_image
;
2208 return QLA_FUNCTION_FAILED
;
2210 memset(ha
->bios_revision
, 0, sizeof(ha
->bios_revision
));
2211 memset(ha
->efi_revision
, 0, sizeof(ha
->efi_revision
));
2212 memset(ha
->fcode_revision
, 0, sizeof(ha
->fcode_revision
));
2213 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2217 /* Begin with first PCI expansion ROM header. */
2221 /* Verify PCI expansion ROM header. */
2222 qla24xx_read_flash_data(ha
, dcode
, pcihdr
>> 2, 0x20);
2223 bcode
= mbuf
+ (pcihdr
% 4);
2224 if (bcode
[0x0] != 0x55 || bcode
[0x1] != 0xaa) {
2226 DEBUG2(printk("scsi(%ld): No matching ROM "
2227 "signature.\n", ha
->host_no
));
2228 ret
= QLA_FUNCTION_FAILED
;
2232 /* Locate PCI data structure. */
2233 pcids
= pcihdr
+ ((bcode
[0x19] << 8) | bcode
[0x18]);
2235 qla24xx_read_flash_data(ha
, dcode
, pcids
>> 2, 0x20);
2236 bcode
= mbuf
+ (pcihdr
% 4);
2238 /* Validate signature of PCI data structure. */
2239 if (bcode
[0x0] != 'P' || bcode
[0x1] != 'C' ||
2240 bcode
[0x2] != 'I' || bcode
[0x3] != 'R') {
2241 /* Incorrect header. */
2242 DEBUG2(printk("%s(): PCI data struct not found "
2243 "pcir_adr=%x.\n", __func__
, pcids
));
2244 ret
= QLA_FUNCTION_FAILED
;
2249 code_type
= bcode
[0x14];
2250 switch (code_type
) {
2251 case ROM_CODE_TYPE_BIOS
:
2252 /* Intel x86, PC-AT compatible. */
2253 ha
->bios_revision
[0] = bcode
[0x12];
2254 ha
->bios_revision
[1] = bcode
[0x13];
2255 DEBUG3(printk("%s(): read BIOS %d.%d.\n", __func__
,
2256 ha
->bios_revision
[1], ha
->bios_revision
[0]));
2258 case ROM_CODE_TYPE_FCODE
:
2259 /* Open Firmware standard for PCI (FCode). */
2260 ha
->fcode_revision
[0] = bcode
[0x12];
2261 ha
->fcode_revision
[1] = bcode
[0x13];
2262 DEBUG3(printk("%s(): read FCODE %d.%d.\n", __func__
,
2263 ha
->fcode_revision
[1], ha
->fcode_revision
[0]));
2265 case ROM_CODE_TYPE_EFI
:
2266 /* Extensible Firmware Interface (EFI). */
2267 ha
->efi_revision
[0] = bcode
[0x12];
2268 ha
->efi_revision
[1] = bcode
[0x13];
2269 DEBUG3(printk("%s(): read EFI %d.%d.\n", __func__
,
2270 ha
->efi_revision
[1], ha
->efi_revision
[0]));
2273 DEBUG2(printk("%s(): Unrecognized code type %x at "
2274 "pcids %x.\n", __func__
, code_type
, pcids
));
2278 last_image
= bcode
[0x15] & BIT_7
;
2280 /* Locate next PCI expansion ROM. */
2281 pcihdr
+= ((bcode
[0x11] << 8) | bcode
[0x10]) * 512;
2282 } while (!last_image
);
2284 /* Read firmware image information. */
2285 memset(ha
->fw_revision
, 0, sizeof(ha
->fw_revision
));
2288 qla24xx_read_flash_data(ha
, dcode
, FA_RISC_CODE_ADDR
+ 4, 4);
2289 for (i
= 0; i
< 4; i
++)
2290 dcode
[i
] = be32_to_cpu(dcode
[i
]);
2292 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
2293 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
2294 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
2296 DEBUG2(printk("%s(): Unrecognized fw version at %x.\n",
2297 __func__
, FA_RISC_CODE_ADDR
));
2299 ha
->fw_revision
[0] = dcode
[0];
2300 ha
->fw_revision
[1] = dcode
[1];
2301 ha
->fw_revision
[2] = dcode
[2];
2302 ha
->fw_revision
[3] = dcode
[3];
2309 qla2xxx_hw_event_store(scsi_qla_host_t
*ha
, uint32_t *fdata
)
2311 uint32_t d
[2], faddr
;
2313 /* Locate first empty entry. */
2315 if (ha
->hw_event_ptr
>=
2316 ha
->hw_event_start
+ FA_HW_EVENT_SIZE
) {
2317 DEBUG2(qla_printk(KERN_WARNING
, ha
,
2318 "HW event -- Log Full!\n"));
2319 return QLA_MEMORY_ALLOC_FAILED
;
2322 qla24xx_read_flash_data(ha
, d
, ha
->hw_event_ptr
, 2);
2323 faddr
= flash_data_to_access_addr(ha
->hw_event_ptr
);
2324 ha
->hw_event_ptr
+= FA_HW_EVENT_ENTRY_SIZE
;
2325 if (d
[0] == __constant_cpu_to_le32(0xffffffff) &&
2326 d
[1] == __constant_cpu_to_le32(0xffffffff)) {
2327 qla24xx_unprotect_flash(ha
);
2329 qla24xx_write_flash_dword(ha
, faddr
++,
2330 cpu_to_le32(jiffies
));
2331 qla24xx_write_flash_dword(ha
, faddr
++, 0);
2332 qla24xx_write_flash_dword(ha
, faddr
++, *fdata
++);
2333 qla24xx_write_flash_dword(ha
, faddr
++, *fdata
);
2335 qla24xx_protect_flash(ha
);
2343 qla2xxx_hw_event_log(scsi_qla_host_t
*ha
, uint16_t code
, uint16_t d1
,
2344 uint16_t d2
, uint16_t d3
)
2346 #define QMARK(a, b, c, d) \
2347 cpu_to_le32(LSB(a) << 24 | LSB(b) << 16 | LSB(c) << 8 | LSB(d))
2350 uint32_t marker
[2], fdata
[4];
2352 if (ha
->hw_event_start
== 0)
2353 return QLA_FUNCTION_FAILED
;
2355 DEBUG2(qla_printk(KERN_WARNING
, ha
,
2356 "HW event -- code=%x, d1=%x, d2=%x, d3=%x.\n", code
, d1
, d2
, d3
));
2358 /* If marker not already found, locate or write. */
2359 if (!ha
->flags
.hw_event_marker_found
) {
2360 /* Create marker. */
2361 marker
[0] = QMARK('L', ha
->fw_major_version
,
2362 ha
->fw_minor_version
, ha
->fw_subminor_version
);
2363 marker
[1] = QMARK(QLA_DRIVER_MAJOR_VER
, QLA_DRIVER_MINOR_VER
,
2364 QLA_DRIVER_PATCH_VER
, QLA_DRIVER_BETA_VER
);
2366 /* Locate marker. */
2367 ha
->hw_event_ptr
= ha
->hw_event_start
;
2369 qla24xx_read_flash_data(ha
, fdata
, ha
->hw_event_ptr
,
2371 if (fdata
[0] == __constant_cpu_to_le32(0xffffffff) &&
2372 fdata
[1] == __constant_cpu_to_le32(0xffffffff))
2374 ha
->hw_event_ptr
+= FA_HW_EVENT_ENTRY_SIZE
;
2375 if (ha
->hw_event_ptr
>=
2376 ha
->hw_event_start
+ FA_HW_EVENT_SIZE
) {
2377 DEBUG2(qla_printk(KERN_WARNING
, ha
,
2378 "HW event -- Log Full!\n"));
2379 return QLA_MEMORY_ALLOC_FAILED
;
2381 if (fdata
[2] == marker
[0] && fdata
[3] == marker
[1]) {
2382 ha
->flags
.hw_event_marker_found
= 1;
2386 /* No marker, write it. */
2387 if (!ha
->flags
.hw_event_marker_found
) {
2388 rval
= qla2xxx_hw_event_store(ha
, marker
);
2389 if (rval
!= QLA_SUCCESS
) {
2390 DEBUG2(qla_printk(KERN_WARNING
, ha
,
2391 "HW event -- Failed marker write=%x.!\n",
2395 ha
->flags
.hw_event_marker_found
= 1;
2400 fdata
[0] = cpu_to_le32(code
<< 16 | d1
);
2401 fdata
[1] = cpu_to_le32(d2
<< 16 | d3
);
2402 rval
= qla2xxx_hw_event_store(ha
, fdata
);
2403 if (rval
!= QLA_SUCCESS
) {
2404 DEBUG2(qla_printk(KERN_WARNING
, ha
,
2405 "HW event -- Failed error write=%x.!\n",