2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
8 #include <linux/vmalloc.h>
9 #include <linux/delay.h>
14 #define TIMEOUT_100_MS 100
16 static const uint32_t qla8044_reg_tbl[] = {
17 QLA8044_PEG_HALT_STATUS1,
18 QLA8044_PEG_HALT_STATUS2,
19 QLA8044_PEG_ALIVE_COUNTER,
20 QLA8044_CRB_DRV_ACTIVE,
21 QLA8044_CRB_DEV_STATE,
22 QLA8044_CRB_DRV_STATE,
23 QLA8044_CRB_DRV_SCRATCH,
24 QLA8044_CRB_DEV_PART_INFO1,
25 QLA8044_CRB_IDC_VER_MAJOR,
33 /* 8044 Flash Read/Write functions */
35 qla8044_rd_reg(struct qla_hw_data *ha, ulong addr)
37 return readl((void __iomem *) (ha->nx_pcibase + addr));
41 qla8044_wr_reg(struct qla_hw_data *ha, ulong addr, uint32_t val)
43 writel(val, (void __iomem *)((ha)->nx_pcibase + addr));
47 qla8044_rd_direct(struct scsi_qla_host *vha,
48 const uint32_t crb_reg)
50 struct qla_hw_data *ha = vha->hw;
52 if (crb_reg < CRB_REG_INDEX_MAX)
53 return qla8044_rd_reg(ha, qla8044_reg_tbl[crb_reg]);
55 return QLA_FUNCTION_FAILED;
59 qla8044_wr_direct(struct scsi_qla_host *vha,
60 const uint32_t crb_reg,
63 struct qla_hw_data *ha = vha->hw;
65 if (crb_reg < CRB_REG_INDEX_MAX)
66 qla8044_wr_reg(ha, qla8044_reg_tbl[crb_reg], value);
70 qla8044_set_win_base(scsi_qla_host_t *vha, uint32_t addr)
73 int ret_val = QLA_SUCCESS;
74 struct qla_hw_data *ha = vha->hw;
76 qla8044_wr_reg(ha, QLA8044_CRB_WIN_FUNC(ha->portnum), addr);
77 val = qla8044_rd_reg(ha, QLA8044_CRB_WIN_FUNC(ha->portnum));
80 ql_log(ql_log_warn, vha, 0xb087,
81 "%s: Failed to set register window : "
82 "addr written 0x%x, read 0x%x!\n",
84 ret_val = QLA_FUNCTION_FAILED;
90 qla8044_rd_reg_indirect(scsi_qla_host_t *vha, uint32_t addr, uint32_t *data)
92 int ret_val = QLA_SUCCESS;
93 struct qla_hw_data *ha = vha->hw;
95 ret_val = qla8044_set_win_base(vha, addr);
97 *data = qla8044_rd_reg(ha, QLA8044_WILDCARD);
99 ql_log(ql_log_warn, vha, 0xb088,
100 "%s: failed read of addr 0x%x!\n", __func__, addr);
105 qla8044_wr_reg_indirect(scsi_qla_host_t *vha, uint32_t addr, uint32_t data)
107 int ret_val = QLA_SUCCESS;
108 struct qla_hw_data *ha = vha->hw;
110 ret_val = qla8044_set_win_base(vha, addr);
112 qla8044_wr_reg(ha, QLA8044_WILDCARD, data);
114 ql_log(ql_log_warn, vha, 0xb089,
115 "%s: failed wrt to addr 0x%x, data 0x%x\n",
116 __func__, addr, data);
121 * qla8044_read_write_crb_reg - Read from raddr and write value to waddr.
123 * @ha : Pointer to adapter structure
124 * @raddr : CRB address to read from
125 * @waddr : CRB address to write to
129 qla8044_read_write_crb_reg(struct scsi_qla_host *vha,
130 uint32_t raddr, uint32_t waddr)
134 qla8044_rd_reg_indirect(vha, raddr, &value);
135 qla8044_wr_reg_indirect(vha, waddr, value);
139 qla8044_poll_wait_for_ready(struct scsi_qla_host *vha, uint32_t addr1,
142 unsigned long timeout;
145 /* jiffies after 100ms */
146 timeout = jiffies + msecs_to_jiffies(TIMEOUT_100_MS);
148 qla8044_rd_reg_indirect(vha, addr1, &temp);
149 if ((temp & mask) != 0)
151 if (time_after_eq(jiffies, timeout)) {
152 ql_log(ql_log_warn, vha, 0xb151,
153 "Error in processing rdmdio entry\n");
162 qla8044_ipmdio_rd_reg(struct scsi_qla_host *vha,
163 uint32_t addr1, uint32_t addr3, uint32_t mask, uint32_t addr)
168 ret = qla8044_poll_wait_for_ready(vha, addr1, mask);
172 temp = (0x40000000 | addr);
173 qla8044_wr_reg_indirect(vha, addr1, temp);
175 ret = qla8044_poll_wait_for_ready(vha, addr1, mask);
179 qla8044_rd_reg_indirect(vha, addr3, &ret);
186 qla8044_poll_wait_ipmdio_bus_idle(struct scsi_qla_host *vha,
187 uint32_t addr1, uint32_t addr2, uint32_t addr3, uint32_t mask)
189 unsigned long timeout;
192 /* jiffies after 100 msecs */
193 timeout = jiffies + msecs_to_jiffies(TIMEOUT_100_MS);
195 temp = qla8044_ipmdio_rd_reg(vha, addr1, addr3, mask, addr2);
196 if ((temp & 0x1) != 1)
198 if (time_after_eq(jiffies, timeout)) {
199 ql_log(ql_log_warn, vha, 0xb152,
200 "Error in processing mdiobus idle\n");
209 qla8044_ipmdio_wr_reg(struct scsi_qla_host *vha, uint32_t addr1,
210 uint32_t addr3, uint32_t mask, uint32_t addr, uint32_t value)
214 ret = qla8044_poll_wait_for_ready(vha, addr1, mask);
218 qla8044_wr_reg_indirect(vha, addr3, value);
219 qla8044_wr_reg_indirect(vha, addr1, addr);
221 ret = qla8044_poll_wait_for_ready(vha, addr1, mask);
228 * qla8044_rmw_crb_reg - Read value from raddr, AND with test_mask,
229 * Shift Left,Right/OR/XOR with values RMW header and write value to waddr.
231 * @vha : Pointer to adapter structure
232 * @raddr : CRB address to read from
233 * @waddr : CRB address to write to
234 * @p_rmw_hdr : header with shift/or/xor values.
238 qla8044_rmw_crb_reg(struct scsi_qla_host *vha,
239 uint32_t raddr, uint32_t waddr, struct qla8044_rmw *p_rmw_hdr)
243 if (p_rmw_hdr->index_a)
244 value = vha->reset_tmplt.array[p_rmw_hdr->index_a];
246 qla8044_rd_reg_indirect(vha, raddr, &value);
247 value &= p_rmw_hdr->test_mask;
248 value <<= p_rmw_hdr->shl;
249 value >>= p_rmw_hdr->shr;
250 value |= p_rmw_hdr->or_value;
251 value ^= p_rmw_hdr->xor_value;
252 qla8044_wr_reg_indirect(vha, waddr, value);
257 qla8044_set_qsnt_ready(struct scsi_qla_host *vha)
260 struct qla_hw_data *ha = vha->hw;
262 qsnt_state = qla8044_rd_direct(vha, QLA8044_CRB_DRV_STATE_INDEX);
263 qsnt_state |= (1 << ha->portnum);
264 qla8044_wr_direct(vha, QLA8044_CRB_DRV_STATE_INDEX, qsnt_state);
265 ql_log(ql_log_info, vha, 0xb08e, "%s(%ld): qsnt_state: 0x%08x\n",
266 __func__, vha->host_no, qsnt_state);
270 qla8044_clear_qsnt_ready(struct scsi_qla_host *vha)
273 struct qla_hw_data *ha = vha->hw;
275 qsnt_state = qla8044_rd_direct(vha, QLA8044_CRB_DRV_STATE_INDEX);
276 qsnt_state &= ~(1 << ha->portnum);
277 qla8044_wr_direct(vha, QLA8044_CRB_DRV_STATE_INDEX, qsnt_state);
278 ql_log(ql_log_info, vha, 0xb08f, "%s(%ld): qsnt_state: 0x%08x\n",
279 __func__, vha->host_no, qsnt_state);
283 * qla8044_lock_recovery - Recovers the idc_lock.
284 * @vha : Pointer to adapter structure
286 * Lock Recovery Register
287 * 5-2 Lock recovery owner: Function ID of driver doing lock recovery,
288 * valid if bits 1..0 are set by driver doing lock recovery.
289 * 1-0 1 - Driver intends to force unlock the IDC lock.
290 * 2 - Driver is moving forward to unlock the IDC lock. Driver clears
291 * this field after force unlocking the IDC lock.
293 * Lock Recovery process
294 * a. Read the IDC_LOCK_RECOVERY register. If the value in bits 1..0 is
295 * greater than 0, then wait for the other driver to unlock otherwise
296 * move to the next step.
297 * b. Indicate intent to force-unlock by writing 1h to the IDC_LOCK_RECOVERY
298 * register bits 1..0 and also set the function# in bits 5..2.
299 * c. Read the IDC_LOCK_RECOVERY register again after a delay of 200ms.
300 * Wait for the other driver to perform lock recovery if the function
301 * number in bits 5..2 has changed, otherwise move to the next step.
302 * d. Write a value of 2h to the IDC_LOCK_RECOVERY register bits 1..0
303 * leaving your function# in bits 5..2.
304 * e. Force unlock using the DRIVER_UNLOCK register and immediately clear
305 * the IDC_LOCK_RECOVERY bits 5..0 by writing 0.
308 qla8044_lock_recovery(struct scsi_qla_host *vha)
310 uint32_t lock = 0, lockid;
311 struct qla_hw_data *ha = vha->hw;
313 lockid = qla8044_rd_reg(ha, QLA8044_DRV_LOCKRECOVERY);
315 /* Check for other Recovery in progress, go wait */
316 if ((lockid & IDC_LOCK_RECOVERY_STATE_MASK) != 0)
317 return QLA_FUNCTION_FAILED;
319 /* Intent to Recover */
320 qla8044_wr_reg(ha, QLA8044_DRV_LOCKRECOVERY,
322 IDC_LOCK_RECOVERY_STATE_SHIFT_BITS) | INTENT_TO_RECOVER);
325 /* Check Intent to Recover is advertised */
326 lockid = qla8044_rd_reg(ha, QLA8044_DRV_LOCKRECOVERY);
327 if ((lockid & IDC_LOCK_RECOVERY_OWNER_MASK) != (ha->portnum <<
328 IDC_LOCK_RECOVERY_STATE_SHIFT_BITS))
329 return QLA_FUNCTION_FAILED;
331 ql_dbg(ql_dbg_p3p, vha, 0xb08B, "%s:%d: IDC Lock recovery initiated\n"
332 , __func__, ha->portnum);
334 /* Proceed to Recover */
335 qla8044_wr_reg(ha, QLA8044_DRV_LOCKRECOVERY,
336 (ha->portnum << IDC_LOCK_RECOVERY_STATE_SHIFT_BITS) |
340 qla8044_wr_reg(ha, QLA8044_DRV_LOCK_ID, 0xFF);
341 qla8044_rd_reg(ha, QLA8044_DRV_UNLOCK);
343 /* Clear bits 0-5 in IDC_RECOVERY register*/
344 qla8044_wr_reg(ha, QLA8044_DRV_LOCKRECOVERY, 0);
347 lock = qla8044_rd_reg(ha, QLA8044_DRV_LOCK);
349 lockid = qla8044_rd_reg(ha, QLA8044_DRV_LOCK_ID);
350 lockid = ((lockid + (1 << 8)) & ~0xFF) | ha->portnum;
351 qla8044_wr_reg(ha, QLA8044_DRV_LOCK_ID, lockid);
354 return QLA_FUNCTION_FAILED;
358 qla8044_idc_lock(struct qla_hw_data *ha)
360 uint32_t ret_val = QLA_SUCCESS, timeout = 0, status = 0;
361 uint32_t lock_id, lock_cnt, func_num, tmo_owner = 0, first_owner = 0;
362 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
364 while (status == 0) {
365 /* acquire semaphore5 from PCI HW block */
366 status = qla8044_rd_reg(ha, QLA8044_DRV_LOCK);
369 /* Increment Counter (8-31) and update func_num (0-7) on
370 * getting a successful lock */
371 lock_id = qla8044_rd_reg(ha, QLA8044_DRV_LOCK_ID);
372 lock_id = ((lock_id + (1 << 8)) & ~0xFF) | ha->portnum;
373 qla8044_wr_reg(ha, QLA8044_DRV_LOCK_ID, lock_id);
378 first_owner = qla8044_rd_reg(ha, QLA8044_DRV_LOCK_ID);
381 (QLA8044_DRV_LOCK_TIMEOUT / QLA8044_DRV_LOCK_MSLEEP)) {
382 tmo_owner = qla8044_rd_reg(ha, QLA8044_DRV_LOCK_ID);
383 func_num = tmo_owner & 0xFF;
384 lock_cnt = tmo_owner >> 8;
385 ql_log(ql_log_warn, vha, 0xb114,
386 "%s: Lock by func %d failed after 2s, lock held "
387 "by func %d, lock count %d, first_owner %d\n",
388 __func__, ha->portnum, func_num, lock_cnt,
389 (first_owner & 0xFF));
390 if (first_owner != tmo_owner) {
391 /* Some other driver got lock,
392 * OR same driver got lock again (counter
393 * value changed), when we were waiting for
394 * lock. Retry for another 2 sec */
395 ql_dbg(ql_dbg_p3p, vha, 0xb115,
396 "%s: %d: IDC lock failed\n",
397 __func__, ha->portnum);
400 /* Same driver holding lock > 2sec.
402 if (qla8044_lock_recovery(vha) == QLA_SUCCESS) {
403 /* Recovered and got lock */
404 ret_val = QLA_SUCCESS;
405 ql_dbg(ql_dbg_p3p, vha, 0xb116,
406 "%s:IDC lock Recovery by %d"
407 "successful...\n", __func__,
410 /* Recovery Failed, some other function
411 * has the lock, wait for 2secs
414 ql_dbg(ql_dbg_p3p, vha, 0xb08a,
415 "%s: IDC lock Recovery by %d "
416 "failed, Retrying timeout\n", __func__,
421 msleep(QLA8044_DRV_LOCK_MSLEEP);
427 qla8044_idc_unlock(struct qla_hw_data *ha)
430 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
432 id = qla8044_rd_reg(ha, QLA8044_DRV_LOCK_ID);
434 if ((id & 0xFF) != ha->portnum) {
435 ql_log(ql_log_warn, vha, 0xb118,
436 "%s: IDC Unlock by %d failed, lock owner is %d!\n",
437 __func__, ha->portnum, (id & 0xFF));
441 /* Keep lock counter value, update the ha->func_num to 0xFF */
442 qla8044_wr_reg(ha, QLA8044_DRV_LOCK_ID, (id | 0xFF));
443 qla8044_rd_reg(ha, QLA8044_DRV_UNLOCK);
446 /* 8044 Flash Lock/Unlock functions */
448 qla8044_flash_lock(scsi_qla_host_t *vha)
452 uint32_t lock_status = 0;
453 int ret_val = QLA_SUCCESS;
454 struct qla_hw_data *ha = vha->hw;
456 while (lock_status == 0) {
457 lock_status = qla8044_rd_reg(ha, QLA8044_FLASH_LOCK);
461 if (++timeout >= QLA8044_FLASH_LOCK_TIMEOUT / 20) {
462 lock_owner = qla8044_rd_reg(ha,
463 QLA8044_FLASH_LOCK_ID);
464 ql_log(ql_log_warn, vha, 0xb113,
465 "%s: Simultaneous flash access by following ports, active port = %d: accessing port = %d",
466 __func__, ha->portnum, lock_owner);
467 ret_val = QLA_FUNCTION_FAILED;
472 qla8044_wr_reg(ha, QLA8044_FLASH_LOCK_ID, ha->portnum);
477 qla8044_flash_unlock(scsi_qla_host_t *vha)
479 struct qla_hw_data *ha = vha->hw;
481 /* Reading FLASH_UNLOCK register unlocks the Flash */
482 qla8044_wr_reg(ha, QLA8044_FLASH_LOCK_ID, 0xFF);
483 qla8044_rd_reg(ha, QLA8044_FLASH_UNLOCK);
488 void qla8044_flash_lock_recovery(struct scsi_qla_host *vha)
491 if (qla8044_flash_lock(vha)) {
492 /* Someone else is holding the lock. */
493 ql_log(ql_log_warn, vha, 0xb120, "Resetting flash_lock\n");
497 * Either we got the lock, or someone
498 * else died while holding it.
499 * In either case, unlock.
501 qla8044_flash_unlock(vha);
505 * Address and length are byte address
508 qla8044_read_flash_data(scsi_qla_host_t *vha, uint8_t *p_data,
509 uint32_t flash_addr, int u32_word_count)
511 int i, ret_val = QLA_SUCCESS;
514 if (qla8044_flash_lock(vha) != QLA_SUCCESS) {
515 ret_val = QLA_FUNCTION_FAILED;
516 goto exit_lock_error;
519 if (flash_addr & 0x03) {
520 ql_log(ql_log_warn, vha, 0xb117,
521 "%s: Illegal addr = 0x%x\n", __func__, flash_addr);
522 ret_val = QLA_FUNCTION_FAILED;
523 goto exit_flash_read;
526 for (i = 0; i < u32_word_count; i++) {
527 if (qla8044_wr_reg_indirect(vha, QLA8044_FLASH_DIRECT_WINDOW,
528 (flash_addr & 0xFFFF0000))) {
529 ql_log(ql_log_warn, vha, 0xb119,
530 "%s: failed to write addr 0x%x to "
531 "FLASH_DIRECT_WINDOW\n! ",
532 __func__, flash_addr);
533 ret_val = QLA_FUNCTION_FAILED;
534 goto exit_flash_read;
537 ret_val = qla8044_rd_reg_indirect(vha,
538 QLA8044_FLASH_DIRECT_DATA(flash_addr),
540 if (ret_val != QLA_SUCCESS) {
541 ql_log(ql_log_warn, vha, 0xb08c,
542 "%s: failed to read addr 0x%x!\n",
543 __func__, flash_addr);
544 goto exit_flash_read;
547 *(uint32_t *)p_data = u32_word;
549 flash_addr = flash_addr + 4;
553 qla8044_flash_unlock(vha);
560 * Address and length are byte address
563 qla8044_read_optrom_data(struct scsi_qla_host *vha, void *buf,
564 uint32_t offset, uint32_t length)
566 scsi_block_requests(vha->host);
567 if (qla8044_read_flash_data(vha, buf, offset, length / 4)
569 ql_log(ql_log_warn, vha, 0xb08d,
570 "%s: Failed to read from flash\n",
573 scsi_unblock_requests(vha->host);
578 qla8044_need_reset(struct scsi_qla_host *vha)
580 uint32_t drv_state, drv_active;
582 struct qla_hw_data *ha = vha->hw;
584 drv_active = qla8044_rd_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX);
585 drv_state = qla8044_rd_direct(vha, QLA8044_CRB_DRV_STATE_INDEX);
587 rval = drv_state & (1 << ha->portnum);
589 if (ha->flags.eeh_busy && drv_active)
595 * qla8044_write_list - Write the value (p_entry->arg2) to address specified
596 * by p_entry->arg1 for all entries in header with delay of p_hdr->delay between
599 * @vha : Pointer to adapter structure
600 * @p_hdr : reset_entry header for WRITE_LIST opcode.
604 qla8044_write_list(struct scsi_qla_host *vha,
605 struct qla8044_reset_entry_hdr *p_hdr)
607 struct qla8044_entry *p_entry;
610 p_entry = (struct qla8044_entry *)((char *)p_hdr +
611 sizeof(struct qla8044_reset_entry_hdr));
613 for (i = 0; i < p_hdr->count; i++, p_entry++) {
614 qla8044_wr_reg_indirect(vha, p_entry->arg1, p_entry->arg2);
616 udelay((uint32_t)(p_hdr->delay));
621 * qla8044_read_write_list - Read from address specified by p_entry->arg1,
622 * write value read to address specified by p_entry->arg2, for all entries in
623 * header with delay of p_hdr->delay between entries.
625 * @vha : Pointer to adapter structure
626 * @p_hdr : reset_entry header for READ_WRITE_LIST opcode.
630 qla8044_read_write_list(struct scsi_qla_host *vha,
631 struct qla8044_reset_entry_hdr *p_hdr)
633 struct qla8044_entry *p_entry;
636 p_entry = (struct qla8044_entry *)((char *)p_hdr +
637 sizeof(struct qla8044_reset_entry_hdr));
639 for (i = 0; i < p_hdr->count; i++, p_entry++) {
640 qla8044_read_write_crb_reg(vha, p_entry->arg1,
643 udelay((uint32_t)(p_hdr->delay));
648 * qla8044_poll_reg - Poll the given CRB addr for duration msecs till
649 * value read ANDed with test_mask is equal to test_result.
651 * @ha : Pointer to adapter structure
652 * @addr : CRB register address
653 * @duration : Poll for total of "duration" msecs
654 * @test_mask : Mask value read with "test_mask"
655 * @test_result : Compare (value&test_mask) with test_result.
657 * Return Value - QLA_SUCCESS/QLA_FUNCTION_FAILED
660 qla8044_poll_reg(struct scsi_qla_host *vha, uint32_t addr,
661 int duration, uint32_t test_mask, uint32_t test_result)
666 int ret_val = QLA_SUCCESS;
668 ret_val = qla8044_rd_reg_indirect(vha, addr, &value);
669 if (ret_val == QLA_FUNCTION_FAILED) {
674 /* poll every 1/10 of the total duration */
675 retries = duration/10;
678 if ((value & test_mask) != test_result) {
681 ret_val = qla8044_rd_reg_indirect(vha, addr, &value);
682 if (ret_val == QLA_FUNCTION_FAILED) {
694 vha->reset_tmplt.seq_error++;
695 ql_log(ql_log_fatal, vha, 0xb090,
696 "%s: Poll Failed: 0x%08x 0x%08x 0x%08x\n",
697 __func__, value, test_mask, test_result);
700 return timeout_error;
704 * qla8044_poll_list - For all entries in the POLL_LIST header, poll read CRB
705 * register specified by p_entry->arg1 and compare (value AND test_mask) with
706 * test_result to validate it. Wait for p_hdr->delay between processing entries.
708 * @ha : Pointer to adapter structure
709 * @p_hdr : reset_entry header for POLL_LIST opcode.
713 qla8044_poll_list(struct scsi_qla_host *vha,
714 struct qla8044_reset_entry_hdr *p_hdr)
717 struct qla8044_entry *p_entry;
718 struct qla8044_poll *p_poll;
722 p_poll = (struct qla8044_poll *)
723 ((char *)p_hdr + sizeof(struct qla8044_reset_entry_hdr));
725 /* Entries start after 8 byte qla8044_poll, poll header contains
726 * the test_mask, test_value.
728 p_entry = (struct qla8044_entry *)((char *)p_poll +
729 sizeof(struct qla8044_poll));
731 delay = (long)p_hdr->delay;
734 for (i = 0; i < p_hdr->count; i++, p_entry++)
735 qla8044_poll_reg(vha, p_entry->arg1,
736 delay, p_poll->test_mask, p_poll->test_value);
738 for (i = 0; i < p_hdr->count; i++, p_entry++) {
740 if (qla8044_poll_reg(vha,
741 p_entry->arg1, delay,
743 p_poll->test_value)) {
745 * (data_read&test_mask != test_value)
746 * read TIMEOUT_ADDR (arg1) and
747 * ADDR (arg2) registers
749 qla8044_rd_reg_indirect(vha,
750 p_entry->arg1, &value);
751 qla8044_rd_reg_indirect(vha,
752 p_entry->arg2, &value);
760 * qla8044_poll_write_list - Write dr_value, ar_value to dr_addr/ar_addr,
761 * read ar_addr, if (value& test_mask != test_mask) re-read till timeout
764 * @vha : Pointer to adapter structure
765 * @p_hdr : reset entry header for POLL_WRITE_LIST opcode.
769 qla8044_poll_write_list(struct scsi_qla_host *vha,
770 struct qla8044_reset_entry_hdr *p_hdr)
773 struct qla8044_quad_entry *p_entry;
774 struct qla8044_poll *p_poll;
777 p_poll = (struct qla8044_poll *)((char *)p_hdr +
778 sizeof(struct qla8044_reset_entry_hdr));
780 p_entry = (struct qla8044_quad_entry *)((char *)p_poll +
781 sizeof(struct qla8044_poll));
783 delay = (long)p_hdr->delay;
785 for (i = 0; i < p_hdr->count; i++, p_entry++) {
786 qla8044_wr_reg_indirect(vha,
787 p_entry->dr_addr, p_entry->dr_value);
788 qla8044_wr_reg_indirect(vha,
789 p_entry->ar_addr, p_entry->ar_value);
791 if (qla8044_poll_reg(vha,
792 p_entry->ar_addr, delay,
794 p_poll->test_value)) {
795 ql_dbg(ql_dbg_p3p, vha, 0xb091,
796 "%s: Timeout Error: poll list, ",
798 ql_dbg(ql_dbg_p3p, vha, 0xb092,
799 "item_num %d, entry_num %d\n", i,
800 vha->reset_tmplt.seq_index);
807 * qla8044_read_modify_write - Read value from p_entry->arg1, modify the
808 * value, write value to p_entry->arg2. Process entries with p_hdr->delay
811 * @vha : Pointer to adapter structure
812 * @p_hdr : header with shift/or/xor values.
816 qla8044_read_modify_write(struct scsi_qla_host *vha,
817 struct qla8044_reset_entry_hdr *p_hdr)
819 struct qla8044_entry *p_entry;
820 struct qla8044_rmw *p_rmw_hdr;
823 p_rmw_hdr = (struct qla8044_rmw *)((char *)p_hdr +
824 sizeof(struct qla8044_reset_entry_hdr));
826 p_entry = (struct qla8044_entry *)((char *)p_rmw_hdr +
827 sizeof(struct qla8044_rmw));
829 for (i = 0; i < p_hdr->count; i++, p_entry++) {
830 qla8044_rmw_crb_reg(vha, p_entry->arg1,
831 p_entry->arg2, p_rmw_hdr);
833 udelay((uint32_t)(p_hdr->delay));
838 * qla8044_pause - Wait for p_hdr->delay msecs, called between processing
839 * two entries of a sequence.
841 * @vha : Pointer to adapter structure
842 * @p_hdr : Common reset entry header.
846 void qla8044_pause(struct scsi_qla_host *vha,
847 struct qla8044_reset_entry_hdr *p_hdr)
850 mdelay((uint32_t)((long)p_hdr->delay));
854 * qla8044_template_end - Indicates end of reset sequence processing.
856 * @vha : Pointer to adapter structure
857 * @p_hdr : Common reset entry header.
861 qla8044_template_end(struct scsi_qla_host *vha,
862 struct qla8044_reset_entry_hdr *p_hdr)
864 vha->reset_tmplt.template_end = 1;
866 if (vha->reset_tmplt.seq_error == 0) {
867 ql_dbg(ql_dbg_p3p, vha, 0xb093,
868 "%s: Reset sequence completed SUCCESSFULLY.\n", __func__);
870 ql_log(ql_log_fatal, vha, 0xb094,
871 "%s: Reset sequence completed with some timeout "
872 "errors.\n", __func__);
877 * qla8044_poll_read_list - Write ar_value to ar_addr register, read ar_addr,
878 * if (value & test_mask != test_value) re-read till timeout value expires,
879 * read dr_addr register and assign to reset_tmplt.array.
881 * @vha : Pointer to adapter structure
882 * @p_hdr : Common reset entry header.
886 qla8044_poll_read_list(struct scsi_qla_host *vha,
887 struct qla8044_reset_entry_hdr *p_hdr)
891 struct qla8044_quad_entry *p_entry;
892 struct qla8044_poll *p_poll;
896 p_poll = (struct qla8044_poll *)
897 ((char *)p_hdr + sizeof(struct qla8044_reset_entry_hdr));
899 p_entry = (struct qla8044_quad_entry *)
900 ((char *)p_poll + sizeof(struct qla8044_poll));
902 delay = (long)p_hdr->delay;
904 for (i = 0; i < p_hdr->count; i++, p_entry++) {
905 qla8044_wr_reg_indirect(vha, p_entry->ar_addr,
908 if (qla8044_poll_reg(vha, p_entry->ar_addr, delay,
909 p_poll->test_mask, p_poll->test_value)) {
910 ql_dbg(ql_dbg_p3p, vha, 0xb095,
911 "%s: Timeout Error: poll "
913 ql_dbg(ql_dbg_p3p, vha, 0xb096,
916 vha->reset_tmplt.seq_index);
918 index = vha->reset_tmplt.array_index;
919 qla8044_rd_reg_indirect(vha,
920 p_entry->dr_addr, &value);
921 vha->reset_tmplt.array[index++] = value;
922 if (index == QLA8044_MAX_RESET_SEQ_ENTRIES)
923 vha->reset_tmplt.array_index = 1;
930 * qla8031_process_reset_template - Process all entries in reset template
931 * till entry with SEQ_END opcode, which indicates end of the reset template
932 * processing. Each entry has a Reset Entry header, entry opcode/command, with
933 * size of the entry, number of entries in sub-sequence and delay in microsecs
934 * or timeout in millisecs.
936 * @ha : Pointer to adapter structure
937 * @p_buff : Common reset entry header.
941 qla8044_process_reset_template(struct scsi_qla_host *vha,
945 struct qla8044_reset_entry_hdr *p_hdr;
946 char *p_entry = p_buff;
948 vha->reset_tmplt.seq_end = 0;
949 vha->reset_tmplt.template_end = 0;
950 entries = vha->reset_tmplt.hdr->entries;
951 index = vha->reset_tmplt.seq_index;
953 for (; (!vha->reset_tmplt.seq_end) && (index < entries); index++) {
954 p_hdr = (struct qla8044_reset_entry_hdr *)p_entry;
955 switch (p_hdr->cmd) {
958 case OPCODE_WRITE_LIST:
959 qla8044_write_list(vha, p_hdr);
961 case OPCODE_READ_WRITE_LIST:
962 qla8044_read_write_list(vha, p_hdr);
964 case OPCODE_POLL_LIST:
965 qla8044_poll_list(vha, p_hdr);
967 case OPCODE_POLL_WRITE_LIST:
968 qla8044_poll_write_list(vha, p_hdr);
970 case OPCODE_READ_MODIFY_WRITE:
971 qla8044_read_modify_write(vha, p_hdr);
973 case OPCODE_SEQ_PAUSE:
974 qla8044_pause(vha, p_hdr);
977 vha->reset_tmplt.seq_end = 1;
979 case OPCODE_TMPL_END:
980 qla8044_template_end(vha, p_hdr);
982 case OPCODE_POLL_READ_LIST:
983 qla8044_poll_read_list(vha, p_hdr);
986 ql_log(ql_log_fatal, vha, 0xb097,
987 "%s: Unknown command ==> 0x%04x on "
988 "entry = %d\n", __func__, p_hdr->cmd, index);
992 *Set pointer to next entry in the sequence.
994 p_entry += p_hdr->size;
996 vha->reset_tmplt.seq_index = index;
1000 qla8044_process_init_seq(struct scsi_qla_host *vha)
1002 qla8044_process_reset_template(vha,
1003 vha->reset_tmplt.init_offset);
1004 if (vha->reset_tmplt.seq_end != 1)
1005 ql_log(ql_log_fatal, vha, 0xb098,
1006 "%s: Abrupt INIT Sub-Sequence end.\n",
1011 qla8044_process_stop_seq(struct scsi_qla_host *vha)
1013 vha->reset_tmplt.seq_index = 0;
1014 qla8044_process_reset_template(vha, vha->reset_tmplt.stop_offset);
1015 if (vha->reset_tmplt.seq_end != 1)
1016 ql_log(ql_log_fatal, vha, 0xb099,
1017 "%s: Abrupt STOP Sub-Sequence end.\n", __func__);
1021 qla8044_process_start_seq(struct scsi_qla_host *vha)
1023 qla8044_process_reset_template(vha, vha->reset_tmplt.start_offset);
1024 if (vha->reset_tmplt.template_end != 1)
1025 ql_log(ql_log_fatal, vha, 0xb09a,
1026 "%s: Abrupt START Sub-Sequence end.\n",
1031 qla8044_lockless_flash_read_u32(struct scsi_qla_host *vha,
1032 uint32_t flash_addr, uint8_t *p_data, int u32_word_count)
1036 uint32_t flash_offset;
1037 uint32_t addr = flash_addr;
1038 int ret_val = QLA_SUCCESS;
1040 flash_offset = addr & (QLA8044_FLASH_SECTOR_SIZE - 1);
1043 ql_log(ql_log_fatal, vha, 0xb09b, "%s: Illegal addr = 0x%x\n",
1045 ret_val = QLA_FUNCTION_FAILED;
1046 goto exit_lockless_read;
1049 ret_val = qla8044_wr_reg_indirect(vha,
1050 QLA8044_FLASH_DIRECT_WINDOW, (addr));
1052 if (ret_val != QLA_SUCCESS) {
1053 ql_log(ql_log_fatal, vha, 0xb09c,
1054 "%s: failed to write addr 0x%x to FLASH_DIRECT_WINDOW!\n",
1056 goto exit_lockless_read;
1059 /* Check if data is spread across multiple sectors */
1060 if ((flash_offset + (u32_word_count * sizeof(uint32_t))) >
1061 (QLA8044_FLASH_SECTOR_SIZE - 1)) {
1062 /* Multi sector read */
1063 for (i = 0; i < u32_word_count; i++) {
1064 ret_val = qla8044_rd_reg_indirect(vha,
1065 QLA8044_FLASH_DIRECT_DATA(addr), &u32_word);
1066 if (ret_val != QLA_SUCCESS) {
1067 ql_log(ql_log_fatal, vha, 0xb09d,
1068 "%s: failed to read addr 0x%x!\n",
1070 goto exit_lockless_read;
1072 *(uint32_t *)p_data = u32_word;
1073 p_data = p_data + 4;
1075 flash_offset = flash_offset + 4;
1076 if (flash_offset > (QLA8044_FLASH_SECTOR_SIZE - 1)) {
1077 /* This write is needed once for each sector */
1078 ret_val = qla8044_wr_reg_indirect(vha,
1079 QLA8044_FLASH_DIRECT_WINDOW, (addr));
1080 if (ret_val != QLA_SUCCESS) {
1081 ql_log(ql_log_fatal, vha, 0xb09f,
1082 "%s: failed to write addr "
1083 "0x%x to FLASH_DIRECT_WINDOW!\n",
1085 goto exit_lockless_read;
1091 /* Single sector read */
1092 for (i = 0; i < u32_word_count; i++) {
1093 ret_val = qla8044_rd_reg_indirect(vha,
1094 QLA8044_FLASH_DIRECT_DATA(addr), &u32_word);
1095 if (ret_val != QLA_SUCCESS) {
1096 ql_log(ql_log_fatal, vha, 0xb0a0,
1097 "%s: failed to read addr 0x%x!\n",
1099 goto exit_lockless_read;
1101 *(uint32_t *)p_data = u32_word;
1102 p_data = p_data + 4;
1112 * qla8044_ms_mem_write_128b - Writes data to MS/off-chip memory
1114 * @vha : Pointer to adapter structure
1115 * addr : Flash address to write to
1116 * data : Data to be written
1117 * count : word_count to be written
1119 * Return Value - QLA_SUCCESS/QLA_FUNCTION_FAILED
1122 qla8044_ms_mem_write_128b(struct scsi_qla_host *vha,
1123 uint64_t addr, uint32_t *data, uint32_t count)
1125 int i, j, ret_val = QLA_SUCCESS;
1127 unsigned long flags;
1128 struct qla_hw_data *ha = vha->hw;
1130 /* Only 128-bit aligned access */
1132 ret_val = QLA_FUNCTION_FAILED;
1133 goto exit_ms_mem_write;
1135 write_lock_irqsave(&ha->hw_lock, flags);
1138 ret_val = qla8044_wr_reg_indirect(vha, MD_MIU_TEST_AGT_ADDR_HI, 0);
1139 if (ret_val == QLA_FUNCTION_FAILED) {
1140 ql_log(ql_log_fatal, vha, 0xb0a1,
1141 "%s: write to AGT_ADDR_HI failed!\n", __func__);
1142 goto exit_ms_mem_write_unlock;
1145 for (i = 0; i < count; i++, addr += 16) {
1146 if (!((addr_in_range(addr, QLA8044_ADDR_QDR_NET,
1147 QLA8044_ADDR_QDR_NET_MAX)) ||
1148 (addr_in_range(addr, QLA8044_ADDR_DDR_NET,
1149 QLA8044_ADDR_DDR_NET_MAX)))) {
1150 ret_val = QLA_FUNCTION_FAILED;
1151 goto exit_ms_mem_write_unlock;
1154 ret_val = qla8044_wr_reg_indirect(vha,
1155 MD_MIU_TEST_AGT_ADDR_LO, addr);
1158 ret_val += qla8044_wr_reg_indirect(vha,
1159 MD_MIU_TEST_AGT_WRDATA_LO, *data++);
1160 ret_val += qla8044_wr_reg_indirect(vha,
1161 MD_MIU_TEST_AGT_WRDATA_HI, *data++);
1162 ret_val += qla8044_wr_reg_indirect(vha,
1163 MD_MIU_TEST_AGT_WRDATA_ULO, *data++);
1164 ret_val += qla8044_wr_reg_indirect(vha,
1165 MD_MIU_TEST_AGT_WRDATA_UHI, *data++);
1166 if (ret_val == QLA_FUNCTION_FAILED) {
1167 ql_log(ql_log_fatal, vha, 0xb0a2,
1168 "%s: write to AGT_WRDATA failed!\n",
1170 goto exit_ms_mem_write_unlock;
1173 /* Check write status */
1174 ret_val = qla8044_wr_reg_indirect(vha, MD_MIU_TEST_AGT_CTRL,
1175 MIU_TA_CTL_WRITE_ENABLE);
1176 ret_val += qla8044_wr_reg_indirect(vha, MD_MIU_TEST_AGT_CTRL,
1177 MIU_TA_CTL_WRITE_START);
1178 if (ret_val == QLA_FUNCTION_FAILED) {
1179 ql_log(ql_log_fatal, vha, 0xb0a3,
1180 "%s: write to AGT_CTRL failed!\n", __func__);
1181 goto exit_ms_mem_write_unlock;
1184 for (j = 0; j < MAX_CTL_CHECK; j++) {
1185 ret_val = qla8044_rd_reg_indirect(vha,
1186 MD_MIU_TEST_AGT_CTRL, &agt_ctrl);
1187 if (ret_val == QLA_FUNCTION_FAILED) {
1188 ql_log(ql_log_fatal, vha, 0xb0a4,
1189 "%s: failed to read "
1190 "MD_MIU_TEST_AGT_CTRL!\n", __func__);
1191 goto exit_ms_mem_write_unlock;
1193 if ((agt_ctrl & MIU_TA_CTL_BUSY) == 0)
1197 /* Status check failed */
1198 if (j >= MAX_CTL_CHECK) {
1199 ql_log(ql_log_fatal, vha, 0xb0a5,
1200 "%s: MS memory write failed!\n",
1202 ret_val = QLA_FUNCTION_FAILED;
1203 goto exit_ms_mem_write_unlock;
1207 exit_ms_mem_write_unlock:
1208 write_unlock_irqrestore(&ha->hw_lock, flags);
1215 qla8044_copy_bootloader(struct scsi_qla_host *vha)
1218 uint32_t src, count, size;
1220 int ret_val = QLA_SUCCESS;
1221 struct qla_hw_data *ha = vha->hw;
1223 src = QLA8044_BOOTLOADER_FLASH_ADDR;
1224 dest = qla8044_rd_reg(ha, QLA8044_BOOTLOADER_ADDR);
1225 size = qla8044_rd_reg(ha, QLA8044_BOOTLOADER_SIZE);
1227 /* 128 bit alignment check */
1229 size = (size + 16) & ~0xF;
1234 p_cache = vmalloc(size);
1235 if (p_cache == NULL) {
1236 ql_log(ql_log_fatal, vha, 0xb0a6,
1237 "%s: Failed to allocate memory for "
1238 "boot loader cache\n", __func__);
1239 ret_val = QLA_FUNCTION_FAILED;
1240 goto exit_copy_bootloader;
1243 ret_val = qla8044_lockless_flash_read_u32(vha, src,
1244 p_cache, size/sizeof(uint32_t));
1245 if (ret_val == QLA_FUNCTION_FAILED) {
1246 ql_log(ql_log_fatal, vha, 0xb0a7,
1247 "%s: Error reading F/W from flash!!!\n", __func__);
1248 goto exit_copy_error;
1250 ql_dbg(ql_dbg_p3p, vha, 0xb0a8, "%s: Read F/W from flash!\n",
1253 /* 128 bit/16 byte write to MS memory */
1254 ret_val = qla8044_ms_mem_write_128b(vha, dest,
1255 (uint32_t *)p_cache, count);
1256 if (ret_val == QLA_FUNCTION_FAILED) {
1257 ql_log(ql_log_fatal, vha, 0xb0a9,
1258 "%s: Error writing F/W to MS !!!\n", __func__);
1259 goto exit_copy_error;
1261 ql_dbg(ql_dbg_p3p, vha, 0xb0aa,
1262 "%s: Wrote F/W (size %d) to MS !!!\n",
1268 exit_copy_bootloader:
1273 qla8044_restart(struct scsi_qla_host *vha)
1275 int ret_val = QLA_SUCCESS;
1276 struct qla_hw_data *ha = vha->hw;
1278 qla8044_process_stop_seq(vha);
1280 /* Collect minidump */
1282 qla8044_get_minidump(vha);
1284 ql_log(ql_log_fatal, vha, 0xb14c,
1285 "Minidump disabled.\n");
1287 qla8044_process_init_seq(vha);
1289 if (qla8044_copy_bootloader(vha)) {
1290 ql_log(ql_log_fatal, vha, 0xb0ab,
1291 "%s: Copy bootloader, firmware restart failed!\n",
1293 ret_val = QLA_FUNCTION_FAILED;
1298 * Loads F/W from flash
1300 qla8044_wr_reg(ha, QLA8044_FW_IMAGE_VALID, QLA8044_BOOT_FROM_FLASH);
1302 qla8044_process_start_seq(vha);
1309 * qla8044_check_cmd_peg_status - Check peg status to see if Peg is
1312 * @ha : Pointer to adapter structure
1314 * Return Value - QLA_SUCCESS/QLA_FUNCTION_FAILED
1317 qla8044_check_cmd_peg_status(struct scsi_qla_host *vha)
1319 uint32_t val, ret_val = QLA_FUNCTION_FAILED;
1320 int retries = CRB_CMDPEG_CHECK_RETRY_COUNT;
1321 struct qla_hw_data *ha = vha->hw;
1324 val = qla8044_rd_reg(ha, QLA8044_CMDPEG_STATE);
1325 if (val == PHAN_INITIALIZE_COMPLETE) {
1326 ql_dbg(ql_dbg_p3p, vha, 0xb0ac,
1327 "%s: Command Peg initialization "
1328 "complete! state=0x%x\n", __func__, val);
1329 ret_val = QLA_SUCCESS;
1332 msleep(CRB_CMDPEG_CHECK_DELAY);
1333 } while (--retries);
1339 qla8044_start_firmware(struct scsi_qla_host *vha)
1341 int ret_val = QLA_SUCCESS;
1343 if (qla8044_restart(vha)) {
1344 ql_log(ql_log_fatal, vha, 0xb0ad,
1345 "%s: Restart Error!!!, Need Reset!!!\n",
1347 ret_val = QLA_FUNCTION_FAILED;
1350 ql_dbg(ql_dbg_p3p, vha, 0xb0af,
1351 "%s: Restart done!\n", __func__);
1353 ret_val = qla8044_check_cmd_peg_status(vha);
1355 ql_log(ql_log_fatal, vha, 0xb0b0,
1356 "%s: Peg not initialized!\n", __func__);
1357 ret_val = QLA_FUNCTION_FAILED;
1365 qla8044_clear_drv_active(struct qla_hw_data *ha)
1367 uint32_t drv_active;
1368 struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
1370 drv_active = qla8044_rd_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX);
1371 drv_active &= ~(1 << (ha->portnum));
1373 ql_log(ql_log_info, vha, 0xb0b1,
1374 "%s(%ld): drv_active: 0x%08x\n",
1375 __func__, vha->host_no, drv_active);
1377 qla8044_wr_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX, drv_active);
1381 * qla8044_device_bootstrap - Initialize device, set DEV_READY, start fw
1382 * @ha: pointer to adapter structure
1384 * Note: IDC lock must be held upon entry
1387 qla8044_device_bootstrap(struct scsi_qla_host *vha)
1389 int rval = QLA_FUNCTION_FAILED;
1391 uint32_t old_count = 0, count = 0;
1394 struct qla_hw_data *ha = vha->hw;
1396 need_reset = qla8044_need_reset(vha);
1399 old_count = qla8044_rd_direct(vha,
1400 QLA8044_PEG_ALIVE_COUNTER_INDEX);
1402 for (i = 0; i < 10; i++) {
1405 count = qla8044_rd_direct(vha,
1406 QLA8044_PEG_ALIVE_COUNTER_INDEX);
1407 if (count != old_count) {
1412 qla8044_flash_lock_recovery(vha);
1414 /* We are trying to perform a recovery here. */
1415 if (ha->flags.isp82xx_fw_hung)
1416 qla8044_flash_lock_recovery(vha);
1419 /* set to DEV_INITIALIZING */
1420 ql_log(ql_log_info, vha, 0xb0b2,
1421 "%s: HW State: INITIALIZING\n", __func__);
1422 qla8044_wr_direct(vha, QLA8044_CRB_DEV_STATE_INDEX,
1423 QLA8XXX_DEV_INITIALIZING);
1425 qla8044_idc_unlock(ha);
1426 rval = qla8044_start_firmware(vha);
1427 qla8044_idc_lock(ha);
1429 if (rval != QLA_SUCCESS) {
1430 ql_log(ql_log_info, vha, 0xb0b3,
1431 "%s: HW State: FAILED\n", __func__);
1432 qla8044_clear_drv_active(ha);
1433 qla8044_wr_direct(vha, QLA8044_CRB_DEV_STATE_INDEX,
1434 QLA8XXX_DEV_FAILED);
1438 /* For ISP8044, If IDC_CTRL GRACEFUL_RESET_BIT1 is set , reset it after
1439 * device goes to INIT state. */
1440 idc_ctrl = qla8044_rd_reg(ha, QLA8044_IDC_DRV_CTRL);
1441 if (idc_ctrl & GRACEFUL_RESET_BIT1) {
1442 qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL,
1443 (idc_ctrl & ~GRACEFUL_RESET_BIT1));
1444 ha->fw_dumped = false;
1448 ql_log(ql_log_info, vha, 0xb0b4,
1449 "%s: HW State: READY\n", __func__);
1450 qla8044_wr_direct(vha, QLA8044_CRB_DEV_STATE_INDEX, QLA8XXX_DEV_READY);
1455 /*-------------------------Reset Sequence Functions-----------------------*/
1457 qla8044_dump_reset_seq_hdr(struct scsi_qla_host *vha)
1461 if (!vha->reset_tmplt.buff) {
1462 ql_log(ql_log_fatal, vha, 0xb0b5,
1463 "%s: Error Invalid reset_seq_template\n", __func__);
1467 phdr = vha->reset_tmplt.buff;
1468 ql_dbg(ql_dbg_p3p, vha, 0xb0b6,
1469 "Reset Template :\n\t0x%X 0x%X 0x%X 0x%X"
1470 "0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n"
1471 "\t0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n\n",
1472 *phdr, *(phdr+1), *(phdr+2), *(phdr+3), *(phdr+4),
1473 *(phdr+5), *(phdr+6), *(phdr+7), *(phdr + 8),
1474 *(phdr+9), *(phdr+10), *(phdr+11), *(phdr+12),
1475 *(phdr+13), *(phdr+14), *(phdr+15));
1479 * qla8044_reset_seq_checksum_test - Validate Reset Sequence template.
1481 * @ha : Pointer to adapter structure
1483 * Return Value - QLA_SUCCESS/QLA_FUNCTION_FAILED
1486 qla8044_reset_seq_checksum_test(struct scsi_qla_host *vha)
1489 uint16_t *buff = (uint16_t *)vha->reset_tmplt.buff;
1490 int u16_count = vha->reset_tmplt.hdr->size / sizeof(uint16_t);
1492 while (u16_count-- > 0)
1496 sum = (sum & 0xFFFF) + (sum >> 16);
1498 /* checksum of 0 indicates a valid template */
1502 ql_log(ql_log_fatal, vha, 0xb0b7,
1503 "%s: Reset seq checksum failed\n", __func__);
1504 return QLA_FUNCTION_FAILED;
1509 * qla8044_read_reset_template - Read Reset Template from Flash, validate
1510 * the template and store offsets of stop/start/init offsets in ha->reset_tmplt.
1512 * @ha : Pointer to adapter structure
1515 qla8044_read_reset_template(struct scsi_qla_host *vha)
1518 uint32_t addr, tmplt_hdr_def_size, tmplt_hdr_size;
1520 vha->reset_tmplt.seq_error = 0;
1521 vha->reset_tmplt.buff = vmalloc(QLA8044_RESTART_TEMPLATE_SIZE);
1522 if (vha->reset_tmplt.buff == NULL) {
1523 ql_log(ql_log_fatal, vha, 0xb0b8,
1524 "%s: Failed to allocate reset template resources\n",
1526 goto exit_read_reset_template;
1529 p_buff = vha->reset_tmplt.buff;
1530 addr = QLA8044_RESET_TEMPLATE_ADDR;
1532 tmplt_hdr_def_size =
1533 sizeof(struct qla8044_reset_template_hdr) / sizeof(uint32_t);
1535 ql_dbg(ql_dbg_p3p, vha, 0xb0b9,
1536 "%s: Read template hdr size %d from Flash\n",
1537 __func__, tmplt_hdr_def_size);
1539 /* Copy template header from flash */
1540 if (qla8044_read_flash_data(vha, p_buff, addr, tmplt_hdr_def_size)) {
1541 ql_log(ql_log_fatal, vha, 0xb0ba,
1542 "%s: Failed to read reset template\n", __func__);
1543 goto exit_read_template_error;
1546 vha->reset_tmplt.hdr =
1547 (struct qla8044_reset_template_hdr *) vha->reset_tmplt.buff;
1549 /* Validate the template header size and signature */
1550 tmplt_hdr_size = vha->reset_tmplt.hdr->hdr_size/sizeof(uint32_t);
1551 if ((tmplt_hdr_size != tmplt_hdr_def_size) ||
1552 (vha->reset_tmplt.hdr->signature != RESET_TMPLT_HDR_SIGNATURE)) {
1553 ql_log(ql_log_fatal, vha, 0xb0bb,
1554 "%s: Template Header size invalid %d "
1555 "tmplt_hdr_def_size %d!!!\n", __func__,
1556 tmplt_hdr_size, tmplt_hdr_def_size);
1557 goto exit_read_template_error;
1560 addr = QLA8044_RESET_TEMPLATE_ADDR + vha->reset_tmplt.hdr->hdr_size;
1561 p_buff = vha->reset_tmplt.buff + vha->reset_tmplt.hdr->hdr_size;
1562 tmplt_hdr_def_size = (vha->reset_tmplt.hdr->size -
1563 vha->reset_tmplt.hdr->hdr_size)/sizeof(uint32_t);
1565 ql_dbg(ql_dbg_p3p, vha, 0xb0bc,
1566 "%s: Read rest of the template size %d\n",
1567 __func__, vha->reset_tmplt.hdr->size);
1569 /* Copy rest of the template */
1570 if (qla8044_read_flash_data(vha, p_buff, addr, tmplt_hdr_def_size)) {
1571 ql_log(ql_log_fatal, vha, 0xb0bd,
1572 "%s: Failed to read reset template\n", __func__);
1573 goto exit_read_template_error;
1576 /* Integrity check */
1577 if (qla8044_reset_seq_checksum_test(vha)) {
1578 ql_log(ql_log_fatal, vha, 0xb0be,
1579 "%s: Reset Seq checksum failed!\n", __func__);
1580 goto exit_read_template_error;
1583 ql_dbg(ql_dbg_p3p, vha, 0xb0bf,
1584 "%s: Reset Seq checksum passed! Get stop, "
1585 "start and init seq offsets\n", __func__);
1587 /* Get STOP, START, INIT sequence offsets */
1588 vha->reset_tmplt.init_offset = vha->reset_tmplt.buff +
1589 vha->reset_tmplt.hdr->init_seq_offset;
1591 vha->reset_tmplt.start_offset = vha->reset_tmplt.buff +
1592 vha->reset_tmplt.hdr->start_seq_offset;
1594 vha->reset_tmplt.stop_offset = vha->reset_tmplt.buff +
1595 vha->reset_tmplt.hdr->hdr_size;
1597 qla8044_dump_reset_seq_hdr(vha);
1599 goto exit_read_reset_template;
1601 exit_read_template_error:
1602 vfree(vha->reset_tmplt.buff);
1604 exit_read_reset_template:
1609 qla8044_set_idc_dontreset(struct scsi_qla_host *vha)
1612 struct qla_hw_data *ha = vha->hw;
1614 idc_ctrl = qla8044_rd_reg(ha, QLA8044_IDC_DRV_CTRL);
1615 idc_ctrl |= DONTRESET_BIT0;
1616 ql_dbg(ql_dbg_p3p, vha, 0xb0c0,
1617 "%s: idc_ctrl = %d\n", __func__, idc_ctrl);
1618 qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL, idc_ctrl);
1622 qla8044_set_rst_ready(struct scsi_qla_host *vha)
1625 struct qla_hw_data *ha = vha->hw;
1627 drv_state = qla8044_rd_direct(vha, QLA8044_CRB_DRV_STATE_INDEX);
1629 /* For ISP8044, drv_active register has 1 bit per function,
1630 * shift 1 by func_num to set a bit for the function.*/
1631 drv_state |= (1 << ha->portnum);
1633 ql_log(ql_log_info, vha, 0xb0c1,
1634 "%s(%ld): drv_state: 0x%08x\n",
1635 __func__, vha->host_no, drv_state);
1636 qla8044_wr_direct(vha, QLA8044_CRB_DRV_STATE_INDEX, drv_state);
1640 * qla8044_need_reset_handler - Code to start reset sequence
1641 * @vha: pointer to adapter structure
1643 * Note: IDC lock must be held upon entry
1646 qla8044_need_reset_handler(struct scsi_qla_host *vha)
1648 uint32_t dev_state = 0, drv_state, drv_active;
1649 unsigned long reset_timeout;
1650 struct qla_hw_data *ha = vha->hw;
1652 ql_log(ql_log_fatal, vha, 0xb0c2,
1653 "%s: Performing ISP error recovery\n", __func__);
1655 if (vha->flags.online) {
1656 qla8044_idc_unlock(ha);
1657 qla2x00_abort_isp_cleanup(vha);
1658 ha->isp_ops->get_flash_version(vha, vha->req->ring);
1659 ha->isp_ops->nvram_config(vha);
1660 qla8044_idc_lock(ha);
1663 dev_state = qla8044_rd_direct(vha,
1664 QLA8044_CRB_DEV_STATE_INDEX);
1665 drv_state = qla8044_rd_direct(vha,
1666 QLA8044_CRB_DRV_STATE_INDEX);
1667 drv_active = qla8044_rd_direct(vha,
1668 QLA8044_CRB_DRV_ACTIVE_INDEX);
1670 ql_log(ql_log_info, vha, 0xb0c5,
1671 "%s(%ld): drv_state = 0x%x, drv_active = 0x%x dev_state = 0x%x\n",
1672 __func__, vha->host_no, drv_state, drv_active, dev_state);
1674 qla8044_set_rst_ready(vha);
1676 /* wait for 10 seconds for reset ack from all functions */
1677 reset_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
1680 if (time_after_eq(jiffies, reset_timeout)) {
1681 ql_log(ql_log_info, vha, 0xb0c4,
1682 "%s: Function %d: Reset Ack Timeout!, drv_state: 0x%08x, drv_active: 0x%08x\n",
1683 __func__, ha->portnum, drv_state, drv_active);
1687 qla8044_idc_unlock(ha);
1689 qla8044_idc_lock(ha);
1691 dev_state = qla8044_rd_direct(vha,
1692 QLA8044_CRB_DEV_STATE_INDEX);
1693 drv_state = qla8044_rd_direct(vha,
1694 QLA8044_CRB_DRV_STATE_INDEX);
1695 drv_active = qla8044_rd_direct(vha,
1696 QLA8044_CRB_DRV_ACTIVE_INDEX);
1697 } while (((drv_state & drv_active) != drv_active) &&
1698 (dev_state == QLA8XXX_DEV_NEED_RESET));
1700 /* Remove IDC participation of functions not acknowledging */
1701 if (drv_state != drv_active) {
1702 ql_log(ql_log_info, vha, 0xb0c7,
1703 "%s(%ld): Function %d turning off drv_active of non-acking function 0x%x\n",
1704 __func__, vha->host_no, ha->portnum,
1705 (drv_active ^ drv_state));
1706 drv_active = drv_active & drv_state;
1707 qla8044_wr_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX,
1711 * Reset owner should execute reset recovery,
1712 * if all functions acknowledged
1714 if ((ha->flags.nic_core_reset_owner) &&
1715 (dev_state == QLA8XXX_DEV_NEED_RESET)) {
1716 ha->flags.nic_core_reset_owner = 0;
1717 qla8044_device_bootstrap(vha);
1722 /* Exit if non active function */
1723 if (!(drv_active & (1 << ha->portnum))) {
1724 ha->flags.nic_core_reset_owner = 0;
1729 * Execute Reset Recovery if Reset Owner or Function 7
1730 * is the only active function
1732 if (ha->flags.nic_core_reset_owner ||
1733 ((drv_state & drv_active) == QLA8044_FUN7_ACTIVE_INDEX)) {
1734 ha->flags.nic_core_reset_owner = 0;
1735 qla8044_device_bootstrap(vha);
1740 qla8044_set_drv_active(struct scsi_qla_host *vha)
1742 uint32_t drv_active;
1743 struct qla_hw_data *ha = vha->hw;
1745 drv_active = qla8044_rd_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX);
1747 /* For ISP8044, drv_active register has 1 bit per function,
1748 * shift 1 by func_num to set a bit for the function.*/
1749 drv_active |= (1 << ha->portnum);
1751 ql_log(ql_log_info, vha, 0xb0c8,
1752 "%s(%ld): drv_active: 0x%08x\n",
1753 __func__, vha->host_no, drv_active);
1754 qla8044_wr_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX, drv_active);
1758 qla8044_check_drv_active(struct scsi_qla_host *vha)
1760 uint32_t drv_active;
1761 struct qla_hw_data *ha = vha->hw;
1763 drv_active = qla8044_rd_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX);
1764 if (drv_active & (1 << ha->portnum))
1767 return QLA_TEST_FAILED;
1771 qla8044_clear_idc_dontreset(struct scsi_qla_host *vha)
1774 struct qla_hw_data *ha = vha->hw;
1776 idc_ctrl = qla8044_rd_reg(ha, QLA8044_IDC_DRV_CTRL);
1777 idc_ctrl &= ~DONTRESET_BIT0;
1778 ql_log(ql_log_info, vha, 0xb0c9,
1779 "%s: idc_ctrl = %d\n", __func__,
1781 qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL, idc_ctrl);
1785 qla8044_set_idc_ver(struct scsi_qla_host *vha)
1788 uint32_t drv_active;
1789 int rval = QLA_SUCCESS;
1790 struct qla_hw_data *ha = vha->hw;
1792 drv_active = qla8044_rd_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX);
1793 if (drv_active == (1 << ha->portnum)) {
1794 idc_ver = qla8044_rd_direct(vha,
1795 QLA8044_CRB_DRV_IDC_VERSION_INDEX);
1797 idc_ver |= QLA8044_IDC_VER_MAJ_VALUE;
1798 qla8044_wr_direct(vha, QLA8044_CRB_DRV_IDC_VERSION_INDEX,
1800 ql_log(ql_log_info, vha, 0xb0ca,
1801 "%s: IDC version updated to %d\n",
1804 idc_ver = qla8044_rd_direct(vha,
1805 QLA8044_CRB_DRV_IDC_VERSION_INDEX);
1807 if (QLA8044_IDC_VER_MAJ_VALUE != idc_ver) {
1808 ql_log(ql_log_info, vha, 0xb0cb,
1809 "%s: qla4xxx driver IDC version %d "
1810 "is not compatible with IDC version %d "
1811 "of other drivers!\n",
1812 __func__, QLA8044_IDC_VER_MAJ_VALUE,
1814 rval = QLA_FUNCTION_FAILED;
1815 goto exit_set_idc_ver;
1819 /* Update IDC_MINOR_VERSION */
1820 idc_ver = qla8044_rd_reg(ha, QLA8044_CRB_IDC_VER_MINOR);
1821 idc_ver &= ~(0x03 << (ha->portnum * 2));
1822 idc_ver |= (QLA8044_IDC_VER_MIN_VALUE << (ha->portnum * 2));
1823 qla8044_wr_reg(ha, QLA8044_CRB_IDC_VER_MINOR, idc_ver);
1830 qla8044_update_idc_reg(struct scsi_qla_host *vha)
1832 uint32_t drv_active;
1833 int rval = QLA_SUCCESS;
1834 struct qla_hw_data *ha = vha->hw;
1836 if (vha->flags.init_done)
1837 goto exit_update_idc_reg;
1839 qla8044_idc_lock(ha);
1840 qla8044_set_drv_active(vha);
1842 drv_active = qla8044_rd_direct(vha,
1843 QLA8044_CRB_DRV_ACTIVE_INDEX);
1845 /* If we are the first driver to load and
1846 * ql2xdontresethba is not set, clear IDC_CTRL BIT0. */
1847 if ((drv_active == (1 << ha->portnum)) && !ql2xdontresethba)
1848 qla8044_clear_idc_dontreset(vha);
1850 rval = qla8044_set_idc_ver(vha);
1851 if (rval == QLA_FUNCTION_FAILED)
1852 qla8044_clear_drv_active(ha);
1853 qla8044_idc_unlock(ha);
1855 exit_update_idc_reg:
1860 * qla8044_need_qsnt_handler - Code to start qsnt
1861 * @vha: pointer to adapter structure
1864 qla8044_need_qsnt_handler(struct scsi_qla_host *vha)
1866 unsigned long qsnt_timeout;
1867 uint32_t drv_state, drv_active, dev_state;
1868 struct qla_hw_data *ha = vha->hw;
1870 if (vha->flags.online)
1871 qla2x00_quiesce_io(vha);
1875 qla8044_set_qsnt_ready(vha);
1877 /* Wait for 30 secs for all functions to ack qsnt mode */
1878 qsnt_timeout = jiffies + (QSNT_ACK_TOV * HZ);
1879 drv_state = qla8044_rd_direct(vha, QLA8044_CRB_DRV_STATE_INDEX);
1880 drv_active = qla8044_rd_direct(vha, QLA8044_CRB_DRV_ACTIVE_INDEX);
1882 /* Shift drv_active by 1 to match drv_state. As quiescent ready bit
1883 position is at bit 1 and drv active is at bit 0 */
1884 drv_active = drv_active << 1;
1886 while (drv_state != drv_active) {
1887 if (time_after_eq(jiffies, qsnt_timeout)) {
1888 /* Other functions did not ack, changing state to
1891 clear_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags);
1892 qla8044_wr_direct(vha, QLA8044_CRB_DEV_STATE_INDEX,
1894 qla8044_clear_qsnt_ready(vha);
1895 ql_log(ql_log_info, vha, 0xb0cc,
1896 "Timeout waiting for quiescent ack!!!\n");
1899 qla8044_idc_unlock(ha);
1901 qla8044_idc_lock(ha);
1903 drv_state = qla8044_rd_direct(vha,
1904 QLA8044_CRB_DRV_STATE_INDEX);
1905 drv_active = qla8044_rd_direct(vha,
1906 QLA8044_CRB_DRV_ACTIVE_INDEX);
1907 drv_active = drv_active << 1;
1910 /* All functions have Acked. Set quiescent state */
1911 dev_state = qla8044_rd_direct(vha, QLA8044_CRB_DEV_STATE_INDEX);
1913 if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
1914 qla8044_wr_direct(vha, QLA8044_CRB_DEV_STATE_INDEX,
1915 QLA8XXX_DEV_QUIESCENT);
1916 ql_log(ql_log_info, vha, 0xb0cd,
1917 "%s: HW State: QUIESCENT\n", __func__);
1922 * qla8044_device_state_handler - Adapter state machine
1923 * @ha: pointer to host adapter structure.
1925 * Note: IDC lock must be UNLOCKED upon entry
1928 qla8044_device_state_handler(struct scsi_qla_host *vha)
1931 int rval = QLA_SUCCESS;
1932 unsigned long dev_init_timeout;
1933 struct qla_hw_data *ha = vha->hw;
1935 rval = qla8044_update_idc_reg(vha);
1936 if (rval == QLA_FUNCTION_FAILED)
1939 dev_state = qla8044_rd_direct(vha, QLA8044_CRB_DEV_STATE_INDEX);
1940 ql_dbg(ql_dbg_p3p, vha, 0xb0ce,
1941 "Device state is 0x%x = %s\n",
1942 dev_state, dev_state < MAX_STATES ?
1943 qdev_state(dev_state) : "Unknown");
1945 /* wait for 30 seconds for device to go ready */
1946 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
1948 qla8044_idc_lock(ha);
1951 if (time_after_eq(jiffies, dev_init_timeout)) {
1952 if (qla8044_check_drv_active(vha) == QLA_SUCCESS) {
1953 ql_log(ql_log_warn, vha, 0xb0cf,
1954 "%s: Device Init Failed 0x%x = %s\n",
1955 QLA2XXX_DRIVER_NAME, dev_state,
1956 dev_state < MAX_STATES ?
1957 qdev_state(dev_state) : "Unknown");
1958 qla8044_wr_direct(vha,
1959 QLA8044_CRB_DEV_STATE_INDEX,
1960 QLA8XXX_DEV_FAILED);
1964 dev_state = qla8044_rd_direct(vha, QLA8044_CRB_DEV_STATE_INDEX);
1965 ql_log(ql_log_info, vha, 0xb0d0,
1966 "Device state is 0x%x = %s\n",
1967 dev_state, dev_state < MAX_STATES ?
1968 qdev_state(dev_state) : "Unknown");
1970 /* NOTE: Make sure idc unlocked upon exit of switch statement */
1971 switch (dev_state) {
1972 case QLA8XXX_DEV_READY:
1973 ha->flags.nic_core_reset_owner = 0;
1975 case QLA8XXX_DEV_COLD:
1976 rval = qla8044_device_bootstrap(vha);
1978 case QLA8XXX_DEV_INITIALIZING:
1979 qla8044_idc_unlock(ha);
1981 qla8044_idc_lock(ha);
1983 case QLA8XXX_DEV_NEED_RESET:
1984 /* For ISP8044, if NEED_RESET is set by any driver,
1985 * it should be honored, irrespective of IDC_CTRL
1987 qla8044_need_reset_handler(vha);
1989 case QLA8XXX_DEV_NEED_QUIESCENT:
1990 /* idc locked/unlocked in handler */
1991 qla8044_need_qsnt_handler(vha);
1993 /* Reset the init timeout after qsnt handler */
1994 dev_init_timeout = jiffies +
1995 (ha->fcoe_reset_timeout * HZ);
1997 case QLA8XXX_DEV_QUIESCENT:
1998 ql_log(ql_log_info, vha, 0xb0d1,
1999 "HW State: QUIESCENT\n");
2001 qla8044_idc_unlock(ha);
2003 qla8044_idc_lock(ha);
2005 /* Reset the init timeout after qsnt handler */
2006 dev_init_timeout = jiffies +
2007 (ha->fcoe_reset_timeout * HZ);
2009 case QLA8XXX_DEV_FAILED:
2010 ha->flags.nic_core_reset_owner = 0;
2011 qla8044_idc_unlock(ha);
2012 qla8xxx_dev_failed_handler(vha);
2013 rval = QLA_FUNCTION_FAILED;
2014 qla8044_idc_lock(ha);
2017 qla8044_idc_unlock(ha);
2018 qla8xxx_dev_failed_handler(vha);
2019 rval = QLA_FUNCTION_FAILED;
2020 qla8044_idc_lock(ha);
2025 qla8044_idc_unlock(ha);
2032 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
2033 * @vha: adapter block pointer.
2035 * Note: The caller should not hold the idc lock.
2038 qla8044_check_temp(struct scsi_qla_host *vha)
2040 uint32_t temp, temp_state, temp_val;
2041 int status = QLA_SUCCESS;
2043 temp = qla8044_rd_direct(vha, QLA8044_CRB_TEMP_STATE_INDEX);
2044 temp_state = qla82xx_get_temp_state(temp);
2045 temp_val = qla82xx_get_temp_val(temp);
2047 if (temp_state == QLA82XX_TEMP_PANIC) {
2048 ql_log(ql_log_warn, vha, 0xb0d2,
2049 "Device temperature %d degrees C"
2050 " exceeds maximum allowed. Hardware has been shut"
2051 " down\n", temp_val);
2052 status = QLA_FUNCTION_FAILED;
2054 } else if (temp_state == QLA82XX_TEMP_WARN) {
2055 ql_log(ql_log_warn, vha, 0xb0d3,
2056 "Device temperature %d"
2057 " degrees C exceeds operating range."
2058 " Immediate action needed.\n", temp_val);
2063 int qla8044_read_temperature(scsi_qla_host_t *vha)
2067 temp = qla8044_rd_direct(vha, QLA8044_CRB_TEMP_STATE_INDEX);
2068 return qla82xx_get_temp_val(temp);
2072 * qla8044_check_fw_alive - Check firmware health
2073 * @vha: Pointer to host adapter structure.
2075 * Context: Interrupt
2078 qla8044_check_fw_alive(struct scsi_qla_host *vha)
2080 uint32_t fw_heartbeat_counter;
2081 uint32_t halt_status1, halt_status2;
2082 int status = QLA_SUCCESS;
2084 fw_heartbeat_counter = qla8044_rd_direct(vha,
2085 QLA8044_PEG_ALIVE_COUNTER_INDEX);
2087 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
2088 if (fw_heartbeat_counter == 0xffffffff) {
2089 ql_dbg(ql_dbg_p3p, vha, 0xb0d4,
2090 "scsi%ld: %s: Device in frozen "
2091 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
2092 vha->host_no, __func__);
2096 if (vha->fw_heartbeat_counter == fw_heartbeat_counter) {
2097 vha->seconds_since_last_heartbeat++;
2098 /* FW not alive after 2 seconds */
2099 if (vha->seconds_since_last_heartbeat == 2) {
2100 vha->seconds_since_last_heartbeat = 0;
2101 halt_status1 = qla8044_rd_direct(vha,
2102 QLA8044_PEG_HALT_STATUS1_INDEX);
2103 halt_status2 = qla8044_rd_direct(vha,
2104 QLA8044_PEG_HALT_STATUS2_INDEX);
2106 ql_log(ql_log_info, vha, 0xb0d5,
2107 "scsi(%ld): %s, ISP8044 "
2108 "Dumping hw/fw registers:\n"
2109 " PEG_HALT_STATUS1: 0x%x, "
2110 "PEG_HALT_STATUS2: 0x%x,\n",
2111 vha->host_no, __func__, halt_status1,
2113 status = QLA_FUNCTION_FAILED;
2116 vha->seconds_since_last_heartbeat = 0;
2118 vha->fw_heartbeat_counter = fw_heartbeat_counter;
2123 qla8044_watchdog(struct scsi_qla_host *vha)
2125 uint32_t dev_state, halt_status;
2126 int halt_status_unrecoverable = 0;
2127 struct qla_hw_data *ha = vha->hw;
2129 /* don't poll if reset is going on or FW hang in quiescent state */
2130 if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
2131 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))) {
2132 dev_state = qla8044_rd_direct(vha, QLA8044_CRB_DEV_STATE_INDEX);
2134 if (qla8044_check_fw_alive(vha)) {
2135 ha->flags.isp82xx_fw_hung = 1;
2136 ql_log(ql_log_warn, vha, 0xb10a,
2137 "Firmware hung.\n");
2138 qla82xx_clear_pending_mbx(vha);
2141 if (qla8044_check_temp(vha)) {
2142 set_bit(ISP_UNRECOVERABLE, &vha->dpc_flags);
2143 ha->flags.isp82xx_fw_hung = 1;
2144 qla2xxx_wake_dpc(vha);
2145 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
2146 !test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) {
2147 ql_log(ql_log_info, vha, 0xb0d6,
2148 "%s: HW State: NEED RESET!\n",
2150 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2151 qla2xxx_wake_dpc(vha);
2152 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
2153 !test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags)) {
2154 ql_log(ql_log_info, vha, 0xb0d7,
2155 "%s: HW State: NEED QUIES detected!\n",
2157 set_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags);
2158 qla2xxx_wake_dpc(vha);
2160 /* Check firmware health */
2161 if (ha->flags.isp82xx_fw_hung) {
2162 halt_status = qla8044_rd_direct(vha,
2163 QLA8044_PEG_HALT_STATUS1_INDEX);
2165 QLA8044_HALT_STATUS_FW_RESET) {
2166 ql_log(ql_log_fatal, vha,
2167 0xb0d8, "%s: Firmware "
2168 "error detected device "
2171 } else if (halt_status &
2172 QLA8044_HALT_STATUS_UNRECOVERABLE) {
2173 halt_status_unrecoverable = 1;
2176 /* Since we cannot change dev_state in interrupt
2177 * context, set appropriate DPC flag then wakeup
2179 if (halt_status_unrecoverable) {
2180 set_bit(ISP_UNRECOVERABLE,
2184 QLA8XXX_DEV_QUIESCENT) {
2185 set_bit(FCOE_CTX_RESET_NEEDED,
2187 ql_log(ql_log_info, vha, 0xb0d9,
2188 "%s: FW CONTEXT Reset "
2189 "needed!\n", __func__);
2191 ql_log(ql_log_info, vha,
2193 "detect abort needed\n",
2195 set_bit(ISP_ABORT_NEEDED,
2199 qla2xxx_wake_dpc(vha);
2207 qla8044_minidump_process_control(struct scsi_qla_host *vha,
2208 struct qla8044_minidump_entry_hdr *entry_hdr)
2210 struct qla8044_minidump_entry_crb *crb_entry;
2211 uint32_t read_value, opcode, poll_time, addr, index;
2212 uint32_t crb_addr, rval = QLA_SUCCESS;
2213 unsigned long wtime;
2214 struct qla8044_minidump_template_hdr *tmplt_hdr;
2216 struct qla_hw_data *ha = vha->hw;
2218 ql_dbg(ql_dbg_p3p, vha, 0xb0dd, "Entering fn: %s\n", __func__);
2219 tmplt_hdr = (struct qla8044_minidump_template_hdr *)
2221 crb_entry = (struct qla8044_minidump_entry_crb *)entry_hdr;
2223 crb_addr = crb_entry->addr;
2224 for (i = 0; i < crb_entry->op_count; i++) {
2225 opcode = crb_entry->crb_ctrl.opcode;
2227 if (opcode & QLA82XX_DBG_OPCODE_WR) {
2228 qla8044_wr_reg_indirect(vha, crb_addr,
2229 crb_entry->value_1);
2230 opcode &= ~QLA82XX_DBG_OPCODE_WR;
2233 if (opcode & QLA82XX_DBG_OPCODE_RW) {
2234 qla8044_rd_reg_indirect(vha, crb_addr, &read_value);
2235 qla8044_wr_reg_indirect(vha, crb_addr, read_value);
2236 opcode &= ~QLA82XX_DBG_OPCODE_RW;
2239 if (opcode & QLA82XX_DBG_OPCODE_AND) {
2240 qla8044_rd_reg_indirect(vha, crb_addr, &read_value);
2241 read_value &= crb_entry->value_2;
2242 opcode &= ~QLA82XX_DBG_OPCODE_AND;
2243 if (opcode & QLA82XX_DBG_OPCODE_OR) {
2244 read_value |= crb_entry->value_3;
2245 opcode &= ~QLA82XX_DBG_OPCODE_OR;
2247 qla8044_wr_reg_indirect(vha, crb_addr, read_value);
2249 if (opcode & QLA82XX_DBG_OPCODE_OR) {
2250 qla8044_rd_reg_indirect(vha, crb_addr, &read_value);
2251 read_value |= crb_entry->value_3;
2252 qla8044_wr_reg_indirect(vha, crb_addr, read_value);
2253 opcode &= ~QLA82XX_DBG_OPCODE_OR;
2255 if (opcode & QLA82XX_DBG_OPCODE_POLL) {
2256 poll_time = crb_entry->crb_strd.poll_timeout;
2257 wtime = jiffies + poll_time;
2258 qla8044_rd_reg_indirect(vha, crb_addr, &read_value);
2261 if ((read_value & crb_entry->value_2) ==
2262 crb_entry->value_1) {
2264 } else if (time_after_eq(jiffies, wtime)) {
2265 /* capturing dump failed */
2266 rval = QLA_FUNCTION_FAILED;
2269 qla8044_rd_reg_indirect(vha,
2270 crb_addr, &read_value);
2273 opcode &= ~QLA82XX_DBG_OPCODE_POLL;
2276 if (opcode & QLA82XX_DBG_OPCODE_RDSTATE) {
2277 if (crb_entry->crb_strd.state_index_a) {
2278 index = crb_entry->crb_strd.state_index_a;
2279 addr = tmplt_hdr->saved_state_array[index];
2284 qla8044_rd_reg_indirect(vha, addr, &read_value);
2285 index = crb_entry->crb_ctrl.state_index_v;
2286 tmplt_hdr->saved_state_array[index] = read_value;
2287 opcode &= ~QLA82XX_DBG_OPCODE_RDSTATE;
2290 if (opcode & QLA82XX_DBG_OPCODE_WRSTATE) {
2291 if (crb_entry->crb_strd.state_index_a) {
2292 index = crb_entry->crb_strd.state_index_a;
2293 addr = tmplt_hdr->saved_state_array[index];
2298 if (crb_entry->crb_ctrl.state_index_v) {
2299 index = crb_entry->crb_ctrl.state_index_v;
2301 tmplt_hdr->saved_state_array[index];
2303 read_value = crb_entry->value_1;
2306 qla8044_wr_reg_indirect(vha, addr, read_value);
2307 opcode &= ~QLA82XX_DBG_OPCODE_WRSTATE;
2310 if (opcode & QLA82XX_DBG_OPCODE_MDSTATE) {
2311 index = crb_entry->crb_ctrl.state_index_v;
2312 read_value = tmplt_hdr->saved_state_array[index];
2313 read_value <<= crb_entry->crb_ctrl.shl;
2314 read_value >>= crb_entry->crb_ctrl.shr;
2315 if (crb_entry->value_2)
2316 read_value &= crb_entry->value_2;
2317 read_value |= crb_entry->value_3;
2318 read_value += crb_entry->value_1;
2319 tmplt_hdr->saved_state_array[index] = read_value;
2320 opcode &= ~QLA82XX_DBG_OPCODE_MDSTATE;
2322 crb_addr += crb_entry->crb_strd.addr_stride;
2328 qla8044_minidump_process_rdcrb(struct scsi_qla_host *vha,
2329 struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
2331 uint32_t r_addr, r_stride, loop_cnt, i, r_value;
2332 struct qla8044_minidump_entry_crb *crb_hdr;
2333 uint32_t *data_ptr = *d_ptr;
2335 ql_dbg(ql_dbg_p3p, vha, 0xb0de, "Entering fn: %s\n", __func__);
2336 crb_hdr = (struct qla8044_minidump_entry_crb *)entry_hdr;
2337 r_addr = crb_hdr->addr;
2338 r_stride = crb_hdr->crb_strd.addr_stride;
2339 loop_cnt = crb_hdr->op_count;
2341 for (i = 0; i < loop_cnt; i++) {
2342 qla8044_rd_reg_indirect(vha, r_addr, &r_value);
2343 *data_ptr++ = r_addr;
2344 *data_ptr++ = r_value;
2351 qla8044_minidump_process_rdmem(struct scsi_qla_host *vha,
2352 struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
2354 uint32_t r_addr, r_value, r_data;
2355 uint32_t i, j, loop_cnt;
2356 struct qla8044_minidump_entry_rdmem *m_hdr;
2357 unsigned long flags;
2358 uint32_t *data_ptr = *d_ptr;
2359 struct qla_hw_data *ha = vha->hw;
2361 ql_dbg(ql_dbg_p3p, vha, 0xb0df, "Entering fn: %s\n", __func__);
2362 m_hdr = (struct qla8044_minidump_entry_rdmem *)entry_hdr;
2363 r_addr = m_hdr->read_addr;
2364 loop_cnt = m_hdr->read_data_size/16;
2366 ql_dbg(ql_dbg_p3p, vha, 0xb0f0,
2367 "[%s]: Read addr: 0x%x, read_data_size: 0x%x\n",
2368 __func__, r_addr, m_hdr->read_data_size);
2371 ql_dbg(ql_dbg_p3p, vha, 0xb0f1,
2372 "[%s]: Read addr 0x%x not 16 bytes aligned\n",
2374 return QLA_FUNCTION_FAILED;
2377 if (m_hdr->read_data_size % 16) {
2378 ql_dbg(ql_dbg_p3p, vha, 0xb0f2,
2379 "[%s]: Read data[0x%x] not multiple of 16 bytes\n",
2380 __func__, m_hdr->read_data_size);
2381 return QLA_FUNCTION_FAILED;
2384 ql_dbg(ql_dbg_p3p, vha, 0xb0f3,
2385 "[%s]: rdmem_addr: 0x%x, read_data_size: 0x%x, loop_cnt: 0x%x\n",
2386 __func__, r_addr, m_hdr->read_data_size, loop_cnt);
2388 write_lock_irqsave(&ha->hw_lock, flags);
2389 for (i = 0; i < loop_cnt; i++) {
2390 qla8044_wr_reg_indirect(vha, MD_MIU_TEST_AGT_ADDR_LO, r_addr);
2392 qla8044_wr_reg_indirect(vha, MD_MIU_TEST_AGT_ADDR_HI, r_value);
2393 r_value = MIU_TA_CTL_ENABLE;
2394 qla8044_wr_reg_indirect(vha, MD_MIU_TEST_AGT_CTRL, r_value);
2395 r_value = MIU_TA_CTL_START_ENABLE;
2396 qla8044_wr_reg_indirect(vha, MD_MIU_TEST_AGT_CTRL, r_value);
2398 for (j = 0; j < MAX_CTL_CHECK; j++) {
2399 qla8044_rd_reg_indirect(vha, MD_MIU_TEST_AGT_CTRL,
2401 if ((r_value & MIU_TA_CTL_BUSY) == 0)
2405 if (j >= MAX_CTL_CHECK) {
2406 write_unlock_irqrestore(&ha->hw_lock, flags);
2410 for (j = 0; j < 4; j++) {
2411 qla8044_rd_reg_indirect(vha, MD_MIU_TEST_AGT_RDDATA[j],
2413 *data_ptr++ = r_data;
2418 write_unlock_irqrestore(&ha->hw_lock, flags);
2420 ql_dbg(ql_dbg_p3p, vha, 0xb0f4,
2421 "Leaving fn: %s datacount: 0x%x\n",
2422 __func__, (loop_cnt * 16));
2428 /* ISP83xx flash read for _RDROM _BOARD */
2430 qla8044_minidump_process_rdrom(struct scsi_qla_host *vha,
2431 struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
2433 uint32_t fl_addr, u32_count, rval;
2434 struct qla8044_minidump_entry_rdrom *rom_hdr;
2435 uint32_t *data_ptr = *d_ptr;
2437 rom_hdr = (struct qla8044_minidump_entry_rdrom *)entry_hdr;
2438 fl_addr = rom_hdr->read_addr;
2439 u32_count = (rom_hdr->read_data_size)/sizeof(uint32_t);
2441 ql_dbg(ql_dbg_p3p, vha, 0xb0f5, "[%s]: fl_addr: 0x%x, count: 0x%x\n",
2442 __func__, fl_addr, u32_count);
2444 rval = qla8044_lockless_flash_read_u32(vha, fl_addr,
2445 (u8 *)(data_ptr), u32_count);
2447 if (rval != QLA_SUCCESS) {
2448 ql_log(ql_log_fatal, vha, 0xb0f6,
2449 "%s: Flash Read Error,Count=%d\n", __func__, u32_count);
2450 return QLA_FUNCTION_FAILED;
2452 data_ptr += u32_count;
2459 qla8044_mark_entry_skipped(struct scsi_qla_host *vha,
2460 struct qla8044_minidump_entry_hdr *entry_hdr, int index)
2462 entry_hdr->d_ctrl.driver_flags |= QLA82XX_DBG_SKIPPED_FLAG;
2464 ql_log(ql_log_info, vha, 0xb0f7,
2465 "scsi(%ld): Skipping entry[%d]: ETYPE[0x%x]-ELEVEL[0x%x]\n",
2466 vha->host_no, index, entry_hdr->entry_type,
2467 entry_hdr->d_ctrl.entry_capture_mask);
2471 qla8044_minidump_process_l2tag(struct scsi_qla_host *vha,
2472 struct qla8044_minidump_entry_hdr *entry_hdr,
2475 uint32_t addr, r_addr, c_addr, t_r_addr;
2476 uint32_t i, k, loop_count, t_value, r_cnt, r_value;
2477 unsigned long p_wait, w_time, p_mask;
2478 uint32_t c_value_w, c_value_r;
2479 struct qla8044_minidump_entry_cache *cache_hdr;
2480 int rval = QLA_FUNCTION_FAILED;
2481 uint32_t *data_ptr = *d_ptr;
2483 ql_dbg(ql_dbg_p3p, vha, 0xb0f8, "Entering fn: %s\n", __func__);
2484 cache_hdr = (struct qla8044_minidump_entry_cache *)entry_hdr;
2486 loop_count = cache_hdr->op_count;
2487 r_addr = cache_hdr->read_addr;
2488 c_addr = cache_hdr->control_addr;
2489 c_value_w = cache_hdr->cache_ctrl.write_value;
2491 t_r_addr = cache_hdr->tag_reg_addr;
2492 t_value = cache_hdr->addr_ctrl.init_tag_value;
2493 r_cnt = cache_hdr->read_ctrl.read_addr_cnt;
2494 p_wait = cache_hdr->cache_ctrl.poll_wait;
2495 p_mask = cache_hdr->cache_ctrl.poll_mask;
2497 for (i = 0; i < loop_count; i++) {
2498 qla8044_wr_reg_indirect(vha, t_r_addr, t_value);
2500 qla8044_wr_reg_indirect(vha, c_addr, c_value_w);
2503 w_time = jiffies + p_wait;
2505 qla8044_rd_reg_indirect(vha, c_addr,
2507 if ((c_value_r & p_mask) == 0) {
2509 } else if (time_after_eq(jiffies, w_time)) {
2510 /* capturing dump failed */
2517 for (k = 0; k < r_cnt; k++) {
2518 qla8044_rd_reg_indirect(vha, addr, &r_value);
2519 *data_ptr++ = r_value;
2520 addr += cache_hdr->read_ctrl.read_addr_stride;
2522 t_value += cache_hdr->addr_ctrl.tag_value_stride;
2529 qla8044_minidump_process_l1cache(struct scsi_qla_host *vha,
2530 struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
2532 uint32_t addr, r_addr, c_addr, t_r_addr;
2533 uint32_t i, k, loop_count, t_value, r_cnt, r_value;
2535 struct qla8044_minidump_entry_cache *cache_hdr;
2536 uint32_t *data_ptr = *d_ptr;
2538 cache_hdr = (struct qla8044_minidump_entry_cache *)entry_hdr;
2539 loop_count = cache_hdr->op_count;
2540 r_addr = cache_hdr->read_addr;
2541 c_addr = cache_hdr->control_addr;
2542 c_value_w = cache_hdr->cache_ctrl.write_value;
2544 t_r_addr = cache_hdr->tag_reg_addr;
2545 t_value = cache_hdr->addr_ctrl.init_tag_value;
2546 r_cnt = cache_hdr->read_ctrl.read_addr_cnt;
2548 for (i = 0; i < loop_count; i++) {
2549 qla8044_wr_reg_indirect(vha, t_r_addr, t_value);
2550 qla8044_wr_reg_indirect(vha, c_addr, c_value_w);
2552 for (k = 0; k < r_cnt; k++) {
2553 qla8044_rd_reg_indirect(vha, addr, &r_value);
2554 *data_ptr++ = r_value;
2555 addr += cache_hdr->read_ctrl.read_addr_stride;
2557 t_value += cache_hdr->addr_ctrl.tag_value_stride;
2563 qla8044_minidump_process_rdocm(struct scsi_qla_host *vha,
2564 struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
2566 uint32_t r_addr, r_stride, loop_cnt, i, r_value;
2567 struct qla8044_minidump_entry_rdocm *ocm_hdr;
2568 uint32_t *data_ptr = *d_ptr;
2569 struct qla_hw_data *ha = vha->hw;
2571 ql_dbg(ql_dbg_p3p, vha, 0xb0f9, "Entering fn: %s\n", __func__);
2573 ocm_hdr = (struct qla8044_minidump_entry_rdocm *)entry_hdr;
2574 r_addr = ocm_hdr->read_addr;
2575 r_stride = ocm_hdr->read_addr_stride;
2576 loop_cnt = ocm_hdr->op_count;
2578 ql_dbg(ql_dbg_p3p, vha, 0xb0fa,
2579 "[%s]: r_addr: 0x%x, r_stride: 0x%x, loop_cnt: 0x%x\n",
2580 __func__, r_addr, r_stride, loop_cnt);
2582 for (i = 0; i < loop_cnt; i++) {
2583 r_value = readl((void __iomem *)(r_addr + ha->nx_pcibase));
2584 *data_ptr++ = r_value;
2587 ql_dbg(ql_dbg_p3p, vha, 0xb0fb, "Leaving fn: %s datacount: 0x%lx\n",
2588 __func__, (long unsigned int) (loop_cnt * sizeof(uint32_t)));
2594 qla8044_minidump_process_rdmux(struct scsi_qla_host *vha,
2595 struct qla8044_minidump_entry_hdr *entry_hdr,
2598 uint32_t r_addr, s_stride, s_addr, s_value, loop_cnt, i, r_value;
2599 struct qla8044_minidump_entry_mux *mux_hdr;
2600 uint32_t *data_ptr = *d_ptr;
2602 ql_dbg(ql_dbg_p3p, vha, 0xb0fc, "Entering fn: %s\n", __func__);
2604 mux_hdr = (struct qla8044_minidump_entry_mux *)entry_hdr;
2605 r_addr = mux_hdr->read_addr;
2606 s_addr = mux_hdr->select_addr;
2607 s_stride = mux_hdr->select_value_stride;
2608 s_value = mux_hdr->select_value;
2609 loop_cnt = mux_hdr->op_count;
2611 for (i = 0; i < loop_cnt; i++) {
2612 qla8044_wr_reg_indirect(vha, s_addr, s_value);
2613 qla8044_rd_reg_indirect(vha, r_addr, &r_value);
2614 *data_ptr++ = s_value;
2615 *data_ptr++ = r_value;
2616 s_value += s_stride;
2622 qla8044_minidump_process_queue(struct scsi_qla_host *vha,
2623 struct qla8044_minidump_entry_hdr *entry_hdr,
2626 uint32_t s_addr, r_addr;
2627 uint32_t r_stride, r_value, r_cnt, qid = 0;
2628 uint32_t i, k, loop_cnt;
2629 struct qla8044_minidump_entry_queue *q_hdr;
2630 uint32_t *data_ptr = *d_ptr;
2632 ql_dbg(ql_dbg_p3p, vha, 0xb0fd, "Entering fn: %s\n", __func__);
2633 q_hdr = (struct qla8044_minidump_entry_queue *)entry_hdr;
2634 s_addr = q_hdr->select_addr;
2635 r_cnt = q_hdr->rd_strd.read_addr_cnt;
2636 r_stride = q_hdr->rd_strd.read_addr_stride;
2637 loop_cnt = q_hdr->op_count;
2639 for (i = 0; i < loop_cnt; i++) {
2640 qla8044_wr_reg_indirect(vha, s_addr, qid);
2641 r_addr = q_hdr->read_addr;
2642 for (k = 0; k < r_cnt; k++) {
2643 qla8044_rd_reg_indirect(vha, r_addr, &r_value);
2644 *data_ptr++ = r_value;
2647 qid += q_hdr->q_strd.queue_id_stride;
2652 /* ISP83xx functions to process new minidump entries... */
2654 qla8044_minidump_process_pollrd(struct scsi_qla_host *vha,
2655 struct qla8044_minidump_entry_hdr *entry_hdr,
2658 uint32_t r_addr, s_addr, s_value, r_value, poll_wait, poll_mask;
2659 uint16_t s_stride, i;
2660 struct qla8044_minidump_entry_pollrd *pollrd_hdr;
2661 uint32_t *data_ptr = *d_ptr;
2663 pollrd_hdr = (struct qla8044_minidump_entry_pollrd *) entry_hdr;
2664 s_addr = pollrd_hdr->select_addr;
2665 r_addr = pollrd_hdr->read_addr;
2666 s_value = pollrd_hdr->select_value;
2667 s_stride = pollrd_hdr->select_value_stride;
2669 poll_wait = pollrd_hdr->poll_wait;
2670 poll_mask = pollrd_hdr->poll_mask;
2672 for (i = 0; i < pollrd_hdr->op_count; i++) {
2673 qla8044_wr_reg_indirect(vha, s_addr, s_value);
2674 poll_wait = pollrd_hdr->poll_wait;
2676 qla8044_rd_reg_indirect(vha, s_addr, &r_value);
2677 if ((r_value & poll_mask) != 0) {
2680 usleep_range(1000, 1100);
2681 if (--poll_wait == 0) {
2682 ql_log(ql_log_fatal, vha, 0xb0fe,
2683 "%s: TIMEOUT\n", __func__);
2688 qla8044_rd_reg_indirect(vha, r_addr, &r_value);
2689 *data_ptr++ = s_value;
2690 *data_ptr++ = r_value;
2692 s_value += s_stride;
2698 return QLA_FUNCTION_FAILED;
2702 qla8044_minidump_process_rdmux2(struct scsi_qla_host *vha,
2703 struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
2705 uint32_t sel_val1, sel_val2, t_sel_val, data, i;
2706 uint32_t sel_addr1, sel_addr2, sel_val_mask, read_addr;
2707 struct qla8044_minidump_entry_rdmux2 *rdmux2_hdr;
2708 uint32_t *data_ptr = *d_ptr;
2710 rdmux2_hdr = (struct qla8044_minidump_entry_rdmux2 *) entry_hdr;
2711 sel_val1 = rdmux2_hdr->select_value_1;
2712 sel_val2 = rdmux2_hdr->select_value_2;
2713 sel_addr1 = rdmux2_hdr->select_addr_1;
2714 sel_addr2 = rdmux2_hdr->select_addr_2;
2715 sel_val_mask = rdmux2_hdr->select_value_mask;
2716 read_addr = rdmux2_hdr->read_addr;
2718 for (i = 0; i < rdmux2_hdr->op_count; i++) {
2719 qla8044_wr_reg_indirect(vha, sel_addr1, sel_val1);
2720 t_sel_val = sel_val1 & sel_val_mask;
2721 *data_ptr++ = t_sel_val;
2723 qla8044_wr_reg_indirect(vha, sel_addr2, t_sel_val);
2724 qla8044_rd_reg_indirect(vha, read_addr, &data);
2728 qla8044_wr_reg_indirect(vha, sel_addr1, sel_val2);
2729 t_sel_val = sel_val2 & sel_val_mask;
2730 *data_ptr++ = t_sel_val;
2732 qla8044_wr_reg_indirect(vha, sel_addr2, t_sel_val);
2733 qla8044_rd_reg_indirect(vha, read_addr, &data);
2737 sel_val1 += rdmux2_hdr->select_value_stride;
2738 sel_val2 += rdmux2_hdr->select_value_stride;
2745 qla8044_minidump_process_pollrdmwr(struct scsi_qla_host *vha,
2746 struct qla8044_minidump_entry_hdr *entry_hdr,
2749 uint32_t poll_wait, poll_mask, r_value, data;
2750 uint32_t addr_1, addr_2, value_1, value_2;
2751 struct qla8044_minidump_entry_pollrdmwr *poll_hdr;
2752 uint32_t *data_ptr = *d_ptr;
2754 poll_hdr = (struct qla8044_minidump_entry_pollrdmwr *) entry_hdr;
2755 addr_1 = poll_hdr->addr_1;
2756 addr_2 = poll_hdr->addr_2;
2757 value_1 = poll_hdr->value_1;
2758 value_2 = poll_hdr->value_2;
2759 poll_mask = poll_hdr->poll_mask;
2761 qla8044_wr_reg_indirect(vha, addr_1, value_1);
2763 poll_wait = poll_hdr->poll_wait;
2765 qla8044_rd_reg_indirect(vha, addr_1, &r_value);
2767 if ((r_value & poll_mask) != 0) {
2770 usleep_range(1000, 1100);
2771 if (--poll_wait == 0) {
2772 ql_log(ql_log_fatal, vha, 0xb0ff,
2773 "%s: TIMEOUT\n", __func__);
2779 qla8044_rd_reg_indirect(vha, addr_2, &data);
2780 data &= poll_hdr->modify_mask;
2781 qla8044_wr_reg_indirect(vha, addr_2, data);
2782 qla8044_wr_reg_indirect(vha, addr_1, value_2);
2784 poll_wait = poll_hdr->poll_wait;
2786 qla8044_rd_reg_indirect(vha, addr_1, &r_value);
2788 if ((r_value & poll_mask) != 0) {
2791 usleep_range(1000, 1100);
2792 if (--poll_wait == 0) {
2793 ql_log(ql_log_fatal, vha, 0xb100,
2794 "%s: TIMEOUT2\n", __func__);
2800 *data_ptr++ = addr_2;
2808 return QLA_FUNCTION_FAILED;
2811 #define ISP8044_PEX_DMA_ENGINE_INDEX 8
2812 #define ISP8044_PEX_DMA_BASE_ADDRESS 0x77320000
2813 #define ISP8044_PEX_DMA_NUM_OFFSET 0x10000UL
2814 #define ISP8044_PEX_DMA_CMD_ADDR_LOW 0x0
2815 #define ISP8044_PEX_DMA_CMD_ADDR_HIGH 0x04
2816 #define ISP8044_PEX_DMA_CMD_STS_AND_CNTRL 0x08
2818 #define ISP8044_PEX_DMA_READ_SIZE (16 * 1024)
2819 #define ISP8044_PEX_DMA_MAX_WAIT (100 * 100) /* Max wait of 100 msecs */
2822 qla8044_check_dma_engine_state(struct scsi_qla_host *vha)
2824 struct qla_hw_data *ha = vha->hw;
2825 int rval = QLA_SUCCESS;
2826 uint32_t dma_eng_num = 0, cmd_sts_and_cntrl = 0;
2827 uint64_t dma_base_addr = 0;
2828 struct qla8044_minidump_template_hdr *tmplt_hdr = NULL;
2830 tmplt_hdr = ha->md_tmplt_hdr;
2832 tmplt_hdr->saved_state_array[ISP8044_PEX_DMA_ENGINE_INDEX];
2833 dma_base_addr = ISP8044_PEX_DMA_BASE_ADDRESS +
2834 (dma_eng_num * ISP8044_PEX_DMA_NUM_OFFSET);
2836 /* Read the pex-dma's command-status-and-control register. */
2837 rval = qla8044_rd_reg_indirect(vha,
2838 (dma_base_addr + ISP8044_PEX_DMA_CMD_STS_AND_CNTRL),
2839 &cmd_sts_and_cntrl);
2841 return QLA_FUNCTION_FAILED;
2843 /* Check if requested pex-dma engine is available. */
2844 if (cmd_sts_and_cntrl & BIT_31)
2847 return QLA_FUNCTION_FAILED;
2851 qla8044_start_pex_dma(struct scsi_qla_host *vha,
2852 struct qla8044_minidump_entry_rdmem_pex_dma *m_hdr)
2854 struct qla_hw_data *ha = vha->hw;
2855 int rval = QLA_SUCCESS, wait = 0;
2856 uint32_t dma_eng_num = 0, cmd_sts_and_cntrl = 0;
2857 uint64_t dma_base_addr = 0;
2858 struct qla8044_minidump_template_hdr *tmplt_hdr = NULL;
2860 tmplt_hdr = ha->md_tmplt_hdr;
2862 tmplt_hdr->saved_state_array[ISP8044_PEX_DMA_ENGINE_INDEX];
2863 dma_base_addr = ISP8044_PEX_DMA_BASE_ADDRESS +
2864 (dma_eng_num * ISP8044_PEX_DMA_NUM_OFFSET);
2866 rval = qla8044_wr_reg_indirect(vha,
2867 dma_base_addr + ISP8044_PEX_DMA_CMD_ADDR_LOW,
2868 m_hdr->desc_card_addr);
2872 rval = qla8044_wr_reg_indirect(vha,
2873 dma_base_addr + ISP8044_PEX_DMA_CMD_ADDR_HIGH, 0);
2877 rval = qla8044_wr_reg_indirect(vha,
2878 dma_base_addr + ISP8044_PEX_DMA_CMD_STS_AND_CNTRL,
2879 m_hdr->start_dma_cmd);
2883 /* Wait for dma operation to complete. */
2884 for (wait = 0; wait < ISP8044_PEX_DMA_MAX_WAIT; wait++) {
2885 rval = qla8044_rd_reg_indirect(vha,
2886 (dma_base_addr + ISP8044_PEX_DMA_CMD_STS_AND_CNTRL),
2887 &cmd_sts_and_cntrl);
2891 if ((cmd_sts_and_cntrl & BIT_1) == 0)
2897 /* Wait a max of 100 ms, otherwise fallback to rdmem entry read */
2898 if (wait >= ISP8044_PEX_DMA_MAX_WAIT) {
2899 rval = QLA_FUNCTION_FAILED;
2908 qla8044_minidump_pex_dma_read(struct scsi_qla_host *vha,
2909 struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
2911 struct qla_hw_data *ha = vha->hw;
2912 int rval = QLA_SUCCESS;
2913 struct qla8044_minidump_entry_rdmem_pex_dma *m_hdr = NULL;
2914 uint32_t chunk_size, read_size;
2915 uint8_t *data_ptr = (uint8_t *)*d_ptr;
2916 void *rdmem_buffer = NULL;
2917 dma_addr_t rdmem_dma;
2918 struct qla8044_pex_dma_descriptor dma_desc;
2920 rval = qla8044_check_dma_engine_state(vha);
2921 if (rval != QLA_SUCCESS) {
2922 ql_dbg(ql_dbg_p3p, vha, 0xb147,
2923 "DMA engine not available. Fallback to rdmem-read.\n");
2924 return QLA_FUNCTION_FAILED;
2927 m_hdr = (void *)entry_hdr;
2929 rdmem_buffer = dma_alloc_coherent(&ha->pdev->dev,
2930 ISP8044_PEX_DMA_READ_SIZE, &rdmem_dma, GFP_KERNEL);
2931 if (!rdmem_buffer) {
2932 ql_dbg(ql_dbg_p3p, vha, 0xb148,
2933 "Unable to allocate rdmem dma buffer\n");
2934 return QLA_FUNCTION_FAILED;
2937 /* Prepare pex-dma descriptor to be written to MS memory. */
2938 /* dma-desc-cmd layout:
2939 * 0-3: dma-desc-cmd 0-3
2940 * 4-7: pcid function number
2941 * 8-15: dma-desc-cmd 8-15
2942 * dma_bus_addr: dma buffer address
2943 * cmd.read_data_size: amount of data-chunk to be read.
2945 dma_desc.cmd.dma_desc_cmd = (m_hdr->dma_desc_cmd & 0xff0f);
2946 dma_desc.cmd.dma_desc_cmd |=
2947 ((PCI_FUNC(ha->pdev->devfn) & 0xf) << 0x4);
2949 dma_desc.dma_bus_addr = rdmem_dma;
2950 dma_desc.cmd.read_data_size = chunk_size = ISP8044_PEX_DMA_READ_SIZE;
2954 * Perform rdmem operation using pex-dma.
2955 * Prepare dma in chunks of ISP8044_PEX_DMA_READ_SIZE.
2957 while (read_size < m_hdr->read_data_size) {
2958 if (m_hdr->read_data_size - read_size <
2959 ISP8044_PEX_DMA_READ_SIZE) {
2960 chunk_size = (m_hdr->read_data_size - read_size);
2961 dma_desc.cmd.read_data_size = chunk_size;
2964 dma_desc.src_addr = m_hdr->read_addr + read_size;
2966 /* Prepare: Write pex-dma descriptor to MS memory. */
2967 rval = qla8044_ms_mem_write_128b(vha,
2968 m_hdr->desc_card_addr, (void *)&dma_desc,
2969 (sizeof(struct qla8044_pex_dma_descriptor)/16));
2971 ql_log(ql_log_warn, vha, 0xb14a,
2972 "%s: Error writing rdmem-dma-init to MS !!!\n",
2976 ql_dbg(ql_dbg_p3p, vha, 0xb14b,
2977 "%s: Dma-descriptor: Instruct for rdmem dma "
2978 "(chunk_size 0x%x).\n", __func__, chunk_size);
2980 /* Execute: Start pex-dma operation. */
2981 rval = qla8044_start_pex_dma(vha, m_hdr);
2985 memcpy(data_ptr, rdmem_buffer, chunk_size);
2986 data_ptr += chunk_size;
2987 read_size += chunk_size;
2990 *d_ptr = (void *)data_ptr;
2994 dma_free_coherent(&ha->pdev->dev, ISP8044_PEX_DMA_READ_SIZE,
2995 rdmem_buffer, rdmem_dma);
3001 qla8044_minidump_process_rddfe(struct scsi_qla_host *vha,
3002 struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
3005 uint32_t addr1, addr2, value, data, temp, wrVal;
3006 uint8_t stride, stride2;
3008 uint32_t poll, mask, modify_mask;
3009 uint32_t wait_count = 0;
3010 uint32_t *data_ptr = *d_ptr;
3011 struct qla8044_minidump_entry_rddfe *rddfe;
3013 rddfe = (struct qla8044_minidump_entry_rddfe *) entry_hdr;
3015 addr1 = rddfe->addr_1;
3016 value = rddfe->value;
3017 stride = rddfe->stride;
3018 stride2 = rddfe->stride2;
3019 count = rddfe->count;
3023 modify_mask = rddfe->modify_mask;
3025 addr2 = addr1 + stride;
3027 for (loop_cnt = 0x0; loop_cnt < count; loop_cnt++) {
3028 qla8044_wr_reg_indirect(vha, addr1, (0x40000000 | value));
3031 while (wait_count < poll) {
3032 qla8044_rd_reg_indirect(vha, addr1, &temp);
3033 if ((temp & mask) != 0)
3038 if (wait_count == poll) {
3039 ql_log(ql_log_warn, vha, 0xb153,
3040 "%s: TIMEOUT\n", __func__);
3043 qla8044_rd_reg_indirect(vha, addr2, &temp);
3044 temp = temp & modify_mask;
3045 temp = (temp | ((loop_cnt << 16) | loop_cnt));
3046 wrVal = ((temp << 16) | temp);
3048 qla8044_wr_reg_indirect(vha, addr2, wrVal);
3049 qla8044_wr_reg_indirect(vha, addr1, value);
3052 while (wait_count < poll) {
3053 qla8044_rd_reg_indirect(vha, addr1, &temp);
3054 if ((temp & mask) != 0)
3058 if (wait_count == poll) {
3059 ql_log(ql_log_warn, vha, 0xb154,
3060 "%s: TIMEOUT\n", __func__);
3064 qla8044_wr_reg_indirect(vha, addr1,
3065 ((0x40000000 | value) + stride2));
3067 while (wait_count < poll) {
3068 qla8044_rd_reg_indirect(vha, addr1, &temp);
3069 if ((temp & mask) != 0)
3074 if (wait_count == poll) {
3075 ql_log(ql_log_warn, vha, 0xb155,
3076 "%s: TIMEOUT\n", __func__);
3080 qla8044_rd_reg_indirect(vha, addr2, &data);
3082 *data_ptr++ = wrVal;
3097 qla8044_minidump_process_rdmdio(struct scsi_qla_host *vha,
3098 struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
3101 uint32_t addr1, addr2, value1, value2, data, selVal;
3102 uint8_t stride1, stride2;
3103 uint32_t addr3, addr4, addr5, addr6, addr7;
3104 uint16_t count, loop_cnt;
3106 uint32_t *data_ptr = *d_ptr;
3108 struct qla8044_minidump_entry_rdmdio *rdmdio;
3110 rdmdio = (struct qla8044_minidump_entry_rdmdio *) entry_hdr;
3112 addr1 = rdmdio->addr_1;
3113 addr2 = rdmdio->addr_2;
3114 value1 = rdmdio->value_1;
3115 stride1 = rdmdio->stride_1;
3116 stride2 = rdmdio->stride_2;
3117 count = rdmdio->count;
3119 mask = rdmdio->mask;
3120 value2 = rdmdio->value_2;
3122 addr3 = addr1 + stride1;
3124 for (loop_cnt = 0; loop_cnt < count; loop_cnt++) {
3125 ret = qla8044_poll_wait_ipmdio_bus_idle(vha, addr1, addr2,
3130 addr4 = addr2 - stride1;
3131 ret = qla8044_ipmdio_wr_reg(vha, addr1, addr3, mask, addr4,
3136 addr5 = addr2 - (2 * stride1);
3137 ret = qla8044_ipmdio_wr_reg(vha, addr1, addr3, mask, addr5,
3142 addr6 = addr2 - (3 * stride1);
3143 ret = qla8044_ipmdio_wr_reg(vha, addr1, addr3, mask,
3148 ret = qla8044_poll_wait_ipmdio_bus_idle(vha, addr1, addr2,
3153 addr7 = addr2 - (4 * stride1);
3154 data = qla8044_ipmdio_rd_reg(vha, addr1, addr3, mask, addr7);
3158 selVal = (value2 << 18) | (value1 << 2) | 2;
3160 stride2 = rdmdio->stride_2;
3161 *data_ptr++ = selVal;
3164 value1 = value1 + stride2;
3174 static uint32_t qla8044_minidump_process_pollwr(struct scsi_qla_host *vha,
3175 struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
3177 uint32_t addr1, addr2, value1, value2, poll, r_value;
3178 uint32_t wait_count = 0;
3179 struct qla8044_minidump_entry_pollwr *pollwr_hdr;
3181 pollwr_hdr = (struct qla8044_minidump_entry_pollwr *)entry_hdr;
3182 addr1 = pollwr_hdr->addr_1;
3183 addr2 = pollwr_hdr->addr_2;
3184 value1 = pollwr_hdr->value_1;
3185 value2 = pollwr_hdr->value_2;
3187 poll = pollwr_hdr->poll;
3189 while (wait_count < poll) {
3190 qla8044_rd_reg_indirect(vha, addr1, &r_value);
3192 if ((r_value & poll) != 0)
3197 if (wait_count == poll) {
3198 ql_log(ql_log_warn, vha, 0xb156, "%s: TIMEOUT\n", __func__);
3202 qla8044_wr_reg_indirect(vha, addr2, value2);
3203 qla8044_wr_reg_indirect(vha, addr1, value1);
3206 while (wait_count < poll) {
3207 qla8044_rd_reg_indirect(vha, addr1, &r_value);
3209 if ((r_value & poll) != 0)
3222 * qla8044_collect_md_data - Retrieve firmware minidump data.
3223 * @ha: pointer to adapter structure
3226 qla8044_collect_md_data(struct scsi_qla_host *vha)
3228 int num_entry_hdr = 0;
3229 struct qla8044_minidump_entry_hdr *entry_hdr;
3230 struct qla8044_minidump_template_hdr *tmplt_hdr;
3232 uint32_t data_collected = 0, f_capture_mask;
3233 int i, rval = QLA_FUNCTION_FAILED;
3235 uint32_t timestamp, idc_control;
3236 struct qla_hw_data *ha = vha->hw;
3239 ql_log(ql_log_info, vha, 0xb101,
3240 "%s(%ld) No buffer to dump\n",
3241 __func__, vha->host_no);
3245 if (ha->fw_dumped) {
3246 ql_log(ql_log_warn, vha, 0xb10d,
3247 "Firmware has been previously dumped (%p) "
3248 "-- ignoring request.\n", ha->fw_dump);
3252 ha->fw_dumped = false;
3254 if (!ha->md_tmplt_hdr || !ha->md_dump) {
3255 ql_log(ql_log_warn, vha, 0xb10e,
3256 "Memory not allocated for minidump capture\n");
3260 qla8044_idc_lock(ha);
3261 idc_control = qla8044_rd_reg(ha, QLA8044_IDC_DRV_CTRL);
3262 if (idc_control & GRACEFUL_RESET_BIT1) {
3263 ql_log(ql_log_warn, vha, 0xb112,
3264 "Forced reset from application, "
3265 "ignore minidump capture\n");
3266 qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL,
3267 (idc_control & ~GRACEFUL_RESET_BIT1));
3268 qla8044_idc_unlock(ha);
3272 qla8044_idc_unlock(ha);
3274 if (qla82xx_validate_template_chksum(vha)) {
3275 ql_log(ql_log_info, vha, 0xb109,
3276 "Template checksum validation error\n");
3280 tmplt_hdr = (struct qla8044_minidump_template_hdr *)
3282 data_ptr = (uint32_t *)((uint8_t *)ha->md_dump);
3283 num_entry_hdr = tmplt_hdr->num_of_entries;
3285 ql_dbg(ql_dbg_p3p, vha, 0xb11a,
3286 "Capture Mask obtained: 0x%x\n", tmplt_hdr->capture_debug_level);
3288 f_capture_mask = tmplt_hdr->capture_debug_level & 0xFF;
3290 /* Validate whether required debug level is set */
3291 if ((f_capture_mask & 0x3) != 0x3) {
3292 ql_log(ql_log_warn, vha, 0xb10f,
3293 "Minimum required capture mask[0x%x] level not set\n",
3297 tmplt_hdr->driver_capture_mask = ql2xmdcapmask;
3298 ql_log(ql_log_info, vha, 0xb102,
3299 "[%s]: starting data ptr: %p\n",
3300 __func__, data_ptr);
3301 ql_log(ql_log_info, vha, 0xb10b,
3302 "[%s]: no of entry headers in Template: 0x%x\n",
3303 __func__, num_entry_hdr);
3304 ql_log(ql_log_info, vha, 0xb10c,
3305 "[%s]: Total_data_size 0x%x, %d obtained\n",
3306 __func__, ha->md_dump_size, ha->md_dump_size);
3308 /* Update current timestamp before taking dump */
3309 now = get_jiffies_64();
3310 timestamp = (u32)(jiffies_to_msecs(now) / 1000);
3311 tmplt_hdr->driver_timestamp = timestamp;
3313 entry_hdr = (struct qla8044_minidump_entry_hdr *)
3314 (((uint8_t *)ha->md_tmplt_hdr) + tmplt_hdr->first_entry_offset);
3315 tmplt_hdr->saved_state_array[QLA8044_SS_OCM_WNDREG_INDEX] =
3316 tmplt_hdr->ocm_window_reg[ha->portnum];
3318 /* Walk through the entry headers - validate/perform required action */
3319 for (i = 0; i < num_entry_hdr; i++) {
3320 if (data_collected > ha->md_dump_size) {
3321 ql_log(ql_log_info, vha, 0xb103,
3322 "Data collected: [0x%x], "
3323 "Total Dump size: [0x%x]\n",
3324 data_collected, ha->md_dump_size);
3328 if (!(entry_hdr->d_ctrl.entry_capture_mask &
3330 entry_hdr->d_ctrl.driver_flags |=
3331 QLA82XX_DBG_SKIPPED_FLAG;
3332 goto skip_nxt_entry;
3335 ql_dbg(ql_dbg_p3p, vha, 0xb104,
3336 "Data collected: [0x%x], Dump size left:[0x%x]\n",
3338 (ha->md_dump_size - data_collected));
3340 /* Decode the entry type and take required action to capture
3343 switch (entry_hdr->entry_type) {
3345 qla8044_mark_entry_skipped(vha, entry_hdr, i);
3348 rval = qla8044_minidump_process_control(vha,
3350 if (rval != QLA_SUCCESS) {
3351 qla8044_mark_entry_skipped(vha, entry_hdr, i);
3356 qla8044_minidump_process_rdcrb(vha,
3357 entry_hdr, &data_ptr);
3360 rval = qla8044_minidump_pex_dma_read(vha,
3361 entry_hdr, &data_ptr);
3362 if (rval != QLA_SUCCESS) {
3363 rval = qla8044_minidump_process_rdmem(vha,
3364 entry_hdr, &data_ptr);
3365 if (rval != QLA_SUCCESS) {
3366 qla8044_mark_entry_skipped(vha,
3374 rval = qla8044_minidump_process_rdrom(vha,
3375 entry_hdr, &data_ptr);
3376 if (rval != QLA_SUCCESS) {
3377 qla8044_mark_entry_skipped(vha,
3385 rval = qla8044_minidump_process_l2tag(vha,
3386 entry_hdr, &data_ptr);
3387 if (rval != QLA_SUCCESS) {
3388 qla8044_mark_entry_skipped(vha, entry_hdr, i);
3396 qla8044_minidump_process_l1cache(vha,
3397 entry_hdr, &data_ptr);
3400 qla8044_minidump_process_rdocm(vha,
3401 entry_hdr, &data_ptr);
3404 qla8044_minidump_process_rdmux(vha,
3405 entry_hdr, &data_ptr);
3408 qla8044_minidump_process_queue(vha,
3409 entry_hdr, &data_ptr);
3411 case QLA8044_POLLRD:
3412 rval = qla8044_minidump_process_pollrd(vha,
3413 entry_hdr, &data_ptr);
3414 if (rval != QLA_SUCCESS)
3415 qla8044_mark_entry_skipped(vha, entry_hdr, i);
3417 case QLA8044_RDMUX2:
3418 qla8044_minidump_process_rdmux2(vha,
3419 entry_hdr, &data_ptr);
3421 case QLA8044_POLLRDMWR:
3422 rval = qla8044_minidump_process_pollrdmwr(vha,
3423 entry_hdr, &data_ptr);
3424 if (rval != QLA_SUCCESS)
3425 qla8044_mark_entry_skipped(vha, entry_hdr, i);
3428 rval = qla8044_minidump_process_rddfe(vha, entry_hdr,
3430 if (rval != QLA_SUCCESS)
3431 qla8044_mark_entry_skipped(vha, entry_hdr, i);
3433 case QLA8044_RDMDIO:
3434 rval = qla8044_minidump_process_rdmdio(vha, entry_hdr,
3436 if (rval != QLA_SUCCESS)
3437 qla8044_mark_entry_skipped(vha, entry_hdr, i);
3439 case QLA8044_POLLWR:
3440 rval = qla8044_minidump_process_pollwr(vha, entry_hdr,
3442 if (rval != QLA_SUCCESS)
3443 qla8044_mark_entry_skipped(vha, entry_hdr, i);
3447 qla8044_mark_entry_skipped(vha, entry_hdr, i);
3451 data_collected = (uint8_t *)data_ptr -
3452 (uint8_t *)((uint8_t *)ha->md_dump);
3455 * next entry in the template
3457 entry_hdr = (struct qla8044_minidump_entry_hdr *)
3458 (((uint8_t *)entry_hdr) + entry_hdr->entry_size);
3461 if (data_collected != ha->md_dump_size) {
3462 ql_log(ql_log_info, vha, 0xb105,
3463 "Dump data mismatch: Data collected: "
3464 "[0x%x], total_data_size:[0x%x]\n",
3465 data_collected, ha->md_dump_size);
3466 rval = QLA_FUNCTION_FAILED;
3470 ql_log(ql_log_info, vha, 0xb110,
3471 "Firmware dump saved to temp buffer (%ld/%p %ld/%p).\n",
3472 vha->host_no, ha->md_tmplt_hdr, vha->host_no, ha->md_dump);
3473 ha->fw_dumped = true;
3474 qla2x00_post_uevent_work(vha, QLA_UEVENT_CODE_FW_DUMP);
3477 ql_log(ql_log_info, vha, 0xb106,
3478 "Leaving fn: %s Last entry: 0x%x\n",
3485 qla8044_get_minidump(struct scsi_qla_host *vha)
3487 struct qla_hw_data *ha = vha->hw;
3489 if (!qla8044_collect_md_data(vha)) {
3490 ha->fw_dumped = true;
3491 ha->prev_minidump_failed = 0;
3493 ql_log(ql_log_fatal, vha, 0xb0db,
3494 "%s: Unable to collect minidump\n",
3496 ha->prev_minidump_failed = 1;
3501 qla8044_poll_flash_status_reg(struct scsi_qla_host *vha)
3503 uint32_t flash_status;
3504 int retries = QLA8044_FLASH_READ_RETRY_COUNT;
3505 int ret_val = QLA_SUCCESS;
3508 ret_val = qla8044_rd_reg_indirect(vha, QLA8044_FLASH_STATUS,
3511 ql_log(ql_log_warn, vha, 0xb13c,
3512 "%s: Failed to read FLASH_STATUS reg.\n",
3516 if ((flash_status & QLA8044_FLASH_STATUS_READY) ==
3517 QLA8044_FLASH_STATUS_READY)
3519 msleep(QLA8044_FLASH_STATUS_REG_POLL_DELAY);
3523 ret_val = QLA_FUNCTION_FAILED;
3529 qla8044_write_flash_status_reg(struct scsi_qla_host *vha,
3532 int ret_val = QLA_SUCCESS;
3535 cmd = vha->hw->fdt_wrt_sts_reg_cmd;
3537 ret_val = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_ADDR,
3538 QLA8044_FLASH_STATUS_WRITE_DEF_SIG | cmd);
3540 ql_log(ql_log_warn, vha, 0xb125,
3541 "%s: Failed to write to FLASH_ADDR.\n", __func__);
3545 ret_val = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_WRDATA, data);
3547 ql_log(ql_log_warn, vha, 0xb126,
3548 "%s: Failed to write to FLASH_WRDATA.\n", __func__);
3552 ret_val = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_CONTROL,
3553 QLA8044_FLASH_SECOND_ERASE_MS_VAL);
3555 ql_log(ql_log_warn, vha, 0xb127,
3556 "%s: Failed to write to FLASH_CONTROL.\n", __func__);
3560 ret_val = qla8044_poll_flash_status_reg(vha);
3562 ql_log(ql_log_warn, vha, 0xb128,
3563 "%s: Error polling flash status reg.\n", __func__);
3570 * This function assumes that the flash lock is held.
3573 qla8044_unprotect_flash(scsi_qla_host_t *vha)
3576 struct qla_hw_data *ha = vha->hw;
3578 ret_val = qla8044_write_flash_status_reg(vha, ha->fdt_wrt_enable);
3580 ql_log(ql_log_warn, vha, 0xb139,
3581 "%s: Write flash status failed.\n", __func__);
3587 * This function assumes that the flash lock is held.
3590 qla8044_protect_flash(scsi_qla_host_t *vha)
3593 struct qla_hw_data *ha = vha->hw;
3595 ret_val = qla8044_write_flash_status_reg(vha, ha->fdt_wrt_disable);
3597 ql_log(ql_log_warn, vha, 0xb13b,
3598 "%s: Write flash status failed.\n", __func__);
3605 qla8044_erase_flash_sector(struct scsi_qla_host *vha,
3606 uint32_t sector_start_addr)
3608 uint32_t reversed_addr;
3609 int ret_val = QLA_SUCCESS;
3611 ret_val = qla8044_poll_flash_status_reg(vha);
3613 ql_log(ql_log_warn, vha, 0xb12e,
3614 "%s: Poll flash status after erase failed..\n", __func__);
3617 reversed_addr = (((sector_start_addr & 0xFF) << 16) |
3618 (sector_start_addr & 0xFF00) |
3619 ((sector_start_addr & 0xFF0000) >> 16));
3621 ret_val = qla8044_wr_reg_indirect(vha,
3622 QLA8044_FLASH_WRDATA, reversed_addr);
3624 ql_log(ql_log_warn, vha, 0xb12f,
3625 "%s: Failed to write to FLASH_WRDATA.\n", __func__);
3627 ret_val = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_ADDR,
3628 QLA8044_FLASH_ERASE_SIG | vha->hw->fdt_erase_cmd);
3630 ql_log(ql_log_warn, vha, 0xb130,
3631 "%s: Failed to write to FLASH_ADDR.\n", __func__);
3633 ret_val = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_CONTROL,
3634 QLA8044_FLASH_LAST_ERASE_MS_VAL);
3636 ql_log(ql_log_warn, vha, 0xb131,
3637 "%s: Failed write to FLASH_CONTROL.\n", __func__);
3639 ret_val = qla8044_poll_flash_status_reg(vha);
3641 ql_log(ql_log_warn, vha, 0xb132,
3642 "%s: Poll flash status failed.\n", __func__);
3650 * qla8044_flash_write_u32 - Write data to flash
3652 * @ha : Pointer to adapter structure
3653 * addr : Flash address to write to
3654 * p_data : Data to be written
3656 * Return Value - QLA_SUCCESS/QLA_FUNCTION_FAILED
3658 * NOTE: Lock should be held on entry
3661 qla8044_flash_write_u32(struct scsi_qla_host *vha, uint32_t addr,
3664 int ret_val = QLA_SUCCESS;
3666 ret_val = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_ADDR,
3667 0x00800000 | (addr >> 2));
3669 ql_log(ql_log_warn, vha, 0xb134,
3670 "%s: Failed write to FLASH_ADDR.\n", __func__);
3673 ret_val = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_WRDATA, *p_data);
3675 ql_log(ql_log_warn, vha, 0xb135,
3676 "%s: Failed write to FLASH_WRDATA.\n", __func__);
3679 ret_val = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_CONTROL, 0x3D);
3681 ql_log(ql_log_warn, vha, 0xb136,
3682 "%s: Failed write to FLASH_CONTROL.\n", __func__);
3685 ret_val = qla8044_poll_flash_status_reg(vha);
3687 ql_log(ql_log_warn, vha, 0xb137,
3688 "%s: Poll flash status failed.\n", __func__);
3696 qla8044_write_flash_buffer_mode(scsi_qla_host_t *vha, uint32_t *dwptr,
3697 uint32_t faddr, uint32_t dwords)
3699 int ret = QLA_FUNCTION_FAILED;
3702 if (dwords < QLA8044_MIN_OPTROM_BURST_DWORDS ||
3703 dwords > QLA8044_MAX_OPTROM_BURST_DWORDS) {
3704 ql_dbg(ql_dbg_user, vha, 0xb123,
3705 "Got unsupported dwords = 0x%x.\n",
3707 return QLA_FUNCTION_FAILED;
3710 qla8044_rd_reg_indirect(vha, QLA8044_FLASH_SPI_CONTROL, &spi_val);
3711 qla8044_wr_reg_indirect(vha, QLA8044_FLASH_SPI_CONTROL,
3712 spi_val | QLA8044_FLASH_SPI_CTL);
3713 qla8044_wr_reg_indirect(vha, QLA8044_FLASH_ADDR,
3714 QLA8044_FLASH_FIRST_TEMP_VAL);
3716 /* First DWORD write to FLASH_WRDATA */
3717 ret = qla8044_wr_reg_indirect(vha, QLA8044_FLASH_WRDATA,
3719 qla8044_wr_reg_indirect(vha, QLA8044_FLASH_CONTROL,
3720 QLA8044_FLASH_FIRST_MS_PATTERN);
3722 ret = qla8044_poll_flash_status_reg(vha);
3724 ql_log(ql_log_warn, vha, 0xb124,
3725 "%s: Failed.\n", __func__);
3731 qla8044_wr_reg_indirect(vha, QLA8044_FLASH_ADDR,
3732 QLA8044_FLASH_SECOND_TEMP_VAL);
3735 /* Second to N-1 DWORDS writes */
3736 while (dwords != 1) {
3737 qla8044_wr_reg_indirect(vha, QLA8044_FLASH_WRDATA, *dwptr++);
3738 qla8044_wr_reg_indirect(vha, QLA8044_FLASH_CONTROL,
3739 QLA8044_FLASH_SECOND_MS_PATTERN);
3740 ret = qla8044_poll_flash_status_reg(vha);
3742 ql_log(ql_log_warn, vha, 0xb129,
3743 "%s: Failed.\n", __func__);
3749 qla8044_wr_reg_indirect(vha, QLA8044_FLASH_ADDR,
3750 QLA8044_FLASH_FIRST_TEMP_VAL | (faddr >> 2));
3752 /* Last DWORD write */
3753 qla8044_wr_reg_indirect(vha, QLA8044_FLASH_WRDATA, *dwptr++);
3754 qla8044_wr_reg_indirect(vha, QLA8044_FLASH_CONTROL,
3755 QLA8044_FLASH_LAST_MS_PATTERN);
3756 ret = qla8044_poll_flash_status_reg(vha);
3758 ql_log(ql_log_warn, vha, 0xb12a,
3759 "%s: Failed.\n", __func__);
3762 qla8044_rd_reg_indirect(vha, QLA8044_FLASH_SPI_STATUS, &spi_val);
3764 if ((spi_val & QLA8044_FLASH_SPI_CTL) == QLA8044_FLASH_SPI_CTL) {
3765 ql_log(ql_log_warn, vha, 0xb12b,
3766 "%s: Failed.\n", __func__);
3768 /* Operation failed, clear error bit. */
3769 qla8044_rd_reg_indirect(vha, QLA8044_FLASH_SPI_CONTROL,
3771 qla8044_wr_reg_indirect(vha, QLA8044_FLASH_SPI_CONTROL,
3772 spi_val | QLA8044_FLASH_SPI_CTL);
3779 qla8044_write_flash_dword_mode(scsi_qla_host_t *vha, uint32_t *dwptr,
3780 uint32_t faddr, uint32_t dwords)
3782 int ret = QLA_FUNCTION_FAILED;
3785 for (liter = 0; liter < dwords; liter++, faddr += 4, dwptr++) {
3786 ret = qla8044_flash_write_u32(vha, faddr, dwptr);
3788 ql_dbg(ql_dbg_p3p, vha, 0xb141,
3789 "%s: flash address=%x data=%x.\n", __func__,
3799 qla8044_write_optrom_data(struct scsi_qla_host *vha, void *buf,
3800 uint32_t offset, uint32_t length)
3802 int rval = QLA_FUNCTION_FAILED, i, burst_iter_count;
3803 int dword_count, erase_sec_count;
3804 uint32_t erase_offset;
3805 uint8_t *p_cache, *p_src;
3807 erase_offset = offset;
3809 p_cache = kcalloc(length, sizeof(uint8_t), GFP_KERNEL);
3811 return QLA_FUNCTION_FAILED;
3813 memcpy(p_cache, buf, length);
3815 dword_count = length / sizeof(uint32_t);
3816 /* Since the offset and legth are sector aligned, it will be always
3817 * multiple of burst_iter_count (64)
3819 burst_iter_count = dword_count / QLA8044_MAX_OPTROM_BURST_DWORDS;
3820 erase_sec_count = length / QLA8044_SECTOR_SIZE;
3823 scsi_block_requests(vha->host);
3824 /* Lock and enable write for whole operation. */
3825 qla8044_flash_lock(vha);
3826 qla8044_unprotect_flash(vha);
3828 /* Erasing the sectors */
3829 for (i = 0; i < erase_sec_count; i++) {
3830 rval = qla8044_erase_flash_sector(vha, erase_offset);
3831 ql_dbg(ql_dbg_user, vha, 0xb138,
3832 "Done erase of sector=0x%x.\n",
3835 ql_log(ql_log_warn, vha, 0xb121,
3836 "Failed to erase the sector having address: "
3837 "0x%x.\n", erase_offset);
3840 erase_offset += QLA8044_SECTOR_SIZE;
3842 ql_dbg(ql_dbg_user, vha, 0xb13f,
3843 "Got write for addr = 0x%x length=0x%x.\n",
3846 for (i = 0; i < burst_iter_count; i++) {
3848 /* Go with write. */
3849 rval = qla8044_write_flash_buffer_mode(vha, (uint32_t *)p_src,
3850 offset, QLA8044_MAX_OPTROM_BURST_DWORDS);
3852 /* Buffer Mode failed skip to dword mode */
3853 ql_log(ql_log_warn, vha, 0xb122,
3854 "Failed to write flash in buffer mode, "
3855 "Reverting to slow-write.\n");
3856 rval = qla8044_write_flash_dword_mode(vha,
3857 (uint32_t *)p_src, offset,
3858 QLA8044_MAX_OPTROM_BURST_DWORDS);
3860 p_src += sizeof(uint32_t) * QLA8044_MAX_OPTROM_BURST_DWORDS;
3861 offset += sizeof(uint32_t) * QLA8044_MAX_OPTROM_BURST_DWORDS;
3863 ql_dbg(ql_dbg_user, vha, 0xb133,
3867 qla8044_protect_flash(vha);
3868 qla8044_flash_unlock(vha);
3869 scsi_unblock_requests(vha->host);
3875 #define LEG_INT_PTR_B31 (1 << 31)
3876 #define LEG_INT_PTR_B30 (1 << 30)
3877 #define PF_BITS_MASK (0xF << 16)
3879 * qla8044_intr_handler() - Process interrupts for the ISP8044
3880 * @irq: interrupt number
3881 * @dev_id: SCSI driver HA context
3883 * Called by system whenever the host adapter generates an interrupt.
3885 * Returns handled flag.
3888 qla8044_intr_handler(int irq, void *dev_id)
3890 scsi_qla_host_t *vha;
3891 struct qla_hw_data *ha;
3892 struct rsp_que *rsp;
3893 struct device_reg_82xx __iomem *reg;
3895 unsigned long flags;
3899 uint32_t leg_int_ptr = 0, pf_bit;
3901 rsp = (struct rsp_que *) dev_id;
3903 ql_log(ql_log_info, NULL, 0xb143,
3904 "%s(): NULL response queue pointer\n", __func__);
3908 vha = pci_get_drvdata(ha->pdev);
3910 if (unlikely(pci_channel_offline(ha->pdev)))
3913 leg_int_ptr = qla8044_rd_reg(ha, LEG_INTR_PTR_OFFSET);
3915 /* Legacy interrupt is valid if bit31 of leg_int_ptr is set */
3916 if (!(leg_int_ptr & (LEG_INT_PTR_B31))) {
3917 ql_dbg(ql_dbg_p3p, vha, 0xb144,
3918 "%s: Legacy Interrupt Bit 31 not set, "
3919 "spurious interrupt!\n", __func__);
3923 pf_bit = ha->portnum << 16;
3924 /* Validate the PCIE function ID set in leg_int_ptr bits [19..16] */
3925 if ((leg_int_ptr & (PF_BITS_MASK)) != pf_bit) {
3926 ql_dbg(ql_dbg_p3p, vha, 0xb145,
3927 "%s: Incorrect function ID 0x%x in "
3928 "legacy interrupt register, "
3929 "ha->pf_bit = 0x%x\n", __func__,
3930 (leg_int_ptr & (PF_BITS_MASK)), pf_bit);
3934 /* To de-assert legacy interrupt, write 0 to Legacy Interrupt Trigger
3935 * Control register and poll till Legacy Interrupt Pointer register
3938 qla8044_wr_reg(ha, LEG_INTR_TRIG_OFFSET, 0);
3940 leg_int_ptr = qla8044_rd_reg(ha, LEG_INTR_PTR_OFFSET);
3941 if ((leg_int_ptr & (PF_BITS_MASK)) != pf_bit)
3943 } while (leg_int_ptr & (LEG_INT_PTR_B30));
3945 reg = &ha->iobase->isp82;
3946 spin_lock_irqsave(&ha->hardware_lock, flags);
3947 for (iter = 1; iter--; ) {
3949 if (RD_REG_DWORD(®->host_int)) {
3950 stat = RD_REG_DWORD(®->host_status);
3951 if ((stat & HSRX_RISC_INT) == 0)
3954 switch (stat & 0xff) {
3959 qla82xx_mbx_completion(vha, MSW(stat));
3960 status |= MBX_INTERRUPT;
3964 mb[1] = RD_REG_WORD(®->mailbox_out[1]);
3965 mb[2] = RD_REG_WORD(®->mailbox_out[2]);
3966 mb[3] = RD_REG_WORD(®->mailbox_out[3]);
3967 qla2x00_async_event(vha, rsp, mb);
3970 qla24xx_process_response_queue(vha, rsp);
3973 ql_dbg(ql_dbg_p3p, vha, 0xb146,
3974 "Unrecognized interrupt type "
3975 "(%d).\n", stat & 0xff);
3979 WRT_REG_DWORD(®->host_int, 0);
3982 qla2x00_handle_mbx_completion(ha, status);
3983 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3989 qla8044_idc_dontreset(struct qla_hw_data *ha)
3993 idc_ctrl = qla8044_rd_reg(ha, QLA8044_IDC_DRV_CTRL);
3994 return idc_ctrl & DONTRESET_BIT0;
3998 qla8044_clear_rst_ready(scsi_qla_host_t *vha)
4002 drv_state = qla8044_rd_direct(vha, QLA8044_CRB_DRV_STATE_INDEX);
4005 * For ISP8044, drv_active register has 1 bit per function,
4006 * shift 1 by func_num to set a bit for the function.
4007 * For ISP82xx, drv_active has 4 bits per function
4009 drv_state &= ~(1 << vha->hw->portnum);
4011 ql_dbg(ql_dbg_p3p, vha, 0xb13d,
4012 "drv_state: 0x%08x\n", drv_state);
4013 qla8044_wr_direct(vha, QLA8044_CRB_DRV_STATE_INDEX, drv_state);
4017 qla8044_abort_isp(scsi_qla_host_t *vha)
4021 struct qla_hw_data *ha = vha->hw;
4023 qla8044_idc_lock(ha);
4024 dev_state = qla8044_rd_direct(vha, QLA8044_CRB_DEV_STATE_INDEX);
4026 if (ql2xdontresethba)
4027 qla8044_set_idc_dontreset(vha);
4029 /* If device_state is NEED_RESET, go ahead with
4030 * Reset,irrespective of ql2xdontresethba. This is to allow a
4031 * non-reset-owner to force a reset. Non-reset-owner sets
4032 * the IDC_CTRL BIT0 to prevent Reset-owner from doing a Reset
4033 * and then forces a Reset by setting device_state to
4035 if (dev_state == QLA8XXX_DEV_READY) {
4036 /* If IDC_CTRL DONTRESETHBA_BIT0 is set don't do reset
4038 if (qla8044_idc_dontreset(ha) == DONTRESET_BIT0) {
4039 ql_dbg(ql_dbg_p3p, vha, 0xb13e,
4040 "Reset recovery disabled\n");
4041 rval = QLA_FUNCTION_FAILED;
4042 goto exit_isp_reset;
4045 ql_dbg(ql_dbg_p3p, vha, 0xb140,
4046 "HW State: NEED RESET\n");
4047 qla8044_wr_direct(vha, QLA8044_CRB_DEV_STATE_INDEX,
4048 QLA8XXX_DEV_NEED_RESET);
4051 /* For ISP8044, Reset owner is NIC, iSCSI or FCOE based on priority
4052 * and which drivers are present. Unlike ISP82XX, the function setting
4053 * NEED_RESET, may not be the Reset owner. */
4054 qla83xx_reset_ownership(vha);
4056 qla8044_idc_unlock(ha);
4057 rval = qla8044_device_state_handler(vha);
4058 qla8044_idc_lock(ha);
4059 qla8044_clear_rst_ready(vha);
4062 qla8044_idc_unlock(ha);
4063 if (rval == QLA_SUCCESS) {
4064 ha->flags.isp82xx_fw_hung = 0;
4065 ha->flags.nic_core_reset_hdlr_active = 0;
4066 rval = qla82xx_restart_isp(vha);
4073 qla8044_fw_dump(scsi_qla_host_t *vha)
4075 struct qla_hw_data *ha = vha->hw;
4077 if (!ha->allow_cna_fw_dump)
4080 scsi_block_requests(vha->host);
4081 ha->flags.isp82xx_no_md_cap = 1;
4082 qla8044_idc_lock(ha);
4083 qla82xx_set_reset_owner(vha);
4084 qla8044_idc_unlock(ha);
4085 qla2x00_wait_for_chip_reset(vha);
4086 scsi_unblock_requests(vha->host);