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;
91 /* Initialize request queue. */
92 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
95 ha
->request_ptr
= &ha
->request_ring
[ha
->request_in
];
96 ha
->req_q_count
= REQUEST_QUEUE_DEPTH
;
98 /* Initialize response queue. */
100 ha
->response_out
= 0;
101 ha
->response_ptr
= &ha
->response_ring
[ha
->response_out
];
103 if (is_qla8022(ha
)) {
105 (unsigned long __iomem
*)&ha
->qla4_8xxx_reg
->req_q_out
);
107 (unsigned long __iomem
*)&ha
->qla4_8xxx_reg
->rsp_q_in
);
109 (unsigned long __iomem
*)&ha
->qla4_8xxx_reg
->rsp_q_out
);
112 * Initialize DMA Shadow registers. The firmware is really
113 * supposed to take care of this, but on some uniprocessor
114 * systems, the shadow registers aren't cleared-- causing
115 * the interrupt_handler to think there are responses to be
116 * processed when there aren't.
118 ha
->shadow_regs
->req_q_out
= __constant_cpu_to_le32(0);
119 ha
->shadow_regs
->rsp_q_in
= __constant_cpu_to_le32(0);
122 writel(0, &ha
->reg
->req_q_in
);
123 writel(0, &ha
->reg
->rsp_q_out
);
124 readl(&ha
->reg
->rsp_q_out
);
127 qla4xxx_init_response_q_entries(ha
);
129 /* Initialize mabilbox active array */
130 for (i
= 0; i
< MAX_MRB
; i
++)
131 ha
->active_mrb_array
[i
] = NULL
;
133 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
139 * qla4xxx_get_sys_info - validate adapter MAC address(es)
140 * @ha: pointer to host adapter structure.
143 int qla4xxx_get_sys_info(struct scsi_qla_host
*ha
)
145 struct flash_sys_info
*sys_info
;
146 dma_addr_t sys_info_dma
;
147 int status
= QLA_ERROR
;
149 sys_info
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*sys_info
),
150 &sys_info_dma
, GFP_KERNEL
);
151 if (sys_info
== NULL
) {
152 DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
153 ha
->host_no
, __func__
));
155 goto exit_get_sys_info_no_free
;
157 memset(sys_info
, 0, sizeof(*sys_info
));
159 /* Get flash sys info */
160 if (qla4xxx_get_flash(ha
, sys_info_dma
, FLASH_OFFSET_SYS_INFO
,
161 sizeof(*sys_info
)) != QLA_SUCCESS
) {
162 DEBUG2(printk("scsi%ld: %s: get_flash FLASH_OFFSET_SYS_INFO "
163 "failed\n", ha
->host_no
, __func__
));
165 goto exit_get_sys_info
;
168 /* Save M.A.C. address & serial_number */
169 memcpy(ha
->my_mac
, &sys_info
->physAddr
[0].address
[0],
170 min(sizeof(ha
->my_mac
),
171 sizeof(sys_info
->physAddr
[0].address
)));
172 memcpy(ha
->serial_number
, &sys_info
->acSerialNumber
,
173 min(sizeof(ha
->serial_number
),
174 sizeof(sys_info
->acSerialNumber
)));
176 status
= QLA_SUCCESS
;
179 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*sys_info
), sys_info
,
182 exit_get_sys_info_no_free
:
187 * qla4xxx_init_local_data - initialize adapter specific local data
188 * @ha: pointer to host adapter structure.
191 static int qla4xxx_init_local_data(struct scsi_qla_host
*ha
)
193 /* Initialize aen queue */
194 ha
->aen_q_count
= MAX_AEN_ENTRIES
;
196 return qla4xxx_get_firmware_status(ha
);
200 qla4xxx_wait_for_ip_config(struct scsi_qla_host
*ha
)
202 uint8_t ipv4_wait
= 0;
203 uint8_t ipv6_wait
= 0;
204 int8_t ip_address
[IPv6_ADDR_LEN
] = {0} ;
206 /* If both IPv4 & IPv6 are enabled, possibly only one
207 * IP address may be acquired, so check to see if we
208 * need to wait for another */
209 if (is_ipv4_enabled(ha
) && is_ipv6_enabled(ha
)) {
210 if (((ha
->addl_fw_state
& FW_ADDSTATE_DHCPv4_ENABLED
) != 0) &&
211 ((ha
->addl_fw_state
&
212 FW_ADDSTATE_DHCPv4_LEASE_ACQUIRED
) == 0)) {
215 if (((ha
->ip_config
.ipv6_addl_options
&
216 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE
) != 0) &&
217 ((ha
->ip_config
.ipv6_link_local_state
==
218 IP_ADDRSTATE_ACQUIRING
) ||
219 (ha
->ip_config
.ipv6_addr0_state
==
220 IP_ADDRSTATE_ACQUIRING
) ||
221 (ha
->ip_config
.ipv6_addr1_state
==
222 IP_ADDRSTATE_ACQUIRING
))) {
226 if ((ha
->ip_config
.ipv6_link_local_state
==
227 IP_ADDRSTATE_PREFERRED
) ||
228 (ha
->ip_config
.ipv6_addr0_state
==
229 IP_ADDRSTATE_PREFERRED
) ||
230 (ha
->ip_config
.ipv6_addr1_state
==
231 IP_ADDRSTATE_PREFERRED
)) {
232 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: "
233 "Preferred IP configured."
234 " Don't wait!\n", ha
->host_no
,
238 if (memcmp(&ha
->ip_config
.ipv6_default_router_addr
,
239 ip_address
, IPv6_ADDR_LEN
) == 0) {
240 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: "
241 "No Router configured. "
242 "Don't wait!\n", ha
->host_no
,
246 if ((ha
->ip_config
.ipv6_default_router_state
==
247 IPV6_RTRSTATE_MANUAL
) &&
248 (ha
->ip_config
.ipv6_link_local_state
==
249 IP_ADDRSTATE_TENTATIVE
) &&
250 (memcmp(&ha
->ip_config
.ipv6_link_local_addr
,
251 &ha
->ip_config
.ipv6_default_router_addr
, 4) ==
253 DEBUG2(printk("scsi%ld: %s: LinkLocal Router & "
254 "IP configured. Don't wait!\n",
255 ha
->host_no
, __func__
));
259 if (ipv4_wait
|| ipv6_wait
) {
260 DEBUG2(printk("scsi%ld: %s: Wait for additional "
261 "IP(s) \"", ha
->host_no
, __func__
));
263 DEBUG2(printk("IPv4 "));
264 if (ha
->ip_config
.ipv6_link_local_state
==
265 IP_ADDRSTATE_ACQUIRING
)
266 DEBUG2(printk("IPv6LinkLocal "));
267 if (ha
->ip_config
.ipv6_addr0_state
==
268 IP_ADDRSTATE_ACQUIRING
)
269 DEBUG2(printk("IPv6Addr0 "));
270 if (ha
->ip_config
.ipv6_addr1_state
==
271 IP_ADDRSTATE_ACQUIRING
)
272 DEBUG2(printk("IPv6Addr1 "));
273 DEBUG2(printk("\"\n"));
277 return ipv4_wait
|ipv6_wait
;
280 static int qla4xxx_fw_ready(struct scsi_qla_host
*ha
)
282 uint32_t timeout_count
;
285 DEBUG2(ql4_printk(KERN_INFO
, ha
, "Waiting for Firmware Ready..\n"));
286 for (timeout_count
= ADAPTER_INIT_TOV
; timeout_count
> 0;
288 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR
, &ha
->dpc_flags
))
289 qla4xxx_get_dhcp_ip_address(ha
);
291 /* Get firmware state. */
292 if (qla4xxx_get_firmware_state(ha
) != QLA_SUCCESS
) {
293 DEBUG2(printk("scsi%ld: %s: unable to get firmware "
294 "state\n", ha
->host_no
, __func__
));
298 if (ha
->firmware_state
& FW_STATE_ERROR
) {
299 DEBUG2(printk("scsi%ld: %s: an unrecoverable error has"
300 " occurred\n", ha
->host_no
, __func__
));
304 if (ha
->firmware_state
& FW_STATE_CONFIG_WAIT
) {
306 * The firmware has not yet been issued an Initialize
307 * Firmware command, so issue it now.
309 if (qla4xxx_initialize_fw_cb(ha
) == QLA_ERROR
)
312 /* Go back and test for ready state - no wait. */
316 if (ha
->firmware_state
& FW_STATE_WAIT_AUTOCONNECT
) {
317 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: fwstate:"
318 "AUTOCONNECT in progress\n",
319 ha
->host_no
, __func__
));
322 if (ha
->firmware_state
& FW_STATE_CONFIGURING_IP
) {
323 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: fwstate:"
325 ha
->host_no
, __func__
));
327 * Check for link state after 15 secs and if link is
328 * still DOWN then, cable is unplugged. Ignore "DHCP
329 * in Progress/CONFIGURING IP" bit to check if firmware
330 * is in ready state or not after 15 secs.
331 * This is applicable for both 2.x & 3.x firmware
333 if (timeout_count
<= (ADAPTER_INIT_TOV
- 15)) {
334 if (ha
->addl_fw_state
& FW_ADDSTATE_LINK_UP
) {
335 DEBUG2(printk(KERN_INFO
"scsi%ld: %s:"
336 " LINK UP (Cable plugged)\n",
337 ha
->host_no
, __func__
));
338 } else if (ha
->firmware_state
&
339 (FW_STATE_CONFIGURING_IP
|
341 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: "
342 "LINK DOWN (Cable unplugged)\n",
343 ha
->host_no
, __func__
));
344 ha
->firmware_state
= FW_STATE_READY
;
349 if (ha
->firmware_state
== FW_STATE_READY
) {
350 /* If DHCP IP Addr is available, retrieve it now. */
351 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR
,
353 qla4xxx_get_dhcp_ip_address(ha
);
355 if (!qla4xxx_wait_for_ip_config(ha
) ||
356 timeout_count
== 1) {
357 DEBUG2(ql4_printk(KERN_INFO
, ha
,
358 "Firmware Ready..\n"));
359 /* The firmware is ready to process SCSI
361 DEBUG2(ql4_printk(KERN_INFO
, ha
,
362 "scsi%ld: %s: MEDIA TYPE"
363 " - %s\n", ha
->host_no
,
364 __func__
, (ha
->addl_fw_state
&
365 FW_ADDSTATE_OPTICAL_MEDIA
)
366 != 0 ? "OPTICAL" : "COPPER"));
367 DEBUG2(ql4_printk(KERN_INFO
, ha
,
368 "scsi%ld: %s: DHCPv4 STATE"
369 " Enabled %s\n", ha
->host_no
,
370 __func__
, (ha
->addl_fw_state
&
371 FW_ADDSTATE_DHCPv4_ENABLED
) != 0 ?
373 DEBUG2(ql4_printk(KERN_INFO
, ha
,
374 "scsi%ld: %s: LINK %s\n",
375 ha
->host_no
, __func__
,
377 FW_ADDSTATE_LINK_UP
) != 0 ?
379 DEBUG2(ql4_printk(KERN_INFO
, ha
,
380 "scsi%ld: %s: iSNS Service "
382 ha
->host_no
, __func__
,
384 FW_ADDSTATE_ISNS_SVC_ENABLED
) != 0 ?
391 DEBUG2(printk("scsi%ld: %s: waiting on fw, state=%x:%x - "
392 "seconds expired= %d\n", ha
->host_no
, __func__
,
393 ha
->firmware_state
, ha
->addl_fw_state
,
395 if (is_qla4032(ha
) &&
396 !(ha
->addl_fw_state
& FW_ADDSTATE_LINK_UP
) &&
397 (timeout_count
< ADAPTER_INIT_TOV
- 5)) {
404 if (timeout_count
<= 0)
405 DEBUG2(printk("scsi%ld: %s: FW Initialization timed out!\n",
406 ha
->host_no
, __func__
));
408 if (ha
->firmware_state
& FW_STATE_CONFIGURING_IP
) {
409 DEBUG2(printk("scsi%ld: %s: FW initialized, but is reporting "
410 "it's waiting to configure an IP address\n",
411 ha
->host_no
, __func__
));
413 } else if (ha
->firmware_state
& FW_STATE_WAIT_AUTOCONNECT
) {
414 DEBUG2(printk("scsi%ld: %s: FW initialized, but "
415 "auto-discovery still in process\n",
416 ha
->host_no
, __func__
));
424 * qla4xxx_init_firmware - initializes the firmware.
425 * @ha: pointer to host adapter structure.
428 static int qla4xxx_init_firmware(struct scsi_qla_host
*ha
)
430 int status
= QLA_ERROR
;
432 if (is_aer_supported(ha
) &&
433 test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE
, &ha
->flags
))
436 /* For 82xx, stop firmware before initializing because if BIOS
437 * has previously initialized firmware, then driver's initialize
438 * firmware will fail. */
440 qla4_8xxx_stop_firmware(ha
);
442 ql4_printk(KERN_INFO
, ha
, "Initializing firmware..\n");
443 if (qla4xxx_initialize_fw_cb(ha
) == QLA_ERROR
) {
444 DEBUG2(printk("scsi%ld: %s: Failed to initialize firmware "
445 "control block\n", ha
->host_no
, __func__
));
448 if (!qla4xxx_fw_ready(ha
))
451 return qla4xxx_get_firmware_status(ha
);
454 static void qla4xxx_set_model_info(struct scsi_qla_host
*ha
)
456 uint16_t board_id_string
[8];
458 int size
= sizeof(ha
->nvram
->isp4022
.boardIdStr
);
459 int offset
= offsetof(struct eeprom_data
, isp4022
.boardIdStr
) / 2;
461 for (i
= 0; i
< (size
/ 2) ; i
++) {
462 board_id_string
[i
] = rd_nvram_word(ha
, offset
);
466 memcpy(ha
->model_name
, board_id_string
, size
);
469 static int qla4xxx_config_nvram(struct scsi_qla_host
*ha
)
472 union external_hw_config_reg extHwConfig
;
474 DEBUG2(printk("scsi%ld: %s: Get EEProm parameters \n", ha
->host_no
,
476 if (ql4xxx_lock_flash(ha
) != QLA_SUCCESS
)
478 if (ql4xxx_lock_nvram(ha
) != QLA_SUCCESS
) {
479 ql4xxx_unlock_flash(ha
);
483 /* Get EEPRom Parameters from NVRAM and validate */
484 ql4_printk(KERN_INFO
, ha
, "Configuring NVRAM ...\n");
485 if (qla4xxx_is_nvram_configuration_valid(ha
) == QLA_SUCCESS
) {
486 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
487 extHwConfig
.Asuint32_t
=
488 rd_nvram_word(ha
, eeprom_ext_hw_conf_offset(ha
));
489 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
491 ql4_printk(KERN_WARNING
, ha
,
492 "scsi%ld: %s: EEProm checksum invalid. "
493 "Please update your EEPROM\n", ha
->host_no
,
496 /* Attempt to set defaults */
498 extHwConfig
.Asuint32_t
= 0x1912;
499 else if (is_qla4022(ha
) | is_qla4032(ha
))
500 extHwConfig
.Asuint32_t
= 0x0023;
505 if (is_qla4022(ha
) || is_qla4032(ha
))
506 qla4xxx_set_model_info(ha
);
508 strcpy(ha
->model_name
, "QLA4010");
510 DEBUG(printk("scsi%ld: %s: Setting extHwConfig to 0xFFFF%04x\n",
511 ha
->host_no
, __func__
, extHwConfig
.Asuint32_t
));
513 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
514 writel((0xFFFF << 16) | extHwConfig
.Asuint32_t
, isp_ext_hw_conf(ha
));
515 readl(isp_ext_hw_conf(ha
));
516 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
518 ql4xxx_unlock_nvram(ha
);
519 ql4xxx_unlock_flash(ha
);
525 * qla4_8xxx_pci_config() - Setup ISP82xx PCI configuration registers.
528 void qla4_8xxx_pci_config(struct scsi_qla_host
*ha
)
530 pci_set_master(ha
->pdev
);
533 void qla4xxx_pci_config(struct scsi_qla_host
*ha
)
538 ql4_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
540 pci_set_master(ha
->pdev
);
541 status
= pci_set_mwi(ha
->pdev
);
543 * We want to respect framework's setting of PCI configuration space
544 * command register and also want to make sure that all bits of
545 * interest to us are properly set in command register.
547 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
548 w
|= PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
;
549 w
&= ~PCI_COMMAND_INTX_DISABLE
;
550 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
553 static int qla4xxx_start_firmware_from_flash(struct scsi_qla_host
*ha
)
555 int status
= QLA_ERROR
;
556 unsigned long max_wait_time
;
558 uint32_t mbox_status
;
560 ql4_printk(KERN_INFO
, ha
, "Starting firmware ...\n");
563 * Start firmware from flash ROM
565 * WORKAROUND: Stuff a non-constant value that the firmware can
566 * use as a seed for a random number generator in MB7 prior to
567 * setting BOOT_ENABLE. Fixes problem where the TCP
568 * connections use the same TCP ports after each reboot,
569 * causing some connections to not get re-established.
571 DEBUG(printk("scsi%d: %s: Start firmware from flash ROM\n",
572 ha
->host_no
, __func__
));
574 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
575 writel(jiffies
, &ha
->reg
->mailbox
[7]);
576 if (is_qla4022(ha
) | is_qla4032(ha
))
577 writel(set_rmask(NVR_WRITE_ENABLE
),
578 &ha
->reg
->u1
.isp4022
.nvram
);
580 writel(2, &ha
->reg
->mailbox
[6]);
581 readl(&ha
->reg
->mailbox
[6]);
583 writel(set_rmask(CSR_BOOT_ENABLE
), &ha
->reg
->ctrl_status
);
584 readl(&ha
->reg
->ctrl_status
);
585 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
587 /* Wait for firmware to come UP. */
588 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: Wait up to %d seconds for "
589 "boot firmware to complete...\n",
590 ha
->host_no
, __func__
, FIRMWARE_UP_TOV
));
591 max_wait_time
= jiffies
+ (FIRMWARE_UP_TOV
* HZ
);
593 uint32_t ctrl_status
;
595 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
596 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
597 mbox_status
= readw(&ha
->reg
->mailbox
[0]);
598 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
600 if (ctrl_status
& set_rmask(CSR_SCSI_PROCESSOR_INTR
))
602 if (mbox_status
== MBOX_STS_COMMAND_COMPLETE
)
605 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: Waiting for boot "
606 "firmware to complete... ctrl_sts=0x%x, remaining=%ld\n",
607 ha
->host_no
, __func__
, ctrl_status
, max_wait_time
));
609 msleep_interruptible(250);
610 } while (!time_after_eq(jiffies
, max_wait_time
));
612 if (mbox_status
== MBOX_STS_COMMAND_COMPLETE
) {
613 DEBUG(printk(KERN_INFO
"scsi%ld: %s: Firmware has started\n",
614 ha
->host_no
, __func__
));
616 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
617 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR
),
618 &ha
->reg
->ctrl_status
);
619 readl(&ha
->reg
->ctrl_status
);
620 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
622 status
= QLA_SUCCESS
;
624 printk(KERN_INFO
"scsi%ld: %s: Boot firmware failed "
625 "- mbox status 0x%x\n", ha
->host_no
, __func__
,
632 int ql4xxx_lock_drvr_wait(struct scsi_qla_host
*a
)
634 #define QL4_LOCK_DRVR_WAIT 60
635 #define QL4_LOCK_DRVR_SLEEP 1
637 int drvr_wait
= QL4_LOCK_DRVR_WAIT
;
639 if (ql4xxx_lock_drvr(a
) == 0) {
640 ssleep(QL4_LOCK_DRVR_SLEEP
);
642 DEBUG2(printk("scsi%ld: %s: Waiting for "
643 "Global Init Semaphore(%d)...\n",
645 __func__
, drvr_wait
));
647 drvr_wait
-= QL4_LOCK_DRVR_SLEEP
;
649 DEBUG2(printk("scsi%ld: %s: Global Init Semaphore "
650 "acquired\n", a
->host_no
, __func__
));
658 * qla4xxx_start_firmware - starts qla4xxx firmware
659 * @ha: Pointer to host adapter structure.
661 * This routine performs the necessary steps to start the firmware for
662 * the QLA4010 adapter.
664 int qla4xxx_start_firmware(struct scsi_qla_host
*ha
)
666 unsigned long flags
= 0;
667 uint32_t mbox_status
;
668 int status
= QLA_ERROR
;
672 if (is_qla4022(ha
) | is_qla4032(ha
))
673 ql4xxx_set_mac_number(ha
);
675 if (ql4xxx_lock_drvr_wait(ha
) != QLA_SUCCESS
)
678 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
680 DEBUG2(printk("scsi%ld: %s: port_ctrl = 0x%08X\n", ha
->host_no
,
681 __func__
, readw(isp_port_ctrl(ha
))));
682 DEBUG(printk("scsi%ld: %s: port_status = 0x%08X\n", ha
->host_no
,
683 __func__
, readw(isp_port_status(ha
))));
685 /* Is Hardware already initialized? */
686 if ((readw(isp_port_ctrl(ha
)) & 0x8000) != 0) {
687 DEBUG(printk("scsi%ld: %s: Hardware has already been "
688 "initialized\n", ha
->host_no
, __func__
));
690 /* Receive firmware boot acknowledgement */
691 mbox_status
= readw(&ha
->reg
->mailbox
[0]);
693 DEBUG2(printk("scsi%ld: %s: H/W Config complete - mbox[0]= "
694 "0x%x\n", ha
->host_no
, __func__
, mbox_status
));
696 /* Is firmware already booted? */
697 if (mbox_status
== 0) {
698 /* F/W not running, must be config by net driver */
702 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR
),
703 &ha
->reg
->ctrl_status
);
704 readl(&ha
->reg
->ctrl_status
);
705 writel(set_rmask(CSR_SCSI_COMPLETION_INTR
),
706 &ha
->reg
->ctrl_status
);
707 readl(&ha
->reg
->ctrl_status
);
708 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
709 if (qla4xxx_get_firmware_state(ha
) == QLA_SUCCESS
) {
710 DEBUG2(printk("scsi%ld: %s: Get firmware "
711 "state -- state = 0x%x\n",
713 __func__
, ha
->firmware_state
));
715 if (ha
->firmware_state
&
716 FW_STATE_CONFIG_WAIT
) {
717 DEBUG2(printk("scsi%ld: %s: Firmware "
720 "boot, state = 0x%x\n",
721 ha
->host_no
, __func__
,
722 ha
->firmware_state
));
727 DEBUG2(printk("scsi%ld: %s: Firmware in "
728 "unknown state -- resetting,"
730 "0x%x\n", ha
->host_no
, __func__
,
731 ha
->firmware_state
));
733 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
736 DEBUG(printk("scsi%ld: %s: H/W initialization hasn't been "
737 "started - resetting\n", ha
->host_no
, __func__
));
739 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
741 DEBUG(printk("scsi%ld: %s: Flags soft_rest=%d, config= %d\n ",
742 ha
->host_no
, __func__
, soft_reset
, config_chip
));
744 DEBUG(printk("scsi%ld: %s: Issue Soft Reset\n", ha
->host_no
,
746 status
= qla4xxx_soft_reset(ha
); /* NOTE: acquires drvr
747 * lock again, but ok */
748 if (status
== QLA_ERROR
) {
749 DEBUG(printk("scsi%d: %s: Soft Reset failed!\n",
750 ha
->host_no
, __func__
));
751 ql4xxx_unlock_drvr(ha
);
756 /* Reset clears the semaphore, so acquire again */
757 if (ql4xxx_lock_drvr_wait(ha
) != QLA_SUCCESS
)
762 if ((status
= qla4xxx_config_nvram(ha
)) == QLA_SUCCESS
)
763 status
= qla4xxx_start_firmware_from_flash(ha
);
766 ql4xxx_unlock_drvr(ha
);
767 if (status
== QLA_SUCCESS
) {
768 if (test_and_clear_bit(AF_GET_CRASH_RECORD
, &ha
->flags
))
769 qla4xxx_get_crash_record(ha
);
771 DEBUG(printk("scsi%ld: %s: Firmware has NOT started\n",
772 ha
->host_no
, __func__
));
777 * qla4xxx_free_ddb_index - Free DDBs reserved by firmware
778 * @ha: pointer to adapter structure
780 * Since firmware is not running in autoconnect mode the DDB indices should
781 * be freed so that when login happens from user space there are free DDB
784 void qla4xxx_free_ddb_index(struct scsi_qla_host
*ha
)
788 uint32_t idx
= 0, next_idx
= 0;
789 uint32_t state
= 0, conn_err
= 0;
791 max_ddbs
= is_qla40XX(ha
) ? MAX_DEV_DB_ENTRIES_40XX
:
794 for (idx
= 0; idx
< max_ddbs
; idx
= next_idx
) {
795 ret
= qla4xxx_get_fwddb_entry(ha
, idx
, NULL
, 0, NULL
,
796 &next_idx
, &state
, &conn_err
,
798 if (ret
== QLA_ERROR
) {
802 if (state
== DDB_DS_NO_CONNECTION_ACTIVE
||
803 state
== DDB_DS_SESSION_FAILED
) {
804 DEBUG2(ql4_printk(KERN_INFO
, ha
,
805 "Freeing DDB index = 0x%x\n", idx
));
806 ret
= qla4xxx_clear_ddb_entry(ha
, idx
);
807 if (ret
== QLA_ERROR
)
808 ql4_printk(KERN_ERR
, ha
,
809 "Unable to clear DDB index = "
818 * qla4xxx_initialize_adapter - initiailizes hba
819 * @ha: Pointer to host adapter structure.
821 * This routine parforms all of the steps necessary to initialize the adapter.
824 int qla4xxx_initialize_adapter(struct scsi_qla_host
*ha
, int is_reset
)
826 int status
= QLA_ERROR
;
828 ha
->eeprom_cmd_data
= 0;
830 ql4_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
831 ha
->isp_ops
->pci_config(ha
);
833 ha
->isp_ops
->disable_intrs(ha
);
835 /* Initialize the Host adapter request/response queues and firmware */
836 if (ha
->isp_ops
->start_firmware(ha
) == QLA_ERROR
)
839 if (qla4xxx_about_firmware(ha
) == QLA_ERROR
)
842 if (ha
->isp_ops
->get_sys_info(ha
) == QLA_ERROR
)
845 if (qla4xxx_init_local_data(ha
) == QLA_ERROR
)
848 status
= qla4xxx_init_firmware(ha
);
849 if (status
== QLA_ERROR
)
852 if (is_reset
== RESET_ADAPTER
)
853 qla4xxx_build_ddb_list(ha
, is_reset
);
855 set_bit(AF_ONLINE
, &ha
->flags
);
857 if (is_qla8022(ha
) && (status
== QLA_ERROR
)) {
858 /* Since interrupts are registered in start_firmware for
859 * 82xx, release them here if initialize_adapter fails */
860 qla4xxx_free_irqs(ha
);
863 DEBUG2(printk("scsi%ld: initialize adapter: %s\n", ha
->host_no
,
864 status
== QLA_ERROR
? "FAILED" : "SUCCEEDED"));
868 int qla4xxx_ddb_change(struct scsi_qla_host
*ha
, uint32_t fw_ddb_index
,
869 struct ddb_entry
*ddb_entry
, uint32_t state
)
871 uint32_t old_fw_ddb_device_state
;
872 int status
= QLA_ERROR
;
874 old_fw_ddb_device_state
= ddb_entry
->fw_ddb_device_state
;
875 DEBUG2(ql4_printk(KERN_INFO
, ha
,
876 "%s: DDB - old state = 0x%x, new state = 0x%x for "
877 "index [%d]\n", __func__
,
878 ddb_entry
->fw_ddb_device_state
, state
, fw_ddb_index
));
880 ddb_entry
->fw_ddb_device_state
= state
;
882 switch (old_fw_ddb_device_state
) {
883 case DDB_DS_LOGIN_IN_PROCESS
:
885 case DDB_DS_SESSION_ACTIVE
:
886 case DDB_DS_DISCOVERY
:
887 ddb_entry
->unblock_sess(ddb_entry
->sess
);
888 qla4xxx_update_session_conn_param(ha
, ddb_entry
);
889 status
= QLA_SUCCESS
;
891 case DDB_DS_SESSION_FAILED
:
892 case DDB_DS_NO_CONNECTION_ACTIVE
:
893 iscsi_conn_login_event(ddb_entry
->conn
,
894 ISCSI_CONN_STATE_FREE
);
895 status
= QLA_SUCCESS
;
899 case DDB_DS_SESSION_ACTIVE
:
901 case DDB_DS_SESSION_FAILED
:
903 * iscsi_session failure will cause userspace to
904 * stop the connection which in turn would block the
905 * iscsi_session and start relogin
907 iscsi_session_failure(ddb_entry
->sess
->dd_data
,
908 ISCSI_ERR_CONN_FAILED
);
909 status
= QLA_SUCCESS
;
911 case DDB_DS_NO_CONNECTION_ACTIVE
:
912 clear_bit(fw_ddb_index
, ha
->ddb_idx_map
);
913 status
= QLA_SUCCESS
;
917 case DDB_DS_SESSION_FAILED
:
919 case DDB_DS_SESSION_ACTIVE
:
920 case DDB_DS_DISCOVERY
:
921 ddb_entry
->unblock_sess(ddb_entry
->sess
);
922 qla4xxx_update_session_conn_param(ha
, ddb_entry
);
923 status
= QLA_SUCCESS
;
925 case DDB_DS_SESSION_FAILED
:
926 iscsi_session_failure(ddb_entry
->sess
->dd_data
,
927 ISCSI_ERR_CONN_FAILED
);
928 status
= QLA_SUCCESS
;
933 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: Unknown Event\n",
940 void qla4xxx_arm_relogin_timer(struct ddb_entry
*ddb_entry
)
943 * This triggers a relogin. After the relogin_timer
944 * expires, the relogin gets scheduled. We must wait a
945 * minimum amount of time since receiving an 0x8014 AEN
946 * with failed device_state or a logout response before
947 * we can issue another relogin.
949 * Firmware pads this timeout: (time2wait +1).
950 * Driver retry to login should be longer than F/W.
951 * Otherwise F/W will fail
952 * set_ddb() mbx cmd with 0x4005 since it still
953 * counting down its time2wait.
955 atomic_set(&ddb_entry
->relogin_timer
, 0);
956 atomic_set(&ddb_entry
->retry_relogin_timer
,
957 ddb_entry
->default_time2wait
+ 4);
961 int qla4xxx_flash_ddb_change(struct scsi_qla_host
*ha
, uint32_t fw_ddb_index
,
962 struct ddb_entry
*ddb_entry
, uint32_t state
)
964 uint32_t old_fw_ddb_device_state
;
965 int status
= QLA_ERROR
;
967 old_fw_ddb_device_state
= ddb_entry
->fw_ddb_device_state
;
968 DEBUG2(ql4_printk(KERN_INFO
, ha
,
969 "%s: DDB - old state = 0x%x, new state = 0x%x for "
970 "index [%d]\n", __func__
,
971 ddb_entry
->fw_ddb_device_state
, state
, fw_ddb_index
));
973 ddb_entry
->fw_ddb_device_state
= state
;
975 switch (old_fw_ddb_device_state
) {
976 case DDB_DS_LOGIN_IN_PROCESS
:
977 case DDB_DS_NO_CONNECTION_ACTIVE
:
979 case DDB_DS_SESSION_ACTIVE
:
980 ddb_entry
->unblock_sess(ddb_entry
->sess
);
981 qla4xxx_update_session_conn_fwddb_param(ha
, ddb_entry
);
982 status
= QLA_SUCCESS
;
984 case DDB_DS_SESSION_FAILED
:
985 iscsi_block_session(ddb_entry
->sess
);
986 if (!test_bit(DF_RELOGIN
, &ddb_entry
->flags
))
987 qla4xxx_arm_relogin_timer(ddb_entry
);
988 status
= QLA_SUCCESS
;
992 case DDB_DS_SESSION_ACTIVE
:
994 case DDB_DS_SESSION_FAILED
:
995 iscsi_block_session(ddb_entry
->sess
);
996 if (!test_bit(DF_RELOGIN
, &ddb_entry
->flags
))
997 qla4xxx_arm_relogin_timer(ddb_entry
);
998 status
= QLA_SUCCESS
;
1002 case DDB_DS_SESSION_FAILED
:
1004 case DDB_DS_SESSION_ACTIVE
:
1005 ddb_entry
->unblock_sess(ddb_entry
->sess
);
1006 qla4xxx_update_session_conn_fwddb_param(ha
, ddb_entry
);
1007 status
= QLA_SUCCESS
;
1009 case DDB_DS_SESSION_FAILED
:
1010 if (!test_bit(DF_RELOGIN
, &ddb_entry
->flags
))
1011 qla4xxx_arm_relogin_timer(ddb_entry
);
1012 status
= QLA_SUCCESS
;
1017 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: Unknown Event\n",
1025 * qla4xxx_process_ddb_changed - process ddb state change
1026 * @ha - Pointer to host adapter structure.
1027 * @fw_ddb_index - Firmware's device database index
1028 * @state - Device state
1030 * This routine processes a Decive Database Changed AEN Event.
1032 int qla4xxx_process_ddb_changed(struct scsi_qla_host
*ha
,
1033 uint32_t fw_ddb_index
,
1034 uint32_t state
, uint32_t conn_err
)
1036 struct ddb_entry
*ddb_entry
;
1037 int status
= QLA_ERROR
;
1039 /* check for out of range index */
1040 if (fw_ddb_index
>= MAX_DDB_ENTRIES
)
1041 goto exit_ddb_event
;
1043 /* Get the corresponging ddb entry */
1044 ddb_entry
= qla4xxx_lookup_ddb_by_fw_index(ha
, fw_ddb_index
);
1045 /* Device does not currently exist in our database. */
1046 if (ddb_entry
== NULL
) {
1047 ql4_printk(KERN_ERR
, ha
, "%s: No ddb_entry at FW index [%d]\n",
1048 __func__
, fw_ddb_index
);
1050 if (state
== DDB_DS_NO_CONNECTION_ACTIVE
)
1051 clear_bit(fw_ddb_index
, ha
->ddb_idx_map
);
1053 goto exit_ddb_event
;
1056 ddb_entry
->ddb_change(ha
, fw_ddb_index
, ddb_entry
, state
);
1063 * qla4xxx_login_flash_ddb - Login to target (DDB)
1064 * @cls_session: Pointer to the session to login
1066 * This routine logins to the target.
1067 * Issues setddb and conn open mbx
1069 void qla4xxx_login_flash_ddb(struct iscsi_cls_session
*cls_session
)
1071 struct iscsi_session
*sess
;
1072 struct ddb_entry
*ddb_entry
;
1073 struct scsi_qla_host
*ha
;
1074 struct dev_db_entry
*fw_ddb_entry
= NULL
;
1075 dma_addr_t fw_ddb_dma
;
1076 uint32_t mbx_sts
= 0;
1079 sess
= cls_session
->dd_data
;
1080 ddb_entry
= sess
->dd_data
;
1083 if (!test_bit(AF_LINK_UP
, &ha
->flags
))
1086 if (ddb_entry
->ddb_type
!= FLASH_DDB
) {
1087 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1088 "Skipping login to non FLASH DB"));
1092 fw_ddb_entry
= dma_pool_alloc(ha
->fw_ddb_dma_pool
, GFP_KERNEL
,
1094 if (fw_ddb_entry
== NULL
) {
1095 DEBUG2(ql4_printk(KERN_ERR
, ha
, "Out of memory\n"));
1099 if (ddb_entry
->fw_ddb_index
== INVALID_ENTRY
) {
1100 ret
= qla4xxx_get_ddb_index(ha
, &ddb_entry
->fw_ddb_index
);
1101 if (ret
== QLA_ERROR
)
1104 ha
->fw_ddb_index_map
[ddb_entry
->fw_ddb_index
] = ddb_entry
;
1108 memcpy(fw_ddb_entry
, &ddb_entry
->fw_ddb_entry
,
1109 sizeof(struct dev_db_entry
));
1110 ddb_entry
->sess
->target_id
= ddb_entry
->fw_ddb_index
;
1112 ret
= qla4xxx_set_ddb_entry(ha
, ddb_entry
->fw_ddb_index
,
1113 fw_ddb_dma
, &mbx_sts
);
1114 if (ret
== QLA_ERROR
) {
1115 DEBUG2(ql4_printk(KERN_ERR
, ha
, "Set DDB failed\n"));
1119 ddb_entry
->fw_ddb_device_state
= DDB_DS_LOGIN_IN_PROCESS
;
1120 ret
= qla4xxx_conn_open(ha
, ddb_entry
->fw_ddb_index
);
1121 if (ret
== QLA_ERROR
) {
1122 ql4_printk(KERN_ERR
, ha
, "%s: Login failed: %s\n", __func__
,
1129 dma_pool_free(ha
->fw_ddb_dma_pool
, fw_ddb_entry
, fw_ddb_dma
);