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;
472 /* TODO: What happens if we time out? */
474 if (rval == QLA_SUCCESS)
475 data = RD_REG_DWORD(®->flash_data);
481 qla24xx_read_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
486 /* Dword reads to flash. */
487 for (i = 0; i < dwords; i++, faddr++)
488 dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
489 flash_data_to_access_addr(faddr)));
495 qla24xx_write_flash_dword(scsi_qla_host_t *ha, uint32_t addr, uint32_t data)
499 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
501 WRT_REG_DWORD(®->flash_data, data);
502 RD_REG_DWORD(®->flash_data); /* PCI Posting. */
503 WRT_REG_DWORD(®->flash_addr, addr | FARX_DATA_FLAG);
504 /* Wait for Write cycle to complete. */
506 for (cnt = 500000; (RD_REG_DWORD(®->flash_addr) & FARX_DATA_FLAG) &&
507 rval == QLA_SUCCESS; cnt--) {
511 rval = QLA_FUNCTION_TIMEOUT;
518 qla24xx_get_flash_manufacturer(scsi_qla_host_t *ha, uint8_t *man_id,
523 ids = qla24xx_read_flash_dword(ha, flash_data_to_access_addr(0xd03ab));
525 *flash_id = MSB(ids);
527 /* Check if man_id and flash_id are valid. */
528 if (ids != 0xDEADDEAD && (*man_id == 0 || *flash_id == 0)) {
529 /* Read information using 0x9f opcode
530 * Device ID, Mfg ID would be read in the format:
531 * <Ext Dev Info><Device ID Part2><Device ID Part 1><Mfg ID>
532 * Example: ATMEL 0x00 01 45 1F
533 * Extract MFG and Dev ID from last two bytes.
535 ids = qla24xx_read_flash_dword(ha,
536 flash_data_to_access_addr(0xd009f));
538 *flash_id = MSB(ids);
543 qla24xx_write_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
548 uint32_t sec_mask, rest_addr, conf_addr, sec_end_mask;
549 uint32_t fdata, findex ;
550 uint8_t man_id, flash_id;
551 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
555 qla24xx_get_flash_manufacturer(ha, &man_id, &flash_id);
556 DEBUG9(printk("%s(%ld): Flash man_id=%d flash_id=%d\n", __func__,
557 ha->host_no, man_id, flash_id));
560 conf_addr = flash_conf_to_access_addr(0x03d8);
562 case 0xbf: /* STT flash. */
565 if (flash_id == 0x80)
566 conf_addr = flash_conf_to_access_addr(0x0352);
568 case 0x13: /* ST M25P80. */
572 case 0x1f: // Atmel 26DF081A
575 sec_end_mask = 0x003ff;
576 conf_addr = flash_conf_to_access_addr(0x0320);
579 /* Default to 64 kb sector size. */
585 /* Enable flash write. */
586 WRT_REG_DWORD(®->ctrl_status,
587 RD_REG_DWORD(®->ctrl_status) | CSRX_FLASH_ENABLE);
588 RD_REG_DWORD(®->ctrl_status); /* PCI Posting. */
590 /* Disable flash write-protection. */
591 qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0);
592 /* Some flash parts need an additional zero-write to clear bits.*/
593 qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0);
595 do { /* Loop once to provide quick error exit. */
596 for (liter = 0; liter < dwords; liter++, faddr++, dwptr++) {
597 if (man_id == 0x1f) {
599 fdata = findex & sec_mask;
602 fdata = (findex & sec_mask) << 2;
605 /* Are we at the beginning of a sector? */
606 if ((findex & rest_addr) == 0) {
608 * Do sector unprotect at 4K boundry for Atmel
612 qla24xx_write_flash_dword(ha,
613 flash_conf_to_access_addr(0x0339),
614 (fdata & 0xff00) | ((fdata << 16) &
615 0xff0000) | ((fdata >> 16) & 0xff));
616 ret = qla24xx_write_flash_dword(ha, conf_addr,
617 (fdata & 0xff00) |((fdata << 16) &
618 0xff0000) | ((fdata >> 16) & 0xff));
619 if (ret != QLA_SUCCESS) {
620 DEBUG9(printk("%s(%ld) Unable to flash "
621 "sector: address=%x.\n", __func__,
622 ha->host_no, faddr));
626 ret = qla24xx_write_flash_dword(ha,
627 flash_data_to_access_addr(faddr),
628 cpu_to_le32(*dwptr));
629 if (ret != QLA_SUCCESS) {
630 DEBUG9(printk("%s(%ld) Unable to program flash "
631 "address=%x data=%x.\n", __func__,
632 ha->host_no, faddr, *dwptr));
636 /* Do sector protect at 4K boundry for Atmel part. */
637 if (man_id == 0x1f &&
638 ((faddr & sec_end_mask) == 0x3ff))
639 qla24xx_write_flash_dword(ha,
640 flash_conf_to_access_addr(0x0336),
641 (fdata & 0xff00) | ((fdata << 16) &
642 0xff0000) | ((fdata >> 16) & 0xff));
646 /* Enable flash write-protection. */
647 qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0x9c);
649 /* Disable flash write. */
650 WRT_REG_DWORD(®->ctrl_status,
651 RD_REG_DWORD(®->ctrl_status) & ~CSRX_FLASH_ENABLE);
652 RD_REG_DWORD(®->ctrl_status); /* PCI Posting. */
658 qla2x00_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
664 /* Word reads to NVRAM via registers. */
665 wptr = (uint16_t *)buf;
666 qla2x00_lock_nvram_access(ha);
667 for (i = 0; i < bytes >> 1; i++, naddr++)
668 wptr[i] = cpu_to_le16(qla2x00_get_nvram_word(ha,
670 qla2x00_unlock_nvram_access(ha);
676 qla24xx_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
682 /* Dword reads to flash. */
683 dwptr = (uint32_t *)buf;
684 for (i = 0; i < bytes >> 2; i++, naddr++)
685 dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
686 nvram_data_to_access_addr(naddr)));
692 qla2x00_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
701 qla2x00_lock_nvram_access(ha);
703 /* Disable NVRAM write-protection. */
704 stat = qla2x00_clear_nvram_protection(ha);
706 wptr = (uint16_t *)buf;
707 for (i = 0; i < bytes >> 1; i++, naddr++) {
708 qla2x00_write_nvram_word(ha, naddr,
713 /* Enable NVRAM write-protection. */
714 qla2x00_set_nvram_protection(ha, stat);
716 qla2x00_unlock_nvram_access(ha);
722 qla24xx_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
728 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
732 /* Enable flash write. */
733 WRT_REG_DWORD(®->ctrl_status,
734 RD_REG_DWORD(®->ctrl_status) | CSRX_FLASH_ENABLE);
735 RD_REG_DWORD(®->ctrl_status); /* PCI Posting. */
737 /* Disable NVRAM write-protection. */
738 qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
740 qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
743 /* Dword writes to flash. */
744 dwptr = (uint32_t *)buf;
745 for (i = 0; i < bytes >> 2; i++, naddr++, dwptr++) {
746 ret = qla24xx_write_flash_dword(ha,
747 nvram_data_to_access_addr(naddr),
748 cpu_to_le32(*dwptr));
749 if (ret != QLA_SUCCESS) {
750 DEBUG9(printk("%s(%ld) Unable to program "
751 "nvram address=%x data=%x.\n", __func__,
752 ha->host_no, naddr, *dwptr));
757 /* Enable NVRAM write-protection. */
758 qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
761 /* Disable flash write. */
762 WRT_REG_DWORD(®->ctrl_status,
763 RD_REG_DWORD(®->ctrl_status) & ~CSRX_FLASH_ENABLE);
764 RD_REG_DWORD(®->ctrl_status); /* PCI Posting. */
770 qla25xx_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
776 /* Dword reads to flash. */
777 dwptr = (uint32_t *)buf;
778 for (i = 0; i < bytes >> 2; i++, naddr++)
779 dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
780 flash_data_to_access_addr(FA_VPD_NVRAM_ADDR | naddr)));
786 qla25xx_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
789 return qla24xx_write_flash_data(ha, (uint32_t *)buf,
790 FA_VPD_NVRAM_ADDR | naddr, bytes >> 2);
794 qla2x00_flip_colors(scsi_qla_host_t *ha, uint16_t *pflags)
796 if (IS_QLA2322(ha)) {
797 /* Flip all colors. */
798 if (ha->beacon_color_state == QLA_LED_ALL_ON) {
800 ha->beacon_color_state = 0;
801 *pflags = GPIO_LED_ALL_OFF;
804 ha->beacon_color_state = QLA_LED_ALL_ON;
805 *pflags = GPIO_LED_RGA_ON;
808 /* Flip green led only. */
809 if (ha->beacon_color_state == QLA_LED_GRN_ON) {
811 ha->beacon_color_state = 0;
812 *pflags = GPIO_LED_GREEN_OFF_AMBER_OFF;
815 ha->beacon_color_state = QLA_LED_GRN_ON;
816 *pflags = GPIO_LED_GREEN_ON_AMBER_OFF;
822 qla2x00_beacon_blink(struct scsi_qla_host *ha)
824 uint16_t gpio_enable;
826 uint16_t led_color = 0;
828 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
831 reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
833 spin_lock_irqsave(&ha->hardware_lock, flags);
835 /* Save the Original GPIOE. */
836 if (ha->pio_address) {
837 gpio_enable = RD_REG_WORD_PIO(®->gpioe);
838 gpio_data = RD_REG_WORD_PIO(®->gpiod);
840 gpio_enable = RD_REG_WORD(®->gpioe);
841 gpio_data = RD_REG_WORD(®->gpiod);
844 /* Set the modified gpio_enable values */
845 gpio_enable |= GPIO_LED_MASK;
847 if (ha->pio_address) {
848 WRT_REG_WORD_PIO(®->gpioe, gpio_enable);
850 WRT_REG_WORD(®->gpioe, gpio_enable);
851 RD_REG_WORD(®->gpioe);
854 qla2x00_flip_colors(ha, &led_color);
856 /* Clear out any previously set LED color. */
857 gpio_data &= ~GPIO_LED_MASK;
859 /* Set the new input LED color to GPIOD. */
860 gpio_data |= led_color;
862 /* Set the modified gpio_data values */
863 if (ha->pio_address) {
864 WRT_REG_WORD_PIO(®->gpiod, gpio_data);
866 WRT_REG_WORD(®->gpiod, gpio_data);
867 RD_REG_WORD(®->gpiod);
870 spin_unlock_irqrestore(&ha->hardware_lock, flags);
874 qla2x00_beacon_on(struct scsi_qla_host *ha)
876 uint16_t gpio_enable;
879 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
881 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
882 ha->fw_options[1] |= FO1_DISABLE_GPIO6_7;
884 if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
885 qla_printk(KERN_WARNING, ha,
886 "Unable to update fw options (beacon on).\n");
887 return QLA_FUNCTION_FAILED;
891 reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
894 spin_lock_irqsave(&ha->hardware_lock, flags);
895 if (ha->pio_address) {
896 gpio_enable = RD_REG_WORD_PIO(®->gpioe);
897 gpio_data = RD_REG_WORD_PIO(®->gpiod);
899 gpio_enable = RD_REG_WORD(®->gpioe);
900 gpio_data = RD_REG_WORD(®->gpiod);
902 gpio_enable |= GPIO_LED_MASK;
904 /* Set the modified gpio_enable values. */
905 if (ha->pio_address) {
906 WRT_REG_WORD_PIO(®->gpioe, gpio_enable);
908 WRT_REG_WORD(®->gpioe, gpio_enable);
909 RD_REG_WORD(®->gpioe);
912 /* Clear out previously set LED colour. */
913 gpio_data &= ~GPIO_LED_MASK;
914 if (ha->pio_address) {
915 WRT_REG_WORD_PIO(®->gpiod, gpio_data);
917 WRT_REG_WORD(®->gpiod, gpio_data);
918 RD_REG_WORD(®->gpiod);
920 spin_unlock_irqrestore(&ha->hardware_lock, flags);
923 * Let the per HBA timer kick off the blinking process based on
924 * the following flags. No need to do anything else now.
926 ha->beacon_blink_led = 1;
927 ha->beacon_color_state = 0;
933 qla2x00_beacon_off(struct scsi_qla_host *ha)
935 int rval = QLA_SUCCESS;
937 ha->beacon_blink_led = 0;
939 /* Set the on flag so when it gets flipped it will be off. */
941 ha->beacon_color_state = QLA_LED_ALL_ON;
943 ha->beacon_color_state = QLA_LED_GRN_ON;
945 ha->isp_ops->beacon_blink(ha); /* This turns green LED off */
947 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
948 ha->fw_options[1] &= ~FO1_DISABLE_GPIO6_7;
950 rval = qla2x00_set_fw_options(ha, ha->fw_options);
951 if (rval != QLA_SUCCESS)
952 qla_printk(KERN_WARNING, ha,
953 "Unable to update fw options (beacon off).\n");
959 qla24xx_flip_colors(scsi_qla_host_t *ha, uint16_t *pflags)
961 /* Flip all colors. */
962 if (ha->beacon_color_state == QLA_LED_ALL_ON) {
964 ha->beacon_color_state = 0;
968 ha->beacon_color_state = QLA_LED_ALL_ON;
969 *pflags = GPDX_LED_YELLOW_ON | GPDX_LED_AMBER_ON;
974 qla24xx_beacon_blink(struct scsi_qla_host *ha)
976 uint16_t led_color = 0;
979 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
981 /* Save the Original GPIOD. */
982 spin_lock_irqsave(&ha->hardware_lock, flags);
983 gpio_data = RD_REG_DWORD(®->gpiod);
985 /* Enable the gpio_data reg for update. */
986 gpio_data |= GPDX_LED_UPDATE_MASK;
988 WRT_REG_DWORD(®->gpiod, gpio_data);
989 gpio_data = RD_REG_DWORD(®->gpiod);
991 /* Set the color bits. */
992 qla24xx_flip_colors(ha, &led_color);
994 /* Clear out any previously set LED color. */
995 gpio_data &= ~GPDX_LED_COLOR_MASK;
997 /* Set the new input LED color to GPIOD. */
998 gpio_data |= led_color;
1000 /* Set the modified gpio_data values. */
1001 WRT_REG_DWORD(®->gpiod, gpio_data);
1002 gpio_data = RD_REG_DWORD(®->gpiod);
1003 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1007 qla24xx_beacon_on(struct scsi_qla_host *ha)
1010 unsigned long flags;
1011 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1013 if (ha->beacon_blink_led == 0) {
1014 /* Enable firmware for update */
1015 ha->fw_options[1] |= ADD_FO1_DISABLE_GPIO_LED_CTRL;
1017 if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS)
1018 return QLA_FUNCTION_FAILED;
1020 if (qla2x00_get_fw_options(ha, ha->fw_options) !=
1022 qla_printk(KERN_WARNING, ha,
1023 "Unable to update fw options (beacon on).\n");
1024 return QLA_FUNCTION_FAILED;
1027 spin_lock_irqsave(&ha->hardware_lock, flags);
1028 gpio_data = RD_REG_DWORD(®->gpiod);
1030 /* Enable the gpio_data reg for update. */
1031 gpio_data |= GPDX_LED_UPDATE_MASK;
1032 WRT_REG_DWORD(®->gpiod, gpio_data);
1033 RD_REG_DWORD(®->gpiod);
1035 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1038 /* So all colors blink together. */
1039 ha->beacon_color_state = 0;
1041 /* Let the per HBA timer kick off the blinking process. */
1042 ha->beacon_blink_led = 1;
1048 qla24xx_beacon_off(struct scsi_qla_host *ha)
1051 unsigned long flags;
1052 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1054 ha->beacon_blink_led = 0;
1055 ha->beacon_color_state = QLA_LED_ALL_ON;
1057 ha->isp_ops->beacon_blink(ha); /* Will flip to all off. */
1059 /* Give control back to firmware. */
1060 spin_lock_irqsave(&ha->hardware_lock, flags);
1061 gpio_data = RD_REG_DWORD(®->gpiod);
1063 /* Disable the gpio_data reg for update. */
1064 gpio_data &= ~GPDX_LED_UPDATE_MASK;
1065 WRT_REG_DWORD(®->gpiod, gpio_data);
1066 RD_REG_DWORD(®->gpiod);
1067 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1069 ha->fw_options[1] &= ~ADD_FO1_DISABLE_GPIO_LED_CTRL;
1071 if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
1072 qla_printk(KERN_WARNING, ha,
1073 "Unable to update fw options (beacon off).\n");
1074 return QLA_FUNCTION_FAILED;
1077 if (qla2x00_get_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
1078 qla_printk(KERN_WARNING, ha,
1079 "Unable to get fw options (beacon off).\n");
1080 return QLA_FUNCTION_FAILED;
1088 * Flash support routines
1092 * qla2x00_flash_enable() - Setup flash for reading and writing.
1096 qla2x00_flash_enable(scsi_qla_host_t *ha)
1099 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1101 data = RD_REG_WORD(®->ctrl_status);
1102 data |= CSR_FLASH_ENABLE;
1103 WRT_REG_WORD(®->ctrl_status, data);
1104 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1108 * qla2x00_flash_disable() - Disable flash and allow RISC to run.
1112 qla2x00_flash_disable(scsi_qla_host_t *ha)
1115 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1117 data = RD_REG_WORD(®->ctrl_status);
1118 data &= ~(CSR_FLASH_ENABLE);
1119 WRT_REG_WORD(®->ctrl_status, data);
1120 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1124 * qla2x00_read_flash_byte() - Reads a byte from flash
1126 * @addr: Address in flash to read
1128 * A word is read from the chip, but, only the lower byte is valid.
1130 * Returns the byte read from flash @addr.
1133 qla2x00_read_flash_byte(scsi_qla_host_t *ha, uint32_t addr)
1136 uint16_t bank_select;
1137 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1139 bank_select = RD_REG_WORD(®->ctrl_status);
1141 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
1142 /* Specify 64K address range: */
1143 /* clear out Module Select and Flash Address bits [19:16]. */
1144 bank_select &= ~0xf8;
1145 bank_select |= addr >> 12 & 0xf0;
1146 bank_select |= CSR_FLASH_64K_BANK;
1147 WRT_REG_WORD(®->ctrl_status, bank_select);
1148 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1150 WRT_REG_WORD(®->flash_address, (uint16_t)addr);
1151 data = RD_REG_WORD(®->flash_data);
1153 return (uint8_t)data;
1156 /* Setup bit 16 of flash address. */
1157 if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
1158 bank_select |= CSR_FLASH_64K_BANK;
1159 WRT_REG_WORD(®->ctrl_status, bank_select);
1160 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1161 } else if (((addr & BIT_16) == 0) &&
1162 (bank_select & CSR_FLASH_64K_BANK)) {
1163 bank_select &= ~(CSR_FLASH_64K_BANK);
1164 WRT_REG_WORD(®->ctrl_status, bank_select);
1165 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1168 /* Always perform IO mapped accesses to the FLASH registers. */
1169 if (ha->pio_address) {
1172 reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
1173 WRT_REG_WORD_PIO(®->flash_address, (uint16_t)addr);
1175 data = RD_REG_WORD_PIO(®->flash_data);
1178 data2 = RD_REG_WORD_PIO(®->flash_data);
1179 } while (data != data2);
1181 WRT_REG_WORD(®->flash_address, (uint16_t)addr);
1182 data = qla2x00_debounce_register(®->flash_data);
1185 return (uint8_t)data;
1189 * qla2x00_write_flash_byte() - Write a byte to flash
1191 * @addr: Address in flash to write
1192 * @data: Data to write
1195 qla2x00_write_flash_byte(scsi_qla_host_t *ha, uint32_t addr, uint8_t data)
1197 uint16_t bank_select;
1198 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1200 bank_select = RD_REG_WORD(®->ctrl_status);
1201 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
1202 /* Specify 64K address range: */
1203 /* clear out Module Select and Flash Address bits [19:16]. */
1204 bank_select &= ~0xf8;
1205 bank_select |= addr >> 12 & 0xf0;
1206 bank_select |= CSR_FLASH_64K_BANK;
1207 WRT_REG_WORD(®->ctrl_status, bank_select);
1208 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1210 WRT_REG_WORD(®->flash_address, (uint16_t)addr);
1211 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1212 WRT_REG_WORD(®->flash_data, (uint16_t)data);
1213 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1218 /* Setup bit 16 of flash address. */
1219 if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
1220 bank_select |= CSR_FLASH_64K_BANK;
1221 WRT_REG_WORD(®->ctrl_status, bank_select);
1222 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1223 } else if (((addr & BIT_16) == 0) &&
1224 (bank_select & CSR_FLASH_64K_BANK)) {
1225 bank_select &= ~(CSR_FLASH_64K_BANK);
1226 WRT_REG_WORD(®->ctrl_status, bank_select);
1227 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1230 /* Always perform IO mapped accesses to the FLASH registers. */
1231 if (ha->pio_address) {
1232 reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
1233 WRT_REG_WORD_PIO(®->flash_address, (uint16_t)addr);
1234 WRT_REG_WORD_PIO(®->flash_data, (uint16_t)data);
1236 WRT_REG_WORD(®->flash_address, (uint16_t)addr);
1237 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1238 WRT_REG_WORD(®->flash_data, (uint16_t)data);
1239 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1244 * qla2x00_poll_flash() - Polls flash for completion.
1246 * @addr: Address in flash to poll
1247 * @poll_data: Data to be polled
1248 * @man_id: Flash manufacturer ID
1249 * @flash_id: Flash ID
1251 * This function polls the device until bit 7 of what is read matches data
1252 * bit 7 or until data bit 5 becomes a 1. If that hapens, the flash ROM timed
1253 * out (a fatal error). The flash book recommeds reading bit 7 again after
1254 * reading bit 5 as a 1.
1256 * Returns 0 on success, else non-zero.
1259 qla2x00_poll_flash(scsi_qla_host_t *ha, uint32_t addr, uint8_t poll_data,
1260 uint8_t man_id, uint8_t flash_id)
1268 /* Wait for 30 seconds for command to finish. */
1270 for (cnt = 3000000; cnt; cnt--) {
1271 flash_data = qla2x00_read_flash_byte(ha, addr);
1272 if ((flash_data & BIT_7) == poll_data) {
1277 if (man_id != 0x40 && man_id != 0xda) {
1278 if ((flash_data & BIT_5) && cnt > 2)
1289 * qla2x00_program_flash_address() - Programs a flash address
1291 * @addr: Address in flash to program
1292 * @data: Data to be written in flash
1293 * @man_id: Flash manufacturer ID
1294 * @flash_id: Flash ID
1296 * Returns 0 on success, else non-zero.
1299 qla2x00_program_flash_address(scsi_qla_host_t *ha, uint32_t addr, uint8_t data,
1300 uint8_t man_id, uint8_t flash_id)
1302 /* Write Program Command Sequence. */
1303 if (IS_OEM_001(ha)) {
1304 qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
1305 qla2x00_write_flash_byte(ha, 0x555, 0x55);
1306 qla2x00_write_flash_byte(ha, 0xaaa, 0xa0);
1307 qla2x00_write_flash_byte(ha, addr, data);
1309 if (man_id == 0xda && flash_id == 0xc1) {
1310 qla2x00_write_flash_byte(ha, addr, data);
1314 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1315 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1316 qla2x00_write_flash_byte(ha, 0x5555, 0xa0);
1317 qla2x00_write_flash_byte(ha, addr, data);
1323 /* Wait for write to complete. */
1324 return qla2x00_poll_flash(ha, addr, data, man_id, flash_id);
1328 * qla2x00_erase_flash() - Erase the flash.
1330 * @man_id: Flash manufacturer ID
1331 * @flash_id: Flash ID
1333 * Returns 0 on success, else non-zero.
1336 qla2x00_erase_flash(scsi_qla_host_t *ha, uint8_t man_id, uint8_t flash_id)
1338 /* Individual Sector Erase Command Sequence */
1339 if (IS_OEM_001(ha)) {
1340 qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
1341 qla2x00_write_flash_byte(ha, 0x555, 0x55);
1342 qla2x00_write_flash_byte(ha, 0xaaa, 0x80);
1343 qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
1344 qla2x00_write_flash_byte(ha, 0x555, 0x55);
1345 qla2x00_write_flash_byte(ha, 0xaaa, 0x10);
1347 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1348 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1349 qla2x00_write_flash_byte(ha, 0x5555, 0x80);
1350 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1351 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1352 qla2x00_write_flash_byte(ha, 0x5555, 0x10);
1357 /* Wait for erase to complete. */
1358 return qla2x00_poll_flash(ha, 0x00, 0x80, man_id, flash_id);
1362 * qla2x00_erase_flash_sector() - Erase a flash sector.
1364 * @addr: Flash sector to erase
1365 * @sec_mask: Sector address mask
1366 * @man_id: Flash manufacturer ID
1367 * @flash_id: Flash ID
1369 * Returns 0 on success, else non-zero.
1372 qla2x00_erase_flash_sector(scsi_qla_host_t *ha, uint32_t addr,
1373 uint32_t sec_mask, uint8_t man_id, uint8_t flash_id)
1375 /* Individual Sector Erase Command Sequence */
1376 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1377 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1378 qla2x00_write_flash_byte(ha, 0x5555, 0x80);
1379 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1380 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1381 if (man_id == 0x1f && flash_id == 0x13)
1382 qla2x00_write_flash_byte(ha, addr & sec_mask, 0x10);
1384 qla2x00_write_flash_byte(ha, addr & sec_mask, 0x30);
1388 /* Wait for erase to complete. */
1389 return qla2x00_poll_flash(ha, addr, 0x80, man_id, flash_id);
1393 * qla2x00_get_flash_manufacturer() - Read manufacturer ID from flash chip.
1394 * @man_id: Flash manufacturer ID
1395 * @flash_id: Flash ID
1398 qla2x00_get_flash_manufacturer(scsi_qla_host_t *ha, uint8_t *man_id,
1401 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1402 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1403 qla2x00_write_flash_byte(ha, 0x5555, 0x90);
1404 *man_id = qla2x00_read_flash_byte(ha, 0x0000);
1405 *flash_id = qla2x00_read_flash_byte(ha, 0x0001);
1406 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1407 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1408 qla2x00_write_flash_byte(ha, 0x5555, 0xf0);
1412 qla2x00_read_flash_data(scsi_qla_host_t *ha, uint8_t *tmp_buf, uint32_t saddr,
1415 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1416 uint32_t midpoint, ilength;
1419 midpoint = length / 2;
1421 WRT_REG_WORD(®->nvram, 0);
1422 RD_REG_WORD(®->nvram);
1423 for (ilength = 0; ilength < length; saddr++, ilength++, tmp_buf++) {
1424 if (ilength == midpoint) {
1425 WRT_REG_WORD(®->nvram, NVR_SELECT);
1426 RD_REG_WORD(®->nvram);
1428 data = qla2x00_read_flash_byte(ha, saddr);
1437 qla2x00_suspend_hba(struct scsi_qla_host *ha)
1440 unsigned long flags;
1441 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1444 scsi_block_requests(ha->host);
1445 ha->isp_ops->disable_intrs(ha);
1446 set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
1449 spin_lock_irqsave(&ha->hardware_lock, flags);
1450 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
1451 RD_REG_WORD(®->hccr);
1452 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1453 for (cnt = 0; cnt < 30000; cnt++) {
1454 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
1461 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1465 qla2x00_resume_hba(struct scsi_qla_host *ha)
1468 clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
1469 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1470 qla2xxx_wake_dpc(ha);
1471 qla2x00_wait_for_hba_online(ha);
1472 scsi_unblock_requests(ha->host);
1476 qla2x00_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
1477 uint32_t offset, uint32_t length)
1479 uint32_t addr, midpoint;
1481 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1484 qla2x00_suspend_hba(ha);
1487 midpoint = ha->optrom_size / 2;
1489 qla2x00_flash_enable(ha);
1490 WRT_REG_WORD(®->nvram, 0);
1491 RD_REG_WORD(®->nvram); /* PCI Posting. */
1492 for (addr = offset, data = buf; addr < length; addr++, data++) {
1493 if (addr == midpoint) {
1494 WRT_REG_WORD(®->nvram, NVR_SELECT);
1495 RD_REG_WORD(®->nvram); /* PCI Posting. */
1498 *data = qla2x00_read_flash_byte(ha, addr);
1500 qla2x00_flash_disable(ha);
1503 qla2x00_resume_hba(ha);
1509 qla2x00_write_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
1510 uint32_t offset, uint32_t length)
1514 uint8_t man_id, flash_id, sec_number, data;
1516 uint32_t addr, liter, sec_mask, rest_addr;
1517 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1520 qla2x00_suspend_hba(ha);
1525 /* Reset ISP chip. */
1526 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
1527 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
1529 /* Go with write. */
1530 qla2x00_flash_enable(ha);
1531 do { /* Loop once to provide quick error exit */
1532 /* Structure of flash memory based on manufacturer */
1533 if (IS_OEM_001(ha)) {
1534 /* OEM variant with special flash part. */
1535 man_id = flash_id = 0;
1540 qla2x00_get_flash_manufacturer(ha, &man_id, &flash_id);
1542 case 0x20: /* ST flash. */
1543 if (flash_id == 0xd2 || flash_id == 0xe3) {
1545 * ST m29w008at part - 64kb sector size with
1546 * 32kb,8kb,8kb,16kb sectors at memory address
1554 * ST m29w010b part - 16kb sector size
1555 * Default to 16kb sectors
1560 case 0x40: /* Mostel flash. */
1561 /* Mostel v29c51001 part - 512 byte sector size. */
1565 case 0xbf: /* SST flash. */
1566 /* SST39sf10 part - 4kb sector size. */
1570 case 0xda: /* Winbond flash. */
1571 /* Winbond W29EE011 part - 256 byte sector size. */
1575 case 0xc2: /* Macronix flash. */
1576 /* 64k sector size. */
1577 if (flash_id == 0x38 || flash_id == 0x4f) {
1582 /* Fall through... */
1584 case 0x1f: /* Atmel flash. */
1585 /* 512k sector size. */
1586 if (flash_id == 0x13) {
1587 rest_addr = 0x7fffffff;
1588 sec_mask = 0x80000000;
1591 /* Fall through... */
1593 case 0x01: /* AMD flash. */
1594 if (flash_id == 0x38 || flash_id == 0x40 ||
1596 /* Am29LV081 part - 64kb sector size. */
1597 /* Am29LV002BT part - 64kb sector size. */
1601 } else if (flash_id == 0x3e) {
1603 * Am29LV008b part - 64kb sector size with
1604 * 32kb,8kb,8kb,16kb sector at memory address
1610 } else if (flash_id == 0x20 || flash_id == 0x6e) {
1612 * Am29LV010 part or AM29f010 - 16kb sector
1618 } else if (flash_id == 0x6d) {
1619 /* Am29LV001 part - 8kb sector size. */
1625 /* Default to 16 kb sector size. */
1632 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
1633 if (qla2x00_erase_flash(ha, man_id, flash_id)) {
1634 rval = QLA_FUNCTION_FAILED;
1639 for (addr = offset, liter = 0; liter < length; liter++,
1642 /* Are we at the beginning of a sector? */
1643 if ((addr & rest_addr) == 0) {
1644 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
1645 if (addr >= 0x10000UL) {
1646 if (((addr >> 12) & 0xf0) &&
1648 flash_id == 0x3e) ||
1650 flash_id == 0xd2))) {
1652 if (sec_number == 1) {
1673 } else if (addr == ha->optrom_size / 2) {
1674 WRT_REG_WORD(®->nvram, NVR_SELECT);
1675 RD_REG_WORD(®->nvram);
1678 if (flash_id == 0xda && man_id == 0xc1) {
1679 qla2x00_write_flash_byte(ha, 0x5555,
1681 qla2x00_write_flash_byte(ha, 0x2aaa,
1683 qla2x00_write_flash_byte(ha, 0x5555,
1685 } else if (!IS_QLA2322(ha) && !IS_QLA6322(ha)) {
1687 if (qla2x00_erase_flash_sector(ha,
1688 addr, sec_mask, man_id,
1690 rval = QLA_FUNCTION_FAILED;
1693 if (man_id == 0x01 && flash_id == 0x6d)
1698 if (man_id == 0x01 && flash_id == 0x6d) {
1699 if (sec_number == 1 &&
1700 addr == (rest_addr - 1)) {
1703 } else if (sec_number == 3 && (addr & 0x7ffe)) {
1709 if (qla2x00_program_flash_address(ha, addr, data,
1710 man_id, flash_id)) {
1711 rval = QLA_FUNCTION_FAILED;
1717 qla2x00_flash_disable(ha);
1720 qla2x00_resume_hba(ha);
1726 qla24xx_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
1727 uint32_t offset, uint32_t length)
1730 scsi_block_requests(ha->host);
1731 ha->isp_ops->disable_intrs(ha);
1732 set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
1735 qla24xx_read_flash_data(ha, (uint32_t *)buf, offset >> 2, length >> 2);
1738 clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
1739 ha->isp_ops->enable_intrs(ha);
1740 scsi_unblock_requests(ha->host);
1746 qla24xx_write_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
1747 uint32_t offset, uint32_t length)
1752 scsi_block_requests(ha->host);
1753 ha->isp_ops->disable_intrs(ha);
1754 set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
1756 /* Go with write. */
1757 rval = qla24xx_write_flash_data(ha, (uint32_t *)buf, offset >> 2,
1760 /* Resume HBA -- RISC reset needed. */
1761 clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
1762 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1763 qla2xxx_wake_dpc(ha);
1764 qla2x00_wait_for_hba_online(ha);
1765 scsi_unblock_requests(ha->host);
1771 * qla2x00_get_fcode_version() - Determine an FCODE image's version.
1773 * @pcids: Pointer to the FCODE PCI data structure
1775 * The process of retrieving the FCODE version information is at best
1776 * described as interesting.
1778 * Within the first 100h bytes of the image an ASCII string is present
1779 * which contains several pieces of information including the FCODE
1780 * version. Unfortunately it seems the only reliable way to retrieve
1781 * the version is by scanning for another sentinel within the string,
1782 * the FCODE build date:
1784 * ... 2.00.02 10/17/02 ...
1786 * Returns QLA_SUCCESS on successful retrieval of version.
1789 qla2x00_get_fcode_version(scsi_qla_host_t *ha, uint32_t pcids)
1791 int ret = QLA_FUNCTION_FAILED;
1792 uint32_t istart, iend, iter, vend;
1793 uint8_t do_next, rbyte, *vbyte;
1795 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
1797 /* Skip the PCI data structure. */
1799 ((qla2x00_read_flash_byte(ha, pcids + 0x0B) << 8) |
1800 qla2x00_read_flash_byte(ha, pcids + 0x0A));
1801 iend = istart + 0x100;
1803 /* Scan for the sentinel date string...eeewww. */
1806 while ((iter < iend) && !do_next) {
1808 if (qla2x00_read_flash_byte(ha, iter) == '/') {
1809 if (qla2x00_read_flash_byte(ha, iter + 2) ==
1812 else if (qla2x00_read_flash_byte(ha,
1820 /* Backtrack to previous ' ' (space). */
1822 while ((iter > istart) && !do_next) {
1824 if (qla2x00_read_flash_byte(ha, iter) == ' ')
1831 * Mark end of version tag, and find previous ' ' (space) or
1832 * string length (recent FCODE images -- major hack ahead!!!).
1836 while ((iter > istart) && !do_next) {
1838 rbyte = qla2x00_read_flash_byte(ha, iter);
1839 if (rbyte == ' ' || rbyte == 0xd || rbyte == 0x10)
1845 /* Mark beginning of version tag, and copy data. */
1847 if ((vend - iter) &&
1848 ((vend - iter) < sizeof(ha->fcode_revision))) {
1849 vbyte = ha->fcode_revision;
1850 while (iter <= vend) {
1851 *vbyte++ = qla2x00_read_flash_byte(ha, iter);
1858 if (ret != QLA_SUCCESS)
1859 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
1863 qla2x00_get_flash_version(scsi_qla_host_t *ha, void *mbuf)
1865 int ret = QLA_SUCCESS;
1866 uint8_t code_type, last_image;
1867 uint32_t pcihdr, pcids;
1871 if (!ha->pio_address || !mbuf)
1872 return QLA_FUNCTION_FAILED;
1874 memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
1875 memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
1876 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
1877 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
1879 qla2x00_flash_enable(ha);
1881 /* Begin with first PCI expansion ROM header. */
1885 /* Verify PCI expansion ROM header. */
1886 if (qla2x00_read_flash_byte(ha, pcihdr) != 0x55 ||
1887 qla2x00_read_flash_byte(ha, pcihdr + 0x01) != 0xaa) {
1889 DEBUG2(printk("scsi(%ld): No matching ROM "
1890 "signature.\n", ha->host_no));
1891 ret = QLA_FUNCTION_FAILED;
1895 /* Locate PCI data structure. */
1897 ((qla2x00_read_flash_byte(ha, pcihdr + 0x19) << 8) |
1898 qla2x00_read_flash_byte(ha, pcihdr + 0x18));
1900 /* Validate signature of PCI data structure. */
1901 if (qla2x00_read_flash_byte(ha, pcids) != 'P' ||
1902 qla2x00_read_flash_byte(ha, pcids + 0x1) != 'C' ||
1903 qla2x00_read_flash_byte(ha, pcids + 0x2) != 'I' ||
1904 qla2x00_read_flash_byte(ha, pcids + 0x3) != 'R') {
1905 /* Incorrect header. */
1906 DEBUG2(printk("%s(): PCI data struct not found "
1907 "pcir_adr=%x.\n", __func__, pcids));
1908 ret = QLA_FUNCTION_FAILED;
1913 code_type = qla2x00_read_flash_byte(ha, pcids + 0x14);
1914 switch (code_type) {
1915 case ROM_CODE_TYPE_BIOS:
1916 /* Intel x86, PC-AT compatible. */
1917 ha->bios_revision[0] =
1918 qla2x00_read_flash_byte(ha, pcids + 0x12);
1919 ha->bios_revision[1] =
1920 qla2x00_read_flash_byte(ha, pcids + 0x13);
1921 DEBUG3(printk("%s(): read BIOS %d.%d.\n", __func__,
1922 ha->bios_revision[1], ha->bios_revision[0]));
1924 case ROM_CODE_TYPE_FCODE:
1925 /* Open Firmware standard for PCI (FCode). */
1927 qla2x00_get_fcode_version(ha, pcids);
1929 case ROM_CODE_TYPE_EFI:
1930 /* Extensible Firmware Interface (EFI). */
1931 ha->efi_revision[0] =
1932 qla2x00_read_flash_byte(ha, pcids + 0x12);
1933 ha->efi_revision[1] =
1934 qla2x00_read_flash_byte(ha, pcids + 0x13);
1935 DEBUG3(printk("%s(): read EFI %d.%d.\n", __func__,
1936 ha->efi_revision[1], ha->efi_revision[0]));
1939 DEBUG2(printk("%s(): Unrecognized code type %x at "
1940 "pcids %x.\n", __func__, code_type, pcids));
1944 last_image = qla2x00_read_flash_byte(ha, pcids + 0x15) & BIT_7;
1946 /* Locate next PCI expansion ROM. */
1947 pcihdr += ((qla2x00_read_flash_byte(ha, pcids + 0x11) << 8) |
1948 qla2x00_read_flash_byte(ha, pcids + 0x10)) * 512;
1949 } while (!last_image);
1951 if (IS_QLA2322(ha)) {
1952 /* Read firmware image information. */
1953 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
1955 memset(dbyte, 0, 8);
1956 dcode = (uint16_t *)dbyte;
1958 qla2x00_read_flash_data(ha, dbyte, FA_RISC_CODE_ADDR * 4 + 10,
1960 DEBUG3(printk("%s(%ld): dumping fw ver from flash:\n",
1961 __func__, ha->host_no));
1962 DEBUG3(qla2x00_dump_buffer((uint8_t *)dbyte, 8));
1964 if ((dcode[0] == 0xffff && dcode[1] == 0xffff &&
1965 dcode[2] == 0xffff && dcode[3] == 0xffff) ||
1966 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
1968 DEBUG2(printk("%s(): Unrecognized fw revision at "
1969 "%x.\n", __func__, FA_RISC_CODE_ADDR * 4));
1971 /* values are in big endian */
1972 ha->fw_revision[0] = dbyte[0] << 16 | dbyte[1];
1973 ha->fw_revision[1] = dbyte[2] << 16 | dbyte[3];
1974 ha->fw_revision[2] = dbyte[4] << 16 | dbyte[5];
1978 qla2x00_flash_disable(ha);
1984 qla24xx_get_flash_version(scsi_qla_host_t *ha, void *mbuf)
1986 int ret = QLA_SUCCESS;
1987 uint32_t pcihdr, pcids;
1990 uint8_t code_type, last_image;
1994 return QLA_FUNCTION_FAILED;
1996 memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
1997 memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
1998 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
1999 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
2003 /* Begin with first PCI expansion ROM header. */
2007 /* Verify PCI expansion ROM header. */
2008 qla24xx_read_flash_data(ha, dcode, pcihdr >> 2, 0x20);
2009 bcode = mbuf + (pcihdr % 4);
2010 if (bcode[0x0] != 0x55 || bcode[0x1] != 0xaa) {
2012 DEBUG2(printk("scsi(%ld): No matching ROM "
2013 "signature.\n", ha->host_no));
2014 ret = QLA_FUNCTION_FAILED;
2018 /* Locate PCI data structure. */
2019 pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]);
2021 qla24xx_read_flash_data(ha, dcode, pcids >> 2, 0x20);
2022 bcode = mbuf + (pcihdr % 4);
2024 /* Validate signature of PCI data structure. */
2025 if (bcode[0x0] != 'P' || bcode[0x1] != 'C' ||
2026 bcode[0x2] != 'I' || bcode[0x3] != 'R') {
2027 /* Incorrect header. */
2028 DEBUG2(printk("%s(): PCI data struct not found "
2029 "pcir_adr=%x.\n", __func__, pcids));
2030 ret = QLA_FUNCTION_FAILED;
2035 code_type = bcode[0x14];
2036 switch (code_type) {
2037 case ROM_CODE_TYPE_BIOS:
2038 /* Intel x86, PC-AT compatible. */
2039 ha->bios_revision[0] = bcode[0x12];
2040 ha->bios_revision[1] = bcode[0x13];
2041 DEBUG3(printk("%s(): read BIOS %d.%d.\n", __func__,
2042 ha->bios_revision[1], ha->bios_revision[0]));
2044 case ROM_CODE_TYPE_FCODE:
2045 /* Open Firmware standard for PCI (FCode). */
2046 ha->fcode_revision[0] = bcode[0x12];
2047 ha->fcode_revision[1] = bcode[0x13];
2048 DEBUG3(printk("%s(): read FCODE %d.%d.\n", __func__,
2049 ha->fcode_revision[1], ha->fcode_revision[0]));
2051 case ROM_CODE_TYPE_EFI:
2052 /* Extensible Firmware Interface (EFI). */
2053 ha->efi_revision[0] = bcode[0x12];
2054 ha->efi_revision[1] = bcode[0x13];
2055 DEBUG3(printk("%s(): read EFI %d.%d.\n", __func__,
2056 ha->efi_revision[1], ha->efi_revision[0]));
2059 DEBUG2(printk("%s(): Unrecognized code type %x at "
2060 "pcids %x.\n", __func__, code_type, pcids));
2064 last_image = bcode[0x15] & BIT_7;
2066 /* Locate next PCI expansion ROM. */
2067 pcihdr += ((bcode[0x11] << 8) | bcode[0x10]) * 512;
2068 } while (!last_image);
2070 /* Read firmware image information. */
2071 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
2074 qla24xx_read_flash_data(ha, dcode, FA_RISC_CODE_ADDR + 4, 4);
2075 for (i = 0; i < 4; i++)
2076 dcode[i] = be32_to_cpu(dcode[i]);
2078 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
2079 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
2080 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
2082 DEBUG2(printk("%s(): Unrecognized fw version at %x.\n",
2083 __func__, FA_RISC_CODE_ADDR));
2085 ha->fw_revision[0] = dcode[0];
2086 ha->fw_revision[1] = dcode[1];
2087 ha->fw_revision[2] = dcode[2];
2088 ha->fw_revision[3] = dcode[3];