2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
13 * qla2x00_mailbox_command
14 * Issue mailbox command and waits for completion.
17 * ha = adapter block pointer.
18 * mcp = driver internal mbx struct pointer.
21 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
24 * 0 : QLA_SUCCESS = cmd performed success
25 * 1 : QLA_FUNCTION_FAILED (error encountered)
26 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
32 qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
35 unsigned long flags = 0;
36 device_reg_t __iomem *reg;
41 uint16_t __iomem *optr;
44 unsigned long wait_time;
45 struct qla_hw_data *ha = vha->hw;
46 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
49 io_lock_on = base_vha->flags.init_done;
52 abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
54 DEBUG11(printk("%s(%ld): entered.\n", __func__, base_vha->host_no));
57 * Wait for active mailbox commands to finish by waiting at most tov
58 * seconds. This is to serialize actual issuing of mailbox cmds during
62 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp,
64 /* Timeout occurred. Return error. */
65 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
66 "Exiting.\n", __func__, base_vha->host_no));
67 return QLA_FUNCTION_TIMEOUT;
71 ha->flags.mbox_busy = 1;
72 /* Save mailbox command for debug */
75 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
76 base_vha->host_no, mcp->mb[0]));
78 spin_lock_irqsave(&ha->hardware_lock, flags);
80 /* Load mailbox registers. */
81 if (IS_FWI2_CAPABLE(ha))
82 optr = (uint16_t __iomem *)®->isp24.mailbox0;
84 optr = (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 0);
90 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
91 if (IS_QLA2200(ha) && cnt == 8)
93 (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 8);
95 WRT_REG_WORD(optr, *iptr);
102 #if defined(QL_DEBUG_LEVEL_1)
103 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
104 __func__, base_vha->host_no);
105 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
107 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
109 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
111 printk("%s(%ld): I/O address = %p.\n", __func__, base_vha->host_no,
113 qla2x00_dump_regs(base_vha);
116 /* Issue set host interrupt command to send cmd out. */
117 ha->flags.mbox_int = 0;
118 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
120 /* Unlock mbx registers and wait for interrupt */
121 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
122 "jiffies=%lx.\n", __func__, base_vha->host_no, jiffies));
124 /* Wait for mbx cmd completion until timeout */
126 if (!abort_active && io_lock_on) {
128 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
130 if (IS_FWI2_CAPABLE(ha))
131 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
133 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
134 spin_unlock_irqrestore(&ha->hardware_lock, flags);
136 wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ);
138 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
141 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
142 base_vha->host_no, command));
144 if (IS_FWI2_CAPABLE(ha))
145 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
147 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
148 spin_unlock_irqrestore(&ha->hardware_lock, flags);
150 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
151 while (!ha->flags.mbox_int) {
152 if (time_after(jiffies, wait_time))
155 /* Check for pending interrupts. */
156 qla2x00_poll(ha->rsp);
158 if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
164 /* Check whether we timed out */
165 if (ha->flags.mbox_int) {
168 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
169 base_vha->host_no, command));
171 /* Got interrupt. Clear the flag. */
172 ha->flags.mbox_int = 0;
173 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
175 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
176 rval = QLA_FUNCTION_FAILED;
178 /* Load return mailbox registers. */
180 iptr = (uint16_t *)&ha->mailbox_out[0];
182 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
192 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
193 defined(QL_DEBUG_LEVEL_11)
197 if (IS_FWI2_CAPABLE(ha)) {
198 mb0 = RD_REG_WORD(®->isp24.mailbox0);
199 ictrl = RD_REG_DWORD(®->isp24.ictrl);
201 mb0 = RD_MAILBOX_REG(ha, ®->isp, 0);
202 ictrl = RD_REG_WORD(®->isp.ictrl);
204 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
205 __func__, base_vha->host_no, command);
206 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
207 base_vha->host_no, ictrl, jiffies);
208 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
209 base_vha->host_no, mb0);
210 qla2x00_dump_regs(base_vha);
213 rval = QLA_FUNCTION_TIMEOUT;
216 ha->flags.mbox_busy = 0;
221 if (abort_active || !io_lock_on) {
222 DEBUG11(printk("%s(%ld): checking for additional resp "
223 "interrupt.\n", __func__, base_vha->host_no));
225 /* polling mode for non isp_abort commands. */
226 qla2x00_poll(ha->rsp);
229 if (rval == QLA_FUNCTION_TIMEOUT &&
230 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
231 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
232 /* not in dpc. schedule it for dpc to take over. */
233 DEBUG(printk("%s(%ld): timeout schedule "
234 "isp_abort_needed.\n", __func__,
236 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
237 "isp_abort_needed.\n", __func__,
239 qla_printk(KERN_WARNING, ha,
240 "Mailbox command timeout occurred. Scheduling ISP "
242 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
243 qla2xxx_wake_dpc(vha);
244 } else if (!abort_active) {
245 /* call abort directly since we are in the DPC thread */
246 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
247 __func__, base_vha->host_no));
248 DEBUG2_3_11(printk("%s(%ld): timeout calling "
249 "abort_isp\n", __func__, base_vha->host_no));
250 qla_printk(KERN_WARNING, ha,
251 "Mailbox command timeout occurred. Issuing ISP "
254 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
255 clear_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
256 if (qla2x00_abort_isp(base_vha)) {
257 /* Failed. retry later. */
258 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
260 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
261 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
263 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
264 __func__, base_vha->host_no));
268 /* Allow next mbx cmd to come in. */
270 complete(&ha->mbx_cmd_comp);
273 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
274 "mbx2=%x, cmd=%x ****\n", __func__, base_vha->host_no,
275 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
277 DEBUG11(printk("%s(%ld): done.\n", __func__,
285 qla2x00_load_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t risc_addr,
286 uint32_t risc_code_size)
289 struct qla_hw_data *ha = vha->hw;
291 mbx_cmd_t *mcp = &mc;
293 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
295 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
296 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
297 mcp->mb[8] = MSW(risc_addr);
298 mcp->out_mb = MBX_8|MBX_0;
300 mcp->mb[0] = MBC_LOAD_RISC_RAM;
303 mcp->mb[1] = LSW(risc_addr);
304 mcp->mb[2] = MSW(req_dma);
305 mcp->mb[3] = LSW(req_dma);
306 mcp->mb[6] = MSW(MSD(req_dma));
307 mcp->mb[7] = LSW(MSD(req_dma));
308 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
309 if (IS_FWI2_CAPABLE(ha)) {
310 mcp->mb[4] = MSW(risc_code_size);
311 mcp->mb[5] = LSW(risc_code_size);
312 mcp->out_mb |= MBX_5|MBX_4;
314 mcp->mb[4] = LSW(risc_code_size);
315 mcp->out_mb |= MBX_4;
319 mcp->tov = MBX_TOV_SECONDS;
321 rval = qla2x00_mailbox_command(vha, mcp);
323 if (rval != QLA_SUCCESS) {
324 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
325 vha->host_no, rval, mcp->mb[0]));
327 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
335 * Start adapter firmware.
338 * ha = adapter block pointer.
339 * TARGET_QUEUE_LOCK must be released.
340 * ADAPTER_STATE_LOCK must be released.
343 * qla2x00 local function return status code.
349 qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
352 struct qla_hw_data *ha = vha->hw;
354 mbx_cmd_t *mcp = &mc;
356 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
358 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
361 if (IS_FWI2_CAPABLE(ha)) {
362 mcp->mb[1] = MSW(risc_addr);
363 mcp->mb[2] = LSW(risc_addr);
366 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
369 mcp->mb[1] = LSW(risc_addr);
370 mcp->out_mb |= MBX_1;
371 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
373 mcp->out_mb |= MBX_2;
377 mcp->tov = MBX_TOV_SECONDS;
379 rval = qla2x00_mailbox_command(vha, mcp);
381 if (rval != QLA_SUCCESS) {
382 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
383 vha->host_no, rval, mcp->mb[0]));
385 if (IS_FWI2_CAPABLE(ha)) {
386 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
387 __func__, vha->host_no, mcp->mb[1]));
389 DEBUG11(printk("%s(%ld): done.\n", __func__,
398 * qla2x00_get_fw_version
399 * Get firmware version.
402 * ha: adapter state pointer.
403 * major: pointer for major number.
404 * minor: pointer for minor number.
405 * subminor: pointer for subminor number.
408 * qla2x00 local function return status code.
414 qla2x00_get_fw_version(scsi_qla_host_t *vha, uint16_t *major, uint16_t *minor,
415 uint16_t *subminor, uint16_t *attributes, uint32_t *memory)
419 mbx_cmd_t *mcp = &mc;
421 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
423 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
425 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
427 mcp->tov = MBX_TOV_SECONDS;
428 rval = qla2x00_mailbox_command(vha, mcp);
430 /* Return mailbox data. */
433 *subminor = mcp->mb[3];
434 *attributes = mcp->mb[6];
435 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
436 *memory = 0x1FFFF; /* Defaults to 128KB. */
438 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
440 if (rval != QLA_SUCCESS) {
442 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
443 vha->host_no, rval));
446 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
451 * qla2x00_get_fw_options
452 * Set firmware options.
455 * ha = adapter block pointer.
456 * fwopt = pointer for firmware options.
459 * qla2x00 local function return status code.
465 qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
469 mbx_cmd_t *mcp = &mc;
471 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
473 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
475 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
476 mcp->tov = MBX_TOV_SECONDS;
478 rval = qla2x00_mailbox_command(vha, mcp);
480 if (rval != QLA_SUCCESS) {
482 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
483 vha->host_no, rval));
485 fwopts[0] = mcp->mb[0];
486 fwopts[1] = mcp->mb[1];
487 fwopts[2] = mcp->mb[2];
488 fwopts[3] = mcp->mb[3];
490 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
498 * qla2x00_set_fw_options
499 * Set firmware options.
502 * ha = adapter block pointer.
503 * fwopt = pointer for firmware options.
506 * qla2x00 local function return status code.
512 qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
516 mbx_cmd_t *mcp = &mc;
518 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
520 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
521 mcp->mb[1] = fwopts[1];
522 mcp->mb[2] = fwopts[2];
523 mcp->mb[3] = fwopts[3];
524 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
526 if (IS_FWI2_CAPABLE(vha->hw)) {
529 mcp->mb[10] = fwopts[10];
530 mcp->mb[11] = fwopts[11];
531 mcp->mb[12] = 0; /* Undocumented, but used */
532 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
534 mcp->tov = MBX_TOV_SECONDS;
536 rval = qla2x00_mailbox_command(vha, mcp);
538 fwopts[0] = mcp->mb[0];
540 if (rval != QLA_SUCCESS) {
542 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
543 vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
546 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
553 * qla2x00_mbx_reg_test
554 * Mailbox register wrap test.
557 * ha = adapter block pointer.
558 * TARGET_QUEUE_LOCK must be released.
559 * ADAPTER_STATE_LOCK must be released.
562 * qla2x00 local function return status code.
568 qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
571 struct qla_hw_data *ha = vha->hw;
573 mbx_cmd_t *mcp = &mc;
575 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", vha->host_no));
577 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
585 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
586 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
587 mcp->tov = MBX_TOV_SECONDS;
589 rval = qla2x00_mailbox_command(vha, mcp);
591 if (rval == QLA_SUCCESS) {
592 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
593 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
594 rval = QLA_FUNCTION_FAILED;
595 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
596 mcp->mb[7] != 0x2525)
597 rval = QLA_FUNCTION_FAILED;
598 if (rval == QLA_FUNCTION_FAILED) {
599 struct device_reg_24xx __iomem *reg =
602 qla2xxx_hw_event_log(vha, HW_EVENT_ISP_ERR, 0,
603 LSW(RD_REG_DWORD(®->hccr)),
604 LSW(RD_REG_DWORD(®->istatus)));
608 if (rval != QLA_SUCCESS) {
610 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
611 vha->host_no, rval));
614 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
622 * qla2x00_verify_checksum
623 * Verify firmware checksum.
626 * ha = adapter block pointer.
627 * TARGET_QUEUE_LOCK must be released.
628 * ADAPTER_STATE_LOCK must be released.
631 * qla2x00 local function return status code.
637 qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
641 mbx_cmd_t *mcp = &mc;
643 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
645 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
648 if (IS_FWI2_CAPABLE(vha->hw)) {
649 mcp->mb[1] = MSW(risc_addr);
650 mcp->mb[2] = LSW(risc_addr);
651 mcp->out_mb |= MBX_2|MBX_1;
652 mcp->in_mb |= MBX_2|MBX_1;
654 mcp->mb[1] = LSW(risc_addr);
655 mcp->out_mb |= MBX_1;
659 mcp->tov = MBX_TOV_SECONDS;
661 rval = qla2x00_mailbox_command(vha, mcp);
663 if (rval != QLA_SUCCESS) {
664 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
665 vha->host_no, rval, IS_FWI2_CAPABLE(vha->hw) ?
666 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
668 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
676 * Issue IOCB using mailbox command
679 * ha = adapter state pointer.
680 * buffer = buffer pointer.
681 * phys_addr = physical address of buffer.
682 * size = size of buffer.
683 * TARGET_QUEUE_LOCK must be released.
684 * ADAPTER_STATE_LOCK must be released.
687 * qla2x00 local function return status code.
693 qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
694 dma_addr_t phys_addr, size_t size, uint32_t tov)
698 mbx_cmd_t *mcp = &mc;
700 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
702 mcp->mb[2] = MSW(phys_addr);
703 mcp->mb[3] = LSW(phys_addr);
704 mcp->mb[6] = MSW(MSD(phys_addr));
705 mcp->mb[7] = LSW(MSD(phys_addr));
706 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
707 mcp->in_mb = MBX_2|MBX_0;
710 rval = qla2x00_mailbox_command(vha, mcp);
712 if (rval != QLA_SUCCESS) {
714 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
715 vha->host_no, rval));
716 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
717 vha->host_no, rval));
719 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
721 /* Mask reserved bits. */
722 sts_entry->entry_status &=
723 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
730 qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
733 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
738 * qla2x00_abort_command
739 * Abort command aborts a specified IOCB.
742 * ha = adapter block pointer.
743 * sp = SB structure pointer.
746 * qla2x00 local function return status code.
752 qla2x00_abort_command(scsi_qla_host_t *vha, srb_t *sp)
754 unsigned long flags = 0;
759 mbx_cmd_t *mcp = &mc;
760 struct qla_hw_data *ha = vha->hw;
761 struct req_que *req = ha->req;
763 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", vha->host_no));
767 spin_lock_irqsave(&ha->hardware_lock, flags);
768 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
769 if (req->outstanding_cmds[handle] == sp)
772 spin_unlock_irqrestore(&ha->hardware_lock, flags);
774 if (handle == MAX_OUTSTANDING_COMMANDS) {
775 /* command not found */
776 return QLA_FUNCTION_FAILED;
779 mcp->mb[0] = MBC_ABORT_COMMAND;
780 if (HAS_EXTENDED_IDS(ha))
781 mcp->mb[1] = fcport->loop_id;
783 mcp->mb[1] = fcport->loop_id << 8;
784 mcp->mb[2] = (uint16_t)handle;
785 mcp->mb[3] = (uint16_t)(handle >> 16);
786 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
787 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
789 mcp->tov = MBX_TOV_SECONDS;
791 rval = qla2x00_mailbox_command(vha, mcp);
793 if (rval != QLA_SUCCESS) {
794 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
795 vha->host_no, rval));
797 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
805 qla2x00_abort_target(struct fc_port *fcport, unsigned int l)
809 mbx_cmd_t *mcp = &mc;
810 scsi_qla_host_t *vha;
812 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
816 mcp->mb[0] = MBC_ABORT_TARGET;
817 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
818 if (HAS_EXTENDED_IDS(vha->hw)) {
819 mcp->mb[1] = fcport->loop_id;
821 mcp->out_mb |= MBX_10;
823 mcp->mb[1] = fcport->loop_id << 8;
825 mcp->mb[2] = vha->hw->loop_reset_delay;
826 mcp->mb[9] = vha->vp_idx;
829 mcp->tov = MBX_TOV_SECONDS;
831 rval = qla2x00_mailbox_command(vha, mcp);
832 if (rval != QLA_SUCCESS) {
833 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
834 vha->host_no, rval));
837 /* Issue marker IOCB. */
838 rval2 = qla2x00_marker(vha, fcport->loop_id, 0, MK_SYNC_ID);
839 if (rval2 != QLA_SUCCESS) {
840 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
841 "(%x).\n", __func__, vha->host_no, rval2));
843 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
850 qla2x00_lun_reset(struct fc_port *fcport, unsigned int l)
854 mbx_cmd_t *mcp = &mc;
855 scsi_qla_host_t *vha;
857 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
860 mcp->mb[0] = MBC_LUN_RESET;
861 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
862 if (HAS_EXTENDED_IDS(vha->hw))
863 mcp->mb[1] = fcport->loop_id;
865 mcp->mb[1] = fcport->loop_id << 8;
868 mcp->mb[9] = vha->vp_idx;
871 mcp->tov = MBX_TOV_SECONDS;
873 rval = qla2x00_mailbox_command(vha, mcp);
874 if (rval != QLA_SUCCESS) {
875 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
876 vha->host_no, rval));
879 /* Issue marker IOCB. */
880 rval2 = qla2x00_marker(vha, fcport->loop_id, l, MK_SYNC_ID_LUN);
881 if (rval2 != QLA_SUCCESS) {
882 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
883 "(%x).\n", __func__, vha->host_no, rval2));
885 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
892 * qla2x00_get_adapter_id
893 * Get adapter ID and topology.
896 * ha = adapter block pointer.
897 * id = pointer for loop ID.
898 * al_pa = pointer for AL_PA.
899 * area = pointer for area.
900 * domain = pointer for domain.
901 * top = pointer for topology.
902 * TARGET_QUEUE_LOCK must be released.
903 * ADAPTER_STATE_LOCK must be released.
906 * qla2x00 local function return status code.
912 qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
913 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
917 mbx_cmd_t *mcp = &mc;
919 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
922 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
923 mcp->mb[9] = vha->vp_idx;
924 mcp->out_mb = MBX_9|MBX_0;
925 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
926 mcp->tov = MBX_TOV_SECONDS;
928 rval = qla2x00_mailbox_command(vha, mcp);
929 if (mcp->mb[0] == MBS_COMMAND_ERROR)
930 rval = QLA_COMMAND_ERROR;
931 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
932 rval = QLA_INVALID_COMMAND;
936 *al_pa = LSB(mcp->mb[2]);
937 *area = MSB(mcp->mb[2]);
938 *domain = LSB(mcp->mb[3]);
940 *sw_cap = mcp->mb[7];
942 if (rval != QLA_SUCCESS) {
944 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
945 vha->host_no, rval));
948 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
956 * qla2x00_get_retry_cnt
957 * Get current firmware login retry count and delay.
960 * ha = adapter block pointer.
961 * retry_cnt = pointer to login retry count.
962 * tov = pointer to login timeout value.
965 * qla2x00 local function return status code.
971 qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
977 mbx_cmd_t *mcp = &mc;
979 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
982 mcp->mb[0] = MBC_GET_RETRY_COUNT;
984 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
985 mcp->tov = MBX_TOV_SECONDS;
987 rval = qla2x00_mailbox_command(vha, mcp);
989 if (rval != QLA_SUCCESS) {
991 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
992 vha->host_no, mcp->mb[0]));
994 /* Convert returned data and check our values. */
995 *r_a_tov = mcp->mb[3] / 2;
996 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
997 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
998 /* Update to the larger values */
999 *retry_cnt = (uint8_t)mcp->mb[1];
1003 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
1004 "ratov=%d.\n", vha->host_no, mcp->mb[3], ratov));
1011 * qla2x00_init_firmware
1012 * Initialize adapter firmware.
1015 * ha = adapter block pointer.
1016 * dptr = Initialization control block pointer.
1017 * size = size of initialization control block.
1018 * TARGET_QUEUE_LOCK must be released.
1019 * ADAPTER_STATE_LOCK must be released.
1022 * qla2x00 local function return status code.
1028 qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
1032 mbx_cmd_t *mcp = &mc;
1033 struct qla_hw_data *ha = vha->hw;
1035 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1038 if (ha->flags.npiv_supported)
1039 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1041 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1043 mcp->mb[2] = MSW(ha->init_cb_dma);
1044 mcp->mb[3] = LSW(ha->init_cb_dma);
1047 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1048 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1049 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1050 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1051 mcp->buf_size = size;
1052 mcp->flags = MBX_DMA_OUT;
1053 mcp->tov = MBX_TOV_SECONDS;
1054 rval = qla2x00_mailbox_command(vha, mcp);
1056 if (rval != QLA_SUCCESS) {
1058 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1060 vha->host_no, rval, mcp->mb[0]));
1063 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1071 * qla2x00_get_port_database
1072 * Issue normal/enhanced get port database mailbox command
1073 * and copy device name as necessary.
1076 * ha = adapter state pointer.
1077 * dev = structure pointer.
1078 * opt = enhanced cmd option byte.
1081 * qla2x00 local function return status code.
1087 qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
1091 mbx_cmd_t *mcp = &mc;
1092 port_database_t *pd;
1093 struct port_database_24xx *pd24;
1095 struct qla_hw_data *ha = vha->hw;
1097 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1100 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1102 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1103 "structure.\n", __func__, vha->host_no));
1104 return QLA_MEMORY_ALLOC_FAILED;
1106 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
1108 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1109 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
1110 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1111 mcp->mb[2] = MSW(pd_dma);
1112 mcp->mb[3] = LSW(pd_dma);
1113 mcp->mb[6] = MSW(MSD(pd_dma));
1114 mcp->mb[7] = LSW(MSD(pd_dma));
1115 mcp->mb[9] = vha->vp_idx;
1116 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1118 if (IS_FWI2_CAPABLE(ha)) {
1119 mcp->mb[1] = fcport->loop_id;
1121 mcp->out_mb |= MBX_10|MBX_1;
1122 mcp->in_mb |= MBX_1;
1123 } else if (HAS_EXTENDED_IDS(ha)) {
1124 mcp->mb[1] = fcport->loop_id;
1126 mcp->out_mb |= MBX_10|MBX_1;
1128 mcp->mb[1] = fcport->loop_id << 8 | opt;
1129 mcp->out_mb |= MBX_1;
1131 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1132 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
1133 mcp->flags = MBX_DMA_IN;
1134 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1135 rval = qla2x00_mailbox_command(vha, mcp);
1136 if (rval != QLA_SUCCESS)
1139 if (IS_FWI2_CAPABLE(ha)) {
1140 pd24 = (struct port_database_24xx *) pd;
1142 /* Check for logged in state. */
1143 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1144 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1145 DEBUG2(printk("%s(%ld): Unable to verify "
1146 "login-state (%x/%x) for loop_id %x\n",
1147 __func__, vha->host_no,
1148 pd24->current_login_state,
1149 pd24->last_login_state, fcport->loop_id));
1150 rval = QLA_FUNCTION_FAILED;
1154 /* Names are little-endian. */
1155 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1156 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1158 /* Get port_id of device. */
1159 fcport->d_id.b.domain = pd24->port_id[0];
1160 fcport->d_id.b.area = pd24->port_id[1];
1161 fcport->d_id.b.al_pa = pd24->port_id[2];
1162 fcport->d_id.b.rsvd_1 = 0;
1164 /* If not target must be initiator or unknown type. */
1165 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1166 fcport->port_type = FCT_INITIATOR;
1168 fcport->port_type = FCT_TARGET;
1170 /* Check for logged in state. */
1171 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1172 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1173 rval = QLA_FUNCTION_FAILED;
1177 /* Names are little-endian. */
1178 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1179 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1181 /* Get port_id of device. */
1182 fcport->d_id.b.domain = pd->port_id[0];
1183 fcport->d_id.b.area = pd->port_id[3];
1184 fcport->d_id.b.al_pa = pd->port_id[2];
1185 fcport->d_id.b.rsvd_1 = 0;
1187 /* Check for device require authentication. */
1188 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1189 (fcport->flags &= ~FCF_AUTH_REQ);
1191 /* If not target must be initiator or unknown type. */
1192 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1193 fcport->port_type = FCT_INITIATOR;
1195 fcport->port_type = FCT_TARGET;
1197 /* Passback COS information. */
1198 fcport->supported_classes = (pd->options & BIT_4) ?
1199 FC_COS_CLASS2: FC_COS_CLASS3;
1203 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1205 if (rval != QLA_SUCCESS) {
1206 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1207 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1209 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1216 * qla2x00_get_firmware_state
1217 * Get adapter firmware state.
1220 * ha = adapter block pointer.
1221 * dptr = pointer for firmware state.
1222 * TARGET_QUEUE_LOCK must be released.
1223 * ADAPTER_STATE_LOCK must be released.
1226 * qla2x00 local function return status code.
1232 qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
1236 mbx_cmd_t *mcp = &mc;
1238 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1241 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1242 mcp->out_mb = MBX_0;
1243 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1244 mcp->tov = MBX_TOV_SECONDS;
1246 rval = qla2x00_mailbox_command(vha, mcp);
1248 /* Return firmware states. */
1249 states[0] = mcp->mb[1];
1250 states[1] = mcp->mb[2];
1251 states[2] = mcp->mb[3];
1253 if (rval != QLA_SUCCESS) {
1255 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1256 "failed=%x.\n", vha->host_no, rval));
1259 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1267 * qla2x00_get_port_name
1268 * Issue get port name mailbox command.
1269 * Returned name is in big endian format.
1272 * ha = adapter block pointer.
1273 * loop_id = loop ID of device.
1274 * name = pointer for name.
1275 * TARGET_QUEUE_LOCK must be released.
1276 * ADAPTER_STATE_LOCK must be released.
1279 * qla2x00 local function return status code.
1285 qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
1290 mbx_cmd_t *mcp = &mc;
1292 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1295 mcp->mb[0] = MBC_GET_PORT_NAME;
1296 mcp->mb[9] = vha->vp_idx;
1297 mcp->out_mb = MBX_9|MBX_1|MBX_0;
1298 if (HAS_EXTENDED_IDS(vha->hw)) {
1299 mcp->mb[1] = loop_id;
1301 mcp->out_mb |= MBX_10;
1303 mcp->mb[1] = loop_id << 8 | opt;
1306 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1307 mcp->tov = MBX_TOV_SECONDS;
1309 rval = qla2x00_mailbox_command(vha, mcp);
1311 if (rval != QLA_SUCCESS) {
1313 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1314 vha->host_no, rval));
1317 /* This function returns name in big endian. */
1318 name[0] = MSB(mcp->mb[2]);
1319 name[1] = LSB(mcp->mb[2]);
1320 name[2] = MSB(mcp->mb[3]);
1321 name[3] = LSB(mcp->mb[3]);
1322 name[4] = MSB(mcp->mb[6]);
1323 name[5] = LSB(mcp->mb[6]);
1324 name[6] = MSB(mcp->mb[7]);
1325 name[7] = LSB(mcp->mb[7]);
1328 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1337 * Issue LIP reset mailbox command.
1340 * ha = adapter block pointer.
1341 * TARGET_QUEUE_LOCK must be released.
1342 * ADAPTER_STATE_LOCK must be released.
1345 * qla2x00 local function return status code.
1351 qla2x00_lip_reset(scsi_qla_host_t *vha)
1355 mbx_cmd_t *mcp = &mc;
1357 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1359 if (IS_FWI2_CAPABLE(vha->hw)) {
1360 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1363 mcp->mb[3] = vha->hw->loop_reset_delay;
1364 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1366 mcp->mb[0] = MBC_LIP_RESET;
1367 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1368 if (HAS_EXTENDED_IDS(vha->hw)) {
1369 mcp->mb[1] = 0x00ff;
1371 mcp->out_mb |= MBX_10;
1373 mcp->mb[1] = 0xff00;
1375 mcp->mb[2] = vha->hw->loop_reset_delay;
1379 mcp->tov = MBX_TOV_SECONDS;
1381 rval = qla2x00_mailbox_command(vha, mcp);
1383 if (rval != QLA_SUCCESS) {
1385 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1386 __func__, vha->host_no, rval));
1389 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1400 * ha = adapter block pointer.
1401 * sns = pointer for command.
1402 * cmd_size = command size.
1403 * buf_size = response/command size.
1404 * TARGET_QUEUE_LOCK must be released.
1405 * ADAPTER_STATE_LOCK must be released.
1408 * qla2x00 local function return status code.
1414 qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
1415 uint16_t cmd_size, size_t buf_size)
1419 mbx_cmd_t *mcp = &mc;
1421 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1424 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1425 "tov=%d.\n", vha->hw->retry_count, vha->hw->login_timeout,
1428 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1429 mcp->mb[1] = cmd_size;
1430 mcp->mb[2] = MSW(sns_phys_address);
1431 mcp->mb[3] = LSW(sns_phys_address);
1432 mcp->mb[6] = MSW(MSD(sns_phys_address));
1433 mcp->mb[7] = LSW(MSD(sns_phys_address));
1434 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1435 mcp->in_mb = MBX_0|MBX_1;
1436 mcp->buf_size = buf_size;
1437 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1438 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
1439 rval = qla2x00_mailbox_command(vha, mcp);
1441 if (rval != QLA_SUCCESS) {
1443 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1444 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1445 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1446 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1449 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", vha->host_no));
1456 qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1457 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1461 struct logio_entry_24xx *lg;
1464 struct qla_hw_data *ha = vha->hw;
1466 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1468 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1470 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1471 __func__, vha->host_no));
1472 return QLA_MEMORY_ALLOC_FAILED;
1474 memset(lg, 0, sizeof(struct logio_entry_24xx));
1476 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1477 lg->entry_count = 1;
1478 lg->nport_handle = cpu_to_le16(loop_id);
1479 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1481 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1483 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
1484 lg->port_id[0] = al_pa;
1485 lg->port_id[1] = area;
1486 lg->port_id[2] = domain;
1487 lg->vp_index = vha->vp_idx;
1488 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
1489 if (rval != QLA_SUCCESS) {
1490 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
1491 "(%x).\n", __func__, vha->host_no, rval));
1492 } else if (lg->entry_status != 0) {
1493 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1494 "-- error status (%x).\n", __func__, vha->host_no,
1496 rval = QLA_FUNCTION_FAILED;
1497 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1498 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1499 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1501 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1502 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1503 vha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1507 case LSC_SCODE_PORTID_USED:
1508 mb[0] = MBS_PORT_ID_USED;
1509 mb[1] = LSW(iop[1]);
1511 case LSC_SCODE_NPORT_USED:
1512 mb[0] = MBS_LOOP_ID_USED;
1514 case LSC_SCODE_NOLINK:
1515 case LSC_SCODE_NOIOCB:
1516 case LSC_SCODE_NOXCB:
1517 case LSC_SCODE_CMD_FAILED:
1518 case LSC_SCODE_NOFABRIC:
1519 case LSC_SCODE_FW_NOT_READY:
1520 case LSC_SCODE_NOT_LOGGED_IN:
1521 case LSC_SCODE_NOPCB:
1522 case LSC_SCODE_ELS_REJECT:
1523 case LSC_SCODE_CMD_PARAM_ERR:
1524 case LSC_SCODE_NONPORT:
1525 case LSC_SCODE_LOGGED_IN:
1526 case LSC_SCODE_NOFLOGI_ACC:
1528 mb[0] = MBS_COMMAND_ERROR;
1532 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1534 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1536 mb[0] = MBS_COMMAND_COMPLETE;
1538 if (iop[0] & BIT_4) {
1544 /* Passback COS information. */
1546 if (lg->io_parameter[7] || lg->io_parameter[8])
1547 mb[10] |= BIT_0; /* Class 2. */
1548 if (lg->io_parameter[9] || lg->io_parameter[10])
1549 mb[10] |= BIT_1; /* Class 3. */
1552 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1558 * qla2x00_login_fabric
1559 * Issue login fabric port mailbox command.
1562 * ha = adapter block pointer.
1563 * loop_id = device loop ID.
1564 * domain = device domain.
1565 * area = device area.
1566 * al_pa = device AL_PA.
1567 * status = pointer for return status.
1568 * opt = command options.
1569 * TARGET_QUEUE_LOCK must be released.
1570 * ADAPTER_STATE_LOCK must be released.
1573 * qla2x00 local function return status code.
1579 qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1580 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1584 mbx_cmd_t *mcp = &mc;
1585 struct qla_hw_data *ha = vha->hw;
1587 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", vha->host_no));
1589 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1590 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1591 if (HAS_EXTENDED_IDS(ha)) {
1592 mcp->mb[1] = loop_id;
1594 mcp->out_mb |= MBX_10;
1596 mcp->mb[1] = (loop_id << 8) | opt;
1598 mcp->mb[2] = domain;
1599 mcp->mb[3] = area << 8 | al_pa;
1601 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1602 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1604 rval = qla2x00_mailbox_command(vha, mcp);
1606 /* Return mailbox statuses. */
1613 /* COS retrieved from Get-Port-Database mailbox command. */
1617 if (rval != QLA_SUCCESS) {
1618 /* RLU tmp code: need to change main mailbox_command function to
1619 * return ok even when the mailbox completion value is not
1620 * SUCCESS. The caller needs to be responsible to interpret
1621 * the return values of this mailbox command if we're not
1622 * to change too much of the existing code.
1624 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1625 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1626 mcp->mb[0] == 0x4006)
1630 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1631 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", vha->host_no, rval,
1632 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
1635 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1643 * qla2x00_login_local_device
1644 * Issue login loop port mailbox command.
1647 * ha = adapter block pointer.
1648 * loop_id = device loop ID.
1649 * opt = command options.
1652 * Return status code.
1659 qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
1660 uint16_t *mb_ret, uint8_t opt)
1664 mbx_cmd_t *mcp = &mc;
1665 struct qla_hw_data *ha = vha->hw;
1667 if (IS_FWI2_CAPABLE(ha))
1668 return qla24xx_login_fabric(vha, fcport->loop_id,
1669 fcport->d_id.b.domain, fcport->d_id.b.area,
1670 fcport->d_id.b.al_pa, mb_ret, opt);
1672 DEBUG3(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1674 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1675 if (HAS_EXTENDED_IDS(ha))
1676 mcp->mb[1] = fcport->loop_id;
1678 mcp->mb[1] = fcport->loop_id << 8;
1680 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1681 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1682 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1684 rval = qla2x00_mailbox_command(vha, mcp);
1686 /* Return mailbox statuses. */
1687 if (mb_ret != NULL) {
1688 mb_ret[0] = mcp->mb[0];
1689 mb_ret[1] = mcp->mb[1];
1690 mb_ret[6] = mcp->mb[6];
1691 mb_ret[7] = mcp->mb[7];
1694 if (rval != QLA_SUCCESS) {
1695 /* AV tmp code: need to change main mailbox_command function to
1696 * return ok even when the mailbox completion value is not
1697 * SUCCESS. The caller needs to be responsible to interpret
1698 * the return values of this mailbox command if we're not
1699 * to change too much of the existing code.
1701 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1704 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1705 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
1706 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1707 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1708 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
1709 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1712 DEBUG3(printk("%s(%ld): done.\n", __func__, vha->host_no));
1719 qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1720 uint8_t area, uint8_t al_pa)
1723 struct logio_entry_24xx *lg;
1725 struct qla_hw_data *ha = vha->hw;
1727 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1729 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1731 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1732 __func__, vha->host_no));
1733 return QLA_MEMORY_ALLOC_FAILED;
1735 memset(lg, 0, sizeof(struct logio_entry_24xx));
1737 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1738 lg->entry_count = 1;
1739 lg->nport_handle = cpu_to_le16(loop_id);
1741 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
1742 lg->port_id[0] = al_pa;
1743 lg->port_id[1] = area;
1744 lg->port_id[2] = domain;
1745 lg->vp_index = vha->vp_idx;
1746 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
1747 if (rval != QLA_SUCCESS) {
1748 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1749 "(%x).\n", __func__, vha->host_no, rval));
1750 } else if (lg->entry_status != 0) {
1751 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1752 "-- error status (%x).\n", __func__, vha->host_no,
1754 rval = QLA_FUNCTION_FAILED;
1755 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1756 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1757 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1758 vha->host_no, le16_to_cpu(lg->comp_status),
1759 le32_to_cpu(lg->io_parameter[0]),
1760 le32_to_cpu(lg->io_parameter[1])));
1763 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1766 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1772 * qla2x00_fabric_logout
1773 * Issue logout fabric port mailbox command.
1776 * ha = adapter block pointer.
1777 * loop_id = device loop ID.
1778 * TARGET_QUEUE_LOCK must be released.
1779 * ADAPTER_STATE_LOCK must be released.
1782 * qla2x00 local function return status code.
1788 qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1789 uint8_t area, uint8_t al_pa)
1793 mbx_cmd_t *mcp = &mc;
1795 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1798 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1799 mcp->out_mb = MBX_1|MBX_0;
1800 if (HAS_EXTENDED_IDS(vha->hw)) {
1801 mcp->mb[1] = loop_id;
1803 mcp->out_mb |= MBX_10;
1805 mcp->mb[1] = loop_id << 8;
1808 mcp->in_mb = MBX_1|MBX_0;
1809 mcp->tov = MBX_TOV_SECONDS;
1811 rval = qla2x00_mailbox_command(vha, mcp);
1813 if (rval != QLA_SUCCESS) {
1815 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1816 "mbx1=%x.\n", vha->host_no, rval, mcp->mb[1]));
1819 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1827 * qla2x00_full_login_lip
1828 * Issue full login LIP mailbox command.
1831 * ha = adapter block pointer.
1832 * TARGET_QUEUE_LOCK must be released.
1833 * ADAPTER_STATE_LOCK must be released.
1836 * qla2x00 local function return status code.
1842 qla2x00_full_login_lip(scsi_qla_host_t *vha)
1846 mbx_cmd_t *mcp = &mc;
1848 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1851 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1852 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
1855 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1857 mcp->tov = MBX_TOV_SECONDS;
1859 rval = qla2x00_mailbox_command(vha, mcp);
1861 if (rval != QLA_SUCCESS) {
1863 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1864 vha->host_no, rval));
1867 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1875 * qla2x00_get_id_list
1878 * ha = adapter block pointer.
1881 * qla2x00 local function return status code.
1887 qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
1892 mbx_cmd_t *mcp = &mc;
1894 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1897 if (id_list == NULL)
1898 return QLA_FUNCTION_FAILED;
1900 mcp->mb[0] = MBC_GET_ID_LIST;
1901 mcp->out_mb = MBX_0;
1902 if (IS_FWI2_CAPABLE(vha->hw)) {
1903 mcp->mb[2] = MSW(id_list_dma);
1904 mcp->mb[3] = LSW(id_list_dma);
1905 mcp->mb[6] = MSW(MSD(id_list_dma));
1906 mcp->mb[7] = LSW(MSD(id_list_dma));
1908 mcp->mb[9] = vha->vp_idx;
1909 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
1911 mcp->mb[1] = MSW(id_list_dma);
1912 mcp->mb[2] = LSW(id_list_dma);
1913 mcp->mb[3] = MSW(MSD(id_list_dma));
1914 mcp->mb[6] = LSW(MSD(id_list_dma));
1915 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1917 mcp->in_mb = MBX_1|MBX_0;
1918 mcp->tov = MBX_TOV_SECONDS;
1920 rval = qla2x00_mailbox_command(vha, mcp);
1922 if (rval != QLA_SUCCESS) {
1924 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
1925 vha->host_no, rval));
1927 *entries = mcp->mb[1];
1928 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
1936 * qla2x00_get_resource_cnts
1937 * Get current firmware resource counts.
1940 * ha = adapter block pointer.
1943 * qla2x00 local function return status code.
1949 qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
1950 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
1951 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports)
1955 mbx_cmd_t *mcp = &mc;
1957 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1959 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
1960 mcp->out_mb = MBX_0;
1961 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1962 mcp->tov = MBX_TOV_SECONDS;
1964 rval = qla2x00_mailbox_command(vha, mcp);
1966 if (rval != QLA_SUCCESS) {
1968 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
1969 vha->host_no, mcp->mb[0]));
1971 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
1972 "mb7=%x mb10=%x mb11=%x.\n", __func__, vha->host_no,
1973 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
1974 mcp->mb[10], mcp->mb[11]));
1977 *cur_xchg_cnt = mcp->mb[3];
1979 *orig_xchg_cnt = mcp->mb[6];
1981 *cur_iocb_cnt = mcp->mb[7];
1983 *orig_iocb_cnt = mcp->mb[10];
1984 if (vha->hw->flags.npiv_supported && max_npiv_vports)
1985 *max_npiv_vports = mcp->mb[11];
1991 #if defined(QL_DEBUG_LEVEL_3)
1993 * qla2x00_get_fcal_position_map
1994 * Get FCAL (LILP) position map using mailbox command
1997 * ha = adapter state pointer.
1998 * pos_map = buffer pointer (can be NULL).
2001 * qla2x00 local function return status code.
2007 qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
2011 mbx_cmd_t *mcp = &mc;
2013 dma_addr_t pmap_dma;
2014 struct qla_hw_data *ha = vha->hw;
2016 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
2018 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
2019 __func__, vha->host_no));
2020 return QLA_MEMORY_ALLOC_FAILED;
2022 memset(pmap, 0, FCAL_MAP_SIZE);
2024 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2025 mcp->mb[2] = MSW(pmap_dma);
2026 mcp->mb[3] = LSW(pmap_dma);
2027 mcp->mb[6] = MSW(MSD(pmap_dma));
2028 mcp->mb[7] = LSW(MSD(pmap_dma));
2029 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2030 mcp->in_mb = MBX_1|MBX_0;
2031 mcp->buf_size = FCAL_MAP_SIZE;
2032 mcp->flags = MBX_DMA_IN;
2033 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2034 rval = qla2x00_mailbox_command(vha, mcp);
2036 if (rval == QLA_SUCCESS) {
2037 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2038 "size (%x)\n", __func__, vha->host_no, mcp->mb[0],
2039 mcp->mb[1], (unsigned)pmap[0]));
2040 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2043 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2045 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2047 if (rval != QLA_SUCCESS) {
2048 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2049 vha->host_no, rval));
2051 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2059 * qla2x00_get_link_status
2062 * ha = adapter block pointer.
2063 * loop_id = device loop ID.
2064 * ret_buf = pointer to link status return buffer.
2068 * BIT_0 = mem alloc error.
2069 * BIT_1 = mailbox error.
2072 qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
2073 struct link_statistics *stats, dma_addr_t stats_dma)
2077 mbx_cmd_t *mcp = &mc;
2078 uint32_t *siter, *diter, dwords;
2079 struct qla_hw_data *ha = vha->hw;
2081 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2083 mcp->mb[0] = MBC_GET_LINK_STATUS;
2084 mcp->mb[2] = MSW(stats_dma);
2085 mcp->mb[3] = LSW(stats_dma);
2086 mcp->mb[6] = MSW(MSD(stats_dma));
2087 mcp->mb[7] = LSW(MSD(stats_dma));
2088 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2090 if (IS_FWI2_CAPABLE(ha)) {
2091 mcp->mb[1] = loop_id;
2094 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2095 mcp->in_mb |= MBX_1;
2096 } else if (HAS_EXTENDED_IDS(ha)) {
2097 mcp->mb[1] = loop_id;
2099 mcp->out_mb |= MBX_10|MBX_1;
2101 mcp->mb[1] = loop_id << 8;
2102 mcp->out_mb |= MBX_1;
2104 mcp->tov = MBX_TOV_SECONDS;
2105 mcp->flags = IOCTL_CMD;
2106 rval = qla2x00_mailbox_command(vha, mcp);
2108 if (rval == QLA_SUCCESS) {
2109 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2110 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2111 __func__, vha->host_no, mcp->mb[0]));
2112 rval = QLA_FUNCTION_FAILED;
2114 /* Copy over data -- firmware data is LE. */
2115 dwords = offsetof(struct link_statistics, unused1) / 4;
2116 siter = diter = &stats->link_fail_cnt;
2118 *diter++ = le32_to_cpu(*siter++);
2122 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2123 vha->host_no, rval));
2130 qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
2131 dma_addr_t stats_dma)
2135 mbx_cmd_t *mcp = &mc;
2136 uint32_t *siter, *diter, dwords;
2138 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2140 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2141 mcp->mb[2] = MSW(stats_dma);
2142 mcp->mb[3] = LSW(stats_dma);
2143 mcp->mb[6] = MSW(MSD(stats_dma));
2144 mcp->mb[7] = LSW(MSD(stats_dma));
2145 mcp->mb[8] = sizeof(struct link_statistics) / 4;
2146 mcp->mb[9] = vha->vp_idx;
2148 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2149 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2150 mcp->tov = MBX_TOV_SECONDS;
2151 mcp->flags = IOCTL_CMD;
2152 rval = qla2x00_mailbox_command(vha, mcp);
2154 if (rval == QLA_SUCCESS) {
2155 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2156 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2157 __func__, vha->host_no, mcp->mb[0]));
2158 rval = QLA_FUNCTION_FAILED;
2160 /* Copy over data -- firmware data is LE. */
2161 dwords = sizeof(struct link_statistics) / 4;
2162 siter = diter = &stats->link_fail_cnt;
2164 *diter++ = le32_to_cpu(*siter++);
2168 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2169 vha->host_no, rval));
2176 qla24xx_abort_command(scsi_qla_host_t *vha, srb_t *sp)
2180 unsigned long flags = 0;
2182 struct abort_entry_24xx *abt;
2185 struct qla_hw_data *ha = vha->hw;
2186 struct req_que *req = ha->req;
2188 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2190 fcport = sp->fcport;
2192 spin_lock_irqsave(&ha->hardware_lock, flags);
2193 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2194 if (req->outstanding_cmds[handle] == sp)
2197 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2198 if (handle == MAX_OUTSTANDING_COMMANDS) {
2199 /* Command not found. */
2200 return QLA_FUNCTION_FAILED;
2203 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2205 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2206 __func__, vha->host_no));
2207 return QLA_MEMORY_ALLOC_FAILED;
2209 memset(abt, 0, sizeof(struct abort_entry_24xx));
2211 abt->entry_type = ABORT_IOCB_TYPE;
2212 abt->entry_count = 1;
2213 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2214 abt->handle_to_abort = handle;
2215 abt->port_id[0] = fcport->d_id.b.al_pa;
2216 abt->port_id[1] = fcport->d_id.b.area;
2217 abt->port_id[2] = fcport->d_id.b.domain;
2218 abt->vp_index = fcport->vp_idx;
2219 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
2220 if (rval != QLA_SUCCESS) {
2221 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2222 __func__, vha->host_no, rval));
2223 } else if (abt->entry_status != 0) {
2224 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2225 "-- error status (%x).\n", __func__, vha->host_no,
2226 abt->entry_status));
2227 rval = QLA_FUNCTION_FAILED;
2228 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2229 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2230 "-- completion status (%x).\n", __func__, vha->host_no,
2231 le16_to_cpu(abt->nport_handle)));
2232 rval = QLA_FUNCTION_FAILED;
2234 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2237 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2242 struct tsk_mgmt_cmd {
2244 struct tsk_mgmt_entry tsk;
2245 struct sts_entry_24xx sts;
2250 __qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
2254 struct tsk_mgmt_cmd *tsk;
2256 scsi_qla_host_t *vha;
2257 struct qla_hw_data *ha;
2259 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
2263 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
2265 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2266 "IOCB.\n", __func__, vha->host_no));
2267 return QLA_MEMORY_ALLOC_FAILED;
2269 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2271 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2272 tsk->p.tsk.entry_count = 1;
2273 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2274 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
2275 tsk->p.tsk.control_flags = cpu_to_le32(type);
2276 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2277 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2278 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2279 tsk->p.tsk.vp_index = fcport->vp_idx;
2280 if (type == TCF_LUN_RESET) {
2281 int_to_scsilun(l, &tsk->p.tsk.lun);
2282 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2283 sizeof(tsk->p.tsk.lun));
2286 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
2287 if (rval != QLA_SUCCESS) {
2288 DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
2289 "(%x).\n", __func__, vha->host_no, name, rval));
2290 } else if (tsk->p.sts.entry_status != 0) {
2291 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2292 "-- error status (%x).\n", __func__, vha->host_no,
2293 tsk->p.sts.entry_status));
2294 rval = QLA_FUNCTION_FAILED;
2295 } else if (tsk->p.sts.comp_status !=
2296 __constant_cpu_to_le16(CS_COMPLETE)) {
2297 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2298 "-- completion status (%x).\n", __func__,
2299 vha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
2300 rval = QLA_FUNCTION_FAILED;
2303 /* Issue marker IOCB. */
2304 rval2 = qla2x00_marker(vha, fcport->loop_id, l,
2305 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2306 if (rval2 != QLA_SUCCESS) {
2307 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2308 "(%x).\n", __func__, vha->host_no, rval2));
2310 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2313 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
2319 qla24xx_abort_target(struct fc_port *fcport, unsigned int l)
2321 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l);
2325 qla24xx_lun_reset(struct fc_port *fcport, unsigned int l)
2327 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l);
2331 qla2x00_system_error(scsi_qla_host_t *vha)
2335 mbx_cmd_t *mcp = &mc;
2336 struct qla_hw_data *ha = vha->hw;
2338 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
2339 return QLA_FUNCTION_FAILED;
2341 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2343 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2344 mcp->out_mb = MBX_0;
2348 rval = qla2x00_mailbox_command(vha, mcp);
2350 if (rval != QLA_SUCCESS) {
2351 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2352 vha->host_no, rval));
2354 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2361 * qla2x00_set_serdes_params() -
2367 qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
2368 uint16_t sw_em_2g, uint16_t sw_em_4g)
2372 mbx_cmd_t *mcp = &mc;
2374 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2376 mcp->mb[0] = MBC_SERDES_PARAMS;
2378 mcp->mb[2] = sw_em_1g | BIT_15;
2379 mcp->mb[3] = sw_em_2g | BIT_15;
2380 mcp->mb[4] = sw_em_4g | BIT_15;
2381 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2383 mcp->tov = MBX_TOV_SECONDS;
2385 rval = qla2x00_mailbox_command(vha, mcp);
2387 if (rval != QLA_SUCCESS) {
2389 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2390 vha->host_no, rval, mcp->mb[0]));
2393 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2400 qla2x00_stop_firmware(scsi_qla_host_t *vha)
2404 mbx_cmd_t *mcp = &mc;
2406 if (!IS_FWI2_CAPABLE(vha->hw))
2407 return QLA_FUNCTION_FAILED;
2409 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2411 mcp->mb[0] = MBC_STOP_FIRMWARE;
2412 mcp->out_mb = MBX_0;
2416 rval = qla2x00_mailbox_command(vha, mcp);
2418 if (rval != QLA_SUCCESS) {
2419 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2420 vha->host_no, rval));
2422 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2429 qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
2434 mbx_cmd_t *mcp = &mc;
2436 if (!IS_FWI2_CAPABLE(vha->hw))
2437 return QLA_FUNCTION_FAILED;
2439 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2441 mcp->mb[0] = MBC_TRACE_CONTROL;
2442 mcp->mb[1] = TC_EFT_ENABLE;
2443 mcp->mb[2] = LSW(eft_dma);
2444 mcp->mb[3] = MSW(eft_dma);
2445 mcp->mb[4] = LSW(MSD(eft_dma));
2446 mcp->mb[5] = MSW(MSD(eft_dma));
2447 mcp->mb[6] = buffers;
2448 mcp->mb[7] = TC_AEN_DISABLE;
2449 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2450 mcp->in_mb = MBX_1|MBX_0;
2451 mcp->tov = MBX_TOV_SECONDS;
2453 rval = qla2x00_mailbox_command(vha, mcp);
2454 if (rval != QLA_SUCCESS) {
2455 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2456 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2458 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2465 qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
2469 mbx_cmd_t *mcp = &mc;
2471 if (!IS_FWI2_CAPABLE(vha->hw))
2472 return QLA_FUNCTION_FAILED;
2474 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2476 mcp->mb[0] = MBC_TRACE_CONTROL;
2477 mcp->mb[1] = TC_EFT_DISABLE;
2478 mcp->out_mb = MBX_1|MBX_0;
2479 mcp->in_mb = MBX_1|MBX_0;
2480 mcp->tov = MBX_TOV_SECONDS;
2482 rval = qla2x00_mailbox_command(vha, mcp);
2483 if (rval != QLA_SUCCESS) {
2484 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2485 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2487 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2494 qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
2495 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2499 mbx_cmd_t *mcp = &mc;
2501 if (!IS_QLA25XX(vha->hw))
2502 return QLA_FUNCTION_FAILED;
2504 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2506 mcp->mb[0] = MBC_TRACE_CONTROL;
2507 mcp->mb[1] = TC_FCE_ENABLE;
2508 mcp->mb[2] = LSW(fce_dma);
2509 mcp->mb[3] = MSW(fce_dma);
2510 mcp->mb[4] = LSW(MSD(fce_dma));
2511 mcp->mb[5] = MSW(MSD(fce_dma));
2512 mcp->mb[6] = buffers;
2513 mcp->mb[7] = TC_AEN_DISABLE;
2515 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2516 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2517 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2519 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2520 mcp->tov = MBX_TOV_SECONDS;
2522 rval = qla2x00_mailbox_command(vha, mcp);
2523 if (rval != QLA_SUCCESS) {
2524 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2525 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2527 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2530 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2539 qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
2543 mbx_cmd_t *mcp = &mc;
2545 if (!IS_FWI2_CAPABLE(vha->hw))
2546 return QLA_FUNCTION_FAILED;
2548 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2550 mcp->mb[0] = MBC_TRACE_CONTROL;
2551 mcp->mb[1] = TC_FCE_DISABLE;
2552 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
2553 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2554 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2556 mcp->tov = MBX_TOV_SECONDS;
2558 rval = qla2x00_mailbox_command(vha, mcp);
2559 if (rval != QLA_SUCCESS) {
2560 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2561 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2563 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2566 *wr = (uint64_t) mcp->mb[5] << 48 |
2567 (uint64_t) mcp->mb[4] << 32 |
2568 (uint64_t) mcp->mb[3] << 16 |
2569 (uint64_t) mcp->mb[2];
2571 *rd = (uint64_t) mcp->mb[9] << 48 |
2572 (uint64_t) mcp->mb[8] << 32 |
2573 (uint64_t) mcp->mb[7] << 16 |
2574 (uint64_t) mcp->mb[6];
2581 qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint16_t addr,
2582 uint16_t off, uint16_t count)
2586 mbx_cmd_t *mcp = &mc;
2588 if (!IS_FWI2_CAPABLE(vha->hw))
2589 return QLA_FUNCTION_FAILED;
2591 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2593 mcp->mb[0] = MBC_READ_SFP;
2595 mcp->mb[2] = MSW(sfp_dma);
2596 mcp->mb[3] = LSW(sfp_dma);
2597 mcp->mb[6] = MSW(MSD(sfp_dma));
2598 mcp->mb[7] = LSW(MSD(sfp_dma));
2602 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2604 mcp->tov = MBX_TOV_SECONDS;
2606 rval = qla2x00_mailbox_command(vha, mcp);
2608 if (rval != QLA_SUCCESS) {
2609 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2610 vha->host_no, rval, mcp->mb[0]));
2612 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2619 qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
2620 uint16_t port_speed, uint16_t *mb)
2624 mbx_cmd_t *mcp = &mc;
2626 if (!IS_IIDMA_CAPABLE(vha->hw))
2627 return QLA_FUNCTION_FAILED;
2629 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2631 mcp->mb[0] = MBC_PORT_PARAMS;
2632 mcp->mb[1] = loop_id;
2634 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2635 mcp->mb[4] = mcp->mb[5] = 0;
2636 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2637 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2638 mcp->tov = MBX_TOV_SECONDS;
2640 rval = qla2x00_mailbox_command(vha, mcp);
2642 /* Return mailbox statuses. */
2651 if (rval != QLA_SUCCESS) {
2652 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2653 vha->host_no, rval));
2655 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2662 qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
2663 struct vp_rpt_id_entry_24xx *rptid_entry)
2666 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
2667 struct qla_hw_data *ha = vha->hw;
2668 scsi_qla_host_t *vp;
2670 if (rptid_entry->entry_status != 0)
2673 if (rptid_entry->format == 0) {
2674 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
2675 " number of VPs acquired %d\n", __func__, vha->host_no,
2676 MSB(rptid_entry->vp_count), LSB(rptid_entry->vp_count)));
2677 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2678 rptid_entry->port_id[2], rptid_entry->port_id[1],
2679 rptid_entry->port_id[0]));
2680 } else if (rptid_entry->format == 1) {
2682 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2684 "with port id %02x%02x%02x\n", __func__, vha->host_no,
2686 rptid_entry->port_id[2], rptid_entry->port_id[1],
2687 rptid_entry->port_id[0]));
2694 list_for_each_entry(vp, &ha->vp_list, list)
2695 if (vp_idx == vp->vp_idx)
2700 vp->d_id.b.domain = rptid_entry->port_id[2];
2701 vp->d_id.b.area = rptid_entry->port_id[1];
2702 vp->d_id.b.al_pa = rptid_entry->port_id[0];
2705 * Cannot configure here as we are still sitting on the
2706 * response queue. Handle it in dpc context.
2708 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
2709 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
2711 qla2xxx_wake_dpc(vha);
2716 * qla24xx_modify_vp_config
2717 * Change VP configuration for vha
2720 * vha = adapter block pointer.
2723 * qla2xxx local function return status code.
2729 qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2732 struct vp_config_entry_24xx *vpmod;
2733 dma_addr_t vpmod_dma;
2734 struct qla_hw_data *ha = vha->hw;
2735 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2737 /* This can be called by the parent */
2739 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
2741 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
2742 "IOCB.\n", __func__, vha->host_no));
2743 return QLA_MEMORY_ALLOC_FAILED;
2746 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2747 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2748 vpmod->entry_count = 1;
2749 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2750 vpmod->vp_count = 1;
2751 vpmod->vp_index1 = vha->vp_idx;
2752 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2753 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2754 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2755 vpmod->entry_count = 1;
2757 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
2758 if (rval != QLA_SUCCESS) {
2759 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
2760 "(%x).\n", __func__, base_vha->host_no, rval));
2761 } else if (vpmod->comp_status != 0) {
2762 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2763 "-- error status (%x).\n", __func__, base_vha->host_no,
2764 vpmod->comp_status));
2765 rval = QLA_FUNCTION_FAILED;
2766 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2767 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2768 "-- completion status (%x).\n", __func__, base_vha->host_no,
2769 le16_to_cpu(vpmod->comp_status)));
2770 rval = QLA_FUNCTION_FAILED;
2773 DEBUG11(printk("%s(%ld): done.\n", __func__,
2774 base_vha->host_no));
2775 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2777 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
2783 * qla24xx_control_vp
2784 * Enable a virtual port for given host
2787 * ha = adapter block pointer.
2788 * vhba = virtual adapter (unused)
2789 * index = index number for enabled VP
2792 * qla2xxx local function return status code.
2798 qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2802 struct vp_ctrl_entry_24xx *vce;
2804 struct qla_hw_data *ha = vha->hw;
2805 int vp_index = vha->vp_idx;
2806 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2808 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
2809 vha->host_no, vp_index));
2811 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
2812 return QLA_PARAMETER_ERROR;
2814 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2816 DEBUG2_3(printk("%s(%ld): "
2817 "failed to allocate VP Control IOCB.\n", __func__,
2818 base_vha->host_no));
2819 return QLA_MEMORY_ALLOC_FAILED;
2821 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2823 vce->entry_type = VP_CTRL_IOCB_TYPE;
2824 vce->entry_count = 1;
2825 vce->command = cpu_to_le16(cmd);
2826 vce->vp_count = __constant_cpu_to_le16(1);
2828 /* index map in firmware starts with 1; decrement index
2829 * this is ok as we never use index 0
2831 map = (vp_index - 1) / 8;
2832 pos = (vp_index - 1) & 7;
2833 mutex_lock(&ha->vport_lock);
2834 vce->vp_idx_map[map] |= 1 << pos;
2835 mutex_unlock(&ha->vport_lock);
2837 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
2838 if (rval != QLA_SUCCESS) {
2839 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
2840 "(%x).\n", __func__, base_vha->host_no, rval));
2841 printk("%s(%ld): failed to issue VP control IOCB"
2842 "(%x).\n", __func__, base_vha->host_no, rval);
2843 } else if (vce->entry_status != 0) {
2844 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2845 "-- error status (%x).\n", __func__, base_vha->host_no,
2846 vce->entry_status));
2847 printk("%s(%ld): failed to complete IOCB "
2848 "-- error status (%x).\n", __func__, base_vha->host_no,
2850 rval = QLA_FUNCTION_FAILED;
2851 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2852 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2853 "-- completion status (%x).\n", __func__, base_vha->host_no,
2854 le16_to_cpu(vce->comp_status)));
2855 printk("%s(%ld): failed to complete IOCB "
2856 "-- completion status (%x).\n", __func__, base_vha->host_no,
2857 le16_to_cpu(vce->comp_status));
2858 rval = QLA_FUNCTION_FAILED;
2860 DEBUG2(printk("%s(%ld): done.\n", __func__, base_vha->host_no));
2863 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
2869 * qla2x00_send_change_request
2870 * Receive or disable RSCN request from fabric controller
2873 * ha = adapter block pointer
2874 * format = registration format:
2876 * 1 - Fabric detected registration
2877 * 2 - N_port detected registration
2878 * 3 - Full registration
2879 * FF - clear registration
2880 * vp_idx = Virtual port index
2883 * qla2x00 local function return status code.
2890 qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
2895 mbx_cmd_t *mcp = &mc;
2898 * This command is implicitly executed by firmware during login for the
2902 return QLA_FUNCTION_FAILED;
2904 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
2905 mcp->mb[1] = format;
2906 mcp->mb[9] = vp_idx;
2907 mcp->out_mb = MBX_9|MBX_1|MBX_0;
2908 mcp->in_mb = MBX_0|MBX_1;
2909 mcp->tov = MBX_TOV_SECONDS;
2911 rval = qla2x00_mailbox_command(vha, mcp);
2913 if (rval == QLA_SUCCESS) {
2914 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2924 qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
2929 mbx_cmd_t *mcp = &mc;
2931 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2933 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
2934 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
2935 mcp->mb[8] = MSW(addr);
2936 mcp->out_mb = MBX_8|MBX_0;
2938 mcp->mb[0] = MBC_DUMP_RISC_RAM;
2939 mcp->out_mb = MBX_0;
2941 mcp->mb[1] = LSW(addr);
2942 mcp->mb[2] = MSW(req_dma);
2943 mcp->mb[3] = LSW(req_dma);
2944 mcp->mb[6] = MSW(MSD(req_dma));
2945 mcp->mb[7] = LSW(MSD(req_dma));
2946 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
2947 if (IS_FWI2_CAPABLE(vha->hw)) {
2948 mcp->mb[4] = MSW(size);
2949 mcp->mb[5] = LSW(size);
2950 mcp->out_mb |= MBX_5|MBX_4;
2952 mcp->mb[4] = LSW(size);
2953 mcp->out_mb |= MBX_4;
2957 mcp->tov = MBX_TOV_SECONDS;
2959 rval = qla2x00_mailbox_command(vha, mcp);
2961 if (rval != QLA_SUCCESS) {
2962 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
2963 vha->host_no, rval, mcp->mb[0]));
2965 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2971 /* 84XX Support **************************************************************/
2973 struct cs84xx_mgmt_cmd {
2975 struct verify_chip_entry_84xx req;
2976 struct verify_chip_rsp_84xx rsp;
2981 qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
2984 struct cs84xx_mgmt_cmd *mn;
2987 unsigned long flags;
2988 struct qla_hw_data *ha = vha->hw;
2990 DEBUG16(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2992 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
2994 DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX "
2995 "IOCB.\n", __func__, vha->host_no));
2996 return QLA_MEMORY_ALLOC_FAILED;
3000 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
3001 /* Diagnostic firmware? */
3002 /* options |= MENLO_DIAG_FW; */
3003 /* We update the firmware with only one data sequence. */
3004 options |= VCO_END_OF_DATA;
3008 memset(mn, 0, sizeof(*mn));
3009 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
3010 mn->p.req.entry_count = 1;
3011 mn->p.req.options = cpu_to_le16(options);
3013 DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__,
3015 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3018 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
3019 if (rval != QLA_SUCCESS) {
3020 DEBUG2_16(printk("%s(%ld): failed to issue Verify "
3021 "IOCB (%x).\n", __func__, vha->host_no, rval));
3025 DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__,
3027 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3030 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3031 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3032 le16_to_cpu(mn->p.rsp.failure_code) : 0;
3033 DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__,
3034 vha->host_no, status[0], status[1]));
3036 if (status[0] != CS_COMPLETE) {
3037 rval = QLA_FUNCTION_FAILED;
3038 if (!(options & VCO_DONT_UPDATE_FW)) {
3039 DEBUG2_16(printk("%s(%ld): Firmware update "
3040 "failed. Retrying without update "
3041 "firmware.\n", __func__, vha->host_no));
3042 options |= VCO_DONT_UPDATE_FW;
3043 options &= ~VCO_FORCE_UPDATE;
3047 DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n",
3048 __func__, vha->host_no,
3049 le32_to_cpu(mn->p.rsp.fw_ver)));
3051 /* NOTE: we only update OP firmware. */
3052 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3053 ha->cs84xx->op_fw_version =
3054 le32_to_cpu(mn->p.rsp.fw_ver);
3055 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3061 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3063 if (rval != QLA_SUCCESS) {
3064 DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__,
3065 vha->host_no, rval));
3067 DEBUG16(printk("%s(%ld): done.\n", __func__, vha->host_no));