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
);
253 * qla4_83xx_ms_mem_write_128b - Writes data to MS/off-chip memory
254 * @ha: Pointer to adapter structure
255 * @addr: Flash address to write to
256 * @data: Data to be written
257 * @count: word_count to be written
259 * Return: On success return QLA_SUCCESS
260 * On error return QLA_ERROR
262 int qla4_83xx_ms_mem_write_128b(struct scsi_qla_host
*ha
, uint64_t addr
,
263 uint32_t *data
, uint32_t count
)
268 int ret_val
= QLA_SUCCESS
;
270 /* Only 128-bit aligned access */
273 goto exit_ms_mem_write
;
276 write_lock_irqsave(&ha
->hw_lock
, flags
);
279 ret_val
= qla4_83xx_wr_reg_indirect(ha
, MD_MIU_TEST_AGT_ADDR_HI
, 0);
280 if (ret_val
== QLA_ERROR
) {
281 ql4_printk(KERN_ERR
, ha
, "%s: write to AGT_ADDR_HI failed\n",
283 goto exit_ms_mem_write_unlock
;
286 for (i
= 0; i
< count
; i
++, addr
+= 16) {
287 if (!((QLA8XXX_ADDR_IN_RANGE(addr
, QLA8XXX_ADDR_QDR_NET
,
288 QLA8XXX_ADDR_QDR_NET_MAX
)) ||
289 (QLA8XXX_ADDR_IN_RANGE(addr
, QLA8XXX_ADDR_DDR_NET
,
290 QLA8XXX_ADDR_DDR_NET_MAX
)))) {
292 goto exit_ms_mem_write_unlock
;
295 ret_val
= qla4_83xx_wr_reg_indirect(ha
, MD_MIU_TEST_AGT_ADDR_LO
,
298 ret_val
|= qla4_83xx_wr_reg_indirect(ha
,
299 MD_MIU_TEST_AGT_WRDATA_LO
,
301 ret_val
|= qla4_83xx_wr_reg_indirect(ha
,
302 MD_MIU_TEST_AGT_WRDATA_HI
,
304 ret_val
|= qla4_83xx_wr_reg_indirect(ha
,
305 MD_MIU_TEST_AGT_WRDATA_ULO
,
307 ret_val
|= qla4_83xx_wr_reg_indirect(ha
,
308 MD_MIU_TEST_AGT_WRDATA_UHI
,
310 if (ret_val
== QLA_ERROR
) {
311 ql4_printk(KERN_ERR
, ha
, "%s: write to AGT_WRDATA failed\n",
313 goto exit_ms_mem_write_unlock
;
316 /* Check write status */
317 ret_val
= qla4_83xx_wr_reg_indirect(ha
, MD_MIU_TEST_AGT_CTRL
,
318 MIU_TA_CTL_WRITE_ENABLE
);
319 ret_val
|= qla4_83xx_wr_reg_indirect(ha
, MD_MIU_TEST_AGT_CTRL
,
320 MIU_TA_CTL_WRITE_START
);
321 if (ret_val
== QLA_ERROR
) {
322 ql4_printk(KERN_ERR
, ha
, "%s: write to AGT_CTRL failed\n",
324 goto exit_ms_mem_write_unlock
;
327 for (j
= 0; j
< MAX_CTL_CHECK
; j
++) {
328 ret_val
= qla4_83xx_rd_reg_indirect(ha
,
329 MD_MIU_TEST_AGT_CTRL
,
331 if (ret_val
== QLA_ERROR
) {
332 ql4_printk(KERN_ERR
, ha
, "%s: failed to read MD_MIU_TEST_AGT_CTRL\n",
334 goto exit_ms_mem_write_unlock
;
336 if ((agt_ctrl
& MIU_TA_CTL_BUSY
) == 0)
340 /* Status check failed */
341 if (j
>= MAX_CTL_CHECK
) {
342 printk_ratelimited(KERN_ERR
"%s: MS memory write failed!\n",
345 goto exit_ms_mem_write_unlock
;
349 exit_ms_mem_write_unlock
:
350 write_unlock_irqrestore(&ha
->hw_lock
, flags
);
356 #define INTENT_TO_RECOVER 0x01
357 #define PROCEED_TO_RECOVER 0x02
359 static int qla4_83xx_lock_recovery(struct scsi_qla_host
*ha
)
362 uint32_t lock
= 0, lockid
;
363 int ret_val
= QLA_ERROR
;
365 lockid
= ha
->isp_ops
->rd_reg_direct(ha
, QLA83XX_DRV_LOCKRECOVERY
);
367 /* Check for other Recovery in progress, go wait */
368 if ((lockid
& 0x3) != 0)
369 goto exit_lock_recovery
;
371 /* Intent to Recover */
372 ha
->isp_ops
->wr_reg_direct(ha
, QLA83XX_DRV_LOCKRECOVERY
,
373 (ha
->func_num
<< 2) | INTENT_TO_RECOVER
);
377 /* Check Intent to Recover is advertised */
378 lockid
= ha
->isp_ops
->rd_reg_direct(ha
, QLA83XX_DRV_LOCKRECOVERY
);
379 if ((lockid
& 0x3C) != (ha
->func_num
<< 2))
380 goto exit_lock_recovery
;
382 ql4_printk(KERN_INFO
, ha
, "%s: IDC Lock recovery initiated for func %d\n",
383 __func__
, ha
->func_num
);
385 /* Proceed to Recover */
386 ha
->isp_ops
->wr_reg_direct(ha
, QLA83XX_DRV_LOCKRECOVERY
,
387 (ha
->func_num
<< 2) | PROCEED_TO_RECOVER
);
390 ha
->isp_ops
->wr_reg_direct(ha
, QLA83XX_DRV_LOCK_ID
, 0xFF);
391 ha
->isp_ops
->rd_reg_direct(ha
, QLA83XX_DRV_UNLOCK
);
393 /* Clear bits 0-5 in IDC_RECOVERY register*/
394 ha
->isp_ops
->wr_reg_direct(ha
, QLA83XX_DRV_LOCKRECOVERY
, 0);
397 lock
= ha
->isp_ops
->rd_reg_direct(ha
, QLA83XX_DRV_LOCK
);
399 lockid
= ha
->isp_ops
->rd_reg_direct(ha
, QLA83XX_DRV_LOCK_ID
);
400 lockid
= ((lockid
+ (1 << 8)) & ~0xFF) | ha
->func_num
;
401 ha
->isp_ops
->wr_reg_direct(ha
, QLA83XX_DRV_LOCK_ID
, lockid
);
402 ret_val
= QLA_SUCCESS
;
409 #define QLA83XX_DRV_LOCK_MSLEEP 200
411 int qla4_83xx_drv_lock(struct scsi_qla_host
*ha
)
415 int ret_val
= QLA_SUCCESS
;
416 uint32_t first_owner
= 0;
417 uint32_t tmo_owner
= 0;
422 while (status
== 0) {
423 status
= qla4_83xx_rd_reg(ha
, QLA83XX_DRV_LOCK
);
425 /* Increment Counter (8-31) and update func_num (0-7) on
426 * getting a successful lock */
427 lock_id
= qla4_83xx_rd_reg(ha
, QLA83XX_DRV_LOCK_ID
);
428 lock_id
= ((lock_id
+ (1 << 8)) & ~0xFF) | ha
->func_num
;
429 qla4_83xx_wr_reg(ha
, QLA83XX_DRV_LOCK_ID
, lock_id
);
434 /* Save counter + ID of function holding the lock for
436 first_owner
= ha
->isp_ops
->rd_reg_direct(ha
,
437 QLA83XX_DRV_LOCK_ID
);
440 (QLA83XX_DRV_LOCK_TIMEOUT
/ QLA83XX_DRV_LOCK_MSLEEP
)) {
441 tmo_owner
= qla4_83xx_rd_reg(ha
, QLA83XX_DRV_LOCK_ID
);
442 func_num
= tmo_owner
& 0xFF;
443 lock_cnt
= tmo_owner
>> 8;
444 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",
445 __func__
, ha
->func_num
, func_num
, lock_cnt
,
446 (first_owner
& 0xFF));
448 if (first_owner
!= tmo_owner
) {
449 /* Some other driver got lock, OR same driver
450 * got lock again (counter value changed), when
451 * we were waiting for lock.
452 * Retry for another 2 sec */
453 ql4_printk(KERN_INFO
, ha
, "%s: IDC lock failed for func %d\n",
454 __func__
, ha
->func_num
);
457 /* Same driver holding lock > 2sec.
459 ret_val
= qla4_83xx_lock_recovery(ha
);
460 if (ret_val
== QLA_SUCCESS
) {
461 /* Recovered and got lock */
462 ql4_printk(KERN_INFO
, ha
, "%s: IDC lock Recovery by %d successful\n",
463 __func__
, ha
->func_num
);
466 /* Recovery Failed, some other function
467 * has the lock, wait for 2secs and retry */
468 ql4_printk(KERN_INFO
, ha
, "%s: IDC lock Recovery by %d failed, Retrying timout\n",
469 __func__
, ha
->func_num
);
473 msleep(QLA83XX_DRV_LOCK_MSLEEP
);
479 void qla4_83xx_drv_unlock(struct scsi_qla_host
*ha
)
483 id
= qla4_83xx_rd_reg(ha
, QLA83XX_DRV_LOCK_ID
);
485 if ((id
& 0xFF) != ha
->func_num
) {
486 ql4_printk(KERN_ERR
, ha
, "%s: IDC Unlock by %d failed, lock owner is %d\n",
487 __func__
, ha
->func_num
, (id
& 0xFF));
491 /* Keep lock counter value, update the ha->func_num to 0xFF */
492 qla4_83xx_wr_reg(ha
, QLA83XX_DRV_LOCK_ID
, (id
| 0xFF));
493 qla4_83xx_rd_reg(ha
, QLA83XX_DRV_UNLOCK
);
496 void qla4_83xx_set_idc_dontreset(struct scsi_qla_host
*ha
)
500 idc_ctrl
= qla4_83xx_rd_reg(ha
, QLA83XX_IDC_DRV_CTRL
);
501 idc_ctrl
|= DONTRESET_BIT0
;
502 qla4_83xx_wr_reg(ha
, QLA83XX_IDC_DRV_CTRL
, idc_ctrl
);
503 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: idc_ctrl = %d\n", __func__
,
507 void qla4_83xx_clear_idc_dontreset(struct scsi_qla_host
*ha
)
511 idc_ctrl
= qla4_83xx_rd_reg(ha
, QLA83XX_IDC_DRV_CTRL
);
512 idc_ctrl
&= ~DONTRESET_BIT0
;
513 qla4_83xx_wr_reg(ha
, QLA83XX_IDC_DRV_CTRL
, idc_ctrl
);
514 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: idc_ctrl = %d\n", __func__
,
518 int qla4_83xx_idc_dontreset(struct scsi_qla_host
*ha
)
522 idc_ctrl
= qla4_83xx_rd_reg(ha
, QLA83XX_IDC_DRV_CTRL
);
523 return idc_ctrl
& DONTRESET_BIT0
;
526 /*-------------------------IDC State Machine ---------------------*/
541 int qla4_83xx_can_perform_reset(struct scsi_qla_host
*ha
)
544 uint32_t dev_part
, dev_part1
, dev_part2
;
546 struct device_info device_map
[16];
550 int iscsi_present
= 0;
551 int iscsi_func_low
= 0;
553 /* Use the dev_partition register to determine the PCI function number
554 * and then check drv_active register to see which driver is loaded */
555 dev_part1
= qla4_83xx_rd_reg(ha
,
556 ha
->reg_tbl
[QLA8XXX_CRB_DEV_PART_INFO
]);
557 dev_part2
= qla4_83xx_rd_reg(ha
, QLA83XX_CRB_DEV_PART_INFO2
);
558 drv_active
= qla4_83xx_rd_reg(ha
, ha
->reg_tbl
[QLA8XXX_CRB_DRV_ACTIVE
]);
560 /* Each function has 4 bits in dev_partition Info register,
561 * Lower 2 bits - device type, Upper 2 bits - physical port number */
562 dev_part
= dev_part1
;
563 for (i
= nibble
= 0; i
<= 15; i
++, nibble
++) {
564 func_nibble
= dev_part
& (0xF << (nibble
* 4));
565 func_nibble
>>= (nibble
* 4);
566 device_map
[i
].func_num
= i
;
567 device_map
[i
].device_type
= func_nibble
& 0x3;
568 device_map
[i
].port_num
= func_nibble
& 0xC;
570 if (device_map
[i
].device_type
== NIC_CLASS
) {
571 if (drv_active
& (1 << device_map
[i
].func_num
)) {
575 } else if (device_map
[i
].device_type
== ISCSI_CLASS
) {
576 if (drv_active
& (1 << device_map
[i
].func_num
)) {
577 if (!iscsi_present
||
579 (iscsi_func_low
> device_map
[i
].func_num
)))
580 iscsi_func_low
= device_map
[i
].func_num
;
586 /* For function_num[8..15] get info from dev_part2 register */
589 dev_part
= dev_part2
;
593 /* NIC, iSCSI and FCOE are the Reset owners based on order, NIC gets
594 * precedence over iSCSI and FCOE and iSCSI over FCOE, based on drivers
596 if (!nic_present
&& (ha
->func_num
== iscsi_func_low
)) {
597 DEBUG2(ql4_printk(KERN_INFO
, ha
,
598 "%s: can reset - NIC not present and lower iSCSI function is %d\n",
599 __func__
, ha
->func_num
));
607 * qla4_83xx_need_reset_handler - Code to start reset sequence
608 * @ha: pointer to adapter structure
610 * Note: IDC lock must be held upon entry
612 void qla4_83xx_need_reset_handler(struct scsi_qla_host
*ha
)
614 uint32_t dev_state
, drv_state
, drv_active
;
615 unsigned long reset_timeout
, dev_init_timeout
;
617 ql4_printk(KERN_INFO
, ha
, "%s: Performing ISP error recovery\n",
620 if (!test_bit(AF_8XXX_RST_OWNER
, &ha
->flags
)) {
621 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: reset acknowledged\n",
623 qla4_8xxx_set_rst_ready(ha
);
625 /* Non-reset owners ACK Reset and wait for device INIT state
626 * as part of Reset Recovery by Reset Owner */
627 dev_init_timeout
= jiffies
+ (ha
->nx_dev_init_timeout
* HZ
);
630 if (time_after_eq(jiffies
, dev_init_timeout
)) {
631 ql4_printk(KERN_INFO
, ha
, "%s: Non Reset owner dev init timeout\n",
636 ha
->isp_ops
->idc_unlock(ha
);
638 ha
->isp_ops
->idc_lock(ha
);
640 dev_state
= qla4_8xxx_rd_direct(ha
,
641 QLA8XXX_CRB_DEV_STATE
);
642 } while (dev_state
== QLA8XXX_DEV_NEED_RESET
);
644 qla4_8xxx_set_rst_ready(ha
);
645 reset_timeout
= jiffies
+ (ha
->nx_reset_timeout
* HZ
);
646 drv_state
= qla4_8xxx_rd_direct(ha
, QLA8XXX_CRB_DRV_STATE
);
647 drv_active
= qla4_8xxx_rd_direct(ha
, QLA8XXX_CRB_DRV_ACTIVE
);
649 ql4_printk(KERN_INFO
, ha
, "%s: drv_state = 0x%x, drv_active = 0x%x\n",
650 __func__
, drv_state
, drv_active
);
652 while (drv_state
!= drv_active
) {
653 if (time_after_eq(jiffies
, reset_timeout
)) {
654 ql4_printk(KERN_INFO
, ha
, "%s: %s: RESET TIMEOUT! drv_state: 0x%08x, drv_active: 0x%08x\n",
655 __func__
, DRIVER_NAME
, drv_state
,
660 ha
->isp_ops
->idc_unlock(ha
);
662 ha
->isp_ops
->idc_lock(ha
);
664 drv_state
= qla4_8xxx_rd_direct(ha
,
665 QLA8XXX_CRB_DRV_STATE
);
666 drv_active
= qla4_8xxx_rd_direct(ha
,
667 QLA8XXX_CRB_DRV_ACTIVE
);
670 if (drv_state
!= drv_active
) {
671 ql4_printk(KERN_INFO
, ha
, "%s: Reset_owner turning off drv_active of non-acking function 0x%x\n",
672 __func__
, (drv_active
^ drv_state
));
673 drv_active
= drv_active
& drv_state
;
674 qla4_8xxx_wr_direct(ha
, QLA8XXX_CRB_DRV_ACTIVE
,
678 clear_bit(AF_8XXX_RST_OWNER
, &ha
->flags
);
679 /* Start Reset Recovery */
680 qla4_8xxx_device_bootstrap(ha
);
684 void qla4_83xx_get_idc_param(struct scsi_qla_host
*ha
)
686 uint32_t idc_params
, ret_val
;
688 ret_val
= qla4_83xx_flash_read_u32(ha
, QLA83XX_IDC_PARAM_ADDR
,
689 (uint8_t *)&idc_params
, 1);
690 if (ret_val
== QLA_SUCCESS
) {
691 ha
->nx_dev_init_timeout
= idc_params
& 0xFFFF;
692 ha
->nx_reset_timeout
= (idc_params
>> 16) & 0xFFFF;
694 ha
->nx_dev_init_timeout
= ROM_DEV_INIT_TIMEOUT
;
695 ha
->nx_reset_timeout
= ROM_DRV_RESET_ACK_TIMEOUT
;
698 DEBUG2(ql4_printk(KERN_DEBUG
, ha
,
699 "%s: ha->nx_dev_init_timeout = %d, ha->nx_reset_timeout = %d\n",
700 __func__
, ha
->nx_dev_init_timeout
,
701 ha
->nx_reset_timeout
));
704 /*-------------------------Reset Sequence Functions-----------------------*/
706 static void qla4_83xx_dump_reset_seq_hdr(struct scsi_qla_host
*ha
)
710 if (!ha
->reset_tmplt
.buff
) {
711 ql4_printk(KERN_ERR
, ha
, "%s: Error: Invalid reset_seq_template\n",
716 phdr
= ha
->reset_tmplt
.buff
;
718 DEBUG2(ql4_printk(KERN_INFO
, ha
,
719 "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",
720 *phdr
, *(phdr
+1), *(phdr
+2), *(phdr
+3), *(phdr
+4),
721 *(phdr
+5), *(phdr
+6), *(phdr
+7), *(phdr
+ 8),
722 *(phdr
+9), *(phdr
+10), *(phdr
+11), *(phdr
+12),
723 *(phdr
+13), *(phdr
+14), *(phdr
+15)));
726 static int qla4_83xx_copy_bootloader(struct scsi_qla_host
*ha
)
729 uint32_t src
, count
, size
;
731 int ret_val
= QLA_SUCCESS
;
733 src
= QLA83XX_BOOTLOADER_FLASH_ADDR
;
734 dest
= qla4_83xx_rd_reg(ha
, QLA83XX_BOOTLOADER_ADDR
);
735 size
= qla4_83xx_rd_reg(ha
, QLA83XX_BOOTLOADER_SIZE
);
737 /* 128 bit alignment check */
739 size
= (size
+ 16) & ~0xF;
744 p_cache
= vmalloc(size
);
745 if (p_cache
== NULL
) {
746 ql4_printk(KERN_ERR
, ha
, "%s: Failed to allocate memory for boot loader cache\n",
749 goto exit_copy_bootloader
;
752 ret_val
= qla4_83xx_lockless_flash_read_u32(ha
, src
, p_cache
,
753 size
/ sizeof(uint32_t));
754 if (ret_val
== QLA_ERROR
) {
755 ql4_printk(KERN_ERR
, ha
, "%s: Error reading firmware from flash\n",
757 goto exit_copy_error
;
759 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: Read firmware from flash\n",
762 /* 128 bit/16 byte write to MS memory */
763 ret_val
= qla4_83xx_ms_mem_write_128b(ha
, dest
, (uint32_t *)p_cache
,
765 if (ret_val
== QLA_ERROR
) {
766 ql4_printk(KERN_ERR
, ha
, "%s: Error writing firmware to MS\n",
768 goto exit_copy_error
;
771 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: Wrote firmware size %d to MS\n",
777 exit_copy_bootloader
:
781 static int qla4_83xx_check_cmd_peg_status(struct scsi_qla_host
*ha
)
783 uint32_t val
, ret_val
= QLA_ERROR
;
784 int retries
= CRB_CMDPEG_CHECK_RETRY_COUNT
;
787 val
= qla4_83xx_rd_reg(ha
, QLA83XX_CMDPEG_STATE
);
788 if (val
== PHAN_INITIALIZE_COMPLETE
) {
789 DEBUG2(ql4_printk(KERN_INFO
, ha
,
790 "%s: Command Peg initialization complete. State=0x%x\n",
792 ret_val
= QLA_SUCCESS
;
795 msleep(CRB_CMDPEG_CHECK_DELAY
);
802 * qla4_83xx_poll_reg - Poll the given CRB addr for duration msecs till
803 * value read ANDed with test_mask is equal to test_result.
805 * @ha : Pointer to adapter structure
806 * @addr : CRB register address
807 * @duration : Poll for total of "duration" msecs
808 * @test_mask : Mask value read with "test_mask"
809 * @test_result : Compare (value&test_mask) with test_result.
811 static int qla4_83xx_poll_reg(struct scsi_qla_host
*ha
, uint32_t addr
,
812 int duration
, uint32_t test_mask
,
813 uint32_t test_result
)
817 int ret_val
= QLA_SUCCESS
;
819 ret_val
= qla4_83xx_rd_reg_indirect(ha
, addr
, &value
);
820 if (ret_val
== QLA_ERROR
)
823 retries
= duration
/ 10;
825 if ((value
& test_mask
) != test_result
) {
826 msleep(duration
/ 10);
827 ret_val
= qla4_83xx_rd_reg_indirect(ha
, addr
, &value
);
828 if (ret_val
== QLA_ERROR
)
833 ret_val
= QLA_SUCCESS
;
839 if (ret_val
== QLA_ERROR
) {
840 ha
->reset_tmplt
.seq_error
++;
841 ql4_printk(KERN_ERR
, ha
, "%s: Poll Failed: 0x%08x 0x%08x 0x%08x\n",
842 __func__
, value
, test_mask
, test_result
);
848 static int qla4_83xx_reset_seq_checksum_test(struct scsi_qla_host
*ha
)
851 uint16_t *buff
= (uint16_t *)ha
->reset_tmplt
.buff
;
852 int u16_count
= ha
->reset_tmplt
.hdr
->size
/ sizeof(uint16_t);
855 while (u16_count
-- > 0)
859 sum
= (sum
& 0xFFFF) + (sum
>> 16);
861 /* checksum of 0 indicates a valid template */
863 ret_val
= QLA_SUCCESS
;
865 ql4_printk(KERN_ERR
, ha
, "%s: Reset seq checksum failed\n",
874 * qla4_83xx_read_reset_template - Read Reset Template from Flash
875 * @ha: Pointer to adapter structure
877 void qla4_83xx_read_reset_template(struct scsi_qla_host
*ha
)
880 uint32_t addr
, tmplt_hdr_def_size
, tmplt_hdr_size
;
883 ha
->reset_tmplt
.seq_error
= 0;
884 ha
->reset_tmplt
.buff
= vmalloc(QLA83XX_RESTART_TEMPLATE_SIZE
);
885 if (ha
->reset_tmplt
.buff
== NULL
) {
886 ql4_printk(KERN_ERR
, ha
, "%s: Failed to allocate reset template resources\n",
888 goto exit_read_reset_template
;
891 p_buff
= ha
->reset_tmplt
.buff
;
892 addr
= QLA83XX_RESET_TEMPLATE_ADDR
;
894 tmplt_hdr_def_size
= sizeof(struct qla4_83xx_reset_template_hdr
) /
897 DEBUG2(ql4_printk(KERN_INFO
, ha
,
898 "%s: Read template hdr size %d from Flash\n",
899 __func__
, tmplt_hdr_def_size
));
901 /* Copy template header from flash */
902 ret_val
= qla4_83xx_flash_read_u32(ha
, addr
, p_buff
,
904 if (ret_val
!= QLA_SUCCESS
) {
905 ql4_printk(KERN_ERR
, ha
, "%s: Failed to read reset template\n",
907 goto exit_read_template_error
;
910 ha
->reset_tmplt
.hdr
=
911 (struct qla4_83xx_reset_template_hdr
*)ha
->reset_tmplt
.buff
;
913 /* Validate the template header size and signature */
914 tmplt_hdr_size
= ha
->reset_tmplt
.hdr
->hdr_size
/sizeof(uint32_t);
915 if ((tmplt_hdr_size
!= tmplt_hdr_def_size
) ||
916 (ha
->reset_tmplt
.hdr
->signature
!= RESET_TMPLT_HDR_SIGNATURE
)) {
917 ql4_printk(KERN_ERR
, ha
, "%s: Template Header size %d is invalid, tmplt_hdr_def_size %d\n",
918 __func__
, tmplt_hdr_size
, tmplt_hdr_def_size
);
919 goto exit_read_template_error
;
922 addr
= QLA83XX_RESET_TEMPLATE_ADDR
+ ha
->reset_tmplt
.hdr
->hdr_size
;
923 p_buff
= ha
->reset_tmplt
.buff
+ ha
->reset_tmplt
.hdr
->hdr_size
;
924 tmplt_hdr_def_size
= (ha
->reset_tmplt
.hdr
->size
-
925 ha
->reset_tmplt
.hdr
->hdr_size
) / sizeof(uint32_t);
927 DEBUG2(ql4_printk(KERN_INFO
, ha
,
928 "%s: Read rest of the template size %d\n",
929 __func__
, ha
->reset_tmplt
.hdr
->size
));
931 /* Copy rest of the template */
932 ret_val
= qla4_83xx_flash_read_u32(ha
, addr
, p_buff
,
934 if (ret_val
!= QLA_SUCCESS
) {
935 ql4_printk(KERN_ERR
, ha
, "%s: Failed to read reset tempelate\n",
937 goto exit_read_template_error
;
940 /* Integrity check */
941 if (qla4_83xx_reset_seq_checksum_test(ha
)) {
942 ql4_printk(KERN_ERR
, ha
, "%s: Reset Seq checksum failed!\n",
944 goto exit_read_template_error
;
946 DEBUG2(ql4_printk(KERN_INFO
, ha
,
947 "%s: Reset Seq checksum passed, Get stop, start and init seq offsets\n",
950 /* Get STOP, START, INIT sequence offsets */
951 ha
->reset_tmplt
.init_offset
= ha
->reset_tmplt
.buff
+
952 ha
->reset_tmplt
.hdr
->init_seq_offset
;
953 ha
->reset_tmplt
.start_offset
= ha
->reset_tmplt
.buff
+
954 ha
->reset_tmplt
.hdr
->start_seq_offset
;
955 ha
->reset_tmplt
.stop_offset
= ha
->reset_tmplt
.buff
+
956 ha
->reset_tmplt
.hdr
->hdr_size
;
957 qla4_83xx_dump_reset_seq_hdr(ha
);
959 goto exit_read_reset_template
;
961 exit_read_template_error
:
962 vfree(ha
->reset_tmplt
.buff
);
964 exit_read_reset_template
:
969 * qla4_83xx_read_write_crb_reg - Read from raddr and write value to waddr.
971 * @ha : Pointer to adapter structure
972 * @raddr : CRB address to read from
973 * @waddr : CRB address to write to
975 static void qla4_83xx_read_write_crb_reg(struct scsi_qla_host
*ha
,
976 uint32_t raddr
, uint32_t waddr
)
980 qla4_83xx_rd_reg_indirect(ha
, raddr
, &value
);
981 qla4_83xx_wr_reg_indirect(ha
, waddr
, value
);
985 * qla4_83xx_rmw_crb_reg - Read Modify Write crb register
987 * This function read value from raddr, AND with test_mask,
988 * Shift Left,Right/OR/XOR with values RMW header and write value to waddr.
990 * @ha : Pointer to adapter structure
991 * @raddr : CRB address to read from
992 * @waddr : CRB address to write to
993 * @p_rmw_hdr : header with shift/or/xor values.
995 static void qla4_83xx_rmw_crb_reg(struct scsi_qla_host
*ha
, uint32_t raddr
,
997 struct qla4_83xx_rmw
*p_rmw_hdr
)
1001 if (p_rmw_hdr
->index_a
)
1002 value
= ha
->reset_tmplt
.array
[p_rmw_hdr
->index_a
];
1004 qla4_83xx_rd_reg_indirect(ha
, raddr
, &value
);
1006 value
&= p_rmw_hdr
->test_mask
;
1007 value
<<= p_rmw_hdr
->shl
;
1008 value
>>= p_rmw_hdr
->shr
;
1009 value
|= p_rmw_hdr
->or_value
;
1010 value
^= p_rmw_hdr
->xor_value
;
1012 qla4_83xx_wr_reg_indirect(ha
, waddr
, value
);
1017 static void qla4_83xx_write_list(struct scsi_qla_host
*ha
,
1018 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
1020 struct qla4_83xx_entry
*p_entry
;
1023 p_entry
= (struct qla4_83xx_entry
*)
1024 ((char *)p_hdr
+ sizeof(struct qla4_83xx_reset_entry_hdr
));
1026 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
1027 qla4_83xx_wr_reg_indirect(ha
, p_entry
->arg1
, p_entry
->arg2
);
1029 udelay((uint32_t)(p_hdr
->delay
));
1033 static void qla4_83xx_read_write_list(struct scsi_qla_host
*ha
,
1034 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
1036 struct qla4_83xx_entry
*p_entry
;
1039 p_entry
= (struct qla4_83xx_entry
*)
1040 ((char *)p_hdr
+ sizeof(struct qla4_83xx_reset_entry_hdr
));
1042 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
1043 qla4_83xx_read_write_crb_reg(ha
, p_entry
->arg1
, p_entry
->arg2
);
1045 udelay((uint32_t)(p_hdr
->delay
));
1049 static void qla4_83xx_poll_list(struct scsi_qla_host
*ha
,
1050 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
1053 struct qla4_83xx_entry
*p_entry
;
1054 struct qla4_83xx_poll
*p_poll
;
1058 p_poll
= (struct qla4_83xx_poll
*)
1059 ((char *)p_hdr
+ sizeof(struct qla4_83xx_reset_entry_hdr
));
1061 /* Entries start after 8 byte qla4_83xx_poll, poll header contains
1062 * the test_mask, test_value. */
1063 p_entry
= (struct qla4_83xx_entry
*)((char *)p_poll
+
1064 sizeof(struct qla4_83xx_poll
));
1066 delay
= (long)p_hdr
->delay
;
1068 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
1069 qla4_83xx_poll_reg(ha
, p_entry
->arg1
, delay
,
1071 p_poll
->test_value
);
1074 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
1075 if (qla4_83xx_poll_reg(ha
, p_entry
->arg1
, delay
,
1077 p_poll
->test_value
)) {
1078 qla4_83xx_rd_reg_indirect(ha
, p_entry
->arg1
,
1080 qla4_83xx_rd_reg_indirect(ha
, p_entry
->arg2
,
1087 static void qla4_83xx_poll_write_list(struct scsi_qla_host
*ha
,
1088 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
1091 struct qla4_83xx_quad_entry
*p_entry
;
1092 struct qla4_83xx_poll
*p_poll
;
1095 p_poll
= (struct qla4_83xx_poll
*)
1096 ((char *)p_hdr
+ sizeof(struct qla4_83xx_reset_entry_hdr
));
1097 p_entry
= (struct qla4_83xx_quad_entry
*)
1098 ((char *)p_poll
+ sizeof(struct qla4_83xx_poll
));
1099 delay
= (long)p_hdr
->delay
;
1101 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
1102 qla4_83xx_wr_reg_indirect(ha
, p_entry
->dr_addr
,
1104 qla4_83xx_wr_reg_indirect(ha
, p_entry
->ar_addr
,
1107 if (qla4_83xx_poll_reg(ha
, p_entry
->ar_addr
, delay
,
1109 p_poll
->test_value
)) {
1110 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1111 "%s: Timeout Error: poll list, item_num %d, entry_num %d\n",
1113 ha
->reset_tmplt
.seq_index
));
1119 static void qla4_83xx_read_modify_write(struct scsi_qla_host
*ha
,
1120 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
1122 struct qla4_83xx_entry
*p_entry
;
1123 struct qla4_83xx_rmw
*p_rmw_hdr
;
1126 p_rmw_hdr
= (struct qla4_83xx_rmw
*)
1127 ((char *)p_hdr
+ sizeof(struct qla4_83xx_reset_entry_hdr
));
1128 p_entry
= (struct qla4_83xx_entry
*)
1129 ((char *)p_rmw_hdr
+ sizeof(struct qla4_83xx_rmw
));
1131 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
1132 qla4_83xx_rmw_crb_reg(ha
, p_entry
->arg1
, p_entry
->arg2
,
1135 udelay((uint32_t)(p_hdr
->delay
));
1139 static void qla4_83xx_pause(struct scsi_qla_host
*ha
,
1140 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
1143 mdelay((uint32_t)((long)p_hdr
->delay
));
1146 static void qla4_83xx_poll_read_list(struct scsi_qla_host
*ha
,
1147 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
1151 struct qla4_83xx_quad_entry
*p_entry
;
1152 struct qla4_83xx_poll
*p_poll
;
1156 p_poll
= (struct qla4_83xx_poll
*)
1157 ((char *)p_hdr
+ sizeof(struct qla4_83xx_reset_entry_hdr
));
1158 p_entry
= (struct qla4_83xx_quad_entry
*)
1159 ((char *)p_poll
+ sizeof(struct qla4_83xx_poll
));
1160 delay
= (long)p_hdr
->delay
;
1162 for (i
= 0; i
< p_hdr
->count
; i
++, p_entry
++) {
1163 qla4_83xx_wr_reg_indirect(ha
, p_entry
->ar_addr
,
1166 if (qla4_83xx_poll_reg(ha
, p_entry
->ar_addr
, delay
,
1168 p_poll
->test_value
)) {
1169 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1170 "%s: Timeout Error: poll list, Item_num %d, entry_num %d\n",
1172 ha
->reset_tmplt
.seq_index
));
1174 index
= ha
->reset_tmplt
.array_index
;
1175 qla4_83xx_rd_reg_indirect(ha
, p_entry
->dr_addr
,
1177 ha
->reset_tmplt
.array
[index
++] = value
;
1179 if (index
== QLA83XX_MAX_RESET_SEQ_ENTRIES
)
1180 ha
->reset_tmplt
.array_index
= 1;
1186 static void qla4_83xx_seq_end(struct scsi_qla_host
*ha
,
1187 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
1189 ha
->reset_tmplt
.seq_end
= 1;
1192 static void qla4_83xx_template_end(struct scsi_qla_host
*ha
,
1193 struct qla4_83xx_reset_entry_hdr
*p_hdr
)
1195 ha
->reset_tmplt
.template_end
= 1;
1197 if (ha
->reset_tmplt
.seq_error
== 0) {
1198 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1199 "%s: Reset sequence completed SUCCESSFULLY.\n",
1202 ql4_printk(KERN_ERR
, ha
, "%s: Reset sequence completed with some timeout errors.\n",
1208 * qla4_83xx_process_reset_template - Process reset template.
1210 * Process all entries in reset template till entry with SEQ_END opcode,
1211 * which indicates end of the reset template processing. Each entry has a
1212 * Reset Entry header, entry opcode/command, with size of the entry, number
1213 * of entries in sub-sequence and delay in microsecs or timeout in millisecs.
1215 * @ha : Pointer to adapter structure
1216 * @p_buff : Common reset entry header.
1218 static void qla4_83xx_process_reset_template(struct scsi_qla_host
*ha
,
1222 struct qla4_83xx_reset_entry_hdr
*p_hdr
;
1223 char *p_entry
= p_buff
;
1225 ha
->reset_tmplt
.seq_end
= 0;
1226 ha
->reset_tmplt
.template_end
= 0;
1227 entries
= ha
->reset_tmplt
.hdr
->entries
;
1228 index
= ha
->reset_tmplt
.seq_index
;
1230 for (; (!ha
->reset_tmplt
.seq_end
) && (index
< entries
); index
++) {
1232 p_hdr
= (struct qla4_83xx_reset_entry_hdr
*)p_entry
;
1233 switch (p_hdr
->cmd
) {
1236 case OPCODE_WRITE_LIST
:
1237 qla4_83xx_write_list(ha
, p_hdr
);
1239 case OPCODE_READ_WRITE_LIST
:
1240 qla4_83xx_read_write_list(ha
, p_hdr
);
1242 case OPCODE_POLL_LIST
:
1243 qla4_83xx_poll_list(ha
, p_hdr
);
1245 case OPCODE_POLL_WRITE_LIST
:
1246 qla4_83xx_poll_write_list(ha
, p_hdr
);
1248 case OPCODE_READ_MODIFY_WRITE
:
1249 qla4_83xx_read_modify_write(ha
, p_hdr
);
1251 case OPCODE_SEQ_PAUSE
:
1252 qla4_83xx_pause(ha
, p_hdr
);
1254 case OPCODE_SEQ_END
:
1255 qla4_83xx_seq_end(ha
, p_hdr
);
1257 case OPCODE_TMPL_END
:
1258 qla4_83xx_template_end(ha
, p_hdr
);
1260 case OPCODE_POLL_READ_LIST
:
1261 qla4_83xx_poll_read_list(ha
, p_hdr
);
1264 ql4_printk(KERN_ERR
, ha
, "%s: Unknown command ==> 0x%04x on entry = %d\n",
1265 __func__
, p_hdr
->cmd
, index
);
1269 /* Set pointer to next entry in the sequence. */
1270 p_entry
+= p_hdr
->size
;
1273 ha
->reset_tmplt
.seq_index
= index
;
1276 static void qla4_83xx_process_stop_seq(struct scsi_qla_host
*ha
)
1278 ha
->reset_tmplt
.seq_index
= 0;
1279 qla4_83xx_process_reset_template(ha
, ha
->reset_tmplt
.stop_offset
);
1281 if (ha
->reset_tmplt
.seq_end
!= 1)
1282 ql4_printk(KERN_ERR
, ha
, "%s: Abrupt STOP Sub-Sequence end.\n",
1286 static void qla4_83xx_process_start_seq(struct scsi_qla_host
*ha
)
1288 qla4_83xx_process_reset_template(ha
, ha
->reset_tmplt
.start_offset
);
1290 if (ha
->reset_tmplt
.template_end
!= 1)
1291 ql4_printk(KERN_ERR
, ha
, "%s: Abrupt START Sub-Sequence end.\n",
1295 static void qla4_83xx_process_init_seq(struct scsi_qla_host
*ha
)
1297 qla4_83xx_process_reset_template(ha
, ha
->reset_tmplt
.init_offset
);
1299 if (ha
->reset_tmplt
.seq_end
!= 1)
1300 ql4_printk(KERN_ERR
, ha
, "%s: Abrupt INIT Sub-Sequence end.\n",
1304 static int qla4_83xx_restart(struct scsi_qla_host
*ha
)
1306 int ret_val
= QLA_SUCCESS
;
1308 qla4_83xx_process_stop_seq(ha
);
1310 /* Collect minidump*/
1311 if (!test_and_clear_bit(AF_83XX_NO_FW_DUMP
, &ha
->flags
))
1312 qla4_8xxx_get_minidump(ha
);
1314 qla4_83xx_process_init_seq(ha
);
1316 if (qla4_83xx_copy_bootloader(ha
)) {
1317 ql4_printk(KERN_ERR
, ha
, "%s: Copy bootloader, firmware restart failed!\n",
1319 ret_val
= QLA_ERROR
;
1323 qla4_83xx_wr_reg(ha
, QLA83XX_FW_IMAGE_VALID
, QLA83XX_BOOT_FROM_FLASH
);
1324 qla4_83xx_process_start_seq(ha
);
1330 int qla4_83xx_start_firmware(struct scsi_qla_host
*ha
)
1332 int ret_val
= QLA_SUCCESS
;
1334 ret_val
= qla4_83xx_restart(ha
);
1335 if (ret_val
== QLA_ERROR
) {
1336 ql4_printk(KERN_ERR
, ha
, "%s: Restart error\n", __func__
);
1339 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: Restart done\n",
1343 ret_val
= qla4_83xx_check_cmd_peg_status(ha
);
1344 if (ret_val
== QLA_ERROR
)
1345 ql4_printk(KERN_ERR
, ha
, "%s: Peg not initialized\n",
1352 /*----------------------Interrupt Related functions ---------------------*/
1354 static void qla4_83xx_disable_iocb_intrs(struct scsi_qla_host
*ha
)
1356 if (test_and_clear_bit(AF_83XX_IOCB_INTR_ON
, &ha
->flags
))
1357 qla4_8xxx_intr_disable(ha
);
1360 static void qla4_83xx_disable_mbox_intrs(struct scsi_qla_host
*ha
)
1362 uint32_t mb_int
, ret
;
1364 if (test_and_clear_bit(AF_83XX_MBOX_INTR_ON
, &ha
->flags
)) {
1365 ret
= readl(&ha
->qla4_83xx_reg
->mbox_int
);
1366 mb_int
= ret
& ~INT_ENABLE_FW_MB
;
1367 writel(mb_int
, &ha
->qla4_83xx_reg
->mbox_int
);
1368 writel(1, &ha
->qla4_83xx_reg
->leg_int_mask
);
1372 void qla4_83xx_disable_intrs(struct scsi_qla_host
*ha
)
1374 qla4_83xx_disable_mbox_intrs(ha
);
1375 qla4_83xx_disable_iocb_intrs(ha
);
1378 static void qla4_83xx_enable_iocb_intrs(struct scsi_qla_host
*ha
)
1380 if (!test_bit(AF_83XX_IOCB_INTR_ON
, &ha
->flags
)) {
1381 qla4_8xxx_intr_enable(ha
);
1382 set_bit(AF_83XX_IOCB_INTR_ON
, &ha
->flags
);
1386 void qla4_83xx_enable_mbox_intrs(struct scsi_qla_host
*ha
)
1390 if (!test_bit(AF_83XX_MBOX_INTR_ON
, &ha
->flags
)) {
1391 mb_int
= INT_ENABLE_FW_MB
;
1392 writel(mb_int
, &ha
->qla4_83xx_reg
->mbox_int
);
1393 writel(0, &ha
->qla4_83xx_reg
->leg_int_mask
);
1394 set_bit(AF_83XX_MBOX_INTR_ON
, &ha
->flags
);
1399 void qla4_83xx_enable_intrs(struct scsi_qla_host
*ha
)
1401 qla4_83xx_enable_mbox_intrs(ha
);
1402 qla4_83xx_enable_iocb_intrs(ha
);
1406 void qla4_83xx_queue_mbox_cmd(struct scsi_qla_host
*ha
, uint32_t *mbx_cmd
,
1411 /* Load all mailbox registers, except mailbox 0. */
1412 for (i
= 1; i
< incount
; i
++)
1413 writel(mbx_cmd
[i
], &ha
->qla4_83xx_reg
->mailbox_in
[i
]);
1415 writel(mbx_cmd
[0], &ha
->qla4_83xx_reg
->mailbox_in
[0]);
1417 /* Set Host Interrupt register to 1, to tell the firmware that
1418 * a mailbox command is pending. Firmware after reading the
1419 * mailbox command, clears the host interrupt register */
1420 writel(HINT_MBX_INT_PENDING
, &ha
->qla4_83xx_reg
->host_intr
);
1423 void qla4_83xx_process_mbox_intr(struct scsi_qla_host
*ha
, int outcount
)
1427 intr_status
= readl(&ha
->qla4_83xx_reg
->risc_intr
);
1429 ha
->mbox_status_count
= outcount
;
1430 ha
->isp_ops
->interrupt_service_routine(ha
, intr_status
);
1435 * qla4_83xx_isp_reset - Resets ISP and aborts all outstanding commands.
1436 * @ha: pointer to host adapter structure.
1438 int qla4_83xx_isp_reset(struct scsi_qla_host
*ha
)
1443 ha
->isp_ops
->idc_lock(ha
);
1444 dev_state
= qla4_8xxx_rd_direct(ha
, QLA8XXX_CRB_DEV_STATE
);
1446 if (ql4xdontresethba
)
1447 qla4_83xx_set_idc_dontreset(ha
);
1449 if (dev_state
== QLA8XXX_DEV_READY
) {
1450 /* If IDC_CTRL DONTRESETHBA_BIT0 is set dont do reset
1452 if (qla4_83xx_idc_dontreset(ha
) == DONTRESET_BIT0
) {
1453 ql4_printk(KERN_ERR
, ha
, "%s: Reset recovery disabled\n",
1456 goto exit_isp_reset
;
1459 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: HW State: NEED RESET\n",
1461 qla4_8xxx_wr_direct(ha
, QLA8XXX_CRB_DEV_STATE
,
1462 QLA8XXX_DEV_NEED_RESET
);
1465 /* If device_state is NEED_RESET, go ahead with
1466 * Reset,irrespective of ql4xdontresethba. This is to allow a
1467 * non-reset-owner to force a reset. Non-reset-owner sets
1468 * the IDC_CTRL BIT0 to prevent Reset-owner from doing a Reset
1469 * and then forces a Reset by setting device_state to
1471 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1472 "%s: HW state already set to NEED_RESET\n",
1476 /* For ISP8324 and ISP8042, Reset owner is NIC, iSCSI or FCOE based on
1477 * priority and which drivers are present. Unlike ISP8022, the function
1478 * setting NEED_RESET, may not be the Reset owner. */
1479 if (qla4_83xx_can_perform_reset(ha
))
1480 set_bit(AF_8XXX_RST_OWNER
, &ha
->flags
);
1482 ha
->isp_ops
->idc_unlock(ha
);
1483 rval
= qla4_8xxx_device_state_handler(ha
);
1485 ha
->isp_ops
->idc_lock(ha
);
1486 qla4_8xxx_clear_rst_ready(ha
);
1488 ha
->isp_ops
->idc_unlock(ha
);
1490 if (rval
== QLA_SUCCESS
)
1491 clear_bit(AF_FW_RECOVERY
, &ha
->flags
);
1496 static void qla4_83xx_dump_pause_control_regs(struct scsi_qla_host
*ha
)
1498 u32 val
= 0, val1
= 0;
1499 int i
, status
= QLA_SUCCESS
;
1501 status
= qla4_83xx_rd_reg_indirect(ha
, QLA83XX_SRE_SHIM_CONTROL
, &val
);
1502 DEBUG2(ql4_printk(KERN_INFO
, ha
, "SRE-Shim Ctrl:0x%x\n", val
));
1504 /* Port 0 Rx Buffer Pause Threshold Registers. */
1505 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1506 "Port 0 Rx Buffer Pause Threshold Registers[TC7..TC0]:"));
1507 for (i
= 0; i
< 8; i
++) {
1508 status
= qla4_83xx_rd_reg_indirect(ha
,
1509 QLA83XX_PORT0_RXB_PAUSE_THRS
+ (i
* 0x4), &val
);
1510 DEBUG2(pr_info("0x%x ", val
));
1513 DEBUG2(pr_info("\n"));
1515 /* Port 1 Rx Buffer Pause Threshold Registers. */
1516 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1517 "Port 1 Rx Buffer Pause Threshold Registers[TC7..TC0]:"));
1518 for (i
= 0; i
< 8; i
++) {
1519 status
= qla4_83xx_rd_reg_indirect(ha
,
1520 QLA83XX_PORT1_RXB_PAUSE_THRS
+ (i
* 0x4), &val
);
1521 DEBUG2(pr_info("0x%x ", val
));
1524 DEBUG2(pr_info("\n"));
1526 /* Port 0 RxB Traffic Class Max Cell Registers. */
1527 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1528 "Port 0 RxB Traffic Class Max Cell Registers[3..0]:"));
1529 for (i
= 0; i
< 4; i
++) {
1530 status
= qla4_83xx_rd_reg_indirect(ha
,
1531 QLA83XX_PORT0_RXB_TC_MAX_CELL
+ (i
* 0x4), &val
);
1532 DEBUG2(pr_info("0x%x ", val
));
1535 DEBUG2(pr_info("\n"));
1537 /* Port 1 RxB Traffic Class Max Cell Registers. */
1538 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1539 "Port 1 RxB Traffic Class Max Cell Registers[3..0]:"));
1540 for (i
= 0; i
< 4; i
++) {
1541 status
= qla4_83xx_rd_reg_indirect(ha
,
1542 QLA83XX_PORT1_RXB_TC_MAX_CELL
+ (i
* 0x4), &val
);
1543 DEBUG2(pr_info("0x%x ", val
));
1546 DEBUG2(pr_info("\n"));
1548 /* Port 0 RxB Rx Traffic Class Stats. */
1549 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1550 "Port 0 RxB Rx Traffic Class Stats [TC7..TC0]"));
1551 for (i
= 7; i
>= 0; i
--) {
1552 status
= qla4_83xx_rd_reg_indirect(ha
,
1553 QLA83XX_PORT0_RXB_TC_STATS
,
1555 val
&= ~(0x7 << 29); /* Reset bits 29 to 31 */
1556 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_PORT0_RXB_TC_STATS
,
1558 status
= qla4_83xx_rd_reg_indirect(ha
,
1559 QLA83XX_PORT0_RXB_TC_STATS
,
1561 DEBUG2(pr_info("0x%x ", val
));
1564 DEBUG2(pr_info("\n"));
1566 /* Port 1 RxB Rx Traffic Class Stats. */
1567 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1568 "Port 1 RxB Rx Traffic Class Stats [TC7..TC0]"));
1569 for (i
= 7; i
>= 0; i
--) {
1570 status
= qla4_83xx_rd_reg_indirect(ha
,
1571 QLA83XX_PORT1_RXB_TC_STATS
,
1573 val
&= ~(0x7 << 29); /* Reset bits 29 to 31 */
1574 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_PORT1_RXB_TC_STATS
,
1576 status
= qla4_83xx_rd_reg_indirect(ha
,
1577 QLA83XX_PORT1_RXB_TC_STATS
,
1579 DEBUG2(pr_info("0x%x ", val
));
1582 DEBUG2(pr_info("\n"));
1584 status
= qla4_83xx_rd_reg_indirect(ha
, QLA83XX_PORT2_IFB_PAUSE_THRS
,
1586 status
= qla4_83xx_rd_reg_indirect(ha
, QLA83XX_PORT3_IFB_PAUSE_THRS
,
1589 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1590 "IFB-Pause Thresholds: Port 2:0x%x, Port 3:0x%x\n",
1594 static void __qla4_83xx_disable_pause(struct scsi_qla_host
*ha
)
1598 /* set SRE-Shim Control Register */
1599 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_SRE_SHIM_CONTROL
,
1600 QLA83XX_SET_PAUSE_VAL
);
1602 for (i
= 0; i
< 8; i
++) {
1603 /* Port 0 Rx Buffer Pause Threshold Registers. */
1604 qla4_83xx_wr_reg_indirect(ha
,
1605 QLA83XX_PORT0_RXB_PAUSE_THRS
+ (i
* 0x4),
1606 QLA83XX_SET_PAUSE_VAL
);
1607 /* Port 1 Rx Buffer Pause Threshold Registers. */
1608 qla4_83xx_wr_reg_indirect(ha
,
1609 QLA83XX_PORT1_RXB_PAUSE_THRS
+ (i
* 0x4),
1610 QLA83XX_SET_PAUSE_VAL
);
1613 for (i
= 0; i
< 4; i
++) {
1614 /* Port 0 RxB Traffic Class Max Cell Registers. */
1615 qla4_83xx_wr_reg_indirect(ha
,
1616 QLA83XX_PORT0_RXB_TC_MAX_CELL
+ (i
* 0x4),
1617 QLA83XX_SET_TC_MAX_CELL_VAL
);
1618 /* Port 1 RxB Traffic Class Max Cell Registers. */
1619 qla4_83xx_wr_reg_indirect(ha
,
1620 QLA83XX_PORT1_RXB_TC_MAX_CELL
+ (i
* 0x4),
1621 QLA83XX_SET_TC_MAX_CELL_VAL
);
1624 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_PORT2_IFB_PAUSE_THRS
,
1625 QLA83XX_SET_PAUSE_VAL
);
1626 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_PORT3_IFB_PAUSE_THRS
,
1627 QLA83XX_SET_PAUSE_VAL
);
1629 ql4_printk(KERN_INFO
, ha
, "Disabled pause frames successfully.\n");
1633 * qla4_83xx_eport_init - Initialize EPort.
1634 * @ha: Pointer to host adapter structure.
1636 * If EPort hardware is in reset state before disabling pause, there would be
1637 * serious hardware wedging issues. To prevent this perform eport init everytime
1638 * before disabling pause frames.
1640 static void qla4_83xx_eport_init(struct scsi_qla_host
*ha
)
1642 /* Clear the 8 registers */
1643 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_REG
, 0x0);
1644 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_PORT0
, 0x0);
1645 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_PORT1
, 0x0);
1646 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_PORT2
, 0x0);
1647 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_PORT3
, 0x0);
1648 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_SRE_SHIM
, 0x0);
1649 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_EPG_SHIM
, 0x0);
1650 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_ETHER_PCS
, 0x0);
1652 /* Write any value to Reset Control register */
1653 qla4_83xx_wr_reg_indirect(ha
, QLA83XX_RESET_CONTROL
, 0xFF);
1655 ql4_printk(KERN_INFO
, ha
, "EPORT is out of reset.\n");
1658 void qla4_83xx_disable_pause(struct scsi_qla_host
*ha
)
1660 ha
->isp_ops
->idc_lock(ha
);
1661 /* Before disabling pause frames, ensure that eport is not in reset */
1662 qla4_83xx_eport_init(ha
);
1663 qla4_83xx_dump_pause_control_regs(ha
);
1664 __qla4_83xx_disable_pause(ha
);
1665 ha
->isp_ops
->idc_unlock(ha
);