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 /* Mailbox code active */
52 wait_count
= MBOX_TOV
* 100;
54 while (wait_count
--) {
55 mutex_lock(&ha
->mbox_sem
);
56 if (!test_bit(AF_MBOX_COMMAND
, &ha
->flags
)) {
57 set_bit(AF_MBOX_COMMAND
, &ha
->flags
);
58 mutex_unlock(&ha
->mbox_sem
);
61 mutex_unlock(&ha
->mbox_sem
);
63 DEBUG2(printk("scsi%ld: %s: mbox_sem failed\n",
64 ha
->host_no
, __func__
));
70 /* To prevent overwriting mailbox registers for a command that has
71 * not yet been serviced, check to see if an active command
72 * (AEN, IOCB, etc.) is interrupting, then service it.
73 * -----------------------------------------------------------------
75 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
78 intr_status
= readl(&ha
->qla4_8xxx_reg
->host_int
);
79 if (intr_status
& ISRX_82XX_RISC_INT
) {
80 /* Service existing interrupt */
81 DEBUG2(printk("scsi%ld: %s: "
82 "servicing existing interrupt\n",
83 ha
->host_no
, __func__
));
84 intr_status
= readl(&ha
->qla4_8xxx_reg
->host_status
);
85 ha
->isp_ops
->interrupt_service_routine(ha
, intr_status
);
86 clear_bit(AF_MBOX_COMMAND_DONE
, &ha
->flags
);
87 if (test_bit(AF_INTERRUPTS_ON
, &ha
->flags
) &&
88 test_bit(AF_INTx_ENABLED
, &ha
->flags
))
90 ha
->nx_legacy_intr
.tgt_mask_reg
,
94 intr_status
= readl(&ha
->reg
->ctrl_status
);
95 if (intr_status
& CSR_SCSI_PROCESSOR_INTR
) {
96 /* Service existing interrupt */
97 ha
->isp_ops
->interrupt_service_routine(ha
, intr_status
);
98 clear_bit(AF_MBOX_COMMAND_DONE
, &ha
->flags
);
102 ha
->mbox_status_count
= outCount
;
103 for (i
= 0; i
< outCount
; i
++)
104 ha
->mbox_status
[i
] = 0;
106 if (is_qla8022(ha
)) {
107 /* Load all mailbox registers, except mailbox 0. */
109 printk("scsi%ld: %s: Cmd ", ha
->host_no
, __func__
);
110 for (i
= 0; i
< inCount
; i
++)
111 printk("mb%d=%04x ", i
, mbx_cmd
[i
]);
114 for (i
= 1; i
< inCount
; i
++)
115 writel(mbx_cmd
[i
], &ha
->qla4_8xxx_reg
->mailbox_in
[i
]);
116 writel(mbx_cmd
[0], &ha
->qla4_8xxx_reg
->mailbox_in
[0]);
117 readl(&ha
->qla4_8xxx_reg
->mailbox_in
[0]);
118 writel(HINT_MBX_INT_PENDING
, &ha
->qla4_8xxx_reg
->hint
);
120 /* Load all mailbox registers, except mailbox 0. */
121 for (i
= 1; i
< inCount
; i
++)
122 writel(mbx_cmd
[i
], &ha
->reg
->mailbox
[i
]);
124 /* Wakeup firmware */
125 writel(mbx_cmd
[0], &ha
->reg
->mailbox
[0]);
126 readl(&ha
->reg
->mailbox
[0]);
127 writel(set_rmask(CSR_INTR_RISC
), &ha
->reg
->ctrl_status
);
128 readl(&ha
->reg
->ctrl_status
);
131 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
133 /* Wait for completion */
136 * If we don't want status, don't wait for the mailbox command to
137 * complete. For example, MBOX_CMD_RESET_FW doesn't return status,
138 * you must poll the inbound Interrupt Mask for completion.
141 status
= QLA_SUCCESS
;
146 * Wait for completion: Poll or completion queue
148 if (test_bit(AF_IRQ_ATTACHED
, &ha
->flags
) &&
149 test_bit(AF_INTERRUPTS_ON
, &ha
->flags
) &&
150 test_bit(AF_ONLINE
, &ha
->flags
) &&
151 !test_bit(AF_HBA_GOING_AWAY
, &ha
->flags
)) {
152 /* Do not poll for completion. Use completion queue */
153 set_bit(AF_MBOX_COMMAND_NOPOLL
, &ha
->flags
);
154 wait_for_completion_timeout(&ha
->mbx_intr_comp
, MBOX_TOV
* HZ
);
155 clear_bit(AF_MBOX_COMMAND_NOPOLL
, &ha
->flags
);
157 /* Poll for command to complete */
158 wait_count
= jiffies
+ MBOX_TOV
* HZ
;
159 while (test_bit(AF_MBOX_COMMAND_DONE
, &ha
->flags
) == 0) {
160 if (time_after_eq(jiffies
, wait_count
))
163 * Service the interrupt.
164 * The ISR will save the mailbox status registers
165 * to a temporary storage location in the adapter
169 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
170 if (is_qla8022(ha
)) {
172 readl(&ha
->qla4_8xxx_reg
->host_int
);
173 if (intr_status
& ISRX_82XX_RISC_INT
) {
174 ha
->mbox_status_count
= outCount
;
176 readl(&ha
->qla4_8xxx_reg
->host_status
);
177 ha
->isp_ops
->interrupt_service_routine(
179 if (test_bit(AF_INTERRUPTS_ON
,
181 test_bit(AF_INTx_ENABLED
,
184 ha
->nx_legacy_intr
.tgt_mask_reg
,
188 intr_status
= readl(&ha
->reg
->ctrl_status
);
189 if (intr_status
& INTR_PENDING
) {
191 * Service the interrupt.
192 * The ISR will save the mailbox status
193 * registers to a temporary storage
194 * location in the adapter structure.
196 ha
->mbox_status_count
= outCount
;
197 ha
->isp_ops
->interrupt_service_routine(
201 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
206 /* Check for mailbox timeout. */
207 if (!test_bit(AF_MBOX_COMMAND_DONE
, &ha
->flags
)) {
208 if (is_qla8022(ha
) &&
209 test_bit(AF_FW_RECOVERY
, &ha
->flags
)) {
210 DEBUG2(ql4_printk(KERN_INFO
, ha
,
211 "scsi%ld: %s: prematurely completing mbx cmd as "
212 "firmware recovery detected\n",
213 ha
->host_no
, __func__
));
216 DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
217 " Scheduling Adapter Reset\n", ha
->host_no
,
219 ha
->mailbox_timeout_count
++;
221 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
226 * Copy the mailbox out registers to the caller's mailbox in/out
229 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
230 for (i
= 0; i
< outCount
; i
++)
231 mbx_sts
[i
] = ha
->mbox_status
[i
];
233 /* Set return status and error flags (if applicable). */
234 switch (ha
->mbox_status
[0]) {
235 case MBOX_STS_COMMAND_COMPLETE
:
236 status
= QLA_SUCCESS
;
239 case MBOX_STS_INTERMEDIATE_COMPLETION
:
240 status
= QLA_SUCCESS
;
244 DEBUG2( printk("scsi%ld: %s: Cmd = %08X, ISP BUSY\n",
245 ha
->host_no
, __func__
, mbx_cmd
[0]));
246 ha
->mailbox_timeout_count
++;
250 DEBUG2(printk("scsi%ld: %s: **** FAILED, cmd = %08X, "
251 "sts = %08X ****\n", ha
->host_no
, __func__
,
252 mbx_cmd
[0], mbx_sts
[0]));
255 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
258 mutex_lock(&ha
->mbox_sem
);
259 clear_bit(AF_MBOX_COMMAND
, &ha
->flags
);
260 mutex_unlock(&ha
->mbox_sem
);
261 clear_bit(AF_MBOX_COMMAND_DONE
, &ha
->flags
);
266 void qla4xxx_mailbox_premature_completion(struct scsi_qla_host
*ha
)
268 set_bit(AF_FW_RECOVERY
, &ha
->flags
);
269 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: set FW RECOVERY!\n",
270 ha
->host_no
, __func__
);
272 if (test_bit(AF_MBOX_COMMAND
, &ha
->flags
)) {
273 if (test_bit(AF_MBOX_COMMAND_NOPOLL
, &ha
->flags
)) {
274 complete(&ha
->mbx_intr_comp
);
275 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: Due to fw "
276 "recovery, doing premature completion of "
277 "mbx cmd\n", ha
->host_no
, __func__
);
280 set_bit(AF_MBOX_COMMAND_DONE
, &ha
->flags
);
281 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: Due to fw "
282 "recovery, doing premature completion of "
283 "polling mbx cmd\n", ha
->host_no
, __func__
);
289 qla4xxx_set_ifcb(struct scsi_qla_host
*ha
, uint32_t *mbox_cmd
,
290 uint32_t *mbox_sts
, dma_addr_t init_fw_cb_dma
)
292 memset(mbox_cmd
, 0, sizeof(mbox_cmd
[0]) * MBOX_REG_COUNT
);
293 memset(mbox_sts
, 0, sizeof(mbox_sts
[0]) * MBOX_REG_COUNT
);
294 mbox_cmd
[0] = MBOX_CMD_INITIALIZE_FIRMWARE
;
296 mbox_cmd
[2] = LSDW(init_fw_cb_dma
);
297 mbox_cmd
[3] = MSDW(init_fw_cb_dma
);
298 mbox_cmd
[4] = sizeof(struct addr_ctrl_blk
);
299 mbox_cmd
[5] = (IFCB_VER_MAX
<< 8) | IFCB_VER_MIN
;
301 if (qla4xxx_mailbox_command(ha
, 6, 6, mbox_cmd
, mbox_sts
) !=
303 DEBUG2(printk(KERN_WARNING
"scsi%ld: %s: "
304 "MBOX_CMD_INITIALIZE_FIRMWARE"
305 " failed w/ status %04X\n",
306 ha
->host_no
, __func__
, mbox_sts
[0]));
313 qla4xxx_get_ifcb(struct scsi_qla_host
*ha
, uint32_t *mbox_cmd
,
314 uint32_t *mbox_sts
, dma_addr_t init_fw_cb_dma
)
316 memset(mbox_cmd
, 0, sizeof(mbox_cmd
[0]) * MBOX_REG_COUNT
);
317 memset(mbox_sts
, 0, sizeof(mbox_sts
[0]) * MBOX_REG_COUNT
);
318 mbox_cmd
[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK
;
319 mbox_cmd
[2] = LSDW(init_fw_cb_dma
);
320 mbox_cmd
[3] = MSDW(init_fw_cb_dma
);
321 mbox_cmd
[4] = sizeof(struct addr_ctrl_blk
);
323 if (qla4xxx_mailbox_command(ha
, 5, 5, mbox_cmd
, mbox_sts
) !=
325 DEBUG2(printk(KERN_WARNING
"scsi%ld: %s: "
326 "MBOX_CMD_GET_INIT_FW_CTRL_BLOCK"
327 " failed w/ status %04X\n",
328 ha
->host_no
, __func__
, mbox_sts
[0]));
335 qla4xxx_update_local_ip(struct scsi_qla_host
*ha
,
336 struct addr_ctrl_blk
*init_fw_cb
)
338 /* Save IPv4 Address Info */
339 memcpy(ha
->ip_address
, init_fw_cb
->ipv4_addr
,
340 min(sizeof(ha
->ip_address
), sizeof(init_fw_cb
->ipv4_addr
)));
341 memcpy(ha
->subnet_mask
, init_fw_cb
->ipv4_subnet
,
342 min(sizeof(ha
->subnet_mask
), sizeof(init_fw_cb
->ipv4_subnet
)));
343 memcpy(ha
->gateway
, init_fw_cb
->ipv4_gw_addr
,
344 min(sizeof(ha
->gateway
), sizeof(init_fw_cb
->ipv4_gw_addr
)));
346 if (is_ipv6_enabled(ha
)) {
347 /* Save IPv6 Address */
348 ha
->ipv6_link_local_state
= init_fw_cb
->ipv6_lnk_lcl_addr_state
;
349 ha
->ipv6_addr0_state
= init_fw_cb
->ipv6_addr0_state
;
350 ha
->ipv6_addr1_state
= init_fw_cb
->ipv6_addr1_state
;
351 ha
->ipv6_default_router_state
= init_fw_cb
->ipv6_dflt_rtr_state
;
352 ha
->ipv6_link_local_addr
.in6_u
.u6_addr8
[0] = 0xFE;
353 ha
->ipv6_link_local_addr
.in6_u
.u6_addr8
[1] = 0x80;
355 memcpy(&ha
->ipv6_link_local_addr
.in6_u
.u6_addr8
[8],
356 init_fw_cb
->ipv6_if_id
,
357 min(sizeof(ha
->ipv6_link_local_addr
)/2,
358 sizeof(init_fw_cb
->ipv6_if_id
)));
359 memcpy(&ha
->ipv6_addr0
, init_fw_cb
->ipv6_addr0
,
360 min(sizeof(ha
->ipv6_addr0
),
361 sizeof(init_fw_cb
->ipv6_addr0
)));
362 memcpy(&ha
->ipv6_addr1
, init_fw_cb
->ipv6_addr1
,
363 min(sizeof(ha
->ipv6_addr1
),
364 sizeof(init_fw_cb
->ipv6_addr1
)));
365 memcpy(&ha
->ipv6_default_router_addr
,
366 init_fw_cb
->ipv6_dflt_rtr_addr
,
367 min(sizeof(ha
->ipv6_default_router_addr
),
368 sizeof(init_fw_cb
->ipv6_dflt_rtr_addr
)));
373 qla4xxx_update_local_ifcb(struct scsi_qla_host
*ha
,
376 struct addr_ctrl_blk
*init_fw_cb
,
377 dma_addr_t init_fw_cb_dma
)
379 if (qla4xxx_get_ifcb(ha
, mbox_cmd
, mbox_sts
, init_fw_cb_dma
)
381 DEBUG2(printk(KERN_WARNING
382 "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
383 ha
->host_no
, __func__
));
387 DEBUG2(qla4xxx_dump_buffer(init_fw_cb
, sizeof(struct addr_ctrl_blk
)));
389 /* Save some info in adapter structure. */
390 ha
->acb_version
= init_fw_cb
->acb_version
;
391 ha
->firmware_options
= le16_to_cpu(init_fw_cb
->fw_options
);
392 ha
->tcp_options
= le16_to_cpu(init_fw_cb
->ipv4_tcp_opts
);
393 ha
->ipv4_options
= le16_to_cpu(init_fw_cb
->ipv4_ip_opts
);
394 ha
->ipv4_addr_state
= le16_to_cpu(init_fw_cb
->ipv4_addr_state
);
395 ha
->heartbeat_interval
= init_fw_cb
->hb_interval
;
396 memcpy(ha
->name_string
, init_fw_cb
->iscsi_name
,
397 min(sizeof(ha
->name_string
),
398 sizeof(init_fw_cb
->iscsi_name
)));
399 /*memcpy(ha->alias, init_fw_cb->Alias,
400 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
402 /* Save Command Line Paramater info */
403 ha
->discovery_wait
= ql4xdiscoverywait
;
405 if (ha
->acb_version
== ACB_SUPPORTED
) {
406 ha
->ipv6_options
= init_fw_cb
->ipv6_opts
;
407 ha
->ipv6_addl_options
= init_fw_cb
->ipv6_addtl_opts
;
409 qla4xxx_update_local_ip(ha
, init_fw_cb
);
415 * qla4xxx_initialize_fw_cb - initializes firmware control block.
416 * @ha: Pointer to host adapter structure.
418 int qla4xxx_initialize_fw_cb(struct scsi_qla_host
* ha
)
420 struct addr_ctrl_blk
*init_fw_cb
;
421 dma_addr_t init_fw_cb_dma
;
422 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
423 uint32_t mbox_sts
[MBOX_REG_COUNT
];
424 int status
= QLA_ERROR
;
426 init_fw_cb
= dma_alloc_coherent(&ha
->pdev
->dev
,
427 sizeof(struct addr_ctrl_blk
),
428 &init_fw_cb_dma
, GFP_KERNEL
);
429 if (init_fw_cb
== NULL
) {
430 DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
431 ha
->host_no
, __func__
));
432 goto exit_init_fw_cb_no_free
;
434 memset(init_fw_cb
, 0, sizeof(struct addr_ctrl_blk
));
436 /* Get Initialize Firmware Control Block. */
437 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
438 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
440 if (qla4xxx_get_ifcb(ha
, &mbox_cmd
[0], &mbox_sts
[0], init_fw_cb_dma
) !=
442 dma_free_coherent(&ha
->pdev
->dev
,
443 sizeof(struct addr_ctrl_blk
),
444 init_fw_cb
, init_fw_cb_dma
);
445 goto exit_init_fw_cb
;
448 /* Initialize request and response queues. */
449 qla4xxx_init_rings(ha
);
451 /* Fill in the request and response queue information. */
452 init_fw_cb
->rqq_consumer_idx
= cpu_to_le16(ha
->request_out
);
453 init_fw_cb
->compq_producer_idx
= cpu_to_le16(ha
->response_in
);
454 init_fw_cb
->rqq_len
= __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH
);
455 init_fw_cb
->compq_len
= __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH
);
456 init_fw_cb
->rqq_addr_lo
= cpu_to_le32(LSDW(ha
->request_dma
));
457 init_fw_cb
->rqq_addr_hi
= cpu_to_le32(MSDW(ha
->request_dma
));
458 init_fw_cb
->compq_addr_lo
= cpu_to_le32(LSDW(ha
->response_dma
));
459 init_fw_cb
->compq_addr_hi
= cpu_to_le32(MSDW(ha
->response_dma
));
460 init_fw_cb
->shdwreg_addr_lo
= cpu_to_le32(LSDW(ha
->shadow_regs_dma
));
461 init_fw_cb
->shdwreg_addr_hi
= cpu_to_le32(MSDW(ha
->shadow_regs_dma
));
463 /* Set up required options. */
464 init_fw_cb
->fw_options
|=
465 __constant_cpu_to_le16(FWOPT_SESSION_MODE
|
466 FWOPT_INITIATOR_MODE
);
467 init_fw_cb
->fw_options
&= __constant_cpu_to_le16(~FWOPT_TARGET_MODE
);
469 if (qla4xxx_set_ifcb(ha
, &mbox_cmd
[0], &mbox_sts
[0], init_fw_cb_dma
)
471 DEBUG2(printk(KERN_WARNING
472 "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
473 ha
->host_no
, __func__
));
474 goto exit_init_fw_cb
;
477 if (qla4xxx_update_local_ifcb(ha
, &mbox_cmd
[0], &mbox_sts
[0],
478 init_fw_cb
, init_fw_cb_dma
) != QLA_SUCCESS
) {
479 DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
480 ha
->host_no
, __func__
));
481 goto exit_init_fw_cb
;
483 status
= QLA_SUCCESS
;
486 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct addr_ctrl_blk
),
487 init_fw_cb
, init_fw_cb_dma
);
488 exit_init_fw_cb_no_free
:
493 * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
494 * @ha: Pointer to host adapter structure.
496 int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host
* ha
)
498 struct addr_ctrl_blk
*init_fw_cb
;
499 dma_addr_t init_fw_cb_dma
;
500 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
501 uint32_t mbox_sts
[MBOX_REG_COUNT
];
503 init_fw_cb
= dma_alloc_coherent(&ha
->pdev
->dev
,
504 sizeof(struct addr_ctrl_blk
),
505 &init_fw_cb_dma
, GFP_KERNEL
);
506 if (init_fw_cb
== NULL
) {
507 printk("scsi%ld: %s: Unable to alloc init_cb\n", ha
->host_no
,
512 /* Get Initialize Firmware Control Block. */
513 memset(init_fw_cb
, 0, sizeof(struct addr_ctrl_blk
));
514 if (qla4xxx_get_ifcb(ha
, &mbox_cmd
[0], &mbox_sts
[0], init_fw_cb_dma
) !=
516 DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
517 ha
->host_no
, __func__
));
518 dma_free_coherent(&ha
->pdev
->dev
,
519 sizeof(struct addr_ctrl_blk
),
520 init_fw_cb
, init_fw_cb_dma
);
524 /* Save IP Address. */
525 qla4xxx_update_local_ip(ha
, init_fw_cb
);
526 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct addr_ctrl_blk
),
527 init_fw_cb
, init_fw_cb_dma
);
533 * qla4xxx_get_firmware_state - gets firmware state of HBA
534 * @ha: Pointer to host adapter structure.
536 int qla4xxx_get_firmware_state(struct scsi_qla_host
* ha
)
538 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
539 uint32_t mbox_sts
[MBOX_REG_COUNT
];
541 /* Get firmware version */
542 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
543 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
545 mbox_cmd
[0] = MBOX_CMD_GET_FW_STATE
;
547 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 4, &mbox_cmd
[0], &mbox_sts
[0]) !=
549 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
550 "status %04X\n", ha
->host_no
, __func__
,
554 ha
->firmware_state
= mbox_sts
[1];
555 ha
->board_id
= mbox_sts
[2];
556 ha
->addl_fw_state
= mbox_sts
[3];
557 DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
558 ha
->host_no
, __func__
, ha
->firmware_state
);)
564 * qla4xxx_get_firmware_status - retrieves firmware status
565 * @ha: Pointer to host adapter structure.
567 int qla4xxx_get_firmware_status(struct scsi_qla_host
* ha
)
569 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
570 uint32_t mbox_sts
[MBOX_REG_COUNT
];
572 /* Get firmware version */
573 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
574 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
576 mbox_cmd
[0] = MBOX_CMD_GET_FW_STATUS
;
578 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 3, &mbox_cmd
[0], &mbox_sts
[0]) !=
580 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
581 "status %04X\n", ha
->host_no
, __func__
,
586 ql4_printk(KERN_INFO
, ha
, "%ld firmare IOCBs available (%d).\n",
587 ha
->host_no
, mbox_cmd
[2]);
593 * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
594 * @ha: Pointer to host adapter structure.
595 * @fw_ddb_index: Firmware's device database index
596 * @fw_ddb_entry: Pointer to firmware's device database entry structure
597 * @num_valid_ddb_entries: Pointer to number of valid ddb entries
598 * @next_ddb_index: Pointer to next valid device database index
599 * @fw_ddb_device_state: Pointer to device state
601 int qla4xxx_get_fwddb_entry(struct scsi_qla_host
*ha
,
602 uint16_t fw_ddb_index
,
603 struct dev_db_entry
*fw_ddb_entry
,
604 dma_addr_t fw_ddb_entry_dma
,
605 uint32_t *num_valid_ddb_entries
,
606 uint32_t *next_ddb_index
,
607 uint32_t *fw_ddb_device_state
,
608 uint32_t *conn_err_detail
,
609 uint16_t *tcp_source_port_num
,
610 uint16_t *connection_id
)
612 int status
= QLA_ERROR
;
614 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
615 uint32_t mbox_sts
[MBOX_REG_COUNT
];
617 /* Make sure the device index is valid */
618 if (fw_ddb_index
>= MAX_DDB_ENTRIES
) {
619 DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
620 ha
->host_no
, __func__
, fw_ddb_index
));
623 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
624 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
626 mbox_cmd
[0] = MBOX_CMD_GET_DATABASE_ENTRY
;
627 mbox_cmd
[1] = (uint32_t) fw_ddb_index
;
628 mbox_cmd
[2] = LSDW(fw_ddb_entry_dma
);
629 mbox_cmd
[3] = MSDW(fw_ddb_entry_dma
);
630 mbox_cmd
[4] = sizeof(struct dev_db_entry
);
632 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 7, &mbox_cmd
[0], &mbox_sts
[0]) ==
634 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
635 " with status 0x%04X\n", ha
->host_no
, __func__
,
639 if (fw_ddb_index
!= mbox_sts
[1]) {
640 DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
641 ha
->host_no
, __func__
, fw_ddb_index
,
646 options
= le16_to_cpu(fw_ddb_entry
->options
);
647 if (options
& DDB_OPT_IPV6_DEVICE
) {
648 ql4_printk(KERN_INFO
, ha
, "%s: DDB[%d] MB0 %04x Tot %d "
649 "Next %d State %04x ConnErr %08x %pI6 "
650 ":%04d \"%s\"\n", __func__
, fw_ddb_index
,
651 mbox_sts
[0], mbox_sts
[2], mbox_sts
[3],
652 mbox_sts
[4], mbox_sts
[5],
653 fw_ddb_entry
->ip_addr
,
654 le16_to_cpu(fw_ddb_entry
->port
),
655 fw_ddb_entry
->iscsi_name
);
657 ql4_printk(KERN_INFO
, ha
, "%s: DDB[%d] MB0 %04x Tot %d "
658 "Next %d State %04x ConnErr %08x %pI4 "
659 ":%04d \"%s\"\n", __func__
, fw_ddb_index
,
660 mbox_sts
[0], mbox_sts
[2], mbox_sts
[3],
661 mbox_sts
[4], mbox_sts
[5],
662 fw_ddb_entry
->ip_addr
,
663 le16_to_cpu(fw_ddb_entry
->port
),
664 fw_ddb_entry
->iscsi_name
);
667 if (num_valid_ddb_entries
)
668 *num_valid_ddb_entries
= mbox_sts
[2];
670 *next_ddb_index
= mbox_sts
[3];
671 if (fw_ddb_device_state
)
672 *fw_ddb_device_state
= mbox_sts
[4];
675 * RA: This mailbox has been changed to pass connection error and
676 * details. Its true for ISP4010 as per Version E - Not sure when it
677 * was changed. Get the time2wait from the fw_dd_entry field :
678 * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
682 *conn_err_detail
= mbox_sts
[5];
683 if (tcp_source_port_num
)
684 *tcp_source_port_num
= (uint16_t) (mbox_sts
[6] >> 16);
686 *connection_id
= (uint16_t) mbox_sts
[6] & 0x00FF;
687 status
= QLA_SUCCESS
;
694 * qla4xxx_set_fwddb_entry - sets a ddb entry.
695 * @ha: Pointer to host adapter structure.
696 * @fw_ddb_index: Firmware's device database index
697 * @fw_ddb_entry: Pointer to firmware's ddb entry structure, or NULL.
699 * This routine initializes or updates the adapter's device database
700 * entry for the specified device. It also triggers a login for the
701 * specified device. Therefore, it may also be used as a secondary
702 * login routine when a NULL pointer is specified for the fw_ddb_entry.
704 int qla4xxx_set_ddb_entry(struct scsi_qla_host
* ha
, uint16_t fw_ddb_index
,
705 dma_addr_t fw_ddb_entry_dma
)
707 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
708 uint32_t mbox_sts
[MBOX_REG_COUNT
];
711 /* Do not wait for completion. The firmware will send us an
712 * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
714 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
715 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
717 mbox_cmd
[0] = MBOX_CMD_SET_DATABASE_ENTRY
;
718 mbox_cmd
[1] = (uint32_t) fw_ddb_index
;
719 mbox_cmd
[2] = LSDW(fw_ddb_entry_dma
);
720 mbox_cmd
[3] = MSDW(fw_ddb_entry_dma
);
721 mbox_cmd
[4] = sizeof(struct dev_db_entry
);
723 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0],
725 DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
726 ha
->host_no
, __func__
, status
, mbox_sts
[0], mbox_sts
[4]);)
732 * qla4xxx_get_crash_record - retrieves crash record.
733 * @ha: Pointer to host adapter structure.
735 * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
737 void qla4xxx_get_crash_record(struct scsi_qla_host
* ha
)
739 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
740 uint32_t mbox_sts
[MBOX_REG_COUNT
];
741 struct crash_record
*crash_record
= NULL
;
742 dma_addr_t crash_record_dma
= 0;
743 uint32_t crash_record_size
= 0;
745 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
746 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
748 /* Get size of crash record. */
749 mbox_cmd
[0] = MBOX_CMD_GET_CRASH_RECORD
;
751 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
753 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
754 ha
->host_no
, __func__
));
755 goto exit_get_crash_record
;
757 crash_record_size
= mbox_sts
[4];
758 if (crash_record_size
== 0) {
759 DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
760 ha
->host_no
, __func__
));
761 goto exit_get_crash_record
;
764 /* Alloc Memory for Crash Record. */
765 crash_record
= dma_alloc_coherent(&ha
->pdev
->dev
, crash_record_size
,
766 &crash_record_dma
, GFP_KERNEL
);
767 if (crash_record
== NULL
)
768 goto exit_get_crash_record
;
770 /* Get Crash Record. */
771 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
772 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
774 mbox_cmd
[0] = MBOX_CMD_GET_CRASH_RECORD
;
775 mbox_cmd
[2] = LSDW(crash_record_dma
);
776 mbox_cmd
[3] = MSDW(crash_record_dma
);
777 mbox_cmd
[4] = crash_record_size
;
779 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
781 goto exit_get_crash_record
;
783 /* Dump Crash Record. */
785 exit_get_crash_record
:
787 dma_free_coherent(&ha
->pdev
->dev
, crash_record_size
,
788 crash_record
, crash_record_dma
);
792 * qla4xxx_get_conn_event_log - retrieves connection event log
793 * @ha: Pointer to host adapter structure.
795 void qla4xxx_get_conn_event_log(struct scsi_qla_host
* ha
)
797 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
798 uint32_t mbox_sts
[MBOX_REG_COUNT
];
799 struct conn_event_log_entry
*event_log
= NULL
;
800 dma_addr_t event_log_dma
= 0;
801 uint32_t event_log_size
= 0;
802 uint32_t num_valid_entries
;
803 uint32_t oldest_entry
= 0;
804 uint32_t max_event_log_entries
;
808 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
809 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
811 /* Get size of crash record. */
812 mbox_cmd
[0] = MBOX_CMD_GET_CONN_EVENT_LOG
;
814 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
816 goto exit_get_event_log
;
818 event_log_size
= mbox_sts
[4];
819 if (event_log_size
== 0)
820 goto exit_get_event_log
;
822 /* Alloc Memory for Crash Record. */
823 event_log
= dma_alloc_coherent(&ha
->pdev
->dev
, event_log_size
,
824 &event_log_dma
, GFP_KERNEL
);
825 if (event_log
== NULL
)
826 goto exit_get_event_log
;
828 /* Get Crash Record. */
829 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
830 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
832 mbox_cmd
[0] = MBOX_CMD_GET_CONN_EVENT_LOG
;
833 mbox_cmd
[2] = LSDW(event_log_dma
);
834 mbox_cmd
[3] = MSDW(event_log_dma
);
836 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
838 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
839 "log!\n", ha
->host_no
, __func__
));
840 goto exit_get_event_log
;
843 /* Dump Event Log. */
844 num_valid_entries
= mbox_sts
[1];
846 max_event_log_entries
= event_log_size
/
847 sizeof(struct conn_event_log_entry
);
849 if (num_valid_entries
> max_event_log_entries
)
850 oldest_entry
= num_valid_entries
% max_event_log_entries
;
852 DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
853 ha
->host_no
, num_valid_entries
));
855 if (ql4xextended_error_logging
== 3) {
856 if (oldest_entry
== 0) {
857 /* Circular Buffer has not wrapped around */
858 for (i
=0; i
< num_valid_entries
; i
++) {
859 qla4xxx_dump_buffer((uint8_t *)event_log
+
860 (i
*sizeof(*event_log
)),
865 /* Circular Buffer has wrapped around -
866 * display accordingly*/
867 for (i
=oldest_entry
; i
< max_event_log_entries
; i
++) {
868 qla4xxx_dump_buffer((uint8_t *)event_log
+
869 (i
*sizeof(*event_log
)),
872 for (i
=0; i
< oldest_entry
; i
++) {
873 qla4xxx_dump_buffer((uint8_t *)event_log
+
874 (i
*sizeof(*event_log
)),
882 dma_free_coherent(&ha
->pdev
->dev
, event_log_size
, event_log
,
887 * qla4xxx_abort_task - issues Abort Task
888 * @ha: Pointer to host adapter structure.
889 * @srb: Pointer to srb entry
891 * This routine performs a LUN RESET on the specified target/lun.
892 * The caller must ensure that the ddb_entry and lun_entry pointers
893 * are valid before calling this routine.
895 int qla4xxx_abort_task(struct scsi_qla_host
*ha
, struct srb
*srb
)
897 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
898 uint32_t mbox_sts
[MBOX_REG_COUNT
];
899 struct scsi_cmnd
*cmd
= srb
->cmd
;
900 int status
= QLA_SUCCESS
;
901 unsigned long flags
= 0;
905 * Send abort task command to ISP, so that the ISP will return
906 * request with ABORT status
908 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
909 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
911 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
912 index
= (unsigned long)(unsigned char *)cmd
->host_scribble
;
913 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
915 /* Firmware already posted completion on response queue */
916 if (index
== MAX_SRBS
)
919 mbox_cmd
[0] = MBOX_CMD_ABORT_TASK
;
920 mbox_cmd
[1] = srb
->fw_ddb_index
;
922 /* Immediate Command Enable */
925 qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0],
927 if (mbox_sts
[0] != MBOX_STS_COMMAND_COMPLETE
) {
930 DEBUG2(printk(KERN_WARNING
"scsi%ld:%d:%d: abort task FAILED: "
931 "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
932 ha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, mbox_sts
[0],
933 mbox_sts
[1], mbox_sts
[2], mbox_sts
[3], mbox_sts
[4]));
940 * qla4xxx_reset_lun - issues LUN Reset
941 * @ha: Pointer to host adapter structure.
942 * @ddb_entry: Pointer to device database entry
945 * This routine performs a LUN RESET on the specified target/lun.
946 * The caller must ensure that the ddb_entry and lun_entry pointers
947 * are valid before calling this routine.
949 int qla4xxx_reset_lun(struct scsi_qla_host
* ha
, struct ddb_entry
* ddb_entry
,
952 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
953 uint32_t mbox_sts
[MBOX_REG_COUNT
];
954 int status
= QLA_SUCCESS
;
956 DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha
->host_no
,
957 ddb_entry
->fw_ddb_index
, lun
));
960 * Send lun reset command to ISP, so that the ISP will return all
961 * outstanding requests with RESET status
963 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
964 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
966 mbox_cmd
[0] = MBOX_CMD_LUN_RESET
;
967 mbox_cmd
[1] = ddb_entry
->fw_ddb_index
;
968 mbox_cmd
[2] = lun
<< 8;
969 mbox_cmd
[5] = 0x01; /* Immediate Command Enable */
971 qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0], &mbox_sts
[0]);
972 if (mbox_sts
[0] != MBOX_STS_COMMAND_COMPLETE
&&
973 mbox_sts
[0] != MBOX_STS_COMMAND_ERROR
)
980 * qla4xxx_reset_target - issues target Reset
981 * @ha: Pointer to host adapter structure.
982 * @db_entry: Pointer to device database entry
983 * @un_entry: Pointer to lun entry structure
985 * This routine performs a TARGET RESET on the specified target.
986 * The caller must ensure that the ddb_entry pointers
987 * are valid before calling this routine.
989 int qla4xxx_reset_target(struct scsi_qla_host
*ha
,
990 struct ddb_entry
*ddb_entry
)
992 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
993 uint32_t mbox_sts
[MBOX_REG_COUNT
];
994 int status
= QLA_SUCCESS
;
996 DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha
->host_no
,
997 ddb_entry
->fw_ddb_index
));
1000 * Send target reset command to ISP, so that the ISP will return all
1001 * outstanding requests with RESET status
1003 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1004 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1006 mbox_cmd
[0] = MBOX_CMD_TARGET_WARM_RESET
;
1007 mbox_cmd
[1] = ddb_entry
->fw_ddb_index
;
1008 mbox_cmd
[5] = 0x01; /* Immediate Command Enable */
1010 qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0],
1012 if (mbox_sts
[0] != MBOX_STS_COMMAND_COMPLETE
&&
1013 mbox_sts
[0] != MBOX_STS_COMMAND_ERROR
)
1019 int qla4xxx_get_flash(struct scsi_qla_host
* ha
, dma_addr_t dma_addr
,
1020 uint32_t offset
, uint32_t len
)
1022 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1023 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1025 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1026 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1028 mbox_cmd
[0] = MBOX_CMD_READ_FLASH
;
1029 mbox_cmd
[1] = LSDW(dma_addr
);
1030 mbox_cmd
[2] = MSDW(dma_addr
);
1031 mbox_cmd
[3] = offset
;
1034 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 2, &mbox_cmd
[0], &mbox_sts
[0]) !=
1036 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
1037 "status %04X %04X, offset %08x, len %08x\n", ha
->host_no
,
1038 __func__
, mbox_sts
[0], mbox_sts
[1], offset
, len
));
1045 * qla4xxx_get_fw_version - gets firmware version
1046 * @ha: Pointer to host adapter structure.
1048 * Retrieves the firmware version on HBA. In QLA4010, mailboxes 2 & 3 may
1049 * hold an address for data. Make sure that we write 0 to those mailboxes,
1052 int qla4xxx_get_fw_version(struct scsi_qla_host
* ha
)
1054 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1055 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1057 /* Get firmware version. */
1058 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1059 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1061 mbox_cmd
[0] = MBOX_CMD_ABOUT_FW
;
1063 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
1065 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_ABOUT_FW failed w/ "
1066 "status %04X\n", ha
->host_no
, __func__
, mbox_sts
[0]));
1070 /* Save firmware version information. */
1071 ha
->firmware_version
[0] = mbox_sts
[1];
1072 ha
->firmware_version
[1] = mbox_sts
[2];
1073 ha
->patch_number
= mbox_sts
[3];
1074 ha
->build_number
= mbox_sts
[4];
1079 static int qla4xxx_get_default_ddb(struct scsi_qla_host
*ha
,
1080 dma_addr_t dma_addr
)
1082 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1083 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1085 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1086 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1088 mbox_cmd
[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS
;
1089 mbox_cmd
[2] = LSDW(dma_addr
);
1090 mbox_cmd
[3] = MSDW(dma_addr
);
1092 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0], &mbox_sts
[0]) !=
1094 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1095 ha
->host_no
, __func__
, mbox_sts
[0]));
1101 static int qla4xxx_req_ddb_entry(struct scsi_qla_host
*ha
, uint32_t *ddb_index
)
1103 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1104 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1106 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1107 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1109 mbox_cmd
[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY
;
1110 mbox_cmd
[1] = MAX_PRST_DEV_DB_ENTRIES
;
1112 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 3, &mbox_cmd
[0], &mbox_sts
[0]) !=
1114 if (mbox_sts
[0] == MBOX_STS_COMMAND_ERROR
) {
1115 *ddb_index
= mbox_sts
[2];
1117 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1118 ha
->host_no
, __func__
, mbox_sts
[0]));
1122 *ddb_index
= MAX_PRST_DEV_DB_ENTRIES
;
1129 int qla4xxx_send_tgts(struct scsi_qla_host
*ha
, char *ip
, uint16_t port
)
1131 struct dev_db_entry
*fw_ddb_entry
;
1132 dma_addr_t fw_ddb_entry_dma
;
1134 int ret_val
= QLA_SUCCESS
;
1137 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
,
1138 sizeof(*fw_ddb_entry
),
1139 &fw_ddb_entry_dma
, GFP_KERNEL
);
1140 if (!fw_ddb_entry
) {
1141 DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
1142 ha
->host_no
, __func__
));
1143 ret_val
= QLA_ERROR
;
1144 goto exit_send_tgts_no_free
;
1147 ret_val
= qla4xxx_get_default_ddb(ha
, fw_ddb_entry_dma
);
1148 if (ret_val
!= QLA_SUCCESS
)
1149 goto exit_send_tgts
;
1151 ret_val
= qla4xxx_req_ddb_entry(ha
, &ddb_index
);
1152 if (ret_val
!= QLA_SUCCESS
)
1153 goto exit_send_tgts
;
1155 memset(fw_ddb_entry
->iscsi_alias
, 0,
1156 sizeof(fw_ddb_entry
->iscsi_alias
));
1158 memset(fw_ddb_entry
->iscsi_name
, 0,
1159 sizeof(fw_ddb_entry
->iscsi_name
));
1161 memset(fw_ddb_entry
->ip_addr
, 0, sizeof(fw_ddb_entry
->ip_addr
));
1162 memset(fw_ddb_entry
->tgt_addr
, 0,
1163 sizeof(fw_ddb_entry
->tgt_addr
));
1165 fw_ddb_entry
->options
= (DDB_OPT_DISC_SESSION
| DDB_OPT_TARGET
);
1166 fw_ddb_entry
->port
= cpu_to_le16(ntohs(port
));
1168 fw_ddb_entry
->ip_addr
[0] = *ip
;
1169 fw_ddb_entry
->ip_addr
[1] = *(ip
+ 1);
1170 fw_ddb_entry
->ip_addr
[2] = *(ip
+ 2);
1171 fw_ddb_entry
->ip_addr
[3] = *(ip
+ 3);
1173 ret_val
= qla4xxx_set_ddb_entry(ha
, ddb_index
, fw_ddb_entry_dma
);
1176 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
1177 fw_ddb_entry
, fw_ddb_entry_dma
);
1178 exit_send_tgts_no_free
: