Skip to content

Commit 45aeaf1

Browse files
Ravi AnandJames Bottomley
authored andcommitted
[SCSI] qla2xxx: Add support for new flash part.
Signed-off-by: Andrew Vasquez <andrew.vasquez@qlogic.com> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
1 parent 5768008 commit 45aeaf1

File tree

2 files changed

+83
-12
lines changed

2 files changed

+83
-12
lines changed

drivers/scsi/qla2xxx/qla_def.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ struct device_reg_2xxx {
270270
#define NVR_SELECT BIT_1
271271
#define NVR_CLOCK BIT_0
272272

273+
#define NVR_WAIT_CNT 20000
274+
273275
union {
274276
struct {
275277
uint16_t mailbox0;

drivers/scsi/qla2xxx/qla_sup.c

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ qla2x00_write_nvram_word(scsi_qla_host_t *ha, uint32_t addr, uint16_t data)
9797
{
9898
int count;
9999
uint16_t word;
100-
uint32_t nv_cmd;
100+
uint32_t nv_cmd, wait_cnt;
101101
struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
102102

103103
qla2x00_nv_write(ha, NVR_DATA_OUT);
@@ -127,7 +127,13 @@ qla2x00_write_nvram_word(scsi_qla_host_t *ha, uint32_t addr, uint16_t data)
127127
/* Wait for NVRAM to become ready */
128128
WRT_REG_WORD(&reg->nvram, NVR_SELECT);
129129
RD_REG_WORD(&reg->nvram); /* PCI Posting. */
130+
wait_cnt = NVR_WAIT_CNT;
130131
do {
132+
if (!--wait_cnt) {
133+
DEBUG9_10(printk("%s(%ld): NVRAM didn't go ready...\n",
134+
__func__, ha->host_no));
135+
break;
136+
}
131137
NVRAM_DELAY();
132138
word = RD_REG_WORD(&reg->nvram);
133139
} while ((word & NVR_DATA_IN) == 0);
@@ -301,16 +307,17 @@ qla2x00_clear_nvram_protection(scsi_qla_host_t *ha)
301307
{
302308
int ret, stat;
303309
struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
304-
uint32_t word;
310+
uint32_t word, wait_cnt;
305311
uint16_t wprot, wprot_old;
306312

307313
/* Clear NVRAM write protection. */
308314
ret = QLA_FUNCTION_FAILED;
309-
wprot_old = cpu_to_le16(qla2x00_get_nvram_word(ha, 0));
310-
stat = qla2x00_write_nvram_word_tmo(ha, 0,
315+
316+
wprot_old = cpu_to_le16(qla2x00_get_nvram_word(ha, ha->nvram_base));
317+
stat = qla2x00_write_nvram_word_tmo(ha, ha->nvram_base,
311318
__constant_cpu_to_le16(0x1234), 100000);
312-
wprot = cpu_to_le16(qla2x00_get_nvram_word(ha, 0));
313-
if (stat != QLA_SUCCESS || wprot != __constant_cpu_to_le16(0x1234)) {
319+
wprot = cpu_to_le16(qla2x00_get_nvram_word(ha, ha->nvram_base));
320+
if (stat != QLA_SUCCESS || wprot != 0x1234) {
314321
/* Write enable. */
315322
qla2x00_nv_write(ha, NVR_DATA_OUT);
316323
qla2x00_nv_write(ha, 0);
@@ -341,14 +348,22 @@ qla2x00_clear_nvram_protection(scsi_qla_host_t *ha)
341348
/* Wait for NVRAM to become ready. */
342349
WRT_REG_WORD(&reg->nvram, NVR_SELECT);
343350
RD_REG_WORD(&reg->nvram); /* PCI Posting. */
351+
wait_cnt = NVR_WAIT_CNT;
344352
do {
353+
if (!--wait_cnt) {
354+
DEBUG9_10(printk("%s(%ld): NVRAM didn't go "
355+
"ready...\n", __func__,
356+
ha->host_no));
357+
break;
358+
}
345359
NVRAM_DELAY();
346360
word = RD_REG_WORD(&reg->nvram);
347361
} while ((word & NVR_DATA_IN) == 0);
348362

349-
ret = QLA_SUCCESS;
363+
if (wait_cnt)
364+
ret = QLA_SUCCESS;
350365
} else
351-
qla2x00_write_nvram_word(ha, 0, wprot_old);
366+
qla2x00_write_nvram_word(ha, ha->nvram_base, wprot_old);
352367

353368
return ret;
354369
}
@@ -357,7 +372,7 @@ static void
357372
qla2x00_set_nvram_protection(scsi_qla_host_t *ha, int stat)
358373
{
359374
struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
360-
uint32_t word;
375+
uint32_t word, wait_cnt;
361376

362377
if (stat != QLA_SUCCESS)
363378
return;
@@ -393,7 +408,13 @@ qla2x00_set_nvram_protection(scsi_qla_host_t *ha, int stat)
393408
/* Wait for NVRAM to become ready. */
394409
WRT_REG_WORD(&reg->nvram, NVR_SELECT);
395410
RD_REG_WORD(&reg->nvram); /* PCI Posting. */
411+
wait_cnt = NVR_WAIT_CNT;
396412
do {
413+
if (!--wait_cnt) {
414+
DEBUG9_10(printk("%s(%ld): NVRAM didn't go ready...\n",
415+
__func__, ha->host_no));
416+
break;
417+
}
397418
NVRAM_DELAY();
398419
word = RD_REG_WORD(&reg->nvram);
399420
} while ((word & NVR_DATA_IN) == 0);
@@ -500,6 +521,20 @@ qla24xx_get_flash_manufacturer(scsi_qla_host_t *ha, uint8_t *man_id,
500521
ids = qla24xx_read_flash_dword(ha, flash_data_to_access_addr(0xd03ab));
501522
*man_id = LSB(ids);
502523
*flash_id = MSB(ids);
524+
525+
/* Check if man_id and flash_id are valid. */
526+
if (ids != 0xDEADDEAD && (*man_id == 0 || *flash_id == 0)) {
527+
/* Read information using 0x9f opcode
528+
* Device ID, Mfg ID would be read in the format:
529+
* <Ext Dev Info><Device ID Part2><Device ID Part 1><Mfg ID>
530+
* Example: ATMEL 0x00 01 45 1F
531+
* Extract MFG and Dev ID from last two bytes.
532+
*/
533+
ids = qla24xx_read_flash_dword(ha,
534+
flash_data_to_access_addr(0xd009f));
535+
*man_id = LSB(ids);
536+
*flash_id = MSB(ids);
537+
}
503538
}
504539

505540
int
@@ -508,8 +543,8 @@ qla24xx_write_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
508543
{
509544
int ret;
510545
uint32_t liter;
511-
uint32_t sec_mask, rest_addr, conf_addr;
512-
uint32_t fdata;
546+
uint32_t sec_mask, rest_addr, conf_addr, sec_end_mask;
547+
uint32_t fdata, findex ;
513548
uint8_t man_id, flash_id;
514549
struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
515550

@@ -519,6 +554,7 @@ qla24xx_write_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
519554
DEBUG9(printk("%s(%ld): Flash man_id=%d flash_id=%d\n", __func__,
520555
ha->host_no, man_id, flash_id));
521556

557+
sec_end_mask = 0;
522558
conf_addr = flash_conf_to_access_addr(0x03d8);
523559
switch (man_id) {
524560
case 0xbf: /* STT flash. */
@@ -531,6 +567,12 @@ qla24xx_write_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
531567
rest_addr = 0x3fff;
532568
sec_mask = 0x3c000;
533569
break;
570+
case 0x1f: // Atmel 26DF081A
571+
rest_addr = 0x0fff;
572+
sec_mask = 0xff000;
573+
sec_end_mask = 0x003ff;
574+
conf_addr = flash_conf_to_access_addr(0x0320);
575+
break;
534576
default:
535577
/* Default to 64 kb sector size. */
536578
rest_addr = 0x3fff;
@@ -545,11 +587,30 @@ qla24xx_write_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
545587

546588
/* Disable flash write-protection. */
547589
qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0);
590+
/* Some flash parts need an additional zero-write to clear bits.*/
591+
qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0);
548592

549593
do { /* Loop once to provide quick error exit. */
550594
for (liter = 0; liter < dwords; liter++, faddr++, dwptr++) {
595+
if (man_id == 0x1f) {
596+
findex = faddr << 2;
597+
fdata = findex & sec_mask;
598+
} else {
599+
findex = faddr;
600+
fdata = (findex & sec_mask) << 2;
601+
}
602+
551603
/* Are we at the beginning of a sector? */
552-
if ((faddr & rest_addr) == 0) {
604+
if ((findex & rest_addr) == 0) {
605+
/*
606+
* Do sector unprotect at 4K boundry for Atmel
607+
* part.
608+
*/
609+
if (man_id == 0x1f)
610+
qla24xx_write_flash_dword(ha,
611+
flash_conf_to_access_addr(0x0339),
612+
(fdata & 0xff00) | ((fdata << 16) &
613+
0xff0000) | ((fdata >> 16) & 0xff));
553614
fdata = (faddr & sec_mask) << 2;
554615
ret = qla24xx_write_flash_dword(ha, conf_addr,
555616
(fdata & 0xff00) |((fdata << 16) &
@@ -570,6 +631,14 @@ qla24xx_write_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
570631
ha->host_no, faddr, *dwptr));
571632
break;
572633
}
634+
635+
/* Do sector protect at 4K boundry for Atmel part. */
636+
if (man_id == 0x1f &&
637+
((faddr & sec_end_mask) == 0x3ff))
638+
qla24xx_write_flash_dword(ha,
639+
flash_conf_to_access_addr(0x0336),
640+
(fdata & 0xff00) | ((fdata << 16) &
641+
0xff0000) | ((fdata >> 16) & 0xff));
573642
}
574643
} while (0);
575644

0 commit comments

Comments
 (0)