forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/scsi/qla2xxx/qla_sup.c
....@@ -1,8 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * QLogic Fibre Channel HBA Driver
34 * Copyright (c) 2003-2014 QLogic Corporation
4
- *
5
- * See LICENSE.qla2xxx for copyright and licensing details.
65 */
76 #include "qla_def.h"
87
....@@ -26,24 +25,24 @@
2625 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2726
2827 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) {
29
- data = RD_REG_WORD(&reg->nvram);
28
+ data = rd_reg_word(&reg->nvram);
3029 while (data & NVR_BUSY) {
3130 udelay(100);
32
- data = RD_REG_WORD(&reg->nvram);
31
+ data = rd_reg_word(&reg->nvram);
3332 }
3433
3534 /* Lock resource */
36
- WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0x1);
37
- RD_REG_WORD(&reg->u.isp2300.host_semaphore);
35
+ wrt_reg_word(&reg->u.isp2300.host_semaphore, 0x1);
36
+ rd_reg_word(&reg->u.isp2300.host_semaphore);
3837 udelay(5);
39
- data = RD_REG_WORD(&reg->u.isp2300.host_semaphore);
38
+ data = rd_reg_word(&reg->u.isp2300.host_semaphore);
4039 while ((data & BIT_0) == 0) {
4140 /* Lock failed */
4241 udelay(100);
43
- WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0x1);
44
- RD_REG_WORD(&reg->u.isp2300.host_semaphore);
42
+ wrt_reg_word(&reg->u.isp2300.host_semaphore, 0x1);
43
+ rd_reg_word(&reg->u.isp2300.host_semaphore);
4544 udelay(5);
46
- data = RD_REG_WORD(&reg->u.isp2300.host_semaphore);
45
+ data = rd_reg_word(&reg->u.isp2300.host_semaphore);
4746 }
4847 }
4948 }
....@@ -58,8 +57,8 @@
5857 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
5958
6059 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) {
61
- WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0);
62
- RD_REG_WORD(&reg->u.isp2300.host_semaphore);
60
+ wrt_reg_word(&reg->u.isp2300.host_semaphore, 0);
61
+ rd_reg_word(&reg->u.isp2300.host_semaphore);
6362 }
6463 }
6564
....@@ -73,15 +72,15 @@
7372 {
7473 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7574
76
- WRT_REG_WORD(&reg->nvram, data | NVR_SELECT | NVR_WRT_ENABLE);
77
- RD_REG_WORD(&reg->nvram); /* PCI Posting. */
75
+ wrt_reg_word(&reg->nvram, data | NVR_SELECT | NVR_WRT_ENABLE);
76
+ rd_reg_word(&reg->nvram); /* PCI Posting. */
7877 NVRAM_DELAY();
79
- WRT_REG_WORD(&reg->nvram, data | NVR_SELECT | NVR_CLOCK |
78
+ wrt_reg_word(&reg->nvram, data | NVR_SELECT | NVR_CLOCK |
8079 NVR_WRT_ENABLE);
81
- RD_REG_WORD(&reg->nvram); /* PCI Posting. */
80
+ rd_reg_word(&reg->nvram); /* PCI Posting. */
8281 NVRAM_DELAY();
83
- WRT_REG_WORD(&reg->nvram, data | NVR_SELECT | NVR_WRT_ENABLE);
84
- RD_REG_WORD(&reg->nvram); /* PCI Posting. */
82
+ wrt_reg_word(&reg->nvram, data | NVR_SELECT | NVR_WRT_ENABLE);
83
+ rd_reg_word(&reg->nvram); /* PCI Posting. */
8584 NVRAM_DELAY();
8685 }
8786
....@@ -120,21 +119,21 @@
120119
121120 /* Read data from NVRAM. */
122121 for (cnt = 0; cnt < 16; cnt++) {
123
- WRT_REG_WORD(&reg->nvram, NVR_SELECT | NVR_CLOCK);
124
- RD_REG_WORD(&reg->nvram); /* PCI Posting. */
122
+ wrt_reg_word(&reg->nvram, NVR_SELECT | NVR_CLOCK);
123
+ rd_reg_word(&reg->nvram); /* PCI Posting. */
125124 NVRAM_DELAY();
126125 data <<= 1;
127
- reg_data = RD_REG_WORD(&reg->nvram);
126
+ reg_data = rd_reg_word(&reg->nvram);
128127 if (reg_data & NVR_DATA_IN)
129128 data |= BIT_0;
130
- WRT_REG_WORD(&reg->nvram, NVR_SELECT);
131
- RD_REG_WORD(&reg->nvram); /* PCI Posting. */
129
+ wrt_reg_word(&reg->nvram, NVR_SELECT);
130
+ rd_reg_word(&reg->nvram); /* PCI Posting. */
132131 NVRAM_DELAY();
133132 }
134133
135134 /* Deselect chip. */
136
- WRT_REG_WORD(&reg->nvram, NVR_DESELECT);
137
- RD_REG_WORD(&reg->nvram); /* PCI Posting. */
135
+ wrt_reg_word(&reg->nvram, NVR_DESELECT);
136
+ rd_reg_word(&reg->nvram); /* PCI Posting. */
138137 NVRAM_DELAY();
139138
140139 return data;
....@@ -171,8 +170,8 @@
171170 {
172171 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
173172
174
- WRT_REG_WORD(&reg->nvram, NVR_DESELECT);
175
- RD_REG_WORD(&reg->nvram); /* PCI Posting. */
173
+ wrt_reg_word(&reg->nvram, NVR_DESELECT);
174
+ rd_reg_word(&reg->nvram); /* PCI Posting. */
176175 NVRAM_DELAY();
177176 }
178177
....@@ -183,7 +182,7 @@
183182 * @data: word to program
184183 */
185184 static void
186
-qla2x00_write_nvram_word(struct qla_hw_data *ha, uint32_t addr, uint16_t data)
185
+qla2x00_write_nvram_word(struct qla_hw_data *ha, uint32_t addr, __le16 data)
187186 {
188187 int count;
189188 uint16_t word;
....@@ -202,7 +201,7 @@
202201
203202 /* Write data */
204203 nv_cmd = (addr << 16) | NV_WRITE_OP;
205
- nv_cmd |= data;
204
+ nv_cmd |= (__force u16)data;
206205 nv_cmd <<= 5;
207206 for (count = 0; count < 27; count++) {
208207 if (nv_cmd & BIT_31)
....@@ -216,8 +215,8 @@
216215 qla2x00_nv_deselect(ha);
217216
218217 /* Wait for NVRAM to become ready */
219
- WRT_REG_WORD(&reg->nvram, NVR_SELECT);
220
- RD_REG_WORD(&reg->nvram); /* PCI Posting. */
218
+ wrt_reg_word(&reg->nvram, NVR_SELECT);
219
+ rd_reg_word(&reg->nvram); /* PCI Posting. */
221220 wait_cnt = NVR_WAIT_CNT;
222221 do {
223222 if (!--wait_cnt) {
....@@ -226,7 +225,7 @@
226225 break;
227226 }
228227 NVRAM_DELAY();
229
- word = RD_REG_WORD(&reg->nvram);
228
+ word = rd_reg_word(&reg->nvram);
230229 } while ((word & NVR_DATA_IN) == 0);
231230
232231 qla2x00_nv_deselect(ha);
....@@ -241,7 +240,7 @@
241240
242241 static int
243242 qla2x00_write_nvram_word_tmo(struct qla_hw_data *ha, uint32_t addr,
244
- uint16_t data, uint32_t tmo)
243
+ __le16 data, uint32_t tmo)
245244 {
246245 int ret, count;
247246 uint16_t word;
....@@ -261,7 +260,7 @@
261260
262261 /* Write data */
263262 nv_cmd = (addr << 16) | NV_WRITE_OP;
264
- nv_cmd |= data;
263
+ nv_cmd |= (__force u16)data;
265264 nv_cmd <<= 5;
266265 for (count = 0; count < 27; count++) {
267266 if (nv_cmd & BIT_31)
....@@ -275,11 +274,11 @@
275274 qla2x00_nv_deselect(ha);
276275
277276 /* Wait for NVRAM to become ready */
278
- WRT_REG_WORD(&reg->nvram, NVR_SELECT);
279
- RD_REG_WORD(&reg->nvram); /* PCI Posting. */
277
+ wrt_reg_word(&reg->nvram, NVR_SELECT);
278
+ rd_reg_word(&reg->nvram); /* PCI Posting. */
280279 do {
281280 NVRAM_DELAY();
282
- word = RD_REG_WORD(&reg->nvram);
281
+ word = rd_reg_word(&reg->nvram);
283282 if (!--tmo) {
284283 ret = QLA_FUNCTION_FAILED;
285284 break;
....@@ -308,7 +307,7 @@
308307 int ret, stat;
309308 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
310309 uint32_t word, wait_cnt;
311
- uint16_t wprot, wprot_old;
310
+ __le16 wprot, wprot_old;
312311 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
313312
314313 /* Clear NVRAM write protection. */
....@@ -318,7 +317,7 @@
318317 stat = qla2x00_write_nvram_word_tmo(ha, ha->nvram_base,
319318 cpu_to_le16(0x1234), 100000);
320319 wprot = cpu_to_le16(qla2x00_get_nvram_word(ha, ha->nvram_base));
321
- if (stat != QLA_SUCCESS || wprot != 0x1234) {
320
+ if (stat != QLA_SUCCESS || wprot != cpu_to_le16(0x1234)) {
322321 /* Write enable. */
323322 qla2x00_nv_write(ha, NVR_DATA_OUT);
324323 qla2x00_nv_write(ha, 0);
....@@ -347,8 +346,8 @@
347346 qla2x00_nv_deselect(ha);
348347
349348 /* Wait for NVRAM to become ready. */
350
- WRT_REG_WORD(&reg->nvram, NVR_SELECT);
351
- RD_REG_WORD(&reg->nvram); /* PCI Posting. */
349
+ wrt_reg_word(&reg->nvram, NVR_SELECT);
350
+ rd_reg_word(&reg->nvram); /* PCI Posting. */
352351 wait_cnt = NVR_WAIT_CNT;
353352 do {
354353 if (!--wait_cnt) {
....@@ -357,7 +356,7 @@
357356 break;
358357 }
359358 NVRAM_DELAY();
360
- word = RD_REG_WORD(&reg->nvram);
359
+ word = rd_reg_word(&reg->nvram);
361360 } while ((word & NVR_DATA_IN) == 0);
362361
363362 if (wait_cnt)
....@@ -407,8 +406,8 @@
407406 qla2x00_nv_deselect(ha);
408407
409408 /* Wait for NVRAM to become ready. */
410
- WRT_REG_WORD(&reg->nvram, NVR_SELECT);
411
- RD_REG_WORD(&reg->nvram); /* PCI Posting. */
409
+ wrt_reg_word(&reg->nvram, NVR_SELECT);
410
+ rd_reg_word(&reg->nvram); /* PCI Posting. */
412411 wait_cnt = NVR_WAIT_CNT;
413412 do {
414413 if (!--wait_cnt) {
....@@ -417,7 +416,7 @@
417416 break;
418417 }
419418 NVRAM_DELAY();
420
- word = RD_REG_WORD(&reg->nvram);
419
+ word = rd_reg_word(&reg->nvram);
421420 } while ((word & NVR_DATA_IN) == 0);
422421 }
423422
....@@ -429,102 +428,104 @@
429428 static inline uint32_t
430429 flash_conf_addr(struct qla_hw_data *ha, uint32_t faddr)
431430 {
432
- return ha->flash_conf_off | faddr;
431
+ return ha->flash_conf_off + faddr;
433432 }
434433
435434 static inline uint32_t
436435 flash_data_addr(struct qla_hw_data *ha, uint32_t faddr)
437436 {
438
- return ha->flash_data_off | faddr;
437
+ return ha->flash_data_off + faddr;
439438 }
440439
441440 static inline uint32_t
442441 nvram_conf_addr(struct qla_hw_data *ha, uint32_t naddr)
443442 {
444
- return ha->nvram_conf_off | naddr;
443
+ return ha->nvram_conf_off + naddr;
445444 }
446445
447446 static inline uint32_t
448447 nvram_data_addr(struct qla_hw_data *ha, uint32_t naddr)
449448 {
450
- return ha->nvram_data_off | naddr;
449
+ return ha->nvram_data_off + naddr;
451450 }
452451
453
-static uint32_t
454
-qla24xx_read_flash_dword(struct qla_hw_data *ha, uint32_t addr)
452
+static int
453
+qla24xx_read_flash_dword(struct qla_hw_data *ha, uint32_t addr, uint32_t *data)
455454 {
456
- int rval;
457
- uint32_t cnt, data;
458455 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
456
+ ulong cnt = 30000;
459457
460
- WRT_REG_DWORD(&reg->flash_addr, addr & ~FARX_DATA_FLAG);
461
- /* Wait for READ cycle to complete. */
462
- rval = QLA_SUCCESS;
463
- for (cnt = 3000;
464
- (RD_REG_DWORD(&reg->flash_addr) & FARX_DATA_FLAG) == 0 &&
465
- rval == QLA_SUCCESS; cnt--) {
466
- if (cnt)
467
- udelay(10);
468
- else
469
- rval = QLA_FUNCTION_TIMEOUT;
458
+ wrt_reg_dword(&reg->flash_addr, addr & ~FARX_DATA_FLAG);
459
+
460
+ while (cnt--) {
461
+ if (rd_reg_dword(&reg->flash_addr) & FARX_DATA_FLAG) {
462
+ *data = rd_reg_dword(&reg->flash_data);
463
+ return QLA_SUCCESS;
464
+ }
465
+ udelay(10);
470466 cond_resched();
471467 }
472468
473
- /* TODO: What happens if we time out? */
474
- data = 0xDEADDEAD;
475
- if (rval == QLA_SUCCESS)
476
- data = RD_REG_DWORD(&reg->flash_data);
477
-
478
- return data;
469
+ ql_log(ql_log_warn, pci_get_drvdata(ha->pdev), 0x7090,
470
+ "Flash read dword at %x timeout.\n", addr);
471
+ *data = 0xDEADDEAD;
472
+ return QLA_FUNCTION_TIMEOUT;
479473 }
480474
481
-uint32_t *
475
+int
482476 qla24xx_read_flash_data(scsi_qla_host_t *vha, uint32_t *dwptr, uint32_t faddr,
483477 uint32_t dwords)
484478 {
485
- uint32_t i;
479
+ ulong i;
480
+ int ret = QLA_SUCCESS;
486481 struct qla_hw_data *ha = vha->hw;
487482
488483 /* Dword reads to flash. */
489
- for (i = 0; i < dwords; i++, faddr++)
490
- dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
491
- flash_data_addr(ha, faddr)));
484
+ faddr = flash_data_addr(ha, faddr);
485
+ for (i = 0; i < dwords; i++, faddr++, dwptr++) {
486
+ ret = qla24xx_read_flash_dword(ha, faddr, dwptr);
487
+ if (ret != QLA_SUCCESS)
488
+ break;
489
+ cpu_to_le32s(dwptr);
490
+ }
492491
493
- return dwptr;
492
+ return ret;
494493 }
495494
496495 static int
497496 qla24xx_write_flash_dword(struct qla_hw_data *ha, uint32_t addr, uint32_t data)
498497 {
499
- int rval;
500
- uint32_t cnt;
501498 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
499
+ ulong cnt = 500000;
502500
503
- WRT_REG_DWORD(&reg->flash_data, data);
504
- RD_REG_DWORD(&reg->flash_data); /* PCI Posting. */
505
- WRT_REG_DWORD(&reg->flash_addr, addr | FARX_DATA_FLAG);
506
- /* Wait for Write cycle to complete. */
507
- rval = QLA_SUCCESS;
508
- for (cnt = 500000; (RD_REG_DWORD(&reg->flash_addr) & FARX_DATA_FLAG) &&
509
- rval == QLA_SUCCESS; cnt--) {
510
- if (cnt)
511
- udelay(10);
512
- else
513
- rval = QLA_FUNCTION_TIMEOUT;
501
+ wrt_reg_dword(&reg->flash_data, data);
502
+ wrt_reg_dword(&reg->flash_addr, addr | FARX_DATA_FLAG);
503
+
504
+ while (cnt--) {
505
+ if (!(rd_reg_dword(&reg->flash_addr) & FARX_DATA_FLAG))
506
+ return QLA_SUCCESS;
507
+ udelay(10);
514508 cond_resched();
515509 }
516
- return rval;
510
+
511
+ ql_log(ql_log_warn, pci_get_drvdata(ha->pdev), 0x7090,
512
+ "Flash write dword at %x timeout.\n", addr);
513
+ return QLA_FUNCTION_TIMEOUT;
517514 }
518515
519516 static void
520517 qla24xx_get_flash_manufacturer(struct qla_hw_data *ha, uint8_t *man_id,
521518 uint8_t *flash_id)
522519 {
523
- uint32_t ids;
520
+ uint32_t faddr, ids = 0;
524521
525
- ids = qla24xx_read_flash_dword(ha, flash_conf_addr(ha, 0x03ab));
526
- *man_id = LSB(ids);
527
- *flash_id = MSB(ids);
522
+ *man_id = *flash_id = 0;
523
+
524
+ faddr = flash_conf_addr(ha, 0x03ab);
525
+ if (!qla24xx_read_flash_dword(ha, faddr, &ids)) {
526
+ *man_id = LSB(ids);
527
+ *flash_id = MSB(ids);
528
+ }
528529
529530 /* Check if man_id and flash_id are valid. */
530531 if (ids != 0xDEADDEAD && (*man_id == 0 || *flash_id == 0)) {
....@@ -534,9 +535,11 @@
534535 * Example: ATMEL 0x00 01 45 1F
535536 * Extract MFG and Dev ID from last two bytes.
536537 */
537
- ids = qla24xx_read_flash_dword(ha, flash_conf_addr(ha, 0x009f));
538
- *man_id = LSB(ids);
539
- *flash_id = MSB(ids);
538
+ faddr = flash_conf_addr(ha, 0x009f);
539
+ if (!qla24xx_read_flash_dword(ha, faddr, &ids)) {
540
+ *man_id = LSB(ids);
541
+ *flash_id = MSB(ids);
542
+ }
540543 }
541544 }
542545
....@@ -545,12 +548,13 @@
545548 {
546549 const char *loc, *locations[] = { "DEF", "PCI" };
547550 uint32_t pcihdr, pcids;
548
- uint32_t *dcode;
549
- uint8_t *buf, *bcode, last_image;
550
- uint16_t cnt, chksum, *wptr;
551
- struct qla_flt_location *fltl;
551
+ uint16_t cnt, chksum;
552
+ __le16 *wptr;
552553 struct qla_hw_data *ha = vha->hw;
553554 struct req_que *req = ha->req_q_map[0];
555
+ struct qla_flt_location *fltl = (void *)req->ring;
556
+ uint32_t *dcode = (uint32_t *)req->ring;
557
+ uint8_t *buf = (void *)req->ring, *bcode, last_image;
554558
555559 /*
556560 * FLT-location structure resides after the last PCI region.
....@@ -571,12 +575,13 @@
571575 } else if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
572576 *start = FA_FLASH_LAYOUT_ADDR_83;
573577 goto end;
578
+ } else if (IS_QLA28XX(ha)) {
579
+ *start = FA_FLASH_LAYOUT_ADDR_28;
580
+ goto end;
574581 }
582
+
575583 /* Begin with first PCI expansion ROM header. */
576
- buf = (uint8_t *)req->ring;
577
- dcode = (uint32_t *)req->ring;
578584 pcihdr = 0;
579
- last_image = 1;
580585 do {
581586 /* Verify PCI expansion ROM header. */
582587 qla24xx_read_flash_data(vha, dcode, pcihdr >> 2, 0x20);
....@@ -601,22 +606,19 @@
601606 } while (!last_image);
602607
603608 /* Now verify FLT-location structure. */
604
- fltl = (struct qla_flt_location *)req->ring;
605
- qla24xx_read_flash_data(vha, dcode, pcihdr >> 2,
606
- sizeof(struct qla_flt_location) >> 2);
607
- if (fltl->sig[0] != 'Q' || fltl->sig[1] != 'F' ||
608
- fltl->sig[2] != 'L' || fltl->sig[3] != 'T')
609
+ qla24xx_read_flash_data(vha, dcode, pcihdr >> 2, sizeof(*fltl) >> 2);
610
+ if (memcmp(fltl->sig, "QFLT", 4))
609611 goto end;
610612
611
- wptr = (uint16_t *)req->ring;
612
- cnt = sizeof(struct qla_flt_location) >> 1;
613
+ wptr = (__force __le16 *)req->ring;
614
+ cnt = sizeof(*fltl) / sizeof(*wptr);
613615 for (chksum = 0; cnt--; wptr++)
614616 chksum += le16_to_cpu(*wptr);
615617 if (chksum) {
616618 ql_log(ql_log_fatal, vha, 0x0045,
617619 "Inconsistent FLTL detected: checksum=0x%x.\n", chksum);
618620 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010e,
619
- buf, sizeof(struct qla_flt_location));
621
+ fltl, sizeof(*fltl));
620622 return QLA_FUNCTION_FAILED;
621623 }
622624
....@@ -634,7 +636,7 @@
634636 static void
635637 qla2xxx_get_flt_info(scsi_qla_host_t *vha, uint32_t flt_addr)
636638 {
637
- const char *loc, *locations[] = { "DEF", "FLT" };
639
+ const char *locations[] = { "DEF", "FLT" }, *loc = locations[1];
638640 const uint32_t def_fw[] =
639641 { FA_RISC_CODE_ADDR, FA_RISC_CODE_ADDR, FA_RISC_CODE_ADDR_81 };
640642 const uint32_t def_boot[] =
....@@ -664,20 +666,14 @@
664666 const uint32_t fcp_prio_cfg1[] =
665667 { FA_FCP_PRIO1_ADDR, FA_FCP_PRIO1_ADDR_25,
666668 0 };
667
- uint32_t def;
668
- uint16_t *wptr;
669
+
670
+ struct qla_hw_data *ha = vha->hw;
671
+ uint32_t def = IS_QLA81XX(ha) ? 2 : IS_QLA25XX(ha) ? 1 : 0;
672
+ struct qla_flt_header *flt = ha->flt;
673
+ struct qla_flt_region *region = &flt->region[0];
674
+ __le16 *wptr;
669675 uint16_t cnt, chksum;
670676 uint32_t start;
671
- struct qla_flt_header *flt;
672
- struct qla_flt_region *region;
673
- struct qla_hw_data *ha = vha->hw;
674
- struct req_que *req = ha->req_q_map[0];
675
-
676
- def = 0;
677
- if (IS_QLA25XX(ha))
678
- def = 1;
679
- else if (IS_QLA81XX(ha))
680
- def = 2;
681677
682678 /* Assign FCP prio region since older adapters may not have FLT, or
683679 FCP prio region in it's FLT.
....@@ -686,12 +682,11 @@
686682 fcp_prio_cfg0[def] : fcp_prio_cfg1[def];
687683
688684 ha->flt_region_flt = flt_addr;
689
- wptr = (uint16_t *)req->ring;
690
- flt = (struct qla_flt_header *)req->ring;
691
- region = (struct qla_flt_region *)&flt[1];
692
- ha->isp_ops->read_optrom(vha, (uint8_t *)req->ring,
693
- flt_addr << 2, OPTROM_BURST_SIZE);
694
- if (*wptr == cpu_to_le16(0xffff))
685
+ wptr = (__force __le16 *)ha->flt;
686
+ ha->isp_ops->read_optrom(vha, flt, flt_addr << 2,
687
+ (sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE));
688
+
689
+ if (le16_to_cpu(*wptr) == 0xffff)
695690 goto no_flash_data;
696691 if (flt->version != cpu_to_le16(1)) {
697692 ql_log(ql_log_warn, vha, 0x0047,
....@@ -701,7 +696,7 @@
701696 goto no_flash_data;
702697 }
703698
704
- cnt = (sizeof(struct qla_flt_header) + le16_to_cpu(flt->length)) >> 1;
699
+ cnt = (sizeof(*flt) + le16_to_cpu(flt->length)) / sizeof(*wptr);
705700 for (chksum = 0; cnt--; wptr++)
706701 chksum += le16_to_cpu(*wptr);
707702 if (chksum) {
....@@ -712,18 +707,20 @@
712707 goto no_flash_data;
713708 }
714709
715
- loc = locations[1];
716
- cnt = le16_to_cpu(flt->length) / sizeof(struct qla_flt_region);
710
+ cnt = le16_to_cpu(flt->length) / sizeof(*region);
717711 for ( ; cnt; cnt--, region++) {
718712 /* Store addresses as DWORD offsets. */
719713 start = le32_to_cpu(region->start) >> 2;
720714 ql_dbg(ql_dbg_init, vha, 0x0049,
721
- "FLT[%02x]: start=0x%x "
722
- "end=0x%x size=0x%x.\n", le32_to_cpu(region->code) & 0xff,
723
- start, le32_to_cpu(region->end) >> 2,
724
- le32_to_cpu(region->size));
715
+ "FLT[%#x]: start=%#x end=%#x size=%#x.\n",
716
+ le16_to_cpu(region->code), start,
717
+ le32_to_cpu(region->end) >> 2,
718
+ le32_to_cpu(region->size) >> 2);
719
+ if (region->attribute)
720
+ ql_log(ql_dbg_init, vha, 0xffff,
721
+ "Region %x is secure\n", region->code);
725722
726
- switch (le32_to_cpu(region->code) & 0xff) {
723
+ switch (le16_to_cpu(region->code)) {
727724 case FLT_REG_FCOE_FW:
728725 if (!IS_QLA8031(ha))
729726 break;
....@@ -753,13 +750,13 @@
753750 ha->flt_region_vpd = start;
754751 break;
755752 case FLT_REG_VPD_2:
756
- if (!IS_QLA27XX(ha))
753
+ if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
757754 break;
758755 if (ha->port_no == 2)
759756 ha->flt_region_vpd = start;
760757 break;
761758 case FLT_REG_VPD_3:
762
- if (!IS_QLA27XX(ha))
759
+ if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
763760 break;
764761 if (ha->port_no == 3)
765762 ha->flt_region_vpd = start;
....@@ -777,13 +774,13 @@
777774 ha->flt_region_nvram = start;
778775 break;
779776 case FLT_REG_NVRAM_2:
780
- if (!IS_QLA27XX(ha))
777
+ if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
781778 break;
782779 if (ha->port_no == 2)
783780 ha->flt_region_nvram = start;
784781 break;
785782 case FLT_REG_NVRAM_3:
786
- if (!IS_QLA27XX(ha))
783
+ if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
787784 break;
788785 if (ha->port_no == 3)
789786 ha->flt_region_nvram = start;
....@@ -847,36 +844,74 @@
847844 ha->flt_region_nvram = start;
848845 break;
849846 case FLT_REG_IMG_PRI_27XX:
850
- if (IS_QLA27XX(ha))
847
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
851848 ha->flt_region_img_status_pri = start;
852849 break;
853850 case FLT_REG_IMG_SEC_27XX:
854
- if (IS_QLA27XX(ha))
851
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
855852 ha->flt_region_img_status_sec = start;
856853 break;
857854 case FLT_REG_FW_SEC_27XX:
858
- if (IS_QLA27XX(ha))
855
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
859856 ha->flt_region_fw_sec = start;
860857 break;
861858 case FLT_REG_BOOTLOAD_SEC_27XX:
862
- if (IS_QLA27XX(ha))
859
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
863860 ha->flt_region_boot_sec = start;
864861 break;
862
+ case FLT_REG_AUX_IMG_PRI_28XX:
863
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
864
+ ha->flt_region_aux_img_status_pri = start;
865
+ break;
866
+ case FLT_REG_AUX_IMG_SEC_28XX:
867
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
868
+ ha->flt_region_aux_img_status_sec = start;
869
+ break;
870
+ case FLT_REG_NVRAM_SEC_28XX_0:
871
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
872
+ if (ha->port_no == 0)
873
+ ha->flt_region_nvram_sec = start;
874
+ break;
875
+ case FLT_REG_NVRAM_SEC_28XX_1:
876
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
877
+ if (ha->port_no == 1)
878
+ ha->flt_region_nvram_sec = start;
879
+ break;
880
+ case FLT_REG_NVRAM_SEC_28XX_2:
881
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
882
+ if (ha->port_no == 2)
883
+ ha->flt_region_nvram_sec = start;
884
+ break;
885
+ case FLT_REG_NVRAM_SEC_28XX_3:
886
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
887
+ if (ha->port_no == 3)
888
+ ha->flt_region_nvram_sec = start;
889
+ break;
865890 case FLT_REG_VPD_SEC_27XX_0:
866
- if (IS_QLA27XX(ha))
867
- ha->flt_region_vpd_sec = start;
891
+ case FLT_REG_VPD_SEC_28XX_0:
892
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
893
+ ha->flt_region_vpd_nvram_sec = start;
894
+ if (ha->port_no == 0)
895
+ ha->flt_region_vpd_sec = start;
896
+ }
868897 break;
869898 case FLT_REG_VPD_SEC_27XX_1:
870
- if (IS_QLA27XX(ha))
871
- ha->flt_region_vpd_sec = start;
899
+ case FLT_REG_VPD_SEC_28XX_1:
900
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
901
+ if (ha->port_no == 1)
902
+ ha->flt_region_vpd_sec = start;
872903 break;
873904 case FLT_REG_VPD_SEC_27XX_2:
874
- if (IS_QLA27XX(ha))
875
- ha->flt_region_vpd_sec = start;
905
+ case FLT_REG_VPD_SEC_28XX_2:
906
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
907
+ if (ha->port_no == 2)
908
+ ha->flt_region_vpd_sec = start;
876909 break;
877910 case FLT_REG_VPD_SEC_27XX_3:
878
- if (IS_QLA27XX(ha))
879
- ha->flt_region_vpd_sec = start;
911
+ case FLT_REG_VPD_SEC_28XX_3:
912
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
913
+ if (ha->port_no == 3)
914
+ ha->flt_region_vpd_sec = start;
880915 break;
881916 }
882917 }
....@@ -912,22 +947,19 @@
912947 #define FLASH_BLK_SIZE_32K 0x8000
913948 #define FLASH_BLK_SIZE_64K 0x10000
914949 const char *loc, *locations[] = { "MID", "FDT" };
915
- uint16_t cnt, chksum;
916
- uint16_t *wptr;
917
- struct qla_fdt_layout *fdt;
918
- uint8_t man_id, flash_id;
919
- uint16_t mid = 0, fid = 0;
920950 struct qla_hw_data *ha = vha->hw;
921951 struct req_que *req = ha->req_q_map[0];
952
+ uint16_t cnt, chksum;
953
+ __le16 *wptr = (__force __le16 *)req->ring;
954
+ struct qla_fdt_layout *fdt = (struct qla_fdt_layout *)req->ring;
955
+ uint8_t man_id, flash_id;
956
+ uint16_t mid = 0, fid = 0;
922957
923
- wptr = (uint16_t *)req->ring;
924
- fdt = (struct qla_fdt_layout *)req->ring;
925
- ha->isp_ops->read_optrom(vha, (uint8_t *)req->ring,
926
- ha->flt_region_fdt << 2, OPTROM_BURST_SIZE);
927
- if (*wptr == cpu_to_le16(0xffff))
958
+ ha->isp_ops->read_optrom(vha, fdt, ha->flt_region_fdt << 2,
959
+ OPTROM_BURST_DWORDS);
960
+ if (le16_to_cpu(*wptr) == 0xffff)
928961 goto no_flash_data;
929
- if (fdt->sig[0] != 'Q' || fdt->sig[1] != 'L' || fdt->sig[2] != 'I' ||
930
- fdt->sig[3] != 'D')
962
+ if (memcmp(fdt->sig, "QLID", 4))
931963 goto no_flash_data;
932964
933965 for (cnt = 0, chksum = 0; cnt < sizeof(*fdt) >> 1; cnt++, wptr++)
....@@ -938,7 +970,7 @@
938970 " checksum=0x%x id=%c version0x%x.\n", chksum,
939971 fdt->sig[0], le16_to_cpu(fdt->version));
940972 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0113,
941
- (uint8_t *)fdt, sizeof(*fdt));
973
+ fdt, sizeof(*fdt));
942974 goto no_flash_data;
943975 }
944976
....@@ -958,7 +990,7 @@
958990 ha->fdt_unprotect_sec_cmd = flash_conf_addr(ha, 0x0300 |
959991 fdt->unprotect_sec_cmd);
960992 ha->fdt_protect_sec_cmd = fdt->protect_sec_cmd ?
961
- flash_conf_addr(ha, 0x0300 | fdt->protect_sec_cmd):
993
+ flash_conf_addr(ha, 0x0300 | fdt->protect_sec_cmd) :
962994 flash_conf_addr(ha, 0x0336);
963995 }
964996 goto done;
....@@ -1011,16 +1043,15 @@
10111043 qla2xxx_get_idc_param(scsi_qla_host_t *vha)
10121044 {
10131045 #define QLA82XX_IDC_PARAM_ADDR 0x003e885c
1014
- uint32_t *wptr;
1046
+ __le32 *wptr;
10151047 struct qla_hw_data *ha = vha->hw;
10161048 struct req_que *req = ha->req_q_map[0];
10171049
10181050 if (!(IS_P3P_TYPE(ha)))
10191051 return;
10201052
1021
- wptr = (uint32_t *)req->ring;
1022
- ha->isp_ops->read_optrom(vha, (uint8_t *)req->ring,
1023
- QLA82XX_IDC_PARAM_ADDR , 8);
1053
+ wptr = (__force __le32 *)req->ring;
1054
+ ha->isp_ops->read_optrom(vha, req->ring, QLA82XX_IDC_PARAM_ADDR, 8);
10241055
10251056 if (*wptr == cpu_to_le32(0xffffffff)) {
10261057 ha->fcoe_dev_init_timeout = QLA82XX_ROM_DEV_INIT_TIMEOUT;
....@@ -1045,7 +1076,8 @@
10451076 struct qla_hw_data *ha = vha->hw;
10461077
10471078 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
1048
- !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha) && !IS_QLA27XX(ha))
1079
+ !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha) &&
1080
+ !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
10491081 return QLA_SUCCESS;
10501082
10511083 ret = qla2xxx_find_flt_start(vha, &flt_addr);
....@@ -1064,7 +1096,7 @@
10641096 {
10651097 #define NPIV_CONFIG_SIZE (16*1024)
10661098 void *data;
1067
- uint16_t *wptr;
1099
+ __le16 *wptr;
10681100 uint16_t cnt, chksum;
10691101 int i;
10701102 struct qla_npiv_header hdr;
....@@ -1081,8 +1113,8 @@
10811113 if (IS_QLA8044(ha))
10821114 return;
10831115
1084
- ha->isp_ops->read_optrom(vha, (uint8_t *)&hdr,
1085
- ha->flt_region_npiv_conf << 2, sizeof(struct qla_npiv_header));
1116
+ ha->isp_ops->read_optrom(vha, &hdr, ha->flt_region_npiv_conf << 2,
1117
+ sizeof(struct qla_npiv_header));
10861118 if (hdr.version == cpu_to_le16(0xffff))
10871119 return;
10881120 if (hdr.version != cpu_to_le16(1)) {
....@@ -1101,8 +1133,8 @@
11011133 return;
11021134 }
11031135
1104
- ha->isp_ops->read_optrom(vha, (uint8_t *)data,
1105
- ha->flt_region_npiv_conf << 2, NPIV_CONFIG_SIZE);
1136
+ ha->isp_ops->read_optrom(vha, data, ha->flt_region_npiv_conf << 2,
1137
+ NPIV_CONFIG_SIZE);
11061138
11071139 cnt = (sizeof(hdr) + le16_to_cpu(hdr.entries) * sizeof(*entry)) >> 1;
11081140 for (wptr = data, chksum = 0; cnt--; wptr++)
....@@ -1139,10 +1171,8 @@
11391171 vid.node_name = wwn_to_u64(entry->node_name);
11401172
11411173 ql_dbg(ql_dbg_user, vha, 0x7093,
1142
- "NPIV[%02x]: wwpn=%llx "
1143
- "wwnn=%llx vf_id=0x%x Q_qos=0x%x F_qos=0x%x.\n", cnt,
1144
- (unsigned long long)vid.port_name,
1145
- (unsigned long long)vid.node_name,
1174
+ "NPIV[%02x]: wwpn=%llx wwnn=%llx vf_id=%#x Q_qos=%#x F_qos=%#x.\n",
1175
+ cnt, vid.port_name, vid.node_name,
11461176 le16_to_cpu(entry->vf_id),
11471177 entry->q_qos, entry->f_qos);
11481178
....@@ -1150,10 +1180,8 @@
11501180 vport = fc_vport_create(vha->host, 0, &vid);
11511181 if (!vport)
11521182 ql_log(ql_log_warn, vha, 0x7094,
1153
- "NPIV-Config Failed to create vport [%02x]: "
1154
- "wwpn=%llx wwnn=%llx.\n", cnt,
1155
- (unsigned long long)vid.port_name,
1156
- (unsigned long long)vid.node_name);
1183
+ "NPIV-Config Failed to create vport [%02x]: wwpn=%llx wwnn=%llx.\n",
1184
+ cnt, vid.port_name, vid.node_name);
11571185 }
11581186 }
11591187 done:
....@@ -1170,9 +1198,9 @@
11701198 return qla81xx_fac_do_write_enable(vha, 1);
11711199
11721200 /* Enable flash write. */
1173
- WRT_REG_DWORD(&reg->ctrl_status,
1174
- RD_REG_DWORD(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
1175
- RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
1201
+ wrt_reg_dword(&reg->ctrl_status,
1202
+ rd_reg_dword(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
1203
+ rd_reg_dword(&reg->ctrl_status); /* PCI Posting. */
11761204
11771205 if (!ha->fdt_wrt_disable)
11781206 goto done;
....@@ -1188,9 +1216,10 @@
11881216 static int
11891217 qla24xx_protect_flash(scsi_qla_host_t *vha)
11901218 {
1191
- uint32_t cnt;
11921219 struct qla_hw_data *ha = vha->hw;
11931220 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1221
+ ulong cnt = 300;
1222
+ uint32_t faddr, dword;
11941223
11951224 if (ha->flags.fac_supported)
11961225 return qla81xx_fac_do_write_enable(vha, 0);
....@@ -1199,19 +1228,21 @@
11991228 goto skip_wrt_protect;
12001229
12011230 /* Enable flash write-protection and wait for completion. */
1202
- qla24xx_write_flash_dword(ha, flash_conf_addr(ha, 0x101),
1203
- ha->fdt_wrt_disable);
1204
- for (cnt = 300; cnt &&
1205
- qla24xx_read_flash_dword(ha, flash_conf_addr(ha, 0x005)) & BIT_0;
1206
- cnt--) {
1231
+ faddr = flash_conf_addr(ha, 0x101);
1232
+ qla24xx_write_flash_dword(ha, faddr, ha->fdt_wrt_disable);
1233
+ faddr = flash_conf_addr(ha, 0x5);
1234
+ while (cnt--) {
1235
+ if (!qla24xx_read_flash_dword(ha, faddr, &dword)) {
1236
+ if (!(dword & BIT_0))
1237
+ break;
1238
+ }
12071239 udelay(10);
12081240 }
12091241
12101242 skip_wrt_protect:
12111243 /* Disable flash write. */
1212
- WRT_REG_DWORD(&reg->ctrl_status,
1213
- RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
1214
- RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
1244
+ wrt_reg_dword(&reg->ctrl_status,
1245
+ rd_reg_dword(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
12151246
12161247 return QLA_SUCCESS;
12171248 }
....@@ -1235,111 +1266,107 @@
12351266 }
12361267
12371268 static int
1238
-qla24xx_write_flash_data(scsi_qla_host_t *vha, uint32_t *dwptr, uint32_t faddr,
1269
+qla24xx_write_flash_data(scsi_qla_host_t *vha, __le32 *dwptr, uint32_t faddr,
12391270 uint32_t dwords)
12401271 {
12411272 int ret;
1242
- uint32_t liter;
1243
- uint32_t sec_mask, rest_addr;
1244
- uint32_t fdata;
1273
+ ulong liter;
1274
+ ulong dburst = OPTROM_BURST_DWORDS; /* burst size in dwords */
1275
+ uint32_t sec_mask, rest_addr, fdata;
12451276 dma_addr_t optrom_dma;
12461277 void *optrom = NULL;
12471278 struct qla_hw_data *ha = vha->hw;
12481279
1249
- /* Prepare burst-capable write on supported ISPs. */
1250
- if ((IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
1251
- IS_QLA27XX(ha)) &&
1252
- !(faddr & 0xfff) && dwords > OPTROM_BURST_DWORDS) {
1253
- optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
1254
- &optrom_dma, GFP_KERNEL);
1255
- if (!optrom) {
1256
- ql_log(ql_log_warn, vha, 0x7095,
1257
- "Unable to allocate "
1258
- "memory for optrom burst write (%x KB).\n",
1259
- OPTROM_BURST_SIZE / 1024);
1260
- }
1280
+ if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
1281
+ !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1282
+ goto next;
1283
+
1284
+ /* Allocate dma buffer for burst write */
1285
+ optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
1286
+ &optrom_dma, GFP_KERNEL);
1287
+ if (!optrom) {
1288
+ ql_log(ql_log_warn, vha, 0x7095,
1289
+ "Failed allocate burst (%x bytes)\n", OPTROM_BURST_SIZE);
1290
+ }
1291
+
1292
+next:
1293
+ ql_log(ql_log_warn + ql_dbg_verbose, vha, 0x7095,
1294
+ "Unprotect flash...\n");
1295
+ ret = qla24xx_unprotect_flash(vha);
1296
+ if (ret) {
1297
+ ql_log(ql_log_warn, vha, 0x7096,
1298
+ "Failed to unprotect flash.\n");
1299
+ goto done;
12611300 }
12621301
12631302 rest_addr = (ha->fdt_block_size >> 2) - 1;
12641303 sec_mask = ~rest_addr;
1265
-
1266
- ret = qla24xx_unprotect_flash(vha);
1267
- if (ret != QLA_SUCCESS) {
1268
- ql_log(ql_log_warn, vha, 0x7096,
1269
- "Unable to unprotect flash for update.\n");
1270
- goto done;
1271
- }
1272
-
12731304 for (liter = 0; liter < dwords; liter++, faddr++, dwptr++) {
12741305 fdata = (faddr & sec_mask) << 2;
12751306
12761307 /* Are we at the beginning of a sector? */
1277
- if ((faddr & rest_addr) == 0) {
1278
- /* Do sector unprotect. */
1279
- if (ha->fdt_unprotect_sec_cmd)
1280
- qla24xx_write_flash_dword(ha,
1281
- ha->fdt_unprotect_sec_cmd,
1282
- (fdata & 0xff00) | ((fdata << 16) &
1283
- 0xff0000) | ((fdata >> 16) & 0xff));
1308
+ if (!(faddr & rest_addr)) {
1309
+ ql_log(ql_log_warn + ql_dbg_verbose, vha, 0x7095,
1310
+ "Erase sector %#x...\n", faddr);
1311
+
12841312 ret = qla24xx_erase_sector(vha, fdata);
1285
- if (ret != QLA_SUCCESS) {
1313
+ if (ret) {
12861314 ql_dbg(ql_dbg_user, vha, 0x7007,
1287
- "Unable to erase erase sector: address=%x.\n",
1288
- faddr);
1315
+ "Failed to erase sector %x.\n", faddr);
12891316 break;
12901317 }
12911318 }
12921319
1293
- /* Go with burst-write. */
1294
- if (optrom && (liter + OPTROM_BURST_DWORDS) <= dwords) {
1295
- /* Copy data to DMA'ble buffer. */
1296
- memcpy(optrom, dwptr, OPTROM_BURST_SIZE);
1320
+ if (optrom) {
1321
+ /* If smaller than a burst remaining */
1322
+ if (dwords - liter < dburst)
1323
+ dburst = dwords - liter;
12971324
1325
+ /* Copy to dma buffer */
1326
+ memcpy(optrom, dwptr, dburst << 2);
1327
+
1328
+ /* Burst write */
1329
+ ql_log(ql_log_warn + ql_dbg_verbose, vha, 0x7095,
1330
+ "Write burst (%#lx dwords)...\n", dburst);
12981331 ret = qla2x00_load_ram(vha, optrom_dma,
1299
- flash_data_addr(ha, faddr),
1300
- OPTROM_BURST_DWORDS);
1301
- if (ret != QLA_SUCCESS) {
1302
- ql_log(ql_log_warn, vha, 0x7097,
1303
- "Unable to burst-write optrom segment "
1304
- "(%x/%x/%llx).\n", ret,
1305
- flash_data_addr(ha, faddr),
1306
- (unsigned long long)optrom_dma);
1307
- ql_log(ql_log_warn, vha, 0x7098,
1308
- "Reverting to slow-write.\n");
1309
-
1310
- dma_free_coherent(&ha->pdev->dev,
1311
- OPTROM_BURST_SIZE, optrom, optrom_dma);
1312
- optrom = NULL;
1313
- } else {
1314
- liter += OPTROM_BURST_DWORDS - 1;
1315
- faddr += OPTROM_BURST_DWORDS - 1;
1316
- dwptr += OPTROM_BURST_DWORDS - 1;
1332
+ flash_data_addr(ha, faddr), dburst);
1333
+ if (!ret) {
1334
+ liter += dburst - 1;
1335
+ faddr += dburst - 1;
1336
+ dwptr += dburst - 1;
13171337 continue;
13181338 }
1339
+
1340
+ ql_log(ql_log_warn, vha, 0x7097,
1341
+ "Failed burst-write at %x (%p/%#llx)....\n",
1342
+ flash_data_addr(ha, faddr), optrom,
1343
+ (u64)optrom_dma);
1344
+
1345
+ dma_free_coherent(&ha->pdev->dev,
1346
+ OPTROM_BURST_SIZE, optrom, optrom_dma);
1347
+ optrom = NULL;
1348
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
1349
+ break;
1350
+ ql_log(ql_log_warn, vha, 0x7098,
1351
+ "Reverting to slow write...\n");
13191352 }
13201353
1354
+ /* Slow write */
13211355 ret = qla24xx_write_flash_dword(ha,
1322
- flash_data_addr(ha, faddr), cpu_to_le32(*dwptr));
1323
- if (ret != QLA_SUCCESS) {
1356
+ flash_data_addr(ha, faddr), le32_to_cpu(*dwptr));
1357
+ if (ret) {
13241358 ql_dbg(ql_dbg_user, vha, 0x7006,
1325
- "Unable to program flash address=%x data=%x.\n",
1326
- faddr, *dwptr);
1359
+ "Failed slow write %x (%x)\n", faddr, *dwptr);
13271360 break;
13281361 }
1329
-
1330
- /* Do sector protect. */
1331
- if (ha->fdt_unprotect_sec_cmd &&
1332
- ((faddr & rest_addr) == rest_addr))
1333
- qla24xx_write_flash_dword(ha,
1334
- ha->fdt_protect_sec_cmd,
1335
- (fdata & 0xff00) | ((fdata << 16) &
1336
- 0xff0000) | ((fdata >> 16) & 0xff));
13371362 }
13381363
1364
+ ql_log(ql_log_warn + ql_dbg_verbose, vha, 0x7095,
1365
+ "Protect flash...\n");
13391366 ret = qla24xx_protect_flash(vha);
1340
- if (ret != QLA_SUCCESS)
1367
+ if (ret)
13411368 ql_log(ql_log_warn, vha, 0x7099,
1342
- "Unable to protect flash after update.\n");
1369
+ "Failed to protect flash\n");
13431370 done:
13441371 if (optrom)
13451372 dma_free_coherent(&ha->pdev->dev,
....@@ -1349,15 +1376,15 @@
13491376 }
13501377
13511378 uint8_t *
1352
-qla2x00_read_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
1379
+qla2x00_read_nvram_data(scsi_qla_host_t *vha, void *buf, uint32_t naddr,
13531380 uint32_t bytes)
13541381 {
13551382 uint32_t i;
1356
- uint16_t *wptr;
1383
+ __le16 *wptr;
13571384 struct qla_hw_data *ha = vha->hw;
13581385
13591386 /* Word reads to NVRAM via registers. */
1360
- wptr = (uint16_t *)buf;
1387
+ wptr = buf;
13611388 qla2x00_lock_nvram_access(ha);
13621389 for (i = 0; i < bytes >> 1; i++, naddr++)
13631390 wptr[i] = cpu_to_le16(qla2x00_get_nvram_word(ha,
....@@ -1368,27 +1395,30 @@
13681395 }
13691396
13701397 uint8_t *
1371
-qla24xx_read_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
1398
+qla24xx_read_nvram_data(scsi_qla_host_t *vha, void *buf, uint32_t naddr,
13721399 uint32_t bytes)
13731400 {
1374
- uint32_t i;
1375
- uint32_t *dwptr;
13761401 struct qla_hw_data *ha = vha->hw;
1402
+ uint32_t *dwptr = buf;
1403
+ uint32_t i;
13771404
13781405 if (IS_P3P_TYPE(ha))
13791406 return buf;
13801407
13811408 /* Dword reads to flash. */
1382
- dwptr = (uint32_t *)buf;
1383
- for (i = 0; i < bytes >> 2; i++, naddr++)
1384
- dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
1385
- nvram_data_addr(ha, naddr)));
1409
+ naddr = nvram_data_addr(ha, naddr);
1410
+ bytes >>= 2;
1411
+ for (i = 0; i < bytes; i++, naddr++, dwptr++) {
1412
+ if (qla24xx_read_flash_dword(ha, naddr, dwptr))
1413
+ break;
1414
+ cpu_to_le32s(dwptr);
1415
+ }
13861416
13871417 return buf;
13881418 }
13891419
13901420 int
1391
-qla2x00_write_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
1421
+qla2x00_write_nvram_data(scsi_qla_host_t *vha, void *buf, uint32_t naddr,
13921422 uint32_t bytes)
13931423 {
13941424 int ret, stat;
....@@ -1422,14 +1452,14 @@
14221452 }
14231453
14241454 int
1425
-qla24xx_write_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
1455
+qla24xx_write_nvram_data(scsi_qla_host_t *vha, void *buf, uint32_t naddr,
14261456 uint32_t bytes)
14271457 {
1428
- int ret;
1429
- uint32_t i;
1430
- uint32_t *dwptr;
14311458 struct qla_hw_data *ha = vha->hw;
14321459 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1460
+ __le32 *dwptr = buf;
1461
+ uint32_t i;
1462
+ int ret;
14331463
14341464 ret = QLA_SUCCESS;
14351465
....@@ -1437,20 +1467,19 @@
14371467 return ret;
14381468
14391469 /* Enable flash write. */
1440
- WRT_REG_DWORD(&reg->ctrl_status,
1441
- RD_REG_DWORD(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
1442
- RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
1470
+ wrt_reg_dword(&reg->ctrl_status,
1471
+ rd_reg_dword(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
1472
+ rd_reg_dword(&reg->ctrl_status); /* PCI Posting. */
14431473
14441474 /* Disable NVRAM write-protection. */
14451475 qla24xx_write_flash_dword(ha, nvram_conf_addr(ha, 0x101), 0);
14461476 qla24xx_write_flash_dword(ha, nvram_conf_addr(ha, 0x101), 0);
14471477
14481478 /* Dword writes to flash. */
1449
- dwptr = (uint32_t *)buf;
1450
- for (i = 0; i < bytes >> 2; i++, naddr++, dwptr++) {
1451
- ret = qla24xx_write_flash_dword(ha,
1452
- nvram_data_addr(ha, naddr), cpu_to_le32(*dwptr));
1453
- if (ret != QLA_SUCCESS) {
1479
+ naddr = nvram_data_addr(ha, naddr);
1480
+ bytes >>= 2;
1481
+ for (i = 0; i < bytes; i++, naddr++, dwptr++) {
1482
+ if (qla24xx_write_flash_dword(ha, naddr, le32_to_cpu(*dwptr))) {
14541483 ql_dbg(ql_dbg_user, vha, 0x709a,
14551484 "Unable to program nvram address=%x data=%x.\n",
14561485 naddr, *dwptr);
....@@ -1462,39 +1491,42 @@
14621491 qla24xx_write_flash_dword(ha, nvram_conf_addr(ha, 0x101), 0x8c);
14631492
14641493 /* Disable flash write. */
1465
- WRT_REG_DWORD(&reg->ctrl_status,
1466
- RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
1467
- RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
1494
+ wrt_reg_dword(&reg->ctrl_status,
1495
+ rd_reg_dword(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
1496
+ rd_reg_dword(&reg->ctrl_status); /* PCI Posting. */
14681497
14691498 return ret;
14701499 }
14711500
14721501 uint8_t *
1473
-qla25xx_read_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
1502
+qla25xx_read_nvram_data(scsi_qla_host_t *vha, void *buf, uint32_t naddr,
14741503 uint32_t bytes)
14751504 {
1476
- uint32_t i;
1477
- uint32_t *dwptr;
14781505 struct qla_hw_data *ha = vha->hw;
1506
+ uint32_t *dwptr = buf;
1507
+ uint32_t i;
14791508
14801509 /* Dword reads to flash. */
1481
- dwptr = (uint32_t *)buf;
1482
- for (i = 0; i < bytes >> 2; i++, naddr++)
1483
- dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
1484
- flash_data_addr(ha, ha->flt_region_vpd_nvram | naddr)));
1510
+ naddr = flash_data_addr(ha, ha->flt_region_vpd_nvram | naddr);
1511
+ bytes >>= 2;
1512
+ for (i = 0; i < bytes; i++, naddr++, dwptr++) {
1513
+ if (qla24xx_read_flash_dword(ha, naddr, dwptr))
1514
+ break;
1515
+
1516
+ cpu_to_le32s(dwptr);
1517
+ }
14851518
14861519 return buf;
14871520 }
14881521
1522
+#define RMW_BUFFER_SIZE (64 * 1024)
14891523 int
1490
-qla25xx_write_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
1524
+qla25xx_write_nvram_data(scsi_qla_host_t *vha, void *buf, uint32_t naddr,
14911525 uint32_t bytes)
14921526 {
14931527 struct qla_hw_data *ha = vha->hw;
1494
-#define RMW_BUFFER_SIZE (64 * 1024)
1495
- uint8_t *dbuf;
1528
+ uint8_t *dbuf = vmalloc(RMW_BUFFER_SIZE);
14961529
1497
- dbuf = vmalloc(RMW_BUFFER_SIZE);
14981530 if (!dbuf)
14991531 return QLA_MEMORY_ALLOC_FAILED;
15001532 ha->isp_ops->read_optrom(vha, dbuf, ha->flt_region_vpd_nvram << 2,
....@@ -1557,8 +1589,8 @@
15571589 gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
15581590 gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
15591591 } else {
1560
- gpio_enable = RD_REG_WORD(&reg->gpioe);
1561
- gpio_data = RD_REG_WORD(&reg->gpiod);
1592
+ gpio_enable = rd_reg_word(&reg->gpioe);
1593
+ gpio_data = rd_reg_word(&reg->gpiod);
15621594 }
15631595
15641596 /* Set the modified gpio_enable values */
....@@ -1567,8 +1599,8 @@
15671599 if (ha->pio_address) {
15681600 WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
15691601 } else {
1570
- WRT_REG_WORD(&reg->gpioe, gpio_enable);
1571
- RD_REG_WORD(&reg->gpioe);
1602
+ wrt_reg_word(&reg->gpioe, gpio_enable);
1603
+ rd_reg_word(&reg->gpioe);
15721604 }
15731605
15741606 qla2x00_flip_colors(ha, &led_color);
....@@ -1583,8 +1615,8 @@
15831615 if (ha->pio_address) {
15841616 WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
15851617 } else {
1586
- WRT_REG_WORD(&reg->gpiod, gpio_data);
1587
- RD_REG_WORD(&reg->gpiod);
1618
+ wrt_reg_word(&reg->gpiod, gpio_data);
1619
+ rd_reg_word(&reg->gpiod);
15881620 }
15891621
15901622 spin_unlock_irqrestore(&ha->hardware_lock, flags);
....@@ -1614,8 +1646,8 @@
16141646 gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
16151647 gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
16161648 } else {
1617
- gpio_enable = RD_REG_WORD(&reg->gpioe);
1618
- gpio_data = RD_REG_WORD(&reg->gpiod);
1649
+ gpio_enable = rd_reg_word(&reg->gpioe);
1650
+ gpio_data = rd_reg_word(&reg->gpiod);
16191651 }
16201652 gpio_enable |= GPIO_LED_MASK;
16211653
....@@ -1623,8 +1655,8 @@
16231655 if (ha->pio_address) {
16241656 WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
16251657 } else {
1626
- WRT_REG_WORD(&reg->gpioe, gpio_enable);
1627
- RD_REG_WORD(&reg->gpioe);
1658
+ wrt_reg_word(&reg->gpioe, gpio_enable);
1659
+ rd_reg_word(&reg->gpioe);
16281660 }
16291661
16301662 /* Clear out previously set LED colour. */
....@@ -1632,8 +1664,8 @@
16321664 if (ha->pio_address) {
16331665 WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
16341666 } else {
1635
- WRT_REG_WORD(&reg->gpiod, gpio_data);
1636
- RD_REG_WORD(&reg->gpiod);
1667
+ wrt_reg_word(&reg->gpiod, gpio_data);
1668
+ rd_reg_word(&reg->gpiod);
16371669 }
16381670 spin_unlock_irqrestore(&ha->hardware_lock, flags);
16391671
....@@ -1700,13 +1732,13 @@
17001732
17011733 /* Save the Original GPIOD. */
17021734 spin_lock_irqsave(&ha->hardware_lock, flags);
1703
- gpio_data = RD_REG_DWORD(&reg->gpiod);
1735
+ gpio_data = rd_reg_dword(&reg->gpiod);
17041736
17051737 /* Enable the gpio_data reg for update. */
17061738 gpio_data |= GPDX_LED_UPDATE_MASK;
17071739
1708
- WRT_REG_DWORD(&reg->gpiod, gpio_data);
1709
- gpio_data = RD_REG_DWORD(&reg->gpiod);
1740
+ wrt_reg_dword(&reg->gpiod, gpio_data);
1741
+ gpio_data = rd_reg_dword(&reg->gpiod);
17101742
17111743 /* Set the color bits. */
17121744 qla24xx_flip_colors(ha, &led_color);
....@@ -1718,8 +1750,8 @@
17181750 gpio_data |= led_color;
17191751
17201752 /* Set the modified gpio_data values. */
1721
- WRT_REG_DWORD(&reg->gpiod, gpio_data);
1722
- gpio_data = RD_REG_DWORD(&reg->gpiod);
1753
+ wrt_reg_dword(&reg->gpiod, gpio_data);
1754
+ gpio_data = rd_reg_dword(&reg->gpiod);
17231755 spin_unlock_irqrestore(&ha->hardware_lock, flags);
17241756 }
17251757
....@@ -1728,7 +1760,7 @@
17281760 {
17291761 uint32_t led_select_value = 0;
17301762
1731
- if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
1763
+ if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
17321764 goto out;
17331765
17341766 if (ha->port_no == 0)
....@@ -1749,13 +1781,14 @@
17491781 uint16_t orig_led_cfg[6];
17501782 uint32_t led_10_value, led_43_value;
17511783
1752
- if (!IS_QLA83XX(ha) && !IS_QLA81XX(ha) && !IS_QLA27XX(ha))
1784
+ if (!IS_QLA83XX(ha) && !IS_QLA81XX(ha) && !IS_QLA27XX(ha) &&
1785
+ !IS_QLA28XX(ha))
17531786 return;
17541787
17551788 if (!ha->beacon_blink_led)
17561789 return;
17571790
1758
- if (IS_QLA27XX(ha)) {
1791
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
17591792 qla2x00_write_ram_word(vha, 0x1003, 0x40000230);
17601793 qla2x00_write_ram_word(vha, 0x1004, 0x40000230);
17611794 } else if (IS_QLA2031(ha)) {
....@@ -1845,16 +1878,16 @@
18451878 return QLA_FUNCTION_FAILED;
18461879 }
18471880
1848
- if (IS_QLA2031(ha) || IS_QLA27XX(ha))
1881
+ if (IS_QLA2031(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
18491882 goto skip_gpio;
18501883
18511884 spin_lock_irqsave(&ha->hardware_lock, flags);
1852
- gpio_data = RD_REG_DWORD(&reg->gpiod);
1885
+ gpio_data = rd_reg_dword(&reg->gpiod);
18531886
18541887 /* Enable the gpio_data reg for update. */
18551888 gpio_data |= GPDX_LED_UPDATE_MASK;
1856
- WRT_REG_DWORD(&reg->gpiod, gpio_data);
1857
- RD_REG_DWORD(&reg->gpiod);
1889
+ wrt_reg_dword(&reg->gpiod, gpio_data);
1890
+ rd_reg_dword(&reg->gpiod);
18581891
18591892 spin_unlock_irqrestore(&ha->hardware_lock, flags);
18601893 }
....@@ -1885,7 +1918,7 @@
18851918
18861919 ha->beacon_blink_led = 0;
18871920
1888
- if (IS_QLA2031(ha) || IS_QLA27XX(ha))
1921
+ if (IS_QLA2031(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
18891922 goto set_fw_options;
18901923
18911924 if (IS_QLA8031(ha) || IS_QLA81XX(ha))
....@@ -1897,12 +1930,12 @@
18971930
18981931 /* Give control back to firmware. */
18991932 spin_lock_irqsave(&ha->hardware_lock, flags);
1900
- gpio_data = RD_REG_DWORD(&reg->gpiod);
1933
+ gpio_data = rd_reg_dword(&reg->gpiod);
19011934
19021935 /* Disable the gpio_data reg for update. */
19031936 gpio_data &= ~GPDX_LED_UPDATE_MASK;
1904
- WRT_REG_DWORD(&reg->gpiod, gpio_data);
1905
- RD_REG_DWORD(&reg->gpiod);
1937
+ wrt_reg_dword(&reg->gpiod, gpio_data);
1938
+ rd_reg_dword(&reg->gpiod);
19061939 spin_unlock_irqrestore(&ha->hardware_lock, flags);
19071940
19081941 set_fw_options:
....@@ -1938,10 +1971,10 @@
19381971 uint16_t data;
19391972 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
19401973
1941
- data = RD_REG_WORD(&reg->ctrl_status);
1974
+ data = rd_reg_word(&reg->ctrl_status);
19421975 data |= CSR_FLASH_ENABLE;
1943
- WRT_REG_WORD(&reg->ctrl_status, data);
1944
- RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1976
+ wrt_reg_word(&reg->ctrl_status, data);
1977
+ rd_reg_word(&reg->ctrl_status); /* PCI Posting. */
19451978 }
19461979
19471980 /**
....@@ -1954,10 +1987,10 @@
19541987 uint16_t data;
19551988 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
19561989
1957
- data = RD_REG_WORD(&reg->ctrl_status);
1990
+ data = rd_reg_word(&reg->ctrl_status);
19581991 data &= ~(CSR_FLASH_ENABLE);
1959
- WRT_REG_WORD(&reg->ctrl_status, data);
1960
- RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1992
+ wrt_reg_word(&reg->ctrl_status, data);
1993
+ rd_reg_word(&reg->ctrl_status); /* PCI Posting. */
19611994 }
19621995
19631996 /**
....@@ -1976,7 +2009,7 @@
19762009 uint16_t bank_select;
19772010 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
19782011
1979
- bank_select = RD_REG_WORD(&reg->ctrl_status);
2012
+ bank_select = rd_reg_word(&reg->ctrl_status);
19802013
19812014 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
19822015 /* Specify 64K address range: */
....@@ -1984,11 +2017,11 @@
19842017 bank_select &= ~0xf8;
19852018 bank_select |= addr >> 12 & 0xf0;
19862019 bank_select |= CSR_FLASH_64K_BANK;
1987
- WRT_REG_WORD(&reg->ctrl_status, bank_select);
1988
- RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2020
+ wrt_reg_word(&reg->ctrl_status, bank_select);
2021
+ rd_reg_word(&reg->ctrl_status); /* PCI Posting. */
19892022
1990
- WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
1991
- data = RD_REG_WORD(&reg->flash_data);
2023
+ wrt_reg_word(&reg->flash_address, (uint16_t)addr);
2024
+ data = rd_reg_word(&reg->flash_data);
19922025
19932026 return (uint8_t)data;
19942027 }
....@@ -1996,13 +2029,13 @@
19962029 /* Setup bit 16 of flash address. */
19972030 if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
19982031 bank_select |= CSR_FLASH_64K_BANK;
1999
- WRT_REG_WORD(&reg->ctrl_status, bank_select);
2000
- RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2032
+ wrt_reg_word(&reg->ctrl_status, bank_select);
2033
+ rd_reg_word(&reg->ctrl_status); /* PCI Posting. */
20012034 } else if (((addr & BIT_16) == 0) &&
20022035 (bank_select & CSR_FLASH_64K_BANK)) {
20032036 bank_select &= ~(CSR_FLASH_64K_BANK);
2004
- WRT_REG_WORD(&reg->ctrl_status, bank_select);
2005
- RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2037
+ wrt_reg_word(&reg->ctrl_status, bank_select);
2038
+ rd_reg_word(&reg->ctrl_status); /* PCI Posting. */
20062039 }
20072040
20082041 /* Always perform IO mapped accesses to the FLASH registers. */
....@@ -2017,7 +2050,7 @@
20172050 data2 = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
20182051 } while (data != data2);
20192052 } else {
2020
- WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
2053
+ wrt_reg_word(&reg->flash_address, (uint16_t)addr);
20212054 data = qla2x00_debounce_register(&reg->flash_data);
20222055 }
20232056
....@@ -2036,20 +2069,20 @@
20362069 uint16_t bank_select;
20372070 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
20382071
2039
- bank_select = RD_REG_WORD(&reg->ctrl_status);
2072
+ bank_select = rd_reg_word(&reg->ctrl_status);
20402073 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
20412074 /* Specify 64K address range: */
20422075 /* clear out Module Select and Flash Address bits [19:16]. */
20432076 bank_select &= ~0xf8;
20442077 bank_select |= addr >> 12 & 0xf0;
20452078 bank_select |= CSR_FLASH_64K_BANK;
2046
- WRT_REG_WORD(&reg->ctrl_status, bank_select);
2047
- RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2079
+ wrt_reg_word(&reg->ctrl_status, bank_select);
2080
+ rd_reg_word(&reg->ctrl_status); /* PCI Posting. */
20482081
2049
- WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
2050
- RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2051
- WRT_REG_WORD(&reg->flash_data, (uint16_t)data);
2052
- RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2082
+ wrt_reg_word(&reg->flash_address, (uint16_t)addr);
2083
+ rd_reg_word(&reg->ctrl_status); /* PCI Posting. */
2084
+ wrt_reg_word(&reg->flash_data, (uint16_t)data);
2085
+ rd_reg_word(&reg->ctrl_status); /* PCI Posting. */
20532086
20542087 return;
20552088 }
....@@ -2057,13 +2090,13 @@
20572090 /* Setup bit 16 of flash address. */
20582091 if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
20592092 bank_select |= CSR_FLASH_64K_BANK;
2060
- WRT_REG_WORD(&reg->ctrl_status, bank_select);
2061
- RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2093
+ wrt_reg_word(&reg->ctrl_status, bank_select);
2094
+ rd_reg_word(&reg->ctrl_status); /* PCI Posting. */
20622095 } else if (((addr & BIT_16) == 0) &&
20632096 (bank_select & CSR_FLASH_64K_BANK)) {
20642097 bank_select &= ~(CSR_FLASH_64K_BANK);
2065
- WRT_REG_WORD(&reg->ctrl_status, bank_select);
2066
- RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2098
+ wrt_reg_word(&reg->ctrl_status, bank_select);
2099
+ rd_reg_word(&reg->ctrl_status); /* PCI Posting. */
20672100 }
20682101
20692102 /* Always perform IO mapped accesses to the FLASH registers. */
....@@ -2071,10 +2104,10 @@
20712104 WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
20722105 WRT_REG_WORD_PIO(PIO_REG(ha, flash_data), (uint16_t)data);
20732106 } else {
2074
- WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
2075
- RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2076
- WRT_REG_WORD(&reg->flash_data, (uint16_t)data);
2077
- RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2107
+ wrt_reg_word(&reg->flash_address, (uint16_t)addr);
2108
+ rd_reg_word(&reg->ctrl_status); /* PCI Posting. */
2109
+ wrt_reg_word(&reg->flash_data, (uint16_t)data);
2110
+ rd_reg_word(&reg->ctrl_status); /* PCI Posting. */
20782111 }
20792112 }
20802113
....@@ -2229,7 +2262,7 @@
22292262
22302263 /**
22312264 * qla2x00_get_flash_manufacturer() - Read manufacturer ID from flash chip.
2232
- * @ha:
2265
+ * @ha: host adapter
22332266 * @man_id: Flash manufacturer ID
22342267 * @flash_id: Flash ID
22352268 */
....@@ -2257,12 +2290,12 @@
22572290
22582291 midpoint = length / 2;
22592292
2260
- WRT_REG_WORD(&reg->nvram, 0);
2261
- RD_REG_WORD(&reg->nvram);
2293
+ wrt_reg_word(&reg->nvram, 0);
2294
+ rd_reg_word(&reg->nvram);
22622295 for (ilength = 0; ilength < length; saddr++, ilength++, tmp_buf++) {
22632296 if (ilength == midpoint) {
2264
- WRT_REG_WORD(&reg->nvram, NVR_SELECT);
2265
- RD_REG_WORD(&reg->nvram);
2297
+ wrt_reg_word(&reg->nvram, NVR_SELECT);
2298
+ rd_reg_word(&reg->nvram);
22662299 }
22672300 data = qla2x00_read_flash_byte(ha, saddr);
22682301 if (saddr % 100)
....@@ -2287,11 +2320,11 @@
22872320
22882321 /* Pause RISC. */
22892322 spin_lock_irqsave(&ha->hardware_lock, flags);
2290
- WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
2291
- RD_REG_WORD(&reg->hccr);
2323
+ wrt_reg_word(&reg->hccr, HCCR_PAUSE_RISC);
2324
+ rd_reg_word(&reg->hccr);
22922325 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
22932326 for (cnt = 0; cnt < 30000; cnt++) {
2294
- if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
2327
+ if ((rd_reg_word(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
22952328 break;
22962329 udelay(100);
22972330 }
....@@ -2314,8 +2347,8 @@
23142347 scsi_unblock_requests(vha->host);
23152348 }
23162349
2317
-uint8_t *
2318
-qla2x00_read_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
2350
+void *
2351
+qla2x00_read_optrom_data(struct scsi_qla_host *vha, void *buf,
23192352 uint32_t offset, uint32_t length)
23202353 {
23212354 uint32_t addr, midpoint;
....@@ -2330,12 +2363,12 @@
23302363 midpoint = ha->optrom_size / 2;
23312364
23322365 qla2x00_flash_enable(ha);
2333
- WRT_REG_WORD(&reg->nvram, 0);
2334
- RD_REG_WORD(&reg->nvram); /* PCI Posting. */
2366
+ wrt_reg_word(&reg->nvram, 0);
2367
+ rd_reg_word(&reg->nvram); /* PCI Posting. */
23352368 for (addr = offset, data = buf; addr < length; addr++, data++) {
23362369 if (addr == midpoint) {
2337
- WRT_REG_WORD(&reg->nvram, NVR_SELECT);
2338
- RD_REG_WORD(&reg->nvram); /* PCI Posting. */
2370
+ wrt_reg_word(&reg->nvram, NVR_SELECT);
2371
+ rd_reg_word(&reg->nvram); /* PCI Posting. */
23392372 }
23402373
23412374 *data = qla2x00_read_flash_byte(ha, addr);
....@@ -2349,12 +2382,12 @@
23492382 }
23502383
23512384 int
2352
-qla2x00_write_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
2385
+qla2x00_write_optrom_data(struct scsi_qla_host *vha, void *buf,
23532386 uint32_t offset, uint32_t length)
23542387 {
23552388
23562389 int rval;
2357
- uint8_t man_id, flash_id, sec_number, data;
2390
+ uint8_t man_id, flash_id, sec_number, *data;
23582391 uint16_t wd;
23592392 uint32_t addr, liter, sec_mask, rest_addr;
23602393 struct qla_hw_data *ha = vha->hw;
....@@ -2367,7 +2400,7 @@
23672400 sec_number = 0;
23682401
23692402 /* Reset ISP chip. */
2370
- WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
2403
+ wrt_reg_word(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
23712404 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
23722405
23732406 /* Go with write. */
....@@ -2423,7 +2456,7 @@
24232456 sec_mask = 0x10000;
24242457 break;
24252458 }
2426
- /* Fall through... */
2459
+ fallthrough;
24272460
24282461 case 0x1f: /* Atmel flash. */
24292462 /* 512k sector size. */
....@@ -2432,7 +2465,7 @@
24322465 sec_mask = 0x80000000;
24332466 break;
24342467 }
2435
- /* Fall through... */
2468
+ fallthrough;
24362469
24372470 case 0x01: /* AMD flash. */
24382471 if (flash_id == 0x38 || flash_id == 0x40 ||
....@@ -2465,7 +2498,7 @@
24652498 sec_mask = 0x1e000;
24662499 break;
24672500 }
2468
- /* fall through */
2501
+ fallthrough;
24692502 default:
24702503 /* Default to 16 kb sector size. */
24712504 rest_addr = 0x3fff;
....@@ -2483,7 +2516,7 @@
24832516
24842517 for (addr = offset, liter = 0; liter < length; liter++,
24852518 addr++) {
2486
- data = buf[liter];
2519
+ data = buf + liter;
24872520 /* Are we at the beginning of a sector? */
24882521 if ((addr & rest_addr) == 0) {
24892522 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
....@@ -2516,8 +2549,8 @@
25162549 }
25172550 }
25182551 } else if (addr == ha->optrom_size / 2) {
2519
- WRT_REG_WORD(&reg->nvram, NVR_SELECT);
2520
- RD_REG_WORD(&reg->nvram);
2552
+ wrt_reg_word(&reg->nvram, NVR_SELECT);
2553
+ rd_reg_word(&reg->nvram);
25212554 }
25222555
25232556 if (flash_id == 0xda && man_id == 0xc1) {
....@@ -2551,7 +2584,7 @@
25512584 }
25522585 }
25532586
2554
- if (qla2x00_program_flash_address(ha, addr, data,
2587
+ if (qla2x00_program_flash_address(ha, addr, *data,
25552588 man_id, flash_id)) {
25562589 rval = QLA_FUNCTION_FAILED;
25572590 break;
....@@ -2567,8 +2600,8 @@
25672600 return rval;
25682601 }
25692602
2570
-uint8_t *
2571
-qla24xx_read_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
2603
+void *
2604
+qla24xx_read_optrom_data(struct scsi_qla_host *vha, void *buf,
25722605 uint32_t offset, uint32_t length)
25732606 {
25742607 struct qla_hw_data *ha = vha->hw;
....@@ -2578,7 +2611,7 @@
25782611 set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
25792612
25802613 /* Go with read. */
2581
- qla24xx_read_flash_data(vha, (uint32_t *)buf, offset >> 2, length >> 2);
2614
+ qla24xx_read_flash_data(vha, buf, offset >> 2, length >> 2);
25822615
25832616 /* Resume HBA. */
25842617 clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
....@@ -2587,8 +2620,358 @@
25872620 return buf;
25882621 }
25892622
2623
+static int
2624
+qla28xx_extract_sfub_and_verify(struct scsi_qla_host *vha, uint32_t *buf,
2625
+ uint32_t len, uint32_t buf_size_without_sfub, uint8_t *sfub_buf)
2626
+{
2627
+ uint32_t *p, check_sum = 0;
2628
+ int i;
2629
+
2630
+ p = buf + buf_size_without_sfub;
2631
+
2632
+ /* Extract SFUB from end of file */
2633
+ memcpy(sfub_buf, (uint8_t *)p,
2634
+ sizeof(struct secure_flash_update_block));
2635
+
2636
+ for (i = 0; i < (sizeof(struct secure_flash_update_block) >> 2); i++)
2637
+ check_sum += p[i];
2638
+
2639
+ check_sum = (~check_sum) + 1;
2640
+
2641
+ if (check_sum != p[i]) {
2642
+ ql_log(ql_log_warn, vha, 0x7097,
2643
+ "SFUB checksum failed, 0x%x, 0x%x\n",
2644
+ check_sum, p[i]);
2645
+ return QLA_COMMAND_ERROR;
2646
+ }
2647
+
2648
+ return QLA_SUCCESS;
2649
+}
2650
+
2651
+static int
2652
+qla28xx_get_flash_region(struct scsi_qla_host *vha, uint32_t start,
2653
+ struct qla_flt_region *region)
2654
+{
2655
+ struct qla_hw_data *ha = vha->hw;
2656
+ struct qla_flt_header *flt = ha->flt;
2657
+ struct qla_flt_region *flt_reg = &flt->region[0];
2658
+ uint16_t cnt;
2659
+ int rval = QLA_FUNCTION_FAILED;
2660
+
2661
+ if (!ha->flt)
2662
+ return QLA_FUNCTION_FAILED;
2663
+
2664
+ cnt = le16_to_cpu(flt->length) / sizeof(struct qla_flt_region);
2665
+ for (; cnt; cnt--, flt_reg++) {
2666
+ if (le32_to_cpu(flt_reg->start) == start) {
2667
+ memcpy((uint8_t *)region, flt_reg,
2668
+ sizeof(struct qla_flt_region));
2669
+ rval = QLA_SUCCESS;
2670
+ break;
2671
+ }
2672
+ }
2673
+
2674
+ return rval;
2675
+}
2676
+
2677
+static int
2678
+qla28xx_write_flash_data(scsi_qla_host_t *vha, uint32_t *dwptr, uint32_t faddr,
2679
+ uint32_t dwords)
2680
+{
2681
+ struct qla_hw_data *ha = vha->hw;
2682
+ ulong liter;
2683
+ ulong dburst = OPTROM_BURST_DWORDS; /* burst size in dwords */
2684
+ uint32_t sec_mask, rest_addr, fdata;
2685
+ void *optrom = NULL;
2686
+ dma_addr_t optrom_dma;
2687
+ int rval, ret;
2688
+ struct secure_flash_update_block *sfub;
2689
+ dma_addr_t sfub_dma;
2690
+ uint32_t offset = faddr << 2;
2691
+ uint32_t buf_size_without_sfub = 0;
2692
+ struct qla_flt_region region;
2693
+ bool reset_to_rom = false;
2694
+ uint32_t risc_size, risc_attr = 0;
2695
+ __be32 *fw_array = NULL;
2696
+
2697
+ /* Retrieve region info - must be a start address passed in */
2698
+ rval = qla28xx_get_flash_region(vha, offset, &region);
2699
+
2700
+ if (rval != QLA_SUCCESS) {
2701
+ ql_log(ql_log_warn, vha, 0xffff,
2702
+ "Invalid address %x - not a region start address\n",
2703
+ offset);
2704
+ goto done;
2705
+ }
2706
+
2707
+ /* Allocate dma buffer for burst write */
2708
+ optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
2709
+ &optrom_dma, GFP_KERNEL);
2710
+ if (!optrom) {
2711
+ ql_log(ql_log_warn, vha, 0x7095,
2712
+ "Failed allocate burst (%x bytes)\n", OPTROM_BURST_SIZE);
2713
+ rval = QLA_COMMAND_ERROR;
2714
+ goto done;
2715
+ }
2716
+
2717
+ /*
2718
+ * If adapter supports secure flash and region is secure
2719
+ * extract secure flash update block (SFUB) and verify
2720
+ */
2721
+ if (ha->flags.secure_adapter && region.attribute) {
2722
+
2723
+ ql_log(ql_log_warn + ql_dbg_verbose, vha, 0xffff,
2724
+ "Region %x is secure\n", region.code);
2725
+
2726
+ switch (le16_to_cpu(region.code)) {
2727
+ case FLT_REG_FW:
2728
+ case FLT_REG_FW_SEC_27XX:
2729
+ case FLT_REG_MPI_PRI_28XX:
2730
+ case FLT_REG_MPI_SEC_28XX:
2731
+ fw_array = (__force __be32 *)dwptr;
2732
+
2733
+ /* 1st fw array */
2734
+ risc_size = be32_to_cpu(fw_array[3]);
2735
+ risc_attr = be32_to_cpu(fw_array[9]);
2736
+
2737
+ buf_size_without_sfub = risc_size;
2738
+ fw_array += risc_size;
2739
+
2740
+ /* 2nd fw array */
2741
+ risc_size = be32_to_cpu(fw_array[3]);
2742
+
2743
+ buf_size_without_sfub += risc_size;
2744
+ fw_array += risc_size;
2745
+
2746
+ /* 1st dump template */
2747
+ risc_size = be32_to_cpu(fw_array[2]);
2748
+
2749
+ /* skip header and ignore checksum */
2750
+ buf_size_without_sfub += risc_size;
2751
+ fw_array += risc_size;
2752
+
2753
+ if (risc_attr & BIT_9) {
2754
+ /* 2nd dump template */
2755
+ risc_size = be32_to_cpu(fw_array[2]);
2756
+
2757
+ /* skip header and ignore checksum */
2758
+ buf_size_without_sfub += risc_size;
2759
+ fw_array += risc_size;
2760
+ }
2761
+ break;
2762
+
2763
+ case FLT_REG_PEP_PRI_28XX:
2764
+ case FLT_REG_PEP_SEC_28XX:
2765
+ fw_array = (__force __be32 *)dwptr;
2766
+
2767
+ /* 1st fw array */
2768
+ risc_size = be32_to_cpu(fw_array[3]);
2769
+ risc_attr = be32_to_cpu(fw_array[9]);
2770
+
2771
+ buf_size_without_sfub = risc_size;
2772
+ fw_array += risc_size;
2773
+ break;
2774
+
2775
+ default:
2776
+ ql_log(ql_log_warn + ql_dbg_verbose, vha,
2777
+ 0xffff, "Secure region %x not supported\n",
2778
+ region.code);
2779
+ rval = QLA_COMMAND_ERROR;
2780
+ goto done;
2781
+ }
2782
+
2783
+ sfub = dma_alloc_coherent(&ha->pdev->dev,
2784
+ sizeof(struct secure_flash_update_block), &sfub_dma,
2785
+ GFP_KERNEL);
2786
+ if (!sfub) {
2787
+ ql_log(ql_log_warn, vha, 0xffff,
2788
+ "Unable to allocate memory for SFUB\n");
2789
+ rval = QLA_COMMAND_ERROR;
2790
+ goto done;
2791
+ }
2792
+
2793
+ rval = qla28xx_extract_sfub_and_verify(vha, dwptr, dwords,
2794
+ buf_size_without_sfub, (uint8_t *)sfub);
2795
+
2796
+ if (rval != QLA_SUCCESS)
2797
+ goto done;
2798
+
2799
+ ql_log(ql_log_warn + ql_dbg_verbose, vha, 0xffff,
2800
+ "SFUB extract and verify successful\n");
2801
+ }
2802
+
2803
+ rest_addr = (ha->fdt_block_size >> 2) - 1;
2804
+ sec_mask = ~rest_addr;
2805
+
2806
+ /* Lock semaphore */
2807
+ rval = qla81xx_fac_semaphore_access(vha, FAC_SEMAPHORE_LOCK);
2808
+ if (rval != QLA_SUCCESS) {
2809
+ ql_log(ql_log_warn, vha, 0xffff,
2810
+ "Unable to lock flash semaphore.");
2811
+ goto done;
2812
+ }
2813
+
2814
+ ql_log(ql_log_warn + ql_dbg_verbose, vha, 0x7095,
2815
+ "Unprotect flash...\n");
2816
+ rval = qla24xx_unprotect_flash(vha);
2817
+ if (rval) {
2818
+ qla81xx_fac_semaphore_access(vha, FAC_SEMAPHORE_UNLOCK);
2819
+ ql_log(ql_log_warn, vha, 0x7096, "Failed unprotect flash\n");
2820
+ goto done;
2821
+ }
2822
+
2823
+ for (liter = 0; liter < dwords; liter++, faddr++) {
2824
+ fdata = (faddr & sec_mask) << 2;
2825
+
2826
+ /* If start of sector */
2827
+ if (!(faddr & rest_addr)) {
2828
+ ql_log(ql_log_warn + ql_dbg_verbose, vha, 0x7095,
2829
+ "Erase sector %#x...\n", faddr);
2830
+ rval = qla24xx_erase_sector(vha, fdata);
2831
+ if (rval) {
2832
+ ql_dbg(ql_dbg_user, vha, 0x7007,
2833
+ "Failed erase sector %#x\n", faddr);
2834
+ goto write_protect;
2835
+ }
2836
+ }
2837
+ }
2838
+
2839
+ if (ha->flags.secure_adapter) {
2840
+ /*
2841
+ * If adapter supports secure flash but FW doesn't,
2842
+ * disable write protect, release semaphore and reset
2843
+ * chip to execute ROM code in order to update region securely
2844
+ */
2845
+ if (!ha->flags.secure_fw) {
2846
+ ql_log(ql_log_warn + ql_dbg_verbose, vha, 0xffff,
2847
+ "Disable Write and Release Semaphore.");
2848
+ rval = qla24xx_protect_flash(vha);
2849
+ if (rval != QLA_SUCCESS) {
2850
+ qla81xx_fac_semaphore_access(vha,
2851
+ FAC_SEMAPHORE_UNLOCK);
2852
+ ql_log(ql_log_warn, vha, 0xffff,
2853
+ "Unable to protect flash.");
2854
+ goto done;
2855
+ }
2856
+
2857
+ ql_log(ql_log_warn + ql_dbg_verbose, vha, 0xffff,
2858
+ "Reset chip to ROM.");
2859
+ set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2860
+ set_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags);
2861
+ qla2xxx_wake_dpc(vha);
2862
+ rval = qla2x00_wait_for_chip_reset(vha);
2863
+ if (rval != QLA_SUCCESS) {
2864
+ ql_log(ql_log_warn, vha, 0xffff,
2865
+ "Unable to reset to ROM code.");
2866
+ goto done;
2867
+ }
2868
+ reset_to_rom = true;
2869
+ ha->flags.fac_supported = 0;
2870
+
2871
+ ql_log(ql_log_warn + ql_dbg_verbose, vha, 0xffff,
2872
+ "Lock Semaphore");
2873
+ rval = qla2xxx_write_remote_register(vha,
2874
+ FLASH_SEMAPHORE_REGISTER_ADDR, 0x00020002);
2875
+ if (rval != QLA_SUCCESS) {
2876
+ ql_log(ql_log_warn, vha, 0xffff,
2877
+ "Unable to lock flash semaphore.");
2878
+ goto done;
2879
+ }
2880
+
2881
+ /* Unprotect flash */
2882
+ ql_log(ql_log_warn + ql_dbg_verbose, vha, 0xffff,
2883
+ "Enable Write.");
2884
+ rval = qla2x00_write_ram_word(vha, 0x7ffd0101, 0);
2885
+ if (rval) {
2886
+ ql_log(ql_log_warn, vha, 0x7096,
2887
+ "Failed unprotect flash\n");
2888
+ goto done;
2889
+ }
2890
+ }
2891
+
2892
+ /* If region is secure, send Secure Flash MB Cmd */
2893
+ if (region.attribute && buf_size_without_sfub) {
2894
+ ql_log(ql_log_warn + ql_dbg_verbose, vha, 0xffff,
2895
+ "Sending Secure Flash MB Cmd\n");
2896
+ rval = qla28xx_secure_flash_update(vha, 0,
2897
+ le16_to_cpu(region.code),
2898
+ buf_size_without_sfub, sfub_dma,
2899
+ sizeof(struct secure_flash_update_block) >> 2);
2900
+ if (rval != QLA_SUCCESS) {
2901
+ ql_log(ql_log_warn, vha, 0xffff,
2902
+ "Secure Flash MB Cmd failed %x.", rval);
2903
+ goto write_protect;
2904
+ }
2905
+ }
2906
+
2907
+ }
2908
+
2909
+ /* re-init flash offset */
2910
+ faddr = offset >> 2;
2911
+
2912
+ for (liter = 0; liter < dwords; liter++, faddr++, dwptr++) {
2913
+ fdata = (faddr & sec_mask) << 2;
2914
+
2915
+ /* If smaller than a burst remaining */
2916
+ if (dwords - liter < dburst)
2917
+ dburst = dwords - liter;
2918
+
2919
+ /* Copy to dma buffer */
2920
+ memcpy(optrom, dwptr, dburst << 2);
2921
+
2922
+ /* Burst write */
2923
+ ql_log(ql_log_warn + ql_dbg_verbose, vha, 0x7095,
2924
+ "Write burst (%#lx dwords)...\n", dburst);
2925
+ rval = qla2x00_load_ram(vha, optrom_dma,
2926
+ flash_data_addr(ha, faddr), dburst);
2927
+ if (rval != QLA_SUCCESS) {
2928
+ ql_log(ql_log_warn, vha, 0x7097,
2929
+ "Failed burst write at %x (%p/%#llx)...\n",
2930
+ flash_data_addr(ha, faddr), optrom,
2931
+ (u64)optrom_dma);
2932
+ break;
2933
+ }
2934
+
2935
+ liter += dburst - 1;
2936
+ faddr += dburst - 1;
2937
+ dwptr += dburst - 1;
2938
+ continue;
2939
+ }
2940
+
2941
+write_protect:
2942
+ ql_log(ql_log_warn + ql_dbg_verbose, vha, 0x7095,
2943
+ "Protect flash...\n");
2944
+ ret = qla24xx_protect_flash(vha);
2945
+ if (ret) {
2946
+ qla81xx_fac_semaphore_access(vha, FAC_SEMAPHORE_UNLOCK);
2947
+ ql_log(ql_log_warn, vha, 0x7099,
2948
+ "Failed protect flash\n");
2949
+ rval = QLA_COMMAND_ERROR;
2950
+ }
2951
+
2952
+ if (reset_to_rom == true) {
2953
+ /* Schedule DPC to restart the RISC */
2954
+ set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2955
+ qla2xxx_wake_dpc(vha);
2956
+
2957
+ ret = qla2x00_wait_for_hba_online(vha);
2958
+ if (ret != QLA_SUCCESS) {
2959
+ ql_log(ql_log_warn, vha, 0xffff,
2960
+ "Adapter did not come out of reset\n");
2961
+ rval = QLA_COMMAND_ERROR;
2962
+ }
2963
+ }
2964
+
2965
+done:
2966
+ if (optrom)
2967
+ dma_free_coherent(&ha->pdev->dev,
2968
+ OPTROM_BURST_SIZE, optrom, optrom_dma);
2969
+
2970
+ return rval;
2971
+}
2972
+
25902973 int
2591
-qla24xx_write_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
2974
+qla24xx_write_optrom_data(struct scsi_qla_host *vha, void *buf,
25922975 uint32_t offset, uint32_t length)
25932976 {
25942977 int rval;
....@@ -2599,8 +2982,12 @@
25992982 set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
26002983
26012984 /* Go with write. */
2602
- rval = qla24xx_write_flash_data(vha, (uint32_t *)buf, offset >> 2,
2603
- length >> 2);
2985
+ if (IS_QLA28XX(ha))
2986
+ rval = qla28xx_write_flash_data(vha, buf, offset >> 2,
2987
+ length >> 2);
2988
+ else
2989
+ rval = qla24xx_write_flash_data(vha, buf, offset >> 2,
2990
+ length >> 2);
26042991
26052992 clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
26062993 scsi_unblock_requests(vha->host);
....@@ -2608,8 +2995,8 @@
26082995 return rval;
26092996 }
26102997
2611
-uint8_t *
2612
-qla25xx_read_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
2998
+void *
2999
+qla25xx_read_optrom_data(struct scsi_qla_host *vha, void *buf,
26133000 uint32_t offset, uint32_t length)
26143001 {
26153002 int rval;
....@@ -2620,7 +3007,7 @@
26203007 struct qla_hw_data *ha = vha->hw;
26213008
26223009 if (IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
2623
- IS_QLA27XX(ha))
3010
+ IS_QLA27XX(ha) || IS_QLA28XX(ha))
26243011 goto try_fast;
26253012 if (offset & 0xfff)
26263013 goto slow_read;
....@@ -2628,6 +3015,8 @@
26283015 goto slow_read;
26293016
26303017 try_fast:
3018
+ if (offset & 0xff)
3019
+ goto slow_read;
26313020 optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
26323021 &optrom_dma, GFP_KERNEL);
26333022 if (!optrom) {
....@@ -2874,7 +3263,7 @@
28743263 "Dumping fw "
28753264 "ver from flash:.\n");
28763265 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010b,
2877
- (uint8_t *)dbyte, 8);
3266
+ dbyte, 32);
28783267
28793268 if ((dcode[0] == 0xffff && dcode[1] == 0xffff &&
28803269 dcode[2] == 0xffff && dcode[3] == 0xffff) ||
....@@ -2905,8 +3294,8 @@
29053294 {
29063295 int ret = QLA_SUCCESS;
29073296 uint32_t pcihdr, pcids;
2908
- uint32_t *dcode;
2909
- uint8_t *bcode;
3297
+ uint32_t *dcode = mbuf;
3298
+ uint8_t *bcode = mbuf;
29103299 uint8_t code_type, last_image;
29113300 struct qla_hw_data *ha = vha->hw;
29123301
....@@ -2918,17 +3307,14 @@
29183307 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
29193308 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
29203309
2921
- dcode = mbuf;
2922
-
29233310 /* Begin with first PCI expansion ROM header. */
29243311 pcihdr = ha->flt_region_boot << 2;
29253312 last_image = 1;
29263313 do {
29273314 /* Verify PCI expansion ROM header. */
2928
- ha->isp_ops->read_optrom(vha, (uint8_t *)dcode, pcihdr,
2929
- 0x20 * 4);
3315
+ ha->isp_ops->read_optrom(vha, dcode, pcihdr, 0x20 * 4);
29303316 bcode = mbuf + (pcihdr % 4);
2931
- if (bcode[0x0] != 0x55 || bcode[0x1] != 0xaa) {
3317
+ if (memcmp(bcode, "\x55\xaa", 2)) {
29323318 /* No signature */
29333319 ql_log(ql_log_fatal, vha, 0x0154,
29343320 "No matching ROM signature.\n");
....@@ -2939,13 +3325,11 @@
29393325 /* Locate PCI data structure. */
29403326 pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]);
29413327
2942
- ha->isp_ops->read_optrom(vha, (uint8_t *)dcode, pcids,
2943
- 0x20 * 4);
3328
+ ha->isp_ops->read_optrom(vha, dcode, pcids, 0x20 * 4);
29443329 bcode = mbuf + (pcihdr % 4);
29453330
29463331 /* Validate signature of PCI data structure. */
2947
- if (bcode[0x0] != 'P' || bcode[0x1] != 'C' ||
2948
- bcode[0x2] != 'I' || bcode[0x3] != 'R') {
3332
+ if (memcmp(bcode, "PCIR", 4)) {
29493333 /* Incorrect header. */
29503334 ql_log(ql_log_fatal, vha, 0x0155,
29513335 "PCI data struct not found pcir_adr=%x.\n", pcids);
....@@ -2996,8 +3380,7 @@
29963380 /* Read firmware image information. */
29973381 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
29983382 dcode = mbuf;
2999
- ha->isp_ops->read_optrom(vha, (uint8_t *)dcode, ha->flt_region_fw << 2,
3000
- 0x20);
3383
+ ha->isp_ops->read_optrom(vha, dcode, ha->flt_region_fw << 2, 0x20);
30013384 bcode = mbuf + (pcihdr % 4);
30023385
30033386 /* Validate signature of PCI data structure. */
....@@ -3019,15 +3402,14 @@
30193402 qla24xx_get_flash_version(scsi_qla_host_t *vha, void *mbuf)
30203403 {
30213404 int ret = QLA_SUCCESS;
3022
- uint32_t pcihdr, pcids;
3023
- uint32_t *dcode;
3024
- uint8_t *bcode;
3405
+ uint32_t pcihdr = 0, pcids = 0;
3406
+ uint32_t *dcode = mbuf;
3407
+ uint8_t *bcode = mbuf;
30253408 uint8_t code_type, last_image;
30263409 int i;
30273410 struct qla_hw_data *ha = vha->hw;
30283411 uint32_t faddr = 0;
3029
-
3030
- pcihdr = pcids = 0;
3412
+ struct active_regions active_regions = { };
30313413
30323414 if (IS_P3P_TYPE(ha))
30333415 return ret;
....@@ -3040,18 +3422,19 @@
30403422 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
30413423 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
30423424
3043
- dcode = mbuf;
30443425 pcihdr = ha->flt_region_boot << 2;
3045
- if (IS_QLA27XX(ha) &&
3046
- qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
3047
- pcihdr = ha->flt_region_boot_sec << 2;
3426
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3427
+ qla27xx_get_active_image(vha, &active_regions);
3428
+ if (active_regions.global == QLA27XX_SECONDARY_IMAGE) {
3429
+ pcihdr = ha->flt_region_boot_sec << 2;
3430
+ }
3431
+ }
30483432
3049
- last_image = 1;
30503433 do {
30513434 /* Verify PCI expansion ROM header. */
30523435 qla24xx_read_flash_data(vha, dcode, pcihdr >> 2, 0x20);
30533436 bcode = mbuf + (pcihdr % 4);
3054
- if (bcode[0x0] != 0x55 || bcode[0x1] != 0xaa) {
3437
+ if (memcmp(bcode, "\x55\xaa", 2)) {
30553438 /* No signature */
30563439 ql_log(ql_log_fatal, vha, 0x0059,
30573440 "No matching ROM signature.\n");
....@@ -3066,11 +3449,11 @@
30663449 bcode = mbuf + (pcihdr % 4);
30673450
30683451 /* Validate signature of PCI data structure. */
3069
- if (bcode[0x0] != 'P' || bcode[0x1] != 'C' ||
3070
- bcode[0x2] != 'I' || bcode[0x3] != 'R') {
3452
+ if (memcmp(bcode, "PCIR", 4)) {
30713453 /* Incorrect header. */
30723454 ql_log(ql_log_fatal, vha, 0x005a,
30733455 "PCI data struct not found pcir_adr=%x.\n", pcids);
3456
+ ql_dump_buffer(ql_dbg_init, vha, 0x0059, dcode, 32);
30743457 ret = QLA_FUNCTION_FAILED;
30753458 break;
30763459 }
....@@ -3117,30 +3500,25 @@
31173500
31183501 /* Read firmware image information. */
31193502 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
3120
- dcode = mbuf;
31213503 faddr = ha->flt_region_fw;
3122
- if (IS_QLA27XX(ha) &&
3123
- qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
3124
- faddr = ha->flt_region_fw_sec;
3504
+ if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3505
+ qla27xx_get_active_image(vha, &active_regions);
3506
+ if (active_regions.global == QLA27XX_SECONDARY_IMAGE)
3507
+ faddr = ha->flt_region_fw_sec;
3508
+ }
31253509
3126
- qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
3127
- for (i = 0; i < 4; i++)
3128
- dcode[i] = be32_to_cpu(dcode[i]);
3129
-
3130
- if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3131
- dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3132
- (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3133
- dcode[3] == 0)) {
3510
+ qla24xx_read_flash_data(vha, dcode, faddr, 8);
3511
+ if (qla24xx_risc_firmware_invalid(dcode)) {
31343512 ql_log(ql_log_warn, vha, 0x005f,
31353513 "Unrecognized fw revision at %x.\n",
31363514 ha->flt_region_fw * 4);
3515
+ ql_dump_buffer(ql_dbg_init, vha, 0x005f, dcode, 32);
31373516 } else {
3138
- ha->fw_revision[0] = dcode[0];
3139
- ha->fw_revision[1] = dcode[1];
3140
- ha->fw_revision[2] = dcode[2];
3141
- ha->fw_revision[3] = dcode[3];
3517
+ for (i = 0; i < 4; i++)
3518
+ ha->fw_revision[i] =
3519
+ be32_to_cpu((__force __be32)dcode[4+i]);
31423520 ql_dbg(ql_dbg_init, vha, 0x0060,
3143
- "Firmware revision %d.%d.%d (%x).\n",
3521
+ "Firmware revision (flash) %u.%u.%u (%x).\n",
31443522 ha->fw_revision[0], ha->fw_revision[1],
31453523 ha->fw_revision[2], ha->fw_revision[3]);
31463524 }
....@@ -3152,20 +3530,18 @@
31523530 }
31533531
31543532 memset(ha->gold_fw_version, 0, sizeof(ha->gold_fw_version));
3155
- dcode = mbuf;
3156
- ha->isp_ops->read_optrom(vha, (uint8_t *)dcode,
3157
- ha->flt_region_gold_fw << 2, 32);
3158
-
3159
- if (dcode[4] == 0xFFFFFFFF && dcode[5] == 0xFFFFFFFF &&
3160
- dcode[6] == 0xFFFFFFFF && dcode[7] == 0xFFFFFFFF) {
3533
+ faddr = ha->flt_region_gold_fw;
3534
+ qla24xx_read_flash_data(vha, dcode, ha->flt_region_gold_fw, 8);
3535
+ if (qla24xx_risc_firmware_invalid(dcode)) {
31613536 ql_log(ql_log_warn, vha, 0x0056,
3162
- "Unrecognized golden fw at 0x%x.\n",
3163
- ha->flt_region_gold_fw * 4);
3537
+ "Unrecognized golden fw at %#x.\n", faddr);
3538
+ ql_dump_buffer(ql_dbg_init, vha, 0x0056, dcode, 32);
31643539 return ret;
31653540 }
31663541
3167
- for (i = 4; i < 8; i++)
3168
- ha->gold_fw_version[i-4] = be32_to_cpu(dcode[i]);
3542
+ for (i = 0; i < 4; i++)
3543
+ ha->gold_fw_version[i] =
3544
+ be32_to_cpu((__force __be32)dcode[4+i]);
31693545
31703546 return ret;
31713547 }
....@@ -3237,7 +3613,7 @@
32373613 fcp_prio_addr = ha->flt_region_fcp_prio;
32383614
32393615 /* first read the fcp priority data header from flash */
3240
- ha->isp_ops->read_optrom(vha, (uint8_t *)ha->fcp_prio_cfg,
3616
+ ha->isp_ops->read_optrom(vha, ha->fcp_prio_cfg,
32413617 fcp_prio_addr << 2, FCP_PRIO_CFG_HDR_SIZE);
32423618
32433619 if (!qla24xx_fcp_prio_cfg_valid(vha, ha->fcp_prio_cfg, 0))
....@@ -3245,10 +3621,10 @@
32453621
32463622 /* read remaining FCP CMD config data from flash */
32473623 fcp_prio_addr += (FCP_PRIO_CFG_HDR_SIZE >> 2);
3248
- len = ha->fcp_prio_cfg->num_entries * FCP_PRIO_CFG_ENTRY_SIZE;
3624
+ len = ha->fcp_prio_cfg->num_entries * sizeof(struct qla_fcp_prio_entry);
32493625 max_len = FCP_PRIO_CFG_SIZE - FCP_PRIO_CFG_HDR_SIZE;
32503626
3251
- ha->isp_ops->read_optrom(vha, (uint8_t *)&ha->fcp_prio_cfg->entry[0],
3627
+ ha->isp_ops->read_optrom(vha, &ha->fcp_prio_cfg->entry[0],
32523628 fcp_prio_addr << 2, (len < max_len ? len : max_len));
32533629
32543630 /* revalidate the entire FCP priority config data, including entries */