2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
12 qla2x00_mbx_sem_timeout(unsigned long data)
14 struct semaphore *sem_ptr = (struct semaphore *)data;
16 DEBUG11(printk("qla2x00_sem_timeout: entered.\n"));
18 if (sem_ptr != NULL) {
22 DEBUG11(printk("qla2x00_mbx_sem_timeout: exiting.\n"));
26 * qla2x00_mailbox_command
27 * Issue mailbox command and waits for completion.
30 * ha = adapter block pointer.
31 * mcp = driver internal mbx struct pointer.
34 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
37 * 0 : QLA_SUCCESS = cmd performed success
38 * 1 : QLA_FUNCTION_FAILED (error encountered)
39 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
45 qla2x00_mailbox_command(scsi_qla_host_t *pvha, mbx_cmd_t *mcp)
48 unsigned long flags = 0;
49 device_reg_t __iomem *reg;
50 struct timer_list tmp_intr_timer;
55 uint16_t __iomem *optr;
58 unsigned long wait_time;
59 scsi_qla_host_t *ha = to_qla_parent(pvha);
62 io_lock_on = ha->flags.init_done;
65 abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
67 DEBUG11(printk("%s(%ld): entered.\n", __func__, pvha->host_no));
70 * Wait for active mailbox commands to finish by waiting at most tov
71 * seconds. This is to serialize actual issuing of mailbox cmds during
75 if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) {
76 /* Timeout occurred. Return error. */
77 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
78 "Exiting.\n", __func__, ha->host_no));
79 return QLA_FUNCTION_TIMEOUT;
83 ha->flags.mbox_busy = 1;
84 /* Save mailbox command for debug */
87 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
88 ha->host_no, mcp->mb[0]));
90 spin_lock_irqsave(&ha->hardware_lock, flags);
92 /* Load mailbox registers. */
93 if (IS_FWI2_CAPABLE(ha))
94 optr = (uint16_t __iomem *)®->isp24.mailbox0;
96 optr = (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 0);
100 mboxes = mcp->out_mb;
102 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
103 if (IS_QLA2200(ha) && cnt == 8)
105 (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 8);
107 WRT_REG_WORD(optr, *iptr);
114 #if defined(QL_DEBUG_LEVEL_1)
115 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
116 __func__, ha->host_no);
117 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
119 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
121 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
123 printk("%s(%ld): I/O address = %p.\n", __func__, ha->host_no, optr);
124 qla2x00_dump_regs(ha);
127 /* Issue set host interrupt command to send cmd out. */
128 ha->flags.mbox_int = 0;
129 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
131 /* Unlock mbx registers and wait for interrupt */
132 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
133 "jiffies=%lx.\n", __func__, ha->host_no, jiffies));
135 /* Wait for mbx cmd completion until timeout */
137 if (!abort_active && io_lock_on) {
138 /* sleep on completion semaphore */
139 DEBUG11(printk("%s(%ld): INTERRUPT MODE. Initializing timer.\n",
140 __func__, ha->host_no));
142 init_timer(&tmp_intr_timer);
143 tmp_intr_timer.data = (unsigned long)&ha->mbx_intr_sem;
144 tmp_intr_timer.expires = jiffies + mcp->tov * HZ;
145 tmp_intr_timer.function =
146 (void (*)(unsigned long))qla2x00_mbx_sem_timeout;
148 DEBUG11(printk("%s(%ld): Adding timer.\n", __func__,
150 add_timer(&tmp_intr_timer);
152 DEBUG11(printk("%s(%ld): going to unlock & sleep. "
153 "time=0x%lx.\n", __func__, ha->host_no, jiffies));
155 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
157 if (IS_FWI2_CAPABLE(ha))
158 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
160 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
161 spin_unlock_irqrestore(&ha->hardware_lock, flags);
163 /* Wait for either the timer to expire
164 * or the mbox completion interrupt
166 down(&ha->mbx_intr_sem);
168 DEBUG11(printk("%s(%ld): waking up. time=0x%lx\n", __func__,
169 ha->host_no, jiffies));
170 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
172 /* delete the timer */
173 del_timer(&tmp_intr_timer);
175 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
176 ha->host_no, command));
178 if (IS_FWI2_CAPABLE(ha))
179 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
181 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
182 spin_unlock_irqrestore(&ha->hardware_lock, flags);
184 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
185 while (!ha->flags.mbox_int) {
186 if (time_after(jiffies, wait_time))
189 /* Check for pending interrupts. */
192 if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
198 /* Check whether we timed out */
199 if (ha->flags.mbox_int) {
202 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
203 ha->host_no, command));
205 /* Got interrupt. Clear the flag. */
206 ha->flags.mbox_int = 0;
207 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
209 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
210 rval = QLA_FUNCTION_FAILED;
212 /* Load return mailbox registers. */
214 iptr = (uint16_t *)&ha->mailbox_out[0];
216 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
226 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
227 defined(QL_DEBUG_LEVEL_11)
231 if (IS_FWI2_CAPABLE(ha)) {
232 mb0 = RD_REG_WORD(®->isp24.mailbox0);
233 ictrl = RD_REG_DWORD(®->isp24.ictrl);
235 mb0 = RD_MAILBOX_REG(ha, ®->isp, 0);
236 ictrl = RD_REG_WORD(®->isp.ictrl);
238 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
239 __func__, ha->host_no, command);
240 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
241 ha->host_no, ictrl, jiffies);
242 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
244 qla2x00_dump_regs(ha);
247 rval = QLA_FUNCTION_TIMEOUT;
250 ha->flags.mbox_busy = 0;
256 DEBUG11(printk("%s(%ld): checking for additional resp "
257 "interrupt.\n", __func__, ha->host_no));
259 /* polling mode for non isp_abort commands. */
263 if (rval == QLA_FUNCTION_TIMEOUT &&
264 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
265 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
266 /* not in dpc. schedule it for dpc to take over. */
267 DEBUG(printk("%s(%ld): timeout schedule "
268 "isp_abort_needed.\n", __func__, ha->host_no));
269 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
270 "isp_abort_needed.\n", __func__, ha->host_no));
271 qla_printk(KERN_WARNING, ha,
272 "Mailbox command timeout occured. Scheduling ISP "
274 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
275 qla2xxx_wake_dpc(ha);
276 } else if (!abort_active) {
277 /* call abort directly since we are in the DPC thread */
278 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
279 __func__, ha->host_no));
280 DEBUG2_3_11(printk("%s(%ld): timeout calling "
281 "abort_isp\n", __func__, ha->host_no));
282 qla_printk(KERN_WARNING, ha,
283 "Mailbox command timeout occured. Issuing ISP "
286 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
287 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
288 if (qla2x00_abort_isp(ha)) {
289 /* Failed. retry later. */
290 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
292 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
293 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
295 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
296 __func__, ha->host_no));
300 /* Allow next mbx cmd to come in. */
302 up(&ha->mbx_cmd_sem);
305 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
306 "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no,
307 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
309 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
316 qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t risc_addr,
317 uint32_t risc_code_size)
321 mbx_cmd_t *mcp = &mc;
323 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
325 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
326 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
327 mcp->mb[8] = MSW(risc_addr);
328 mcp->out_mb = MBX_8|MBX_0;
330 mcp->mb[0] = MBC_LOAD_RISC_RAM;
333 mcp->mb[1] = LSW(risc_addr);
334 mcp->mb[2] = MSW(req_dma);
335 mcp->mb[3] = LSW(req_dma);
336 mcp->mb[6] = MSW(MSD(req_dma));
337 mcp->mb[7] = LSW(MSD(req_dma));
338 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
339 if (IS_FWI2_CAPABLE(ha)) {
340 mcp->mb[4] = MSW(risc_code_size);
341 mcp->mb[5] = LSW(risc_code_size);
342 mcp->out_mb |= MBX_5|MBX_4;
344 mcp->mb[4] = LSW(risc_code_size);
345 mcp->out_mb |= MBX_4;
351 rval = qla2x00_mailbox_command(ha, mcp);
353 if (rval != QLA_SUCCESS) {
354 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
355 ha->host_no, rval, mcp->mb[0]));
357 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
365 * Start adapter firmware.
368 * ha = adapter block pointer.
369 * TARGET_QUEUE_LOCK must be released.
370 * ADAPTER_STATE_LOCK must be released.
373 * qla2x00 local function return status code.
379 qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
383 mbx_cmd_t *mcp = &mc;
385 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
387 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
390 if (IS_FWI2_CAPABLE(ha)) {
391 mcp->mb[1] = MSW(risc_addr);
392 mcp->mb[2] = LSW(risc_addr);
394 mcp->out_mb |= MBX_3|MBX_2|MBX_1;
397 mcp->mb[1] = LSW(risc_addr);
398 mcp->out_mb |= MBX_1;
399 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
401 mcp->out_mb |= MBX_2;
407 rval = qla2x00_mailbox_command(ha, mcp);
409 if (rval != QLA_SUCCESS) {
410 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
411 ha->host_no, rval, mcp->mb[0]));
413 if (IS_FWI2_CAPABLE(ha)) {
414 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
415 __func__, ha->host_no, mcp->mb[1]));
417 DEBUG11(printk("%s(%ld): done.\n", __func__,
426 * qla2x00_get_fw_version
427 * Get firmware version.
430 * ha: adapter state pointer.
431 * major: pointer for major number.
432 * minor: pointer for minor number.
433 * subminor: pointer for subminor number.
436 * qla2x00 local function return status code.
442 qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,
443 uint16_t *subminor, uint16_t *attributes, uint32_t *memory)
447 mbx_cmd_t *mcp = &mc;
449 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
451 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
453 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
456 rval = qla2x00_mailbox_command(ha, mcp);
458 /* Return mailbox data. */
461 *subminor = mcp->mb[3];
462 *attributes = mcp->mb[6];
463 if (IS_QLA2100(ha) || IS_QLA2200(ha))
464 *memory = 0x1FFFF; /* Defaults to 128KB. */
466 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
468 if (rval != QLA_SUCCESS) {
470 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
474 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
479 * qla2x00_get_fw_options
480 * Set firmware options.
483 * ha = adapter block pointer.
484 * fwopt = pointer for firmware options.
487 * qla2x00 local function return status code.
493 qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
497 mbx_cmd_t *mcp = &mc;
499 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
501 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
503 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
506 rval = qla2x00_mailbox_command(ha, mcp);
508 if (rval != QLA_SUCCESS) {
510 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
513 fwopts[0] = mcp->mb[0];
514 fwopts[1] = mcp->mb[1];
515 fwopts[2] = mcp->mb[2];
516 fwopts[3] = mcp->mb[3];
518 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
526 * qla2x00_set_fw_options
527 * Set firmware options.
530 * ha = adapter block pointer.
531 * fwopt = pointer for firmware options.
534 * qla2x00 local function return status code.
540 qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
544 mbx_cmd_t *mcp = &mc;
546 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
548 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
549 mcp->mb[1] = fwopts[1];
550 mcp->mb[2] = fwopts[2];
551 mcp->mb[3] = fwopts[3];
552 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
554 if (IS_FWI2_CAPABLE(ha)) {
557 mcp->mb[10] = fwopts[10];
558 mcp->mb[11] = fwopts[11];
559 mcp->mb[12] = 0; /* Undocumented, but used */
560 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
564 rval = qla2x00_mailbox_command(ha, mcp);
566 fwopts[0] = mcp->mb[0];
568 if (rval != QLA_SUCCESS) {
570 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
571 ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
574 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
581 * qla2x00_mbx_reg_test
582 * Mailbox register wrap test.
585 * ha = adapter block pointer.
586 * TARGET_QUEUE_LOCK must be released.
587 * ADAPTER_STATE_LOCK must be released.
590 * qla2x00 local function return status code.
596 qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
600 mbx_cmd_t *mcp = &mc;
602 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no));
604 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
612 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
613 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
616 rval = qla2x00_mailbox_command(ha, mcp);
618 if (rval == QLA_SUCCESS) {
619 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
620 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
621 rval = QLA_FUNCTION_FAILED;
622 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
623 mcp->mb[7] != 0x2525)
624 rval = QLA_FUNCTION_FAILED;
627 if (rval != QLA_SUCCESS) {
629 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
633 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
641 * qla2x00_verify_checksum
642 * Verify firmware checksum.
645 * ha = adapter block pointer.
646 * TARGET_QUEUE_LOCK must be released.
647 * ADAPTER_STATE_LOCK must be released.
650 * qla2x00 local function return status code.
656 qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
660 mbx_cmd_t *mcp = &mc;
662 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
664 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
667 if (IS_FWI2_CAPABLE(ha)) {
668 mcp->mb[1] = MSW(risc_addr);
669 mcp->mb[2] = LSW(risc_addr);
670 mcp->out_mb |= MBX_2|MBX_1;
671 mcp->in_mb |= MBX_2|MBX_1;
673 mcp->mb[1] = LSW(risc_addr);
674 mcp->out_mb |= MBX_1;
680 rval = qla2x00_mailbox_command(ha, mcp);
682 if (rval != QLA_SUCCESS) {
683 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
684 ha->host_no, rval, IS_FWI2_CAPABLE(ha) ?
685 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
687 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
695 * Issue IOCB using mailbox command
698 * ha = adapter state pointer.
699 * buffer = buffer pointer.
700 * phys_addr = physical address of buffer.
701 * size = size of buffer.
702 * TARGET_QUEUE_LOCK must be released.
703 * ADAPTER_STATE_LOCK must be released.
706 * qla2x00 local function return status code.
712 qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr,
717 mbx_cmd_t *mcp = &mc;
719 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
721 mcp->mb[2] = MSW(phys_addr);
722 mcp->mb[3] = LSW(phys_addr);
723 mcp->mb[6] = MSW(MSD(phys_addr));
724 mcp->mb[7] = LSW(MSD(phys_addr));
725 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
726 mcp->in_mb = MBX_2|MBX_0;
729 rval = qla2x00_mailbox_command(ha, mcp);
731 if (rval != QLA_SUCCESS) {
733 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
735 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
738 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
740 /* Mask reserved bits. */
741 sts_entry->entry_status &=
742 IS_FWI2_CAPABLE(ha) ? RF_MASK_24XX :RF_MASK;
749 * qla2x00_abort_command
750 * Abort command aborts a specified IOCB.
753 * ha = adapter block pointer.
754 * sp = SB structure pointer.
757 * qla2x00 local function return status code.
763 qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
765 unsigned long flags = 0;
770 mbx_cmd_t *mcp = &mc;
772 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no));
776 spin_lock_irqsave(&ha->hardware_lock, flags);
777 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
778 if (ha->outstanding_cmds[handle] == sp)
781 spin_unlock_irqrestore(&ha->hardware_lock, flags);
783 if (handle == MAX_OUTSTANDING_COMMANDS) {
784 /* command not found */
785 return QLA_FUNCTION_FAILED;
788 mcp->mb[0] = MBC_ABORT_COMMAND;
789 if (HAS_EXTENDED_IDS(ha))
790 mcp->mb[1] = fcport->loop_id;
792 mcp->mb[1] = fcport->loop_id << 8;
793 mcp->mb[2] = (uint16_t)handle;
794 mcp->mb[3] = (uint16_t)(handle >> 16);
795 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
796 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
800 rval = qla2x00_mailbox_command(ha, mcp);
802 if (rval != QLA_SUCCESS) {
803 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
806 sp->flags |= SRB_ABORT_PENDING;
807 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
816 * qla2x00_abort_target
817 * Issue abort target mailbox command.
820 * ha = adapter block pointer.
823 * qla2x00 local function return status code.
829 qla2x00_abort_target(fc_port_t *fcport)
833 mbx_cmd_t *mcp = &mc;
839 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
842 mcp->mb[0] = MBC_ABORT_TARGET;
843 mcp->out_mb = MBX_2|MBX_1|MBX_0;
844 if (HAS_EXTENDED_IDS(ha)) {
845 mcp->mb[1] = fcport->loop_id;
847 mcp->out_mb |= MBX_10;
849 mcp->mb[1] = fcport->loop_id << 8;
851 mcp->mb[2] = ha->loop_reset_delay;
856 rval = qla2x00_mailbox_command(ha, mcp);
858 /* Issue marker command. */
859 ha->marker_needed = 1;
861 if (rval != QLA_SUCCESS) {
862 DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
866 DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
875 * qla2x00_get_adapter_id
876 * Get adapter ID and topology.
879 * ha = adapter block pointer.
880 * id = pointer for loop ID.
881 * al_pa = pointer for AL_PA.
882 * area = pointer for area.
883 * domain = pointer for domain.
884 * top = pointer for topology.
885 * TARGET_QUEUE_LOCK must be released.
886 * ADAPTER_STATE_LOCK must be released.
889 * qla2x00 local function return status code.
895 qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
896 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
900 mbx_cmd_t *mcp = &mc;
902 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
905 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
906 mcp->mb[9] = ha->vp_idx;
908 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
911 rval = qla2x00_mailbox_command(ha, mcp);
912 if (mcp->mb[0] == MBS_COMMAND_ERROR)
913 rval = QLA_COMMAND_ERROR;
917 *al_pa = LSB(mcp->mb[2]);
918 *area = MSB(mcp->mb[2]);
919 *domain = LSB(mcp->mb[3]);
921 *sw_cap = mcp->mb[7];
923 if (rval != QLA_SUCCESS) {
925 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
929 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
937 * qla2x00_get_retry_cnt
938 * Get current firmware login retry count and delay.
941 * ha = adapter block pointer.
942 * retry_cnt = pointer to login retry count.
943 * tov = pointer to login timeout value.
946 * qla2x00 local function return status code.
952 qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
958 mbx_cmd_t *mcp = &mc;
960 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
963 mcp->mb[0] = MBC_GET_RETRY_COUNT;
965 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
968 rval = qla2x00_mailbox_command(ha, mcp);
970 if (rval != QLA_SUCCESS) {
972 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
973 ha->host_no, mcp->mb[0]));
975 /* Convert returned data and check our values. */
976 *r_a_tov = mcp->mb[3] / 2;
977 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
978 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
979 /* Update to the larger values */
980 *retry_cnt = (uint8_t)mcp->mb[1];
984 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
985 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov));
992 * qla2x00_init_firmware
993 * Initialize adapter firmware.
996 * ha = adapter block pointer.
997 * dptr = Initialization control block pointer.
998 * size = size of initialization control block.
999 * TARGET_QUEUE_LOCK must be released.
1000 * ADAPTER_STATE_LOCK must be released.
1003 * qla2x00 local function return status code.
1009 qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1013 mbx_cmd_t *mcp = &mc;
1015 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1018 if (ha->flags.npiv_supported)
1019 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1021 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1023 mcp->mb[2] = MSW(ha->init_cb_dma);
1024 mcp->mb[3] = LSW(ha->init_cb_dma);
1027 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1028 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1029 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1030 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1031 mcp->buf_size = size;
1032 mcp->flags = MBX_DMA_OUT;
1034 rval = qla2x00_mailbox_command(ha, mcp);
1036 if (rval != QLA_SUCCESS) {
1038 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1040 ha->host_no, rval, mcp->mb[0]));
1043 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1051 * qla2x00_get_port_database
1052 * Issue normal/enhanced get port database mailbox command
1053 * and copy device name as necessary.
1056 * ha = adapter state pointer.
1057 * dev = structure pointer.
1058 * opt = enhanced cmd option byte.
1061 * qla2x00 local function return status code.
1067 qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1071 mbx_cmd_t *mcp = &mc;
1072 port_database_t *pd;
1073 struct port_database_24xx *pd24;
1076 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1079 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1081 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1082 "structure.\n", __func__, ha->host_no));
1083 return QLA_MEMORY_ALLOC_FAILED;
1085 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
1087 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1088 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
1089 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1090 mcp->mb[2] = MSW(pd_dma);
1091 mcp->mb[3] = LSW(pd_dma);
1092 mcp->mb[6] = MSW(MSD(pd_dma));
1093 mcp->mb[7] = LSW(MSD(pd_dma));
1094 mcp->mb[9] = ha->vp_idx;
1095 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1097 if (IS_FWI2_CAPABLE(ha)) {
1098 mcp->mb[1] = fcport->loop_id;
1100 mcp->out_mb |= MBX_10|MBX_1;
1101 mcp->in_mb |= MBX_1;
1102 } else if (HAS_EXTENDED_IDS(ha)) {
1103 mcp->mb[1] = fcport->loop_id;
1105 mcp->out_mb |= MBX_10|MBX_1;
1107 mcp->mb[1] = fcport->loop_id << 8 | opt;
1108 mcp->out_mb |= MBX_1;
1110 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1111 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
1112 mcp->flags = MBX_DMA_IN;
1113 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1114 rval = qla2x00_mailbox_command(ha, mcp);
1115 if (rval != QLA_SUCCESS)
1118 if (IS_FWI2_CAPABLE(ha)) {
1119 pd24 = (struct port_database_24xx *) pd;
1121 /* Check for logged in state. */
1122 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1123 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1124 DEBUG2(printk("%s(%ld): Unable to verify "
1125 "login-state (%x/%x) for loop_id %x\n",
1126 __func__, ha->host_no,
1127 pd24->current_login_state,
1128 pd24->last_login_state, fcport->loop_id));
1129 rval = QLA_FUNCTION_FAILED;
1133 /* Names are little-endian. */
1134 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1135 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1137 /* Get port_id of device. */
1138 fcport->d_id.b.domain = pd24->port_id[0];
1139 fcport->d_id.b.area = pd24->port_id[1];
1140 fcport->d_id.b.al_pa = pd24->port_id[2];
1141 fcport->d_id.b.rsvd_1 = 0;
1143 /* If not target must be initiator or unknown type. */
1144 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1145 fcport->port_type = FCT_INITIATOR;
1147 fcport->port_type = FCT_TARGET;
1149 /* Check for logged in state. */
1150 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1151 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1152 rval = QLA_FUNCTION_FAILED;
1156 /* Names are little-endian. */
1157 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1158 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1160 /* Get port_id of device. */
1161 fcport->d_id.b.domain = pd->port_id[0];
1162 fcport->d_id.b.area = pd->port_id[3];
1163 fcport->d_id.b.al_pa = pd->port_id[2];
1164 fcport->d_id.b.rsvd_1 = 0;
1166 /* Check for device require authentication. */
1167 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1168 (fcport->flags &= ~FCF_AUTH_REQ);
1170 /* If not target must be initiator or unknown type. */
1171 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1172 fcport->port_type = FCT_INITIATOR;
1174 fcport->port_type = FCT_TARGET;
1176 /* Passback COS information. */
1177 fcport->supported_classes = (pd->options & BIT_4) ?
1178 FC_COS_CLASS2: FC_COS_CLASS3;
1182 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1184 if (rval != QLA_SUCCESS) {
1185 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1186 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1188 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1195 * qla2x00_get_firmware_state
1196 * Get adapter firmware state.
1199 * ha = adapter block pointer.
1200 * dptr = pointer for firmware state.
1201 * TARGET_QUEUE_LOCK must be released.
1202 * ADAPTER_STATE_LOCK must be released.
1205 * qla2x00 local function return status code.
1211 qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
1215 mbx_cmd_t *mcp = &mc;
1217 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1220 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1221 mcp->out_mb = MBX_0;
1222 mcp->in_mb = MBX_2|MBX_1|MBX_0;
1225 rval = qla2x00_mailbox_command(ha, mcp);
1227 /* Return firmware state. */
1230 if (rval != QLA_SUCCESS) {
1232 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1233 "failed=%x.\n", ha->host_no, rval));
1236 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1244 * qla2x00_get_port_name
1245 * Issue get port name mailbox command.
1246 * Returned name is in big endian format.
1249 * ha = adapter block pointer.
1250 * loop_id = loop ID of device.
1251 * name = pointer for name.
1252 * TARGET_QUEUE_LOCK must be released.
1253 * ADAPTER_STATE_LOCK must be released.
1256 * qla2x00 local function return status code.
1262 qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1267 mbx_cmd_t *mcp = &mc;
1269 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1272 mcp->mb[0] = MBC_GET_PORT_NAME;
1273 mcp->mb[9] = ha->vp_idx;
1274 mcp->out_mb = MBX_9|MBX_1|MBX_0;
1275 if (HAS_EXTENDED_IDS(ha)) {
1276 mcp->mb[1] = loop_id;
1278 mcp->out_mb |= MBX_10;
1280 mcp->mb[1] = loop_id << 8 | opt;
1283 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1286 rval = qla2x00_mailbox_command(ha, mcp);
1288 if (rval != QLA_SUCCESS) {
1290 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1291 ha->host_no, rval));
1294 /* This function returns name in big endian. */
1295 name[0] = MSB(mcp->mb[2]);
1296 name[1] = LSB(mcp->mb[2]);
1297 name[2] = MSB(mcp->mb[3]);
1298 name[3] = LSB(mcp->mb[3]);
1299 name[4] = MSB(mcp->mb[6]);
1300 name[5] = LSB(mcp->mb[6]);
1301 name[6] = MSB(mcp->mb[7]);
1302 name[7] = LSB(mcp->mb[7]);
1305 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1314 * Issue LIP reset mailbox command.
1317 * ha = adapter block pointer.
1318 * TARGET_QUEUE_LOCK must be released.
1319 * ADAPTER_STATE_LOCK must be released.
1322 * qla2x00 local function return status code.
1328 qla2x00_lip_reset(scsi_qla_host_t *ha)
1332 mbx_cmd_t *mcp = &mc;
1334 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1336 if (IS_FWI2_CAPABLE(ha)) {
1337 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1340 mcp->mb[3] = ha->loop_reset_delay;
1341 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1343 mcp->mb[0] = MBC_LIP_RESET;
1344 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1345 if (HAS_EXTENDED_IDS(ha)) {
1346 mcp->mb[1] = 0x00ff;
1348 mcp->out_mb |= MBX_10;
1350 mcp->mb[1] = 0xff00;
1352 mcp->mb[2] = ha->loop_reset_delay;
1358 rval = qla2x00_mailbox_command(ha, mcp);
1360 if (rval != QLA_SUCCESS) {
1362 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1363 __func__, ha->host_no, rval));
1366 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1377 * ha = adapter block pointer.
1378 * sns = pointer for command.
1379 * cmd_size = command size.
1380 * buf_size = response/command size.
1381 * TARGET_QUEUE_LOCK must be released.
1382 * ADAPTER_STATE_LOCK must be released.
1385 * qla2x00 local function return status code.
1391 qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1392 uint16_t cmd_size, size_t buf_size)
1396 mbx_cmd_t *mcp = &mc;
1398 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1401 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1402 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov));
1404 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1405 mcp->mb[1] = cmd_size;
1406 mcp->mb[2] = MSW(sns_phys_address);
1407 mcp->mb[3] = LSW(sns_phys_address);
1408 mcp->mb[6] = MSW(MSD(sns_phys_address));
1409 mcp->mb[7] = LSW(MSD(sns_phys_address));
1410 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1411 mcp->in_mb = MBX_0|MBX_1;
1412 mcp->buf_size = buf_size;
1413 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1414 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1415 rval = qla2x00_mailbox_command(ha, mcp);
1417 if (rval != QLA_SUCCESS) {
1419 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1420 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1421 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1422 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1425 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no));
1432 qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1433 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1437 struct logio_entry_24xx *lg;
1441 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1443 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1445 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1446 __func__, ha->host_no));
1447 return QLA_MEMORY_ALLOC_FAILED;
1449 memset(lg, 0, sizeof(struct logio_entry_24xx));
1451 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1452 lg->entry_count = 1;
1453 lg->nport_handle = cpu_to_le16(loop_id);
1454 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1456 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1458 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
1459 lg->port_id[0] = al_pa;
1460 lg->port_id[1] = area;
1461 lg->port_id[2] = domain;
1462 lg->vp_index = cpu_to_le16(ha->vp_idx);
1463 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1464 if (rval != QLA_SUCCESS) {
1465 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
1466 "(%x).\n", __func__, ha->host_no, rval));
1467 } else if (lg->entry_status != 0) {
1468 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1469 "-- error status (%x).\n", __func__, ha->host_no,
1471 rval = QLA_FUNCTION_FAILED;
1472 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1473 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1474 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1476 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1477 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1478 ha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1482 case LSC_SCODE_PORTID_USED:
1483 mb[0] = MBS_PORT_ID_USED;
1484 mb[1] = LSW(iop[1]);
1486 case LSC_SCODE_NPORT_USED:
1487 mb[0] = MBS_LOOP_ID_USED;
1489 case LSC_SCODE_NOLINK:
1490 case LSC_SCODE_NOIOCB:
1491 case LSC_SCODE_NOXCB:
1492 case LSC_SCODE_CMD_FAILED:
1493 case LSC_SCODE_NOFABRIC:
1494 case LSC_SCODE_FW_NOT_READY:
1495 case LSC_SCODE_NOT_LOGGED_IN:
1496 case LSC_SCODE_NOPCB:
1497 case LSC_SCODE_ELS_REJECT:
1498 case LSC_SCODE_CMD_PARAM_ERR:
1499 case LSC_SCODE_NONPORT:
1500 case LSC_SCODE_LOGGED_IN:
1501 case LSC_SCODE_NOFLOGI_ACC:
1503 mb[0] = MBS_COMMAND_ERROR;
1507 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1509 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1511 mb[0] = MBS_COMMAND_COMPLETE;
1513 if (iop[0] & BIT_4) {
1519 /* Passback COS information. */
1521 if (lg->io_parameter[7] || lg->io_parameter[8])
1522 mb[10] |= BIT_0; /* Class 2. */
1523 if (lg->io_parameter[9] || lg->io_parameter[10])
1524 mb[10] |= BIT_1; /* Class 3. */
1527 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1533 * qla2x00_login_fabric
1534 * Issue login fabric port mailbox command.
1537 * ha = adapter block pointer.
1538 * loop_id = device loop ID.
1539 * domain = device domain.
1540 * area = device area.
1541 * al_pa = device AL_PA.
1542 * status = pointer for return status.
1543 * opt = command options.
1544 * TARGET_QUEUE_LOCK must be released.
1545 * ADAPTER_STATE_LOCK must be released.
1548 * qla2x00 local function return status code.
1554 qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1555 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1559 mbx_cmd_t *mcp = &mc;
1561 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no));
1563 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1564 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1565 if (HAS_EXTENDED_IDS(ha)) {
1566 mcp->mb[1] = loop_id;
1568 mcp->out_mb |= MBX_10;
1570 mcp->mb[1] = (loop_id << 8) | opt;
1572 mcp->mb[2] = domain;
1573 mcp->mb[3] = area << 8 | al_pa;
1575 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1576 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1578 rval = qla2x00_mailbox_command(ha, mcp);
1580 /* Return mailbox statuses. */
1587 /* COS retrieved from Get-Port-Database mailbox command. */
1591 if (rval != QLA_SUCCESS) {
1592 /* RLU tmp code: need to change main mailbox_command function to
1593 * return ok even when the mailbox completion value is not
1594 * SUCCESS. The caller needs to be responsible to interpret
1595 * the return values of this mailbox command if we're not
1596 * to change too much of the existing code.
1598 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1599 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1600 mcp->mb[0] == 0x4006)
1604 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1605 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
1606 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
1609 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1617 * qla2x00_login_local_device
1618 * Issue login loop port mailbox command.
1621 * ha = adapter block pointer.
1622 * loop_id = device loop ID.
1623 * opt = command options.
1626 * Return status code.
1633 qla2x00_login_local_device(scsi_qla_host_t *ha, fc_port_t *fcport,
1634 uint16_t *mb_ret, uint8_t opt)
1638 mbx_cmd_t *mcp = &mc;
1640 if (IS_FWI2_CAPABLE(ha))
1641 return qla24xx_login_fabric(ha, fcport->loop_id,
1642 fcport->d_id.b.domain, fcport->d_id.b.area,
1643 fcport->d_id.b.al_pa, mb_ret, opt);
1645 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1647 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1648 if (HAS_EXTENDED_IDS(ha))
1649 mcp->mb[1] = fcport->loop_id;
1651 mcp->mb[1] = fcport->loop_id << 8;
1653 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1654 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1655 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1657 rval = qla2x00_mailbox_command(ha, mcp);
1659 /* Return mailbox statuses. */
1660 if (mb_ret != NULL) {
1661 mb_ret[0] = mcp->mb[0];
1662 mb_ret[1] = mcp->mb[1];
1663 mb_ret[6] = mcp->mb[6];
1664 mb_ret[7] = mcp->mb[7];
1667 if (rval != QLA_SUCCESS) {
1668 /* AV tmp code: need to change main mailbox_command function to
1669 * return ok even when the mailbox completion value is not
1670 * SUCCESS. The caller needs to be responsible to interpret
1671 * the return values of this mailbox command if we're not
1672 * to change too much of the existing code.
1674 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1677 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1678 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1679 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1680 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1681 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1682 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1685 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no));
1692 qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1693 uint8_t area, uint8_t al_pa)
1696 struct logio_entry_24xx *lg;
1699 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1701 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1703 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1704 __func__, ha->host_no));
1705 return QLA_MEMORY_ALLOC_FAILED;
1707 memset(lg, 0, sizeof(struct logio_entry_24xx));
1709 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1710 lg->entry_count = 1;
1711 lg->nport_handle = cpu_to_le16(loop_id);
1713 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
1714 lg->port_id[0] = al_pa;
1715 lg->port_id[1] = area;
1716 lg->port_id[2] = domain;
1717 lg->vp_index = cpu_to_le16(ha->vp_idx);
1718 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1719 if (rval != QLA_SUCCESS) {
1720 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1721 "(%x).\n", __func__, ha->host_no, rval));
1722 } else if (lg->entry_status != 0) {
1723 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1724 "-- error status (%x).\n", __func__, ha->host_no,
1726 rval = QLA_FUNCTION_FAILED;
1727 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1728 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1729 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1730 ha->host_no, le16_to_cpu(lg->comp_status),
1731 le32_to_cpu(lg->io_parameter[0]),
1732 le32_to_cpu(lg->io_parameter[1])));
1735 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1738 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1744 * qla2x00_fabric_logout
1745 * Issue logout fabric port mailbox command.
1748 * ha = adapter block pointer.
1749 * loop_id = device loop ID.
1750 * TARGET_QUEUE_LOCK must be released.
1751 * ADAPTER_STATE_LOCK must be released.
1754 * qla2x00 local function return status code.
1760 qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1761 uint8_t area, uint8_t al_pa)
1765 mbx_cmd_t *mcp = &mc;
1767 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1770 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1771 mcp->out_mb = MBX_1|MBX_0;
1772 if (HAS_EXTENDED_IDS(ha)) {
1773 mcp->mb[1] = loop_id;
1775 mcp->out_mb |= MBX_10;
1777 mcp->mb[1] = loop_id << 8;
1780 mcp->in_mb = MBX_1|MBX_0;
1783 rval = qla2x00_mailbox_command(ha, mcp);
1785 if (rval != QLA_SUCCESS) {
1787 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1788 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]));
1791 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1799 * qla2x00_full_login_lip
1800 * Issue full login LIP mailbox command.
1803 * ha = adapter block pointer.
1804 * TARGET_QUEUE_LOCK must be released.
1805 * ADAPTER_STATE_LOCK must be released.
1808 * qla2x00 local function return status code.
1814 qla2x00_full_login_lip(scsi_qla_host_t *ha)
1818 mbx_cmd_t *mcp = &mc;
1820 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1823 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1824 mcp->mb[1] = IS_FWI2_CAPABLE(ha) ? BIT_3: 0;
1827 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1831 rval = qla2x00_mailbox_command(ha, mcp);
1833 if (rval != QLA_SUCCESS) {
1835 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1836 ha->host_no, rval));
1839 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1847 * qla2x00_get_id_list
1850 * ha = adapter block pointer.
1853 * qla2x00 local function return status code.
1859 qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
1864 mbx_cmd_t *mcp = &mc;
1866 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1869 if (id_list == NULL)
1870 return QLA_FUNCTION_FAILED;
1872 mcp->mb[0] = MBC_GET_ID_LIST;
1873 mcp->out_mb = MBX_0;
1874 if (IS_FWI2_CAPABLE(ha)) {
1875 mcp->mb[2] = MSW(id_list_dma);
1876 mcp->mb[3] = LSW(id_list_dma);
1877 mcp->mb[6] = MSW(MSD(id_list_dma));
1878 mcp->mb[7] = LSW(MSD(id_list_dma));
1880 mcp->mb[9] = ha->vp_idx;
1881 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
1883 mcp->mb[1] = MSW(id_list_dma);
1884 mcp->mb[2] = LSW(id_list_dma);
1885 mcp->mb[3] = MSW(MSD(id_list_dma));
1886 mcp->mb[6] = LSW(MSD(id_list_dma));
1887 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1889 mcp->in_mb = MBX_1|MBX_0;
1892 rval = qla2x00_mailbox_command(ha, mcp);
1894 if (rval != QLA_SUCCESS) {
1896 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
1897 ha->host_no, rval));
1899 *entries = mcp->mb[1];
1900 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
1908 * qla2x00_get_resource_cnts
1909 * Get current firmware resource counts.
1912 * ha = adapter block pointer.
1915 * qla2x00 local function return status code.
1921 qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
1922 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt, uint16_t *orig_iocb_cnt)
1926 mbx_cmd_t *mcp = &mc;
1928 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1930 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
1931 mcp->out_mb = MBX_0;
1932 mcp->in_mb = MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1935 rval = qla2x00_mailbox_command(ha, mcp);
1937 if (rval != QLA_SUCCESS) {
1939 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
1940 ha->host_no, mcp->mb[0]));
1942 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
1943 "mb7=%x mb10=%x.\n", __func__, ha->host_no,
1944 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
1948 *cur_xchg_cnt = mcp->mb[3];
1950 *orig_xchg_cnt = mcp->mb[6];
1952 *cur_iocb_cnt = mcp->mb[7];
1954 *orig_iocb_cnt = mcp->mb[10];
1960 #if defined(QL_DEBUG_LEVEL_3)
1962 * qla2x00_get_fcal_position_map
1963 * Get FCAL (LILP) position map using mailbox command
1966 * ha = adapter state pointer.
1967 * pos_map = buffer pointer (can be NULL).
1970 * qla2x00 local function return status code.
1976 qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
1980 mbx_cmd_t *mcp = &mc;
1982 dma_addr_t pmap_dma;
1984 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma);
1986 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
1987 __func__, ha->host_no));
1988 return QLA_MEMORY_ALLOC_FAILED;
1990 memset(pmap, 0, FCAL_MAP_SIZE);
1992 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
1993 mcp->mb[2] = MSW(pmap_dma);
1994 mcp->mb[3] = LSW(pmap_dma);
1995 mcp->mb[6] = MSW(MSD(pmap_dma));
1996 mcp->mb[7] = LSW(MSD(pmap_dma));
1997 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1998 mcp->in_mb = MBX_1|MBX_0;
1999 mcp->buf_size = FCAL_MAP_SIZE;
2000 mcp->flags = MBX_DMA_IN;
2001 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2002 rval = qla2x00_mailbox_command(ha, mcp);
2004 if (rval == QLA_SUCCESS) {
2005 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2006 "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
2007 mcp->mb[1], (unsigned)pmap[0]));
2008 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2011 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2013 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2015 if (rval != QLA_SUCCESS) {
2016 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2017 ha->host_no, rval));
2019 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2027 * qla2x00_get_link_status
2030 * ha = adapter block pointer.
2031 * loop_id = device loop ID.
2032 * ret_buf = pointer to link status return buffer.
2036 * BIT_0 = mem alloc error.
2037 * BIT_1 = mailbox error.
2040 qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
2041 link_stat_t *ret_buf, uint16_t *status)
2045 mbx_cmd_t *mcp = &mc;
2046 link_stat_t *stat_buf;
2047 dma_addr_t stat_buf_dma;
2049 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2051 stat_buf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &stat_buf_dma);
2052 if (stat_buf == NULL) {
2053 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
2054 __func__, ha->host_no));
2057 memset(stat_buf, 0, sizeof(link_stat_t));
2059 mcp->mb[0] = MBC_GET_LINK_STATUS;
2060 mcp->mb[2] = MSW(stat_buf_dma);
2061 mcp->mb[3] = LSW(stat_buf_dma);
2062 mcp->mb[6] = MSW(MSD(stat_buf_dma));
2063 mcp->mb[7] = LSW(MSD(stat_buf_dma));
2064 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2066 if (IS_FWI2_CAPABLE(ha)) {
2067 mcp->mb[1] = loop_id;
2070 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2071 mcp->in_mb |= MBX_1;
2072 } else if (HAS_EXTENDED_IDS(ha)) {
2073 mcp->mb[1] = loop_id;
2075 mcp->out_mb |= MBX_10|MBX_1;
2077 mcp->mb[1] = loop_id << 8;
2078 mcp->out_mb |= MBX_1;
2081 mcp->flags = IOCTL_CMD;
2082 rval = qla2x00_mailbox_command(ha, mcp);
2084 if (rval == QLA_SUCCESS) {
2085 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2086 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2087 __func__, ha->host_no, mcp->mb[0]));
2088 status[0] = mcp->mb[0];
2091 /* copy over data -- firmware data is LE. */
2092 ret_buf->link_fail_cnt =
2093 le32_to_cpu(stat_buf->link_fail_cnt);
2094 ret_buf->loss_sync_cnt =
2095 le32_to_cpu(stat_buf->loss_sync_cnt);
2096 ret_buf->loss_sig_cnt =
2097 le32_to_cpu(stat_buf->loss_sig_cnt);
2098 ret_buf->prim_seq_err_cnt =
2099 le32_to_cpu(stat_buf->prim_seq_err_cnt);
2100 ret_buf->inval_xmit_word_cnt =
2101 le32_to_cpu(stat_buf->inval_xmit_word_cnt);
2102 ret_buf->inval_crc_cnt =
2103 le32_to_cpu(stat_buf->inval_crc_cnt);
2105 DEBUG11(printk("%s(%ld): stat dump: fail_cnt=%d "
2106 "loss_sync=%d loss_sig=%d seq_err=%d "
2107 "inval_xmt_word=%d inval_crc=%d.\n", __func__,
2108 ha->host_no, stat_buf->link_fail_cnt,
2109 stat_buf->loss_sync_cnt, stat_buf->loss_sig_cnt,
2110 stat_buf->prim_seq_err_cnt,
2111 stat_buf->inval_xmit_word_cnt,
2112 stat_buf->inval_crc_cnt));
2116 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2117 ha->host_no, rval));
2121 dma_pool_free(ha->s_dma_pool, stat_buf, stat_buf_dma);
2127 qla24xx_get_isp_stats(scsi_qla_host_t *ha, uint32_t *dwbuf, uint32_t dwords,
2132 mbx_cmd_t *mcp = &mc;
2133 uint32_t *sbuf, *siter;
2134 dma_addr_t sbuf_dma;
2136 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2138 if (dwords > (DMA_POOL_SIZE / 4)) {
2139 DEBUG2_3_11(printk("%s(%ld): Unabled to retrieve %d DWORDs "
2140 "(max %d).\n", __func__, ha->host_no, dwords,
2141 DMA_POOL_SIZE / 4));
2144 sbuf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &sbuf_dma);
2146 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
2147 __func__, ha->host_no));
2150 memset(sbuf, 0, DMA_POOL_SIZE);
2152 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2153 mcp->mb[2] = MSW(sbuf_dma);
2154 mcp->mb[3] = LSW(sbuf_dma);
2155 mcp->mb[6] = MSW(MSD(sbuf_dma));
2156 mcp->mb[7] = LSW(MSD(sbuf_dma));
2157 mcp->mb[8] = dwords;
2159 mcp->out_mb = MBX_10|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2160 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2162 mcp->flags = IOCTL_CMD;
2163 rval = qla2x00_mailbox_command(ha, mcp);
2165 if (rval == QLA_SUCCESS) {
2166 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2167 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2168 __func__, ha->host_no, mcp->mb[0]));
2169 status[0] = mcp->mb[0];
2172 /* Copy over data -- firmware data is LE. */
2175 *dwbuf++ = le32_to_cpu(*siter++);
2179 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2180 ha->host_no, rval));
2184 dma_pool_free(ha->s_dma_pool, sbuf, sbuf_dma);
2190 qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
2194 unsigned long flags = 0;
2196 struct abort_entry_24xx *abt;
2200 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2202 fcport = sp->fcport;
2204 spin_lock_irqsave(&ha->hardware_lock, flags);
2205 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2206 if (ha->outstanding_cmds[handle] == sp)
2209 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2210 if (handle == MAX_OUTSTANDING_COMMANDS) {
2211 /* Command not found. */
2212 return QLA_FUNCTION_FAILED;
2215 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2217 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2218 __func__, ha->host_no));
2219 return QLA_MEMORY_ALLOC_FAILED;
2221 memset(abt, 0, sizeof(struct abort_entry_24xx));
2223 abt->entry_type = ABORT_IOCB_TYPE;
2224 abt->entry_count = 1;
2225 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2226 abt->handle_to_abort = handle;
2227 abt->port_id[0] = fcport->d_id.b.al_pa;
2228 abt->port_id[1] = fcport->d_id.b.area;
2229 abt->port_id[2] = fcport->d_id.b.domain;
2230 abt->vp_index = fcport->vp_idx;
2231 rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
2232 if (rval != QLA_SUCCESS) {
2233 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2234 __func__, ha->host_no, rval));
2235 } else if (abt->entry_status != 0) {
2236 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2237 "-- error status (%x).\n", __func__, ha->host_no,
2238 abt->entry_status));
2239 rval = QLA_FUNCTION_FAILED;
2240 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2241 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2242 "-- completion status (%x).\n", __func__, ha->host_no,
2243 le16_to_cpu(abt->nport_handle)));
2244 rval = QLA_FUNCTION_FAILED;
2246 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2247 sp->flags |= SRB_ABORT_PENDING;
2250 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2255 struct tsk_mgmt_cmd {
2257 struct tsk_mgmt_entry tsk;
2258 struct sts_entry_24xx sts;
2263 qla24xx_abort_target(fc_port_t *fcport)
2266 struct tsk_mgmt_cmd *tsk;
2268 scsi_qla_host_t *ha, *pha;
2273 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
2276 pha = to_qla_parent(ha);
2277 tsk = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &tsk_dma);
2279 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2280 "IOCB.\n", __func__, ha->host_no));
2281 return QLA_MEMORY_ALLOC_FAILED;
2283 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2285 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2286 tsk->p.tsk.entry_count = 1;
2287 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2288 tsk->p.tsk.timeout = __constant_cpu_to_le16(25);
2289 tsk->p.tsk.control_flags = __constant_cpu_to_le32(TCF_TARGET_RESET);
2290 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2291 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2292 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2293 tsk->p.tsk.vp_index = fcport->vp_idx;
2295 rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
2296 if (rval != QLA_SUCCESS) {
2297 DEBUG2_3_11(printk("%s(%ld): failed to issue Target Reset IOCB "
2298 "(%x).\n", __func__, ha->host_no, rval));
2300 } else if (tsk->p.sts.entry_status != 0) {
2301 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2302 "-- error status (%x).\n", __func__, ha->host_no,
2303 tsk->p.sts.entry_status));
2304 rval = QLA_FUNCTION_FAILED;
2306 } else if (tsk->p.sts.comp_status !=
2307 __constant_cpu_to_le16(CS_COMPLETE)) {
2308 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2309 "-- completion status (%x).\n", __func__,
2310 ha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
2311 rval = QLA_FUNCTION_FAILED;
2315 /* Issue marker IOCB. */
2316 rval = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
2317 if (rval != QLA_SUCCESS) {
2318 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2319 "(%x).\n", __func__, ha->host_no, rval));
2321 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2325 dma_pool_free(pha->s_dma_pool, tsk, tsk_dma);
2331 qla2x00_system_error(scsi_qla_host_t *ha)
2335 mbx_cmd_t *mcp = &mc;
2337 if (!IS_FWI2_CAPABLE(ha))
2338 return QLA_FUNCTION_FAILED;
2340 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2342 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2343 mcp->out_mb = MBX_0;
2347 rval = qla2x00_mailbox_command(ha, mcp);
2349 if (rval != QLA_SUCCESS) {
2350 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2351 ha->host_no, rval));
2353 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2360 * qla2x00_get_serdes_params() -
2366 qla2x00_get_serdes_params(scsi_qla_host_t *ha, uint16_t *sw_em_1g,
2367 uint16_t *sw_em_2g, uint16_t *sw_em_4g)
2371 mbx_cmd_t *mcp = &mc;
2373 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2375 mcp->mb[0] = MBC_SERDES_PARAMS;
2377 mcp->out_mb = MBX_1|MBX_0;
2378 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_0;
2381 rval = qla2x00_mailbox_command(ha, mcp);
2383 if (rval != QLA_SUCCESS) {
2385 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2386 ha->host_no, rval, mcp->mb[0]));
2388 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2391 *sw_em_1g = mcp->mb[2];
2393 *sw_em_2g = mcp->mb[3];
2395 *sw_em_4g = mcp->mb[4];
2402 * qla2x00_set_serdes_params() -
2408 qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
2409 uint16_t sw_em_2g, uint16_t sw_em_4g)
2413 mbx_cmd_t *mcp = &mc;
2415 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2417 mcp->mb[0] = MBC_SERDES_PARAMS;
2419 mcp->mb[2] = sw_em_1g | BIT_15;
2420 mcp->mb[3] = sw_em_2g | BIT_15;
2421 mcp->mb[4] = sw_em_4g | BIT_15;
2422 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2426 rval = qla2x00_mailbox_command(ha, mcp);
2428 if (rval != QLA_SUCCESS) {
2430 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2431 ha->host_no, rval, mcp->mb[0]));
2434 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2441 qla2x00_stop_firmware(scsi_qla_host_t *ha)
2445 mbx_cmd_t *mcp = &mc;
2447 if (!IS_FWI2_CAPABLE(ha))
2448 return QLA_FUNCTION_FAILED;
2450 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2452 mcp->mb[0] = MBC_STOP_FIRMWARE;
2453 mcp->out_mb = MBX_0;
2457 rval = qla2x00_mailbox_command(ha, mcp);
2459 if (rval != QLA_SUCCESS) {
2460 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2461 ha->host_no, rval));
2463 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2470 qla2x00_trace_control(scsi_qla_host_t *ha, uint16_t ctrl, dma_addr_t eft_dma,
2475 mbx_cmd_t *mcp = &mc;
2477 if (!IS_FWI2_CAPABLE(ha))
2478 return QLA_FUNCTION_FAILED;
2480 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2482 mcp->mb[0] = MBC_TRACE_CONTROL;
2484 mcp->out_mb = MBX_1|MBX_0;
2485 mcp->in_mb = MBX_1|MBX_0;
2486 if (ctrl == TC_ENABLE) {
2487 mcp->mb[2] = LSW(eft_dma);
2488 mcp->mb[3] = MSW(eft_dma);
2489 mcp->mb[4] = LSW(MSD(eft_dma));
2490 mcp->mb[5] = MSW(MSD(eft_dma));
2491 mcp->mb[6] = buffers;
2493 mcp->out_mb |= MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2;
2497 rval = qla2x00_mailbox_command(ha, mcp);
2499 if (rval != QLA_SUCCESS) {
2500 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2501 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2503 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2510 qla2x00_read_sfp(scsi_qla_host_t *ha, dma_addr_t sfp_dma, uint16_t addr,
2511 uint16_t off, uint16_t count)
2515 mbx_cmd_t *mcp = &mc;
2517 if (!IS_FWI2_CAPABLE(ha))
2518 return QLA_FUNCTION_FAILED;
2520 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2522 mcp->mb[0] = MBC_READ_SFP;
2524 mcp->mb[2] = MSW(sfp_dma);
2525 mcp->mb[3] = LSW(sfp_dma);
2526 mcp->mb[6] = MSW(MSD(sfp_dma));
2527 mcp->mb[7] = LSW(MSD(sfp_dma));
2531 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2535 rval = qla2x00_mailbox_command(ha, mcp);
2537 if (rval != QLA_SUCCESS) {
2538 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2539 ha->host_no, rval, mcp->mb[0]));
2541 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2548 qla2x00_get_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id,
2549 uint16_t *port_speed, uint16_t *mb)
2553 mbx_cmd_t *mcp = &mc;
2555 if (!IS_IIDMA_CAPABLE(ha))
2556 return QLA_FUNCTION_FAILED;
2558 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2560 mcp->mb[0] = MBC_PORT_PARAMS;
2561 mcp->mb[1] = loop_id;
2562 mcp->mb[2] = mcp->mb[3] = mcp->mb[4] = mcp->mb[5] = 0;
2563 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2564 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2567 rval = qla2x00_mailbox_command(ha, mcp);
2569 /* Return mailbox statuses. */
2578 if (rval != QLA_SUCCESS) {
2579 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2580 ha->host_no, rval));
2582 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2584 *port_speed = mcp->mb[3];
2591 qla2x00_set_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id,
2592 uint16_t port_speed, uint16_t *mb)
2596 mbx_cmd_t *mcp = &mc;
2598 if (!IS_IIDMA_CAPABLE(ha))
2599 return QLA_FUNCTION_FAILED;
2601 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2603 mcp->mb[0] = MBC_PORT_PARAMS;
2604 mcp->mb[1] = loop_id;
2606 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2607 mcp->mb[4] = mcp->mb[5] = 0;
2608 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2609 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2612 rval = qla2x00_mailbox_command(ha, mcp);
2614 /* Return mailbox statuses. */
2623 if (rval != QLA_SUCCESS) {
2624 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2625 ha->host_no, rval));
2627 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2634 * qla24xx_get_vp_database
2635 * Get the VP's database for all configured ports.
2638 * ha = adapter block pointer.
2639 * size = size of initialization control block.
2642 * qla2x00 local function return status code.
2648 qla24xx_get_vp_database(scsi_qla_host_t *ha, uint16_t size)
2652 mbx_cmd_t *mcp = &mc;
2654 DEBUG11(printk("scsi(%ld):%s - entered.\n",
2655 ha->host_no, __func__));
2657 mcp->mb[0] = MBC_MID_GET_VP_DATABASE;
2658 mcp->mb[2] = MSW(ha->init_cb_dma);
2659 mcp->mb[3] = LSW(ha->init_cb_dma);
2662 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
2663 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
2664 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2665 mcp->in_mb = MBX_1|MBX_0;
2666 mcp->buf_size = size;
2667 mcp->flags = MBX_DMA_OUT;
2668 mcp->tov = MBX_TOV_SECONDS;
2669 rval = qla2x00_mailbox_command(ha, mcp);
2671 if (rval != QLA_SUCCESS) {
2673 DEBUG2_3_11(printk("%s(%ld): failed=%x "
2675 __func__, ha->host_no, rval, mcp->mb[0]));
2678 DEBUG11(printk("%s(%ld): done.\n",
2679 __func__, ha->host_no));
2686 qla24xx_get_vp_entry(scsi_qla_host_t *ha, uint16_t size, int vp_id)
2690 mbx_cmd_t *mcp = &mc;
2692 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2694 mcp->mb[0] = MBC_MID_GET_VP_ENTRY;
2695 mcp->mb[2] = MSW(ha->init_cb_dma);
2696 mcp->mb[3] = LSW(ha->init_cb_dma);
2699 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
2700 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
2702 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2704 mcp->buf_size = size;
2705 mcp->flags = MBX_DMA_OUT;
2707 rval = qla2x00_mailbox_command(ha, mcp);
2709 if (rval != QLA_SUCCESS) {
2711 DEBUG2_3_11(printk("qla24xx_get_vp_entry(%ld): failed=%x "
2713 ha->host_no, rval, mcp->mb[0]));
2716 DEBUG11(printk("qla24xx_get_vp_entry(%ld): done.\n",
2724 qla24xx_report_id_acquisition(scsi_qla_host_t *ha,
2725 struct vp_rpt_id_entry_24xx *rptid_entry)
2728 scsi_qla_host_t *vha;
2730 if (rptid_entry->entry_status != 0)
2732 if (rptid_entry->entry_status != __constant_cpu_to_le16(CS_COMPLETE))
2735 if (rptid_entry->format == 0) {
2736 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
2737 " number of VPs acquired %d\n", __func__, ha->host_no,
2738 MSB(rptid_entry->vp_count), LSB(rptid_entry->vp_count)));
2739 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2740 rptid_entry->port_id[2], rptid_entry->port_id[1],
2741 rptid_entry->port_id[0]));
2742 } else if (rptid_entry->format == 1) {
2743 vp_idx = LSB(rptid_entry->vp_idx);
2744 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2746 "with port id %02x%02x%02x\n",__func__,ha->host_no,
2747 vp_idx, MSB(rptid_entry->vp_idx),
2748 rptid_entry->port_id[2], rptid_entry->port_id[1],
2749 rptid_entry->port_id[0]));
2753 if (MSB(rptid_entry->vp_idx) == 1)
2756 list_for_each_entry(vha, &ha->vp_list, vp_list)
2757 if (vp_idx == vha->vp_idx)
2763 vha->d_id.b.domain = rptid_entry->port_id[2];
2764 vha->d_id.b.area = rptid_entry->port_id[1];
2765 vha->d_id.b.al_pa = rptid_entry->port_id[0];
2768 * Cannot configure here as we are still sitting on the
2769 * response queue. Handle it in dpc context.
2771 set_bit(VP_IDX_ACQUIRED, &vha->vp_flags);
2772 set_bit(VP_DPC_NEEDED, &ha->dpc_flags);
2774 wake_up_process(ha->dpc_thread);
2779 * qla24xx_modify_vp_config
2780 * Change VP configuration for vha
2783 * vha = adapter block pointer.
2786 * qla2xxx local function return status code.
2792 qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2795 struct vp_config_entry_24xx *vpmod;
2796 dma_addr_t vpmod_dma;
2797 scsi_qla_host_t *pha;
2799 /* This can be called by the parent */
2800 pha = to_qla_parent(vha);
2802 vpmod = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
2804 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
2805 "IOCB.\n", __func__, pha->host_no));
2806 return QLA_MEMORY_ALLOC_FAILED;
2809 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2810 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2811 vpmod->entry_count = 1;
2812 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2813 vpmod->vp_count = 1;
2814 vpmod->vp_index1 = vha->vp_idx;
2815 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2816 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2817 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2818 vpmod->entry_count = 1;
2820 rval = qla2x00_issue_iocb(pha, vpmod, vpmod_dma, 0);
2821 if (rval != QLA_SUCCESS) {
2822 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
2823 "(%x).\n", __func__, pha->host_no, rval));
2824 } else if (vpmod->comp_status != 0) {
2825 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2826 "-- error status (%x).\n", __func__, pha->host_no,
2827 vpmod->comp_status));
2828 rval = QLA_FUNCTION_FAILED;
2829 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2830 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2831 "-- completion status (%x).\n", __func__, pha->host_no,
2832 le16_to_cpu(vpmod->comp_status)));
2833 rval = QLA_FUNCTION_FAILED;
2836 DEBUG11(printk("%s(%ld): done.\n", __func__, pha->host_no));
2837 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2839 dma_pool_free(pha->s_dma_pool, vpmod, vpmod_dma);
2845 * qla24xx_control_vp
2846 * Enable a virtual port for given host
2849 * ha = adapter block pointer.
2850 * vhba = virtual adapter (unused)
2851 * index = index number for enabled VP
2854 * qla2xxx local function return status code.
2860 qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2864 struct vp_ctrl_entry_24xx *vce;
2866 scsi_qla_host_t *ha = vha->parent;
2867 int vp_index = vha->vp_idx;
2869 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
2870 ha->host_no, vp_index));
2872 if (vp_index == 0 || vp_index >= MAX_MULTI_ID_LOOP)
2873 return QLA_PARAMETER_ERROR;
2875 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2877 DEBUG2_3(printk("%s(%ld): "
2878 "failed to allocate VP Control IOCB.\n", __func__,
2880 return QLA_MEMORY_ALLOC_FAILED;
2882 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2884 vce->entry_type = VP_CTRL_IOCB_TYPE;
2885 vce->entry_count = 1;
2886 vce->command = cpu_to_le16(cmd);
2887 vce->vp_count = __constant_cpu_to_le16(1);
2889 /* index map in firmware starts with 1; decrement index
2890 * this is ok as we never use index 0
2892 map = (vp_index - 1) / 8;
2893 pos = (vp_index - 1) & 7;
2894 down(&ha->vport_sem);
2895 vce->vp_idx_map[map] |= 1 << pos;
2898 rval = qla2x00_issue_iocb(ha, vce, vce_dma, 0);
2899 if (rval != QLA_SUCCESS) {
2900 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
2901 "(%x).\n", __func__, ha->host_no, rval));
2902 printk("%s(%ld): failed to issue VP control IOCB"
2903 "(%x).\n", __func__, ha->host_no, rval);
2904 } else if (vce->entry_status != 0) {
2905 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2906 "-- error status (%x).\n", __func__, ha->host_no,
2907 vce->entry_status));
2908 printk("%s(%ld): failed to complete IOCB "
2909 "-- error status (%x).\n", __func__, ha->host_no,
2911 rval = QLA_FUNCTION_FAILED;
2912 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2913 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2914 "-- completion status (%x).\n", __func__, ha->host_no,
2915 le16_to_cpu(vce->comp_status)));
2916 printk("%s(%ld): failed to complete IOCB "
2917 "-- completion status (%x).\n", __func__, ha->host_no,
2918 le16_to_cpu(vce->comp_status));
2919 rval = QLA_FUNCTION_FAILED;
2921 DEBUG2(printk("%s(%ld): done.\n", __func__, ha->host_no));
2924 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
2930 * qla2x00_send_change_request
2931 * Receive or disable RSCN request from fabric controller
2934 * ha = adapter block pointer
2935 * format = registration format:
2937 * 1 - Fabric detected registration
2938 * 2 - N_port detected registration
2939 * 3 - Full registration
2940 * FF - clear registration
2941 * vp_idx = Virtual port index
2944 * qla2x00 local function return status code.
2951 qla2x00_send_change_request(scsi_qla_host_t *ha, uint16_t format,
2956 mbx_cmd_t *mcp = &mc;
2959 * This command is implicitly executed by firmware during login for the
2963 return QLA_FUNCTION_FAILED;
2965 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
2966 mcp->mb[1] = format;
2967 mcp->mb[9] = vp_idx;
2968 mcp->out_mb = MBX_9|MBX_1|MBX_0;
2969 mcp->in_mb = MBX_0|MBX_1;
2970 mcp->tov = MBX_TOV_SECONDS;
2972 rval = qla2x00_mailbox_command(ha, mcp);
2974 if (rval == QLA_SUCCESS) {
2975 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {