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, vid.port_name,
898 vid.node_name, le16_to_cpu(entry->vf_id),
899 le16_to_cpu(entry->qos)));
901 vport = fc_vport_create(ha->host, 0, &vid);
903 qla_printk(KERN_INFO, ha, "NPIV-Config: Failed to "
904 "create vport [%02x]: wwpn=%llx wwnn=%llx.\n", cnt,
905 vid.port_name, vid.node_name);
912 qla24xx_unprotect_flash(scsi_qla_host_t *ha)
914 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
916 /* Enable flash write. */
917 WRT_REG_DWORD(®->ctrl_status,
918 RD_REG_DWORD(®->ctrl_status) | CSRX_FLASH_ENABLE);
919 RD_REG_DWORD(®->ctrl_status); /* PCI Posting. */
921 if (!ha->fdt_wrt_disable)
924 /* Disable flash write-protection. */
925 qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0);
926 /* Some flash parts need an additional zero-write to clear bits.*/
927 qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0);
931 qla24xx_protect_flash(scsi_qla_host_t *ha)
934 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
936 if (!ha->fdt_wrt_disable)
937 goto skip_wrt_protect;
939 /* Enable flash write-protection and wait for completion. */
940 qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101),
941 ha->fdt_wrt_disable);
942 for (cnt = 300; cnt &&
943 qla24xx_read_flash_dword(ha,
944 flash_conf_to_access_addr(0x005)) & BIT_0;
950 /* Disable flash write. */
951 WRT_REG_DWORD(®->ctrl_status,
952 RD_REG_DWORD(®->ctrl_status) & ~CSRX_FLASH_ENABLE);
953 RD_REG_DWORD(®->ctrl_status); /* PCI Posting. */
957 qla24xx_write_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
961 uint32_t liter, miter;
962 uint32_t sec_mask, rest_addr;
963 uint32_t fdata, findex;
964 dma_addr_t optrom_dma;
970 /* Prepare burst-capable write on supported ISPs. */
971 if (IS_QLA25XX(ha) && !(faddr & 0xfff) &&
972 dwords > OPTROM_BURST_DWORDS) {
973 optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
974 &optrom_dma, GFP_KERNEL);
976 qla_printk(KERN_DEBUG, ha,
977 "Unable to allocate memory for optrom burst write "
978 "(%x KB).\n", OPTROM_BURST_SIZE / 1024);
982 rest_addr = (ha->fdt_block_size >> 2) - 1;
983 sec_mask = 0x80000 - (ha->fdt_block_size >> 2);
985 qla24xx_unprotect_flash(ha);
987 for (liter = 0; liter < dwords; liter++, faddr++, dwptr++) {
988 if (ha->fdt_odd_index) {
990 fdata = findex & sec_mask;
993 fdata = (findex & sec_mask) << 2;
996 /* Are we at the beginning of a sector? */
997 if ((findex & rest_addr) == 0) {
998 /* Do sector unprotect. */
999 if (ha->fdt_unprotect_sec_cmd)
1000 qla24xx_write_flash_dword(ha,
1001 ha->fdt_unprotect_sec_cmd,
1002 (fdata & 0xff00) | ((fdata << 16) &
1003 0xff0000) | ((fdata >> 16) & 0xff));
1004 ret = qla24xx_write_flash_dword(ha, ha->fdt_erase_cmd,
1005 (fdata & 0xff00) |((fdata << 16) &
1006 0xff0000) | ((fdata >> 16) & 0xff));
1007 if (ret != QLA_SUCCESS) {
1008 DEBUG9(printk("%s(%ld) Unable to flash "
1009 "sector: address=%x.\n", __func__,
1010 ha->host_no, faddr));
1015 /* Go with burst-write. */
1016 if (optrom && (liter + OPTROM_BURST_DWORDS) <= dwords) {
1017 /* Copy data to DMA'ble buffer. */
1018 for (miter = 0, s = optrom, d = dwptr;
1019 miter < OPTROM_BURST_DWORDS; miter++, s++, d++)
1020 *s = cpu_to_le32(*d);
1022 ret = qla2x00_load_ram(ha, optrom_dma,
1023 flash_data_to_access_addr(faddr),
1024 OPTROM_BURST_DWORDS);
1025 if (ret != QLA_SUCCESS) {
1026 qla_printk(KERN_WARNING, ha,
1027 "Unable to burst-write optrom segment "
1028 "(%x/%x/%llx).\n", ret,
1029 flash_data_to_access_addr(faddr),
1030 (unsigned long long)optrom_dma);
1031 qla_printk(KERN_WARNING, ha,
1032 "Reverting to slow-write.\n");
1034 dma_free_coherent(&ha->pdev->dev,
1035 OPTROM_BURST_SIZE, optrom, optrom_dma);
1038 liter += OPTROM_BURST_DWORDS - 1;
1039 faddr += OPTROM_BURST_DWORDS - 1;
1040 dwptr += OPTROM_BURST_DWORDS - 1;
1045 ret = qla24xx_write_flash_dword(ha,
1046 flash_data_to_access_addr(faddr), cpu_to_le32(*dwptr));
1047 if (ret != QLA_SUCCESS) {
1048 DEBUG9(printk("%s(%ld) Unable to program flash "
1049 "address=%x data=%x.\n", __func__,
1050 ha->host_no, faddr, *dwptr));
1054 /* Do sector protect. */
1055 if (ha->fdt_unprotect_sec_cmd &&
1056 ((faddr & rest_addr) == rest_addr))
1057 qla24xx_write_flash_dword(ha,
1058 ha->fdt_protect_sec_cmd,
1059 (fdata & 0xff00) | ((fdata << 16) &
1060 0xff0000) | ((fdata >> 16) & 0xff));
1063 qla24xx_protect_flash(ha);
1066 dma_free_coherent(&ha->pdev->dev,
1067 OPTROM_BURST_SIZE, optrom, optrom_dma);
1073 qla2x00_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
1079 /* Word reads to NVRAM via registers. */
1080 wptr = (uint16_t *)buf;
1081 qla2x00_lock_nvram_access(ha);
1082 for (i = 0; i < bytes >> 1; i++, naddr++)
1083 wptr[i] = cpu_to_le16(qla2x00_get_nvram_word(ha,
1085 qla2x00_unlock_nvram_access(ha);
1091 qla24xx_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
1097 /* Dword reads to flash. */
1098 dwptr = (uint32_t *)buf;
1099 for (i = 0; i < bytes >> 2; i++, naddr++)
1100 dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
1101 nvram_data_to_access_addr(naddr)));
1107 qla2x00_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
1113 unsigned long flags;
1117 spin_lock_irqsave(&ha->hardware_lock, flags);
1118 qla2x00_lock_nvram_access(ha);
1120 /* Disable NVRAM write-protection. */
1121 stat = qla2x00_clear_nvram_protection(ha);
1123 wptr = (uint16_t *)buf;
1124 for (i = 0; i < bytes >> 1; i++, naddr++) {
1125 qla2x00_write_nvram_word(ha, naddr,
1126 cpu_to_le16(*wptr));
1130 /* Enable NVRAM write-protection. */
1131 qla2x00_set_nvram_protection(ha, stat);
1133 qla2x00_unlock_nvram_access(ha);
1134 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1140 qla24xx_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
1146 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1150 /* Enable flash write. */
1151 WRT_REG_DWORD(®->ctrl_status,
1152 RD_REG_DWORD(®->ctrl_status) | CSRX_FLASH_ENABLE);
1153 RD_REG_DWORD(®->ctrl_status); /* PCI Posting. */
1155 /* Disable NVRAM write-protection. */
1156 qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
1158 qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
1161 /* Dword writes to flash. */
1162 dwptr = (uint32_t *)buf;
1163 for (i = 0; i < bytes >> 2; i++, naddr++, dwptr++) {
1164 ret = qla24xx_write_flash_dword(ha,
1165 nvram_data_to_access_addr(naddr),
1166 cpu_to_le32(*dwptr));
1167 if (ret != QLA_SUCCESS) {
1168 DEBUG9(printk("%s(%ld) Unable to program "
1169 "nvram address=%x data=%x.\n", __func__,
1170 ha->host_no, naddr, *dwptr));
1175 /* Enable NVRAM write-protection. */
1176 qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
1179 /* Disable flash write. */
1180 WRT_REG_DWORD(®->ctrl_status,
1181 RD_REG_DWORD(®->ctrl_status) & ~CSRX_FLASH_ENABLE);
1182 RD_REG_DWORD(®->ctrl_status); /* PCI Posting. */
1188 qla25xx_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
1194 /* Dword reads to flash. */
1195 dwptr = (uint32_t *)buf;
1196 for (i = 0; i < bytes >> 2; i++, naddr++)
1197 dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
1198 flash_data_to_access_addr(ha->flt_region_vpd_nvram |
1205 qla25xx_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
1208 #define RMW_BUFFER_SIZE (64 * 1024)
1211 dbuf = vmalloc(RMW_BUFFER_SIZE);
1213 return QLA_MEMORY_ALLOC_FAILED;
1214 ha->isp_ops->read_optrom(ha, dbuf, ha->flt_region_vpd_nvram << 2,
1216 memcpy(dbuf + (naddr << 2), buf, bytes);
1217 ha->isp_ops->write_optrom(ha, dbuf, ha->flt_region_vpd_nvram << 2,
1225 qla2x00_flip_colors(scsi_qla_host_t *ha, uint16_t *pflags)
1227 if (IS_QLA2322(ha)) {
1228 /* Flip all colors. */
1229 if (ha->beacon_color_state == QLA_LED_ALL_ON) {
1231 ha->beacon_color_state = 0;
1232 *pflags = GPIO_LED_ALL_OFF;
1235 ha->beacon_color_state = QLA_LED_ALL_ON;
1236 *pflags = GPIO_LED_RGA_ON;
1239 /* Flip green led only. */
1240 if (ha->beacon_color_state == QLA_LED_GRN_ON) {
1242 ha->beacon_color_state = 0;
1243 *pflags = GPIO_LED_GREEN_OFF_AMBER_OFF;
1246 ha->beacon_color_state = QLA_LED_GRN_ON;
1247 *pflags = GPIO_LED_GREEN_ON_AMBER_OFF;
1252 #define PIO_REG(h, r) ((h)->pio_address + offsetof(struct device_reg_2xxx, r))
1255 qla2x00_beacon_blink(struct scsi_qla_host *ha)
1257 uint16_t gpio_enable;
1259 uint16_t led_color = 0;
1260 unsigned long flags;
1261 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1263 spin_lock_irqsave(&ha->hardware_lock, flags);
1265 /* Save the Original GPIOE. */
1266 if (ha->pio_address) {
1267 gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
1268 gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
1270 gpio_enable = RD_REG_WORD(®->gpioe);
1271 gpio_data = RD_REG_WORD(®->gpiod);
1274 /* Set the modified gpio_enable values */
1275 gpio_enable |= GPIO_LED_MASK;
1277 if (ha->pio_address) {
1278 WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
1280 WRT_REG_WORD(®->gpioe, gpio_enable);
1281 RD_REG_WORD(®->gpioe);
1284 qla2x00_flip_colors(ha, &led_color);
1286 /* Clear out any previously set LED color. */
1287 gpio_data &= ~GPIO_LED_MASK;
1289 /* Set the new input LED color to GPIOD. */
1290 gpio_data |= led_color;
1292 /* Set the modified gpio_data values */
1293 if (ha->pio_address) {
1294 WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
1296 WRT_REG_WORD(®->gpiod, gpio_data);
1297 RD_REG_WORD(®->gpiod);
1300 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1304 qla2x00_beacon_on(struct scsi_qla_host *ha)
1306 uint16_t gpio_enable;
1308 unsigned long flags;
1309 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1311 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1312 ha->fw_options[1] |= FO1_DISABLE_GPIO6_7;
1314 if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
1315 qla_printk(KERN_WARNING, ha,
1316 "Unable to update fw options (beacon on).\n");
1317 return QLA_FUNCTION_FAILED;
1320 /* Turn off LEDs. */
1321 spin_lock_irqsave(&ha->hardware_lock, flags);
1322 if (ha->pio_address) {
1323 gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
1324 gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
1326 gpio_enable = RD_REG_WORD(®->gpioe);
1327 gpio_data = RD_REG_WORD(®->gpiod);
1329 gpio_enable |= GPIO_LED_MASK;
1331 /* Set the modified gpio_enable values. */
1332 if (ha->pio_address) {
1333 WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
1335 WRT_REG_WORD(®->gpioe, gpio_enable);
1336 RD_REG_WORD(®->gpioe);
1339 /* Clear out previously set LED colour. */
1340 gpio_data &= ~GPIO_LED_MASK;
1341 if (ha->pio_address) {
1342 WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
1344 WRT_REG_WORD(®->gpiod, gpio_data);
1345 RD_REG_WORD(®->gpiod);
1347 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1350 * Let the per HBA timer kick off the blinking process based on
1351 * the following flags. No need to do anything else now.
1353 ha->beacon_blink_led = 1;
1354 ha->beacon_color_state = 0;
1360 qla2x00_beacon_off(struct scsi_qla_host *ha)
1362 int rval = QLA_SUCCESS;
1364 ha->beacon_blink_led = 0;
1366 /* Set the on flag so when it gets flipped it will be off. */
1368 ha->beacon_color_state = QLA_LED_ALL_ON;
1370 ha->beacon_color_state = QLA_LED_GRN_ON;
1372 ha->isp_ops->beacon_blink(ha); /* This turns green LED off */
1374 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1375 ha->fw_options[1] &= ~FO1_DISABLE_GPIO6_7;
1377 rval = qla2x00_set_fw_options(ha, ha->fw_options);
1378 if (rval != QLA_SUCCESS)
1379 qla_printk(KERN_WARNING, ha,
1380 "Unable to update fw options (beacon off).\n");
1386 qla24xx_flip_colors(scsi_qla_host_t *ha, uint16_t *pflags)
1388 /* Flip all colors. */
1389 if (ha->beacon_color_state == QLA_LED_ALL_ON) {
1391 ha->beacon_color_state = 0;
1395 ha->beacon_color_state = QLA_LED_ALL_ON;
1396 *pflags = GPDX_LED_YELLOW_ON | GPDX_LED_AMBER_ON;
1401 qla24xx_beacon_blink(struct scsi_qla_host *ha)
1403 uint16_t led_color = 0;
1405 unsigned long flags;
1406 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1408 /* Save the Original GPIOD. */
1409 spin_lock_irqsave(&ha->hardware_lock, flags);
1410 gpio_data = RD_REG_DWORD(®->gpiod);
1412 /* Enable the gpio_data reg for update. */
1413 gpio_data |= GPDX_LED_UPDATE_MASK;
1415 WRT_REG_DWORD(®->gpiod, gpio_data);
1416 gpio_data = RD_REG_DWORD(®->gpiod);
1418 /* Set the color bits. */
1419 qla24xx_flip_colors(ha, &led_color);
1421 /* Clear out any previously set LED color. */
1422 gpio_data &= ~GPDX_LED_COLOR_MASK;
1424 /* Set the new input LED color to GPIOD. */
1425 gpio_data |= led_color;
1427 /* Set the modified gpio_data values. */
1428 WRT_REG_DWORD(®->gpiod, gpio_data);
1429 gpio_data = RD_REG_DWORD(®->gpiod);
1430 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1434 qla24xx_beacon_on(struct scsi_qla_host *ha)
1437 unsigned long flags;
1438 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1440 if (ha->beacon_blink_led == 0) {
1441 /* Enable firmware for update */
1442 ha->fw_options[1] |= ADD_FO1_DISABLE_GPIO_LED_CTRL;
1444 if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS)
1445 return QLA_FUNCTION_FAILED;
1447 if (qla2x00_get_fw_options(ha, ha->fw_options) !=
1449 qla_printk(KERN_WARNING, ha,
1450 "Unable to update fw options (beacon on).\n");
1451 return QLA_FUNCTION_FAILED;
1454 spin_lock_irqsave(&ha->hardware_lock, flags);
1455 gpio_data = RD_REG_DWORD(®->gpiod);
1457 /* Enable the gpio_data reg for update. */
1458 gpio_data |= GPDX_LED_UPDATE_MASK;
1459 WRT_REG_DWORD(®->gpiod, gpio_data);
1460 RD_REG_DWORD(®->gpiod);
1462 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1465 /* So all colors blink together. */
1466 ha->beacon_color_state = 0;
1468 /* Let the per HBA timer kick off the blinking process. */
1469 ha->beacon_blink_led = 1;
1475 qla24xx_beacon_off(struct scsi_qla_host *ha)
1478 unsigned long flags;
1479 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1481 ha->beacon_blink_led = 0;
1482 ha->beacon_color_state = QLA_LED_ALL_ON;
1484 ha->isp_ops->beacon_blink(ha); /* Will flip to all off. */
1486 /* Give control back to firmware. */
1487 spin_lock_irqsave(&ha->hardware_lock, flags);
1488 gpio_data = RD_REG_DWORD(®->gpiod);
1490 /* Disable the gpio_data reg for update. */
1491 gpio_data &= ~GPDX_LED_UPDATE_MASK;
1492 WRT_REG_DWORD(®->gpiod, gpio_data);
1493 RD_REG_DWORD(®->gpiod);
1494 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1496 ha->fw_options[1] &= ~ADD_FO1_DISABLE_GPIO_LED_CTRL;
1498 if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
1499 qla_printk(KERN_WARNING, ha,
1500 "Unable to update fw options (beacon off).\n");
1501 return QLA_FUNCTION_FAILED;
1504 if (qla2x00_get_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
1505 qla_printk(KERN_WARNING, ha,
1506 "Unable to get fw options (beacon off).\n");
1507 return QLA_FUNCTION_FAILED;
1515 * Flash support routines
1519 * qla2x00_flash_enable() - Setup flash for reading and writing.
1523 qla2x00_flash_enable(scsi_qla_host_t *ha)
1526 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1528 data = RD_REG_WORD(®->ctrl_status);
1529 data |= CSR_FLASH_ENABLE;
1530 WRT_REG_WORD(®->ctrl_status, data);
1531 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1535 * qla2x00_flash_disable() - Disable flash and allow RISC to run.
1539 qla2x00_flash_disable(scsi_qla_host_t *ha)
1542 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1544 data = RD_REG_WORD(®->ctrl_status);
1545 data &= ~(CSR_FLASH_ENABLE);
1546 WRT_REG_WORD(®->ctrl_status, data);
1547 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1551 * qla2x00_read_flash_byte() - Reads a byte from flash
1553 * @addr: Address in flash to read
1555 * A word is read from the chip, but, only the lower byte is valid.
1557 * Returns the byte read from flash @addr.
1560 qla2x00_read_flash_byte(scsi_qla_host_t *ha, uint32_t addr)
1563 uint16_t bank_select;
1564 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1566 bank_select = RD_REG_WORD(®->ctrl_status);
1568 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
1569 /* Specify 64K address range: */
1570 /* clear out Module Select and Flash Address bits [19:16]. */
1571 bank_select &= ~0xf8;
1572 bank_select |= addr >> 12 & 0xf0;
1573 bank_select |= CSR_FLASH_64K_BANK;
1574 WRT_REG_WORD(®->ctrl_status, bank_select);
1575 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1577 WRT_REG_WORD(®->flash_address, (uint16_t)addr);
1578 data = RD_REG_WORD(®->flash_data);
1580 return (uint8_t)data;
1583 /* Setup bit 16 of flash address. */
1584 if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
1585 bank_select |= CSR_FLASH_64K_BANK;
1586 WRT_REG_WORD(®->ctrl_status, bank_select);
1587 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1588 } else if (((addr & BIT_16) == 0) &&
1589 (bank_select & CSR_FLASH_64K_BANK)) {
1590 bank_select &= ~(CSR_FLASH_64K_BANK);
1591 WRT_REG_WORD(®->ctrl_status, bank_select);
1592 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1595 /* Always perform IO mapped accesses to the FLASH registers. */
1596 if (ha->pio_address) {
1599 WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
1601 data = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
1604 data2 = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
1605 } while (data != data2);
1607 WRT_REG_WORD(®->flash_address, (uint16_t)addr);
1608 data = qla2x00_debounce_register(®->flash_data);
1611 return (uint8_t)data;
1615 * qla2x00_write_flash_byte() - Write a byte to flash
1617 * @addr: Address in flash to write
1618 * @data: Data to write
1621 qla2x00_write_flash_byte(scsi_qla_host_t *ha, uint32_t addr, uint8_t data)
1623 uint16_t bank_select;
1624 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1626 bank_select = RD_REG_WORD(®->ctrl_status);
1627 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
1628 /* Specify 64K address range: */
1629 /* clear out Module Select and Flash Address bits [19:16]. */
1630 bank_select &= ~0xf8;
1631 bank_select |= addr >> 12 & 0xf0;
1632 bank_select |= CSR_FLASH_64K_BANK;
1633 WRT_REG_WORD(®->ctrl_status, bank_select);
1634 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1636 WRT_REG_WORD(®->flash_address, (uint16_t)addr);
1637 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1638 WRT_REG_WORD(®->flash_data, (uint16_t)data);
1639 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1644 /* Setup bit 16 of flash address. */
1645 if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
1646 bank_select |= CSR_FLASH_64K_BANK;
1647 WRT_REG_WORD(®->ctrl_status, bank_select);
1648 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1649 } else if (((addr & BIT_16) == 0) &&
1650 (bank_select & CSR_FLASH_64K_BANK)) {
1651 bank_select &= ~(CSR_FLASH_64K_BANK);
1652 WRT_REG_WORD(®->ctrl_status, bank_select);
1653 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1656 /* Always perform IO mapped accesses to the FLASH registers. */
1657 if (ha->pio_address) {
1658 WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
1659 WRT_REG_WORD_PIO(PIO_REG(ha, flash_data), (uint16_t)data);
1661 WRT_REG_WORD(®->flash_address, (uint16_t)addr);
1662 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1663 WRT_REG_WORD(®->flash_data, (uint16_t)data);
1664 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1669 * qla2x00_poll_flash() - Polls flash for completion.
1671 * @addr: Address in flash to poll
1672 * @poll_data: Data to be polled
1673 * @man_id: Flash manufacturer ID
1674 * @flash_id: Flash ID
1676 * This function polls the device until bit 7 of what is read matches data
1677 * bit 7 or until data bit 5 becomes a 1. If that hapens, the flash ROM timed
1678 * out (a fatal error). The flash book recommeds reading bit 7 again after
1679 * reading bit 5 as a 1.
1681 * Returns 0 on success, else non-zero.
1684 qla2x00_poll_flash(scsi_qla_host_t *ha, uint32_t addr, uint8_t poll_data,
1685 uint8_t man_id, uint8_t flash_id)
1693 /* Wait for 30 seconds for command to finish. */
1695 for (cnt = 3000000; cnt; cnt--) {
1696 flash_data = qla2x00_read_flash_byte(ha, addr);
1697 if ((flash_data & BIT_7) == poll_data) {
1702 if (man_id != 0x40 && man_id != 0xda) {
1703 if ((flash_data & BIT_5) && cnt > 2)
1714 * qla2x00_program_flash_address() - Programs a flash address
1716 * @addr: Address in flash to program
1717 * @data: Data to be written in flash
1718 * @man_id: Flash manufacturer ID
1719 * @flash_id: Flash ID
1721 * Returns 0 on success, else non-zero.
1724 qla2x00_program_flash_address(scsi_qla_host_t *ha, uint32_t addr, uint8_t data,
1725 uint8_t man_id, uint8_t flash_id)
1727 /* Write Program Command Sequence. */
1728 if (IS_OEM_001(ha)) {
1729 qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
1730 qla2x00_write_flash_byte(ha, 0x555, 0x55);
1731 qla2x00_write_flash_byte(ha, 0xaaa, 0xa0);
1732 qla2x00_write_flash_byte(ha, addr, data);
1734 if (man_id == 0xda && flash_id == 0xc1) {
1735 qla2x00_write_flash_byte(ha, addr, data);
1739 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1740 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1741 qla2x00_write_flash_byte(ha, 0x5555, 0xa0);
1742 qla2x00_write_flash_byte(ha, addr, data);
1748 /* Wait for write to complete. */
1749 return qla2x00_poll_flash(ha, addr, data, man_id, flash_id);
1753 * qla2x00_erase_flash() - Erase the flash.
1755 * @man_id: Flash manufacturer ID
1756 * @flash_id: Flash ID
1758 * Returns 0 on success, else non-zero.
1761 qla2x00_erase_flash(scsi_qla_host_t *ha, uint8_t man_id, uint8_t flash_id)
1763 /* Individual Sector Erase Command Sequence */
1764 if (IS_OEM_001(ha)) {
1765 qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
1766 qla2x00_write_flash_byte(ha, 0x555, 0x55);
1767 qla2x00_write_flash_byte(ha, 0xaaa, 0x80);
1768 qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
1769 qla2x00_write_flash_byte(ha, 0x555, 0x55);
1770 qla2x00_write_flash_byte(ha, 0xaaa, 0x10);
1772 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1773 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1774 qla2x00_write_flash_byte(ha, 0x5555, 0x80);
1775 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1776 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1777 qla2x00_write_flash_byte(ha, 0x5555, 0x10);
1782 /* Wait for erase to complete. */
1783 return qla2x00_poll_flash(ha, 0x00, 0x80, man_id, flash_id);
1787 * qla2x00_erase_flash_sector() - Erase a flash sector.
1789 * @addr: Flash sector to erase
1790 * @sec_mask: Sector address mask
1791 * @man_id: Flash manufacturer ID
1792 * @flash_id: Flash ID
1794 * Returns 0 on success, else non-zero.
1797 qla2x00_erase_flash_sector(scsi_qla_host_t *ha, uint32_t addr,
1798 uint32_t sec_mask, uint8_t man_id, uint8_t flash_id)
1800 /* Individual Sector Erase Command Sequence */
1801 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1802 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1803 qla2x00_write_flash_byte(ha, 0x5555, 0x80);
1804 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1805 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1806 if (man_id == 0x1f && flash_id == 0x13)
1807 qla2x00_write_flash_byte(ha, addr & sec_mask, 0x10);
1809 qla2x00_write_flash_byte(ha, addr & sec_mask, 0x30);
1813 /* Wait for erase to complete. */
1814 return qla2x00_poll_flash(ha, addr, 0x80, man_id, flash_id);
1818 * qla2x00_get_flash_manufacturer() - Read manufacturer ID from flash chip.
1819 * @man_id: Flash manufacturer ID
1820 * @flash_id: Flash ID
1823 qla2x00_get_flash_manufacturer(scsi_qla_host_t *ha, uint8_t *man_id,
1826 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1827 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1828 qla2x00_write_flash_byte(ha, 0x5555, 0x90);
1829 *man_id = qla2x00_read_flash_byte(ha, 0x0000);
1830 *flash_id = qla2x00_read_flash_byte(ha, 0x0001);
1831 qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
1832 qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
1833 qla2x00_write_flash_byte(ha, 0x5555, 0xf0);
1837 qla2x00_read_flash_data(scsi_qla_host_t *ha, uint8_t *tmp_buf, uint32_t saddr,
1840 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1841 uint32_t midpoint, ilength;
1844 midpoint = length / 2;
1846 WRT_REG_WORD(®->nvram, 0);
1847 RD_REG_WORD(®->nvram);
1848 for (ilength = 0; ilength < length; saddr++, ilength++, tmp_buf++) {
1849 if (ilength == midpoint) {
1850 WRT_REG_WORD(®->nvram, NVR_SELECT);
1851 RD_REG_WORD(®->nvram);
1853 data = qla2x00_read_flash_byte(ha, saddr);
1862 qla2x00_suspend_hba(struct scsi_qla_host *ha)
1865 unsigned long flags;
1866 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1869 scsi_block_requests(ha->host);
1870 ha->isp_ops->disable_intrs(ha);
1871 set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
1874 spin_lock_irqsave(&ha->hardware_lock, flags);
1875 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
1876 RD_REG_WORD(®->hccr);
1877 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1878 for (cnt = 0; cnt < 30000; cnt++) {
1879 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
1886 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1890 qla2x00_resume_hba(struct scsi_qla_host *ha)
1893 clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
1894 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1895 qla2xxx_wake_dpc(ha);
1896 qla2x00_wait_for_hba_online(ha);
1897 scsi_unblock_requests(ha->host);
1901 qla2x00_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
1902 uint32_t offset, uint32_t length)
1904 uint32_t addr, midpoint;
1906 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1909 qla2x00_suspend_hba(ha);
1912 midpoint = ha->optrom_size / 2;
1914 qla2x00_flash_enable(ha);
1915 WRT_REG_WORD(®->nvram, 0);
1916 RD_REG_WORD(®->nvram); /* PCI Posting. */
1917 for (addr = offset, data = buf; addr < length; addr++, data++) {
1918 if (addr == midpoint) {
1919 WRT_REG_WORD(®->nvram, NVR_SELECT);
1920 RD_REG_WORD(®->nvram); /* PCI Posting. */
1923 *data = qla2x00_read_flash_byte(ha, addr);
1925 qla2x00_flash_disable(ha);
1928 qla2x00_resume_hba(ha);
1934 qla2x00_write_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
1935 uint32_t offset, uint32_t length)
1939 uint8_t man_id, flash_id, sec_number, data;
1941 uint32_t addr, liter, sec_mask, rest_addr;
1942 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1945 qla2x00_suspend_hba(ha);
1950 /* Reset ISP chip. */
1951 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
1952 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
1954 /* Go with write. */
1955 qla2x00_flash_enable(ha);
1956 do { /* Loop once to provide quick error exit */
1957 /* Structure of flash memory based on manufacturer */
1958 if (IS_OEM_001(ha)) {
1959 /* OEM variant with special flash part. */
1960 man_id = flash_id = 0;
1965 qla2x00_get_flash_manufacturer(ha, &man_id, &flash_id);
1967 case 0x20: /* ST flash. */
1968 if (flash_id == 0xd2 || flash_id == 0xe3) {
1970 * ST m29w008at part - 64kb sector size with
1971 * 32kb,8kb,8kb,16kb sectors at memory address
1979 * ST m29w010b part - 16kb sector size
1980 * Default to 16kb sectors
1985 case 0x40: /* Mostel flash. */
1986 /* Mostel v29c51001 part - 512 byte sector size. */
1990 case 0xbf: /* SST flash. */
1991 /* SST39sf10 part - 4kb sector size. */
1995 case 0xda: /* Winbond flash. */
1996 /* Winbond W29EE011 part - 256 byte sector size. */
2000 case 0xc2: /* Macronix flash. */
2001 /* 64k sector size. */
2002 if (flash_id == 0x38 || flash_id == 0x4f) {
2007 /* Fall through... */
2009 case 0x1f: /* Atmel flash. */
2010 /* 512k sector size. */
2011 if (flash_id == 0x13) {
2012 rest_addr = 0x7fffffff;
2013 sec_mask = 0x80000000;
2016 /* Fall through... */
2018 case 0x01: /* AMD flash. */
2019 if (flash_id == 0x38 || flash_id == 0x40 ||
2021 /* Am29LV081 part - 64kb sector size. */
2022 /* Am29LV002BT part - 64kb sector size. */
2026 } else if (flash_id == 0x3e) {
2028 * Am29LV008b part - 64kb sector size with
2029 * 32kb,8kb,8kb,16kb sector at memory address
2035 } else if (flash_id == 0x20 || flash_id == 0x6e) {
2037 * Am29LV010 part or AM29f010 - 16kb sector
2043 } else if (flash_id == 0x6d) {
2044 /* Am29LV001 part - 8kb sector size. */
2050 /* Default to 16 kb sector size. */
2057 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
2058 if (qla2x00_erase_flash(ha, man_id, flash_id)) {
2059 rval = QLA_FUNCTION_FAILED;
2064 for (addr = offset, liter = 0; liter < length; liter++,
2067 /* Are we at the beginning of a sector? */
2068 if ((addr & rest_addr) == 0) {
2069 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
2070 if (addr >= 0x10000UL) {
2071 if (((addr >> 12) & 0xf0) &&
2073 flash_id == 0x3e) ||
2075 flash_id == 0xd2))) {
2077 if (sec_number == 1) {
2098 } else if (addr == ha->optrom_size / 2) {
2099 WRT_REG_WORD(®->nvram, NVR_SELECT);
2100 RD_REG_WORD(®->nvram);
2103 if (flash_id == 0xda && man_id == 0xc1) {
2104 qla2x00_write_flash_byte(ha, 0x5555,
2106 qla2x00_write_flash_byte(ha, 0x2aaa,
2108 qla2x00_write_flash_byte(ha, 0x5555,
2110 } else if (!IS_QLA2322(ha) && !IS_QLA6322(ha)) {
2112 if (qla2x00_erase_flash_sector(ha,
2113 addr, sec_mask, man_id,
2115 rval = QLA_FUNCTION_FAILED;
2118 if (man_id == 0x01 && flash_id == 0x6d)
2123 if (man_id == 0x01 && flash_id == 0x6d) {
2124 if (sec_number == 1 &&
2125 addr == (rest_addr - 1)) {
2128 } else if (sec_number == 3 && (addr & 0x7ffe)) {
2134 if (qla2x00_program_flash_address(ha, addr, data,
2135 man_id, flash_id)) {
2136 rval = QLA_FUNCTION_FAILED;
2142 qla2x00_flash_disable(ha);
2145 qla2x00_resume_hba(ha);
2151 qla24xx_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
2152 uint32_t offset, uint32_t length)
2155 scsi_block_requests(ha->host);
2156 set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
2159 qla24xx_read_flash_data(ha, (uint32_t *)buf, offset >> 2, length >> 2);
2162 clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
2163 scsi_unblock_requests(ha->host);
2169 qla24xx_write_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
2170 uint32_t offset, uint32_t length)
2175 scsi_block_requests(ha->host);
2176 set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
2178 /* Go with write. */
2179 rval = qla24xx_write_flash_data(ha, (uint32_t *)buf, offset >> 2,
2182 /* Resume HBA -- RISC reset needed. */
2183 clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
2184 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2185 qla2xxx_wake_dpc(ha);
2186 qla2x00_wait_for_hba_online(ha);
2187 scsi_unblock_requests(ha->host);
2193 qla25xx_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
2194 uint32_t offset, uint32_t length)
2197 dma_addr_t optrom_dma;
2200 uint32_t faddr, left, burst;
2204 if (length < OPTROM_BURST_SIZE)
2207 optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
2208 &optrom_dma, GFP_KERNEL);
2210 qla_printk(KERN_DEBUG, ha,
2211 "Unable to allocate memory for optrom burst read "
2212 "(%x KB).\n", OPTROM_BURST_SIZE / 1024);
2218 faddr = offset >> 2;
2220 burst = OPTROM_BURST_DWORDS;
2225 rval = qla2x00_dump_ram(ha, optrom_dma,
2226 flash_data_to_access_addr(faddr), burst);
2228 qla_printk(KERN_WARNING, ha,
2229 "Unable to burst-read optrom segment "
2230 "(%x/%x/%llx).\n", rval,
2231 flash_data_to_access_addr(faddr),
2232 (unsigned long long)optrom_dma);
2233 qla_printk(KERN_WARNING, ha,
2234 "Reverting to slow-read.\n");
2236 dma_free_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
2237 optrom, optrom_dma);
2241 memcpy(pbuf, optrom, burst * 4);
2248 dma_free_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE, optrom,
2254 return qla24xx_read_optrom_data(ha, buf, offset, length);
2258 * qla2x00_get_fcode_version() - Determine an FCODE image's version.
2260 * @pcids: Pointer to the FCODE PCI data structure
2262 * The process of retrieving the FCODE version information is at best
2263 * described as interesting.
2265 * Within the first 100h bytes of the image an ASCII string is present
2266 * which contains several pieces of information including the FCODE
2267 * version. Unfortunately it seems the only reliable way to retrieve
2268 * the version is by scanning for another sentinel within the string,
2269 * the FCODE build date:
2271 * ... 2.00.02 10/17/02 ...
2273 * Returns QLA_SUCCESS on successful retrieval of version.
2276 qla2x00_get_fcode_version(scsi_qla_host_t *ha, uint32_t pcids)
2278 int ret = QLA_FUNCTION_FAILED;
2279 uint32_t istart, iend, iter, vend;
2280 uint8_t do_next, rbyte, *vbyte;
2282 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
2284 /* Skip the PCI data structure. */
2286 ((qla2x00_read_flash_byte(ha, pcids + 0x0B) << 8) |
2287 qla2x00_read_flash_byte(ha, pcids + 0x0A));
2288 iend = istart + 0x100;
2290 /* Scan for the sentinel date string...eeewww. */
2293 while ((iter < iend) && !do_next) {
2295 if (qla2x00_read_flash_byte(ha, iter) == '/') {
2296 if (qla2x00_read_flash_byte(ha, iter + 2) ==
2299 else if (qla2x00_read_flash_byte(ha,
2307 /* Backtrack to previous ' ' (space). */
2309 while ((iter > istart) && !do_next) {
2311 if (qla2x00_read_flash_byte(ha, iter) == ' ')
2318 * Mark end of version tag, and find previous ' ' (space) or
2319 * string length (recent FCODE images -- major hack ahead!!!).
2323 while ((iter > istart) && !do_next) {
2325 rbyte = qla2x00_read_flash_byte(ha, iter);
2326 if (rbyte == ' ' || rbyte == 0xd || rbyte == 0x10)
2332 /* Mark beginning of version tag, and copy data. */
2334 if ((vend - iter) &&
2335 ((vend - iter) < sizeof(ha->fcode_revision))) {
2336 vbyte = ha->fcode_revision;
2337 while (iter <= vend) {
2338 *vbyte++ = qla2x00_read_flash_byte(ha, iter);
2345 if (ret != QLA_SUCCESS)
2346 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
2350 qla2x00_get_flash_version(scsi_qla_host_t *ha, void *mbuf)
2352 int ret = QLA_SUCCESS;
2353 uint8_t code_type, last_image;
2354 uint32_t pcihdr, pcids;
2358 if (!ha->pio_address || !mbuf)
2359 return QLA_FUNCTION_FAILED;
2361 memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
2362 memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
2363 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
2364 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
2366 qla2x00_flash_enable(ha);
2368 /* Begin with first PCI expansion ROM header. */
2372 /* Verify PCI expansion ROM header. */
2373 if (qla2x00_read_flash_byte(ha, pcihdr) != 0x55 ||
2374 qla2x00_read_flash_byte(ha, pcihdr + 0x01) != 0xaa) {
2376 DEBUG2(printk("scsi(%ld): No matching ROM "
2377 "signature.\n", ha->host_no));
2378 ret = QLA_FUNCTION_FAILED;
2382 /* Locate PCI data structure. */
2384 ((qla2x00_read_flash_byte(ha, pcihdr + 0x19) << 8) |
2385 qla2x00_read_flash_byte(ha, pcihdr + 0x18));
2387 /* Validate signature of PCI data structure. */
2388 if (qla2x00_read_flash_byte(ha, pcids) != 'P' ||
2389 qla2x00_read_flash_byte(ha, pcids + 0x1) != 'C' ||
2390 qla2x00_read_flash_byte(ha, pcids + 0x2) != 'I' ||
2391 qla2x00_read_flash_byte(ha, pcids + 0x3) != 'R') {
2392 /* Incorrect header. */
2393 DEBUG2(printk("%s(): PCI data struct not found "
2394 "pcir_adr=%x.\n", __func__, pcids));
2395 ret = QLA_FUNCTION_FAILED;
2400 code_type = qla2x00_read_flash_byte(ha, pcids + 0x14);
2401 switch (code_type) {
2402 case ROM_CODE_TYPE_BIOS:
2403 /* Intel x86, PC-AT compatible. */
2404 ha->bios_revision[0] =
2405 qla2x00_read_flash_byte(ha, pcids + 0x12);
2406 ha->bios_revision[1] =
2407 qla2x00_read_flash_byte(ha, pcids + 0x13);
2408 DEBUG3(printk("%s(): read BIOS %d.%d.\n", __func__,
2409 ha->bios_revision[1], ha->bios_revision[0]));
2411 case ROM_CODE_TYPE_FCODE:
2412 /* Open Firmware standard for PCI (FCode). */
2414 qla2x00_get_fcode_version(ha, pcids);
2416 case ROM_CODE_TYPE_EFI:
2417 /* Extensible Firmware Interface (EFI). */
2418 ha->efi_revision[0] =
2419 qla2x00_read_flash_byte(ha, pcids + 0x12);
2420 ha->efi_revision[1] =
2421 qla2x00_read_flash_byte(ha, pcids + 0x13);
2422 DEBUG3(printk("%s(): read EFI %d.%d.\n", __func__,
2423 ha->efi_revision[1], ha->efi_revision[0]));
2426 DEBUG2(printk("%s(): Unrecognized code type %x at "
2427 "pcids %x.\n", __func__, code_type, pcids));
2431 last_image = qla2x00_read_flash_byte(ha, pcids + 0x15) & BIT_7;
2433 /* Locate next PCI expansion ROM. */
2434 pcihdr += ((qla2x00_read_flash_byte(ha, pcids + 0x11) << 8) |
2435 qla2x00_read_flash_byte(ha, pcids + 0x10)) * 512;
2436 } while (!last_image);
2438 if (IS_QLA2322(ha)) {
2439 /* Read firmware image information. */
2440 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
2442 memset(dbyte, 0, 8);
2443 dcode = (uint16_t *)dbyte;
2445 qla2x00_read_flash_data(ha, dbyte, ha->flt_region_fw * 4 + 10,
2447 DEBUG3(printk("%s(%ld): dumping fw ver from flash:\n",
2448 __func__, ha->host_no));
2449 DEBUG3(qla2x00_dump_buffer((uint8_t *)dbyte, 8));
2451 if ((dcode[0] == 0xffff && dcode[1] == 0xffff &&
2452 dcode[2] == 0xffff && dcode[3] == 0xffff) ||
2453 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
2455 DEBUG2(printk("%s(): Unrecognized fw revision at "
2456 "%x.\n", __func__, ha->flt_region_fw * 4));
2458 /* values are in big endian */
2459 ha->fw_revision[0] = dbyte[0] << 16 | dbyte[1];
2460 ha->fw_revision[1] = dbyte[2] << 16 | dbyte[3];
2461 ha->fw_revision[2] = dbyte[4] << 16 | dbyte[5];
2465 qla2x00_flash_disable(ha);
2471 qla24xx_get_flash_version(scsi_qla_host_t *ha, void *mbuf)
2473 int ret = QLA_SUCCESS;
2474 uint32_t pcihdr, pcids;
2477 uint8_t code_type, last_image;
2481 return QLA_FUNCTION_FAILED;
2483 memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
2484 memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
2485 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
2486 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
2490 /* Begin with first PCI expansion ROM header. */
2491 pcihdr = ha->flt_region_boot;
2494 /* Verify PCI expansion ROM header. */
2495 qla24xx_read_flash_data(ha, dcode, pcihdr >> 2, 0x20);
2496 bcode = mbuf + (pcihdr % 4);
2497 if (bcode[0x0] != 0x55 || bcode[0x1] != 0xaa) {
2499 DEBUG2(printk("scsi(%ld): No matching ROM "
2500 "signature.\n", ha->host_no));
2501 ret = QLA_FUNCTION_FAILED;
2505 /* Locate PCI data structure. */
2506 pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]);
2508 qla24xx_read_flash_data(ha, dcode, pcids >> 2, 0x20);
2509 bcode = mbuf + (pcihdr % 4);
2511 /* Validate signature of PCI data structure. */
2512 if (bcode[0x0] != 'P' || bcode[0x1] != 'C' ||
2513 bcode[0x2] != 'I' || bcode[0x3] != 'R') {
2514 /* Incorrect header. */
2515 DEBUG2(printk("%s(): PCI data struct not found "
2516 "pcir_adr=%x.\n", __func__, pcids));
2517 ret = QLA_FUNCTION_FAILED;
2522 code_type = bcode[0x14];
2523 switch (code_type) {
2524 case ROM_CODE_TYPE_BIOS:
2525 /* Intel x86, PC-AT compatible. */
2526 ha->bios_revision[0] = bcode[0x12];
2527 ha->bios_revision[1] = bcode[0x13];
2528 DEBUG3(printk("%s(): read BIOS %d.%d.\n", __func__,
2529 ha->bios_revision[1], ha->bios_revision[0]));
2531 case ROM_CODE_TYPE_FCODE:
2532 /* Open Firmware standard for PCI (FCode). */
2533 ha->fcode_revision[0] = bcode[0x12];
2534 ha->fcode_revision[1] = bcode[0x13];
2535 DEBUG3(printk("%s(): read FCODE %d.%d.\n", __func__,
2536 ha->fcode_revision[1], ha->fcode_revision[0]));
2538 case ROM_CODE_TYPE_EFI:
2539 /* Extensible Firmware Interface (EFI). */
2540 ha->efi_revision[0] = bcode[0x12];
2541 ha->efi_revision[1] = bcode[0x13];
2542 DEBUG3(printk("%s(): read EFI %d.%d.\n", __func__,
2543 ha->efi_revision[1], ha->efi_revision[0]));
2546 DEBUG2(printk("%s(): Unrecognized code type %x at "
2547 "pcids %x.\n", __func__, code_type, pcids));
2551 last_image = bcode[0x15] & BIT_7;
2553 /* Locate next PCI expansion ROM. */
2554 pcihdr += ((bcode[0x11] << 8) | bcode[0x10]) * 512;
2555 } while (!last_image);
2557 /* Read firmware image information. */
2558 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
2561 qla24xx_read_flash_data(ha, dcode, ha->flt_region_fw + 4, 4);
2562 for (i = 0; i < 4; i++)
2563 dcode[i] = be32_to_cpu(dcode[i]);
2565 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
2566 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
2567 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
2569 DEBUG2(printk("%s(): Unrecognized fw version at %x.\n",
2570 __func__, ha->flt_region_fw));
2572 ha->fw_revision[0] = dcode[0];
2573 ha->fw_revision[1] = dcode[1];
2574 ha->fw_revision[2] = dcode[2];
2575 ha->fw_revision[3] = dcode[3];
2582 qla2xxx_is_vpd_valid(uint8_t *pos, uint8_t *end)
2584 if (pos >= end || *pos != 0x82)
2588 if (pos >= end || *pos != 0x90)
2592 if (pos >= end || *pos != 0x78)
2599 qla2xxx_get_vpd_field(scsi_qla_host_t *ha, char *key, char *str, size_t size)
2601 uint8_t *pos = ha->vpd;
2602 uint8_t *end = pos + ha->vpd_size;
2605 if (!IS_FWI2_CAPABLE(ha) || !qla2xxx_is_vpd_valid(pos, end))
2608 while (pos < end && *pos != 0x78) {
2609 len = (*pos == 0x82) ? pos[1] : pos[2];
2611 if (!strncmp(pos, key, strlen(key)))
2614 if (*pos != 0x90 && *pos != 0x91)
2620 if (pos < end - len && *pos != 0x78)
2621 return snprintf(str, size, "%.*s", len, pos + 3);
2627 qla2xxx_hw_event_store(scsi_qla_host_t *ha, uint32_t *fdata)
2629 uint32_t d[2], faddr;
2631 /* Locate first empty entry. */
2633 if (ha->hw_event_ptr >=
2634 ha->flt_region_hw_event + FA_HW_EVENT_SIZE) {
2635 DEBUG2(qla_printk(KERN_WARNING, ha,
2636 "HW event -- Log Full!\n"));
2637 return QLA_MEMORY_ALLOC_FAILED;
2640 qla24xx_read_flash_data(ha, d, ha->hw_event_ptr, 2);
2641 faddr = flash_data_to_access_addr(ha->hw_event_ptr);
2642 ha->hw_event_ptr += FA_HW_EVENT_ENTRY_SIZE;
2643 if (d[0] == __constant_cpu_to_le32(0xffffffff) &&
2644 d[1] == __constant_cpu_to_le32(0xffffffff)) {
2645 qla24xx_unprotect_flash(ha);
2647 qla24xx_write_flash_dword(ha, faddr++,
2648 cpu_to_le32(jiffies));
2649 qla24xx_write_flash_dword(ha, faddr++, 0);
2650 qla24xx_write_flash_dword(ha, faddr++, *fdata++);
2651 qla24xx_write_flash_dword(ha, faddr++, *fdata);
2653 qla24xx_protect_flash(ha);
2661 qla2xxx_hw_event_log(scsi_qla_host_t *ha, uint16_t code, uint16_t d1,
2662 uint16_t d2, uint16_t d3)
2664 #define QMARK(a, b, c, d) \
2665 cpu_to_le32(LSB(a) << 24 | LSB(b) << 16 | LSB(c) << 8 | LSB(d))
2668 uint32_t marker[2], fdata[4];
2670 if (ha->flt_region_hw_event == 0)
2671 return QLA_FUNCTION_FAILED;
2673 DEBUG2(qla_printk(KERN_WARNING, ha,
2674 "HW event -- code=%x, d1=%x, d2=%x, d3=%x.\n", code, d1, d2, d3));
2676 /* If marker not already found, locate or write. */
2677 if (!ha->flags.hw_event_marker_found) {
2678 /* Create marker. */
2679 marker[0] = QMARK('L', ha->fw_major_version,
2680 ha->fw_minor_version, ha->fw_subminor_version);
2681 marker[1] = QMARK(QLA_DRIVER_MAJOR_VER, QLA_DRIVER_MINOR_VER,
2682 QLA_DRIVER_PATCH_VER, QLA_DRIVER_BETA_VER);
2684 /* Locate marker. */
2685 ha->hw_event_ptr = ha->flt_region_hw_event;
2687 qla24xx_read_flash_data(ha, fdata, ha->hw_event_ptr,
2689 if (fdata[0] == __constant_cpu_to_le32(0xffffffff) &&
2690 fdata[1] == __constant_cpu_to_le32(0xffffffff))
2692 ha->hw_event_ptr += FA_HW_EVENT_ENTRY_SIZE;
2693 if (ha->hw_event_ptr >=
2694 ha->flt_region_hw_event + FA_HW_EVENT_SIZE) {
2695 DEBUG2(qla_printk(KERN_WARNING, ha,
2696 "HW event -- Log Full!\n"));
2697 return QLA_MEMORY_ALLOC_FAILED;
2699 if (fdata[2] == marker[0] && fdata[3] == marker[1]) {
2700 ha->flags.hw_event_marker_found = 1;
2704 /* No marker, write it. */
2705 if (!ha->flags.hw_event_marker_found) {
2706 rval = qla2xxx_hw_event_store(ha, marker);
2707 if (rval != QLA_SUCCESS) {
2708 DEBUG2(qla_printk(KERN_WARNING, ha,
2709 "HW event -- Failed marker write=%x.!\n",
2713 ha->flags.hw_event_marker_found = 1;
2718 fdata[0] = cpu_to_le32(code << 16 | d1);
2719 fdata[1] = cpu_to_le32(d2 << 16 | d3);
2720 rval = qla2xxx_hw_event_store(ha, fdata);
2721 if (rval != QLA_SUCCESS) {
2722 DEBUG2(qla_printk(KERN_WARNING, ha,
2723 "HW event -- Failed error write=%x.!\n",