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);
49 io_lock_on = base_vha->flags.init_done;
52 abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
54 DEBUG11(printk("%s(%ld): entered.\n", __func__, base_vha->host_no));
57 * Wait for active mailbox commands to finish by waiting at most tov
58 * seconds. This is to serialize actual issuing of mailbox cmds during
62 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp,
64 /* Timeout occurred. Return error. */
65 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
66 "Exiting.\n", __func__, base_vha->host_no));
67 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) {
128 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
130 if (IS_FWI2_CAPABLE(ha))
131 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
133 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
134 spin_unlock_irqrestore(&ha->hardware_lock, flags);
136 wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ);
138 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
141 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
142 base_vha->host_no, command));
144 if (IS_FWI2_CAPABLE(ha))
145 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
147 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
148 spin_unlock_irqrestore(&ha->hardware_lock, flags);
150 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
151 while (!ha->flags.mbox_int) {
152 if (time_after(jiffies, wait_time))
155 /* Check for pending interrupts. */
156 qla2x00_poll(ha->rsp_q_map[0]);
158 if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
164 /* Check whether we timed out */
165 if (ha->flags.mbox_int) {
168 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
169 base_vha->host_no, command));
171 /* Got interrupt. Clear the flag. */
172 ha->flags.mbox_int = 0;
173 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
175 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
176 rval = QLA_FUNCTION_FAILED;
178 /* Load return mailbox registers. */
180 iptr = (uint16_t *)&ha->mailbox_out[0];
182 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
192 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
193 defined(QL_DEBUG_LEVEL_11)
197 if (IS_FWI2_CAPABLE(ha)) {
198 mb0 = RD_REG_WORD(®->isp24.mailbox0);
199 ictrl = RD_REG_DWORD(®->isp24.ictrl);
201 mb0 = RD_MAILBOX_REG(ha, ®->isp, 0);
202 ictrl = RD_REG_WORD(®->isp.ictrl);
204 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
205 __func__, base_vha->host_no, command);
206 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
207 base_vha->host_no, ictrl, jiffies);
208 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
209 base_vha->host_no, mb0);
210 qla2x00_dump_regs(base_vha);
213 rval = QLA_FUNCTION_TIMEOUT;
216 ha->flags.mbox_busy = 0;
221 if (abort_active || !io_lock_on) {
222 DEBUG11(printk("%s(%ld): checking for additional resp "
223 "interrupt.\n", __func__, base_vha->host_no));
225 /* polling mode for non isp_abort commands. */
226 qla2x00_poll(ha->rsp_q_map[0]);
229 if (rval == QLA_FUNCTION_TIMEOUT &&
230 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
231 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
232 /* not in dpc. schedule it for dpc to take over. */
233 DEBUG(printk("%s(%ld): timeout schedule "
234 "isp_abort_needed.\n", __func__,
236 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
237 "isp_abort_needed.\n", __func__,
239 qla_printk(KERN_WARNING, ha,
240 "Mailbox command timeout occurred. Scheduling ISP "
242 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
243 qla2xxx_wake_dpc(vha);
244 } else if (!abort_active) {
245 /* call abort directly since we are in the DPC thread */
246 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
247 __func__, base_vha->host_no));
248 DEBUG2_3_11(printk("%s(%ld): timeout calling "
249 "abort_isp\n", __func__, base_vha->host_no));
250 qla_printk(KERN_WARNING, ha,
251 "Mailbox command timeout occurred. Issuing ISP "
254 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
255 clear_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
256 if (qla2x00_abort_isp(base_vha)) {
257 /* Failed. retry later. */
258 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
260 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
261 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
263 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
264 __func__, base_vha->host_no));
268 /* Allow next mbx cmd to come in. */
270 complete(&ha->mbx_cmd_comp);
273 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
274 "mbx2=%x, cmd=%x ****\n", __func__, base_vha->host_no,
275 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
277 DEBUG11(printk("%s(%ld): done.\n", __func__,
285 qla2x00_load_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t risc_addr,
286 uint32_t risc_code_size)
289 struct qla_hw_data *ha = vha->hw;
291 mbx_cmd_t *mcp = &mc;
293 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
295 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
296 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
297 mcp->mb[8] = MSW(risc_addr);
298 mcp->out_mb = MBX_8|MBX_0;
300 mcp->mb[0] = MBC_LOAD_RISC_RAM;
303 mcp->mb[1] = LSW(risc_addr);
304 mcp->mb[2] = MSW(req_dma);
305 mcp->mb[3] = LSW(req_dma);
306 mcp->mb[6] = MSW(MSD(req_dma));
307 mcp->mb[7] = LSW(MSD(req_dma));
308 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
309 if (IS_FWI2_CAPABLE(ha)) {
310 mcp->mb[4] = MSW(risc_code_size);
311 mcp->mb[5] = LSW(risc_code_size);
312 mcp->out_mb |= MBX_5|MBX_4;
314 mcp->mb[4] = LSW(risc_code_size);
315 mcp->out_mb |= MBX_4;
319 mcp->tov = MBX_TOV_SECONDS;
321 rval = qla2x00_mailbox_command(vha, mcp);
323 if (rval != QLA_SUCCESS) {
324 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
325 vha->host_no, rval, mcp->mb[0]));
327 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
335 * Start adapter firmware.
338 * ha = adapter block pointer.
339 * TARGET_QUEUE_LOCK must be released.
340 * ADAPTER_STATE_LOCK must be released.
343 * qla2x00 local function return status code.
349 qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
352 struct qla_hw_data *ha = vha->hw;
354 mbx_cmd_t *mcp = &mc;
356 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
358 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
361 if (IS_FWI2_CAPABLE(ha)) {
362 mcp->mb[1] = MSW(risc_addr);
363 mcp->mb[2] = LSW(risc_addr);
366 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
369 mcp->mb[1] = LSW(risc_addr);
370 mcp->out_mb |= MBX_1;
371 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
373 mcp->out_mb |= MBX_2;
377 mcp->tov = MBX_TOV_SECONDS;
379 rval = qla2x00_mailbox_command(vha, mcp);
381 if (rval != QLA_SUCCESS) {
382 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
383 vha->host_no, rval, mcp->mb[0]));
385 if (IS_FWI2_CAPABLE(ha)) {
386 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
387 __func__, vha->host_no, mcp->mb[1]));
389 DEBUG11(printk("%s(%ld): done.\n", __func__,
398 * qla2x00_get_fw_version
399 * Get firmware version.
402 * ha: adapter state pointer.
403 * major: pointer for major number.
404 * minor: pointer for minor number.
405 * subminor: pointer for subminor number.
408 * qla2x00 local function return status code.
414 qla2x00_get_fw_version(scsi_qla_host_t *vha, uint16_t *major, uint16_t *minor,
415 uint16_t *subminor, uint16_t *attributes, uint32_t *memory)
419 mbx_cmd_t *mcp = &mc;
421 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
423 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
425 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
427 mcp->tov = MBX_TOV_SECONDS;
428 rval = qla2x00_mailbox_command(vha, mcp);
430 /* Return mailbox data. */
433 *subminor = mcp->mb[3];
434 *attributes = mcp->mb[6];
435 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
436 *memory = 0x1FFFF; /* Defaults to 128KB. */
438 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
440 if (rval != QLA_SUCCESS) {
442 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
443 vha->host_no, rval));
446 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
451 * qla2x00_get_fw_options
452 * Set firmware options.
455 * ha = adapter block pointer.
456 * fwopt = pointer for firmware options.
459 * qla2x00 local function return status code.
465 qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
469 mbx_cmd_t *mcp = &mc;
471 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
473 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
475 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
476 mcp->tov = MBX_TOV_SECONDS;
478 rval = qla2x00_mailbox_command(vha, mcp);
480 if (rval != QLA_SUCCESS) {
482 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
483 vha->host_no, rval));
485 fwopts[0] = mcp->mb[0];
486 fwopts[1] = mcp->mb[1];
487 fwopts[2] = mcp->mb[2];
488 fwopts[3] = mcp->mb[3];
490 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
498 * qla2x00_set_fw_options
499 * Set firmware options.
502 * ha = adapter block pointer.
503 * fwopt = pointer for firmware options.
506 * qla2x00 local function return status code.
512 qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
516 mbx_cmd_t *mcp = &mc;
518 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
520 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
521 mcp->mb[1] = fwopts[1];
522 mcp->mb[2] = fwopts[2];
523 mcp->mb[3] = fwopts[3];
524 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
526 if (IS_FWI2_CAPABLE(vha->hw)) {
529 mcp->mb[10] = fwopts[10];
530 mcp->mb[11] = fwopts[11];
531 mcp->mb[12] = 0; /* Undocumented, but used */
532 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
534 mcp->tov = MBX_TOV_SECONDS;
536 rval = qla2x00_mailbox_command(vha, mcp);
538 fwopts[0] = mcp->mb[0];
540 if (rval != QLA_SUCCESS) {
542 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
543 vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
546 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
553 * qla2x00_mbx_reg_test
554 * Mailbox register wrap test.
557 * ha = adapter block pointer.
558 * TARGET_QUEUE_LOCK must be released.
559 * ADAPTER_STATE_LOCK must be released.
562 * qla2x00 local function return status code.
568 qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
572 mbx_cmd_t *mcp = &mc;
574 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", vha->host_no));
576 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
584 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
585 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
586 mcp->tov = MBX_TOV_SECONDS;
588 rval = qla2x00_mailbox_command(vha, mcp);
590 if (rval == QLA_SUCCESS) {
591 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
592 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
593 rval = QLA_FUNCTION_FAILED;
594 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
595 mcp->mb[7] != 0x2525)
596 rval = QLA_FUNCTION_FAILED;
599 if (rval != QLA_SUCCESS) {
601 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
602 vha->host_no, rval));
605 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
613 * qla2x00_verify_checksum
614 * Verify firmware checksum.
617 * ha = adapter block pointer.
618 * TARGET_QUEUE_LOCK must be released.
619 * ADAPTER_STATE_LOCK must be released.
622 * qla2x00 local function return status code.
628 qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
632 mbx_cmd_t *mcp = &mc;
634 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
636 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
639 if (IS_FWI2_CAPABLE(vha->hw)) {
640 mcp->mb[1] = MSW(risc_addr);
641 mcp->mb[2] = LSW(risc_addr);
642 mcp->out_mb |= MBX_2|MBX_1;
643 mcp->in_mb |= MBX_2|MBX_1;
645 mcp->mb[1] = LSW(risc_addr);
646 mcp->out_mb |= MBX_1;
650 mcp->tov = MBX_TOV_SECONDS;
652 rval = qla2x00_mailbox_command(vha, mcp);
654 if (rval != QLA_SUCCESS) {
655 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
656 vha->host_no, rval, IS_FWI2_CAPABLE(vha->hw) ?
657 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
659 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
667 * Issue IOCB using mailbox command
670 * ha = adapter state pointer.
671 * buffer = buffer pointer.
672 * phys_addr = physical address of buffer.
673 * size = size of buffer.
674 * TARGET_QUEUE_LOCK must be released.
675 * ADAPTER_STATE_LOCK must be released.
678 * qla2x00 local function return status code.
684 qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
685 dma_addr_t phys_addr, size_t size, uint32_t tov)
689 mbx_cmd_t *mcp = &mc;
691 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
693 mcp->mb[2] = MSW(phys_addr);
694 mcp->mb[3] = LSW(phys_addr);
695 mcp->mb[6] = MSW(MSD(phys_addr));
696 mcp->mb[7] = LSW(MSD(phys_addr));
697 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
698 mcp->in_mb = MBX_2|MBX_0;
701 rval = qla2x00_mailbox_command(vha, mcp);
703 if (rval != QLA_SUCCESS) {
705 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
706 vha->host_no, rval));
708 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
710 /* Mask reserved bits. */
711 sts_entry->entry_status &=
712 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
719 qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
722 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
727 * qla2x00_abort_command
728 * Abort command aborts a specified IOCB.
731 * ha = adapter block pointer.
732 * sp = SB structure pointer.
735 * qla2x00 local function return status code.
741 qla2x00_abort_command(scsi_qla_host_t *vha, srb_t *sp, struct req_que *req)
743 unsigned long flags = 0;
748 mbx_cmd_t *mcp = &mc;
749 struct qla_hw_data *ha = vha->hw;
751 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", vha->host_no));
755 spin_lock_irqsave(&ha->hardware_lock, flags);
756 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
757 if (req->outstanding_cmds[handle] == sp)
760 spin_unlock_irqrestore(&ha->hardware_lock, flags);
762 if (handle == MAX_OUTSTANDING_COMMANDS) {
763 /* command not found */
764 return QLA_FUNCTION_FAILED;
767 mcp->mb[0] = MBC_ABORT_COMMAND;
768 if (HAS_EXTENDED_IDS(ha))
769 mcp->mb[1] = fcport->loop_id;
771 mcp->mb[1] = fcport->loop_id << 8;
772 mcp->mb[2] = (uint16_t)handle;
773 mcp->mb[3] = (uint16_t)(handle >> 16);
774 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
775 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
777 mcp->tov = MBX_TOV_SECONDS;
779 rval = qla2x00_mailbox_command(vha, mcp);
781 if (rval != QLA_SUCCESS) {
782 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
783 vha->host_no, rval));
785 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
793 qla2x00_abort_target(struct fc_port *fcport, unsigned int l)
797 mbx_cmd_t *mcp = &mc;
798 scsi_qla_host_t *vha;
802 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
806 req = vha->hw->req_q_map[0];
807 rsp = vha->hw->rsp_q_map[0];
808 mcp->mb[0] = MBC_ABORT_TARGET;
809 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
810 if (HAS_EXTENDED_IDS(vha->hw)) {
811 mcp->mb[1] = fcport->loop_id;
813 mcp->out_mb |= MBX_10;
815 mcp->mb[1] = fcport->loop_id << 8;
817 mcp->mb[2] = vha->hw->loop_reset_delay;
818 mcp->mb[9] = vha->vp_idx;
821 mcp->tov = MBX_TOV_SECONDS;
823 rval = qla2x00_mailbox_command(vha, mcp);
824 if (rval != QLA_SUCCESS) {
825 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
826 vha->host_no, rval));
829 /* Issue marker IOCB. */
830 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
832 if (rval2 != QLA_SUCCESS) {
833 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
834 "(%x).\n", __func__, vha->host_no, rval2));
836 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
843 qla2x00_lun_reset(struct fc_port *fcport, unsigned int l)
847 mbx_cmd_t *mcp = &mc;
848 scsi_qla_host_t *vha;
852 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
855 req = vha->hw->req_q_map[0];
856 rsp = vha->hw->rsp_q_map[0];
857 mcp->mb[0] = MBC_LUN_RESET;
858 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
859 if (HAS_EXTENDED_IDS(vha->hw))
860 mcp->mb[1] = fcport->loop_id;
862 mcp->mb[1] = fcport->loop_id << 8;
865 mcp->mb[9] = vha->vp_idx;
868 mcp->tov = MBX_TOV_SECONDS;
870 rval = qla2x00_mailbox_command(vha, mcp);
871 if (rval != QLA_SUCCESS) {
872 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
873 vha->host_no, rval));
876 /* Issue marker IOCB. */
877 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
879 if (rval2 != QLA_SUCCESS) {
880 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
881 "(%x).\n", __func__, vha->host_no, rval2));
883 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
890 * qla2x00_get_adapter_id
891 * Get adapter ID and topology.
894 * ha = adapter block pointer.
895 * id = pointer for loop ID.
896 * al_pa = pointer for AL_PA.
897 * area = pointer for area.
898 * domain = pointer for domain.
899 * top = pointer for topology.
900 * TARGET_QUEUE_LOCK must be released.
901 * ADAPTER_STATE_LOCK must be released.
904 * qla2x00 local function return status code.
910 qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
911 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
915 mbx_cmd_t *mcp = &mc;
917 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
920 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
921 mcp->mb[9] = vha->vp_idx;
922 mcp->out_mb = MBX_9|MBX_0;
923 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
924 mcp->tov = MBX_TOV_SECONDS;
926 rval = qla2x00_mailbox_command(vha, mcp);
927 if (mcp->mb[0] == MBS_COMMAND_ERROR)
928 rval = QLA_COMMAND_ERROR;
929 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
930 rval = QLA_INVALID_COMMAND;
934 *al_pa = LSB(mcp->mb[2]);
935 *area = MSB(mcp->mb[2]);
936 *domain = LSB(mcp->mb[3]);
938 *sw_cap = mcp->mb[7];
940 if (rval != QLA_SUCCESS) {
942 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
943 vha->host_no, rval));
946 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
954 * qla2x00_get_retry_cnt
955 * Get current firmware login retry count and delay.
958 * ha = adapter block pointer.
959 * retry_cnt = pointer to login retry count.
960 * tov = pointer to login timeout value.
963 * qla2x00 local function return status code.
969 qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
975 mbx_cmd_t *mcp = &mc;
977 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
980 mcp->mb[0] = MBC_GET_RETRY_COUNT;
982 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
983 mcp->tov = MBX_TOV_SECONDS;
985 rval = qla2x00_mailbox_command(vha, mcp);
987 if (rval != QLA_SUCCESS) {
989 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
990 vha->host_no, mcp->mb[0]));
992 /* Convert returned data and check our values. */
993 *r_a_tov = mcp->mb[3] / 2;
994 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
995 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
996 /* Update to the larger values */
997 *retry_cnt = (uint8_t)mcp->mb[1];
1001 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
1002 "ratov=%d.\n", vha->host_no, mcp->mb[3], ratov));
1009 * qla2x00_init_firmware
1010 * Initialize adapter firmware.
1013 * ha = adapter block pointer.
1014 * dptr = Initialization control block pointer.
1015 * size = size of initialization control block.
1016 * TARGET_QUEUE_LOCK must be released.
1017 * ADAPTER_STATE_LOCK must be released.
1020 * qla2x00 local function return status code.
1026 qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
1030 mbx_cmd_t *mcp = &mc;
1031 struct qla_hw_data *ha = vha->hw;
1033 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1036 if (ha->flags.npiv_supported)
1037 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1039 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1041 mcp->mb[2] = MSW(ha->init_cb_dma);
1042 mcp->mb[3] = LSW(ha->init_cb_dma);
1045 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1046 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1047 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1048 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1049 mcp->buf_size = size;
1050 mcp->flags = MBX_DMA_OUT;
1051 mcp->tov = MBX_TOV_SECONDS;
1052 rval = qla2x00_mailbox_command(vha, mcp);
1054 if (rval != QLA_SUCCESS) {
1056 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1058 vha->host_no, rval, mcp->mb[0]));
1061 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1069 * qla2x00_get_port_database
1070 * Issue normal/enhanced get port database mailbox command
1071 * and copy device name as necessary.
1074 * ha = adapter state pointer.
1075 * dev = structure pointer.
1076 * opt = enhanced cmd option byte.
1079 * qla2x00 local function return status code.
1085 qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
1089 mbx_cmd_t *mcp = &mc;
1090 port_database_t *pd;
1091 struct port_database_24xx *pd24;
1093 struct qla_hw_data *ha = vha->hw;
1095 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1098 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1100 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1101 "structure.\n", __func__, vha->host_no));
1102 return QLA_MEMORY_ALLOC_FAILED;
1104 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
1106 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1107 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
1108 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1109 mcp->mb[2] = MSW(pd_dma);
1110 mcp->mb[3] = LSW(pd_dma);
1111 mcp->mb[6] = MSW(MSD(pd_dma));
1112 mcp->mb[7] = LSW(MSD(pd_dma));
1113 mcp->mb[9] = vha->vp_idx;
1114 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1116 if (IS_FWI2_CAPABLE(ha)) {
1117 mcp->mb[1] = fcport->loop_id;
1119 mcp->out_mb |= MBX_10|MBX_1;
1120 mcp->in_mb |= MBX_1;
1121 } else if (HAS_EXTENDED_IDS(ha)) {
1122 mcp->mb[1] = fcport->loop_id;
1124 mcp->out_mb |= MBX_10|MBX_1;
1126 mcp->mb[1] = fcport->loop_id << 8 | opt;
1127 mcp->out_mb |= MBX_1;
1129 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1130 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
1131 mcp->flags = MBX_DMA_IN;
1132 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1133 rval = qla2x00_mailbox_command(vha, mcp);
1134 if (rval != QLA_SUCCESS)
1137 if (IS_FWI2_CAPABLE(ha)) {
1138 pd24 = (struct port_database_24xx *) pd;
1140 /* Check for logged in state. */
1141 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1142 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1143 DEBUG2(printk("%s(%ld): Unable to verify "
1144 "login-state (%x/%x) for loop_id %x\n",
1145 __func__, vha->host_no,
1146 pd24->current_login_state,
1147 pd24->last_login_state, fcport->loop_id));
1148 rval = QLA_FUNCTION_FAILED;
1152 /* Names are little-endian. */
1153 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1154 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1156 /* Get port_id of device. */
1157 fcport->d_id.b.domain = pd24->port_id[0];
1158 fcport->d_id.b.area = pd24->port_id[1];
1159 fcport->d_id.b.al_pa = pd24->port_id[2];
1160 fcport->d_id.b.rsvd_1 = 0;
1162 /* If not target must be initiator or unknown type. */
1163 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1164 fcport->port_type = FCT_INITIATOR;
1166 fcport->port_type = FCT_TARGET;
1168 /* Check for logged in state. */
1169 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1170 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1171 rval = QLA_FUNCTION_FAILED;
1175 /* Names are little-endian. */
1176 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1177 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1179 /* Get port_id of device. */
1180 fcport->d_id.b.domain = pd->port_id[0];
1181 fcport->d_id.b.area = pd->port_id[3];
1182 fcport->d_id.b.al_pa = pd->port_id[2];
1183 fcport->d_id.b.rsvd_1 = 0;
1185 /* Check for device require authentication. */
1186 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1187 (fcport->flags &= ~FCF_AUTH_REQ);
1189 /* If not target must be initiator or unknown type. */
1190 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1191 fcport->port_type = FCT_INITIATOR;
1193 fcport->port_type = FCT_TARGET;
1195 /* Passback COS information. */
1196 fcport->supported_classes = (pd->options & BIT_4) ?
1197 FC_COS_CLASS2: FC_COS_CLASS3;
1201 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1203 if (rval != QLA_SUCCESS) {
1204 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1205 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1207 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1214 * qla2x00_get_firmware_state
1215 * Get adapter firmware state.
1218 * ha = adapter block pointer.
1219 * dptr = pointer for firmware state.
1220 * TARGET_QUEUE_LOCK must be released.
1221 * ADAPTER_STATE_LOCK must be released.
1224 * qla2x00 local function return status code.
1230 qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
1234 mbx_cmd_t *mcp = &mc;
1236 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1239 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1240 mcp->out_mb = MBX_0;
1241 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1242 mcp->tov = MBX_TOV_SECONDS;
1244 rval = qla2x00_mailbox_command(vha, mcp);
1246 /* Return firmware states. */
1247 states[0] = mcp->mb[1];
1248 states[1] = mcp->mb[2];
1249 states[2] = mcp->mb[3];
1251 if (rval != QLA_SUCCESS) {
1253 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1254 "failed=%x.\n", vha->host_no, rval));
1257 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1265 * qla2x00_get_port_name
1266 * Issue get port name mailbox command.
1267 * Returned name is in big endian format.
1270 * ha = adapter block pointer.
1271 * loop_id = loop ID of device.
1272 * name = pointer for name.
1273 * TARGET_QUEUE_LOCK must be released.
1274 * ADAPTER_STATE_LOCK must be released.
1277 * qla2x00 local function return status code.
1283 qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
1288 mbx_cmd_t *mcp = &mc;
1290 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1293 mcp->mb[0] = MBC_GET_PORT_NAME;
1294 mcp->mb[9] = vha->vp_idx;
1295 mcp->out_mb = MBX_9|MBX_1|MBX_0;
1296 if (HAS_EXTENDED_IDS(vha->hw)) {
1297 mcp->mb[1] = loop_id;
1299 mcp->out_mb |= MBX_10;
1301 mcp->mb[1] = loop_id << 8 | opt;
1304 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1305 mcp->tov = MBX_TOV_SECONDS;
1307 rval = qla2x00_mailbox_command(vha, mcp);
1309 if (rval != QLA_SUCCESS) {
1311 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1312 vha->host_no, rval));
1315 /* This function returns name in big endian. */
1316 name[0] = MSB(mcp->mb[2]);
1317 name[1] = LSB(mcp->mb[2]);
1318 name[2] = MSB(mcp->mb[3]);
1319 name[3] = LSB(mcp->mb[3]);
1320 name[4] = MSB(mcp->mb[6]);
1321 name[5] = LSB(mcp->mb[6]);
1322 name[6] = MSB(mcp->mb[7]);
1323 name[7] = LSB(mcp->mb[7]);
1326 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1335 * Issue LIP reset mailbox command.
1338 * ha = adapter block pointer.
1339 * TARGET_QUEUE_LOCK must be released.
1340 * ADAPTER_STATE_LOCK must be released.
1343 * qla2x00 local function return status code.
1349 qla2x00_lip_reset(scsi_qla_host_t *vha)
1353 mbx_cmd_t *mcp = &mc;
1355 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1357 if (IS_FWI2_CAPABLE(vha->hw)) {
1358 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1361 mcp->mb[3] = vha->hw->loop_reset_delay;
1362 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1364 mcp->mb[0] = MBC_LIP_RESET;
1365 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1366 if (HAS_EXTENDED_IDS(vha->hw)) {
1367 mcp->mb[1] = 0x00ff;
1369 mcp->out_mb |= MBX_10;
1371 mcp->mb[1] = 0xff00;
1373 mcp->mb[2] = vha->hw->loop_reset_delay;
1377 mcp->tov = MBX_TOV_SECONDS;
1379 rval = qla2x00_mailbox_command(vha, mcp);
1381 if (rval != QLA_SUCCESS) {
1383 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1384 __func__, vha->host_no, rval));
1387 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1398 * ha = adapter block pointer.
1399 * sns = pointer for command.
1400 * cmd_size = command size.
1401 * buf_size = response/command size.
1402 * TARGET_QUEUE_LOCK must be released.
1403 * ADAPTER_STATE_LOCK must be released.
1406 * qla2x00 local function return status code.
1412 qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
1413 uint16_t cmd_size, size_t buf_size)
1417 mbx_cmd_t *mcp = &mc;
1419 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1422 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1423 "tov=%d.\n", vha->hw->retry_count, vha->hw->login_timeout,
1426 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1427 mcp->mb[1] = cmd_size;
1428 mcp->mb[2] = MSW(sns_phys_address);
1429 mcp->mb[3] = LSW(sns_phys_address);
1430 mcp->mb[6] = MSW(MSD(sns_phys_address));
1431 mcp->mb[7] = LSW(MSD(sns_phys_address));
1432 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1433 mcp->in_mb = MBX_0|MBX_1;
1434 mcp->buf_size = buf_size;
1435 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1436 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
1437 rval = qla2x00_mailbox_command(vha, mcp);
1439 if (rval != QLA_SUCCESS) {
1441 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1442 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1443 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1444 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1447 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", vha->host_no));
1454 qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1455 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1459 struct logio_entry_24xx *lg;
1462 struct qla_hw_data *ha = vha->hw;
1464 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1466 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1468 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1469 __func__, vha->host_no));
1470 return QLA_MEMORY_ALLOC_FAILED;
1472 memset(lg, 0, sizeof(struct logio_entry_24xx));
1474 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1475 lg->entry_count = 1;
1476 lg->nport_handle = cpu_to_le16(loop_id);
1477 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1479 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1481 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
1482 lg->port_id[0] = al_pa;
1483 lg->port_id[1] = area;
1484 lg->port_id[2] = domain;
1485 lg->vp_index = vha->vp_idx;
1486 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
1487 if (rval != QLA_SUCCESS) {
1488 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
1489 "(%x).\n", __func__, vha->host_no, rval));
1490 } else if (lg->entry_status != 0) {
1491 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1492 "-- error status (%x).\n", __func__, vha->host_no,
1494 rval = QLA_FUNCTION_FAILED;
1495 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1496 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1497 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1499 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1500 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1501 vha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1505 case LSC_SCODE_PORTID_USED:
1506 mb[0] = MBS_PORT_ID_USED;
1507 mb[1] = LSW(iop[1]);
1509 case LSC_SCODE_NPORT_USED:
1510 mb[0] = MBS_LOOP_ID_USED;
1512 case LSC_SCODE_NOLINK:
1513 case LSC_SCODE_NOIOCB:
1514 case LSC_SCODE_NOXCB:
1515 case LSC_SCODE_CMD_FAILED:
1516 case LSC_SCODE_NOFABRIC:
1517 case LSC_SCODE_FW_NOT_READY:
1518 case LSC_SCODE_NOT_LOGGED_IN:
1519 case LSC_SCODE_NOPCB:
1520 case LSC_SCODE_ELS_REJECT:
1521 case LSC_SCODE_CMD_PARAM_ERR:
1522 case LSC_SCODE_NONPORT:
1523 case LSC_SCODE_LOGGED_IN:
1524 case LSC_SCODE_NOFLOGI_ACC:
1526 mb[0] = MBS_COMMAND_ERROR;
1530 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1532 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1534 mb[0] = MBS_COMMAND_COMPLETE;
1536 if (iop[0] & BIT_4) {
1542 /* Passback COS information. */
1544 if (lg->io_parameter[7] || lg->io_parameter[8])
1545 mb[10] |= BIT_0; /* Class 2. */
1546 if (lg->io_parameter[9] || lg->io_parameter[10])
1547 mb[10] |= BIT_1; /* Class 3. */
1550 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1556 * qla2x00_login_fabric
1557 * Issue login fabric port mailbox command.
1560 * ha = adapter block pointer.
1561 * loop_id = device loop ID.
1562 * domain = device domain.
1563 * area = device area.
1564 * al_pa = device AL_PA.
1565 * status = pointer for return status.
1566 * opt = command options.
1567 * TARGET_QUEUE_LOCK must be released.
1568 * ADAPTER_STATE_LOCK must be released.
1571 * qla2x00 local function return status code.
1577 qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1578 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1582 mbx_cmd_t *mcp = &mc;
1583 struct qla_hw_data *ha = vha->hw;
1585 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", vha->host_no));
1587 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1588 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1589 if (HAS_EXTENDED_IDS(ha)) {
1590 mcp->mb[1] = loop_id;
1592 mcp->out_mb |= MBX_10;
1594 mcp->mb[1] = (loop_id << 8) | opt;
1596 mcp->mb[2] = domain;
1597 mcp->mb[3] = area << 8 | al_pa;
1599 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1600 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1602 rval = qla2x00_mailbox_command(vha, mcp);
1604 /* Return mailbox statuses. */
1611 /* COS retrieved from Get-Port-Database mailbox command. */
1615 if (rval != QLA_SUCCESS) {
1616 /* RLU tmp code: need to change main mailbox_command function to
1617 * return ok even when the mailbox completion value is not
1618 * SUCCESS. The caller needs to be responsible to interpret
1619 * the return values of this mailbox command if we're not
1620 * to change too much of the existing code.
1622 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1623 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1624 mcp->mb[0] == 0x4006)
1628 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1629 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", vha->host_no, rval,
1630 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
1633 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1641 * qla2x00_login_local_device
1642 * Issue login loop port mailbox command.
1645 * ha = adapter block pointer.
1646 * loop_id = device loop ID.
1647 * opt = command options.
1650 * Return status code.
1657 qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
1658 uint16_t *mb_ret, uint8_t opt)
1662 mbx_cmd_t *mcp = &mc;
1663 struct qla_hw_data *ha = vha->hw;
1665 if (IS_FWI2_CAPABLE(ha))
1666 return qla24xx_login_fabric(vha, fcport->loop_id,
1667 fcport->d_id.b.domain, fcport->d_id.b.area,
1668 fcport->d_id.b.al_pa, mb_ret, opt);
1670 DEBUG3(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1672 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1673 if (HAS_EXTENDED_IDS(ha))
1674 mcp->mb[1] = fcport->loop_id;
1676 mcp->mb[1] = fcport->loop_id << 8;
1678 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1679 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1680 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1682 rval = qla2x00_mailbox_command(vha, mcp);
1684 /* Return mailbox statuses. */
1685 if (mb_ret != NULL) {
1686 mb_ret[0] = mcp->mb[0];
1687 mb_ret[1] = mcp->mb[1];
1688 mb_ret[6] = mcp->mb[6];
1689 mb_ret[7] = mcp->mb[7];
1692 if (rval != QLA_SUCCESS) {
1693 /* AV tmp code: need to change main mailbox_command function to
1694 * return ok even when the mailbox completion value is not
1695 * SUCCESS. The caller needs to be responsible to interpret
1696 * the return values of this mailbox command if we're not
1697 * to change too much of the existing code.
1699 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1702 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1703 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
1704 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1705 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1706 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
1707 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1710 DEBUG3(printk("%s(%ld): done.\n", __func__, vha->host_no));
1717 qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1718 uint8_t area, uint8_t al_pa)
1721 struct logio_entry_24xx *lg;
1723 struct qla_hw_data *ha = vha->hw;
1725 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1727 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1729 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1730 __func__, vha->host_no));
1731 return QLA_MEMORY_ALLOC_FAILED;
1733 memset(lg, 0, sizeof(struct logio_entry_24xx));
1735 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1736 lg->entry_count = 1;
1737 lg->nport_handle = cpu_to_le16(loop_id);
1739 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
1740 lg->port_id[0] = al_pa;
1741 lg->port_id[1] = area;
1742 lg->port_id[2] = domain;
1743 lg->vp_index = vha->vp_idx;
1745 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
1746 if (rval != QLA_SUCCESS) {
1747 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1748 "(%x).\n", __func__, vha->host_no, rval));
1749 } else if (lg->entry_status != 0) {
1750 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1751 "-- error status (%x).\n", __func__, vha->host_no,
1753 rval = QLA_FUNCTION_FAILED;
1754 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1755 DEBUG2_3_11(printk("%s(%ld %d): failed to complete IOCB "
1756 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1757 vha->host_no, vha->vp_idx, le16_to_cpu(lg->comp_status),
1758 le32_to_cpu(lg->io_parameter[0]),
1759 le32_to_cpu(lg->io_parameter[1])));
1762 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1765 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1771 * qla2x00_fabric_logout
1772 * Issue logout fabric port mailbox command.
1775 * ha = adapter block pointer.
1776 * loop_id = device loop ID.
1777 * TARGET_QUEUE_LOCK must be released.
1778 * ADAPTER_STATE_LOCK must be released.
1781 * qla2x00 local function return status code.
1787 qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1788 uint8_t area, uint8_t al_pa)
1792 mbx_cmd_t *mcp = &mc;
1794 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1797 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1798 mcp->out_mb = MBX_1|MBX_0;
1799 if (HAS_EXTENDED_IDS(vha->hw)) {
1800 mcp->mb[1] = loop_id;
1802 mcp->out_mb |= MBX_10;
1804 mcp->mb[1] = loop_id << 8;
1807 mcp->in_mb = MBX_1|MBX_0;
1808 mcp->tov = MBX_TOV_SECONDS;
1810 rval = qla2x00_mailbox_command(vha, mcp);
1812 if (rval != QLA_SUCCESS) {
1814 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1815 "mbx1=%x.\n", vha->host_no, rval, mcp->mb[1]));
1818 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1826 * qla2x00_full_login_lip
1827 * Issue full login LIP mailbox command.
1830 * ha = adapter block pointer.
1831 * TARGET_QUEUE_LOCK must be released.
1832 * ADAPTER_STATE_LOCK must be released.
1835 * qla2x00 local function return status code.
1841 qla2x00_full_login_lip(scsi_qla_host_t *vha)
1845 mbx_cmd_t *mcp = &mc;
1847 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1850 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1851 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
1854 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1856 mcp->tov = MBX_TOV_SECONDS;
1858 rval = qla2x00_mailbox_command(vha, mcp);
1860 if (rval != QLA_SUCCESS) {
1862 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1863 vha->host_no, rval));
1866 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1874 * qla2x00_get_id_list
1877 * ha = adapter block pointer.
1880 * qla2x00 local function return status code.
1886 qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
1891 mbx_cmd_t *mcp = &mc;
1893 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1896 if (id_list == NULL)
1897 return QLA_FUNCTION_FAILED;
1899 mcp->mb[0] = MBC_GET_ID_LIST;
1900 mcp->out_mb = MBX_0;
1901 if (IS_FWI2_CAPABLE(vha->hw)) {
1902 mcp->mb[2] = MSW(id_list_dma);
1903 mcp->mb[3] = LSW(id_list_dma);
1904 mcp->mb[6] = MSW(MSD(id_list_dma));
1905 mcp->mb[7] = LSW(MSD(id_list_dma));
1907 mcp->mb[9] = vha->vp_idx;
1908 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
1910 mcp->mb[1] = MSW(id_list_dma);
1911 mcp->mb[2] = LSW(id_list_dma);
1912 mcp->mb[3] = MSW(MSD(id_list_dma));
1913 mcp->mb[6] = LSW(MSD(id_list_dma));
1914 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1916 mcp->in_mb = MBX_1|MBX_0;
1917 mcp->tov = MBX_TOV_SECONDS;
1919 rval = qla2x00_mailbox_command(vha, mcp);
1921 if (rval != QLA_SUCCESS) {
1923 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
1924 vha->host_no, rval));
1926 *entries = mcp->mb[1];
1927 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
1935 * qla2x00_get_resource_cnts
1936 * Get current firmware resource counts.
1939 * ha = adapter block pointer.
1942 * qla2x00 local function return status code.
1948 qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
1949 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
1950 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports)
1954 mbx_cmd_t *mcp = &mc;
1956 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1958 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
1959 mcp->out_mb = MBX_0;
1960 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1961 mcp->tov = MBX_TOV_SECONDS;
1963 rval = qla2x00_mailbox_command(vha, mcp);
1965 if (rval != QLA_SUCCESS) {
1967 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
1968 vha->host_no, mcp->mb[0]));
1970 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
1971 "mb7=%x mb10=%x mb11=%x.\n", __func__, vha->host_no,
1972 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
1973 mcp->mb[10], mcp->mb[11]));
1976 *cur_xchg_cnt = mcp->mb[3];
1978 *orig_xchg_cnt = mcp->mb[6];
1980 *cur_iocb_cnt = mcp->mb[7];
1982 *orig_iocb_cnt = mcp->mb[10];
1983 if (vha->hw->flags.npiv_supported && max_npiv_vports)
1984 *max_npiv_vports = mcp->mb[11];
1990 #if defined(QL_DEBUG_LEVEL_3)
1992 * qla2x00_get_fcal_position_map
1993 * Get FCAL (LILP) position map using mailbox command
1996 * ha = adapter state pointer.
1997 * pos_map = buffer pointer (can be NULL).
2000 * qla2x00 local function return status code.
2006 qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
2010 mbx_cmd_t *mcp = &mc;
2012 dma_addr_t pmap_dma;
2013 struct qla_hw_data *ha = vha->hw;
2015 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
2017 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
2018 __func__, vha->host_no));
2019 return QLA_MEMORY_ALLOC_FAILED;
2021 memset(pmap, 0, FCAL_MAP_SIZE);
2023 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2024 mcp->mb[2] = MSW(pmap_dma);
2025 mcp->mb[3] = LSW(pmap_dma);
2026 mcp->mb[6] = MSW(MSD(pmap_dma));
2027 mcp->mb[7] = LSW(MSD(pmap_dma));
2028 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2029 mcp->in_mb = MBX_1|MBX_0;
2030 mcp->buf_size = FCAL_MAP_SIZE;
2031 mcp->flags = MBX_DMA_IN;
2032 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2033 rval = qla2x00_mailbox_command(vha, mcp);
2035 if (rval == QLA_SUCCESS) {
2036 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2037 "size (%x)\n", __func__, vha->host_no, mcp->mb[0],
2038 mcp->mb[1], (unsigned)pmap[0]));
2039 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2042 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2044 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2046 if (rval != QLA_SUCCESS) {
2047 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2048 vha->host_no, rval));
2050 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2058 * qla2x00_get_link_status
2061 * ha = adapter block pointer.
2062 * loop_id = device loop ID.
2063 * ret_buf = pointer to link status return buffer.
2067 * BIT_0 = mem alloc error.
2068 * BIT_1 = mailbox error.
2071 qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
2072 struct link_statistics *stats, dma_addr_t stats_dma)
2076 mbx_cmd_t *mcp = &mc;
2077 uint32_t *siter, *diter, dwords;
2078 struct qla_hw_data *ha = vha->hw;
2080 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2082 mcp->mb[0] = MBC_GET_LINK_STATUS;
2083 mcp->mb[2] = MSW(stats_dma);
2084 mcp->mb[3] = LSW(stats_dma);
2085 mcp->mb[6] = MSW(MSD(stats_dma));
2086 mcp->mb[7] = LSW(MSD(stats_dma));
2087 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2089 if (IS_FWI2_CAPABLE(ha)) {
2090 mcp->mb[1] = loop_id;
2093 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2094 mcp->in_mb |= MBX_1;
2095 } else if (HAS_EXTENDED_IDS(ha)) {
2096 mcp->mb[1] = loop_id;
2098 mcp->out_mb |= MBX_10|MBX_1;
2100 mcp->mb[1] = loop_id << 8;
2101 mcp->out_mb |= MBX_1;
2103 mcp->tov = MBX_TOV_SECONDS;
2104 mcp->flags = IOCTL_CMD;
2105 rval = qla2x00_mailbox_command(vha, mcp);
2107 if (rval == QLA_SUCCESS) {
2108 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2109 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2110 __func__, vha->host_no, mcp->mb[0]));
2111 rval = QLA_FUNCTION_FAILED;
2113 /* Copy over data -- firmware data is LE. */
2114 dwords = offsetof(struct link_statistics, unused1) / 4;
2115 siter = diter = &stats->link_fail_cnt;
2117 *diter++ = le32_to_cpu(*siter++);
2121 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2122 vha->host_no, rval));
2129 qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
2130 dma_addr_t stats_dma)
2134 mbx_cmd_t *mcp = &mc;
2135 uint32_t *siter, *diter, dwords;
2137 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2139 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2140 mcp->mb[2] = MSW(stats_dma);
2141 mcp->mb[3] = LSW(stats_dma);
2142 mcp->mb[6] = MSW(MSD(stats_dma));
2143 mcp->mb[7] = LSW(MSD(stats_dma));
2144 mcp->mb[8] = sizeof(struct link_statistics) / 4;
2145 mcp->mb[9] = vha->vp_idx;
2147 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2148 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2149 mcp->tov = MBX_TOV_SECONDS;
2150 mcp->flags = IOCTL_CMD;
2151 rval = qla2x00_mailbox_command(vha, mcp);
2153 if (rval == QLA_SUCCESS) {
2154 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2155 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2156 __func__, vha->host_no, mcp->mb[0]));
2157 rval = QLA_FUNCTION_FAILED;
2159 /* Copy over data -- firmware data is LE. */
2160 dwords = sizeof(struct link_statistics) / 4;
2161 siter = diter = &stats->link_fail_cnt;
2163 *diter++ = le32_to_cpu(*siter++);
2167 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2168 vha->host_no, rval));
2175 qla24xx_abort_command(scsi_qla_host_t *vha, srb_t *sp, struct req_que *req)
2179 unsigned long flags = 0;
2181 struct abort_entry_24xx *abt;
2184 struct qla_hw_data *ha = vha->hw;
2186 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2188 fcport = sp->fcport;
2190 spin_lock_irqsave(&ha->hardware_lock, flags);
2191 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2192 if (req->outstanding_cmds[handle] == sp)
2195 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2196 if (handle == MAX_OUTSTANDING_COMMANDS) {
2197 /* Command not found. */
2198 return QLA_FUNCTION_FAILED;
2201 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2203 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2204 __func__, vha->host_no));
2205 return QLA_MEMORY_ALLOC_FAILED;
2207 memset(abt, 0, sizeof(struct abort_entry_24xx));
2209 abt->entry_type = ABORT_IOCB_TYPE;
2210 abt->entry_count = 1;
2211 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2212 abt->handle_to_abort = handle;
2213 abt->port_id[0] = fcport->d_id.b.al_pa;
2214 abt->port_id[1] = fcport->d_id.b.area;
2215 abt->port_id[2] = fcport->d_id.b.domain;
2216 abt->vp_index = fcport->vp_idx;
2218 abt->req_que_no = cpu_to_le16(req->id);
2220 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
2221 if (rval != QLA_SUCCESS) {
2222 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2223 __func__, vha->host_no, rval));
2224 } else if (abt->entry_status != 0) {
2225 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2226 "-- error status (%x).\n", __func__, vha->host_no,
2227 abt->entry_status));
2228 rval = QLA_FUNCTION_FAILED;
2229 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2230 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2231 "-- completion status (%x).\n", __func__, vha->host_no,
2232 le16_to_cpu(abt->nport_handle)));
2233 rval = QLA_FUNCTION_FAILED;
2235 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2238 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2243 struct tsk_mgmt_cmd {
2245 struct tsk_mgmt_entry tsk;
2246 struct sts_entry_24xx sts;
2251 __qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
2255 struct tsk_mgmt_cmd *tsk;
2257 scsi_qla_host_t *vha;
2258 struct qla_hw_data *ha;
2259 struct req_que *req;
2260 struct rsp_que *rsp;
2262 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
2266 req = ha->req_q_map[0];
2267 rsp = ha->rsp_q_map[0];
2268 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
2270 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2271 "IOCB.\n", __func__, vha->host_no));
2272 return QLA_MEMORY_ALLOC_FAILED;
2274 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2276 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2277 tsk->p.tsk.entry_count = 1;
2278 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2279 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
2280 tsk->p.tsk.control_flags = cpu_to_le32(type);
2281 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2282 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2283 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2284 tsk->p.tsk.vp_index = fcport->vp_idx;
2285 if (type == TCF_LUN_RESET) {
2286 int_to_scsilun(l, &tsk->p.tsk.lun);
2287 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2288 sizeof(tsk->p.tsk.lun));
2291 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
2292 if (rval != QLA_SUCCESS) {
2293 DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
2294 "(%x).\n", __func__, vha->host_no, name, rval));
2295 } else if (tsk->p.sts.entry_status != 0) {
2296 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2297 "-- error status (%x).\n", __func__, vha->host_no,
2298 tsk->p.sts.entry_status));
2299 rval = QLA_FUNCTION_FAILED;
2300 } else if (tsk->p.sts.comp_status !=
2301 __constant_cpu_to_le16(CS_COMPLETE)) {
2302 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2303 "-- completion status (%x).\n", __func__,
2304 vha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
2305 rval = QLA_FUNCTION_FAILED;
2308 /* Issue marker IOCB. */
2309 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
2310 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2311 if (rval2 != QLA_SUCCESS) {
2312 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2313 "(%x).\n", __func__, vha->host_no, rval2));
2315 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2318 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
2324 qla24xx_abort_target(struct fc_port *fcport, unsigned int l)
2326 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l);
2330 qla24xx_lun_reset(struct fc_port *fcport, unsigned int l)
2332 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l);
2336 qla2x00_system_error(scsi_qla_host_t *vha)
2340 mbx_cmd_t *mcp = &mc;
2341 struct qla_hw_data *ha = vha->hw;
2343 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
2344 return QLA_FUNCTION_FAILED;
2346 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2348 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2349 mcp->out_mb = MBX_0;
2353 rval = qla2x00_mailbox_command(vha, mcp);
2355 if (rval != QLA_SUCCESS) {
2356 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2357 vha->host_no, rval));
2359 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2366 * qla2x00_set_serdes_params() -
2372 qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
2373 uint16_t sw_em_2g, uint16_t sw_em_4g)
2377 mbx_cmd_t *mcp = &mc;
2379 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2381 mcp->mb[0] = MBC_SERDES_PARAMS;
2383 mcp->mb[2] = sw_em_1g | BIT_15;
2384 mcp->mb[3] = sw_em_2g | BIT_15;
2385 mcp->mb[4] = sw_em_4g | BIT_15;
2386 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2388 mcp->tov = MBX_TOV_SECONDS;
2390 rval = qla2x00_mailbox_command(vha, mcp);
2392 if (rval != QLA_SUCCESS) {
2394 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2395 vha->host_no, rval, mcp->mb[0]));
2398 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2405 qla2x00_stop_firmware(scsi_qla_host_t *vha)
2409 mbx_cmd_t *mcp = &mc;
2411 if (!IS_FWI2_CAPABLE(vha->hw))
2412 return QLA_FUNCTION_FAILED;
2414 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2416 mcp->mb[0] = MBC_STOP_FIRMWARE;
2417 mcp->out_mb = MBX_0;
2421 rval = qla2x00_mailbox_command(vha, mcp);
2423 if (rval != QLA_SUCCESS) {
2424 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2425 vha->host_no, rval));
2427 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2434 qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
2439 mbx_cmd_t *mcp = &mc;
2441 if (!IS_FWI2_CAPABLE(vha->hw))
2442 return QLA_FUNCTION_FAILED;
2444 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2446 mcp->mb[0] = MBC_TRACE_CONTROL;
2447 mcp->mb[1] = TC_EFT_ENABLE;
2448 mcp->mb[2] = LSW(eft_dma);
2449 mcp->mb[3] = MSW(eft_dma);
2450 mcp->mb[4] = LSW(MSD(eft_dma));
2451 mcp->mb[5] = MSW(MSD(eft_dma));
2452 mcp->mb[6] = buffers;
2453 mcp->mb[7] = TC_AEN_DISABLE;
2454 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2455 mcp->in_mb = MBX_1|MBX_0;
2456 mcp->tov = MBX_TOV_SECONDS;
2458 rval = qla2x00_mailbox_command(vha, mcp);
2459 if (rval != QLA_SUCCESS) {
2460 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2461 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2463 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2470 qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
2474 mbx_cmd_t *mcp = &mc;
2476 if (!IS_FWI2_CAPABLE(vha->hw))
2477 return QLA_FUNCTION_FAILED;
2479 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2481 mcp->mb[0] = MBC_TRACE_CONTROL;
2482 mcp->mb[1] = TC_EFT_DISABLE;
2483 mcp->out_mb = MBX_1|MBX_0;
2484 mcp->in_mb = MBX_1|MBX_0;
2485 mcp->tov = MBX_TOV_SECONDS;
2487 rval = qla2x00_mailbox_command(vha, mcp);
2488 if (rval != QLA_SUCCESS) {
2489 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2490 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2492 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2499 qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
2500 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2504 mbx_cmd_t *mcp = &mc;
2506 if (!IS_QLA25XX(vha->hw))
2507 return QLA_FUNCTION_FAILED;
2509 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2511 mcp->mb[0] = MBC_TRACE_CONTROL;
2512 mcp->mb[1] = TC_FCE_ENABLE;
2513 mcp->mb[2] = LSW(fce_dma);
2514 mcp->mb[3] = MSW(fce_dma);
2515 mcp->mb[4] = LSW(MSD(fce_dma));
2516 mcp->mb[5] = MSW(MSD(fce_dma));
2517 mcp->mb[6] = buffers;
2518 mcp->mb[7] = TC_AEN_DISABLE;
2520 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2521 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2522 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2524 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2525 mcp->tov = MBX_TOV_SECONDS;
2527 rval = qla2x00_mailbox_command(vha, mcp);
2528 if (rval != QLA_SUCCESS) {
2529 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2530 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2532 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2535 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2544 qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
2548 mbx_cmd_t *mcp = &mc;
2550 if (!IS_FWI2_CAPABLE(vha->hw))
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_FCE_DISABLE;
2557 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
2558 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2559 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2561 mcp->tov = MBX_TOV_SECONDS;
2563 rval = qla2x00_mailbox_command(vha, mcp);
2564 if (rval != QLA_SUCCESS) {
2565 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2566 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2568 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2571 *wr = (uint64_t) mcp->mb[5] << 48 |
2572 (uint64_t) mcp->mb[4] << 32 |
2573 (uint64_t) mcp->mb[3] << 16 |
2574 (uint64_t) mcp->mb[2];
2576 *rd = (uint64_t) mcp->mb[9] << 48 |
2577 (uint64_t) mcp->mb[8] << 32 |
2578 (uint64_t) mcp->mb[7] << 16 |
2579 (uint64_t) mcp->mb[6];
2586 qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint16_t addr,
2587 uint16_t off, uint16_t count)
2591 mbx_cmd_t *mcp = &mc;
2593 if (!IS_FWI2_CAPABLE(vha->hw))
2594 return QLA_FUNCTION_FAILED;
2596 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2598 mcp->mb[0] = MBC_READ_SFP;
2600 mcp->mb[2] = MSW(sfp_dma);
2601 mcp->mb[3] = LSW(sfp_dma);
2602 mcp->mb[6] = MSW(MSD(sfp_dma));
2603 mcp->mb[7] = LSW(MSD(sfp_dma));
2607 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2609 mcp->tov = MBX_TOV_SECONDS;
2611 rval = qla2x00_mailbox_command(vha, mcp);
2613 if (rval != QLA_SUCCESS) {
2614 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2615 vha->host_no, rval, mcp->mb[0]));
2617 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2624 qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
2625 uint16_t port_speed, uint16_t *mb)
2629 mbx_cmd_t *mcp = &mc;
2631 if (!IS_IIDMA_CAPABLE(vha->hw))
2632 return QLA_FUNCTION_FAILED;
2634 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2636 mcp->mb[0] = MBC_PORT_PARAMS;
2637 mcp->mb[1] = loop_id;
2639 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2640 mcp->mb[4] = mcp->mb[5] = 0;
2641 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2642 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2643 mcp->tov = MBX_TOV_SECONDS;
2645 rval = qla2x00_mailbox_command(vha, mcp);
2647 /* Return mailbox statuses. */
2656 if (rval != QLA_SUCCESS) {
2657 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2658 vha->host_no, rval));
2660 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2667 qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
2668 struct vp_rpt_id_entry_24xx *rptid_entry)
2671 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
2672 struct qla_hw_data *ha = vha->hw;
2673 scsi_qla_host_t *vp;
2675 if (rptid_entry->entry_status != 0)
2678 if (rptid_entry->format == 0) {
2679 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
2680 " number of VPs acquired %d\n", __func__, vha->host_no,
2681 MSB(rptid_entry->vp_count), LSB(rptid_entry->vp_count)));
2682 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2683 rptid_entry->port_id[2], rptid_entry->port_id[1],
2684 rptid_entry->port_id[0]));
2685 } else if (rptid_entry->format == 1) {
2687 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2689 "with port id %02x%02x%02x\n", __func__, vha->host_no,
2691 rptid_entry->port_id[2], rptid_entry->port_id[1],
2692 rptid_entry->port_id[0]));
2699 list_for_each_entry(vp, &ha->vp_list, list)
2700 if (vp_idx == vp->vp_idx)
2705 vp->d_id.b.domain = rptid_entry->port_id[2];
2706 vp->d_id.b.area = rptid_entry->port_id[1];
2707 vp->d_id.b.al_pa = rptid_entry->port_id[0];
2710 * Cannot configure here as we are still sitting on the
2711 * response queue. Handle it in dpc context.
2713 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
2714 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
2716 qla2xxx_wake_dpc(vha);
2721 * qla24xx_modify_vp_config
2722 * Change VP configuration for vha
2725 * vha = adapter block pointer.
2728 * qla2xxx local function return status code.
2734 qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2737 struct vp_config_entry_24xx *vpmod;
2738 dma_addr_t vpmod_dma;
2739 struct qla_hw_data *ha = vha->hw;
2740 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2742 /* This can be called by the parent */
2744 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
2746 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
2747 "IOCB.\n", __func__, vha->host_no));
2748 return QLA_MEMORY_ALLOC_FAILED;
2751 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2752 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2753 vpmod->entry_count = 1;
2754 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2755 vpmod->vp_count = 1;
2756 vpmod->vp_index1 = vha->vp_idx;
2757 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2758 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2759 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2760 vpmod->entry_count = 1;
2762 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
2763 if (rval != QLA_SUCCESS) {
2764 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
2765 "(%x).\n", __func__, base_vha->host_no, rval));
2766 } else if (vpmod->comp_status != 0) {
2767 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2768 "-- error status (%x).\n", __func__, base_vha->host_no,
2769 vpmod->comp_status));
2770 rval = QLA_FUNCTION_FAILED;
2771 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2772 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2773 "-- completion status (%x).\n", __func__, base_vha->host_no,
2774 le16_to_cpu(vpmod->comp_status)));
2775 rval = QLA_FUNCTION_FAILED;
2778 DEBUG11(printk("%s(%ld): done.\n", __func__,
2779 base_vha->host_no));
2780 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2782 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
2788 * qla24xx_control_vp
2789 * Enable a virtual port for given host
2792 * ha = adapter block pointer.
2793 * vhba = virtual adapter (unused)
2794 * index = index number for enabled VP
2797 * qla2xxx local function return status code.
2803 qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2807 struct vp_ctrl_entry_24xx *vce;
2809 struct qla_hw_data *ha = vha->hw;
2810 int vp_index = vha->vp_idx;
2811 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2813 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
2814 vha->host_no, vp_index));
2816 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
2817 return QLA_PARAMETER_ERROR;
2819 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2821 DEBUG2_3(printk("%s(%ld): "
2822 "failed to allocate VP Control IOCB.\n", __func__,
2823 base_vha->host_no));
2824 return QLA_MEMORY_ALLOC_FAILED;
2826 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2828 vce->entry_type = VP_CTRL_IOCB_TYPE;
2829 vce->entry_count = 1;
2830 vce->command = cpu_to_le16(cmd);
2831 vce->vp_count = __constant_cpu_to_le16(1);
2833 /* index map in firmware starts with 1; decrement index
2834 * this is ok as we never use index 0
2836 map = (vp_index - 1) / 8;
2837 pos = (vp_index - 1) & 7;
2838 mutex_lock(&ha->vport_lock);
2839 vce->vp_idx_map[map] |= 1 << pos;
2840 mutex_unlock(&ha->vport_lock);
2842 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
2843 if (rval != QLA_SUCCESS) {
2844 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
2845 "(%x).\n", __func__, base_vha->host_no, rval));
2846 printk("%s(%ld): failed to issue VP control IOCB"
2847 "(%x).\n", __func__, base_vha->host_no, rval);
2848 } else if (vce->entry_status != 0) {
2849 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2850 "-- error status (%x).\n", __func__, base_vha->host_no,
2851 vce->entry_status));
2852 printk("%s(%ld): failed to complete IOCB "
2853 "-- error status (%x).\n", __func__, base_vha->host_no,
2855 rval = QLA_FUNCTION_FAILED;
2856 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2857 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2858 "-- completion status (%x).\n", __func__, base_vha->host_no,
2859 le16_to_cpu(vce->comp_status)));
2860 printk("%s(%ld): failed to complete IOCB "
2861 "-- completion status (%x).\n", __func__, base_vha->host_no,
2862 le16_to_cpu(vce->comp_status));
2863 rval = QLA_FUNCTION_FAILED;
2865 DEBUG2(printk("%s(%ld): done.\n", __func__, base_vha->host_no));
2868 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
2874 * qla2x00_send_change_request
2875 * Receive or disable RSCN request from fabric controller
2878 * ha = adapter block pointer
2879 * format = registration format:
2881 * 1 - Fabric detected registration
2882 * 2 - N_port detected registration
2883 * 3 - Full registration
2884 * FF - clear registration
2885 * vp_idx = Virtual port index
2888 * qla2x00 local function return status code.
2895 qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
2900 mbx_cmd_t *mcp = &mc;
2903 * This command is implicitly executed by firmware during login for the
2907 return QLA_FUNCTION_FAILED;
2909 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
2910 mcp->mb[1] = format;
2911 mcp->mb[9] = vp_idx;
2912 mcp->out_mb = MBX_9|MBX_1|MBX_0;
2913 mcp->in_mb = MBX_0|MBX_1;
2914 mcp->tov = MBX_TOV_SECONDS;
2916 rval = qla2x00_mailbox_command(vha, mcp);
2918 if (rval == QLA_SUCCESS) {
2919 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2929 qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
2934 mbx_cmd_t *mcp = &mc;
2936 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2938 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
2939 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
2940 mcp->mb[8] = MSW(addr);
2941 mcp->out_mb = MBX_8|MBX_0;
2943 mcp->mb[0] = MBC_DUMP_RISC_RAM;
2944 mcp->out_mb = MBX_0;
2946 mcp->mb[1] = LSW(addr);
2947 mcp->mb[2] = MSW(req_dma);
2948 mcp->mb[3] = LSW(req_dma);
2949 mcp->mb[6] = MSW(MSD(req_dma));
2950 mcp->mb[7] = LSW(MSD(req_dma));
2951 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
2952 if (IS_FWI2_CAPABLE(vha->hw)) {
2953 mcp->mb[4] = MSW(size);
2954 mcp->mb[5] = LSW(size);
2955 mcp->out_mb |= MBX_5|MBX_4;
2957 mcp->mb[4] = LSW(size);
2958 mcp->out_mb |= MBX_4;
2962 mcp->tov = MBX_TOV_SECONDS;
2964 rval = qla2x00_mailbox_command(vha, mcp);
2966 if (rval != QLA_SUCCESS) {
2967 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
2968 vha->host_no, rval, mcp->mb[0]));
2970 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2976 /* 84XX Support **************************************************************/
2978 struct cs84xx_mgmt_cmd {
2980 struct verify_chip_entry_84xx req;
2981 struct verify_chip_rsp_84xx rsp;
2986 qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
2989 struct cs84xx_mgmt_cmd *mn;
2992 unsigned long flags;
2993 struct qla_hw_data *ha = vha->hw;
2995 DEBUG16(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2997 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
2999 DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX "
3000 "IOCB.\n", __func__, vha->host_no));
3001 return QLA_MEMORY_ALLOC_FAILED;
3005 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
3006 /* Diagnostic firmware? */
3007 /* options |= MENLO_DIAG_FW; */
3008 /* We update the firmware with only one data sequence. */
3009 options |= VCO_END_OF_DATA;
3013 memset(mn, 0, sizeof(*mn));
3014 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
3015 mn->p.req.entry_count = 1;
3016 mn->p.req.options = cpu_to_le16(options);
3018 DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__,
3020 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3023 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
3024 if (rval != QLA_SUCCESS) {
3025 DEBUG2_16(printk("%s(%ld): failed to issue Verify "
3026 "IOCB (%x).\n", __func__, vha->host_no, rval));
3030 DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__,
3032 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3035 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3036 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3037 le16_to_cpu(mn->p.rsp.failure_code) : 0;
3038 DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__,
3039 vha->host_no, status[0], status[1]));
3041 if (status[0] != CS_COMPLETE) {
3042 rval = QLA_FUNCTION_FAILED;
3043 if (!(options & VCO_DONT_UPDATE_FW)) {
3044 DEBUG2_16(printk("%s(%ld): Firmware update "
3045 "failed. Retrying without update "
3046 "firmware.\n", __func__, vha->host_no));
3047 options |= VCO_DONT_UPDATE_FW;
3048 options &= ~VCO_FORCE_UPDATE;
3052 DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n",
3053 __func__, vha->host_no,
3054 le32_to_cpu(mn->p.rsp.fw_ver)));
3056 /* NOTE: we only update OP firmware. */
3057 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3058 ha->cs84xx->op_fw_version =
3059 le32_to_cpu(mn->p.rsp.fw_ver);
3060 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3066 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3068 if (rval != QLA_SUCCESS) {
3069 DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__,
3070 vha->host_no, rval));
3072 DEBUG16(printk("%s(%ld): done.\n", __func__, vha->host_no));
3079 qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req,
3083 unsigned long flags;
3085 mbx_cmd_t *mcp = &mc;
3086 struct device_reg_25xxmq __iomem *reg;
3087 struct qla_hw_data *ha = vha->hw;
3089 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
3090 mcp->mb[1] = options;
3091 mcp->mb[2] = MSW(LSD(req->dma));
3092 mcp->mb[3] = LSW(LSD(req->dma));
3093 mcp->mb[6] = MSW(MSD(req->dma));
3094 mcp->mb[7] = LSW(MSD(req->dma));
3095 mcp->mb[5] = req->length;
3097 mcp->mb[10] = req->rsp->id;
3098 mcp->mb[12] = req->qos;
3099 mcp->mb[11] = req->vp_idx;
3100 mcp->mb[13] = req->rid;
3102 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3103 QLA_QUE_PAGE * req->id);
3105 mcp->mb[4] = req->id;
3106 /* que in ptr index */
3108 /* que out ptr index */
3110 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
3111 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3113 mcp->flags = MBX_DMA_OUT;
3116 spin_lock_irqsave(&ha->hardware_lock, flags);
3117 if (!(options & BIT_0)) {
3118 WRT_REG_DWORD(®->req_q_in, 0);
3119 WRT_REG_DWORD(®->req_q_out, 0);
3121 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3123 rval = qla2x00_mailbox_command(vha, mcp);
3124 if (rval != QLA_SUCCESS)
3125 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x mb0=%x.\n",
3126 __func__, vha->host_no, rval, mcp->mb[0]));
3131 qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp,
3135 unsigned long flags;
3137 mbx_cmd_t *mcp = &mc;
3138 struct device_reg_25xxmq __iomem *reg;
3139 struct qla_hw_data *ha = vha->hw;
3141 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
3142 mcp->mb[1] = options;
3143 mcp->mb[2] = MSW(LSD(rsp->dma));
3144 mcp->mb[3] = LSW(LSD(rsp->dma));
3145 mcp->mb[6] = MSW(MSD(rsp->dma));
3146 mcp->mb[7] = LSW(MSD(rsp->dma));
3147 mcp->mb[5] = rsp->length;
3148 mcp->mb[11] = rsp->vp_idx;
3149 mcp->mb[14] = rsp->msix->vector;
3150 mcp->mb[13] = rsp->rid;
3152 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3153 QLA_QUE_PAGE * rsp->id);
3155 mcp->mb[4] = rsp->id;
3156 /* que in ptr index */
3158 /* que out ptr index */
3160 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7
3161 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3163 mcp->flags = MBX_DMA_OUT;
3166 spin_lock_irqsave(&ha->hardware_lock, flags);
3167 if (!(options & BIT_0)) {
3168 WRT_REG_DWORD(®->rsp_q_out, 0);
3169 WRT_REG_DWORD(®->rsp_q_in, 0);
3172 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3174 rval = qla2x00_mailbox_command(vha, mcp);
3175 if (rval != QLA_SUCCESS)
3176 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x "
3177 "mb0=%x.\n", __func__,
3178 vha->host_no, rval, mcp->mb[0]));