2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2010 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
11 #include "ql4_inline.h"
15 * qla4xxx_mailbox_command - issues mailbox commands
16 * @ha: Pointer to host adapter structure.
17 * @inCount: number of mailbox registers to load.
18 * @outCount: number of mailbox registers to return.
19 * @mbx_cmd: data pointer for mailbox in registers.
20 * @mbx_sts: data pointer for mailbox out registers.
22 * This routine issue mailbox commands and waits for completion.
23 * If outCount is 0, this routine completes successfully WITHOUT waiting
24 * for the mailbox command to complete.
26 int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
27 uint8_t outCount, uint32_t *mbx_cmd,
30 int status = QLA_ERROR;
34 unsigned long flags = 0;
37 /* Make sure that pointers are valid */
38 if (!mbx_cmd || !mbx_sts) {
39 DEBUG2(printk("scsi%ld: %s: Invalid mbx_cmd or mbx_sts "
40 "pointer\n", ha->host_no, __func__));
45 if (test_bit(AF_FW_RECOVERY, &ha->flags)) {
46 DEBUG2(ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: "
47 "prematurely completing mbx cmd as firmware "
48 "recovery detected\n", ha->host_no, __func__));
51 /* Do not send any mbx cmd if h/w is in failed state*/
52 qla4_8xxx_idc_lock(ha);
53 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
54 qla4_8xxx_idc_unlock(ha);
55 if (dev_state == QLA82XX_DEV_FAILED) {
56 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: H/W is in "
57 "failed state, do not send any mailbox commands\n",
58 ha->host_no, __func__);
63 if ((is_aer_supported(ha)) &&
64 (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))) {
65 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Perm failure on EEH, "
66 "timeout MBX Exiting.\n", ha->host_no, __func__));
70 /* Mailbox code active */
71 wait_count = MBOX_TOV * 100;
73 while (wait_count--) {
74 mutex_lock(&ha->mbox_sem);
75 if (!test_bit(AF_MBOX_COMMAND, &ha->flags)) {
76 set_bit(AF_MBOX_COMMAND, &ha->flags);
77 mutex_unlock(&ha->mbox_sem);
80 mutex_unlock(&ha->mbox_sem);
82 DEBUG2(printk("scsi%ld: %s: mbox_sem failed\n",
83 ha->host_no, __func__));
89 spin_lock_irqsave(&ha->hardware_lock, flags);
91 ha->mbox_status_count = outCount;
92 for (i = 0; i < outCount; i++)
93 ha->mbox_status[i] = 0;
96 /* Load all mailbox registers, except mailbox 0. */
98 printk("scsi%ld: %s: Cmd ", ha->host_no, __func__);
99 for (i = 0; i < inCount; i++)
100 printk("mb%d=%04x ", i, mbx_cmd[i]);
103 for (i = 1; i < inCount; i++)
104 writel(mbx_cmd[i], &ha->qla4_8xxx_reg->mailbox_in[i]);
105 writel(mbx_cmd[0], &ha->qla4_8xxx_reg->mailbox_in[0]);
106 readl(&ha->qla4_8xxx_reg->mailbox_in[0]);
107 writel(HINT_MBX_INT_PENDING, &ha->qla4_8xxx_reg->hint);
109 /* Load all mailbox registers, except mailbox 0. */
110 for (i = 1; i < inCount; i++)
111 writel(mbx_cmd[i], &ha->reg->mailbox[i]);
113 /* Wakeup firmware */
114 writel(mbx_cmd[0], &ha->reg->mailbox[0]);
115 readl(&ha->reg->mailbox[0]);
116 writel(set_rmask(CSR_INTR_RISC), &ha->reg->ctrl_status);
117 readl(&ha->reg->ctrl_status);
120 spin_unlock_irqrestore(&ha->hardware_lock, flags);
122 /* Wait for completion */
125 * If we don't want status, don't wait for the mailbox command to
126 * complete. For example, MBOX_CMD_RESET_FW doesn't return status,
127 * you must poll the inbound Interrupt Mask for completion.
130 status = QLA_SUCCESS;
135 * Wait for completion: Poll or completion queue
137 if (test_bit(AF_IRQ_ATTACHED, &ha->flags) &&
138 test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
139 test_bit(AF_ONLINE, &ha->flags) &&
140 !test_bit(AF_HA_REMOVAL, &ha->flags)) {
141 /* Do not poll for completion. Use completion queue */
142 set_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
143 wait_for_completion_timeout(&ha->mbx_intr_comp, MBOX_TOV * HZ);
144 clear_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
146 /* Poll for command to complete */
147 wait_count = jiffies + MBOX_TOV * HZ;
148 while (test_bit(AF_MBOX_COMMAND_DONE, &ha->flags) == 0) {
149 if (time_after_eq(jiffies, wait_count))
153 * Service the interrupt.
154 * The ISR will save the mailbox status registers
155 * to a temporary storage location in the adapter
159 spin_lock_irqsave(&ha->hardware_lock, flags);
160 if (is_qla8022(ha)) {
162 readl(&ha->qla4_8xxx_reg->host_int);
163 if (intr_status & ISRX_82XX_RISC_INT) {
164 ha->mbox_status_count = outCount;
166 readl(&ha->qla4_8xxx_reg->host_status);
167 ha->isp_ops->interrupt_service_routine(
169 if (test_bit(AF_INTERRUPTS_ON,
171 test_bit(AF_INTx_ENABLED,
174 ha->nx_legacy_intr.tgt_mask_reg,
178 intr_status = readl(&ha->reg->ctrl_status);
179 if (intr_status & INTR_PENDING) {
181 * Service the interrupt.
182 * The ISR will save the mailbox status
183 * registers to a temporary storage
184 * location in the adapter structure.
186 ha->mbox_status_count = outCount;
187 ha->isp_ops->interrupt_service_routine(
191 spin_unlock_irqrestore(&ha->hardware_lock, flags);
196 /* Check for mailbox timeout. */
197 if (!test_bit(AF_MBOX_COMMAND_DONE, &ha->flags)) {
198 if (is_qla8022(ha) &&
199 test_bit(AF_FW_RECOVERY, &ha->flags)) {
200 DEBUG2(ql4_printk(KERN_INFO, ha,
201 "scsi%ld: %s: prematurely completing mbx cmd as "
202 "firmware recovery detected\n",
203 ha->host_no, __func__));
206 DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
207 " Scheduling Adapter Reset\n", ha->host_no,
209 ha->mailbox_timeout_count++;
211 set_bit(DPC_RESET_HA, &ha->dpc_flags);
216 * Copy the mailbox out registers to the caller's mailbox in/out
219 spin_lock_irqsave(&ha->hardware_lock, flags);
220 for (i = 0; i < outCount; i++)
221 mbx_sts[i] = ha->mbox_status[i];
223 /* Set return status and error flags (if applicable). */
224 switch (ha->mbox_status[0]) {
225 case MBOX_STS_COMMAND_COMPLETE:
226 status = QLA_SUCCESS;
229 case MBOX_STS_INTERMEDIATE_COMPLETION:
230 status = QLA_SUCCESS;
234 DEBUG2( printk("scsi%ld: %s: Cmd = %08X, ISP BUSY\n",
235 ha->host_no, __func__, mbx_cmd[0]));
236 ha->mailbox_timeout_count++;
240 DEBUG2(printk("scsi%ld: %s: **** FAILED, cmd = %08X, "
241 "sts = %08X ****\n", ha->host_no, __func__,
242 mbx_cmd[0], mbx_sts[0]));
245 spin_unlock_irqrestore(&ha->hardware_lock, flags);
248 mutex_lock(&ha->mbox_sem);
249 clear_bit(AF_MBOX_COMMAND, &ha->flags);
250 mutex_unlock(&ha->mbox_sem);
251 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
256 void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha)
258 set_bit(AF_FW_RECOVERY, &ha->flags);
259 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: set FW RECOVERY!\n",
260 ha->host_no, __func__);
262 if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
263 if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags)) {
264 complete(&ha->mbx_intr_comp);
265 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
266 "recovery, doing premature completion of "
267 "mbx cmd\n", ha->host_no, __func__);
270 set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
271 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
272 "recovery, doing premature completion of "
273 "polling mbx cmd\n", ha->host_no, __func__);
279 qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
280 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
282 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
283 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
286 qla4_8xxx_wr_32(ha, ha->nx_db_wr_ptr, 0);
288 mbox_cmd[0] = MBOX_CMD_INITIALIZE_FIRMWARE;
290 mbox_cmd[2] = LSDW(init_fw_cb_dma);
291 mbox_cmd[3] = MSDW(init_fw_cb_dma);
292 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
293 mbox_cmd[5] = (IFCB_VER_MAX << 8) | IFCB_VER_MIN;
295 if (qla4xxx_mailbox_command(ha, 6, 6, mbox_cmd, mbox_sts) !=
297 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
298 "MBOX_CMD_INITIALIZE_FIRMWARE"
299 " failed w/ status %04X\n",
300 ha->host_no, __func__, mbox_sts[0]));
307 qla4xxx_get_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
308 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
310 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
311 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
312 mbox_cmd[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK;
313 mbox_cmd[2] = LSDW(init_fw_cb_dma);
314 mbox_cmd[3] = MSDW(init_fw_cb_dma);
315 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
317 if (qla4xxx_mailbox_command(ha, 5, 5, mbox_cmd, mbox_sts) !=
319 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
320 "MBOX_CMD_GET_INIT_FW_CTRL_BLOCK"
321 " failed w/ status %04X\n",
322 ha->host_no, __func__, mbox_sts[0]));
329 qla4xxx_update_local_ip(struct scsi_qla_host *ha,
330 struct addr_ctrl_blk *init_fw_cb)
332 ha->ip_config.tcp_options = le16_to_cpu(init_fw_cb->ipv4_tcp_opts);
333 ha->ip_config.ipv4_options = le16_to_cpu(init_fw_cb->ipv4_ip_opts);
334 ha->ip_config.ipv4_addr_state =
335 le16_to_cpu(init_fw_cb->ipv4_addr_state);
336 ha->ip_config.eth_mtu_size =
337 le16_to_cpu(init_fw_cb->eth_mtu_size);
339 if (ha->acb_version == ACB_SUPPORTED) {
340 ha->ip_config.ipv6_options = le16_to_cpu(init_fw_cb->ipv6_opts);
341 ha->ip_config.ipv6_addl_options =
342 le16_to_cpu(init_fw_cb->ipv6_addtl_opts);
345 /* Save IPv4 Address Info */
346 memcpy(ha->ip_config.ip_address, init_fw_cb->ipv4_addr,
347 min(sizeof(ha->ip_config.ip_address),
348 sizeof(init_fw_cb->ipv4_addr)));
349 memcpy(ha->ip_config.subnet_mask, init_fw_cb->ipv4_subnet,
350 min(sizeof(ha->ip_config.subnet_mask),
351 sizeof(init_fw_cb->ipv4_subnet)));
352 memcpy(ha->ip_config.gateway, init_fw_cb->ipv4_gw_addr,
353 min(sizeof(ha->ip_config.gateway),
354 sizeof(init_fw_cb->ipv4_gw_addr)));
356 ha->ip_config.ipv4_vlan_tag = be16_to_cpu(init_fw_cb->ipv4_vlan_tag);
358 if (is_ipv6_enabled(ha)) {
359 /* Save IPv6 Address */
360 ha->ip_config.ipv6_link_local_state =
361 le16_to_cpu(init_fw_cb->ipv6_lnk_lcl_addr_state);
362 ha->ip_config.ipv6_addr0_state =
363 le16_to_cpu(init_fw_cb->ipv6_addr0_state);
364 ha->ip_config.ipv6_addr1_state =
365 le16_to_cpu(init_fw_cb->ipv6_addr1_state);
366 ha->ip_config.ipv6_default_router_state =
367 le16_to_cpu(init_fw_cb->ipv6_dflt_rtr_state);
368 ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[0] = 0xFE;
369 ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[1] = 0x80;
371 memcpy(&ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[8],
372 init_fw_cb->ipv6_if_id,
373 min(sizeof(ha->ip_config.ipv6_link_local_addr)/2,
374 sizeof(init_fw_cb->ipv6_if_id)));
375 memcpy(&ha->ip_config.ipv6_addr0, init_fw_cb->ipv6_addr0,
376 min(sizeof(ha->ip_config.ipv6_addr0),
377 sizeof(init_fw_cb->ipv6_addr0)));
378 memcpy(&ha->ip_config.ipv6_addr1, init_fw_cb->ipv6_addr1,
379 min(sizeof(ha->ip_config.ipv6_addr1),
380 sizeof(init_fw_cb->ipv6_addr1)));
381 memcpy(&ha->ip_config.ipv6_default_router_addr,
382 init_fw_cb->ipv6_dflt_rtr_addr,
383 min(sizeof(ha->ip_config.ipv6_default_router_addr),
384 sizeof(init_fw_cb->ipv6_dflt_rtr_addr)));
385 ha->ip_config.ipv6_vlan_tag =
386 be16_to_cpu(init_fw_cb->ipv6_vlan_tag);
391 qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
394 struct addr_ctrl_blk *init_fw_cb,
395 dma_addr_t init_fw_cb_dma)
397 if (qla4xxx_get_ifcb(ha, mbox_cmd, mbox_sts, init_fw_cb_dma)
399 DEBUG2(printk(KERN_WARNING
400 "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
401 ha->host_no, __func__));
405 DEBUG2(qla4xxx_dump_buffer(init_fw_cb, sizeof(struct addr_ctrl_blk)));
407 /* Save some info in adapter structure. */
408 ha->acb_version = init_fw_cb->acb_version;
409 ha->firmware_options = le16_to_cpu(init_fw_cb->fw_options);
410 ha->heartbeat_interval = init_fw_cb->hb_interval;
411 memcpy(ha->name_string, init_fw_cb->iscsi_name,
412 min(sizeof(ha->name_string),
413 sizeof(init_fw_cb->iscsi_name)));
414 /*memcpy(ha->alias, init_fw_cb->Alias,
415 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
417 qla4xxx_update_local_ip(ha, init_fw_cb);
423 * qla4xxx_initialize_fw_cb - initializes firmware control block.
424 * @ha: Pointer to host adapter structure.
426 int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
428 struct addr_ctrl_blk *init_fw_cb;
429 dma_addr_t init_fw_cb_dma;
430 uint32_t mbox_cmd[MBOX_REG_COUNT];
431 uint32_t mbox_sts[MBOX_REG_COUNT];
432 int status = QLA_ERROR;
434 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
435 sizeof(struct addr_ctrl_blk),
436 &init_fw_cb_dma, GFP_KERNEL);
437 if (init_fw_cb == NULL) {
438 DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
439 ha->host_no, __func__));
440 goto exit_init_fw_cb_no_free;
442 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
444 /* Get Initialize Firmware Control Block. */
445 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
446 memset(&mbox_sts, 0, sizeof(mbox_sts));
448 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
450 dma_free_coherent(&ha->pdev->dev,
451 sizeof(struct addr_ctrl_blk),
452 init_fw_cb, init_fw_cb_dma);
453 goto exit_init_fw_cb;
456 /* Initialize request and response queues. */
457 qla4xxx_init_rings(ha);
459 /* Fill in the request and response queue information. */
460 init_fw_cb->rqq_consumer_idx = cpu_to_le16(ha->request_out);
461 init_fw_cb->compq_producer_idx = cpu_to_le16(ha->response_in);
462 init_fw_cb->rqq_len = __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH);
463 init_fw_cb->compq_len = __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH);
464 init_fw_cb->rqq_addr_lo = cpu_to_le32(LSDW(ha->request_dma));
465 init_fw_cb->rqq_addr_hi = cpu_to_le32(MSDW(ha->request_dma));
466 init_fw_cb->compq_addr_lo = cpu_to_le32(LSDW(ha->response_dma));
467 init_fw_cb->compq_addr_hi = cpu_to_le32(MSDW(ha->response_dma));
468 init_fw_cb->shdwreg_addr_lo = cpu_to_le32(LSDW(ha->shadow_regs_dma));
469 init_fw_cb->shdwreg_addr_hi = cpu_to_le32(MSDW(ha->shadow_regs_dma));
471 /* Set up required options. */
472 init_fw_cb->fw_options |=
473 __constant_cpu_to_le16(FWOPT_SESSION_MODE |
474 FWOPT_INITIATOR_MODE);
477 init_fw_cb->fw_options |=
478 __constant_cpu_to_le16(FWOPT_ENABLE_CRBDB);
480 init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
482 init_fw_cb->add_fw_options = 0;
483 init_fw_cb->add_fw_options |=
484 __constant_cpu_to_le16(ADFWOPT_SERIALIZE_TASK_MGMT);
485 init_fw_cb->add_fw_options |=
486 __constant_cpu_to_le16(ADFWOPT_AUTOCONN_DISABLE);
488 if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
490 DEBUG2(printk(KERN_WARNING
491 "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
492 ha->host_no, __func__));
493 goto exit_init_fw_cb;
496 if (qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0],
497 init_fw_cb, init_fw_cb_dma) != QLA_SUCCESS) {
498 DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
499 ha->host_no, __func__));
500 goto exit_init_fw_cb;
502 status = QLA_SUCCESS;
505 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
506 init_fw_cb, init_fw_cb_dma);
507 exit_init_fw_cb_no_free:
512 * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
513 * @ha: Pointer to host adapter structure.
515 int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host * ha)
517 struct addr_ctrl_blk *init_fw_cb;
518 dma_addr_t init_fw_cb_dma;
519 uint32_t mbox_cmd[MBOX_REG_COUNT];
520 uint32_t mbox_sts[MBOX_REG_COUNT];
522 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
523 sizeof(struct addr_ctrl_blk),
524 &init_fw_cb_dma, GFP_KERNEL);
525 if (init_fw_cb == NULL) {
526 printk("scsi%ld: %s: Unable to alloc init_cb\n", ha->host_no,
531 /* Get Initialize Firmware Control Block. */
532 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
533 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
535 DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
536 ha->host_no, __func__));
537 dma_free_coherent(&ha->pdev->dev,
538 sizeof(struct addr_ctrl_blk),
539 init_fw_cb, init_fw_cb_dma);
543 /* Save IP Address. */
544 qla4xxx_update_local_ip(ha, init_fw_cb);
545 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
546 init_fw_cb, init_fw_cb_dma);
552 * qla4xxx_get_firmware_state - gets firmware state of HBA
553 * @ha: Pointer to host adapter structure.
555 int qla4xxx_get_firmware_state(struct scsi_qla_host * ha)
557 uint32_t mbox_cmd[MBOX_REG_COUNT];
558 uint32_t mbox_sts[MBOX_REG_COUNT];
560 /* Get firmware version */
561 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
562 memset(&mbox_sts, 0, sizeof(mbox_sts));
564 mbox_cmd[0] = MBOX_CMD_GET_FW_STATE;
566 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 4, &mbox_cmd[0], &mbox_sts[0]) !=
568 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
569 "status %04X\n", ha->host_no, __func__,
573 ha->firmware_state = mbox_sts[1];
574 ha->board_id = mbox_sts[2];
575 ha->addl_fw_state = mbox_sts[3];
576 DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
577 ha->host_no, __func__, ha->firmware_state);)
583 * qla4xxx_get_firmware_status - retrieves firmware status
584 * @ha: Pointer to host adapter structure.
586 int qla4xxx_get_firmware_status(struct scsi_qla_host * ha)
588 uint32_t mbox_cmd[MBOX_REG_COUNT];
589 uint32_t mbox_sts[MBOX_REG_COUNT];
591 /* Get firmware version */
592 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
593 memset(&mbox_sts, 0, sizeof(mbox_sts));
595 mbox_cmd[0] = MBOX_CMD_GET_FW_STATUS;
597 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
599 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
600 "status %04X\n", ha->host_no, __func__,
605 ql4_printk(KERN_INFO, ha, "%ld firmare IOCBs available (%d).\n",
606 ha->host_no, mbox_sts[2]);
612 * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
613 * @ha: Pointer to host adapter structure.
614 * @fw_ddb_index: Firmware's device database index
615 * @fw_ddb_entry: Pointer to firmware's device database entry structure
616 * @num_valid_ddb_entries: Pointer to number of valid ddb entries
617 * @next_ddb_index: Pointer to next valid device database index
618 * @fw_ddb_device_state: Pointer to device state
620 int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
621 uint16_t fw_ddb_index,
622 struct dev_db_entry *fw_ddb_entry,
623 dma_addr_t fw_ddb_entry_dma,
624 uint32_t *num_valid_ddb_entries,
625 uint32_t *next_ddb_index,
626 uint32_t *fw_ddb_device_state,
627 uint32_t *conn_err_detail,
628 uint16_t *tcp_source_port_num,
629 uint16_t *connection_id)
631 int status = QLA_ERROR;
633 uint32_t mbox_cmd[MBOX_REG_COUNT];
634 uint32_t mbox_sts[MBOX_REG_COUNT];
636 /* Make sure the device index is valid */
637 if (fw_ddb_index >= MAX_DDB_ENTRIES) {
638 DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
639 ha->host_no, __func__, fw_ddb_index));
642 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
643 memset(&mbox_sts, 0, sizeof(mbox_sts));
645 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY;
646 mbox_cmd[1] = (uint32_t) fw_ddb_index;
647 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
648 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
649 mbox_cmd[4] = sizeof(struct dev_db_entry);
651 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 7, &mbox_cmd[0], &mbox_sts[0]) ==
653 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
654 " with status 0x%04X\n", ha->host_no, __func__,
658 if (fw_ddb_index != mbox_sts[1]) {
659 DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
660 ha->host_no, __func__, fw_ddb_index,
665 options = le16_to_cpu(fw_ddb_entry->options);
666 if (options & DDB_OPT_IPV6_DEVICE) {
667 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
668 "Next %d State %04x ConnErr %08x %pI6 "
669 ":%04d \"%s\"\n", __func__, fw_ddb_index,
670 mbox_sts[0], mbox_sts[2], mbox_sts[3],
671 mbox_sts[4], mbox_sts[5],
672 fw_ddb_entry->ip_addr,
673 le16_to_cpu(fw_ddb_entry->port),
674 fw_ddb_entry->iscsi_name);
676 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
677 "Next %d State %04x ConnErr %08x %pI4 "
678 ":%04d \"%s\"\n", __func__, fw_ddb_index,
679 mbox_sts[0], mbox_sts[2], mbox_sts[3],
680 mbox_sts[4], mbox_sts[5],
681 fw_ddb_entry->ip_addr,
682 le16_to_cpu(fw_ddb_entry->port),
683 fw_ddb_entry->iscsi_name);
686 if (num_valid_ddb_entries)
687 *num_valid_ddb_entries = mbox_sts[2];
689 *next_ddb_index = mbox_sts[3];
690 if (fw_ddb_device_state)
691 *fw_ddb_device_state = mbox_sts[4];
694 * RA: This mailbox has been changed to pass connection error and
695 * details. Its true for ISP4010 as per Version E - Not sure when it
696 * was changed. Get the time2wait from the fw_dd_entry field :
697 * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
701 *conn_err_detail = mbox_sts[5];
702 if (tcp_source_port_num)
703 *tcp_source_port_num = (uint16_t) (mbox_sts[6] >> 16);
705 *connection_id = (uint16_t) mbox_sts[6] & 0x00FF;
706 status = QLA_SUCCESS;
712 int qla4xxx_conn_open(struct scsi_qla_host *ha, uint16_t fw_ddb_index)
714 uint32_t mbox_cmd[MBOX_REG_COUNT];
715 uint32_t mbox_sts[MBOX_REG_COUNT];
718 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
719 memset(&mbox_sts, 0, sizeof(mbox_sts));
721 mbox_cmd[0] = MBOX_CMD_CONN_OPEN;
722 mbox_cmd[1] = fw_ddb_index;
724 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
726 DEBUG2(ql4_printk(KERN_INFO, ha,
727 "%s: status = %d mbx0 = 0x%x mbx1 = 0x%x\n",
728 __func__, status, mbox_sts[0], mbox_sts[1]));
733 * qla4xxx_set_fwddb_entry - sets a ddb entry.
734 * @ha: Pointer to host adapter structure.
735 * @fw_ddb_index: Firmware's device database index
736 * @fw_ddb_entry_dma: dma address of ddb entry
737 * @mbx_sts: mailbox 0 to be returned or NULL
739 * This routine initializes or updates the adapter's device database
740 * entry for the specified device.
742 int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
743 dma_addr_t fw_ddb_entry_dma, uint32_t *mbx_sts)
745 uint32_t mbox_cmd[MBOX_REG_COUNT];
746 uint32_t mbox_sts[MBOX_REG_COUNT];
749 /* Do not wait for completion. The firmware will send us an
750 * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
752 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
753 memset(&mbox_sts, 0, sizeof(mbox_sts));
755 mbox_cmd[0] = MBOX_CMD_SET_DATABASE_ENTRY;
756 mbox_cmd[1] = (uint32_t) fw_ddb_index;
757 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
758 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
759 mbox_cmd[4] = sizeof(struct dev_db_entry);
761 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
764 *mbx_sts = mbox_sts[0];
765 DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
766 ha->host_no, __func__, status, mbox_sts[0], mbox_sts[4]);)
771 int qla4xxx_session_logout_ddb(struct scsi_qla_host *ha,
772 struct ddb_entry *ddb_entry, int options)
775 uint32_t mbox_cmd[MBOX_REG_COUNT];
776 uint32_t mbox_sts[MBOX_REG_COUNT];
778 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
779 memset(&mbox_sts, 0, sizeof(mbox_sts));
781 mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
782 mbox_cmd[1] = ddb_entry->fw_ddb_index;
783 mbox_cmd[3] = options;
785 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
787 if (status != QLA_SUCCESS) {
788 DEBUG2(ql4_printk(KERN_INFO, ha,
789 "%s: MBOX_CMD_CONN_CLOSE_SESS_LOGOUT "
790 "failed sts %04X %04X", __func__,
791 mbox_sts[0], mbox_sts[1]));
798 * qla4xxx_get_crash_record - retrieves crash record.
799 * @ha: Pointer to host adapter structure.
801 * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
803 void qla4xxx_get_crash_record(struct scsi_qla_host * ha)
805 uint32_t mbox_cmd[MBOX_REG_COUNT];
806 uint32_t mbox_sts[MBOX_REG_COUNT];
807 struct crash_record *crash_record = NULL;
808 dma_addr_t crash_record_dma = 0;
809 uint32_t crash_record_size = 0;
811 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
812 memset(&mbox_sts, 0, sizeof(mbox_cmd));
814 /* Get size of crash record. */
815 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
817 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
819 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
820 ha->host_no, __func__));
821 goto exit_get_crash_record;
823 crash_record_size = mbox_sts[4];
824 if (crash_record_size == 0) {
825 DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
826 ha->host_no, __func__));
827 goto exit_get_crash_record;
830 /* Alloc Memory for Crash Record. */
831 crash_record = dma_alloc_coherent(&ha->pdev->dev, crash_record_size,
832 &crash_record_dma, GFP_KERNEL);
833 if (crash_record == NULL)
834 goto exit_get_crash_record;
836 /* Get Crash Record. */
837 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
838 memset(&mbox_sts, 0, sizeof(mbox_cmd));
840 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
841 mbox_cmd[2] = LSDW(crash_record_dma);
842 mbox_cmd[3] = MSDW(crash_record_dma);
843 mbox_cmd[4] = crash_record_size;
845 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
847 goto exit_get_crash_record;
849 /* Dump Crash Record. */
851 exit_get_crash_record:
853 dma_free_coherent(&ha->pdev->dev, crash_record_size,
854 crash_record, crash_record_dma);
858 * qla4xxx_get_conn_event_log - retrieves connection event log
859 * @ha: Pointer to host adapter structure.
861 void qla4xxx_get_conn_event_log(struct scsi_qla_host * ha)
863 uint32_t mbox_cmd[MBOX_REG_COUNT];
864 uint32_t mbox_sts[MBOX_REG_COUNT];
865 struct conn_event_log_entry *event_log = NULL;
866 dma_addr_t event_log_dma = 0;
867 uint32_t event_log_size = 0;
868 uint32_t num_valid_entries;
869 uint32_t oldest_entry = 0;
870 uint32_t max_event_log_entries;
874 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
875 memset(&mbox_sts, 0, sizeof(mbox_cmd));
877 /* Get size of crash record. */
878 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
880 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
882 goto exit_get_event_log;
884 event_log_size = mbox_sts[4];
885 if (event_log_size == 0)
886 goto exit_get_event_log;
888 /* Alloc Memory for Crash Record. */
889 event_log = dma_alloc_coherent(&ha->pdev->dev, event_log_size,
890 &event_log_dma, GFP_KERNEL);
891 if (event_log == NULL)
892 goto exit_get_event_log;
894 /* Get Crash Record. */
895 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
896 memset(&mbox_sts, 0, sizeof(mbox_cmd));
898 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
899 mbox_cmd[2] = LSDW(event_log_dma);
900 mbox_cmd[3] = MSDW(event_log_dma);
902 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
904 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
905 "log!\n", ha->host_no, __func__));
906 goto exit_get_event_log;
909 /* Dump Event Log. */
910 num_valid_entries = mbox_sts[1];
912 max_event_log_entries = event_log_size /
913 sizeof(struct conn_event_log_entry);
915 if (num_valid_entries > max_event_log_entries)
916 oldest_entry = num_valid_entries % max_event_log_entries;
918 DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
919 ha->host_no, num_valid_entries));
921 if (ql4xextended_error_logging == 3) {
922 if (oldest_entry == 0) {
923 /* Circular Buffer has not wrapped around */
924 for (i=0; i < num_valid_entries; i++) {
925 qla4xxx_dump_buffer((uint8_t *)event_log+
926 (i*sizeof(*event_log)),
931 /* Circular Buffer has wrapped around -
932 * display accordingly*/
933 for (i=oldest_entry; i < max_event_log_entries; i++) {
934 qla4xxx_dump_buffer((uint8_t *)event_log+
935 (i*sizeof(*event_log)),
938 for (i=0; i < oldest_entry; i++) {
939 qla4xxx_dump_buffer((uint8_t *)event_log+
940 (i*sizeof(*event_log)),
948 dma_free_coherent(&ha->pdev->dev, event_log_size, event_log,
953 * qla4xxx_abort_task - issues Abort Task
954 * @ha: Pointer to host adapter structure.
955 * @srb: Pointer to srb entry
957 * This routine performs a LUN RESET on the specified target/lun.
958 * The caller must ensure that the ddb_entry and lun_entry pointers
959 * are valid before calling this routine.
961 int qla4xxx_abort_task(struct scsi_qla_host *ha, struct srb *srb)
963 uint32_t mbox_cmd[MBOX_REG_COUNT];
964 uint32_t mbox_sts[MBOX_REG_COUNT];
965 struct scsi_cmnd *cmd = srb->cmd;
966 int status = QLA_SUCCESS;
967 unsigned long flags = 0;
971 * Send abort task command to ISP, so that the ISP will return
972 * request with ABORT status
974 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
975 memset(&mbox_sts, 0, sizeof(mbox_sts));
977 spin_lock_irqsave(&ha->hardware_lock, flags);
978 index = (unsigned long)(unsigned char *)cmd->host_scribble;
979 spin_unlock_irqrestore(&ha->hardware_lock, flags);
981 /* Firmware already posted completion on response queue */
982 if (index == MAX_SRBS)
985 mbox_cmd[0] = MBOX_CMD_ABORT_TASK;
986 mbox_cmd[1] = srb->ddb->fw_ddb_index;
988 /* Immediate Command Enable */
991 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
993 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE) {
996 DEBUG2(printk(KERN_WARNING "scsi%ld:%d:%d: abort task FAILED: "
997 "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
998 ha->host_no, cmd->device->id, cmd->device->lun, mbox_sts[0],
999 mbox_sts[1], mbox_sts[2], mbox_sts[3], mbox_sts[4]));
1006 * qla4xxx_reset_lun - issues LUN Reset
1007 * @ha: Pointer to host adapter structure.
1008 * @ddb_entry: Pointer to device database entry
1011 * This routine performs a LUN RESET on the specified target/lun.
1012 * The caller must ensure that the ddb_entry and lun_entry pointers
1013 * are valid before calling this routine.
1015 int qla4xxx_reset_lun(struct scsi_qla_host * ha, struct ddb_entry * ddb_entry,
1018 uint32_t mbox_cmd[MBOX_REG_COUNT];
1019 uint32_t mbox_sts[MBOX_REG_COUNT];
1020 int status = QLA_SUCCESS;
1022 DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha->host_no,
1023 ddb_entry->fw_ddb_index, lun));
1026 * Send lun reset command to ISP, so that the ISP will return all
1027 * outstanding requests with RESET status
1029 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1030 memset(&mbox_sts, 0, sizeof(mbox_sts));
1032 mbox_cmd[0] = MBOX_CMD_LUN_RESET;
1033 mbox_cmd[1] = ddb_entry->fw_ddb_index;
1034 mbox_cmd[2] = lun << 8;
1035 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
1037 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]);
1038 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
1039 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
1046 * qla4xxx_reset_target - issues target Reset
1047 * @ha: Pointer to host adapter structure.
1048 * @db_entry: Pointer to device database entry
1049 * @un_entry: Pointer to lun entry structure
1051 * This routine performs a TARGET RESET on the specified target.
1052 * The caller must ensure that the ddb_entry pointers
1053 * are valid before calling this routine.
1055 int qla4xxx_reset_target(struct scsi_qla_host *ha,
1056 struct ddb_entry *ddb_entry)
1058 uint32_t mbox_cmd[MBOX_REG_COUNT];
1059 uint32_t mbox_sts[MBOX_REG_COUNT];
1060 int status = QLA_SUCCESS;
1062 DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha->host_no,
1063 ddb_entry->fw_ddb_index));
1066 * Send target reset command to ISP, so that the ISP will return all
1067 * outstanding requests with RESET status
1069 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1070 memset(&mbox_sts, 0, sizeof(mbox_sts));
1072 mbox_cmd[0] = MBOX_CMD_TARGET_WARM_RESET;
1073 mbox_cmd[1] = ddb_entry->fw_ddb_index;
1074 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
1076 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1078 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
1079 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
1085 int qla4xxx_get_flash(struct scsi_qla_host * ha, dma_addr_t dma_addr,
1086 uint32_t offset, uint32_t len)
1088 uint32_t mbox_cmd[MBOX_REG_COUNT];
1089 uint32_t mbox_sts[MBOX_REG_COUNT];
1091 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1092 memset(&mbox_sts, 0, sizeof(mbox_sts));
1094 mbox_cmd[0] = MBOX_CMD_READ_FLASH;
1095 mbox_cmd[1] = LSDW(dma_addr);
1096 mbox_cmd[2] = MSDW(dma_addr);
1097 mbox_cmd[3] = offset;
1100 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0], &mbox_sts[0]) !=
1102 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
1103 "status %04X %04X, offset %08x, len %08x\n", ha->host_no,
1104 __func__, mbox_sts[0], mbox_sts[1], offset, len));
1111 * qla4xxx_about_firmware - gets FW, iscsi draft and boot loader version
1112 * @ha: Pointer to host adapter structure.
1114 * Retrieves the FW version, iSCSI draft version & bootloader version of HBA.
1115 * Mailboxes 2 & 3 may hold an address for data. Make sure that we write 0 to
1116 * those mailboxes, if unused.
1118 int qla4xxx_about_firmware(struct scsi_qla_host *ha)
1120 struct about_fw_info *about_fw = NULL;
1121 dma_addr_t about_fw_dma;
1122 uint32_t mbox_cmd[MBOX_REG_COUNT];
1123 uint32_t mbox_sts[MBOX_REG_COUNT];
1124 int status = QLA_ERROR;
1126 about_fw = dma_alloc_coherent(&ha->pdev->dev,
1127 sizeof(struct about_fw_info),
1128 &about_fw_dma, GFP_KERNEL);
1130 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Unable to alloc memory "
1131 "for about_fw\n", __func__));
1135 memset(about_fw, 0, sizeof(struct about_fw_info));
1136 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1137 memset(&mbox_sts, 0, sizeof(mbox_sts));
1139 mbox_cmd[0] = MBOX_CMD_ABOUT_FW;
1140 mbox_cmd[2] = LSDW(about_fw_dma);
1141 mbox_cmd[3] = MSDW(about_fw_dma);
1142 mbox_cmd[4] = sizeof(struct about_fw_info);
1144 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, MBOX_REG_COUNT,
1145 &mbox_cmd[0], &mbox_sts[0]);
1146 if (status != QLA_SUCCESS) {
1147 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_ABOUT_FW "
1148 "failed w/ status %04X\n", __func__,
1153 /* Save version information. */
1154 ha->firmware_version[0] = le16_to_cpu(about_fw->fw_major);
1155 ha->firmware_version[1] = le16_to_cpu(about_fw->fw_minor);
1156 ha->patch_number = le16_to_cpu(about_fw->fw_patch);
1157 ha->build_number = le16_to_cpu(about_fw->fw_build);
1158 ha->iscsi_major = le16_to_cpu(about_fw->iscsi_major);
1159 ha->iscsi_minor = le16_to_cpu(about_fw->iscsi_minor);
1160 ha->bootload_major = le16_to_cpu(about_fw->bootload_major);
1161 ha->bootload_minor = le16_to_cpu(about_fw->bootload_minor);
1162 ha->bootload_patch = le16_to_cpu(about_fw->bootload_patch);
1163 ha->bootload_build = le16_to_cpu(about_fw->bootload_build);
1164 status = QLA_SUCCESS;
1167 dma_free_coherent(&ha->pdev->dev, sizeof(struct about_fw_info),
1168 about_fw, about_fw_dma);
1172 static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha, uint32_t options,
1173 dma_addr_t dma_addr)
1175 uint32_t mbox_cmd[MBOX_REG_COUNT];
1176 uint32_t mbox_sts[MBOX_REG_COUNT];
1178 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1179 memset(&mbox_sts, 0, sizeof(mbox_sts));
1181 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS;
1182 mbox_cmd[1] = options;
1183 mbox_cmd[2] = LSDW(dma_addr);
1184 mbox_cmd[3] = MSDW(dma_addr);
1186 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]) !=
1188 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1189 ha->host_no, __func__, mbox_sts[0]));
1195 int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t ddb_index,
1199 uint32_t mbox_cmd[MBOX_REG_COUNT];
1200 uint32_t mbox_sts[MBOX_REG_COUNT];
1202 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1203 memset(&mbox_sts, 0, sizeof(mbox_sts));
1205 mbox_cmd[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY;
1206 mbox_cmd[1] = ddb_index;
1208 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1210 if (status != QLA_SUCCESS) {
1211 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
1212 __func__, mbox_sts[0]));
1215 *mbx_sts = mbox_sts[0];
1219 int qla4xxx_clear_ddb_entry(struct scsi_qla_host *ha, uint32_t ddb_index)
1222 uint32_t mbox_cmd[MBOX_REG_COUNT];
1223 uint32_t mbox_sts[MBOX_REG_COUNT];
1225 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1226 memset(&mbox_sts, 0, sizeof(mbox_sts));
1228 mbox_cmd[0] = MBOX_CMD_CLEAR_DATABASE_ENTRY;
1229 mbox_cmd[1] = ddb_index;
1231 status = qla4xxx_mailbox_command(ha, 2, 1, &mbox_cmd[0],
1233 if (status != QLA_SUCCESS) {
1234 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
1235 __func__, mbox_sts[0]));
1241 int qla4xxx_set_flash(struct scsi_qla_host *ha, dma_addr_t dma_addr,
1242 uint32_t offset, uint32_t length, uint32_t options)
1244 uint32_t mbox_cmd[MBOX_REG_COUNT];
1245 uint32_t mbox_sts[MBOX_REG_COUNT];
1246 int status = QLA_SUCCESS;
1248 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1249 memset(&mbox_sts, 0, sizeof(mbox_sts));
1251 mbox_cmd[0] = MBOX_CMD_WRITE_FLASH;
1252 mbox_cmd[1] = LSDW(dma_addr);
1253 mbox_cmd[2] = MSDW(dma_addr);
1254 mbox_cmd[3] = offset;
1255 mbox_cmd[4] = length;
1256 mbox_cmd[5] = options;
1258 status = qla4xxx_mailbox_command(ha, 6, 2, &mbox_cmd[0], &mbox_sts[0]);
1259 if (status != QLA_SUCCESS) {
1260 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_WRITE_FLASH "
1261 "failed w/ status %04X, mbx1 %04X\n",
1262 __func__, mbox_sts[0], mbox_sts[1]));
1267 int qla4xxx_bootdb_by_index(struct scsi_qla_host *ha,
1268 struct dev_db_entry *fw_ddb_entry,
1269 dma_addr_t fw_ddb_entry_dma, uint16_t ddb_index)
1271 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
1272 uint32_t dev_db_end_offset;
1273 int status = QLA_ERROR;
1275 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
1277 dev_db_start_offset += (ddb_index * sizeof(*fw_ddb_entry));
1278 dev_db_end_offset = FLASH_OFFSET_DB_END;
1280 if (dev_db_start_offset > dev_db_end_offset) {
1281 DEBUG2(ql4_printk(KERN_ERR, ha,
1282 "%s:Invalid DDB index %d", __func__,
1284 goto exit_bootdb_failed;
1287 if (qla4xxx_get_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
1288 sizeof(*fw_ddb_entry)) != QLA_SUCCESS) {
1289 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
1290 "failed\n", ha->host_no, __func__);
1291 goto exit_bootdb_failed;
1294 if (fw_ddb_entry->cookie == DDB_VALID_COOKIE)
1295 status = QLA_SUCCESS;
1301 int qla4xxx_get_chap(struct scsi_qla_host *ha, char *username, char *password,
1305 int rval = QLA_ERROR;
1306 uint32_t offset = 0;
1307 struct ql4_chap_table *chap_table;
1308 dma_addr_t chap_dma;
1310 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
1311 if (chap_table == NULL) {
1316 memset(chap_table, 0, sizeof(struct ql4_chap_table));
1318 offset = 0x06000000 | (idx * sizeof(struct ql4_chap_table));
1320 rval = qla4xxx_get_flash(ha, chap_dma, offset,
1321 sizeof(struct ql4_chap_table));
1322 if (rval != QLA_SUCCESS) {
1327 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
1328 __le16_to_cpu(chap_table->cookie)));
1330 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
1331 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
1335 strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
1336 strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
1337 chap_table->cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
1340 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
1344 static int qla4xxx_set_chap(struct scsi_qla_host *ha, char *username,
1345 char *password, uint16_t idx, int bidi)
1348 int rval = QLA_ERROR;
1349 uint32_t offset = 0;
1350 struct ql4_chap_table *chap_table;
1351 dma_addr_t chap_dma;
1353 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
1354 if (chap_table == NULL) {
1359 memset(chap_table, 0, sizeof(struct ql4_chap_table));
1361 chap_table->flags |= BIT_6; /* peer */
1363 chap_table->flags |= BIT_7; /* local */
1364 chap_table->secret_len = strlen(password);
1365 strncpy(chap_table->secret, password, MAX_CHAP_SECRET_LEN);
1366 strncpy(chap_table->name, username, MAX_CHAP_NAME_LEN);
1367 chap_table->cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
1368 offset = 0x06000000 | (idx * sizeof(struct ql4_chap_table));
1369 rval = qla4xxx_set_flash(ha, chap_dma, offset,
1370 sizeof(struct ql4_chap_table),
1371 FLASH_OPT_RMW_COMMIT);
1372 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
1373 if (rval != QLA_SUCCESS)
1380 int qla4xxx_conn_close_sess_logout(struct scsi_qla_host *ha,
1381 uint16_t fw_ddb_index,
1382 uint16_t connection_id,
1385 uint32_t mbox_cmd[MBOX_REG_COUNT];
1386 uint32_t mbox_sts[MBOX_REG_COUNT];
1387 int status = QLA_SUCCESS;
1389 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1390 memset(&mbox_sts, 0, sizeof(mbox_sts));
1392 mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
1393 mbox_cmd[1] = fw_ddb_index;
1394 mbox_cmd[2] = connection_id;
1395 mbox_cmd[3] = option;
1397 status = qla4xxx_mailbox_command(ha, 4, 2, &mbox_cmd[0], &mbox_sts[0]);
1398 if (status != QLA_SUCCESS) {
1399 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_CONN_CLOSE "
1400 "option %04x failed w/ status %04X %04X\n",
1401 __func__, option, mbox_sts[0], mbox_sts[1]));
1406 int qla4xxx_disable_acb(struct scsi_qla_host *ha)
1408 uint32_t mbox_cmd[MBOX_REG_COUNT];
1409 uint32_t mbox_sts[MBOX_REG_COUNT];
1410 int status = QLA_SUCCESS;
1412 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1413 memset(&mbox_sts, 0, sizeof(mbox_sts));
1415 mbox_cmd[0] = MBOX_CMD_DISABLE_ACB;
1417 status = qla4xxx_mailbox_command(ha, 8, 5, &mbox_cmd[0], &mbox_sts[0]);
1418 if (status != QLA_SUCCESS) {
1419 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_DISABLE_ACB "
1420 "failed w/ status %04X %04X %04X", __func__,
1421 mbox_sts[0], mbox_sts[1], mbox_sts[2]));
1426 int qla4xxx_get_acb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
1427 uint32_t *mbox_sts, dma_addr_t acb_dma)
1429 int status = QLA_SUCCESS;
1431 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
1432 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
1433 mbox_cmd[0] = MBOX_CMD_GET_ACB;
1434 mbox_cmd[1] = 0; /* Primary ACB */
1435 mbox_cmd[2] = LSDW(acb_dma);
1436 mbox_cmd[3] = MSDW(acb_dma);
1437 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
1439 status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
1440 if (status != QLA_SUCCESS) {
1441 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_GET_ACB "
1442 "failed w/ status %04X\n", __func__,
1448 int qla4xxx_set_acb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
1449 uint32_t *mbox_sts, dma_addr_t acb_dma)
1451 int status = QLA_SUCCESS;
1453 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
1454 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
1455 mbox_cmd[0] = MBOX_CMD_SET_ACB;
1456 mbox_cmd[1] = 0; /* Primary ACB */
1457 mbox_cmd[2] = LSDW(acb_dma);
1458 mbox_cmd[3] = MSDW(acb_dma);
1459 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
1461 status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
1462 if (status != QLA_SUCCESS) {
1463 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_SET_ACB "
1464 "failed w/ status %04X\n", __func__,
1470 int qla4xxx_set_param_ddbentry(struct scsi_qla_host *ha,
1471 struct ddb_entry *ddb_entry,
1472 struct iscsi_cls_conn *cls_conn,
1475 struct dev_db_entry *fw_ddb_entry;
1476 struct iscsi_conn *conn;
1477 struct iscsi_session *sess;
1478 struct qla_conn *qla_conn;
1479 struct sockaddr *dst_addr;
1480 dma_addr_t fw_ddb_entry_dma;
1481 int status = QLA_SUCCESS;
1483 struct sockaddr_in *addr;
1484 struct sockaddr_in6 *addr6;
1486 uint16_t iscsi_opts = 0;
1487 uint32_t options = 0;
1489 int max_chap_entries = 0;
1491 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1492 &fw_ddb_entry_dma, GFP_KERNEL);
1493 if (!fw_ddb_entry) {
1494 DEBUG2(ql4_printk(KERN_ERR, ha,
1495 "%s: Unable to allocate dma buffer.\n",
1498 goto exit_set_param_no_free;
1501 conn = cls_conn->dd_data;
1502 qla_conn = conn->dd_data;
1503 sess = conn->session;
1504 dst_addr = &qla_conn->qla_ep->dst_addr;
1506 if (dst_addr->sa_family == AF_INET6)
1507 options |= IPV6_DEFAULT_DDB_ENTRY;
1509 status = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
1510 if (status == QLA_ERROR) {
1512 goto exit_set_param;
1515 iscsi_opts = le16_to_cpu(fw_ddb_entry->iscsi_options);
1516 memset(fw_ddb_entry->iscsi_alias, 0, sizeof(fw_ddb_entry->iscsi_alias));
1518 memset(fw_ddb_entry->iscsi_name, 0, sizeof(fw_ddb_entry->iscsi_name));
1520 if (sess->targetname != NULL) {
1521 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
1522 min(strlen(sess->targetname),
1523 sizeof(fw_ddb_entry->iscsi_name)));
1526 memset(fw_ddb_entry->ip_addr, 0, sizeof(fw_ddb_entry->ip_addr));
1527 memset(fw_ddb_entry->tgt_addr, 0, sizeof(fw_ddb_entry->tgt_addr));
1529 fw_ddb_entry->options = DDB_OPT_TARGET | DDB_OPT_AUTO_SENDTGTS_DISABLE;
1531 if (dst_addr->sa_family == AF_INET) {
1532 addr = (struct sockaddr_in *)dst_addr;
1533 ip = (char *)&addr->sin_addr;
1534 memcpy(fw_ddb_entry->ip_addr, ip, IP_ADDR_LEN);
1535 fw_ddb_entry->port = cpu_to_le16(ntohs(addr->sin_port));
1536 DEBUG2(ql4_printk(KERN_INFO, ha,
1537 "%s: Destination Address [%pI4]: index [%d]\n",
1538 __func__, fw_ddb_entry->ip_addr,
1539 ddb_entry->fw_ddb_index));
1540 } else if (dst_addr->sa_family == AF_INET6) {
1541 addr6 = (struct sockaddr_in6 *)dst_addr;
1542 ip = (char *)&addr6->sin6_addr;
1543 memcpy(fw_ddb_entry->ip_addr, ip, IPv6_ADDR_LEN);
1544 fw_ddb_entry->port = cpu_to_le16(ntohs(addr6->sin6_port));
1545 fw_ddb_entry->options |= DDB_OPT_IPV6_DEVICE;
1546 DEBUG2(ql4_printk(KERN_INFO, ha,
1547 "%s: Destination Address [%pI6]: index [%d]\n",
1548 __func__, fw_ddb_entry->ip_addr,
1549 ddb_entry->fw_ddb_index));
1551 ql4_printk(KERN_ERR, ha,
1552 "%s: Failed to get IP Address\n",
1555 goto exit_set_param;
1559 max_chap_entries = MAX_CHAP_ENTRIES_82XX;
1561 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
1563 if (sess->username != NULL && sess->password != NULL) {
1564 if (strlen(sess->username) && strlen(sess->password)) {
1565 iscsi_opts |= BIT_7;
1566 idx = ddb_entry->fw_ddb_index * 2;
1567 if (idx > max_chap_entries) {
1568 ql4_printk(KERN_ERR, ha,
1569 "%s: Invalid ddb or chap index\n",
1572 goto exit_set_param;
1575 rval = qla4xxx_set_chap(ha, sess->username,
1576 sess->password, idx, 0);
1578 goto exit_set_param;
1580 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(idx);
1584 if (sess->username_in != NULL && sess->password_in != NULL) {
1585 /* Check if BIDI CHAP */
1586 if (strlen(sess->username_in) && strlen(sess->password_in)) {
1587 iscsi_opts |= BIT_4;
1588 idx = (ddb_entry->fw_ddb_index * 2) + 1;
1589 if (idx > max_chap_entries) {
1590 ql4_printk(KERN_ERR, ha,
1591 "%s: Invalid ddb or bidi chap "
1592 "index\n", __func__);
1594 goto exit_set_param;
1596 rval = qla4xxx_set_chap(ha, sess->username_in,
1597 sess->password_in, idx, 0);
1599 goto exit_set_param;
1603 if (sess->initial_r2t_en)
1604 iscsi_opts |= BIT_10;
1606 if (sess->imm_data_en)
1607 iscsi_opts |= BIT_11;
1609 fw_ddb_entry->iscsi_options = cpu_to_le16(iscsi_opts);
1611 if (conn->max_recv_dlength)
1612 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
1613 __constant_cpu_to_le16((conn->max_recv_dlength / BYTE_UNITS));
1616 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
1618 if (sess->first_burst)
1619 fw_ddb_entry->iscsi_first_burst_len =
1620 __constant_cpu_to_le16((sess->first_burst / BYTE_UNITS));
1622 if (sess->max_burst)
1623 fw_ddb_entry->iscsi_max_burst_len =
1624 __constant_cpu_to_le16((sess->max_burst / BYTE_UNITS));
1626 if (sess->time2wait)
1627 fw_ddb_entry->iscsi_def_time2wait =
1628 cpu_to_le16(sess->time2wait);
1630 if (sess->time2retain)
1631 fw_ddb_entry->iscsi_def_time2retain =
1632 cpu_to_le16(sess->time2retain);
1634 status = qla4xxx_set_ddb_entry(ha, ddb_entry->fw_ddb_index,
1635 fw_ddb_entry_dma, mbx_sts);
1637 if (status != QLA_SUCCESS)
1640 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1641 fw_ddb_entry, fw_ddb_entry_dma);
1642 exit_set_param_no_free:
1646 int qla4xxx_get_mgmt_data(struct scsi_qla_host *ha, uint16_t fw_ddb_index,
1647 uint16_t stats_size, dma_addr_t stats_dma)
1649 int status = QLA_SUCCESS;
1650 uint32_t mbox_cmd[MBOX_REG_COUNT];
1651 uint32_t mbox_sts[MBOX_REG_COUNT];
1653 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
1654 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
1655 mbox_cmd[0] = MBOX_CMD_GET_MANAGEMENT_DATA;
1656 mbox_cmd[1] = fw_ddb_index;
1657 mbox_cmd[2] = LSDW(stats_dma);
1658 mbox_cmd[3] = MSDW(stats_dma);
1659 mbox_cmd[4] = stats_size;
1661 status = qla4xxx_mailbox_command(ha, 5, 1, &mbox_cmd[0], &mbox_sts[0]);
1662 if (status != QLA_SUCCESS) {
1663 DEBUG2(ql4_printk(KERN_WARNING, ha,
1664 "%s: MBOX_CMD_GET_MANAGEMENT_DATA "
1665 "failed w/ status %04X\n", __func__,
1671 int qla4xxx_get_ip_state(struct scsi_qla_host *ha, uint32_t acb_idx,
1672 uint32_t ip_idx, uint32_t *sts)
1674 uint32_t mbox_cmd[MBOX_REG_COUNT];
1675 uint32_t mbox_sts[MBOX_REG_COUNT];
1676 int status = QLA_SUCCESS;
1678 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1679 memset(&mbox_sts, 0, sizeof(mbox_sts));
1680 mbox_cmd[0] = MBOX_CMD_GET_IP_ADDR_STATE;
1681 mbox_cmd[1] = acb_idx;
1682 mbox_cmd[2] = ip_idx;
1684 status = qla4xxx_mailbox_command(ha, 3, 8, &mbox_cmd[0], &mbox_sts[0]);
1685 if (status != QLA_SUCCESS) {
1686 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: "
1687 "MBOX_CMD_GET_IP_ADDR_STATE failed w/ "
1688 "status %04X\n", __func__, mbox_sts[0]));
1690 memcpy(sts, mbox_sts, sizeof(mbox_sts));
1694 int qla4xxx_get_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
1695 uint32_t offset, uint32_t size)
1697 int status = QLA_SUCCESS;
1698 uint32_t mbox_cmd[MBOX_REG_COUNT];
1699 uint32_t mbox_sts[MBOX_REG_COUNT];
1701 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1702 memset(&mbox_sts, 0, sizeof(mbox_sts));
1704 mbox_cmd[0] = MBOX_CMD_GET_NVRAM;
1705 mbox_cmd[1] = LSDW(nvram_dma);
1706 mbox_cmd[2] = MSDW(nvram_dma);
1707 mbox_cmd[3] = offset;
1710 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1712 if (status != QLA_SUCCESS) {
1713 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1714 "status %04X\n", ha->host_no, __func__,
1720 int qla4xxx_set_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
1721 uint32_t offset, uint32_t size)
1723 int status = QLA_SUCCESS;
1724 uint32_t mbox_cmd[MBOX_REG_COUNT];
1725 uint32_t mbox_sts[MBOX_REG_COUNT];
1727 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1728 memset(&mbox_sts, 0, sizeof(mbox_sts));
1730 mbox_cmd[0] = MBOX_CMD_SET_NVRAM;
1731 mbox_cmd[1] = LSDW(nvram_dma);
1732 mbox_cmd[2] = MSDW(nvram_dma);
1733 mbox_cmd[3] = offset;
1736 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1738 if (status != QLA_SUCCESS) {
1739 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1740 "status %04X\n", ha->host_no, __func__,