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)
571 struct qla_hw_data *ha = vha->hw;
573 mbx_cmd_t *mcp = &mc;
575 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", vha->host_no));
577 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
585 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
586 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
587 mcp->tov = MBX_TOV_SECONDS;
589 rval = qla2x00_mailbox_command(vha, mcp);
591 if (rval == QLA_SUCCESS) {
592 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
593 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
594 rval = QLA_FUNCTION_FAILED;
595 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
596 mcp->mb[7] != 0x2525)
597 rval = QLA_FUNCTION_FAILED;
598 if (rval == QLA_FUNCTION_FAILED) {
599 struct device_reg_24xx __iomem *reg =
602 qla2xxx_hw_event_log(vha, HW_EVENT_ISP_ERR, 0,
603 LSW(RD_REG_DWORD(®->hccr)),
604 LSW(RD_REG_DWORD(®->istatus)));
608 if (rval != QLA_SUCCESS) {
610 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
611 vha->host_no, rval));
614 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
622 * qla2x00_verify_checksum
623 * Verify firmware checksum.
626 * ha = adapter block pointer.
627 * TARGET_QUEUE_LOCK must be released.
628 * ADAPTER_STATE_LOCK must be released.
631 * qla2x00 local function return status code.
637 qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
641 mbx_cmd_t *mcp = &mc;
643 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
645 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
648 if (IS_FWI2_CAPABLE(vha->hw)) {
649 mcp->mb[1] = MSW(risc_addr);
650 mcp->mb[2] = LSW(risc_addr);
651 mcp->out_mb |= MBX_2|MBX_1;
652 mcp->in_mb |= MBX_2|MBX_1;
654 mcp->mb[1] = LSW(risc_addr);
655 mcp->out_mb |= MBX_1;
659 mcp->tov = MBX_TOV_SECONDS;
661 rval = qla2x00_mailbox_command(vha, mcp);
663 if (rval != QLA_SUCCESS) {
664 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
665 vha->host_no, rval, IS_FWI2_CAPABLE(vha->hw) ?
666 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
668 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
676 * Issue IOCB using mailbox command
679 * ha = adapter state pointer.
680 * buffer = buffer pointer.
681 * phys_addr = physical address of buffer.
682 * size = size of buffer.
683 * TARGET_QUEUE_LOCK must be released.
684 * ADAPTER_STATE_LOCK must be released.
687 * qla2x00 local function return status code.
693 qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
694 dma_addr_t phys_addr, size_t size, uint32_t tov)
698 mbx_cmd_t *mcp = &mc;
700 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
702 mcp->mb[2] = MSW(phys_addr);
703 mcp->mb[3] = LSW(phys_addr);
704 mcp->mb[6] = MSW(MSD(phys_addr));
705 mcp->mb[7] = LSW(MSD(phys_addr));
706 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
707 mcp->in_mb = MBX_2|MBX_0;
710 rval = qla2x00_mailbox_command(vha, mcp);
712 if (rval != QLA_SUCCESS) {
714 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
715 vha->host_no, rval));
717 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
719 /* Mask reserved bits. */
720 sts_entry->entry_status &=
721 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
728 qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
731 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
736 * qla2x00_abort_command
737 * Abort command aborts a specified IOCB.
740 * ha = adapter block pointer.
741 * sp = SB structure pointer.
744 * qla2x00 local function return status code.
750 qla2x00_abort_command(scsi_qla_host_t *vha, srb_t *sp, struct req_que *req)
752 unsigned long flags = 0;
757 mbx_cmd_t *mcp = &mc;
758 struct qla_hw_data *ha = vha->hw;
760 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", vha->host_no));
764 spin_lock_irqsave(&ha->hardware_lock, flags);
765 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
766 if (req->outstanding_cmds[handle] == sp)
769 spin_unlock_irqrestore(&ha->hardware_lock, flags);
771 if (handle == MAX_OUTSTANDING_COMMANDS) {
772 /* command not found */
773 return QLA_FUNCTION_FAILED;
776 mcp->mb[0] = MBC_ABORT_COMMAND;
777 if (HAS_EXTENDED_IDS(ha))
778 mcp->mb[1] = fcport->loop_id;
780 mcp->mb[1] = fcport->loop_id << 8;
781 mcp->mb[2] = (uint16_t)handle;
782 mcp->mb[3] = (uint16_t)(handle >> 16);
783 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
784 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
786 mcp->tov = MBX_TOV_SECONDS;
788 rval = qla2x00_mailbox_command(vha, mcp);
790 if (rval != QLA_SUCCESS) {
791 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
792 vha->host_no, rval));
794 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
802 qla2x00_abort_target(struct fc_port *fcport, unsigned int l)
806 mbx_cmd_t *mcp = &mc;
807 scsi_qla_host_t *vha;
811 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
815 req = vha->hw->req_q_map[0];
816 rsp = vha->hw->rsp_q_map[0];
817 mcp->mb[0] = MBC_ABORT_TARGET;
818 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
819 if (HAS_EXTENDED_IDS(vha->hw)) {
820 mcp->mb[1] = fcport->loop_id;
822 mcp->out_mb |= MBX_10;
824 mcp->mb[1] = fcport->loop_id << 8;
826 mcp->mb[2] = vha->hw->loop_reset_delay;
827 mcp->mb[9] = vha->vp_idx;
830 mcp->tov = MBX_TOV_SECONDS;
832 rval = qla2x00_mailbox_command(vha, mcp);
833 if (rval != QLA_SUCCESS) {
834 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
835 vha->host_no, rval));
838 /* Issue marker IOCB. */
839 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
841 if (rval2 != QLA_SUCCESS) {
842 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
843 "(%x).\n", __func__, vha->host_no, rval2));
845 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
852 qla2x00_lun_reset(struct fc_port *fcport, unsigned int l)
856 mbx_cmd_t *mcp = &mc;
857 scsi_qla_host_t *vha;
861 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
864 req = vha->hw->req_q_map[0];
865 rsp = vha->hw->rsp_q_map[0];
866 mcp->mb[0] = MBC_LUN_RESET;
867 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
868 if (HAS_EXTENDED_IDS(vha->hw))
869 mcp->mb[1] = fcport->loop_id;
871 mcp->mb[1] = fcport->loop_id << 8;
874 mcp->mb[9] = vha->vp_idx;
877 mcp->tov = MBX_TOV_SECONDS;
879 rval = qla2x00_mailbox_command(vha, mcp);
880 if (rval != QLA_SUCCESS) {
881 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
882 vha->host_no, rval));
885 /* Issue marker IOCB. */
886 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
888 if (rval2 != QLA_SUCCESS) {
889 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
890 "(%x).\n", __func__, vha->host_no, rval2));
892 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
899 * qla2x00_get_adapter_id
900 * Get adapter ID and topology.
903 * ha = adapter block pointer.
904 * id = pointer for loop ID.
905 * al_pa = pointer for AL_PA.
906 * area = pointer for area.
907 * domain = pointer for domain.
908 * top = pointer for topology.
909 * TARGET_QUEUE_LOCK must be released.
910 * ADAPTER_STATE_LOCK must be released.
913 * qla2x00 local function return status code.
919 qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
920 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
924 mbx_cmd_t *mcp = &mc;
926 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
929 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
930 mcp->mb[9] = vha->vp_idx;
931 mcp->out_mb = MBX_9|MBX_0;
932 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
933 mcp->tov = MBX_TOV_SECONDS;
935 rval = qla2x00_mailbox_command(vha, mcp);
936 if (mcp->mb[0] == MBS_COMMAND_ERROR)
937 rval = QLA_COMMAND_ERROR;
938 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
939 rval = QLA_INVALID_COMMAND;
943 *al_pa = LSB(mcp->mb[2]);
944 *area = MSB(mcp->mb[2]);
945 *domain = LSB(mcp->mb[3]);
947 *sw_cap = mcp->mb[7];
949 if (rval != QLA_SUCCESS) {
951 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
952 vha->host_no, rval));
955 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
963 * qla2x00_get_retry_cnt
964 * Get current firmware login retry count and delay.
967 * ha = adapter block pointer.
968 * retry_cnt = pointer to login retry count.
969 * tov = pointer to login timeout value.
972 * qla2x00 local function return status code.
978 qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
984 mbx_cmd_t *mcp = &mc;
986 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
989 mcp->mb[0] = MBC_GET_RETRY_COUNT;
991 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
992 mcp->tov = MBX_TOV_SECONDS;
994 rval = qla2x00_mailbox_command(vha, mcp);
996 if (rval != QLA_SUCCESS) {
998 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
999 vha->host_no, mcp->mb[0]));
1001 /* Convert returned data and check our values. */
1002 *r_a_tov = mcp->mb[3] / 2;
1003 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1004 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1005 /* Update to the larger values */
1006 *retry_cnt = (uint8_t)mcp->mb[1];
1010 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
1011 "ratov=%d.\n", vha->host_no, mcp->mb[3], ratov));
1018 * qla2x00_init_firmware
1019 * Initialize adapter firmware.
1022 * ha = adapter block pointer.
1023 * dptr = Initialization control block pointer.
1024 * size = size of initialization control block.
1025 * TARGET_QUEUE_LOCK must be released.
1026 * ADAPTER_STATE_LOCK must be released.
1029 * qla2x00 local function return status code.
1035 qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
1039 mbx_cmd_t *mcp = &mc;
1040 struct qla_hw_data *ha = vha->hw;
1042 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1045 if (ha->flags.npiv_supported)
1046 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1048 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1050 mcp->mb[2] = MSW(ha->init_cb_dma);
1051 mcp->mb[3] = LSW(ha->init_cb_dma);
1054 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1055 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1056 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1057 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1058 mcp->buf_size = size;
1059 mcp->flags = MBX_DMA_OUT;
1060 mcp->tov = MBX_TOV_SECONDS;
1061 rval = qla2x00_mailbox_command(vha, mcp);
1063 if (rval != QLA_SUCCESS) {
1065 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1067 vha->host_no, rval, mcp->mb[0]));
1070 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1078 * qla2x00_get_port_database
1079 * Issue normal/enhanced get port database mailbox command
1080 * and copy device name as necessary.
1083 * ha = adapter state pointer.
1084 * dev = structure pointer.
1085 * opt = enhanced cmd option byte.
1088 * qla2x00 local function return status code.
1094 qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
1098 mbx_cmd_t *mcp = &mc;
1099 port_database_t *pd;
1100 struct port_database_24xx *pd24;
1102 struct qla_hw_data *ha = vha->hw;
1104 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1107 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1109 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1110 "structure.\n", __func__, vha->host_no));
1111 return QLA_MEMORY_ALLOC_FAILED;
1113 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
1115 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1116 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
1117 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1118 mcp->mb[2] = MSW(pd_dma);
1119 mcp->mb[3] = LSW(pd_dma);
1120 mcp->mb[6] = MSW(MSD(pd_dma));
1121 mcp->mb[7] = LSW(MSD(pd_dma));
1122 mcp->mb[9] = vha->vp_idx;
1123 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1125 if (IS_FWI2_CAPABLE(ha)) {
1126 mcp->mb[1] = fcport->loop_id;
1128 mcp->out_mb |= MBX_10|MBX_1;
1129 mcp->in_mb |= MBX_1;
1130 } else if (HAS_EXTENDED_IDS(ha)) {
1131 mcp->mb[1] = fcport->loop_id;
1133 mcp->out_mb |= MBX_10|MBX_1;
1135 mcp->mb[1] = fcport->loop_id << 8 | opt;
1136 mcp->out_mb |= MBX_1;
1138 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1139 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
1140 mcp->flags = MBX_DMA_IN;
1141 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1142 rval = qla2x00_mailbox_command(vha, mcp);
1143 if (rval != QLA_SUCCESS)
1146 if (IS_FWI2_CAPABLE(ha)) {
1147 pd24 = (struct port_database_24xx *) pd;
1149 /* Check for logged in state. */
1150 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1151 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1152 DEBUG2(printk("%s(%ld): Unable to verify "
1153 "login-state (%x/%x) for loop_id %x\n",
1154 __func__, vha->host_no,
1155 pd24->current_login_state,
1156 pd24->last_login_state, fcport->loop_id));
1157 rval = QLA_FUNCTION_FAILED;
1161 /* Names are little-endian. */
1162 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1163 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1165 /* Get port_id of device. */
1166 fcport->d_id.b.domain = pd24->port_id[0];
1167 fcport->d_id.b.area = pd24->port_id[1];
1168 fcport->d_id.b.al_pa = pd24->port_id[2];
1169 fcport->d_id.b.rsvd_1 = 0;
1171 /* If not target must be initiator or unknown type. */
1172 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1173 fcport->port_type = FCT_INITIATOR;
1175 fcport->port_type = FCT_TARGET;
1177 /* Check for logged in state. */
1178 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1179 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1180 rval = QLA_FUNCTION_FAILED;
1184 /* Names are little-endian. */
1185 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1186 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1188 /* Get port_id of device. */
1189 fcport->d_id.b.domain = pd->port_id[0];
1190 fcport->d_id.b.area = pd->port_id[3];
1191 fcport->d_id.b.al_pa = pd->port_id[2];
1192 fcport->d_id.b.rsvd_1 = 0;
1194 /* Check for device require authentication. */
1195 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1196 (fcport->flags &= ~FCF_AUTH_REQ);
1198 /* If not target must be initiator or unknown type. */
1199 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1200 fcport->port_type = FCT_INITIATOR;
1202 fcport->port_type = FCT_TARGET;
1204 /* Passback COS information. */
1205 fcport->supported_classes = (pd->options & BIT_4) ?
1206 FC_COS_CLASS2: FC_COS_CLASS3;
1210 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1212 if (rval != QLA_SUCCESS) {
1213 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1214 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1216 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1223 * qla2x00_get_firmware_state
1224 * Get adapter firmware state.
1227 * ha = adapter block pointer.
1228 * dptr = pointer for firmware state.
1229 * TARGET_QUEUE_LOCK must be released.
1230 * ADAPTER_STATE_LOCK must be released.
1233 * qla2x00 local function return status code.
1239 qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
1243 mbx_cmd_t *mcp = &mc;
1245 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1248 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1249 mcp->out_mb = MBX_0;
1250 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1251 mcp->tov = MBX_TOV_SECONDS;
1253 rval = qla2x00_mailbox_command(vha, mcp);
1255 /* Return firmware states. */
1256 states[0] = mcp->mb[1];
1257 states[1] = mcp->mb[2];
1258 states[2] = mcp->mb[3];
1260 if (rval != QLA_SUCCESS) {
1262 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1263 "failed=%x.\n", vha->host_no, rval));
1266 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1274 * qla2x00_get_port_name
1275 * Issue get port name mailbox command.
1276 * Returned name is in big endian format.
1279 * ha = adapter block pointer.
1280 * loop_id = loop ID of device.
1281 * name = pointer for name.
1282 * TARGET_QUEUE_LOCK must be released.
1283 * ADAPTER_STATE_LOCK must be released.
1286 * qla2x00 local function return status code.
1292 qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
1297 mbx_cmd_t *mcp = &mc;
1299 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1302 mcp->mb[0] = MBC_GET_PORT_NAME;
1303 mcp->mb[9] = vha->vp_idx;
1304 mcp->out_mb = MBX_9|MBX_1|MBX_0;
1305 if (HAS_EXTENDED_IDS(vha->hw)) {
1306 mcp->mb[1] = loop_id;
1308 mcp->out_mb |= MBX_10;
1310 mcp->mb[1] = loop_id << 8 | opt;
1313 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1314 mcp->tov = MBX_TOV_SECONDS;
1316 rval = qla2x00_mailbox_command(vha, mcp);
1318 if (rval != QLA_SUCCESS) {
1320 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1321 vha->host_no, rval));
1324 /* This function returns name in big endian. */
1325 name[0] = MSB(mcp->mb[2]);
1326 name[1] = LSB(mcp->mb[2]);
1327 name[2] = MSB(mcp->mb[3]);
1328 name[3] = LSB(mcp->mb[3]);
1329 name[4] = MSB(mcp->mb[6]);
1330 name[5] = LSB(mcp->mb[6]);
1331 name[6] = MSB(mcp->mb[7]);
1332 name[7] = LSB(mcp->mb[7]);
1335 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1344 * Issue LIP reset mailbox command.
1347 * ha = adapter block pointer.
1348 * TARGET_QUEUE_LOCK must be released.
1349 * ADAPTER_STATE_LOCK must be released.
1352 * qla2x00 local function return status code.
1358 qla2x00_lip_reset(scsi_qla_host_t *vha)
1362 mbx_cmd_t *mcp = &mc;
1364 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1366 if (IS_FWI2_CAPABLE(vha->hw)) {
1367 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1370 mcp->mb[3] = vha->hw->loop_reset_delay;
1371 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1373 mcp->mb[0] = MBC_LIP_RESET;
1374 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1375 if (HAS_EXTENDED_IDS(vha->hw)) {
1376 mcp->mb[1] = 0x00ff;
1378 mcp->out_mb |= MBX_10;
1380 mcp->mb[1] = 0xff00;
1382 mcp->mb[2] = vha->hw->loop_reset_delay;
1386 mcp->tov = MBX_TOV_SECONDS;
1388 rval = qla2x00_mailbox_command(vha, mcp);
1390 if (rval != QLA_SUCCESS) {
1392 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1393 __func__, vha->host_no, rval));
1396 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1407 * ha = adapter block pointer.
1408 * sns = pointer for command.
1409 * cmd_size = command size.
1410 * buf_size = response/command size.
1411 * TARGET_QUEUE_LOCK must be released.
1412 * ADAPTER_STATE_LOCK must be released.
1415 * qla2x00 local function return status code.
1421 qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
1422 uint16_t cmd_size, size_t buf_size)
1426 mbx_cmd_t *mcp = &mc;
1428 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1431 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1432 "tov=%d.\n", vha->hw->retry_count, vha->hw->login_timeout,
1435 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1436 mcp->mb[1] = cmd_size;
1437 mcp->mb[2] = MSW(sns_phys_address);
1438 mcp->mb[3] = LSW(sns_phys_address);
1439 mcp->mb[6] = MSW(MSD(sns_phys_address));
1440 mcp->mb[7] = LSW(MSD(sns_phys_address));
1441 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1442 mcp->in_mb = MBX_0|MBX_1;
1443 mcp->buf_size = buf_size;
1444 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1445 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
1446 rval = qla2x00_mailbox_command(vha, mcp);
1448 if (rval != QLA_SUCCESS) {
1450 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1451 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1452 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1453 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1456 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", vha->host_no));
1463 qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1464 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1468 struct logio_entry_24xx *lg;
1471 struct qla_hw_data *ha = vha->hw;
1473 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1475 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1477 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1478 __func__, vha->host_no));
1479 return QLA_MEMORY_ALLOC_FAILED;
1481 memset(lg, 0, sizeof(struct logio_entry_24xx));
1483 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1484 lg->entry_count = 1;
1485 lg->nport_handle = cpu_to_le16(loop_id);
1486 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1488 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1490 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
1491 lg->port_id[0] = al_pa;
1492 lg->port_id[1] = area;
1493 lg->port_id[2] = domain;
1494 lg->vp_index = vha->vp_idx;
1495 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
1496 if (rval != QLA_SUCCESS) {
1497 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
1498 "(%x).\n", __func__, vha->host_no, rval));
1499 } else if (lg->entry_status != 0) {
1500 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1501 "-- error status (%x).\n", __func__, vha->host_no,
1503 rval = QLA_FUNCTION_FAILED;
1504 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1505 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1506 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1508 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1509 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1510 vha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1514 case LSC_SCODE_PORTID_USED:
1515 mb[0] = MBS_PORT_ID_USED;
1516 mb[1] = LSW(iop[1]);
1518 case LSC_SCODE_NPORT_USED:
1519 mb[0] = MBS_LOOP_ID_USED;
1521 case LSC_SCODE_NOLINK:
1522 case LSC_SCODE_NOIOCB:
1523 case LSC_SCODE_NOXCB:
1524 case LSC_SCODE_CMD_FAILED:
1525 case LSC_SCODE_NOFABRIC:
1526 case LSC_SCODE_FW_NOT_READY:
1527 case LSC_SCODE_NOT_LOGGED_IN:
1528 case LSC_SCODE_NOPCB:
1529 case LSC_SCODE_ELS_REJECT:
1530 case LSC_SCODE_CMD_PARAM_ERR:
1531 case LSC_SCODE_NONPORT:
1532 case LSC_SCODE_LOGGED_IN:
1533 case LSC_SCODE_NOFLOGI_ACC:
1535 mb[0] = MBS_COMMAND_ERROR;
1539 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1541 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1543 mb[0] = MBS_COMMAND_COMPLETE;
1545 if (iop[0] & BIT_4) {
1551 /* Passback COS information. */
1553 if (lg->io_parameter[7] || lg->io_parameter[8])
1554 mb[10] |= BIT_0; /* Class 2. */
1555 if (lg->io_parameter[9] || lg->io_parameter[10])
1556 mb[10] |= BIT_1; /* Class 3. */
1559 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1565 * qla2x00_login_fabric
1566 * Issue login fabric port mailbox command.
1569 * ha = adapter block pointer.
1570 * loop_id = device loop ID.
1571 * domain = device domain.
1572 * area = device area.
1573 * al_pa = device AL_PA.
1574 * status = pointer for return status.
1575 * opt = command options.
1576 * TARGET_QUEUE_LOCK must be released.
1577 * ADAPTER_STATE_LOCK must be released.
1580 * qla2x00 local function return status code.
1586 qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1587 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1591 mbx_cmd_t *mcp = &mc;
1592 struct qla_hw_data *ha = vha->hw;
1594 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", vha->host_no));
1596 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1597 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1598 if (HAS_EXTENDED_IDS(ha)) {
1599 mcp->mb[1] = loop_id;
1601 mcp->out_mb |= MBX_10;
1603 mcp->mb[1] = (loop_id << 8) | opt;
1605 mcp->mb[2] = domain;
1606 mcp->mb[3] = area << 8 | al_pa;
1608 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1609 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1611 rval = qla2x00_mailbox_command(vha, mcp);
1613 /* Return mailbox statuses. */
1620 /* COS retrieved from Get-Port-Database mailbox command. */
1624 if (rval != QLA_SUCCESS) {
1625 /* RLU tmp code: need to change main mailbox_command function to
1626 * return ok even when the mailbox completion value is not
1627 * SUCCESS. The caller needs to be responsible to interpret
1628 * the return values of this mailbox command if we're not
1629 * to change too much of the existing code.
1631 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1632 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1633 mcp->mb[0] == 0x4006)
1637 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1638 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", vha->host_no, rval,
1639 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
1642 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1650 * qla2x00_login_local_device
1651 * Issue login loop port mailbox command.
1654 * ha = adapter block pointer.
1655 * loop_id = device loop ID.
1656 * opt = command options.
1659 * Return status code.
1666 qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
1667 uint16_t *mb_ret, uint8_t opt)
1671 mbx_cmd_t *mcp = &mc;
1672 struct qla_hw_data *ha = vha->hw;
1674 if (IS_FWI2_CAPABLE(ha))
1675 return qla24xx_login_fabric(vha, fcport->loop_id,
1676 fcport->d_id.b.domain, fcport->d_id.b.area,
1677 fcport->d_id.b.al_pa, mb_ret, opt);
1679 DEBUG3(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1681 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1682 if (HAS_EXTENDED_IDS(ha))
1683 mcp->mb[1] = fcport->loop_id;
1685 mcp->mb[1] = fcport->loop_id << 8;
1687 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1688 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1689 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1691 rval = qla2x00_mailbox_command(vha, mcp);
1693 /* Return mailbox statuses. */
1694 if (mb_ret != NULL) {
1695 mb_ret[0] = mcp->mb[0];
1696 mb_ret[1] = mcp->mb[1];
1697 mb_ret[6] = mcp->mb[6];
1698 mb_ret[7] = mcp->mb[7];
1701 if (rval != QLA_SUCCESS) {
1702 /* AV tmp code: need to change main mailbox_command function to
1703 * return ok even when the mailbox completion value is not
1704 * SUCCESS. The caller needs to be responsible to interpret
1705 * the return values of this mailbox command if we're not
1706 * to change too much of the existing code.
1708 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1711 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1712 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
1713 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1714 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1715 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
1716 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1719 DEBUG3(printk("%s(%ld): done.\n", __func__, vha->host_no));
1726 qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1727 uint8_t area, uint8_t al_pa)
1730 struct logio_entry_24xx *lg;
1732 struct qla_hw_data *ha = vha->hw;
1734 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1736 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1738 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1739 __func__, vha->host_no));
1740 return QLA_MEMORY_ALLOC_FAILED;
1742 memset(lg, 0, sizeof(struct logio_entry_24xx));
1744 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1745 lg->entry_count = 1;
1746 lg->nport_handle = cpu_to_le16(loop_id);
1748 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
1749 lg->port_id[0] = al_pa;
1750 lg->port_id[1] = area;
1751 lg->port_id[2] = domain;
1752 lg->vp_index = vha->vp_idx;
1754 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
1755 if (rval != QLA_SUCCESS) {
1756 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1757 "(%x).\n", __func__, vha->host_no, rval));
1758 } else if (lg->entry_status != 0) {
1759 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1760 "-- error status (%x).\n", __func__, vha->host_no,
1762 rval = QLA_FUNCTION_FAILED;
1763 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1764 DEBUG2_3_11(printk("%s(%ld %d): failed to complete IOCB "
1765 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1766 vha->host_no, vha->vp_idx, le16_to_cpu(lg->comp_status),
1767 le32_to_cpu(lg->io_parameter[0]),
1768 le32_to_cpu(lg->io_parameter[1])));
1771 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1774 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1780 * qla2x00_fabric_logout
1781 * Issue logout fabric port mailbox command.
1784 * ha = adapter block pointer.
1785 * loop_id = device loop ID.
1786 * TARGET_QUEUE_LOCK must be released.
1787 * ADAPTER_STATE_LOCK must be released.
1790 * qla2x00 local function return status code.
1796 qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1797 uint8_t area, uint8_t al_pa)
1801 mbx_cmd_t *mcp = &mc;
1803 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1806 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1807 mcp->out_mb = MBX_1|MBX_0;
1808 if (HAS_EXTENDED_IDS(vha->hw)) {
1809 mcp->mb[1] = loop_id;
1811 mcp->out_mb |= MBX_10;
1813 mcp->mb[1] = loop_id << 8;
1816 mcp->in_mb = MBX_1|MBX_0;
1817 mcp->tov = MBX_TOV_SECONDS;
1819 rval = qla2x00_mailbox_command(vha, mcp);
1821 if (rval != QLA_SUCCESS) {
1823 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1824 "mbx1=%x.\n", vha->host_no, rval, mcp->mb[1]));
1827 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1835 * qla2x00_full_login_lip
1836 * Issue full login LIP mailbox command.
1839 * ha = adapter block pointer.
1840 * TARGET_QUEUE_LOCK must be released.
1841 * ADAPTER_STATE_LOCK must be released.
1844 * qla2x00 local function return status code.
1850 qla2x00_full_login_lip(scsi_qla_host_t *vha)
1854 mbx_cmd_t *mcp = &mc;
1856 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1859 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1860 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
1863 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1865 mcp->tov = MBX_TOV_SECONDS;
1867 rval = qla2x00_mailbox_command(vha, mcp);
1869 if (rval != QLA_SUCCESS) {
1871 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1872 vha->host_no, rval));
1875 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1883 * qla2x00_get_id_list
1886 * ha = adapter block pointer.
1889 * qla2x00 local function return status code.
1895 qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
1900 mbx_cmd_t *mcp = &mc;
1902 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1905 if (id_list == NULL)
1906 return QLA_FUNCTION_FAILED;
1908 mcp->mb[0] = MBC_GET_ID_LIST;
1909 mcp->out_mb = MBX_0;
1910 if (IS_FWI2_CAPABLE(vha->hw)) {
1911 mcp->mb[2] = MSW(id_list_dma);
1912 mcp->mb[3] = LSW(id_list_dma);
1913 mcp->mb[6] = MSW(MSD(id_list_dma));
1914 mcp->mb[7] = LSW(MSD(id_list_dma));
1916 mcp->mb[9] = vha->vp_idx;
1917 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
1919 mcp->mb[1] = MSW(id_list_dma);
1920 mcp->mb[2] = LSW(id_list_dma);
1921 mcp->mb[3] = MSW(MSD(id_list_dma));
1922 mcp->mb[6] = LSW(MSD(id_list_dma));
1923 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1925 mcp->in_mb = MBX_1|MBX_0;
1926 mcp->tov = MBX_TOV_SECONDS;
1928 rval = qla2x00_mailbox_command(vha, mcp);
1930 if (rval != QLA_SUCCESS) {
1932 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
1933 vha->host_no, rval));
1935 *entries = mcp->mb[1];
1936 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
1944 * qla2x00_get_resource_cnts
1945 * Get current firmware resource counts.
1948 * ha = adapter block pointer.
1951 * qla2x00 local function return status code.
1957 qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
1958 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
1959 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports)
1963 mbx_cmd_t *mcp = &mc;
1965 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1967 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
1968 mcp->out_mb = MBX_0;
1969 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1970 mcp->tov = MBX_TOV_SECONDS;
1972 rval = qla2x00_mailbox_command(vha, mcp);
1974 if (rval != QLA_SUCCESS) {
1976 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
1977 vha->host_no, mcp->mb[0]));
1979 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
1980 "mb7=%x mb10=%x mb11=%x.\n", __func__, vha->host_no,
1981 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
1982 mcp->mb[10], mcp->mb[11]));
1985 *cur_xchg_cnt = mcp->mb[3];
1987 *orig_xchg_cnt = mcp->mb[6];
1989 *cur_iocb_cnt = mcp->mb[7];
1991 *orig_iocb_cnt = mcp->mb[10];
1992 if (vha->hw->flags.npiv_supported && max_npiv_vports)
1993 *max_npiv_vports = mcp->mb[11];
1999 #if defined(QL_DEBUG_LEVEL_3)
2001 * qla2x00_get_fcal_position_map
2002 * Get FCAL (LILP) position map using mailbox command
2005 * ha = adapter state pointer.
2006 * pos_map = buffer pointer (can be NULL).
2009 * qla2x00 local function return status code.
2015 qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
2019 mbx_cmd_t *mcp = &mc;
2021 dma_addr_t pmap_dma;
2022 struct qla_hw_data *ha = vha->hw;
2024 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
2026 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
2027 __func__, vha->host_no));
2028 return QLA_MEMORY_ALLOC_FAILED;
2030 memset(pmap, 0, FCAL_MAP_SIZE);
2032 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2033 mcp->mb[2] = MSW(pmap_dma);
2034 mcp->mb[3] = LSW(pmap_dma);
2035 mcp->mb[6] = MSW(MSD(pmap_dma));
2036 mcp->mb[7] = LSW(MSD(pmap_dma));
2037 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2038 mcp->in_mb = MBX_1|MBX_0;
2039 mcp->buf_size = FCAL_MAP_SIZE;
2040 mcp->flags = MBX_DMA_IN;
2041 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2042 rval = qla2x00_mailbox_command(vha, mcp);
2044 if (rval == QLA_SUCCESS) {
2045 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2046 "size (%x)\n", __func__, vha->host_no, mcp->mb[0],
2047 mcp->mb[1], (unsigned)pmap[0]));
2048 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2051 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2053 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2055 if (rval != QLA_SUCCESS) {
2056 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2057 vha->host_no, rval));
2059 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2067 * qla2x00_get_link_status
2070 * ha = adapter block pointer.
2071 * loop_id = device loop ID.
2072 * ret_buf = pointer to link status return buffer.
2076 * BIT_0 = mem alloc error.
2077 * BIT_1 = mailbox error.
2080 qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
2081 struct link_statistics *stats, dma_addr_t stats_dma)
2085 mbx_cmd_t *mcp = &mc;
2086 uint32_t *siter, *diter, dwords;
2087 struct qla_hw_data *ha = vha->hw;
2089 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2091 mcp->mb[0] = MBC_GET_LINK_STATUS;
2092 mcp->mb[2] = MSW(stats_dma);
2093 mcp->mb[3] = LSW(stats_dma);
2094 mcp->mb[6] = MSW(MSD(stats_dma));
2095 mcp->mb[7] = LSW(MSD(stats_dma));
2096 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2098 if (IS_FWI2_CAPABLE(ha)) {
2099 mcp->mb[1] = loop_id;
2102 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2103 mcp->in_mb |= MBX_1;
2104 } else if (HAS_EXTENDED_IDS(ha)) {
2105 mcp->mb[1] = loop_id;
2107 mcp->out_mb |= MBX_10|MBX_1;
2109 mcp->mb[1] = loop_id << 8;
2110 mcp->out_mb |= MBX_1;
2112 mcp->tov = MBX_TOV_SECONDS;
2113 mcp->flags = IOCTL_CMD;
2114 rval = qla2x00_mailbox_command(vha, mcp);
2116 if (rval == QLA_SUCCESS) {
2117 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2118 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2119 __func__, vha->host_no, mcp->mb[0]));
2120 rval = QLA_FUNCTION_FAILED;
2122 /* Copy over data -- firmware data is LE. */
2123 dwords = offsetof(struct link_statistics, unused1) / 4;
2124 siter = diter = &stats->link_fail_cnt;
2126 *diter++ = le32_to_cpu(*siter++);
2130 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2131 vha->host_no, rval));
2138 qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
2139 dma_addr_t stats_dma)
2143 mbx_cmd_t *mcp = &mc;
2144 uint32_t *siter, *diter, dwords;
2146 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2148 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2149 mcp->mb[2] = MSW(stats_dma);
2150 mcp->mb[3] = LSW(stats_dma);
2151 mcp->mb[6] = MSW(MSD(stats_dma));
2152 mcp->mb[7] = LSW(MSD(stats_dma));
2153 mcp->mb[8] = sizeof(struct link_statistics) / 4;
2154 mcp->mb[9] = vha->vp_idx;
2156 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2157 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2158 mcp->tov = MBX_TOV_SECONDS;
2159 mcp->flags = IOCTL_CMD;
2160 rval = qla2x00_mailbox_command(vha, mcp);
2162 if (rval == QLA_SUCCESS) {
2163 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2164 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2165 __func__, vha->host_no, mcp->mb[0]));
2166 rval = QLA_FUNCTION_FAILED;
2168 /* Copy over data -- firmware data is LE. */
2169 dwords = sizeof(struct link_statistics) / 4;
2170 siter = diter = &stats->link_fail_cnt;
2172 *diter++ = le32_to_cpu(*siter++);
2176 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2177 vha->host_no, rval));
2184 qla24xx_abort_command(scsi_qla_host_t *vha, srb_t *sp, struct req_que *req)
2188 unsigned long flags = 0;
2190 struct abort_entry_24xx *abt;
2193 struct qla_hw_data *ha = vha->hw;
2195 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2197 fcport = sp->fcport;
2199 spin_lock_irqsave(&ha->hardware_lock, flags);
2200 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2201 if (req->outstanding_cmds[handle] == sp)
2204 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2205 if (handle == MAX_OUTSTANDING_COMMANDS) {
2206 /* Command not found. */
2207 return QLA_FUNCTION_FAILED;
2210 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2212 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2213 __func__, vha->host_no));
2214 return QLA_MEMORY_ALLOC_FAILED;
2216 memset(abt, 0, sizeof(struct abort_entry_24xx));
2218 abt->entry_type = ABORT_IOCB_TYPE;
2219 abt->entry_count = 1;
2220 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2221 abt->handle_to_abort = handle;
2222 abt->port_id[0] = fcport->d_id.b.al_pa;
2223 abt->port_id[1] = fcport->d_id.b.area;
2224 abt->port_id[2] = fcport->d_id.b.domain;
2225 abt->vp_index = fcport->vp_idx;
2227 abt->req_que_no = cpu_to_le16(req->id);
2229 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
2230 if (rval != QLA_SUCCESS) {
2231 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2232 __func__, vha->host_no, rval));
2233 } else if (abt->entry_status != 0) {
2234 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2235 "-- error status (%x).\n", __func__, vha->host_no,
2236 abt->entry_status));
2237 rval = QLA_FUNCTION_FAILED;
2238 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2239 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2240 "-- completion status (%x).\n", __func__, vha->host_no,
2241 le16_to_cpu(abt->nport_handle)));
2242 rval = QLA_FUNCTION_FAILED;
2244 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2247 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2252 struct tsk_mgmt_cmd {
2254 struct tsk_mgmt_entry tsk;
2255 struct sts_entry_24xx sts;
2260 __qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
2264 struct tsk_mgmt_cmd *tsk;
2266 scsi_qla_host_t *vha;
2267 struct qla_hw_data *ha;
2268 struct req_que *req;
2269 struct rsp_que *rsp;
2271 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
2275 req = ha->req_q_map[0];
2276 rsp = ha->rsp_q_map[0];
2277 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
2279 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2280 "IOCB.\n", __func__, vha->host_no));
2281 return QLA_MEMORY_ALLOC_FAILED;
2283 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2285 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2286 tsk->p.tsk.entry_count = 1;
2287 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2288 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
2289 tsk->p.tsk.control_flags = cpu_to_le32(type);
2290 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2291 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2292 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2293 tsk->p.tsk.vp_index = fcport->vp_idx;
2294 if (type == TCF_LUN_RESET) {
2295 int_to_scsilun(l, &tsk->p.tsk.lun);
2296 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2297 sizeof(tsk->p.tsk.lun));
2300 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
2301 if (rval != QLA_SUCCESS) {
2302 DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
2303 "(%x).\n", __func__, vha->host_no, name, rval));
2304 } else if (tsk->p.sts.entry_status != 0) {
2305 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2306 "-- error status (%x).\n", __func__, vha->host_no,
2307 tsk->p.sts.entry_status));
2308 rval = QLA_FUNCTION_FAILED;
2309 } else if (tsk->p.sts.comp_status !=
2310 __constant_cpu_to_le16(CS_COMPLETE)) {
2311 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2312 "-- completion status (%x).\n", __func__,
2313 vha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
2314 rval = QLA_FUNCTION_FAILED;
2317 /* Issue marker IOCB. */
2318 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
2319 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2320 if (rval2 != QLA_SUCCESS) {
2321 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2322 "(%x).\n", __func__, vha->host_no, rval2));
2324 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2327 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
2333 qla24xx_abort_target(struct fc_port *fcport, unsigned int l)
2335 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l);
2339 qla24xx_lun_reset(struct fc_port *fcport, unsigned int l)
2341 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l);
2345 qla2x00_system_error(scsi_qla_host_t *vha)
2349 mbx_cmd_t *mcp = &mc;
2350 struct qla_hw_data *ha = vha->hw;
2352 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
2353 return QLA_FUNCTION_FAILED;
2355 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2357 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2358 mcp->out_mb = MBX_0;
2362 rval = qla2x00_mailbox_command(vha, mcp);
2364 if (rval != QLA_SUCCESS) {
2365 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2366 vha->host_no, rval));
2368 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2375 * qla2x00_set_serdes_params() -
2381 qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
2382 uint16_t sw_em_2g, uint16_t sw_em_4g)
2386 mbx_cmd_t *mcp = &mc;
2388 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2390 mcp->mb[0] = MBC_SERDES_PARAMS;
2392 mcp->mb[2] = sw_em_1g | BIT_15;
2393 mcp->mb[3] = sw_em_2g | BIT_15;
2394 mcp->mb[4] = sw_em_4g | BIT_15;
2395 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2397 mcp->tov = MBX_TOV_SECONDS;
2399 rval = qla2x00_mailbox_command(vha, mcp);
2401 if (rval != QLA_SUCCESS) {
2403 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2404 vha->host_no, rval, mcp->mb[0]));
2407 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2414 qla2x00_stop_firmware(scsi_qla_host_t *vha)
2418 mbx_cmd_t *mcp = &mc;
2420 if (!IS_FWI2_CAPABLE(vha->hw))
2421 return QLA_FUNCTION_FAILED;
2423 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2425 mcp->mb[0] = MBC_STOP_FIRMWARE;
2426 mcp->out_mb = MBX_0;
2430 rval = qla2x00_mailbox_command(vha, mcp);
2432 if (rval != QLA_SUCCESS) {
2433 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2434 vha->host_no, rval));
2436 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2443 qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
2448 mbx_cmd_t *mcp = &mc;
2450 if (!IS_FWI2_CAPABLE(vha->hw))
2451 return QLA_FUNCTION_FAILED;
2453 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2455 mcp->mb[0] = MBC_TRACE_CONTROL;
2456 mcp->mb[1] = TC_EFT_ENABLE;
2457 mcp->mb[2] = LSW(eft_dma);
2458 mcp->mb[3] = MSW(eft_dma);
2459 mcp->mb[4] = LSW(MSD(eft_dma));
2460 mcp->mb[5] = MSW(MSD(eft_dma));
2461 mcp->mb[6] = buffers;
2462 mcp->mb[7] = TC_AEN_DISABLE;
2463 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2464 mcp->in_mb = MBX_1|MBX_0;
2465 mcp->tov = MBX_TOV_SECONDS;
2467 rval = qla2x00_mailbox_command(vha, mcp);
2468 if (rval != QLA_SUCCESS) {
2469 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2470 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2472 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2479 qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
2483 mbx_cmd_t *mcp = &mc;
2485 if (!IS_FWI2_CAPABLE(vha->hw))
2486 return QLA_FUNCTION_FAILED;
2488 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2490 mcp->mb[0] = MBC_TRACE_CONTROL;
2491 mcp->mb[1] = TC_EFT_DISABLE;
2492 mcp->out_mb = MBX_1|MBX_0;
2493 mcp->in_mb = MBX_1|MBX_0;
2494 mcp->tov = MBX_TOV_SECONDS;
2496 rval = qla2x00_mailbox_command(vha, mcp);
2497 if (rval != QLA_SUCCESS) {
2498 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2499 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2501 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2508 qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
2509 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2513 mbx_cmd_t *mcp = &mc;
2515 if (!IS_QLA25XX(vha->hw))
2516 return QLA_FUNCTION_FAILED;
2518 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2520 mcp->mb[0] = MBC_TRACE_CONTROL;
2521 mcp->mb[1] = TC_FCE_ENABLE;
2522 mcp->mb[2] = LSW(fce_dma);
2523 mcp->mb[3] = MSW(fce_dma);
2524 mcp->mb[4] = LSW(MSD(fce_dma));
2525 mcp->mb[5] = MSW(MSD(fce_dma));
2526 mcp->mb[6] = buffers;
2527 mcp->mb[7] = TC_AEN_DISABLE;
2529 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2530 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2531 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2533 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2534 mcp->tov = MBX_TOV_SECONDS;
2536 rval = qla2x00_mailbox_command(vha, mcp);
2537 if (rval != QLA_SUCCESS) {
2538 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2539 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2541 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2544 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2553 qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
2557 mbx_cmd_t *mcp = &mc;
2559 if (!IS_FWI2_CAPABLE(vha->hw))
2560 return QLA_FUNCTION_FAILED;
2562 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2564 mcp->mb[0] = MBC_TRACE_CONTROL;
2565 mcp->mb[1] = TC_FCE_DISABLE;
2566 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
2567 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2568 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2570 mcp->tov = MBX_TOV_SECONDS;
2572 rval = qla2x00_mailbox_command(vha, mcp);
2573 if (rval != QLA_SUCCESS) {
2574 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2575 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2577 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2580 *wr = (uint64_t) mcp->mb[5] << 48 |
2581 (uint64_t) mcp->mb[4] << 32 |
2582 (uint64_t) mcp->mb[3] << 16 |
2583 (uint64_t) mcp->mb[2];
2585 *rd = (uint64_t) mcp->mb[9] << 48 |
2586 (uint64_t) mcp->mb[8] << 32 |
2587 (uint64_t) mcp->mb[7] << 16 |
2588 (uint64_t) mcp->mb[6];
2595 qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint16_t addr,
2596 uint16_t off, uint16_t count)
2600 mbx_cmd_t *mcp = &mc;
2602 if (!IS_FWI2_CAPABLE(vha->hw))
2603 return QLA_FUNCTION_FAILED;
2605 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2607 mcp->mb[0] = MBC_READ_SFP;
2609 mcp->mb[2] = MSW(sfp_dma);
2610 mcp->mb[3] = LSW(sfp_dma);
2611 mcp->mb[6] = MSW(MSD(sfp_dma));
2612 mcp->mb[7] = LSW(MSD(sfp_dma));
2616 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2618 mcp->tov = MBX_TOV_SECONDS;
2620 rval = qla2x00_mailbox_command(vha, mcp);
2622 if (rval != QLA_SUCCESS) {
2623 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2624 vha->host_no, rval, mcp->mb[0]));
2626 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2633 qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
2634 uint16_t port_speed, uint16_t *mb)
2638 mbx_cmd_t *mcp = &mc;
2640 if (!IS_IIDMA_CAPABLE(vha->hw))
2641 return QLA_FUNCTION_FAILED;
2643 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2645 mcp->mb[0] = MBC_PORT_PARAMS;
2646 mcp->mb[1] = loop_id;
2648 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2649 mcp->mb[4] = mcp->mb[5] = 0;
2650 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2651 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2652 mcp->tov = MBX_TOV_SECONDS;
2654 rval = qla2x00_mailbox_command(vha, mcp);
2656 /* Return mailbox statuses. */
2665 if (rval != QLA_SUCCESS) {
2666 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2667 vha->host_no, rval));
2669 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2676 qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
2677 struct vp_rpt_id_entry_24xx *rptid_entry)
2680 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
2681 struct qla_hw_data *ha = vha->hw;
2682 scsi_qla_host_t *vp;
2684 if (rptid_entry->entry_status != 0)
2687 if (rptid_entry->format == 0) {
2688 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
2689 " number of VPs acquired %d\n", __func__, vha->host_no,
2690 MSB(rptid_entry->vp_count), LSB(rptid_entry->vp_count)));
2691 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2692 rptid_entry->port_id[2], rptid_entry->port_id[1],
2693 rptid_entry->port_id[0]));
2694 } else if (rptid_entry->format == 1) {
2696 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2698 "with port id %02x%02x%02x\n", __func__, vha->host_no,
2700 rptid_entry->port_id[2], rptid_entry->port_id[1],
2701 rptid_entry->port_id[0]));
2708 list_for_each_entry(vp, &ha->vp_list, list)
2709 if (vp_idx == vp->vp_idx)
2714 vp->d_id.b.domain = rptid_entry->port_id[2];
2715 vp->d_id.b.area = rptid_entry->port_id[1];
2716 vp->d_id.b.al_pa = rptid_entry->port_id[0];
2719 * Cannot configure here as we are still sitting on the
2720 * response queue. Handle it in dpc context.
2722 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
2723 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
2725 qla2xxx_wake_dpc(vha);
2730 * qla24xx_modify_vp_config
2731 * Change VP configuration for vha
2734 * vha = adapter block pointer.
2737 * qla2xxx local function return status code.
2743 qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2746 struct vp_config_entry_24xx *vpmod;
2747 dma_addr_t vpmod_dma;
2748 struct qla_hw_data *ha = vha->hw;
2749 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2751 /* This can be called by the parent */
2753 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
2755 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
2756 "IOCB.\n", __func__, vha->host_no));
2757 return QLA_MEMORY_ALLOC_FAILED;
2760 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2761 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2762 vpmod->entry_count = 1;
2763 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2764 vpmod->vp_count = 1;
2765 vpmod->vp_index1 = vha->vp_idx;
2766 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2767 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2768 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2769 vpmod->entry_count = 1;
2771 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
2772 if (rval != QLA_SUCCESS) {
2773 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
2774 "(%x).\n", __func__, base_vha->host_no, rval));
2775 } else if (vpmod->comp_status != 0) {
2776 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2777 "-- error status (%x).\n", __func__, base_vha->host_no,
2778 vpmod->comp_status));
2779 rval = QLA_FUNCTION_FAILED;
2780 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2781 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2782 "-- completion status (%x).\n", __func__, base_vha->host_no,
2783 le16_to_cpu(vpmod->comp_status)));
2784 rval = QLA_FUNCTION_FAILED;
2787 DEBUG11(printk("%s(%ld): done.\n", __func__,
2788 base_vha->host_no));
2789 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2791 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
2797 * qla24xx_control_vp
2798 * Enable a virtual port for given host
2801 * ha = adapter block pointer.
2802 * vhba = virtual adapter (unused)
2803 * index = index number for enabled VP
2806 * qla2xxx local function return status code.
2812 qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2816 struct vp_ctrl_entry_24xx *vce;
2818 struct qla_hw_data *ha = vha->hw;
2819 int vp_index = vha->vp_idx;
2820 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2822 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
2823 vha->host_no, vp_index));
2825 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
2826 return QLA_PARAMETER_ERROR;
2828 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2830 DEBUG2_3(printk("%s(%ld): "
2831 "failed to allocate VP Control IOCB.\n", __func__,
2832 base_vha->host_no));
2833 return QLA_MEMORY_ALLOC_FAILED;
2835 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2837 vce->entry_type = VP_CTRL_IOCB_TYPE;
2838 vce->entry_count = 1;
2839 vce->command = cpu_to_le16(cmd);
2840 vce->vp_count = __constant_cpu_to_le16(1);
2842 /* index map in firmware starts with 1; decrement index
2843 * this is ok as we never use index 0
2845 map = (vp_index - 1) / 8;
2846 pos = (vp_index - 1) & 7;
2847 mutex_lock(&ha->vport_lock);
2848 vce->vp_idx_map[map] |= 1 << pos;
2849 mutex_unlock(&ha->vport_lock);
2851 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
2852 if (rval != QLA_SUCCESS) {
2853 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
2854 "(%x).\n", __func__, base_vha->host_no, rval));
2855 printk("%s(%ld): failed to issue VP control IOCB"
2856 "(%x).\n", __func__, base_vha->host_no, rval);
2857 } else if (vce->entry_status != 0) {
2858 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2859 "-- error status (%x).\n", __func__, base_vha->host_no,
2860 vce->entry_status));
2861 printk("%s(%ld): failed to complete IOCB "
2862 "-- error status (%x).\n", __func__, base_vha->host_no,
2864 rval = QLA_FUNCTION_FAILED;
2865 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2866 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2867 "-- completion status (%x).\n", __func__, base_vha->host_no,
2868 le16_to_cpu(vce->comp_status)));
2869 printk("%s(%ld): failed to complete IOCB "
2870 "-- completion status (%x).\n", __func__, base_vha->host_no,
2871 le16_to_cpu(vce->comp_status));
2872 rval = QLA_FUNCTION_FAILED;
2874 DEBUG2(printk("%s(%ld): done.\n", __func__, base_vha->host_no));
2877 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
2883 * qla2x00_send_change_request
2884 * Receive or disable RSCN request from fabric controller
2887 * ha = adapter block pointer
2888 * format = registration format:
2890 * 1 - Fabric detected registration
2891 * 2 - N_port detected registration
2892 * 3 - Full registration
2893 * FF - clear registration
2894 * vp_idx = Virtual port index
2897 * qla2x00 local function return status code.
2904 qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
2909 mbx_cmd_t *mcp = &mc;
2912 * This command is implicitly executed by firmware during login for the
2916 return QLA_FUNCTION_FAILED;
2918 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
2919 mcp->mb[1] = format;
2920 mcp->mb[9] = vp_idx;
2921 mcp->out_mb = MBX_9|MBX_1|MBX_0;
2922 mcp->in_mb = MBX_0|MBX_1;
2923 mcp->tov = MBX_TOV_SECONDS;
2925 rval = qla2x00_mailbox_command(vha, mcp);
2927 if (rval == QLA_SUCCESS) {
2928 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2938 qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
2943 mbx_cmd_t *mcp = &mc;
2945 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2947 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
2948 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
2949 mcp->mb[8] = MSW(addr);
2950 mcp->out_mb = MBX_8|MBX_0;
2952 mcp->mb[0] = MBC_DUMP_RISC_RAM;
2953 mcp->out_mb = MBX_0;
2955 mcp->mb[1] = LSW(addr);
2956 mcp->mb[2] = MSW(req_dma);
2957 mcp->mb[3] = LSW(req_dma);
2958 mcp->mb[6] = MSW(MSD(req_dma));
2959 mcp->mb[7] = LSW(MSD(req_dma));
2960 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
2961 if (IS_FWI2_CAPABLE(vha->hw)) {
2962 mcp->mb[4] = MSW(size);
2963 mcp->mb[5] = LSW(size);
2964 mcp->out_mb |= MBX_5|MBX_4;
2966 mcp->mb[4] = LSW(size);
2967 mcp->out_mb |= MBX_4;
2971 mcp->tov = MBX_TOV_SECONDS;
2973 rval = qla2x00_mailbox_command(vha, mcp);
2975 if (rval != QLA_SUCCESS) {
2976 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
2977 vha->host_no, rval, mcp->mb[0]));
2979 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2985 /* 84XX Support **************************************************************/
2987 struct cs84xx_mgmt_cmd {
2989 struct verify_chip_entry_84xx req;
2990 struct verify_chip_rsp_84xx rsp;
2995 qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
2998 struct cs84xx_mgmt_cmd *mn;
3001 unsigned long flags;
3002 struct qla_hw_data *ha = vha->hw;
3004 DEBUG16(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3006 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
3008 DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX "
3009 "IOCB.\n", __func__, vha->host_no));
3010 return QLA_MEMORY_ALLOC_FAILED;
3014 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
3015 /* Diagnostic firmware? */
3016 /* options |= MENLO_DIAG_FW; */
3017 /* We update the firmware with only one data sequence. */
3018 options |= VCO_END_OF_DATA;
3022 memset(mn, 0, sizeof(*mn));
3023 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
3024 mn->p.req.entry_count = 1;
3025 mn->p.req.options = cpu_to_le16(options);
3027 DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__,
3029 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3032 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
3033 if (rval != QLA_SUCCESS) {
3034 DEBUG2_16(printk("%s(%ld): failed to issue Verify "
3035 "IOCB (%x).\n", __func__, vha->host_no, rval));
3039 DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__,
3041 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3044 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3045 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3046 le16_to_cpu(mn->p.rsp.failure_code) : 0;
3047 DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__,
3048 vha->host_no, status[0], status[1]));
3050 if (status[0] != CS_COMPLETE) {
3051 rval = QLA_FUNCTION_FAILED;
3052 if (!(options & VCO_DONT_UPDATE_FW)) {
3053 DEBUG2_16(printk("%s(%ld): Firmware update "
3054 "failed. Retrying without update "
3055 "firmware.\n", __func__, vha->host_no));
3056 options |= VCO_DONT_UPDATE_FW;
3057 options &= ~VCO_FORCE_UPDATE;
3061 DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n",
3062 __func__, vha->host_no,
3063 le32_to_cpu(mn->p.rsp.fw_ver)));
3065 /* NOTE: we only update OP firmware. */
3066 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3067 ha->cs84xx->op_fw_version =
3068 le32_to_cpu(mn->p.rsp.fw_ver);
3069 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3075 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3077 if (rval != QLA_SUCCESS) {
3078 DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__,
3079 vha->host_no, rval));
3081 DEBUG16(printk("%s(%ld): done.\n", __func__, vha->host_no));
3088 qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req,
3092 unsigned long flags;
3094 mbx_cmd_t *mcp = &mc;
3095 struct device_reg_25xxmq __iomem *reg;
3096 struct qla_hw_data *ha = vha->hw;
3098 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
3099 mcp->mb[1] = options;
3100 mcp->mb[2] = MSW(LSD(req->dma));
3101 mcp->mb[3] = LSW(LSD(req->dma));
3102 mcp->mb[6] = MSW(MSD(req->dma));
3103 mcp->mb[7] = LSW(MSD(req->dma));
3104 mcp->mb[5] = req->length;
3106 mcp->mb[10] = req->rsp->id;
3107 mcp->mb[12] = req->qos;
3108 mcp->mb[11] = req->vp_idx;
3109 mcp->mb[13] = req->rid;
3111 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3112 QLA_QUE_PAGE * req->id);
3114 mcp->mb[4] = req->id;
3115 /* que in ptr index */
3117 /* que out ptr index */
3119 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
3120 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3122 mcp->flags = MBX_DMA_OUT;
3125 spin_lock_irqsave(&ha->hardware_lock, flags);
3126 if (!(options & BIT_0)) {
3127 WRT_REG_DWORD(®->req_q_in, 0);
3128 WRT_REG_DWORD(®->req_q_out, 0);
3130 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3132 rval = qla2x00_mailbox_command(vha, mcp);
3133 if (rval != QLA_SUCCESS)
3134 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x mb0=%x.\n",
3135 __func__, vha->host_no, rval, mcp->mb[0]));
3140 qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp,
3144 unsigned long flags;
3146 mbx_cmd_t *mcp = &mc;
3147 struct device_reg_25xxmq __iomem *reg;
3148 struct qla_hw_data *ha = vha->hw;
3150 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
3151 mcp->mb[1] = options;
3152 mcp->mb[2] = MSW(LSD(rsp->dma));
3153 mcp->mb[3] = LSW(LSD(rsp->dma));
3154 mcp->mb[6] = MSW(MSD(rsp->dma));
3155 mcp->mb[7] = LSW(MSD(rsp->dma));
3156 mcp->mb[5] = rsp->length;
3157 mcp->mb[11] = rsp->vp_idx;
3158 mcp->mb[14] = rsp->msix->vector;
3159 mcp->mb[13] = rsp->rid;
3161 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3162 QLA_QUE_PAGE * rsp->id);
3164 mcp->mb[4] = rsp->id;
3165 /* que in ptr index */
3167 /* que out ptr index */
3169 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7
3170 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3172 mcp->flags = MBX_DMA_OUT;
3175 spin_lock_irqsave(&ha->hardware_lock, flags);
3176 if (!(options & BIT_0)) {
3177 WRT_REG_DWORD(®->rsp_q_out, 0);
3178 WRT_REG_DWORD(®->rsp_q_in, 0);
3181 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3183 rval = qla2x00_mailbox_command(vha, mcp);
3184 if (rval != QLA_SUCCESS)
3185 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x "
3186 "mb0=%x.\n", __func__,
3187 vha->host_no, rval, mcp->mb[0]));