2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2004 QLogic Corporation
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
21 #include <linux/delay.h>
23 #include "qla_devtbl.h"
25 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
26 #ifndef EXT_IS_LUN_BIT_SET
27 #define EXT_IS_LUN_BIT_SET(P,L) \
28 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
29 #define EXT_SET_LUN_BIT(P,L) \
30 ((P)->mask[L/8] |= (0x80 >> (L%8)))
34 * QLogic ISP2x00 Hardware Support Function Prototypes.
36 static int qla2x00_pci_config(scsi_qla_host_t
*);
37 static int qla2x00_isp_firmware(scsi_qla_host_t
*);
38 static void qla2x00_reset_chip(scsi_qla_host_t
*);
39 static int qla2x00_chip_diag(scsi_qla_host_t
*);
40 static void qla2x00_resize_request_q(scsi_qla_host_t
*);
41 static int qla2x00_setup_chip(scsi_qla_host_t
*);
42 static void qla2x00_init_response_q_entries(scsi_qla_host_t
*);
43 static int qla2x00_init_rings(scsi_qla_host_t
*);
44 static int qla2x00_fw_ready(scsi_qla_host_t
*);
45 static int qla2x00_configure_hba(scsi_qla_host_t
*);
46 static int qla2x00_nvram_config(scsi_qla_host_t
*);
47 static void qla2x00_init_tgt_map(scsi_qla_host_t
*);
48 static int qla2x00_configure_loop(scsi_qla_host_t
*);
49 static int qla2x00_configure_local_loop(scsi_qla_host_t
*);
50 static void qla2x00_update_fcport(scsi_qla_host_t
*, fc_port_t
*);
51 static void qla2x00_lun_discovery(scsi_qla_host_t
*, fc_port_t
*);
52 static int qla2x00_rpt_lun_discovery(scsi_qla_host_t
*, fc_port_t
*,
53 inq_cmd_rsp_t
*, dma_addr_t
);
54 static int qla2x00_report_lun(scsi_qla_host_t
*, fc_port_t
*);
55 static fc_lun_t
*qla2x00_cfg_lun(scsi_qla_host_t
*, fc_port_t
*, uint16_t,
56 inq_cmd_rsp_t
*, dma_addr_t
);
57 static fc_lun_t
* qla2x00_add_lun(fc_port_t
*, uint16_t);
58 static int qla2x00_inquiry(scsi_qla_host_t
*, fc_port_t
*, uint16_t,
59 inq_cmd_rsp_t
*, dma_addr_t
);
60 static int qla2x00_configure_fabric(scsi_qla_host_t
*);
61 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t
*, struct list_head
*);
62 static int qla2x00_device_resync(scsi_qla_host_t
*);
63 static int qla2x00_fabric_dev_login(scsi_qla_host_t
*, fc_port_t
*,
65 static void qla2x00_config_os(scsi_qla_host_t
*ha
);
66 static uint16_t qla2x00_fcport_bind(scsi_qla_host_t
*ha
, fc_port_t
*fcport
);
67 static os_lun_t
* qla2x00_fclun_bind(scsi_qla_host_t
*, fc_port_t
*,
69 static void qla2x00_lun_free(scsi_qla_host_t
*, uint16_t, uint16_t);
71 static int qla2x00_restart_isp(scsi_qla_host_t
*);
72 static void qla2x00_reset_adapter(scsi_qla_host_t
*);
73 static os_tgt_t
*qla2x00_tgt_alloc(scsi_qla_host_t
*, uint16_t);
74 static os_lun_t
*qla2x00_lun_alloc(scsi_qla_host_t
*, uint16_t, uint16_t);
76 /****************************************************************************/
77 /* QLogic ISP2x00 Hardware Support Functions. */
78 /****************************************************************************/
81 * qla2x00_initialize_adapter
85 * ha = adapter block pointer.
91 qla2x00_initialize_adapter(scsi_qla_host_t
*ha
)
94 uint8_t restart_risc
= 0;
98 /* Clear adapter flags. */
100 ha
->flags
.reset_active
= 0;
101 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
102 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
103 ha
->device_flags
= 0;
104 ha
->sns_retry_cnt
= 0;
106 ha
->failback_delay
= 0;
107 ha
->flags
.management_server_logged_in
= 0;
108 ha
->marker_needed
= 0;
110 ha
->isp_abort_cnt
= 0;
111 ha
->beacon_blink_led
= 0;
113 rval
= qla2x00_pci_config(ha
);
115 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
120 qla2x00_reset_chip(ha
);
122 /* Initialize target map database. */
123 qla2x00_init_tgt_map(ha
);
125 qla_printk(KERN_INFO
, ha
, "Configure NVRAM parameters...\n");
126 qla2x00_nvram_config(ha
);
128 qla_printk(KERN_INFO
, ha
, "Verifying loaded RISC code...\n");
132 * Try to configure the loop.
137 /* If firmware needs to be loaded */
138 if (qla2x00_isp_firmware(ha
) != QLA_SUCCESS
) {
139 if ((rval
= qla2x00_chip_diag(ha
)) == QLA_SUCCESS
) {
140 rval
= qla2x00_setup_chip(ha
);
144 if (rval
== QLA_SUCCESS
&&
145 (rval
= qla2x00_init_rings(ha
)) == QLA_SUCCESS
) {
146 check_fw_ready_again
:
148 * Wait for a successful LIP up to a maximum
149 * of (in seconds): RISC login timeout value,
150 * RISC retry count value, and port down retry
151 * value OR a minimum of 4 seconds OR If no
152 * cable, only 5 seconds.
154 rval
= qla2x00_fw_ready(ha
);
155 if (rval
== QLA_SUCCESS
) {
156 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
159 * Wait at most MAX_TARGET RSCNs for a stable
164 clear_bit(LOOP_RESYNC_NEEDED
,
166 rval
= qla2x00_configure_loop(ha
);
168 if (test_and_clear_bit(ISP_ABORT_NEEDED
,
175 * If loop state change while we were
176 * discoverying devices then wait for
180 if (atomic_read(&ha
->loop_state
) ==
181 LOOP_DOWN
&& retry
--) {
182 goto check_fw_ready_again
;
185 } while (!atomic_read(&ha
->loop_down_timer
) &&
188 (test_bit(LOOP_RESYNC_NEEDED
,
192 rval
= QLA_FUNCTION_FAILED
;
195 } else if (ha
->device_flags
& DFLG_NO_CABLE
)
196 /* If no cable, then all is good. */
199 } while (restart_risc
&& retry
--);
201 if (rval
== QLA_SUCCESS
) {
202 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
203 ha
->marker_needed
= 1;
204 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
205 ha
->marker_needed
= 0;
207 ha
->flags
.online
= 1;
209 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
216 * qla2x00_pci_config() - Setup device PCI configuration registers.
219 * Returns 0 on success.
222 qla2x00_pci_config(scsi_qla_host_t
*ha
)
225 unsigned long flags
= 0;
228 qla_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
231 * Turn on PCI master; for system BIOSes that don't turn it on by
234 pci_set_master(ha
->pdev
);
236 if (pci_set_mwi(ha
->pdev
))
237 mwi
= PCI_COMMAND_INVALIDATE
;
238 pci_read_config_word(ha
->pdev
, PCI_REVISION_ID
, &ha
->revision
);
241 return (QLA_FUNCTION_FAILED
);
244 * We want to respect framework's setting of PCI configuration space
245 * command register and also want to make sure that all bits of
246 * interest to us are properly set in command register.
248 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
249 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
251 /* Get PCI bus information. */
252 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
253 ha
->pci_attr
= RD_REG_WORD(&ha
->iobase
->ctrl_status
);
254 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
256 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
257 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
259 /* PCI Specification Revision 2.3 changes */
260 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
261 /* Command Register - Reset Interrupt Disable. */
262 w
&= ~PCI_COMMAND_INTX_DISABLE
;
265 * If this is a 2300 card and not 2312, reset the
266 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
267 * the 2310 also reports itself as a 2300 so we need to get the
268 * fb revision level -- a 6 indicates it really is a 2300 and
271 if (IS_QLA2300(ha
)) {
272 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
275 WRT_REG_WORD(&ha
->iobase
->hccr
, HCCR_PAUSE_RISC
);
276 for (cnt
= 0; cnt
< 30000; cnt
++) {
277 if ((RD_REG_WORD(&ha
->iobase
->hccr
) &
278 HCCR_RISC_PAUSE
) != 0)
284 /* Select FPM registers. */
285 WRT_REG_WORD(&ha
->iobase
->ctrl_status
, 0x20);
286 RD_REG_WORD(&ha
->iobase
->ctrl_status
);
288 /* Get the fb rev level */
289 ha
->fb_rev
= RD_FB_CMD_REG(ha
, ha
->iobase
);
291 if (ha
->fb_rev
== FPM_2300
)
292 w
&= ~PCI_COMMAND_INVALIDATE
;
294 /* Deselect FPM registers. */
295 WRT_REG_WORD(&ha
->iobase
->ctrl_status
, 0x0);
296 RD_REG_WORD(&ha
->iobase
->ctrl_status
);
298 /* Release RISC module. */
299 WRT_REG_WORD(&ha
->iobase
->hccr
, HCCR_RELEASE_RISC
);
300 for (cnt
= 0; cnt
< 30000; cnt
++) {
301 if ((RD_REG_WORD(&ha
->iobase
->hccr
) &
302 HCCR_RISC_PAUSE
) == 0)
308 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
312 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
314 /* Reset expansion ROM address decode enable */
315 pci_read_config_word(ha
->pdev
, PCI_ROM_ADDRESS
, &w
);
316 w
&= ~PCI_ROM_ADDRESS_ENABLE
;
317 pci_write_config_word(ha
->pdev
, PCI_ROM_ADDRESS
, w
);
319 return (QLA_SUCCESS
);
323 * qla2x00_isp_firmware() - Choose firmware image.
326 * Returns 0 on success.
329 qla2x00_isp_firmware(scsi_qla_host_t
*ha
)
333 /* Assume loading risc code */
334 rval
= QLA_FUNCTION_FAILED
;
336 if (ha
->flags
.disable_risc_code_load
) {
337 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
339 qla_printk(KERN_INFO
, ha
, "RISC CODE NOT loaded\n");
341 /* Verify checksum of loaded RISC code. */
342 rval
= qla2x00_verify_checksum(ha
);
346 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
354 * qla2x00_reset_chip() - Reset ISP chip.
357 * Returns 0 on success.
360 qla2x00_reset_chip(scsi_qla_host_t
*ha
)
362 unsigned long flags
= 0;
363 device_reg_t __iomem
*reg
= ha
->iobase
;
365 unsigned long mbx_flags
= 0;
368 /* Disable ISP interrupts. */
369 qla2x00_disable_intrs(ha
);
371 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
373 /* Turn off master enable */
375 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
376 cmd
&= ~PCI_COMMAND_MASTER
;
377 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
379 if (!IS_QLA2100(ha
)) {
381 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
382 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
383 for (cnt
= 0; cnt
< 30000; cnt
++) {
384 if ((RD_REG_WORD(®
->hccr
) &
385 HCCR_RISC_PAUSE
) != 0)
390 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
394 /* Select FPM registers. */
395 WRT_REG_WORD(®
->ctrl_status
, 0x20);
396 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
398 /* FPM Soft Reset. */
399 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
400 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
402 /* Toggle Fpm Reset. */
403 if (!IS_QLA2200(ha
)) {
404 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
405 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
408 /* Select frame buffer registers. */
409 WRT_REG_WORD(®
->ctrl_status
, 0x10);
410 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
412 /* Reset frame buffer FIFOs. */
413 if (IS_QLA2200(ha
)) {
414 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
415 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
417 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
419 /* Read back fb_cmd until zero or 3 seconds max */
420 for (cnt
= 0; cnt
< 3000; cnt
++) {
421 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
427 /* Select RISC module registers. */
428 WRT_REG_WORD(®
->ctrl_status
, 0);
429 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
431 /* Reset RISC processor. */
432 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
433 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
435 /* Release RISC processor. */
436 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
437 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
440 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
441 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
443 /* Reset ISP chip. */
444 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
446 /* Wait for RISC to recover from reset. */
447 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
449 * It is necessary to for a delay here since the card doesn't
450 * respond to PCI reads during a reset. On some architectures
451 * this will result in an MCA.
454 for (cnt
= 30000; cnt
; cnt
--) {
455 if ((RD_REG_WORD(®
->ctrl_status
) &
456 CSR_ISP_SOFT_RESET
) == 0)
463 /* Reset RISC processor. */
464 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
466 WRT_REG_WORD(®
->semaphore
, 0);
468 /* Release RISC processor. */
469 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
470 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
472 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
473 for (cnt
= 0; cnt
< 30000; cnt
++) {
474 if (!(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
)))
475 spin_lock_irqsave(&ha
->mbx_reg_lock
, mbx_flags
);
477 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
) {
478 if (!(test_bit(ABORT_ISP_ACTIVE
,
480 spin_unlock_irqrestore(
481 &ha
->mbx_reg_lock
, mbx_flags
);
485 if (!(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
)))
486 spin_unlock_irqrestore(&ha
->mbx_reg_lock
,
494 /* Turn on master enable */
495 cmd
|= PCI_COMMAND_MASTER
;
496 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
498 /* Disable RISC pause on FPM parity error. */
499 if (!IS_QLA2100(ha
)) {
500 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
501 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
504 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
508 * qla2x00_chip_diag() - Test chip for proper operation.
511 * Returns 0 on success.
514 qla2x00_chip_diag(scsi_qla_host_t
*ha
)
517 device_reg_t __iomem
*reg
= ha
->iobase
;
518 unsigned long flags
= 0;
523 /* Assume a failed state */
524 rval
= QLA_FUNCTION_FAILED
;
526 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
527 ha
->host_no
, (u_long
)®
->flash_address
));
529 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
531 /* Reset ISP chip. */
532 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
535 * We need to have a delay here since the card will not respond while
536 * in reset causing an MCA on some architectures.
539 data
= qla2x00_debounce_register(®
->ctrl_status
);
540 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
542 data
= RD_REG_WORD(®
->ctrl_status
);
547 goto chip_diag_failed
;
549 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
552 /* Reset RISC processor. */
553 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
554 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
556 /* Workaround for QLA2312 PCI parity error */
557 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
558 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
559 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
561 data
= RD_MAILBOX_REG(ha
, reg
, 0);
568 goto chip_diag_failed
;
570 /* Check product ID of chip */
571 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha
->host_no
));
573 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
574 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
575 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
576 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
577 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
578 mb
[3] != PROD_ID_3
) {
579 qla_printk(KERN_WARNING
, ha
,
580 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
582 goto chip_diag_failed
;
584 ha
->product_id
[0] = mb
[1];
585 ha
->product_id
[1] = mb
[2];
586 ha
->product_id
[2] = mb
[3];
587 ha
->product_id
[3] = mb
[4];
589 /* Adjust fw RISC transfer size */
590 if (ha
->request_q_length
> 1024)
591 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
593 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
594 ha
->request_q_length
;
596 if (IS_QLA2200(ha
) &&
597 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
598 /* Limit firmware transfer size with a 2200A */
599 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
602 ha
->fw_transfer_size
= 128;
605 /* Wrap Incoming Mailboxes Test. */
606 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
608 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha
->host_no
));
609 rval
= qla2x00_mbx_reg_test(ha
);
611 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
613 qla_printk(KERN_WARNING
, ha
,
614 "Failed mailbox send register test\n");
617 /* Flag a successful rval */
620 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
624 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
625 "****\n", ha
->host_no
));
627 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
633 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
636 * Returns 0 on success.
639 qla2x00_resize_request_q(scsi_qla_host_t
*ha
)
642 uint16_t fw_iocb_cnt
= 0;
643 uint16_t request_q_length
= REQUEST_ENTRY_CNT_2XXX_EXT_MEM
;
644 dma_addr_t request_dma
;
645 request_t
*request_ring
;
647 /* Valid only on recent ISPs. */
648 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
651 /* Retrieve IOCB counts available to the firmware. */
652 rval
= qla2x00_get_resource_cnts(ha
, NULL
, NULL
, NULL
, &fw_iocb_cnt
);
655 /* No point in continuing if current settings are sufficient. */
656 if (fw_iocb_cnt
< 1024)
658 if (ha
->request_q_length
>= request_q_length
)
661 /* Attempt to claim larger area for request queue. */
662 request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
663 (request_q_length
+ 1) * sizeof(request_t
), &request_dma
,
665 if (request_ring
== NULL
)
668 /* Resize successful, report extensions. */
669 qla_printk(KERN_INFO
, ha
, "Extended memory detected (%d KB)...\n",
670 (ha
->fw_memory_size
+ 1) / 1024);
671 qla_printk(KERN_INFO
, ha
, "Resizing request queue depth "
672 "(%d -> %d)...\n", ha
->request_q_length
, request_q_length
);
674 /* Clear old allocations. */
675 dma_free_coherent(&ha
->pdev
->dev
,
676 (ha
->request_q_length
+ 1) * sizeof(request_t
), ha
->request_ring
,
679 /* Begin using larger queue. */
680 ha
->request_q_length
= request_q_length
;
681 ha
->request_ring
= request_ring
;
682 ha
->request_dma
= request_dma
;
686 * qla2x00_setup_chip() - Load and start RISC firmware.
689 * Returns 0 on success.
692 qla2x00_setup_chip(scsi_qla_host_t
*ha
)
697 unsigned long risc_address
;
698 unsigned long risc_code_size
;
702 struct qla_fw_info
*fw_iter
;
706 /* Load firmware sequences */
707 fw_iter
= ha
->brd_info
->fw_info
;
708 while (fw_iter
->addressing
!= FW_INFO_ADDR_NOMORE
) {
709 risc_code
= fw_iter
->fwcode
;
710 risc_code_size
= *fw_iter
->fwlen
;
712 if (fw_iter
->addressing
== FW_INFO_ADDR_NORMAL
) {
713 risc_address
= *fw_iter
->fwstart
;
715 /* Extended address */
716 risc_address
= *fw_iter
->lfwstart
;
721 while (risc_code_size
> 0 && !rval
) {
722 cnt
= (uint16_t)(ha
->fw_transfer_size
>> 1);
723 if (cnt
> risc_code_size
)
724 cnt
= risc_code_size
;
726 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
727 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
728 ha
->host_no
, risc_code
, cnt
, risc_address
));
730 req_ring
= (uint16_t *)ha
->request_ring
;
731 for (i
= 0; i
< cnt
; i
++)
732 req_ring
[i
] = cpu_to_le16(risc_code
[i
]);
734 if (fw_iter
->addressing
== FW_INFO_ADDR_NORMAL
) {
735 rval
= qla2x00_load_ram(ha
,
736 ha
->request_dma
, risc_address
, cnt
);
738 rval
= qla2x00_load_ram_ext(ha
,
739 ha
->request_dma
, risc_address
, cnt
);
742 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
743 "load segment %d of firmware\n",
745 qla_printk(KERN_WARNING
, ha
,
746 "[ERROR] Failed to load "
747 "segment %d of firmware\n", num
);
749 qla2x00_dump_regs(ha
);
755 risc_code_size
-= cnt
;
759 /* Next firmware sequence */
763 /* Verify checksum of loaded RISC code. */
765 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
766 "code.\n", ha
->host_no
));
768 rval
= qla2x00_verify_checksum(ha
);
769 if (rval
== QLA_SUCCESS
) {
770 /* Start firmware execution. */
771 DEBUG(printk("scsi(%ld): Checksum OK, start "
772 "firmware.\n", ha
->host_no
));
774 rval
= qla2x00_execute_fw(ha
);
775 /* Retrieve firmware information. */
776 if (rval
== QLA_SUCCESS
&& ha
->fw_major_version
== 0) {
777 qla2x00_get_fw_version(ha
,
778 &ha
->fw_major_version
,
779 &ha
->fw_minor_version
,
780 &ha
->fw_subminor_version
,
781 &ha
->fw_attributes
, &ha
->fw_memory_size
);
782 qla2x00_resize_request_q(ha
);
785 DEBUG2(printk(KERN_INFO
786 "scsi(%ld): ISP Firmware failed checksum.\n",
792 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
800 * qla2x00_init_response_q_entries() - Initializes response queue entries.
803 * Beginning of request ring has initialization control block already built
804 * by nvram config routine.
806 * Returns 0 on success.
809 qla2x00_init_response_q_entries(scsi_qla_host_t
*ha
)
814 pkt
= ha
->response_ring_ptr
;
815 for (cnt
= 0; cnt
< ha
->response_q_length
; cnt
++) {
816 pkt
->signature
= RESPONSE_PROCESSED
;
823 * qla2x00_update_fw_options() - Read and process firmware options.
826 * Returns 0 on success.
829 qla2x00_update_fw_options(scsi_qla_host_t
*ha
)
831 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
833 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
834 qla2x00_get_fw_options(ha
, ha
->fw_options
);
836 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
839 /* Serial Link options. */
840 DEBUG3(printk("scsi(%ld): Serial link options:\n",
842 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
843 sizeof(ha
->fw_seriallink_options
)));
845 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
846 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
847 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
850 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
851 emphasis
= (ha
->fw_seriallink_options
[2] &
852 (BIT_4
| BIT_3
)) >> 3;
853 tx_sens
= ha
->fw_seriallink_options
[0] &
854 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
855 rx_sens
= (ha
->fw_seriallink_options
[0] &
856 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
857 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
858 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
861 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
862 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
863 ha
->fw_options
[10] |= BIT_5
|
864 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
865 (tx_sens
& (BIT_1
| BIT_0
));
868 swing
= (ha
->fw_seriallink_options
[2] &
869 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
870 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
871 tx_sens
= ha
->fw_seriallink_options
[1] &
872 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
873 rx_sens
= (ha
->fw_seriallink_options
[1] &
874 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
875 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
876 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
879 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
880 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
881 ha
->fw_options
[11] |= BIT_5
|
882 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
883 (tx_sens
& (BIT_1
| BIT_0
));
887 /* Return command IOCBs without waiting for an ABTS to complete. */
888 ha
->fw_options
[3] |= BIT_13
;
891 if (ha
->flags
.enable_led_scheme
)
892 ha
->fw_options
[2] |= BIT_12
;
894 /* Update firmware options. */
895 qla2x00_set_fw_options(ha
, ha
->fw_options
);
899 * qla2x00_init_rings() - Initializes firmware.
902 * Beginning of request ring has initialization control block already built
903 * by nvram config routine.
905 * Returns 0 on success.
908 qla2x00_init_rings(scsi_qla_host_t
*ha
)
911 unsigned long flags
= 0;
913 device_reg_t __iomem
*reg
= ha
->iobase
;
915 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
917 /* Clear outstanding commands array. */
918 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
919 ha
->outstanding_cmds
[cnt
] = NULL
;
921 ha
->current_outstanding_cmd
= 0;
923 /* Clear RSCN queue. */
925 ha
->rscn_out_ptr
= 0;
927 /* Initialize firmware. */
928 ha
->request_ring_ptr
= ha
->request_ring
;
929 ha
->req_ring_index
= 0;
930 ha
->req_q_cnt
= ha
->request_q_length
;
931 ha
->response_ring_ptr
= ha
->response_ring
;
932 ha
->rsp_ring_index
= 0;
934 /* Setup ring parameters in initialization control block. */
935 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
936 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
937 ha
->init_cb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
938 ha
->init_cb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
939 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
940 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
941 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
942 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
944 /* Initialize response queue entries */
945 qla2x00_init_response_q_entries(ha
);
947 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
948 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
949 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
950 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
951 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
953 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
955 /* Update any ISP specific firmware options before initialization. */
956 qla2x00_update_fw_options(ha
);
958 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha
->host_no
));
959 rval
= qla2x00_init_firmware(ha
, sizeof(init_cb_t
));
961 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
964 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
972 * qla2x00_fw_ready() - Waits for firmware ready.
975 * Returns 0 on success.
978 qla2x00_fw_ready(scsi_qla_host_t
*ha
)
981 unsigned long wtime
, mtime
;
982 uint16_t min_wait
; /* Minimum wait time if loop is down */
983 uint16_t wait_time
; /* Wait time if loop is coming ready */
988 /* 20 seconds for loop down. */
992 * Firmware should take at most one RATOV to login, plus 5 seconds for
993 * our own processing.
995 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
996 wait_time
= min_wait
;
999 /* Min wait time if loop down */
1000 mtime
= jiffies
+ (min_wait
* HZ
);
1002 /* wait time before firmware ready */
1003 wtime
= jiffies
+ (wait_time
* HZ
);
1005 /* Wait for ISP to finish LIP */
1006 if (!ha
->flags
.init_done
)
1007 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1009 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1013 rval
= qla2x00_get_firmware_state(ha
, &fw_state
);
1014 if (rval
== QLA_SUCCESS
) {
1015 if (fw_state
< FSTATE_LOSS_OF_SYNC
) {
1016 ha
->device_flags
&= ~DFLG_NO_CABLE
;
1018 if (fw_state
== FSTATE_READY
) {
1019 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1022 qla2x00_get_retry_cnt(ha
, &ha
->retry_count
,
1023 &ha
->login_timeout
, &ha
->r_a_tov
);
1029 rval
= QLA_FUNCTION_FAILED
;
1031 if (atomic_read(&ha
->loop_down_timer
) &&
1032 (fw_state
>= FSTATE_LOSS_OF_SYNC
||
1033 fw_state
== FSTATE_WAIT_AL_PA
)) {
1034 /* Loop down. Timeout on min_wait for states
1035 * other than Wait for Login.
1037 if (time_after_eq(jiffies
, mtime
)) {
1038 qla_printk(KERN_INFO
, ha
,
1039 "Cable is unplugged...\n");
1041 ha
->device_flags
|= DFLG_NO_CABLE
;
1046 /* Mailbox cmd failed. Timeout on min_wait. */
1047 if (time_after_eq(jiffies
, mtime
))
1051 if (time_after_eq(jiffies
, wtime
))
1054 /* Delay for a while */
1057 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1058 ha
->host_no
, fw_state
, jiffies
));
1061 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1062 ha
->host_no
, fw_state
, jiffies
));
1065 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1073 * qla2x00_configure_hba
1074 * Setup adapter context.
1077 * ha = adapter state pointer.
1086 qla2x00_configure_hba(scsi_qla_host_t
*ha
)
1094 char connect_type
[22];
1096 /* Get host addresses. */
1097 rval
= qla2x00_get_adapter_id(ha
,
1098 &loop_id
, &al_pa
, &area
, &domain
, &topo
);
1099 if (rval
!= QLA_SUCCESS
) {
1100 qla_printk(KERN_WARNING
, ha
,
1101 "ERROR -- Unable to get host loop ID.\n");
1102 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1107 qla_printk(KERN_INFO
, ha
,
1108 "Cannot get topology - retrying.\n");
1109 return (QLA_FUNCTION_FAILED
);
1112 ha
->loop_id
= loop_id
;
1115 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
1116 ha
->operating_mode
= LOOP
;
1120 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1122 ha
->current_topology
= ISP_CFG_NL
;
1123 strcpy(connect_type
, "(Loop)");
1127 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1129 ha
->current_topology
= ISP_CFG_FL
;
1130 strcpy(connect_type
, "(FL_Port)");
1134 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1136 ha
->operating_mode
= P2P
;
1137 ha
->current_topology
= ISP_CFG_N
;
1138 strcpy(connect_type
, "(N_Port-to-N_Port)");
1142 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1144 ha
->operating_mode
= P2P
;
1145 ha
->current_topology
= ISP_CFG_F
;
1146 strcpy(connect_type
, "(F_Port)");
1150 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1152 ha
->host_no
, topo
));
1153 ha
->current_topology
= ISP_CFG_NL
;
1154 strcpy(connect_type
, "(Loop)");
1158 /* Save Host port and loop ID. */
1159 /* byte order - Big Endian */
1160 ha
->d_id
.b
.domain
= domain
;
1161 ha
->d_id
.b
.area
= area
;
1162 ha
->d_id
.b
.al_pa
= al_pa
;
1164 if (!ha
->flags
.init_done
)
1165 qla_printk(KERN_INFO
, ha
,
1166 "Topology - %s, Host Loop address 0x%x\n",
1167 connect_type
, ha
->loop_id
);
1170 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha
->host_no
));
1172 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha
->host_no
));
1179 * NVRAM configuration for ISP 2xxx
1182 * ha = adapter block pointer.
1185 * initialization control block in response_ring
1186 * host adapters parameters in host adapter block
1192 qla2x00_nvram_config(scsi_qla_host_t
*ha
)
1197 uint8_t *dptr1
, *dptr2
;
1198 init_cb_t
*icb
= ha
->init_cb
;
1199 nvram_t
*nv
= (nvram_t
*)ha
->request_ring
;
1200 uint16_t *wptr
= (uint16_t *)ha
->request_ring
;
1201 device_reg_t __iomem
*reg
= ha
->iobase
;
1206 /* Determine NVRAM starting address. */
1208 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
1209 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
1210 ha
->nvram_base
= 0x80;
1212 /* Get NVRAM data and calculate checksum. */
1213 qla2x00_lock_nvram_access(ha
);
1214 for (cnt
= 0; cnt
< sizeof(nvram_t
)/2; cnt
++) {
1215 *wptr
= cpu_to_le16(qla2x00_get_nvram_word(ha
,
1216 (cnt
+ha
->nvram_base
)));
1217 chksum
+= (uint8_t)*wptr
;
1218 chksum
+= (uint8_t)(*wptr
>> 8);
1221 qla2x00_unlock_nvram_access(ha
);
1223 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
1224 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
1227 /* Bad NVRAM data, set defaults parameters. */
1228 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
1229 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
1230 /* Reset NVRAM data. */
1231 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
1232 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
1234 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
1235 "invalid -- WWPN) defaults.\n");
1238 * Set default initialization control block.
1240 memset(nv
, 0, sizeof(nvram_t
));
1241 nv
->parameter_block_version
= ICB_VERSION
;
1243 if (IS_QLA23XX(ha
)) {
1244 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1245 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1246 nv
->add_firmware_options
[0] = BIT_5
;
1247 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1248 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1249 nv
->special_options
[1] = BIT_7
;
1250 } else if (IS_QLA2200(ha
)) {
1251 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1252 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1253 nv
->add_firmware_options
[0] = BIT_5
;
1254 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1255 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1256 } else if (IS_QLA2100(ha
)) {
1257 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
1258 nv
->firmware_options
[1] = BIT_5
;
1259 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1262 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
1263 nv
->execution_throttle
= __constant_cpu_to_le16(16);
1264 nv
->retry_count
= 8;
1265 nv
->retry_delay
= 1;
1267 nv
->port_name
[0] = 33;
1268 nv
->port_name
[3] = 224;
1269 nv
->port_name
[4] = 139;
1271 nv
->login_timeout
= 4;
1274 * Set default host adapter parameters
1276 nv
->host_p
[1] = BIT_2
;
1277 nv
->reset_delay
= 5;
1278 nv
->port_down_retry_count
= 8;
1279 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
1280 nv
->link_down_timeout
= 60;
1285 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1287 * The SN2 does not provide BIOS emulation which means you can't change
1288 * potentially bogus BIOS settings. Force the use of default settings
1289 * for link rate and frame size. Hope that the rest of the settings
1292 if (ia64_platform_is("sn2")) {
1293 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1295 nv
->special_options
[1] = BIT_7
;
1299 /* Reset Initialization control block */
1300 memset(icb
, 0, sizeof(init_cb_t
));
1303 * Setup driver NVRAM options.
1305 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
1306 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
1307 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
1308 nv
->firmware_options
[1] &= ~BIT_4
;
1310 if (IS_QLA23XX(ha
)) {
1311 nv
->firmware_options
[0] |= BIT_2
;
1312 nv
->firmware_options
[0] &= ~BIT_3
;
1314 if (IS_QLA2300(ha
)) {
1315 if (ha
->fb_rev
== FPM_2310
) {
1316 strcpy(ha
->model_number
, "QLA2310");
1318 strcpy(ha
->model_number
, "QLA2300");
1322 memcmp(nv
->model_number
, BINZERO
,
1323 sizeof(nv
->model_number
)) != 0) {
1326 strncpy(ha
->model_number
, nv
->model_number
,
1327 sizeof(nv
->model_number
));
1328 st
= en
= ha
->model_number
;
1329 en
+= sizeof(nv
->model_number
) - 1;
1331 if (*en
!= 0x20 && *en
!= 0x00)
1338 index
= (ha
->pdev
->subsystem_device
& 0xff);
1339 if (index
< QLA_MODEL_NAMES
) {
1340 strcpy(ha
->model_number
,
1341 qla2x00_model_name
[index
]);
1343 qla2x00_model_desc
[index
];
1345 strcpy(ha
->model_number
, "QLA23xx");
1349 } else if (IS_QLA2200(ha
)) {
1350 nv
->firmware_options
[0] |= BIT_2
;
1352 * 'Point-to-point preferred, else loop' is not a safe
1353 * connection mode setting.
1355 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
1357 /* Force 'loop preferred, else point-to-point'. */
1358 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
1359 nv
->add_firmware_options
[0] |= BIT_5
;
1361 strcpy(ha
->model_number
, "QLA22xx");
1362 } else /*if (IS_QLA2100(ha))*/ {
1363 strcpy(ha
->model_number
, "QLA2100");
1367 * Copy over NVRAM RISC parameter block to initialization control block.
1369 dptr1
= (uint8_t *)icb
;
1370 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
1371 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
1373 *dptr1
++ = *dptr2
++;
1375 /* Copy 2nd half. */
1376 dptr1
= (uint8_t *)icb
->add_firmware_options
;
1377 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
1379 *dptr1
++ = *dptr2
++;
1381 /* Prepare nodename */
1382 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
1384 * Firmware will apply the following mask if the nodename was
1387 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
1388 icb
->node_name
[0] &= 0xF0;
1392 * Set host adapter parameters.
1394 ha
->nvram_version
= nv
->nvram_version
;
1396 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
1397 /* Always load RISC code on non ISP2[12]00 chips. */
1398 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1399 ha
->flags
.disable_risc_code_load
= 0;
1400 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
1401 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
1402 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
1403 ha
->flags
.enable_led_scheme
= ((nv
->efi_parameters
& BIT_3
) ? 1 : 0);
1405 ha
->operating_mode
=
1406 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
1408 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
1409 sizeof(ha
->fw_seriallink_options
));
1411 /* save HBA serial number */
1412 ha
->serial0
= icb
->port_name
[5];
1413 ha
->serial1
= icb
->port_name
[6];
1414 ha
->serial2
= icb
->port_name
[7];
1415 memcpy(ha
->node_name
, icb
->node_name
, WWN_SIZE
);
1417 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
1419 ha
->retry_count
= nv
->retry_count
;
1421 /* Set minimum login_timeout to 4 seconds. */
1422 if (nv
->login_timeout
< ql2xlogintimeout
)
1423 nv
->login_timeout
= ql2xlogintimeout
;
1424 if (nv
->login_timeout
< 4)
1425 nv
->login_timeout
= 4;
1426 ha
->login_timeout
= nv
->login_timeout
;
1427 icb
->login_timeout
= nv
->login_timeout
;
1429 /* Set minimum RATOV to 200 tenths of a second. */
1432 ha
->minimum_timeout
=
1433 (ha
->login_timeout
* ha
->retry_count
) + nv
->port_down_retry_count
;
1434 ha
->loop_reset_delay
= nv
->reset_delay
;
1436 /* Will get the value from NVRAM. */
1437 ha
->loop_down_timeout
= LOOP_DOWN_TIMEOUT
;
1439 /* Link Down Timeout = 0:
1441 * When Port Down timer expires we will start returning
1442 * I/O's to OS with "DID_NO_CONNECT".
1444 * Link Down Timeout != 0:
1446 * The driver waits for the link to come up after link down
1447 * before returning I/Os to OS with "DID_NO_CONNECT".
1449 if (nv
->link_down_timeout
== 0) {
1450 ha
->loop_down_abort_time
=
1451 (LOOP_DOWN_TIME
- ha
->loop_down_timeout
);
1453 ha
->link_down_timeout
= nv
->link_down_timeout
;
1454 ha
->loop_down_abort_time
=
1455 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
1458 ha
->max_luns
= MAX_LUNS
;
1459 ha
->max_probe_luns
= le16_to_cpu(nv
->max_luns_per_target
);
1460 if (ha
->max_probe_luns
== 0)
1461 ha
->max_probe_luns
= MIN_LUNS
;
1464 * Need enough time to try and get the port back.
1466 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
1467 if (qlport_down_retry
)
1468 ha
->port_down_retry_count
= qlport_down_retry
;
1469 /* Set login_retry_count */
1470 ha
->login_retry_count
= nv
->retry_count
;
1471 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
1472 ha
->port_down_retry_count
> 3)
1473 ha
->login_retry_count
= ha
->port_down_retry_count
;
1474 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
1475 ha
->login_retry_count
= ha
->port_down_retry_count
;
1476 if (ql2xloginretrycount
)
1477 ha
->login_retry_count
= ql2xloginretrycount
;
1479 ha
->binding_type
= Bind
;
1480 if (ha
->binding_type
!= BIND_BY_PORT_NAME
&&
1481 ha
->binding_type
!= BIND_BY_PORT_ID
) {
1482 qla_printk(KERN_WARNING
, ha
,
1483 "Invalid binding type specified (%d), "
1484 "defaulting to BIND_BY_PORT_NAME!!!\n", ha
->binding_type
);
1486 ha
->binding_type
= BIND_BY_PORT_NAME
;
1489 icb
->lun_enables
= __constant_cpu_to_le16(0);
1490 icb
->command_resource_count
= 0;
1491 icb
->immediate_notify_resource_count
= 0;
1492 icb
->timeout
= __constant_cpu_to_le16(0);
1494 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1496 icb
->firmware_options
[0] &= ~BIT_3
;
1497 icb
->add_firmware_options
[0] &=
1498 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1499 icb
->add_firmware_options
[0] |= BIT_2
;
1500 icb
->response_accumulation_timer
= 3;
1501 icb
->interrupt_delay_timer
= 5;
1503 ha
->flags
.process_response_queue
= 1;
1505 /* Enable ZIO -- Support mode 5 only. */
1506 timer_mode
= icb
->add_firmware_options
[0] &
1507 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1508 icb
->add_firmware_options
[0] &=
1509 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1511 timer_mode
= BIT_2
| BIT_0
;
1512 if (timer_mode
== (BIT_2
| BIT_0
)) {
1513 DEBUG2(printk("scsi(%ld): ZIO enabled; timer delay "
1514 "(%d).\n", ha
->host_no
, ql2xintrdelaytimer
));
1515 qla_printk(KERN_INFO
, ha
,
1516 "ZIO enabled; timer delay (%d).\n",
1517 ql2xintrdelaytimer
);
1519 icb
->add_firmware_options
[0] |= timer_mode
;
1520 icb
->interrupt_delay_timer
= ql2xintrdelaytimer
;
1521 ha
->flags
.process_response_queue
= 1;
1526 DEBUG2_3(printk(KERN_WARNING
1527 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
1533 * qla2x00_init_tgt_map
1534 * Initializes target map.
1537 * ha = adapter block pointer.
1543 qla2x00_init_tgt_map(scsi_qla_host_t
*ha
)
1547 for (t
= 0; t
< MAX_TARGETS
; t
++)
1548 TGT_Q(ha
, t
) = (os_tgt_t
*)NULL
;
1552 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1554 * @flags: allocation flags
1556 * Returns a pointer to the allocated fcport, or NULL, if none available.
1559 qla2x00_alloc_fcport(scsi_qla_host_t
*ha
, int flags
)
1563 fcport
= kmalloc(sizeof(fc_port_t
), flags
);
1567 /* Setup fcport template structure. */
1568 memset(fcport
, 0, sizeof (fc_port_t
));
1570 fcport
->port_type
= FCT_UNKNOWN
;
1571 fcport
->loop_id
= FC_NO_LOOP_ID
;
1572 fcport
->iodesc_idx_sent
= IODESC_INVALID_INDEX
;
1573 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
1574 fcport
->flags
= FCF_RLC_SUPPORT
;
1575 INIT_LIST_HEAD(&fcport
->fcluns
);
1581 * qla2x00_configure_loop
1582 * Updates Fibre Channel Device Database with what is actually on loop.
1585 * ha = adapter block pointer.
1590 * 2 = database was full and device was not configured.
1593 qla2x00_configure_loop(scsi_qla_host_t
*ha
)
1596 unsigned long flags
, save_flags
;
1600 /* Get Initiator ID */
1601 if (test_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
)) {
1602 rval
= qla2x00_configure_hba(ha
);
1603 if (rval
!= QLA_SUCCESS
) {
1604 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1610 save_flags
= flags
= ha
->dpc_flags
;
1611 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1612 ha
->host_no
, flags
));
1615 * If we have both an RSCN and PORT UPDATE pending then handle them
1616 * both at the same time.
1618 clear_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1619 clear_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1622 /* Determine what we need to do */
1623 if (ha
->current_topology
== ISP_CFG_FL
&&
1624 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1626 ha
->flags
.rscn_queue_overflow
= 1;
1627 set_bit(RSCN_UPDATE
, &flags
);
1629 } else if (ha
->current_topology
== ISP_CFG_F
&&
1630 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1632 ha
->flags
.rscn_queue_overflow
= 1;
1633 set_bit(RSCN_UPDATE
, &flags
);
1634 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
1636 } else if (!ha
->flags
.online
||
1637 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
1639 ha
->flags
.rscn_queue_overflow
= 1;
1640 set_bit(RSCN_UPDATE
, &flags
);
1641 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
1644 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
1645 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1646 rval
= QLA_FUNCTION_FAILED
;
1648 rval
= qla2x00_configure_local_loop(ha
);
1652 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
1653 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1654 rval
= QLA_FUNCTION_FAILED
;
1656 rval
= qla2x00_configure_fabric(ha
);
1660 if (rval
== QLA_SUCCESS
) {
1661 if (atomic_read(&ha
->loop_down_timer
) ||
1662 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1663 rval
= QLA_FUNCTION_FAILED
;
1665 qla2x00_config_os(ha
);
1666 atomic_set(&ha
->loop_state
, LOOP_READY
);
1668 DEBUG(printk("scsi(%ld): LOOP READY\n", ha
->host_no
));
1673 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1674 __func__
, ha
->host_no
));
1676 DEBUG3(printk("%s: exiting normally\n", __func__
));
1679 /* Restore state if a resync event occured during processing */
1680 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1681 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
1682 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1683 if (test_bit(RSCN_UPDATE
, &save_flags
))
1684 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1693 * qla2x00_configure_local_loop
1694 * Updates Fibre Channel Device Database with local loop devices.
1697 * ha = adapter block pointer.
1703 qla2x00_configure_local_loop(scsi_qla_host_t
*ha
)
1708 fc_port_t
*fcport
, *new_fcport
;
1714 uint8_t domain
, area
, al_pa
;
1718 entries
= MAX_FIBRE_DEVICES
;
1720 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha
->host_no
));
1721 DEBUG3(qla2x00_get_fcal_position_map(ha
, NULL
));
1723 /* Get list of logged in devices. */
1724 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
1725 rval
= qla2x00_get_id_list(ha
, ha
->gid_list
, ha
->gid_list_dma
,
1727 if (rval
!= QLA_SUCCESS
)
1728 goto cleanup_allocation
;
1730 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1731 ha
->host_no
, entries
));
1732 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
1733 entries
* sizeof(struct gid_list_info
)));
1735 /* Allocate temporary fcport for any new fcports discovered. */
1736 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1737 if (new_fcport
== NULL
) {
1738 rval
= QLA_MEMORY_ALLOC_FAILED
;
1739 goto cleanup_allocation
;
1741 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
1744 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1746 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1747 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
1748 fcport
->port_type
!= FCT_BROADCAST
&&
1749 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
1751 DEBUG(printk("scsi(%ld): Marking port lost, "
1753 ha
->host_no
, fcport
->loop_id
));
1755 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1756 fcport
->flags
&= ~FCF_FARP_DONE
;
1760 /* Add devices to port list. */
1761 id_iter
= (char *)ha
->gid_list
;
1762 for (index
= 0; index
< entries
; index
++) {
1763 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
1764 area
= ((struct gid_list_info
*)id_iter
)->area
;
1765 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
1766 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1767 loop_id
= (uint16_t)
1768 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
1771 loop_id
= le16_to_cpu(
1772 ((struct gid_list_info
*)id_iter
)->loop_id
);
1776 /* Bypass reserved domain fields. */
1777 if ((domain
& 0xf0) == 0xf0)
1780 /* Bypass if not same domain and area of adapter. */
1781 if (area
!= ha
->d_id
.b
.area
|| domain
!= ha
->d_id
.b
.domain
)
1784 /* Bypass invalid local loop ID. */
1785 if (loop_id
> LAST_LOCAL_LOOP_ID
)
1788 /* Fill in member data. */
1789 new_fcport
->d_id
.b
.domain
= domain
;
1790 new_fcport
->d_id
.b
.area
= area
;
1791 new_fcport
->d_id
.b
.al_pa
= al_pa
;
1792 new_fcport
->loop_id
= loop_id
;
1793 rval2
= qla2x00_get_port_database(ha
, new_fcport
, 0);
1794 if (rval2
!= QLA_SUCCESS
) {
1795 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1796 "information -- get_port_database=%x, "
1798 ha
->host_no
, rval2
, new_fcport
->loop_id
));
1802 /* Check for matching device in port list. */
1805 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1806 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
1810 fcport
->flags
&= ~(FCF_FABRIC_DEVICE
|
1811 FCF_PERSISTENT_BOUND
);
1812 fcport
->loop_id
= new_fcport
->loop_id
;
1813 fcport
->port_type
= new_fcport
->port_type
;
1814 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
1815 memcpy(fcport
->node_name
, new_fcport
->node_name
,
1823 /* New device, add to fcports list. */
1824 new_fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
1825 list_add_tail(&new_fcport
->list
, &ha
->fcports
);
1827 /* Allocate a new replacement fcport. */
1828 fcport
= new_fcport
;
1829 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1830 if (new_fcport
== NULL
) {
1831 rval
= QLA_MEMORY_ALLOC_FAILED
;
1832 goto cleanup_allocation
;
1834 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
1837 qla2x00_update_fcport(ha
, fcport
);
1846 if (rval
!= QLA_SUCCESS
) {
1847 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1848 "rval=%x\n", ha
->host_no
, rval
));
1852 ha
->device_flags
|= DFLG_LOCAL_DEVICES
;
1853 ha
->device_flags
&= ~DFLG_RETRY_LOCAL_DEVICES
;
1860 qla2x00_probe_for_all_luns(scsi_qla_host_t
*ha
)
1864 qla2x00_mark_all_devices_lost(ha
);
1865 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1866 if (fcport
->port_type
!= FCT_TARGET
)
1869 qla2x00_update_fcport(ha
, fcport
);
1874 * qla2x00_update_fcport
1875 * Updates device on list.
1878 * ha = adapter block pointer.
1879 * fcport = port structure pointer.
1889 qla2x00_update_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
1892 unsigned long flags
;
1896 fcport
->login_retry
= 0;
1897 fcport
->port_login_retry_count
= ha
->port_down_retry_count
*
1899 atomic_set(&fcport
->port_down_timer
, ha
->port_down_retry_count
*
1901 fcport
->flags
&= ~FCF_LOGIN_NEEDED
;
1904 * Check for outstanding cmd on tape Bypass LUN discovery if active
1907 if (fcport
->flags
& FCF_TAPE_PRESENT
) {
1908 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1909 for (index
= 1; index
< MAX_OUTSTANDING_COMMANDS
; index
++) {
1910 if ((sp
= ha
->outstanding_cmds
[index
]) != 0) {
1911 if (sp
->fclun
->fcport
== fcport
) {
1912 atomic_set(&fcport
->state
, FCS_ONLINE
);
1913 spin_unlock_irqrestore(
1914 &ha
->hardware_lock
, flags
);
1919 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1922 /* Do LUN discovery. */
1923 if (fcport
->port_type
== FCT_INITIATOR
||
1924 fcport
->port_type
== FCT_BROADCAST
) {
1925 fcport
->device_type
= TYPE_PROCESSOR
;
1927 qla2x00_lun_discovery(ha
, fcport
);
1929 atomic_set(&fcport
->state
, FCS_ONLINE
);
1933 * qla2x00_lun_discovery
1934 * Issue SCSI inquiry command for LUN discovery.
1937 * ha: adapter state pointer.
1938 * fcport: FC port structure pointer.
1944 qla2x00_lun_discovery(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
1950 inq
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
, &inq_dma
);
1952 qla_printk(KERN_WARNING
, ha
,
1953 "Memory Allocation failed - INQ\n");
1957 /* Always add a fc_lun_t structure for lun 0 -- mid-layer requirement */
1958 qla2x00_add_lun(fcport
, 0);
1960 /* If report LUN works, exit. */
1961 if (qla2x00_rpt_lun_discovery(ha
, fcport
, inq
, inq_dma
) !=
1963 for (lun
= 0; lun
< ha
->max_probe_luns
; lun
++) {
1964 /* Configure LUN. */
1965 qla2x00_cfg_lun(ha
, fcport
, lun
, inq
, inq_dma
);
1969 dma_pool_free(ha
->s_dma_pool
, inq
, inq_dma
);
1973 * qla2x00_rpt_lun_discovery
1974 * Issue SCSI report LUN command for LUN discovery.
1977 * ha: adapter state pointer.
1978 * fcport: FC port structure pointer.
1981 * qla2x00 local function return status code.
1987 qla2x00_rpt_lun_discovery(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
1988 inq_cmd_rsp_t
*inq
, dma_addr_t inq_dma
)
1994 /* Assume a failed status */
1995 rval
= QLA_FUNCTION_FAILED
;
1997 /* No point in continuing if the device doesn't support RLC */
1998 if ((fcport
->flags
& FCF_RLC_SUPPORT
) == 0)
2001 rval
= qla2x00_report_lun(ha
, fcport
);
2002 if (rval
!= QLA_SUCCESS
)
2005 /* Configure LUN list. */
2006 len
= be32_to_cpu(ha
->rlc_rsp
->list
.hdr
.len
);
2008 for (cnt
= 0; cnt
< len
; cnt
++) {
2009 lun
= CHAR_TO_SHORT(ha
->rlc_rsp
->list
.lst
[cnt
].lsb
,
2010 ha
->rlc_rsp
->list
.lst
[cnt
].msb
.b
);
2012 DEBUG3(printk("scsi(%ld): RLC lun = (%d)\n", ha
->host_no
, lun
));
2014 /* We only support 0 through MAX_LUNS-1 range */
2015 if (lun
< MAX_LUNS
) {
2016 qla2x00_cfg_lun(ha
, fcport
, lun
, inq
, inq_dma
);
2019 atomic_set(&fcport
->state
, FCS_ONLINE
);
2025 * qla2x00_report_lun
2026 * Issue SCSI report LUN command.
2029 * ha: adapter state pointer.
2030 * fcport: FC port structure pointer.
2033 * qla2x00 local function return status code.
2039 qla2x00_report_lun(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2043 uint16_t comp_status
;
2044 uint16_t scsi_status
;
2045 rpt_lun_cmd_rsp_t
*rlc
;
2048 rval
= QLA_FUNCTION_FAILED
;
2050 rlc_dma
= ha
->rlc_rsp_dma
;
2052 for (retries
= 3; retries
; retries
--) {
2053 memset(rlc
, 0, sizeof(rpt_lun_cmd_rsp_t
));
2054 rlc
->p
.cmd
.entry_type
= COMMAND_A64_TYPE
;
2055 rlc
->p
.cmd
.entry_count
= 1;
2056 SET_TARGET_ID(ha
, rlc
->p
.cmd
.target
, fcport
->loop_id
);
2057 rlc
->p
.cmd
.control_flags
=
2058 __constant_cpu_to_le16(CF_READ
| CF_SIMPLE_TAG
);
2059 rlc
->p
.cmd
.scsi_cdb
[0] = REPORT_LUNS
;
2060 rlc
->p
.cmd
.scsi_cdb
[8] = MSB(sizeof(rpt_lun_lst_t
));
2061 rlc
->p
.cmd
.scsi_cdb
[9] = LSB(sizeof(rpt_lun_lst_t
));
2062 rlc
->p
.cmd
.dseg_count
= __constant_cpu_to_le16(1);
2063 rlc
->p
.cmd
.timeout
= __constant_cpu_to_le16(10);
2064 rlc
->p
.cmd
.byte_count
=
2065 __constant_cpu_to_le32(sizeof(rpt_lun_lst_t
));
2066 rlc
->p
.cmd
.dseg_0_address
[0] = cpu_to_le32(
2067 LSD(rlc_dma
+ sizeof(sts_entry_t
)));
2068 rlc
->p
.cmd
.dseg_0_address
[1] = cpu_to_le32(
2069 MSD(rlc_dma
+ sizeof(sts_entry_t
)));
2070 rlc
->p
.cmd
.dseg_0_length
=
2071 __constant_cpu_to_le32(sizeof(rpt_lun_lst_t
));
2073 rval
= qla2x00_issue_iocb(ha
, rlc
, rlc_dma
,
2074 sizeof(rpt_lun_cmd_rsp_t
));
2076 comp_status
= le16_to_cpu(rlc
->p
.rsp
.comp_status
);
2077 scsi_status
= le16_to_cpu(rlc
->p
.rsp
.scsi_status
);
2079 if (rval
!= QLA_SUCCESS
|| comp_status
!= CS_COMPLETE
||
2080 scsi_status
& SS_CHECK_CONDITION
) {
2082 /* Device underrun, treat as OK. */
2083 if (rval
== QLA_SUCCESS
&&
2084 comp_status
== CS_DATA_UNDERRUN
&&
2085 scsi_status
& SS_RESIDUAL_UNDER
) {
2091 DEBUG(printk("scsi(%ld): RLC failed to issue iocb! "
2092 "fcport=[%04x/%p] rval=%x cs=%x ss=%x\n",
2093 ha
->host_no
, fcport
->loop_id
, fcport
, rval
,
2094 comp_status
, scsi_status
));
2096 rval
= QLA_FUNCTION_FAILED
;
2097 if (scsi_status
& SS_CHECK_CONDITION
) {
2098 DEBUG2(printk("scsi(%ld): RLC "
2099 "SS_CHECK_CONDITION Sense Data "
2100 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
2102 rlc
->p
.rsp
.req_sense_data
[0],
2103 rlc
->p
.rsp
.req_sense_data
[1],
2104 rlc
->p
.rsp
.req_sense_data
[2],
2105 rlc
->p
.rsp
.req_sense_data
[3],
2106 rlc
->p
.rsp
.req_sense_data
[4],
2107 rlc
->p
.rsp
.req_sense_data
[5],
2108 rlc
->p
.rsp
.req_sense_data
[6],
2109 rlc
->p
.rsp
.req_sense_data
[7]));
2110 if (rlc
->p
.rsp
.req_sense_data
[2] ==
2112 fcport
->flags
&= ~(FCF_RLC_SUPPORT
);
2126 * Configures LUN into fcport LUN list.
2129 * fcport: FC port structure pointer.
2136 qla2x00_cfg_lun(scsi_qla_host_t
*ha
, fc_port_t
*fcport
, uint16_t lun
,
2137 inq_cmd_rsp_t
*inq
, dma_addr_t inq_dma
)
2140 uint8_t device_type
;
2142 /* Bypass LUNs that failed. */
2143 if (qla2x00_inquiry(ha
, fcport
, lun
, inq
, inq_dma
) != QLA_SUCCESS
) {
2144 DEBUG2(printk("scsi(%ld): Failed inquiry - loop id=0x%04x "
2145 "lun=%d\n", ha
->host_no
, fcport
->loop_id
, lun
));
2149 device_type
= (inq
->inq
[0] & 0x1f);
2150 switch (device_type
) {
2152 case TYPE_PROCESSOR
:
2157 case TYPE_MEDIUM_CHANGER
:
2158 case TYPE_ENCLOSURE
:
2163 fcport
->flags
|= FCF_TAPE_PRESENT
;
2166 DEBUG2(printk("scsi(%ld): Unsupported lun type -- "
2167 "loop id=0x%04x lun=%d type=%x\n",
2168 ha
->host_no
, fcport
->loop_id
, lun
, device_type
));
2172 fcport
->device_type
= device_type
;
2173 fclun
= qla2x00_add_lun(fcport
, lun
);
2175 if (fclun
!= NULL
) {
2176 atomic_set(&fcport
->state
, FCS_ONLINE
);
2184 * Adds LUN to database
2187 * fcport: FC port structure pointer.
2194 qla2x00_add_lun(fc_port_t
*fcport
, uint16_t lun
)
2199 if (fcport
== NULL
) {
2200 DEBUG(printk("scsi: Unable to add lun to NULL port\n"));
2204 /* Allocate LUN if not already allocated. */
2206 list_for_each_entry(fclun
, &fcport
->fcluns
, list
) {
2207 if (fclun
->lun
== lun
) {
2215 fclun
= kmalloc(sizeof(fc_lun_t
), GFP_ATOMIC
);
2216 if (fclun
== NULL
) {
2218 "%s(): Memory Allocation failed - FCLUN\n",
2223 /* Setup LUN structure. */
2224 memset(fclun
, 0, sizeof(fc_lun_t
));
2226 fclun
->fcport
= fcport
;
2227 fclun
->o_fcport
= fcport
;
2228 fclun
->device_type
= fcport
->device_type
;
2229 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
2231 list_add_tail(&fclun
->list
, &fcport
->fcluns
);
2238 * Issue SCSI inquiry command.
2241 * ha = adapter block pointer.
2242 * fcport = FC port structure pointer.
2252 qla2x00_inquiry(scsi_qla_host_t
*ha
,
2253 fc_port_t
*fcport
, uint16_t lun
, inq_cmd_rsp_t
*inq
, dma_addr_t inq_dma
)
2257 uint16_t comp_status
;
2258 uint16_t scsi_status
;
2260 rval
= QLA_FUNCTION_FAILED
;
2262 for (retries
= 3; retries
; retries
--) {
2263 memset(inq
, 0, sizeof(inq_cmd_rsp_t
));
2264 inq
->p
.cmd
.entry_type
= COMMAND_A64_TYPE
;
2265 inq
->p
.cmd
.entry_count
= 1;
2266 inq
->p
.cmd
.lun
= cpu_to_le16(lun
);
2267 SET_TARGET_ID(ha
, inq
->p
.cmd
.target
, fcport
->loop_id
);
2268 inq
->p
.cmd
.control_flags
=
2269 __constant_cpu_to_le16(CF_READ
| CF_SIMPLE_TAG
);
2270 inq
->p
.cmd
.scsi_cdb
[0] = INQUIRY
;
2271 inq
->p
.cmd
.scsi_cdb
[4] = INQ_DATA_SIZE
;
2272 inq
->p
.cmd
.dseg_count
= __constant_cpu_to_le16(1);
2273 inq
->p
.cmd
.timeout
= __constant_cpu_to_le16(10);
2274 inq
->p
.cmd
.byte_count
=
2275 __constant_cpu_to_le32(INQ_DATA_SIZE
);
2276 inq
->p
.cmd
.dseg_0_address
[0] = cpu_to_le32(
2277 LSD(inq_dma
+ sizeof(sts_entry_t
)));
2278 inq
->p
.cmd
.dseg_0_address
[1] = cpu_to_le32(
2279 MSD(inq_dma
+ sizeof(sts_entry_t
)));
2280 inq
->p
.cmd
.dseg_0_length
=
2281 __constant_cpu_to_le32(INQ_DATA_SIZE
);
2283 DEBUG5(printk("scsi(%ld): Lun Inquiry - fcport=[%04x/%p],"
2285 ha
->host_no
, fcport
->loop_id
, fcport
, lun
));
2287 rval
= qla2x00_issue_iocb(ha
, inq
, inq_dma
,
2288 sizeof(inq_cmd_rsp_t
));
2290 comp_status
= le16_to_cpu(inq
->p
.rsp
.comp_status
);
2291 scsi_status
= le16_to_cpu(inq
->p
.rsp
.scsi_status
);
2293 DEBUG5(printk("scsi(%ld): lun (%d) inquiry - "
2294 "inq[0]= 0x%x, comp status 0x%x, scsi status 0x%x, "
2296 ha
->host_no
, lun
, inq
->inq
[0], comp_status
, scsi_status
,
2299 if (rval
!= QLA_SUCCESS
|| comp_status
!= CS_COMPLETE
||
2300 scsi_status
& SS_CHECK_CONDITION
) {
2302 DEBUG(printk("scsi(%ld): INQ failed to issue iocb! "
2303 "fcport=[%04x/%p] rval=%x cs=%x ss=%x\n",
2304 ha
->host_no
, fcport
->loop_id
, fcport
, rval
,
2305 comp_status
, scsi_status
));
2307 if (rval
== QLA_SUCCESS
)
2308 rval
= QLA_FUNCTION_FAILED
;
2310 if (scsi_status
& SS_CHECK_CONDITION
) {
2311 DEBUG2(printk("scsi(%ld): INQ "
2312 "SS_CHECK_CONDITION Sense Data "
2313 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
2315 inq
->p
.rsp
.req_sense_data
[0],
2316 inq
->p
.rsp
.req_sense_data
[1],
2317 inq
->p
.rsp
.req_sense_data
[2],
2318 inq
->p
.rsp
.req_sense_data
[3],
2319 inq
->p
.rsp
.req_sense_data
[4],
2320 inq
->p
.rsp
.req_sense_data
[5],
2321 inq
->p
.rsp
.req_sense_data
[6],
2322 inq
->p
.rsp
.req_sense_data
[7]));
2325 /* Device underrun drop LUN. */
2326 if (comp_status
== CS_DATA_UNDERRUN
&&
2327 scsi_status
& SS_RESIDUAL_UNDER
) {
2340 * qla2x00_configure_fabric
2341 * Setup SNS devices with loop ID's.
2344 * ha = adapter block pointer.
2351 qla2x00_configure_fabric(scsi_qla_host_t
*ha
)
2354 fc_port_t
*fcport
, *fcptemp
;
2355 uint16_t next_loopid
;
2356 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2357 LIST_HEAD(new_fcports
);
2359 /* If FL port exists, then SNS is present */
2360 rval
= qla2x00_get_port_name(ha
, SNS_FL_PORT
, NULL
, 0);
2361 if (rval
!= QLA_SUCCESS
) {
2362 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2363 "Port\n", ha
->host_no
));
2365 ha
->device_flags
&= ~SWITCH_FOUND
;
2366 return (QLA_SUCCESS
);
2369 /* Mark devices that need re-synchronization. */
2370 rval2
= qla2x00_device_resync(ha
);
2371 if (rval2
== QLA_RSCNS_HANDLED
) {
2372 /* No point doing the scan, just continue. */
2373 return (QLA_SUCCESS
);
2376 /* Ensure we are logged into the SNS. */
2377 qla2x00_login_fabric(ha
, SIMPLE_NAME_SERVER
, 0xff, 0xff, 0xfc,
2379 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2380 DEBUG2(qla_printk(KERN_INFO
, ha
,
2381 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2382 "mb[2]=%x mb[6]=%x mb[7]=%x\n", SIMPLE_NAME_SERVER
,
2383 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2384 return (QLA_SUCCESS
);
2387 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
)) {
2388 if (qla2x00_rft_id(ha
)) {
2390 DEBUG2(printk("scsi(%ld): Register FC-4 "
2391 "TYPE failed.\n", ha
->host_no
));
2393 if (qla2x00_rff_id(ha
)) {
2395 DEBUG2(printk("scsi(%ld): Register FC-4 "
2396 "Features failed.\n", ha
->host_no
));
2398 if (qla2x00_rnn_id(ha
)) {
2400 DEBUG2(printk("scsi(%ld): Register Node Name "
2401 "failed.\n", ha
->host_no
));
2402 } else if (qla2x00_rsnn_nn(ha
)) {
2404 DEBUG2(printk("scsi(%ld): Register Symbolic "
2405 "Node Name failed.\n", ha
->host_no
));
2409 rval
= qla2x00_find_all_fabric_devs(ha
, &new_fcports
);
2410 if (rval
!= QLA_SUCCESS
)
2414 * Logout all previous fabric devices marked lost, except
2417 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2418 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2421 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
2424 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2425 qla2x00_mark_device_lost(ha
, fcport
,
2426 ql2xplogiabsentdevice
);
2427 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2428 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2429 fcport
->port_type
!= FCT_INITIATOR
&&
2430 fcport
->port_type
!= FCT_BROADCAST
) {
2432 qla2x00_fabric_logout(ha
,
2434 fcport
->loop_id
= FC_NO_LOOP_ID
;
2439 /* Starting free loop ID. */
2440 next_loopid
= ha
->min_external_loopid
;
2443 * Scan through our port list and login entries that need to be
2446 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2447 if (atomic_read(&ha
->loop_down_timer
) ||
2448 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2451 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2452 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
2455 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
2456 fcport
->loop_id
= next_loopid
;
2457 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2458 if (rval
!= QLA_SUCCESS
) {
2459 /* Ran out of IDs to use */
2464 /* Login and update database */
2465 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2468 /* Exit if out of loop IDs. */
2469 if (rval
!= QLA_SUCCESS
) {
2474 * Login and add the new devices to our port list.
2476 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2477 if (atomic_read(&ha
->loop_down_timer
) ||
2478 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2481 /* Find a new loop ID to use. */
2482 fcport
->loop_id
= next_loopid
;
2483 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2484 if (rval
!= QLA_SUCCESS
) {
2485 /* Ran out of IDs to use */
2489 /* Login and update database */
2490 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2492 /* Remove device from the new list and add it to DB */
2493 list_del(&fcport
->list
);
2494 list_add_tail(&fcport
->list
, &ha
->fcports
);
2498 /* Free all new device structures not processed. */
2499 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2500 list_del(&fcport
->list
);
2505 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2506 "rval=%d\n", ha
->host_no
, rval
));
2514 * qla2x00_find_all_fabric_devs
2517 * ha = adapter block pointer.
2518 * dev = database device entry pointer.
2527 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*ha
, struct list_head
*new_fcports
)
2531 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
2536 int first_dev
, last_dev
;
2537 port_id_t wrap
, nxt_d_id
;
2541 /* Try GID_PT to get device list, else GAN. */
2542 swl
= kmalloc(sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
, GFP_ATOMIC
);
2545 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2546 "on GA_NXT\n", ha
->host_no
));
2548 memset(swl
, 0, sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
);
2549 if (qla2x00_gid_pt(ha
, swl
) != QLA_SUCCESS
) {
2552 } else if (qla2x00_gpn_id(ha
, swl
) != QLA_SUCCESS
) {
2555 } else if (qla2x00_gnn_id(ha
, swl
) != QLA_SUCCESS
) {
2562 /* Allocate temporary fcport for any new fcports discovered. */
2563 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2564 if (new_fcport
== NULL
) {
2567 return (QLA_MEMORY_ALLOC_FAILED
);
2569 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2571 /* Set start port ID scan at adapter ID. */
2575 /* Starting free loop ID. */
2576 loop_id
= ha
->min_external_loopid
;
2578 for (; loop_id
<= ha
->last_loop_id
; loop_id
++) {
2579 if (RESERVED_LOOP_ID(loop_id
))
2582 if (atomic_read(&ha
->loop_down_timer
) ||
2583 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2588 wrap
.b24
= new_fcport
->d_id
.b24
;
2590 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
2591 memcpy(new_fcport
->node_name
,
2592 swl
[swl_idx
].node_name
, WWN_SIZE
);
2593 memcpy(new_fcport
->port_name
,
2594 swl
[swl_idx
].port_name
, WWN_SIZE
);
2596 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
2602 /* Send GA_NXT to the switch */
2603 rval
= qla2x00_ga_nxt(ha
, new_fcport
);
2604 if (rval
!= QLA_SUCCESS
) {
2605 qla_printk(KERN_WARNING
, ha
,
2606 "SNS scan failed -- assuming zero-entry "
2608 list_for_each_entry_safe(fcport
, fcptemp
,
2609 new_fcports
, list
) {
2610 list_del(&fcport
->list
);
2618 /* If wrap on switch device list, exit. */
2620 wrap
.b24
= new_fcport
->d_id
.b24
;
2622 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
2623 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2624 ha
->host_no
, new_fcport
->d_id
.b
.domain
,
2625 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
2629 /* Bypass if host adapter. */
2630 if (new_fcport
->d_id
.b24
== ha
->d_id
.b24
)
2633 /* Bypass reserved domain fields. */
2634 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
2637 /* Locate matching device in database. */
2639 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2640 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2647 * If address the same and state FCS_ONLINE, nothing
2650 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
2651 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2656 * If device was not a fabric device before.
2658 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2659 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2660 fcport
->loop_id
= FC_NO_LOOP_ID
;
2661 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
2663 fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2668 * Port ID changed or device was marked to be updated;
2669 * Log it out if still logged in and mark it for
2672 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2673 fcport
->flags
|= FCF_LOGIN_NEEDED
;
2674 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2675 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2676 fcport
->port_type
!= FCT_INITIATOR
&&
2677 fcport
->port_type
!= FCT_BROADCAST
) {
2678 qla2x00_fabric_logout(ha
, fcport
->loop_id
);
2679 fcport
->loop_id
= FC_NO_LOOP_ID
;
2688 /* If device was not in our fcports list, then add it. */
2689 list_add_tail(&new_fcport
->list
, new_fcports
);
2691 /* Allocate a new replacement fcport. */
2692 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
2693 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2694 if (new_fcport
== NULL
) {
2697 return (QLA_MEMORY_ALLOC_FAILED
);
2699 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2700 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
2709 if (!list_empty(new_fcports
))
2710 ha
->device_flags
|= DFLG_FABRIC_DEVICES
;
2716 * qla2x00_find_new_loop_id
2717 * Scan through our port list and find a new usable loop ID.
2720 * ha: adapter state pointer.
2721 * dev: port structure pointer.
2724 * qla2x00 local function return status code.
2730 qla2x00_find_new_loop_id(scsi_qla_host_t
*ha
, fc_port_t
*dev
)
2735 uint16_t first_loop_id
;
2739 /* Save starting loop ID. */
2740 first_loop_id
= dev
->loop_id
;
2743 /* Skip loop ID if already used by adapter. */
2744 if (dev
->loop_id
== ha
->loop_id
) {
2748 /* Skip reserved loop IDs. */
2749 while (RESERVED_LOOP_ID(dev
->loop_id
)) {
2753 /* Reset loop ID if passed the end. */
2754 if (dev
->loop_id
> ha
->last_loop_id
) {
2755 /* first loop ID. */
2756 dev
->loop_id
= ha
->min_external_loopid
;
2759 /* Check for loop ID being already in use. */
2762 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2763 if (fcport
->loop_id
== dev
->loop_id
&& fcport
!= dev
) {
2764 /* ID possibly in use */
2770 /* If not in use then it is free to use. */
2775 /* ID in use. Try next value. */
2778 /* If wrap around. No free ID to use. */
2779 if (dev
->loop_id
== first_loop_id
) {
2780 dev
->loop_id
= FC_NO_LOOP_ID
;
2781 rval
= QLA_FUNCTION_FAILED
;
2790 * qla2x00_device_resync
2791 * Marks devices in the database that needs resynchronization.
2794 * ha = adapter block pointer.
2800 qla2x00_device_resync(scsi_qla_host_t
*ha
)
2806 uint32_t rscn_entry
;
2807 uint8_t rscn_out_iter
;
2811 rval
= QLA_RSCNS_HANDLED
;
2813 while (ha
->rscn_out_ptr
!= ha
->rscn_in_ptr
||
2814 ha
->flags
.rscn_queue_overflow
) {
2816 rscn_entry
= ha
->rscn_queue
[ha
->rscn_out_ptr
];
2817 format
= MSB(MSW(rscn_entry
));
2818 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
2819 d_id
.b
.area
= MSB(LSW(rscn_entry
));
2820 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
2822 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2823 "[%02x/%02x%02x%02x].\n",
2824 ha
->host_no
, ha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
2825 d_id
.b
.area
, d_id
.b
.al_pa
));
2828 if (ha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
2829 ha
->rscn_out_ptr
= 0;
2831 /* Skip duplicate entries. */
2832 for (rscn_out_iter
= ha
->rscn_out_ptr
;
2833 !ha
->flags
.rscn_queue_overflow
&&
2834 rscn_out_iter
!= ha
->rscn_in_ptr
;
2835 rscn_out_iter
= (rscn_out_iter
==
2836 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
2838 if (rscn_entry
!= ha
->rscn_queue
[rscn_out_iter
])
2841 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2842 "entry found at [%d].\n", ha
->host_no
,
2845 ha
->rscn_out_ptr
= rscn_out_iter
;
2848 /* Queue overflow, set switch default case. */
2849 if (ha
->flags
.rscn_queue_overflow
) {
2850 DEBUG(printk("scsi(%ld): device_resync: rscn "
2851 "overflow.\n", ha
->host_no
));
2854 ha
->flags
.rscn_queue_overflow
= 0;
2859 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) &&
2860 !IS_QLA6312(ha
) && !IS_QLA6322(ha
) &&
2861 ha
->flags
.init_done
) {
2862 /* Handle port RSCN via asyncronous IOCBs */
2863 rval2
= qla2x00_handle_port_rscn(ha
, rscn_entry
,
2865 if (rval2
== QLA_SUCCESS
)
2879 ha
->rscn_out_ptr
= ha
->rscn_in_ptr
;
2885 /* Abort any outstanding IO descriptors. */
2886 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
2887 qla2x00_cancel_io_descriptors(ha
);
2889 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2890 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2891 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
2892 fcport
->port_type
== FCT_BROADCAST
)
2895 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2897 fcport
->port_type
!= FCT_INITIATOR
) {
2898 atomic_set(&fcport
->state
,
2902 fcport
->flags
&= ~FCF_FARP_DONE
;
2909 * qla2x00_fabric_dev_login
2910 * Login fabric target device and update FC port database.
2913 * ha: adapter state pointer.
2914 * fcport: port structure list pointer.
2915 * next_loopid: contains value of a new loop ID that can be used
2916 * by the next login attempt.
2919 * qla2x00 local function return status code.
2925 qla2x00_fabric_dev_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2926 uint16_t *next_loopid
)
2934 rval
= qla2x00_fabric_login(ha
, fcport
, next_loopid
);
2935 if (rval
== QLA_SUCCESS
) {
2936 rval
= qla2x00_get_port_database(ha
, fcport
, 0);
2937 if (rval
!= QLA_SUCCESS
) {
2938 qla2x00_fabric_logout(ha
, fcport
->loop_id
);
2940 qla2x00_update_fcport(ha
, fcport
);
2948 * qla2x00_fabric_login
2949 * Issue fabric login command.
2952 * ha = adapter block pointer.
2953 * device = pointer to FC device type structure.
2956 * 0 - Login successfully
2958 * 2 - Initiator device
2962 qla2x00_fabric_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2963 uint16_t *next_loopid
)
2967 uint16_t tmp_loopid
;
2968 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2974 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2975 "for port %02x%02x%02x.\n",
2976 ha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2977 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2979 /* Login fcport on switch. */
2980 qla2x00_login_fabric(ha
, fcport
->loop_id
,
2981 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2982 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
2983 if (mb
[0] == MBS_PORT_ID_USED
) {
2985 * Device has another loop ID. The firmware team
2986 * recommends us to perform an implicit login with the
2987 * specified ID again. The ID we just used is save here
2988 * so we return with an ID that can be tried by the
2992 tmp_loopid
= fcport
->loop_id
;
2993 fcport
->loop_id
= mb
[1];
2995 DEBUG(printk("Fabric Login: port in use - next "
2996 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2997 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2998 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3000 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
3005 /* A retry occurred before. */
3006 *next_loopid
= tmp_loopid
;
3009 * No retry occurred before. Just increment the
3010 * ID value for next login.
3012 *next_loopid
= (fcport
->loop_id
+ 1);
3015 if (mb
[1] & BIT_0
) {
3016 fcport
->port_type
= FCT_INITIATOR
;
3018 fcport
->port_type
= FCT_TARGET
;
3019 if (mb
[1] & BIT_1
) {
3020 fcport
->flags
|= FCF_TAPE_PRESENT
;
3026 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
3028 * Loop ID already used, try next loop ID.
3031 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
3032 if (rval
!= QLA_SUCCESS
) {
3033 /* Ran out of loop IDs to use */
3036 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
3038 * Firmware possibly timed out during login. If NO
3039 * retries are left to do then the device is declared
3042 *next_loopid
= fcport
->loop_id
;
3043 qla2x00_fabric_logout(ha
, fcport
->loop_id
);
3044 qla2x00_mark_device_lost(ha
, fcport
, 1);
3050 * unrecoverable / not handled error
3052 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3053 "loop_id=%x jiffies=%lx.\n",
3054 __func__
, ha
->host_no
, mb
[0],
3055 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3056 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
3058 *next_loopid
= fcport
->loop_id
;
3059 qla2x00_fabric_logout(ha
, fcport
->loop_id
);
3060 fcport
->loop_id
= FC_NO_LOOP_ID
;
3061 atomic_set(&fcport
->state
, FCS_DEVICE_DEAD
);
3072 * qla2x00_local_device_login
3073 * Issue local device login command.
3076 * ha = adapter block pointer.
3077 * loop_id = loop id of device to login to.
3079 * Returns (Where's the #define!!!!):
3080 * 0 - Login successfully
3085 qla2x00_local_device_login(scsi_qla_host_t
*ha
, uint16_t loop_id
)
3088 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3090 memset(mb
, 0, sizeof(mb
));
3091 rval
= qla2x00_login_local_device(ha
, loop_id
, mb
, BIT_0
);
3092 if (rval
== QLA_SUCCESS
) {
3093 /* Interrogate mailbox registers for any errors */
3094 if (mb
[0] == MBS_COMMAND_ERROR
)
3096 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
3097 /* device not in PCB table */
3105 * qla2x00_loop_resync
3106 * Resync with fibre channel devices.
3109 * ha = adapter block pointer.
3115 qla2x00_loop_resync(scsi_qla_host_t
*ha
)
3122 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
3123 qla2x00_stats
.loop_resync
++;
3124 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3125 if (ha
->flags
.online
) {
3126 if (!(rval
= qla2x00_fw_ready(ha
))) {
3127 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3131 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
3134 * Issue marker command only when we are going
3135 * to start the I/O .
3137 ha
->marker_needed
= 1;
3139 /* Remap devices on Loop. */
3140 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3142 qla2x00_configure_loop(ha
);
3144 } while (!atomic_read(&ha
->loop_down_timer
) &&
3145 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3147 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3149 qla2x00_restart_queues(ha
, 1);
3152 if (test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
3153 return (QLA_FUNCTION_FAILED
);
3157 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
3164 * qla2x00_restart_queues
3165 * Restart device queues.
3168 * ha = adapter block pointer.
3171 * Kernel/Interrupt context.
3174 qla2x00_restart_queues(scsi_qla_host_t
*ha
, uint8_t flush
)
3177 int retry_q_cnt
= 0;
3178 int pending_q_cnt
= 0;
3179 struct list_head
*list
, *temp
;
3180 unsigned long flags
= 0;
3182 clear_bit(RESTART_QUEUES_NEEDED
, &ha
->dpc_flags
);
3184 /* start pending queue */
3185 pending_q_cnt
= ha
->qthreads
;
3187 spin_lock_irqsave(&ha
->list_lock
,flags
);
3188 list_for_each_safe(list
, temp
, &ha
->pending_queue
) {
3189 sp
= list_entry(list
, srb_t
, list
);
3191 if ((sp
->flags
& SRB_TAPE
))
3195 * When time expire return request back to OS as BUSY
3197 __del_from_pending_queue(ha
, sp
);
3198 sp
->cmd
->result
= DID_BUS_BUSY
<< 16;
3199 sp
->cmd
->host_scribble
= (unsigned char *)NULL
;
3200 __add_to_done_queue(ha
, sp
);
3202 spin_unlock_irqrestore(&ha
->list_lock
, flags
);
3204 if (!list_empty(&ha
->pending_queue
))
3209 * Clear out our retry queue
3212 spin_lock_irqsave(&ha
->list_lock
, flags
);
3213 retry_q_cnt
= ha
->retry_q_cnt
;
3214 list_for_each_safe(list
, temp
, &ha
->retry_queue
) {
3215 sp
= list_entry(list
, srb_t
, list
);
3216 /* when time expire return request back to OS as BUSY */
3217 __del_from_retry_queue(ha
, sp
);
3218 sp
->cmd
->result
= DID_BUS_BUSY
<< 16;
3219 sp
->cmd
->host_scribble
= (unsigned char *)NULL
;
3220 __add_to_done_queue(ha
, sp
);
3222 spin_unlock_irqrestore(&ha
->list_lock
, flags
);
3224 DEBUG2(printk("%s(%ld): callback %d commands.\n",
3230 DEBUG2(printk("%s(%ld): active=%ld, retry=%d, pending=%d, "
3231 "done=%ld, scsi retry=%d commands.\n",
3238 ha
->scsi_retry_q_cnt
);)
3240 if (!list_empty(&ha
->done_queue
))
3245 qla2x00_rescan_fcports(scsi_qla_host_t
*ha
)
3251 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
3252 if ((fcport
->flags
& FCF_RESCAN_NEEDED
) == 0)
3255 qla2x00_update_fcport(ha
, fcport
);
3256 fcport
->flags
&= ~FCF_RESCAN_NEEDED
;
3260 qla2x00_probe_for_all_luns(ha
);
3262 /* Update OS target and lun structures if necessary. */
3264 qla2x00_config_os(ha
);
3271 * Setup OS target and LUN structures.
3274 * ha = adapter state pointer.
3280 qla2x00_config_os(scsi_qla_host_t
*ha
)
3288 for (tgt
= 0; tgt
< MAX_TARGETS
; tgt
++) {
3289 if ((tq
= TGT_Q(ha
, tgt
)) == NULL
)
3292 clear_bit(TQF_ONLINE
, &tq
->flags
);
3295 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
3296 if (atomic_read(&fcport
->state
) != FCS_ONLINE
||
3297 fcport
->port_type
== FCT_INITIATOR
||
3298 fcport
->port_type
== FCT_BROADCAST
) {
3299 fcport
->os_target_id
= MAX_TARGETS
;
3303 if (fcport
->flags
& FCF_FO_MASKED
) {
3307 /* Bind FC port to OS target number. */
3308 if (qla2x00_fcport_bind(ha
, fcport
) == MAX_TARGETS
) {
3312 /* Bind FC LUN to OS LUN number. */
3313 list_for_each_entry(fclun
, &fcport
->fcluns
, list
) {
3314 qla2x00_fclun_bind(ha
, fcport
, fclun
);
3320 * qla2x00_fcport_bind
3321 * Locates a target number for FC port.
3324 * ha = adapter state pointer.
3325 * fcport = FC port structure pointer.
3334 qla2x00_fcport_bind(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
3340 /* Check for persistent binding. */
3341 for (tgt
= 0; tgt
< MAX_TARGETS
; tgt
++) {
3342 if ((tq
= TGT_Q(ha
, tgt
)) == NULL
)
3346 switch (ha
->binding_type
) {
3347 case BIND_BY_PORT_ID
:
3348 if (fcport
->d_id
.b24
== tq
->d_id
.b24
) {
3349 memcpy(tq
->node_name
, fcport
->node_name
,
3351 memcpy(tq
->port_name
, fcport
->port_name
,
3356 case BIND_BY_PORT_NAME
:
3357 if (memcmp(fcport
->port_name
, tq
->port_name
,
3360 * In case of persistent binding, update the
3363 memcpy(tq
->node_name
, fcport
->node_name
,
3373 /* TODO: honor the ConfigRequired flag */
3374 if (tgt
== MAX_TARGETS
) {
3375 /* Check if targetID 0 available. */
3378 if (TGT_Q(ha
, tgt
) != NULL
) {
3379 /* Locate first free target for device. */
3380 for (tgt
= 0; tgt
< MAX_TARGETS
; tgt
++) {
3381 if (TGT_Q(ha
, tgt
) == NULL
) {
3386 if (tgt
!= MAX_TARGETS
) {
3387 if ((tq
= qla2x00_tgt_alloc(ha
, tgt
)) != NULL
) {
3388 memcpy(tq
->node_name
, fcport
->node_name
,
3390 memcpy(tq
->port_name
, fcport
->port_name
,
3392 tq
->d_id
.b24
= fcport
->d_id
.b24
;
3397 /* Reset target numbers incase it changed. */
3398 fcport
->os_target_id
= tgt
;
3399 if (tgt
!= MAX_TARGETS
&& tq
!= NULL
) {
3400 DEBUG2(printk("scsi(%ld): Assigning target ID=%02d @ %p to "
3401 "loop id=0x%04x, port state=0x%x, port down retry=%d\n",
3402 ha
->host_no
, tgt
, tq
, fcport
->loop_id
,
3403 atomic_read(&fcport
->state
),
3404 atomic_read(&fcport
->port_down_timer
)));
3406 fcport
->tgt_queue
= tq
;
3407 fcport
->flags
|= FCF_PERSISTENT_BOUND
;
3408 tq
->fcport
= fcport
;
3409 set_bit(TQF_ONLINE
, &tq
->flags
);
3410 tq
->port_down_retry_count
= ha
->port_down_retry_count
;
3413 if (tgt
== MAX_TARGETS
) {
3414 qla_printk(KERN_WARNING
, ha
,
3415 "Unable to bind fcport, loop_id=%x\n", fcport
->loop_id
);
3422 * qla2x00_fclun_bind
3423 * Binds all FC device LUNS to OS LUNS.
3426 * ha: adapter state pointer.
3427 * fcport: FC port structure pointer.
3436 qla2x00_fclun_bind(scsi_qla_host_t
*ha
, fc_port_t
*fcport
, fc_lun_t
*fclun
)
3442 tgt
= fcport
->os_target_id
;
3446 if (lun
>= MAX_LUNS
) {
3447 DEBUG2(printk("scsi(%ld): Unable to bind lun, invalid "
3448 "lun=(%x).\n", ha
->host_no
, lun
));
3452 /* Always alloc LUN 0 so kernel will scan past LUN 0. */
3453 if (lun
!= 0 && (EXT_IS_LUN_BIT_SET(&(fcport
->lun_mask
), lun
))) {
3457 if ((lq
= qla2x00_lun_alloc(ha
, tgt
, lun
)) == NULL
) {
3458 qla_printk(KERN_WARNING
, ha
,
3459 "Unable to bind fclun, loop_id=%x lun=%x\n",
3460 fcport
->loop_id
, lun
);
3471 * Allocate and pre-initialize target queue.
3474 * ha = adapter block pointer.
3475 * t = SCSI target number.
3484 qla2x00_tgt_alloc(scsi_qla_host_t
*ha
, uint16_t tgt
)
3489 * If SCSI addressing OK, allocate TGT queue and lock.
3491 if (tgt
>= MAX_TARGETS
) {
3492 DEBUG2(printk("scsi(%ld): Unable to allocate target, invalid "
3493 "target number %d.\n", ha
->host_no
, tgt
));
3497 tq
= TGT_Q(ha
, tgt
);
3499 tq
= kmalloc(sizeof(os_tgt_t
), GFP_ATOMIC
);
3501 DEBUG2(printk("scsi(%ld): Alloc Target %d @ %p\n",
3502 ha
->host_no
, tgt
, tq
));
3504 memset(tq
, 0, sizeof(os_tgt_t
));
3507 TGT_Q(ha
, tgt
) = tq
;
3511 tq
->port_down_retry_count
= ha
->port_down_retry_count
;
3513 qla_printk(KERN_WARNING
, ha
,
3514 "Unable to allocate target.\n");
3523 * Frees target and LUN queues.
3526 * ha = adapter block pointer.
3527 * t = SCSI target number.
3533 qla2x00_tgt_free(scsi_qla_host_t
*ha
, uint16_t tgt
)
3539 * If SCSI addressing OK, allocate TGT queue and lock.
3541 if (tgt
>= MAX_TARGETS
) {
3542 DEBUG2(printk("scsi(%ld): Unable to de-allocate target, "
3543 "invalid target number %d.\n", ha
->host_no
, tgt
));
3548 tq
= TGT_Q(ha
, tgt
);
3550 TGT_Q(ha
, tgt
) = NULL
;
3552 /* Free LUN structures. */
3553 for (lun
= 0; lun
< MAX_LUNS
; lun
++)
3554 qla2x00_lun_free(ha
, tgt
, lun
);
3564 * Allocate and initialize LUN queue.
3567 * ha = adapter block pointer.
3568 * t = SCSI target number.
3578 qla2x00_lun_alloc(scsi_qla_host_t
*ha
, uint16_t tgt
, uint16_t lun
)
3583 * If SCSI addressing OK, allocate LUN queue.
3585 if (tgt
>= MAX_TARGETS
|| lun
>= MAX_LUNS
|| TGT_Q(ha
, tgt
) == NULL
) {
3586 DEBUG2(printk("scsi(%ld): Unable to allocate lun, invalid "
3587 "parameter.\n", ha
->host_no
));
3592 lq
= LUN_Q(ha
, tgt
, lun
);
3594 lq
= kmalloc(sizeof(os_lun_t
), GFP_ATOMIC
);
3596 DEBUG2(printk("scsi(%ld): Alloc Lun %d @ tgt %d.\n",
3597 ha
->host_no
, lun
, tgt
));
3599 memset(lq
, 0, sizeof(os_lun_t
));
3600 LUN_Q(ha
, tgt
, lun
) = lq
;
3603 * The following lun queue initialization code
3604 * must be duplicated in alloc_ioctl_mem function
3607 lq
->q_state
= LUN_STATE_READY
;
3608 spin_lock_init(&lq
->q_lock
);
3613 qla_printk(KERN_WARNING
, ha
, "Unable to allocate lun.\n");
3624 * ha = adapter block pointer.
3625 * t = SCSI target number.
3631 qla2x00_lun_free(scsi_qla_host_t
*ha
, uint16_t tgt
, uint16_t lun
)
3636 * If SCSI addressing OK, allocate TGT queue and lock.
3638 if (tgt
>= MAX_TARGETS
|| lun
>= MAX_LUNS
) {
3639 DEBUG2(printk("scsi(%ld): Unable to deallocate lun, invalid "
3640 "parameter.\n", ha
->host_no
));
3645 if (TGT_Q(ha
, tgt
) != NULL
&& (lq
= LUN_Q(ha
, tgt
, lun
)) != NULL
) {
3646 LUN_Q(ha
, tgt
, lun
) = NULL
;
3655 * Resets ISP and aborts all outstanding commands.
3658 * ha = adapter block pointer.
3664 qla2x00_abort_isp(scsi_qla_host_t
*ha
)
3666 unsigned long flags
= 0;
3671 if (ha
->flags
.online
) {
3672 ha
->flags
.online
= 0;
3673 clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
3674 qla2x00_stats
.ispAbort
++;
3675 ha
->total_isp_aborts
++; /* used by ioctl */
3676 ha
->sns_retry_cnt
= 0;
3678 qla_printk(KERN_INFO
, ha
,
3679 "Performing ISP error recovery - ha= %p.\n", ha
);
3680 qla2x00_reset_chip(ha
);
3682 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
3683 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
3684 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
3685 qla2x00_mark_all_devices_lost(ha
);
3687 if (!atomic_read(&ha
->loop_down_timer
))
3688 atomic_set(&ha
->loop_down_timer
,
3692 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3693 /* Requeue all commands in outstanding command list. */
3694 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
3695 sp
= ha
->outstanding_cmds
[cnt
];
3697 ha
->outstanding_cmds
[cnt
] = NULL
;
3700 sp
->lun_queue
->out_cnt
--;
3703 * Set the cmd host_byte status depending on
3704 * whether the scsi_error_handler is
3707 if (sp
->flags
& SRB_TAPE
) {
3708 sp
->cmd
->result
= DID_NO_CONNECT
<< 16;
3710 if (ha
->host
->eh_active
!= EH_ACTIVE
)
3718 sp
->cmd
->host_scribble
= (unsigned char *)NULL
;
3719 add_to_done_queue(ha
, sp
);
3722 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3724 qla2x00_nvram_config(ha
);
3726 if (!qla2x00_restart_isp(ha
)) {
3727 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3729 if (!atomic_read(&ha
->loop_down_timer
)) {
3731 * Issue marker command only when we are going
3732 * to start the I/O .
3734 ha
->marker_needed
= 1;
3737 ha
->flags
.online
= 1;
3739 /* Enable ISP interrupts. */
3740 qla2x00_enable_intrs(ha
);
3742 /* v2.19.5b6 Return all commands */
3743 qla2x00_abort_queues(ha
, 1);
3745 /* Restart queues that may have been stopped. */
3746 qla2x00_restart_queues(ha
, 1);
3747 ha
->isp_abort_cnt
= 0;
3748 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3749 } else { /* failed the ISP abort */
3750 ha
->flags
.online
= 1;
3751 if (test_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
)) {
3752 if (ha
->isp_abort_cnt
== 0) {
3753 qla_printk(KERN_WARNING
, ha
,
3754 "ISP error recovery failed - "
3755 "board disabled\n");
3757 * The next call disables the board
3760 qla2x00_reset_adapter(ha
);
3761 qla2x00_abort_queues(ha
, 0);
3762 ha
->flags
.online
= 0;
3763 clear_bit(ISP_ABORT_RETRY
,
3766 } else { /* schedule another ISP abort */
3767 ha
->isp_abort_cnt
--;
3768 DEBUG(printk("qla%ld: ISP abort - "
3769 "retry remainning %d\n",
3770 ha
->host_no
, ha
->isp_abort_cnt
);)
3774 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3775 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3776 "- retrying (%d) more times\n",
3777 ha
->host_no
, ha
->isp_abort_cnt
);)
3778 set_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3786 qla_printk(KERN_INFO
, ha
,
3787 "qla2x00_abort_isp: **** FAILED ****\n");
3789 DEBUG(printk(KERN_INFO
3790 "qla2x00_abort_isp(%ld): exiting.\n",
3798 * qla2x00_restart_isp
3799 * restarts the ISP after a reset
3802 * ha = adapter block pointer.
3808 qla2x00_restart_isp(scsi_qla_host_t
*ha
)
3811 device_reg_t __iomem
*reg
= ha
->iobase
;
3812 unsigned long flags
= 0;
3815 /* If firmware needs to be loaded */
3816 if (qla2x00_isp_firmware(ha
)) {
3817 ha
->flags
.online
= 0;
3818 if (!(status
= qla2x00_chip_diag(ha
))) {
3819 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
3820 status
= qla2x00_setup_chip(ha
);
3826 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3828 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3829 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
3830 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3832 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3834 status
= qla2x00_setup_chip(ha
);
3836 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3838 /* Enable proper parity */
3841 WRT_REG_WORD(®
->hccr
,
3842 (HCCR_ENABLE_PARITY
+ 0x1));
3844 /* SRAM, Instruction RAM and GP RAM parity */
3845 WRT_REG_WORD(®
->hccr
,
3846 (HCCR_ENABLE_PARITY
+ 0x7));
3847 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3849 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3854 if (!status
&& !(status
= qla2x00_init_rings(ha
))) {
3855 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3856 if (!(status
= qla2x00_fw_ready(ha
))) {
3857 DEBUG(printk("%s(): Start configure loop, "
3861 ha
->flags
.online
= 1;
3862 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3865 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3866 qla2x00_configure_loop(ha
);
3868 } while (!atomic_read(&ha
->loop_down_timer
) &&
3869 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3871 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3874 /* if no cable then assume it's good */
3875 if ((ha
->device_flags
& DFLG_NO_CABLE
))
3878 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3886 * qla2x00_reset_adapter
3890 * ha = adapter block pointer.
3893 qla2x00_reset_adapter(scsi_qla_host_t
*ha
)
3895 unsigned long flags
= 0;
3896 device_reg_t __iomem
*reg
= ha
->iobase
;
3898 ha
->flags
.online
= 0;
3899 qla2x00_disable_intrs(ha
);
3901 /* Reset RISC processor. */
3902 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3903 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3904 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3905 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3906 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3907 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);