2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2013 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
8 #include <linux/ratelimit.h>
11 #include "ql4_version.h"
14 #include "ql4_inline.h"
16 uint32_t qla4_83xx_rd_reg(struct scsi_qla_host
*ha
, ulong addr
)
18 return readl((void __iomem
*)(ha
->nx_pcibase
+ addr
));
21 void qla4_83xx_wr_reg(struct scsi_qla_host
*ha
, ulong addr
, uint32_t val
)
23 writel(val
, (void __iomem
*)(ha
->nx_pcibase
+ addr
));
26 static int qla4_83xx_set_win_base(struct scsi_qla_host
*ha
, uint32_t addr
)
29 int ret_val
= QLA_SUCCESS
;
31 qla4_83xx_wr_reg(ha
, QLA83XX_CRB_WIN_FUNC(ha
->func_num
), addr
);
32 val
= qla4_83xx_rd_reg(ha
, QLA83XX_CRB_WIN_FUNC(ha
->func_num
));
34 ql4_printk(KERN_ERR
, ha
, "%s: Failed to set register window : addr written 0x%x, read 0x%x!\n",
42 int qla4_83xx_rd_reg_indirect(struct scsi_qla_host
*ha
, uint32_t addr
,
47 ret_val
= qla4_83xx_set_win_base(ha
, addr
);
49 if (ret_val
== QLA_SUCCESS
)
50 *data
= qla4_83xx_rd_reg(ha
, QLA83XX_WILDCARD
);
52 ql4_printk(KERN_ERR
, ha
, "%s: failed read of addr 0x%x!\n",
58 int qla4_83xx_wr_reg_indirect(struct scsi_qla_host
*ha
, uint32_t addr
,
63 ret_val
= qla4_83xx_set_win_base(ha
, addr
);
65 if (ret_val
== QLA_SUCCESS
)
66 qla4_83xx_wr_reg(ha
, QLA83XX_WILDCARD
, data
);
68 ql4_printk(KERN_ERR
, ha
, "%s: failed wrt to addr 0x%x, data 0x%x\n",
69 __func__
, addr
, data
);
74 static int qla4_83xx_flash_lock(struct scsi_qla_host
*ha
)
78 uint32_t lock_status
= 0;
79 int ret_val
= QLA_SUCCESS
;
81 while (lock_status
== 0) {
82 lock_status
= qla4_83xx_rd_reg(ha
, QLA83XX_FLASH_LOCK
);
86 if (++timeout
>= QLA83XX_FLASH_LOCK_TIMEOUT
/ 20) {
87 lock_owner
= qla4_83xx_rd_reg(ha
,
88 QLA83XX_FLASH_LOCK_ID
);
89 ql4_printk(KERN_ERR
, ha
, "%s: flash lock by func %d failed, held by func %d\n",
90 __func__
, ha
->func_num
, lock_owner
);
97 qla4_83xx_wr_reg(ha
, QLA83XX_FLASH_LOCK_ID
, ha
->func_num
);
101 static void qla4_83xx_flash_unlock(struct scsi_qla_host
*ha
)
103 /* Reading FLASH_UNLOCK register unlocks the Flash */
104 qla4_83xx_wr_reg(ha
, QLA83XX_FLASH_LOCK_ID
, 0xFF);
105 qla4_83xx_rd_reg(ha
, QLA83XX_FLASH_UNLOCK
);
108 int qla4_83xx_flash_read_u32(struct scsi_qla_host
*ha
, uint32_t flash_addr
,
109 uint8_t *p_data
, int u32_word_count
)
113 uint32_t addr
= flash_addr
;
114 int ret_val
= QLA_SUCCESS
;
116 ret_val
= qla4_83xx_flash_lock(ha
);
117 if (ret_val
== QLA_ERROR
)
118 goto exit_lock_error
;
121 ql4_printk(KERN_ERR
, ha
, "%s: Illegal addr = 0x%x\n",
124 goto exit_flash_read
;
127 for (i
= 0; i
< u32_word_count
; i
++) {
128 ret_val
= qla4_83xx_wr_reg_indirect(ha
,
129 QLA83XX_FLASH_DIRECT_WINDOW
,
130 (addr
& 0xFFFF0000));
131 if (ret_val
== QLA_ERROR
) {
132 ql4_printk(KERN_ERR
, ha
, "%s: failed to write addr 0x%x to FLASH_DIRECT_WINDOW\n!",
134 goto exit_flash_read
;
137 ret_val
= qla4_83xx_rd_reg_indirect(ha
,
138 QLA83XX_FLASH_DIRECT_DATA(addr
),
140 if (ret_val
== QLA_ERROR
) {
141 ql4_printk(KERN_ERR
, ha
, "%s: failed to read addr 0x%x!\n",
143 goto exit_flash_read
;
146 *(__le32
*)p_data
= le32_to_cpu(u32_word
);
152 qla4_83xx_flash_unlock(ha
);
158 int qla4_83xx_lockless_flash_read_u32(struct scsi_qla_host
*ha
,
159 uint32_t flash_addr
, uint8_t *p_data
,
164 uint32_t flash_offset
;
165 uint32_t addr
= flash_addr
;
166 int ret_val
= QLA_SUCCESS
;
168 flash_offset
= addr
& (QLA83XX_FLASH_SECTOR_SIZE
- 1);
171 ql4_printk(KERN_ERR
, ha
, "%s: Illegal addr = 0x%x\n",
174 goto exit_lockless_read
;
177 ret_val
= qla4_83xx_wr_reg_indirect(ha
, QLA83XX_FLASH_DIRECT_WINDOW
,
179 if (ret_val
== QLA_ERROR
) {
180 ql4_printk(KERN_ERR
, ha
, "%s: failed to write addr 0x%x to FLASH_DIRECT_WINDOW!\n",
182 goto exit_lockless_read
;
185 /* Check if data is spread across multiple sectors */
186 if ((flash_offset
+ (u32_word_count
* sizeof(uint32_t))) >
187 (QLA83XX_FLASH_SECTOR_SIZE
- 1)) {
189 /* Multi sector read */
190 for (i
= 0; i
< u32_word_count
; i
++) {
191 ret_val
= qla4_83xx_rd_reg_indirect(ha
,
192 QLA83XX_FLASH_DIRECT_DATA(addr
),
194 if (ret_val
== QLA_ERROR
) {
195 ql4_printk(KERN_ERR
, ha
, "%s: failed to read addr 0x%x!\n",
197 goto exit_lockless_read
;
200 *(__le32
*)p_data
= le32_to_cpu(u32_word
);
203 flash_offset
= flash_offset
+ 4;
205 if (flash_offset
> (QLA83XX_FLASH_SECTOR_SIZE
- 1)) {
206 /* This write is needed once for each sector */
207 ret_val
= qla4_83xx_wr_reg_indirect(ha
,
208 QLA83XX_FLASH_DIRECT_WINDOW
,
210 if (ret_val
== QLA_ERROR
) {
211 ql4_printk(KERN_ERR
, ha
, "%s: failed to write addr 0x%x to FLASH_DIRECT_WINDOW!\n",
213 goto exit_lockless_read
;
219 /* Single sector read */
220 for (i
= 0; i
< u32_word_count
; i
++) {
221 ret_val
= qla4_83xx_rd_reg_indirect(ha
,
222 QLA83XX_FLASH_DIRECT_DATA(addr
),
224 if (ret_val
== QLA_ERROR
) {
225 ql4_printk(KERN_ERR
, ha
, "%s: failed to read addr 0x%x!\n",
227 goto exit_lockless_read
;
230 *(__le32
*)p_data
= le32_to_cpu(u32_word
);
240 void qla4_83xx_rom_lock_recovery(struct scsi_qla_host
*ha
)
242 if (qla4_83xx_flash_lock(ha
))
243 ql4_printk(KERN_INFO
, ha
, "%s: Resetting rom lock\n", __func__
);
246 * We got the lock, or someone else is holding the lock
247 * since we are restting, forcefully unlock
249 qla4_83xx_flash_unlock(ha
);
252 #define INTENT_TO_RECOVER 0x01
253 #define PROCEED_TO_RECOVER 0x02
255 static int qla4_83xx_lock_recovery(struct scsi_qla_host
*ha
)
258 uint32_t lock
= 0, lockid
;
259 int ret_val
= QLA_ERROR
;
261 lockid
= ha
->isp_ops
->rd_reg_direct(ha
, QLA83XX_DRV_LOCKRECOVERY
);
263 /* Check for other Recovery in progress, go wait */
264 if ((lockid
& 0x3) != 0)
265 goto exit_lock_recovery
;
267 /* Intent to Recover */
268 ha
->isp_ops
->wr_reg_direct(ha
, QLA83XX_DRV_LOCKRECOVERY
,
269 (ha
->func_num
<< 2) | INTENT_TO_RECOVER
);
273 /* Check Intent to Recover is advertised */
274 lockid
= ha
->isp_ops
->rd_reg_direct(ha
, QLA83XX_DRV_LOCKRECOVERY
);
275 if ((lockid
& 0x3C) != (ha
->func_num
<< 2))
276 goto exit_lock_recovery
;
278 ql4_printk(KERN_INFO
, ha
, "%s: IDC Lock recovery initiated for func %d\n",
279 __func__
, ha
->func_num
);
281 /* Proceed to Recover */
282 ha
->isp_ops
->wr_reg_direct(ha
, QLA83XX_DRV_LOCKRECOVERY
,
283 (ha
->func_num
<< 2) | PROCEED_TO_RECOVER
);
286 ha
->isp_ops
->wr_reg_direct(ha
, QLA83XX_DRV_LOCK_ID
, 0xFF);
287 ha
->isp_ops
->rd_reg_direct(ha
, QLA83XX_DRV_UNLOCK
);
289 /* Clear bits 0-5 in IDC_RECOVERY register*/
290 ha
->isp_ops
->wr_reg_direct(ha
, QLA83XX_DRV_LOCKRECOVERY
, 0);
293 lock
= ha
->isp_ops
->rd_reg_direct(ha
, QLA83XX_DRV_LOCK
);
295 lockid
= ha
->isp_ops
->rd_reg_direct(ha
, QLA83XX_DRV_LOCK_ID
);
296 lockid
= ((lockid
+ (1 << 8)) & ~0xFF) | ha
->func_num
;
297 ha
->isp_ops
->wr_reg_direct(ha
, QLA83XX_DRV_LOCK_ID
, lockid
);
298 ret_val
= QLA_SUCCESS
;
305 #define QLA83XX_DRV_LOCK_MSLEEP 200
307 int qla4_83xx_drv_lock(struct scsi_qla_host
*ha
)
311 int ret_val
= QLA_SUCCESS
;
312 uint32_t first_owner
= 0;
313 uint32_t tmo_owner
= 0;
318 while (status
== 0) {
319 status
= qla4_83xx_rd_reg(ha
, QLA83XX_DRV_LOCK
);
321 /* Increment Counter (8-31) and update func_num (0-7) on
322 * getting a successful lock */
323 lock_id
= qla4_83xx_rd_reg(ha
, QLA83XX_DRV_LOCK_ID
);
324 lock_id
= ((lock_id
+ (1 << 8)) & ~0xFF) | ha
->func_num
;
325 qla4_83xx_wr_reg(ha
, QLA83XX_DRV_LOCK_ID
, lock_id
);
330 /* Save counter + ID of function holding the lock for
332 first_owner
= ha
->isp_ops
->rd_reg_direct(ha
,
333 QLA83XX_DRV_LOCK_ID
);
336 (QLA83XX_DRV_LOCK_TIMEOUT
/ QLA83XX_DRV_LOCK_MSLEEP
)) {
337 tmo_owner
= qla4_83xx_rd_reg(ha
, QLA83XX_DRV_LOCK_ID
);
338 func_num
= tmo_owner
& 0xFF;
339 lock_cnt
= tmo_owner
>> 8;
340 ql4_printk(KERN_INFO
, ha
, "%s: Lock by func %d failed after 2s, lock held by func %d, lock count %d, first_owner %d\n",
341 __func__
, ha
->func_num
, func_num
, lock_cnt
,
342 (first_owner
& 0xFF));
344 if (first_owner
!= tmo_owner
) {
345 /* Some other driver got lock, OR same driver
346 * got lock again (counter value changed), when
347 * we were waiting for lock.
348 * Retry for another 2 sec */
349 ql4_printk(KERN_INFO
, ha
, "%s: IDC lock failed for func %d\n",
350 __func__
, ha
->func_num
);
353 /* Same driver holding lock > 2sec.
355 ret_val
= qla4_83xx_lock_recovery(ha
);
356 if (ret_val
== QLA_SUCCESS
) {
357 /* Recovered and got lock */
358 ql4_printk(KERN_INFO
, ha
, "%s: IDC lock Recovery by %d successful\n",
359 __func__
, ha
->func_num
);
362 /* Recovery Failed, some other function
363 * has the lock, wait for 2secs and retry */
364 ql4_printk(KERN_INFO
, ha
, "%s: IDC lock Recovery by %d failed, Retrying timeout\n",
365 __func__
, ha
->func_num
);
369 msleep(QLA83XX_DRV_LOCK_MSLEEP
);
375 void qla4_83xx_drv_unlock(struct scsi_qla_host
*ha
)
379 id
= qla4_83xx_rd_reg(ha
, QLA83XX_DRV_LOCK_ID
);
381 if ((id
& 0xFF) != ha
->func_num
) {
382 ql4_printk(KERN_ERR
, ha
, "%s: IDC Unlock by %d failed, lock owner is %d\n",
383 __func__
, ha
->func_num
, (id
& 0xFF));
387 /* Keep lock counter value, update the ha->func_num to 0xFF */
388 qla4_83xx_wr_reg(ha
, QLA83XX_DRV_LOCK_ID
, (id
| 0xFF));
389 qla4_83xx_rd_reg(ha
, QLA83XX_DRV_UNLOCK
);
392 void qla4_83xx_set_idc_dontreset(struct scsi_qla_host
*ha
)
396 idc_ctrl
= qla4_83xx_rd_reg(ha
, QLA83XX_IDC_DRV_CTRL
);
397 idc_ctrl
|= DONTRESET_BIT0
;
398 qla4_83xx_wr_reg(ha
, QLA83XX_IDC_DRV_CTRL
, idc_ctrl
);
399 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: idc_ctrl = %d\n", __func__
,
403 void qla4_83xx_clear_idc_dontreset(struct scsi_qla_host
*ha
)
407 idc_ctrl
= qla4_83xx_rd_reg(ha
, QLA83XX_IDC_DRV_CTRL
);
408 idc_ctrl
&= ~DONTRESET_BIT0
;
409 qla4_83xx_wr_reg(ha
, QLA83XX_IDC_DRV_CTRL
, idc_ctrl
);
410 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: idc_ctrl = %d\n", __func__
,
414 int qla4_83xx_idc_dontreset(struct scsi_qla_host
*ha
)
418 idc_ctrl
= qla4_83xx_rd_reg(ha
, QLA83XX_IDC_DRV_CTRL
);
419 return idc_ctrl
& DONTRESET_BIT0
;
422 /*-------------------------IDC State Machine ---------------------*/
437 int qla4_83xx_can_perform_reset(struct scsi_qla_host
*ha
)
440 uint32_t dev_part
, dev_part1
, dev_part2
;
442 struct device_info device_map
[16];
446 int iscsi_present
= 0;
447 int iscsi_func_low
= 0;
449 /* Use the dev_partition register to determine the PCI function number
450 * and then check drv_active register to see which driver is loaded */
451 dev_part1
= qla4_83xx_rd_reg(ha
,
452 ha
->reg_tbl
[QLA8XXX_CRB_DEV_PART_INFO
]);
453 dev_part2
= qla4_83xx_rd_reg(ha
, QLA83XX_CRB_DEV_PART_INFO2
);
454 drv_active
= qla4_83xx_rd_reg(ha
, ha
->reg_tbl
[QLA8XXX_CRB_DRV_ACTIVE
]);
456 /* Each function has 4 bits in dev_partition Info register,
457 * Lower 2 bits - device type, Upper 2 bits - physical port number */
458 dev_part
= dev_part1
;
459 for (i
= nibble
= 0; i
<= 15; i
++, nibble
++) {
460 func_nibble
= dev_part
& (0xF << (nibble
* 4));
461 func_nibble
>>= (nibble
* 4);
462 device_map
[i
].func_num
= i
;
463 device_map
[i
].device_type
= func_nibble
& 0x3;
464 device_map
[i
].port_num
= func_nibble
& 0xC;
466 if (device_map
[i
].device_type
== NIC_CLASS
) {
467 if (drv_active
& (1 << device_map
[i
].func_num
)) {
471 } else if (device_map
[i
].device_type
== ISCSI_CLASS
) {
472 if (drv_active
& (1 << device_map
[i
].func_num
)) {
473 if (!iscsi_present
||
475 (iscsi_func_low
> device_map
[i
].func_num
)))
476 iscsi_func_low
= device_map
[i
].func_num
;
482 /* For function_num[8..15] get info from dev_part2 register */
485 dev_part
= dev_part2
;
489 /* NIC, iSCSI and FCOE are the Reset owners based on order, NIC gets
490 * precedence over iSCSI and FCOE and iSCSI over FCOE, based on drivers
492 if (!nic_present
&& (ha
->func_num
== iscsi_func_low
)) {
493 DEBUG2(ql4_printk(KERN_INFO
, ha
,
494 "%s: can reset - NIC not present and lower iSCSI function is %d\n",
495 __func__
, ha
->func_num
));
503 * qla4_83xx_need_reset_handler - Code to start reset sequence
504 * @ha: pointer to adapter structure
506 * Note: IDC lock must be held upon entry
508 void qla4_83xx_need_reset_handler(struct scsi_qla_host
*ha
)
510 uint32_t dev_state
, drv_state
, drv_active
;
511 unsigned long reset_timeout
, dev_init_timeout
;
513 ql4_printk(KERN_INFO
, ha
, "%s: Performing ISP error recovery\n",
516 if (!test_bit(AF_8XXX_RST_OWNER
, &ha
->flags
)) {
517 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: reset acknowledged\n",
519 qla4_8xxx_set_rst_ready(ha
);
521 /* Non-reset owners ACK Reset and wait for device INIT state
522 * as part of Reset Recovery by Reset Owner */
523 dev_init_timeout
= jiffies
+ (ha
->nx_dev_init_timeout
* HZ
);
526 if (time_after_eq(jiffies
, dev_init_timeout
)) {
527 ql4_printk(KERN_INFO
, ha
, "%s: Non Reset owner dev init timeout\n",
532 ha
->isp_ops
->idc_unlock(ha
);
534 ha
->isp_ops
->idc_lock(ha
);
536 dev_state
= qla4_8xxx_rd_direct(ha
,
537 QLA8XXX_CRB_DEV_STATE
);
538 } while (dev_state
== QLA8XXX_DEV_NEED_RESET
);
540 qla4_8xxx_set_rst_ready(ha
);
541 reset_timeout
= jiffies
+ (ha
->nx_reset_timeout
* HZ
);
542 drv_state
= qla4_8xxx_rd_direct(ha
, QLA8XXX_CRB_DRV_STATE
);
543 drv_active
= qla4_8xxx_rd_direct(ha
, QLA8XXX_CRB_DRV_ACTIVE
);
545 ql4_printk(KERN_INFO
, ha
, "%s: drv_state = 0x%x, drv_active = 0x%x\n",
546 __func__
, drv_state
, drv_active
);
548 while (drv_state
!= drv_active
) {
549 if (time_after_eq(jiffies
, reset_timeout
)) {
550 ql4_printk(KERN_INFO
, ha
, "%s: %s: RESET TIMEOUT! drv_state: 0x%08x, drv_active: 0x%08x\n",
551 __func__
, DRIVER_NAME
, drv_state
,
556 ha
->isp_ops
->idc_unlock(ha
);
558 ha
->isp_ops
->idc_lock(ha
);
560 drv_state
= qla4_8xxx_rd_direct(ha
,
561 QLA8XXX_CRB_DRV_STATE
);
562 drv_active
= qla4_8xxx_rd_direct(ha
,
563 QLA8XXX_CRB_DRV_ACTIVE
);
566 if (drv_state
!= drv_active
) {
567 ql4_printk(KERN_INFO
, ha
, "%s: Reset_owner turning off drv_active of non-acking function 0x%x\n",
568 __func__
, (drv_active
^ drv_state
));
569 drv_active
= drv_active
& drv_state
;
570 qla4_8xxx_wr_direct(ha
, QLA8XXX_CRB_DRV_ACTIVE
,
574 clear_bit(AF_8XXX_RST_OWNER
, &ha
->flags
);
575 /* Start Reset Recovery */
576 qla4_8xxx_device_bootstrap(ha
);
580 void qla4_83xx_get_idc_param(struct scsi_qla_host
*ha
)
582 uint32_t idc_params
, ret_val
;
584 ret_val
= qla4_83xx_flash_read_u32(ha
, QLA83XX_IDC_PARAM_ADDR
,
585 (uint8_t *)&idc_params
, 1);
586 if (ret_val
== QLA_SUCCESS
) {
587 ha
->nx_dev_init_timeout
= idc_params
& 0xFFFF;
588 ha
->nx_reset_timeout
= (idc_params
>> 16) & 0xFFFF;
590 ha
->nx_dev_init_timeout
= ROM_DEV_INIT_TIMEOUT
;
591 ha
->nx_reset_timeout
= ROM_DRV_RESET_ACK_TIMEOUT
;
594 DEBUG2(ql4_printk(KERN_DEBUG
, ha
,
595 "%s: ha->nx_dev_init_timeout = %d, ha->nx_reset_timeout = %d\n",
596 __func__
, ha
->nx_dev_init_timeout
,
597 ha
->nx_reset_timeout
));
600 /*-------------------------Reset Sequence Functions-----------------------*/
602 static void qla4_83xx_dump_reset_seq_hdr(struct scsi_qla_host
*ha
)
606 if (!ha
->reset_tmplt
.buff
) {
607 ql4_printk(KERN_ERR
, ha
, "%s: Error: Invalid reset_seq_template\n",
612 phdr
= ha
->reset_tmplt
.buff
;
614 DEBUG2(ql4_printk(KERN_INFO
, ha
,
615 "Reset Template: 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n",
616 *phdr
, *(phdr
+1), *(phdr
+2), *(phdr
+3), *(phdr
+4),
617 *(phdr
+5), *(phdr
+6), *(phdr
+7), *(phdr
+ 8),
618 *(phdr
+9), *(phdr
+10), *(phdr
+11), *(phdr
+12),
619 *(phdr
+13), *(phdr
+14), *(phdr
+15)));
622 static int qla4_83xx_copy_bootloader(struct scsi_qla_host
*ha
)
625 uint32_t src
, count
, size
;
627 int ret_val
= QLA_SUCCESS
;
629 src
= QLA83XX_BOOTLOADER_FLASH_ADDR
;
630 dest
= qla4_83xx_rd_reg(ha
, QLA83XX_BOOTLOADER_ADDR
);
631 size
= qla4_83xx_rd_reg(ha
, QLA83XX_BOOTLOADER_SIZE
);
633 /* 128 bit alignment check */
635 size
= (size
+ 16) & ~0xF;
640 p_cache
= vmalloc(size
);
641 if (p_cache
== NULL
) {
642 ql4_printk(KERN_ERR
, ha
, "%s: Failed to allocate memory for boot loader cache\n",
645 goto exit_copy_bootloader
;
648 ret_val
= qla4_83xx_lockless_flash_read_u32(ha
, src
, p_cache
,
649 size
/ sizeof(uint32_t));
650 if (ret_val
== QLA_ERROR
) {
651 ql4_printk(KERN_ERR
, ha
, "%s: Error reading firmware from flash\n",
653 goto exit_copy_error
;
655 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: Read firmware from flash\n",
658 /* 128 bit/16 byte write to MS memory */
659 ret_val
= qla4_8xxx_ms_mem_write_128b(ha
, dest
, (uint32_t *)p_cache
,
661 if (ret_val
== QLA_ERROR
) {
662 ql4_printk(KERN_ERR
, ha
, "%s: Error writing firmware to MS\n",
664 goto exit_copy_error
;
667 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: Wrote firmware size %d to MS\n",
673 exit_copy_bootloader
:
677 static int qla4_83xx_check_cmd_peg_status(struct scsi_qla_host
*ha
)
679 uint32_t val
, ret_val
= QLA_ERROR
;
680 int retries
= CRB_CMDPEG_CHECK_RETRY_COUNT
;
683 val
= qla4_83xx_rd_reg(ha
, QLA83XX_CMDPEG_STATE
);
684 if (val
== PHAN_INITIALIZE_COMPLETE
) {
685 DEBUG2(ql4_printk(KERN_INFO
, ha
,
686 "%s: Command Peg initialization complete. State=0x%x\n",
688 ret_val
= QLA_SUCCESS
;
691 msleep(CRB_CMDPEG_CHECK_DELAY
);
698 * qla4_83xx_poll_reg - Poll the given CRB addr for duration msecs till
699 * value read ANDed with test_mask is equal to test_result.
701 * @ha : Pointer to adapter structure
702 * @addr : CRB register address
703 * @duration : Poll for total of "duration" msecs
704 * @test_mask : Mask value read with "test_mask"
705 * @test_result : Compare (value&test_mask) with test_result.
707 static int qla4_83xx_poll_reg(struct scsi_qla_host
*ha
, uint32_t addr
,
708 int duration
, uint32_t test_mask
,
709 uint32_t test_result
)
713 int ret_val
= QLA_SUCCESS
;
715 ret_val
= qla4_83xx_rd_reg_indirect(ha
, addr
, &value
);
716 if (ret_val
== QLA_ERROR
)
719 retries
= duration
/ 10;
721 if ((value
& test_mask
) != test_result
) {
722 msleep(duration
/ 10);
723 ret_val
= qla4_83xx_rd_reg_indirect(ha
, addr
, &value
);
724 if (ret_val
== QLA_ERROR
)
729 ret_val
= QLA_SUCCESS
;
735 if (ret_val
== QLA_ERROR
) {
736 ha
->reset_tmplt
.seq_error
++;
737 ql4_printk(KERN_ERR
, ha
, "%s: Poll Failed: 0x%08x 0x%08x 0x%08x\n",
738 __func__
, value
, test_mask
, test_result
);
744 static int qla4_83xx_reset_seq_checksum_test(struct scsi_qla_host
*ha
)
747 uint16_t *buff
= (uint16_t *)ha
->reset_tmplt
.buff
;
748 int u16_count
= ha
->reset_tmplt
.hdr
->size
/ sizeof(uint16_t);
751 while (u16_count
-- > 0)
755 sum
= (sum
& 0xFFFF) + (sum
>> 16);
757 /* checksum of 0 indicates a valid template */
759 ret_val
= QLA_SUCCESS
;
761 ql4_printk(KERN_ERR
, ha
, "%s: Reset seq checksum failed\n",
770 * qla4_83xx_read_reset_template - Read Reset Template from Flash
771 * @ha: Pointer to adapter structure
773 void qla4_83xx_read_reset_template(struct scsi_qla_host
*ha
)
776 uint32_t addr
, tmplt_hdr_def_size
, tmplt_hdr_size
;
779 ha
->reset_tmplt
.seq_error
= 0;
780 ha
->reset_tmplt
.buff
= vmalloc(QLA83XX_RESTART_TEMPLATE_SIZE
);
781 if (ha
->reset_tmplt
.buff
== NULL
) {
782 ql4_printk(KERN_ERR
, ha
, "%s: Failed to allocate reset template resources\n",
784 goto exit_read_reset_template
;
787 p_buff
= ha
->reset_tmplt
.buff
;
788 addr
= QLA83XX_RESET_TEMPLATE_ADDR
;
790 tmplt_hdr_def_size
= sizeof(struct qla4_83xx_reset_template_hdr
) /
793 DEBUG2(ql4_printk(KERN_INFO
, ha
,
794 "%s: Read template hdr size %d from Flash\n",
795 __func__
, tmplt_hdr_def_size
));
797 /* Copy template header from flash */
798 ret_val
= qla4_83xx_flash_read_u32(ha
, addr
, p_buff
,
800 if (ret_val
!= QLA_SUCCESS
) {
801 ql4_printk(KERN_ERR
, ha
, "%s: Failed to read reset template\n",
803 goto exit_read_template_error
;
806 ha
->reset_tmplt
.hdr
=
807 (struct qla4_83xx_reset_template_hdr
*)ha
->reset_tmplt
.buff
;
809 /* Validate the template header size and signature */
810 tmplt_hdr_size
= ha
->reset_tmplt
.hdr
->hdr_size
/sizeof(uint32_t);
811 if ((tmplt_hdr_size
!= tmplt_hdr_def_size
) ||
812 (ha
->reset_tmplt
.hdr
->signature
!= RESET_TMPLT_HDR_SIGNATURE
)) {
813 ql4_printk(KERN_ERR
, ha
, "%s: Template Header size %d is invalid, tmplt_hdr_def_size %d\n",
814 __func__
, tmplt_hdr_size
, tmplt_hdr_def_size
);
815 goto exit_read_template_error
;
818 addr
= QLA83XX_RESET_TEMPLATE_ADDR
+ ha
->reset_tmplt
.hdr
->hdr_size
;
819 p_buff
= ha
->reset_tmplt
.buff
+ ha
->reset_tmplt
.hdr
->hdr_size
;
820 tmplt_hdr_def_size
= (ha
->reset_tmplt
.hdr
->size
-
821 ha
->reset_tmplt
.hdr
->hdr_size
) / sizeof(uint32_t);
823 DEBUG2(ql4_printk(KERN_INFO
, ha
,
824 "%s: Read rest of the template size %d\n",
825 __func__
, ha
->reset_tmplt
.hdr
->size
));
827 /* Copy rest of the template */
828 ret_val
= qla4_83xx_flash_read_u32(ha
, addr
, p_buff
,
830 if (ret_val
!= QLA_SUCCESS
) {
831 ql4_printk(KERN_ERR
, ha
, "%s: Failed to read reset template\n",
833 goto exit_read_template_error
;
836 /* Integrity check */
837 if (qla4_83xx_reset_seq_checksum_test(ha
)) {
838 ql4_printk(KERN_ERR
, ha
, "%s: Reset Seq checksum failed!\n",
840 goto exit_read_template_error
;
842 DEBUG2(ql4_printk(KERN_INFO
, ha
,
843 "%s: Reset Seq checksum passed, Get stop, start and init seq offsets\n",
846 /* Get STOP, START, INIT sequence offsets */
847 ha
->reset_tmplt
.init_offset
= ha
->reset_tmplt
.buff
+
848 ha
->reset_tmplt
.hdr
->init_seq_offset
;
849 ha
->reset_tmplt
.start_offset
= ha
->reset_tmplt
.buff
+
850 ha
->reset_tmplt
.hdr
->start_seq_offset
;
851 ha
->reset_tmplt
.stop_offset
= ha
->reset_tmplt
.buff
+
852 ha
->reset_tmplt
.hdr
->hdr_size
;
853 qla4_83xx_dump_reset_seq_hdr(ha
);
855 goto exit_read_reset_template
;
857 exit_read_template_error
:
858 vfree(ha
->reset_tmplt
.buff
);
860 exit_read_reset_template
:
865 * qla4_83xx_read_write_crb_reg - Read from raddr and write value to waddr.
867 * @ha : Pointer to adapter structure
868 * @raddr : CRB address to read from
869 * @waddr : CRB address to write to
871 static void qla4_83xx_read_write_crb_reg(struct scsi_qla_host
*ha
,
872 uint32_t raddr
, uint32_t waddr
)
876 qla4_83xx_rd_reg_indirect(ha
, raddr
, &value
);
877 qla4_83xx_wr_reg_indirect(ha
, waddr
, value
);
881 * qla4_83xx_rmw_crb_reg - Read Modify Write crb register
883 * This function read value from raddr, AND with test_mask,
884 * Shift Left,Right/OR/XOR with values RMW header and write value to waddr.
886 * @ha : Pointer to adapter structure
887 * @raddr : CRB address to read from
888 * @waddr : CRB address to write to
889 * @p_rmw_hdr : header with shift/or/xor values.
891 static void qla4_83xx_rmw_crb_reg(struct scsi_qla_host
*ha
, uint32_t raddr
,
893 struct qla4_83xx_rmw
*p_rmw_hdr
)
897 if (p_rmw_hdr
->index_a
)
898 value
= ha
->reset_tmplt
.array
[p_rmw_hdr
->index_a
];
900 qla4_83xx_rd_reg_indirect(ha
, raddr
, &value
);
902 value
&= p_rmw_hdr
->test_mask
;
903 value
<<= p_rmw_hdr
->shl
;
904 value
>>= p_rmw_hdr
->shr
;
905 value
|= p_rmw_hdr
->or_value
;
906 value
^= p_rmw_hdr
->xor_value
;
908 qla4_83xx_wr_reg_indirect(ha
, waddr
, value
);
913 static void qla4_83xx_write_list(struct scsi_qla_host
*ha
,
914 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
916 struct qla4_83xx_entry
*p_entry
;
919 p_entry
= (struct qla4_83xx_entry
*)
920 ((char *)p_hdr
+ sizeof(struct qla4_83xx_reset_entry_hdr
));
922 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
923 qla4_83xx_wr_reg_indirect(ha
, p_entry
->arg1
, p_entry
->arg2
);
925 udelay((uint32_t)(p_hdr
->delay
));
929 static void qla4_83xx_read_write_list(struct scsi_qla_host
*ha
,
930 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
932 struct qla4_83xx_entry
*p_entry
;
935 p_entry
= (struct qla4_83xx_entry
*)
936 ((char *)p_hdr
+ sizeof(struct qla4_83xx_reset_entry_hdr
));
938 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
939 qla4_83xx_read_write_crb_reg(ha
, p_entry
->arg1
, p_entry
->arg2
);
941 udelay((uint32_t)(p_hdr
->delay
));
945 static void qla4_83xx_poll_list(struct scsi_qla_host
*ha
,
946 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
949 struct qla4_83xx_entry
*p_entry
;
950 struct qla4_83xx_poll
*p_poll
;
954 p_poll
= (struct qla4_83xx_poll
*)
955 ((char *)p_hdr
+ sizeof(struct qla4_83xx_reset_entry_hdr
));
957 /* Entries start after 8 byte qla4_83xx_poll, poll header contains
958 * the test_mask, test_value. */
959 p_entry
= (struct qla4_83xx_entry
*)((char *)p_poll
+
960 sizeof(struct qla4_83xx_poll
));
962 delay
= (long)p_hdr
->delay
;
964 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
965 qla4_83xx_poll_reg(ha
, p_entry
->arg1
, delay
,
970 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
971 if (qla4_83xx_poll_reg(ha
, p_entry
->arg1
, delay
,
973 p_poll
->test_value
)) {
974 qla4_83xx_rd_reg_indirect(ha
, p_entry
->arg1
,
976 qla4_83xx_rd_reg_indirect(ha
, p_entry
->arg2
,
983 static void qla4_83xx_poll_write_list(struct scsi_qla_host
*ha
,
984 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
987 struct qla4_83xx_quad_entry
*p_entry
;
988 struct qla4_83xx_poll
*p_poll
;
991 p_poll
= (struct qla4_83xx_poll
*)
992 ((char *)p_hdr
+ sizeof(struct qla4_83xx_reset_entry_hdr
));
993 p_entry
= (struct qla4_83xx_quad_entry
*)
994 ((char *)p_poll
+ sizeof(struct qla4_83xx_poll
));
995 delay
= (long)p_hdr
->delay
;
997 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
998 qla4_83xx_wr_reg_indirect(ha
, p_entry
->dr_addr
,
1000 qla4_83xx_wr_reg_indirect(ha
, p_entry
->ar_addr
,
1003 if (qla4_83xx_poll_reg(ha
, p_entry
->ar_addr
, delay
,
1005 p_poll
->test_value
)) {
1006 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1007 "%s: Timeout Error: poll list, item_num %d, entry_num %d\n",
1009 ha
->reset_tmplt
.seq_index
));
1015 static void qla4_83xx_read_modify_write(struct scsi_qla_host
*ha
,
1016 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
1018 struct qla4_83xx_entry
*p_entry
;
1019 struct qla4_83xx_rmw
*p_rmw_hdr
;
1022 p_rmw_hdr
= (struct qla4_83xx_rmw
*)
1023 ((char *)p_hdr
+ sizeof(struct qla4_83xx_reset_entry_hdr
));
1024 p_entry
= (struct qla4_83xx_entry
*)
1025 ((char *)p_rmw_hdr
+ sizeof(struct qla4_83xx_rmw
));
1027 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
1028 qla4_83xx_rmw_crb_reg(ha
, p_entry
->arg1
, p_entry
->arg2
,
1031 udelay((uint32_t)(p_hdr
->delay
));
1035 static void qla4_83xx_pause(struct scsi_qla_host
*ha
,
1036 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
1039 mdelay((uint32_t)((long)p_hdr
->delay
));
1042 static void qla4_83xx_poll_read_list(struct scsi_qla_host
*ha
,
1043 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
1047 struct qla4_83xx_quad_entry
*p_entry
;
1048 struct qla4_83xx_poll
*p_poll
;
1052 p_poll
= (struct qla4_83xx_poll
*)
1053 ((char *)p_hdr
+ sizeof(struct qla4_83xx_reset_entry_hdr
));
1054 p_entry
= (struct qla4_83xx_quad_entry
*)
1055 ((char *)p_poll
+ sizeof(struct qla4_83xx_poll
));
1056 delay
= (long)p_hdr
->delay
;
1058 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
1059 qla4_83xx_wr_reg_indirect(ha
, p_entry
->ar_addr
,
1062 if (qla4_83xx_poll_reg(ha
, p_entry
->ar_addr
, delay
,
1064 p_poll
->test_value
)) {
1065 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1066 "%s: Timeout Error: poll list, Item_num %d, entry_num %d\n",
1068 ha
->reset_tmplt
.seq_index
));
1070 index
= ha
->reset_tmplt
.array_index
;
1071 qla4_83xx_rd_reg_indirect(ha
, p_entry
->dr_addr
,
1073 ha
->reset_tmplt
.array
[index
++] = value
;
1075 if (index
== QLA83XX_MAX_RESET_SEQ_ENTRIES
)
1076 ha
->reset_tmplt
.array_index
= 1;
1082 static void qla4_83xx_seq_end(struct scsi_qla_host
*ha
,
1083 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
1085 ha
->reset_tmplt
.seq_end
= 1;
1088 static void qla4_83xx_template_end(struct scsi_qla_host
*ha
,
1089 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
1091 ha
->reset_tmplt
.template_end
= 1;
1093 if (ha
->reset_tmplt
.seq_error
== 0) {
1094 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1095 "%s: Reset sequence completed SUCCESSFULLY.\n",
1098 ql4_printk(KERN_ERR
, ha
, "%s: Reset sequence completed with some timeout errors.\n",
1104 * qla4_83xx_process_reset_template - Process reset template.
1106 * Process all entries in reset template till entry with SEQ_END opcode,
1107 * which indicates end of the reset template processing. Each entry has a
1108 * Reset Entry header, entry opcode/command, with size of the entry, number
1109 * of entries in sub-sequence and delay in microsecs or timeout in millisecs.
1111 * @ha : Pointer to adapter structure
1112 * @p_buff : Common reset entry header.
1114 static void qla4_83xx_process_reset_template(struct scsi_qla_host
*ha
,
1118 struct qla4_83xx_reset_entry_hdr
*p_hdr
;
1119 char *p_entry
= p_buff
;
1121 ha
->reset_tmplt
.seq_end
= 0;
1122 ha
->reset_tmplt
.template_end
= 0;
1123 entries
= ha
->reset_tmplt
.hdr
->entries
;
1124 index
= ha
->reset_tmplt
.seq_index
;
1126 for (; (!ha
->reset_tmplt
.seq_end
) && (index
< entries
); index
++) {
1128 p_hdr
= (struct qla4_83xx_reset_entry_hdr
*)p_entry
;
1129 switch (p_hdr
->cmd
) {
1132 case OPCODE_WRITE_LIST
:
1133 qla4_83xx_write_list(ha
, p_hdr
);
1135 case OPCODE_READ_WRITE_LIST
:
1136 qla4_83xx_read_write_list(ha
, p_hdr
);
1138 case OPCODE_POLL_LIST
:
1139 qla4_83xx_poll_list(ha
, p_hdr
);
1141 case OPCODE_POLL_WRITE_LIST
:
1142 qla4_83xx_poll_write_list(ha
, p_hdr
);
1144 case OPCODE_READ_MODIFY_WRITE
:
1145 qla4_83xx_read_modify_write(ha
, p_hdr
);
1147 case OPCODE_SEQ_PAUSE
:
1148 qla4_83xx_pause(ha
, p_hdr
);
1150 case OPCODE_SEQ_END
:
1151 qla4_83xx_seq_end(ha
, p_hdr
);
1153 case OPCODE_TMPL_END
:
1154 qla4_83xx_template_end(ha
, p_hdr
);
1156 case OPCODE_POLL_READ_LIST
:
1157 qla4_83xx_poll_read_list(ha
, p_hdr
);
1160 ql4_printk(KERN_ERR
, ha
, "%s: Unknown command ==> 0x%04x on entry = %d\n",
1161 __func__
, p_hdr
->cmd
, index
);
1165 /* Set pointer to next entry in the sequence. */
1166 p_entry
+= p_hdr
->size
;
1169 ha
->reset_tmplt
.seq_index
= index
;
1172 static void qla4_83xx_process_stop_seq(struct scsi_qla_host
*ha
)
1174 ha
->reset_tmplt
.seq_index
= 0;
1175 qla4_83xx_process_reset_template(ha
, ha
->reset_tmplt
.stop_offset
);
1177 if (ha
->reset_tmplt
.seq_end
!= 1)
1178 ql4_printk(KERN_ERR
, ha
, "%s: Abrupt STOP Sub-Sequence end.\n",
1182 static void qla4_83xx_process_start_seq(struct scsi_qla_host
*ha
)
1184 qla4_83xx_process_reset_template(ha
, ha
->reset_tmplt
.start_offset
);
1186 if (ha
->reset_tmplt
.template_end
!= 1)
1187 ql4_printk(KERN_ERR
, ha
, "%s: Abrupt START Sub-Sequence end.\n",
1191 static void qla4_83xx_process_init_seq(struct scsi_qla_host
*ha
)
1193 qla4_83xx_process_reset_template(ha
, ha
->reset_tmplt
.init_offset
);
1195 if (ha
->reset_tmplt
.seq_end
!= 1)
1196 ql4_printk(KERN_ERR
, ha
, "%s: Abrupt INIT Sub-Sequence end.\n",
1200 static int qla4_83xx_restart(struct scsi_qla_host
*ha
)
1202 int ret_val
= QLA_SUCCESS
;
1205 qla4_83xx_process_stop_seq(ha
);
1209 * If IDC_CTRL BIT1 is set, clear it on going to INIT state and
1210 * don't collect minidump
1212 idc_ctrl
= qla4_83xx_rd_reg(ha
, QLA83XX_IDC_DRV_CTRL
);
1213 if (idc_ctrl
& GRACEFUL_RESET_BIT1
) {
1214 qla4_83xx_wr_reg(ha
, QLA83XX_IDC_DRV_CTRL
,
1215 (idc_ctrl
& ~GRACEFUL_RESET_BIT1
));
1216 ql4_printk(KERN_INFO
, ha
, "%s: Graceful RESET: Not collecting minidump\n",
1219 qla4_8xxx_get_minidump(ha
);
1222 qla4_83xx_process_init_seq(ha
);
1224 if (qla4_83xx_copy_bootloader(ha
)) {
1225 ql4_printk(KERN_ERR
, ha
, "%s: Copy bootloader, firmware restart failed!\n",
1227 ret_val
= QLA_ERROR
;
1231 qla4_83xx_wr_reg(ha
, QLA83XX_FW_IMAGE_VALID
, QLA83XX_BOOT_FROM_FLASH
);
1232 qla4_83xx_process_start_seq(ha
);
1238 int qla4_83xx_start_firmware(struct scsi_qla_host
*ha
)
1240 int ret_val
= QLA_SUCCESS
;
1242 ret_val
= qla4_83xx_restart(ha
);
1243 if (ret_val
== QLA_ERROR
) {
1244 ql4_printk(KERN_ERR
, ha
, "%s: Restart error\n", __func__
);
1247 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: Restart done\n",
1251 ret_val
= qla4_83xx_check_cmd_peg_status(ha
);
1252 if (ret_val
== QLA_ERROR
)
1253 ql4_printk(KERN_ERR
, ha
, "%s: Peg not initialized\n",
1260 /*----------------------Interrupt Related functions ---------------------*/
1262 static void qla4_83xx_disable_iocb_intrs(struct scsi_qla_host
*ha
)
1264 if (test_and_clear_bit(AF_83XX_IOCB_INTR_ON
, &ha
->flags
))
1265 qla4_8xxx_intr_disable(ha
);
1268 static void qla4_83xx_disable_mbox_intrs(struct scsi_qla_host
*ha
)
1270 uint32_t mb_int
, ret
;
1272 if (test_and_clear_bit(AF_83XX_MBOX_INTR_ON
, &ha
->flags
)) {
1273 ret
= readl(&ha
->qla4_83xx_reg
->mbox_int
);
1274 mb_int
= ret
& ~INT_ENABLE_FW_MB
;
1275 writel(mb_int
, &ha
->qla4_83xx_reg
->mbox_int
);
1276 writel(1, &ha
->qla4_83xx_reg
->leg_int_mask
);
1280 void qla4_83xx_disable_intrs(struct scsi_qla_host
*ha
)
1282 qla4_83xx_disable_mbox_intrs(ha
);
1283 qla4_83xx_disable_iocb_intrs(ha
);
1286 static void qla4_83xx_enable_iocb_intrs(struct scsi_qla_host
*ha
)
1288 if (!test_bit(AF_83XX_IOCB_INTR_ON
, &ha
->flags
)) {
1289 qla4_8xxx_intr_enable(ha
);
1290 set_bit(AF_83XX_IOCB_INTR_ON
, &ha
->flags
);
1294 void qla4_83xx_enable_mbox_intrs(struct scsi_qla_host
*ha
)
1298 if (!test_bit(AF_83XX_MBOX_INTR_ON
, &ha
->flags
)) {
1299 mb_int
= INT_ENABLE_FW_MB
;
1300 writel(mb_int
, &ha
->qla4_83xx_reg
->mbox_int
);
1301 writel(0, &ha
->qla4_83xx_reg
->leg_int_mask
);
1302 set_bit(AF_83XX_MBOX_INTR_ON
, &ha
->flags
);
1307 void qla4_83xx_enable_intrs(struct scsi_qla_host
*ha
)
1309 qla4_83xx_enable_mbox_intrs(ha
);
1310 qla4_83xx_enable_iocb_intrs(ha
);
1314 void qla4_83xx_queue_mbox_cmd(struct scsi_qla_host
*ha
, uint32_t *mbx_cmd
,
1319 /* Load all mailbox registers, except mailbox 0. */
1320 for (i
= 1; i
< incount
; i
++)
1321 writel(mbx_cmd
[i
], &ha
->qla4_83xx_reg
->mailbox_in
[i
]);
1323 writel(mbx_cmd
[0], &ha
->qla4_83xx_reg
->mailbox_in
[0]);
1325 /* Set Host Interrupt register to 1, to tell the firmware that
1326 * a mailbox command is pending. Firmware after reading the
1327 * mailbox command, clears the host interrupt register */
1328 writel(HINT_MBX_INT_PENDING
, &ha
->qla4_83xx_reg
->host_intr
);
1331 void qla4_83xx_process_mbox_intr(struct scsi_qla_host
*ha
, int outcount
)
1335 intr_status
= readl(&ha
->qla4_83xx_reg
->risc_intr
);
1337 ha
->mbox_status_count
= outcount
;
1338 ha
->isp_ops
->interrupt_service_routine(ha
, intr_status
);
1343 * qla4_83xx_isp_reset - Resets ISP and aborts all outstanding commands.
1344 * @ha: pointer to host adapter structure.
1346 int qla4_83xx_isp_reset(struct scsi_qla_host
*ha
)
1351 ha
->isp_ops
->idc_lock(ha
);
1352 dev_state
= qla4_8xxx_rd_direct(ha
, QLA8XXX_CRB_DEV_STATE
);
1354 if (ql4xdontresethba
)
1355 qla4_83xx_set_idc_dontreset(ha
);
1357 if (dev_state
== QLA8XXX_DEV_READY
) {
1358 /* If IDC_CTRL DONTRESETHBA_BIT0 is set dont do reset
1360 if (qla4_83xx_idc_dontreset(ha
) == DONTRESET_BIT0
) {
1361 ql4_printk(KERN_ERR
, ha
, "%s: Reset recovery disabled\n",
1364 goto exit_isp_reset
;
1367 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: HW State: NEED RESET\n",
1369 qla4_8xxx_wr_direct(ha
, QLA8XXX_CRB_DEV_STATE
,
1370 QLA8XXX_DEV_NEED_RESET
);
1373 /* If device_state is NEED_RESET, go ahead with
1374 * Reset,irrespective of ql4xdontresethba. This is to allow a
1375 * non-reset-owner to force a reset. Non-reset-owner sets
1376 * the IDC_CTRL BIT0 to prevent Reset-owner from doing a Reset
1377 * and then forces a Reset by setting device_state to
1379 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1380 "%s: HW state already set to NEED_RESET\n",
1384 /* For ISP8324 and ISP8042, Reset owner is NIC, iSCSI or FCOE based on
1385 * priority and which drivers are present. Unlike ISP8022, the function
1386 * setting NEED_RESET, may not be the Reset owner. */
1387 if (qla4_83xx_can_perform_reset(ha
))
1388 set_bit(AF_8XXX_RST_OWNER
, &ha
->flags
);
1390 ha
->isp_ops
->idc_unlock(ha
);
1391 rval
= qla4_8xxx_device_state_handler(ha
);
1393 ha
->isp_ops
->idc_lock(ha
);
1394 qla4_8xxx_clear_rst_ready(ha
);
1396 ha
->isp_ops
->idc_unlock(ha
);
1398 if (rval
== QLA_SUCCESS
)
1399 clear_bit(AF_FW_RECOVERY
, &ha
->flags
);
1404 static void qla4_83xx_dump_pause_control_regs(struct scsi_qla_host
*ha
)
1406 u32 val
= 0, val1
= 0;
1407 int i
, status
= QLA_SUCCESS
;
1409 status
= qla4_83xx_rd_reg_indirect(ha
, QLA83XX_SRE_SHIM_CONTROL
, &val
);
1410 DEBUG2(ql4_printk(KERN_INFO
, ha
, "SRE-Shim Ctrl:0x%x\n", val
));
1412 /* Port 0 Rx Buffer Pause Threshold Registers. */
1413 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1414 "Port 0 Rx Buffer Pause Threshold Registers[TC7..TC0]:"));
1415 for (i
= 0; i
< 8; i
++) {
1416 status
= qla4_83xx_rd_reg_indirect(ha
,
1417 QLA83XX_PORT0_RXB_PAUSE_THRS
+ (i
* 0x4), &val
);
1418 DEBUG2(pr_info("0x%x ", val
));
1421 DEBUG2(pr_info("\n"));
1423 /* Port 1 Rx Buffer Pause Threshold Registers. */
1424 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1425 "Port 1 Rx Buffer Pause Threshold Registers[TC7..TC0]:"));
1426 for (i
= 0; i
< 8; i
++) {
1427 status
= qla4_83xx_rd_reg_indirect(ha
,
1428 QLA83XX_PORT1_RXB_PAUSE_THRS
+ (i
* 0x4), &val
);
1429 DEBUG2(pr_info("0x%x ", val
));
1432 DEBUG2(pr_info("\n"));
1434 /* Port 0 RxB Traffic Class Max Cell Registers. */
1435 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1436 "Port 0 RxB Traffic Class Max Cell Registers[3..0]:"));
1437 for (i
= 0; i
< 4; i
++) {
1438 status
= qla4_83xx_rd_reg_indirect(ha
,
1439 QLA83XX_PORT0_RXB_TC_MAX_CELL
+ (i
* 0x4), &val
);
1440 DEBUG2(pr_info("0x%x ", val
));
1443 DEBUG2(pr_info("\n"));
1445 /* Port 1 RxB Traffic Class Max Cell Registers. */
1446 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1447 "Port 1 RxB Traffic Class Max Cell Registers[3..0]:"));
1448 for (i
= 0; i
< 4; i
++) {
1449 status
= qla4_83xx_rd_reg_indirect(ha
,
1450 QLA83XX_PORT1_RXB_TC_MAX_CELL
+ (i
* 0x4), &val
);
1451 DEBUG2(pr_info("0x%x ", val
));
1454 DEBUG2(pr_info("\n"));
1456 /* Port 0 RxB Rx Traffic Class Stats. */
1457 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1458 "Port 0 RxB Rx Traffic Class Stats [TC7..TC0]"));
1459 for (i
= 7; i
>= 0; i
--) {
1460 status
= qla4_83xx_rd_reg_indirect(ha
,
1461 QLA83XX_PORT0_RXB_TC_STATS
,
1463 val
&= ~(0x7 << 29); /* Reset bits 29 to 31 */
1464 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_PORT0_RXB_TC_STATS
,
1466 status
= qla4_83xx_rd_reg_indirect(ha
,
1467 QLA83XX_PORT0_RXB_TC_STATS
,
1469 DEBUG2(pr_info("0x%x ", val
));
1472 DEBUG2(pr_info("\n"));
1474 /* Port 1 RxB Rx Traffic Class Stats. */
1475 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1476 "Port 1 RxB Rx Traffic Class Stats [TC7..TC0]"));
1477 for (i
= 7; i
>= 0; i
--) {
1478 status
= qla4_83xx_rd_reg_indirect(ha
,
1479 QLA83XX_PORT1_RXB_TC_STATS
,
1481 val
&= ~(0x7 << 29); /* Reset bits 29 to 31 */
1482 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_PORT1_RXB_TC_STATS
,
1484 status
= qla4_83xx_rd_reg_indirect(ha
,
1485 QLA83XX_PORT1_RXB_TC_STATS
,
1487 DEBUG2(pr_info("0x%x ", val
));
1490 DEBUG2(pr_info("\n"));
1492 status
= qla4_83xx_rd_reg_indirect(ha
, QLA83XX_PORT2_IFB_PAUSE_THRS
,
1494 status
= qla4_83xx_rd_reg_indirect(ha
, QLA83XX_PORT3_IFB_PAUSE_THRS
,
1497 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1498 "IFB-Pause Thresholds: Port 2:0x%x, Port 3:0x%x\n",
1502 static void __qla4_83xx_disable_pause(struct scsi_qla_host
*ha
)
1506 /* set SRE-Shim Control Register */
1507 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_SRE_SHIM_CONTROL
,
1508 QLA83XX_SET_PAUSE_VAL
);
1510 for (i
= 0; i
< 8; i
++) {
1511 /* Port 0 Rx Buffer Pause Threshold Registers. */
1512 qla4_83xx_wr_reg_indirect(ha
,
1513 QLA83XX_PORT0_RXB_PAUSE_THRS
+ (i
* 0x4),
1514 QLA83XX_SET_PAUSE_VAL
);
1515 /* Port 1 Rx Buffer Pause Threshold Registers. */
1516 qla4_83xx_wr_reg_indirect(ha
,
1517 QLA83XX_PORT1_RXB_PAUSE_THRS
+ (i
* 0x4),
1518 QLA83XX_SET_PAUSE_VAL
);
1521 for (i
= 0; i
< 4; i
++) {
1522 /* Port 0 RxB Traffic Class Max Cell Registers. */
1523 qla4_83xx_wr_reg_indirect(ha
,
1524 QLA83XX_PORT0_RXB_TC_MAX_CELL
+ (i
* 0x4),
1525 QLA83XX_SET_TC_MAX_CELL_VAL
);
1526 /* Port 1 RxB Traffic Class Max Cell Registers. */
1527 qla4_83xx_wr_reg_indirect(ha
,
1528 QLA83XX_PORT1_RXB_TC_MAX_CELL
+ (i
* 0x4),
1529 QLA83XX_SET_TC_MAX_CELL_VAL
);
1532 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_PORT2_IFB_PAUSE_THRS
,
1533 QLA83XX_SET_PAUSE_VAL
);
1534 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_PORT3_IFB_PAUSE_THRS
,
1535 QLA83XX_SET_PAUSE_VAL
);
1537 ql4_printk(KERN_INFO
, ha
, "Disabled pause frames successfully.\n");
1541 * qla4_83xx_eport_init - Initialize EPort.
1542 * @ha: Pointer to host adapter structure.
1544 * If EPort hardware is in reset state before disabling pause, there would be
1545 * serious hardware wedging issues. To prevent this perform eport init everytime
1546 * before disabling pause frames.
1548 static void qla4_83xx_eport_init(struct scsi_qla_host
*ha
)
1550 /* Clear the 8 registers */
1551 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_REG
, 0x0);
1552 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_PORT0
, 0x0);
1553 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_PORT1
, 0x0);
1554 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_PORT2
, 0x0);
1555 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_PORT3
, 0x0);
1556 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_SRE_SHIM
, 0x0);
1557 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_EPG_SHIM
, 0x0);
1558 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_ETHER_PCS
, 0x0);
1560 /* Write any value to Reset Control register */
1561 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_CONTROL
, 0xFF);
1563 ql4_printk(KERN_INFO
, ha
, "EPORT is out of reset.\n");
1566 void qla4_83xx_disable_pause(struct scsi_qla_host
*ha
)
1568 ha
->isp_ops
->idc_lock(ha
);
1569 /* Before disabling pause frames, ensure that eport is not in reset */
1570 qla4_83xx_eport_init(ha
);
1571 qla4_83xx_dump_pause_control_regs(ha
);
1572 __qla4_83xx_disable_pause(ha
);
1573 ha
->isp_ops
->idc_unlock(ha
);
1577 * qla4_83xx_is_detached - Check if we are marked invisible.
1578 * @ha: Pointer to host adapter structure.
1580 int qla4_83xx_is_detached(struct scsi_qla_host
*ha
)
1582 uint32_t drv_active
;
1584 drv_active
= qla4_8xxx_rd_direct(ha
, QLA8XXX_CRB_DRV_ACTIVE
);
1586 if (test_bit(AF_INIT_DONE
, &ha
->flags
) &&
1587 !(drv_active
& (1 << ha
->func_num
))) {
1588 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: drv_active = 0x%X\n",
1589 __func__
, drv_active
));