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__
));
54 if ((is_aer_supported(ha
)) &&
55 (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE
, &ha
->flags
))) {
56 DEBUG2(printk(KERN_WARNING
"scsi%ld: %s: Perm failure on EEH, "
57 "timeout MBX Exiting.\n", ha
->host_no
, __func__
));
61 /* Mailbox code active */
62 wait_count
= MBOX_TOV
* 100;
64 while (wait_count
--) {
65 mutex_lock(&ha
->mbox_sem
);
66 if (!test_bit(AF_MBOX_COMMAND
, &ha
->flags
)) {
67 set_bit(AF_MBOX_COMMAND
, &ha
->flags
);
68 mutex_unlock(&ha
->mbox_sem
);
71 mutex_unlock(&ha
->mbox_sem
);
73 DEBUG2(printk("scsi%ld: %s: mbox_sem failed\n",
74 ha
->host_no
, __func__
));
81 if (test_bit(AF_FW_RECOVERY
, &ha
->flags
)) {
82 DEBUG2(ql4_printk(KERN_WARNING
, ha
,
83 "scsi%ld: %s: prematurely completing mbx cmd as firmware recovery detected\n",
84 ha
->host_no
, __func__
));
87 /* Do not send any mbx cmd if h/w is in failed state*/
88 qla4_8xxx_idc_lock(ha
);
89 dev_state
= qla4_8xxx_rd_32(ha
, QLA82XX_CRB_DEV_STATE
);
90 qla4_8xxx_idc_unlock(ha
);
91 if (dev_state
== QLA82XX_DEV_FAILED
) {
92 ql4_printk(KERN_WARNING
, ha
,
93 "scsi%ld: %s: H/W is in failed state, do not send any mailbox commands\n",
94 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
);
274 * qla4xxx_get_minidump_template - Get the firmware template
275 * @ha: Pointer to host adapter structure.
276 * @phys_addr: dma address for template
278 * Obtain the minidump template from firmware during initialization
279 * as it may not be available when minidump is desired.
281 int qla4xxx_get_minidump_template(struct scsi_qla_host
*ha
,
282 dma_addr_t phys_addr
)
284 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
285 uint32_t mbox_sts
[MBOX_REG_COUNT
];
288 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
289 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
291 mbox_cmd
[0] = MBOX_CMD_MINIDUMP
;
292 mbox_cmd
[1] = MINIDUMP_GET_TMPLT_SUBCOMMAND
;
293 mbox_cmd
[2] = LSDW(phys_addr
);
294 mbox_cmd
[3] = MSDW(phys_addr
);
295 mbox_cmd
[4] = ha
->fw_dump_tmplt_size
;
298 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 2, &mbox_cmd
[0],
300 if (status
!= QLA_SUCCESS
) {
301 DEBUG2(ql4_printk(KERN_INFO
, ha
,
302 "scsi%ld: %s: Cmd = %08X, mbx[0] = 0x%04x, mbx[1] = 0x%04x\n",
303 ha
->host_no
, __func__
, mbox_cmd
[0],
304 mbox_sts
[0], mbox_sts
[1]));
310 * qla4xxx_req_template_size - Get minidump template size from firmware.
311 * @ha: Pointer to host adapter structure.
313 int qla4xxx_req_template_size(struct scsi_qla_host
*ha
)
315 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
316 uint32_t mbox_sts
[MBOX_REG_COUNT
];
319 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
320 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
322 mbox_cmd
[0] = MBOX_CMD_MINIDUMP
;
323 mbox_cmd
[1] = MINIDUMP_GET_SIZE_SUBCOMMAND
;
325 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 8, &mbox_cmd
[0],
327 if (status
== QLA_SUCCESS
) {
328 ha
->fw_dump_tmplt_size
= mbox_sts
[1];
329 DEBUG2(ql4_printk(KERN_INFO
, ha
,
330 "%s: sts[0]=0x%04x, template size=0x%04x, size_cm_02=0x%04x, size_cm_04=0x%04x, size_cm_08=0x%04x, size_cm_10=0x%04x, size_cm_FF=0x%04x, version=0x%04x\n",
331 __func__
, mbox_sts
[0], mbox_sts
[1],
332 mbox_sts
[2], mbox_sts
[3], mbox_sts
[4],
333 mbox_sts
[5], mbox_sts
[6], mbox_sts
[7]));
334 if (ha
->fw_dump_tmplt_size
== 0)
337 ql4_printk(KERN_WARNING
, ha
,
338 "%s: Error sts[0]=0x%04x, mbx[1]=0x%04x\n",
339 __func__
, mbox_sts
[0], mbox_sts
[1]);
346 void qla4xxx_mailbox_premature_completion(struct scsi_qla_host
*ha
)
348 set_bit(AF_FW_RECOVERY
, &ha
->flags
);
349 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: set FW RECOVERY!\n",
350 ha
->host_no
, __func__
);
352 if (test_bit(AF_MBOX_COMMAND
, &ha
->flags
)) {
353 if (test_bit(AF_MBOX_COMMAND_NOPOLL
, &ha
->flags
)) {
354 complete(&ha
->mbx_intr_comp
);
355 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: Due to fw "
356 "recovery, doing premature completion of "
357 "mbx cmd\n", ha
->host_no
, __func__
);
360 set_bit(AF_MBOX_COMMAND_DONE
, &ha
->flags
);
361 ql4_printk(KERN_INFO
, ha
, "scsi%ld: %s: Due to fw "
362 "recovery, doing premature completion of "
363 "polling mbx cmd\n", ha
->host_no
, __func__
);
369 qla4xxx_set_ifcb(struct scsi_qla_host
*ha
, uint32_t *mbox_cmd
,
370 uint32_t *mbox_sts
, dma_addr_t init_fw_cb_dma
)
372 memset(mbox_cmd
, 0, sizeof(mbox_cmd
[0]) * MBOX_REG_COUNT
);
373 memset(mbox_sts
, 0, sizeof(mbox_sts
[0]) * MBOX_REG_COUNT
);
376 qla4_8xxx_wr_32(ha
, ha
->nx_db_wr_ptr
, 0);
378 mbox_cmd
[0] = MBOX_CMD_INITIALIZE_FIRMWARE
;
380 mbox_cmd
[2] = LSDW(init_fw_cb_dma
);
381 mbox_cmd
[3] = MSDW(init_fw_cb_dma
);
382 mbox_cmd
[4] = sizeof(struct addr_ctrl_blk
);
383 mbox_cmd
[5] = (IFCB_VER_MAX
<< 8) | IFCB_VER_MIN
;
385 if (qla4xxx_mailbox_command(ha
, 6, 6, mbox_cmd
, mbox_sts
) !=
387 DEBUG2(printk(KERN_WARNING
"scsi%ld: %s: "
388 "MBOX_CMD_INITIALIZE_FIRMWARE"
389 " failed w/ status %04X\n",
390 ha
->host_no
, __func__
, mbox_sts
[0]));
397 qla4xxx_get_ifcb(struct scsi_qla_host
*ha
, uint32_t *mbox_cmd
,
398 uint32_t *mbox_sts
, dma_addr_t init_fw_cb_dma
)
400 memset(mbox_cmd
, 0, sizeof(mbox_cmd
[0]) * MBOX_REG_COUNT
);
401 memset(mbox_sts
, 0, sizeof(mbox_sts
[0]) * MBOX_REG_COUNT
);
402 mbox_cmd
[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK
;
403 mbox_cmd
[2] = LSDW(init_fw_cb_dma
);
404 mbox_cmd
[3] = MSDW(init_fw_cb_dma
);
405 mbox_cmd
[4] = sizeof(struct addr_ctrl_blk
);
407 if (qla4xxx_mailbox_command(ha
, 5, 5, mbox_cmd
, mbox_sts
) !=
409 DEBUG2(printk(KERN_WARNING
"scsi%ld: %s: "
410 "MBOX_CMD_GET_INIT_FW_CTRL_BLOCK"
411 " failed w/ status %04X\n",
412 ha
->host_no
, __func__
, mbox_sts
[0]));
419 qla4xxx_update_local_ip(struct scsi_qla_host
*ha
,
420 struct addr_ctrl_blk
*init_fw_cb
)
422 ha
->ip_config
.tcp_options
= le16_to_cpu(init_fw_cb
->ipv4_tcp_opts
);
423 ha
->ip_config
.ipv4_options
= le16_to_cpu(init_fw_cb
->ipv4_ip_opts
);
424 ha
->ip_config
.ipv4_addr_state
=
425 le16_to_cpu(init_fw_cb
->ipv4_addr_state
);
426 ha
->ip_config
.eth_mtu_size
=
427 le16_to_cpu(init_fw_cb
->eth_mtu_size
);
428 ha
->ip_config
.ipv4_port
= le16_to_cpu(init_fw_cb
->ipv4_port
);
430 if (ha
->acb_version
== ACB_SUPPORTED
) {
431 ha
->ip_config
.ipv6_options
= le16_to_cpu(init_fw_cb
->ipv6_opts
);
432 ha
->ip_config
.ipv6_addl_options
=
433 le16_to_cpu(init_fw_cb
->ipv6_addtl_opts
);
436 /* Save IPv4 Address Info */
437 memcpy(ha
->ip_config
.ip_address
, init_fw_cb
->ipv4_addr
,
438 min(sizeof(ha
->ip_config
.ip_address
),
439 sizeof(init_fw_cb
->ipv4_addr
)));
440 memcpy(ha
->ip_config
.subnet_mask
, init_fw_cb
->ipv4_subnet
,
441 min(sizeof(ha
->ip_config
.subnet_mask
),
442 sizeof(init_fw_cb
->ipv4_subnet
)));
443 memcpy(ha
->ip_config
.gateway
, init_fw_cb
->ipv4_gw_addr
,
444 min(sizeof(ha
->ip_config
.gateway
),
445 sizeof(init_fw_cb
->ipv4_gw_addr
)));
447 ha
->ip_config
.ipv4_vlan_tag
= be16_to_cpu(init_fw_cb
->ipv4_vlan_tag
);
449 if (is_ipv6_enabled(ha
)) {
450 /* Save IPv6 Address */
451 ha
->ip_config
.ipv6_link_local_state
=
452 le16_to_cpu(init_fw_cb
->ipv6_lnk_lcl_addr_state
);
453 ha
->ip_config
.ipv6_addr0_state
=
454 le16_to_cpu(init_fw_cb
->ipv6_addr0_state
);
455 ha
->ip_config
.ipv6_addr1_state
=
456 le16_to_cpu(init_fw_cb
->ipv6_addr1_state
);
457 ha
->ip_config
.ipv6_default_router_state
=
458 le16_to_cpu(init_fw_cb
->ipv6_dflt_rtr_state
);
459 ha
->ip_config
.ipv6_link_local_addr
.in6_u
.u6_addr8
[0] = 0xFE;
460 ha
->ip_config
.ipv6_link_local_addr
.in6_u
.u6_addr8
[1] = 0x80;
462 memcpy(&ha
->ip_config
.ipv6_link_local_addr
.in6_u
.u6_addr8
[8],
463 init_fw_cb
->ipv6_if_id
,
464 min(sizeof(ha
->ip_config
.ipv6_link_local_addr
)/2,
465 sizeof(init_fw_cb
->ipv6_if_id
)));
466 memcpy(&ha
->ip_config
.ipv6_addr0
, init_fw_cb
->ipv6_addr0
,
467 min(sizeof(ha
->ip_config
.ipv6_addr0
),
468 sizeof(init_fw_cb
->ipv6_addr0
)));
469 memcpy(&ha
->ip_config
.ipv6_addr1
, init_fw_cb
->ipv6_addr1
,
470 min(sizeof(ha
->ip_config
.ipv6_addr1
),
471 sizeof(init_fw_cb
->ipv6_addr1
)));
472 memcpy(&ha
->ip_config
.ipv6_default_router_addr
,
473 init_fw_cb
->ipv6_dflt_rtr_addr
,
474 min(sizeof(ha
->ip_config
.ipv6_default_router_addr
),
475 sizeof(init_fw_cb
->ipv6_dflt_rtr_addr
)));
476 ha
->ip_config
.ipv6_vlan_tag
=
477 be16_to_cpu(init_fw_cb
->ipv6_vlan_tag
);
478 ha
->ip_config
.ipv6_port
= le16_to_cpu(init_fw_cb
->ipv6_port
);
483 qla4xxx_update_local_ifcb(struct scsi_qla_host
*ha
,
486 struct addr_ctrl_blk
*init_fw_cb
,
487 dma_addr_t init_fw_cb_dma
)
489 if (qla4xxx_get_ifcb(ha
, mbox_cmd
, mbox_sts
, init_fw_cb_dma
)
491 DEBUG2(printk(KERN_WARNING
492 "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
493 ha
->host_no
, __func__
));
497 DEBUG2(qla4xxx_dump_buffer(init_fw_cb
, sizeof(struct addr_ctrl_blk
)));
499 /* Save some info in adapter structure. */
500 ha
->acb_version
= init_fw_cb
->acb_version
;
501 ha
->firmware_options
= le16_to_cpu(init_fw_cb
->fw_options
);
502 ha
->heartbeat_interval
= init_fw_cb
->hb_interval
;
503 memcpy(ha
->name_string
, init_fw_cb
->iscsi_name
,
504 min(sizeof(ha
->name_string
),
505 sizeof(init_fw_cb
->iscsi_name
)));
506 ha
->def_timeout
= le16_to_cpu(init_fw_cb
->def_timeout
);
507 /*memcpy(ha->alias, init_fw_cb->Alias,
508 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
510 qla4xxx_update_local_ip(ha
, init_fw_cb
);
516 * qla4xxx_initialize_fw_cb - initializes firmware control block.
517 * @ha: Pointer to host adapter structure.
519 int qla4xxx_initialize_fw_cb(struct scsi_qla_host
* ha
)
521 struct addr_ctrl_blk
*init_fw_cb
;
522 dma_addr_t init_fw_cb_dma
;
523 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
524 uint32_t mbox_sts
[MBOX_REG_COUNT
];
525 int status
= QLA_ERROR
;
527 init_fw_cb
= dma_alloc_coherent(&ha
->pdev
->dev
,
528 sizeof(struct addr_ctrl_blk
),
529 &init_fw_cb_dma
, GFP_KERNEL
);
530 if (init_fw_cb
== NULL
) {
531 DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
532 ha
->host_no
, __func__
));
533 goto exit_init_fw_cb_no_free
;
535 memset(init_fw_cb
, 0, sizeof(struct addr_ctrl_blk
));
537 /* Get Initialize Firmware Control Block. */
538 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
539 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
541 if (qla4xxx_get_ifcb(ha
, &mbox_cmd
[0], &mbox_sts
[0], init_fw_cb_dma
) !=
543 dma_free_coherent(&ha
->pdev
->dev
,
544 sizeof(struct addr_ctrl_blk
),
545 init_fw_cb
, init_fw_cb_dma
);
546 goto exit_init_fw_cb
;
549 /* Initialize request and response queues. */
550 qla4xxx_init_rings(ha
);
552 /* Fill in the request and response queue information. */
553 init_fw_cb
->rqq_consumer_idx
= cpu_to_le16(ha
->request_out
);
554 init_fw_cb
->compq_producer_idx
= cpu_to_le16(ha
->response_in
);
555 init_fw_cb
->rqq_len
= __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH
);
556 init_fw_cb
->compq_len
= __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH
);
557 init_fw_cb
->rqq_addr_lo
= cpu_to_le32(LSDW(ha
->request_dma
));
558 init_fw_cb
->rqq_addr_hi
= cpu_to_le32(MSDW(ha
->request_dma
));
559 init_fw_cb
->compq_addr_lo
= cpu_to_le32(LSDW(ha
->response_dma
));
560 init_fw_cb
->compq_addr_hi
= cpu_to_le32(MSDW(ha
->response_dma
));
561 init_fw_cb
->shdwreg_addr_lo
= cpu_to_le32(LSDW(ha
->shadow_regs_dma
));
562 init_fw_cb
->shdwreg_addr_hi
= cpu_to_le32(MSDW(ha
->shadow_regs_dma
));
564 /* Set up required options. */
565 init_fw_cb
->fw_options
|=
566 __constant_cpu_to_le16(FWOPT_SESSION_MODE
|
567 FWOPT_INITIATOR_MODE
);
570 init_fw_cb
->fw_options
|=
571 __constant_cpu_to_le16(FWOPT_ENABLE_CRBDB
);
573 init_fw_cb
->fw_options
&= __constant_cpu_to_le16(~FWOPT_TARGET_MODE
);
575 init_fw_cb
->add_fw_options
= 0;
576 init_fw_cb
->add_fw_options
|=
577 __constant_cpu_to_le16(ADFWOPT_SERIALIZE_TASK_MGMT
);
578 init_fw_cb
->add_fw_options
|=
579 __constant_cpu_to_le16(ADFWOPT_AUTOCONN_DISABLE
);
581 if (qla4xxx_set_ifcb(ha
, &mbox_cmd
[0], &mbox_sts
[0], init_fw_cb_dma
)
583 DEBUG2(printk(KERN_WARNING
584 "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
585 ha
->host_no
, __func__
));
586 goto exit_init_fw_cb
;
589 if (qla4xxx_update_local_ifcb(ha
, &mbox_cmd
[0], &mbox_sts
[0],
590 init_fw_cb
, init_fw_cb_dma
) != QLA_SUCCESS
) {
591 DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
592 ha
->host_no
, __func__
));
593 goto exit_init_fw_cb
;
595 status
= QLA_SUCCESS
;
598 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct addr_ctrl_blk
),
599 init_fw_cb
, init_fw_cb_dma
);
600 exit_init_fw_cb_no_free
:
605 * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
606 * @ha: Pointer to host adapter structure.
608 int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host
* ha
)
610 struct addr_ctrl_blk
*init_fw_cb
;
611 dma_addr_t init_fw_cb_dma
;
612 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
613 uint32_t mbox_sts
[MBOX_REG_COUNT
];
615 init_fw_cb
= dma_alloc_coherent(&ha
->pdev
->dev
,
616 sizeof(struct addr_ctrl_blk
),
617 &init_fw_cb_dma
, GFP_KERNEL
);
618 if (init_fw_cb
== NULL
) {
619 printk("scsi%ld: %s: Unable to alloc init_cb\n", ha
->host_no
,
624 /* Get Initialize Firmware Control Block. */
625 memset(init_fw_cb
, 0, sizeof(struct addr_ctrl_blk
));
626 if (qla4xxx_get_ifcb(ha
, &mbox_cmd
[0], &mbox_sts
[0], init_fw_cb_dma
) !=
628 DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
629 ha
->host_no
, __func__
));
630 dma_free_coherent(&ha
->pdev
->dev
,
631 sizeof(struct addr_ctrl_blk
),
632 init_fw_cb
, init_fw_cb_dma
);
636 /* Save IP Address. */
637 qla4xxx_update_local_ip(ha
, init_fw_cb
);
638 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct addr_ctrl_blk
),
639 init_fw_cb
, init_fw_cb_dma
);
645 * qla4xxx_get_firmware_state - gets firmware state of HBA
646 * @ha: Pointer to host adapter structure.
648 int qla4xxx_get_firmware_state(struct scsi_qla_host
* ha
)
650 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
651 uint32_t mbox_sts
[MBOX_REG_COUNT
];
653 /* Get firmware version */
654 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
655 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
657 mbox_cmd
[0] = MBOX_CMD_GET_FW_STATE
;
659 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 4, &mbox_cmd
[0], &mbox_sts
[0]) !=
661 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
662 "status %04X\n", ha
->host_no
, __func__
,
666 ha
->firmware_state
= mbox_sts
[1];
667 ha
->board_id
= mbox_sts
[2];
668 ha
->addl_fw_state
= mbox_sts
[3];
669 DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
670 ha
->host_no
, __func__
, ha
->firmware_state
);)
676 * qla4xxx_get_firmware_status - retrieves firmware status
677 * @ha: Pointer to host adapter structure.
679 int qla4xxx_get_firmware_status(struct scsi_qla_host
* ha
)
681 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
682 uint32_t mbox_sts
[MBOX_REG_COUNT
];
684 /* Get firmware version */
685 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
686 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
688 mbox_cmd
[0] = MBOX_CMD_GET_FW_STATUS
;
690 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 3, &mbox_cmd
[0], &mbox_sts
[0]) !=
692 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
693 "status %04X\n", ha
->host_no
, __func__
,
698 ql4_printk(KERN_INFO
, ha
, "%ld firmware IOCBs available (%d).\n",
699 ha
->host_no
, mbox_sts
[2]);
705 * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
706 * @ha: Pointer to host adapter structure.
707 * @fw_ddb_index: Firmware's device database index
708 * @fw_ddb_entry: Pointer to firmware's device database entry structure
709 * @num_valid_ddb_entries: Pointer to number of valid ddb entries
710 * @next_ddb_index: Pointer to next valid device database index
711 * @fw_ddb_device_state: Pointer to device state
713 int qla4xxx_get_fwddb_entry(struct scsi_qla_host
*ha
,
714 uint16_t fw_ddb_index
,
715 struct dev_db_entry
*fw_ddb_entry
,
716 dma_addr_t fw_ddb_entry_dma
,
717 uint32_t *num_valid_ddb_entries
,
718 uint32_t *next_ddb_index
,
719 uint32_t *fw_ddb_device_state
,
720 uint32_t *conn_err_detail
,
721 uint16_t *tcp_source_port_num
,
722 uint16_t *connection_id
)
724 int status
= QLA_ERROR
;
726 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
727 uint32_t mbox_sts
[MBOX_REG_COUNT
];
729 /* Make sure the device index is valid */
730 if (fw_ddb_index
>= MAX_DDB_ENTRIES
) {
731 DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
732 ha
->host_no
, __func__
, fw_ddb_index
));
735 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
736 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
738 memset(fw_ddb_entry
, 0, sizeof(struct dev_db_entry
));
740 mbox_cmd
[0] = MBOX_CMD_GET_DATABASE_ENTRY
;
741 mbox_cmd
[1] = (uint32_t) fw_ddb_index
;
742 mbox_cmd
[2] = LSDW(fw_ddb_entry_dma
);
743 mbox_cmd
[3] = MSDW(fw_ddb_entry_dma
);
744 mbox_cmd
[4] = sizeof(struct dev_db_entry
);
746 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 7, &mbox_cmd
[0], &mbox_sts
[0]) ==
748 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
749 " with status 0x%04X\n", ha
->host_no
, __func__
,
753 if (fw_ddb_index
!= mbox_sts
[1]) {
754 DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
755 ha
->host_no
, __func__
, fw_ddb_index
,
760 options
= le16_to_cpu(fw_ddb_entry
->options
);
761 if (options
& DDB_OPT_IPV6_DEVICE
) {
762 ql4_printk(KERN_INFO
, ha
, "%s: DDB[%d] MB0 %04x Tot %d "
763 "Next %d State %04x ConnErr %08x %pI6 "
764 ":%04d \"%s\"\n", __func__
, fw_ddb_index
,
765 mbox_sts
[0], mbox_sts
[2], mbox_sts
[3],
766 mbox_sts
[4], mbox_sts
[5],
767 fw_ddb_entry
->ip_addr
,
768 le16_to_cpu(fw_ddb_entry
->port
),
769 fw_ddb_entry
->iscsi_name
);
771 ql4_printk(KERN_INFO
, ha
, "%s: DDB[%d] MB0 %04x Tot %d "
772 "Next %d State %04x ConnErr %08x %pI4 "
773 ":%04d \"%s\"\n", __func__
, fw_ddb_index
,
774 mbox_sts
[0], mbox_sts
[2], mbox_sts
[3],
775 mbox_sts
[4], mbox_sts
[5],
776 fw_ddb_entry
->ip_addr
,
777 le16_to_cpu(fw_ddb_entry
->port
),
778 fw_ddb_entry
->iscsi_name
);
781 if (num_valid_ddb_entries
)
782 *num_valid_ddb_entries
= mbox_sts
[2];
784 *next_ddb_index
= mbox_sts
[3];
785 if (fw_ddb_device_state
)
786 *fw_ddb_device_state
= mbox_sts
[4];
789 * RA: This mailbox has been changed to pass connection error and
790 * details. Its true for ISP4010 as per Version E - Not sure when it
791 * was changed. Get the time2wait from the fw_dd_entry field :
792 * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
796 *conn_err_detail
= mbox_sts
[5];
797 if (tcp_source_port_num
)
798 *tcp_source_port_num
= (uint16_t) (mbox_sts
[6] >> 16);
800 *connection_id
= (uint16_t) mbox_sts
[6] & 0x00FF;
801 status
= QLA_SUCCESS
;
807 int qla4xxx_conn_open(struct scsi_qla_host
*ha
, uint16_t fw_ddb_index
)
809 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
810 uint32_t mbox_sts
[MBOX_REG_COUNT
];
813 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
814 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
816 mbox_cmd
[0] = MBOX_CMD_CONN_OPEN
;
817 mbox_cmd
[1] = fw_ddb_index
;
819 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 2, &mbox_cmd
[0],
821 DEBUG2(ql4_printk(KERN_INFO
, ha
,
822 "%s: status = %d mbx0 = 0x%x mbx1 = 0x%x\n",
823 __func__
, status
, mbox_sts
[0], mbox_sts
[1]));
828 * qla4xxx_set_fwddb_entry - sets a ddb entry.
829 * @ha: Pointer to host adapter structure.
830 * @fw_ddb_index: Firmware's device database index
831 * @fw_ddb_entry_dma: dma address of ddb entry
832 * @mbx_sts: mailbox 0 to be returned or NULL
834 * This routine initializes or updates the adapter's device database
835 * entry for the specified device.
837 int qla4xxx_set_ddb_entry(struct scsi_qla_host
* ha
, uint16_t fw_ddb_index
,
838 dma_addr_t fw_ddb_entry_dma
, uint32_t *mbx_sts
)
840 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
841 uint32_t mbox_sts
[MBOX_REG_COUNT
];
844 /* Do not wait for completion. The firmware will send us an
845 * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
847 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
848 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
850 mbox_cmd
[0] = MBOX_CMD_SET_DATABASE_ENTRY
;
851 mbox_cmd
[1] = (uint32_t) fw_ddb_index
;
852 mbox_cmd
[2] = LSDW(fw_ddb_entry_dma
);
853 mbox_cmd
[3] = MSDW(fw_ddb_entry_dma
);
854 mbox_cmd
[4] = sizeof(struct dev_db_entry
);
856 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0],
859 *mbx_sts
= mbox_sts
[0];
860 DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
861 ha
->host_no
, __func__
, status
, mbox_sts
[0], mbox_sts
[4]);)
866 int qla4xxx_session_logout_ddb(struct scsi_qla_host
*ha
,
867 struct ddb_entry
*ddb_entry
, int options
)
870 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
871 uint32_t mbox_sts
[MBOX_REG_COUNT
];
873 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
874 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
876 mbox_cmd
[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT
;
877 mbox_cmd
[1] = ddb_entry
->fw_ddb_index
;
878 mbox_cmd
[3] = options
;
880 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 2, &mbox_cmd
[0],
882 if (status
!= QLA_SUCCESS
) {
883 DEBUG2(ql4_printk(KERN_INFO
, ha
,
884 "%s: MBOX_CMD_CONN_CLOSE_SESS_LOGOUT "
885 "failed sts %04X %04X", __func__
,
886 mbox_sts
[0], mbox_sts
[1]));
893 * qla4xxx_get_crash_record - retrieves crash record.
894 * @ha: Pointer to host adapter structure.
896 * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
898 void qla4xxx_get_crash_record(struct scsi_qla_host
* ha
)
900 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
901 uint32_t mbox_sts
[MBOX_REG_COUNT
];
902 struct crash_record
*crash_record
= NULL
;
903 dma_addr_t crash_record_dma
= 0;
904 uint32_t crash_record_size
= 0;
906 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
907 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
909 /* Get size of crash record. */
910 mbox_cmd
[0] = MBOX_CMD_GET_CRASH_RECORD
;
912 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
914 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
915 ha
->host_no
, __func__
));
916 goto exit_get_crash_record
;
918 crash_record_size
= mbox_sts
[4];
919 if (crash_record_size
== 0) {
920 DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
921 ha
->host_no
, __func__
));
922 goto exit_get_crash_record
;
925 /* Alloc Memory for Crash Record. */
926 crash_record
= dma_alloc_coherent(&ha
->pdev
->dev
, crash_record_size
,
927 &crash_record_dma
, GFP_KERNEL
);
928 if (crash_record
== NULL
)
929 goto exit_get_crash_record
;
931 /* Get Crash Record. */
932 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
933 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
935 mbox_cmd
[0] = MBOX_CMD_GET_CRASH_RECORD
;
936 mbox_cmd
[2] = LSDW(crash_record_dma
);
937 mbox_cmd
[3] = MSDW(crash_record_dma
);
938 mbox_cmd
[4] = crash_record_size
;
940 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
942 goto exit_get_crash_record
;
944 /* Dump Crash Record. */
946 exit_get_crash_record
:
948 dma_free_coherent(&ha
->pdev
->dev
, crash_record_size
,
949 crash_record
, crash_record_dma
);
953 * qla4xxx_get_conn_event_log - retrieves connection event log
954 * @ha: Pointer to host adapter structure.
956 void qla4xxx_get_conn_event_log(struct scsi_qla_host
* ha
)
958 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
959 uint32_t mbox_sts
[MBOX_REG_COUNT
];
960 struct conn_event_log_entry
*event_log
= NULL
;
961 dma_addr_t event_log_dma
= 0;
962 uint32_t event_log_size
= 0;
963 uint32_t num_valid_entries
;
964 uint32_t oldest_entry
= 0;
965 uint32_t max_event_log_entries
;
968 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
969 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
971 /* Get size of crash record. */
972 mbox_cmd
[0] = MBOX_CMD_GET_CONN_EVENT_LOG
;
974 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
976 goto exit_get_event_log
;
978 event_log_size
= mbox_sts
[4];
979 if (event_log_size
== 0)
980 goto exit_get_event_log
;
982 /* Alloc Memory for Crash Record. */
983 event_log
= dma_alloc_coherent(&ha
->pdev
->dev
, event_log_size
,
984 &event_log_dma
, GFP_KERNEL
);
985 if (event_log
== NULL
)
986 goto exit_get_event_log
;
988 /* Get Crash Record. */
989 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
990 memset(&mbox_sts
, 0, sizeof(mbox_cmd
));
992 mbox_cmd
[0] = MBOX_CMD_GET_CONN_EVENT_LOG
;
993 mbox_cmd
[2] = LSDW(event_log_dma
);
994 mbox_cmd
[3] = MSDW(event_log_dma
);
996 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0], &mbox_sts
[0]) !=
998 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
999 "log!\n", ha
->host_no
, __func__
));
1000 goto exit_get_event_log
;
1003 /* Dump Event Log. */
1004 num_valid_entries
= mbox_sts
[1];
1006 max_event_log_entries
= event_log_size
/
1007 sizeof(struct conn_event_log_entry
);
1009 if (num_valid_entries
> max_event_log_entries
)
1010 oldest_entry
= num_valid_entries
% max_event_log_entries
;
1012 DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
1013 ha
->host_no
, num_valid_entries
));
1015 if (ql4xextended_error_logging
== 3) {
1016 if (oldest_entry
== 0) {
1017 /* Circular Buffer has not wrapped around */
1018 for (i
=0; i
< num_valid_entries
; i
++) {
1019 qla4xxx_dump_buffer((uint8_t *)event_log
+
1020 (i
*sizeof(*event_log
)),
1021 sizeof(*event_log
));
1025 /* Circular Buffer has wrapped around -
1026 * display accordingly*/
1027 for (i
=oldest_entry
; i
< max_event_log_entries
; i
++) {
1028 qla4xxx_dump_buffer((uint8_t *)event_log
+
1029 (i
*sizeof(*event_log
)),
1030 sizeof(*event_log
));
1032 for (i
=0; i
< oldest_entry
; i
++) {
1033 qla4xxx_dump_buffer((uint8_t *)event_log
+
1034 (i
*sizeof(*event_log
)),
1035 sizeof(*event_log
));
1042 dma_free_coherent(&ha
->pdev
->dev
, event_log_size
, event_log
,
1047 * qla4xxx_abort_task - issues Abort Task
1048 * @ha: Pointer to host adapter structure.
1049 * @srb: Pointer to srb entry
1051 * This routine performs a LUN RESET on the specified target/lun.
1052 * The caller must ensure that the ddb_entry and lun_entry pointers
1053 * are valid before calling this routine.
1055 int qla4xxx_abort_task(struct scsi_qla_host
*ha
, struct srb
*srb
)
1057 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1058 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1059 struct scsi_cmnd
*cmd
= srb
->cmd
;
1060 int status
= QLA_SUCCESS
;
1061 unsigned long flags
= 0;
1065 * Send abort task command to ISP, so that the ISP will return
1066 * request with ABORT status
1068 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1069 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1071 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1072 index
= (unsigned long)(unsigned char *)cmd
->host_scribble
;
1073 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1075 /* Firmware already posted completion on response queue */
1076 if (index
== MAX_SRBS
)
1079 mbox_cmd
[0] = MBOX_CMD_ABORT_TASK
;
1080 mbox_cmd
[1] = srb
->ddb
->fw_ddb_index
;
1081 mbox_cmd
[2] = index
;
1082 /* Immediate Command Enable */
1085 qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 5, &mbox_cmd
[0],
1087 if (mbox_sts
[0] != MBOX_STS_COMMAND_COMPLETE
) {
1090 DEBUG2(printk(KERN_WARNING
"scsi%ld:%d:%d: abort task FAILED: "
1091 "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
1092 ha
->host_no
, cmd
->device
->id
, cmd
->device
->lun
, mbox_sts
[0],
1093 mbox_sts
[1], mbox_sts
[2], mbox_sts
[3], mbox_sts
[4]));
1100 * qla4xxx_reset_lun - issues LUN Reset
1101 * @ha: Pointer to host adapter structure.
1102 * @ddb_entry: Pointer to device database entry
1105 * This routine performs a LUN RESET on the specified target/lun.
1106 * The caller must ensure that the ddb_entry and lun_entry pointers
1107 * are valid before calling this routine.
1109 int qla4xxx_reset_lun(struct scsi_qla_host
* ha
, struct ddb_entry
* ddb_entry
,
1112 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1113 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1114 int status
= QLA_SUCCESS
;
1116 DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha
->host_no
,
1117 ddb_entry
->fw_ddb_index
, lun
));
1120 * Send lun reset command to ISP, so that the ISP will return all
1121 * outstanding requests with RESET status
1123 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1124 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1126 mbox_cmd
[0] = MBOX_CMD_LUN_RESET
;
1127 mbox_cmd
[1] = ddb_entry
->fw_ddb_index
;
1128 mbox_cmd
[2] = lun
<< 8;
1129 mbox_cmd
[5] = 0x01; /* Immediate Command Enable */
1131 qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0], &mbox_sts
[0]);
1132 if (mbox_sts
[0] != MBOX_STS_COMMAND_COMPLETE
&&
1133 mbox_sts
[0] != MBOX_STS_COMMAND_ERROR
)
1140 * qla4xxx_reset_target - issues target Reset
1141 * @ha: Pointer to host adapter structure.
1142 * @db_entry: Pointer to device database entry
1143 * @un_entry: Pointer to lun entry structure
1145 * This routine performs a TARGET RESET on the specified target.
1146 * The caller must ensure that the ddb_entry pointers
1147 * are valid before calling this routine.
1149 int qla4xxx_reset_target(struct scsi_qla_host
*ha
,
1150 struct ddb_entry
*ddb_entry
)
1152 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1153 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1154 int status
= QLA_SUCCESS
;
1156 DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha
->host_no
,
1157 ddb_entry
->fw_ddb_index
));
1160 * Send target reset command to ISP, so that the ISP will return all
1161 * outstanding requests with RESET status
1163 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1164 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1166 mbox_cmd
[0] = MBOX_CMD_TARGET_WARM_RESET
;
1167 mbox_cmd
[1] = ddb_entry
->fw_ddb_index
;
1168 mbox_cmd
[5] = 0x01; /* Immediate Command Enable */
1170 qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0],
1172 if (mbox_sts
[0] != MBOX_STS_COMMAND_COMPLETE
&&
1173 mbox_sts
[0] != MBOX_STS_COMMAND_ERROR
)
1179 int qla4xxx_get_flash(struct scsi_qla_host
* ha
, dma_addr_t dma_addr
,
1180 uint32_t offset
, uint32_t len
)
1182 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1183 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1185 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1186 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1188 mbox_cmd
[0] = MBOX_CMD_READ_FLASH
;
1189 mbox_cmd
[1] = LSDW(dma_addr
);
1190 mbox_cmd
[2] = MSDW(dma_addr
);
1191 mbox_cmd
[3] = offset
;
1194 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 2, &mbox_cmd
[0], &mbox_sts
[0]) !=
1196 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
1197 "status %04X %04X, offset %08x, len %08x\n", ha
->host_no
,
1198 __func__
, mbox_sts
[0], mbox_sts
[1], offset
, len
));
1205 * qla4xxx_about_firmware - gets FW, iscsi draft and boot loader version
1206 * @ha: Pointer to host adapter structure.
1208 * Retrieves the FW version, iSCSI draft version & bootloader version of HBA.
1209 * Mailboxes 2 & 3 may hold an address for data. Make sure that we write 0 to
1210 * those mailboxes, if unused.
1212 int qla4xxx_about_firmware(struct scsi_qla_host
*ha
)
1214 struct about_fw_info
*about_fw
= NULL
;
1215 dma_addr_t about_fw_dma
;
1216 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1217 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1218 int status
= QLA_ERROR
;
1220 about_fw
= dma_alloc_coherent(&ha
->pdev
->dev
,
1221 sizeof(struct about_fw_info
),
1222 &about_fw_dma
, GFP_KERNEL
);
1224 DEBUG2(ql4_printk(KERN_ERR
, ha
, "%s: Unable to alloc memory "
1225 "for about_fw\n", __func__
));
1229 memset(about_fw
, 0, sizeof(struct about_fw_info
));
1230 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1231 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1233 mbox_cmd
[0] = MBOX_CMD_ABOUT_FW
;
1234 mbox_cmd
[2] = LSDW(about_fw_dma
);
1235 mbox_cmd
[3] = MSDW(about_fw_dma
);
1236 mbox_cmd
[4] = sizeof(struct about_fw_info
);
1238 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, MBOX_REG_COUNT
,
1239 &mbox_cmd
[0], &mbox_sts
[0]);
1240 if (status
!= QLA_SUCCESS
) {
1241 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_ABOUT_FW "
1242 "failed w/ status %04X\n", __func__
,
1247 /* Save version information. */
1248 ha
->firmware_version
[0] = le16_to_cpu(about_fw
->fw_major
);
1249 ha
->firmware_version
[1] = le16_to_cpu(about_fw
->fw_minor
);
1250 ha
->patch_number
= le16_to_cpu(about_fw
->fw_patch
);
1251 ha
->build_number
= le16_to_cpu(about_fw
->fw_build
);
1252 ha
->iscsi_major
= le16_to_cpu(about_fw
->iscsi_major
);
1253 ha
->iscsi_minor
= le16_to_cpu(about_fw
->iscsi_minor
);
1254 ha
->bootload_major
= le16_to_cpu(about_fw
->bootload_major
);
1255 ha
->bootload_minor
= le16_to_cpu(about_fw
->bootload_minor
);
1256 ha
->bootload_patch
= le16_to_cpu(about_fw
->bootload_patch
);
1257 ha
->bootload_build
= le16_to_cpu(about_fw
->bootload_build
);
1258 status
= QLA_SUCCESS
;
1261 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct about_fw_info
),
1262 about_fw
, about_fw_dma
);
1266 static int qla4xxx_get_default_ddb(struct scsi_qla_host
*ha
, uint32_t options
,
1267 dma_addr_t dma_addr
)
1269 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1270 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1272 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1273 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1275 mbox_cmd
[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS
;
1276 mbox_cmd
[1] = options
;
1277 mbox_cmd
[2] = LSDW(dma_addr
);
1278 mbox_cmd
[3] = MSDW(dma_addr
);
1280 if (qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0], &mbox_sts
[0]) !=
1282 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1283 ha
->host_no
, __func__
, mbox_sts
[0]));
1289 int qla4xxx_req_ddb_entry(struct scsi_qla_host
*ha
, uint32_t ddb_index
,
1293 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1294 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1296 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1297 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1299 mbox_cmd
[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY
;
1300 mbox_cmd
[1] = ddb_index
;
1302 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0],
1304 if (status
!= QLA_SUCCESS
) {
1305 DEBUG2(ql4_printk(KERN_ERR
, ha
, "%s: failed status %04X\n",
1306 __func__
, mbox_sts
[0]));
1309 *mbx_sts
= mbox_sts
[0];
1313 int qla4xxx_clear_ddb_entry(struct scsi_qla_host
*ha
, uint32_t ddb_index
)
1316 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1317 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1319 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1320 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1322 mbox_cmd
[0] = MBOX_CMD_CLEAR_DATABASE_ENTRY
;
1323 mbox_cmd
[1] = ddb_index
;
1325 status
= qla4xxx_mailbox_command(ha
, 2, 1, &mbox_cmd
[0],
1327 if (status
!= QLA_SUCCESS
) {
1328 DEBUG2(ql4_printk(KERN_ERR
, ha
, "%s: failed status %04X\n",
1329 __func__
, mbox_sts
[0]));
1335 int qla4xxx_set_flash(struct scsi_qla_host
*ha
, dma_addr_t dma_addr
,
1336 uint32_t offset
, uint32_t length
, uint32_t options
)
1338 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1339 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1340 int status
= QLA_SUCCESS
;
1342 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1343 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1345 mbox_cmd
[0] = MBOX_CMD_WRITE_FLASH
;
1346 mbox_cmd
[1] = LSDW(dma_addr
);
1347 mbox_cmd
[2] = MSDW(dma_addr
);
1348 mbox_cmd
[3] = offset
;
1349 mbox_cmd
[4] = length
;
1350 mbox_cmd
[5] = options
;
1352 status
= qla4xxx_mailbox_command(ha
, 6, 2, &mbox_cmd
[0], &mbox_sts
[0]);
1353 if (status
!= QLA_SUCCESS
) {
1354 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_WRITE_FLASH "
1355 "failed w/ status %04X, mbx1 %04X\n",
1356 __func__
, mbox_sts
[0], mbox_sts
[1]));
1361 int qla4xxx_bootdb_by_index(struct scsi_qla_host
*ha
,
1362 struct dev_db_entry
*fw_ddb_entry
,
1363 dma_addr_t fw_ddb_entry_dma
, uint16_t ddb_index
)
1365 uint32_t dev_db_start_offset
= FLASH_OFFSET_DB_INFO
;
1366 uint32_t dev_db_end_offset
;
1367 int status
= QLA_ERROR
;
1369 memset(fw_ddb_entry
, 0, sizeof(*fw_ddb_entry
));
1371 dev_db_start_offset
+= (ddb_index
* sizeof(*fw_ddb_entry
));
1372 dev_db_end_offset
= FLASH_OFFSET_DB_END
;
1374 if (dev_db_start_offset
> dev_db_end_offset
) {
1375 DEBUG2(ql4_printk(KERN_ERR
, ha
,
1376 "%s:Invalid DDB index %d", __func__
,
1378 goto exit_bootdb_failed
;
1381 if (qla4xxx_get_flash(ha
, fw_ddb_entry_dma
, dev_db_start_offset
,
1382 sizeof(*fw_ddb_entry
)) != QLA_SUCCESS
) {
1383 ql4_printk(KERN_ERR
, ha
, "scsi%ld: %s: Get Flash"
1384 "failed\n", ha
->host_no
, __func__
);
1385 goto exit_bootdb_failed
;
1388 if (fw_ddb_entry
->cookie
== DDB_VALID_COOKIE
)
1389 status
= QLA_SUCCESS
;
1395 int qla4xxx_get_chap(struct scsi_qla_host
*ha
, char *username
, char *password
,
1399 int rval
= QLA_ERROR
;
1400 uint32_t offset
= 0, chap_size
;
1401 struct ql4_chap_table
*chap_table
;
1402 dma_addr_t chap_dma
;
1404 chap_table
= dma_pool_alloc(ha
->chap_dma_pool
, GFP_KERNEL
, &chap_dma
);
1405 if (chap_table
== NULL
) {
1410 chap_size
= sizeof(struct ql4_chap_table
);
1411 memset(chap_table
, 0, chap_size
);
1414 offset
= FLASH_CHAP_OFFSET
| (idx
* chap_size
);
1416 offset
= FLASH_RAW_ACCESS_ADDR
+ (ha
->hw
.flt_region_chap
<< 2);
1417 /* flt_chap_size is CHAP table size for both ports
1418 * so divide it by 2 to calculate the offset for second port
1420 if (ha
->port_num
== 1)
1421 offset
+= (ha
->hw
.flt_chap_size
/ 2);
1422 offset
+= (idx
* chap_size
);
1425 rval
= qla4xxx_get_flash(ha
, chap_dma
, offset
, chap_size
);
1426 if (rval
!= QLA_SUCCESS
) {
1431 DEBUG2(ql4_printk(KERN_INFO
, ha
, "Chap Cookie: x%x\n",
1432 __le16_to_cpu(chap_table
->cookie
)));
1434 if (__le16_to_cpu(chap_table
->cookie
) != CHAP_VALID_COOKIE
) {
1435 ql4_printk(KERN_ERR
, ha
, "No valid chap entry found\n");
1439 strncpy(password
, chap_table
->secret
, QL4_CHAP_MAX_SECRET_LEN
);
1440 strncpy(username
, chap_table
->name
, QL4_CHAP_MAX_NAME_LEN
);
1441 chap_table
->cookie
= __constant_cpu_to_le16(CHAP_VALID_COOKIE
);
1444 dma_pool_free(ha
->chap_dma_pool
, chap_table
, chap_dma
);
1448 static int qla4xxx_set_chap(struct scsi_qla_host
*ha
, char *username
,
1449 char *password
, uint16_t idx
, int bidi
)
1452 int rval
= QLA_ERROR
;
1453 uint32_t offset
= 0;
1454 struct ql4_chap_table
*chap_table
;
1455 dma_addr_t chap_dma
;
1457 chap_table
= dma_pool_alloc(ha
->chap_dma_pool
, GFP_KERNEL
, &chap_dma
);
1458 if (chap_table
== NULL
) {
1463 memset(chap_table
, 0, sizeof(struct ql4_chap_table
));
1465 chap_table
->flags
|= BIT_6
; /* peer */
1467 chap_table
->flags
|= BIT_7
; /* local */
1468 chap_table
->secret_len
= strlen(password
);
1469 strncpy(chap_table
->secret
, password
, MAX_CHAP_SECRET_LEN
);
1470 strncpy(chap_table
->name
, username
, MAX_CHAP_NAME_LEN
);
1471 chap_table
->cookie
= __constant_cpu_to_le16(CHAP_VALID_COOKIE
);
1472 offset
= FLASH_CHAP_OFFSET
| (idx
* sizeof(struct ql4_chap_table
));
1473 rval
= qla4xxx_set_flash(ha
, chap_dma
, offset
,
1474 sizeof(struct ql4_chap_table
),
1475 FLASH_OPT_RMW_COMMIT
);
1477 if (rval
== QLA_SUCCESS
&& ha
->chap_list
) {
1478 /* Update ha chap_list cache */
1479 memcpy((struct ql4_chap_table
*)ha
->chap_list
+ idx
,
1480 chap_table
, sizeof(struct ql4_chap_table
));
1482 dma_pool_free(ha
->chap_dma_pool
, chap_table
, chap_dma
);
1483 if (rval
!= QLA_SUCCESS
)
1491 * qla4xxx_get_chap_index - Get chap index given username and secret
1492 * @ha: pointer to adapter structure
1493 * @username: CHAP username to be searched
1494 * @password: CHAP password to be searched
1495 * @bidi: Is this a BIDI CHAP
1496 * @chap_index: CHAP index to be returned
1498 * Match the username and password in the chap_list, return the index if a
1499 * match is found. If a match is not found then add the entry in FLASH and
1500 * return the index at which entry is written in the FLASH.
1502 int qla4xxx_get_chap_index(struct scsi_qla_host
*ha
, char *username
,
1503 char *password
, int bidi
, uint16_t *chap_index
)
1506 int free_index
= -1;
1507 int found_index
= 0;
1508 int max_chap_entries
= 0;
1509 struct ql4_chap_table
*chap_table
;
1512 max_chap_entries
= (ha
->hw
.flt_chap_size
/ 2) /
1513 sizeof(struct ql4_chap_table
);
1515 max_chap_entries
= MAX_CHAP_ENTRIES_40XX
;
1517 if (!ha
->chap_list
) {
1518 ql4_printk(KERN_ERR
, ha
, "Do not have CHAP table cache\n");
1522 if (!username
|| !password
) {
1523 ql4_printk(KERN_ERR
, ha
, "Do not have username and psw\n");
1527 mutex_lock(&ha
->chap_sem
);
1528 for (i
= 0; i
< max_chap_entries
; i
++) {
1529 chap_table
= (struct ql4_chap_table
*)ha
->chap_list
+ i
;
1530 if (chap_table
->cookie
!=
1531 __constant_cpu_to_le16(CHAP_VALID_COOKIE
)) {
1532 if (i
> MAX_RESRV_CHAP_IDX
&& free_index
== -1)
1537 if (chap_table
->flags
& BIT_7
)
1540 if (chap_table
->flags
& BIT_6
)
1543 if (!strncmp(chap_table
->secret
, password
,
1544 MAX_CHAP_SECRET_LEN
) &&
1545 !strncmp(chap_table
->name
, username
,
1546 MAX_CHAP_NAME_LEN
)) {
1553 /* If chap entry is not present and a free index is available then
1554 * write the entry in flash
1556 if (!found_index
&& free_index
!= -1) {
1557 rval
= qla4xxx_set_chap(ha
, username
, password
,
1560 *chap_index
= free_index
;
1565 mutex_unlock(&ha
->chap_sem
);
1572 int qla4xxx_conn_close_sess_logout(struct scsi_qla_host
*ha
,
1573 uint16_t fw_ddb_index
,
1574 uint16_t connection_id
,
1577 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1578 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1579 int status
= QLA_SUCCESS
;
1581 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1582 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1584 mbox_cmd
[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT
;
1585 mbox_cmd
[1] = fw_ddb_index
;
1586 mbox_cmd
[2] = connection_id
;
1587 mbox_cmd
[3] = option
;
1589 status
= qla4xxx_mailbox_command(ha
, 4, 2, &mbox_cmd
[0], &mbox_sts
[0]);
1590 if (status
!= QLA_SUCCESS
) {
1591 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_CONN_CLOSE "
1592 "option %04x failed w/ status %04X %04X\n",
1593 __func__
, option
, mbox_sts
[0], mbox_sts
[1]));
1598 int qla4xxx_disable_acb(struct scsi_qla_host
*ha
)
1600 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1601 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1602 int status
= QLA_SUCCESS
;
1604 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1605 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1607 mbox_cmd
[0] = MBOX_CMD_DISABLE_ACB
;
1609 status
= qla4xxx_mailbox_command(ha
, 8, 5, &mbox_cmd
[0], &mbox_sts
[0]);
1610 if (status
!= QLA_SUCCESS
) {
1611 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_DISABLE_ACB "
1612 "failed w/ status %04X %04X %04X", __func__
,
1613 mbox_sts
[0], mbox_sts
[1], mbox_sts
[2]));
1618 int qla4xxx_get_acb(struct scsi_qla_host
*ha
, dma_addr_t acb_dma
,
1619 uint32_t acb_type
, uint32_t len
)
1621 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1622 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1623 int status
= QLA_SUCCESS
;
1625 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1626 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1628 mbox_cmd
[0] = MBOX_CMD_GET_ACB
;
1629 mbox_cmd
[1] = acb_type
;
1630 mbox_cmd
[2] = LSDW(acb_dma
);
1631 mbox_cmd
[3] = MSDW(acb_dma
);
1634 status
= qla4xxx_mailbox_command(ha
, 5, 5, &mbox_cmd
[0], &mbox_sts
[0]);
1635 if (status
!= QLA_SUCCESS
) {
1636 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_GET_ACB "
1637 "failed w/ status %04X\n", __func__
,
1643 int qla4xxx_set_acb(struct scsi_qla_host
*ha
, uint32_t *mbox_cmd
,
1644 uint32_t *mbox_sts
, dma_addr_t acb_dma
)
1646 int status
= QLA_SUCCESS
;
1648 memset(mbox_cmd
, 0, sizeof(mbox_cmd
[0]) * MBOX_REG_COUNT
);
1649 memset(mbox_sts
, 0, sizeof(mbox_sts
[0]) * MBOX_REG_COUNT
);
1650 mbox_cmd
[0] = MBOX_CMD_SET_ACB
;
1651 mbox_cmd
[1] = 0; /* Primary ACB */
1652 mbox_cmd
[2] = LSDW(acb_dma
);
1653 mbox_cmd
[3] = MSDW(acb_dma
);
1654 mbox_cmd
[4] = sizeof(struct addr_ctrl_blk
);
1656 status
= qla4xxx_mailbox_command(ha
, 5, 5, &mbox_cmd
[0], &mbox_sts
[0]);
1657 if (status
!= QLA_SUCCESS
) {
1658 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: MBOX_CMD_SET_ACB "
1659 "failed w/ status %04X\n", __func__
,
1665 int qla4xxx_set_param_ddbentry(struct scsi_qla_host
*ha
,
1666 struct ddb_entry
*ddb_entry
,
1667 struct iscsi_cls_conn
*cls_conn
,
1670 struct dev_db_entry
*fw_ddb_entry
;
1671 struct iscsi_conn
*conn
;
1672 struct iscsi_session
*sess
;
1673 struct qla_conn
*qla_conn
;
1674 struct sockaddr
*dst_addr
;
1675 dma_addr_t fw_ddb_entry_dma
;
1676 int status
= QLA_SUCCESS
;
1678 struct sockaddr_in
*addr
;
1679 struct sockaddr_in6
*addr6
;
1681 uint16_t iscsi_opts
= 0;
1682 uint32_t options
= 0;
1683 uint16_t idx
, *ptid
;
1685 fw_ddb_entry
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
1686 &fw_ddb_entry_dma
, GFP_KERNEL
);
1687 if (!fw_ddb_entry
) {
1688 DEBUG2(ql4_printk(KERN_ERR
, ha
,
1689 "%s: Unable to allocate dma buffer.\n",
1692 goto exit_set_param_no_free
;
1695 conn
= cls_conn
->dd_data
;
1696 qla_conn
= conn
->dd_data
;
1697 sess
= conn
->session
;
1698 dst_addr
= &qla_conn
->qla_ep
->dst_addr
;
1700 if (dst_addr
->sa_family
== AF_INET6
)
1701 options
|= IPV6_DEFAULT_DDB_ENTRY
;
1703 status
= qla4xxx_get_default_ddb(ha
, options
, fw_ddb_entry_dma
);
1704 if (status
== QLA_ERROR
) {
1706 goto exit_set_param
;
1709 ptid
= (uint16_t *)&fw_ddb_entry
->isid
[1];
1710 *ptid
= cpu_to_le16((uint16_t)ddb_entry
->sess
->target_id
);
1712 DEBUG2(ql4_printk(KERN_INFO
, ha
, "ISID [%02x%02x%02x%02x%02x%02x]\n",
1713 fw_ddb_entry
->isid
[5], fw_ddb_entry
->isid
[4],
1714 fw_ddb_entry
->isid
[3], fw_ddb_entry
->isid
[2],
1715 fw_ddb_entry
->isid
[1], fw_ddb_entry
->isid
[0]));
1717 iscsi_opts
= le16_to_cpu(fw_ddb_entry
->iscsi_options
);
1718 memset(fw_ddb_entry
->iscsi_alias
, 0, sizeof(fw_ddb_entry
->iscsi_alias
));
1720 memset(fw_ddb_entry
->iscsi_name
, 0, sizeof(fw_ddb_entry
->iscsi_name
));
1722 if (sess
->targetname
!= NULL
) {
1723 memcpy(fw_ddb_entry
->iscsi_name
, sess
->targetname
,
1724 min(strlen(sess
->targetname
),
1725 sizeof(fw_ddb_entry
->iscsi_name
)));
1728 memset(fw_ddb_entry
->ip_addr
, 0, sizeof(fw_ddb_entry
->ip_addr
));
1729 memset(fw_ddb_entry
->tgt_addr
, 0, sizeof(fw_ddb_entry
->tgt_addr
));
1731 fw_ddb_entry
->options
= DDB_OPT_TARGET
| DDB_OPT_AUTO_SENDTGTS_DISABLE
;
1733 if (dst_addr
->sa_family
== AF_INET
) {
1734 addr
= (struct sockaddr_in
*)dst_addr
;
1735 ip
= (char *)&addr
->sin_addr
;
1736 memcpy(fw_ddb_entry
->ip_addr
, ip
, IP_ADDR_LEN
);
1737 fw_ddb_entry
->port
= cpu_to_le16(ntohs(addr
->sin_port
));
1738 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1739 "%s: Destination Address [%pI4]: index [%d]\n",
1740 __func__
, fw_ddb_entry
->ip_addr
,
1741 ddb_entry
->fw_ddb_index
));
1742 } else if (dst_addr
->sa_family
== AF_INET6
) {
1743 addr6
= (struct sockaddr_in6
*)dst_addr
;
1744 ip
= (char *)&addr6
->sin6_addr
;
1745 memcpy(fw_ddb_entry
->ip_addr
, ip
, IPv6_ADDR_LEN
);
1746 fw_ddb_entry
->port
= cpu_to_le16(ntohs(addr6
->sin6_port
));
1747 fw_ddb_entry
->options
|= DDB_OPT_IPV6_DEVICE
;
1748 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1749 "%s: Destination Address [%pI6]: index [%d]\n",
1750 __func__
, fw_ddb_entry
->ip_addr
,
1751 ddb_entry
->fw_ddb_index
));
1753 ql4_printk(KERN_ERR
, ha
,
1754 "%s: Failed to get IP Address\n",
1757 goto exit_set_param
;
1761 if (sess
->username
!= NULL
&& sess
->password
!= NULL
) {
1762 if (strlen(sess
->username
) && strlen(sess
->password
)) {
1763 iscsi_opts
|= BIT_7
;
1765 rval
= qla4xxx_get_chap_index(ha
, sess
->username
,
1769 goto exit_set_param
;
1771 fw_ddb_entry
->chap_tbl_idx
= cpu_to_le16(idx
);
1775 if (sess
->username_in
!= NULL
&& sess
->password_in
!= NULL
) {
1776 /* Check if BIDI CHAP */
1777 if (strlen(sess
->username_in
) && strlen(sess
->password_in
)) {
1778 iscsi_opts
|= BIT_4
;
1780 rval
= qla4xxx_get_chap_index(ha
, sess
->username_in
,
1784 goto exit_set_param
;
1788 if (sess
->initial_r2t_en
)
1789 iscsi_opts
|= BIT_10
;
1791 if (sess
->imm_data_en
)
1792 iscsi_opts
|= BIT_11
;
1794 fw_ddb_entry
->iscsi_options
= cpu_to_le16(iscsi_opts
);
1796 if (conn
->max_recv_dlength
)
1797 fw_ddb_entry
->iscsi_max_rcv_data_seg_len
=
1798 __constant_cpu_to_le16((conn
->max_recv_dlength
/ BYTE_UNITS
));
1801 fw_ddb_entry
->iscsi_max_outsnd_r2t
= cpu_to_le16(sess
->max_r2t
);
1803 if (sess
->first_burst
)
1804 fw_ddb_entry
->iscsi_first_burst_len
=
1805 __constant_cpu_to_le16((sess
->first_burst
/ BYTE_UNITS
));
1807 if (sess
->max_burst
)
1808 fw_ddb_entry
->iscsi_max_burst_len
=
1809 __constant_cpu_to_le16((sess
->max_burst
/ BYTE_UNITS
));
1811 if (sess
->time2wait
)
1812 fw_ddb_entry
->iscsi_def_time2wait
=
1813 cpu_to_le16(sess
->time2wait
);
1815 if (sess
->time2retain
)
1816 fw_ddb_entry
->iscsi_def_time2retain
=
1817 cpu_to_le16(sess
->time2retain
);
1819 status
= qla4xxx_set_ddb_entry(ha
, ddb_entry
->fw_ddb_index
,
1820 fw_ddb_entry_dma
, mbx_sts
);
1822 if (status
!= QLA_SUCCESS
)
1825 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*fw_ddb_entry
),
1826 fw_ddb_entry
, fw_ddb_entry_dma
);
1827 exit_set_param_no_free
:
1831 int qla4xxx_get_mgmt_data(struct scsi_qla_host
*ha
, uint16_t fw_ddb_index
,
1832 uint16_t stats_size
, dma_addr_t stats_dma
)
1834 int status
= QLA_SUCCESS
;
1835 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1836 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1838 memset(mbox_cmd
, 0, sizeof(mbox_cmd
[0]) * MBOX_REG_COUNT
);
1839 memset(mbox_sts
, 0, sizeof(mbox_sts
[0]) * MBOX_REG_COUNT
);
1840 mbox_cmd
[0] = MBOX_CMD_GET_MANAGEMENT_DATA
;
1841 mbox_cmd
[1] = fw_ddb_index
;
1842 mbox_cmd
[2] = LSDW(stats_dma
);
1843 mbox_cmd
[3] = MSDW(stats_dma
);
1844 mbox_cmd
[4] = stats_size
;
1846 status
= qla4xxx_mailbox_command(ha
, 5, 1, &mbox_cmd
[0], &mbox_sts
[0]);
1847 if (status
!= QLA_SUCCESS
) {
1848 DEBUG2(ql4_printk(KERN_WARNING
, ha
,
1849 "%s: MBOX_CMD_GET_MANAGEMENT_DATA "
1850 "failed w/ status %04X\n", __func__
,
1856 int qla4xxx_get_ip_state(struct scsi_qla_host
*ha
, uint32_t acb_idx
,
1857 uint32_t ip_idx
, uint32_t *sts
)
1859 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1860 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1861 int status
= QLA_SUCCESS
;
1863 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1864 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1865 mbox_cmd
[0] = MBOX_CMD_GET_IP_ADDR_STATE
;
1866 mbox_cmd
[1] = acb_idx
;
1867 mbox_cmd
[2] = ip_idx
;
1869 status
= qla4xxx_mailbox_command(ha
, 3, 8, &mbox_cmd
[0], &mbox_sts
[0]);
1870 if (status
!= QLA_SUCCESS
) {
1871 DEBUG2(ql4_printk(KERN_WARNING
, ha
, "%s: "
1872 "MBOX_CMD_GET_IP_ADDR_STATE failed w/ "
1873 "status %04X\n", __func__
, mbox_sts
[0]));
1875 memcpy(sts
, mbox_sts
, sizeof(mbox_sts
));
1879 int qla4xxx_get_nvram(struct scsi_qla_host
*ha
, dma_addr_t nvram_dma
,
1880 uint32_t offset
, uint32_t size
)
1882 int status
= QLA_SUCCESS
;
1883 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1884 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1886 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1887 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1889 mbox_cmd
[0] = MBOX_CMD_GET_NVRAM
;
1890 mbox_cmd
[1] = LSDW(nvram_dma
);
1891 mbox_cmd
[2] = MSDW(nvram_dma
);
1892 mbox_cmd
[3] = offset
;
1895 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0],
1897 if (status
!= QLA_SUCCESS
) {
1898 DEBUG2(ql4_printk(KERN_ERR
, ha
, "scsi%ld: %s: failed "
1899 "status %04X\n", ha
->host_no
, __func__
,
1905 int qla4xxx_set_nvram(struct scsi_qla_host
*ha
, dma_addr_t nvram_dma
,
1906 uint32_t offset
, uint32_t size
)
1908 int status
= QLA_SUCCESS
;
1909 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1910 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1912 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1913 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1915 mbox_cmd
[0] = MBOX_CMD_SET_NVRAM
;
1916 mbox_cmd
[1] = LSDW(nvram_dma
);
1917 mbox_cmd
[2] = MSDW(nvram_dma
);
1918 mbox_cmd
[3] = offset
;
1921 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 1, &mbox_cmd
[0],
1923 if (status
!= QLA_SUCCESS
) {
1924 DEBUG2(ql4_printk(KERN_ERR
, ha
, "scsi%ld: %s: failed "
1925 "status %04X\n", ha
->host_no
, __func__
,
1931 int qla4xxx_restore_factory_defaults(struct scsi_qla_host
*ha
,
1932 uint32_t region
, uint32_t field0
,
1935 int status
= QLA_SUCCESS
;
1936 uint32_t mbox_cmd
[MBOX_REG_COUNT
];
1937 uint32_t mbox_sts
[MBOX_REG_COUNT
];
1939 memset(&mbox_cmd
, 0, sizeof(mbox_cmd
));
1940 memset(&mbox_sts
, 0, sizeof(mbox_sts
));
1942 mbox_cmd
[0] = MBOX_CMD_RESTORE_FACTORY_DEFAULTS
;
1943 mbox_cmd
[3] = region
;
1944 mbox_cmd
[4] = field0
;
1945 mbox_cmd
[5] = field1
;
1947 status
= qla4xxx_mailbox_command(ha
, MBOX_REG_COUNT
, 3, &mbox_cmd
[0],
1949 if (status
!= QLA_SUCCESS
) {
1950 DEBUG2(ql4_printk(KERN_ERR
, ha
, "scsi%ld: %s: failed "
1951 "status %04X\n", ha
->host_no
, __func__
,