2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2006 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
11 #include "ql4_inline.h"
15 * qla4xxx_mailbox_command - issues mailbox commands
16 * @ha: Pointer to host adapter structure.
17 * @inCount: number of mailbox registers to load.
18 * @outCount: number of mailbox registers to return.
19 * @mbx_cmd: data pointer for mailbox in registers.
20 * @mbx_sts: data pointer for mailbox out registers.
22 * This routine isssue mailbox commands and waits for completion.
23 * If outCount is 0, this routine completes successfully WITHOUT waiting
24 * for the mailbox command to complete.
26 int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
27 uint8_t outCount, uint32_t *mbx_cmd,
30 int status = QLA_ERROR;
34 unsigned long flags = 0;
36 /* Make sure that pointers are valid */
37 if (!mbx_cmd || !mbx_sts) {
38 DEBUG2(printk("scsi%ld: %s: Invalid mbx_cmd or mbx_sts "
39 "pointer\n", ha->host_no, __func__));
44 test_bit(AF_FW_RECOVERY, &ha->flags)) {
45 DEBUG2(ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: prematurely "
46 "completing mbx cmd as firmware recovery detected\n",
47 ha->host_no, __func__));
51 if ((is_aer_supported(ha)) &&
52 (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))) {
53 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Perm failure on EEH, "
54 "timeout MBX Exiting.\n", ha->host_no, __func__));
58 /* Mailbox code active */
59 wait_count = MBOX_TOV * 100;
61 while (wait_count--) {
62 mutex_lock(&ha->mbox_sem);
63 if (!test_bit(AF_MBOX_COMMAND, &ha->flags)) {
64 set_bit(AF_MBOX_COMMAND, &ha->flags);
65 mutex_unlock(&ha->mbox_sem);
68 mutex_unlock(&ha->mbox_sem);
70 DEBUG2(printk("scsi%ld: %s: mbox_sem failed\n",
71 ha->host_no, __func__));
77 /* To prevent overwriting mailbox registers for a command that has
78 * not yet been serviced, check to see if an active command
79 * (AEN, IOCB, etc.) is interrupting, then service it.
80 * -----------------------------------------------------------------
82 spin_lock_irqsave(&ha->hardware_lock, flags);
85 intr_status = readl(&ha->qla4_8xxx_reg->host_int);
86 if (intr_status & ISRX_82XX_RISC_INT) {
87 /* Service existing interrupt */
88 DEBUG2(printk("scsi%ld: %s: "
89 "servicing existing interrupt\n",
90 ha->host_no, __func__));
91 intr_status = readl(&ha->qla4_8xxx_reg->host_status);
92 ha->isp_ops->interrupt_service_routine(ha, intr_status);
93 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
94 if (test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
95 test_bit(AF_INTx_ENABLED, &ha->flags))
97 ha->nx_legacy_intr.tgt_mask_reg,
101 intr_status = readl(&ha->reg->ctrl_status);
102 if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
103 /* Service existing interrupt */
104 ha->isp_ops->interrupt_service_routine(ha, intr_status);
105 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
109 ha->mbox_status_count = outCount;
110 for (i = 0; i < outCount; i++)
111 ha->mbox_status[i] = 0;
113 if (is_qla8022(ha)) {
114 /* Load all mailbox registers, except mailbox 0. */
116 printk("scsi%ld: %s: Cmd ", ha->host_no, __func__);
117 for (i = 0; i < inCount; i++)
118 printk("mb%d=%04x ", i, mbx_cmd[i]);
121 for (i = 1; i < inCount; i++)
122 writel(mbx_cmd[i], &ha->qla4_8xxx_reg->mailbox_in[i]);
123 writel(mbx_cmd[0], &ha->qla4_8xxx_reg->mailbox_in[0]);
124 readl(&ha->qla4_8xxx_reg->mailbox_in[0]);
125 writel(HINT_MBX_INT_PENDING, &ha->qla4_8xxx_reg->hint);
127 /* Load all mailbox registers, except mailbox 0. */
128 for (i = 1; i < inCount; i++)
129 writel(mbx_cmd[i], &ha->reg->mailbox[i]);
131 /* Wakeup firmware */
132 writel(mbx_cmd[0], &ha->reg->mailbox[0]);
133 readl(&ha->reg->mailbox[0]);
134 writel(set_rmask(CSR_INTR_RISC), &ha->reg->ctrl_status);
135 readl(&ha->reg->ctrl_status);
138 spin_unlock_irqrestore(&ha->hardware_lock, flags);
140 /* Wait for completion */
143 * If we don't want status, don't wait for the mailbox command to
144 * complete. For example, MBOX_CMD_RESET_FW doesn't return status,
145 * you must poll the inbound Interrupt Mask for completion.
148 status = QLA_SUCCESS;
153 * Wait for completion: Poll or completion queue
155 if (test_bit(AF_IRQ_ATTACHED, &ha->flags) &&
156 test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
157 test_bit(AF_ONLINE, &ha->flags) &&
158 !test_bit(AF_HBA_GOING_AWAY, &ha->flags)) {
159 /* Do not poll for completion. Use completion queue */
160 set_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
161 wait_for_completion_timeout(&ha->mbx_intr_comp, MBOX_TOV * HZ);
162 clear_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
164 /* Poll for command to complete */
165 wait_count = jiffies + MBOX_TOV * HZ;
166 while (test_bit(AF_MBOX_COMMAND_DONE, &ha->flags) == 0) {
167 if (time_after_eq(jiffies, wait_count))
171 * Service the interrupt.
172 * The ISR will save the mailbox status registers
173 * to a temporary storage location in the adapter
177 spin_lock_irqsave(&ha->hardware_lock, flags);
178 if (is_qla8022(ha)) {
180 readl(&ha->qla4_8xxx_reg->host_int);
181 if (intr_status & ISRX_82XX_RISC_INT) {
182 ha->mbox_status_count = outCount;
184 readl(&ha->qla4_8xxx_reg->host_status);
185 ha->isp_ops->interrupt_service_routine(
187 if (test_bit(AF_INTERRUPTS_ON,
189 test_bit(AF_INTx_ENABLED,
192 ha->nx_legacy_intr.tgt_mask_reg,
196 intr_status = readl(&ha->reg->ctrl_status);
197 if (intr_status & INTR_PENDING) {
199 * Service the interrupt.
200 * The ISR will save the mailbox status
201 * registers to a temporary storage
202 * location in the adapter structure.
204 ha->mbox_status_count = outCount;
205 ha->isp_ops->interrupt_service_routine(
209 spin_unlock_irqrestore(&ha->hardware_lock, flags);
214 /* Check for mailbox timeout. */
215 if (!test_bit(AF_MBOX_COMMAND_DONE, &ha->flags)) {
216 if (is_qla8022(ha) &&
217 test_bit(AF_FW_RECOVERY, &ha->flags)) {
218 DEBUG2(ql4_printk(KERN_INFO, ha,
219 "scsi%ld: %s: prematurely completing mbx cmd as "
220 "firmware recovery detected\n",
221 ha->host_no, __func__));
224 DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
225 " Scheduling Adapter Reset\n", ha->host_no,
227 ha->mailbox_timeout_count++;
229 set_bit(DPC_RESET_HA, &ha->dpc_flags);
234 * Copy the mailbox out registers to the caller's mailbox in/out
237 spin_lock_irqsave(&ha->hardware_lock, flags);
238 for (i = 0; i < outCount; i++)
239 mbx_sts[i] = ha->mbox_status[i];
241 /* Set return status and error flags (if applicable). */
242 switch (ha->mbox_status[0]) {
243 case MBOX_STS_COMMAND_COMPLETE:
244 status = QLA_SUCCESS;
247 case MBOX_STS_INTERMEDIATE_COMPLETION:
248 status = QLA_SUCCESS;
252 DEBUG2( printk("scsi%ld: %s: Cmd = %08X, ISP BUSY\n",
253 ha->host_no, __func__, mbx_cmd[0]));
254 ha->mailbox_timeout_count++;
258 DEBUG2(printk("scsi%ld: %s: **** FAILED, cmd = %08X, "
259 "sts = %08X ****\n", ha->host_no, __func__,
260 mbx_cmd[0], mbx_sts[0]));
263 spin_unlock_irqrestore(&ha->hardware_lock, flags);
266 mutex_lock(&ha->mbox_sem);
267 clear_bit(AF_MBOX_COMMAND, &ha->flags);
268 mutex_unlock(&ha->mbox_sem);
269 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
274 void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha)
276 set_bit(AF_FW_RECOVERY, &ha->flags);
277 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: set FW RECOVERY!\n",
278 ha->host_no, __func__);
280 if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
281 if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags)) {
282 complete(&ha->mbx_intr_comp);
283 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
284 "recovery, doing premature completion of "
285 "mbx cmd\n", ha->host_no, __func__);
288 set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
289 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
290 "recovery, doing premature completion of "
291 "polling mbx cmd\n", ha->host_no, __func__);
297 qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
298 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
300 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
301 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
304 qla4_8xxx_wr_32(ha, ha->nx_db_wr_ptr, 0);
306 mbox_cmd[0] = MBOX_CMD_INITIALIZE_FIRMWARE;
308 mbox_cmd[2] = LSDW(init_fw_cb_dma);
309 mbox_cmd[3] = MSDW(init_fw_cb_dma);
310 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
311 mbox_cmd[5] = (IFCB_VER_MAX << 8) | IFCB_VER_MIN;
313 if (qla4xxx_mailbox_command(ha, 6, 6, mbox_cmd, mbox_sts) !=
315 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
316 "MBOX_CMD_INITIALIZE_FIRMWARE"
317 " failed w/ status %04X\n",
318 ha->host_no, __func__, mbox_sts[0]));
325 qla4xxx_get_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
326 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
328 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
329 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
330 mbox_cmd[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK;
331 mbox_cmd[2] = LSDW(init_fw_cb_dma);
332 mbox_cmd[3] = MSDW(init_fw_cb_dma);
333 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
335 if (qla4xxx_mailbox_command(ha, 5, 5, mbox_cmd, mbox_sts) !=
337 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
338 "MBOX_CMD_GET_INIT_FW_CTRL_BLOCK"
339 " failed w/ status %04X\n",
340 ha->host_no, __func__, mbox_sts[0]));
347 qla4xxx_update_local_ip(struct scsi_qla_host *ha,
348 struct addr_ctrl_blk *init_fw_cb)
350 /* Save IPv4 Address Info */
351 memcpy(ha->ip_address, init_fw_cb->ipv4_addr,
352 min(sizeof(ha->ip_address), sizeof(init_fw_cb->ipv4_addr)));
353 memcpy(ha->subnet_mask, init_fw_cb->ipv4_subnet,
354 min(sizeof(ha->subnet_mask), sizeof(init_fw_cb->ipv4_subnet)));
355 memcpy(ha->gateway, init_fw_cb->ipv4_gw_addr,
356 min(sizeof(ha->gateway), sizeof(init_fw_cb->ipv4_gw_addr)));
358 if (is_ipv6_enabled(ha)) {
359 /* Save IPv6 Address */
360 ha->ipv6_link_local_state = init_fw_cb->ipv6_lnk_lcl_addr_state;
361 ha->ipv6_addr0_state = init_fw_cb->ipv6_addr0_state;
362 ha->ipv6_addr1_state = init_fw_cb->ipv6_addr1_state;
363 ha->ipv6_default_router_state = init_fw_cb->ipv6_dflt_rtr_state;
364 ha->ipv6_link_local_addr.in6_u.u6_addr8[0] = 0xFE;
365 ha->ipv6_link_local_addr.in6_u.u6_addr8[1] = 0x80;
367 memcpy(&ha->ipv6_link_local_addr.in6_u.u6_addr8[8],
368 init_fw_cb->ipv6_if_id,
369 min(sizeof(ha->ipv6_link_local_addr)/2,
370 sizeof(init_fw_cb->ipv6_if_id)));
371 memcpy(&ha->ipv6_addr0, init_fw_cb->ipv6_addr0,
372 min(sizeof(ha->ipv6_addr0),
373 sizeof(init_fw_cb->ipv6_addr0)));
374 memcpy(&ha->ipv6_addr1, init_fw_cb->ipv6_addr1,
375 min(sizeof(ha->ipv6_addr1),
376 sizeof(init_fw_cb->ipv6_addr1)));
377 memcpy(&ha->ipv6_default_router_addr,
378 init_fw_cb->ipv6_dflt_rtr_addr,
379 min(sizeof(ha->ipv6_default_router_addr),
380 sizeof(init_fw_cb->ipv6_dflt_rtr_addr)));
385 qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
388 struct addr_ctrl_blk *init_fw_cb,
389 dma_addr_t init_fw_cb_dma)
391 if (qla4xxx_get_ifcb(ha, mbox_cmd, mbox_sts, init_fw_cb_dma)
393 DEBUG2(printk(KERN_WARNING
394 "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
395 ha->host_no, __func__));
399 DEBUG2(qla4xxx_dump_buffer(init_fw_cb, sizeof(struct addr_ctrl_blk)));
401 /* Save some info in adapter structure. */
402 ha->acb_version = init_fw_cb->acb_version;
403 ha->firmware_options = le16_to_cpu(init_fw_cb->fw_options);
404 ha->tcp_options = le16_to_cpu(init_fw_cb->ipv4_tcp_opts);
405 ha->ipv4_options = le16_to_cpu(init_fw_cb->ipv4_ip_opts);
406 ha->ipv4_addr_state = le16_to_cpu(init_fw_cb->ipv4_addr_state);
407 ha->heartbeat_interval = init_fw_cb->hb_interval;
408 memcpy(ha->name_string, init_fw_cb->iscsi_name,
409 min(sizeof(ha->name_string),
410 sizeof(init_fw_cb->iscsi_name)));
411 /*memcpy(ha->alias, init_fw_cb->Alias,
412 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
414 /* Save Command Line Paramater info */
415 ha->discovery_wait = ql4xdiscoverywait;
417 if (ha->acb_version == ACB_SUPPORTED) {
418 ha->ipv6_options = init_fw_cb->ipv6_opts;
419 ha->ipv6_addl_options = init_fw_cb->ipv6_addtl_opts;
421 qla4xxx_update_local_ip(ha, init_fw_cb);
427 * qla4xxx_initialize_fw_cb - initializes firmware control block.
428 * @ha: Pointer to host adapter structure.
430 int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
432 struct addr_ctrl_blk *init_fw_cb;
433 dma_addr_t init_fw_cb_dma;
434 uint32_t mbox_cmd[MBOX_REG_COUNT];
435 uint32_t mbox_sts[MBOX_REG_COUNT];
436 int status = QLA_ERROR;
438 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
439 sizeof(struct addr_ctrl_blk),
440 &init_fw_cb_dma, GFP_KERNEL);
441 if (init_fw_cb == NULL) {
442 DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
443 ha->host_no, __func__));
444 goto exit_init_fw_cb_no_free;
446 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
448 /* Get Initialize Firmware Control Block. */
449 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
450 memset(&mbox_sts, 0, sizeof(mbox_sts));
452 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
454 dma_free_coherent(&ha->pdev->dev,
455 sizeof(struct addr_ctrl_blk),
456 init_fw_cb, init_fw_cb_dma);
457 goto exit_init_fw_cb;
460 /* Initialize request and response queues. */
461 qla4xxx_init_rings(ha);
463 /* Fill in the request and response queue information. */
464 init_fw_cb->rqq_consumer_idx = cpu_to_le16(ha->request_out);
465 init_fw_cb->compq_producer_idx = cpu_to_le16(ha->response_in);
466 init_fw_cb->rqq_len = __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH);
467 init_fw_cb->compq_len = __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH);
468 init_fw_cb->rqq_addr_lo = cpu_to_le32(LSDW(ha->request_dma));
469 init_fw_cb->rqq_addr_hi = cpu_to_le32(MSDW(ha->request_dma));
470 init_fw_cb->compq_addr_lo = cpu_to_le32(LSDW(ha->response_dma));
471 init_fw_cb->compq_addr_hi = cpu_to_le32(MSDW(ha->response_dma));
472 init_fw_cb->shdwreg_addr_lo = cpu_to_le32(LSDW(ha->shadow_regs_dma));
473 init_fw_cb->shdwreg_addr_hi = cpu_to_le32(MSDW(ha->shadow_regs_dma));
475 /* Set up required options. */
476 init_fw_cb->fw_options |=
477 __constant_cpu_to_le16(FWOPT_SESSION_MODE |
478 FWOPT_INITIATOR_MODE);
481 init_fw_cb->fw_options |=
482 __constant_cpu_to_le16(FWOPT_ENABLE_CRBDB);
484 init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
486 if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
488 DEBUG2(printk(KERN_WARNING
489 "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
490 ha->host_no, __func__));
491 goto exit_init_fw_cb;
494 if (qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0],
495 init_fw_cb, init_fw_cb_dma) != QLA_SUCCESS) {
496 DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
497 ha->host_no, __func__));
498 goto exit_init_fw_cb;
500 status = QLA_SUCCESS;
503 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
504 init_fw_cb, init_fw_cb_dma);
505 exit_init_fw_cb_no_free:
510 * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
511 * @ha: Pointer to host adapter structure.
513 int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host * ha)
515 struct addr_ctrl_blk *init_fw_cb;
516 dma_addr_t init_fw_cb_dma;
517 uint32_t mbox_cmd[MBOX_REG_COUNT];
518 uint32_t mbox_sts[MBOX_REG_COUNT];
520 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
521 sizeof(struct addr_ctrl_blk),
522 &init_fw_cb_dma, GFP_KERNEL);
523 if (init_fw_cb == NULL) {
524 printk("scsi%ld: %s: Unable to alloc init_cb\n", ha->host_no,
529 /* Get Initialize Firmware Control Block. */
530 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
531 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
533 DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
534 ha->host_no, __func__));
535 dma_free_coherent(&ha->pdev->dev,
536 sizeof(struct addr_ctrl_blk),
537 init_fw_cb, init_fw_cb_dma);
541 /* Save IP Address. */
542 qla4xxx_update_local_ip(ha, init_fw_cb);
543 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
544 init_fw_cb, init_fw_cb_dma);
550 * qla4xxx_get_firmware_state - gets firmware state of HBA
551 * @ha: Pointer to host adapter structure.
553 int qla4xxx_get_firmware_state(struct scsi_qla_host * ha)
555 uint32_t mbox_cmd[MBOX_REG_COUNT];
556 uint32_t mbox_sts[MBOX_REG_COUNT];
558 /* Get firmware version */
559 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
560 memset(&mbox_sts, 0, sizeof(mbox_sts));
562 mbox_cmd[0] = MBOX_CMD_GET_FW_STATE;
564 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 4, &mbox_cmd[0], &mbox_sts[0]) !=
566 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
567 "status %04X\n", ha->host_no, __func__,
571 ha->firmware_state = mbox_sts[1];
572 ha->board_id = mbox_sts[2];
573 ha->addl_fw_state = mbox_sts[3];
574 DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
575 ha->host_no, __func__, ha->firmware_state);)
581 * qla4xxx_get_firmware_status - retrieves firmware status
582 * @ha: Pointer to host adapter structure.
584 int qla4xxx_get_firmware_status(struct scsi_qla_host * ha)
586 uint32_t mbox_cmd[MBOX_REG_COUNT];
587 uint32_t mbox_sts[MBOX_REG_COUNT];
589 /* Get firmware version */
590 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
591 memset(&mbox_sts, 0, sizeof(mbox_sts));
593 mbox_cmd[0] = MBOX_CMD_GET_FW_STATUS;
595 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
597 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
598 "status %04X\n", ha->host_no, __func__,
603 ql4_printk(KERN_INFO, ha, "%ld firmare IOCBs available (%d).\n",
604 ha->host_no, mbox_sts[2]);
610 * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
611 * @ha: Pointer to host adapter structure.
612 * @fw_ddb_index: Firmware's device database index
613 * @fw_ddb_entry: Pointer to firmware's device database entry structure
614 * @num_valid_ddb_entries: Pointer to number of valid ddb entries
615 * @next_ddb_index: Pointer to next valid device database index
616 * @fw_ddb_device_state: Pointer to device state
618 int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
619 uint16_t fw_ddb_index,
620 struct dev_db_entry *fw_ddb_entry,
621 dma_addr_t fw_ddb_entry_dma,
622 uint32_t *num_valid_ddb_entries,
623 uint32_t *next_ddb_index,
624 uint32_t *fw_ddb_device_state,
625 uint32_t *conn_err_detail,
626 uint16_t *tcp_source_port_num,
627 uint16_t *connection_id)
629 int status = QLA_ERROR;
631 uint32_t mbox_cmd[MBOX_REG_COUNT];
632 uint32_t mbox_sts[MBOX_REG_COUNT];
634 /* Make sure the device index is valid */
635 if (fw_ddb_index >= MAX_DDB_ENTRIES) {
636 DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
637 ha->host_no, __func__, fw_ddb_index));
640 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
641 memset(&mbox_sts, 0, sizeof(mbox_sts));
643 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY;
644 mbox_cmd[1] = (uint32_t) fw_ddb_index;
645 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
646 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
647 mbox_cmd[4] = sizeof(struct dev_db_entry);
649 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 7, &mbox_cmd[0], &mbox_sts[0]) ==
651 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
652 " with status 0x%04X\n", ha->host_no, __func__,
656 if (fw_ddb_index != mbox_sts[1]) {
657 DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
658 ha->host_no, __func__, fw_ddb_index,
663 options = le16_to_cpu(fw_ddb_entry->options);
664 if (options & DDB_OPT_IPV6_DEVICE) {
665 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
666 "Next %d State %04x ConnErr %08x %pI6 "
667 ":%04d \"%s\"\n", __func__, fw_ddb_index,
668 mbox_sts[0], mbox_sts[2], mbox_sts[3],
669 mbox_sts[4], mbox_sts[5],
670 fw_ddb_entry->ip_addr,
671 le16_to_cpu(fw_ddb_entry->port),
672 fw_ddb_entry->iscsi_name);
674 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
675 "Next %d State %04x ConnErr %08x %pI4 "
676 ":%04d \"%s\"\n", __func__, fw_ddb_index,
677 mbox_sts[0], mbox_sts[2], mbox_sts[3],
678 mbox_sts[4], mbox_sts[5],
679 fw_ddb_entry->ip_addr,
680 le16_to_cpu(fw_ddb_entry->port),
681 fw_ddb_entry->iscsi_name);
684 if (num_valid_ddb_entries)
685 *num_valid_ddb_entries = mbox_sts[2];
687 *next_ddb_index = mbox_sts[3];
688 if (fw_ddb_device_state)
689 *fw_ddb_device_state = mbox_sts[4];
692 * RA: This mailbox has been changed to pass connection error and
693 * details. Its true for ISP4010 as per Version E - Not sure when it
694 * was changed. Get the time2wait from the fw_dd_entry field :
695 * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
699 *conn_err_detail = mbox_sts[5];
700 if (tcp_source_port_num)
701 *tcp_source_port_num = (uint16_t) (mbox_sts[6] >> 16);
703 *connection_id = (uint16_t) mbox_sts[6] & 0x00FF;
704 status = QLA_SUCCESS;
711 * qla4xxx_set_fwddb_entry - sets a ddb entry.
712 * @ha: Pointer to host adapter structure.
713 * @fw_ddb_index: Firmware's device database index
714 * @fw_ddb_entry: Pointer to firmware's ddb entry structure, or NULL.
716 * This routine initializes or updates the adapter's device database
717 * entry for the specified device. It also triggers a login for the
718 * specified device. Therefore, it may also be used as a secondary
719 * login routine when a NULL pointer is specified for the fw_ddb_entry.
721 int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
722 dma_addr_t fw_ddb_entry_dma)
724 uint32_t mbox_cmd[MBOX_REG_COUNT];
725 uint32_t mbox_sts[MBOX_REG_COUNT];
728 /* Do not wait for completion. The firmware will send us an
729 * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
731 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
732 memset(&mbox_sts, 0, sizeof(mbox_sts));
734 mbox_cmd[0] = MBOX_CMD_SET_DATABASE_ENTRY;
735 mbox_cmd[1] = (uint32_t) fw_ddb_index;
736 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
737 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
738 mbox_cmd[4] = sizeof(struct dev_db_entry);
740 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
742 DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
743 ha->host_no, __func__, status, mbox_sts[0], mbox_sts[4]);)
749 * qla4xxx_get_crash_record - retrieves crash record.
750 * @ha: Pointer to host adapter structure.
752 * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
754 void qla4xxx_get_crash_record(struct scsi_qla_host * ha)
756 uint32_t mbox_cmd[MBOX_REG_COUNT];
757 uint32_t mbox_sts[MBOX_REG_COUNT];
758 struct crash_record *crash_record = NULL;
759 dma_addr_t crash_record_dma = 0;
760 uint32_t crash_record_size = 0;
762 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
763 memset(&mbox_sts, 0, sizeof(mbox_cmd));
765 /* Get size of crash record. */
766 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
768 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
770 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
771 ha->host_no, __func__));
772 goto exit_get_crash_record;
774 crash_record_size = mbox_sts[4];
775 if (crash_record_size == 0) {
776 DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
777 ha->host_no, __func__));
778 goto exit_get_crash_record;
781 /* Alloc Memory for Crash Record. */
782 crash_record = dma_alloc_coherent(&ha->pdev->dev, crash_record_size,
783 &crash_record_dma, GFP_KERNEL);
784 if (crash_record == NULL)
785 goto exit_get_crash_record;
787 /* Get Crash Record. */
788 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
789 memset(&mbox_sts, 0, sizeof(mbox_cmd));
791 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
792 mbox_cmd[2] = LSDW(crash_record_dma);
793 mbox_cmd[3] = MSDW(crash_record_dma);
794 mbox_cmd[4] = crash_record_size;
796 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
798 goto exit_get_crash_record;
800 /* Dump Crash Record. */
802 exit_get_crash_record:
804 dma_free_coherent(&ha->pdev->dev, crash_record_size,
805 crash_record, crash_record_dma);
809 * qla4xxx_get_conn_event_log - retrieves connection event log
810 * @ha: Pointer to host adapter structure.
812 void qla4xxx_get_conn_event_log(struct scsi_qla_host * ha)
814 uint32_t mbox_cmd[MBOX_REG_COUNT];
815 uint32_t mbox_sts[MBOX_REG_COUNT];
816 struct conn_event_log_entry *event_log = NULL;
817 dma_addr_t event_log_dma = 0;
818 uint32_t event_log_size = 0;
819 uint32_t num_valid_entries;
820 uint32_t oldest_entry = 0;
821 uint32_t max_event_log_entries;
825 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
826 memset(&mbox_sts, 0, sizeof(mbox_cmd));
828 /* Get size of crash record. */
829 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
831 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
833 goto exit_get_event_log;
835 event_log_size = mbox_sts[4];
836 if (event_log_size == 0)
837 goto exit_get_event_log;
839 /* Alloc Memory for Crash Record. */
840 event_log = dma_alloc_coherent(&ha->pdev->dev, event_log_size,
841 &event_log_dma, GFP_KERNEL);
842 if (event_log == NULL)
843 goto exit_get_event_log;
845 /* Get Crash Record. */
846 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
847 memset(&mbox_sts, 0, sizeof(mbox_cmd));
849 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
850 mbox_cmd[2] = LSDW(event_log_dma);
851 mbox_cmd[3] = MSDW(event_log_dma);
853 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
855 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
856 "log!\n", ha->host_no, __func__));
857 goto exit_get_event_log;
860 /* Dump Event Log. */
861 num_valid_entries = mbox_sts[1];
863 max_event_log_entries = event_log_size /
864 sizeof(struct conn_event_log_entry);
866 if (num_valid_entries > max_event_log_entries)
867 oldest_entry = num_valid_entries % max_event_log_entries;
869 DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
870 ha->host_no, num_valid_entries));
872 if (ql4xextended_error_logging == 3) {
873 if (oldest_entry == 0) {
874 /* Circular Buffer has not wrapped around */
875 for (i=0; i < num_valid_entries; i++) {
876 qla4xxx_dump_buffer((uint8_t *)event_log+
877 (i*sizeof(*event_log)),
882 /* Circular Buffer has wrapped around -
883 * display accordingly*/
884 for (i=oldest_entry; i < max_event_log_entries; i++) {
885 qla4xxx_dump_buffer((uint8_t *)event_log+
886 (i*sizeof(*event_log)),
889 for (i=0; i < oldest_entry; i++) {
890 qla4xxx_dump_buffer((uint8_t *)event_log+
891 (i*sizeof(*event_log)),
899 dma_free_coherent(&ha->pdev->dev, event_log_size, event_log,
904 * qla4xxx_abort_task - issues Abort Task
905 * @ha: Pointer to host adapter structure.
906 * @srb: Pointer to srb entry
908 * This routine performs a LUN RESET on the specified target/lun.
909 * The caller must ensure that the ddb_entry and lun_entry pointers
910 * are valid before calling this routine.
912 int qla4xxx_abort_task(struct scsi_qla_host *ha, struct srb *srb)
914 uint32_t mbox_cmd[MBOX_REG_COUNT];
915 uint32_t mbox_sts[MBOX_REG_COUNT];
916 struct scsi_cmnd *cmd = srb->cmd;
917 int status = QLA_SUCCESS;
918 unsigned long flags = 0;
922 * Send abort task command to ISP, so that the ISP will return
923 * request with ABORT status
925 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
926 memset(&mbox_sts, 0, sizeof(mbox_sts));
928 spin_lock_irqsave(&ha->hardware_lock, flags);
929 index = (unsigned long)(unsigned char *)cmd->host_scribble;
930 spin_unlock_irqrestore(&ha->hardware_lock, flags);
932 /* Firmware already posted completion on response queue */
933 if (index == MAX_SRBS)
936 mbox_cmd[0] = MBOX_CMD_ABORT_TASK;
937 mbox_cmd[1] = srb->fw_ddb_index;
939 /* Immediate Command Enable */
942 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
944 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE) {
947 DEBUG2(printk(KERN_WARNING "scsi%ld:%d:%d: abort task FAILED: "
948 "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
949 ha->host_no, cmd->device->id, cmd->device->lun, mbox_sts[0],
950 mbox_sts[1], mbox_sts[2], mbox_sts[3], mbox_sts[4]));
957 * qla4xxx_reset_lun - issues LUN Reset
958 * @ha: Pointer to host adapter structure.
959 * @ddb_entry: Pointer to device database entry
962 * This routine performs a LUN RESET on the specified target/lun.
963 * The caller must ensure that the ddb_entry and lun_entry pointers
964 * are valid before calling this routine.
966 int qla4xxx_reset_lun(struct scsi_qla_host * ha, struct ddb_entry * ddb_entry,
969 uint32_t mbox_cmd[MBOX_REG_COUNT];
970 uint32_t mbox_sts[MBOX_REG_COUNT];
971 int status = QLA_SUCCESS;
973 DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha->host_no,
974 ddb_entry->fw_ddb_index, lun));
977 * Send lun reset command to ISP, so that the ISP will return all
978 * outstanding requests with RESET status
980 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
981 memset(&mbox_sts, 0, sizeof(mbox_sts));
983 mbox_cmd[0] = MBOX_CMD_LUN_RESET;
984 mbox_cmd[1] = ddb_entry->fw_ddb_index;
985 mbox_cmd[2] = lun << 8;
986 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
988 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]);
989 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
990 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
997 * qla4xxx_reset_target - issues target Reset
998 * @ha: Pointer to host adapter structure.
999 * @db_entry: Pointer to device database entry
1000 * @un_entry: Pointer to lun entry structure
1002 * This routine performs a TARGET RESET on the specified target.
1003 * The caller must ensure that the ddb_entry pointers
1004 * are valid before calling this routine.
1006 int qla4xxx_reset_target(struct scsi_qla_host *ha,
1007 struct ddb_entry *ddb_entry)
1009 uint32_t mbox_cmd[MBOX_REG_COUNT];
1010 uint32_t mbox_sts[MBOX_REG_COUNT];
1011 int status = QLA_SUCCESS;
1013 DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha->host_no,
1014 ddb_entry->fw_ddb_index));
1017 * Send target reset command to ISP, so that the ISP will return all
1018 * outstanding requests with RESET status
1020 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1021 memset(&mbox_sts, 0, sizeof(mbox_sts));
1023 mbox_cmd[0] = MBOX_CMD_TARGET_WARM_RESET;
1024 mbox_cmd[1] = ddb_entry->fw_ddb_index;
1025 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
1027 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1029 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
1030 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
1036 int qla4xxx_get_flash(struct scsi_qla_host * ha, dma_addr_t dma_addr,
1037 uint32_t offset, uint32_t len)
1039 uint32_t mbox_cmd[MBOX_REG_COUNT];
1040 uint32_t mbox_sts[MBOX_REG_COUNT];
1042 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1043 memset(&mbox_sts, 0, sizeof(mbox_sts));
1045 mbox_cmd[0] = MBOX_CMD_READ_FLASH;
1046 mbox_cmd[1] = LSDW(dma_addr);
1047 mbox_cmd[2] = MSDW(dma_addr);
1048 mbox_cmd[3] = offset;
1051 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0], &mbox_sts[0]) !=
1053 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
1054 "status %04X %04X, offset %08x, len %08x\n", ha->host_no,
1055 __func__, mbox_sts[0], mbox_sts[1], offset, len));
1062 * qla4xxx_get_fw_version - gets firmware version
1063 * @ha: Pointer to host adapter structure.
1065 * Retrieves the firmware version on HBA. In QLA4010, mailboxes 2 & 3 may
1066 * hold an address for data. Make sure that we write 0 to those mailboxes,
1069 int qla4xxx_get_fw_version(struct scsi_qla_host * ha)
1071 uint32_t mbox_cmd[MBOX_REG_COUNT];
1072 uint32_t mbox_sts[MBOX_REG_COUNT];
1074 /* Get firmware version. */
1075 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1076 memset(&mbox_sts, 0, sizeof(mbox_sts));
1078 mbox_cmd[0] = MBOX_CMD_ABOUT_FW;
1080 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
1082 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_ABOUT_FW failed w/ "
1083 "status %04X\n", ha->host_no, __func__, mbox_sts[0]));
1087 /* Save firmware version information. */
1088 ha->firmware_version[0] = mbox_sts[1];
1089 ha->firmware_version[1] = mbox_sts[2];
1090 ha->patch_number = mbox_sts[3];
1091 ha->build_number = mbox_sts[4];
1096 static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha,
1097 dma_addr_t dma_addr)
1099 uint32_t mbox_cmd[MBOX_REG_COUNT];
1100 uint32_t mbox_sts[MBOX_REG_COUNT];
1102 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1103 memset(&mbox_sts, 0, sizeof(mbox_sts));
1105 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS;
1106 mbox_cmd[2] = LSDW(dma_addr);
1107 mbox_cmd[3] = MSDW(dma_addr);
1109 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]) !=
1111 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1112 ha->host_no, __func__, mbox_sts[0]));
1118 static int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t *ddb_index)
1120 uint32_t mbox_cmd[MBOX_REG_COUNT];
1121 uint32_t mbox_sts[MBOX_REG_COUNT];
1123 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1124 memset(&mbox_sts, 0, sizeof(mbox_sts));
1126 mbox_cmd[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY;
1127 mbox_cmd[1] = MAX_PRST_DEV_DB_ENTRIES;
1129 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
1131 if (mbox_sts[0] == MBOX_STS_COMMAND_ERROR) {
1132 *ddb_index = mbox_sts[2];
1134 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1135 ha->host_no, __func__, mbox_sts[0]));
1139 *ddb_index = MAX_PRST_DEV_DB_ENTRIES;
1146 int qla4xxx_send_tgts(struct scsi_qla_host *ha, char *ip, uint16_t port)
1148 struct dev_db_entry *fw_ddb_entry;
1149 dma_addr_t fw_ddb_entry_dma;
1151 int ret_val = QLA_SUCCESS;
1154 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
1155 sizeof(*fw_ddb_entry),
1156 &fw_ddb_entry_dma, GFP_KERNEL);
1157 if (!fw_ddb_entry) {
1158 DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
1159 ha->host_no, __func__));
1160 ret_val = QLA_ERROR;
1161 goto exit_send_tgts_no_free;
1164 ret_val = qla4xxx_get_default_ddb(ha, fw_ddb_entry_dma);
1165 if (ret_val != QLA_SUCCESS)
1166 goto exit_send_tgts;
1168 ret_val = qla4xxx_req_ddb_entry(ha, &ddb_index);
1169 if (ret_val != QLA_SUCCESS)
1170 goto exit_send_tgts;
1172 memset(fw_ddb_entry->iscsi_alias, 0,
1173 sizeof(fw_ddb_entry->iscsi_alias));
1175 memset(fw_ddb_entry->iscsi_name, 0,
1176 sizeof(fw_ddb_entry->iscsi_name));
1178 memset(fw_ddb_entry->ip_addr, 0, sizeof(fw_ddb_entry->ip_addr));
1179 memset(fw_ddb_entry->tgt_addr, 0,
1180 sizeof(fw_ddb_entry->tgt_addr));
1182 fw_ddb_entry->options = (DDB_OPT_DISC_SESSION | DDB_OPT_TARGET);
1183 fw_ddb_entry->port = cpu_to_le16(ntohs(port));
1185 fw_ddb_entry->ip_addr[0] = *ip;
1186 fw_ddb_entry->ip_addr[1] = *(ip + 1);
1187 fw_ddb_entry->ip_addr[2] = *(ip + 2);
1188 fw_ddb_entry->ip_addr[3] = *(ip + 3);
1190 ret_val = qla4xxx_set_ddb_entry(ha, ddb_index, fw_ddb_entry_dma);
1193 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1194 fw_ddb_entry, fw_ddb_entry_dma);
1195 exit_send_tgts_no_free: