2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2010 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
11 #include "ql4_inline.h"
15 * qla4xxx_mailbox_command - issues mailbox commands
16 * @ha: Pointer to host adapter structure.
17 * @inCount: number of mailbox registers to load.
18 * @outCount: number of mailbox registers to return.
19 * @mbx_cmd: data pointer for mailbox in registers.
20 * @mbx_sts: data pointer for mailbox out registers.
22 * This routine issue mailbox commands and waits for completion.
23 * If outCount is 0, this routine completes successfully WITHOUT waiting
24 * for the mailbox command to complete.
26 int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
27 uint8_t outCount, uint32_t *mbx_cmd,
30 int status = QLA_ERROR;
34 unsigned long flags = 0;
37 /* Make sure that pointers are valid */
38 if (!mbx_cmd || !mbx_sts) {
39 DEBUG2(printk("scsi%ld: %s: Invalid mbx_cmd or mbx_sts "
40 "pointer\n", ha->host_no, __func__));
45 if (test_bit(AF_HA_REMOVAL, &ha->flags)) {
46 DEBUG2(ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: "
47 "prematurely completing mbx cmd as "
48 "adapter removal detected\n",
49 ha->host_no, __func__));
55 if (test_bit(AF_FW_RECOVERY, &ha->flags)) {
56 DEBUG2(ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: "
57 "prematurely completing mbx cmd as firmware "
58 "recovery detected\n", ha->host_no, __func__));
61 /* Do not send any mbx cmd if h/w is in failed state*/
62 qla4_8xxx_idc_lock(ha);
63 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
64 qla4_8xxx_idc_unlock(ha);
65 if (dev_state == QLA82XX_DEV_FAILED) {
66 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: H/W is in "
67 "failed state, do not send any mailbox commands\n",
68 ha->host_no, __func__);
73 if ((is_aer_supported(ha)) &&
74 (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))) {
75 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Perm failure on EEH, "
76 "timeout MBX Exiting.\n", ha->host_no, __func__));
80 /* Mailbox code active */
81 wait_count = MBOX_TOV * 100;
83 while (wait_count--) {
84 mutex_lock(&ha->mbox_sem);
85 if (!test_bit(AF_MBOX_COMMAND, &ha->flags)) {
86 set_bit(AF_MBOX_COMMAND, &ha->flags);
87 mutex_unlock(&ha->mbox_sem);
90 mutex_unlock(&ha->mbox_sem);
92 DEBUG2(printk("scsi%ld: %s: mbox_sem failed\n",
93 ha->host_no, __func__));
99 spin_lock_irqsave(&ha->hardware_lock, flags);
101 ha->mbox_status_count = outCount;
102 for (i = 0; i < outCount; i++)
103 ha->mbox_status[i] = 0;
105 if (is_qla8022(ha)) {
106 /* Load all mailbox registers, except mailbox 0. */
108 printk("scsi%ld: %s: Cmd ", ha->host_no, __func__);
109 for (i = 0; i < inCount; i++)
110 printk("mb%d=%04x ", i, mbx_cmd[i]);
113 for (i = 1; i < inCount; i++)
114 writel(mbx_cmd[i], &ha->qla4_8xxx_reg->mailbox_in[i]);
115 writel(mbx_cmd[0], &ha->qla4_8xxx_reg->mailbox_in[0]);
116 readl(&ha->qla4_8xxx_reg->mailbox_in[0]);
117 writel(HINT_MBX_INT_PENDING, &ha->qla4_8xxx_reg->hint);
119 /* Load all mailbox registers, except mailbox 0. */
120 for (i = 1; i < inCount; i++)
121 writel(mbx_cmd[i], &ha->reg->mailbox[i]);
123 /* Wakeup firmware */
124 writel(mbx_cmd[0], &ha->reg->mailbox[0]);
125 readl(&ha->reg->mailbox[0]);
126 writel(set_rmask(CSR_INTR_RISC), &ha->reg->ctrl_status);
127 readl(&ha->reg->ctrl_status);
130 spin_unlock_irqrestore(&ha->hardware_lock, flags);
132 /* Wait for completion */
135 * If we don't want status, don't wait for the mailbox command to
136 * complete. For example, MBOX_CMD_RESET_FW doesn't return status,
137 * you must poll the inbound Interrupt Mask for completion.
140 status = QLA_SUCCESS;
145 * Wait for completion: Poll or completion queue
147 if (test_bit(AF_IRQ_ATTACHED, &ha->flags) &&
148 test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
149 test_bit(AF_ONLINE, &ha->flags) &&
150 !test_bit(AF_HA_REMOVAL, &ha->flags)) {
151 /* Do not poll for completion. Use completion queue */
152 set_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
153 wait_for_completion_timeout(&ha->mbx_intr_comp, MBOX_TOV * HZ);
154 clear_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
156 /* Poll for command to complete */
157 wait_count = jiffies + MBOX_TOV * HZ;
158 while (test_bit(AF_MBOX_COMMAND_DONE, &ha->flags) == 0) {
159 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);
222 if (is_qla8022(ha)) {
223 ql4_printk(KERN_INFO, ha,
224 "disabling pause transmit on port 0 & 1.\n");
225 qla4_8xxx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
226 CRB_NIU_XG_PAUSE_CTL_P0 |
227 CRB_NIU_XG_PAUSE_CTL_P1);
233 * Copy the mailbox out registers to the caller's mailbox in/out
236 spin_lock_irqsave(&ha->hardware_lock, flags);
237 for (i = 0; i < outCount; i++)
238 mbx_sts[i] = ha->mbox_status[i];
240 /* Set return status and error flags (if applicable). */
241 switch (ha->mbox_status[0]) {
242 case MBOX_STS_COMMAND_COMPLETE:
243 status = QLA_SUCCESS;
246 case MBOX_STS_INTERMEDIATE_COMPLETION:
247 status = QLA_SUCCESS;
251 DEBUG2( printk("scsi%ld: %s: Cmd = %08X, ISP BUSY\n",
252 ha->host_no, __func__, mbx_cmd[0]));
253 ha->mailbox_timeout_count++;
257 DEBUG2(printk("scsi%ld: %s: **** FAILED, cmd = %08X, "
258 "sts = %08X ****\n", ha->host_no, __func__,
259 mbx_cmd[0], mbx_sts[0]));
262 spin_unlock_irqrestore(&ha->hardware_lock, flags);
265 mutex_lock(&ha->mbox_sem);
266 clear_bit(AF_MBOX_COMMAND, &ha->flags);
267 mutex_unlock(&ha->mbox_sem);
268 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
273 void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha)
275 set_bit(AF_FW_RECOVERY, &ha->flags);
276 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: set FW RECOVERY!\n",
277 ha->host_no, __func__);
279 if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
280 if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags)) {
281 complete(&ha->mbx_intr_comp);
282 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
283 "recovery, doing premature completion of "
284 "mbx cmd\n", ha->host_no, __func__);
287 set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
288 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
289 "recovery, doing premature completion of "
290 "polling mbx cmd\n", ha->host_no, __func__);
296 qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
297 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
299 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
300 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
303 qla4_8xxx_wr_32(ha, ha->nx_db_wr_ptr, 0);
305 mbox_cmd[0] = MBOX_CMD_INITIALIZE_FIRMWARE;
307 mbox_cmd[2] = LSDW(init_fw_cb_dma);
308 mbox_cmd[3] = MSDW(init_fw_cb_dma);
309 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
310 mbox_cmd[5] = (IFCB_VER_MAX << 8) | IFCB_VER_MIN;
312 if (qla4xxx_mailbox_command(ha, 6, 6, mbox_cmd, mbox_sts) !=
314 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
315 "MBOX_CMD_INITIALIZE_FIRMWARE"
316 " failed w/ status %04X\n",
317 ha->host_no, __func__, mbox_sts[0]));
324 qla4xxx_get_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
325 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
327 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
328 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
329 mbox_cmd[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK;
330 mbox_cmd[2] = LSDW(init_fw_cb_dma);
331 mbox_cmd[3] = MSDW(init_fw_cb_dma);
332 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
334 if (qla4xxx_mailbox_command(ha, 5, 5, mbox_cmd, mbox_sts) !=
336 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
337 "MBOX_CMD_GET_INIT_FW_CTRL_BLOCK"
338 " failed w/ status %04X\n",
339 ha->host_no, __func__, mbox_sts[0]));
346 qla4xxx_update_local_ip(struct scsi_qla_host *ha,
347 struct addr_ctrl_blk *init_fw_cb)
349 ha->ip_config.tcp_options = le16_to_cpu(init_fw_cb->ipv4_tcp_opts);
350 ha->ip_config.ipv4_options = le16_to_cpu(init_fw_cb->ipv4_ip_opts);
351 ha->ip_config.ipv4_addr_state =
352 le16_to_cpu(init_fw_cb->ipv4_addr_state);
353 ha->ip_config.eth_mtu_size =
354 le16_to_cpu(init_fw_cb->eth_mtu_size);
355 ha->ip_config.ipv4_port = le16_to_cpu(init_fw_cb->ipv4_port);
357 if (ha->acb_version == ACB_SUPPORTED) {
358 ha->ip_config.ipv6_options = le16_to_cpu(init_fw_cb->ipv6_opts);
359 ha->ip_config.ipv6_addl_options =
360 le16_to_cpu(init_fw_cb->ipv6_addtl_opts);
363 /* Save IPv4 Address Info */
364 memcpy(ha->ip_config.ip_address, init_fw_cb->ipv4_addr,
365 min(sizeof(ha->ip_config.ip_address),
366 sizeof(init_fw_cb->ipv4_addr)));
367 memcpy(ha->ip_config.subnet_mask, init_fw_cb->ipv4_subnet,
368 min(sizeof(ha->ip_config.subnet_mask),
369 sizeof(init_fw_cb->ipv4_subnet)));
370 memcpy(ha->ip_config.gateway, init_fw_cb->ipv4_gw_addr,
371 min(sizeof(ha->ip_config.gateway),
372 sizeof(init_fw_cb->ipv4_gw_addr)));
374 ha->ip_config.ipv4_vlan_tag = be16_to_cpu(init_fw_cb->ipv4_vlan_tag);
376 if (is_ipv6_enabled(ha)) {
377 /* Save IPv6 Address */
378 ha->ip_config.ipv6_link_local_state =
379 le16_to_cpu(init_fw_cb->ipv6_lnk_lcl_addr_state);
380 ha->ip_config.ipv6_addr0_state =
381 le16_to_cpu(init_fw_cb->ipv6_addr0_state);
382 ha->ip_config.ipv6_addr1_state =
383 le16_to_cpu(init_fw_cb->ipv6_addr1_state);
384 ha->ip_config.ipv6_default_router_state =
385 le16_to_cpu(init_fw_cb->ipv6_dflt_rtr_state);
386 ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[0] = 0xFE;
387 ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[1] = 0x80;
389 memcpy(&ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[8],
390 init_fw_cb->ipv6_if_id,
391 min(sizeof(ha->ip_config.ipv6_link_local_addr)/2,
392 sizeof(init_fw_cb->ipv6_if_id)));
393 memcpy(&ha->ip_config.ipv6_addr0, init_fw_cb->ipv6_addr0,
394 min(sizeof(ha->ip_config.ipv6_addr0),
395 sizeof(init_fw_cb->ipv6_addr0)));
396 memcpy(&ha->ip_config.ipv6_addr1, init_fw_cb->ipv6_addr1,
397 min(sizeof(ha->ip_config.ipv6_addr1),
398 sizeof(init_fw_cb->ipv6_addr1)));
399 memcpy(&ha->ip_config.ipv6_default_router_addr,
400 init_fw_cb->ipv6_dflt_rtr_addr,
401 min(sizeof(ha->ip_config.ipv6_default_router_addr),
402 sizeof(init_fw_cb->ipv6_dflt_rtr_addr)));
403 ha->ip_config.ipv6_vlan_tag =
404 be16_to_cpu(init_fw_cb->ipv6_vlan_tag);
405 ha->ip_config.ipv6_port = le16_to_cpu(init_fw_cb->ipv6_port);
410 qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
413 struct addr_ctrl_blk *init_fw_cb,
414 dma_addr_t init_fw_cb_dma)
416 if (qla4xxx_get_ifcb(ha, mbox_cmd, mbox_sts, init_fw_cb_dma)
418 DEBUG2(printk(KERN_WARNING
419 "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
420 ha->host_no, __func__));
424 DEBUG2(qla4xxx_dump_buffer(init_fw_cb, sizeof(struct addr_ctrl_blk)));
426 /* Save some info in adapter structure. */
427 ha->acb_version = init_fw_cb->acb_version;
428 ha->firmware_options = le16_to_cpu(init_fw_cb->fw_options);
429 ha->heartbeat_interval = init_fw_cb->hb_interval;
430 memcpy(ha->name_string, init_fw_cb->iscsi_name,
431 min(sizeof(ha->name_string),
432 sizeof(init_fw_cb->iscsi_name)));
433 ha->def_timeout = le16_to_cpu(init_fw_cb->def_timeout);
434 /*memcpy(ha->alias, init_fw_cb->Alias,
435 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
437 qla4xxx_update_local_ip(ha, init_fw_cb);
443 * qla4xxx_initialize_fw_cb - initializes firmware control block.
444 * @ha: Pointer to host adapter structure.
446 int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
448 struct addr_ctrl_blk *init_fw_cb;
449 dma_addr_t init_fw_cb_dma;
450 uint32_t mbox_cmd[MBOX_REG_COUNT];
451 uint32_t mbox_sts[MBOX_REG_COUNT];
452 int status = QLA_ERROR;
454 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
455 sizeof(struct addr_ctrl_blk),
456 &init_fw_cb_dma, GFP_KERNEL);
457 if (init_fw_cb == NULL) {
458 DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
459 ha->host_no, __func__));
460 goto exit_init_fw_cb_no_free;
462 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
464 /* Get Initialize Firmware Control Block. */
465 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
466 memset(&mbox_sts, 0, sizeof(mbox_sts));
468 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
470 dma_free_coherent(&ha->pdev->dev,
471 sizeof(struct addr_ctrl_blk),
472 init_fw_cb, init_fw_cb_dma);
473 goto exit_init_fw_cb;
476 /* Initialize request and response queues. */
477 qla4xxx_init_rings(ha);
479 /* Fill in the request and response queue information. */
480 init_fw_cb->rqq_consumer_idx = cpu_to_le16(ha->request_out);
481 init_fw_cb->compq_producer_idx = cpu_to_le16(ha->response_in);
482 init_fw_cb->rqq_len = __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH);
483 init_fw_cb->compq_len = __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH);
484 init_fw_cb->rqq_addr_lo = cpu_to_le32(LSDW(ha->request_dma));
485 init_fw_cb->rqq_addr_hi = cpu_to_le32(MSDW(ha->request_dma));
486 init_fw_cb->compq_addr_lo = cpu_to_le32(LSDW(ha->response_dma));
487 init_fw_cb->compq_addr_hi = cpu_to_le32(MSDW(ha->response_dma));
488 init_fw_cb->shdwreg_addr_lo = cpu_to_le32(LSDW(ha->shadow_regs_dma));
489 init_fw_cb->shdwreg_addr_hi = cpu_to_le32(MSDW(ha->shadow_regs_dma));
491 /* Set up required options. */
492 init_fw_cb->fw_options |=
493 __constant_cpu_to_le16(FWOPT_SESSION_MODE |
494 FWOPT_INITIATOR_MODE);
497 init_fw_cb->fw_options |=
498 __constant_cpu_to_le16(FWOPT_ENABLE_CRBDB);
500 init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
502 init_fw_cb->add_fw_options = 0;
503 init_fw_cb->add_fw_options |=
504 __constant_cpu_to_le16(ADFWOPT_SERIALIZE_TASK_MGMT);
505 init_fw_cb->add_fw_options |=
506 __constant_cpu_to_le16(ADFWOPT_AUTOCONN_DISABLE);
508 if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
510 DEBUG2(printk(KERN_WARNING
511 "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
512 ha->host_no, __func__));
513 goto exit_init_fw_cb;
516 if (qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0],
517 init_fw_cb, init_fw_cb_dma) != QLA_SUCCESS) {
518 DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
519 ha->host_no, __func__));
520 goto exit_init_fw_cb;
522 status = QLA_SUCCESS;
525 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
526 init_fw_cb, init_fw_cb_dma);
527 exit_init_fw_cb_no_free:
532 * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
533 * @ha: Pointer to host adapter structure.
535 int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host * ha)
537 struct addr_ctrl_blk *init_fw_cb;
538 dma_addr_t init_fw_cb_dma;
539 uint32_t mbox_cmd[MBOX_REG_COUNT];
540 uint32_t mbox_sts[MBOX_REG_COUNT];
542 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
543 sizeof(struct addr_ctrl_blk),
544 &init_fw_cb_dma, GFP_KERNEL);
545 if (init_fw_cb == NULL) {
546 printk("scsi%ld: %s: Unable to alloc init_cb\n", ha->host_no,
551 /* Get Initialize Firmware Control Block. */
552 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
553 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
555 DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
556 ha->host_no, __func__));
557 dma_free_coherent(&ha->pdev->dev,
558 sizeof(struct addr_ctrl_blk),
559 init_fw_cb, init_fw_cb_dma);
563 /* Save IP Address. */
564 qla4xxx_update_local_ip(ha, init_fw_cb);
565 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
566 init_fw_cb, init_fw_cb_dma);
572 * qla4xxx_get_firmware_state - gets firmware state of HBA
573 * @ha: Pointer to host adapter structure.
575 int qla4xxx_get_firmware_state(struct scsi_qla_host * ha)
577 uint32_t mbox_cmd[MBOX_REG_COUNT];
578 uint32_t mbox_sts[MBOX_REG_COUNT];
580 /* Get firmware version */
581 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
582 memset(&mbox_sts, 0, sizeof(mbox_sts));
584 mbox_cmd[0] = MBOX_CMD_GET_FW_STATE;
586 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 4, &mbox_cmd[0], &mbox_sts[0]) !=
588 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
589 "status %04X\n", ha->host_no, __func__,
593 ha->firmware_state = mbox_sts[1];
594 ha->board_id = mbox_sts[2];
595 ha->addl_fw_state = mbox_sts[3];
596 DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
597 ha->host_no, __func__, ha->firmware_state);)
603 * qla4xxx_get_firmware_status - retrieves firmware status
604 * @ha: Pointer to host adapter structure.
606 int qla4xxx_get_firmware_status(struct scsi_qla_host * ha)
608 uint32_t mbox_cmd[MBOX_REG_COUNT];
609 uint32_t mbox_sts[MBOX_REG_COUNT];
611 /* Get firmware version */
612 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
613 memset(&mbox_sts, 0, sizeof(mbox_sts));
615 mbox_cmd[0] = MBOX_CMD_GET_FW_STATUS;
617 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
619 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
620 "status %04X\n", ha->host_no, __func__,
625 ql4_printk(KERN_INFO, ha, "%ld firmare IOCBs available (%d).\n",
626 ha->host_no, mbox_sts[2]);
632 * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
633 * @ha: Pointer to host adapter structure.
634 * @fw_ddb_index: Firmware's device database index
635 * @fw_ddb_entry: Pointer to firmware's device database entry structure
636 * @num_valid_ddb_entries: Pointer to number of valid ddb entries
637 * @next_ddb_index: Pointer to next valid device database index
638 * @fw_ddb_device_state: Pointer to device state
640 int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
641 uint16_t fw_ddb_index,
642 struct dev_db_entry *fw_ddb_entry,
643 dma_addr_t fw_ddb_entry_dma,
644 uint32_t *num_valid_ddb_entries,
645 uint32_t *next_ddb_index,
646 uint32_t *fw_ddb_device_state,
647 uint32_t *conn_err_detail,
648 uint16_t *tcp_source_port_num,
649 uint16_t *connection_id)
651 int status = QLA_ERROR;
653 uint32_t mbox_cmd[MBOX_REG_COUNT];
654 uint32_t mbox_sts[MBOX_REG_COUNT];
656 /* Make sure the device index is valid */
657 if (fw_ddb_index >= MAX_DDB_ENTRIES) {
658 DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
659 ha->host_no, __func__, fw_ddb_index));
662 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
663 memset(&mbox_sts, 0, sizeof(mbox_sts));
665 memset(fw_ddb_entry, 0, sizeof(struct dev_db_entry));
667 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY;
668 mbox_cmd[1] = (uint32_t) fw_ddb_index;
669 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
670 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
671 mbox_cmd[4] = sizeof(struct dev_db_entry);
673 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 7, &mbox_cmd[0], &mbox_sts[0]) ==
675 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
676 " with status 0x%04X\n", ha->host_no, __func__,
680 if (fw_ddb_index != mbox_sts[1]) {
681 DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
682 ha->host_no, __func__, fw_ddb_index,
687 options = le16_to_cpu(fw_ddb_entry->options);
688 if (options & DDB_OPT_IPV6_DEVICE) {
689 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
690 "Next %d State %04x ConnErr %08x %pI6 "
691 ":%04d \"%s\"\n", __func__, fw_ddb_index,
692 mbox_sts[0], mbox_sts[2], mbox_sts[3],
693 mbox_sts[4], mbox_sts[5],
694 fw_ddb_entry->ip_addr,
695 le16_to_cpu(fw_ddb_entry->port),
696 fw_ddb_entry->iscsi_name);
698 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
699 "Next %d State %04x ConnErr %08x %pI4 "
700 ":%04d \"%s\"\n", __func__, fw_ddb_index,
701 mbox_sts[0], mbox_sts[2], mbox_sts[3],
702 mbox_sts[4], mbox_sts[5],
703 fw_ddb_entry->ip_addr,
704 le16_to_cpu(fw_ddb_entry->port),
705 fw_ddb_entry->iscsi_name);
708 if (num_valid_ddb_entries)
709 *num_valid_ddb_entries = mbox_sts[2];
711 *next_ddb_index = mbox_sts[3];
712 if (fw_ddb_device_state)
713 *fw_ddb_device_state = mbox_sts[4];
716 * RA: This mailbox has been changed to pass connection error and
717 * details. Its true for ISP4010 as per Version E - Not sure when it
718 * was changed. Get the time2wait from the fw_dd_entry field :
719 * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
723 *conn_err_detail = mbox_sts[5];
724 if (tcp_source_port_num)
725 *tcp_source_port_num = (uint16_t) (mbox_sts[6] >> 16);
727 *connection_id = (uint16_t) mbox_sts[6] & 0x00FF;
728 status = QLA_SUCCESS;
734 int qla4xxx_conn_open(struct scsi_qla_host *ha, uint16_t fw_ddb_index)
736 uint32_t mbox_cmd[MBOX_REG_COUNT];
737 uint32_t mbox_sts[MBOX_REG_COUNT];
740 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
741 memset(&mbox_sts, 0, sizeof(mbox_sts));
743 mbox_cmd[0] = MBOX_CMD_CONN_OPEN;
744 mbox_cmd[1] = fw_ddb_index;
746 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
748 DEBUG2(ql4_printk(KERN_INFO, ha,
749 "%s: status = %d mbx0 = 0x%x mbx1 = 0x%x\n",
750 __func__, status, mbox_sts[0], mbox_sts[1]));
755 * qla4xxx_set_fwddb_entry - sets a ddb entry.
756 * @ha: Pointer to host adapter structure.
757 * @fw_ddb_index: Firmware's device database index
758 * @fw_ddb_entry_dma: dma address of ddb entry
759 * @mbx_sts: mailbox 0 to be returned or NULL
761 * This routine initializes or updates the adapter's device database
762 * entry for the specified device.
764 int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
765 dma_addr_t fw_ddb_entry_dma, uint32_t *mbx_sts)
767 uint32_t mbox_cmd[MBOX_REG_COUNT];
768 uint32_t mbox_sts[MBOX_REG_COUNT];
771 /* Do not wait for completion. The firmware will send us an
772 * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
774 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
775 memset(&mbox_sts, 0, sizeof(mbox_sts));
777 mbox_cmd[0] = MBOX_CMD_SET_DATABASE_ENTRY;
778 mbox_cmd[1] = (uint32_t) fw_ddb_index;
779 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
780 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
781 mbox_cmd[4] = sizeof(struct dev_db_entry);
783 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
786 *mbx_sts = mbox_sts[0];
787 DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
788 ha->host_no, __func__, status, mbox_sts[0], mbox_sts[4]);)
793 int qla4xxx_session_logout_ddb(struct scsi_qla_host *ha,
794 struct ddb_entry *ddb_entry, int options)
797 uint32_t mbox_cmd[MBOX_REG_COUNT];
798 uint32_t mbox_sts[MBOX_REG_COUNT];
800 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
801 memset(&mbox_sts, 0, sizeof(mbox_sts));
803 mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
804 mbox_cmd[1] = ddb_entry->fw_ddb_index;
805 mbox_cmd[3] = options;
807 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
809 if (status != QLA_SUCCESS) {
810 DEBUG2(ql4_printk(KERN_INFO, ha,
811 "%s: MBOX_CMD_CONN_CLOSE_SESS_LOGOUT "
812 "failed sts %04X %04X", __func__,
813 mbox_sts[0], mbox_sts[1]));
820 * qla4xxx_get_crash_record - retrieves crash record.
821 * @ha: Pointer to host adapter structure.
823 * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
825 void qla4xxx_get_crash_record(struct scsi_qla_host * ha)
827 uint32_t mbox_cmd[MBOX_REG_COUNT];
828 uint32_t mbox_sts[MBOX_REG_COUNT];
829 struct crash_record *crash_record = NULL;
830 dma_addr_t crash_record_dma = 0;
831 uint32_t crash_record_size = 0;
833 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
834 memset(&mbox_sts, 0, sizeof(mbox_cmd));
836 /* Get size of crash record. */
837 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
839 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
841 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
842 ha->host_no, __func__));
843 goto exit_get_crash_record;
845 crash_record_size = mbox_sts[4];
846 if (crash_record_size == 0) {
847 DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
848 ha->host_no, __func__));
849 goto exit_get_crash_record;
852 /* Alloc Memory for Crash Record. */
853 crash_record = dma_alloc_coherent(&ha->pdev->dev, crash_record_size,
854 &crash_record_dma, GFP_KERNEL);
855 if (crash_record == NULL)
856 goto exit_get_crash_record;
858 /* Get Crash Record. */
859 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
860 memset(&mbox_sts, 0, sizeof(mbox_cmd));
862 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
863 mbox_cmd[2] = LSDW(crash_record_dma);
864 mbox_cmd[3] = MSDW(crash_record_dma);
865 mbox_cmd[4] = crash_record_size;
867 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
869 goto exit_get_crash_record;
871 /* Dump Crash Record. */
873 exit_get_crash_record:
875 dma_free_coherent(&ha->pdev->dev, crash_record_size,
876 crash_record, crash_record_dma);
880 * qla4xxx_get_conn_event_log - retrieves connection event log
881 * @ha: Pointer to host adapter structure.
883 void qla4xxx_get_conn_event_log(struct scsi_qla_host * ha)
885 uint32_t mbox_cmd[MBOX_REG_COUNT];
886 uint32_t mbox_sts[MBOX_REG_COUNT];
887 struct conn_event_log_entry *event_log = NULL;
888 dma_addr_t event_log_dma = 0;
889 uint32_t event_log_size = 0;
890 uint32_t num_valid_entries;
891 uint32_t oldest_entry = 0;
892 uint32_t max_event_log_entries;
895 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
896 memset(&mbox_sts, 0, sizeof(mbox_cmd));
898 /* Get size of crash record. */
899 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
901 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
903 goto exit_get_event_log;
905 event_log_size = mbox_sts[4];
906 if (event_log_size == 0)
907 goto exit_get_event_log;
909 /* Alloc Memory for Crash Record. */
910 event_log = dma_alloc_coherent(&ha->pdev->dev, event_log_size,
911 &event_log_dma, GFP_KERNEL);
912 if (event_log == NULL)
913 goto exit_get_event_log;
915 /* Get Crash Record. */
916 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
917 memset(&mbox_sts, 0, sizeof(mbox_cmd));
919 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
920 mbox_cmd[2] = LSDW(event_log_dma);
921 mbox_cmd[3] = MSDW(event_log_dma);
923 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
925 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
926 "log!\n", ha->host_no, __func__));
927 goto exit_get_event_log;
930 /* Dump Event Log. */
931 num_valid_entries = mbox_sts[1];
933 max_event_log_entries = event_log_size /
934 sizeof(struct conn_event_log_entry);
936 if (num_valid_entries > max_event_log_entries)
937 oldest_entry = num_valid_entries % max_event_log_entries;
939 DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
940 ha->host_no, num_valid_entries));
942 if (ql4xextended_error_logging == 3) {
943 if (oldest_entry == 0) {
944 /* Circular Buffer has not wrapped around */
945 for (i=0; i < num_valid_entries; i++) {
946 qla4xxx_dump_buffer((uint8_t *)event_log+
947 (i*sizeof(*event_log)),
952 /* Circular Buffer has wrapped around -
953 * display accordingly*/
954 for (i=oldest_entry; i < max_event_log_entries; i++) {
955 qla4xxx_dump_buffer((uint8_t *)event_log+
956 (i*sizeof(*event_log)),
959 for (i=0; i < oldest_entry; i++) {
960 qla4xxx_dump_buffer((uint8_t *)event_log+
961 (i*sizeof(*event_log)),
969 dma_free_coherent(&ha->pdev->dev, event_log_size, event_log,
974 * qla4xxx_abort_task - issues Abort Task
975 * @ha: Pointer to host adapter structure.
976 * @srb: Pointer to srb entry
978 * This routine performs a LUN RESET on the specified target/lun.
979 * The caller must ensure that the ddb_entry and lun_entry pointers
980 * are valid before calling this routine.
982 int qla4xxx_abort_task(struct scsi_qla_host *ha, struct srb *srb)
984 uint32_t mbox_cmd[MBOX_REG_COUNT];
985 uint32_t mbox_sts[MBOX_REG_COUNT];
986 struct scsi_cmnd *cmd = srb->cmd;
987 int status = QLA_SUCCESS;
988 unsigned long flags = 0;
992 * Send abort task command to ISP, so that the ISP will return
993 * request with ABORT status
995 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
996 memset(&mbox_sts, 0, sizeof(mbox_sts));
998 spin_lock_irqsave(&ha->hardware_lock, flags);
999 index = (unsigned long)(unsigned char *)cmd->host_scribble;
1000 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1002 /* Firmware already posted completion on response queue */
1003 if (index == MAX_SRBS)
1006 mbox_cmd[0] = MBOX_CMD_ABORT_TASK;
1007 mbox_cmd[1] = srb->ddb->fw_ddb_index;
1008 mbox_cmd[2] = index;
1009 /* Immediate Command Enable */
1012 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
1014 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE) {
1017 DEBUG2(printk(KERN_WARNING "scsi%ld:%d:%d: abort task FAILED: "
1018 "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
1019 ha->host_no, cmd->device->id, cmd->device->lun, mbox_sts[0],
1020 mbox_sts[1], mbox_sts[2], mbox_sts[3], mbox_sts[4]));
1027 * qla4xxx_reset_lun - issues LUN Reset
1028 * @ha: Pointer to host adapter structure.
1029 * @ddb_entry: Pointer to device database entry
1032 * This routine performs a LUN RESET on the specified target/lun.
1033 * The caller must ensure that the ddb_entry and lun_entry pointers
1034 * are valid before calling this routine.
1036 int qla4xxx_reset_lun(struct scsi_qla_host * ha, struct ddb_entry * ddb_entry,
1039 uint32_t mbox_cmd[MBOX_REG_COUNT];
1040 uint32_t mbox_sts[MBOX_REG_COUNT];
1041 int status = QLA_SUCCESS;
1043 DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha->host_no,
1044 ddb_entry->fw_ddb_index, lun));
1047 * Send lun reset command to ISP, so that the ISP will return all
1048 * outstanding requests with RESET status
1050 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1051 memset(&mbox_sts, 0, sizeof(mbox_sts));
1053 mbox_cmd[0] = MBOX_CMD_LUN_RESET;
1054 mbox_cmd[1] = ddb_entry->fw_ddb_index;
1055 mbox_cmd[2] = lun << 8;
1056 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
1058 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]);
1059 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
1060 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
1067 * qla4xxx_reset_target - issues target Reset
1068 * @ha: Pointer to host adapter structure.
1069 * @db_entry: Pointer to device database entry
1070 * @un_entry: Pointer to lun entry structure
1072 * This routine performs a TARGET RESET on the specified target.
1073 * The caller must ensure that the ddb_entry pointers
1074 * are valid before calling this routine.
1076 int qla4xxx_reset_target(struct scsi_qla_host *ha,
1077 struct ddb_entry *ddb_entry)
1079 uint32_t mbox_cmd[MBOX_REG_COUNT];
1080 uint32_t mbox_sts[MBOX_REG_COUNT];
1081 int status = QLA_SUCCESS;
1083 DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha->host_no,
1084 ddb_entry->fw_ddb_index));
1087 * Send target reset command to ISP, so that the ISP will return all
1088 * outstanding requests with RESET status
1090 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1091 memset(&mbox_sts, 0, sizeof(mbox_sts));
1093 mbox_cmd[0] = MBOX_CMD_TARGET_WARM_RESET;
1094 mbox_cmd[1] = ddb_entry->fw_ddb_index;
1095 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
1097 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1099 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
1100 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
1106 int qla4xxx_get_flash(struct scsi_qla_host * ha, dma_addr_t dma_addr,
1107 uint32_t offset, uint32_t len)
1109 uint32_t mbox_cmd[MBOX_REG_COUNT];
1110 uint32_t mbox_sts[MBOX_REG_COUNT];
1112 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1113 memset(&mbox_sts, 0, sizeof(mbox_sts));
1115 mbox_cmd[0] = MBOX_CMD_READ_FLASH;
1116 mbox_cmd[1] = LSDW(dma_addr);
1117 mbox_cmd[2] = MSDW(dma_addr);
1118 mbox_cmd[3] = offset;
1121 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0], &mbox_sts[0]) !=
1123 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
1124 "status %04X %04X, offset %08x, len %08x\n", ha->host_no,
1125 __func__, mbox_sts[0], mbox_sts[1], offset, len));
1132 * qla4xxx_about_firmware - gets FW, iscsi draft and boot loader version
1133 * @ha: Pointer to host adapter structure.
1135 * Retrieves the FW version, iSCSI draft version & bootloader version of HBA.
1136 * Mailboxes 2 & 3 may hold an address for data. Make sure that we write 0 to
1137 * those mailboxes, if unused.
1139 int qla4xxx_about_firmware(struct scsi_qla_host *ha)
1141 struct about_fw_info *about_fw = NULL;
1142 dma_addr_t about_fw_dma;
1143 uint32_t mbox_cmd[MBOX_REG_COUNT];
1144 uint32_t mbox_sts[MBOX_REG_COUNT];
1145 int status = QLA_ERROR;
1147 about_fw = dma_alloc_coherent(&ha->pdev->dev,
1148 sizeof(struct about_fw_info),
1149 &about_fw_dma, GFP_KERNEL);
1151 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Unable to alloc memory "
1152 "for about_fw\n", __func__));
1156 memset(about_fw, 0, sizeof(struct about_fw_info));
1157 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1158 memset(&mbox_sts, 0, sizeof(mbox_sts));
1160 mbox_cmd[0] = MBOX_CMD_ABOUT_FW;
1161 mbox_cmd[2] = LSDW(about_fw_dma);
1162 mbox_cmd[3] = MSDW(about_fw_dma);
1163 mbox_cmd[4] = sizeof(struct about_fw_info);
1165 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, MBOX_REG_COUNT,
1166 &mbox_cmd[0], &mbox_sts[0]);
1167 if (status != QLA_SUCCESS) {
1168 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_ABOUT_FW "
1169 "failed w/ status %04X\n", __func__,
1174 /* Save version information. */
1175 ha->firmware_version[0] = le16_to_cpu(about_fw->fw_major);
1176 ha->firmware_version[1] = le16_to_cpu(about_fw->fw_minor);
1177 ha->patch_number = le16_to_cpu(about_fw->fw_patch);
1178 ha->build_number = le16_to_cpu(about_fw->fw_build);
1179 ha->iscsi_major = le16_to_cpu(about_fw->iscsi_major);
1180 ha->iscsi_minor = le16_to_cpu(about_fw->iscsi_minor);
1181 ha->bootload_major = le16_to_cpu(about_fw->bootload_major);
1182 ha->bootload_minor = le16_to_cpu(about_fw->bootload_minor);
1183 ha->bootload_patch = le16_to_cpu(about_fw->bootload_patch);
1184 ha->bootload_build = le16_to_cpu(about_fw->bootload_build);
1185 status = QLA_SUCCESS;
1188 dma_free_coherent(&ha->pdev->dev, sizeof(struct about_fw_info),
1189 about_fw, about_fw_dma);
1193 static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha, uint32_t options,
1194 dma_addr_t dma_addr)
1196 uint32_t mbox_cmd[MBOX_REG_COUNT];
1197 uint32_t mbox_sts[MBOX_REG_COUNT];
1199 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1200 memset(&mbox_sts, 0, sizeof(mbox_sts));
1202 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS;
1203 mbox_cmd[1] = options;
1204 mbox_cmd[2] = LSDW(dma_addr);
1205 mbox_cmd[3] = MSDW(dma_addr);
1207 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]) !=
1209 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1210 ha->host_no, __func__, mbox_sts[0]));
1216 int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t ddb_index,
1220 uint32_t mbox_cmd[MBOX_REG_COUNT];
1221 uint32_t mbox_sts[MBOX_REG_COUNT];
1223 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1224 memset(&mbox_sts, 0, sizeof(mbox_sts));
1226 mbox_cmd[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY;
1227 mbox_cmd[1] = ddb_index;
1229 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1231 if (status != QLA_SUCCESS) {
1232 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
1233 __func__, mbox_sts[0]));
1236 *mbx_sts = mbox_sts[0];
1240 int qla4xxx_clear_ddb_entry(struct scsi_qla_host *ha, uint32_t ddb_index)
1243 uint32_t mbox_cmd[MBOX_REG_COUNT];
1244 uint32_t mbox_sts[MBOX_REG_COUNT];
1246 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1247 memset(&mbox_sts, 0, sizeof(mbox_sts));
1249 mbox_cmd[0] = MBOX_CMD_CLEAR_DATABASE_ENTRY;
1250 mbox_cmd[1] = ddb_index;
1252 status = qla4xxx_mailbox_command(ha, 2, 1, &mbox_cmd[0],
1254 if (status != QLA_SUCCESS) {
1255 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
1256 __func__, mbox_sts[0]));
1262 int qla4xxx_set_flash(struct scsi_qla_host *ha, dma_addr_t dma_addr,
1263 uint32_t offset, uint32_t length, uint32_t options)
1265 uint32_t mbox_cmd[MBOX_REG_COUNT];
1266 uint32_t mbox_sts[MBOX_REG_COUNT];
1267 int status = QLA_SUCCESS;
1269 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1270 memset(&mbox_sts, 0, sizeof(mbox_sts));
1272 mbox_cmd[0] = MBOX_CMD_WRITE_FLASH;
1273 mbox_cmd[1] = LSDW(dma_addr);
1274 mbox_cmd[2] = MSDW(dma_addr);
1275 mbox_cmd[3] = offset;
1276 mbox_cmd[4] = length;
1277 mbox_cmd[5] = options;
1279 status = qla4xxx_mailbox_command(ha, 6, 2, &mbox_cmd[0], &mbox_sts[0]);
1280 if (status != QLA_SUCCESS) {
1281 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_WRITE_FLASH "
1282 "failed w/ status %04X, mbx1 %04X\n",
1283 __func__, mbox_sts[0], mbox_sts[1]));
1288 int qla4xxx_bootdb_by_index(struct scsi_qla_host *ha,
1289 struct dev_db_entry *fw_ddb_entry,
1290 dma_addr_t fw_ddb_entry_dma, uint16_t ddb_index)
1292 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
1293 uint32_t dev_db_end_offset;
1294 int status = QLA_ERROR;
1296 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
1298 dev_db_start_offset += (ddb_index * sizeof(*fw_ddb_entry));
1299 dev_db_end_offset = FLASH_OFFSET_DB_END;
1301 if (dev_db_start_offset > dev_db_end_offset) {
1302 DEBUG2(ql4_printk(KERN_ERR, ha,
1303 "%s:Invalid DDB index %d", __func__,
1305 goto exit_bootdb_failed;
1308 if (qla4xxx_get_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
1309 sizeof(*fw_ddb_entry)) != QLA_SUCCESS) {
1310 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
1311 "failed\n", ha->host_no, __func__);
1312 goto exit_bootdb_failed;
1315 if (fw_ddb_entry->cookie == DDB_VALID_COOKIE)
1316 status = QLA_SUCCESS;
1322 int qla4xxx_get_chap(struct scsi_qla_host *ha, char *username, char *password,
1326 int rval = QLA_ERROR;
1327 uint32_t offset = 0, chap_size;
1328 struct ql4_chap_table *chap_table;
1329 dma_addr_t chap_dma;
1331 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
1332 if (chap_table == NULL) {
1337 chap_size = sizeof(struct ql4_chap_table);
1338 memset(chap_table, 0, chap_size);
1341 offset = FLASH_CHAP_OFFSET | (idx * chap_size);
1343 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
1344 /* flt_chap_size is CHAP table size for both ports
1345 * so divide it by 2 to calculate the offset for second port
1347 if (ha->port_num == 1)
1348 offset += (ha->hw.flt_chap_size / 2);
1349 offset += (idx * chap_size);
1352 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
1353 if (rval != QLA_SUCCESS) {
1358 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
1359 __le16_to_cpu(chap_table->cookie)));
1361 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
1362 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
1366 strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
1367 strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
1368 chap_table->cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
1371 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
1375 static int qla4xxx_set_chap(struct scsi_qla_host *ha, char *username,
1376 char *password, uint16_t idx, int bidi)
1379 int rval = QLA_ERROR;
1380 uint32_t offset = 0;
1381 struct ql4_chap_table *chap_table;
1382 dma_addr_t chap_dma;
1384 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
1385 if (chap_table == NULL) {
1390 memset(chap_table, 0, sizeof(struct ql4_chap_table));
1392 chap_table->flags |= BIT_6; /* peer */
1394 chap_table->flags |= BIT_7; /* local */
1395 chap_table->secret_len = strlen(password);
1396 strncpy(chap_table->secret, password, MAX_CHAP_SECRET_LEN);
1397 strncpy(chap_table->name, username, MAX_CHAP_NAME_LEN);
1398 chap_table->cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
1399 offset = FLASH_CHAP_OFFSET | (idx * sizeof(struct ql4_chap_table));
1400 rval = qla4xxx_set_flash(ha, chap_dma, offset,
1401 sizeof(struct ql4_chap_table),
1402 FLASH_OPT_RMW_COMMIT);
1404 if (rval == QLA_SUCCESS && ha->chap_list) {
1405 /* Update ha chap_list cache */
1406 memcpy((struct ql4_chap_table *)ha->chap_list + idx,
1407 chap_table, sizeof(struct ql4_chap_table));
1409 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
1410 if (rval != QLA_SUCCESS)
1418 * qla4xxx_get_chap_index - Get chap index given username and secret
1419 * @ha: pointer to adapter structure
1420 * @username: CHAP username to be searched
1421 * @password: CHAP password to be searched
1422 * @bidi: Is this a BIDI CHAP
1423 * @chap_index: CHAP index to be returned
1425 * Match the username and password in the chap_list, return the index if a
1426 * match is found. If a match is not found then add the entry in FLASH and
1427 * return the index at which entry is written in the FLASH.
1429 int qla4xxx_get_chap_index(struct scsi_qla_host *ha, char *username,
1430 char *password, int bidi, uint16_t *chap_index)
1433 int free_index = -1;
1434 int found_index = 0;
1435 int max_chap_entries = 0;
1436 struct ql4_chap_table *chap_table;
1439 max_chap_entries = (ha->hw.flt_chap_size / 2) /
1440 sizeof(struct ql4_chap_table);
1442 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
1444 if (!ha->chap_list) {
1445 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
1449 if (!username || !password) {
1450 ql4_printk(KERN_ERR, ha, "Do not have username and psw\n");
1454 mutex_lock(&ha->chap_sem);
1455 for (i = 0; i < max_chap_entries; i++) {
1456 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
1457 if (chap_table->cookie !=
1458 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
1459 if (i > MAX_RESRV_CHAP_IDX && free_index == -1)
1464 if (chap_table->flags & BIT_7)
1467 if (chap_table->flags & BIT_6)
1470 if (!strncmp(chap_table->secret, password,
1471 MAX_CHAP_SECRET_LEN) &&
1472 !strncmp(chap_table->name, username,
1473 MAX_CHAP_NAME_LEN)) {
1480 /* If chap entry is not present and a free index is available then
1481 * write the entry in flash
1483 if (!found_index && free_index != -1) {
1484 rval = qla4xxx_set_chap(ha, username, password,
1487 *chap_index = free_index;
1492 mutex_unlock(&ha->chap_sem);
1499 int qla4xxx_conn_close_sess_logout(struct scsi_qla_host *ha,
1500 uint16_t fw_ddb_index,
1501 uint16_t connection_id,
1504 uint32_t mbox_cmd[MBOX_REG_COUNT];
1505 uint32_t mbox_sts[MBOX_REG_COUNT];
1506 int status = QLA_SUCCESS;
1508 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1509 memset(&mbox_sts, 0, sizeof(mbox_sts));
1511 mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
1512 mbox_cmd[1] = fw_ddb_index;
1513 mbox_cmd[2] = connection_id;
1514 mbox_cmd[3] = option;
1516 status = qla4xxx_mailbox_command(ha, 4, 2, &mbox_cmd[0], &mbox_sts[0]);
1517 if (status != QLA_SUCCESS) {
1518 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_CONN_CLOSE "
1519 "option %04x failed w/ status %04X %04X\n",
1520 __func__, option, mbox_sts[0], mbox_sts[1]));
1525 int qla4xxx_disable_acb(struct scsi_qla_host *ha)
1527 uint32_t mbox_cmd[MBOX_REG_COUNT];
1528 uint32_t mbox_sts[MBOX_REG_COUNT];
1529 int status = QLA_SUCCESS;
1531 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1532 memset(&mbox_sts, 0, sizeof(mbox_sts));
1534 mbox_cmd[0] = MBOX_CMD_DISABLE_ACB;
1536 status = qla4xxx_mailbox_command(ha, 8, 5, &mbox_cmd[0], &mbox_sts[0]);
1537 if (status != QLA_SUCCESS) {
1538 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_DISABLE_ACB "
1539 "failed w/ status %04X %04X %04X", __func__,
1540 mbox_sts[0], mbox_sts[1], mbox_sts[2]));
1545 int qla4xxx_get_acb(struct scsi_qla_host *ha, dma_addr_t acb_dma,
1546 uint32_t acb_type, uint32_t len)
1548 uint32_t mbox_cmd[MBOX_REG_COUNT];
1549 uint32_t mbox_sts[MBOX_REG_COUNT];
1550 int status = QLA_SUCCESS;
1552 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1553 memset(&mbox_sts, 0, sizeof(mbox_sts));
1555 mbox_cmd[0] = MBOX_CMD_GET_ACB;
1556 mbox_cmd[1] = acb_type;
1557 mbox_cmd[2] = LSDW(acb_dma);
1558 mbox_cmd[3] = MSDW(acb_dma);
1561 status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
1562 if (status != QLA_SUCCESS) {
1563 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_GET_ACB "
1564 "failed w/ status %04X\n", __func__,
1570 int qla4xxx_set_acb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
1571 uint32_t *mbox_sts, dma_addr_t acb_dma)
1573 int status = QLA_SUCCESS;
1575 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
1576 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
1577 mbox_cmd[0] = MBOX_CMD_SET_ACB;
1578 mbox_cmd[1] = 0; /* Primary ACB */
1579 mbox_cmd[2] = LSDW(acb_dma);
1580 mbox_cmd[3] = MSDW(acb_dma);
1581 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
1583 status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
1584 if (status != QLA_SUCCESS) {
1585 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_SET_ACB "
1586 "failed w/ status %04X\n", __func__,
1592 int qla4xxx_set_param_ddbentry(struct scsi_qla_host *ha,
1593 struct ddb_entry *ddb_entry,
1594 struct iscsi_cls_conn *cls_conn,
1597 struct dev_db_entry *fw_ddb_entry;
1598 struct iscsi_conn *conn;
1599 struct iscsi_session *sess;
1600 struct qla_conn *qla_conn;
1601 struct sockaddr *dst_addr;
1602 dma_addr_t fw_ddb_entry_dma;
1603 int status = QLA_SUCCESS;
1605 struct sockaddr_in *addr;
1606 struct sockaddr_in6 *addr6;
1608 uint16_t iscsi_opts = 0;
1609 uint32_t options = 0;
1612 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1613 &fw_ddb_entry_dma, GFP_KERNEL);
1614 if (!fw_ddb_entry) {
1615 DEBUG2(ql4_printk(KERN_ERR, ha,
1616 "%s: Unable to allocate dma buffer.\n",
1619 goto exit_set_param_no_free;
1622 conn = cls_conn->dd_data;
1623 qla_conn = conn->dd_data;
1624 sess = conn->session;
1625 dst_addr = &qla_conn->qla_ep->dst_addr;
1627 if (dst_addr->sa_family == AF_INET6)
1628 options |= IPV6_DEFAULT_DDB_ENTRY;
1630 status = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
1631 if (status == QLA_ERROR) {
1633 goto exit_set_param;
1636 iscsi_opts = le16_to_cpu(fw_ddb_entry->iscsi_options);
1637 memset(fw_ddb_entry->iscsi_alias, 0, sizeof(fw_ddb_entry->iscsi_alias));
1639 memset(fw_ddb_entry->iscsi_name, 0, sizeof(fw_ddb_entry->iscsi_name));
1641 if (sess->targetname != NULL) {
1642 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
1643 min(strlen(sess->targetname),
1644 sizeof(fw_ddb_entry->iscsi_name)));
1647 memset(fw_ddb_entry->ip_addr, 0, sizeof(fw_ddb_entry->ip_addr));
1648 memset(fw_ddb_entry->tgt_addr, 0, sizeof(fw_ddb_entry->tgt_addr));
1650 fw_ddb_entry->options = DDB_OPT_TARGET | DDB_OPT_AUTO_SENDTGTS_DISABLE;
1652 if (dst_addr->sa_family == AF_INET) {
1653 addr = (struct sockaddr_in *)dst_addr;
1654 ip = (char *)&addr->sin_addr;
1655 memcpy(fw_ddb_entry->ip_addr, ip, IP_ADDR_LEN);
1656 fw_ddb_entry->port = cpu_to_le16(ntohs(addr->sin_port));
1657 DEBUG2(ql4_printk(KERN_INFO, ha,
1658 "%s: Destination Address [%pI4]: index [%d]\n",
1659 __func__, fw_ddb_entry->ip_addr,
1660 ddb_entry->fw_ddb_index));
1661 } else if (dst_addr->sa_family == AF_INET6) {
1662 addr6 = (struct sockaddr_in6 *)dst_addr;
1663 ip = (char *)&addr6->sin6_addr;
1664 memcpy(fw_ddb_entry->ip_addr, ip, IPv6_ADDR_LEN);
1665 fw_ddb_entry->port = cpu_to_le16(ntohs(addr6->sin6_port));
1666 fw_ddb_entry->options |= DDB_OPT_IPV6_DEVICE;
1667 DEBUG2(ql4_printk(KERN_INFO, ha,
1668 "%s: Destination Address [%pI6]: index [%d]\n",
1669 __func__, fw_ddb_entry->ip_addr,
1670 ddb_entry->fw_ddb_index));
1672 ql4_printk(KERN_ERR, ha,
1673 "%s: Failed to get IP Address\n",
1676 goto exit_set_param;
1680 if (sess->username != NULL && sess->password != NULL) {
1681 if (strlen(sess->username) && strlen(sess->password)) {
1682 iscsi_opts |= BIT_7;
1684 rval = qla4xxx_get_chap_index(ha, sess->username,
1688 goto exit_set_param;
1690 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(idx);
1694 if (sess->username_in != NULL && sess->password_in != NULL) {
1695 /* Check if BIDI CHAP */
1696 if (strlen(sess->username_in) && strlen(sess->password_in)) {
1697 iscsi_opts |= BIT_4;
1699 rval = qla4xxx_get_chap_index(ha, sess->username_in,
1703 goto exit_set_param;
1707 if (sess->initial_r2t_en)
1708 iscsi_opts |= BIT_10;
1710 if (sess->imm_data_en)
1711 iscsi_opts |= BIT_11;
1713 fw_ddb_entry->iscsi_options = cpu_to_le16(iscsi_opts);
1715 if (conn->max_recv_dlength)
1716 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
1717 __constant_cpu_to_le16((conn->max_recv_dlength / BYTE_UNITS));
1720 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
1722 if (sess->first_burst)
1723 fw_ddb_entry->iscsi_first_burst_len =
1724 __constant_cpu_to_le16((sess->first_burst / BYTE_UNITS));
1726 if (sess->max_burst)
1727 fw_ddb_entry->iscsi_max_burst_len =
1728 __constant_cpu_to_le16((sess->max_burst / BYTE_UNITS));
1730 if (sess->time2wait)
1731 fw_ddb_entry->iscsi_def_time2wait =
1732 cpu_to_le16(sess->time2wait);
1734 if (sess->time2retain)
1735 fw_ddb_entry->iscsi_def_time2retain =
1736 cpu_to_le16(sess->time2retain);
1738 status = qla4xxx_set_ddb_entry(ha, ddb_entry->fw_ddb_index,
1739 fw_ddb_entry_dma, mbx_sts);
1741 if (status != QLA_SUCCESS)
1744 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1745 fw_ddb_entry, fw_ddb_entry_dma);
1746 exit_set_param_no_free:
1750 int qla4xxx_get_mgmt_data(struct scsi_qla_host *ha, uint16_t fw_ddb_index,
1751 uint16_t stats_size, dma_addr_t stats_dma)
1753 int status = QLA_SUCCESS;
1754 uint32_t mbox_cmd[MBOX_REG_COUNT];
1755 uint32_t mbox_sts[MBOX_REG_COUNT];
1757 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
1758 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
1759 mbox_cmd[0] = MBOX_CMD_GET_MANAGEMENT_DATA;
1760 mbox_cmd[1] = fw_ddb_index;
1761 mbox_cmd[2] = LSDW(stats_dma);
1762 mbox_cmd[3] = MSDW(stats_dma);
1763 mbox_cmd[4] = stats_size;
1765 status = qla4xxx_mailbox_command(ha, 5, 1, &mbox_cmd[0], &mbox_sts[0]);
1766 if (status != QLA_SUCCESS) {
1767 DEBUG2(ql4_printk(KERN_WARNING, ha,
1768 "%s: MBOX_CMD_GET_MANAGEMENT_DATA "
1769 "failed w/ status %04X\n", __func__,
1775 int qla4xxx_get_ip_state(struct scsi_qla_host *ha, uint32_t acb_idx,
1776 uint32_t ip_idx, uint32_t *sts)
1778 uint32_t mbox_cmd[MBOX_REG_COUNT];
1779 uint32_t mbox_sts[MBOX_REG_COUNT];
1780 int status = QLA_SUCCESS;
1782 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1783 memset(&mbox_sts, 0, sizeof(mbox_sts));
1784 mbox_cmd[0] = MBOX_CMD_GET_IP_ADDR_STATE;
1785 mbox_cmd[1] = acb_idx;
1786 mbox_cmd[2] = ip_idx;
1788 status = qla4xxx_mailbox_command(ha, 3, 8, &mbox_cmd[0], &mbox_sts[0]);
1789 if (status != QLA_SUCCESS) {
1790 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: "
1791 "MBOX_CMD_GET_IP_ADDR_STATE failed w/ "
1792 "status %04X\n", __func__, mbox_sts[0]));
1794 memcpy(sts, mbox_sts, sizeof(mbox_sts));
1798 int qla4xxx_get_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
1799 uint32_t offset, uint32_t size)
1801 int status = QLA_SUCCESS;
1802 uint32_t mbox_cmd[MBOX_REG_COUNT];
1803 uint32_t mbox_sts[MBOX_REG_COUNT];
1805 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1806 memset(&mbox_sts, 0, sizeof(mbox_sts));
1808 mbox_cmd[0] = MBOX_CMD_GET_NVRAM;
1809 mbox_cmd[1] = LSDW(nvram_dma);
1810 mbox_cmd[2] = MSDW(nvram_dma);
1811 mbox_cmd[3] = offset;
1814 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1816 if (status != QLA_SUCCESS) {
1817 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1818 "status %04X\n", ha->host_no, __func__,
1824 int qla4xxx_set_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
1825 uint32_t offset, uint32_t size)
1827 int status = QLA_SUCCESS;
1828 uint32_t mbox_cmd[MBOX_REG_COUNT];
1829 uint32_t mbox_sts[MBOX_REG_COUNT];
1831 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1832 memset(&mbox_sts, 0, sizeof(mbox_sts));
1834 mbox_cmd[0] = MBOX_CMD_SET_NVRAM;
1835 mbox_cmd[1] = LSDW(nvram_dma);
1836 mbox_cmd[2] = MSDW(nvram_dma);
1837 mbox_cmd[3] = offset;
1840 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1842 if (status != QLA_SUCCESS) {
1843 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1844 "status %04X\n", ha->host_no, __func__,
1850 int qla4xxx_restore_factory_defaults(struct scsi_qla_host *ha,
1851 uint32_t region, uint32_t field0,
1854 int status = QLA_SUCCESS;
1855 uint32_t mbox_cmd[MBOX_REG_COUNT];
1856 uint32_t mbox_sts[MBOX_REG_COUNT];
1858 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1859 memset(&mbox_sts, 0, sizeof(mbox_sts));
1861 mbox_cmd[0] = MBOX_CMD_RESTORE_FACTORY_DEFAULTS;
1862 mbox_cmd[3] = region;
1863 mbox_cmd[4] = field0;
1864 mbox_cmd[5] = field1;
1866 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0],
1868 if (status != QLA_SUCCESS) {
1869 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1870 "status %04X\n", ha->host_no, __func__,