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_find_flt_start(scsi_qla_host_t *ha, uint32_t *start)
549 const char *loc, *locations[] = { "DEF", "PCI" };
550 uint32_t pcihdr, pcids;
552 uint8_t *buf, *bcode, last_image;
553 uint16_t cnt, chksum, *wptr;
554 struct qla_flt_location *fltl;
557 * FLT-location structure resides after the last PCI region.
560 /* Begin with sane defaults. */
562 *start = IS_QLA24XX_TYPE(ha) ? FA_FLASH_LAYOUT_ADDR_24:
563 FA_FLASH_LAYOUT_ADDR;
565 /* Begin with first PCI expansion ROM header. */
566 buf = (uint8_t *)ha->request_ring;
567 dcode = (uint32_t *)ha->request_ring;
571 /* Verify PCI expansion ROM header. */
572 qla24xx_read_flash_data(ha, dcode, pcihdr >> 2, 0x20);
573 bcode = buf + (pcihdr % 4);
574 if (bcode[0x0] != 0x55 || bcode[0x1] != 0xaa)
577 /* Locate PCI data structure. */
578 pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]);
579 qla24xx_read_flash_data(ha, dcode, pcids >> 2, 0x20);
580 bcode = buf + (pcihdr % 4);
582 /* Validate signature of PCI data structure. */
583 if (bcode[0x0] != 'P' || bcode[0x1] != 'C' ||
584 bcode[0x2] != 'I' || bcode[0x3] != 'R')
587 last_image = bcode[0x15] & BIT_7;
589 /* Locate next PCI expansion ROM. */
590 pcihdr += ((bcode[0x11] << 8) | bcode[0x10]) * 512;
591 } while (!last_image);
593 /* Now verify FLT-location structure. */
594 fltl = (struct qla_flt_location *)ha->request_ring;
595 qla24xx_read_flash_data(ha, dcode, pcihdr >> 2,
596 sizeof(struct qla_flt_location) >> 2);
597 if (fltl->sig[0] != 'Q' || fltl->sig[1] != 'F' ||
598 fltl->sig[2] != 'L' || fltl->sig[3] != 'T')
601 wptr = (uint16_t *)ha->request_ring;
602 cnt = sizeof(struct qla_flt_location) >> 1;
603 for (chksum = 0; cnt; cnt--)
604 chksum += le16_to_cpu(*wptr++);
606 qla_printk(KERN_ERR, ha,
607 "Inconsistent FLTL detected: checksum=0x%x.\n", chksum);
608 qla2x00_dump_buffer(buf, sizeof(struct qla_flt_location));
609 return QLA_FUNCTION_FAILED;
612 /* Good data. Use specified location. */
614 *start = le16_to_cpu(fltl->start_hi) << 16 |
615 le16_to_cpu(fltl->start_lo);
617 DEBUG2(qla_printk(KERN_DEBUG, ha, "FLTL[%s] = 0x%x.\n", loc, *start));
622 qla2xxx_get_flt_info(scsi_qla_host_t *ha, uint32_t flt_addr)
624 const char *loc, *locations[] = { "DEF", "FLT" };
626 uint16_t cnt, chksum;
628 struct qla_flt_header *flt;
629 struct qla_flt_region *region;
631 ha->flt_region_flt = flt_addr;
632 wptr = (uint16_t *)ha->request_ring;
633 flt = (struct qla_flt_header *)ha->request_ring;
634 region = (struct qla_flt_region *)&flt[1];
635 ha->isp_ops->read_optrom(ha, (uint8_t *)ha->request_ring,
636 flt_addr << 2, OPTROM_BURST_SIZE);
637 if (*wptr == __constant_cpu_to_le16(0xffff))
639 if (flt->version != __constant_cpu_to_le16(1)) {
640 DEBUG2(qla_printk(KERN_INFO, ha, "Unsupported FLT detected: "
641 "version=0x%x length=0x%x checksum=0x%x.\n",
642 le16_to_cpu(flt->version), le16_to_cpu(flt->length),
643 le16_to_cpu(flt->checksum)));
647 cnt = (sizeof(struct qla_flt_header) + le16_to_cpu(flt->length)) >> 1;
648 for (chksum = 0; cnt; cnt--)
649 chksum += le16_to_cpu(*wptr++);
651 DEBUG2(qla_printk(KERN_INFO, ha, "Inconsistent FLT detected: "
652 "version=0x%x length=0x%x checksum=0x%x.\n",
653 le16_to_cpu(flt->version), le16_to_cpu(flt->length),
659 cnt = le16_to_cpu(flt->length) / sizeof(struct qla_flt_region);
660 for ( ; cnt; cnt--, region++) {
661 /* Store addresses as DWORD offsets. */
662 start = le32_to_cpu(region->start) >> 2;
664 DEBUG3(qla_printk(KERN_DEBUG, ha, "FLT[%02x]: start=0x%x "
665 "end=0x%x size=0x%x.\n", le32_to_cpu(region->code), start,
666 le32_to_cpu(region->end) >> 2, le32_to_cpu(region->size)));
668 switch (le32_to_cpu(region->code)) {
670 ha->flt_region_fw = start;
672 case FLT_REG_BOOT_CODE:
673 ha->flt_region_boot = start;
676 ha->flt_region_vpd_nvram = start;
679 ha->flt_region_fdt = start;
681 case FLT_REG_HW_EVENT_0:
682 if (!PCI_FUNC(ha->pdev->devfn))
683 ha->flt_region_hw_event = start;
685 case FLT_REG_HW_EVENT_1:
686 if (PCI_FUNC(ha->pdev->devfn))
687 ha->flt_region_hw_event = start;
689 case FLT_REG_NPIV_CONF_0:
690 if (!PCI_FUNC(ha->pdev->devfn))
691 ha->flt_region_npiv_conf = start;
693 case FLT_REG_NPIV_CONF_1:
694 if (PCI_FUNC(ha->pdev->devfn))
695 ha->flt_region_npiv_conf = start;
702 /* Use hardcoded defaults. */
704 ha->flt_region_fw = FA_RISC_CODE_ADDR;
705 ha->flt_region_boot = FA_BOOT_CODE_ADDR;
706 ha->flt_region_vpd_nvram = FA_VPD_NVRAM_ADDR;
707 ha->flt_region_fdt = IS_QLA24XX_TYPE(ha) ? FA_FLASH_DESCR_ADDR_24:
709 ha->flt_region_hw_event = !PCI_FUNC(ha->pdev->devfn) ?
710 FA_HW_EVENT0_ADDR: FA_HW_EVENT1_ADDR;
711 ha->flt_region_npiv_conf = !PCI_FUNC(ha->pdev->devfn) ?
712 (IS_QLA24XX_TYPE(ha) ? FA_NPIV_CONF0_ADDR_24: FA_NPIV_CONF0_ADDR):
713 (IS_QLA24XX_TYPE(ha) ? FA_NPIV_CONF1_ADDR_24: FA_NPIV_CONF1_ADDR);
715 DEBUG2(qla_printk(KERN_DEBUG, ha, "FLT[%s]: boot=0x%x fw=0x%x "
716 "vpd_nvram=0x%x fdt=0x%x flt=0x%x hwe=0x%x npiv=0x%x.\n", loc,
717 ha->flt_region_boot, ha->flt_region_fw, ha->flt_region_vpd_nvram,
718 ha->flt_region_fdt, ha->flt_region_flt, ha->flt_region_hw_event,
719 ha->flt_region_npiv_conf));
723 qla2xxx_get_fdt_info(scsi_qla_host_t *ha)
725 #define FLASH_BLK_SIZE_32K 0x8000
726 #define FLASH_BLK_SIZE_64K 0x10000
727 const char *loc, *locations[] = { "MID", "FDT" };
728 uint16_t cnt, chksum;
730 struct qla_fdt_layout *fdt;
731 uint8_t man_id, flash_id;
734 wptr = (uint16_t *)ha->request_ring;
735 fdt = (struct qla_fdt_layout *)ha->request_ring;
736 ha->isp_ops->read_optrom(ha, (uint8_t *)ha->request_ring,
737 ha->flt_region_fdt << 2, OPTROM_BURST_SIZE);
738 if (*wptr == __constant_cpu_to_le16(0xffff))
740 if (fdt->sig[0] != 'Q' || fdt->sig[1] != 'L' || fdt->sig[2] != 'I' ||
744 for (cnt = 0, chksum = 0; cnt < sizeof(struct qla_fdt_layout) >> 1;
746 chksum += le16_to_cpu(*wptr++);
748 DEBUG2(qla_printk(KERN_INFO, ha, "Inconsistent FDT detected: "
749 "checksum=0x%x id=%c version=0x%x.\n", chksum, fdt->sig[0],
750 le16_to_cpu(fdt->version)));
751 DEBUG9(qla2x00_dump_buffer((uint8_t *)fdt, sizeof(*fdt)));
756 mid = le16_to_cpu(fdt->man_id);
757 fid = le16_to_cpu(fdt->id);
758 ha->fdt_odd_index = mid == 0x1f;
759 ha->fdt_wrt_disable = fdt->wrt_disable_bits;
760 ha->fdt_erase_cmd = flash_conf_to_access_addr(0x0300 | fdt->erase_cmd);
761 ha->fdt_block_size = le32_to_cpu(fdt->block_size);
762 if (fdt->unprotect_sec_cmd) {
763 ha->fdt_unprotect_sec_cmd = flash_conf_to_access_addr(0x0300 |
764 fdt->unprotect_sec_cmd);
765 ha->fdt_protect_sec_cmd = fdt->protect_sec_cmd ?
766 flash_conf_to_access_addr(0x0300 | fdt->protect_sec_cmd):
767 flash_conf_to_access_addr(0x0336);
772 qla24xx_get_flash_manufacturer(ha, &man_id, &flash_id);
775 ha->fdt_wrt_disable = 0x9c;
776 ha->fdt_erase_cmd = flash_conf_to_access_addr(0x03d8);
778 case 0xbf: /* STT flash. */
779 if (flash_id == 0x8e)
780 ha->fdt_block_size = FLASH_BLK_SIZE_64K;
782 ha->fdt_block_size = FLASH_BLK_SIZE_32K;
784 if (flash_id == 0x80)
785 ha->fdt_erase_cmd = flash_conf_to_access_addr(0x0352);
787 case 0x13: /* ST M25P80. */
788 ha->fdt_block_size = FLASH_BLK_SIZE_64K;
790 case 0x1f: /* Atmel 26DF081A. */
791 ha->fdt_odd_index = 1;
792 ha->fdt_block_size = FLASH_BLK_SIZE_64K;
793 ha->fdt_erase_cmd = flash_conf_to_access_addr(0x0320);
794 ha->fdt_unprotect_sec_cmd = flash_conf_to_access_addr(0x0339);
795 ha->fdt_protect_sec_cmd = flash_conf_to_access_addr(0x0336);
798 /* Default to 64 kb sector size. */
799 ha->fdt_block_size = FLASH_BLK_SIZE_64K;
803 DEBUG2(qla_printk(KERN_DEBUG, ha, "FDT[%s]: (0x%x/0x%x) erase=0x%x "
804 "pro=%x upro=%x idx=%d wrtd=0x%x blk=0x%x.\n", loc, mid, fid,
805 ha->fdt_erase_cmd, ha->fdt_protect_sec_cmd,
806 ha->fdt_unprotect_sec_cmd, ha->fdt_odd_index, ha->fdt_wrt_disable,
807 ha->fdt_block_size));
811 qla2xxx_get_flash_info(scsi_qla_host_t *ha)
816 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
819 ret = qla2xxx_find_flt_start(ha, &flt_addr);
820 if (ret != QLA_SUCCESS)
823 qla2xxx_get_flt_info(ha, flt_addr);
824 qla2xxx_get_fdt_info(ha);
830 qla2xxx_flash_npiv_conf(scsi_qla_host_t *ha)
832 #define NPIV_CONFIG_SIZE (16*1024)
835 uint16_t cnt, chksum;
836 struct qla_npiv_header hdr;
837 struct qla_npiv_entry *entry;
839 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
842 ha->isp_ops->read_optrom(ha, (uint8_t *)&hdr,
843 ha->flt_region_npiv_conf << 2, sizeof(struct qla_npiv_header));
844 if (hdr.version == __constant_cpu_to_le16(0xffff))
846 if (hdr.version != __constant_cpu_to_le16(1)) {
847 DEBUG2(qla_printk(KERN_INFO, ha, "Unsupported NPIV-Config "
848 "detected: version=0x%x entries=0x%x checksum=0x%x.\n",
849 le16_to_cpu(hdr.version), le16_to_cpu(hdr.entries),
850 le16_to_cpu(hdr.checksum)));
854 data = kmalloc(NPIV_CONFIG_SIZE, GFP_KERNEL);
856 DEBUG2(qla_printk(KERN_INFO, ha, "NPIV-Config: Unable to "
857 "allocate memory.\n"));
861 ha->isp_ops->read_optrom(ha, (uint8_t *)data,
862 ha->flt_region_npiv_conf << 2, NPIV_CONFIG_SIZE);
864 cnt = (sizeof(struct qla_npiv_header) + le16_to_cpu(hdr.entries) *
865 sizeof(struct qla_npiv_entry)) >> 1;
866 for (wptr = data, chksum = 0; cnt; cnt--)
867 chksum += le16_to_cpu(*wptr++);
869 DEBUG2(qla_printk(KERN_INFO, ha, "Inconsistent NPIV-Config "
870 "detected: version=0x%x entries=0x%x checksum=0x%x.\n",
871 le16_to_cpu(hdr.version), le16_to_cpu(hdr.entries),
876 entry = data + sizeof(struct qla_npiv_header);
877 cnt = le16_to_cpu(hdr.entries);
878 for ( ; cnt; cnt--, entry++) {
880 struct fc_vport_identifiers vid;
881 struct fc_vport *vport;
883 flags = le16_to_cpu(entry->flags);
886 if ((flags & BIT_0) == 0)
889 memset(&vid, 0, sizeof(vid));
890 vid.roles = FC_PORT_ROLE_FCP_INITIATOR;
891 vid.vport_type = FC_PORTTYPE_NPIV;
893 vid.port_name = wwn_to_u64(entry->port_name);
894 vid.node_name = wwn_to_u64(entry->node_name);
896 DEBUG2(qla_printk(KERN_DEBUG, ha, "NPIV[%02x]: wwpn=%llx "
897 "wwnn=%llx vf_id=0x%x qos=0x%x.\n", cnt,
898 (unsigned long long)vid.port_name,
899 (unsigned long long)vid.node_name,
900 le16_to_cpu(entry->vf_id), le16_to_cpu(entry->qos)));
902 vport = fc_vport_create(ha->host, 0, &vid);
904 qla_printk(KERN_INFO, ha, "NPIV-Config: Failed to "
905 "create vport [%02x]: wwpn=%llx wwnn=%llx.\n", cnt,
906 (unsigned long long)vid.port_name,
907 (unsigned long long)vid.node_name);
914 qla24xx_unprotect_flash(scsi_qla_host_t *ha)
916 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
918 /* Enable flash write. */
919 WRT_REG_DWORD(®->ctrl_status,
920 RD_REG_DWORD(®->ctrl_status) | CSRX_FLASH_ENABLE);
921 RD_REG_DWORD(®->ctrl_status); /* PCI Posting. */
923 if (!ha->fdt_wrt_disable)
926 /* Disable flash write-protection. */
927 qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0);
928 /* Some flash parts need an additional zero-write to clear bits.*/
929 qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0);
933 qla24xx_protect_flash(scsi_qla_host_t *ha)
936 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
938 if (!ha->fdt_wrt_disable)
939 goto skip_wrt_protect;
941 /* Enable flash write-protection and wait for completion. */
942 qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101),
943 ha->fdt_wrt_disable);
944 for (cnt = 300; cnt &&
945 qla24xx_read_flash_dword(ha,
946 flash_conf_to_access_addr(0x005)) & BIT_0;
952 /* Disable flash write. */
953 WRT_REG_DWORD(®->ctrl_status,
954 RD_REG_DWORD(®->ctrl_status) & ~CSRX_FLASH_ENABLE);
955 RD_REG_DWORD(®->ctrl_status); /* PCI Posting. */
959 qla24xx_write_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
963 uint32_t liter, miter;
964 uint32_t sec_mask, rest_addr;
965 uint32_t fdata, findex;
966 dma_addr_t optrom_dma;
972 /* Prepare burst-capable write on supported ISPs. */
973 if (IS_QLA25XX(ha) && !(faddr & 0xfff) &&
974 dwords > OPTROM_BURST_DWORDS) {
975 optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
976 &optrom_dma, GFP_KERNEL);
978 qla_printk(KERN_DEBUG, ha,
979 "Unable to allocate memory for optrom burst write "
980 "(%x KB).\n", OPTROM_BURST_SIZE / 1024);
984 rest_addr = (ha->fdt_block_size >> 2) - 1;
985 sec_mask = 0x80000 - (ha->fdt_block_size >> 2);
987 qla24xx_unprotect_flash(ha);
989 for (liter = 0; liter < dwords; liter++, faddr++, dwptr++) {
990 if (ha->fdt_odd_index) {
992 fdata = findex & sec_mask;
995 fdata = (findex & sec_mask) << 2;
998 /* Are we at the beginning of a sector? */
999 if ((findex & rest_addr) == 0) {
1000 /* Do sector unprotect. */
1001 if (ha->fdt_unprotect_sec_cmd)
1002 qla24xx_write_flash_dword(ha,
1003 ha->fdt_unprotect_sec_cmd,
1004 (fdata & 0xff00) | ((fdata << 16) &
1005 0xff0000) | ((fdata >> 16) & 0xff));
1006 ret = qla24xx_write_flash_dword(ha, ha->fdt_erase_cmd,
1007 (fdata & 0xff00) |((fdata << 16) &
1008 0xff0000) | ((fdata >> 16) & 0xff));
1009 if (ret != QLA_SUCCESS) {
1010 DEBUG9(printk("%s(%ld) Unable to flash "
1011 "sector: address=%x.\n", __func__,
1012 ha->host_no, faddr));
1017 /* Go with burst-write. */
1018 if (optrom && (liter + OPTROM_BURST_DWORDS) <= dwords) {
1019 /* Copy data to DMA'ble buffer. */
1020 for (miter = 0, s = optrom, d = dwptr;
1021 miter < OPTROM_BURST_DWORDS; miter++, s++, d++)
1022 *s = cpu_to_le32(*d);
1024 ret = qla2x00_load_ram(ha, optrom_dma,
1025 flash_data_to_access_addr(faddr),
1026 OPTROM_BURST_DWORDS);
1027 if (ret != QLA_SUCCESS) {
1028 qla_printk(KERN_WARNING, ha,
1029 "Unable to burst-write optrom segment "
1030 "(%x/%x/%llx).\n", ret,
1031 flash_data_to_access_addr(faddr),
1032 (unsigned long long)optrom_dma);
1033 qla_printk(KERN_WARNING, ha,
1034 "Reverting to slow-write.\n");
1036 dma_free_coherent(&ha->pdev->dev,
1037 OPTROM_BURST_SIZE, optrom, optrom_dma);
1040 liter += OPTROM_BURST_DWORDS - 1;
1041 faddr += OPTROM_BURST_DWORDS - 1;
1042 dwptr += OPTROM_BURST_DWORDS - 1;
1047 ret = qla24xx_write_flash_dword(ha,
1048 flash_data_to_access_addr(faddr), cpu_to_le32(*dwptr));
1049 if (ret != QLA_SUCCESS) {
1050 DEBUG9(printk("%s(%ld) Unable to program flash "
1051 "address=%x data=%x.\n", __func__,
1052 ha->host_no, faddr, *dwptr));
1056 /* Do sector protect. */
1057 if (ha->fdt_unprotect_sec_cmd &&
1058 ((faddr & rest_addr) == rest_addr))
1059 qla24xx_write_flash_dword(ha,
1060 ha->fdt_protect_sec_cmd,
1061 (fdata & 0xff00) | ((fdata << 16) &
1062 0xff0000) | ((fdata >> 16) & 0xff));
1065 qla24xx_protect_flash(ha);
1068 dma_free_coherent(&ha->pdev->dev,
1069 OPTROM_BURST_SIZE, optrom, optrom_dma);
1075 qla2x00_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
1081 /* Word reads to NVRAM via registers. */
1082 wptr = (uint16_t *)buf;
1083 qla2x00_lock_nvram_access(ha);
1084 for (i = 0; i < bytes >> 1; i++, naddr++)
1085 wptr[i] = cpu_to_le16(qla2x00_get_nvram_word(ha,
1087 qla2x00_unlock_nvram_access(ha);
1093 qla24xx_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
1099 /* Dword reads to flash. */
1100 dwptr = (uint32_t *)buf;
1101 for (i = 0; i < bytes >> 2; i++, naddr++)
1102 dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
1103 nvram_data_to_access_addr(naddr)));
1109 qla2x00_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
1115 unsigned long flags;
1119 spin_lock_irqsave(&ha->hardware_lock, flags);
1120 qla2x00_lock_nvram_access(ha);
1122 /* Disable NVRAM write-protection. */
1123 stat = qla2x00_clear_nvram_protection(ha);
1125 wptr = (uint16_t *)buf;
1126 for (i = 0; i < bytes >> 1; i++, naddr++) {
1127 qla2x00_write_nvram_word(ha, naddr,
1128 cpu_to_le16(*wptr));
1132 /* Enable NVRAM write-protection. */
1133 qla2x00_set_nvram_protection(ha, stat);
1135 qla2x00_unlock_nvram_access(ha);
1136 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1142 qla24xx_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
1148 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1152 /* Enable flash write. */
1153 WRT_REG_DWORD(®->ctrl_status,
1154 RD_REG_DWORD(®->ctrl_status) | CSRX_FLASH_ENABLE);
1155 RD_REG_DWORD(®->ctrl_status); /* PCI Posting. */
1157 /* Disable NVRAM write-protection. */
1158 qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
1160 qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
1163 /* Dword writes to flash. */
1164 dwptr = (uint32_t *)buf;
1165 for (i = 0; i < bytes >> 2; i++, naddr++, dwptr++) {
1166 ret = qla24xx_write_flash_dword(ha,
1167 nvram_data_to_access_addr(naddr),
1168 cpu_to_le32(*dwptr));
1169 if (ret != QLA_SUCCESS) {
1170 DEBUG9(printk("%s(%ld) Unable to program "
1171 "nvram address=%x data=%x.\n", __func__,
1172 ha->host_no, naddr, *dwptr));
1177 /* Enable NVRAM write-protection. */
1178 qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
1181 /* Disable flash write. */
1182 WRT_REG_DWORD(®->ctrl_status,
1183 RD_REG_DWORD(®->ctrl_status) & ~CSRX_FLASH_ENABLE);
1184 RD_REG_DWORD(®->ctrl_status); /* PCI Posting. */
1190 qla25xx_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
1196 /* Dword reads to flash. */
1197 dwptr = (uint32_t *)buf;
1198 for (i = 0; i < bytes >> 2; i++, naddr++)
1199 dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
1200 flash_data_to_access_addr(ha->flt_region_vpd_nvram |
1207 qla25xx_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
1210 #define RMW_BUFFER_SIZE (64 * 1024)
1213 dbuf = vmalloc(RMW_BUFFER_SIZE);
1215 return QLA_MEMORY_ALLOC_FAILED;
1216 ha->isp_ops->read_optrom(ha, dbuf, ha->flt_region_vpd_nvram << 2,
1218 memcpy(dbuf + (naddr << 2), buf, bytes);
1219 ha->isp_ops->write_optrom(ha, dbuf, ha->flt_region_vpd_nvram << 2,
1227 qla2x00_flip_colors(scsi_qla_host_t *ha, uint16_t *pflags)
1229 if (IS_QLA2322(ha)) {
1230 /* Flip all colors. */
1231 if (ha->beacon_color_state == QLA_LED_ALL_ON) {
1233 ha->beacon_color_state = 0;
1234 *pflags = GPIO_LED_ALL_OFF;
1237 ha->beacon_color_state = QLA_LED_ALL_ON;
1238 *pflags = GPIO_LED_RGA_ON;
1241 /* Flip green led only. */
1242 if (ha->beacon_color_state == QLA_LED_GRN_ON) {
1244 ha->beacon_color_state = 0;
1245 *pflags = GPIO_LED_GREEN_OFF_AMBER_OFF;
1248 ha->beacon_color_state = QLA_LED_GRN_ON;
1249 *pflags = GPIO_LED_GREEN_ON_AMBER_OFF;
1254 #define PIO_REG(h, r) ((h)->pio_address + offsetof(struct device_reg_2xxx, r))
1257 qla2x00_beacon_blink(struct scsi_qla_host *ha)
1259 uint16_t gpio_enable;
1261 uint16_t led_color = 0;
1262 unsigned long flags;
1263 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1265 spin_lock_irqsave(&ha->hardware_lock, flags);
1267 /* Save the Original GPIOE. */
1268 if (ha->pio_address) {
1269 gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
1270 gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
1272 gpio_enable = RD_REG_WORD(®->gpioe);
1273 gpio_data = RD_REG_WORD(®->gpiod);
1276 /* Set the modified gpio_enable values */
1277 gpio_enable |= GPIO_LED_MASK;
1279 if (ha->pio_address) {
1280 WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
1282 WRT_REG_WORD(®->gpioe, gpio_enable);
1283 RD_REG_WORD(®->gpioe);
1286 qla2x00_flip_colors(ha, &led_color);
1288 /* Clear out any previously set LED color. */
1289 gpio_data &= ~GPIO_LED_MASK;
1291 /* Set the new input LED color to GPIOD. */
1292 gpio_data |= led_color;
1294 /* Set the modified gpio_data values */
1295 if (ha->pio_address) {
1296 WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
1298 WRT_REG_WORD(®->gpiod, gpio_data);
1299 RD_REG_WORD(®->gpiod);
1302 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1306 qla2x00_beacon_on(struct scsi_qla_host *ha)
1308 uint16_t gpio_enable;
1310 unsigned long flags;
1311 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1313 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1314 ha->fw_options[1] |= FO1_DISABLE_GPIO6_7;
1316 if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
1317 qla_printk(KERN_WARNING, ha,
1318 "Unable to update fw options (beacon on).\n");
1319 return QLA_FUNCTION_FAILED;
1322 /* Turn off LEDs. */
1323 spin_lock_irqsave(&ha->hardware_lock, flags);
1324 if (ha->pio_address) {
1325 gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
1326 gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
1328 gpio_enable = RD_REG_WORD(®->gpioe);
1329 gpio_data = RD_REG_WORD(®->gpiod);
1331 gpio_enable |= GPIO_LED_MASK;
1333 /* Set the modified gpio_enable values. */
1334 if (ha->pio_address) {
1335 WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
1337 WRT_REG_WORD(®->gpioe, gpio_enable);
1338 RD_REG_WORD(®->gpioe);
1341 /* Clear out previously set LED colour. */
1342 gpio_data &= ~GPIO_LED_MASK;
1343 if (ha->pio_address) {
1344 WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
1346 WRT_REG_WORD(®->gpiod, gpio_data);
1347 RD_REG_WORD(®->gpiod);
1349 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1352 * Let the per HBA timer kick off the blinking process based on
1353 * the following flags. No need to do anything else now.
1355 ha->beacon_blink_led = 1;
1356 ha->beacon_color_state = 0;
1362 qla2x00_beacon_off(struct scsi_qla_host *ha)
1364 int rval = QLA_SUCCESS;
1366 ha->beacon_blink_led = 0;
1368 /* Set the on flag so when it gets flipped it will be off. */
1370 ha->beacon_color_state = QLA_LED_ALL_ON;
1372 ha->beacon_color_state = QLA_LED_GRN_ON;
1374 ha->isp_ops->beacon_blink(ha); /* This turns green LED off */
1376 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1377 ha->fw_options[1] &= ~FO1_DISABLE_GPIO6_7;
1379 rval = qla2x00_set_fw_options(ha, ha->fw_options);
1380 if (rval != QLA_SUCCESS)
1381 qla_printk(KERN_WARNING, ha,
1382 "Unable to update fw options (beacon off).\n");
1388 qla24xx_flip_colors(scsi_qla_host_t *ha, uint16_t *pflags)
1390 /* Flip all colors. */
1391 if (ha->beacon_color_state == QLA_LED_ALL_ON) {
1393 ha->beacon_color_state = 0;
1397 ha->beacon_color_state = QLA_LED_ALL_ON;
1398 *pflags = GPDX_LED_YELLOW_ON | GPDX_LED_AMBER_ON;
1403 qla24xx_beacon_blink(struct scsi_qla_host *ha)
1405 uint16_t led_color = 0;
1407 unsigned long flags;
1408 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1410 /* Save the Original GPIOD. */
1411 spin_lock_irqsave(&ha->hardware_lock, flags);
1412 gpio_data = RD_REG_DWORD(®->gpiod);
1414 /* Enable the gpio_data reg for update. */
1415 gpio_data |= GPDX_LED_UPDATE_MASK;
1417 WRT_REG_DWORD(®->gpiod, gpio_data);
1418 gpio_data = RD_REG_DWORD(®->gpiod);
1420 /* Set the color bits. */
1421 qla24xx_flip_colors(ha, &led_color);
1423 /* Clear out any previously set LED color. */
1424 gpio_data &= ~GPDX_LED_COLOR_MASK;
1426 /* Set the new input LED color to GPIOD. */
1427 gpio_data |= led_color;
1429 /* Set the modified gpio_data values. */
1430 WRT_REG_DWORD(®->gpiod, gpio_data);
1431 gpio_data = RD_REG_DWORD(®->gpiod);
1432 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1436 qla24xx_beacon_on(struct scsi_qla_host *ha)
1439 unsigned long flags;
1440 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1442 if (ha->beacon_blink_led == 0) {
1443 /* Enable firmware for update */
1444 ha->fw_options[1] |= ADD_FO1_DISABLE_GPIO_LED_CTRL;
1446 if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS)
1447 return QLA_FUNCTION_FAILED;
1449 if (qla2x00_get_fw_options(ha, ha->fw_options) !=
1451 qla_printk(KERN_WARNING, ha,
1452 "Unable to update fw options (beacon on).\n");
1453 return QLA_FUNCTION_FAILED;
1456 spin_lock_irqsave(&ha->hardware_lock, flags);
1457 gpio_data = RD_REG_DWORD(®->gpiod);
1459 /* Enable the gpio_data reg for update. */
1460 gpio_data |= GPDX_LED_UPDATE_MASK;
1461 WRT_REG_DWORD(®->gpiod, gpio_data);
1462 RD_REG_DWORD(®->gpiod);
1464 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1467 /* So all colors blink together. */
1468 ha->beacon_color_state = 0;
1470 /* Let the per HBA timer kick off the blinking process. */
1471 ha->beacon_blink_led = 1;
1477 qla24xx_beacon_off(struct scsi_qla_host *ha)
1480 unsigned long flags;
1481 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1483 ha->beacon_blink_led = 0;
1484 ha->beacon_color_state = QLA_LED_ALL_ON;
1486 ha->isp_ops->beacon_blink(ha); /* Will flip to all off. */
1488 /* Give control back to firmware. */
1489 spin_lock_irqsave(&ha->hardware_lock, flags);
1490 gpio_data = RD_REG_DWORD(®->gpiod);
1492 /* Disable the gpio_data reg for update. */
1493 gpio_data &= ~GPDX_LED_UPDATE_MASK;
1494 WRT_REG_DWORD(®->gpiod, gpio_data);
1495 RD_REG_DWORD(®->gpiod);
1496 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1498 ha->fw_options[1] &= ~ADD_FO1_DISABLE_GPIO_LED_CTRL;
1500 if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
1501 qla_printk(KERN_WARNING, ha,
1502 "Unable to update fw options (beacon off).\n");
1503 return QLA_FUNCTION_FAILED;
1506 if (qla2x00_get_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
1507 qla_printk(KERN_WARNING, ha,
1508 "Unable to get fw options (beacon off).\n");
1509 return QLA_FUNCTION_FAILED;
1517 * Flash support routines
1521 * qla2x00_flash_enable() - Setup flash for reading and writing.
1525 qla2x00_flash_enable(scsi_qla_host_t *ha)
1528 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1530 data = RD_REG_WORD(®->ctrl_status);
1531 data |= CSR_FLASH_ENABLE;
1532 WRT_REG_WORD(®->ctrl_status, data);
1533 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1537 * qla2x00_flash_disable() - Disable flash and allow RISC to run.
1541 qla2x00_flash_disable(scsi_qla_host_t *ha)
1544 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1546 data = RD_REG_WORD(®->ctrl_status);
1547 data &= ~(CSR_FLASH_ENABLE);
1548 WRT_REG_WORD(®->ctrl_status, data);
1549 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1553 * qla2x00_read_flash_byte() - Reads a byte from flash
1555 * @addr: Address in flash to read
1557 * A word is read from the chip, but, only the lower byte is valid.
1559 * Returns the byte read from flash @addr.
1562 qla2x00_read_flash_byte(scsi_qla_host_t *ha, uint32_t addr)
1565 uint16_t bank_select;
1566 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1568 bank_select = RD_REG_WORD(®->ctrl_status);
1570 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
1571 /* Specify 64K address range: */
1572 /* clear out Module Select and Flash Address bits [19:16]. */
1573 bank_select &= ~0xf8;
1574 bank_select |= addr >> 12 & 0xf0;
1575 bank_select |= CSR_FLASH_64K_BANK;
1576 WRT_REG_WORD(®->ctrl_status, bank_select);
1577 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1579 WRT_REG_WORD(®->flash_address, (uint16_t)addr);
1580 data = RD_REG_WORD(®->flash_data);
1582 return (uint8_t)data;
1585 /* Setup bit 16 of flash address. */
1586 if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
1587 bank_select |= CSR_FLASH_64K_BANK;
1588 WRT_REG_WORD(®->ctrl_status, bank_select);
1589 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1590 } else if (((addr & BIT_16) == 0) &&
1591 (bank_select & CSR_FLASH_64K_BANK)) {
1592 bank_select &= ~(CSR_FLASH_64K_BANK);
1593 WRT_REG_WORD(®->ctrl_status, bank_select);
1594 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1597 /* Always perform IO mapped accesses to the FLASH registers. */
1598 if (ha->pio_address) {
1601 WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
1603 data = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
1606 data2 = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
1607 } while (data != data2);
1609 WRT_REG_WORD(®->flash_address, (uint16_t)addr);
1610 data = qla2x00_debounce_register(®->flash_data);
1613 return (uint8_t)data;
1617 * qla2x00_write_flash_byte() - Write a byte to flash
1619 * @addr: Address in flash to write
1620 * @data: Data to write
1623 qla2x00_write_flash_byte(scsi_qla_host_t *ha, uint32_t addr, uint8_t data)
1625 uint16_t bank_select;
1626 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1628 bank_select = RD_REG_WORD(®->ctrl_status);
1629 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
1630 /* Specify 64K address range: */
1631 /* clear out Module Select and Flash Address bits [19:16]. */
1632 bank_select &= ~0xf8;
1633 bank_select |= addr >> 12 & 0xf0;
1634 bank_select |= CSR_FLASH_64K_BANK;
1635 WRT_REG_WORD(®->ctrl_status, bank_select);
1636 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1638 WRT_REG_WORD(®->flash_address, (uint16_t)addr);
1639 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1640 WRT_REG_WORD(®->flash_data, (uint16_t)data);
1641 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1646 /* Setup bit 16 of flash address. */
1647 if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
1648 bank_select |= CSR_FLASH_64K_BANK;
1649 WRT_REG_WORD(®->ctrl_status, bank_select);
1650 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1651 } else if (((addr & BIT_16) == 0) &&
1652 (bank_select & CSR_FLASH_64K_BANK)) {
1653 bank_select &= ~(CSR_FLASH_64K_BANK);
1654 WRT_REG_WORD(®->ctrl_status, bank_select);
1655 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1658 /* Always perform IO mapped accesses to the FLASH registers. */
1659 if (ha->pio_address) {
1660 WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
1661 WRT_REG_WORD_PIO(PIO_REG(ha, flash_data), (uint16_t)data);
1663 WRT_REG_WORD(®->flash_address, (uint16_t)addr);
1664 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1665 WRT_REG_WORD(®->flash_data, (uint16_t)data);
1666 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1671 * qla2x00_poll_flash() - Polls flash for completion.
1673 * @addr: Address in flash to poll
1674 * @poll_data: Data to be polled
1675 * @man_id: Flash manufacturer ID
1676 * @flash_id: Flash ID
1678 * This function polls the device until bit 7 of what is read matches data
1679 * bit 7 or until data bit 5 becomes a 1. If that hapens, the flash ROM timed
1680 * out (a fatal error). The flash book recommeds reading bit 7 again after
1681 * reading bit 5 as a 1.
1683 * Returns 0 on success, else non-zero.
1686 qla2x00_poll_flash(scsi_qla_host_t *ha, uint32_t addr, uint8_t poll_data,
1687 uint8_t man_id, uint8_t flash_id)
1695 /* Wait for 30 seconds for command to finish. */
1697 for (cnt = 3000000; cnt; cnt--) {
1698 flash_data = qla2x00_read_flash_byte(ha, addr);
1699 if ((flash_data & BIT_7) == poll_data) {
1704 if (man_id != 0x40 && man_id != 0xda) {
1705 if ((flash_data & BIT_5) && cnt > 2)
1716 * qla2x00_program_flash_address() - Programs a flash address
1718 * @addr: Address in flash to program
1719 * @data: Data to be written in flash
1720 * @man_id: Flash manufacturer ID
1721 * @flash_id: Flash ID
1723 * Returns 0 on success, else non-zero.
1726 qla2x00_program_flash_address(scsi_qla_host_t *ha, uint32_t addr, uint8_t data,
1727 uint8_t man_id, uint8_t flash_id)
1729 /* Write Program Command Sequence. */
1730 if (IS_OEM_001(ha)) {
1731 qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
1732 qla2x00_write_flash_byte(ha, 0x555, 0x55);
1733 qla2x00_write_flash_byte(ha, 0xaaa, 0xa0);
1734 qla2x00_write_flash_byte(ha, addr, data);
1736 if (man_id == 0xda && flash_id == 0xc1) {
1737 qla2x00_write_flash_byte(ha, addr, data);
1741 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1742 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1743 qla2x00_write_flash_byte(ha, 0x5555, 0xa0);
1744 qla2x00_write_flash_byte(ha, addr, data);
1750 /* Wait for write to complete. */
1751 return qla2x00_poll_flash(ha, addr, data, man_id, flash_id);
1755 * qla2x00_erase_flash() - Erase the flash.
1757 * @man_id: Flash manufacturer ID
1758 * @flash_id: Flash ID
1760 * Returns 0 on success, else non-zero.
1763 qla2x00_erase_flash(scsi_qla_host_t *ha, uint8_t man_id, uint8_t flash_id)
1765 /* Individual Sector Erase Command Sequence */
1766 if (IS_OEM_001(ha)) {
1767 qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
1768 qla2x00_write_flash_byte(ha, 0x555, 0x55);
1769 qla2x00_write_flash_byte(ha, 0xaaa, 0x80);
1770 qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
1771 qla2x00_write_flash_byte(ha, 0x555, 0x55);
1772 qla2x00_write_flash_byte(ha, 0xaaa, 0x10);
1774 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1775 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1776 qla2x00_write_flash_byte(ha, 0x5555, 0x80);
1777 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1778 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1779 qla2x00_write_flash_byte(ha, 0x5555, 0x10);
1784 /* Wait for erase to complete. */
1785 return qla2x00_poll_flash(ha, 0x00, 0x80, man_id, flash_id);
1789 * qla2x00_erase_flash_sector() - Erase a flash sector.
1791 * @addr: Flash sector to erase
1792 * @sec_mask: Sector address mask
1793 * @man_id: Flash manufacturer ID
1794 * @flash_id: Flash ID
1796 * Returns 0 on success, else non-zero.
1799 qla2x00_erase_flash_sector(scsi_qla_host_t *ha, uint32_t addr,
1800 uint32_t sec_mask, uint8_t man_id, uint8_t flash_id)
1802 /* Individual Sector Erase Command Sequence */
1803 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1804 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1805 qla2x00_write_flash_byte(ha, 0x5555, 0x80);
1806 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1807 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1808 if (man_id == 0x1f && flash_id == 0x13)
1809 qla2x00_write_flash_byte(ha, addr & sec_mask, 0x10);
1811 qla2x00_write_flash_byte(ha, addr & sec_mask, 0x30);
1815 /* Wait for erase to complete. */
1816 return qla2x00_poll_flash(ha, addr, 0x80, man_id, flash_id);
1820 * qla2x00_get_flash_manufacturer() - Read manufacturer ID from flash chip.
1821 * @man_id: Flash manufacturer ID
1822 * @flash_id: Flash ID
1825 qla2x00_get_flash_manufacturer(scsi_qla_host_t *ha, uint8_t *man_id,
1828 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1829 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1830 qla2x00_write_flash_byte(ha, 0x5555, 0x90);
1831 *man_id = qla2x00_read_flash_byte(ha, 0x0000);
1832 *flash_id = qla2x00_read_flash_byte(ha, 0x0001);
1833 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1834 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1835 qla2x00_write_flash_byte(ha, 0x5555, 0xf0);
1839 qla2x00_read_flash_data(scsi_qla_host_t *ha, uint8_t *tmp_buf, uint32_t saddr,
1842 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1843 uint32_t midpoint, ilength;
1846 midpoint = length / 2;
1848 WRT_REG_WORD(®->nvram, 0);
1849 RD_REG_WORD(®->nvram);
1850 for (ilength = 0; ilength < length; saddr++, ilength++, tmp_buf++) {
1851 if (ilength == midpoint) {
1852 WRT_REG_WORD(®->nvram, NVR_SELECT);
1853 RD_REG_WORD(®->nvram);
1855 data = qla2x00_read_flash_byte(ha, saddr);
1864 qla2x00_suspend_hba(struct scsi_qla_host *ha)
1867 unsigned long flags;
1868 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1871 scsi_block_requests(ha->host);
1872 ha->isp_ops->disable_intrs(ha);
1873 set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
1876 spin_lock_irqsave(&ha->hardware_lock, flags);
1877 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
1878 RD_REG_WORD(®->hccr);
1879 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1880 for (cnt = 0; cnt < 30000; cnt++) {
1881 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
1888 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1892 qla2x00_resume_hba(struct scsi_qla_host *ha)
1895 clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
1896 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1897 qla2xxx_wake_dpc(ha);
1898 qla2x00_wait_for_hba_online(ha);
1899 scsi_unblock_requests(ha->host);
1903 qla2x00_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
1904 uint32_t offset, uint32_t length)
1906 uint32_t addr, midpoint;
1908 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1911 qla2x00_suspend_hba(ha);
1914 midpoint = ha->optrom_size / 2;
1916 qla2x00_flash_enable(ha);
1917 WRT_REG_WORD(®->nvram, 0);
1918 RD_REG_WORD(®->nvram); /* PCI Posting. */
1919 for (addr = offset, data = buf; addr < length; addr++, data++) {
1920 if (addr == midpoint) {
1921 WRT_REG_WORD(®->nvram, NVR_SELECT);
1922 RD_REG_WORD(®->nvram); /* PCI Posting. */
1925 *data = qla2x00_read_flash_byte(ha, addr);
1927 qla2x00_flash_disable(ha);
1930 qla2x00_resume_hba(ha);
1936 qla2x00_write_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
1937 uint32_t offset, uint32_t length)
1941 uint8_t man_id, flash_id, sec_number, data;
1943 uint32_t addr, liter, sec_mask, rest_addr;
1944 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1947 qla2x00_suspend_hba(ha);
1952 /* Reset ISP chip. */
1953 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
1954 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
1956 /* Go with write. */
1957 qla2x00_flash_enable(ha);
1958 do { /* Loop once to provide quick error exit */
1959 /* Structure of flash memory based on manufacturer */
1960 if (IS_OEM_001(ha)) {
1961 /* OEM variant with special flash part. */
1962 man_id = flash_id = 0;
1967 qla2x00_get_flash_manufacturer(ha, &man_id, &flash_id);
1969 case 0x20: /* ST flash. */
1970 if (flash_id == 0xd2 || flash_id == 0xe3) {
1972 * ST m29w008at part - 64kb sector size with
1973 * 32kb,8kb,8kb,16kb sectors at memory address
1981 * ST m29w010b part - 16kb sector size
1982 * Default to 16kb sectors
1987 case 0x40: /* Mostel flash. */
1988 /* Mostel v29c51001 part - 512 byte sector size. */
1992 case 0xbf: /* SST flash. */
1993 /* SST39sf10 part - 4kb sector size. */
1997 case 0xda: /* Winbond flash. */
1998 /* Winbond W29EE011 part - 256 byte sector size. */
2002 case 0xc2: /* Macronix flash. */
2003 /* 64k sector size. */
2004 if (flash_id == 0x38 || flash_id == 0x4f) {
2009 /* Fall through... */
2011 case 0x1f: /* Atmel flash. */
2012 /* 512k sector size. */
2013 if (flash_id == 0x13) {
2014 rest_addr = 0x7fffffff;
2015 sec_mask = 0x80000000;
2018 /* Fall through... */
2020 case 0x01: /* AMD flash. */
2021 if (flash_id == 0x38 || flash_id == 0x40 ||
2023 /* Am29LV081 part - 64kb sector size. */
2024 /* Am29LV002BT part - 64kb sector size. */
2028 } else if (flash_id == 0x3e) {
2030 * Am29LV008b part - 64kb sector size with
2031 * 32kb,8kb,8kb,16kb sector at memory address
2037 } else if (flash_id == 0x20 || flash_id == 0x6e) {
2039 * Am29LV010 part or AM29f010 - 16kb sector
2045 } else if (flash_id == 0x6d) {
2046 /* Am29LV001 part - 8kb sector size. */
2052 /* Default to 16 kb sector size. */
2059 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
2060 if (qla2x00_erase_flash(ha, man_id, flash_id)) {
2061 rval = QLA_FUNCTION_FAILED;
2066 for (addr = offset, liter = 0; liter < length; liter++,
2069 /* Are we at the beginning of a sector? */
2070 if ((addr & rest_addr) == 0) {
2071 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
2072 if (addr >= 0x10000UL) {
2073 if (((addr >> 12) & 0xf0) &&
2075 flash_id == 0x3e) ||
2077 flash_id == 0xd2))) {
2079 if (sec_number == 1) {
2100 } else if (addr == ha->optrom_size / 2) {
2101 WRT_REG_WORD(®->nvram, NVR_SELECT);
2102 RD_REG_WORD(®->nvram);
2105 if (flash_id == 0xda && man_id == 0xc1) {
2106 qla2x00_write_flash_byte(ha, 0x5555,
2108 qla2x00_write_flash_byte(ha, 0x2aaa,
2110 qla2x00_write_flash_byte(ha, 0x5555,
2112 } else if (!IS_QLA2322(ha) && !IS_QLA6322(ha)) {
2114 if (qla2x00_erase_flash_sector(ha,
2115 addr, sec_mask, man_id,
2117 rval = QLA_FUNCTION_FAILED;
2120 if (man_id == 0x01 && flash_id == 0x6d)
2125 if (man_id == 0x01 && flash_id == 0x6d) {
2126 if (sec_number == 1 &&
2127 addr == (rest_addr - 1)) {
2130 } else if (sec_number == 3 && (addr & 0x7ffe)) {
2136 if (qla2x00_program_flash_address(ha, addr, data,
2137 man_id, flash_id)) {
2138 rval = QLA_FUNCTION_FAILED;
2144 qla2x00_flash_disable(ha);
2147 qla2x00_resume_hba(ha);
2153 qla24xx_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
2154 uint32_t offset, uint32_t length)
2157 scsi_block_requests(ha->host);
2158 set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
2161 qla24xx_read_flash_data(ha, (uint32_t *)buf, offset >> 2, length >> 2);
2164 clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
2165 scsi_unblock_requests(ha->host);
2171 qla24xx_write_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
2172 uint32_t offset, uint32_t length)
2177 scsi_block_requests(ha->host);
2178 set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
2180 /* Go with write. */
2181 rval = qla24xx_write_flash_data(ha, (uint32_t *)buf, offset >> 2,
2184 /* Resume HBA -- RISC reset needed. */
2185 clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
2186 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2187 qla2xxx_wake_dpc(ha);
2188 qla2x00_wait_for_hba_online(ha);
2189 scsi_unblock_requests(ha->host);
2195 qla25xx_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
2196 uint32_t offset, uint32_t length)
2199 dma_addr_t optrom_dma;
2202 uint32_t faddr, left, burst;
2206 if (length < OPTROM_BURST_SIZE)
2209 optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
2210 &optrom_dma, GFP_KERNEL);
2212 qla_printk(KERN_DEBUG, ha,
2213 "Unable to allocate memory for optrom burst read "
2214 "(%x KB).\n", OPTROM_BURST_SIZE / 1024);
2220 faddr = offset >> 2;
2222 burst = OPTROM_BURST_DWORDS;
2227 rval = qla2x00_dump_ram(ha, optrom_dma,
2228 flash_data_to_access_addr(faddr), burst);
2230 qla_printk(KERN_WARNING, ha,
2231 "Unable to burst-read optrom segment "
2232 "(%x/%x/%llx).\n", rval,
2233 flash_data_to_access_addr(faddr),
2234 (unsigned long long)optrom_dma);
2235 qla_printk(KERN_WARNING, ha,
2236 "Reverting to slow-read.\n");
2238 dma_free_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
2239 optrom, optrom_dma);
2243 memcpy(pbuf, optrom, burst * 4);
2250 dma_free_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE, optrom,
2256 return qla24xx_read_optrom_data(ha, buf, offset, length);
2260 * qla2x00_get_fcode_version() - Determine an FCODE image's version.
2262 * @pcids: Pointer to the FCODE PCI data structure
2264 * The process of retrieving the FCODE version information is at best
2265 * described as interesting.
2267 * Within the first 100h bytes of the image an ASCII string is present
2268 * which contains several pieces of information including the FCODE
2269 * version. Unfortunately it seems the only reliable way to retrieve
2270 * the version is by scanning for another sentinel within the string,
2271 * the FCODE build date:
2273 * ... 2.00.02 10/17/02 ...
2275 * Returns QLA_SUCCESS on successful retrieval of version.
2278 qla2x00_get_fcode_version(scsi_qla_host_t *ha, uint32_t pcids)
2280 int ret = QLA_FUNCTION_FAILED;
2281 uint32_t istart, iend, iter, vend;
2282 uint8_t do_next, rbyte, *vbyte;
2284 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
2286 /* Skip the PCI data structure. */
2288 ((qla2x00_read_flash_byte(ha, pcids + 0x0B) << 8) |
2289 qla2x00_read_flash_byte(ha, pcids + 0x0A));
2290 iend = istart + 0x100;
2292 /* Scan for the sentinel date string...eeewww. */
2295 while ((iter < iend) && !do_next) {
2297 if (qla2x00_read_flash_byte(ha, iter) == '/') {
2298 if (qla2x00_read_flash_byte(ha, iter + 2) ==
2301 else if (qla2x00_read_flash_byte(ha,
2309 /* Backtrack to previous ' ' (space). */
2311 while ((iter > istart) && !do_next) {
2313 if (qla2x00_read_flash_byte(ha, iter) == ' ')
2320 * Mark end of version tag, and find previous ' ' (space) or
2321 * string length (recent FCODE images -- major hack ahead!!!).
2325 while ((iter > istart) && !do_next) {
2327 rbyte = qla2x00_read_flash_byte(ha, iter);
2328 if (rbyte == ' ' || rbyte == 0xd || rbyte == 0x10)
2334 /* Mark beginning of version tag, and copy data. */
2336 if ((vend - iter) &&
2337 ((vend - iter) < sizeof(ha->fcode_revision))) {
2338 vbyte = ha->fcode_revision;
2339 while (iter <= vend) {
2340 *vbyte++ = qla2x00_read_flash_byte(ha, iter);
2347 if (ret != QLA_SUCCESS)
2348 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
2352 qla2x00_get_flash_version(scsi_qla_host_t *ha, void *mbuf)
2354 int ret = QLA_SUCCESS;
2355 uint8_t code_type, last_image;
2356 uint32_t pcihdr, pcids;
2360 if (!ha->pio_address || !mbuf)
2361 return QLA_FUNCTION_FAILED;
2363 memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
2364 memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
2365 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
2366 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
2368 qla2x00_flash_enable(ha);
2370 /* Begin with first PCI expansion ROM header. */
2374 /* Verify PCI expansion ROM header. */
2375 if (qla2x00_read_flash_byte(ha, pcihdr) != 0x55 ||
2376 qla2x00_read_flash_byte(ha, pcihdr + 0x01) != 0xaa) {
2378 DEBUG2(printk("scsi(%ld): No matching ROM "
2379 "signature.\n", ha->host_no));
2380 ret = QLA_FUNCTION_FAILED;
2384 /* Locate PCI data structure. */
2386 ((qla2x00_read_flash_byte(ha, pcihdr + 0x19) << 8) |
2387 qla2x00_read_flash_byte(ha, pcihdr + 0x18));
2389 /* Validate signature of PCI data structure. */
2390 if (qla2x00_read_flash_byte(ha, pcids) != 'P' ||
2391 qla2x00_read_flash_byte(ha, pcids + 0x1) != 'C' ||
2392 qla2x00_read_flash_byte(ha, pcids + 0x2) != 'I' ||
2393 qla2x00_read_flash_byte(ha, pcids + 0x3) != 'R') {
2394 /* Incorrect header. */
2395 DEBUG2(printk("%s(): PCI data struct not found "
2396 "pcir_adr=%x.\n", __func__, pcids));
2397 ret = QLA_FUNCTION_FAILED;
2402 code_type = qla2x00_read_flash_byte(ha, pcids + 0x14);
2403 switch (code_type) {
2404 case ROM_CODE_TYPE_BIOS:
2405 /* Intel x86, PC-AT compatible. */
2406 ha->bios_revision[0] =
2407 qla2x00_read_flash_byte(ha, pcids + 0x12);
2408 ha->bios_revision[1] =
2409 qla2x00_read_flash_byte(ha, pcids + 0x13);
2410 DEBUG3(printk("%s(): read BIOS %d.%d.\n", __func__,
2411 ha->bios_revision[1], ha->bios_revision[0]));
2413 case ROM_CODE_TYPE_FCODE:
2414 /* Open Firmware standard for PCI (FCode). */
2416 qla2x00_get_fcode_version(ha, pcids);
2418 case ROM_CODE_TYPE_EFI:
2419 /* Extensible Firmware Interface (EFI). */
2420 ha->efi_revision[0] =
2421 qla2x00_read_flash_byte(ha, pcids + 0x12);
2422 ha->efi_revision[1] =
2423 qla2x00_read_flash_byte(ha, pcids + 0x13);
2424 DEBUG3(printk("%s(): read EFI %d.%d.\n", __func__,
2425 ha->efi_revision[1], ha->efi_revision[0]));
2428 DEBUG2(printk("%s(): Unrecognized code type %x at "
2429 "pcids %x.\n", __func__, code_type, pcids));
2433 last_image = qla2x00_read_flash_byte(ha, pcids + 0x15) & BIT_7;
2435 /* Locate next PCI expansion ROM. */
2436 pcihdr += ((qla2x00_read_flash_byte(ha, pcids + 0x11) << 8) |
2437 qla2x00_read_flash_byte(ha, pcids + 0x10)) * 512;
2438 } while (!last_image);
2440 if (IS_QLA2322(ha)) {
2441 /* Read firmware image information. */
2442 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
2444 memset(dbyte, 0, 8);
2445 dcode = (uint16_t *)dbyte;
2447 qla2x00_read_flash_data(ha, dbyte, ha->flt_region_fw * 4 + 10,
2449 DEBUG3(printk("%s(%ld): dumping fw ver from flash:\n",
2450 __func__, ha->host_no));
2451 DEBUG3(qla2x00_dump_buffer((uint8_t *)dbyte, 8));
2453 if ((dcode[0] == 0xffff && dcode[1] == 0xffff &&
2454 dcode[2] == 0xffff && dcode[3] == 0xffff) ||
2455 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
2457 DEBUG2(printk("%s(): Unrecognized fw revision at "
2458 "%x.\n", __func__, ha->flt_region_fw * 4));
2460 /* values are in big endian */
2461 ha->fw_revision[0] = dbyte[0] << 16 | dbyte[1];
2462 ha->fw_revision[1] = dbyte[2] << 16 | dbyte[3];
2463 ha->fw_revision[2] = dbyte[4] << 16 | dbyte[5];
2467 qla2x00_flash_disable(ha);
2473 qla24xx_get_flash_version(scsi_qla_host_t *ha, void *mbuf)
2475 int ret = QLA_SUCCESS;
2476 uint32_t pcihdr, pcids;
2479 uint8_t code_type, last_image;
2483 return QLA_FUNCTION_FAILED;
2485 memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
2486 memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
2487 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
2488 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
2492 /* Begin with first PCI expansion ROM header. */
2493 pcihdr = ha->flt_region_boot;
2496 /* Verify PCI expansion ROM header. */
2497 qla24xx_read_flash_data(ha, dcode, pcihdr >> 2, 0x20);
2498 bcode = mbuf + (pcihdr % 4);
2499 if (bcode[0x0] != 0x55 || bcode[0x1] != 0xaa) {
2501 DEBUG2(printk("scsi(%ld): No matching ROM "
2502 "signature.\n", ha->host_no));
2503 ret = QLA_FUNCTION_FAILED;
2507 /* Locate PCI data structure. */
2508 pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]);
2510 qla24xx_read_flash_data(ha, dcode, pcids >> 2, 0x20);
2511 bcode = mbuf + (pcihdr % 4);
2513 /* Validate signature of PCI data structure. */
2514 if (bcode[0x0] != 'P' || bcode[0x1] != 'C' ||
2515 bcode[0x2] != 'I' || bcode[0x3] != 'R') {
2516 /* Incorrect header. */
2517 DEBUG2(printk("%s(): PCI data struct not found "
2518 "pcir_adr=%x.\n", __func__, pcids));
2519 ret = QLA_FUNCTION_FAILED;
2524 code_type = bcode[0x14];
2525 switch (code_type) {
2526 case ROM_CODE_TYPE_BIOS:
2527 /* Intel x86, PC-AT compatible. */
2528 ha->bios_revision[0] = bcode[0x12];
2529 ha->bios_revision[1] = bcode[0x13];
2530 DEBUG3(printk("%s(): read BIOS %d.%d.\n", __func__,
2531 ha->bios_revision[1], ha->bios_revision[0]));
2533 case ROM_CODE_TYPE_FCODE:
2534 /* Open Firmware standard for PCI (FCode). */
2535 ha->fcode_revision[0] = bcode[0x12];
2536 ha->fcode_revision[1] = bcode[0x13];
2537 DEBUG3(printk("%s(): read FCODE %d.%d.\n", __func__,
2538 ha->fcode_revision[1], ha->fcode_revision[0]));
2540 case ROM_CODE_TYPE_EFI:
2541 /* Extensible Firmware Interface (EFI). */
2542 ha->efi_revision[0] = bcode[0x12];
2543 ha->efi_revision[1] = bcode[0x13];
2544 DEBUG3(printk("%s(): read EFI %d.%d.\n", __func__,
2545 ha->efi_revision[1], ha->efi_revision[0]));
2548 DEBUG2(printk("%s(): Unrecognized code type %x at "
2549 "pcids %x.\n", __func__, code_type, pcids));
2553 last_image = bcode[0x15] & BIT_7;
2555 /* Locate next PCI expansion ROM. */
2556 pcihdr += ((bcode[0x11] << 8) | bcode[0x10]) * 512;
2557 } while (!last_image);
2559 /* Read firmware image information. */
2560 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
2563 qla24xx_read_flash_data(ha, dcode, ha->flt_region_fw + 4, 4);
2564 for (i = 0; i < 4; i++)
2565 dcode[i] = be32_to_cpu(dcode[i]);
2567 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
2568 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
2569 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
2571 DEBUG2(printk("%s(): Unrecognized fw version at %x.\n",
2572 __func__, ha->flt_region_fw));
2574 ha->fw_revision[0] = dcode[0];
2575 ha->fw_revision[1] = dcode[1];
2576 ha->fw_revision[2] = dcode[2];
2577 ha->fw_revision[3] = dcode[3];
2584 qla2xxx_is_vpd_valid(uint8_t *pos, uint8_t *end)
2586 if (pos >= end || *pos != 0x82)
2590 if (pos >= end || *pos != 0x90)
2594 if (pos >= end || *pos != 0x78)
2601 qla2xxx_get_vpd_field(scsi_qla_host_t *ha, char *key, char *str, size_t size)
2603 uint8_t *pos = ha->vpd;
2604 uint8_t *end = pos + ha->vpd_size;
2607 if (!IS_FWI2_CAPABLE(ha) || !qla2xxx_is_vpd_valid(pos, end))
2610 while (pos < end && *pos != 0x78) {
2611 len = (*pos == 0x82) ? pos[1] : pos[2];
2613 if (!strncmp(pos, key, strlen(key)))
2616 if (*pos != 0x90 && *pos != 0x91)
2622 if (pos < end - len && *pos != 0x78)
2623 return snprintf(str, size, "%.*s", len, pos + 3);
2629 qla2xxx_hw_event_store(scsi_qla_host_t *ha, uint32_t *fdata)
2631 uint32_t d[2], faddr;
2633 /* Locate first empty entry. */
2635 if (ha->hw_event_ptr >=
2636 ha->flt_region_hw_event + FA_HW_EVENT_SIZE) {
2637 DEBUG2(qla_printk(KERN_WARNING, ha,
2638 "HW event -- Log Full!\n"));
2639 return QLA_MEMORY_ALLOC_FAILED;
2642 qla24xx_read_flash_data(ha, d, ha->hw_event_ptr, 2);
2643 faddr = flash_data_to_access_addr(ha->hw_event_ptr);
2644 ha->hw_event_ptr += FA_HW_EVENT_ENTRY_SIZE;
2645 if (d[0] == __constant_cpu_to_le32(0xffffffff) &&
2646 d[1] == __constant_cpu_to_le32(0xffffffff)) {
2647 qla24xx_unprotect_flash(ha);
2649 qla24xx_write_flash_dword(ha, faddr++,
2650 cpu_to_le32(jiffies));
2651 qla24xx_write_flash_dword(ha, faddr++, 0);
2652 qla24xx_write_flash_dword(ha, faddr++, *fdata++);
2653 qla24xx_write_flash_dword(ha, faddr++, *fdata);
2655 qla24xx_protect_flash(ha);
2663 qla2xxx_hw_event_log(scsi_qla_host_t *ha, uint16_t code, uint16_t d1,
2664 uint16_t d2, uint16_t d3)
2666 #define QMARK(a, b, c, d) \
2667 cpu_to_le32(LSB(a) << 24 | LSB(b) << 16 | LSB(c) << 8 | LSB(d))
2670 uint32_t marker[2], fdata[4];
2672 if (ha->flt_region_hw_event == 0)
2673 return QLA_FUNCTION_FAILED;
2675 DEBUG2(qla_printk(KERN_WARNING, ha,
2676 "HW event -- code=%x, d1=%x, d2=%x, d3=%x.\n", code, d1, d2, d3));
2678 /* If marker not already found, locate or write. */
2679 if (!ha->flags.hw_event_marker_found) {
2680 /* Create marker. */
2681 marker[0] = QMARK('L', ha->fw_major_version,
2682 ha->fw_minor_version, ha->fw_subminor_version);
2683 marker[1] = QMARK(QLA_DRIVER_MAJOR_VER, QLA_DRIVER_MINOR_VER,
2684 QLA_DRIVER_PATCH_VER, QLA_DRIVER_BETA_VER);
2686 /* Locate marker. */
2687 ha->hw_event_ptr = ha->flt_region_hw_event;
2689 qla24xx_read_flash_data(ha, fdata, ha->hw_event_ptr,
2691 if (fdata[0] == __constant_cpu_to_le32(0xffffffff) &&
2692 fdata[1] == __constant_cpu_to_le32(0xffffffff))
2694 ha->hw_event_ptr += FA_HW_EVENT_ENTRY_SIZE;
2695 if (ha->hw_event_ptr >=
2696 ha->flt_region_hw_event + FA_HW_EVENT_SIZE) {
2697 DEBUG2(qla_printk(KERN_WARNING, ha,
2698 "HW event -- Log Full!\n"));
2699 return QLA_MEMORY_ALLOC_FAILED;
2701 if (fdata[2] == marker[0] && fdata[3] == marker[1]) {
2702 ha->flags.hw_event_marker_found = 1;
2706 /* No marker, write it. */
2707 if (!ha->flags.hw_event_marker_found) {
2708 rval = qla2xxx_hw_event_store(ha, marker);
2709 if (rval != QLA_SUCCESS) {
2710 DEBUG2(qla_printk(KERN_WARNING, ha,
2711 "HW event -- Failed marker write=%x.!\n",
2715 ha->flags.hw_event_marker_found = 1;
2720 fdata[0] = cpu_to_le32(code << 16 | d1);
2721 fdata[1] = cpu_to_le32(d2 << 16 | d3);
2722 rval = qla2xxx_hw_event_store(ha, fdata);
2723 if (rval != QLA_SUCCESS) {
2724 DEBUG2(qla_printk(KERN_WARNING, ha,
2725 "HW event -- Failed error write=%x.!\n",