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 mbox_cmd
[0] = MBOX_CMD_GET_DATABASE_ENTRY
;
666 mbox_cmd
[1] = (uint32_t) fw_ddb_index
;
667 mbox_cmd
[2] = LSDW(fw_ddb_entry_dma
);
668 mbox_cmd
[3] = MSDW(fw_ddb_entry_dma
);
669 mbox_cmd
[4] = sizeof(struct dev_db_entry
);
671 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 7, &mbox_cmd
[0], &mbox_sts
[0]) ==
673 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
674 " with status 0x%04X\n", ha
->host_no
, __func__
,
678 if (fw_ddb_index
!= mbox_sts
[1]) {
679 DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
680 ha
->host_no
, __func__
, fw_ddb_index
,
685 options
= le16_to_cpu(fw_ddb_entry
->options
);
686 if (options
& DDB_OPT_IPV6_DEVICE
) {
687 ql4_printk(KERN_INFO
, ha
, "%s: DDB[%d] MB0 %04x Tot %d "
688 "Next %d State %04x ConnErr %08x %pI6 "
689 ":%04d \"%s\"\n", __func__
, fw_ddb_index
,
690 mbox_sts
[0], mbox_sts
[2], mbox_sts
[3],
691 mbox_sts
[4], mbox_sts
[5],
692 fw_ddb_entry
->ip_addr
,
693 le16_to_cpu(fw_ddb_entry
->port
),
694 fw_ddb_entry
->iscsi_name
);
696 ql4_printk(KERN_INFO
, ha
, "%s: DDB[%d] MB0 %04x Tot %d "
697 "Next %d State %04x ConnErr %08x %pI4 "
698 ":%04d \"%s\"\n", __func__
, fw_ddb_index
,
699 mbox_sts
[0], mbox_sts
[2], mbox_sts
[3],
700 mbox_sts
[4], mbox_sts
[5],
701 fw_ddb_entry
->ip_addr
,
702 le16_to_cpu(fw_ddb_entry
->port
),
703 fw_ddb_entry
->iscsi_name
);
706 if (num_valid_ddb_entries
)
707 *num_valid_ddb_entries
= mbox_sts
[2];
709 *next_ddb_index
= mbox_sts
[3];
710 if (fw_ddb_device_state
)
711 *fw_ddb_device_state
= mbox_sts
[4];
714 * RA: This mailbox has been changed to pass connection error and
715 * details. Its true for ISP4010 as per Version E - Not sure when it
716 * was changed. Get the time2wait from the fw_dd_entry field :
717 * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
721 *conn_err_detail
= mbox_sts
[5];
722 if (tcp_source_port_num
)
723 *tcp_source_port_num
= (uint16_t) (mbox_sts
[6] >> 16);
725 *connection_id
= (uint16_t) mbox_sts
[6] & 0x00FF;
726 status
= QLA_SUCCESS
;
732 int qla4xxx_conn_open(struct scsi_qla_host
*ha
, uint16_t fw_ddb_index
)
734 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
735 uint32_t mbox_sts
[MBOX_REG_COUNT
];
738 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
739 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
741 mbox_cmd
[0] = MBOX_CMD_CONN_OPEN
;
742 mbox_cmd
[1] = fw_ddb_index
;
744 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 2, &mbox_cmd
[0],
746 DEBUG2(ql4_printk(KERN_INFO
, ha
,
747 "%s: status = %d mbx0 = 0x%x mbx1 = 0x%x\n",
748 __func__
, status
, mbox_sts
[0], mbox_sts
[1]));
753 * qla4xxx_set_fwddb_entry - sets a ddb entry.
754 * @ha: Pointer to host adapter structure.
755 * @fw_ddb_index: Firmware's device database index
756 * @fw_ddb_entry_dma: dma address of ddb entry
757 * @mbx_sts: mailbox 0 to be returned or NULL
759 * This routine initializes or updates the adapter's device database
760 * entry for the specified device.
762 int qla4xxx_set_ddb_entry(struct scsi_qla_host
* ha
, uint16_t fw_ddb_index
,
763 dma_addr_t fw_ddb_entry_dma
, uint32_t *mbx_sts
)
765 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
766 uint32_t mbox_sts
[MBOX_REG_COUNT
];
769 /* Do not wait for completion. The firmware will send us an
770 * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
772 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
773 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
775 mbox_cmd
[0] = MBOX_CMD_SET_DATABASE_ENTRY
;
776 mbox_cmd
[1] = (uint32_t) fw_ddb_index
;
777 mbox_cmd
[2] = LSDW(fw_ddb_entry_dma
);
778 mbox_cmd
[3] = MSDW(fw_ddb_entry_dma
);
779 mbox_cmd
[4] = sizeof(struct dev_db_entry
);
781 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0],
784 *mbx_sts
= mbox_sts
[0];
785 DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
786 ha
->host_no
, __func__
, status
, mbox_sts
[0], mbox_sts
[4]);)
791 int qla4xxx_session_logout_ddb(struct scsi_qla_host
*ha
,
792 struct ddb_entry
*ddb_entry
, int options
)
795 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
796 uint32_t mbox_sts
[MBOX_REG_COUNT
];
798 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
799 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
801 mbox_cmd
[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT
;
802 mbox_cmd
[1] = ddb_entry
->fw_ddb_index
;
803 mbox_cmd
[3] = options
;
805 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 2, &mbox_cmd
[0],
807 if (status
!= QLA_SUCCESS
) {
808 DEBUG2(ql4_printk(KERN_INFO
, ha
,
809 "%s: MBOX_CMD_CONN_CLOSE_SESS_LOGOUT "
810 "failed sts %04X %04X", __func__
,
811 mbox_sts
[0], mbox_sts
[1]));
818 * qla4xxx_get_crash_record - retrieves crash record.
819 * @ha: Pointer to host adapter structure.
821 * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
823 void qla4xxx_get_crash_record(struct scsi_qla_host
* ha
)
825 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
826 uint32_t mbox_sts
[MBOX_REG_COUNT
];
827 struct crash_record
*crash_record
= NULL
;
828 dma_addr_t crash_record_dma
= 0;
829 uint32_t crash_record_size
= 0;
831 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
832 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
834 /* Get size of crash record. */
835 mbox_cmd
[0] = MBOX_CMD_GET_CRASH_RECORD
;
837 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
839 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
840 ha
->host_no
, __func__
));
841 goto exit_get_crash_record
;
843 crash_record_size
= mbox_sts
[4];
844 if (crash_record_size
== 0) {
845 DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
846 ha
->host_no
, __func__
));
847 goto exit_get_crash_record
;
850 /* Alloc Memory for Crash Record. */
851 crash_record
= dma_alloc_coherent(&ha
->pdev
->dev
, crash_record_size
,
852 &crash_record_dma
, GFP_KERNEL
);
853 if (crash_record
== NULL
)
854 goto exit_get_crash_record
;
856 /* Get Crash Record. */
857 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
858 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
860 mbox_cmd
[0] = MBOX_CMD_GET_CRASH_RECORD
;
861 mbox_cmd
[2] = LSDW(crash_record_dma
);
862 mbox_cmd
[3] = MSDW(crash_record_dma
);
863 mbox_cmd
[4] = crash_record_size
;
865 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
867 goto exit_get_crash_record
;
869 /* Dump Crash Record. */
871 exit_get_crash_record
:
873 dma_free_coherent(&ha
->pdev
->dev
, crash_record_size
,
874 crash_record
, crash_record_dma
);
878 * qla4xxx_get_conn_event_log - retrieves connection event log
879 * @ha: Pointer to host adapter structure.
881 void qla4xxx_get_conn_event_log(struct scsi_qla_host
* ha
)
883 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
884 uint32_t mbox_sts
[MBOX_REG_COUNT
];
885 struct conn_event_log_entry
*event_log
= NULL
;
886 dma_addr_t event_log_dma
= 0;
887 uint32_t event_log_size
= 0;
888 uint32_t num_valid_entries
;
889 uint32_t oldest_entry
= 0;
890 uint32_t max_event_log_entries
;
893 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
894 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
896 /* Get size of crash record. */
897 mbox_cmd
[0] = MBOX_CMD_GET_CONN_EVENT_LOG
;
899 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
901 goto exit_get_event_log
;
903 event_log_size
= mbox_sts
[4];
904 if (event_log_size
== 0)
905 goto exit_get_event_log
;
907 /* Alloc Memory for Crash Record. */
908 event_log
= dma_alloc_coherent(&ha
->pdev
->dev
, event_log_size
,
909 &event_log_dma
, GFP_KERNEL
);
910 if (event_log
== NULL
)
911 goto exit_get_event_log
;
913 /* Get Crash Record. */
914 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
915 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
917 mbox_cmd
[0] = MBOX_CMD_GET_CONN_EVENT_LOG
;
918 mbox_cmd
[2] = LSDW(event_log_dma
);
919 mbox_cmd
[3] = MSDW(event_log_dma
);
921 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
923 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
924 "log!\n", ha
->host_no
, __func__
));
925 goto exit_get_event_log
;
928 /* Dump Event Log. */
929 num_valid_entries
= mbox_sts
[1];
931 max_event_log_entries
= event_log_size
/
932 sizeof(struct conn_event_log_entry
);
934 if (num_valid_entries
> max_event_log_entries
)
935 oldest_entry
= num_valid_entries
% max_event_log_entries
;
937 DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
938 ha
->host_no
, num_valid_entries
));
940 if (ql4xextended_error_logging
== 3) {
941 if (oldest_entry
== 0) {
942 /* Circular Buffer has not wrapped around */
943 for (i
=0; i
< num_valid_entries
; i
++) {
944 qla4xxx_dump_buffer((uint8_t *)event_log
+
945 (i
*sizeof(*event_log
)),
950 /* Circular Buffer has wrapped around -
951 * display accordingly*/
952 for (i
=oldest_entry
; i
< max_event_log_entries
; i
++) {
953 qla4xxx_dump_buffer((uint8_t *)event_log
+
954 (i
*sizeof(*event_log
)),
957 for (i
=0; i
< oldest_entry
; i
++) {
958 qla4xxx_dump_buffer((uint8_t *)event_log
+
959 (i
*sizeof(*event_log
)),
967 dma_free_coherent(&ha
->pdev
->dev
, event_log_size
, event_log
,
972 * qla4xxx_abort_task - issues Abort Task
973 * @ha: Pointer to host adapter structure.
974 * @srb: Pointer to srb entry
976 * This routine performs a LUN RESET on the specified target/lun.
977 * The caller must ensure that the ddb_entry and lun_entry pointers
978 * are valid before calling this routine.
980 int qla4xxx_abort_task(struct scsi_qla_host
*ha
, struct srb
*srb
)
982 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
983 uint32_t mbox_sts
[MBOX_REG_COUNT
];
984 struct scsi_cmnd
*cmd
= srb
->cmd
;
985 int status
= QLA_SUCCESS
;
986 unsigned long flags
= 0;
990 * Send abort task command to ISP, so that the ISP will return
991 * request with ABORT status
993 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
994 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
996 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
997 index
= (unsigned long)(unsigned char *)cmd
->host_scribble
;
998 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1000 /* Firmware already posted completion on response queue */
1001 if (index
== MAX_SRBS
)
1004 mbox_cmd
[0] = MBOX_CMD_ABORT_TASK
;
1005 mbox_cmd
[1] = srb
->ddb
->fw_ddb_index
;
1006 mbox_cmd
[2] = index
;
1007 /* Immediate Command Enable */
1010 qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0],
1012 if (mbox_sts
[0] != MBOX_STS_COMMAND_COMPLETE
) {
1015 DEBUG2(printk(KERN_WARNING
"scsi%ld:%d:%d: abort task FAILED: "
1016 "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
1017 ha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, mbox_sts
[0],
1018 mbox_sts
[1], mbox_sts
[2], mbox_sts
[3], mbox_sts
[4]));
1025 * qla4xxx_reset_lun - issues LUN Reset
1026 * @ha: Pointer to host adapter structure.
1027 * @ddb_entry: Pointer to device database entry
1030 * This routine performs a LUN RESET on the specified target/lun.
1031 * The caller must ensure that the ddb_entry and lun_entry pointers
1032 * are valid before calling this routine.
1034 int qla4xxx_reset_lun(struct scsi_qla_host
* ha
, struct ddb_entry
* ddb_entry
,
1037 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1038 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1039 int status
= QLA_SUCCESS
;
1041 DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha
->host_no
,
1042 ddb_entry
->fw_ddb_index
, lun
));
1045 * Send lun reset command to ISP, so that the ISP will return all
1046 * outstanding requests with RESET status
1048 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1049 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1051 mbox_cmd
[0] = MBOX_CMD_LUN_RESET
;
1052 mbox_cmd
[1] = ddb_entry
->fw_ddb_index
;
1053 mbox_cmd
[2] = lun
<< 8;
1054 mbox_cmd
[5] = 0x01; /* Immediate Command Enable */
1056 qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0], &mbox_sts
[0]);
1057 if (mbox_sts
[0] != MBOX_STS_COMMAND_COMPLETE
&&
1058 mbox_sts
[0] != MBOX_STS_COMMAND_ERROR
)
1065 * qla4xxx_reset_target - issues target Reset
1066 * @ha: Pointer to host adapter structure.
1067 * @db_entry: Pointer to device database entry
1068 * @un_entry: Pointer to lun entry structure
1070 * This routine performs a TARGET RESET on the specified target.
1071 * The caller must ensure that the ddb_entry pointers
1072 * are valid before calling this routine.
1074 int qla4xxx_reset_target(struct scsi_qla_host
*ha
,
1075 struct ddb_entry
*ddb_entry
)
1077 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1078 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1079 int status
= QLA_SUCCESS
;
1081 DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha
->host_no
,
1082 ddb_entry
->fw_ddb_index
));
1085 * Send target reset command to ISP, so that the ISP will return all
1086 * outstanding requests with RESET status
1088 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1089 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1091 mbox_cmd
[0] = MBOX_CMD_TARGET_WARM_RESET
;
1092 mbox_cmd
[1] = ddb_entry
->fw_ddb_index
;
1093 mbox_cmd
[5] = 0x01; /* Immediate Command Enable */
1095 qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0],
1097 if (mbox_sts
[0] != MBOX_STS_COMMAND_COMPLETE
&&
1098 mbox_sts
[0] != MBOX_STS_COMMAND_ERROR
)
1104 int qla4xxx_get_flash(struct scsi_qla_host
* ha
, dma_addr_t dma_addr
,
1105 uint32_t offset
, uint32_t len
)
1107 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1108 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1110 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1111 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1113 mbox_cmd
[0] = MBOX_CMD_READ_FLASH
;
1114 mbox_cmd
[1] = LSDW(dma_addr
);
1115 mbox_cmd
[2] = MSDW(dma_addr
);
1116 mbox_cmd
[3] = offset
;
1119 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 2, &mbox_cmd
[0], &mbox_sts
[0]) !=
1121 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
1122 "status %04X %04X, offset %08x, len %08x\n", ha
->host_no
,
1123 __func__
, mbox_sts
[0], mbox_sts
[1], offset
, len
));
1130 * qla4xxx_about_firmware - gets FW, iscsi draft and boot loader version
1131 * @ha: Pointer to host adapter structure.
1133 * Retrieves the FW version, iSCSI draft version & bootloader version of HBA.
1134 * Mailboxes 2 & 3 may hold an address for data. Make sure that we write 0 to
1135 * those mailboxes, if unused.
1137 int qla4xxx_about_firmware(struct scsi_qla_host
*ha
)
1139 struct about_fw_info
*about_fw
= NULL
;
1140 dma_addr_t about_fw_dma
;
1141 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1142 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1143 int status
= QLA_ERROR
;
1145 about_fw
= dma_alloc_coherent(&ha
->pdev
->dev
,
1146 sizeof(struct about_fw_info
),
1147 &about_fw_dma
, GFP_KERNEL
);
1149 DEBUG2(ql4_printk(KERN_ERR
, ha
, "%s: Unable to alloc memory "
1150 "for about_fw\n", __func__
));
1154 memset(about_fw
, 0, sizeof(struct about_fw_info
));
1155 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1156 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1158 mbox_cmd
[0] = MBOX_CMD_ABOUT_FW
;
1159 mbox_cmd
[2] = LSDW(about_fw_dma
);
1160 mbox_cmd
[3] = MSDW(about_fw_dma
);
1161 mbox_cmd
[4] = sizeof(struct about_fw_info
);
1163 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, MBOX_REG_COUNT
,
1164 &mbox_cmd
[0], &mbox_sts
[0]);
1165 if (status
!= QLA_SUCCESS
) {
1166 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_ABOUT_FW "
1167 "failed w/ status %04X\n", __func__
,
1172 /* Save version information. */
1173 ha
->firmware_version
[0] = le16_to_cpu(about_fw
->fw_major
);
1174 ha
->firmware_version
[1] = le16_to_cpu(about_fw
->fw_minor
);
1175 ha
->patch_number
= le16_to_cpu(about_fw
->fw_patch
);
1176 ha
->build_number
= le16_to_cpu(about_fw
->fw_build
);
1177 ha
->iscsi_major
= le16_to_cpu(about_fw
->iscsi_major
);
1178 ha
->iscsi_minor
= le16_to_cpu(about_fw
->iscsi_minor
);
1179 ha
->bootload_major
= le16_to_cpu(about_fw
->bootload_major
);
1180 ha
->bootload_minor
= le16_to_cpu(about_fw
->bootload_minor
);
1181 ha
->bootload_patch
= le16_to_cpu(about_fw
->bootload_patch
);
1182 ha
->bootload_build
= le16_to_cpu(about_fw
->bootload_build
);
1183 status
= QLA_SUCCESS
;
1186 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct about_fw_info
),
1187 about_fw
, about_fw_dma
);
1191 static int qla4xxx_get_default_ddb(struct scsi_qla_host
*ha
, uint32_t options
,
1192 dma_addr_t dma_addr
)
1194 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1195 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1197 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1198 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1200 mbox_cmd
[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS
;
1201 mbox_cmd
[1] = options
;
1202 mbox_cmd
[2] = LSDW(dma_addr
);
1203 mbox_cmd
[3] = MSDW(dma_addr
);
1205 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0], &mbox_sts
[0]) !=
1207 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1208 ha
->host_no
, __func__
, mbox_sts
[0]));
1214 int qla4xxx_req_ddb_entry(struct scsi_qla_host
*ha
, uint32_t ddb_index
,
1218 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1219 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1221 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1222 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1224 mbox_cmd
[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY
;
1225 mbox_cmd
[1] = ddb_index
;
1227 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0],
1229 if (status
!= QLA_SUCCESS
) {
1230 DEBUG2(ql4_printk(KERN_ERR
, ha
, "%s: failed status %04X\n",
1231 __func__
, mbox_sts
[0]));
1234 *mbx_sts
= mbox_sts
[0];
1238 int qla4xxx_clear_ddb_entry(struct scsi_qla_host
*ha
, uint32_t ddb_index
)
1241 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1242 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1244 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1245 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1247 mbox_cmd
[0] = MBOX_CMD_CLEAR_DATABASE_ENTRY
;
1248 mbox_cmd
[1] = ddb_index
;
1250 status
= qla4xxx_mailbox_command(ha
, 2, 1, &mbox_cmd
[0],
1252 if (status
!= QLA_SUCCESS
) {
1253 DEBUG2(ql4_printk(KERN_ERR
, ha
, "%s: failed status %04X\n",
1254 __func__
, mbox_sts
[0]));
1260 int qla4xxx_set_flash(struct scsi_qla_host
*ha
, dma_addr_t dma_addr
,
1261 uint32_t offset
, uint32_t length
, uint32_t options
)
1263 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1264 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1265 int status
= QLA_SUCCESS
;
1267 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1268 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1270 mbox_cmd
[0] = MBOX_CMD_WRITE_FLASH
;
1271 mbox_cmd
[1] = LSDW(dma_addr
);
1272 mbox_cmd
[2] = MSDW(dma_addr
);
1273 mbox_cmd
[3] = offset
;
1274 mbox_cmd
[4] = length
;
1275 mbox_cmd
[5] = options
;
1277 status
= qla4xxx_mailbox_command(ha
, 6, 2, &mbox_cmd
[0], &mbox_sts
[0]);
1278 if (status
!= QLA_SUCCESS
) {
1279 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_WRITE_FLASH "
1280 "failed w/ status %04X, mbx1 %04X\n",
1281 __func__
, mbox_sts
[0], mbox_sts
[1]));
1286 int qla4xxx_bootdb_by_index(struct scsi_qla_host
*ha
,
1287 struct dev_db_entry
*fw_ddb_entry
,
1288 dma_addr_t fw_ddb_entry_dma
, uint16_t ddb_index
)
1290 uint32_t dev_db_start_offset
= FLASH_OFFSET_DB_INFO
;
1291 uint32_t dev_db_end_offset
;
1292 int status
= QLA_ERROR
;
1294 memset(fw_ddb_entry
, 0, sizeof(*fw_ddb_entry
));
1296 dev_db_start_offset
+= (ddb_index
* sizeof(*fw_ddb_entry
));
1297 dev_db_end_offset
= FLASH_OFFSET_DB_END
;
1299 if (dev_db_start_offset
> dev_db_end_offset
) {
1300 DEBUG2(ql4_printk(KERN_ERR
, ha
,
1301 "%s:Invalid DDB index %d", __func__
,
1303 goto exit_bootdb_failed
;
1306 if (qla4xxx_get_flash(ha
, fw_ddb_entry_dma
, dev_db_start_offset
,
1307 sizeof(*fw_ddb_entry
)) != QLA_SUCCESS
) {
1308 ql4_printk(KERN_ERR
, ha
, "scsi%ld: %s: Get Flash"
1309 "failed\n", ha
->host_no
, __func__
);
1310 goto exit_bootdb_failed
;
1313 if (fw_ddb_entry
->cookie
== DDB_VALID_COOKIE
)
1314 status
= QLA_SUCCESS
;
1320 int qla4xxx_get_chap(struct scsi_qla_host
*ha
, char *username
, char *password
,
1324 int rval
= QLA_ERROR
;
1325 uint32_t offset
= 0, chap_size
;
1326 struct ql4_chap_table
*chap_table
;
1327 dma_addr_t chap_dma
;
1329 chap_table
= dma_pool_alloc(ha
->chap_dma_pool
, GFP_KERNEL
, &chap_dma
);
1330 if (chap_table
== NULL
) {
1335 chap_size
= sizeof(struct ql4_chap_table
);
1336 memset(chap_table
, 0, chap_size
);
1339 offset
= FLASH_CHAP_OFFSET
| (idx
* chap_size
);
1341 offset
= FLASH_RAW_ACCESS_ADDR
+ (ha
->hw
.flt_region_chap
<< 2);
1342 /* flt_chap_size is CHAP table size for both ports
1343 * so divide it by 2 to calculate the offset for second port
1345 if (ha
->port_num
== 1)
1346 offset
+= (ha
->hw
.flt_chap_size
/ 2);
1347 offset
+= (idx
* chap_size
);
1350 rval
= qla4xxx_get_flash(ha
, chap_dma
, offset
, chap_size
);
1351 if (rval
!= QLA_SUCCESS
) {
1356 DEBUG2(ql4_printk(KERN_INFO
, ha
, "Chap Cookie: x%x\n",
1357 __le16_to_cpu(chap_table
->cookie
)));
1359 if (__le16_to_cpu(chap_table
->cookie
) != CHAP_VALID_COOKIE
) {
1360 ql4_printk(KERN_ERR
, ha
, "No valid chap entry found\n");
1364 strncpy(password
, chap_table
->secret
, QL4_CHAP_MAX_SECRET_LEN
);
1365 strncpy(username
, chap_table
->name
, QL4_CHAP_MAX_NAME_LEN
);
1366 chap_table
->cookie
= __constant_cpu_to_le16(CHAP_VALID_COOKIE
);
1369 dma_pool_free(ha
->chap_dma_pool
, chap_table
, chap_dma
);
1373 static int qla4xxx_set_chap(struct scsi_qla_host
*ha
, char *username
,
1374 char *password
, uint16_t idx
, int bidi
)
1377 int rval
= QLA_ERROR
;
1378 uint32_t offset
= 0;
1379 struct ql4_chap_table
*chap_table
;
1380 dma_addr_t chap_dma
;
1382 chap_table
= dma_pool_alloc(ha
->chap_dma_pool
, GFP_KERNEL
, &chap_dma
);
1383 if (chap_table
== NULL
) {
1388 memset(chap_table
, 0, sizeof(struct ql4_chap_table
));
1390 chap_table
->flags
|= BIT_6
; /* peer */
1392 chap_table
->flags
|= BIT_7
; /* local */
1393 chap_table
->secret_len
= strlen(password
);
1394 strncpy(chap_table
->secret
, password
, MAX_CHAP_SECRET_LEN
);
1395 strncpy(chap_table
->name
, username
, MAX_CHAP_NAME_LEN
);
1396 chap_table
->cookie
= __constant_cpu_to_le16(CHAP_VALID_COOKIE
);
1397 offset
= FLASH_CHAP_OFFSET
| (idx
* sizeof(struct ql4_chap_table
));
1398 rval
= qla4xxx_set_flash(ha
, chap_dma
, offset
,
1399 sizeof(struct ql4_chap_table
),
1400 FLASH_OPT_RMW_COMMIT
);
1402 if (rval
== QLA_SUCCESS
&& ha
->chap_list
) {
1403 /* Update ha chap_list cache */
1404 memcpy((struct ql4_chap_table
*)ha
->chap_list
+ idx
,
1405 chap_table
, sizeof(struct ql4_chap_table
));
1407 dma_pool_free(ha
->chap_dma_pool
, chap_table
, chap_dma
);
1408 if (rval
!= QLA_SUCCESS
)
1416 * qla4xxx_get_chap_index - Get chap index given username and secret
1417 * @ha: pointer to adapter structure
1418 * @username: CHAP username to be searched
1419 * @password: CHAP password to be searched
1420 * @bidi: Is this a BIDI CHAP
1421 * @chap_index: CHAP index to be returned
1423 * Match the username and password in the chap_list, return the index if a
1424 * match is found. If a match is not found then add the entry in FLASH and
1425 * return the index at which entry is written in the FLASH.
1427 static int qla4xxx_get_chap_index(struct scsi_qla_host
*ha
, char *username
,
1428 char *password
, int bidi
, uint16_t *chap_index
)
1431 int free_index
= -1;
1432 int found_index
= 0;
1433 int max_chap_entries
= 0;
1434 struct ql4_chap_table
*chap_table
;
1437 max_chap_entries
= (ha
->hw
.flt_chap_size
/ 2) /
1438 sizeof(struct ql4_chap_table
);
1440 max_chap_entries
= MAX_CHAP_ENTRIES_40XX
;
1442 if (!ha
->chap_list
) {
1443 ql4_printk(KERN_ERR
, ha
, "Do not have CHAP table cache\n");
1447 mutex_lock(&ha
->chap_sem
);
1448 for (i
= 0; i
< max_chap_entries
; i
++) {
1449 chap_table
= (struct ql4_chap_table
*)ha
->chap_list
+ i
;
1450 if (chap_table
->cookie
!=
1451 __constant_cpu_to_le16(CHAP_VALID_COOKIE
)) {
1452 if (i
> MAX_RESRV_CHAP_IDX
&& free_index
== -1)
1457 if (chap_table
->flags
& BIT_7
)
1460 if (chap_table
->flags
& BIT_6
)
1463 if (!strncmp(chap_table
->secret
, password
,
1464 MAX_CHAP_SECRET_LEN
) &&
1465 !strncmp(chap_table
->name
, username
,
1466 MAX_CHAP_NAME_LEN
)) {
1473 /* If chap entry is not present and a free index is available then
1474 * write the entry in flash
1476 if (!found_index
&& free_index
!= -1) {
1477 rval
= qla4xxx_set_chap(ha
, username
, password
,
1480 *chap_index
= free_index
;
1485 mutex_unlock(&ha
->chap_sem
);
1492 int qla4xxx_conn_close_sess_logout(struct scsi_qla_host
*ha
,
1493 uint16_t fw_ddb_index
,
1494 uint16_t connection_id
,
1497 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1498 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1499 int status
= QLA_SUCCESS
;
1501 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1502 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1504 mbox_cmd
[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT
;
1505 mbox_cmd
[1] = fw_ddb_index
;
1506 mbox_cmd
[2] = connection_id
;
1507 mbox_cmd
[3] = option
;
1509 status
= qla4xxx_mailbox_command(ha
, 4, 2, &mbox_cmd
[0], &mbox_sts
[0]);
1510 if (status
!= QLA_SUCCESS
) {
1511 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_CONN_CLOSE "
1512 "option %04x failed w/ status %04X %04X\n",
1513 __func__
, option
, mbox_sts
[0], mbox_sts
[1]));
1518 int qla4xxx_disable_acb(struct scsi_qla_host
*ha
)
1520 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1521 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1522 int status
= QLA_SUCCESS
;
1524 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1525 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1527 mbox_cmd
[0] = MBOX_CMD_DISABLE_ACB
;
1529 status
= qla4xxx_mailbox_command(ha
, 8, 5, &mbox_cmd
[0], &mbox_sts
[0]);
1530 if (status
!= QLA_SUCCESS
) {
1531 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_DISABLE_ACB "
1532 "failed w/ status %04X %04X %04X", __func__
,
1533 mbox_sts
[0], mbox_sts
[1], mbox_sts
[2]));
1538 int qla4xxx_get_acb(struct scsi_qla_host
*ha
, dma_addr_t acb_dma
,
1539 uint32_t acb_type
, uint32_t len
)
1541 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1542 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1543 int status
= QLA_SUCCESS
;
1545 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1546 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1548 mbox_cmd
[0] = MBOX_CMD_GET_ACB
;
1549 mbox_cmd
[1] = acb_type
;
1550 mbox_cmd
[2] = LSDW(acb_dma
);
1551 mbox_cmd
[3] = MSDW(acb_dma
);
1554 status
= qla4xxx_mailbox_command(ha
, 5, 5, &mbox_cmd
[0], &mbox_sts
[0]);
1555 if (status
!= QLA_SUCCESS
) {
1556 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_GET_ACB "
1557 "failed w/ status %04X\n", __func__
,
1563 int qla4xxx_set_acb(struct scsi_qla_host
*ha
, uint32_t *mbox_cmd
,
1564 uint32_t *mbox_sts
, dma_addr_t acb_dma
)
1566 int status
= QLA_SUCCESS
;
1568 memset(mbox_cmd
, 0, sizeof(mbox_cmd
[0]) * MBOX_REG_COUNT
);
1569 memset(mbox_sts
, 0, sizeof(mbox_sts
[0]) * MBOX_REG_COUNT
);
1570 mbox_cmd
[0] = MBOX_CMD_SET_ACB
;
1571 mbox_cmd
[1] = 0; /* Primary ACB */
1572 mbox_cmd
[2] = LSDW(acb_dma
);
1573 mbox_cmd
[3] = MSDW(acb_dma
);
1574 mbox_cmd
[4] = sizeof(struct addr_ctrl_blk
);
1576 status
= qla4xxx_mailbox_command(ha
, 5, 5, &mbox_cmd
[0], &mbox_sts
[0]);
1577 if (status
!= QLA_SUCCESS
) {
1578 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_SET_ACB "
1579 "failed w/ status %04X\n", __func__
,
1585 int qla4xxx_set_param_ddbentry(struct scsi_qla_host
*ha
,
1586 struct ddb_entry
*ddb_entry
,
1587 struct iscsi_cls_conn
*cls_conn
,
1590 struct dev_db_entry
*fw_ddb_entry
;
1591 struct iscsi_conn
*conn
;
1592 struct iscsi_session
*sess
;
1593 struct qla_conn
*qla_conn
;
1594 struct sockaddr
*dst_addr
;
1595 dma_addr_t fw_ddb_entry_dma
;
1596 int status
= QLA_SUCCESS
;
1598 struct sockaddr_in
*addr
;
1599 struct sockaddr_in6
*addr6
;
1601 uint16_t iscsi_opts
= 0;
1602 uint32_t options
= 0;
1605 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
1606 &fw_ddb_entry_dma
, GFP_KERNEL
);
1607 if (!fw_ddb_entry
) {
1608 DEBUG2(ql4_printk(KERN_ERR
, ha
,
1609 "%s: Unable to allocate dma buffer.\n",
1612 goto exit_set_param_no_free
;
1615 conn
= cls_conn
->dd_data
;
1616 qla_conn
= conn
->dd_data
;
1617 sess
= conn
->session
;
1618 dst_addr
= &qla_conn
->qla_ep
->dst_addr
;
1620 if (dst_addr
->sa_family
== AF_INET6
)
1621 options
|= IPV6_DEFAULT_DDB_ENTRY
;
1623 status
= qla4xxx_get_default_ddb(ha
, options
, fw_ddb_entry_dma
);
1624 if (status
== QLA_ERROR
) {
1626 goto exit_set_param
;
1629 iscsi_opts
= le16_to_cpu(fw_ddb_entry
->iscsi_options
);
1630 memset(fw_ddb_entry
->iscsi_alias
, 0, sizeof(fw_ddb_entry
->iscsi_alias
));
1632 memset(fw_ddb_entry
->iscsi_name
, 0, sizeof(fw_ddb_entry
->iscsi_name
));
1634 if (sess
->targetname
!= NULL
) {
1635 memcpy(fw_ddb_entry
->iscsi_name
, sess
->targetname
,
1636 min(strlen(sess
->targetname
),
1637 sizeof(fw_ddb_entry
->iscsi_name
)));
1640 memset(fw_ddb_entry
->ip_addr
, 0, sizeof(fw_ddb_entry
->ip_addr
));
1641 memset(fw_ddb_entry
->tgt_addr
, 0, sizeof(fw_ddb_entry
->tgt_addr
));
1643 fw_ddb_entry
->options
= DDB_OPT_TARGET
| DDB_OPT_AUTO_SENDTGTS_DISABLE
;
1645 if (dst_addr
->sa_family
== AF_INET
) {
1646 addr
= (struct sockaddr_in
*)dst_addr
;
1647 ip
= (char *)&addr
->sin_addr
;
1648 memcpy(fw_ddb_entry
->ip_addr
, ip
, IP_ADDR_LEN
);
1649 fw_ddb_entry
->port
= cpu_to_le16(ntohs(addr
->sin_port
));
1650 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1651 "%s: Destination Address [%pI4]: index [%d]\n",
1652 __func__
, fw_ddb_entry
->ip_addr
,
1653 ddb_entry
->fw_ddb_index
));
1654 } else if (dst_addr
->sa_family
== AF_INET6
) {
1655 addr6
= (struct sockaddr_in6
*)dst_addr
;
1656 ip
= (char *)&addr6
->sin6_addr
;
1657 memcpy(fw_ddb_entry
->ip_addr
, ip
, IPv6_ADDR_LEN
);
1658 fw_ddb_entry
->port
= cpu_to_le16(ntohs(addr6
->sin6_port
));
1659 fw_ddb_entry
->options
|= DDB_OPT_IPV6_DEVICE
;
1660 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1661 "%s: Destination Address [%pI6]: index [%d]\n",
1662 __func__
, fw_ddb_entry
->ip_addr
,
1663 ddb_entry
->fw_ddb_index
));
1665 ql4_printk(KERN_ERR
, ha
,
1666 "%s: Failed to get IP Address\n",
1669 goto exit_set_param
;
1673 if (sess
->username
!= NULL
&& sess
->password
!= NULL
) {
1674 if (strlen(sess
->username
) && strlen(sess
->password
)) {
1675 iscsi_opts
|= BIT_7
;
1677 rval
= qla4xxx_get_chap_index(ha
, sess
->username
,
1681 goto exit_set_param
;
1683 fw_ddb_entry
->chap_tbl_idx
= cpu_to_le16(idx
);
1687 if (sess
->username_in
!= NULL
&& sess
->password_in
!= NULL
) {
1688 /* Check if BIDI CHAP */
1689 if (strlen(sess
->username_in
) && strlen(sess
->password_in
)) {
1690 iscsi_opts
|= BIT_4
;
1692 rval
= qla4xxx_get_chap_index(ha
, sess
->username_in
,
1696 goto exit_set_param
;
1700 if (sess
->initial_r2t_en
)
1701 iscsi_opts
|= BIT_10
;
1703 if (sess
->imm_data_en
)
1704 iscsi_opts
|= BIT_11
;
1706 fw_ddb_entry
->iscsi_options
= cpu_to_le16(iscsi_opts
);
1708 if (conn
->max_recv_dlength
)
1709 fw_ddb_entry
->iscsi_max_rcv_data_seg_len
=
1710 __constant_cpu_to_le16((conn
->max_recv_dlength
/ BYTE_UNITS
));
1713 fw_ddb_entry
->iscsi_max_outsnd_r2t
= cpu_to_le16(sess
->max_r2t
);
1715 if (sess
->first_burst
)
1716 fw_ddb_entry
->iscsi_first_burst_len
=
1717 __constant_cpu_to_le16((sess
->first_burst
/ BYTE_UNITS
));
1719 if (sess
->max_burst
)
1720 fw_ddb_entry
->iscsi_max_burst_len
=
1721 __constant_cpu_to_le16((sess
->max_burst
/ BYTE_UNITS
));
1723 if (sess
->time2wait
)
1724 fw_ddb_entry
->iscsi_def_time2wait
=
1725 cpu_to_le16(sess
->time2wait
);
1727 if (sess
->time2retain
)
1728 fw_ddb_entry
->iscsi_def_time2retain
=
1729 cpu_to_le16(sess
->time2retain
);
1731 status
= qla4xxx_set_ddb_entry(ha
, ddb_entry
->fw_ddb_index
,
1732 fw_ddb_entry_dma
, mbx_sts
);
1734 if (status
!= QLA_SUCCESS
)
1737 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
1738 fw_ddb_entry
, fw_ddb_entry_dma
);
1739 exit_set_param_no_free
:
1743 int qla4xxx_get_mgmt_data(struct scsi_qla_host
*ha
, uint16_t fw_ddb_index
,
1744 uint16_t stats_size
, dma_addr_t stats_dma
)
1746 int status
= QLA_SUCCESS
;
1747 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1748 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1750 memset(mbox_cmd
, 0, sizeof(mbox_cmd
[0]) * MBOX_REG_COUNT
);
1751 memset(mbox_sts
, 0, sizeof(mbox_sts
[0]) * MBOX_REG_COUNT
);
1752 mbox_cmd
[0] = MBOX_CMD_GET_MANAGEMENT_DATA
;
1753 mbox_cmd
[1] = fw_ddb_index
;
1754 mbox_cmd
[2] = LSDW(stats_dma
);
1755 mbox_cmd
[3] = MSDW(stats_dma
);
1756 mbox_cmd
[4] = stats_size
;
1758 status
= qla4xxx_mailbox_command(ha
, 5, 1, &mbox_cmd
[0], &mbox_sts
[0]);
1759 if (status
!= QLA_SUCCESS
) {
1760 DEBUG2(ql4_printk(KERN_WARNING
, ha
,
1761 "%s: MBOX_CMD_GET_MANAGEMENT_DATA "
1762 "failed w/ status %04X\n", __func__
,
1768 int qla4xxx_get_ip_state(struct scsi_qla_host
*ha
, uint32_t acb_idx
,
1769 uint32_t ip_idx
, uint32_t *sts
)
1771 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1772 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1773 int status
= QLA_SUCCESS
;
1775 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1776 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1777 mbox_cmd
[0] = MBOX_CMD_GET_IP_ADDR_STATE
;
1778 mbox_cmd
[1] = acb_idx
;
1779 mbox_cmd
[2] = ip_idx
;
1781 status
= qla4xxx_mailbox_command(ha
, 3, 8, &mbox_cmd
[0], &mbox_sts
[0]);
1782 if (status
!= QLA_SUCCESS
) {
1783 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: "
1784 "MBOX_CMD_GET_IP_ADDR_STATE failed w/ "
1785 "status %04X\n", __func__
, mbox_sts
[0]));
1787 memcpy(sts
, mbox_sts
, sizeof(mbox_sts
));
1791 int qla4xxx_get_nvram(struct scsi_qla_host
*ha
, dma_addr_t nvram_dma
,
1792 uint32_t offset
, uint32_t size
)
1794 int status
= QLA_SUCCESS
;
1795 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1796 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1798 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1799 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1801 mbox_cmd
[0] = MBOX_CMD_GET_NVRAM
;
1802 mbox_cmd
[1] = LSDW(nvram_dma
);
1803 mbox_cmd
[2] = MSDW(nvram_dma
);
1804 mbox_cmd
[3] = offset
;
1807 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0],
1809 if (status
!= QLA_SUCCESS
) {
1810 DEBUG2(ql4_printk(KERN_ERR
, ha
, "scsi%ld: %s: failed "
1811 "status %04X\n", ha
->host_no
, __func__
,
1817 int qla4xxx_set_nvram(struct scsi_qla_host
*ha
, dma_addr_t nvram_dma
,
1818 uint32_t offset
, uint32_t size
)
1820 int status
= QLA_SUCCESS
;
1821 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1822 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1824 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1825 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1827 mbox_cmd
[0] = MBOX_CMD_SET_NVRAM
;
1828 mbox_cmd
[1] = LSDW(nvram_dma
);
1829 mbox_cmd
[2] = MSDW(nvram_dma
);
1830 mbox_cmd
[3] = offset
;
1833 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0],
1835 if (status
!= QLA_SUCCESS
) {
1836 DEBUG2(ql4_printk(KERN_ERR
, ha
, "scsi%ld: %s: failed "
1837 "status %04X\n", ha
->host_no
, __func__
,
1843 int qla4xxx_restore_factory_defaults(struct scsi_qla_host
*ha
,
1844 uint32_t region
, uint32_t field0
,
1847 int status
= QLA_SUCCESS
;
1848 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1849 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1851 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1852 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1854 mbox_cmd
[0] = MBOX_CMD_RESTORE_FACTORY_DEFAULTS
;
1855 mbox_cmd
[3] = region
;
1856 mbox_cmd
[4] = field0
;
1857 mbox_cmd
[5] = field1
;
1859 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 3, &mbox_cmd
[0],
1861 if (status
!= QLA_SUCCESS
) {
1862 DEBUG2(ql4_printk(KERN_ERR
, ha
, "scsi%ld: %s: failed "
1863 "status %04X\n", ha
->host_no
, __func__
,