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 *ha, mbx_cmd_t *mcp)
48 unsigned long flags = 0;
49 device_reg_t __iomem *reg = ha->iobase;
50 struct timer_list tmp_intr_timer;
52 uint8_t io_lock_on = ha->flags.init_done;
55 uint16_t __iomem *optr;
58 unsigned long wait_time;
61 abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
63 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
66 * Wait for active mailbox commands to finish by waiting at most tov
67 * seconds. This is to serialize actual issuing of mailbox cmds during
71 if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) {
72 /* Timeout occurred. Return error. */
73 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
74 "Exiting.\n", __func__, ha->host_no));
75 return QLA_FUNCTION_TIMEOUT;
79 ha->flags.mbox_busy = 1;
80 /* Save mailbox command for debug */
83 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
84 ha->host_no, mcp->mb[0]));
86 spin_lock_irqsave(&ha->hardware_lock, flags);
88 /* Load mailbox registers. */
89 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
90 optr = (uint16_t __iomem *)®->isp24.mailbox0;
92 optr = (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 0);
98 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
99 if (IS_QLA2200(ha) && cnt == 8)
101 (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 8);
103 WRT_REG_WORD(optr, *iptr);
110 #if defined(QL_DEBUG_LEVEL_1)
111 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
112 __func__, ha->host_no);
113 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
115 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
117 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
119 printk("%s(%ld): I/O address = %p.\n", __func__, ha->host_no, optr);
120 qla2x00_dump_regs(ha);
123 /* Issue set host interrupt command to send cmd out. */
124 ha->flags.mbox_int = 0;
125 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
127 /* Unlock mbx registers and wait for interrupt */
128 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
129 "jiffies=%lx.\n", __func__, ha->host_no, jiffies));
131 /* Wait for mbx cmd completion until timeout */
133 if (!abort_active && io_lock_on) {
134 /* sleep on completion semaphore */
135 DEBUG11(printk("%s(%ld): INTERRUPT MODE. Initializing timer.\n",
136 __func__, ha->host_no));
138 init_timer(&tmp_intr_timer);
139 tmp_intr_timer.data = (unsigned long)&ha->mbx_intr_sem;
140 tmp_intr_timer.expires = jiffies + mcp->tov * HZ;
141 tmp_intr_timer.function =
142 (void (*)(unsigned long))qla2x00_mbx_sem_timeout;
144 DEBUG11(printk("%s(%ld): Adding timer.\n", __func__,
146 add_timer(&tmp_intr_timer);
148 DEBUG11(printk("%s(%ld): going to unlock & sleep. "
149 "time=0x%lx.\n", __func__, ha->host_no, jiffies));
151 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
153 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
154 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
156 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
157 spin_unlock_irqrestore(&ha->hardware_lock, flags);
159 /* Wait for either the timer to expire
160 * or the mbox completion interrupt
162 down(&ha->mbx_intr_sem);
164 DEBUG11(printk("%s(%ld): waking up. time=0x%lx\n", __func__,
165 ha->host_no, jiffies));
166 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
168 /* delete the timer */
169 del_timer(&tmp_intr_timer);
171 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
172 ha->host_no, command));
174 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
175 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
177 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
178 spin_unlock_irqrestore(&ha->hardware_lock, flags);
180 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
181 while (!ha->flags.mbox_int) {
182 if (time_after(jiffies, wait_time))
185 /* Check for pending interrupts. */
188 if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
194 /* Check whether we timed out */
195 if (ha->flags.mbox_int) {
198 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
199 ha->host_no, command));
201 /* Got interrupt. Clear the flag. */
202 ha->flags.mbox_int = 0;
203 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
205 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
206 rval = QLA_FUNCTION_FAILED;
208 /* Load return mailbox registers. */
210 iptr = (uint16_t *)&ha->mailbox_out[0];
212 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
222 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
223 defined(QL_DEBUG_LEVEL_11)
227 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
228 mb0 = RD_REG_WORD(®->isp24.mailbox0);
229 ictrl = RD_REG_DWORD(®->isp24.ictrl);
231 mb0 = RD_MAILBOX_REG(ha, ®->isp, 0);
232 ictrl = RD_REG_WORD(®->isp.ictrl);
234 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
235 __func__, ha->host_no, command);
236 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
237 ha->host_no, ictrl, jiffies);
238 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
240 qla2x00_dump_regs(ha);
243 rval = QLA_FUNCTION_TIMEOUT;
246 ha->flags.mbox_busy = 0;
252 DEBUG11(printk("%s(%ld): checking for additional resp "
253 "interrupt.\n", __func__, ha->host_no));
255 /* polling mode for non isp_abort commands. */
259 if (rval == QLA_FUNCTION_TIMEOUT &&
260 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
261 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
262 /* not in dpc. schedule it for dpc to take over. */
263 DEBUG(printk("%s(%ld): timeout schedule "
264 "isp_abort_needed.\n", __func__, ha->host_no));
265 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
266 "isp_abort_needed.\n", __func__, ha->host_no));
267 qla_printk(KERN_WARNING, ha,
268 "Mailbox command timeout occured. Scheduling ISP "
270 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
271 qla2xxx_wake_dpc(ha);
272 } else if (!abort_active) {
273 /* call abort directly since we are in the DPC thread */
274 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
275 __func__, ha->host_no));
276 DEBUG2_3_11(printk("%s(%ld): timeout calling "
277 "abort_isp\n", __func__, ha->host_no));
278 qla_printk(KERN_WARNING, ha,
279 "Mailbox command timeout occured. Issuing ISP "
282 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
283 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
284 if (qla2x00_abort_isp(ha)) {
285 /* Failed. retry later. */
286 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
288 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
289 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
291 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
292 __func__, ha->host_no));
296 /* Allow next mbx cmd to come in. */
298 up(&ha->mbx_cmd_sem);
301 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
302 "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no,
303 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
305 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
312 qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t risc_addr,
313 uint32_t risc_code_size)
317 mbx_cmd_t *mcp = &mc;
319 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
321 if (MSW(risc_addr) || IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
322 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
323 mcp->mb[8] = MSW(risc_addr);
324 mcp->out_mb = MBX_8|MBX_0;
326 mcp->mb[0] = MBC_LOAD_RISC_RAM;
329 mcp->mb[1] = LSW(risc_addr);
330 mcp->mb[2] = MSW(req_dma);
331 mcp->mb[3] = LSW(req_dma);
332 mcp->mb[6] = MSW(MSD(req_dma));
333 mcp->mb[7] = LSW(MSD(req_dma));
334 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
335 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
336 mcp->mb[4] = MSW(risc_code_size);
337 mcp->mb[5] = LSW(risc_code_size);
338 mcp->out_mb |= MBX_5|MBX_4;
340 mcp->mb[4] = LSW(risc_code_size);
341 mcp->out_mb |= MBX_4;
347 rval = qla2x00_mailbox_command(ha, mcp);
349 if (rval != QLA_SUCCESS) {
350 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
351 ha->host_no, rval, mcp->mb[0]));
353 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
361 * Start adapter firmware.
364 * ha = adapter block pointer.
365 * TARGET_QUEUE_LOCK must be released.
366 * ADAPTER_STATE_LOCK must be released.
369 * qla2x00 local function return status code.
375 qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
379 mbx_cmd_t *mcp = &mc;
381 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
383 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
386 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
387 mcp->mb[1] = MSW(risc_addr);
388 mcp->mb[2] = LSW(risc_addr);
390 mcp->out_mb |= MBX_3|MBX_2|MBX_1;
393 mcp->mb[1] = LSW(risc_addr);
394 mcp->out_mb |= MBX_1;
395 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
397 mcp->out_mb |= MBX_2;
403 rval = qla2x00_mailbox_command(ha, mcp);
405 if (rval != QLA_SUCCESS) {
406 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
407 ha->host_no, rval, mcp->mb[0]));
409 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
410 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
411 __func__, ha->host_no, mcp->mb[1]));
413 DEBUG11(printk("%s(%ld): done.\n", __func__,
422 * qla2x00_get_fw_version
423 * Get firmware version.
426 * ha: adapter state pointer.
427 * major: pointer for major number.
428 * minor: pointer for minor number.
429 * subminor: pointer for subminor number.
432 * qla2x00 local function return status code.
438 qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,
439 uint16_t *subminor, uint16_t *attributes, uint32_t *memory)
443 mbx_cmd_t *mcp = &mc;
445 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
447 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
449 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
452 rval = qla2x00_mailbox_command(ha, mcp);
454 /* Return mailbox data. */
457 *subminor = mcp->mb[3];
458 *attributes = mcp->mb[6];
459 if (IS_QLA2100(ha) || IS_QLA2200(ha))
460 *memory = 0x1FFFF; /* Defaults to 128KB. */
462 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
464 if (rval != QLA_SUCCESS) {
466 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
470 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
475 * qla2x00_get_fw_options
476 * Set firmware options.
479 * ha = adapter block pointer.
480 * fwopt = pointer for firmware options.
483 * qla2x00 local function return status code.
489 qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
493 mbx_cmd_t *mcp = &mc;
495 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
497 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
499 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
502 rval = qla2x00_mailbox_command(ha, mcp);
504 if (rval != QLA_SUCCESS) {
506 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
509 fwopts[0] = mcp->mb[0];
510 fwopts[1] = mcp->mb[1];
511 fwopts[2] = mcp->mb[2];
512 fwopts[3] = mcp->mb[3];
514 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
522 * qla2x00_set_fw_options
523 * Set firmware options.
526 * ha = adapter block pointer.
527 * fwopt = pointer for firmware options.
530 * qla2x00 local function return status code.
536 qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
540 mbx_cmd_t *mcp = &mc;
542 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
544 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
545 mcp->mb[1] = fwopts[1];
546 mcp->mb[2] = fwopts[2];
547 mcp->mb[3] = fwopts[3];
548 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
550 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
553 mcp->mb[10] = fwopts[10];
554 mcp->mb[11] = fwopts[11];
555 mcp->mb[12] = 0; /* Undocumented, but used */
556 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
560 rval = qla2x00_mailbox_command(ha, mcp);
562 fwopts[0] = mcp->mb[0];
564 if (rval != QLA_SUCCESS) {
566 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
567 ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
570 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
577 * qla2x00_mbx_reg_test
578 * Mailbox register wrap test.
581 * ha = adapter block pointer.
582 * TARGET_QUEUE_LOCK must be released.
583 * ADAPTER_STATE_LOCK must be released.
586 * qla2x00 local function return status code.
592 qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
596 mbx_cmd_t *mcp = &mc;
598 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no));
600 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
608 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
609 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
612 rval = qla2x00_mailbox_command(ha, mcp);
614 if (rval == QLA_SUCCESS) {
615 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
616 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
617 rval = QLA_FUNCTION_FAILED;
618 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
619 mcp->mb[7] != 0x2525)
620 rval = QLA_FUNCTION_FAILED;
623 if (rval != QLA_SUCCESS) {
625 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
629 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
637 * qla2x00_verify_checksum
638 * Verify firmware checksum.
641 * ha = adapter block pointer.
642 * TARGET_QUEUE_LOCK must be released.
643 * ADAPTER_STATE_LOCK must be released.
646 * qla2x00 local function return status code.
652 qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
656 mbx_cmd_t *mcp = &mc;
658 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
660 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
663 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
664 mcp->mb[1] = MSW(risc_addr);
665 mcp->mb[2] = LSW(risc_addr);
666 mcp->out_mb |= MBX_2|MBX_1;
667 mcp->in_mb |= MBX_2|MBX_1;
669 mcp->mb[1] = LSW(risc_addr);
670 mcp->out_mb |= MBX_1;
676 rval = qla2x00_mailbox_command(ha, mcp);
678 if (rval != QLA_SUCCESS) {
679 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
680 ha->host_no, rval, (IS_QLA24XX(ha) || IS_QLA54XX(ha) ?
681 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1])));
683 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
691 * Issue IOCB using mailbox command
694 * ha = adapter state pointer.
695 * buffer = buffer pointer.
696 * phys_addr = physical address of buffer.
697 * size = size of buffer.
698 * TARGET_QUEUE_LOCK must be released.
699 * ADAPTER_STATE_LOCK must be released.
702 * qla2x00 local function return status code.
708 qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr,
713 mbx_cmd_t *mcp = &mc;
715 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
717 mcp->mb[2] = MSW(phys_addr);
718 mcp->mb[3] = LSW(phys_addr);
719 mcp->mb[6] = MSW(MSD(phys_addr));
720 mcp->mb[7] = LSW(MSD(phys_addr));
721 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
722 mcp->in_mb = MBX_2|MBX_0;
725 rval = qla2x00_mailbox_command(ha, mcp);
727 if (rval != QLA_SUCCESS) {
729 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
731 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
734 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
736 /* Mask reserved bits. */
737 sts_entry->entry_status &=
738 IS_QLA24XX(ha) || IS_QLA54XX(ha) ? RF_MASK_24XX :RF_MASK;
745 * qla2x00_abort_command
746 * Abort command aborts a specified IOCB.
749 * ha = adapter block pointer.
750 * sp = SB structure pointer.
753 * qla2x00 local function return status code.
759 qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
761 unsigned long flags = 0;
766 mbx_cmd_t *mcp = &mc;
768 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no));
772 spin_lock_irqsave(&ha->hardware_lock, flags);
773 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
774 if (ha->outstanding_cmds[handle] == sp)
777 spin_unlock_irqrestore(&ha->hardware_lock, flags);
779 if (handle == MAX_OUTSTANDING_COMMANDS) {
780 /* command not found */
781 return QLA_FUNCTION_FAILED;
784 mcp->mb[0] = MBC_ABORT_COMMAND;
785 if (HAS_EXTENDED_IDS(ha))
786 mcp->mb[1] = fcport->loop_id;
788 mcp->mb[1] = fcport->loop_id << 8;
789 mcp->mb[2] = (uint16_t)handle;
790 mcp->mb[3] = (uint16_t)(handle >> 16);
791 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
792 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
796 rval = qla2x00_mailbox_command(ha, mcp);
798 if (rval != QLA_SUCCESS) {
799 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
802 sp->flags |= SRB_ABORT_PENDING;
803 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
812 * qla2x00_abort_target
813 * Issue abort target mailbox command.
816 * ha = adapter block pointer.
819 * qla2x00 local function return status code.
825 qla2x00_abort_target(fc_port_t *fcport)
829 mbx_cmd_t *mcp = &mc;
835 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
838 mcp->mb[0] = MBC_ABORT_TARGET;
839 mcp->out_mb = MBX_2|MBX_1|MBX_0;
840 if (HAS_EXTENDED_IDS(ha)) {
841 mcp->mb[1] = fcport->loop_id;
843 mcp->out_mb |= MBX_10;
845 mcp->mb[1] = fcport->loop_id << 8;
847 mcp->mb[2] = ha->loop_reset_delay;
852 rval = qla2x00_mailbox_command(ha, mcp);
854 /* Issue marker command. */
855 ha->marker_needed = 1;
857 if (rval != QLA_SUCCESS) {
858 DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
862 DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
871 * qla2x00_get_adapter_id
872 * Get adapter ID and topology.
875 * ha = adapter block pointer.
876 * id = pointer for loop ID.
877 * al_pa = pointer for AL_PA.
878 * area = pointer for area.
879 * domain = pointer for domain.
880 * top = pointer for topology.
881 * TARGET_QUEUE_LOCK must be released.
882 * ADAPTER_STATE_LOCK must be released.
885 * qla2x00 local function return status code.
891 qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
892 uint8_t *area, uint8_t *domain, uint16_t *top)
896 mbx_cmd_t *mcp = &mc;
898 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
901 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
903 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
906 rval = qla2x00_mailbox_command(ha, mcp);
907 if (mcp->mb[0] == MBS_COMMAND_ERROR)
908 rval = QLA_COMMAND_ERROR;
912 *al_pa = LSB(mcp->mb[2]);
913 *area = MSB(mcp->mb[2]);
914 *domain = LSB(mcp->mb[3]);
917 if (rval != QLA_SUCCESS) {
919 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
923 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
931 * qla2x00_get_retry_cnt
932 * Get current firmware login retry count and delay.
935 * ha = adapter block pointer.
936 * retry_cnt = pointer to login retry count.
937 * tov = pointer to login timeout value.
940 * qla2x00 local function return status code.
946 qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
952 mbx_cmd_t *mcp = &mc;
954 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
957 mcp->mb[0] = MBC_GET_RETRY_COUNT;
959 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
962 rval = qla2x00_mailbox_command(ha, mcp);
964 if (rval != QLA_SUCCESS) {
966 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
967 ha->host_no, mcp->mb[0]));
969 /* Convert returned data and check our values. */
970 *r_a_tov = mcp->mb[3] / 2;
971 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
972 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
973 /* Update to the larger values */
974 *retry_cnt = (uint8_t)mcp->mb[1];
978 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
979 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov));
986 * qla2x00_init_firmware
987 * Initialize adapter firmware.
990 * ha = adapter block pointer.
991 * dptr = Initialization control block pointer.
992 * size = size of initialization control block.
993 * TARGET_QUEUE_LOCK must be released.
994 * ADAPTER_STATE_LOCK must be released.
997 * qla2x00 local function return status code.
1003 qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1007 mbx_cmd_t *mcp = &mc;
1009 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1012 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1013 mcp->mb[2] = MSW(ha->init_cb_dma);
1014 mcp->mb[3] = LSW(ha->init_cb_dma);
1017 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1018 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1019 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1020 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1021 mcp->buf_size = size;
1022 mcp->flags = MBX_DMA_OUT;
1024 rval = qla2x00_mailbox_command(ha, mcp);
1026 if (rval != QLA_SUCCESS) {
1028 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1030 ha->host_no, rval, mcp->mb[0]));
1033 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1041 * qla2x00_get_port_database
1042 * Issue normal/enhanced get port database mailbox command
1043 * and copy device name as necessary.
1046 * ha = adapter state pointer.
1047 * dev = structure pointer.
1048 * opt = enhanced cmd option byte.
1051 * qla2x00 local function return status code.
1057 qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1061 mbx_cmd_t *mcp = &mc;
1062 port_database_t *pd;
1063 struct port_database_24xx *pd24;
1066 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1069 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1071 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1072 "structure.\n", __func__, ha->host_no));
1073 return QLA_MEMORY_ALLOC_FAILED;
1075 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
1077 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1078 if (opt != 0 && !IS_QLA24XX(ha) && !IS_QLA54XX(ha))
1079 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1080 mcp->mb[2] = MSW(pd_dma);
1081 mcp->mb[3] = LSW(pd_dma);
1082 mcp->mb[6] = MSW(MSD(pd_dma));
1083 mcp->mb[7] = LSW(MSD(pd_dma));
1084 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1086 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
1087 mcp->mb[1] = fcport->loop_id;
1089 mcp->out_mb |= MBX_10|MBX_1;
1090 mcp->in_mb |= MBX_1;
1091 } else if (HAS_EXTENDED_IDS(ha)) {
1092 mcp->mb[1] = fcport->loop_id;
1094 mcp->out_mb |= MBX_10|MBX_1;
1096 mcp->mb[1] = fcport->loop_id << 8 | opt;
1097 mcp->out_mb |= MBX_1;
1099 mcp->buf_size = (IS_QLA24XX(ha) || IS_QLA54XX(ha) ?
1100 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE);
1101 mcp->flags = MBX_DMA_IN;
1102 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1103 rval = qla2x00_mailbox_command(ha, mcp);
1104 if (rval != QLA_SUCCESS)
1107 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
1108 pd24 = (struct port_database_24xx *) pd;
1110 /* Check for logged in state. */
1111 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1112 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1113 DEBUG2(printk("%s(%ld): Unable to verify "
1114 "login-state (%x/%x) for loop_id %x\n",
1115 __func__, ha->host_no,
1116 pd24->current_login_state,
1117 pd24->last_login_state, fcport->loop_id));
1118 rval = QLA_FUNCTION_FAILED;
1122 /* Names are little-endian. */
1123 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1124 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1126 /* Get port_id of device. */
1127 fcport->d_id.b.domain = pd24->port_id[0];
1128 fcport->d_id.b.area = pd24->port_id[1];
1129 fcport->d_id.b.al_pa = pd24->port_id[2];
1130 fcport->d_id.b.rsvd_1 = 0;
1132 /* If not target must be initiator or unknown type. */
1133 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1134 fcport->port_type = FCT_INITIATOR;
1136 fcport->port_type = FCT_TARGET;
1138 /* Check for logged in state. */
1139 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1140 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1141 rval = QLA_FUNCTION_FAILED;
1145 /* Names are little-endian. */
1146 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1147 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1149 /* Get port_id of device. */
1150 fcport->d_id.b.domain = pd->port_id[0];
1151 fcport->d_id.b.area = pd->port_id[3];
1152 fcport->d_id.b.al_pa = pd->port_id[2];
1153 fcport->d_id.b.rsvd_1 = 0;
1155 /* Check for device require authentication. */
1156 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1157 (fcport->flags &= ~FCF_AUTH_REQ);
1159 /* If not target must be initiator or unknown type. */
1160 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1161 fcport->port_type = FCT_INITIATOR;
1163 fcport->port_type = FCT_TARGET;
1165 /* Passback COS information. */
1166 fcport->supported_classes = (pd->options & BIT_4) ?
1167 FC_COS_CLASS2: FC_COS_CLASS3;
1171 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1173 if (rval != QLA_SUCCESS) {
1174 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1175 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1177 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1184 * qla2x00_get_firmware_state
1185 * Get adapter firmware state.
1188 * ha = adapter block pointer.
1189 * dptr = pointer for firmware state.
1190 * TARGET_QUEUE_LOCK must be released.
1191 * ADAPTER_STATE_LOCK must be released.
1194 * qla2x00 local function return status code.
1200 qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
1204 mbx_cmd_t *mcp = &mc;
1206 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1209 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1210 mcp->out_mb = MBX_0;
1211 mcp->in_mb = MBX_2|MBX_1|MBX_0;
1214 rval = qla2x00_mailbox_command(ha, mcp);
1216 /* Return firmware state. */
1219 if (rval != QLA_SUCCESS) {
1221 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1222 "failed=%x.\n", ha->host_no, rval));
1225 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1233 * qla2x00_get_port_name
1234 * Issue get port name mailbox command.
1235 * Returned name is in big endian format.
1238 * ha = adapter block pointer.
1239 * loop_id = loop ID of device.
1240 * name = pointer for name.
1241 * TARGET_QUEUE_LOCK must be released.
1242 * ADAPTER_STATE_LOCK must be released.
1245 * qla2x00 local function return status code.
1251 qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1256 mbx_cmd_t *mcp = &mc;
1258 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1261 mcp->mb[0] = MBC_GET_PORT_NAME;
1262 mcp->out_mb = MBX_1|MBX_0;
1263 if (HAS_EXTENDED_IDS(ha)) {
1264 mcp->mb[1] = loop_id;
1266 mcp->out_mb |= MBX_10;
1268 mcp->mb[1] = loop_id << 8 | opt;
1271 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1274 rval = qla2x00_mailbox_command(ha, mcp);
1276 if (rval != QLA_SUCCESS) {
1278 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1279 ha->host_no, rval));
1282 /* This function returns name in big endian. */
1283 name[0] = LSB(mcp->mb[2]);
1284 name[1] = MSB(mcp->mb[2]);
1285 name[2] = LSB(mcp->mb[3]);
1286 name[3] = MSB(mcp->mb[3]);
1287 name[4] = LSB(mcp->mb[6]);
1288 name[5] = MSB(mcp->mb[6]);
1289 name[6] = LSB(mcp->mb[7]);
1290 name[7] = MSB(mcp->mb[7]);
1293 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1302 * Issue LIP reset mailbox command.
1305 * ha = adapter block pointer.
1306 * TARGET_QUEUE_LOCK must be released.
1307 * ADAPTER_STATE_LOCK must be released.
1310 * qla2x00 local function return status code.
1316 qla2x00_lip_reset(scsi_qla_host_t *ha)
1320 mbx_cmd_t *mcp = &mc;
1322 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1324 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
1325 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1328 mcp->mb[3] = ha->loop_reset_delay;
1329 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1331 mcp->mb[0] = MBC_LIP_RESET;
1332 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1333 if (HAS_EXTENDED_IDS(ha)) {
1334 mcp->mb[1] = 0x00ff;
1336 mcp->out_mb |= MBX_10;
1338 mcp->mb[1] = 0xff00;
1340 mcp->mb[2] = ha->loop_reset_delay;
1346 rval = qla2x00_mailbox_command(ha, mcp);
1348 if (rval != QLA_SUCCESS) {
1350 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1351 __func__, ha->host_no, rval));
1354 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1365 * ha = adapter block pointer.
1366 * sns = pointer for command.
1367 * cmd_size = command size.
1368 * buf_size = response/command size.
1369 * TARGET_QUEUE_LOCK must be released.
1370 * ADAPTER_STATE_LOCK must be released.
1373 * qla2x00 local function return status code.
1379 qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1380 uint16_t cmd_size, size_t buf_size)
1384 mbx_cmd_t *mcp = &mc;
1386 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1389 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1390 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov));
1392 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1393 mcp->mb[1] = cmd_size;
1394 mcp->mb[2] = MSW(sns_phys_address);
1395 mcp->mb[3] = LSW(sns_phys_address);
1396 mcp->mb[6] = MSW(MSD(sns_phys_address));
1397 mcp->mb[7] = LSW(MSD(sns_phys_address));
1398 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1399 mcp->in_mb = MBX_0|MBX_1;
1400 mcp->buf_size = buf_size;
1401 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1402 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1403 rval = qla2x00_mailbox_command(ha, mcp);
1405 if (rval != QLA_SUCCESS) {
1407 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1408 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1409 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1410 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1413 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no));
1420 qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1421 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1425 struct logio_entry_24xx *lg;
1429 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1431 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1433 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1434 __func__, ha->host_no));
1435 return QLA_MEMORY_ALLOC_FAILED;
1437 memset(lg, 0, sizeof(struct logio_entry_24xx));
1439 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1440 lg->entry_count = 1;
1441 lg->nport_handle = cpu_to_le16(loop_id);
1442 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1444 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1446 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
1447 lg->port_id[0] = al_pa;
1448 lg->port_id[1] = area;
1449 lg->port_id[2] = domain;
1450 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1451 if (rval != QLA_SUCCESS) {
1452 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
1453 "(%x).\n", __func__, ha->host_no, rval));
1454 } else if (lg->entry_status != 0) {
1455 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1456 "-- error status (%x).\n", __func__, ha->host_no,
1458 rval = QLA_FUNCTION_FAILED;
1459 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1460 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1461 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1463 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1464 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1465 ha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1469 case LSC_SCODE_PORTID_USED:
1470 mb[0] = MBS_PORT_ID_USED;
1471 mb[1] = LSW(iop[1]);
1473 case LSC_SCODE_NPORT_USED:
1474 mb[0] = MBS_LOOP_ID_USED;
1476 case LSC_SCODE_NOLINK:
1477 case LSC_SCODE_NOIOCB:
1478 case LSC_SCODE_NOXCB:
1479 case LSC_SCODE_CMD_FAILED:
1480 case LSC_SCODE_NOFABRIC:
1481 case LSC_SCODE_FW_NOT_READY:
1482 case LSC_SCODE_NOT_LOGGED_IN:
1483 case LSC_SCODE_NOPCB:
1484 case LSC_SCODE_ELS_REJECT:
1485 case LSC_SCODE_CMD_PARAM_ERR:
1486 case LSC_SCODE_NONPORT:
1487 case LSC_SCODE_LOGGED_IN:
1488 case LSC_SCODE_NOFLOGI_ACC:
1490 mb[0] = MBS_COMMAND_ERROR;
1494 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1496 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1498 mb[0] = MBS_COMMAND_COMPLETE;
1500 if (iop[0] & BIT_4) {
1506 /* Passback COS information. */
1508 if (lg->io_parameter[7] || lg->io_parameter[8])
1509 mb[10] |= BIT_0; /* Class 2. */
1510 if (lg->io_parameter[9] || lg->io_parameter[10])
1511 mb[10] |= BIT_1; /* Class 3. */
1514 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1520 * qla2x00_login_fabric
1521 * Issue login fabric port mailbox command.
1524 * ha = adapter block pointer.
1525 * loop_id = device loop ID.
1526 * domain = device domain.
1527 * area = device area.
1528 * al_pa = device AL_PA.
1529 * status = pointer for return status.
1530 * opt = command options.
1531 * TARGET_QUEUE_LOCK must be released.
1532 * ADAPTER_STATE_LOCK must be released.
1535 * qla2x00 local function return status code.
1541 qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1542 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1546 mbx_cmd_t *mcp = &mc;
1548 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no));
1550 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1551 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1552 if (HAS_EXTENDED_IDS(ha)) {
1553 mcp->mb[1] = loop_id;
1555 mcp->out_mb |= MBX_10;
1557 mcp->mb[1] = (loop_id << 8) | opt;
1559 mcp->mb[2] = domain;
1560 mcp->mb[3] = area << 8 | al_pa;
1562 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1563 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1565 rval = qla2x00_mailbox_command(ha, mcp);
1567 /* Return mailbox statuses. */
1574 /* COS retrieved from Get-Port-Database mailbox command. */
1578 if (rval != QLA_SUCCESS) {
1579 /* RLU tmp code: need to change main mailbox_command function to
1580 * return ok even when the mailbox completion value is not
1581 * SUCCESS. The caller needs to be responsible to interpret
1582 * the return values of this mailbox command if we're not
1583 * to change too much of the existing code.
1585 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1586 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1587 mcp->mb[0] == 0x4006)
1591 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1592 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
1593 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
1596 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1604 * qla2x00_login_local_device
1605 * Issue login loop port mailbox command.
1608 * ha = adapter block pointer.
1609 * loop_id = device loop ID.
1610 * opt = command options.
1613 * Return status code.
1620 qla2x00_login_local_device(scsi_qla_host_t *ha, fc_port_t *fcport,
1621 uint16_t *mb_ret, uint8_t opt)
1625 mbx_cmd_t *mcp = &mc;
1627 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
1628 return qla24xx_login_fabric(ha, fcport->loop_id,
1629 fcport->d_id.b.domain, fcport->d_id.b.area,
1630 fcport->d_id.b.al_pa, mb_ret, opt);
1632 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1634 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1635 if (HAS_EXTENDED_IDS(ha))
1636 mcp->mb[1] = fcport->loop_id;
1638 mcp->mb[1] = fcport->loop_id << 8;
1640 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1641 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1642 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1644 rval = qla2x00_mailbox_command(ha, mcp);
1646 /* Return mailbox statuses. */
1647 if (mb_ret != NULL) {
1648 mb_ret[0] = mcp->mb[0];
1649 mb_ret[1] = mcp->mb[1];
1650 mb_ret[6] = mcp->mb[6];
1651 mb_ret[7] = mcp->mb[7];
1654 if (rval != QLA_SUCCESS) {
1655 /* AV tmp code: need to change main mailbox_command function to
1656 * return ok even when the mailbox completion value is not
1657 * SUCCESS. The caller needs to be responsible to interpret
1658 * the return values of this mailbox command if we're not
1659 * to change too much of the existing code.
1661 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1664 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1665 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1666 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1667 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1668 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1669 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1672 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no));
1679 qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1680 uint8_t area, uint8_t al_pa)
1683 struct logio_entry_24xx *lg;
1686 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1688 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1690 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1691 __func__, ha->host_no));
1692 return QLA_MEMORY_ALLOC_FAILED;
1694 memset(lg, 0, sizeof(struct logio_entry_24xx));
1696 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1697 lg->entry_count = 1;
1698 lg->nport_handle = cpu_to_le16(loop_id);
1700 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
1701 lg->port_id[0] = al_pa;
1702 lg->port_id[1] = area;
1703 lg->port_id[2] = domain;
1704 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1705 if (rval != QLA_SUCCESS) {
1706 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1707 "(%x).\n", __func__, ha->host_no, rval));
1708 } else if (lg->entry_status != 0) {
1709 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1710 "-- error status (%x).\n", __func__, ha->host_no,
1712 rval = QLA_FUNCTION_FAILED;
1713 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1714 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1715 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1716 ha->host_no, le16_to_cpu(lg->comp_status),
1717 le32_to_cpu(lg->io_parameter[0]),
1718 le32_to_cpu(lg->io_parameter[1])));
1721 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1724 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1730 * qla2x00_fabric_logout
1731 * Issue logout fabric port mailbox command.
1734 * ha = adapter block pointer.
1735 * loop_id = device loop ID.
1736 * TARGET_QUEUE_LOCK must be released.
1737 * ADAPTER_STATE_LOCK must be released.
1740 * qla2x00 local function return status code.
1746 qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1747 uint8_t area, uint8_t al_pa)
1751 mbx_cmd_t *mcp = &mc;
1753 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1756 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1757 mcp->out_mb = MBX_1|MBX_0;
1758 if (HAS_EXTENDED_IDS(ha)) {
1759 mcp->mb[1] = loop_id;
1761 mcp->out_mb |= MBX_10;
1763 mcp->mb[1] = loop_id << 8;
1766 mcp->in_mb = MBX_1|MBX_0;
1769 rval = qla2x00_mailbox_command(ha, mcp);
1771 if (rval != QLA_SUCCESS) {
1773 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1774 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]));
1777 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1785 * qla2x00_full_login_lip
1786 * Issue full login LIP mailbox command.
1789 * ha = adapter block pointer.
1790 * TARGET_QUEUE_LOCK must be released.
1791 * ADAPTER_STATE_LOCK must be released.
1794 * qla2x00 local function return status code.
1800 qla2x00_full_login_lip(scsi_qla_host_t *ha)
1804 mbx_cmd_t *mcp = &mc;
1806 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1809 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1810 mcp->mb[1] = IS_QLA24XX(ha) || IS_QLA54XX(ha) ? BIT_3: 0;
1813 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1817 rval = qla2x00_mailbox_command(ha, mcp);
1819 if (rval != QLA_SUCCESS) {
1821 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1822 ha->host_no, rval));
1825 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1833 * qla2x00_get_id_list
1836 * ha = adapter block pointer.
1839 * qla2x00 local function return status code.
1845 qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
1850 mbx_cmd_t *mcp = &mc;
1852 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1855 if (id_list == NULL)
1856 return QLA_FUNCTION_FAILED;
1858 mcp->mb[0] = MBC_GET_ID_LIST;
1859 mcp->out_mb = MBX_0;
1860 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
1861 mcp->mb[2] = MSW(id_list_dma);
1862 mcp->mb[3] = LSW(id_list_dma);
1863 mcp->mb[6] = MSW(MSD(id_list_dma));
1864 mcp->mb[7] = LSW(MSD(id_list_dma));
1866 mcp->out_mb |= MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
1868 mcp->mb[1] = MSW(id_list_dma);
1869 mcp->mb[2] = LSW(id_list_dma);
1870 mcp->mb[3] = MSW(MSD(id_list_dma));
1871 mcp->mb[6] = LSW(MSD(id_list_dma));
1872 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1874 mcp->in_mb = MBX_1|MBX_0;
1877 rval = qla2x00_mailbox_command(ha, mcp);
1879 if (rval != QLA_SUCCESS) {
1881 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
1882 ha->host_no, rval));
1884 *entries = mcp->mb[1];
1885 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
1893 * qla2x00_get_resource_cnts
1894 * Get current firmware resource counts.
1897 * ha = adapter block pointer.
1900 * qla2x00 local function return status code.
1906 qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
1907 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt, uint16_t *orig_iocb_cnt)
1911 mbx_cmd_t *mcp = &mc;
1913 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1915 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
1916 mcp->out_mb = MBX_0;
1917 mcp->in_mb = MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1920 rval = qla2x00_mailbox_command(ha, mcp);
1922 if (rval != QLA_SUCCESS) {
1924 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
1925 ha->host_no, mcp->mb[0]));
1927 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
1928 "mb7=%x mb10=%x.\n", __func__, ha->host_no,
1929 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
1933 *cur_xchg_cnt = mcp->mb[3];
1935 *orig_xchg_cnt = mcp->mb[6];
1937 *cur_iocb_cnt = mcp->mb[7];
1939 *orig_iocb_cnt = mcp->mb[10];
1945 #if defined(QL_DEBUG_LEVEL_3)
1947 * qla2x00_get_fcal_position_map
1948 * Get FCAL (LILP) position map using mailbox command
1951 * ha = adapter state pointer.
1952 * pos_map = buffer pointer (can be NULL).
1955 * qla2x00 local function return status code.
1961 qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
1965 mbx_cmd_t *mcp = &mc;
1967 dma_addr_t pmap_dma;
1969 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma);
1971 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
1972 __func__, ha->host_no));
1973 return QLA_MEMORY_ALLOC_FAILED;
1975 memset(pmap, 0, FCAL_MAP_SIZE);
1977 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
1978 mcp->mb[2] = MSW(pmap_dma);
1979 mcp->mb[3] = LSW(pmap_dma);
1980 mcp->mb[6] = MSW(MSD(pmap_dma));
1981 mcp->mb[7] = LSW(MSD(pmap_dma));
1982 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1983 mcp->in_mb = MBX_1|MBX_0;
1984 mcp->buf_size = FCAL_MAP_SIZE;
1985 mcp->flags = MBX_DMA_IN;
1986 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1987 rval = qla2x00_mailbox_command(ha, mcp);
1989 if (rval == QLA_SUCCESS) {
1990 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
1991 "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
1992 mcp->mb[1], (unsigned)pmap[0]));
1993 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
1996 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
1998 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2000 if (rval != QLA_SUCCESS) {
2001 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2002 ha->host_no, rval));
2004 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2012 * qla2x00_get_link_status
2015 * ha = adapter block pointer.
2016 * loop_id = device loop ID.
2017 * ret_buf = pointer to link status return buffer.
2021 * BIT_0 = mem alloc error.
2022 * BIT_1 = mailbox error.
2025 qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
2026 link_stat_t *ret_buf, uint16_t *status)
2030 mbx_cmd_t *mcp = &mc;
2031 link_stat_t *stat_buf;
2032 dma_addr_t stat_buf_dma;
2034 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2036 stat_buf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &stat_buf_dma);
2037 if (stat_buf == NULL) {
2038 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
2039 __func__, ha->host_no));
2042 memset(stat_buf, 0, sizeof(link_stat_t));
2044 mcp->mb[0] = MBC_GET_LINK_STATUS;
2045 mcp->mb[2] = MSW(stat_buf_dma);
2046 mcp->mb[3] = LSW(stat_buf_dma);
2047 mcp->mb[6] = MSW(MSD(stat_buf_dma));
2048 mcp->mb[7] = LSW(MSD(stat_buf_dma));
2049 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2051 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
2052 mcp->mb[1] = loop_id;
2055 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2056 mcp->in_mb |= MBX_1;
2057 } else if (HAS_EXTENDED_IDS(ha)) {
2058 mcp->mb[1] = loop_id;
2060 mcp->out_mb |= MBX_10|MBX_1;
2062 mcp->mb[1] = loop_id << 8;
2063 mcp->out_mb |= MBX_1;
2066 mcp->flags = IOCTL_CMD;
2067 rval = qla2x00_mailbox_command(ha, mcp);
2069 if (rval == QLA_SUCCESS) {
2070 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2071 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2072 __func__, ha->host_no, mcp->mb[0]));
2073 status[0] = mcp->mb[0];
2076 /* copy over data -- firmware data is LE. */
2077 ret_buf->link_fail_cnt =
2078 le32_to_cpu(stat_buf->link_fail_cnt);
2079 ret_buf->loss_sync_cnt =
2080 le32_to_cpu(stat_buf->loss_sync_cnt);
2081 ret_buf->loss_sig_cnt =
2082 le32_to_cpu(stat_buf->loss_sig_cnt);
2083 ret_buf->prim_seq_err_cnt =
2084 le32_to_cpu(stat_buf->prim_seq_err_cnt);
2085 ret_buf->inval_xmit_word_cnt =
2086 le32_to_cpu(stat_buf->inval_xmit_word_cnt);
2087 ret_buf->inval_crc_cnt =
2088 le32_to_cpu(stat_buf->inval_crc_cnt);
2090 DEBUG11(printk("%s(%ld): stat dump: fail_cnt=%d "
2091 "loss_sync=%d loss_sig=%d seq_err=%d "
2092 "inval_xmt_word=%d inval_crc=%d.\n", __func__,
2093 ha->host_no, stat_buf->link_fail_cnt,
2094 stat_buf->loss_sync_cnt, stat_buf->loss_sig_cnt,
2095 stat_buf->prim_seq_err_cnt,
2096 stat_buf->inval_xmit_word_cnt,
2097 stat_buf->inval_crc_cnt));
2101 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2102 ha->host_no, rval));
2106 dma_pool_free(ha->s_dma_pool, stat_buf, stat_buf_dma);
2112 qla24xx_get_isp_stats(scsi_qla_host_t *ha, uint32_t *dwbuf, uint32_t dwords,
2117 mbx_cmd_t *mcp = &mc;
2118 uint32_t *sbuf, *siter;
2119 dma_addr_t sbuf_dma;
2121 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2123 if (dwords > (DMA_POOL_SIZE / 4)) {
2124 DEBUG2_3_11(printk("%s(%ld): Unabled to retrieve %d DWORDs "
2125 "(max %d).\n", __func__, ha->host_no, dwords,
2126 DMA_POOL_SIZE / 4));
2129 sbuf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &sbuf_dma);
2131 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
2132 __func__, ha->host_no));
2135 memset(sbuf, 0, DMA_POOL_SIZE);
2137 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2138 mcp->mb[2] = MSW(sbuf_dma);
2139 mcp->mb[3] = LSW(sbuf_dma);
2140 mcp->mb[6] = MSW(MSD(sbuf_dma));
2141 mcp->mb[7] = LSW(MSD(sbuf_dma));
2142 mcp->mb[8] = dwords;
2144 mcp->out_mb = MBX_10|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2145 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2147 mcp->flags = IOCTL_CMD;
2148 rval = qla2x00_mailbox_command(ha, mcp);
2150 if (rval == QLA_SUCCESS) {
2151 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2152 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2153 __func__, ha->host_no, mcp->mb[0]));
2154 status[0] = mcp->mb[0];
2157 /* Copy over data -- firmware data is LE. */
2160 *dwbuf++ = le32_to_cpu(*siter++);
2164 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2165 ha->host_no, rval));
2169 dma_pool_free(ha->s_dma_pool, sbuf, sbuf_dma);
2175 qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
2179 unsigned long flags = 0;
2181 struct abort_entry_24xx *abt;
2185 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2187 fcport = sp->fcport;
2189 spin_lock_irqsave(&ha->hardware_lock, flags);
2190 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2191 if (ha->outstanding_cmds[handle] == sp)
2194 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2195 if (handle == MAX_OUTSTANDING_COMMANDS) {
2196 /* Command not found. */
2197 return QLA_FUNCTION_FAILED;
2200 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2202 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2203 __func__, ha->host_no));
2204 return QLA_MEMORY_ALLOC_FAILED;
2206 memset(abt, 0, sizeof(struct abort_entry_24xx));
2208 abt->entry_type = ABORT_IOCB_TYPE;
2209 abt->entry_count = 1;
2210 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2211 abt->handle_to_abort = handle;
2212 abt->port_id[0] = fcport->d_id.b.al_pa;
2213 abt->port_id[1] = fcport->d_id.b.area;
2214 abt->port_id[2] = fcport->d_id.b.domain;
2215 rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
2216 if (rval != QLA_SUCCESS) {
2217 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2218 __func__, ha->host_no, rval));
2219 } else if (abt->entry_status != 0) {
2220 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2221 "-- error status (%x).\n", __func__, ha->host_no,
2222 abt->entry_status));
2223 rval = QLA_FUNCTION_FAILED;
2224 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2225 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2226 "-- completion status (%x).\n", __func__, ha->host_no,
2227 le16_to_cpu(abt->nport_handle)));
2228 rval = QLA_FUNCTION_FAILED;
2230 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2231 sp->flags |= SRB_ABORT_PENDING;
2234 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2239 struct tsk_mgmt_cmd {
2241 struct tsk_mgmt_entry tsk;
2242 struct sts_entry_24xx sts;
2247 qla24xx_abort_target(fc_port_t *fcport)
2250 struct tsk_mgmt_cmd *tsk;
2252 scsi_qla_host_t *ha;
2257 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
2260 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
2262 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2263 "IOCB.\n", __func__, ha->host_no));
2264 return QLA_MEMORY_ALLOC_FAILED;
2266 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2268 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2269 tsk->p.tsk.entry_count = 1;
2270 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2271 tsk->p.tsk.timeout = __constant_cpu_to_le16(25);
2272 tsk->p.tsk.control_flags = __constant_cpu_to_le32(TCF_TARGET_RESET);
2273 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2274 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2275 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2276 rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
2277 if (rval != QLA_SUCCESS) {
2278 DEBUG2_3_11(printk("%s(%ld): failed to issue Target Reset IOCB "
2279 "(%x).\n", __func__, ha->host_no, rval));
2281 } else if (tsk->p.sts.entry_status != 0) {
2282 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2283 "-- error status (%x).\n", __func__, ha->host_no,
2284 tsk->p.sts.entry_status));
2285 rval = QLA_FUNCTION_FAILED;
2287 } else if (tsk->p.sts.comp_status !=
2288 __constant_cpu_to_le16(CS_COMPLETE)) {
2289 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2290 "-- completion status (%x).\n", __func__,
2291 ha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
2292 rval = QLA_FUNCTION_FAILED;
2296 /* Issue marker IOCB. */
2297 rval = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
2298 if (rval != QLA_SUCCESS) {
2299 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2300 "(%x).\n", __func__, ha->host_no, rval));
2302 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2306 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
2312 qla2x00_system_error(scsi_qla_host_t *ha)
2316 mbx_cmd_t *mcp = &mc;
2318 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
2319 return QLA_FUNCTION_FAILED;
2321 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2323 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2324 mcp->out_mb = MBX_0;
2328 rval = qla2x00_mailbox_command(ha, mcp);
2330 if (rval != QLA_SUCCESS) {
2331 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2332 ha->host_no, rval));
2334 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2341 * qla2x00_get_serdes_params() -
2347 qla2x00_get_serdes_params(scsi_qla_host_t *ha, uint16_t *sw_em_1g,
2348 uint16_t *sw_em_2g, uint16_t *sw_em_4g)
2352 mbx_cmd_t *mcp = &mc;
2354 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2356 mcp->mb[0] = MBC_SERDES_PARAMS;
2358 mcp->out_mb = MBX_1|MBX_0;
2359 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_0;
2362 rval = qla2x00_mailbox_command(ha, mcp);
2364 if (rval != QLA_SUCCESS) {
2366 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2367 ha->host_no, rval, mcp->mb[0]));
2369 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2372 *sw_em_1g = mcp->mb[2];
2374 *sw_em_2g = mcp->mb[3];
2376 *sw_em_4g = mcp->mb[4];
2383 * qla2x00_set_serdes_params() -
2389 qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
2390 uint16_t sw_em_2g, uint16_t sw_em_4g)
2394 mbx_cmd_t *mcp = &mc;
2396 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2398 mcp->mb[0] = MBC_SERDES_PARAMS;
2400 mcp->mb[2] = sw_em_1g | BIT_15;
2401 mcp->mb[3] = sw_em_2g | BIT_15;
2402 mcp->mb[4] = sw_em_4g | BIT_15;
2403 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2407 rval = qla2x00_mailbox_command(ha, mcp);
2409 if (rval != QLA_SUCCESS) {
2411 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2412 ha->host_no, rval, mcp->mb[0]));
2415 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2422 qla2x00_stop_firmware(scsi_qla_host_t *ha)
2426 mbx_cmd_t *mcp = &mc;
2428 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
2429 return QLA_FUNCTION_FAILED;
2431 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2433 mcp->mb[0] = MBC_STOP_FIRMWARE;
2434 mcp->out_mb = MBX_0;
2438 rval = qla2x00_mailbox_command(ha, mcp);
2440 if (rval != QLA_SUCCESS) {
2441 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2442 ha->host_no, rval));
2444 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2451 qla2x00_trace_control(scsi_qla_host_t *ha, uint16_t ctrl, dma_addr_t eft_dma,
2456 mbx_cmd_t *mcp = &mc;
2458 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
2459 return QLA_FUNCTION_FAILED;
2461 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2463 mcp->mb[0] = MBC_TRACE_CONTROL;
2465 mcp->out_mb = MBX_1|MBX_0;
2466 mcp->in_mb = MBX_1|MBX_0;
2467 if (ctrl == TC_ENABLE) {
2468 mcp->mb[2] = LSW(eft_dma);
2469 mcp->mb[3] = MSW(eft_dma);
2470 mcp->mb[4] = LSW(MSD(eft_dma));
2471 mcp->mb[5] = MSW(MSD(eft_dma));
2472 mcp->mb[6] = buffers;
2474 mcp->out_mb |= MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2;
2478 rval = qla2x00_mailbox_command(ha, mcp);
2480 if (rval != QLA_SUCCESS) {
2481 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2482 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2484 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2491 qla2x00_read_sfp(scsi_qla_host_t *ha, dma_addr_t sfp_dma, uint16_t addr,
2492 uint16_t off, uint16_t count)
2496 mbx_cmd_t *mcp = &mc;
2498 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
2499 return QLA_FUNCTION_FAILED;
2501 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2503 mcp->mb[0] = MBC_READ_SFP;
2505 mcp->mb[2] = MSW(sfp_dma);
2506 mcp->mb[3] = LSW(sfp_dma);
2507 mcp->mb[6] = MSW(MSD(sfp_dma));
2508 mcp->mb[7] = LSW(MSD(sfp_dma));
2512 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2516 rval = qla2x00_mailbox_command(ha, mcp);
2518 if (rval != QLA_SUCCESS) {
2519 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2520 ha->host_no, rval, mcp->mb[0]));
2522 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2529 qla2x00_get_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id,
2530 uint16_t *port_speed, uint16_t *mb)
2534 mbx_cmd_t *mcp = &mc;
2536 if (!IS_QLA24XX(ha))
2537 return QLA_FUNCTION_FAILED;
2539 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2541 mcp->mb[0] = MBC_PORT_PARAMS;
2542 mcp->mb[1] = loop_id;
2543 mcp->mb[2] = mcp->mb[3] = mcp->mb[4] = mcp->mb[5] = 0;
2544 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2545 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2548 rval = qla2x00_mailbox_command(ha, mcp);
2550 /* Return mailbox statuses. */
2559 if (rval != QLA_SUCCESS) {
2560 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2561 ha->host_no, rval));
2563 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2565 *port_speed = mcp->mb[3];
2572 qla2x00_set_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id,
2573 uint16_t port_speed, uint16_t *mb)
2577 mbx_cmd_t *mcp = &mc;
2579 if (!IS_QLA24XX(ha))
2580 return QLA_FUNCTION_FAILED;
2582 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2584 mcp->mb[0] = MBC_PORT_PARAMS;
2585 mcp->mb[1] = loop_id;
2587 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2588 mcp->mb[4] = mcp->mb[5] = 0;
2589 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2590 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2593 rval = qla2x00_mailbox_command(ha, mcp);
2595 /* Return mailbox statuses. */
2604 if (rval != QLA_SUCCESS) {
2605 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2606 ha->host_no, rval));
2608 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));