2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
10 #include <asm/uaccess.h>
12 static uint16_t qla2x00_nvram_request(scsi_qla_host_t
*, uint32_t);
13 static void qla2x00_nv_deselect(scsi_qla_host_t
*);
14 static void qla2x00_nv_write(scsi_qla_host_t
*, uint16_t);
17 * NVRAM support routines
21 * qla2x00_lock_nvram_access() -
25 qla2x00_lock_nvram_access(scsi_qla_host_t
*ha
)
28 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
30 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
)) {
31 data
= RD_REG_WORD(®
->nvram
);
32 while (data
& NVR_BUSY
) {
34 data
= RD_REG_WORD(®
->nvram
);
38 WRT_REG_WORD(®
->u
.isp2300
.host_semaphore
, 0x1);
39 RD_REG_WORD(®
->u
.isp2300
.host_semaphore
);
41 data
= RD_REG_WORD(®
->u
.isp2300
.host_semaphore
);
42 while ((data
& BIT_0
) == 0) {
45 WRT_REG_WORD(®
->u
.isp2300
.host_semaphore
, 0x1);
46 RD_REG_WORD(®
->u
.isp2300
.host_semaphore
);
48 data
= RD_REG_WORD(®
->u
.isp2300
.host_semaphore
);
54 * qla2x00_unlock_nvram_access() -
58 qla2x00_unlock_nvram_access(scsi_qla_host_t
*ha
)
60 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
62 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
)) {
63 WRT_REG_WORD(®
->u
.isp2300
.host_semaphore
, 0);
64 RD_REG_WORD(®
->u
.isp2300
.host_semaphore
);
69 * qla2x00_get_nvram_word() - Calculates word position in NVRAM and calls the
70 * request routine to get the word from NVRAM.
72 * @addr: Address in NVRAM to read
74 * Returns the word read from nvram @addr.
77 qla2x00_get_nvram_word(scsi_qla_host_t
*ha
, uint32_t addr
)
84 data
= qla2x00_nvram_request(ha
, nv_cmd
);
90 * qla2x00_write_nvram_word() - Write NVRAM data.
92 * @addr: Address in NVRAM to write
93 * @data: word to program
96 qla2x00_write_nvram_word(scsi_qla_host_t
*ha
, uint32_t addr
, uint16_t data
)
100 uint32_t nv_cmd
, wait_cnt
;
101 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
103 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
104 qla2x00_nv_write(ha
, 0);
105 qla2x00_nv_write(ha
, 0);
107 for (word
= 0; word
< 8; word
++)
108 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
110 qla2x00_nv_deselect(ha
);
113 nv_cmd
= (addr
<< 16) | NV_WRITE_OP
;
116 for (count
= 0; count
< 27; count
++) {
118 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
120 qla2x00_nv_write(ha
, 0);
125 qla2x00_nv_deselect(ha
);
127 /* Wait for NVRAM to become ready */
128 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
129 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
130 wait_cnt
= NVR_WAIT_CNT
;
133 DEBUG9_10(printk("%s(%ld): NVRAM didn't go ready...\n",
134 __func__
, ha
->host_no
));
138 word
= RD_REG_WORD(®
->nvram
);
139 } while ((word
& NVR_DATA_IN
) == 0);
141 qla2x00_nv_deselect(ha
);
144 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
145 for (count
= 0; count
< 10; count
++)
146 qla2x00_nv_write(ha
, 0);
148 qla2x00_nv_deselect(ha
);
152 qla2x00_write_nvram_word_tmo(scsi_qla_host_t
*ha
, uint32_t addr
, uint16_t data
,
158 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
162 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
163 qla2x00_nv_write(ha
, 0);
164 qla2x00_nv_write(ha
, 0);
166 for (word
= 0; word
< 8; word
++)
167 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
169 qla2x00_nv_deselect(ha
);
172 nv_cmd
= (addr
<< 16) | NV_WRITE_OP
;
175 for (count
= 0; count
< 27; count
++) {
177 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
179 qla2x00_nv_write(ha
, 0);
184 qla2x00_nv_deselect(ha
);
186 /* Wait for NVRAM to become ready */
187 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
188 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
191 word
= RD_REG_WORD(®
->nvram
);
193 ret
= QLA_FUNCTION_FAILED
;
196 } while ((word
& NVR_DATA_IN
) == 0);
198 qla2x00_nv_deselect(ha
);
201 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
202 for (count
= 0; count
< 10; count
++)
203 qla2x00_nv_write(ha
, 0);
205 qla2x00_nv_deselect(ha
);
211 * qla2x00_nvram_request() - Sends read command to NVRAM and gets data from
214 * @nv_cmd: NVRAM command
216 * Bit definitions for NVRAM command:
219 * Bit 25, 24 = opcode
220 * Bit 23-16 = address
221 * Bit 15-0 = write data
223 * Returns the word read from nvram @addr.
226 qla2x00_nvram_request(scsi_qla_host_t
*ha
, uint32_t nv_cmd
)
229 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
233 /* Send command to NVRAM. */
235 for (cnt
= 0; cnt
< 11; cnt
++) {
237 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
239 qla2x00_nv_write(ha
, 0);
243 /* Read data from NVRAM. */
244 for (cnt
= 0; cnt
< 16; cnt
++) {
245 WRT_REG_WORD(®
->nvram
, NVR_SELECT
| NVR_CLOCK
);
246 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
249 reg_data
= RD_REG_WORD(®
->nvram
);
250 if (reg_data
& NVR_DATA_IN
)
252 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
253 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
258 WRT_REG_WORD(®
->nvram
, NVR_DESELECT
);
259 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
266 * qla2x00_nv_write() - Clean NVRAM operations.
270 qla2x00_nv_deselect(scsi_qla_host_t
*ha
)
272 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
274 WRT_REG_WORD(®
->nvram
, NVR_DESELECT
);
275 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
280 * qla2x00_nv_write() - Prepare for NVRAM read/write operation.
282 * @data: Serial interface selector
285 qla2x00_nv_write(scsi_qla_host_t
*ha
, uint16_t data
)
287 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
289 WRT_REG_WORD(®
->nvram
, data
| NVR_SELECT
| NVR_WRT_ENABLE
);
290 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
292 WRT_REG_WORD(®
->nvram
, data
| NVR_SELECT
| NVR_CLOCK
|
294 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
296 WRT_REG_WORD(®
->nvram
, data
| NVR_SELECT
| NVR_WRT_ENABLE
);
297 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
302 * qla2x00_clear_nvram_protection() -
306 qla2x00_clear_nvram_protection(scsi_qla_host_t
*ha
)
309 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
310 uint32_t word
, wait_cnt
;
311 uint16_t wprot
, wprot_old
;
313 /* Clear NVRAM write protection. */
314 ret
= QLA_FUNCTION_FAILED
;
316 wprot_old
= cpu_to_le16(qla2x00_get_nvram_word(ha
, ha
->nvram_base
));
317 stat
= qla2x00_write_nvram_word_tmo(ha
, ha
->nvram_base
,
318 __constant_cpu_to_le16(0x1234), 100000);
319 wprot
= cpu_to_le16(qla2x00_get_nvram_word(ha
, ha
->nvram_base
));
320 if (stat
!= QLA_SUCCESS
|| wprot
!= 0x1234) {
322 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
323 qla2x00_nv_write(ha
, 0);
324 qla2x00_nv_write(ha
, 0);
325 for (word
= 0; word
< 8; word
++)
326 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
328 qla2x00_nv_deselect(ha
);
330 /* Enable protection register. */
331 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
332 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
333 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
334 for (word
= 0; word
< 8; word
++)
335 qla2x00_nv_write(ha
, NVR_DATA_OUT
| NVR_PR_ENABLE
);
337 qla2x00_nv_deselect(ha
);
339 /* Clear protection register (ffff is cleared). */
340 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
341 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
342 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
343 for (word
= 0; word
< 8; word
++)
344 qla2x00_nv_write(ha
, NVR_DATA_OUT
| NVR_PR_ENABLE
);
346 qla2x00_nv_deselect(ha
);
348 /* Wait for NVRAM to become ready. */
349 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
350 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
351 wait_cnt
= NVR_WAIT_CNT
;
354 DEBUG9_10(printk("%s(%ld): NVRAM didn't go "
355 "ready...\n", __func__
,
360 word
= RD_REG_WORD(®
->nvram
);
361 } while ((word
& NVR_DATA_IN
) == 0);
366 qla2x00_write_nvram_word(ha
, ha
->nvram_base
, wprot_old
);
372 qla2x00_set_nvram_protection(scsi_qla_host_t
*ha
, int stat
)
374 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
375 uint32_t word
, wait_cnt
;
377 if (stat
!= QLA_SUCCESS
)
380 /* Set NVRAM write protection. */
382 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
383 qla2x00_nv_write(ha
, 0);
384 qla2x00_nv_write(ha
, 0);
385 for (word
= 0; word
< 8; word
++)
386 qla2x00_nv_write(ha
, NVR_DATA_OUT
);
388 qla2x00_nv_deselect(ha
);
390 /* Enable protection register. */
391 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
392 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
393 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
394 for (word
= 0; word
< 8; word
++)
395 qla2x00_nv_write(ha
, NVR_DATA_OUT
| NVR_PR_ENABLE
);
397 qla2x00_nv_deselect(ha
);
399 /* Enable protection register. */
400 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
401 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
402 qla2x00_nv_write(ha
, NVR_PR_ENABLE
| NVR_DATA_OUT
);
403 for (word
= 0; word
< 8; word
++)
404 qla2x00_nv_write(ha
, NVR_PR_ENABLE
);
406 qla2x00_nv_deselect(ha
);
408 /* Wait for NVRAM to become ready. */
409 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
410 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
411 wait_cnt
= NVR_WAIT_CNT
;
414 DEBUG9_10(printk("%s(%ld): NVRAM didn't go ready...\n",
415 __func__
, ha
->host_no
));
419 word
= RD_REG_WORD(®
->nvram
);
420 } while ((word
& NVR_DATA_IN
) == 0);
424 /*****************************************************************************/
425 /* Flash Manipulation Routines */
426 /*****************************************************************************/
428 static inline uint32_t
429 flash_conf_to_access_addr(uint32_t faddr
)
431 return FARX_ACCESS_FLASH_CONF
| faddr
;
434 static inline uint32_t
435 flash_data_to_access_addr(uint32_t faddr
)
437 return FARX_ACCESS_FLASH_DATA
| faddr
;
440 static inline uint32_t
441 nvram_conf_to_access_addr(uint32_t naddr
)
443 return FARX_ACCESS_NVRAM_CONF
| naddr
;
446 static inline uint32_t
447 nvram_data_to_access_addr(uint32_t naddr
)
449 return FARX_ACCESS_NVRAM_DATA
| naddr
;
453 qla24xx_read_flash_dword(scsi_qla_host_t
*ha
, uint32_t addr
)
457 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
459 WRT_REG_DWORD(®
->flash_addr
, addr
& ~FARX_DATA_FLAG
);
460 /* Wait for READ cycle to complete. */
463 (RD_REG_DWORD(®
->flash_addr
) & FARX_DATA_FLAG
) == 0 &&
464 rval
== QLA_SUCCESS
; cnt
--) {
468 rval
= QLA_FUNCTION_TIMEOUT
;
471 /* TODO: What happens if we time out? */
473 if (rval
== QLA_SUCCESS
)
474 data
= RD_REG_DWORD(®
->flash_data
);
480 qla24xx_read_flash_data(scsi_qla_host_t
*ha
, uint32_t *dwptr
, uint32_t faddr
,
485 /* Dword reads to flash. */
486 for (i
= 0; i
< dwords
; i
++, faddr
++)
487 dwptr
[i
] = cpu_to_le32(qla24xx_read_flash_dword(ha
,
488 flash_data_to_access_addr(faddr
)));
494 qla24xx_write_flash_dword(scsi_qla_host_t
*ha
, uint32_t addr
, uint32_t data
)
498 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
500 WRT_REG_DWORD(®
->flash_data
, data
);
501 RD_REG_DWORD(®
->flash_data
); /* PCI Posting. */
502 WRT_REG_DWORD(®
->flash_addr
, addr
| FARX_DATA_FLAG
);
503 /* Wait for Write cycle to complete. */
505 for (cnt
= 500000; (RD_REG_DWORD(®
->flash_addr
) & FARX_DATA_FLAG
) &&
506 rval
== QLA_SUCCESS
; cnt
--) {
510 rval
= QLA_FUNCTION_TIMEOUT
;
516 qla24xx_get_flash_manufacturer(scsi_qla_host_t
*ha
, uint8_t *man_id
,
521 ids
= qla24xx_read_flash_dword(ha
, flash_data_to_access_addr(0xd03ab));
523 *flash_id
= MSB(ids
);
525 /* Check if man_id and flash_id are valid. */
526 if (ids
!= 0xDEADDEAD && (*man_id
== 0 || *flash_id
== 0)) {
527 /* Read information using 0x9f opcode
528 * Device ID, Mfg ID would be read in the format:
529 * <Ext Dev Info><Device ID Part2><Device ID Part 1><Mfg ID>
530 * Example: ATMEL 0x00 01 45 1F
531 * Extract MFG and Dev ID from last two bytes.
533 ids
= qla24xx_read_flash_dword(ha
,
534 flash_data_to_access_addr(0xd009f));
536 *flash_id
= MSB(ids
);
541 qla24xx_write_flash_data(scsi_qla_host_t
*ha
, uint32_t *dwptr
, uint32_t faddr
,
546 uint32_t sec_mask
, rest_addr
, conf_addr
, sec_end_mask
;
547 uint32_t fdata
, findex
;
548 uint8_t man_id
, flash_id
;
549 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
553 qla24xx_get_flash_manufacturer(ha
, &man_id
, &flash_id
);
554 DEBUG9(printk("%s(%ld): Flash man_id=%d flash_id=%d\n", __func__
,
555 ha
->host_no
, man_id
, flash_id
));
558 conf_addr
= flash_conf_to_access_addr(0x03d8);
560 case 0xbf: /* STT flash. */
563 if (flash_id
== 0x80)
564 conf_addr
= flash_conf_to_access_addr(0x0352);
566 case 0x13: /* ST M25P80. */
570 case 0x1f: // Atmel 26DF081A
573 sec_end_mask
= 0x003ff;
574 conf_addr
= flash_conf_to_access_addr(0x0320);
577 /* Default to 64 kb sector size. */
583 /* Enable flash write. */
584 WRT_REG_DWORD(®
->ctrl_status
,
585 RD_REG_DWORD(®
->ctrl_status
) | CSRX_FLASH_ENABLE
);
586 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
588 /* Disable flash write-protection. */
589 qla24xx_write_flash_dword(ha
, flash_conf_to_access_addr(0x101), 0);
590 /* Some flash parts need an additional zero-write to clear bits.*/
591 qla24xx_write_flash_dword(ha
, flash_conf_to_access_addr(0x101), 0);
593 do { /* Loop once to provide quick error exit. */
594 for (liter
= 0; liter
< dwords
; liter
++, faddr
++, dwptr
++) {
595 if (man_id
== 0x1f) {
597 fdata
= findex
& sec_mask
;
600 fdata
= (findex
& sec_mask
) << 2;
603 /* Are we at the beginning of a sector? */
604 if ((findex
& rest_addr
) == 0) {
606 * Do sector unprotect at 4K boundry for Atmel
610 qla24xx_write_flash_dword(ha
,
611 flash_conf_to_access_addr(0x0339),
612 (fdata
& 0xff00) | ((fdata
<< 16) &
613 0xff0000) | ((fdata
>> 16) & 0xff));
614 fdata
= (faddr
& sec_mask
) << 2;
615 ret
= qla24xx_write_flash_dword(ha
, conf_addr
,
616 (fdata
& 0xff00) |((fdata
<< 16) &
617 0xff0000) | ((fdata
>> 16) & 0xff));
618 if (ret
!= QLA_SUCCESS
) {
619 DEBUG9(printk("%s(%ld) Unable to flash "
620 "sector: address=%x.\n", __func__
,
621 ha
->host_no
, faddr
));
625 ret
= qla24xx_write_flash_dword(ha
,
626 flash_data_to_access_addr(faddr
),
627 cpu_to_le32(*dwptr
));
628 if (ret
!= QLA_SUCCESS
) {
629 DEBUG9(printk("%s(%ld) Unable to program flash "
630 "address=%x data=%x.\n", __func__
,
631 ha
->host_no
, faddr
, *dwptr
));
635 /* Do sector protect at 4K boundry for Atmel part. */
636 if (man_id
== 0x1f &&
637 ((faddr
& sec_end_mask
) == 0x3ff))
638 qla24xx_write_flash_dword(ha
,
639 flash_conf_to_access_addr(0x0336),
640 (fdata
& 0xff00) | ((fdata
<< 16) &
641 0xff0000) | ((fdata
>> 16) & 0xff));
645 /* Enable flash write-protection. */
646 qla24xx_write_flash_dword(ha
, flash_conf_to_access_addr(0x101), 0x9c);
648 /* Disable flash write. */
649 WRT_REG_DWORD(®
->ctrl_status
,
650 RD_REG_DWORD(®
->ctrl_status
) & ~CSRX_FLASH_ENABLE
);
651 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
657 qla2x00_read_nvram_data(scsi_qla_host_t
*ha
, uint8_t *buf
, uint32_t naddr
,
663 /* Word reads to NVRAM via registers. */
664 wptr
= (uint16_t *)buf
;
665 qla2x00_lock_nvram_access(ha
);
666 for (i
= 0; i
< bytes
>> 1; i
++, naddr
++)
667 wptr
[i
] = cpu_to_le16(qla2x00_get_nvram_word(ha
,
669 qla2x00_unlock_nvram_access(ha
);
675 qla24xx_read_nvram_data(scsi_qla_host_t
*ha
, uint8_t *buf
, uint32_t naddr
,
681 /* Dword reads to flash. */
682 dwptr
= (uint32_t *)buf
;
683 for (i
= 0; i
< bytes
>> 2; i
++, naddr
++)
684 dwptr
[i
] = cpu_to_le32(qla24xx_read_flash_dword(ha
,
685 nvram_data_to_access_addr(naddr
)));
691 qla2x00_write_nvram_data(scsi_qla_host_t
*ha
, uint8_t *buf
, uint32_t naddr
,
700 qla2x00_lock_nvram_access(ha
);
702 /* Disable NVRAM write-protection. */
703 stat
= qla2x00_clear_nvram_protection(ha
);
705 wptr
= (uint16_t *)buf
;
706 for (i
= 0; i
< bytes
>> 1; i
++, naddr
++) {
707 qla2x00_write_nvram_word(ha
, naddr
,
712 /* Enable NVRAM write-protection. */
713 qla2x00_set_nvram_protection(ha
, stat
);
715 qla2x00_unlock_nvram_access(ha
);
721 qla24xx_write_nvram_data(scsi_qla_host_t
*ha
, uint8_t *buf
, uint32_t naddr
,
727 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
731 /* Enable flash write. */
732 WRT_REG_DWORD(®
->ctrl_status
,
733 RD_REG_DWORD(®
->ctrl_status
) | CSRX_FLASH_ENABLE
);
734 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
736 /* Disable NVRAM write-protection. */
737 qla24xx_write_flash_dword(ha
, nvram_conf_to_access_addr(0x101),
739 qla24xx_write_flash_dword(ha
, nvram_conf_to_access_addr(0x101),
742 /* Dword writes to flash. */
743 dwptr
= (uint32_t *)buf
;
744 for (i
= 0; i
< bytes
>> 2; i
++, naddr
++, dwptr
++) {
745 ret
= qla24xx_write_flash_dword(ha
,
746 nvram_data_to_access_addr(naddr
),
747 cpu_to_le32(*dwptr
));
748 if (ret
!= QLA_SUCCESS
) {
749 DEBUG9(printk("%s(%ld) Unable to program "
750 "nvram address=%x data=%x.\n", __func__
,
751 ha
->host_no
, naddr
, *dwptr
));
756 /* Enable NVRAM write-protection. */
757 qla24xx_write_flash_dword(ha
, nvram_conf_to_access_addr(0x101),
760 /* Disable flash write. */
761 WRT_REG_DWORD(®
->ctrl_status
,
762 RD_REG_DWORD(®
->ctrl_status
) & ~CSRX_FLASH_ENABLE
);
763 RD_REG_DWORD(®
->ctrl_status
); /* PCI Posting. */
770 qla2x00_flip_colors(scsi_qla_host_t
*ha
, uint16_t *pflags
)
772 if (IS_QLA2322(ha
)) {
773 /* Flip all colors. */
774 if (ha
->beacon_color_state
== QLA_LED_ALL_ON
) {
776 ha
->beacon_color_state
= 0;
777 *pflags
= GPIO_LED_ALL_OFF
;
780 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
781 *pflags
= GPIO_LED_RGA_ON
;
784 /* Flip green led only. */
785 if (ha
->beacon_color_state
== QLA_LED_GRN_ON
) {
787 ha
->beacon_color_state
= 0;
788 *pflags
= GPIO_LED_GREEN_OFF_AMBER_OFF
;
791 ha
->beacon_color_state
= QLA_LED_GRN_ON
;
792 *pflags
= GPIO_LED_GREEN_ON_AMBER_OFF
;
798 qla2x00_beacon_blink(struct scsi_qla_host
*ha
)
800 uint16_t gpio_enable
;
802 uint16_t led_color
= 0;
804 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
807 reg
= (struct device_reg_2xxx __iomem
*)ha
->pio_address
;
809 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
811 /* Save the Original GPIOE. */
812 if (ha
->pio_address
) {
813 gpio_enable
= RD_REG_WORD_PIO(®
->gpioe
);
814 gpio_data
= RD_REG_WORD_PIO(®
->gpiod
);
816 gpio_enable
= RD_REG_WORD(®
->gpioe
);
817 gpio_data
= RD_REG_WORD(®
->gpiod
);
820 /* Set the modified gpio_enable values */
821 gpio_enable
|= GPIO_LED_MASK
;
823 if (ha
->pio_address
) {
824 WRT_REG_WORD_PIO(®
->gpioe
, gpio_enable
);
826 WRT_REG_WORD(®
->gpioe
, gpio_enable
);
827 RD_REG_WORD(®
->gpioe
);
830 qla2x00_flip_colors(ha
, &led_color
);
832 /* Clear out any previously set LED color. */
833 gpio_data
&= ~GPIO_LED_MASK
;
835 /* Set the new input LED color to GPIOD. */
836 gpio_data
|= led_color
;
838 /* Set the modified gpio_data values */
839 if (ha
->pio_address
) {
840 WRT_REG_WORD_PIO(®
->gpiod
, gpio_data
);
842 WRT_REG_WORD(®
->gpiod
, gpio_data
);
843 RD_REG_WORD(®
->gpiod
);
846 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
850 qla2x00_beacon_on(struct scsi_qla_host
*ha
)
852 uint16_t gpio_enable
;
855 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
857 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
858 ha
->fw_options
[1] |= FO1_DISABLE_GPIO6_7
;
860 if (qla2x00_set_fw_options(ha
, ha
->fw_options
) != QLA_SUCCESS
) {
861 qla_printk(KERN_WARNING
, ha
,
862 "Unable to update fw options (beacon on).\n");
863 return QLA_FUNCTION_FAILED
;
867 reg
= (struct device_reg_2xxx __iomem
*)ha
->pio_address
;
870 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
871 if (ha
->pio_address
) {
872 gpio_enable
= RD_REG_WORD_PIO(®
->gpioe
);
873 gpio_data
= RD_REG_WORD_PIO(®
->gpiod
);
875 gpio_enable
= RD_REG_WORD(®
->gpioe
);
876 gpio_data
= RD_REG_WORD(®
->gpiod
);
878 gpio_enable
|= GPIO_LED_MASK
;
880 /* Set the modified gpio_enable values. */
881 if (ha
->pio_address
) {
882 WRT_REG_WORD_PIO(®
->gpioe
, gpio_enable
);
884 WRT_REG_WORD(®
->gpioe
, gpio_enable
);
885 RD_REG_WORD(®
->gpioe
);
888 /* Clear out previously set LED colour. */
889 gpio_data
&= ~GPIO_LED_MASK
;
890 if (ha
->pio_address
) {
891 WRT_REG_WORD_PIO(®
->gpiod
, gpio_data
);
893 WRT_REG_WORD(®
->gpiod
, gpio_data
);
894 RD_REG_WORD(®
->gpiod
);
896 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
899 * Let the per HBA timer kick off the blinking process based on
900 * the following flags. No need to do anything else now.
902 ha
->beacon_blink_led
= 1;
903 ha
->beacon_color_state
= 0;
909 qla2x00_beacon_off(struct scsi_qla_host
*ha
)
911 int rval
= QLA_SUCCESS
;
913 ha
->beacon_blink_led
= 0;
915 /* Set the on flag so when it gets flipped it will be off. */
917 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
919 ha
->beacon_color_state
= QLA_LED_GRN_ON
;
921 ha
->isp_ops
.beacon_blink(ha
); /* This turns green LED off */
923 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
924 ha
->fw_options
[1] &= ~FO1_DISABLE_GPIO6_7
;
926 rval
= qla2x00_set_fw_options(ha
, ha
->fw_options
);
927 if (rval
!= QLA_SUCCESS
)
928 qla_printk(KERN_WARNING
, ha
,
929 "Unable to update fw options (beacon off).\n");
935 qla24xx_flip_colors(scsi_qla_host_t
*ha
, uint16_t *pflags
)
937 /* Flip all colors. */
938 if (ha
->beacon_color_state
== QLA_LED_ALL_ON
) {
940 ha
->beacon_color_state
= 0;
944 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
945 *pflags
= GPDX_LED_YELLOW_ON
| GPDX_LED_AMBER_ON
;
950 qla24xx_beacon_blink(struct scsi_qla_host
*ha
)
952 uint16_t led_color
= 0;
955 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
957 /* Save the Original GPIOD. */
958 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
959 gpio_data
= RD_REG_DWORD(®
->gpiod
);
961 /* Enable the gpio_data reg for update. */
962 gpio_data
|= GPDX_LED_UPDATE_MASK
;
964 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
965 gpio_data
= RD_REG_DWORD(®
->gpiod
);
967 /* Set the color bits. */
968 qla24xx_flip_colors(ha
, &led_color
);
970 /* Clear out any previously set LED color. */
971 gpio_data
&= ~GPDX_LED_COLOR_MASK
;
973 /* Set the new input LED color to GPIOD. */
974 gpio_data
|= led_color
;
976 /* Set the modified gpio_data values. */
977 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
978 gpio_data
= RD_REG_DWORD(®
->gpiod
);
979 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
983 qla24xx_beacon_on(struct scsi_qla_host
*ha
)
987 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
989 if (ha
->beacon_blink_led
== 0) {
990 /* Enable firmware for update */
991 ha
->fw_options
[1] |= ADD_FO1_DISABLE_GPIO_LED_CTRL
;
993 if (qla2x00_set_fw_options(ha
, ha
->fw_options
) != QLA_SUCCESS
)
994 return QLA_FUNCTION_FAILED
;
996 if (qla2x00_get_fw_options(ha
, ha
->fw_options
) !=
998 qla_printk(KERN_WARNING
, ha
,
999 "Unable to update fw options (beacon on).\n");
1000 return QLA_FUNCTION_FAILED
;
1003 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1004 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1006 /* Enable the gpio_data reg for update. */
1007 gpio_data
|= GPDX_LED_UPDATE_MASK
;
1008 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1009 RD_REG_DWORD(®
->gpiod
);
1011 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1014 /* So all colors blink together. */
1015 ha
->beacon_color_state
= 0;
1017 /* Let the per HBA timer kick off the blinking process. */
1018 ha
->beacon_blink_led
= 1;
1024 qla24xx_beacon_off(struct scsi_qla_host
*ha
)
1027 unsigned long flags
;
1028 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1030 ha
->beacon_blink_led
= 0;
1031 ha
->beacon_color_state
= QLA_LED_ALL_ON
;
1033 ha
->isp_ops
.beacon_blink(ha
); /* Will flip to all off. */
1035 /* Give control back to firmware. */
1036 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1037 gpio_data
= RD_REG_DWORD(®
->gpiod
);
1039 /* Disable the gpio_data reg for update. */
1040 gpio_data
&= ~GPDX_LED_UPDATE_MASK
;
1041 WRT_REG_DWORD(®
->gpiod
, gpio_data
);
1042 RD_REG_DWORD(®
->gpiod
);
1043 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1045 ha
->fw_options
[1] &= ~ADD_FO1_DISABLE_GPIO_LED_CTRL
;
1047 if (qla2x00_set_fw_options(ha
, ha
->fw_options
) != QLA_SUCCESS
) {
1048 qla_printk(KERN_WARNING
, ha
,
1049 "Unable to update fw options (beacon off).\n");
1050 return QLA_FUNCTION_FAILED
;
1053 if (qla2x00_get_fw_options(ha
, ha
->fw_options
) != QLA_SUCCESS
) {
1054 qla_printk(KERN_WARNING
, ha
,
1055 "Unable to get fw options (beacon off).\n");
1056 return QLA_FUNCTION_FAILED
;
1064 * Flash support routines
1068 * qla2x00_flash_enable() - Setup flash for reading and writing.
1072 qla2x00_flash_enable(scsi_qla_host_t
*ha
)
1075 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1077 data
= RD_REG_WORD(®
->ctrl_status
);
1078 data
|= CSR_FLASH_ENABLE
;
1079 WRT_REG_WORD(®
->ctrl_status
, data
);
1080 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1084 * qla2x00_flash_disable() - Disable flash and allow RISC to run.
1088 qla2x00_flash_disable(scsi_qla_host_t
*ha
)
1091 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1093 data
= RD_REG_WORD(®
->ctrl_status
);
1094 data
&= ~(CSR_FLASH_ENABLE
);
1095 WRT_REG_WORD(®
->ctrl_status
, data
);
1096 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1100 * qla2x00_read_flash_byte() - Reads a byte from flash
1102 * @addr: Address in flash to read
1104 * A word is read from the chip, but, only the lower byte is valid.
1106 * Returns the byte read from flash @addr.
1109 qla2x00_read_flash_byte(scsi_qla_host_t
*ha
, uint32_t addr
)
1112 uint16_t bank_select
;
1113 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1115 bank_select
= RD_REG_WORD(®
->ctrl_status
);
1117 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1118 /* Specify 64K address range: */
1119 /* clear out Module Select and Flash Address bits [19:16]. */
1120 bank_select
&= ~0xf8;
1121 bank_select
|= addr
>> 12 & 0xf0;
1122 bank_select
|= CSR_FLASH_64K_BANK
;
1123 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1124 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1126 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1127 data
= RD_REG_WORD(®
->flash_data
);
1129 return (uint8_t)data
;
1132 /* Setup bit 16 of flash address. */
1133 if ((addr
& BIT_16
) && ((bank_select
& CSR_FLASH_64K_BANK
) == 0)) {
1134 bank_select
|= CSR_FLASH_64K_BANK
;
1135 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1136 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1137 } else if (((addr
& BIT_16
) == 0) &&
1138 (bank_select
& CSR_FLASH_64K_BANK
)) {
1139 bank_select
&= ~(CSR_FLASH_64K_BANK
);
1140 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1141 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1144 /* Always perform IO mapped accesses to the FLASH registers. */
1145 if (ha
->pio_address
) {
1148 reg
= (struct device_reg_2xxx __iomem
*)ha
->pio_address
;
1149 WRT_REG_WORD_PIO(®
->flash_address
, (uint16_t)addr
);
1151 data
= RD_REG_WORD_PIO(®
->flash_data
);
1154 data2
= RD_REG_WORD_PIO(®
->flash_data
);
1155 } while (data
!= data2
);
1157 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1158 data
= qla2x00_debounce_register(®
->flash_data
);
1161 return (uint8_t)data
;
1165 * qla2x00_write_flash_byte() - Write a byte to flash
1167 * @addr: Address in flash to write
1168 * @data: Data to write
1171 qla2x00_write_flash_byte(scsi_qla_host_t
*ha
, uint32_t addr
, uint8_t data
)
1173 uint16_t bank_select
;
1174 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1176 bank_select
= RD_REG_WORD(®
->ctrl_status
);
1177 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1178 /* Specify 64K address range: */
1179 /* clear out Module Select and Flash Address bits [19:16]. */
1180 bank_select
&= ~0xf8;
1181 bank_select
|= addr
>> 12 & 0xf0;
1182 bank_select
|= CSR_FLASH_64K_BANK
;
1183 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1184 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1186 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1187 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1188 WRT_REG_WORD(®
->flash_data
, (uint16_t)data
);
1189 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1194 /* Setup bit 16 of flash address. */
1195 if ((addr
& BIT_16
) && ((bank_select
& CSR_FLASH_64K_BANK
) == 0)) {
1196 bank_select
|= CSR_FLASH_64K_BANK
;
1197 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1198 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1199 } else if (((addr
& BIT_16
) == 0) &&
1200 (bank_select
& CSR_FLASH_64K_BANK
)) {
1201 bank_select
&= ~(CSR_FLASH_64K_BANK
);
1202 WRT_REG_WORD(®
->ctrl_status
, bank_select
);
1203 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1206 /* Always perform IO mapped accesses to the FLASH registers. */
1207 if (ha
->pio_address
) {
1208 reg
= (struct device_reg_2xxx __iomem
*)ha
->pio_address
;
1209 WRT_REG_WORD_PIO(®
->flash_address
, (uint16_t)addr
);
1210 WRT_REG_WORD_PIO(®
->flash_data
, (uint16_t)data
);
1212 WRT_REG_WORD(®
->flash_address
, (uint16_t)addr
);
1213 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1214 WRT_REG_WORD(®
->flash_data
, (uint16_t)data
);
1215 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1220 * qla2x00_poll_flash() - Polls flash for completion.
1222 * @addr: Address in flash to poll
1223 * @poll_data: Data to be polled
1224 * @man_id: Flash manufacturer ID
1225 * @flash_id: Flash ID
1227 * This function polls the device until bit 7 of what is read matches data
1228 * bit 7 or until data bit 5 becomes a 1. If that hapens, the flash ROM timed
1229 * out (a fatal error). The flash book recommeds reading bit 7 again after
1230 * reading bit 5 as a 1.
1232 * Returns 0 on success, else non-zero.
1235 qla2x00_poll_flash(scsi_qla_host_t
*ha
, uint32_t addr
, uint8_t poll_data
,
1236 uint8_t man_id
, uint8_t flash_id
)
1244 /* Wait for 30 seconds for command to finish. */
1246 for (cnt
= 3000000; cnt
; cnt
--) {
1247 flash_data
= qla2x00_read_flash_byte(ha
, addr
);
1248 if ((flash_data
& BIT_7
) == poll_data
) {
1253 if (man_id
!= 0x40 && man_id
!= 0xda) {
1254 if ((flash_data
& BIT_5
) && cnt
> 2)
1264 * qla2x00_program_flash_address() - Programs a flash address
1266 * @addr: Address in flash to program
1267 * @data: Data to be written in flash
1268 * @man_id: Flash manufacturer ID
1269 * @flash_id: Flash ID
1271 * Returns 0 on success, else non-zero.
1274 qla2x00_program_flash_address(scsi_qla_host_t
*ha
, uint32_t addr
, uint8_t data
,
1275 uint8_t man_id
, uint8_t flash_id
)
1277 /* Write Program Command Sequence. */
1278 if (IS_OEM_001(ha
)) {
1279 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1280 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1281 qla2x00_write_flash_byte(ha
, 0xaaa, 0xa0);
1282 qla2x00_write_flash_byte(ha
, addr
, data
);
1284 if (man_id
== 0xda && flash_id
== 0xc1) {
1285 qla2x00_write_flash_byte(ha
, addr
, data
);
1289 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1290 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1291 qla2x00_write_flash_byte(ha
, 0x5555, 0xa0);
1292 qla2x00_write_flash_byte(ha
, addr
, data
);
1298 /* Wait for write to complete. */
1299 return qla2x00_poll_flash(ha
, addr
, data
, man_id
, flash_id
);
1303 * qla2x00_erase_flash() - Erase the flash.
1305 * @man_id: Flash manufacturer ID
1306 * @flash_id: Flash ID
1308 * Returns 0 on success, else non-zero.
1311 qla2x00_erase_flash(scsi_qla_host_t
*ha
, uint8_t man_id
, uint8_t flash_id
)
1313 /* Individual Sector Erase Command Sequence */
1314 if (IS_OEM_001(ha
)) {
1315 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1316 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1317 qla2x00_write_flash_byte(ha
, 0xaaa, 0x80);
1318 qla2x00_write_flash_byte(ha
, 0xaaa, 0xaa);
1319 qla2x00_write_flash_byte(ha
, 0x555, 0x55);
1320 qla2x00_write_flash_byte(ha
, 0xaaa, 0x10);
1322 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1323 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1324 qla2x00_write_flash_byte(ha
, 0x5555, 0x80);
1325 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1326 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1327 qla2x00_write_flash_byte(ha
, 0x5555, 0x10);
1332 /* Wait for erase to complete. */
1333 return qla2x00_poll_flash(ha
, 0x00, 0x80, man_id
, flash_id
);
1337 * qla2x00_erase_flash_sector() - Erase a flash sector.
1339 * @addr: Flash sector to erase
1340 * @sec_mask: Sector address mask
1341 * @man_id: Flash manufacturer ID
1342 * @flash_id: Flash ID
1344 * Returns 0 on success, else non-zero.
1347 qla2x00_erase_flash_sector(scsi_qla_host_t
*ha
, uint32_t addr
,
1348 uint32_t sec_mask
, uint8_t man_id
, uint8_t flash_id
)
1350 /* Individual Sector Erase Command Sequence */
1351 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1352 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1353 qla2x00_write_flash_byte(ha
, 0x5555, 0x80);
1354 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1355 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1356 if (man_id
== 0x1f && flash_id
== 0x13)
1357 qla2x00_write_flash_byte(ha
, addr
& sec_mask
, 0x10);
1359 qla2x00_write_flash_byte(ha
, addr
& sec_mask
, 0x30);
1363 /* Wait for erase to complete. */
1364 return qla2x00_poll_flash(ha
, addr
, 0x80, man_id
, flash_id
);
1368 * qla2x00_get_flash_manufacturer() - Read manufacturer ID from flash chip.
1369 * @man_id: Flash manufacturer ID
1370 * @flash_id: Flash ID
1373 qla2x00_get_flash_manufacturer(scsi_qla_host_t
*ha
, uint8_t *man_id
,
1376 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1377 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1378 qla2x00_write_flash_byte(ha
, 0x5555, 0x90);
1379 *man_id
= qla2x00_read_flash_byte(ha
, 0x0000);
1380 *flash_id
= qla2x00_read_flash_byte(ha
, 0x0001);
1381 qla2x00_write_flash_byte(ha
, 0x5555, 0xaa);
1382 qla2x00_write_flash_byte(ha
, 0x2aaa, 0x55);
1383 qla2x00_write_flash_byte(ha
, 0x5555, 0xf0);
1388 qla2x00_suspend_hba(struct scsi_qla_host
*ha
)
1391 unsigned long flags
;
1392 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1395 scsi_block_requests(ha
->host
);
1396 ha
->isp_ops
.disable_intrs(ha
);
1397 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1400 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1401 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
1402 RD_REG_WORD(®
->hccr
);
1403 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
1404 for (cnt
= 0; cnt
< 30000; cnt
++) {
1405 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
1412 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1416 qla2x00_resume_hba(struct scsi_qla_host
*ha
)
1419 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1420 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1421 qla2xxx_wake_dpc(ha
);
1422 qla2x00_wait_for_hba_online(ha
);
1423 scsi_unblock_requests(ha
->host
);
1427 qla2x00_read_optrom_data(struct scsi_qla_host
*ha
, uint8_t *buf
,
1428 uint32_t offset
, uint32_t length
)
1430 unsigned long flags
;
1431 uint32_t addr
, midpoint
;
1433 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1436 qla2x00_suspend_hba(ha
);
1439 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1440 midpoint
= ha
->optrom_size
/ 2;
1442 qla2x00_flash_enable(ha
);
1443 WRT_REG_WORD(®
->nvram
, 0);
1444 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
1445 for (addr
= offset
, data
= buf
; addr
< length
; addr
++, data
++) {
1446 if (addr
== midpoint
) {
1447 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
1448 RD_REG_WORD(®
->nvram
); /* PCI Posting. */
1451 *data
= qla2x00_read_flash_byte(ha
, addr
);
1453 qla2x00_flash_disable(ha
);
1454 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1457 qla2x00_resume_hba(ha
);
1463 qla2x00_write_optrom_data(struct scsi_qla_host
*ha
, uint8_t *buf
,
1464 uint32_t offset
, uint32_t length
)
1468 unsigned long flags
;
1469 uint8_t man_id
, flash_id
, sec_number
, data
;
1471 uint32_t addr
, liter
, sec_mask
, rest_addr
;
1472 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1475 qla2x00_suspend_hba(ha
);
1480 /* Reset ISP chip. */
1481 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1482 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
1483 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
1485 /* Go with write. */
1486 qla2x00_flash_enable(ha
);
1487 do { /* Loop once to provide quick error exit */
1488 /* Structure of flash memory based on manufacturer */
1489 if (IS_OEM_001(ha
)) {
1490 /* OEM variant with special flash part. */
1491 man_id
= flash_id
= 0;
1496 qla2x00_get_flash_manufacturer(ha
, &man_id
, &flash_id
);
1498 case 0x20: /* ST flash. */
1499 if (flash_id
== 0xd2 || flash_id
== 0xe3) {
1501 * ST m29w008at part - 64kb sector size with
1502 * 32kb,8kb,8kb,16kb sectors at memory address
1510 * ST m29w010b part - 16kb sector size
1511 * Default to 16kb sectors
1516 case 0x40: /* Mostel flash. */
1517 /* Mostel v29c51001 part - 512 byte sector size. */
1521 case 0xbf: /* SST flash. */
1522 /* SST39sf10 part - 4kb sector size. */
1526 case 0xda: /* Winbond flash. */
1527 /* Winbond W29EE011 part - 256 byte sector size. */
1531 case 0xc2: /* Macronix flash. */
1532 /* 64k sector size. */
1533 if (flash_id
== 0x38 || flash_id
== 0x4f) {
1538 /* Fall through... */
1540 case 0x1f: /* Atmel flash. */
1541 /* 512k sector size. */
1542 if (flash_id
== 0x13) {
1543 rest_addr
= 0x7fffffff;
1544 sec_mask
= 0x80000000;
1547 /* Fall through... */
1549 case 0x01: /* AMD flash. */
1550 if (flash_id
== 0x38 || flash_id
== 0x40 ||
1552 /* Am29LV081 part - 64kb sector size. */
1553 /* Am29LV002BT part - 64kb sector size. */
1557 } else if (flash_id
== 0x3e) {
1559 * Am29LV008b part - 64kb sector size with
1560 * 32kb,8kb,8kb,16kb sector at memory address
1566 } else if (flash_id
== 0x20 || flash_id
== 0x6e) {
1568 * Am29LV010 part or AM29f010 - 16kb sector
1574 } else if (flash_id
== 0x6d) {
1575 /* Am29LV001 part - 8kb sector size. */
1581 /* Default to 16 kb sector size. */
1588 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1589 if (qla2x00_erase_flash(ha
, man_id
, flash_id
)) {
1590 rval
= QLA_FUNCTION_FAILED
;
1595 for (addr
= offset
, liter
= 0; liter
< length
; liter
++,
1598 /* Are we at the beginning of a sector? */
1599 if ((addr
& rest_addr
) == 0) {
1600 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
1601 if (addr
>= 0x10000UL
) {
1602 if (((addr
>> 12) & 0xf0) &&
1604 flash_id
== 0x3e) ||
1606 flash_id
== 0xd2))) {
1608 if (sec_number
== 1) {
1629 } else if (addr
== ha
->optrom_size
/ 2) {
1630 WRT_REG_WORD(®
->nvram
, NVR_SELECT
);
1631 RD_REG_WORD(®
->nvram
);
1634 if (flash_id
== 0xda && man_id
== 0xc1) {
1635 qla2x00_write_flash_byte(ha
, 0x5555,
1637 qla2x00_write_flash_byte(ha
, 0x2aaa,
1639 qla2x00_write_flash_byte(ha
, 0x5555,
1641 } else if (!IS_QLA2322(ha
) && !IS_QLA6322(ha
)) {
1643 if (qla2x00_erase_flash_sector(ha
,
1644 addr
, sec_mask
, man_id
,
1646 rval
= QLA_FUNCTION_FAILED
;
1649 if (man_id
== 0x01 && flash_id
== 0x6d)
1654 if (man_id
== 0x01 && flash_id
== 0x6d) {
1655 if (sec_number
== 1 &&
1656 addr
== (rest_addr
- 1)) {
1659 } else if (sec_number
== 3 && (addr
& 0x7ffe)) {
1665 if (qla2x00_program_flash_address(ha
, addr
, data
,
1666 man_id
, flash_id
)) {
1667 rval
= QLA_FUNCTION_FAILED
;
1672 qla2x00_flash_disable(ha
);
1673 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1676 qla2x00_resume_hba(ha
);
1682 qla24xx_read_optrom_data(struct scsi_qla_host
*ha
, uint8_t *buf
,
1683 uint32_t offset
, uint32_t length
)
1686 scsi_block_requests(ha
->host
);
1687 ha
->isp_ops
.disable_intrs(ha
);
1688 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1691 qla24xx_read_flash_data(ha
, (uint32_t *)buf
, offset
>> 2, length
>> 2);
1694 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1695 ha
->isp_ops
.enable_intrs(ha
);
1696 scsi_unblock_requests(ha
->host
);
1702 qla24xx_write_optrom_data(struct scsi_qla_host
*ha
, uint8_t *buf
,
1703 uint32_t offset
, uint32_t length
)
1708 scsi_block_requests(ha
->host
);
1709 ha
->isp_ops
.disable_intrs(ha
);
1710 set_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1712 /* Go with write. */
1713 rval
= qla24xx_write_flash_data(ha
, (uint32_t *)buf
, offset
>> 2,
1716 /* Resume HBA -- RISC reset needed. */
1717 clear_bit(MBX_UPDATE_FLASH_ACTIVE
, &ha
->mbx_cmd_flags
);
1718 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1719 qla2xxx_wake_dpc(ha
);
1720 qla2x00_wait_for_hba_online(ha
);
1721 scsi_unblock_requests(ha
->host
);