2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2006 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
8 #include <scsi/iscsi_if.h>
12 #include "ql4_inline.h"
14 static struct ddb_entry
*qla4xxx_alloc_ddb(struct scsi_qla_host
*ha
,
15 uint32_t fw_ddb_index
);
17 static void ql4xxx_set_mac_number(struct scsi_qla_host
*ha
)
23 /* Get the function number */
24 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
25 value
= readw(&ha
->reg
->ctrl_status
);
26 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
28 func_number
= (uint8_t) ((value
>> 4) & 0x30);
29 switch (value
& ISP_CONTROL_FN_MASK
) {
30 case ISP_CONTROL_FN0_SCSI
:
33 case ISP_CONTROL_FN1_SCSI
:
37 DEBUG2(printk("scsi%ld: %s: Invalid function number, "
38 "ispControlStatus = 0x%x\n", ha
->host_no
,
42 DEBUG2(printk("scsi%ld: %s: mac_index %d.\n", ha
->host_no
, __func__
,
47 * qla4xxx_free_ddb - deallocate ddb
48 * @ha: pointer to host adapter structure.
49 * @ddb_entry: pointer to device database entry
51 * This routine deallocates and unlinks the specified ddb_entry from the
54 void qla4xxx_free_ddb(struct scsi_qla_host
*ha
,
55 struct ddb_entry
*ddb_entry
)
57 /* Remove device entry from list */
58 list_del_init(&ddb_entry
->list
);
60 /* Remove device pointer from index mapping arrays */
61 ha
->fw_ddb_index_map
[ddb_entry
->fw_ddb_index
] =
62 (struct ddb_entry
*) INVALID_ENTRY
;
65 /* Free memory and scsi-ml struct for device entry */
66 qla4xxx_destroy_sess(ddb_entry
);
70 * qla4xxx_free_ddb_list - deallocate all ddbs
71 * @ha: pointer to host adapter structure.
73 * This routine deallocates and removes all devices on the sppecified adapter.
75 void qla4xxx_free_ddb_list(struct scsi_qla_host
*ha
)
77 struct list_head
*ptr
;
78 struct ddb_entry
*ddb_entry
;
80 while (!list_empty(&ha
->ddb_list
)) {
81 ptr
= ha
->ddb_list
.next
;
82 /* Free memory for device entry and remove */
83 ddb_entry
= list_entry(ptr
, struct ddb_entry
, list
);
84 qla4xxx_free_ddb(ha
, ddb_entry
);
89 * qla4xxx_init_response_q_entries() - Initializes response queue entries.
92 * Beginning of request ring has initialization control block already built
93 * by nvram config routine.
95 static void qla4xxx_init_response_q_entries(struct scsi_qla_host
*ha
)
100 pkt
= (struct response
*)ha
->response_ptr
;
101 for (cnt
= 0; cnt
< RESPONSE_QUEUE_DEPTH
; cnt
++) {
102 pkt
->signature
= RESPONSE_PROCESSED
;
108 * qla4xxx_init_rings - initialize hw queues
109 * @ha: pointer to host adapter structure.
111 * This routine initializes the internal queues for the specified adapter.
112 * The QLA4010 requires us to restart the queues at index 0.
113 * The QLA4000 doesn't care, so just default to QLA4010's requirement.
115 int qla4xxx_init_rings(struct scsi_qla_host
*ha
)
117 unsigned long flags
= 0;
119 /* Initialize request queue. */
120 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
123 ha
->request_ptr
= &ha
->request_ring
[ha
->request_in
];
124 ha
->req_q_count
= REQUEST_QUEUE_DEPTH
;
126 /* Initialize response queue. */
128 ha
->response_out
= 0;
129 ha
->response_ptr
= &ha
->response_ring
[ha
->response_out
];
131 if (is_qla8022(ha
)) {
133 (unsigned long __iomem
*)&ha
->qla4_8xxx_reg
->req_q_out
);
135 (unsigned long __iomem
*)&ha
->qla4_8xxx_reg
->rsp_q_in
);
137 (unsigned long __iomem
*)&ha
->qla4_8xxx_reg
->rsp_q_out
);
140 * Initialize DMA Shadow registers. The firmware is really
141 * supposed to take care of this, but on some uniprocessor
142 * systems, the shadow registers aren't cleared-- causing
143 * the interrupt_handler to think there are responses to be
144 * processed when there aren't.
146 ha
->shadow_regs
->req_q_out
= __constant_cpu_to_le32(0);
147 ha
->shadow_regs
->rsp_q_in
= __constant_cpu_to_le32(0);
150 writel(0, &ha
->reg
->req_q_in
);
151 writel(0, &ha
->reg
->rsp_q_out
);
152 readl(&ha
->reg
->rsp_q_out
);
155 qla4xxx_init_response_q_entries(ha
);
157 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
163 * qla4xxx_get_sys_info - validate adapter MAC address(es)
164 * @ha: pointer to host adapter structure.
167 int qla4xxx_get_sys_info(struct scsi_qla_host
*ha
)
169 struct flash_sys_info
*sys_info
;
170 dma_addr_t sys_info_dma
;
171 int status
= QLA_ERROR
;
173 sys_info
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*sys_info
),
174 &sys_info_dma
, GFP_KERNEL
);
175 if (sys_info
== NULL
) {
176 DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
177 ha
->host_no
, __func__
));
179 goto exit_get_sys_info_no_free
;
181 memset(sys_info
, 0, sizeof(*sys_info
));
183 /* Get flash sys info */
184 if (qla4xxx_get_flash(ha
, sys_info_dma
, FLASH_OFFSET_SYS_INFO
,
185 sizeof(*sys_info
)) != QLA_SUCCESS
) {
186 DEBUG2(printk("scsi%ld: %s: get_flash FLASH_OFFSET_SYS_INFO "
187 "failed\n", ha
->host_no
, __func__
));
189 goto exit_get_sys_info
;
192 /* Save M.A.C. address & serial_number */
193 memcpy(ha
->my_mac
, &sys_info
->physAddr
[0].address
[0],
194 min(sizeof(ha
->my_mac
),
195 sizeof(sys_info
->physAddr
[0].address
)));
196 memcpy(ha
->serial_number
, &sys_info
->acSerialNumber
,
197 min(sizeof(ha
->serial_number
),
198 sizeof(sys_info
->acSerialNumber
)));
200 status
= QLA_SUCCESS
;
203 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*sys_info
), sys_info
,
206 exit_get_sys_info_no_free
:
211 * qla4xxx_init_local_data - initialize adapter specific local data
212 * @ha: pointer to host adapter structure.
215 static int qla4xxx_init_local_data(struct scsi_qla_host
*ha
)
217 /* Initialize aen queue */
218 ha
->aen_q_count
= MAX_AEN_ENTRIES
;
220 return qla4xxx_get_firmware_status(ha
);
224 qla4xxx_wait_for_ip_config(struct scsi_qla_host
*ha
)
226 uint8_t ipv4_wait
= 0;
227 uint8_t ipv6_wait
= 0;
228 int8_t ip_address
[IPv6_ADDR_LEN
] = {0} ;
230 /* If both IPv4 & IPv6 are enabled, possibly only one
231 * IP address may be acquired, so check to see if we
232 * need to wait for another */
233 if (is_ipv4_enabled(ha
) && is_ipv6_enabled(ha
)) {
234 if (((ha
->addl_fw_state
& FW_ADDSTATE_DHCPv4_ENABLED
) != 0) &&
235 ((ha
->addl_fw_state
&
236 FW_ADDSTATE_DHCPv4_LEASE_ACQUIRED
) == 0)) {
239 if (((ha
->ipv6_addl_options
&
240 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE
) != 0) &&
241 ((ha
->ipv6_link_local_state
== IP_ADDRSTATE_ACQUIRING
) ||
242 (ha
->ipv6_addr0_state
== IP_ADDRSTATE_ACQUIRING
) ||
243 (ha
->ipv6_addr1_state
== IP_ADDRSTATE_ACQUIRING
))) {
247 if ((ha
->ipv6_link_local_state
==
248 IP_ADDRSTATE_PREFERRED
) ||
249 (ha
->ipv6_addr0_state
== IP_ADDRSTATE_PREFERRED
) ||
250 (ha
->ipv6_addr1_state
== IP_ADDRSTATE_PREFERRED
)) {
251 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: "
252 "Preferred IP configured."
253 " Don't wait!\n", ha
->host_no
,
257 if (memcmp(&ha
->ipv6_default_router_addr
, ip_address
,
258 IPv6_ADDR_LEN
) == 0) {
259 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: "
260 "No Router configured. "
261 "Don't wait!\n", ha
->host_no
,
265 if ((ha
->ipv6_default_router_state
==
266 IPV6_RTRSTATE_MANUAL
) &&
267 (ha
->ipv6_link_local_state
==
268 IP_ADDRSTATE_TENTATIVE
) &&
269 (memcmp(&ha
->ipv6_link_local_addr
,
270 &ha
->ipv6_default_router_addr
, 4) == 0)) {
271 DEBUG2(printk("scsi%ld: %s: LinkLocal Router & "
272 "IP configured. Don't wait!\n",
273 ha
->host_no
, __func__
));
277 if (ipv4_wait
|| ipv6_wait
) {
278 DEBUG2(printk("scsi%ld: %s: Wait for additional "
279 "IP(s) \"", ha
->host_no
, __func__
));
281 DEBUG2(printk("IPv4 "));
282 if (ha
->ipv6_link_local_state
== IP_ADDRSTATE_ACQUIRING
)
283 DEBUG2(printk("IPv6LinkLocal "));
284 if (ha
->ipv6_addr0_state
== IP_ADDRSTATE_ACQUIRING
)
285 DEBUG2(printk("IPv6Addr0 "));
286 if (ha
->ipv6_addr1_state
== IP_ADDRSTATE_ACQUIRING
)
287 DEBUG2(printk("IPv6Addr1 "));
288 DEBUG2(printk("\"\n"));
292 return ipv4_wait
|ipv6_wait
;
295 static int qla4xxx_fw_ready(struct scsi_qla_host
*ha
)
297 uint32_t timeout_count
;
300 DEBUG2(ql4_printk(KERN_INFO
, ha
, "Waiting for Firmware Ready..\n"));
301 for (timeout_count
= ADAPTER_INIT_TOV
; timeout_count
> 0;
303 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR
, &ha
->dpc_flags
))
304 qla4xxx_get_dhcp_ip_address(ha
);
306 /* Get firmware state. */
307 if (qla4xxx_get_firmware_state(ha
) != QLA_SUCCESS
) {
308 DEBUG2(printk("scsi%ld: %s: unable to get firmware "
309 "state\n", ha
->host_no
, __func__
));
313 if (ha
->firmware_state
& FW_STATE_ERROR
) {
314 DEBUG2(printk("scsi%ld: %s: an unrecoverable error has"
315 " occurred\n", ha
->host_no
, __func__
));
319 if (ha
->firmware_state
& FW_STATE_CONFIG_WAIT
) {
321 * The firmware has not yet been issued an Initialize
322 * Firmware command, so issue it now.
324 if (qla4xxx_initialize_fw_cb(ha
) == QLA_ERROR
)
327 /* Go back and test for ready state - no wait. */
331 if (ha
->firmware_state
& FW_STATE_WAIT_AUTOCONNECT
) {
332 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: fwstate:"
333 "AUTOCONNECT in progress\n",
334 ha
->host_no
, __func__
));
337 if (ha
->firmware_state
& FW_STATE_CONFIGURING_IP
) {
338 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: fwstate:"
340 ha
->host_no
, __func__
));
342 * Check for link state after 15 secs and if link is
343 * still DOWN then, cable is unplugged. Ignore "DHCP
344 * in Progress/CONFIGURING IP" bit to check if firmware
345 * is in ready state or not after 15 secs.
346 * This is applicable for both 2.x & 3.x firmware
348 if (timeout_count
<= (ADAPTER_INIT_TOV
- 15)) {
349 if (ha
->addl_fw_state
& FW_ADDSTATE_LINK_UP
) {
350 DEBUG2(printk(KERN_INFO
"scsi%ld: %s:"
351 " LINK UP (Cable plugged)\n",
352 ha
->host_no
, __func__
));
353 } else if (ha
->firmware_state
&
354 (FW_STATE_CONFIGURING_IP
|
356 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: "
357 "LINK DOWN (Cable unplugged)\n",
358 ha
->host_no
, __func__
));
359 ha
->firmware_state
= FW_STATE_READY
;
364 if (ha
->firmware_state
== FW_STATE_READY
) {
365 /* If DHCP IP Addr is available, retrieve it now. */
366 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR
,
368 qla4xxx_get_dhcp_ip_address(ha
);
370 if (!qla4xxx_wait_for_ip_config(ha
) ||
371 timeout_count
== 1) {
372 DEBUG2(ql4_printk(KERN_INFO
, ha
,
373 "Firmware Ready..\n"));
374 /* The firmware is ready to process SCSI
376 DEBUG2(ql4_printk(KERN_INFO
, ha
,
377 "scsi%ld: %s: MEDIA TYPE"
378 " - %s\n", ha
->host_no
,
379 __func__
, (ha
->addl_fw_state
&
380 FW_ADDSTATE_OPTICAL_MEDIA
)
381 != 0 ? "OPTICAL" : "COPPER"));
382 DEBUG2(ql4_printk(KERN_INFO
, ha
,
383 "scsi%ld: %s: DHCPv4 STATE"
384 " Enabled %s\n", ha
->host_no
,
385 __func__
, (ha
->addl_fw_state
&
386 FW_ADDSTATE_DHCPv4_ENABLED
) != 0 ?
388 DEBUG2(ql4_printk(KERN_INFO
, ha
,
389 "scsi%ld: %s: LINK %s\n",
390 ha
->host_no
, __func__
,
392 FW_ADDSTATE_LINK_UP
) != 0 ?
394 DEBUG2(ql4_printk(KERN_INFO
, ha
,
395 "scsi%ld: %s: iSNS Service "
397 ha
->host_no
, __func__
,
399 FW_ADDSTATE_ISNS_SVC_ENABLED
) != 0 ?
406 DEBUG2(printk("scsi%ld: %s: waiting on fw, state=%x:%x - "
407 "seconds expired= %d\n", ha
->host_no
, __func__
,
408 ha
->firmware_state
, ha
->addl_fw_state
,
410 if (is_qla4032(ha
) &&
411 !(ha
->addl_fw_state
& FW_ADDSTATE_LINK_UP
) &&
412 (timeout_count
< ADAPTER_INIT_TOV
- 5)) {
419 if (timeout_count
<= 0)
420 DEBUG2(printk("scsi%ld: %s: FW Initialization timed out!\n",
421 ha
->host_no
, __func__
));
423 if (ha
->firmware_state
& FW_STATE_CONFIGURING_IP
) {
424 DEBUG2(printk("scsi%ld: %s: FW initialized, but is reporting "
425 "it's waiting to configure an IP address\n",
426 ha
->host_no
, __func__
));
428 } else if (ha
->firmware_state
& FW_STATE_WAIT_AUTOCONNECT
) {
429 DEBUG2(printk("scsi%ld: %s: FW initialized, but "
430 "auto-discovery still in process\n",
431 ha
->host_no
, __func__
));
439 * qla4xxx_init_firmware - initializes the firmware.
440 * @ha: pointer to host adapter structure.
443 static int qla4xxx_init_firmware(struct scsi_qla_host
*ha
)
445 int status
= QLA_ERROR
;
447 if (is_aer_supported(ha
) &&
448 test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE
, &ha
->flags
))
451 /* For 82xx, stop firmware before initializing because if BIOS
452 * has previously initialized firmware, then driver's initialize
453 * firmware will fail. */
455 qla4_8xxx_stop_firmware(ha
);
457 ql4_printk(KERN_INFO
, ha
, "Initializing firmware..\n");
458 if (qla4xxx_initialize_fw_cb(ha
) == QLA_ERROR
) {
459 DEBUG2(printk("scsi%ld: %s: Failed to initialize firmware "
460 "control block\n", ha
->host_no
, __func__
));
463 if (!qla4xxx_fw_ready(ha
))
466 return qla4xxx_get_firmware_status(ha
);
469 static struct ddb_entry
* qla4xxx_get_ddb_entry(struct scsi_qla_host
*ha
,
470 uint32_t fw_ddb_index
,
473 struct dev_db_entry
*fw_ddb_entry
= NULL
;
474 dma_addr_t fw_ddb_entry_dma
;
475 struct ddb_entry
*ddb_entry
= NULL
;
477 uint32_t device_state
;
480 /* Make sure the dma buffer is valid */
481 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
,
482 sizeof(*fw_ddb_entry
),
483 &fw_ddb_entry_dma
, GFP_KERNEL
);
484 if (fw_ddb_entry
== NULL
) {
485 DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
486 ha
->host_no
, __func__
));
487 goto exit_get_ddb_entry_no_free
;
490 if (qla4xxx_get_fwddb_entry(ha
, fw_ddb_index
, fw_ddb_entry
,
491 fw_ddb_entry_dma
, NULL
, NULL
,
492 &device_state
, NULL
, NULL
, NULL
) ==
494 DEBUG2(printk("scsi%ld: %s: failed get_ddb_entry for "
495 "fw_ddb_index %d\n", ha
->host_no
, __func__
,
497 goto exit_get_ddb_entry
;
500 /* Allocate DDB if not already allocated. */
501 DEBUG2(printk("scsi%ld: %s: Looking for ddb[%d]\n", ha
->host_no
,
502 __func__
, fw_ddb_index
));
503 list_for_each_entry(ddb_entry
, &ha
->ddb_list
, list
) {
504 if ((memcmp(ddb_entry
->iscsi_name
, fw_ddb_entry
->iscsi_name
,
505 ISCSI_NAME_SIZE
) == 0) &&
507 le32_to_cpu(fw_ddb_entry
->tgt_portal_grp
)) &&
508 (memcmp(ddb_entry
->isid
, fw_ddb_entry
->isid
,
509 sizeof(ddb_entry
->isid
)) == 0)) {
515 /* if not found allocate new ddb */
517 DEBUG2(printk("scsi%ld: %s: ddb[%d] not found - allocating "
518 "new ddb\n", ha
->host_no
, __func__
,
521 ddb_entry
= qla4xxx_alloc_ddb(ha
, fw_ddb_index
);
525 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
), fw_ddb_entry
,
528 exit_get_ddb_entry_no_free
:
533 * qla4xxx_update_ddb_entry - update driver's internal ddb
534 * @ha: pointer to host adapter structure.
535 * @ddb_entry: pointer to device database structure to be filled
536 * @fw_ddb_index: index of the ddb entry in fw ddb table
538 * This routine updates the driver's internal device database entry
539 * with information retrieved from the firmware's device database
540 * entry for the specified device. The ddb_entry->fw_ddb_index field
541 * must be initialized prior to calling this routine
544 static int qla4xxx_update_ddb_entry(struct scsi_qla_host
*ha
,
545 struct ddb_entry
*ddb_entry
,
546 uint32_t fw_ddb_index
)
548 struct dev_db_entry
*fw_ddb_entry
= NULL
;
549 dma_addr_t fw_ddb_entry_dma
;
550 int status
= QLA_ERROR
;
553 if (ddb_entry
== NULL
) {
554 DEBUG2(printk("scsi%ld: %s: ddb_entry is NULL\n", ha
->host_no
,
557 goto exit_update_ddb_no_free
;
560 /* Make sure the dma buffer is valid */
561 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
,
562 sizeof(*fw_ddb_entry
),
563 &fw_ddb_entry_dma
, GFP_KERNEL
);
564 if (fw_ddb_entry
== NULL
) {
565 DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
566 ha
->host_no
, __func__
));
568 goto exit_update_ddb_no_free
;
571 if (qla4xxx_get_fwddb_entry(ha
, fw_ddb_index
, fw_ddb_entry
,
572 fw_ddb_entry_dma
, NULL
, NULL
,
573 &ddb_entry
->fw_ddb_device_state
, &conn_err
,
574 &ddb_entry
->tcp_source_port_num
,
575 &ddb_entry
->connection_id
) ==
577 DEBUG2(printk("scsi%ld: %s: failed get_ddb_entry for "
578 "fw_ddb_index %d\n", ha
->host_no
, __func__
,
581 goto exit_update_ddb
;
584 status
= QLA_SUCCESS
;
585 ddb_entry
->options
= le16_to_cpu(fw_ddb_entry
->options
);
586 ddb_entry
->target_session_id
= le16_to_cpu(fw_ddb_entry
->tsid
);
587 ddb_entry
->task_mgmt_timeout
=
588 le16_to_cpu(fw_ddb_entry
->def_timeout
);
589 ddb_entry
->CmdSn
= 0;
590 ddb_entry
->exe_throttle
= le16_to_cpu(fw_ddb_entry
->exec_throttle
);
591 ddb_entry
->default_relogin_timeout
=
592 le16_to_cpu(fw_ddb_entry
->def_timeout
);
593 ddb_entry
->default_time2wait
= le16_to_cpu(fw_ddb_entry
->iscsi_def_time2wait
);
595 /* Update index in case it changed */
596 ddb_entry
->fw_ddb_index
= fw_ddb_index
;
597 ha
->fw_ddb_index_map
[fw_ddb_index
] = ddb_entry
;
599 ddb_entry
->port
= le16_to_cpu(fw_ddb_entry
->port
);
600 ddb_entry
->tpgt
= le32_to_cpu(fw_ddb_entry
->tgt_portal_grp
);
601 memcpy(ddb_entry
->isid
, fw_ddb_entry
->isid
, sizeof(ddb_entry
->isid
));
603 memcpy(&ddb_entry
->iscsi_name
[0], &fw_ddb_entry
->iscsi_name
[0],
604 min(sizeof(ddb_entry
->iscsi_name
),
605 sizeof(fw_ddb_entry
->iscsi_name
)));
606 memcpy(&ddb_entry
->iscsi_alias
[0], &fw_ddb_entry
->iscsi_alias
[0],
607 min(sizeof(ddb_entry
->iscsi_alias
),
608 sizeof(fw_ddb_entry
->iscsi_alias
)));
609 memcpy(&ddb_entry
->ip_addr
[0], &fw_ddb_entry
->ip_addr
[0],
610 min(sizeof(ddb_entry
->ip_addr
), sizeof(fw_ddb_entry
->ip_addr
)));
612 ddb_entry
->iscsi_max_burst_len
= fw_ddb_entry
->iscsi_max_burst_len
;
613 ddb_entry
->iscsi_max_outsnd_r2t
= fw_ddb_entry
->iscsi_max_outsnd_r2t
;
614 ddb_entry
->iscsi_first_burst_len
= fw_ddb_entry
->iscsi_first_burst_len
;
615 ddb_entry
->iscsi_max_rcv_data_seg_len
=
616 fw_ddb_entry
->iscsi_max_rcv_data_seg_len
;
617 ddb_entry
->iscsi_max_snd_data_seg_len
=
618 fw_ddb_entry
->iscsi_max_snd_data_seg_len
;
620 if (ddb_entry
->options
& DDB_OPT_IPV6_DEVICE
) {
621 memcpy(&ddb_entry
->remote_ipv6_addr
,
622 fw_ddb_entry
->ip_addr
,
623 min(sizeof(ddb_entry
->remote_ipv6_addr
),
624 sizeof(fw_ddb_entry
->ip_addr
)));
625 memcpy(&ddb_entry
->link_local_ipv6_addr
,
626 fw_ddb_entry
->link_local_ipv6_addr
,
627 min(sizeof(ddb_entry
->link_local_ipv6_addr
),
628 sizeof(fw_ddb_entry
->link_local_ipv6_addr
)));
630 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: DDB[%d] State %04x"
631 " ConnErr %08x IP %pI6 "
633 __func__
, fw_ddb_index
,
634 ddb_entry
->fw_ddb_device_state
,
635 conn_err
, fw_ddb_entry
->ip_addr
,
636 le16_to_cpu(fw_ddb_entry
->port
),
637 fw_ddb_entry
->iscsi_name
));
639 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: DDB[%d] State %04x"
640 " ConnErr %08x IP %pI4 "
642 __func__
, fw_ddb_index
,
643 ddb_entry
->fw_ddb_device_state
,
644 conn_err
, fw_ddb_entry
->ip_addr
,
645 le16_to_cpu(fw_ddb_entry
->port
),
646 fw_ddb_entry
->iscsi_name
));
649 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
650 fw_ddb_entry
, fw_ddb_entry_dma
);
652 exit_update_ddb_no_free
:
657 * qla4xxx_alloc_ddb - allocate device database entry
658 * @ha: Pointer to host adapter structure.
659 * @fw_ddb_index: Firmware's device database index
661 * This routine allocates a ddb_entry, ititializes some values, and
662 * inserts it into the ddb list.
664 static struct ddb_entry
* qla4xxx_alloc_ddb(struct scsi_qla_host
*ha
,
665 uint32_t fw_ddb_index
)
667 struct ddb_entry
*ddb_entry
;
669 DEBUG2(printk("scsi%ld: %s: fw_ddb_index [%d]\n", ha
->host_no
,
670 __func__
, fw_ddb_index
));
672 ddb_entry
= qla4xxx_alloc_sess(ha
);
673 if (ddb_entry
== NULL
) {
674 DEBUG2(printk("scsi%ld: %s: Unable to allocate memory "
675 "to add fw_ddb_index [%d]\n",
676 ha
->host_no
, __func__
, fw_ddb_index
));
680 ddb_entry
->fw_ddb_index
= fw_ddb_index
;
681 atomic_set(&ddb_entry
->retry_relogin_timer
, INVALID_ENTRY
);
682 atomic_set(&ddb_entry
->relogin_timer
, 0);
683 atomic_set(&ddb_entry
->relogin_retry_count
, 0);
684 atomic_set(&ddb_entry
->state
, DDB_STATE_ONLINE
);
685 list_add_tail(&ddb_entry
->list
, &ha
->ddb_list
);
686 ha
->fw_ddb_index_map
[fw_ddb_index
] = ddb_entry
;
693 * qla4_is_relogin_allowed - Are we allowed to login?
694 * @ha: Pointer to host adapter structure.
695 * @conn_err: Last connection error associated with the ddb
697 * This routine tests the given connection error to determine if
698 * we are allowed to login.
700 int qla4_is_relogin_allowed(struct scsi_qla_host
*ha
, uint32_t conn_err
)
702 uint32_t err_code
, login_rsp_sts_class
;
705 err_code
= ((conn_err
& 0x00ff0000) >> 16);
706 login_rsp_sts_class
= ((conn_err
& 0x0000ff00) >> 8);
707 if (err_code
== 0x1c || err_code
== 0x06) {
708 DEBUG2(ql4_printk(KERN_INFO
, ha
,
709 ": conn_err=0x%08x, send target completed"
710 " or access denied failure\n", conn_err
));
713 if ((err_code
== 0x08) && (login_rsp_sts_class
== 0x02)) {
714 /* Login Response PDU returned an error.
715 Login Response Status in Error Code Detail
716 indicates login should not be retried.*/
717 DEBUG2(ql4_printk(KERN_INFO
, ha
,
718 ": conn_err=0x%08x, do not retry relogin\n",
727 * qla4xxx_configure_ddbs - builds driver ddb list
728 * @ha: Pointer to host adapter structure.
730 * This routine searches for all valid firmware ddb entries and builds
731 * an internal ddb list. Ddbs that are considered valid are those with
732 * a device state of SESSION_ACTIVE.
734 static int qla4xxx_build_ddb_list(struct scsi_qla_host
*ha
)
736 int status
= QLA_ERROR
;
737 uint32_t fw_ddb_index
= 0;
738 uint32_t next_fw_ddb_index
= 0;
741 struct ddb_entry
*ddb_entry
;
742 struct dev_db_entry
*fw_ddb_entry
= NULL
;
743 dma_addr_t fw_ddb_entry_dma
;
744 uint32_t ipv6_device
;
747 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
748 &fw_ddb_entry_dma
, GFP_KERNEL
);
749 if (fw_ddb_entry
== NULL
) {
750 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: DMA alloc failed\n",
753 goto exit_build_ddb_list_no_free
;
756 ql4_printk(KERN_INFO
, ha
, "Initializing DDBs ...\n");
757 for (fw_ddb_index
= 0; fw_ddb_index
< MAX_DDB_ENTRIES
;
758 fw_ddb_index
= next_fw_ddb_index
) {
759 /* First, let's see if a device exists here */
760 if (qla4xxx_get_fwddb_entry(ha
, fw_ddb_index
, fw_ddb_entry
,
761 0, NULL
, &next_fw_ddb_index
,
762 &ddb_state
, &conn_err
,
765 DEBUG2(printk("scsi%ld: %s: get_ddb_entry, "
766 "fw_ddb_index %d failed", ha
->host_no
,
767 __func__
, fw_ddb_index
));
768 goto exit_build_ddb_list
;
771 DEBUG2(printk("scsi%ld: %s: Getting DDB[%d] ddbstate=0x%x, "
772 "next_fw_ddb_index=%d.\n", ha
->host_no
, __func__
,
773 fw_ddb_index
, ddb_state
, next_fw_ddb_index
));
775 /* Issue relogin, if necessary. */
776 if (ddb_state
== DDB_DS_SESSION_FAILED
||
777 ddb_state
== DDB_DS_NO_CONNECTION_ACTIVE
) {
778 /* Try and login to device */
779 DEBUG2(printk("scsi%ld: %s: Login to DDB[%d]\n",
780 ha
->host_no
, __func__
, fw_ddb_index
));
781 ipv6_device
= le16_to_cpu(fw_ddb_entry
->options
) &
783 if (qla4_is_relogin_allowed(ha
, conn_err
) &&
785 *((uint32_t *)fw_ddb_entry
->ip_addr
))
787 qla4xxx_set_ddb_entry(ha
, fw_ddb_index
, 0);
788 if (qla4xxx_get_fwddb_entry(ha
, fw_ddb_index
,
791 &ddb_state
, &conn_err
,
794 DEBUG2(printk("scsi%ld: %s:"
795 "get_ddb_entry %d failed\n",
797 __func__
, fw_ddb_index
));
798 goto exit_build_ddb_list
;
803 if (ddb_state
!= DDB_DS_SESSION_ACTIVE
)
806 * if fw_ddb with session active state found,
809 DEBUG2(printk("scsi%ld: %s: DDB[%d] added to list\n",
810 ha
->host_no
, __func__
, fw_ddb_index
));
812 /* Add DDB to internal our ddb list. */
813 ddb_entry
= qla4xxx_get_ddb_entry(ha
, fw_ddb_index
, &new_tgt
);
814 if (ddb_entry
== NULL
) {
815 DEBUG2(printk("scsi%ld: %s: Unable to allocate memory "
816 "for device at fw_ddb_index %d\n",
817 ha
->host_no
, __func__
, fw_ddb_index
));
818 goto exit_build_ddb_list
;
820 /* Fill in the device structure */
821 if (qla4xxx_update_ddb_entry(ha
, ddb_entry
, fw_ddb_index
) ==
823 ha
->fw_ddb_index_map
[fw_ddb_index
] =
824 (struct ddb_entry
*)INVALID_ENTRY
;
826 DEBUG2(printk("scsi%ld: %s: update_ddb_entry failed "
827 "for fw_ddb_index %d.\n",
828 ha
->host_no
, __func__
, fw_ddb_index
));
829 goto exit_build_ddb_list
;
833 /* We know we've reached the last device when
834 * next_fw_ddb_index is 0 */
835 if (next_fw_ddb_index
== 0)
839 status
= QLA_SUCCESS
;
840 ql4_printk(KERN_INFO
, ha
, "DDB list done..\n");
843 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
), fw_ddb_entry
,
846 exit_build_ddb_list_no_free
:
850 struct qla4_relog_scan
{
853 uint32_t fw_ddb_index
;
854 uint32_t next_fw_ddb_index
;
855 uint32_t fw_ddb_device_state
;
858 static int qla4_test_rdy(struct scsi_qla_host
*ha
, struct qla4_relog_scan
*rs
)
860 struct ddb_entry
*ddb_entry
;
862 if (qla4_is_relogin_allowed(ha
, rs
->conn_err
)) {
863 /* We either have a device that is in
864 * the process of relogging in or a
865 * device that is waiting to be
869 ddb_entry
= qla4xxx_lookup_ddb_by_fw_index(ha
,
871 if (ddb_entry
== NULL
)
874 if (ddb_entry
->dev_scan_wait_to_start_relogin
!= 0
875 && time_after_eq(jiffies
,
877 dev_scan_wait_to_start_relogin
))
879 ddb_entry
->dev_scan_wait_to_start_relogin
= 0;
880 qla4xxx_set_ddb_entry(ha
, rs
->fw_ddb_index
, 0);
886 static int qla4_scan_for_relogin(struct scsi_qla_host
*ha
,
887 struct qla4_relog_scan
*rs
)
892 * ----------------- */
893 for (rs
->fw_ddb_index
= 0; rs
->fw_ddb_index
< MAX_DDB_ENTRIES
;
894 rs
->fw_ddb_index
= rs
->next_fw_ddb_index
) {
895 if (qla4xxx_get_fwddb_entry(ha
, rs
->fw_ddb_index
, NULL
, 0,
896 NULL
, &rs
->next_fw_ddb_index
,
897 &rs
->fw_ddb_device_state
,
898 &rs
->conn_err
, NULL
, NULL
)
902 if (rs
->fw_ddb_device_state
== DDB_DS_LOGIN_IN_PROCESS
)
905 if (rs
->fw_ddb_device_state
== DDB_DS_SESSION_FAILED
||
906 rs
->fw_ddb_device_state
== DDB_DS_NO_CONNECTION_ACTIVE
) {
907 error
= qla4_test_rdy(ha
, rs
);
912 /* We know we've reached the last device when
913 * next_fw_ddb_index is 0 */
914 if (rs
->next_fw_ddb_index
== 0)
921 * qla4xxx_devices_ready - wait for target devices to be logged in
922 * @ha: pointer to adapter structure
924 * This routine waits up to ql4xdiscoverywait seconds
925 * F/W database during driver load time.
927 static int qla4xxx_devices_ready(struct scsi_qla_host
*ha
)
930 unsigned long discovery_wtime
;
931 struct qla4_relog_scan rs
;
933 discovery_wtime
= jiffies
+ (ql4xdiscoverywait
* HZ
);
935 DEBUG(printk("Waiting (%d) for devices ...\n", ql4xdiscoverywait
));
938 qla4xxx_get_firmware_state(ha
);
939 if (test_and_clear_bit(DPC_AEN
, &ha
->dpc_flags
)) {
940 /* Set time-between-relogin timer */
941 qla4xxx_process_aen(ha
, RELOGIN_DDB_CHANGED_AENS
);
944 /* if no relogins active or needed, halt discvery wait */
947 error
= qla4_scan_for_relogin(ha
, &rs
);
950 DEBUG2(printk("scsi%ld: %s: Delay halted. Devices "
951 "Ready.\n", ha
->host_no
, __func__
));
956 } while (!time_after_eq(jiffies
, discovery_wtime
));
958 DEBUG3(qla4xxx_get_conn_event_log(ha
));
963 static void qla4xxx_flush_AENS(struct scsi_qla_host
*ha
)
967 /* Flush the 0x8014 AEN from the firmware as a result of
968 * Auto connect. We are basically doing get_firmware_ddb()
969 * to determine whether we need to log back in or not.
970 * Trying to do a set ddb before we have processed 0x8014
971 * will result in another set_ddb() for the same ddb. In other
972 * words there will be stale entries in the aen_q.
974 wtime
= jiffies
+ (2 * HZ
);
976 if (qla4xxx_get_firmware_state(ha
) == QLA_SUCCESS
)
977 if (ha
->firmware_state
& (BIT_2
| BIT_0
))
980 if (test_and_clear_bit(DPC_AEN
, &ha
->dpc_flags
))
981 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
984 } while (!time_after_eq(jiffies
, wtime
));
988 static int qla4xxx_initialize_ddb_list(struct scsi_qla_host
*ha
)
990 uint16_t fw_ddb_index
;
991 int status
= QLA_SUCCESS
;
993 /* free the ddb list if is not empty */
994 if (!list_empty(&ha
->ddb_list
))
995 qla4xxx_free_ddb_list(ha
);
997 for (fw_ddb_index
= 0; fw_ddb_index
< MAX_DDB_ENTRIES
; fw_ddb_index
++)
998 ha
->fw_ddb_index_map
[fw_ddb_index
] =
999 (struct ddb_entry
*)INVALID_ENTRY
;
1003 qla4xxx_flush_AENS(ha
);
1005 /* Wait for an AEN */
1006 qla4xxx_devices_ready(ha
);
1009 * First perform device discovery for active
1010 * fw ddb indexes and build
1013 if ((status
= qla4xxx_build_ddb_list(ha
)) == QLA_ERROR
)
1017 * Targets can come online after the inital discovery, so processing
1018 * the aens here will catch them.
1020 if (test_and_clear_bit(DPC_AEN
, &ha
->dpc_flags
))
1021 qla4xxx_process_aen(ha
, PROCESS_ALL_AENS
);
1027 * qla4xxx_reinitialize_ddb_list - update the driver ddb list
1028 * @ha: pointer to host adapter structure.
1030 * This routine obtains device information from the F/W database after
1031 * firmware or adapter resets. The device table is preserved.
1033 int qla4xxx_reinitialize_ddb_list(struct scsi_qla_host
*ha
)
1035 int status
= QLA_SUCCESS
;
1036 struct ddb_entry
*ddb_entry
, *detemp
;
1038 /* Update the device information for all devices. */
1039 list_for_each_entry_safe(ddb_entry
, detemp
, &ha
->ddb_list
, list
) {
1040 qla4xxx_update_ddb_entry(ha
, ddb_entry
,
1041 ddb_entry
->fw_ddb_index
);
1042 if (ddb_entry
->fw_ddb_device_state
== DDB_DS_SESSION_ACTIVE
) {
1043 atomic_set(&ddb_entry
->state
, DDB_STATE_ONLINE
);
1044 DEBUG2(printk ("scsi%ld: %s: ddb index [%d] marked "
1045 "ONLINE\n", ha
->host_no
, __func__
,
1046 ddb_entry
->fw_ddb_index
));
1047 iscsi_unblock_session(ddb_entry
->sess
);
1048 } else if (atomic_read(&ddb_entry
->state
) == DDB_STATE_ONLINE
)
1049 qla4xxx_mark_device_missing(ha
, ddb_entry
);
1055 * qla4xxx_relogin_device - re-establish session
1056 * @ha: Pointer to host adapter structure.
1057 * @ddb_entry: Pointer to device database entry
1059 * This routine does a session relogin with the specified device.
1060 * The ddb entry must be assigned prior to making this call.
1062 int qla4xxx_relogin_device(struct scsi_qla_host
*ha
,
1063 struct ddb_entry
* ddb_entry
)
1065 uint16_t relogin_timer
;
1067 relogin_timer
= max(ddb_entry
->default_relogin_timeout
,
1068 (uint16_t)RELOGIN_TOV
);
1069 atomic_set(&ddb_entry
->relogin_timer
, relogin_timer
);
1071 DEBUG2(printk("scsi%ld: Relogin ddb [%d]. TOV=%d\n", ha
->host_no
,
1072 ddb_entry
->fw_ddb_index
, relogin_timer
));
1074 qla4xxx_set_ddb_entry(ha
, ddb_entry
->fw_ddb_index
, 0);
1079 static int qla4xxx_config_nvram(struct scsi_qla_host
*ha
)
1081 unsigned long flags
;
1082 union external_hw_config_reg extHwConfig
;
1084 DEBUG2(printk("scsi%ld: %s: Get EEProm parameters \n", ha
->host_no
,
1086 if (ql4xxx_lock_flash(ha
) != QLA_SUCCESS
)
1088 if (ql4xxx_lock_nvram(ha
) != QLA_SUCCESS
) {
1089 ql4xxx_unlock_flash(ha
);
1093 /* Get EEPRom Parameters from NVRAM and validate */
1094 ql4_printk(KERN_INFO
, ha
, "Configuring NVRAM ...\n");
1095 if (qla4xxx_is_nvram_configuration_valid(ha
) == QLA_SUCCESS
) {
1096 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1097 extHwConfig
.Asuint32_t
=
1098 rd_nvram_word(ha
, eeprom_ext_hw_conf_offset(ha
));
1099 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1101 ql4_printk(KERN_WARNING
, ha
,
1102 "scsi%ld: %s: EEProm checksum invalid. "
1103 "Please update your EEPROM\n", ha
->host_no
,
1106 /* Attempt to set defaults */
1108 extHwConfig
.Asuint32_t
= 0x1912;
1109 else if (is_qla4022(ha
) | is_qla4032(ha
))
1110 extHwConfig
.Asuint32_t
= 0x0023;
1114 DEBUG(printk("scsi%ld: %s: Setting extHwConfig to 0xFFFF%04x\n",
1115 ha
->host_no
, __func__
, extHwConfig
.Asuint32_t
));
1117 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1118 writel((0xFFFF << 16) | extHwConfig
.Asuint32_t
, isp_ext_hw_conf(ha
));
1119 readl(isp_ext_hw_conf(ha
));
1120 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1122 ql4xxx_unlock_nvram(ha
);
1123 ql4xxx_unlock_flash(ha
);
1129 * qla4_8xxx_pci_config() - Setup ISP82xx PCI configuration registers.
1132 void qla4_8xxx_pci_config(struct scsi_qla_host
*ha
)
1134 pci_set_master(ha
->pdev
);
1137 void qla4xxx_pci_config(struct scsi_qla_host
*ha
)
1142 ql4_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
1144 pci_set_master(ha
->pdev
);
1145 status
= pci_set_mwi(ha
->pdev
);
1147 * We want to respect framework's setting of PCI configuration space
1148 * command register and also want to make sure that all bits of
1149 * interest to us are properly set in command register.
1151 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
1152 w
|= PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
;
1153 w
&= ~PCI_COMMAND_INTX_DISABLE
;
1154 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
1157 static int qla4xxx_start_firmware_from_flash(struct scsi_qla_host
*ha
)
1159 int status
= QLA_ERROR
;
1160 unsigned long max_wait_time
;
1161 unsigned long flags
;
1162 uint32_t mbox_status
;
1164 ql4_printk(KERN_INFO
, ha
, "Starting firmware ...\n");
1166 DEBUG(printk("scsi%d: %s: Start firmware from flash ROM\n",
1167 ha
->host_no
, __func__
));
1169 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1170 writel(jiffies
, &ha
->reg
->mailbox
[7]);
1171 if (is_qla4022(ha
) | is_qla4032(ha
))
1172 writel(set_rmask(NVR_WRITE_ENABLE
),
1173 &ha
->reg
->u1
.isp4022
.nvram
);
1175 writel(2, &ha
->reg
->mailbox
[6]);
1176 readl(&ha
->reg
->mailbox
[6]);
1178 writel(set_rmask(CSR_BOOT_ENABLE
), &ha
->reg
->ctrl_status
);
1179 readl(&ha
->reg
->ctrl_status
);
1180 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1182 /* Wait for firmware to come UP. */
1183 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: Wait up to %d seconds for "
1184 "boot firmware to complete...\n",
1185 ha
->host_no
, __func__
, FIRMWARE_UP_TOV
));
1186 max_wait_time
= jiffies
+ (FIRMWARE_UP_TOV
* HZ
);
1188 uint32_t ctrl_status
;
1190 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1191 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
1192 mbox_status
= readw(&ha
->reg
->mailbox
[0]);
1193 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1195 if (ctrl_status
& set_rmask(CSR_SCSI_PROCESSOR_INTR
))
1197 if (mbox_status
== MBOX_STS_COMMAND_COMPLETE
)
1200 DEBUG2(printk(KERN_INFO
"scsi%ld: %s: Waiting for boot "
1201 "firmware to complete... ctrl_sts=0x%x\n",
1202 ha
->host_no
, __func__
, ctrl_status
));
1204 msleep_interruptible(250);
1205 } while (!time_after_eq(jiffies
, max_wait_time
));
1207 if (mbox_status
== MBOX_STS_COMMAND_COMPLETE
) {
1208 DEBUG(printk(KERN_INFO
"scsi%ld: %s: Firmware has started\n",
1209 ha
->host_no
, __func__
));
1211 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1212 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR
),
1213 &ha
->reg
->ctrl_status
);
1214 readl(&ha
->reg
->ctrl_status
);
1215 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1217 status
= QLA_SUCCESS
;
1219 printk(KERN_INFO
"scsi%ld: %s: Boot firmware failed "
1220 "- mbox status 0x%x\n", ha
->host_no
, __func__
,
1227 int ql4xxx_lock_drvr_wait(struct scsi_qla_host
*a
)
1229 #define QL4_LOCK_DRVR_WAIT 60
1230 #define QL4_LOCK_DRVR_SLEEP 1
1232 int drvr_wait
= QL4_LOCK_DRVR_WAIT
;
1234 if (ql4xxx_lock_drvr(a
) == 0) {
1235 ssleep(QL4_LOCK_DRVR_SLEEP
);
1237 DEBUG2(printk("scsi%ld: %s: Waiting for "
1238 "Global Init Semaphore(%d)...\n",
1240 __func__
, drvr_wait
));
1242 drvr_wait
-= QL4_LOCK_DRVR_SLEEP
;
1244 DEBUG2(printk("scsi%ld: %s: Global Init Semaphore "
1245 "acquired\n", a
->host_no
, __func__
));
1253 * qla4xxx_start_firmware - starts qla4xxx firmware
1254 * @ha: Pointer to host adapter structure.
1256 * This routine performs the necessary steps to start the firmware for
1257 * the QLA4010 adapter.
1259 int qla4xxx_start_firmware(struct scsi_qla_host
*ha
)
1261 unsigned long flags
= 0;
1262 uint32_t mbox_status
;
1263 int status
= QLA_ERROR
;
1265 int config_chip
= 0;
1267 if (is_qla4022(ha
) | is_qla4032(ha
))
1268 ql4xxx_set_mac_number(ha
);
1270 if (ql4xxx_lock_drvr_wait(ha
) != QLA_SUCCESS
)
1273 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1275 DEBUG2(printk("scsi%ld: %s: port_ctrl = 0x%08X\n", ha
->host_no
,
1276 __func__
, readw(isp_port_ctrl(ha
))));
1277 DEBUG(printk("scsi%ld: %s: port_status = 0x%08X\n", ha
->host_no
,
1278 __func__
, readw(isp_port_status(ha
))));
1280 /* Is Hardware already initialized? */
1281 if ((readw(isp_port_ctrl(ha
)) & 0x8000) != 0) {
1282 DEBUG(printk("scsi%ld: %s: Hardware has already been "
1283 "initialized\n", ha
->host_no
, __func__
));
1285 /* Receive firmware boot acknowledgement */
1286 mbox_status
= readw(&ha
->reg
->mailbox
[0]);
1288 DEBUG2(printk("scsi%ld: %s: H/W Config complete - mbox[0]= "
1289 "0x%x\n", ha
->host_no
, __func__
, mbox_status
));
1291 /* Is firmware already booted? */
1292 if (mbox_status
== 0) {
1293 /* F/W not running, must be config by net driver */
1297 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR
),
1298 &ha
->reg
->ctrl_status
);
1299 readl(&ha
->reg
->ctrl_status
);
1300 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1301 if (qla4xxx_get_firmware_state(ha
) == QLA_SUCCESS
) {
1302 DEBUG2(printk("scsi%ld: %s: Get firmware "
1303 "state -- state = 0x%x\n",
1305 __func__
, ha
->firmware_state
));
1306 /* F/W is running */
1307 if (ha
->firmware_state
&
1308 FW_STATE_CONFIG_WAIT
) {
1309 DEBUG2(printk("scsi%ld: %s: Firmware "
1310 "in known state -- "
1312 "boot, state = 0x%x\n",
1313 ha
->host_no
, __func__
,
1314 ha
->firmware_state
));
1319 DEBUG2(printk("scsi%ld: %s: Firmware in "
1320 "unknown state -- resetting,"
1322 "0x%x\n", ha
->host_no
, __func__
,
1323 ha
->firmware_state
));
1325 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1328 DEBUG(printk("scsi%ld: %s: H/W initialization hasn't been "
1329 "started - resetting\n", ha
->host_no
, __func__
));
1331 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1333 DEBUG(printk("scsi%ld: %s: Flags soft_rest=%d, config= %d\n ",
1334 ha
->host_no
, __func__
, soft_reset
, config_chip
));
1336 DEBUG(printk("scsi%ld: %s: Issue Soft Reset\n", ha
->host_no
,
1338 status
= qla4xxx_soft_reset(ha
); /* NOTE: acquires drvr
1339 * lock again, but ok */
1340 if (status
== QLA_ERROR
) {
1341 DEBUG(printk("scsi%d: %s: Soft Reset failed!\n",
1342 ha
->host_no
, __func__
));
1343 ql4xxx_unlock_drvr(ha
);
1348 /* Reset clears the semaphore, so acquire again */
1349 if (ql4xxx_lock_drvr_wait(ha
) != QLA_SUCCESS
)
1354 if ((status
= qla4xxx_config_nvram(ha
)) == QLA_SUCCESS
)
1355 status
= qla4xxx_start_firmware_from_flash(ha
);
1358 ql4xxx_unlock_drvr(ha
);
1359 if (status
== QLA_SUCCESS
) {
1360 if (test_and_clear_bit(AF_GET_CRASH_RECORD
, &ha
->flags
))
1361 qla4xxx_get_crash_record(ha
);
1363 DEBUG(printk("scsi%ld: %s: Firmware has NOT started\n",
1364 ha
->host_no
, __func__
));
1371 * qla4xxx_initialize_adapter - initiailizes hba
1372 * @ha: Pointer to host adapter structure.
1373 * @renew_ddb_list: Indicates what to do with the adapter's ddb list
1374 * after adapter recovery has completed.
1375 * 0=preserve ddb list, 1=destroy and rebuild ddb list
1377 * This routine parforms all of the steps necessary to initialize the adapter.
1380 int qla4xxx_initialize_adapter(struct scsi_qla_host
*ha
,
1381 uint8_t renew_ddb_list
)
1383 int status
= QLA_ERROR
;
1384 int8_t ip_address
[IP_ADDR_LEN
] = {0} ;
1386 ha
->eeprom_cmd_data
= 0;
1388 ql4_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
1389 ha
->isp_ops
->pci_config(ha
);
1391 ha
->isp_ops
->disable_intrs(ha
);
1393 /* Initialize the Host adapter request/response queues and firmware */
1394 if (ha
->isp_ops
->start_firmware(ha
) == QLA_ERROR
)
1397 if (qla4xxx_get_fw_version(ha
) == QLA_ERROR
)
1400 if (ha
->isp_ops
->get_sys_info(ha
) == QLA_ERROR
)
1403 if (qla4xxx_init_local_data(ha
) == QLA_ERROR
)
1406 status
= qla4xxx_init_firmware(ha
);
1407 if (status
== QLA_ERROR
)
1411 * FW is waiting to get an IP address from DHCP server: Skip building
1412 * the ddb_list and wait for DHCP lease acquired aen to come in
1413 * followed by 0x8014 aen" to trigger the tgt discovery process.
1415 if (ha
->firmware_state
& FW_STATE_CONFIGURING_IP
)
1416 goto exit_init_online
;
1418 /* Skip device discovery if ip and subnet is zero */
1419 if (memcmp(ha
->ip_address
, ip_address
, IP_ADDR_LEN
) == 0 ||
1420 memcmp(ha
->subnet_mask
, ip_address
, IP_ADDR_LEN
) == 0)
1421 goto exit_init_online
;
1423 if (renew_ddb_list
== PRESERVE_DDB_LIST
) {
1425 * We want to preserve lun states (i.e. suspended, etc.)
1426 * for recovery initiated by the driver. So just update
1427 * the device states for the existing ddb_list.
1429 qla4xxx_reinitialize_ddb_list(ha
);
1430 } else if (renew_ddb_list
== REBUILD_DDB_LIST
) {
1432 * We want to build the ddb_list from scratch during
1433 * driver initialization and recovery initiated by the
1434 * INT_HBA_RESET IOCTL.
1436 status
= qla4xxx_initialize_ddb_list(ha
);
1437 if (status
== QLA_ERROR
) {
1438 DEBUG2(printk("%s(%ld) Error occurred during build"
1439 "ddb list\n", __func__
, ha
->host_no
));
1444 if (!ha
->tot_ddbs
) {
1445 DEBUG2(printk("scsi%ld: Failed to initialize devices or none "
1446 "present in Firmware device database\n",
1451 set_bit(AF_ONLINE
, &ha
->flags
);
1453 DEBUG2(printk("scsi%ld: initialize adapter: %s\n", ha
->host_no
,
1454 status
== QLA_ERROR
? "FAILED" : "SUCCEDED"));
1459 * qla4xxx_add_device_dynamically - ddb addition due to an AEN
1460 * @ha: Pointer to host adapter structure.
1461 * @fw_ddb_index: Firmware's device database index
1463 * This routine processes adds a device as a result of an 8014h AEN.
1465 static void qla4xxx_add_device_dynamically(struct scsi_qla_host
*ha
,
1466 uint32_t fw_ddb_index
)
1468 struct ddb_entry
* ddb_entry
;
1471 /* First allocate a device structure */
1472 ddb_entry
= qla4xxx_get_ddb_entry(ha
, fw_ddb_index
, &new_tgt
);
1473 if (ddb_entry
== NULL
) {
1474 DEBUG2(printk(KERN_WARNING
1475 "scsi%ld: Unable to allocate memory to add "
1476 "fw_ddb_index %d\n", ha
->host_no
, fw_ddb_index
));
1480 if (!new_tgt
&& (ddb_entry
->fw_ddb_index
!= fw_ddb_index
)) {
1481 /* Target has been bound to a new fw_ddb_index */
1482 qla4xxx_free_ddb(ha
, ddb_entry
);
1483 ddb_entry
= qla4xxx_alloc_ddb(ha
, fw_ddb_index
);
1484 if (ddb_entry
== NULL
) {
1485 DEBUG2(printk(KERN_WARNING
1486 "scsi%ld: Unable to allocate memory"
1487 " to add fw_ddb_index %d\n",
1488 ha
->host_no
, fw_ddb_index
));
1492 if (qla4xxx_update_ddb_entry(ha
, ddb_entry
, fw_ddb_index
) ==
1494 ha
->fw_ddb_index_map
[fw_ddb_index
] =
1495 (struct ddb_entry
*)INVALID_ENTRY
;
1496 DEBUG2(printk(KERN_WARNING
1497 "scsi%ld: failed to add new device at index "
1498 "[%d]\n Unable to retrieve fw ddb entry\n",
1499 ha
->host_no
, fw_ddb_index
));
1500 qla4xxx_free_ddb(ha
, ddb_entry
);
1504 if (qla4xxx_add_sess(ddb_entry
)) {
1505 DEBUG2(printk(KERN_WARNING
1506 "scsi%ld: failed to add new device at index "
1507 "[%d]\n Unable to add connection and session\n",
1508 ha
->host_no
, fw_ddb_index
));
1509 qla4xxx_free_ddb(ha
, ddb_entry
);
1514 * qla4xxx_process_ddb_changed - process ddb state change
1515 * @ha - Pointer to host adapter structure.
1516 * @fw_ddb_index - Firmware's device database index
1517 * @state - Device state
1519 * This routine processes a Decive Database Changed AEN Event.
1521 int qla4xxx_process_ddb_changed(struct scsi_qla_host
*ha
, uint32_t fw_ddb_index
,
1522 uint32_t state
, uint32_t conn_err
)
1524 struct ddb_entry
* ddb_entry
;
1525 uint32_t old_fw_ddb_device_state
;
1527 /* check for out of range index */
1528 if (fw_ddb_index
>= MAX_DDB_ENTRIES
)
1531 /* Get the corresponging ddb entry */
1532 ddb_entry
= qla4xxx_lookup_ddb_by_fw_index(ha
, fw_ddb_index
);
1533 /* Device does not currently exist in our database. */
1534 if (ddb_entry
== NULL
) {
1535 if (state
== DDB_DS_SESSION_ACTIVE
)
1536 qla4xxx_add_device_dynamically(ha
, fw_ddb_index
);
1540 /* Device already exists in our database. */
1541 old_fw_ddb_device_state
= ddb_entry
->fw_ddb_device_state
;
1542 DEBUG2(printk("scsi%ld: %s DDB - old state= 0x%x, new state=0x%x for "
1543 "index [%d]\n", ha
->host_no
, __func__
,
1544 ddb_entry
->fw_ddb_device_state
, state
, fw_ddb_index
));
1545 if (old_fw_ddb_device_state
== state
&&
1546 state
== DDB_DS_SESSION_ACTIVE
) {
1547 if (atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
) {
1548 atomic_set(&ddb_entry
->state
, DDB_STATE_ONLINE
);
1549 iscsi_unblock_session(ddb_entry
->sess
);
1554 ddb_entry
->fw_ddb_device_state
= state
;
1555 /* Device is back online. */
1556 if (ddb_entry
->fw_ddb_device_state
== DDB_DS_SESSION_ACTIVE
) {
1557 atomic_set(&ddb_entry
->state
, DDB_STATE_ONLINE
);
1558 atomic_set(&ddb_entry
->relogin_retry_count
, 0);
1559 atomic_set(&ddb_entry
->relogin_timer
, 0);
1560 clear_bit(DF_RELOGIN
, &ddb_entry
->flags
);
1561 clear_bit(DF_NO_RELOGIN
, &ddb_entry
->flags
);
1562 iscsi_unblock_session(ddb_entry
->sess
);
1563 iscsi_session_event(ddb_entry
->sess
,
1564 ISCSI_KEVENT_CREATE_SESSION
);
1566 * Change the lun state to READY in case the lun TIMEOUT before
1567 * the device came back.
1570 /* Device went away, mark device missing */
1571 if (atomic_read(&ddb_entry
->state
) == DDB_STATE_ONLINE
) {
1572 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s mark missing "
1573 "ddb_entry 0x%p sess 0x%p conn 0x%p\n",
1574 __func__
, ddb_entry
,
1575 ddb_entry
->sess
, ddb_entry
->conn
));
1576 qla4xxx_mark_device_missing(ha
, ddb_entry
);
1580 * Relogin if device state changed to a not active state.
1581 * However, do not relogin if a RELOGIN is in process, or
1582 * we are not allowed to relogin to this DDB.
1584 if (ddb_entry
->fw_ddb_device_state
== DDB_DS_SESSION_FAILED
&&
1585 !test_bit(DF_RELOGIN
, &ddb_entry
->flags
) &&
1586 !test_bit(DF_NO_RELOGIN
, &ddb_entry
->flags
) &&
1587 qla4_is_relogin_allowed(ha
, conn_err
)) {
1589 * This triggers a relogin. After the relogin_timer
1590 * expires, the relogin gets scheduled. We must wait a
1591 * minimum amount of time since receiving an 0x8014 AEN
1592 * with failed device_state or a logout response before
1593 * we can issue another relogin.
1595 /* Firmware pads this timeout: (time2wait +1).
1596 * Driver retry to login should be longer than F/W.
1597 * Otherwise F/W will fail
1598 * set_ddb() mbx cmd with 0x4005 since it still
1599 * counting down its time2wait.
1601 atomic_set(&ddb_entry
->relogin_timer
, 0);
1602 atomic_set(&ddb_entry
->retry_relogin_timer
,
1603 ddb_entry
->default_time2wait
+ 4);
1604 DEBUG(printk("scsi%ld: %s: ddb[%d] "
1605 "initiate relogin after %d seconds\n",
1606 ha
->host_no
, __func__
,
1607 ddb_entry
->fw_ddb_index
,
1608 ddb_entry
->default_time2wait
+ 4));
1610 DEBUG(printk("scsi%ld: %s: ddb[%d] "
1611 "relogin not initiated, state = %d, "
1612 "ddb_entry->flags = 0x%lx\n",
1613 ha
->host_no
, __func__
,
1614 ddb_entry
->fw_ddb_index
,
1615 ddb_entry
->fw_ddb_device_state
,