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_FW_RECOVERY
, &ha
->flags
)) {
46 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "scsi%ld: %s: "
47 "prematurely completing mbx cmd as firmware "
48 "recovery detected\n", ha
->host_no
, __func__
));
51 /* Do not send any mbx cmd if h/w is in failed state*/
52 qla4_8xxx_idc_lock(ha
);
53 dev_state
= qla4_8xxx_rd_32(ha
, QLA82XX_CRB_DEV_STATE
);
54 qla4_8xxx_idc_unlock(ha
);
55 if (dev_state
== QLA82XX_DEV_FAILED
) {
56 ql4_printk(KERN_WARNING
, ha
, "scsi%ld: %s: H/W is in "
57 "failed state, do not send any mailbox commands\n",
58 ha
->host_no
, __func__
);
63 if ((is_aer_supported(ha
)) &&
64 (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE
, &ha
->flags
))) {
65 DEBUG2(printk(KERN_WARNING
"scsi%ld: %s: Perm failure on EEH, "
66 "timeout MBX Exiting.\n", ha
->host_no
, __func__
));
70 /* Mailbox code active */
71 wait_count
= MBOX_TOV
* 100;
73 while (wait_count
--) {
74 mutex_lock(&ha
->mbox_sem
);
75 if (!test_bit(AF_MBOX_COMMAND
, &ha
->flags
)) {
76 set_bit(AF_MBOX_COMMAND
, &ha
->flags
);
77 mutex_unlock(&ha
->mbox_sem
);
80 mutex_unlock(&ha
->mbox_sem
);
82 DEBUG2(printk("scsi%ld: %s: mbox_sem failed\n",
83 ha
->host_no
, __func__
));
89 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
91 ha
->mbox_status_count
= outCount
;
92 for (i
= 0; i
< outCount
; i
++)
93 ha
->mbox_status
[i
] = 0;
96 /* Load all mailbox registers, except mailbox 0. */
98 printk("scsi%ld: %s: Cmd ", ha
->host_no
, __func__
);
99 for (i
= 0; i
< inCount
; i
++)
100 printk("mb%d=%04x ", i
, mbx_cmd
[i
]);
103 for (i
= 1; i
< inCount
; i
++)
104 writel(mbx_cmd
[i
], &ha
->qla4_8xxx_reg
->mailbox_in
[i
]);
105 writel(mbx_cmd
[0], &ha
->qla4_8xxx_reg
->mailbox_in
[0]);
106 readl(&ha
->qla4_8xxx_reg
->mailbox_in
[0]);
107 writel(HINT_MBX_INT_PENDING
, &ha
->qla4_8xxx_reg
->hint
);
109 /* Load all mailbox registers, except mailbox 0. */
110 for (i
= 1; i
< inCount
; i
++)
111 writel(mbx_cmd
[i
], &ha
->reg
->mailbox
[i
]);
113 /* Wakeup firmware */
114 writel(mbx_cmd
[0], &ha
->reg
->mailbox
[0]);
115 readl(&ha
->reg
->mailbox
[0]);
116 writel(set_rmask(CSR_INTR_RISC
), &ha
->reg
->ctrl_status
);
117 readl(&ha
->reg
->ctrl_status
);
120 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
122 /* Wait for completion */
125 * If we don't want status, don't wait for the mailbox command to
126 * complete. For example, MBOX_CMD_RESET_FW doesn't return status,
127 * you must poll the inbound Interrupt Mask for completion.
130 status
= QLA_SUCCESS
;
135 * Wait for completion: Poll or completion queue
137 if (test_bit(AF_IRQ_ATTACHED
, &ha
->flags
) &&
138 test_bit(AF_INTERRUPTS_ON
, &ha
->flags
) &&
139 test_bit(AF_ONLINE
, &ha
->flags
) &&
140 !test_bit(AF_HA_REMOVAL
, &ha
->flags
)) {
141 /* Do not poll for completion. Use completion queue */
142 set_bit(AF_MBOX_COMMAND_NOPOLL
, &ha
->flags
);
143 wait_for_completion_timeout(&ha
->mbx_intr_comp
, MBOX_TOV
* HZ
);
144 clear_bit(AF_MBOX_COMMAND_NOPOLL
, &ha
->flags
);
146 /* Poll for command to complete */
147 wait_count
= jiffies
+ MBOX_TOV
* HZ
;
148 while (test_bit(AF_MBOX_COMMAND_DONE
, &ha
->flags
) == 0) {
149 if (time_after_eq(jiffies
, wait_count
))
153 * Service the interrupt.
154 * The ISR will save the mailbox status registers
155 * to a temporary storage location in the adapter
159 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
160 if (is_qla8022(ha
)) {
162 readl(&ha
->qla4_8xxx_reg
->host_int
);
163 if (intr_status
& ISRX_82XX_RISC_INT
) {
164 ha
->mbox_status_count
= outCount
;
166 readl(&ha
->qla4_8xxx_reg
->host_status
);
167 ha
->isp_ops
->interrupt_service_routine(
169 if (test_bit(AF_INTERRUPTS_ON
,
171 test_bit(AF_INTx_ENABLED
,
174 ha
->nx_legacy_intr
.tgt_mask_reg
,
178 intr_status
= readl(&ha
->reg
->ctrl_status
);
179 if (intr_status
& INTR_PENDING
) {
181 * Service the interrupt.
182 * The ISR will save the mailbox status
183 * registers to a temporary storage
184 * location in the adapter structure.
186 ha
->mbox_status_count
= outCount
;
187 ha
->isp_ops
->interrupt_service_routine(
191 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
196 /* Check for mailbox timeout. */
197 if (!test_bit(AF_MBOX_COMMAND_DONE
, &ha
->flags
)) {
198 if (is_qla8022(ha
) &&
199 test_bit(AF_FW_RECOVERY
, &ha
->flags
)) {
200 DEBUG2(ql4_printk(KERN_INFO
, ha
,
201 "scsi%ld: %s: prematurely completing mbx cmd as "
202 "firmware recovery detected\n",
203 ha
->host_no
, __func__
));
206 DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
207 " Scheduling Adapter Reset\n", ha
->host_no
,
209 ha
->mailbox_timeout_count
++;
211 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
216 * Copy the mailbox out registers to the caller's mailbox in/out
219 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
220 for (i
= 0; i
< outCount
; i
++)
221 mbx_sts
[i
] = ha
->mbox_status
[i
];
223 /* Set return status and error flags (if applicable). */
224 switch (ha
->mbox_status
[0]) {
225 case MBOX_STS_COMMAND_COMPLETE
:
226 status
= QLA_SUCCESS
;
229 case MBOX_STS_INTERMEDIATE_COMPLETION
:
230 status
= QLA_SUCCESS
;
234 DEBUG2( printk("scsi%ld: %s: Cmd = %08X, ISP BUSY\n",
235 ha
->host_no
, __func__
, mbx_cmd
[0]));
236 ha
->mailbox_timeout_count
++;
240 DEBUG2(printk("scsi%ld: %s: **** FAILED, cmd = %08X, "
241 "sts = %08X ****\n", ha
->host_no
, __func__
,
242 mbx_cmd
[0], mbx_sts
[0]));
245 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
248 mutex_lock(&ha
->mbox_sem
);
249 clear_bit(AF_MBOX_COMMAND
, &ha
->flags
);
250 mutex_unlock(&ha
->mbox_sem
);
251 clear_bit(AF_MBOX_COMMAND_DONE
, &ha
->flags
);
256 void qla4xxx_mailbox_premature_completion(struct scsi_qla_host
*ha
)
258 set_bit(AF_FW_RECOVERY
, &ha
->flags
);
259 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: set FW RECOVERY!\n",
260 ha
->host_no
, __func__
);
262 if (test_bit(AF_MBOX_COMMAND
, &ha
->flags
)) {
263 if (test_bit(AF_MBOX_COMMAND_NOPOLL
, &ha
->flags
)) {
264 complete(&ha
->mbx_intr_comp
);
265 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: Due to fw "
266 "recovery, doing premature completion of "
267 "mbx cmd\n", ha
->host_no
, __func__
);
270 set_bit(AF_MBOX_COMMAND_DONE
, &ha
->flags
);
271 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: Due to fw "
272 "recovery, doing premature completion of "
273 "polling mbx cmd\n", ha
->host_no
, __func__
);
279 qla4xxx_set_ifcb(struct scsi_qla_host
*ha
, uint32_t *mbox_cmd
,
280 uint32_t *mbox_sts
, dma_addr_t init_fw_cb_dma
)
282 memset(mbox_cmd
, 0, sizeof(mbox_cmd
[0]) * MBOX_REG_COUNT
);
283 memset(mbox_sts
, 0, sizeof(mbox_sts
[0]) * MBOX_REG_COUNT
);
286 qla4_8xxx_wr_32(ha
, ha
->nx_db_wr_ptr
, 0);
288 mbox_cmd
[0] = MBOX_CMD_INITIALIZE_FIRMWARE
;
290 mbox_cmd
[2] = LSDW(init_fw_cb_dma
);
291 mbox_cmd
[3] = MSDW(init_fw_cb_dma
);
292 mbox_cmd
[4] = sizeof(struct addr_ctrl_blk
);
293 mbox_cmd
[5] = (IFCB_VER_MAX
<< 8) | IFCB_VER_MIN
;
295 if (qla4xxx_mailbox_command(ha
, 6, 6, mbox_cmd
, mbox_sts
) !=
297 DEBUG2(printk(KERN_WARNING
"scsi%ld: %s: "
298 "MBOX_CMD_INITIALIZE_FIRMWARE"
299 " failed w/ status %04X\n",
300 ha
->host_no
, __func__
, mbox_sts
[0]));
307 qla4xxx_get_ifcb(struct scsi_qla_host
*ha
, uint32_t *mbox_cmd
,
308 uint32_t *mbox_sts
, dma_addr_t init_fw_cb_dma
)
310 memset(mbox_cmd
, 0, sizeof(mbox_cmd
[0]) * MBOX_REG_COUNT
);
311 memset(mbox_sts
, 0, sizeof(mbox_sts
[0]) * MBOX_REG_COUNT
);
312 mbox_cmd
[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK
;
313 mbox_cmd
[2] = LSDW(init_fw_cb_dma
);
314 mbox_cmd
[3] = MSDW(init_fw_cb_dma
);
315 mbox_cmd
[4] = sizeof(struct addr_ctrl_blk
);
317 if (qla4xxx_mailbox_command(ha
, 5, 5, mbox_cmd
, mbox_sts
) !=
319 DEBUG2(printk(KERN_WARNING
"scsi%ld: %s: "
320 "MBOX_CMD_GET_INIT_FW_CTRL_BLOCK"
321 " failed w/ status %04X\n",
322 ha
->host_no
, __func__
, mbox_sts
[0]));
329 qla4xxx_update_local_ip(struct scsi_qla_host
*ha
,
330 struct addr_ctrl_blk
*init_fw_cb
)
332 ha
->ip_config
.tcp_options
= le16_to_cpu(init_fw_cb
->ipv4_tcp_opts
);
333 ha
->ip_config
.ipv4_options
= le16_to_cpu(init_fw_cb
->ipv4_ip_opts
);
334 ha
->ip_config
.ipv4_addr_state
=
335 le16_to_cpu(init_fw_cb
->ipv4_addr_state
);
336 ha
->ip_config
.eth_mtu_size
=
337 le16_to_cpu(init_fw_cb
->eth_mtu_size
);
338 ha
->ip_config
.ipv4_port
= le16_to_cpu(init_fw_cb
->ipv4_port
);
340 if (ha
->acb_version
== ACB_SUPPORTED
) {
341 ha
->ip_config
.ipv6_options
= le16_to_cpu(init_fw_cb
->ipv6_opts
);
342 ha
->ip_config
.ipv6_addl_options
=
343 le16_to_cpu(init_fw_cb
->ipv6_addtl_opts
);
346 /* Save IPv4 Address Info */
347 memcpy(ha
->ip_config
.ip_address
, init_fw_cb
->ipv4_addr
,
348 min(sizeof(ha
->ip_config
.ip_address
),
349 sizeof(init_fw_cb
->ipv4_addr
)));
350 memcpy(ha
->ip_config
.subnet_mask
, init_fw_cb
->ipv4_subnet
,
351 min(sizeof(ha
->ip_config
.subnet_mask
),
352 sizeof(init_fw_cb
->ipv4_subnet
)));
353 memcpy(ha
->ip_config
.gateway
, init_fw_cb
->ipv4_gw_addr
,
354 min(sizeof(ha
->ip_config
.gateway
),
355 sizeof(init_fw_cb
->ipv4_gw_addr
)));
357 ha
->ip_config
.ipv4_vlan_tag
= be16_to_cpu(init_fw_cb
->ipv4_vlan_tag
);
359 if (is_ipv6_enabled(ha
)) {
360 /* Save IPv6 Address */
361 ha
->ip_config
.ipv6_link_local_state
=
362 le16_to_cpu(init_fw_cb
->ipv6_lnk_lcl_addr_state
);
363 ha
->ip_config
.ipv6_addr0_state
=
364 le16_to_cpu(init_fw_cb
->ipv6_addr0_state
);
365 ha
->ip_config
.ipv6_addr1_state
=
366 le16_to_cpu(init_fw_cb
->ipv6_addr1_state
);
367 ha
->ip_config
.ipv6_default_router_state
=
368 le16_to_cpu(init_fw_cb
->ipv6_dflt_rtr_state
);
369 ha
->ip_config
.ipv6_link_local_addr
.in6_u
.u6_addr8
[0] = 0xFE;
370 ha
->ip_config
.ipv6_link_local_addr
.in6_u
.u6_addr8
[1] = 0x80;
372 memcpy(&ha
->ip_config
.ipv6_link_local_addr
.in6_u
.u6_addr8
[8],
373 init_fw_cb
->ipv6_if_id
,
374 min(sizeof(ha
->ip_config
.ipv6_link_local_addr
)/2,
375 sizeof(init_fw_cb
->ipv6_if_id
)));
376 memcpy(&ha
->ip_config
.ipv6_addr0
, init_fw_cb
->ipv6_addr0
,
377 min(sizeof(ha
->ip_config
.ipv6_addr0
),
378 sizeof(init_fw_cb
->ipv6_addr0
)));
379 memcpy(&ha
->ip_config
.ipv6_addr1
, init_fw_cb
->ipv6_addr1
,
380 min(sizeof(ha
->ip_config
.ipv6_addr1
),
381 sizeof(init_fw_cb
->ipv6_addr1
)));
382 memcpy(&ha
->ip_config
.ipv6_default_router_addr
,
383 init_fw_cb
->ipv6_dflt_rtr_addr
,
384 min(sizeof(ha
->ip_config
.ipv6_default_router_addr
),
385 sizeof(init_fw_cb
->ipv6_dflt_rtr_addr
)));
386 ha
->ip_config
.ipv6_vlan_tag
=
387 be16_to_cpu(init_fw_cb
->ipv6_vlan_tag
);
388 ha
->ip_config
.ipv6_port
= le16_to_cpu(init_fw_cb
->ipv6_port
);
393 qla4xxx_update_local_ifcb(struct scsi_qla_host
*ha
,
396 struct addr_ctrl_blk
*init_fw_cb
,
397 dma_addr_t init_fw_cb_dma
)
399 if (qla4xxx_get_ifcb(ha
, mbox_cmd
, mbox_sts
, init_fw_cb_dma
)
401 DEBUG2(printk(KERN_WARNING
402 "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
403 ha
->host_no
, __func__
));
407 DEBUG2(qla4xxx_dump_buffer(init_fw_cb
, sizeof(struct addr_ctrl_blk
)));
409 /* Save some info in adapter structure. */
410 ha
->acb_version
= init_fw_cb
->acb_version
;
411 ha
->firmware_options
= le16_to_cpu(init_fw_cb
->fw_options
);
412 ha
->heartbeat_interval
= init_fw_cb
->hb_interval
;
413 memcpy(ha
->name_string
, init_fw_cb
->iscsi_name
,
414 min(sizeof(ha
->name_string
),
415 sizeof(init_fw_cb
->iscsi_name
)));
416 /*memcpy(ha->alias, init_fw_cb->Alias,
417 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
419 qla4xxx_update_local_ip(ha
, init_fw_cb
);
425 * qla4xxx_initialize_fw_cb - initializes firmware control block.
426 * @ha: Pointer to host adapter structure.
428 int qla4xxx_initialize_fw_cb(struct scsi_qla_host
* ha
)
430 struct addr_ctrl_blk
*init_fw_cb
;
431 dma_addr_t init_fw_cb_dma
;
432 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
433 uint32_t mbox_sts
[MBOX_REG_COUNT
];
434 int status
= QLA_ERROR
;
436 init_fw_cb
= dma_alloc_coherent(&ha
->pdev
->dev
,
437 sizeof(struct addr_ctrl_blk
),
438 &init_fw_cb_dma
, GFP_KERNEL
);
439 if (init_fw_cb
== NULL
) {
440 DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
441 ha
->host_no
, __func__
));
442 goto exit_init_fw_cb_no_free
;
444 memset(init_fw_cb
, 0, sizeof(struct addr_ctrl_blk
));
446 /* Get Initialize Firmware Control Block. */
447 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
448 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
450 if (qla4xxx_get_ifcb(ha
, &mbox_cmd
[0], &mbox_sts
[0], init_fw_cb_dma
) !=
452 dma_free_coherent(&ha
->pdev
->dev
,
453 sizeof(struct addr_ctrl_blk
),
454 init_fw_cb
, init_fw_cb_dma
);
455 goto exit_init_fw_cb
;
458 /* Initialize request and response queues. */
459 qla4xxx_init_rings(ha
);
461 /* Fill in the request and response queue information. */
462 init_fw_cb
->rqq_consumer_idx
= cpu_to_le16(ha
->request_out
);
463 init_fw_cb
->compq_producer_idx
= cpu_to_le16(ha
->response_in
);
464 init_fw_cb
->rqq_len
= __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH
);
465 init_fw_cb
->compq_len
= __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH
);
466 init_fw_cb
->rqq_addr_lo
= cpu_to_le32(LSDW(ha
->request_dma
));
467 init_fw_cb
->rqq_addr_hi
= cpu_to_le32(MSDW(ha
->request_dma
));
468 init_fw_cb
->compq_addr_lo
= cpu_to_le32(LSDW(ha
->response_dma
));
469 init_fw_cb
->compq_addr_hi
= cpu_to_le32(MSDW(ha
->response_dma
));
470 init_fw_cb
->shdwreg_addr_lo
= cpu_to_le32(LSDW(ha
->shadow_regs_dma
));
471 init_fw_cb
->shdwreg_addr_hi
= cpu_to_le32(MSDW(ha
->shadow_regs_dma
));
473 /* Set up required options. */
474 init_fw_cb
->fw_options
|=
475 __constant_cpu_to_le16(FWOPT_SESSION_MODE
|
476 FWOPT_INITIATOR_MODE
);
479 init_fw_cb
->fw_options
|=
480 __constant_cpu_to_le16(FWOPT_ENABLE_CRBDB
);
482 init_fw_cb
->fw_options
&= __constant_cpu_to_le16(~FWOPT_TARGET_MODE
);
484 init_fw_cb
->add_fw_options
= 0;
485 init_fw_cb
->add_fw_options
|=
486 __constant_cpu_to_le16(ADFWOPT_SERIALIZE_TASK_MGMT
);
487 init_fw_cb
->add_fw_options
|=
488 __constant_cpu_to_le16(ADFWOPT_AUTOCONN_DISABLE
);
490 if (qla4xxx_set_ifcb(ha
, &mbox_cmd
[0], &mbox_sts
[0], init_fw_cb_dma
)
492 DEBUG2(printk(KERN_WARNING
493 "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
494 ha
->host_no
, __func__
));
495 goto exit_init_fw_cb
;
498 if (qla4xxx_update_local_ifcb(ha
, &mbox_cmd
[0], &mbox_sts
[0],
499 init_fw_cb
, init_fw_cb_dma
) != QLA_SUCCESS
) {
500 DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
501 ha
->host_no
, __func__
));
502 goto exit_init_fw_cb
;
504 status
= QLA_SUCCESS
;
507 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct addr_ctrl_blk
),
508 init_fw_cb
, init_fw_cb_dma
);
509 exit_init_fw_cb_no_free
:
514 * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
515 * @ha: Pointer to host adapter structure.
517 int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host
* ha
)
519 struct addr_ctrl_blk
*init_fw_cb
;
520 dma_addr_t init_fw_cb_dma
;
521 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
522 uint32_t mbox_sts
[MBOX_REG_COUNT
];
524 init_fw_cb
= dma_alloc_coherent(&ha
->pdev
->dev
,
525 sizeof(struct addr_ctrl_blk
),
526 &init_fw_cb_dma
, GFP_KERNEL
);
527 if (init_fw_cb
== NULL
) {
528 printk("scsi%ld: %s: Unable to alloc init_cb\n", ha
->host_no
,
533 /* Get Initialize Firmware Control Block. */
534 memset(init_fw_cb
, 0, sizeof(struct addr_ctrl_blk
));
535 if (qla4xxx_get_ifcb(ha
, &mbox_cmd
[0], &mbox_sts
[0], init_fw_cb_dma
) !=
537 DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
538 ha
->host_no
, __func__
));
539 dma_free_coherent(&ha
->pdev
->dev
,
540 sizeof(struct addr_ctrl_blk
),
541 init_fw_cb
, init_fw_cb_dma
);
545 /* Save IP Address. */
546 qla4xxx_update_local_ip(ha
, init_fw_cb
);
547 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct addr_ctrl_blk
),
548 init_fw_cb
, init_fw_cb_dma
);
554 * qla4xxx_get_firmware_state - gets firmware state of HBA
555 * @ha: Pointer to host adapter structure.
557 int qla4xxx_get_firmware_state(struct scsi_qla_host
* ha
)
559 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
560 uint32_t mbox_sts
[MBOX_REG_COUNT
];
562 /* Get firmware version */
563 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
564 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
566 mbox_cmd
[0] = MBOX_CMD_GET_FW_STATE
;
568 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 4, &mbox_cmd
[0], &mbox_sts
[0]) !=
570 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
571 "status %04X\n", ha
->host_no
, __func__
,
575 ha
->firmware_state
= mbox_sts
[1];
576 ha
->board_id
= mbox_sts
[2];
577 ha
->addl_fw_state
= mbox_sts
[3];
578 DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
579 ha
->host_no
, __func__
, ha
->firmware_state
);)
585 * qla4xxx_get_firmware_status - retrieves firmware status
586 * @ha: Pointer to host adapter structure.
588 int qla4xxx_get_firmware_status(struct scsi_qla_host
* ha
)
590 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
591 uint32_t mbox_sts
[MBOX_REG_COUNT
];
593 /* Get firmware version */
594 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
595 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
597 mbox_cmd
[0] = MBOX_CMD_GET_FW_STATUS
;
599 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 3, &mbox_cmd
[0], &mbox_sts
[0]) !=
601 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
602 "status %04X\n", ha
->host_no
, __func__
,
607 ql4_printk(KERN_INFO
, ha
, "%ld firmare IOCBs available (%d).\n",
608 ha
->host_no
, mbox_sts
[2]);
614 * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
615 * @ha: Pointer to host adapter structure.
616 * @fw_ddb_index: Firmware's device database index
617 * @fw_ddb_entry: Pointer to firmware's device database entry structure
618 * @num_valid_ddb_entries: Pointer to number of valid ddb entries
619 * @next_ddb_index: Pointer to next valid device database index
620 * @fw_ddb_device_state: Pointer to device state
622 int qla4xxx_get_fwddb_entry(struct scsi_qla_host
*ha
,
623 uint16_t fw_ddb_index
,
624 struct dev_db_entry
*fw_ddb_entry
,
625 dma_addr_t fw_ddb_entry_dma
,
626 uint32_t *num_valid_ddb_entries
,
627 uint32_t *next_ddb_index
,
628 uint32_t *fw_ddb_device_state
,
629 uint32_t *conn_err_detail
,
630 uint16_t *tcp_source_port_num
,
631 uint16_t *connection_id
)
633 int status
= QLA_ERROR
;
635 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
636 uint32_t mbox_sts
[MBOX_REG_COUNT
];
638 /* Make sure the device index is valid */
639 if (fw_ddb_index
>= MAX_DDB_ENTRIES
) {
640 DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
641 ha
->host_no
, __func__
, fw_ddb_index
));
644 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
645 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
647 mbox_cmd
[0] = MBOX_CMD_GET_DATABASE_ENTRY
;
648 mbox_cmd
[1] = (uint32_t) fw_ddb_index
;
649 mbox_cmd
[2] = LSDW(fw_ddb_entry_dma
);
650 mbox_cmd
[3] = MSDW(fw_ddb_entry_dma
);
651 mbox_cmd
[4] = sizeof(struct dev_db_entry
);
653 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 7, &mbox_cmd
[0], &mbox_sts
[0]) ==
655 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
656 " with status 0x%04X\n", ha
->host_no
, __func__
,
660 if (fw_ddb_index
!= mbox_sts
[1]) {
661 DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
662 ha
->host_no
, __func__
, fw_ddb_index
,
667 options
= le16_to_cpu(fw_ddb_entry
->options
);
668 if (options
& DDB_OPT_IPV6_DEVICE
) {
669 ql4_printk(KERN_INFO
, ha
, "%s: DDB[%d] MB0 %04x Tot %d "
670 "Next %d State %04x ConnErr %08x %pI6 "
671 ":%04d \"%s\"\n", __func__
, fw_ddb_index
,
672 mbox_sts
[0], mbox_sts
[2], mbox_sts
[3],
673 mbox_sts
[4], mbox_sts
[5],
674 fw_ddb_entry
->ip_addr
,
675 le16_to_cpu(fw_ddb_entry
->port
),
676 fw_ddb_entry
->iscsi_name
);
678 ql4_printk(KERN_INFO
, ha
, "%s: DDB[%d] MB0 %04x Tot %d "
679 "Next %d State %04x ConnErr %08x %pI4 "
680 ":%04d \"%s\"\n", __func__
, fw_ddb_index
,
681 mbox_sts
[0], mbox_sts
[2], mbox_sts
[3],
682 mbox_sts
[4], mbox_sts
[5],
683 fw_ddb_entry
->ip_addr
,
684 le16_to_cpu(fw_ddb_entry
->port
),
685 fw_ddb_entry
->iscsi_name
);
688 if (num_valid_ddb_entries
)
689 *num_valid_ddb_entries
= mbox_sts
[2];
691 *next_ddb_index
= mbox_sts
[3];
692 if (fw_ddb_device_state
)
693 *fw_ddb_device_state
= mbox_sts
[4];
696 * RA: This mailbox has been changed to pass connection error and
697 * details. Its true for ISP4010 as per Version E - Not sure when it
698 * was changed. Get the time2wait from the fw_dd_entry field :
699 * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
703 *conn_err_detail
= mbox_sts
[5];
704 if (tcp_source_port_num
)
705 *tcp_source_port_num
= (uint16_t) (mbox_sts
[6] >> 16);
707 *connection_id
= (uint16_t) mbox_sts
[6] & 0x00FF;
708 status
= QLA_SUCCESS
;
714 int qla4xxx_conn_open(struct scsi_qla_host
*ha
, uint16_t fw_ddb_index
)
716 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
717 uint32_t mbox_sts
[MBOX_REG_COUNT
];
720 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
721 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
723 mbox_cmd
[0] = MBOX_CMD_CONN_OPEN
;
724 mbox_cmd
[1] = fw_ddb_index
;
726 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 2, &mbox_cmd
[0],
728 DEBUG2(ql4_printk(KERN_INFO
, ha
,
729 "%s: status = %d mbx0 = 0x%x mbx1 = 0x%x\n",
730 __func__
, status
, mbox_sts
[0], mbox_sts
[1]));
735 * qla4xxx_set_fwddb_entry - sets a ddb entry.
736 * @ha: Pointer to host adapter structure.
737 * @fw_ddb_index: Firmware's device database index
738 * @fw_ddb_entry_dma: dma address of ddb entry
739 * @mbx_sts: mailbox 0 to be returned or NULL
741 * This routine initializes or updates the adapter's device database
742 * entry for the specified device.
744 int qla4xxx_set_ddb_entry(struct scsi_qla_host
* ha
, uint16_t fw_ddb_index
,
745 dma_addr_t fw_ddb_entry_dma
, uint32_t *mbx_sts
)
747 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
748 uint32_t mbox_sts
[MBOX_REG_COUNT
];
751 /* Do not wait for completion. The firmware will send us an
752 * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
754 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
755 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
757 mbox_cmd
[0] = MBOX_CMD_SET_DATABASE_ENTRY
;
758 mbox_cmd
[1] = (uint32_t) fw_ddb_index
;
759 mbox_cmd
[2] = LSDW(fw_ddb_entry_dma
);
760 mbox_cmd
[3] = MSDW(fw_ddb_entry_dma
);
761 mbox_cmd
[4] = sizeof(struct dev_db_entry
);
763 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0],
766 *mbx_sts
= mbox_sts
[0];
767 DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
768 ha
->host_no
, __func__
, status
, mbox_sts
[0], mbox_sts
[4]);)
773 int qla4xxx_session_logout_ddb(struct scsi_qla_host
*ha
,
774 struct ddb_entry
*ddb_entry
, int options
)
777 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
778 uint32_t mbox_sts
[MBOX_REG_COUNT
];
780 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
781 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
783 mbox_cmd
[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT
;
784 mbox_cmd
[1] = ddb_entry
->fw_ddb_index
;
785 mbox_cmd
[3] = options
;
787 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 2, &mbox_cmd
[0],
789 if (status
!= QLA_SUCCESS
) {
790 DEBUG2(ql4_printk(KERN_INFO
, ha
,
791 "%s: MBOX_CMD_CONN_CLOSE_SESS_LOGOUT "
792 "failed sts %04X %04X", __func__
,
793 mbox_sts
[0], mbox_sts
[1]));
800 * qla4xxx_get_crash_record - retrieves crash record.
801 * @ha: Pointer to host adapter structure.
803 * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
805 void qla4xxx_get_crash_record(struct scsi_qla_host
* ha
)
807 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
808 uint32_t mbox_sts
[MBOX_REG_COUNT
];
809 struct crash_record
*crash_record
= NULL
;
810 dma_addr_t crash_record_dma
= 0;
811 uint32_t crash_record_size
= 0;
813 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
814 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
816 /* Get size of crash record. */
817 mbox_cmd
[0] = MBOX_CMD_GET_CRASH_RECORD
;
819 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
821 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
822 ha
->host_no
, __func__
));
823 goto exit_get_crash_record
;
825 crash_record_size
= mbox_sts
[4];
826 if (crash_record_size
== 0) {
827 DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
828 ha
->host_no
, __func__
));
829 goto exit_get_crash_record
;
832 /* Alloc Memory for Crash Record. */
833 crash_record
= dma_alloc_coherent(&ha
->pdev
->dev
, crash_record_size
,
834 &crash_record_dma
, GFP_KERNEL
);
835 if (crash_record
== NULL
)
836 goto exit_get_crash_record
;
838 /* Get Crash Record. */
839 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
840 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
842 mbox_cmd
[0] = MBOX_CMD_GET_CRASH_RECORD
;
843 mbox_cmd
[2] = LSDW(crash_record_dma
);
844 mbox_cmd
[3] = MSDW(crash_record_dma
);
845 mbox_cmd
[4] = crash_record_size
;
847 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
849 goto exit_get_crash_record
;
851 /* Dump Crash Record. */
853 exit_get_crash_record
:
855 dma_free_coherent(&ha
->pdev
->dev
, crash_record_size
,
856 crash_record
, crash_record_dma
);
860 * qla4xxx_get_conn_event_log - retrieves connection event log
861 * @ha: Pointer to host adapter structure.
863 void qla4xxx_get_conn_event_log(struct scsi_qla_host
* ha
)
865 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
866 uint32_t mbox_sts
[MBOX_REG_COUNT
];
867 struct conn_event_log_entry
*event_log
= NULL
;
868 dma_addr_t event_log_dma
= 0;
869 uint32_t event_log_size
= 0;
870 uint32_t num_valid_entries
;
871 uint32_t oldest_entry
= 0;
872 uint32_t max_event_log_entries
;
876 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
877 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
879 /* Get size of crash record. */
880 mbox_cmd
[0] = MBOX_CMD_GET_CONN_EVENT_LOG
;
882 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
884 goto exit_get_event_log
;
886 event_log_size
= mbox_sts
[4];
887 if (event_log_size
== 0)
888 goto exit_get_event_log
;
890 /* Alloc Memory for Crash Record. */
891 event_log
= dma_alloc_coherent(&ha
->pdev
->dev
, event_log_size
,
892 &event_log_dma
, GFP_KERNEL
);
893 if (event_log
== NULL
)
894 goto exit_get_event_log
;
896 /* Get Crash Record. */
897 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
898 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
900 mbox_cmd
[0] = MBOX_CMD_GET_CONN_EVENT_LOG
;
901 mbox_cmd
[2] = LSDW(event_log_dma
);
902 mbox_cmd
[3] = MSDW(event_log_dma
);
904 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
906 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
907 "log!\n", ha
->host_no
, __func__
));
908 goto exit_get_event_log
;
911 /* Dump Event Log. */
912 num_valid_entries
= mbox_sts
[1];
914 max_event_log_entries
= event_log_size
/
915 sizeof(struct conn_event_log_entry
);
917 if (num_valid_entries
> max_event_log_entries
)
918 oldest_entry
= num_valid_entries
% max_event_log_entries
;
920 DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
921 ha
->host_no
, num_valid_entries
));
923 if (ql4xextended_error_logging
== 3) {
924 if (oldest_entry
== 0) {
925 /* Circular Buffer has not wrapped around */
926 for (i
=0; i
< num_valid_entries
; i
++) {
927 qla4xxx_dump_buffer((uint8_t *)event_log
+
928 (i
*sizeof(*event_log
)),
933 /* Circular Buffer has wrapped around -
934 * display accordingly*/
935 for (i
=oldest_entry
; i
< max_event_log_entries
; i
++) {
936 qla4xxx_dump_buffer((uint8_t *)event_log
+
937 (i
*sizeof(*event_log
)),
940 for (i
=0; i
< oldest_entry
; i
++) {
941 qla4xxx_dump_buffer((uint8_t *)event_log
+
942 (i
*sizeof(*event_log
)),
950 dma_free_coherent(&ha
->pdev
->dev
, event_log_size
, event_log
,
955 * qla4xxx_abort_task - issues Abort Task
956 * @ha: Pointer to host adapter structure.
957 * @srb: Pointer to srb entry
959 * This routine performs a LUN RESET on the specified target/lun.
960 * The caller must ensure that the ddb_entry and lun_entry pointers
961 * are valid before calling this routine.
963 int qla4xxx_abort_task(struct scsi_qla_host
*ha
, struct srb
*srb
)
965 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
966 uint32_t mbox_sts
[MBOX_REG_COUNT
];
967 struct scsi_cmnd
*cmd
= srb
->cmd
;
968 int status
= QLA_SUCCESS
;
969 unsigned long flags
= 0;
973 * Send abort task command to ISP, so that the ISP will return
974 * request with ABORT status
976 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
977 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
979 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
980 index
= (unsigned long)(unsigned char *)cmd
->host_scribble
;
981 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
983 /* Firmware already posted completion on response queue */
984 if (index
== MAX_SRBS
)
987 mbox_cmd
[0] = MBOX_CMD_ABORT_TASK
;
988 mbox_cmd
[1] = srb
->ddb
->fw_ddb_index
;
990 /* Immediate Command Enable */
993 qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0],
995 if (mbox_sts
[0] != MBOX_STS_COMMAND_COMPLETE
) {
998 DEBUG2(printk(KERN_WARNING
"scsi%ld:%d:%d: abort task FAILED: "
999 "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
1000 ha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, mbox_sts
[0],
1001 mbox_sts
[1], mbox_sts
[2], mbox_sts
[3], mbox_sts
[4]));
1008 * qla4xxx_reset_lun - issues LUN Reset
1009 * @ha: Pointer to host adapter structure.
1010 * @ddb_entry: Pointer to device database entry
1013 * This routine performs a LUN RESET on the specified target/lun.
1014 * The caller must ensure that the ddb_entry and lun_entry pointers
1015 * are valid before calling this routine.
1017 int qla4xxx_reset_lun(struct scsi_qla_host
* ha
, struct ddb_entry
* ddb_entry
,
1020 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1021 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1022 int status
= QLA_SUCCESS
;
1024 DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha
->host_no
,
1025 ddb_entry
->fw_ddb_index
, lun
));
1028 * Send lun reset command to ISP, so that the ISP will return all
1029 * outstanding requests with RESET status
1031 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1032 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1034 mbox_cmd
[0] = MBOX_CMD_LUN_RESET
;
1035 mbox_cmd
[1] = ddb_entry
->fw_ddb_index
;
1036 mbox_cmd
[2] = lun
<< 8;
1037 mbox_cmd
[5] = 0x01; /* Immediate Command Enable */
1039 qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0], &mbox_sts
[0]);
1040 if (mbox_sts
[0] != MBOX_STS_COMMAND_COMPLETE
&&
1041 mbox_sts
[0] != MBOX_STS_COMMAND_ERROR
)
1048 * qla4xxx_reset_target - issues target Reset
1049 * @ha: Pointer to host adapter structure.
1050 * @db_entry: Pointer to device database entry
1051 * @un_entry: Pointer to lun entry structure
1053 * This routine performs a TARGET RESET on the specified target.
1054 * The caller must ensure that the ddb_entry pointers
1055 * are valid before calling this routine.
1057 int qla4xxx_reset_target(struct scsi_qla_host
*ha
,
1058 struct ddb_entry
*ddb_entry
)
1060 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1061 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1062 int status
= QLA_SUCCESS
;
1064 DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha
->host_no
,
1065 ddb_entry
->fw_ddb_index
));
1068 * Send target reset command to ISP, so that the ISP will return all
1069 * outstanding requests with RESET status
1071 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1072 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1074 mbox_cmd
[0] = MBOX_CMD_TARGET_WARM_RESET
;
1075 mbox_cmd
[1] = ddb_entry
->fw_ddb_index
;
1076 mbox_cmd
[5] = 0x01; /* Immediate Command Enable */
1078 qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0],
1080 if (mbox_sts
[0] != MBOX_STS_COMMAND_COMPLETE
&&
1081 mbox_sts
[0] != MBOX_STS_COMMAND_ERROR
)
1087 int qla4xxx_get_flash(struct scsi_qla_host
* ha
, dma_addr_t dma_addr
,
1088 uint32_t offset
, uint32_t len
)
1090 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1091 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1093 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1094 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1096 mbox_cmd
[0] = MBOX_CMD_READ_FLASH
;
1097 mbox_cmd
[1] = LSDW(dma_addr
);
1098 mbox_cmd
[2] = MSDW(dma_addr
);
1099 mbox_cmd
[3] = offset
;
1102 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 2, &mbox_cmd
[0], &mbox_sts
[0]) !=
1104 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
1105 "status %04X %04X, offset %08x, len %08x\n", ha
->host_no
,
1106 __func__
, mbox_sts
[0], mbox_sts
[1], offset
, len
));
1113 * qla4xxx_about_firmware - gets FW, iscsi draft and boot loader version
1114 * @ha: Pointer to host adapter structure.
1116 * Retrieves the FW version, iSCSI draft version & bootloader version of HBA.
1117 * Mailboxes 2 & 3 may hold an address for data. Make sure that we write 0 to
1118 * those mailboxes, if unused.
1120 int qla4xxx_about_firmware(struct scsi_qla_host
*ha
)
1122 struct about_fw_info
*about_fw
= NULL
;
1123 dma_addr_t about_fw_dma
;
1124 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1125 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1126 int status
= QLA_ERROR
;
1128 about_fw
= dma_alloc_coherent(&ha
->pdev
->dev
,
1129 sizeof(struct about_fw_info
),
1130 &about_fw_dma
, GFP_KERNEL
);
1132 DEBUG2(ql4_printk(KERN_ERR
, ha
, "%s: Unable to alloc memory "
1133 "for about_fw\n", __func__
));
1137 memset(about_fw
, 0, sizeof(struct about_fw_info
));
1138 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1139 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1141 mbox_cmd
[0] = MBOX_CMD_ABOUT_FW
;
1142 mbox_cmd
[2] = LSDW(about_fw_dma
);
1143 mbox_cmd
[3] = MSDW(about_fw_dma
);
1144 mbox_cmd
[4] = sizeof(struct about_fw_info
);
1146 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, MBOX_REG_COUNT
,
1147 &mbox_cmd
[0], &mbox_sts
[0]);
1148 if (status
!= QLA_SUCCESS
) {
1149 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_ABOUT_FW "
1150 "failed w/ status %04X\n", __func__
,
1155 /* Save version information. */
1156 ha
->firmware_version
[0] = le16_to_cpu(about_fw
->fw_major
);
1157 ha
->firmware_version
[1] = le16_to_cpu(about_fw
->fw_minor
);
1158 ha
->patch_number
= le16_to_cpu(about_fw
->fw_patch
);
1159 ha
->build_number
= le16_to_cpu(about_fw
->fw_build
);
1160 ha
->iscsi_major
= le16_to_cpu(about_fw
->iscsi_major
);
1161 ha
->iscsi_minor
= le16_to_cpu(about_fw
->iscsi_minor
);
1162 ha
->bootload_major
= le16_to_cpu(about_fw
->bootload_major
);
1163 ha
->bootload_minor
= le16_to_cpu(about_fw
->bootload_minor
);
1164 ha
->bootload_patch
= le16_to_cpu(about_fw
->bootload_patch
);
1165 ha
->bootload_build
= le16_to_cpu(about_fw
->bootload_build
);
1166 status
= QLA_SUCCESS
;
1169 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct about_fw_info
),
1170 about_fw
, about_fw_dma
);
1174 static int qla4xxx_get_default_ddb(struct scsi_qla_host
*ha
, uint32_t options
,
1175 dma_addr_t dma_addr
)
1177 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1178 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1180 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1181 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1183 mbox_cmd
[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS
;
1184 mbox_cmd
[1] = options
;
1185 mbox_cmd
[2] = LSDW(dma_addr
);
1186 mbox_cmd
[3] = MSDW(dma_addr
);
1188 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0], &mbox_sts
[0]) !=
1190 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1191 ha
->host_no
, __func__
, mbox_sts
[0]));
1197 int qla4xxx_req_ddb_entry(struct scsi_qla_host
*ha
, uint32_t ddb_index
,
1201 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1202 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1204 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1205 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1207 mbox_cmd
[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY
;
1208 mbox_cmd
[1] = ddb_index
;
1210 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0],
1212 if (status
!= QLA_SUCCESS
) {
1213 DEBUG2(ql4_printk(KERN_ERR
, ha
, "%s: failed status %04X\n",
1214 __func__
, mbox_sts
[0]));
1217 *mbx_sts
= mbox_sts
[0];
1221 int qla4xxx_clear_ddb_entry(struct scsi_qla_host
*ha
, uint32_t ddb_index
)
1224 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1225 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1227 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1228 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1230 mbox_cmd
[0] = MBOX_CMD_CLEAR_DATABASE_ENTRY
;
1231 mbox_cmd
[1] = ddb_index
;
1233 status
= qla4xxx_mailbox_command(ha
, 2, 1, &mbox_cmd
[0],
1235 if (status
!= QLA_SUCCESS
) {
1236 DEBUG2(ql4_printk(KERN_ERR
, ha
, "%s: failed status %04X\n",
1237 __func__
, mbox_sts
[0]));
1243 int qla4xxx_set_flash(struct scsi_qla_host
*ha
, dma_addr_t dma_addr
,
1244 uint32_t offset
, uint32_t length
, uint32_t options
)
1246 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1247 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1248 int status
= QLA_SUCCESS
;
1250 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1251 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1253 mbox_cmd
[0] = MBOX_CMD_WRITE_FLASH
;
1254 mbox_cmd
[1] = LSDW(dma_addr
);
1255 mbox_cmd
[2] = MSDW(dma_addr
);
1256 mbox_cmd
[3] = offset
;
1257 mbox_cmd
[4] = length
;
1258 mbox_cmd
[5] = options
;
1260 status
= qla4xxx_mailbox_command(ha
, 6, 2, &mbox_cmd
[0], &mbox_sts
[0]);
1261 if (status
!= QLA_SUCCESS
) {
1262 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_WRITE_FLASH "
1263 "failed w/ status %04X, mbx1 %04X\n",
1264 __func__
, mbox_sts
[0], mbox_sts
[1]));
1269 int qla4xxx_bootdb_by_index(struct scsi_qla_host
*ha
,
1270 struct dev_db_entry
*fw_ddb_entry
,
1271 dma_addr_t fw_ddb_entry_dma
, uint16_t ddb_index
)
1273 uint32_t dev_db_start_offset
= FLASH_OFFSET_DB_INFO
;
1274 uint32_t dev_db_end_offset
;
1275 int status
= QLA_ERROR
;
1277 memset(fw_ddb_entry
, 0, sizeof(*fw_ddb_entry
));
1279 dev_db_start_offset
+= (ddb_index
* sizeof(*fw_ddb_entry
));
1280 dev_db_end_offset
= FLASH_OFFSET_DB_END
;
1282 if (dev_db_start_offset
> dev_db_end_offset
) {
1283 DEBUG2(ql4_printk(KERN_ERR
, ha
,
1284 "%s:Invalid DDB index %d", __func__
,
1286 goto exit_bootdb_failed
;
1289 if (qla4xxx_get_flash(ha
, fw_ddb_entry_dma
, dev_db_start_offset
,
1290 sizeof(*fw_ddb_entry
)) != QLA_SUCCESS
) {
1291 ql4_printk(KERN_ERR
, ha
, "scsi%ld: %s: Get Flash"
1292 "failed\n", ha
->host_no
, __func__
);
1293 goto exit_bootdb_failed
;
1296 if (fw_ddb_entry
->cookie
== DDB_VALID_COOKIE
)
1297 status
= QLA_SUCCESS
;
1303 int qla4xxx_get_chap(struct scsi_qla_host
*ha
, char *username
, char *password
,
1307 int rval
= QLA_ERROR
;
1308 uint32_t offset
= 0;
1309 struct ql4_chap_table
*chap_table
;
1310 dma_addr_t chap_dma
;
1312 chap_table
= dma_pool_alloc(ha
->chap_dma_pool
, GFP_KERNEL
, &chap_dma
);
1313 if (chap_table
== NULL
) {
1318 memset(chap_table
, 0, sizeof(struct ql4_chap_table
));
1320 offset
= 0x06000000 | (idx
* sizeof(struct ql4_chap_table
));
1322 rval
= qla4xxx_get_flash(ha
, chap_dma
, offset
,
1323 sizeof(struct ql4_chap_table
));
1324 if (rval
!= QLA_SUCCESS
) {
1329 DEBUG2(ql4_printk(KERN_INFO
, ha
, "Chap Cookie: x%x\n",
1330 __le16_to_cpu(chap_table
->cookie
)));
1332 if (__le16_to_cpu(chap_table
->cookie
) != CHAP_VALID_COOKIE
) {
1333 ql4_printk(KERN_ERR
, ha
, "No valid chap entry found\n");
1337 strncpy(password
, chap_table
->secret
, QL4_CHAP_MAX_SECRET_LEN
);
1338 strncpy(username
, chap_table
->name
, QL4_CHAP_MAX_NAME_LEN
);
1339 chap_table
->cookie
= __constant_cpu_to_le16(CHAP_VALID_COOKIE
);
1342 dma_pool_free(ha
->chap_dma_pool
, chap_table
, chap_dma
);
1346 static int qla4xxx_set_chap(struct scsi_qla_host
*ha
, char *username
,
1347 char *password
, uint16_t idx
, int bidi
)
1350 int rval
= QLA_ERROR
;
1351 uint32_t offset
= 0;
1352 struct ql4_chap_table
*chap_table
;
1353 dma_addr_t chap_dma
;
1355 chap_table
= dma_pool_alloc(ha
->chap_dma_pool
, GFP_KERNEL
, &chap_dma
);
1356 if (chap_table
== NULL
) {
1361 memset(chap_table
, 0, sizeof(struct ql4_chap_table
));
1363 chap_table
->flags
|= BIT_6
; /* peer */
1365 chap_table
->flags
|= BIT_7
; /* local */
1366 chap_table
->secret_len
= strlen(password
);
1367 strncpy(chap_table
->secret
, password
, MAX_CHAP_SECRET_LEN
);
1368 strncpy(chap_table
->name
, username
, MAX_CHAP_NAME_LEN
);
1369 chap_table
->cookie
= __constant_cpu_to_le16(CHAP_VALID_COOKIE
);
1370 offset
= 0x06000000 | (idx
* sizeof(struct ql4_chap_table
));
1371 rval
= qla4xxx_set_flash(ha
, chap_dma
, offset
,
1372 sizeof(struct ql4_chap_table
),
1373 FLASH_OPT_RMW_COMMIT
);
1374 dma_pool_free(ha
->chap_dma_pool
, chap_table
, chap_dma
);
1375 if (rval
!= QLA_SUCCESS
)
1382 int qla4xxx_conn_close_sess_logout(struct scsi_qla_host
*ha
,
1383 uint16_t fw_ddb_index
,
1384 uint16_t connection_id
,
1387 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1388 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1389 int status
= QLA_SUCCESS
;
1391 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1392 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1394 mbox_cmd
[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT
;
1395 mbox_cmd
[1] = fw_ddb_index
;
1396 mbox_cmd
[2] = connection_id
;
1397 mbox_cmd
[3] = option
;
1399 status
= qla4xxx_mailbox_command(ha
, 4, 2, &mbox_cmd
[0], &mbox_sts
[0]);
1400 if (status
!= QLA_SUCCESS
) {
1401 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_CONN_CLOSE "
1402 "option %04x failed w/ status %04X %04X\n",
1403 __func__
, option
, mbox_sts
[0], mbox_sts
[1]));
1408 int qla4xxx_disable_acb(struct scsi_qla_host
*ha
)
1410 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1411 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1412 int status
= QLA_SUCCESS
;
1414 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1415 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1417 mbox_cmd
[0] = MBOX_CMD_DISABLE_ACB
;
1419 status
= qla4xxx_mailbox_command(ha
, 8, 5, &mbox_cmd
[0], &mbox_sts
[0]);
1420 if (status
!= QLA_SUCCESS
) {
1421 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_DISABLE_ACB "
1422 "failed w/ status %04X %04X %04X", __func__
,
1423 mbox_sts
[0], mbox_sts
[1], mbox_sts
[2]));
1428 int qla4xxx_get_acb(struct scsi_qla_host
*ha
, dma_addr_t acb_dma
,
1429 uint32_t acb_type
, uint32_t len
)
1431 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1432 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1433 int status
= QLA_SUCCESS
;
1435 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1436 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1438 mbox_cmd
[0] = MBOX_CMD_GET_ACB
;
1439 mbox_cmd
[1] = acb_type
;
1440 mbox_cmd
[2] = LSDW(acb_dma
);
1441 mbox_cmd
[3] = MSDW(acb_dma
);
1444 status
= qla4xxx_mailbox_command(ha
, 5, 5, &mbox_cmd
[0], &mbox_sts
[0]);
1445 if (status
!= QLA_SUCCESS
) {
1446 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_GET_ACB "
1447 "failed w/ status %04X\n", __func__
,
1453 int qla4xxx_set_acb(struct scsi_qla_host
*ha
, uint32_t *mbox_cmd
,
1454 uint32_t *mbox_sts
, dma_addr_t acb_dma
)
1456 int status
= QLA_SUCCESS
;
1458 memset(mbox_cmd
, 0, sizeof(mbox_cmd
[0]) * MBOX_REG_COUNT
);
1459 memset(mbox_sts
, 0, sizeof(mbox_sts
[0]) * MBOX_REG_COUNT
);
1460 mbox_cmd
[0] = MBOX_CMD_SET_ACB
;
1461 mbox_cmd
[1] = 0; /* Primary ACB */
1462 mbox_cmd
[2] = LSDW(acb_dma
);
1463 mbox_cmd
[3] = MSDW(acb_dma
);
1464 mbox_cmd
[4] = sizeof(struct addr_ctrl_blk
);
1466 status
= qla4xxx_mailbox_command(ha
, 5, 5, &mbox_cmd
[0], &mbox_sts
[0]);
1467 if (status
!= QLA_SUCCESS
) {
1468 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_SET_ACB "
1469 "failed w/ status %04X\n", __func__
,
1475 int qla4xxx_set_param_ddbentry(struct scsi_qla_host
*ha
,
1476 struct ddb_entry
*ddb_entry
,
1477 struct iscsi_cls_conn
*cls_conn
,
1480 struct dev_db_entry
*fw_ddb_entry
;
1481 struct iscsi_conn
*conn
;
1482 struct iscsi_session
*sess
;
1483 struct qla_conn
*qla_conn
;
1484 struct sockaddr
*dst_addr
;
1485 dma_addr_t fw_ddb_entry_dma
;
1486 int status
= QLA_SUCCESS
;
1488 struct sockaddr_in
*addr
;
1489 struct sockaddr_in6
*addr6
;
1491 uint16_t iscsi_opts
= 0;
1492 uint32_t options
= 0;
1494 int max_chap_entries
= 0;
1496 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
1497 &fw_ddb_entry_dma
, GFP_KERNEL
);
1498 if (!fw_ddb_entry
) {
1499 DEBUG2(ql4_printk(KERN_ERR
, ha
,
1500 "%s: Unable to allocate dma buffer.\n",
1503 goto exit_set_param_no_free
;
1506 conn
= cls_conn
->dd_data
;
1507 qla_conn
= conn
->dd_data
;
1508 sess
= conn
->session
;
1509 dst_addr
= &qla_conn
->qla_ep
->dst_addr
;
1511 if (dst_addr
->sa_family
== AF_INET6
)
1512 options
|= IPV6_DEFAULT_DDB_ENTRY
;
1514 status
= qla4xxx_get_default_ddb(ha
, options
, fw_ddb_entry_dma
);
1515 if (status
== QLA_ERROR
) {
1517 goto exit_set_param
;
1520 iscsi_opts
= le16_to_cpu(fw_ddb_entry
->iscsi_options
);
1521 memset(fw_ddb_entry
->iscsi_alias
, 0, sizeof(fw_ddb_entry
->iscsi_alias
));
1523 memset(fw_ddb_entry
->iscsi_name
, 0, sizeof(fw_ddb_entry
->iscsi_name
));
1525 if (sess
->targetname
!= NULL
) {
1526 memcpy(fw_ddb_entry
->iscsi_name
, sess
->targetname
,
1527 min(strlen(sess
->targetname
),
1528 sizeof(fw_ddb_entry
->iscsi_name
)));
1531 memset(fw_ddb_entry
->ip_addr
, 0, sizeof(fw_ddb_entry
->ip_addr
));
1532 memset(fw_ddb_entry
->tgt_addr
, 0, sizeof(fw_ddb_entry
->tgt_addr
));
1534 fw_ddb_entry
->options
= DDB_OPT_TARGET
| DDB_OPT_AUTO_SENDTGTS_DISABLE
;
1536 if (dst_addr
->sa_family
== AF_INET
) {
1537 addr
= (struct sockaddr_in
*)dst_addr
;
1538 ip
= (char *)&addr
->sin_addr
;
1539 memcpy(fw_ddb_entry
->ip_addr
, ip
, IP_ADDR_LEN
);
1540 fw_ddb_entry
->port
= cpu_to_le16(ntohs(addr
->sin_port
));
1541 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1542 "%s: Destination Address [%pI4]: index [%d]\n",
1543 __func__
, fw_ddb_entry
->ip_addr
,
1544 ddb_entry
->fw_ddb_index
));
1545 } else if (dst_addr
->sa_family
== AF_INET6
) {
1546 addr6
= (struct sockaddr_in6
*)dst_addr
;
1547 ip
= (char *)&addr6
->sin6_addr
;
1548 memcpy(fw_ddb_entry
->ip_addr
, ip
, IPv6_ADDR_LEN
);
1549 fw_ddb_entry
->port
= cpu_to_le16(ntohs(addr6
->sin6_port
));
1550 fw_ddb_entry
->options
|= DDB_OPT_IPV6_DEVICE
;
1551 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1552 "%s: Destination Address [%pI6]: index [%d]\n",
1553 __func__
, fw_ddb_entry
->ip_addr
,
1554 ddb_entry
->fw_ddb_index
));
1556 ql4_printk(KERN_ERR
, ha
,
1557 "%s: Failed to get IP Address\n",
1560 goto exit_set_param
;
1564 max_chap_entries
= MAX_CHAP_ENTRIES_82XX
;
1566 max_chap_entries
= MAX_CHAP_ENTRIES_40XX
;
1568 if (sess
->username
!= NULL
&& sess
->password
!= NULL
) {
1569 if (strlen(sess
->username
) && strlen(sess
->password
)) {
1570 iscsi_opts
|= BIT_7
;
1571 idx
= ddb_entry
->fw_ddb_index
* 2;
1572 if (idx
> max_chap_entries
) {
1573 ql4_printk(KERN_ERR
, ha
,
1574 "%s: Invalid ddb or chap index\n",
1577 goto exit_set_param
;
1580 rval
= qla4xxx_set_chap(ha
, sess
->username
,
1581 sess
->password
, idx
, 0);
1583 goto exit_set_param
;
1585 fw_ddb_entry
->chap_tbl_idx
= cpu_to_le16(idx
);
1589 if (sess
->username_in
!= NULL
&& sess
->password_in
!= NULL
) {
1590 /* Check if BIDI CHAP */
1591 if (strlen(sess
->username_in
) && strlen(sess
->password_in
)) {
1592 iscsi_opts
|= BIT_4
;
1593 idx
= (ddb_entry
->fw_ddb_index
* 2) + 1;
1594 if (idx
> max_chap_entries
) {
1595 ql4_printk(KERN_ERR
, ha
,
1596 "%s: Invalid ddb or bidi chap "
1597 "index\n", __func__
);
1599 goto exit_set_param
;
1601 rval
= qla4xxx_set_chap(ha
, sess
->username_in
,
1602 sess
->password_in
, idx
, 0);
1604 goto exit_set_param
;
1608 if (sess
->initial_r2t_en
)
1609 iscsi_opts
|= BIT_10
;
1611 if (sess
->imm_data_en
)
1612 iscsi_opts
|= BIT_11
;
1614 fw_ddb_entry
->iscsi_options
= cpu_to_le16(iscsi_opts
);
1616 if (conn
->max_recv_dlength
)
1617 fw_ddb_entry
->iscsi_max_rcv_data_seg_len
=
1618 __constant_cpu_to_le16((conn
->max_recv_dlength
/ BYTE_UNITS
));
1621 fw_ddb_entry
->iscsi_max_outsnd_r2t
= cpu_to_le16(sess
->max_r2t
);
1623 if (sess
->first_burst
)
1624 fw_ddb_entry
->iscsi_first_burst_len
=
1625 __constant_cpu_to_le16((sess
->first_burst
/ BYTE_UNITS
));
1627 if (sess
->max_burst
)
1628 fw_ddb_entry
->iscsi_max_burst_len
=
1629 __constant_cpu_to_le16((sess
->max_burst
/ BYTE_UNITS
));
1631 if (sess
->time2wait
)
1632 fw_ddb_entry
->iscsi_def_time2wait
=
1633 cpu_to_le16(sess
->time2wait
);
1635 if (sess
->time2retain
)
1636 fw_ddb_entry
->iscsi_def_time2retain
=
1637 cpu_to_le16(sess
->time2retain
);
1639 status
= qla4xxx_set_ddb_entry(ha
, ddb_entry
->fw_ddb_index
,
1640 fw_ddb_entry_dma
, mbx_sts
);
1642 if (status
!= QLA_SUCCESS
)
1645 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
1646 fw_ddb_entry
, fw_ddb_entry_dma
);
1647 exit_set_param_no_free
:
1651 int qla4xxx_get_mgmt_data(struct scsi_qla_host
*ha
, uint16_t fw_ddb_index
,
1652 uint16_t stats_size
, dma_addr_t stats_dma
)
1654 int status
= QLA_SUCCESS
;
1655 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1656 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1658 memset(mbox_cmd
, 0, sizeof(mbox_cmd
[0]) * MBOX_REG_COUNT
);
1659 memset(mbox_sts
, 0, sizeof(mbox_sts
[0]) * MBOX_REG_COUNT
);
1660 mbox_cmd
[0] = MBOX_CMD_GET_MANAGEMENT_DATA
;
1661 mbox_cmd
[1] = fw_ddb_index
;
1662 mbox_cmd
[2] = LSDW(stats_dma
);
1663 mbox_cmd
[3] = MSDW(stats_dma
);
1664 mbox_cmd
[4] = stats_size
;
1666 status
= qla4xxx_mailbox_command(ha
, 5, 1, &mbox_cmd
[0], &mbox_sts
[0]);
1667 if (status
!= QLA_SUCCESS
) {
1668 DEBUG2(ql4_printk(KERN_WARNING
, ha
,
1669 "%s: MBOX_CMD_GET_MANAGEMENT_DATA "
1670 "failed w/ status %04X\n", __func__
,
1676 int qla4xxx_get_ip_state(struct scsi_qla_host
*ha
, uint32_t acb_idx
,
1677 uint32_t ip_idx
, uint32_t *sts
)
1679 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1680 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1681 int status
= QLA_SUCCESS
;
1683 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1684 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1685 mbox_cmd
[0] = MBOX_CMD_GET_IP_ADDR_STATE
;
1686 mbox_cmd
[1] = acb_idx
;
1687 mbox_cmd
[2] = ip_idx
;
1689 status
= qla4xxx_mailbox_command(ha
, 3, 8, &mbox_cmd
[0], &mbox_sts
[0]);
1690 if (status
!= QLA_SUCCESS
) {
1691 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: "
1692 "MBOX_CMD_GET_IP_ADDR_STATE failed w/ "
1693 "status %04X\n", __func__
, mbox_sts
[0]));
1695 memcpy(sts
, mbox_sts
, sizeof(mbox_sts
));
1699 int qla4xxx_get_nvram(struct scsi_qla_host
*ha
, dma_addr_t nvram_dma
,
1700 uint32_t offset
, uint32_t size
)
1702 int status
= QLA_SUCCESS
;
1703 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1704 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1706 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1707 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1709 mbox_cmd
[0] = MBOX_CMD_GET_NVRAM
;
1710 mbox_cmd
[1] = LSDW(nvram_dma
);
1711 mbox_cmd
[2] = MSDW(nvram_dma
);
1712 mbox_cmd
[3] = offset
;
1715 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0],
1717 if (status
!= QLA_SUCCESS
) {
1718 DEBUG2(ql4_printk(KERN_ERR
, ha
, "scsi%ld: %s: failed "
1719 "status %04X\n", ha
->host_no
, __func__
,
1725 int qla4xxx_set_nvram(struct scsi_qla_host
*ha
, dma_addr_t nvram_dma
,
1726 uint32_t offset
, uint32_t size
)
1728 int status
= QLA_SUCCESS
;
1729 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1730 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1732 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1733 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1735 mbox_cmd
[0] = MBOX_CMD_SET_NVRAM
;
1736 mbox_cmd
[1] = LSDW(nvram_dma
);
1737 mbox_cmd
[2] = MSDW(nvram_dma
);
1738 mbox_cmd
[3] = offset
;
1741 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0],
1743 if (status
!= QLA_SUCCESS
) {
1744 DEBUG2(ql4_printk(KERN_ERR
, ha
, "scsi%ld: %s: failed "
1745 "status %04X\n", ha
->host_no
, __func__
,
1751 int qla4xxx_restore_factory_defaults(struct scsi_qla_host
*ha
,
1752 uint32_t region
, uint32_t field0
,
1755 int status
= QLA_SUCCESS
;
1756 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1757 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1759 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1760 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1762 mbox_cmd
[0] = MBOX_CMD_RESTORE_FACTORY_DEFAULTS
;
1763 mbox_cmd
[3] = region
;
1764 mbox_cmd
[4] = field0
;
1765 mbox_cmd
[5] = field1
;
1767 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 3, &mbox_cmd
[0],
1769 if (status
!= QLA_SUCCESS
) {
1770 DEBUG2(ql4_printk(KERN_ERR
, ha
, "scsi%ld: %s: failed "
1771 "status %04X\n", ha
->host_no
, __func__
,