2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
10 #define ISPREG(vha) (&(vha)->hw->iobase->isp24)
11 #define IOBAR(reg) offsetof(typeof(*(reg)), iobase_addr)
12 #define IOBASE(vha) IOBAR(ISPREG(vha))
15 qla27xx_insert16(uint16_t value, void *buf, ulong *len)
19 *(__le16 *)buf = cpu_to_le16(value);
21 *len += sizeof(value);
25 qla27xx_insert32(uint32_t value, void *buf, ulong *len)
29 *(__le32 *)buf = cpu_to_le32(value);
31 *len += sizeof(value);
35 qla27xx_insertbuf(void *mem, ulong size, void *buf, ulong *len)
37 if (buf && mem && size) {
39 memcpy(buf, mem, size);
45 qla27xx_read8(void __iomem *window, void *buf, ulong *len)
50 value = RD_REG_BYTE(window);
52 qla27xx_insert32(value, buf, len);
56 qla27xx_read16(void __iomem *window, void *buf, ulong *len)
61 value = RD_REG_WORD(window);
63 qla27xx_insert32(value, buf, len);
67 qla27xx_read32(void __iomem *window, void *buf, ulong *len)
72 value = RD_REG_DWORD(window);
74 qla27xx_insert32(value, buf, len);
77 static inline void (*qla27xx_read_vector(uint width))(void __iomem*, void *, ulong *)
80 (width == 1) ? qla27xx_read8 :
81 (width == 2) ? qla27xx_read16 :
86 qla27xx_read_reg(__iomem struct device_reg_24xx *reg,
87 uint offset, void *buf, ulong *len)
89 void __iomem *window = (void __iomem *)reg + offset;
91 qla27xx_read32(window, buf, len);
95 qla27xx_write_reg(__iomem struct device_reg_24xx *reg,
96 uint offset, uint32_t data, void *buf)
99 void __iomem *window = (void __iomem *)reg + offset;
101 WRT_REG_DWORD(window, data);
106 qla27xx_read_window(__iomem struct device_reg_24xx *reg,
107 uint32_t addr, uint offset, uint count, uint width, void *buf,
110 void __iomem *window = (void __iomem *)reg + offset;
111 void (*readn)(void __iomem*, void *, ulong *) = qla27xx_read_vector(width);
113 qla27xx_write_reg(reg, IOBAR(reg), addr, buf);
115 qla27xx_insert32(addr, buf, len);
116 readn(window, buf, len);
123 qla27xx_skip_entry(struct qla27xx_fwdt_entry *ent, void *buf)
126 ent->hdr.driver_flags |= DRIVER_FLAG_SKIP_ENTRY;
129 static inline struct qla27xx_fwdt_entry *
130 qla27xx_next_entry(struct qla27xx_fwdt_entry *ent)
132 return (void *)ent + le32_to_cpu(ent->hdr.size);
135 static struct qla27xx_fwdt_entry *
136 qla27xx_fwdt_entry_t0(struct scsi_qla_host *vha,
137 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
139 ql_dbg(ql_dbg_misc, vha, 0xd100,
140 "%s: nop [%lx]\n", __func__, *len);
141 qla27xx_skip_entry(ent, buf);
143 return qla27xx_next_entry(ent);
146 static struct qla27xx_fwdt_entry *
147 qla27xx_fwdt_entry_t255(struct scsi_qla_host *vha,
148 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
150 ql_dbg(ql_dbg_misc, vha, 0xd1ff,
151 "%s: end [%lx]\n", __func__, *len);
152 qla27xx_skip_entry(ent, buf);
158 static struct qla27xx_fwdt_entry *
159 qla27xx_fwdt_entry_t256(struct scsi_qla_host *vha,
160 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
162 ulong addr = le32_to_cpu(ent->t256.base_addr);
163 uint offset = ent->t256.pci_offset;
164 ulong count = le16_to_cpu(ent->t256.reg_count);
165 uint width = ent->t256.reg_width;
167 ql_dbg(ql_dbg_misc, vha, 0xd200,
168 "%s: rdio t1 [%lx]\n", __func__, *len);
169 qla27xx_read_window(ISPREG(vha), addr, offset, count, width, buf, len);
171 return qla27xx_next_entry(ent);
174 static struct qla27xx_fwdt_entry *
175 qla27xx_fwdt_entry_t257(struct scsi_qla_host *vha,
176 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
178 ulong addr = le32_to_cpu(ent->t257.base_addr);
179 uint offset = ent->t257.pci_offset;
180 ulong data = le32_to_cpu(ent->t257.write_data);
182 ql_dbg(ql_dbg_misc, vha, 0xd201,
183 "%s: wrio t1 [%lx]\n", __func__, *len);
184 qla27xx_write_reg(ISPREG(vha), IOBASE(vha), addr, buf);
185 qla27xx_write_reg(ISPREG(vha), offset, data, buf);
187 return qla27xx_next_entry(ent);
190 static struct qla27xx_fwdt_entry *
191 qla27xx_fwdt_entry_t258(struct scsi_qla_host *vha,
192 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
194 uint banksel = ent->t258.banksel_offset;
195 ulong bank = le32_to_cpu(ent->t258.bank);
196 ulong addr = le32_to_cpu(ent->t258.base_addr);
197 uint offset = ent->t258.pci_offset;
198 uint count = le16_to_cpu(ent->t258.reg_count);
199 uint width = ent->t258.reg_width;
201 ql_dbg(ql_dbg_misc, vha, 0xd202,
202 "%s: rdio t2 [%lx]\n", __func__, *len);
203 qla27xx_write_reg(ISPREG(vha), banksel, bank, buf);
204 qla27xx_read_window(ISPREG(vha), addr, offset, count, width, buf, len);
206 return qla27xx_next_entry(ent);
209 static struct qla27xx_fwdt_entry *
210 qla27xx_fwdt_entry_t259(struct scsi_qla_host *vha,
211 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
213 ulong addr = le32_to_cpu(ent->t259.base_addr);
214 uint banksel = ent->t259.banksel_offset;
215 ulong bank = le32_to_cpu(ent->t259.bank);
216 uint offset = ent->t259.pci_offset;
217 ulong data = le32_to_cpu(ent->t259.write_data);
219 ql_dbg(ql_dbg_misc, vha, 0xd203,
220 "%s: wrio t2 [%lx]\n", __func__, *len);
221 qla27xx_write_reg(ISPREG(vha), IOBASE(vha), addr, buf);
222 qla27xx_write_reg(ISPREG(vha), banksel, bank, buf);
223 qla27xx_write_reg(ISPREG(vha), offset, data, buf);
225 return qla27xx_next_entry(ent);
228 static struct qla27xx_fwdt_entry *
229 qla27xx_fwdt_entry_t260(struct scsi_qla_host *vha,
230 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
232 uint offset = ent->t260.pci_offset;
234 ql_dbg(ql_dbg_misc, vha, 0xd204,
235 "%s: rdpci [%lx]\n", __func__, *len);
236 qla27xx_insert32(offset, buf, len);
237 qla27xx_read_reg(ISPREG(vha), offset, buf, len);
239 return qla27xx_next_entry(ent);
242 static struct qla27xx_fwdt_entry *
243 qla27xx_fwdt_entry_t261(struct scsi_qla_host *vha,
244 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
246 uint offset = ent->t261.pci_offset;
247 ulong data = le32_to_cpu(ent->t261.write_data);
249 ql_dbg(ql_dbg_misc, vha, 0xd205,
250 "%s: wrpci [%lx]\n", __func__, *len);
251 qla27xx_write_reg(ISPREG(vha), offset, data, buf);
253 return qla27xx_next_entry(ent);
256 static struct qla27xx_fwdt_entry *
257 qla27xx_fwdt_entry_t262(struct scsi_qla_host *vha,
258 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
260 uint area = ent->t262.ram_area;
261 ulong start = le32_to_cpu(ent->t262.start_addr);
262 ulong end = le32_to_cpu(ent->t262.end_addr);
265 ql_dbg(ql_dbg_misc, vha, 0xd206,
266 "%s: rdram(%x) [%lx]\n", __func__, ent->t262.ram_area, *len);
268 if (area == T262_RAM_AREA_CRITICAL_RAM) {
270 } else if (area == T262_RAM_AREA_EXTERNAL_RAM) {
271 end = vha->hw->fw_memory_size;
273 ent->t262.end_addr = cpu_to_le32(end);
274 } else if (area == T262_RAM_AREA_SHARED_RAM) {
275 start = vha->hw->fw_shared_ram_start;
276 end = vha->hw->fw_shared_ram_end;
278 ent->t262.start_addr = cpu_to_le32(start);
279 ent->t262.end_addr = cpu_to_le32(end);
281 } else if (area == T262_RAM_AREA_DDR_RAM) {
282 start = vha->hw->fw_ddr_ram_start;
283 end = vha->hw->fw_ddr_ram_end;
285 ent->t262.start_addr = cpu_to_le32(start);
286 ent->t262.end_addr = cpu_to_le32(end);
288 } else if (area == T262_RAM_AREA_MISC) {
290 ent->t262.start_addr = cpu_to_le32(start);
291 ent->t262.end_addr = cpu_to_le32(end);
294 ql_dbg(ql_dbg_misc, vha, 0xd022,
295 "%s: unknown area %x\n", __func__, area);
296 qla27xx_skip_entry(ent, buf);
300 if (end < start || start == 0 || end == 0) {
301 ql_dbg(ql_dbg_misc, vha, 0xd023,
302 "%s: unusable range (start=%lx end=%lx)\n",
303 __func__, start, end);
304 qla27xx_skip_entry(ent, buf);
308 dwords = end - start + 1;
311 qla24xx_dump_ram(vha->hw, start, buf, dwords, &buf);
313 *len += dwords * sizeof(uint32_t);
315 return qla27xx_next_entry(ent);
318 static struct qla27xx_fwdt_entry *
319 qla27xx_fwdt_entry_t263(struct scsi_qla_host *vha,
320 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
322 uint type = ent->t263.queue_type;
327 ql_dbg(ql_dbg_misc + ql_dbg_verbose, vha, 0xd207,
328 "%s: getq(%x) [%lx]\n", __func__, type, *len);
329 if (type == T263_QUEUE_TYPE_REQ) {
330 for (i = 0; i < vha->hw->max_req_queues; i++) {
331 struct req_que *req = vha->hw->req_q_map[i];
335 req->length : REQUEST_ENTRY_CNT_24XX;
336 qla27xx_insert16(i, buf, len);
337 qla27xx_insert16(length, buf, len);
338 qla27xx_insertbuf(req ? req->ring : NULL,
339 length * sizeof(*req->ring), buf, len);
343 } else if (type == T263_QUEUE_TYPE_RSP) {
344 for (i = 0; i < vha->hw->max_rsp_queues; i++) {
345 struct rsp_que *rsp = vha->hw->rsp_q_map[i];
349 rsp->length : RESPONSE_ENTRY_CNT_MQ;
350 qla27xx_insert16(i, buf, len);
351 qla27xx_insert16(length, buf, len);
352 qla27xx_insertbuf(rsp ? rsp->ring : NULL,
353 length * sizeof(*rsp->ring), buf, len);
357 } else if (QLA_TGT_MODE_ENABLED() &&
358 ent->t263.queue_type == T263_QUEUE_TYPE_ATIO) {
359 struct qla_hw_data *ha = vha->hw;
360 struct atio *atr = ha->tgt.atio_ring;
363 length = ha->tgt.atio_q_length;
364 qla27xx_insert16(0, buf, len);
365 qla27xx_insert16(length, buf, len);
366 qla27xx_insertbuf(atr, length * sizeof(*atr), buf, len);
370 ql_dbg(ql_dbg_misc, vha, 0xd026,
371 "%s: unknown queue %x\n", __func__, type);
372 qla27xx_skip_entry(ent, buf);
377 ent->t263.num_queues = count;
379 qla27xx_skip_entry(ent, buf);
382 return qla27xx_next_entry(ent);
385 static struct qla27xx_fwdt_entry *
386 qla27xx_fwdt_entry_t264(struct scsi_qla_host *vha,
387 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
389 ql_dbg(ql_dbg_misc, vha, 0xd208,
390 "%s: getfce [%lx]\n", __func__, *len);
393 ent->t264.fce_trace_size = FCE_SIZE;
394 ent->t264.write_pointer = vha->hw->fce_wr;
395 ent->t264.base_pointer = vha->hw->fce_dma;
396 ent->t264.fce_enable_mb0 = vha->hw->fce_mb[0];
397 ent->t264.fce_enable_mb2 = vha->hw->fce_mb[2];
398 ent->t264.fce_enable_mb3 = vha->hw->fce_mb[3];
399 ent->t264.fce_enable_mb4 = vha->hw->fce_mb[4];
400 ent->t264.fce_enable_mb5 = vha->hw->fce_mb[5];
401 ent->t264.fce_enable_mb6 = vha->hw->fce_mb[6];
403 qla27xx_insertbuf(vha->hw->fce, FCE_SIZE, buf, len);
405 ql_dbg(ql_dbg_misc, vha, 0xd027,
406 "%s: missing fce\n", __func__);
407 qla27xx_skip_entry(ent, buf);
410 return qla27xx_next_entry(ent);
413 static struct qla27xx_fwdt_entry *
414 qla27xx_fwdt_entry_t265(struct scsi_qla_host *vha,
415 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
417 ql_dbg(ql_dbg_misc + ql_dbg_verbose, vha, 0xd209,
418 "%s: pause risc [%lx]\n", __func__, *len);
420 qla24xx_pause_risc(ISPREG(vha), vha->hw);
422 return qla27xx_next_entry(ent);
425 static struct qla27xx_fwdt_entry *
426 qla27xx_fwdt_entry_t266(struct scsi_qla_host *vha,
427 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
429 ql_dbg(ql_dbg_misc, vha, 0xd20a,
430 "%s: reset risc [%lx]\n", __func__, *len);
432 WARN_ON_ONCE(qla24xx_soft_reset(vha->hw) != QLA_SUCCESS);
434 return qla27xx_next_entry(ent);
437 static struct qla27xx_fwdt_entry *
438 qla27xx_fwdt_entry_t267(struct scsi_qla_host *vha,
439 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
441 uint offset = ent->t267.pci_offset;
442 ulong data = le32_to_cpu(ent->t267.data);
444 ql_dbg(ql_dbg_misc, vha, 0xd20b,
445 "%s: dis intr [%lx]\n", __func__, *len);
446 qla27xx_write_reg(ISPREG(vha), offset, data, buf);
448 return qla27xx_next_entry(ent);
451 static struct qla27xx_fwdt_entry *
452 qla27xx_fwdt_entry_t268(struct scsi_qla_host *vha,
453 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
455 ql_dbg(ql_dbg_misc, vha, 0xd20c,
456 "%s: gethb(%x) [%lx]\n", __func__, ent->t268.buf_type, *len);
457 switch (ent->t268.buf_type) {
458 case T268_BUF_TYPE_EXTD_TRACE:
461 ent->t268.buf_size = EFT_SIZE;
462 ent->t268.start_addr = vha->hw->eft_dma;
464 qla27xx_insertbuf(vha->hw->eft, EFT_SIZE, buf, len);
466 ql_dbg(ql_dbg_misc, vha, 0xd028,
467 "%s: missing eft\n", __func__);
468 qla27xx_skip_entry(ent, buf);
471 case T268_BUF_TYPE_EXCH_BUFOFF:
472 if (vha->hw->exchoffld_buf) {
474 ent->t268.buf_size = vha->hw->exchoffld_size;
475 ent->t268.start_addr =
476 vha->hw->exchoffld_buf_dma;
478 qla27xx_insertbuf(vha->hw->exchoffld_buf,
479 vha->hw->exchoffld_size, buf, len);
481 ql_dbg(ql_dbg_misc, vha, 0xd028,
482 "%s: missing exch offld\n", __func__);
483 qla27xx_skip_entry(ent, buf);
486 case T268_BUF_TYPE_EXTD_LOGIN:
487 if (vha->hw->exlogin_buf) {
489 ent->t268.buf_size = vha->hw->exlogin_size;
490 ent->t268.start_addr =
491 vha->hw->exlogin_buf_dma;
493 qla27xx_insertbuf(vha->hw->exlogin_buf,
494 vha->hw->exlogin_size, buf, len);
496 ql_dbg(ql_dbg_misc, vha, 0xd028,
497 "%s: missing ext login\n", __func__);
498 qla27xx_skip_entry(ent, buf);
502 case T268_BUF_TYPE_REQ_MIRROR:
503 case T268_BUF_TYPE_RSP_MIRROR:
505 * Mirror pointers are not implemented in the
506 * driver, instead shadow pointers are used by
507 * the drier. Skip these entries.
509 qla27xx_skip_entry(ent, buf);
512 ql_dbg(ql_dbg_async, vha, 0xd02b,
513 "%s: unknown buffer %x\n", __func__, ent->t268.buf_type);
514 qla27xx_skip_entry(ent, buf);
518 return qla27xx_next_entry(ent);
521 static struct qla27xx_fwdt_entry *
522 qla27xx_fwdt_entry_t269(struct scsi_qla_host *vha,
523 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
525 ql_dbg(ql_dbg_misc, vha, 0xd20d,
526 "%s: scratch [%lx]\n", __func__, *len);
527 qla27xx_insert32(0xaaaaaaaa, buf, len);
528 qla27xx_insert32(0xbbbbbbbb, buf, len);
529 qla27xx_insert32(0xcccccccc, buf, len);
530 qla27xx_insert32(0xdddddddd, buf, len);
531 qla27xx_insert32(*len + sizeof(uint32_t), buf, len);
533 ent->t269.scratch_size = 5 * sizeof(uint32_t);
535 return qla27xx_next_entry(ent);
538 static struct qla27xx_fwdt_entry *
539 qla27xx_fwdt_entry_t270(struct scsi_qla_host *vha,
540 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
542 ulong addr = le32_to_cpu(ent->t270.addr);
543 ulong dwords = le32_to_cpu(ent->t270.count);
545 ql_dbg(ql_dbg_misc, vha, 0xd20e,
546 "%s: rdremreg [%lx]\n", __func__, *len);
547 qla27xx_write_reg(ISPREG(vha), IOBASE_ADDR, 0x40, buf);
549 qla27xx_write_reg(ISPREG(vha), 0xc0, addr|0x80000000, buf);
550 qla27xx_insert32(addr, buf, len);
551 qla27xx_read_reg(ISPREG(vha), 0xc4, buf, len);
552 addr += sizeof(uint32_t);
555 return qla27xx_next_entry(ent);
558 static struct qla27xx_fwdt_entry *
559 qla27xx_fwdt_entry_t271(struct scsi_qla_host *vha,
560 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
562 ulong addr = le32_to_cpu(ent->t271.addr);
563 ulong data = le32_to_cpu(ent->t271.data);
565 ql_dbg(ql_dbg_misc, vha, 0xd20f,
566 "%s: wrremreg [%lx]\n", __func__, *len);
567 qla27xx_write_reg(ISPREG(vha), IOBASE(vha), 0x40, buf);
568 qla27xx_write_reg(ISPREG(vha), 0xc4, data, buf);
569 qla27xx_write_reg(ISPREG(vha), 0xc0, addr, buf);
571 return qla27xx_next_entry(ent);
574 static struct qla27xx_fwdt_entry *
575 qla27xx_fwdt_entry_t272(struct scsi_qla_host *vha,
576 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
578 ulong dwords = le32_to_cpu(ent->t272.count);
579 ulong start = le32_to_cpu(ent->t272.addr);
581 ql_dbg(ql_dbg_misc, vha, 0xd210,
582 "%s: rdremram [%lx]\n", __func__, *len);
584 ql_dbg(ql_dbg_misc, vha, 0xd02c,
585 "%s: @%lx -> (%lx dwords)\n", __func__, start, dwords);
587 qla27xx_dump_mpi_ram(vha->hw, start, buf, dwords, &buf);
589 *len += dwords * sizeof(uint32_t);
591 return qla27xx_next_entry(ent);
594 static struct qla27xx_fwdt_entry *
595 qla27xx_fwdt_entry_t273(struct scsi_qla_host *vha,
596 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
598 ulong dwords = le32_to_cpu(ent->t273.count);
599 ulong addr = le32_to_cpu(ent->t273.addr);
602 ql_dbg(ql_dbg_misc, vha, 0xd211,
603 "%s: pcicfg [%lx]\n", __func__, *len);
606 if (pci_read_config_dword(vha->hw->pdev, addr, &value))
607 ql_dbg(ql_dbg_misc, vha, 0xd02d,
608 "%s: failed pcicfg read at %lx\n", __func__, addr);
609 qla27xx_insert32(addr, buf, len);
610 qla27xx_insert32(value, buf, len);
611 addr += sizeof(uint32_t);
614 return qla27xx_next_entry(ent);
617 static struct qla27xx_fwdt_entry *
618 qla27xx_fwdt_entry_t274(struct scsi_qla_host *vha,
619 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
621 ulong type = ent->t274.queue_type;
625 ql_dbg(ql_dbg_misc + ql_dbg_verbose, vha, 0xd212,
626 "%s: getqsh(%lx) [%lx]\n", __func__, type, *len);
627 if (type == T274_QUEUE_TYPE_REQ_SHAD) {
628 for (i = 0; i < vha->hw->max_req_queues; i++) {
629 struct req_que *req = vha->hw->req_q_map[i];
632 qla27xx_insert16(i, buf, len);
633 qla27xx_insert16(1, buf, len);
634 qla27xx_insert32(req && req->out_ptr ?
635 *req->out_ptr : 0, buf, len);
639 } else if (type == T274_QUEUE_TYPE_RSP_SHAD) {
640 for (i = 0; i < vha->hw->max_rsp_queues; i++) {
641 struct rsp_que *rsp = vha->hw->rsp_q_map[i];
644 qla27xx_insert16(i, buf, len);
645 qla27xx_insert16(1, buf, len);
646 qla27xx_insert32(rsp && rsp->in_ptr ?
647 *rsp->in_ptr : 0, buf, len);
651 } else if (QLA_TGT_MODE_ENABLED() &&
652 ent->t274.queue_type == T274_QUEUE_TYPE_ATIO_SHAD) {
653 struct qla_hw_data *ha = vha->hw;
654 struct atio *atr = ha->tgt.atio_ring_ptr;
657 qla27xx_insert16(0, buf, len);
658 qla27xx_insert16(1, buf, len);
659 qla27xx_insert32(ha->tgt.atio_q_in ?
660 readl(ha->tgt.atio_q_in) : 0, buf, len);
664 ql_dbg(ql_dbg_misc, vha, 0xd02f,
665 "%s: unknown queue %lx\n", __func__, type);
666 qla27xx_skip_entry(ent, buf);
671 ent->t274.num_queues = count;
673 qla27xx_skip_entry(ent, buf);
676 return qla27xx_next_entry(ent);
679 static struct qla27xx_fwdt_entry *
680 qla27xx_fwdt_entry_t275(struct scsi_qla_host *vha,
681 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
683 ulong offset = offsetof(typeof(*ent), t275.buffer);
684 ulong length = le32_to_cpu(ent->t275.length);
685 ulong size = le32_to_cpu(ent->hdr.size);
686 void *buffer = ent->t275.buffer;
688 ql_dbg(ql_dbg_misc + ql_dbg_verbose, vha, 0xd213,
689 "%s: buffer(%lx) [%lx]\n", __func__, length, *len);
691 ql_dbg(ql_dbg_misc, vha, 0xd020,
692 "%s: buffer zero length\n", __func__);
693 qla27xx_skip_entry(ent, buf);
696 if (offset + length > size) {
697 length = size - offset;
698 ql_dbg(ql_dbg_misc, vha, 0xd030,
699 "%s: buffer overflow, truncate [%lx]\n", __func__, length);
700 ent->t275.length = cpu_to_le32(length);
703 qla27xx_insertbuf(buffer, length, buf, len);
705 return qla27xx_next_entry(ent);
708 static struct qla27xx_fwdt_entry *
709 qla27xx_fwdt_entry_t276(struct scsi_qla_host *vha,
710 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
712 ql_dbg(ql_dbg_misc + ql_dbg_verbose, vha, 0xd214,
713 "%s: cond [%lx]\n", __func__, *len);
716 ulong cond1 = le32_to_cpu(ent->t276.cond1);
717 ulong cond2 = le32_to_cpu(ent->t276.cond2);
718 uint type = vha->hw->pdev->device >> 4 & 0xf;
719 uint func = vha->hw->port_no & 0x3;
721 if (type != cond1 || func != cond2) {
722 struct qla27xx_fwdt_template *tmp = buf;
725 ent = qla27xx_next_entry(ent);
726 qla27xx_skip_entry(ent, buf);
730 return qla27xx_next_entry(ent);
733 static struct qla27xx_fwdt_entry *
734 qla27xx_fwdt_entry_t277(struct scsi_qla_host *vha,
735 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
737 ulong cmd_addr = le32_to_cpu(ent->t277.cmd_addr);
738 ulong wr_cmd_data = le32_to_cpu(ent->t277.wr_cmd_data);
739 ulong data_addr = le32_to_cpu(ent->t277.data_addr);
741 ql_dbg(ql_dbg_misc + ql_dbg_verbose, vha, 0xd215,
742 "%s: rdpep [%lx]\n", __func__, *len);
743 qla27xx_insert32(wr_cmd_data, buf, len);
744 qla27xx_write_reg(ISPREG(vha), cmd_addr, wr_cmd_data, buf);
745 qla27xx_read_reg(ISPREG(vha), data_addr, buf, len);
747 return qla27xx_next_entry(ent);
750 static struct qla27xx_fwdt_entry *
751 qla27xx_fwdt_entry_t278(struct scsi_qla_host *vha,
752 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
754 ulong cmd_addr = le32_to_cpu(ent->t278.cmd_addr);
755 ulong wr_cmd_data = le32_to_cpu(ent->t278.wr_cmd_data);
756 ulong data_addr = le32_to_cpu(ent->t278.data_addr);
757 ulong wr_data = le32_to_cpu(ent->t278.wr_data);
759 ql_dbg(ql_dbg_misc + ql_dbg_verbose, vha, 0xd216,
760 "%s: wrpep [%lx]\n", __func__, *len);
761 qla27xx_write_reg(ISPREG(vha), data_addr, wr_data, buf);
762 qla27xx_write_reg(ISPREG(vha), cmd_addr, wr_cmd_data, buf);
764 return qla27xx_next_entry(ent);
767 static struct qla27xx_fwdt_entry *
768 qla27xx_fwdt_entry_other(struct scsi_qla_host *vha,
769 struct qla27xx_fwdt_entry *ent, void *buf, ulong *len)
771 ulong type = le32_to_cpu(ent->hdr.type);
773 ql_dbg(ql_dbg_misc, vha, 0xd2ff,
774 "%s: other %lx [%lx]\n", __func__, type, *len);
775 qla27xx_skip_entry(ent, buf);
777 return qla27xx_next_entry(ent);
782 typeof(qla27xx_fwdt_entry_other)(*call);
783 } qla27xx_fwdt_entry_call[] = {
784 { ENTRY_TYPE_NOP, qla27xx_fwdt_entry_t0 },
785 { ENTRY_TYPE_TMP_END, qla27xx_fwdt_entry_t255 },
786 { ENTRY_TYPE_RD_IOB_T1, qla27xx_fwdt_entry_t256 },
787 { ENTRY_TYPE_WR_IOB_T1, qla27xx_fwdt_entry_t257 },
788 { ENTRY_TYPE_RD_IOB_T2, qla27xx_fwdt_entry_t258 },
789 { ENTRY_TYPE_WR_IOB_T2, qla27xx_fwdt_entry_t259 },
790 { ENTRY_TYPE_RD_PCI, qla27xx_fwdt_entry_t260 },
791 { ENTRY_TYPE_WR_PCI, qla27xx_fwdt_entry_t261 },
792 { ENTRY_TYPE_RD_RAM, qla27xx_fwdt_entry_t262 },
793 { ENTRY_TYPE_GET_QUEUE, qla27xx_fwdt_entry_t263 },
794 { ENTRY_TYPE_GET_FCE, qla27xx_fwdt_entry_t264 },
795 { ENTRY_TYPE_PSE_RISC, qla27xx_fwdt_entry_t265 },
796 { ENTRY_TYPE_RST_RISC, qla27xx_fwdt_entry_t266 },
797 { ENTRY_TYPE_DIS_INTR, qla27xx_fwdt_entry_t267 },
798 { ENTRY_TYPE_GET_HBUF, qla27xx_fwdt_entry_t268 },
799 { ENTRY_TYPE_SCRATCH, qla27xx_fwdt_entry_t269 },
800 { ENTRY_TYPE_RDREMREG, qla27xx_fwdt_entry_t270 },
801 { ENTRY_TYPE_WRREMREG, qla27xx_fwdt_entry_t271 },
802 { ENTRY_TYPE_RDREMRAM, qla27xx_fwdt_entry_t272 },
803 { ENTRY_TYPE_PCICFG, qla27xx_fwdt_entry_t273 },
804 { ENTRY_TYPE_GET_SHADOW, qla27xx_fwdt_entry_t274 },
805 { ENTRY_TYPE_WRITE_BUF, qla27xx_fwdt_entry_t275 },
806 { ENTRY_TYPE_CONDITIONAL, qla27xx_fwdt_entry_t276 },
807 { ENTRY_TYPE_RDPEPREG, qla27xx_fwdt_entry_t277 },
808 { ENTRY_TYPE_WRPEPREG, qla27xx_fwdt_entry_t278 },
809 { -1, qla27xx_fwdt_entry_other }
813 typeof(qla27xx_fwdt_entry_call->call)(qla27xx_find_entry(uint type))
815 typeof(*qla27xx_fwdt_entry_call) *list = qla27xx_fwdt_entry_call;
817 while (list->type < type)
820 if (list->type == type)
822 return qla27xx_fwdt_entry_other;
826 qla27xx_walk_template(struct scsi_qla_host *vha,
827 struct qla27xx_fwdt_template *tmp, void *buf, ulong *len)
829 struct qla27xx_fwdt_entry *ent = (void *)tmp +
830 le32_to_cpu(tmp->entry_offset);
833 tmp->count = le32_to_cpu(tmp->entry_count);
834 ql_dbg(ql_dbg_misc, vha, 0xd01a,
835 "%s: entry count %u\n", __func__, tmp->count);
836 while (ent && tmp->count--) {
837 type = le32_to_cpu(ent->hdr.type);
838 ent = qla27xx_find_entry(type)(vha, ent, buf, len);
844 ql_dbg(ql_dbg_misc, vha, 0xd018,
845 "%s: entry count residual=+%u\n", __func__, tmp->count);
848 ql_dbg(ql_dbg_misc, vha, 0xd019,
849 "%s: missing end entry\n", __func__);
853 qla27xx_time_stamp(struct qla27xx_fwdt_template *tmp)
855 tmp->capture_timestamp = jiffies;
859 qla27xx_driver_info(struct qla27xx_fwdt_template *tmp)
861 uint8_t v[] = { 0, 0, 0, 0, 0, 0 };
863 WARN_ON_ONCE(sscanf(qla2x00_version_str,
864 "%hhu.%hhu.%hhu.%hhu.%hhu.%hhu",
865 v+0, v+1, v+2, v+3, v+4, v+5) != 6);
867 tmp->driver_info[0] = v[3] << 24 | v[2] << 16 | v[1] << 8 | v[0];
868 tmp->driver_info[1] = v[5] << 8 | v[4];
869 tmp->driver_info[2] = 0x12345678;
873 qla27xx_firmware_info(struct scsi_qla_host *vha,
874 struct qla27xx_fwdt_template *tmp)
876 tmp->firmware_version[0] = vha->hw->fw_major_version;
877 tmp->firmware_version[1] = vha->hw->fw_minor_version;
878 tmp->firmware_version[2] = vha->hw->fw_subminor_version;
879 tmp->firmware_version[3] =
880 vha->hw->fw_attributes_h << 16 | vha->hw->fw_attributes;
881 tmp->firmware_version[4] =
882 vha->hw->fw_attributes_ext[1] << 16 | vha->hw->fw_attributes_ext[0];
886 ql27xx_edit_template(struct scsi_qla_host *vha,
887 struct qla27xx_fwdt_template *tmp)
889 qla27xx_time_stamp(tmp);
890 qla27xx_driver_info(tmp);
891 qla27xx_firmware_info(vha, tmp);
894 static inline uint32_t
895 qla27xx_template_checksum(void *p, ulong size)
900 size /= sizeof(*buf);
902 for ( ; size--; buf++)
903 sum += le32_to_cpu(*buf);
905 sum = (sum & 0xffffffff) + (sum >> 32);
911 qla27xx_verify_template_checksum(struct qla27xx_fwdt_template *tmp)
913 return qla27xx_template_checksum(tmp,
914 le32_to_cpu(tmp->template_size)) == 0;
918 qla27xx_verify_template_header(struct qla27xx_fwdt_template *tmp)
920 return le32_to_cpu(tmp->template_type) == TEMPLATE_TYPE_FWDUMP;
924 qla27xx_execute_fwdt_template(struct scsi_qla_host *vha,
925 struct qla27xx_fwdt_template *tmp, void *buf)
929 if (qla27xx_fwdt_template_valid(tmp)) {
930 len = le32_to_cpu(tmp->template_size);
931 tmp = memcpy(buf, tmp, len);
932 ql27xx_edit_template(vha, tmp);
933 qla27xx_walk_template(vha, tmp, buf, &len);
940 qla27xx_fwdt_calculate_dump_size(struct scsi_qla_host *vha, void *p)
942 struct qla27xx_fwdt_template *tmp = p;
945 if (qla27xx_fwdt_template_valid(tmp)) {
946 len = le32_to_cpu(tmp->template_size);
947 qla27xx_walk_template(vha, tmp, NULL, &len);
954 qla27xx_fwdt_template_size(void *p)
956 struct qla27xx_fwdt_template *tmp = p;
958 return le32_to_cpu(tmp->template_size);
962 qla27xx_fwdt_template_valid(void *p)
964 struct qla27xx_fwdt_template *tmp = p;
966 if (!qla27xx_verify_template_header(tmp)) {
967 ql_log(ql_log_warn, NULL, 0xd01c,
968 "%s: template type %x\n", __func__,
969 le32_to_cpu(tmp->template_type));
973 if (!qla27xx_verify_template_checksum(tmp)) {
974 ql_log(ql_log_warn, NULL, 0xd01d,
975 "%s: failed template checksum\n", __func__);
983 qla27xx_fwdump(scsi_qla_host_t *vha, int hardware_locked)
988 if (!hardware_locked)
989 spin_lock_irqsave(&vha->hw->hardware_lock, flags);
992 if (!vha->hw->fw_dump) {
993 ql_log(ql_log_warn, vha, 0xd01e, "-> fwdump no buffer\n");
994 } else if (vha->hw->fw_dumped) {
995 ql_log(ql_log_warn, vha, 0xd01f,
996 "-> Firmware already dumped (%p) -- ignoring request\n",
999 struct fwdt *fwdt = vha->hw->fwdt;
1002 void *buf = vha->hw->fw_dump;
1004 for (j = 0; j < 2; j++, fwdt++, buf += len) {
1005 ql_log(ql_log_warn, vha, 0xd011,
1006 "-> fwdt%u running...\n", j);
1007 if (!fwdt->template) {
1008 ql_log(ql_log_warn, vha, 0xd012,
1009 "-> fwdt%u no template\n", j);
1012 len = qla27xx_execute_fwdt_template(vha,
1013 fwdt->template, buf);
1014 if (len != fwdt->dump_size) {
1015 ql_log(ql_log_warn, vha, 0xd013,
1016 "-> fwdt%u fwdump residual=%+ld\n",
1017 j, fwdt->dump_size - len);
1020 vha->hw->fw_dump_len = buf - (void *)vha->hw->fw_dump;
1021 vha->hw->fw_dumped = 1;
1023 ql_log(ql_log_warn, vha, 0xd015,
1024 "-> Firmware dump saved to buffer (%lu/%p) <%lx>\n",
1025 vha->host_no, vha->hw->fw_dump, vha->hw->fw_dump_cap_flags);
1026 qla2x00_post_uevent_work(vha, QLA_UEVENT_CODE_FW_DUMP);
1030 if (!hardware_locked)
1031 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);