2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2012 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
11 #include "ql4_inline.h"
12 #include "ql4_version.h"
14 void qla4xxx_queue_mbox_cmd(struct scsi_qla_host *ha, uint32_t *mbx_cmd,
19 /* Load all mailbox registers, except mailbox 0. */
20 for (i = 1; i < in_count; i++)
21 writel(mbx_cmd[i], &ha->reg->mailbox[i]);
24 writel(mbx_cmd[0], &ha->reg->mailbox[0]);
25 readl(&ha->reg->mailbox[0]);
26 writel(set_rmask(CSR_INTR_RISC), &ha->reg->ctrl_status);
27 readl(&ha->reg->ctrl_status);
30 void qla4xxx_process_mbox_intr(struct scsi_qla_host *ha, int out_count)
34 intr_status = readl(&ha->reg->ctrl_status);
35 if (intr_status & INTR_PENDING) {
37 * Service the interrupt.
38 * The ISR will save the mailbox status registers
39 * to a temporary storage location in the adapter structure.
41 ha->mbox_status_count = out_count;
42 ha->isp_ops->interrupt_service_routine(ha, intr_status);
47 * qla4xxx_is_intr_poll_mode – Are we allowed to poll for interrupts?
48 * @ha: Pointer to host adapter structure.
49 * @ret: 1=polling mode, 0=non-polling mode
51 static int qla4xxx_is_intr_poll_mode(struct scsi_qla_host *ha)
56 if (test_bit(AF_IRQ_ATTACHED, &ha->flags) &&
57 test_bit(AF_83XX_MBOX_INTR_ON, &ha->flags))
60 if (test_bit(AF_IRQ_ATTACHED, &ha->flags) &&
61 test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
62 test_bit(AF_ONLINE, &ha->flags) &&
63 !test_bit(AF_HA_REMOVAL, &ha->flags))
71 * qla4xxx_mailbox_command - issues mailbox commands
72 * @ha: Pointer to host adapter structure.
73 * @inCount: number of mailbox registers to load.
74 * @outCount: number of mailbox registers to return.
75 * @mbx_cmd: data pointer for mailbox in registers.
76 * @mbx_sts: data pointer for mailbox out registers.
78 * This routine issue mailbox commands and waits for completion.
79 * If outCount is 0, this routine completes successfully WITHOUT waiting
80 * for the mailbox command to complete.
82 int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
83 uint8_t outCount, uint32_t *mbx_cmd,
86 int status = QLA_ERROR;
89 unsigned long flags = 0;
92 /* Make sure that pointers are valid */
93 if (!mbx_cmd || !mbx_sts) {
94 DEBUG2(printk("scsi%ld: %s: Invalid mbx_cmd or mbx_sts "
95 "pointer\n", ha->host_no, __func__));
100 if (test_bit(AF_HA_REMOVAL, &ha->flags)) {
101 DEBUG2(ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: "
102 "prematurely completing mbx cmd as "
103 "adapter removal detected\n",
104 ha->host_no, __func__));
109 if ((is_aer_supported(ha)) &&
110 (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))) {
111 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Perm failure on EEH, "
112 "timeout MBX Exiting.\n", ha->host_no, __func__));
116 /* Mailbox code active */
117 wait_count = MBOX_TOV * 100;
119 while (wait_count--) {
120 mutex_lock(&ha->mbox_sem);
121 if (!test_bit(AF_MBOX_COMMAND, &ha->flags)) {
122 set_bit(AF_MBOX_COMMAND, &ha->flags);
123 mutex_unlock(&ha->mbox_sem);
126 mutex_unlock(&ha->mbox_sem);
128 DEBUG2(printk("scsi%ld: %s: mbox_sem failed\n",
129 ha->host_no, __func__));
135 if (is_qla80XX(ha)) {
136 if (test_bit(AF_FW_RECOVERY, &ha->flags)) {
137 DEBUG2(ql4_printk(KERN_WARNING, ha,
138 "scsi%ld: %s: prematurely completing mbx cmd as firmware recovery detected\n",
139 ha->host_no, __func__));
142 /* Do not send any mbx cmd if h/w is in failed state*/
143 ha->isp_ops->idc_lock(ha);
144 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
145 ha->isp_ops->idc_unlock(ha);
146 if (dev_state == QLA8XXX_DEV_FAILED) {
147 ql4_printk(KERN_WARNING, ha,
148 "scsi%ld: %s: H/W is in failed state, do not send any mailbox commands\n",
149 ha->host_no, __func__);
154 spin_lock_irqsave(&ha->hardware_lock, flags);
156 ha->mbox_status_count = outCount;
157 for (i = 0; i < outCount; i++)
158 ha->mbox_status[i] = 0;
160 /* Queue the mailbox command to the firmware */
161 ha->isp_ops->queue_mailbox_command(ha, mbx_cmd, inCount);
163 spin_unlock_irqrestore(&ha->hardware_lock, flags);
165 /* Wait for completion */
168 * If we don't want status, don't wait for the mailbox command to
169 * complete. For example, MBOX_CMD_RESET_FW doesn't return status,
170 * you must poll the inbound Interrupt Mask for completion.
173 status = QLA_SUCCESS;
178 * Wait for completion: Poll or completion queue
180 if (qla4xxx_is_intr_poll_mode(ha)) {
181 /* Poll for command to complete */
182 wait_count = jiffies + MBOX_TOV * HZ;
183 while (test_bit(AF_MBOX_COMMAND_DONE, &ha->flags) == 0) {
184 if (time_after_eq(jiffies, wait_count))
187 * Service the interrupt.
188 * The ISR will save the mailbox status registers
189 * to a temporary storage location in the adapter
192 spin_lock_irqsave(&ha->hardware_lock, flags);
193 ha->isp_ops->process_mailbox_interrupt(ha, outCount);
194 spin_unlock_irqrestore(&ha->hardware_lock, flags);
198 /* Do not poll for completion. Use completion queue */
199 set_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
200 wait_for_completion_timeout(&ha->mbx_intr_comp, MBOX_TOV * HZ);
201 clear_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
204 /* Check for mailbox timeout. */
205 if (!test_bit(AF_MBOX_COMMAND_DONE, &ha->flags)) {
206 if (is_qla80XX(ha) &&
207 test_bit(AF_FW_RECOVERY, &ha->flags)) {
208 DEBUG2(ql4_printk(KERN_INFO, ha,
209 "scsi%ld: %s: prematurely completing mbx cmd as "
210 "firmware recovery detected\n",
211 ha->host_no, __func__));
214 DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
215 " Scheduling Adapter Reset\n", ha->host_no,
217 ha->mailbox_timeout_count++;
219 set_bit(DPC_RESET_HA, &ha->dpc_flags);
220 if (is_qla8022(ha)) {
221 ql4_printk(KERN_INFO, ha,
222 "disabling pause transmit on port 0 & 1.\n");
223 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
224 CRB_NIU_XG_PAUSE_CTL_P0 |
225 CRB_NIU_XG_PAUSE_CTL_P1);
226 } else if (is_qla8032(ha)) {
227 ql4_printk(KERN_INFO, ha, " %s: disabling pause transmit on port 0 & 1.\n",
229 qla4_83xx_disable_pause(ha);
235 * Copy the mailbox out registers to the caller's mailbox in/out
238 spin_lock_irqsave(&ha->hardware_lock, flags);
239 for (i = 0; i < outCount; i++)
240 mbx_sts[i] = ha->mbox_status[i];
242 /* Set return status and error flags (if applicable). */
243 switch (ha->mbox_status[0]) {
244 case MBOX_STS_COMMAND_COMPLETE:
245 status = QLA_SUCCESS;
248 case MBOX_STS_INTERMEDIATE_COMPLETION:
249 status = QLA_SUCCESS;
253 DEBUG2( printk("scsi%ld: %s: Cmd = %08X, ISP BUSY\n",
254 ha->host_no, __func__, mbx_cmd[0]));
255 ha->mailbox_timeout_count++;
259 DEBUG2(printk("scsi%ld: %s: **** FAILED, cmd = %08X, "
260 "sts = %08X ****\n", ha->host_no, __func__,
261 mbx_cmd[0], mbx_sts[0]));
264 spin_unlock_irqrestore(&ha->hardware_lock, flags);
267 mutex_lock(&ha->mbox_sem);
268 clear_bit(AF_MBOX_COMMAND, &ha->flags);
269 mutex_unlock(&ha->mbox_sem);
270 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
276 * qla4xxx_get_minidump_template - Get the firmware template
277 * @ha: Pointer to host adapter structure.
278 * @phys_addr: dma address for template
280 * Obtain the minidump template from firmware during initialization
281 * as it may not be available when minidump is desired.
283 int qla4xxx_get_minidump_template(struct scsi_qla_host *ha,
284 dma_addr_t phys_addr)
286 uint32_t mbox_cmd[MBOX_REG_COUNT];
287 uint32_t mbox_sts[MBOX_REG_COUNT];
290 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
291 memset(&mbox_sts, 0, sizeof(mbox_sts));
293 mbox_cmd[0] = MBOX_CMD_MINIDUMP;
294 mbox_cmd[1] = MINIDUMP_GET_TMPLT_SUBCOMMAND;
295 mbox_cmd[2] = LSDW(phys_addr);
296 mbox_cmd[3] = MSDW(phys_addr);
297 mbox_cmd[4] = ha->fw_dump_tmplt_size;
300 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
302 if (status != QLA_SUCCESS) {
303 DEBUG2(ql4_printk(KERN_INFO, ha,
304 "scsi%ld: %s: Cmd = %08X, mbx[0] = 0x%04x, mbx[1] = 0x%04x\n",
305 ha->host_no, __func__, mbox_cmd[0],
306 mbox_sts[0], mbox_sts[1]));
312 * qla4xxx_req_template_size - Get minidump template size from firmware.
313 * @ha: Pointer to host adapter structure.
315 int qla4xxx_req_template_size(struct scsi_qla_host *ha)
317 uint32_t mbox_cmd[MBOX_REG_COUNT];
318 uint32_t mbox_sts[MBOX_REG_COUNT];
321 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
322 memset(&mbox_sts, 0, sizeof(mbox_sts));
324 mbox_cmd[0] = MBOX_CMD_MINIDUMP;
325 mbox_cmd[1] = MINIDUMP_GET_SIZE_SUBCOMMAND;
327 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 8, &mbox_cmd[0],
329 if (status == QLA_SUCCESS) {
330 ha->fw_dump_tmplt_size = mbox_sts[1];
331 DEBUG2(ql4_printk(KERN_INFO, ha,
332 "%s: sts[0]=0x%04x, template size=0x%04x, size_cm_02=0x%04x, size_cm_04=0x%04x, size_cm_08=0x%04x, size_cm_10=0x%04x, size_cm_FF=0x%04x, version=0x%04x\n",
333 __func__, mbox_sts[0], mbox_sts[1],
334 mbox_sts[2], mbox_sts[3], mbox_sts[4],
335 mbox_sts[5], mbox_sts[6], mbox_sts[7]));
336 if (ha->fw_dump_tmplt_size == 0)
339 ql4_printk(KERN_WARNING, ha,
340 "%s: Error sts[0]=0x%04x, mbx[1]=0x%04x\n",
341 __func__, mbox_sts[0], mbox_sts[1]);
348 void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha)
350 set_bit(AF_FW_RECOVERY, &ha->flags);
351 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: set FW RECOVERY!\n",
352 ha->host_no, __func__);
354 if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
355 if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags)) {
356 complete(&ha->mbx_intr_comp);
357 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
358 "recovery, doing premature completion of "
359 "mbx cmd\n", ha->host_no, __func__);
362 set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
363 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
364 "recovery, doing premature completion of "
365 "polling mbx cmd\n", ha->host_no, __func__);
371 qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
372 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
374 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
375 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
378 qla4_82xx_wr_32(ha, ha->nx_db_wr_ptr, 0);
380 mbox_cmd[0] = MBOX_CMD_INITIALIZE_FIRMWARE;
382 mbox_cmd[2] = LSDW(init_fw_cb_dma);
383 mbox_cmd[3] = MSDW(init_fw_cb_dma);
384 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
385 mbox_cmd[5] = (IFCB_VER_MAX << 8) | IFCB_VER_MIN;
387 if (qla4xxx_mailbox_command(ha, 6, 6, mbox_cmd, mbox_sts) !=
389 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
390 "MBOX_CMD_INITIALIZE_FIRMWARE"
391 " failed w/ status %04X\n",
392 ha->host_no, __func__, mbox_sts[0]));
399 qla4xxx_get_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
400 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
402 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
403 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
404 mbox_cmd[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK;
405 mbox_cmd[2] = LSDW(init_fw_cb_dma);
406 mbox_cmd[3] = MSDW(init_fw_cb_dma);
407 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
409 if (qla4xxx_mailbox_command(ha, 5, 5, mbox_cmd, mbox_sts) !=
411 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
412 "MBOX_CMD_GET_INIT_FW_CTRL_BLOCK"
413 " failed w/ status %04X\n",
414 ha->host_no, __func__, mbox_sts[0]));
421 qla4xxx_update_local_ip(struct scsi_qla_host *ha,
422 struct addr_ctrl_blk *init_fw_cb)
424 ha->ip_config.tcp_options = le16_to_cpu(init_fw_cb->ipv4_tcp_opts);
425 ha->ip_config.ipv4_options = le16_to_cpu(init_fw_cb->ipv4_ip_opts);
426 ha->ip_config.ipv4_addr_state =
427 le16_to_cpu(init_fw_cb->ipv4_addr_state);
428 ha->ip_config.eth_mtu_size =
429 le16_to_cpu(init_fw_cb->eth_mtu_size);
430 ha->ip_config.ipv4_port = le16_to_cpu(init_fw_cb->ipv4_port);
432 if (ha->acb_version == ACB_SUPPORTED) {
433 ha->ip_config.ipv6_options = le16_to_cpu(init_fw_cb->ipv6_opts);
434 ha->ip_config.ipv6_addl_options =
435 le16_to_cpu(init_fw_cb->ipv6_addtl_opts);
438 /* Save IPv4 Address Info */
439 memcpy(ha->ip_config.ip_address, init_fw_cb->ipv4_addr,
440 min(sizeof(ha->ip_config.ip_address),
441 sizeof(init_fw_cb->ipv4_addr)));
442 memcpy(ha->ip_config.subnet_mask, init_fw_cb->ipv4_subnet,
443 min(sizeof(ha->ip_config.subnet_mask),
444 sizeof(init_fw_cb->ipv4_subnet)));
445 memcpy(ha->ip_config.gateway, init_fw_cb->ipv4_gw_addr,
446 min(sizeof(ha->ip_config.gateway),
447 sizeof(init_fw_cb->ipv4_gw_addr)));
449 ha->ip_config.ipv4_vlan_tag = be16_to_cpu(init_fw_cb->ipv4_vlan_tag);
451 if (is_ipv6_enabled(ha)) {
452 /* Save IPv6 Address */
453 ha->ip_config.ipv6_link_local_state =
454 le16_to_cpu(init_fw_cb->ipv6_lnk_lcl_addr_state);
455 ha->ip_config.ipv6_addr0_state =
456 le16_to_cpu(init_fw_cb->ipv6_addr0_state);
457 ha->ip_config.ipv6_addr1_state =
458 le16_to_cpu(init_fw_cb->ipv6_addr1_state);
459 ha->ip_config.ipv6_default_router_state =
460 le16_to_cpu(init_fw_cb->ipv6_dflt_rtr_state);
461 ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[0] = 0xFE;
462 ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[1] = 0x80;
464 memcpy(&ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[8],
465 init_fw_cb->ipv6_if_id,
466 min(sizeof(ha->ip_config.ipv6_link_local_addr)/2,
467 sizeof(init_fw_cb->ipv6_if_id)));
468 memcpy(&ha->ip_config.ipv6_addr0, init_fw_cb->ipv6_addr0,
469 min(sizeof(ha->ip_config.ipv6_addr0),
470 sizeof(init_fw_cb->ipv6_addr0)));
471 memcpy(&ha->ip_config.ipv6_addr1, init_fw_cb->ipv6_addr1,
472 min(sizeof(ha->ip_config.ipv6_addr1),
473 sizeof(init_fw_cb->ipv6_addr1)));
474 memcpy(&ha->ip_config.ipv6_default_router_addr,
475 init_fw_cb->ipv6_dflt_rtr_addr,
476 min(sizeof(ha->ip_config.ipv6_default_router_addr),
477 sizeof(init_fw_cb->ipv6_dflt_rtr_addr)));
478 ha->ip_config.ipv6_vlan_tag =
479 be16_to_cpu(init_fw_cb->ipv6_vlan_tag);
480 ha->ip_config.ipv6_port = le16_to_cpu(init_fw_cb->ipv6_port);
485 qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
488 struct addr_ctrl_blk *init_fw_cb,
489 dma_addr_t init_fw_cb_dma)
491 if (qla4xxx_get_ifcb(ha, mbox_cmd, mbox_sts, init_fw_cb_dma)
493 DEBUG2(printk(KERN_WARNING
494 "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
495 ha->host_no, __func__));
499 DEBUG2(qla4xxx_dump_buffer(init_fw_cb, sizeof(struct addr_ctrl_blk)));
501 /* Save some info in adapter structure. */
502 ha->acb_version = init_fw_cb->acb_version;
503 ha->firmware_options = le16_to_cpu(init_fw_cb->fw_options);
504 ha->heartbeat_interval = init_fw_cb->hb_interval;
505 memcpy(ha->name_string, init_fw_cb->iscsi_name,
506 min(sizeof(ha->name_string),
507 sizeof(init_fw_cb->iscsi_name)));
508 ha->def_timeout = le16_to_cpu(init_fw_cb->def_timeout);
509 /*memcpy(ha->alias, init_fw_cb->Alias,
510 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
512 qla4xxx_update_local_ip(ha, init_fw_cb);
518 * qla4xxx_initialize_fw_cb - initializes firmware control block.
519 * @ha: Pointer to host adapter structure.
521 int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
523 struct addr_ctrl_blk *init_fw_cb;
524 dma_addr_t init_fw_cb_dma;
525 uint32_t mbox_cmd[MBOX_REG_COUNT];
526 uint32_t mbox_sts[MBOX_REG_COUNT];
527 int status = QLA_ERROR;
529 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
530 sizeof(struct addr_ctrl_blk),
531 &init_fw_cb_dma, GFP_KERNEL);
532 if (init_fw_cb == NULL) {
533 DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
534 ha->host_no, __func__));
535 goto exit_init_fw_cb_no_free;
537 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
539 /* Get Initialize Firmware Control Block. */
540 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
541 memset(&mbox_sts, 0, sizeof(mbox_sts));
543 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
545 dma_free_coherent(&ha->pdev->dev,
546 sizeof(struct addr_ctrl_blk),
547 init_fw_cb, init_fw_cb_dma);
548 goto exit_init_fw_cb;
551 /* Initialize request and response queues. */
552 qla4xxx_init_rings(ha);
554 /* Fill in the request and response queue information. */
555 init_fw_cb->rqq_consumer_idx = cpu_to_le16(ha->request_out);
556 init_fw_cb->compq_producer_idx = cpu_to_le16(ha->response_in);
557 init_fw_cb->rqq_len = __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH);
558 init_fw_cb->compq_len = __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH);
559 init_fw_cb->rqq_addr_lo = cpu_to_le32(LSDW(ha->request_dma));
560 init_fw_cb->rqq_addr_hi = cpu_to_le32(MSDW(ha->request_dma));
561 init_fw_cb->compq_addr_lo = cpu_to_le32(LSDW(ha->response_dma));
562 init_fw_cb->compq_addr_hi = cpu_to_le32(MSDW(ha->response_dma));
563 init_fw_cb->shdwreg_addr_lo = cpu_to_le32(LSDW(ha->shadow_regs_dma));
564 init_fw_cb->shdwreg_addr_hi = cpu_to_le32(MSDW(ha->shadow_regs_dma));
566 /* Set up required options. */
567 init_fw_cb->fw_options |=
568 __constant_cpu_to_le16(FWOPT_SESSION_MODE |
569 FWOPT_INITIATOR_MODE);
572 init_fw_cb->fw_options |=
573 __constant_cpu_to_le16(FWOPT_ENABLE_CRBDB);
575 init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
577 init_fw_cb->add_fw_options = 0;
578 init_fw_cb->add_fw_options |=
579 __constant_cpu_to_le16(ADFWOPT_SERIALIZE_TASK_MGMT);
580 init_fw_cb->add_fw_options |=
581 __constant_cpu_to_le16(ADFWOPT_AUTOCONN_DISABLE);
583 if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
585 DEBUG2(printk(KERN_WARNING
586 "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
587 ha->host_no, __func__));
588 goto exit_init_fw_cb;
591 if (qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0],
592 init_fw_cb, init_fw_cb_dma) != QLA_SUCCESS) {
593 DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
594 ha->host_no, __func__));
595 goto exit_init_fw_cb;
597 status = QLA_SUCCESS;
600 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
601 init_fw_cb, init_fw_cb_dma);
602 exit_init_fw_cb_no_free:
607 * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
608 * @ha: Pointer to host adapter structure.
610 int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host * ha)
612 struct addr_ctrl_blk *init_fw_cb;
613 dma_addr_t init_fw_cb_dma;
614 uint32_t mbox_cmd[MBOX_REG_COUNT];
615 uint32_t mbox_sts[MBOX_REG_COUNT];
617 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
618 sizeof(struct addr_ctrl_blk),
619 &init_fw_cb_dma, GFP_KERNEL);
620 if (init_fw_cb == NULL) {
621 printk("scsi%ld: %s: Unable to alloc init_cb\n", ha->host_no,
626 /* Get Initialize Firmware Control Block. */
627 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
628 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
630 DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
631 ha->host_no, __func__));
632 dma_free_coherent(&ha->pdev->dev,
633 sizeof(struct addr_ctrl_blk),
634 init_fw_cb, init_fw_cb_dma);
638 /* Save IP Address. */
639 qla4xxx_update_local_ip(ha, init_fw_cb);
640 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
641 init_fw_cb, init_fw_cb_dma);
647 * qla4xxx_get_firmware_state - gets firmware state of HBA
648 * @ha: Pointer to host adapter structure.
650 int qla4xxx_get_firmware_state(struct scsi_qla_host * ha)
652 uint32_t mbox_cmd[MBOX_REG_COUNT];
653 uint32_t mbox_sts[MBOX_REG_COUNT];
655 /* Get firmware version */
656 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
657 memset(&mbox_sts, 0, sizeof(mbox_sts));
659 mbox_cmd[0] = MBOX_CMD_GET_FW_STATE;
661 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 4, &mbox_cmd[0], &mbox_sts[0]) !=
663 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
664 "status %04X\n", ha->host_no, __func__,
668 ha->firmware_state = mbox_sts[1];
669 ha->board_id = mbox_sts[2];
670 ha->addl_fw_state = mbox_sts[3];
671 DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
672 ha->host_no, __func__, ha->firmware_state);)
678 * qla4xxx_get_firmware_status - retrieves firmware status
679 * @ha: Pointer to host adapter structure.
681 int qla4xxx_get_firmware_status(struct scsi_qla_host * ha)
683 uint32_t mbox_cmd[MBOX_REG_COUNT];
684 uint32_t mbox_sts[MBOX_REG_COUNT];
686 /* Get firmware version */
687 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
688 memset(&mbox_sts, 0, sizeof(mbox_sts));
690 mbox_cmd[0] = MBOX_CMD_GET_FW_STATUS;
692 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
694 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
695 "status %04X\n", ha->host_no, __func__,
700 /* High-water mark of IOCBs */
701 ha->iocb_hiwat = mbox_sts[2];
702 DEBUG2(ql4_printk(KERN_INFO, ha,
703 "%s: firmware IOCBs available = %d\n", __func__,
706 if (ha->iocb_hiwat > IOCB_HIWAT_CUSHION)
707 ha->iocb_hiwat -= IOCB_HIWAT_CUSHION;
709 /* Ideally, we should not enter this code, as the # of firmware
710 * IOCBs is hard-coded in the firmware. We set a default
711 * iocb_hiwat here just in case */
712 if (ha->iocb_hiwat == 0) {
713 ha->iocb_hiwat = REQUEST_QUEUE_DEPTH / 4;
714 DEBUG2(ql4_printk(KERN_WARNING, ha,
715 "%s: Setting IOCB's to = %d\n", __func__,
723 * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
724 * @ha: Pointer to host adapter structure.
725 * @fw_ddb_index: Firmware's device database index
726 * @fw_ddb_entry: Pointer to firmware's device database entry structure
727 * @num_valid_ddb_entries: Pointer to number of valid ddb entries
728 * @next_ddb_index: Pointer to next valid device database index
729 * @fw_ddb_device_state: Pointer to device state
731 int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
732 uint16_t fw_ddb_index,
733 struct dev_db_entry *fw_ddb_entry,
734 dma_addr_t fw_ddb_entry_dma,
735 uint32_t *num_valid_ddb_entries,
736 uint32_t *next_ddb_index,
737 uint32_t *fw_ddb_device_state,
738 uint32_t *conn_err_detail,
739 uint16_t *tcp_source_port_num,
740 uint16_t *connection_id)
742 int status = QLA_ERROR;
744 uint32_t mbox_cmd[MBOX_REG_COUNT];
745 uint32_t mbox_sts[MBOX_REG_COUNT];
747 /* Make sure the device index is valid */
748 if (fw_ddb_index >= MAX_DDB_ENTRIES) {
749 DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
750 ha->host_no, __func__, fw_ddb_index));
753 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
754 memset(&mbox_sts, 0, sizeof(mbox_sts));
756 memset(fw_ddb_entry, 0, sizeof(struct dev_db_entry));
758 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY;
759 mbox_cmd[1] = (uint32_t) fw_ddb_index;
760 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
761 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
762 mbox_cmd[4] = sizeof(struct dev_db_entry);
764 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 7, &mbox_cmd[0], &mbox_sts[0]) ==
766 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
767 " with status 0x%04X\n", ha->host_no, __func__,
771 if (fw_ddb_index != mbox_sts[1]) {
772 DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
773 ha->host_no, __func__, fw_ddb_index,
778 options = le16_to_cpu(fw_ddb_entry->options);
779 if (options & DDB_OPT_IPV6_DEVICE) {
780 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
781 "Next %d State %04x ConnErr %08x %pI6 "
782 ":%04d \"%s\"\n", __func__, fw_ddb_index,
783 mbox_sts[0], mbox_sts[2], mbox_sts[3],
784 mbox_sts[4], mbox_sts[5],
785 fw_ddb_entry->ip_addr,
786 le16_to_cpu(fw_ddb_entry->port),
787 fw_ddb_entry->iscsi_name);
789 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
790 "Next %d State %04x ConnErr %08x %pI4 "
791 ":%04d \"%s\"\n", __func__, fw_ddb_index,
792 mbox_sts[0], mbox_sts[2], mbox_sts[3],
793 mbox_sts[4], mbox_sts[5],
794 fw_ddb_entry->ip_addr,
795 le16_to_cpu(fw_ddb_entry->port),
796 fw_ddb_entry->iscsi_name);
799 if (num_valid_ddb_entries)
800 *num_valid_ddb_entries = mbox_sts[2];
802 *next_ddb_index = mbox_sts[3];
803 if (fw_ddb_device_state)
804 *fw_ddb_device_state = mbox_sts[4];
807 * RA: This mailbox has been changed to pass connection error and
808 * details. Its true for ISP4010 as per Version E - Not sure when it
809 * was changed. Get the time2wait from the fw_dd_entry field :
810 * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
814 *conn_err_detail = mbox_sts[5];
815 if (tcp_source_port_num)
816 *tcp_source_port_num = (uint16_t) (mbox_sts[6] >> 16);
818 *connection_id = (uint16_t) mbox_sts[6] & 0x00FF;
819 status = QLA_SUCCESS;
825 int qla4xxx_conn_open(struct scsi_qla_host *ha, uint16_t fw_ddb_index)
827 uint32_t mbox_cmd[MBOX_REG_COUNT];
828 uint32_t mbox_sts[MBOX_REG_COUNT];
831 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
832 memset(&mbox_sts, 0, sizeof(mbox_sts));
834 mbox_cmd[0] = MBOX_CMD_CONN_OPEN;
835 mbox_cmd[1] = fw_ddb_index;
837 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
839 DEBUG2(ql4_printk(KERN_INFO, ha,
840 "%s: status = %d mbx0 = 0x%x mbx1 = 0x%x\n",
841 __func__, status, mbox_sts[0], mbox_sts[1]));
846 * qla4xxx_set_fwddb_entry - sets a ddb entry.
847 * @ha: Pointer to host adapter structure.
848 * @fw_ddb_index: Firmware's device database index
849 * @fw_ddb_entry_dma: dma address of ddb entry
850 * @mbx_sts: mailbox 0 to be returned or NULL
852 * This routine initializes or updates the adapter's device database
853 * entry for the specified device.
855 int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
856 dma_addr_t fw_ddb_entry_dma, uint32_t *mbx_sts)
858 uint32_t mbox_cmd[MBOX_REG_COUNT];
859 uint32_t mbox_sts[MBOX_REG_COUNT];
862 /* Do not wait for completion. The firmware will send us an
863 * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
865 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
866 memset(&mbox_sts, 0, sizeof(mbox_sts));
868 mbox_cmd[0] = MBOX_CMD_SET_DATABASE_ENTRY;
869 mbox_cmd[1] = (uint32_t) fw_ddb_index;
870 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
871 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
872 mbox_cmd[4] = sizeof(struct dev_db_entry);
874 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
877 *mbx_sts = mbox_sts[0];
878 DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
879 ha->host_no, __func__, status, mbox_sts[0], mbox_sts[4]);)
884 int qla4xxx_session_logout_ddb(struct scsi_qla_host *ha,
885 struct ddb_entry *ddb_entry, int options)
888 uint32_t mbox_cmd[MBOX_REG_COUNT];
889 uint32_t mbox_sts[MBOX_REG_COUNT];
891 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
892 memset(&mbox_sts, 0, sizeof(mbox_sts));
894 mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
895 mbox_cmd[1] = ddb_entry->fw_ddb_index;
896 mbox_cmd[3] = options;
898 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
900 if (status != QLA_SUCCESS) {
901 DEBUG2(ql4_printk(KERN_INFO, ha,
902 "%s: MBOX_CMD_CONN_CLOSE_SESS_LOGOUT "
903 "failed sts %04X %04X", __func__,
904 mbox_sts[0], mbox_sts[1]));
911 * qla4xxx_get_crash_record - retrieves crash record.
912 * @ha: Pointer to host adapter structure.
914 * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
916 void qla4xxx_get_crash_record(struct scsi_qla_host * ha)
918 uint32_t mbox_cmd[MBOX_REG_COUNT];
919 uint32_t mbox_sts[MBOX_REG_COUNT];
920 struct crash_record *crash_record = NULL;
921 dma_addr_t crash_record_dma = 0;
922 uint32_t crash_record_size = 0;
924 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
925 memset(&mbox_sts, 0, sizeof(mbox_cmd));
927 /* Get size of crash record. */
928 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
930 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
932 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
933 ha->host_no, __func__));
934 goto exit_get_crash_record;
936 crash_record_size = mbox_sts[4];
937 if (crash_record_size == 0) {
938 DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
939 ha->host_no, __func__));
940 goto exit_get_crash_record;
943 /* Alloc Memory for Crash Record. */
944 crash_record = dma_alloc_coherent(&ha->pdev->dev, crash_record_size,
945 &crash_record_dma, GFP_KERNEL);
946 if (crash_record == NULL)
947 goto exit_get_crash_record;
949 /* Get Crash Record. */
950 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
951 memset(&mbox_sts, 0, sizeof(mbox_cmd));
953 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
954 mbox_cmd[2] = LSDW(crash_record_dma);
955 mbox_cmd[3] = MSDW(crash_record_dma);
956 mbox_cmd[4] = crash_record_size;
958 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
960 goto exit_get_crash_record;
962 /* Dump Crash Record. */
964 exit_get_crash_record:
966 dma_free_coherent(&ha->pdev->dev, crash_record_size,
967 crash_record, crash_record_dma);
971 * qla4xxx_get_conn_event_log - retrieves connection event log
972 * @ha: Pointer to host adapter structure.
974 void qla4xxx_get_conn_event_log(struct scsi_qla_host * ha)
976 uint32_t mbox_cmd[MBOX_REG_COUNT];
977 uint32_t mbox_sts[MBOX_REG_COUNT];
978 struct conn_event_log_entry *event_log = NULL;
979 dma_addr_t event_log_dma = 0;
980 uint32_t event_log_size = 0;
981 uint32_t num_valid_entries;
982 uint32_t oldest_entry = 0;
983 uint32_t max_event_log_entries;
986 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
987 memset(&mbox_sts, 0, sizeof(mbox_cmd));
989 /* Get size of crash record. */
990 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
992 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
994 goto exit_get_event_log;
996 event_log_size = mbox_sts[4];
997 if (event_log_size == 0)
998 goto exit_get_event_log;
1000 /* Alloc Memory for Crash Record. */
1001 event_log = dma_alloc_coherent(&ha->pdev->dev, event_log_size,
1002 &event_log_dma, GFP_KERNEL);
1003 if (event_log == NULL)
1004 goto exit_get_event_log;
1006 /* Get Crash Record. */
1007 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1008 memset(&mbox_sts, 0, sizeof(mbox_cmd));
1010 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
1011 mbox_cmd[2] = LSDW(event_log_dma);
1012 mbox_cmd[3] = MSDW(event_log_dma);
1014 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
1016 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
1017 "log!\n", ha->host_no, __func__));
1018 goto exit_get_event_log;
1021 /* Dump Event Log. */
1022 num_valid_entries = mbox_sts[1];
1024 max_event_log_entries = event_log_size /
1025 sizeof(struct conn_event_log_entry);
1027 if (num_valid_entries > max_event_log_entries)
1028 oldest_entry = num_valid_entries % max_event_log_entries;
1030 DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
1031 ha->host_no, num_valid_entries));
1033 if (ql4xextended_error_logging == 3) {
1034 if (oldest_entry == 0) {
1035 /* Circular Buffer has not wrapped around */
1036 for (i=0; i < num_valid_entries; i++) {
1037 qla4xxx_dump_buffer((uint8_t *)event_log+
1038 (i*sizeof(*event_log)),
1039 sizeof(*event_log));
1043 /* Circular Buffer has wrapped around -
1044 * display accordingly*/
1045 for (i=oldest_entry; i < max_event_log_entries; i++) {
1046 qla4xxx_dump_buffer((uint8_t *)event_log+
1047 (i*sizeof(*event_log)),
1048 sizeof(*event_log));
1050 for (i=0; i < oldest_entry; i++) {
1051 qla4xxx_dump_buffer((uint8_t *)event_log+
1052 (i*sizeof(*event_log)),
1053 sizeof(*event_log));
1060 dma_free_coherent(&ha->pdev->dev, event_log_size, event_log,
1065 * qla4xxx_abort_task - issues Abort Task
1066 * @ha: Pointer to host adapter structure.
1067 * @srb: Pointer to srb entry
1069 * This routine performs a LUN RESET on the specified target/lun.
1070 * The caller must ensure that the ddb_entry and lun_entry pointers
1071 * are valid before calling this routine.
1073 int qla4xxx_abort_task(struct scsi_qla_host *ha, struct srb *srb)
1075 uint32_t mbox_cmd[MBOX_REG_COUNT];
1076 uint32_t mbox_sts[MBOX_REG_COUNT];
1077 struct scsi_cmnd *cmd = srb->cmd;
1078 int status = QLA_SUCCESS;
1079 unsigned long flags = 0;
1083 * Send abort task command to ISP, so that the ISP will return
1084 * request with ABORT status
1086 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1087 memset(&mbox_sts, 0, sizeof(mbox_sts));
1089 spin_lock_irqsave(&ha->hardware_lock, flags);
1090 index = (unsigned long)(unsigned char *)cmd->host_scribble;
1091 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1093 /* Firmware already posted completion on response queue */
1094 if (index == MAX_SRBS)
1097 mbox_cmd[0] = MBOX_CMD_ABORT_TASK;
1098 mbox_cmd[1] = srb->ddb->fw_ddb_index;
1099 mbox_cmd[2] = index;
1100 /* Immediate Command Enable */
1103 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
1105 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE) {
1108 DEBUG2(printk(KERN_WARNING "scsi%ld:%d:%d: abort task FAILED: "
1109 "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
1110 ha->host_no, cmd->device->id, cmd->device->lun, mbox_sts[0],
1111 mbox_sts[1], mbox_sts[2], mbox_sts[3], mbox_sts[4]));
1118 * qla4xxx_reset_lun - issues LUN Reset
1119 * @ha: Pointer to host adapter structure.
1120 * @ddb_entry: Pointer to device database entry
1123 * This routine performs a LUN RESET on the specified target/lun.
1124 * The caller must ensure that the ddb_entry and lun_entry pointers
1125 * are valid before calling this routine.
1127 int qla4xxx_reset_lun(struct scsi_qla_host * ha, struct ddb_entry * ddb_entry,
1130 uint32_t mbox_cmd[MBOX_REG_COUNT];
1131 uint32_t mbox_sts[MBOX_REG_COUNT];
1132 int status = QLA_SUCCESS;
1134 DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha->host_no,
1135 ddb_entry->fw_ddb_index, lun));
1138 * Send lun reset command to ISP, so that the ISP will return all
1139 * outstanding requests with RESET status
1141 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1142 memset(&mbox_sts, 0, sizeof(mbox_sts));
1144 mbox_cmd[0] = MBOX_CMD_LUN_RESET;
1145 mbox_cmd[1] = ddb_entry->fw_ddb_index;
1146 mbox_cmd[2] = lun << 8;
1147 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
1149 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]);
1150 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
1151 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
1158 * qla4xxx_reset_target - issues target Reset
1159 * @ha: Pointer to host adapter structure.
1160 * @db_entry: Pointer to device database entry
1161 * @un_entry: Pointer to lun entry structure
1163 * This routine performs a TARGET RESET on the specified target.
1164 * The caller must ensure that the ddb_entry pointers
1165 * are valid before calling this routine.
1167 int qla4xxx_reset_target(struct scsi_qla_host *ha,
1168 struct ddb_entry *ddb_entry)
1170 uint32_t mbox_cmd[MBOX_REG_COUNT];
1171 uint32_t mbox_sts[MBOX_REG_COUNT];
1172 int status = QLA_SUCCESS;
1174 DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha->host_no,
1175 ddb_entry->fw_ddb_index));
1178 * Send target reset command to ISP, so that the ISP will return all
1179 * outstanding requests with RESET status
1181 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1182 memset(&mbox_sts, 0, sizeof(mbox_sts));
1184 mbox_cmd[0] = MBOX_CMD_TARGET_WARM_RESET;
1185 mbox_cmd[1] = ddb_entry->fw_ddb_index;
1186 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
1188 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1190 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
1191 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
1197 int qla4xxx_get_flash(struct scsi_qla_host * ha, dma_addr_t dma_addr,
1198 uint32_t offset, uint32_t len)
1200 uint32_t mbox_cmd[MBOX_REG_COUNT];
1201 uint32_t mbox_sts[MBOX_REG_COUNT];
1203 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1204 memset(&mbox_sts, 0, sizeof(mbox_sts));
1206 mbox_cmd[0] = MBOX_CMD_READ_FLASH;
1207 mbox_cmd[1] = LSDW(dma_addr);
1208 mbox_cmd[2] = MSDW(dma_addr);
1209 mbox_cmd[3] = offset;
1212 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0], &mbox_sts[0]) !=
1214 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
1215 "status %04X %04X, offset %08x, len %08x\n", ha->host_no,
1216 __func__, mbox_sts[0], mbox_sts[1], offset, len));
1223 * qla4xxx_about_firmware - gets FW, iscsi draft and boot loader version
1224 * @ha: Pointer to host adapter structure.
1226 * Retrieves the FW version, iSCSI draft version & bootloader version of HBA.
1227 * Mailboxes 2 & 3 may hold an address for data. Make sure that we write 0 to
1228 * those mailboxes, if unused.
1230 int qla4xxx_about_firmware(struct scsi_qla_host *ha)
1232 struct about_fw_info *about_fw = NULL;
1233 dma_addr_t about_fw_dma;
1234 uint32_t mbox_cmd[MBOX_REG_COUNT];
1235 uint32_t mbox_sts[MBOX_REG_COUNT];
1236 int status = QLA_ERROR;
1238 about_fw = dma_alloc_coherent(&ha->pdev->dev,
1239 sizeof(struct about_fw_info),
1240 &about_fw_dma, GFP_KERNEL);
1242 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Unable to alloc memory "
1243 "for about_fw\n", __func__));
1247 memset(about_fw, 0, sizeof(struct about_fw_info));
1248 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1249 memset(&mbox_sts, 0, sizeof(mbox_sts));
1251 mbox_cmd[0] = MBOX_CMD_ABOUT_FW;
1252 mbox_cmd[2] = LSDW(about_fw_dma);
1253 mbox_cmd[3] = MSDW(about_fw_dma);
1254 mbox_cmd[4] = sizeof(struct about_fw_info);
1256 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, MBOX_REG_COUNT,
1257 &mbox_cmd[0], &mbox_sts[0]);
1258 if (status != QLA_SUCCESS) {
1259 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_ABOUT_FW "
1260 "failed w/ status %04X\n", __func__,
1265 /* Save version information. */
1266 ha->firmware_version[0] = le16_to_cpu(about_fw->fw_major);
1267 ha->firmware_version[1] = le16_to_cpu(about_fw->fw_minor);
1268 ha->patch_number = le16_to_cpu(about_fw->fw_patch);
1269 ha->build_number = le16_to_cpu(about_fw->fw_build);
1270 ha->iscsi_major = le16_to_cpu(about_fw->iscsi_major);
1271 ha->iscsi_minor = le16_to_cpu(about_fw->iscsi_minor);
1272 ha->bootload_major = le16_to_cpu(about_fw->bootload_major);
1273 ha->bootload_minor = le16_to_cpu(about_fw->bootload_minor);
1274 ha->bootload_patch = le16_to_cpu(about_fw->bootload_patch);
1275 ha->bootload_build = le16_to_cpu(about_fw->bootload_build);
1276 status = QLA_SUCCESS;
1279 dma_free_coherent(&ha->pdev->dev, sizeof(struct about_fw_info),
1280 about_fw, about_fw_dma);
1284 static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha, uint32_t options,
1285 dma_addr_t dma_addr)
1287 uint32_t mbox_cmd[MBOX_REG_COUNT];
1288 uint32_t mbox_sts[MBOX_REG_COUNT];
1290 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1291 memset(&mbox_sts, 0, sizeof(mbox_sts));
1293 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS;
1294 mbox_cmd[1] = options;
1295 mbox_cmd[2] = LSDW(dma_addr);
1296 mbox_cmd[3] = MSDW(dma_addr);
1298 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]) !=
1300 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1301 ha->host_no, __func__, mbox_sts[0]));
1307 int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t ddb_index,
1311 uint32_t mbox_cmd[MBOX_REG_COUNT];
1312 uint32_t mbox_sts[MBOX_REG_COUNT];
1314 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1315 memset(&mbox_sts, 0, sizeof(mbox_sts));
1317 mbox_cmd[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY;
1318 mbox_cmd[1] = ddb_index;
1320 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1322 if (status != QLA_SUCCESS) {
1323 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
1324 __func__, mbox_sts[0]));
1327 *mbx_sts = mbox_sts[0];
1331 int qla4xxx_clear_ddb_entry(struct scsi_qla_host *ha, uint32_t ddb_index)
1334 uint32_t mbox_cmd[MBOX_REG_COUNT];
1335 uint32_t mbox_sts[MBOX_REG_COUNT];
1337 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1338 memset(&mbox_sts, 0, sizeof(mbox_sts));
1340 mbox_cmd[0] = MBOX_CMD_CLEAR_DATABASE_ENTRY;
1341 mbox_cmd[1] = ddb_index;
1343 status = qla4xxx_mailbox_command(ha, 2, 1, &mbox_cmd[0],
1345 if (status != QLA_SUCCESS) {
1346 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
1347 __func__, mbox_sts[0]));
1353 int qla4xxx_set_flash(struct scsi_qla_host *ha, dma_addr_t dma_addr,
1354 uint32_t offset, uint32_t length, uint32_t options)
1356 uint32_t mbox_cmd[MBOX_REG_COUNT];
1357 uint32_t mbox_sts[MBOX_REG_COUNT];
1358 int status = QLA_SUCCESS;
1360 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1361 memset(&mbox_sts, 0, sizeof(mbox_sts));
1363 mbox_cmd[0] = MBOX_CMD_WRITE_FLASH;
1364 mbox_cmd[1] = LSDW(dma_addr);
1365 mbox_cmd[2] = MSDW(dma_addr);
1366 mbox_cmd[3] = offset;
1367 mbox_cmd[4] = length;
1368 mbox_cmd[5] = options;
1370 status = qla4xxx_mailbox_command(ha, 6, 2, &mbox_cmd[0], &mbox_sts[0]);
1371 if (status != QLA_SUCCESS) {
1372 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_WRITE_FLASH "
1373 "failed w/ status %04X, mbx1 %04X\n",
1374 __func__, mbox_sts[0], mbox_sts[1]));
1379 int qla4xxx_bootdb_by_index(struct scsi_qla_host *ha,
1380 struct dev_db_entry *fw_ddb_entry,
1381 dma_addr_t fw_ddb_entry_dma, uint16_t ddb_index)
1383 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
1384 uint32_t dev_db_end_offset;
1385 int status = QLA_ERROR;
1387 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
1389 dev_db_start_offset += (ddb_index * sizeof(*fw_ddb_entry));
1390 dev_db_end_offset = FLASH_OFFSET_DB_END;
1392 if (dev_db_start_offset > dev_db_end_offset) {
1393 DEBUG2(ql4_printk(KERN_ERR, ha,
1394 "%s:Invalid DDB index %d", __func__,
1396 goto exit_bootdb_failed;
1399 if (qla4xxx_get_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
1400 sizeof(*fw_ddb_entry)) != QLA_SUCCESS) {
1401 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
1402 "failed\n", ha->host_no, __func__);
1403 goto exit_bootdb_failed;
1406 if (fw_ddb_entry->cookie == DDB_VALID_COOKIE)
1407 status = QLA_SUCCESS;
1413 int qla4xxx_get_chap(struct scsi_qla_host *ha, char *username, char *password,
1417 int rval = QLA_ERROR;
1418 uint32_t offset = 0, chap_size;
1419 struct ql4_chap_table *chap_table;
1420 dma_addr_t chap_dma;
1422 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
1423 if (chap_table == NULL)
1426 chap_size = sizeof(struct ql4_chap_table);
1427 memset(chap_table, 0, chap_size);
1430 offset = FLASH_CHAP_OFFSET | (idx * chap_size);
1432 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
1433 /* flt_chap_size is CHAP table size for both ports
1434 * so divide it by 2 to calculate the offset for second port
1436 if (ha->port_num == 1)
1437 offset += (ha->hw.flt_chap_size / 2);
1438 offset += (idx * chap_size);
1441 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
1442 if (rval != QLA_SUCCESS) {
1447 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
1448 __le16_to_cpu(chap_table->cookie)));
1450 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
1451 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
1455 strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
1456 strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
1457 chap_table->cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
1460 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
1464 static int qla4xxx_set_chap(struct scsi_qla_host *ha, char *username,
1465 char *password, uint16_t idx, int bidi)
1468 int rval = QLA_ERROR;
1469 uint32_t offset = 0;
1470 struct ql4_chap_table *chap_table;
1471 dma_addr_t chap_dma;
1473 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
1474 if (chap_table == NULL) {
1479 memset(chap_table, 0, sizeof(struct ql4_chap_table));
1481 chap_table->flags |= BIT_6; /* peer */
1483 chap_table->flags |= BIT_7; /* local */
1484 chap_table->secret_len = strlen(password);
1485 strncpy(chap_table->secret, password, MAX_CHAP_SECRET_LEN);
1486 strncpy(chap_table->name, username, MAX_CHAP_NAME_LEN);
1487 chap_table->cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
1488 offset = FLASH_CHAP_OFFSET | (idx * sizeof(struct ql4_chap_table));
1489 rval = qla4xxx_set_flash(ha, chap_dma, offset,
1490 sizeof(struct ql4_chap_table),
1491 FLASH_OPT_RMW_COMMIT);
1493 if (rval == QLA_SUCCESS && ha->chap_list) {
1494 /* Update ha chap_list cache */
1495 memcpy((struct ql4_chap_table *)ha->chap_list + idx,
1496 chap_table, sizeof(struct ql4_chap_table));
1498 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
1499 if (rval != QLA_SUCCESS)
1507 * qla4xxx_get_chap_index - Get chap index given username and secret
1508 * @ha: pointer to adapter structure
1509 * @username: CHAP username to be searched
1510 * @password: CHAP password to be searched
1511 * @bidi: Is this a BIDI CHAP
1512 * @chap_index: CHAP index to be returned
1514 * Match the username and password in the chap_list, return the index if a
1515 * match is found. If a match is not found then add the entry in FLASH and
1516 * return the index at which entry is written in the FLASH.
1518 int qla4xxx_get_chap_index(struct scsi_qla_host *ha, char *username,
1519 char *password, int bidi, uint16_t *chap_index)
1522 int free_index = -1;
1523 int found_index = 0;
1524 int max_chap_entries = 0;
1525 struct ql4_chap_table *chap_table;
1528 max_chap_entries = (ha->hw.flt_chap_size / 2) /
1529 sizeof(struct ql4_chap_table);
1531 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
1533 if (!ha->chap_list) {
1534 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
1538 if (!username || !password) {
1539 ql4_printk(KERN_ERR, ha, "Do not have username and psw\n");
1543 mutex_lock(&ha->chap_sem);
1544 for (i = 0; i < max_chap_entries; i++) {
1545 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
1546 if (chap_table->cookie !=
1547 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
1548 if (i > MAX_RESRV_CHAP_IDX && free_index == -1)
1553 if (chap_table->flags & BIT_7)
1556 if (chap_table->flags & BIT_6)
1559 if (!strncmp(chap_table->secret, password,
1560 MAX_CHAP_SECRET_LEN) &&
1561 !strncmp(chap_table->name, username,
1562 MAX_CHAP_NAME_LEN)) {
1569 /* If chap entry is not present and a free index is available then
1570 * write the entry in flash
1572 if (!found_index && free_index != -1) {
1573 rval = qla4xxx_set_chap(ha, username, password,
1576 *chap_index = free_index;
1581 mutex_unlock(&ha->chap_sem);
1588 int qla4xxx_conn_close_sess_logout(struct scsi_qla_host *ha,
1589 uint16_t fw_ddb_index,
1590 uint16_t connection_id,
1593 uint32_t mbox_cmd[MBOX_REG_COUNT];
1594 uint32_t mbox_sts[MBOX_REG_COUNT];
1595 int status = QLA_SUCCESS;
1597 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1598 memset(&mbox_sts, 0, sizeof(mbox_sts));
1600 mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
1601 mbox_cmd[1] = fw_ddb_index;
1602 mbox_cmd[2] = connection_id;
1603 mbox_cmd[3] = option;
1605 status = qla4xxx_mailbox_command(ha, 4, 2, &mbox_cmd[0], &mbox_sts[0]);
1606 if (status != QLA_SUCCESS) {
1607 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_CONN_CLOSE "
1608 "option %04x failed w/ status %04X %04X\n",
1609 __func__, option, mbox_sts[0], mbox_sts[1]));
1614 int qla4xxx_disable_acb(struct scsi_qla_host *ha)
1616 uint32_t mbox_cmd[MBOX_REG_COUNT];
1617 uint32_t mbox_sts[MBOX_REG_COUNT];
1618 int status = QLA_SUCCESS;
1620 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1621 memset(&mbox_sts, 0, sizeof(mbox_sts));
1623 mbox_cmd[0] = MBOX_CMD_DISABLE_ACB;
1625 status = qla4xxx_mailbox_command(ha, 8, 5, &mbox_cmd[0], &mbox_sts[0]);
1626 if (status != QLA_SUCCESS) {
1627 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_DISABLE_ACB "
1628 "failed w/ status %04X %04X %04X", __func__,
1629 mbox_sts[0], mbox_sts[1], mbox_sts[2]));
1634 int qla4xxx_get_acb(struct scsi_qla_host *ha, dma_addr_t acb_dma,
1635 uint32_t acb_type, uint32_t len)
1637 uint32_t mbox_cmd[MBOX_REG_COUNT];
1638 uint32_t mbox_sts[MBOX_REG_COUNT];
1639 int status = QLA_SUCCESS;
1641 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1642 memset(&mbox_sts, 0, sizeof(mbox_sts));
1644 mbox_cmd[0] = MBOX_CMD_GET_ACB;
1645 mbox_cmd[1] = acb_type;
1646 mbox_cmd[2] = LSDW(acb_dma);
1647 mbox_cmd[3] = MSDW(acb_dma);
1650 status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
1651 if (status != QLA_SUCCESS) {
1652 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_GET_ACB "
1653 "failed w/ status %04X\n", __func__,
1659 int qla4xxx_set_acb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
1660 uint32_t *mbox_sts, dma_addr_t acb_dma)
1662 int status = QLA_SUCCESS;
1664 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
1665 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
1666 mbox_cmd[0] = MBOX_CMD_SET_ACB;
1667 mbox_cmd[1] = 0; /* Primary ACB */
1668 mbox_cmd[2] = LSDW(acb_dma);
1669 mbox_cmd[3] = MSDW(acb_dma);
1670 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
1672 status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
1673 if (status != QLA_SUCCESS) {
1674 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_SET_ACB "
1675 "failed w/ status %04X\n", __func__,
1681 int qla4xxx_set_param_ddbentry(struct scsi_qla_host *ha,
1682 struct ddb_entry *ddb_entry,
1683 struct iscsi_cls_conn *cls_conn,
1686 struct dev_db_entry *fw_ddb_entry;
1687 struct iscsi_conn *conn;
1688 struct iscsi_session *sess;
1689 struct qla_conn *qla_conn;
1690 struct sockaddr *dst_addr;
1691 dma_addr_t fw_ddb_entry_dma;
1692 int status = QLA_SUCCESS;
1694 struct sockaddr_in *addr;
1695 struct sockaddr_in6 *addr6;
1697 uint16_t iscsi_opts = 0;
1698 uint32_t options = 0;
1699 uint16_t idx, *ptid;
1701 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1702 &fw_ddb_entry_dma, GFP_KERNEL);
1703 if (!fw_ddb_entry) {
1704 DEBUG2(ql4_printk(KERN_ERR, ha,
1705 "%s: Unable to allocate dma buffer.\n",
1708 goto exit_set_param_no_free;
1711 conn = cls_conn->dd_data;
1712 qla_conn = conn->dd_data;
1713 sess = conn->session;
1714 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
1716 if (dst_addr->sa_family == AF_INET6)
1717 options |= IPV6_DEFAULT_DDB_ENTRY;
1719 status = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
1720 if (status == QLA_ERROR) {
1722 goto exit_set_param;
1725 ptid = (uint16_t *)&fw_ddb_entry->isid[1];
1726 *ptid = cpu_to_le16((uint16_t)ddb_entry->sess->target_id);
1728 DEBUG2(ql4_printk(KERN_INFO, ha, "ISID [%02x%02x%02x%02x%02x%02x]\n",
1729 fw_ddb_entry->isid[5], fw_ddb_entry->isid[4],
1730 fw_ddb_entry->isid[3], fw_ddb_entry->isid[2],
1731 fw_ddb_entry->isid[1], fw_ddb_entry->isid[0]));
1733 iscsi_opts = le16_to_cpu(fw_ddb_entry->iscsi_options);
1734 memset(fw_ddb_entry->iscsi_alias, 0, sizeof(fw_ddb_entry->iscsi_alias));
1736 memset(fw_ddb_entry->iscsi_name, 0, sizeof(fw_ddb_entry->iscsi_name));
1738 if (sess->targetname != NULL) {
1739 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
1740 min(strlen(sess->targetname),
1741 sizeof(fw_ddb_entry->iscsi_name)));
1744 memset(fw_ddb_entry->ip_addr, 0, sizeof(fw_ddb_entry->ip_addr));
1745 memset(fw_ddb_entry->tgt_addr, 0, sizeof(fw_ddb_entry->tgt_addr));
1747 fw_ddb_entry->options = DDB_OPT_TARGET | DDB_OPT_AUTO_SENDTGTS_DISABLE;
1749 if (dst_addr->sa_family == AF_INET) {
1750 addr = (struct sockaddr_in *)dst_addr;
1751 ip = (char *)&addr->sin_addr;
1752 memcpy(fw_ddb_entry->ip_addr, ip, IP_ADDR_LEN);
1753 fw_ddb_entry->port = cpu_to_le16(ntohs(addr->sin_port));
1754 DEBUG2(ql4_printk(KERN_INFO, ha,
1755 "%s: Destination Address [%pI4]: index [%d]\n",
1756 __func__, fw_ddb_entry->ip_addr,
1757 ddb_entry->fw_ddb_index));
1758 } else if (dst_addr->sa_family == AF_INET6) {
1759 addr6 = (struct sockaddr_in6 *)dst_addr;
1760 ip = (char *)&addr6->sin6_addr;
1761 memcpy(fw_ddb_entry->ip_addr, ip, IPv6_ADDR_LEN);
1762 fw_ddb_entry->port = cpu_to_le16(ntohs(addr6->sin6_port));
1763 fw_ddb_entry->options |= DDB_OPT_IPV6_DEVICE;
1764 DEBUG2(ql4_printk(KERN_INFO, ha,
1765 "%s: Destination Address [%pI6]: index [%d]\n",
1766 __func__, fw_ddb_entry->ip_addr,
1767 ddb_entry->fw_ddb_index));
1769 ql4_printk(KERN_ERR, ha,
1770 "%s: Failed to get IP Address\n",
1773 goto exit_set_param;
1777 if (sess->username != NULL && sess->password != NULL) {
1778 if (strlen(sess->username) && strlen(sess->password)) {
1779 iscsi_opts |= BIT_7;
1781 rval = qla4xxx_get_chap_index(ha, sess->username,
1785 goto exit_set_param;
1787 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(idx);
1791 if (sess->username_in != NULL && sess->password_in != NULL) {
1792 /* Check if BIDI CHAP */
1793 if (strlen(sess->username_in) && strlen(sess->password_in)) {
1794 iscsi_opts |= BIT_4;
1796 rval = qla4xxx_get_chap_index(ha, sess->username_in,
1800 goto exit_set_param;
1804 if (sess->initial_r2t_en)
1805 iscsi_opts |= BIT_10;
1807 if (sess->imm_data_en)
1808 iscsi_opts |= BIT_11;
1810 fw_ddb_entry->iscsi_options = cpu_to_le16(iscsi_opts);
1812 if (conn->max_recv_dlength)
1813 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
1814 __constant_cpu_to_le16((conn->max_recv_dlength / BYTE_UNITS));
1817 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
1819 if (sess->first_burst)
1820 fw_ddb_entry->iscsi_first_burst_len =
1821 __constant_cpu_to_le16((sess->first_burst / BYTE_UNITS));
1823 if (sess->max_burst)
1824 fw_ddb_entry->iscsi_max_burst_len =
1825 __constant_cpu_to_le16((sess->max_burst / BYTE_UNITS));
1827 if (sess->time2wait)
1828 fw_ddb_entry->iscsi_def_time2wait =
1829 cpu_to_le16(sess->time2wait);
1831 if (sess->time2retain)
1832 fw_ddb_entry->iscsi_def_time2retain =
1833 cpu_to_le16(sess->time2retain);
1835 status = qla4xxx_set_ddb_entry(ha, ddb_entry->fw_ddb_index,
1836 fw_ddb_entry_dma, mbx_sts);
1838 if (status != QLA_SUCCESS)
1841 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1842 fw_ddb_entry, fw_ddb_entry_dma);
1843 exit_set_param_no_free:
1847 int qla4xxx_get_mgmt_data(struct scsi_qla_host *ha, uint16_t fw_ddb_index,
1848 uint16_t stats_size, dma_addr_t stats_dma)
1850 int status = QLA_SUCCESS;
1851 uint32_t mbox_cmd[MBOX_REG_COUNT];
1852 uint32_t mbox_sts[MBOX_REG_COUNT];
1854 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
1855 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
1856 mbox_cmd[0] = MBOX_CMD_GET_MANAGEMENT_DATA;
1857 mbox_cmd[1] = fw_ddb_index;
1858 mbox_cmd[2] = LSDW(stats_dma);
1859 mbox_cmd[3] = MSDW(stats_dma);
1860 mbox_cmd[4] = stats_size;
1862 status = qla4xxx_mailbox_command(ha, 5, 1, &mbox_cmd[0], &mbox_sts[0]);
1863 if (status != QLA_SUCCESS) {
1864 DEBUG2(ql4_printk(KERN_WARNING, ha,
1865 "%s: MBOX_CMD_GET_MANAGEMENT_DATA "
1866 "failed w/ status %04X\n", __func__,
1872 int qla4xxx_get_ip_state(struct scsi_qla_host *ha, uint32_t acb_idx,
1873 uint32_t ip_idx, uint32_t *sts)
1875 uint32_t mbox_cmd[MBOX_REG_COUNT];
1876 uint32_t mbox_sts[MBOX_REG_COUNT];
1877 int status = QLA_SUCCESS;
1879 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1880 memset(&mbox_sts, 0, sizeof(mbox_sts));
1881 mbox_cmd[0] = MBOX_CMD_GET_IP_ADDR_STATE;
1882 mbox_cmd[1] = acb_idx;
1883 mbox_cmd[2] = ip_idx;
1885 status = qla4xxx_mailbox_command(ha, 3, 8, &mbox_cmd[0], &mbox_sts[0]);
1886 if (status != QLA_SUCCESS) {
1887 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: "
1888 "MBOX_CMD_GET_IP_ADDR_STATE failed w/ "
1889 "status %04X\n", __func__, mbox_sts[0]));
1891 memcpy(sts, mbox_sts, sizeof(mbox_sts));
1895 int qla4xxx_get_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
1896 uint32_t offset, uint32_t size)
1898 int status = QLA_SUCCESS;
1899 uint32_t mbox_cmd[MBOX_REG_COUNT];
1900 uint32_t mbox_sts[MBOX_REG_COUNT];
1902 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1903 memset(&mbox_sts, 0, sizeof(mbox_sts));
1905 mbox_cmd[0] = MBOX_CMD_GET_NVRAM;
1906 mbox_cmd[1] = LSDW(nvram_dma);
1907 mbox_cmd[2] = MSDW(nvram_dma);
1908 mbox_cmd[3] = offset;
1911 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1913 if (status != QLA_SUCCESS) {
1914 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1915 "status %04X\n", ha->host_no, __func__,
1921 int qla4xxx_set_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
1922 uint32_t offset, uint32_t size)
1924 int status = QLA_SUCCESS;
1925 uint32_t mbox_cmd[MBOX_REG_COUNT];
1926 uint32_t mbox_sts[MBOX_REG_COUNT];
1928 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1929 memset(&mbox_sts, 0, sizeof(mbox_sts));
1931 mbox_cmd[0] = MBOX_CMD_SET_NVRAM;
1932 mbox_cmd[1] = LSDW(nvram_dma);
1933 mbox_cmd[2] = MSDW(nvram_dma);
1934 mbox_cmd[3] = offset;
1937 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1939 if (status != QLA_SUCCESS) {
1940 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1941 "status %04X\n", ha->host_no, __func__,
1947 int qla4xxx_restore_factory_defaults(struct scsi_qla_host *ha,
1948 uint32_t region, uint32_t field0,
1951 int status = QLA_SUCCESS;
1952 uint32_t mbox_cmd[MBOX_REG_COUNT];
1953 uint32_t mbox_sts[MBOX_REG_COUNT];
1955 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1956 memset(&mbox_sts, 0, sizeof(mbox_sts));
1958 mbox_cmd[0] = MBOX_CMD_RESTORE_FACTORY_DEFAULTS;
1959 mbox_cmd[3] = region;
1960 mbox_cmd[4] = field0;
1961 mbox_cmd[5] = field1;
1963 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0],
1965 if (status != QLA_SUCCESS) {
1966 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1967 "status %04X\n", ha->host_no, __func__,
1974 * qla4_8xxx_set_param - set driver version in firmware.
1975 * @ha: Pointer to host adapter structure.
1976 * @param: Parameter to set i.e driver version
1978 int qla4_8xxx_set_param(struct scsi_qla_host *ha, int param)
1980 uint32_t mbox_cmd[MBOX_REG_COUNT];
1981 uint32_t mbox_sts[MBOX_REG_COUNT];
1984 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1985 memset(&mbox_sts, 0, sizeof(mbox_sts));
1987 mbox_cmd[0] = MBOX_CMD_SET_PARAM;
1988 if (param == SET_DRVR_VERSION) {
1989 mbox_cmd[1] = SET_DRVR_VERSION;
1990 strncpy((char *)&mbox_cmd[2], QLA4XXX_DRIVER_VERSION,
1993 ql4_printk(KERN_ERR, ha, "%s: invalid parameter 0x%x\n",
1996 goto exit_set_param;
1999 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, mbox_cmd,
2001 if (status == QLA_ERROR)
2002 ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
2003 __func__, mbox_sts[0]);
2010 * qla4_83xx_post_idc_ack - post IDC ACK
2011 * @ha: Pointer to host adapter structure.
2013 * Posts IDC ACK for IDC Request Notification AEN.
2015 int qla4_83xx_post_idc_ack(struct scsi_qla_host *ha)
2017 uint32_t mbox_cmd[MBOX_REG_COUNT];
2018 uint32_t mbox_sts[MBOX_REG_COUNT];
2021 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2022 memset(&mbox_sts, 0, sizeof(mbox_sts));
2024 mbox_cmd[0] = MBOX_CMD_IDC_ACK;
2025 mbox_cmd[1] = ha->idc_info.request_desc;
2026 mbox_cmd[2] = ha->idc_info.info1;
2027 mbox_cmd[3] = ha->idc_info.info2;
2028 mbox_cmd[4] = ha->idc_info.info3;
2030 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, MBOX_REG_COUNT,
2031 mbox_cmd, mbox_sts);
2032 if (status == QLA_ERROR)
2033 ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n", __func__,
2036 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IDC ACK posted\n",