2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2010 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;
37 /* Make sure that pointers are valid */
38 if (!mbx_cmd || !mbx_sts) {
39 DEBUG2(printk("scsi%ld: %s: Invalid mbx_cmd or mbx_sts "
40 "pointer\n", ha->host_no, __func__));
45 if (test_bit(AF_FW_RECOVERY, &ha->flags)) {
46 DEBUG2(ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: "
47 "prematurely completing mbx cmd as firmware "
48 "recovery detected\n", ha->host_no, __func__));
51 /* Do not send any mbx cmd if h/w is in failed state*/
52 qla4_8xxx_idc_lock(ha);
53 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
54 qla4_8xxx_idc_unlock(ha);
55 if (dev_state == QLA82XX_DEV_FAILED) {
56 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: H/W is in "
57 "failed state, do not send any mailbox commands\n",
58 ha->host_no, __func__);
63 if ((is_aer_supported(ha)) &&
64 (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))) {
65 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Perm failure on EEH, "
66 "timeout MBX Exiting.\n", ha->host_no, __func__));
70 /* Mailbox code active */
71 wait_count = MBOX_TOV * 100;
73 while (wait_count--) {
74 mutex_lock(&ha->mbox_sem);
75 if (!test_bit(AF_MBOX_COMMAND, &ha->flags)) {
76 set_bit(AF_MBOX_COMMAND, &ha->flags);
77 mutex_unlock(&ha->mbox_sem);
80 mutex_unlock(&ha->mbox_sem);
82 DEBUG2(printk("scsi%ld: %s: mbox_sem failed\n",
83 ha->host_no, __func__));
89 /* To prevent overwriting mailbox registers for a command that has
90 * not yet been serviced, check to see if an active command
91 * (AEN, IOCB, etc.) is interrupting, then service it.
92 * -----------------------------------------------------------------
94 spin_lock_irqsave(&ha->hardware_lock, flags);
96 if (!is_qla8022(ha)) {
97 intr_status = readl(&ha->reg->ctrl_status);
98 if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
99 /* Service existing interrupt */
100 ha->isp_ops->interrupt_service_routine(ha, intr_status);
101 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
105 ha->mbox_status_count = outCount;
106 for (i = 0; i < outCount; i++)
107 ha->mbox_status[i] = 0;
109 if (is_qla8022(ha)) {
110 /* Load all mailbox registers, except mailbox 0. */
112 printk("scsi%ld: %s: Cmd ", ha->host_no, __func__);
113 for (i = 0; i < inCount; i++)
114 printk("mb%d=%04x ", i, mbx_cmd[i]);
117 for (i = 1; i < inCount; i++)
118 writel(mbx_cmd[i], &ha->qla4_8xxx_reg->mailbox_in[i]);
119 writel(mbx_cmd[0], &ha->qla4_8xxx_reg->mailbox_in[0]);
120 readl(&ha->qla4_8xxx_reg->mailbox_in[0]);
121 writel(HINT_MBX_INT_PENDING, &ha->qla4_8xxx_reg->hint);
123 /* Load all mailbox registers, except mailbox 0. */
124 for (i = 1; i < inCount; i++)
125 writel(mbx_cmd[i], &ha->reg->mailbox[i]);
127 /* Wakeup firmware */
128 writel(mbx_cmd[0], &ha->reg->mailbox[0]);
129 readl(&ha->reg->mailbox[0]);
130 writel(set_rmask(CSR_INTR_RISC), &ha->reg->ctrl_status);
131 readl(&ha->reg->ctrl_status);
134 spin_unlock_irqrestore(&ha->hardware_lock, flags);
136 /* Wait for completion */
139 * If we don't want status, don't wait for the mailbox command to
140 * complete. For example, MBOX_CMD_RESET_FW doesn't return status,
141 * you must poll the inbound Interrupt Mask for completion.
144 status = QLA_SUCCESS;
149 * Wait for completion: Poll or completion queue
151 if (test_bit(AF_IRQ_ATTACHED, &ha->flags) &&
152 test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
153 test_bit(AF_ONLINE, &ha->flags) &&
154 !test_bit(AF_HBA_GOING_AWAY, &ha->flags)) {
155 /* Do not poll for completion. Use completion queue */
156 set_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
157 wait_for_completion_timeout(&ha->mbx_intr_comp, MBOX_TOV * HZ);
158 clear_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
160 /* Poll for command to complete */
161 wait_count = jiffies + MBOX_TOV * HZ;
162 while (test_bit(AF_MBOX_COMMAND_DONE, &ha->flags) == 0) {
163 if (time_after_eq(jiffies, wait_count))
167 * Service the interrupt.
168 * The ISR will save the mailbox status registers
169 * to a temporary storage location in the adapter
173 spin_lock_irqsave(&ha->hardware_lock, flags);
174 if (is_qla8022(ha)) {
176 readl(&ha->qla4_8xxx_reg->host_int);
177 if (intr_status & ISRX_82XX_RISC_INT) {
178 ha->mbox_status_count = outCount;
180 readl(&ha->qla4_8xxx_reg->host_status);
181 ha->isp_ops->interrupt_service_routine(
183 if (test_bit(AF_INTERRUPTS_ON,
185 test_bit(AF_INTx_ENABLED,
188 ha->nx_legacy_intr.tgt_mask_reg,
192 intr_status = readl(&ha->reg->ctrl_status);
193 if (intr_status & INTR_PENDING) {
195 * Service the interrupt.
196 * The ISR will save the mailbox status
197 * registers to a temporary storage
198 * location in the adapter structure.
200 ha->mbox_status_count = outCount;
201 ha->isp_ops->interrupt_service_routine(
205 spin_unlock_irqrestore(&ha->hardware_lock, flags);
210 /* Check for mailbox timeout. */
211 if (!test_bit(AF_MBOX_COMMAND_DONE, &ha->flags)) {
212 if (is_qla8022(ha) &&
213 test_bit(AF_FW_RECOVERY, &ha->flags)) {
214 DEBUG2(ql4_printk(KERN_INFO, ha,
215 "scsi%ld: %s: prematurely completing mbx cmd as "
216 "firmware recovery detected\n",
217 ha->host_no, __func__));
220 DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
221 " Scheduling Adapter Reset\n", ha->host_no,
223 ha->mailbox_timeout_count++;
225 set_bit(DPC_RESET_HA, &ha->dpc_flags);
230 * Copy the mailbox out registers to the caller's mailbox in/out
233 spin_lock_irqsave(&ha->hardware_lock, flags);
234 for (i = 0; i < outCount; i++)
235 mbx_sts[i] = ha->mbox_status[i];
237 /* Set return status and error flags (if applicable). */
238 switch (ha->mbox_status[0]) {
239 case MBOX_STS_COMMAND_COMPLETE:
240 status = QLA_SUCCESS;
243 case MBOX_STS_INTERMEDIATE_COMPLETION:
244 status = QLA_SUCCESS;
248 DEBUG2( printk("scsi%ld: %s: Cmd = %08X, ISP BUSY\n",
249 ha->host_no, __func__, mbx_cmd[0]));
250 ha->mailbox_timeout_count++;
254 DEBUG2(printk("scsi%ld: %s: **** FAILED, cmd = %08X, "
255 "sts = %08X ****\n", ha->host_no, __func__,
256 mbx_cmd[0], mbx_sts[0]));
259 spin_unlock_irqrestore(&ha->hardware_lock, flags);
262 mutex_lock(&ha->mbox_sem);
263 clear_bit(AF_MBOX_COMMAND, &ha->flags);
264 mutex_unlock(&ha->mbox_sem);
265 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
270 void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha)
272 set_bit(AF_FW_RECOVERY, &ha->flags);
273 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: set FW RECOVERY!\n",
274 ha->host_no, __func__);
276 if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
277 if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags)) {
278 complete(&ha->mbx_intr_comp);
279 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
280 "recovery, doing premature completion of "
281 "mbx cmd\n", ha->host_no, __func__);
284 set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
285 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
286 "recovery, doing premature completion of "
287 "polling mbx cmd\n", ha->host_no, __func__);
293 qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
294 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
296 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
297 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
300 qla4_8xxx_wr_32(ha, ha->nx_db_wr_ptr, 0);
302 mbox_cmd[0] = MBOX_CMD_INITIALIZE_FIRMWARE;
304 mbox_cmd[2] = LSDW(init_fw_cb_dma);
305 mbox_cmd[3] = MSDW(init_fw_cb_dma);
306 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
307 mbox_cmd[5] = (IFCB_VER_MAX << 8) | IFCB_VER_MIN;
309 if (qla4xxx_mailbox_command(ha, 6, 6, mbox_cmd, mbox_sts) !=
311 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
312 "MBOX_CMD_INITIALIZE_FIRMWARE"
313 " failed w/ status %04X\n",
314 ha->host_no, __func__, mbox_sts[0]));
321 qla4xxx_get_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
322 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
324 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
325 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
326 mbox_cmd[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK;
327 mbox_cmd[2] = LSDW(init_fw_cb_dma);
328 mbox_cmd[3] = MSDW(init_fw_cb_dma);
329 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
331 if (qla4xxx_mailbox_command(ha, 5, 5, mbox_cmd, mbox_sts) !=
333 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
334 "MBOX_CMD_GET_INIT_FW_CTRL_BLOCK"
335 " failed w/ status %04X\n",
336 ha->host_no, __func__, mbox_sts[0]));
343 qla4xxx_update_local_ip(struct scsi_qla_host *ha,
344 struct addr_ctrl_blk *init_fw_cb)
346 /* Save IPv4 Address Info */
347 memcpy(ha->ip_address, init_fw_cb->ipv4_addr,
348 min(sizeof(ha->ip_address), sizeof(init_fw_cb->ipv4_addr)));
349 memcpy(ha->subnet_mask, init_fw_cb->ipv4_subnet,
350 min(sizeof(ha->subnet_mask), sizeof(init_fw_cb->ipv4_subnet)));
351 memcpy(ha->gateway, init_fw_cb->ipv4_gw_addr,
352 min(sizeof(ha->gateway), sizeof(init_fw_cb->ipv4_gw_addr)));
354 if (is_ipv6_enabled(ha)) {
355 /* Save IPv6 Address */
356 ha->ipv6_link_local_state = init_fw_cb->ipv6_lnk_lcl_addr_state;
357 ha->ipv6_addr0_state = init_fw_cb->ipv6_addr0_state;
358 ha->ipv6_addr1_state = init_fw_cb->ipv6_addr1_state;
359 ha->ipv6_default_router_state = init_fw_cb->ipv6_dflt_rtr_state;
360 ha->ipv6_link_local_addr.in6_u.u6_addr8[0] = 0xFE;
361 ha->ipv6_link_local_addr.in6_u.u6_addr8[1] = 0x80;
363 memcpy(&ha->ipv6_link_local_addr.in6_u.u6_addr8[8],
364 init_fw_cb->ipv6_if_id,
365 min(sizeof(ha->ipv6_link_local_addr)/2,
366 sizeof(init_fw_cb->ipv6_if_id)));
367 memcpy(&ha->ipv6_addr0, init_fw_cb->ipv6_addr0,
368 min(sizeof(ha->ipv6_addr0),
369 sizeof(init_fw_cb->ipv6_addr0)));
370 memcpy(&ha->ipv6_addr1, init_fw_cb->ipv6_addr1,
371 min(sizeof(ha->ipv6_addr1),
372 sizeof(init_fw_cb->ipv6_addr1)));
373 memcpy(&ha->ipv6_default_router_addr,
374 init_fw_cb->ipv6_dflt_rtr_addr,
375 min(sizeof(ha->ipv6_default_router_addr),
376 sizeof(init_fw_cb->ipv6_dflt_rtr_addr)));
381 qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
384 struct addr_ctrl_blk *init_fw_cb,
385 dma_addr_t init_fw_cb_dma)
387 if (qla4xxx_get_ifcb(ha, mbox_cmd, mbox_sts, init_fw_cb_dma)
389 DEBUG2(printk(KERN_WARNING
390 "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
391 ha->host_no, __func__));
395 DEBUG2(qla4xxx_dump_buffer(init_fw_cb, sizeof(struct addr_ctrl_blk)));
397 /* Save some info in adapter structure. */
398 ha->acb_version = init_fw_cb->acb_version;
399 ha->firmware_options = le16_to_cpu(init_fw_cb->fw_options);
400 ha->tcp_options = le16_to_cpu(init_fw_cb->ipv4_tcp_opts);
401 ha->ipv4_options = le16_to_cpu(init_fw_cb->ipv4_ip_opts);
402 ha->ipv4_addr_state = le16_to_cpu(init_fw_cb->ipv4_addr_state);
403 ha->heartbeat_interval = init_fw_cb->hb_interval;
404 memcpy(ha->name_string, init_fw_cb->iscsi_name,
405 min(sizeof(ha->name_string),
406 sizeof(init_fw_cb->iscsi_name)));
407 /*memcpy(ha->alias, init_fw_cb->Alias,
408 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
410 if (ha->acb_version == ACB_SUPPORTED) {
411 ha->ipv6_options = init_fw_cb->ipv6_opts;
412 ha->ipv6_addl_options = init_fw_cb->ipv6_addtl_opts;
414 qla4xxx_update_local_ip(ha, init_fw_cb);
420 * qla4xxx_initialize_fw_cb - initializes firmware control block.
421 * @ha: Pointer to host adapter structure.
423 int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
425 struct addr_ctrl_blk *init_fw_cb;
426 dma_addr_t init_fw_cb_dma;
427 uint32_t mbox_cmd[MBOX_REG_COUNT];
428 uint32_t mbox_sts[MBOX_REG_COUNT];
429 int status = QLA_ERROR;
431 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
432 sizeof(struct addr_ctrl_blk),
433 &init_fw_cb_dma, GFP_KERNEL);
434 if (init_fw_cb == NULL) {
435 DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
436 ha->host_no, __func__));
437 goto exit_init_fw_cb_no_free;
439 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
441 /* Get Initialize Firmware Control Block. */
442 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
443 memset(&mbox_sts, 0, sizeof(mbox_sts));
445 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
447 dma_free_coherent(&ha->pdev->dev,
448 sizeof(struct addr_ctrl_blk),
449 init_fw_cb, init_fw_cb_dma);
450 goto exit_init_fw_cb;
453 /* Initialize request and response queues. */
454 qla4xxx_init_rings(ha);
456 /* Fill in the request and response queue information. */
457 init_fw_cb->rqq_consumer_idx = cpu_to_le16(ha->request_out);
458 init_fw_cb->compq_producer_idx = cpu_to_le16(ha->response_in);
459 init_fw_cb->rqq_len = __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH);
460 init_fw_cb->compq_len = __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH);
461 init_fw_cb->rqq_addr_lo = cpu_to_le32(LSDW(ha->request_dma));
462 init_fw_cb->rqq_addr_hi = cpu_to_le32(MSDW(ha->request_dma));
463 init_fw_cb->compq_addr_lo = cpu_to_le32(LSDW(ha->response_dma));
464 init_fw_cb->compq_addr_hi = cpu_to_le32(MSDW(ha->response_dma));
465 init_fw_cb->shdwreg_addr_lo = cpu_to_le32(LSDW(ha->shadow_regs_dma));
466 init_fw_cb->shdwreg_addr_hi = cpu_to_le32(MSDW(ha->shadow_regs_dma));
468 /* Set up required options. */
469 init_fw_cb->fw_options |=
470 __constant_cpu_to_le16(FWOPT_SESSION_MODE |
471 FWOPT_INITIATOR_MODE);
474 init_fw_cb->fw_options |=
475 __constant_cpu_to_le16(FWOPT_ENABLE_CRBDB);
477 init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
479 if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
481 DEBUG2(printk(KERN_WARNING
482 "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
483 ha->host_no, __func__));
484 goto exit_init_fw_cb;
487 if (qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0],
488 init_fw_cb, init_fw_cb_dma) != QLA_SUCCESS) {
489 DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
490 ha->host_no, __func__));
491 goto exit_init_fw_cb;
493 status = QLA_SUCCESS;
496 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
497 init_fw_cb, init_fw_cb_dma);
498 exit_init_fw_cb_no_free:
503 * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
504 * @ha: Pointer to host adapter structure.
506 int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host * ha)
508 struct addr_ctrl_blk *init_fw_cb;
509 dma_addr_t init_fw_cb_dma;
510 uint32_t mbox_cmd[MBOX_REG_COUNT];
511 uint32_t mbox_sts[MBOX_REG_COUNT];
513 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
514 sizeof(struct addr_ctrl_blk),
515 &init_fw_cb_dma, GFP_KERNEL);
516 if (init_fw_cb == NULL) {
517 printk("scsi%ld: %s: Unable to alloc init_cb\n", ha->host_no,
522 /* Get Initialize Firmware Control Block. */
523 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
524 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
526 DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
527 ha->host_no, __func__));
528 dma_free_coherent(&ha->pdev->dev,
529 sizeof(struct addr_ctrl_blk),
530 init_fw_cb, init_fw_cb_dma);
534 /* Save IP Address. */
535 qla4xxx_update_local_ip(ha, init_fw_cb);
536 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
537 init_fw_cb, init_fw_cb_dma);
543 * qla4xxx_get_firmware_state - gets firmware state of HBA
544 * @ha: Pointer to host adapter structure.
546 int qla4xxx_get_firmware_state(struct scsi_qla_host * ha)
548 uint32_t mbox_cmd[MBOX_REG_COUNT];
549 uint32_t mbox_sts[MBOX_REG_COUNT];
551 /* Get firmware version */
552 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
553 memset(&mbox_sts, 0, sizeof(mbox_sts));
555 mbox_cmd[0] = MBOX_CMD_GET_FW_STATE;
557 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 4, &mbox_cmd[0], &mbox_sts[0]) !=
559 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
560 "status %04X\n", ha->host_no, __func__,
564 ha->firmware_state = mbox_sts[1];
565 ha->board_id = mbox_sts[2];
566 ha->addl_fw_state = mbox_sts[3];
567 DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
568 ha->host_no, __func__, ha->firmware_state);)
574 * qla4xxx_get_firmware_status - retrieves firmware status
575 * @ha: Pointer to host adapter structure.
577 int qla4xxx_get_firmware_status(struct scsi_qla_host * ha)
579 uint32_t mbox_cmd[MBOX_REG_COUNT];
580 uint32_t mbox_sts[MBOX_REG_COUNT];
582 /* Get firmware version */
583 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
584 memset(&mbox_sts, 0, sizeof(mbox_sts));
586 mbox_cmd[0] = MBOX_CMD_GET_FW_STATUS;
588 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
590 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
591 "status %04X\n", ha->host_no, __func__,
596 ql4_printk(KERN_INFO, ha, "%ld firmare IOCBs available (%d).\n",
597 ha->host_no, mbox_sts[2]);
603 * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
604 * @ha: Pointer to host adapter structure.
605 * @fw_ddb_index: Firmware's device database index
606 * @fw_ddb_entry: Pointer to firmware's device database entry structure
607 * @num_valid_ddb_entries: Pointer to number of valid ddb entries
608 * @next_ddb_index: Pointer to next valid device database index
609 * @fw_ddb_device_state: Pointer to device state
611 int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
612 uint16_t fw_ddb_index,
613 struct dev_db_entry *fw_ddb_entry,
614 dma_addr_t fw_ddb_entry_dma,
615 uint32_t *num_valid_ddb_entries,
616 uint32_t *next_ddb_index,
617 uint32_t *fw_ddb_device_state,
618 uint32_t *conn_err_detail,
619 uint16_t *tcp_source_port_num,
620 uint16_t *connection_id)
622 int status = QLA_ERROR;
624 uint32_t mbox_cmd[MBOX_REG_COUNT];
625 uint32_t mbox_sts[MBOX_REG_COUNT];
627 /* Make sure the device index is valid */
628 if (fw_ddb_index >= MAX_DDB_ENTRIES) {
629 DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
630 ha->host_no, __func__, fw_ddb_index));
633 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
634 memset(&mbox_sts, 0, sizeof(mbox_sts));
636 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY;
637 mbox_cmd[1] = (uint32_t) fw_ddb_index;
638 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
639 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
640 mbox_cmd[4] = sizeof(struct dev_db_entry);
642 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 7, &mbox_cmd[0], &mbox_sts[0]) ==
644 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
645 " with status 0x%04X\n", ha->host_no, __func__,
649 if (fw_ddb_index != mbox_sts[1]) {
650 DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
651 ha->host_no, __func__, fw_ddb_index,
656 options = le16_to_cpu(fw_ddb_entry->options);
657 if (options & DDB_OPT_IPV6_DEVICE) {
658 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
659 "Next %d State %04x ConnErr %08x %pI6 "
660 ":%04d \"%s\"\n", __func__, fw_ddb_index,
661 mbox_sts[0], mbox_sts[2], mbox_sts[3],
662 mbox_sts[4], mbox_sts[5],
663 fw_ddb_entry->ip_addr,
664 le16_to_cpu(fw_ddb_entry->port),
665 fw_ddb_entry->iscsi_name);
667 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
668 "Next %d State %04x ConnErr %08x %pI4 "
669 ":%04d \"%s\"\n", __func__, fw_ddb_index,
670 mbox_sts[0], mbox_sts[2], mbox_sts[3],
671 mbox_sts[4], mbox_sts[5],
672 fw_ddb_entry->ip_addr,
673 le16_to_cpu(fw_ddb_entry->port),
674 fw_ddb_entry->iscsi_name);
677 if (num_valid_ddb_entries)
678 *num_valid_ddb_entries = mbox_sts[2];
680 *next_ddb_index = mbox_sts[3];
681 if (fw_ddb_device_state)
682 *fw_ddb_device_state = mbox_sts[4];
685 * RA: This mailbox has been changed to pass connection error and
686 * details. Its true for ISP4010 as per Version E - Not sure when it
687 * was changed. Get the time2wait from the fw_dd_entry field :
688 * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
692 *conn_err_detail = mbox_sts[5];
693 if (tcp_source_port_num)
694 *tcp_source_port_num = (uint16_t) (mbox_sts[6] >> 16);
696 *connection_id = (uint16_t) mbox_sts[6] & 0x00FF;
697 status = QLA_SUCCESS;
704 * qla4xxx_set_fwddb_entry - sets a ddb entry.
705 * @ha: Pointer to host adapter structure.
706 * @fw_ddb_index: Firmware's device database index
707 * @fw_ddb_entry: Pointer to firmware's ddb entry structure, or NULL.
709 * This routine initializes or updates the adapter's device database
710 * entry for the specified device. It also triggers a login for the
711 * specified device. Therefore, it may also be used as a secondary
712 * login routine when a NULL pointer is specified for the fw_ddb_entry.
714 int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
715 dma_addr_t fw_ddb_entry_dma)
717 uint32_t mbox_cmd[MBOX_REG_COUNT];
718 uint32_t mbox_sts[MBOX_REG_COUNT];
721 /* Do not wait for completion. The firmware will send us an
722 * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
724 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
725 memset(&mbox_sts, 0, sizeof(mbox_sts));
727 mbox_cmd[0] = MBOX_CMD_SET_DATABASE_ENTRY;
728 mbox_cmd[1] = (uint32_t) fw_ddb_index;
729 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
730 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
731 mbox_cmd[4] = sizeof(struct dev_db_entry);
733 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
735 DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
736 ha->host_no, __func__, status, mbox_sts[0], mbox_sts[4]);)
742 * qla4xxx_get_crash_record - retrieves crash record.
743 * @ha: Pointer to host adapter structure.
745 * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
747 void qla4xxx_get_crash_record(struct scsi_qla_host * ha)
749 uint32_t mbox_cmd[MBOX_REG_COUNT];
750 uint32_t mbox_sts[MBOX_REG_COUNT];
751 struct crash_record *crash_record = NULL;
752 dma_addr_t crash_record_dma = 0;
753 uint32_t crash_record_size = 0;
755 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
756 memset(&mbox_sts, 0, sizeof(mbox_cmd));
758 /* Get size of crash record. */
759 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
761 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
763 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
764 ha->host_no, __func__));
765 goto exit_get_crash_record;
767 crash_record_size = mbox_sts[4];
768 if (crash_record_size == 0) {
769 DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
770 ha->host_no, __func__));
771 goto exit_get_crash_record;
774 /* Alloc Memory for Crash Record. */
775 crash_record = dma_alloc_coherent(&ha->pdev->dev, crash_record_size,
776 &crash_record_dma, GFP_KERNEL);
777 if (crash_record == NULL)
778 goto exit_get_crash_record;
780 /* Get Crash Record. */
781 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
782 memset(&mbox_sts, 0, sizeof(mbox_cmd));
784 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
785 mbox_cmd[2] = LSDW(crash_record_dma);
786 mbox_cmd[3] = MSDW(crash_record_dma);
787 mbox_cmd[4] = crash_record_size;
789 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
791 goto exit_get_crash_record;
793 /* Dump Crash Record. */
795 exit_get_crash_record:
797 dma_free_coherent(&ha->pdev->dev, crash_record_size,
798 crash_record, crash_record_dma);
802 * qla4xxx_get_conn_event_log - retrieves connection event log
803 * @ha: Pointer to host adapter structure.
805 void qla4xxx_get_conn_event_log(struct scsi_qla_host * ha)
807 uint32_t mbox_cmd[MBOX_REG_COUNT];
808 uint32_t mbox_sts[MBOX_REG_COUNT];
809 struct conn_event_log_entry *event_log = NULL;
810 dma_addr_t event_log_dma = 0;
811 uint32_t event_log_size = 0;
812 uint32_t num_valid_entries;
813 uint32_t oldest_entry = 0;
814 uint32_t max_event_log_entries;
818 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
819 memset(&mbox_sts, 0, sizeof(mbox_cmd));
821 /* Get size of crash record. */
822 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
824 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
826 goto exit_get_event_log;
828 event_log_size = mbox_sts[4];
829 if (event_log_size == 0)
830 goto exit_get_event_log;
832 /* Alloc Memory for Crash Record. */
833 event_log = dma_alloc_coherent(&ha->pdev->dev, event_log_size,
834 &event_log_dma, GFP_KERNEL);
835 if (event_log == NULL)
836 goto exit_get_event_log;
838 /* Get Crash Record. */
839 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
840 memset(&mbox_sts, 0, sizeof(mbox_cmd));
842 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
843 mbox_cmd[2] = LSDW(event_log_dma);
844 mbox_cmd[3] = MSDW(event_log_dma);
846 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
848 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
849 "log!\n", ha->host_no, __func__));
850 goto exit_get_event_log;
853 /* Dump Event Log. */
854 num_valid_entries = mbox_sts[1];
856 max_event_log_entries = event_log_size /
857 sizeof(struct conn_event_log_entry);
859 if (num_valid_entries > max_event_log_entries)
860 oldest_entry = num_valid_entries % max_event_log_entries;
862 DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
863 ha->host_no, num_valid_entries));
865 if (ql4xextended_error_logging == 3) {
866 if (oldest_entry == 0) {
867 /* Circular Buffer has not wrapped around */
868 for (i=0; i < num_valid_entries; i++) {
869 qla4xxx_dump_buffer((uint8_t *)event_log+
870 (i*sizeof(*event_log)),
875 /* Circular Buffer has wrapped around -
876 * display accordingly*/
877 for (i=oldest_entry; i < max_event_log_entries; i++) {
878 qla4xxx_dump_buffer((uint8_t *)event_log+
879 (i*sizeof(*event_log)),
882 for (i=0; i < oldest_entry; i++) {
883 qla4xxx_dump_buffer((uint8_t *)event_log+
884 (i*sizeof(*event_log)),
892 dma_free_coherent(&ha->pdev->dev, event_log_size, event_log,
897 * qla4xxx_abort_task - issues Abort Task
898 * @ha: Pointer to host adapter structure.
899 * @srb: Pointer to srb entry
901 * This routine performs a LUN RESET on the specified target/lun.
902 * The caller must ensure that the ddb_entry and lun_entry pointers
903 * are valid before calling this routine.
905 int qla4xxx_abort_task(struct scsi_qla_host *ha, struct srb *srb)
907 uint32_t mbox_cmd[MBOX_REG_COUNT];
908 uint32_t mbox_sts[MBOX_REG_COUNT];
909 struct scsi_cmnd *cmd = srb->cmd;
910 int status = QLA_SUCCESS;
911 unsigned long flags = 0;
915 * Send abort task command to ISP, so that the ISP will return
916 * request with ABORT status
918 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
919 memset(&mbox_sts, 0, sizeof(mbox_sts));
921 spin_lock_irqsave(&ha->hardware_lock, flags);
922 index = (unsigned long)(unsigned char *)cmd->host_scribble;
923 spin_unlock_irqrestore(&ha->hardware_lock, flags);
925 /* Firmware already posted completion on response queue */
926 if (index == MAX_SRBS)
929 mbox_cmd[0] = MBOX_CMD_ABORT_TASK;
930 mbox_cmd[1] = srb->ddb->fw_ddb_index;
932 /* Immediate Command Enable */
935 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
937 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE) {
940 DEBUG2(printk(KERN_WARNING "scsi%ld:%d:%d: abort task FAILED: "
941 "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
942 ha->host_no, cmd->device->id, cmd->device->lun, mbox_sts[0],
943 mbox_sts[1], mbox_sts[2], mbox_sts[3], mbox_sts[4]));
950 * qla4xxx_reset_lun - issues LUN Reset
951 * @ha: Pointer to host adapter structure.
952 * @ddb_entry: Pointer to device database entry
955 * This routine performs a LUN RESET on the specified target/lun.
956 * The caller must ensure that the ddb_entry and lun_entry pointers
957 * are valid before calling this routine.
959 int qla4xxx_reset_lun(struct scsi_qla_host * ha, struct ddb_entry * ddb_entry,
962 uint32_t mbox_cmd[MBOX_REG_COUNT];
963 uint32_t mbox_sts[MBOX_REG_COUNT];
964 int status = QLA_SUCCESS;
966 DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha->host_no,
967 ddb_entry->fw_ddb_index, lun));
970 * Send lun reset command to ISP, so that the ISP will return all
971 * outstanding requests with RESET status
973 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
974 memset(&mbox_sts, 0, sizeof(mbox_sts));
976 mbox_cmd[0] = MBOX_CMD_LUN_RESET;
977 mbox_cmd[1] = ddb_entry->fw_ddb_index;
978 mbox_cmd[2] = lun << 8;
979 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
981 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]);
982 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
983 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
990 * qla4xxx_reset_target - issues target Reset
991 * @ha: Pointer to host adapter structure.
992 * @db_entry: Pointer to device database entry
993 * @un_entry: Pointer to lun entry structure
995 * This routine performs a TARGET RESET on the specified target.
996 * The caller must ensure that the ddb_entry pointers
997 * are valid before calling this routine.
999 int qla4xxx_reset_target(struct scsi_qla_host *ha,
1000 struct ddb_entry *ddb_entry)
1002 uint32_t mbox_cmd[MBOX_REG_COUNT];
1003 uint32_t mbox_sts[MBOX_REG_COUNT];
1004 int status = QLA_SUCCESS;
1006 DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha->host_no,
1007 ddb_entry->fw_ddb_index));
1010 * Send target reset command to ISP, so that the ISP will return all
1011 * outstanding requests with RESET status
1013 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1014 memset(&mbox_sts, 0, sizeof(mbox_sts));
1016 mbox_cmd[0] = MBOX_CMD_TARGET_WARM_RESET;
1017 mbox_cmd[1] = ddb_entry->fw_ddb_index;
1018 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
1020 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1022 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
1023 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
1029 int qla4xxx_get_flash(struct scsi_qla_host * ha, dma_addr_t dma_addr,
1030 uint32_t offset, uint32_t len)
1032 uint32_t mbox_cmd[MBOX_REG_COUNT];
1033 uint32_t mbox_sts[MBOX_REG_COUNT];
1035 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1036 memset(&mbox_sts, 0, sizeof(mbox_sts));
1038 mbox_cmd[0] = MBOX_CMD_READ_FLASH;
1039 mbox_cmd[1] = LSDW(dma_addr);
1040 mbox_cmd[2] = MSDW(dma_addr);
1041 mbox_cmd[3] = offset;
1044 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0], &mbox_sts[0]) !=
1046 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
1047 "status %04X %04X, offset %08x, len %08x\n", ha->host_no,
1048 __func__, mbox_sts[0], mbox_sts[1], offset, len));
1055 * qla4xxx_get_fw_version - gets firmware version
1056 * @ha: Pointer to host adapter structure.
1058 * Retrieves the firmware version on HBA. In QLA4010, mailboxes 2 & 3 may
1059 * hold an address for data. Make sure that we write 0 to those mailboxes,
1062 int qla4xxx_get_fw_version(struct scsi_qla_host * ha)
1064 uint32_t mbox_cmd[MBOX_REG_COUNT];
1065 uint32_t mbox_sts[MBOX_REG_COUNT];
1067 /* Get firmware version. */
1068 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1069 memset(&mbox_sts, 0, sizeof(mbox_sts));
1071 mbox_cmd[0] = MBOX_CMD_ABOUT_FW;
1073 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
1075 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_ABOUT_FW failed w/ "
1076 "status %04X\n", ha->host_no, __func__, mbox_sts[0]));
1080 /* Save firmware version information. */
1081 ha->firmware_version[0] = mbox_sts[1];
1082 ha->firmware_version[1] = mbox_sts[2];
1083 ha->patch_number = mbox_sts[3];
1084 ha->build_number = mbox_sts[4];
1089 static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha,
1090 dma_addr_t dma_addr)
1092 uint32_t mbox_cmd[MBOX_REG_COUNT];
1093 uint32_t mbox_sts[MBOX_REG_COUNT];
1095 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1096 memset(&mbox_sts, 0, sizeof(mbox_sts));
1098 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS;
1099 mbox_cmd[2] = LSDW(dma_addr);
1100 mbox_cmd[3] = MSDW(dma_addr);
1102 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]) !=
1104 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1105 ha->host_no, __func__, mbox_sts[0]));
1111 static int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t *ddb_index)
1113 uint32_t mbox_cmd[MBOX_REG_COUNT];
1114 uint32_t mbox_sts[MBOX_REG_COUNT];
1116 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1117 memset(&mbox_sts, 0, sizeof(mbox_sts));
1119 mbox_cmd[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY;
1120 mbox_cmd[1] = MAX_PRST_DEV_DB_ENTRIES;
1122 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
1124 if (mbox_sts[0] == MBOX_STS_COMMAND_ERROR) {
1125 *ddb_index = mbox_sts[2];
1127 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1128 ha->host_no, __func__, mbox_sts[0]));
1132 *ddb_index = MAX_PRST_DEV_DB_ENTRIES;
1139 int qla4xxx_send_tgts(struct scsi_qla_host *ha, char *ip, uint16_t port)
1141 struct dev_db_entry *fw_ddb_entry;
1142 dma_addr_t fw_ddb_entry_dma;
1144 int ret_val = QLA_SUCCESS;
1147 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
1148 sizeof(*fw_ddb_entry),
1149 &fw_ddb_entry_dma, GFP_KERNEL);
1150 if (!fw_ddb_entry) {
1151 DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
1152 ha->host_no, __func__));
1153 ret_val = QLA_ERROR;
1154 goto exit_send_tgts_no_free;
1157 ret_val = qla4xxx_get_default_ddb(ha, fw_ddb_entry_dma);
1158 if (ret_val != QLA_SUCCESS)
1159 goto exit_send_tgts;
1161 ret_val = qla4xxx_req_ddb_entry(ha, &ddb_index);
1162 if (ret_val != QLA_SUCCESS)
1163 goto exit_send_tgts;
1165 memset(fw_ddb_entry->iscsi_alias, 0,
1166 sizeof(fw_ddb_entry->iscsi_alias));
1168 memset(fw_ddb_entry->iscsi_name, 0,
1169 sizeof(fw_ddb_entry->iscsi_name));
1171 memset(fw_ddb_entry->ip_addr, 0, sizeof(fw_ddb_entry->ip_addr));
1172 memset(fw_ddb_entry->tgt_addr, 0,
1173 sizeof(fw_ddb_entry->tgt_addr));
1175 fw_ddb_entry->options = (DDB_OPT_DISC_SESSION | DDB_OPT_TARGET);
1176 fw_ddb_entry->port = cpu_to_le16(ntohs(port));
1178 fw_ddb_entry->ip_addr[0] = *ip;
1179 fw_ddb_entry->ip_addr[1] = *(ip + 1);
1180 fw_ddb_entry->ip_addr[2] = *(ip + 2);
1181 fw_ddb_entry->ip_addr[3] = *(ip + 3);
1183 ret_val = qla4xxx_set_ddb_entry(ha, ddb_index, fw_ddb_entry_dma);
1186 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1187 fw_ddb_entry, fw_ddb_entry_dma);
1188 exit_send_tgts_no_free: