2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
13 * qla2x00_mailbox_command
14 * Issue mailbox command and waits for completion.
17 * ha = adapter block pointer.
18 * mcp = driver internal mbx struct pointer.
21 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
24 * 0 : QLA_SUCCESS = cmd performed success
25 * 1 : QLA_FUNCTION_FAILED (error encountered)
26 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
32 qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
35 unsigned long flags = 0;
36 device_reg_t __iomem *reg;
41 uint16_t __iomem *optr;
44 unsigned long wait_time;
45 struct qla_hw_data *ha = vha->hw;
46 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
48 if (ha->pdev->error_state > pci_channel_io_frozen)
49 return QLA_FUNCTION_TIMEOUT;
52 io_lock_on = base_vha->flags.init_done;
55 abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
57 DEBUG11(printk("%s(%ld): entered.\n", __func__, base_vha->host_no));
59 if (ha->flags.pci_channel_io_perm_failure) {
60 DEBUG(printk("%s(%ld): Perm failure on EEH, timeout MBX "
61 "Exiting.\n", __func__, vha->host_no));
62 return QLA_FUNCTION_TIMEOUT;
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
70 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp, mcp->tov * HZ)) {
71 /* Timeout occurred. Return error. */
72 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
73 "Exiting.\n", __func__, base_vha->host_no));
74 return QLA_FUNCTION_TIMEOUT;
77 ha->flags.mbox_busy = 1;
78 /* Save mailbox command for debug */
81 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
82 base_vha->host_no, mcp->mb[0]));
84 spin_lock_irqsave(&ha->hardware_lock, flags);
86 /* Load mailbox registers. */
87 if (IS_FWI2_CAPABLE(ha))
88 optr = (uint16_t __iomem *)®->isp24.mailbox0;
90 optr = (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 0);
96 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
97 if (IS_QLA2200(ha) && cnt == 8)
99 (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 8);
101 WRT_REG_WORD(optr, *iptr);
108 #if defined(QL_DEBUG_LEVEL_1)
109 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
110 __func__, base_vha->host_no);
111 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
113 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
115 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
117 printk("%s(%ld): I/O address = %p.\n", __func__, base_vha->host_no,
119 qla2x00_dump_regs(base_vha);
122 /* Issue set host interrupt command to send cmd out. */
123 ha->flags.mbox_int = 0;
124 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
126 /* Unlock mbx registers and wait for interrupt */
127 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
128 "jiffies=%lx.\n", __func__, base_vha->host_no, jiffies));
130 /* Wait for mbx cmd completion until timeout */
132 if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
133 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
135 if (IS_FWI2_CAPABLE(ha))
136 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
138 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
139 spin_unlock_irqrestore(&ha->hardware_lock, flags);
141 wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ);
143 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
146 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
147 base_vha->host_no, command));
149 if (IS_FWI2_CAPABLE(ha))
150 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
152 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
153 spin_unlock_irqrestore(&ha->hardware_lock, flags);
155 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
156 while (!ha->flags.mbox_int) {
157 if (time_after(jiffies, wait_time))
160 /* Check for pending interrupts. */
161 qla2x00_poll(ha->rsp_q_map[0]);
163 if (!ha->flags.mbox_int &&
165 command == MBC_LOAD_RISC_RAM_EXTENDED))
168 DEBUG17(qla_printk(KERN_WARNING, ha,
170 (uint)((jiffies - (wait_time - (mcp->tov * HZ)))/HZ)));
173 /* Check whether we timed out */
174 if (ha->flags.mbox_int) {
177 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
178 base_vha->host_no, command));
180 /* Got interrupt. Clear the flag. */
181 ha->flags.mbox_int = 0;
182 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
184 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
185 rval = QLA_FUNCTION_FAILED;
187 /* Load return mailbox registers. */
189 iptr = (uint16_t *)&ha->mailbox_out[0];
191 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
201 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
202 defined(QL_DEBUG_LEVEL_11)
206 if (IS_FWI2_CAPABLE(ha)) {
207 mb0 = RD_REG_WORD(®->isp24.mailbox0);
208 ictrl = RD_REG_DWORD(®->isp24.ictrl);
210 mb0 = RD_MAILBOX_REG(ha, ®->isp, 0);
211 ictrl = RD_REG_WORD(®->isp.ictrl);
213 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
214 __func__, base_vha->host_no, command);
215 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
216 base_vha->host_no, ictrl, jiffies);
217 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
218 base_vha->host_no, mb0);
219 qla2x00_dump_regs(base_vha);
222 rval = QLA_FUNCTION_TIMEOUT;
225 ha->flags.mbox_busy = 0;
230 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
231 DEBUG11(printk("%s(%ld): checking for additional resp "
232 "interrupt.\n", __func__, base_vha->host_no));
234 /* polling mode for non isp_abort commands. */
235 qla2x00_poll(ha->rsp_q_map[0]);
238 if (rval == QLA_FUNCTION_TIMEOUT &&
239 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
240 if (!io_lock_on || (mcp->flags & IOCTL_CMD) ||
241 ha->flags.eeh_busy) {
242 /* not in dpc. schedule it for dpc to take over. */
243 DEBUG(printk("%s(%ld): timeout schedule "
244 "isp_abort_needed.\n", __func__,
246 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
247 "isp_abort_needed.\n", __func__,
249 qla_printk(KERN_WARNING, ha,
250 "Mailbox command timeout occurred. Scheduling ISP "
251 "abort. eeh_busy: 0x%x\n", ha->flags.eeh_busy);
252 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
253 qla2xxx_wake_dpc(vha);
254 } else if (!abort_active) {
255 /* call abort directly since we are in the DPC thread */
256 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
257 __func__, base_vha->host_no));
258 DEBUG2_3_11(printk("%s(%ld): timeout calling "
259 "abort_isp\n", __func__, base_vha->host_no));
260 qla_printk(KERN_WARNING, ha,
261 "Mailbox command timeout occurred. Issuing ISP "
264 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
265 clear_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
266 if (qla2x00_abort_isp(base_vha)) {
267 /* Failed. retry later. */
268 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
270 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
271 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
273 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
274 __func__, base_vha->host_no));
278 /* Allow next mbx cmd to come in. */
279 complete(&ha->mbx_cmd_comp);
282 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
283 "mbx2=%x, cmd=%x ****\n", __func__, base_vha->host_no,
284 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
286 DEBUG11(printk("%s(%ld): done.\n", __func__,
294 qla2x00_load_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t risc_addr,
295 uint32_t risc_code_size)
298 struct qla_hw_data *ha = vha->hw;
300 mbx_cmd_t *mcp = &mc;
302 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
304 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
305 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
306 mcp->mb[8] = MSW(risc_addr);
307 mcp->out_mb = MBX_8|MBX_0;
309 mcp->mb[0] = MBC_LOAD_RISC_RAM;
312 mcp->mb[1] = LSW(risc_addr);
313 mcp->mb[2] = MSW(req_dma);
314 mcp->mb[3] = LSW(req_dma);
315 mcp->mb[6] = MSW(MSD(req_dma));
316 mcp->mb[7] = LSW(MSD(req_dma));
317 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
318 if (IS_FWI2_CAPABLE(ha)) {
319 mcp->mb[4] = MSW(risc_code_size);
320 mcp->mb[5] = LSW(risc_code_size);
321 mcp->out_mb |= MBX_5|MBX_4;
323 mcp->mb[4] = LSW(risc_code_size);
324 mcp->out_mb |= MBX_4;
328 mcp->tov = MBX_TOV_SECONDS;
330 rval = qla2x00_mailbox_command(vha, mcp);
332 if (rval != QLA_SUCCESS) {
333 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
334 vha->host_no, rval, mcp->mb[0]));
336 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
344 * Start adapter firmware.
347 * ha = adapter block pointer.
348 * TARGET_QUEUE_LOCK must be released.
349 * ADAPTER_STATE_LOCK must be released.
352 * qla2x00 local function return status code.
358 qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
361 struct qla_hw_data *ha = vha->hw;
363 mbx_cmd_t *mcp = &mc;
365 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
367 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
370 if (IS_FWI2_CAPABLE(ha)) {
371 mcp->mb[1] = MSW(risc_addr);
372 mcp->mb[2] = LSW(risc_addr);
375 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
378 mcp->mb[1] = LSW(risc_addr);
379 mcp->out_mb |= MBX_1;
380 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
382 mcp->out_mb |= MBX_2;
386 mcp->tov = MBX_TOV_SECONDS;
388 rval = qla2x00_mailbox_command(vha, mcp);
390 if (rval != QLA_SUCCESS) {
391 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
392 vha->host_no, rval, mcp->mb[0]));
394 if (IS_FWI2_CAPABLE(ha)) {
395 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
396 __func__, vha->host_no, mcp->mb[1]));
398 DEBUG11(printk("%s(%ld): done.\n", __func__,
407 * qla2x00_get_fw_version
408 * Get firmware version.
411 * ha: adapter state pointer.
412 * major: pointer for major number.
413 * minor: pointer for minor number.
414 * subminor: pointer for subminor number.
417 * qla2x00 local function return status code.
423 qla2x00_get_fw_version(scsi_qla_host_t *vha, uint16_t *major, uint16_t *minor,
424 uint16_t *subminor, uint16_t *attributes, uint32_t *memory, uint8_t *mpi,
425 uint32_t *mpi_caps, uint8_t *phy)
429 mbx_cmd_t *mcp = &mc;
431 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
433 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
435 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
436 if (IS_QLA81XX(vha->hw))
437 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
439 mcp->tov = MBX_TOV_SECONDS;
440 rval = qla2x00_mailbox_command(vha, mcp);
441 if (rval != QLA_SUCCESS)
444 /* Return mailbox data. */
447 *subminor = mcp->mb[3];
448 *attributes = mcp->mb[6];
449 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
450 *memory = 0x1FFFF; /* Defaults to 128KB. */
452 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
453 if (IS_QLA81XX(vha->hw)) {
454 mpi[0] = mcp->mb[10] & 0xff;
455 mpi[1] = mcp->mb[11] >> 8;
456 mpi[2] = mcp->mb[11] & 0xff;
457 *mpi_caps = (mcp->mb[12] << 16) | mcp->mb[13];
458 phy[0] = mcp->mb[8] & 0xff;
459 phy[1] = mcp->mb[9] >> 8;
460 phy[2] = mcp->mb[9] & 0xff;
463 if (rval != QLA_SUCCESS) {
465 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
466 vha->host_no, rval));
469 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->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 *vha, uint16_t *fwopts)
493 mbx_cmd_t *mcp = &mc;
495 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
497 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
499 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
500 mcp->tov = MBX_TOV_SECONDS;
502 rval = qla2x00_mailbox_command(vha, mcp);
504 if (rval != QLA_SUCCESS) {
506 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
507 vha->host_no, rval));
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__, vha->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 *vha, uint16_t *fwopts)
540 mbx_cmd_t *mcp = &mc;
542 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->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_FWI2_CAPABLE(vha->hw)) {
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;
558 mcp->tov = MBX_TOV_SECONDS;
560 rval = qla2x00_mailbox_command(vha, 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 vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
570 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->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 *vha)
596 mbx_cmd_t *mcp = &mc;
598 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", vha->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;
610 mcp->tov = MBX_TOV_SECONDS;
612 rval = qla2x00_mailbox_command(vha, 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",
626 vha->host_no, rval));
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 *vha, uint32_t risc_addr)
656 mbx_cmd_t *mcp = &mc;
658 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
660 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
663 if (IS_FWI2_CAPABLE(vha->hw)) {
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;
674 mcp->tov = MBX_TOV_SECONDS;
676 rval = qla2x00_mailbox_command(vha, mcp);
678 if (rval != QLA_SUCCESS) {
679 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
680 vha->host_no, rval, IS_FWI2_CAPABLE(vha->hw) ?
681 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
683 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->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_timeout(scsi_qla_host_t *vha, void *buffer,
709 dma_addr_t phys_addr, size_t size, uint32_t tov)
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(vha, mcp);
727 if (rval != QLA_SUCCESS) {
729 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
730 vha->host_no, rval));
732 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
734 /* Mask reserved bits. */
735 sts_entry->entry_status &=
736 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
743 qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
746 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
751 * qla2x00_abort_command
752 * Abort command aborts a specified IOCB.
755 * ha = adapter block pointer.
756 * sp = SB structure pointer.
759 * qla2x00 local function return status code.
765 qla2x00_abort_command(srb_t *sp)
767 unsigned long flags = 0;
771 mbx_cmd_t *mcp = &mc;
772 fc_port_t *fcport = sp->fcport;
773 scsi_qla_host_t *vha = fcport->vha;
774 struct qla_hw_data *ha = vha->hw;
775 struct req_que *req = vha->req;
777 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", vha->host_no));
779 spin_lock_irqsave(&ha->hardware_lock, flags);
780 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
781 if (req->outstanding_cmds[handle] == sp)
784 spin_unlock_irqrestore(&ha->hardware_lock, flags);
786 if (handle == MAX_OUTSTANDING_COMMANDS) {
787 /* command not found */
788 return QLA_FUNCTION_FAILED;
791 mcp->mb[0] = MBC_ABORT_COMMAND;
792 if (HAS_EXTENDED_IDS(ha))
793 mcp->mb[1] = fcport->loop_id;
795 mcp->mb[1] = fcport->loop_id << 8;
796 mcp->mb[2] = (uint16_t)handle;
797 mcp->mb[3] = (uint16_t)(handle >> 16);
798 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
799 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
801 mcp->tov = MBX_TOV_SECONDS;
803 rval = qla2x00_mailbox_command(vha, mcp);
805 if (rval != QLA_SUCCESS) {
806 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
807 vha->host_no, rval));
809 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
817 qla2x00_abort_target(struct fc_port *fcport, unsigned int l, int tag)
821 mbx_cmd_t *mcp = &mc;
822 scsi_qla_host_t *vha;
826 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
830 req = vha->hw->req_q_map[tag];
831 rsp = vha->hw->rsp_q_map[tag];
832 mcp->mb[0] = MBC_ABORT_TARGET;
833 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
834 if (HAS_EXTENDED_IDS(vha->hw)) {
835 mcp->mb[1] = fcport->loop_id;
837 mcp->out_mb |= MBX_10;
839 mcp->mb[1] = fcport->loop_id << 8;
841 mcp->mb[2] = vha->hw->loop_reset_delay;
842 mcp->mb[9] = vha->vp_idx;
845 mcp->tov = MBX_TOV_SECONDS;
847 rval = qla2x00_mailbox_command(vha, mcp);
848 if (rval != QLA_SUCCESS) {
849 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
850 vha->host_no, rval));
853 /* Issue marker IOCB. */
854 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
856 if (rval2 != QLA_SUCCESS) {
857 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
858 "(%x).\n", __func__, vha->host_no, rval2));
860 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
867 qla2x00_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
871 mbx_cmd_t *mcp = &mc;
872 scsi_qla_host_t *vha;
876 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
879 req = vha->hw->req_q_map[tag];
880 rsp = vha->hw->rsp_q_map[tag];
881 mcp->mb[0] = MBC_LUN_RESET;
882 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
883 if (HAS_EXTENDED_IDS(vha->hw))
884 mcp->mb[1] = fcport->loop_id;
886 mcp->mb[1] = fcport->loop_id << 8;
889 mcp->mb[9] = vha->vp_idx;
892 mcp->tov = MBX_TOV_SECONDS;
894 rval = qla2x00_mailbox_command(vha, mcp);
895 if (rval != QLA_SUCCESS) {
896 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
897 vha->host_no, rval));
900 /* Issue marker IOCB. */
901 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
903 if (rval2 != QLA_SUCCESS) {
904 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
905 "(%x).\n", __func__, vha->host_no, rval2));
907 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
914 * qla2x00_get_adapter_id
915 * Get adapter ID and topology.
918 * ha = adapter block pointer.
919 * id = pointer for loop ID.
920 * al_pa = pointer for AL_PA.
921 * area = pointer for area.
922 * domain = pointer for domain.
923 * top = pointer for topology.
924 * TARGET_QUEUE_LOCK must be released.
925 * ADAPTER_STATE_LOCK must be released.
928 * qla2x00 local function return status code.
934 qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
935 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
939 mbx_cmd_t *mcp = &mc;
941 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
944 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
945 mcp->mb[9] = vha->vp_idx;
946 mcp->out_mb = MBX_9|MBX_0;
947 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
948 if (IS_QLA81XX(vha->hw))
949 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
950 mcp->tov = MBX_TOV_SECONDS;
952 rval = qla2x00_mailbox_command(vha, mcp);
953 if (mcp->mb[0] == MBS_COMMAND_ERROR)
954 rval = QLA_COMMAND_ERROR;
955 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
956 rval = QLA_INVALID_COMMAND;
960 *al_pa = LSB(mcp->mb[2]);
961 *area = MSB(mcp->mb[2]);
962 *domain = LSB(mcp->mb[3]);
964 *sw_cap = mcp->mb[7];
966 if (rval != QLA_SUCCESS) {
968 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
969 vha->host_no, rval));
971 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
974 if (IS_QLA81XX(vha->hw)) {
975 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
976 vha->fcoe_fcf_idx = mcp->mb[10];
977 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
978 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
979 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
980 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
981 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
982 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
990 * qla2x00_get_retry_cnt
991 * Get current firmware login retry count and delay.
994 * ha = adapter block pointer.
995 * retry_cnt = pointer to login retry count.
996 * tov = pointer to login timeout value.
999 * qla2x00 local function return status code.
1005 qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
1011 mbx_cmd_t *mcp = &mc;
1013 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
1016 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1017 mcp->out_mb = MBX_0;
1018 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1019 mcp->tov = MBX_TOV_SECONDS;
1021 rval = qla2x00_mailbox_command(vha, mcp);
1023 if (rval != QLA_SUCCESS) {
1025 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
1026 vha->host_no, mcp->mb[0]));
1028 /* Convert returned data and check our values. */
1029 *r_a_tov = mcp->mb[3] / 2;
1030 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1031 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1032 /* Update to the larger values */
1033 *retry_cnt = (uint8_t)mcp->mb[1];
1037 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
1038 "ratov=%d.\n", vha->host_no, mcp->mb[3], ratov));
1045 * qla2x00_init_firmware
1046 * Initialize adapter firmware.
1049 * ha = adapter block pointer.
1050 * dptr = Initialization control block pointer.
1051 * size = size of initialization control block.
1052 * TARGET_QUEUE_LOCK must be released.
1053 * ADAPTER_STATE_LOCK must be released.
1056 * qla2x00 local function return status code.
1062 qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
1066 mbx_cmd_t *mcp = &mc;
1067 struct qla_hw_data *ha = vha->hw;
1069 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1072 if (ha->flags.npiv_supported)
1073 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1075 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1078 mcp->mb[2] = MSW(ha->init_cb_dma);
1079 mcp->mb[3] = LSW(ha->init_cb_dma);
1080 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1081 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1082 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1083 if (IS_QLA81XX(ha) && ha->ex_init_cb->ex_version) {
1085 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1086 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1087 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1088 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1089 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1090 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1093 mcp->buf_size = size;
1094 mcp->flags = MBX_DMA_OUT;
1095 mcp->tov = MBX_TOV_SECONDS;
1096 rval = qla2x00_mailbox_command(vha, mcp);
1098 if (rval != QLA_SUCCESS) {
1100 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1102 vha->host_no, rval, mcp->mb[0]));
1105 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1113 * qla2x00_get_port_database
1114 * Issue normal/enhanced get port database mailbox command
1115 * and copy device name as necessary.
1118 * ha = adapter state pointer.
1119 * dev = structure pointer.
1120 * opt = enhanced cmd option byte.
1123 * qla2x00 local function return status code.
1129 qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
1133 mbx_cmd_t *mcp = &mc;
1134 port_database_t *pd;
1135 struct port_database_24xx *pd24;
1137 struct qla_hw_data *ha = vha->hw;
1139 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1142 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1144 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1145 "structure.\n", __func__, vha->host_no));
1146 return QLA_MEMORY_ALLOC_FAILED;
1148 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
1150 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1151 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
1152 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1153 mcp->mb[2] = MSW(pd_dma);
1154 mcp->mb[3] = LSW(pd_dma);
1155 mcp->mb[6] = MSW(MSD(pd_dma));
1156 mcp->mb[7] = LSW(MSD(pd_dma));
1157 mcp->mb[9] = vha->vp_idx;
1158 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1160 if (IS_FWI2_CAPABLE(ha)) {
1161 mcp->mb[1] = fcport->loop_id;
1163 mcp->out_mb |= MBX_10|MBX_1;
1164 mcp->in_mb |= MBX_1;
1165 } else if (HAS_EXTENDED_IDS(ha)) {
1166 mcp->mb[1] = fcport->loop_id;
1168 mcp->out_mb |= MBX_10|MBX_1;
1170 mcp->mb[1] = fcport->loop_id << 8 | opt;
1171 mcp->out_mb |= MBX_1;
1173 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1174 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
1175 mcp->flags = MBX_DMA_IN;
1176 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1177 rval = qla2x00_mailbox_command(vha, mcp);
1178 if (rval != QLA_SUCCESS)
1181 if (IS_FWI2_CAPABLE(ha)) {
1182 pd24 = (struct port_database_24xx *) pd;
1184 /* Check for logged in state. */
1185 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1186 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1187 DEBUG2(printk("%s(%ld): Unable to verify "
1188 "login-state (%x/%x) for loop_id %x\n",
1189 __func__, vha->host_no,
1190 pd24->current_login_state,
1191 pd24->last_login_state, fcport->loop_id));
1192 rval = QLA_FUNCTION_FAILED;
1196 /* Names are little-endian. */
1197 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1198 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1200 /* Get port_id of device. */
1201 fcport->d_id.b.domain = pd24->port_id[0];
1202 fcport->d_id.b.area = pd24->port_id[1];
1203 fcport->d_id.b.al_pa = pd24->port_id[2];
1204 fcport->d_id.b.rsvd_1 = 0;
1206 /* If not target must be initiator or unknown type. */
1207 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1208 fcport->port_type = FCT_INITIATOR;
1210 fcport->port_type = FCT_TARGET;
1212 /* Check for logged in state. */
1213 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1214 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1215 rval = QLA_FUNCTION_FAILED;
1219 /* Names are little-endian. */
1220 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1221 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1223 /* Get port_id of device. */
1224 fcport->d_id.b.domain = pd->port_id[0];
1225 fcport->d_id.b.area = pd->port_id[3];
1226 fcport->d_id.b.al_pa = pd->port_id[2];
1227 fcport->d_id.b.rsvd_1 = 0;
1229 /* If not target must be initiator or unknown type. */
1230 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1231 fcport->port_type = FCT_INITIATOR;
1233 fcport->port_type = FCT_TARGET;
1235 /* Passback COS information. */
1236 fcport->supported_classes = (pd->options & BIT_4) ?
1237 FC_COS_CLASS2: FC_COS_CLASS3;
1241 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1243 if (rval != QLA_SUCCESS) {
1244 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1245 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1247 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1254 * qla2x00_get_firmware_state
1255 * Get adapter firmware state.
1258 * ha = adapter block pointer.
1259 * dptr = pointer for firmware state.
1260 * TARGET_QUEUE_LOCK must be released.
1261 * ADAPTER_STATE_LOCK must be released.
1264 * qla2x00 local function return status code.
1270 qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
1274 mbx_cmd_t *mcp = &mc;
1276 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1279 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1280 mcp->out_mb = MBX_0;
1281 if (IS_FWI2_CAPABLE(vha->hw))
1282 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1284 mcp->in_mb = MBX_1|MBX_0;
1285 mcp->tov = MBX_TOV_SECONDS;
1287 rval = qla2x00_mailbox_command(vha, mcp);
1289 /* Return firmware states. */
1290 states[0] = mcp->mb[1];
1291 if (IS_FWI2_CAPABLE(vha->hw)) {
1292 states[1] = mcp->mb[2];
1293 states[2] = mcp->mb[3];
1294 states[3] = mcp->mb[4];
1295 states[4] = mcp->mb[5];
1298 if (rval != QLA_SUCCESS) {
1300 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1301 "failed=%x.\n", vha->host_no, rval));
1304 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1312 * qla2x00_get_port_name
1313 * Issue get port name mailbox command.
1314 * Returned name is in big endian format.
1317 * ha = adapter block pointer.
1318 * loop_id = loop ID of device.
1319 * name = pointer for name.
1320 * TARGET_QUEUE_LOCK must be released.
1321 * ADAPTER_STATE_LOCK must be released.
1324 * qla2x00 local function return status code.
1330 qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
1335 mbx_cmd_t *mcp = &mc;
1337 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1340 mcp->mb[0] = MBC_GET_PORT_NAME;
1341 mcp->mb[9] = vha->vp_idx;
1342 mcp->out_mb = MBX_9|MBX_1|MBX_0;
1343 if (HAS_EXTENDED_IDS(vha->hw)) {
1344 mcp->mb[1] = loop_id;
1346 mcp->out_mb |= MBX_10;
1348 mcp->mb[1] = loop_id << 8 | opt;
1351 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1352 mcp->tov = MBX_TOV_SECONDS;
1354 rval = qla2x00_mailbox_command(vha, mcp);
1356 if (rval != QLA_SUCCESS) {
1358 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1359 vha->host_no, rval));
1362 /* This function returns name in big endian. */
1363 name[0] = MSB(mcp->mb[2]);
1364 name[1] = LSB(mcp->mb[2]);
1365 name[2] = MSB(mcp->mb[3]);
1366 name[3] = LSB(mcp->mb[3]);
1367 name[4] = MSB(mcp->mb[6]);
1368 name[5] = LSB(mcp->mb[6]);
1369 name[6] = MSB(mcp->mb[7]);
1370 name[7] = LSB(mcp->mb[7]);
1373 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1382 * Issue LIP reset mailbox command.
1385 * ha = adapter block pointer.
1386 * TARGET_QUEUE_LOCK must be released.
1387 * ADAPTER_STATE_LOCK must be released.
1390 * qla2x00 local function return status code.
1396 qla2x00_lip_reset(scsi_qla_host_t *vha)
1400 mbx_cmd_t *mcp = &mc;
1402 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1404 if (IS_QLA81XX(vha->hw)) {
1405 /* Logout across all FCFs. */
1406 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1409 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1410 } else if (IS_FWI2_CAPABLE(vha->hw)) {
1411 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1414 mcp->mb[3] = vha->hw->loop_reset_delay;
1415 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1417 mcp->mb[0] = MBC_LIP_RESET;
1418 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1419 if (HAS_EXTENDED_IDS(vha->hw)) {
1420 mcp->mb[1] = 0x00ff;
1422 mcp->out_mb |= MBX_10;
1424 mcp->mb[1] = 0xff00;
1426 mcp->mb[2] = vha->hw->loop_reset_delay;
1430 mcp->tov = MBX_TOV_SECONDS;
1432 rval = qla2x00_mailbox_command(vha, mcp);
1434 if (rval != QLA_SUCCESS) {
1436 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1437 __func__, vha->host_no, rval));
1440 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1451 * ha = adapter block pointer.
1452 * sns = pointer for command.
1453 * cmd_size = command size.
1454 * buf_size = response/command size.
1455 * TARGET_QUEUE_LOCK must be released.
1456 * ADAPTER_STATE_LOCK must be released.
1459 * qla2x00 local function return status code.
1465 qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
1466 uint16_t cmd_size, size_t buf_size)
1470 mbx_cmd_t *mcp = &mc;
1472 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1475 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1476 "tov=%d.\n", vha->hw->retry_count, vha->hw->login_timeout,
1479 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1480 mcp->mb[1] = cmd_size;
1481 mcp->mb[2] = MSW(sns_phys_address);
1482 mcp->mb[3] = LSW(sns_phys_address);
1483 mcp->mb[6] = MSW(MSD(sns_phys_address));
1484 mcp->mb[7] = LSW(MSD(sns_phys_address));
1485 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1486 mcp->in_mb = MBX_0|MBX_1;
1487 mcp->buf_size = buf_size;
1488 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1489 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
1490 rval = qla2x00_mailbox_command(vha, mcp);
1492 if (rval != QLA_SUCCESS) {
1494 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1495 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1496 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1497 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1500 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", vha->host_no));
1507 qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1508 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1512 struct logio_entry_24xx *lg;
1515 struct qla_hw_data *ha = vha->hw;
1516 struct req_que *req;
1517 struct rsp_que *rsp;
1519 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1521 if (ha->flags.cpu_affinity_enabled)
1522 req = ha->req_q_map[0];
1527 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1529 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1530 __func__, vha->host_no));
1531 return QLA_MEMORY_ALLOC_FAILED;
1533 memset(lg, 0, sizeof(struct logio_entry_24xx));
1535 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1536 lg->entry_count = 1;
1537 lg->handle = MAKE_HANDLE(req->id, lg->handle);
1538 lg->nport_handle = cpu_to_le16(loop_id);
1539 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1541 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1543 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
1544 lg->port_id[0] = al_pa;
1545 lg->port_id[1] = area;
1546 lg->port_id[2] = domain;
1547 lg->vp_index = vha->vp_idx;
1548 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
1549 if (rval != QLA_SUCCESS) {
1550 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
1551 "(%x).\n", __func__, vha->host_no, rval));
1552 } else if (lg->entry_status != 0) {
1553 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1554 "-- error status (%x).\n", __func__, vha->host_no,
1556 rval = QLA_FUNCTION_FAILED;
1557 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1558 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1559 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1561 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1562 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1563 vha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1567 case LSC_SCODE_PORTID_USED:
1568 mb[0] = MBS_PORT_ID_USED;
1569 mb[1] = LSW(iop[1]);
1571 case LSC_SCODE_NPORT_USED:
1572 mb[0] = MBS_LOOP_ID_USED;
1574 case LSC_SCODE_NOLINK:
1575 case LSC_SCODE_NOIOCB:
1576 case LSC_SCODE_NOXCB:
1577 case LSC_SCODE_CMD_FAILED:
1578 case LSC_SCODE_NOFABRIC:
1579 case LSC_SCODE_FW_NOT_READY:
1580 case LSC_SCODE_NOT_LOGGED_IN:
1581 case LSC_SCODE_NOPCB:
1582 case LSC_SCODE_ELS_REJECT:
1583 case LSC_SCODE_CMD_PARAM_ERR:
1584 case LSC_SCODE_NONPORT:
1585 case LSC_SCODE_LOGGED_IN:
1586 case LSC_SCODE_NOFLOGI_ACC:
1588 mb[0] = MBS_COMMAND_ERROR;
1592 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1594 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1596 mb[0] = MBS_COMMAND_COMPLETE;
1598 if (iop[0] & BIT_4) {
1604 /* Passback COS information. */
1606 if (lg->io_parameter[7] || lg->io_parameter[8])
1607 mb[10] |= BIT_0; /* Class 2. */
1608 if (lg->io_parameter[9] || lg->io_parameter[10])
1609 mb[10] |= BIT_1; /* Class 3. */
1612 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1618 * qla2x00_login_fabric
1619 * Issue login fabric port mailbox command.
1622 * ha = adapter block pointer.
1623 * loop_id = device loop ID.
1624 * domain = device domain.
1625 * area = device area.
1626 * al_pa = device AL_PA.
1627 * status = pointer for return status.
1628 * opt = command options.
1629 * TARGET_QUEUE_LOCK must be released.
1630 * ADAPTER_STATE_LOCK must be released.
1633 * qla2x00 local function return status code.
1639 qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1640 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1644 mbx_cmd_t *mcp = &mc;
1645 struct qla_hw_data *ha = vha->hw;
1647 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", vha->host_no));
1649 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1650 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1651 if (HAS_EXTENDED_IDS(ha)) {
1652 mcp->mb[1] = loop_id;
1654 mcp->out_mb |= MBX_10;
1656 mcp->mb[1] = (loop_id << 8) | opt;
1658 mcp->mb[2] = domain;
1659 mcp->mb[3] = area << 8 | al_pa;
1661 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1662 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1664 rval = qla2x00_mailbox_command(vha, mcp);
1666 /* Return mailbox statuses. */
1673 /* COS retrieved from Get-Port-Database mailbox command. */
1677 if (rval != QLA_SUCCESS) {
1678 /* RLU tmp code: need to change main mailbox_command function to
1679 * return ok even when the mailbox completion value is not
1680 * SUCCESS. The caller needs to be responsible to interpret
1681 * the return values of this mailbox command if we're not
1682 * to change too much of the existing code.
1684 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1685 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1686 mcp->mb[0] == 0x4006)
1690 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1691 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", vha->host_no, rval,
1692 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
1695 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1703 * qla2x00_login_local_device
1704 * Issue login loop port mailbox command.
1707 * ha = adapter block pointer.
1708 * loop_id = device loop ID.
1709 * opt = command options.
1712 * Return status code.
1719 qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
1720 uint16_t *mb_ret, uint8_t opt)
1724 mbx_cmd_t *mcp = &mc;
1725 struct qla_hw_data *ha = vha->hw;
1727 if (IS_FWI2_CAPABLE(ha))
1728 return qla24xx_login_fabric(vha, fcport->loop_id,
1729 fcport->d_id.b.domain, fcport->d_id.b.area,
1730 fcport->d_id.b.al_pa, mb_ret, opt);
1732 DEBUG3(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1734 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1735 if (HAS_EXTENDED_IDS(ha))
1736 mcp->mb[1] = fcport->loop_id;
1738 mcp->mb[1] = fcport->loop_id << 8;
1740 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1741 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1742 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1744 rval = qla2x00_mailbox_command(vha, mcp);
1746 /* Return mailbox statuses. */
1747 if (mb_ret != NULL) {
1748 mb_ret[0] = mcp->mb[0];
1749 mb_ret[1] = mcp->mb[1];
1750 mb_ret[6] = mcp->mb[6];
1751 mb_ret[7] = mcp->mb[7];
1754 if (rval != QLA_SUCCESS) {
1755 /* AV tmp code: need to change main mailbox_command function to
1756 * return ok even when the mailbox completion value is not
1757 * SUCCESS. The caller needs to be responsible to interpret
1758 * the return values of this mailbox command if we're not
1759 * to change too much of the existing code.
1761 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1764 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1765 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
1766 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1767 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1768 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
1769 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1772 DEBUG3(printk("%s(%ld): done.\n", __func__, vha->host_no));
1779 qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1780 uint8_t area, uint8_t al_pa)
1783 struct logio_entry_24xx *lg;
1785 struct qla_hw_data *ha = vha->hw;
1786 struct req_que *req;
1787 struct rsp_que *rsp;
1789 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1791 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1793 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1794 __func__, vha->host_no));
1795 return QLA_MEMORY_ALLOC_FAILED;
1797 memset(lg, 0, sizeof(struct logio_entry_24xx));
1799 if (ql2xmaxqueues > 1)
1800 req = ha->req_q_map[0];
1804 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1805 lg->entry_count = 1;
1806 lg->handle = MAKE_HANDLE(req->id, lg->handle);
1807 lg->nport_handle = cpu_to_le16(loop_id);
1809 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
1810 lg->port_id[0] = al_pa;
1811 lg->port_id[1] = area;
1812 lg->port_id[2] = domain;
1813 lg->vp_index = vha->vp_idx;
1815 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
1816 if (rval != QLA_SUCCESS) {
1817 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1818 "(%x).\n", __func__, vha->host_no, rval));
1819 } else if (lg->entry_status != 0) {
1820 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1821 "-- error status (%x).\n", __func__, vha->host_no,
1823 rval = QLA_FUNCTION_FAILED;
1824 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1825 DEBUG2_3_11(printk("%s(%ld %d): failed to complete IOCB "
1826 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1827 vha->host_no, vha->vp_idx, le16_to_cpu(lg->comp_status),
1828 le32_to_cpu(lg->io_parameter[0]),
1829 le32_to_cpu(lg->io_parameter[1])));
1832 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1835 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1841 * qla2x00_fabric_logout
1842 * Issue logout fabric port mailbox command.
1845 * ha = adapter block pointer.
1846 * loop_id = device loop ID.
1847 * TARGET_QUEUE_LOCK must be released.
1848 * ADAPTER_STATE_LOCK must be released.
1851 * qla2x00 local function return status code.
1857 qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1858 uint8_t area, uint8_t al_pa)
1862 mbx_cmd_t *mcp = &mc;
1864 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1867 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1868 mcp->out_mb = MBX_1|MBX_0;
1869 if (HAS_EXTENDED_IDS(vha->hw)) {
1870 mcp->mb[1] = loop_id;
1872 mcp->out_mb |= MBX_10;
1874 mcp->mb[1] = loop_id << 8;
1877 mcp->in_mb = MBX_1|MBX_0;
1878 mcp->tov = MBX_TOV_SECONDS;
1880 rval = qla2x00_mailbox_command(vha, mcp);
1882 if (rval != QLA_SUCCESS) {
1884 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1885 "mbx1=%x.\n", vha->host_no, rval, mcp->mb[1]));
1888 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1896 * qla2x00_full_login_lip
1897 * Issue full login LIP mailbox command.
1900 * ha = adapter block pointer.
1901 * TARGET_QUEUE_LOCK must be released.
1902 * ADAPTER_STATE_LOCK must be released.
1905 * qla2x00 local function return status code.
1911 qla2x00_full_login_lip(scsi_qla_host_t *vha)
1915 mbx_cmd_t *mcp = &mc;
1917 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1920 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1921 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
1924 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1926 mcp->tov = MBX_TOV_SECONDS;
1928 rval = qla2x00_mailbox_command(vha, mcp);
1930 if (rval != QLA_SUCCESS) {
1932 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1933 vha->host_no, rval));
1936 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1944 * qla2x00_get_id_list
1947 * ha = adapter block pointer.
1950 * qla2x00 local function return status code.
1956 qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
1961 mbx_cmd_t *mcp = &mc;
1963 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1966 if (id_list == NULL)
1967 return QLA_FUNCTION_FAILED;
1969 mcp->mb[0] = MBC_GET_ID_LIST;
1970 mcp->out_mb = MBX_0;
1971 if (IS_FWI2_CAPABLE(vha->hw)) {
1972 mcp->mb[2] = MSW(id_list_dma);
1973 mcp->mb[3] = LSW(id_list_dma);
1974 mcp->mb[6] = MSW(MSD(id_list_dma));
1975 mcp->mb[7] = LSW(MSD(id_list_dma));
1977 mcp->mb[9] = vha->vp_idx;
1978 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
1980 mcp->mb[1] = MSW(id_list_dma);
1981 mcp->mb[2] = LSW(id_list_dma);
1982 mcp->mb[3] = MSW(MSD(id_list_dma));
1983 mcp->mb[6] = LSW(MSD(id_list_dma));
1984 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1986 mcp->in_mb = MBX_1|MBX_0;
1987 mcp->tov = MBX_TOV_SECONDS;
1989 rval = qla2x00_mailbox_command(vha, mcp);
1991 if (rval != QLA_SUCCESS) {
1993 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
1994 vha->host_no, rval));
1996 *entries = mcp->mb[1];
1997 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
2005 * qla2x00_get_resource_cnts
2006 * Get current firmware resource counts.
2009 * ha = adapter block pointer.
2012 * qla2x00 local function return status code.
2018 qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
2019 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
2020 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports, uint16_t *max_fcfs)
2024 mbx_cmd_t *mcp = &mc;
2026 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2028 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2029 mcp->out_mb = MBX_0;
2030 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2031 if (IS_QLA81XX(vha->hw))
2032 mcp->in_mb |= MBX_12;
2033 mcp->tov = MBX_TOV_SECONDS;
2035 rval = qla2x00_mailbox_command(vha, mcp);
2037 if (rval != QLA_SUCCESS) {
2039 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
2040 vha->host_no, mcp->mb[0]));
2042 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
2043 "mb7=%x mb10=%x mb11=%x mb12=%x.\n", __func__,
2044 vha->host_no, mcp->mb[1], mcp->mb[2], mcp->mb[3],
2045 mcp->mb[6], mcp->mb[7], mcp->mb[10], mcp->mb[11],
2049 *cur_xchg_cnt = mcp->mb[3];
2051 *orig_xchg_cnt = mcp->mb[6];
2053 *cur_iocb_cnt = mcp->mb[7];
2055 *orig_iocb_cnt = mcp->mb[10];
2056 if (vha->hw->flags.npiv_supported && max_npiv_vports)
2057 *max_npiv_vports = mcp->mb[11];
2058 if (IS_QLA81XX(vha->hw) && max_fcfs)
2059 *max_fcfs = mcp->mb[12];
2065 #if defined(QL_DEBUG_LEVEL_3)
2067 * qla2x00_get_fcal_position_map
2068 * Get FCAL (LILP) position map using mailbox command
2071 * ha = adapter state pointer.
2072 * pos_map = buffer pointer (can be NULL).
2075 * qla2x00 local function return status code.
2081 qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
2085 mbx_cmd_t *mcp = &mc;
2087 dma_addr_t pmap_dma;
2088 struct qla_hw_data *ha = vha->hw;
2090 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
2092 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
2093 __func__, vha->host_no));
2094 return QLA_MEMORY_ALLOC_FAILED;
2096 memset(pmap, 0, FCAL_MAP_SIZE);
2098 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2099 mcp->mb[2] = MSW(pmap_dma);
2100 mcp->mb[3] = LSW(pmap_dma);
2101 mcp->mb[6] = MSW(MSD(pmap_dma));
2102 mcp->mb[7] = LSW(MSD(pmap_dma));
2103 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2104 mcp->in_mb = MBX_1|MBX_0;
2105 mcp->buf_size = FCAL_MAP_SIZE;
2106 mcp->flags = MBX_DMA_IN;
2107 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2108 rval = qla2x00_mailbox_command(vha, mcp);
2110 if (rval == QLA_SUCCESS) {
2111 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2112 "size (%x)\n", __func__, vha->host_no, mcp->mb[0],
2113 mcp->mb[1], (unsigned)pmap[0]));
2114 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2117 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2119 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2121 if (rval != QLA_SUCCESS) {
2122 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2123 vha->host_no, rval));
2125 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2133 * qla2x00_get_link_status
2136 * ha = adapter block pointer.
2137 * loop_id = device loop ID.
2138 * ret_buf = pointer to link status return buffer.
2142 * BIT_0 = mem alloc error.
2143 * BIT_1 = mailbox error.
2146 qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
2147 struct link_statistics *stats, dma_addr_t stats_dma)
2151 mbx_cmd_t *mcp = &mc;
2152 uint32_t *siter, *diter, dwords;
2153 struct qla_hw_data *ha = vha->hw;
2155 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2157 mcp->mb[0] = MBC_GET_LINK_STATUS;
2158 mcp->mb[2] = MSW(stats_dma);
2159 mcp->mb[3] = LSW(stats_dma);
2160 mcp->mb[6] = MSW(MSD(stats_dma));
2161 mcp->mb[7] = LSW(MSD(stats_dma));
2162 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2164 if (IS_FWI2_CAPABLE(ha)) {
2165 mcp->mb[1] = loop_id;
2168 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2169 mcp->in_mb |= MBX_1;
2170 } else if (HAS_EXTENDED_IDS(ha)) {
2171 mcp->mb[1] = loop_id;
2173 mcp->out_mb |= MBX_10|MBX_1;
2175 mcp->mb[1] = loop_id << 8;
2176 mcp->out_mb |= MBX_1;
2178 mcp->tov = MBX_TOV_SECONDS;
2179 mcp->flags = IOCTL_CMD;
2180 rval = qla2x00_mailbox_command(vha, mcp);
2182 if (rval == QLA_SUCCESS) {
2183 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2184 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2185 __func__, vha->host_no, mcp->mb[0]));
2186 rval = QLA_FUNCTION_FAILED;
2188 /* Copy over data -- firmware data is LE. */
2189 dwords = offsetof(struct link_statistics, unused1) / 4;
2190 siter = diter = &stats->link_fail_cnt;
2192 *diter++ = le32_to_cpu(*siter++);
2196 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2197 vha->host_no, rval));
2204 qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
2205 dma_addr_t stats_dma)
2209 mbx_cmd_t *mcp = &mc;
2210 uint32_t *siter, *diter, dwords;
2212 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2214 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2215 mcp->mb[2] = MSW(stats_dma);
2216 mcp->mb[3] = LSW(stats_dma);
2217 mcp->mb[6] = MSW(MSD(stats_dma));
2218 mcp->mb[7] = LSW(MSD(stats_dma));
2219 mcp->mb[8] = sizeof(struct link_statistics) / 4;
2220 mcp->mb[9] = vha->vp_idx;
2222 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2223 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2224 mcp->tov = MBX_TOV_SECONDS;
2225 mcp->flags = IOCTL_CMD;
2226 rval = qla2x00_mailbox_command(vha, mcp);
2228 if (rval == QLA_SUCCESS) {
2229 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2230 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2231 __func__, vha->host_no, mcp->mb[0]));
2232 rval = QLA_FUNCTION_FAILED;
2234 /* Copy over data -- firmware data is LE. */
2235 dwords = sizeof(struct link_statistics) / 4;
2236 siter = diter = &stats->link_fail_cnt;
2238 *diter++ = le32_to_cpu(*siter++);
2242 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2243 vha->host_no, rval));
2250 qla24xx_abort_command(srb_t *sp)
2253 unsigned long flags = 0;
2255 struct abort_entry_24xx *abt;
2258 fc_port_t *fcport = sp->fcport;
2259 struct scsi_qla_host *vha = fcport->vha;
2260 struct qla_hw_data *ha = vha->hw;
2261 struct req_que *req = vha->req;
2263 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2265 spin_lock_irqsave(&ha->hardware_lock, flags);
2266 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2267 if (req->outstanding_cmds[handle] == sp)
2270 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2271 if (handle == MAX_OUTSTANDING_COMMANDS) {
2272 /* Command not found. */
2273 return QLA_FUNCTION_FAILED;
2276 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2278 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2279 __func__, vha->host_no));
2280 return QLA_MEMORY_ALLOC_FAILED;
2282 memset(abt, 0, sizeof(struct abort_entry_24xx));
2284 abt->entry_type = ABORT_IOCB_TYPE;
2285 abt->entry_count = 1;
2286 abt->handle = MAKE_HANDLE(req->id, abt->handle);
2287 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2288 abt->handle_to_abort = handle;
2289 abt->port_id[0] = fcport->d_id.b.al_pa;
2290 abt->port_id[1] = fcport->d_id.b.area;
2291 abt->port_id[2] = fcport->d_id.b.domain;
2292 abt->vp_index = fcport->vp_idx;
2294 abt->req_que_no = cpu_to_le16(req->id);
2296 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
2297 if (rval != QLA_SUCCESS) {
2298 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2299 __func__, vha->host_no, rval));
2300 } else if (abt->entry_status != 0) {
2301 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2302 "-- error status (%x).\n", __func__, vha->host_no,
2303 abt->entry_status));
2304 rval = QLA_FUNCTION_FAILED;
2305 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2306 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2307 "-- completion status (%x).\n", __func__, vha->host_no,
2308 le16_to_cpu(abt->nport_handle)));
2309 rval = QLA_FUNCTION_FAILED;
2311 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2314 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2319 struct tsk_mgmt_cmd {
2321 struct tsk_mgmt_entry tsk;
2322 struct sts_entry_24xx sts;
2327 __qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
2328 unsigned int l, int tag)
2331 struct tsk_mgmt_cmd *tsk;
2332 struct sts_entry_24xx *sts;
2334 scsi_qla_host_t *vha;
2335 struct qla_hw_data *ha;
2336 struct req_que *req;
2337 struct rsp_que *rsp;
2339 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
2344 if (ha->flags.cpu_affinity_enabled)
2345 rsp = ha->rsp_q_map[tag + 1];
2348 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
2350 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2351 "IOCB.\n", __func__, vha->host_no));
2352 return QLA_MEMORY_ALLOC_FAILED;
2354 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2356 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2357 tsk->p.tsk.entry_count = 1;
2358 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
2359 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2360 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
2361 tsk->p.tsk.control_flags = cpu_to_le32(type);
2362 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2363 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2364 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2365 tsk->p.tsk.vp_index = fcport->vp_idx;
2366 if (type == TCF_LUN_RESET) {
2367 int_to_scsilun(l, &tsk->p.tsk.lun);
2368 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2369 sizeof(tsk->p.tsk.lun));
2373 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
2374 if (rval != QLA_SUCCESS) {
2375 DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
2376 "(%x).\n", __func__, vha->host_no, name, rval));
2377 } else if (sts->entry_status != 0) {
2378 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2379 "-- error status (%x).\n", __func__, vha->host_no,
2380 sts->entry_status));
2381 rval = QLA_FUNCTION_FAILED;
2382 } else if (sts->comp_status !=
2383 __constant_cpu_to_le16(CS_COMPLETE)) {
2384 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2385 "-- completion status (%x).\n", __func__,
2386 vha->host_no, le16_to_cpu(sts->comp_status)));
2387 rval = QLA_FUNCTION_FAILED;
2388 } else if (!(le16_to_cpu(sts->scsi_status) &
2389 SS_RESPONSE_INFO_LEN_VALID)) {
2390 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2391 "-- no response info (%x).\n", __func__, vha->host_no,
2392 le16_to_cpu(sts->scsi_status)));
2393 rval = QLA_FUNCTION_FAILED;
2394 } else if (le32_to_cpu(sts->rsp_data_len) < 4) {
2395 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2396 "-- not enough response info (%d).\n", __func__,
2397 vha->host_no, le32_to_cpu(sts->rsp_data_len)));
2398 rval = QLA_FUNCTION_FAILED;
2399 } else if (sts->data[3]) {
2400 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2401 "-- response (%x).\n", __func__,
2402 vha->host_no, sts->data[3]));
2403 rval = QLA_FUNCTION_FAILED;
2406 /* Issue marker IOCB. */
2407 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
2408 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2409 if (rval2 != QLA_SUCCESS) {
2410 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2411 "(%x).\n", __func__, vha->host_no, rval2));
2413 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2416 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
2422 qla24xx_abort_target(struct fc_port *fcport, unsigned int l, int tag)
2424 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
2428 qla24xx_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
2430 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
2434 qla2x00_system_error(scsi_qla_host_t *vha)
2438 mbx_cmd_t *mcp = &mc;
2439 struct qla_hw_data *ha = vha->hw;
2441 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
2442 return QLA_FUNCTION_FAILED;
2444 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2446 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2447 mcp->out_mb = MBX_0;
2451 rval = qla2x00_mailbox_command(vha, mcp);
2453 if (rval != QLA_SUCCESS) {
2454 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2455 vha->host_no, rval));
2457 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2464 * qla2x00_set_serdes_params() -
2470 qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
2471 uint16_t sw_em_2g, uint16_t sw_em_4g)
2475 mbx_cmd_t *mcp = &mc;
2477 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2479 mcp->mb[0] = MBC_SERDES_PARAMS;
2481 mcp->mb[2] = sw_em_1g | BIT_15;
2482 mcp->mb[3] = sw_em_2g | BIT_15;
2483 mcp->mb[4] = sw_em_4g | BIT_15;
2484 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2486 mcp->tov = MBX_TOV_SECONDS;
2488 rval = qla2x00_mailbox_command(vha, mcp);
2490 if (rval != QLA_SUCCESS) {
2492 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2493 vha->host_no, rval, mcp->mb[0]));
2496 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2503 qla2x00_stop_firmware(scsi_qla_host_t *vha)
2507 mbx_cmd_t *mcp = &mc;
2509 if (!IS_FWI2_CAPABLE(vha->hw))
2510 return QLA_FUNCTION_FAILED;
2512 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2514 mcp->mb[0] = MBC_STOP_FIRMWARE;
2515 mcp->out_mb = MBX_0;
2519 rval = qla2x00_mailbox_command(vha, mcp);
2521 if (rval != QLA_SUCCESS) {
2522 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2523 vha->host_no, rval));
2524 if (mcp->mb[0] == MBS_INVALID_COMMAND)
2525 rval = QLA_INVALID_COMMAND;
2527 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2534 qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
2539 mbx_cmd_t *mcp = &mc;
2541 if (!IS_FWI2_CAPABLE(vha->hw))
2542 return QLA_FUNCTION_FAILED;
2544 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2545 return QLA_FUNCTION_FAILED;
2547 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2549 mcp->mb[0] = MBC_TRACE_CONTROL;
2550 mcp->mb[1] = TC_EFT_ENABLE;
2551 mcp->mb[2] = LSW(eft_dma);
2552 mcp->mb[3] = MSW(eft_dma);
2553 mcp->mb[4] = LSW(MSD(eft_dma));
2554 mcp->mb[5] = MSW(MSD(eft_dma));
2555 mcp->mb[6] = buffers;
2556 mcp->mb[7] = TC_AEN_DISABLE;
2557 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2558 mcp->in_mb = MBX_1|MBX_0;
2559 mcp->tov = MBX_TOV_SECONDS;
2561 rval = qla2x00_mailbox_command(vha, mcp);
2562 if (rval != QLA_SUCCESS) {
2563 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2564 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2566 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2573 qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
2577 mbx_cmd_t *mcp = &mc;
2579 if (!IS_FWI2_CAPABLE(vha->hw))
2580 return QLA_FUNCTION_FAILED;
2582 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2583 return QLA_FUNCTION_FAILED;
2585 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2587 mcp->mb[0] = MBC_TRACE_CONTROL;
2588 mcp->mb[1] = TC_EFT_DISABLE;
2589 mcp->out_mb = MBX_1|MBX_0;
2590 mcp->in_mb = MBX_1|MBX_0;
2591 mcp->tov = MBX_TOV_SECONDS;
2593 rval = qla2x00_mailbox_command(vha, mcp);
2594 if (rval != QLA_SUCCESS) {
2595 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2596 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2598 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2605 qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
2606 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2610 mbx_cmd_t *mcp = &mc;
2612 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw))
2613 return QLA_FUNCTION_FAILED;
2615 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2616 return QLA_FUNCTION_FAILED;
2618 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2620 mcp->mb[0] = MBC_TRACE_CONTROL;
2621 mcp->mb[1] = TC_FCE_ENABLE;
2622 mcp->mb[2] = LSW(fce_dma);
2623 mcp->mb[3] = MSW(fce_dma);
2624 mcp->mb[4] = LSW(MSD(fce_dma));
2625 mcp->mb[5] = MSW(MSD(fce_dma));
2626 mcp->mb[6] = buffers;
2627 mcp->mb[7] = TC_AEN_DISABLE;
2629 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2630 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2631 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2633 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2634 mcp->tov = MBX_TOV_SECONDS;
2636 rval = qla2x00_mailbox_command(vha, mcp);
2637 if (rval != QLA_SUCCESS) {
2638 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2639 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2641 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2644 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2653 qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
2657 mbx_cmd_t *mcp = &mc;
2659 if (!IS_FWI2_CAPABLE(vha->hw))
2660 return QLA_FUNCTION_FAILED;
2662 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2663 return QLA_FUNCTION_FAILED;
2665 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2667 mcp->mb[0] = MBC_TRACE_CONTROL;
2668 mcp->mb[1] = TC_FCE_DISABLE;
2669 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
2670 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2671 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2673 mcp->tov = MBX_TOV_SECONDS;
2675 rval = qla2x00_mailbox_command(vha, mcp);
2676 if (rval != QLA_SUCCESS) {
2677 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2678 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2680 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2683 *wr = (uint64_t) mcp->mb[5] << 48 |
2684 (uint64_t) mcp->mb[4] << 32 |
2685 (uint64_t) mcp->mb[3] << 16 |
2686 (uint64_t) mcp->mb[2];
2688 *rd = (uint64_t) mcp->mb[9] << 48 |
2689 (uint64_t) mcp->mb[8] << 32 |
2690 (uint64_t) mcp->mb[7] << 16 |
2691 (uint64_t) mcp->mb[6];
2698 qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint16_t addr,
2699 uint16_t off, uint16_t count)
2703 mbx_cmd_t *mcp = &mc;
2705 if (!IS_FWI2_CAPABLE(vha->hw))
2706 return QLA_FUNCTION_FAILED;
2708 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2710 mcp->mb[0] = MBC_READ_SFP;
2712 mcp->mb[2] = MSW(sfp_dma);
2713 mcp->mb[3] = LSW(sfp_dma);
2714 mcp->mb[6] = MSW(MSD(sfp_dma));
2715 mcp->mb[7] = LSW(MSD(sfp_dma));
2719 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2721 mcp->tov = MBX_TOV_SECONDS;
2723 rval = qla2x00_mailbox_command(vha, mcp);
2725 if (rval != QLA_SUCCESS) {
2726 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2727 vha->host_no, rval, mcp->mb[0]));
2729 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2736 qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
2737 uint16_t port_speed, uint16_t *mb)
2741 mbx_cmd_t *mcp = &mc;
2743 if (!IS_IIDMA_CAPABLE(vha->hw))
2744 return QLA_FUNCTION_FAILED;
2746 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2748 mcp->mb[0] = MBC_PORT_PARAMS;
2749 mcp->mb[1] = loop_id;
2751 if (IS_QLA81XX(vha->hw))
2752 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
2754 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2755 mcp->mb[9] = vha->vp_idx;
2756 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
2757 mcp->in_mb = MBX_3|MBX_1|MBX_0;
2758 mcp->tov = MBX_TOV_SECONDS;
2760 rval = qla2x00_mailbox_command(vha, mcp);
2762 /* Return mailbox statuses. */
2769 if (rval != QLA_SUCCESS) {
2770 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2771 vha->host_no, rval));
2773 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2780 qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
2781 struct vp_rpt_id_entry_24xx *rptid_entry)
2784 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
2785 struct qla_hw_data *ha = vha->hw;
2786 scsi_qla_host_t *vp;
2787 scsi_qla_host_t *tvp;
2789 if (rptid_entry->entry_status != 0)
2792 if (rptid_entry->format == 0) {
2793 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
2794 " number of VPs acquired %d\n", __func__, vha->host_no,
2795 MSB(le16_to_cpu(rptid_entry->vp_count)),
2796 LSB(le16_to_cpu(rptid_entry->vp_count))));
2797 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2798 rptid_entry->port_id[2], rptid_entry->port_id[1],
2799 rptid_entry->port_id[0]));
2800 } else if (rptid_entry->format == 1) {
2802 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2804 "with port id %02x%02x%02x\n", __func__, vha->host_no,
2806 rptid_entry->port_id[2], rptid_entry->port_id[1],
2807 rptid_entry->port_id[0]));
2810 if (vp_idx == 0 && (MSB(stat) != 1))
2813 if (MSB(stat) == 1) {
2814 DEBUG2(printk("scsi(%ld): Could not acquire ID for "
2815 "VP[%d].\n", vha->host_no, vp_idx));
2819 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
2820 if (vp_idx == vp->vp_idx)
2825 vp->d_id.b.domain = rptid_entry->port_id[2];
2826 vp->d_id.b.area = rptid_entry->port_id[1];
2827 vp->d_id.b.al_pa = rptid_entry->port_id[0];
2830 * Cannot configure here as we are still sitting on the
2831 * response queue. Handle it in dpc context.
2833 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
2836 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
2837 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
2838 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
2839 qla2xxx_wake_dpc(vha);
2844 * qla24xx_modify_vp_config
2845 * Change VP configuration for vha
2848 * vha = adapter block pointer.
2851 * qla2xxx local function return status code.
2857 qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2860 struct vp_config_entry_24xx *vpmod;
2861 dma_addr_t vpmod_dma;
2862 struct qla_hw_data *ha = vha->hw;
2863 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2865 /* This can be called by the parent */
2867 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
2869 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
2870 "IOCB.\n", __func__, vha->host_no));
2871 return QLA_MEMORY_ALLOC_FAILED;
2874 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2875 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2876 vpmod->entry_count = 1;
2877 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2878 vpmod->vp_count = 1;
2879 vpmod->vp_index1 = vha->vp_idx;
2880 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2881 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2882 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2883 vpmod->entry_count = 1;
2885 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
2886 if (rval != QLA_SUCCESS) {
2887 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
2888 "(%x).\n", __func__, base_vha->host_no, rval));
2889 } else if (vpmod->comp_status != 0) {
2890 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2891 "-- error status (%x).\n", __func__, base_vha->host_no,
2892 vpmod->comp_status));
2893 rval = QLA_FUNCTION_FAILED;
2894 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2895 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2896 "-- completion status (%x).\n", __func__, base_vha->host_no,
2897 le16_to_cpu(vpmod->comp_status)));
2898 rval = QLA_FUNCTION_FAILED;
2901 DEBUG11(printk("%s(%ld): done.\n", __func__,
2902 base_vha->host_no));
2903 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2905 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
2911 * qla24xx_control_vp
2912 * Enable a virtual port for given host
2915 * ha = adapter block pointer.
2916 * vhba = virtual adapter (unused)
2917 * index = index number for enabled VP
2920 * qla2xxx local function return status code.
2926 qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2930 struct vp_ctrl_entry_24xx *vce;
2932 struct qla_hw_data *ha = vha->hw;
2933 int vp_index = vha->vp_idx;
2934 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2936 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
2937 vha->host_no, vp_index));
2939 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
2940 return QLA_PARAMETER_ERROR;
2942 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2944 DEBUG2_3(printk("%s(%ld): "
2945 "failed to allocate VP Control IOCB.\n", __func__,
2946 base_vha->host_no));
2947 return QLA_MEMORY_ALLOC_FAILED;
2949 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2951 vce->entry_type = VP_CTRL_IOCB_TYPE;
2952 vce->entry_count = 1;
2953 vce->command = cpu_to_le16(cmd);
2954 vce->vp_count = __constant_cpu_to_le16(1);
2956 /* index map in firmware starts with 1; decrement index
2957 * this is ok as we never use index 0
2959 map = (vp_index - 1) / 8;
2960 pos = (vp_index - 1) & 7;
2961 mutex_lock(&ha->vport_lock);
2962 vce->vp_idx_map[map] |= 1 << pos;
2963 mutex_unlock(&ha->vport_lock);
2965 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
2966 if (rval != QLA_SUCCESS) {
2967 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
2968 "(%x).\n", __func__, base_vha->host_no, rval));
2969 printk("%s(%ld): failed to issue VP control IOCB"
2970 "(%x).\n", __func__, base_vha->host_no, rval);
2971 } else if (vce->entry_status != 0) {
2972 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2973 "-- error status (%x).\n", __func__, base_vha->host_no,
2974 vce->entry_status));
2975 printk("%s(%ld): failed to complete IOCB "
2976 "-- error status (%x).\n", __func__, base_vha->host_no,
2978 rval = QLA_FUNCTION_FAILED;
2979 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2980 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2981 "-- completion status (%x).\n", __func__, base_vha->host_no,
2982 le16_to_cpu(vce->comp_status)));
2983 printk("%s(%ld): failed to complete IOCB "
2984 "-- completion status (%x).\n", __func__, base_vha->host_no,
2985 le16_to_cpu(vce->comp_status));
2986 rval = QLA_FUNCTION_FAILED;
2988 DEBUG2(printk("%s(%ld): done.\n", __func__, base_vha->host_no));
2991 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
2997 * qla2x00_send_change_request
2998 * Receive or disable RSCN request from fabric controller
3001 * ha = adapter block pointer
3002 * format = registration format:
3004 * 1 - Fabric detected registration
3005 * 2 - N_port detected registration
3006 * 3 - Full registration
3007 * FF - clear registration
3008 * vp_idx = Virtual port index
3011 * qla2x00 local function return status code.
3018 qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
3023 mbx_cmd_t *mcp = &mc;
3026 * This command is implicitly executed by firmware during login for the
3030 return QLA_FUNCTION_FAILED;
3032 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
3033 mcp->mb[1] = format;
3034 mcp->mb[9] = vp_idx;
3035 mcp->out_mb = MBX_9|MBX_1|MBX_0;
3036 mcp->in_mb = MBX_0|MBX_1;
3037 mcp->tov = MBX_TOV_SECONDS;
3039 rval = qla2x00_mailbox_command(vha, mcp);
3041 if (rval == QLA_SUCCESS) {
3042 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
3052 qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
3057 mbx_cmd_t *mcp = &mc;
3059 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3061 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
3062 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3063 mcp->mb[8] = MSW(addr);
3064 mcp->out_mb = MBX_8|MBX_0;
3066 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3067 mcp->out_mb = MBX_0;
3069 mcp->mb[1] = LSW(addr);
3070 mcp->mb[2] = MSW(req_dma);
3071 mcp->mb[3] = LSW(req_dma);
3072 mcp->mb[6] = MSW(MSD(req_dma));
3073 mcp->mb[7] = LSW(MSD(req_dma));
3074 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
3075 if (IS_FWI2_CAPABLE(vha->hw)) {
3076 mcp->mb[4] = MSW(size);
3077 mcp->mb[5] = LSW(size);
3078 mcp->out_mb |= MBX_5|MBX_4;
3080 mcp->mb[4] = LSW(size);
3081 mcp->out_mb |= MBX_4;
3085 mcp->tov = MBX_TOV_SECONDS;
3087 rval = qla2x00_mailbox_command(vha, mcp);
3089 if (rval != QLA_SUCCESS) {
3090 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3091 vha->host_no, rval, mcp->mb[0]));
3093 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3099 /* 84XX Support **************************************************************/
3101 struct cs84xx_mgmt_cmd {
3103 struct verify_chip_entry_84xx req;
3104 struct verify_chip_rsp_84xx rsp;
3109 qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
3112 struct cs84xx_mgmt_cmd *mn;
3115 unsigned long flags;
3116 struct qla_hw_data *ha = vha->hw;
3118 DEBUG16(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3120 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
3122 DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX "
3123 "IOCB.\n", __func__, vha->host_no));
3124 return QLA_MEMORY_ALLOC_FAILED;
3128 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
3129 /* Diagnostic firmware? */
3130 /* options |= MENLO_DIAG_FW; */
3131 /* We update the firmware with only one data sequence. */
3132 options |= VCO_END_OF_DATA;
3136 memset(mn, 0, sizeof(*mn));
3137 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
3138 mn->p.req.entry_count = 1;
3139 mn->p.req.options = cpu_to_le16(options);
3141 DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__,
3143 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3146 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
3147 if (rval != QLA_SUCCESS) {
3148 DEBUG2_16(printk("%s(%ld): failed to issue Verify "
3149 "IOCB (%x).\n", __func__, vha->host_no, rval));
3153 DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__,
3155 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3158 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3159 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3160 le16_to_cpu(mn->p.rsp.failure_code) : 0;
3161 DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__,
3162 vha->host_no, status[0], status[1]));
3164 if (status[0] != CS_COMPLETE) {
3165 rval = QLA_FUNCTION_FAILED;
3166 if (!(options & VCO_DONT_UPDATE_FW)) {
3167 DEBUG2_16(printk("%s(%ld): Firmware update "
3168 "failed. Retrying without update "
3169 "firmware.\n", __func__, vha->host_no));
3170 options |= VCO_DONT_UPDATE_FW;
3171 options &= ~VCO_FORCE_UPDATE;
3175 DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n",
3176 __func__, vha->host_no,
3177 le32_to_cpu(mn->p.rsp.fw_ver)));
3179 /* NOTE: we only update OP firmware. */
3180 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3181 ha->cs84xx->op_fw_version =
3182 le32_to_cpu(mn->p.rsp.fw_ver);
3183 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3189 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3191 if (rval != QLA_SUCCESS) {
3192 DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__,
3193 vha->host_no, rval));
3195 DEBUG16(printk("%s(%ld): done.\n", __func__, vha->host_no));
3202 qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
3205 unsigned long flags;
3207 mbx_cmd_t *mcp = &mc;
3208 struct device_reg_25xxmq __iomem *reg;
3209 struct qla_hw_data *ha = vha->hw;
3211 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
3212 mcp->mb[1] = req->options;
3213 mcp->mb[2] = MSW(LSD(req->dma));
3214 mcp->mb[3] = LSW(LSD(req->dma));
3215 mcp->mb[6] = MSW(MSD(req->dma));
3216 mcp->mb[7] = LSW(MSD(req->dma));
3217 mcp->mb[5] = req->length;
3219 mcp->mb[10] = req->rsp->id;
3220 mcp->mb[12] = req->qos;
3221 mcp->mb[11] = req->vp_idx;
3222 mcp->mb[13] = req->rid;
3224 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3225 QLA_QUE_PAGE * req->id);
3227 mcp->mb[4] = req->id;
3228 /* que in ptr index */
3230 /* que out ptr index */
3232 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
3233 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3235 mcp->flags = MBX_DMA_OUT;
3238 spin_lock_irqsave(&ha->hardware_lock, flags);
3239 if (!(req->options & BIT_0)) {
3240 WRT_REG_DWORD(®->req_q_in, 0);
3241 WRT_REG_DWORD(®->req_q_out, 0);
3243 req->req_q_in = ®->req_q_in;
3244 req->req_q_out = ®->req_q_out;
3245 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3247 rval = qla2x00_mailbox_command(vha, mcp);
3248 if (rval != QLA_SUCCESS)
3249 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x mb0=%x.\n",
3250 __func__, vha->host_no, rval, mcp->mb[0]));
3255 qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
3258 unsigned long flags;
3260 mbx_cmd_t *mcp = &mc;
3261 struct device_reg_25xxmq __iomem *reg;
3262 struct qla_hw_data *ha = vha->hw;
3264 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
3265 mcp->mb[1] = rsp->options;
3266 mcp->mb[2] = MSW(LSD(rsp->dma));
3267 mcp->mb[3] = LSW(LSD(rsp->dma));
3268 mcp->mb[6] = MSW(MSD(rsp->dma));
3269 mcp->mb[7] = LSW(MSD(rsp->dma));
3270 mcp->mb[5] = rsp->length;
3271 mcp->mb[14] = rsp->msix->entry;
3272 mcp->mb[13] = rsp->rid;
3274 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3275 QLA_QUE_PAGE * rsp->id);
3277 mcp->mb[4] = rsp->id;
3278 /* que in ptr index */
3280 /* que out ptr index */
3282 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
3283 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3285 mcp->flags = MBX_DMA_OUT;
3288 spin_lock_irqsave(&ha->hardware_lock, flags);
3289 if (!(rsp->options & BIT_0)) {
3290 WRT_REG_DWORD(®->rsp_q_out, 0);
3291 WRT_REG_DWORD(®->rsp_q_in, 0);
3294 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3296 rval = qla2x00_mailbox_command(vha, mcp);
3297 if (rval != QLA_SUCCESS)
3298 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x "
3299 "mb0=%x.\n", __func__,
3300 vha->host_no, rval, mcp->mb[0]));
3305 qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
3309 mbx_cmd_t *mcp = &mc;
3311 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3313 mcp->mb[0] = MBC_IDC_ACK;
3314 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
3315 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3317 mcp->tov = MBX_TOV_SECONDS;
3319 rval = qla2x00_mailbox_command(vha, mcp);
3321 if (rval != QLA_SUCCESS) {
3322 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3323 vha->host_no, rval, mcp->mb[0]));
3325 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3332 qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
3336 mbx_cmd_t *mcp = &mc;
3338 if (!IS_QLA81XX(vha->hw))
3339 return QLA_FUNCTION_FAILED;
3341 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3343 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3344 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
3345 mcp->out_mb = MBX_1|MBX_0;
3346 mcp->in_mb = MBX_1|MBX_0;
3347 mcp->tov = MBX_TOV_SECONDS;
3349 rval = qla2x00_mailbox_command(vha, mcp);
3351 if (rval != QLA_SUCCESS) {
3352 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
3353 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3355 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3356 *sector_size = mcp->mb[1];
3363 qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
3367 mbx_cmd_t *mcp = &mc;
3369 if (!IS_QLA81XX(vha->hw))
3370 return QLA_FUNCTION_FAILED;
3372 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3374 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3375 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
3376 FAC_OPT_CMD_WRITE_PROTECT;
3377 mcp->out_mb = MBX_1|MBX_0;
3378 mcp->in_mb = MBX_1|MBX_0;
3379 mcp->tov = MBX_TOV_SECONDS;
3381 rval = qla2x00_mailbox_command(vha, mcp);
3383 if (rval != QLA_SUCCESS) {
3384 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
3385 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3387 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3394 qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
3398 mbx_cmd_t *mcp = &mc;
3400 if (!IS_QLA81XX(vha->hw))
3401 return QLA_FUNCTION_FAILED;
3403 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3405 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3406 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
3407 mcp->mb[2] = LSW(start);
3408 mcp->mb[3] = MSW(start);
3409 mcp->mb[4] = LSW(finish);
3410 mcp->mb[5] = MSW(finish);
3411 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3412 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3413 mcp->tov = MBX_TOV_SECONDS;
3415 rval = qla2x00_mailbox_command(vha, mcp);
3417 if (rval != QLA_SUCCESS) {
3418 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
3419 "mb[2]=%x.\n", __func__, vha->host_no, rval, mcp->mb[0],
3420 mcp->mb[1], mcp->mb[2]));
3422 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3429 qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
3433 mbx_cmd_t *mcp = &mc;
3435 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3437 mcp->mb[0] = MBC_RESTART_MPI_FW;
3438 mcp->out_mb = MBX_0;
3439 mcp->in_mb = MBX_0|MBX_1;
3440 mcp->tov = MBX_TOV_SECONDS;
3442 rval = qla2x00_mailbox_command(vha, mcp);
3444 if (rval != QLA_SUCCESS) {
3445 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x mb[1]=0x%x.\n",
3446 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3448 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3455 qla2x00_read_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
3456 dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
3460 mbx_cmd_t *mcp = &mc;
3462 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3464 mcp->mb[0] = MBC_READ_SFP;
3466 mcp->mb[2] = MSW(sfp_dma);
3467 mcp->mb[3] = LSW(sfp_dma);
3468 mcp->mb[6] = MSW(MSD(sfp_dma));
3469 mcp->mb[7] = LSW(MSD(sfp_dma));
3473 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3475 mcp->tov = MBX_TOV_SECONDS;
3477 rval = qla2x00_mailbox_command(vha, mcp);
3483 if (rval != QLA_SUCCESS) {
3484 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3485 vha->host_no, rval, mcp->mb[0]));
3487 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3494 qla2x00_write_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
3495 dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
3499 mbx_cmd_t *mcp = &mc;
3501 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3507 mcp->mb[0] = MBC_WRITE_SFP;
3509 mcp->mb[2] = MSW(sfp_dma);
3510 mcp->mb[3] = LSW(sfp_dma);
3511 mcp->mb[6] = MSW(MSD(sfp_dma));
3512 mcp->mb[7] = LSW(MSD(sfp_dma));
3516 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3518 mcp->tov = MBX_TOV_SECONDS;
3520 rval = qla2x00_mailbox_command(vha, mcp);
3522 if (rval != QLA_SUCCESS) {
3523 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3524 vha->host_no, rval, mcp->mb[0]));
3526 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3533 qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
3534 uint16_t size_in_bytes, uint16_t *actual_size)
3538 mbx_cmd_t *mcp = &mc;
3540 if (!IS_QLA81XX(vha->hw))
3541 return QLA_FUNCTION_FAILED;
3543 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3545 mcp->mb[0] = MBC_GET_XGMAC_STATS;
3546 mcp->mb[2] = MSW(stats_dma);
3547 mcp->mb[3] = LSW(stats_dma);
3548 mcp->mb[6] = MSW(MSD(stats_dma));
3549 mcp->mb[7] = LSW(MSD(stats_dma));
3550 mcp->mb[8] = size_in_bytes >> 2;
3551 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
3552 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3553 mcp->tov = MBX_TOV_SECONDS;
3555 rval = qla2x00_mailbox_command(vha, mcp);
3557 if (rval != QLA_SUCCESS) {
3558 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x "
3559 "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval,
3560 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
3562 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3564 *actual_size = mcp->mb[2] << 2;
3571 qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
3576 mbx_cmd_t *mcp = &mc;
3578 if (!IS_QLA81XX(vha->hw))
3579 return QLA_FUNCTION_FAILED;
3581 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3583 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
3585 mcp->mb[2] = MSW(tlv_dma);
3586 mcp->mb[3] = LSW(tlv_dma);
3587 mcp->mb[6] = MSW(MSD(tlv_dma));
3588 mcp->mb[7] = LSW(MSD(tlv_dma));
3590 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3591 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3592 mcp->tov = MBX_TOV_SECONDS;
3594 rval = qla2x00_mailbox_command(vha, mcp);
3596 if (rval != QLA_SUCCESS) {
3597 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x "
3598 "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval,
3599 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
3601 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3608 qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
3612 mbx_cmd_t *mcp = &mc;
3614 if (!IS_FWI2_CAPABLE(vha->hw))
3615 return QLA_FUNCTION_FAILED;
3617 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3619 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
3620 mcp->mb[1] = LSW(risc_addr);
3621 mcp->mb[8] = MSW(risc_addr);
3622 mcp->out_mb = MBX_8|MBX_1|MBX_0;
3623 mcp->in_mb = MBX_3|MBX_2|MBX_0;
3626 rval = qla2x00_mailbox_command(vha, mcp);
3627 if (rval != QLA_SUCCESS) {
3628 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3629 vha->host_no, rval, mcp->mb[0]));
3631 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3632 *data = mcp->mb[3] << 16 | mcp->mb[2];
3639 qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq, uint16_t *mresp)
3643 mbx_cmd_t *mcp = &mc;
3644 uint32_t iter_cnt = 0x1;
3646 DEBUG11(printk("scsi(%ld): entered.\n", vha->host_no));
3648 memset(mcp->mb, 0 , sizeof(mcp->mb));
3649 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
3650 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
3652 /* transfer count */
3653 mcp->mb[10] = LSW(mreq->transfer_size);
3654 mcp->mb[11] = MSW(mreq->transfer_size);
3656 /* send data address */
3657 mcp->mb[14] = LSW(mreq->send_dma);
3658 mcp->mb[15] = MSW(mreq->send_dma);
3659 mcp->mb[20] = LSW(MSD(mreq->send_dma));
3660 mcp->mb[21] = MSW(MSD(mreq->send_dma));
3662 /* recieve data address */
3663 mcp->mb[16] = LSW(mreq->rcv_dma);
3664 mcp->mb[17] = MSW(mreq->rcv_dma);
3665 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
3666 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
3668 /* Iteration count */
3669 mcp->mb[18] = LSW(iter_cnt);
3670 mcp->mb[19] = MSW(iter_cnt);
3672 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
3673 MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
3674 if (IS_QLA81XX(vha->hw))
3675 mcp->out_mb |= MBX_2;
3676 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
3678 mcp->buf_size = mreq->transfer_size;
3679 mcp->tov = MBX_TOV_SECONDS;
3680 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3682 rval = qla2x00_mailbox_command(vha, mcp);
3684 if (rval != QLA_SUCCESS) {
3685 DEBUG2(printk(KERN_WARNING
3686 "(%ld): failed=%x mb[0]=0x%x "
3687 "mb[1]=0x%x mb[2]=0x%x mb[3]=0x%x mb[18]=0x%x mb[19]=0x%x. \n", vha->host_no, rval,
3688 mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[18], mcp->mb[19]));
3690 DEBUG2(printk(KERN_WARNING
3691 "scsi(%ld): done.\n", vha->host_no));
3694 /* Copy mailbox information */
3695 memcpy( mresp, mcp->mb, 64);
3696 mresp[3] = mcp->mb[18];
3697 mresp[4] = mcp->mb[19];
3702 qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq, uint16_t *mresp)
3706 mbx_cmd_t *mcp = &mc;
3707 struct qla_hw_data *ha = vha->hw;
3709 DEBUG11(printk("scsi(%ld): entered.\n", vha->host_no));
3711 memset(mcp->mb, 0 , sizeof(mcp->mb));
3712 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
3713 mcp->mb[1] = mreq->options | BIT_6; /* BIT_6 specifies 64bit address */
3715 mcp->mb[1] |= BIT_15;
3716 mcp->mb[2] = IS_QLA81XX(ha) ? vha->fcoe_fcf_idx : 0;
3717 mcp->mb[16] = LSW(mreq->rcv_dma);
3718 mcp->mb[17] = MSW(mreq->rcv_dma);
3719 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
3720 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
3722 mcp->mb[10] = LSW(mreq->transfer_size);
3724 mcp->mb[14] = LSW(mreq->send_dma);
3725 mcp->mb[15] = MSW(mreq->send_dma);
3726 mcp->mb[20] = LSW(MSD(mreq->send_dma));
3727 mcp->mb[21] = MSW(MSD(mreq->send_dma));
3729 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
3730 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
3732 mcp->out_mb |= MBX_2;
3735 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha))
3736 mcp->in_mb |= MBX_1;
3738 mcp->in_mb |= MBX_3;
3740 mcp->tov = MBX_TOV_SECONDS;
3741 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3742 mcp->buf_size = mreq->transfer_size;
3744 rval = qla2x00_mailbox_command(vha, mcp);
3746 if (rval != QLA_SUCCESS) {
3747 DEBUG2(printk(KERN_WARNING
3748 "(%ld): failed=%x mb[0]=0x%x mb[1]=0x%x.\n",
3749 vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3751 DEBUG2(printk(KERN_WARNING
3752 "scsi(%ld): done.\n", vha->host_no));
3755 /* Copy mailbox information */
3756 memcpy( mresp, mcp->mb, 32);
3760 qla84xx_reset_chip(scsi_qla_host_t *ha, uint16_t enable_diagnostic,
3761 uint16_t *cmd_status)
3765 mbx_cmd_t *mcp = &mc;
3767 DEBUG16(printk("%s(%ld): enable_diag=%d entered.\n", __func__,
3768 ha->host_no, enable_diagnostic));
3770 mcp->mb[0] = MBC_ISP84XX_RESET;
3771 mcp->mb[1] = enable_diagnostic;
3772 mcp->out_mb = MBX_1|MBX_0;
3773 mcp->in_mb = MBX_1|MBX_0;
3774 mcp->tov = MBX_TOV_SECONDS;
3775 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3776 rval = qla2x00_mailbox_command(ha, mcp);
3778 /* Return mailbox statuses. */
3779 *cmd_status = mcp->mb[0];
3780 if (rval != QLA_SUCCESS)
3781 DEBUG16(printk("%s(%ld): failed=%x.\n", __func__, ha->host_no,
3784 DEBUG16(printk("%s(%ld): done.\n", __func__, ha->host_no));
3790 qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
3794 mbx_cmd_t *mcp = &mc;
3796 if (!IS_FWI2_CAPABLE(vha->hw))
3797 return QLA_FUNCTION_FAILED;
3799 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3801 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
3802 mcp->mb[1] = LSW(risc_addr);
3803 mcp->mb[2] = LSW(data);
3804 mcp->mb[3] = MSW(data);
3805 mcp->mb[8] = MSW(risc_addr);
3806 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
3810 rval = qla2x00_mailbox_command(vha, mcp);
3811 if (rval != QLA_SUCCESS) {
3812 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3813 vha->host_no, rval, mcp->mb[0]));
3815 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3822 qla2x00_get_data_rate(scsi_qla_host_t *vha)
3826 mbx_cmd_t *mcp = &mc;
3827 struct qla_hw_data *ha = vha->hw;
3829 if (!IS_FWI2_CAPABLE(ha))
3830 return QLA_FUNCTION_FAILED;
3832 DEBUG11(printk(KERN_INFO "%s(%ld): entered.\n", __func__, vha->host_no));
3834 mcp->mb[0] = MBC_DATA_RATE;
3836 mcp->out_mb = MBX_1|MBX_0;
3837 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3838 mcp->tov = MBX_TOV_SECONDS;
3840 rval = qla2x00_mailbox_command(vha, mcp);
3841 if (rval != QLA_SUCCESS) {
3842 DEBUG2_3_11(printk(KERN_INFO "%s(%ld): failed=%x mb[0]=%x.\n",
3843 __func__, vha->host_no, rval, mcp->mb[0]));
3845 DEBUG11(printk(KERN_INFO
3846 "%s(%ld): done.\n", __func__, vha->host_no));
3847 if (mcp->mb[1] != 0x7)
3848 ha->link_data_rate = mcp->mb[1];