2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2013 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
8 #include <linux/vmalloc.h>
13 #include <linux/delay.h>
15 /* 8044 Flash Read/Write functions */
17 qla8044_rd_reg(struct qla_hw_data
*ha
, ulong addr
)
19 return readl((void __iomem
*) (ha
->nx_pcibase
+ addr
));
23 qla8044_wr_reg(struct qla_hw_data
*ha
, ulong addr
, uint32_t val
)
25 writel(val
, (void __iomem
*)((ha
)->nx_pcibase
+ addr
));
29 qla8044_rd_direct(struct scsi_qla_host
*vha
,
30 const uint32_t crb_reg
)
32 struct qla_hw_data
*ha
= vha
->hw
;
34 if (crb_reg
< CRB_REG_INDEX_MAX
)
35 return qla8044_rd_reg(ha
, qla8044_reg_tbl
[crb_reg
]);
37 return QLA_FUNCTION_FAILED
;
41 qla8044_wr_direct(struct scsi_qla_host
*vha
,
42 const uint32_t crb_reg
,
45 struct qla_hw_data
*ha
= vha
->hw
;
47 if (crb_reg
< CRB_REG_INDEX_MAX
)
48 qla8044_wr_reg(ha
, qla8044_reg_tbl
[crb_reg
], value
);
52 qla8044_set_win_base(scsi_qla_host_t
*vha
, uint32_t addr
)
55 int ret_val
= QLA_SUCCESS
;
56 struct qla_hw_data
*ha
= vha
->hw
;
58 qla8044_wr_reg(ha
, QLA8044_CRB_WIN_FUNC(ha
->portnum
), addr
);
59 val
= qla8044_rd_reg(ha
, QLA8044_CRB_WIN_FUNC(ha
->portnum
));
62 ql_log(ql_log_warn
, vha
, 0xb087,
63 "%s: Failed to set register window : "
64 "addr written 0x%x, read 0x%x!\n",
66 ret_val
= QLA_FUNCTION_FAILED
;
72 qla8044_rd_reg_indirect(scsi_qla_host_t
*vha
, uint32_t addr
, uint32_t *data
)
74 int ret_val
= QLA_SUCCESS
;
75 struct qla_hw_data
*ha
= vha
->hw
;
77 ret_val
= qla8044_set_win_base(vha
, addr
);
79 *data
= qla8044_rd_reg(ha
, QLA8044_WILDCARD
);
81 ql_log(ql_log_warn
, vha
, 0xb088,
82 "%s: failed read of addr 0x%x!\n", __func__
, addr
);
87 qla8044_wr_reg_indirect(scsi_qla_host_t
*vha
, uint32_t addr
, uint32_t data
)
89 int ret_val
= QLA_SUCCESS
;
90 struct qla_hw_data
*ha
= vha
->hw
;
92 ret_val
= qla8044_set_win_base(vha
, addr
);
94 qla8044_wr_reg(ha
, QLA8044_WILDCARD
, data
);
96 ql_log(ql_log_warn
, vha
, 0xb089,
97 "%s: failed wrt to addr 0x%x, data 0x%x\n",
98 __func__
, addr
, data
);
103 * qla8044_read_write_crb_reg - Read from raddr and write value to waddr.
105 * @ha : Pointer to adapter structure
106 * @raddr : CRB address to read from
107 * @waddr : CRB address to write to
111 qla8044_read_write_crb_reg(struct scsi_qla_host
*vha
,
112 uint32_t raddr
, uint32_t waddr
)
116 qla8044_rd_reg_indirect(vha
, raddr
, &value
);
117 qla8044_wr_reg_indirect(vha
, waddr
, value
);
121 * qla8044_rmw_crb_reg - Read value from raddr, AND with test_mask,
122 * Shift Left,Right/OR/XOR with values RMW header and write value to waddr.
124 * @vha : Pointer to adapter structure
125 * @raddr : CRB address to read from
126 * @waddr : CRB address to write to
127 * @p_rmw_hdr : header with shift/or/xor values.
131 qla8044_rmw_crb_reg(struct scsi_qla_host
*vha
,
132 uint32_t raddr
, uint32_t waddr
, struct qla8044_rmw
*p_rmw_hdr
)
136 if (p_rmw_hdr
->index_a
)
137 value
= vha
->reset_tmplt
.array
[p_rmw_hdr
->index_a
];
139 qla8044_rd_reg_indirect(vha
, raddr
, &value
);
140 value
&= p_rmw_hdr
->test_mask
;
141 value
<<= p_rmw_hdr
->shl
;
142 value
>>= p_rmw_hdr
->shr
;
143 value
|= p_rmw_hdr
->or_value
;
144 value
^= p_rmw_hdr
->xor_value
;
145 qla8044_wr_reg_indirect(vha
, waddr
, value
);
150 qla8044_set_qsnt_ready(struct scsi_qla_host
*vha
)
153 struct qla_hw_data
*ha
= vha
->hw
;
155 qsnt_state
= qla8044_rd_direct(vha
, QLA8044_CRB_DRV_STATE_INDEX
);
156 qsnt_state
|= (1 << ha
->portnum
);
157 qla8044_wr_direct(vha
, QLA8044_CRB_DRV_STATE_INDEX
, qsnt_state
);
158 ql_log(ql_log_info
, vha
, 0xb08e, "%s(%ld): qsnt_state: 0x%08x\n",
159 __func__
, vha
->host_no
, qsnt_state
);
163 qla8044_clear_qsnt_ready(struct scsi_qla_host
*vha
)
166 struct qla_hw_data
*ha
= vha
->hw
;
168 qsnt_state
= qla8044_rd_direct(vha
, QLA8044_CRB_DRV_STATE_INDEX
);
169 qsnt_state
&= ~(1 << ha
->portnum
);
170 qla8044_wr_direct(vha
, QLA8044_CRB_DRV_STATE_INDEX
, qsnt_state
);
171 ql_log(ql_log_info
, vha
, 0xb08f, "%s(%ld): qsnt_state: 0x%08x\n",
172 __func__
, vha
->host_no
, qsnt_state
);
177 * qla8044_lock_recovery - Recovers the idc_lock.
178 * @ha : Pointer to adapter structure
180 * Lock Recovery Register
181 * 5-2 Lock recovery owner: Function ID of driver doing lock recovery,
182 * valid if bits 1..0 are set by driver doing lock recovery.
183 * 1-0 1 - Driver intends to force unlock the IDC lock.
184 * 2 - Driver is moving forward to unlock the IDC lock. Driver clears
185 * this field after force unlocking the IDC lock.
187 * Lock Recovery process
188 * a. Read the IDC_LOCK_RECOVERY register. If the value in bits 1..0 is
189 * greater than 0, then wait for the other driver to unlock otherwise
190 * move to the next step.
191 * b. Indicate intent to force-unlock by writing 1h to the IDC_LOCK_RECOVERY
192 * register bits 1..0 and also set the function# in bits 5..2.
193 * c. Read the IDC_LOCK_RECOVERY register again after a delay of 200ms.
194 * Wait for the other driver to perform lock recovery if the function
195 * number in bits 5..2 has changed, otherwise move to the next step.
196 * d. Write a value of 2h to the IDC_LOCK_RECOVERY register bits 1..0
197 * leaving your function# in bits 5..2.
198 * e. Force unlock using the DRIVER_UNLOCK register and immediately clear
199 * the IDC_LOCK_RECOVERY bits 5..0 by writing 0.
202 qla8044_lock_recovery(struct scsi_qla_host
*vha
)
204 uint32_t lock
= 0, lockid
;
205 struct qla_hw_data
*ha
= vha
->hw
;
207 lockid
= qla8044_rd_reg(ha
, QLA8044_DRV_LOCKRECOVERY
);
209 /* Check for other Recovery in progress, go wait */
210 if ((lockid
& IDC_LOCK_RECOVERY_STATE_MASK
) != 0)
211 return QLA_FUNCTION_FAILED
;
213 /* Intent to Recover */
214 qla8044_wr_reg(ha
, QLA8044_DRV_LOCKRECOVERY
,
216 IDC_LOCK_RECOVERY_STATE_SHIFT_BITS
) | INTENT_TO_RECOVER
);
219 /* Check Intent to Recover is advertised */
220 lockid
= qla8044_rd_reg(ha
, QLA8044_DRV_LOCKRECOVERY
);
221 if ((lockid
& IDC_LOCK_RECOVERY_OWNER_MASK
) != (ha
->portnum
<<
222 IDC_LOCK_RECOVERY_STATE_SHIFT_BITS
))
223 return QLA_FUNCTION_FAILED
;
225 ql_dbg(ql_dbg_p3p
, vha
, 0xb08B, "%s:%d: IDC Lock recovery initiated\n"
226 , __func__
, ha
->portnum
);
228 /* Proceed to Recover */
229 qla8044_wr_reg(ha
, QLA8044_DRV_LOCKRECOVERY
,
230 (ha
->portnum
<< IDC_LOCK_RECOVERY_STATE_SHIFT_BITS
) |
234 qla8044_wr_reg(ha
, QLA8044_DRV_LOCK_ID
, 0xFF);
235 qla8044_rd_reg(ha
, QLA8044_DRV_UNLOCK
);
237 /* Clear bits 0-5 in IDC_RECOVERY register*/
238 qla8044_wr_reg(ha
, QLA8044_DRV_LOCKRECOVERY
, 0);
241 lock
= qla8044_rd_reg(ha
, QLA8044_DRV_LOCK
);
243 lockid
= qla8044_rd_reg(ha
, QLA8044_DRV_LOCK_ID
);
244 lockid
= ((lockid
+ (1 << 8)) & ~0xFF) | ha
->portnum
;
245 qla8044_wr_reg(ha
, QLA8044_DRV_LOCK_ID
, lockid
);
248 return QLA_FUNCTION_FAILED
;
252 qla8044_idc_lock(struct qla_hw_data
*ha
)
254 uint32_t ret_val
= QLA_SUCCESS
, timeout
= 0, status
= 0;
255 uint32_t lock_id
, lock_cnt
, func_num
, tmo_owner
= 0, first_owner
= 0;
256 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
258 while (status
== 0) {
259 /* acquire semaphore5 from PCI HW block */
260 status
= qla8044_rd_reg(ha
, QLA8044_DRV_LOCK
);
263 /* Increment Counter (8-31) and update func_num (0-7) on
264 * getting a successful lock */
265 lock_id
= qla8044_rd_reg(ha
, QLA8044_DRV_LOCK_ID
);
266 lock_id
= ((lock_id
+ (1 << 8)) & ~0xFF) | ha
->portnum
;
267 qla8044_wr_reg(ha
, QLA8044_DRV_LOCK_ID
, lock_id
);
272 first_owner
= qla8044_rd_reg(ha
, QLA8044_DRV_LOCK_ID
);
275 (QLA8044_DRV_LOCK_TIMEOUT
/ QLA8044_DRV_LOCK_MSLEEP
)) {
276 tmo_owner
= qla8044_rd_reg(ha
, QLA8044_DRV_LOCK_ID
);
277 func_num
= tmo_owner
& 0xFF;
278 lock_cnt
= tmo_owner
>> 8;
279 ql_log(ql_log_warn
, vha
, 0xb114,
280 "%s: Lock by func %d failed after 2s, lock held "
281 "by func %d, lock count %d, first_owner %d\n",
282 __func__
, ha
->portnum
, func_num
, lock_cnt
,
283 (first_owner
& 0xFF));
284 if (first_owner
!= tmo_owner
) {
285 /* Some other driver got lock,
286 * OR same driver got lock again (counter
287 * value changed), when we were waiting for
288 * lock. Retry for another 2 sec */
289 ql_dbg(ql_dbg_p3p
, vha
, 0xb115,
290 "%s: %d: IDC lock failed\n",
291 __func__
, ha
->portnum
);
294 /* Same driver holding lock > 2sec.
296 if (qla8044_lock_recovery(vha
) == QLA_SUCCESS
) {
297 /* Recovered and got lock */
298 ret_val
= QLA_SUCCESS
;
299 ql_dbg(ql_dbg_p3p
, vha
, 0xb116,
300 "%s:IDC lock Recovery by %d"
301 "successful...\n", __func__
,
304 /* Recovery Failed, some other function
305 * has the lock, wait for 2secs
308 ql_dbg(ql_dbg_p3p
, vha
, 0xb08a,
309 "%s: IDC lock Recovery by %d "
310 "failed, Retrying timout\n", __func__
,
315 msleep(QLA8044_DRV_LOCK_MSLEEP
);
321 qla8044_idc_unlock(struct qla_hw_data
*ha
)
324 scsi_qla_host_t
*vha
= pci_get_drvdata(ha
->pdev
);
326 id
= qla8044_rd_reg(ha
, QLA8044_DRV_LOCK_ID
);
328 if ((id
& 0xFF) != ha
->portnum
) {
329 ql_log(ql_log_warn
, vha
, 0xb118,
330 "%s: IDC Unlock by %d failed, lock owner is %d!\n",
331 __func__
, ha
->portnum
, (id
& 0xFF));
335 /* Keep lock counter value, update the ha->func_num to 0xFF */
336 qla8044_wr_reg(ha
, QLA8044_DRV_LOCK_ID
, (id
| 0xFF));
337 qla8044_rd_reg(ha
, QLA8044_DRV_UNLOCK
);
340 /* 8044 Flash Lock/Unlock functions */
342 qla8044_flash_lock(scsi_qla_host_t
*vha
)
346 uint32_t lock_status
= 0;
347 int ret_val
= QLA_SUCCESS
;
348 struct qla_hw_data
*ha
= vha
->hw
;
350 while (lock_status
== 0) {
351 lock_status
= qla8044_rd_reg(ha
, QLA8044_FLASH_LOCK
);
355 if (++timeout
>= QLA8044_FLASH_LOCK_TIMEOUT
/ 20) {
356 lock_owner
= qla8044_rd_reg(ha
,
357 QLA8044_FLASH_LOCK_ID
);
358 ql_log(ql_log_warn
, vha
, 0xb113,
359 "%s: flash lock by %d failed, held by %d\n",
360 __func__
, ha
->portnum
, lock_owner
);
361 ret_val
= QLA_FUNCTION_FAILED
;
366 qla8044_wr_reg(ha
, QLA8044_FLASH_LOCK_ID
, ha
->portnum
);
371 qla8044_flash_unlock(scsi_qla_host_t
*vha
)
374 struct qla_hw_data
*ha
= vha
->hw
;
376 /* Reading FLASH_UNLOCK register unlocks the Flash */
377 qla8044_wr_reg(ha
, QLA8044_FLASH_LOCK_ID
, 0xFF);
378 ret_val
= qla8044_rd_reg(ha
, QLA8044_FLASH_UNLOCK
);
383 void qla8044_flash_lock_recovery(struct scsi_qla_host
*vha
)
386 if (qla8044_flash_lock(vha
)) {
387 /* Someone else is holding the lock. */
388 ql_log(ql_log_warn
, vha
, 0xb120, "Resetting flash_lock\n");
392 * Either we got the lock, or someone
393 * else died while holding it.
394 * In either case, unlock.
396 qla8044_flash_unlock(vha
);
400 * Address and length are byte address
403 qla8044_read_flash_data(scsi_qla_host_t
*vha
, uint8_t *p_data
,
404 uint32_t flash_addr
, int u32_word_count
)
406 int i
, ret_val
= QLA_SUCCESS
;
409 if (qla8044_flash_lock(vha
) != QLA_SUCCESS
) {
410 ret_val
= QLA_FUNCTION_FAILED
;
411 goto exit_lock_error
;
414 if (flash_addr
& 0x03) {
415 ql_log(ql_log_warn
, vha
, 0xb117,
416 "%s: Illegal addr = 0x%x\n", __func__
, flash_addr
);
417 ret_val
= QLA_FUNCTION_FAILED
;
418 goto exit_flash_read
;
421 for (i
= 0; i
< u32_word_count
; i
++) {
422 if (qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_DIRECT_WINDOW
,
423 (flash_addr
& 0xFFFF0000))) {
424 ql_log(ql_log_warn
, vha
, 0xb119,
425 "%s: failed to write addr 0x%x to "
426 "FLASH_DIRECT_WINDOW\n! ",
427 __func__
, flash_addr
);
428 ret_val
= QLA_FUNCTION_FAILED
;
429 goto exit_flash_read
;
432 ret_val
= qla8044_rd_reg_indirect(vha
,
433 QLA8044_FLASH_DIRECT_DATA(flash_addr
),
435 if (ret_val
!= QLA_SUCCESS
) {
436 ql_log(ql_log_warn
, vha
, 0xb08c,
437 "%s: failed to read addr 0x%x!\n",
438 __func__
, flash_addr
);
439 goto exit_flash_read
;
442 *(uint32_t *)p_data
= u32_word
;
444 flash_addr
= flash_addr
+ 4;
448 qla8044_flash_unlock(vha
);
455 * Address and length are byte address
458 qla8044_read_optrom_data(struct scsi_qla_host
*vha
, uint8_t *buf
,
459 uint32_t offset
, uint32_t length
)
461 scsi_block_requests(vha
->host
);
462 if (qla8044_read_flash_data(vha
, (uint8_t *)buf
, offset
, length
/ 4)
464 ql_log(ql_log_warn
, vha
, 0xb08d,
465 "%s: Failed to read from flash\n",
468 scsi_unblock_requests(vha
->host
);
473 qla8044_need_reset(struct scsi_qla_host
*vha
)
475 uint32_t drv_state
, drv_active
;
477 struct qla_hw_data
*ha
= vha
->hw
;
479 drv_active
= qla8044_rd_direct(vha
, QLA8044_CRB_DRV_ACTIVE_INDEX
);
480 drv_state
= qla8044_rd_direct(vha
, QLA8044_CRB_DRV_STATE_INDEX
);
482 rval
= drv_state
& (1 << ha
->portnum
);
484 if (ha
->flags
.eeh_busy
&& drv_active
)
490 * qla8044_write_list - Write the value (p_entry->arg2) to address specified
491 * by p_entry->arg1 for all entries in header with delay of p_hdr->delay between
494 * @vha : Pointer to adapter structure
495 * @p_hdr : reset_entry header for WRITE_LIST opcode.
499 qla8044_write_list(struct scsi_qla_host
*vha
,
500 struct qla8044_reset_entry_hdr
*p_hdr
)
502 struct qla8044_entry
*p_entry
;
505 p_entry
= (struct qla8044_entry
*)((char *)p_hdr
+
506 sizeof(struct qla8044_reset_entry_hdr
));
508 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
509 qla8044_wr_reg_indirect(vha
, p_entry
->arg1
, p_entry
->arg2
);
511 udelay((uint32_t)(p_hdr
->delay
));
516 * qla8044_read_write_list - Read from address specified by p_entry->arg1,
517 * write value read to address specified by p_entry->arg2, for all entries in
518 * header with delay of p_hdr->delay between entries.
520 * @vha : Pointer to adapter structure
521 * @p_hdr : reset_entry header for READ_WRITE_LIST opcode.
525 qla8044_read_write_list(struct scsi_qla_host
*vha
,
526 struct qla8044_reset_entry_hdr
*p_hdr
)
528 struct qla8044_entry
*p_entry
;
531 p_entry
= (struct qla8044_entry
*)((char *)p_hdr
+
532 sizeof(struct qla8044_reset_entry_hdr
));
534 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
535 qla8044_read_write_crb_reg(vha
, p_entry
->arg1
,
538 udelay((uint32_t)(p_hdr
->delay
));
543 * qla8044_poll_reg - Poll the given CRB addr for duration msecs till
544 * value read ANDed with test_mask is equal to test_result.
546 * @ha : Pointer to adapter structure
547 * @addr : CRB register address
548 * @duration : Poll for total of "duration" msecs
549 * @test_mask : Mask value read with "test_mask"
550 * @test_result : Compare (value&test_mask) with test_result.
552 * Return Value - QLA_SUCCESS/QLA_FUNCTION_FAILED
555 qla8044_poll_reg(struct scsi_qla_host
*vha
, uint32_t addr
,
556 int duration
, uint32_t test_mask
, uint32_t test_result
)
561 int ret_val
= QLA_SUCCESS
;
563 ret_val
= qla8044_rd_reg_indirect(vha
, addr
, &value
);
564 if (ret_val
== QLA_FUNCTION_FAILED
) {
569 /* poll every 1/10 of the total duration */
570 retries
= duration
/10;
573 if ((value
& test_mask
) != test_result
) {
576 ret_val
= qla8044_rd_reg_indirect(vha
, addr
, &value
);
577 if (ret_val
== QLA_FUNCTION_FAILED
) {
589 vha
->reset_tmplt
.seq_error
++;
590 ql_log(ql_log_fatal
, vha
, 0xb090,
591 "%s: Poll Failed: 0x%08x 0x%08x 0x%08x\n",
592 __func__
, value
, test_mask
, test_result
);
595 return timeout_error
;
599 * qla8044_poll_list - For all entries in the POLL_LIST header, poll read CRB
600 * register specified by p_entry->arg1 and compare (value AND test_mask) with
601 * test_result to validate it. Wait for p_hdr->delay between processing entries.
603 * @ha : Pointer to adapter structure
604 * @p_hdr : reset_entry header for POLL_LIST opcode.
608 qla8044_poll_list(struct scsi_qla_host
*vha
,
609 struct qla8044_reset_entry_hdr
*p_hdr
)
612 struct qla8044_entry
*p_entry
;
613 struct qla8044_poll
*p_poll
;
617 p_poll
= (struct qla8044_poll
*)
618 ((char *)p_hdr
+ sizeof(struct qla8044_reset_entry_hdr
));
620 /* Entries start after 8 byte qla8044_poll, poll header contains
621 * the test_mask, test_value.
623 p_entry
= (struct qla8044_entry
*)((char *)p_poll
+
624 sizeof(struct qla8044_poll
));
626 delay
= (long)p_hdr
->delay
;
629 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++)
630 qla8044_poll_reg(vha
, p_entry
->arg1
,
631 delay
, p_poll
->test_mask
, p_poll
->test_value
);
633 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
635 if (qla8044_poll_reg(vha
,
636 p_entry
->arg1
, delay
,
638 p_poll
->test_value
)) {
640 * (data_read&test_mask != test_value)
641 * read TIMEOUT_ADDR (arg1) and
642 * ADDR (arg2) registers
644 qla8044_rd_reg_indirect(vha
,
645 p_entry
->arg1
, &value
);
646 qla8044_rd_reg_indirect(vha
,
647 p_entry
->arg2
, &value
);
655 * qla8044_poll_write_list - Write dr_value, ar_value to dr_addr/ar_addr,
656 * read ar_addr, if (value& test_mask != test_mask) re-read till timeout
659 * @vha : Pointer to adapter structure
660 * @p_hdr : reset entry header for POLL_WRITE_LIST opcode.
664 qla8044_poll_write_list(struct scsi_qla_host
*vha
,
665 struct qla8044_reset_entry_hdr
*p_hdr
)
668 struct qla8044_quad_entry
*p_entry
;
669 struct qla8044_poll
*p_poll
;
672 p_poll
= (struct qla8044_poll
*)((char *)p_hdr
+
673 sizeof(struct qla8044_reset_entry_hdr
));
675 p_entry
= (struct qla8044_quad_entry
*)((char *)p_poll
+
676 sizeof(struct qla8044_poll
));
678 delay
= (long)p_hdr
->delay
;
680 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
681 qla8044_wr_reg_indirect(vha
,
682 p_entry
->dr_addr
, p_entry
->dr_value
);
683 qla8044_wr_reg_indirect(vha
,
684 p_entry
->ar_addr
, p_entry
->ar_value
);
686 if (qla8044_poll_reg(vha
,
687 p_entry
->ar_addr
, delay
,
689 p_poll
->test_value
)) {
690 ql_dbg(ql_dbg_p3p
, vha
, 0xb091,
691 "%s: Timeout Error: poll list, ",
693 ql_dbg(ql_dbg_p3p
, vha
, 0xb092,
694 "item_num %d, entry_num %d\n", i
,
695 vha
->reset_tmplt
.seq_index
);
702 * qla8044_read_modify_write - Read value from p_entry->arg1, modify the
703 * value, write value to p_entry->arg2. Process entries with p_hdr->delay
706 * @vha : Pointer to adapter structure
707 * @p_hdr : header with shift/or/xor values.
711 qla8044_read_modify_write(struct scsi_qla_host
*vha
,
712 struct qla8044_reset_entry_hdr
*p_hdr
)
714 struct qla8044_entry
*p_entry
;
715 struct qla8044_rmw
*p_rmw_hdr
;
718 p_rmw_hdr
= (struct qla8044_rmw
*)((char *)p_hdr
+
719 sizeof(struct qla8044_reset_entry_hdr
));
721 p_entry
= (struct qla8044_entry
*)((char *)p_rmw_hdr
+
722 sizeof(struct qla8044_rmw
));
724 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
725 qla8044_rmw_crb_reg(vha
, p_entry
->arg1
,
726 p_entry
->arg2
, p_rmw_hdr
);
728 udelay((uint32_t)(p_hdr
->delay
));
733 * qla8044_pause - Wait for p_hdr->delay msecs, called between processing
734 * two entries of a sequence.
736 * @vha : Pointer to adapter structure
737 * @p_hdr : Common reset entry header.
741 void qla8044_pause(struct scsi_qla_host
*vha
,
742 struct qla8044_reset_entry_hdr
*p_hdr
)
745 mdelay((uint32_t)((long)p_hdr
->delay
));
749 * qla8044_template_end - Indicates end of reset sequence processing.
751 * @vha : Pointer to adapter structure
752 * @p_hdr : Common reset entry header.
756 qla8044_template_end(struct scsi_qla_host
*vha
,
757 struct qla8044_reset_entry_hdr
*p_hdr
)
759 vha
->reset_tmplt
.template_end
= 1;
761 if (vha
->reset_tmplt
.seq_error
== 0) {
762 ql_dbg(ql_dbg_p3p
, vha
, 0xb093,
763 "%s: Reset sequence completed SUCCESSFULLY.\n", __func__
);
765 ql_log(ql_log_fatal
, vha
, 0xb094,
766 "%s: Reset sequence completed with some timeout "
767 "errors.\n", __func__
);
772 * qla8044_poll_read_list - Write ar_value to ar_addr register, read ar_addr,
773 * if (value & test_mask != test_value) re-read till timeout value expires,
774 * read dr_addr register and assign to reset_tmplt.array.
776 * @vha : Pointer to adapter structure
777 * @p_hdr : Common reset entry header.
781 qla8044_poll_read_list(struct scsi_qla_host
*vha
,
782 struct qla8044_reset_entry_hdr
*p_hdr
)
786 struct qla8044_quad_entry
*p_entry
;
787 struct qla8044_poll
*p_poll
;
791 p_poll
= (struct qla8044_poll
*)
792 ((char *)p_hdr
+ sizeof(struct qla8044_reset_entry_hdr
));
794 p_entry
= (struct qla8044_quad_entry
*)
795 ((char *)p_poll
+ sizeof(struct qla8044_poll
));
797 delay
= (long)p_hdr
->delay
;
799 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
800 qla8044_wr_reg_indirect(vha
, p_entry
->ar_addr
,
803 if (qla8044_poll_reg(vha
, p_entry
->ar_addr
, delay
,
804 p_poll
->test_mask
, p_poll
->test_value
)) {
805 ql_dbg(ql_dbg_p3p
, vha
, 0xb095,
806 "%s: Timeout Error: poll "
808 ql_dbg(ql_dbg_p3p
, vha
, 0xb096,
811 vha
->reset_tmplt
.seq_index
);
813 index
= vha
->reset_tmplt
.array_index
;
814 qla8044_rd_reg_indirect(vha
,
815 p_entry
->dr_addr
, &value
);
816 vha
->reset_tmplt
.array
[index
++] = value
;
817 if (index
== QLA8044_MAX_RESET_SEQ_ENTRIES
)
818 vha
->reset_tmplt
.array_index
= 1;
825 * qla8031_process_reset_template - Process all entries in reset template
826 * till entry with SEQ_END opcode, which indicates end of the reset template
827 * processing. Each entry has a Reset Entry header, entry opcode/command, with
828 * size of the entry, number of entries in sub-sequence and delay in microsecs
829 * or timeout in millisecs.
831 * @ha : Pointer to adapter structure
832 * @p_buff : Common reset entry header.
836 qla8044_process_reset_template(struct scsi_qla_host
*vha
,
840 struct qla8044_reset_entry_hdr
*p_hdr
;
841 char *p_entry
= p_buff
;
843 vha
->reset_tmplt
.seq_end
= 0;
844 vha
->reset_tmplt
.template_end
= 0;
845 entries
= vha
->reset_tmplt
.hdr
->entries
;
846 index
= vha
->reset_tmplt
.seq_index
;
848 for (; (!vha
->reset_tmplt
.seq_end
) && (index
< entries
); index
++) {
849 p_hdr
= (struct qla8044_reset_entry_hdr
*)p_entry
;
850 switch (p_hdr
->cmd
) {
853 case OPCODE_WRITE_LIST
:
854 qla8044_write_list(vha
, p_hdr
);
856 case OPCODE_READ_WRITE_LIST
:
857 qla8044_read_write_list(vha
, p_hdr
);
859 case OPCODE_POLL_LIST
:
860 qla8044_poll_list(vha
, p_hdr
);
862 case OPCODE_POLL_WRITE_LIST
:
863 qla8044_poll_write_list(vha
, p_hdr
);
865 case OPCODE_READ_MODIFY_WRITE
:
866 qla8044_read_modify_write(vha
, p_hdr
);
868 case OPCODE_SEQ_PAUSE
:
869 qla8044_pause(vha
, p_hdr
);
872 vha
->reset_tmplt
.seq_end
= 1;
874 case OPCODE_TMPL_END
:
875 qla8044_template_end(vha
, p_hdr
);
877 case OPCODE_POLL_READ_LIST
:
878 qla8044_poll_read_list(vha
, p_hdr
);
881 ql_log(ql_log_fatal
, vha
, 0xb097,
882 "%s: Unknown command ==> 0x%04x on "
883 "entry = %d\n", __func__
, p_hdr
->cmd
, index
);
887 *Set pointer to next entry in the sequence.
889 p_entry
+= p_hdr
->size
;
891 vha
->reset_tmplt
.seq_index
= index
;
895 qla8044_process_init_seq(struct scsi_qla_host
*vha
)
897 qla8044_process_reset_template(vha
,
898 vha
->reset_tmplt
.init_offset
);
899 if (vha
->reset_tmplt
.seq_end
!= 1)
900 ql_log(ql_log_fatal
, vha
, 0xb098,
901 "%s: Abrupt INIT Sub-Sequence end.\n",
906 qla8044_process_stop_seq(struct scsi_qla_host
*vha
)
908 vha
->reset_tmplt
.seq_index
= 0;
909 qla8044_process_reset_template(vha
, vha
->reset_tmplt
.stop_offset
);
910 if (vha
->reset_tmplt
.seq_end
!= 1)
911 ql_log(ql_log_fatal
, vha
, 0xb099,
912 "%s: Abrupt STOP Sub-Sequence end.\n", __func__
);
916 qla8044_process_start_seq(struct scsi_qla_host
*vha
)
918 qla8044_process_reset_template(vha
, vha
->reset_tmplt
.start_offset
);
919 if (vha
->reset_tmplt
.template_end
!= 1)
920 ql_log(ql_log_fatal
, vha
, 0xb09a,
921 "%s: Abrupt START Sub-Sequence end.\n",
926 qla8044_lockless_flash_read_u32(struct scsi_qla_host
*vha
,
927 uint32_t flash_addr
, uint8_t *p_data
, int u32_word_count
)
931 uint32_t flash_offset
;
932 uint32_t addr
= flash_addr
;
933 int ret_val
= QLA_SUCCESS
;
935 flash_offset
= addr
& (QLA8044_FLASH_SECTOR_SIZE
- 1);
938 ql_log(ql_log_fatal
, vha
, 0xb09b, "%s: Illegal addr = 0x%x\n",
940 ret_val
= QLA_FUNCTION_FAILED
;
941 goto exit_lockless_read
;
944 ret_val
= qla8044_wr_reg_indirect(vha
,
945 QLA8044_FLASH_DIRECT_WINDOW
, (addr
));
947 if (ret_val
!= QLA_SUCCESS
) {
948 ql_log(ql_log_fatal
, vha
, 0xb09c,
949 "%s: failed to write addr 0x%x to FLASH_DIRECT_WINDOW!\n",
951 goto exit_lockless_read
;
954 /* Check if data is spread across multiple sectors */
955 if ((flash_offset
+ (u32_word_count
* sizeof(uint32_t))) >
956 (QLA8044_FLASH_SECTOR_SIZE
- 1)) {
957 /* Multi sector read */
958 for (i
= 0; i
< u32_word_count
; i
++) {
959 ret_val
= qla8044_rd_reg_indirect(vha
,
960 QLA8044_FLASH_DIRECT_DATA(addr
), &u32_word
);
961 if (ret_val
!= QLA_SUCCESS
) {
962 ql_log(ql_log_fatal
, vha
, 0xb09d,
963 "%s: failed to read addr 0x%x!\n",
965 goto exit_lockless_read
;
967 *(uint32_t *)p_data
= u32_word
;
970 flash_offset
= flash_offset
+ 4;
971 if (flash_offset
> (QLA8044_FLASH_SECTOR_SIZE
- 1)) {
972 /* This write is needed once for each sector */
973 ret_val
= qla8044_wr_reg_indirect(vha
,
974 QLA8044_FLASH_DIRECT_WINDOW
, (addr
));
975 if (ret_val
!= QLA_SUCCESS
) {
976 ql_log(ql_log_fatal
, vha
, 0xb09f,
977 "%s: failed to write addr "
978 "0x%x to FLASH_DIRECT_WINDOW!\n",
980 goto exit_lockless_read
;
986 /* Single sector read */
987 for (i
= 0; i
< u32_word_count
; i
++) {
988 ret_val
= qla8044_rd_reg_indirect(vha
,
989 QLA8044_FLASH_DIRECT_DATA(addr
), &u32_word
);
990 if (ret_val
!= QLA_SUCCESS
) {
991 ql_log(ql_log_fatal
, vha
, 0xb0a0,
992 "%s: failed to read addr 0x%x!\n",
994 goto exit_lockless_read
;
996 *(uint32_t *)p_data
= u32_word
;
1007 * qla8044_ms_mem_write_128b - Writes data to MS/off-chip memory
1009 * @vha : Pointer to adapter structure
1010 * addr : Flash address to write to
1011 * data : Data to be written
1012 * count : word_count to be written
1014 * Return Value - QLA_SUCCESS/QLA_FUNCTION_FAILED
1017 qla8044_ms_mem_write_128b(struct scsi_qla_host
*vha
,
1018 uint64_t addr
, uint32_t *data
, uint32_t count
)
1020 int i
, j
, ret_val
= QLA_SUCCESS
;
1022 unsigned long flags
;
1023 struct qla_hw_data
*ha
= vha
->hw
;
1025 /* Only 128-bit aligned access */
1027 ret_val
= QLA_FUNCTION_FAILED
;
1028 goto exit_ms_mem_write
;
1030 write_lock_irqsave(&ha
->hw_lock
, flags
);
1033 ret_val
= qla8044_wr_reg_indirect(vha
, MD_MIU_TEST_AGT_ADDR_HI
, 0);
1034 if (ret_val
== QLA_FUNCTION_FAILED
) {
1035 ql_log(ql_log_fatal
, vha
, 0xb0a1,
1036 "%s: write to AGT_ADDR_HI failed!\n", __func__
);
1037 goto exit_ms_mem_write_unlock
;
1040 for (i
= 0; i
< count
; i
++, addr
+= 16) {
1041 if (!((QLA8044_ADDR_IN_RANGE(addr
, QLA8044_ADDR_QDR_NET
,
1042 QLA8044_ADDR_QDR_NET_MAX
)) ||
1043 (QLA8044_ADDR_IN_RANGE(addr
, QLA8044_ADDR_DDR_NET
,
1044 QLA8044_ADDR_DDR_NET_MAX
)))) {
1045 ret_val
= QLA_FUNCTION_FAILED
;
1046 goto exit_ms_mem_write_unlock
;
1049 ret_val
= qla8044_wr_reg_indirect(vha
,
1050 MD_MIU_TEST_AGT_ADDR_LO
, addr
);
1053 ret_val
+= qla8044_wr_reg_indirect(vha
,
1054 MD_MIU_TEST_AGT_WRDATA_LO
, *data
++);
1055 ret_val
+= qla8044_wr_reg_indirect(vha
,
1056 MD_MIU_TEST_AGT_WRDATA_HI
, *data
++);
1057 ret_val
+= qla8044_wr_reg_indirect(vha
,
1058 MD_MIU_TEST_AGT_WRDATA_ULO
, *data
++);
1059 ret_val
+= qla8044_wr_reg_indirect(vha
,
1060 MD_MIU_TEST_AGT_WRDATA_UHI
, *data
++);
1061 if (ret_val
== QLA_FUNCTION_FAILED
) {
1062 ql_log(ql_log_fatal
, vha
, 0xb0a2,
1063 "%s: write to AGT_WRDATA failed!\n",
1065 goto exit_ms_mem_write_unlock
;
1068 /* Check write status */
1069 ret_val
= qla8044_wr_reg_indirect(vha
, MD_MIU_TEST_AGT_CTRL
,
1070 MIU_TA_CTL_WRITE_ENABLE
);
1071 ret_val
+= qla8044_wr_reg_indirect(vha
, MD_MIU_TEST_AGT_CTRL
,
1072 MIU_TA_CTL_WRITE_START
);
1073 if (ret_val
== QLA_FUNCTION_FAILED
) {
1074 ql_log(ql_log_fatal
, vha
, 0xb0a3,
1075 "%s: write to AGT_CTRL failed!\n", __func__
);
1076 goto exit_ms_mem_write_unlock
;
1079 for (j
= 0; j
< MAX_CTL_CHECK
; j
++) {
1080 ret_val
= qla8044_rd_reg_indirect(vha
,
1081 MD_MIU_TEST_AGT_CTRL
, &agt_ctrl
);
1082 if (ret_val
== QLA_FUNCTION_FAILED
) {
1083 ql_log(ql_log_fatal
, vha
, 0xb0a4,
1084 "%s: failed to read "
1085 "MD_MIU_TEST_AGT_CTRL!\n", __func__
);
1086 goto exit_ms_mem_write_unlock
;
1088 if ((agt_ctrl
& MIU_TA_CTL_BUSY
) == 0)
1092 /* Status check failed */
1093 if (j
>= MAX_CTL_CHECK
) {
1094 ql_log(ql_log_fatal
, vha
, 0xb0a5,
1095 "%s: MS memory write failed!\n",
1097 ret_val
= QLA_FUNCTION_FAILED
;
1098 goto exit_ms_mem_write_unlock
;
1102 exit_ms_mem_write_unlock
:
1103 write_unlock_irqrestore(&ha
->hw_lock
, flags
);
1110 qla8044_copy_bootloader(struct scsi_qla_host
*vha
)
1113 uint32_t src
, count
, size
;
1115 int ret_val
= QLA_SUCCESS
;
1116 struct qla_hw_data
*ha
= vha
->hw
;
1118 src
= QLA8044_BOOTLOADER_FLASH_ADDR
;
1119 dest
= qla8044_rd_reg(ha
, QLA8044_BOOTLOADER_ADDR
);
1120 size
= qla8044_rd_reg(ha
, QLA8044_BOOTLOADER_SIZE
);
1122 /* 128 bit alignment check */
1124 size
= (size
+ 16) & ~0xF;
1129 p_cache
= vmalloc(size
);
1130 if (p_cache
== NULL
) {
1131 ql_log(ql_log_fatal
, vha
, 0xb0a6,
1132 "%s: Failed to allocate memory for "
1133 "boot loader cache\n", __func__
);
1134 ret_val
= QLA_FUNCTION_FAILED
;
1135 goto exit_copy_bootloader
;
1138 ret_val
= qla8044_lockless_flash_read_u32(vha
, src
,
1139 p_cache
, size
/sizeof(uint32_t));
1140 if (ret_val
== QLA_FUNCTION_FAILED
) {
1141 ql_log(ql_log_fatal
, vha
, 0xb0a7,
1142 "%s: Error reading F/W from flash!!!\n", __func__
);
1143 goto exit_copy_error
;
1145 ql_dbg(ql_dbg_p3p
, vha
, 0xb0a8, "%s: Read F/W from flash!\n",
1148 /* 128 bit/16 byte write to MS memory */
1149 ret_val
= qla8044_ms_mem_write_128b(vha
, dest
,
1150 (uint32_t *)p_cache
, count
);
1151 if (ret_val
== QLA_FUNCTION_FAILED
) {
1152 ql_log(ql_log_fatal
, vha
, 0xb0a9,
1153 "%s: Error writing F/W to MS !!!\n", __func__
);
1154 goto exit_copy_error
;
1156 ql_dbg(ql_dbg_p3p
, vha
, 0xb0aa,
1157 "%s: Wrote F/W (size %d) to MS !!!\n",
1163 exit_copy_bootloader
:
1168 qla8044_restart(struct scsi_qla_host
*vha
)
1170 int ret_val
= QLA_SUCCESS
;
1171 struct qla_hw_data
*ha
= vha
->hw
;
1173 qla8044_process_stop_seq(vha
);
1175 /* Collect minidump */
1177 qla8044_get_minidump(vha
);
1179 ql_log(ql_log_fatal
, vha
, 0xb14c,
1180 "Minidump disabled.\n");
1182 qla8044_process_init_seq(vha
);
1184 if (qla8044_copy_bootloader(vha
)) {
1185 ql_log(ql_log_fatal
, vha
, 0xb0ab,
1186 "%s: Copy bootloader, firmware restart failed!\n",
1188 ret_val
= QLA_FUNCTION_FAILED
;
1193 * Loads F/W from flash
1195 qla8044_wr_reg(ha
, QLA8044_FW_IMAGE_VALID
, QLA8044_BOOT_FROM_FLASH
);
1197 qla8044_process_start_seq(vha
);
1204 * qla8044_check_cmd_peg_status - Check peg status to see if Peg is
1207 * @ha : Pointer to adapter structure
1209 * Return Value - QLA_SUCCESS/QLA_FUNCTION_FAILED
1212 qla8044_check_cmd_peg_status(struct scsi_qla_host
*vha
)
1214 uint32_t val
, ret_val
= QLA_FUNCTION_FAILED
;
1215 int retries
= CRB_CMDPEG_CHECK_RETRY_COUNT
;
1216 struct qla_hw_data
*ha
= vha
->hw
;
1219 val
= qla8044_rd_reg(ha
, QLA8044_CMDPEG_STATE
);
1220 if (val
== PHAN_INITIALIZE_COMPLETE
) {
1221 ql_dbg(ql_dbg_p3p
, vha
, 0xb0ac,
1222 "%s: Command Peg initialization "
1223 "complete! state=0x%x\n", __func__
, val
);
1224 ret_val
= QLA_SUCCESS
;
1227 msleep(CRB_CMDPEG_CHECK_DELAY
);
1228 } while (--retries
);
1234 qla8044_start_firmware(struct scsi_qla_host
*vha
)
1236 int ret_val
= QLA_SUCCESS
;
1238 if (qla8044_restart(vha
)) {
1239 ql_log(ql_log_fatal
, vha
, 0xb0ad,
1240 "%s: Restart Error!!!, Need Reset!!!\n",
1242 ret_val
= QLA_FUNCTION_FAILED
;
1245 ql_dbg(ql_dbg_p3p
, vha
, 0xb0af,
1246 "%s: Restart done!\n", __func__
);
1248 ret_val
= qla8044_check_cmd_peg_status(vha
);
1250 ql_log(ql_log_fatal
, vha
, 0xb0b0,
1251 "%s: Peg not initialized!\n", __func__
);
1252 ret_val
= QLA_FUNCTION_FAILED
;
1260 qla8044_clear_drv_active(struct qla_hw_data
*ha
)
1262 uint32_t drv_active
;
1263 struct scsi_qla_host
*vha
= pci_get_drvdata(ha
->pdev
);
1265 drv_active
= qla8044_rd_direct(vha
, QLA8044_CRB_DRV_ACTIVE_INDEX
);
1266 drv_active
&= ~(1 << (ha
->portnum
));
1268 ql_log(ql_log_info
, vha
, 0xb0b1,
1269 "%s(%ld): drv_active: 0x%08x\n",
1270 __func__
, vha
->host_no
, drv_active
);
1272 qla8044_wr_direct(vha
, QLA8044_CRB_DRV_ACTIVE_INDEX
, drv_active
);
1276 * qla8044_device_bootstrap - Initialize device, set DEV_READY, start fw
1277 * @ha: pointer to adapter structure
1279 * Note: IDC lock must be held upon entry
1282 qla8044_device_bootstrap(struct scsi_qla_host
*vha
)
1284 int rval
= QLA_FUNCTION_FAILED
;
1286 uint32_t old_count
= 0, count
= 0;
1289 struct qla_hw_data
*ha
= vha
->hw
;
1291 need_reset
= qla8044_need_reset(vha
);
1294 old_count
= qla8044_rd_direct(vha
,
1295 QLA8044_PEG_ALIVE_COUNTER_INDEX
);
1297 for (i
= 0; i
< 10; i
++) {
1300 count
= qla8044_rd_direct(vha
,
1301 QLA8044_PEG_ALIVE_COUNTER_INDEX
);
1302 if (count
!= old_count
) {
1307 qla8044_flash_lock_recovery(vha
);
1309 /* We are trying to perform a recovery here. */
1310 if (ha
->flags
.isp82xx_fw_hung
)
1311 qla8044_flash_lock_recovery(vha
);
1314 /* set to DEV_INITIALIZING */
1315 ql_log(ql_log_info
, vha
, 0xb0b2,
1316 "%s: HW State: INITIALIZING\n", __func__
);
1317 qla8044_wr_direct(vha
, QLA8044_CRB_DEV_STATE_INDEX
,
1318 QLA8XXX_DEV_INITIALIZING
);
1320 qla8044_idc_unlock(ha
);
1321 rval
= qla8044_start_firmware(vha
);
1322 qla8044_idc_lock(ha
);
1324 if (rval
!= QLA_SUCCESS
) {
1325 ql_log(ql_log_info
, vha
, 0xb0b3,
1326 "%s: HW State: FAILED\n", __func__
);
1327 qla8044_clear_drv_active(ha
);
1328 qla8044_wr_direct(vha
, QLA8044_CRB_DEV_STATE_INDEX
,
1329 QLA8XXX_DEV_FAILED
);
1333 /* For ISP8044, If IDC_CTRL GRACEFUL_RESET_BIT1 is set , reset it after
1334 * device goes to INIT state. */
1335 idc_ctrl
= qla8044_rd_reg(ha
, QLA8044_IDC_DRV_CTRL
);
1336 if (idc_ctrl
& GRACEFUL_RESET_BIT1
) {
1337 qla8044_wr_reg(ha
, QLA8044_IDC_DRV_CTRL
,
1338 (idc_ctrl
& ~GRACEFUL_RESET_BIT1
));
1343 ql_log(ql_log_info
, vha
, 0xb0b4,
1344 "%s: HW State: READY\n", __func__
);
1345 qla8044_wr_direct(vha
, QLA8044_CRB_DEV_STATE_INDEX
, QLA8XXX_DEV_READY
);
1350 /*-------------------------Reset Sequence Functions-----------------------*/
1352 qla8044_dump_reset_seq_hdr(struct scsi_qla_host
*vha
)
1356 if (!vha
->reset_tmplt
.buff
) {
1357 ql_log(ql_log_fatal
, vha
, 0xb0b5,
1358 "%s: Error Invalid reset_seq_template\n", __func__
);
1362 phdr
= vha
->reset_tmplt
.buff
;
1363 ql_dbg(ql_dbg_p3p
, vha
, 0xb0b6,
1364 "Reset Template :\n\t0x%X 0x%X 0x%X 0x%X"
1365 "0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n"
1366 "\t0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n\n",
1367 *phdr
, *(phdr
+1), *(phdr
+2), *(phdr
+3), *(phdr
+4),
1368 *(phdr
+5), *(phdr
+6), *(phdr
+7), *(phdr
+ 8),
1369 *(phdr
+9), *(phdr
+10), *(phdr
+11), *(phdr
+12),
1370 *(phdr
+13), *(phdr
+14), *(phdr
+15));
1374 * qla8044_reset_seq_checksum_test - Validate Reset Sequence template.
1376 * @ha : Pointer to adapter structure
1378 * Return Value - QLA_SUCCESS/QLA_FUNCTION_FAILED
1381 qla8044_reset_seq_checksum_test(struct scsi_qla_host
*vha
)
1384 uint16_t *buff
= (uint16_t *)vha
->reset_tmplt
.buff
;
1385 int u16_count
= vha
->reset_tmplt
.hdr
->size
/ sizeof(uint16_t);
1387 while (u16_count
-- > 0)
1391 sum
= (sum
& 0xFFFF) + (sum
>> 16);
1393 /* checksum of 0 indicates a valid template */
1397 ql_log(ql_log_fatal
, vha
, 0xb0b7,
1398 "%s: Reset seq checksum failed\n", __func__
);
1399 return QLA_FUNCTION_FAILED
;
1404 * qla8044_read_reset_template - Read Reset Template from Flash, validate
1405 * the template and store offsets of stop/start/init offsets in ha->reset_tmplt.
1407 * @ha : Pointer to adapter structure
1410 qla8044_read_reset_template(struct scsi_qla_host
*vha
)
1413 uint32_t addr
, tmplt_hdr_def_size
, tmplt_hdr_size
;
1415 vha
->reset_tmplt
.seq_error
= 0;
1416 vha
->reset_tmplt
.buff
= vmalloc(QLA8044_RESTART_TEMPLATE_SIZE
);
1417 if (vha
->reset_tmplt
.buff
== NULL
) {
1418 ql_log(ql_log_fatal
, vha
, 0xb0b8,
1419 "%s: Failed to allocate reset template resources\n",
1421 goto exit_read_reset_template
;
1424 p_buff
= vha
->reset_tmplt
.buff
;
1425 addr
= QLA8044_RESET_TEMPLATE_ADDR
;
1427 tmplt_hdr_def_size
=
1428 sizeof(struct qla8044_reset_template_hdr
) / sizeof(uint32_t);
1430 ql_dbg(ql_dbg_p3p
, vha
, 0xb0b9,
1431 "%s: Read template hdr size %d from Flash\n",
1432 __func__
, tmplt_hdr_def_size
);
1434 /* Copy template header from flash */
1435 if (qla8044_read_flash_data(vha
, p_buff
, addr
, tmplt_hdr_def_size
)) {
1436 ql_log(ql_log_fatal
, vha
, 0xb0ba,
1437 "%s: Failed to read reset template\n", __func__
);
1438 goto exit_read_template_error
;
1441 vha
->reset_tmplt
.hdr
=
1442 (struct qla8044_reset_template_hdr
*) vha
->reset_tmplt
.buff
;
1444 /* Validate the template header size and signature */
1445 tmplt_hdr_size
= vha
->reset_tmplt
.hdr
->hdr_size
/sizeof(uint32_t);
1446 if ((tmplt_hdr_size
!= tmplt_hdr_def_size
) ||
1447 (vha
->reset_tmplt
.hdr
->signature
!= RESET_TMPLT_HDR_SIGNATURE
)) {
1448 ql_log(ql_log_fatal
, vha
, 0xb0bb,
1449 "%s: Template Header size invalid %d "
1450 "tmplt_hdr_def_size %d!!!\n", __func__
,
1451 tmplt_hdr_size
, tmplt_hdr_def_size
);
1452 goto exit_read_template_error
;
1455 addr
= QLA8044_RESET_TEMPLATE_ADDR
+ vha
->reset_tmplt
.hdr
->hdr_size
;
1456 p_buff
= vha
->reset_tmplt
.buff
+ vha
->reset_tmplt
.hdr
->hdr_size
;
1457 tmplt_hdr_def_size
= (vha
->reset_tmplt
.hdr
->size
-
1458 vha
->reset_tmplt
.hdr
->hdr_size
)/sizeof(uint32_t);
1460 ql_dbg(ql_dbg_p3p
, vha
, 0xb0bc,
1461 "%s: Read rest of the template size %d\n",
1462 __func__
, vha
->reset_tmplt
.hdr
->size
);
1464 /* Copy rest of the template */
1465 if (qla8044_read_flash_data(vha
, p_buff
, addr
, tmplt_hdr_def_size
)) {
1466 ql_log(ql_log_fatal
, vha
, 0xb0bd,
1467 "%s: Failed to read reset tempelate\n", __func__
);
1468 goto exit_read_template_error
;
1471 /* Integrity check */
1472 if (qla8044_reset_seq_checksum_test(vha
)) {
1473 ql_log(ql_log_fatal
, vha
, 0xb0be,
1474 "%s: Reset Seq checksum failed!\n", __func__
);
1475 goto exit_read_template_error
;
1478 ql_dbg(ql_dbg_p3p
, vha
, 0xb0bf,
1479 "%s: Reset Seq checksum passed! Get stop, "
1480 "start and init seq offsets\n", __func__
);
1482 /* Get STOP, START, INIT sequence offsets */
1483 vha
->reset_tmplt
.init_offset
= vha
->reset_tmplt
.buff
+
1484 vha
->reset_tmplt
.hdr
->init_seq_offset
;
1486 vha
->reset_tmplt
.start_offset
= vha
->reset_tmplt
.buff
+
1487 vha
->reset_tmplt
.hdr
->start_seq_offset
;
1489 vha
->reset_tmplt
.stop_offset
= vha
->reset_tmplt
.buff
+
1490 vha
->reset_tmplt
.hdr
->hdr_size
;
1492 qla8044_dump_reset_seq_hdr(vha
);
1494 goto exit_read_reset_template
;
1496 exit_read_template_error
:
1497 vfree(vha
->reset_tmplt
.buff
);
1499 exit_read_reset_template
:
1504 qla8044_set_idc_dontreset(struct scsi_qla_host
*vha
)
1507 struct qla_hw_data
*ha
= vha
->hw
;
1509 idc_ctrl
= qla8044_rd_reg(ha
, QLA8044_IDC_DRV_CTRL
);
1510 idc_ctrl
|= DONTRESET_BIT0
;
1511 ql_dbg(ql_dbg_p3p
, vha
, 0xb0c0,
1512 "%s: idc_ctrl = %d\n", __func__
, idc_ctrl
);
1513 qla8044_wr_reg(ha
, QLA8044_IDC_DRV_CTRL
, idc_ctrl
);
1517 qla8044_set_rst_ready(struct scsi_qla_host
*vha
)
1520 struct qla_hw_data
*ha
= vha
->hw
;
1522 drv_state
= qla8044_rd_direct(vha
, QLA8044_CRB_DRV_STATE_INDEX
);
1524 /* For ISP8044, drv_active register has 1 bit per function,
1525 * shift 1 by func_num to set a bit for the function.*/
1526 drv_state
|= (1 << ha
->portnum
);
1528 ql_log(ql_log_info
, vha
, 0xb0c1,
1529 "%s(%ld): drv_state: 0x%08x\n",
1530 __func__
, vha
->host_no
, drv_state
);
1531 qla8044_wr_direct(vha
, QLA8044_CRB_DRV_STATE_INDEX
, drv_state
);
1535 * qla8044_need_reset_handler - Code to start reset sequence
1536 * @ha: pointer to adapter structure
1538 * Note: IDC lock must be held upon entry
1541 qla8044_need_reset_handler(struct scsi_qla_host
*vha
)
1543 uint32_t dev_state
= 0, drv_state
, drv_active
;
1544 unsigned long reset_timeout
, dev_init_timeout
;
1545 struct qla_hw_data
*ha
= vha
->hw
;
1547 ql_log(ql_log_fatal
, vha
, 0xb0c2,
1548 "%s: Performing ISP error recovery\n", __func__
);
1550 if (vha
->flags
.online
) {
1551 qla8044_idc_unlock(ha
);
1552 qla2x00_abort_isp_cleanup(vha
);
1553 ha
->isp_ops
->get_flash_version(vha
, vha
->req
->ring
);
1554 ha
->isp_ops
->nvram_config(vha
);
1555 qla8044_idc_lock(ha
);
1558 drv_state
= qla8044_rd_direct(vha
,
1559 QLA8044_CRB_DRV_STATE_INDEX
);
1560 drv_active
= qla8044_rd_direct(vha
,
1561 QLA8044_CRB_DRV_ACTIVE_INDEX
);
1563 ql_log(ql_log_info
, vha
, 0xb0c5,
1564 "%s(%ld): drv_state = 0x%x, drv_active = 0x%x\n",
1565 __func__
, vha
->host_no
, drv_state
, drv_active
);
1567 if (!ha
->flags
.nic_core_reset_owner
) {
1568 ql_dbg(ql_dbg_p3p
, vha
, 0xb0c3,
1569 "%s(%ld): reset acknowledged\n",
1570 __func__
, vha
->host_no
);
1571 qla8044_set_rst_ready(vha
);
1573 /* Non-reset owners ACK Reset and wait for device INIT state
1574 * as part of Reset Recovery by Reset Owner
1576 dev_init_timeout
= jiffies
+ (ha
->fcoe_reset_timeout
* HZ
);
1579 if (time_after_eq(jiffies
, dev_init_timeout
)) {
1580 ql_log(ql_log_info
, vha
, 0xb0c4,
1581 "%s: Non Reset owner DEV INIT "
1582 "TIMEOUT!\n", __func__
);
1586 qla8044_idc_unlock(ha
);
1588 qla8044_idc_lock(ha
);
1590 dev_state
= qla8044_rd_direct(vha
,
1591 QLA8044_CRB_DEV_STATE_INDEX
);
1592 } while (((drv_state
& drv_active
) != drv_active
) &&
1593 (dev_state
== QLA8XXX_DEV_NEED_RESET
));
1595 qla8044_set_rst_ready(vha
);
1597 /* wait for 10 seconds for reset ack from all functions */
1598 reset_timeout
= jiffies
+ (ha
->fcoe_reset_timeout
* HZ
);
1600 while ((drv_state
& drv_active
) != drv_active
) {
1601 if (time_after_eq(jiffies
, reset_timeout
)) {
1602 ql_log(ql_log_info
, vha
, 0xb0c6,
1603 "%s: RESET TIMEOUT!"
1604 "drv_state: 0x%08x, drv_active: 0x%08x\n",
1605 QLA2XXX_DRIVER_NAME
, drv_state
, drv_active
);
1609 qla8044_idc_unlock(ha
);
1611 qla8044_idc_lock(ha
);
1613 drv_state
= qla8044_rd_direct(vha
,
1614 QLA8044_CRB_DRV_STATE_INDEX
);
1615 drv_active
= qla8044_rd_direct(vha
,
1616 QLA8044_CRB_DRV_ACTIVE_INDEX
);
1619 if (drv_state
!= drv_active
) {
1620 ql_log(ql_log_info
, vha
, 0xb0c7,
1621 "%s(%ld): Reset_owner turning off drv_active "
1622 "of non-acking function 0x%x\n", __func__
,
1623 vha
->host_no
, (drv_active
^ drv_state
));
1624 drv_active
= drv_active
& drv_state
;
1625 qla8044_wr_direct(vha
, QLA8044_CRB_DRV_ACTIVE_INDEX
,
1630 * Clear RESET OWNER, will be set at next reset
1633 ha
->flags
.nic_core_reset_owner
= 0;
1635 /* Start Reset Recovery */
1636 qla8044_device_bootstrap(vha
);
1641 qla8044_set_drv_active(struct scsi_qla_host
*vha
)
1643 uint32_t drv_active
;
1644 struct qla_hw_data
*ha
= vha
->hw
;
1646 drv_active
= qla8044_rd_direct(vha
, QLA8044_CRB_DRV_ACTIVE_INDEX
);
1648 /* For ISP8044, drv_active register has 1 bit per function,
1649 * shift 1 by func_num to set a bit for the function.*/
1650 drv_active
|= (1 << ha
->portnum
);
1652 ql_log(ql_log_info
, vha
, 0xb0c8,
1653 "%s(%ld): drv_active: 0x%08x\n",
1654 __func__
, vha
->host_no
, drv_active
);
1655 qla8044_wr_direct(vha
, QLA8044_CRB_DRV_ACTIVE_INDEX
, drv_active
);
1659 qla8044_clear_idc_dontreset(struct scsi_qla_host
*vha
)
1662 struct qla_hw_data
*ha
= vha
->hw
;
1664 idc_ctrl
= qla8044_rd_reg(ha
, QLA8044_IDC_DRV_CTRL
);
1665 idc_ctrl
&= ~DONTRESET_BIT0
;
1666 ql_log(ql_log_info
, vha
, 0xb0c9,
1667 "%s: idc_ctrl = %d\n", __func__
,
1669 qla8044_wr_reg(ha
, QLA8044_IDC_DRV_CTRL
, idc_ctrl
);
1673 qla8044_set_idc_ver(struct scsi_qla_host
*vha
)
1676 uint32_t drv_active
;
1677 int rval
= QLA_SUCCESS
;
1678 struct qla_hw_data
*ha
= vha
->hw
;
1680 drv_active
= qla8044_rd_direct(vha
, QLA8044_CRB_DRV_ACTIVE_INDEX
);
1681 if (drv_active
== (1 << ha
->portnum
)) {
1682 idc_ver
= qla8044_rd_direct(vha
,
1683 QLA8044_CRB_DRV_IDC_VERSION_INDEX
);
1685 idc_ver
|= QLA8044_IDC_VER_MAJ_VALUE
;
1686 qla8044_wr_direct(vha
, QLA8044_CRB_DRV_IDC_VERSION_INDEX
,
1688 ql_log(ql_log_info
, vha
, 0xb0ca,
1689 "%s: IDC version updated to %d\n",
1692 idc_ver
= qla8044_rd_direct(vha
,
1693 QLA8044_CRB_DRV_IDC_VERSION_INDEX
);
1695 if (QLA8044_IDC_VER_MAJ_VALUE
!= idc_ver
) {
1696 ql_log(ql_log_info
, vha
, 0xb0cb,
1697 "%s: qla4xxx driver IDC version %d "
1698 "is not compatible with IDC version %d "
1699 "of other drivers!\n",
1700 __func__
, QLA8044_IDC_VER_MAJ_VALUE
,
1702 rval
= QLA_FUNCTION_FAILED
;
1703 goto exit_set_idc_ver
;
1707 /* Update IDC_MINOR_VERSION */
1708 idc_ver
= qla8044_rd_reg(ha
, QLA8044_CRB_IDC_VER_MINOR
);
1709 idc_ver
&= ~(0x03 << (ha
->portnum
* 2));
1710 idc_ver
|= (QLA8044_IDC_VER_MIN_VALUE
<< (ha
->portnum
* 2));
1711 qla8044_wr_reg(ha
, QLA8044_CRB_IDC_VER_MINOR
, idc_ver
);
1718 qla8044_update_idc_reg(struct scsi_qla_host
*vha
)
1720 uint32_t drv_active
;
1721 int rval
= QLA_SUCCESS
;
1722 struct qla_hw_data
*ha
= vha
->hw
;
1724 if (vha
->flags
.init_done
)
1725 goto exit_update_idc_reg
;
1727 qla8044_idc_lock(ha
);
1728 qla8044_set_drv_active(vha
);
1730 drv_active
= qla8044_rd_direct(vha
,
1731 QLA8044_CRB_DRV_ACTIVE_INDEX
);
1733 /* If we are the first driver to load and
1734 * ql2xdontresethba is not set, clear IDC_CTRL BIT0. */
1735 if ((drv_active
== (1 << ha
->portnum
)) && !ql2xdontresethba
)
1736 qla8044_clear_idc_dontreset(vha
);
1738 rval
= qla8044_set_idc_ver(vha
);
1739 if (rval
== QLA_FUNCTION_FAILED
)
1740 qla8044_clear_drv_active(ha
);
1741 qla8044_idc_unlock(ha
);
1743 exit_update_idc_reg
:
1748 * qla8044_need_qsnt_handler - Code to start qsnt
1749 * @ha: pointer to adapter structure
1752 qla8044_need_qsnt_handler(struct scsi_qla_host
*vha
)
1754 unsigned long qsnt_timeout
;
1755 uint32_t drv_state
, drv_active
, dev_state
;
1756 struct qla_hw_data
*ha
= vha
->hw
;
1758 if (vha
->flags
.online
)
1759 qla2x00_quiesce_io(vha
);
1763 qla8044_set_qsnt_ready(vha
);
1765 /* Wait for 30 secs for all functions to ack qsnt mode */
1766 qsnt_timeout
= jiffies
+ (QSNT_ACK_TOV
* HZ
);
1767 drv_state
= qla8044_rd_direct(vha
, QLA8044_CRB_DRV_STATE_INDEX
);
1768 drv_active
= qla8044_rd_direct(vha
, QLA8044_CRB_DRV_ACTIVE_INDEX
);
1770 /* Shift drv_active by 1 to match drv_state. As quiescent ready bit
1771 position is at bit 1 and drv active is at bit 0 */
1772 drv_active
= drv_active
<< 1;
1774 while (drv_state
!= drv_active
) {
1775 if (time_after_eq(jiffies
, qsnt_timeout
)) {
1776 /* Other functions did not ack, changing state to
1779 clear_bit(ISP_QUIESCE_NEEDED
, &vha
->dpc_flags
);
1780 qla8044_wr_direct(vha
, QLA8044_CRB_DEV_STATE_INDEX
,
1782 qla8044_clear_qsnt_ready(vha
);
1783 ql_log(ql_log_info
, vha
, 0xb0cc,
1784 "Timeout waiting for quiescent ack!!!\n");
1787 qla8044_idc_unlock(ha
);
1789 qla8044_idc_lock(ha
);
1791 drv_state
= qla8044_rd_direct(vha
,
1792 QLA8044_CRB_DRV_STATE_INDEX
);
1793 drv_active
= qla8044_rd_direct(vha
,
1794 QLA8044_CRB_DRV_ACTIVE_INDEX
);
1795 drv_active
= drv_active
<< 1;
1798 /* All functions have Acked. Set quiescent state */
1799 dev_state
= qla8044_rd_direct(vha
, QLA8044_CRB_DEV_STATE_INDEX
);
1801 if (dev_state
== QLA8XXX_DEV_NEED_QUIESCENT
) {
1802 qla8044_wr_direct(vha
, QLA8044_CRB_DEV_STATE_INDEX
,
1803 QLA8XXX_DEV_QUIESCENT
);
1804 ql_log(ql_log_info
, vha
, 0xb0cd,
1805 "%s: HW State: QUIESCENT\n", __func__
);
1810 * qla8044_device_state_handler - Adapter state machine
1811 * @ha: pointer to host adapter structure.
1813 * Note: IDC lock must be UNLOCKED upon entry
1816 qla8044_device_state_handler(struct scsi_qla_host
*vha
)
1819 int rval
= QLA_SUCCESS
;
1820 unsigned long dev_init_timeout
;
1821 struct qla_hw_data
*ha
= vha
->hw
;
1823 rval
= qla8044_update_idc_reg(vha
);
1824 if (rval
== QLA_FUNCTION_FAILED
)
1827 dev_state
= qla8044_rd_direct(vha
, QLA8044_CRB_DEV_STATE_INDEX
);
1828 ql_dbg(ql_dbg_p3p
, vha
, 0xb0ce,
1829 "Device state is 0x%x = %s\n",
1830 dev_state
, dev_state
< MAX_STATES
?
1831 qdev_state(dev_state
) : "Unknown");
1833 /* wait for 30 seconds for device to go ready */
1834 dev_init_timeout
= jiffies
+ (ha
->fcoe_dev_init_timeout
* HZ
);
1836 qla8044_idc_lock(ha
);
1839 if (time_after_eq(jiffies
, dev_init_timeout
)) {
1840 ql_log(ql_log_warn
, vha
, 0xb0cf,
1841 "%s: Device Init Failed 0x%x = %s\n",
1842 QLA2XXX_DRIVER_NAME
, dev_state
,
1843 dev_state
< MAX_STATES
?
1844 qdev_state(dev_state
) : "Unknown");
1846 qla8044_wr_direct(vha
, QLA8044_CRB_DEV_STATE_INDEX
,
1847 QLA8XXX_DEV_FAILED
);
1850 dev_state
= qla8044_rd_direct(vha
, QLA8044_CRB_DEV_STATE_INDEX
);
1851 ql_log(ql_log_info
, vha
, 0xb0d0,
1852 "Device state is 0x%x = %s\n",
1853 dev_state
, dev_state
< MAX_STATES
?
1854 qdev_state(dev_state
) : "Unknown");
1856 /* NOTE: Make sure idc unlocked upon exit of switch statement */
1857 switch (dev_state
) {
1858 case QLA8XXX_DEV_READY
:
1859 ha
->flags
.nic_core_reset_owner
= 0;
1861 case QLA8XXX_DEV_COLD
:
1862 rval
= qla8044_device_bootstrap(vha
);
1864 case QLA8XXX_DEV_INITIALIZING
:
1865 qla8044_idc_unlock(ha
);
1867 qla8044_idc_lock(ha
);
1869 case QLA8XXX_DEV_NEED_RESET
:
1870 /* For ISP8044, if NEED_RESET is set by any driver,
1871 * it should be honored, irrespective of IDC_CTRL
1873 qla8044_need_reset_handler(vha
);
1875 case QLA8XXX_DEV_NEED_QUIESCENT
:
1876 /* idc locked/unlocked in handler */
1877 qla8044_need_qsnt_handler(vha
);
1879 /* Reset the init timeout after qsnt handler */
1880 dev_init_timeout
= jiffies
+
1881 (ha
->fcoe_reset_timeout
* HZ
);
1883 case QLA8XXX_DEV_QUIESCENT
:
1884 ql_log(ql_log_info
, vha
, 0xb0d1,
1885 "HW State: QUIESCENT\n");
1887 qla8044_idc_unlock(ha
);
1889 qla8044_idc_lock(ha
);
1891 /* Reset the init timeout after qsnt handler */
1892 dev_init_timeout
= jiffies
+
1893 (ha
->fcoe_reset_timeout
* HZ
);
1895 case QLA8XXX_DEV_FAILED
:
1896 ha
->flags
.nic_core_reset_owner
= 0;
1897 qla8044_idc_unlock(ha
);
1898 qla8xxx_dev_failed_handler(vha
);
1899 rval
= QLA_FUNCTION_FAILED
;
1900 qla8044_idc_lock(ha
);
1903 qla8044_idc_unlock(ha
);
1904 qla8xxx_dev_failed_handler(vha
);
1905 rval
= QLA_FUNCTION_FAILED
;
1906 qla8044_idc_lock(ha
);
1911 qla8044_idc_unlock(ha
);
1918 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
1919 * @ha: adapter block pointer.
1921 * Note: The caller should not hold the idc lock.
1924 qla8044_check_temp(struct scsi_qla_host
*vha
)
1926 uint32_t temp
, temp_state
, temp_val
;
1927 int status
= QLA_SUCCESS
;
1929 temp
= qla8044_rd_direct(vha
, QLA8044_CRB_TEMP_STATE_INDEX
);
1930 temp_state
= qla82xx_get_temp_state(temp
);
1931 temp_val
= qla82xx_get_temp_val(temp
);
1933 if (temp_state
== QLA82XX_TEMP_PANIC
) {
1934 ql_log(ql_log_warn
, vha
, 0xb0d2,
1935 "Device temperature %d degrees C"
1936 " exceeds maximum allowed. Hardware has been shut"
1937 " down\n", temp_val
);
1938 status
= QLA_FUNCTION_FAILED
;
1940 } else if (temp_state
== QLA82XX_TEMP_WARN
) {
1941 ql_log(ql_log_warn
, vha
, 0xb0d3,
1942 "Device temperature %d"
1943 " degrees C exceeds operating range."
1944 " Immediate action needed.\n", temp_val
);
1949 int qla8044_read_temperature(scsi_qla_host_t
*vha
)
1953 temp
= qla8044_rd_direct(vha
, QLA8044_CRB_TEMP_STATE_INDEX
);
1954 return qla82xx_get_temp_val(temp
);
1958 * qla8044_check_fw_alive - Check firmware health
1959 * @ha: Pointer to host adapter structure.
1961 * Context: Interrupt
1964 qla8044_check_fw_alive(struct scsi_qla_host
*vha
)
1966 uint32_t fw_heartbeat_counter
;
1967 uint32_t halt_status1
, halt_status2
;
1968 int status
= QLA_SUCCESS
;
1970 fw_heartbeat_counter
= qla8044_rd_direct(vha
,
1971 QLA8044_PEG_ALIVE_COUNTER_INDEX
);
1973 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
1974 if (fw_heartbeat_counter
== 0xffffffff) {
1975 ql_dbg(ql_dbg_p3p
, vha
, 0xb0d4,
1976 "scsi%ld: %s: Device in frozen "
1977 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
1978 vha
->host_no
, __func__
);
1982 if (vha
->fw_heartbeat_counter
== fw_heartbeat_counter
) {
1983 vha
->seconds_since_last_heartbeat
++;
1984 /* FW not alive after 2 seconds */
1985 if (vha
->seconds_since_last_heartbeat
== 2) {
1986 vha
->seconds_since_last_heartbeat
= 0;
1987 halt_status1
= qla8044_rd_direct(vha
,
1988 QLA8044_PEG_HALT_STATUS1_INDEX
);
1989 halt_status2
= qla8044_rd_direct(vha
,
1990 QLA8044_PEG_HALT_STATUS2_INDEX
);
1992 ql_log(ql_log_info
, vha
, 0xb0d5,
1993 "scsi(%ld): %s, ISP8044 "
1994 "Dumping hw/fw registers:\n"
1995 " PEG_HALT_STATUS1: 0x%x, "
1996 "PEG_HALT_STATUS2: 0x%x,\n",
1997 vha
->host_no
, __func__
, halt_status1
,
1999 status
= QLA_FUNCTION_FAILED
;
2002 vha
->seconds_since_last_heartbeat
= 0;
2004 vha
->fw_heartbeat_counter
= fw_heartbeat_counter
;
2009 qla8044_watchdog(struct scsi_qla_host
*vha
)
2011 uint32_t dev_state
, halt_status
;
2012 int halt_status_unrecoverable
= 0;
2013 struct qla_hw_data
*ha
= vha
->hw
;
2015 /* don't poll if reset is going on or FW hang in quiescent state */
2016 if (!(test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
) ||
2017 test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
) ||
2018 test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
) ||
2019 test_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
))) {
2020 dev_state
= qla8044_rd_direct(vha
, QLA8044_CRB_DEV_STATE_INDEX
);
2022 if (qla8044_check_temp(vha
)) {
2023 set_bit(ISP_UNRECOVERABLE
, &vha
->dpc_flags
);
2024 ha
->flags
.isp82xx_fw_hung
= 1;
2025 qla2xxx_wake_dpc(vha
);
2026 } else if (dev_state
== QLA8XXX_DEV_NEED_RESET
&&
2027 !test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
)) {
2028 ql_log(ql_log_info
, vha
, 0xb0d6,
2029 "%s: HW State: NEED RESET!\n",
2031 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2032 qla2xxx_wake_dpc(vha
);
2033 } else if (dev_state
== QLA8XXX_DEV_NEED_QUIESCENT
&&
2034 !test_bit(ISP_QUIESCE_NEEDED
, &vha
->dpc_flags
)) {
2035 ql_log(ql_log_info
, vha
, 0xb0d7,
2036 "%s: HW State: NEED QUIES detected!\n",
2038 set_bit(ISP_QUIESCE_NEEDED
, &vha
->dpc_flags
);
2039 qla2xxx_wake_dpc(vha
);
2041 /* Check firmware health */
2042 if (qla8044_check_fw_alive(vha
)) {
2043 halt_status
= qla8044_rd_direct(vha
,
2044 QLA8044_PEG_HALT_STATUS1_INDEX
);
2046 QLA8044_HALT_STATUS_FW_RESET
) {
2047 ql_log(ql_log_fatal
, vha
,
2048 0xb0d8, "%s: Firmware "
2049 "error detected device "
2052 } else if (halt_status
&
2053 QLA8044_HALT_STATUS_UNRECOVERABLE
) {
2054 halt_status_unrecoverable
= 1;
2057 /* Since we cannot change dev_state in interrupt
2058 * context, set appropriate DPC flag then wakeup
2060 if (halt_status_unrecoverable
) {
2061 set_bit(ISP_UNRECOVERABLE
,
2065 QLA8XXX_DEV_QUIESCENT
) {
2066 set_bit(FCOE_CTX_RESET_NEEDED
,
2068 ql_log(ql_log_info
, vha
, 0xb0d9,
2069 "%s: FW CONTEXT Reset "
2070 "needed!\n", __func__
);
2072 ql_log(ql_log_info
, vha
,
2074 "detect abort needed\n",
2076 set_bit(ISP_ABORT_NEEDED
,
2078 qla82xx_clear_pending_mbx(vha
);
2081 ha
->flags
.isp82xx_fw_hung
= 1;
2082 ql_log(ql_log_warn
, vha
, 0xb10a,
2083 "Firmware hung.\n");
2084 qla2xxx_wake_dpc(vha
);
2092 qla8044_minidump_process_control(struct scsi_qla_host
*vha
,
2093 struct qla8044_minidump_entry_hdr
*entry_hdr
)
2095 struct qla8044_minidump_entry_crb
*crb_entry
;
2096 uint32_t read_value
, opcode
, poll_time
, addr
, index
;
2097 uint32_t crb_addr
, rval
= QLA_SUCCESS
;
2098 unsigned long wtime
;
2099 struct qla8044_minidump_template_hdr
*tmplt_hdr
;
2101 struct qla_hw_data
*ha
= vha
->hw
;
2103 ql_dbg(ql_dbg_p3p
, vha
, 0xb0dd, "Entering fn: %s\n", __func__
);
2104 tmplt_hdr
= (struct qla8044_minidump_template_hdr
*)
2106 crb_entry
= (struct qla8044_minidump_entry_crb
*)entry_hdr
;
2108 crb_addr
= crb_entry
->addr
;
2109 for (i
= 0; i
< crb_entry
->op_count
; i
++) {
2110 opcode
= crb_entry
->crb_ctrl
.opcode
;
2112 if (opcode
& QLA82XX_DBG_OPCODE_WR
) {
2113 qla8044_wr_reg_indirect(vha
, crb_addr
,
2114 crb_entry
->value_1
);
2115 opcode
&= ~QLA82XX_DBG_OPCODE_WR
;
2118 if (opcode
& QLA82XX_DBG_OPCODE_RW
) {
2119 qla8044_rd_reg_indirect(vha
, crb_addr
, &read_value
);
2120 qla8044_wr_reg_indirect(vha
, crb_addr
, read_value
);
2121 opcode
&= ~QLA82XX_DBG_OPCODE_RW
;
2124 if (opcode
& QLA82XX_DBG_OPCODE_AND
) {
2125 qla8044_rd_reg_indirect(vha
, crb_addr
, &read_value
);
2126 read_value
&= crb_entry
->value_2
;
2127 opcode
&= ~QLA82XX_DBG_OPCODE_AND
;
2128 if (opcode
& QLA82XX_DBG_OPCODE_OR
) {
2129 read_value
|= crb_entry
->value_3
;
2130 opcode
&= ~QLA82XX_DBG_OPCODE_OR
;
2132 qla8044_wr_reg_indirect(vha
, crb_addr
, read_value
);
2134 if (opcode
& QLA82XX_DBG_OPCODE_OR
) {
2135 qla8044_rd_reg_indirect(vha
, crb_addr
, &read_value
);
2136 read_value
|= crb_entry
->value_3
;
2137 qla8044_wr_reg_indirect(vha
, crb_addr
, read_value
);
2138 opcode
&= ~QLA82XX_DBG_OPCODE_OR
;
2140 if (opcode
& QLA82XX_DBG_OPCODE_POLL
) {
2141 poll_time
= crb_entry
->crb_strd
.poll_timeout
;
2142 wtime
= jiffies
+ poll_time
;
2143 qla8044_rd_reg_indirect(vha
, crb_addr
, &read_value
);
2146 if ((read_value
& crb_entry
->value_2
) ==
2147 crb_entry
->value_1
) {
2149 } else if (time_after_eq(jiffies
, wtime
)) {
2150 /* capturing dump failed */
2151 rval
= QLA_FUNCTION_FAILED
;
2154 qla8044_rd_reg_indirect(vha
,
2155 crb_addr
, &read_value
);
2158 opcode
&= ~QLA82XX_DBG_OPCODE_POLL
;
2161 if (opcode
& QLA82XX_DBG_OPCODE_RDSTATE
) {
2162 if (crb_entry
->crb_strd
.state_index_a
) {
2163 index
= crb_entry
->crb_strd
.state_index_a
;
2164 addr
= tmplt_hdr
->saved_state_array
[index
];
2169 qla8044_rd_reg_indirect(vha
, addr
, &read_value
);
2170 index
= crb_entry
->crb_ctrl
.state_index_v
;
2171 tmplt_hdr
->saved_state_array
[index
] = read_value
;
2172 opcode
&= ~QLA82XX_DBG_OPCODE_RDSTATE
;
2175 if (opcode
& QLA82XX_DBG_OPCODE_WRSTATE
) {
2176 if (crb_entry
->crb_strd
.state_index_a
) {
2177 index
= crb_entry
->crb_strd
.state_index_a
;
2178 addr
= tmplt_hdr
->saved_state_array
[index
];
2183 if (crb_entry
->crb_ctrl
.state_index_v
) {
2184 index
= crb_entry
->crb_ctrl
.state_index_v
;
2186 tmplt_hdr
->saved_state_array
[index
];
2188 read_value
= crb_entry
->value_1
;
2191 qla8044_wr_reg_indirect(vha
, addr
, read_value
);
2192 opcode
&= ~QLA82XX_DBG_OPCODE_WRSTATE
;
2195 if (opcode
& QLA82XX_DBG_OPCODE_MDSTATE
) {
2196 index
= crb_entry
->crb_ctrl
.state_index_v
;
2197 read_value
= tmplt_hdr
->saved_state_array
[index
];
2198 read_value
<<= crb_entry
->crb_ctrl
.shl
;
2199 read_value
>>= crb_entry
->crb_ctrl
.shr
;
2200 if (crb_entry
->value_2
)
2201 read_value
&= crb_entry
->value_2
;
2202 read_value
|= crb_entry
->value_3
;
2203 read_value
+= crb_entry
->value_1
;
2204 tmplt_hdr
->saved_state_array
[index
] = read_value
;
2205 opcode
&= ~QLA82XX_DBG_OPCODE_MDSTATE
;
2207 crb_addr
+= crb_entry
->crb_strd
.addr_stride
;
2213 qla8044_minidump_process_rdcrb(struct scsi_qla_host
*vha
,
2214 struct qla8044_minidump_entry_hdr
*entry_hdr
, uint32_t **d_ptr
)
2216 uint32_t r_addr
, r_stride
, loop_cnt
, i
, r_value
;
2217 struct qla8044_minidump_entry_crb
*crb_hdr
;
2218 uint32_t *data_ptr
= *d_ptr
;
2220 ql_dbg(ql_dbg_p3p
, vha
, 0xb0de, "Entering fn: %s\n", __func__
);
2221 crb_hdr
= (struct qla8044_minidump_entry_crb
*)entry_hdr
;
2222 r_addr
= crb_hdr
->addr
;
2223 r_stride
= crb_hdr
->crb_strd
.addr_stride
;
2224 loop_cnt
= crb_hdr
->op_count
;
2226 for (i
= 0; i
< loop_cnt
; i
++) {
2227 qla8044_rd_reg_indirect(vha
, r_addr
, &r_value
);
2228 *data_ptr
++ = r_addr
;
2229 *data_ptr
++ = r_value
;
2236 qla8044_minidump_process_rdmem(struct scsi_qla_host
*vha
,
2237 struct qla8044_minidump_entry_hdr
*entry_hdr
, uint32_t **d_ptr
)
2239 uint32_t r_addr
, r_value
, r_data
;
2240 uint32_t i
, j
, loop_cnt
;
2241 struct qla8044_minidump_entry_rdmem
*m_hdr
;
2242 unsigned long flags
;
2243 uint32_t *data_ptr
= *d_ptr
;
2244 struct qla_hw_data
*ha
= vha
->hw
;
2246 ql_dbg(ql_dbg_p3p
, vha
, 0xb0df, "Entering fn: %s\n", __func__
);
2247 m_hdr
= (struct qla8044_minidump_entry_rdmem
*)entry_hdr
;
2248 r_addr
= m_hdr
->read_addr
;
2249 loop_cnt
= m_hdr
->read_data_size
/16;
2251 ql_dbg(ql_dbg_p3p
, vha
, 0xb0f0,
2252 "[%s]: Read addr: 0x%x, read_data_size: 0x%x\n",
2253 __func__
, r_addr
, m_hdr
->read_data_size
);
2256 ql_dbg(ql_dbg_p3p
, vha
, 0xb0f1,
2257 "[%s]: Read addr 0x%x not 16 bytes aligned\n",
2259 return QLA_FUNCTION_FAILED
;
2262 if (m_hdr
->read_data_size
% 16) {
2263 ql_dbg(ql_dbg_p3p
, vha
, 0xb0f2,
2264 "[%s]: Read data[0x%x] not multiple of 16 bytes\n",
2265 __func__
, m_hdr
->read_data_size
);
2266 return QLA_FUNCTION_FAILED
;
2269 ql_dbg(ql_dbg_p3p
, vha
, 0xb0f3,
2270 "[%s]: rdmem_addr: 0x%x, read_data_size: 0x%x, loop_cnt: 0x%x\n",
2271 __func__
, r_addr
, m_hdr
->read_data_size
, loop_cnt
);
2273 write_lock_irqsave(&ha
->hw_lock
, flags
);
2274 for (i
= 0; i
< loop_cnt
; i
++) {
2275 qla8044_wr_reg_indirect(vha
, MD_MIU_TEST_AGT_ADDR_LO
, r_addr
);
2277 qla8044_wr_reg_indirect(vha
, MD_MIU_TEST_AGT_ADDR_HI
, r_value
);
2278 r_value
= MIU_TA_CTL_ENABLE
;
2279 qla8044_wr_reg_indirect(vha
, MD_MIU_TEST_AGT_CTRL
, r_value
);
2280 r_value
= MIU_TA_CTL_START_ENABLE
;
2281 qla8044_wr_reg_indirect(vha
, MD_MIU_TEST_AGT_CTRL
, r_value
);
2283 for (j
= 0; j
< MAX_CTL_CHECK
; j
++) {
2284 qla8044_rd_reg_indirect(vha
, MD_MIU_TEST_AGT_CTRL
,
2286 if ((r_value
& MIU_TA_CTL_BUSY
) == 0)
2290 if (j
>= MAX_CTL_CHECK
) {
2291 printk_ratelimited(KERN_ERR
2292 "%s: failed to read through agent\n", __func__
);
2293 write_unlock_irqrestore(&ha
->hw_lock
, flags
);
2297 for (j
= 0; j
< 4; j
++) {
2298 qla8044_rd_reg_indirect(vha
, MD_MIU_TEST_AGT_RDDATA
[j
],
2300 *data_ptr
++ = r_data
;
2305 write_unlock_irqrestore(&ha
->hw_lock
, flags
);
2307 ql_dbg(ql_dbg_p3p
, vha
, 0xb0f4,
2308 "Leaving fn: %s datacount: 0x%x\n",
2309 __func__
, (loop_cnt
* 16));
2315 /* ISP83xx flash read for _RDROM _BOARD */
2317 qla8044_minidump_process_rdrom(struct scsi_qla_host
*vha
,
2318 struct qla8044_minidump_entry_hdr
*entry_hdr
, uint32_t **d_ptr
)
2320 uint32_t fl_addr
, u32_count
, rval
;
2321 struct qla8044_minidump_entry_rdrom
*rom_hdr
;
2322 uint32_t *data_ptr
= *d_ptr
;
2324 rom_hdr
= (struct qla8044_minidump_entry_rdrom
*)entry_hdr
;
2325 fl_addr
= rom_hdr
->read_addr
;
2326 u32_count
= (rom_hdr
->read_data_size
)/sizeof(uint32_t);
2328 ql_dbg(ql_dbg_p3p
, vha
, 0xb0f5, "[%s]: fl_addr: 0x%x, count: 0x%x\n",
2329 __func__
, fl_addr
, u32_count
);
2331 rval
= qla8044_lockless_flash_read_u32(vha
, fl_addr
,
2332 (u8
*)(data_ptr
), u32_count
);
2334 if (rval
!= QLA_SUCCESS
) {
2335 ql_log(ql_log_fatal
, vha
, 0xb0f6,
2336 "%s: Flash Read Error,Count=%d\n", __func__
, u32_count
);
2337 return QLA_FUNCTION_FAILED
;
2339 data_ptr
+= u32_count
;
2346 qla8044_mark_entry_skipped(struct scsi_qla_host
*vha
,
2347 struct qla8044_minidump_entry_hdr
*entry_hdr
, int index
)
2349 entry_hdr
->d_ctrl
.driver_flags
|= QLA82XX_DBG_SKIPPED_FLAG
;
2351 ql_log(ql_log_info
, vha
, 0xb0f7,
2352 "scsi(%ld): Skipping entry[%d]: ETYPE[0x%x]-ELEVEL[0x%x]\n",
2353 vha
->host_no
, index
, entry_hdr
->entry_type
,
2354 entry_hdr
->d_ctrl
.entry_capture_mask
);
2358 qla8044_minidump_process_l2tag(struct scsi_qla_host
*vha
,
2359 struct qla8044_minidump_entry_hdr
*entry_hdr
,
2362 uint32_t addr
, r_addr
, c_addr
, t_r_addr
;
2363 uint32_t i
, k
, loop_count
, t_value
, r_cnt
, r_value
;
2364 unsigned long p_wait
, w_time
, p_mask
;
2365 uint32_t c_value_w
, c_value_r
;
2366 struct qla8044_minidump_entry_cache
*cache_hdr
;
2367 int rval
= QLA_FUNCTION_FAILED
;
2368 uint32_t *data_ptr
= *d_ptr
;
2370 ql_dbg(ql_dbg_p3p
, vha
, 0xb0f8, "Entering fn: %s\n", __func__
);
2371 cache_hdr
= (struct qla8044_minidump_entry_cache
*)entry_hdr
;
2373 loop_count
= cache_hdr
->op_count
;
2374 r_addr
= cache_hdr
->read_addr
;
2375 c_addr
= cache_hdr
->control_addr
;
2376 c_value_w
= cache_hdr
->cache_ctrl
.write_value
;
2378 t_r_addr
= cache_hdr
->tag_reg_addr
;
2379 t_value
= cache_hdr
->addr_ctrl
.init_tag_value
;
2380 r_cnt
= cache_hdr
->read_ctrl
.read_addr_cnt
;
2381 p_wait
= cache_hdr
->cache_ctrl
.poll_wait
;
2382 p_mask
= cache_hdr
->cache_ctrl
.poll_mask
;
2384 for (i
= 0; i
< loop_count
; i
++) {
2385 qla8044_wr_reg_indirect(vha
, t_r_addr
, t_value
);
2387 qla8044_wr_reg_indirect(vha
, c_addr
, c_value_w
);
2390 w_time
= jiffies
+ p_wait
;
2392 qla8044_rd_reg_indirect(vha
, c_addr
,
2394 if ((c_value_r
& p_mask
) == 0) {
2396 } else if (time_after_eq(jiffies
, w_time
)) {
2397 /* capturing dump failed */
2404 for (k
= 0; k
< r_cnt
; k
++) {
2405 qla8044_rd_reg_indirect(vha
, addr
, &r_value
);
2406 *data_ptr
++ = r_value
;
2407 addr
+= cache_hdr
->read_ctrl
.read_addr_stride
;
2409 t_value
+= cache_hdr
->addr_ctrl
.tag_value_stride
;
2416 qla8044_minidump_process_l1cache(struct scsi_qla_host
*vha
,
2417 struct qla8044_minidump_entry_hdr
*entry_hdr
, uint32_t **d_ptr
)
2419 uint32_t addr
, r_addr
, c_addr
, t_r_addr
;
2420 uint32_t i
, k
, loop_count
, t_value
, r_cnt
, r_value
;
2422 struct qla8044_minidump_entry_cache
*cache_hdr
;
2423 uint32_t *data_ptr
= *d_ptr
;
2425 cache_hdr
= (struct qla8044_minidump_entry_cache
*)entry_hdr
;
2426 loop_count
= cache_hdr
->op_count
;
2427 r_addr
= cache_hdr
->read_addr
;
2428 c_addr
= cache_hdr
->control_addr
;
2429 c_value_w
= cache_hdr
->cache_ctrl
.write_value
;
2431 t_r_addr
= cache_hdr
->tag_reg_addr
;
2432 t_value
= cache_hdr
->addr_ctrl
.init_tag_value
;
2433 r_cnt
= cache_hdr
->read_ctrl
.read_addr_cnt
;
2435 for (i
= 0; i
< loop_count
; i
++) {
2436 qla8044_wr_reg_indirect(vha
, t_r_addr
, t_value
);
2437 qla8044_wr_reg_indirect(vha
, c_addr
, c_value_w
);
2439 for (k
= 0; k
< r_cnt
; k
++) {
2440 qla8044_rd_reg_indirect(vha
, addr
, &r_value
);
2441 *data_ptr
++ = r_value
;
2442 addr
+= cache_hdr
->read_ctrl
.read_addr_stride
;
2444 t_value
+= cache_hdr
->addr_ctrl
.tag_value_stride
;
2450 qla8044_minidump_process_rdocm(struct scsi_qla_host
*vha
,
2451 struct qla8044_minidump_entry_hdr
*entry_hdr
, uint32_t **d_ptr
)
2453 uint32_t r_addr
, r_stride
, loop_cnt
, i
, r_value
;
2454 struct qla8044_minidump_entry_rdocm
*ocm_hdr
;
2455 uint32_t *data_ptr
= *d_ptr
;
2456 struct qla_hw_data
*ha
= vha
->hw
;
2458 ql_dbg(ql_dbg_p3p
, vha
, 0xb0f9, "Entering fn: %s\n", __func__
);
2460 ocm_hdr
= (struct qla8044_minidump_entry_rdocm
*)entry_hdr
;
2461 r_addr
= ocm_hdr
->read_addr
;
2462 r_stride
= ocm_hdr
->read_addr_stride
;
2463 loop_cnt
= ocm_hdr
->op_count
;
2465 ql_dbg(ql_dbg_p3p
, vha
, 0xb0fa,
2466 "[%s]: r_addr: 0x%x, r_stride: 0x%x, loop_cnt: 0x%x\n",
2467 __func__
, r_addr
, r_stride
, loop_cnt
);
2469 for (i
= 0; i
< loop_cnt
; i
++) {
2470 r_value
= readl((void __iomem
*)(r_addr
+ ha
->nx_pcibase
));
2471 *data_ptr
++ = r_value
;
2474 ql_dbg(ql_dbg_p3p
, vha
, 0xb0fb, "Leaving fn: %s datacount: 0x%lx\n",
2475 __func__
, (long unsigned int) (loop_cnt
* sizeof(uint32_t)));
2481 qla8044_minidump_process_rdmux(struct scsi_qla_host
*vha
,
2482 struct qla8044_minidump_entry_hdr
*entry_hdr
,
2485 uint32_t r_addr
, s_stride
, s_addr
, s_value
, loop_cnt
, i
, r_value
;
2486 struct qla8044_minidump_entry_mux
*mux_hdr
;
2487 uint32_t *data_ptr
= *d_ptr
;
2489 ql_dbg(ql_dbg_p3p
, vha
, 0xb0fc, "Entering fn: %s\n", __func__
);
2491 mux_hdr
= (struct qla8044_minidump_entry_mux
*)entry_hdr
;
2492 r_addr
= mux_hdr
->read_addr
;
2493 s_addr
= mux_hdr
->select_addr
;
2494 s_stride
= mux_hdr
->select_value_stride
;
2495 s_value
= mux_hdr
->select_value
;
2496 loop_cnt
= mux_hdr
->op_count
;
2498 for (i
= 0; i
< loop_cnt
; i
++) {
2499 qla8044_wr_reg_indirect(vha
, s_addr
, s_value
);
2500 qla8044_rd_reg_indirect(vha
, r_addr
, &r_value
);
2501 *data_ptr
++ = s_value
;
2502 *data_ptr
++ = r_value
;
2503 s_value
+= s_stride
;
2509 qla8044_minidump_process_queue(struct scsi_qla_host
*vha
,
2510 struct qla8044_minidump_entry_hdr
*entry_hdr
,
2513 uint32_t s_addr
, r_addr
;
2514 uint32_t r_stride
, r_value
, r_cnt
, qid
= 0;
2515 uint32_t i
, k
, loop_cnt
;
2516 struct qla8044_minidump_entry_queue
*q_hdr
;
2517 uint32_t *data_ptr
= *d_ptr
;
2519 ql_dbg(ql_dbg_p3p
, vha
, 0xb0fd, "Entering fn: %s\n", __func__
);
2520 q_hdr
= (struct qla8044_minidump_entry_queue
*)entry_hdr
;
2521 s_addr
= q_hdr
->select_addr
;
2522 r_cnt
= q_hdr
->rd_strd
.read_addr_cnt
;
2523 r_stride
= q_hdr
->rd_strd
.read_addr_stride
;
2524 loop_cnt
= q_hdr
->op_count
;
2526 for (i
= 0; i
< loop_cnt
; i
++) {
2527 qla8044_wr_reg_indirect(vha
, s_addr
, qid
);
2528 r_addr
= q_hdr
->read_addr
;
2529 for (k
= 0; k
< r_cnt
; k
++) {
2530 qla8044_rd_reg_indirect(vha
, r_addr
, &r_value
);
2531 *data_ptr
++ = r_value
;
2534 qid
+= q_hdr
->q_strd
.queue_id_stride
;
2539 /* ISP83xx functions to process new minidump entries... */
2541 qla8044_minidump_process_pollrd(struct scsi_qla_host
*vha
,
2542 struct qla8044_minidump_entry_hdr
*entry_hdr
,
2545 uint32_t r_addr
, s_addr
, s_value
, r_value
, poll_wait
, poll_mask
;
2546 uint16_t s_stride
, i
;
2547 struct qla8044_minidump_entry_pollrd
*pollrd_hdr
;
2548 uint32_t *data_ptr
= *d_ptr
;
2550 pollrd_hdr
= (struct qla8044_minidump_entry_pollrd
*) entry_hdr
;
2551 s_addr
= pollrd_hdr
->select_addr
;
2552 r_addr
= pollrd_hdr
->read_addr
;
2553 s_value
= pollrd_hdr
->select_value
;
2554 s_stride
= pollrd_hdr
->select_value_stride
;
2556 poll_wait
= pollrd_hdr
->poll_wait
;
2557 poll_mask
= pollrd_hdr
->poll_mask
;
2559 for (i
= 0; i
< pollrd_hdr
->op_count
; i
++) {
2560 qla8044_wr_reg_indirect(vha
, s_addr
, s_value
);
2561 poll_wait
= pollrd_hdr
->poll_wait
;
2563 qla8044_rd_reg_indirect(vha
, s_addr
, &r_value
);
2564 if ((r_value
& poll_mask
) != 0) {
2567 usleep_range(1000, 1100);
2568 if (--poll_wait
== 0) {
2569 ql_log(ql_log_fatal
, vha
, 0xb0fe,
2570 "%s: TIMEOUT\n", __func__
);
2575 qla8044_rd_reg_indirect(vha
, r_addr
, &r_value
);
2576 *data_ptr
++ = s_value
;
2577 *data_ptr
++ = r_value
;
2579 s_value
+= s_stride
;
2585 return QLA_FUNCTION_FAILED
;
2589 qla8044_minidump_process_rdmux2(struct scsi_qla_host
*vha
,
2590 struct qla8044_minidump_entry_hdr
*entry_hdr
, uint32_t **d_ptr
)
2592 uint32_t sel_val1
, sel_val2
, t_sel_val
, data
, i
;
2593 uint32_t sel_addr1
, sel_addr2
, sel_val_mask
, read_addr
;
2594 struct qla8044_minidump_entry_rdmux2
*rdmux2_hdr
;
2595 uint32_t *data_ptr
= *d_ptr
;
2597 rdmux2_hdr
= (struct qla8044_minidump_entry_rdmux2
*) entry_hdr
;
2598 sel_val1
= rdmux2_hdr
->select_value_1
;
2599 sel_val2
= rdmux2_hdr
->select_value_2
;
2600 sel_addr1
= rdmux2_hdr
->select_addr_1
;
2601 sel_addr2
= rdmux2_hdr
->select_addr_2
;
2602 sel_val_mask
= rdmux2_hdr
->select_value_mask
;
2603 read_addr
= rdmux2_hdr
->read_addr
;
2605 for (i
= 0; i
< rdmux2_hdr
->op_count
; i
++) {
2606 qla8044_wr_reg_indirect(vha
, sel_addr1
, sel_val1
);
2607 t_sel_val
= sel_val1
& sel_val_mask
;
2608 *data_ptr
++ = t_sel_val
;
2610 qla8044_wr_reg_indirect(vha
, sel_addr2
, t_sel_val
);
2611 qla8044_rd_reg_indirect(vha
, read_addr
, &data
);
2615 qla8044_wr_reg_indirect(vha
, sel_addr1
, sel_val2
);
2616 t_sel_val
= sel_val2
& sel_val_mask
;
2617 *data_ptr
++ = t_sel_val
;
2619 qla8044_wr_reg_indirect(vha
, sel_addr2
, t_sel_val
);
2620 qla8044_rd_reg_indirect(vha
, read_addr
, &data
);
2624 sel_val1
+= rdmux2_hdr
->select_value_stride
;
2625 sel_val2
+= rdmux2_hdr
->select_value_stride
;
2632 qla8044_minidump_process_pollrdmwr(struct scsi_qla_host
*vha
,
2633 struct qla8044_minidump_entry_hdr
*entry_hdr
,
2636 uint32_t poll_wait
, poll_mask
, r_value
, data
;
2637 uint32_t addr_1
, addr_2
, value_1
, value_2
;
2638 struct qla8044_minidump_entry_pollrdmwr
*poll_hdr
;
2639 uint32_t *data_ptr
= *d_ptr
;
2641 poll_hdr
= (struct qla8044_minidump_entry_pollrdmwr
*) entry_hdr
;
2642 addr_1
= poll_hdr
->addr_1
;
2643 addr_2
= poll_hdr
->addr_2
;
2644 value_1
= poll_hdr
->value_1
;
2645 value_2
= poll_hdr
->value_2
;
2646 poll_mask
= poll_hdr
->poll_mask
;
2648 qla8044_wr_reg_indirect(vha
, addr_1
, value_1
);
2650 poll_wait
= poll_hdr
->poll_wait
;
2652 qla8044_rd_reg_indirect(vha
, addr_1
, &r_value
);
2654 if ((r_value
& poll_mask
) != 0) {
2657 usleep_range(1000, 1100);
2658 if (--poll_wait
== 0) {
2659 ql_log(ql_log_fatal
, vha
, 0xb0ff,
2660 "%s: TIMEOUT\n", __func__
);
2666 qla8044_rd_reg_indirect(vha
, addr_2
, &data
);
2667 data
&= poll_hdr
->modify_mask
;
2668 qla8044_wr_reg_indirect(vha
, addr_2
, data
);
2669 qla8044_wr_reg_indirect(vha
, addr_1
, value_2
);
2671 poll_wait
= poll_hdr
->poll_wait
;
2673 qla8044_rd_reg_indirect(vha
, addr_1
, &r_value
);
2675 if ((r_value
& poll_mask
) != 0) {
2678 usleep_range(1000, 1100);
2679 if (--poll_wait
== 0) {
2680 ql_log(ql_log_fatal
, vha
, 0xb100,
2681 "%s: TIMEOUT2\n", __func__
);
2687 *data_ptr
++ = addr_2
;
2695 return QLA_FUNCTION_FAILED
;
2698 #define ISP8044_PEX_DMA_ENGINE_INDEX 8
2699 #define ISP8044_PEX_DMA_BASE_ADDRESS 0x77320000
2700 #define ISP8044_PEX_DMA_NUM_OFFSET 0x10000
2701 #define ISP8044_PEX_DMA_CMD_ADDR_LOW 0x0
2702 #define ISP8044_PEX_DMA_CMD_ADDR_HIGH 0x04
2703 #define ISP8044_PEX_DMA_CMD_STS_AND_CNTRL 0x08
2705 #define ISP8044_PEX_DMA_READ_SIZE (16 * 1024)
2706 #define ISP8044_PEX_DMA_MAX_WAIT (100 * 100) /* Max wait of 100 msecs */
2709 qla8044_check_dma_engine_state(struct scsi_qla_host
*vha
)
2711 struct qla_hw_data
*ha
= vha
->hw
;
2712 int rval
= QLA_SUCCESS
;
2713 uint32_t dma_eng_num
= 0, cmd_sts_and_cntrl
= 0;
2714 uint64_t dma_base_addr
= 0;
2715 struct qla8044_minidump_template_hdr
*tmplt_hdr
= NULL
;
2717 tmplt_hdr
= ha
->md_tmplt_hdr
;
2719 tmplt_hdr
->saved_state_array
[ISP8044_PEX_DMA_ENGINE_INDEX
];
2720 dma_base_addr
= ISP8044_PEX_DMA_BASE_ADDRESS
+
2721 (dma_eng_num
* ISP8044_PEX_DMA_NUM_OFFSET
);
2723 /* Read the pex-dma's command-status-and-control register. */
2724 rval
= qla8044_rd_reg_indirect(vha
,
2725 (dma_base_addr
+ ISP8044_PEX_DMA_CMD_STS_AND_CNTRL
),
2726 &cmd_sts_and_cntrl
);
2728 return QLA_FUNCTION_FAILED
;
2730 /* Check if requested pex-dma engine is available. */
2731 if (cmd_sts_and_cntrl
& BIT_31
)
2734 return QLA_FUNCTION_FAILED
;
2738 qla8044_start_pex_dma(struct scsi_qla_host
*vha
,
2739 struct qla8044_minidump_entry_rdmem_pex_dma
*m_hdr
)
2741 struct qla_hw_data
*ha
= vha
->hw
;
2742 int rval
= QLA_SUCCESS
, wait
= 0;
2743 uint32_t dma_eng_num
= 0, cmd_sts_and_cntrl
= 0;
2744 uint64_t dma_base_addr
= 0;
2745 struct qla8044_minidump_template_hdr
*tmplt_hdr
= NULL
;
2747 tmplt_hdr
= ha
->md_tmplt_hdr
;
2749 tmplt_hdr
->saved_state_array
[ISP8044_PEX_DMA_ENGINE_INDEX
];
2750 dma_base_addr
= ISP8044_PEX_DMA_BASE_ADDRESS
+
2751 (dma_eng_num
* ISP8044_PEX_DMA_NUM_OFFSET
);
2753 rval
= qla8044_wr_reg_indirect(vha
,
2754 dma_base_addr
+ ISP8044_PEX_DMA_CMD_ADDR_LOW
,
2755 m_hdr
->desc_card_addr
);
2759 rval
= qla8044_wr_reg_indirect(vha
,
2760 dma_base_addr
+ ISP8044_PEX_DMA_CMD_ADDR_HIGH
, 0);
2764 rval
= qla8044_wr_reg_indirect(vha
,
2765 dma_base_addr
+ ISP8044_PEX_DMA_CMD_STS_AND_CNTRL
,
2766 m_hdr
->start_dma_cmd
);
2770 /* Wait for dma operation to complete. */
2771 for (wait
= 0; wait
< ISP8044_PEX_DMA_MAX_WAIT
; wait
++) {
2772 rval
= qla8044_rd_reg_indirect(vha
,
2773 (dma_base_addr
+ ISP8044_PEX_DMA_CMD_STS_AND_CNTRL
),
2774 &cmd_sts_and_cntrl
);
2778 if ((cmd_sts_and_cntrl
& BIT_1
) == 0)
2784 /* Wait a max of 100 ms, otherwise fallback to rdmem entry read */
2785 if (wait
>= ISP8044_PEX_DMA_MAX_WAIT
) {
2786 rval
= QLA_FUNCTION_FAILED
;
2795 qla8044_minidump_pex_dma_read(struct scsi_qla_host
*vha
,
2796 struct qla8044_minidump_entry_hdr
*entry_hdr
, uint32_t **d_ptr
)
2798 struct qla_hw_data
*ha
= vha
->hw
;
2799 int rval
= QLA_SUCCESS
;
2800 struct qla8044_minidump_entry_rdmem_pex_dma
*m_hdr
= NULL
;
2801 uint32_t chunk_size
, read_size
;
2802 uint8_t *data_ptr
= (uint8_t *)*d_ptr
;
2803 void *rdmem_buffer
= NULL
;
2804 dma_addr_t rdmem_dma
;
2805 struct qla8044_pex_dma_descriptor dma_desc
;
2807 rval
= qla8044_check_dma_engine_state(vha
);
2808 if (rval
!= QLA_SUCCESS
) {
2809 ql_dbg(ql_dbg_p3p
, vha
, 0xb147,
2810 "DMA engine not available. Fallback to rdmem-read.\n");
2811 return QLA_FUNCTION_FAILED
;
2814 m_hdr
= (void *)entry_hdr
;
2816 rdmem_buffer
= dma_alloc_coherent(&ha
->pdev
->dev
,
2817 ISP8044_PEX_DMA_READ_SIZE
, &rdmem_dma
, GFP_KERNEL
);
2818 if (!rdmem_buffer
) {
2819 ql_dbg(ql_dbg_p3p
, vha
, 0xb148,
2820 "Unable to allocate rdmem dma buffer\n");
2821 return QLA_FUNCTION_FAILED
;
2824 /* Prepare pex-dma descriptor to be written to MS memory. */
2825 /* dma-desc-cmd layout:
2826 * 0-3: dma-desc-cmd 0-3
2827 * 4-7: pcid function number
2828 * 8-15: dma-desc-cmd 8-15
2829 * dma_bus_addr: dma buffer address
2830 * cmd.read_data_size: amount of data-chunk to be read.
2832 dma_desc
.cmd
.dma_desc_cmd
= (m_hdr
->dma_desc_cmd
& 0xff0f);
2833 dma_desc
.cmd
.dma_desc_cmd
|=
2834 ((PCI_FUNC(ha
->pdev
->devfn
) & 0xf) << 0x4);
2836 dma_desc
.dma_bus_addr
= rdmem_dma
;
2837 dma_desc
.cmd
.read_data_size
= chunk_size
= ISP8044_PEX_DMA_READ_SIZE
;
2841 * Perform rdmem operation using pex-dma.
2842 * Prepare dma in chunks of ISP8044_PEX_DMA_READ_SIZE.
2844 while (read_size
< m_hdr
->read_data_size
) {
2845 if (m_hdr
->read_data_size
- read_size
<
2846 ISP8044_PEX_DMA_READ_SIZE
) {
2847 chunk_size
= (m_hdr
->read_data_size
- read_size
);
2848 dma_desc
.cmd
.read_data_size
= chunk_size
;
2851 dma_desc
.src_addr
= m_hdr
->read_addr
+ read_size
;
2853 /* Prepare: Write pex-dma descriptor to MS memory. */
2854 rval
= qla8044_ms_mem_write_128b(vha
,
2855 m_hdr
->desc_card_addr
, (void *)&dma_desc
,
2856 (sizeof(struct qla8044_pex_dma_descriptor
)/16));
2858 ql_log(ql_log_warn
, vha
, 0xb14a,
2859 "%s: Error writing rdmem-dma-init to MS !!!\n",
2863 ql_dbg(ql_dbg_p3p
, vha
, 0xb14b,
2864 "%s: Dma-descriptor: Instruct for rdmem dma "
2865 "(chunk_size 0x%x).\n", __func__
, chunk_size
);
2867 /* Execute: Start pex-dma operation. */
2868 rval
= qla8044_start_pex_dma(vha
, m_hdr
);
2872 memcpy(data_ptr
, rdmem_buffer
, chunk_size
);
2873 data_ptr
+= chunk_size
;
2874 read_size
+= chunk_size
;
2877 *d_ptr
= (void *)data_ptr
;
2881 dma_free_coherent(&ha
->pdev
->dev
, ISP8044_PEX_DMA_READ_SIZE
,
2882 rdmem_buffer
, rdmem_dma
);
2889 * qla8044_collect_md_data - Retrieve firmware minidump data.
2890 * @ha: pointer to adapter structure
2893 qla8044_collect_md_data(struct scsi_qla_host
*vha
)
2895 int num_entry_hdr
= 0;
2896 struct qla8044_minidump_entry_hdr
*entry_hdr
;
2897 struct qla8044_minidump_template_hdr
*tmplt_hdr
;
2899 uint32_t data_collected
= 0, f_capture_mask
;
2900 int i
, rval
= QLA_FUNCTION_FAILED
;
2902 uint32_t timestamp
, idc_control
;
2903 struct qla_hw_data
*ha
= vha
->hw
;
2906 ql_log(ql_log_info
, vha
, 0xb101,
2907 "%s(%ld) No buffer to dump\n",
2908 __func__
, vha
->host_no
);
2912 if (ha
->fw_dumped
) {
2913 ql_log(ql_log_warn
, vha
, 0xb10d,
2914 "Firmware has been previously dumped (%p) "
2915 "-- ignoring request.\n", ha
->fw_dump
);
2921 if (!ha
->md_tmplt_hdr
|| !ha
->md_dump
) {
2922 ql_log(ql_log_warn
, vha
, 0xb10e,
2923 "Memory not allocated for minidump capture\n");
2927 qla8044_idc_lock(ha
);
2928 idc_control
= qla8044_rd_reg(ha
, QLA8044_IDC_DRV_CTRL
);
2929 if (idc_control
& GRACEFUL_RESET_BIT1
) {
2930 ql_log(ql_log_warn
, vha
, 0xb112,
2931 "Forced reset from application, "
2932 "ignore minidump capture\n");
2933 qla8044_wr_reg(ha
, QLA8044_IDC_DRV_CTRL
,
2934 (idc_control
& ~GRACEFUL_RESET_BIT1
));
2935 qla8044_idc_unlock(ha
);
2939 qla8044_idc_unlock(ha
);
2941 if (qla82xx_validate_template_chksum(vha
)) {
2942 ql_log(ql_log_info
, vha
, 0xb109,
2943 "Template checksum validation error\n");
2947 tmplt_hdr
= (struct qla8044_minidump_template_hdr
*)
2949 data_ptr
= (uint32_t *)((uint8_t *)ha
->md_dump
);
2950 num_entry_hdr
= tmplt_hdr
->num_of_entries
;
2952 ql_dbg(ql_dbg_p3p
, vha
, 0xb11a,
2953 "Capture Mask obtained: 0x%x\n", tmplt_hdr
->capture_debug_level
);
2955 f_capture_mask
= tmplt_hdr
->capture_debug_level
& 0xFF;
2957 /* Validate whether required debug level is set */
2958 if ((f_capture_mask
& 0x3) != 0x3) {
2959 ql_log(ql_log_warn
, vha
, 0xb10f,
2960 "Minimum required capture mask[0x%x] level not set\n",
2964 tmplt_hdr
->driver_capture_mask
= ql2xmdcapmask
;
2965 ql_log(ql_log_info
, vha
, 0xb102,
2966 "[%s]: starting data ptr: %p\n",
2967 __func__
, data_ptr
);
2968 ql_log(ql_log_info
, vha
, 0xb10b,
2969 "[%s]: no of entry headers in Template: 0x%x\n",
2970 __func__
, num_entry_hdr
);
2971 ql_log(ql_log_info
, vha
, 0xb10c,
2972 "[%s]: Total_data_size 0x%x, %d obtained\n",
2973 __func__
, ha
->md_dump_size
, ha
->md_dump_size
);
2975 /* Update current timestamp before taking dump */
2976 now
= get_jiffies_64();
2977 timestamp
= (u32
)(jiffies_to_msecs(now
) / 1000);
2978 tmplt_hdr
->driver_timestamp
= timestamp
;
2980 entry_hdr
= (struct qla8044_minidump_entry_hdr
*)
2981 (((uint8_t *)ha
->md_tmplt_hdr
) + tmplt_hdr
->first_entry_offset
);
2982 tmplt_hdr
->saved_state_array
[QLA8044_SS_OCM_WNDREG_INDEX
] =
2983 tmplt_hdr
->ocm_window_reg
[ha
->portnum
];
2985 /* Walk through the entry headers - validate/perform required action */
2986 for (i
= 0; i
< num_entry_hdr
; i
++) {
2987 if (data_collected
> ha
->md_dump_size
) {
2988 ql_log(ql_log_info
, vha
, 0xb103,
2989 "Data collected: [0x%x], "
2990 "Total Dump size: [0x%x]\n",
2991 data_collected
, ha
->md_dump_size
);
2995 if (!(entry_hdr
->d_ctrl
.entry_capture_mask
&
2997 entry_hdr
->d_ctrl
.driver_flags
|=
2998 QLA82XX_DBG_SKIPPED_FLAG
;
2999 goto skip_nxt_entry
;
3002 ql_dbg(ql_dbg_p3p
, vha
, 0xb104,
3003 "Data collected: [0x%x], Dump size left:[0x%x]\n",
3005 (ha
->md_dump_size
- data_collected
));
3007 /* Decode the entry type and take required action to capture
3010 switch (entry_hdr
->entry_type
) {
3012 qla8044_mark_entry_skipped(vha
, entry_hdr
, i
);
3015 rval
= qla8044_minidump_process_control(vha
,
3017 if (rval
!= QLA_SUCCESS
) {
3018 qla8044_mark_entry_skipped(vha
, entry_hdr
, i
);
3023 qla8044_minidump_process_rdcrb(vha
,
3024 entry_hdr
, &data_ptr
);
3027 rval
= qla8044_minidump_pex_dma_read(vha
,
3028 entry_hdr
, &data_ptr
);
3029 if (rval
!= QLA_SUCCESS
) {
3030 rval
= qla8044_minidump_process_rdmem(vha
,
3031 entry_hdr
, &data_ptr
);
3032 if (rval
!= QLA_SUCCESS
) {
3033 qla8044_mark_entry_skipped(vha
,
3041 rval
= qla8044_minidump_process_rdrom(vha
,
3042 entry_hdr
, &data_ptr
);
3043 if (rval
!= QLA_SUCCESS
) {
3044 qla8044_mark_entry_skipped(vha
,
3052 rval
= qla8044_minidump_process_l2tag(vha
,
3053 entry_hdr
, &data_ptr
);
3054 if (rval
!= QLA_SUCCESS
) {
3055 qla8044_mark_entry_skipped(vha
, entry_hdr
, i
);
3063 qla8044_minidump_process_l1cache(vha
,
3064 entry_hdr
, &data_ptr
);
3067 qla8044_minidump_process_rdocm(vha
,
3068 entry_hdr
, &data_ptr
);
3071 qla8044_minidump_process_rdmux(vha
,
3072 entry_hdr
, &data_ptr
);
3075 qla8044_minidump_process_queue(vha
,
3076 entry_hdr
, &data_ptr
);
3078 case QLA8044_POLLRD
:
3079 rval
= qla8044_minidump_process_pollrd(vha
,
3080 entry_hdr
, &data_ptr
);
3081 if (rval
!= QLA_SUCCESS
)
3082 qla8044_mark_entry_skipped(vha
, entry_hdr
, i
);
3084 case QLA8044_RDMUX2
:
3085 qla8044_minidump_process_rdmux2(vha
,
3086 entry_hdr
, &data_ptr
);
3088 case QLA8044_POLLRDMWR
:
3089 rval
= qla8044_minidump_process_pollrdmwr(vha
,
3090 entry_hdr
, &data_ptr
);
3091 if (rval
!= QLA_SUCCESS
)
3092 qla8044_mark_entry_skipped(vha
, entry_hdr
, i
);
3096 qla8044_mark_entry_skipped(vha
, entry_hdr
, i
);
3100 data_collected
= (uint8_t *)data_ptr
-
3101 (uint8_t *)((uint8_t *)ha
->md_dump
);
3104 * next entry in the template
3106 entry_hdr
= (struct qla8044_minidump_entry_hdr
*)
3107 (((uint8_t *)entry_hdr
) + entry_hdr
->entry_size
);
3110 if (data_collected
!= ha
->md_dump_size
) {
3111 ql_log(ql_log_info
, vha
, 0xb105,
3112 "Dump data mismatch: Data collected: "
3113 "[0x%x], total_data_size:[0x%x]\n",
3114 data_collected
, ha
->md_dump_size
);
3118 ql_log(ql_log_info
, vha
, 0xb110,
3119 "Firmware dump saved to temp buffer (%ld/%p %ld/%p).\n",
3120 vha
->host_no
, ha
->md_tmplt_hdr
, vha
->host_no
, ha
->md_dump
);
3122 qla2x00_post_uevent_work(vha
, QLA_UEVENT_CODE_FW_DUMP
);
3125 ql_log(ql_log_info
, vha
, 0xb106,
3126 "Leaving fn: %s Last entry: 0x%x\n",
3133 qla8044_get_minidump(struct scsi_qla_host
*vha
)
3135 struct qla_hw_data
*ha
= vha
->hw
;
3137 if (!qla8044_collect_md_data(vha
)) {
3140 ql_log(ql_log_fatal
, vha
, 0xb0db,
3141 "%s: Unable to collect minidump\n",
3147 qla8044_poll_flash_status_reg(struct scsi_qla_host
*vha
)
3149 uint32_t flash_status
;
3150 int retries
= QLA8044_FLASH_READ_RETRY_COUNT
;
3151 int ret_val
= QLA_SUCCESS
;
3154 ret_val
= qla8044_rd_reg_indirect(vha
, QLA8044_FLASH_STATUS
,
3157 ql_log(ql_log_warn
, vha
, 0xb13c,
3158 "%s: Failed to read FLASH_STATUS reg.\n",
3162 if ((flash_status
& QLA8044_FLASH_STATUS_READY
) ==
3163 QLA8044_FLASH_STATUS_READY
)
3165 msleep(QLA8044_FLASH_STATUS_REG_POLL_DELAY
);
3169 ret_val
= QLA_FUNCTION_FAILED
;
3175 qla8044_write_flash_status_reg(struct scsi_qla_host
*vha
,
3178 int ret_val
= QLA_SUCCESS
;
3181 cmd
= vha
->hw
->fdt_wrt_sts_reg_cmd
;
3183 ret_val
= qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_ADDR
,
3184 QLA8044_FLASH_STATUS_WRITE_DEF_SIG
| cmd
);
3186 ql_log(ql_log_warn
, vha
, 0xb125,
3187 "%s: Failed to write to FLASH_ADDR.\n", __func__
);
3191 ret_val
= qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_WRDATA
, data
);
3193 ql_log(ql_log_warn
, vha
, 0xb126,
3194 "%s: Failed to write to FLASH_WRDATA.\n", __func__
);
3198 ret_val
= qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_CONTROL
,
3199 QLA8044_FLASH_SECOND_ERASE_MS_VAL
);
3201 ql_log(ql_log_warn
, vha
, 0xb127,
3202 "%s: Failed to write to FLASH_CONTROL.\n", __func__
);
3206 ret_val
= qla8044_poll_flash_status_reg(vha
);
3208 ql_log(ql_log_warn
, vha
, 0xb128,
3209 "%s: Error polling flash status reg.\n", __func__
);
3216 * This function assumes that the flash lock is held.
3219 qla8044_unprotect_flash(scsi_qla_host_t
*vha
)
3222 struct qla_hw_data
*ha
= vha
->hw
;
3224 ret_val
= qla8044_write_flash_status_reg(vha
, ha
->fdt_wrt_enable
);
3226 ql_log(ql_log_warn
, vha
, 0xb139,
3227 "%s: Write flash status failed.\n", __func__
);
3233 * This function assumes that the flash lock is held.
3236 qla8044_protect_flash(scsi_qla_host_t
*vha
)
3239 struct qla_hw_data
*ha
= vha
->hw
;
3241 ret_val
= qla8044_write_flash_status_reg(vha
, ha
->fdt_wrt_disable
);
3243 ql_log(ql_log_warn
, vha
, 0xb13b,
3244 "%s: Write flash status failed.\n", __func__
);
3251 qla8044_erase_flash_sector(struct scsi_qla_host
*vha
,
3252 uint32_t sector_start_addr
)
3254 uint32_t reversed_addr
;
3255 int ret_val
= QLA_SUCCESS
;
3257 ret_val
= qla8044_poll_flash_status_reg(vha
);
3259 ql_log(ql_log_warn
, vha
, 0xb12e,
3260 "%s: Poll flash status after erase failed..\n", __func__
);
3263 reversed_addr
= (((sector_start_addr
& 0xFF) << 16) |
3264 (sector_start_addr
& 0xFF00) |
3265 ((sector_start_addr
& 0xFF0000) >> 16));
3267 ret_val
= qla8044_wr_reg_indirect(vha
,
3268 QLA8044_FLASH_WRDATA
, reversed_addr
);
3270 ql_log(ql_log_warn
, vha
, 0xb12f,
3271 "%s: Failed to write to FLASH_WRDATA.\n", __func__
);
3273 ret_val
= qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_ADDR
,
3274 QLA8044_FLASH_ERASE_SIG
| vha
->hw
->fdt_erase_cmd
);
3276 ql_log(ql_log_warn
, vha
, 0xb130,
3277 "%s: Failed to write to FLASH_ADDR.\n", __func__
);
3279 ret_val
= qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_CONTROL
,
3280 QLA8044_FLASH_LAST_ERASE_MS_VAL
);
3282 ql_log(ql_log_warn
, vha
, 0xb131,
3283 "%s: Failed write to FLASH_CONTROL.\n", __func__
);
3285 ret_val
= qla8044_poll_flash_status_reg(vha
);
3287 ql_log(ql_log_warn
, vha
, 0xb132,
3288 "%s: Poll flash status failed.\n", __func__
);
3296 * qla8044_flash_write_u32 - Write data to flash
3298 * @ha : Pointer to adapter structure
3299 * addr : Flash address to write to
3300 * p_data : Data to be written
3302 * Return Value - QLA_SUCCESS/QLA_FUNCTION_FAILED
3304 * NOTE: Lock should be held on entry
3307 qla8044_flash_write_u32(struct scsi_qla_host
*vha
, uint32_t addr
,
3310 int ret_val
= QLA_SUCCESS
;
3312 ret_val
= qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_ADDR
,
3313 0x00800000 | (addr
>> 2));
3315 ql_log(ql_log_warn
, vha
, 0xb134,
3316 "%s: Failed write to FLASH_ADDR.\n", __func__
);
3319 ret_val
= qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_WRDATA
, *p_data
);
3321 ql_log(ql_log_warn
, vha
, 0xb135,
3322 "%s: Failed write to FLASH_WRDATA.\n", __func__
);
3325 ret_val
= qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_CONTROL
, 0x3D);
3327 ql_log(ql_log_warn
, vha
, 0xb136,
3328 "%s: Failed write to FLASH_CONTROL.\n", __func__
);
3331 ret_val
= qla8044_poll_flash_status_reg(vha
);
3333 ql_log(ql_log_warn
, vha
, 0xb137,
3334 "%s: Poll flash status failed.\n", __func__
);
3342 qla8044_write_flash_buffer_mode(scsi_qla_host_t
*vha
, uint32_t *dwptr
,
3343 uint32_t faddr
, uint32_t dwords
)
3345 int ret
= QLA_FUNCTION_FAILED
;
3348 if (dwords
< QLA8044_MIN_OPTROM_BURST_DWORDS
||
3349 dwords
> QLA8044_MAX_OPTROM_BURST_DWORDS
) {
3350 ql_dbg(ql_dbg_user
, vha
, 0xb123,
3351 "Got unsupported dwords = 0x%x.\n",
3353 return QLA_FUNCTION_FAILED
;
3356 qla8044_rd_reg_indirect(vha
, QLA8044_FLASH_SPI_CONTROL
, &spi_val
);
3357 qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_SPI_CONTROL
,
3358 spi_val
| QLA8044_FLASH_SPI_CTL
);
3359 qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_ADDR
,
3360 QLA8044_FLASH_FIRST_TEMP_VAL
);
3362 /* First DWORD write to FLASH_WRDATA */
3363 ret
= qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_WRDATA
,
3365 qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_CONTROL
,
3366 QLA8044_FLASH_FIRST_MS_PATTERN
);
3368 ret
= qla8044_poll_flash_status_reg(vha
);
3370 ql_log(ql_log_warn
, vha
, 0xb124,
3371 "%s: Failed.\n", __func__
);
3377 qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_ADDR
,
3378 QLA8044_FLASH_SECOND_TEMP_VAL
);
3381 /* Second to N-1 DWORDS writes */
3382 while (dwords
!= 1) {
3383 qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_WRDATA
, *dwptr
++);
3384 qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_CONTROL
,
3385 QLA8044_FLASH_SECOND_MS_PATTERN
);
3386 ret
= qla8044_poll_flash_status_reg(vha
);
3388 ql_log(ql_log_warn
, vha
, 0xb129,
3389 "%s: Failed.\n", __func__
);
3395 qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_ADDR
,
3396 QLA8044_FLASH_FIRST_TEMP_VAL
| (faddr
>> 2));
3398 /* Last DWORD write */
3399 qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_WRDATA
, *dwptr
++);
3400 qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_CONTROL
,
3401 QLA8044_FLASH_LAST_MS_PATTERN
);
3402 ret
= qla8044_poll_flash_status_reg(vha
);
3404 ql_log(ql_log_warn
, vha
, 0xb12a,
3405 "%s: Failed.\n", __func__
);
3408 qla8044_rd_reg_indirect(vha
, QLA8044_FLASH_SPI_STATUS
, &spi_val
);
3410 if ((spi_val
& QLA8044_FLASH_SPI_CTL
) == QLA8044_FLASH_SPI_CTL
) {
3411 ql_log(ql_log_warn
, vha
, 0xb12b,
3412 "%s: Failed.\n", __func__
);
3414 /* Operation failed, clear error bit. */
3415 qla8044_rd_reg_indirect(vha
, QLA8044_FLASH_SPI_CONTROL
,
3417 qla8044_wr_reg_indirect(vha
, QLA8044_FLASH_SPI_CONTROL
,
3418 spi_val
| QLA8044_FLASH_SPI_CTL
);
3425 qla8044_write_flash_dword_mode(scsi_qla_host_t
*vha
, uint32_t *dwptr
,
3426 uint32_t faddr
, uint32_t dwords
)
3428 int ret
= QLA_FUNCTION_FAILED
;
3431 for (liter
= 0; liter
< dwords
; liter
++, faddr
+= 4, dwptr
++) {
3432 ret
= qla8044_flash_write_u32(vha
, faddr
, dwptr
);
3434 ql_dbg(ql_dbg_p3p
, vha
, 0xb141,
3435 "%s: flash address=%x data=%x.\n", __func__
,
3445 qla8044_write_optrom_data(struct scsi_qla_host
*vha
, uint8_t *buf
,
3446 uint32_t offset
, uint32_t length
)
3448 int rval
= QLA_FUNCTION_FAILED
, i
, burst_iter_count
;
3449 int dword_count
, erase_sec_count
;
3450 uint32_t erase_offset
;
3451 uint8_t *p_cache
, *p_src
;
3453 erase_offset
= offset
;
3455 p_cache
= kcalloc(length
, sizeof(uint8_t), GFP_KERNEL
);
3457 return QLA_FUNCTION_FAILED
;
3459 memcpy(p_cache
, buf
, length
);
3461 dword_count
= length
/ sizeof(uint32_t);
3462 /* Since the offset and legth are sector aligned, it will be always
3463 * multiple of burst_iter_count (64)
3465 burst_iter_count
= dword_count
/ QLA8044_MAX_OPTROM_BURST_DWORDS
;
3466 erase_sec_count
= length
/ QLA8044_SECTOR_SIZE
;
3469 scsi_block_requests(vha
->host
);
3470 /* Lock and enable write for whole operation. */
3471 qla8044_flash_lock(vha
);
3472 qla8044_unprotect_flash(vha
);
3474 /* Erasing the sectors */
3475 for (i
= 0; i
< erase_sec_count
; i
++) {
3476 rval
= qla8044_erase_flash_sector(vha
, erase_offset
);
3477 ql_dbg(ql_dbg_user
, vha
, 0xb138,
3478 "Done erase of sector=0x%x.\n",
3481 ql_log(ql_log_warn
, vha
, 0xb121,
3482 "Failed to erase the sector having address: "
3483 "0x%x.\n", erase_offset
);
3486 erase_offset
+= QLA8044_SECTOR_SIZE
;
3488 ql_dbg(ql_dbg_user
, vha
, 0xb13f,
3489 "Got write for addr = 0x%x length=0x%x.\n",
3492 for (i
= 0; i
< burst_iter_count
; i
++) {
3494 /* Go with write. */
3495 rval
= qla8044_write_flash_buffer_mode(vha
, (uint32_t *)p_src
,
3496 offset
, QLA8044_MAX_OPTROM_BURST_DWORDS
);
3498 /* Buffer Mode failed skip to dword mode */
3499 ql_log(ql_log_warn
, vha
, 0xb122,
3500 "Failed to write flash in buffer mode, "
3501 "Reverting to slow-write.\n");
3502 rval
= qla8044_write_flash_dword_mode(vha
,
3503 (uint32_t *)p_src
, offset
,
3504 QLA8044_MAX_OPTROM_BURST_DWORDS
);
3506 p_src
+= sizeof(uint32_t) * QLA8044_MAX_OPTROM_BURST_DWORDS
;
3507 offset
+= sizeof(uint32_t) * QLA8044_MAX_OPTROM_BURST_DWORDS
;
3509 ql_dbg(ql_dbg_user
, vha
, 0xb133,
3513 qla8044_protect_flash(vha
);
3514 qla8044_flash_unlock(vha
);
3515 scsi_unblock_requests(vha
->host
);
3521 #define LEG_INT_PTR_B31 (1 << 31)
3522 #define LEG_INT_PTR_B30 (1 << 30)
3523 #define PF_BITS_MASK (0xF << 16)
3525 * qla8044_intr_handler() - Process interrupts for the ISP8044
3527 * @dev_id: SCSI driver HA context
3529 * Called by system whenever the host adapter generates an interrupt.
3531 * Returns handled flag.
3534 qla8044_intr_handler(int irq
, void *dev_id
)
3536 scsi_qla_host_t
*vha
;
3537 struct qla_hw_data
*ha
;
3538 struct rsp_que
*rsp
;
3539 struct device_reg_82xx __iomem
*reg
;
3541 unsigned long flags
;
3545 uint32_t leg_int_ptr
= 0, pf_bit
;
3547 rsp
= (struct rsp_que
*) dev_id
;
3549 ql_log(ql_log_info
, NULL
, 0xb143,
3550 "%s(): NULL response queue pointer\n", __func__
);
3554 vha
= pci_get_drvdata(ha
->pdev
);
3556 if (unlikely(pci_channel_offline(ha
->pdev
)))
3559 leg_int_ptr
= qla8044_rd_reg(ha
, LEG_INTR_PTR_OFFSET
);
3561 /* Legacy interrupt is valid if bit31 of leg_int_ptr is set */
3562 if (!(leg_int_ptr
& (LEG_INT_PTR_B31
))) {
3563 ql_dbg(ql_dbg_p3p
, vha
, 0xb144,
3564 "%s: Legacy Interrupt Bit 31 not set, "
3565 "spurious interrupt!\n", __func__
);
3569 pf_bit
= ha
->portnum
<< 16;
3570 /* Validate the PCIE function ID set in leg_int_ptr bits [19..16] */
3571 if ((leg_int_ptr
& (PF_BITS_MASK
)) != pf_bit
) {
3572 ql_dbg(ql_dbg_p3p
, vha
, 0xb145,
3573 "%s: Incorrect function ID 0x%x in "
3574 "legacy interrupt register, "
3575 "ha->pf_bit = 0x%x\n", __func__
,
3576 (leg_int_ptr
& (PF_BITS_MASK
)), pf_bit
);
3580 /* To de-assert legacy interrupt, write 0 to Legacy Interrupt Trigger
3581 * Control register and poll till Legacy Interrupt Pointer register
3584 qla8044_wr_reg(ha
, LEG_INTR_TRIG_OFFSET
, 0);
3586 leg_int_ptr
= qla8044_rd_reg(ha
, LEG_INTR_PTR_OFFSET
);
3587 if ((leg_int_ptr
& (PF_BITS_MASK
)) != pf_bit
)
3589 } while (leg_int_ptr
& (LEG_INT_PTR_B30
));
3591 reg
= &ha
->iobase
->isp82
;
3592 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3593 for (iter
= 1; iter
--; ) {
3595 if (RD_REG_DWORD(®
->host_int
)) {
3596 stat
= RD_REG_DWORD(®
->host_status
);
3597 if ((stat
& HSRX_RISC_INT
) == 0)
3600 switch (stat
& 0xff) {
3605 qla82xx_mbx_completion(vha
, MSW(stat
));
3606 status
|= MBX_INTERRUPT
;
3610 mb
[1] = RD_REG_WORD(®
->mailbox_out
[1]);
3611 mb
[2] = RD_REG_WORD(®
->mailbox_out
[2]);
3612 mb
[3] = RD_REG_WORD(®
->mailbox_out
[3]);
3613 qla2x00_async_event(vha
, rsp
, mb
);
3616 qla24xx_process_response_queue(vha
, rsp
);
3619 ql_dbg(ql_dbg_p3p
, vha
, 0xb146,
3620 "Unrecognized interrupt type "
3621 "(%d).\n", stat
& 0xff);
3625 WRT_REG_DWORD(®
->host_int
, 0);
3628 qla2x00_handle_mbx_completion(ha
, status
);
3629 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3635 qla8044_idc_dontreset(struct qla_hw_data
*ha
)
3639 idc_ctrl
= qla8044_rd_reg(ha
, QLA8044_IDC_DRV_CTRL
);
3640 return idc_ctrl
& DONTRESET_BIT0
;
3644 qla8044_clear_rst_ready(scsi_qla_host_t
*vha
)
3648 drv_state
= qla8044_rd_direct(vha
, QLA8044_CRB_DRV_STATE_INDEX
);
3651 * For ISP8044, drv_active register has 1 bit per function,
3652 * shift 1 by func_num to set a bit for the function.
3653 * For ISP82xx, drv_active has 4 bits per function
3655 drv_state
&= ~(1 << vha
->hw
->portnum
);
3657 ql_dbg(ql_dbg_p3p
, vha
, 0xb13d,
3658 "drv_state: 0x%08x\n", drv_state
);
3659 qla8044_wr_direct(vha
, QLA8044_CRB_DRV_STATE_INDEX
, drv_state
);
3663 qla8044_abort_isp(scsi_qla_host_t
*vha
)
3667 struct qla_hw_data
*ha
= vha
->hw
;
3669 qla8044_idc_lock(ha
);
3670 dev_state
= qla8044_rd_direct(vha
, QLA8044_CRB_DEV_STATE_INDEX
);
3672 if (ql2xdontresethba
)
3673 qla8044_set_idc_dontreset(vha
);
3675 /* If device_state is NEED_RESET, go ahead with
3676 * Reset,irrespective of ql2xdontresethba. This is to allow a
3677 * non-reset-owner to force a reset. Non-reset-owner sets
3678 * the IDC_CTRL BIT0 to prevent Reset-owner from doing a Reset
3679 * and then forces a Reset by setting device_state to
3681 if (dev_state
== QLA8XXX_DEV_READY
) {
3682 /* If IDC_CTRL DONTRESETHBA_BIT0 is set don't do reset
3684 if (qla8044_idc_dontreset(ha
) == DONTRESET_BIT0
) {
3685 ql_dbg(ql_dbg_p3p
, vha
, 0xb13e,
3686 "Reset recovery disabled\n");
3687 rval
= QLA_FUNCTION_FAILED
;
3688 goto exit_isp_reset
;
3691 ql_dbg(ql_dbg_p3p
, vha
, 0xb140,
3692 "HW State: NEED RESET\n");
3693 qla8044_wr_direct(vha
, QLA8044_CRB_DEV_STATE_INDEX
,
3694 QLA8XXX_DEV_NEED_RESET
);
3697 /* For ISP8044, Reset owner is NIC, iSCSI or FCOE based on priority
3698 * and which drivers are present. Unlike ISP82XX, the function setting
3699 * NEED_RESET, may not be the Reset owner. */
3700 qla83xx_reset_ownership(vha
);
3702 qla8044_idc_unlock(ha
);
3703 rval
= qla8044_device_state_handler(vha
);
3704 qla8044_idc_lock(ha
);
3705 qla8044_clear_rst_ready(vha
);
3708 qla8044_idc_unlock(ha
);
3709 if (rval
== QLA_SUCCESS
) {
3710 ha
->flags
.isp82xx_fw_hung
= 0;
3711 ha
->flags
.nic_core_reset_hdlr_active
= 0;
3712 rval
= qla82xx_restart_isp(vha
);