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 sssue 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 static 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 a previously issued
63 * mailbox command is interrupting.
64 * -----------------------------------------------------------------
66 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
67 intr_status
= readl(&ha
->reg
->ctrl_status
);
68 if (intr_status
& CSR_SCSI_PROCESSOR_INTR
) {
69 /* Service existing interrupt */
70 qla4xxx_interrupt_service_routine(ha
, intr_status
);
71 clear_bit(AF_MBOX_COMMAND_DONE
, &ha
->flags
);
74 /* Send the mailbox command to the firmware */
75 ha
->mbox_status_count
= outCount
;
76 for (i
= 0; i
< outCount
; i
++)
77 ha
->mbox_status
[i
] = 0;
79 /* Load all mailbox registers, except mailbox 0. */
80 for (i
= 1; i
< inCount
; i
++)
81 writel(mbx_cmd
[i
], &ha
->reg
->mailbox
[i
]);
84 writel(mbx_cmd
[0], &ha
->reg
->mailbox
[0]);
85 readl(&ha
->reg
->mailbox
[0]);
86 writel(set_rmask(CSR_INTR_RISC
), &ha
->reg
->ctrl_status
);
87 readl(&ha
->reg
->ctrl_status
);
88 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
90 /* Wait for completion */
93 * If we don't want status, don't wait for the mailbox command to
94 * complete. For example, MBOX_CMD_RESET_FW doesn't return status,
95 * you must poll the inbound Interrupt Mask for completion.
101 /* Wait for command to complete */
102 wait_count
= jiffies
+ MBOX_TOV
* HZ
;
103 while (test_bit(AF_MBOX_COMMAND_DONE
, &ha
->flags
) == 0) {
104 if (time_after_eq(jiffies
, wait_count
))
107 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
108 intr_status
= readl(&ha
->reg
->ctrl_status
);
109 if (intr_status
& INTR_PENDING
) {
111 * Service the interrupt.
112 * The ISR will save the mailbox status registers
113 * to a temporary storage location in the adapter
116 ha
->mbox_status_count
= outCount
;
117 qla4xxx_interrupt_service_routine(ha
, intr_status
);
119 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
123 /* Check for mailbox timeout. */
124 if (!test_bit(AF_MBOX_COMMAND_DONE
, &ha
->flags
)) {
125 DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
126 " Scheduling Adapter Reset\n", ha
->host_no
,
128 ha
->mailbox_timeout_count
++;
130 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
135 * Copy the mailbox out registers to the caller's mailbox in/out
138 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
139 for (i
= 0; i
< outCount
; i
++)
140 mbx_sts
[i
] = ha
->mbox_status
[i
];
142 /* Set return status and error flags (if applicable). */
143 switch (ha
->mbox_status
[0]) {
144 case MBOX_STS_COMMAND_COMPLETE
:
145 status
= QLA_SUCCESS
;
148 case MBOX_STS_INTERMEDIATE_COMPLETION
:
149 status
= QLA_SUCCESS
;
153 DEBUG2( printk("scsi%ld: %s: Cmd = %08X, ISP BUSY\n",
154 ha
->host_no
, __func__
, mbx_cmd
[0]));
155 ha
->mailbox_timeout_count
++;
159 DEBUG2(printk("scsi%ld: %s: **** FAILED, cmd = %08X, "
160 "sts = %08X ****\n", ha
->host_no
, __func__
,
161 mbx_cmd
[0], mbx_sts
[0]));
164 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
167 mutex_lock(&ha
->mbox_sem
);
168 clear_bit(AF_MBOX_COMMAND
, &ha
->flags
);
169 mutex_unlock(&ha
->mbox_sem
);
170 clear_bit(AF_MBOX_COMMAND_DONE
, &ha
->flags
);
176 * qla4xxx_initialize_fw_cb - initializes firmware control block.
177 * @ha: Pointer to host adapter structure.
179 int qla4xxx_initialize_fw_cb(struct scsi_qla_host
* ha
)
181 struct init_fw_ctrl_blk
*init_fw_cb
;
182 dma_addr_t init_fw_cb_dma
;
183 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
184 uint32_t mbox_sts
[MBOX_REG_COUNT
];
185 int status
= QLA_ERROR
;
187 init_fw_cb
= dma_alloc_coherent(&ha
->pdev
->dev
,
188 sizeof(struct init_fw_ctrl_blk
),
189 &init_fw_cb_dma
, GFP_KERNEL
);
190 if (init_fw_cb
== NULL
) {
191 DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
192 ha
->host_no
, __func__
));
195 memset(init_fw_cb
, 0, sizeof(struct init_fw_ctrl_blk
));
197 /* Get Initialize Firmware Control Block. */
198 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
199 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
201 mbox_cmd
[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK
;
202 mbox_cmd
[2] = LSDW(init_fw_cb_dma
);
203 mbox_cmd
[3] = MSDW(init_fw_cb_dma
);
204 mbox_cmd
[4] = sizeof(struct init_fw_ctrl_blk
);
206 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0], &mbox_sts
[0]) !=
208 dma_free_coherent(&ha
->pdev
->dev
,
209 sizeof(struct init_fw_ctrl_blk
),
210 init_fw_cb
, init_fw_cb_dma
);
214 /* Initialize request and response queues. */
215 qla4xxx_init_rings(ha
);
217 /* Fill in the request and response queue information. */
218 init_fw_cb
->pri
.rqq_consumer_idx
= cpu_to_le16(ha
->request_out
);
219 init_fw_cb
->pri
.compq_producer_idx
= cpu_to_le16(ha
->response_in
);
220 init_fw_cb
->pri
.rqq_len
= __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH
);
221 init_fw_cb
->pri
.compq_len
= __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH
);
222 init_fw_cb
->pri
.rqq_addr_lo
= cpu_to_le32(LSDW(ha
->request_dma
));
223 init_fw_cb
->pri
.rqq_addr_hi
= cpu_to_le32(MSDW(ha
->request_dma
));
224 init_fw_cb
->pri
.compq_addr_lo
= cpu_to_le32(LSDW(ha
->response_dma
));
225 init_fw_cb
->pri
.compq_addr_hi
= cpu_to_le32(MSDW(ha
->response_dma
));
226 init_fw_cb
->pri
.shdwreg_addr_lo
=
227 cpu_to_le32(LSDW(ha
->shadow_regs_dma
));
228 init_fw_cb
->pri
.shdwreg_addr_hi
=
229 cpu_to_le32(MSDW(ha
->shadow_regs_dma
));
231 /* Set up required options. */
232 init_fw_cb
->pri
.fw_options
|=
233 __constant_cpu_to_le16(FWOPT_SESSION_MODE
|
234 FWOPT_INITIATOR_MODE
);
235 init_fw_cb
->pri
.fw_options
&= __constant_cpu_to_le16(~FWOPT_TARGET_MODE
);
237 /* Save some info in adapter structure. */
238 ha
->firmware_options
= le16_to_cpu(init_fw_cb
->pri
.fw_options
);
239 ha
->tcp_options
= le16_to_cpu(init_fw_cb
->pri
.ipv4_tcp_opts
);
240 ha
->heartbeat_interval
= init_fw_cb
->pri
.hb_interval
;
241 memcpy(ha
->ip_address
, init_fw_cb
->pri
.ipv4_addr
,
242 min(sizeof(ha
->ip_address
), sizeof(init_fw_cb
->pri
.ipv4_addr
)));
243 memcpy(ha
->subnet_mask
, init_fw_cb
->pri
.ipv4_subnet
,
244 min(sizeof(ha
->subnet_mask
), sizeof(init_fw_cb
->pri
.ipv4_subnet
)));
245 memcpy(ha
->gateway
, init_fw_cb
->pri
.ipv4_gw_addr
,
246 min(sizeof(ha
->gateway
), sizeof(init_fw_cb
->pri
.ipv4_gw_addr
)));
247 memcpy(ha
->name_string
, init_fw_cb
->pri
.iscsi_name
,
248 min(sizeof(ha
->name_string
),
249 sizeof(init_fw_cb
->pri
.iscsi_name
)));
250 /*memcpy(ha->alias, init_fw_cb->Alias,
251 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
253 /* Save Command Line Paramater info */
254 ha
->port_down_retry_count
= le16_to_cpu(init_fw_cb
->pri
.conn_ka_timeout
);
255 ha
->discovery_wait
= ql4xdiscoverywait
;
257 /* Send Initialize Firmware Control Block. */
258 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
259 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
261 mbox_cmd
[0] = MBOX_CMD_INITIALIZE_FIRMWARE
;
263 mbox_cmd
[2] = LSDW(init_fw_cb_dma
);
264 mbox_cmd
[3] = MSDW(init_fw_cb_dma
);
265 mbox_cmd
[4] = sizeof(struct init_fw_ctrl_blk
);
267 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0], &mbox_sts
[0]) ==
269 status
= QLA_SUCCESS
;
271 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_INITIALIZE_FIRMWARE "
272 "failed w/ status %04X\n", ha
->host_no
, __func__
,
275 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct init_fw_ctrl_blk
),
276 init_fw_cb
, init_fw_cb_dma
);
282 * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
283 * @ha: Pointer to host adapter structure.
285 int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host
* ha
)
287 struct init_fw_ctrl_blk
*init_fw_cb
;
288 dma_addr_t init_fw_cb_dma
;
289 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
290 uint32_t mbox_sts
[MBOX_REG_COUNT
];
292 init_fw_cb
= dma_alloc_coherent(&ha
->pdev
->dev
,
293 sizeof(struct init_fw_ctrl_blk
),
294 &init_fw_cb_dma
, GFP_KERNEL
);
295 if (init_fw_cb
== NULL
) {
296 printk("scsi%ld: %s: Unable to alloc init_cb\n", ha
->host_no
,
301 /* Get Initialize Firmware Control Block. */
302 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
303 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
305 memset(init_fw_cb
, 0, sizeof(struct init_fw_ctrl_blk
));
306 mbox_cmd
[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK
;
307 mbox_cmd
[2] = LSDW(init_fw_cb_dma
);
308 mbox_cmd
[3] = MSDW(init_fw_cb_dma
);
309 mbox_cmd
[4] = sizeof(struct init_fw_ctrl_blk
);
311 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0], &mbox_sts
[0]) !=
313 DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
314 ha
->host_no
, __func__
));
315 dma_free_coherent(&ha
->pdev
->dev
,
316 sizeof(struct init_fw_ctrl_blk
),
317 init_fw_cb
, init_fw_cb_dma
);
321 /* Save IP Address. */
322 memcpy(ha
->ip_address
, init_fw_cb
->pri
.ipv4_addr
,
323 min(sizeof(ha
->ip_address
), sizeof(init_fw_cb
->pri
.ipv4_addr
)));
324 memcpy(ha
->subnet_mask
, init_fw_cb
->pri
.ipv4_subnet
,
325 min(sizeof(ha
->subnet_mask
), sizeof(init_fw_cb
->pri
.ipv4_subnet
)));
326 memcpy(ha
->gateway
, init_fw_cb
->pri
.ipv4_gw_addr
,
327 min(sizeof(ha
->gateway
), sizeof(init_fw_cb
->pri
.ipv4_gw_addr
)));
329 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct init_fw_ctrl_blk
),
330 init_fw_cb
, init_fw_cb_dma
);
336 * qla4xxx_get_firmware_state - gets firmware state of HBA
337 * @ha: Pointer to host adapter structure.
339 int qla4xxx_get_firmware_state(struct scsi_qla_host
* ha
)
341 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
342 uint32_t mbox_sts
[MBOX_REG_COUNT
];
344 /* Get firmware version */
345 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
346 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
348 mbox_cmd
[0] = MBOX_CMD_GET_FW_STATE
;
350 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 4, &mbox_cmd
[0], &mbox_sts
[0]) !=
352 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
353 "status %04X\n", ha
->host_no
, __func__
,
357 ha
->firmware_state
= mbox_sts
[1];
358 ha
->board_id
= mbox_sts
[2];
359 ha
->addl_fw_state
= mbox_sts
[3];
360 DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
361 ha
->host_no
, __func__
, ha
->firmware_state
);)
367 * qla4xxx_get_firmware_status - retrieves firmware status
368 * @ha: Pointer to host adapter structure.
370 int qla4xxx_get_firmware_status(struct scsi_qla_host
* ha
)
372 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
373 uint32_t mbox_sts
[MBOX_REG_COUNT
];
375 /* Get firmware version */
376 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
377 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
379 mbox_cmd
[0] = MBOX_CMD_GET_FW_STATUS
;
381 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 3, &mbox_cmd
[0], &mbox_sts
[0]) !=
383 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
384 "status %04X\n", ha
->host_no
, __func__
,
389 /* High-water mark of IOCBs */
390 ha
->iocb_hiwat
= mbox_sts
[2];
391 if (ha
->iocb_hiwat
> IOCB_HIWAT_CUSHION
)
392 ha
->iocb_hiwat
-= IOCB_HIWAT_CUSHION
;
394 dev_info(&ha
->pdev
->dev
, "WARNING!!! You have less than %d "
395 "firmare IOCBs available (%d).\n",
396 IOCB_HIWAT_CUSHION
, ha
->iocb_hiwat
);
402 * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
403 * @ha: Pointer to host adapter structure.
404 * @fw_ddb_index: Firmware's device database index
405 * @fw_ddb_entry: Pointer to firmware's device database entry structure
406 * @num_valid_ddb_entries: Pointer to number of valid ddb entries
407 * @next_ddb_index: Pointer to next valid device database index
408 * @fw_ddb_device_state: Pointer to device state
410 int qla4xxx_get_fwddb_entry(struct scsi_qla_host
*ha
,
411 uint16_t fw_ddb_index
,
412 struct dev_db_entry
*fw_ddb_entry
,
413 dma_addr_t fw_ddb_entry_dma
,
414 uint32_t *num_valid_ddb_entries
,
415 uint32_t *next_ddb_index
,
416 uint32_t *fw_ddb_device_state
,
417 uint32_t *conn_err_detail
,
418 uint16_t *tcp_source_port_num
,
419 uint16_t *connection_id
)
421 int status
= QLA_ERROR
;
422 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
423 uint32_t mbox_sts
[MBOX_REG_COUNT
];
425 /* Make sure the device index is valid */
426 if (fw_ddb_index
>= MAX_DDB_ENTRIES
) {
427 DEBUG2(printk("scsi%ld: %s: index [%d] out of range.\n",
428 ha
->host_no
, __func__
, fw_ddb_index
));
431 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
432 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
434 mbox_cmd
[0] = MBOX_CMD_GET_DATABASE_ENTRY
;
435 mbox_cmd
[1] = (uint32_t) fw_ddb_index
;
436 mbox_cmd
[2] = LSDW(fw_ddb_entry_dma
);
437 mbox_cmd
[3] = MSDW(fw_ddb_entry_dma
);
438 mbox_cmd
[4] = sizeof(struct dev_db_entry
);
440 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 7, &mbox_cmd
[0], &mbox_sts
[0]) ==
442 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
443 " with status 0x%04X\n", ha
->host_no
, __func__
,
447 if (fw_ddb_index
!= mbox_sts
[1]) {
448 DEBUG2(printk("scsi%ld: %s: index mismatch [%d] != [%d].\n",
449 ha
->host_no
, __func__
, fw_ddb_index
,
454 dev_info(&ha
->pdev
->dev
, "DDB[%d] MB0 %04x Tot %d Next %d "
455 "State %04x ConnErr %08x %d.%d.%d.%d:%04d \"%s\"\n",
456 fw_ddb_index
, mbox_sts
[0], mbox_sts
[2], mbox_sts
[3],
457 mbox_sts
[4], mbox_sts
[5], fw_ddb_entry
->ip_addr
[0],
458 fw_ddb_entry
->ip_addr
[1], fw_ddb_entry
->ip_addr
[2],
459 fw_ddb_entry
->ip_addr
[3],
460 le16_to_cpu(fw_ddb_entry
->port
),
461 fw_ddb_entry
->iscsi_name
);
463 if (num_valid_ddb_entries
)
464 *num_valid_ddb_entries
= mbox_sts
[2];
466 *next_ddb_index
= mbox_sts
[3];
467 if (fw_ddb_device_state
)
468 *fw_ddb_device_state
= mbox_sts
[4];
471 * RA: This mailbox has been changed to pass connection error and
472 * details. Its true for ISP4010 as per Version E - Not sure when it
473 * was changed. Get the time2wait from the fw_dd_entry field :
474 * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
478 *conn_err_detail
= mbox_sts
[5];
479 if (tcp_source_port_num
)
480 *tcp_source_port_num
= (uint16_t) mbox_sts
[6] >> 16;
482 *connection_id
= (uint16_t) mbox_sts
[6] & 0x00FF;
483 status
= QLA_SUCCESS
;
490 * qla4xxx_set_fwddb_entry - sets a ddb entry.
491 * @ha: Pointer to host adapter structure.
492 * @fw_ddb_index: Firmware's device database index
493 * @fw_ddb_entry: Pointer to firmware's ddb entry structure, or NULL.
495 * This routine initializes or updates the adapter's device database
496 * entry for the specified device. It also triggers a login for the
497 * specified device. Therefore, it may also be used as a secondary
498 * login routine when a NULL pointer is specified for the fw_ddb_entry.
500 int qla4xxx_set_ddb_entry(struct scsi_qla_host
* ha
, uint16_t fw_ddb_index
,
501 dma_addr_t fw_ddb_entry_dma
)
503 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
504 uint32_t mbox_sts
[MBOX_REG_COUNT
];
506 /* Do not wait for completion. The firmware will send us an
507 * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
509 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
510 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
512 mbox_cmd
[0] = MBOX_CMD_SET_DATABASE_ENTRY
;
513 mbox_cmd
[1] = (uint32_t) fw_ddb_index
;
514 mbox_cmd
[2] = LSDW(fw_ddb_entry_dma
);
515 mbox_cmd
[3] = MSDW(fw_ddb_entry_dma
);
516 mbox_cmd
[4] = sizeof(struct dev_db_entry
);
518 return qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0], &mbox_sts
[0]);
522 * qla4xxx_get_crash_record - retrieves crash record.
523 * @ha: Pointer to host adapter structure.
525 * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
527 void qla4xxx_get_crash_record(struct scsi_qla_host
* ha
)
529 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
530 uint32_t mbox_sts
[MBOX_REG_COUNT
];
531 struct crash_record
*crash_record
= NULL
;
532 dma_addr_t crash_record_dma
= 0;
533 uint32_t crash_record_size
= 0;
535 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
536 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
538 /* Get size of crash record. */
539 mbox_cmd
[0] = MBOX_CMD_GET_CRASH_RECORD
;
541 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
543 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
544 ha
->host_no
, __func__
));
545 goto exit_get_crash_record
;
547 crash_record_size
= mbox_sts
[4];
548 if (crash_record_size
== 0) {
549 DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
550 ha
->host_no
, __func__
));
551 goto exit_get_crash_record
;
554 /* Alloc Memory for Crash Record. */
555 crash_record
= dma_alloc_coherent(&ha
->pdev
->dev
, crash_record_size
,
556 &crash_record_dma
, GFP_KERNEL
);
557 if (crash_record
== NULL
)
558 goto exit_get_crash_record
;
560 /* Get Crash Record. */
561 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
562 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
564 mbox_cmd
[0] = MBOX_CMD_GET_CRASH_RECORD
;
565 mbox_cmd
[2] = LSDW(crash_record_dma
);
566 mbox_cmd
[3] = MSDW(crash_record_dma
);
567 mbox_cmd
[4] = crash_record_size
;
569 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
571 goto exit_get_crash_record
;
573 /* Dump Crash Record. */
575 exit_get_crash_record
:
577 dma_free_coherent(&ha
->pdev
->dev
, crash_record_size
,
578 crash_record
, crash_record_dma
);
582 * qla4xxx_get_conn_event_log - retrieves connection event log
583 * @ha: Pointer to host adapter structure.
585 void qla4xxx_get_conn_event_log(struct scsi_qla_host
* ha
)
587 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
588 uint32_t mbox_sts
[MBOX_REG_COUNT
];
589 struct conn_event_log_entry
*event_log
= NULL
;
590 dma_addr_t event_log_dma
= 0;
591 uint32_t event_log_size
= 0;
592 uint32_t num_valid_entries
;
593 uint32_t oldest_entry
= 0;
594 uint32_t max_event_log_entries
;
598 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
599 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
601 /* Get size of crash record. */
602 mbox_cmd
[0] = MBOX_CMD_GET_CONN_EVENT_LOG
;
604 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
606 goto exit_get_event_log
;
608 event_log_size
= mbox_sts
[4];
609 if (event_log_size
== 0)
610 goto exit_get_event_log
;
612 /* Alloc Memory for Crash Record. */
613 event_log
= dma_alloc_coherent(&ha
->pdev
->dev
, event_log_size
,
614 &event_log_dma
, GFP_KERNEL
);
615 if (event_log
== NULL
)
616 goto exit_get_event_log
;
618 /* Get Crash Record. */
619 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
620 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
622 mbox_cmd
[0] = MBOX_CMD_GET_CONN_EVENT_LOG
;
623 mbox_cmd
[2] = LSDW(event_log_dma
);
624 mbox_cmd
[3] = MSDW(event_log_dma
);
626 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
628 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
629 "log!\n", ha
->host_no
, __func__
));
630 goto exit_get_event_log
;
633 /* Dump Event Log. */
634 num_valid_entries
= mbox_sts
[1];
636 max_event_log_entries
= event_log_size
/
637 sizeof(struct conn_event_log_entry
);
639 if (num_valid_entries
> max_event_log_entries
)
640 oldest_entry
= num_valid_entries
% max_event_log_entries
;
642 DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
643 ha
->host_no
, num_valid_entries
));
645 if (ql4xextended_error_logging
== 3) {
646 if (oldest_entry
== 0) {
647 /* Circular Buffer has not wrapped around */
648 for (i
=0; i
< num_valid_entries
; i
++) {
649 qla4xxx_dump_buffer((uint8_t *)event_log
+
650 (i
*sizeof(*event_log
)),
655 /* Circular Buffer has wrapped around -
656 * display accordingly*/
657 for (i
=oldest_entry
; i
< max_event_log_entries
; i
++) {
658 qla4xxx_dump_buffer((uint8_t *)event_log
+
659 (i
*sizeof(*event_log
)),
662 for (i
=0; i
< oldest_entry
; i
++) {
663 qla4xxx_dump_buffer((uint8_t *)event_log
+
664 (i
*sizeof(*event_log
)),
672 dma_free_coherent(&ha
->pdev
->dev
, event_log_size
, event_log
,
677 * qla4xxx_reset_lun - issues LUN Reset
678 * @ha: Pointer to host adapter structure.
679 * @db_entry: Pointer to device database entry
680 * @un_entry: Pointer to lun entry structure
682 * This routine performs a LUN RESET on the specified target/lun.
683 * The caller must ensure that the ddb_entry and lun_entry pointers
684 * are valid before calling this routine.
686 int qla4xxx_reset_lun(struct scsi_qla_host
* ha
, struct ddb_entry
* ddb_entry
,
689 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
690 uint32_t mbox_sts
[MBOX_REG_COUNT
];
691 int status
= QLA_SUCCESS
;
693 DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha
->host_no
,
694 ddb_entry
->os_target_id
, lun
));
697 * Send lun reset command to ISP, so that the ISP will return all
698 * outstanding requests with RESET status
700 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
701 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
703 mbox_cmd
[0] = MBOX_CMD_LUN_RESET
;
704 mbox_cmd
[1] = ddb_entry
->fw_ddb_index
;
705 mbox_cmd
[2] = lun
<< 8;
706 mbox_cmd
[5] = 0x01; /* Immediate Command Enable */
708 qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0], &mbox_sts
[0]);
709 if (mbox_sts
[0] != MBOX_STS_COMMAND_COMPLETE
&&
710 mbox_sts
[0] != MBOX_STS_COMMAND_ERROR
)
717 * qla4xxx_reset_target - issues target Reset
718 * @ha: Pointer to host adapter structure.
719 * @db_entry: Pointer to device database entry
720 * @un_entry: Pointer to lun entry structure
722 * This routine performs a TARGET RESET on the specified target.
723 * The caller must ensure that the ddb_entry pointers
724 * are valid before calling this routine.
726 int qla4xxx_reset_target(struct scsi_qla_host
*ha
,
727 struct ddb_entry
*ddb_entry
)
729 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
730 uint32_t mbox_sts
[MBOX_REG_COUNT
];
731 int status
= QLA_SUCCESS
;
733 DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha
->host_no
,
734 ddb_entry
->os_target_id
));
737 * Send target reset command to ISP, so that the ISP will return all
738 * outstanding requests with RESET status
740 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
741 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
743 mbox_cmd
[0] = MBOX_CMD_TARGET_WARM_RESET
;
744 mbox_cmd
[1] = ddb_entry
->fw_ddb_index
;
745 mbox_cmd
[5] = 0x01; /* Immediate Command Enable */
747 qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0],
749 if (mbox_sts
[0] != MBOX_STS_COMMAND_COMPLETE
&&
750 mbox_sts
[0] != MBOX_STS_COMMAND_ERROR
)
756 int qla4xxx_get_flash(struct scsi_qla_host
* ha
, dma_addr_t dma_addr
,
757 uint32_t offset
, uint32_t len
)
759 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
760 uint32_t mbox_sts
[MBOX_REG_COUNT
];
762 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
763 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
765 mbox_cmd
[0] = MBOX_CMD_READ_FLASH
;
766 mbox_cmd
[1] = LSDW(dma_addr
);
767 mbox_cmd
[2] = MSDW(dma_addr
);
768 mbox_cmd
[3] = offset
;
771 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 2, &mbox_cmd
[0], &mbox_sts
[0]) !=
773 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
774 "status %04X %04X, offset %08x, len %08x\n", ha
->host_no
,
775 __func__
, mbox_sts
[0], mbox_sts
[1], offset
, len
));
782 * qla4xxx_get_fw_version - gets firmware version
783 * @ha: Pointer to host adapter structure.
785 * Retrieves the firmware version on HBA. In QLA4010, mailboxes 2 & 3 may
786 * hold an address for data. Make sure that we write 0 to those mailboxes,
789 int qla4xxx_get_fw_version(struct scsi_qla_host
* ha
)
791 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
792 uint32_t mbox_sts
[MBOX_REG_COUNT
];
794 /* Get firmware version. */
795 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
796 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
798 mbox_cmd
[0] = MBOX_CMD_ABOUT_FW
;
800 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
802 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_ABOUT_FW failed w/ "
803 "status %04X\n", ha
->host_no
, __func__
, mbox_sts
[0]));
807 /* Save firmware version information. */
808 ha
->firmware_version
[0] = mbox_sts
[1];
809 ha
->firmware_version
[1] = mbox_sts
[2];
810 ha
->patch_number
= mbox_sts
[3];
811 ha
->build_number
= mbox_sts
[4];
816 static int qla4xxx_get_default_ddb(struct scsi_qla_host
*ha
,
819 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
820 uint32_t mbox_sts
[MBOX_REG_COUNT
];
822 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
823 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
825 mbox_cmd
[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS
;
826 mbox_cmd
[2] = LSDW(dma_addr
);
827 mbox_cmd
[3] = MSDW(dma_addr
);
829 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0], &mbox_sts
[0]) !=
831 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
832 ha
->host_no
, __func__
, mbox_sts
[0]));
838 static int qla4xxx_req_ddb_entry(struct scsi_qla_host
*ha
, uint32_t *ddb_index
)
840 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
841 uint32_t mbox_sts
[MBOX_REG_COUNT
];
843 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
844 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
846 mbox_cmd
[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY
;
847 mbox_cmd
[1] = MAX_PRST_DEV_DB_ENTRIES
;
849 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 3, &mbox_cmd
[0], &mbox_sts
[0]) !=
851 if (mbox_sts
[0] == MBOX_STS_COMMAND_ERROR
) {
852 *ddb_index
= mbox_sts
[2];
854 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
855 ha
->host_no
, __func__
, mbox_sts
[0]));
859 *ddb_index
= MAX_PRST_DEV_DB_ENTRIES
;
866 int qla4xxx_send_tgts(struct scsi_qla_host
*ha
, char *ip
, uint16_t port
)
868 struct dev_db_entry
*fw_ddb_entry
;
869 dma_addr_t fw_ddb_entry_dma
;
871 int ret_val
= QLA_SUCCESS
;
874 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
,
875 sizeof(*fw_ddb_entry
),
876 &fw_ddb_entry_dma
, GFP_KERNEL
);
878 DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
879 ha
->host_no
, __func__
));
881 goto qla4xxx_send_tgts_exit
;
884 ret_val
= qla4xxx_get_default_ddb(ha
, fw_ddb_entry_dma
);
885 if (ret_val
!= QLA_SUCCESS
)
886 goto qla4xxx_send_tgts_exit
;
888 ret_val
= qla4xxx_req_ddb_entry(ha
, &ddb_index
);
889 if (ret_val
!= QLA_SUCCESS
)
890 goto qla4xxx_send_tgts_exit
;
892 memset(fw_ddb_entry
->iscsi_alias
, 0,
893 sizeof(fw_ddb_entry
->iscsi_alias
));
895 memset(fw_ddb_entry
->iscsi_name
, 0,
896 sizeof(fw_ddb_entry
->iscsi_name
));
898 memset(fw_ddb_entry
->ip_addr
, 0, sizeof(fw_ddb_entry
->ip_addr
));
899 memset(fw_ddb_entry
->tgt_addr
, 0,
900 sizeof(fw_ddb_entry
->tgt_addr
));
902 fw_ddb_entry
->options
= (DDB_OPT_DISC_SESSION
| DDB_OPT_TARGET
);
903 fw_ddb_entry
->port
= cpu_to_le16(ntohs(port
));
905 fw_ddb_entry
->ip_addr
[0] = *ip
;
906 fw_ddb_entry
->ip_addr
[1] = *(ip
+ 1);
907 fw_ddb_entry
->ip_addr
[2] = *(ip
+ 2);
908 fw_ddb_entry
->ip_addr
[3] = *(ip
+ 3);
910 ret_val
= qla4xxx_set_ddb_entry(ha
, ddb_index
, fw_ddb_entry_dma
);
912 qla4xxx_send_tgts_exit
:
913 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
914 fw_ddb_entry
, fw_ddb_entry_dma
);