2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2010 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
8 #include <scsi/iscsi_if.h>
12 #include "ql4_inline.h"
14 static void ql4xxx_set_mac_number(struct scsi_qla_host
*ha
)
20 /* Get the function number */
21 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
22 value
= readw(&ha
->reg
->ctrl_status
);
23 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
25 func_number
= (uint8_t) ((value
>> 4) & 0x30);
26 switch (value
& ISP_CONTROL_FN_MASK
) {
27 case ISP_CONTROL_FN0_SCSI
:
30 case ISP_CONTROL_FN1_SCSI
:
34 DEBUG2(printk("scsi%ld: %s: Invalid function number, "
35 "ispControlStatus = 0x%x\n", ha
->host_no
,
39 DEBUG2(printk("scsi%ld: %s: mac_index %d.\n", ha
->host_no
, __func__
,
44 * qla4xxx_free_ddb - deallocate ddb
45 * @ha: pointer to host adapter structure.
46 * @ddb_entry: pointer to device database entry
48 * This routine marks a DDB entry INVALID
50 void qla4xxx_free_ddb(struct scsi_qla_host
*ha
,
51 struct ddb_entry
*ddb_entry
)
53 /* Remove device pointer from index mapping arrays */
54 ha
->fw_ddb_index_map
[ddb_entry
->fw_ddb_index
] =
55 (struct ddb_entry
*) INVALID_ENTRY
;
60 * qla4xxx_init_response_q_entries() - Initializes response queue entries.
63 * Beginning of request ring has initialization control block already built
64 * by nvram config routine.
66 static void qla4xxx_init_response_q_entries(struct scsi_qla_host
*ha
)
71 pkt
= (struct response
*)ha
->response_ptr
;
72 for (cnt
= 0; cnt
< RESPONSE_QUEUE_DEPTH
; cnt
++) {
73 pkt
->signature
= RESPONSE_PROCESSED
;
79 * qla4xxx_init_rings - initialize hw queues
80 * @ha: pointer to host adapter structure.
82 * This routine initializes the internal queues for the specified adapter.
83 * The QLA4010 requires us to restart the queues at index 0.
84 * The QLA4000 doesn't care, so just default to QLA4010's requirement.
86 int qla4xxx_init_rings(struct scsi_qla_host
*ha
)
88 unsigned long flags
= 0;
90 /* Initialize request queue. */
91 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
94 ha
->request_ptr
= &ha
->request_ring
[ha
->request_in
];
95 ha
->req_q_count
= REQUEST_QUEUE_DEPTH
;
97 /* Initialize response queue. */
100 ha
->response_ptr
= &ha
->response_ring
[ha
->response_out
];
102 if (is_qla8022(ha
)) {
104 (unsigned long __iomem
*)&ha
->qla4_8xxx_reg
->req_q_out
);
106 (unsigned long __iomem
*)&ha
->qla4_8xxx_reg
->rsp_q_in
);
108 (unsigned long __iomem
*)&ha
->qla4_8xxx_reg
->rsp_q_out
);
111 * Initialize DMA Shadow registers. The firmware is really
112 * supposed to take care of this, but on some uniprocessor
113 * systems, the shadow registers aren't cleared-- causing
114 * the interrupt_handler to think there are responses to be
115 * processed when there aren't.
117 ha
->shadow_regs
->req_q_out
= __constant_cpu_to_le32(0);
118 ha
->shadow_regs
->rsp_q_in
= __constant_cpu_to_le32(0);
121 writel(0, &ha
->reg
->req_q_in
);
122 writel(0, &ha
->reg
->rsp_q_out
);
123 readl(&ha
->reg
->rsp_q_out
);
126 qla4xxx_init_response_q_entries(ha
);
128 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
134 * qla4xxx_get_sys_info - validate adapter MAC address(es)
135 * @ha: pointer to host adapter structure.
138 int qla4xxx_get_sys_info(struct scsi_qla_host
*ha
)
140 struct flash_sys_info
*sys_info
;
141 dma_addr_t sys_info_dma
;
142 int status
= QLA_ERROR
;
144 sys_info
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*sys_info
),
145 &sys_info_dma
, GFP_KERNEL
);
146 if (sys_info
== NULL
) {
147 DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
148 ha
->host_no
, __func__
));
150 goto exit_get_sys_info_no_free
;
152 memset(sys_info
, 0, sizeof(*sys_info
));
154 /* Get flash sys info */
155 if (qla4xxx_get_flash(ha
, sys_info_dma
, FLASH_OFFSET_SYS_INFO
,
156 sizeof(*sys_info
)) != QLA_SUCCESS
) {
157 DEBUG2(printk("scsi%ld: %s: get_flash FLASH_OFFSET_SYS_INFO "
158 "failed\n", ha
->host_no
, __func__
));
160 goto exit_get_sys_info
;
163 /* Save M.A.C. address & serial_number */
164 memcpy(ha
->my_mac
, &sys_info
->physAddr
[0].address
[0],
165 min(sizeof(ha
->my_mac
),
166 sizeof(sys_info
->physAddr
[0].address
)));
167 memcpy(ha
->serial_number
, &sys_info
->acSerialNumber
,
168 min(sizeof(ha
->serial_number
),
169 sizeof(sys_info
->acSerialNumber
)));
171 status
= QLA_SUCCESS
;
174 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*sys_info
), sys_info
,
177 exit_get_sys_info_no_free
:
182 * qla4xxx_init_local_data - initialize adapter specific local data
183 * @ha: pointer to host adapter structure.
186 static int qla4xxx_init_local_data(struct scsi_qla_host
*ha
)
188 /* Initialize aen queue */
189 ha
->aen_q_count
= MAX_AEN_ENTRIES
;
191 return qla4xxx_get_firmware_status(ha
);
195 qla4xxx_wait_for_ip_config(struct scsi_qla_host
*ha
)
197 uint8_t ipv4_wait
= 0;
198 uint8_t ipv6_wait
= 0;
199 int8_t ip_address
[IPv6_ADDR_LEN
] = {0} ;
201 /* If both IPv4 & IPv6 are enabled, possibly only one
202 * IP address may be acquired, so check to see if we
203 * need to wait for another */
204 if (is_ipv4_enabled(ha
) && is_ipv6_enabled(ha
)) {
205 if (((ha
->addl_fw_state
& FW_ADDSTATE_DHCPv4_ENABLED
) != 0) &&
206 ((ha
->addl_fw_state
&
207 FW_ADDSTATE_DHCPv4_LEASE_ACQUIRED
) == 0)) {
210 if (((ha
->ip_config
.ipv6_addl_options
&
211 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE
) != 0) &&
212 ((ha
->ip_config
.ipv6_link_local_state
==
213 IP_ADDRSTATE_ACQUIRING
) ||
214 (ha
->ip_config
.ipv6_addr0_state
==
215 IP_ADDRSTATE_ACQUIRING
) ||
216 (ha
->ip_config
.ipv6_addr1_state
==
217 IP_ADDRSTATE_ACQUIRING
))) {
221 if ((ha
->ip_config
.ipv6_link_local_state
==
222 IP_ADDRSTATE_PREFERRED
) ||
223 (ha
->ip_config
.ipv6_addr0_state
==
224 IP_ADDRSTATE_PREFERRED
) ||
225 (ha
->ip_config
.ipv6_addr1_state
==
226 IP_ADDRSTATE_PREFERRED
)) {
227 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: "
228 "Preferred IP configured."
229 " Don't wait!\n", ha
->host_no
,
233 if (memcmp(&ha
->ip_config
.ipv6_default_router_addr
,
234 ip_address
, IPv6_ADDR_LEN
) == 0) {
235 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: "
236 "No Router configured. "
237 "Don't wait!\n", ha
->host_no
,
241 if ((ha
->ip_config
.ipv6_default_router_state
==
242 IPV6_RTRSTATE_MANUAL
) &&
243 (ha
->ip_config
.ipv6_link_local_state
==
244 IP_ADDRSTATE_TENTATIVE
) &&
245 (memcmp(&ha
->ip_config
.ipv6_link_local_addr
,
246 &ha
->ip_config
.ipv6_default_router_addr
, 4) ==
248 DEBUG2(printk("scsi%ld: %s: LinkLocal Router & "
249 "IP configured. Don't wait!\n",
250 ha
->host_no
, __func__
));
254 if (ipv4_wait
|| ipv6_wait
) {
255 DEBUG2(printk("scsi%ld: %s: Wait for additional "
256 "IP(s) \"", ha
->host_no
, __func__
));
258 DEBUG2(printk("IPv4 "));
259 if (ha
->ip_config
.ipv6_link_local_state
==
260 IP_ADDRSTATE_ACQUIRING
)
261 DEBUG2(printk("IPv6LinkLocal "));
262 if (ha
->ip_config
.ipv6_addr0_state
==
263 IP_ADDRSTATE_ACQUIRING
)
264 DEBUG2(printk("IPv6Addr0 "));
265 if (ha
->ip_config
.ipv6_addr1_state
==
266 IP_ADDRSTATE_ACQUIRING
)
267 DEBUG2(printk("IPv6Addr1 "));
268 DEBUG2(printk("\"\n"));
272 return ipv4_wait
|ipv6_wait
;
275 static int qla4xxx_fw_ready(struct scsi_qla_host
*ha
)
277 uint32_t timeout_count
;
280 DEBUG2(ql4_printk(KERN_INFO
, ha
, "Waiting for Firmware Ready..\n"));
281 for (timeout_count
= ADAPTER_INIT_TOV
; timeout_count
> 0;
283 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR
, &ha
->dpc_flags
))
284 qla4xxx_get_dhcp_ip_address(ha
);
286 /* Get firmware state. */
287 if (qla4xxx_get_firmware_state(ha
) != QLA_SUCCESS
) {
288 DEBUG2(printk("scsi%ld: %s: unable to get firmware "
289 "state\n", ha
->host_no
, __func__
));
293 if (ha
->firmware_state
& FW_STATE_ERROR
) {
294 DEBUG2(printk("scsi%ld: %s: an unrecoverable error has"
295 " occurred\n", ha
->host_no
, __func__
));
299 if (ha
->firmware_state
& FW_STATE_CONFIG_WAIT
) {
301 * The firmware has not yet been issued an Initialize
302 * Firmware command, so issue it now.
304 if (qla4xxx_initialize_fw_cb(ha
) == QLA_ERROR
)
307 /* Go back and test for ready state - no wait. */
311 if (ha
->firmware_state
& FW_STATE_WAIT_AUTOCONNECT
) {
312 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: fwstate:"
313 "AUTOCONNECT in progress\n",
314 ha
->host_no
, __func__
));
317 if (ha
->firmware_state
& FW_STATE_CONFIGURING_IP
) {
318 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: fwstate:"
320 ha
->host_no
, __func__
));
322 * Check for link state after 15 secs and if link is
323 * still DOWN then, cable is unplugged. Ignore "DHCP
324 * in Progress/CONFIGURING IP" bit to check if firmware
325 * is in ready state or not after 15 secs.
326 * This is applicable for both 2.x & 3.x firmware
328 if (timeout_count
<= (ADAPTER_INIT_TOV
- 15)) {
329 if (ha
->addl_fw_state
& FW_ADDSTATE_LINK_UP
) {
330 DEBUG2(printk(KERN_INFO
"scsi%ld: %s:"
331 " LINK UP (Cable plugged)\n",
332 ha
->host_no
, __func__
));
333 } else if (ha
->firmware_state
&
334 (FW_STATE_CONFIGURING_IP
|
336 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: "
337 "LINK DOWN (Cable unplugged)\n",
338 ha
->host_no
, __func__
));
339 ha
->firmware_state
= FW_STATE_READY
;
344 if (ha
->firmware_state
== FW_STATE_READY
) {
345 /* If DHCP IP Addr is available, retrieve it now. */
346 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR
,
348 qla4xxx_get_dhcp_ip_address(ha
);
350 if (!qla4xxx_wait_for_ip_config(ha
) ||
351 timeout_count
== 1) {
352 DEBUG2(ql4_printk(KERN_INFO
, ha
,
353 "Firmware Ready..\n"));
354 /* The firmware is ready to process SCSI
356 DEBUG2(ql4_printk(KERN_INFO
, ha
,
357 "scsi%ld: %s: MEDIA TYPE"
358 " - %s\n", ha
->host_no
,
359 __func__
, (ha
->addl_fw_state
&
360 FW_ADDSTATE_OPTICAL_MEDIA
)
361 != 0 ? "OPTICAL" : "COPPER"));
362 DEBUG2(ql4_printk(KERN_INFO
, ha
,
363 "scsi%ld: %s: DHCPv4 STATE"
364 " Enabled %s\n", ha
->host_no
,
365 __func__
, (ha
->addl_fw_state
&
366 FW_ADDSTATE_DHCPv4_ENABLED
) != 0 ?
368 DEBUG2(ql4_printk(KERN_INFO
, ha
,
369 "scsi%ld: %s: LINK %s\n",
370 ha
->host_no
, __func__
,
372 FW_ADDSTATE_LINK_UP
) != 0 ?
374 DEBUG2(ql4_printk(KERN_INFO
, ha
,
375 "scsi%ld: %s: iSNS Service "
377 ha
->host_no
, __func__
,
379 FW_ADDSTATE_ISNS_SVC_ENABLED
) != 0 ?
386 DEBUG2(printk("scsi%ld: %s: waiting on fw, state=%x:%x - "
387 "seconds expired= %d\n", ha
->host_no
, __func__
,
388 ha
->firmware_state
, ha
->addl_fw_state
,
390 if (is_qla4032(ha
) &&
391 !(ha
->addl_fw_state
& FW_ADDSTATE_LINK_UP
) &&
392 (timeout_count
< ADAPTER_INIT_TOV
- 5)) {
399 if (timeout_count
<= 0)
400 DEBUG2(printk("scsi%ld: %s: FW Initialization timed out!\n",
401 ha
->host_no
, __func__
));
403 if (ha
->firmware_state
& FW_STATE_CONFIGURING_IP
) {
404 DEBUG2(printk("scsi%ld: %s: FW initialized, but is reporting "
405 "it's waiting to configure an IP address\n",
406 ha
->host_no
, __func__
));
408 } else if (ha
->firmware_state
& FW_STATE_WAIT_AUTOCONNECT
) {
409 DEBUG2(printk("scsi%ld: %s: FW initialized, but "
410 "auto-discovery still in process\n",
411 ha
->host_no
, __func__
));
419 * qla4xxx_init_firmware - initializes the firmware.
420 * @ha: pointer to host adapter structure.
423 static int qla4xxx_init_firmware(struct scsi_qla_host
*ha
)
425 int status
= QLA_ERROR
;
427 if (is_aer_supported(ha
) &&
428 test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE
, &ha
->flags
))
431 /* For 82xx, stop firmware before initializing because if BIOS
432 * has previously initialized firmware, then driver's initialize
433 * firmware will fail. */
435 qla4_8xxx_stop_firmware(ha
);
437 ql4_printk(KERN_INFO
, ha
, "Initializing firmware..\n");
438 if (qla4xxx_initialize_fw_cb(ha
) == QLA_ERROR
) {
439 DEBUG2(printk("scsi%ld: %s: Failed to initialize firmware "
440 "control block\n", ha
->host_no
, __func__
));
443 if (!qla4xxx_fw_ready(ha
))
446 return qla4xxx_get_firmware_status(ha
);
449 static void qla4xxx_set_model_info(struct scsi_qla_host
*ha
)
451 uint16_t board_id_string
[8];
453 int size
= sizeof(ha
->nvram
->isp4022
.boardIdStr
);
454 int offset
= offsetof(struct eeprom_data
, isp4022
.boardIdStr
) / 2;
456 for (i
= 0; i
< (size
/ 2) ; i
++) {
457 board_id_string
[i
] = rd_nvram_word(ha
, offset
);
461 memcpy(ha
->model_name
, board_id_string
, size
);
464 static int qla4xxx_config_nvram(struct scsi_qla_host
*ha
)
467 union external_hw_config_reg extHwConfig
;
469 DEBUG2(printk("scsi%ld: %s: Get EEProm parameters \n", ha
->host_no
,
471 if (ql4xxx_lock_flash(ha
) != QLA_SUCCESS
)
473 if (ql4xxx_lock_nvram(ha
) != QLA_SUCCESS
) {
474 ql4xxx_unlock_flash(ha
);
478 /* Get EEPRom Parameters from NVRAM and validate */
479 ql4_printk(KERN_INFO
, ha
, "Configuring NVRAM ...\n");
480 if (qla4xxx_is_nvram_configuration_valid(ha
) == QLA_SUCCESS
) {
481 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
482 extHwConfig
.Asuint32_t
=
483 rd_nvram_word(ha
, eeprom_ext_hw_conf_offset(ha
));
484 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
486 ql4_printk(KERN_WARNING
, ha
,
487 "scsi%ld: %s: EEProm checksum invalid. "
488 "Please update your EEPROM\n", ha
->host_no
,
491 /* Attempt to set defaults */
493 extHwConfig
.Asuint32_t
= 0x1912;
494 else if (is_qla4022(ha
) | is_qla4032(ha
))
495 extHwConfig
.Asuint32_t
= 0x0023;
500 if (is_qla4022(ha
) || is_qla4032(ha
))
501 qla4xxx_set_model_info(ha
);
503 strcpy(ha
->model_name
, "QLA4010");
505 DEBUG(printk("scsi%ld: %s: Setting extHwConfig to 0xFFFF%04x\n",
506 ha
->host_no
, __func__
, extHwConfig
.Asuint32_t
));
508 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
509 writel((0xFFFF << 16) | extHwConfig
.Asuint32_t
, isp_ext_hw_conf(ha
));
510 readl(isp_ext_hw_conf(ha
));
511 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
513 ql4xxx_unlock_nvram(ha
);
514 ql4xxx_unlock_flash(ha
);
520 * qla4_8xxx_pci_config() - Setup ISP82xx PCI configuration registers.
523 void qla4_8xxx_pci_config(struct scsi_qla_host
*ha
)
525 pci_set_master(ha
->pdev
);
528 void qla4xxx_pci_config(struct scsi_qla_host
*ha
)
533 ql4_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
535 pci_set_master(ha
->pdev
);
536 status
= pci_set_mwi(ha
->pdev
);
538 * We want to respect framework's setting of PCI configuration space
539 * command register and also want to make sure that all bits of
540 * interest to us are properly set in command register.
542 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
543 w
|= PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
;
544 w
&= ~PCI_COMMAND_INTX_DISABLE
;
545 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
548 static int qla4xxx_start_firmware_from_flash(struct scsi_qla_host
*ha
)
550 int status
= QLA_ERROR
;
551 unsigned long max_wait_time
;
553 uint32_t mbox_status
;
555 ql4_printk(KERN_INFO
, ha
, "Starting firmware ...\n");
558 * Start firmware from flash ROM
560 * WORKAROUND: Stuff a non-constant value that the firmware can
561 * use as a seed for a random number generator in MB7 prior to
562 * setting BOOT_ENABLE. Fixes problem where the TCP
563 * connections use the same TCP ports after each reboot,
564 * causing some connections to not get re-established.
566 DEBUG(printk("scsi%d: %s: Start firmware from flash ROM\n",
567 ha
->host_no
, __func__
));
569 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
570 writel(jiffies
, &ha
->reg
->mailbox
[7]);
571 if (is_qla4022(ha
) | is_qla4032(ha
))
572 writel(set_rmask(NVR_WRITE_ENABLE
),
573 &ha
->reg
->u1
.isp4022
.nvram
);
575 writel(2, &ha
->reg
->mailbox
[6]);
576 readl(&ha
->reg
->mailbox
[6]);
578 writel(set_rmask(CSR_BOOT_ENABLE
), &ha
->reg
->ctrl_status
);
579 readl(&ha
->reg
->ctrl_status
);
580 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
582 /* Wait for firmware to come UP. */
583 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: Wait up to %d seconds for "
584 "boot firmware to complete...\n",
585 ha
->host_no
, __func__
, FIRMWARE_UP_TOV
));
586 max_wait_time
= jiffies
+ (FIRMWARE_UP_TOV
* HZ
);
588 uint32_t ctrl_status
;
590 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
591 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
592 mbox_status
= readw(&ha
->reg
->mailbox
[0]);
593 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
595 if (ctrl_status
& set_rmask(CSR_SCSI_PROCESSOR_INTR
))
597 if (mbox_status
== MBOX_STS_COMMAND_COMPLETE
)
600 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: Waiting for boot "
601 "firmware to complete... ctrl_sts=0x%x, remaining=%ld\n",
602 ha
->host_no
, __func__
, ctrl_status
, max_wait_time
));
604 msleep_interruptible(250);
605 } while (!time_after_eq(jiffies
, max_wait_time
));
607 if (mbox_status
== MBOX_STS_COMMAND_COMPLETE
) {
608 DEBUG(printk(KERN_INFO
"scsi%ld: %s: Firmware has started\n",
609 ha
->host_no
, __func__
));
611 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
612 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR
),
613 &ha
->reg
->ctrl_status
);
614 readl(&ha
->reg
->ctrl_status
);
615 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
617 status
= QLA_SUCCESS
;
619 printk(KERN_INFO
"scsi%ld: %s: Boot firmware failed "
620 "- mbox status 0x%x\n", ha
->host_no
, __func__
,
627 int ql4xxx_lock_drvr_wait(struct scsi_qla_host
*a
)
629 #define QL4_LOCK_DRVR_WAIT 60
630 #define QL4_LOCK_DRVR_SLEEP 1
632 int drvr_wait
= QL4_LOCK_DRVR_WAIT
;
634 if (ql4xxx_lock_drvr(a
) == 0) {
635 ssleep(QL4_LOCK_DRVR_SLEEP
);
637 DEBUG2(printk("scsi%ld: %s: Waiting for "
638 "Global Init Semaphore(%d)...\n",
640 __func__
, drvr_wait
));
642 drvr_wait
-= QL4_LOCK_DRVR_SLEEP
;
644 DEBUG2(printk("scsi%ld: %s: Global Init Semaphore "
645 "acquired\n", a
->host_no
, __func__
));
653 * qla4xxx_start_firmware - starts qla4xxx firmware
654 * @ha: Pointer to host adapter structure.
656 * This routine performs the necessary steps to start the firmware for
657 * the QLA4010 adapter.
659 int qla4xxx_start_firmware(struct scsi_qla_host
*ha
)
661 unsigned long flags
= 0;
662 uint32_t mbox_status
;
663 int status
= QLA_ERROR
;
667 if (is_qla4022(ha
) | is_qla4032(ha
))
668 ql4xxx_set_mac_number(ha
);
670 if (ql4xxx_lock_drvr_wait(ha
) != QLA_SUCCESS
)
673 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
675 DEBUG2(printk("scsi%ld: %s: port_ctrl = 0x%08X\n", ha
->host_no
,
676 __func__
, readw(isp_port_ctrl(ha
))));
677 DEBUG(printk("scsi%ld: %s: port_status = 0x%08X\n", ha
->host_no
,
678 __func__
, readw(isp_port_status(ha
))));
680 /* Is Hardware already initialized? */
681 if ((readw(isp_port_ctrl(ha
)) & 0x8000) != 0) {
682 DEBUG(printk("scsi%ld: %s: Hardware has already been "
683 "initialized\n", ha
->host_no
, __func__
));
685 /* Receive firmware boot acknowledgement */
686 mbox_status
= readw(&ha
->reg
->mailbox
[0]);
688 DEBUG2(printk("scsi%ld: %s: H/W Config complete - mbox[0]= "
689 "0x%x\n", ha
->host_no
, __func__
, mbox_status
));
691 /* Is firmware already booted? */
692 if (mbox_status
== 0) {
693 /* F/W not running, must be config by net driver */
697 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR
),
698 &ha
->reg
->ctrl_status
);
699 readl(&ha
->reg
->ctrl_status
);
700 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
701 if (qla4xxx_get_firmware_state(ha
) == QLA_SUCCESS
) {
702 DEBUG2(printk("scsi%ld: %s: Get firmware "
703 "state -- state = 0x%x\n",
705 __func__
, ha
->firmware_state
));
707 if (ha
->firmware_state
&
708 FW_STATE_CONFIG_WAIT
) {
709 DEBUG2(printk("scsi%ld: %s: Firmware "
712 "boot, state = 0x%x\n",
713 ha
->host_no
, __func__
,
714 ha
->firmware_state
));
719 DEBUG2(printk("scsi%ld: %s: Firmware in "
720 "unknown state -- resetting,"
722 "0x%x\n", ha
->host_no
, __func__
,
723 ha
->firmware_state
));
725 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
728 DEBUG(printk("scsi%ld: %s: H/W initialization hasn't been "
729 "started - resetting\n", ha
->host_no
, __func__
));
731 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
733 DEBUG(printk("scsi%ld: %s: Flags soft_rest=%d, config= %d\n ",
734 ha
->host_no
, __func__
, soft_reset
, config_chip
));
736 DEBUG(printk("scsi%ld: %s: Issue Soft Reset\n", ha
->host_no
,
738 status
= qla4xxx_soft_reset(ha
); /* NOTE: acquires drvr
739 * lock again, but ok */
740 if (status
== QLA_ERROR
) {
741 DEBUG(printk("scsi%d: %s: Soft Reset failed!\n",
742 ha
->host_no
, __func__
));
743 ql4xxx_unlock_drvr(ha
);
748 /* Reset clears the semaphore, so acquire again */
749 if (ql4xxx_lock_drvr_wait(ha
) != QLA_SUCCESS
)
754 if ((status
= qla4xxx_config_nvram(ha
)) == QLA_SUCCESS
)
755 status
= qla4xxx_start_firmware_from_flash(ha
);
758 ql4xxx_unlock_drvr(ha
);
759 if (status
== QLA_SUCCESS
) {
760 if (test_and_clear_bit(AF_GET_CRASH_RECORD
, &ha
->flags
))
761 qla4xxx_get_crash_record(ha
);
763 DEBUG(printk("scsi%ld: %s: Firmware has NOT started\n",
764 ha
->host_no
, __func__
));
769 * qla4xxx_free_ddb_index - Free DDBs reserved by firmware
770 * @ha: pointer to adapter structure
772 * Since firmware is not running in autoconnect mode the DDB indices should
773 * be freed so that when login happens from user space there are free DDB
776 void qla4xxx_free_ddb_index(struct scsi_qla_host
*ha
)
780 uint32_t idx
= 0, next_idx
= 0;
781 uint32_t state
= 0, conn_err
= 0;
783 max_ddbs
= is_qla40XX(ha
) ? MAX_DEV_DB_ENTRIES_40XX
:
786 for (idx
= 0; idx
< max_ddbs
; idx
= next_idx
) {
787 ret
= qla4xxx_get_fwddb_entry(ha
, idx
, NULL
, 0, NULL
,
788 &next_idx
, &state
, &conn_err
,
790 if (ret
== QLA_ERROR
) {
794 if (state
== DDB_DS_NO_CONNECTION_ACTIVE
||
795 state
== DDB_DS_SESSION_FAILED
) {
796 DEBUG2(ql4_printk(KERN_INFO
, ha
,
797 "Freeing DDB index = 0x%x\n", idx
));
798 ret
= qla4xxx_clear_ddb_entry(ha
, idx
);
799 if (ret
== QLA_ERROR
)
800 ql4_printk(KERN_ERR
, ha
,
801 "Unable to clear DDB index = "
810 * qla4xxx_initialize_adapter - initiailizes hba
811 * @ha: Pointer to host adapter structure.
813 * This routine parforms all of the steps necessary to initialize the adapter.
816 int qla4xxx_initialize_adapter(struct scsi_qla_host
*ha
, int is_reset
)
818 int status
= QLA_ERROR
;
820 ha
->eeprom_cmd_data
= 0;
822 ql4_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
823 ha
->isp_ops
->pci_config(ha
);
825 ha
->isp_ops
->disable_intrs(ha
);
827 /* Initialize the Host adapter request/response queues and firmware */
828 if (ha
->isp_ops
->start_firmware(ha
) == QLA_ERROR
)
831 if (qla4xxx_about_firmware(ha
) == QLA_ERROR
)
834 if (ha
->isp_ops
->get_sys_info(ha
) == QLA_ERROR
)
837 if (qla4xxx_init_local_data(ha
) == QLA_ERROR
)
840 status
= qla4xxx_init_firmware(ha
);
841 if (status
== QLA_ERROR
)
844 if (is_reset
== RESET_ADAPTER
)
845 qla4xxx_build_ddb_list(ha
, is_reset
);
847 set_bit(AF_ONLINE
, &ha
->flags
);
849 if (is_qla8022(ha
) && (status
== QLA_ERROR
)) {
850 /* Since interrupts are registered in start_firmware for
851 * 82xx, release them here if initialize_adapter fails */
852 qla4xxx_free_irqs(ha
);
855 DEBUG2(printk("scsi%ld: initialize adapter: %s\n", ha
->host_no
,
856 status
== QLA_ERROR
? "FAILED" : "SUCCEEDED"));
860 int qla4xxx_ddb_change(struct scsi_qla_host
*ha
, uint32_t fw_ddb_index
,
861 struct ddb_entry
*ddb_entry
, uint32_t state
)
863 uint32_t old_fw_ddb_device_state
;
864 int status
= QLA_ERROR
;
866 old_fw_ddb_device_state
= ddb_entry
->fw_ddb_device_state
;
867 DEBUG2(ql4_printk(KERN_INFO
, ha
,
868 "%s: DDB - old state = 0x%x, new state = 0x%x for "
869 "index [%d]\n", __func__
,
870 ddb_entry
->fw_ddb_device_state
, state
, fw_ddb_index
));
872 ddb_entry
->fw_ddb_device_state
= state
;
874 switch (old_fw_ddb_device_state
) {
875 case DDB_DS_LOGIN_IN_PROCESS
:
877 case DDB_DS_SESSION_ACTIVE
:
878 case DDB_DS_DISCOVERY
:
879 ddb_entry
->unblock_sess(ddb_entry
->sess
);
880 qla4xxx_update_session_conn_param(ha
, ddb_entry
);
881 status
= QLA_SUCCESS
;
883 case DDB_DS_SESSION_FAILED
:
884 case DDB_DS_NO_CONNECTION_ACTIVE
:
885 iscsi_conn_login_event(ddb_entry
->conn
,
886 ISCSI_CONN_STATE_FREE
);
887 status
= QLA_SUCCESS
;
891 case DDB_DS_SESSION_ACTIVE
:
893 case DDB_DS_SESSION_FAILED
:
895 * iscsi_session failure will cause userspace to
896 * stop the connection which in turn would block the
897 * iscsi_session and start relogin
899 iscsi_session_failure(ddb_entry
->sess
->dd_data
,
900 ISCSI_ERR_CONN_FAILED
);
901 status
= QLA_SUCCESS
;
903 case DDB_DS_NO_CONNECTION_ACTIVE
:
904 clear_bit(fw_ddb_index
, ha
->ddb_idx_map
);
905 status
= QLA_SUCCESS
;
909 case DDB_DS_SESSION_FAILED
:
911 case DDB_DS_SESSION_ACTIVE
:
912 case DDB_DS_DISCOVERY
:
913 ddb_entry
->unblock_sess(ddb_entry
->sess
);
914 qla4xxx_update_session_conn_param(ha
, ddb_entry
);
915 status
= QLA_SUCCESS
;
917 case DDB_DS_SESSION_FAILED
:
918 iscsi_session_failure(ddb_entry
->sess
->dd_data
,
919 ISCSI_ERR_CONN_FAILED
);
920 status
= QLA_SUCCESS
;
925 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: Unknown Event\n",
932 void qla4xxx_arm_relogin_timer(struct ddb_entry
*ddb_entry
)
935 * This triggers a relogin. After the relogin_timer
936 * expires, the relogin gets scheduled. We must wait a
937 * minimum amount of time since receiving an 0x8014 AEN
938 * with failed device_state or a logout response before
939 * we can issue another relogin.
941 * Firmware pads this timeout: (time2wait +1).
942 * Driver retry to login should be longer than F/W.
943 * Otherwise F/W will fail
944 * set_ddb() mbx cmd with 0x4005 since it still
945 * counting down its time2wait.
947 atomic_set(&ddb_entry
->relogin_timer
, 0);
948 atomic_set(&ddb_entry
->retry_relogin_timer
,
949 ddb_entry
->default_time2wait
+ 4);
953 int qla4xxx_flash_ddb_change(struct scsi_qla_host
*ha
, uint32_t fw_ddb_index
,
954 struct ddb_entry
*ddb_entry
, uint32_t state
)
956 uint32_t old_fw_ddb_device_state
;
957 int status
= QLA_ERROR
;
959 old_fw_ddb_device_state
= ddb_entry
->fw_ddb_device_state
;
960 DEBUG2(ql4_printk(KERN_INFO
, ha
,
961 "%s: DDB - old state = 0x%x, new state = 0x%x for "
962 "index [%d]\n", __func__
,
963 ddb_entry
->fw_ddb_device_state
, state
, fw_ddb_index
));
965 ddb_entry
->fw_ddb_device_state
= state
;
967 switch (old_fw_ddb_device_state
) {
968 case DDB_DS_LOGIN_IN_PROCESS
:
969 case DDB_DS_NO_CONNECTION_ACTIVE
:
971 case DDB_DS_SESSION_ACTIVE
:
972 ddb_entry
->unblock_sess(ddb_entry
->sess
);
973 qla4xxx_update_session_conn_fwddb_param(ha
, ddb_entry
);
974 status
= QLA_SUCCESS
;
976 case DDB_DS_SESSION_FAILED
:
977 iscsi_block_session(ddb_entry
->sess
);
978 if (!test_bit(DF_RELOGIN
, &ddb_entry
->flags
))
979 qla4xxx_arm_relogin_timer(ddb_entry
);
980 status
= QLA_SUCCESS
;
984 case DDB_DS_SESSION_ACTIVE
:
986 case DDB_DS_SESSION_FAILED
:
987 iscsi_block_session(ddb_entry
->sess
);
988 if (!test_bit(DF_RELOGIN
, &ddb_entry
->flags
))
989 qla4xxx_arm_relogin_timer(ddb_entry
);
990 status
= QLA_SUCCESS
;
994 case DDB_DS_SESSION_FAILED
:
996 case DDB_DS_SESSION_ACTIVE
:
997 ddb_entry
->unblock_sess(ddb_entry
->sess
);
998 qla4xxx_update_session_conn_fwddb_param(ha
, ddb_entry
);
999 status
= QLA_SUCCESS
;
1001 case DDB_DS_SESSION_FAILED
:
1002 if (!test_bit(DF_RELOGIN
, &ddb_entry
->flags
))
1003 qla4xxx_arm_relogin_timer(ddb_entry
);
1004 status
= QLA_SUCCESS
;
1009 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: Unknown Event\n",
1017 * qla4xxx_process_ddb_changed - process ddb state change
1018 * @ha - Pointer to host adapter structure.
1019 * @fw_ddb_index - Firmware's device database index
1020 * @state - Device state
1022 * This routine processes a Decive Database Changed AEN Event.
1024 int qla4xxx_process_ddb_changed(struct scsi_qla_host
*ha
,
1025 uint32_t fw_ddb_index
,
1026 uint32_t state
, uint32_t conn_err
)
1028 struct ddb_entry
*ddb_entry
;
1029 int status
= QLA_ERROR
;
1031 /* check for out of range index */
1032 if (fw_ddb_index
>= MAX_DDB_ENTRIES
)
1033 goto exit_ddb_event
;
1035 /* Get the corresponging ddb entry */
1036 ddb_entry
= qla4xxx_lookup_ddb_by_fw_index(ha
, fw_ddb_index
);
1037 /* Device does not currently exist in our database. */
1038 if (ddb_entry
== NULL
) {
1039 ql4_printk(KERN_ERR
, ha
, "%s: No ddb_entry at FW index [%d]\n",
1040 __func__
, fw_ddb_index
);
1042 if (state
== DDB_DS_NO_CONNECTION_ACTIVE
)
1043 clear_bit(fw_ddb_index
, ha
->ddb_idx_map
);
1045 goto exit_ddb_event
;
1048 ddb_entry
->ddb_change(ha
, fw_ddb_index
, ddb_entry
, state
);
1055 * qla4xxx_login_flash_ddb - Login to target (DDB)
1056 * @cls_session: Pointer to the session to login
1058 * This routine logins to the target.
1059 * Issues setddb and conn open mbx
1061 void qla4xxx_login_flash_ddb(struct iscsi_cls_session
*cls_session
)
1063 struct iscsi_session
*sess
;
1064 struct ddb_entry
*ddb_entry
;
1065 struct scsi_qla_host
*ha
;
1066 struct dev_db_entry
*fw_ddb_entry
= NULL
;
1067 dma_addr_t fw_ddb_dma
;
1068 uint32_t mbx_sts
= 0;
1071 sess
= cls_session
->dd_data
;
1072 ddb_entry
= sess
->dd_data
;
1075 if (!test_bit(AF_LINK_UP
, &ha
->flags
))
1078 if (ddb_entry
->ddb_type
!= FLASH_DDB
) {
1079 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1080 "Skipping login to non FLASH DB"));
1084 fw_ddb_entry
= dma_pool_alloc(ha
->fw_ddb_dma_pool
, GFP_KERNEL
,
1086 if (fw_ddb_entry
== NULL
) {
1087 DEBUG2(ql4_printk(KERN_ERR
, ha
, "Out of memory\n"));
1091 if (ddb_entry
->fw_ddb_index
== INVALID_ENTRY
) {
1092 ret
= qla4xxx_get_ddb_index(ha
, &ddb_entry
->fw_ddb_index
);
1093 if (ret
== QLA_ERROR
)
1096 ha
->fw_ddb_index_map
[ddb_entry
->fw_ddb_index
] = ddb_entry
;
1100 memcpy(fw_ddb_entry
, &ddb_entry
->fw_ddb_entry
,
1101 sizeof(struct dev_db_entry
));
1102 ddb_entry
->sess
->target_id
= ddb_entry
->fw_ddb_index
;
1104 ret
= qla4xxx_set_ddb_entry(ha
, ddb_entry
->fw_ddb_index
,
1105 fw_ddb_dma
, &mbx_sts
);
1106 if (ret
== QLA_ERROR
) {
1107 DEBUG2(ql4_printk(KERN_ERR
, ha
, "Set DDB failed\n"));
1111 ddb_entry
->fw_ddb_device_state
= DDB_DS_LOGIN_IN_PROCESS
;
1112 ret
= qla4xxx_conn_open(ha
, ddb_entry
->fw_ddb_index
);
1113 if (ret
== QLA_ERROR
) {
1114 ql4_printk(KERN_ERR
, ha
, "%s: Login failed: %s\n", __func__
,
1121 dma_pool_free(ha
->fw_ddb_dma_pool
, fw_ddb_entry
, fw_ddb_dma
);