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>
10 #include <linux/gfp.h>
14 * qla2x00_mailbox_command
15 * Issue mailbox command and waits for completion.
18 * ha = adapter block pointer.
19 * mcp = driver internal mbx struct pointer.
22 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
25 * 0 : QLA_SUCCESS = cmd performed success
26 * 1 : QLA_FUNCTION_FAILED (error encountered)
27 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
33 qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
36 unsigned long flags = 0;
37 device_reg_t __iomem *reg;
42 uint16_t __iomem *optr;
45 unsigned long wait_time;
46 struct qla_hw_data *ha = vha->hw;
47 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
49 if (ha->pdev->error_state > pci_channel_io_frozen)
50 return QLA_FUNCTION_TIMEOUT;
53 io_lock_on = base_vha->flags.init_done;
56 abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
58 DEBUG11(printk("%s(%ld): entered.\n", __func__, base_vha->host_no));
60 if (ha->flags.pci_channel_io_perm_failure) {
61 DEBUG(printk("%s(%ld): Perm failure on EEH, timeout MBX "
62 "Exiting.\n", __func__, vha->host_no));
63 return QLA_FUNCTION_TIMEOUT;
67 * Wait for active mailbox commands to finish by waiting at most tov
68 * seconds. This is to serialize actual issuing of mailbox cmds during
71 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp, mcp->tov * HZ)) {
72 /* Timeout occurred. Return error. */
73 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
74 "Exiting.\n", __func__, base_vha->host_no));
75 return QLA_FUNCTION_TIMEOUT;
78 ha->flags.mbox_busy = 1;
79 /* Save mailbox command for debug */
82 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
83 base_vha->host_no, mcp->mb[0]));
85 spin_lock_irqsave(&ha->hardware_lock, flags);
87 /* Load mailbox registers. */
88 if (IS_FWI2_CAPABLE(ha))
89 optr = (uint16_t __iomem *)®->isp24.mailbox0;
91 optr = (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 0);
97 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
98 if (IS_QLA2200(ha) && cnt == 8)
100 (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 8);
102 WRT_REG_WORD(optr, *iptr);
109 #if defined(QL_DEBUG_LEVEL_1)
110 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
111 __func__, base_vha->host_no);
112 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
114 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
116 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
118 printk("%s(%ld): I/O address = %p.\n", __func__, base_vha->host_no,
120 qla2x00_dump_regs(base_vha);
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__, base_vha->host_no, jiffies));
131 /* Wait for mbx cmd completion until timeout */
133 if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
134 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
136 if (IS_FWI2_CAPABLE(ha))
137 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
139 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
140 spin_unlock_irqrestore(&ha->hardware_lock, flags);
142 wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ);
144 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
147 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
148 base_vha->host_no, command));
150 if (IS_FWI2_CAPABLE(ha))
151 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
153 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
154 spin_unlock_irqrestore(&ha->hardware_lock, flags);
156 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
157 while (!ha->flags.mbox_int) {
158 if (time_after(jiffies, wait_time))
161 /* Check for pending interrupts. */
162 qla2x00_poll(ha->rsp_q_map[0]);
164 if (!ha->flags.mbox_int &&
166 command == MBC_LOAD_RISC_RAM_EXTENDED))
169 DEBUG17(qla_printk(KERN_WARNING, ha,
171 (uint)((jiffies - (wait_time - (mcp->tov * HZ)))/HZ)));
174 /* Check whether we timed out */
175 if (ha->flags.mbox_int) {
178 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
179 base_vha->host_no, command));
181 /* Got interrupt. Clear the flag. */
182 ha->flags.mbox_int = 0;
183 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
185 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
186 rval = QLA_FUNCTION_FAILED;
188 /* Load return mailbox registers. */
190 iptr = (uint16_t *)&ha->mailbox_out[0];
192 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
202 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
203 defined(QL_DEBUG_LEVEL_11)
207 if (IS_FWI2_CAPABLE(ha)) {
208 mb0 = RD_REG_WORD(®->isp24.mailbox0);
209 ictrl = RD_REG_DWORD(®->isp24.ictrl);
211 mb0 = RD_MAILBOX_REG(ha, ®->isp, 0);
212 ictrl = RD_REG_WORD(®->isp.ictrl);
214 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
215 __func__, base_vha->host_no, command);
216 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
217 base_vha->host_no, ictrl, jiffies);
218 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
219 base_vha->host_no, mb0);
220 qla2x00_dump_regs(base_vha);
223 rval = QLA_FUNCTION_TIMEOUT;
226 ha->flags.mbox_busy = 0;
231 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
232 DEBUG11(printk("%s(%ld): checking for additional resp "
233 "interrupt.\n", __func__, base_vha->host_no));
235 /* polling mode for non isp_abort commands. */
236 qla2x00_poll(ha->rsp_q_map[0]);
239 if (rval == QLA_FUNCTION_TIMEOUT &&
240 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
241 if (!io_lock_on || (mcp->flags & IOCTL_CMD) ||
242 ha->flags.eeh_busy) {
243 /* not in dpc. schedule it for dpc to take over. */
244 DEBUG(printk("%s(%ld): timeout schedule "
245 "isp_abort_needed.\n", __func__,
247 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
248 "isp_abort_needed.\n", __func__,
250 qla_printk(KERN_WARNING, ha,
251 "Mailbox command timeout occurred. Scheduling ISP "
252 "abort. eeh_busy: 0x%x\n", ha->flags.eeh_busy);
253 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
254 qla2xxx_wake_dpc(vha);
255 } else if (!abort_active) {
256 /* call abort directly since we are in the DPC thread */
257 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
258 __func__, base_vha->host_no));
259 DEBUG2_3_11(printk("%s(%ld): timeout calling "
260 "abort_isp\n", __func__, base_vha->host_no));
261 qla_printk(KERN_WARNING, ha,
262 "Mailbox command timeout occurred. Issuing ISP "
265 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
266 clear_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
267 if (qla2x00_abort_isp(base_vha)) {
268 /* Failed. retry later. */
269 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
271 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
272 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
274 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
275 __func__, base_vha->host_no));
279 /* Allow next mbx cmd to come in. */
280 complete(&ha->mbx_cmd_comp);
283 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
284 "mbx2=%x, cmd=%x ****\n", __func__, base_vha->host_no,
285 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
287 DEBUG11(printk("%s(%ld): done.\n", __func__,
295 qla2x00_load_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t risc_addr,
296 uint32_t risc_code_size)
299 struct qla_hw_data *ha = vha->hw;
301 mbx_cmd_t *mcp = &mc;
303 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
305 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
306 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
307 mcp->mb[8] = MSW(risc_addr);
308 mcp->out_mb = MBX_8|MBX_0;
310 mcp->mb[0] = MBC_LOAD_RISC_RAM;
313 mcp->mb[1] = LSW(risc_addr);
314 mcp->mb[2] = MSW(req_dma);
315 mcp->mb[3] = LSW(req_dma);
316 mcp->mb[6] = MSW(MSD(req_dma));
317 mcp->mb[7] = LSW(MSD(req_dma));
318 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
319 if (IS_FWI2_CAPABLE(ha)) {
320 mcp->mb[4] = MSW(risc_code_size);
321 mcp->mb[5] = LSW(risc_code_size);
322 mcp->out_mb |= MBX_5|MBX_4;
324 mcp->mb[4] = LSW(risc_code_size);
325 mcp->out_mb |= MBX_4;
329 mcp->tov = MBX_TOV_SECONDS;
331 rval = qla2x00_mailbox_command(vha, mcp);
333 if (rval != QLA_SUCCESS) {
334 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
335 vha->host_no, rval, mcp->mb[0]));
337 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
343 #define EXTENDED_BB_CREDITS BIT_0
346 * Start adapter firmware.
349 * ha = adapter block pointer.
350 * TARGET_QUEUE_LOCK must be released.
351 * ADAPTER_STATE_LOCK must be released.
354 * qla2x00 local function return status code.
360 qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
363 struct qla_hw_data *ha = vha->hw;
365 mbx_cmd_t *mcp = &mc;
367 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
369 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
372 if (IS_FWI2_CAPABLE(ha)) {
373 mcp->mb[1] = MSW(risc_addr);
374 mcp->mb[2] = LSW(risc_addr);
376 if (IS_QLA81XX(ha)) {
377 struct nvram_81xx *nv = ha->nvram;
378 mcp->mb[4] = (nv->enhanced_features &
379 EXTENDED_BB_CREDITS);
382 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
385 mcp->mb[1] = LSW(risc_addr);
386 mcp->out_mb |= MBX_1;
387 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
389 mcp->out_mb |= MBX_2;
393 mcp->tov = MBX_TOV_SECONDS;
395 rval = qla2x00_mailbox_command(vha, mcp);
397 if (rval != QLA_SUCCESS) {
398 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
399 vha->host_no, rval, mcp->mb[0]));
401 if (IS_FWI2_CAPABLE(ha)) {
402 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
403 __func__, vha->host_no, mcp->mb[1]));
405 DEBUG11(printk("%s(%ld): done.\n", __func__,
414 * qla2x00_get_fw_version
415 * Get firmware version.
418 * ha: adapter state pointer.
419 * major: pointer for major number.
420 * minor: pointer for minor number.
421 * subminor: pointer for subminor number.
424 * qla2x00 local function return status code.
430 qla2x00_get_fw_version(scsi_qla_host_t *vha, uint16_t *major, uint16_t *minor,
431 uint16_t *subminor, uint16_t *attributes, uint32_t *memory, uint8_t *mpi,
432 uint32_t *mpi_caps, uint8_t *phy)
436 mbx_cmd_t *mcp = &mc;
438 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
440 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
442 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
443 if (IS_QLA81XX(vha->hw))
444 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
446 mcp->tov = MBX_TOV_SECONDS;
447 rval = qla2x00_mailbox_command(vha, mcp);
448 if (rval != QLA_SUCCESS)
451 /* Return mailbox data. */
454 *subminor = mcp->mb[3];
455 *attributes = mcp->mb[6];
456 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
457 *memory = 0x1FFFF; /* Defaults to 128KB. */
459 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
460 if (IS_QLA81XX(vha->hw)) {
461 mpi[0] = mcp->mb[10] & 0xff;
462 mpi[1] = mcp->mb[11] >> 8;
463 mpi[2] = mcp->mb[11] & 0xff;
464 *mpi_caps = (mcp->mb[12] << 16) | mcp->mb[13];
465 phy[0] = mcp->mb[8] & 0xff;
466 phy[1] = mcp->mb[9] >> 8;
467 phy[2] = mcp->mb[9] & 0xff;
470 if (rval != QLA_SUCCESS) {
472 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
473 vha->host_no, rval));
476 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
482 * qla2x00_get_fw_options
483 * Set firmware options.
486 * ha = adapter block pointer.
487 * fwopt = pointer for firmware options.
490 * qla2x00 local function return status code.
496 qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
500 mbx_cmd_t *mcp = &mc;
502 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
504 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
506 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
507 mcp->tov = MBX_TOV_SECONDS;
509 rval = qla2x00_mailbox_command(vha, mcp);
511 if (rval != QLA_SUCCESS) {
513 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
514 vha->host_no, rval));
516 fwopts[0] = mcp->mb[0];
517 fwopts[1] = mcp->mb[1];
518 fwopts[2] = mcp->mb[2];
519 fwopts[3] = mcp->mb[3];
521 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
529 * qla2x00_set_fw_options
530 * Set firmware options.
533 * ha = adapter block pointer.
534 * fwopt = pointer for firmware options.
537 * qla2x00 local function return status code.
543 qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
547 mbx_cmd_t *mcp = &mc;
549 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
551 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
552 mcp->mb[1] = fwopts[1];
553 mcp->mb[2] = fwopts[2];
554 mcp->mb[3] = fwopts[3];
555 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
557 if (IS_FWI2_CAPABLE(vha->hw)) {
560 mcp->mb[10] = fwopts[10];
561 mcp->mb[11] = fwopts[11];
562 mcp->mb[12] = 0; /* Undocumented, but used */
563 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
565 mcp->tov = MBX_TOV_SECONDS;
567 rval = qla2x00_mailbox_command(vha, mcp);
569 fwopts[0] = mcp->mb[0];
571 if (rval != QLA_SUCCESS) {
573 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
574 vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
577 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
584 * qla2x00_mbx_reg_test
585 * Mailbox register wrap test.
588 * ha = adapter block pointer.
589 * TARGET_QUEUE_LOCK must be released.
590 * ADAPTER_STATE_LOCK must be released.
593 * qla2x00 local function return status code.
599 qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
603 mbx_cmd_t *mcp = &mc;
605 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", vha->host_no));
607 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
615 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
616 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
617 mcp->tov = MBX_TOV_SECONDS;
619 rval = qla2x00_mailbox_command(vha, mcp);
621 if (rval == QLA_SUCCESS) {
622 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
623 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
624 rval = QLA_FUNCTION_FAILED;
625 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
626 mcp->mb[7] != 0x2525)
627 rval = QLA_FUNCTION_FAILED;
630 if (rval != QLA_SUCCESS) {
632 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
633 vha->host_no, rval));
636 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
644 * qla2x00_verify_checksum
645 * Verify firmware checksum.
648 * ha = adapter block pointer.
649 * TARGET_QUEUE_LOCK must be released.
650 * ADAPTER_STATE_LOCK must be released.
653 * qla2x00 local function return status code.
659 qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
663 mbx_cmd_t *mcp = &mc;
665 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
667 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
670 if (IS_FWI2_CAPABLE(vha->hw)) {
671 mcp->mb[1] = MSW(risc_addr);
672 mcp->mb[2] = LSW(risc_addr);
673 mcp->out_mb |= MBX_2|MBX_1;
674 mcp->in_mb |= MBX_2|MBX_1;
676 mcp->mb[1] = LSW(risc_addr);
677 mcp->out_mb |= MBX_1;
681 mcp->tov = MBX_TOV_SECONDS;
683 rval = qla2x00_mailbox_command(vha, mcp);
685 if (rval != QLA_SUCCESS) {
686 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
687 vha->host_no, rval, IS_FWI2_CAPABLE(vha->hw) ?
688 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
690 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
698 * Issue IOCB using mailbox command
701 * ha = adapter state pointer.
702 * buffer = buffer pointer.
703 * phys_addr = physical address of buffer.
704 * size = size of buffer.
705 * TARGET_QUEUE_LOCK must be released.
706 * ADAPTER_STATE_LOCK must be released.
709 * qla2x00 local function return status code.
715 qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
716 dma_addr_t phys_addr, size_t size, uint32_t tov)
720 mbx_cmd_t *mcp = &mc;
722 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
724 mcp->mb[2] = MSW(phys_addr);
725 mcp->mb[3] = LSW(phys_addr);
726 mcp->mb[6] = MSW(MSD(phys_addr));
727 mcp->mb[7] = LSW(MSD(phys_addr));
728 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
729 mcp->in_mb = MBX_2|MBX_0;
732 rval = qla2x00_mailbox_command(vha, mcp);
734 if (rval != QLA_SUCCESS) {
736 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
737 vha->host_no, rval));
739 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
741 /* Mask reserved bits. */
742 sts_entry->entry_status &=
743 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
750 qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
753 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
758 * qla2x00_abort_command
759 * Abort command aborts a specified IOCB.
762 * ha = adapter block pointer.
763 * sp = SB structure pointer.
766 * qla2x00 local function return status code.
772 qla2x00_abort_command(srb_t *sp)
774 unsigned long flags = 0;
778 mbx_cmd_t *mcp = &mc;
779 fc_port_t *fcport = sp->fcport;
780 scsi_qla_host_t *vha = fcport->vha;
781 struct qla_hw_data *ha = vha->hw;
782 struct req_que *req = vha->req;
784 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", vha->host_no));
786 spin_lock_irqsave(&ha->hardware_lock, flags);
787 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
788 if (req->outstanding_cmds[handle] == sp)
791 spin_unlock_irqrestore(&ha->hardware_lock, flags);
793 if (handle == MAX_OUTSTANDING_COMMANDS) {
794 /* command not found */
795 return QLA_FUNCTION_FAILED;
798 mcp->mb[0] = MBC_ABORT_COMMAND;
799 if (HAS_EXTENDED_IDS(ha))
800 mcp->mb[1] = fcport->loop_id;
802 mcp->mb[1] = fcport->loop_id << 8;
803 mcp->mb[2] = (uint16_t)handle;
804 mcp->mb[3] = (uint16_t)(handle >> 16);
805 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
806 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
808 mcp->tov = MBX_TOV_SECONDS;
810 rval = qla2x00_mailbox_command(vha, mcp);
812 if (rval != QLA_SUCCESS) {
813 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
814 vha->host_no, rval));
816 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
824 qla2x00_abort_target(struct fc_port *fcport, unsigned int l, int tag)
828 mbx_cmd_t *mcp = &mc;
829 scsi_qla_host_t *vha;
833 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
837 req = vha->hw->req_q_map[tag];
838 rsp = vha->hw->rsp_q_map[tag];
839 mcp->mb[0] = MBC_ABORT_TARGET;
840 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
841 if (HAS_EXTENDED_IDS(vha->hw)) {
842 mcp->mb[1] = fcport->loop_id;
844 mcp->out_mb |= MBX_10;
846 mcp->mb[1] = fcport->loop_id << 8;
848 mcp->mb[2] = vha->hw->loop_reset_delay;
849 mcp->mb[9] = vha->vp_idx;
852 mcp->tov = MBX_TOV_SECONDS;
854 rval = qla2x00_mailbox_command(vha, mcp);
855 if (rval != QLA_SUCCESS) {
856 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
857 vha->host_no, rval));
860 /* Issue marker IOCB. */
861 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
863 if (rval2 != QLA_SUCCESS) {
864 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
865 "(%x).\n", __func__, vha->host_no, rval2));
867 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
874 qla2x00_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
878 mbx_cmd_t *mcp = &mc;
879 scsi_qla_host_t *vha;
883 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
886 req = vha->hw->req_q_map[tag];
887 rsp = vha->hw->rsp_q_map[tag];
888 mcp->mb[0] = MBC_LUN_RESET;
889 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
890 if (HAS_EXTENDED_IDS(vha->hw))
891 mcp->mb[1] = fcport->loop_id;
893 mcp->mb[1] = fcport->loop_id << 8;
896 mcp->mb[9] = vha->vp_idx;
899 mcp->tov = MBX_TOV_SECONDS;
901 rval = qla2x00_mailbox_command(vha, mcp);
902 if (rval != QLA_SUCCESS) {
903 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
904 vha->host_no, rval));
907 /* Issue marker IOCB. */
908 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
910 if (rval2 != QLA_SUCCESS) {
911 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
912 "(%x).\n", __func__, vha->host_no, rval2));
914 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
921 * qla2x00_get_adapter_id
922 * Get adapter ID and topology.
925 * ha = adapter block pointer.
926 * id = pointer for loop ID.
927 * al_pa = pointer for AL_PA.
928 * area = pointer for area.
929 * domain = pointer for domain.
930 * top = pointer for topology.
931 * TARGET_QUEUE_LOCK must be released.
932 * ADAPTER_STATE_LOCK must be released.
935 * qla2x00 local function return status code.
941 qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
942 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
946 mbx_cmd_t *mcp = &mc;
948 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
951 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
952 mcp->mb[9] = vha->vp_idx;
953 mcp->out_mb = MBX_9|MBX_0;
954 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
955 if (IS_QLA81XX(vha->hw))
956 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
957 mcp->tov = MBX_TOV_SECONDS;
959 rval = qla2x00_mailbox_command(vha, mcp);
960 if (mcp->mb[0] == MBS_COMMAND_ERROR)
961 rval = QLA_COMMAND_ERROR;
962 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
963 rval = QLA_INVALID_COMMAND;
967 *al_pa = LSB(mcp->mb[2]);
968 *area = MSB(mcp->mb[2]);
969 *domain = LSB(mcp->mb[3]);
971 *sw_cap = mcp->mb[7];
973 if (rval != QLA_SUCCESS) {
975 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
976 vha->host_no, rval));
978 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
981 if (IS_QLA81XX(vha->hw)) {
982 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
983 vha->fcoe_fcf_idx = mcp->mb[10];
984 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
985 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
986 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
987 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
988 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
989 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
997 * qla2x00_get_retry_cnt
998 * Get current firmware login retry count and delay.
1001 * ha = adapter block pointer.
1002 * retry_cnt = pointer to login retry count.
1003 * tov = pointer to login timeout value.
1006 * qla2x00 local function return status code.
1012 qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
1018 mbx_cmd_t *mcp = &mc;
1020 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
1023 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1024 mcp->out_mb = MBX_0;
1025 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1026 mcp->tov = MBX_TOV_SECONDS;
1028 rval = qla2x00_mailbox_command(vha, mcp);
1030 if (rval != QLA_SUCCESS) {
1032 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
1033 vha->host_no, mcp->mb[0]));
1035 /* Convert returned data and check our values. */
1036 *r_a_tov = mcp->mb[3] / 2;
1037 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1038 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1039 /* Update to the larger values */
1040 *retry_cnt = (uint8_t)mcp->mb[1];
1044 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
1045 "ratov=%d.\n", vha->host_no, mcp->mb[3], ratov));
1052 * qla2x00_init_firmware
1053 * Initialize adapter firmware.
1056 * ha = adapter block pointer.
1057 * dptr = Initialization control block pointer.
1058 * size = size of initialization control block.
1059 * TARGET_QUEUE_LOCK must be released.
1060 * ADAPTER_STATE_LOCK must be released.
1063 * qla2x00 local function return status code.
1069 qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
1073 mbx_cmd_t *mcp = &mc;
1074 struct qla_hw_data *ha = vha->hw;
1076 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1079 if (ha->flags.npiv_supported)
1080 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1082 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1085 mcp->mb[2] = MSW(ha->init_cb_dma);
1086 mcp->mb[3] = LSW(ha->init_cb_dma);
1087 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1088 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1089 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1090 if (IS_QLA81XX(ha) && ha->ex_init_cb->ex_version) {
1092 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1093 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1094 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1095 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1096 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1097 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1100 mcp->buf_size = size;
1101 mcp->flags = MBX_DMA_OUT;
1102 mcp->tov = MBX_TOV_SECONDS;
1103 rval = qla2x00_mailbox_command(vha, mcp);
1105 if (rval != QLA_SUCCESS) {
1107 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1109 vha->host_no, rval, mcp->mb[0]));
1112 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1120 * qla2x00_get_port_database
1121 * Issue normal/enhanced get port database mailbox command
1122 * and copy device name as necessary.
1125 * ha = adapter state pointer.
1126 * dev = structure pointer.
1127 * opt = enhanced cmd option byte.
1130 * qla2x00 local function return status code.
1136 qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
1140 mbx_cmd_t *mcp = &mc;
1141 port_database_t *pd;
1142 struct port_database_24xx *pd24;
1144 struct qla_hw_data *ha = vha->hw;
1146 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1149 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1151 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1152 "structure.\n", __func__, vha->host_no));
1153 return QLA_MEMORY_ALLOC_FAILED;
1155 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
1157 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1158 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
1159 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1160 mcp->mb[2] = MSW(pd_dma);
1161 mcp->mb[3] = LSW(pd_dma);
1162 mcp->mb[6] = MSW(MSD(pd_dma));
1163 mcp->mb[7] = LSW(MSD(pd_dma));
1164 mcp->mb[9] = vha->vp_idx;
1165 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1167 if (IS_FWI2_CAPABLE(ha)) {
1168 mcp->mb[1] = fcport->loop_id;
1170 mcp->out_mb |= MBX_10|MBX_1;
1171 mcp->in_mb |= MBX_1;
1172 } else if (HAS_EXTENDED_IDS(ha)) {
1173 mcp->mb[1] = fcport->loop_id;
1175 mcp->out_mb |= MBX_10|MBX_1;
1177 mcp->mb[1] = fcport->loop_id << 8 | opt;
1178 mcp->out_mb |= MBX_1;
1180 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1181 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
1182 mcp->flags = MBX_DMA_IN;
1183 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1184 rval = qla2x00_mailbox_command(vha, mcp);
1185 if (rval != QLA_SUCCESS)
1188 if (IS_FWI2_CAPABLE(ha)) {
1189 pd24 = (struct port_database_24xx *) pd;
1191 /* Check for logged in state. */
1192 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1193 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1194 DEBUG2(printk("%s(%ld): Unable to verify "
1195 "login-state (%x/%x) for loop_id %x\n",
1196 __func__, vha->host_no,
1197 pd24->current_login_state,
1198 pd24->last_login_state, fcport->loop_id));
1199 rval = QLA_FUNCTION_FAILED;
1203 /* Names are little-endian. */
1204 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1205 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1207 /* Get port_id of device. */
1208 fcport->d_id.b.domain = pd24->port_id[0];
1209 fcport->d_id.b.area = pd24->port_id[1];
1210 fcport->d_id.b.al_pa = pd24->port_id[2];
1211 fcport->d_id.b.rsvd_1 = 0;
1213 /* If not target must be initiator or unknown type. */
1214 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1215 fcport->port_type = FCT_INITIATOR;
1217 fcport->port_type = FCT_TARGET;
1219 /* Check for logged in state. */
1220 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1221 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1222 rval = QLA_FUNCTION_FAILED;
1226 /* Names are little-endian. */
1227 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1228 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1230 /* Get port_id of device. */
1231 fcport->d_id.b.domain = pd->port_id[0];
1232 fcport->d_id.b.area = pd->port_id[3];
1233 fcport->d_id.b.al_pa = pd->port_id[2];
1234 fcport->d_id.b.rsvd_1 = 0;
1236 /* If not target must be initiator or unknown type. */
1237 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1238 fcport->port_type = FCT_INITIATOR;
1240 fcport->port_type = FCT_TARGET;
1242 /* Passback COS information. */
1243 fcport->supported_classes = (pd->options & BIT_4) ?
1244 FC_COS_CLASS2: FC_COS_CLASS3;
1248 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1250 if (rval != QLA_SUCCESS) {
1251 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1252 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1254 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1261 * qla2x00_get_firmware_state
1262 * Get adapter firmware state.
1265 * ha = adapter block pointer.
1266 * dptr = pointer for firmware state.
1267 * TARGET_QUEUE_LOCK must be released.
1268 * ADAPTER_STATE_LOCK must be released.
1271 * qla2x00 local function return status code.
1277 qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
1281 mbx_cmd_t *mcp = &mc;
1283 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1286 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1287 mcp->out_mb = MBX_0;
1288 if (IS_FWI2_CAPABLE(vha->hw))
1289 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1291 mcp->in_mb = MBX_1|MBX_0;
1292 mcp->tov = MBX_TOV_SECONDS;
1294 rval = qla2x00_mailbox_command(vha, mcp);
1296 /* Return firmware states. */
1297 states[0] = mcp->mb[1];
1298 if (IS_FWI2_CAPABLE(vha->hw)) {
1299 states[1] = mcp->mb[2];
1300 states[2] = mcp->mb[3];
1301 states[3] = mcp->mb[4];
1302 states[4] = mcp->mb[5];
1305 if (rval != QLA_SUCCESS) {
1307 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1308 "failed=%x.\n", vha->host_no, rval));
1311 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1319 * qla2x00_get_port_name
1320 * Issue get port name mailbox command.
1321 * Returned name is in big endian format.
1324 * ha = adapter block pointer.
1325 * loop_id = loop ID of device.
1326 * name = pointer for name.
1327 * TARGET_QUEUE_LOCK must be released.
1328 * ADAPTER_STATE_LOCK must be released.
1331 * qla2x00 local function return status code.
1337 qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
1342 mbx_cmd_t *mcp = &mc;
1344 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1347 mcp->mb[0] = MBC_GET_PORT_NAME;
1348 mcp->mb[9] = vha->vp_idx;
1349 mcp->out_mb = MBX_9|MBX_1|MBX_0;
1350 if (HAS_EXTENDED_IDS(vha->hw)) {
1351 mcp->mb[1] = loop_id;
1353 mcp->out_mb |= MBX_10;
1355 mcp->mb[1] = loop_id << 8 | opt;
1358 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1359 mcp->tov = MBX_TOV_SECONDS;
1361 rval = qla2x00_mailbox_command(vha, mcp);
1363 if (rval != QLA_SUCCESS) {
1365 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1366 vha->host_no, rval));
1369 /* This function returns name in big endian. */
1370 name[0] = MSB(mcp->mb[2]);
1371 name[1] = LSB(mcp->mb[2]);
1372 name[2] = MSB(mcp->mb[3]);
1373 name[3] = LSB(mcp->mb[3]);
1374 name[4] = MSB(mcp->mb[6]);
1375 name[5] = LSB(mcp->mb[6]);
1376 name[6] = MSB(mcp->mb[7]);
1377 name[7] = LSB(mcp->mb[7]);
1380 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1389 * Issue LIP reset mailbox command.
1392 * ha = adapter block pointer.
1393 * TARGET_QUEUE_LOCK must be released.
1394 * ADAPTER_STATE_LOCK must be released.
1397 * qla2x00 local function return status code.
1403 qla2x00_lip_reset(scsi_qla_host_t *vha)
1407 mbx_cmd_t *mcp = &mc;
1409 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1411 if (IS_QLA81XX(vha->hw)) {
1412 /* Logout across all FCFs. */
1413 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1416 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1417 } else if (IS_FWI2_CAPABLE(vha->hw)) {
1418 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1421 mcp->mb[3] = vha->hw->loop_reset_delay;
1422 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1424 mcp->mb[0] = MBC_LIP_RESET;
1425 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1426 if (HAS_EXTENDED_IDS(vha->hw)) {
1427 mcp->mb[1] = 0x00ff;
1429 mcp->out_mb |= MBX_10;
1431 mcp->mb[1] = 0xff00;
1433 mcp->mb[2] = vha->hw->loop_reset_delay;
1437 mcp->tov = MBX_TOV_SECONDS;
1439 rval = qla2x00_mailbox_command(vha, mcp);
1441 if (rval != QLA_SUCCESS) {
1443 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1444 __func__, vha->host_no, rval));
1447 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1458 * ha = adapter block pointer.
1459 * sns = pointer for command.
1460 * cmd_size = command size.
1461 * buf_size = response/command size.
1462 * TARGET_QUEUE_LOCK must be released.
1463 * ADAPTER_STATE_LOCK must be released.
1466 * qla2x00 local function return status code.
1472 qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
1473 uint16_t cmd_size, size_t buf_size)
1477 mbx_cmd_t *mcp = &mc;
1479 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1482 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1483 "tov=%d.\n", vha->hw->retry_count, vha->hw->login_timeout,
1486 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1487 mcp->mb[1] = cmd_size;
1488 mcp->mb[2] = MSW(sns_phys_address);
1489 mcp->mb[3] = LSW(sns_phys_address);
1490 mcp->mb[6] = MSW(MSD(sns_phys_address));
1491 mcp->mb[7] = LSW(MSD(sns_phys_address));
1492 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1493 mcp->in_mb = MBX_0|MBX_1;
1494 mcp->buf_size = buf_size;
1495 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1496 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
1497 rval = qla2x00_mailbox_command(vha, mcp);
1499 if (rval != QLA_SUCCESS) {
1501 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1502 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1503 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1504 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1507 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", vha->host_no));
1514 qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1515 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1519 struct logio_entry_24xx *lg;
1522 struct qla_hw_data *ha = vha->hw;
1523 struct req_que *req;
1524 struct rsp_que *rsp;
1526 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1528 if (ha->flags.cpu_affinity_enabled)
1529 req = ha->req_q_map[0];
1534 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1536 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1537 __func__, vha->host_no));
1538 return QLA_MEMORY_ALLOC_FAILED;
1540 memset(lg, 0, sizeof(struct logio_entry_24xx));
1542 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1543 lg->entry_count = 1;
1544 lg->handle = MAKE_HANDLE(req->id, lg->handle);
1545 lg->nport_handle = cpu_to_le16(loop_id);
1546 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1548 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1550 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
1551 lg->port_id[0] = al_pa;
1552 lg->port_id[1] = area;
1553 lg->port_id[2] = domain;
1554 lg->vp_index = vha->vp_idx;
1555 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
1556 if (rval != QLA_SUCCESS) {
1557 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
1558 "(%x).\n", __func__, vha->host_no, rval));
1559 } else if (lg->entry_status != 0) {
1560 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1561 "-- error status (%x).\n", __func__, vha->host_no,
1563 rval = QLA_FUNCTION_FAILED;
1564 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1565 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1566 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1568 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1569 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1570 vha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1574 case LSC_SCODE_PORTID_USED:
1575 mb[0] = MBS_PORT_ID_USED;
1576 mb[1] = LSW(iop[1]);
1578 case LSC_SCODE_NPORT_USED:
1579 mb[0] = MBS_LOOP_ID_USED;
1581 case LSC_SCODE_NOLINK:
1582 case LSC_SCODE_NOIOCB:
1583 case LSC_SCODE_NOXCB:
1584 case LSC_SCODE_CMD_FAILED:
1585 case LSC_SCODE_NOFABRIC:
1586 case LSC_SCODE_FW_NOT_READY:
1587 case LSC_SCODE_NOT_LOGGED_IN:
1588 case LSC_SCODE_NOPCB:
1589 case LSC_SCODE_ELS_REJECT:
1590 case LSC_SCODE_CMD_PARAM_ERR:
1591 case LSC_SCODE_NONPORT:
1592 case LSC_SCODE_LOGGED_IN:
1593 case LSC_SCODE_NOFLOGI_ACC:
1595 mb[0] = MBS_COMMAND_ERROR;
1599 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1601 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1603 mb[0] = MBS_COMMAND_COMPLETE;
1605 if (iop[0] & BIT_4) {
1611 /* Passback COS information. */
1613 if (lg->io_parameter[7] || lg->io_parameter[8])
1614 mb[10] |= BIT_0; /* Class 2. */
1615 if (lg->io_parameter[9] || lg->io_parameter[10])
1616 mb[10] |= BIT_1; /* Class 3. */
1619 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1625 * qla2x00_login_fabric
1626 * Issue login fabric port mailbox command.
1629 * ha = adapter block pointer.
1630 * loop_id = device loop ID.
1631 * domain = device domain.
1632 * area = device area.
1633 * al_pa = device AL_PA.
1634 * status = pointer for return status.
1635 * opt = command options.
1636 * TARGET_QUEUE_LOCK must be released.
1637 * ADAPTER_STATE_LOCK must be released.
1640 * qla2x00 local function return status code.
1646 qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1647 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1651 mbx_cmd_t *mcp = &mc;
1652 struct qla_hw_data *ha = vha->hw;
1654 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", vha->host_no));
1656 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1657 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1658 if (HAS_EXTENDED_IDS(ha)) {
1659 mcp->mb[1] = loop_id;
1661 mcp->out_mb |= MBX_10;
1663 mcp->mb[1] = (loop_id << 8) | opt;
1665 mcp->mb[2] = domain;
1666 mcp->mb[3] = area << 8 | al_pa;
1668 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1669 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1671 rval = qla2x00_mailbox_command(vha, mcp);
1673 /* Return mailbox statuses. */
1680 /* COS retrieved from Get-Port-Database mailbox command. */
1684 if (rval != QLA_SUCCESS) {
1685 /* RLU tmp code: need to change main mailbox_command function to
1686 * return ok even when the mailbox completion value is not
1687 * SUCCESS. The caller needs to be responsible to interpret
1688 * the return values of this mailbox command if we're not
1689 * to change too much of the existing code.
1691 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1692 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1693 mcp->mb[0] == 0x4006)
1697 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1698 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", vha->host_no, rval,
1699 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
1702 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1710 * qla2x00_login_local_device
1711 * Issue login loop port mailbox command.
1714 * ha = adapter block pointer.
1715 * loop_id = device loop ID.
1716 * opt = command options.
1719 * Return status code.
1726 qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
1727 uint16_t *mb_ret, uint8_t opt)
1731 mbx_cmd_t *mcp = &mc;
1732 struct qla_hw_data *ha = vha->hw;
1734 if (IS_FWI2_CAPABLE(ha))
1735 return qla24xx_login_fabric(vha, fcport->loop_id,
1736 fcport->d_id.b.domain, fcport->d_id.b.area,
1737 fcport->d_id.b.al_pa, mb_ret, opt);
1739 DEBUG3(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1741 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1742 if (HAS_EXTENDED_IDS(ha))
1743 mcp->mb[1] = fcport->loop_id;
1745 mcp->mb[1] = fcport->loop_id << 8;
1747 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1748 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1749 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1751 rval = qla2x00_mailbox_command(vha, mcp);
1753 /* Return mailbox statuses. */
1754 if (mb_ret != NULL) {
1755 mb_ret[0] = mcp->mb[0];
1756 mb_ret[1] = mcp->mb[1];
1757 mb_ret[6] = mcp->mb[6];
1758 mb_ret[7] = mcp->mb[7];
1761 if (rval != QLA_SUCCESS) {
1762 /* AV tmp code: need to change main mailbox_command function to
1763 * return ok even when the mailbox completion value is not
1764 * SUCCESS. The caller needs to be responsible to interpret
1765 * the return values of this mailbox command if we're not
1766 * to change too much of the existing code.
1768 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1771 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1772 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
1773 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1774 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1775 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
1776 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1779 DEBUG3(printk("%s(%ld): done.\n", __func__, vha->host_no));
1786 qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1787 uint8_t area, uint8_t al_pa)
1790 struct logio_entry_24xx *lg;
1792 struct qla_hw_data *ha = vha->hw;
1793 struct req_que *req;
1794 struct rsp_que *rsp;
1796 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1798 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1800 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1801 __func__, vha->host_no));
1802 return QLA_MEMORY_ALLOC_FAILED;
1804 memset(lg, 0, sizeof(struct logio_entry_24xx));
1806 if (ql2xmaxqueues > 1)
1807 req = ha->req_q_map[0];
1811 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1812 lg->entry_count = 1;
1813 lg->handle = MAKE_HANDLE(req->id, lg->handle);
1814 lg->nport_handle = cpu_to_le16(loop_id);
1816 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
1817 lg->port_id[0] = al_pa;
1818 lg->port_id[1] = area;
1819 lg->port_id[2] = domain;
1820 lg->vp_index = vha->vp_idx;
1822 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
1823 if (rval != QLA_SUCCESS) {
1824 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1825 "(%x).\n", __func__, vha->host_no, rval));
1826 } else if (lg->entry_status != 0) {
1827 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1828 "-- error status (%x).\n", __func__, vha->host_no,
1830 rval = QLA_FUNCTION_FAILED;
1831 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1832 DEBUG2_3_11(printk("%s(%ld %d): failed to complete IOCB "
1833 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1834 vha->host_no, vha->vp_idx, le16_to_cpu(lg->comp_status),
1835 le32_to_cpu(lg->io_parameter[0]),
1836 le32_to_cpu(lg->io_parameter[1])));
1839 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1842 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1848 * qla2x00_fabric_logout
1849 * Issue logout fabric port mailbox command.
1852 * ha = adapter block pointer.
1853 * loop_id = device loop ID.
1854 * TARGET_QUEUE_LOCK must be released.
1855 * ADAPTER_STATE_LOCK must be released.
1858 * qla2x00 local function return status code.
1864 qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1865 uint8_t area, uint8_t al_pa)
1869 mbx_cmd_t *mcp = &mc;
1871 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1874 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1875 mcp->out_mb = MBX_1|MBX_0;
1876 if (HAS_EXTENDED_IDS(vha->hw)) {
1877 mcp->mb[1] = loop_id;
1879 mcp->out_mb |= MBX_10;
1881 mcp->mb[1] = loop_id << 8;
1884 mcp->in_mb = MBX_1|MBX_0;
1885 mcp->tov = MBX_TOV_SECONDS;
1887 rval = qla2x00_mailbox_command(vha, mcp);
1889 if (rval != QLA_SUCCESS) {
1891 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1892 "mbx1=%x.\n", vha->host_no, rval, mcp->mb[1]));
1895 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1903 * qla2x00_full_login_lip
1904 * Issue full login LIP mailbox command.
1907 * ha = adapter block pointer.
1908 * TARGET_QUEUE_LOCK must be released.
1909 * ADAPTER_STATE_LOCK must be released.
1912 * qla2x00 local function return status code.
1918 qla2x00_full_login_lip(scsi_qla_host_t *vha)
1922 mbx_cmd_t *mcp = &mc;
1924 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1927 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1928 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
1931 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1933 mcp->tov = MBX_TOV_SECONDS;
1935 rval = qla2x00_mailbox_command(vha, mcp);
1937 if (rval != QLA_SUCCESS) {
1939 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1940 vha->host_no, rval));
1943 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1951 * qla2x00_get_id_list
1954 * ha = adapter block pointer.
1957 * qla2x00 local function return status code.
1963 qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
1968 mbx_cmd_t *mcp = &mc;
1970 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1973 if (id_list == NULL)
1974 return QLA_FUNCTION_FAILED;
1976 mcp->mb[0] = MBC_GET_ID_LIST;
1977 mcp->out_mb = MBX_0;
1978 if (IS_FWI2_CAPABLE(vha->hw)) {
1979 mcp->mb[2] = MSW(id_list_dma);
1980 mcp->mb[3] = LSW(id_list_dma);
1981 mcp->mb[6] = MSW(MSD(id_list_dma));
1982 mcp->mb[7] = LSW(MSD(id_list_dma));
1984 mcp->mb[9] = vha->vp_idx;
1985 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
1987 mcp->mb[1] = MSW(id_list_dma);
1988 mcp->mb[2] = LSW(id_list_dma);
1989 mcp->mb[3] = MSW(MSD(id_list_dma));
1990 mcp->mb[6] = LSW(MSD(id_list_dma));
1991 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1993 mcp->in_mb = MBX_1|MBX_0;
1994 mcp->tov = MBX_TOV_SECONDS;
1996 rval = qla2x00_mailbox_command(vha, mcp);
1998 if (rval != QLA_SUCCESS) {
2000 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
2001 vha->host_no, rval));
2003 *entries = mcp->mb[1];
2004 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
2012 * qla2x00_get_resource_cnts
2013 * Get current firmware resource counts.
2016 * ha = adapter block pointer.
2019 * qla2x00 local function return status code.
2025 qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
2026 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
2027 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports, uint16_t *max_fcfs)
2031 mbx_cmd_t *mcp = &mc;
2033 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2035 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2036 mcp->out_mb = MBX_0;
2037 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2038 if (IS_QLA81XX(vha->hw))
2039 mcp->in_mb |= MBX_12;
2040 mcp->tov = MBX_TOV_SECONDS;
2042 rval = qla2x00_mailbox_command(vha, mcp);
2044 if (rval != QLA_SUCCESS) {
2046 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
2047 vha->host_no, mcp->mb[0]));
2049 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
2050 "mb7=%x mb10=%x mb11=%x mb12=%x.\n", __func__,
2051 vha->host_no, mcp->mb[1], mcp->mb[2], mcp->mb[3],
2052 mcp->mb[6], mcp->mb[7], mcp->mb[10], mcp->mb[11],
2056 *cur_xchg_cnt = mcp->mb[3];
2058 *orig_xchg_cnt = mcp->mb[6];
2060 *cur_iocb_cnt = mcp->mb[7];
2062 *orig_iocb_cnt = mcp->mb[10];
2063 if (vha->hw->flags.npiv_supported && max_npiv_vports)
2064 *max_npiv_vports = mcp->mb[11];
2065 if (IS_QLA81XX(vha->hw) && max_fcfs)
2066 *max_fcfs = mcp->mb[12];
2072 #if defined(QL_DEBUG_LEVEL_3)
2074 * qla2x00_get_fcal_position_map
2075 * Get FCAL (LILP) position map using mailbox command
2078 * ha = adapter state pointer.
2079 * pos_map = buffer pointer (can be NULL).
2082 * qla2x00 local function return status code.
2088 qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
2092 mbx_cmd_t *mcp = &mc;
2094 dma_addr_t pmap_dma;
2095 struct qla_hw_data *ha = vha->hw;
2097 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
2099 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
2100 __func__, vha->host_no));
2101 return QLA_MEMORY_ALLOC_FAILED;
2103 memset(pmap, 0, FCAL_MAP_SIZE);
2105 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2106 mcp->mb[2] = MSW(pmap_dma);
2107 mcp->mb[3] = LSW(pmap_dma);
2108 mcp->mb[6] = MSW(MSD(pmap_dma));
2109 mcp->mb[7] = LSW(MSD(pmap_dma));
2110 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2111 mcp->in_mb = MBX_1|MBX_0;
2112 mcp->buf_size = FCAL_MAP_SIZE;
2113 mcp->flags = MBX_DMA_IN;
2114 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2115 rval = qla2x00_mailbox_command(vha, mcp);
2117 if (rval == QLA_SUCCESS) {
2118 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2119 "size (%x)\n", __func__, vha->host_no, mcp->mb[0],
2120 mcp->mb[1], (unsigned)pmap[0]));
2121 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2124 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2126 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2128 if (rval != QLA_SUCCESS) {
2129 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2130 vha->host_no, rval));
2132 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2140 * qla2x00_get_link_status
2143 * ha = adapter block pointer.
2144 * loop_id = device loop ID.
2145 * ret_buf = pointer to link status return buffer.
2149 * BIT_0 = mem alloc error.
2150 * BIT_1 = mailbox error.
2153 qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
2154 struct link_statistics *stats, dma_addr_t stats_dma)
2158 mbx_cmd_t *mcp = &mc;
2159 uint32_t *siter, *diter, dwords;
2160 struct qla_hw_data *ha = vha->hw;
2162 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2164 mcp->mb[0] = MBC_GET_LINK_STATUS;
2165 mcp->mb[2] = MSW(stats_dma);
2166 mcp->mb[3] = LSW(stats_dma);
2167 mcp->mb[6] = MSW(MSD(stats_dma));
2168 mcp->mb[7] = LSW(MSD(stats_dma));
2169 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2171 if (IS_FWI2_CAPABLE(ha)) {
2172 mcp->mb[1] = loop_id;
2175 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2176 mcp->in_mb |= MBX_1;
2177 } else if (HAS_EXTENDED_IDS(ha)) {
2178 mcp->mb[1] = loop_id;
2180 mcp->out_mb |= MBX_10|MBX_1;
2182 mcp->mb[1] = loop_id << 8;
2183 mcp->out_mb |= MBX_1;
2185 mcp->tov = MBX_TOV_SECONDS;
2186 mcp->flags = IOCTL_CMD;
2187 rval = qla2x00_mailbox_command(vha, mcp);
2189 if (rval == QLA_SUCCESS) {
2190 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2191 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2192 __func__, vha->host_no, mcp->mb[0]));
2193 rval = QLA_FUNCTION_FAILED;
2195 /* Copy over data -- firmware data is LE. */
2196 dwords = offsetof(struct link_statistics, unused1) / 4;
2197 siter = diter = &stats->link_fail_cnt;
2199 *diter++ = le32_to_cpu(*siter++);
2203 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2204 vha->host_no, rval));
2211 qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
2212 dma_addr_t stats_dma)
2216 mbx_cmd_t *mcp = &mc;
2217 uint32_t *siter, *diter, dwords;
2219 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2221 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2222 mcp->mb[2] = MSW(stats_dma);
2223 mcp->mb[3] = LSW(stats_dma);
2224 mcp->mb[6] = MSW(MSD(stats_dma));
2225 mcp->mb[7] = LSW(MSD(stats_dma));
2226 mcp->mb[8] = sizeof(struct link_statistics) / 4;
2227 mcp->mb[9] = vha->vp_idx;
2229 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2230 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2231 mcp->tov = MBX_TOV_SECONDS;
2232 mcp->flags = IOCTL_CMD;
2233 rval = qla2x00_mailbox_command(vha, mcp);
2235 if (rval == QLA_SUCCESS) {
2236 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2237 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2238 __func__, vha->host_no, mcp->mb[0]));
2239 rval = QLA_FUNCTION_FAILED;
2241 /* Copy over data -- firmware data is LE. */
2242 dwords = sizeof(struct link_statistics) / 4;
2243 siter = diter = &stats->link_fail_cnt;
2245 *diter++ = le32_to_cpu(*siter++);
2249 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2250 vha->host_no, rval));
2257 qla24xx_abort_command(srb_t *sp)
2260 unsigned long flags = 0;
2262 struct abort_entry_24xx *abt;
2265 fc_port_t *fcport = sp->fcport;
2266 struct scsi_qla_host *vha = fcport->vha;
2267 struct qla_hw_data *ha = vha->hw;
2268 struct req_que *req = vha->req;
2270 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2272 spin_lock_irqsave(&ha->hardware_lock, flags);
2273 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2274 if (req->outstanding_cmds[handle] == sp)
2277 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2278 if (handle == MAX_OUTSTANDING_COMMANDS) {
2279 /* Command not found. */
2280 return QLA_FUNCTION_FAILED;
2283 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2285 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2286 __func__, vha->host_no));
2287 return QLA_MEMORY_ALLOC_FAILED;
2289 memset(abt, 0, sizeof(struct abort_entry_24xx));
2291 abt->entry_type = ABORT_IOCB_TYPE;
2292 abt->entry_count = 1;
2293 abt->handle = MAKE_HANDLE(req->id, abt->handle);
2294 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2295 abt->handle_to_abort = handle;
2296 abt->port_id[0] = fcport->d_id.b.al_pa;
2297 abt->port_id[1] = fcport->d_id.b.area;
2298 abt->port_id[2] = fcport->d_id.b.domain;
2299 abt->vp_index = fcport->vp_idx;
2301 abt->req_que_no = cpu_to_le16(req->id);
2303 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
2304 if (rval != QLA_SUCCESS) {
2305 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2306 __func__, vha->host_no, rval));
2307 } else if (abt->entry_status != 0) {
2308 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2309 "-- error status (%x).\n", __func__, vha->host_no,
2310 abt->entry_status));
2311 rval = QLA_FUNCTION_FAILED;
2312 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2313 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2314 "-- completion status (%x).\n", __func__, vha->host_no,
2315 le16_to_cpu(abt->nport_handle)));
2316 rval = QLA_FUNCTION_FAILED;
2318 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2321 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2326 struct tsk_mgmt_cmd {
2328 struct tsk_mgmt_entry tsk;
2329 struct sts_entry_24xx sts;
2334 __qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
2335 unsigned int l, int tag)
2338 struct tsk_mgmt_cmd *tsk;
2339 struct sts_entry_24xx *sts;
2341 scsi_qla_host_t *vha;
2342 struct qla_hw_data *ha;
2343 struct req_que *req;
2344 struct rsp_que *rsp;
2346 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
2351 if (ha->flags.cpu_affinity_enabled)
2352 rsp = ha->rsp_q_map[tag + 1];
2355 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
2357 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2358 "IOCB.\n", __func__, vha->host_no));
2359 return QLA_MEMORY_ALLOC_FAILED;
2361 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2363 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2364 tsk->p.tsk.entry_count = 1;
2365 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
2366 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2367 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
2368 tsk->p.tsk.control_flags = cpu_to_le32(type);
2369 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2370 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2371 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2372 tsk->p.tsk.vp_index = fcport->vp_idx;
2373 if (type == TCF_LUN_RESET) {
2374 int_to_scsilun(l, &tsk->p.tsk.lun);
2375 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2376 sizeof(tsk->p.tsk.lun));
2380 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
2381 if (rval != QLA_SUCCESS) {
2382 DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
2383 "(%x).\n", __func__, vha->host_no, name, rval));
2384 } else if (sts->entry_status != 0) {
2385 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2386 "-- error status (%x).\n", __func__, vha->host_no,
2387 sts->entry_status));
2388 rval = QLA_FUNCTION_FAILED;
2389 } else if (sts->comp_status !=
2390 __constant_cpu_to_le16(CS_COMPLETE)) {
2391 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2392 "-- completion status (%x).\n", __func__,
2393 vha->host_no, le16_to_cpu(sts->comp_status)));
2394 rval = QLA_FUNCTION_FAILED;
2395 } else if (!(le16_to_cpu(sts->scsi_status) &
2396 SS_RESPONSE_INFO_LEN_VALID)) {
2397 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2398 "-- no response info (%x).\n", __func__, vha->host_no,
2399 le16_to_cpu(sts->scsi_status)));
2400 rval = QLA_FUNCTION_FAILED;
2401 } else if (le32_to_cpu(sts->rsp_data_len) < 4) {
2402 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2403 "-- not enough response info (%d).\n", __func__,
2404 vha->host_no, le32_to_cpu(sts->rsp_data_len)));
2405 rval = QLA_FUNCTION_FAILED;
2406 } else if (sts->data[3]) {
2407 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2408 "-- response (%x).\n", __func__,
2409 vha->host_no, sts->data[3]));
2410 rval = QLA_FUNCTION_FAILED;
2413 /* Issue marker IOCB. */
2414 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
2415 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2416 if (rval2 != QLA_SUCCESS) {
2417 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2418 "(%x).\n", __func__, vha->host_no, rval2));
2420 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2423 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
2429 qla24xx_abort_target(struct fc_port *fcport, unsigned int l, int tag)
2431 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
2435 qla24xx_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
2437 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
2441 qla2x00_system_error(scsi_qla_host_t *vha)
2445 mbx_cmd_t *mcp = &mc;
2446 struct qla_hw_data *ha = vha->hw;
2448 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
2449 return QLA_FUNCTION_FAILED;
2451 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2453 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2454 mcp->out_mb = MBX_0;
2458 rval = qla2x00_mailbox_command(vha, mcp);
2460 if (rval != QLA_SUCCESS) {
2461 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2462 vha->host_no, rval));
2464 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2471 * qla2x00_set_serdes_params() -
2477 qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
2478 uint16_t sw_em_2g, uint16_t sw_em_4g)
2482 mbx_cmd_t *mcp = &mc;
2484 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2486 mcp->mb[0] = MBC_SERDES_PARAMS;
2488 mcp->mb[2] = sw_em_1g | BIT_15;
2489 mcp->mb[3] = sw_em_2g | BIT_15;
2490 mcp->mb[4] = sw_em_4g | BIT_15;
2491 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2493 mcp->tov = MBX_TOV_SECONDS;
2495 rval = qla2x00_mailbox_command(vha, mcp);
2497 if (rval != QLA_SUCCESS) {
2499 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2500 vha->host_no, rval, mcp->mb[0]));
2503 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2510 qla2x00_stop_firmware(scsi_qla_host_t *vha)
2514 mbx_cmd_t *mcp = &mc;
2516 if (!IS_FWI2_CAPABLE(vha->hw))
2517 return QLA_FUNCTION_FAILED;
2519 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2521 mcp->mb[0] = MBC_STOP_FIRMWARE;
2522 mcp->out_mb = MBX_0;
2526 rval = qla2x00_mailbox_command(vha, mcp);
2528 if (rval != QLA_SUCCESS) {
2529 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2530 vha->host_no, rval));
2531 if (mcp->mb[0] == MBS_INVALID_COMMAND)
2532 rval = QLA_INVALID_COMMAND;
2534 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2541 qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
2546 mbx_cmd_t *mcp = &mc;
2548 if (!IS_FWI2_CAPABLE(vha->hw))
2549 return QLA_FUNCTION_FAILED;
2551 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2552 return QLA_FUNCTION_FAILED;
2554 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2556 mcp->mb[0] = MBC_TRACE_CONTROL;
2557 mcp->mb[1] = TC_EFT_ENABLE;
2558 mcp->mb[2] = LSW(eft_dma);
2559 mcp->mb[3] = MSW(eft_dma);
2560 mcp->mb[4] = LSW(MSD(eft_dma));
2561 mcp->mb[5] = MSW(MSD(eft_dma));
2562 mcp->mb[6] = buffers;
2563 mcp->mb[7] = TC_AEN_DISABLE;
2564 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2565 mcp->in_mb = MBX_1|MBX_0;
2566 mcp->tov = MBX_TOV_SECONDS;
2568 rval = qla2x00_mailbox_command(vha, mcp);
2569 if (rval != QLA_SUCCESS) {
2570 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2571 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2573 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2580 qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
2584 mbx_cmd_t *mcp = &mc;
2586 if (!IS_FWI2_CAPABLE(vha->hw))
2587 return QLA_FUNCTION_FAILED;
2589 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2590 return QLA_FUNCTION_FAILED;
2592 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2594 mcp->mb[0] = MBC_TRACE_CONTROL;
2595 mcp->mb[1] = TC_EFT_DISABLE;
2596 mcp->out_mb = MBX_1|MBX_0;
2597 mcp->in_mb = MBX_1|MBX_0;
2598 mcp->tov = MBX_TOV_SECONDS;
2600 rval = qla2x00_mailbox_command(vha, mcp);
2601 if (rval != QLA_SUCCESS) {
2602 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2603 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2605 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2612 qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
2613 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2617 mbx_cmd_t *mcp = &mc;
2619 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw))
2620 return QLA_FUNCTION_FAILED;
2622 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2623 return QLA_FUNCTION_FAILED;
2625 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2627 mcp->mb[0] = MBC_TRACE_CONTROL;
2628 mcp->mb[1] = TC_FCE_ENABLE;
2629 mcp->mb[2] = LSW(fce_dma);
2630 mcp->mb[3] = MSW(fce_dma);
2631 mcp->mb[4] = LSW(MSD(fce_dma));
2632 mcp->mb[5] = MSW(MSD(fce_dma));
2633 mcp->mb[6] = buffers;
2634 mcp->mb[7] = TC_AEN_DISABLE;
2636 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2637 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2638 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2640 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2641 mcp->tov = MBX_TOV_SECONDS;
2643 rval = qla2x00_mailbox_command(vha, mcp);
2644 if (rval != QLA_SUCCESS) {
2645 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2646 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2648 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2651 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2660 qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
2664 mbx_cmd_t *mcp = &mc;
2666 if (!IS_FWI2_CAPABLE(vha->hw))
2667 return QLA_FUNCTION_FAILED;
2669 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2670 return QLA_FUNCTION_FAILED;
2672 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2674 mcp->mb[0] = MBC_TRACE_CONTROL;
2675 mcp->mb[1] = TC_FCE_DISABLE;
2676 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
2677 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2678 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2680 mcp->tov = MBX_TOV_SECONDS;
2682 rval = qla2x00_mailbox_command(vha, mcp);
2683 if (rval != QLA_SUCCESS) {
2684 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2685 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2687 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2690 *wr = (uint64_t) mcp->mb[5] << 48 |
2691 (uint64_t) mcp->mb[4] << 32 |
2692 (uint64_t) mcp->mb[3] << 16 |
2693 (uint64_t) mcp->mb[2];
2695 *rd = (uint64_t) mcp->mb[9] << 48 |
2696 (uint64_t) mcp->mb[8] << 32 |
2697 (uint64_t) mcp->mb[7] << 16 |
2698 (uint64_t) mcp->mb[6];
2705 qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint16_t addr,
2706 uint16_t off, uint16_t count)
2710 mbx_cmd_t *mcp = &mc;
2712 if (!IS_FWI2_CAPABLE(vha->hw))
2713 return QLA_FUNCTION_FAILED;
2715 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2717 mcp->mb[0] = MBC_READ_SFP;
2719 mcp->mb[2] = MSW(sfp_dma);
2720 mcp->mb[3] = LSW(sfp_dma);
2721 mcp->mb[6] = MSW(MSD(sfp_dma));
2722 mcp->mb[7] = LSW(MSD(sfp_dma));
2726 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2728 mcp->tov = MBX_TOV_SECONDS;
2730 rval = qla2x00_mailbox_command(vha, mcp);
2732 if (rval != QLA_SUCCESS) {
2733 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2734 vha->host_no, rval, mcp->mb[0]));
2736 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2743 qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
2744 uint16_t port_speed, uint16_t *mb)
2748 mbx_cmd_t *mcp = &mc;
2750 if (!IS_IIDMA_CAPABLE(vha->hw))
2751 return QLA_FUNCTION_FAILED;
2753 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2755 mcp->mb[0] = MBC_PORT_PARAMS;
2756 mcp->mb[1] = loop_id;
2758 if (IS_QLA81XX(vha->hw))
2759 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
2761 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2762 mcp->mb[9] = vha->vp_idx;
2763 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
2764 mcp->in_mb = MBX_3|MBX_1|MBX_0;
2765 mcp->tov = MBX_TOV_SECONDS;
2767 rval = qla2x00_mailbox_command(vha, mcp);
2769 /* Return mailbox statuses. */
2776 if (rval != QLA_SUCCESS) {
2777 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2778 vha->host_no, rval));
2780 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2787 qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
2788 struct vp_rpt_id_entry_24xx *rptid_entry)
2791 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
2792 struct qla_hw_data *ha = vha->hw;
2793 scsi_qla_host_t *vp;
2794 scsi_qla_host_t *tvp;
2796 if (rptid_entry->entry_status != 0)
2799 if (rptid_entry->format == 0) {
2800 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
2801 " number of VPs acquired %d\n", __func__, vha->host_no,
2802 MSB(le16_to_cpu(rptid_entry->vp_count)),
2803 LSB(le16_to_cpu(rptid_entry->vp_count))));
2804 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2805 rptid_entry->port_id[2], rptid_entry->port_id[1],
2806 rptid_entry->port_id[0]));
2807 } else if (rptid_entry->format == 1) {
2809 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2811 "with port id %02x%02x%02x\n", __func__, vha->host_no,
2813 rptid_entry->port_id[2], rptid_entry->port_id[1],
2814 rptid_entry->port_id[0]));
2817 if (vp_idx == 0 && (MSB(stat) != 1))
2820 if (MSB(stat) == 1) {
2821 DEBUG2(printk("scsi(%ld): Could not acquire ID for "
2822 "VP[%d].\n", vha->host_no, vp_idx));
2826 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
2827 if (vp_idx == vp->vp_idx)
2832 vp->d_id.b.domain = rptid_entry->port_id[2];
2833 vp->d_id.b.area = rptid_entry->port_id[1];
2834 vp->d_id.b.al_pa = rptid_entry->port_id[0];
2837 * Cannot configure here as we are still sitting on the
2838 * response queue. Handle it in dpc context.
2840 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
2843 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
2844 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
2845 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
2846 qla2xxx_wake_dpc(vha);
2851 * qla24xx_modify_vp_config
2852 * Change VP configuration for vha
2855 * vha = adapter block pointer.
2858 * qla2xxx local function return status code.
2864 qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2867 struct vp_config_entry_24xx *vpmod;
2868 dma_addr_t vpmod_dma;
2869 struct qla_hw_data *ha = vha->hw;
2870 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2872 /* This can be called by the parent */
2874 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
2876 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
2877 "IOCB.\n", __func__, vha->host_no));
2878 return QLA_MEMORY_ALLOC_FAILED;
2881 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2882 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2883 vpmod->entry_count = 1;
2884 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2885 vpmod->vp_count = 1;
2886 vpmod->vp_index1 = vha->vp_idx;
2887 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2888 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2889 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2890 vpmod->entry_count = 1;
2892 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
2893 if (rval != QLA_SUCCESS) {
2894 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
2895 "(%x).\n", __func__, base_vha->host_no, rval));
2896 } else if (vpmod->comp_status != 0) {
2897 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2898 "-- error status (%x).\n", __func__, base_vha->host_no,
2899 vpmod->comp_status));
2900 rval = QLA_FUNCTION_FAILED;
2901 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2902 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2903 "-- completion status (%x).\n", __func__, base_vha->host_no,
2904 le16_to_cpu(vpmod->comp_status)));
2905 rval = QLA_FUNCTION_FAILED;
2908 DEBUG11(printk("%s(%ld): done.\n", __func__,
2909 base_vha->host_no));
2910 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2912 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
2918 * qla24xx_control_vp
2919 * Enable a virtual port for given host
2922 * ha = adapter block pointer.
2923 * vhba = virtual adapter (unused)
2924 * index = index number for enabled VP
2927 * qla2xxx local function return status code.
2933 qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2937 struct vp_ctrl_entry_24xx *vce;
2939 struct qla_hw_data *ha = vha->hw;
2940 int vp_index = vha->vp_idx;
2941 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2943 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
2944 vha->host_no, vp_index));
2946 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
2947 return QLA_PARAMETER_ERROR;
2949 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2951 DEBUG2_3(printk("%s(%ld): "
2952 "failed to allocate VP Control IOCB.\n", __func__,
2953 base_vha->host_no));
2954 return QLA_MEMORY_ALLOC_FAILED;
2956 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2958 vce->entry_type = VP_CTRL_IOCB_TYPE;
2959 vce->entry_count = 1;
2960 vce->command = cpu_to_le16(cmd);
2961 vce->vp_count = __constant_cpu_to_le16(1);
2963 /* index map in firmware starts with 1; decrement index
2964 * this is ok as we never use index 0
2966 map = (vp_index - 1) / 8;
2967 pos = (vp_index - 1) & 7;
2968 mutex_lock(&ha->vport_lock);
2969 vce->vp_idx_map[map] |= 1 << pos;
2970 mutex_unlock(&ha->vport_lock);
2972 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
2973 if (rval != QLA_SUCCESS) {
2974 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
2975 "(%x).\n", __func__, base_vha->host_no, rval));
2976 printk("%s(%ld): failed to issue VP control IOCB"
2977 "(%x).\n", __func__, base_vha->host_no, rval);
2978 } else if (vce->entry_status != 0) {
2979 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2980 "-- error status (%x).\n", __func__, base_vha->host_no,
2981 vce->entry_status));
2982 printk("%s(%ld): failed to complete IOCB "
2983 "-- error status (%x).\n", __func__, base_vha->host_no,
2985 rval = QLA_FUNCTION_FAILED;
2986 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2987 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2988 "-- completion status (%x).\n", __func__, base_vha->host_no,
2989 le16_to_cpu(vce->comp_status)));
2990 printk("%s(%ld): failed to complete IOCB "
2991 "-- completion status (%x).\n", __func__, base_vha->host_no,
2992 le16_to_cpu(vce->comp_status));
2993 rval = QLA_FUNCTION_FAILED;
2995 DEBUG2(printk("%s(%ld): done.\n", __func__, base_vha->host_no));
2998 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
3004 * qla2x00_send_change_request
3005 * Receive or disable RSCN request from fabric controller
3008 * ha = adapter block pointer
3009 * format = registration format:
3011 * 1 - Fabric detected registration
3012 * 2 - N_port detected registration
3013 * 3 - Full registration
3014 * FF - clear registration
3015 * vp_idx = Virtual port index
3018 * qla2x00 local function return status code.
3025 qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
3030 mbx_cmd_t *mcp = &mc;
3033 * This command is implicitly executed by firmware during login for the
3037 return QLA_FUNCTION_FAILED;
3039 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
3040 mcp->mb[1] = format;
3041 mcp->mb[9] = vp_idx;
3042 mcp->out_mb = MBX_9|MBX_1|MBX_0;
3043 mcp->in_mb = MBX_0|MBX_1;
3044 mcp->tov = MBX_TOV_SECONDS;
3046 rval = qla2x00_mailbox_command(vha, mcp);
3048 if (rval == QLA_SUCCESS) {
3049 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
3059 qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
3064 mbx_cmd_t *mcp = &mc;
3066 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3068 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
3069 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3070 mcp->mb[8] = MSW(addr);
3071 mcp->out_mb = MBX_8|MBX_0;
3073 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3074 mcp->out_mb = MBX_0;
3076 mcp->mb[1] = LSW(addr);
3077 mcp->mb[2] = MSW(req_dma);
3078 mcp->mb[3] = LSW(req_dma);
3079 mcp->mb[6] = MSW(MSD(req_dma));
3080 mcp->mb[7] = LSW(MSD(req_dma));
3081 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
3082 if (IS_FWI2_CAPABLE(vha->hw)) {
3083 mcp->mb[4] = MSW(size);
3084 mcp->mb[5] = LSW(size);
3085 mcp->out_mb |= MBX_5|MBX_4;
3087 mcp->mb[4] = LSW(size);
3088 mcp->out_mb |= MBX_4;
3092 mcp->tov = MBX_TOV_SECONDS;
3094 rval = qla2x00_mailbox_command(vha, mcp);
3096 if (rval != QLA_SUCCESS) {
3097 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3098 vha->host_no, rval, mcp->mb[0]));
3100 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3106 /* 84XX Support **************************************************************/
3108 struct cs84xx_mgmt_cmd {
3110 struct verify_chip_entry_84xx req;
3111 struct verify_chip_rsp_84xx rsp;
3116 qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
3119 struct cs84xx_mgmt_cmd *mn;
3122 unsigned long flags;
3123 struct qla_hw_data *ha = vha->hw;
3125 DEBUG16(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3127 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
3129 DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX "
3130 "IOCB.\n", __func__, vha->host_no));
3131 return QLA_MEMORY_ALLOC_FAILED;
3135 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
3136 /* Diagnostic firmware? */
3137 /* options |= MENLO_DIAG_FW; */
3138 /* We update the firmware with only one data sequence. */
3139 options |= VCO_END_OF_DATA;
3143 memset(mn, 0, sizeof(*mn));
3144 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
3145 mn->p.req.entry_count = 1;
3146 mn->p.req.options = cpu_to_le16(options);
3148 DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__,
3150 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3153 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
3154 if (rval != QLA_SUCCESS) {
3155 DEBUG2_16(printk("%s(%ld): failed to issue Verify "
3156 "IOCB (%x).\n", __func__, vha->host_no, rval));
3160 DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__,
3162 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3165 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3166 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3167 le16_to_cpu(mn->p.rsp.failure_code) : 0;
3168 DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__,
3169 vha->host_no, status[0], status[1]));
3171 if (status[0] != CS_COMPLETE) {
3172 rval = QLA_FUNCTION_FAILED;
3173 if (!(options & VCO_DONT_UPDATE_FW)) {
3174 DEBUG2_16(printk("%s(%ld): Firmware update "
3175 "failed. Retrying without update "
3176 "firmware.\n", __func__, vha->host_no));
3177 options |= VCO_DONT_UPDATE_FW;
3178 options &= ~VCO_FORCE_UPDATE;
3182 DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n",
3183 __func__, vha->host_no,
3184 le32_to_cpu(mn->p.rsp.fw_ver)));
3186 /* NOTE: we only update OP firmware. */
3187 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3188 ha->cs84xx->op_fw_version =
3189 le32_to_cpu(mn->p.rsp.fw_ver);
3190 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3196 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3198 if (rval != QLA_SUCCESS) {
3199 DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__,
3200 vha->host_no, rval));
3202 DEBUG16(printk("%s(%ld): done.\n", __func__, vha->host_no));
3209 qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
3212 unsigned long flags;
3214 mbx_cmd_t *mcp = &mc;
3215 struct device_reg_25xxmq __iomem *reg;
3216 struct qla_hw_data *ha = vha->hw;
3218 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
3219 mcp->mb[1] = req->options;
3220 mcp->mb[2] = MSW(LSD(req->dma));
3221 mcp->mb[3] = LSW(LSD(req->dma));
3222 mcp->mb[6] = MSW(MSD(req->dma));
3223 mcp->mb[7] = LSW(MSD(req->dma));
3224 mcp->mb[5] = req->length;
3226 mcp->mb[10] = req->rsp->id;
3227 mcp->mb[12] = req->qos;
3228 mcp->mb[11] = req->vp_idx;
3229 mcp->mb[13] = req->rid;
3231 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3232 QLA_QUE_PAGE * req->id);
3234 mcp->mb[4] = req->id;
3235 /* que in ptr index */
3237 /* que out ptr index */
3239 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
3240 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3242 mcp->flags = MBX_DMA_OUT;
3245 spin_lock_irqsave(&ha->hardware_lock, flags);
3246 if (!(req->options & BIT_0)) {
3247 WRT_REG_DWORD(®->req_q_in, 0);
3248 WRT_REG_DWORD(®->req_q_out, 0);
3250 req->req_q_in = ®->req_q_in;
3251 req->req_q_out = ®->req_q_out;
3252 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3254 rval = qla2x00_mailbox_command(vha, mcp);
3255 if (rval != QLA_SUCCESS)
3256 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x mb0=%x.\n",
3257 __func__, vha->host_no, rval, mcp->mb[0]));
3262 qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
3265 unsigned long flags;
3267 mbx_cmd_t *mcp = &mc;
3268 struct device_reg_25xxmq __iomem *reg;
3269 struct qla_hw_data *ha = vha->hw;
3271 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
3272 mcp->mb[1] = rsp->options;
3273 mcp->mb[2] = MSW(LSD(rsp->dma));
3274 mcp->mb[3] = LSW(LSD(rsp->dma));
3275 mcp->mb[6] = MSW(MSD(rsp->dma));
3276 mcp->mb[7] = LSW(MSD(rsp->dma));
3277 mcp->mb[5] = rsp->length;
3278 mcp->mb[14] = rsp->msix->entry;
3279 mcp->mb[13] = rsp->rid;
3281 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3282 QLA_QUE_PAGE * rsp->id);
3284 mcp->mb[4] = rsp->id;
3285 /* que in ptr index */
3287 /* que out ptr index */
3289 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
3290 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3292 mcp->flags = MBX_DMA_OUT;
3295 spin_lock_irqsave(&ha->hardware_lock, flags);
3296 if (!(rsp->options & BIT_0)) {
3297 WRT_REG_DWORD(®->rsp_q_out, 0);
3298 WRT_REG_DWORD(®->rsp_q_in, 0);
3301 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3303 rval = qla2x00_mailbox_command(vha, mcp);
3304 if (rval != QLA_SUCCESS)
3305 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x "
3306 "mb0=%x.\n", __func__,
3307 vha->host_no, rval, mcp->mb[0]));
3312 qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
3316 mbx_cmd_t *mcp = &mc;
3318 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3320 mcp->mb[0] = MBC_IDC_ACK;
3321 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
3322 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3324 mcp->tov = MBX_TOV_SECONDS;
3326 rval = qla2x00_mailbox_command(vha, mcp);
3328 if (rval != QLA_SUCCESS) {
3329 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3330 vha->host_no, rval, mcp->mb[0]));
3332 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3339 qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
3343 mbx_cmd_t *mcp = &mc;
3345 if (!IS_QLA81XX(vha->hw))
3346 return QLA_FUNCTION_FAILED;
3348 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3350 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3351 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
3352 mcp->out_mb = MBX_1|MBX_0;
3353 mcp->in_mb = MBX_1|MBX_0;
3354 mcp->tov = MBX_TOV_SECONDS;
3356 rval = qla2x00_mailbox_command(vha, mcp);
3358 if (rval != QLA_SUCCESS) {
3359 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
3360 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3362 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3363 *sector_size = mcp->mb[1];
3370 qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
3374 mbx_cmd_t *mcp = &mc;
3376 if (!IS_QLA81XX(vha->hw))
3377 return QLA_FUNCTION_FAILED;
3379 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3381 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3382 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
3383 FAC_OPT_CMD_WRITE_PROTECT;
3384 mcp->out_mb = MBX_1|MBX_0;
3385 mcp->in_mb = MBX_1|MBX_0;
3386 mcp->tov = MBX_TOV_SECONDS;
3388 rval = qla2x00_mailbox_command(vha, mcp);
3390 if (rval != QLA_SUCCESS) {
3391 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
3392 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3394 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3401 qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
3405 mbx_cmd_t *mcp = &mc;
3407 if (!IS_QLA81XX(vha->hw))
3408 return QLA_FUNCTION_FAILED;
3410 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3412 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3413 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
3414 mcp->mb[2] = LSW(start);
3415 mcp->mb[3] = MSW(start);
3416 mcp->mb[4] = LSW(finish);
3417 mcp->mb[5] = MSW(finish);
3418 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3419 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3420 mcp->tov = MBX_TOV_SECONDS;
3422 rval = qla2x00_mailbox_command(vha, mcp);
3424 if (rval != QLA_SUCCESS) {
3425 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
3426 "mb[2]=%x.\n", __func__, vha->host_no, rval, mcp->mb[0],
3427 mcp->mb[1], mcp->mb[2]));
3429 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3436 qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
3440 mbx_cmd_t *mcp = &mc;
3442 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3444 mcp->mb[0] = MBC_RESTART_MPI_FW;
3445 mcp->out_mb = MBX_0;
3446 mcp->in_mb = MBX_0|MBX_1;
3447 mcp->tov = MBX_TOV_SECONDS;
3449 rval = qla2x00_mailbox_command(vha, mcp);
3451 if (rval != QLA_SUCCESS) {
3452 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x mb[1]=0x%x.\n",
3453 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3455 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3462 qla2x00_read_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
3463 dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
3467 mbx_cmd_t *mcp = &mc;
3469 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3471 mcp->mb[0] = MBC_READ_SFP;
3473 mcp->mb[2] = MSW(sfp_dma);
3474 mcp->mb[3] = LSW(sfp_dma);
3475 mcp->mb[6] = MSW(MSD(sfp_dma));
3476 mcp->mb[7] = LSW(MSD(sfp_dma));
3480 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3482 mcp->tov = MBX_TOV_SECONDS;
3484 rval = qla2x00_mailbox_command(vha, mcp);
3490 if (rval != QLA_SUCCESS) {
3491 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3492 vha->host_no, rval, mcp->mb[0]));
3494 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3501 qla2x00_write_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
3502 dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
3506 mbx_cmd_t *mcp = &mc;
3508 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3514 mcp->mb[0] = MBC_WRITE_SFP;
3516 mcp->mb[2] = MSW(sfp_dma);
3517 mcp->mb[3] = LSW(sfp_dma);
3518 mcp->mb[6] = MSW(MSD(sfp_dma));
3519 mcp->mb[7] = LSW(MSD(sfp_dma));
3523 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3525 mcp->tov = MBX_TOV_SECONDS;
3527 rval = qla2x00_mailbox_command(vha, mcp);
3529 if (rval != QLA_SUCCESS) {
3530 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3531 vha->host_no, rval, mcp->mb[0]));
3533 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3540 qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
3541 uint16_t size_in_bytes, uint16_t *actual_size)
3545 mbx_cmd_t *mcp = &mc;
3547 if (!IS_QLA81XX(vha->hw))
3548 return QLA_FUNCTION_FAILED;
3550 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3552 mcp->mb[0] = MBC_GET_XGMAC_STATS;
3553 mcp->mb[2] = MSW(stats_dma);
3554 mcp->mb[3] = LSW(stats_dma);
3555 mcp->mb[6] = MSW(MSD(stats_dma));
3556 mcp->mb[7] = LSW(MSD(stats_dma));
3557 mcp->mb[8] = size_in_bytes >> 2;
3558 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
3559 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3560 mcp->tov = MBX_TOV_SECONDS;
3562 rval = qla2x00_mailbox_command(vha, mcp);
3564 if (rval != QLA_SUCCESS) {
3565 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x "
3566 "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval,
3567 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
3569 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3571 *actual_size = mcp->mb[2] << 2;
3578 qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
3583 mbx_cmd_t *mcp = &mc;
3585 if (!IS_QLA81XX(vha->hw))
3586 return QLA_FUNCTION_FAILED;
3588 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3590 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
3592 mcp->mb[2] = MSW(tlv_dma);
3593 mcp->mb[3] = LSW(tlv_dma);
3594 mcp->mb[6] = MSW(MSD(tlv_dma));
3595 mcp->mb[7] = LSW(MSD(tlv_dma));
3597 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3598 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3599 mcp->tov = MBX_TOV_SECONDS;
3601 rval = qla2x00_mailbox_command(vha, mcp);
3603 if (rval != QLA_SUCCESS) {
3604 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x "
3605 "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval,
3606 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
3608 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3615 qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
3619 mbx_cmd_t *mcp = &mc;
3621 if (!IS_FWI2_CAPABLE(vha->hw))
3622 return QLA_FUNCTION_FAILED;
3624 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3626 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
3627 mcp->mb[1] = LSW(risc_addr);
3628 mcp->mb[8] = MSW(risc_addr);
3629 mcp->out_mb = MBX_8|MBX_1|MBX_0;
3630 mcp->in_mb = MBX_3|MBX_2|MBX_0;
3633 rval = qla2x00_mailbox_command(vha, mcp);
3634 if (rval != QLA_SUCCESS) {
3635 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3636 vha->host_no, rval, mcp->mb[0]));
3638 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3639 *data = mcp->mb[3] << 16 | mcp->mb[2];
3646 qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq, uint16_t *mresp)
3650 mbx_cmd_t *mcp = &mc;
3651 uint32_t iter_cnt = 0x1;
3653 DEBUG11(printk("scsi(%ld): entered.\n", vha->host_no));
3655 memset(mcp->mb, 0 , sizeof(mcp->mb));
3656 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
3657 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
3659 /* transfer count */
3660 mcp->mb[10] = LSW(mreq->transfer_size);
3661 mcp->mb[11] = MSW(mreq->transfer_size);
3663 /* send data address */
3664 mcp->mb[14] = LSW(mreq->send_dma);
3665 mcp->mb[15] = MSW(mreq->send_dma);
3666 mcp->mb[20] = LSW(MSD(mreq->send_dma));
3667 mcp->mb[21] = MSW(MSD(mreq->send_dma));
3669 /* recieve data address */
3670 mcp->mb[16] = LSW(mreq->rcv_dma);
3671 mcp->mb[17] = MSW(mreq->rcv_dma);
3672 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
3673 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
3675 /* Iteration count */
3676 mcp->mb[18] = LSW(iter_cnt);
3677 mcp->mb[19] = MSW(iter_cnt);
3679 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
3680 MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
3681 if (IS_QLA81XX(vha->hw))
3682 mcp->out_mb |= MBX_2;
3683 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
3685 mcp->buf_size = mreq->transfer_size;
3686 mcp->tov = MBX_TOV_SECONDS;
3687 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3689 rval = qla2x00_mailbox_command(vha, mcp);
3691 if (rval != QLA_SUCCESS) {
3692 DEBUG2(printk(KERN_WARNING
3693 "(%ld): failed=%x mb[0]=0x%x "
3694 "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,
3695 mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[18], mcp->mb[19]));
3697 DEBUG2(printk(KERN_WARNING
3698 "scsi(%ld): done.\n", vha->host_no));
3701 /* Copy mailbox information */
3702 memcpy( mresp, mcp->mb, 64);
3703 mresp[3] = mcp->mb[18];
3704 mresp[4] = mcp->mb[19];
3709 qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq, uint16_t *mresp)
3713 mbx_cmd_t *mcp = &mc;
3714 struct qla_hw_data *ha = vha->hw;
3716 DEBUG11(printk("scsi(%ld): entered.\n", vha->host_no));
3718 memset(mcp->mb, 0 , sizeof(mcp->mb));
3719 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
3720 mcp->mb[1] = mreq->options | BIT_6; /* BIT_6 specifies 64bit address */
3722 mcp->mb[1] |= BIT_15;
3723 mcp->mb[2] = IS_QLA81XX(ha) ? vha->fcoe_fcf_idx : 0;
3724 mcp->mb[16] = LSW(mreq->rcv_dma);
3725 mcp->mb[17] = MSW(mreq->rcv_dma);
3726 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
3727 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
3729 mcp->mb[10] = LSW(mreq->transfer_size);
3731 mcp->mb[14] = LSW(mreq->send_dma);
3732 mcp->mb[15] = MSW(mreq->send_dma);
3733 mcp->mb[20] = LSW(MSD(mreq->send_dma));
3734 mcp->mb[21] = MSW(MSD(mreq->send_dma));
3736 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
3737 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
3739 mcp->out_mb |= MBX_2;
3742 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha))
3743 mcp->in_mb |= MBX_1;
3745 mcp->in_mb |= MBX_3;
3747 mcp->tov = MBX_TOV_SECONDS;
3748 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3749 mcp->buf_size = mreq->transfer_size;
3751 rval = qla2x00_mailbox_command(vha, mcp);
3753 if (rval != QLA_SUCCESS) {
3754 DEBUG2(printk(KERN_WARNING
3755 "(%ld): failed=%x mb[0]=0x%x mb[1]=0x%x.\n",
3756 vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3758 DEBUG2(printk(KERN_WARNING
3759 "scsi(%ld): done.\n", vha->host_no));
3762 /* Copy mailbox information */
3763 memcpy( mresp, mcp->mb, 32);
3767 qla84xx_reset_chip(scsi_qla_host_t *ha, uint16_t enable_diagnostic,
3768 uint16_t *cmd_status)
3772 mbx_cmd_t *mcp = &mc;
3774 DEBUG16(printk("%s(%ld): enable_diag=%d entered.\n", __func__,
3775 ha->host_no, enable_diagnostic));
3777 mcp->mb[0] = MBC_ISP84XX_RESET;
3778 mcp->mb[1] = enable_diagnostic;
3779 mcp->out_mb = MBX_1|MBX_0;
3780 mcp->in_mb = MBX_1|MBX_0;
3781 mcp->tov = MBX_TOV_SECONDS;
3782 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3783 rval = qla2x00_mailbox_command(ha, mcp);
3785 /* Return mailbox statuses. */
3786 *cmd_status = mcp->mb[0];
3787 if (rval != QLA_SUCCESS)
3788 DEBUG16(printk("%s(%ld): failed=%x.\n", __func__, ha->host_no,
3791 DEBUG16(printk("%s(%ld): done.\n", __func__, ha->host_no));
3797 qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
3801 mbx_cmd_t *mcp = &mc;
3803 if (!IS_FWI2_CAPABLE(vha->hw))
3804 return QLA_FUNCTION_FAILED;
3806 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3808 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
3809 mcp->mb[1] = LSW(risc_addr);
3810 mcp->mb[2] = LSW(data);
3811 mcp->mb[3] = MSW(data);
3812 mcp->mb[8] = MSW(risc_addr);
3813 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
3817 rval = qla2x00_mailbox_command(vha, mcp);
3818 if (rval != QLA_SUCCESS) {
3819 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3820 vha->host_no, rval, mcp->mb[0]));
3822 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3829 qla2x00_get_data_rate(scsi_qla_host_t *vha)
3833 mbx_cmd_t *mcp = &mc;
3834 struct qla_hw_data *ha = vha->hw;
3836 if (!IS_FWI2_CAPABLE(ha))
3837 return QLA_FUNCTION_FAILED;
3839 DEBUG11(printk(KERN_INFO "%s(%ld): entered.\n", __func__, vha->host_no));
3841 mcp->mb[0] = MBC_DATA_RATE;
3843 mcp->out_mb = MBX_1|MBX_0;
3844 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3845 mcp->tov = MBX_TOV_SECONDS;
3847 rval = qla2x00_mailbox_command(vha, mcp);
3848 if (rval != QLA_SUCCESS) {
3849 DEBUG2_3_11(printk(KERN_INFO "%s(%ld): failed=%x mb[0]=%x.\n",
3850 __func__, vha->host_no, rval, mcp->mb[0]));
3852 DEBUG11(printk(KERN_INFO
3853 "%s(%ld): done.\n", __func__, vha->host_no));
3854 if (mcp->mb[1] != 0x7)
3855 ha->link_data_rate = mcp->mb[1];