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) || IS_NOPOLLING_TYPE(ha)) {
127 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
129 if (IS_FWI2_CAPABLE(ha))
130 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
132 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
133 spin_unlock_irqrestore(&ha->hardware_lock, flags);
135 wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ);
137 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
140 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
141 base_vha->host_no, command));
143 if (IS_FWI2_CAPABLE(ha))
144 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
146 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
147 spin_unlock_irqrestore(&ha->hardware_lock, flags);
149 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
150 while (!ha->flags.mbox_int) {
151 if (time_after(jiffies, wait_time))
154 /* Check for pending interrupts. */
155 qla2x00_poll(ha->rsp_q_map[0]);
157 if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
163 /* Check whether we timed out */
164 if (ha->flags.mbox_int) {
167 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
168 base_vha->host_no, command));
170 /* Got interrupt. Clear the flag. */
171 ha->flags.mbox_int = 0;
172 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
174 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
175 rval = QLA_FUNCTION_FAILED;
177 /* Load return mailbox registers. */
179 iptr = (uint16_t *)&ha->mailbox_out[0];
181 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
191 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
192 defined(QL_DEBUG_LEVEL_11)
196 if (IS_FWI2_CAPABLE(ha)) {
197 mb0 = RD_REG_WORD(®->isp24.mailbox0);
198 ictrl = RD_REG_DWORD(®->isp24.ictrl);
200 mb0 = RD_MAILBOX_REG(ha, ®->isp, 0);
201 ictrl = RD_REG_WORD(®->isp.ictrl);
203 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
204 __func__, base_vha->host_no, command);
205 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
206 base_vha->host_no, ictrl, jiffies);
207 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
208 base_vha->host_no, mb0);
209 qla2x00_dump_regs(base_vha);
212 rval = QLA_FUNCTION_TIMEOUT;
215 ha->flags.mbox_busy = 0;
220 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
221 DEBUG11(printk("%s(%ld): checking for additional resp "
222 "interrupt.\n", __func__, base_vha->host_no));
224 /* polling mode for non isp_abort commands. */
225 qla2x00_poll(ha->rsp_q_map[0]);
228 if (rval == QLA_FUNCTION_TIMEOUT &&
229 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
230 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
231 /* not in dpc. schedule it for dpc to take over. */
232 DEBUG(printk("%s(%ld): timeout schedule "
233 "isp_abort_needed.\n", __func__,
235 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
236 "isp_abort_needed.\n", __func__,
238 qla_printk(KERN_WARNING, ha,
239 "Mailbox command timeout occurred. Scheduling ISP "
241 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
242 qla2xxx_wake_dpc(vha);
243 } else if (!abort_active) {
244 /* call abort directly since we are in the DPC thread */
245 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
246 __func__, base_vha->host_no));
247 DEBUG2_3_11(printk("%s(%ld): timeout calling "
248 "abort_isp\n", __func__, base_vha->host_no));
249 qla_printk(KERN_WARNING, ha,
250 "Mailbox command timeout occurred. Issuing ISP "
253 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
254 clear_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
255 if (qla2x00_abort_isp(base_vha)) {
256 /* Failed. retry later. */
257 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
259 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
260 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
262 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
263 __func__, base_vha->host_no));
267 /* Allow next mbx cmd to come in. */
269 complete(&ha->mbx_cmd_comp);
272 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
273 "mbx2=%x, cmd=%x ****\n", __func__, base_vha->host_no,
274 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
276 DEBUG11(printk("%s(%ld): done.\n", __func__,
284 qla2x00_load_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t risc_addr,
285 uint32_t risc_code_size)
288 struct qla_hw_data *ha = vha->hw;
290 mbx_cmd_t *mcp = &mc;
292 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
294 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
295 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
296 mcp->mb[8] = MSW(risc_addr);
297 mcp->out_mb = MBX_8|MBX_0;
299 mcp->mb[0] = MBC_LOAD_RISC_RAM;
302 mcp->mb[1] = LSW(risc_addr);
303 mcp->mb[2] = MSW(req_dma);
304 mcp->mb[3] = LSW(req_dma);
305 mcp->mb[6] = MSW(MSD(req_dma));
306 mcp->mb[7] = LSW(MSD(req_dma));
307 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
308 if (IS_FWI2_CAPABLE(ha)) {
309 mcp->mb[4] = MSW(risc_code_size);
310 mcp->mb[5] = LSW(risc_code_size);
311 mcp->out_mb |= MBX_5|MBX_4;
313 mcp->mb[4] = LSW(risc_code_size);
314 mcp->out_mb |= MBX_4;
318 mcp->tov = MBX_TOV_SECONDS;
320 rval = qla2x00_mailbox_command(vha, mcp);
322 if (rval != QLA_SUCCESS) {
323 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
324 vha->host_no, rval, mcp->mb[0]));
326 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
334 * Start adapter firmware.
337 * ha = adapter block pointer.
338 * TARGET_QUEUE_LOCK must be released.
339 * ADAPTER_STATE_LOCK must be released.
342 * qla2x00 local function return status code.
348 qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
351 struct qla_hw_data *ha = vha->hw;
353 mbx_cmd_t *mcp = &mc;
355 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
357 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
360 if (IS_FWI2_CAPABLE(ha)) {
361 mcp->mb[1] = MSW(risc_addr);
362 mcp->mb[2] = LSW(risc_addr);
365 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
368 mcp->mb[1] = LSW(risc_addr);
369 mcp->out_mb |= MBX_1;
370 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
372 mcp->out_mb |= MBX_2;
376 mcp->tov = MBX_TOV_SECONDS;
378 rval = qla2x00_mailbox_command(vha, mcp);
380 if (rval != QLA_SUCCESS) {
381 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
382 vha->host_no, rval, mcp->mb[0]));
384 if (IS_FWI2_CAPABLE(ha)) {
385 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
386 __func__, vha->host_no, mcp->mb[1]));
388 DEBUG11(printk("%s(%ld): done.\n", __func__,
397 * qla2x00_get_fw_version
398 * Get firmware version.
401 * ha: adapter state pointer.
402 * major: pointer for major number.
403 * minor: pointer for minor number.
404 * subminor: pointer for subminor number.
407 * qla2x00 local function return status code.
413 qla2x00_get_fw_version(scsi_qla_host_t *vha, uint16_t *major, uint16_t *minor,
414 uint16_t *subminor, uint16_t *attributes, uint32_t *memory, uint8_t *mpi,
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;
426 if (IS_QLA81XX(vha->hw))
427 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
429 mcp->tov = MBX_TOV_SECONDS;
430 rval = qla2x00_mailbox_command(vha, mcp);
432 /* Return mailbox data. */
435 *subminor = mcp->mb[3];
436 *attributes = mcp->mb[6];
437 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
438 *memory = 0x1FFFF; /* Defaults to 128KB. */
440 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
441 if (IS_QLA81XX(vha->hw)) {
442 mpi[0] = mcp->mb[10] >> 8;
443 mpi[1] = mcp->mb[10] & 0xff;
444 mpi[2] = mcp->mb[11] >> 8;
445 mpi[3] = mcp->mb[11] & 0xff;
446 *mpi_caps = (mcp->mb[12] << 16) | mcp->mb[13];
449 if (rval != QLA_SUCCESS) {
451 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
452 vha->host_no, rval));
455 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
460 * qla2x00_get_fw_options
461 * Set firmware options.
464 * ha = adapter block pointer.
465 * fwopt = pointer for firmware options.
468 * qla2x00 local function return status code.
474 qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
478 mbx_cmd_t *mcp = &mc;
480 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
482 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
484 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
485 mcp->tov = MBX_TOV_SECONDS;
487 rval = qla2x00_mailbox_command(vha, mcp);
489 if (rval != QLA_SUCCESS) {
491 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
492 vha->host_no, rval));
494 fwopts[0] = mcp->mb[0];
495 fwopts[1] = mcp->mb[1];
496 fwopts[2] = mcp->mb[2];
497 fwopts[3] = mcp->mb[3];
499 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
507 * qla2x00_set_fw_options
508 * Set firmware options.
511 * ha = adapter block pointer.
512 * fwopt = pointer for firmware options.
515 * qla2x00 local function return status code.
521 qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
525 mbx_cmd_t *mcp = &mc;
527 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
529 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
530 mcp->mb[1] = fwopts[1];
531 mcp->mb[2] = fwopts[2];
532 mcp->mb[3] = fwopts[3];
533 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
535 if (IS_FWI2_CAPABLE(vha->hw)) {
538 mcp->mb[10] = fwopts[10];
539 mcp->mb[11] = fwopts[11];
540 mcp->mb[12] = 0; /* Undocumented, but used */
541 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
543 mcp->tov = MBX_TOV_SECONDS;
545 rval = qla2x00_mailbox_command(vha, mcp);
547 fwopts[0] = mcp->mb[0];
549 if (rval != QLA_SUCCESS) {
551 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
552 vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
555 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
562 * qla2x00_mbx_reg_test
563 * Mailbox register wrap test.
566 * ha = adapter block pointer.
567 * TARGET_QUEUE_LOCK must be released.
568 * ADAPTER_STATE_LOCK must be released.
571 * qla2x00 local function return status code.
577 qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
581 mbx_cmd_t *mcp = &mc;
583 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", vha->host_no));
585 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
593 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
594 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
595 mcp->tov = MBX_TOV_SECONDS;
597 rval = qla2x00_mailbox_command(vha, mcp);
599 if (rval == QLA_SUCCESS) {
600 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
601 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
602 rval = QLA_FUNCTION_FAILED;
603 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
604 mcp->mb[7] != 0x2525)
605 rval = QLA_FUNCTION_FAILED;
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_QLA81XX(vha->hw)) {
1367 /* Logout across all FCFs. */
1368 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1371 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1372 } else if (IS_FWI2_CAPABLE(vha->hw)) {
1373 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1376 mcp->mb[3] = vha->hw->loop_reset_delay;
1377 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1379 mcp->mb[0] = MBC_LIP_RESET;
1380 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1381 if (HAS_EXTENDED_IDS(vha->hw)) {
1382 mcp->mb[1] = 0x00ff;
1384 mcp->out_mb |= MBX_10;
1386 mcp->mb[1] = 0xff00;
1388 mcp->mb[2] = vha->hw->loop_reset_delay;
1392 mcp->tov = MBX_TOV_SECONDS;
1394 rval = qla2x00_mailbox_command(vha, mcp);
1396 if (rval != QLA_SUCCESS) {
1398 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1399 __func__, vha->host_no, rval));
1402 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1413 * ha = adapter block pointer.
1414 * sns = pointer for command.
1415 * cmd_size = command size.
1416 * buf_size = response/command size.
1417 * TARGET_QUEUE_LOCK must be released.
1418 * ADAPTER_STATE_LOCK must be released.
1421 * qla2x00 local function return status code.
1427 qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
1428 uint16_t cmd_size, size_t buf_size)
1432 mbx_cmd_t *mcp = &mc;
1434 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1437 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1438 "tov=%d.\n", vha->hw->retry_count, vha->hw->login_timeout,
1441 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1442 mcp->mb[1] = cmd_size;
1443 mcp->mb[2] = MSW(sns_phys_address);
1444 mcp->mb[3] = LSW(sns_phys_address);
1445 mcp->mb[6] = MSW(MSD(sns_phys_address));
1446 mcp->mb[7] = LSW(MSD(sns_phys_address));
1447 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1448 mcp->in_mb = MBX_0|MBX_1;
1449 mcp->buf_size = buf_size;
1450 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1451 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
1452 rval = qla2x00_mailbox_command(vha, mcp);
1454 if (rval != QLA_SUCCESS) {
1456 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1457 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1458 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1459 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1462 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", vha->host_no));
1469 qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1470 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1474 struct logio_entry_24xx *lg;
1477 struct qla_hw_data *ha = vha->hw;
1479 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1481 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1483 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1484 __func__, vha->host_no));
1485 return QLA_MEMORY_ALLOC_FAILED;
1487 memset(lg, 0, sizeof(struct logio_entry_24xx));
1489 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1490 lg->entry_count = 1;
1491 lg->nport_handle = cpu_to_le16(loop_id);
1492 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1494 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1496 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
1497 lg->port_id[0] = al_pa;
1498 lg->port_id[1] = area;
1499 lg->port_id[2] = domain;
1500 lg->vp_index = vha->vp_idx;
1501 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
1502 if (rval != QLA_SUCCESS) {
1503 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
1504 "(%x).\n", __func__, vha->host_no, rval));
1505 } else if (lg->entry_status != 0) {
1506 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1507 "-- error status (%x).\n", __func__, vha->host_no,
1509 rval = QLA_FUNCTION_FAILED;
1510 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1511 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1512 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1514 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1515 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1516 vha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1520 case LSC_SCODE_PORTID_USED:
1521 mb[0] = MBS_PORT_ID_USED;
1522 mb[1] = LSW(iop[1]);
1524 case LSC_SCODE_NPORT_USED:
1525 mb[0] = MBS_LOOP_ID_USED;
1527 case LSC_SCODE_NOLINK:
1528 case LSC_SCODE_NOIOCB:
1529 case LSC_SCODE_NOXCB:
1530 case LSC_SCODE_CMD_FAILED:
1531 case LSC_SCODE_NOFABRIC:
1532 case LSC_SCODE_FW_NOT_READY:
1533 case LSC_SCODE_NOT_LOGGED_IN:
1534 case LSC_SCODE_NOPCB:
1535 case LSC_SCODE_ELS_REJECT:
1536 case LSC_SCODE_CMD_PARAM_ERR:
1537 case LSC_SCODE_NONPORT:
1538 case LSC_SCODE_LOGGED_IN:
1539 case LSC_SCODE_NOFLOGI_ACC:
1541 mb[0] = MBS_COMMAND_ERROR;
1545 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1547 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1549 mb[0] = MBS_COMMAND_COMPLETE;
1551 if (iop[0] & BIT_4) {
1557 /* Passback COS information. */
1559 if (lg->io_parameter[7] || lg->io_parameter[8])
1560 mb[10] |= BIT_0; /* Class 2. */
1561 if (lg->io_parameter[9] || lg->io_parameter[10])
1562 mb[10] |= BIT_1; /* Class 3. */
1565 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1571 * qla2x00_login_fabric
1572 * Issue login fabric port mailbox command.
1575 * ha = adapter block pointer.
1576 * loop_id = device loop ID.
1577 * domain = device domain.
1578 * area = device area.
1579 * al_pa = device AL_PA.
1580 * status = pointer for return status.
1581 * opt = command options.
1582 * TARGET_QUEUE_LOCK must be released.
1583 * ADAPTER_STATE_LOCK must be released.
1586 * qla2x00 local function return status code.
1592 qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1593 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1597 mbx_cmd_t *mcp = &mc;
1598 struct qla_hw_data *ha = vha->hw;
1600 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", vha->host_no));
1602 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1603 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1604 if (HAS_EXTENDED_IDS(ha)) {
1605 mcp->mb[1] = loop_id;
1607 mcp->out_mb |= MBX_10;
1609 mcp->mb[1] = (loop_id << 8) | opt;
1611 mcp->mb[2] = domain;
1612 mcp->mb[3] = area << 8 | al_pa;
1614 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1615 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1617 rval = qla2x00_mailbox_command(vha, mcp);
1619 /* Return mailbox statuses. */
1626 /* COS retrieved from Get-Port-Database mailbox command. */
1630 if (rval != QLA_SUCCESS) {
1631 /* RLU tmp code: need to change main mailbox_command function to
1632 * return ok even when the mailbox completion value is not
1633 * SUCCESS. The caller needs to be responsible to interpret
1634 * the return values of this mailbox command if we're not
1635 * to change too much of the existing code.
1637 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1638 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1639 mcp->mb[0] == 0x4006)
1643 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1644 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", vha->host_no, rval,
1645 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
1648 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1656 * qla2x00_login_local_device
1657 * Issue login loop port mailbox command.
1660 * ha = adapter block pointer.
1661 * loop_id = device loop ID.
1662 * opt = command options.
1665 * Return status code.
1672 qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
1673 uint16_t *mb_ret, uint8_t opt)
1677 mbx_cmd_t *mcp = &mc;
1678 struct qla_hw_data *ha = vha->hw;
1680 if (IS_FWI2_CAPABLE(ha))
1681 return qla24xx_login_fabric(vha, fcport->loop_id,
1682 fcport->d_id.b.domain, fcport->d_id.b.area,
1683 fcport->d_id.b.al_pa, mb_ret, opt);
1685 DEBUG3(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1687 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1688 if (HAS_EXTENDED_IDS(ha))
1689 mcp->mb[1] = fcport->loop_id;
1691 mcp->mb[1] = fcport->loop_id << 8;
1693 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1694 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1695 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1697 rval = qla2x00_mailbox_command(vha, mcp);
1699 /* Return mailbox statuses. */
1700 if (mb_ret != NULL) {
1701 mb_ret[0] = mcp->mb[0];
1702 mb_ret[1] = mcp->mb[1];
1703 mb_ret[6] = mcp->mb[6];
1704 mb_ret[7] = mcp->mb[7];
1707 if (rval != QLA_SUCCESS) {
1708 /* AV tmp code: need to change main mailbox_command function to
1709 * return ok even when the mailbox completion value is not
1710 * SUCCESS. The caller needs to be responsible to interpret
1711 * the return values of this mailbox command if we're not
1712 * to change too much of the existing code.
1714 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1717 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1718 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
1719 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1720 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1721 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
1722 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1725 DEBUG3(printk("%s(%ld): done.\n", __func__, vha->host_no));
1732 qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1733 uint8_t area, uint8_t al_pa)
1736 struct logio_entry_24xx *lg;
1738 struct qla_hw_data *ha = vha->hw;
1740 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1742 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1744 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1745 __func__, vha->host_no));
1746 return QLA_MEMORY_ALLOC_FAILED;
1748 memset(lg, 0, sizeof(struct logio_entry_24xx));
1750 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1751 lg->entry_count = 1;
1752 lg->nport_handle = cpu_to_le16(loop_id);
1754 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
1755 lg->port_id[0] = al_pa;
1756 lg->port_id[1] = area;
1757 lg->port_id[2] = domain;
1758 lg->vp_index = vha->vp_idx;
1760 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
1761 if (rval != QLA_SUCCESS) {
1762 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1763 "(%x).\n", __func__, vha->host_no, rval));
1764 } else if (lg->entry_status != 0) {
1765 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1766 "-- error status (%x).\n", __func__, vha->host_no,
1768 rval = QLA_FUNCTION_FAILED;
1769 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1770 DEBUG2_3_11(printk("%s(%ld %d): failed to complete IOCB "
1771 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1772 vha->host_no, vha->vp_idx, le16_to_cpu(lg->comp_status),
1773 le32_to_cpu(lg->io_parameter[0]),
1774 le32_to_cpu(lg->io_parameter[1])));
1777 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
1780 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1786 * qla2x00_fabric_logout
1787 * Issue logout fabric port mailbox command.
1790 * ha = adapter block pointer.
1791 * loop_id = device loop ID.
1792 * TARGET_QUEUE_LOCK must be released.
1793 * ADAPTER_STATE_LOCK must be released.
1796 * qla2x00 local function return status code.
1802 qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
1803 uint8_t area, uint8_t al_pa)
1807 mbx_cmd_t *mcp = &mc;
1809 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1812 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1813 mcp->out_mb = MBX_1|MBX_0;
1814 if (HAS_EXTENDED_IDS(vha->hw)) {
1815 mcp->mb[1] = loop_id;
1817 mcp->out_mb |= MBX_10;
1819 mcp->mb[1] = loop_id << 8;
1822 mcp->in_mb = MBX_1|MBX_0;
1823 mcp->tov = MBX_TOV_SECONDS;
1825 rval = qla2x00_mailbox_command(vha, mcp);
1827 if (rval != QLA_SUCCESS) {
1829 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1830 "mbx1=%x.\n", vha->host_no, rval, mcp->mb[1]));
1833 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1841 * qla2x00_full_login_lip
1842 * Issue full login LIP mailbox command.
1845 * ha = adapter block pointer.
1846 * TARGET_QUEUE_LOCK must be released.
1847 * ADAPTER_STATE_LOCK must be released.
1850 * qla2x00 local function return status code.
1856 qla2x00_full_login_lip(scsi_qla_host_t *vha)
1860 mbx_cmd_t *mcp = &mc;
1862 if (IS_QLA81XX(vha->hw))
1865 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1868 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1869 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
1872 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1874 mcp->tov = MBX_TOV_SECONDS;
1876 rval = qla2x00_mailbox_command(vha, mcp);
1878 if (rval != QLA_SUCCESS) {
1880 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1881 vha->host_no, rval));
1884 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1892 * qla2x00_get_id_list
1895 * ha = adapter block pointer.
1898 * qla2x00 local function return status code.
1904 qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
1909 mbx_cmd_t *mcp = &mc;
1911 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1914 if (id_list == NULL)
1915 return QLA_FUNCTION_FAILED;
1917 mcp->mb[0] = MBC_GET_ID_LIST;
1918 mcp->out_mb = MBX_0;
1919 if (IS_FWI2_CAPABLE(vha->hw)) {
1920 mcp->mb[2] = MSW(id_list_dma);
1921 mcp->mb[3] = LSW(id_list_dma);
1922 mcp->mb[6] = MSW(MSD(id_list_dma));
1923 mcp->mb[7] = LSW(MSD(id_list_dma));
1925 mcp->mb[9] = vha->vp_idx;
1926 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
1928 mcp->mb[1] = MSW(id_list_dma);
1929 mcp->mb[2] = LSW(id_list_dma);
1930 mcp->mb[3] = MSW(MSD(id_list_dma));
1931 mcp->mb[6] = LSW(MSD(id_list_dma));
1932 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1934 mcp->in_mb = MBX_1|MBX_0;
1935 mcp->tov = MBX_TOV_SECONDS;
1937 rval = qla2x00_mailbox_command(vha, mcp);
1939 if (rval != QLA_SUCCESS) {
1941 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
1942 vha->host_no, rval));
1944 *entries = mcp->mb[1];
1945 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
1953 * qla2x00_get_resource_cnts
1954 * Get current firmware resource counts.
1957 * ha = adapter block pointer.
1960 * qla2x00 local function return status code.
1966 qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
1967 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
1968 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports)
1972 mbx_cmd_t *mcp = &mc;
1974 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
1976 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
1977 mcp->out_mb = MBX_0;
1978 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1979 mcp->tov = MBX_TOV_SECONDS;
1981 rval = qla2x00_mailbox_command(vha, mcp);
1983 if (rval != QLA_SUCCESS) {
1985 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
1986 vha->host_no, mcp->mb[0]));
1988 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
1989 "mb7=%x mb10=%x mb11=%x.\n", __func__, vha->host_no,
1990 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
1991 mcp->mb[10], mcp->mb[11]));
1994 *cur_xchg_cnt = mcp->mb[3];
1996 *orig_xchg_cnt = mcp->mb[6];
1998 *cur_iocb_cnt = mcp->mb[7];
2000 *orig_iocb_cnt = mcp->mb[10];
2001 if (vha->hw->flags.npiv_supported && max_npiv_vports)
2002 *max_npiv_vports = mcp->mb[11];
2008 #if defined(QL_DEBUG_LEVEL_3)
2010 * qla2x00_get_fcal_position_map
2011 * Get FCAL (LILP) position map using mailbox command
2014 * ha = adapter state pointer.
2015 * pos_map = buffer pointer (can be NULL).
2018 * qla2x00 local function return status code.
2024 qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
2028 mbx_cmd_t *mcp = &mc;
2030 dma_addr_t pmap_dma;
2031 struct qla_hw_data *ha = vha->hw;
2033 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
2035 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
2036 __func__, vha->host_no));
2037 return QLA_MEMORY_ALLOC_FAILED;
2039 memset(pmap, 0, FCAL_MAP_SIZE);
2041 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2042 mcp->mb[2] = MSW(pmap_dma);
2043 mcp->mb[3] = LSW(pmap_dma);
2044 mcp->mb[6] = MSW(MSD(pmap_dma));
2045 mcp->mb[7] = LSW(MSD(pmap_dma));
2046 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2047 mcp->in_mb = MBX_1|MBX_0;
2048 mcp->buf_size = FCAL_MAP_SIZE;
2049 mcp->flags = MBX_DMA_IN;
2050 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2051 rval = qla2x00_mailbox_command(vha, mcp);
2053 if (rval == QLA_SUCCESS) {
2054 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2055 "size (%x)\n", __func__, vha->host_no, mcp->mb[0],
2056 mcp->mb[1], (unsigned)pmap[0]));
2057 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2060 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2062 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2064 if (rval != QLA_SUCCESS) {
2065 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2066 vha->host_no, rval));
2068 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2076 * qla2x00_get_link_status
2079 * ha = adapter block pointer.
2080 * loop_id = device loop ID.
2081 * ret_buf = pointer to link status return buffer.
2085 * BIT_0 = mem alloc error.
2086 * BIT_1 = mailbox error.
2089 qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
2090 struct link_statistics *stats, dma_addr_t stats_dma)
2094 mbx_cmd_t *mcp = &mc;
2095 uint32_t *siter, *diter, dwords;
2096 struct qla_hw_data *ha = vha->hw;
2098 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2100 mcp->mb[0] = MBC_GET_LINK_STATUS;
2101 mcp->mb[2] = MSW(stats_dma);
2102 mcp->mb[3] = LSW(stats_dma);
2103 mcp->mb[6] = MSW(MSD(stats_dma));
2104 mcp->mb[7] = LSW(MSD(stats_dma));
2105 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2107 if (IS_FWI2_CAPABLE(ha)) {
2108 mcp->mb[1] = loop_id;
2111 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2112 mcp->in_mb |= MBX_1;
2113 } else if (HAS_EXTENDED_IDS(ha)) {
2114 mcp->mb[1] = loop_id;
2116 mcp->out_mb |= MBX_10|MBX_1;
2118 mcp->mb[1] = loop_id << 8;
2119 mcp->out_mb |= MBX_1;
2121 mcp->tov = MBX_TOV_SECONDS;
2122 mcp->flags = IOCTL_CMD;
2123 rval = qla2x00_mailbox_command(vha, mcp);
2125 if (rval == QLA_SUCCESS) {
2126 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2127 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2128 __func__, vha->host_no, mcp->mb[0]));
2129 rval = QLA_FUNCTION_FAILED;
2131 /* Copy over data -- firmware data is LE. */
2132 dwords = offsetof(struct link_statistics, unused1) / 4;
2133 siter = diter = &stats->link_fail_cnt;
2135 *diter++ = le32_to_cpu(*siter++);
2139 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2140 vha->host_no, rval));
2147 qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
2148 dma_addr_t stats_dma)
2152 mbx_cmd_t *mcp = &mc;
2153 uint32_t *siter, *diter, dwords;
2155 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2157 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2158 mcp->mb[2] = MSW(stats_dma);
2159 mcp->mb[3] = LSW(stats_dma);
2160 mcp->mb[6] = MSW(MSD(stats_dma));
2161 mcp->mb[7] = LSW(MSD(stats_dma));
2162 mcp->mb[8] = sizeof(struct link_statistics) / 4;
2163 mcp->mb[9] = vha->vp_idx;
2165 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2166 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2167 mcp->tov = MBX_TOV_SECONDS;
2168 mcp->flags = IOCTL_CMD;
2169 rval = qla2x00_mailbox_command(vha, mcp);
2171 if (rval == QLA_SUCCESS) {
2172 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2173 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2174 __func__, vha->host_no, mcp->mb[0]));
2175 rval = QLA_FUNCTION_FAILED;
2177 /* Copy over data -- firmware data is LE. */
2178 dwords = sizeof(struct link_statistics) / 4;
2179 siter = diter = &stats->link_fail_cnt;
2181 *diter++ = le32_to_cpu(*siter++);
2185 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2186 vha->host_no, rval));
2193 qla24xx_abort_command(scsi_qla_host_t *vha, srb_t *sp, struct req_que *req)
2197 unsigned long flags = 0;
2199 struct abort_entry_24xx *abt;
2202 struct qla_hw_data *ha = vha->hw;
2204 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2206 fcport = sp->fcport;
2208 spin_lock_irqsave(&ha->hardware_lock, flags);
2209 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2210 if (req->outstanding_cmds[handle] == sp)
2213 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2214 if (handle == MAX_OUTSTANDING_COMMANDS) {
2215 /* Command not found. */
2216 return QLA_FUNCTION_FAILED;
2219 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2221 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2222 __func__, vha->host_no));
2223 return QLA_MEMORY_ALLOC_FAILED;
2225 memset(abt, 0, sizeof(struct abort_entry_24xx));
2227 abt->entry_type = ABORT_IOCB_TYPE;
2228 abt->entry_count = 1;
2229 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2230 abt->handle_to_abort = handle;
2231 abt->port_id[0] = fcport->d_id.b.al_pa;
2232 abt->port_id[1] = fcport->d_id.b.area;
2233 abt->port_id[2] = fcport->d_id.b.domain;
2234 abt->vp_index = fcport->vp_idx;
2236 abt->req_que_no = cpu_to_le16(req->id);
2238 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
2239 if (rval != QLA_SUCCESS) {
2240 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2241 __func__, vha->host_no, rval));
2242 } else if (abt->entry_status != 0) {
2243 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2244 "-- error status (%x).\n", __func__, vha->host_no,
2245 abt->entry_status));
2246 rval = QLA_FUNCTION_FAILED;
2247 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2248 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2249 "-- completion status (%x).\n", __func__, vha->host_no,
2250 le16_to_cpu(abt->nport_handle)));
2251 rval = QLA_FUNCTION_FAILED;
2253 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2256 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2261 struct tsk_mgmt_cmd {
2263 struct tsk_mgmt_entry tsk;
2264 struct sts_entry_24xx sts;
2269 __qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
2273 struct tsk_mgmt_cmd *tsk;
2275 scsi_qla_host_t *vha;
2276 struct qla_hw_data *ha;
2277 struct req_que *req;
2278 struct rsp_que *rsp;
2280 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
2284 req = ha->req_q_map[0];
2285 rsp = ha->rsp_q_map[0];
2286 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
2288 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2289 "IOCB.\n", __func__, vha->host_no));
2290 return QLA_MEMORY_ALLOC_FAILED;
2292 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2294 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2295 tsk->p.tsk.entry_count = 1;
2296 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2297 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
2298 tsk->p.tsk.control_flags = cpu_to_le32(type);
2299 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2300 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2301 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2302 tsk->p.tsk.vp_index = fcport->vp_idx;
2303 if (type == TCF_LUN_RESET) {
2304 int_to_scsilun(l, &tsk->p.tsk.lun);
2305 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2306 sizeof(tsk->p.tsk.lun));
2309 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
2310 if (rval != QLA_SUCCESS) {
2311 DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
2312 "(%x).\n", __func__, vha->host_no, name, rval));
2313 } else if (tsk->p.sts.entry_status != 0) {
2314 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2315 "-- error status (%x).\n", __func__, vha->host_no,
2316 tsk->p.sts.entry_status));
2317 rval = QLA_FUNCTION_FAILED;
2318 } else if (tsk->p.sts.comp_status !=
2319 __constant_cpu_to_le16(CS_COMPLETE)) {
2320 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2321 "-- completion status (%x).\n", __func__,
2322 vha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
2323 rval = QLA_FUNCTION_FAILED;
2326 /* Issue marker IOCB. */
2327 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
2328 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2329 if (rval2 != QLA_SUCCESS) {
2330 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2331 "(%x).\n", __func__, vha->host_no, rval2));
2333 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2336 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
2342 qla24xx_abort_target(struct fc_port *fcport, unsigned int l)
2344 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l);
2348 qla24xx_lun_reset(struct fc_port *fcport, unsigned int l)
2350 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l);
2354 qla2x00_system_error(scsi_qla_host_t *vha)
2358 mbx_cmd_t *mcp = &mc;
2359 struct qla_hw_data *ha = vha->hw;
2361 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
2362 return QLA_FUNCTION_FAILED;
2364 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2366 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2367 mcp->out_mb = MBX_0;
2371 rval = qla2x00_mailbox_command(vha, mcp);
2373 if (rval != QLA_SUCCESS) {
2374 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2375 vha->host_no, rval));
2377 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2384 * qla2x00_set_serdes_params() -
2390 qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
2391 uint16_t sw_em_2g, uint16_t sw_em_4g)
2395 mbx_cmd_t *mcp = &mc;
2397 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2399 mcp->mb[0] = MBC_SERDES_PARAMS;
2401 mcp->mb[2] = sw_em_1g | BIT_15;
2402 mcp->mb[3] = sw_em_2g | BIT_15;
2403 mcp->mb[4] = sw_em_4g | BIT_15;
2404 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2406 mcp->tov = MBX_TOV_SECONDS;
2408 rval = qla2x00_mailbox_command(vha, mcp);
2410 if (rval != QLA_SUCCESS) {
2412 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2413 vha->host_no, rval, mcp->mb[0]));
2416 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2423 qla2x00_stop_firmware(scsi_qla_host_t *vha)
2427 mbx_cmd_t *mcp = &mc;
2429 if (!IS_FWI2_CAPABLE(vha->hw))
2430 return QLA_FUNCTION_FAILED;
2432 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2434 mcp->mb[0] = MBC_STOP_FIRMWARE;
2435 mcp->out_mb = MBX_0;
2439 rval = qla2x00_mailbox_command(vha, mcp);
2441 if (rval != QLA_SUCCESS) {
2442 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2443 vha->host_no, rval));
2445 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2452 qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
2457 mbx_cmd_t *mcp = &mc;
2459 if (!IS_FWI2_CAPABLE(vha->hw))
2460 return QLA_FUNCTION_FAILED;
2462 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2464 mcp->mb[0] = MBC_TRACE_CONTROL;
2465 mcp->mb[1] = TC_EFT_ENABLE;
2466 mcp->mb[2] = LSW(eft_dma);
2467 mcp->mb[3] = MSW(eft_dma);
2468 mcp->mb[4] = LSW(MSD(eft_dma));
2469 mcp->mb[5] = MSW(MSD(eft_dma));
2470 mcp->mb[6] = buffers;
2471 mcp->mb[7] = TC_AEN_DISABLE;
2472 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2473 mcp->in_mb = MBX_1|MBX_0;
2474 mcp->tov = MBX_TOV_SECONDS;
2476 rval = qla2x00_mailbox_command(vha, mcp);
2477 if (rval != QLA_SUCCESS) {
2478 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2479 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2481 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2488 qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
2492 mbx_cmd_t *mcp = &mc;
2494 if (!IS_FWI2_CAPABLE(vha->hw))
2495 return QLA_FUNCTION_FAILED;
2497 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2499 mcp->mb[0] = MBC_TRACE_CONTROL;
2500 mcp->mb[1] = TC_EFT_DISABLE;
2501 mcp->out_mb = MBX_1|MBX_0;
2502 mcp->in_mb = MBX_1|MBX_0;
2503 mcp->tov = MBX_TOV_SECONDS;
2505 rval = qla2x00_mailbox_command(vha, mcp);
2506 if (rval != QLA_SUCCESS) {
2507 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2508 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2510 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2517 qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
2518 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2522 mbx_cmd_t *mcp = &mc;
2524 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw))
2525 return QLA_FUNCTION_FAILED;
2527 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2529 mcp->mb[0] = MBC_TRACE_CONTROL;
2530 mcp->mb[1] = TC_FCE_ENABLE;
2531 mcp->mb[2] = LSW(fce_dma);
2532 mcp->mb[3] = MSW(fce_dma);
2533 mcp->mb[4] = LSW(MSD(fce_dma));
2534 mcp->mb[5] = MSW(MSD(fce_dma));
2535 mcp->mb[6] = buffers;
2536 mcp->mb[7] = TC_AEN_DISABLE;
2538 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2539 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2540 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2542 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2543 mcp->tov = MBX_TOV_SECONDS;
2545 rval = qla2x00_mailbox_command(vha, mcp);
2546 if (rval != QLA_SUCCESS) {
2547 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2548 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2550 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2553 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2562 qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
2566 mbx_cmd_t *mcp = &mc;
2568 if (!IS_FWI2_CAPABLE(vha->hw))
2569 return QLA_FUNCTION_FAILED;
2571 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2573 mcp->mb[0] = MBC_TRACE_CONTROL;
2574 mcp->mb[1] = TC_FCE_DISABLE;
2575 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
2576 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2577 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2579 mcp->tov = MBX_TOV_SECONDS;
2581 rval = qla2x00_mailbox_command(vha, mcp);
2582 if (rval != QLA_SUCCESS) {
2583 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2584 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2586 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2589 *wr = (uint64_t) mcp->mb[5] << 48 |
2590 (uint64_t) mcp->mb[4] << 32 |
2591 (uint64_t) mcp->mb[3] << 16 |
2592 (uint64_t) mcp->mb[2];
2594 *rd = (uint64_t) mcp->mb[9] << 48 |
2595 (uint64_t) mcp->mb[8] << 32 |
2596 (uint64_t) mcp->mb[7] << 16 |
2597 (uint64_t) mcp->mb[6];
2604 qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint16_t addr,
2605 uint16_t off, uint16_t count)
2609 mbx_cmd_t *mcp = &mc;
2611 if (!IS_FWI2_CAPABLE(vha->hw))
2612 return QLA_FUNCTION_FAILED;
2614 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2616 mcp->mb[0] = MBC_READ_SFP;
2618 mcp->mb[2] = MSW(sfp_dma);
2619 mcp->mb[3] = LSW(sfp_dma);
2620 mcp->mb[6] = MSW(MSD(sfp_dma));
2621 mcp->mb[7] = LSW(MSD(sfp_dma));
2625 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2627 mcp->tov = MBX_TOV_SECONDS;
2629 rval = qla2x00_mailbox_command(vha, mcp);
2631 if (rval != QLA_SUCCESS) {
2632 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2633 vha->host_no, rval, mcp->mb[0]));
2635 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2642 qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
2643 uint16_t port_speed, uint16_t *mb)
2647 mbx_cmd_t *mcp = &mc;
2649 if (!IS_IIDMA_CAPABLE(vha->hw))
2650 return QLA_FUNCTION_FAILED;
2652 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2654 mcp->mb[0] = MBC_PORT_PARAMS;
2655 mcp->mb[1] = loop_id;
2657 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2658 mcp->mb[4] = mcp->mb[5] = 0;
2659 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2660 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2661 mcp->tov = MBX_TOV_SECONDS;
2663 rval = qla2x00_mailbox_command(vha, mcp);
2665 /* Return mailbox statuses. */
2674 if (rval != QLA_SUCCESS) {
2675 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2676 vha->host_no, rval));
2678 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2685 qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
2686 struct vp_rpt_id_entry_24xx *rptid_entry)
2689 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
2690 struct qla_hw_data *ha = vha->hw;
2691 scsi_qla_host_t *vp;
2693 if (rptid_entry->entry_status != 0)
2696 if (rptid_entry->format == 0) {
2697 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
2698 " number of VPs acquired %d\n", __func__, vha->host_no,
2699 MSB(rptid_entry->vp_count), LSB(rptid_entry->vp_count)));
2700 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2701 rptid_entry->port_id[2], rptid_entry->port_id[1],
2702 rptid_entry->port_id[0]));
2703 } else if (rptid_entry->format == 1) {
2705 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2707 "with port id %02x%02x%02x\n", __func__, vha->host_no,
2709 rptid_entry->port_id[2], rptid_entry->port_id[1],
2710 rptid_entry->port_id[0]));
2717 list_for_each_entry(vp, &ha->vp_list, list)
2718 if (vp_idx == vp->vp_idx)
2723 vp->d_id.b.domain = rptid_entry->port_id[2];
2724 vp->d_id.b.area = rptid_entry->port_id[1];
2725 vp->d_id.b.al_pa = rptid_entry->port_id[0];
2728 * Cannot configure here as we are still sitting on the
2729 * response queue. Handle it in dpc context.
2731 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
2732 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
2734 qla2xxx_wake_dpc(vha);
2739 * qla24xx_modify_vp_config
2740 * Change VP configuration for vha
2743 * vha = adapter block pointer.
2746 * qla2xxx local function return status code.
2752 qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2755 struct vp_config_entry_24xx *vpmod;
2756 dma_addr_t vpmod_dma;
2757 struct qla_hw_data *ha = vha->hw;
2758 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2760 /* This can be called by the parent */
2762 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
2764 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
2765 "IOCB.\n", __func__, vha->host_no));
2766 return QLA_MEMORY_ALLOC_FAILED;
2769 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2770 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2771 vpmod->entry_count = 1;
2772 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2773 vpmod->vp_count = 1;
2774 vpmod->vp_index1 = vha->vp_idx;
2775 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2776 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2777 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2778 vpmod->entry_count = 1;
2780 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
2781 if (rval != QLA_SUCCESS) {
2782 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
2783 "(%x).\n", __func__, base_vha->host_no, rval));
2784 } else if (vpmod->comp_status != 0) {
2785 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2786 "-- error status (%x).\n", __func__, base_vha->host_no,
2787 vpmod->comp_status));
2788 rval = QLA_FUNCTION_FAILED;
2789 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2790 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2791 "-- completion status (%x).\n", __func__, base_vha->host_no,
2792 le16_to_cpu(vpmod->comp_status)));
2793 rval = QLA_FUNCTION_FAILED;
2796 DEBUG11(printk("%s(%ld): done.\n", __func__,
2797 base_vha->host_no));
2798 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2800 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
2806 * qla24xx_control_vp
2807 * Enable a virtual port for given host
2810 * ha = adapter block pointer.
2811 * vhba = virtual adapter (unused)
2812 * index = index number for enabled VP
2815 * qla2xxx local function return status code.
2821 qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2825 struct vp_ctrl_entry_24xx *vce;
2827 struct qla_hw_data *ha = vha->hw;
2828 int vp_index = vha->vp_idx;
2829 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2831 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
2832 vha->host_no, vp_index));
2834 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
2835 return QLA_PARAMETER_ERROR;
2837 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2839 DEBUG2_3(printk("%s(%ld): "
2840 "failed to allocate VP Control IOCB.\n", __func__,
2841 base_vha->host_no));
2842 return QLA_MEMORY_ALLOC_FAILED;
2844 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2846 vce->entry_type = VP_CTRL_IOCB_TYPE;
2847 vce->entry_count = 1;
2848 vce->command = cpu_to_le16(cmd);
2849 vce->vp_count = __constant_cpu_to_le16(1);
2851 /* index map in firmware starts with 1; decrement index
2852 * this is ok as we never use index 0
2854 map = (vp_index - 1) / 8;
2855 pos = (vp_index - 1) & 7;
2856 mutex_lock(&ha->vport_lock);
2857 vce->vp_idx_map[map] |= 1 << pos;
2858 mutex_unlock(&ha->vport_lock);
2860 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
2861 if (rval != QLA_SUCCESS) {
2862 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
2863 "(%x).\n", __func__, base_vha->host_no, rval));
2864 printk("%s(%ld): failed to issue VP control IOCB"
2865 "(%x).\n", __func__, base_vha->host_no, rval);
2866 } else if (vce->entry_status != 0) {
2867 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2868 "-- error status (%x).\n", __func__, base_vha->host_no,
2869 vce->entry_status));
2870 printk("%s(%ld): failed to complete IOCB "
2871 "-- error status (%x).\n", __func__, base_vha->host_no,
2873 rval = QLA_FUNCTION_FAILED;
2874 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2875 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2876 "-- completion status (%x).\n", __func__, base_vha->host_no,
2877 le16_to_cpu(vce->comp_status)));
2878 printk("%s(%ld): failed to complete IOCB "
2879 "-- completion status (%x).\n", __func__, base_vha->host_no,
2880 le16_to_cpu(vce->comp_status));
2881 rval = QLA_FUNCTION_FAILED;
2883 DEBUG2(printk("%s(%ld): done.\n", __func__, base_vha->host_no));
2886 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
2892 * qla2x00_send_change_request
2893 * Receive or disable RSCN request from fabric controller
2896 * ha = adapter block pointer
2897 * format = registration format:
2899 * 1 - Fabric detected registration
2900 * 2 - N_port detected registration
2901 * 3 - Full registration
2902 * FF - clear registration
2903 * vp_idx = Virtual port index
2906 * qla2x00 local function return status code.
2913 qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
2918 mbx_cmd_t *mcp = &mc;
2921 * This command is implicitly executed by firmware during login for the
2925 return QLA_FUNCTION_FAILED;
2927 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
2928 mcp->mb[1] = format;
2929 mcp->mb[9] = vp_idx;
2930 mcp->out_mb = MBX_9|MBX_1|MBX_0;
2931 mcp->in_mb = MBX_0|MBX_1;
2932 mcp->tov = MBX_TOV_SECONDS;
2934 rval = qla2x00_mailbox_command(vha, mcp);
2936 if (rval == QLA_SUCCESS) {
2937 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2947 qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
2952 mbx_cmd_t *mcp = &mc;
2954 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2956 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
2957 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
2958 mcp->mb[8] = MSW(addr);
2959 mcp->out_mb = MBX_8|MBX_0;
2961 mcp->mb[0] = MBC_DUMP_RISC_RAM;
2962 mcp->out_mb = MBX_0;
2964 mcp->mb[1] = LSW(addr);
2965 mcp->mb[2] = MSW(req_dma);
2966 mcp->mb[3] = LSW(req_dma);
2967 mcp->mb[6] = MSW(MSD(req_dma));
2968 mcp->mb[7] = LSW(MSD(req_dma));
2969 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
2970 if (IS_FWI2_CAPABLE(vha->hw)) {
2971 mcp->mb[4] = MSW(size);
2972 mcp->mb[5] = LSW(size);
2973 mcp->out_mb |= MBX_5|MBX_4;
2975 mcp->mb[4] = LSW(size);
2976 mcp->out_mb |= MBX_4;
2980 mcp->tov = MBX_TOV_SECONDS;
2982 rval = qla2x00_mailbox_command(vha, mcp);
2984 if (rval != QLA_SUCCESS) {
2985 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
2986 vha->host_no, rval, mcp->mb[0]));
2988 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2994 /* 84XX Support **************************************************************/
2996 struct cs84xx_mgmt_cmd {
2998 struct verify_chip_entry_84xx req;
2999 struct verify_chip_rsp_84xx rsp;
3004 qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
3007 struct cs84xx_mgmt_cmd *mn;
3010 unsigned long flags;
3011 struct qla_hw_data *ha = vha->hw;
3013 DEBUG16(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3015 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
3017 DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX "
3018 "IOCB.\n", __func__, vha->host_no));
3019 return QLA_MEMORY_ALLOC_FAILED;
3023 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
3024 /* Diagnostic firmware? */
3025 /* options |= MENLO_DIAG_FW; */
3026 /* We update the firmware with only one data sequence. */
3027 options |= VCO_END_OF_DATA;
3031 memset(mn, 0, sizeof(*mn));
3032 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
3033 mn->p.req.entry_count = 1;
3034 mn->p.req.options = cpu_to_le16(options);
3036 DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__,
3038 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3041 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
3042 if (rval != QLA_SUCCESS) {
3043 DEBUG2_16(printk("%s(%ld): failed to issue Verify "
3044 "IOCB (%x).\n", __func__, vha->host_no, rval));
3048 DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__,
3050 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3053 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3054 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3055 le16_to_cpu(mn->p.rsp.failure_code) : 0;
3056 DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__,
3057 vha->host_no, status[0], status[1]));
3059 if (status[0] != CS_COMPLETE) {
3060 rval = QLA_FUNCTION_FAILED;
3061 if (!(options & VCO_DONT_UPDATE_FW)) {
3062 DEBUG2_16(printk("%s(%ld): Firmware update "
3063 "failed. Retrying without update "
3064 "firmware.\n", __func__, vha->host_no));
3065 options |= VCO_DONT_UPDATE_FW;
3066 options &= ~VCO_FORCE_UPDATE;
3070 DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n",
3071 __func__, vha->host_no,
3072 le32_to_cpu(mn->p.rsp.fw_ver)));
3074 /* NOTE: we only update OP firmware. */
3075 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3076 ha->cs84xx->op_fw_version =
3077 le32_to_cpu(mn->p.rsp.fw_ver);
3078 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3084 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3086 if (rval != QLA_SUCCESS) {
3087 DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__,
3088 vha->host_no, rval));
3090 DEBUG16(printk("%s(%ld): done.\n", __func__, vha->host_no));
3097 qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req,
3101 unsigned long flags;
3103 mbx_cmd_t *mcp = &mc;
3104 struct device_reg_25xxmq __iomem *reg;
3105 struct qla_hw_data *ha = vha->hw;
3107 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
3108 mcp->mb[1] = options;
3109 mcp->mb[2] = MSW(LSD(req->dma));
3110 mcp->mb[3] = LSW(LSD(req->dma));
3111 mcp->mb[6] = MSW(MSD(req->dma));
3112 mcp->mb[7] = LSW(MSD(req->dma));
3113 mcp->mb[5] = req->length;
3115 mcp->mb[10] = req->rsp->id;
3116 mcp->mb[12] = req->qos;
3117 mcp->mb[11] = req->vp_idx;
3118 mcp->mb[13] = req->rid;
3120 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3121 QLA_QUE_PAGE * req->id);
3123 mcp->mb[4] = req->id;
3124 /* que in ptr index */
3126 /* que out ptr index */
3128 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
3129 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3131 mcp->flags = MBX_DMA_OUT;
3134 spin_lock_irqsave(&ha->hardware_lock, flags);
3135 if (!(options & BIT_0)) {
3136 WRT_REG_DWORD(®->req_q_in, 0);
3137 WRT_REG_DWORD(®->req_q_out, 0);
3139 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3141 rval = qla2x00_mailbox_command(vha, mcp);
3142 if (rval != QLA_SUCCESS)
3143 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x mb0=%x.\n",
3144 __func__, vha->host_no, rval, mcp->mb[0]));
3149 qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp,
3153 unsigned long flags;
3155 mbx_cmd_t *mcp = &mc;
3156 struct device_reg_25xxmq __iomem *reg;
3157 struct qla_hw_data *ha = vha->hw;
3159 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
3160 mcp->mb[1] = options;
3161 mcp->mb[2] = MSW(LSD(rsp->dma));
3162 mcp->mb[3] = LSW(LSD(rsp->dma));
3163 mcp->mb[6] = MSW(MSD(rsp->dma));
3164 mcp->mb[7] = LSW(MSD(rsp->dma));
3165 mcp->mb[5] = rsp->length;
3166 mcp->mb[11] = rsp->vp_idx;
3167 mcp->mb[14] = rsp->msix->entry;
3168 mcp->mb[13] = rsp->rid;
3170 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3171 QLA_QUE_PAGE * rsp->id);
3173 mcp->mb[4] = rsp->id;
3174 /* que in ptr index */
3176 /* que out ptr index */
3178 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7
3179 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3181 mcp->flags = MBX_DMA_OUT;
3184 spin_lock_irqsave(&ha->hardware_lock, flags);
3185 if (!(options & BIT_0)) {
3186 WRT_REG_DWORD(®->rsp_q_out, 0);
3187 WRT_REG_DWORD(®->rsp_q_in, 0);
3190 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3192 rval = qla2x00_mailbox_command(vha, mcp);
3193 if (rval != QLA_SUCCESS)
3194 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x "
3195 "mb0=%x.\n", __func__,
3196 vha->host_no, rval, mcp->mb[0]));