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__));
42 /* Mailbox code active */
43 wait_count = MBOX_TOV * 100;
45 while (wait_count--) {
46 mutex_lock(&ha->mbox_sem);
47 if (!test_bit(AF_MBOX_COMMAND, &ha->flags)) {
48 set_bit(AF_MBOX_COMMAND, &ha->flags);
49 mutex_unlock(&ha->mbox_sem);
52 mutex_unlock(&ha->mbox_sem);
54 DEBUG2(printk("scsi%ld: %s: mbox_sem failed\n",
55 ha->host_no, __func__));
61 /* To prevent overwriting mailbox registers for a command that has
62 * not yet been serviced, check to see if an active command
63 * (AEN, IOCB, etc.) is interrupting, then service it.
64 * -----------------------------------------------------------------
66 spin_lock_irqsave(&ha->hardware_lock, flags);
69 intr_status = readl(&ha->qla4_8xxx_reg->host_int);
70 if (intr_status & ISRX_82XX_RISC_INT) {
71 /* Service existing interrupt */
72 DEBUG2(printk("scsi%ld: %s: "
73 "servicing existing interrupt\n",
74 ha->host_no, __func__));
75 intr_status = readl(&ha->qla4_8xxx_reg->host_status);
76 ha->isp_ops->interrupt_service_routine(ha, intr_status);
77 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
78 if (test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
79 test_bit(AF_INTx_ENABLED, &ha->flags))
81 ha->nx_legacy_intr.tgt_mask_reg,
85 intr_status = readl(&ha->reg->ctrl_status);
86 if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
87 /* Service existing interrupt */
88 ha->isp_ops->interrupt_service_routine(ha, intr_status);
89 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
93 ha->mbox_status_count = outCount;
94 for (i = 0; i < outCount; i++)
95 ha->mbox_status[i] = 0;
98 /* Load all mailbox registers, except mailbox 0. */
100 printk("scsi%ld: %s: Cmd ", ha->host_no, __func__);
101 for (i = 0; i < inCount; i++)
102 printk("mb%d=%04x ", i, mbx_cmd[i]);
105 for (i = 1; i < inCount; i++)
106 writel(mbx_cmd[i], &ha->qla4_8xxx_reg->mailbox_in[i]);
107 writel(mbx_cmd[0], &ha->qla4_8xxx_reg->mailbox_in[0]);
108 readl(&ha->qla4_8xxx_reg->mailbox_in[0]);
109 writel(HINT_MBX_INT_PENDING, &ha->qla4_8xxx_reg->hint);
111 /* Load all mailbox registers, except mailbox 0. */
112 for (i = 1; i < inCount; i++)
113 writel(mbx_cmd[i], &ha->reg->mailbox[i]);
115 /* Wakeup firmware */
116 writel(mbx_cmd[0], &ha->reg->mailbox[0]);
117 readl(&ha->reg->mailbox[0]);
118 writel(set_rmask(CSR_INTR_RISC), &ha->reg->ctrl_status);
119 readl(&ha->reg->ctrl_status);
122 spin_unlock_irqrestore(&ha->hardware_lock, flags);
124 /* Wait for completion */
127 * If we don't want status, don't wait for the mailbox command to
128 * complete. For example, MBOX_CMD_RESET_FW doesn't return status,
129 * you must poll the inbound Interrupt Mask for completion.
132 status = QLA_SUCCESS;
137 * Wait for completion: Poll or completion queue
139 if (test_bit(AF_IRQ_ATTACHED, &ha->flags) &&
140 test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
141 test_bit(AF_ONLINE, &ha->flags) &&
142 !test_bit(AF_HBA_GOING_AWAY, &ha->flags)) {
143 /* Do not poll for completion. Use completion queue */
144 set_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
145 wait_for_completion_timeout(&ha->mbx_intr_comp, MBOX_TOV * HZ);
146 clear_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
148 /* Poll for command to complete */
149 wait_count = jiffies + MBOX_TOV * HZ;
150 while (test_bit(AF_MBOX_COMMAND_DONE, &ha->flags) == 0) {
151 if (time_after_eq(jiffies, wait_count))
154 * Service the interrupt.
155 * The ISR will save the mailbox status registers
156 * to a temporary storage location in the adapter
160 spin_lock_irqsave(&ha->hardware_lock, flags);
161 if (is_qla8022(ha)) {
163 readl(&ha->qla4_8xxx_reg->host_int);
164 if (intr_status & ISRX_82XX_RISC_INT) {
165 ha->mbox_status_count = outCount;
167 readl(&ha->qla4_8xxx_reg->host_status);
168 ha->isp_ops->interrupt_service_routine(
170 if (test_bit(AF_INTERRUPTS_ON,
172 test_bit(AF_INTx_ENABLED,
175 ha->nx_legacy_intr.tgt_mask_reg,
179 intr_status = readl(&ha->reg->ctrl_status);
180 if (intr_status & INTR_PENDING) {
182 * Service the interrupt.
183 * The ISR will save the mailbox status
184 * registers to a temporary storage
185 * location in the adapter structure.
187 ha->mbox_status_count = outCount;
188 ha->isp_ops->interrupt_service_routine(
192 spin_unlock_irqrestore(&ha->hardware_lock, flags);
197 /* Check for mailbox timeout. */
198 if (!test_bit(AF_MBOX_COMMAND_DONE, &ha->flags)) {
199 DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
200 " Scheduling Adapter Reset\n", ha->host_no,
202 ha->mailbox_timeout_count++;
204 set_bit(DPC_RESET_HA, &ha->dpc_flags);
209 * Copy the mailbox out registers to the caller's mailbox in/out
212 spin_lock_irqsave(&ha->hardware_lock, flags);
213 for (i = 0; i < outCount; i++)
214 mbx_sts[i] = ha->mbox_status[i];
216 /* Set return status and error flags (if applicable). */
217 switch (ha->mbox_status[0]) {
218 case MBOX_STS_COMMAND_COMPLETE:
219 status = QLA_SUCCESS;
222 case MBOX_STS_INTERMEDIATE_COMPLETION:
223 status = QLA_SUCCESS;
227 DEBUG2( printk("scsi%ld: %s: Cmd = %08X, ISP BUSY\n",
228 ha->host_no, __func__, mbx_cmd[0]));
229 ha->mailbox_timeout_count++;
233 DEBUG2(printk("scsi%ld: %s: **** FAILED, cmd = %08X, "
234 "sts = %08X ****\n", ha->host_no, __func__,
235 mbx_cmd[0], mbx_sts[0]));
238 spin_unlock_irqrestore(&ha->hardware_lock, flags);
241 mutex_lock(&ha->mbox_sem);
242 clear_bit(AF_MBOX_COMMAND, &ha->flags);
243 mutex_unlock(&ha->mbox_sem);
244 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
250 qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
251 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
253 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
254 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
255 mbox_cmd[0] = MBOX_CMD_INITIALIZE_FIRMWARE;
257 mbox_cmd[2] = LSDW(init_fw_cb_dma);
258 mbox_cmd[3] = MSDW(init_fw_cb_dma);
259 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
260 mbox_cmd[5] = (IFCB_VER_MAX << 8) | IFCB_VER_MIN;
262 if (qla4xxx_mailbox_command(ha, 6, 6, mbox_cmd, mbox_sts) !=
264 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
265 "MBOX_CMD_INITIALIZE_FIRMWARE"
266 " failed w/ status %04X\n",
267 ha->host_no, __func__, mbox_sts[0]));
274 qla4xxx_get_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
275 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
277 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
278 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
279 mbox_cmd[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK;
280 mbox_cmd[2] = LSDW(init_fw_cb_dma);
281 mbox_cmd[3] = MSDW(init_fw_cb_dma);
282 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
284 if (qla4xxx_mailbox_command(ha, 5, 5, mbox_cmd, mbox_sts) !=
286 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
287 "MBOX_CMD_GET_INIT_FW_CTRL_BLOCK"
288 " failed w/ status %04X\n",
289 ha->host_no, __func__, mbox_sts[0]));
296 qla4xxx_update_local_ip(struct scsi_qla_host *ha,
297 struct addr_ctrl_blk *init_fw_cb)
299 /* Save IPv4 Address Info */
300 memcpy(ha->ip_address, init_fw_cb->ipv4_addr,
301 min(sizeof(ha->ip_address), sizeof(init_fw_cb->ipv4_addr)));
302 memcpy(ha->subnet_mask, init_fw_cb->ipv4_subnet,
303 min(sizeof(ha->subnet_mask), sizeof(init_fw_cb->ipv4_subnet)));
304 memcpy(ha->gateway, init_fw_cb->ipv4_gw_addr,
305 min(sizeof(ha->gateway), sizeof(init_fw_cb->ipv4_gw_addr)));
307 if (is_ipv6_enabled(ha)) {
308 /* Save IPv6 Address */
309 ha->ipv6_link_local_state = init_fw_cb->ipv6_lnk_lcl_addr_state;
310 ha->ipv6_addr0_state = init_fw_cb->ipv6_addr0_state;
311 ha->ipv6_addr1_state = init_fw_cb->ipv6_addr1_state;
312 ha->ipv6_default_router_state = init_fw_cb->ipv6_dflt_rtr_state;
313 ha->ipv6_link_local_addr.in6_u.u6_addr8[0] = 0xFE;
314 ha->ipv6_link_local_addr.in6_u.u6_addr8[1] = 0x80;
316 memcpy(&ha->ipv6_link_local_addr.in6_u.u6_addr8[8],
317 init_fw_cb->ipv6_if_id,
318 min(sizeof(ha->ipv6_link_local_addr)/2,
319 sizeof(init_fw_cb->ipv6_if_id)));
320 memcpy(&ha->ipv6_addr0, init_fw_cb->ipv6_addr0,
321 min(sizeof(ha->ipv6_addr0),
322 sizeof(init_fw_cb->ipv6_addr0)));
323 memcpy(&ha->ipv6_addr1, init_fw_cb->ipv6_addr1,
324 min(sizeof(ha->ipv6_addr1),
325 sizeof(init_fw_cb->ipv6_addr1)));
326 memcpy(&ha->ipv6_default_router_addr,
327 init_fw_cb->ipv6_dflt_rtr_addr,
328 min(sizeof(ha->ipv6_default_router_addr),
329 sizeof(init_fw_cb->ipv6_dflt_rtr_addr)));
334 qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
337 struct addr_ctrl_blk *init_fw_cb,
338 dma_addr_t init_fw_cb_dma)
340 if (qla4xxx_get_ifcb(ha, mbox_cmd, mbox_sts, init_fw_cb_dma)
342 DEBUG2(printk(KERN_WARNING
343 "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
344 ha->host_no, __func__));
348 DEBUG2(qla4xxx_dump_buffer(init_fw_cb, sizeof(struct addr_ctrl_blk)));
350 /* Save some info in adapter structure. */
351 ha->acb_version = init_fw_cb->acb_version;
352 ha->firmware_options = le16_to_cpu(init_fw_cb->fw_options);
353 ha->tcp_options = le16_to_cpu(init_fw_cb->ipv4_tcp_opts);
354 ha->ipv4_options = le16_to_cpu(init_fw_cb->ipv4_ip_opts);
355 ha->ipv4_addr_state = le16_to_cpu(init_fw_cb->ipv4_addr_state);
356 ha->heartbeat_interval = init_fw_cb->hb_interval;
357 memcpy(ha->name_string, init_fw_cb->iscsi_name,
358 min(sizeof(ha->name_string),
359 sizeof(init_fw_cb->iscsi_name)));
360 /*memcpy(ha->alias, init_fw_cb->Alias,
361 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
363 /* Save Command Line Paramater info */
364 ha->discovery_wait = ql4xdiscoverywait;
366 if (ha->acb_version == ACB_SUPPORTED) {
367 ha->ipv6_options = init_fw_cb->ipv6_opts;
368 ha->ipv6_addl_options = init_fw_cb->ipv6_addtl_opts;
370 qla4xxx_update_local_ip(ha, init_fw_cb);
376 * qla4xxx_initialize_fw_cb - initializes firmware control block.
377 * @ha: Pointer to host adapter structure.
379 int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
381 struct addr_ctrl_blk *init_fw_cb;
382 dma_addr_t init_fw_cb_dma;
383 uint32_t mbox_cmd[MBOX_REG_COUNT];
384 uint32_t mbox_sts[MBOX_REG_COUNT];
385 int status = QLA_ERROR;
387 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
388 sizeof(struct addr_ctrl_blk),
389 &init_fw_cb_dma, GFP_KERNEL);
390 if (init_fw_cb == NULL) {
391 DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
392 ha->host_no, __func__));
393 goto exit_init_fw_cb_no_free;
395 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
397 /* Get Initialize Firmware Control Block. */
398 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
399 memset(&mbox_sts, 0, sizeof(mbox_sts));
401 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
403 dma_free_coherent(&ha->pdev->dev,
404 sizeof(struct addr_ctrl_blk),
405 init_fw_cb, init_fw_cb_dma);
406 goto exit_init_fw_cb;
409 /* Initialize request and response queues. */
410 qla4xxx_init_rings(ha);
412 /* Fill in the request and response queue information. */
413 init_fw_cb->rqq_consumer_idx = cpu_to_le16(ha->request_out);
414 init_fw_cb->compq_producer_idx = cpu_to_le16(ha->response_in);
415 init_fw_cb->rqq_len = __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH);
416 init_fw_cb->compq_len = __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH);
417 init_fw_cb->rqq_addr_lo = cpu_to_le32(LSDW(ha->request_dma));
418 init_fw_cb->rqq_addr_hi = cpu_to_le32(MSDW(ha->request_dma));
419 init_fw_cb->compq_addr_lo = cpu_to_le32(LSDW(ha->response_dma));
420 init_fw_cb->compq_addr_hi = cpu_to_le32(MSDW(ha->response_dma));
421 init_fw_cb->shdwreg_addr_lo = cpu_to_le32(LSDW(ha->shadow_regs_dma));
422 init_fw_cb->shdwreg_addr_hi = cpu_to_le32(MSDW(ha->shadow_regs_dma));
424 /* Set up required options. */
425 init_fw_cb->fw_options |=
426 __constant_cpu_to_le16(FWOPT_SESSION_MODE |
427 FWOPT_INITIATOR_MODE);
428 init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
430 if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
432 DEBUG2(printk(KERN_WARNING
433 "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
434 ha->host_no, __func__));
435 goto exit_init_fw_cb;
438 if (qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0],
439 init_fw_cb, init_fw_cb_dma) != QLA_SUCCESS) {
440 DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
441 ha->host_no, __func__));
442 goto exit_init_fw_cb;
444 status = QLA_SUCCESS;
447 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
448 init_fw_cb, init_fw_cb_dma);
449 exit_init_fw_cb_no_free:
454 * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
455 * @ha: Pointer to host adapter structure.
457 int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host * ha)
459 struct addr_ctrl_blk *init_fw_cb;
460 dma_addr_t init_fw_cb_dma;
461 uint32_t mbox_cmd[MBOX_REG_COUNT];
462 uint32_t mbox_sts[MBOX_REG_COUNT];
464 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
465 sizeof(struct addr_ctrl_blk),
466 &init_fw_cb_dma, GFP_KERNEL);
467 if (init_fw_cb == NULL) {
468 printk("scsi%ld: %s: Unable to alloc init_cb\n", ha->host_no,
473 /* Get Initialize Firmware Control Block. */
474 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
475 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
477 DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
478 ha->host_no, __func__));
479 dma_free_coherent(&ha->pdev->dev,
480 sizeof(struct addr_ctrl_blk),
481 init_fw_cb, init_fw_cb_dma);
485 /* Save IP Address. */
486 qla4xxx_update_local_ip(ha, init_fw_cb);
487 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
488 init_fw_cb, init_fw_cb_dma);
494 * qla4xxx_get_firmware_state - gets firmware state of HBA
495 * @ha: Pointer to host adapter structure.
497 int qla4xxx_get_firmware_state(struct scsi_qla_host * ha)
499 uint32_t mbox_cmd[MBOX_REG_COUNT];
500 uint32_t mbox_sts[MBOX_REG_COUNT];
502 /* Get firmware version */
503 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
504 memset(&mbox_sts, 0, sizeof(mbox_sts));
506 mbox_cmd[0] = MBOX_CMD_GET_FW_STATE;
508 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 4, &mbox_cmd[0], &mbox_sts[0]) !=
510 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
511 "status %04X\n", ha->host_no, __func__,
515 ha->firmware_state = mbox_sts[1];
516 ha->board_id = mbox_sts[2];
517 ha->addl_fw_state = mbox_sts[3];
518 DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
519 ha->host_no, __func__, ha->firmware_state);)
525 * qla4xxx_get_firmware_status - retrieves firmware status
526 * @ha: Pointer to host adapter structure.
528 int qla4xxx_get_firmware_status(struct scsi_qla_host * ha)
530 uint32_t mbox_cmd[MBOX_REG_COUNT];
531 uint32_t mbox_sts[MBOX_REG_COUNT];
533 /* Get firmware version */
534 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
535 memset(&mbox_sts, 0, sizeof(mbox_sts));
537 mbox_cmd[0] = MBOX_CMD_GET_FW_STATUS;
539 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
541 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
542 "status %04X\n", ha->host_no, __func__,
547 ql4_printk(KERN_INFO, ha, "%ld firmare IOCBs available (%d).\n",
548 ha->host_no, mbox_cmd[2]);
554 * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
555 * @ha: Pointer to host adapter structure.
556 * @fw_ddb_index: Firmware's device database index
557 * @fw_ddb_entry: Pointer to firmware's device database entry structure
558 * @num_valid_ddb_entries: Pointer to number of valid ddb entries
559 * @next_ddb_index: Pointer to next valid device database index
560 * @fw_ddb_device_state: Pointer to device state
562 int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
563 uint16_t fw_ddb_index,
564 struct dev_db_entry *fw_ddb_entry,
565 dma_addr_t fw_ddb_entry_dma,
566 uint32_t *num_valid_ddb_entries,
567 uint32_t *next_ddb_index,
568 uint32_t *fw_ddb_device_state,
569 uint32_t *conn_err_detail,
570 uint16_t *tcp_source_port_num,
571 uint16_t *connection_id)
573 int status = QLA_ERROR;
575 uint32_t mbox_cmd[MBOX_REG_COUNT];
576 uint32_t mbox_sts[MBOX_REG_COUNT];
578 /* Make sure the device index is valid */
579 if (fw_ddb_index >= MAX_DDB_ENTRIES) {
580 DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
581 ha->host_no, __func__, fw_ddb_index));
584 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
585 memset(&mbox_sts, 0, sizeof(mbox_sts));
587 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY;
588 mbox_cmd[1] = (uint32_t) fw_ddb_index;
589 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
590 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
591 mbox_cmd[4] = sizeof(struct dev_db_entry);
593 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 7, &mbox_cmd[0], &mbox_sts[0]) ==
595 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
596 " with status 0x%04X\n", ha->host_no, __func__,
600 if (fw_ddb_index != mbox_sts[1]) {
601 DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
602 ha->host_no, __func__, fw_ddb_index,
607 options = le16_to_cpu(fw_ddb_entry->options);
608 if (options & DDB_OPT_IPV6_DEVICE) {
609 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
610 "Next %d State %04x ConnErr %08x %pI6 "
611 ":%04d \"%s\"\n", __func__, fw_ddb_index,
612 mbox_sts[0], mbox_sts[2], mbox_sts[3],
613 mbox_sts[4], mbox_sts[5],
614 fw_ddb_entry->ip_addr,
615 le16_to_cpu(fw_ddb_entry->port),
616 fw_ddb_entry->iscsi_name);
618 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
619 "Next %d State %04x ConnErr %08x %pI4 "
620 ":%04d \"%s\"\n", __func__, fw_ddb_index,
621 mbox_sts[0], mbox_sts[2], mbox_sts[3],
622 mbox_sts[4], mbox_sts[5],
623 fw_ddb_entry->ip_addr,
624 le16_to_cpu(fw_ddb_entry->port),
625 fw_ddb_entry->iscsi_name);
628 if (num_valid_ddb_entries)
629 *num_valid_ddb_entries = mbox_sts[2];
631 *next_ddb_index = mbox_sts[3];
632 if (fw_ddb_device_state)
633 *fw_ddb_device_state = mbox_sts[4];
636 * RA: This mailbox has been changed to pass connection error and
637 * details. Its true for ISP4010 as per Version E - Not sure when it
638 * was changed. Get the time2wait from the fw_dd_entry field :
639 * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
643 *conn_err_detail = mbox_sts[5];
644 if (tcp_source_port_num)
645 *tcp_source_port_num = (uint16_t) (mbox_sts[6] >> 16);
647 *connection_id = (uint16_t) mbox_sts[6] & 0x00FF;
648 status = QLA_SUCCESS;
655 * qla4xxx_set_fwddb_entry - sets a ddb entry.
656 * @ha: Pointer to host adapter structure.
657 * @fw_ddb_index: Firmware's device database index
658 * @fw_ddb_entry: Pointer to firmware's ddb entry structure, or NULL.
660 * This routine initializes or updates the adapter's device database
661 * entry for the specified device. It also triggers a login for the
662 * specified device. Therefore, it may also be used as a secondary
663 * login routine when a NULL pointer is specified for the fw_ddb_entry.
665 int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
666 dma_addr_t fw_ddb_entry_dma)
668 uint32_t mbox_cmd[MBOX_REG_COUNT];
669 uint32_t mbox_sts[MBOX_REG_COUNT];
672 /* Do not wait for completion. The firmware will send us an
673 * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
675 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
676 memset(&mbox_sts, 0, sizeof(mbox_sts));
678 mbox_cmd[0] = MBOX_CMD_SET_DATABASE_ENTRY;
679 mbox_cmd[1] = (uint32_t) fw_ddb_index;
680 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
681 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
682 mbox_cmd[4] = sizeof(struct dev_db_entry);
684 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
686 DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
687 ha->host_no, __func__, status, mbox_sts[0], mbox_sts[4]);)
693 * qla4xxx_get_crash_record - retrieves crash record.
694 * @ha: Pointer to host adapter structure.
696 * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
698 void qla4xxx_get_crash_record(struct scsi_qla_host * ha)
700 uint32_t mbox_cmd[MBOX_REG_COUNT];
701 uint32_t mbox_sts[MBOX_REG_COUNT];
702 struct crash_record *crash_record = NULL;
703 dma_addr_t crash_record_dma = 0;
704 uint32_t crash_record_size = 0;
706 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
707 memset(&mbox_sts, 0, sizeof(mbox_cmd));
709 /* Get size of crash record. */
710 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
712 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
714 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
715 ha->host_no, __func__));
716 goto exit_get_crash_record;
718 crash_record_size = mbox_sts[4];
719 if (crash_record_size == 0) {
720 DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
721 ha->host_no, __func__));
722 goto exit_get_crash_record;
725 /* Alloc Memory for Crash Record. */
726 crash_record = dma_alloc_coherent(&ha->pdev->dev, crash_record_size,
727 &crash_record_dma, GFP_KERNEL);
728 if (crash_record == NULL)
729 goto exit_get_crash_record;
731 /* Get Crash Record. */
732 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
733 memset(&mbox_sts, 0, sizeof(mbox_cmd));
735 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
736 mbox_cmd[2] = LSDW(crash_record_dma);
737 mbox_cmd[3] = MSDW(crash_record_dma);
738 mbox_cmd[4] = crash_record_size;
740 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
742 goto exit_get_crash_record;
744 /* Dump Crash Record. */
746 exit_get_crash_record:
748 dma_free_coherent(&ha->pdev->dev, crash_record_size,
749 crash_record, crash_record_dma);
753 * qla4xxx_get_conn_event_log - retrieves connection event log
754 * @ha: Pointer to host adapter structure.
756 void qla4xxx_get_conn_event_log(struct scsi_qla_host * ha)
758 uint32_t mbox_cmd[MBOX_REG_COUNT];
759 uint32_t mbox_sts[MBOX_REG_COUNT];
760 struct conn_event_log_entry *event_log = NULL;
761 dma_addr_t event_log_dma = 0;
762 uint32_t event_log_size = 0;
763 uint32_t num_valid_entries;
764 uint32_t oldest_entry = 0;
765 uint32_t max_event_log_entries;
769 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
770 memset(&mbox_sts, 0, sizeof(mbox_cmd));
772 /* Get size of crash record. */
773 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
775 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
777 goto exit_get_event_log;
779 event_log_size = mbox_sts[4];
780 if (event_log_size == 0)
781 goto exit_get_event_log;
783 /* Alloc Memory for Crash Record. */
784 event_log = dma_alloc_coherent(&ha->pdev->dev, event_log_size,
785 &event_log_dma, GFP_KERNEL);
786 if (event_log == NULL)
787 goto exit_get_event_log;
789 /* Get Crash Record. */
790 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
791 memset(&mbox_sts, 0, sizeof(mbox_cmd));
793 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
794 mbox_cmd[2] = LSDW(event_log_dma);
795 mbox_cmd[3] = MSDW(event_log_dma);
797 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
799 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
800 "log!\n", ha->host_no, __func__));
801 goto exit_get_event_log;
804 /* Dump Event Log. */
805 num_valid_entries = mbox_sts[1];
807 max_event_log_entries = event_log_size /
808 sizeof(struct conn_event_log_entry);
810 if (num_valid_entries > max_event_log_entries)
811 oldest_entry = num_valid_entries % max_event_log_entries;
813 DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
814 ha->host_no, num_valid_entries));
816 if (ql4xextended_error_logging == 3) {
817 if (oldest_entry == 0) {
818 /* Circular Buffer has not wrapped around */
819 for (i=0; i < num_valid_entries; i++) {
820 qla4xxx_dump_buffer((uint8_t *)event_log+
821 (i*sizeof(*event_log)),
826 /* Circular Buffer has wrapped around -
827 * display accordingly*/
828 for (i=oldest_entry; i < max_event_log_entries; i++) {
829 qla4xxx_dump_buffer((uint8_t *)event_log+
830 (i*sizeof(*event_log)),
833 for (i=0; i < oldest_entry; i++) {
834 qla4xxx_dump_buffer((uint8_t *)event_log+
835 (i*sizeof(*event_log)),
843 dma_free_coherent(&ha->pdev->dev, event_log_size, event_log,
848 * qla4xxx_abort_task - issues Abort Task
849 * @ha: Pointer to host adapter structure.
850 * @srb: Pointer to srb entry
852 * This routine performs a LUN RESET on the specified target/lun.
853 * The caller must ensure that the ddb_entry and lun_entry pointers
854 * are valid before calling this routine.
856 int qla4xxx_abort_task(struct scsi_qla_host *ha, struct srb *srb)
858 uint32_t mbox_cmd[MBOX_REG_COUNT];
859 uint32_t mbox_sts[MBOX_REG_COUNT];
860 struct scsi_cmnd *cmd = srb->cmd;
861 int status = QLA_SUCCESS;
862 unsigned long flags = 0;
866 * Send abort task command to ISP, so that the ISP will return
867 * request with ABORT status
869 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
870 memset(&mbox_sts, 0, sizeof(mbox_sts));
872 spin_lock_irqsave(&ha->hardware_lock, flags);
873 index = (unsigned long)(unsigned char *)cmd->host_scribble;
874 spin_unlock_irqrestore(&ha->hardware_lock, flags);
876 /* Firmware already posted completion on response queue */
877 if (index == MAX_SRBS)
880 mbox_cmd[0] = MBOX_CMD_ABORT_TASK;
881 mbox_cmd[1] = srb->fw_ddb_index;
883 /* Immediate Command Enable */
886 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
888 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE) {
891 DEBUG2(printk(KERN_WARNING "scsi%ld:%d:%d: abort task FAILED: "
892 "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
893 ha->host_no, cmd->device->id, cmd->device->lun, mbox_sts[0],
894 mbox_sts[1], mbox_sts[2], mbox_sts[3], mbox_sts[4]));
901 * qla4xxx_reset_lun - issues LUN Reset
902 * @ha: Pointer to host adapter structure.
903 * @ddb_entry: Pointer to device database entry
906 * This routine performs a LUN RESET on the specified target/lun.
907 * The caller must ensure that the ddb_entry and lun_entry pointers
908 * are valid before calling this routine.
910 int qla4xxx_reset_lun(struct scsi_qla_host * ha, struct ddb_entry * ddb_entry,
913 uint32_t mbox_cmd[MBOX_REG_COUNT];
914 uint32_t mbox_sts[MBOX_REG_COUNT];
915 int status = QLA_SUCCESS;
917 DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha->host_no,
918 ddb_entry->fw_ddb_index, lun));
921 * Send lun reset command to ISP, so that the ISP will return all
922 * outstanding requests with RESET status
924 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
925 memset(&mbox_sts, 0, sizeof(mbox_sts));
927 mbox_cmd[0] = MBOX_CMD_LUN_RESET;
928 mbox_cmd[1] = ddb_entry->fw_ddb_index;
929 mbox_cmd[2] = lun << 8;
930 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
932 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]);
933 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
934 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
941 * qla4xxx_reset_target - issues target Reset
942 * @ha: Pointer to host adapter structure.
943 * @db_entry: Pointer to device database entry
944 * @un_entry: Pointer to lun entry structure
946 * This routine performs a TARGET RESET on the specified target.
947 * The caller must ensure that the ddb_entry pointers
948 * are valid before calling this routine.
950 int qla4xxx_reset_target(struct scsi_qla_host *ha,
951 struct ddb_entry *ddb_entry)
953 uint32_t mbox_cmd[MBOX_REG_COUNT];
954 uint32_t mbox_sts[MBOX_REG_COUNT];
955 int status = QLA_SUCCESS;
957 DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha->host_no,
958 ddb_entry->fw_ddb_index));
961 * Send target reset command to ISP, so that the ISP will return all
962 * outstanding requests with RESET status
964 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
965 memset(&mbox_sts, 0, sizeof(mbox_sts));
967 mbox_cmd[0] = MBOX_CMD_TARGET_WARM_RESET;
968 mbox_cmd[1] = ddb_entry->fw_ddb_index;
969 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
971 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
973 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
974 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
980 int qla4xxx_get_flash(struct scsi_qla_host * ha, dma_addr_t dma_addr,
981 uint32_t offset, uint32_t len)
983 uint32_t mbox_cmd[MBOX_REG_COUNT];
984 uint32_t mbox_sts[MBOX_REG_COUNT];
986 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
987 memset(&mbox_sts, 0, sizeof(mbox_sts));
989 mbox_cmd[0] = MBOX_CMD_READ_FLASH;
990 mbox_cmd[1] = LSDW(dma_addr);
991 mbox_cmd[2] = MSDW(dma_addr);
992 mbox_cmd[3] = offset;
995 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0], &mbox_sts[0]) !=
997 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
998 "status %04X %04X, offset %08x, len %08x\n", ha->host_no,
999 __func__, mbox_sts[0], mbox_sts[1], offset, len));
1006 * qla4xxx_get_fw_version - gets firmware version
1007 * @ha: Pointer to host adapter structure.
1009 * Retrieves the firmware version on HBA. In QLA4010, mailboxes 2 & 3 may
1010 * hold an address for data. Make sure that we write 0 to those mailboxes,
1013 int qla4xxx_get_fw_version(struct scsi_qla_host * ha)
1015 uint32_t mbox_cmd[MBOX_REG_COUNT];
1016 uint32_t mbox_sts[MBOX_REG_COUNT];
1018 /* Get firmware version. */
1019 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1020 memset(&mbox_sts, 0, sizeof(mbox_sts));
1022 mbox_cmd[0] = MBOX_CMD_ABOUT_FW;
1024 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
1026 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_ABOUT_FW failed w/ "
1027 "status %04X\n", ha->host_no, __func__, mbox_sts[0]));
1031 /* Save firmware version information. */
1032 ha->firmware_version[0] = mbox_sts[1];
1033 ha->firmware_version[1] = mbox_sts[2];
1034 ha->patch_number = mbox_sts[3];
1035 ha->build_number = mbox_sts[4];
1040 static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha,
1041 dma_addr_t dma_addr)
1043 uint32_t mbox_cmd[MBOX_REG_COUNT];
1044 uint32_t mbox_sts[MBOX_REG_COUNT];
1046 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1047 memset(&mbox_sts, 0, sizeof(mbox_sts));
1049 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS;
1050 mbox_cmd[2] = LSDW(dma_addr);
1051 mbox_cmd[3] = MSDW(dma_addr);
1053 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]) !=
1055 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1056 ha->host_no, __func__, mbox_sts[0]));
1062 static int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t *ddb_index)
1064 uint32_t mbox_cmd[MBOX_REG_COUNT];
1065 uint32_t mbox_sts[MBOX_REG_COUNT];
1067 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1068 memset(&mbox_sts, 0, sizeof(mbox_sts));
1070 mbox_cmd[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY;
1071 mbox_cmd[1] = MAX_PRST_DEV_DB_ENTRIES;
1073 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
1075 if (mbox_sts[0] == MBOX_STS_COMMAND_ERROR) {
1076 *ddb_index = mbox_sts[2];
1078 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1079 ha->host_no, __func__, mbox_sts[0]));
1083 *ddb_index = MAX_PRST_DEV_DB_ENTRIES;
1090 int qla4xxx_send_tgts(struct scsi_qla_host *ha, char *ip, uint16_t port)
1092 struct dev_db_entry *fw_ddb_entry;
1093 dma_addr_t fw_ddb_entry_dma;
1095 int ret_val = QLA_SUCCESS;
1098 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
1099 sizeof(*fw_ddb_entry),
1100 &fw_ddb_entry_dma, GFP_KERNEL);
1101 if (!fw_ddb_entry) {
1102 DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
1103 ha->host_no, __func__));
1104 ret_val = QLA_ERROR;
1105 goto exit_send_tgts_no_free;
1108 ret_val = qla4xxx_get_default_ddb(ha, fw_ddb_entry_dma);
1109 if (ret_val != QLA_SUCCESS)
1110 goto exit_send_tgts;
1112 ret_val = qla4xxx_req_ddb_entry(ha, &ddb_index);
1113 if (ret_val != QLA_SUCCESS)
1114 goto exit_send_tgts;
1116 memset(fw_ddb_entry->iscsi_alias, 0,
1117 sizeof(fw_ddb_entry->iscsi_alias));
1119 memset(fw_ddb_entry->iscsi_name, 0,
1120 sizeof(fw_ddb_entry->iscsi_name));
1122 memset(fw_ddb_entry->ip_addr, 0, sizeof(fw_ddb_entry->ip_addr));
1123 memset(fw_ddb_entry->tgt_addr, 0,
1124 sizeof(fw_ddb_entry->tgt_addr));
1126 fw_ddb_entry->options = (DDB_OPT_DISC_SESSION | DDB_OPT_TARGET);
1127 fw_ddb_entry->port = cpu_to_le16(ntohs(port));
1129 fw_ddb_entry->ip_addr[0] = *ip;
1130 fw_ddb_entry->ip_addr[1] = *(ip + 1);
1131 fw_ddb_entry->ip_addr[2] = *(ip + 2);
1132 fw_ddb_entry->ip_addr[3] = *(ip + 3);
1134 ret_val = qla4xxx_set_ddb_entry(ha, ddb_index, fw_ddb_entry_dma);
1137 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1138 fw_ddb_entry, fw_ddb_entry_dma);
1139 exit_send_tgts_no_free: