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));
60 * Wait for active mailbox commands to finish by waiting at most tov
61 * seconds. This is to serialize actual issuing of mailbox cmds during
64 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp, mcp->tov * HZ)) {
65 /* Timeout occurred. Return error. */
66 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
67 "Exiting.\n", __func__, base_vha->host_no));
68 return QLA_FUNCTION_TIMEOUT;
71 ha->flags.mbox_busy = 1;
72 /* Save mailbox command for debug */
75 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
76 base_vha->host_no, mcp->mb[0]));
78 spin_lock_irqsave(&ha->hardware_lock, flags);
80 /* Load mailbox registers. */
81 if (IS_FWI2_CAPABLE(ha))
82 optr = (uint16_t __iomem *)®->isp24.mailbox0;
84 optr = (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 0);
90 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
91 if (IS_QLA2200(ha) && cnt == 8)
93 (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 8);
95 WRT_REG_WORD(optr, *iptr);
102 #if defined(QL_DEBUG_LEVEL_1)
103 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
104 __func__, base_vha->host_no);
105 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
107 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
109 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
111 printk("%s(%ld): I/O address = %p.\n", __func__, base_vha->host_no,
113 qla2x00_dump_regs(base_vha);
116 /* Issue set host interrupt command to send cmd out. */
117 ha->flags.mbox_int = 0;
118 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
120 /* Unlock mbx registers and wait for interrupt */
121 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
122 "jiffies=%lx.\n", __func__, base_vha->host_no, jiffies));
124 /* Wait for mbx cmd completion until timeout */
126 if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
127 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
129 if (IS_FWI2_CAPABLE(ha))
130 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
132 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
133 spin_unlock_irqrestore(&ha->hardware_lock, flags);
135 wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ);
137 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
140 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
141 base_vha->host_no, command));
143 if (IS_FWI2_CAPABLE(ha))
144 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
146 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
147 spin_unlock_irqrestore(&ha->hardware_lock, flags);
149 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
150 while (!ha->flags.mbox_int) {
151 if (time_after(jiffies, wait_time))
154 /* Check for pending interrupts. */
155 qla2x00_poll(ha->rsp_q_map[0]);
157 if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
163 /* Check whether we timed out */
164 if (ha->flags.mbox_int) {
167 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
168 base_vha->host_no, command));
170 /* Got interrupt. Clear the flag. */
171 ha->flags.mbox_int = 0;
172 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
174 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
175 rval = QLA_FUNCTION_FAILED;
177 /* Load return mailbox registers. */
179 iptr = (uint16_t *)&ha->mailbox_out[0];
181 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
191 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
192 defined(QL_DEBUG_LEVEL_11)
196 if (IS_FWI2_CAPABLE(ha)) {
197 mb0 = RD_REG_WORD(®->isp24.mailbox0);
198 ictrl = RD_REG_DWORD(®->isp24.ictrl);
200 mb0 = RD_MAILBOX_REG(ha, ®->isp, 0);
201 ictrl = RD_REG_WORD(®->isp.ictrl);
203 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
204 __func__, base_vha->host_no, command);
205 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
206 base_vha->host_no, ictrl, jiffies);
207 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
208 base_vha->host_no, mb0);
209 qla2x00_dump_regs(base_vha);
212 rval = QLA_FUNCTION_TIMEOUT;
215 ha->flags.mbox_busy = 0;
220 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
221 DEBUG11(printk("%s(%ld): checking for additional resp "
222 "interrupt.\n", __func__, base_vha->host_no));
224 /* polling mode for non isp_abort commands. */
225 qla2x00_poll(ha->rsp_q_map[0]);
228 if (rval == QLA_FUNCTION_TIMEOUT &&
229 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
230 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
231 /* not in dpc. schedule it for dpc to take over. */
232 DEBUG(printk("%s(%ld): timeout schedule "
233 "isp_abort_needed.\n", __func__,
235 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
236 "isp_abort_needed.\n", __func__,
238 qla_printk(KERN_WARNING, ha,
239 "Mailbox command timeout occurred. Scheduling ISP "
241 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
242 qla2xxx_wake_dpc(vha);
243 } else if (!abort_active) {
244 /* call abort directly since we are in the DPC thread */
245 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
246 __func__, base_vha->host_no));
247 DEBUG2_3_11(printk("%s(%ld): timeout calling "
248 "abort_isp\n", __func__, base_vha->host_no));
249 qla_printk(KERN_WARNING, ha,
250 "Mailbox command timeout occurred. Issuing ISP "
253 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
254 clear_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
255 if (qla2x00_abort_isp(base_vha)) {
256 /* Failed. retry later. */
257 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
259 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
260 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
262 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
263 __func__, base_vha->host_no));
267 /* Allow next mbx cmd to come in. */
268 complete(&ha->mbx_cmd_comp);
271 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
272 "mbx2=%x, cmd=%x ****\n", __func__, base_vha->host_no,
273 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
275 DEBUG11(printk("%s(%ld): done.\n", __func__,
283 qla2x00_load_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t risc_addr,
284 uint32_t risc_code_size)
287 struct qla_hw_data *ha = vha->hw;
289 mbx_cmd_t *mcp = &mc;
291 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
293 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
294 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
295 mcp->mb[8] = MSW(risc_addr);
296 mcp->out_mb = MBX_8|MBX_0;
298 mcp->mb[0] = MBC_LOAD_RISC_RAM;
301 mcp->mb[1] = LSW(risc_addr);
302 mcp->mb[2] = MSW(req_dma);
303 mcp->mb[3] = LSW(req_dma);
304 mcp->mb[6] = MSW(MSD(req_dma));
305 mcp->mb[7] = LSW(MSD(req_dma));
306 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
307 if (IS_FWI2_CAPABLE(ha)) {
308 mcp->mb[4] = MSW(risc_code_size);
309 mcp->mb[5] = LSW(risc_code_size);
310 mcp->out_mb |= MBX_5|MBX_4;
312 mcp->mb[4] = LSW(risc_code_size);
313 mcp->out_mb |= MBX_4;
317 mcp->tov = MBX_TOV_SECONDS;
319 rval = qla2x00_mailbox_command(vha, mcp);
321 if (rval != QLA_SUCCESS) {
322 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
323 vha->host_no, rval, mcp->mb[0]));
325 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
333 * Start adapter firmware.
336 * ha = adapter block pointer.
337 * TARGET_QUEUE_LOCK must be released.
338 * ADAPTER_STATE_LOCK must be released.
341 * qla2x00 local function return status code.
347 qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
350 struct qla_hw_data *ha = vha->hw;
352 mbx_cmd_t *mcp = &mc;
354 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
356 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
359 if (IS_FWI2_CAPABLE(ha)) {
360 mcp->mb[1] = MSW(risc_addr);
361 mcp->mb[2] = LSW(risc_addr);
364 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
367 mcp->mb[1] = LSW(risc_addr);
368 mcp->out_mb |= MBX_1;
369 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
371 mcp->out_mb |= MBX_2;
375 mcp->tov = MBX_TOV_SECONDS;
377 rval = qla2x00_mailbox_command(vha, mcp);
379 if (rval != QLA_SUCCESS) {
380 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
381 vha->host_no, rval, mcp->mb[0]));
383 if (IS_FWI2_CAPABLE(ha)) {
384 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
385 __func__, vha->host_no, mcp->mb[1]));
387 DEBUG11(printk("%s(%ld): done.\n", __func__,
396 * qla2x00_get_fw_version
397 * Get firmware version.
400 * ha: adapter state pointer.
401 * major: pointer for major number.
402 * minor: pointer for minor number.
403 * subminor: pointer for subminor number.
406 * qla2x00 local function return status code.
412 qla2x00_get_fw_version(scsi_qla_host_t *vha, uint16_t *major, uint16_t *minor,
413 uint16_t *subminor, uint16_t *attributes, uint32_t *memory, uint8_t *mpi,
414 uint32_t *mpi_caps, uint8_t *phy)
418 mbx_cmd_t *mcp = &mc;
420 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
422 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
424 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
425 if (IS_QLA81XX(vha->hw))
426 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
428 mcp->tov = MBX_TOV_SECONDS;
429 rval = qla2x00_mailbox_command(vha, mcp);
430 if (rval != QLA_SUCCESS)
433 /* Return mailbox data. */
436 *subminor = mcp->mb[3];
437 *attributes = mcp->mb[6];
438 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
439 *memory = 0x1FFFF; /* Defaults to 128KB. */
441 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
442 if (IS_QLA81XX(vha->hw)) {
443 mpi[0] = mcp->mb[10] & 0xff;
444 mpi[1] = mcp->mb[11] >> 8;
445 mpi[2] = mcp->mb[11] & 0xff;
446 *mpi_caps = (mcp->mb[12] << 16) | mcp->mb[13];
447 phy[0] = mcp->mb[8] & 0xff;
448 phy[1] = mcp->mb[9] >> 8;
449 phy[2] = mcp->mb[9] & 0xff;
452 if (rval != QLA_SUCCESS) {
454 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
455 vha->host_no, rval));
458 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
464 * qla2x00_get_fw_options
465 * Set firmware options.
468 * ha = adapter block pointer.
469 * fwopt = pointer for firmware options.
472 * qla2x00 local function return status code.
478 qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
482 mbx_cmd_t *mcp = &mc;
484 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
486 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
488 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
489 mcp->tov = MBX_TOV_SECONDS;
491 rval = qla2x00_mailbox_command(vha, mcp);
493 if (rval != QLA_SUCCESS) {
495 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
496 vha->host_no, rval));
498 fwopts[0] = mcp->mb[0];
499 fwopts[1] = mcp->mb[1];
500 fwopts[2] = mcp->mb[2];
501 fwopts[3] = mcp->mb[3];
503 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
511 * qla2x00_set_fw_options
512 * Set firmware options.
515 * ha = adapter block pointer.
516 * fwopt = pointer for firmware options.
519 * qla2x00 local function return status code.
525 qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
529 mbx_cmd_t *mcp = &mc;
531 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
533 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
534 mcp->mb[1] = fwopts[1];
535 mcp->mb[2] = fwopts[2];
536 mcp->mb[3] = fwopts[3];
537 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
539 if (IS_FWI2_CAPABLE(vha->hw)) {
542 mcp->mb[10] = fwopts[10];
543 mcp->mb[11] = fwopts[11];
544 mcp->mb[12] = 0; /* Undocumented, but used */
545 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
547 mcp->tov = MBX_TOV_SECONDS;
549 rval = qla2x00_mailbox_command(vha, mcp);
551 fwopts[0] = mcp->mb[0];
553 if (rval != QLA_SUCCESS) {
555 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
556 vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
559 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
566 * qla2x00_mbx_reg_test
567 * Mailbox register wrap test.
570 * ha = adapter block pointer.
571 * TARGET_QUEUE_LOCK must be released.
572 * ADAPTER_STATE_LOCK must be released.
575 * qla2x00 local function return status code.
581 qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
585 mbx_cmd_t *mcp = &mc;
587 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", vha->host_no));
589 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
597 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
598 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
599 mcp->tov = MBX_TOV_SECONDS;
601 rval = qla2x00_mailbox_command(vha, mcp);
603 if (rval == QLA_SUCCESS) {
604 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
605 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
606 rval = QLA_FUNCTION_FAILED;
607 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
608 mcp->mb[7] != 0x2525)
609 rval = QLA_FUNCTION_FAILED;
612 if (rval != QLA_SUCCESS) {
614 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
615 vha->host_no, rval));
618 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
626 * qla2x00_verify_checksum
627 * Verify firmware checksum.
630 * ha = adapter block pointer.
631 * TARGET_QUEUE_LOCK must be released.
632 * ADAPTER_STATE_LOCK must be released.
635 * qla2x00 local function return status code.
641 qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
645 mbx_cmd_t *mcp = &mc;
647 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
649 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
652 if (IS_FWI2_CAPABLE(vha->hw)) {
653 mcp->mb[1] = MSW(risc_addr);
654 mcp->mb[2] = LSW(risc_addr);
655 mcp->out_mb |= MBX_2|MBX_1;
656 mcp->in_mb |= MBX_2|MBX_1;
658 mcp->mb[1] = LSW(risc_addr);
659 mcp->out_mb |= MBX_1;
663 mcp->tov = MBX_TOV_SECONDS;
665 rval = qla2x00_mailbox_command(vha, mcp);
667 if (rval != QLA_SUCCESS) {
668 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
669 vha->host_no, rval, IS_FWI2_CAPABLE(vha->hw) ?
670 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
672 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
680 * Issue IOCB using mailbox command
683 * ha = adapter state pointer.
684 * buffer = buffer pointer.
685 * phys_addr = physical address of buffer.
686 * size = size of buffer.
687 * TARGET_QUEUE_LOCK must be released.
688 * ADAPTER_STATE_LOCK must be released.
691 * qla2x00 local function return status code.
697 qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
698 dma_addr_t phys_addr, size_t size, uint32_t tov)
702 mbx_cmd_t *mcp = &mc;
704 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
706 mcp->mb[2] = MSW(phys_addr);
707 mcp->mb[3] = LSW(phys_addr);
708 mcp->mb[6] = MSW(MSD(phys_addr));
709 mcp->mb[7] = LSW(MSD(phys_addr));
710 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
711 mcp->in_mb = MBX_2|MBX_0;
714 rval = qla2x00_mailbox_command(vha, mcp);
716 if (rval != QLA_SUCCESS) {
718 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
719 vha->host_no, rval));
721 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
723 /* Mask reserved bits. */
724 sts_entry->entry_status &=
725 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
732 qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
735 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
740 * qla2x00_abort_command
741 * Abort command aborts a specified IOCB.
744 * ha = adapter block pointer.
745 * sp = SB structure pointer.
748 * qla2x00 local function return status code.
754 qla2x00_abort_command(srb_t *sp)
756 unsigned long flags = 0;
760 mbx_cmd_t *mcp = &mc;
761 fc_port_t *fcport = sp->fcport;
762 scsi_qla_host_t *vha = fcport->vha;
763 struct qla_hw_data *ha = vha->hw;
764 struct req_que *req = vha->req;
766 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", vha->host_no));
768 spin_lock_irqsave(&ha->hardware_lock, flags);
769 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
770 if (req->outstanding_cmds[handle] == sp)
773 spin_unlock_irqrestore(&ha->hardware_lock, flags);
775 if (handle == MAX_OUTSTANDING_COMMANDS) {
776 /* command not found */
777 return QLA_FUNCTION_FAILED;
780 mcp->mb[0] = MBC_ABORT_COMMAND;
781 if (HAS_EXTENDED_IDS(ha))
782 mcp->mb[1] = fcport->loop_id;
784 mcp->mb[1] = fcport->loop_id << 8;
785 mcp->mb[2] = (uint16_t)handle;
786 mcp->mb[3] = (uint16_t)(handle >> 16);
787 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
788 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
790 mcp->tov = MBX_TOV_SECONDS;
792 rval = qla2x00_mailbox_command(vha, mcp);
794 if (rval != QLA_SUCCESS) {
795 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
796 vha->host_no, rval));
798 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
806 qla2x00_abort_target(struct fc_port *fcport, unsigned int l, int tag)
810 mbx_cmd_t *mcp = &mc;
811 scsi_qla_host_t *vha;
815 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
819 req = vha->hw->req_q_map[tag];
820 rsp = vha->hw->rsp_q_map[tag];
821 mcp->mb[0] = MBC_ABORT_TARGET;
822 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
823 if (HAS_EXTENDED_IDS(vha->hw)) {
824 mcp->mb[1] = fcport->loop_id;
826 mcp->out_mb |= MBX_10;
828 mcp->mb[1] = fcport->loop_id << 8;
830 mcp->mb[2] = vha->hw->loop_reset_delay;
831 mcp->mb[9] = vha->vp_idx;
834 mcp->tov = MBX_TOV_SECONDS;
836 rval = qla2x00_mailbox_command(vha, mcp);
837 if (rval != QLA_SUCCESS) {
838 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
839 vha->host_no, rval));
842 /* Issue marker IOCB. */
843 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
845 if (rval2 != QLA_SUCCESS) {
846 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
847 "(%x).\n", __func__, vha->host_no, rval2));
849 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
856 qla2x00_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
860 mbx_cmd_t *mcp = &mc;
861 scsi_qla_host_t *vha;
865 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
868 req = vha->hw->req_q_map[tag];
869 rsp = vha->hw->rsp_q_map[tag];
870 mcp->mb[0] = MBC_LUN_RESET;
871 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
872 if (HAS_EXTENDED_IDS(vha->hw))
873 mcp->mb[1] = fcport->loop_id;
875 mcp->mb[1] = fcport->loop_id << 8;
878 mcp->mb[9] = vha->vp_idx;
881 mcp->tov = MBX_TOV_SECONDS;
883 rval = qla2x00_mailbox_command(vha, mcp);
884 if (rval != QLA_SUCCESS) {
885 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
886 vha->host_no, rval));
889 /* Issue marker IOCB. */
890 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
892 if (rval2 != QLA_SUCCESS) {
893 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
894 "(%x).\n", __func__, vha->host_no, rval2));
896 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
903 * qla2x00_get_adapter_id
904 * Get adapter ID and topology.
907 * ha = adapter block pointer.
908 * id = pointer for loop ID.
909 * al_pa = pointer for AL_PA.
910 * area = pointer for area.
911 * domain = pointer for domain.
912 * top = pointer for topology.
913 * TARGET_QUEUE_LOCK must be released.
914 * ADAPTER_STATE_LOCK must be released.
917 * qla2x00 local function return status code.
923 qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
924 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
928 mbx_cmd_t *mcp = &mc;
930 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
933 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
934 mcp->mb[9] = vha->vp_idx;
935 mcp->out_mb = MBX_9|MBX_0;
936 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
937 if (IS_QLA81XX(vha->hw))
938 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
939 mcp->tov = MBX_TOV_SECONDS;
941 rval = qla2x00_mailbox_command(vha, mcp);
942 if (mcp->mb[0] == MBS_COMMAND_ERROR)
943 rval = QLA_COMMAND_ERROR;
944 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
945 rval = QLA_INVALID_COMMAND;
949 *al_pa = LSB(mcp->mb[2]);
950 *area = MSB(mcp->mb[2]);
951 *domain = LSB(mcp->mb[3]);
953 *sw_cap = mcp->mb[7];
955 if (rval != QLA_SUCCESS) {
957 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
958 vha->host_no, rval));
960 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
963 if (IS_QLA81XX(vha->hw)) {
964 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
965 vha->fcoe_fcf_idx = mcp->mb[10];
966 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
967 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
968 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
969 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
970 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
971 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
979 * qla2x00_get_retry_cnt
980 * Get current firmware login retry count and delay.
983 * ha = adapter block pointer.
984 * retry_cnt = pointer to login retry count.
985 * tov = pointer to login timeout value.
988 * qla2x00 local function return status code.
994 qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
1000 mbx_cmd_t *mcp = &mc;
1002 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
1005 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1006 mcp->out_mb = MBX_0;
1007 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1008 mcp->tov = MBX_TOV_SECONDS;
1010 rval = qla2x00_mailbox_command(vha, mcp);
1012 if (rval != QLA_SUCCESS) {
1014 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
1015 vha->host_no, mcp->mb[0]));
1017 /* Convert returned data and check our values. */
1018 *r_a_tov = mcp->mb[3] / 2;
1019 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1020 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1021 /* Update to the larger values */
1022 *retry_cnt = (uint8_t)mcp->mb[1];
1026 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
1027 "ratov=%d.\n", vha->host_no, mcp->mb[3], ratov));
1034 * qla2x00_init_firmware
1035 * Initialize adapter firmware.
1038 * ha = adapter block pointer.
1039 * dptr = Initialization control block pointer.
1040 * size = size of initialization control block.
1041 * TARGET_QUEUE_LOCK must be released.
1042 * ADAPTER_STATE_LOCK must be released.
1045 * qla2x00 local function return status code.
1051 qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
1055 mbx_cmd_t *mcp = &mc;
1056 struct qla_hw_data *ha = vha->hw;
1058 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1061 if (ha->flags.npiv_supported)
1062 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1064 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1067 mcp->mb[2] = MSW(ha->init_cb_dma);
1068 mcp->mb[3] = LSW(ha->init_cb_dma);
1069 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1070 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1071 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1072 if (IS_QLA81XX(ha) && ha->ex_init_cb->ex_version) {
1074 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1075 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1076 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1077 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1078 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1079 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1082 mcp->buf_size = size;
1083 mcp->flags = MBX_DMA_OUT;
1084 mcp->tov = MBX_TOV_SECONDS;
1085 rval = qla2x00_mailbox_command(vha, mcp);
1087 if (rval != QLA_SUCCESS) {
1089 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1091 vha->host_no, rval, mcp->mb[0]));
1094 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1102 * qla2x00_get_port_database
1103 * Issue normal/enhanced get port database mailbox command
1104 * and copy device name as necessary.
1107 * ha = adapter state pointer.
1108 * dev = structure pointer.
1109 * opt = enhanced cmd option byte.
1112 * qla2x00 local function return status code.
1118 qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
1122 mbx_cmd_t *mcp = &mc;
1123 port_database_t *pd;
1124 struct port_database_24xx *pd24;
1126 struct qla_hw_data *ha = vha->hw;
1128 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1131 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1133 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1134 "structure.\n", __func__, vha->host_no));
1135 return QLA_MEMORY_ALLOC_FAILED;
1137 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
1139 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1140 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
1141 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1142 mcp->mb[2] = MSW(pd_dma);
1143 mcp->mb[3] = LSW(pd_dma);
1144 mcp->mb[6] = MSW(MSD(pd_dma));
1145 mcp->mb[7] = LSW(MSD(pd_dma));
1146 mcp->mb[9] = vha->vp_idx;
1147 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1149 if (IS_FWI2_CAPABLE(ha)) {
1150 mcp->mb[1] = fcport->loop_id;
1152 mcp->out_mb |= MBX_10|MBX_1;
1153 mcp->in_mb |= MBX_1;
1154 } else if (HAS_EXTENDED_IDS(ha)) {
1155 mcp->mb[1] = fcport->loop_id;
1157 mcp->out_mb |= MBX_10|MBX_1;
1159 mcp->mb[1] = fcport->loop_id << 8 | opt;
1160 mcp->out_mb |= MBX_1;
1162 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1163 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
1164 mcp->flags = MBX_DMA_IN;
1165 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1166 rval = qla2x00_mailbox_command(vha, mcp);
1167 if (rval != QLA_SUCCESS)
1170 if (IS_FWI2_CAPABLE(ha)) {
1171 pd24 = (struct port_database_24xx *) pd;
1173 /* Check for logged in state. */
1174 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1175 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1176 DEBUG2(printk("%s(%ld): Unable to verify "
1177 "login-state (%x/%x) for loop_id %x\n",
1178 __func__, vha->host_no,
1179 pd24->current_login_state,
1180 pd24->last_login_state, fcport->loop_id));
1181 rval = QLA_FUNCTION_FAILED;
1185 /* Names are little-endian. */
1186 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1187 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1189 /* Get port_id of device. */
1190 fcport->d_id.b.domain = pd24->port_id[0];
1191 fcport->d_id.b.area = pd24->port_id[1];
1192 fcport->d_id.b.al_pa = pd24->port_id[2];
1193 fcport->d_id.b.rsvd_1 = 0;
1195 /* If not target must be initiator or unknown type. */
1196 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1197 fcport->port_type = FCT_INITIATOR;
1199 fcport->port_type = FCT_TARGET;
1201 /* Check for logged in state. */
1202 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1203 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1204 rval = QLA_FUNCTION_FAILED;
1208 /* Names are little-endian. */
1209 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1210 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1212 /* Get port_id of device. */
1213 fcport->d_id.b.domain = pd->port_id[0];
1214 fcport->d_id.b.area = pd->port_id[3];
1215 fcport->d_id.b.al_pa = pd->port_id[2];
1216 fcport->d_id.b.rsvd_1 = 0;
1218 /* If not target must be initiator or unknown type. */
1219 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1220 fcport->port_type = FCT_INITIATOR;
1222 fcport->port_type = FCT_TARGET;
1224 /* Passback COS information. */
1225 fcport->supported_classes = (pd->options & BIT_4) ?
1226 FC_COS_CLASS2: FC_COS_CLASS3;
1230 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1232 if (rval != QLA_SUCCESS) {
1233 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1234 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1236 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1243 * qla2x00_get_firmware_state
1244 * Get adapter firmware state.
1247 * ha = adapter block pointer.
1248 * dptr = pointer for firmware state.
1249 * TARGET_QUEUE_LOCK must be released.
1250 * ADAPTER_STATE_LOCK must be released.
1253 * qla2x00 local function return status code.
1259 qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
1263 mbx_cmd_t *mcp = &mc;
1265 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1268 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1269 mcp->out_mb = MBX_0;
1270 if (IS_FWI2_CAPABLE(vha->hw))
1271 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1273 mcp->in_mb = MBX_1|MBX_0;
1274 mcp->tov = MBX_TOV_SECONDS;
1276 rval = qla2x00_mailbox_command(vha, mcp);
1278 /* Return firmware states. */
1279 states[0] = mcp->mb[1];
1280 if (IS_FWI2_CAPABLE(vha->hw)) {
1281 states[1] = mcp->mb[2];
1282 states[2] = mcp->mb[3];
1283 states[3] = mcp->mb[4];
1284 states[4] = mcp->mb[5];
1287 if (rval != QLA_SUCCESS) {
1289 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1290 "failed=%x.\n", vha->host_no, rval));
1293 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1301 * qla2x00_get_port_name
1302 * Issue get port name mailbox command.
1303 * Returned name is in big endian format.
1306 * ha = adapter block pointer.
1307 * loop_id = loop ID of device.
1308 * name = pointer for name.
1309 * TARGET_QUEUE_LOCK must be released.
1310 * ADAPTER_STATE_LOCK must be released.
1313 * qla2x00 local function return status code.
1319 qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
1324 mbx_cmd_t *mcp = &mc;
1326 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1329 mcp->mb[0] = MBC_GET_PORT_NAME;
1330 mcp->mb[9] = vha->vp_idx;
1331 mcp->out_mb = MBX_9|MBX_1|MBX_0;
1332 if (HAS_EXTENDED_IDS(vha->hw)) {
1333 mcp->mb[1] = loop_id;
1335 mcp->out_mb |= MBX_10;
1337 mcp->mb[1] = loop_id << 8 | opt;
1340 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1341 mcp->tov = MBX_TOV_SECONDS;
1343 rval = qla2x00_mailbox_command(vha, mcp);
1345 if (rval != QLA_SUCCESS) {
1347 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1348 vha->host_no, rval));
1351 /* This function returns name in big endian. */
1352 name[0] = MSB(mcp->mb[2]);
1353 name[1] = LSB(mcp->mb[2]);
1354 name[2] = MSB(mcp->mb[3]);
1355 name[3] = LSB(mcp->mb[3]);
1356 name[4] = MSB(mcp->mb[6]);
1357 name[5] = LSB(mcp->mb[6]);
1358 name[6] = MSB(mcp->mb[7]);
1359 name[7] = LSB(mcp->mb[7]);
1362 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1371 * Issue LIP reset mailbox command.
1374 * ha = adapter block pointer.
1375 * TARGET_QUEUE_LOCK must be released.
1376 * ADAPTER_STATE_LOCK must be released.
1379 * qla2x00 local function return status code.
1385 qla2x00_lip_reset(scsi_qla_host_t *vha)
1389 mbx_cmd_t *mcp = &mc;
1391 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1393 if (IS_QLA81XX(vha->hw)) {
1394 /* Logout across all FCFs. */
1395 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1398 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1399 } else if (IS_FWI2_CAPABLE(vha->hw)) {
1400 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1403 mcp->mb[3] = vha->hw->loop_reset_delay;
1404 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1406 mcp->mb[0] = MBC_LIP_RESET;
1407 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1408 if (HAS_EXTENDED_IDS(vha->hw)) {
1409 mcp->mb[1] = 0x00ff;
1411 mcp->out_mb |= MBX_10;
1413 mcp->mb[1] = 0xff00;
1415 mcp->mb[2] = vha->hw->loop_reset_delay;
1419 mcp->tov = MBX_TOV_SECONDS;
1421 rval = qla2x00_mailbox_command(vha, mcp);
1423 if (rval != QLA_SUCCESS) {
1425 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1426 __func__, vha->host_no, rval));
1429 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1440 * ha = adapter block pointer.
1441 * sns = pointer for command.
1442 * cmd_size = command size.
1443 * buf_size = response/command size.
1444 * TARGET_QUEUE_LOCK must be released.
1445 * ADAPTER_STATE_LOCK must be released.
1448 * qla2x00 local function return status code.
1454 qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
1455 uint16_t cmd_size, size_t buf_size)
1459 mbx_cmd_t *mcp = &mc;
1461 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1464 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1465 "tov=%d.\n", vha->hw->retry_count, vha->hw->login_timeout,
1468 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1469 mcp->mb[1] = cmd_size;
1470 mcp->mb[2] = MSW(sns_phys_address);
1471 mcp->mb[3] = LSW(sns_phys_address);
1472 mcp->mb[6] = MSW(MSD(sns_phys_address));
1473 mcp->mb[7] = LSW(MSD(sns_phys_address));
1474 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1475 mcp->in_mb = MBX_0|MBX_1;
1476 mcp->buf_size = buf_size;
1477 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1478 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
1479 rval = qla2x00_mailbox_command(vha, mcp);
1481 if (rval != QLA_SUCCESS) {
1483 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1484 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1485 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1486 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1489 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", vha->host_no));
1496 qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1497 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1501 struct logio_entry_24xx *lg;
1504 struct qla_hw_data *ha = vha->hw;
1505 struct req_que *req;
1506 struct rsp_que *rsp;
1508 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1510 if (ha->flags.cpu_affinity_enabled)
1511 req = ha->req_q_map[0];
1516 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1518 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1519 __func__, vha->host_no));
1520 return QLA_MEMORY_ALLOC_FAILED;
1522 memset(lg, 0, sizeof(struct logio_entry_24xx));
1524 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1525 lg->entry_count = 1;
1526 lg->handle = MAKE_HANDLE(req->id, lg->handle);
1527 lg->nport_handle = cpu_to_le16(loop_id);
1528 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1530 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1532 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
1533 lg->port_id[0] = al_pa;
1534 lg->port_id[1] = area;
1535 lg->port_id[2] = domain;
1536 lg->vp_index = vha->vp_idx;
1537 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
1538 if (rval != QLA_SUCCESS) {
1539 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
1540 "(%x).\n", __func__, vha->host_no, rval));
1541 } else if (lg->entry_status != 0) {
1542 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1543 "-- error status (%x).\n", __func__, vha->host_no,
1545 rval = QLA_FUNCTION_FAILED;
1546 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1547 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1548 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1550 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1551 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1552 vha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1556 case LSC_SCODE_PORTID_USED:
1557 mb[0] = MBS_PORT_ID_USED;
1558 mb[1] = LSW(iop[1]);
1560 case LSC_SCODE_NPORT_USED:
1561 mb[0] = MBS_LOOP_ID_USED;
1563 case LSC_SCODE_NOLINK:
1564 case LSC_SCODE_NOIOCB:
1565 case LSC_SCODE_NOXCB:
1566 case LSC_SCODE_CMD_FAILED:
1567 case LSC_SCODE_NOFABRIC:
1568 case LSC_SCODE_FW_NOT_READY:
1569 case LSC_SCODE_NOT_LOGGED_IN:
1570 case LSC_SCODE_NOPCB:
1571 case LSC_SCODE_ELS_REJECT:
1572 case LSC_SCODE_CMD_PARAM_ERR:
1573 case LSC_SCODE_NONPORT:
1574 case LSC_SCODE_LOGGED_IN:
1575 case LSC_SCODE_NOFLOGI_ACC:
1577 mb[0] = MBS_COMMAND_ERROR;
1581 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1583 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1585 mb[0] = MBS_COMMAND_COMPLETE;
1587 if (iop[0] & BIT_4) {
1593 /* Passback COS information. */
1595 if (lg->io_parameter[7] || lg->io_parameter[8])
1596 mb[10] |= BIT_0; /* Class 2. */
1597 if (lg->io_parameter[9] || lg->io_parameter[10])
1598 mb[10] |= BIT_1; /* Class 3. */
1601 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1607 * qla2x00_login_fabric
1608 * Issue login fabric port mailbox command.
1611 * ha = adapter block pointer.
1612 * loop_id = device loop ID.
1613 * domain = device domain.
1614 * area = device area.
1615 * al_pa = device AL_PA.
1616 * status = pointer for return status.
1617 * opt = command options.
1618 * TARGET_QUEUE_LOCK must be released.
1619 * ADAPTER_STATE_LOCK must be released.
1622 * qla2x00 local function return status code.
1628 qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1629 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1633 mbx_cmd_t *mcp = &mc;
1634 struct qla_hw_data *ha = vha->hw;
1636 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", vha->host_no));
1638 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1639 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1640 if (HAS_EXTENDED_IDS(ha)) {
1641 mcp->mb[1] = loop_id;
1643 mcp->out_mb |= MBX_10;
1645 mcp->mb[1] = (loop_id << 8) | opt;
1647 mcp->mb[2] = domain;
1648 mcp->mb[3] = area << 8 | al_pa;
1650 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1651 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1653 rval = qla2x00_mailbox_command(vha, mcp);
1655 /* Return mailbox statuses. */
1662 /* COS retrieved from Get-Port-Database mailbox command. */
1666 if (rval != QLA_SUCCESS) {
1667 /* RLU tmp code: need to change main mailbox_command function to
1668 * return ok even when the mailbox completion value is not
1669 * SUCCESS. The caller needs to be responsible to interpret
1670 * the return values of this mailbox command if we're not
1671 * to change too much of the existing code.
1673 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1674 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1675 mcp->mb[0] == 0x4006)
1679 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1680 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", vha->host_no, rval,
1681 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
1684 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1692 * qla2x00_login_local_device
1693 * Issue login loop port mailbox command.
1696 * ha = adapter block pointer.
1697 * loop_id = device loop ID.
1698 * opt = command options.
1701 * Return status code.
1708 qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
1709 uint16_t *mb_ret, uint8_t opt)
1713 mbx_cmd_t *mcp = &mc;
1714 struct qla_hw_data *ha = vha->hw;
1716 if (IS_FWI2_CAPABLE(ha))
1717 return qla24xx_login_fabric(vha, fcport->loop_id,
1718 fcport->d_id.b.domain, fcport->d_id.b.area,
1719 fcport->d_id.b.al_pa, mb_ret, opt);
1721 DEBUG3(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1723 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1724 if (HAS_EXTENDED_IDS(ha))
1725 mcp->mb[1] = fcport->loop_id;
1727 mcp->mb[1] = fcport->loop_id << 8;
1729 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1730 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1731 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1733 rval = qla2x00_mailbox_command(vha, mcp);
1735 /* Return mailbox statuses. */
1736 if (mb_ret != NULL) {
1737 mb_ret[0] = mcp->mb[0];
1738 mb_ret[1] = mcp->mb[1];
1739 mb_ret[6] = mcp->mb[6];
1740 mb_ret[7] = mcp->mb[7];
1743 if (rval != QLA_SUCCESS) {
1744 /* AV tmp code: need to change main mailbox_command function to
1745 * return ok even when the mailbox completion value is not
1746 * SUCCESS. The caller needs to be responsible to interpret
1747 * the return values of this mailbox command if we're not
1748 * to change too much of the existing code.
1750 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1753 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1754 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
1755 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1756 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1757 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
1758 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1761 DEBUG3(printk("%s(%ld): done.\n", __func__, vha->host_no));
1768 qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1769 uint8_t area, uint8_t al_pa)
1772 struct logio_entry_24xx *lg;
1774 struct qla_hw_data *ha = vha->hw;
1775 struct req_que *req;
1776 struct rsp_que *rsp;
1778 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1780 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1782 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1783 __func__, vha->host_no));
1784 return QLA_MEMORY_ALLOC_FAILED;
1786 memset(lg, 0, sizeof(struct logio_entry_24xx));
1788 if (ql2xmaxqueues > 1)
1789 req = ha->req_q_map[0];
1793 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1794 lg->entry_count = 1;
1795 lg->handle = MAKE_HANDLE(req->id, lg->handle);
1796 lg->nport_handle = cpu_to_le16(loop_id);
1798 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
1799 lg->port_id[0] = al_pa;
1800 lg->port_id[1] = area;
1801 lg->port_id[2] = domain;
1802 lg->vp_index = vha->vp_idx;
1804 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
1805 if (rval != QLA_SUCCESS) {
1806 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1807 "(%x).\n", __func__, vha->host_no, rval));
1808 } else if (lg->entry_status != 0) {
1809 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1810 "-- error status (%x).\n", __func__, vha->host_no,
1812 rval = QLA_FUNCTION_FAILED;
1813 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1814 DEBUG2_3_11(printk("%s(%ld %d): failed to complete IOCB "
1815 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1816 vha->host_no, vha->vp_idx, le16_to_cpu(lg->comp_status),
1817 le32_to_cpu(lg->io_parameter[0]),
1818 le32_to_cpu(lg->io_parameter[1])));
1821 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1824 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1830 * qla2x00_fabric_logout
1831 * Issue logout fabric port mailbox command.
1834 * ha = adapter block pointer.
1835 * loop_id = device loop ID.
1836 * TARGET_QUEUE_LOCK must be released.
1837 * ADAPTER_STATE_LOCK must be released.
1840 * qla2x00 local function return status code.
1846 qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1847 uint8_t area, uint8_t al_pa)
1851 mbx_cmd_t *mcp = &mc;
1853 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1856 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1857 mcp->out_mb = MBX_1|MBX_0;
1858 if (HAS_EXTENDED_IDS(vha->hw)) {
1859 mcp->mb[1] = loop_id;
1861 mcp->out_mb |= MBX_10;
1863 mcp->mb[1] = loop_id << 8;
1866 mcp->in_mb = MBX_1|MBX_0;
1867 mcp->tov = MBX_TOV_SECONDS;
1869 rval = qla2x00_mailbox_command(vha, mcp);
1871 if (rval != QLA_SUCCESS) {
1873 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1874 "mbx1=%x.\n", vha->host_no, rval, mcp->mb[1]));
1877 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1885 * qla2x00_full_login_lip
1886 * Issue full login LIP mailbox command.
1889 * ha = adapter block pointer.
1890 * TARGET_QUEUE_LOCK must be released.
1891 * ADAPTER_STATE_LOCK must be released.
1894 * qla2x00 local function return status code.
1900 qla2x00_full_login_lip(scsi_qla_host_t *vha)
1904 mbx_cmd_t *mcp = &mc;
1906 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1909 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1910 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
1913 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1915 mcp->tov = MBX_TOV_SECONDS;
1917 rval = qla2x00_mailbox_command(vha, mcp);
1919 if (rval != QLA_SUCCESS) {
1921 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1922 vha->host_no, rval));
1925 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1933 * qla2x00_get_id_list
1936 * ha = adapter block pointer.
1939 * qla2x00 local function return status code.
1945 qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
1950 mbx_cmd_t *mcp = &mc;
1952 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1955 if (id_list == NULL)
1956 return QLA_FUNCTION_FAILED;
1958 mcp->mb[0] = MBC_GET_ID_LIST;
1959 mcp->out_mb = MBX_0;
1960 if (IS_FWI2_CAPABLE(vha->hw)) {
1961 mcp->mb[2] = MSW(id_list_dma);
1962 mcp->mb[3] = LSW(id_list_dma);
1963 mcp->mb[6] = MSW(MSD(id_list_dma));
1964 mcp->mb[7] = LSW(MSD(id_list_dma));
1966 mcp->mb[9] = vha->vp_idx;
1967 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
1969 mcp->mb[1] = MSW(id_list_dma);
1970 mcp->mb[2] = LSW(id_list_dma);
1971 mcp->mb[3] = MSW(MSD(id_list_dma));
1972 mcp->mb[6] = LSW(MSD(id_list_dma));
1973 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1975 mcp->in_mb = MBX_1|MBX_0;
1976 mcp->tov = MBX_TOV_SECONDS;
1978 rval = qla2x00_mailbox_command(vha, mcp);
1980 if (rval != QLA_SUCCESS) {
1982 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
1983 vha->host_no, rval));
1985 *entries = mcp->mb[1];
1986 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
1994 * qla2x00_get_resource_cnts
1995 * Get current firmware resource counts.
1998 * ha = adapter block pointer.
2001 * qla2x00 local function return status code.
2007 qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
2008 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
2009 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports)
2013 mbx_cmd_t *mcp = &mc;
2015 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2017 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2018 mcp->out_mb = MBX_0;
2019 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2020 mcp->tov = MBX_TOV_SECONDS;
2022 rval = qla2x00_mailbox_command(vha, mcp);
2024 if (rval != QLA_SUCCESS) {
2026 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
2027 vha->host_no, mcp->mb[0]));
2029 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
2030 "mb7=%x mb10=%x mb11=%x.\n", __func__, vha->host_no,
2031 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
2032 mcp->mb[10], mcp->mb[11]));
2035 *cur_xchg_cnt = mcp->mb[3];
2037 *orig_xchg_cnt = mcp->mb[6];
2039 *cur_iocb_cnt = mcp->mb[7];
2041 *orig_iocb_cnt = mcp->mb[10];
2042 if (vha->hw->flags.npiv_supported && max_npiv_vports)
2043 *max_npiv_vports = mcp->mb[11];
2049 #if defined(QL_DEBUG_LEVEL_3)
2051 * qla2x00_get_fcal_position_map
2052 * Get FCAL (LILP) position map using mailbox command
2055 * ha = adapter state pointer.
2056 * pos_map = buffer pointer (can be NULL).
2059 * qla2x00 local function return status code.
2065 qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
2069 mbx_cmd_t *mcp = &mc;
2071 dma_addr_t pmap_dma;
2072 struct qla_hw_data *ha = vha->hw;
2074 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
2076 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
2077 __func__, vha->host_no));
2078 return QLA_MEMORY_ALLOC_FAILED;
2080 memset(pmap, 0, FCAL_MAP_SIZE);
2082 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2083 mcp->mb[2] = MSW(pmap_dma);
2084 mcp->mb[3] = LSW(pmap_dma);
2085 mcp->mb[6] = MSW(MSD(pmap_dma));
2086 mcp->mb[7] = LSW(MSD(pmap_dma));
2087 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2088 mcp->in_mb = MBX_1|MBX_0;
2089 mcp->buf_size = FCAL_MAP_SIZE;
2090 mcp->flags = MBX_DMA_IN;
2091 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2092 rval = qla2x00_mailbox_command(vha, mcp);
2094 if (rval == QLA_SUCCESS) {
2095 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2096 "size (%x)\n", __func__, vha->host_no, mcp->mb[0],
2097 mcp->mb[1], (unsigned)pmap[0]));
2098 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2101 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2103 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2105 if (rval != QLA_SUCCESS) {
2106 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2107 vha->host_no, rval));
2109 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2117 * qla2x00_get_link_status
2120 * ha = adapter block pointer.
2121 * loop_id = device loop ID.
2122 * ret_buf = pointer to link status return buffer.
2126 * BIT_0 = mem alloc error.
2127 * BIT_1 = mailbox error.
2130 qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
2131 struct link_statistics *stats, dma_addr_t stats_dma)
2135 mbx_cmd_t *mcp = &mc;
2136 uint32_t *siter, *diter, dwords;
2137 struct qla_hw_data *ha = vha->hw;
2139 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2141 mcp->mb[0] = MBC_GET_LINK_STATUS;
2142 mcp->mb[2] = MSW(stats_dma);
2143 mcp->mb[3] = LSW(stats_dma);
2144 mcp->mb[6] = MSW(MSD(stats_dma));
2145 mcp->mb[7] = LSW(MSD(stats_dma));
2146 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2148 if (IS_FWI2_CAPABLE(ha)) {
2149 mcp->mb[1] = loop_id;
2152 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2153 mcp->in_mb |= MBX_1;
2154 } else if (HAS_EXTENDED_IDS(ha)) {
2155 mcp->mb[1] = loop_id;
2157 mcp->out_mb |= MBX_10|MBX_1;
2159 mcp->mb[1] = loop_id << 8;
2160 mcp->out_mb |= MBX_1;
2162 mcp->tov = MBX_TOV_SECONDS;
2163 mcp->flags = IOCTL_CMD;
2164 rval = qla2x00_mailbox_command(vha, mcp);
2166 if (rval == QLA_SUCCESS) {
2167 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2168 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2169 __func__, vha->host_no, mcp->mb[0]));
2170 rval = QLA_FUNCTION_FAILED;
2172 /* Copy over data -- firmware data is LE. */
2173 dwords = offsetof(struct link_statistics, unused1) / 4;
2174 siter = diter = &stats->link_fail_cnt;
2176 *diter++ = le32_to_cpu(*siter++);
2180 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2181 vha->host_no, rval));
2188 qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
2189 dma_addr_t stats_dma)
2193 mbx_cmd_t *mcp = &mc;
2194 uint32_t *siter, *diter, dwords;
2196 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2198 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2199 mcp->mb[2] = MSW(stats_dma);
2200 mcp->mb[3] = LSW(stats_dma);
2201 mcp->mb[6] = MSW(MSD(stats_dma));
2202 mcp->mb[7] = LSW(MSD(stats_dma));
2203 mcp->mb[8] = sizeof(struct link_statistics) / 4;
2204 mcp->mb[9] = vha->vp_idx;
2206 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2207 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2208 mcp->tov = MBX_TOV_SECONDS;
2209 mcp->flags = IOCTL_CMD;
2210 rval = qla2x00_mailbox_command(vha, mcp);
2212 if (rval == QLA_SUCCESS) {
2213 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2214 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2215 __func__, vha->host_no, mcp->mb[0]));
2216 rval = QLA_FUNCTION_FAILED;
2218 /* Copy over data -- firmware data is LE. */
2219 dwords = sizeof(struct link_statistics) / 4;
2220 siter = diter = &stats->link_fail_cnt;
2222 *diter++ = le32_to_cpu(*siter++);
2226 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2227 vha->host_no, rval));
2234 qla24xx_abort_command(srb_t *sp)
2237 unsigned long flags = 0;
2239 struct abort_entry_24xx *abt;
2242 fc_port_t *fcport = sp->fcport;
2243 struct scsi_qla_host *vha = fcport->vha;
2244 struct qla_hw_data *ha = vha->hw;
2245 struct req_que *req = vha->req;
2247 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2249 spin_lock_irqsave(&ha->hardware_lock, flags);
2250 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2251 if (req->outstanding_cmds[handle] == sp)
2254 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2255 if (handle == MAX_OUTSTANDING_COMMANDS) {
2256 /* Command not found. */
2257 return QLA_FUNCTION_FAILED;
2260 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2262 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2263 __func__, vha->host_no));
2264 return QLA_MEMORY_ALLOC_FAILED;
2266 memset(abt, 0, sizeof(struct abort_entry_24xx));
2268 abt->entry_type = ABORT_IOCB_TYPE;
2269 abt->entry_count = 1;
2270 abt->handle = MAKE_HANDLE(req->id, abt->handle);
2271 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2272 abt->handle_to_abort = handle;
2273 abt->port_id[0] = fcport->d_id.b.al_pa;
2274 abt->port_id[1] = fcport->d_id.b.area;
2275 abt->port_id[2] = fcport->d_id.b.domain;
2276 abt->vp_index = fcport->vp_idx;
2278 abt->req_que_no = cpu_to_le16(req->id);
2280 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
2281 if (rval != QLA_SUCCESS) {
2282 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2283 __func__, vha->host_no, rval));
2284 } else if (abt->entry_status != 0) {
2285 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2286 "-- error status (%x).\n", __func__, vha->host_no,
2287 abt->entry_status));
2288 rval = QLA_FUNCTION_FAILED;
2289 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2290 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2291 "-- completion status (%x).\n", __func__, vha->host_no,
2292 le16_to_cpu(abt->nport_handle)));
2293 rval = QLA_FUNCTION_FAILED;
2295 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2298 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2303 struct tsk_mgmt_cmd {
2305 struct tsk_mgmt_entry tsk;
2306 struct sts_entry_24xx sts;
2311 __qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
2312 unsigned int l, int tag)
2315 struct tsk_mgmt_cmd *tsk;
2317 scsi_qla_host_t *vha;
2318 struct qla_hw_data *ha;
2319 struct req_que *req;
2320 struct rsp_que *rsp;
2322 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
2327 if (ha->flags.cpu_affinity_enabled)
2328 rsp = ha->rsp_q_map[tag + 1];
2331 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
2333 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2334 "IOCB.\n", __func__, vha->host_no));
2335 return QLA_MEMORY_ALLOC_FAILED;
2337 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2339 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2340 tsk->p.tsk.entry_count = 1;
2341 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
2342 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2343 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
2344 tsk->p.tsk.control_flags = cpu_to_le32(type);
2345 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2346 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2347 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2348 tsk->p.tsk.vp_index = fcport->vp_idx;
2349 if (type == TCF_LUN_RESET) {
2350 int_to_scsilun(l, &tsk->p.tsk.lun);
2351 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2352 sizeof(tsk->p.tsk.lun));
2355 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
2356 if (rval != QLA_SUCCESS) {
2357 DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
2358 "(%x).\n", __func__, vha->host_no, name, rval));
2359 } else if (tsk->p.sts.entry_status != 0) {
2360 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2361 "-- error status (%x).\n", __func__, vha->host_no,
2362 tsk->p.sts.entry_status));
2363 rval = QLA_FUNCTION_FAILED;
2364 } else if (tsk->p.sts.comp_status !=
2365 __constant_cpu_to_le16(CS_COMPLETE)) {
2366 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2367 "-- completion status (%x).\n", __func__,
2368 vha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
2369 rval = QLA_FUNCTION_FAILED;
2372 /* Issue marker IOCB. */
2373 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
2374 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2375 if (rval2 != QLA_SUCCESS) {
2376 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2377 "(%x).\n", __func__, vha->host_no, rval2));
2379 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2382 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
2388 qla24xx_abort_target(struct fc_port *fcport, unsigned int l, int tag)
2390 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
2394 qla24xx_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
2396 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
2400 qla2x00_system_error(scsi_qla_host_t *vha)
2404 mbx_cmd_t *mcp = &mc;
2405 struct qla_hw_data *ha = vha->hw;
2407 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
2408 return QLA_FUNCTION_FAILED;
2410 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2412 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2413 mcp->out_mb = MBX_0;
2417 rval = qla2x00_mailbox_command(vha, mcp);
2419 if (rval != QLA_SUCCESS) {
2420 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2421 vha->host_no, rval));
2423 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2430 * qla2x00_set_serdes_params() -
2436 qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
2437 uint16_t sw_em_2g, uint16_t sw_em_4g)
2441 mbx_cmd_t *mcp = &mc;
2443 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2445 mcp->mb[0] = MBC_SERDES_PARAMS;
2447 mcp->mb[2] = sw_em_1g | BIT_15;
2448 mcp->mb[3] = sw_em_2g | BIT_15;
2449 mcp->mb[4] = sw_em_4g | BIT_15;
2450 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2452 mcp->tov = MBX_TOV_SECONDS;
2454 rval = qla2x00_mailbox_command(vha, mcp);
2456 if (rval != QLA_SUCCESS) {
2458 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2459 vha->host_no, rval, mcp->mb[0]));
2462 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2469 qla2x00_stop_firmware(scsi_qla_host_t *vha)
2473 mbx_cmd_t *mcp = &mc;
2475 if (!IS_FWI2_CAPABLE(vha->hw))
2476 return QLA_FUNCTION_FAILED;
2478 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2480 mcp->mb[0] = MBC_STOP_FIRMWARE;
2481 mcp->out_mb = MBX_0;
2485 rval = qla2x00_mailbox_command(vha, mcp);
2487 if (rval != QLA_SUCCESS) {
2488 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2489 vha->host_no, rval));
2490 if (mcp->mb[0] == MBS_INVALID_COMMAND)
2491 rval = QLA_INVALID_COMMAND;
2493 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2500 qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
2505 mbx_cmd_t *mcp = &mc;
2507 if (!IS_FWI2_CAPABLE(vha->hw))
2508 return QLA_FUNCTION_FAILED;
2510 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2512 mcp->mb[0] = MBC_TRACE_CONTROL;
2513 mcp->mb[1] = TC_EFT_ENABLE;
2514 mcp->mb[2] = LSW(eft_dma);
2515 mcp->mb[3] = MSW(eft_dma);
2516 mcp->mb[4] = LSW(MSD(eft_dma));
2517 mcp->mb[5] = MSW(MSD(eft_dma));
2518 mcp->mb[6] = buffers;
2519 mcp->mb[7] = TC_AEN_DISABLE;
2520 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2521 mcp->in_mb = MBX_1|MBX_0;
2522 mcp->tov = MBX_TOV_SECONDS;
2524 rval = qla2x00_mailbox_command(vha, mcp);
2525 if (rval != QLA_SUCCESS) {
2526 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2527 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2529 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2536 qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
2540 mbx_cmd_t *mcp = &mc;
2542 if (!IS_FWI2_CAPABLE(vha->hw))
2543 return QLA_FUNCTION_FAILED;
2545 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2547 mcp->mb[0] = MBC_TRACE_CONTROL;
2548 mcp->mb[1] = TC_EFT_DISABLE;
2549 mcp->out_mb = MBX_1|MBX_0;
2550 mcp->in_mb = MBX_1|MBX_0;
2551 mcp->tov = MBX_TOV_SECONDS;
2553 rval = qla2x00_mailbox_command(vha, mcp);
2554 if (rval != QLA_SUCCESS) {
2555 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2556 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2558 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2565 qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
2566 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2570 mbx_cmd_t *mcp = &mc;
2572 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw))
2573 return QLA_FUNCTION_FAILED;
2575 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2577 mcp->mb[0] = MBC_TRACE_CONTROL;
2578 mcp->mb[1] = TC_FCE_ENABLE;
2579 mcp->mb[2] = LSW(fce_dma);
2580 mcp->mb[3] = MSW(fce_dma);
2581 mcp->mb[4] = LSW(MSD(fce_dma));
2582 mcp->mb[5] = MSW(MSD(fce_dma));
2583 mcp->mb[6] = buffers;
2584 mcp->mb[7] = TC_AEN_DISABLE;
2586 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2587 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2588 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2590 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2591 mcp->tov = MBX_TOV_SECONDS;
2593 rval = qla2x00_mailbox_command(vha, mcp);
2594 if (rval != QLA_SUCCESS) {
2595 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2596 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2598 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2601 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2610 qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
2614 mbx_cmd_t *mcp = &mc;
2616 if (!IS_FWI2_CAPABLE(vha->hw))
2617 return QLA_FUNCTION_FAILED;
2619 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2621 mcp->mb[0] = MBC_TRACE_CONTROL;
2622 mcp->mb[1] = TC_FCE_DISABLE;
2623 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
2624 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2625 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2627 mcp->tov = MBX_TOV_SECONDS;
2629 rval = qla2x00_mailbox_command(vha, mcp);
2630 if (rval != QLA_SUCCESS) {
2631 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2632 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2634 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2637 *wr = (uint64_t) mcp->mb[5] << 48 |
2638 (uint64_t) mcp->mb[4] << 32 |
2639 (uint64_t) mcp->mb[3] << 16 |
2640 (uint64_t) mcp->mb[2];
2642 *rd = (uint64_t) mcp->mb[9] << 48 |
2643 (uint64_t) mcp->mb[8] << 32 |
2644 (uint64_t) mcp->mb[7] << 16 |
2645 (uint64_t) mcp->mb[6];
2652 qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint16_t addr,
2653 uint16_t off, uint16_t count)
2657 mbx_cmd_t *mcp = &mc;
2659 if (!IS_FWI2_CAPABLE(vha->hw))
2660 return QLA_FUNCTION_FAILED;
2662 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2664 mcp->mb[0] = MBC_READ_SFP;
2666 mcp->mb[2] = MSW(sfp_dma);
2667 mcp->mb[3] = LSW(sfp_dma);
2668 mcp->mb[6] = MSW(MSD(sfp_dma));
2669 mcp->mb[7] = LSW(MSD(sfp_dma));
2673 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2675 mcp->tov = MBX_TOV_SECONDS;
2677 rval = qla2x00_mailbox_command(vha, mcp);
2679 if (rval != QLA_SUCCESS) {
2680 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2681 vha->host_no, rval, mcp->mb[0]));
2683 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2690 qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
2691 uint16_t port_speed, uint16_t *mb)
2695 mbx_cmd_t *mcp = &mc;
2697 if (!IS_IIDMA_CAPABLE(vha->hw))
2698 return QLA_FUNCTION_FAILED;
2700 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2702 mcp->mb[0] = MBC_PORT_PARAMS;
2703 mcp->mb[1] = loop_id;
2705 if (IS_QLA81XX(vha->hw))
2706 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
2708 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2709 mcp->mb[9] = vha->vp_idx;
2710 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
2711 mcp->in_mb = MBX_3|MBX_1|MBX_0;
2712 mcp->tov = MBX_TOV_SECONDS;
2714 rval = qla2x00_mailbox_command(vha, mcp);
2716 /* Return mailbox statuses. */
2723 if (rval != QLA_SUCCESS) {
2724 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2725 vha->host_no, rval));
2727 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2734 qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
2735 struct vp_rpt_id_entry_24xx *rptid_entry)
2738 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
2739 struct qla_hw_data *ha = vha->hw;
2740 scsi_qla_host_t *vp;
2741 scsi_qla_host_t *tvp;
2743 if (rptid_entry->entry_status != 0)
2746 if (rptid_entry->format == 0) {
2747 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
2748 " number of VPs acquired %d\n", __func__, vha->host_no,
2749 MSB(le16_to_cpu(rptid_entry->vp_count)),
2750 LSB(le16_to_cpu(rptid_entry->vp_count))));
2751 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2752 rptid_entry->port_id[2], rptid_entry->port_id[1],
2753 rptid_entry->port_id[0]));
2754 } else if (rptid_entry->format == 1) {
2756 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2758 "with port id %02x%02x%02x\n", __func__, vha->host_no,
2760 rptid_entry->port_id[2], rptid_entry->port_id[1],
2761 rptid_entry->port_id[0]));
2765 if (MSB(stat) == 1) {
2766 DEBUG2(printk("scsi(%ld): Could not acquire ID for "
2767 "VP[%d].\n", vha->host_no, vp_idx));
2771 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
2772 if (vp_idx == vp->vp_idx)
2777 vp->d_id.b.domain = rptid_entry->port_id[2];
2778 vp->d_id.b.area = rptid_entry->port_id[1];
2779 vp->d_id.b.al_pa = rptid_entry->port_id[0];
2782 * Cannot configure here as we are still sitting on the
2783 * response queue. Handle it in dpc context.
2785 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
2786 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
2788 qla2xxx_wake_dpc(vha);
2793 * qla24xx_modify_vp_config
2794 * Change VP configuration for vha
2797 * vha = adapter block pointer.
2800 * qla2xxx local function return status code.
2806 qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2809 struct vp_config_entry_24xx *vpmod;
2810 dma_addr_t vpmod_dma;
2811 struct qla_hw_data *ha = vha->hw;
2812 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2814 /* This can be called by the parent */
2816 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
2818 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
2819 "IOCB.\n", __func__, vha->host_no));
2820 return QLA_MEMORY_ALLOC_FAILED;
2823 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2824 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2825 vpmod->entry_count = 1;
2826 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2827 vpmod->vp_count = 1;
2828 vpmod->vp_index1 = vha->vp_idx;
2829 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2830 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2831 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2832 vpmod->entry_count = 1;
2834 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
2835 if (rval != QLA_SUCCESS) {
2836 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
2837 "(%x).\n", __func__, base_vha->host_no, rval));
2838 } else if (vpmod->comp_status != 0) {
2839 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2840 "-- error status (%x).\n", __func__, base_vha->host_no,
2841 vpmod->comp_status));
2842 rval = QLA_FUNCTION_FAILED;
2843 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2844 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2845 "-- completion status (%x).\n", __func__, base_vha->host_no,
2846 le16_to_cpu(vpmod->comp_status)));
2847 rval = QLA_FUNCTION_FAILED;
2850 DEBUG11(printk("%s(%ld): done.\n", __func__,
2851 base_vha->host_no));
2852 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2854 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
2860 * qla24xx_control_vp
2861 * Enable a virtual port for given host
2864 * ha = adapter block pointer.
2865 * vhba = virtual adapter (unused)
2866 * index = index number for enabled VP
2869 * qla2xxx local function return status code.
2875 qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2879 struct vp_ctrl_entry_24xx *vce;
2881 struct qla_hw_data *ha = vha->hw;
2882 int vp_index = vha->vp_idx;
2883 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2885 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
2886 vha->host_no, vp_index));
2888 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
2889 return QLA_PARAMETER_ERROR;
2891 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2893 DEBUG2_3(printk("%s(%ld): "
2894 "failed to allocate VP Control IOCB.\n", __func__,
2895 base_vha->host_no));
2896 return QLA_MEMORY_ALLOC_FAILED;
2898 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2900 vce->entry_type = VP_CTRL_IOCB_TYPE;
2901 vce->entry_count = 1;
2902 vce->command = cpu_to_le16(cmd);
2903 vce->vp_count = __constant_cpu_to_le16(1);
2905 /* index map in firmware starts with 1; decrement index
2906 * this is ok as we never use index 0
2908 map = (vp_index - 1) / 8;
2909 pos = (vp_index - 1) & 7;
2910 mutex_lock(&ha->vport_lock);
2911 vce->vp_idx_map[map] |= 1 << pos;
2912 mutex_unlock(&ha->vport_lock);
2914 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
2915 if (rval != QLA_SUCCESS) {
2916 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
2917 "(%x).\n", __func__, base_vha->host_no, rval));
2918 printk("%s(%ld): failed to issue VP control IOCB"
2919 "(%x).\n", __func__, base_vha->host_no, rval);
2920 } else if (vce->entry_status != 0) {
2921 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2922 "-- error status (%x).\n", __func__, base_vha->host_no,
2923 vce->entry_status));
2924 printk("%s(%ld): failed to complete IOCB "
2925 "-- error status (%x).\n", __func__, base_vha->host_no,
2927 rval = QLA_FUNCTION_FAILED;
2928 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2929 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2930 "-- completion status (%x).\n", __func__, base_vha->host_no,
2931 le16_to_cpu(vce->comp_status)));
2932 printk("%s(%ld): failed to complete IOCB "
2933 "-- completion status (%x).\n", __func__, base_vha->host_no,
2934 le16_to_cpu(vce->comp_status));
2935 rval = QLA_FUNCTION_FAILED;
2937 DEBUG2(printk("%s(%ld): done.\n", __func__, base_vha->host_no));
2940 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
2946 * qla2x00_send_change_request
2947 * Receive or disable RSCN request from fabric controller
2950 * ha = adapter block pointer
2951 * format = registration format:
2953 * 1 - Fabric detected registration
2954 * 2 - N_port detected registration
2955 * 3 - Full registration
2956 * FF - clear registration
2957 * vp_idx = Virtual port index
2960 * qla2x00 local function return status code.
2967 qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
2972 mbx_cmd_t *mcp = &mc;
2975 * This command is implicitly executed by firmware during login for the
2979 return QLA_FUNCTION_FAILED;
2981 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
2982 mcp->mb[1] = format;
2983 mcp->mb[9] = vp_idx;
2984 mcp->out_mb = MBX_9|MBX_1|MBX_0;
2985 mcp->in_mb = MBX_0|MBX_1;
2986 mcp->tov = MBX_TOV_SECONDS;
2988 rval = qla2x00_mailbox_command(vha, mcp);
2990 if (rval == QLA_SUCCESS) {
2991 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
3001 qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
3006 mbx_cmd_t *mcp = &mc;
3008 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3010 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
3011 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3012 mcp->mb[8] = MSW(addr);
3013 mcp->out_mb = MBX_8|MBX_0;
3015 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3016 mcp->out_mb = MBX_0;
3018 mcp->mb[1] = LSW(addr);
3019 mcp->mb[2] = MSW(req_dma);
3020 mcp->mb[3] = LSW(req_dma);
3021 mcp->mb[6] = MSW(MSD(req_dma));
3022 mcp->mb[7] = LSW(MSD(req_dma));
3023 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
3024 if (IS_FWI2_CAPABLE(vha->hw)) {
3025 mcp->mb[4] = MSW(size);
3026 mcp->mb[5] = LSW(size);
3027 mcp->out_mb |= MBX_5|MBX_4;
3029 mcp->mb[4] = LSW(size);
3030 mcp->out_mb |= MBX_4;
3034 mcp->tov = MBX_TOV_SECONDS;
3036 rval = qla2x00_mailbox_command(vha, mcp);
3038 if (rval != QLA_SUCCESS) {
3039 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3040 vha->host_no, rval, mcp->mb[0]));
3042 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3048 /* 84XX Support **************************************************************/
3050 struct cs84xx_mgmt_cmd {
3052 struct verify_chip_entry_84xx req;
3053 struct verify_chip_rsp_84xx rsp;
3058 qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
3061 struct cs84xx_mgmt_cmd *mn;
3064 unsigned long flags;
3065 struct qla_hw_data *ha = vha->hw;
3067 DEBUG16(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3069 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
3071 DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX "
3072 "IOCB.\n", __func__, vha->host_no));
3073 return QLA_MEMORY_ALLOC_FAILED;
3077 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
3078 /* Diagnostic firmware? */
3079 /* options |= MENLO_DIAG_FW; */
3080 /* We update the firmware with only one data sequence. */
3081 options |= VCO_END_OF_DATA;
3085 memset(mn, 0, sizeof(*mn));
3086 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
3087 mn->p.req.entry_count = 1;
3088 mn->p.req.options = cpu_to_le16(options);
3090 DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__,
3092 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3095 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
3096 if (rval != QLA_SUCCESS) {
3097 DEBUG2_16(printk("%s(%ld): failed to issue Verify "
3098 "IOCB (%x).\n", __func__, vha->host_no, rval));
3102 DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__,
3104 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3107 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3108 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3109 le16_to_cpu(mn->p.rsp.failure_code) : 0;
3110 DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__,
3111 vha->host_no, status[0], status[1]));
3113 if (status[0] != CS_COMPLETE) {
3114 rval = QLA_FUNCTION_FAILED;
3115 if (!(options & VCO_DONT_UPDATE_FW)) {
3116 DEBUG2_16(printk("%s(%ld): Firmware update "
3117 "failed. Retrying without update "
3118 "firmware.\n", __func__, vha->host_no));
3119 options |= VCO_DONT_UPDATE_FW;
3120 options &= ~VCO_FORCE_UPDATE;
3124 DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n",
3125 __func__, vha->host_no,
3126 le32_to_cpu(mn->p.rsp.fw_ver)));
3128 /* NOTE: we only update OP firmware. */
3129 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3130 ha->cs84xx->op_fw_version =
3131 le32_to_cpu(mn->p.rsp.fw_ver);
3132 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3138 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3140 if (rval != QLA_SUCCESS) {
3141 DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__,
3142 vha->host_no, rval));
3144 DEBUG16(printk("%s(%ld): done.\n", __func__, vha->host_no));
3151 qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
3154 unsigned long flags;
3156 mbx_cmd_t *mcp = &mc;
3157 struct device_reg_25xxmq __iomem *reg;
3158 struct qla_hw_data *ha = vha->hw;
3160 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
3161 mcp->mb[1] = req->options;
3162 mcp->mb[2] = MSW(LSD(req->dma));
3163 mcp->mb[3] = LSW(LSD(req->dma));
3164 mcp->mb[6] = MSW(MSD(req->dma));
3165 mcp->mb[7] = LSW(MSD(req->dma));
3166 mcp->mb[5] = req->length;
3168 mcp->mb[10] = req->rsp->id;
3169 mcp->mb[12] = req->qos;
3170 mcp->mb[11] = req->vp_idx;
3171 mcp->mb[13] = req->rid;
3173 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3174 QLA_QUE_PAGE * req->id);
3176 mcp->mb[4] = req->id;
3177 /* que in ptr index */
3179 /* que out ptr index */
3181 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
3182 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3184 mcp->flags = MBX_DMA_OUT;
3187 spin_lock_irqsave(&ha->hardware_lock, flags);
3188 if (!(req->options & BIT_0)) {
3189 WRT_REG_DWORD(®->req_q_in, 0);
3190 WRT_REG_DWORD(®->req_q_out, 0);
3192 req->req_q_in = ®->req_q_in;
3193 req->req_q_out = ®->req_q_out;
3194 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3196 rval = qla2x00_mailbox_command(vha, mcp);
3197 if (rval != QLA_SUCCESS)
3198 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x mb0=%x.\n",
3199 __func__, vha->host_no, rval, mcp->mb[0]));
3204 qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
3207 unsigned long flags;
3209 mbx_cmd_t *mcp = &mc;
3210 struct device_reg_25xxmq __iomem *reg;
3211 struct qla_hw_data *ha = vha->hw;
3213 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
3214 mcp->mb[1] = rsp->options;
3215 mcp->mb[2] = MSW(LSD(rsp->dma));
3216 mcp->mb[3] = LSW(LSD(rsp->dma));
3217 mcp->mb[6] = MSW(MSD(rsp->dma));
3218 mcp->mb[7] = LSW(MSD(rsp->dma));
3219 mcp->mb[5] = rsp->length;
3220 mcp->mb[14] = rsp->msix->entry;
3221 mcp->mb[13] = rsp->rid;
3223 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3224 QLA_QUE_PAGE * rsp->id);
3226 mcp->mb[4] = rsp->id;
3227 /* que in ptr index */
3229 /* que out ptr index */
3231 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
3232 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3234 mcp->flags = MBX_DMA_OUT;
3237 spin_lock_irqsave(&ha->hardware_lock, flags);
3238 if (!(rsp->options & BIT_0)) {
3239 WRT_REG_DWORD(®->rsp_q_out, 0);
3240 WRT_REG_DWORD(®->rsp_q_in, 0);
3243 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3245 rval = qla2x00_mailbox_command(vha, mcp);
3246 if (rval != QLA_SUCCESS)
3247 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x "
3248 "mb0=%x.\n", __func__,
3249 vha->host_no, rval, mcp->mb[0]));
3254 qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
3258 mbx_cmd_t *mcp = &mc;
3260 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3262 mcp->mb[0] = MBC_IDC_ACK;
3263 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
3264 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3266 mcp->tov = MBX_TOV_SECONDS;
3268 rval = qla2x00_mailbox_command(vha, mcp);
3270 if (rval != QLA_SUCCESS) {
3271 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3272 vha->host_no, rval, mcp->mb[0]));
3274 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3281 qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
3285 mbx_cmd_t *mcp = &mc;
3287 if (!IS_QLA81XX(vha->hw))
3288 return QLA_FUNCTION_FAILED;
3290 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3292 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3293 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
3294 mcp->out_mb = MBX_1|MBX_0;
3295 mcp->in_mb = MBX_1|MBX_0;
3296 mcp->tov = MBX_TOV_SECONDS;
3298 rval = qla2x00_mailbox_command(vha, mcp);
3300 if (rval != QLA_SUCCESS) {
3301 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
3302 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3304 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3305 *sector_size = mcp->mb[1];
3312 qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
3316 mbx_cmd_t *mcp = &mc;
3318 if (!IS_QLA81XX(vha->hw))
3319 return QLA_FUNCTION_FAILED;
3321 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3323 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3324 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
3325 FAC_OPT_CMD_WRITE_PROTECT;
3326 mcp->out_mb = MBX_1|MBX_0;
3327 mcp->in_mb = MBX_1|MBX_0;
3328 mcp->tov = MBX_TOV_SECONDS;
3330 rval = qla2x00_mailbox_command(vha, mcp);
3332 if (rval != QLA_SUCCESS) {
3333 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
3334 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3336 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3343 qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
3347 mbx_cmd_t *mcp = &mc;
3349 if (!IS_QLA81XX(vha->hw))
3350 return QLA_FUNCTION_FAILED;
3352 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3354 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3355 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
3356 mcp->mb[2] = LSW(start);
3357 mcp->mb[3] = MSW(start);
3358 mcp->mb[4] = LSW(finish);
3359 mcp->mb[5] = MSW(finish);
3360 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3361 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3362 mcp->tov = MBX_TOV_SECONDS;
3364 rval = qla2x00_mailbox_command(vha, mcp);
3366 if (rval != QLA_SUCCESS) {
3367 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
3368 "mb[2]=%x.\n", __func__, vha->host_no, rval, mcp->mb[0],
3369 mcp->mb[1], mcp->mb[2]));
3371 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3378 qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
3382 mbx_cmd_t *mcp = &mc;
3384 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3386 mcp->mb[0] = MBC_RESTART_MPI_FW;
3387 mcp->out_mb = MBX_0;
3388 mcp->in_mb = MBX_0|MBX_1;
3389 mcp->tov = MBX_TOV_SECONDS;
3391 rval = qla2x00_mailbox_command(vha, mcp);
3393 if (rval != QLA_SUCCESS) {
3394 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x mb[1]=0x%x.\n",
3395 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3397 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3404 qla2x00_read_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
3405 dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
3409 mbx_cmd_t *mcp = &mc;
3411 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3413 mcp->mb[0] = MBC_READ_SFP;
3415 mcp->mb[2] = MSW(sfp_dma);
3416 mcp->mb[3] = LSW(sfp_dma);
3417 mcp->mb[6] = MSW(MSD(sfp_dma));
3418 mcp->mb[7] = LSW(MSD(sfp_dma));
3422 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3424 mcp->tov = MBX_TOV_SECONDS;
3426 rval = qla2x00_mailbox_command(vha, mcp);
3432 if (rval != QLA_SUCCESS) {
3433 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3434 vha->host_no, rval, mcp->mb[0]));
3436 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3443 qla2x00_write_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
3444 dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
3448 mbx_cmd_t *mcp = &mc;
3450 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3456 mcp->mb[0] = MBC_WRITE_SFP;
3458 mcp->mb[2] = MSW(sfp_dma);
3459 mcp->mb[3] = LSW(sfp_dma);
3460 mcp->mb[6] = MSW(MSD(sfp_dma));
3461 mcp->mb[7] = LSW(MSD(sfp_dma));
3465 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3467 mcp->tov = MBX_TOV_SECONDS;
3469 rval = qla2x00_mailbox_command(vha, mcp);
3471 if (rval != QLA_SUCCESS) {
3472 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3473 vha->host_no, rval, mcp->mb[0]));
3475 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3482 qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
3483 uint16_t size_in_bytes, uint16_t *actual_size)
3487 mbx_cmd_t *mcp = &mc;
3489 if (!IS_QLA81XX(vha->hw))
3490 return QLA_FUNCTION_FAILED;
3492 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3494 mcp->mb[0] = MBC_GET_XGMAC_STATS;
3495 mcp->mb[2] = MSW(stats_dma);
3496 mcp->mb[3] = LSW(stats_dma);
3497 mcp->mb[6] = MSW(MSD(stats_dma));
3498 mcp->mb[7] = LSW(MSD(stats_dma));
3499 mcp->mb[8] = size_in_bytes >> 2;
3500 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
3501 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3502 mcp->tov = MBX_TOV_SECONDS;
3504 rval = qla2x00_mailbox_command(vha, mcp);
3506 if (rval != QLA_SUCCESS) {
3507 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x "
3508 "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval,
3509 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
3511 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3513 *actual_size = mcp->mb[2] << 2;
3520 qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
3525 mbx_cmd_t *mcp = &mc;
3527 if (!IS_QLA81XX(vha->hw))
3528 return QLA_FUNCTION_FAILED;
3530 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3532 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
3534 mcp->mb[2] = MSW(tlv_dma);
3535 mcp->mb[3] = LSW(tlv_dma);
3536 mcp->mb[6] = MSW(MSD(tlv_dma));
3537 mcp->mb[7] = LSW(MSD(tlv_dma));
3539 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3540 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3541 mcp->tov = MBX_TOV_SECONDS;
3543 rval = qla2x00_mailbox_command(vha, mcp);
3545 if (rval != QLA_SUCCESS) {
3546 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x "
3547 "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval,
3548 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
3550 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3557 qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
3561 mbx_cmd_t *mcp = &mc;
3563 if (!IS_FWI2_CAPABLE(vha->hw))
3564 return QLA_FUNCTION_FAILED;
3566 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3568 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
3569 mcp->mb[1] = LSW(risc_addr);
3570 mcp->mb[8] = MSW(risc_addr);
3571 mcp->out_mb = MBX_8|MBX_1|MBX_0;
3572 mcp->in_mb = MBX_3|MBX_2|MBX_0;
3575 rval = qla2x00_mailbox_command(vha, mcp);
3576 if (rval != QLA_SUCCESS) {
3577 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3578 vha->host_no, rval, mcp->mb[0]));
3580 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3581 *data = mcp->mb[3] << 16 | mcp->mb[2];
3588 qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
3592 mbx_cmd_t *mcp = &mc;
3594 if (!IS_FWI2_CAPABLE(vha->hw))
3595 return QLA_FUNCTION_FAILED;
3597 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3599 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
3600 mcp->mb[1] = LSW(risc_addr);
3601 mcp->mb[2] = LSW(data);
3602 mcp->mb[3] = MSW(data);
3603 mcp->mb[8] = MSW(risc_addr);
3604 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
3608 rval = qla2x00_mailbox_command(vha, mcp);
3609 if (rval != QLA_SUCCESS) {
3610 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3611 vha->host_no, rval, mcp->mb[0]));
3613 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));