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 *pvha, 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 scsi_qla_host_t *ha = to_qla_parent(pvha);
48 io_lock_on = ha->flags.init_done;
51 abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
53 DEBUG11(printk("%s(%ld): entered.\n", __func__, pvha->host_no));
56 * Wait for active mailbox commands to finish by waiting at most tov
57 * seconds. This is to serialize actual issuing of mailbox cmds during
61 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp,
63 /* Timeout occurred. Return error. */
64 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
65 "Exiting.\n", __func__, ha->host_no));
66 return QLA_FUNCTION_TIMEOUT;
70 ha->flags.mbox_busy = 1;
71 /* Save mailbox command for debug */
74 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
75 ha->host_no, mcp->mb[0]));
77 spin_lock_irqsave(&ha->hardware_lock, flags);
79 /* Load mailbox registers. */
80 if (IS_FWI2_CAPABLE(ha))
81 optr = (uint16_t __iomem *)®->isp24.mailbox0;
83 optr = (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 0);
89 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
90 if (IS_QLA2200(ha) && cnt == 8)
92 (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 8);
94 WRT_REG_WORD(optr, *iptr);
101 #if defined(QL_DEBUG_LEVEL_1)
102 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
103 __func__, ha->host_no);
104 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
106 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
108 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
110 printk("%s(%ld): I/O address = %p.\n", __func__, ha->host_no, optr);
111 qla2x00_dump_regs(ha);
114 /* Issue set host interrupt command to send cmd out. */
115 ha->flags.mbox_int = 0;
116 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
118 /* Unlock mbx registers and wait for interrupt */
119 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
120 "jiffies=%lx.\n", __func__, ha->host_no, jiffies));
122 /* Wait for mbx cmd completion until timeout */
124 if (!abort_active && io_lock_on) {
126 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
128 if (IS_FWI2_CAPABLE(ha))
129 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
131 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
132 spin_unlock_irqrestore(&ha->hardware_lock, flags);
134 wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ);
136 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
139 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
140 ha->host_no, command));
142 if (IS_FWI2_CAPABLE(ha))
143 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
145 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
146 spin_unlock_irqrestore(&ha->hardware_lock, flags);
148 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
149 while (!ha->flags.mbox_int) {
150 if (time_after(jiffies, wait_time))
153 /* Check for pending interrupts. */
156 if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
162 /* Check whether we timed out */
163 if (ha->flags.mbox_int) {
166 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
167 ha->host_no, command));
169 /* Got interrupt. Clear the flag. */
170 ha->flags.mbox_int = 0;
171 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
173 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
174 rval = QLA_FUNCTION_FAILED;
176 /* Load return mailbox registers. */
178 iptr = (uint16_t *)&ha->mailbox_out[0];
180 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
190 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
191 defined(QL_DEBUG_LEVEL_11)
195 if (IS_FWI2_CAPABLE(ha)) {
196 mb0 = RD_REG_WORD(®->isp24.mailbox0);
197 ictrl = RD_REG_DWORD(®->isp24.ictrl);
199 mb0 = RD_MAILBOX_REG(ha, ®->isp, 0);
200 ictrl = RD_REG_WORD(®->isp.ictrl);
202 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
203 __func__, ha->host_no, command);
204 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
205 ha->host_no, ictrl, jiffies);
206 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
208 qla2x00_dump_regs(ha);
211 rval = QLA_FUNCTION_TIMEOUT;
214 ha->flags.mbox_busy = 0;
219 if (abort_active || !io_lock_on) {
220 DEBUG11(printk("%s(%ld): checking for additional resp "
221 "interrupt.\n", __func__, ha->host_no));
223 /* polling mode for non isp_abort commands. */
227 if (rval == QLA_FUNCTION_TIMEOUT &&
228 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
229 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
230 /* not in dpc. schedule it for dpc to take over. */
231 DEBUG(printk("%s(%ld): timeout schedule "
232 "isp_abort_needed.\n", __func__, ha->host_no));
233 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
234 "isp_abort_needed.\n", __func__, ha->host_no));
235 qla_printk(KERN_WARNING, ha,
236 "Mailbox command timeout occured. Scheduling ISP "
238 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
239 qla2xxx_wake_dpc(ha);
240 } else if (!abort_active) {
241 /* call abort directly since we are in the DPC thread */
242 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
243 __func__, ha->host_no));
244 DEBUG2_3_11(printk("%s(%ld): timeout calling "
245 "abort_isp\n", __func__, ha->host_no));
246 qla_printk(KERN_WARNING, ha,
247 "Mailbox command timeout occured. Issuing ISP "
250 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
251 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
252 if (qla2x00_abort_isp(ha)) {
253 /* Failed. retry later. */
254 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
256 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
257 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
259 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
260 __func__, ha->host_no));
264 /* Allow next mbx cmd to come in. */
266 complete(&ha->mbx_cmd_comp);
268 if (rval != QLA_SUCCESS) {
269 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
270 "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no,
271 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
273 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
280 qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t risc_addr,
281 uint32_t risc_code_size)
285 mbx_cmd_t *mcp = &mc;
287 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
289 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
290 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
291 mcp->mb[8] = MSW(risc_addr);
292 mcp->out_mb = MBX_8|MBX_0;
294 mcp->mb[0] = MBC_LOAD_RISC_RAM;
297 mcp->mb[1] = LSW(risc_addr);
298 mcp->mb[2] = MSW(req_dma);
299 mcp->mb[3] = LSW(req_dma);
300 mcp->mb[6] = MSW(MSD(req_dma));
301 mcp->mb[7] = LSW(MSD(req_dma));
302 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
303 if (IS_FWI2_CAPABLE(ha)) {
304 mcp->mb[4] = MSW(risc_code_size);
305 mcp->mb[5] = LSW(risc_code_size);
306 mcp->out_mb |= MBX_5|MBX_4;
308 mcp->mb[4] = LSW(risc_code_size);
309 mcp->out_mb |= MBX_4;
313 mcp->tov = MBX_TOV_SECONDS;
315 rval = qla2x00_mailbox_command(ha, mcp);
317 if (rval != QLA_SUCCESS) {
318 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
319 ha->host_no, rval, mcp->mb[0]));
321 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
329 * Start adapter firmware.
332 * ha = adapter block pointer.
333 * TARGET_QUEUE_LOCK must be released.
334 * ADAPTER_STATE_LOCK must be released.
337 * qla2x00 local function return status code.
343 qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
347 mbx_cmd_t *mcp = &mc;
349 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
351 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
354 if (IS_FWI2_CAPABLE(ha)) {
355 mcp->mb[1] = MSW(risc_addr);
356 mcp->mb[2] = LSW(risc_addr);
359 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
362 mcp->mb[1] = LSW(risc_addr);
363 mcp->out_mb |= MBX_1;
364 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
366 mcp->out_mb |= MBX_2;
370 mcp->tov = MBX_TOV_SECONDS;
372 rval = qla2x00_mailbox_command(ha, mcp);
374 if (rval != QLA_SUCCESS) {
375 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
376 ha->host_no, rval, mcp->mb[0]));
378 if (IS_FWI2_CAPABLE(ha)) {
379 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
380 __func__, ha->host_no, mcp->mb[1]));
382 DEBUG11(printk("%s(%ld): done.\n", __func__,
391 * qla2x00_get_fw_version
392 * Get firmware version.
395 * ha: adapter state pointer.
396 * major: pointer for major number.
397 * minor: pointer for minor number.
398 * subminor: pointer for subminor number.
401 * qla2x00 local function return status code.
407 qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,
408 uint16_t *subminor, uint16_t *attributes, uint32_t *memory)
412 mbx_cmd_t *mcp = &mc;
414 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
416 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
418 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
420 mcp->tov = MBX_TOV_SECONDS;
421 rval = qla2x00_mailbox_command(ha, mcp);
423 /* Return mailbox data. */
426 *subminor = mcp->mb[3];
427 *attributes = mcp->mb[6];
428 if (IS_QLA2100(ha) || IS_QLA2200(ha))
429 *memory = 0x1FFFF; /* Defaults to 128KB. */
431 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
433 if (rval != QLA_SUCCESS) {
435 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
439 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
444 * qla2x00_get_fw_options
445 * Set firmware options.
448 * ha = adapter block pointer.
449 * fwopt = pointer for firmware options.
452 * qla2x00 local function return status code.
458 qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
462 mbx_cmd_t *mcp = &mc;
464 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
466 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
468 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
469 mcp->tov = MBX_TOV_SECONDS;
471 rval = qla2x00_mailbox_command(ha, mcp);
473 if (rval != QLA_SUCCESS) {
475 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
478 fwopts[0] = mcp->mb[0];
479 fwopts[1] = mcp->mb[1];
480 fwopts[2] = mcp->mb[2];
481 fwopts[3] = mcp->mb[3];
483 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
491 * qla2x00_set_fw_options
492 * Set firmware options.
495 * ha = adapter block pointer.
496 * fwopt = pointer for firmware options.
499 * qla2x00 local function return status code.
505 qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
509 mbx_cmd_t *mcp = &mc;
511 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
513 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
514 mcp->mb[1] = fwopts[1];
515 mcp->mb[2] = fwopts[2];
516 mcp->mb[3] = fwopts[3];
517 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
519 if (IS_FWI2_CAPABLE(ha)) {
522 mcp->mb[10] = fwopts[10];
523 mcp->mb[11] = fwopts[11];
524 mcp->mb[12] = 0; /* Undocumented, but used */
525 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
527 mcp->tov = MBX_TOV_SECONDS;
529 rval = qla2x00_mailbox_command(ha, mcp);
531 fwopts[0] = mcp->mb[0];
533 if (rval != QLA_SUCCESS) {
535 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
536 ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
539 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
546 * qla2x00_mbx_reg_test
547 * Mailbox register wrap test.
550 * ha = adapter block pointer.
551 * TARGET_QUEUE_LOCK must be released.
552 * ADAPTER_STATE_LOCK must be released.
555 * qla2x00 local function return status code.
561 qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
565 mbx_cmd_t *mcp = &mc;
567 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no));
569 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
577 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
578 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
579 mcp->tov = MBX_TOV_SECONDS;
581 rval = qla2x00_mailbox_command(ha, mcp);
583 if (rval == QLA_SUCCESS) {
584 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
585 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
586 rval = QLA_FUNCTION_FAILED;
587 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
588 mcp->mb[7] != 0x2525)
589 rval = QLA_FUNCTION_FAILED;
590 if (rval == QLA_FUNCTION_FAILED) {
591 struct device_reg_24xx __iomem *reg =
594 qla2xxx_hw_event_log(ha, HW_EVENT_ISP_ERR, 0,
595 LSW(RD_REG_DWORD(®->hccr)),
596 LSW(RD_REG_DWORD(®->istatus)));
600 if (rval != QLA_SUCCESS) {
602 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
606 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
614 * qla2x00_verify_checksum
615 * Verify firmware checksum.
618 * ha = adapter block pointer.
619 * TARGET_QUEUE_LOCK must be released.
620 * ADAPTER_STATE_LOCK must be released.
623 * qla2x00 local function return status code.
629 qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
633 mbx_cmd_t *mcp = &mc;
635 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
637 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
640 if (IS_FWI2_CAPABLE(ha)) {
641 mcp->mb[1] = MSW(risc_addr);
642 mcp->mb[2] = LSW(risc_addr);
643 mcp->out_mb |= MBX_2|MBX_1;
644 mcp->in_mb |= MBX_2|MBX_1;
646 mcp->mb[1] = LSW(risc_addr);
647 mcp->out_mb |= MBX_1;
651 mcp->tov = MBX_TOV_SECONDS;
653 rval = qla2x00_mailbox_command(ha, mcp);
655 if (rval != QLA_SUCCESS) {
656 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
657 ha->host_no, rval, IS_FWI2_CAPABLE(ha) ?
658 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
660 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
668 * Issue IOCB using mailbox command
671 * ha = adapter state pointer.
672 * buffer = buffer pointer.
673 * phys_addr = physical address of buffer.
674 * size = size of buffer.
675 * TARGET_QUEUE_LOCK must be released.
676 * ADAPTER_STATE_LOCK must be released.
679 * qla2x00 local function return status code.
685 qla2x00_issue_iocb_timeout(scsi_qla_host_t *ha, void *buffer,
686 dma_addr_t phys_addr, size_t size, uint32_t tov)
690 mbx_cmd_t *mcp = &mc;
692 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
694 mcp->mb[2] = MSW(phys_addr);
695 mcp->mb[3] = LSW(phys_addr);
696 mcp->mb[6] = MSW(MSD(phys_addr));
697 mcp->mb[7] = LSW(MSD(phys_addr));
698 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
699 mcp->in_mb = MBX_2|MBX_0;
702 rval = qla2x00_mailbox_command(ha, mcp);
704 if (rval != QLA_SUCCESS) {
706 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
708 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
711 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
713 /* Mask reserved bits. */
714 sts_entry->entry_status &=
715 IS_FWI2_CAPABLE(ha) ? RF_MASK_24XX :RF_MASK;
722 qla2x00_issue_iocb(scsi_qla_host_t *ha, void *buffer, dma_addr_t phys_addr,
725 return qla2x00_issue_iocb_timeout(ha, buffer, phys_addr, size,
730 * qla2x00_abort_command
731 * Abort command aborts a specified IOCB.
734 * ha = adapter block pointer.
735 * sp = SB structure pointer.
738 * qla2x00 local function return status code.
744 qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
746 unsigned long flags = 0;
751 mbx_cmd_t *mcp = &mc;
753 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no));
757 spin_lock_irqsave(&ha->hardware_lock, flags);
758 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
759 if (ha->outstanding_cmds[handle] == sp)
762 spin_unlock_irqrestore(&ha->hardware_lock, flags);
764 if (handle == MAX_OUTSTANDING_COMMANDS) {
765 /* command not found */
766 return QLA_FUNCTION_FAILED;
769 mcp->mb[0] = MBC_ABORT_COMMAND;
770 if (HAS_EXTENDED_IDS(ha))
771 mcp->mb[1] = fcport->loop_id;
773 mcp->mb[1] = fcport->loop_id << 8;
774 mcp->mb[2] = (uint16_t)handle;
775 mcp->mb[3] = (uint16_t)(handle >> 16);
776 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
777 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
779 mcp->tov = MBX_TOV_SECONDS;
781 rval = qla2x00_mailbox_command(ha, mcp);
783 if (rval != QLA_SUCCESS) {
784 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
787 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
795 qla2x00_abort_target(struct fc_port *fcport, unsigned int l)
799 mbx_cmd_t *mcp = &mc;
802 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
806 mcp->mb[0] = MBC_ABORT_TARGET;
807 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
808 if (HAS_EXTENDED_IDS(ha)) {
809 mcp->mb[1] = fcport->loop_id;
811 mcp->out_mb |= MBX_10;
813 mcp->mb[1] = fcport->loop_id << 8;
815 mcp->mb[2] = ha->loop_reset_delay;
816 mcp->mb[9] = ha->vp_idx;
819 mcp->tov = MBX_TOV_SECONDS;
821 rval = qla2x00_mailbox_command(ha, mcp);
822 if (rval != QLA_SUCCESS) {
823 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
827 /* Issue marker IOCB. */
828 rval2 = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
829 if (rval2 != QLA_SUCCESS) {
830 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
831 "(%x).\n", __func__, ha->host_no, rval2));
833 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
840 qla2x00_lun_reset(struct fc_port *fcport, unsigned int l)
844 mbx_cmd_t *mcp = &mc;
847 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
850 mcp->mb[0] = MBC_LUN_RESET;
851 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
852 if (HAS_EXTENDED_IDS(ha))
853 mcp->mb[1] = fcport->loop_id;
855 mcp->mb[1] = fcport->loop_id << 8;
858 mcp->mb[9] = ha->vp_idx;
861 mcp->tov = MBX_TOV_SECONDS;
863 rval = qla2x00_mailbox_command(ha, mcp);
864 if (rval != QLA_SUCCESS) {
865 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
869 /* Issue marker IOCB. */
870 rval2 = qla2x00_marker(ha, fcport->loop_id, l, MK_SYNC_ID_LUN);
871 if (rval2 != QLA_SUCCESS) {
872 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
873 "(%x).\n", __func__, ha->host_no, rval2));
875 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
882 * qla2x00_get_adapter_id
883 * Get adapter ID and topology.
886 * ha = adapter block pointer.
887 * id = pointer for loop ID.
888 * al_pa = pointer for AL_PA.
889 * area = pointer for area.
890 * domain = pointer for domain.
891 * top = pointer for topology.
892 * TARGET_QUEUE_LOCK must be released.
893 * ADAPTER_STATE_LOCK must be released.
896 * qla2x00 local function return status code.
902 qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
903 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
907 mbx_cmd_t *mcp = &mc;
909 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
912 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
913 mcp->mb[9] = ha->vp_idx;
914 mcp->out_mb = MBX_9|MBX_0;
915 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
916 mcp->tov = MBX_TOV_SECONDS;
918 rval = qla2x00_mailbox_command(ha, mcp);
919 if (mcp->mb[0] == MBS_COMMAND_ERROR)
920 rval = QLA_COMMAND_ERROR;
924 *al_pa = LSB(mcp->mb[2]);
925 *area = MSB(mcp->mb[2]);
926 *domain = LSB(mcp->mb[3]);
928 *sw_cap = mcp->mb[7];
930 if (rval != QLA_SUCCESS) {
932 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
936 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
944 * qla2x00_get_retry_cnt
945 * Get current firmware login retry count and delay.
948 * ha = adapter block pointer.
949 * retry_cnt = pointer to login retry count.
950 * tov = pointer to login timeout value.
953 * qla2x00 local function return status code.
959 qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
965 mbx_cmd_t *mcp = &mc;
967 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
970 mcp->mb[0] = MBC_GET_RETRY_COUNT;
972 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
973 mcp->tov = MBX_TOV_SECONDS;
975 rval = qla2x00_mailbox_command(ha, mcp);
977 if (rval != QLA_SUCCESS) {
979 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
980 ha->host_no, mcp->mb[0]));
982 /* Convert returned data and check our values. */
983 *r_a_tov = mcp->mb[3] / 2;
984 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
985 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
986 /* Update to the larger values */
987 *retry_cnt = (uint8_t)mcp->mb[1];
991 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
992 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov));
999 * qla2x00_init_firmware
1000 * Initialize adapter firmware.
1003 * ha = adapter block pointer.
1004 * dptr = Initialization control block pointer.
1005 * size = size of initialization control block.
1006 * TARGET_QUEUE_LOCK must be released.
1007 * ADAPTER_STATE_LOCK must be released.
1010 * qla2x00 local function return status code.
1016 qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1020 mbx_cmd_t *mcp = &mc;
1022 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1025 #ifdef QL_DEBUG_LEVEL_5
1026 if (IS_FWI2_CAPABLE(ha)) {
1027 struct init_cb_24xx *icb = (struct init_cb_24xx *)ha->init_cb;
1028 DEBUG5(printk(KERN_INFO "%s(): firmware_options_1 %x, "
1029 "firmware_options_2 %x, firmware_options_3 %x\n",
1030 __func__, icb->firmware_options_1,
1031 icb->firmware_options_2, icb->firmware_options_3));
1032 DEBUG5(printk(KERN_INFO "%s(): Control Block:\n", __func__));
1033 DEBUG5(qla2x00_dump_buffer((uint8_t *)icb, sizeof(*icb)));
1035 init_cb_t *icb = (init_cb_t *)ha->init_cb;
1036 DEBUG5(printk(KERN_INFO "%s(): firmware_options[0] %x, "
1037 "firmware_options[1] %x, add_firmware_options[0] %x, "
1038 "add_firmware_options[1] %x\n", __func__,
1039 icb->firmware_options[0], icb->firmware_options[1],
1040 icb->add_firmware_options[0],
1041 icb->add_firmware_options[1]));
1042 DEBUG5(printk(KERN_INFO "%s(): Control Block:\n", __func__));
1043 DEBUG5(qla2x00_dump_buffer((uint8_t *)icb, sizeof(*icb)));
1047 if (ha->flags.npiv_supported)
1048 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1050 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1052 mcp->mb[2] = MSW(ha->init_cb_dma);
1053 mcp->mb[3] = LSW(ha->init_cb_dma);
1056 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1057 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1058 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1059 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1060 mcp->buf_size = size;
1061 mcp->flags = MBX_DMA_OUT;
1062 mcp->tov = MBX_TOV_SECONDS;
1063 rval = qla2x00_mailbox_command(ha, mcp);
1065 if (rval != QLA_SUCCESS) {
1067 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1069 ha->host_no, rval, mcp->mb[0]));
1072 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1080 * qla2x00_get_port_database
1081 * Issue normal/enhanced get port database mailbox command
1082 * and copy device name as necessary.
1085 * ha = adapter state pointer.
1086 * dev = structure pointer.
1087 * opt = enhanced cmd option byte.
1090 * qla2x00 local function return status code.
1096 qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1100 mbx_cmd_t *mcp = &mc;
1101 port_database_t *pd;
1102 struct port_database_24xx *pd24;
1105 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1108 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1110 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1111 "structure.\n", __func__, ha->host_no));
1112 return QLA_MEMORY_ALLOC_FAILED;
1114 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
1116 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1117 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
1118 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1119 mcp->mb[2] = MSW(pd_dma);
1120 mcp->mb[3] = LSW(pd_dma);
1121 mcp->mb[6] = MSW(MSD(pd_dma));
1122 mcp->mb[7] = LSW(MSD(pd_dma));
1123 mcp->mb[9] = ha->vp_idx;
1124 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1126 if (IS_FWI2_CAPABLE(ha)) {
1127 mcp->mb[1] = fcport->loop_id;
1129 mcp->out_mb |= MBX_10|MBX_1;
1130 mcp->in_mb |= MBX_1;
1131 } else if (HAS_EXTENDED_IDS(ha)) {
1132 mcp->mb[1] = fcport->loop_id;
1134 mcp->out_mb |= MBX_10|MBX_1;
1136 mcp->mb[1] = fcport->loop_id << 8 | opt;
1137 mcp->out_mb |= MBX_1;
1139 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1140 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
1141 mcp->flags = MBX_DMA_IN;
1142 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1143 rval = qla2x00_mailbox_command(ha, mcp);
1144 if (rval != QLA_SUCCESS)
1147 if (IS_FWI2_CAPABLE(ha)) {
1148 pd24 = (struct port_database_24xx *) pd;
1150 /* Check for logged in state. */
1151 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1152 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1153 DEBUG2(printk("%s(%ld): Unable to verify "
1154 "login-state (%x/%x) for loop_id %x\n",
1155 __func__, ha->host_no,
1156 pd24->current_login_state,
1157 pd24->last_login_state, fcport->loop_id));
1158 rval = QLA_FUNCTION_FAILED;
1162 /* Names are little-endian. */
1163 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1164 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1166 /* Get port_id of device. */
1167 fcport->d_id.b.domain = pd24->port_id[0];
1168 fcport->d_id.b.area = pd24->port_id[1];
1169 fcport->d_id.b.al_pa = pd24->port_id[2];
1170 fcport->d_id.b.rsvd_1 = 0;
1172 /* If not target must be initiator or unknown type. */
1173 if ((pd24->prli_svc_param_word_3[0] & BIT_4))
1174 fcport->port_type = FCT_TARGET;
1175 else if ((pd24->prli_svc_param_word_3[0] & BIT_5))
1176 fcport->port_type = FCT_INITIATOR;
1178 fcport->port_type = FCT_UNKNOWN;
1180 /* Passback COS information. */
1181 fcport->supported_classes = (pd24->flags & PDF_CLASS_2) ?
1182 FC_COS_CLASS2 : FC_COS_CLASS3;
1184 if (pd24->prli_svc_param_word_3[0] & BIT_7)
1185 fcport->conf_compl_supported = 1;
1187 /* Check for logged in state. */
1188 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1189 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1190 rval = QLA_FUNCTION_FAILED;
1194 /* Names are little-endian. */
1195 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1196 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1198 /* Get port_id of device. */
1199 fcport->d_id.b.domain = pd->port_id[0];
1200 fcport->d_id.b.area = pd->port_id[3];
1201 fcport->d_id.b.al_pa = pd->port_id[2];
1202 fcport->d_id.b.rsvd_1 = 0;
1204 /* Check for device require authentication. */
1205 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1206 (fcport->flags &= ~FCF_AUTH_REQ);
1208 /* If not target must be initiator or unknown type. */
1209 if ((pd->prli_svc_param_word_3[0] & BIT_4))
1210 fcport->port_type = FCT_TARGET;
1211 else if ((pd->prli_svc_param_word_3[0] & BIT_5))
1212 fcport->port_type = FCT_INITIATOR;
1214 fcport->port_type = FCT_UNKNOWN;
1216 /* Passback COS information. */
1217 fcport->supported_classes = (pd->options & BIT_4) ?
1218 FC_COS_CLASS2: FC_COS_CLASS3;
1220 if (pd->prli_svc_param_word_3[0] & BIT_7)
1221 fcport->conf_compl_supported = 1;
1225 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1227 if (rval != QLA_SUCCESS) {
1228 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1229 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1231 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1236 EXPORT_SYMBOL(qla2x00_get_port_database);
1239 * qla2x00_get_firmware_state
1240 * Get adapter firmware state.
1243 * ha = adapter block pointer.
1244 * dptr = pointer for firmware state.
1245 * TARGET_QUEUE_LOCK must be released.
1246 * ADAPTER_STATE_LOCK must be released.
1249 * qla2x00 local function return status code.
1255 qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *states)
1259 mbx_cmd_t *mcp = &mc;
1261 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1264 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1265 mcp->out_mb = MBX_0;
1266 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1267 mcp->tov = MBX_TOV_SECONDS;
1269 rval = qla2x00_mailbox_command(ha, mcp);
1271 /* Return firmware states. */
1272 states[0] = mcp->mb[1];
1273 states[1] = mcp->mb[2];
1274 states[2] = mcp->mb[3];
1276 if (rval != QLA_SUCCESS) {
1278 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1279 "failed=%x.\n", ha->host_no, rval));
1282 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1290 * qla2x00_get_port_name
1291 * Issue get port name mailbox command.
1292 * Returned name is in big endian format.
1295 * ha = adapter block pointer.
1296 * loop_id = loop ID of device.
1297 * name = pointer for name.
1298 * TARGET_QUEUE_LOCK must be released.
1299 * ADAPTER_STATE_LOCK must be released.
1302 * qla2x00 local function return status code.
1308 qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1313 mbx_cmd_t *mcp = &mc;
1315 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1318 mcp->mb[0] = MBC_GET_PORT_NAME;
1319 mcp->mb[9] = ha->vp_idx;
1320 mcp->out_mb = MBX_9|MBX_1|MBX_0;
1321 if (HAS_EXTENDED_IDS(ha)) {
1322 mcp->mb[1] = loop_id;
1324 mcp->out_mb |= MBX_10;
1326 mcp->mb[1] = loop_id << 8 | opt;
1329 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1330 mcp->tov = MBX_TOV_SECONDS;
1332 rval = qla2x00_mailbox_command(ha, mcp);
1334 if (rval != QLA_SUCCESS) {
1336 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1337 ha->host_no, rval));
1340 /* This function returns name in big endian. */
1341 name[0] = MSB(mcp->mb[2]);
1342 name[1] = LSB(mcp->mb[2]);
1343 name[2] = MSB(mcp->mb[3]);
1344 name[3] = LSB(mcp->mb[3]);
1345 name[4] = MSB(mcp->mb[6]);
1346 name[5] = LSB(mcp->mb[6]);
1347 name[6] = MSB(mcp->mb[7]);
1348 name[7] = LSB(mcp->mb[7]);
1351 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1360 * Issue LIP reset mailbox command.
1363 * ha = adapter block pointer.
1364 * TARGET_QUEUE_LOCK must be released.
1365 * ADAPTER_STATE_LOCK must be released.
1368 * qla2x00 local function return status code.
1374 qla2x00_lip_reset(scsi_qla_host_t *ha)
1378 mbx_cmd_t *mcp = &mc;
1380 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1382 if (IS_FWI2_CAPABLE(ha)) {
1383 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1386 mcp->mb[3] = ha->loop_reset_delay;
1387 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1389 mcp->mb[0] = MBC_LIP_RESET;
1390 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1391 if (HAS_EXTENDED_IDS(ha)) {
1392 mcp->mb[1] = 0x00ff;
1394 mcp->out_mb |= MBX_10;
1396 mcp->mb[1] = 0xff00;
1398 mcp->mb[2] = ha->loop_reset_delay;
1402 mcp->tov = MBX_TOV_SECONDS;
1404 rval = qla2x00_mailbox_command(ha, mcp);
1406 if (rval != QLA_SUCCESS) {
1408 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1409 __func__, ha->host_no, rval));
1412 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1423 * ha = adapter block pointer.
1424 * sns = pointer for command.
1425 * cmd_size = command size.
1426 * buf_size = response/command size.
1427 * TARGET_QUEUE_LOCK must be released.
1428 * ADAPTER_STATE_LOCK must be released.
1431 * qla2x00 local function return status code.
1437 qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1438 uint16_t cmd_size, size_t buf_size)
1442 mbx_cmd_t *mcp = &mc;
1444 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1447 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1448 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov));
1450 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1451 mcp->mb[1] = cmd_size;
1452 mcp->mb[2] = MSW(sns_phys_address);
1453 mcp->mb[3] = LSW(sns_phys_address);
1454 mcp->mb[6] = MSW(MSD(sns_phys_address));
1455 mcp->mb[7] = LSW(MSD(sns_phys_address));
1456 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1457 mcp->in_mb = MBX_0|MBX_1;
1458 mcp->buf_size = buf_size;
1459 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1460 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1461 rval = qla2x00_mailbox_command(ha, mcp);
1463 if (rval != QLA_SUCCESS) {
1465 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1466 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1467 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1468 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1471 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no));
1478 qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1479 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1483 struct logio_entry_24xx *lg;
1487 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1489 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1491 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1492 __func__, ha->host_no));
1493 return QLA_MEMORY_ALLOC_FAILED;
1495 memset(lg, 0, sizeof(struct logio_entry_24xx));
1497 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1498 lg->entry_count = 1;
1499 lg->nport_handle = cpu_to_le16(loop_id);
1500 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1502 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1504 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
1505 lg->port_id[0] = al_pa;
1506 lg->port_id[1] = area;
1507 lg->port_id[2] = domain;
1508 lg->vp_index = ha->vp_idx;
1509 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1510 if (rval != QLA_SUCCESS) {
1511 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
1512 "(%x).\n", __func__, ha->host_no, rval));
1513 } else if (lg->entry_status != 0) {
1514 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1515 "-- error status (%x).\n", __func__, ha->host_no,
1517 rval = QLA_FUNCTION_FAILED;
1518 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1519 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1520 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1522 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1523 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1524 ha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1528 case LSC_SCODE_PORTID_USED:
1529 mb[0] = MBS_PORT_ID_USED;
1530 mb[1] = LSW(iop[1]);
1532 case LSC_SCODE_NPORT_USED:
1533 mb[0] = MBS_LOOP_ID_USED;
1535 case LSC_SCODE_NOLINK:
1536 case LSC_SCODE_NOIOCB:
1537 case LSC_SCODE_NOXCB:
1538 case LSC_SCODE_CMD_FAILED:
1539 case LSC_SCODE_NOFABRIC:
1540 case LSC_SCODE_FW_NOT_READY:
1541 case LSC_SCODE_NOT_LOGGED_IN:
1542 case LSC_SCODE_NOPCB:
1543 case LSC_SCODE_ELS_REJECT:
1544 case LSC_SCODE_CMD_PARAM_ERR:
1545 case LSC_SCODE_NONPORT:
1546 case LSC_SCODE_LOGGED_IN:
1547 case LSC_SCODE_NOFLOGI_ACC:
1549 mb[0] = MBS_COMMAND_ERROR;
1553 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1555 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1557 mb[0] = MBS_COMMAND_COMPLETE;
1559 if (iop[0] & BIT_4) {
1565 /* Passback COS information. */
1567 if (lg->io_parameter[7] || lg->io_parameter[8])
1568 mb[10] |= BIT_0; /* Class 2. */
1569 if (lg->io_parameter[9] || lg->io_parameter[10])
1570 mb[10] |= BIT_1; /* Class 3. */
1571 if (lg->io_parameter[0] & __constant_cpu_to_le32(BIT_7))
1572 mb[10] |= BIT_7; /* Confirmed Completion Allowed */
1575 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1581 * qla2x00_login_fabric
1582 * Issue login fabric port mailbox command.
1585 * ha = adapter block pointer.
1586 * loop_id = device loop ID.
1587 * domain = device domain.
1588 * area = device area.
1589 * al_pa = device AL_PA.
1590 * status = pointer for return status.
1591 * opt = command options.
1592 * TARGET_QUEUE_LOCK must be released.
1593 * ADAPTER_STATE_LOCK must be released.
1596 * qla2x00 local function return status code.
1602 qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1603 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1607 mbx_cmd_t *mcp = &mc;
1609 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no));
1611 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1612 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1613 if (HAS_EXTENDED_IDS(ha)) {
1614 mcp->mb[1] = loop_id;
1616 mcp->out_mb |= MBX_10;
1618 mcp->mb[1] = (loop_id << 8) | opt;
1620 mcp->mb[2] = domain;
1621 mcp->mb[3] = area << 8 | al_pa;
1623 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1624 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1626 rval = qla2x00_mailbox_command(ha, mcp);
1628 /* Return mailbox statuses. */
1635 /* COS retrieved from Get-Port-Database mailbox command. */
1639 if (rval != QLA_SUCCESS) {
1640 /* RLU tmp code: need to change main mailbox_command function to
1641 * return ok even when the mailbox completion value is not
1642 * SUCCESS. The caller needs to be responsible to interpret
1643 * the return values of this mailbox command if we're not
1644 * to change too much of the existing code.
1646 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1647 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1648 mcp->mb[0] == 0x4006)
1652 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1653 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
1654 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
1657 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1665 * qla2x00_login_local_device
1666 * Issue login loop port mailbox command.
1669 * ha = adapter block pointer.
1670 * loop_id = device loop ID.
1671 * opt = command options.
1674 * Return status code.
1681 qla2x00_login_local_device(scsi_qla_host_t *ha, fc_port_t *fcport,
1682 uint16_t *mb_ret, uint8_t opt)
1686 mbx_cmd_t *mcp = &mc;
1688 if (IS_FWI2_CAPABLE(ha))
1689 return qla24xx_login_fabric(ha, fcport->loop_id,
1690 fcport->d_id.b.domain, fcport->d_id.b.area,
1691 fcport->d_id.b.al_pa, mb_ret, opt);
1693 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1695 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1696 if (HAS_EXTENDED_IDS(ha))
1697 mcp->mb[1] = fcport->loop_id;
1699 mcp->mb[1] = fcport->loop_id << 8;
1701 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1702 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1703 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1705 rval = qla2x00_mailbox_command(ha, mcp);
1707 /* Return mailbox statuses. */
1708 if (mb_ret != NULL) {
1709 mb_ret[0] = mcp->mb[0];
1710 mb_ret[1] = mcp->mb[1];
1711 mb_ret[6] = mcp->mb[6];
1712 mb_ret[7] = mcp->mb[7];
1715 if (rval != QLA_SUCCESS) {
1716 /* AV tmp code: need to change main mailbox_command function to
1717 * return ok even when the mailbox completion value is not
1718 * SUCCESS. The caller needs to be responsible to interpret
1719 * the return values of this mailbox command if we're not
1720 * to change too much of the existing code.
1722 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1725 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1726 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1727 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1728 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1729 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1730 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1733 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no));
1740 qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1741 uint8_t area, uint8_t al_pa)
1744 struct logio_entry_24xx *lg;
1747 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1749 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1751 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1752 __func__, ha->host_no));
1753 return QLA_MEMORY_ALLOC_FAILED;
1755 memset(lg, 0, sizeof(struct logio_entry_24xx));
1757 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1758 lg->entry_count = 1;
1759 lg->nport_handle = cpu_to_le16(loop_id);
1761 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
1762 lg->port_id[0] = al_pa;
1763 lg->port_id[1] = area;
1764 lg->port_id[2] = domain;
1765 lg->vp_index = ha->vp_idx;
1766 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1767 if (rval != QLA_SUCCESS) {
1768 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1769 "(%x).\n", __func__, ha->host_no, rval));
1770 } else if (lg->entry_status != 0) {
1771 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1772 "-- error status (%x).\n", __func__, ha->host_no,
1774 rval = QLA_FUNCTION_FAILED;
1775 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1776 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1777 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1778 ha->host_no, le16_to_cpu(lg->comp_status),
1779 le32_to_cpu(lg->io_parameter[0]),
1780 le32_to_cpu(lg->io_parameter[1])));
1783 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1786 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1792 * qla2x00_fabric_logout
1793 * Issue logout fabric port mailbox command.
1796 * ha = adapter block pointer.
1797 * loop_id = device loop ID.
1798 * TARGET_QUEUE_LOCK must be released.
1799 * ADAPTER_STATE_LOCK must be released.
1802 * qla2x00 local function return status code.
1808 qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1809 uint8_t area, uint8_t al_pa)
1813 mbx_cmd_t *mcp = &mc;
1815 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1818 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1819 mcp->out_mb = MBX_1|MBX_0;
1820 if (HAS_EXTENDED_IDS(ha)) {
1821 mcp->mb[1] = loop_id;
1823 mcp->out_mb |= MBX_10;
1825 mcp->mb[1] = loop_id << 8;
1828 mcp->in_mb = MBX_1|MBX_0;
1829 mcp->tov = MBX_TOV_SECONDS;
1831 rval = qla2x00_mailbox_command(ha, mcp);
1833 if (rval != QLA_SUCCESS) {
1835 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1836 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]));
1839 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1847 * qla2x00_full_login_lip
1848 * Issue full login LIP mailbox command.
1851 * ha = adapter block pointer.
1852 * TARGET_QUEUE_LOCK must be released.
1853 * ADAPTER_STATE_LOCK must be released.
1856 * qla2x00 local function return status code.
1862 qla2x00_full_login_lip(scsi_qla_host_t *ha)
1866 mbx_cmd_t *mcp = &mc;
1868 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1871 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1872 mcp->mb[1] = IS_FWI2_CAPABLE(ha) ? BIT_3: 0;
1875 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1877 mcp->tov = MBX_TOV_SECONDS;
1879 rval = qla2x00_mailbox_command(ha, mcp);
1881 if (rval != QLA_SUCCESS) {
1883 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1884 ha->host_no, rval));
1887 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1895 * qla2x00_get_id_list
1898 * ha = adapter block pointer.
1901 * qla2x00 local function return status code.
1907 qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
1912 mbx_cmd_t *mcp = &mc;
1914 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1917 if (id_list == NULL)
1918 return QLA_FUNCTION_FAILED;
1920 mcp->mb[0] = MBC_GET_ID_LIST;
1921 mcp->out_mb = MBX_0;
1922 if (IS_FWI2_CAPABLE(ha)) {
1923 mcp->mb[2] = MSW(id_list_dma);
1924 mcp->mb[3] = LSW(id_list_dma);
1925 mcp->mb[6] = MSW(MSD(id_list_dma));
1926 mcp->mb[7] = LSW(MSD(id_list_dma));
1928 mcp->mb[9] = ha->vp_idx;
1929 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
1931 mcp->mb[1] = MSW(id_list_dma);
1932 mcp->mb[2] = LSW(id_list_dma);
1933 mcp->mb[3] = MSW(MSD(id_list_dma));
1934 mcp->mb[6] = LSW(MSD(id_list_dma));
1935 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1937 mcp->in_mb = MBX_1|MBX_0;
1938 mcp->tov = MBX_TOV_SECONDS;
1940 rval = qla2x00_mailbox_command(ha, mcp);
1942 if (rval != QLA_SUCCESS) {
1944 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
1945 ha->host_no, rval));
1947 *entries = mcp->mb[1];
1948 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
1954 EXPORT_SYMBOL(qla2x00_get_id_list);
1957 * qla2x00_get_resource_cnts
1958 * Get current firmware resource counts.
1961 * ha = adapter block pointer.
1964 * qla2x00 local function return status code.
1970 qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
1971 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
1972 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports)
1976 mbx_cmd_t *mcp = &mc;
1978 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1980 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
1981 mcp->out_mb = MBX_0;
1982 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1983 mcp->tov = MBX_TOV_SECONDS;
1985 rval = qla2x00_mailbox_command(ha, mcp);
1987 if (rval != QLA_SUCCESS) {
1989 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
1990 ha->host_no, mcp->mb[0]));
1992 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
1993 "mb7=%x mb10=%x mb11=%x.\n", __func__, ha->host_no,
1994 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
1995 mcp->mb[10], mcp->mb[11]));
1998 *cur_xchg_cnt = mcp->mb[3];
2000 *orig_xchg_cnt = mcp->mb[6];
2002 *cur_iocb_cnt = mcp->mb[7];
2004 *orig_iocb_cnt = mcp->mb[10];
2005 if (max_npiv_vports)
2006 *max_npiv_vports = mcp->mb[11];
2012 #if defined(QL_DEBUG_LEVEL_3)
2014 * qla2x00_get_fcal_position_map
2015 * Get FCAL (LILP) position map using mailbox command
2018 * ha = adapter state pointer.
2019 * pos_map = buffer pointer (can be NULL).
2022 * qla2x00 local function return status code.
2028 qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
2032 mbx_cmd_t *mcp = &mc;
2034 dma_addr_t pmap_dma;
2036 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma);
2038 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
2039 __func__, ha->host_no));
2040 return QLA_MEMORY_ALLOC_FAILED;
2042 memset(pmap, 0, FCAL_MAP_SIZE);
2044 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2045 mcp->mb[2] = MSW(pmap_dma);
2046 mcp->mb[3] = LSW(pmap_dma);
2047 mcp->mb[6] = MSW(MSD(pmap_dma));
2048 mcp->mb[7] = LSW(MSD(pmap_dma));
2049 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2050 mcp->in_mb = MBX_1|MBX_0;
2051 mcp->buf_size = FCAL_MAP_SIZE;
2052 mcp->flags = MBX_DMA_IN;
2053 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2054 rval = qla2x00_mailbox_command(ha, mcp);
2056 if (rval == QLA_SUCCESS) {
2057 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2058 "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
2059 mcp->mb[1], (unsigned)pmap[0]));
2060 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2063 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2065 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2067 if (rval != QLA_SUCCESS) {
2068 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2069 ha->host_no, rval));
2071 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2079 * qla2x00_get_link_status
2082 * ha = adapter block pointer.
2083 * loop_id = device loop ID.
2084 * ret_buf = pointer to link status return buffer.
2088 * BIT_0 = mem alloc error.
2089 * BIT_1 = mailbox error.
2092 qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
2093 struct link_statistics *stats, dma_addr_t stats_dma)
2097 mbx_cmd_t *mcp = &mc;
2098 uint32_t *siter, *diter, dwords;
2100 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2102 mcp->mb[0] = MBC_GET_LINK_STATUS;
2103 mcp->mb[2] = MSW(stats_dma);
2104 mcp->mb[3] = LSW(stats_dma);
2105 mcp->mb[6] = MSW(MSD(stats_dma));
2106 mcp->mb[7] = LSW(MSD(stats_dma));
2107 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2109 if (IS_FWI2_CAPABLE(ha)) {
2110 mcp->mb[1] = loop_id;
2113 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2114 mcp->in_mb |= MBX_1;
2115 } else if (HAS_EXTENDED_IDS(ha)) {
2116 mcp->mb[1] = loop_id;
2118 mcp->out_mb |= MBX_10|MBX_1;
2120 mcp->mb[1] = loop_id << 8;
2121 mcp->out_mb |= MBX_1;
2123 mcp->tov = MBX_TOV_SECONDS;
2124 mcp->flags = IOCTL_CMD;
2125 rval = qla2x00_mailbox_command(ha, mcp);
2127 if (rval == QLA_SUCCESS) {
2128 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2129 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2130 __func__, ha->host_no, mcp->mb[0]));
2131 rval = QLA_FUNCTION_FAILED;
2133 /* Copy over data -- firmware data is LE. */
2134 dwords = offsetof(struct link_statistics, unused1) / 4;
2135 siter = diter = &stats->link_fail_cnt;
2137 *diter++ = le32_to_cpu(*siter++);
2141 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2142 ha->host_no, rval));
2149 qla24xx_get_isp_stats(scsi_qla_host_t *ha, struct link_statistics *stats,
2150 dma_addr_t stats_dma)
2154 mbx_cmd_t *mcp = &mc;
2155 uint32_t *siter, *diter, dwords;
2157 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2159 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2160 mcp->mb[2] = MSW(stats_dma);
2161 mcp->mb[3] = LSW(stats_dma);
2162 mcp->mb[6] = MSW(MSD(stats_dma));
2163 mcp->mb[7] = LSW(MSD(stats_dma));
2164 mcp->mb[8] = sizeof(struct link_statistics) / 4;
2165 mcp->mb[9] = ha->vp_idx;
2167 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2168 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2169 mcp->tov = MBX_TOV_SECONDS;
2170 mcp->flags = IOCTL_CMD;
2171 rval = qla2x00_mailbox_command(ha, mcp);
2173 if (rval == QLA_SUCCESS) {
2174 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2175 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2176 __func__, ha->host_no, mcp->mb[0]));
2177 rval = QLA_FUNCTION_FAILED;
2179 /* Copy over data -- firmware data is LE. */
2180 dwords = sizeof(struct link_statistics) / 4;
2181 siter = diter = &stats->link_fail_cnt;
2183 *diter++ = le32_to_cpu(*siter++);
2187 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2188 ha->host_no, rval));
2195 qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
2199 unsigned long flags = 0;
2201 struct abort_entry_24xx *abt;
2205 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2207 fcport = sp->fcport;
2209 spin_lock_irqsave(&ha->hardware_lock, flags);
2210 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2211 if (ha->outstanding_cmds[handle] == sp)
2214 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2215 if (handle == MAX_OUTSTANDING_COMMANDS) {
2216 /* Command not found. */
2217 return QLA_FUNCTION_FAILED;
2220 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2222 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2223 __func__, ha->host_no));
2224 return QLA_MEMORY_ALLOC_FAILED;
2226 memset(abt, 0, sizeof(struct abort_entry_24xx));
2228 abt->entry_type = ABORT_IOCB_TYPE;
2229 abt->entry_count = 1;
2230 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2231 abt->handle_to_abort = handle;
2232 abt->port_id[0] = fcport->d_id.b.al_pa;
2233 abt->port_id[1] = fcport->d_id.b.area;
2234 abt->port_id[2] = fcport->d_id.b.domain;
2235 abt->vp_index = fcport->vp_idx;
2236 rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
2237 if (rval != QLA_SUCCESS) {
2238 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2239 __func__, ha->host_no, rval));
2240 } else if (abt->entry_status != 0) {
2241 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2242 "-- error status (%x).\n", __func__, ha->host_no,
2243 abt->entry_status));
2244 rval = QLA_FUNCTION_FAILED;
2245 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2246 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2247 "-- completion status (%x).\n", __func__, ha->host_no,
2248 le16_to_cpu(abt->nport_handle)));
2249 rval = QLA_FUNCTION_FAILED;
2251 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2254 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2259 struct tsk_mgmt_cmd {
2261 struct tsk_mgmt_entry tsk;
2262 struct sts_entry_24xx sts;
2267 __qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
2271 struct tsk_mgmt_cmd *tsk;
2273 scsi_qla_host_t *ha, *pha;
2275 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
2278 pha = to_qla_parent(ha);
2279 tsk = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &tsk_dma);
2281 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2282 "IOCB.\n", __func__, ha->host_no));
2283 return QLA_MEMORY_ALLOC_FAILED;
2285 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2287 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2288 tsk->p.tsk.entry_count = 1;
2289 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2290 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
2291 tsk->p.tsk.control_flags = cpu_to_le32(type);
2292 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2293 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2294 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2295 tsk->p.tsk.vp_index = fcport->vp_idx;
2296 if (type == TCF_LUN_RESET) {
2297 int_to_scsilun(l, &tsk->p.tsk.lun);
2298 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2299 sizeof(tsk->p.tsk.lun));
2302 rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
2303 if (rval != QLA_SUCCESS) {
2304 DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
2305 "(%x).\n", __func__, ha->host_no, name, rval));
2306 } else if (tsk->p.sts.entry_status != 0) {
2307 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2308 "-- error status (%x).\n", __func__, ha->host_no,
2309 tsk->p.sts.entry_status));
2310 rval = QLA_FUNCTION_FAILED;
2311 } else if (tsk->p.sts.comp_status !=
2312 __constant_cpu_to_le16(CS_COMPLETE)) {
2313 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2314 "-- completion status (%x).\n", __func__,
2315 ha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
2316 rval = QLA_FUNCTION_FAILED;
2319 /* Issue marker IOCB. */
2320 rval2 = qla2x00_marker(ha, fcport->loop_id, l,
2321 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2322 if (rval2 != QLA_SUCCESS) {
2323 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2324 "(%x).\n", __func__, ha->host_no, rval2));
2326 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2329 dma_pool_free(pha->s_dma_pool, tsk, tsk_dma);
2335 qla24xx_abort_target(struct fc_port *fcport, unsigned int l)
2337 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l);
2341 qla24xx_lun_reset(struct fc_port *fcport, unsigned int l)
2343 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l);
2347 qla2x00_system_error(scsi_qla_host_t *ha)
2351 mbx_cmd_t *mcp = &mc;
2353 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
2354 return QLA_FUNCTION_FAILED;
2356 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2358 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2359 mcp->out_mb = MBX_0;
2363 rval = qla2x00_mailbox_command(ha, mcp);
2365 if (rval != QLA_SUCCESS) {
2366 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2367 ha->host_no, rval));
2369 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2376 * qla2x00_set_serdes_params() -
2382 qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
2383 uint16_t sw_em_2g, uint16_t sw_em_4g)
2387 mbx_cmd_t *mcp = &mc;
2389 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2391 mcp->mb[0] = MBC_SERDES_PARAMS;
2393 mcp->mb[2] = sw_em_1g | BIT_15;
2394 mcp->mb[3] = sw_em_2g | BIT_15;
2395 mcp->mb[4] = sw_em_4g | BIT_15;
2396 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2398 mcp->tov = MBX_TOV_SECONDS;
2400 rval = qla2x00_mailbox_command(ha, mcp);
2402 if (rval != QLA_SUCCESS) {
2404 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2405 ha->host_no, rval, mcp->mb[0]));
2408 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2415 qla2x00_stop_firmware(scsi_qla_host_t *ha)
2419 mbx_cmd_t *mcp = &mc;
2421 if (!IS_FWI2_CAPABLE(ha))
2422 return QLA_FUNCTION_FAILED;
2424 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2426 mcp->mb[0] = MBC_STOP_FIRMWARE;
2427 mcp->out_mb = MBX_0;
2431 rval = qla2x00_mailbox_command(ha, mcp);
2433 if (rval != QLA_SUCCESS) {
2434 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2435 ha->host_no, rval));
2437 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2444 qla2x00_enable_eft_trace(scsi_qla_host_t *ha, dma_addr_t eft_dma,
2449 mbx_cmd_t *mcp = &mc;
2451 if (!IS_FWI2_CAPABLE(ha))
2452 return QLA_FUNCTION_FAILED;
2454 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2456 mcp->mb[0] = MBC_TRACE_CONTROL;
2457 mcp->mb[1] = TC_EFT_ENABLE;
2458 mcp->mb[2] = LSW(eft_dma);
2459 mcp->mb[3] = MSW(eft_dma);
2460 mcp->mb[4] = LSW(MSD(eft_dma));
2461 mcp->mb[5] = MSW(MSD(eft_dma));
2462 mcp->mb[6] = buffers;
2463 mcp->mb[7] = TC_AEN_DISABLE;
2464 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2465 mcp->in_mb = MBX_1|MBX_0;
2466 mcp->tov = MBX_TOV_SECONDS;
2468 rval = qla2x00_mailbox_command(ha, mcp);
2469 if (rval != QLA_SUCCESS) {
2470 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2471 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2473 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2480 qla2x00_disable_eft_trace(scsi_qla_host_t *ha)
2484 mbx_cmd_t *mcp = &mc;
2486 if (!IS_FWI2_CAPABLE(ha))
2487 return QLA_FUNCTION_FAILED;
2489 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2491 mcp->mb[0] = MBC_TRACE_CONTROL;
2492 mcp->mb[1] = TC_EFT_DISABLE;
2493 mcp->out_mb = MBX_1|MBX_0;
2494 mcp->in_mb = MBX_1|MBX_0;
2495 mcp->tov = MBX_TOV_SECONDS;
2497 rval = qla2x00_mailbox_command(ha, mcp);
2498 if (rval != QLA_SUCCESS) {
2499 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2500 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2502 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2509 qla2x00_enable_fce_trace(scsi_qla_host_t *ha, dma_addr_t fce_dma,
2510 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2514 mbx_cmd_t *mcp = &mc;
2516 if (!IS_QLA25XX(ha))
2517 return QLA_FUNCTION_FAILED;
2519 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2521 mcp->mb[0] = MBC_TRACE_CONTROL;
2522 mcp->mb[1] = TC_FCE_ENABLE;
2523 mcp->mb[2] = LSW(fce_dma);
2524 mcp->mb[3] = MSW(fce_dma);
2525 mcp->mb[4] = LSW(MSD(fce_dma));
2526 mcp->mb[5] = MSW(MSD(fce_dma));
2527 mcp->mb[6] = buffers;
2528 mcp->mb[7] = TC_AEN_DISABLE;
2530 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2531 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2532 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2534 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2535 mcp->tov = MBX_TOV_SECONDS;
2537 rval = qla2x00_mailbox_command(ha, mcp);
2538 if (rval != QLA_SUCCESS) {
2539 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2540 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2542 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2545 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2554 qla2x00_disable_fce_trace(scsi_qla_host_t *ha, uint64_t *wr, uint64_t *rd)
2558 mbx_cmd_t *mcp = &mc;
2560 if (!IS_FWI2_CAPABLE(ha))
2561 return QLA_FUNCTION_FAILED;
2563 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2565 mcp->mb[0] = MBC_TRACE_CONTROL;
2566 mcp->mb[1] = TC_FCE_DISABLE;
2567 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
2568 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2569 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2571 mcp->tov = MBX_TOV_SECONDS;
2573 rval = qla2x00_mailbox_command(ha, mcp);
2574 if (rval != QLA_SUCCESS) {
2575 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2576 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2578 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2581 *wr = (uint64_t) mcp->mb[5] << 48 |
2582 (uint64_t) mcp->mb[4] << 32 |
2583 (uint64_t) mcp->mb[3] << 16 |
2584 (uint64_t) mcp->mb[2];
2586 *rd = (uint64_t) mcp->mb[9] << 48 |
2587 (uint64_t) mcp->mb[8] << 32 |
2588 (uint64_t) mcp->mb[7] << 16 |
2589 (uint64_t) mcp->mb[6];
2596 qla2x00_read_sfp(scsi_qla_host_t *ha, dma_addr_t sfp_dma, uint16_t addr,
2597 uint16_t off, uint16_t count)
2601 mbx_cmd_t *mcp = &mc;
2603 if (!IS_FWI2_CAPABLE(ha))
2604 return QLA_FUNCTION_FAILED;
2606 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2608 mcp->mb[0] = MBC_READ_SFP;
2610 mcp->mb[2] = MSW(sfp_dma);
2611 mcp->mb[3] = LSW(sfp_dma);
2612 mcp->mb[6] = MSW(MSD(sfp_dma));
2613 mcp->mb[7] = LSW(MSD(sfp_dma));
2617 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2619 mcp->tov = MBX_TOV_SECONDS;
2621 rval = qla2x00_mailbox_command(ha, mcp);
2623 if (rval != QLA_SUCCESS) {
2624 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2625 ha->host_no, rval, mcp->mb[0]));
2627 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2634 qla2x00_set_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id,
2635 uint16_t port_speed, uint16_t *mb)
2639 mbx_cmd_t *mcp = &mc;
2641 if (!IS_IIDMA_CAPABLE(ha))
2642 return QLA_FUNCTION_FAILED;
2644 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2646 mcp->mb[0] = MBC_PORT_PARAMS;
2647 mcp->mb[1] = loop_id;
2649 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2650 mcp->mb[4] = mcp->mb[5] = 0;
2651 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2652 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2653 mcp->tov = MBX_TOV_SECONDS;
2655 rval = qla2x00_mailbox_command(ha, mcp);
2657 /* Return mailbox statuses. */
2666 if (rval != QLA_SUCCESS) {
2667 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2668 ha->host_no, rval));
2670 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2677 qla24xx_report_id_acquisition(scsi_qla_host_t *ha,
2678 struct vp_rpt_id_entry_24xx *rptid_entry)
2681 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
2682 scsi_qla_host_t *vha;
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__, ha->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__,ha->host_no,
2700 rptid_entry->port_id[2], rptid_entry->port_id[1],
2701 rptid_entry->port_id[0]));
2708 list_for_each_entry(vha, &ha->vp_list, vp_list)
2709 if (vp_idx == vha->vp_idx)
2715 vha->d_id.b.domain = rptid_entry->port_id[2];
2716 vha->d_id.b.area = rptid_entry->port_id[1];
2717 vha->d_id.b.al_pa = rptid_entry->port_id[0];
2720 * Cannot configure here as we are still sitting on the
2721 * response queue. Handle it in dpc context.
2723 set_bit(VP_IDX_ACQUIRED, &vha->vp_flags);
2724 set_bit(VP_DPC_NEEDED, &ha->dpc_flags);
2726 qla2xxx_wake_dpc(ha);
2731 * qla24xx_modify_vp_config
2732 * Change VP configuration for vha
2735 * vha = adapter block pointer.
2738 * qla2xxx local function return status code.
2744 qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2747 struct vp_config_entry_24xx *vpmod;
2748 dma_addr_t vpmod_dma;
2749 scsi_qla_host_t *pha;
2751 /* This can be called by the parent */
2752 pha = to_qla_parent(vha);
2754 vpmod = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
2756 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
2757 "IOCB.\n", __func__, pha->host_no));
2758 return QLA_MEMORY_ALLOC_FAILED;
2761 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2762 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2763 vpmod->entry_count = 1;
2764 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2765 vpmod->vp_count = 1;
2766 vpmod->vp_index1 = vha->vp_idx;
2767 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2768 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2769 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2770 vpmod->entry_count = 1;
2772 rval = qla2x00_issue_iocb(pha, vpmod, vpmod_dma, 0);
2773 if (rval != QLA_SUCCESS) {
2774 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
2775 "(%x).\n", __func__, pha->host_no, rval));
2776 } else if (vpmod->comp_status != 0) {
2777 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2778 "-- error status (%x).\n", __func__, pha->host_no,
2779 vpmod->comp_status));
2780 rval = QLA_FUNCTION_FAILED;
2781 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2782 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2783 "-- completion status (%x).\n", __func__, pha->host_no,
2784 le16_to_cpu(vpmod->comp_status)));
2785 rval = QLA_FUNCTION_FAILED;
2788 DEBUG11(printk("%s(%ld): done.\n", __func__, pha->host_no));
2789 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2791 dma_pool_free(pha->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 scsi_qla_host_t *ha = vha->parent;
2819 int vp_index = vha->vp_idx;
2821 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
2822 ha->host_no, vp_index));
2824 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
2825 return QLA_PARAMETER_ERROR;
2827 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2829 DEBUG2_3(printk("%s(%ld): "
2830 "failed to allocate VP Control IOCB.\n", __func__,
2832 return QLA_MEMORY_ALLOC_FAILED;
2834 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2836 vce->entry_type = VP_CTRL_IOCB_TYPE;
2837 vce->entry_count = 1;
2838 vce->command = cpu_to_le16(cmd);
2839 vce->vp_count = __constant_cpu_to_le16(1);
2841 /* index map in firmware starts with 1; decrement index
2842 * this is ok as we never use index 0
2844 map = (vp_index - 1) / 8;
2845 pos = (vp_index - 1) & 7;
2846 mutex_lock(&ha->vport_lock);
2847 vce->vp_idx_map[map] |= 1 << pos;
2848 mutex_unlock(&ha->vport_lock);
2850 rval = qla2x00_issue_iocb(ha, vce, vce_dma, 0);
2851 if (rval != QLA_SUCCESS) {
2852 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
2853 "(%x).\n", __func__, ha->host_no, rval));
2854 printk("%s(%ld): failed to issue VP control IOCB"
2855 "(%x).\n", __func__, ha->host_no, rval);
2856 } else if (vce->entry_status != 0) {
2857 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2858 "-- error status (%x).\n", __func__, ha->host_no,
2859 vce->entry_status));
2860 printk("%s(%ld): failed to complete IOCB "
2861 "-- error status (%x).\n", __func__, ha->host_no,
2863 rval = QLA_FUNCTION_FAILED;
2864 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2865 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2866 "-- completion status (%x).\n", __func__, ha->host_no,
2867 le16_to_cpu(vce->comp_status)));
2868 printk("%s(%ld): failed to complete IOCB "
2869 "-- completion status (%x).\n", __func__, ha->host_no,
2870 le16_to_cpu(vce->comp_status));
2871 rval = QLA_FUNCTION_FAILED;
2873 DEBUG2(printk("%s(%ld): done.\n", __func__, ha->host_no));
2876 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
2882 * qla2x00_send_change_request
2883 * Receive or disable RSCN request from fabric controller
2886 * ha = adapter block pointer
2887 * format = registration format:
2889 * 1 - Fabric detected registration
2890 * 2 - N_port detected registration
2891 * 3 - Full registration
2892 * FF - clear registration
2893 * vp_idx = Virtual port index
2896 * qla2x00 local function return status code.
2903 qla2x00_send_change_request(scsi_qla_host_t *ha, uint16_t format,
2908 mbx_cmd_t *mcp = &mc;
2911 * This command is implicitly executed by firmware during login for the
2915 return QLA_FUNCTION_FAILED;
2917 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
2918 mcp->mb[1] = format;
2919 mcp->mb[9] = vp_idx;
2920 mcp->out_mb = MBX_9|MBX_1|MBX_0;
2921 mcp->in_mb = MBX_0|MBX_1;
2922 mcp->tov = MBX_TOV_SECONDS;
2924 rval = qla2x00_mailbox_command(ha, mcp);
2926 if (rval == QLA_SUCCESS) {
2927 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2937 qla2x00_dump_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t addr,
2942 mbx_cmd_t *mcp = &mc;
2944 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2946 if (MSW(addr) || IS_FWI2_CAPABLE(ha)) {
2947 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
2948 mcp->mb[8] = MSW(addr);
2949 mcp->out_mb = MBX_8|MBX_0;
2951 mcp->mb[0] = MBC_DUMP_RISC_RAM;
2952 mcp->out_mb = MBX_0;
2954 mcp->mb[1] = LSW(addr);
2955 mcp->mb[2] = MSW(req_dma);
2956 mcp->mb[3] = LSW(req_dma);
2957 mcp->mb[6] = MSW(MSD(req_dma));
2958 mcp->mb[7] = LSW(MSD(req_dma));
2959 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
2960 if (IS_FWI2_CAPABLE(ha)) {
2961 mcp->mb[4] = MSW(size);
2962 mcp->mb[5] = LSW(size);
2963 mcp->out_mb |= MBX_5|MBX_4;
2965 mcp->mb[4] = LSW(size);
2966 mcp->out_mb |= MBX_4;
2970 mcp->tov = MBX_TOV_SECONDS;
2972 rval = qla2x00_mailbox_command(ha, mcp);
2974 if (rval != QLA_SUCCESS) {
2975 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
2976 ha->host_no, rval, mcp->mb[0]));
2978 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2984 /* 84XX Support **************************************************************/
2986 struct cs84xx_mgmt_cmd {
2988 struct verify_chip_entry_84xx req;
2989 struct verify_chip_rsp_84xx rsp;
2994 qla84xx_verify_chip(struct scsi_qla_host *ha, uint16_t *status)
2997 struct cs84xx_mgmt_cmd *mn;
3000 unsigned long flags;
3002 DEBUG16(printk("%s(%ld): entered.\n", __func__, ha->host_no));
3004 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
3006 DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX "
3007 "IOCB.\n", __func__, ha->host_no));
3008 return QLA_MEMORY_ALLOC_FAILED;
3012 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
3013 /* Diagnostic firmware? */
3014 /* options |= MENLO_DIAG_FW; */
3015 /* We update the firmware with only one data sequence. */
3016 options |= VCO_END_OF_DATA;
3020 memset(mn, 0, sizeof(*mn));
3021 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
3022 mn->p.req.entry_count = 1;
3023 mn->p.req.options = cpu_to_le16(options);
3025 DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__,
3027 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3030 rval = qla2x00_issue_iocb_timeout(ha, mn, mn_dma, 0, 120);
3031 if (rval != QLA_SUCCESS) {
3032 DEBUG2_16(printk("%s(%ld): failed to issue Verify "
3033 "IOCB (%x).\n", __func__, ha->host_no, rval));
3037 DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__,
3039 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3042 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3043 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3044 le16_to_cpu(mn->p.rsp.failure_code) : 0;
3045 DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__,
3046 ha->host_no, status[0], status[1]));
3048 if (status[0] != CS_COMPLETE) {
3049 rval = QLA_FUNCTION_FAILED;
3050 if (!(options & VCO_DONT_UPDATE_FW)) {
3051 DEBUG2_16(printk("%s(%ld): Firmware update "
3052 "failed. Retrying without update "
3053 "firmware.\n", __func__, ha->host_no));
3054 options |= VCO_DONT_UPDATE_FW;
3055 options &= ~VCO_FORCE_UPDATE;
3059 DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n",
3060 __func__, ha->host_no,
3061 le32_to_cpu(mn->p.rsp.fw_ver)));
3063 /* NOTE: we only update OP firmware. */
3064 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3065 ha->cs84xx->op_fw_version =
3066 le32_to_cpu(mn->p.rsp.fw_ver);
3067 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3073 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3075 if (rval != QLA_SUCCESS) {
3076 DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__,
3077 ha->host_no, rval));
3079 DEBUG16(printk("%s(%ld): done.\n", __func__, ha->host_no));