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));
342 #define EXTENDED_BB_CREDITS BIT_0
345 * Start adapter firmware.
348 * ha = adapter block pointer.
349 * TARGET_QUEUE_LOCK must be released.
350 * ADAPTER_STATE_LOCK must be released.
353 * qla2x00 local function return status code.
359 qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
362 struct qla_hw_data *ha = vha->hw;
364 mbx_cmd_t *mcp = &mc;
366 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
368 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
371 if (IS_FWI2_CAPABLE(ha)) {
372 mcp->mb[1] = MSW(risc_addr);
373 mcp->mb[2] = LSW(risc_addr);
375 if (IS_QLA81XX(ha)) {
376 struct nvram_81xx *nv = ha->nvram;
377 mcp->mb[4] = (nv->enhanced_features &
378 EXTENDED_BB_CREDITS);
381 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
384 mcp->mb[1] = LSW(risc_addr);
385 mcp->out_mb |= MBX_1;
386 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
388 mcp->out_mb |= MBX_2;
392 mcp->tov = MBX_TOV_SECONDS;
394 rval = qla2x00_mailbox_command(vha, mcp);
396 if (rval != QLA_SUCCESS) {
397 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
398 vha->host_no, rval, mcp->mb[0]));
400 if (IS_FWI2_CAPABLE(ha)) {
401 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
402 __func__, vha->host_no, mcp->mb[1]));
404 DEBUG11(printk("%s(%ld): done.\n", __func__,
413 * qla2x00_get_fw_version
414 * Get firmware version.
417 * ha: adapter state pointer.
418 * major: pointer for major number.
419 * minor: pointer for minor number.
420 * subminor: pointer for subminor number.
423 * qla2x00 local function return status code.
429 qla2x00_get_fw_version(scsi_qla_host_t *vha, uint16_t *major, uint16_t *minor,
430 uint16_t *subminor, uint16_t *attributes, uint32_t *memory, uint8_t *mpi,
431 uint32_t *mpi_caps, uint8_t *phy)
435 mbx_cmd_t *mcp = &mc;
437 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
439 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
441 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
442 if (IS_QLA81XX(vha->hw))
443 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
445 mcp->tov = MBX_TOV_SECONDS;
446 rval = qla2x00_mailbox_command(vha, mcp);
447 if (rval != QLA_SUCCESS)
450 /* Return mailbox data. */
453 *subminor = mcp->mb[3];
454 *attributes = mcp->mb[6];
455 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
456 *memory = 0x1FFFF; /* Defaults to 128KB. */
458 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
459 if (IS_QLA81XX(vha->hw)) {
460 mpi[0] = mcp->mb[10] & 0xff;
461 mpi[1] = mcp->mb[11] >> 8;
462 mpi[2] = mcp->mb[11] & 0xff;
463 *mpi_caps = (mcp->mb[12] << 16) | mcp->mb[13];
464 phy[0] = mcp->mb[8] & 0xff;
465 phy[1] = mcp->mb[9] >> 8;
466 phy[2] = mcp->mb[9] & 0xff;
469 if (rval != QLA_SUCCESS) {
471 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
472 vha->host_no, rval));
475 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
481 * qla2x00_get_fw_options
482 * Set firmware options.
485 * ha = adapter block pointer.
486 * fwopt = pointer for firmware options.
489 * qla2x00 local function return status code.
495 qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
499 mbx_cmd_t *mcp = &mc;
501 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
503 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
505 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
506 mcp->tov = MBX_TOV_SECONDS;
508 rval = qla2x00_mailbox_command(vha, mcp);
510 if (rval != QLA_SUCCESS) {
512 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
513 vha->host_no, rval));
515 fwopts[0] = mcp->mb[0];
516 fwopts[1] = mcp->mb[1];
517 fwopts[2] = mcp->mb[2];
518 fwopts[3] = mcp->mb[3];
520 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
528 * qla2x00_set_fw_options
529 * Set firmware options.
532 * ha = adapter block pointer.
533 * fwopt = pointer for firmware options.
536 * qla2x00 local function return status code.
542 qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
546 mbx_cmd_t *mcp = &mc;
548 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
550 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
551 mcp->mb[1] = fwopts[1];
552 mcp->mb[2] = fwopts[2];
553 mcp->mb[3] = fwopts[3];
554 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
556 if (IS_FWI2_CAPABLE(vha->hw)) {
559 mcp->mb[10] = fwopts[10];
560 mcp->mb[11] = fwopts[11];
561 mcp->mb[12] = 0; /* Undocumented, but used */
562 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
564 mcp->tov = MBX_TOV_SECONDS;
566 rval = qla2x00_mailbox_command(vha, mcp);
568 fwopts[0] = mcp->mb[0];
570 if (rval != QLA_SUCCESS) {
572 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
573 vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
576 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
583 * qla2x00_mbx_reg_test
584 * Mailbox register wrap test.
587 * ha = adapter block pointer.
588 * TARGET_QUEUE_LOCK must be released.
589 * ADAPTER_STATE_LOCK must be released.
592 * qla2x00 local function return status code.
598 qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
602 mbx_cmd_t *mcp = &mc;
604 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", vha->host_no));
606 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
614 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
615 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
616 mcp->tov = MBX_TOV_SECONDS;
618 rval = qla2x00_mailbox_command(vha, mcp);
620 if (rval == QLA_SUCCESS) {
621 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
622 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
623 rval = QLA_FUNCTION_FAILED;
624 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
625 mcp->mb[7] != 0x2525)
626 rval = QLA_FUNCTION_FAILED;
629 if (rval != QLA_SUCCESS) {
631 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
632 vha->host_no, rval));
635 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
643 * qla2x00_verify_checksum
644 * Verify firmware checksum.
647 * ha = adapter block pointer.
648 * TARGET_QUEUE_LOCK must be released.
649 * ADAPTER_STATE_LOCK must be released.
652 * qla2x00 local function return status code.
658 qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
662 mbx_cmd_t *mcp = &mc;
664 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
666 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
669 if (IS_FWI2_CAPABLE(vha->hw)) {
670 mcp->mb[1] = MSW(risc_addr);
671 mcp->mb[2] = LSW(risc_addr);
672 mcp->out_mb |= MBX_2|MBX_1;
673 mcp->in_mb |= MBX_2|MBX_1;
675 mcp->mb[1] = LSW(risc_addr);
676 mcp->out_mb |= MBX_1;
680 mcp->tov = MBX_TOV_SECONDS;
682 rval = qla2x00_mailbox_command(vha, mcp);
684 if (rval != QLA_SUCCESS) {
685 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
686 vha->host_no, rval, IS_FWI2_CAPABLE(vha->hw) ?
687 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
689 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
697 * Issue IOCB using mailbox command
700 * ha = adapter state pointer.
701 * buffer = buffer pointer.
702 * phys_addr = physical address of buffer.
703 * size = size of buffer.
704 * TARGET_QUEUE_LOCK must be released.
705 * ADAPTER_STATE_LOCK must be released.
708 * qla2x00 local function return status code.
714 qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
715 dma_addr_t phys_addr, size_t size, uint32_t tov)
719 mbx_cmd_t *mcp = &mc;
721 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
723 mcp->mb[2] = MSW(phys_addr);
724 mcp->mb[3] = LSW(phys_addr);
725 mcp->mb[6] = MSW(MSD(phys_addr));
726 mcp->mb[7] = LSW(MSD(phys_addr));
727 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
728 mcp->in_mb = MBX_2|MBX_0;
731 rval = qla2x00_mailbox_command(vha, mcp);
733 if (rval != QLA_SUCCESS) {
735 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
736 vha->host_no, rval));
738 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
740 /* Mask reserved bits. */
741 sts_entry->entry_status &=
742 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
749 qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
752 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
757 * qla2x00_abort_command
758 * Abort command aborts a specified IOCB.
761 * ha = adapter block pointer.
762 * sp = SB structure pointer.
765 * qla2x00 local function return status code.
771 qla2x00_abort_command(srb_t *sp)
773 unsigned long flags = 0;
777 mbx_cmd_t *mcp = &mc;
778 fc_port_t *fcport = sp->fcport;
779 scsi_qla_host_t *vha = fcport->vha;
780 struct qla_hw_data *ha = vha->hw;
781 struct req_que *req = vha->req;
783 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", vha->host_no));
785 spin_lock_irqsave(&ha->hardware_lock, flags);
786 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
787 if (req->outstanding_cmds[handle] == sp)
790 spin_unlock_irqrestore(&ha->hardware_lock, flags);
792 if (handle == MAX_OUTSTANDING_COMMANDS) {
793 /* command not found */
794 return QLA_FUNCTION_FAILED;
797 mcp->mb[0] = MBC_ABORT_COMMAND;
798 if (HAS_EXTENDED_IDS(ha))
799 mcp->mb[1] = fcport->loop_id;
801 mcp->mb[1] = fcport->loop_id << 8;
802 mcp->mb[2] = (uint16_t)handle;
803 mcp->mb[3] = (uint16_t)(handle >> 16);
804 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
805 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
807 mcp->tov = MBX_TOV_SECONDS;
809 rval = qla2x00_mailbox_command(vha, mcp);
811 if (rval != QLA_SUCCESS) {
812 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
813 vha->host_no, rval));
815 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
823 qla2x00_abort_target(struct fc_port *fcport, unsigned int l, int tag)
827 mbx_cmd_t *mcp = &mc;
828 scsi_qla_host_t *vha;
832 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
836 req = vha->hw->req_q_map[tag];
837 rsp = vha->hw->rsp_q_map[tag];
838 mcp->mb[0] = MBC_ABORT_TARGET;
839 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
840 if (HAS_EXTENDED_IDS(vha->hw)) {
841 mcp->mb[1] = fcport->loop_id;
843 mcp->out_mb |= MBX_10;
845 mcp->mb[1] = fcport->loop_id << 8;
847 mcp->mb[2] = vha->hw->loop_reset_delay;
848 mcp->mb[9] = vha->vp_idx;
851 mcp->tov = MBX_TOV_SECONDS;
853 rval = qla2x00_mailbox_command(vha, mcp);
854 if (rval != QLA_SUCCESS) {
855 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
856 vha->host_no, rval));
859 /* Issue marker IOCB. */
860 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
862 if (rval2 != QLA_SUCCESS) {
863 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
864 "(%x).\n", __func__, vha->host_no, rval2));
866 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
873 qla2x00_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
877 mbx_cmd_t *mcp = &mc;
878 scsi_qla_host_t *vha;
882 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
885 req = vha->hw->req_q_map[tag];
886 rsp = vha->hw->rsp_q_map[tag];
887 mcp->mb[0] = MBC_LUN_RESET;
888 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
889 if (HAS_EXTENDED_IDS(vha->hw))
890 mcp->mb[1] = fcport->loop_id;
892 mcp->mb[1] = fcport->loop_id << 8;
895 mcp->mb[9] = vha->vp_idx;
898 mcp->tov = MBX_TOV_SECONDS;
900 rval = qla2x00_mailbox_command(vha, mcp);
901 if (rval != QLA_SUCCESS) {
902 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
903 vha->host_no, rval));
906 /* Issue marker IOCB. */
907 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
909 if (rval2 != QLA_SUCCESS) {
910 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
911 "(%x).\n", __func__, vha->host_no, rval2));
913 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
920 * qla2x00_get_adapter_id
921 * Get adapter ID and topology.
924 * ha = adapter block pointer.
925 * id = pointer for loop ID.
926 * al_pa = pointer for AL_PA.
927 * area = pointer for area.
928 * domain = pointer for domain.
929 * top = pointer for topology.
930 * TARGET_QUEUE_LOCK must be released.
931 * ADAPTER_STATE_LOCK must be released.
934 * qla2x00 local function return status code.
940 qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
941 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
945 mbx_cmd_t *mcp = &mc;
947 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
950 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
951 mcp->mb[9] = vha->vp_idx;
952 mcp->out_mb = MBX_9|MBX_0;
953 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
954 if (IS_QLA81XX(vha->hw))
955 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
956 mcp->tov = MBX_TOV_SECONDS;
958 rval = qla2x00_mailbox_command(vha, mcp);
959 if (mcp->mb[0] == MBS_COMMAND_ERROR)
960 rval = QLA_COMMAND_ERROR;
961 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
962 rval = QLA_INVALID_COMMAND;
966 *al_pa = LSB(mcp->mb[2]);
967 *area = MSB(mcp->mb[2]);
968 *domain = LSB(mcp->mb[3]);
970 *sw_cap = mcp->mb[7];
972 if (rval != QLA_SUCCESS) {
974 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
975 vha->host_no, rval));
977 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
980 if (IS_QLA81XX(vha->hw)) {
981 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
982 vha->fcoe_fcf_idx = mcp->mb[10];
983 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
984 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
985 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
986 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
987 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
988 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
996 * qla2x00_get_retry_cnt
997 * Get current firmware login retry count and delay.
1000 * ha = adapter block pointer.
1001 * retry_cnt = pointer to login retry count.
1002 * tov = pointer to login timeout value.
1005 * qla2x00 local function return status code.
1011 qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
1017 mbx_cmd_t *mcp = &mc;
1019 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
1022 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1023 mcp->out_mb = MBX_0;
1024 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1025 mcp->tov = MBX_TOV_SECONDS;
1027 rval = qla2x00_mailbox_command(vha, mcp);
1029 if (rval != QLA_SUCCESS) {
1031 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
1032 vha->host_no, mcp->mb[0]));
1034 /* Convert returned data and check our values. */
1035 *r_a_tov = mcp->mb[3] / 2;
1036 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1037 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1038 /* Update to the larger values */
1039 *retry_cnt = (uint8_t)mcp->mb[1];
1043 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
1044 "ratov=%d.\n", vha->host_no, mcp->mb[3], ratov));
1051 * qla2x00_init_firmware
1052 * Initialize adapter firmware.
1055 * ha = adapter block pointer.
1056 * dptr = Initialization control block pointer.
1057 * size = size of initialization control block.
1058 * TARGET_QUEUE_LOCK must be released.
1059 * ADAPTER_STATE_LOCK must be released.
1062 * qla2x00 local function return status code.
1068 qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
1072 mbx_cmd_t *mcp = &mc;
1073 struct qla_hw_data *ha = vha->hw;
1075 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1078 if (ha->flags.npiv_supported)
1079 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1081 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1084 mcp->mb[2] = MSW(ha->init_cb_dma);
1085 mcp->mb[3] = LSW(ha->init_cb_dma);
1086 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1087 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1088 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1089 if (IS_QLA81XX(ha) && ha->ex_init_cb->ex_version) {
1091 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1092 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1093 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1094 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1095 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1096 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1099 mcp->buf_size = size;
1100 mcp->flags = MBX_DMA_OUT;
1101 mcp->tov = MBX_TOV_SECONDS;
1102 rval = qla2x00_mailbox_command(vha, mcp);
1104 if (rval != QLA_SUCCESS) {
1106 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1108 vha->host_no, rval, mcp->mb[0]));
1111 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1119 * qla2x00_get_port_database
1120 * Issue normal/enhanced get port database mailbox command
1121 * and copy device name as necessary.
1124 * ha = adapter state pointer.
1125 * dev = structure pointer.
1126 * opt = enhanced cmd option byte.
1129 * qla2x00 local function return status code.
1135 qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
1139 mbx_cmd_t *mcp = &mc;
1140 port_database_t *pd;
1141 struct port_database_24xx *pd24;
1143 struct qla_hw_data *ha = vha->hw;
1145 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1148 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1150 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1151 "structure.\n", __func__, vha->host_no));
1152 return QLA_MEMORY_ALLOC_FAILED;
1154 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
1156 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1157 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
1158 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1159 mcp->mb[2] = MSW(pd_dma);
1160 mcp->mb[3] = LSW(pd_dma);
1161 mcp->mb[6] = MSW(MSD(pd_dma));
1162 mcp->mb[7] = LSW(MSD(pd_dma));
1163 mcp->mb[9] = vha->vp_idx;
1164 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1166 if (IS_FWI2_CAPABLE(ha)) {
1167 mcp->mb[1] = fcport->loop_id;
1169 mcp->out_mb |= MBX_10|MBX_1;
1170 mcp->in_mb |= MBX_1;
1171 } else if (HAS_EXTENDED_IDS(ha)) {
1172 mcp->mb[1] = fcport->loop_id;
1174 mcp->out_mb |= MBX_10|MBX_1;
1176 mcp->mb[1] = fcport->loop_id << 8 | opt;
1177 mcp->out_mb |= MBX_1;
1179 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1180 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
1181 mcp->flags = MBX_DMA_IN;
1182 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1183 rval = qla2x00_mailbox_command(vha, mcp);
1184 if (rval != QLA_SUCCESS)
1187 if (IS_FWI2_CAPABLE(ha)) {
1188 pd24 = (struct port_database_24xx *) pd;
1190 /* Check for logged in state. */
1191 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1192 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1193 DEBUG2(printk("%s(%ld): Unable to verify "
1194 "login-state (%x/%x) for loop_id %x\n",
1195 __func__, vha->host_no,
1196 pd24->current_login_state,
1197 pd24->last_login_state, fcport->loop_id));
1198 rval = QLA_FUNCTION_FAILED;
1202 /* Names are little-endian. */
1203 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1204 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1206 /* Get port_id of device. */
1207 fcport->d_id.b.domain = pd24->port_id[0];
1208 fcport->d_id.b.area = pd24->port_id[1];
1209 fcport->d_id.b.al_pa = pd24->port_id[2];
1210 fcport->d_id.b.rsvd_1 = 0;
1212 /* If not target must be initiator or unknown type. */
1213 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1214 fcport->port_type = FCT_INITIATOR;
1216 fcport->port_type = FCT_TARGET;
1218 /* Check for logged in state. */
1219 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1220 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1221 rval = QLA_FUNCTION_FAILED;
1225 /* Names are little-endian. */
1226 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1227 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1229 /* Get port_id of device. */
1230 fcport->d_id.b.domain = pd->port_id[0];
1231 fcport->d_id.b.area = pd->port_id[3];
1232 fcport->d_id.b.al_pa = pd->port_id[2];
1233 fcport->d_id.b.rsvd_1 = 0;
1235 /* If not target must be initiator or unknown type. */
1236 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1237 fcport->port_type = FCT_INITIATOR;
1239 fcport->port_type = FCT_TARGET;
1241 /* Passback COS information. */
1242 fcport->supported_classes = (pd->options & BIT_4) ?
1243 FC_COS_CLASS2: FC_COS_CLASS3;
1247 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1249 if (rval != QLA_SUCCESS) {
1250 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1251 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1253 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1260 * qla2x00_get_firmware_state
1261 * Get adapter firmware state.
1264 * ha = adapter block pointer.
1265 * dptr = pointer for firmware state.
1266 * TARGET_QUEUE_LOCK must be released.
1267 * ADAPTER_STATE_LOCK must be released.
1270 * qla2x00 local function return status code.
1276 qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
1280 mbx_cmd_t *mcp = &mc;
1282 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1285 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1286 mcp->out_mb = MBX_0;
1287 if (IS_FWI2_CAPABLE(vha->hw))
1288 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1290 mcp->in_mb = MBX_1|MBX_0;
1291 mcp->tov = MBX_TOV_SECONDS;
1293 rval = qla2x00_mailbox_command(vha, mcp);
1295 /* Return firmware states. */
1296 states[0] = mcp->mb[1];
1297 if (IS_FWI2_CAPABLE(vha->hw)) {
1298 states[1] = mcp->mb[2];
1299 states[2] = mcp->mb[3];
1300 states[3] = mcp->mb[4];
1301 states[4] = mcp->mb[5];
1304 if (rval != QLA_SUCCESS) {
1306 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1307 "failed=%x.\n", vha->host_no, rval));
1310 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1318 * qla2x00_get_port_name
1319 * Issue get port name mailbox command.
1320 * Returned name is in big endian format.
1323 * ha = adapter block pointer.
1324 * loop_id = loop ID of device.
1325 * name = pointer for name.
1326 * TARGET_QUEUE_LOCK must be released.
1327 * ADAPTER_STATE_LOCK must be released.
1330 * qla2x00 local function return status code.
1336 qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
1341 mbx_cmd_t *mcp = &mc;
1343 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1346 mcp->mb[0] = MBC_GET_PORT_NAME;
1347 mcp->mb[9] = vha->vp_idx;
1348 mcp->out_mb = MBX_9|MBX_1|MBX_0;
1349 if (HAS_EXTENDED_IDS(vha->hw)) {
1350 mcp->mb[1] = loop_id;
1352 mcp->out_mb |= MBX_10;
1354 mcp->mb[1] = loop_id << 8 | opt;
1357 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1358 mcp->tov = MBX_TOV_SECONDS;
1360 rval = qla2x00_mailbox_command(vha, mcp);
1362 if (rval != QLA_SUCCESS) {
1364 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1365 vha->host_no, rval));
1368 /* This function returns name in big endian. */
1369 name[0] = MSB(mcp->mb[2]);
1370 name[1] = LSB(mcp->mb[2]);
1371 name[2] = MSB(mcp->mb[3]);
1372 name[3] = LSB(mcp->mb[3]);
1373 name[4] = MSB(mcp->mb[6]);
1374 name[5] = LSB(mcp->mb[6]);
1375 name[6] = MSB(mcp->mb[7]);
1376 name[7] = LSB(mcp->mb[7]);
1379 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1388 * Issue LIP reset mailbox command.
1391 * ha = adapter block pointer.
1392 * TARGET_QUEUE_LOCK must be released.
1393 * ADAPTER_STATE_LOCK must be released.
1396 * qla2x00 local function return status code.
1402 qla2x00_lip_reset(scsi_qla_host_t *vha)
1406 mbx_cmd_t *mcp = &mc;
1408 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1410 if (IS_QLA81XX(vha->hw)) {
1411 /* Logout across all FCFs. */
1412 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1415 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1416 } else if (IS_FWI2_CAPABLE(vha->hw)) {
1417 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1420 mcp->mb[3] = vha->hw->loop_reset_delay;
1421 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1423 mcp->mb[0] = MBC_LIP_RESET;
1424 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1425 if (HAS_EXTENDED_IDS(vha->hw)) {
1426 mcp->mb[1] = 0x00ff;
1428 mcp->out_mb |= MBX_10;
1430 mcp->mb[1] = 0xff00;
1432 mcp->mb[2] = vha->hw->loop_reset_delay;
1436 mcp->tov = MBX_TOV_SECONDS;
1438 rval = qla2x00_mailbox_command(vha, mcp);
1440 if (rval != QLA_SUCCESS) {
1442 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1443 __func__, vha->host_no, rval));
1446 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1457 * ha = adapter block pointer.
1458 * sns = pointer for command.
1459 * cmd_size = command size.
1460 * buf_size = response/command size.
1461 * TARGET_QUEUE_LOCK must be released.
1462 * ADAPTER_STATE_LOCK must be released.
1465 * qla2x00 local function return status code.
1471 qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
1472 uint16_t cmd_size, size_t buf_size)
1476 mbx_cmd_t *mcp = &mc;
1478 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1481 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1482 "tov=%d.\n", vha->hw->retry_count, vha->hw->login_timeout,
1485 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1486 mcp->mb[1] = cmd_size;
1487 mcp->mb[2] = MSW(sns_phys_address);
1488 mcp->mb[3] = LSW(sns_phys_address);
1489 mcp->mb[6] = MSW(MSD(sns_phys_address));
1490 mcp->mb[7] = LSW(MSD(sns_phys_address));
1491 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1492 mcp->in_mb = MBX_0|MBX_1;
1493 mcp->buf_size = buf_size;
1494 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1495 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
1496 rval = qla2x00_mailbox_command(vha, mcp);
1498 if (rval != QLA_SUCCESS) {
1500 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1501 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1502 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1503 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1506 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", vha->host_no));
1513 qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1514 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1518 struct logio_entry_24xx *lg;
1521 struct qla_hw_data *ha = vha->hw;
1522 struct req_que *req;
1523 struct rsp_que *rsp;
1525 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1527 if (ha->flags.cpu_affinity_enabled)
1528 req = ha->req_q_map[0];
1533 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1535 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1536 __func__, vha->host_no));
1537 return QLA_MEMORY_ALLOC_FAILED;
1539 memset(lg, 0, sizeof(struct logio_entry_24xx));
1541 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1542 lg->entry_count = 1;
1543 lg->handle = MAKE_HANDLE(req->id, lg->handle);
1544 lg->nport_handle = cpu_to_le16(loop_id);
1545 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1547 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1549 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
1550 lg->port_id[0] = al_pa;
1551 lg->port_id[1] = area;
1552 lg->port_id[2] = domain;
1553 lg->vp_index = vha->vp_idx;
1554 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
1555 if (rval != QLA_SUCCESS) {
1556 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
1557 "(%x).\n", __func__, vha->host_no, rval));
1558 } else if (lg->entry_status != 0) {
1559 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1560 "-- error status (%x).\n", __func__, vha->host_no,
1562 rval = QLA_FUNCTION_FAILED;
1563 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1564 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1565 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1567 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1568 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1569 vha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1573 case LSC_SCODE_PORTID_USED:
1574 mb[0] = MBS_PORT_ID_USED;
1575 mb[1] = LSW(iop[1]);
1577 case LSC_SCODE_NPORT_USED:
1578 mb[0] = MBS_LOOP_ID_USED;
1580 case LSC_SCODE_NOLINK:
1581 case LSC_SCODE_NOIOCB:
1582 case LSC_SCODE_NOXCB:
1583 case LSC_SCODE_CMD_FAILED:
1584 case LSC_SCODE_NOFABRIC:
1585 case LSC_SCODE_FW_NOT_READY:
1586 case LSC_SCODE_NOT_LOGGED_IN:
1587 case LSC_SCODE_NOPCB:
1588 case LSC_SCODE_ELS_REJECT:
1589 case LSC_SCODE_CMD_PARAM_ERR:
1590 case LSC_SCODE_NONPORT:
1591 case LSC_SCODE_LOGGED_IN:
1592 case LSC_SCODE_NOFLOGI_ACC:
1594 mb[0] = MBS_COMMAND_ERROR;
1598 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1600 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1602 mb[0] = MBS_COMMAND_COMPLETE;
1604 if (iop[0] & BIT_4) {
1610 /* Passback COS information. */
1612 if (lg->io_parameter[7] || lg->io_parameter[8])
1613 mb[10] |= BIT_0; /* Class 2. */
1614 if (lg->io_parameter[9] || lg->io_parameter[10])
1615 mb[10] |= BIT_1; /* Class 3. */
1618 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1624 * qla2x00_login_fabric
1625 * Issue login fabric port mailbox command.
1628 * ha = adapter block pointer.
1629 * loop_id = device loop ID.
1630 * domain = device domain.
1631 * area = device area.
1632 * al_pa = device AL_PA.
1633 * status = pointer for return status.
1634 * opt = command options.
1635 * TARGET_QUEUE_LOCK must be released.
1636 * ADAPTER_STATE_LOCK must be released.
1639 * qla2x00 local function return status code.
1645 qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1646 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1650 mbx_cmd_t *mcp = &mc;
1651 struct qla_hw_data *ha = vha->hw;
1653 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", vha->host_no));
1655 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1656 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1657 if (HAS_EXTENDED_IDS(ha)) {
1658 mcp->mb[1] = loop_id;
1660 mcp->out_mb |= MBX_10;
1662 mcp->mb[1] = (loop_id << 8) | opt;
1664 mcp->mb[2] = domain;
1665 mcp->mb[3] = area << 8 | al_pa;
1667 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1668 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1670 rval = qla2x00_mailbox_command(vha, mcp);
1672 /* Return mailbox statuses. */
1679 /* COS retrieved from Get-Port-Database mailbox command. */
1683 if (rval != QLA_SUCCESS) {
1684 /* RLU tmp code: need to change main mailbox_command function to
1685 * return ok even when the mailbox completion value is not
1686 * SUCCESS. The caller needs to be responsible to interpret
1687 * the return values of this mailbox command if we're not
1688 * to change too much of the existing code.
1690 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1691 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1692 mcp->mb[0] == 0x4006)
1696 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1697 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", vha->host_no, rval,
1698 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
1701 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1709 * qla2x00_login_local_device
1710 * Issue login loop port mailbox command.
1713 * ha = adapter block pointer.
1714 * loop_id = device loop ID.
1715 * opt = command options.
1718 * Return status code.
1725 qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
1726 uint16_t *mb_ret, uint8_t opt)
1730 mbx_cmd_t *mcp = &mc;
1731 struct qla_hw_data *ha = vha->hw;
1733 if (IS_FWI2_CAPABLE(ha))
1734 return qla24xx_login_fabric(vha, fcport->loop_id,
1735 fcport->d_id.b.domain, fcport->d_id.b.area,
1736 fcport->d_id.b.al_pa, mb_ret, opt);
1738 DEBUG3(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1740 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1741 if (HAS_EXTENDED_IDS(ha))
1742 mcp->mb[1] = fcport->loop_id;
1744 mcp->mb[1] = fcport->loop_id << 8;
1746 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1747 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1748 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1750 rval = qla2x00_mailbox_command(vha, mcp);
1752 /* Return mailbox statuses. */
1753 if (mb_ret != NULL) {
1754 mb_ret[0] = mcp->mb[0];
1755 mb_ret[1] = mcp->mb[1];
1756 mb_ret[6] = mcp->mb[6];
1757 mb_ret[7] = mcp->mb[7];
1760 if (rval != QLA_SUCCESS) {
1761 /* AV tmp code: need to change main mailbox_command function to
1762 * return ok even when the mailbox completion value is not
1763 * SUCCESS. The caller needs to be responsible to interpret
1764 * the return values of this mailbox command if we're not
1765 * to change too much of the existing code.
1767 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1770 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1771 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
1772 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1773 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1774 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
1775 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1778 DEBUG3(printk("%s(%ld): done.\n", __func__, vha->host_no));
1785 qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1786 uint8_t area, uint8_t al_pa)
1789 struct logio_entry_24xx *lg;
1791 struct qla_hw_data *ha = vha->hw;
1792 struct req_que *req;
1793 struct rsp_que *rsp;
1795 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1797 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1799 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1800 __func__, vha->host_no));
1801 return QLA_MEMORY_ALLOC_FAILED;
1803 memset(lg, 0, sizeof(struct logio_entry_24xx));
1805 if (ql2xmaxqueues > 1)
1806 req = ha->req_q_map[0];
1810 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1811 lg->entry_count = 1;
1812 lg->handle = MAKE_HANDLE(req->id, lg->handle);
1813 lg->nport_handle = cpu_to_le16(loop_id);
1815 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
1816 lg->port_id[0] = al_pa;
1817 lg->port_id[1] = area;
1818 lg->port_id[2] = domain;
1819 lg->vp_index = vha->vp_idx;
1821 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
1822 if (rval != QLA_SUCCESS) {
1823 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1824 "(%x).\n", __func__, vha->host_no, rval));
1825 } else if (lg->entry_status != 0) {
1826 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1827 "-- error status (%x).\n", __func__, vha->host_no,
1829 rval = QLA_FUNCTION_FAILED;
1830 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1831 DEBUG2_3_11(printk("%s(%ld %d): failed to complete IOCB "
1832 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1833 vha->host_no, vha->vp_idx, le16_to_cpu(lg->comp_status),
1834 le32_to_cpu(lg->io_parameter[0]),
1835 le32_to_cpu(lg->io_parameter[1])));
1838 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1841 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1847 * qla2x00_fabric_logout
1848 * Issue logout fabric port mailbox command.
1851 * ha = adapter block pointer.
1852 * loop_id = device loop ID.
1853 * TARGET_QUEUE_LOCK must be released.
1854 * ADAPTER_STATE_LOCK must be released.
1857 * qla2x00 local function return status code.
1863 qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1864 uint8_t area, uint8_t al_pa)
1868 mbx_cmd_t *mcp = &mc;
1870 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1873 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1874 mcp->out_mb = MBX_1|MBX_0;
1875 if (HAS_EXTENDED_IDS(vha->hw)) {
1876 mcp->mb[1] = loop_id;
1878 mcp->out_mb |= MBX_10;
1880 mcp->mb[1] = loop_id << 8;
1883 mcp->in_mb = MBX_1|MBX_0;
1884 mcp->tov = MBX_TOV_SECONDS;
1886 rval = qla2x00_mailbox_command(vha, mcp);
1888 if (rval != QLA_SUCCESS) {
1890 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1891 "mbx1=%x.\n", vha->host_no, rval, mcp->mb[1]));
1894 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1902 * qla2x00_full_login_lip
1903 * Issue full login LIP mailbox command.
1906 * ha = adapter block pointer.
1907 * TARGET_QUEUE_LOCK must be released.
1908 * ADAPTER_STATE_LOCK must be released.
1911 * qla2x00 local function return status code.
1917 qla2x00_full_login_lip(scsi_qla_host_t *vha)
1921 mbx_cmd_t *mcp = &mc;
1923 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1926 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1927 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
1930 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1932 mcp->tov = MBX_TOV_SECONDS;
1934 rval = qla2x00_mailbox_command(vha, mcp);
1936 if (rval != QLA_SUCCESS) {
1938 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1939 vha->host_no, rval));
1942 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1950 * qla2x00_get_id_list
1953 * ha = adapter block pointer.
1956 * qla2x00 local function return status code.
1962 qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
1967 mbx_cmd_t *mcp = &mc;
1969 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1972 if (id_list == NULL)
1973 return QLA_FUNCTION_FAILED;
1975 mcp->mb[0] = MBC_GET_ID_LIST;
1976 mcp->out_mb = MBX_0;
1977 if (IS_FWI2_CAPABLE(vha->hw)) {
1978 mcp->mb[2] = MSW(id_list_dma);
1979 mcp->mb[3] = LSW(id_list_dma);
1980 mcp->mb[6] = MSW(MSD(id_list_dma));
1981 mcp->mb[7] = LSW(MSD(id_list_dma));
1983 mcp->mb[9] = vha->vp_idx;
1984 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
1986 mcp->mb[1] = MSW(id_list_dma);
1987 mcp->mb[2] = LSW(id_list_dma);
1988 mcp->mb[3] = MSW(MSD(id_list_dma));
1989 mcp->mb[6] = LSW(MSD(id_list_dma));
1990 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1992 mcp->in_mb = MBX_1|MBX_0;
1993 mcp->tov = MBX_TOV_SECONDS;
1995 rval = qla2x00_mailbox_command(vha, mcp);
1997 if (rval != QLA_SUCCESS) {
1999 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
2000 vha->host_no, rval));
2002 *entries = mcp->mb[1];
2003 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
2011 * qla2x00_get_resource_cnts
2012 * Get current firmware resource counts.
2015 * ha = adapter block pointer.
2018 * qla2x00 local function return status code.
2024 qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
2025 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
2026 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports, uint16_t *max_fcfs)
2030 mbx_cmd_t *mcp = &mc;
2032 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2034 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2035 mcp->out_mb = MBX_0;
2036 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2037 if (IS_QLA81XX(vha->hw))
2038 mcp->in_mb |= MBX_12;
2039 mcp->tov = MBX_TOV_SECONDS;
2041 rval = qla2x00_mailbox_command(vha, mcp);
2043 if (rval != QLA_SUCCESS) {
2045 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
2046 vha->host_no, mcp->mb[0]));
2048 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
2049 "mb7=%x mb10=%x mb11=%x mb12=%x.\n", __func__,
2050 vha->host_no, mcp->mb[1], mcp->mb[2], mcp->mb[3],
2051 mcp->mb[6], mcp->mb[7], mcp->mb[10], mcp->mb[11],
2055 *cur_xchg_cnt = mcp->mb[3];
2057 *orig_xchg_cnt = mcp->mb[6];
2059 *cur_iocb_cnt = mcp->mb[7];
2061 *orig_iocb_cnt = mcp->mb[10];
2062 if (vha->hw->flags.npiv_supported && max_npiv_vports)
2063 *max_npiv_vports = mcp->mb[11];
2064 if (IS_QLA81XX(vha->hw) && max_fcfs)
2065 *max_fcfs = mcp->mb[12];
2071 #if defined(QL_DEBUG_LEVEL_3)
2073 * qla2x00_get_fcal_position_map
2074 * Get FCAL (LILP) position map using mailbox command
2077 * ha = adapter state pointer.
2078 * pos_map = buffer pointer (can be NULL).
2081 * qla2x00 local function return status code.
2087 qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
2091 mbx_cmd_t *mcp = &mc;
2093 dma_addr_t pmap_dma;
2094 struct qla_hw_data *ha = vha->hw;
2096 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
2098 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
2099 __func__, vha->host_no));
2100 return QLA_MEMORY_ALLOC_FAILED;
2102 memset(pmap, 0, FCAL_MAP_SIZE);
2104 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2105 mcp->mb[2] = MSW(pmap_dma);
2106 mcp->mb[3] = LSW(pmap_dma);
2107 mcp->mb[6] = MSW(MSD(pmap_dma));
2108 mcp->mb[7] = LSW(MSD(pmap_dma));
2109 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2110 mcp->in_mb = MBX_1|MBX_0;
2111 mcp->buf_size = FCAL_MAP_SIZE;
2112 mcp->flags = MBX_DMA_IN;
2113 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2114 rval = qla2x00_mailbox_command(vha, mcp);
2116 if (rval == QLA_SUCCESS) {
2117 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2118 "size (%x)\n", __func__, vha->host_no, mcp->mb[0],
2119 mcp->mb[1], (unsigned)pmap[0]));
2120 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2123 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2125 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2127 if (rval != QLA_SUCCESS) {
2128 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2129 vha->host_no, rval));
2131 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2139 * qla2x00_get_link_status
2142 * ha = adapter block pointer.
2143 * loop_id = device loop ID.
2144 * ret_buf = pointer to link status return buffer.
2148 * BIT_0 = mem alloc error.
2149 * BIT_1 = mailbox error.
2152 qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
2153 struct link_statistics *stats, dma_addr_t stats_dma)
2157 mbx_cmd_t *mcp = &mc;
2158 uint32_t *siter, *diter, dwords;
2159 struct qla_hw_data *ha = vha->hw;
2161 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2163 mcp->mb[0] = MBC_GET_LINK_STATUS;
2164 mcp->mb[2] = MSW(stats_dma);
2165 mcp->mb[3] = LSW(stats_dma);
2166 mcp->mb[6] = MSW(MSD(stats_dma));
2167 mcp->mb[7] = LSW(MSD(stats_dma));
2168 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2170 if (IS_FWI2_CAPABLE(ha)) {
2171 mcp->mb[1] = loop_id;
2174 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2175 mcp->in_mb |= MBX_1;
2176 } else if (HAS_EXTENDED_IDS(ha)) {
2177 mcp->mb[1] = loop_id;
2179 mcp->out_mb |= MBX_10|MBX_1;
2181 mcp->mb[1] = loop_id << 8;
2182 mcp->out_mb |= MBX_1;
2184 mcp->tov = MBX_TOV_SECONDS;
2185 mcp->flags = IOCTL_CMD;
2186 rval = qla2x00_mailbox_command(vha, mcp);
2188 if (rval == QLA_SUCCESS) {
2189 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2190 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2191 __func__, vha->host_no, mcp->mb[0]));
2192 rval = QLA_FUNCTION_FAILED;
2194 /* Copy over data -- firmware data is LE. */
2195 dwords = offsetof(struct link_statistics, unused1) / 4;
2196 siter = diter = &stats->link_fail_cnt;
2198 *diter++ = le32_to_cpu(*siter++);
2202 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2203 vha->host_no, rval));
2210 qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
2211 dma_addr_t stats_dma)
2215 mbx_cmd_t *mcp = &mc;
2216 uint32_t *siter, *diter, dwords;
2218 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2220 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2221 mcp->mb[2] = MSW(stats_dma);
2222 mcp->mb[3] = LSW(stats_dma);
2223 mcp->mb[6] = MSW(MSD(stats_dma));
2224 mcp->mb[7] = LSW(MSD(stats_dma));
2225 mcp->mb[8] = sizeof(struct link_statistics) / 4;
2226 mcp->mb[9] = vha->vp_idx;
2228 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2229 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2230 mcp->tov = MBX_TOV_SECONDS;
2231 mcp->flags = IOCTL_CMD;
2232 rval = qla2x00_mailbox_command(vha, mcp);
2234 if (rval == QLA_SUCCESS) {
2235 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2236 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2237 __func__, vha->host_no, mcp->mb[0]));
2238 rval = QLA_FUNCTION_FAILED;
2240 /* Copy over data -- firmware data is LE. */
2241 dwords = sizeof(struct link_statistics) / 4;
2242 siter = diter = &stats->link_fail_cnt;
2244 *diter++ = le32_to_cpu(*siter++);
2248 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2249 vha->host_no, rval));
2256 qla24xx_abort_command(srb_t *sp)
2259 unsigned long flags = 0;
2261 struct abort_entry_24xx *abt;
2264 fc_port_t *fcport = sp->fcport;
2265 struct scsi_qla_host *vha = fcport->vha;
2266 struct qla_hw_data *ha = vha->hw;
2267 struct req_que *req = vha->req;
2269 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2271 spin_lock_irqsave(&ha->hardware_lock, flags);
2272 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2273 if (req->outstanding_cmds[handle] == sp)
2276 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2277 if (handle == MAX_OUTSTANDING_COMMANDS) {
2278 /* Command not found. */
2279 return QLA_FUNCTION_FAILED;
2282 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2284 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2285 __func__, vha->host_no));
2286 return QLA_MEMORY_ALLOC_FAILED;
2288 memset(abt, 0, sizeof(struct abort_entry_24xx));
2290 abt->entry_type = ABORT_IOCB_TYPE;
2291 abt->entry_count = 1;
2292 abt->handle = MAKE_HANDLE(req->id, abt->handle);
2293 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2294 abt->handle_to_abort = handle;
2295 abt->port_id[0] = fcport->d_id.b.al_pa;
2296 abt->port_id[1] = fcport->d_id.b.area;
2297 abt->port_id[2] = fcport->d_id.b.domain;
2298 abt->vp_index = fcport->vp_idx;
2300 abt->req_que_no = cpu_to_le16(req->id);
2302 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
2303 if (rval != QLA_SUCCESS) {
2304 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2305 __func__, vha->host_no, rval));
2306 } else if (abt->entry_status != 0) {
2307 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2308 "-- error status (%x).\n", __func__, vha->host_no,
2309 abt->entry_status));
2310 rval = QLA_FUNCTION_FAILED;
2311 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2312 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2313 "-- completion status (%x).\n", __func__, vha->host_no,
2314 le16_to_cpu(abt->nport_handle)));
2315 rval = QLA_FUNCTION_FAILED;
2317 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2320 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2325 struct tsk_mgmt_cmd {
2327 struct tsk_mgmt_entry tsk;
2328 struct sts_entry_24xx sts;
2333 __qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
2334 unsigned int l, int tag)
2337 struct tsk_mgmt_cmd *tsk;
2338 struct sts_entry_24xx *sts;
2340 scsi_qla_host_t *vha;
2341 struct qla_hw_data *ha;
2342 struct req_que *req;
2343 struct rsp_que *rsp;
2345 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
2350 if (ha->flags.cpu_affinity_enabled)
2351 rsp = ha->rsp_q_map[tag + 1];
2354 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
2356 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2357 "IOCB.\n", __func__, vha->host_no));
2358 return QLA_MEMORY_ALLOC_FAILED;
2360 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2362 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2363 tsk->p.tsk.entry_count = 1;
2364 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
2365 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2366 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
2367 tsk->p.tsk.control_flags = cpu_to_le32(type);
2368 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2369 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2370 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2371 tsk->p.tsk.vp_index = fcport->vp_idx;
2372 if (type == TCF_LUN_RESET) {
2373 int_to_scsilun(l, &tsk->p.tsk.lun);
2374 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2375 sizeof(tsk->p.tsk.lun));
2379 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
2380 if (rval != QLA_SUCCESS) {
2381 DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
2382 "(%x).\n", __func__, vha->host_no, name, rval));
2383 } else if (sts->entry_status != 0) {
2384 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2385 "-- error status (%x).\n", __func__, vha->host_no,
2386 sts->entry_status));
2387 rval = QLA_FUNCTION_FAILED;
2388 } else if (sts->comp_status !=
2389 __constant_cpu_to_le16(CS_COMPLETE)) {
2390 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2391 "-- completion status (%x).\n", __func__,
2392 vha->host_no, le16_to_cpu(sts->comp_status)));
2393 rval = QLA_FUNCTION_FAILED;
2394 } else if (!(le16_to_cpu(sts->scsi_status) &
2395 SS_RESPONSE_INFO_LEN_VALID)) {
2396 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2397 "-- no response info (%x).\n", __func__, vha->host_no,
2398 le16_to_cpu(sts->scsi_status)));
2399 rval = QLA_FUNCTION_FAILED;
2400 } else if (le32_to_cpu(sts->rsp_data_len) < 4) {
2401 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2402 "-- not enough response info (%d).\n", __func__,
2403 vha->host_no, le32_to_cpu(sts->rsp_data_len)));
2404 rval = QLA_FUNCTION_FAILED;
2405 } else if (sts->data[3]) {
2406 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2407 "-- response (%x).\n", __func__,
2408 vha->host_no, sts->data[3]));
2409 rval = QLA_FUNCTION_FAILED;
2412 /* Issue marker IOCB. */
2413 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
2414 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2415 if (rval2 != QLA_SUCCESS) {
2416 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2417 "(%x).\n", __func__, vha->host_no, rval2));
2419 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2422 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
2428 qla24xx_abort_target(struct fc_port *fcport, unsigned int l, int tag)
2430 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
2434 qla24xx_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
2436 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
2440 qla2x00_system_error(scsi_qla_host_t *vha)
2444 mbx_cmd_t *mcp = &mc;
2445 struct qla_hw_data *ha = vha->hw;
2447 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
2448 return QLA_FUNCTION_FAILED;
2450 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2452 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2453 mcp->out_mb = MBX_0;
2457 rval = qla2x00_mailbox_command(vha, mcp);
2459 if (rval != QLA_SUCCESS) {
2460 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2461 vha->host_no, rval));
2463 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2470 * qla2x00_set_serdes_params() -
2476 qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
2477 uint16_t sw_em_2g, uint16_t sw_em_4g)
2481 mbx_cmd_t *mcp = &mc;
2483 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2485 mcp->mb[0] = MBC_SERDES_PARAMS;
2487 mcp->mb[2] = sw_em_1g | BIT_15;
2488 mcp->mb[3] = sw_em_2g | BIT_15;
2489 mcp->mb[4] = sw_em_4g | BIT_15;
2490 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2492 mcp->tov = MBX_TOV_SECONDS;
2494 rval = qla2x00_mailbox_command(vha, mcp);
2496 if (rval != QLA_SUCCESS) {
2498 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2499 vha->host_no, rval, mcp->mb[0]));
2502 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2509 qla2x00_stop_firmware(scsi_qla_host_t *vha)
2513 mbx_cmd_t *mcp = &mc;
2515 if (!IS_FWI2_CAPABLE(vha->hw))
2516 return QLA_FUNCTION_FAILED;
2518 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2520 mcp->mb[0] = MBC_STOP_FIRMWARE;
2521 mcp->out_mb = MBX_0;
2525 rval = qla2x00_mailbox_command(vha, mcp);
2527 if (rval != QLA_SUCCESS) {
2528 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2529 vha->host_no, rval));
2530 if (mcp->mb[0] == MBS_INVALID_COMMAND)
2531 rval = QLA_INVALID_COMMAND;
2533 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2540 qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
2545 mbx_cmd_t *mcp = &mc;
2547 if (!IS_FWI2_CAPABLE(vha->hw))
2548 return QLA_FUNCTION_FAILED;
2550 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2551 return QLA_FUNCTION_FAILED;
2553 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2555 mcp->mb[0] = MBC_TRACE_CONTROL;
2556 mcp->mb[1] = TC_EFT_ENABLE;
2557 mcp->mb[2] = LSW(eft_dma);
2558 mcp->mb[3] = MSW(eft_dma);
2559 mcp->mb[4] = LSW(MSD(eft_dma));
2560 mcp->mb[5] = MSW(MSD(eft_dma));
2561 mcp->mb[6] = buffers;
2562 mcp->mb[7] = TC_AEN_DISABLE;
2563 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2564 mcp->in_mb = MBX_1|MBX_0;
2565 mcp->tov = MBX_TOV_SECONDS;
2567 rval = qla2x00_mailbox_command(vha, mcp);
2568 if (rval != QLA_SUCCESS) {
2569 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2570 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2572 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2579 qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
2583 mbx_cmd_t *mcp = &mc;
2585 if (!IS_FWI2_CAPABLE(vha->hw))
2586 return QLA_FUNCTION_FAILED;
2588 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2589 return QLA_FUNCTION_FAILED;
2591 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2593 mcp->mb[0] = MBC_TRACE_CONTROL;
2594 mcp->mb[1] = TC_EFT_DISABLE;
2595 mcp->out_mb = MBX_1|MBX_0;
2596 mcp->in_mb = MBX_1|MBX_0;
2597 mcp->tov = MBX_TOV_SECONDS;
2599 rval = qla2x00_mailbox_command(vha, mcp);
2600 if (rval != QLA_SUCCESS) {
2601 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2602 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2604 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2611 qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
2612 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2616 mbx_cmd_t *mcp = &mc;
2618 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw))
2619 return QLA_FUNCTION_FAILED;
2621 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2622 return QLA_FUNCTION_FAILED;
2624 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2626 mcp->mb[0] = MBC_TRACE_CONTROL;
2627 mcp->mb[1] = TC_FCE_ENABLE;
2628 mcp->mb[2] = LSW(fce_dma);
2629 mcp->mb[3] = MSW(fce_dma);
2630 mcp->mb[4] = LSW(MSD(fce_dma));
2631 mcp->mb[5] = MSW(MSD(fce_dma));
2632 mcp->mb[6] = buffers;
2633 mcp->mb[7] = TC_AEN_DISABLE;
2635 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2636 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2637 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2639 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2640 mcp->tov = MBX_TOV_SECONDS;
2642 rval = qla2x00_mailbox_command(vha, mcp);
2643 if (rval != QLA_SUCCESS) {
2644 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2645 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2647 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2650 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2659 qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
2663 mbx_cmd_t *mcp = &mc;
2665 if (!IS_FWI2_CAPABLE(vha->hw))
2666 return QLA_FUNCTION_FAILED;
2668 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2669 return QLA_FUNCTION_FAILED;
2671 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2673 mcp->mb[0] = MBC_TRACE_CONTROL;
2674 mcp->mb[1] = TC_FCE_DISABLE;
2675 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
2676 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2677 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2679 mcp->tov = MBX_TOV_SECONDS;
2681 rval = qla2x00_mailbox_command(vha, mcp);
2682 if (rval != QLA_SUCCESS) {
2683 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2684 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2686 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2689 *wr = (uint64_t) mcp->mb[5] << 48 |
2690 (uint64_t) mcp->mb[4] << 32 |
2691 (uint64_t) mcp->mb[3] << 16 |
2692 (uint64_t) mcp->mb[2];
2694 *rd = (uint64_t) mcp->mb[9] << 48 |
2695 (uint64_t) mcp->mb[8] << 32 |
2696 (uint64_t) mcp->mb[7] << 16 |
2697 (uint64_t) mcp->mb[6];
2704 qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint16_t addr,
2705 uint16_t off, uint16_t count)
2709 mbx_cmd_t *mcp = &mc;
2711 if (!IS_FWI2_CAPABLE(vha->hw))
2712 return QLA_FUNCTION_FAILED;
2714 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2716 mcp->mb[0] = MBC_READ_SFP;
2718 mcp->mb[2] = MSW(sfp_dma);
2719 mcp->mb[3] = LSW(sfp_dma);
2720 mcp->mb[6] = MSW(MSD(sfp_dma));
2721 mcp->mb[7] = LSW(MSD(sfp_dma));
2725 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2727 mcp->tov = MBX_TOV_SECONDS;
2729 rval = qla2x00_mailbox_command(vha, mcp);
2731 if (rval != QLA_SUCCESS) {
2732 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2733 vha->host_no, rval, mcp->mb[0]));
2735 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2742 qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
2743 uint16_t port_speed, uint16_t *mb)
2747 mbx_cmd_t *mcp = &mc;
2749 if (!IS_IIDMA_CAPABLE(vha->hw))
2750 return QLA_FUNCTION_FAILED;
2752 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2754 mcp->mb[0] = MBC_PORT_PARAMS;
2755 mcp->mb[1] = loop_id;
2757 if (IS_QLA81XX(vha->hw))
2758 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
2760 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2761 mcp->mb[9] = vha->vp_idx;
2762 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
2763 mcp->in_mb = MBX_3|MBX_1|MBX_0;
2764 mcp->tov = MBX_TOV_SECONDS;
2766 rval = qla2x00_mailbox_command(vha, mcp);
2768 /* Return mailbox statuses. */
2775 if (rval != QLA_SUCCESS) {
2776 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2777 vha->host_no, rval));
2779 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2786 qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
2787 struct vp_rpt_id_entry_24xx *rptid_entry)
2790 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
2791 struct qla_hw_data *ha = vha->hw;
2792 scsi_qla_host_t *vp;
2793 scsi_qla_host_t *tvp;
2795 if (rptid_entry->entry_status != 0)
2798 if (rptid_entry->format == 0) {
2799 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
2800 " number of VPs acquired %d\n", __func__, vha->host_no,
2801 MSB(le16_to_cpu(rptid_entry->vp_count)),
2802 LSB(le16_to_cpu(rptid_entry->vp_count))));
2803 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2804 rptid_entry->port_id[2], rptid_entry->port_id[1],
2805 rptid_entry->port_id[0]));
2806 } else if (rptid_entry->format == 1) {
2808 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2810 "with port id %02x%02x%02x\n", __func__, vha->host_no,
2812 rptid_entry->port_id[2], rptid_entry->port_id[1],
2813 rptid_entry->port_id[0]));
2816 if (vp_idx == 0 && (MSB(stat) != 1))
2819 if (MSB(stat) == 1) {
2820 DEBUG2(printk("scsi(%ld): Could not acquire ID for "
2821 "VP[%d].\n", vha->host_no, vp_idx));
2825 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
2826 if (vp_idx == vp->vp_idx)
2831 vp->d_id.b.domain = rptid_entry->port_id[2];
2832 vp->d_id.b.area = rptid_entry->port_id[1];
2833 vp->d_id.b.al_pa = rptid_entry->port_id[0];
2836 * Cannot configure here as we are still sitting on the
2837 * response queue. Handle it in dpc context.
2839 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
2842 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
2843 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
2844 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
2845 qla2xxx_wake_dpc(vha);
2850 * qla24xx_modify_vp_config
2851 * Change VP configuration for vha
2854 * vha = adapter block pointer.
2857 * qla2xxx local function return status code.
2863 qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2866 struct vp_config_entry_24xx *vpmod;
2867 dma_addr_t vpmod_dma;
2868 struct qla_hw_data *ha = vha->hw;
2869 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2871 /* This can be called by the parent */
2873 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
2875 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
2876 "IOCB.\n", __func__, vha->host_no));
2877 return QLA_MEMORY_ALLOC_FAILED;
2880 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2881 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2882 vpmod->entry_count = 1;
2883 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2884 vpmod->vp_count = 1;
2885 vpmod->vp_index1 = vha->vp_idx;
2886 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2887 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2888 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2889 vpmod->entry_count = 1;
2891 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
2892 if (rval != QLA_SUCCESS) {
2893 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
2894 "(%x).\n", __func__, base_vha->host_no, rval));
2895 } else if (vpmod->comp_status != 0) {
2896 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2897 "-- error status (%x).\n", __func__, base_vha->host_no,
2898 vpmod->comp_status));
2899 rval = QLA_FUNCTION_FAILED;
2900 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2901 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2902 "-- completion status (%x).\n", __func__, base_vha->host_no,
2903 le16_to_cpu(vpmod->comp_status)));
2904 rval = QLA_FUNCTION_FAILED;
2907 DEBUG11(printk("%s(%ld): done.\n", __func__,
2908 base_vha->host_no));
2909 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2911 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
2917 * qla24xx_control_vp
2918 * Enable a virtual port for given host
2921 * ha = adapter block pointer.
2922 * vhba = virtual adapter (unused)
2923 * index = index number for enabled VP
2926 * qla2xxx local function return status code.
2932 qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2936 struct vp_ctrl_entry_24xx *vce;
2938 struct qla_hw_data *ha = vha->hw;
2939 int vp_index = vha->vp_idx;
2940 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2942 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
2943 vha->host_no, vp_index));
2945 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
2946 return QLA_PARAMETER_ERROR;
2948 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2950 DEBUG2_3(printk("%s(%ld): "
2951 "failed to allocate VP Control IOCB.\n", __func__,
2952 base_vha->host_no));
2953 return QLA_MEMORY_ALLOC_FAILED;
2955 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2957 vce->entry_type = VP_CTRL_IOCB_TYPE;
2958 vce->entry_count = 1;
2959 vce->command = cpu_to_le16(cmd);
2960 vce->vp_count = __constant_cpu_to_le16(1);
2962 /* index map in firmware starts with 1; decrement index
2963 * this is ok as we never use index 0
2965 map = (vp_index - 1) / 8;
2966 pos = (vp_index - 1) & 7;
2967 mutex_lock(&ha->vport_lock);
2968 vce->vp_idx_map[map] |= 1 << pos;
2969 mutex_unlock(&ha->vport_lock);
2971 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
2972 if (rval != QLA_SUCCESS) {
2973 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
2974 "(%x).\n", __func__, base_vha->host_no, rval));
2975 printk("%s(%ld): failed to issue VP control IOCB"
2976 "(%x).\n", __func__, base_vha->host_no, rval);
2977 } else if (vce->entry_status != 0) {
2978 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2979 "-- error status (%x).\n", __func__, base_vha->host_no,
2980 vce->entry_status));
2981 printk("%s(%ld): failed to complete IOCB "
2982 "-- error status (%x).\n", __func__, base_vha->host_no,
2984 rval = QLA_FUNCTION_FAILED;
2985 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2986 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2987 "-- completion status (%x).\n", __func__, base_vha->host_no,
2988 le16_to_cpu(vce->comp_status)));
2989 printk("%s(%ld): failed to complete IOCB "
2990 "-- completion status (%x).\n", __func__, base_vha->host_no,
2991 le16_to_cpu(vce->comp_status));
2992 rval = QLA_FUNCTION_FAILED;
2994 DEBUG2(printk("%s(%ld): done.\n", __func__, base_vha->host_no));
2997 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
3003 * qla2x00_send_change_request
3004 * Receive or disable RSCN request from fabric controller
3007 * ha = adapter block pointer
3008 * format = registration format:
3010 * 1 - Fabric detected registration
3011 * 2 - N_port detected registration
3012 * 3 - Full registration
3013 * FF - clear registration
3014 * vp_idx = Virtual port index
3017 * qla2x00 local function return status code.
3024 qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
3029 mbx_cmd_t *mcp = &mc;
3032 * This command is implicitly executed by firmware during login for the
3036 return QLA_FUNCTION_FAILED;
3038 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
3039 mcp->mb[1] = format;
3040 mcp->mb[9] = vp_idx;
3041 mcp->out_mb = MBX_9|MBX_1|MBX_0;
3042 mcp->in_mb = MBX_0|MBX_1;
3043 mcp->tov = MBX_TOV_SECONDS;
3045 rval = qla2x00_mailbox_command(vha, mcp);
3047 if (rval == QLA_SUCCESS) {
3048 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
3058 qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
3063 mbx_cmd_t *mcp = &mc;
3065 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3067 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
3068 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3069 mcp->mb[8] = MSW(addr);
3070 mcp->out_mb = MBX_8|MBX_0;
3072 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3073 mcp->out_mb = MBX_0;
3075 mcp->mb[1] = LSW(addr);
3076 mcp->mb[2] = MSW(req_dma);
3077 mcp->mb[3] = LSW(req_dma);
3078 mcp->mb[6] = MSW(MSD(req_dma));
3079 mcp->mb[7] = LSW(MSD(req_dma));
3080 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
3081 if (IS_FWI2_CAPABLE(vha->hw)) {
3082 mcp->mb[4] = MSW(size);
3083 mcp->mb[5] = LSW(size);
3084 mcp->out_mb |= MBX_5|MBX_4;
3086 mcp->mb[4] = LSW(size);
3087 mcp->out_mb |= MBX_4;
3091 mcp->tov = MBX_TOV_SECONDS;
3093 rval = qla2x00_mailbox_command(vha, mcp);
3095 if (rval != QLA_SUCCESS) {
3096 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3097 vha->host_no, rval, mcp->mb[0]));
3099 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3105 /* 84XX Support **************************************************************/
3107 struct cs84xx_mgmt_cmd {
3109 struct verify_chip_entry_84xx req;
3110 struct verify_chip_rsp_84xx rsp;
3115 qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
3118 struct cs84xx_mgmt_cmd *mn;
3121 unsigned long flags;
3122 struct qla_hw_data *ha = vha->hw;
3124 DEBUG16(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3126 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
3128 DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX "
3129 "IOCB.\n", __func__, vha->host_no));
3130 return QLA_MEMORY_ALLOC_FAILED;
3134 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
3135 /* Diagnostic firmware? */
3136 /* options |= MENLO_DIAG_FW; */
3137 /* We update the firmware with only one data sequence. */
3138 options |= VCO_END_OF_DATA;
3142 memset(mn, 0, sizeof(*mn));
3143 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
3144 mn->p.req.entry_count = 1;
3145 mn->p.req.options = cpu_to_le16(options);
3147 DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__,
3149 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3152 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
3153 if (rval != QLA_SUCCESS) {
3154 DEBUG2_16(printk("%s(%ld): failed to issue Verify "
3155 "IOCB (%x).\n", __func__, vha->host_no, rval));
3159 DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__,
3161 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3164 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3165 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3166 le16_to_cpu(mn->p.rsp.failure_code) : 0;
3167 DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__,
3168 vha->host_no, status[0], status[1]));
3170 if (status[0] != CS_COMPLETE) {
3171 rval = QLA_FUNCTION_FAILED;
3172 if (!(options & VCO_DONT_UPDATE_FW)) {
3173 DEBUG2_16(printk("%s(%ld): Firmware update "
3174 "failed. Retrying without update "
3175 "firmware.\n", __func__, vha->host_no));
3176 options |= VCO_DONT_UPDATE_FW;
3177 options &= ~VCO_FORCE_UPDATE;
3181 DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n",
3182 __func__, vha->host_no,
3183 le32_to_cpu(mn->p.rsp.fw_ver)));
3185 /* NOTE: we only update OP firmware. */
3186 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3187 ha->cs84xx->op_fw_version =
3188 le32_to_cpu(mn->p.rsp.fw_ver);
3189 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3195 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3197 if (rval != QLA_SUCCESS) {
3198 DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__,
3199 vha->host_no, rval));
3201 DEBUG16(printk("%s(%ld): done.\n", __func__, vha->host_no));
3208 qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
3211 unsigned long flags;
3213 mbx_cmd_t *mcp = &mc;
3214 struct device_reg_25xxmq __iomem *reg;
3215 struct qla_hw_data *ha = vha->hw;
3217 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
3218 mcp->mb[1] = req->options;
3219 mcp->mb[2] = MSW(LSD(req->dma));
3220 mcp->mb[3] = LSW(LSD(req->dma));
3221 mcp->mb[6] = MSW(MSD(req->dma));
3222 mcp->mb[7] = LSW(MSD(req->dma));
3223 mcp->mb[5] = req->length;
3225 mcp->mb[10] = req->rsp->id;
3226 mcp->mb[12] = req->qos;
3227 mcp->mb[11] = req->vp_idx;
3228 mcp->mb[13] = req->rid;
3230 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3231 QLA_QUE_PAGE * req->id);
3233 mcp->mb[4] = req->id;
3234 /* que in ptr index */
3236 /* que out ptr index */
3238 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
3239 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3241 mcp->flags = MBX_DMA_OUT;
3244 spin_lock_irqsave(&ha->hardware_lock, flags);
3245 if (!(req->options & BIT_0)) {
3246 WRT_REG_DWORD(®->req_q_in, 0);
3247 WRT_REG_DWORD(®->req_q_out, 0);
3249 req->req_q_in = ®->req_q_in;
3250 req->req_q_out = ®->req_q_out;
3251 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3253 rval = qla2x00_mailbox_command(vha, mcp);
3254 if (rval != QLA_SUCCESS)
3255 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x mb0=%x.\n",
3256 __func__, vha->host_no, rval, mcp->mb[0]));
3261 qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
3264 unsigned long flags;
3266 mbx_cmd_t *mcp = &mc;
3267 struct device_reg_25xxmq __iomem *reg;
3268 struct qla_hw_data *ha = vha->hw;
3270 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
3271 mcp->mb[1] = rsp->options;
3272 mcp->mb[2] = MSW(LSD(rsp->dma));
3273 mcp->mb[3] = LSW(LSD(rsp->dma));
3274 mcp->mb[6] = MSW(MSD(rsp->dma));
3275 mcp->mb[7] = LSW(MSD(rsp->dma));
3276 mcp->mb[5] = rsp->length;
3277 mcp->mb[14] = rsp->msix->entry;
3278 mcp->mb[13] = rsp->rid;
3280 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3281 QLA_QUE_PAGE * rsp->id);
3283 mcp->mb[4] = rsp->id;
3284 /* que in ptr index */
3286 /* que out ptr index */
3288 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
3289 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3291 mcp->flags = MBX_DMA_OUT;
3294 spin_lock_irqsave(&ha->hardware_lock, flags);
3295 if (!(rsp->options & BIT_0)) {
3296 WRT_REG_DWORD(®->rsp_q_out, 0);
3297 WRT_REG_DWORD(®->rsp_q_in, 0);
3300 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3302 rval = qla2x00_mailbox_command(vha, mcp);
3303 if (rval != QLA_SUCCESS)
3304 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x "
3305 "mb0=%x.\n", __func__,
3306 vha->host_no, rval, mcp->mb[0]));
3311 qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
3315 mbx_cmd_t *mcp = &mc;
3317 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3319 mcp->mb[0] = MBC_IDC_ACK;
3320 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
3321 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3323 mcp->tov = MBX_TOV_SECONDS;
3325 rval = qla2x00_mailbox_command(vha, mcp);
3327 if (rval != QLA_SUCCESS) {
3328 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3329 vha->host_no, rval, mcp->mb[0]));
3331 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3338 qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
3342 mbx_cmd_t *mcp = &mc;
3344 if (!IS_QLA81XX(vha->hw))
3345 return QLA_FUNCTION_FAILED;
3347 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3349 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3350 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
3351 mcp->out_mb = MBX_1|MBX_0;
3352 mcp->in_mb = MBX_1|MBX_0;
3353 mcp->tov = MBX_TOV_SECONDS;
3355 rval = qla2x00_mailbox_command(vha, mcp);
3357 if (rval != QLA_SUCCESS) {
3358 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
3359 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3361 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3362 *sector_size = mcp->mb[1];
3369 qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
3373 mbx_cmd_t *mcp = &mc;
3375 if (!IS_QLA81XX(vha->hw))
3376 return QLA_FUNCTION_FAILED;
3378 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3380 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3381 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
3382 FAC_OPT_CMD_WRITE_PROTECT;
3383 mcp->out_mb = MBX_1|MBX_0;
3384 mcp->in_mb = MBX_1|MBX_0;
3385 mcp->tov = MBX_TOV_SECONDS;
3387 rval = qla2x00_mailbox_command(vha, mcp);
3389 if (rval != QLA_SUCCESS) {
3390 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
3391 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3393 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3400 qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
3404 mbx_cmd_t *mcp = &mc;
3406 if (!IS_QLA81XX(vha->hw))
3407 return QLA_FUNCTION_FAILED;
3409 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3411 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3412 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
3413 mcp->mb[2] = LSW(start);
3414 mcp->mb[3] = MSW(start);
3415 mcp->mb[4] = LSW(finish);
3416 mcp->mb[5] = MSW(finish);
3417 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3418 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3419 mcp->tov = MBX_TOV_SECONDS;
3421 rval = qla2x00_mailbox_command(vha, mcp);
3423 if (rval != QLA_SUCCESS) {
3424 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
3425 "mb[2]=%x.\n", __func__, vha->host_no, rval, mcp->mb[0],
3426 mcp->mb[1], mcp->mb[2]));
3428 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3435 qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
3439 mbx_cmd_t *mcp = &mc;
3441 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3443 mcp->mb[0] = MBC_RESTART_MPI_FW;
3444 mcp->out_mb = MBX_0;
3445 mcp->in_mb = MBX_0|MBX_1;
3446 mcp->tov = MBX_TOV_SECONDS;
3448 rval = qla2x00_mailbox_command(vha, mcp);
3450 if (rval != QLA_SUCCESS) {
3451 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x mb[1]=0x%x.\n",
3452 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3454 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3461 qla2x00_read_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
3462 dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
3466 mbx_cmd_t *mcp = &mc;
3468 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3470 mcp->mb[0] = MBC_READ_SFP;
3472 mcp->mb[2] = MSW(sfp_dma);
3473 mcp->mb[3] = LSW(sfp_dma);
3474 mcp->mb[6] = MSW(MSD(sfp_dma));
3475 mcp->mb[7] = LSW(MSD(sfp_dma));
3479 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3481 mcp->tov = MBX_TOV_SECONDS;
3483 rval = qla2x00_mailbox_command(vha, mcp);
3489 if (rval != QLA_SUCCESS) {
3490 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3491 vha->host_no, rval, mcp->mb[0]));
3493 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3500 qla2x00_write_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
3501 dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
3505 mbx_cmd_t *mcp = &mc;
3507 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3513 mcp->mb[0] = MBC_WRITE_SFP;
3515 mcp->mb[2] = MSW(sfp_dma);
3516 mcp->mb[3] = LSW(sfp_dma);
3517 mcp->mb[6] = MSW(MSD(sfp_dma));
3518 mcp->mb[7] = LSW(MSD(sfp_dma));
3522 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3524 mcp->tov = MBX_TOV_SECONDS;
3526 rval = qla2x00_mailbox_command(vha, mcp);
3528 if (rval != QLA_SUCCESS) {
3529 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3530 vha->host_no, rval, mcp->mb[0]));
3532 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3539 qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
3540 uint16_t size_in_bytes, uint16_t *actual_size)
3544 mbx_cmd_t *mcp = &mc;
3546 if (!IS_QLA81XX(vha->hw))
3547 return QLA_FUNCTION_FAILED;
3549 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3551 mcp->mb[0] = MBC_GET_XGMAC_STATS;
3552 mcp->mb[2] = MSW(stats_dma);
3553 mcp->mb[3] = LSW(stats_dma);
3554 mcp->mb[6] = MSW(MSD(stats_dma));
3555 mcp->mb[7] = LSW(MSD(stats_dma));
3556 mcp->mb[8] = size_in_bytes >> 2;
3557 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
3558 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3559 mcp->tov = MBX_TOV_SECONDS;
3561 rval = qla2x00_mailbox_command(vha, mcp);
3563 if (rval != QLA_SUCCESS) {
3564 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x "
3565 "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval,
3566 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
3568 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3570 *actual_size = mcp->mb[2] << 2;
3577 qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
3582 mbx_cmd_t *mcp = &mc;
3584 if (!IS_QLA81XX(vha->hw))
3585 return QLA_FUNCTION_FAILED;
3587 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3589 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
3591 mcp->mb[2] = MSW(tlv_dma);
3592 mcp->mb[3] = LSW(tlv_dma);
3593 mcp->mb[6] = MSW(MSD(tlv_dma));
3594 mcp->mb[7] = LSW(MSD(tlv_dma));
3596 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3597 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3598 mcp->tov = MBX_TOV_SECONDS;
3600 rval = qla2x00_mailbox_command(vha, mcp);
3602 if (rval != QLA_SUCCESS) {
3603 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x "
3604 "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval,
3605 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
3607 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3614 qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
3618 mbx_cmd_t *mcp = &mc;
3620 if (!IS_FWI2_CAPABLE(vha->hw))
3621 return QLA_FUNCTION_FAILED;
3623 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3625 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
3626 mcp->mb[1] = LSW(risc_addr);
3627 mcp->mb[8] = MSW(risc_addr);
3628 mcp->out_mb = MBX_8|MBX_1|MBX_0;
3629 mcp->in_mb = MBX_3|MBX_2|MBX_0;
3632 rval = qla2x00_mailbox_command(vha, mcp);
3633 if (rval != QLA_SUCCESS) {
3634 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3635 vha->host_no, rval, mcp->mb[0]));
3637 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3638 *data = mcp->mb[3] << 16 | mcp->mb[2];
3645 qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq, uint16_t *mresp)
3649 mbx_cmd_t *mcp = &mc;
3650 uint32_t iter_cnt = 0x1;
3652 DEBUG11(printk("scsi(%ld): entered.\n", vha->host_no));
3654 memset(mcp->mb, 0 , sizeof(mcp->mb));
3655 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
3656 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
3658 /* transfer count */
3659 mcp->mb[10] = LSW(mreq->transfer_size);
3660 mcp->mb[11] = MSW(mreq->transfer_size);
3662 /* send data address */
3663 mcp->mb[14] = LSW(mreq->send_dma);
3664 mcp->mb[15] = MSW(mreq->send_dma);
3665 mcp->mb[20] = LSW(MSD(mreq->send_dma));
3666 mcp->mb[21] = MSW(MSD(mreq->send_dma));
3668 /* recieve data address */
3669 mcp->mb[16] = LSW(mreq->rcv_dma);
3670 mcp->mb[17] = MSW(mreq->rcv_dma);
3671 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
3672 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
3674 /* Iteration count */
3675 mcp->mb[18] = LSW(iter_cnt);
3676 mcp->mb[19] = MSW(iter_cnt);
3678 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
3679 MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
3680 if (IS_QLA81XX(vha->hw))
3681 mcp->out_mb |= MBX_2;
3682 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
3684 mcp->buf_size = mreq->transfer_size;
3685 mcp->tov = MBX_TOV_SECONDS;
3686 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3688 rval = qla2x00_mailbox_command(vha, mcp);
3690 if (rval != QLA_SUCCESS) {
3691 DEBUG2(printk(KERN_WARNING
3692 "(%ld): failed=%x mb[0]=0x%x "
3693 "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,
3694 mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[18], mcp->mb[19]));
3696 DEBUG2(printk(KERN_WARNING
3697 "scsi(%ld): done.\n", vha->host_no));
3700 /* Copy mailbox information */
3701 memcpy( mresp, mcp->mb, 64);
3702 mresp[3] = mcp->mb[18];
3703 mresp[4] = mcp->mb[19];
3708 qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq, uint16_t *mresp)
3712 mbx_cmd_t *mcp = &mc;
3713 struct qla_hw_data *ha = vha->hw;
3715 DEBUG11(printk("scsi(%ld): entered.\n", vha->host_no));
3717 memset(mcp->mb, 0 , sizeof(mcp->mb));
3718 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
3719 mcp->mb[1] = mreq->options | BIT_6; /* BIT_6 specifies 64bit address */
3721 mcp->mb[1] |= BIT_15;
3722 mcp->mb[2] = IS_QLA81XX(ha) ? vha->fcoe_fcf_idx : 0;
3723 mcp->mb[16] = LSW(mreq->rcv_dma);
3724 mcp->mb[17] = MSW(mreq->rcv_dma);
3725 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
3726 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
3728 mcp->mb[10] = LSW(mreq->transfer_size);
3730 mcp->mb[14] = LSW(mreq->send_dma);
3731 mcp->mb[15] = MSW(mreq->send_dma);
3732 mcp->mb[20] = LSW(MSD(mreq->send_dma));
3733 mcp->mb[21] = MSW(MSD(mreq->send_dma));
3735 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
3736 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
3738 mcp->out_mb |= MBX_2;
3741 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha))
3742 mcp->in_mb |= MBX_1;
3744 mcp->in_mb |= MBX_3;
3746 mcp->tov = MBX_TOV_SECONDS;
3747 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3748 mcp->buf_size = mreq->transfer_size;
3750 rval = qla2x00_mailbox_command(vha, mcp);
3752 if (rval != QLA_SUCCESS) {
3753 DEBUG2(printk(KERN_WARNING
3754 "(%ld): failed=%x mb[0]=0x%x mb[1]=0x%x.\n",
3755 vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3757 DEBUG2(printk(KERN_WARNING
3758 "scsi(%ld): done.\n", vha->host_no));
3761 /* Copy mailbox information */
3762 memcpy( mresp, mcp->mb, 32);
3766 qla84xx_reset_chip(scsi_qla_host_t *ha, uint16_t enable_diagnostic,
3767 uint16_t *cmd_status)
3771 mbx_cmd_t *mcp = &mc;
3773 DEBUG16(printk("%s(%ld): enable_diag=%d entered.\n", __func__,
3774 ha->host_no, enable_diagnostic));
3776 mcp->mb[0] = MBC_ISP84XX_RESET;
3777 mcp->mb[1] = enable_diagnostic;
3778 mcp->out_mb = MBX_1|MBX_0;
3779 mcp->in_mb = MBX_1|MBX_0;
3780 mcp->tov = MBX_TOV_SECONDS;
3781 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3782 rval = qla2x00_mailbox_command(ha, mcp);
3784 /* Return mailbox statuses. */
3785 *cmd_status = mcp->mb[0];
3786 if (rval != QLA_SUCCESS)
3787 DEBUG16(printk("%s(%ld): failed=%x.\n", __func__, ha->host_no,
3790 DEBUG16(printk("%s(%ld): done.\n", __func__, ha->host_no));
3796 qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
3800 mbx_cmd_t *mcp = &mc;
3802 if (!IS_FWI2_CAPABLE(vha->hw))
3803 return QLA_FUNCTION_FAILED;
3805 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3807 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
3808 mcp->mb[1] = LSW(risc_addr);
3809 mcp->mb[2] = LSW(data);
3810 mcp->mb[3] = MSW(data);
3811 mcp->mb[8] = MSW(risc_addr);
3812 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
3816 rval = qla2x00_mailbox_command(vha, mcp);
3817 if (rval != QLA_SUCCESS) {
3818 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3819 vha->host_no, rval, mcp->mb[0]));
3821 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3828 qla2x00_get_data_rate(scsi_qla_host_t *vha)
3832 mbx_cmd_t *mcp = &mc;
3833 struct qla_hw_data *ha = vha->hw;
3835 if (!IS_FWI2_CAPABLE(ha))
3836 return QLA_FUNCTION_FAILED;
3838 DEBUG11(printk(KERN_INFO "%s(%ld): entered.\n", __func__, vha->host_no));
3840 mcp->mb[0] = MBC_DATA_RATE;
3842 mcp->out_mb = MBX_1|MBX_0;
3843 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3844 mcp->tov = MBX_TOV_SECONDS;
3846 rval = qla2x00_mailbox_command(vha, mcp);
3847 if (rval != QLA_SUCCESS) {
3848 DEBUG2_3_11(printk(KERN_INFO "%s(%ld): failed=%x mb[0]=%x.\n",
3849 __func__, vha->host_no, rval, mcp->mb[0]));
3851 DEBUG11(printk(KERN_INFO
3852 "%s(%ld): done.\n", __func__, vha->host_no));
3853 if (mcp->mb[1] != 0x7)
3854 ha->link_data_rate = mcp->mb[1];